Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions changes/feat-reserved-shared-commands.md
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 1 addition & 1 deletion docs/standards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
3 changes: 2 additions & 1 deletion docs/standards/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions docs/standards/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions src/dev/audit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
`)
})
})
Expand Down
18 changes: 15 additions & 3 deletions src/dev/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) =>
Expand All @@ -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)
Expand All @@ -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)]
}),
)
Expand Down
76 changes: 74 additions & 2 deletions src/dev/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const clean = (): Command => {
ran(chats.command("show").description("show one chat").argument("<chat>", "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
Expand Down Expand Up @@ -86,6 +85,8 @@ const failing: Record<string, (root: Command) => 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) =>
Expand Down Expand Up @@ -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 <agent>", "x"), {
Expand Down Expand Up @@ -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"`)
Expand Down Expand Up @@ -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)
Expand Down
Loading