@wirecat/cli-core 0.653.0 → 0.654.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,25 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
5
5
  minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
6
6
  shape of this file.
7
7
 
8
+ ## 0.654.0 — 13.11.2026
9
+
10
+ ### Added
11
+
12
+ - **`syncAfterInstallCases` in `/testing`**: a CLI's sync, run as its own tests run it, with no shared config, a
13
+ broken one, a byte-order mark, a folder, an older `setup` shape and the "read only" answer; each must succeed, and
14
+ an optional local-only write must still be refused under "read only". The kit points `WIRECAT_CONFIG_DIR` at a
15
+ folder of its own, so the owner's config cannot hide the failure.
16
+
17
+ ### Fixed
18
+
19
+ - **A fresh install syncs: only the owner's own "read only" answer limits a tool.** A shared config
20
+ (`~/.config/WireCat/config.json`) that is not JSON, starts with a byte-order mark, is a folder or holds a
21
+ `setup` section in an older shape no longer makes every WireCat tool read-only; each profile's permissions apply.
22
+ Before, such a file refused `sync` with "setup's answer keeps every WireCat tool read-only".
23
+ - **Setup's "read only" answer lets a sync run.** A command that only fetches from the service into the local store
24
+ (`fetchesOnly`) is no longer refused by that answer, on the command line, in `--dry-run` previews and over MCP. A
25
+ profile's own `readonly` level still refuses it, and every other write stays refused under the answer.
26
+
8
27
  ## 0.653.0 — 13.11.2026
9
28
 
10
29
  ### Added
@@ -3,7 +3,7 @@ import { CliError } from "@wirecat/cli-base";
3
3
  import { annotate, describeProgram } from "@wirecat/cli-base/commands";
4
4
  import { Command } from "commander";
5
5
  import { environmentOf } from "../context.js";
6
- import { changesAuthorityAt, LOCAL_READ, REMOTE_WRITE, readsOverMcpAt } from "../effects.js";
6
+ import { changesAuthorityAt, fetchesOnlyAt, LOCAL_READ, REMOTE_WRITE, readsOverMcpAt } from "../effects.js";
7
7
  import { itemOf, renderAnswer } from "../envelope.js";
8
8
  import { serverEntry } from "../messenger/mcp-command.js";
9
9
  import { nextStep, rootOf } from "../steps.js";
