@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,100 @@
1
+ import { annotate } from "@wirecat/cli-base/commands";
2
+ import { FACT_TYPES, LOCAL_READ, LOCAL_WRITE, MEMORY_SCOPES, withQuery, } from "@wirecat/cli-core";
3
+ import { answers, itemAnswer } from "../answer.js";
4
+ import { byOption, deciderOf, reasonOption, whoRuns } from "../author.js";
5
+ import { FORGET_HELP } from "../memories/command.js";
6
+ import { challengeCommand, explainQuote, quotedEvidence, quoteOption } from "../memories/sources.js";
7
+ import { oneOf, positive } from "../options.js";
8
+ import { pageOf } from "../page.js";
9
+ import { decideOne, decisionOf } from "../review/review.js";
10
+ import { sourcesIn, stripped } from "../store/guard.js";
11
+ import { canonicalProject } from "../vocabulary/project.js";
12
+ import { FACT_QUERY, factItem, listFacts } from "./fact.js";
13
+ import { addFact } from "./facts.js";
14
+ export const factsCommand = (program, streams, env) => {
15
+ const { run } = answers(program, streams, env);
16
+ const facts = program.command("facts").description("what happened — said, asked, decided, promised — with evidence");
17
+ quoteOption(byOption(annotate(facts.command("add"), {
18
+ effects: LOCAL_WRITE,
19
+ output: { entity: "fact" },
20
+ literal_after_dashes: true,
21
+ }).description("record a fact; an agent's waits as proposed until you confirm it")))
22
+ .argument("<statement...>", "what happened, in one sentence")
23
+ .requiredOption("--kind <kind>", FACT_TYPES.join(", "), oneOf(FACT_TYPES))
24
+ .option("--evidence <ref...>", "what shows it: msg:, note:, meeting:, person: or another reference")
25
+ .option("--project <project>", "the project it belongs to: its key or project:<id>")
26
+ .option("--subject <ref>", "what it is about, as a reference")
27
+ .option("--occurred-time <time>", "when it happened, as the evidence shows, ISO 8601")
28
+ .option("--scope <scope>", MEMORY_SCOPES.join(" or "), oneOf(MEMORY_SCOPES))
29
+ .option("--supersedes <ref>", "the proposed or accepted fact this one corrects; it stays, marked superseded once this one is accepted")
30
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
31
+ .action(async (words, options, command) => {
32
+ const evidence = options.quote?.length ? quotedEvidence(options.evidence ?? [], options.quote) : options.evidence;
33
+ const by = await whoRuns(command, env, { asOwner: options.asOwner, question: "record this fact as yours?" });
34
+ await run(options.json, async (store) => itemAnswer(factItem(await addFact(store, {
35
+ type: options.kind,
36
+ statement: words.join(" "),
37
+ by,
38
+ ...(evidence === undefined ? {} : { evidence }),
39
+ ...(options.project === undefined ? {} : { project: await canonicalProject(store, options.project) }),
40
+ ...(options.subject === undefined ? {} : { subject: options.subject }),
41
+ ...(options.occurredTime === undefined ? {} : { occurredAt: options.occurredTime }),
42
+ ...(options.scope === undefined ? {} : { scope: options.scope }),
43
+ ...(options.supersedes === undefined ? {} : { supersedes: options.supersedes }),
44
+ }).catch(explainQuote))));
45
+ });
46
+ withQuery(annotate(facts.command("list"), { effects: LOCAL_READ }).description("facts, latest first"), FACT_QUERY)
47
+ .option("--limit <n>", "most facts on a page, up to 500", positive, 100)
48
+ .option("--page <n>", "which page, from 1", positive, 1)
49
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
50
+ .action((words, { json, limit, page }) => run(json, async (store) => stripped(store, env, await listFacts(store, words, limit, page))));
51
+ annotate(facts.command("show"), { effects: LOCAL_READ, output: { entity: "fact" } })
52
+ .description("one fact with its evidence")
53
+ .argument("<ref>", "fact:<id>")
54
+ .option("--sources", "read each piece of evidence back: who, when, a short excerpt, and whether it is gone")
55
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
56
+ .action((ref, options) => run(options.json, async (store) => itemAnswer(await stripped(store, env, {
57
+ ...factItem(await store.facts.get(ref)),
58
+ ...(options.sources ? await sourcesIn(store, env, await store.facts.sources(ref)) : {}),
59
+ }))));
60
+ const decide = (name, description, act) => reasonOption(byOption(annotate(facts.command(name), {
61
+ effects: LOCAL_WRITE,
62
+ ...(name === "remove" ? {} : { output: { entity: "fact" } }),
63
+ }))
64
+ .description(description)
65
+ .argument("<ref>", "fact:<id>")
66
+ .option("--json", "print JSON; --json=id,title keeps only those fields")).action(async (ref, options, command) => {
67
+ await run(options.json, async (store) => {
68
+ // An unknown ref is not_found for anyone, before asking who decides.
69
+ await store.facts.get(ref);
70
+ const by = await deciderOf(command, env, { ...options, question: `${name} ${ref} as you, the owner?` });
71
+ const done = await act(store, ref, by, options.reason);
72
+ return itemAnswer(name === "remove" ? done : factItem(done));
73
+ });
74
+ });
75
+ decide("confirm", "stand behind a fact an agent proposed; a fact it supersedes stops holding. wcat review confirm decides many", async (store, ref, by, why) => {
76
+ await decideOne(store, env, ref, decisionOf(true, by, why));
77
+ return store.facts.get(ref);
78
+ }).summary("stand behind a fact an agent proposed");
79
+ decide("revoke", "take back your approval of an agent's fact; it waits as proposed again. Not for a correction or your own fact", (store, ref, by, why) => store.facts.revoke(ref, by, why)).summary("take back your approval of a fact an agent proposed");
80
+ decide("reverse", "an accepted decision no longer holds, and nothing replaced it", (store, ref, by, why) => store.facts.reverse(ref, by, why));
81
+ decide("reject", "turn down a fact an agent proposed; it stays, marked rejected", async (store, ref, by, why) => {
82
+ await decideOne(store, env, ref, decisionOf(false, by, why));
83
+ return store.facts.get(ref);
84
+ });
85
+ decide("remove", "forget a fact: erase its text, its links to sources and its tags. wcat facts history keeps who removed it, " +
86
+ "when and why, never what it said", (store, ref, by, why) => store.facts.remove(ref, by, why))
87
+ .summary("forget a fact; facts history keeps who removed it and why")
88
+ .addHelpText("after", `\n${FORGET_HELP.replace("use invalidate", "use reject or reverse")}`);
89
+ annotate(facts.command("history"), { effects: LOCAL_READ })
90
+ .summary("the facts removed: who, when and why, never what they said")
91
+ .description("the facts removed, newest first: who removed each, when and why, never what it said")
92
+ .option("--limit <n>", "most removals on a page, up to 500", positive, 100)
93
+ .option("--page <n>", "which page, from 1", positive, 1)
94
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
95
+ .action(({ json, limit, page }) => run(json, async (store) => stripped(store, env, await pageOf("facts history", limit, (most, offset) => store.facts.removed({ limit: most, offset }), {
96
+ page,
97
+ }))));
98
+ challengeCommand(facts, "fact", streams, env);
99
+ };
100
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1,54 @@
1
+ import { FACT_STATUSES, FACT_TYPES, queryTerms, termField, typedQuery, } from "@wirecat/cli-core";
2
+ import { pageOf } from "../page.js";
3
+ import { canonicalProject } from "../vocabulary/project.js";
4
+ export const FACT_QUERY = {
5
+ entity: "fact",
6
+ backend: "native",
7
+ fields: [
8
+ termField("kind", "enum", "kind:decision", { values: FACT_TYPES }),
9
+ termField("status", "enum", "status:proposed", { values: FACT_STATUSES }),
10
+ termField("project", "kw", "project:SYH"),
11
+ termField("subject", "ref", 'subject:"person:42"'),
12
+ ],
13
+ };
14
+ /** A fact as cli-core's `fact` entity. */
15
+ export const factItem = ({ type, statement, source, confirmedBy, ...fact }) => ({
16
+ ref: fact.ref,
17
+ id: fact.id,
18
+ kind: type,
19
+ text: statement,
20
+ status: fact.status,
21
+ project: fact.project,
22
+ project_name: fact.projectName,
23
+ subject: fact.subject,
24
+ subject_name: fact.subjectName,
25
+ subject_is_owner: fact.subjectIsOwner,
26
+ occurred_at: fact.occurredAt,
27
+ supersedes: fact.supersedes,
28
+ author: fact.author,
29
+ model: fact.model,
30
+ scope: fact.scope,
31
+ origin: source,
32
+ evidence: fact.evidence,
33
+ source_review: fact.sourceReview,
34
+ created_at: fact.createdAt,
35
+ updated_at: fact.updatedAt,
36
+ confirmed_by: confirmedBy,
37
+ });
38
+ /** Facts the store filters by the query's terms; CLI and MCP list through it. */
39
+ export const listFacts = async (store, query, limit, page) => {
40
+ const terms = queryTerms(query, FACT_QUERY, "facts list");
41
+ const project = terms.get("project");
42
+ const filters = {
43
+ ...(terms.has("kind") ? { type: terms.get("kind") } : {}),
44
+ ...(terms.has("status") ? { status: terms.get("status") } : {}),
45
+ ...(project === undefined ? {} : { project: await canonicalProject(store, project) }),
46
+ ...(terms.has("subject") ? { subject: terms.get("subject") } : {}),
47
+ };
48
+ return pageOf("facts list", limit, (most, offset) => store.facts.list({ ...filters, limit: most, offset }), {
49
+ page,
50
+ args: { query: typedQuery(query) },
51
+ shape: (rows) => rows.map(factItem),
52
+ });
53
+ };
54
+ //# sourceMappingURL=fact.js.map
@@ -0,0 +1,15 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ export const addFact = async (store, input) => {
3
+ if (input.by !== "owner" && !input.evidence?.length)
4
+ throw new CliError("validation_error", "an agent's fact must cite at least one evidence reference", {
5
+ param: "evidence",
6
+ });
7
+ // An agent may confirm its own proposal over MCP or in a terminal, which would push out what the owner accepted.
8
+ if (input.by !== "owner" && input.supersedes !== undefined)
9
+ if ((await store.facts.get(input.supersedes)).status === "accepted")
10
+ throw new CliError("permission_error", "only the owner corrects an accepted fact; an agent adds a new one", {
11
+ param: "supersedes",
12
+ });
13
+ return store.facts.add(input);
14
+ };
15
+ //# sourceMappingURL=facts.js.map
@@ -0,0 +1,58 @@
1
+ import { CliError, errorObjectOf, errorRecordOf, exitCodeOfError, mcpErrorResult, renderError, } from "@wirecat/cli-base";
2
+ import { metaOf } from "@wirecat/cli-base/commands";
3
+ import { agentResult, failureContext, judgedEffects, storeDamaged } from "@wirecat/cli-core";
4
+ import { CommanderError } from "commander";
5
+ import { ValiError } from "valibot";
6
+ import { APP } from "./app.js";
7
+ import { interactiveOf, optionsOf } from "./terminal.js";
8
+ const context = failureContext(APP.errors);
9
+ export const recognisable = (error) => {
10
+ if (error instanceof CommanderError)
11
+ return new CliError("validation_error", error.message.replace(/^error: /, ""), { reason: "input.invalid" });
12
+ if (error instanceof ValiError) {
13
+ const [issue] = error.issues;
14
+ const param = issue?.path?.map((item) => String(item.key)).join(".");
15
+ return new CliError("validation_error", issue?.message ?? "the input is not valid", {
16
+ reason: "input.invalid",
17
+ ...(param ? { param } : {}),
18
+ });
19
+ }
20
+ return storeDamaged(error, `${APP.command} store recover`);
21
+ };
22
+ export const errorObject = (error) => errorObjectOf(recognisable(error), context);
23
+ /** The same object as `--json` prints on stderr, as MCP's `isError` answer, with hidden characters shown. */
24
+ export const mcpFailure = (error) => agentResult(mcpErrorResult(errorObject(error)));
25
+ const commandOf = (program, args) => {
26
+ const path = [];
27
+ let at = program;
28
+ for (const arg of args) {
29
+ if (arg.startsWith("-"))
30
+ continue;
31
+ const child = at?.commands.find((command) => command.name() === arg);
32
+ if (!child)
33
+ break;
34
+ path.push(child.name());
35
+ at = child;
36
+ }
37
+ return { name: path.join(" ") || "wcat", command: path.length ? at : undefined };
38
+ };
39
+ /** Parse failures reach the handler as `CommanderError` instead of Commander's own text and exit. */
40
+ export const throwParseFailures = (program) => {
41
+ program.exitOverride().configureOutput({ outputError: () => undefined });
42
+ for (const command of program.commands)
43
+ throwParseFailures(command);
44
+ };
45
+ /** One error object on stderr, `✗ message` at a terminal; returns the exit code. */
46
+ export const reportFailure = (error, { args, program, streams, tty }) => {
47
+ const failure = recognisable(error);
48
+ const flags = optionsOf(args);
49
+ const failed = commandOf(program, flags);
50
+ const effects = judgedEffects(failed.command && metaOf(failed.command).effects);
51
+ const object = errorObjectOf(failure, { ...context, ...(effects ? { effects } : {}) });
52
+ const record = flags.includes("--debug")
53
+ ? errorRecordOf(failure, object, { command: failed.name, service: APP.command, version: APP.version })
54
+ : undefined;
55
+ streams.diagnostic(renderError(object, { cli: APP.command, interactive: interactiveOf(args, tty), ...(record ? { record } : {}) }));
56
+ return exitCodeOfError(object);
57
+ };
58
+ //# sourceMappingURL=failure.js.map
@@ -0,0 +1,121 @@
1
+ import { annotate } from "@wirecat/cli-base/commands";
2
+ import { INVOICE_DIRECTIONS, LOCAL_READ, LOCAL_WRITE, MONEY_DIRECTIONS, withQuery } from "@wirecat/cli-core";
3
+ import { answers, itemAnswer } from "../answer.js";
4
+ import { byOption, whoRuns } from "../author.js";
5
+ import { positive } from "../options.js";
6
+ import { withSources } from "../records/sources.js";
7
+ import { dayOf, INVOICE_QUERY, listInvoices, listPayments, PAYMENT_QUERY, partyOf, today } from "./finance.js";
8
+ import { lineCommands } from "./lines-command.js";
9
+ import { choice, json, PROPOSES, party, writeMeta, writtenBy } from "./written.js";
10
+ export const financeCommands = (program, streams, env) => {
11
+ const { run } = answers(program, streams, env);
12
+ const invoices = program
13
+ .command("invoices")
14
+ .description("invoices you issued or received, with their lines and what paid them; amounts per currency")
15
+ .summary("invoices you issued or received, and what paid them");
16
+ withQuery(json(annotate(invoices.command("list"), { effects: LOCAL_READ })).description("invoices, newest first; review:proposed lists what waits for you"), INVOICE_QUERY)
17
+ .option("--limit <n>", "most invoices, up to 500", positive, 100)
18
+ .action((words, { json, limit }) => run(json, (store) => listInvoices(store, words, limit)));
19
+ json(annotate(invoices.command("show"), { effects: LOCAL_READ, output: { entity: "invoice" } }))
20
+ .description("one invoice with its lines and the payments allocated to it")
21
+ .argument("<ref>", "invoice:<id>")
22
+ .action((ref, options, command) => run(options.json, async (store) => itemAnswer(await withSources(command, store, await store.finance.invoice(ref)))));
23
+ json(writeMeta(party(annotate(invoices.command("add"), {
24
+ effects: LOCAL_WRITE,
25
+ output: { entity: "invoice" },
26
+ literal_after_dashes: true,
27
+ }), "billed or billing")
28
+ .option("--kind <kind>", "receivable (you bill them) or payable (they bill you)")
29
+ .option("--title <title>", "the invoice's number, as printed on it")
30
+ .option("--occurred-time <time>", "the day it was issued, such as 2026-11-01")
31
+ .option("--due <time>", "the day it is due, such as 2026-11-15")))
32
+ .description(`record an invoice of one line, and add more with invoices lines add; ${PROPOSES}`)
33
+ .summary("record an invoice; an agent's waits for your review")
34
+ .argument("<amount>", "a decimal, such as 50000.00")
35
+ .argument("<currency>", "ISO 4217, such as RUB")
36
+ .argument("<description...>", "what it bills, in a few words")
37
+ .action(async (amount, currency, words, options, command) => {
38
+ const by = await whoRuns(command, env, { asOwner: options.asOwner, question: "record this invoice as yours?" });
39
+ await run(options.json, async (store) => {
40
+ const issueDate = dayOf(options.occurredTime);
41
+ const dueDate = dayOf(options.due);
42
+ return itemAnswer(await store.finance.addInvoice({
43
+ ...(await writtenBy(store, by, options)),
44
+ direction: choice(options.kind, INVOICE_DIRECTIONS, "--kind"),
45
+ counterparty: partyOf(options, true),
46
+ currency,
47
+ lines: [{ description: words.join(" "), amount }],
48
+ ...(options.title === undefined ? {} : { number: options.title }),
49
+ ...(issueDate === undefined ? {} : { issueDate }),
50
+ ...(dueDate === undefined ? {} : { dueDate }),
51
+ }));
52
+ });
53
+ });
54
+ lineCommands(invoices, "invoice", run, env);
55
+ const payments = program
56
+ .command("payments")
57
+ .description("money paid to you or by you, and the invoices each payment settles; amounts per currency")
58
+ .summary("money paid to you or by you, and what it settles");
59
+ withQuery(json(annotate(payments.command("list"), { effects: LOCAL_READ })).description("payments, newest first; review:proposed lists what waits for you"), PAYMENT_QUERY)
60
+ .option("--limit <n>", "most payments, up to 500", positive, 100)
61
+ .action((words, { json, limit }) => run(json, (store) => listPayments(store, words, limit)));
62
+ json(annotate(payments.command("show"), { effects: LOCAL_READ, output: { entity: "payment" } }))
63
+ .description("one payment with the invoices it is allocated to")
64
+ .argument("<ref>", "payment:<id>")
65
+ .action((ref, options, command) => run(options.json, async (store) => itemAnswer(await withSources(command, store, await store.finance.payment(ref)))));
66
+ json(writeMeta(party(annotate(payments.command("add"), { effects: LOCAL_WRITE, output: { entity: "payment" } }), "who paid or was paid")
67
+ .option("--kind <kind>", "in (paid to you) or out (paid by you)")
68
+ .option("--title <title>", "the payment's reference, such as the bank's purpose line")
69
+ .option("--occurred-time <time>", "the day it was paid, such as 2026-11-01; today when left out")
70
+ .option("--refund-of <payment>", "the payment this one gives money back for, going the other way: payment:<id>")))
71
+ .description(`record a payment, or with --refund-of a refund of one; ${PROPOSES}. payments allocate matches it to an invoice`)
72
+ .summary("record a payment; an agent's waits for your review")
73
+ .argument("<amount>", "a decimal, such as 50000.00")
74
+ .argument("<currency>", "ISO 4217, such as RUB")
75
+ .action(async (amount, currency, options, command) => {
76
+ const by = await whoRuns(command, env, { asOwner: options.asOwner, question: "record this payment as yours?" });
77
+ await run(options.json, async (store) => {
78
+ const direction = choice(options.kind, MONEY_DIRECTIONS, "--kind");
79
+ const counterparty = partyOf(options, false);
80
+ return itemAnswer(await store.finance.addPayment({
81
+ ...(await writtenBy(store, by, options)),
82
+ direction,
83
+ ...(counterparty === undefined
84
+ ? {}
85
+ : direction === "in"
86
+ ? { payer: counterparty }
87
+ : { payee: counterparty }),
88
+ amount,
89
+ currency,
90
+ date: dayOf(options.occurredTime) ?? today(),
91
+ ...(options.title === undefined ? {} : { reference: options.title }),
92
+ ...(options.refundOf === undefined ? {} : { refundOf: options.refundOf }),
93
+ }));
94
+ });
95
+ });
96
+ json(byOption(annotate(payments.command("allocate"), { effects: LOCAL_WRITE, output: { entity: "payment_allocation" } })))
97
+ .description("settle part of an invoice with part of a payment, in their one currency, never beyond either; an agent " +
98
+ "allocates only a payment it proposed")
99
+ .summary("settle part of an invoice with part of a payment")
100
+ .argument("<payment>", "payment:<id>")
101
+ .argument("<invoice>", "invoice:<id>")
102
+ .argument("<amount>", "a decimal, such as 25000.00")
103
+ .action(async (payment, invoice, amount, options, command) => {
104
+ const by = await whoRuns(command, env, { asOwner: options.asOwner, question: `allocate ${payment} as yours?` });
105
+ await run(options.json, async (store) => itemAnswer(await store.finance.allocate({ payment, invoice, amount, by })));
106
+ });
107
+ json(byOption(annotate(payments.command("unlink"), { effects: LOCAL_WRITE, output: { entity: "payment" } })))
108
+ .description("take back what a payment settles of an invoice, to allocate it again; you set right a confirmed payment's " +
109
+ "wrong split, and an agent unlinks only a still-proposed payment it proposed")
110
+ .summary("take back a payment's allocation to an invoice")
111
+ .argument("<payment>", "payment:<id>")
112
+ .argument("<invoice>", "invoice:<id>")
113
+ .action(async (payment, invoice, options, command) => {
114
+ const by = await whoRuns(command, env, {
115
+ asOwner: options.asOwner,
116
+ question: `unlink ${payment} as yours?`,
117
+ });
118
+ await run(options.json, async (store) => itemAnswer(await store.finance.unallocate({ payment, invoice, by })));
119
+ });
120
+ };
121
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1,109 @@
1
+ import { annotate } from "@wirecat/cli-base/commands";
2
+ import { CONTRACT_KINDS, CONTRACT_STATUSES, FINANCE_REVIEWS, LOCAL_READ, LOCAL_WRITE, queryTerms, termField, withQuery, } from "@wirecat/cli-core";
3
+ import { InvalidArgumentError } from "commander";
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 } from "./finance.js";
11
+ import { choice, given, json, onOff, optionalChoice, writeMeta, writtenBy } from "./written.js";
12
+ export const CONTRACT_QUERY = {
13
+ entity: "contract",
14
+ backend: "native",
15
+ fields: [
16
+ termField("status", "enum", "status:active", { values: CONTRACT_STATUSES }),
17
+ termField("kind", "enum", "kind:lease", { values: CONTRACT_KINDS }),
18
+ termField("project", "kw", "project:PMED"),
19
+ termField("review", "enum", "review:proposed", { values: FINANCE_REVIEWS }),
20
+ termField("expires", "time", "expires:2026-12-31"),
21
+ ],
22
+ };
23
+ export const listContracts = async (store, words, limit) => {
24
+ const terms = queryTerms(words, CONTRACT_QUERY, "contracts list");
25
+ const project = terms.get("project");
26
+ const filter = given({
27
+ status: terms.get("status"),
28
+ kind: terms.get("kind"),
29
+ review: terms.get("review"),
30
+ expiresBy: dayOf(terms.get("expires")),
31
+ project: project === undefined ? undefined : await canonicalProject(store, project),
32
+ });
33
+ return pageOf("contracts list", limit, (most) => store.contracts.list({ ...filter, limit: most }));
34
+ };
35
+ const days = (value) => {
36
+ const number = Number(value);
37
+ if (!Number.isInteger(number) || number < 0)
38
+ throw new InvalidArgumentError("a whole number of days, 0 or more");
39
+ return number;
40
+ };
41
+ const terms = (command) => command
42
+ .option("--kind <kind>", `what it is: ${CONTRACT_KINDS.join(", ")}`)
43
+ .option("--status <state>", `${CONTRACT_STATUSES.join(", ")}; active when left out`)
44
+ .option("--start-date <date>", "the first day it is in force, YYYY-MM-DD")
45
+ .option("--end-date <date>", "the last day it is in force, YYYY-MM-DD; left out, it runs until ended")
46
+ .option("--auto-renew <on|off>", "it renews by itself at its end, or it does not")
47
+ .option("--notice-days <days>", "how many days before its end a party must say it will not go on", days)
48
+ .option("--amount <decimal>", "what it is worth, such as 120000.00, in --currency; with it, an agent's waits for you")
49
+ .option("--currency <code>", "an ISO 4217 code, such as RUB");
50
+ const fieldsOf = (options) => given({
51
+ status: optionalChoice(options.status, CONTRACT_STATUSES, "--status"),
52
+ effectiveDate: dayOf(options.startDate),
53
+ expirationDate: dayOf(options.endDate),
54
+ autoRenew: onOff(options.autoRenew, "--auto-renew"),
55
+ noticeDays: options.noticeDays,
56
+ value: options.amount,
57
+ currency: options.currency,
58
+ });
59
+ const VALUED = "one with no amount is written as it is, by anyone; with an amount yours is confirmed at once and an agent's " +
60
+ "waits as proposed for you in wcat review";
61
+ /** `wcat contracts`: what the owner works under, its dates, renewal and notice. */
62
+ export const contractCommands = (program, streams, env) => {
63
+ const { run } = answers(program, streams, env);
64
+ const contracts = program
65
+ .command("contracts")
66
+ .description("contracts you work under: their kind, dates, renewal, notice and what they are worth")
67
+ .summary("contracts you work under, with their dates and notice");
68
+ withQuery(json(annotate(contracts.command("list"), { effects: LOCAL_READ })).description("contracts, newest first; expires:2026-12-31 lists those that end by then"), CONTRACT_QUERY)
69
+ .option("--limit <n>", "most contracts, up to 500", positive, 100)
70
+ .action((words, { json, limit }) => run(json, (store) => listContracts(store, words, limit)));
71
+ json(annotate(contracts.command("show"), { effects: LOCAL_READ, output: { entity: "contract" } }))
72
+ .description("one contract with its dates, renewal and the last day to give notice")
73
+ .argument("<contract>", "contract:<id>")
74
+ .action((ref, options, command) => run(options.json, async (store) => itemAnswer(await withSources(command, store, await store.contracts.get(ref)))));
75
+ json(writeMeta(terms(annotate(contracts.command("add"), {
76
+ effects: LOCAL_WRITE,
77
+ output: { entity: "contract" },
78
+ literal_after_dashes: true,
79
+ }))))
80
+ .description(`record a contract; ${VALUED}`)
81
+ .summary("record a contract")
82
+ .argument("<name>", "what it is called, such as 'Rental agreement'")
83
+ .action(async (name, options, command) => {
84
+ const by = await whoRuns(command, env, { asOwner: options.asOwner, question: "record this contract as yours?" });
85
+ await run(options.json, async (store) => itemAnswer(await store.contracts.add({
86
+ ...(await writtenBy(store, by, options)),
87
+ name,
88
+ kind: choice(options.kind, CONTRACT_KINDS, "--kind"),
89
+ ...fieldsOf(options),
90
+ })));
91
+ });
92
+ json(byOption(terms(annotate(contracts.command("update"), { effects: LOCAL_WRITE, output: { entity: "contract" } })).option("--title <title>", "its new name")))
93
+ .description("change a contract's dates, status, terms or worth; you change any, an agent only one it proposed that is " +
94
+ "still proposed, and a confirmed contract's worth only you")
95
+ .summary("change a contract")
96
+ .argument("<contract>", "contract:<id>")
97
+ .action(async (ref, options, command) => {
98
+ const by = await whoRuns(command, env, { asOwner: options.asOwner, question: `change ${ref} as yours?` });
99
+ await run(options.json, async (store) => itemAnswer(await store.contracts.update(ref, {
100
+ by,
101
+ ...fieldsOf(options),
102
+ ...given({
103
+ name: options.title,
104
+ kind: optionalChoice(options.kind, CONTRACT_KINDS, "--kind"),
105
+ }),
106
+ })));
107
+ });
108
+ };
109
+ //# sourceMappingURL=contracts-command.js.map
@@ -0,0 +1,34 @@
1
+ import { coverageLines, relatedLine, sectionLines } from "../knowledge/business-text.js";
2
+ import { moneyLines } from "../knowledge/money-text.js";
3
+ const amountOf = (amount, currency) => [amount, currency].filter(Boolean).join(" ");
4
+ export const dealText = (context) => {
5
+ const { deal, organization, owner, project, window, communications } = context;
6
+ return [
7
+ `${deal.title} ${deal.ref} ${deal.stage} ${deal.status} ${amountOf(deal.amount, deal.currency)}`,
8
+ `Client ${organization ? `${organization.name ?? organization.ref} ${organization.ref}` : "none"}`,
9
+ `Owner ${owner ? relatedLine(owner).trim() : "none"}`,
10
+ `Project ${project ? `${project.name ?? project.ref} ${project.ref}` : "none"}`,
11
+ ...sectionLines("Stages", context.stages, (one) => ` ${one.at.slice(0, 10)} ${one.from ?? "—"} → ${one.to}`),
12
+ ...sectionLines("People", context.participants),
13
+ ...moneyLines(context.money),
14
+ `Between ${window.since.slice(0, 10)} and ${window.until.slice(0, 10)}, proposed: they share people, nothing links them`,
15
+ ...sectionLines("Messages, mail and meetings", communications, (one) => ` ${one.at?.slice(0, 16).replace("T", " ") ?? "—"} ${one.kind} ${one.title ?? ""} ${one.ref}`),
16
+ ...sectionLines("Open tasks", context.tasks, (one) => ` ${one.key} ${one.title} ${one.status}`),
17
+ ...coverageLines(context.coverage),
18
+ ]
19
+ .map((line) => line.trimEnd())
20
+ .join("\n");
21
+ };
22
+ export const dealBriefText = (brief) => [
23
+ `${brief.title} ${brief.ref} ${brief.pipeline}/${brief.stage} ${brief.status} ${amountOf(brief.amount, brief.currency)}`,
24
+ `client ${brief.organization ?? "none"}; owner ${brief.owner ?? "none"}; project ${brief.project ?? "none"}`,
25
+ ...brief.people.map((one) => ` ${one.name ?? one.ref} ${one.ref} ${one.roles.join(", ")} ${one.standing}`),
26
+ ...(brief.stages.length ? [`stages ${brief.stages.join("; ")}`] : []),
27
+ `invoiced ${brief.money.invoices.map((one) => `${one.status} ${one.total} ${one.currency}`).join(", ") || "none"}; ` +
28
+ `paid ${brief.money.payments.map((one) => `${one.total} ${one.currency}`).join(", ") || "none"}`,
29
+ `${brief.communications.messages} messages, ${brief.communications.mail} emails, ${brief.communications.meetings} meetings (proposed); ${brief.openTasks} open tasks`,
30
+ ...brief.notRead.map(({ source, reason }) => `not read: ${source} — ${reason}`),
31
+ ]
32
+ .map((line) => line.trimEnd())
33
+ .join("\n");
34
+ //# sourceMappingURL=deal-text.js.map