@wirecat/wirecat 0.0.0-stage → 1.1.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 (230) hide show
  1. package/LICENSE +204 -0
  2. package/README.md +399 -2
  3. package/THIRD_PARTY_NOTICES +2 -0
  4. package/contracts/wirecat.json +4612 -0
  5. package/dist/actions/actions.js +269 -0
  6. package/dist/actions/command.js +102 -0
  7. package/dist/agents/command.js +17 -0
  8. package/dist/agents/log.js +23 -0
  9. package/dist/answer.js +100 -0
  10. package/dist/answers/command.js +128 -0
  11. package/dist/app.js +15 -0
  12. package/dist/author.js +109 -0
  13. package/dist/bin/wcat-wirecat.js +40 -0
  14. package/dist/bots/command.js +175 -0
  15. package/dist/bundle/auto-O24ISPOI.js +43 -0
  16. package/dist/bundle/chunk-2A3YPENI.js +31 -0
  17. package/dist/bundle/chunk-6BDIFKF5.js +222 -0
  18. package/dist/bundle/chunk-7O7XM37N.js +2 -0
  19. package/dist/bundle/chunk-AYHZY24E.js +120 -0
  20. package/dist/bundle/chunk-CKBTMZUX.js +72 -0
  21. package/dist/bundle/chunk-FGXUH3XL.js +416 -0
  22. package/dist/bundle/chunk-I5JQBRRC.js +807 -0
  23. package/dist/bundle/chunk-RKVAWMZT.js +38 -0
  24. package/dist/bundle/chunk-SCDNOUUR.js +395 -0
  25. package/dist/bundle/chunk-T7TG4JKR.js +312 -0
  26. package/dist/bundle/chunk-XBUCXQKT.js +51 -0
  27. package/dist/bundle/entry-EW5A7FYV.js +64 -0
  28. package/dist/bundle/failure-HMELJ3K5.js +19 -0
  29. package/dist/bundle/from-memo-F7NTUXAR.js +314 -0
  30. package/dist/bundle/program-7XWGFN4H.js +14994 -0
  31. package/dist/bundle/server-T7RVBNRW.js +303 -0
  32. package/dist/bundle/update-JZDS7B6L.js +22 -0
  33. package/dist/bundle/wcat-wirecat.js +83 -0
  34. package/dist/config-command.js +39 -0
  35. package/dist/config-issues.js +15 -0
  36. package/dist/config.js +187 -0
  37. package/dist/context/command.js +162 -0
  38. package/dist/context/context.js +197 -0
  39. package/dist/contract-overrides/commands.js +81 -0
  40. package/dist/contract-overrides/mcp.js +241 -0
  41. package/dist/contract-overrides/meetings.js +344 -0
  42. package/dist/contract-overrides/search.js +508 -0
  43. package/dist/contract-overrides/skill.js +85 -0
  44. package/dist/contract-overrides.js +7 -0
  45. package/dist/digest/backfill.js +175 -0
  46. package/dist/digest/brief.js +189 -0
  47. package/dist/digest/catch-up-record.js +30 -0
  48. package/dist/digest/catch-up.js +86 -0
  49. package/dist/digest/command.js +110 -0
  50. package/dist/digest/digest-commands.js +327 -0
  51. package/dist/digest/digest.js +560 -0
  52. package/dist/digest/digests.js +213 -0
  53. package/dist/digest/history.js +202 -0
  54. package/dist/digest/input.js +30 -0
  55. package/dist/digest/known.js +28 -0
  56. package/dist/digest/sources.js +155 -0
  57. package/dist/digest/sync-health.js +158 -0
  58. package/dist/digest/task-proposals.js +67 -0
  59. package/dist/digest/tasks.js +145 -0
  60. package/dist/digest/text.js +49 -0
  61. package/dist/discovery/command.js +107 -0
  62. package/dist/doctor/command.js +167 -0
  63. package/dist/documents/command.js +107 -0
  64. package/dist/domain-lists/command.js +13 -0
  65. package/dist/events/command.js +35 -0
  66. package/dist/events/events.js +196 -0
  67. package/dist/examples.js +609 -0
  68. package/dist/facts/command.js +100 -0
  69. package/dist/facts/fact.js +54 -0
  70. package/dist/facts/facts.js +15 -0
  71. package/dist/failure.js +58 -0
  72. package/dist/finance/command.js +121 -0
  73. package/dist/finance/contracts-command.js +109 -0
  74. package/dist/finance/deal-text.js +34 -0
  75. package/dist/finance/deals-command.js +346 -0
  76. package/dist/finance/finance.js +129 -0
  77. package/dist/finance/lines-command.js +70 -0
  78. package/dist/finance/orders-command.js +94 -0
  79. package/dist/finance/products-command.js +98 -0
  80. package/dist/finance/subscriptions-command.js +152 -0
  81. package/dist/finance/transactions-command.js +136 -0
  82. package/dist/finance/wallets-command.js +105 -0
  83. package/dist/finance/written.js +36 -0
  84. package/dist/findings/command.js +102 -0
  85. package/dist/findings-input.js +23 -0
  86. package/dist/identity.js +20 -0
  87. package/dist/install/postinstall.js +47 -0
  88. package/dist/json-fields.js +48 -0
  89. package/dist/knowledge/business-text.js +19 -0
  90. package/dist/knowledge/command.js +435 -0
  91. package/dist/knowledge/document-context.js +33 -0
  92. package/dist/knowledge/key-documents.js +120 -0
  93. package/dist/knowledge/list-queries.js +20 -0
  94. package/dist/knowledge/meeting-projects-command.js +61 -0
  95. package/dist/knowledge/messenger-sync.js +253 -0
  96. package/dist/knowledge/money-text.js +16 -0
  97. package/dist/knowledge/notes-about.js +81 -0
  98. package/dist/knowledge/organization-delete-command.js +44 -0
  99. package/dist/knowledge/organization-text.js +27 -0
  100. package/dist/knowledge/project-actions-command.js +130 -0
  101. package/dist/knowledge/project-actions.js +104 -0
  102. package/dist/knowledge/project-activity-command.js +70 -0
  103. package/dist/knowledge/project-context.js +101 -0
  104. package/dist/knowledge/project-findings.js +41 -0
  105. package/dist/knowledge/project-gather-command.js +100 -0
  106. package/dist/knowledge/project-status-command.js +129 -0
  107. package/dist/knowledge/project-transfer-command.js +58 -0
  108. package/dist/knowledge/project-transfer.js +107 -0
  109. package/dist/knowledge/relationships-scan.js +116 -0
  110. package/dist/knowledge/relationships.js +115 -0
  111. package/dist/knowledge/roles-command.js +67 -0
  112. package/dist/mail/command.js +20 -0
  113. package/dist/mail/findings-command.js +143 -0
  114. package/dist/mail/findings-duplicates.js +159 -0
  115. package/dist/mail/messages-command.js +77 -0
  116. package/dist/mail/review-command.js +59 -0
  117. package/dist/mail/subscriptions-command.js +84 -0
  118. package/dist/mcp/catalogue.js +159 -0
  119. package/dist/mcp/command.js +125 -0
  120. package/dist/mcp/granted.js +18 -0
  121. package/dist/mcp/permissions.js +61 -0
  122. package/dist/mcp/server.js +128 -0
  123. package/dist/meetings/command.js +31 -0
  124. package/dist/meetings/list-command.js +59 -0
  125. package/dist/meetings/preparation-command.js +42 -0
  126. package/dist/meetings/preparation-text.js +44 -0
  127. package/dist/meetings/preparation.js +50 -0
  128. package/dist/meetings/read.js +32 -0
  129. package/dist/memories/command.js +105 -0
  130. package/dist/memories/memories.js +17 -0
  131. package/dist/memories/memory.js +89 -0
  132. package/dist/memories/sources.js +111 -0
  133. package/dist/mentions/command.js +91 -0
  134. package/dist/migrate/check.js +48 -0
  135. package/dist/migrate/from-memo.js +345 -0
  136. package/dist/migrate/skill.js +35 -0
  137. package/dist/models/command.js +19 -0
  138. package/dist/options.js +35 -0
  139. package/dist/output.js +17 -0
  140. package/dist/page.js +14 -0
  141. package/dist/people/command.js +144 -0
  142. package/dist/people/delete-command.js +53 -0
  143. package/dist/people/doubts-command.js +81 -0
  144. package/dist/people/identities-command.js +188 -0
  145. package/dist/people/identity.js +42 -0
  146. package/dist/people/owner.js +14 -0
  147. package/dist/people/proposal-rows.js +70 -0
  148. package/dist/people/proposals-command.js +248 -0
  149. package/dist/people/review-context.js +108 -0
  150. package/dist/people/subject.js +19 -0
  151. package/dist/program.js +875 -0
  152. package/dist/read-only.js +51 -0
  153. package/dist/reasons.js +368 -0
  154. package/dist/records/import.js +135 -0
  155. package/dist/records/input.js +210 -0
  156. package/dist/records/mapping.js +80 -0
  157. package/dist/records/record-commands.js +125 -0
  158. package/dist/records/sources.js +73 -0
  159. package/dist/refs.js +28 -0
  160. package/dist/review/command.js +171 -0
  161. package/dist/review/kinds.js +44 -0
  162. package/dist/review/review.js +299 -0
  163. package/dist/review/status.js +93 -0
  164. package/dist/rows.js +219 -0
  165. package/dist/run/auto.js +237 -0
  166. package/dist/run/entry.js +62 -0
  167. package/dist/run/files.js +51 -0
  168. package/dist/run/import.js +253 -0
  169. package/dist/run/lock.js +20 -0
  170. package/dist/save-help.js +3 -0
  171. package/dist/schedule/command.js +58 -0
  172. package/dist/schedule/mail-triage-input.js +152 -0
  173. package/dist/schedule/task-triage-input.js +152 -0
  174. package/dist/search/answers.js +176 -0
  175. package/dist/search/command.js +257 -0
  176. package/dist/search/denied.js +9 -0
  177. package/dist/search/embed.js +126 -0
  178. package/dist/search/hits.js +4 -0
  179. package/dist/search/lane-gates.js +76 -0
  180. package/dist/search/notes-text.js +18 -0
  181. package/dist/search/people.js +88 -0
  182. package/dist/search/search.js +306 -0
  183. package/dist/show/command.js +179 -0
  184. package/dist/store/crm-viewer.js +102 -0
  185. package/dist/store/group.js +112 -0
  186. package/dist/store/groups-command.js +136 -0
  187. package/dist/store/guard.js +94 -0
  188. package/dist/store/held.js +21 -0
  189. package/dist/store/info-command.js +37 -0
  190. package/dist/store/scope.js +53 -0
  191. package/dist/store/source-list.js +222 -0
  192. package/dist/store/source-target.js +28 -0
  193. package/dist/tags/command.js +176 -0
  194. package/dist/tasks/command.js +174 -0
  195. package/dist/tasks/context.js +74 -0
  196. package/dist/tasks/list.js +199 -0
  197. package/dist/tasks/proposal-duplicates.js +70 -0
  198. package/dist/tasks/relations-command.js +28 -0
  199. package/dist/tasks/shared.js +105 -0
  200. package/dist/tasks/tasks.js +197 -0
  201. package/dist/templates/command.js +18 -0
  202. package/dist/terminal.js +23 -0
  203. package/dist/update.js +35 -0
  204. package/dist/version.js +2 -0
  205. package/dist/vocabulary/command.js +103 -0
  206. package/dist/vocabulary/inspect.js +23 -0
  207. package/dist/vocabulary/inspection.js +18 -0
  208. package/dist/vocabulary/list.js +18 -0
  209. package/dist/vocabulary/project.js +19 -0
  210. package/dist/wcat.js +3 -0
  211. package/install/postinstall.mjs +9 -0
  212. package/package.json +89 -4
  213. package/scenarios/decision-trail.md +21 -0
  214. package/scenarios/person-brief.md +35 -0
  215. package/scenarios/prepare-meeting.md +17 -0
  216. package/scenarios/project-state.md +26 -0
  217. package/scenarios/set-up.md +18 -0
  218. package/scenarios/start-the-day.md +19 -0
  219. package/skills/mail-triage/SKILL.md +208 -0
  220. package/skills/morning-digest/SKILL.md +147 -0
  221. package/skills/task-triage/SKILL.md +79 -0
  222. package/skills/wcat/SKILL.md +65 -0
  223. package/skills/wcat/topics/mail.md +32 -0
  224. package/skills/wcat/topics/mcp.md +22 -0
  225. package/skills/wcat/topics/meetings.md +37 -0
  226. package/skills/wcat/topics/money.md +52 -0
  227. package/skills/wcat/topics/projects.md +54 -0
  228. package/skills/wcat/topics/proposals.md +113 -0
  229. package/skills/wcat/topics/search.md +85 -0
  230. package/skills/wcat/topics/vocabulary.md +8 -0
