@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,222 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { entriesOfList, isFolderProvider, } from "@wirecat/cli-core";
3
+ import { memoListContext, scopedAccounts } from "./group.js";
4
+ const MAIL = new Set(["mail", "email"]);
5
+ const MESSENGERS = new Set(["messages", "telegram", "tg", "max", "whatsapp", "wa", "personal", "bots"]);
6
+ const SHAPES = "provider:account (email:personal), a provider (email), a kind (mail, notes, documents) or group:<name>";
7
+ const mailboxOf = async (store, name) => {
8
+ const held = (await store.accounts.accounts()).filter((key) => key.provider === "email");
9
+ const stored = held.find((key) => key.account === name.toLowerCase());
10
+ if (stored)
11
+ return stored;
12
+ const choices = held.map((one) => one.account).join(", ") || "none";
13
+ throw new CliError("not_found", `no mail account "${name}" — stored mail accounts: ${choices}`, {
14
+ reason: "mail.account-unknown",
15
+ account: name,
16
+ });
17
+ };
18
+ /** The list reader names a notes folder and a documents account (Drive's) alike: `notes:<row>`. */
19
+ const filesAccounts = async (store) => {
20
+ const ids = new Set([...(await store.notes.folders()), ...(await store.notes.documentsAccounts())].map(({ id }) => id));
21
+ return (one) => ids.has(String(one.id));
22
+ };
23
+ const messengers = (entry) => new CliError("validation_error", `${entry}: mentions in chats are the messenger's — tg <profile> mentions list`);
24
+ /**
25
+ * cli-core's four `--source` shapes through its own reader. A mailbox not in the store is refused with the ones it
26
+ * holds; notes and documents are wcat's own texts and count even before the store holds an account of them.
27
+ */
28
+ const listedOf = async (store, env, value) => {
29
+ // cli-core's context: `personal` holds every account in no other group, and under WCAT_GROUP_LOCK only the group's.
30
+ const context = await memoListContext(store, env);
31
+ const { held } = context;
32
+ const holdsFiles = await filesAccounts(store);
33
+ const named = async (entry) => {
34
+ const [provider = "", ...rest] = entry.trim().split(":");
35
+ const account = rest.join(":");
36
+ // The store names a notes folder <provider>:<id>, and wcat's own errors show that; the list reader knows notes:<row>.
37
+ // `folder`, every folder's provider before store version 32, is what saved commands still say.
38
+ if (isFolderProvider(provider) && account) {
39
+ const folder = held.find((one) => holdsFiles(one) && one.account === account && (provider === "folder" || one.provider === provider));
40
+ if (folder === undefined)
41
+ throw new CliError("not_found", `no notes folder ${account} in the store`);
42
+ return `notes:${folder.id}`;
43
+ }
44
+ if (!MAIL.has(provider) || !account)
45
+ return entry.trim();
46
+ return `email:${(await mailboxOf(store, account)).account}`;
47
+ };
48
+ const each = (entries) => Promise.all(entries.filter((one) => one.trim()).map(named));
49
+ const groups = Object.fromEntries(await Promise.all(Object.entries(context.groups).map(async ([name, members]) => [name, await each(members)])));
50
+ return entriesOfList((await each(value.split(","))).join(","), {
51
+ ...context,
52
+ groups,
53
+ running: { provider: "email", command: "wcat" },
54
+ });
55
+ };
56
+ /**
57
+ * A group holds accounts of every kind, so a command that reads one kind takes the group's accounts of that kind
58
+ * (`mail` keeps its mailboxes); an entry typed as another kind is still refused.
59
+ */
60
+ export const sourceListOf = async (store, env, value, only) => {
61
+ const listed = await listedOf(store, env, value);
62
+ const typed = new Set(value.split(",").map((item) => item.trim()));
63
+ const list = { mail: [], notes: false, documents: false };
64
+ for (const { entry, accounts } of listed) {
65
+ const word = entry.split(":")[0] ?? "";
66
+ // A group's members come back as entries of their own; only a typed entry of the wrong kind is refused.
67
+ const group = word === "group" || !typed.has(entry.trim());
68
+ if (only !== undefined && group && accounts.every(({ kind }) => kind !== only))
69
+ continue;
70
+ if (MESSENGERS.has(word))
71
+ throw messengers(entry);
72
+ if (word === "notes" || word === "all")
73
+ list.notes = true;
74
+ if (word === "documents" || word === "drive" || word === "all")
75
+ list.documents = true;
76
+ for (const { provider, account, kind } of accounts) {
77
+ if (kind === "mail") {
78
+ if (!list.mail.some((one) => one.account === account))
79
+ list.mail.push({ provider, account });
80
+ }
81
+ else if (group && only !== undefined)
82
+ continue;
83
+ else if (kind === "notes")
84
+ list.notes = true;
85
+ else if (kind === "documents")
86
+ list.documents = true;
87
+ else if (word !== "all" && !group)
88
+ throw messengers(entry);
89
+ }
90
+ }
91
+ return list;
92
+ };
93
+ export const SOURCE_HELP = `which texts, separated by commas: ${SHAPES}`;
94
+ export const MAIL_SOURCES = "email:<address>, email or group:<name>";
95
+ /** The mailboxes a mail-only command reads; a list that names notes or documents is refused, not cut. */
96
+ export const mailboxesOf = async (store, env, value) => {
97
+ const list = await sourceListOf(store, env, value, "mail");
98
+ if (list.notes || list.documents)
99
+ throw new CliError("validation_error", `${value}: this reads mail only — ${MAIL_SOURCES}`);
100
+ if (list.mail.length === 0 && value.split(",").some((entry) => entry.trim().startsWith("group:")))
101
+ throw new CliError("not_found", `${value} holds no mailbox`);
102
+ return list.mail;
103
+ };
104
+ export const ACCOUNTS_HELP = `which accounts, separated by commas: ${SHAPES}`;
105
+ export const MEETING_ACCOUNT_HELP = "the meeting account: provider:account (zoom:me@example.com), or a provider that has one";
106
+ export const MEETING_WRITE_HELP = "the meeting account it acts as: provider:account, such as zoom:me@example.com";
107
+ export const ONE_ACCOUNT_HELP = "the one account: provider:account (telegram:500, email:personal), or a provider or group:<name> that holds only one";
108
+ /** Every stored account a `--source` value names, of any kind, each once. */
109
+ export const accountsOf = async (store, env, value) => {
110
+ const keys = [];
111
+ for (const { accounts } of await listedOf(store, env, value))
112
+ for (const { provider, account } of accounts)
113
+ if (!keys.some((one) => one.provider === provider && one.account === account))
114
+ keys.push({ provider, account });
115
+ return keys;
116
+ };
117
+ const named = (keys) => keys.map((key) => accountName(key)).join(", ");
118
+ const unnamed = async (store, env, option = "--source") => new CliError("validation_error", `give ${option} <provider>:<account> — the store holds ${named(await scopedAccounts(store, env)) || "no account yet"}`);
119
+ /**
120
+ * The store's own key of each account the list reader named: a notes folder is `notes:<row>` to it but `folder:<id>`
121
+ * in the store. Notes written with `notes add` belong to no stored account, so nothing can act as them.
122
+ */
123
+ const storedKeysOf = async (store, env, value) => {
124
+ const held = await store.accounts.storedAccounts();
125
+ const holdsFiles = await filesAccounts(store);
126
+ const keys = [];
127
+ for (const key of await accountsOf(store, env, value)) {
128
+ const folder = key.provider === "notes" ? held.find((one) => holdsFiles(one) && String(one.id) === key.account) : null;
129
+ if (folder === undefined)
130
+ continue;
131
+ const stored = folder ? { provider: folder.provider, account: folder.account } : key;
132
+ if (!keys.some((one) => one.provider === stored.provider && one.account === stored.account))
133
+ keys.push(stored);
134
+ }
135
+ return keys;
136
+ };
137
+ const noStoredAccount = (value) => new CliError("not_found", `${value} names no stored account; notes written with files notes add belong to none — name a notes folder ` +
138
+ "(notes:<id>), a mailbox or a messenger account");
139
+ /** One account, and the owner names it: none or several is an error listing the choices. */
140
+ export const oneAccountOf = async (store, env, value, option = "--source") => {
141
+ if (value === undefined)
142
+ throw await unnamed(store, env, option);
143
+ const keys = await storedKeysOf(store, env, value);
144
+ if (option === "--account" && !value.includes(":") && keys.length === 1)
145
+ throw new CliError("validation_error", `give --account ${named(keys)}; a provider alone does not name an acting account`);
146
+ if (keys.length === 1)
147
+ return keys[0];
148
+ if (keys.length === 0)
149
+ throw noStoredAccount(value);
150
+ throw new CliError("validation_error", `${value} names ${keys.length} accounts; give one: ${named(keys)}`);
151
+ };
152
+ /**
153
+ * The stored accounts a project gather reads, as context sources: messenger accounts, mailboxes and imported notes
154
+ * folders and meeting accounts. Your own internal notes have no context reader yet; `all` reports them as left out,
155
+ * an entry that names only them is refused.
156
+ */
157
+ export const contextSourcesOf = async (store, env, value) => {
158
+ const held = await store.accounts.storedAccounts();
159
+ const holdsFiles = await filesAccounts(store);
160
+ const sources = [];
161
+ const unread = [];
162
+ for (const { entry, accounts } of await listedOf(store, env, value)) {
163
+ let read = 0;
164
+ for (const { provider, account, kind } of accounts) {
165
+ const stored = kind === "notes"
166
+ ? held.find((one) => holdsFiles(one) && String(one.id) === account)
167
+ : kind === "messages" || kind === "mail" || kind === "meetings"
168
+ ? held.find((one) => one.provider === provider && one.account === account)
169
+ : undefined;
170
+ if (stored === undefined) {
171
+ unread.push(kind === undefined
172
+ ? { source: `${provider}:${account}`, kind: "unknown", reason: "unknown-provider" }
173
+ : { source: `${provider}:${account}`, kind });
174
+ continue;
175
+ }
176
+ read++;
177
+ const source = {
178
+ kind: kind === "notes" ? "document" : kind === "mail" ? "mail" : kind === "meetings" ? "meeting" : "message",
179
+ accountId: stored.id,
180
+ provider: stored.provider,
181
+ account: stored.account,
182
+ };
183
+ if (!sources.some((one) => one.accountId === source.accountId && one.kind === source.kind))
184
+ sources.push(source);
185
+ }
186
+ if (read === 0 && entry.trim() !== "all")
187
+ throw new CliError("validation_error", `${entry}: a gather reads messenger accounts, mailboxes, meeting transcripts and imported notes folders (notes:<id>)`, { param: "source" });
188
+ }
189
+ return { sources, unread, scope: value.trim() === "all" ? "all-connected" : "explicit" };
190
+ };
191
+ export const sourceOptions = (command, help) => command.option("--source <accounts>", help);
192
+ export const sourceOf = (options, _warn) => options.source;
193
+ /** The one account `--source` names. */
194
+ export const theAccount = (store, env, options, warn) => oneAccountOf(store, env, sourceOf(options, warn));
195
+ /** Every account `--source` names; none named is every stored account. */
196
+ export const theAccounts = async (store, env, options, warn) => {
197
+ const value = sourceOf(options, warn);
198
+ if (value === undefined)
199
+ return scopedAccounts(store, env);
200
+ const keys = await storedKeysOf(store, env, value);
201
+ if (keys.length === 0)
202
+ throw noStoredAccount(value);
203
+ return keys;
204
+ };
205
+ /** Every account `--source` names, and the owner names them: none given is an error listing the choices. */
206
+ export const namedAccounts = async (store, env, options, warn) => {
207
+ if (sourceOf(options, warn) === undefined)
208
+ throw await unnamed(store, env);
209
+ return theAccounts(store, env, options, warn);
210
+ };
211
+ export const accountName = ({ provider, account }) => `${provider}:${account}`;
212
+ export const WRITE_HELP = "the account it acts as: provider:account, such as telegram:1 or email:personal";
213
+ export const writeOptions = (command, help = WRITE_HELP) => command.option("--account <account>", help);
214
+ export const writeAccountOf = (options, _warn) => {
215
+ const { account } = options;
216
+ if (account !== undefined && (!account.includes(":") || account.startsWith("group:")))
217
+ throw new CliError("validation_error", `--account takes provider:account, such as telegram:${account}`);
218
+ return account;
219
+ };
220
+ /** The one account a write acts as. */
221
+ export const writeAccount = (store, env, options, warn) => oneAccountOf(store, env, writeAccountOf(options, warn), "--account");
222
+ //# sourceMappingURL=source-list.js.map
@@ -0,0 +1,28 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { formatLocator, parseLocator } from "@wirecat/cli-core";
3
+ export const sourceTarget = ({ message, chat, provider, account }) => {
4
+ if (message !== undefined) {
5
+ if (chat !== undefined || provider !== undefined || account !== undefined)
6
+ throw new CliError("validation_error", "a message locator names its account and chat — use --message alone");
7
+ let parsed;
8
+ try {
9
+ parsed = parseLocator(message);
10
+ }
11
+ catch (error) {
12
+ if (error instanceof URIError)
13
+ throw new CliError("validation_error", "invalid percent encoding in the locator");
14
+ throw error;
15
+ }
16
+ return {
17
+ key: { provider: parsed.provider, account: parsed.account },
18
+ target: { type: "message", chatId: parsed.chat, messageId: parsed.message },
19
+ locator: formatLocator(parsed),
20
+ };
21
+ }
22
+ if (chat === undefined || provider === undefined || account === undefined)
23
+ throw new CliError("validation_error", "name --message <locator>, or --chat <chat> with --provider <provider> and --account <account>");
24
+ if (!chat.trim() || !provider.trim() || !account.trim())
25
+ throw new CliError("validation_error", "the provider, account and chat id must not be empty");
26
+ return { key: { provider, account }, target: { type: "chat", chatId: chat } };
27
+ };
28
+ //# sourceMappingURL=source-target.js.map
@@ -0,0 +1,176 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { annotate } from "@wirecat/cli-base/commands";
3
+ import { formatReference, LOCAL_READ, LOCAL_WRITE, normalizeTag, notLocalPaths, queryTerms, termField, withQuery, } from "@wirecat/cli-core";
4
+ import { answers, itemAnswer, listAnswer, withStore } from "../answer.js";
5
+ import { positive } from "../options.js";
6
+ import { scopedAccounts } from "../store/group.js";
7
+ import { heldMessage } from "../store/held.js";
8
+ import { selectTarget } from "../store/scope.js";
9
+ import { ACCOUNTS_HELP, accountName, accountsOf, oneAccountOf, sourceOf, sourceOptions, WRITE_HELP, writeAccountOf, writeOptions, } from "../store/source-list.js";
10
+ import { sourceTarget } from "../store/source-target.js";
11
+ import { canonicalProject } from "../vocabulary/project.js";
12
+ const OWNED = ["note", "document", "person", "organization", "project", "task", "meeting", "folder"];
13
+ const TYPES = ["chat", "message", "contact", ...OWNED];
14
+ /** wcat's rows carry labels on notes, people and folders too, beyond cli-core's `tagging` entity. */
15
+ const TAG_QUERY = {
16
+ entity: "source_tag",
17
+ backend: "native",
18
+ fields: [termField("tag", "kw", "tag:work"), termField("type", "enum", "type:note", { values: TYPES })],
19
+ };
20
+ const reference = ({ provider, account }, chat) => provider && account ? formatReference({ type: "chat", provider, account, chat }) : chat;
21
+ const targetOptions = (command) => writeOptions(notLocalPaths(command, "folder", "subfolder")
22
+ .argument("<tag...>", "one or more tags: 1–32 letters a–z, digits or hyphens; case is ignored")
23
+ .option("--message <message>", "a stored email or message's full msg: locator")
24
+ .option("--note <reference>", "a note: note:<id>, a file in a notes folder: document:<id>; a bare id is a note")
25
+ .option("--chat <chat>", "a stored mail thread or chat's exact id; requires --account")
26
+ .option("--task <id>", "label a task")
27
+ .option("--contact <person>", "label a contact identity, with --account")
28
+ .option("--person <uid>", "label a unified person")
29
+ .option("--organization <organization>", "label an organization: its id or organization:<id>")
30
+ .option("--project <project>", "label a project: its key or project:<id>")
31
+ .option("--meeting <id>", "label a meeting by its store id, with --account")
32
+ .option("--folder <folder>", "label a notes folder by its id or path, or with --subfolder one subfolder: every note under it")
33
+ .option("--subfolder <path>", "the subfolder inside --folder"), `the account of --chat, --contact or --meeting: ${WRITE_HELP}`).option("--json", "print JSON; --json=id,title keeps only those fields");
34
+ const listTags = async (store, options) => {
35
+ const items = [];
36
+ for (const key of options.keys) {
37
+ const types = options.type === undefined
38
+ ? ["chat", "message", "contact"]
39
+ : options.type === "chat" || options.type === "message" || options.type === "contact"
40
+ ? [options.type]
41
+ : [];
42
+ for (const type of types) {
43
+ const found = await store.tags.tags(key, { type, ...(options.tag === undefined ? {} : { tag: options.tag }) });
44
+ for (const row of found) {
45
+ if (row.type === "contact" &&
46
+ !(await store.knowledge.tags(key, { type: "contact", id: row.personId })).includes(row.tag))
47
+ continue;
48
+ if (row.type === "message" &&
49
+ (await heldMessage(store, key, row.messageId, row.chatId)) === undefined)
50
+ continue;
51
+ items.push({ ...key, ...row });
52
+ if (items.length > options.limit)
53
+ return { items: items.slice(0, options.limit), hasMore: true };
54
+ }
55
+ }
56
+ }
57
+ return { items, hasMore: false };
58
+ };
59
+ export const tagsCommand = (program, streams, env) => {
60
+ const tags = program.command("tags").description("your labels on stored sources and folders or threads");
61
+ const { print } = answers(program, streams, env);
62
+ const warn = (text) => streams.diagnostic(text);
63
+ const mutate = async (operation, given, { account, ...options }) => {
64
+ const value = writeAccountOf({ account }, warn);
65
+ const scoped = async (store) => value === undefined ? {} : oneAccountOf(store, env, value, "--account");
66
+ const target = options.note !== undefined
67
+ ? options.note.startsWith("document:")
68
+ ? { type: "document", id: options.note.slice("document:".length) }
69
+ : { type: "note", id: options.note.replace(/^note:/, "") }
70
+ : options.person !== undefined
71
+ ? { type: "person", id: options.person.replace(/^person:/, "") }
72
+ : options.organization !== undefined
73
+ ? { type: "organization", id: options.organization.replace(/^organization:/, "") }
74
+ : options.project !== undefined
75
+ ? { type: "project", id: options.project }
76
+ : options.task !== undefined
77
+ ? { type: "task", id: options.task.replace(/^task:/, "") }
78
+ : options.folder !== undefined
79
+ ? { type: "folder", id: options.folder, path: options.subfolder ?? null }
80
+ : undefined;
81
+ if (options.subfolder !== undefined && options.folder === undefined)
82
+ throw new CliError("validation_error", "--subfolder names a subfolder of --folder");
83
+ if (target !== undefined) {
84
+ await withStore(env, async (store) => {
85
+ if (target.type === "project")
86
+ target.id = (await canonicalProject(store, target.id)).slice("project:".length);
87
+ if (target.type === "folder") {
88
+ // A folder's place on disk is the files CLI's, so a folder is named here by the id the store holds.
89
+ if (!(await store.notes.folders()).some(({ id }) => id === target.id))
90
+ throw new CliError("not_found", `no folder of notes ${target.id}; files folders list names their ids`, {
91
+ reason: "folder.not-found",
92
+ });
93
+ }
94
+ const changed = await (operation === "add" ? store.knowledge.addTags : store.knowledge.removeTags)(null, target, given);
95
+ print(options.json, itemAnswer({ target, [operation === "add" ? "added" : "removed"]: changed }), `${operation}: ${changed.join(", ") || "no labels changed"}`);
96
+ });
97
+ return;
98
+ }
99
+ if (options.contact !== undefined || options.meeting !== undefined) {
100
+ await withStore(env, async (store) => {
101
+ const { key, target } = await selectTarget(store, env, { ...options, ...(await scoped(store)) });
102
+ const changed = await (operation === "add" ? store.knowledge.addTags : store.knowledge.removeTags)(key, target, given);
103
+ print(options.json, itemAnswer({ ...key, target, [operation === "add" ? "added" : "removed"]: changed }), `${operation}: ${changed.join(", ") || "no labels changed"}`);
104
+ });
105
+ return;
106
+ }
107
+ if (options.message !== undefined && value !== undefined)
108
+ throw new CliError("validation_error", "a message locator names its account and chat — use --message alone");
109
+ const labels = [...new Set(given.map(normalizeTag))];
110
+ await withStore(env, async (store) => {
111
+ const selected = sourceTarget({ ...options, ...(await scoped(store)) });
112
+ const changed = await (operation === "add" ? store.tags.addTags : store.tags.removeTags)(selected.key, selected.target, labels);
113
+ const target = { ...selected.target, ...(selected.locator === undefined ? {} : { locator: selected.locator }) };
114
+ const answer = {
115
+ ...selected.key,
116
+ target,
117
+ [operation === "add" ? "added" : "removed"]: changed,
118
+ unchanged: labels.filter((tag) => !changed.includes(tag)),
119
+ };
120
+ const name = selected.locator ?? reference(selected.key, selected.target.chatId);
121
+ print(options.json, itemAnswer(answer), `${name}: ${changed.length ? `${operation}: ${changed.join(", ")}` : "no tags changed"}`);
122
+ });
123
+ };
124
+ for (const operation of ["add", "remove"])
125
+ targetOptions(annotate(tags.command(operation), { effects: LOCAL_WRITE }).description(operation === "add" ? "put labels on one source" : "remove labels from one source")).action((given, options) => mutate(operation, given, options));
126
+ const tagsList = withQuery(annotate(tags.command("list"), { effects: LOCAL_READ, output: { entity: "source_tag" } }).description("list source labels, of every account or of the ones --source names"), TAG_QUERY);
127
+ sourceOptions(tagsList, `only these accounts (default: every one): ${ACCOUNTS_HELP}`)
128
+ .option("--limit <n>", "most labels to show", positive, 100)
129
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
130
+ .action(async (words, given) => {
131
+ const terms = queryTerms(words, TAG_QUERY, "tags list");
132
+ const tag = terms.get("tag");
133
+ const value = sourceOf(given, warn);
134
+ const options = {
135
+ limit: given.limit,
136
+ ...(given.json === undefined ? {} : { json: given.json }),
137
+ ...(tag === undefined ? {} : { tag: normalizeTag(tag) }),
138
+ ...(terms.has("type") ? { type: terms.get("type") } : {}),
139
+ };
140
+ await withStore(env, async (store) => {
141
+ const keys = value === undefined ? await scopedAccounts(store, env) : await accountsOf(store, env, value);
142
+ const answer = await listTags(store, { ...options, keys });
143
+ const owned = options.type === undefined || OWNED.includes(options.type)
144
+ ? await store.knowledge.labelled(null, {
145
+ ...(options.tag === undefined ? {} : { tag: options.tag }),
146
+ ...(options.type === undefined ? {} : { type: options.type }),
147
+ limit: Math.min(options.limit, 500),
148
+ })
149
+ : { items: [], hasMore: false };
150
+ const knowledge = owned.items;
151
+ answer.hasMore ||= owned.hasMore;
152
+ const lines = answer.items.map((row) => `${row.tag} ${row.type} ${row.locator ??
153
+ (row.type === "contact" ? `${row.provider}:${row.personId ?? ""}` : reference(row, row.chatId ?? ""))}`);
154
+ if (answer.hasMore)
155
+ lines.push("More labels match; raise --limit to see them.");
156
+ answer.hasMore ||= knowledge.length > options.limit;
157
+ print(options.json, listAnswer("tags list", {
158
+ items: [
159
+ ...answer.items,
160
+ ...knowledge
161
+ .slice(0, options.limit)
162
+ .flatMap(({ target, labels }) => labels.map(({ tag, origin }) => ({ ...target, tag, origin }))),
163
+ ],
164
+ limit: options.limit,
165
+ has_more: answer.hasMore,
166
+ meta: { accounts: keys.map(accountName) },
167
+ }), [
168
+ ...lines,
169
+ ...knowledge
170
+ .slice(0, options.limit)
171
+ .map((item) => `${item.labels.map(({ tag, origin }) => (origin === "file" ? `${tag} (file)` : tag)).join(", ")} ${item.target.type} ${item.target.type === "message" ? item.target.locator : `${item.target.type}:${item.target.id}`}`),
172
+ ].join("\n") || "No source tags.");
173
+ });
174
+ });
175
+ };
176
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1,174 @@
1
+ import { annotate } from "@wirecat/cli-base/commands";
2
+ import { closedStateOf, dateOrNone, LOCAL_READ, LOCAL_WRITE, listQuery, overrideSharedContract, PRIORITY_LABELS, priorityOf, TASK_ROLES, TASK_SORTS, TASK_STATES, TASK_TYPES, typedQuery, WORK_TASK_TYPES, withQuery, } from "@wirecat/cli-core";
3
+ import { InvalidArgumentError } from "commander";
4
+ import { answers, itemAnswer, wholeList, withStore } from "../answer.js";
5
+ import { oneOf, positive, readScope, writeScope } from "../options.js";
6
+ import { withOwner } from "../people/owner.js";
7
+ import { scopeOf } from "../store/scope.js";
8
+ import { ACCOUNTS_HELP, theAccounts } from "../store/source-list.js";
9
+ import { countTasks, listTasks, TASKS_LIST_QUERY } from "./list.js";
10
+ import { taskRelationsCommand } from "./relations-command.js";
11
+ import { sharedTaskCommands } from "./shared.js";
12
+ import { addTask, assignTask, closeTask, commentTask, moveTask, taskHistory, unassignTask, updateTask, } from "./tasks.js";
13
+ const revisionOf = (value) => {
14
+ const number = Number(value);
15
+ if (!Number.isSafeInteger(number) || number < 1)
16
+ throw new InvalidArgumentError("the revision a read gave");
17
+ return number;
18
+ };
19
+ const REVISION_HELP = "refuse the write unless the task is still at this revision (conflict, task.stale, exit 15)";
20
+ const fieldOptions = (command) => command
21
+ .option("--title <title>", "one line saying what is to be done")
22
+ .option("--priority <n>", `${PRIORITY_LABELS.join(", ")}; 0 (urgent) … 4 (low) still read as before`, priorityOf)
23
+ .option("--parent <id>", "the parent task, in the same project")
24
+ .option("--description <text>", "the detail, in Markdown");
25
+ export const tasksCommand = (program, streams, env) => {
26
+ const group = program.command("tasks").description("open work linked to stored messages, documents and emails");
27
+ taskRelationsCommand(group, streams, env);
28
+ const { print } = answers(program, streams, env);
29
+ const warn = (text) => streams.diagnostic(text);
30
+ fieldOptions(writeScope(annotate(group.command("add"), { effects: LOCAL_WRITE })))
31
+ .description("add a task from a message, note or document, or one of your own in a project")
32
+ .argument("[source]", "msg: source locator, note:<id> or document:<id>; leave out for a task in a project")
33
+ .option("--type <type>", "question, request (default), mention or promise from a source; bug, feature or chore (default) in a project", oneOf(TASK_TYPES))
34
+ .option("--project <project>", "a task without a source: the project's key or project:<id>")
35
+ .option("--assignee <person...>", "who does it: a person's UID")
36
+ .option("--due <time>", "a project task: when it must be done, an ISO 8601 time or 2h, 3d from now", dateOrNone("--due"))
37
+ .option("--status <state>", `a project task: its state from the start, ${TASK_STATES.join(", ")}`, oneOf(TASK_STATES))
38
+ .option("--agent <agent>", "a project task: the agent working on it, apart from its assignees")
39
+ .option("--external-id <service:id>", "its id in an outside service, such as avito:4512345678 for an Avito chat")
40
+ .option("--source-url <url>", "the http or https page it is about, such as the Avito ad or conversation")
41
+ .option("--into <id>", "link the source to this task instead of opening one that may be the same job")
42
+ .option("--new", "open the task even when one like it is open or was closed in the last 14 days")
43
+ .action(async (source, options) => {
44
+ await withStore(env, async (store) => {
45
+ const scope = await scopeOf(store, env, options, warn);
46
+ print(options.json, itemAnswer(await addTask(store, env, source, { ...options, ...scope })));
47
+ });
48
+ });
49
+ withQuery(readScope(annotate(group.command("list"), { effects: LOCAL_READ }).description("tasks of the --source accounts, open by default; a board field lists every task"), ACCOUNTS_HELP), TASKS_LIST_QUERY)
50
+ .option("--limit <n>", "most tasks, at most 500 for a project's", positive, 100)
51
+ .option("--sort <field>", `every task: ${TASK_SORTS.join(", ")} (default priority)`, oneOf(TASK_SORTS))
52
+ .option("--desc", "the --sort order reversed")
53
+ .option("--cursor <cursor>", "the next page of every task, from page.next_cursor, with the same query and order")
54
+ .action(async (words, options) => {
55
+ await withStore(env, async (store) => {
56
+ print(options.json, await listTasks(store, words, options, () => theAccounts(store, env, options, warn)));
57
+ });
58
+ });
59
+ withQuery(annotate(group.command("counts"), { effects: LOCAL_READ, output: { entity: "task_counts" } }).description("how many tasks match, found ones too, by project, assignee, priority and state"), TASKS_LIST_QUERY)
60
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
61
+ .action(async (words, options) => {
62
+ await withStore(env, async (store) => {
63
+ print(options.json, itemAnswer(await countTasks(store, words)));
64
+ });
65
+ });
66
+ const comments = group.command("comments").description("what people and agents wrote on a task");
67
+ annotate(comments.command("add"), { effects: LOCAL_WRITE, literal_after_dashes: true })
68
+ .description("comment on a task, in your name or the agent's that runs wcat")
69
+ .argument("<id>", "the task's id or key")
70
+ .argument("<text...>", "what to say, in Markdown")
71
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
72
+ .action(async (id, words, options) => {
73
+ await withStore(env, async (store) => {
74
+ print(options.json, itemAnswer(await commentTask(store, env, id, words.join(" "))));
75
+ });
76
+ });
77
+ const commentQuery = { entity: "task_comment", backend: "native", fields: [] };
78
+ withQuery(annotate(comments.command("list"), { effects: LOCAL_READ })
79
+ .description("a task's comments, oldest first, with who wrote each and when")
80
+ .argument("<id>", "the task's id or key"), commentQuery)
81
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
82
+ .action(async (id, words, options) => {
83
+ listQuery(typedQuery(words), commentQuery, "tasks comments list");
84
+ await withStore(env, async (store) => {
85
+ print(options.json, wholeList("tasks comments list", await store.tasks.comments(id)));
86
+ });
87
+ });
88
+ annotate(group.command("history"), { effects: LOCAL_READ, output: { entity: "task_event" } })
89
+ .description("who changed a task, what and when, oldest first")
90
+ .argument("<id>", "the task's id or key")
91
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
92
+ .action(async (id, options) => {
93
+ await withStore(env, async (store) => {
94
+ print(options.json, wholeList("tasks history", await taskHistory(store, id)));
95
+ });
96
+ });
97
+ writeScope(annotate(group.command("close"), { effects: LOCAL_WRITE })
98
+ .description("close a task as done or dismissed")
99
+ .argument("<id>", "the task's id"))
100
+ .option("--as <state>", "done or dismissed", closedStateOf, "done")
101
+ .option("--reason <text>", "why it is closed")
102
+ .option("--revision <n>", REVISION_HELP, revisionOf)
103
+ .action(async (id, options) => {
104
+ await withStore(env, async (store) => {
105
+ const scope = await scopeOf(store, env, options, warn);
106
+ print(options.json, itemAnswer(await closeTask(store, env, id, { ...options, ...scope })));
107
+ });
108
+ });
109
+ annotate(group.command("assign"), { effects: LOCAL_WRITE })
110
+ .description("name who works on a task, or with --clear take them off it")
111
+ .argument("<id>", "the task's id or key")
112
+ .argument("<person>", "explicit canonical person UID")
113
+ .option("--role <role>", TASK_ROLES.join(", "), oneOf(TASK_ROLES), "assignee")
114
+ .option("--clear", "take the person off the task in that role, instead of adding them")
115
+ .option("--revision <n>", REVISION_HELP, revisionOf)
116
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
117
+ .action(async (id, person, options) => {
118
+ await withStore(env, async (store) => {
119
+ const who = await withOwner(store, person);
120
+ const change = options.clear ? unassignTask : assignTask;
121
+ print(options.json, itemAnswer(await change(store, env, id, who, options.role, options.revision)));
122
+ });
123
+ });
124
+ annotate(group.command("move"), { effects: LOCAL_WRITE, output: { entity: "task_move" } })
125
+ .summary("put a project task before or after another in its board column")
126
+ .description("put a project task before or after another in its board column: it takes a priority between them, " +
127
+ "and the answer says when its label changed; beside a task in another column it moves into that column")
128
+ .argument("<id>", "the task's id or key")
129
+ .option("--status <state>", `move it to this column too: ${TASK_STATES.join(", ")}; with --before or --after it must be that task's column`, oneOf(TASK_STATES))
130
+ .option("--before <id>", "the task it goes just above")
131
+ .option("--after <id>", "the task it goes just below")
132
+ .option("--revision <n>", REVISION_HELP, revisionOf)
133
+ .option("--json", "print JSON; --json=id,title keeps only those fields")
134
+ .action(async (id, options) => {
135
+ await withStore(env, async (store) => {
136
+ print(options.json, itemAnswer(await moveTask(store, env, id, options)));
137
+ });
138
+ });
139
+ sharedTaskCommands(program, group, streams, env);
140
+ const sharedUpdate = group.commands.find((command) => command.name() === "update");
141
+ if (!sharedUpdate)
142
+ throw new Error("shared task update is missing");
143
+ overrideSharedContract(sharedUpdate, "wcat preserves source-account checks and bare person UIDs; a found task takes priority, status and agent too.", (command) => {
144
+ command
145
+ .description("update stored tasks: source edits name --account; a found task takes priority, status, agent and --project")
146
+ .option("--agent <agent>", "the agent working on the task, apart from its assignees; none clears it")
147
+ .option("--project <project>", "move the task, a found one too, to a project, by key or project:<id>; it and its subtasks take new keys " +
148
+ "there, and the old keys still find them. A subtask moves alone only with --parent none")
149
+ .option("--type <type>", `${WORK_TASK_TYPES.join(", ")} in a project; a found task keeps a message kind until it moves into one`, oneOf(TASK_TYPES))
150
+ .option("--revision <n>", REVISION_HELP, revisionOf)
151
+ .option("--status <state>", `the task's state: ${TASK_STATES.join(", ")}; a closed one reopens`, oneOf(TASK_STATES));
152
+ const description = command.options.find((option) => option.long === "--description");
153
+ if (description)
154
+ description.description = "the detail, in Markdown; none clears it";
155
+ command.action(async (id, given) => {
156
+ const raw = given;
157
+ const options = {
158
+ ...given,
159
+ ...(typeof given.description === "string" && given.description.trim().toLowerCase() === "none"
160
+ ? { description: null }
161
+ : {}),
162
+ priority: raw.priority === "none" ? null : raw.priority,
163
+ parent: raw.parent === null || raw.parent === "none" ? null : raw.parent,
164
+ due: raw.due === "none" ? null : raw.due,
165
+ remindTime: raw.remindTime === "none" ? null : raw.remindTime,
166
+ };
167
+ await withStore(env, async (store) => {
168
+ const scope = await scopeOf(store, env, options, warn);
169
+ print(options.json, itemAnswer(await updateTask(store, env, id, { ...options, ...scope })));
170
+ });
171
+ });
172
+ });
173
+ };
174
+ //# sourceMappingURL=command.js.map