@wirecat/cli-core 0.618.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 (274) hide show
  1. package/CHANGELOG.md +339 -1
  2. package/README.md +1 -1
  3. package/THIRD_PARTY_NOTICES +3 -0
  4. package/dist/background/daily-archive-timer.d.ts +1 -1
  5. package/dist/background/deliver.d.ts +5 -2
  6. package/dist/background/deliver.js +30 -12
  7. package/dist/background/report/render.d.ts +3 -1
  8. package/dist/background/report/render.js +3 -1
  9. package/dist/calendar/cli/answers.d.ts +1 -0
  10. package/dist/calendar/cli/answers.js +6 -1
  11. package/dist/calendar/cli/index.js +2 -14
  12. package/dist/calendar/cli/people-link.d.ts +3 -0
  13. package/dist/calendar/cli/people-link.js +23 -0
  14. package/dist/calendar/index.d.ts +1 -1
  15. package/dist/calendar/index.js +1 -1
  16. package/dist/calendar/mcp/index.d.ts +12 -12
  17. package/dist/cli/base-stages-command.d.ts +22 -0
  18. package/dist/cli/base-stages-command.js +174 -0
  19. package/dist/cli/command-runs.d.ts +2 -0
  20. package/dist/cli/command-runs.js +3 -1
  21. package/dist/cli/config-command.js +6 -1
  22. package/dist/cli/context.js +1 -0
  23. package/dist/cli/group-lock.d.ts +42 -0
  24. package/dist/cli/group-lock.js +130 -0
  25. package/dist/cli/index.d.ts +7 -2
  26. package/dist/cli/index.js +7 -2
  27. package/dist/cli/messenger/backfill-command.js +27 -15
  28. package/dist/cli/messenger/contacts-command.js +10 -3
  29. package/dist/cli/messenger/context.js +1 -0
  30. package/dist/cli/messenger/doctor-command.js +3 -1
  31. package/dist/cli/messenger/models-command.js +1 -1
  32. package/dist/cli/messenger/store-maintenance-command.d.ts +22 -2
  33. package/dist/cli/messenger/store-maintenance-command.js +9 -4
  34. package/dist/cli/model-catalogue-command.d.ts +3 -1
  35. package/dist/cli/model-catalogue-command.js +46 -2
  36. package/dist/cli/profile.d.ts +8 -0
  37. package/dist/cli/profile.js +25 -0
  38. package/dist/cli/program.js +2 -0
  39. package/dist/cli/runs/search-query.d.ts +1 -1
  40. package/dist/cli/runs/search-query.js +4 -0
  41. package/dist/cli/runs/search.d.ts +5 -1
  42. package/dist/cli/runs/search.js +12 -1
  43. package/dist/cli/search-left-out.d.ts +6 -1
  44. package/dist/cli/search-left-out.js +9 -4
  45. package/dist/cli/settings.d.ts +8 -0
  46. package/dist/cli/settings.js +17 -2
  47. package/dist/cli/shared-command-exports.d.ts +16 -0
  48. package/dist/cli/store-recover.d.ts +3 -3
  49. package/dist/cli/store-recover.js +26 -26
  50. package/dist/cli/store-settings.d.ts +2 -0
  51. package/dist/cli/store-settings.js +37 -9
  52. package/dist/crm/cli/index.js +38 -6
  53. package/dist/crm/group-hint.d.ts +8 -0
  54. package/dist/crm/group-hint.js +13 -0
  55. package/dist/crm/source.d.ts +12 -1
  56. package/dist/crm/sync.d.ts +31 -2
  57. package/dist/crm/sync.js +110 -3
  58. package/dist/crm/testing/acme-scenario.d.ts +40 -0
  59. package/dist/crm/testing/acme-scenario.js +170 -0
  60. package/dist/crm/testing/index.d.ts +1 -0
  61. package/dist/crm/testing/index.js +1 -0
  62. package/dist/crm/testing/source-contract.js +12 -0
  63. package/dist/crm/testing/source.d.ts +2 -0
  64. package/dist/crm/testing/source.js +1 -0
  65. package/dist/domain/addresses.d.ts +13 -0
  66. package/dist/domain/addresses.js +63 -0
  67. package/dist/domain/categories.d.ts +3 -0
  68. package/dist/domain/categories.js +2 -0
  69. package/dist/domain/crm.d.ts +23 -0
  70. package/dist/domain/crm.js +7 -0
  71. package/dist/domain/mentions.d.ts +2 -12
  72. package/dist/domain/mentions.js +2 -19
  73. package/dist/domain/orders.d.ts +8 -1
  74. package/dist/domain/orders.js +6 -2
  75. package/dist/domain/phones.d.ts +26 -0
  76. package/dist/domain/phones.js +48 -0
  77. package/dist/domain/record-types.d.ts +1 -1
  78. package/dist/domain/record-types.js +1 -0
  79. package/dist/domain/records.d.ts +5 -0
  80. package/dist/domain/ref-summaries.d.ts +39 -0
  81. package/dist/domain/ref-summaries.js +51 -3
  82. package/dist/domain/relations.d.ts +12 -2
  83. package/dist/domain/relations.js +14 -3
  84. package/dist/domain/vcard.d.ts +2 -2
  85. package/dist/domain/vcard.js +4 -10
  86. package/dist/embeddings/models.d.ts +11 -3
  87. package/dist/embeddings/models.js +28 -4
  88. package/dist/entities/business-context.d.ts +149 -0
  89. package/dist/entities/business-context.js +192 -0
  90. package/dist/entities/contact-activity.d.ts +2 -0
  91. package/dist/entities/contact-activity.js +7 -1
  92. package/dist/entities/contact-context.d.ts +157 -0
  93. package/dist/entities/contact-context.js +2 -0
  94. package/dist/entities/deal.d.ts +10 -0
  95. package/dist/entities/deal.js +2 -0
  96. package/dist/entities/index.d.ts +23 -3
  97. package/dist/entities/index.js +5 -0
  98. package/dist/entities/mention.d.ts +4 -3
  99. package/dist/entities/mention.js +2 -1
  100. package/dist/entities/message-transfer.d.ts +4 -2
  101. package/dist/entities/message-transfer.js +2 -2
  102. package/dist/entities/model.d.ts +2 -2
  103. package/dist/entities/model.js +1 -1
  104. package/dist/entities/relationship.d.ts +4 -0
  105. package/dist/entities/relationship.js +4 -0
  106. package/dist/errors/reasons.js +37 -4
  107. package/dist/fetch/page.js +2 -1
  108. package/dist/index.d.ts +3 -2
  109. package/dist/index.js +3 -2
  110. package/dist/meetings/context-store.d.ts +2 -0
  111. package/dist/meetings/findings-rules.d.ts +4 -0
  112. package/dist/meetings/findings-rules.js +5 -2
  113. package/dist/meetings/result-items.d.ts +1 -0
  114. package/dist/meetings/result-items.js +1 -0
  115. package/dist/models/index.js +22 -5
  116. package/dist/runs/events.d.ts +11 -1
  117. package/dist/runs/events.js +3 -1
  118. package/dist/runs/log-attributes.js +4 -0
  119. package/dist/runs/log-events.js +2 -0
  120. package/dist/runs/recording.d.ts +3 -0
  121. package/dist/runs/recording.js +36 -12
  122. package/dist/runs/run.d.ts +12 -3
  123. package/dist/runs/run.js +32 -13
  124. package/dist/search/account-list.d.ts +6 -0
  125. package/dist/search/account-list.js +9 -3
  126. package/dist/search/groups.d.ts +68 -0
  127. package/dist/search/groups.js +172 -0
  128. package/dist/services/account-groups.d.ts +28 -0
  129. package/dist/services/account-groups.js +89 -0
  130. package/dist/services/archive.d.ts +7 -1
  131. package/dist/services/archive.js +19 -3
  132. package/dist/services/business-context.d.ts +113 -0
  133. package/dist/services/business-context.js +156 -0
  134. package/dist/services/communications.d.ts +50 -0
  135. package/dist/services/communications.js +140 -0
  136. package/dist/services/deal-context.d.ts +90 -0
  137. package/dist/services/deal-context.js +131 -0
  138. package/dist/services/deps.d.ts +2 -0
  139. package/dist/services/enrichment.d.ts +7 -2
  140. package/dist/services/enrichment.js +46 -5
  141. package/dist/services/events-search.js +2 -1
  142. package/dist/services/group-guard.d.ts +28 -0
  143. package/dist/services/group-guard.js +131 -0
  144. package/dist/services/index.d.ts +15 -2
  145. package/dist/services/index.js +9 -2
  146. package/dist/services/ingest.d.ts +12 -0
  147. package/dist/services/ingest.js +4 -0
  148. package/dist/services/meaning-model.d.ts +7 -0
  149. package/dist/services/meaning-model.js +20 -0
  150. package/dist/services/meeting-context.d.ts +6 -1
  151. package/dist/services/meeting-context.js +12 -5
  152. package/dist/services/message-resolution.js +2 -3
  153. package/dist/services/messages-meaning.js +4 -5
  154. package/dist/services/messages-search.d.ts +5 -1
  155. package/dist/services/messages-search.js +1 -1
  156. package/dist/services/model-downloads.d.ts +1 -1
  157. package/dist/services/model-downloads.js +6 -4
  158. package/dist/services/money-context.d.ts +73 -0
  159. package/dist/services/money-context.js +77 -0
  160. package/dist/services/notes-search.d.ts +4 -1
  161. package/dist/services/notes-search.js +19 -7
  162. package/dist/services/organization-context.d.ts +80 -0
  163. package/dist/services/organization-context.js +154 -0
  164. package/dist/services/people.d.ts +22 -6
  165. package/dist/services/people.js +38 -8
  166. package/dist/services/person-business.d.ts +43 -0
  167. package/dist/services/person-business.js +67 -0
  168. package/dist/services/person-context.d.ts +9 -1
  169. package/dist/services/person-context.js +5 -3
  170. package/dist/services/proposals/kinds/identity-link.d.ts +4 -0
  171. package/dist/services/proposals/kinds/identity-link.js +48 -0
  172. package/dist/services/proposals/kinds/orders.js +1 -1
  173. package/dist/services/proposals/registry.js +2 -0
  174. package/dist/services/search-kind.d.ts +12 -5
  175. package/dist/services/search-kind.js +49 -10
  176. package/dist/services/text-model-choice.js +1 -1
  177. package/dist/store/accounts.d.ts +18 -0
  178. package/dist/store/accounts.js +18 -3
  179. package/dist/store/damage.d.ts +43 -10
  180. package/dist/store/damage.js +119 -36
  181. package/dist/store/decisions.js +3 -1
  182. package/dist/store/evidence-findings.d.ts +14 -0
  183. package/dist/store/evidence-findings.js +2 -0
  184. package/dist/store/exports.d.ts +2 -1
  185. package/dist/store/identity-links.d.ts +92 -0
  186. package/dist/store/identity-links.js +6 -0
  187. package/dist/store/index.d.ts +11 -5
  188. package/dist/store/index.js +5 -2
  189. package/dist/store/journal.d.ts +10 -0
  190. package/dist/store/journal.js +33 -0
  191. package/dist/store/marks.d.ts +19 -1
  192. package/dist/store/marks.js +23 -1
  193. package/dist/store/people.d.ts +22 -0
  194. package/dist/store/people.js +15 -1
  195. package/dist/store/sqlite/accounts.js +2 -0
  196. package/dist/store/sqlite/base-stages.d.ts +122 -0
  197. package/dist/store/sqlite/base-stages.js +443 -0
  198. package/dist/store/sqlite/base-suggest.d.ts +13 -0
  199. package/dist/store/sqlite/base-suggest.js +62 -0
  200. package/dist/store/sqlite/business-contracts.js +10 -1
  201. package/dist/store/sqlite/crm-settings.d.ts +12 -2
  202. package/dist/store/sqlite/crm-settings.js +56 -13
  203. package/dist/store/sqlite/crm.d.ts +13 -1
  204. package/dist/store/sqlite/crm.js +20 -4
  205. package/dist/store/sqlite/deals.d.ts +33 -0
  206. package/dist/store/sqlite/deals.js +42 -4
  207. package/dist/store/sqlite/decision-requests.js +7 -3
  208. package/dist/store/sqlite/email-index.js +8 -4
  209. package/dist/store/sqlite/evidence-findings.js +29 -5
  210. package/dist/store/sqlite/findings-core.js +4 -2
  211. package/dist/store/sqlite/identity-link-rows.d.ts +50 -0
  212. package/dist/store/sqlite/identity-link-rows.js +146 -0
  213. package/dist/store/sqlite/identity-proposals.d.ts +53 -0
  214. package/dist/store/sqlite/identity-proposals.js +234 -0
  215. package/dist/store/sqlite/knowledge.js +2 -2
  216. package/dist/store/sqlite/link-kinds.d.ts +1 -0
  217. package/dist/store/sqlite/link-kinds.js +1 -0
  218. package/dist/store/sqlite/link-row.d.ts +6 -0
  219. package/dist/store/sqlite/link-row.js +35 -0
  220. package/dist/store/sqlite/link-source.d.ts +10 -0
  221. package/dist/store/sqlite/link-source.js +16 -0
  222. package/dist/store/sqlite/manifest.js +1 -0
  223. package/dist/store/sqlite/meeting-context-links.js +9 -6
  224. package/dist/store/sqlite/memories.js +9 -7
  225. package/dist/store/sqlite/mentions.d.ts +4 -1
  226. package/dist/store/sqlite/mentions.js +14 -9
  227. package/dist/store/sqlite/migrations.generated.js +8 -0
  228. package/dist/store/sqlite/notes.d.ts +1 -2
  229. package/dist/store/sqlite/notes.js +4 -29
  230. package/dist/store/sqlite/open-store.js +3 -0
  231. package/dist/store/sqlite/open.js +11 -2
  232. package/dist/store/sqlite/orders.d.ts +2 -0
  233. package/dist/store/sqlite/orders.js +9 -3
  234. package/dist/store/sqlite/organization-categories.d.ts +18 -0
  235. package/dist/store/sqlite/organization-categories.js +34 -0
  236. package/dist/store/sqlite/organizations.d.ts +5 -1
  237. package/dist/store/sqlite/organizations.js +14 -4
  238. package/dist/store/sqlite/person-links.d.ts +19 -4
  239. package/dist/store/sqlite/person-links.js +49 -11
  240. package/dist/store/sqlite/person-match-scan.d.ts +13 -0
  241. package/dist/store/sqlite/person-match-scan.js +251 -0
  242. package/dist/store/sqlite/person-matcher.d.ts +16 -0
  243. package/dist/store/sqlite/person-matcher.js +32 -0
  244. package/dist/store/sqlite/proposed-actions.js +6 -0
  245. package/dist/store/sqlite/record-matching.d.ts +2 -8
  246. package/dist/store/sqlite/record-matching.js +8 -40
  247. package/dist/store/sqlite/record-projectors-phone.js +2 -1
  248. package/dist/store/sqlite/record-relationships.d.ts +52 -0
  249. package/dist/store/sqlite/record-relationships.js +243 -0
  250. package/dist/store/sqlite/record-run.d.ts +5 -0
  251. package/dist/store/sqlite/record-run.js +62 -2
  252. package/dist/store/sqlite/record-writes.d.ts +1 -1
  253. package/dist/store/sqlite/record-writes.js +4 -2
  254. package/dist/store/sqlite/records.js +27 -2
  255. package/dist/store/sqlite/ref-accounts.d.ts +13 -0
  256. package/dist/store/sqlite/ref-accounts.js +117 -0
  257. package/dist/store/sqlite/ref-summaries.js +5 -1
  258. package/dist/store/sqlite/relation-list.d.ts +4 -1
  259. package/dist/store/sqlite/relation-list.js +18 -2
  260. package/dist/store/sqlite/relation-proposals.d.ts +6 -0
  261. package/dist/store/sqlite/relation-proposals.js +3 -0
  262. package/dist/store/sqlite/relation-roles.js +12 -6
  263. package/dist/store/sqlite/reported-relations.d.ts +11 -1
  264. package/dist/store/sqlite/reported-relations.js +59 -18
  265. package/dist/store/sqlite/schema.d.ts +32 -0
  266. package/dist/store/sqlite/schema.js +3 -0
  267. package/dist/store/sqlite/transaction.js +11 -1
  268. package/dist/store/store.d.ts +3 -0
  269. package/dist/store/store.js +5 -0
  270. package/dist/store/write-events.d.ts +18 -0
  271. package/dist/store/write-events.js +88 -0
  272. package/package.json +3 -3
  273. package/parity.json +11 -4
  274. package/schemas/records-envelope.v1.schema.json +3 -0
