@wirecat/cli-core 0.641.0 → 0.643.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 (287) hide show
  1. package/CHANGELOG.md +218 -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/attachments/ocr.js +27 -18
  6. package/dist/attachments/picture-reading.d.ts +51 -0
  7. package/dist/attachments/picture-reading.js +207 -0
  8. package/dist/background/backfill.d.ts +4 -2
  9. package/dist/background/backfill.js +3 -3
  10. package/dist/background/schedules.d.ts +28 -2
  11. package/dist/background/schedules.js +73 -20
  12. package/dist/background/units.d.ts +2 -0
  13. package/dist/background/units.js +8 -9
  14. package/dist/calendar/cli/index.js +10 -2
  15. package/dist/calendar/feeds.js +2 -2
  16. package/dist/calendar/mcp/index.d.ts +12 -12
  17. package/dist/calendar/server-search.js +2 -2
  18. package/dist/calendar/source.d.ts +4 -3
  19. package/dist/calendar/sync.js +12 -10
  20. package/dist/calendar/testing/source-contract.js +5 -4
  21. package/dist/calendar/testing/source.js +3 -2
  22. package/dist/cli/ai-model-command.js +6 -3
  23. package/dist/cli/analysis-choice.js +20 -4
  24. package/dist/cli/complete-command.d.ts +23 -0
  25. package/dist/cli/complete-command.js +80 -0
  26. package/dist/cli/context.js +7 -1
  27. package/dist/cli/effects.d.ts +2 -0
  28. package/dist/cli/effects.js +2 -0
  29. package/dist/cli/enrichment-consents-command.js +2 -0
  30. package/dist/cli/envelope.js +6 -1
  31. package/dist/cli/help/first-screen.js +5 -0
  32. package/dist/cli/index.d.ts +4 -2
  33. package/dist/cli/index.js +2 -1
  34. package/dist/cli/list-query.d.ts +3 -1
  35. package/dist/cli/list-query.js +5 -3
  36. package/dist/cli/local-only-command.d.ts +10 -0
  37. package/dist/cli/local-only-command.js +112 -0
  38. package/dist/cli/messenger/backfill-command.js +1 -1
  39. package/dist/cli/messenger/chat-queries.js +2 -1
  40. package/dist/cli/messenger/complete-command.d.ts +4 -7
  41. package/dist/cli/messenger/complete-command.js +31 -98
  42. package/dist/cli/messenger/contacts-command.js +4 -0
  43. package/dist/cli/messenger/conversations-command.js +1 -1
  44. package/dist/cli/messenger/guard-commands.js +1 -1
  45. package/dist/cli/messenger/images-command.js +32 -0
  46. package/dist/cli/messenger/list-result-queries.d.ts +1 -0
  47. package/dist/cli/messenger/list-result-queries.js +2 -1
  48. package/dist/cli/messenger/mentions-command.js +3 -3
  49. package/dist/cli/messenger/message-items.js +1 -0
  50. package/dist/cli/messenger/messages-command.js +7 -6
  51. package/dist/cli/messenger/people-queries.d.ts +2 -2
  52. package/dist/cli/messenger/people-queries.js +4 -4
  53. package/dist/cli/messenger/replies-consents-command.js +12 -6
  54. package/dist/cli/messenger/search-answers.js +2 -2
  55. package/dist/cli/messenger/search-command.js +3 -3
  56. package/dist/cli/messenger/searches-command.js +1 -1
  57. package/dist/cli/messenger/store-maintenance-command.js +4 -0
  58. package/dist/cli/messenger/tasks-analysis-command.js +1 -1
  59. package/dist/cli/messenger/tasks-command.js +2 -2
  60. package/dist/cli/model-catalogue-command.js +4 -0
  61. package/dist/cli/picture-reading-command.d.ts +12 -0
  62. package/dist/cli/picture-reading-command.js +82 -0
  63. package/dist/cli/program.d.ts +6 -0
  64. package/dist/cli/program.js +28 -2
  65. package/dist/cli/schedule/agent-start.d.ts +23 -0
  66. package/dist/cli/schedule/agent-start.js +115 -0
  67. package/dist/cli/schedule/harnesses.d.ts +203 -0
  68. package/dist/cli/schedule/harnesses.js +278 -0
  69. package/dist/cli/schedule/schedule-command.d.ts +9 -5
  70. package/dist/cli/schedule/schedule-command.js +89 -79
  71. package/dist/cli/search-harder-consents-command.js +16 -1
  72. package/dist/cli/shared-command-exports.d.ts +186 -0
  73. package/dist/cli/shared-command-exports.js +2 -0
  74. package/dist/cli/untrusted-marks.d.ts +25 -0
  75. package/dist/cli/untrusted-marks.js +102 -0
  76. package/dist/crm/cli/index.d.ts +1 -0
  77. package/dist/crm/cli/index.js +6 -5
  78. package/dist/crm/cli/store.d.ts +30 -0
  79. package/dist/crm/cli/store.js +63 -0
  80. package/dist/crm/source.d.ts +6 -4
  81. package/dist/crm/sync.js +10 -6
  82. package/dist/crm/testing/source-contract.js +9 -7
  83. package/dist/crm/testing/source.js +6 -2
  84. package/dist/crm/testing/sync-contract.js +4 -4
  85. package/dist/crm/writes.d.ts +5 -2
  86. package/dist/crm/writes.js +1 -1
  87. package/dist/documents.d.ts +2 -1
  88. package/dist/documents.js +2 -1
  89. package/dist/domain/addresses.d.ts +2 -0
  90. package/dist/domain/addresses.js +7 -0
  91. package/dist/domain/attachments.d.ts +2 -0
  92. package/dist/domain/attachments.js +2 -1
  93. package/dist/domain/models.d.ts +2 -0
  94. package/dist/embeddings/remote.d.ts +2 -1
  95. package/dist/embeddings/remote.js +5 -3
  96. package/dist/entities/attachment-results.d.ts +3 -0
  97. package/dist/entities/attachment-results.js +3 -0
  98. package/dist/entities/attachment.d.ts +2 -0
  99. package/dist/entities/attachment.js +8 -1
  100. package/dist/entities/hit.d.ts +1 -0
  101. package/dist/entities/index.d.ts +21 -4
  102. package/dist/entities/index.js +3 -2
  103. package/dist/entities/list-results.d.ts +33 -5
  104. package/dist/entities/list-results.js +33 -5
  105. package/dist/errors/reasons.js +38 -1
  106. package/dist/mail/cli/index.js +7 -6
  107. package/dist/mcp/agent.d.ts +2 -1
  108. package/dist/mcp/agent.js +5 -0
  109. package/dist/mcp/app-server.js +10 -0
  110. package/dist/mcp/surface.d.ts +7 -2
  111. package/dist/mcp/surface.js +49 -10
  112. package/dist/meetings/cli/index.js +6 -1
  113. package/dist/meetings/mcp/index.js +6 -3
  114. package/dist/meetings/participant-search.d.ts +2 -2
  115. package/dist/meetings/project-discovery.d.ts +1 -1
  116. package/dist/meetings/project-evidence-answer.js +2 -2
  117. package/dist/meetings/reads.d.ts +2 -2
  118. package/dist/meetings/reads.js +6 -6
  119. package/dist/meetings/store.d.ts +2 -1
  120. package/dist/meetings/testing/contract.js +6 -6
  121. package/dist/meetings/testing/memory.js +7 -2
  122. package/dist/models/ai.d.ts +17 -4
  123. package/dist/models/ai.js +22 -14
  124. package/dist/models/anthropic.js +15 -9
  125. package/dist/models/endpoint.d.ts +5 -0
  126. package/dist/models/endpoint.js +13 -0
  127. package/dist/models/index.d.ts +4 -0
  128. package/dist/models/index.js +14 -4
  129. package/dist/models/local-only.d.ts +17 -0
  130. package/dist/models/local-only.js +42 -0
  131. package/dist/models/openai.js +24 -11
  132. package/dist/models/purpose.d.ts +24 -0
  133. package/dist/models/purpose.js +26 -0
  134. package/dist/models/types.d.ts +8 -0
  135. package/dist/models/types.js +11 -1
  136. package/dist/ports/app.d.ts +17 -1
  137. package/dist/ports/app.js +63 -3
  138. package/dist/replies/rendering.js +10 -10
  139. package/dist/search/lucene/plain.js +45 -3
  140. package/dist/search/lucene/registry.d.ts +15 -4
  141. package/dist/search/lucene/registry.js +70 -12
  142. package/dist/search/lucene/types.d.ts +2 -0
  143. package/dist/search/lucene/types.js +12 -0
  144. package/dist/sends/upload.d.ts +8 -1
  145. package/dist/sends/upload.js +35 -14
  146. package/dist/services/account-groups.d.ts +11 -0
  147. package/dist/services/account-groups.js +29 -0
  148. package/dist/services/agenda.js +1 -0
  149. package/dist/services/attachments.d.ts +18 -4
  150. package/dist/services/attachments.js +66 -15
  151. package/dist/services/conversations.d.ts +2 -4
  152. package/dist/services/conversations.js +1 -1
  153. package/dist/services/deal-context.js +5 -5
  154. package/dist/services/documents/ingestion.js +3 -3
  155. package/dist/services/documents/knowledge.d.ts +6 -6
  156. package/dist/services/documents/knowledge.js +1 -2
  157. package/dist/services/embeddings-maintenance.js +4 -1
  158. package/dist/services/enrichment.d.ts +1 -1
  159. package/dist/services/enrichment.js +27 -0
  160. package/dist/services/events-search.d.ts +3 -3
  161. package/dist/services/events-search.js +7 -7
  162. package/dist/services/index.d.ts +1 -1
  163. package/dist/services/index.js +1 -1
  164. package/dist/services/meeting-model.js +1 -1
  165. package/dist/services/meeting-project-discovery.js +1 -1
  166. package/dist/services/message-resolution.js +10 -3
  167. package/dist/services/messages-search.js +6 -4
  168. package/dist/services/metadata.d.ts +1 -1
  169. package/dist/services/notes-search.d.ts +3 -3
  170. package/dist/services/notes-search.js +3 -3
  171. package/dist/services/organization-context.js +12 -9
  172. package/dist/services/people.d.ts +2 -0
  173. package/dist/services/people.js +4 -2
  174. package/dist/services/pictures.d.ts +9 -0
  175. package/dist/services/pictures.js +34 -28
  176. package/dist/services/project-status/index.js +1 -1
  177. package/dist/services/project-status/signals/payments.js +4 -2
  178. package/dist/services/project-status/signals/promises.js +5 -2
  179. package/dist/services/proposals/kinds/action.js +1 -1
  180. package/dist/services/proposals/kinds/fact.js +1 -1
  181. package/dist/services/proposals/kinds/findings.d.ts +2 -1
  182. package/dist/services/proposals/kinds/findings.js +12 -5
  183. package/dist/services/proposals/kinds/identity-link.js +1 -1
  184. package/dist/services/proposals/kinds/identity-split.js +1 -1
  185. package/dist/services/proposals/kinds/key-document.js +1 -1
  186. package/dist/services/proposals/kinds/mail-findings.d.ts +1 -1
  187. package/dist/services/proposals/kinds/mail-findings.js +11 -5
  188. package/dist/services/proposals/kinds/meeting-findings.js +10 -4
  189. package/dist/services/proposals/kinds/memory.js +1 -1
  190. package/dist/services/proposals/kinds/organization.js +1 -1
  191. package/dist/services/proposals/kinds/relationship-update.js +1 -1
  192. package/dist/services/proposals/kinds/relationship.js +1 -1
  193. package/dist/services/proposals/kinds/shared.d.ts +3 -2
  194. package/dist/services/proposals/kinds/shared.js +4 -4
  195. package/dist/services/proposals/kinds/source-review.js +1 -1
  196. package/dist/services/proposals/kinds/task-close.js +2 -2
  197. package/dist/services/proposals/registry.js +1 -1
  198. package/dist/services/proposals/types.d.ts +2 -1
  199. package/dist/services/search-all-business.js +3 -4
  200. package/dist/services/search-all.js +13 -14
  201. package/dist/services/search-harder.d.ts +11 -1
  202. package/dist/services/search-harder.js +38 -5
  203. package/dist/services/searches.d.ts +2 -4
  204. package/dist/services/searches.js +1 -4
  205. package/dist/services/stored-project-gathering.js +6 -1
  206. package/dist/services/tags.d.ts +2 -4
  207. package/dist/services/tags.js +1 -1
  208. package/dist/services/tasks.d.ts +1 -1
  209. package/dist/services/tasks.js +4 -3
  210. package/dist/speech/openai.js +2 -0
  211. package/dist/speech/transcribe.d.ts +5 -2
  212. package/dist/speech/transcribe.js +14 -5
  213. package/dist/store/account-store.d.ts +2 -1
  214. package/dist/store/account-store.js +3 -1
  215. package/dist/store/accounts.d.ts +2 -0
  216. package/dist/store/accounts.js +8 -0
  217. package/dist/store/chats.d.ts +5 -0
  218. package/dist/store/chats.js +4 -0
  219. package/dist/store/evidence-findings.d.ts +9 -0
  220. package/dist/store/exports.d.ts +1 -1
  221. package/dist/store/exports.js +1 -1
  222. package/dist/store/identity-links.d.ts +3 -1
  223. package/dist/store/mail-findings.d.ts +9 -0
  224. package/dist/store/meeting-findings.d.ts +9 -0
  225. package/dist/store/searches.d.ts +3 -2
  226. package/dist/store/sqlite/accounts.js +37 -0
  227. package/dist/store/sqlite/agent-actions.d.ts +2 -1
  228. package/dist/store/sqlite/agent-actions.js +10 -4
  229. package/dist/store/sqlite/business-contracts.d.ts +3 -1
  230. package/dist/store/sqlite/business-contracts.js +7 -3
  231. package/dist/store/sqlite/business-search.d.ts +2 -1
  232. package/dist/store/sqlite/business-search.js +6 -4
  233. package/dist/store/sqlite/deals.d.ts +6 -4
  234. package/dist/store/sqlite/deals.js +12 -7
  235. package/dist/store/sqlite/evidence-findings.js +78 -9
  236. package/dist/store/sqlite/facts.d.ts +2 -1
  237. package/dist/store/sqlite/facts.js +6 -2
  238. package/dist/store/sqlite/finance.d.ts +4 -2
  239. package/dist/store/sqlite/finance.js +13 -6
  240. package/dist/store/sqlite/findings-core.d.ts +56 -2
  241. package/dist/store/sqlite/findings-core.js +109 -22
  242. package/dist/store/sqlite/identities.d.ts +4 -0
  243. package/dist/store/sqlite/identities.js +12 -3
  244. package/dist/store/sqlite/identity-proposals.js +34 -4
  245. package/dist/store/sqlite/lucene-fields.d.ts +2 -0
  246. package/dist/store/sqlite/lucene-fields.js +28 -2
  247. package/dist/store/sqlite/lucene.js +21 -10
  248. package/dist/store/sqlite/mail-findings.js +60 -22
  249. package/dist/store/sqlite/meeting-findings.js +53 -7
  250. package/dist/store/sqlite/meeting-participant-search.js +4 -5
  251. package/dist/store/sqlite/meetings.js +7 -3
  252. package/dist/store/sqlite/memories.d.ts +4 -2
  253. package/dist/store/sqlite/memories.js +13 -6
  254. package/dist/store/sqlite/money-transactions.d.ts +3 -1
  255. package/dist/store/sqlite/money-transactions.js +7 -3
  256. package/dist/store/sqlite/name-traces.d.ts +3 -3
  257. package/dist/store/sqlite/name-traces.js +29 -2
  258. package/dist/store/sqlite/orders.d.ts +3 -1
  259. package/dist/store/sqlite/orders.js +5 -2
  260. package/dist/store/sqlite/people-list.js +67 -22
  261. package/dist/store/sqlite/person-match-scan.d.ts +3 -1
  262. package/dist/store/sqlite/person-match-scan.js +97 -7
  263. package/dist/store/sqlite/products.d.ts +3 -1
  264. package/dist/store/sqlite/products.js +5 -2
  265. package/dist/store/sqlite/proposed-actions.d.ts +2 -1
  266. package/dist/store/sqlite/proposed-actions.js +7 -3
  267. package/dist/store/sqlite/query-filter.d.ts +4 -0
  268. package/dist/store/sqlite/query-filter.js +14 -0
  269. package/dist/store/sqlite/reads.d.ts +1 -0
  270. package/dist/store/sqlite/reads.js +14 -0
  271. package/dist/store/sqlite/records.d.ts +3 -1
  272. package/dist/store/sqlite/records.js +7 -5
  273. package/dist/store/sqlite/rows-page.d.ts +3 -0
  274. package/dist/store/sqlite/rows-page.js +4 -0
  275. package/dist/store/sqlite/searches.d.ts +2 -1
  276. package/dist/store/sqlite/searches.js +3 -1
  277. package/dist/store/sqlite/subscriptions.d.ts +5 -2
  278. package/dist/store/sqlite/subscriptions.js +13 -6
  279. package/dist/store/sqlite/task-board.js +27 -0
  280. package/dist/store/sqlite/task-find.d.ts +15 -0
  281. package/dist/store/sqlite/task-find.js +1 -0
  282. package/dist/store/sqlite/wallets.d.ts +3 -1
  283. package/dist/store/sqlite/wallets.js +7 -3
  284. package/dist/store/sqlite/work-tasks.d.ts +3 -11
  285. package/dist/store/sqlite/work-tasks.js +8 -4
  286. package/package.json +2 -2
  287. package/parity.json +24 -0
