@wirecat/cli-core 0.550.0 → 0.551.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 (128) hide show
  1. package/CHANGELOG.md +176 -0
  2. package/THIRD_PARTY_NOTICES +41 -0
  3. package/dist/calendar/ics.d.ts +1 -1
  4. package/dist/calendar/ics.js +5 -2
  5. package/dist/calendar/windows-zones.generated.d.ts +1 -0
  6. package/dist/calendar/windows-zones.generated.js +146 -0
  7. package/dist/cli/compact.js +2 -0
  8. package/dist/cli/index.d.ts +3 -0
  9. package/dist/cli/index.js +3 -0
  10. package/dist/cli/meeting-findings-input.js +4 -3
  11. package/dist/cli/messenger/backfill-command.js +28 -1
  12. package/dist/cli/messenger/context.js +1 -0
  13. package/dist/cli/messenger/history-gaps.js +4 -4
  14. package/dist/cli/messenger/mcp-command.js +1 -0
  15. package/dist/cli/messenger/messages-delete-command.js +7 -8
  16. package/dist/cli/messenger/projects-command.js +47 -2
  17. package/dist/cli/payment-query.d.ts +8 -0
  18. package/dist/cli/payment-query.js +27 -0
  19. package/dist/cli/project-status-rows.d.ts +8 -0
  20. package/dist/cli/project-status-rows.js +102 -0
  21. package/dist/cli/project-status.d.ts +132 -0
  22. package/dist/cli/project-status.js +248 -0
  23. package/dist/cli/steps.js +4 -1
  24. package/dist/domain/knowledge.d.ts +1 -1
  25. package/dist/domain/knowledge.js +1 -1
  26. package/dist/domain/status-words.d.ts +3 -0
  27. package/dist/domain/status-words.js +44 -0
  28. package/dist/entities/fact.d.ts +12 -1
  29. package/dist/entities/fact.js +13 -0
  30. package/dist/entities/index.d.ts +18 -2
  31. package/dist/entities/meeting-findings.d.ts +1 -1
  32. package/dist/entities/message-transfer.d.ts +16 -0
  33. package/dist/entities/message-transfer.js +6 -0
  34. package/dist/mcp/app-server.js +1 -0
  35. package/dist/mcp/http/oauth.d.ts +2 -1
  36. package/dist/mcp/http/oauth.js +2 -2
  37. package/dist/mcp/http/serve.d.ts +2 -0
  38. package/dist/mcp/http/serve.js +2 -1
  39. package/dist/mcp/server.js +1 -0
  40. package/dist/mcp/surface.js +1 -1
  41. package/dist/meetings/findings-rules.d.ts +14 -3
  42. package/dist/meetings/findings-rules.js +16 -2
  43. package/dist/meetings/index.d.ts +3 -2
  44. package/dist/meetings/index.js +2 -1
  45. package/dist/meetings/meeting-context.d.ts +2 -3
  46. package/dist/meetings/meeting-context.js +3 -4
  47. package/dist/meetings/payment.d.ts +27 -0
  48. package/dist/meetings/payment.js +81 -0
  49. package/dist/services/archive.d.ts +13 -0
  50. package/dist/services/archive.js +56 -5
  51. package/dist/services/deps.d.ts +3 -0
  52. package/dist/services/history-limits.d.ts +2 -0
  53. package/dist/services/index.d.ts +4 -1
  54. package/dist/services/index.js +4 -1
  55. package/dist/services/job-query.d.ts +5 -2
  56. package/dist/services/job-query.js +5 -2
  57. package/dist/services/link-scorers/alias-hits.d.ts +7 -0
  58. package/dist/services/link-scorers/alias-hits.js +54 -0
  59. package/dist/services/link-scorers/chat-senders.d.ts +6 -0
  60. package/dist/services/link-scorers/chat-senders.js +56 -0
  61. package/dist/services/link-scorers/chat-title.d.ts +6 -0
  62. package/dist/services/link-scorers/chat-title.js +44 -0
  63. package/dist/services/link-scorers/email-domain.d.ts +6 -0
  64. package/dist/services/link-scorers/email-domain.js +64 -0
  65. package/dist/services/link-scorers/index.d.ts +9 -0
  66. package/dist/services/link-scorers/index.js +8 -0
  67. package/dist/services/link-scorers/mail-thread.d.ts +3 -0
  68. package/dist/services/link-scorers/mail-thread.js +74 -0
  69. package/dist/services/link-scorers/member-chats.d.ts +3 -0
  70. package/dist/services/link-scorers/member-chats.js +40 -0
  71. package/dist/services/link-scorers/member-dialog.d.ts +3 -0
  72. package/dist/services/link-scorers/member-dialog.js +34 -0
  73. package/dist/services/link-scorers/scan.d.ts +41 -0
  74. package/dist/services/link-scorers/scan.js +244 -0
  75. package/dist/services/link-scorers/shared.d.ts +26 -0
  76. package/dist/services/link-scorers/shared.js +48 -0
  77. package/dist/services/link-scorers/types.d.ts +77 -0
  78. package/dist/services/link-scorers/types.js +1 -0
  79. package/dist/services/project-status/index.d.ts +71 -0
  80. package/dist/services/project-status/index.js +196 -0
  81. package/dist/services/project-status/items.d.ts +10 -0
  82. package/dist/services/project-status/items.js +23 -0
  83. package/dist/services/project-status/signals/amounts.d.ts +20 -0
  84. package/dist/services/project-status/signals/amounts.js +91 -0
  85. package/dist/services/project-status/signals/children.d.ts +13 -0
  86. package/dist/services/project-status/signals/children.js +28 -0
  87. package/dist/services/project-status/signals/coverage.d.ts +13 -0
  88. package/dist/services/project-status/signals/coverage.js +30 -0
  89. package/dist/services/project-status/signals/index.d.ts +3 -0
  90. package/dist/services/project-status/signals/index.js +21 -0
  91. package/dist/services/project-status/signals/last-message.d.ts +4 -0
  92. package/dist/services/project-status/signals/last-message.js +22 -0
  93. package/dist/services/project-status/signals/payments.d.ts +9 -0
  94. package/dist/services/project-status/signals/payments.js +24 -0
  95. package/dist/services/project-status/signals/promises.d.ts +17 -0
  96. package/dist/services/project-status/signals/promises.js +109 -0
  97. package/dist/services/project-status/signals/questions.d.ts +8 -0
  98. package/dist/services/project-status/signals/questions.js +38 -0
  99. package/dist/services/project-status/signals/reply-next.d.ts +19 -0
  100. package/dist/services/project-status/signals/reply-next.js +75 -0
  101. package/dist/services/project-status/signals/topics.d.ts +10 -0
  102. package/dist/services/project-status/signals/topics.js +50 -0
  103. package/dist/services/project-status/types.d.ts +84 -0
  104. package/dist/services/project-status/types.js +1 -0
  105. package/dist/services/proposals/index.d.ts +1 -0
  106. package/dist/services/proposals/index.js +1 -0
  107. package/dist/services/proposals/kinds/findings.d.ts +3 -0
  108. package/dist/services/proposals/kinds/findings.js +8 -1
  109. package/dist/store/decisions.d.ts +5 -1
  110. package/dist/store/decisions.js +5 -1
  111. package/dist/store/evidence-findings.js +1 -0
  112. package/dist/store/index.d.ts +2 -1
  113. package/dist/store/index.js +1 -0
  114. package/dist/store/project-transfer/request.d.ts +1 -1
  115. package/dist/store/project-transfer/schema.d.ts +2 -2
  116. package/dist/store/project-transfer/snapshot-model.d.ts +2 -2
  117. package/dist/store/sqlite/evidence-findings.js +5 -1
  118. package/dist/store/sqlite/facts.d.ts +13 -0
  119. package/dist/store/sqlite/facts.js +64 -6
  120. package/dist/store/sqlite/findings-core.js +14 -1
  121. package/dist/store/sqlite/knowledge.d.ts +16 -2
  122. package/dist/store/sqlite/knowledge.js +1 -0
  123. package/dist/store/sqlite/project-transfer/snapshot.d.ts +1 -1
  124. package/dist/store/sqlite/relation-proposals.d.ts +29 -2
  125. package/dist/store/sqlite/relation-proposals.js +75 -4
  126. package/dist/store/store.d.ts +1 -0
  127. package/package.json +3 -3
  128. package/parity.json +11 -0
