@wirecat/cli-core 0.617.0 → 0.619.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 (306) hide show
  1. package/CHANGELOG.md +406 -1
  2. package/README.md +1 -1
  3. package/THIRD_PARTY_NOTICES +3 -0
  4. package/dist/background/backfill.d.ts +21 -0
  5. package/dist/background/backfill.js +41 -0
  6. package/dist/background/daily-archive-timer.d.ts +1 -1
  7. package/dist/background/deliver.d.ts +5 -2
  8. package/dist/background/deliver.js +30 -12
  9. package/dist/background/report/messages.js +4 -1
  10. package/dist/background/report/render.d.ts +3 -1
  11. package/dist/background/report/render.js +3 -1
  12. package/dist/background/report/view.js +4 -1
  13. package/dist/background/schedules.d.ts +17 -0
  14. package/dist/background/schedules.js +21 -8
  15. package/dist/calendar/cli/answers.d.ts +1 -0
  16. package/dist/calendar/cli/answers.js +6 -1
  17. package/dist/calendar/cli/index.js +2 -14
  18. package/dist/calendar/cli/people-link.d.ts +3 -0
  19. package/dist/calendar/cli/people-link.js +23 -0
  20. package/dist/calendar/index.d.ts +1 -1
  21. package/dist/calendar/index.js +1 -1
  22. package/dist/calendar/mcp/index.d.ts +12 -12
  23. package/dist/cli/base-stages-command.d.ts +22 -0
  24. package/dist/cli/base-stages-command.js +174 -0
  25. package/dist/cli/command-runs.d.ts +2 -0
  26. package/dist/cli/command-runs.js +3 -1
  27. package/dist/cli/config-command.js +6 -1
  28. package/dist/cli/context.d.ts +5 -0
  29. package/dist/cli/context.js +1 -0
  30. package/dist/cli/group-lock.d.ts +42 -0
  31. package/dist/cli/group-lock.js +130 -0
  32. package/dist/cli/index.d.ts +10 -4
  33. package/dist/cli/index.js +10 -4
  34. package/dist/cli/messenger/backfill-command.js +27 -15
  35. package/dist/cli/messenger/contacts-command.js +10 -3
  36. package/dist/cli/messenger/context.js +1 -0
  37. package/dist/cli/messenger/doctor-command.js +3 -1
  38. package/dist/cli/messenger/models-command.js +1 -1
  39. package/dist/cli/messenger/serve-command.js +24 -2
  40. package/dist/cli/messenger/serve-outdated.d.ts +22 -0
  41. package/dist/cli/messenger/serve-outdated.js +100 -0
  42. package/dist/cli/messenger/store-maintenance-command.d.ts +22 -2
  43. package/dist/cli/messenger/store-maintenance-command.js +9 -4
  44. package/dist/cli/model-catalogue-command.d.ts +3 -1
  45. package/dist/cli/model-catalogue-command.js +46 -2
  46. package/dist/cli/profile.d.ts +8 -0
  47. package/dist/cli/profile.js +25 -0
  48. package/dist/cli/program.js +2 -0
  49. package/dist/cli/runs/search-query.d.ts +1 -1
  50. package/dist/cli/runs/search-query.js +4 -0
  51. package/dist/cli/runs/search.d.ts +5 -1
  52. package/dist/cli/runs/search.js +12 -1
  53. package/dist/cli/schedule/schedule-command.d.ts +9 -0
  54. package/dist/cli/schedule/schedule-command.js +13 -0
  55. package/dist/cli/search-left-out.d.ts +6 -1
  56. package/dist/cli/search-left-out.js +9 -4
  57. package/dist/cli/settings.d.ts +8 -0
  58. package/dist/cli/settings.js +17 -2
  59. package/dist/cli/shared-command-exports.d.ts +16 -0
  60. package/dist/cli/store-recover.d.ts +3 -3
  61. package/dist/cli/store-recover.js +47 -23
  62. package/dist/cli/store-settings.d.ts +2 -0
  63. package/dist/cli/store-settings.js +37 -9
  64. package/dist/crm/cli/index.js +38 -6
  65. package/dist/crm/group-hint.d.ts +8 -0
  66. package/dist/crm/group-hint.js +13 -0
  67. package/dist/crm/source.d.ts +12 -1
  68. package/dist/crm/sync.d.ts +31 -2
  69. package/dist/crm/sync.js +110 -3
  70. package/dist/crm/testing/acme-scenario.d.ts +40 -0
  71. package/dist/crm/testing/acme-scenario.js +170 -0
  72. package/dist/crm/testing/index.d.ts +1 -0
  73. package/dist/crm/testing/index.js +1 -0
  74. package/dist/crm/testing/source-contract.js +12 -0
  75. package/dist/crm/testing/source.d.ts +2 -0
  76. package/dist/crm/testing/source.js +1 -0
  77. package/dist/domain/addresses.d.ts +13 -0
  78. package/dist/domain/addresses.js +63 -0
  79. package/dist/domain/categories.d.ts +3 -0
  80. package/dist/domain/categories.js +2 -0
  81. package/dist/domain/crm.d.ts +23 -0
  82. package/dist/domain/crm.js +7 -0
  83. package/dist/domain/links.d.ts +17 -4
  84. package/dist/domain/links.js +20 -7
  85. package/dist/domain/mentions.d.ts +2 -12
  86. package/dist/domain/mentions.js +2 -19
  87. package/dist/domain/orders.d.ts +8 -1
  88. package/dist/domain/orders.js +6 -2
  89. package/dist/domain/phones.d.ts +26 -0
  90. package/dist/domain/phones.js +48 -0
  91. package/dist/domain/record-types.d.ts +1 -1
  92. package/dist/domain/record-types.js +1 -0
  93. package/dist/domain/records.d.ts +5 -0
  94. package/dist/domain/ref-summaries.d.ts +39 -0
  95. package/dist/domain/ref-summaries.js +51 -3
  96. package/dist/domain/relations.d.ts +27 -2
  97. package/dist/domain/relations.js +37 -3
  98. package/dist/domain/vcard.d.ts +2 -2
  99. package/dist/domain/vcard.js +4 -10
  100. package/dist/embeddings/models.d.ts +11 -3
  101. package/dist/embeddings/models.js +28 -4
  102. package/dist/entities/business-context.d.ts +149 -0
  103. package/dist/entities/business-context.js +192 -0
  104. package/dist/entities/contact-activity.d.ts +2 -0
  105. package/dist/entities/contact-activity.js +7 -1
  106. package/dist/entities/contact-context.d.ts +157 -0
  107. package/dist/entities/contact-context.js +2 -0
  108. package/dist/entities/deal.d.ts +10 -0
  109. package/dist/entities/deal.js +2 -0
  110. package/dist/entities/index.d.ts +23 -3
  111. package/dist/entities/index.js +5 -0
  112. package/dist/entities/mention.d.ts +4 -3
  113. package/dist/entities/mention.js +2 -1
  114. package/dist/entities/message-transfer.d.ts +4 -2
  115. package/dist/entities/message-transfer.js +2 -2
  116. package/dist/entities/model.d.ts +2 -2
  117. package/dist/entities/model.js +1 -1
  118. package/dist/entities/relationship.d.ts +4 -0
  119. package/dist/entities/relationship.js +4 -0
  120. package/dist/errors/reasons.js +44 -4
  121. package/dist/fetch/page.js +2 -1
  122. package/dist/index.d.ts +4 -3
  123. package/dist/index.js +4 -3
  124. package/dist/meetings/context-store.d.ts +2 -0
  125. package/dist/meetings/findings-rules.d.ts +4 -0
  126. package/dist/meetings/findings-rules.js +5 -2
  127. package/dist/meetings/mcp/index.d.ts +15 -15
  128. package/dist/meetings/result-items.d.ts +1 -0
  129. package/dist/meetings/result-items.js +1 -0
  130. package/dist/models/index.js +22 -5
  131. package/dist/runs/events.d.ts +11 -1
  132. package/dist/runs/events.js +3 -1
  133. package/dist/runs/log-attributes.js +4 -0
  134. package/dist/runs/log-events.js +2 -0
  135. package/dist/runs/recording.d.ts +3 -0
  136. package/dist/runs/recording.js +36 -12
  137. package/dist/runs/run.d.ts +12 -3
  138. package/dist/runs/run.js +32 -13
  139. package/dist/search/account-list.d.ts +6 -0
  140. package/dist/search/account-list.js +9 -3
  141. package/dist/search/groups.d.ts +68 -0
  142. package/dist/search/groups.js +172 -0
  143. package/dist/services/account-groups.d.ts +28 -0
  144. package/dist/services/account-groups.js +89 -0
  145. package/dist/services/archive.d.ts +7 -1
  146. package/dist/services/archive.js +19 -3
  147. package/dist/services/business-context.d.ts +113 -0
  148. package/dist/services/business-context.js +156 -0
  149. package/dist/services/communications.d.ts +50 -0
  150. package/dist/services/communications.js +140 -0
  151. package/dist/services/deal-context.d.ts +90 -0
  152. package/dist/services/deal-context.js +131 -0
  153. package/dist/services/deps.d.ts +2 -0
  154. package/dist/services/enrichment.d.ts +7 -2
  155. package/dist/services/enrichment.js +46 -5
  156. package/dist/services/events-search.js +2 -1
  157. package/dist/services/group-guard.d.ts +28 -0
  158. package/dist/services/group-guard.js +131 -0
  159. package/dist/services/index.d.ts +15 -2
  160. package/dist/services/index.js +9 -2
  161. package/dist/services/ingest.d.ts +12 -0
  162. package/dist/services/ingest.js +4 -0
  163. package/dist/services/link-scorers/chat-senders.js +39 -29
  164. package/dist/services/link-scorers/member-chats.js +4 -3
  165. package/dist/services/link-scorers/member-dialog.js +5 -7
  166. package/dist/services/link-scorers/scan.js +17 -8
  167. package/dist/services/link-scorers/shared.d.ts +6 -2
  168. package/dist/services/link-scorers/shared.js +6 -2
  169. package/dist/services/link-scorers/types.d.ts +2 -0
  170. package/dist/services/meaning-model.d.ts +7 -0
  171. package/dist/services/meaning-model.js +20 -0
  172. package/dist/services/meeting-context.d.ts +6 -1
  173. package/dist/services/meeting-context.js +12 -5
  174. package/dist/services/message-resolution.js +2 -3
  175. package/dist/services/messages-meaning.js +4 -5
  176. package/dist/services/messages-search.d.ts +5 -1
  177. package/dist/services/messages-search.js +1 -1
  178. package/dist/services/model-downloads.d.ts +1 -1
  179. package/dist/services/model-downloads.js +6 -4
  180. package/dist/services/money-context.d.ts +73 -0
  181. package/dist/services/money-context.js +77 -0
  182. package/dist/services/notes-search.d.ts +4 -1
  183. package/dist/services/notes-search.js +19 -7
  184. package/dist/services/organization-context.d.ts +80 -0
  185. package/dist/services/organization-context.js +154 -0
  186. package/dist/services/people.d.ts +22 -6
  187. package/dist/services/people.js +38 -8
  188. package/dist/services/person-business.d.ts +43 -0
  189. package/dist/services/person-business.js +67 -0
  190. package/dist/services/person-context.d.ts +9 -1
  191. package/dist/services/person-context.js +5 -3
  192. package/dist/services/proposals/kinds/identity-link.d.ts +4 -0
  193. package/dist/services/proposals/kinds/identity-link.js +48 -0
  194. package/dist/services/proposals/kinds/orders.js +1 -1
  195. package/dist/services/proposals/registry.js +2 -0
  196. package/dist/services/search-kind.d.ts +12 -5
  197. package/dist/services/search-kind.js +49 -10
  198. package/dist/services/text-model-choice.js +1 -1
  199. package/dist/store/accounts.d.ts +18 -0
  200. package/dist/store/accounts.js +18 -3
  201. package/dist/store/damage.d.ts +43 -10
  202. package/dist/store/damage.js +119 -36
  203. package/dist/store/decisions.js +3 -1
  204. package/dist/store/evidence-findings.d.ts +14 -0
  205. package/dist/store/evidence-findings.js +2 -0
  206. package/dist/store/exports.d.ts +2 -1
  207. package/dist/store/identity-links.d.ts +92 -0
  208. package/dist/store/identity-links.js +6 -0
  209. package/dist/store/index.d.ts +11 -5
  210. package/dist/store/index.js +5 -2
  211. package/dist/store/journal.d.ts +10 -0
  212. package/dist/store/journal.js +33 -0
  213. package/dist/store/marks.d.ts +19 -1
  214. package/dist/store/marks.js +23 -1
  215. package/dist/store/migrations.d.ts +1 -1
  216. package/dist/store/migrations.js +35 -12
  217. package/dist/store/people.d.ts +22 -0
  218. package/dist/store/people.js +15 -1
  219. package/dist/store/recover.d.ts +34 -0
  220. package/dist/store/recover.js +188 -6
  221. package/dist/store/refill.d.ts +28 -0
  222. package/dist/store/refill.js +120 -0
  223. package/dist/store/sqlite/accounts.js +2 -0
  224. package/dist/store/sqlite/base-stages.d.ts +122 -0
  225. package/dist/store/sqlite/base-stages.js +443 -0
  226. package/dist/store/sqlite/base-suggest.d.ts +13 -0
  227. package/dist/store/sqlite/base-suggest.js +62 -0
  228. package/dist/store/sqlite/business-contracts.js +10 -1
  229. package/dist/store/sqlite/clients.d.ts +7 -3
  230. package/dist/store/sqlite/clients.js +11 -7
  231. package/dist/store/sqlite/crm-settings.d.ts +12 -2
  232. package/dist/store/sqlite/crm-settings.js +56 -13
  233. package/dist/store/sqlite/crm.d.ts +13 -1
  234. package/dist/store/sqlite/crm.js +20 -4
  235. package/dist/store/sqlite/deals.d.ts +33 -0
  236. package/dist/store/sqlite/deals.js +42 -4
  237. package/dist/store/sqlite/decision-requests.js +7 -3
  238. package/dist/store/sqlite/email-index.js +17 -15
  239. package/dist/store/sqlite/evidence-findings.js +29 -5
  240. package/dist/store/sqlite/findings-core.js +4 -2
  241. package/dist/store/sqlite/identity-link-rows.d.ts +50 -0
  242. package/dist/store/sqlite/identity-link-rows.js +146 -0
  243. package/dist/store/sqlite/identity-proposals.d.ts +53 -0
  244. package/dist/store/sqlite/identity-proposals.js +234 -0
  245. package/dist/store/sqlite/knowledge.js +5 -3
  246. package/dist/store/sqlite/link-kinds.d.ts +1 -0
  247. package/dist/store/sqlite/link-kinds.js +1 -0
  248. package/dist/store/sqlite/link-row.d.ts +6 -0
  249. package/dist/store/sqlite/link-row.js +35 -0
  250. package/dist/store/sqlite/link-source.d.ts +10 -0
  251. package/dist/store/sqlite/link-source.js +16 -0
  252. package/dist/store/sqlite/manifest.js +1 -0
  253. package/dist/store/sqlite/meeting-context-links.js +9 -6
  254. package/dist/store/sqlite/memories.js +9 -7
  255. package/dist/store/sqlite/mentions.d.ts +4 -1
  256. package/dist/store/sqlite/mentions.js +14 -9
  257. package/dist/store/sqlite/migrations.generated.js +8 -0
  258. package/dist/store/sqlite/note-index.js +9 -7
  259. package/dist/store/sqlite/notes.d.ts +2 -3
  260. package/dist/store/sqlite/notes.js +6 -29
  261. package/dist/store/sqlite/open-store.js +3 -0
  262. package/dist/store/sqlite/open.js +11 -2
  263. package/dist/store/sqlite/orders.d.ts +2 -0
  264. package/dist/store/sqlite/orders.js +9 -3
  265. package/dist/store/sqlite/organization-categories.d.ts +18 -0
  266. package/dist/store/sqlite/organization-categories.js +34 -0
  267. package/dist/store/sqlite/organizations.d.ts +5 -1
  268. package/dist/store/sqlite/organizations.js +14 -4
  269. package/dist/store/sqlite/person-links.d.ts +19 -4
  270. package/dist/store/sqlite/person-links.js +49 -11
  271. package/dist/store/sqlite/person-match-scan.d.ts +13 -0
  272. package/dist/store/sqlite/person-match-scan.js +251 -0
  273. package/dist/store/sqlite/person-matcher.d.ts +16 -0
  274. package/dist/store/sqlite/person-matcher.js +32 -0
  275. package/dist/store/sqlite/proposed-actions.js +6 -0
  276. package/dist/store/sqlite/record-matching.d.ts +2 -8
  277. package/dist/store/sqlite/record-matching.js +8 -40
  278. package/dist/store/sqlite/record-projectors-phone.js +2 -1
  279. package/dist/store/sqlite/record-relationships.d.ts +52 -0
  280. package/dist/store/sqlite/record-relationships.js +243 -0
  281. package/dist/store/sqlite/record-run.d.ts +5 -0
  282. package/dist/store/sqlite/record-run.js +62 -2
  283. package/dist/store/sqlite/record-writes.d.ts +1 -1
  284. package/dist/store/sqlite/record-writes.js +4 -2
  285. package/dist/store/sqlite/records.js +27 -2
  286. package/dist/store/sqlite/ref-accounts.d.ts +13 -0
  287. package/dist/store/sqlite/ref-accounts.js +117 -0
  288. package/dist/store/sqlite/ref-summaries.js +5 -1
  289. package/dist/store/sqlite/relation-list.d.ts +4 -1
  290. package/dist/store/sqlite/relation-list.js +20 -2
  291. package/dist/store/sqlite/relation-proposals.d.ts +18 -1
  292. package/dist/store/sqlite/relation-proposals.js +53 -11
  293. package/dist/store/sqlite/relation-roles.js +12 -6
  294. package/dist/store/sqlite/reported-relations.d.ts +11 -1
  295. package/dist/store/sqlite/reported-relations.js +59 -18
  296. package/dist/store/sqlite/schema.d.ts +32 -0
  297. package/dist/store/sqlite/schema.js +3 -0
  298. package/dist/store/sqlite/transaction.d.ts +13 -0
  299. package/dist/store/sqlite/transaction.js +33 -15
  300. package/dist/store/store.d.ts +3 -0
  301. package/dist/store/store.js +5 -0
  302. package/dist/store/write-events.d.ts +18 -0
  303. package/dist/store/write-events.js +88 -0
  304. package/package.json +3 -3
  305. package/parity.json +11 -4
  306. package/schemas/records-envelope.v1.schema.json +3 -0
