@wirecat/cli-core 0.641.0 → 0.642.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/analysis/provider.d.ts +1 -1
  3. package/dist/analysis/provider.js +2 -1
  4. package/dist/attachments/gateway-ocr.js +13 -8
  5. package/dist/background/schedules.d.ts +5 -1
  6. package/dist/background/schedules.js +28 -3
  7. package/dist/calendar/mcp/index.d.ts +12 -12
  8. package/dist/cli/ai-model-command.js +6 -3
  9. package/dist/cli/analysis-choice.js +20 -4
  10. package/dist/cli/enrichment-consents-command.js +2 -0
  11. package/dist/cli/local-only-command.d.ts +10 -0
  12. package/dist/cli/local-only-command.js +103 -0
  13. package/dist/cli/messenger/conversations-command.js +1 -1
  14. package/dist/cli/messenger/replies-consents-command.js +12 -6
  15. package/dist/cli/model-catalogue-command.js +2 -0
  16. package/dist/cli/search-harder-consents-command.js +16 -1
  17. package/dist/documents.d.ts +1 -1
  18. package/dist/documents.js +1 -1
  19. package/dist/embeddings/remote.d.ts +2 -1
  20. package/dist/embeddings/remote.js +5 -3
  21. package/dist/errors/reasons.js +8 -0
  22. package/dist/meetings/mcp/index.d.ts +15 -15
  23. package/dist/models/ai.d.ts +16 -3
  24. package/dist/models/ai.js +19 -13
  25. package/dist/models/endpoint.d.ts +5 -0
  26. package/dist/models/endpoint.js +13 -0
  27. package/dist/models/index.d.ts +4 -0
  28. package/dist/models/index.js +9 -1
  29. package/dist/models/local-only.d.ts +17 -0
  30. package/dist/models/local-only.js +42 -0
  31. package/dist/models/purpose.d.ts +24 -0
  32. package/dist/models/purpose.js +26 -0
  33. package/dist/replies/rendering.js +10 -10
  34. package/dist/services/embeddings-maintenance.js +4 -1
  35. package/dist/services/enrichment.d.ts +1 -1
  36. package/dist/services/enrichment.js +27 -0
  37. package/dist/services/meeting-model.js +1 -1
  38. package/dist/services/search-harder.d.ts +11 -1
  39. package/dist/services/search-harder.js +38 -5
  40. package/dist/speech/openai.js +2 -0
  41. package/dist/speech/transcribe.d.ts +5 -2
  42. package/dist/speech/transcribe.js +14 -5
  43. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,36 @@ 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.642.0 — 11.11.2026
