From f50d2029ed7a45063b2e46236ac0d782a5b215ab Mon Sep 17 00:00:00 2001 From: leemour Date: Wed, 25 Nov 2026 21:54:57 +0100 Subject: [PATCH] feat(lint): report a command cli-core reserves that the CLI built itself Add the lint rule reserved-shared-command (WC-CMD-34). It reads the CLI's commands --json and reports each of session start|status|end|list, doctor, mcp, account remove, mirrors and complete whose command lacks cli-core's origin mark, once per path, with the cli-core helper to mount instead. Why: audits found own sessions in zoom, drive, gcal, ydisk, notion and the CRM CLIs, an own mirrors in ydisk and an own doctor and MCP server in memo. assertSharedContracts only checks commands cli-core already marked, so a hand-built group passed every check. The rule ships as a warning in cli-dev lint and the family audit. Measured on 20 CLIs it flags 17 (only tg, max and wa pass), partly because cli-core 1.0.0 does not mark tokenSessionCommand, oauthSessionCommand, fileMirrorsCommand and accountRemoveCommand. It becomes an error in a later release after cli-core marks them, planned 2027-01-15. An exception is a lint/overrides.json entry, which already requires a reason, an owner and review_after. A lint/baseline entry for this rule is refused, and --write-baseline writes none. Co-Authored-By: Claude Opus 5.5 --- changes/feat-reserved-shared-commands.md | 13 ++++ docs/standards/README.md | 2 +- docs/standards/architecture.md | 3 +- docs/standards/commands.md | 31 ++++++++++ src/dev/audit.test.ts | 18 +++++- src/dev/audit.ts | 18 +++++- src/dev/lint.test.ts | 76 +++++++++++++++++++++++- src/dev/lint.ts | 60 +++++++++++++++++-- src/dev/main.ts | 13 +++- src/standards/lint.ts | 7 +++ 10 files changed, 225 insertions(+), 16 deletions(-) create mode 100644 changes/feat-reserved-shared-commands.md diff --git a/changes/feat-reserved-shared-commands.md b/changes/feat-reserved-shared-commands.md new file mode 100644 index 0000000..8654cf3 --- /dev/null +++ b/changes/feat-reserved-shared-commands.md @@ -0,0 +1,13 @@ +### Added + +- **`cli-dev lint` reports a command at a path cli-core reserves when the CLI built it itself.** The paths are + `session start`, `session status`, `session end`, `session list`, `doctor`, `mcp`, `account remove`, `mirrors` and + `complete`. The new rule `reserved-shared-command` reads `commands --json` and names each such path that has no + `origin: "cli-core"`, with the cli-core helper to mount instead. Audits found own sessions, an own `mirrors`, an own + `doctor` and an own MCP server in several CLIs, and no check saw them, because `assertSharedContracts` looks only at + commands cli-core marked. For now it is a warning in `cli-dev lint` and in the family audit, so no CI run fails on + it. It becomes an error in a later release, planned for 2027-01-15, once cli-core marks `tokenSessionCommand`, + `oauthSessionCommand`, `fileMirrorsCommand` and `accountRemoveCommand`. Until then a CLI that mounts one of those is + reported too. A deliberate difference goes in `lint/overrides.json` with its reason, owner and `review_after`. An + entry for this rule in `lint/baseline/` fails the lint, because it has no reason or date. The rule is + [WC-CMD-34](../docs/standards/commands.md#wc-cmd-34--mount-cli-cores-shared-command-at-a-reserved-path-never-one-of-your-own). diff --git a/docs/standards/README.md b/docs/standards/README.md index 70a31f8..7790a2a 100644 --- a/docs/standards/README.md +++ b/docs/standards/README.md @@ -29,7 +29,7 @@ the four steps that need a person. A new CLI is ready for its first release when |---|---|---:|---| | [Toolchain](toolchain.md) | `TOOL` | 20 | TypeScript, Biome, grit plugins, size caps, import cycles, spelling, Markdown, Go | | [Layout](layout.md) | `LAY` | 10 | Repository layout, entry points, exports, file size, one job per file, splitting a unit, the bundled bin | -| [Commands](commands.md) | `CMD` | 33 | Paths, vocabulary, flags, arguments, effects, lifetime, query, help, external references, joining `wcat`, settings in the config file, refs, network hosts, the generated `api` group | +| [Commands](commands.md) | `CMD` | 34 | Paths, vocabulary, flags, arguments, effects, lifetime, query, help, external references, joining `wcat`, settings in the config file, refs, network hosts, the generated `api` group, the paths cli-core reserves | | [Output](output.md) | `OUT` | 25 | Data on stdout only, envelopes, errors, exit codes, partial answers, projection, list results in a TypeScript API | | [MCP](mcp.md) | `MCP` | 13 | The MCP tools, how they come from commands, what each permission shows | | [Accounts](accounts.md) | `ACCT` | 13 | The explicit profile, reads across accounts, scope flags, linked identities, sign-in commands, memo's account groups | diff --git a/docs/standards/architecture.md b/docs/standards/architecture.md index 5c51cd7..63d918c 100644 --- a/docs/standards/architecture.md +++ b/docs/standards/architecture.md @@ -113,7 +113,8 @@ cli-core's entities, and the adapter behind cli-core's ports. CRM is the first d ### WC-ARCH-6 · Replace a use case, not a command - **Why:** when a CLI replaces the service method, its command and its MCP tool both get the change. -- **Enforced by:** review only. +- **Enforced by:** review only. For the paths cli-core reserves, `reserved-shared-command` + ([WC-CMD-34](commands.md#wc-cmd-34--mount-cli-cores-shared-command-at-a-reserved-path-never-one-of-your-own)). - **Example:** `Messenger.services` receives the shared services and returns only the ones it changes: `services: (base) => ({ messages: { ...base.messages, list: maxList } })`. To add a subcommand, a CLI calls `addCommand` on the command a factory returns. A calendar CLI changes what the shared calendar commands do through diff --git a/docs/standards/commands.md b/docs/standards/commands.md index 7ead86a..f8b5935 100644 --- a/docs/standards/commands.md +++ b/docs/standards/commands.md @@ -527,6 +527,37 @@ one operation, stay directly under `api`. - **Applies to:** every CLI with a generated `api` group, from its next regeneration. **Since:** the release after cli-base 0.120.0, with the cli-core release that mounts groups. **Rulings:** NEED-2754, NEED-2759. +### WC-CMD-34 · Mount cli-core's shared command at a reserved path, never one of your own + +These root paths belong to cli-core: `session start`, `session status`, `session end`, `session list`, `doctor`, +`mcp`, `account remove`, `mirrors` and `complete`. A CLI that has one of them mounts it from cli-core. It changes the +command only through `overrideSharedContract` or `customizeSharedCommand`, which keep cli-core's mark on it. It may add +a subcommand of its own to a shared group. A CLI does not need every path. + +- **Why:** a hand-built `session` or `doctor` looks the same in help, but it misses every later fix in cli-core. The + audits of 25.11.2026 found an own `session` in zoom, drive, gcal, ydisk, notion and the CRM CLIs, an own `mirrors` + in ydisk, an own `doctor` in memo and an own MCP server in memo. `assertSharedContracts` checks only the commands + cli-core marked, so none of these failed a check. +- **Enforced by:** `reserved-shared-command`. +- **How it is checked:** the lint and the family audit read the CLI's command tree as JSON, where cli-core marks + each shared command with the origin `cli-core`. The rule reports each reserved path whose command has no such mark, + once per path (`session` once for its four leaves). For now it is a warning: the lint and the audit print it and + pass. It becomes an error in the cli-base release after cli-core marks the helpers in the known gap below, planned + for 2027-01-15. +- **Example:** `tokenSessionCommand({ app, service, resolveSettings, verify })` for a sign-in with one token, + `oauthSessionCommand` for a browser sign-in, `messengerSessionCommands` in tg, max and wa. `appDoctorCommand`, + `appMcpCommand`, `appCompleteCommand`, `accountRemoveCommand` and `fileMirrorsCommand` for the other paths. max + replaces `doctor` and `session` through `customizeSharedCommand`, so they keep the mark and need no exception. +- **Exceptions:** an entry in the CLI's `lint/overrides.json`, such as + `{ "rule": "reserved-shared-command", "target": "session", "reason": "…", "owner": "@…", "review_after": "2027-03-01" }`. + An entry without a reason or a date does not apply, and an entry more than 14 days past its date fails. An entry + in `lint/baseline/` is refused, because it has neither. The first expected one is mail's `session`: one profile + signs in by app password or by Google or Microsoft OAuth, and no shared session command covers that. + Known gap, as of 2026-11-25: cli-core 1.0.0 does not mark `tokenSessionCommand`, `oauthSessionCommand`, + `fileMirrorsCommand` and the standalone `accountRemoveCommand`. A CLI that mounts one of them is still reported, + so the rule stays a warning until cli-core marks them. +- **Applies to:** all CLIs. **Since:** cli-base 1.1.0, as a warning. **Rulings:** none. + ## Sources These documents explain the rules on this page in more detail. Where one of them disagrees with this page, this page diff --git a/src/dev/audit.test.ts b/src/dev/audit.test.ts index 8a39d13..896e315 100644 --- a/src/dev/audit.test.ts +++ b/src/dev/audit.test.ts @@ -572,25 +572,39 @@ describe("judging an audit", () => { ) }) + it("counts a reserved path built by hand, blocks nothing on it, and baselines none of it", () => { + const result = auditClis([inputOf(tool("a")), inputOf(tool("b"))], options()) + expect(result.findings.filter((one) => one.rule === "reserved-shared-command").map((one) => one.target)).toEqual([ + "a: doctor", + "a: mcp", + "b: doctor", + "b: mcp", + ]) + expect(result.blocking.filter((one) => one.rule === "reserved-shared-command")).toEqual([]) + expect(result.nextBaseline["reserved-shared-command"]).toEqual([]) + }) + it("prints the scorecard as a table: lines with findings or not measured, and a total per CLI", () => { const result = auditClis(failing["same-path-contract"]?.() ?? [], options()) expect( scorecardTable(result.rows.filter((row) => !row.rule.startsWith("option") && row.rule !== "key-casing")), ).toMatchInlineSnapshot(` "cli rule found baseline overridden new fixed + a reserved-shared-command 2 0 0 2 0 a shared-command-contract n/a n/a n/a n/a n/a a same-path-contract 1 0 0 1 0 a same-flag-meaning 1 0 0 1 0 a same-entity-schema n/a n/a n/a n/a n/a a same-error-reason n/a n/a n/a n/a n/a b flag-two-meanings 1 0 0 1 0 + b reserved-shared-command 2 0 0 2 0 b shared-command-contract n/a n/a n/a n/a n/a b same-path-contract 1 0 0 1 0 b same-flag-meaning 1 0 0 1 0 b same-entity-schema n/a n/a n/a n/a n/a b same-error-reason n/a n/a n/a n/a n/a - a total 2 0 0 2 0 - b total 3 0 0 3 0" + a total 4 0 0 4 0 + b total 5 0 0 5 0" `) }) }) diff --git a/src/dev/audit.ts b/src/dev/audit.ts index 1fa7f58..7064ec7 100644 --- a/src/dev/audit.ts +++ b/src/dev/audit.ts @@ -11,7 +11,17 @@ import { BASE_REASONS, type ErrorReason } from "../standards/errors.js" import { LINT_RULES, OVERRIDE_BUDGET, type Override, overdue, overridesDueSoon } from "../standards/lint.js" import type { Vocabulary } from "../standards/vocabulary.js" import { type Capabilities, capabilityDifference } from "./capabilities.js" -import { judge, kindOf, lintCommands, longName, registeredKinds, summaryOf, walk } from "./lint.js" +import { + judge, + kindOf, + lintCommands, + longName, + OVERRIDE_ONLY_RULES, + registeredKinds, + summaryOf, + WARNING_RULES, + walk, +} from "./lint.js" import { type ContractEdit, sharedContractProblems } from "./shared-contracts.js" export interface AuditInput { @@ -520,7 +530,8 @@ export const auditClis = ( fixed: verdict.stale.filter((entry) => entry.in === "baseline").length, new_targets: verdict.fresh.map((violation) => `${cli}: ${violation.target}`), } - blocking.push(...mine.filter((finding) => row.new_targets.includes(finding.target))) + if (!WARNING_RULES.has(rule)) + blocking.push(...mine.filter((finding) => row.new_targets.includes(finding.target))) } else { const open = mine.filter( (finding) => @@ -546,7 +557,7 @@ export const auditClis = ( ).length, new_targets: fresh.map((finding) => finding.target), } - const blocks = lintIds.includes(rule) || options.blocks === "new" + const blocks = !WARNING_RULES.has(rule) && (lintIds.includes(rule) || options.blocks === "new") if (blocks) blocking.push(...fresh) } rows.push(row) @@ -567,6 +578,7 @@ export const auditClis = ( ) .filter((finding) => !(lintIds.includes(rule) && selfJudged.has(finding.clis[0] ?? ""))) .map((finding) => finding.target) + if (OVERRIDE_ONLY_RULES.has(rule)) return [rule, []] return [rule, STRICT_CONTRACT_RULES.has(rule) ? kept : [...new Set([...kept, ...now])].sort(byText)] }), ) diff --git a/src/dev/lint.test.ts b/src/dev/lint.test.ts index 90582e1..b076fe3 100644 --- a/src/dev/lint.test.ts +++ b/src/dev/lint.test.ts @@ -47,7 +47,6 @@ const clean = (): Command => { ran(chats.command("show").description("show one chat").argument("", "chat id or name"), { examples: ["tool work chats show 'Kai Sample'"], }) - ran(root.command("doctor").description("check this machine"), { examples: ["tool doctor"] }) const bot = root.command("bot").description("the bot account") ran(bot.command("getMe").description(""), { origin: "generated" }) return root @@ -86,6 +85,8 @@ const failing: Record void> = { 1, ) }, + "reserved-shared-command": (root) => + ran(root.command("doctor").description("check this machine"), { examples: ["tool doctor"] }), "unknown-verb": (root) => ran(chatsOf(root).command("grab").description("grab a chat"), { examples: ["tool chats grab"] }), "unknown-resource": (root) => @@ -441,6 +442,36 @@ describe("lint rules", () => { ]) }) + it("flags a reserved path cli-core did not mount, once per path, and allows a CLI's own child of a shared group", () => { + const root = clean() + const session = root.command("session").description("sign in and out") + for (const [leaf, origin] of [ + ["start", "cli-core"], + ["status", "handwritten"], + ["end", "cli-core"], + ["list", "handwritten"], + ] as const) + ran(session.command(leaf).description(`session ${leaf}`), { examples: [`tool work session ${leaf}`], origin }) + const mcp = ran(root.command("mcp").description("the MCP server"), { examples: ["tool mcp"], origin: "cli-core" }) + ran(mcp.command("serve").description("serve over stdio"), { examples: ["tool work mcp serve"] }) + const account = root.command("account").description("this profile's account") + ran(account.command("remove").description("remove this profile"), { examples: ["tool work account remove"] }) + expect(lintOf(root).filter((one) => one.rule === "reserved-shared-command")).toEqual([ + { + rule: "reserved-shared-command", + target: "account remove", + message: + "account remove built by the CLI. Mount cli-core's `accountRemoveCommand` (or the group from `accountCommand`), or add an override with the reason", + }, + { + rule: "reserved-shared-command", + target: "session", + message: + "session status, session list built by the CLI. Mount cli-core's `tokenSessionCommand`, `oauthSessionCommand` or `messengerSessionCommands`, or add an override with the reason", + }, + ]) + }) + it("passes the guided first run, setup --agent, as tg and wa have it", () => { const root = clean() ran(root.command("setup").description("log in, then install the agent skill").option("--agent ", "x"), { @@ -1053,7 +1084,7 @@ describe("cli-dev lint", () => { it("fails the CLI's own word in the baseline once cli-core marks its commands, and only warns with --allow-stale", async () => { const tree = broken() - annotate(tree.commands.find((command) => command.name() === "doctor") as Command, { origin: "cli-core" }) + annotate(tree.commands.find((command) => command.name() === "runs") as Command, { origin: "cli-core" }) document(tree) expect(await lint("--write-baseline")).toBe(1) expect(err).toContain(`the CLI's own word in the baseline — move it to the overrides: unknown-verb "chats grab"`) @@ -1089,6 +1120,47 @@ describe("cli-dev lint", () => { expect(err.join("\n")).not.toMatch(/^low {2}command-example-count/m) }) + it("only warns about a reserved path built by hand, and takes its exception from the overrides alone", async () => { + document(clean()) + const before = await lint() + const tree = clean() + failing["reserved-shared-command"]?.(tree) + document(tree) + err.length = 0 + expect(await lint()).toBe(before) + expect(err.join("\n")).toMatch(/^warning {2}high {2}reserved-shared-command {2}doctor: doctor built by the CLI/m) + + await lint("--write-baseline") + expect(existsSync(join(root, "lint/baseline/reserved-shared-command.json"))).toBe(false) + mkdirSync(join(root, "lint/baseline"), { recursive: true }) + writeFileSync(join(root, "lint/baseline/reserved-shared-command.json"), JSON.stringify(["doctor"])) + err.length = 0 + expect(await lint()).toBe(1) + expect(err).toContain( + "an exception to reserved-shared-command is in the baseline: move it to the overrides, with its reason and date", + ) + + writeFileSync(join(root, "lint/baseline/reserved-shared-command.json"), "[]") + writeFileSync( + join(root, "lint/overrides.json"), + JSON.stringify([{ rule: "reserved-shared-command", target: "doctor", owner: "@octocat" }]), + ) + err.length = 0 + await lint() + expect(err.join("\n")).toMatch(/entry 0 \(reserved-shared-command\) does not apply/) + expect(err.join("\n")).toMatch(/reserved-shared-command {2}doctor/) + + writeFileSync( + join(root, "lint/overrides.json"), + JSON.stringify([ + { rule: "reserved-shared-command", target: "doctor", reason: "the hub has no account to check", ...KEPT }, + ]), + ) + err.length = 0 + await lint() + expect(err.join("\n")).not.toContain("reserved-shared-command doctor") + }) + it("warns about an override two weeks either side of its review date, then fails, naming who keeps it", async () => { const tree = clean() failing["unknown-verb"]?.(tree) diff --git a/src/dev/lint.ts b/src/dev/lint.ts index 489b6d7..8dd44ca 100644 --- a/src/dev/lint.ts +++ b/src/dev/lint.ts @@ -54,6 +54,32 @@ export const registeredKinds = (vocabulary: Vocabulary): Map = const label = (command: CommandInfo): string => command.path.join(" ") +/** + * WC-CMD-34: root paths only cli-core's shared commands may hold. A group is judged by its own node, so a subcommand a + * CLI adds to a shared group stays allowed; `session` is judged by its four leaves, which a CLI may hold in its own group. + */ +export const RESERVED_COMMANDS: readonly { path: string; leaves?: readonly string[]; helpers: string }[] = [ + { + path: "session", + leaves: ["start", "status", "end", "list"], + helpers: "`tokenSessionCommand`, `oauthSessionCommand` or `messengerSessionCommands`", + }, + { path: "doctor", helpers: "`appDoctorCommand` or `doctorCommand`" }, + { path: "mcp", helpers: "`appMcpCommand` or `mcpCommand`" }, + { path: "account remove", helpers: "`accountRemoveCommand` (or the group from `accountCommand`)" }, + { path: "mirrors", helpers: "`fileMirrorsCommand` or `addDocumentMirrorCommands`" }, + { path: "complete", helpers: "`appCompleteCommand` or `completeCommand`" }, +] + +/** + * Rules in their warning phase: `cli-dev lint` and the audit print them and never fail on them. The rule's page names + * the release that ends the phase. + */ +export const WARNING_RULES: ReadonlySet = new Set(["reserved-shared-command"]) + +/** Rules whose exception must carry a reason and a date: a baseline entry has neither, so it is refused. */ +export const OVERRIDE_ONLY_RULES: ReadonlySet = new Set(["reserved-shared-command"]) + export interface LintContext { /** The commands document as the CLI printed it; parsing drops keys it does not know, so casing is checked here. */ raw?: unknown @@ -516,6 +542,22 @@ const CHECKS: Record = { : []), ] }, + "reserved-shared-command": (document) => { + const at = new Map(walk(document.commands).map((command) => [label(command), command])) + return RESERVED_COMMANDS.flatMap(({ path, leaves, helpers }) => { + const own = (leaves ? leaves.map((leaf) => `${path} ${leaf}`) : [path]).filter( + (one) => at.has(one) && at.get(one)?.origin !== "cli-core", + ) + return own.length === 0 + ? [] + : [ + { + target: path, + message: `${own.join(", ")} built by the CLI. Mount cli-core's ${helpers}, or add an override with the reason`, + }, + ] + }) + }, "raw-network": (_document, _vocabulary, context) => (context.network ? rawNetwork(context.network) : []), "undeclared-host": (_document, _vocabulary, context) => (context.network ? undeclaredHosts(context.network) : []), "result-shape": (_document, _vocabulary, context) => (context.declarations ? resultShape(context.declarations) : []), @@ -599,10 +641,14 @@ export const baselineOf = ( return Object.fromEntries( rules.map((rule) => [ rule.id, - violations - .filter((violation) => violation.rule === rule.id && !overridden.has(`${violation.rule} ${violation.target}`)) - .map((violation) => violation.target) - .sort(), + OVERRIDE_ONLY_RULES.has(rule.id) + ? [] + : violations + .filter( + (violation) => violation.rule === rule.id && !overridden.has(`${violation.rule} ${violation.target}`), + ) + .map((violation) => violation.target) + .sort(), ]), ) } @@ -619,14 +665,18 @@ export const misfiled = ( baseline: Readonly>, overrides: readonly Override[], ): string[] => { + const reasonless = [...OVERRIDE_ONLY_RULES] + .filter((rule) => (baseline[rule] ?? []).length > 0) + .map((rule) => `an exception to ${rule} is in the baseline: move it to the overrides, with its reason and date`) const commands = walk(document.commands).sort((a, b) => b.path.length - a.path.length) - if (!commands.some((command) => command.origin === "cli-core")) return [] + if (!commands.some((command) => command.origin === "cli-core")) return reasonless const ownerOf = (target: string) => commands.find((command) => { const path = label(command) return target === path || target.startsWith(`${path} `) || target.startsWith(`${path}:`) })?.origin return [ + ...reasonless, ...Object.entries(baseline) .filter(([rule]) => WORD_RULES.has(rule)) .flatMap(([rule, targets]) => diff --git a/src/dev/main.ts b/src/dev/main.ts index 8b866a4..02cb400 100644 --- a/src/dev/main.ts +++ b/src/dev/main.ts @@ -55,7 +55,16 @@ import { readCapabilities } from "./capabilities.js" import { CONFORMANCE_USAGE, conformanceCommand } from "./conformance.js" import { familyPackages, installFamily } from "./family.js" import { changelogChange, landChange, landFold, newestTag, processShell, restoreChange } from "./land.js" -import { baselineOf, judge, lintCommands, misfiled, RUN_LOG_COMMANDS, type RunLogProbe, walk } from "./lint.js" +import { + baselineOf, + judge, + lintCommands, + misfiled, + RUN_LOG_COMMANDS, + type RunLogProbe, + WARNING_RULES, + walk, +} from "./lint.js" import { type NetworkContext, readSources } from "./network.js" import { levelCommand, nextVersion } from "./next-version.js" import { READY_USAGE, ready } from "./ready.js" @@ -594,7 +603,7 @@ const lintRun = (args: string[], io: DevIo) => { const verdict = judge(violations, baseline, ruleOverrides, budget) // A low rule is advice: it is printed and never fails, so polishing help text never holds a merge. - const advice = (rule: string) => severity.get(rule) === "low" + const advice = (rule: string) => severity.get(rule) === "low" || WARNING_RULES.has(rule) const advised: string[] = [] for (const id of verdict.unknownRules) problems.push(`no lint rule "${id}" (named in ${values.baseline} or ${values.overrides})`) diff --git a/src/standards/lint.ts b/src/standards/lint.ts index 8ad1bc9..d2e3aa2 100644 --- a/src/standards/lint.ts +++ b/src/standards/lint.ts @@ -156,6 +156,13 @@ export const LINT_RULES: LintRule[] = defineLintRules([ summary: "a list or search in the published TypeScript API returns `{ items, hasMore, nextOffset?, total? }`: no bare array, no `hits` or `has_more`", }, + { + id: "reserved-shared-command", + severity: "high", + scope: "command", + summary: + "`session start|status|end|list`, `doctor`, `mcp`, `account remove`, `mirrors` and `complete` are cli-core's shared commands, never built by the CLI", + }, ]) /**