@@ -0,0 +1,51 @@
1
+ import { metaOf } from "@wirecat/cli-base/commands";
2
+ import { changesAuthority, isStoreChange, readOnlyLockOf, readOnlyRefusal, setupPermissionCeiling, } from "@wirecat/cli-core";
3
+ import { APP } from "./app.js";
4
+ // cli-core 2.0.0's closed propose tier (PROPOSE_COMMANDS) still names memo's `mail findings add`; the cli-core
5
+ // release of the split names `review findings add`, and this line goes.
6
+ export const PROPOSES_HERE = "review findings add";
7
+ const pathOf = (command) => {
8
+ const words = [];
9
+ for (let at = command; at?.parent; at = at.parent)
10
+ words.unshift(at.name());
11
+ return words.join(" ");
12
+ };
13
+ const refusalOf = (command) => {
14
+ const { effects, lifetime } = metaOf(command);
15
+ // `mcp` keeps serving reads; writes remain discoverable but are refused.
16
+ if (lifetime === "persistent")
17
+ return undefined;
18
+ if (changesAuthority(command) && command.opts().check !== true)
19
+ return "change what later runs may access";
20
+ if (command.opts().allowRemote === true)
21
+ return "send evidence to a model off this machine";
22
+ if (effects?.remote === "write")
23
+ return "change mail at the provider";
24
+ if (isStoreChange(command) && pathOf(command) !== PROPOSES_HERE)
25
+ return "change wcat's store or files";
26
+ return undefined;
27
+ };
28
+ /**
29
+ * WC-PERM-12: under WCAT_READ_ONLY every change is refused with permission_error (exit 5) before the action runs.
30
+ * A sync still receives, and a local write fails closed: nothing here marks one as harmless.
31
+ */
32
+ /** WCAT_READ_ONLY, or the shared WireCat setup answer "read only", which another tool's `setup` changes. */
33
+ const lockOf = (env) => readOnlyLockOf(APP, env) ??
34
+ (setupPermissionCeiling(env) === "readonly" ? "the WireCat setup answer; `tg setup` changes it" : undefined);
35
+ export const refuseWritesUnderLock = (program, env) => {
36
+ program.hook("preAction", (_root, command) => {
37
+ const lock = lockOf(env);
38
+ if (lock === undefined)
39
+ return;
40
+ const refusal = refusalOf(command);
41
+ if (refusal !== undefined)
42
+ throw readOnlyRefusal(lock, refusal);
43
+ });
44
+ };
45
+ export const readOnly = (env) => lockOf(env) !== undefined;
46
+ export const readOnlyAvailability = (command, env) => {
47
+ const lock = lockOf(env);
48
+ const refusal = lock === undefined ? undefined : refusalOf(command);
49
+ return refusal === undefined ? { available: true } : { available: false, reason: `${lock}: cannot ${refusal}` };
50
+ };
51
+ //# sourceMappingURL=read-only.js.map
@@ -0,0 +1,368 @@
1
+ import { defineReasons } from "@wirecat/cli-base/standards";
2
+ /** The reasons wcat raises itself; cli-base's and cli-core's are merged in by `failureContext`. */
3
+ export const REASONS = defineReasons([
4
+ {
5
+ reason: "backfill.no-schedule",
6
+ code: "not_found",
7
+ message: "no morning-digest schedule to build from — wcat skill show morning-digest says how to make one",
8
+ details: [],
9
+ },
10
+ {
11
+ reason: "backfill.not-daily",
12
+ code: "validation_error",
13
+ message: "{schedule} does not run at a daily time, so it has no past days",
14
+ details: ["schedule"],
15
+ },
16
+ {
17
+ reason: "backfill.owner-only",
18
+ code: "permission_error",
19
+ message: "a backfill spends the owner's money on model calls; the owner runs it at a terminal or in WireCat Desktop",
20
+ details: [],
21
+ },
22
+ {
23
+ reason: "digest.agent-unchosen",
24
+ code: "validation_error",
25
+ message: "no single agent is installed to write the digest; name one with --agent",
26
+ details: ["choices"],
27
+ },
28
+ {
29
+ reason: "digest.exists",
30
+ code: "validation_error",
31
+ message: "a digest or schedule of that name already exists; wcat digest edit changes a digest",
32
+ details: [],
33
+ },
34
+ {
35
+ reason: "digest.not-found",
36
+ code: "not_found",
37
+ message: "no digest of that name — wcat digest list names them",
38
+ details: [],
39
+ },
40
+ {
41
+ reason: "digest.own-prompt",
42
+ code: "validation_error",
43
+ message: "the digest runs a prompt of its own, made with wcat schedule agent; change it there",
44
+ details: [],
45
+ },
46
+ {
47
+ reason: "digest.owner-only",
48
+ code: "permission_error",
49
+ message: "a digest spends the owner's money and writes to his chats; he changes or runs it in a terminal or WireCat Desktop",
50
+ details: [],
51
+ },
52
+ {
53
+ reason: "roles.owner-only",
54
+ code: "permission_error",
55
+ message: "only the owner changes the role lists; an agent uses the roles they hold",
56
+ details: [],
57
+ },
58
+ {
59
+ reason: "source.agent-fetch",
60
+ code: "permission_error",
61
+ message: "an agent over MCP cannot make wcat fetch an address",
62
+ details: [],
63
+ },
64
+ {
65
+ reason: "brief.owner-only",
66
+ code: "permission_error",
67
+ message: "only the owner changes the digest brief, not an agent",
68
+ details: [],
69
+ },
70
+ {
71
+ reason: "brief.no-editor",
72
+ code: "validation_error",
73
+ message: "set VISUAL or EDITOR, or pass the brief with --file",
74
+ details: [],
75
+ },
76
+ {
77
+ reason: "brief.no-history",
78
+ code: "validation_error",
79
+ message: "the brief has no earlier body to put back",
80
+ details: [],
81
+ },
82
+ {
83
+ reason: "brief.empty",
84
+ code: "validation_error",
85
+ message: "the brief is empty; wcat digest brief reset removes it",
86
+ details: [],
87
+ },
88
+ {
89
+ reason: "brief.too-long",
90
+ code: "validation_error",
91
+ message: "the brief is {chars} characters; the limit is {limit}, because every morning run reads it and pays for it",
92
+ details: ["chars", "limit"],
93
+ },
94
+ {
95
+ reason: "ref.bare-number",
96
+ code: "validation_error",
97
+ message: "{value} is a bare number, which names no one kind of record here; give a reference such as {suggestion}",
98
+ details: ["value", "suggestion"],
99
+ },
100
+ {
101
+ reason: "decision.owner-unconfirmed",
102
+ code: "confirmation_required",
103
+ message: "--as-owner asks at a terminal, and nobody is at one to answer; the owner runs it there, without --json",
104
+ details: [],
105
+ },
106
+ {
107
+ reason: "decision.decider-unknown",
108
+ code: "confirmation_required",
109
+ message: "nothing shows who decides; the owner decides at a terminal, an agent from its own session with --reason",
110
+ details: [],
111
+ },
112
+ {
113
+ reason: "findings.file-missing",
114
+ code: "not_found",
115
+ message: "no findings file {path}: give the findings JSON itself, a file that exists, or - for stdin",
116
+ details: ["path"],
117
+ },
118
+ {
119
+ reason: "organization.delete-confirm",
120
+ code: "confirmation_required",
121
+ message: "this deletes the organization and what names it alone; nothing was changed — add --yes",
122
+ details: ["plan"],
123
+ },
124
+ {
125
+ reason: "person.delete-confirm",
126
+ code: "confirmation_required",
127
+ message: "this deletes the person, their identities and what names them alone; nothing was changed — add --yes",
128
+ details: ["plan"],
129
+ },
130
+ {
131
+ reason: "records.clear-synced",
132
+ code: "validation_error",
133
+ message: "{account} is an account a WireCat tool syncs, not an import; remove it with that tool",
134
+ details: ["account"],
135
+ },
136
+ {
137
+ reason: "records.clear-confirm",
138
+ code: "confirmation_required",
139
+ message: "this deletes {records} records of the source and its leads, deals and pipelines; nothing was changed — add --yes",
140
+ details: ["records"],
141
+ },
142
+ {
143
+ reason: "records.not-stored",
144
+ code: "not_found",
145
+ message: "no record {record} from that source; wcat records list shows them",
146
+ details: ["record"],
147
+ },
148
+ {
149
+ reason: "records.file-missing",
150
+ code: "not_found",
151
+ message: "no records file {path}: give a file that exists, or - for stdin",
152
+ details: ["path"],
153
+ },
154
+ {
155
+ reason: "records.file-unreadable",
156
+ code: "validation_error",
157
+ message: "the records file {path} cannot be read: {why}",
158
+ details: ["path", "why"],
159
+ },
160
+ {
161
+ reason: "findings.key-mismatch",
162
+ code: "validation_error",
163
+ message: "the batch's key {key} is not --key {given}; give the key once, as --key",
164
+ details: ["key", "given"],
165
+ },
166
+ {
167
+ reason: "findings.duplicate",
168
+ code: "validation_error",
169
+ message: "the order, invoice, payment, task or fact is stored or waits for the owner already; the answer names it",
170
+ details: [],
171
+ },
172
+ {
173
+ reason: "sync.running",
174
+ code: "rate_limited",
175
+ message: "another wcat sync is running (process {pid}); try again when it ends",
176
+ details: ["pid"],
177
+ },
178
+ {
179
+ reason: "folder.unbound",
180
+ code: "configuration_error",
181
+ message: "the notes folder {path} has no folder id; files folders add or files folders update gives it one",
182
+ details: ["path"],
183
+ },
184
+ { reason: "folder.not-found", code: "not_found", message: "the store has no such folder of notes", details: [] },
185
+ {
186
+ reason: "folder.overlap",
187
+ code: "validation_error",
188
+ message: "{path} is inside or around {other}, which wcat already reads; remove one of them first",
189
+ details: ["path", "other"],
190
+ },
191
+ {
192
+ reason: "folder.delete-notes",
193
+ code: "confirmation_required",
194
+ message: "removing the folder deletes {notes} of its notes from the store; nothing was changed — add --yes",
195
+ details: ["notes"],
196
+ },
197
+ {
198
+ reason: "notes.folder-missing",
199
+ code: "not_found",
200
+ message: "the notes folder {path} is missing — connect its disk; if it moved, files folders update <id> <new path>",
201
+ details: ["path"],
202
+ },
203
+ {
204
+ reason: "note.not-imported",
205
+ code: "not_found",
206
+ message: "the note is not imported; wcat sync --only notes",
207
+ details: [],
208
+ },
209
+ {
210
+ reason: "events.account-unknown",
211
+ code: "not_found",
212
+ message: "account: names no calendar account in the store; the message lists the ones it holds",
213
+ details: [],
214
+ },
215
+ {
216
+ reason: "import.too-many-files",
217
+ code: "validation_error",
218
+ message: "{path} holds more files than one import reads: import them by folder",
219
+ details: ["path"],
220
+ },
221
+ {
222
+ reason: "mail.account-unknown",
223
+ code: "not_found",
224
+ message: "no stored mailbox by that address; the mail CLI syncs one",
225
+ details: ["account"],
226
+ },
227
+ {
228
+ reason: "mail.moved-to-mail-cli",
229
+ code: "validation_error",
230
+ message: "the command moved to the mail CLI; the message names the command to run there",
231
+ details: ["cli", "alternative"],
232
+ },
233
+ {
234
+ reason: "project.not-found",
235
+ code: "not_found",
236
+ message: "no such project; wcat projects list shows them",
237
+ details: [],
238
+ },
239
+ { reason: "person.not-found", code: "not_found", message: "the store has no person by that name", details: [] },
240
+ {
241
+ reason: "bots.whole-store",
242
+ code: "validation_error",
243
+ message: "the bots commands read every account, so they do not run in an account group",
244
+ details: [],
245
+ },
246
+ {
247
+ reason: "identity.not-found",
248
+ code: "not_found",
249
+ message: "no identity has that exact id; people show lists them",
250
+ details: [],
251
+ },
252
+ {
253
+ reason: "proposal.not-found",
254
+ code: "not_found",
255
+ message: "no proposal has that id; people review lists them",
256
+ details: [],
257
+ },
258
+ {
259
+ reason: "proposal.not-people",
260
+ code: "validation_error",
261
+ message: "that proposal is not about people; wcat review decides it",
262
+ details: [],
263
+ },
264
+ {
265
+ reason: "identity.no-messenger",
266
+ code: "validation_error",
267
+ message: "the name has no messenger; write it as <messenger>:<name or id>",
268
+ details: [],
269
+ },
270
+ {
271
+ reason: "evidence.quote-unmatched",
272
+ code: "validation_error",
273
+ message: "a --quote names none of the --evidence references, or one twice; write it as <ref>=<the words>",
274
+ details: [],
275
+ },
276
+ { reason: "auto.systemctl-failed", code: "provider_error", message: "systemctl failed", details: [] },
277
+ {
278
+ reason: "deal.not-readable",
279
+ code: "not_found",
280
+ message: "the deal or lead is in a CRM copy whose sign-in may not read it (SEC-197)",
281
+ details: [],
282
+ },
283
+ {
284
+ reason: "stage.crm-copy",
285
+ code: "validation_error",
286
+ message: "the row is a CRM's copy: its CRM's CLI moves it to a base stage, as writes_with names it",
287
+ details: ["writes_with"],
288
+ },
289
+ {
290
+ reason: "reader.none-chosen",
291
+ code: "configuration_error",
292
+ message: "no reader is chosen for sources; the owner picks one with files sources readers set <reader>",
293
+ details: ["readers"],
294
+ },
295
+ {
296
+ reason: "reader.owner-picks",
297
+ code: "permission_error",
298
+ message: "only the owner picks the reader that reads a source; an agent uses the one the owner chose",
299
+ details: [],
300
+ },
301
+ {
302
+ reason: "reader.unknown",
303
+ code: "validation_error",
304
+ message: "{reader} is not a reader wcat knows; it reads with one of {readers}",
305
+ details: ["reader", "readers"],
306
+ },
307
+ {
308
+ reason: "reader.unavailable",
309
+ code: "configuration_error",
310
+ message: "the chosen reader cannot read now; files sources readers list says why and what fixes it",
311
+ details: [],
312
+ },
313
+ {
314
+ reason: "reader.address-refused",
315
+ code: "validation_error",
316
+ message: "the reader's address must be on this computer (localhost, 127.x.x.x or [::1]); --base-url is Ollama's only",
317
+ details: [],
318
+ },
319
+ {
320
+ reason: "reader.model-missing",
321
+ code: "configuration_error",
322
+ message: "the reader needs a model the owner names; files sources readers set <reader> --model <model>",
323
+ details: [],
324
+ },
325
+ {
326
+ reason: "reader.ai-not-set",
327
+ code: "configuration_error",
328
+ message: "no AI model is chosen for every tool; wcat models ai set <provider> --model <model> chooses one",
329
+ details: [],
330
+ },
331
+ {
332
+ reason: "reader.no-key",
333
+ code: "authentication_error",
334
+ message: "no API key is kept for the reader's provider; wcat models keys set <provider> keeps one",
335
+ details: [],
336
+ },
337
+ {
338
+ reason: "reader.not-running",
339
+ code: "provider_unavailable",
340
+ message: "the local model server is not running on this computer; start it, then try again",
341
+ details: [],
342
+ },
343
+ {
344
+ reason: "reader.timeout",
345
+ code: "timeout",
346
+ message: "the reader gave no answer in time; try again, or a smaller source",
347
+ details: [],
348
+ },
349
+ {
350
+ reason: "reader.limit",
351
+ code: "rate_limited",
352
+ message: "the reader's provider says the limit is reached; try again later",
353
+ details: [],
354
+ },
355
+ {
356
+ reason: "reader.failed",
357
+ code: "invalid_response",
358
+ message: "the reader failed; check its sign-in, key, model and credit, then try again",
359
+ details: [],
360
+ },
361
+ {
362
+ reason: "reader.unusable-answer",
363
+ code: "invalid_response",
364
+ message: "the reader's answer was not the JSON wcat asked for; nothing was staged, so try again",
365
+ details: [],
366
+ },
367
+ ]);
368
+ //# sourceMappingURL=reasons.js.map
@@ -0,0 +1,135 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { annotate } from "@wirecat/cli-base/commands";
3
+ import { defineQuery } from "@wirecat/cli-base/query";
4
+ import { environmentOf, LOCAL_READ, LOCAL_WRITE, listQuery, nativeTerms, recordColumns, recordTemplate, TABLE_RECORD_TYPES, termField, typedQuery, withQuery, } from "@wirecat/cli-core";
5
+ import { answers, itemAnswer, withStore } from "../answer.js";
6
+ import { importRecords, placeText } from "./input.js";
7
+ import { recordMappingCommands, sourceOf } from "./mapping.js";
8
+ import { recordCommands } from "./record-commands.js";
9
+ /** The review kinds of what the import proposed, as `wcat review kind:` takes them: each ref's prefix. */
10
+ const kindsOf = (proposed) => [...new Set(proposed.map((ref) => ref.slice(0, ref.indexOf(":"))))];
11
+ const LOCALES = ["en", "ru", "es"];
12
+ const TEMPLATES_QUERY = defineQuery({
13
+ entity: "records_templates",
14
+ backend: "native",
15
+ fields: [termField("type", "kw", "type:invoice")],
16
+ });
17
+ /** The envelope's root is `/`: an empty JSON pointer would break the answer's issue shape. */
18
+ const pointerOf = (pointer) => pointer || "/";
19
+ const refusedLine = (one) => `refused ${one.place ? placeText(one.place) : pointerOf(one.pointer)} · ${one.message} (${one.code})`;
20
+ export const receiptText = (receipt) => [
21
+ `${receipt.dryRun ? "would import" : "imported"} ${receipt.source?.batchId ?? "nothing"}: ` +
22
+ `${receipt.created} created, ${receipt.updated} updated, ${receipt.unchanged} unchanged, ` +
23
+ `${receipt.deleted} deleted, ${receipt.refused} refused`,
24
+ ...(receipt.proposed.length
25
+ ? [
26
+ `proposed for your review (wcat review list kind:${kindsOf(receipt.proposed).join(",")}): ` +
27
+ receipt.proposed.join(" "),
28
+ ]
29
+ : []),
30
+ ...receipt.waiting.map((one) => `waiting ${one.key}: no entity yet for ${one.missing.join(", ")}`),
31
+ ...receipt.unmatched.map((one) => `unmatched ${one.key}: ${one.candidates.length ? `could be ${one.candidates.join(" or ")}` : one.reason}; ` +
32
+ "you say which with wcat records link"),
33
+ ...receipt.flagged.map((one) => `changed at the source ${one.key}: ${one.entity} kept as it was`),
34
+ ...receipt.ignored.map((one) => `kept as data only ${one.key} ${one.pointer} (${one.reason})`),
35
+ ...(receipt.vcard ?? []).map((one) => `notice card ${one.card}: ${one.message}`),
36
+ ...receipt.errors.map(refusedLine),
37
+ ...(receipt.truncated ? ["the lists stop at 1000 entries each; the counts are exact"] : []),
38
+ ].join("\n");
39
+ const HOLDS_LOCK = "a dry run holds the store's write lock and grows the write-ahead log for its length";
40
+ export const recordsCommand = (program, streams, env) => {
41
+ const answered = answers(program, streams, env);
42
+ const { print } = answered;
43
+ const records = program
44
+ .command("records")
45
+ .description("what a source said, kept per account; what it says about money waits for your review")
46
+ .summary("what a source said, kept per account");
47
+ const importing = (command, dryRun) => command
48
+ .argument("<file>", "a records envelope as JSON, JSONL (a header line, then a record per line, read as it streams), a CSV sheet of one --type, or a vCard address book (.vcf, into phone:<device>); - for stdin")
49
+ .option("--type <type>", `the one type a CSV sheet holds: ${TABLE_RECORD_TYPES.join(", ")}`)
50
+ .option("--account <account>", "the source the envelope is for: <provider>:<account> (sheet:rentals) or its source.account alone; " +
51
+ "phone:<device> for a vCard file")
52
+ .option("--region <country>", "a vCard file's country for phone numbers without +, such as ru or gb; without it they are kept, not matched")
53
+ .option("--json", "print JSON; --json=created,errors keeps only those fields")
54
+ .action(async (file, given) => {
55
+ const account = given.account?.trim();
56
+ if (!account)
57
+ throw new CliError("validation_error", "name the source account the envelope is for: --account <account>", {
58
+ param: "--account",
59
+ });
60
+ const receipt = await withStore(env, (store) => importRecords(store, {
61
+ file,
62
+ stdin: environmentOf(program).stdin ?? process.stdin,
63
+ account,
64
+ dryRun: dryRun ?? given.dryRun === true,
65
+ onIssue: (issue) => streams.diagnostic(`${refusedLine(issue)}\n`),
66
+ ...(given.region === undefined ? {} : { region: given.region }),
67
+ ...(given.type === undefined ? {} : { type: given.type }),
68
+ }));
69
+ const issues = receipt.errors.map((one) => ({
70
+ code: "validation_error",
71
+ source: pointerOf(one.pointer),
72
+ reason: one.code,
73
+ }));
74
+ print(given.json, itemAnswer(receipt, issues.length ? { meta: { complete: false, issues } } : undefined), receiptText(receipt));
75
+ });
76
+ importing(annotate(records.command("import"), { effects: LOCAL_WRITE, output: { entity: "records_receipt" } })
77
+ .description("bring a source's records into the store, once: the same file twice changes nothing, a lower revision is " +
78
+ "refused, and anything that feeds money totals becomes a proposal for you, never confirmed money. Each " +
79
+ "refusal is also printed on stderr as it happens, one line each, past the receipt's 1000")
80
+ .summary("import a source's records; money waits for your review")
81
+ .option("--dry-run", `check and plan the import; write nothing. ${HOLDS_LOCK}`), undefined);
82
+ importing(
83
+ // A dry run holds the write lock for its length, so MCP gates it as a write.
84
+ annotate(records.command("check"), { effects: LOCAL_WRITE, output: { entity: "records_receipt" } })
85
+ .description(`what records import would do with the file, as its receipt, writing nothing; ${HOLDS_LOCK}`)
86
+ .summary("check a records file against the store; write nothing"), true);
87
+ const templates = records
88
+ .command("templates")
89
+ .description("files to fill for records import: a CSV header row or a JSON envelope, one type each")
90
+ .summary("files to fill for records import");
91
+ withQuery(annotate(templates.command("list"), { effects: LOCAL_READ, output: { entity: "records_templates" } }), TEMPLATES_QUERY)
92
+ .description("the types a sheet can hold, and their columns: whether each is required, its shape and its values")
93
+ .summary("the types a sheet can hold, with their columns")
94
+ .option("--json", "print JSON; --json=types keeps only those fields")
95
+ .action((words, given) => {
96
+ const terms = nativeTerms(listQuery(typedQuery(words), TEMPLATES_QUERY, "records templates list"), "records templates list");
97
+ const wanted = terms.get("type")?.value;
98
+ const types = TABLE_RECORD_TYPES.filter((one) => wanted === undefined || one === wanted).map((one) => ({
99
+ type: one,
100
+ columns: recordColumns(one),
101
+ }));
102
+ return print(given.json, itemAnswer({ types }), types.map((one) => one.type).join("\n"));
103
+ });
104
+ annotate(templates.command("show"), { effects: LOCAL_READ, output: { entity: "records_template" } })
105
+ .description("the file to fill for one type: the CSV header row (with a byte-order mark, so Excel reads it as UTF-8) or a " +
106
+ "JSON envelope of one example record")
107
+ .summary("the CSV or JSON file to fill for one type")
108
+ .argument("<type>", `one of ${TABLE_RECORD_TYPES.join(", ")}`)
109
+ .option("--format <format>", "csv or json", "csv")
110
+ // Excel in Russian or Spanish writes and expects ; between cells, because , is their decimal mark.
111
+ .option("--locale <code>", "the language of the Excel that opens it: en takes , and ru or es take ;", "en")
112
+ .option("--account <account>", "the source a JSON template names: <provider>:<account>, such as sheet:rentals")
113
+ .option("--json", "print JSON; --json=text keeps only those fields")
114
+ .action((type, given) => {
115
+ if (!TABLE_RECORD_TYPES.includes(type))
116
+ throw new CliError("validation_error", `no template for ${type}: use one of ${TABLE_RECORD_TYPES.join(", ")}`, {
117
+ param: "type",
118
+ });
119
+ if (given.format !== "csv" && given.format !== "json")
120
+ throw new CliError("validation_error", "--format is csv or json", { param: "--format" });
121
+ if (!LOCALES.includes(given.locale))
122
+ throw new CliError("validation_error", `--locale is one of ${LOCALES.join(", ")}`, { param: "--locale" });
123
+ const source = given.account === undefined ? undefined : sourceOf(given.account);
124
+ const text = recordTemplate(type, given.format, {
125
+ separator: given.locale === "en" ? "," : ";",
126
+ ...(source ? { source } : {}),
127
+ });
128
+ if (given.json)
129
+ return print(true, itemAnswer({ type, format: given.format, columns: recordColumns(type), text }));
130
+ streams.data(text);
131
+ });
132
+ recordMappingCommands(records, program, streams, env);
133
+ recordCommands(records, answered, (work) => withStore(env, work));
134
+ };
135
+ //# sourceMappingURL=import.js.map