@wirecat/wirecat 0.0.0-stage → 1.0.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 +400 -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-YETGUQ2J.js +43 -0
  16. package/dist/bundle/chunk-3ME37WWB.js +31 -0
  17. package/dist/bundle/chunk-4WI3FO7T.js +395 -0
  18. package/dist/bundle/chunk-7O7XM37N.js +2 -0
  19. package/dist/bundle/chunk-DWQQRBQV.js +51 -0
  20. package/dist/bundle/chunk-FOWR5KJS.js +72 -0
  21. package/dist/bundle/chunk-GGRL6DTE.js +120 -0
  22. package/dist/bundle/chunk-KNFSW562.js +312 -0
  23. package/dist/bundle/chunk-KPJVVFQF.js +416 -0
  24. package/dist/bundle/chunk-WMPDRWVF.js +222 -0
  25. package/dist/bundle/chunk-X5OK73GU.js +807 -0
  26. package/dist/bundle/chunk-ZC4PRE6C.js +38 -0
  27. package/dist/bundle/entry-S4DSYEAY.js +64 -0
  28. package/dist/bundle/failure-FALOD7QW.js +19 -0
  29. package/dist/bundle/from-memo-XVOLSUOM.js +314 -0
  30. package/dist/bundle/program-XSZSINBU.js +14994 -0
  31. package/dist/bundle/server-GQ4NZUDL.js +303 -0
  32. package/dist/bundle/update-2EH5KHTV.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,416 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ decisionPolicy