@@ -38,6 +38,7 @@ export const botMcpCommand = (bot) => {
38
38
  program: { run, commands: describeProgram(rootOf(this)) },
39
39
  authority: changesAuthorityAt(rootOf(this)),
40
40
  fetchOnly: readsOverMcpAt(rootOf(this)),
41
+ fetches: fetchesOnlyAt(rootOf(this)),
41
42
  settings: context.settings,
42
43
  levels: () => bot.resolveSettings(this.optsWithGlobals(), { env: context.env, kind: "bot" }).permissions,
43
44
  env: context.env,
@@ -15,4 +15,6 @@ export interface CommandAvailability {
15
15
  level?: Level;
16
16
  }
17
17
  /** Discovery and execution use the same permission decision. */
18
- export declare const commandAvailability: (info: AvailabilityCommand, levels: Readonly<Record<PermissionKey, Level>>, keyOf?: (path: readonly string[]) => PermissionKey | null | undefined, authority?: (path: readonly string[]) => boolean, readOnly?: boolean, mcp?: boolean, declared?: CommandPermissions) => CommandAvailability;
18
+ export declare const commandAvailability: (info: AvailabilityCommand, levels: Readonly<Record<PermissionKey, Level>>, keyOf?: (path: readonly string[]) => PermissionKey | null | undefined, authority?: (path: readonly string[]) => boolean, readOnly?: boolean, mcp?: boolean, declared?: CommandPermissions,
19
+ /** Whether a command only fetches into the store (`fetchesOnlyAt`): setup's "read only" answer lets it run. */
20
+ fetches?: (path: readonly string[]) => boolean) => CommandAvailability;
@@ -1,11 +1,13 @@
1
1
  import { writes } from "@wirecat/cli-base/standards";
2
- import { AUTHORITY_KEY, authorityAllowed, BOT_API_KEY, botApiAllowed, isBotApi, keyForCommand, levelFor, readKeysForCommand, } from "../sends/permissions.js";
2
+ import { AUTHORITY_KEY, authorityAllowed, BOT_API_KEY, botApiAllowed, CEILING_KEY, isBotApi, keyForCommand, levelFor, readKeysForCommand, } from "../sends/permissions.js";
3
3
  import { changesMessenger } from "./effects.js";
4
4
  /** Discovery and execution use the same permission decision. */
5
- export const commandAvailability = (info, levels, keyOf, authority, readOnly = false, mcp = true, declared) => {
5
+ export const commandAvailability = (info, levels, keyOf, authority, readOnly = false, mcp = true, declared,
6
+ /** Whether a command only fetches into the store (`fetchesOnlyAt`): setup's "read only" answer lets it run. */
7
+ fetches) => {
6
8
  const declaredKey = declared?.keyOf(info.path);
7
9
  const key = declared ? declaredKey : (keyOf?.(info.path) ?? keyForCommand(info.path));
8
- const level = key ? levelFor(levels, key, declared?.defaults).level : "allow";
10
+ const { level, key: named } = key ? levelFor(levels, key, declared?.defaults) : { level: "allow", key: null };
9
11
  const judged = { ...(key ? { permission: key } : {}), level };
10
12
  const blocked = (reason, permission) => ({
11
13
  available: false,
@@ -25,7 +27,7 @@ export const commandAvailability = (info, levels, keyOf, authority, readOnly = f
25
27
  return blocked(`the profile requires ${BOT_API_KEY}: allow`, BOT_API_KEY);
26
28
  if (level === "deny")
27
29
  return blocked(`the profile denies ${key}`);
28
- if (level === "readonly" && writes(info.effects))
30
+ if (level === "readonly" && writes(info.effects) && !(named === CEILING_KEY && fetches?.(info.path) === true))
29
31
  return blocked(`${key} is readonly in this profile`);
30
32
  const denied = (declared ? [] : readKeysForCommand(info.path)).find((read) => levelFor(levels, read).level === "deny");
31
33
  return denied ? blocked(`the profile denies ${denied}`, denied) : { available: true, ...judged };
@@ -30,11 +30,11 @@ export declare const refuseWriteBeforeConnecting: (action: Command, { app, env,
30
30
  }) => void;
31
31
  /**
32
32
  * A command of a CLI that declares its own keys (`commandPermissions`), refused by its key before anything connects:
33
- * `deny` stops it, `readonly` stops a write, and the read-only lock stops a write to the service; a command that
34
- * declares no effects counts as both. `ask` is left to the write guard, which can put the question. A saved or
35
- * `--permission` key that names no command stops every keyed command; housekeeping still runs, so `config unset` can
36
- * remove it. Under the lock a non-messenger CLI still previews a `--dry-run`, which sends nothing (WC-PERM-12); a
37
- * messenger's preview stays refused (SEC-65).
33
+ * `deny` stops it, `readonly` stops a write (setup's "read only" answer still lets a fetch into the store run), and
34
+ * the read-only lock stops a write to the service; a command that declares no effects counts as both. `ask` is left to the write
35
+ * guard, which can put the question. A saved or `--permission` key that names no command stops every keyed command;
36
+ * housekeeping still runs, so `config unset` can remove it. Under the lock a non-messenger CLI still previews a
37
+ * `--dry-run`, which sends nothing (WC-PERM-12); a messenger's preview stays refused (SEC-65).
38
38
  */
39
39
  export declare const refuseByCommandPermissions: (action: Command, permissions: CommandPermissions, { app, env, dryRun, resolve }: {
40
40
  app: AppIdentity;
@@ -8,7 +8,7 @@ import { CEILING_KEY, keyForCommand, levelFor, writeOfKey } from "../sends/permi
8
8
  import { newOperationId } from "../sends/send-id.js";
9
9
  import { commandPathOf } from "./command-contract.js";
10
10
  import { withAgentLevels } from "./context.js";
11
- import { changesMessenger } from "./effects.js";
11
+ import { changesMessenger, fetchesOnly } from "./effects.js";
12
12
  import { refuseUnknownPermissionKeys } from "./permission-keys.js";
13
13
  import { NONE_NAMED, settingsFor } from "./settings.js";
14
14
  /**
@@ -96,11 +96,11 @@ export const refuseWriteBeforeConnecting = (action, { app, env, dryRun, resolve
96
96
  };
97
97
  /**
98
98
  * A command of a CLI that declares its own keys (`commandPermissions`), refused by its key before anything connects:
99
- * `deny` stops it, `readonly` stops a write, and the read-only lock stops a write to the service; a command that
100
- * declares no effects counts as both. `ask` is left to the write guard, which can put the question. A saved or
101
- * `--permission` key that names no command stops every keyed command; housekeeping still runs, so `config unset` can
102
- * remove it. Under the lock a non-messenger CLI still previews a `--dry-run`, which sends nothing (WC-PERM-12); a
103
- * messenger's preview stays refused (SEC-65).
99
+ * `deny` stops it, `readonly` stops a write (setup's "read only" answer still lets a fetch into the store run), and
100
+ * the read-only lock stops a write to the service; a command that declares no effects counts as both. `ask` is left to the write
101
+ * guard, which can put the question. A saved or `--permission` key that names no command stops every keyed command;
102
+ * housekeeping still runs, so `config unset` can remove it. Under the lock a non-messenger CLI still previews a
103
+ * `--dry-run`, which sends nothing (WC-PERM-12); a messenger's preview stays refused (SEC-65).
104
104
  */
105
105
  export const refuseByCommandPermissions = (action, permissions, { app, env, dryRun, resolve }) => {
106
106
  const key = permissions.keyOf(commandPathOf(action));
@@ -126,7 +126,7 @@ export const refuseByCommandPermissions = (action, permissions, { app, env, dryR
126
126
  throw new CliError("permission_error", `profile ${settings.profile} denies ${key} (permissions.${named} is deny, from the ` +
127
127
  `${settings.permissionSources[named ?? ""] ?? "default"})`, { permission: key });
128
128
  }
129
- if (level === "readonly" && writes(effects))
129
+ if (level === "readonly" && writes(effects) && !(named === CEILING_KEY && fetchesOnly(action)))
130
130
  throw levelRefusal({
131
131
  profile: settings.profile,
132
132
  command: app.command,
@@ -1,8 +1,9 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { metaOf } from "@wirecat/cli-base/commands";
3
3
  import { writes as writesAnything } from "@wirecat/cli-base/standards";
4
- import { keyForCommand, levelFor, readKeysForCommand, WRITE_KEYS } from "../sends/permissions.js";
4
+ import { CEILING_KEY, keyForCommand, levelFor, readKeysForCommand, WRITE_KEYS, } from "../sends/permissions.js";
5
5
  import { commandPathOf } from "./command-contract.js";
6
+ import { fetchesOnly } from "./effects.js";
6
7
  import { refuseUnknownPermissionKeys } from "./permission-keys.js";
7
8
  export class PreviewComplete extends Error {
8
9
  }
@@ -13,14 +14,17 @@ export const preview = (command, settings, tool, keys, messenger = true) => {
13
14
  const keyOf = typeof keys === "object" ? keys.keyOf : keys;
14
15
  refuseUnknownPermissionKeys(command, settings, tool, declared ?? (keyOf && ((one) => keyOf(commandPathOf(one)))));
15
16
  const key = declared ? declared.keyOf(path) : (keyOf?.(path) ?? keyForCommand(path));
16
- const level = key ? levelFor(permissions, key, declared?.defaults).level : "allow";
17
+ const { level, key: named } = key
18
+ ? levelFor(permissions, key, declared?.defaults)
19
+ : { level: "allow", key: null };
17
20
  for (const source of declared ? [] : readKeysForCommand(path)) {
18
21
  if (levelFor(permissions, source).level === "deny")
19
22
  throw new CliError("permission_error", `this profile does not permit ${source}`, { permission: source });
20
23
  }
21
24
  const meta = metaOf(command);
22
- const writes = (meta.effects !== undefined && writesAnything(meta.effects)) ||
23
- (!declared && key !== null && key !== undefined && WRITE_KEYS.includes(key));
25
+ const writes = ((meta.effects !== undefined && writesAnything(meta.effects)) ||
26
+ (!declared && key !== null && key !== undefined && WRITE_KEYS.includes(key))) &&
27
+ !(named === CEILING_KEY && fetchesOnly(command));
24
28
  if (level === "deny" || (writes && level === "readonly"))
25
29
  throw new CliError("permission_error", `this profile does not permit ${path.join(" ")}`, { permission: key });
26
30
  const also = (declared?.alsoChecks?.(path) ?? []).map((one) => {
@@ -24,7 +24,7 @@ import { exitCodeSet } from "./command-server-request.js";
24
24
  import { entityRows } from "./compact.js";
25
25
  import { outputFor, provide } from "./context.js";
26
26
  import { refuseByCommandPermissions, refuseOfflineCommand, refuseWriteBeforeConnecting } from "./early-refusal.js";
27
- import { admittedUnderLock, changesAuthorityAt, changesAuthorityNow, fileOptionOf, isLogin, isStoreChange, judgedEffects, judgedTargets, storeChangeRefusal, } from "./effects.js";
27
+ import { admittedUnderLock, changesAuthorityAt, changesAuthorityNow, fetchesOnlyAt, fileOptionOf, isLogin, isStoreChange, judgedEffects, judgedTargets, storeChangeRefusal, } from "./effects.js";
28
28
  import { itemOf, renderAnswer, snakeKeys } from "./envelope.js";
29
29
  import { byteCount, DEFAULT_AGENT_COOPERATIVE_MS, DEFAULT_COMMAND_MS, DEFAULT_COOPERATIVE_MS, DEFAULT_OUTPUT_BYTES, DEFAULT_SYNC_MS, execution, } from "./execution.js";
30
30
  import { setupAtStart } from "./first-run.js";
@@ -277,14 +277,10 @@ const runOnce = async (argv, definition, options) => {
277
277
  return undefined;
278
278
  try {
279
279
  const overrides = options.agent?.overrides ?? [];
280
- const settings = (definition.configuration ?? settingsFor(definition.app)).resolveSettings(overrides.length ? { ...flags, permission: [...overrides, ...(flags.permission ?? [])] } : flags, {
281
- env,
282
- needsProfile: false,
283
- kind: info.path[0] === "bot" || flags.bot ? "bot" : "personal",
284
- });
280
+ const settings = (definition.configuration ?? settingsFor(definition.app)).resolveSettings(overrides.length ? { ...flags, permission: [...overrides, ...(flags.permission ?? [])] } : flags, { env, needsProfile: false, kind: info.path[0] === "bot" || flags.bot ? "bot" : "personal" });
285
281
  if (!settings.permissions)
286
282
  return undefined;
287
- return commandAvailability(info, settings.permissions, definition.configuration?.permissionKey ?? definition.configuration?.permissions?.keyOf, changesAuthorityAt(program), readOnlyLockOf(definition.app, env) !== undefined, options.agent !== undefined, definition.configuration?.permissions);
283
+ return commandAvailability(info, settings.permissions, definition.configuration?.permissionKey ?? definition.configuration?.permissions?.keyOf, changesAuthorityAt(program), readOnlyLockOf(definition.app, env) !== undefined, options.agent !== undefined, definition.configuration?.permissions, fetchesOnlyAt(program));
288
284
  }
289
285
  catch {
290
286
  // Help must still work when the configuration needs repair.
@@ -18,8 +18,9 @@ export declare const unanswered: (answers: SetupAnswers) => Question[];
18
18
  /** A section written wrongly is replaced; a file that is not JSON at all still refuses, naming itself. */
19
19
  export declare const writeSetupAnswers: (path: string, answers: SetupAnswers) => void;
20
20
  /**
21
- * The level no command of any WireCat tool goes above, or `undefined` when the owner chose to leave them as they
22
- * are. A file that cannot be read keeps everything read-only: reads still work, and `setup` writes it again.
21
+ * The level no command of any WireCat tool goes above, or `undefined` when the owner did not choose "read only".
22
+ * Only that explicit answer limits: a missing, unreadable or malformed file leaves every tool as each profile
23
+ * allows, so a fresh install syncs (owner ruling, 2026-11-13).
23
24
  */
24
25
  export declare const permissionCeiling: (path: string) => Level | undefined;
25
26
  /** `permissionCeiling` of this machine's shared config, for a tool that keeps its own levels: add it as `CEILING_KEY`. */
@@ -33,18 +33,17 @@ export const writeSetupAnswers = (path, answers) => {
33
33
  writeSharedSection(path, SECTION, { ...kept, ...answers });
34
34
  };
35
35
  /**
36
- * The level no command of any WireCat tool goes above, or `undefined` when the owner chose to leave them as they
37
- * are. A file that cannot be read keeps everything read-only: reads still work, and `setup` writes it again.
36
+ * The level no command of any WireCat tool goes above, or `undefined` when the owner did not choose "read only".
37
+ * Only that explicit answer limits: a missing, unreadable or malformed file leaves every tool as each profile
38
+ * allows, so a fresh install syncs (owner ruling, 2026-11-13).
38
39
  */
39
40
  export const permissionCeiling = (path) => {
40
- let answer;
41
41
  try {
42
- answer = readSetupAnswers(path).permissions;
42
+ return readSetupAnswers(path).permissions === "readonly" ? "readonly" : undefined;
43
43
  }
44
44
  catch {
45
- return "readonly";
45
+ return undefined;
46
46
  }
47
- return answer === "allow" ? undefined : answer;
48
47
  };
49
48
  /** `permissionCeiling` of this machine's shared config, for a tool that keeps its own levels: add it as `CEILING_KEY`. */
50
49
  export const setupPermissionCeiling = (env = process.env) => permissionCeiling(sharedConfigPath(storePath(env), env));
@@ -6,3 +6,4 @@ export { ownCatalogue } from "./own-catalogue.js";
6
6
  export { neverAnswers, type RunScopeCase, type RunScopeOptions, runScopeCases } from "./run-scope.js";
7
7
  export { type SearchRecipes, searchRecipes, seedSearchRecipes } from "./search-recipes.js";
8
8
  export { BUSY_PAGE, contractSeed, digitIds, type IdKind, type IdMaker, type Seed, wordIds } from "./seed.js";
9
+ export { type SyncAfterInstallCase, type SyncAfterInstallOptions, syncAfterInstallCases } from "./sync-after-install.js";
package/dist/kit/index.js CHANGED
@@ -6,3 +6,4 @@ export { ownCatalogue } from "./own-catalogue.js";
6
6
  export { neverAnswers, runScopeCases } from "./run-scope.js";
7
7
  export { searchRecipes, seedSearchRecipes } from "./search-recipes.js";
8
8
  export { BUSY_PAGE, contractSeed, digitIds, wordIds } from "./seed.js";
9
+ export { syncAfterInstallCases } from "./sync-after-install.js";
@@ -0,0 +1,26 @@
1
+ export interface SyncAfterInstallCase {
2
+ name: string;
3
+ /** Throws an `AssertionError` when the command is refused or fails. */
4
+ run(): Promise<void>;
5
+ }
6
+ export interface SyncAfterInstallOptions {
7
+ /** The words that sync a signed-in profile against the CLI's fake service: `["work", "sync"]`. */
8
+ sync: readonly string[];
9
+ /**
10
+ * Runs the CLI as its own tests do, against its fake service, with `env` laid over the test's environment. A CLI
11
+ * on cli-core's program passes `run(argv, definition, { ...fakes, env: { ...process.env, ...env } })`.
12
+ */
13
+ run: (argv: string[], env: NodeJS.ProcessEnv) => Promise<{
14
+ code: number;
15
+ err: string;
16
+ out?: string;
17
+ }>;
18
+ /** Words of a local-only change that the "read only" answer must still refuse, as a check it opens no more. */
19
+ refusedUnderReadOnly?: readonly string[];
20
+ }
21
+ /**
22
+ * Cases that a CLI's sync runs right after install, whatever state the shared config is in. The kit points
23
+ * `WIRECAT_CONFIG_DIR` at a folder of its own, so the owner's config never hides the failure; the store is the one
24
+ * the CLI's own harness gives.
25
+ */
26
+ export declare const syncAfterInstallCases: (options: SyncAfterInstallOptions) => SyncAfterInstallCase[];
@@ -0,0 +1,72 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ /**
6
+ * The shared config (`~/.config/WireCat/config.json`) as a fresh or damaged machine has it. Only an explicit
7
+ * "read only" answer limits a tool, and even then a sync runs: it only reads the service (owner ruling, 2026-11-13).
8
+ */
9
+ const SHARED_CONFIGS = [
10
+ { state: "no shared config, as on a fresh install" },
11
+ { state: "a shared config that is not JSON", write: (dir) => writeFileSync(join(dir, "config.json"), "{ setup: ") },
12
+ {
13
+ state: "a shared config with a byte-order mark",
14
+ write: (dir) => writeFileSync(join(dir, "config.json"), '{"setup":{"permissions":"allow"}}'),
15
+ },
16
+ { state: "a folder where the shared config should be", write: (dir) => mkdirSync(join(dir, "config.json")) },
17
+ {
18
+ state: "a setup section in a shape this version does not take",
19
+ write: (dir) => writeFileSync(join(dir, "config.json"), JSON.stringify({ setup: { languages: ["en"], permissions: "ask" } })),
20
+ },
21
+ {
22
+ state: 'the explicit "read only" answer',
23
+ write: (dir) => writeFileSync(join(dir, "config.json"), JSON.stringify({ setup: { permissions: "readonly" } })),
24
+ readOnly: true,
25
+ },
26
+ ];
27
+ const errorCodeOf = (text) => {
28
+ try {
29
+ return JSON.parse(text.trim()).error?.code;
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ };
35
+ /**
36
+ * Cases that a CLI's sync runs right after install, whatever state the shared config is in. The kit points
37
+ * `WIRECAT_CONFIG_DIR` at a folder of its own, so the owner's config never hides the failure; the store is the one
38
+ * the CLI's own harness gives.
39
+ */
40
+ export const syncAfterInstallCases = (options) => {
41
+ const { sync, refusedUnderReadOnly } = options;
42
+ const cli = async (argv, shared) => {
43
+ const configDir = mkdtempSync(join(tmpdir(), "sync-after-install-"));
44
+ shared.write?.(configDir);
45
+ const ran = await options.run(argv.includes("--json") ? [...argv] : [...argv, "--json"], {
46
+ WIRECAT_CONFIG_DIR: configDir,
47
+ });
48
+ return { code: ran.code, out: ran.out ?? "", err: ran.err };
49
+ };
50
+ return [
51
+ ...SHARED_CONFIGS.map((shared) => ({
52
+ name: `${sync.join(" ")} runs with ${shared.state}`,
53
+ run: async () => {
54
+ const ran = await cli(sync, shared);
55
+ assert.notEqual(errorCodeOf(ran.err), "permission_error", `sync was refused: ${ran.err}`);
56
+ assert.equal(ran.code, 0, `sync exited ${ran.code}: ${ran.out}${ran.err}`);
57
+ },
58
+ })),
59
+ ...(refusedUnderReadOnly
60
+ ? [
61
+ {
62
+ name: `${refusedUnderReadOnly.join(" ")} is still refused under the explicit "read only" answer`,
63
+ run: async () => {
64
+ const readOnly = SHARED_CONFIGS.find((one) => one.readOnly);
65
+ const ran = await cli(refusedUnderReadOnly, readOnly);
66
+ assert.equal(errorCodeOf(ran.err), "permission_error", `it was not refused: ${ran.out}${ran.err}`);
67
+ },
68
+ },
69
+ ]
70
+ : []),
71
+ ];
72
+ };
@@ -27,6 +27,7 @@ export interface AgentContext {
27
27
  /** A declared CLI's keys and defaults (`configuration.permissions`); in place of `keyOf`. */
28
28
  permissions?: CommandPermissions | undefined;
29
29
  authority?: CatalogueOptions["authority"];
30
+ fetches?: CatalogueOptions["fetches"];
30
31
  /** The server's one open connection. The command borrows it: it cannot close it, and never opens its own. */
31
32
  connection?: () => Promise<MessengerAdapter>;
32
33
  /** What a command reads on stdin, as the field an agent gives it in. */
@@ -74,6 +75,8 @@ export interface CatalogueOptions {
74
75
  authority?: (path: readonly string[]) => boolean;
75
76
  /** Whether a command only fetches into this machine (`fetchesOnlyAt`): offered as a read. Unset, every write stays one. */
76
77
  fetchOnly?: (path: readonly string[]) => boolean;
78
+ /** Whether a command only fetches into the store (`fetchesOnlyAt`): setup's "read only" answer lets it run. */
79
+ fetches?: (path: readonly string[]) => boolean;
77
80
  /** Arguments left out of every tool, by name. */
78
81
  omit?: readonly string[];
79
82
  /** Offer `offline` on commands that read the messenger: answer from the copy on this machine. */
package/dist/mcp/agent.js CHANGED
@@ -148,7 +148,7 @@ const keywordsOf = (examples) => [
148
148
  ...new Set(examples.flatMap((example) => example.split(/\s+/u).filter((word) => word !== "" && !word.startsWith("-")))),
149
149
  ];
150
150
  export const toolsFromCommands = (commands, options = {}) => {
151
- const { root = [], exclude = [], levels, keyOf, authority, readOnly = false, permissions } = options;
151
+ const { root = [], exclude = [], levels, keyOf, authority, readOnly = false, permissions, fetches } = options;
152
152
  return flatten(commands)
153
153
  .filter((info) =>
154
154
  // A group is offered only when it runs on its own; without an action it only prints its help.
@@ -162,9 +162,10 @@ export const toolsFromCommands = (commands, options = {}) => {
162
162
  (!(readOnly && (changesMessenger(info) || authority?.(info.path))) &&
163
163
  (levels === undefined && !(readOnly && permissions)
164
164
  ? true
165
- : commandAvailability(info, levels ?? {}, keyOf, authority, readOnly, true, permissions).available))))
165
+ : commandAvailability(info, levels ?? {}, keyOf, authority, readOnly, true, permissions, fetches)
166
+ .available))))
166
167
  .map((info) => ({
167
- availability: () => commandAvailability(info, options.currentLevels?.() ?? levels ?? {}, keyOf, authority, readOnly, true, permissions),
168
+ availability: () => commandAvailability(info, options.currentLevels?.() ?? levels ?? {}, keyOf, authority, readOnly, true, permissions, fetches),
168
169
  command: info.path.slice(root.length).join(" "),
169
170
  path: info.path,
170
171
  title: info.summary ?? info.description,
@@ -217,7 +218,7 @@ export const runCommandForAgent = async (program, path, input, ctx) => {
217
218
  throw new CliError("validation_error", `"${path.join(" ")}" runs until it is stopped; an agent call must return`);
218
219
  const levels = ctx.levels?.();
219
220
  const availability = (levels || ctx.readOnly || ctx.permissions) &&
220
- commandAvailability(info, levels ?? {}, ctx.keyOf, ctx.authority, ctx.readOnly, true, ctx.permissions);
221
+ commandAvailability(info, levels ?? {}, ctx.keyOf, ctx.authority, ctx.readOnly, true, ctx.permissions, ctx.fetches);
221
222
  if (availability && !availability.available)
222
223
  throw new CliError("permission_error", `${path.join(" ")}: ${availability.reason}`, {
223
224
  sent: false,
@@ -4,7 +4,7 @@ import { CliError, mcpErrorResult } from "@wirecat/cli-base";
4
4
  import { describeProgram } from "@wirecat/cli-base/commands";
5
5
  import { skillResource } from "@wirecat/cli-base/skill";
6
6
  import { environmentOf } from "../cli/context.js";
7
- import { changesAuthorityAt, judgedTargets, readsOverMcpAt } from "../cli/effects.js";
7
+ import { changesAuthorityAt, fetchesOnlyAt, judgedTargets, readsOverMcpAt } from "../cli/effects.js";
8
8
  import { DEFAULT_OUTPUT_BYTES } from "../cli/execution.js";
9
9
  import { rootOf } from "../cli/steps.js";
10
10
  import { mcpUrlOf } from "../http/public-url.js";
@@ -45,6 +45,7 @@ export const createAppServer = (command, context, options) => {
45
45
  const levels = () => options.resolveSettings(flags, { env: context.env }).permissions;
46
46
  const readOnly = () => readOnlyLockOf(app, context.env) !== undefined;
47
47
  const authority = changesAuthorityAt(root);
48
+ const fetches = fetchesOnlyAt(root);
48
49
  const targets = judgedTargets(root);
49
50
  const passed = Object.fromEntries(Object.entries(environment).filter(([key]) => !PER_RUN.has(key)));
50
51
  const tools = toolsFromCommands(program.commands, {
@@ -55,6 +56,7 @@ export const createAppServer = (command, context, options) => {
55
56
  readOnly: readOnly(),
56
57
  authority,
57
58
  fetchOnly: readsOverMcpAt(root),
59
+ fetches,
58
60
  permissions: options.permissions,
59
61
  });
60
62
  const availability = (one) => () => {
@@ -88,6 +90,7 @@ export const createAppServer = (command, context, options) => {
88
90
  levels,
89
91
  overrides,
90
92
  authority,
93
+ fetches,
91
94
  permissions: options.permissions,
92
95
  environment: passed,
93
96
  });
@@ -18,6 +18,8 @@ export interface BotServerOptions {
18
18
  authority?: (path: readonly string[]) => boolean;
19
19
  /** Whether a command only fetches into this machine (`fetchesOnlyAt`): offered through the read tool. */
20
20
  fetchOnly?: (path: readonly string[]) => boolean;
21
+ /** Whether a command only fetches into the store (`fetchesOnlyAt`): setup's "read only" answer lets it run. */
22
+ fetches?: (path: readonly string[]) => boolean;
21
23
  env: NodeJS.ProcessEnv;
22
24
  skill?: URL;
23
25
  }
@@ -34,6 +34,7 @@ export const createBotServer = (options) => {
34
34
  ...(options.keyOf ? { keyOf: options.keyOf } : {}),
35
35
  authority,
36
36
  ...(options.fetchOnly ? { fetchOnly: options.fetchOnly } : {}),
37
+ ...(options.fetches ? { fetches: options.fetches } : {}),
37
38
  offline: true,
38
39
  // Another bot's copy is this bot's to read only where `read_other_bots` says so.
39
40
  ...(settings.readOtherBots ? {} : { omit: ["all_bots", "bots"] }),
@@ -59,6 +60,7 @@ export const createBotServer = (options) => {
59
60
  levels,
60
61
  ...(options.keyOf ? { keyOf: options.keyOf } : {}),
61
62
  authority,
63
+ ...(options.fetches ? { fetches: options.fetches } : {}),
62
64
  ...(caller ? { caller } : {}),
63
65
  }));
64
66
  queue = next.catch(() => undefined);
@@ -8,7 +8,7 @@ import * as v from "valibot";
8
8
  import { findCommand } from "../cli/command-contract.js";
9
9
  import { environmentOf } from "../cli/context.js";
10
10
  import { refuseWriteBeforeConnecting } from "../cli/early-refusal.js";
11
- import { changesAuthorityAt, judgedTargets, readsOverMcpAt } from "../cli/effects.js";
11
+ import { changesAuthorityAt, fetchesOnlyAt, judgedTargets, readsOverMcpAt } from "../cli/effects.js";
12
12
  import { itemOf } from "../cli/envelope.js";
13
13
  import { DEFAULT_OUTPUT_BYTES } from "../cli/execution.js";
14
14
  import { recalledAccount } from "../cli/messenger/accounts.js";
@@ -104,6 +104,7 @@ export const createServer = (command, context, messenger, sessionOptions) => {
104
104
  }
105
105
  };
106
106
  const authority = changesAuthorityAt(root);
107
+ const fetches = fetchesOnlyAt(root);
107
108
  const stdin = (path) => {
108
109
  try {
109
110
  return stdinFieldOf(findCommand(root, path));
@@ -128,6 +129,7 @@ export const createServer = (command, context, messenger, sessionOptions) => {
128
129
  keyOf,
129
130
  authority,
130
131
  fetchOnly: readsOverMcpAt(root),
132
+ fetches,
131
133
  offline: true,
132
134
  stdin,
133
135
  }).map((one) => "sync_first" in one.input.entries && !syncAllowed(one.path)
@@ -219,6 +221,7 @@ export const createServer = (command, context, messenger, sessionOptions) => {
219
221
  overrides,
220
222
  keyOf,
221
223
  authority,
224
+ fetches,
222
225
  stdin,
223
226
  connection,
224
227
  environment: agentEnvironment,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.653.0",
3
+ "version": "0.654.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",