@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,346 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { annotate } from "@wirecat/cli-base/commands";
3
+ import { baseStagesCommand, DEAL_KINDS, DEAL_ROLES, DEAL_STATUSES, dealBrief, dealContext, LOCAL_READ, LOCAL_WRITE, queryTerms, storedProfilesFor, termField, withQuery, writesWithOf, } from "@wirecat/cli-core";
4
+ import { answers, itemAnswer, openMemoStore, shortenedBy, wholeList, withStore } from "../answer.js";
5
+ import { APP } from "../app.js";
6
+ import { authorOf } from "../author.js";
7
+ import { collect, positive } from "../options.js";
8
+ import { pageOf } from "../page.js";
9
+ import { withSources } from "../records/sources.js";
10
+ import { deniedCrmKinds } from "../search/denied.js";
11
+ import { crmNotes, crmViewingAll, readableDeal, readablePipeline, readablePipelines, seenPage, } from "../store/crm-viewer.js";
12
+ import { groupScopeOf } from "../store/group.js";
13
+ import { lockedCoverage } from "../store/guard.js";
14
+ import { canonicalProject } from "../vocabulary/project.js";
15
+ import { dealBriefText, dealText } from "./deal-text.js";
16
+ import { dayOf } from "./finance.js";
17
+ import { json } from "./written.js";
18
+ const queryOf = (entity) => ({
19
+ entity,
20
+ backend: "native",
21
+ fields: [
22
+ termField("project", "kw", "project:PMED"),
23
+ termField("status", "enum", "status:open", { values: DEAL_STATUSES }),
24
+ termField("stage", "kw", 'stage:"Quote sent"'),
25
+ termField("pipeline", "kw", "pipeline:Sales"),
26
+ termField("organization", "ref", 'organization:"organization:3"'),
27
+ ],
28
+ });
29
+ const QUERIES = { deal: queryOf("deal"), lead: queryOf("lead") };
30
+ const PIPELINE_QUERY = {
31
+ entity: "pipeline",
32
+ backend: "native",
33
+ fields: [termField("kind", "enum", "kind:lead", { values: DEAL_KINDS }), termField("name", "kw", "name:Sales")],
34
+ };
35
+ /**
36
+ * Each CRM copy's `writes_with`: the CLI and profile that change it on its server. The profiles are read once per
37
+ * command. A row lists only the profiles on its own account, and these lists show only the group's rows, so no
38
+ * profile outside the group is ever named; a list that shows outside rows passes cli-core's `allowed` again.
39
+ */
40
+ const withWriter = async (store) => {
41
+ const profilesFor = storedProfilesFor(await store.accounts.profiles());
42
+ return (item) => ({
43
+ ...item,
44
+ writesWith: writesWithOf(item.account, profilesFor),
45
+ });
46
+ };
47
+ export const listDeals = async (store, env, kind, words, limit) => {
48
+ const command = `${kind}s list`;
49
+ const terms = queryTerms(words, QUERIES[kind], command);
50
+ const filter = {
51
+ kind,
52
+ ...(terms.has("project") ? { project: await canonicalProject(store, terms.get("project")) } : {}),
53
+ ...(terms.has("status") ? { status: terms.get("status") } : {}),
54
+ ...(terms.has("stage") ? { stage: terms.get("stage") } : {}),
55
+ ...(terms.has("pipeline") ? { pipeline: terms.get("pipeline") } : {}),
56
+ ...(terms.has("organization") ? { organization: terms.get("organization") } : {}),
57
+ };
58
+ const scope = await groupScopeOf(store, env);
59
+ const writer = await withWriter(store);
60
+ return pageOf(command, limit, (most) => seenPage(store, most, (limit, offset) => store.deals.list({ ...filter, ...(scope === undefined ? {} : { accounts: scope.accounts }), limit, offset })), { shape: (rows) => rows.map(writer) });
61
+ };
62
+ const BASE_STAGE = /^stage:\d+$/;
63
+ /**
64
+ * The stage name `deals move` writes: a `stage:<id>` is a stage of the row's pipeline, or a base stage, which cli-core
65
+ * resolves to the one stage of that pipeline mapped onto it. A CRM's copy moves on its CRM, or the next sync undoes it.
66
+ */
67
+ const stageToMove = async (store, ref, stage) => {
68
+ if (!BASE_STAGE.test(stage.trim()))
69
+ return stage;
70
+ const row = await readableDeal(store, ref);
71
+ if (row.account !== null) {
72
+ const writesWith = writesWithOf(row.account, storedProfilesFor(await store.accounts.profiles()));
73
+ throw new CliError("validation_error", `${ref} is a copy from ${row.account.provider}:${row.account.account}; move it there with ` +
74
+ `${writesWith?.tool ?? "its CRM's CLI"} ${row.kind}s move ${ref} ${stage.trim()}`, { reason: "stage.crm-copy", writes_with: writesWith });
75
+ }
76
+ return (await store.baseStages.resolve(ref, stage.trim())).stage.name;
77
+ };
78
+ const roleOf = (role) => {
79
+ const value = role ?? "contact";
80
+ if (!DEAL_ROLES.includes(value))
81
+ throw new CliError("validation_error", `--role is one of ${DEAL_ROLES.join(", ")}`, { param: "--role" });
82
+ return value;
83
+ };
84
+ const referenceOf = (kind, value) => /^\d+$/.test(value.trim()) ? `${kind}:${value.trim()}` : value.trim();
85
+ /** `Sales/Quote` or `pipeline:3/Quote` names the pipeline too; a bare `Quote` is found in the only one that has it. */
86
+ const stageOf = (stage) => {
87
+ if (stage === undefined)
88
+ return {};
89
+ const at = stage.lastIndexOf("/");
90
+ return at <= 0 ? { stage } : { pipeline: stage.slice(0, at), stage: stage.slice(at + 1) };
91
+ };
92
+ const WHAT = {
93
+ deal: { one: "deal", hope: "what you hope to sell, such as 'Site for the clinic'" },
94
+ lead: { one: "lead", hope: "who or what came in, such as 'Call from the site'" },
95
+ };
96
+ const itemCommands = (program, kind, { run, print }, env) => {
97
+ const { one, hope } = WHAT[kind];
98
+ const group = program
99
+ .command(`${kind}s`)
100
+ .description(kind === "deal"
101
+ ? "deals you hope to win: the client, the expected amount, the stage and whether it was won or lost"
102
+ : "leads: first contacts in a lead pipeline, before they are deals")
103
+ .summary(kind === "deal" ? "deals in your pipelines, open, won or lost" : "leads in your lead pipelines");
104
+ withQuery(json(annotate(group.command("list"), { effects: LOCAL_READ })).description(`${one}s, newest first; status:open is what is still in play`), QUERIES[kind])
105
+ .summary(`${one}s, newest first`)
106
+ .option("--limit <n>", `most ${one}s, up to 500`, positive, 100)
107
+ .action((words, { json, limit }) => run(json, (store) => listDeals(store, env, kind, words, limit)));
108
+ json(annotate(group.command("show"), { effects: LOCAL_READ, output: { entity: kind } }))
109
+ .description(`one ${one} with its pipeline, stage, status, amount, the people on it and what it was read from`)
110
+ .summary(`one ${one} with its stage, status, amount and people`)
111
+ .argument("<ref>", `${kind}:<id>`)
112
+ .action((ref, options, command) => run(options.json, async (store) => itemAnswer(await withSources(command, store, await readableDeal(store, ref)))));
113
+ json(annotate(group.command("context"), { effects: LOCAL_READ, output: { entity: "deal_context" } }))
114
+ .description(`one ${one} whole: its stages, client, people with their roles and standing, owner, project, invoices and ` +
115
+ `payments as stored, its people's messages, mail and meetings in its lifetime (\`proposed\`: they share ` +
116
+ "people, nothing links them), open tasks and `coverage`. A stage named Won is not a payment")
117
+ .summary(`one ${one}: stages, people, project, money, messages and tasks`)
118
+ .argument("<ref>", `${kind}:<id>`)
119
+ .option("--brief", "the compact form for a model's context: names, roles, totals and counts")
120
+ .option("--limit <n>", "most items in each section", positive, 20)
121
+ .action(async (ref, options, command) => {
122
+ const { answer, notes } = await withStore(env, async (store) => {
123
+ const scope = await groupScopeOf(store, env);
124
+ const answer = await lockedCoverage(store, env, await dealContext(store, ref, {
125
+ limit: options.limit,
126
+ ...(scope === undefined ? {} : { accounts: scope.accounts }),
127
+ deniedKinds: deniedCrmKinds(command, env),
128
+ viewing: await crmViewingAll(store),
129
+ }));
130
+ return { answer, notes: crmNotes(store) };
131
+ });
132
+ if (answer.deal.kind !== kind)
133
+ throw new CliError("validation_error", `${ref} is a ${answer.deal.kind} — wcat ${answer.deal.kind}s context`);
134
+ print(options.json, shortenedBy(notes, itemAnswer(options.brief ? dealBrief(answer) : answer)), options.brief ? dealBriefText(dealBrief(answer)) : dealText(answer));
135
+ });
136
+ json(annotate(group.command("update"), { effects: LOCAL_WRITE, output: { entity: kind } }))
137
+ .description(`set the project a ${one} belongs to; a CRM's copy takes it too, and the next sync keeps it. An empty value ` +
138
+ "clears it")
139
+ .summary(`set the project a ${one} belongs to`)
140
+ .argument("<ref>", `${kind}:<id>`)
141
+ .requiredOption("--project <project>", "the project: its key or project:<id>")
142
+ .action(async (ref, options) => {
143
+ const by = authorOf(env);
144
+ await run(options.json, async (store) => itemAnswer(await store.deals.setProject((await readableDeal(store, ref)).ref, {
145
+ project: options.project === "" ? null : await canonicalProject(store, options.project),
146
+ by,
147
+ })));
148
+ });
149
+ json(annotate(group.command("add"), { effects: LOCAL_WRITE, output: { entity: kind }, literal_after_dashes: true })
150
+ .option("--organization <organization>", "the client: organization:<id>")
151
+ .option("--person <uid>", `a person on the ${one}: person:<id>; repeat for another, up to 20`, collect)
152
+ .option("--role <role>", `what those people are on it: ${DEAL_ROLES.join(", ")}; contact by default`)
153
+ .option("--due <time>", "the day you expect it to close, such as 2026-12-01")
154
+ .option("--project <project>", "the project it belongs to: its key or project:<id>")
155
+ .option("--reason <text>", "why an agent records it, kept with it")
156
+ .option("--evidence <ref...>", "what shows it, up to 8: msg:, note:, document: or another reference"))
157
+ .description(`record a ${one} in a stage; it is written at once, whoever runs it`)
158
+ .summary(`record a ${one} in a stage`)
159
+ .argument("<title>", hope)
160
+ .argument(kind === "deal" ? "<stage>" : "[stage]", kind === "deal"
161
+ ? "the stage it is in; Sales/Quote or pipeline:3/Quote names the pipeline when two have that stage"
162
+ : "the stage it is in; the first stage of the only lead pipeline when left out")
163
+ .argument("[amount]", "the expected amount, a decimal such as 500000.00")
164
+ .argument("[currency]", "ISO 4217, such as RUB; given with the amount")
165
+ .action(async (title, stage, amount, currency, options) => {
166
+ const by = authorOf(env);
167
+ const role = roleOf(options.role);
168
+ await run(options.json, async (store) => {
169
+ const closeDate = dayOf(options.due);
170
+ return itemAnswer(await store.deals.add({
171
+ by,
172
+ kind,
173
+ title,
174
+ ...stageOf(stage),
175
+ ...(options.organization === undefined
176
+ ? {}
177
+ : { organization: referenceOf("organization", options.organization) }),
178
+ ...(options.person === undefined
179
+ ? {}
180
+ : { people: options.person.map((person) => ({ person: referenceOf("person", person), role })) }),
181
+ ...(amount === undefined ? {} : { amount }),
182
+ ...(currency === undefined ? {} : { currency }),
183
+ ...(closeDate === undefined ? {} : { closeDate }),
184
+ ...(options.project === undefined ? {} : { project: await canonicalProject(store, options.project) }),
185
+ ...(options.reason === undefined ? {} : { reason: options.reason }),
186
+ ...(options.evidence === undefined ? {} : { evidence: options.evidence }),
187
+ }));
188
+ });
189
+ });
190
+ json(annotate(group.command("move"), { effects: LOCAL_WRITE, output: { entity: kind } }))
191
+ .description(`move a ${one} to another stage of its pipeline; a won or lost stage closes it, an open one reopens it`)
192
+ .summary(`move a ${one} to another stage`)
193
+ .argument("<ref>", `${kind}:<id>`)
194
+ .argument("<stage>", `a stage of the ${one}'s pipeline by its name or stage:<id>; or a base stage's stage:<id>, which moves it to ` +
195
+ "the one stage of its pipeline mapped there, and refuses several (with the candidates) or none")
196
+ .action(async (ref, stage, options) => {
197
+ const by = authorOf(env);
198
+ await run(options.json, async (store) => itemAnswer(await store.deals.move((await readableDeal(store, ref)).ref, {
199
+ stage: await stageToMove(store, ref, stage),
200
+ by,
201
+ })));
202
+ });
203
+ json(annotate(group.command("close"), { effects: LOCAL_WRITE, output: { entity: kind } })
204
+ .option("--occurred-time <time>", "the day it closed, such as 2026-11-20; today when left out")
205
+ .option("--reason <text>", "why it was won or lost, kept with it"))
206
+ .description(`close a ${one} as won or lost; it moves to its pipeline's won or lost stage when there is one`)
207
+ .summary(`close a ${one} as won or lost`)
208
+ .argument("<ref>", `${kind}:<id>`)
209
+ .argument("<outcome>", "won or lost")
210
+ .action(async (ref, outcome, options) => {
211
+ if (outcome !== "won" && outcome !== "lost")
212
+ throw new CliError("validation_error", `a ${one} closes as won or lost`, { param: "outcome" });
213
+ const by = authorOf(env);
214
+ const date = dayOf(options.occurredTime);
215
+ await run(options.json, async (store) => itemAnswer(await store.deals.close((await readableDeal(store, ref)).ref, {
216
+ status: outcome,
217
+ by,
218
+ ...(date === undefined ? {} : { date }),
219
+ ...(options.reason === undefined ? {} : { reason: options.reason }),
220
+ })));
221
+ });
222
+ };
223
+ const percent = (share) => (share === null ? "" : `, ${Math.round(share * 100)}% go on`);
224
+ /** "Sales (deal), pipeline:2" then a line per stage: open now, reached, and the share that goes on. */
225
+ const funnelText = (report, since) => [
226
+ `${report.name} (${report.kind}), ${report.ref}${since === undefined ? "" : `, made since ${since}`}`,
227
+ ...report.stages.map((stage) => ` ${stage.position}. ${stage.name}${stage.outcome === "open" ? "" : ` [${stage.outcome}]`}: ` +
228
+ `${stage.open} open, ${stage.reached} reached${percent(stage.conversion)}`),
229
+ ` ${report.totals.items} in all: ${report.totals.open} open, ${report.totals.won} won, ${report.totals.lost} lost` +
230
+ (report.totals.winRate === null ? "" : `, win rate ${Math.round(report.totals.winRate * 100)}%`),
231
+ ].join("\n");
232
+ const inScope = (scope) => (pipeline) => scope === undefined || pipeline.account === null || scope.has(pipeline.account);
233
+ /** In a group a name means the group's pipeline: one outside it is never found, and never makes the name ambiguous. */
234
+ const pipelineInGroup = async (store, env, reference) => {
235
+ const scope = await groupScopeOf(store, env);
236
+ if (scope === undefined || /^pipeline:\d+$/.test(reference.trim()))
237
+ return reference;
238
+ const name = reference.trim().toLocaleLowerCase();
239
+ const named = (await store.deals.pipelines()).filter((one) => one.name.toLocaleLowerCase() === name && inScope(scope)(one));
240
+ if (named.length === 1)
241
+ return named[0].ref;
242
+ if (named.length === 0)
243
+ throw new CliError("not_found", `no pipeline named ${reference.trim()} in group:${scope.run.name}`, {
244
+ reason: "pipeline.not-found",
245
+ });
246
+ throw new CliError("validation_error", `more than one pipeline in group:${scope.run.name} is named ${reference.trim()}: ` +
247
+ `${named.map((one) => one.ref).join(", ")}; name one by its reference`, { reason: "pipeline.ambiguous" });
248
+ };
249
+ /** `wcat deals`, `wcat leads` and `wcat pipelines`: sales pipelines and what is in them. */
250
+ export const dealCommands = (program, streams, env) => {
251
+ const { run, print } = answers(program, streams, env);
252
+ const pipelines = program
253
+ .command("pipelines")
254
+ .description("sales pipelines: the stages a deal or a lead goes through, in order, and how many get through each")
255
+ .summary("sales pipelines, their stages and conversion");
256
+ withQuery(json(annotate(pipelines.command("list"), { effects: LOCAL_READ })).description("every pipeline with its stages in order and how many open deals or leads stand in each"), PIPELINE_QUERY)
257
+ .summary("every pipeline with its stages")
258
+ .action((words, options) => run(options.json, async (store) => {
259
+ const terms = queryTerms(words, PIPELINE_QUERY, "pipelines list");
260
+ const name = terms.get("name")?.toLocaleLowerCase();
261
+ const kind = terms.get("kind");
262
+ const scope = await groupScopeOf(store, env);
263
+ const all = await readablePipelines(store, (await store.deals.pipelines(kind === undefined ? {} : { kind })).filter(inScope(scope)), kind);
264
+ const writer = await withWriter(store);
265
+ return wholeList("pipelines list", (name === undefined ? all : all.filter((one) => one.name.toLocaleLowerCase() === name)).map(writer));
266
+ }));
267
+ json(annotate(pipelines.command("show"), { effects: LOCAL_READ, output: { entity: "pipeline" } }).option("--since-time <time>", "count only deals or leads made since this day, such as 2026-09-01"))
268
+ .description("one pipeline's funnel: per stage the open deals or leads in it, how many reached it, and the share that " +
269
+ "went on to the next stage; then won, lost and the win rate")
270
+ .summary("one pipeline's stages with counts and conversion")
271
+ .argument("<pipeline>", "pipeline:<id>, or a name only one pipeline has")
272
+ .action(async (pipeline, options, command) => {
273
+ const since = dayOf(options.sinceTime);
274
+ const { report, notes } = await withStore(env, async (store) => {
275
+ const reference = await pipelineInGroup(store, env, pipeline);
276
+ const read = await readablePipeline(store, reference, since === undefined ? {} : { since });
277
+ return { report: await withSources(command, store, read), notes: crmNotes(store) };
278
+ });
279
+ print(options.json, shortenedBy(notes, itemAnswer(report)), funnelText(report, since));
280
+ });
281
+ json(annotate(pipelines.command("add"), { effects: LOCAL_WRITE, literal_after_dashes: true }).option("--kind <kind>", "what it holds: deal or lead; deal by default"))
282
+ .description("make a pipeline with its stages in order; a stage named won or lost (any letter case) ends a deal or lead " +
283
+ "as that")
284
+ .summary("make a pipeline with its stages")
285
+ .argument("<name>", "the pipeline's name, such as Sales")
286
+ .argument("<stage...>", "its stages in order, such as Call Quote Contract won lost")
287
+ .action(async (name, stages, options) => {
288
+ const kind = options.kind ?? "deal";
289
+ if (!DEAL_KINDS.includes(kind))
290
+ throw new CliError("validation_error", "--kind is deal or lead", { param: "--kind" });
291
+ const by = authorOf(env);
292
+ await run(options.json, async (store) => itemAnswer(await store.deals.addPipeline({
293
+ name,
294
+ kind: kind,
295
+ stages: stages.map((stage) => {
296
+ const word = stage.trim().toLocaleLowerCase();
297
+ return word === "won" || word === "lost" ? { name: stage, outcome: word } : stage;
298
+ }),
299
+ by,
300
+ })));
301
+ });
302
+ itemCommands(program, "deal", { run, print }, env);
303
+ itemCommands(program, "lead", { run, print }, env);
304
+ const stages = baseStagesCommand(APP, {
305
+ env: () => env,
306
+ open: () => openMemoStore(env),
307
+ output: (body, command) => print(command.opts().json, body),
308
+ accounts: async (store) => (await groupScopeOf(store, env))?.accounts,
309
+ });
310
+ // wcat has no global --json; cli-core's builder leaves it to the app.
311
+ for (const leaf of stages.commands)
312
+ json(leaf);
313
+ program.addCommand(stages);
314
+ };
315
+ /** Open deals `projects status` shows, soonest expected close first; more than this is a count. */
316
+ const STATUS_DEALS = 5;
317
+ /** The open deals read per project, cli-core's own list default. */
318
+ const OPEN_DEALS_READ = 100;
319
+ /** The open deals of these projects. */
320
+ export const openDealsOf = async (store, projects) => {
321
+ const found = (await Promise.all(projects.map(async (project) => (await seenPage(store, OPEN_DEALS_READ, (limit, offset) => store.deals.list({ project, status: "open", limit, offset }))).items))).flat();
322
+ const sorted = found.sort((a, b) => (a.closeDate ?? "9999").localeCompare(b.closeDate ?? "9999") || b.createdAt.localeCompare(a.createdAt));
323
+ return {
324
+ deals: sorted.slice(0, STATUS_DEALS).map((deal) => ({
325
+ ref: deal.ref,
326
+ title: deal.title,
327
+ stage: deal.stage,
328
+ amount: deal.amount,
329
+ currency: deal.currency,
330
+ close_date: deal.closeDate,
331
+ })),
332
+ more: Math.max(sorted.length - STATUS_DEALS, 0),
333
+ };
334
+ };
335
+ export const dealsText = ({ deals, more }) => deals.length === 0
336
+ ? []
337
+ : [
338
+ "open deals:",
339
+ ...deals.map((deal) => {
340
+ const money = deal.amount === null ? "" : `, ${deal.amount} ${deal.currency}`;
341
+ const due = deal.close_date === null ? "" : `, close ${deal.close_date}`;
342
+ return ` ${deal.ref} ${deal.title} · ${deal.stage}${money}${due}`;
343
+ }),
344
+ ...(more > 0 ? [` +${more} more: wcat deals list status:open`] : []),
345
+ ];
346
+ //# sourceMappingURL=deals-command.js.map
@@ -0,0 +1,129 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { FINANCE_REVIEWS, INVOICE_DIRECTIONS, INVOICE_STATUSES, MONEY_DIRECTIONS, minorUnits, moneyOf, queryTerms, termField, } from "@wirecat/cli-core";
3
+ import { pageOf } from "../page.js";
4
+ import { canonicalProject } from "../vocabulary/project.js";
5
+ export const INVOICE_QUERY = {
6
+ entity: "invoice",
7
+ backend: "native",
8
+ fields: [
9
+ termField("project", "kw", "project:PMED"),
10
+ termField("direction", "enum", "direction:receivable", { values: INVOICE_DIRECTIONS }),
11
+ termField("status", "enum", "status:partly_paid", { values: INVOICE_STATUSES }),
12
+ termField("review", "enum", "review:proposed", { values: FINANCE_REVIEWS }),
13
+ termField("counterparty", "ref", 'counterparty:"organization:3"'),
14
+ termField("number", "kw", "number:FACT-2026-00012"),
15
+ termField("open", "bool", "open:true"),
16
+ ],
17
+ };
18
+ export const PAYMENT_QUERY = {
19
+ entity: "payment",
20
+ backend: "native",
21
+ fields: [
22
+ termField("project", "kw", "project:PMED"),
23
+ termField("direction", "enum", "direction:in", { values: MONEY_DIRECTIONS }),
24
+ termField("review", "enum", "review:proposed", { values: FINANCE_REVIEWS }),
25
+ termField("party", "ref", 'party:"organization:3"'),
26
+ ],
27
+ };
28
+ const projectTerm = async (store, project) => project === undefined ? {} : { project: await canonicalProject(store, project) };
29
+ const reviewTerm = (review) => review === undefined ? {} : { review: review };
30
+ export const listInvoices = async (store, words, limit) => {
31
+ const terms = queryTerms(words, INVOICE_QUERY, "invoices list");
32
+ const filter = {
33
+ ...(await projectTerm(store, terms.get("project"))),
34
+ ...reviewTerm(terms.get("review")),
35
+ ...(terms.has("direction") ? { direction: terms.get("direction") } : {}),
36
+ ...(terms.has("status") ? { status: terms.get("status") } : {}),
37
+ ...(terms.has("counterparty") ? { counterparty: terms.get("counterparty") } : {}),
38
+ ...(terms.has("number") ? { number: terms.get("number") } : {}),
39
+ ...(terms.has("open") ? { open: terms.get("open") === "true" } : {}),
40
+ };
41
+ return pageOf("invoices list", limit, (most) => store.finance.invoices({ ...filter, limit: most }));
42
+ };
43
+ export const listPayments = async (store, words, limit) => {
44
+ const terms = queryTerms(words, PAYMENT_QUERY, "payments list");
45
+ const filter = {
46
+ ...(await projectTerm(store, terms.get("project"))),
47
+ ...reviewTerm(terms.get("review")),
48
+ ...(terms.has("direction") ? { direction: terms.get("direction") } : {}),
49
+ ...(terms.has("party") ? { party: terms.get("party") } : {}),
50
+ };
51
+ return pageOf("payments list", limit, (most) => store.finance.payments({ ...filter, limit: most }));
52
+ };
53
+ /** `--person 7`, `--person person:7` or `--organization organization:3`: the one party a row names. */
54
+ export const partyOf = ({ person, organization }, required) => {
55
+ if (person !== undefined && organization !== undefined)
56
+ throw new CliError("validation_error", "name one party: --person or --organization", { param: "--organization" });
57
+ const [kind, value] = person !== undefined ? ["person", person] : ["organization", organization];
58
+ if (value === undefined) {
59
+ if (!required)
60
+ return undefined;
61
+ throw new CliError("validation_error", "name the counterparty: --person or --organization", {
62
+ param: "--organization",
63
+ });
64
+ }
65
+ const trimmed = value.trim();
66
+ return /^\d+$/.test(trimmed) ? `${kind}:${trimmed}` : trimmed;
67
+ };
68
+ export const today = () => new Date().toLocaleDateString("sv-SE");
69
+ /** `2026-11-01` from `2026-11-01` or `2026-11-01T10:00:00+03:00`: the store keeps a payment's day. */
70
+ export const dayOf = (time) => time?.trim().slice(0, 10);
71
+ const DIRECTION_OF_PAYMENT = { in: "receivable", out: "payable" };
72
+ /**
73
+ * What the project's confirmed books say, per direction and currency: billed, paid and still owed on its invoices,
74
+ * and the payments behind them. Nothing is converted, and a proposed row counts for nothing until the owner confirms it.
75
+ */
76
+ export const financeOf = async (store, projects) => {
77
+ const totals = new Map();
78
+ const totalOf = (direction, currency) => {
79
+ const key = `${direction} ${currency}`;
80
+ const found = totals.get(key);
81
+ if (found)
82
+ return found;
83
+ const made = { direction, currency, billed: 0, paid: 0, owed: 0, unallocated: 0, invoices: [], payments: [] };
84
+ totals.set(key, made);
85
+ return made;
86
+ };
87
+ for (const project of projects) {
88
+ for (const invoice of (await store.finance.invoices({ project, review: "confirmed", limit: 500 })).items) {
89
+ if (invoice.status === "void" || invoice.status === "draft")
90
+ continue;
91
+ const total = totalOf(invoice.direction, invoice.currency);
92
+ total.billed += minorUnits(invoice.total, invoice.currency);
93
+ total.paid += minorUnits(invoice.paid, invoice.currency);
94
+ total.owed += minorUnits(invoice.open, invoice.currency);
95
+ total.invoices.push(invoice.ref);
96
+ }
97
+ for (const payment of (await store.finance.payments({ project, review: "confirmed", limit: 500 })).items) {
98
+ const total = totalOf(DIRECTION_OF_PAYMENT[payment.direction], payment.currency);
99
+ total.unallocated += minorUnits(payment.unallocated, payment.currency);
100
+ total.payments.push(payment.ref);
101
+ }
102
+ }
103
+ return [...totals.values()]
104
+ .sort((a, b) => a.direction.localeCompare(b.direction) || a.currency.localeCompare(b.currency))
105
+ .map((total) => ({
106
+ direction: total.direction,
107
+ currency: total.currency,
108
+ billed: moneyOf(total.billed, total.currency).amount,
109
+ paid: moneyOf(total.paid, total.currency).amount,
110
+ owed: moneyOf(total.owed, total.currency).amount,
111
+ unallocated: moneyOf(total.unallocated, total.currency).amount,
112
+ invoices: total.invoices,
113
+ payments: total.payments,
114
+ }));
115
+ };
116
+ const WHO = { receivable: "billed by you", payable: "billed to you" };
117
+ export const financeText = (block) => block.length === 0
118
+ ? []
119
+ : [
120
+ "books (confirmed invoices and payments):",
121
+ ...block.map((one) => {
122
+ const refs = [...one.invoices, ...one.payments];
123
+ const shown = refs.slice(0, 6).join(" ") + (refs.length > 6 ? ` +${refs.length - 6}` : "");
124
+ const loose = one.unallocated === moneyOf(0, one.currency).amount ? "" : `, ${one.unallocated} not matched`;
125
+ return (` ${WHO[one.direction]} ${one.currency}: billed ${one.billed}, paid ${one.paid}, owed ${one.owed}` +
126
+ `${loose} · ${shown}`);
127
+ }),
128
+ ];
129
+ //# sourceMappingURL=finance.js.map
@@ -0,0 +1,70 @@
1
+ import { annotate } from "@wirecat/cli-base/commands";
2
+ import { LOCAL_WRITE } from "@wirecat/cli-core";
3
+ import { itemAnswer } from "../answer.js";
4
+ import { byOption, whoRuns } from "../author.js";
5
+ import { positive } from "../options.js";
6
+ import { given, json, needed } from "./written.js";
7
+ /** The two parents with lines; each keeps its own store calls and the words its help names it by. */
8
+ const LINE_PARENTS = {
9
+ order: {
10
+ has: "an order that has a currency (orders add with an amount)",
11
+ shown: "orders show",
12
+ add: (store, ref, line) => store.orders.addLine(ref, line),
13
+ remove: (store, ref, input) => store.orders.removeLine(ref, input),
14
+ },
15
+ invoice: {
16
+ has: "an invoice that is not void; the total never falls below what confirmed payments settled",
17
+ shown: "invoices show",
18
+ add: (store, ref, line) => store.finance.addInvoiceLine(ref, line),
19
+ remove: (store, ref, input) => store.finance.removeInvoiceLine(ref, input),
20
+ },
21
+ };
22
+ /** `wcat orders lines` and `wcat invoices lines`: what it is made of; its total is then their sum. */
23
+ export const lineCommands = (parent, kind, run, env) => {
24
+ const { has, shown, add, remove } = LINE_PARENTS[kind];
25
+ const one = kind === "order" ? "an order" : "an invoice";
26
+ const who = `you change any ${kind}'s lines; an agent only those of ${one} it proposed that is still proposed`;
27
+ const lines = parent
28
+ .command("lines")
29
+ .description(`the lines of ${one}, each a quantity at a price; its total is their sum. ${who}`)
30
+ .summary(`the lines of ${one}`);
31
+ const asker = (ref) => `change ${ref}'s lines as yours?`;
32
+ json(byOption(annotate(lines.command("add"), {
33
+ effects: LOCAL_WRITE,
34
+ output: { entity: kind },
35
+ literal_after_dashes: true,
36
+ })
37
+ .option("--product <product>", "the product or service it is: its name and price are copied onto the line")
38
+ .option("--amount <decimal>", "the price of one, such as 10000.00; the product's when left out with --product")))
39
+ .description(`add a line at the end of ${has}: quantity × price, and the total becomes the sum of the lines. With ` +
40
+ `--product its name and price are copied, so a later price change leaves the line as it is, and --amount ` +
41
+ `sets another price; without --product, --amount is needed. ${who}`)
42
+ .summary(`add a line to ${one}`)
43
+ .argument(`<${kind}>`, `${kind}:<id>`)
44
+ .argument("<quantity>", "how many, a decimal such as 12 or 1.5")
45
+ .argument("[description...]", "what the line is, in a few words; the product's name when left out")
46
+ .action(async (ref, quantity, words, options, command) => {
47
+ if (options.product === undefined)
48
+ needed(options.amount, "--amount", "the price of one, or --product");
49
+ const by = await whoRuns(command, env, { asOwner: options.asOwner, question: asker(ref) });
50
+ await run(options.json, async (store) => itemAnswer(await add(store, ref, {
51
+ by,
52
+ quantity,
53
+ ...given({
54
+ unitPrice: options.amount,
55
+ description: words.length > 0 ? words.join(" ") : undefined,
56
+ product: options.product,
57
+ }),
58
+ })));
59
+ });
60
+ json(byOption(annotate(lines.command("remove"), { effects: LOCAL_WRITE, output: { entity: kind } })))
61
+ .description(`take a line off ${one}; the others keep their positions, and the last line stays. ${who}`)
62
+ .summary(`take a line off ${one}`)
63
+ .argument(`<${kind}>`, `${kind}:<id>`)
64
+ .argument("<position>", `the line's position, from 1, as ${shown} lists it`, positive)
65
+ .action(async (ref, position, options, command) => {
66
+ const by = await whoRuns(command, env, { asOwner: options.asOwner, question: asker(ref) });
67
+ await run(options.json, async (store) => itemAnswer(await remove(store, ref, { position, by })));
68
+ });
69
+ };
70
+ //# sourceMappingURL=lines-command.js.map
@@ -0,0 +1,94 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { annotate } from "@wirecat/cli-base/commands";
3
+ import { FINANCE_REVIEWS, LOCAL_READ, LOCAL_WRITE, ORDER_PURPOSES, ORDER_STATUSES, queryTerms, termField, withQuery, } from "@wirecat/cli-core";
4
+ import { answers, itemAnswer } from "../answer.js";
5
+ import { byOption, whoRuns } from "../author.js";
6
+ import { positive } from "../options.js";
7
+ import { pageOf } from "../page.js";
8
+ import { withSources } from "../records/sources.js";
9
+ import { canonicalProject } from "../vocabulary/project.js";
10
+ import { dayOf, partyOf } from "./finance.js";
11
+ import { lineCommands } from "./lines-command.js";
12
+ import { json } from "./written.js";
13
+ export const ORDER_QUERY = {
14
+ entity: "order",
15
+ backend: "native",
16
+ fields: [
17
+ termField("project", "kw", "project:PMED"),
18
+ termField("status", "enum", "status:shipped", { values: ORDER_STATUSES }),
19
+ termField("purpose", "enum", "purpose:personal", { values: ORDER_PURPOSES }),
20
+ termField("review", "enum", "review:proposed", { values: FINANCE_REVIEWS }),
21
+ termField("customer", "ref", 'customer:"organization:3"'),
22
+ termField("supplier", "kw", 'supplier:"Shop One"'),
23
+ termField("number", "kw", "number:A-1042"),
24
+ ],
25
+ };
26
+ export const listOrders = async (store, words, limit) => {
27
+ const terms = queryTerms(words, ORDER_QUERY, "orders list");
28
+ const filter = {
29
+ ...(terms.has("project") ? { project: await canonicalProject(store, terms.get("project")) } : {}),
30
+ ...(terms.has("status") ? { status: terms.get("status") } : {}),
31
+ ...(terms.has("purpose") ? { purpose: terms.get("purpose") } : {}),
32
+ ...(terms.has("review") ? { review: terms.get("review") } : {}),
33
+ ...(terms.has("customer") ? { customer: terms.get("customer") } : {}),
34
+ ...(terms.has("supplier") ? { supplierName: terms.get("supplier") } : {}),
35
+ ...(terms.has("number") ? { number: terms.get("number") } : {}),
36
+ };
37
+ return pageOf("orders list", limit, (most) => store.orders.list({ ...filter, limit: most }));
38
+ };
39
+ const oneOf = (value, allowed, flag) => {
40
+ if (value === undefined || !allowed.includes(value))
41
+ throw new CliError("validation_error", `${flag} is one of ${allowed.join(", ")}`, { param: flag });
42
+ return value;
43
+ };
44
+ /** `wcat orders`: what the owner, his business or a client ordered, and how far delivery got. */
45
+ export const orderCommands = (program, streams, env) => {
46
+ const { run } = answers(program, streams, env);
47
+ const orders = program
48
+ .command("orders")
49
+ .description("orders you placed or took, for whom, from which shop, and how far delivery got")
50
+ .summary("orders you placed or took, and how far delivery got");
51
+ withQuery(json(annotate(orders.command("list"), { effects: LOCAL_READ })).description("orders, newest first; review:proposed is what waits for you"), ORDER_QUERY)
52
+ .option("--limit <n>", "most orders, up to 500", positive, 100)
53
+ .action((words, { json, limit }) => run(json, (store) => listOrders(store, words, limit)));
54
+ json(annotate(orders.command("show"), { effects: LOCAL_READ, output: { entity: "order" } }))
55
+ .description("one order with its customer, shop, amount, status and the mail it was read from")
56
+ .argument("<ref>", "order:<id>")
57
+ .action((ref, options, command) => run(options.json, async (store) => itemAnswer(await withSources(command, store, await store.orders.get(ref)))));
58
+ json(byOption(annotate(orders.command("add"), { effects: LOCAL_WRITE, output: { entity: "order" }, literal_after_dashes: true })
59
+ .option("--kind <kind>", `why it was ordered: ${ORDER_PURPOSES.join(", ")}`)
60
+ .option("--person <uid>", "whom it is for, when not you: person:<id>")
61
+ .option("--organization <organization>", "whom it is for, when not you: organization:<id>")
62
+ .option("--title <title>", "the shop's order number")
63
+ .option("--occurred-time <time>", "the day it was ordered, such as 2026-11-01")
64
+ .option("--project <project>", "the project it belongs to: its key or project:<id>")
65
+ .option("--reason <text>", "why an agent proposes it, for the owner who decides")
66
+ .option("--evidence <ref...>", "what shows it, up to 8: msg:, note:, document: or another reference")))
67
+ .description("record a placed order; yours is confirmed at once, an agent's waits as proposed for you in wcat review")
68
+ .summary("record an order; an agent's waits for your review")
69
+ .argument("<shop>", "the shop or supplier, as its mail names it")
70
+ .argument("[amount]", "the order's amount, a decimal such as 2499.00")
71
+ .argument("[currency]", "ISO 4217, such as RUB; given with the amount")
72
+ .action(async (shop, amount, currency, options, command) => {
73
+ const by = await whoRuns(command, env, { asOwner: options.asOwner, question: "record this order as yours?" });
74
+ await run(options.json, async (store) => {
75
+ const customer = partyOf(options, false);
76
+ const orderDate = dayOf(options.occurredTime);
77
+ return itemAnswer(await store.orders.add({
78
+ by,
79
+ purpose: oneOf(options.kind, ORDER_PURPOSES, "--kind"),
80
+ supplierName: shop,
81
+ ...(customer === undefined ? {} : { customer }),
82
+ ...(options.title === undefined ? {} : { number: options.title }),
83
+ ...(amount === undefined ? {} : { total: amount }),
84
+ ...(currency === undefined ? {} : { currency }),
85
+ ...(orderDate === undefined ? {} : { orderDate }),
86
+ ...(options.project === undefined ? {} : { project: await canonicalProject(store, options.project) }),
87
+ ...(by !== "owner" && options.reason !== undefined ? { reason: options.reason } : {}),
88
+ ...(options.evidence === undefined ? {} : { evidence: options.evidence }),
89
+ }));
90
+ });
91
+ });
92
+ lineCommands(orders, "order", run, env);
93
+ };
94
+ //# sourceMappingURL=orders-command.js.map