package/dist/cli/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  export { AI_ENTRIES, AI_SETTING_KEYS, resolveAISettings } from "../analysis/settings.js";
2
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";
@@ -112,7 +116,7 @@ export { MODEL_CATALOGUE_QUERY } from "./model-catalogue-command.js";
112
116
  export { writeNewFile } from "./new-file.js";
113
117
  export { positiveCount, window, withPaging } from "./paging.js";
114
118
  export { commandPathKey, commandPermissions, knownBeside, knownPermissionKeys, refuseUnknownPermissionKeys, unknownPermissionIssues, unknownPermissionKeys, } from "./permission-keys.js";
115
- 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";
116
120
  export { ProfileTokenStore } from "./profile-token.js";
117
121
  export { createProgram, run } from "./program.js";
118
122
  export { projectAnswerParts, projectCutoffTime, projectEvidenceText, projectWindowOf, withSyncCommands, } from "./project-evidence.js";
@@ -120,6 +124,7 @@ export { projectStatusAnswer, projectStatusRow, projectStatusSchema, projectStat
120
124
  export { STATUS_ROWS, STATUS_SIGNAL_ROWS } from "./project-status-rows.js";
121
125
  export { fieldsOf, projectFields } from "./result-fields.js";
122
126
  export { backfillScheduleRun, SCHEDULE_SETTINGS, scheduleLimitsOf, } from "./schedule/schedule-command.js";
127
+ export { deniedKinds, deniedKindsOf } from "./search-left-out.js";
123
128
  export { settingRows, withSettingDefaults } from "./setting-defaults.js";
124
129
  export { count, first, flag, fromFile, NONE_NAMED, namedProfile, plain, settingsFor, } from "./settings.js";
125
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);
@@ -32,6 +32,7 @@ export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command, ver
32
32
  run_id?: string;