9
+
10
+ ### Added
11
+
12
+ - **Local only: one switch that keeps every model call on this computer.** `models local-only set on|off` and
13
+ `models local-only show` (in memo): with it on, the model gateway, remote embeddings and OpenAI transcription refuse
14
+ any address that is not `localhost`, `127.x.x.x` or `[::1]` before anything is sent (`local-only.refused`), and the
15
+ setting commands refuse to save one. `show` lists each feature, where its data goes and whether it is refused. Off by
16
+ default; only the owner turns it off. See
17
+ [ai-providers.md, "Local only"](docs/search/ai-providers.md#local-only).
18
+ - **Linking, reply drafts and attachment OCR use the shared AI model** when `models.analysis`, `models.replies` or
19
+ `models.ocr` are not set (`off` stays off), with the key kept for its address (`purposeModel`, `sharedModel`).
20
+ - **`models search-consents set --timeout <duration>`.** Search harder waits 60 s for a model on this computer and 5 s
21
+ for a hosted one unless the owner sets the limit; `show` gives `timeout_s`.
22
+
23
+ ### Changed — may break callers
24
+
25
+ - **Plain http is allowed only to this computer,, for every model call.** Enrichment, search harder,
26
+ linking, reply drafts, attachment OCR and remote embeddings refused nothing but credentials in the address, so a
27
+ `http://` address on another machine sent records across the network unencrypted. They now refuse it, as `models ai`
28
+ already did (`model.address-refused`); use https, or run the model on this computer. A saved setting with such an
29
+ address still reads, and its feature says why it sends nothing.
30
+ - **Voice messages are heard by the downloaded model first.** `auto` asked the messenger's speech service first; it now
31
+ uses the local model when it is downloaded and asks the messenger only when it is not, and never under local only.
32
+ - **An OpenAI-compatible server on this computer needs no key** in `models ai`; one may still be stored for it.
33
+
34
+ ### Fixed
35
+
36
+ - **A daily or one-off schedule sits out a wait the provider asked for.** A timer run that failed with `rate_limited` and a `retry.after_ms` failed for the day. `schedule exec` now waits that long, if it is at most six hours, and runs once more; `last.json` keeps the wait as `retryAfterMs`. A run by hand and a schedule that repeats still fail at once.
37
+
8
38
  ## 0.641.0 — 11.11.2026
9
39
 
10
40
  ### Added
@@ -10,4 +10,4 @@ export interface AnalysisResponse {
10
10
  }
11
11
  export type AnalysisRequest = (system: string, input: string, maxTokens: number) => Promise<AnalysisResponse>;
12
12
  export declare const providerIdentity: (target: AnalysisProvider) => string;
13
- export declare const openAnalysis: (target: AnalysisProvider, signal?: AbortSignal) => AnalysisRequest;
13
+ export declare const openAnalysis: (target: AnalysisProvider, signal?: AbortSignal, env?: NodeJS.ProcessEnv) => AnalysisRequest;
@@ -2,11 +2,12 @@ import { CliError } from "@wirecat/cli-base";
2
2
  import { modelGateway } from "../models/index.js";
3
3
  import { endpoint } from "./settings.js";
4
4
  export const providerIdentity = (target) => `${target.provider}:${target.baseUrl.replace(/\/+$/, "")}`;
5
- export const openAnalysis = (target, signal) => {
5
+ export const openAnalysis = (target, signal, env) => {
6
6
  if (!endpoint(target.baseUrl))
7
7
  throw new CliError("validation_error", "invalid analysis endpoint");
8
8
  const gateway = modelGateway({
9
9
  signal,
10
+ ...(env ? { env } : {}),
10
11
  resolve: () => target,
11
12
  key: () => target.apiKey,
12
13
  // The analysis command checks per-chat consent before each batch.
@@ -1,14 +1,19 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { CliError } from "@wirecat/cli-base";
3
- import { embeddingKeys, endpointKeyName } from "../embeddings/keys.js";
4
- import { modelGateway, modelTarget } from "../models/index.js";
3
+ import { aiImagesAllowed, aiLeavesComputer } from "../models/ai.js";
4
+ import { modelGateway } from "../models/index.js";
5
+ import { purposeModel } from "../models/purpose.js";
5
6
  export const gatewayOcr = ({ app, settings, env, keyring, enabled, signal, fetch, key, }) => {
6
7
  if (!enabled)
7
8
  throw new CliError("permission_error", "API OCR needs an explicit OCR request");
8
- const target = modelTarget(settings, "ocr");
9
- if (!target || target.provider === "off")
10
- throw new CliError("configuration_error", "set models.ocr.provider and models.ocr.model before API OCR");
11
- const baseUrl = target.baseUrl ?? (target.provider === "anthropic" ? "https://api.anthropic.com" : "https://api.openai.com/v1");
9
+ const chosen = purposeModel(settings, "ocr", { app, env, keyring });
10
+ if (!chosen)
11
+ throw new CliError("configuration_error", "set models.ocr.provider and models.ocr.model, or choose an AI model with `models ai set`, before API OCR");
12
+ // The shared model's yes to pictures was given for it alone, at its address; a model elsewhere needs it here too.
13
+ if (chosen.shared && aiLeavesComputer(chosen.shared) && !aiImagesAllowed(chosen.shared))
14
+ throw new CliError("permission_error", "the AI model may not read pictures: allow it with `models ai set … --allow-remote`; nothing was sent", { reason: "ai.images-not-allowed" });
15
+ const { target } = chosen;
16
+ const { baseUrl } = target;
12
17
  const identity = createHash("sha256")
13
18
  .update(JSON.stringify([target.provider, target.model, baseUrl.replace(/\/+$/, "")]))
14
19
  .digest("hex")
@@ -16,8 +21,8 @@ export const gatewayOcr = ({ app, settings, env, keyring, enabled, signal, fetch
16
21
  const gateway = modelGateway({
17
22
  resolve: () => target,
18
23
  consent: () => enabled,
19
- key: key ??
20
- ((provider, selected) => embeddingKeys(app, env, keyring).read(selected.baseUrl === undefined ? provider : endpointKeyName(selected.baseUrl))?.key),
24
+ key: key ?? chosen.key,
25
+ env,
21
26
  ...(signal === undefined ? {} : { signal }),
22
27
  ...(fetch === undefined ? {} : { fetch }),
23
28
  });
@@ -69,6 +69,8 @@ export interface LastRun {
69
69
  reason?: string;
70
70
  /** The `code` of the error the run printed, as run records keep it. */
71
71
  errorCode?: string;
72
+ /** How long the CLI asked to wait before it is tried again (`retry.after_ms` of a `rate_limited` error). */
73
+ retryAfterMs?: number;
72
74
  /** The first failure of the failures in a row, so "failing since" survives every retry. */
73
75
  failingSince?: string;
74
76
  /** Failed runs in a row; absent once a run succeeds. */
@@ -104,6 +106,7 @@ export type SkipReason = (typeof SKIP_REASONS)[keyof typeof SKIP_REASONS];
104
106
  export declare const failureOf: (stderr: string, exitCode: number) => {
105
107
  reason: string;
106
108
  errorCode?: string;
109
+ retryAfterMs?: number;
107
110
  };
108
111
  /** The one-line reason `failureOf` keeps, for a timer that reads a run's stderr itself. */
109
112
  export declare const reasonOf: (stderr: string, exitCode?: number) => string;
@@ -162,7 +165,8 @@ export declare const CREDENTIALS_UNREACHABLE = "credentials.unreachable";
162
165
  *
163
166
  * `untilUnlocked` is for the timer's run: a timer that catches up at boot runs before the login unlocks the
164
167
  * keyring, so a run that fails for that reason is tried again, a minute then up to 15 minutes apart, for up to
165
- * 12 hours. A schedule that repeats every few minutes is left to its next tick; a run by hand fails at once.
168
+ * 12 hours. A run the provider asked to wait (`rate_limited` with `retry.after_ms`, up to 6 hours) waits that long
169
+ * and runs once more. A schedule that repeats every few minutes is left to its next tick; a run by hand fails at once.
166
170
  */
167
171
  export declare const runSchedule: (app: AppIdentity, system: ServerSystem, env: NodeJS.ProcessEnv, file: string, { now, timer, signal, killAfterMs, untilUnlocked, wait, agentRuns, agentInput, ownerLanguage, reportTemplates, skipRepeatedInput, routes: chosen, }?: {
168
172
  now?: () => Date;
@@ -82,9 +82,15 @@ const REASON_ID = /^[a-z0-9][a-z0-9.-]{0,79}$/;
82
82
  export const failureOf = (stderr, exitCode) => {
83
83
  for (const line of stderr.split("\n").reverse()) {
84
84
  try {
85
- const { code, reason } = JSON.parse(line).error ?? {};
85
+ const { code, reason, retry } = JSON.parse(line).error ??
86
+ {};
86
87
  if (errorCodes.includes(code) && typeof reason === "string" && REASON_ID.test(reason)) {
87
- return { reason: `${code} (${reason})`, errorCode: code };
88
+ const after = retry?.after_ms;
89
+ return {
90
+ reason: `${code} (${reason})`,
91
+ errorCode: code,
92
+ ...(code === "rate_limited" && typeof after === "number" && after > 0 ? { retryAfterMs: after } : {}),
93
+ };
88
94
  }
89
95
  }
90
96
  catch { }
@@ -282,6 +288,9 @@ const LOCKED_FIRST_WAIT_MS = 60_000;
282
288
  const LOCKED_LONGEST_WAIT_MS = 15 * 60_000;
283
289
  /** A night's catch-up waits for the morning's login; past that the run fails as it is. */
284
290
  const LOCKED_GIVE_UP_MS = 12 * 60 * 60_000;
291
+ /** A wait the provider asked for that a daily run sits out and then runs once more; a longer one fails for the day. */
292
+ const RATE_LIMITED_WAIT_AT_MOST_MS = 6 * 60 * 60_000;
293
+ const RATE_LIMITED_MARGIN_MS = 30_000;
285
294
  const lockedOut = (last) => last.reason?.endsWith(`(${CREDENTIALS_UNREACHABLE})`) === true;
286
295
  const pause = (ms, signal) => new Promise((resolve) => {
287
296
  if (signal?.aborted)
@@ -301,7 +310,8 @@ const pause = (ms, signal) => new Promise((resolve) => {
301
310
  *
302
311
  * `untilUnlocked` is for the timer's run: a timer that catches up at boot runs before the login unlocks the
303
312
  * keyring, so a run that fails for that reason is tried again, a minute then up to 15 minutes apart, for up to
304
- * 12 hours. A schedule that repeats every few minutes is left to its next tick; a run by hand fails at once.
313
+ * 12 hours. A run the provider asked to wait (`rate_limited` with `retry.after_ms`, up to 6 hours) waits that long
314
+ * and runs once more. A schedule that repeats every few minutes is left to its next tick; a run by hand fails at once.
305
315
  */
306
316
  export const runSchedule = async (app, system, env, file, { now = () => new Date(), timer, signal, killAfterMs = KILL_AFTER_MS, untilUnlocked = false, wait = pause, agentRuns = [], agentInput, ownerLanguage = async () => "ru", reportTemplates, skipRepeatedInput = false, routes: chosen, } = {}) => {
307
317
  const schedule = readSchedule(file);
@@ -339,6 +349,21 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
339
349
  break;
340
350
  last = again;
341
351
  }
352
+ const asked = last.errorCode === "rate_limited" ? last.retryAfterMs : undefined;
353
+ if (retries && asked !== undefined && asked <= RATE_LIMITED_WAIT_AT_MOST_MS && !signal?.aborted) {
354
+ await wait(asked + RATE_LIMITED_MARGIN_MS, signal);
355
+ if (!signal?.aborted) {
356
+ const again = await attemptSchedule(app, system, env, schedule, folder, {
357
+ now,
358
+ signal,
359
+ killAfterMs,
360
+ agentRuns,
361
+ agentInput,
362
+ });
363
+ if (!("repeated" in again))
364
+ last = again;
365
+ }
366
+ }
342
367
  const { exitCode, output } = last;
343
368
  const errors = agent ? output.replace(/\.md$/, ".log") : output;
344
369
  if (agent && exitCode === 0)
@@ -10,13 +10,13 @@ export declare const calendarTools: ({
10
10
  inputSchema: {
11
11
  type: string;
12
12
  properties: {
13
- limit?: undefined;
14
13
  account_id: {
15
14
  type: string;
16
15
  minimum: number;
17
16
  };
18
17
  query?: undefined;
19
18
  timezone?: undefined;
19
+ limit?: undefined;
20
20
  page?: undefined;
21
21
  event?: undefined;
22
22
  } | {
@@ -45,9 +45,9 @@ export declare const calendarTools: ({
45
45
  };
46
46
  event?: undefined;
47
47
  } | {
48
- limit?: undefined;
49
48
  query?: undefined;
50
49
  timezone?: undefined;
50
+ limit?: undefined;
51
51
  page?: undefined;
52
52
  event: {
53
53
  type: string;
@@ -58,9 +58,9 @@ export declare const calendarTools: ({
58
58
  minimum: number;
59
59
  };
60
60
  } | {
61
- limit?: undefined;
62
61
  query?: undefined;
63
62
  timezone?: undefined;
63
+ limit?: undefined;
64
64
  page?: undefined;
65
65
  event?: undefined;
66
66
  account_id?: undefined;
@@ -80,13 +80,13 @@ export declare const calendarTools: ({
80
80
  inputSchema: {
81
81
  type: string;
82
82
  properties: {
83
- limit?: undefined;
84
83
  account_id: {
85
84
  type: string;
86
85
  minimum: number;
87
86
  };
88
87
  query?: undefined;
89
88
  timezone?: undefined;
89
+ limit?: undefined;
90
90
  page?: undefined;
91
91
  event?: undefined;
92
92
  } | {
@@ -115,9 +115,9 @@ export declare const calendarTools: ({
115
115
  };
116
116
  event?: undefined;
117
117
  } | {
118
- limit?: undefined;
119
118
  query?: undefined;
120
119
  timezone?: undefined;
120
+ limit?: undefined;
121
121
  page?: undefined;
122
122
  event: {
123
123
  type: string;
@@ -128,9 +128,9 @@ export declare const calendarTools: ({
128
128
  minimum: number;
129
129
  };
130
130
  } | {
131
- limit?: undefined;
132
131
  query?: undefined;
133
132
  timezone?: undefined;
133
+ limit?: undefined;
134
134
  page?: undefined;
135
135
  event?: undefined;
136
136
  account_id?: undefined;
@@ -150,13 +150,13 @@ export declare const calendarTools: ({
150
150
  inputSchema: {
151
151
  type: string;
152
152
  properties: {
153
- limit?: undefined;
154
153
  account_id: {
155
154
  type: string;
156
155
  minimum: number;
157
156
  };
158
157
  query?: undefined;
159
158
  timezone?: undefined;
159
+ limit?: undefined;
160
160
  page?: undefined;
161
161
  event?: undefined;
162
162
  } | {
@@ -185,9 +185,9 @@ export declare const calendarTools: ({
185
185
  };
186
186
  event?: undefined;
187
187
  } | {
188
- limit?: undefined;
189
188
  query?: undefined;
190
189
  timezone?: undefined;
190
+ limit?: undefined;
191
191
  page?: undefined;
192
192
  event: {
193
193
  type: string;
@@ -198,9 +198,9 @@ export declare const calendarTools: ({
198
198
  minimum: number;
199
199
  };
200
200
  } | {
201
- limit?: undefined;
202
201
  query?: undefined;
203
202
  timezone?: undefined;
203
+ limit?: undefined;
204
204
  page?: undefined;
205
205
  event?: undefined;
206
206
  account_id?: undefined;
@@ -220,13 +220,13 @@ export declare const calendarTools: ({
220
220
  inputSchema: {
221
221
  type: string;
222
222
  properties: {
223
- limit?: undefined;
224
223
  account_id: {
225
224
  type: string;
226
225
  minimum: number;
227
226
  };
228
227
  query?: undefined;
229
228
  timezone?: undefined;
229
+ limit?: undefined;
230
230
  page?: undefined;
231
231
  event?: undefined;
232
232
  } | {
@@ -255,9 +255,9 @@ export declare const calendarTools: ({
255
255
  };
256
256
  event?: undefined;
257
257
  } | {
258
- limit?: undefined;
259
258
  query?: undefined;
260
259
  timezone?: undefined;
260
+ limit?: undefined;
261
261
  page?: undefined;
262
262
  event: {
263
263
  type: string;
@@ -268,9 +268,9 @@ export declare const calendarTools: ({
268
268
  minimum: number;
269
269
  };
270
270
  } | {
271
- limit?: undefined;
272
271
  query?: undefined;
273
272
  timezone?: undefined;
273
+ limit?: undefined;
274
274
  page?: undefined;
275
275
  event?: undefined;
276
276
  account_id?: undefined;
@@ -1,7 +1,8 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { annotate } from "@wirecat/cli-base/commands";
3
3
  import { Command } from "commander";
4
- import { AI_PROVIDERS, aiBaseUrl, aiImagesAllowed, aiKeys, aiNeedsKey, aiOrigin, aiSettingOf, aiSettingPath, checkAi, readAiSetting, writeAiSetting, } from "../models/ai.js";
4
+ import { AI_PROVIDERS, aiBaseUrl, aiImagesAllowed, aiKeys, aiLeavesComputer, aiOrigin, aiSettingOf, aiSettingPath, aiTakesKey, checkAi, readAiSetting, writeAiSetting, } from "../models/ai.js";
5
+ import { localOnly, localOnlyRefusal } from "../models/local-only.js";
5
6
  import { agentOf } from "../runs/run-context.js";
6
7
  import { readSecret } from "../terminal/prompt.js";
7
8
  import { environmentOf } from "./context.js";
@@ -19,7 +20,7 @@ const view = (app, options, setting) => {
19
20
  images: false,
20
21
  key: { stored: false, source: null },
21
22
  };
22
- const key = aiNeedsKey(setting) ? aiKeys(app, options.env(), options.keyring).read(aiOrigin(setting)) : undefined;
23
+ const key = aiTakesKey(setting) ? aiKeys(app, options.env(), options.keyring).read(aiOrigin(setting)) : undefined;
23
24
  return {
24
25
  provider: setting.provider,
25
26
  model: setting.model,
@@ -90,8 +91,10 @@ export const aiModelCommand = (app, options) => {
90
91
  baseUrl: given.baseUrl,
91
92
  allowImages: given.allowRemote,
92
93
  });
94
+ if (aiLeavesComputer(setting) && localOnly(env))
95
+ throw localOnlyRefusal("what WireCat sends to its AI model", new URL(aiBaseUrl(setting)).host);
93
96
  if (given.secretStdin) {
94
- if (!aiNeedsKey(setting))
97
+ if (!aiTakesKey(setting))
95
98
  throw new CliError("validation_error", "Ollama on this computer takes no key");
96
99
  const input = options.stdin?.();
97
100
  const secret = (await readSecret("API key: ", input ? { input } : {})).trim();
@@ -1,6 +1,7 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
- import { endpoint } from "../analysis/settings.js";
3
2
  import { embeddingKeys, endpointKeyName } from "../embeddings/keys.js";
3
+ import { sharedModel } from "../models/ai.js";
4
+ import { refuseModelAddress } from "../models/local-only.js";
4
5
  export const analysisChoice = (options, app, settings, env, keyring) => {
5
6
  const configured = { ...settings.models?.default, ...settings.models?.analysis };
6
7
  // `off` and no provider both leave the linking to the agent.
@@ -8,8 +9,24 @@ export const analysisChoice = (options, app, settings, env, keyring) => {
8
9
  const override = (options.analysisProvider !== undefined && options.analysisProvider !== saved) ||
9
10
  (options.baseUrl !== undefined && options.baseUrl.replace(/\/+$/, "") !== configured.base_url?.replace(/\/+$/, ""));
10
11
  const provider = options.analysisProvider ?? (saved !== "agent" ? saved : options.baseUrl ? "openai" : "agent");
12
+ // Nothing configured for linking (not `off`): the AI model the owner chose for every tool.
13
+ const shared = provider === "agent" && configured.provider === undefined && options.analysisProvider === undefined
14
+ ? sharedModel({ app, env, keyring })
15
+ : undefined;
16
+ if (shared) {
17
+ const { target, key } = shared;
18
+ refuseModelAddress(env, target.baseUrl, "chat messages");
19
+ if (target.provider !== "openai" && target.provider !== "anthropic")
20
+ throw new CliError("validation_error", "analysis provider must be agent, openai or anthropic");
21
+ return {
22
+ provider: target.provider,
23
+ model: options.model ?? target.model,
24
+ baseUrl: target.baseUrl,
25
+ ...(key ? { apiKey: key } : {}),
26
+ };
27
+ }
11
28
  if (provider === "agent")
12
- throw new CliError("validation_error", "models.analysis.provider is off or not set, so the agent links the chat: use your linking skill, or set it to openai or anthropic to use --analyze");
29
+ throw new CliError("validation_error", "models.analysis.provider is off or not set and no AI model is chosen, so the agent links the chat: use your linking skill, choose a model with `memo models ai set`, or set models.analysis.provider to openai or anthropic to use --analyze");
13
30
  if (provider !== "openai" && provider !== "anthropic")
14
31
  throw new CliError("validation_error", "analysis provider must be agent, openai or anthropic");
15
32
  const model = options.model ?? (override ? undefined : configured.model);
@@ -17,8 +34,7 @@ export const analysisChoice = (options, app, settings, env, keyring) => {
17
34
  throw new CliError("validation_error", "set models.analysis.model or give --model before --analyze");
18
35
  const customUrl = options.baseUrl ?? (override ? undefined : configured.base_url);
19
36
  const baseUrl = customUrl ?? (provider === "anthropic" ? "https://api.anthropic.com" : "https://api.openai.com/v1");
20
- if (!endpoint(baseUrl))
21
- throw new CliError("validation_error", "use an HTTP/S analysis endpoint without credentials, query or fragment");
37
+ refuseModelAddress(env, baseUrl, "chat messages");
22
38
  const keyName = customUrl === undefined ? provider : endpointKeyName(baseUrl);
23
39
  const apiKey = embeddingKeys(app, env, keyring).read(keyName)?.key;
24
40
  if (!apiKey && customUrl === undefined)
@@ -1,6 +1,7 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { annotate } from "@wirecat/cli-base/commands";
3
3
  import { Command } from "commander";
4
+ import { refuseModelAddress } from "../models/local-only.js";
4
5
  import { agentOf } from "../runs/run-context.js";
5
6
  import { enrichmentState } from "../services/enrichment.js";
6
7
  import { ENRICHMENT_PROVIDERS, enrichmentEndpoint, isEnrichmentProvider, readEnrichmentSetting, writeEnrichmentSetting, } from "../services/enrichment-setting.js";
@@ -65,6 +66,7 @@ export const enrichmentConsentsCommand = (app, options) => {
65
66
  model: given.model,
66
67
  ...(given.baseUrl === undefined ? {} : { base_url: given.baseUrl }),
67
68
  };
69
+ refuseModelAddress(env, enrichmentEndpoint(chosen), "records to enrich");
68
70
  const state = await withStore(env, (store) => enrichmentState(store, env, chosen, { app, ...(options.keyring ? { keyring: options.keyring } : {}) }));
69
71
  const consent = consentWording(app.command, state);
70
72
  if (!given.yes) {
@@ -0,0 +1,10 @@
1
+ import { Command } from "commander";
2
+ import type { AppIdentity } from "../ports/app.js";
3
+ import { type Body } from "./envelope.js";
4
+ export interface LocalOnlyCommandOptions {
5
+ env: () => NodeJS.ProcessEnv;
6
+ output: (answer: Body, command: Command) => void;
7
+ diagnostic: (line: string) => void;
8
+ }
9
+ /** `models local-only`: one switch that keeps every model call on this computer, and where each feature sends data. */
10
+ export declare const localOnlyCommand: (app: AppIdentity, options: LocalOnlyCommandOptions) => Command;
@@ -0,0 +1,103 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { annotate } from "@wirecat/cli-base/commands";
3
+ import { Command } from "commander";
4
+ import { chosenTextModel } from "../embeddings/models.js";
5
+ import { aiBaseUrl, aiLeavesComputer, aiSettingPath, readAiSetting } from "../models/ai.js";
6
+ import { onThisComputer } from "../models/endpoint.js";
7
+ import { readLocalOnly, writeLocalOnly } from "../models/local-only.js";
8
+ import { agentOf } from "../runs/run-context.js";
9
+ import { enrichmentEndpoint, readEnrichmentSetting } from "../services/enrichment-setting.js";
10
+ import { readHarderSetting } from "../services/search-harder.js";
11
+ import { environmentOf } from "./context.js";
12
+ import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "./effects.js";
13
+ import { itemOf } from "./envelope.js";
14
+ const placeOf = (address) => (onThisComputer(address) ? "this-computer" : "elsewhere");
15
+ const read = (get) => {
16
+ try {
17
+ return get();
18
+ }
19
+ catch {
20
+ return undefined;
21
+ }
22
+ };
23
+ const features = (command, env, on) => {
24
+ const ai = read(() => readAiSetting(aiSettingPath(env)));
25
+ const aiAddress = ai ? aiBaseUrl(ai) : null;
26
+ const aiWhere = ai ? (aiLeavesComputer(ai) ? "elsewhere" : "this-computer") : "off";
27
+ const enrichment = read(() => readEnrichmentSetting(env));
28
+ const enrichmentAddress = enrichment ? enrichmentEndpoint(enrichment) : null;
29
+ const harder = read(() => readHarderSetting(env));
30
+ const harderAddress = harder ? enrichmentEndpoint(harder) : null;
31
+ const blocked = (where) => on && where === "elsewhere";
32
+ const one = (id, title, where, address, note) => ({
33
+ id,
34
+ title,
35
+ where,
36
+ address,
37
+ refused: blocked(where),
38
+ note,
39
+ });
40
+ return [
41
+ one("ai_model", "AI model", aiWhere, aiAddress, `\`${command} models ai set\` chooses it`),
42
+ one("enrichment", "Rewrite records for better search", enrichmentAddress ? placeOf(enrichmentAddress) : "off", enrichmentAddress, `\`${command} models consents\``),
43
+ one("search_harder", "Search harder", harderAddress ? placeOf(harderAddress) : "off", harderAddress, `\`${command} models search-consents\``),
44
+ one("search_by_meaning", "Search by meaning and picture search", "this-computer", null, `the text model ${chosenTextModel(env).id}; a profile that sets embeddingProvider openai sends text out`),
45
+ ...[
46
+ ["chat_linking", "Chat linking (--analyze)", "analysis"],
47
+ ["replies", "Reply drafts", "replies"],
48
+ ["attachment_ocr", "Picture text in attachments (--ocr)", "ocr"],
49
+ ].map(([id, title, purpose]) => one(id, title, aiWhere, aiAddress, `the AI model, unless a messenger profile sets models.${purpose}; that address is checked when it is called`)),
50
+ one("voice_messages", "Voice messages", on ? "this-computer" : "elsewhere", null, on
51
+ ? "the downloaded speech model only"
52
+ : "the downloaded speech model first, else the messenger's own service; OpenAI only when asked by name"),
53
+ one("digest", "Digest", "agent", null, "runs Claude Code or Codex: local only if that agent runs a local model"),
54
+ one("agents", "Agents over MCP", "agent", null, "whatever the agent reads goes to the agent's model"),
55
+ ];
56
+ };
57
+ const state = (command, env) => {
58
+ const setting = readLocalOnly(env);
59
+ const on = setting?.on === true;
60
+ return { on, since: on ? (setting?.at ?? null) : null, features: features(command, env, on) };
61
+ };
62
+ /** `models local-only`: one switch that keeps every model call on this computer, and where each feature sends data. */
63
+ export const localOnlyCommand = (app, options) => {
64
+ const local = annotate(new Command("local-only"), { effects: LOCAL_READ }).description("keep every model call on this computer: refuse any address that is not, in every WireCat tool");
65
+ annotate(local.command("show"), {
66
+ effects: LOCAL_READ,
67
+ output: { entity: "local_only" },
68
+ examples: [`${app.command} models local-only show`],
69
+ })
70
+ .summary("whether local only is on, and where each feature sends data")
71
+ .description("whether local only is on, and for each feature whether its data stays on this computer")
72
+ .action(function () {
73
+ options.output(itemOf(state(app.command, options.env())), this);
74
+ });
75
+ grantsAuthority(annotate(local.command("set"), {
76
+ effects: LOCAL_WRITE,
77
+ mcp: false,
78
+ output: { entity: "local_only" },
79
+ examples: [`${app.command} models local-only set on`, `${app.command} models local-only set off`],
80
+ }))
81
+ .description("turn local only on or off; only you turn it off")
82
+ .argument("<state>", "on or off")
83
+ .option("--from-app", "you did this in WireCat Desktop")
84
+ .action(function (given) {
85
+ if (given !== "on" && given !== "off")
86
+ throw new CliError("validation_error", "say on or off");
87
+ const env = options.env();
88
+ // An agent that turned it off would let records out for the owner; turning it on only refuses more.
89
+ if (given === "off" && (environmentOf(this).agent || agentOf(env)) && !this.opts().fromApp)
90
+ throw new CliError("permission_error", "only the owner turns local only off, not an agent", {
91
+ reason: "local-only.owner-only",
92
+ });
93
+ const before = readLocalOnly(env)?.on === true;
94
+ if (before !== (given === "on"))
95
+ writeLocalOnly(env, given === "on");
96
+ const now = state(app.command, env);
97
+ const out = now.features.filter((one) => one.refused).map((one) => one.title);
98
+ if (given === "on" && out.length)
99
+ options.diagnostic(`local only is on; these now refuse to send until they use this computer: ${out.join(", ")}`);
100
+ options.output(itemOf({ ...now, changed: before !== (given === "on") }), this);
101
+ });
102
+ return local;
103
+ };
@@ -78,7 +78,7 @@ const conversationBuildCommand = (messenger) => boundOptions(reachesOtherService
78
78
  await consents.remember(status.chat, identity);
79
79
  }
80
80
  await services.conversations.build(chat);
81
- const request = openAnalysis(target, controller.signal);
81
+ const request = openAnalysis(target, controller.signal, context.env);
82
82
  return runAnalysis(services.conversations, chat, async (...args) => {
83
83
  if (!(await consents.has(status.chat, identity)))
84
84
  throw new CliError("permission_error", "analysis consent was revoked; no further batch was sent");
@@ -1,7 +1,8 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { annotate } from "@wirecat/cli-base/commands";
3
3
  import { Command } from "commander";
4
- import { modelTarget } from "../../models/index.js";
4
+ import { refuseModelAddress } from "../../models/local-only.js";
5
+ import { purposeModel } from "../../models/purpose.js";
5
6
  import { readReplyConsent, replyConsentPathFor, replyModelIdentity, writeReplyConsent } from "../../replies/consents.js";
6
7
  import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "../effects.js";
7
8
  import { renderItem } from "./chat-answers.js";
@@ -26,11 +27,16 @@ export const replyConsentsCommand = (messenger) => {
26
27
  const path = replyConsentPathFor(messenger.app, settings.profile, env);
27
28
  const consent = readReplyConsent(path);
28
29
  if (grant) {
29
- const target = modelTarget(settings, "replies");
30
- if (!target)
31
- throw new CliError("configuration_error", "set models.replies.provider and models.replies.model before replies consents grant");
32
- consent.provider = replyModelIdentity(target.provider, target.baseUrl ??
33
- (target.provider === "anthropic" ? "https://api.anthropic.com" : "https://api.openai.com/v1"));
30
+ const chosen = purposeModel(settings, "replies", {
31
+ app: messenger.app,
32
+ env,
33
+ keyring: context.keyring,
34
+ });
35
+ if (!chosen)
36
+ throw new CliError("configuration_error", "set models.replies.provider and models.replies.model, or choose an AI model with `models ai set`, " +
37
+ "before replies consents grant");
38
+ refuseModelAddress(env, chosen.target.baseUrl, "incoming messages");
39
+ consent.provider = replyModelIdentity(chosen.target.provider, chosen.target.baseUrl);
34
40
  }
35
41
  else
36
42
  consent.provider = null;
@@ -17,6 +17,7 @@ import { FETCH, grantsAuthority, LOCAL_READ, LOCAL_WRITE, NO_EFFECTS } from "./e
17
17
  import { enrichmentConsentsCommand } from "./enrichment-consents-command.js";
18
18
  import { itemOf, listOf } from "./envelope.js";
19
19
  import { listQuery, nativeTerms, termField, typedQuery, withQuery } from "./list-query.js";
20
+ import { localOnlyCommand } from "./local-only-command.js";
20
21
  import { harderConsentsCommand } from "./search-harder-consents-command.js";
21
22
  export const MODEL_CATALOGUE_QUERY = defineQuery({
22
23
  entity: "model",
@@ -147,6 +148,7 @@ export const modelCatalogueCommand = (app, options) => {
147
148
  models.addCommand(harderConsentsCommand(app, options));
148
149
  models.addCommand(providerKeysCommand(app, options));
149
150
  models.addCommand(aiModelCommand(app, options));
151
+ models.addCommand(localOnlyCommand(app, options));
150
152
  }
151
153
  if (options.jsonOption)
152
154
  for (const command of models.commands.flatMap((one) => (one.commands.length ? one.commands : [one])))