@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,162 @@
1
+ import { annotate } from "@wirecat/cli-base/commands";
2
+ import { LOCAL_READ } from "@wirecat/cli-core";
3
+ import { answers, itemAnswer, shortenedBy, timezone, withStore } from "../answer.js";
4
+ import { beforeOf, sinceOf } from "../digest/command.js";
5
+ import { sectionLines } from "../knowledge/business-text.js";
6
+ import { positive } from "../options.js";
7
+ import { atLeast, kindsText, waitingAbout } from "../review/status.js";
8
+ import { deniedCrmKinds } from "../search/denied.js";
9
+ import { crmNotes } from "../store/crm-viewer.js";
10
+ import { lockedCoverage } from "../store/guard.js";
11
+ import { contextAccountsOf, memoContext, withOwnMailText } from "./context.js";
12
+ const MAX_TEXT = 160;
13
+ /** A stored UTC time as the computer's wall clock, the zone named once at the top. */
14
+ const clock = (iso) => {
15
+ if (!iso || Number.isNaN(Date.parse(iso)))
16
+ return undefined;
17
+ const part = Object.fromEntries(new Intl.DateTimeFormat("en-CA", {
18
+ timeZone: timezone(),
19
+ year: "numeric",
20
+ month: "2-digit",
21
+ day: "2-digit",
22
+ hour: "2-digit",
23
+ minute: "2-digit",
24
+ hourCycle: "h23",
25
+ })
26
+ .formatToParts(Date.parse(iso))
27
+ .map(({ type, value }) => [type, value]));
28
+ return `${part.year}-${part.month}-${part.day} ${part.hour}:${part.minute}`;
29
+ };
30
+ const one = (message) => message === null
31
+ ? "—"
32
+ : `${clock(message.timestamp) ?? "—"} ${message.provider} ${message.chatTitle ?? message.chatId}: ` +
33
+ `${message.text.replace(/\s+/g, " ").slice(0, MAX_TEXT)} ${message.locator}`;
34
+ const eventLine = (event) => ` ${(event.allDay ? event.startsAt?.slice(0, 10) : clock(event.startsAt)) ?? "—"} ` +
35
+ `${(event.title ?? "untitled").replace(/\s+/g, " ").slice(0, MAX_TEXT)}${event.location ? ` ${event.location}` : ""} ${event.ref}`;
36
+ const meetingLine = (meeting) => ` ${clock(meeting.startedAt) ?? "—"} ` +
37
+ `${(meeting.title ?? "untitled").replace(/\s+/g, " ").slice(0, MAX_TEXT)} ${meeting.ref}`;
38
+ const minutes = (ms) => `${Math.floor(ms / 60_000)}:${String(Math.floor(ms / 1000) % 60).padStart(2, "0")}`;
39
+ /** A call says which way it went, how long, and who took it; anything else says what it is. */
40
+ const touchKind = ({ kind, call, durationMs }) => call
41
+ ? ["call", call.direction, durationMs == null ? null : minutes(durationMs), call.manager?.name]
42
+ .filter(Boolean)
43
+ .join(" ")
44
+ : kind;
45
+ export const touchLine = (touch) => ` ${clock(touch.at) ?? "—"} ${touchKind(touch)} ` +
46
+ `${[touch.title, touch.text].filter(Boolean).join(": ").replace(/\s+/g, " ").slice(0, MAX_TEXT)} ${touch.ref}`;
47
+ /** A note by the reference `notes show` takes, then where it is. */
48
+ const noteLine = (note) => ` ${note.ref}${(note.path ?? note.title) ? ` ${note.path ?? note.title}` : ""}`;
49
+ const fileLine = (file) => ` ${file.ref} ${file.role ?? ""} ${file.title ?? ""} ${clock(file.modifiedAt) ?? ""} ${file.url ?? ""}`;
50
+ export const businessLines = (business) => {
51
+ const lines = [
52
+ ...sectionLines("Organizations", business.organizations),
53
+ ...sectionLines("Reports to", business.reportsTo),
54
+ ...sectionLines("Direct reports", business.directReports),
55
+ ...sectionLines("Deals and leads", business.deals),
56
+ ...sectionLines("Projects", business.projects),
57
+ ...(business.categories.length ? [`Categories ${business.categories.join(", ")}`] : []),
58
+ ];
59
+ return lines.length ? ["", "Business", ...lines] : [];
60
+ };
61
+ export const contextText = ({ history, messages, events, meetings, notes, notRead, tasks, yourNotes, files, proposals, business, coverage, }) => {
62
+ const { person, last, recent, shared } = messages;
63
+ return [
64
+ `${person.name ?? person.uid} person:${person.uid}`,
65
+ ...person.identities.map(({ provider, id, name }) => ` ${provider}:${id} ${name ?? ""}`),
66
+ ` times in ${timezone()}`,
67
+ ...(proposals.count
68
+ ? [
69
+ ` ${atLeast(proposals.count, proposals.complete)} proposal${proposals.count === 1 ? "" : "s"} ` +
70
+ `about them waiting (${kindsText(proposals.kinds)}) — wcat ${proposals.next.command}`,
71
+ ]
72
+ : []),
73
+ ...(history.items.length === 0
74
+ ? []
75
+ : [
76
+ "",
77
+ "History",
78
+ ...history.items.map(touchLine),
79
+ ...(history.beforeTime
80
+ ? [` older — wcat context person:${person.uid} --before-time ${history.beforeTime}`]
81
+ : []),
82
+ ]),
83
+ "",
84
+ `Last from them ${one(last.fromThemAnywhere ?? last.fromThem)}`,
85
+ `Last from me ${one(last.fromMe)}`,
86
+ `In common ${shared.length} chats`,
87
+ ...(recent.direct.length === 0 ? [] : ["", "Recent, direct", ...recent.direct.map((m) => ` ${one(m)}`)]),
88
+ ...(recent.groups.length === 0 ? [] : ["", "Recent, in groups", ...recent.groups.map((m) => ` ${one(m)}`)]),
89
+ ...(events.upcoming.length === 0 ? [] : ["", "Upcoming events", ...events.upcoming.map(eventLine)]),
90
+ ...(events.recent.length === 0 ? [] : ["", "Recent events", ...events.recent.map(eventLine)]),
91
+ ...(meetings.length === 0 ? [] : ["", "Calls and meetings", ...meetings.map(meetingLine)]),
92
+ ...businessLines(business),
93
+ "",
94
+ "",
95
+ ...(notes.about.length === 0
96
+ ? ["Note about them none — files notes links add <identity> <path>"]
97
+ : ["Notes about them", ...notes.about.map(noteLine)]),
98
+ ...(notes.linking.length === 0 ? [] : ["Notes linking them", ...notes.linking.map(noteLine)]),
99
+ ...(notes.throughNotes.length === 0
100
+ ? []
101
+ : ["Notes linking a note about them", ...notes.throughNotes.map(noteLine)]),
102
+ ...(notes.hasMore ? [" more — raise --limit"] : []),
103
+ ...(files.length === 0 ? [] : ["", "Files, as their source reports", ...files.map(fileLine)]),
104
+ ...(messages.complete ? [] : ["", `Not read in full: ${messages.notRead.length} chats — messages sync <chat>`]),
105
+ ...notRead.map(({ source, reason }) => `Not read: ${source} — ${reason}`),
106
+ ...(coverage?.notRead ?? []).map(({ source, reason }) => `Not read: ${source} — ${reason}`),
107
+ ...(coverage ? [`Read: ${coverage.accounts.join(", ") || "no account"}`] : []),
108
+ ...(tasks.items.length
109
+ ? [
110
+ "",
111
+ "Open tasks",
112
+ ...tasks.items.map((task) => ` task:${task.id} ${task.kind} ${task.source} ${task.note?.text ?? task.message?.text ?? "source unavailable"}`),
113
+ ]
114
+ : []),
115
+ ...(yourNotes.length
116
+ ? [
117
+ "",
118
+ "Your notes",
119
+ ...yourNotes.map((note) => ` ${note.ref} ${note.text.replace(/\s+/g, " ").slice(0, MAX_TEXT)}`),
120
+ ]
121
+ : []),
122
+ ].join("\n");
123
+ };
124
+ export const contextCommand = (program, streams, env) => {
125
+ const { print } = answers(program, streams, env);
126
+ annotate(program.command("context"), { effects: LOCAL_READ, output: { entity: "person_context_memo" } })
127
+ .description("messages, mail, notes and events about a person, each with a link to its source, and `business`: their " +
128
+ "organizations, reporting lines, deals and projects, each relationship with its standing (`reported` is a " +
129
+ "CRM's word only). person:<id> reads every account; `coverage` names what was read and what was not. " +
130
+ "`proposals` counts what waits for you about them, by kind (`complete: false` means at least), and `next` " +
131
+ "names the command that lists them")
132
+ .summary("messages, mail, notes and events about a person, each with a link to its source")
133
+ .argument("<person>", "<messenger>:<name or id>, e.g. telegram:Ana or email:ana@example.com, person:<id>, or person:me for you")
134
+ .option("--limit <n>", "most messages, notes and events of each kind, and history items", positive, 20)
135
+ .option("--since-time <time>", "the history from this time: hours or days back (12h, 7d) or a date (2026-11-01); the newest when left out")
136
+ .option("--before-time <time>", "the history before this ISO time or date: what `history.before_time` gives, to page back")
137
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
138
+ .option("--source <accounts>", "the accounts to read: every one when left out, or the group's in a group run; for <messenger>:<name>, " +
139
+ "the one account of that messenger")
140
+ .option("--trimmed", "each email's own text, without quoted earlier mail or the signature — for an agent's reads")
141
+ .action(async (person, options, command) => {
142
+ const { answer, notes } = await withStore(env, async (store) => {
143
+ const sources = options.source === undefined ? undefined : await contextAccountsOf(store, env, person, options.source);
144
+ const found = await memoContext(store, env, person, {
145
+ limit: options.limit,
146
+ deniedKinds: deniedCrmKinds(command, env),
147
+ ...(sources === undefined ? {} : { sources }),
148
+ ...(options.sinceTime === undefined ? {} : { since: sinceOf(options.sinceTime) }),
149
+ ...(options.beforeTime === undefined ? {} : { until: beforeOf(options.beforeTime) }),
150
+ });
151
+ const { uid, identities } = found.messages.person;
152
+ const refs = [`person:${uid}`, ...identities.map(({ provider, id }) => `${provider}:${id}`)];
153
+ const answer = await lockedCoverage(store, env, {
154
+ ...(options.trimmed ? withOwnMailText(found) : found),
155
+ proposals: { ...(await waitingAbout(store, env, refs)), next: { command: "review list" } },
156
+ });
157
+ return { answer, notes: crmNotes(store) };
158
+ });
159
+ print(options.json, shortenedBy(notes, itemAnswer(answer)), contextText(answer));
160
+ });
161
+ };
162
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1,197 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { calendarAccounts, canonicalPersonContext, HISTORY_MAX, isUsable, personBusiness, personContext, personHistory, } from "@wirecat/cli-core";
3
+ import { mailOwnText } from "@wirecat/cli-core/mail";
4
+ import { holdsFolder, notesAbout } from "../knowledge/notes-about.js";
5
+ import { withOwner } from "../people/owner.js";
6
+ import { crmViewersAll, crmViewingAll } from "../store/crm-viewer.js";
7
+ import { groupScopeOf, inGroup, scopedAccounts } from "../store/group.js";
8
+ import { selectAccount } from "../store/scope.js";
9
+ import { accountsOf } from "../store/source-list.js";
10
+ import { personTasks } from "../tasks/context.js";
11
+ /** Written by whoever sent the invitation, as cli-core's calendar tools mark them. */
12
+ const UNTRUSTED_EVENT_FIELDS = [
13
+ "events.upcoming.title",
14
+ "events.upcoming.location",
15
+ "events.recent.title",
16
+ "events.recent.location",
17
+ "meetings.snippet",
18
+ "history.items.title",
19
+ "history.items.text",
20
+ ];
21
+ /**
22
+ * A documents CLI (drive, notion) names a link `<provider>:<call>` when it copies who owns or edited a file from the
23
+ * source's own record, so it is a fact as the source states it, not a guess. It counts only on a file of that provider's
24
+ * own documents account, the rule cli-core's `reported` standing follows.
25
+ */
26
+ const reportedFiles = async (store, links, limit, scope) => {
27
+ const inScope = holdsFolder(scope);
28
+ const providers = new Map((await store.notes.documentsAccounts()).flatMap(({ id, account }) => account && inScope(id) ? [[id, account.provider]] : []));
29
+ const files = [];
30
+ for (const link of links) {
31
+ if (files.length >= limit)
32
+ break;
33
+ if (link.kind !== "related-to" || !link.provenance?.includes(":"))
34
+ continue;
35
+ const note = await store.notes.note(link.from).catch(() => null);
36
+ if (!note || note.deletedAt || note.folderId === null || note.path === null)
37
+ continue;
38
+ if (providers.get(note.folderId) !== link.provenance.split(":")[0])
39
+ continue;
40
+ const entry = await store.catalog.get(note.folderId, note.path);
41
+ if (!entry)
42
+ continue;
43
+ files.push({
44
+ ref: note.ref,
45
+ title: entry.name ?? note.title,
46
+ url: entry.url ?? null,
47
+ role: link.role,
48
+ modifiedAt: entry.modifiedAt ?? null,
49
+ provenance: link.provenance,
50
+ confirmed: link.confirmed,
51
+ });
52
+ }
53
+ return files;
54
+ };
55
+ /**
56
+ * One answer about a person: what the store holds of them across messengers and mail (cli-core's
57
+ * person context), and every note linked to them. A name in a note's plain text is not a link.
58
+ */
59
+ /**
60
+ * The stored accounts of the person's messenger that `source` names (`telegram:1`, or a group's), as memoContext
61
+ * takes them.
62
+ */
63
+ export const contextAccountsOf = async (store, env, person, source) => {
64
+ const provider = person.startsWith("person:") ? undefined : person.split(":")[0];
65
+ const keys = (await accountsOf(store, env, source)).filter((key) => provider === undefined || key.provider === provider);
66
+ if (keys.length === 0)
67
+ throw new CliError("validation_error", `${source} is not an account of ${person}'s messenger`, { param: "source" });
68
+ return keys;
69
+ };
70
+ const accountIn = (keys) => keys?.length === 1 ? { account: keys[0].account } : {};
71
+ export const memoContext = async (store, env, reference, { limit = 20, sources, deniedKinds = [], since, until, } = {}) => {
72
+ const window = { ...(since === undefined ? {} : { since }), ...(until === undefined ? {} : { until }) };
73
+ const named = (await withOwner(store, reference)).trim();
74
+ const scope = await groupScopeOf(store, env);
75
+ const viewing = await crmViewingAll(store);
76
+ if (named.startsWith("person:")) {
77
+ // Every account in scope that saw them, a CRM's and a name the owner added too, never one picked (WC-ACCT-9).
78
+ const accounts = sources === undefined ? scope?.accounts : [...sources];
79
+ const { events, meetings, business, coverage, ...messages } = await canonicalPersonContext(store, named, {
80
+ messages: limit,
81
+ limit,
82
+ deniedKinds,
83
+ viewing,
84
+ ...(accounts === undefined ? {} : { accounts }),
85
+ });
86
+ const same = (one) => (key) => key.provider === one.provider && key.account === one.account;
87
+ // A group's list also names notes folders, which hold no tasks of their own: the stored accounts it names.
88
+ const read = accounts === undefined
89
+ ? await scopedAccounts(store, env)
90
+ : (await store.accounts.accounts()).filter((one) => accounts.some(same(one)));
91
+ const calendars = (await calendarAccounts(store)).filter((one) => accounts === undefined || accounts.some(same(one)));
92
+ return withNotesAndTasks(store, env, { messages, events, meetings, business, coverage }, { accounts: read, calendars, deniedKinds, window, ...(accounts === undefined ? {} : { scope: accounts }) }, limit);
93
+ }
94
+ const [, provider, who] = /^([a-z][a-z0-9-]*):(.+)$/.exec(reference.trim()) ?? [];
95
+ if (provider === undefined || who === undefined)
96
+ throw new CliError("validation_error", `"${reference}" names no messenger — write it as <messenger>:<name or id>`, {
97
+ reason: "identity.no-messenger",
98
+ });
99
+ const accounts = await scopedAccounts(store, env);
100
+ const own = sources?.filter((one) => one.provider === provider);
101
+ const asked = own?.length === 1 ? own[0] : await selectAccount(store, env, { provider, ...accountIn(own) });
102
+ const calendars = await inGroup(store, env, await calendarAccounts(store));
103
+ const calendarIds = scope === undefined
104
+ ? undefined
105
+ : await Promise.all(calendars.map(async (key) => (await store.accounts.storedAccount(key)).id));
106
+ const { events, meetings, ...messages } = await personContext(store, asked, who, {
107
+ messages: limit,
108
+ ...(calendarIds === undefined ? {} : { calendarIds }),
109
+ });
110
+ // cli-core keeps a scope, denied kinds and the CRM copies' rules out of `business` in its canonical context only.
111
+ const business = scope === undefined && deniedKinds.length === 0 && viewing.every(({ viewer, note }) => !viewer && !note)
112
+ ? await personBusiness(store, messages.person.uid, { limit })
113
+ : (await canonicalPersonContext(store, `person:${messages.person.uid}`, {
114
+ ...(scope === undefined ? {} : { accounts: scope.accounts }),
115
+ deniedKinds,
116
+ viewing,
117
+ limit,
118
+ messages: 1,
119
+ })).business;
120
+ return withNotesAndTasks(store, env, { messages, events, meetings, business }, { accounts, calendars, deniedKinds, window, ...(scope === undefined ? {} : { scope: scope.accounts }) }, limit);
121
+ };
122
+ /** What wcat adds to cli-core's context of a person: the notes, tasks and files linked to them. */
123
+ const withNotesAndTasks = async (store, _env, { messages, events, meetings, business, coverage }, { accounts, calendars, scope, deniedKinds = [], window, }, limit) => {
124
+ const person = `person:${messages.person.uid}`;
125
+ const linked = await notesAbout(store, { ref: person, person: messages.person }, limit, scope);
126
+ const yourNotes = [];
127
+ for (const ref of linked.about.filter((note) => note.source === "internal")) {
128
+ const note = await store.notes.note(ref.ref);
129
+ yourNotes.push({ id: note.id, ref: note.ref, text: note.text, revision: note.revision, updatedAt: note.updatedAt });
130
+ }
131
+ const notRead = [];
132
+ if ((await store.notes.folders()).length + (await store.notes.documentsAccounts()).length === 0)
133
+ notRead.push({
134
+ source: "notes",
135
+ reason: "no folder of notes — files folders add <path>, then files sync",
136
+ });
137
+ if (!messages.person.identities.some((identity) => identity.provider === "email"))
138
+ notRead.push({
139
+ source: "mail",
140
+ reason: "no mail address linked to them — tg <profile> contacts link <person> email:<address>",
141
+ });
142
+ // For person:<id>, cli-core's coverage already says whether a calendar was read.
143
+ if (calendars.length === 0 && coverage === undefined)
144
+ notRead.push({ source: "events", reason: "no calendar in the store — gcal <profile> sync" });
145
+ const tasks = await personTasks(store, messages.person, accounts, limit);
146
+ const incoming = await store.notes.links({ to: person });
147
+ // cli-core leaves out a link with an end outside the scope, the owner's too, and an end of a denied kind.
148
+ const listed = await store.knowledge.listRelations({
149
+ about: person,
150
+ ...(scope === undefined ? {} : { accounts: scope }),
151
+ ...(deniedKinds.length ? { deniedKinds: [...deniedKinds] } : {}),
152
+ viewers: await crmViewersAll(store),
153
+ limit: 500,
154
+ });
155
+ const providers = new Set((await store.notes.documentsAccounts()).flatMap(({ account }) => account?.provider ?? []));
156
+ // A file its source reports is listed under files; since cli-core 0.621.0 its link is `reported`, so it would repeat here.
157
+ const relationships = listed.items.filter((one) => isUsable(one.standing) &&
158
+ !(one.kind === "related-to" && one.provenance && providers.has(one.provenance.split(":")[0])));
159
+ const files = await reportedFiles(store, incoming, limit, scope);
160
+ const { subject: _, name: __, ...notes } = linked;
161
+ const { next: beforeTime, ...history } = await personHistory(store, person, {
162
+ ...(scope === undefined ? {} : { accounts: scope }),
163
+ deniedKinds,
164
+ ...window,
165
+ limit: Math.min(limit, HISTORY_MAX),
166
+ });
167
+ return {
168
+ history: { ...history, beforeTime },
169
+ messages,
170
+ events: { ...events, accounts: calendars.map(({ provider, account }) => `${provider}:${account}`) },
171
+ meetings,
172
+ notes: { ...notes, about: notes.about.filter((note) => note.source === "file") },
173
+ yourNotes,
174
+ notRead,
175
+ tasks,
176
+ relationships,
177
+ business,
178
+ ...(coverage === undefined ? {} : { coverage }),
179
+ files,
180
+ untrusted: UNTRUSTED_EVENT_FIELDS,
181
+ };
182
+ };
183
+ /** The context with each email's own text (`mailOwnText`): no earlier mail quoted in it, no signature. */
184
+ export const withOwnMailText = (context) => {
185
+ const own = (message) => message?.provider === "email" ? { ...message, text: mailOwnText(message.text) } : message;
186
+ const { last, recent, mentions } = context.messages;
187
+ return {
188
+ ...context,
189
+ messages: {
190
+ ...context.messages,
191
+ last: { fromThem: own(last.fromThem), fromMe: own(last.fromMe), fromThemAnywhere: own(last.fromThemAnywhere) },
192
+ recent: { direct: recent.direct.map(own), groups: recent.groups.map(own) },
193
+ mentions: mentions.map(own),
194
+ },
195
+ };
196
+ };
197
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,81 @@
1
+ // Reviewed differences from Core; update only after reviewing both definitions.
2
+ export const commands = [
3
+ {
4
+ command: ["commands"],
5
+ field: "arguments",
6
+ before: [
7
+ {
8
+ name: "path",
9
+ required: false,
10
+ variadic: true,
11
+ description: "one command path, for example: commands info; inspect other groups in separate calls",
12
+ },
13
+ ],
14
+ after: [
15
+ {
16
+ name: "path",
17
+ required: false,
18
+ variadic: true,
19
+ description: "one command, such as tags add",
20
+ },
21
+ ],
22
+ reason: "wcat binds discovery to its command-local JSON renderer and scoped stored-data document format.",
23
+ },
24
+ {
25
+ command: ["commands"],
26
+ field: "options",
27
+ before: [],
28
+ after: [
29
+ {
30
+ flags: "--json",
31
+ description: "print JSON; --json=id,title keeps only those fields",
32
+ takes_value: false,
33
+ mandatory: false,
34
+ },
35
+ ],
36
+ reason: "wcat binds discovery to its command-local JSON renderer and scoped stored-data document format.",
37
+ },
38
+ {
39
+ command: ["commands", "info"],
40
+ field: "examples",
41
+ before: ["wcat commands info commands"],
42
+ after: ["wcat commands info --json"],
43
+ reason: "wcat binds discovery to its command-local JSON renderer and scoped stored-data document format.",
44
+ },
45
+ {
46
+ command: ["commands", "info"],
47
+ field: "arguments",
48
+ before: [
49
+ {
50
+ name: "path",
51
+ required: false,
52
+ variadic: true,
53
+ description: "one command path; without one, export schemas, error reasons and explicit overrides",
54
+ },
55
+ ],
56
+ after: [
57
+ {
58
+ name: "path",
59
+ required: false,
60
+ variadic: true,
61
+ description: "one command path; without one, schemas, error reasons and explicit overrides",
62
+ },
63
+ ],
64
+ reason: "wcat binds discovery to its command-local JSON renderer and scoped stored-data document format.",
65
+ },
66
+ {
67
+ command: ["commands", "info"],
68
+ field: "options",
69
+ before: [],
70
+ after: [
71
+ {
72
+ flags: "--json",
73
+ description: "print JSON",
74
+ takes_value: false,
75
+ mandatory: false,
76
+ },
77
+ ],
78
+ reason: "wcat binds discovery to its command-local JSON renderer and scoped stored-data document format.",
79
+ },
80
+ ];
81
+ //# sourceMappingURL=commands.js.map