@wirecat/wirecat 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/LICENSE +204 -0
  2. package/README.md +400 -2
  3. package/THIRD_PARTY_NOTICES +2 -0
  4. package/contracts/wirecat.json +4612 -0
  5. package/dist/actions/actions.js +269 -0
  6. package/dist/actions/command.js +102 -0
  7. package/dist/agents/command.js +17 -0
  8. package/dist/agents/log.js +23 -0
  9. package/dist/answer.js +100 -0
  10. package/dist/answers/command.js +128 -0
  11. package/dist/app.js +15 -0
  12. package/dist/author.js +109 -0
  13. package/dist/bin/wcat-wirecat.js +40 -0
  14. package/dist/bots/command.js +175 -0
  15. package/dist/bundle/auto-YETGUQ2J.js +43 -0
  16. package/dist/bundle/chunk-3ME37WWB.js +31 -0
  17. package/dist/bundle/chunk-4WI3FO7T.js +395 -0
  18. package/dist/bundle/chunk-7O7XM37N.js +2 -0
  19. package/dist/bundle/chunk-DWQQRBQV.js +51 -0
  20. package/dist/bundle/chunk-FOWR5KJS.js +72 -0
  21. package/dist/bundle/chunk-GGRL6DTE.js +120 -0
  22. package/dist/bundle/chunk-KNFSW562.js +312 -0
  23. package/dist/bundle/chunk-KPJVVFQF.js +416 -0
  24. package/dist/bundle/chunk-WMPDRWVF.js +222 -0
  25. package/dist/bundle/chunk-X5OK73GU.js +807 -0
  26. package/dist/bundle/chunk-ZC4PRE6C.js +38 -0
  27. package/dist/bundle/entry-S4DSYEAY.js +64 -0
  28. package/dist/bundle/failure-FALOD7QW.js +19 -0
  29. package/dist/bundle/from-memo-XVOLSUOM.js +314 -0
  30. package/dist/bundle/program-XSZSINBU.js +14994 -0
  31. package/dist/bundle/server-GQ4NZUDL.js +303 -0
  32. package/dist/bundle/update-2EH5KHTV.js +22 -0
  33. package/dist/bundle/wcat-wirecat.js +83 -0
  34. package/dist/config-command.js +39 -0
  35. package/dist/config-issues.js +15 -0
  36. package/dist/config.js +187 -0
  37. package/dist/context/command.js +162 -0
  38. package/dist/context/context.js +197 -0
  39. package/dist/contract-overrides/commands.js +81 -0
  40. package/dist/contract-overrides/mcp.js +241 -0
  41. package/dist/contract-overrides/meetings.js +344 -0
  42. package/dist/contract-overrides/search.js +508 -0
  43. package/dist/contract-overrides/skill.js +85 -0
  44. package/dist/contract-overrides.js +7 -0
  45. package/dist/digest/backfill.js +175 -0
  46. package/dist/digest/brief.js +189 -0
  47. package/dist/digest/catch-up-record.js +30 -0
  48. package/dist/digest/catch-up.js +86 -0
  49. package/dist/digest/command.js +110 -0
  50. package/dist/digest/digest-commands.js +327 -0
  51. package/dist/digest/digest.js +560 -0
  52. package/dist/digest/digests.js +213 -0
  53. package/dist/digest/history.js +202 -0
  54. package/dist/digest/input.js +30 -0
  55. package/dist/digest/known.js +28 -0
  56. package/dist/digest/sources.js +155 -0
  57. package/dist/digest/sync-health.js +158 -0
  58. package/dist/digest/task-proposals.js +67 -0
  59. package/dist/digest/tasks.js +145 -0
  60. package/dist/digest/text.js +49 -0
  61. package/dist/discovery/command.js +107 -0
  62. package/dist/doctor/command.js +167 -0
  63. package/dist/documents/command.js +107 -0
  64. package/dist/domain-lists/command.js +13 -0
  65. package/dist/events/command.js +35 -0
  66. package/dist/events/events.js +196 -0
  67. package/dist/examples.js +609 -0
  68. package/dist/facts/command.js +100 -0
  69. package/dist/facts/fact.js +54 -0
  70. package/dist/facts/facts.js +15 -0
  71. package/dist/failure.js +58 -0
  72. package/dist/finance/command.js +121 -0
  73. package/dist/finance/contracts-command.js +109 -0
  74. package/dist/finance/deal-text.js +34 -0
  75. package/dist/finance/deals-command.js +346 -0
  76. package/dist/finance/finance.js +129 -0
  77. package/dist/finance/lines-command.js +70 -0
  78. package/dist/finance/orders-command.js +94 -0
  79. package/dist/finance/products-command.js +98 -0
  80. package/dist/finance/subscriptions-command.js +152 -0
  81. package/dist/finance/transactions-command.js +136 -0
  82. package/dist/finance/wallets-command.js +105 -0
  83. package/dist/finance/written.js +36 -0
  84. package/dist/findings/command.js +102 -0
  85. package/dist/findings-input.js +23 -0
  86. package/dist/identity.js +20 -0
  87. package/dist/install/postinstall.js +47 -0
  88. package/dist/json-fields.js +48 -0
  89. package/dist/knowledge/business-text.js +19 -0
  90. package/dist/knowledge/command.js +435 -0
  91. package/dist/knowledge/document-context.js +33 -0
  92. package/dist/knowledge/key-documents.js +120 -0
  93. package/dist/knowledge/list-queries.js +20 -0
  94. package/dist/knowledge/meeting-projects-command.js +61 -0
  95. package/dist/knowledge/messenger-sync.js +253 -0
  96. package/dist/knowledge/money-text.js +16 -0
  97. package/dist/knowledge/notes-about.js +81 -0
  98. package/dist/knowledge/organization-delete-command.js +44 -0
  99. package/dist/knowledge/organization-text.js +27 -0
  100. package/dist/knowledge/project-actions-command.js +130 -0
  101. package/dist/knowledge/project-actions.js +104 -0
  102. package/dist/knowledge/project-activity-command.js +70 -0
  103. package/dist/knowledge/project-context.js +101 -0
  104. package/dist/knowledge/project-findings.js +41 -0
  105. package/dist/knowledge/project-gather-command.js +100 -0
  106. package/dist/knowledge/project-status-command.js +129 -0
  107. package/dist/knowledge/project-transfer-command.js +58 -0
  108. package/dist/knowledge/project-transfer.js +107 -0
  109. package/dist/knowledge/relationships-scan.js +116 -0
  110. package/dist/knowledge/relationships.js +115 -0
  111. package/dist/knowledge/roles-command.js +67 -0
  112. package/dist/mail/command.js +20 -0
  113. package/dist/mail/findings-command.js +143 -0
  114. package/dist/mail/findings-duplicates.js +159 -0
  115. package/dist/mail/messages-command.js +77 -0
  116. package/dist/mail/review-command.js +59 -0
  117. package/dist/mail/subscriptions-command.js +84 -0
  118. package/dist/mcp/catalogue.js +159 -0
  119. package/dist/mcp/command.js +125 -0
  120. package/dist/mcp/granted.js +18 -0
  121. package/dist/mcp/permissions.js +61 -0
  122. package/dist/mcp/server.js +128 -0
  123. package/dist/meetings/command.js +31 -0
  124. package/dist/meetings/list-command.js +59 -0
  125. package/dist/meetings/preparation-command.js +42 -0
  126. package/dist/meetings/preparation-text.js +44 -0
  127. package/dist/meetings/preparation.js +50 -0
  128. package/dist/meetings/read.js +32 -0
  129. package/dist/memories/command.js +105 -0
  130. package/dist/memories/memories.js +17 -0
  131. package/dist/memories/memory.js +89 -0
  132. package/dist/memories/sources.js +111 -0
  133. package/dist/mentions/command.js +91 -0
  134. package/dist/migrate/check.js +48 -0
  135. package/dist/migrate/from-memo.js +345 -0
  136. package/dist/migrate/skill.js +35 -0
  137. package/dist/models/command.js +19 -0
  138. package/dist/options.js +35 -0
  139. package/dist/output.js +17 -0
  140. package/dist/page.js +14 -0
  141. package/dist/people/command.js +144 -0
  142. package/dist/people/delete-command.js +53 -0
  143. package/dist/people/doubts-command.js +81 -0
  144. package/dist/people/identities-command.js +188 -0
  145. package/dist/people/identity.js +42 -0
  146. package/dist/people/owner.js +14 -0
  147. package/dist/people/proposal-rows.js +70 -0
  148. package/dist/people/proposals-command.js +248 -0
  149. package/dist/people/review-context.js +108 -0
  150. package/dist/people/subject.js +19 -0
  151. package/dist/program.js +875 -0
  152. package/dist/read-only.js +51 -0
  153. package/dist/reasons.js +368 -0
  154. package/dist/records/import.js +135 -0
  155. package/dist/records/input.js +210 -0
  156. package/dist/records/mapping.js +80 -0
  157. package/dist/records/record-commands.js +125 -0
  158. package/dist/records/sources.js +73 -0
  159. package/dist/refs.js +28 -0
  160. package/dist/review/command.js +171 -0
  161. package/dist/review/kinds.js +44 -0
  162. package/dist/review/review.js +299 -0
  163. package/dist/review/status.js +93 -0
  164. package/dist/rows.js +219 -0
  165. package/dist/run/auto.js +237 -0
  166. package/dist/run/entry.js +62 -0
  167. package/dist/run/files.js +51 -0
  168. package/dist/run/import.js +253 -0
  169. package/dist/run/lock.js +20 -0
  170. package/dist/save-help.js +3 -0
  171. package/dist/schedule/command.js +58 -0
  172. package/dist/schedule/mail-triage-input.js +152 -0
  173. package/dist/schedule/task-triage-input.js +152 -0
  174. package/dist/search/answers.js +176 -0
  175. package/dist/search/command.js +257 -0
  176. package/dist/search/denied.js +9 -0
  177. package/dist/search/embed.js +126 -0
  178. package/dist/search/hits.js +4 -0
  179. package/dist/search/lane-gates.js +76 -0
  180. package/dist/search/notes-text.js +18 -0
  181. package/dist/search/people.js +88 -0
  182. package/dist/search/search.js +306 -0
  183. package/dist/show/command.js +179 -0
  184. package/dist/store/crm-viewer.js +102 -0
  185. package/dist/store/group.js +112 -0
  186. package/dist/store/groups-command.js +136 -0
  187. package/dist/store/guard.js +94 -0
  188. package/dist/store/held.js +21 -0
  189. package/dist/store/info-command.js +37 -0
  190. package/dist/store/scope.js +53 -0
  191. package/dist/store/source-list.js +222 -0
  192. package/dist/store/source-target.js +28 -0
  193. package/dist/tags/command.js +176 -0
  194. package/dist/tasks/command.js +174 -0
  195. package/dist/tasks/context.js +74 -0
  196. package/dist/tasks/list.js +199 -0
  197. package/dist/tasks/proposal-duplicates.js +70 -0
  198. package/dist/tasks/relations-command.js +28 -0
  199. package/dist/tasks/shared.js +105 -0
  200. package/dist/tasks/tasks.js +197 -0
  201. package/dist/templates/command.js +18 -0
  202. package/dist/terminal.js +23 -0
  203. package/dist/update.js +35 -0
  204. package/dist/version.js +2 -0
  205. package/dist/vocabulary/command.js +103 -0
  206. package/dist/vocabulary/inspect.js +23 -0
  207. package/dist/vocabulary/inspection.js +18 -0
  208. package/dist/vocabulary/list.js +18 -0
  209. package/dist/vocabulary/project.js +19 -0
  210. package/dist/wcat.js +3 -0
  211. package/install/postinstall.mjs +9 -0
  212. package/package.json +89 -4
  213. package/scenarios/decision-trail.md +21 -0
  214. package/scenarios/person-brief.md +35 -0
  215. package/scenarios/prepare-meeting.md +17 -0
  216. package/scenarios/project-state.md +26 -0
  217. package/scenarios/set-up.md +18 -0
  218. package/scenarios/start-the-day.md +19 -0
  219. package/skills/mail-triage/SKILL.md +208 -0
  220. package/skills/morning-digest/SKILL.md +147 -0
  221. package/skills/task-triage/SKILL.md +79 -0
  222. package/skills/wcat/SKILL.md +65 -0
  223. package/skills/wcat/topics/mail.md +32 -0
  224. package/skills/wcat/topics/mcp.md +22 -0
  225. package/skills/wcat/topics/meetings.md +37 -0
  226. package/skills/wcat/topics/money.md +52 -0
  227. package/skills/wcat/topics/projects.md +54 -0
  228. package/skills/wcat/topics/proposals.md +113 -0
  229. package/skills/wcat/topics/search.md +85 -0
  230. package/skills/wcat/topics/vocabulary.md +8 -0