@@ -3,7 +3,7 @@ import { isCliError } from "@wirecat/cli-base";
3
3
  import { metaOf } from "@wirecat/cli-base/commands";
4
4
  import { providerErrorKey } from "../runs/events.js";
5
5
  import { startRecording, wasSettled } from "../runs/recording.js";
6
- import { KEEP_RUNS_FOR_DAYS, KEEP_SUCCESSFUL_RUNS_FOR_DAYS, RUNS_SIZE_LIMIT_MB } from "../runs/run.js";
6
+ import { KEEP_RUNS_FOR_DAYS, KEEP_STORE_RUNS_FOR_DAYS, KEEP_SUCCESSFUL_RUNS_FOR_DAYS, RUNS_SIZE_LIMIT_MB, } from "../runs/run.js";
7
7
  import { keepsSuccess, runContextOf } from "../runs/run-context.js";
8
8
  import { currentAttempt, runEvent } from "../runs/scope.js";
9
9
  import { environmentOf } from "./context.js";
@@ -19,6 +19,7 @@ export const runSettings = (flag, saved = {}) => {
19
19
  keepFailedRuns: record || flag !== false,
20
20
  keepRunsForDays: saved.keepRunsForDays ?? KEEP_RUNS_FOR_DAYS,
21
21
  keepSuccessfulRunsForDays: saved.keepSuccessfulRunsForDays ?? KEEP_SUCCESSFUL_RUNS_FOR_DAYS,
22
+ keepStoreRunsForDays: saved.keepStoreRunsForDays ?? KEEP_STORE_RUNS_FOR_DAYS,
22
23
  runsSizeLimitMb: saved.runsSizeLimitMb ?? RUNS_SIZE_LIMIT_MB,
23
24
  };
