chore: delete code comments, add ratchet lint and ADRs
Classify every comment as tautology, stale, excuse or decision record. Tautology/stale/excuse comments are deleted (excuses filed as issues #196-#236), decisions moved to docs/adr/0001-0034. - scripts/lint-comments.sh + .comment-baseline: per-file comment count may only go down; wired into tests/all.sh - .claude/skills/delete-comment: repeatable audit workflow - cargo fmt applied to touched crates Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0545702fe0
commit
a94632ea3d
131 files changed
+1051
-1746
No files matched your search
@@ -1,12 +1,9 @@
|
||||
//! Slash-command registry and the completion engine shared by the TUI and RPC mode.
|
||||
|
||||
use crate::context::Skill;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Source {
|
||||
Builtin,
|
||||
/// `SKILL.md` path; running the command sends its body as a prompt.
|
||||
Skill(PathBuf),
|
||||
Mcp,
|
||||
Ext,
|
||||
@@ -22,12 +19,10 @@ pub enum ArgKind {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct CmdSpec {
|
||||
/// Without the leading `/`.
|
||||
pub name: String,
|
||||
pub summary: String,
|
||||
pub source: Source,
|
||||
pub args: ArgKind,
|
||||
/// `argument-hint:` of a skill, shown as `/name <hint>`.
|
||||
pub hint: Option<String>,
|
||||
}
|
||||
|
||||
@@ -43,7 +38,6 @@ impl CmdSpec {
|
||||
}
|
||||
}
|
||||
|
||||
/// Commands handled by the TUI itself. `models` feeds `/model` completion.
|
||||
pub fn builtins(models: &[&str]) -> Vec<CmdSpec> {
|
||||
use ArgKind::*;
|
||||
let b = |n, s, a| CmdSpec::new(n, s, Source::Builtin, a);
|
||||
@@ -128,7 +122,6 @@ pub fn builtins(models: &[&str]) -> Vec<CmdSpec> {
|
||||
]
|
||||
}
|
||||
|
||||
/// One `/<name>` per skill; names taken by `taken` (builtins) are skipped, so builtins win.
|
||||
pub fn skill_specs(skills: &[Skill], taken: &[CmdSpec]) -> Vec<CmdSpec> {
|
||||
skills
|
||||
.iter()
|
||||
@@ -145,7 +138,6 @@ pub fn skill_specs(skills: &[Skill], taken: &[CmdSpec]) -> Vec<CmdSpec> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The prompt a `/<skill> args` command sends: base dir line + body (no frontmatter), then the args.
|
||||
pub fn skill_prompt(name: &str, path: &std::path::Path, arg: &str) -> std::io::Result<String> {
|
||||
let raw = std::fs::read_to_string(path)?;
|
||||
let sk = crate::context::parse_skill(path, &raw)
|
||||
@@ -161,7 +153,6 @@ pub fn skill_prompt(name: &str, path: &std::path::Path, arg: &str) -> std::io::R
|
||||
))
|
||||
}
|
||||
|
||||
/// `/help` text generated from the registry.
|
||||
pub fn help(specs: &[CmdSpec]) -> String {
|
||||
specs
|
||||
.iter()
|
||||
@@ -180,24 +171,19 @@ pub fn help(specs: &[CmdSpec]) -> String {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Candidate {
|
||||
/// Replaces `line[start..cursor]`.
|
||||
pub label: String,
|
||||
pub detail: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct Completion {
|
||||
/// Byte offset where the completed token starts.
|
||||
pub start: usize,
|
||||
pub items: Vec<Candidate>,
|
||||
}
|
||||
|
||||
pub const MAX_ITEMS: usize = 8;
|
||||
/// Enum args (model ids) show every match; the popup scrolls.
|
||||
pub const MAX_ENUM_ITEMS: usize = 100;
|
||||
|
||||
/// Complete the token ending at byte `cur` of `line`:
|
||||
/// `/cmd` at line start → commands; `/cmd partial` → the command's args; `@partial` → files.
|
||||
pub fn complete(line: &str, cur: usize, specs: &[CmdSpec], files: &[String]) -> Completion {
|
||||
let cur = floor_boundary(line, cur.min(line.len()));
|
||||
let before = &line[..cur];
|
||||
@@ -261,7 +247,6 @@ pub fn is_fs_path(t: &str) -> bool {
|
||||
|| t.starts_with("../")
|
||||
}
|
||||
|
||||
/// Expand a leading `~/` to `$HOME`.
|
||||
pub fn expand_home(p: &str) -> PathBuf {
|
||||
match (p.strip_prefix("~/"), std::env::var_os("HOME")) {
|
||||
(Some(rest), Some(h)) => PathBuf::from(h).join(rest),
|
||||
@@ -269,8 +254,6 @@ pub fn expand_home(p: &str) -> PathBuf {
|
||||
}
|
||||
}
|
||||
|
||||
/// Live directory listing for a `~/`, `/`, `./` or `../` token; the typed form is kept in labels.
|
||||
/// Directories first and suffixed `/`; dotfiles only when the prefix starts with `.`.
|
||||
fn complete_path(tok: &str) -> Vec<String> {
|
||||
if tok == "~" {
|
||||
return vec!["~/".into()];
|
||||
@@ -329,8 +312,6 @@ fn floor_boundary(s: &str, mut i: usize) -> usize {
|
||||
i
|
||||
}
|
||||
|
||||
/// Case-insensitive subsequence match. Order: basename prefix, basename substring, substring,
|
||||
/// subsequence; shorter first within a tier.
|
||||
pub fn rank<'a>(xs: impl Iterator<Item = &'a str>, q: &str, n: usize) -> Vec<&'a str> {
|
||||
let q = q.to_lowercase();
|
||||
let mut hits: Vec<(usize, usize, &str)> = xs
|
||||
@@ -357,7 +338,6 @@ pub fn rank<'a>(xs: impl Iterator<Item = &'a str>, q: &str, n: usize) -> Vec<&'a
|
||||
hits.into_iter().take(n).map(|(_, _, x)| x).collect()
|
||||
}
|
||||
|
||||
/// Longest common prefix of all candidates (char-boundary safe).
|
||||
pub fn common_prefix<S: AsRef<str>>(xs: &[S]) -> String {
|
||||
let Some(first) = xs.first().map(AsRef::as_ref) else {
|
||||
return String::new();
|
||||
@@ -400,7 +380,6 @@ mod tests {
|
||||
assert_eq!(t(&format!("{b}/.")), [format!("{b}/.hid")]);
|
||||
assert!(t(&format!("{b}/nope/x")).is_empty());
|
||||
assert_eq!(t("x ~"), ["~/"]);
|
||||
// slash command stays a command
|
||||
assert!(t("/etc").is_empty());
|
||||
}
|
||||
|
||||
@@ -464,7 +443,6 @@ mod tests {
|
||||
(a.start, labels(&a)),
|
||||
(8, vec!["@src/main.rs", "@crates/x/src/main.rs"])
|
||||
);
|
||||
// cursor mid-line, non-ASCII before and inside the token
|
||||
let l = "héllo @ü rest";
|
||||
let u = complete(l, "héllo @ü".len(), &specs, &files);
|
||||
assert_eq!((u.start, labels(&u)), (7, vec!["@docs/ü.md"]));
|
||||
|
||||
Reference in new issue
Block a user