@@ -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)
@@ -0,0 +1,23 @@
1
+ import { type CompletionSources } from "@wirecat/cli-base/completion";
2
+ import { Command } from "commander";
3
+ import type { AppIdentity } from "../ports/app.js";
4
+ import type { Configuration } from "./settings.js";
5
+ /** What the words being completed name: the profile a Tab reads names for, and the words after it. */
6
+ export interface CompletionRequest {
7
+ /** The profile typed, or the locked or session one; unset when none is usable. */
8
+ profile: string | undefined;
9
+ words: string[];
10
+ env: NodeJS.ProcessEnv;
11
+ }
12
+ export interface AppCompletionOptions {
13
+ /** Names for arguments and options, read locally; never a connection, and never an error a shell would show. */
14
+ sources?: (request: CompletionRequest) => CompletionSources | undefined | Promise<CompletionSources | undefined>;
15
+ }
16
+ /**
17
+ * `<app> complete zsh` prints the script a shell sources; the script then runs `<app> complete -- <words>` on every
18
+ * Tab, and this answers from the command registry, the profiles in the config and the CLI's own `sources`.
19
+ *
20
+ * ⚠ **A Tab never connects and never creates anything**, and nothing goes to stderr: a shell shows whatever it is
21
+ * given.
22
+ */
23
+ export declare const appCompleteCommand: (app: Pick<AppIdentity, "command" | "envPrefix">, config: Pick<Configuration, "configuredProfiles">, options?: AppCompletionOptions) => Command;
@@ -0,0 +1,80 @@
1
+ import { script } from "@bomb.sh/tab";
2
+ import { CliError } from "@wirecat/cli-base";
3
+ import { annotate, describeOptions, describeProgram } from "@wirecat/cli-base/commands";
4
+ import { formatSuggestions, suggest } from "@wirecat/cli-base/completion";
5
+ import { Command } from "commander";
6
+ import { environmentOf, outputFor } from "./context.js";
7
+ import { LOCAL_READ } from "./effects.js";
8
+ import { commandWords, liftProfile, rootOf, usableProfileName } from "./profile.js";
9
+ const SHELLS = ["zsh", "bash", "fish", "powershell"];
10
+ /**
11
+ * `<app> complete zsh` prints the script a shell sources; the script then runs `<app> complete -- <words>` on every
12
+ * Tab, and this answers from the command registry, the profiles in the config and the CLI's own `sources`.
13
+ *
14
+ * ⚠ **A Tab never connects and never creates anything**, and nothing goes to stderr: a shell shows whatever it is
15
+ * given.
16
+ */
17
+ export const appCompleteCommand = (app, config, options = {}) => annotate(new Command("complete"), {
18
+ literal_after_dashes: true,
19
+ effects: LOCAL_READ,
20
+ mcp: false,
21
+ examples: [`${app.command} complete zsh`],
22
+ })
23
+ .description(`shell completion: \`${app.command} complete zsh\` prints the script to source`)
24
+ .argument("[words...]", "zsh for the shell script, or command words to complete")
25
+ .allowUnknownOption()
26
+ .helpOption(false)
27
+ .action(async function (words) {
28
+ const root = rootOf(this);
29
+ const { streams } = outputFor(this);
30
+ const env = environmentOf(this).env ?? process.env;
31
+ // Commander drops the `--` from the operands, so only the raw words tell a request from a shell name.
32
+ const raw = root.rawArgs;
33
+ if (!raw.includes("--")) {
34
+ if (words.includes("--help") || words.includes("-h"))
35
+ this.help();
36
+ const [shell] = words;
37
+ if (!shell || !SHELLS.includes(shell)) {
38
+ throw new CliError("validation_error", `name a shell: ${app.command} complete ${SHELLS.join(" | ")}`);
39
+ }
40
+ // tab writes the script through console.log; stdout is where a `source <(…)` reads it.
41
+ script(shell, app.command, app.command);
42
+ return;
43
+ }
44
+ // The last word is still being typed, so it is never taken for a profile: `mess` is on its way to `messages`.
45
+ const { profile, rest } = words.length > 1 ? liftProfile(words, commandWords(root)) : { profile: undefined, rest: words };
46
+ const lock = env[`${app.envPrefix}_PROFILE_LOCK`];
47
+ const wanted = profile ?? lock ?? env[`${app.envPrefix}_PROFILE`];
48
+ const usable = wanted && readable(wanted, lock) ? wanted : undefined;
49
+ const own = await (async () => options.sources?.({ profile: usable, words: rest, env }))().catch(() => undefined);
50
+ const suggestions = suggest({
51
+ commands: describeProgram(root),
52
+ globalOptions: describeOptions(root),
53
+ words: rest.length > 0 ? rest : [""],
54
+ sources: {
55
+ ...(profile === undefined ? { firstWord: () => profileNames(config, env) } : {}),
56
+ ...own,
57
+ },
58
+ });
59
+ streams.data(formatSuggestions(suggestions));
60
+ });
61
+ /** A half-typed or odd first word, or another profile than a locked one, gets no names rather than an error. */
62
+ const readable = (profile, lock) => {
63
+ if (lock && profile !== lock)
64
+ return false;
65
+ try {
66
+ usableProfileName(profile);
67
+ return true;
68
+ }
69
+ catch {
70
+ return false;
71
+ }
72
+ };
73
+ const profileNames = (config, env) => {
74
+ try {
75
+ return config.configuredProfiles({ env });
76
+ }
77
+ catch {
78
+ return [];
79
+ }
80
+ };
@@ -94,6 +94,9 @@ export const baseContext = (command, resolveSettings) => {
94
94
  });