24
25
  };
@@ -69,6 +70,7 @@ const tracker = (options, typed) => {
69
70
  keepFailed: settings.keepFailedRuns,
70
71
  keepDays: settings.keepRunsForDays,
71
72
  keepSuccessDays: settings.keepSuccessfulRunsForDays,
73
+ keepStoreDays: settings.keepStoreRunsForDays,
72
74
  maxBytes: settings.runsSizeLimitMb * 1024 * 1024,
73
75
  trace: false,
74
76
  format,
@@ -14,7 +14,7 @@ import { knownBeside, knownPermissionKeys, unknownPermissionIssues, } from "./pe
14
14
  import { profileFree } from "./profile.js";
15
15
  import { fromFile, NONE_NAMED } from "./settings.js";
16
16
  import { nextStep } from "./steps.js";
17
- import { changeStoreSetting, isStoreSetting, offersStoreSetting, storeSettings, storeSettingsOf, } from "./store-settings.js";
17
+ import { changeStoreSetting, isOwnerOnlyStoreSetting, isStoreSetting, offersStoreSetting, storeSettings, storeSettingsOf, } from "./store-settings.js";
18
18
  export const configCommand = (app, config, { permissionKey = config.permissions, ownerOnly = {}, } = {}) => {
19
19
  const command = new Command("config").description("the settings in force, and where each one came from");
20
20
  // Only a messenger has bots, and with them the personal and bot sections of the file. Elsewhere the options stay
@@ -91,6 +91,11 @@ export const configCommand = (app, config, { permissionKey = config.permissions,
91
91
  if (isStoreSetting(setting) && !offersStoreSetting(app, setting))
92
92
  throw new CliError("validation_error", `no setting called "${setting}" here — it belongs to the messenger CLIs; one of: ${[...config.allSettings, ...storeSettingsOf(app)].join(", ")}`);
93
93
  if (isStoreSetting(setting)) {
94
+ // A guard against a change by mistake, not a boundary: an agent can drop its markers or write the store file.
95
+ if (isOwnerOnlyStoreSetting(setting) && (environmentOf(this).agent || agentOf(env)))
96
+ throw new CliError("permission_error", `${setting} is the owner's to set, in a terminal: an agent's run is stopped from changing it by mistake`, {
97
+ setting,
98
+ });
94
99
  if (everyone || personal || bot)
95
100
  throw new CliError("validation_error", `${setting} is store-wide — --defaults, --personal and --bot do not apply`);
96
101
  const lock = envName(app, "PROFILE_LOCK");
@@ -70,6 +70,11 @@ export interface BaseEnvironment {
70
70
  handled?: (event: MessageEvent) => void;
71
71
  /** A test's hook into `serve`: how long it waits after connecting before its catch-up pass. */
72
72
  startSyncDelayMs?: number;
73
+ /** A test's hook into `serve`: how often it checks for a newer store or install, and the package it checks. */
74
+ outdated?: {
75
+ everyMs?: number;
76
+ packageRoot?: string;
77
+ };
73
78
  /** Set by an MCP server on a command it runs for an agent (`runCommandForAgent`). */
74
79
  agent?: AgentRun;
75
80
  /** Set by `run()`: the words it was given, which a run keeps as `record_input` says (`maskArgv`). */
@@ -131,6 +131,7 @@ export const baseContext = (command, resolveSettings) => {
131
131
  ...(settings.keepSuccessfulRunsForDays === undefined
132
132
  ? {}
133
133
  : { keepSuccessDays: settings.keepSuccessfulRunsForDays }),
134
+ ...(settings.keepStoreRunsForDays === undefined ? {} : { keepStoreDays: settings.keepStoreRunsForDays }),
134
135
  ...(settings.runsSizeLimitMb === undefined ? {} : { maxBytes: settings.runsSizeLimitMb * 1024 * 1024 }),
135
136
  processRun: !environment.agent,
136
137
  format,
@@ -0,0 +1,42 @@
1
+ import type { Command } from "commander";
2
+ import { type SimpleReference } from "../domain/references.js";
3
+ import { type AppIdentity } from "../ports/app.js";
4
+ import { type MessageStore } from "../store/store.js";
5
+ /**
6
+ * Marks a command, and every command under it, as one that keeps to the run's account group: it scopes its reads
7
+ * and writes with `scopeToGroup`. Under `<PREFIX>_GROUP_LOCK` every other command is refused (WC-ACCT-13).
8
+ */
9
+ export declare const groupAware: <T extends Command>(command: T) => T;
10
+ export declare const isGroupAware: (command: Command) => boolean;
11
+ /**
12
+ * What a bare id names: a referenced thing's kind, a proposed action (`action`, as `actions confirm 17` takes it), or
13
+ * a proposal id of the review registry (`proposal`: `17070`, `17080/f1`, `link:17`, `fact:512`).
14
+ */
15
+ export type RefKind = SimpleReference | "action" | "proposal";
16
+ /**
17
+ * The kind of thing a bare id names, per argument (by its name) or option (by its long flag):
18
+ * `refKinds(show, { organization: "organization", "--note": "note" })`. An argument or a `--<kind>` option named
19
+ * after a kind needs no entry. Under the lock a bare value there is checked as `<kind>:<value>`; a command that
20
+ * declares nothing has any other argument value refused, since what it names is unknown (`1e0`, `+1`, `link:1`).
21
+ * `{}` says no argument takes an id, so free text passes.
22
+ */
23
+ export declare const refKinds: <T extends Command>(command: T, kinds: Readonly<Record<string, RefKind>>) => T;
24
+ /**
25
+ * Every reference typed into the run: each word of each argument and option value that is a reference, and each bare
26
+ * id in a position whose kind is known, as `<kind>:<id>`. `unknown` holds every other argument value of a command
27
+ * that declares no kinds.
28
+ */
29
+ export declare const referencesIn: (command: Command) => {
30
+ references: string[];
31
+ unknown: string[];
32
+ };
33
+ /**
34
+ * Under `<PREFIX>_GROUP_LOCK`, refuses a command that does not keep to a group, and a reference whose thing belongs
35
+ * only to accounts outside the group. A thing no account brought is the owner's and passes in every group, a note
36
+ * written in memo included; a person passes when one of their identities is in the group.
37
+ */
38
+ export declare const refuseOutsideGroup: (command: Command, { app, env, store }: {
39
+ app: AppIdentity;
40
+ env: NodeJS.ProcessEnv;
41
+ store?: MessageStore;
42
+ }) => Promise<void>;
@@ -0,0 +1,130 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { INTERNAL_NOTES } from "../domain/providers.js";
3
+ import { looksLikeReference, SIMPLE_REFERENCES } from "../domain/references.js";
4
+ import { envName } from "../ports/app.js";
5
+ import { inGroupOf } from "../search/groups.js";
6
+ import { groupLockOf, listContextOf } from "../services/search-kind.js";
7
+ import { openStore } from "../store/store.js";
8
+ import { PROFILE_FREE } from "./profile.js";
9
+ const keepsToGroup = new WeakSet();
10
+ /**
11
+ * Marks a command, and every command under it, as one that keeps to the run's account group: it scopes its reads
12
+ * and writes with `scopeToGroup`. Under `<PREFIX>_GROUP_LOCK` every other command is refused (WC-ACCT-13).
13
+ */
14
+ export const groupAware = (command) => {
15
+ keepsToGroup.add(command);
16
+ return command;
17
+ };
18
+ export const isGroupAware = (command) => {
19
+ let top;
20
+ for (let at = command; at?.parent; at = at.parent) {
21
+ if (keepsToGroup.has(at))
22
+ return true;
23
+ top = at;
24
+ }
25
+ return top !== undefined && PROFILE_FREE.has(top.name());
26
+ };
27
+ const valuesOf = (value) => typeof value === "string" ? [value] : Array.isArray(value) ? value.flatMap(valuesOf) : [];
28
+ const declared = new WeakMap();
29
+ /**
30
+ * The kind of thing a bare id names, per argument (by its name) or option (by its long flag):
31
+ * `refKinds(show, { organization: "organization", "--note": "note" })`. An argument or a `--<kind>` option named
32
+ * after a kind needs no entry. Under the lock a bare value there is checked as `<kind>:<value>`; a command that
33
+ * declares nothing has any other argument value refused, since what it names is unknown (`1e0`, `+1`, `link:1`).
34
+ * `{}` says no argument takes an id, so free text passes.
35
+ */
36
+ export const refKinds = (command, kinds) => {
37
+ declared.set(command, kinds);
38
+ return command;
39
+ };
40
+ const isSimpleReference = (name) => SIMPLE_REFERENCES.includes(name);
41
+ const kindAt = (command, name, implicit) => declared.get(command)?.[name] ?? (isSimpleReference(implicit) ? implicit : undefined);
42
+ /**
43
+ * Every reference typed into the run: each word of each argument and option value that is a reference, and each bare
44
+ * id in a position whose kind is known, as `<kind>:<id>`. `unknown` holds every other argument value of a command
45
+ * that declares no kinds.
46
+ */
47
+ export const referencesIn = (command) => {
48
+ const references = new Set();
49
+ const unknown = [];
50
+ const typed = (value, kind, onBare) => {
51
+ for (const word of value.split(/[\s,]+/).filter(Boolean)) {
52
+ const stored = /^([1-9]\d*)(?:\/[\w-]+)?$/.exec(word)?.[1];
53
+ const proposalKind = kind === "action" || kind === "proposal";
54
+ if (looksLikeReference(word) || (proposalKind && PROPOSAL_REF.test(word)))
55
+ references.add(word);
56
+ else if (proposalKind && stored)
57
+ references.add(`action:${stored}`);
58
+ // A key-document suggestion is a link between the document and its project, so both ends are checked.
59
+ else if (kind === "proposal" && /^key:[1-9]\d*$/.test(word))
60
+ references.add(`link:${word.slice(4)}`);
61
+ // A close suggestion is its task's, which the owner made; the task's evidence is stripped where it is shown.
62
+ else if (kind === "proposal" && word.startsWith("close:"))
63
+ references.add(`task:${word.slice(6)}`);
64
+ else if (kind !== undefined && kind !== "proposal" && !word.includes(":"))
65
+ references.add(`${kind}:${word}`);
66
+ else
67
+ onBare?.();
68
+ }
69
+ };
70
+ command.registeredArguments.forEach((argument, at) => {
71
+ const name = argument.name();
72
+ const kind = kindAt(command, name, name);
73
+ for (const value of valuesOf(command.processedArgs[at] ?? command.args[at]))
74
+ typed(value, kind, () => {
75
+ // A proposal id of no kind the lock knows cannot be checked, so it is refused even where kinds are declared.
76
+ const named = `<${name}> ${value}`;
77
+ if ((!declared.has(command) || kind === "proposal") && !unknown.includes(named))
78
+ unknown.push(named);
79
+ });
80
+ });
81
+ for (const option of command.options) {
82
+ const long = option.long ?? "";
83
+ for (const value of valuesOf(command.getOptionValue(option.attributeName())))
84
+ typed(value, kindAt(command, long, long.replace(/^--/, "")));
85
+ }
86
+ return { references: [...references], unknown };
87
+ };
88
+ const PROPOSAL_REF = /^(action|link):[1-9]\d*$/;
89
+ const pathOf = (command) => {
90
+ const words = [];
91
+ for (let at = command; at?.parent; at = at.parent)
92
+ words.unshift(at.name());
93
+ return words.join(" ");
94
+ };
95
+ /**
96
+ * Under `<PREFIX>_GROUP_LOCK`, refuses a command that does not keep to a group, and a reference whose thing belongs
97
+ * only to accounts outside the group. A thing no account brought is the owner's and passes in every group, a note
98
+ * written in memo included; a person passes when one of their identities is in the group.
99
+ */
100
+ export const refuseOutsideGroup = async (command, { app, env, store }) => {
101
+ const lock = groupLockOf(app, env);
102
+ if (lock === undefined)
103
+ return;
104
+ const locked = `this process is locked to group ${lock} (${envName(app, "GROUP_LOCK")})`;
105
+ if (!isGroupAware(command))
106
+ throw new CliError("permission_error", `${locked} — \`${app.command} ${pathOf(command)}\` does not keep to a group, so it does not run`, { group: lock });
107
+ const { references, unknown } = referencesIn(command);
108
+ if (unknown.length)
109
+ throw new CliError("permission_error", `${locked} — \`${app.command} ${pathOf(command)}\` takes ${unknown.join(", ")} as an id of a kind it does not ` +
110
+ "declare, so it cannot be checked against the group", { group: lock });
111
+ if (references.length === 0)
112
+ return;
113
+ const opened = store ?? (await openStore({ env, command: app.command, version: app.version }));
114
+ try {
115
+ const context = await listContextOf(opened, { provider: "notes", account: INTERNAL_NOTES }, app, undefined, env);
116
+ const inGroup = inGroupOf(context, lock);
117
+ for (const reference of references) {
118
+ const ends = await opened.refs.ends(reference);
119
+ if (ends?.some((end) => end.length > 0 && !end.some(inGroup)))
120
+ throw new CliError("permission_error", `${locked} — ${reference} belongs to an account outside it`, {
121
+ group: lock,
122
+ reference,
123
+ });
124
+ }
125
+ }
126
+ finally {
127
+ if (!store)
128
+ await opened.close();
129
+ }
130
+ };
@@ -1,7 +1,9 @@
1
1
  export { AI_ENTRIES, AI_SETTING_KEYS, type AISettings, resolveAISettings } from "../analysis/settings.js";
2
- export { AGENT_INPUT_MAX_CHARS, type AgentCli, type AgentInput } from "../background/schedules.js";
2
+ export { AGENT_INPUT_MAX_CHARS, type AgentCli, type AgentInput, readSchedule, SCHEDULE_DEFAULTS, scheduleFile, spentToday, } from "../background/schedules.js";
3
3
  export { parseDuration } from "../domain/duration.js";
4
- export { openOf, PROFILE_PLACEHOLDER, type ProfilesFor, type RefOpen, type RefSummary, refLabel, } from "../domain/ref-summaries.js";
4
+ export { openOf, PROFILE_PLACEHOLDER, type ProfilesFor, profilesOn, type RefOpen, type RefSummary, refLabel, storedProfilesFor, type WritesWith, writesWithOf, } from "../domain/ref-summaries.js";
5
+ /** The shared entities `person_context`, `organization_context`, `deal_context` and `deal_context.brief`. */
6
+ export { dealBrief as dealBriefSchema, dealContext as dealContextSchema, organizationContext as organizationContextSchema, personContext as personContextSchema, } from "../entities/business-context.js";
5
7
  export { botTemplate } from "../entities/list-results.js";
6
8
  export { syncProgress } from "../entities/store-records.js";
7
9
  export { isCliFailure, isCommanderFailure, storeDamaged } from "../errors/failures.js";
@@ -49,6 +51,7 @@ export { answerEntity } from "./answer-entity.js";
49
51
  export { type AppDoctorOptions, appDoctorReport } from "./app-doctor-command.js";
50
52
  export type { AppMcpOptions } from "./app-mcp-command.js";
51
53
  export { actorOf } from "./author.js";
54
+ export { type BaseStagesCommandOptions, baseStagesCommand } from "./base-stages-command.js";
52
55
  export type { ApiCommandInput, ApiCommands } from "./bot/api.js";
53
56
  export { apiFlagOf, apiJson, apiOptionKey, apiPlainJson, checkApiBody, checkApiParameter, parseApiJson, readApiBody, } from "./bot/api-input.js";
54
57
  export { prepareRpcApiBody, type RpcApiBody } from "./bot/api-rpc.js";
@@ -81,6 +84,7 @@ export { type AnswerOutput, answerSchema, type Body, type ItemBody, isBody, item
81
84
  export { withAbort } from "./execution.js";
82
85
  export { parseEvidenceFindingsJson, parseMailFindingsJson, parseMeetingFindingsJson, readMailFindingsJson, } from "./findings-input.js";
83
86
  export { askSetupQuestions, asksAtStart, type FirstRun, type FirstRunIo, setupAtStart, systemLanguage, } from "./first-run.js";
87
+ export { groupAware, isGroupAware, type RefKind, referencesIn, refKinds, refuseOutsideGroup } from "./group-lock.js";
84
88
  export { checkGuide, checkStep, type GuideOptions, type GuideReference, type GuideStep, loadScenarios, MEMO_SCENARIOS, type Scenario, shellProblems, } from "./guide.js";
85
89
  export { type CommandHelp, commandHelp, commandHelpMarkdown, commandHelpText, exampleReport, type NextChoice, nextUsually, } from "./help/command-help.js";
86
90
  export { commandsText } from "./help/commands-text.js";
@@ -112,6 +116,7 @@ export { allAnswer, allHitItem, coverageGaps, type HitItem, type MessageHitItem,
112
116
  export { SEARCHES_QUERY } from "./messenger/searches-command.js";
113
117
  export { servingProfiles } from "./messenger/serve-command.js";
114
118
  export { DAY_MS, FIRST_FETCH_MS, type MemberFetches, memberFetches } from "./messenger/serve-members.js";
119
+ export { OUTDATED_CHECK_MS, outdatedReason, ownPackageRoot, watchOutdated } from "./messenger/serve-outdated.js";
115
120
  export { STEMS_EVERY_MS, STEMS_SLICE_MS, type StemFills, stemFills } from "./messenger/serve-stems.js";
116
121
  export type { Running, ServerOptions, ServerProcess, ServerSystem } from "./messenger/server-command.js";
117
122
  export { storeSummary } from "./messenger/store-maintenance-command.js";
@@ -121,14 +126,15 @@ export { MODEL_CATALOGUE_QUERY, type ModelCatalogueOptions } from "./model-catal
121
126
  export { writeNewFile } from "./new-file.js";
122
127
  export { positiveCount, window, withPaging } from "./paging.js";
123
128
  export { type CommandPermissions, type ConditionalKey, commandPathKey, commandPermissions, knownBeside, knownPermissionKeys, type PermissionKeyOf, type PermissionKeySource, refuseUnknownPermissionKeys, unknownPermissionIssues, unknownPermissionKeys, } from "./permission-keys.js";
124
- export { asFirstWord, commandWords, liftProfile, profileFree, refuseCommandName, rootOf, takesProfile, usableProfileName, } from "./profile.js";
129
+ export { asFirstWord, commandWords, liftProfile, profileFree, refuseCommandName, rootOf, runGroup, takesProfile, usableProfileName, } from "./profile.js";
125
130
  export { ProfileTokenStore, type ProfileTokenStoreOptions, type TokenStorage } from "./profile-token.js";
126
131
  export { createProgram, type ProgramDefinition, type ProgramOptions, type RunOptions, run } from "./program.js";
127
132
  export { type ProjectTextHints, projectAnswerParts, projectCutoffTime, projectEvidenceText, projectWindowOf, withSyncCommands, } from "./project-evidence.js";
128
133
  export { type ProjectStatusHints, type ProjectStatusItem, projectStatusAnswer, projectStatusRow, projectStatusSchema, projectStatusText, } from "./project-status.js";
129
134
  export { STATUS_ROWS, STATUS_SIGNAL_ROWS } from "./project-status-rows.js";
130
135
  export { fieldsOf, projectFields } from "./result-fields.js";
131
- export { SCHEDULE_SETTINGS, type ScheduleHost, type ScheduleLimits, scheduleLimitsOf, } from "./schedule/schedule-command.js";
136
+ export { backfillScheduleRun, SCHEDULE_SETTINGS, type ScheduleHost, type ScheduleLimits, scheduleLimitsOf, } from "./schedule/schedule-command.js";
137
+ export { deniedKinds, deniedKindsOf, type LeftOut, type SearchedKind } from "./search-left-out.js";
132
138
  export { type DeclaredSetting, type SettingRow, settingRows, withSettingDefaults } from "./setting-defaults.js";
133
139
  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";
134
140
  export { type PermissionAnswer, readSetupAnswers, type SetupAnswers, setupPermissionCeiling } from "./setup-answers.js";
package/dist/cli/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  export { AI_ENTRIES, AI_SETTING_KEYS, resolveAISettings } from "../analysis/settings.js";
2
- export { AGENT_INPUT_MAX_CHARS } from "../background/schedules.js";
2
+ export { AGENT_INPUT_MAX_CHARS, readSchedule, SCHEDULE_DEFAULTS, scheduleFile, spentToday, } from "../background/schedules.js";
3
3
  export { parseDuration } from "../domain/duration.js";
4
- export { openOf, PROFILE_PLACEHOLDER, refLabel, } from "../domain/ref-summaries.js";
4
+ export { openOf, PROFILE_PLACEHOLDER, profilesOn, refLabel, storedProfilesFor, writesWithOf, } from "../domain/ref-summaries.js";
5
+ /** The shared entities `person_context`, `organization_context`, `deal_context` and `deal_context.brief`. */
6
+ export { dealBrief as dealBriefSchema, dealContext as dealContextSchema, organizationContext as organizationContextSchema, personContext as personContextSchema, } from "../entities/business-context.js";
5
7
  export { botTemplate } from "../entities/list-results.js";
6
8
  export { syncProgress } from "../entities/store-records.js";
7
9
  export { isCliFailure, isCommanderFailure, storeDamaged } from "../errors/failures.js";
@@ -43,6 +45,7 @@ export { evaluateAgent, } from "./agent-evaluation.js";
43
45
  export { answerEntity } from "./answer-entity.js";
44
46
  export { appDoctorReport } from "./app-doctor-command.js";
45
47
  export { actorOf } from "./author.js";
48
+ export { baseStagesCommand } from "./base-stages-command.js";
46
49
  export { apiFlagOf, apiJson, apiOptionKey, apiPlainJson, checkApiBody, checkApiParameter, parseApiJson, readApiBody, } from "./bot/api-input.js";
47
50
  export { prepareRpcApiBody } from "./bot/api-rpc.js";
48
51
  export { botContext, botWords } from "./bot/context.js";
@@ -73,6 +76,7 @@ export { answerSchema, isBody, itemAnswer, itemOf, jsonlRecords, judgedAnswer, l
73
76
  export { withAbort } from "./execution.js";
74
77
  export { parseEvidenceFindingsJson, parseMailFindingsJson, parseMeetingFindingsJson, readMailFindingsJson, } from "./findings-input.js";
75
78
  export { askSetupQuestions, asksAtStart, setupAtStart, systemLanguage, } from "./first-run.js";
79
+ export { groupAware, isGroupAware, referencesIn, refKinds, refuseOutsideGroup } from "./group-lock.js";
76
80
  export { checkGuide, checkStep, loadScenarios, MEMO_SCENARIOS, shellProblems, } from "./guide.js";
77
81
  export { commandHelp, commandHelpMarkdown, commandHelpText, exampleReport, nextUsually, } from "./help/command-help.js";
78
82
  export { commandsText } from "./help/commands-text.js";
@@ -103,6 +107,7 @@ export { allAnswer, allHitItem, coverageGaps, messageHitItem, noteHitItem, shown
103
107
  export { SEARCHES_QUERY } from "./messenger/searches-command.js";
104
108
  export { servingProfiles } from "./messenger/serve-command.js";
105
109
  export { DAY_MS, FIRST_FETCH_MS, memberFetches } from "./messenger/serve-members.js";
110
+ export { OUTDATED_CHECK_MS, outdatedReason, ownPackageRoot, watchOutdated } from "./messenger/serve-outdated.js";
106
111
  export { STEMS_EVERY_MS, STEMS_SLICE_MS, stemFills } from "./messenger/serve-stems.js";
107
112
  export { storeSummary } from "./messenger/store-maintenance-command.js";
108
113
  export { stored } from "./messenger/stored.js";
@@ -111,14 +116,15 @@ export { MODEL_CATALOGUE_QUERY } from "./model-catalogue-command.js";
111
116
  export { writeNewFile } from "./new-file.js";
112
117
  export { positiveCount, window, withPaging } from "./paging.js";
113
118
  export { commandPathKey, commandPermissions, knownBeside, knownPermissionKeys, refuseUnknownPermissionKeys, unknownPermissionIssues, unknownPermissionKeys, } from "./permission-keys.js";
114
- export { asFirstWord, commandWords, liftProfile, profileFree, refuseCommandName, rootOf, takesProfile, usableProfileName, } from "./profile.js";
119
+ export { asFirstWord, commandWords, liftProfile, profileFree, refuseCommandName, rootOf, runGroup, takesProfile, usableProfileName, } from "./profile.js";
115
120
  export { ProfileTokenStore } from "./profile-token.js";
116
121
  export { createProgram, run } from "./program.js";
117
122
  export { projectAnswerParts, projectCutoffTime, projectEvidenceText, projectWindowOf, withSyncCommands, } from "./project-evidence.js";
118
123
  export { projectStatusAnswer, projectStatusRow, projectStatusSchema, projectStatusText, } from "./project-status.js";
119
124
  export { STATUS_ROWS, STATUS_SIGNAL_ROWS } from "./project-status-rows.js";
120
125
  export { fieldsOf, projectFields } from "./result-fields.js";
121
- export { SCHEDULE_SETTINGS, scheduleLimitsOf, } from "./schedule/schedule-command.js";
126
+ export { backfillScheduleRun, SCHEDULE_SETTINGS, scheduleLimitsOf, } from "./schedule/schedule-command.js";
127
+ export { deniedKinds, deniedKindsOf } from "./search-left-out.js";
122
128
  export { settingRows, withSettingDefaults } from "./setting-defaults.js";
123
129
  export { count, first, flag, fromFile, NONE_NAMED, namedProfile, plain, settingsFor, } from "./settings.js";
124
130
  export { readSetupAnswers, setupPermissionCeiling } from "./setup-answers.js";
@@ -34,19 +34,25 @@ const ALL_SINCE = "90d";
34
34
  /** What a background `--all` job is listed under; no chat argument is spelled like it. */
35
35
  const ALL_CHATS = "--all";
36
36
  /** Says where the history limits (history_* settings) stopped the read, so an agent does not take it for all. */
37
- const limitedLine = (result, status) => {
37
+ const limitedLines = (result, status) => {
38
38
  if ("items" in result) {
39
- const { groupTooLarge = 0, olderThanWindow = 0 } = result.limited ?? {};
40
- if (groupTooLarge + olderThanWindow === 0)
41
- return undefined;
42
- return (`the history limits (history_* settings) left ${groupTooLarge} big group(s) unread and read ${olderThanWindow} ` +
43
- `chat(s) only to the window's start — \`${status}\` lists them; \`messages sync <chat> --full-history\` reads one in full`);
39
+ const { groupTooLarge = 0, olderThanWindow = 0, muted = 0 } = result.limited ?? {};
40
+ const lines = [];
41
+ if (groupTooLarge + olderThanWindow > 0)
42
+ lines.push(`the history limits (history_* settings) left ${groupTooLarge} big group(s) unread and read ${olderThanWindow} ` +
43
+ `chat(s) only to the window's start — \`${status}\` lists them; \`messages sync <chat> --full-history\` reads one in full`);
44
+ if (muted > 0)
45
+ lines.push(`${muted} muted chat(s) not read — --with-muted or history_muted true reads them; \`messages sync <chat>\` reads one, and ` +
46
+ "`--full-history` keeps it in every --all");
47
+ return lines;
44
48
  }
45
49
  if (result.limited === "group_too_large")
46
- return "not read: a group above history_group_members_max — `--full-history` reads it and keeps it in full";
50
+ return ["not read: a group above history_group_members_max — `--full-history` reads it and keeps it in full"];
47
51
  if (result.limited === "older_than_window")
48
- return "read to the history window's start (history_dialog_days / history_group_days) — `--full-history` reads further";
49
- return undefined;
52
+ return [
53
+ "read to the history window's start (history_dialog_days / history_group_days) — `--full-history` reads further",
54
+ ];
55
+ return [];
50
56
  };
51
57
  export const syncCommand = (messenger) => {
52
58
  const fetching = messenger.fetching ?? FETCHING;
@@ -60,7 +66,8 @@ export const syncCommand = (messenger) => {
60
66
  .description("bring a chat's history in the local store up to date, newest first; run it again to continue; --all syncs every chat; " +
61
67
  'with --json, stderr carries progress lines: {"event":"progress","step":"sync","chats","chats_done","fetched"}, counts only')
62
68
  .argument("[chat]", messenger.chatArgument)
63
- .option("--all", `every chat, most recently active first — what search needs; the last ${ALL_SINCE} unless --since-time or --last`)
69
+ .option("--all", `every chat, most recently active first — what search needs; the last ${ALL_SINCE} unless --since-time or --last; ` +
70
+ "muted chats only with --with-muted or history_muted true")
64
71
  .option("--limit <n>", `at most this many messages in this run, per chat with --all; ${fetching.maxPages * fetching.page} if not given`, wholeNumber)
65
72
  .option("--page-size <n>", `how many messages one request asks for; ${fetching.page} if not given`, wholeNumber)
66
73
  .option("--pause <duration>", fetching.jitter
@@ -74,16 +81,19 @@ export const syncCommand = (messenger) => {
74
81
  .option("--catch-up-messages <n>", "skip a graph rebuild larger than this many messages", wholeNumber)
75
82
  .option("--catch-up-time <duration>", "local preparation time budget, 30s by default")
76
83
  .option("--full-history", "read and keep this chat's history in full from now on, past the history limits (history_* settings)")
84
+ .option("--with-muted", "with --all: also read the chats the owner muted, as history_muted true does")
77
85
  .option("--background", "run as a job that outlives this command; `store jobs show` follows it")
78
86
  .option("--dry-run", "only estimate how many messages, requests and minutes a full fetch would still take — from the store, no request")
79
87
  .action(async function (chat) {
80
- const { all, pause, sinceTime: since, last, background, dryRun: estimate, catchUp, catchUpChunks, catchUpMessages, catchUpTime, fullHistory: include, ...sizes } = this.opts();
88
+ const { all, pause, sinceTime: since, last, background, dryRun: estimate, catchUp, catchUpChunks, catchUpMessages, catchUpTime, fullHistory: include, withMuted, ...sizes } = this.opts();
81
89
  if ((chat === undefined) === (all !== true))
82
90
  throw new CliError("validation_error", "name a chat, or --all for every chat");
83
91
  if (all && estimate)
84
92
  throw new CliError("validation_error", "--dry-run prices one chat; not with --all");
85
93
  if (include && chat === undefined)
86
94
  throw new CliError("validation_error", "--full-history keeps one chat: name it");
95
+ if (withMuted && all !== true)
96
+ throw new CliError("validation_error", "--with-muted is for --all; a chat named is read even when muted");
87
97
  if (all && messenger.history === "store") {
88
98
  throw new CliError("validation_error", `--all walks the messenger's chat list, and ${messenger.name ?? messenger.app.command} pushes its chats ` +
89
99
  `instead — keep \`${lineOf(this, "serve")}\` running${messenger.historyOnDemand ? ", or name one chat" : ""}`);
@@ -137,6 +147,7 @@ export const syncCommand = (messenger) => {
137
147
  pageSize,
138
148
  pause,
139
149
  catchUp: prepare,
150
+ ...(withMuted ? { withMuted } : {}),
140
151
  ...(catchUpChunks === undefined ? {} : { catchUpChunks }),
141
152
  ...(catchUpMessages === undefined ? {} : { catchUpMessages }),
142
153
  ...(catchUpTime === undefined ? {} : { catchUpTime }),
@@ -167,6 +178,7 @@ export const syncCommand = (messenger) => {
167
178
  pageSize,
168
179
  pauseMs,
169
180
  ...(include ? { fullHistory: true } : {}),
181
+ ...(withMuted ? { withMuted } : {}),
170
182
  catchUp: prepare ? preparation : false,
171
183
  ...(sinceMs === undefined ? {} : { sinceMs }),
172
184
  ...(last === undefined ? {} : { last }),
@@ -218,9 +230,8 @@ export const syncCommand = (messenger) => {
218
230
  ],
219
231
  meta: window.meta,
220
232
  }));
221
- const limitedNote = limitedLine(result, lineOf(this, "store status"));
222
- if (limitedNote)
223
- context.renderer.note(limitedNote);
233
+ for (const line of limitedLines(result, lineOf(this, "store status")))
234
+ context.renderer.note(line);
224
235
  if (tasks?.held)
225
236
  context.renderer.note(`the first sync left ${tasks.held} possible task(s) in ${tasks.heldChats ?? 0} chat(s) unopened ` +
226
237
  `(config task_first_pass_per_chat) — ask the owner, then \`${lineOf(this, "tasks scan <chat>")}\``);
@@ -376,7 +387,7 @@ const findJob = (messenger, context, id) => {
376
387
  }
377
388
  return job;
378
389
  };
379
- const fetchArgv = (command, { chat, limit, pageSize, pause, since, last, catchUp, catchUpChunks, catchUpMessages, catchUpTime, }) => {
390
+ const fetchArgv = (command, { chat, limit, pageSize, pause, since, last, catchUp, withMuted, catchUpChunks, catchUpMessages, catchUpTime, }) => {
380
391
  const { timeout } = command.optsWithGlobals();
381
392
  return [
382
393
  "messages",
@@ -391,6 +402,7 @@ const fetchArgv = (command, { chat, limit, pageSize, pause, since, last, catchUp
391
402
  ...(since === undefined ? [] : ["--since-time", since]),
392
403
  ...(last === undefined ? [] : ["--last", String(last)]),
393
404
  ...(catchUp === undefined ? [] : [catchUp ? "--catch-up" : "--no-catch-up"]),
405
+ ...(withMuted ? ["--with-muted"] : []),
394
406
  ...(catchUpChunks === undefined ? [] : ["--catch-up-chunks", String(catchUpChunks)]),
395
407
  ...(catchUpMessages === undefined ? [] : ["--catch-up-messages", String(catchUpMessages)]),
396
408
  ...(catchUpTime === undefined ? [] : ["--catch-up-time", catchUpTime]),
@@ -11,6 +11,7 @@ import { withoutPhone } from "../../services/people.js";
11
11
  import { CHAT_MESSAGES, CONTEXT_BYTES, CONTEXT_MESSAGES } from "../../services/person-context.js";
12
12
  import { SCOPES, TIMELINE_ITEMS } from "../../services/person-timeline.js";
13
13
  import { readSecret } from "../../terminal/prompt.js";
14
+ import { actorOf } from "../author.js";
14
15
  import { secretInputOf } from "../context.js";
15
16
  import { FETCH, LOCAL_WRITE, REMOTE_READ } from "../effects.js";
16
17
  import { itemOf, listOf, renderAnswer, snakeKeys } from "../envelope.js";
@@ -256,18 +257,24 @@ export const contactsCommand = (messenger) => {
256
257
  .description("record that two people in the store are one person — the same name is never enough")
257
258
  .argument("<person>", "their id, @username, or part of their name")
258
259
  .argument("<other>", "the same in another messenger of the store, as <messenger>:<person> — max:Ana; me: it is you, as zoom:<id> me")
260
+ .option("--reason <text>", "why they are one person; an agent's link is a proposal and needs it")
259
261
  .action(async function (person, other) {
260
262
  const context = messengerContext(this, messenger);
261
- const linked = await context.withServices((services) => services.people.link(person, other));
263
+ const { reason } = this.opts();
264
+ const by = actorOf(this);
265
+ const linked = await context.withServices((services) => services.people.link(person, other, { by, reason }));
262
266
  renderAnswer(this, context, itemOf(snakeKeys(linked)));
263
- context.renderer.success(`${linked.identities.length} identities are now one person`);
267
+ if (linked.proposal === undefined)
268
+ context.renderer.success(`${linked.identities.length} identities are now one person`);
269
+ else
270
+ context.renderer.note(`proposed as ${linked.proposal}: only the owner links them`);
264
271
  });
265
272
  annotate(contacts.command("unlink"), { effects: LOCAL_WRITE, output: { entity: "linked_person" } })
266
273
  .description("undo contacts link for one identity: it is a person of its own again")
267
274
  .argument("<person>", "their id, @username, or part of their name; <messenger>:<person> for another messenger")
268
275
  .action(async function (person) {
269
276
  const context = messengerContext(this, messenger);
270
- renderAnswer(this, context, itemOf(snakeKeys(await context.withServices((services) => services.people.unlink(person)))));
277
+ renderAnswer(this, context, itemOf(snakeKeys(await context.withServices((services) => services.people.unlink(person, { by: actorOf(this) })))));
271
278
  });
272
279
  /**
273
280
  * ⚠ **The number is asked for or piped, never an argument**: argv is read by `ps` and kept by shell
@@ -423,6 +423,7 @@ export const messengerContext = (command, messenger, resolving = {}) => {
423
423
  history: base.settings.record,
424
424
  searchCatchUp: base.settings.searchCatchUp,
425
425
  ...(base.settings.historyLimits ? { historyLimits: base.settings.historyLimits } : {}),
426
+ historyMuted: base.settings.historyMuted,
426
427
  pictures: base.settings.pictureSearch,
427
428
  reranker: base.settings.searchReranker,
428
429
  guard,
@@ -71,7 +71,9 @@ export const damageNotes = (store) => {
71
71
  `the deep check passed, so writes are allowed again: \`${cleared.command}\` had found the store damaged at ${cleared.at}`,
72
72
  ]
73
73
  : []),
74
- ...(damage ? [damage.what, damage.external_unaffected, ...damage.steps.map((step) => `next: ${step}`)] : []),
74
+ ...(damage
75
+ ? [damage.what_happened, damage.external_data_safe, ...damage.steps.map(({ command }) => `next: ${command}`)]
76
+ : []),
75
77
  ];
76
78
  };
77
79
  const INCLUDES = [
@@ -185,7 +185,7 @@ export const modelsCommand = (messenger) => {
185
185
  .summary("download and verify one speech, embedding or reranker model")
186
186
  .description("download and verify one speech, embedding or reranker model: tens to hundreds of MB, each size in models list")
187
187
  .argument("<model>", "a model id from models list")
188
- .option("--accept-terms", "accept the model's licence terms, for a model that has its own")
188
+ .option("--accept-terms", "no longer needed; kept so older scripts still run")
189
189
  .action(async function (id, options) {
190
190
  if (orderedModels().some((model) => model.id === id))
191
191
  return downloadAudioModel(this, messenger, id);
@@ -17,6 +17,7 @@ import { onlineDeps } from "../../services/deps.js";
17
17
  import { servicesFor } from "../../services/index.js";
18
18
  import { patiently } from "../../services/patience.js";
19
19
  import { applyTaskRulesOnArrival, openRequestTask } from "../../services/task-rules.js";
20
+ import { storePath } from "../../store/path.js";
20
21
  import { environmentOf } from "../context.js";
21
22
  import { REMOTE_WRITE } from "../effects.js";
22
23
  import { itemOf, renderAnswer } from "../envelope.js";
@@ -25,6 +26,7 @@ import { messengerContext } from "./context.js";
25
26
  import { START_SYNC_PER_CHAT, startSync } from "./serve-catch-up.js";
26
27
  import { memberFetches } from "./serve-members.js";
27
28
  import { noticeFor, recordDiagnostics } from "./serve-notice.js";
29
+ import { outdatedReason, ownPackageRoot, watchOutdated } from "./serve-outdated.js";
28
30
  import { serveRelay } from "./serve-relay.js";
29
31
  import { stemFills } from "./serve-stems.js";
30
32
  import { listenUntilStopped } from "./watch-command.js";
@@ -80,7 +82,7 @@ export const serveCommand = (messenger) => {
80
82
  const counts = {};
81
83
  const rules = replying(context, messenger, Date.parse(startedAt));
82
84
  const tasks = tasking(context, warn);
83
- const { handled, startSyncDelayMs } = environmentOf(this);
85
+ const { handled, startSyncDelayMs, outdated: outdatedHook } = environmentOf(this);
84
86
  const count = (event) => {
85
87
  counts[event.event] = (counts[event.event] ?? 0) + 1;
86
88
  if (event.event === "message") {
@@ -152,9 +154,25 @@ export const serveCommand = (messenger) => {
152
154
  withStore: (work) => context.withStore((store) => work(store), { name: "serve stems" }),
153
155
  warn,
154
156
  });
157
+ const listening = new AbortController();
158
+ let outdated;
159
+ const packageRoot = outdatedHook?.packageRoot ?? ownPackageRoot(version);
160
+ const watch = watchOutdated({
161
+ check: () => outdatedReason({
162
+ command: messenger.app.command,
163
+ running: version,
164
+ storePath: storePath(context.env),
165
+ packageRoot,
166
+ }),
167
+ onOutdated: (reason) => {
168
+ outdated = reason;
169
+ listening.abort();
170
+ },
171
+ ...(outdatedHook?.everyMs === undefined ? {} : { everyMs: outdatedHook.everyMs }),
172
+ });
155
173
  try {
156
174
  await listenUntilStopped(this, context, relay?.messenger ?? messenger, count, {
157
- stop: new AbortController(),
175
+ stop: listening,
158
176
  catchUp: true,
159
177
  onReady,
160
178
  connected: (open) => {
@@ -168,6 +186,7 @@ export const serveCommand = (messenger) => {
168
186
  });
169
187
  }
170
188
  finally {
189
+ watch.stop();
171
190
  await relaying;
172
191
  await relay?.close();
173
192
  rules.stop();
@@ -178,6 +197,9 @@ export const serveCommand = (messenger) => {
178
197
  await tasks.settled();
179
198
  releaseLock(path);
180
199
  }
200
+ // Not 0: the unit restarts only a serve that failed, and the restart is what loads the installed build.
201
+ if (outdated !== undefined)
202
+ throw new CliError("configuration_error", outdated, { reason: "serve.outdated" });
181
203
  // `kept` and the reply counts are keyed by event names and rule ids, never camelCased.
182
204
  renderAnswer(this, context, itemOf({
183
205
  profile: context.profile,
@@ -0,0 +1,22 @@
1
+ export declare const OUTDATED_CHECK_MS = 60000;
2
+ /** The folder of the package this process was started from, when its `package.json` still names `running`. */
3
+ export declare const ownPackageRoot: (running: string, script?: string | undefined) => string | undefined;
4
+ /**
5
+ * Why this serve should stop so its unit starts the installed build (BUG-643): the store moved past what this build
6
+ * may write, or a newer version was installed over it. A store that cannot be read now is not a reason.
7
+ */
8
+ export declare const outdatedReason: ({ command, running, storePath, packageRoot, speaks, }: {
9
+ command: string;
10
+ running: string;
11
+ storePath: string;
12
+ packageRoot?: string | undefined;
13
+ speaks?: number;
14
+ }) => Promise<string | undefined>;
15
+ /** Runs `check` every `everyMs` and calls `onOutdated` once with its first reason. */
16
+ export declare const watchOutdated: ({ check, onOutdated, everyMs, }: {
17
+ check: () => Promise<string | undefined>;
18
+ onOutdated: (reason: string) => void;
19
+ everyMs?: number;
20
+ }) => {
21
+ stop: () => void;
22
+ };