From 27def291611f0e421afe13590c41ec62fa07ac85 Mon Sep 17 00:00:00 2001 From: leemour Date: Wed, 25 Nov 2026 22:09:01 +0100 Subject: [PATCH 1/2] feat(cli): mark the session and mirrors commands as cli-core's own cli-base's reserved-shared-command lint rule (WC-CMD-34) warns on CLIs that mount tokenSessionCommand, oauthSessionCommand or fileMirrorsCommand, because those were not marked as shared. They now are, so commands --json gives them origin cli-core. A CLI changes them only through their options. No CLI on main edits the returned commands. accountRemoveCommand takes effects. asterisk, beeline, notion and yandex-disk annotate the returned command with LOCAL_WRITE today, which a marked command refuses at startup, so it stays unmarked until they pass effects instead. Co-Authored-By: Claude Opus 5.5 --- api/cli.api.txt | 3 +- changes/feat-mark-shared-session-commands.md | 10 +++++++ src/cli/account-remove.ts | 5 +++- src/cli/documents/file-mirrors.test.ts | 12 ++++++-- src/cli/documents/index.ts | 12 ++++---- src/cli/index.ts | 4 +-- src/cli/oauth-session.test.ts | 29 +++++++++++++++----- src/cli/shared-command-exports.ts | 5 ++++ src/cli/token-session.test.ts | 14 +++++++++- 9 files changed, 74 insertions(+), 20 deletions(-) create mode 100644 changes/feat-mark-shared-session-commands.md diff --git a/api/cli.api.txt b/api/cli.api.txt index 3bc3ff4d2..0a7d42b0b 100644 --- a/api/cli.api.txt +++ b/api/cli.api.txt @@ -23,6 +23,7 @@ AccountRemoveOptions · interface · export interface AccountRemoveOptions { AccountRemoveOptions · interface · provider?: Provider; AccountRemoveOptions · interface · resolveSettings?: (flags: GlobalFlags, options?: ResolveOptions) => Settings; AccountRemoveOptions · interface · ownerHome?: string; +AccountRemoveOptions · interface · effects?: Effects; AccountRemoveOptions · interface · } AccountSecrets · interface · export interface AccountSecrets { AccountSecrets · interface · credentials: CredentialsOptions; @@ -3257,7 +3258,7 @@ tasksCommand · const · export declare const tasksCommand: (messenger: import(" termField · const · export declare const termField: (name: string, type: FieldType, example: string, more?: Pick) => FieldSpec; terminalAsker · const · export declare const terminalAsker: (command: Command) => Asker; timeLimit · const · export declare const timeLimit: (ms: number) => TimeLimit; -tokenSessionCommand · const · export declare const tokenSessionCommand: (options: TokenSessionOptions) => Command; +tokenSessionCommand · const · export declare const tokenSessionCommand: (options: import("./token-session.js").TokenSessionOptions) => import("commander").Command; typedQuery · const · export declare const typedQuery: (words: QueryWords) => string; unfilteredQuery · const · export declare const unfilteredQuery: (entity: string, schema: Parameters[0]) => QueryRegistry; upgradeCommand · const · export declare const upgradeCommand: (app: import("./entry.js").AppIdentity, packageName: string, contextFor: (command: import("commander").Command) => import("./upgrade-command.js").UpgradeContext) => import("commander").Command; diff --git a/changes/feat-mark-shared-session-commands.md b/changes/feat-mark-shared-session-commands.md new file mode 100644 index 000000000..e3c6c8f95 --- /dev/null +++ b/changes/feat-mark-shared-session-commands.md @@ -0,0 +1,10 @@ +### Added + +- **`tokenSessionCommand`, `oauthSessionCommand` and `fileMirrorsCommand` are marked as cli-core's own commands**, + as `appDoctorCommand` is. `commands --json` gives them `origin: "cli-core"`, so the `reserved-shared-command` lint + rule (WC-CMD-34) stops warning on the CLIs that mount them. A CLI changes them only through their options: an + option, a description or an annotation added to the returned command afterwards stops the run with + `contract.unacknowledged-override`. No CLI does that today. +- **`accountRemoveCommand` takes `effects`.** A CLI whose removal reaches no service passes `LOCAL_WRITE` here, + instead of annotating the returned command. asterisk, beeline, notion and yandex-disk annotate it today, so + `accountRemoveCommand` stays unmarked until they pass `effects`. diff --git a/src/cli/account-remove.ts b/src/cli/account-remove.ts index c6ede5c12..bb627764f 100644 --- a/src/cli/account-remove.ts +++ b/src/cli/account-remove.ts @@ -11,6 +11,7 @@ import { saveConfigFile, } from "@wirecat/cli-base" import { annotate } from "@wirecat/cli-base/commands" +import type { Effects } from "@wirecat/cli-base/standards" import { Command } from "commander" import { lockPath, readLock, servingProfiles } from "../background/lock.js" import { alive } from "../background/processes.js" @@ -105,6 +106,8 @@ export interface AccountRemoveOptions { resolveSettings?: (flags: GlobalFlags, options?: ResolveOptions) => Settings /** The owner's own home; unset, the account's from the user database. A test names its sandbox. */ ownerHome?: string + /** A CLI whose removal reaches no service says so here (`LOCAL_WRITE`), not by annotating the command after. */ + effects?: Effects } type Kind = "sign_in" | "keyring" | "config" | "file" | "store" | "unit" | "schedule" @@ -243,7 +246,7 @@ export const accountRemoveCommand = ( ): Command => logsInOrOut( annotate(new Command("remove"), { - effects: REMOTE_WRITE, + effects: options.effects ?? REMOTE_WRITE, mcp: false, output: { entity: "account_removal" }, examples: [ diff --git a/src/cli/documents/file-mirrors.test.ts b/src/cli/documents/file-mirrors.test.ts index ad236e4ad..9d3b09ec0 100644 --- a/src/cli/documents/file-mirrors.test.ts +++ b/src/cli/documents/file-mirrors.test.ts @@ -9,7 +9,9 @@ import type { Expect, FileTarget, RemoteFile } from "../../documents.js" import type { KeyedGuard } from "../../sends/keyed-guard.js" import { outputFor, provide } from "../context.js" import { type Body, renderAnswer } from "../envelope.js" -import { type FileMirrorWrite, fileMirrorsCommand } from "./file-mirrors.js" +import { hasSharedContract } from "../shared-contracts.js" +import type { FileMirrorWrite } from "./file-mirrors.js" +import { fileMirrorsCommand } from "./index.js" const FOLDER = "/Notes" const sha = (text: string | Buffer) => createHash("sha256").update(text).digest("hex") @@ -132,10 +134,16 @@ const setup = (rewrite?: (text: string) => string, env?: NodeJS.ProcessEnv) => { return bodies.at(-1) as Body & { item?: Record; items?: Record[] } } const add = async () => (await run("add", FOLDER, local)).item?.id as string - return { home, state, local, remote, writes, runs, run, add, streams } + return { home, state, local, remote, writes, runs, run, add, streams, program } } describe("fileMirrorsCommand", () => { + it("is cli-core's own mirrors group", () => { + const { program } = setup() + const mirrors = program.commands.find((command) => command.name() === "mirrors") + expect(mirrors && hasSharedContract(mirrors)).toBe(true) + }) + it("marks the files a preview names for a scheduled agent, and leaves the mirror's own folder as it is", async () => { const preview = async (env: NodeJS.ProcessEnv) => { const { local, remote, run, add, streams } = setup(undefined, env) diff --git a/src/cli/documents/index.ts b/src/cli/documents/index.ts index c8cc5c7d8..ff69bdede 100644 --- a/src/cli/documents/index.ts +++ b/src/cli/documents/index.ts @@ -1,6 +1,9 @@ import type { Command } from "commander" +import { honoursDryRun } from "../dry-run-guard.js" +import { sharedCommand } from "../shared-contracts.js" import { addDocumentCatalogCommands, type DocumentCatalogCommands } from "./catalog.js" import { addLocalDocumentCommands, type LocalDocumentCommands } from "./documents.js" +import { fileMirrorsCommand as fileMirrorsCommandDefinition } from "./file-mirrors.js" import { addDocumentFolderCommands, type DocumentFolderCommands } from "./folders.js" import { addDocumentHistoryCommands, type DocumentHistoryCommands } from "./history.js" import { addDocumentKnowledgeCommands, type DocumentKnowledgeCommands } from "./knowledge.js" @@ -33,12 +36,7 @@ export { export { addLocalDocumentCommands, type ImportedDocument, type LocalDocumentCommands } from "./documents.js" export { type FileConflictCommands, type FileConflictConnection, fileConflictsCommand } from "./file-conflicts.js" export { addFileEditCommands, type FileEditCommands } from "./file-edit.js" -export { - type FileMirrorCommands, - type FileMirrorRemote, - type FileMirrorWrite, - fileMirrorsCommand, -} from "./file-mirrors.js" +export type { FileMirrorCommands, FileMirrorRemote, FileMirrorWrite } from "./file-mirrors.js" export { addFileUpdateCommand, type FileUpdateCommands, type FileUpdatePort } from "./file-update.js" export { addDocumentFolderCommands, type DocumentFolderCommands } from "./folders.js" export { @@ -133,3 +131,5 @@ export { documentSourceFromManifest, type ManifestDocumentSource, } from "./manifest/source.js" + +export const fileMirrorsCommand = honoursDryRun(sharedCommand(fileMirrorsCommandDefinition)) diff --git a/src/cli/index.ts b/src/cli/index.ts index 50664fc90..4cd59d04a 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -615,7 +615,6 @@ export { type OAuthSignedIn, oauthFlowOf, oauthPreset, - oauthSessionCommand, } from "./oauth-session.js" export { pagingOf, positiveCount, window, withPaging } from "./paging.js" export { notLocalPaths } from "./path-options.js" @@ -778,6 +777,7 @@ export { metadataCommand, modelCatalogueCommand, modelsCommand, + oauthSessionCommand, pinCommand, pollsCommand, projectsCommand, @@ -805,6 +805,7 @@ export { tasksCommand, tasksStatsCommand, templatesCommand, + tokenSessionCommand, topicsCommand, unpinCommand, upgradeCommand, @@ -829,6 +830,5 @@ export { signedInSite, storageOf, type TokenSessionOptions, - tokenSessionCommand, } from "./token-session.js" export { restartServers, type UpgradeContext } from "./upgrade-command.js" diff --git a/src/cli/oauth-session.test.ts b/src/cli/oauth-session.test.ts index e94d53f6e..61c35b21c 100644 --- a/src/cli/oauth-session.test.ts +++ b/src/cli/oauth-session.test.ts @@ -7,16 +7,12 @@ import { memoryKeyring } from "@wirecat/cli-base/testing" import { type Command, Option } from "commander" import { afterEach, describe, expect, it, vi } from "vitest" import { driveSessionCodec, zoomTokenCodec } from "../oauth/storage.js" -import { - type OAuthSessionOptions, - type OAuthSignedIn, - oauthFlowOf, - oauthPreset, - oauthSessionCommand, -} from "./oauth-session.js" +import { type OAuthSessionOptions, type OAuthSignedIn, oauthFlowOf, oauthPreset } from "./oauth-session.js" import { run } from "./program.js" import type { ServiceApiManifest } from "./service-api-manifest.js" import { settingsFor } from "./settings.js" +import { oauthSessionCommand } from "./shared-command-exports.js" +import { assertSharedContracts, hasSharedContract } from "./shared-contracts.js" const app = { command: "crm", appName: "crm-cli", envPrefix: "CRM", description: "synthetic", version: "1.0.0" } const manifest: ServiceApiManifest = { @@ -404,3 +400,22 @@ describe("oauthSessionCommand for a CLI that kept its own sign-ins", () => { ]) }) }) + +it("is cli-core's own session group, which a CLI changes only through its options", () => { + const session = oauthSessionCommand({ + app, + resolveSettings: settingsFor(app).resolveSettings, + providerId: "crm", + service: "Crm", + startOptions: [new Option("--grant ", "more to ask")], + preset: () => { + throw new Error("not reached") + }, + verify: async () => ({ id: "w", account: {} }), + }) + const start = session.commands.find((command) => command.name() === "start") as Command + expect(hasSharedContract(session) && hasSharedContract(start)).toBe(true) + expect(() => assertSharedContracts(session)).not.toThrow() + start.option("--later ", "added after the factory") + expect(() => assertSharedContracts(session)).toThrow("shared contract changed") +}) diff --git a/src/cli/shared-command-exports.ts b/src/cli/shared-command-exports.ts index c08db6012..bdf377b42 100644 --- a/src/cli/shared-command-exports.ts +++ b/src/cli/shared-command-exports.ts @@ -73,6 +73,7 @@ import { } from "./messenger/tasks-command.js" import { topicsCommand as topicsCommandDefinition } from "./messenger/topics-command.js" import { watchCommand as watchCommandDefinition } from "./messenger/watch-command.js" +import { oauthSessionCommand as oauthSessionCommandDefinition } from "./oauth-session.js" import { runsCommand as runsCommandDefinition } from "./runs/command.js" import { scheduleCommandFor as scheduleCommandForDefinition } from "./schedule/schedule-command.js" import { serviceApiCommand as serviceApiCommandDefinition } from "./service-api.js" @@ -80,6 +81,7 @@ import { setupCommand as setupCommandDefinition } from "./setup-command.js" import { sharedCommand as protectedCommand } from "./shared-contracts.js" import { skillCommand as skillCommandDefinition } from "./skill-command.js" +import { tokenSessionCommand as tokenSessionCommandDefinition } from "./token-session.js" import { upgradeCommand as upgradeCommandDefinition } from "./upgrade-command.js" const sharedCommand: typeof protectedCommand = (factory) => honoursDryRun(protectedCommand(factory)) @@ -101,6 +103,9 @@ export const botMcpCommand = sharedCommand(botMcpCommandDefinition) /** @experimental */ export const botMessagesCommand = sharedCommand(botMessagesCommandDefinition) export const commandsCommand = sharedCommand(commandsCommandDefinition) +export const tokenSessionCommand = sharedCommand(tokenSessionCommandDefinition) +/** @experimental */ +export const oauthSessionCommand = sharedCommand(oauthSessionCommandDefinition) export const configCommand = sharedCommand(configCommandDefinition) export const setupCommand = sharedCommand(setupCommandDefinition) export const guideCommand = sharedCommand(guideCommandDefinition) diff --git a/src/cli/token-session.test.ts b/src/cli/token-session.test.ts index c5a77dde6..ab01dd3e3 100644 --- a/src/cli/token-session.test.ts +++ b/src/cli/token-session.test.ts @@ -11,7 +11,9 @@ import { run } from "./program.js" import { hostsFetch } from "./service-api-call.js" import type { ServiceApiManifest } from "./service-api-manifest.js" import { settingsFor } from "./settings.js" -import { manifestVerify, type TokenSessionOptions, tokenSessionCommand } from "./token-session.js" +import { tokenSessionCommand } from "./shared-command-exports.js" +import { hasSharedContract } from "./shared-contracts.js" +import { manifestVerify, type TokenSessionOptions } from "./token-session.js" const app = { command: "pages", appName: "pages-cli", envPrefix: "PAGES", description: "synthetic", version: "1.0.0" } const roots: string[] = [] @@ -286,3 +288,13 @@ it("shows its guide before the question at a terminal and in the help, never bef expect((await signIn(["personal", "session", "start", "--json"], false)).err).not.toContain("pages.example") expect((await signIn(["personal", "session", "start", "--help"], false)).out).toContain(plain) }) + +it("is cli-core's own session group", () => { + const session = tokenSessionCommand({ + app, + service: "Pages", + resolveSettings: settingsFor(app).resolveSettings, + verify: async () => ({ id: "w", account: {} }), + }) + expect(session.commands.every(hasSharedContract) && hasSharedContract(session)).toBe(true) +}) From aead3277e208986d2b4025fe78a67247bbd63198 Mon Sep 17 00:00:00 2001 From: leemour Date: Wed, 25 Nov 2026 22:37:09 +0100 Subject: [PATCH 2/2] fix(cli): keep tokenSessionCommand's declared type in the API report Co-Authored-By: Claude Opus 5.5 --- api/cli.api.txt | 2 +- src/cli/index.ts | 2 +- src/cli/shared-command-exports.ts | 2 -- src/cli/token-session.test.ts | 4 ++-- src/cli/token-session.ts | 9 ++++++++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/api/cli.api.txt b/api/cli.api.txt index 0a7d42b0b..cb69b7a01 100644 --- a/api/cli.api.txt +++ b/api/cli.api.txt @@ -3258,7 +3258,7 @@ tasksCommand · const · export declare const tasksCommand: (messenger: import(" termField · const · export declare const termField: (name: string, type: FieldType, example: string, more?: Pick) => FieldSpec; terminalAsker · const · export declare const terminalAsker: (command: Command) => Asker; timeLimit · const · export declare const timeLimit: (ms: number) => TimeLimit; -tokenSessionCommand · const · export declare const tokenSessionCommand: (options: import("./token-session.js").TokenSessionOptions) => import("commander").Command; +tokenSessionCommand · const · export declare const tokenSessionCommand: (options: TokenSessionOptions) => Command; typedQuery · const · export declare const typedQuery: (words: QueryWords) => string; unfilteredQuery · const · export declare const unfilteredQuery: (entity: string, schema: Parameters[0]) => QueryRegistry; upgradeCommand · const · export declare const upgradeCommand: (app: import("./entry.js").AppIdentity, packageName: string, contextFor: (command: import("commander").Command) => import("./upgrade-command.js").UpgradeContext) => import("commander").Command; diff --git a/src/cli/index.ts b/src/cli/index.ts index 4cd59d04a..c7e8a1850 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -805,7 +805,6 @@ export { tasksCommand, tasksStatsCommand, templatesCommand, - tokenSessionCommand, topicsCommand, unpinCommand, upgradeCommand, @@ -830,5 +829,6 @@ export { signedInSite, storageOf, type TokenSessionOptions, + tokenSessionCommand, } from "./token-session.js" export { restartServers, type UpgradeContext } from "./upgrade-command.js" diff --git a/src/cli/shared-command-exports.ts b/src/cli/shared-command-exports.ts index bdf377b42..6e506a978 100644 --- a/src/cli/shared-command-exports.ts +++ b/src/cli/shared-command-exports.ts @@ -81,7 +81,6 @@ import { setupCommand as setupCommandDefinition } from "./setup-command.js" import { sharedCommand as protectedCommand } from "./shared-contracts.js" import { skillCommand as skillCommandDefinition } from "./skill-command.js" -import { tokenSessionCommand as tokenSessionCommandDefinition } from "./token-session.js" import { upgradeCommand as upgradeCommandDefinition } from "./upgrade-command.js" const sharedCommand: typeof protectedCommand = (factory) => honoursDryRun(protectedCommand(factory)) @@ -103,7 +102,6 @@ export const botMcpCommand = sharedCommand(botMcpCommandDefinition) /** @experimental */ export const botMessagesCommand = sharedCommand(botMessagesCommandDefinition) export const commandsCommand = sharedCommand(commandsCommandDefinition) -export const tokenSessionCommand = sharedCommand(tokenSessionCommandDefinition) /** @experimental */ export const oauthSessionCommand = sharedCommand(oauthSessionCommandDefinition) export const configCommand = sharedCommand(configCommandDefinition) diff --git a/src/cli/token-session.test.ts b/src/cli/token-session.test.ts index ab01dd3e3..9a519df43 100644 --- a/src/cli/token-session.test.ts +++ b/src/cli/token-session.test.ts @@ -11,9 +11,9 @@ import { run } from "./program.js" import { hostsFetch } from "./service-api-call.js" import type { ServiceApiManifest } from "./service-api-manifest.js" import { settingsFor } from "./settings.js" -import { tokenSessionCommand } from "./shared-command-exports.js" + import { hasSharedContract } from "./shared-contracts.js" -import { manifestVerify, type TokenSessionOptions } from "./token-session.js" +import { manifestVerify, type TokenSessionOptions, tokenSessionCommand } from "./token-session.js" const app = { command: "pages", appName: "pages-cli", envPrefix: "PAGES", description: "synthetic", version: "1.0.0" } const roots: string[] = [] diff --git a/src/cli/token-session.ts b/src/cli/token-session.ts index 8c1f5862b..7b4a780f1 100644 --- a/src/cli/token-session.ts +++ b/src/cli/token-session.ts @@ -10,6 +10,7 @@ import { plainSetupText } from "../setup/plain.js" import { drawsHyperlinks, hyperlink } from "../terminal/hyperlink.js" import { readSecret } from "../terminal/prompt.js" import { baseContext, environmentOf, outputFor, secretInputOf } from "./context.js" +import { honoursDryRun } from "./dry-run-guard.js" import { refuseOffline } from "./early-refusal.js" import { FETCH, LOCAL_READ, LOCAL_WRITE, logsInOrOut, REMOTE_READ, refuseUnderReadOnly } from "./effects.js" import { itemOf, listOf, renderAnswer } from "./envelope.js" @@ -19,6 +20,7 @@ import { ProfileTokenStore, type TokenStorage } from "./profile-token.js" import { serviceApiCall } from "./service-api-call.js" import { type ServiceApiManifest, siteValue } from "./service-api-manifest.js" import type { GlobalFlags, ResolveOptions, Settings } from "./settings.js" +import { sharedCommand } from "./shared-contracts.js" export interface TokenSessionOptions { app: AppIdentity @@ -140,7 +142,7 @@ export const storageOf = (raw: string): TokenStorage => { * `session start | status | end | list` for a service signed in with one token (WC-ACCT-12): the token is asked hidden * or read from stdin, checked with the service, and only then kept in the keyring or a private file. */ -export const tokenSessionCommand = (options: TokenSessionOptions): Command => { +const tokenSessionCommandDefinition = (options: TokenSessionOptions): Command => { const { app, service } = options const word = options.token ?? (options.login ? "password" : "API token") const contextOf = (command: Command) => { @@ -313,6 +315,11 @@ export const tokenSessionCommand = (options: TokenSessionOptions): Command => { .addCommand(list) } +/** cli-core's own command (WC-CMD-34): a CLI changes it only through its options. */ +export const tokenSessionCommand: (options: TokenSessionOptions) => Command = honoursDryRun( + sharedCommand(tokenSessionCommandDefinition), +) + const SITE = "site" /**