@@ -0,0 +1,196 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { formatReference } from "../../domain/references.js";
3
+ import { chatCoverage } from "../chat-coverage.js";
4
+ import { canonicalProjectRef, linkedChatsOf } from "../stored-project-gathering.js";
5
+ import { centsText } from "./signals/amounts.js";
6
+ import { STATUS_SIGNALS } from "./signals/index.js";
7
+ export { STATUS_SIGNALS };
8
+ const DAY = 86_400_000;
9
+ /** Messages read per chat; the newest of the window. */
10
+ export const STATUS_WINDOW = 300;
11
+ /** Linked chats read at most, as `projects evidence` reads. */
12
+ export const STATUS_CHATS = 16;
13
+ const CHILD_DEPTH = 2;
14
+ const CHILDREN = 8;
15
+ /** What `projects status` reads when no purpose is asked for (built in; memo's config may change it). */
16
+ export const DEFAULT_PURPOSES = ["work"];
17
+ const projectsCatalog = async (store) => new Map((await store.knowledge.vocabulary({ kind: "project" })).entries.map((entry) => [`project:${entry.id}`, entry]));
18
+ /** Confirmed `member-of` links from another project; depth two, eight at most, a project seen twice skipped. */
19
+ const childrenOf = async (store, root, catalog) => {
20
+ const children = [];
21
+ const cut = [];
22
+ const seen = new Set([root.ref]);
23
+ let level = [root.ref];
24
+ for (let depth = 1; level.length > 0; depth++) {
25
+ const below = [];
26
+ for (const parent of level)
27
+ for (const relation of await store.knowledge.relations(null, parent)) {
28
+ if (!relation.confirmed || relation.kind !== "member-of" || relation.to !== parent)
29
+ continue;
30
+ if (!relation.from.startsWith("project:"))
31
+ continue;
32
+ const ref = relation.from;
33
+ const entry = catalog.get(ref);
34
+ if (!entry)
35
+ continue;
36
+ if (seen.has(ref)) {
37
+ if (!cut.some((one) => one.ref === ref) && !children.some((one) => one.ref === ref))
38
+ cut.push({ ref, reason: "cycle" });
39
+ continue;
40
+ }
41
+ seen.add(ref);
42
+ if (depth > CHILD_DEPTH)
43
+ cut.push({ ref, reason: "depth" });
44
+ else if (children.length >= CHILDREN)
45
+ cut.push({ ref, reason: "limit" });
46
+ else {
47
+ children.push({ ref, key: entry.key, name: entry.name, parent, depth });
48
+ below.push(ref);
49
+ }
50
+ }
51
+ level = below;
52
+ }
53
+ return { children, cut };
54
+ };
55
+ const inAccounts = (accounts, provider, account) => accounts === undefined || accounts.some((one) => one.provider === provider && one.account === account);
56
+ const failure = (error) => (error instanceof Error ? error.message : String(error));
57
+ /** An open ask, or an expected payment fact; an ask that a payment fact cites is counted once, as the fact. */
58
+ const counted = (items) => {
59
+ const recorded = new Set(items.filter((item) => item.signal === "payments").flatMap((item) => item.evidence.slice(1).map((one) => one.ref)));
60
+ return (item, state) => item.signal === "payments"
61
+ ? state === "expected"
62
+ : item.signal === "amounts" && state === "open" && !item.evidence.some((one) => recorded.has(one.ref));
63
+ };
64
+ const totalsOf = (items) => {
65
+ const totals = new Map();
66
+ const open = counted(items);
67
+ for (const item of items) {
68
+ const data = item.data;
69
+ if (!open(item, data.state) || data.amount === undefined)
70
+ continue;
71
+ const key = `${data.direction}|${data.currency ?? ""}`;
72
+ const total = totals.get(key) ?? {
73
+ direction: data.direction ?? "unknown",
74
+ currency: data.currency ?? null,
75
+ amount: "0.00",
76
+ rows: 0,
77
+ cents: 0,
78
+ };
79
+ total.cents += Math.round(Number(data.amount) * 100);
80
+ total.rows += 1;
81
+ totals.set(key, total);
82
+ }
83
+ return [...totals.values()].map(({ cents, ...total }) => ({ ...total, amount: centsText(cents) }));
84
+ };
85
+ /**
86
+ * Where a project stands, from the store alone: its linked chats and its children's, each read once, then every
87
+ * signal on its own. A signal that fails is named in `failed` and the others still answer. No model call.
88
+ */
89
+ export const projectStatus = async (store, input) => {
90
+ const now = input.asOf ?? Date.now();
91
+ const since = input.after ?? now - (input.days ?? 60) * DAY;
92
+ if (!(since < now))
93
+ throw new CliError("validation_error", "the window must start before it ends");
94
+ const signals = input.signals ?? STATUS_SIGNALS;
95
+ const purposes = new Set(input.purposes ?? DEFAULT_PURPOSES);
96
+ const catalog = await projectsCatalog(store);
97
+ const ref = await canonicalProjectRef(store, input.project);
98
+ const entry = catalog.get(ref);
99
+ if (!entry)
100
+ throw new CliError("not_found", "the owner project is unavailable");
101
+ const root = { ref, key: entry.key, name: entry.name };
102
+ const { children, cut } = await childrenOf(store, root, catalog);
103
+ const outOfScope = [];
104
+ const linked = new Map();
105
+ for (const project of [root, ...children])
106
+ for (const link of await linkedChatsOf(store, project.ref)) {
107
+ const chat = formatReference({ type: "chat", provider: link.provider, account: link.account, chat: link.chat });
108
+ if (!linked.has(chat))
109
+ linked.set(chat, { ...link, project: project.ref });
110
+ }
111
+ const chosen = [];
112
+ for (const [chat, link] of linked) {
113
+ // Links carry no purpose yet; every one is `work`, as a link without one will be.
114
+ const purpose = "work";
115
+ if (!purposes.has("all") && !purposes.has(purpose))
116
+ outOfScope.push({ chat, reason: "purpose", purpose });
117
+ else if (!inAccounts(input.accounts, link.provider, link.account))
118
+ outOfScope.push({ chat, reason: "other-account" });
119
+ else if (chosen.length >= STATUS_CHATS)
120
+ outOfScope.push({ chat, reason: "linked-chat-limit" });
121
+ else
122
+ chosen.push([chat, link]);
123
+ }
124
+ const sinceIso = new Date(since).toISOString();
125
+ const chats = [];
126
+ for (const [chat, link] of chosen) {
127
+ const account = { provider: link.provider, account: link.account };
128
+ const [coverage] = await chatCoverage(store, account, [link.chat]);
129
+ const page = await store.messages.messages(account, link.chat, { limit: STATUS_WINDOW, since: sinceIso });
130
+ chats.push({
131
+ ref: chat,
132
+ account,
133
+ chatId: link.chat,
134
+ title: coverage?.title ?? null,
135
+ kind: (await store.chats.chatKind(account, link.chat)) ?? "unknown",
136
+ role: link.role,
137
+ purpose: "work",
138
+ project: link.project,
139
+ coverage: coverage,
140
+ messages: page.items.filter((message) => Date.parse(message.timestamp) <= now),
141
+ });
142
+ }
143
+ const context = {
144
+ now,
145
+ since,
146
+ chats,
147
+ project: { ...root, children, cut },
148
+ store,
149
+ contextQueries: input.contextQueries ?? [],
150
+ };
151
+ const items = [];
152
+ const failed = [];
153
+ const weights = new Map();
154
+ for (const signal of signals) {
155
+ try {
156
+ const found = signal.scope === "chat"
157
+ ? (await Promise.all(chats.map((chat) => signal.read(context, chat)))).flat()
158
+ : await signal.read(context);
159
+ for (const one of signal.attention?.(found, context) ?? []) {
160
+ const held = weights.get(one.chat) ?? { weight: 0, why: [] };
161
+ held.weight += Math.max(0, Math.min(3, one.weight));
162
+ if (!held.why.includes(one.why))
163
+ held.why.push(one.why);
164
+ weights.set(one.chat, held);
165
+ }
166
+ for (const one of found)
167
+ items.push(one);
168
+ }
169
+ catch (error) {
170
+ failed.push({ signal: signal.id, why: failure(error) });
171
+ }
172
+ }
173
+ const order = new Map(chats.map((chat, index) => [chat.ref, index]));
174
+ const attention = [...weights]
175
+ .filter(([, { weight }]) => weight > 0)
176
+ .map(([chat, { weight, why }]) => ({ chat, weight, why: why.join(", ") }))
177
+ .sort((a, b) => b.weight - a.weight || (order.get(a.chat) ?? 0) - (order.get(b.chat) ?? 0));
178
+ return {
179
+ project: root,
180
+ children: children.map(({ ref, key, name }) => ({
181
+ ref,
182
+ key,
183
+ name,
184
+ chats: chats.filter((chat) => chat.project === ref).length,
185
+ })),
186
+ window: { since: sinceIso, until: new Date(now).toISOString() },
187
+ accounts: [...new Set(chats.map((chat) => `${chat.account.provider}/${chat.account.account}`))],
188
+ chats: chats.map(({ messages: _messages, account: _account, ...chat }) => chat),
189
+ items,
190
+ money: { open: totalsOf(items) },
191
+ outOfScope,
192
+ failed,
193
+ attention,
194
+ signals: signals.map(({ id, version }) => ({ id, version })),
195
+ };
196
+ };
@@ -0,0 +1,10 @@
1
+ import type { Message } from "../../domain/models.js";
2
+ import type { StatusChat, StatusItem, StatusWho } from "./types.js";
3
+ /** The most of a message's text any status item carries. */
4
+ export declare const EXCERPT_CHARS = 80;
5
+ export declare const excerpt: (text: string) => string;
6
+ export declare const messageRef: (chat: StatusChat, message: Pick<Message, "id">) => string;
7
+ export declare const evidenceOf: (chat: StatusChat, ...messages: Pick<Message, "id">[]) => StatusItem["evidence"];
8
+ export declare const whoOf: (message: Pick<Message, "outgoing" | "senderName">) => StatusWho;
9
+ export declare const fromOwner: (message: Pick<Message, "outgoing">) => boolean;
10
+ export declare const day: (at: number | string) => string;
@@ -0,0 +1,23 @@
1
+ import { formatLocator } from "../../domain/locator.js";
2
+ /** The most of a message's text any status item carries. */
3
+ export const EXCERPT_CHARS = 80;
4
+ export const excerpt = (text) => {
5
+ const flat = text.replace(/\s+/g, " ").trim();
6
+ const letters = Array.from(flat);
7
+ return letters.length <= EXCERPT_CHARS ? flat : `${letters.slice(0, EXCERPT_CHARS - 1).join("")}…`;
8
+ };
9
+ export const messageRef = (chat, message) => formatLocator({
10
+ provider: chat.account.provider,
11
+ account: chat.account.account,
12
+ chat: chat.chatId,
13
+ message: message.id,
14
+ });
15
+ export const evidenceOf = (chat, ...messages) => messages.slice(0, 8).map((message) => ({ ref: messageRef(chat, message), fingerprint: null }));
16
+ // Person refs wait for the shared ref summaries; until then the sender's stored name is the label.
17
+ export const whoOf = (message) => ({
18
+ ref: null,
19
+ name: message.outgoing === true ? null : message.senderName,
20
+ owner: message.outgoing === true,
21
+ });
22
+ export const fromOwner = (message) => message.outgoing === true;
23
+ export const day = (at) => new Date(at).toISOString().slice(0, 10);
@@ -0,0 +1,20 @@
1
+ import type { StatusSignal } from "../types.js";
2
+ export type MoneyDirection = "to_us" | "from_us" | "unknown";
3
+ export interface AmountsData {
4
+ /** Decimal as text, two places: money is never a float. */
5
+ amount: string;
6
+ currency: string | null;
7
+ direction: MoneyDirection;
8
+ /** `paid-mentioned` is a message saying so, never a payment the owner recorded. */
9
+ state: "open" | "paid-mentioned" | "mentioned";
10
+ /** The first ask, or the first mention when nobody asked. */
11
+ since: string;
12
+ lastAsked: string | null;
13
+ asks: number;
14
+ }
15
+ export declare const centsText: (cents: number) => string;
16
+ /**
17
+ * Every message with an amount and a money word, folded by amount and currency per chat: the first ask is `since`, a
18
+ * later "paid" message naming the same amount makes it `paid-mentioned`. Instalments are not summed into a total.
19
+ */
20
+ export declare const amounts: StatusSignal<AmountsData>;
@@ -0,0 +1,91 @@
1
+ import { MONEY_DONE, MONEY_REQUEST } from "../../../domain/money-words.js";
2
+ import { MONEY_DONE_FORMS } from "../../../domain/status-words.js";
3
+ import { DEFAULT_TASK_CATEGORIES } from "../../../domain/task-categories.js";
4
+ import { amountsOf } from "../../../search/task-signature.js";
5
+ import { moneyClassesOf } from "../../money-words.js";
6
+ import { listsHit } from "../../task-categories.js";
7
+ import { evidenceOf, fromOwner, whoOf } from "../items.js";
8
+ const MONEY = DEFAULT_TASK_CATEGORIES.filter((category) => category.name === "money");
9
+ // Past forms first: their stem is also a request's (`оплатил` and `оплати` → `оплат`).
10
+ const verbOf = (text) => {
11
+ if (MONEY_DONE_FORMS.test(text))
12
+ return "done";
13
+ const classes = moneyClassesOf(text);
14
+ if (classes.includes(MONEY_DONE))
15
+ return "done";
16
+ return classes.includes(MONEY_REQUEST) ? "request" : "none";
17
+ };
18
+ const roleDirection = (role) => {
19
+ const named = role?.trim().toLowerCase();
20
+ return named === "client" ? "to_us" : named === "contractor" ? "from_us" : "unknown";
21
+ };
22
+ /** The sender's side decides: a stem cannot tell an ask from a report, so who wrote it is the evidence. */
23
+ const directionOf = (verb, owner, role) => {
24
+ if (verb === "request")
25
+ return owner ? "to_us" : "from_us";
26
+ if (verb === "done")
27
+ return owner ? "from_us" : "to_us";
28
+ return roleDirection(role);
29
+ };
30
+ const rowsOf = (chat) => chat.messages.flatMap((message) => {
31
+ const found = amountsOf(message.text);
32
+ if (!found.length)
33
+ return [];
34
+ const verb = verbOf(message.text);
35
+ if (verb === "none" && !listsHit(message.text, MONEY).length)
36
+ return [];
37
+ const direction = directionOf(verb, fromOwner(message), chat.role);
38
+ return found.map(({ value, currency }) => ({
39
+ message,
40
+ cents: Math.round(value * 100),
41
+ currency,
42
+ verb,
43
+ direction,
44
+ }));
45
+ });
46
+ export const centsText = (cents) => `${Math.floor(cents / 100)}.${String(cents % 100).padStart(2, "0")}`;
47
+ /**
48
+ * Every message with an amount and a money word, folded by amount and currency per chat: the first ask is `since`, a
49
+ * later "paid" message naming the same amount makes it `paid-mentioned`. Instalments are not summed into a total.
50
+ */
51
+ export const amounts = {
52
+ id: "amounts",
53
+ version: 1,
54
+ scope: "chat",
55
+ read: async (_context, chat) => {
56
+ if (!chat)
57
+ return [];
58
+ const groups = new Map();
59
+ for (const row of rowsOf(chat)) {
60
+ const key = `${row.cents}|${row.currency ?? ""}`;
61
+ groups.set(key, [...(groups.get(key) ?? []), row]);
62
+ }
63
+ return [...groups.values()].map((rows) => {
64
+ const asks = rows.filter((row) => row.verb === "request");
65
+ const done = rows.filter((row) => row.verb === "done");
66
+ const lastAsk = asks.at(-1);
67
+ const first = (asks[0] ?? done[0] ?? rows[0]);
68
+ const paidAfter = done.some((row) => !lastAsk || Date.parse(row.message.timestamp) >= Date.parse(lastAsk.message.timestamp));
69
+ const state = asks.length ? (paidAfter ? "paid-mentioned" : "open") : done.length ? "paid-mentioned" : "mentioned";
70
+ const cited = asks.length ? [...asks, ...(paidAfter ? done.slice(-1) : [])] : rows;
71
+ return {
72
+ signal: "amounts",
73
+ chat: chat.ref,
74
+ at: first.message.timestamp,
75
+ who: whoOf(first.message),
76
+ evidence: evidenceOf(chat, ...new Set(cited.map((row) => row.message))),
77
+ basis: "pattern",
78
+ data: {
79
+ amount: centsText(first.cents),
80
+ currency: first.currency,
81
+ direction: first.direction,
82
+ state,
83
+ since: first.message.timestamp,
84
+ lastAsked: lastAsk?.message.timestamp ?? null,
85
+ asks: asks.length,
86
+ },
87
+ };
88
+ });
89
+ },
90
+ attention: (items) => items.flatMap((item) => item.chat !== null && item.data.state === "open" ? [{ chat: item.chat, weight: 2, why: "money open" }] : []),
91
+ };
@@ -0,0 +1,13 @@
1
+ import type { StatusSignal } from "../types.js";
2
+ export interface ChildrenData {
3
+ child: string;
4
+ key: string | null;
5
+ name: string | null;
6
+ depth: number | null;
7
+ /** Linked chats read for it; a chat linked to two projects counts once, under the first. */
8
+ chats: number | null;
9
+ /** Why it was not read: deeper than two levels, seen twice, or past eight children. */
10
+ cut: "depth" | "cycle" | "limit" | null;
11
+ }
12
+ /** Child projects (a confirmed `member-of` link to this one) that were read, and those cut. */
13
+ export declare const children: StatusSignal<ChildrenData>;
@@ -0,0 +1,28 @@
1
+ /** Child projects (a confirmed `member-of` link to this one) that were read, and those cut. */
2
+ export const children = {
3
+ id: "children",
4
+ version: 1,
5
+ scope: "project",
6
+ read: async (context) => {
7
+ const item = (data) => ({
8
+ signal: "children",
9
+ chat: null,
10
+ at: null,
11
+ who: null,
12
+ evidence: [{ ref: data.child, fingerprint: null }],
13
+ basis: "store",
14
+ data,
15
+ });
16
+ return [
17
+ ...context.project.children.map((child) => item({
18
+ child: child.ref,
19
+ key: child.key,
20
+ name: child.name,
21
+ depth: child.depth,
22
+ chats: context.chats.filter((chat) => chat.project === child.ref).length,
23
+ cut: null,
24
+ })),
25
+ ...context.project.cut.map(({ ref, reason }) => item({ child: ref, key: null, name: null, depth: null, chats: null, cut: reason })),
26
+ ];
27
+ },
28
+ };
@@ -0,0 +1,13 @@
1
+ import type { StatusSignal } from "../types.js";
2
+ export interface CoverageData {
3
+ state: "complete" | "partial" | "unknown";
4
+ held: {
5
+ messages: number;
6
+ oldestAt: string | null;
7
+ newestAt: string | null;
8
+ };
9
+ /** The window starts before the oldest message the store holds, so the window is not read whole. */
10
+ beforeHeld: boolean;
11
+ }
12
+ /** What the store holds of a chat it does not hold whole; the answer adds the line that syncs it. */
13
+ export declare const coverage: StatusSignal<CoverageData>;
@@ -0,0 +1,30 @@
1
+ /** What the store holds of a chat it does not hold whole; the answer adds the line that syncs it. */
2
+ export const coverage = {
3
+ id: "coverage",
4
+ version: 1,
5
+ scope: "chat",
6
+ read: async (context, chat) => {
7
+ if (!chat || chat.coverage.completeness.state === "complete")
8
+ return [];
9
+ const { completeness, held } = chat.coverage;
10
+ const oldest = held.oldestAt === null ? null : Date.parse(held.oldestAt);
11
+ return [
12
+ {
13
+ signal: "coverage",
14
+ chat: chat.ref,
15
+ at: completeness.fetchedAt,
16
+ who: null,
17
+ evidence: [],
18
+ basis: "store",
19
+ data: {
20
+ state: completeness.state,
21
+ held,
22
+ beforeHeld: completeness.state !== "complete" && (oldest === null || context.since < oldest),
23
+ },
24
+ },
25
+ ];
26
+ },
27
+ attention: (items) => items.flatMap((item) => item.chat !== null && item.data.state !== "complete" && item.data.beforeHeld
28
+ ? [{ chat: item.chat, weight: 3, why: "held in part" }]
29
+ : []),
30
+ };
@@ -0,0 +1,3 @@
1
+ import type { StatusSignal } from "../types.js";
2
+ /** The registry; its order is the answer's order. A new signal is one file here and its row in the CLI. */
3
+ export declare const STATUS_SIGNALS: readonly StatusSignal[];
@@ -0,0 +1,21 @@
1
+ import { amounts } from "./amounts.js";
2
+ import { children } from "./children.js";
3
+ import { coverage } from "./coverage.js";
4
+ import { lastMessage } from "./last-message.js";
5
+ import { payments } from "./payments.js";
6
+ import { promises } from "./promises.js";
7
+ import { questions } from "./questions.js";
8
+ import { replyNext } from "./reply-next.js";
9
+ import { topics } from "./topics.js";
10
+ /** The registry; its order is the answer's order. A new signal is one file here and its row in the CLI. */
11
+ export const STATUS_SIGNALS = [
12
+ lastMessage,
13
+ replyNext,
14
+ questions,
15
+ promises,
16
+ amounts,
17
+ payments,
18
+ topics,
19
+ coverage,
20
+ children,
21
+ ];
@@ -0,0 +1,4 @@
1
+ import type { StatusSignal } from "../types.js";
2
+ export type LastMessageData = Record<string, never>;
3
+ /** The newest stored message in the window: when, and who wrote it. A chat held in part says so through `coverage`. */
4
+ export declare const lastMessage: StatusSignal<LastMessageData>;
@@ -0,0 +1,22 @@
1
+ import { evidenceOf, whoOf } from "../items.js";
2
+ /** The newest stored message in the window: when, and who wrote it. A chat held in part says so through `coverage`. */
3
+ export const lastMessage = {
4
+ id: "last-message",
5
+ version: 1,
6
+ scope: "chat",
7
+ read: async (_context, chat) => {
8
+ const last = chat?.messages.at(-1);
9
+ if (!chat || !last)
10
+ return [];
11
+ const item = {
12
+ signal: "last-message",
13
+ chat: chat.ref,
14
+ at: last.timestamp,
15
+ who: whoOf(last),
16
+ evidence: evidenceOf(chat, last),
17
+ basis: "store",
18
+ data: {},
19
+ };
20
+ return [item];
21
+ },
22
+ };
@@ -0,0 +1,9 @@
1
+ import { type Payment } from "../../../meetings/index.js";
2
+ import type { StatusSignal } from "../types.js";
3
+ export interface PaymentsData extends Payment {
4
+ title: string;
5
+ /** The fact's review status: proposed or accepted. */
6
+ status: string;
7
+ }
8
+ /** Payment facts of the project and its children, proposed or accepted. Only what someone recorded. */
9
+ export declare const payments: StatusSignal<PaymentsData>;
@@ -0,0 +1,24 @@
1
+ import { paymentTitle } from "../../../meetings/index.js";
2
+ const HOLDING = new Set(["proposed", "accepted"]);
3
+ /** Payment facts of the project and its children, proposed or accepted. Only what someone recorded. */
4
+ export const payments = {
5
+ id: "payments",
6
+ version: 2,
7
+ scope: "project",
8
+ read: async (context) => {
9
+ const projects = [context.project.ref, ...context.project.children.map((child) => child.ref)];
10
+ const facts = (await Promise.all(projects.map((project) => context.store.facts.list({ project, type: "payment", limit: 500 })))).flat();
11
+ return facts
12
+ .filter((fact) => fact.payment !== null && HOLDING.has(fact.status))
13
+ .map((fact) => ({
14
+ signal: "payments",
15
+ chat: null,
16
+ at: fact.occurredAt ?? fact.createdAt,
17
+ who: null,
18
+ // The fact first, then what it cites, so an amount read from a cited message is not counted twice.
19
+ evidence: [fact.ref, ...fact.evidence].map((ref) => ({ ref, fingerprint: null })),
20
+ basis: "fact",
21
+ data: { ...fact.payment, title: paymentTitle(fact), status: fact.status },
22
+ }));
23
+ },
24
+ };
@@ -0,0 +1,17 @@
1
+ import type { StatusSignal } from "../types.js";
2
+ export interface PromisesData {
3
+ /** Where it came from: a stored task, a recorded fact, or a word match in a message (a guess). */
4
+ source: "task" | "fact" | "pattern";
5
+ /** `promise` or `request` for a task; a fact's and a pattern's are promises. */
6
+ kind: string;
7
+ title: string;
8
+ /** Who promised, for a pattern: the owner (`yours`) or the other side. */
9
+ side: "yours" | "theirs" | null;
10
+ due: string | null;
11
+ status: string;
12
+ }
13
+ /**
14
+ * Open promise and request tasks of the project or from its chats, promise facts proposed or accepted, and up to
15
+ * three promises per chat found by first person future words ("сделаю", "I'll send"), marked as patterns.
16
+ */
17
+ export declare const promises: StatusSignal<PromisesData>;
@@ -0,0 +1,109 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { isLocator, parseLocator } from "../../../domain/locator.js";
3
+ import { PROMISE_FORMS } from "../../../domain/status-words.js";
4
+ import { dueDayOf } from "../../../search/task-signature.js";
5
+ import { normalize } from "../../../store/normalize.js";
6
+ import { inboxKey } from "../../../store/store.js";
7
+ import { taskAccount } from "../../task-rules.js";
8
+ import { day, evidenceOf, excerpt, fromOwner, whoOf } from "../items.js";
9
+ const PATTERNS_PER_CHAT = 3;
10
+ const DAY = 86_400_000;
11
+ const KINDS = new Set(["promise", "request"]);
12
+ const OPEN = new Set(["open", "todo", "in_progress"]);
13
+ const chatOfSource = (context, source) => {
14
+ if (source === null || !isLocator(source))
15
+ return undefined;
16
+ const { provider, account, chat } = parseLocator(source);
17
+ return context.chats.find((one) => one.account.provider === provider && one.account.account === account && one.chatId === chat);
18
+ };
19
+ // An account that never had a task has no inbox project yet.
20
+ const orNone = (error) => {
21
+ if (error instanceof CliError && error.code === "not_found")
22
+ return [];
23
+ throw error;
24
+ };
25
+ const tasksOf = async (context) => {
26
+ const projects = [context.project.ref, ...context.project.children.map((child) => child.ref)];
27
+ const accounts = new Map(context.chats.map((chat) => [taskAccount(chat.account), chat.account]));
28
+ const inboxes = [...accounts.keys()].map(inboxKey);
29
+ const found = await Promise.all([...projects, ...inboxes].map((project) => context.store.tasks.find({ project, limit: 500 }).catch(orNone)));
30
+ const projectRefs = new Set(projects);
31
+ return found
32
+ .flat()
33
+ .filter((task) => KINDS.has(task.type) && OPEN.has(task.status))
34
+ .filter((task) => projectRefs.has(task.project) || chatOfSource(context, task.source) !== undefined);
35
+ };
36
+ const taskItem = (context, task) => ({
37
+ signal: "promises",
38
+ chat: chatOfSource(context, task.source)?.ref ?? null,
39
+ at: task.createdAt,
40
+ who: null,
41
+ evidence: [{ ref: task.ref, fingerprint: null }, ...(task.source ? [{ ref: task.source, fingerprint: null }] : [])],
42
+ basis: "task",
43
+ data: {
44
+ source: "task",
45
+ kind: task.type,
46
+ title: excerpt(task.title),
47
+ side: null,
48
+ due: task.dueAt === null ? null : day(task.dueAt),
49
+ status: task.status,
50
+ },
51
+ });
52
+ const patternItems = (chat) => chat.messages
53
+ .filter((message) => !message.text.includes("?") && PROMISE_FORMS.test(message.text))
54
+ .slice(-PATTERNS_PER_CHAT)
55
+ .reverse()
56
+ .map((message) => {
57
+ const due = dueDayOf(normalize(message.text), Date.parse(message.timestamp));
58
+ return {
59
+ signal: "promises",
60
+ chat: chat.ref,
61
+ at: message.timestamp,
62
+ who: whoOf(message),
63
+ evidence: evidenceOf(chat, message),
64
+ basis: "pattern",
65
+ data: {
66
+ source: "pattern",
67
+ kind: "promise",
68
+ title: excerpt(message.text),
69
+ side: fromOwner(message) ? "yours" : "theirs",
70
+ due: due === null ? null : day(due * DAY),
71
+ status: "open",
72
+ },
73
+ };
74
+ });
75
+ /**
76
+ * Open promise and request tasks of the project or from its chats, promise facts proposed or accepted, and up to
77
+ * three promises per chat found by first person future words ("сделаю", "I'll send"), marked as patterns.
78
+ */
79
+ export const promises = {
80
+ id: "promises",
81
+ version: 1,
82
+ scope: "project",
83
+ read: async (context) => {
84
+ const projects = [context.project.ref, ...context.project.children.map((child) => child.ref)];
85
+ const facts = (await Promise.all(projects.map((project) => context.store.facts.list({ type: "promise", project }))))
86
+ .flat()
87
+ .filter((fact) => fact.status === "proposed" || fact.status === "accepted");
88
+ return [
89
+ ...(await tasksOf(context)).map((task) => taskItem(context, task)),
90
+ ...facts.map((fact) => ({
91
+ signal: "promises",
92
+ chat: null,
93
+ at: fact.occurredAt ?? fact.createdAt,
94
+ who: null,
95
+ evidence: [{ ref: fact.ref, fingerprint: null }],
96
+ basis: "fact",
97
+ data: {
98
+ source: "fact",
99
+ kind: "promise",
100
+ title: excerpt(fact.statement),
101
+ side: null,
102
+ due: null,
103
+ status: fact.status,
104
+ },
105
+ })),
106
+ ...context.chats.flatMap(patternItems),
107
+ ];
108
+ },
109
+ };
@@ -0,0 +1,8 @@
1
+ import type { StatusSignal } from "../types.js";
2
+ export interface QuestionsData {
3
+ /** `theirs`: someone asked and the owner has not answered; `yours`: the owner asked and nobody answered. */
4
+ side: "theirs" | "yours";
5
+ excerpt: string;
6
+ }
7
+ /** Open questions both ways, newest first, at most five a side. A question answered in another chat stays open. */
8
+ export declare const questions: StatusSignal<QuestionsData>;