95
95
  const closeables = [];
96
96
  const ranFor = namedProfile(settings);
97
+ // A command can open several runs: `messages sync` fetches, then applies task rules, then counts mentions.
98
+ // Its answer's meta.run_id names the first, the one with the requests; a named side run never takes it.
99
+ let namedTheAnswer = false;
97
100
  return {
98
101
  settings,
99
102
  renderer,
@@ -109,6 +112,9 @@ export const baseContext = (command, resolveSettings) => {
109
112
  return withAbort(environment.commandSignal, () => withDeadline(unbounded ? undefined : settings.commandTimeoutMs, closeables, () => body(() => { })));
110
113
  // An agent's run is named `mcp <command>`, so `search runs` and `sends list` tell it from the owner's.
111
114
  const runName = name ?? `${environment.agent ? "mcp " : ""}${commandPath(command)}`;
115
+ const answersFor = !environment.agent && name === undefined && !namedTheAnswer;
116
+ if (answersFor)
117
+ namedTheAnswer = true;
112
118
  return recorded({
113
119
  app: environment.app,
114
120
  command: runName,
@@ -137,7 +143,7 @@ export const baseContext = (command, resolveSettings) => {
137
143
  : { keepSuccessDays: settings.keepSuccessfulRunsForDays }),
138
144
  ...(settings.keepStoreRunsForDays === undefined ? {} : { keepStoreDays: settings.keepStoreRunsForDays }),
139
145
  ...(settings.runsSizeLimitMb === undefined ? {} : { maxBytes: settings.runsSizeLimitMb * 1024 * 1024 }),
140
- processRun: !environment.agent,
146
+ processRun: answersFor,
141
147
  format,
142
148
  streams,
143
149
  env,
@@ -82,6 +82,8 @@ export declare const writesFileOnlyWith: <T extends Command>(command: T, option:
82
82
  * destroys nothing, and the read-only lock lets it through (`meetings export --output`).
83
83
  */
84
84
  export declare const writesNewFileOnlyWith: <T extends Command>(command: T, option: string) => T;
85
+ /** The option a command writes its one file through, as `writesFileOnlyWith` named it. */
86
+ export declare const fileOptionOf: (command: Command) => string | undefined;
85
87
  /**
86
88
  * What an MCP server runs through `read`: a command that only fetches into the store (`fetchesOnly`), and one whose
87
89
  * only write is a file the tool cannot name (`writesFileOnlyWith`).
@@ -150,6 +150,8 @@ export const writesFileOnlyWith = (command, option) => {
150
150
  * destroys nothing, and the read-only lock lets it through (`meetings export --output`).
151
151
  */
152
152
  export const writesNewFileOnlyWith = (command, option) => destroysNothing(writesFileOnlyWith(command, option));
153
+ /** The option a command writes its one file through, as `writesFileOnlyWith` named it. */
154
+ export const fileOptionOf = (command) => FILE_OPTION.get(command);
153
155
  const writesFileNow = (command) => {
154
156
  const option = FILE_OPTION.get(command);
155
157
  return option === undefined || command.opts()[option] !== 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) {
@@ -8,6 +8,7 @@ import { environmentOf, setExitCode } from "./context.js";
8
8
  import { largeAnswerSteps, SOFT_OUTPUT_BYTES } from "./output-budget.js";
9
9
  import { withoutProviderRefs } from "./provider-refs.js";
10
10
  import { nextStep, rootOf, runnable, stepLine, withLines, withSafety } from "./steps.js";
11
+ import { untrustedFieldsOf, untrustedMarkOf, withFieldsMarked, withUntrustedMarked } from "./untrusted-marks.js";
11
12
  /** Every answer: a list or one thing, with items of `item` — any value where the command declares no entity. */
12
13
  export const answerSchema = (item = v.unknown()) => v.union([listEnvelopeSchema(item), itemEnvelopeSchema(item)]);
13
14
  const capped = (steps) => (steps.length > 0 ? { next: steps.slice(0, MAX_NEXT_STEPS) } : {});
@@ -159,7 +160,11 @@ export const renderAnswer = (command, { renderer, format, streams, compact, full
159
160
  const root = rootOf(command);
160
161
  const runnableSteps = runnable(root, body.next);
161
162
  const next = environmentOf(command).agent ? runnableSteps : withLines(root, runnableSteps);
162
- const kept = withoutProviderRefs({ ...body, ...(next.length > 0 ? { next } : {}) });
163
+ const { app, env } = environmentOf(command);
164
+ const mark = app ? untrustedMarkOf(app, env ?? process.env) : undefined;
165
+ const declared = untrustedFieldsOf(command);
166
+ const shown = mark === undefined ? body : withUntrustedMarked(declared ? withFieldsMarked(body, declared, mark) : body, mark);
167
+ const kept = withoutProviderRefs({ ...shown, ...(next.length > 0 ? { next } : {}) });
163
168
  if (next.length === 0)
164
169
  delete kept.next;
165
170
  const sealedBody = sealed(kept);
@@ -48,6 +48,11 @@ export const WIRECAT_TOOLS = [
48
48
  package: "@wirecat/mail-cli",
49
49
  does: "IMAP mail in the same local store: search your mailbox offline, next to your other WireCat data",
50
50
  },
51
+ {
52
+ command: "b24",
53
+ package: "@wirecat/bitrix24-cli",
54
+ does: "Bitrix24 CRM: deals, leads and pipelines, searchable with your other WireCat data",
55
+ },
51
56
  ];
52
57
  const WIDTH = 100;
53
58
  const widest = (texts) => texts.reduce((most, text) => Math.max(most, text.length), 0);
@@ -68,6 +68,7 @@ export { commandContract, type JsonSchema, SCHEMA_DIALECT } from "./command-cont
68
68
  export { type CommandRunOptions, type CommandRuns, commandRuns, type ProviderAnswer, type ProviderCall, providerEvent, providerRequest, type RunSettings, recordRuns, runSettings, type SavedRunSettings, } from "./command-runs.js";
69
69
  export { CONTRACT } from "./commands-command.js";
70
70
  export { type CompactOptions, compactText, entityRows, GENERIC_ROW, type RowColumn, type RowShape, type RowsResolver, type RowTable, type RowValue, rowShapeOf, rowsOfEntity, SHARED_ROWS, } from "./compact.js";
71
+ export type { AppCompletionOptions, CompletionRequest } from "./complete-command.js";
71
72
  export { refuseUnknownKey } from "./config-command.js";
72
73
  export { type ConfigIssue, type ConfigIssueKind, checkConfigText, issueMessage, readConfigFile, readConfigText, settingPathOf, withoutSetting, } from "./config-issues.js";
73
74
  export { loadSnakeCaseConfig } from "./config-keys.js";
@@ -134,13 +135,14 @@ export { type ProjectTextHints, projectAnswerParts, projectCutoffTime, projectEv
134
135
  export { type ProjectStatusHints, type ProjectStatusItem, projectStatusAnswer, projectStatusRow, projectStatusSchema, projectStatusText, } from "./project-status.js";
135
136
  export { STATUS_ROWS, STATUS_SIGNAL_ROWS } from "./project-status-rows.js";
136
137
  export { fieldsOf, projectFields } from "./result-fields.js";
137
- export { type AgentScheduleSpec, agentSchedule, backfillScheduleRun, type Harness, pauseSchedule, removeSchedule, runScheduleNow, SCHEDULE_SETTINGS, type ScheduleHost, type ScheduleLimits, type ScheduleSite, scheduleLimitsOf, scheduleState, slotsOfAt, writeSchedule, } from "./schedule/schedule-command.js";
138
+ export { HARNESSES, type Harness, harnessesOn, harnessInfo, harnessOfArgv, isHarness, reportsCost, } from "./schedule/harnesses.js";
139
+ export { type AgentScheduleSpec, agentSchedule, backfillScheduleRun, pauseSchedule, removeSchedule, runScheduleNow, SCHEDULE_SETTINGS, type ScheduleHost, type ScheduleLimits, type ScheduleSite, scheduleLimitsOf, scheduleState, slotsOfAt, writeSchedule, } from "./schedule/schedule-command.js";
138
140
  export { deniedKinds, deniedKindsOf, type LeftOut, type SearchedKind } from "./search-left-out.js";
139
141
  export { type DeclaredSetting, type SettingRow, settingRows, withSettingDefaults } from "./setting-defaults.js";
140
142
  export { type Config, type Configuration, count, first, flag, fromFile, type GlobalFlags, NONE_NAMED, namedProfile, type ProfileKind, plain, type ResolveOptions, type Settings, type SettingsExtension, type SettingsExtensionContext, type Source, settingsFor, } from "./settings.js";
141
143
  export { type PermissionAnswer, readSetupAnswers, type SetupAnswers, setupPermissionCeiling } from "./setup-answers.js";
142
144
  export { AGENTS, type Agent, agentFor, screenFor } from "./setup-screen.js";
143
- export { accountCommand, addMeetingBatchCommand, addMeetingPreparationCommand, addMeetingProjectCandidatesCommand, addMeetingSeriesInventoryCommand, appDoctorCommand, appMcpCommand, attachmentsCommand, botAdminsCommand, botCommand, botMcpCommand, botMembersCommand, botMessagesCommand, callsCommand, chatsCommand, commandsCommand, completeCommand, configCommand, contactsCommand, conversationsCommand, deleteCommand, doctorCommand, editCommand, floodCommand, forwardCommand, generatedApiCommand, guideCommand, imagesCommand, inboxCommand, markReadCommand, mcpCommand, mentionsCommand, messagesCommand, metadataCommand, modelCatalogueCommand, modelsCommand, pinCommand, pollsCommand, projectsCommand, reactionsCommand, recipientsCommand, repliesCommand, reviewCommand, runsCommand, scheduleCommand, scheduleCommandFor, searchCommand, searchesCommand, sendCommand, sendsCommand, serveCommand, serverCommand, skillCommand, starCommands, statsCommand, stickersCommand, storeCommand, tagsCommand, tasksCommand, tasksStatsCommand, templatesCommand, topicsCommand, unpinCommand, upgradeCommand, watchCommand, } from "./shared-command-exports.js";
145
+ export { accountCommand, addMeetingBatchCommand, addMeetingPreparationCommand, addMeetingProjectCandidatesCommand, addMeetingSeriesInventoryCommand, appCompleteCommand, appDoctorCommand, appMcpCommand, attachmentsCommand, botAdminsCommand, botCommand, botMcpCommand, botMembersCommand, botMessagesCommand, callsCommand, chatsCommand, commandsCommand, completeCommand, configCommand, contactsCommand, conversationsCommand, deleteCommand, doctorCommand, editCommand, floodCommand, forwardCommand, generatedApiCommand, guideCommand, imagesCommand, inboxCommand, markReadCommand, mcpCommand, mentionsCommand, messagesCommand, metadataCommand, modelCatalogueCommand, modelsCommand, pinCommand, pollsCommand, projectsCommand, reactionsCommand, recipientsCommand, repliesCommand, reviewCommand, runsCommand, scheduleCommand, scheduleCommandFor, searchCommand, searchesCommand, sendCommand, sendsCommand, serveCommand, serverCommand, skillCommand, starCommands, statsCommand, stickersCommand, storeCommand, tagsCommand, tasksCommand, tasksStatsCommand, templatesCommand, topicsCommand, unpinCommand, upgradeCommand, watchCommand, } from "./shared-command-exports.js";
144
146
  export { assertSharedContracts, customizeSharedCommand, hasSharedContract, overrideSharedContract, type SharedContractOverride, sharedContractOverrides, sharedContracts, } from "./shared-contracts.js";
145
147
  export { runnable, withSafety } from "./steps.js";
146
148
  export { type StoreInfo, sharedStoreCommand, storeInfo, storeInfoCommand } from "./store-info.js";
package/dist/cli/index.js CHANGED
@@ -124,13 +124,14 @@ export { projectAnswerParts, projectCutoffTime, projectEvidenceText, projectWind
124
124
  export { projectStatusAnswer, projectStatusRow, projectStatusSchema, projectStatusText, } from "./project-status.js";
125
125
  export { STATUS_ROWS, STATUS_SIGNAL_ROWS } from "./project-status-rows.js";
126
126
  export { fieldsOf, projectFields } from "./result-fields.js";
127
+ export { HARNESSES, harnessesOn, harnessInfo, harnessOfArgv, isHarness, reportsCost, } from "./schedule/harnesses.js";
127
128
  export { agentSchedule, backfillScheduleRun, pauseSchedule, removeSchedule, runScheduleNow, SCHEDULE_SETTINGS, scheduleLimitsOf, scheduleState, slotsOfAt, writeSchedule, } from "./schedule/schedule-command.js";
128
129
  export { deniedKinds, deniedKindsOf } from "./search-left-out.js";
129
130
  export { settingRows, withSettingDefaults } from "./setting-defaults.js";
130
131
  export { count, first, flag, fromFile, NONE_NAMED, namedProfile, plain, settingsFor, } from "./settings.js";
131
132
  export { readSetupAnswers, setupPermissionCeiling } from "./setup-answers.js";
132
133
  export { AGENTS, agentFor, screenFor } from "./setup-screen.js";
133
- export { accountCommand, addMeetingBatchCommand, addMeetingPreparationCommand, addMeetingProjectCandidatesCommand, addMeetingSeriesInventoryCommand, appDoctorCommand, appMcpCommand, attachmentsCommand, botAdminsCommand, botCommand, botMcpCommand, botMembersCommand, botMessagesCommand, callsCommand, chatsCommand, commandsCommand, completeCommand, configCommand, contactsCommand, conversationsCommand, deleteCommand, doctorCommand, editCommand, floodCommand, forwardCommand, generatedApiCommand, guideCommand, imagesCommand, inboxCommand, markReadCommand, mcpCommand, mentionsCommand, messagesCommand, metadataCommand, modelCatalogueCommand, modelsCommand, pinCommand, pollsCommand, projectsCommand, reactionsCommand, recipientsCommand, repliesCommand, reviewCommand, runsCommand, scheduleCommand, scheduleCommandFor, searchCommand, searchesCommand, sendCommand, sendsCommand, serveCommand, serverCommand, skillCommand, starCommands, statsCommand, stickersCommand, storeCommand, tagsCommand, tasksCommand, tasksStatsCommand, templatesCommand, topicsCommand, unpinCommand, upgradeCommand, watchCommand, } from "./shared-command-exports.js";
134
+ export { accountCommand, addMeetingBatchCommand, addMeetingPreparationCommand, addMeetingProjectCandidatesCommand, addMeetingSeriesInventoryCommand, appCompleteCommand, appDoctorCommand, appMcpCommand, attachmentsCommand, botAdminsCommand, botCommand, botMcpCommand, botMembersCommand, botMessagesCommand, callsCommand, chatsCommand, commandsCommand, completeCommand, configCommand, contactsCommand, conversationsCommand, deleteCommand, doctorCommand, editCommand, floodCommand, forwardCommand, generatedApiCommand, guideCommand, imagesCommand, inboxCommand, markReadCommand, mcpCommand, mentionsCommand, messagesCommand, metadataCommand, modelCatalogueCommand, modelsCommand, pinCommand, pollsCommand, projectsCommand, reactionsCommand, recipientsCommand, repliesCommand, reviewCommand, runsCommand, scheduleCommand, scheduleCommandFor, searchCommand, searchesCommand, sendCommand, sendsCommand, serveCommand, serverCommand, skillCommand, starCommands, statsCommand, stickersCommand, storeCommand, tagsCommand, tasksCommand, tasksStatsCommand, templatesCommand, topicsCommand, unpinCommand, upgradeCommand, watchCommand, } from "./shared-command-exports.js";
134
135
  export { assertSharedContracts, customizeSharedCommand, hasSharedContract, overrideSharedContract, sharedContractOverrides, sharedContracts, } from "./shared-contracts.js";
135
136
  export { runnable, withSafety } from "./steps.js";
136
137
  export { sharedStoreCommand, storeInfo, storeInfoCommand } from "./store-info.js";
@@ -31,7 +31,9 @@ export declare const pageOf: ({ limit, page, all }: Pick<Settings, "limit" | "pa
31
31
  offset: number;
32
32
  };
33
33
  /** A page-numbered list's answer; under `--all` its limit is what it holds. */
34
- export declare const pagedList: <T>(command: string, { limit, page, all }: Pick<Settings, "limit" | "page" | "all">, { items, has_more, ...rest }: Omit<ListInput<T>, "limit" | "page" | "cursor">) => ListBody<T>;
34
+ export declare const pagedList: <T>(command: string, { limit, page, all }: Pick<Settings, "limit" | "page" | "all">, { items, hasMore, ...rest }: Omit<ListInput<T>, "limit" | "page" | "cursor" | "has_more"> & {
35
+ hasMore: boolean;
36
+ }) => ListBody<T>;
35
37
  /** An MCP list's `query` argument: the language the CLI list takes after its arguments. */
36
38
  export declare const queryArgument: (registry: QueryRegistry) => v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 8192, undefined>, v.DescriptionAction<string, string>]>, undefined>;
37
39
  /** The fields a native list can also leave out, `-field:value`: what `nativeTermLists` keeps under `-field`. */
@@ -58,7 +58,9 @@ const withTomorrow = (query, registry, zone = timezoneOf(), now = Date.now()) =>
58
58
  };
59
59
  export const listQuery = (text, registry, command, { defaultField = "none" } = {}) => {
60
60
  const context = { command, guide: LIST_QUERY_GUIDE };
61
- const parsed = text.trim() === "" ? undefined : parseLucene(text, { defaultField, ...context });
61
+ // `phone:+34`: a `+` right after a field's colon can only be the value's own sign, never Lucene's "required".
62
+ const signed = text.replace(/(^|[\s(])([\p{L}_][\p{L}\p{N}_.]*:)\+([^\s()"]+)/gu, '$1$2"+$3"');
63
+ const parsed = signed.trim() === "" ? undefined : parseLucene(signed, { defaultField, ...context });
62
64
  const typed = parsed && withTomorrow(parsed, registry);
63
65
  if (typed)
64
66
  validateQuery(typed, registry, context);
@@ -87,11 +89,11 @@ const EVERY = Number.MAX_SAFE_INTEGER - 1;
87
89
  /** The rows a page-numbered list asks its store for; `--all` asks for every one. */
88
90
  export const pageOf = ({ limit, page, all }) => all ? { limit: EVERY, offset: 0 } : { limit, offset: (page - 1) * limit };
89
91
  /** A page-numbered list's answer; under `--all` its limit is what it holds. */
90
- export const pagedList = (command, { limit, page, all }, { items, has_more, ...rest }) => listOf(command, {
92
+ export const pagedList = (command, { limit, page, all }, { items, hasMore, ...rest }) => listOf(command, {
91
93
  ...rest,
92
94
  items,
93
95
  limit: all ? Math.max(1, items.length) : limit,
94
- has_more: all ? false : has_more,
96
+ has_more: all ? false : hasMore,
95
97
  page,
96
98
  });
97
99
  /** The fields a list can be narrowed by: a provider list only those its source answers. */
@@ -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,112 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { annotate } from "@wirecat/cli-base/commands";
3
+ import { Command } from "commander";
4
+ import { readPictureReading } from "../attachments/picture-reading.js";
5
+ import { chosenTextModel } from "../embeddings/models.js";
6
+ import { aiBaseUrl, aiLeavesComputer, aiSettingPath, readAiSetting } from "../models/ai.js";
7
+ import { onThisComputer } from "../models/endpoint.js";
8
+ import { readLocalOnly, writeLocalOnly } from "../models/local-only.js";
9
+ import { agentOf } from "../runs/run-context.js";
10
+ import { enrichmentEndpoint, readEnrichmentSetting } from "../services/enrichment-setting.js";
11
+ import { readHarderSetting } from "../services/search-harder.js";
12
+ import { environmentOf } from "./context.js";
13
+ import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "./effects.js";
14
+ import { itemOf } from "./envelope.js";
15
+ const placeOf = (address) => (onThisComputer(address) ? "this-computer" : "elsewhere");
16
+ const read = (get) => {
17
+ try {
18
+ return get();
19
+ }
20
+ catch {
21
+ return undefined;
22
+ }
23
+ };
24
+ const features = (command, env, on) => {
25
+ const ai = read(() => readAiSetting(aiSettingPath(env)));
26
+ const aiAddress = ai ? aiBaseUrl(ai) : null;
27
+ const aiWhere = ai ? (aiLeavesComputer(ai) ? "elsewhere" : "this-computer") : "off";
28
+ const enrichment = read(() => readEnrichmentSetting(env));
29
+ const enrichmentAddress = enrichment ? enrichmentEndpoint(enrichment) : null;
30
+ const harder = read(() => readHarderSetting(env));
31
+ const harderAddress = harder ? enrichmentEndpoint(harder) : null;
32
+ const blocked = (where) => on && where === "elsewhere";
33
+ const one = (id, title, where, address, note) => ({
34
+ id,
35
+ title,
36
+ where,
37
+ address,
38
+ refused: blocked(where),
39
+ note,
40
+ });
41
+ return [
42
+ one("ai_model", "AI model", aiWhere, aiAddress, `\`${command} models ai set\` chooses it`),
43
+ one("enrichment", "Rewrite records for better search", enrichmentAddress ? placeOf(enrichmentAddress) : "off", enrichmentAddress, `\`${command} models consents\``),
44
+ one("search_harder", "Search harder", harderAddress ? placeOf(harderAddress) : "off", harderAddress, `\`${command} models search-consents\``),
45
+ 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`),
46
+ ...[
47
+ ["chat_linking", "Chat linking (--analyze)", "analysis"],
48
+ ["replies", "Reply drafts", "replies"],
49
+ ["attachment_ocr", "Picture text in attachments (--ocr)", "ocr"],
50
+ ].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`)),
51
+ one("voice_messages", "Voice messages", on ? "this-computer" : "elsewhere", null, on
52
+ ? "the downloaded speech model only"
53
+ : "the downloaded speech model first, else the messenger's own service; OpenAI only when asked by name"),
54
+ ...(() => {
55
+ const pictures = readPictureReading(env);
56
+ return [
57
+ one("picture_reading", "Picture text read by your coding agent", pictures.mode === "never" ? "off" : "agent", null, pictures.mode === "never"
58
+ ? `never; \`${command} models picture-reading set request\` turns it on`
59
+ : `\`${command} images read\` sends one picture to ${pictures.agent}: local only if that agent runs a local model`),
60
+ ];
61
+ })(),
62
+ one("digest", "Digest", "agent", null, "runs Claude Code or Codex: local only if that agent runs a local model"),
63
+ one("agents", "Agents over MCP", "agent", null, "whatever the agent reads goes to the agent's model"),
64
+ ];
65
+ };
66
+ const state = (command, env) => {
67
+ const setting = readLocalOnly(env);
68
+ const on = setting?.on === true;
69
+ return { on, since: on ? (setting?.at ?? null) : null, features: features(command, env, on) };
70
+ };
71
+ /** `models local-only`: one switch that keeps every model call on this computer, and where each feature sends data. */
72
+ export const localOnlyCommand = (app, options) => {
73
+ 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");
74
+ annotate(local.command("show"), {
75
+ effects: LOCAL_READ,
76
+ output: { entity: "local_only" },
77
+ examples: [`${app.command} models local-only show`],
78
+ })
79
+ .summary("whether local only is on, and where each feature sends data")
80
+ .description("whether local only is on, and for each feature whether its data stays on this computer")
81
+ .action(function () {
82
+ options.output(itemOf(state(app.command, options.env())), this);
83
+ });
84
+ grantsAuthority(annotate(local.command("set"), {
85
+ effects: LOCAL_WRITE,
86
+ mcp: false,
87
+ output: { entity: "local_only" },
88
+ examples: [`${app.command} models local-only set on`, `${app.command} models local-only set off`],
89
+ }))
90
+ .description("turn local only on or off; only you turn it off")
91
+ .argument("<state>", "on or off")
92
+ .option("--from-app", "you did this in WireCat Desktop")
93
+ .action(function (given) {
94
+ if (given !== "on" && given !== "off")
95
+ throw new CliError("validation_error", "say on or off");
96
+ const env = options.env();
97
+ // An agent that turned it off would let records out for the owner; turning it on only refuses more.
98
+ if (given === "off" && (environmentOf(this).agent || agentOf(env)) && !this.opts().fromApp)
99
+ throw new CliError("permission_error", "only the owner turns local only off, not an agent", {
100
+ reason: "local-only.owner-only",
101
+ });
102
+ const before = readLocalOnly(env)?.on === true;
103
+ if (before !== (given === "on"))
104
+ writeLocalOnly(env, given === "on");
105
+ const now = state(app.command, env);
106
+ const out = now.features.filter((one) => one.refused).map((one) => one.title);
107
+ if (given === "on" && out.length)
108
+ options.diagnostic(`local only is on; these now refuse to send until they use this computer: ${out.join(", ")}`);
109
+ options.output(itemOf({ ...now, changed: before !== (given === "on") }), this);
110
+ });
111
+ return local;
112
+ };
@@ -308,7 +308,7 @@ export const jobsCommand = (messenger) => {
308
308
  const jobs = jobItems(jobsDir(messenger.app, context.env), context.profile, query);
309
309
  const { limit, offset } = pageOf(context.settings);
310
310
  const items = jobs.slice(offset, offset + limit);
311
- renderAnswer(this, context, pagedList("store jobs list", context.settings, { items, has_more: jobs.length > offset + limit }), () => items.map((one) => `${jobLine(one)}\n`).join(""));
311
+ renderAnswer(this, context, pagedList("store jobs list", context.settings, { items, hasMore: jobs.length > offset + limit }), () => items.map((one) => `${jobLine(one)}\n`).join(""));
312
312
  if (jobs.length === 0 && context.format === "pretty")
313
313
  context.renderer.note(`no ${query ? "matching " : ""}background sync jobs for this profile`);
314
314
  });
@@ -9,7 +9,8 @@ const titleWords = (node) => {
9
9
  if (/[*?]/.test(part))
10
10
  queryError("query.unsupported-operator", node.span, "title: matches part of a title: title:book or title:*book*");
11
11
  if (part.length < 3)
12
- throw new CliError("validation_error", `a chat search takes at least 3 characters, got "${part}"`);
12
+ throw new CliError("validation_error", `a chat search takes at least 3 characters, got "${part}" — write more of the title, or leave title: out ` +
13
+ "and read the list newest first", { reason: "query.short-text" });
13
14
  };
14
15
  /**
15
16
  * The store's chat columns. Online the messenger filters nothing, so `chatsService.list` refuses every field
@@ -1,5 +1,5 @@
1
- import { type CompletionSources } from "@wirecat/cli-base/completion";
2
- import { Command } from "commander";
1
+ import type { CompletionSources } from "@wirecat/cli-base/completion";
2
+ import type { Command } from "commander";
3
3
  import type { Configuration } from "../settings.js";
4
4
  import type { Messenger } from "./context.js";
5
5
  export interface CompletionOptions {
@@ -7,10 +7,7 @@ export interface CompletionOptions {
7
7
  sources?: (profile: string, words: string[], env: NodeJS.ProcessEnv) => CompletionSources | undefined;
8
8
  }
9
9
  /**
10
- * `tg complete zsh` prints the script a shell sources; the script then runs `tg complete -- <words>`
11
- * on every Tab, and this answers from the command registry.
12
- *
13
- * ⚠ **A Tab never connects and never creates anything.** Names come from the message store if it
14
- * exists — no store, no names — and nothing goes to stderr: a shell shows whatever it is given.
10
+ * `tg complete zsh`, as `appCompleteCommand` answers it, with the profile's chats and people from the message store
11
+ * if it exists — no store, no names.
15
12
  */
16
13
  export declare const completeCommand: (messenger: Messenger, config: Pick<Configuration, "configuredProfiles">, options?: CompletionOptions) => Command;