5
+ } from "./chunk-KNFSW562.js";
6
+ import {
7
+ STORE_CLIENT,
8
+ __name
9
+ } from "./chunk-4WI3FO7T.js";
10
+
11
+ // dist/answer.js
12
+ import { CliError as CliError2, createRenderer } from "@wirecat/cli-base";
13
+ import { COMPACT_FLAG } from "@wirecat/cli-base/standards";
14
+ import { compactText, currentRun, itemOf, listOf, openStore, renderAnswer, rootOf, sealed } from "@wirecat/cli-core";
15
+
16
+ // dist/output.js
17
+ import { resolveOutput, snakeKeysKeeping } from "@wirecat/cli-core";
18
+ var snakeKeys = snakeKeysKeeping(["front_matter", "metadata", "headers"]);
19
+ var atDetail = /* @__PURE__ */ __name((value, level) => {
20
+ let picked = "";
21
+ resolveOutput({
22
+ json: true,
23
+ streams: { data: /* @__PURE__ */ __name((chunk) => picked += chunk, "data"), diagnostic: /* @__PURE__ */ __name(() => void 0, "diagnostic"), progress: /* @__PURE__ */ __name(() => void 0, "progress") },
24
+ ...level === void 0 ? {} : { hitDetail: level }
25
+ }).renderer.result(value);
26
+ return JSON.parse(picked);
27
+ }, "atDetail");
28
+
29
+ // dist/rows.js
30
+ import { rowShapeOf, rowsOfEntity } from "@wirecat/cli-core";
31
+ var sender = { field: ["sender_is_me", "sender_name"], tag: "me" };
32
+ var fact = {
33
+ columns: [
34
+ { field: "ref" },
35
+ { field: "kind" },
36
+ { field: "status" },
37
+ { field: "subject_name" },
38
+ { field: "project_name" },
39
+ { field: ["occurred_at", "created_at"], as: "day" }
40
+ ],
41
+ text: ["text"]
42
+ };
43
+ var LINED = {
44
+ columns: [{ field: "ref" }, { field: "title" }, { field: "status" }, { field: "review" }],
45
+ sections: { lines: "memo_money_line" }
46
+ };
47
+ var PROPOSAL_ROW = {
48
+ columns: [
49
+ { field: "id" },
50
+ { field: "kind" },
51
+ { field: "title" },
52
+ { field: "score" },
53
+ { field: "proposer" },
54
+ { field: "created_at", as: "day" }
55
+ ],
56
+ text: ["reason"]
57
+ };
58
+ var DECISIONS = {
59
+ columns: [],
60
+ sections: { decided: "memo_decided", refused: "memo_refused" },
61
+ oneLine: true
62
+ };
63
+ var ROWS = {
64
+ "search all": {
65
+ columns: [{ field: "ref" }, { field: "kind" }, { field: "timestamp", as: "time" }, { field: "title" }, sender],
66
+ text: ["excerpt"]
67
+ },
68
+ "search notes": {
69
+ columns: [{ field: "ref" }, { field: "updated_at", as: "day" }, { field: ["title", "path"] }],
70
+ text: ["excerpt"]
71
+ },
72
+ "search memories": fact,
73
+ "search people": { columns: [{ field: "ref" }, { field: "name" }] },
74
+ "notes list": {
75
+ columns: [
76
+ { field: "ref" },
77
+ { field: "updated_at", as: "day" },
78
+ { field: "source" },
79
+ { field: ["title", "path"] },
80
+ { field: "via" }
81
+ ],
82
+ text: ["text"]
83
+ },
84
+ "facts list": fact,
85
+ "invoices list": {
86
+ columns: [{ field: "ref" }, { field: "project_name" }, { field: ["issue_date", "created_at"], as: "day" }],
87
+ text: ["title"]
88
+ },
89
+ "payments list": {
90
+ columns: [{ field: "ref" }, { field: "project_name" }, { field: "date", as: "day" }],
91
+ text: ["title"]
92
+ },
93
+ "deals list": {
94
+ columns: [{ field: "ref" }, { field: "project_name" }, { field: "close_date", as: "day" }],
95
+ text: ["summary"]
96
+ },
97
+ "leads list": {
98
+ columns: [{ field: "ref" }, { field: "project_name" }, { field: "created_at", as: "day" }],
99
+ text: ["summary"]
100
+ },
101
+ "memories list": fact,
102
+ "people list": {
103
+ columns: [
104
+ { field: "ref" },
105
+ { field: "display_name" },
106
+ { field: "contact" },
107
+ { field: "owner", tag: "owner" },
108
+ { field: "messages_from", as: "count", tag: "messages" },
109
+ { field: "tasks", as: "count", tag: "tasks" },
110
+ { field: "kind_signals" }
111
+ ]
112
+ },
113
+ "people check": {
114
+ columns: [
115
+ { field: "ref" },
116
+ { field: "display_name" },
117
+ { field: "contact" },
118
+ { field: "kind" },
119
+ { field: "same_name", tag: "same name" }
120
+ ]
121
+ },
122
+ "events list": {
123
+ columns: [
124
+ { field: "ref" },
125
+ { field: ["starts_at", "ends_at"], as: "time" },
126
+ { field: "event_type" },
127
+ { field: "in" },
128
+ { field: "title" }
129
+ ],
130
+ text: ["description"]
131
+ },
132
+ "organizations list": { columns: [{ field: "ref" }, { field: "name" }, { field: "kind" }] },
133
+ "projects list": { columns: [{ field: "ref" }, { field: "key" }, { field: "name" }, { field: "kind" }] },
134
+ "relationships list": {
135
+ columns: [
136
+ { field: "id" },
137
+ { field: "from" },
138
+ { field: "kind" },
139
+ { field: "to" },
140
+ { field: "role" },
141
+ { field: "purpose" },
142
+ { field: "confirmed", tag: "confirmed" }
143
+ ]
144
+ },
145
+ "tasks list": {
146
+ columns: [
147
+ { field: ["key", "ref", "id"] },
148
+ { field: "state" },
149
+ { field: "kind" },
150
+ { field: "priority_label" },
151
+ { field: "project_key" },
152
+ { field: "due_at", as: "day" },
153
+ { field: "source" }
154
+ ],
155
+ text: ["title", "message.text"]
156
+ },
157
+ "messages show": {
158
+ columns: [
159
+ { field: "ref" },
160
+ { field: ["timestamp", "date"], as: "time" },
161
+ { field: "chat_title" },
162
+ { field: ["from", "sender_is_me", "sender_name"], tag: "me" },
163
+ { field: "subject" },
164
+ { field: "attachments", as: "files" }
165
+ ],
166
+ text: ["text", "excerpt"]
167
+ },
168
+ "projects evidence": {
169
+ columns: [{ field: "project_ref" }],
170
+ sections: { items: "memo_evidence_item", people: "memo_evidence_person", linked_chats: "linked_chat" }
171
+ },
172
+ show: {
173
+ columns: [{ field: "ref" }, { field: "kind" }, { field: "state" }, { field: "title" }, { field: "open.line" }]
174
+ },
175
+ "wallets list": {
176
+ columns: [{ field: "ref" }, { field: "title" }, { field: "balance.amount" }, { field: "balance.currency" }]
177
+ },
178
+ "review show": { ...PROPOSAL_ROW, oneLine: true },
179
+ "review confirm": DECISIONS,
180
+ "review reject": DECISIONS,
181
+ "orders show": LINED,
182
+ "orders lines add": LINED,
183
+ "orders lines remove": LINED,
184
+ "invoices show": LINED,
185
+ "invoices lines add": LINED,
186
+ "invoices lines remove": LINED
187
+ };
188
+ var SECTION_ROWS = {
189
+ memo_evidence_item: {
190
+ columns: [{ field: "ref" }, { field: "context" }, { field: "kind" }, { field: "title" }],
191
+ text: ["text"]
192
+ },
193
+ memo_finance: {
194
+ columns: [
195
+ { field: "direction" },
196
+ { field: "currency" },
197
+ { field: "billed" },
198
+ { field: "paid" },
199
+ { field: "owed" },
200
+ { field: "invoices", as: "count", tag: "invoices" },
201
+ { field: "payments", as: "count", tag: "payments" }
202
+ ]
203
+ },
204
+ memo_deal: {
205
+ columns: [
206
+ { field: "ref" },
207
+ { field: "stage" },
208
+ { field: "amount" },
209
+ { field: "currency" },
210
+ { field: "close_date", as: "day" }
211
+ ],
212
+ text: ["title"]
213
+ },
214
+ memo_money_line: {
215
+ columns: [
216
+ { field: "position" },
217
+ { field: "quantity" },
218
+ { field: "unit_price" },
219
+ { field: "amount" },
220
+ { field: "product" }
221
+ ],
222
+ text: ["description"]
223
+ },
224
+ memo_decided: { columns: [{ field: "id" }, { field: "status" }, { field: "kind" }] },
225
+ memo_refused: { columns: [{ field: "id" }, { field: "code" }, { field: "reason" }], text: ["message"] },
226
+ memo_evidence_person: {
227
+ columns: [{ field: "person" }, { field: "name" }, { field: "items", as: "count", tag: "items" }]
228
+ }
229
+ };
230
+ var shared = rowsOfEntity();
231
+ var sectionRowOf = /* @__PURE__ */ __name((entity) => SECTION_ROWS[entity] ?? shared(entity), "sectionRowOf");
232
+ var pathOf = /* @__PURE__ */ __name((command) => {
233
+ const words = [];
234
+ for (let at = command; at?.parent; at = at.parent)
235
+ words.unshift(at.name());
236
+ return words.join(" ");
237
+ }, "pathOf");
238
+ var rowOf = /* @__PURE__ */ __name((command) => command && ROWS[pathOf(command)] || rowShapeOf(command), "rowOf");
239
+
240
+ // dist/store/crm-viewer.js
241
+ import { CliError } from "@wirecat/cli-base";
242
+ import { crmViewerOf, kindIn } from "@wirecat/cli-core";
243
+ var shortened = /* @__PURE__ */ new WeakMap();
244
+ var crmNotes = /* @__PURE__ */ __name((store) => [...shortened.get(store) ?? []], "crmNotes");
245
+ var crmViewing = /* @__PURE__ */ __name(async (store, key) => {
246
+ if (kindIn(key.provider) !== "crm")
247
+ return { viewer: void 0 };
248
+ const viewing = await crmViewerOf(store, key, await store.crm.ownUser(key) ?? null);
249
+ if (viewing.note) {
250
+ const notes = shortened.get(store) ?? /* @__PURE__ */ new Set();
251
+ notes.add(`${key.provider}:${key.account}: ${viewing.note}`);
252
+ shortened.set(store, notes);
253
+ }
254
+ return viewing;
255
+ }, "crmViewing");
256
+ var crmAccounts = /* @__PURE__ */ __name(async (store) => (await store.accounts.accounts()).filter((key) => kindIn(key.provider) === "crm"), "crmAccounts");
257
+ var crmViewingAll = /* @__PURE__ */ __name(async (store) => Promise.all((await crmAccounts(store)).map((key) => crmViewing(store, key))), "crmViewingAll");
258
+ var crmViewersAll = /* @__PURE__ */ __name(async (store) => crmViewers(store, await crmAccounts(store)), "crmViewersAll");
259
+ var crmViewers = /* @__PURE__ */ __name(async (store, keys) => (await Promise.all(keys.map(async (key) => (await crmViewing(store, key)).viewer))).filter((one) => one !== void 0), "crmViewers");
260
+ var crmSees = /* @__PURE__ */ __name((store) => {
261
+ const known = /* @__PURE__ */ new Map();
262
+ return async (row) => {
263
+ if (row.account === null)
264
+ return true;
265
+ const id = `${row.account.provider}:${row.account.account}`;
266
+ if (!known.has(id))
267
+ known.set(id, crmViewing(store, row.account).then(({ viewer: viewer2 }) => viewer2));
268
+ const viewer = await known.get(id);
269
+ return viewer === void 0 || viewer.assignee !== null && row.assignee === viewer.assignee;
270
+ };
271
+ }, "crmSees");
272
+ var seenPage = /* @__PURE__ */ __name(async (store, most, read) => {
273
+ const sees = crmSees(store);
274
+ const kept = [];
275
+ let offset = 0;
276
+ let more = true;
277
+ while (more && kept.length <= most) {
278
+ const page = await read(most + 1, offset);
279
+ for (const row of page.items)
280
+ if (await sees(row))
281
+ kept.push(row);
282
+ offset += page.items.length;
283
+ more = page.hasMore && page.items.length > 0;
284
+ }
285
+ return { items: kept.slice(0, most), hasMore: kept.length > most || more };
286
+ }, "seenPage");
287
+ var readableDeal = /* @__PURE__ */ __name(async (store, ref) => {
288
+ const found = await store.deals.get(ref);
289
+ if (!await crmSees(store)(found)) {
290
+ const why = crmNotes(store);
291
+ throw new CliError("not_found", `${ref} is not a copy this store's CRM sign-in may read${why.length ? `: ${why.join("; ")}` : ""}`, { reason: "deal.not-readable" });
292
+ }
293
+ return found;
294
+ }, "readableDeal");
295
+ var readablePipeline = /* @__PURE__ */ __name(async (store, ref, options = {}) => {
296
+ const report = await store.deals.pipeline(ref, options);
297
+ if (report.account === null)
298
+ return report;
299
+ const { viewer } = await crmViewing(store, report.account);
300
+ return viewer === void 0 ? report : store.deals.pipeline(report.ref, { ...options, viewer });
301
+ }, "readablePipeline");
302
+ var readablePipelines = /* @__PURE__ */ __name(async (store, pipelines, kind) => {
303
+ const accounts = new Map(pipelines.flatMap(({ account }) => account ? [[`${account.provider}:${account.account}`, account]] : []));
304
+ const seen = /* @__PURE__ */ new Map();
305
+ for (const account of accounts.values()) {
306
+ const { viewer } = await crmViewing(store, account);
307
+ if (viewer === void 0)
308
+ continue;
309
+ for (const one of await store.deals.pipelines({ ...kind === void 0 ? {} : { kind }, account, viewer }))
310
+ seen.set(one.ref, one);
311
+ }
312
+ return pipelines.map((one) => seen.get(one.ref) ?? one);
313
+ }, "readablePipelines");
314
+
315
+ // dist/answer.js
316
+ var itemAnswer = /* @__PURE__ */ __name((value, extra) => itemOf(snakeKeys(value), extra), "itemAnswer");
317
+ var listAnswer = /* @__PURE__ */ __name((command, input) => {
318
+ const body = listOf(command, { ...input, items: snakeKeys(input.items) });
319
+ if (input.cursor !== void 0 || input.page !== void 0)
320
+ return body;
321
+ if (body.page.mode === "page")
322
+ delete body.page.next_page;
323
+ const next = body.next?.filter(({ step }) => step !== "page.next") ?? [];
324
+ if (next.length > 0)
325
+ body.next = next;
326
+ else
327
+ delete body.next;
328
+ return body;
329
+ }, "listAnswer");
330
+ var wholeList = /* @__PURE__ */ __name((command, items) => listAnswer(command, { items, limit: Math.max(1, items.length), has_more: false }), "wholeList");
331
+ var openMemoStore = /* @__PURE__ */ __name((env) => openStore({ env, ...STORE_CLIENT, decisions: decisionPolicy(env) }), "openMemoStore");
332
+ var withStore = /* @__PURE__ */ __name(async (env, work) => {
333
+ const store = await openMemoStore(env);
334
+ try {
335
+ return await work(store);
336
+ } finally {
337
+ await store.close();
338
+ }
339
+ }, "withStore");
340
+ var running = /* @__PURE__ */ new WeakMap();
341
+ var noted = /* @__PURE__ */ new WeakMap();
342
+ var shortenedBy = /* @__PURE__ */ __name((notes, body) => {
343
+ if (notes.length === 0)
344
+ return body;
345
+ const marked = { ...body, meta: { ...body.meta, complete: false } };
346
+ noted.set(marked, notes);
347
+ return marked;
348
+ }, "shortenedBy");
349
+ var timezone = /* @__PURE__ */ __name(() => Intl.DateTimeFormat().resolvedOptions().timeZone, "timezone");
350
+ var plainText = /* @__PURE__ */ __name((body, command) => {
351
+ const { next: _, ...rest } = body;
352
+ return compactText(rest, rowOf(command), { timezone: timezone() }, sectionRowOf);
353
+ }, "plainText");
354
+ var compactView = /* @__PURE__ */ __name((command, full) => (kept) => {
355
+ const whole = sealed(kept);
356
+ const next = whole.next?.map((step) => step.kind === "command" && step.line ? { ...step, line: `${step.line} ${COMPACT_FLAG}` } : step);
357
+ return compactText(next ? { ...whole, next } : whole, rowOf(command), {
358
+ timezone: timezone(),
359
+ ...full ? { textChars: 0 } : {}
360
+ }, sectionRowOf);
361
+ }, "compactView");
362
+ var trackAnswers = /* @__PURE__ */ __name((program) => {
363
+ currentRun();
364
+ program.option(COMPACT_FLAG, "one line per item for an agent: reference first, text last, paging and next steps as # lines").hook("preAction", (root, leaf) => {
365
+ const { compact, json, brief } = leaf.optsWithGlobals();
366
+ if (compact && (json || brief))
367
+ throw new CliError2("validation_error", `${COMPACT_FLAG} and ${json ? "--json" : "--brief"} are two forms \u2014 pick one`);
368
+ running.set(root, leaf);
369
+ });
370
+ }, "trackAnswers");
371
+ var answers = /* @__PURE__ */ __name((program, streams, env) => {
372
+ const print = /* @__PURE__ */ __name((json, body, text, asked) => {
373
+ const format = json ? "json" : "pretty";
374
+ const root = rootOf(program);
375
+ const leaf = running.get(root) ?? root;
376
+ const { compact = asked, full } = leaf.optsWithGlobals();
377
+ const renderer = createRenderer({ format, color: false, streams });
378
+ for (const note of noted.get(body) ?? [])
379
+ renderer.note(note);
380
+ const drawn = compact === true && !json;
381
+ renderAnswer(leaf, { renderer: drawn ? { ...renderer, note: /* @__PURE__ */ __name(() => void 0, "note") } : renderer, format, streams }, body, drawn ? compactView(leaf, full === true) : () => `${text ?? plainText(body, leaf)}
382
+ `);
383
+ }, "print");
384
+ return {
385
+ print,
386
+ run: /* @__PURE__ */ __name(async (json, work) => print(json, await withStore(env, async (store) => {
387
+ const body = await work(store);
388
+ return shortenedBy(crmNotes(store), body);
389
+ })), "run")
390
+ };
391
+ }, "answers");
392
+
393
+ export {
394
+ snakeKeys,
395
+ atDetail,
396
+ PROPOSAL_ROW,
397
+ crmNotes,
398
+ crmViewing,
399
+ crmViewingAll,
400
+ crmViewersAll,
401
+ crmViewers,
402
+ seenPage,
403
+ readableDeal,
404
+ readablePipeline,
405
+ readablePipelines,
406
+ itemAnswer,
407
+ listAnswer,
408
+ wholeList,
409
+ openMemoStore,
410
+ withStore,
411
+ shortenedBy,
412
+ timezone,
413
+ plainText,
414
+ trackAnswers,
415
+ answers
416
+ };
@@ -0,0 +1,222 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ answers,
5
+ itemAnswer
6
+ } from "./chunk-KPJVVFQF.js";
7
+ import {
8
+ loadConfig,
9
+ updateConfig
10
+ } from "./chunk-KNFSW562.js";
11
+ import {
12
+ __name
13
+ } from "./chunk-4WI3FO7T.js";
14
+
15
+ // dist/run/auto.js
16
+ import { execFile } from "node:child_process";
17
+ import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
18
+ import { homedir } from "node:os";
19
+ import { dirname, join, resolve } from "node:path";
20
+ import { fileURLToPath } from "node:url";
21
+ import { CliError, resolvePaths } from "@wirecat/cli-base";
22
+ import { annotate } from "@wirecat/cli-base/commands";
23
+ import { installerOf } from "@wirecat/cli-base/update";
24
+ import { failingNotice, LOCAL_READ, LOCAL_WRITE, recordRun } from "@wirecat/cli-core";
25
+ import { InvalidArgumentError } from "commander";
26
+ var DEFAULT_EVERY = "5m";
27
+ var UNIT = "wcat-import";
28
+ var lastRunPath = /* @__PURE__ */ __name((env) => join(resolvePaths({ appName: "wcat", prefix: "WCAT", env }).state, "auto", "last.json"), "lastRunPath");
29
+ var lastAutoRun = /* @__PURE__ */ __name((env) => {
30
+ try {
31
+ return JSON.parse(readFileSync(lastRunPath(env), "utf8"));
32
+ } catch {
33
+ return void 0;
34
+ }
35
+ }, "lastAutoRun");
36
+ var recordAutoRun = /* @__PURE__ */ __name((env, at, reason) => {
37
+ if (env.WCAT_AUTO !== "1")
38
+ return;
39
+ recordRun(lastRunPath(env), {
40
+ at: new Date(at).toISOString(),
41
+ exitCode: reason === void 0 ? 0 : 1,
42
+ output: `journalctl --user -u ${UNIT}.service`,
43
+ ...reason === void 0 ? {} : { reason }
44
+ });
45
+ }, "recordAutoRun");
46
+ var autoNotice = /* @__PURE__ */ __name((env) => env.WCAT_AUTO === "1" ? void 0 : failingNotice("wcat", [{ job: "sync", last: lastAutoRun(env) }], "wcat jobs status"), "autoNotice");
47
+ var interval = /* @__PURE__ */ __name((value) => {
48
+ const match = /^(\d+)(s|m|h)$/.exec(value.trim());
49
+ const seconds = match === null ? 0 : Number(match[1]) * { s: 1, m: 60, h: 3600 }[match[2]];
50
+ if (seconds < 60)
51
+ throw new InvalidArgumentError("an interval of a minute or more, like 5m, 90s or 1h");
52
+ return value.trim();
53
+ }, "interval");
54
+ var systemdSpan = /* @__PURE__ */ __name((every) => every.replace(/m$/, "min"), "systemdSpan");
55
+ var unitDir = /* @__PURE__ */ __name((env) => join(env.XDG_CONFIG_HOME ?? join(env.HOME ?? homedir(), ".config"), "systemd", "user"), "unitDir");
56
+ var quote = /* @__PURE__ */ __name((arg) => `"${arg.replace(/(["\\])/g, "\\$1")}"`, "quote");
57
+ var wcatBin = /* @__PURE__ */ __name(() => resolve(dirname(fileURLToPath(new URL("../run/auto.js", import.meta.url).href)), "../bin/wcat-wirecat.js"), "wcatBin");
58
+ var PLACE_VARIABLES = [
59
+ "WCAT_CONFIG_DIR",
60
+ "WCAT_STATE_DIR",
61
+ "WCAT_CACHE_DIR",
62
+ "MESSAGING_STORE",
63
+ "WIRECAT_STATE_DIR"
64
+ ];
65
+ var placesOf = /* @__PURE__ */ __name((env) => Object.fromEntries(PLACE_VARIABLES.flatMap((name) => env[name] ? [[name, env[name]]] : [])), "placesOf");
66
+ var execStart = /* @__PURE__ */ __name(() => `ExecStart=${[process.execPath, wcatBin(), "sync"].map(quote).join(" ")}`, "execStart");
67
+ var serviceUnit = /* @__PURE__ */ __name((env, places = {}) => [
68
+ "[Unit]",
69
+ "Description=wcat: sync notes into the shared store and embed stored mail",
70
+ "",
71
+ "[Service]",
72
+ "Type=oneshot",
73
+ execStart(),
74
+ // The programs wcat calls are found on the PATH wcat was set up with.
75
+ `Environment=${[`PATH=${env.PATH ?? ""}`, ...Object.entries(places).map(([name, value]) => `${name}=${value}`)].map(quote).join(" ")} WCAT_AUTO=1`,
76
+ "Nice=10",
77
+ ""
78
+ ].join("\n"), "serviceUnit");
79
+ var timerUnit = /* @__PURE__ */ __name((every) => [
80
+ "[Unit]",
81
+ `Description=wcat: sync notes and embed stored mail every ${every}`,
82
+ "",
83
+ "[Timer]",
84
+ "OnActiveSec=1min",
85
+ // From when a sync ends: counted from its start, a sync longer than the interval left no next run.
86
+ `OnUnitInactiveSec=${systemdSpan(every)}`,
87
+ "AccuracySec=30s",
88
+ "",
89
+ "[Install]",
90
+ "WantedBy=timers.target",
91
+ ""
92
+ ].join("\n"), "timerUnit");
93
+ var systemctl = /* @__PURE__ */ __name((env) => (...args) => new Promise((done, fail) => execFile(env.WCAT_SYSTEMCTL ?? "systemctl", ["--user", ...args], { env }, (error, stdout, stderr) => error === null ? done(stdout) : fail(new CliError("provider_error", `systemctl ${args.join(" ")}: ${stderr.trim() || error.message}`, {
94
+ reason: "auto.systemctl-failed"
95
+ })))), "systemctl");
96
+ var autoState = /* @__PURE__ */ __name((config) => ({
97
+ enabled: config.auto?.enabled ?? false,
98
+ every: config.auto?.every ?? DEFAULT_EVERY,
99
+ places: config.auto?.places ?? {}
100
+ }), "autoState");
101
+ var applyAuto = /* @__PURE__ */ __name(async (env, state, unit = UNIT, path = env.PATH) => {
102
+ const run = systemctl(env);
103
+ const dir = unitDir(env);
104
+ const timerPath = join(dir, `${unit}.timer`);
105
+ const servicePath = join(dir, `${unit}.service`);
106
+ if (!state.enabled) {
107
+ if (!existsSync(timerPath) && !existsSync(servicePath))
108
+ return;
109
+ await run("disable", "--now", `${unit}.timer`).catch(() => "");
110
+ rmSync(timerPath, { force: true });
111
+ rmSync(servicePath, { force: true });
112
+ await run("daemon-reload");
113
+ return;
114
+ }
115
+ const wanted = {
116
+ [servicePath]: serviceUnit({ ...env, PATH: path }, state.places),
117
+ [timerPath]: timerUnit(state.every)
118
+ };
119
+ const stale = Object.entries(wanted).filter(([path2, text]) => !existsSync(path2) || readFileSync(path2, "utf8") !== text);
120
+ if (stale.length === 0)
121
+ return;
122
+ mkdirSync(dir, { recursive: true });
123
+ for (const [path2, text] of stale)
124
+ writeFileSync(path2, text);
125
+ await run("daemon-reload");
126
+ await run("enable", "--now", `${unit}.timer`);
127
+ if (stale.some(([path2]) => path2 === timerPath))
128
+ await run("restart", `${unit}.timer`);
129
+ }, "applyAuto");
130
+ var globalRoots = /* @__PURE__ */ __name((env, execPath = process.execPath) => {
131
+ const home = env.HOME ?? homedir();
132
+ const bin = dirname(execPath);
133
+ const npmPrefix = env.npm_config_prefix ?? env.NPM_CONFIG_PREFIX;
134
+ return [
135
+ resolve(bin, "..", "lib", "node_modules"),
136
+ resolve(bin, "node_modules"),
137
+ ...npmPrefix ? [resolve(npmPrefix, "lib", "node_modules"), resolve(npmPrefix, "node_modules")] : [],
138
+ "/usr/lib/node_modules",
139
+ "/usr/local/lib/node_modules",
140
+ resolve(env.PNPM_HOME ?? join(home, ".local", "share", "pnpm"), "global"),
141
+ resolve(env.BUN_INSTALL ?? join(home, ".bun"), "install", "global")
142
+ ];
143
+ }, "globalRoots");
144
+ var isGlobal = /* @__PURE__ */ __name((scriptPath, roots) => roots.some((root) => scriptPath.startsWith(`${root}/`) || scriptPath.startsWith(`${root}\\`)), "isGlobal");
145
+ var followInstall = /* @__PURE__ */ __name(async (env, scriptPath, roots = globalRoots(env)) => {
146
+ if (env.WCAT_AUTO === "1")
147
+ return;
148
+ scriptPath ??= realpathSync(wcatBin());
149
+ if (!["npm", "pnpm", "bun"].includes(installerOf(scriptPath)))
150
+ return;
151
+ if (!isGlobal(scriptPath, roots))
152
+ return;
153
+ if (!autoState(loadConfig(env)).enabled)
154
+ return;
155
+ const servicePath = join(unitDir(env), `${UNIT}.service`);
156
+ if (!existsSync(servicePath))
157
+ return;
158
+ const current = readFileSync(servicePath, "utf8");
159
+ const moved = current.replace(/^ExecStart=.*$/m, execStart());
160
+ if (moved === current)
161
+ return;
162
+ writeFileSync(servicePath, moved);
163
+ await systemctl(env)("daemon-reload");
164
+ }, "followInstall");
165
+ var failingOf = /* @__PURE__ */ __name((last) => last && last.exitCode !== 0 ? { since: last.failingSince ?? last.at, runs: last.failures ?? 1, reason: last.reason ?? null, log: last.output } : null, "failingOf");
166
+ var autoCommand = /* @__PURE__ */ __name((program, streams, env) => {
167
+ const run = systemctl(env);
168
+ const { print } = answers(program, streams, env);
169
+ const auto = program.command("jobs").description("run wcat sync on a systemd user timer, set in the config");
170
+ annotate(auto.command("start"), { effects: LOCAL_WRITE }).description("sync every --every (default auto.every, else 5m), starting a minute from now").option("--every <duration>", "how often: 5m, 90s, 1h \u2014 a minute or more", interval).action(async (options) => {
171
+ const config = updateConfig((current) => ({
172
+ ...current,
173
+ auto: { enabled: true, every: options.every ?? autoState(current).every, places: placesOf(env) }
174
+ }), env);
175
+ await applyAuto(env, autoState(config));
176
+ streams.data(`wcat sync runs every ${autoState(config).every}.
177
+ `);
178
+ });
179
+ annotate(auto.command("stop"), { effects: LOCAL_WRITE }).description("stop syncing on a timer and remove the timer").action(async () => {
180
+ const config = updateConfig((current) => ({ ...current, auto: { ...current.auto, enabled: false } }), env);
181
+ await applyAuto(env, autoState(config));
182
+ streams.data("wcat sync no longer runs on a timer.\n");
183
+ });
184
+ annotate(auto.command("status"), { effects: LOCAL_READ }).description("whether the timer is on, its interval, its next run and how the last one ended").option("--json", "print JSON; --json=id,title keeps only those fields").action(async (options) => {
185
+ const state = autoState(loadConfig(env));
186
+ const show = /* @__PURE__ */ __name(async (unit, properties) => Object.fromEntries((await run("show", unit, "--property", properties).catch(() => "")).split("\n").filter(Boolean).map((line) => [line.slice(0, line.indexOf("=")), line.slice(line.indexOf("=") + 1)])), "show");
187
+ const timer = await show(`${UNIT}.timer`, "ActiveState");
188
+ const service = await show(`${UNIT}.service`, "Result");
189
+ const listed = JSON.parse(await run("list-timers", `${UNIT}.timer`, "--output=json").catch(() => "[]") || "[]")[0];
190
+ const when = /* @__PURE__ */ __name((micros) => typeof micros === "number" && micros > 0 ? new Date(micros / 1e3).toISOString() : null, "when");
191
+ const status = {
192
+ ...state,
193
+ timer: timer.ActiveState ?? "unknown",
194
+ next: when(listed?.next),
195
+ last: when(listed?.last),
196
+ lastResult: service.Result || null,
197
+ failing: failingOf(lastAutoRun(env))
198
+ };
199
+ print(options.json, itemAnswer(status), `${status.enabled ? `on, every ${status.every}` : "off"} \u2014 timer ${status.timer}` + (status.next ? `, next ${status.next}` : "") + (status.last ? `, last ${status.last} (${status.lastResult ?? "?"})` : "") + (status.failing ? `
200
+ failing since ${status.failing.since} (${status.failing.runs} runs)` + (status.failing.reason ? `: ${status.failing.reason}` : "") + `
201
+ the full message: ${status.failing.log}` : ""));
202
+ });
203
+ }, "autoCommand");
204
+
205
+ export {
206
+ DEFAULT_EVERY,
207
+ UNIT,
208
+ lastAutoRun,
209
+ recordAutoRun,
210
+ autoNotice,
211
+ interval,
212
+ unitDir,
213
+ PLACE_VARIABLES,
214
+ placesOf,
215
+ serviceUnit,
216
+ timerUnit,
217
+ autoState,
218
+ applyAuto,
219
+ globalRoots,
220
+ followInstall,
221
+ autoCommand
222
+ };