@@ -0,0 +1,74 @@
1
+ import { parseLocator, taskView, } from "@wirecat/cli-core";
2
+ import { isNoteReference } from "../knowledge/notes-about.js";
3
+ import { heldMessage } from "../store/held.js";
4
+ export const taskPage = async (store, key, options = {}) => {
5
+ const page = await store.knowledge.taskIds(key, options);
6
+ const items = [];
7
+ for (const id of page.items) {
8
+ const task = await store.tasks.get(id);
9
+ if (!task)
10
+ continue;
11
+ items.push(await taskView(store, key, task));
12
+ }
13
+ return { items, hasMore: page.hasMore };
14
+ };
15
+ export const personTasks = async (store, person, accounts, limit) => {
16
+ const items = [];
17
+ let incomplete = false;
18
+ for (const key of accounts) {
19
+ const { items: assigned } = await store.tasks.find({ assignee: `person:${person.uid}`, status: "open", limit: 500 });
20
+ for (const one of assigned) {
21
+ const task = await store.tasks.get(one.id);
22
+ if (task?.state !== "open" || task.account !== `${key.provider}:${key.account}`)
23
+ continue;
24
+ items.push(await taskView(store, key, task));
25
+ }
26
+ const identities = person.identities.filter((identity) => identity.provider === key.provider && identity.accounts.includes(key.account));
27
+ const noteLinks = await store.notes.links({ to: `person:${person.uid}` });
28
+ const written = await store.notes.notes({ about: `person:${person.uid}`, source: "internal", limit: 500 });
29
+ incomplete ||= written.hasMore;
30
+ const relatedNotes = new Set([
31
+ ...noteLinks
32
+ .filter((link) => link.confirmed && link.kind === "about" && isNoteReference(link.from))
33
+ .map((link) => link.from),
34
+ ...written.items.map((note) => note.ref),
35
+ ]);
36
+ const page = await taskPage(store, key, { state: "open", limit: 500 });
37
+ incomplete ||= page.hasMore;
38
+ for (const task of page.items) {
39
+ if (task.note && relatedNotes.has(task.source))
40
+ items.push(task);
41
+ }
42
+ if (!identities.length)
43
+ continue;
44
+ const ids = new Set(identities.map((identity) => identity.id));
45
+ const chats = (await store.chats.chats(key, { limit: 500 })).items;
46
+ for (const task of page.items) {
47
+ let source;
48
+ try {
49
+ source = parseLocator(task.source);
50
+ }
51
+ catch {
52
+ continue;
53
+ }
54
+ if (source.provider !== key.provider || source.account !== key.account)
55
+ continue;
56
+ const message = await heldMessage(store, key, source.message, source.chat);
57
+ const chat = chats.find((item) => item.id === source.chat);
58
+ const direct = chat?.kind === "dialog" &&
59
+ (ids.has(source.chat) || (await store.roster.members(key, source.chat)).some((member) => ids.has(member.id)));
60
+ if (!direct && (!message?.senderId || !ids.has(message.senderId)))
61
+ continue;
62
+ items.push({
63
+ ...task,
64
+ message: message
65
+ ? { text: message.text.slice(0, 200), senderName: message.senderName, timestamp: message.timestamp }
66
+ : null,
67
+ });
68
+ }
69
+ }
70
+ items.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime() || a.id.localeCompare(b.id));
71
+ const unique = [...new Map(items.map((item) => [item.id, item])).values()];
72
+ return { items: unique.slice(0, limit), hasMore: unique.length > limit || incomplete };
73
+ };
74
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,199 @@
1
+ import { createHash } from "node:crypto";
2
+ import { CliError } from "@wirecat/cli-base";
3
+ import { timezoneOf, walkQuery } from "@wirecat/cli-base/query";
4
+ import { formatReference, isClosedState, listQuery, PROJECT_TASK_FIELDS, typedQuery, } from "@wirecat/cli-core";
5
+ import { listAnswer } from "../answer.js";
6
+ import { accountName } from "../store/source-list.js";
7
+ import { canonicalProject } from "../vocabulary/project.js";
8
+ const OPEN_WORK = "state:(open OR todo OR in_progress)";
9
+ /** Every task, found ones too, when the query names a board field; otherwise an account's tasks, by state and source. */
10
+ export const TASKS_LIST_QUERY = {
11
+ entity: "task",
12
+ backend: "sql",
13
+ fields: [
14
+ ...PROJECT_TASK_FIELDS,
15
+ {
16
+ name: "source",
17
+ type: "ref",
18
+ operators: ["term", "phrase"],
19
+ example: 'source:"msg:telegram/1/7/1"',
20
+ relation: "tasks from this message, note or document; an account's tasks only",
21
+ },
22
+ ],
23
+ defaults: [OPEN_WORK],
24
+ };
25
+ const ACCOUNT_FIELDS = new Set(["state", "source"]);
26
+ /** A task as cli-core's `task` entity; one found in a message also names its account and chat. */
27
+ const taskItem = (task, extra = {}) => {
28
+ const { held, readiness } = extra;
29
+ return {
30
+ ref: task.ref,
31
+ id: task.id,
32
+ key: task.key,
33
+ title: task.title,
34
+ description: task.description,
35
+ kind: task.type,
36
+ state: task.status,
37
+ project: task.project,
38
+ project_key: task.projectKey,
39
+ project_name: task.projectName,
40
+ ...(held
41
+ ? {
42
+ origin: held.origin,
43
+ account: held.account,
44
+ chat: held.sourceKind === "note"
45
+ ? null
46
+ : formatReference({
47
+ type: "chat",
48
+ provider: held.account.split(":")[0] ?? "",
49
+ account: held.account.split(":").slice(1).join(":"),
50
+ chat: held.group,
51
+ }),
52
+ }
53
+ : {}),
54
+ source_message: task.source,
55
+ external_id: task.externalId,
56
+ source_url: task.sourceUrl,
57
+ priority: task.priority,
58
+ priority_label: task.priorityLabel,
59
+ agent: task.agent,
60
+ revision: task.revision,
61
+ parent: task.parent,
62
+ due_at: task.dueAt,
63
+ closed_at: task.closedAt,
64
+ reason: task.reason,
65
+ category: task.category,
66
+ claimed_by: task.claimedBy,
67
+ claimed_until: task.claimedUntil,
68
+ assignments: task.assignments,
69
+ ...(readiness ? { ready: readiness.ready, blocked_by: readiness.blockers } : {}),
70
+ created_by: task.createdBy,
71
+ created_at: task.createdAt,
72
+ updated_at: task.updatedAt,
73
+ };
74
+ };
75
+ /** Each account's first page in the store's order, oldest first, so the first `limit` of them all are among them. */
76
+ const accountTasks = async (store, keys, options) => {
77
+ const pages = await Promise.all(keys.map((key) => store.knowledge.taskIds(key, options)));
78
+ const items = [];
79
+ for (const id of pages.flatMap((page) => page.items)) {
80
+ const held = await store.tasks.get(id);
81
+ if (held)
82
+ items.push(taskItem(await store.tasks.details(id), { held }));
83
+ }
84
+ items.sort((a, b) => a.created_at.localeCompare(b.created_at));
85
+ return listAnswer("tasks list", {
86
+ items: items.slice(0, options.limit),
87
+ limit: options.limit,
88
+ has_more: items.length > options.limit || pages.some((page) => page.hasMore),
89
+ meta: { accounts: keys.map(accountName) },
90
+ });
91
+ };
92
+ const statesOf = (leaves) => new Set(leaves.filter(({ field }) => field === "state").map(({ value }) => value.toLowerCase()));
93
+ /** An account's list reads open as every task not closed yet; todo or in_progress alone needs the board. */
94
+ const onBoard = (leaves, options) => {
95
+ const states = statesOf(leaves);
96
+ return (leaves.some(({ field }) => !ACCOUNT_FIELDS.has(field)) ||
97
+ ((states.has("todo") || states.has("in_progress")) && !states.has("open")) ||
98
+ options.cursor !== undefined ||
99
+ options.sort !== undefined ||
100
+ Boolean(options.desc));
101
+ };
102
+ const accountTerms = (query) => {
103
+ const leaves = query ? walkQuery(query.root) : [];
104
+ const states = statesOf(leaves);
105
+ const closed = [...states].filter(isClosedState);
106
+ if (closed.length > 1 || (closed.length === 1 && states.size > 1))
107
+ throw new CliError("validation_error", "an account's tasks are listed in one state: state:open, done or dismissed");
108
+ const sources = leaves.filter(({ field }) => field === "source").map(({ value }) => value);
109
+ if (sources.length > 1)
110
+ throw new CliError("validation_error", "source: only once here");
111
+ return { state: closed[0] ?? "open", source: sources[0] };
112
+ };
113
+ /** A project named by its key, name or alias reads as `project:<id>`, as tasks add takes it. */
114
+ const resolveProjects = async (store, query) => {
115
+ for (const node of query ? walkQuery(query.root) : [])
116
+ if (node.field === "project" && node.operator !== "wildcard" && node.operator !== "range")
117
+ node.value = await canonicalProject(store, node.value);
118
+ return query;
119
+ };
120
+ const offsetOf = (cursor, key) => {
121
+ if (cursor === undefined)
122
+ return 0;
123
+ let read;
124
+ try {
125
+ read = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
126
+ }
127
+ catch {
128
+ read = undefined;
129
+ }
130
+ if (read?.version !== 1 || read.key !== key || !Number.isSafeInteger(read.offset) || read.offset < 0)
131
+ throw new CliError("validation_error", "the cursor belongs to another query or order; list again without it");
132
+ return read.offset;
133
+ };
134
+ const projectTasks = async (store, typed, query, options) => {
135
+ const { limit, sort = "priority", desc = false } = options;
136
+ const key = createHash("sha256")
137
+ .update(JSON.stringify([typed, sort, desc]))
138
+ .digest("base64url");
139
+ const offset = offsetOf(options.cursor, key);
140
+ const page = await store.tasks.board(query, { limit, offset, sort, descending: desc, zone: timezoneOf() });
141
+ const items = [];
142
+ for (const task of page.items) {
143
+ // Readiness follows blocked-by links between project tasks; a found task has none.
144
+ const held = task.source === null ? undefined : await store.tasks.get(task.id);
145
+ items.push(taskItem(task, held ? { held } : { readiness: await store.tasks.taskReadiness(task.id) }));
146
+ }
147
+ const next = offset + items.length;
148
+ const more = next < page.total;
149
+ return listAnswer("tasks list", {
150
+ items,
151
+ limit,
152
+ has_more: more,
153
+ paging: "cursor",
154
+ ...(more
155
+ ? {
156
+ cursor: Buffer.from(JSON.stringify({ version: 1, key, offset: next })).toString("base64url"),
157
+ }
158
+ : {}),
159
+ total: { value: page.total, relation: "eq" },
160
+ args: { query: typed, ...(options.sort ? { sort } : {}), ...(desc ? { desc: true } : {}) },
161
+ });
162
+ };
163
+ /**
164
+ * Every task, found ones too, when the query names a board field or asks for an order or a page (project:* keeps to
165
+ * the owner's projects); otherwise the tasks of the accounts `accounts` picks. CLI and MCP list through it.
166
+ */
167
+ export const listTasks = async (store, words, options, accounts) => {
168
+ const flag = Array.isArray(words) ? words.findIndex((word) => /^--[a-z]+$/.test(word)) : -1;
169
+ if (flag >= 0) {
170
+ const field = words[flag]?.slice(2) ?? "";
171
+ const value = words[flag + 1] ?? "<value>";
172
+ const fields = TASKS_LIST_QUERY.fields.map(({ name }) => name);
173
+ throw new CliError("validation_error", fields.includes(field)
174
+ ? `tasks list takes ${field} as a query word: wcat tasks list ${field}:${value}`
175
+ : `tasks list has no --${field}; its query words are ${fields.map((name) => `${name}:`).join(", ")}`);
176
+ }
177
+ const typed = typedQuery(words);
178
+ const query = listQuery(typed, TASKS_LIST_QUERY, "tasks list", { defaultField: "text" });
179
+ const leaves = query ? walkQuery(query.root) : [];
180
+ if (onBoard(leaves, options)) {
181
+ if (leaves.some(({ field }) => field === "source"))
182
+ throw new CliError("validation_error", "source: narrows an account's tasks; leave the other fields out");
183
+ return projectTasks(store, typed, (await resolveProjects(store, query)), options);
184
+ }
185
+ const { state, source } = accountTerms(query);
186
+ return accountTasks(store, await accounts(), {
187
+ state,
188
+ limit: options.limit,
189
+ ...(source === undefined ? {} : { sources: [source] }),
190
+ });
191
+ };
192
+ /** The board's pickers: every task, found ones too, when the query names no project:. */
193
+ export const countTasks = async (store, words) => {
194
+ const query = listQuery(typedQuery(words), TASKS_LIST_QUERY, "tasks counts", { defaultField: "text" });
195
+ if (query && walkQuery(query.root).some(({ field }) => field === "source"))
196
+ throw new CliError("validation_error", "source: narrows an account's tasks; tasks counts counts project tasks");
197
+ return store.tasks.boardCounts(await resolveProjects(store, query), { zone: timezoneOf() });
198
+ };
199
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1,70 @@
1
+ import { timezoneOf } from "@wirecat/cli-base/query";
2
+ import { listQuery, typedQuery } from "@wirecat/cli-core";
3
+ import { taskProposals } from "../digest/task-proposals.js";
4
+ import { DUPLICATE_REASON } from "../mail/findings-duplicates.js";
5
+ import { TASKS_LIST_QUERY } from "./list.js";
6
+ const PAGE = 500;
7
+ /** A title as two agents may word it differently only in case, accents, spacing and punctuation. */
8
+ export const titleKey = (title) => title
9
+ .normalize("NFKD")
10
+ .replace(/\p{M}/gu, "")
11
+ .toLowerCase()
12
+ .replace(/[^\p{L}\p{N}]+/gu, " ")
13
+ .trim();
14
+ /** Every open task's title and every waiting task finding's, whatever source proposed it, as key → reference. */
15
+ const knownTitles = async (store, env) => {
16
+ const seen = new Map();
17
+ const query = listQuery(typedQuery("state:(open OR todo OR in_progress)"), TASKS_LIST_QUERY, "actions add", {
18
+ defaultField: "text",
19
+ });
20
+ for (let offset = 0;; offset += PAGE) {
21
+ const page = await store.tasks.board(query, {
22
+ limit: PAGE,
23
+ offset,
24
+ sort: "priority",
25
+ descending: false,
26
+ zone: timezoneOf(),
27
+ });
28
+ for (const task of page.items)
29
+ if (!seen.has(titleKey(task.title)))
30
+ seen.set(titleKey(task.title), task.ref);
31
+ if (page.items.length < PAGE || offset + PAGE >= page.total)
32
+ break;
33
+ }
34
+ for (const batch of (await taskProposals(store, env)).batches)
35
+ for (const part of batch.parts ?? [])
36
+ if (part.kind === "task" && part.outcome === null && !seen.has(titleKey(part.summary)))
37
+ seen.set(titleKey(part.summary), `proposal:${batch.id}`);
38
+ return seen;
39
+ };
40
+ /**
41
+ * The batch without the tasks already open or already waiting for the owner under the same title, from this source
42
+ * or another: a promise made in a chat and repeated by mail is one task, and a run that reads the same messages again
43
+ * stages nothing new. Facts and payments pass through.
44
+ */
45
+ export const withoutTaskDuplicates = async (store, env, input) => {
46
+ if (!input.findings.some((finding) => finding.kind === "task"))
47
+ return { input, duplicates: [] };
48
+ const seen = await knownTitles(store, env);
49
+ // A retry of a staged batch matches its own tasks; the store answers it with that batch, so it passes whole.
50
+ const keys = new Map();
51
+ const ownBatch = async (held) => {
52
+ if (!held.startsWith("proposal:"))
53
+ return false;
54
+ const id = held.slice("proposal:".length);
55
+ if (!keys.has(id))
56
+ keys.set(id, (await store.proposedActions.get(id)).payload.key);
57
+ return keys.get(id) === input.key;
58
+ };
59
+ const duplicates = [];
60
+ const findings = [];
61
+ for (const finding of input.findings) {
62
+ const held = finding.kind === "task" ? seen.get(titleKey(finding.title)) : undefined;
63
+ if (held === undefined || (await ownBatch(held)))
64
+ findings.push(finding);
65
+ else
66
+ duplicates.push({ finding: finding.id, kind: finding.kind, duplicateOf: held, reason: DUPLICATE_REASON });
67
+ }
68
+ return { input: { ...input, findings }, duplicates };
69
+ };
70
+ //# sourceMappingURL=proposal-duplicates.js.map
@@ -0,0 +1,28 @@
1
+ import { annotate } from "@wirecat/cli-base/commands";
2
+ import { LOCAL_READ, LOCAL_WRITE, TASK_RELATION_KINDS, } from "@wirecat/cli-core";
3
+ import { answers, itemAnswer, wholeList } from "../answer.js";
4
+ import { oneOf } from "../options.js";
5
+ export const taskRelationsCommand = (tasks, streams, env) => {
6
+ const { run } = answers(tasks, streams, env);
7
+ const execute = (options, work) => run(options.json, async (store) => itemAnswer(await work(store)));
8
+ for (const operation of ["unlink"]) {
9
+ annotate(tasks.command(operation), { effects: LOCAL_WRITE })
10
+ .description(`${operation} reviewed project task relationships`)
11
+ .argument("<task>", "the task: task:<id> or its id")
12
+ .argument("<other-task>", "the task it relates to: task:<id> or its id")
13
+ .requiredOption("--kind <kind>", TASK_RELATION_KINDS.join(", "), oneOf(TASK_RELATION_KINDS))
14
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
15
+ .action((task, other, options) => execute(options, (store) => store.tasks.unlinkTask(task, other, options.kind, "owner")));
16
+ }
17
+ annotate(tasks.command("links"), { effects: LOCAL_READ })
18
+ .description("a task's links to other tasks")
19
+ .argument("<task>", "the task: task:<id> or its id")
20
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
21
+ .action((task, options) => run(options.json, async (store) => wholeList("tasks links", await store.tasks.taskRelations(task))));
22
+ annotate(tasks.command("status"), { effects: LOCAL_READ })
23
+ .description("whether a task can start, and what it still waits for")
24
+ .argument("<task>", "the task: task:<id> or its id")
25
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
26
+ .action((task, options) => execute(options, (store) => store.tasks.taskReadiness(task)));
27
+ };
28
+ //# sourceMappingURL=relations-command.js.map
@@ -0,0 +1,105 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { openStore, overrideSharedContract, provide, settingsFor, tasksCommand, tasksStatsCommand, } from "@wirecat/cli-core";
3
+ import { Command } from "commander";
4
+ import { APP, STORE_CLIENT } from "../app.js";
5
+ import { decisionPolicy } from "../config.js";
6
+ import { scopedAccounts } from "../store/group.js";
7
+ import { oneAccountOf, sourceOf, sourceOptions, writeAccountOf, writeOptions, } from "../store/source-list.js";
8
+ const SHARED = ["agenda", "update", "show", "link", "claim", "release"];
9
+ /** These change a task and name the account they act as with `--account`; the rest read with `--source`. */
10
+ const WRITES = new Set(["update", "link", "claim", "release"]);
11
+ /** `task:15`, a bare id or a project key: a `tasks link` target that needs no messenger account. */
12
+ const TASKISH = /^(task:.+|\d+|[A-Z][A-Z0-9]*-\d+)$/;
13
+ // wcat's config file is not a messenger profile's, and cli-core's schema refuses its keys: the builders get
14
+ // the defaults, from a config folder of a name nothing writes.
15
+ const settings = settingsFor({ ...APP, appName: "wcat-tasks", envPrefix: "WCAT_TASKS" });
16
+ /** The account the preAction hook resolved from `--source`; cli-core asks for it synchronously. */
17
+ const resolved = new WeakMap();
18
+ /** `stats tasks show` without `--source`: every account the run may read, counted together. */
19
+ const across = new WeakMap();
20
+ const messenger = {
21
+ app: APP,
22
+ provider: "wcat",
23
+ chatArgument: "a stored chat, by its id or title",
24
+ resolveSettings: (flags, options) => settings.resolveSettings(flags, { ...options, needsProfile: false }),
25
+ connect: async () => {
26
+ throw new CliError("validation_error", "wcat reads no messenger: these commands answer from the store");
27
+ },
28
+ accountOf: (command) => resolved.get(command),
29
+ accountsOf: (command) => across.get(command),
30
+ };
31
+ /**
32
+ * Never one picked for the owner: a command that names no account fails, listing the ones the store holds; a
33
+ * statistic reads them all.
34
+ * `tasks link` between two project tasks, and `tasks show`, `update`, `claim` or `release` of one, need none: project
35
+ * tasks belong to no messenger account.
36
+ */
37
+ const requireAccount = (env, warn) => async (_, command) => {
38
+ const writes = WRITES.has(command.name());
39
+ const option = writes ? "--account" : "--source";
40
+ const value = writes
41
+ ? writeAccountOf(command.opts(), warn)
42
+ : sourceOf(command.opts(), warn);
43
+ const [first, ...targets] = command.args;
44
+ const chats = command.opts().chat ?? [];
45
+ const store = await openStore({ env, ...STORE_CLIENT, decisions: decisionPolicy(env) });
46
+ try {
47
+ if (value !== undefined) {
48
+ resolved.set(command, await oneAccountOf(store, env, value, option));
49
+ return;
50
+ }
51
+ // A chat belongs to one account, so `--chat` still asks for `--source`.
52
+ if (isTaskStats(command) && command.opts().chat === undefined) {
53
+ across.set(command, await scopedAccounts(store, env));
54
+ return;
55
+ }
56
+ if (command.name() === "link" &&
57
+ targets.length > 0 &&
58
+ chats.length === 0 &&
59
+ targets.every((one) => TASKISH.test(one)))
60
+ return;
61
+ if (["show", "update", "claim", "release"].includes(command.name()) &&
62
+ first !== undefined &&
63
+ (await store.tasks.projectTask(first)))
64
+ return;
65
+ const listed = (await scopedAccounts(store, env))
66
+ .map((key) => `${option} ${key.provider}:${key.account}`)
67
+ .join("; ");
68
+ throw new CliError("validation_error", `give ${option} — the stored accounts: ${listed || "none yet"}`);
69
+ }
70
+ finally {
71
+ await store.close();
72
+ }
73
+ };
74
+ const isTaskStats = (command) => command.name() === "show" && command.parent?.name() === "tasks" && command.parent.parent?.name() === "stats";
75
+ const scoped = (command, env, warn) => overrideSharedContract(command, "wcat names stored accounts with --source or --account and uses command-local JSON without messenger profiles.", (one) => {
76
+ ;
77
+ (WRITES.has(one.name())
78
+ ? writeOptions(one, "the account it acts as: telegram:<account>, email:<account>, notes:<id>")
79
+ : sourceOptions(one, isTaskStats(one)
80
+ ? "only this account: telegram:<account>, email:<account>, notes:<id>, or group:<name>; every stored account without it"
81
+ : "the account: telegram:<account>, email:<account>, notes:<id>, or group:<name> of one"))
82
+ .option("--json", "print JSON")
83
+ .hook("preAction", requireAccount(env, warn));
84
+ });
85
+ /**
86
+ * `tasks agenda|update|show|link|claim|release` and `stats tasks show` are cli-core's builders, the ones tg and max
87
+ * have, mounted with wcat's own `--source`, or `--account` for the writes, resolved to one account
88
+ * (`Messenger.accountOf`).
89
+ */
90
+ export const sharedTaskCommands = (program, tasks, streams, env) => {
91
+ provide(program, { streams, env });
92
+ const warn = (text) => streams.diagnostic(text);
93
+ const built = tasksCommand(messenger);
94
+ for (const name of SHARED) {
95
+ const command = built.commands.find((one) => one.name() === name);
96
+ if (!command)
97
+ throw new Error(`cli-core's tasks builder has no ${name}`);
98
+ tasks.addCommand(scoped(command, env, warn));
99
+ }
100
+ program
101
+ .command("stats")
102
+ .description("statistics about what the store holds")
103
+ .addCommand(new Command("tasks").description("task statistics").addCommand(scoped(tasksStatsCommand(messenger), env, warn)));
104
+ };
105
+ //# sourceMappingURL=shared.js.map