33
33
  error: string;
34
34
  } | undefined;
35
+ journalMark?: import("../../store/marks.js").JournalMark | undefined;
35
36
  damageMarkCleared?: {
36
37
  at: string;
37
38
  command: string;
@@ -39,7 +40,16 @@ export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command, ver
39
40
  run_id?: string;
40
41
  error: string;
41
42
  } | undefined;
42
- damage?: import("../../store/damage.js").DamageExplanation | undefined;
43
+ damage?: {
44
+ whatHappened: string;
45
+ likelyCauses: import("../../store/damage.js").DamageCause[];
46
+ impact: string[];
47
+ externalDataSafe: string;
48
+ lastOkAt: string | null;
49
+ loss: string;
50
+ steps: import("../../store/damage.js").RecoveryStep[];
51
+ what: string;
52
+ } | undefined;
43
53
  path: string;
44
54
  exists: boolean;
45
55
  schema: number;
@@ -66,6 +76,7 @@ export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command, ver
66
76
  run_id?: string;
67
77
  error: string;
68
78
  } | undefined;
79
+ journalMark?: import("../../store/marks.js").JournalMark | undefined;
69
80
  damageMarkCleared?: {
70
81
  at: string;
71
82
  command: string;
@@ -73,7 +84,16 @@ export declare const storeSummary: (env: NodeJS.ProcessEnv, { deep, command, ver
73
84
  run_id?: string;
74
85
  error: string;
75
86
  } | undefined;
76
- damage?: import("../../store/damage.js").DamageExplanation | undefined;
87
+ damage?: {
88
+ whatHappened: string;
89
+ likelyCauses: import("../../store/damage.js").DamageCause[];
90
+ impact: string[];
91
+ externalDataSafe: string;
92
+ lastOkAt: string | null;
93
+ loss: string;
94
+ steps: import("../../store/damage.js").RecoveryStep[];
95
+ what: string;
96
+ } | undefined;
77
97
  path: string;
78
98
  exists: boolean;
79
99
  error: string;
@@ -8,9 +8,9 @@ import { RULES_VERSION } from "../../conversations/link.js";
8
8
  import { syncsOneChat } from "../../ports/traits.js";
9
9
  import { isSealed, sealFile, unsealFile } from "../../sealed.js";
10
10
  import { fileSchemaOf, SPEAKS, writableBy } from "../../store/compatibility.js";
11
- import { explainDamage } from "../../store/damage.js";
11
+ import { storeDamageReport } from "../../store/damage.js";
12
12
  import { QUICK_HEALTH_CHECKS, storeHealth } from "../../store/health.js";
13
- import { readDamageMark, readHealthMark, recordDeepCheck } from "../../store/marks.js";
13
+ import { readDamageMark, readHealthMark, readJournalMark, recordDeepCheck } from "../../store/marks.js";
14
14
  import { migrate } from "../../store/migrations.js";
15
15
  import { openCache } from "../../store/open.js";
16
16
  import { storePath } from "../../store/path.js";
@@ -79,6 +79,7 @@ export const storeSummary = async (env, { deep = false, command, version } = {})
79
79
  if (!existsSync(path))
80
80
  return { path, exists: false };
81
81
  const checked = await storeHealth(path, { deep });
82
+ const journal = readJournalMark(path);
82
83
  const recorded = deep
83
84
  ? recordDeepCheck(path, checked, {
84
85
  cli: command ?? "unknown",
@@ -100,13 +101,17 @@ export const storeSummary = async (env, { deep = false, command, version } = {})
100
101
  ? { damagedSearchIndexes: checked.searchIndexes.filter((index) => !index.ok).map((index) => index.name) }
101
102
  : {}),
102
103
  };
103
- const damage = command ? explainDamage(checked, command, mark) : null;
104
+ const damage = command
105
+ ? storeDamageReport({ health: checked, command, mark, journal, lastOkAt: lastKnownGood })
106
+ : null;
104
107
  const healthOf = {
105
108
  health,
106
109
  lastKnownGood,
107
110
  ...(mark ? { damageMark: withoutInode(mark) } : {}),
111
+ ...(journal ? { journalMark: journal } : {}),
108
112
  ...(recorded?.cleared ? { damageMarkCleared: withoutInode(recorded.cleared) } : {}),
109
- ...(damage ? { damage } : {}),
113
+ // `what` keeps memo's doctor, which reads it, compiling until it moves to `whatHappened`.
114
+ ...(damage ? { damage: { what: damage.whatHappened, ...damage } } : {}),
110
115
  };
111
116
  try {
112
117
  return await reading(path, (database) => {
@@ -13,8 +13,10 @@ export interface ModelCatalogueOptions {
13
13
  * (memo): it changes the shared store for every CLI.
14
14
  */
15
15
  enrichment?: boolean;
16
- /** Where `models consents` looks for the enrichment provider's key; the system keyring when absent. */
16
+ /** Where `models consents` and `models keys` keep the provider's key; the system keyring when absent. */
17
17
  keyring?: KeyringStore;
18
+ /** Where `models keys set` reads the key; process.stdin when absent. */
19
+ stdin?: () => NodeJS.ReadableStream | undefined;
18
20
  output: (answer: Body, command: Command) => void;
19
21
  diagnostic: (line: string) => void;
20
22
  jsonOption?: boolean;
@@ -4,11 +4,13 @@ import { annotate } from "@wirecat/cli-base/commands";
4
4
  import { defineQuery } from "@wirecat/cli-base/query";
5
5
  import { Command } from "commander";
6
6
  import { isTextModelInstalled, textModelsDirectory } from "../embeddings/embed.js";
7
+ import { embeddingKeys } from "../embeddings/keys.js";
7
8
  import { chosenTextModel, DEFAULT_TEXT_MODEL, textModel, textModels } from "../embeddings/models.js";
8
9
  import { downloadTextModel } from "../services/model-downloads.js";
9
10
  import { addCustomTextModel, useTextModel } from "../services/text-model-choice.js";
10
11
  import { install, installedBytes, isInstalled, modelsDirectory } from "../speech/install.js";
11
12
  import { DEFAULT_ORDER, orderedModels, speechModel } from "../speech/models.js";
13
+ import { readSecret } from "../terminal/prompt.js";
12
14
  import { stepLines } from "../terminal/step-lines.js";
13
15
  import { FETCH, grantsAuthority, LOCAL_READ, LOCAL_WRITE, NO_EFFECTS } from "./effects.js";
14
16
  import { enrichmentConsentsCommand } from "./enrichment-consents-command.js";
@@ -70,7 +72,7 @@ export const modelCatalogueCommand = (app, options) => {
70
72
  .description("download and verify one speech or embedding model")
71
73
  .argument("<model>", "a model id from models list")
72
74
  .option("--offline", "refuse a download that needs the network")
73
- .option("--accept-terms", "accept the model's licence terms, for a model that has its own")
75
+ .option("--accept-terms", "no longer needed; kept so older scripts still run")
74
76
  .action(async function (id, given) {
75
77
  if (options.offline?.() || this.optsWithGlobals().offline)
76
78
  throw new CliError("permission_error", "downloading a model needs the network; --offline was requested", {
@@ -138,13 +140,55 @@ export const modelCatalogueCommand = (app, options) => {
138
140
  options.output(itemOf(textModelItem(model, env)), this);
139
141
  });
140
142
  }
141
- if (options.enrichment === true)
143
+ if (options.enrichment === true) {
142
144
  models.addCommand(enrichmentConsentsCommand(app, options));
145
+ models.addCommand(providerKeysCommand(app, options));
146
+ }
143
147
  if (options.jsonOption)
144
148
  for (const command of models.commands.flatMap((one) => (one.commands.length ? one.commands : [one])))
145
149
  command.option("--json", "print JSON");
146
150
  return models;
147
151
  };
152
+ const PROVIDER = /^[a-z0-9][a-z0-9.:-]*$/;
153
+ const providerOf = (given) => {
154
+ const provider = given.trim().toLowerCase();
155
+ if (!PROVIDER.test(provider))
156
+ throw new CliError("validation_error", "name the provider: openai, anthropic, or the host of a --base-url server");
157
+ return provider;
158
+ };
159
+ /** The enrichment provider's key in the tool's keyring entry `embeddings:<provider>`; never printed, never an argument. */
160
+ const providerKeysCommand = (app, options) => {
161
+ const keys = new Command("keys").description("the API key write-time enrichment sends with each request");
162
+ const store = () => embeddingKeys(app, options.env(), options.keyring);
163
+ grantsAuthority(annotate(keys.command("set"), {
164
+ effects: LOCAL_WRITE,
165
+ output: { entity: "model_key", view: "stored" },
166
+ examples: [`${app.command} models keys set openai < key.txt`],
167
+ }))
168
+ .argument("<provider>", "openai, anthropic, or the host of a --base-url server that wants a key")
169
+ .description("store a key, typed at a hidden prompt or piped on stdin — never as an argument")
170
+ .action(async function (given) {
171
+ const provider = providerOf(given);
172
+ const input = options.stdin?.();
173
+ const secret = (await readSecret(`API key for ${provider}: `, input ? { input } : {})).trim();
174
+ if (!secret)
175
+ throw new CliError("validation_error", "no key was given — nothing was stored");
176
+ options.output(itemOf({ provider, stored: true, source: store().write(provider, secret) }), this);
177
+ });
178
+ grantsAuthority(annotate(keys.command("remove"), {
179
+ effects: LOCAL_WRITE,
180
+ output: { entity: "model_key", view: "removed" },
181
+ examples: [`${app.command} models keys remove openai`],
182
+ }))
183
+ .argument("<provider>", "openai, anthropic, or a server's host")
184
+ .description("forget the stored key; a key in the environment stays")
185
+ .action(function (given) {
186
+ const provider = providerOf(given);
187
+ const removed = store().remove(provider);
188
+ options.output(itemOf({ provider, removed: removed.length > 0, from: removed }), this);
189
+ });
190
+ return keys;
191
+ };
148
192
  const PROGRESS_EVERY_MS = 500;
149
193
  /**
150
194
  * `{"event":"progress","step":"download",…}` on stderr under --json, for a window to draw a bar by: at most every half
@@ -1,4 +1,6 @@
1
1
  import type { Command } from "commander";
2
+ import { type AppIdentity } from "../ports/app.js";
3
+ import type { RunGroup } from "../search/groups.js";
2
4
  /** How the command line names this profile: always the first word, since none is assumed. */
3
5
  export declare const asFirstWord: (profile: string) => string;
4
6
  export declare const isProfileName: (word: string) => boolean;
@@ -27,6 +29,12 @@ export declare const liftProfile: (argv: string[], words: Set<string>, valued?:
27
29
  profile?: string;
28
30
  rest: string[];
29
31
  };
32
+ /**
33
+ * The group a run reads, from the first word (`liftProfile` lifts it) or `<PREFIX>_GROUP`; `all`, the default, is
34
+ * every account, so no restriction. Under `<PREFIX>_GROUP_LOCK` any other group, `all` included, is refused, as the
35
+ * profile lock refuses another profile (WC-ACCT-5); a lock of `all` locks nothing.
36
+ */
37
+ export declare const runGroup: (app: AppIdentity, env: NodeJS.ProcessEnv, word?: string) => RunGroup | undefined;
30
38
  /** The root's options that take the next word as their value: `--timeout 30s`. */
31
39
  export declare const valuedOptions: (program: Command) => Set<string>;
32
40
  /**
@@ -1,4 +1,6 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
+ import { envName } from "../ports/app.js";
3
+ import { isGroupName } from "../search/account-list.js";
2
4
  /** How the command line names this profile: always the first word, since none is assumed. */
3
5
  export const asFirstWord = (profile) => `${profile} `;
4
6
  /**
@@ -57,6 +59,29 @@ export const liftProfile = (argv, words, valued = new Set()) => {
57
59
  return { rest: argv };
58
60
  return { profile: first, rest: [...argv.slice(0, at), ...argv.slice(at + 1)] };
59
61
  };
62
+ /**
63
+ * The group a run reads, from the first word (`liftProfile` lifts it) or `<PREFIX>_GROUP`; `all`, the default, is
64
+ * every account, so no restriction. Under `<PREFIX>_GROUP_LOCK` any other group, `all` included, is refused, as the
65
+ * profile lock refuses another profile (WC-ACCT-5); a lock of `all` locks nothing.
66
+ */
67
+ export const runGroup = (app, env, word) => {
68
+ const GROUP = envName(app, "GROUP");
69
+ const LOCK = envName(app, "GROUP_LOCK");
70
+ const lock = env[LOCK]?.trim() || undefined;
71
+ const named = word ?? (env[GROUP]?.trim() || undefined);
72
+ const from = word === undefined ? GROUP : "first word";
73
+ for (const [name, origin] of [
74
+ [named, from],
75
+ [lock, LOCK],
76
+ ])
77
+ if (name !== undefined && !isGroupName(name))
78
+ throw new CliError("validation_error", `"${name}" (${origin}) is not a group name — letters, digits, - and _, starting with a letter or a digit`);
79
+ if (lock === undefined || lock.toLowerCase() === "all")
80
+ return named === undefined || named.toLowerCase() === "all" ? undefined : { name: named, from, locked: false };
81
+ if (named !== undefined && named !== lock)
82
+ throw new CliError("permission_error", `this process is locked to group ${lock} (${LOCK}) — group "${named}" (${from}) is refused`);
83
+ return { name: lock, from: LOCK, locked: true };
84
+ };
60
85
  /** The root's options that take the next word as their value: `--timeout 30s`. */
61
86
  export const valuedOptions = (program) => new Set(program.options
62
87
  .filter((option) => option.required)
@@ -25,6 +25,7 @@ import { admittedUnderLock, changesAuthorityAt, changesAuthorityNow, isLogin, is
25
25
  import { itemOf, renderAnswer, snakeKeys } from "./envelope.js";
26
26
  import { byteCount, DEFAULT_AGENT_COOPERATIVE_MS, DEFAULT_COMMAND_MS, DEFAULT_COOPERATIVE_MS, DEFAULT_OUTPUT_BYTES, DEFAULT_SYNC_MS, execution, } from "./execution.js";
27
27
  import { setupAtStart } from "./first-run.js";
28
+ import { refuseOutsideGroup } from "./group-lock.js";
28
29
  import { installHelp } from "./help/first-screen.js";
29
30
  import { showInputFields } from "./input-fields.js";
30
31
  import { MAX_BUFFERED_INPUT, provideInputPolicy } from "./input-policy.js";
@@ -321,6 +322,7 @@ const runOnce = async (argv, definition, options) => {
321
322
  input,
322
323
  terminal: !options.streams && input.isTTY === true && process.stderr.isTTY === true,
323
324
  });
325
+ await refuseOutsideGroup(action, { app: definition.app, env: commandEnv });
324
326
  if (lock && isLogin(action) && !flags.dryRun)
325
327
  throw readOnlyRefusal(lock, "log in or out");
326
328
  if (lock && isStoreChange(action) && !flags.dryRun)
@@ -1,4 +1,4 @@
1
1
  import { type QueryWords } from "../list-query.js";
2
2
  import type { RunSearch } from "./search.js";
3
3
  export declare const RUN_SEARCH_QUERY: import("@wirecat/cli-base/query").QueryRegistry;
4
- export declare const runSearchFilter: (words: QueryWords) => Pick<RunSearch, "terms" | "status" | "errorCode" | "operation" | "profile" | "since" | "until">;
4
+ export declare const runSearchFilter: (words: QueryWords) => Pick<RunSearch, "terms" | "status" | "errorCode" | "operation" | "profile" | "kind" | "table" | "since" | "until">;
@@ -15,6 +15,8 @@ export const RUN_SEARCH_QUERY = defineQuery({
15
15
  termField("error_code", "kw", "error_code:rate_limited"),
16
16
  termField("operation", "kw", "operation:messages.download"),
17
17
  termField("profile", "kw", "profile:work"),
18
+ termField("kind", "kw", "kind:store"),
19
+ termField("table", "kw", "table:emails"),
18
20
  ],
19
21
  });
20
22
  export const runSearchFilter = (words) => {
@@ -62,5 +64,7 @@ export const runSearchFilter = (words) => {
62
64
  ...(fields.has("error_code") ? { errorCode: fields.get("error_code") } : {}),
63
65
  ...(fields.has("operation") ? { operation: fields.get("operation") } : {}),
64
66
  ...(fields.has("profile") ? { profile: fields.get("profile") } : {}),
67
+ ...(fields.has("kind") ? { kind: fields.get("kind") } : {}),
68
+ ...(fields.has("table") ? { table: fields.get("table") } : {}),
65
69
  };
66
70
  };
@@ -5,12 +5,16 @@ export interface RunSearch {
5
5
  errorCode?: string;
6
6
  operation?: string;
7
7
  profile?: string;
8
+ /** An event's `kind`: `store` for the writes a run made to the store. */
9
+ kind?: string;
10
+ /** A store event's table. */
11
+ table?: string;
8
12
  since?: string;
9
13
  until?: string;
10
14
  limit?: number;
11
15
  page?: number;
12
16
  }
13
- export declare const searchRuns: (dir: string, { query, terms, status, errorCode, operation, profile, since, until, limit, page }?: RunSearch) => {
17
+ export declare const searchRuns: (dir: string, { query, terms, status, errorCode, operation, profile, kind, table, since, until, limit, page, }?: RunSearch) => {
14
18
  items: {
15
19
  runId: string;
16
20
  command: string;
@@ -2,6 +2,7 @@ import { CliError } from "@wirecat/cli-base";
2
2
  import { findRun, listRuns, readEvents } from "../../runs/run.js";
3
3
  import { dateWindow } from "../../services/moment.js";
4
4
  import { listOf, snakeKeys } from "../envelope.js";
5
+ const STORE_WRITE = "store.write";
5
6
  const FIELDS = [
6
7
  "event",
7
8
  "operation",
@@ -19,6 +20,10 @@ const FIELDS = [
19
20
  "provider_error",
20
21
  "code",
21
22
  "reason",
23
+ "kind",
24
+ "table",
25
+ "op",
26
+ "n",
22
27
  "time",
23
28
  ];
24
29
  const safeEvent = (event) => Object.fromEntries(FIELDS.flatMap((name) => {
@@ -34,7 +39,7 @@ const safeEvent = (event) => Object.fromEntries(FIELDS.flatMap((name) => {
34
39
  }
35
40
  return typeof value === "string" || typeof value === "number" ? [[name, value]] : [];
36
41
  }));
37
- export const searchRuns = (dir, { query = "", terms = [], status, errorCode, operation, profile, since, until, limit = 20, page = 1 } = {}) => {
42
+ export const searchRuns = (dir, { query = "", terms = [], status, errorCode, operation, profile, kind, table, since, until, limit = 20, page = 1, } = {}) => {
38
43
  if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100 || !Number.isSafeInteger(page) || page < 1)
39
44
  throw new CliError("validation_error", "run search uses a limit from 1 to 100 and a positive page");
40
45
  const window = dateWindow({ sinceTime: since, untilTime: until });
@@ -54,12 +59,16 @@ export const searchRuns = (dir, { query = "", terms = [], status, errorCode, ope
54
59
  run.errorCode === errorCode ||
55
60
  run.partial?.failures.some((failure) => failure.errorCode === errorCode)) &&
56
61
  !operation &&
62
+ !kind &&
63
+ !table &&
57
64
  needles.every((needle) => JSON.stringify(run).toLowerCase().includes(needle));
58
65
  // A finished run lists its operations and codes, so a run that cannot match is never opened.
59
66
  // One still running, or killed, has no such list and is read.
60
67
  const ruledOut = !metadataMatch &&
61
68
  needles.length === 0 &&
62
69
  ((operation !== undefined && run.operations !== undefined && !run.operations.includes(operation)) ||
70
+ (kind === "store" && run.operations !== undefined && !run.operations.includes(STORE_WRITE)) ||
71
+ (table !== undefined && run.operations !== undefined && !(run.tables ?? []).includes(table)) ||
63
72
  (errorCode !== undefined && run.codes !== undefined && !run.codes.includes(errorCode)));
64
73
  if (ruledOut)
65
74
  continue;
@@ -67,6 +76,8 @@ export const searchRuns = (dir, { query = "", terms = [], status, errorCode, ope
67
76
  const events = found ? readEvents(found.dir).map(safeEvent) : [];
68
77
  const filtered = events.filter((event) => (!errorCode || event.error_code === errorCode || event.code === errorCode) &&
69
78
  (!operation || event.operation === operation) &&
79
+ (!kind || event.kind === kind) &&
80
+ (!table || event.table === table) &&
70
81
  needles.every((needle) => JSON.stringify(event).toLowerCase().includes(needle)));
71
82
  if (!metadataMatch && filtered.length === 0)
72
83
  continue;
@@ -1,6 +1,6 @@
1
1
  import type { Command } from "commander";
2
2
  import type { AppIdentity } from "../ports/app.js";
3
- import { type PermissionKey } from "../sends/permissions.js";
3
+ import { type Level, type PermissionKey } from "../sends/permissions.js";
4
4
  /** The list command whose level guards each kind a shared `search all` reads. */
5
5
  declare const LIST_KEYS: {
6
6
  readonly deal: "deals.list";
@@ -19,6 +19,11 @@ export interface LeftOut<K extends SearchedKind> {
19
19
  /** `deal left out: profile work denies deals.list` */
20
20
  why: string;
21
21
  }
22
+ /**
23
+ * The kinds whose list `permissions` deny, for a CLI with levels of its own, such as memo's: `by` names who denies in
24
+ * `why` (`memo's permissions`).
25
+ */
26
+ export declare const deniedKindsOf: <K extends SearchedKind>(permissions: Readonly<Record<PermissionKey, Level>>, kinds: readonly K[], by: string, defaults?: Readonly<Record<PermissionKey, Level>>) => LeftOut<K>[];
22
27
  /**
23
28
  * The kinds whose list the profile denies, so `search all` leaves them out rather than show their titles and excerpts
24
29
  * under another key (SEC-144). Levels as the run judged the command: the profile's, `--permission`, and an MCP
@@ -13,6 +13,14 @@ const LIST_KEYS = {
13
13
  events: "events.list",
14
14
  meetings: "meetings.list",
15
15
  };
16
+ /**
17
+ * The kinds whose list `permissions` deny, for a CLI with levels of its own, such as memo's: `by` names who denies in
18
+ * `why` (`memo's permissions`).
19
+ */
20
+ export const deniedKindsOf = (permissions, kinds, by, defaults) => kinds
21
+ .map((kind) => ({ kind, key: LIST_KEYS[kind] }))
22
+ .filter(({ key }) => levelFor(permissions, key, defaults).level === "deny")
23
+ .map((one) => ({ ...one, why: `${one.kind} left out: ${by} denies ${one.key}` }));
16
24
  /**
17
25
  * The kinds whose list the profile denies, so `search all` leaves them out rather than show their titles and excerpts
18
26
  * under another key (SEC-144). Levels as the run judged the command: the profile's, `--permission`, and an MCP
@@ -26,8 +34,5 @@ export const deniedKinds = (command, app, kinds) => {
26
34
  needsProfile: false,
27
35
  readOnly: true,
28
36
  });
29
- return kinds
30
- .map((kind) => ({ kind, key: LIST_KEYS[kind] }))
31
- .filter(({ key }) => levelFor(permissions, key, environment.permissionDefaults).level === "deny")
32
- .map((one) => ({ ...one, why: `${one.kind} left out: profile ${profile} denies ${one.key}` }));
37
+ return deniedKindsOf(permissions, kinds, `profile ${profile}`, environment.permissionDefaults);
33
38
  };