@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.
- package/LICENSE +204 -0
- package/README.md +399 -2
- package/THIRD_PARTY_NOTICES +2 -0
- package/contracts/wirecat.json +4612 -0
- package/dist/actions/actions.js +269 -0
- package/dist/actions/command.js +102 -0
- package/dist/agents/command.js +17 -0
- package/dist/agents/log.js +23 -0
- package/dist/answer.js +100 -0
- package/dist/answers/command.js +128 -0
- package/dist/app.js +15 -0
- package/dist/author.js +109 -0
- package/dist/bin/wcat-wirecat.js +40 -0
- package/dist/bots/command.js +175 -0
- package/dist/bundle/auto-O24ISPOI.js +43 -0
- package/dist/bundle/chunk-2A3YPENI.js +31 -0
- package/dist/bundle/chunk-6BDIFKF5.js +222 -0
- package/dist/bundle/chunk-7O7XM37N.js +2 -0
- package/dist/bundle/chunk-AYHZY24E.js +120 -0
- package/dist/bundle/chunk-CKBTMZUX.js +72 -0
- package/dist/bundle/chunk-FGXUH3XL.js +416 -0
- package/dist/bundle/chunk-I5JQBRRC.js +807 -0
- package/dist/bundle/chunk-RKVAWMZT.js +38 -0
- package/dist/bundle/chunk-SCDNOUUR.js +395 -0
- package/dist/bundle/chunk-T7TG4JKR.js +312 -0
- package/dist/bundle/chunk-XBUCXQKT.js +51 -0
- package/dist/bundle/entry-EW5A7FYV.js +64 -0
- package/dist/bundle/failure-HMELJ3K5.js +19 -0
- package/dist/bundle/from-memo-F7NTUXAR.js +314 -0
- package/dist/bundle/program-7XWGFN4H.js +14994 -0
- package/dist/bundle/server-T7RVBNRW.js +303 -0
- package/dist/bundle/update-JZDS7B6L.js +22 -0
- package/dist/bundle/wcat-wirecat.js +83 -0
- package/dist/config-command.js +39 -0
- package/dist/config-issues.js +15 -0
- package/dist/config.js +187 -0
- package/dist/context/command.js +162 -0
- package/dist/context/context.js +197 -0
- package/dist/contract-overrides/commands.js +81 -0
- package/dist/contract-overrides/mcp.js +241 -0
- package/dist/contract-overrides/meetings.js +344 -0
- package/dist/contract-overrides/search.js +508 -0
- package/dist/contract-overrides/skill.js +85 -0
- package/dist/contract-overrides.js +7 -0
- package/dist/digest/backfill.js +175 -0
- package/dist/digest/brief.js +189 -0
- package/dist/digest/catch-up-record.js +30 -0
- package/dist/digest/catch-up.js +86 -0
- package/dist/digest/command.js +110 -0
- package/dist/digest/digest-commands.js +327 -0
- package/dist/digest/digest.js +560 -0
- package/dist/digest/digests.js +213 -0
- package/dist/digest/history.js +202 -0
- package/dist/digest/input.js +30 -0
- package/dist/digest/known.js +28 -0
- package/dist/digest/sources.js +155 -0
- package/dist/digest/sync-health.js +158 -0
- package/dist/digest/task-proposals.js +67 -0
- package/dist/digest/tasks.js +145 -0
- package/dist/digest/text.js +49 -0
- package/dist/discovery/command.js +107 -0
- package/dist/doctor/command.js +167 -0
- package/dist/documents/command.js +107 -0
- package/dist/domain-lists/command.js +13 -0
- package/dist/events/command.js +35 -0
- package/dist/events/events.js +196 -0
- package/dist/examples.js +609 -0
- package/dist/facts/command.js +100 -0
- package/dist/facts/fact.js +54 -0
- package/dist/facts/facts.js +15 -0
- package/dist/failure.js +58 -0
- package/dist/finance/command.js +121 -0
- package/dist/finance/contracts-command.js +109 -0
- package/dist/finance/deal-text.js +34 -0
- package/dist/finance/deals-command.js +346 -0
- package/dist/finance/finance.js +129 -0
- package/dist/finance/lines-command.js +70 -0
- package/dist/finance/orders-command.js +94 -0
- package/dist/finance/products-command.js +98 -0
- package/dist/finance/subscriptions-command.js +152 -0
- package/dist/finance/transactions-command.js +136 -0
- package/dist/finance/wallets-command.js +105 -0
- package/dist/finance/written.js +36 -0
- package/dist/findings/command.js +102 -0
- package/dist/findings-input.js +23 -0
- package/dist/identity.js +20 -0
- package/dist/install/postinstall.js +47 -0
- package/dist/json-fields.js +48 -0
- package/dist/knowledge/business-text.js +19 -0
- package/dist/knowledge/command.js +435 -0
- package/dist/knowledge/document-context.js +33 -0
- package/dist/knowledge/key-documents.js +120 -0
- package/dist/knowledge/list-queries.js +20 -0
- package/dist/knowledge/meeting-projects-command.js +61 -0
- package/dist/knowledge/messenger-sync.js +253 -0
- package/dist/knowledge/money-text.js +16 -0
- package/dist/knowledge/notes-about.js +81 -0
- package/dist/knowledge/organization-delete-command.js +44 -0
- package/dist/knowledge/organization-text.js +27 -0
- package/dist/knowledge/project-actions-command.js +130 -0
- package/dist/knowledge/project-actions.js +104 -0
- package/dist/knowledge/project-activity-command.js +70 -0
- package/dist/knowledge/project-context.js +101 -0
- package/dist/knowledge/project-findings.js +41 -0
- package/dist/knowledge/project-gather-command.js +100 -0
- package/dist/knowledge/project-status-command.js +129 -0
- package/dist/knowledge/project-transfer-command.js +58 -0
- package/dist/knowledge/project-transfer.js +107 -0
- package/dist/knowledge/relationships-scan.js +116 -0
- package/dist/knowledge/relationships.js +115 -0
- package/dist/knowledge/roles-command.js +67 -0
- package/dist/mail/command.js +20 -0
- package/dist/mail/findings-command.js +143 -0
- package/dist/mail/findings-duplicates.js +159 -0
- package/dist/mail/messages-command.js +77 -0
- package/dist/mail/review-command.js +59 -0
- package/dist/mail/subscriptions-command.js +84 -0
- package/dist/mcp/catalogue.js +159 -0
- package/dist/mcp/command.js +125 -0
- package/dist/mcp/granted.js +18 -0
- package/dist/mcp/permissions.js +61 -0
- package/dist/mcp/server.js +128 -0
- package/dist/meetings/command.js +31 -0
- package/dist/meetings/list-command.js +59 -0
- package/dist/meetings/preparation-command.js +42 -0
- package/dist/meetings/preparation-text.js +44 -0
- package/dist/meetings/preparation.js +50 -0
- package/dist/meetings/read.js +32 -0
- package/dist/memories/command.js +105 -0
- package/dist/memories/memories.js +17 -0
- package/dist/memories/memory.js +89 -0
- package/dist/memories/sources.js +111 -0
- package/dist/mentions/command.js +91 -0
- package/dist/migrate/check.js +48 -0
- package/dist/migrate/from-memo.js +345 -0
- package/dist/migrate/skill.js +35 -0
- package/dist/models/command.js +19 -0
- package/dist/options.js +35 -0
- package/dist/output.js +17 -0
- package/dist/page.js +14 -0
- package/dist/people/command.js +144 -0
- package/dist/people/delete-command.js +53 -0
- package/dist/people/doubts-command.js +81 -0
- package/dist/people/identities-command.js +188 -0
- package/dist/people/identity.js +42 -0
- package/dist/people/owner.js +14 -0
- package/dist/people/proposal-rows.js +70 -0
- package/dist/people/proposals-command.js +248 -0
- package/dist/people/review-context.js +108 -0
- package/dist/people/subject.js +19 -0
- package/dist/program.js +875 -0
- package/dist/read-only.js +51 -0
- package/dist/reasons.js +368 -0
- package/dist/records/import.js +135 -0
- package/dist/records/input.js +210 -0
- package/dist/records/mapping.js +80 -0
- package/dist/records/record-commands.js +125 -0
- package/dist/records/sources.js +73 -0
- package/dist/refs.js +28 -0
- package/dist/review/command.js +171 -0
- package/dist/review/kinds.js +44 -0
- package/dist/review/review.js +299 -0
- package/dist/review/status.js +93 -0
- package/dist/rows.js +219 -0
- package/dist/run/auto.js +237 -0
- package/dist/run/entry.js +62 -0
- package/dist/run/files.js +51 -0
- package/dist/run/import.js +253 -0
- package/dist/run/lock.js +20 -0
- package/dist/save-help.js +3 -0
- package/dist/schedule/command.js +58 -0
- package/dist/schedule/mail-triage-input.js +152 -0
- package/dist/schedule/task-triage-input.js +152 -0
- package/dist/search/answers.js +176 -0
- package/dist/search/command.js +257 -0
- package/dist/search/denied.js +9 -0
- package/dist/search/embed.js +126 -0
- package/dist/search/hits.js +4 -0
- package/dist/search/lane-gates.js +76 -0
- package/dist/search/notes-text.js +18 -0
- package/dist/search/people.js +88 -0
- package/dist/search/search.js +306 -0
- package/dist/show/command.js +179 -0
- package/dist/store/crm-viewer.js +102 -0
- package/dist/store/group.js +112 -0
- package/dist/store/groups-command.js +136 -0
- package/dist/store/guard.js +94 -0
- package/dist/store/held.js +21 -0
- package/dist/store/info-command.js +37 -0
- package/dist/store/scope.js +53 -0
- package/dist/store/source-list.js +222 -0
- package/dist/store/source-target.js +28 -0
- package/dist/tags/command.js +176 -0
- package/dist/tasks/command.js +174 -0
- package/dist/tasks/context.js +74 -0
- package/dist/tasks/list.js +199 -0
- package/dist/tasks/proposal-duplicates.js +70 -0
- package/dist/tasks/relations-command.js +28 -0
- package/dist/tasks/shared.js +105 -0
- package/dist/tasks/tasks.js +197 -0
- package/dist/templates/command.js +18 -0
- package/dist/terminal.js +23 -0
- package/dist/update.js +35 -0
- package/dist/version.js +2 -0
- package/dist/vocabulary/command.js +103 -0
- package/dist/vocabulary/inspect.js +23 -0
- package/dist/vocabulary/inspection.js +18 -0
- package/dist/vocabulary/list.js +18 -0
- package/dist/vocabulary/project.js +19 -0
- package/dist/wcat.js +3 -0
- package/install/postinstall.mjs +9 -0
- package/package.json +89 -4
- package/scenarios/decision-trail.md +21 -0
- package/scenarios/person-brief.md +35 -0
- package/scenarios/prepare-meeting.md +17 -0
- package/scenarios/project-state.md +26 -0
- package/scenarios/set-up.md +18 -0
- package/scenarios/start-the-day.md +19 -0
- package/skills/mail-triage/SKILL.md +208 -0
- package/skills/morning-digest/SKILL.md +147 -0
- package/skills/task-triage/SKILL.md +79 -0
- package/skills/wcat/SKILL.md +65 -0
- package/skills/wcat/topics/mail.md +32 -0
- package/skills/wcat/topics/mcp.md +22 -0
- package/skills/wcat/topics/meetings.md +37 -0
- package/skills/wcat/topics/money.md +52 -0
- package/skills/wcat/topics/projects.md +54 -0
- package/skills/wcat/topics/proposals.md +113 -0
- package/skills/wcat/topics/search.md +85 -0
- package/skills/wcat/topics/vocabulary.md +8 -0
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import { formatMeetingReference, formatReference, kindOf, projectStatus, SOURCE_REVIEW_KIND, } from "@wirecat/cli-core";
|
|
2
|
+
import { mailTurn, OWED_DAYS } from "@wirecat/cli-core/mail";
|
|
3
|
+
import { listReview, REVIEW_SOURCES } from "../review/review.js";
|
|
4
|
+
import { counted } from "../review/status.js";
|
|
5
|
+
import { scopedAccounts } from "../store/group.js";
|
|
6
|
+
import { knownSenders } from "./known.js";
|
|
7
|
+
import { calendarChanges, crmChanges, driveChanges, isCalendarAccount, isCrmAccount, isDriveAccount, } from "./sources.js";
|
|
8
|
+
import { HEALTH_REASONS, healthOf, SOURCE_WORDS, syncRunsOf } from "./sync-health.js";
|
|
9
|
+
import { REVIEW_TASKS, TASK_AGENTS, taskAgentNotes, taskProposals, waitingTasks } from "./task-proposals.js";
|
|
10
|
+
import { digestRunBefore, gatherTasks, previousDigestAt } from "./tasks.js";
|
|
11
|
+
/** The tag that puts a chat, mail thread, person, project or meeting series on the owner's watch list. */
|
|
12
|
+
export const WATCH_TAG = "watch";
|
|
13
|
+
export const SECTIONS = [
|
|
14
|
+
"watch",
|
|
15
|
+
"owed",
|
|
16
|
+
"mail",
|
|
17
|
+
"meetings",
|
|
18
|
+
"calendar",
|
|
19
|
+
"drive",
|
|
20
|
+
"crm",
|
|
21
|
+
"tasks",
|
|
22
|
+
"projects",
|
|
23
|
+
"sources",
|
|
24
|
+
"proposals",
|
|
25
|
+
];
|
|
26
|
+
export const SCOPE_KINDS = ["telegram", "max", "whatsapp", "mail", "meeting", "task"];
|
|
27
|
+
/** The digest source an account belongs to; one that is none of them stays in. */
|
|
28
|
+
const sourceOf = (provider) => MESSENGERS.has(provider)
|
|
29
|
+
? provider
|
|
30
|
+
: provider === "email"
|
|
31
|
+
? "mail"
|
|
32
|
+
: kindOf(provider) === "meetings"
|
|
33
|
+
? "meetings"
|
|
34
|
+
: isDriveAccount(provider)
|
|
35
|
+
? "drive"
|
|
36
|
+
: isCalendarAccount(provider)
|
|
37
|
+
? "calendar"
|
|
38
|
+
: isCrmAccount(provider)
|
|
39
|
+
? "crm"
|
|
40
|
+
: undefined;
|
|
41
|
+
const DAY = 86_400_000;
|
|
42
|
+
const MESSENGERS = new Set(["telegram", "max", "whatsapp"]);
|
|
43
|
+
const HEALTH_ORDER = HEALTH_REASONS;
|
|
44
|
+
/** A named reason first, in its order; an account that is only behind comes last. */
|
|
45
|
+
const healthRank = (entry) => (entry.reason === null ? HEALTH_ORDER.length : HEALTH_ORDER.indexOf(entry.reason));
|
|
46
|
+
const UNNAMED = "unnamed account";
|
|
47
|
+
/** Dialogs with a messenger's own service account: no person there is owed a reply. */
|
|
48
|
+
const SERVICE_CHATS = { telegram: new Set(["777000"]) };
|
|
49
|
+
/** The dialogs of an account that are not with a person: bots, as the messenger marks them, and service chats. */
|
|
50
|
+
const notPeopleOf = async (store, key) => {
|
|
51
|
+
const found = new Set(SERVICE_CHATS[key.provider] ?? []);
|
|
52
|
+
for (let offset = 0;; offset += 500) {
|
|
53
|
+
const page = await store.chats.chats(key, { limit: 500, offset });
|
|
54
|
+
for (const chat of page.items)
|
|
55
|
+
if (chat.kind === "dialog" && chat.providerMetadata?.isBot === true)
|
|
56
|
+
found.add(chat.id);
|
|
57
|
+
if (!page.hasMore)
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
return found;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* What a person calls each account: its name and username, a mailbox its address. Never the raw id; an account with
|
|
64
|
+
* neither is named by the profile that signs in to it, and two of a provider with one name get theirs added.
|
|
65
|
+
*/
|
|
66
|
+
const labelsOf = async (store, keys) => {
|
|
67
|
+
const stored = new Map((await store.accounts.storedAccounts()).map((one) => [name(one), one.name]));
|
|
68
|
+
const profiles = Object.values(await store.accounts.profiles()).flatMap((byProfile) => Object.entries(byProfile));
|
|
69
|
+
const profileOf = (key) => profiles.find(([, held]) => held.provider === key.provider && held.account === key.account)?.[0];
|
|
70
|
+
const labels = new Map();
|
|
71
|
+
for (const key of keys) {
|
|
72
|
+
if (key.provider === "email") {
|
|
73
|
+
labels.set(name(key), key.account);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const person = await store.people.personOf({ provider: key.provider, id: key.account });
|
|
77
|
+
const username = person?.identities.find((one) => one.provider === key.provider && one.id === key.account)?.username;
|
|
78
|
+
const given = stored.get(name(key));
|
|
79
|
+
const label = [given && given !== key.account ? given : null, username ? `@${username}` : null]
|
|
80
|
+
.filter(Boolean)
|
|
81
|
+
.join(" ");
|
|
82
|
+
const profile = profileOf(key);
|
|
83
|
+
labels.set(name(key), label || (profile ? `profile ${profile}` : UNNAMED));
|
|
84
|
+
}
|
|
85
|
+
const taken = new Map();
|
|
86
|
+
for (const [account, label] of labels) {
|
|
87
|
+
const word = `${account.split(":")[0]}|${label}`;
|
|
88
|
+
taken.set(word, (taken.get(word) ?? 0) + 1);
|
|
89
|
+
}
|
|
90
|
+
for (const key of keys) {
|
|
91
|
+
const label = labels.get(name(key)) ?? UNNAMED;
|
|
92
|
+
const profile = profileOf(key);
|
|
93
|
+
if ((taken.get(`${key.provider}|${label}`) ?? 0) > 1 && profile && !label.startsWith("profile "))
|
|
94
|
+
labels.set(name(key), `${label} (profile ${profile})`);
|
|
95
|
+
}
|
|
96
|
+
return labels;
|
|
97
|
+
};
|
|
98
|
+
const oneLine = (text, size) => {
|
|
99
|
+
const flat = (text ?? "").replace(/\s+/g, " ").trim();
|
|
100
|
+
if (!flat)
|
|
101
|
+
return null;
|
|
102
|
+
return flat.length > size ? `${flat.slice(0, size - 1)}…` : flat;
|
|
103
|
+
};
|
|
104
|
+
const iso = (ms) => new Date(ms).toISOString();
|
|
105
|
+
const name = (key) => `${key.provider}:${key.account}`;
|
|
106
|
+
const section = async (name, found, limit, next, total = found.length) => {
|
|
107
|
+
const kept = found.sort((a, b) => b.item.at.localeCompare(a.item.at)).slice(0, limit);
|
|
108
|
+
const items = await Promise.all(kept.map(async (one) => ({ ...one.item, ...(await one.fill?.()) })));
|
|
109
|
+
return { name, items, total, next };
|
|
110
|
+
};
|
|
111
|
+
const messageFill = (store, key, chatId, messageId, size) => async () => {
|
|
112
|
+
if (messageId === null)
|
|
113
|
+
return {};
|
|
114
|
+
const message = await store.messages.message(key, messageId, { chatId });
|
|
115
|
+
return { ...(message?.senderName ? { who: message.senderName } : {}), excerpt: oneLine(message?.text, size) };
|
|
116
|
+
};
|
|
117
|
+
const mailFill = (store, accountId, externalId, size) => async () => {
|
|
118
|
+
const email = await store.mail.email(accountId, externalId);
|
|
119
|
+
return {
|
|
120
|
+
who: email?.fromName ?? email?.fromAddress ?? null,
|
|
121
|
+
excerpt: oneLine([email?.subject, email?.snippet].filter(Boolean).join(" — "), size),
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
/** The words a project status finding carries, by the shape its signal gives it. */
|
|
125
|
+
const statusLine = (data) => {
|
|
126
|
+
const text = data.excerpt ?? data.title;
|
|
127
|
+
if (typeof text === "string")
|
|
128
|
+
return text;
|
|
129
|
+
if (data.amount !== undefined)
|
|
130
|
+
return [data.direction, data.amount, data.currency, data.state].filter(Boolean).join(" ");
|
|
131
|
+
if (data.next !== undefined)
|
|
132
|
+
return `next: ${String(data.next)}${data.overdue ? ", overdue" : ""}`;
|
|
133
|
+
return "";
|
|
134
|
+
};
|
|
135
|
+
const personal = (newest) => !newest.bulk && !newest.list && !newest.envelope && !newest.demoted;
|
|
136
|
+
/**
|
|
137
|
+
* What the morning needs from the store alone, no model call and no network: the watch list, replies owed, new
|
|
138
|
+
* personal mail, meetings that ended, tasks due, projects that moved, proposals waiting. Every item names its
|
|
139
|
+
* reference, so an agent reads further only where it points.
|
|
140
|
+
*/
|
|
141
|
+
export const gatherDigest = async (store, env, { since, now: clock = Date.now(), until, limit, excerpt, owedWithin, newSince, sources: only = [] }) => {
|
|
142
|
+
const now = until ?? clock;
|
|
143
|
+
const by = (at) => until === undefined || at <= until;
|
|
144
|
+
const upTo = (found) => found.filter((one) => by(Date.parse(one.item.at)));
|
|
145
|
+
const window = (now - since) / DAY;
|
|
146
|
+
const days = `${Math.max(1, Math.ceil(window))}d`;
|
|
147
|
+
const reads = (source) => only.length === 0 || only.includes(source);
|
|
148
|
+
const scoped = await scopedAccounts(store, env);
|
|
149
|
+
const accounts = scoped.filter((key) => {
|
|
150
|
+
const source = sourceOf(key.provider);
|
|
151
|
+
return source === undefined || reads(source);
|
|
152
|
+
});
|
|
153
|
+
const messengers = accounts.filter((key) => MESSENGERS.has(key.provider));
|
|
154
|
+
const mailboxes = accounts.filter((key) => key.provider === "email");
|
|
155
|
+
const owedSince = Math.min(since, now - owedWithin);
|
|
156
|
+
const watched = {
|
|
157
|
+
chats: new Map(),
|
|
158
|
+
people: new Set(),
|
|
159
|
+
projects: new Set(),
|
|
160
|
+
series: new Set(),
|
|
161
|
+
};
|
|
162
|
+
for (const key of [...messengers, ...mailboxes]) {
|
|
163
|
+
const rows = await store.tags.tags(key, { type: "chat", tag: WATCH_TAG });
|
|
164
|
+
if (rows.length)
|
|
165
|
+
watched.chats.set(name(key), rows.map((row) => String(row.chatId)));
|
|
166
|
+
}
|
|
167
|
+
// A meeting is tagged in its account's scope, a person or project in none.
|
|
168
|
+
for (const scope of [null, ...accounts])
|
|
169
|
+
for (const row of (await store.knowledge.labelled(scope, { tag: WATCH_TAG, limit: 200 })).items) {
|
|
170
|
+
const target = row.target;
|
|
171
|
+
if (target.type === "person")
|
|
172
|
+
watched.people.add(target.id);
|
|
173
|
+
if (target.type === "project")
|
|
174
|
+
watched.projects.add(target.id);
|
|
175
|
+
if (target.type === "meeting") {
|
|
176
|
+
const meeting = await store.meetings.meeting(Number(target.id));
|
|
177
|
+
if (meeting?.meeting.meetingSeriesId)
|
|
178
|
+
watched.series.add(meeting.meeting.meetingSeriesId);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const isWatchedChat = (key, chat) => watched.chats.get(name(key))?.includes(chat) === true;
|
|
182
|
+
const coverage = [];
|
|
183
|
+
const watch = [];
|
|
184
|
+
const owed = [];
|
|
185
|
+
const mail = [];
|
|
186
|
+
const owedNext = [];
|
|
187
|
+
const mailNext = [];
|
|
188
|
+
let bulk = 0;
|
|
189
|
+
let olderMail = 0;
|
|
190
|
+
const unknown = { count: 0, next: [] };
|
|
191
|
+
const syncRuns = syncRunsOf(env);
|
|
192
|
+
const labels = await labelsOf(store, [...messengers, ...mailboxes]);
|
|
193
|
+
const health = [];
|
|
194
|
+
const checkHealth = (key, activity) => {
|
|
195
|
+
const found = healthOf(syncRuns(key), activity, now);
|
|
196
|
+
if (found)
|
|
197
|
+
health.push({
|
|
198
|
+
source: SOURCE_WORDS[key.provider] ?? key.provider,
|
|
199
|
+
account: labels.get(name(key)) ?? UNNAMED,
|
|
200
|
+
...found,
|
|
201
|
+
refs: [],
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
let chatsMoved = 0;
|
|
205
|
+
let mailMoved = 0;
|
|
206
|
+
for (const key of messengers) {
|
|
207
|
+
const { chats, storedAt } = await store.chats.chatActivity(key, owedSince);
|
|
208
|
+
const month = (await store.chats.chatActivity(key, now - 30 * DAY)).chats;
|
|
209
|
+
checkHealth(key, {
|
|
210
|
+
newest: month.reduce((most, chat) => Math.max(most ?? 0, Date.parse(chat.lastMessageAt)), null),
|
|
211
|
+
moved30d: month.length,
|
|
212
|
+
storedAt: storedAt === null ? null : Date.parse(storedAt),
|
|
213
|
+
});
|
|
214
|
+
const ref = (chat) => formatReference({ type: "chat", provider: key.provider, account: key.account, chat });
|
|
215
|
+
chatsMoved += chats.filter((chat) => Date.parse(chat.lastMessageAt) >= since && by(Date.parse(chat.lastMessageAt))).length;
|
|
216
|
+
coverage.push({
|
|
217
|
+
account: name(key),
|
|
218
|
+
storedAt,
|
|
219
|
+
waiting: chats.filter((chat) => chat.lastFromOwner === true && Date.parse(chat.lastMessageAt) >= since).length,
|
|
220
|
+
unsynced: chats.filter((chat) => chat.lastMessageId === null && Date.parse(chat.lastMessageAt) >= since).length,
|
|
221
|
+
});
|
|
222
|
+
// A dialog whose newest message the sync has not stored yet may be someone waiting: it is listed, marked so.
|
|
223
|
+
const notSynced = (chat) => chat.lastMessageId === null && Date.parse(chat.lastMessageAt) >= since;
|
|
224
|
+
const owedChats = chats.filter((chat) => !isWatchedChat(key, chat.chatId) && chat.kind === "dialog" && (chat.lastFromOwner === false || notSynced(chat)));
|
|
225
|
+
const notPeople = owedChats.length ? await notPeopleOf(store, key) : new Set();
|
|
226
|
+
let owedHere = 0;
|
|
227
|
+
for (const chat of owedChats) {
|
|
228
|
+
if (notPeople.has(chat.chatId))
|
|
229
|
+
continue;
|
|
230
|
+
owed.push({
|
|
231
|
+
item: {
|
|
232
|
+
ref: ref(chat.chatId),
|
|
233
|
+
who: chat.title,
|
|
234
|
+
at: chat.lastMessageAt,
|
|
235
|
+
excerpt: null,
|
|
236
|
+
why: notSynced(chat) ? "newest message not synced: may be owed" : "owed reply",
|
|
237
|
+
},
|
|
238
|
+
fill: messageFill(store, key, chat.chatId, chat.lastMessageId, excerpt),
|
|
239
|
+
});
|
|
240
|
+
owedHere++;
|
|
241
|
+
}
|
|
242
|
+
if (owedHere)
|
|
243
|
+
owedNext.push(`wcat tasks agenda --source ${name(key)} --unanswered 1m --within ${Math.ceil(owedWithin / DAY)}d`);
|
|
244
|
+
for (const chatId of watched.chats.get(name(key)) ?? []) {
|
|
245
|
+
const page = await store.messages.messages(key, chatId, {
|
|
246
|
+
limit,
|
|
247
|
+
since: iso(since),
|
|
248
|
+
...(until === undefined ? {} : { until }),
|
|
249
|
+
});
|
|
250
|
+
for (const message of page.items)
|
|
251
|
+
watch.push({
|
|
252
|
+
item: {
|
|
253
|
+
ref: formatReference({
|
|
254
|
+
type: "message",
|
|
255
|
+
provider: key.provider,
|
|
256
|
+
account: key.account,
|
|
257
|
+
chat: chatId,
|
|
258
|
+
message: message.id,
|
|
259
|
+
}),
|
|
260
|
+
who: message.outgoing ? "you" : message.senderName,
|
|
261
|
+
at: message.timestamp,
|
|
262
|
+
excerpt: oneLine(message.text, excerpt),
|
|
263
|
+
why: "watched chat",
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
for (const key of mailboxes) {
|
|
269
|
+
const stored = await store.accounts.storedAccount(key);
|
|
270
|
+
const threads = await store.mail.threadActivity(stored.id, Math.min(owedSince, now - OWED_DAYS * DAY));
|
|
271
|
+
const ref = (thread) => formatReference({ type: "chat", provider: "email", account: key.account, chat: thread });
|
|
272
|
+
const newest = threads.reduce((most, thread) => Math.max(most, thread.lastEmailAt), 0);
|
|
273
|
+
checkHealth(key, {
|
|
274
|
+
newest: newest || null,
|
|
275
|
+
moved30d: threads.filter((thread) => thread.lastEmailAt >= now - 30 * DAY).length,
|
|
276
|
+
storedAt: newest || null,
|
|
277
|
+
});
|
|
278
|
+
mailMoved += threads.filter((thread) => thread.lastEmailAt >= since && by(thread.lastEmailAt) && thread.newest !== null && personal(thread.newest)).length;
|
|
279
|
+
coverage.push({
|
|
280
|
+
account: name(key),
|
|
281
|
+
storedAt: newest ? iso(newest) : null,
|
|
282
|
+
waiting: threads.filter((thread) => mailTurn(thread.newest) === "waiting" && thread.lastEmailAt >= since).length,
|
|
283
|
+
unsynced: 0,
|
|
284
|
+
});
|
|
285
|
+
let owedHere = 0;
|
|
286
|
+
let newHere = 0;
|
|
287
|
+
const owedMail = [];
|
|
288
|
+
for (const thread of threads) {
|
|
289
|
+
const last = thread.newest;
|
|
290
|
+
if (last === null)
|
|
291
|
+
continue;
|
|
292
|
+
const inWindow = thread.lastEmailAt >= since;
|
|
293
|
+
if (!personal(last)) {
|
|
294
|
+
if (inWindow)
|
|
295
|
+
bulk++;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const pending = (why) => ({
|
|
299
|
+
item: {
|
|
300
|
+
ref: ref(thread.threadId),
|
|
301
|
+
who: null,
|
|
302
|
+
at: iso(thread.lastEmailAt),
|
|
303
|
+
excerpt: oneLine(thread.subject, excerpt),
|
|
304
|
+
why,
|
|
305
|
+
},
|
|
306
|
+
fill: mailFill(store, stored.id, last.externalId, excerpt),
|
|
307
|
+
});
|
|
308
|
+
if (isWatchedChat(key, thread.threadId)) {
|
|
309
|
+
if (inWindow)
|
|
310
|
+
watch.push(pending("watched thread"));
|
|
311
|
+
}
|
|
312
|
+
else if (mailTurn(last) === "owed") {
|
|
313
|
+
// Mail owed from before the window was in an earlier digest; repeating hundreds of it hides today's.
|
|
314
|
+
if (inWindow)
|
|
315
|
+
owedMail.push({ pending: pending("owed reply"), externalId: last.externalId });
|
|
316
|
+
else if (thread.lastEmailAt >= owedSince)
|
|
317
|
+
olderMail++;
|
|
318
|
+
owedHere++;
|
|
319
|
+
}
|
|
320
|
+
else if (inWindow && !last.outgoing) {
|
|
321
|
+
mail.push(pending("new mail"));
|
|
322
|
+
newHere++;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const known = await knownSenders(store, stored.id, owedMail.map((one) => one.externalId));
|
|
326
|
+
const strangers = owedMail.filter((one) => !known.has(one.externalId));
|
|
327
|
+
for (const one of owedMail)
|
|
328
|
+
if (known.has(one.externalId))
|
|
329
|
+
owed.push(one.pending);
|
|
330
|
+
// Listed with the mail, not the replies owed: a new sender is as often a client as a cold pitch.
|
|
331
|
+
for (const one of strangers)
|
|
332
|
+
mail.push({ ...one.pending, item: { ...one.pending.item, why: "owed reply, new sender" } });
|
|
333
|
+
unknown.count += strangers.length;
|
|
334
|
+
if (owedHere)
|
|
335
|
+
owedNext.push(`wcat review mail --source ${name(key)} --unanswered 1m bulk:false`);
|
|
336
|
+
if (strangers.length)
|
|
337
|
+
unknown.next.push(`wcat review mail --source ${name(key)} --unanswered 1m bulk:false`);
|
|
338
|
+
if (newHere)
|
|
339
|
+
mailNext.push(`wcat review mail --source ${name(key)} date>${days} bulk:false`);
|
|
340
|
+
}
|
|
341
|
+
for (const uid of watched.people) {
|
|
342
|
+
const person = await store.people.personByUid(uid);
|
|
343
|
+
if (!person)
|
|
344
|
+
continue;
|
|
345
|
+
for (const identity of person.identities)
|
|
346
|
+
for (const account of identity.accounts) {
|
|
347
|
+
const key = { provider: identity.provider, account };
|
|
348
|
+
if (!MESSENGERS.has(key.provider))
|
|
349
|
+
continue;
|
|
350
|
+
for (const stats of await store.messages.senderStats(key, identity.id)) {
|
|
351
|
+
if (stats.lastAt === null || Date.parse(stats.lastAt) < since)
|
|
352
|
+
continue;
|
|
353
|
+
watch.push({
|
|
354
|
+
item: {
|
|
355
|
+
ref: formatReference({ type: "chat", provider: key.provider, account, chat: stats.chatId }),
|
|
356
|
+
who: person.name,
|
|
357
|
+
at: stats.lastAt,
|
|
358
|
+
excerpt: oneLine(stats.title, excerpt),
|
|
359
|
+
why: `watched person:${uid} wrote`,
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const meetings = [];
|
|
366
|
+
for (const meeting of reads("meetings") ? await store.meetings.meetings({ since, limit: 100 }) : []) {
|
|
367
|
+
const ended = meeting.endedAt ?? meeting.startedAt;
|
|
368
|
+
if (ended === null || ended < since || meeting.deletedAt !== null)
|
|
369
|
+
continue;
|
|
370
|
+
meetings.push({
|
|
371
|
+
item: {
|
|
372
|
+
ref: formatMeetingReference({ type: "meeting", accountId: meeting.accountId, meetingId: meeting.id }),
|
|
373
|
+
who: null,
|
|
374
|
+
at: iso(ended),
|
|
375
|
+
excerpt: oneLine(meeting.title, excerpt),
|
|
376
|
+
why: meeting.meetingSeriesId !== null && watched.series.has(meeting.meetingSeriesId)
|
|
377
|
+
? "watched series"
|
|
378
|
+
: "meeting",
|
|
379
|
+
},
|
|
380
|
+
fill: async () => {
|
|
381
|
+
const details = await store.meetings.meeting(meeting.id);
|
|
382
|
+
const summary = details?.summaries[0];
|
|
383
|
+
const transcripts = details?.transcripts.length ?? 0;
|
|
384
|
+
return {
|
|
385
|
+
who: details ? `${details.participants.length} people` : null,
|
|
386
|
+
excerpt: oneLine([meeting.title, summary?.text].filter(Boolean).join(" — "), excerpt),
|
|
387
|
+
why: `${meeting.meetingSeriesId !== null && watched.series.has(meeting.meetingSeriesId) ? "watched series, " : ""}${transcripts ? "transcript stored" : "no transcript"}`,
|
|
388
|
+
};
|
|
389
|
+
},
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
const reading = { since, now, excerpt };
|
|
393
|
+
const none = { found: [], next: [] };
|
|
394
|
+
const calendar = reads("calendar") ? await calendarChanges(store, accounts, reading) : none;
|
|
395
|
+
const drive = reads("drive") ? await driveChanges(store, accounts, reading) : none;
|
|
396
|
+
const crm = reads("crm") ? await crmChanges(store, accounts, reading) : none;
|
|
397
|
+
const tasksSince = newSince ?? (until === undefined ? previousDigestAt(env, now) : digestRunBefore(env, until));
|
|
398
|
+
const hot = reads("tasks")
|
|
399
|
+
? // Tasks taken from chats and mail count under tasks, read or not their source.
|
|
400
|
+
await gatherTasks(store, scoped.filter((key) => MESSENGERS.has(key.provider) || key.provider === "email"), {
|
|
401
|
+
now,
|
|
402
|
+
newSince: tasksSince,
|
|
403
|
+
...(until === undefined ? {} : { until }),
|
|
404
|
+
})
|
|
405
|
+
: {
|
|
406
|
+
tasks: [],
|
|
407
|
+
counts: { overdue: 0, today: 0, tomorrow: 0, new: 0, newSince: tasksSince, undated: 0 },
|
|
408
|
+
accounts: 0,
|
|
409
|
+
};
|
|
410
|
+
const tasks = hot.tasks.map(({ task, groups, askedBy, for: doer }) => ({
|
|
411
|
+
item: {
|
|
412
|
+
ref: task.ref,
|
|
413
|
+
who: askedBy,
|
|
414
|
+
at: task.dueAt ?? task.createdAt,
|
|
415
|
+
excerpt: oneLine(task.title, excerpt),
|
|
416
|
+
why: groups.join(", "),
|
|
417
|
+
due: task.dueAt,
|
|
418
|
+
for: doer,
|
|
419
|
+
},
|
|
420
|
+
}));
|
|
421
|
+
const projects = [];
|
|
422
|
+
const projectNext = [];
|
|
423
|
+
for (const project of await store.knowledge.projects()) {
|
|
424
|
+
const status = await projectStatus(store, { project: project.ref, after: since });
|
|
425
|
+
const fresh = status.items.filter((item) => item.signal !== "coverage" && item.at !== null && Date.parse(item.at) >= since);
|
|
426
|
+
const isWatched = watched.projects.has(project.id) || watched.projects.has(project.ref);
|
|
427
|
+
if (fresh.length === 0 && !isWatched)
|
|
428
|
+
continue;
|
|
429
|
+
projectNext.push(`wcat projects status ${project.key ?? project.ref} --since-time ${days}`);
|
|
430
|
+
if (fresh.length === 0)
|
|
431
|
+
projects.push({
|
|
432
|
+
item: { ref: project.ref, who: null, at: iso(since), excerpt: project.name, why: "watched project, quiet" },
|
|
433
|
+
});
|
|
434
|
+
for (const item of fresh)
|
|
435
|
+
projects.push({
|
|
436
|
+
item: {
|
|
437
|
+
ref: item.evidence[0]?.ref ?? item.chat ?? project.ref,
|
|
438
|
+
who: item.who?.owner ? "you" : (item.who?.name ?? null),
|
|
439
|
+
at: item.at,
|
|
440
|
+
excerpt: oneLine(`${project.key ?? project.name}: ${statusLine(item.data)}`, excerpt),
|
|
441
|
+
why: `${isWatched ? "watched project, " : ""}${item.signal}`,
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
// A review refreshed in place keeps its raise time, so it is listed once, when it was raised or grew graver.
|
|
446
|
+
const reviews = await listReview(store, env, [`kind:${SOURCE_REVIEW_KIND}`], { limit: 50, page: 1 });
|
|
447
|
+
const sourceItems = reviews.items
|
|
448
|
+
.filter((row) => Date.parse(row.createdAt) >= since && by(Date.parse(row.createdAt)))
|
|
449
|
+
.map((row) => ({
|
|
450
|
+
item: {
|
|
451
|
+
ref: row.subject,
|
|
452
|
+
who: row.proposer,
|
|
453
|
+
at: row.createdAt,
|
|
454
|
+
excerpt: oneLine(row.title, excerpt),
|
|
455
|
+
why: `review ${row.id}: ${row.summary ?? "sources changed"}`,
|
|
456
|
+
},
|
|
457
|
+
}));
|
|
458
|
+
const reviewCount = sourceItems.length;
|
|
459
|
+
const reviewed = new Set(reviews.items.flatMap((row) => row.evidence));
|
|
460
|
+
for (const changed of await store.knowledge.changedSources({ since }))
|
|
461
|
+
if (!reviewed.has(changed.ref) && by(Date.parse(changed.checkedAt)))
|
|
462
|
+
sourceItems.push({
|
|
463
|
+
item: {
|
|
464
|
+
ref: changed.ref,
|
|
465
|
+
who: null,
|
|
466
|
+
at: changed.checkedAt,
|
|
467
|
+
excerpt: null,
|
|
468
|
+
why: "changed since a memory or fact cited it; no findings batch reads it yet",
|
|
469
|
+
},
|
|
470
|
+
});
|
|
471
|
+
const waiting = await counted(store, env, { status: "proposed" });
|
|
472
|
+
const proposed = await listReview(store, env, [], { limit, page: 1 });
|
|
473
|
+
// Batches with tasks first: hundreds of identity links would otherwise fill the newest page on their own.
|
|
474
|
+
const withTasks = await taskProposals(store, env);
|
|
475
|
+
const taskIds = new Set(withTasks.batches.map((row) => row.id));
|
|
476
|
+
const proposals = [...withTasks.batches, ...proposed.items.filter((row) => !taskIds.has(row.id))]
|
|
477
|
+
.slice(0, limit)
|
|
478
|
+
.map((row) => {
|
|
479
|
+
const tasks = waitingTasks(row);
|
|
480
|
+
return {
|
|
481
|
+
item: {
|
|
482
|
+
ref: row.id,
|
|
483
|
+
who: row.proposer,
|
|
484
|
+
at: row.createdAt,
|
|
485
|
+
excerpt: oneLine(row.title, excerpt),
|
|
486
|
+
why: tasks > 0 ? `${row.kind}: ${tasks} ${tasks === 1 ? "task" : "tasks"}` : row.kind,
|
|
487
|
+
},
|
|
488
|
+
};
|
|
489
|
+
});
|
|
490
|
+
const proposalsNext = [
|
|
491
|
+
"wcat review list",
|
|
492
|
+
...(withTasks.tasks > 0
|
|
493
|
+
? [
|
|
494
|
+
REVIEW_TASKS,
|
|
495
|
+
`# ${withTasks.tasks} proposed tasks wait in ${withTasks.batches.length} batches: ${REVIEW_TASKS}`,
|
|
496
|
+
]
|
|
497
|
+
: []),
|
|
498
|
+
];
|
|
499
|
+
// A past day's agenda says nothing of today's schedules.
|
|
500
|
+
const taskNotes = reads("tasks") && until === undefined
|
|
501
|
+
? taskAgentNotes(env, TASK_AGENTS.filter((agent) => (agent.reads === "mail" ? mailboxes.length > 0 : messengers.length > 0)))
|
|
502
|
+
: [];
|
|
503
|
+
const sections = [
|
|
504
|
+
await section("watch", upTo(watch), limit, [
|
|
505
|
+
"wcat tags list tag:watch",
|
|
506
|
+
...[...watched.people].map((uid) => `wcat context person:${uid}`),
|
|
507
|
+
]),
|
|
508
|
+
{
|
|
509
|
+
...(await section("owed", upTo(owed), limit, [
|
|
510
|
+
...owedNext,
|
|
511
|
+
...(olderMail ? [`# ${olderMail} mail threads owed from before the window left out`] : []),
|
|
512
|
+
])),
|
|
513
|
+
...(unknown.count ? { unknown } : {}),
|
|
514
|
+
},
|
|
515
|
+
await section("mail", upTo(mail), limit, [
|
|
516
|
+
...mailNext,
|
|
517
|
+
...(bulk ? [`# ${bulk} bulk or list threads left out`] : []),
|
|
518
|
+
]),
|
|
519
|
+
await section("meetings", upTo(meetings), limit, ["wcat search meetings <words>"]),
|
|
520
|
+
await section("calendar", calendar.found, limit, calendar.next),
|
|
521
|
+
await section("drive", drive.found, limit, drive.next),
|
|
522
|
+
await section("crm", crm.found, limit, crm.next),
|
|
523
|
+
await section("tasks", tasks, limit, ["wcat tasks list", ...taskNotes]),
|
|
524
|
+
await section("projects", upTo(projects), limit, projectNext),
|
|
525
|
+
await section("sources", sourceItems, limit, [
|
|
526
|
+
REVIEW_SOURCES,
|
|
527
|
+
...(reviewCount > 0 ? [`# decide them: ${REVIEW_SOURCES}`] : []),
|
|
528
|
+
...(sourceItems.length > reviewCount
|
|
529
|
+
? [`# read changed sources again: wcat memories check --since-time ${days} --json`]
|
|
530
|
+
: []),
|
|
531
|
+
]),
|
|
532
|
+
await section("proposals", upTo(proposals), limit, proposalsNext, waiting.total),
|
|
533
|
+
];
|
|
534
|
+
const providerCount = (provider) => accounts.filter((key) => key.provider === provider).length;
|
|
535
|
+
const meetingAccounts = accounts.filter((key) => kindOf(key.provider) === "meetings").length;
|
|
536
|
+
const sources = [
|
|
537
|
+
{ kind: "telegram", accounts: providerCount("telegram") },
|
|
538
|
+
{ kind: "max", accounts: providerCount("max") },
|
|
539
|
+
{ kind: "whatsapp", accounts: providerCount("whatsapp") },
|
|
540
|
+
{ kind: "mail", accounts: mailboxes.length },
|
|
541
|
+
{ kind: "meeting", accounts: meetingAccounts },
|
|
542
|
+
{ kind: "task", accounts: hot.accounts },
|
|
543
|
+
];
|
|
544
|
+
return {
|
|
545
|
+
since: iso(since),
|
|
546
|
+
at: iso(now),
|
|
547
|
+
scope: {
|
|
548
|
+
from: iso(since),
|
|
549
|
+
to: iso(now),
|
|
550
|
+
sources: sources.filter((one) => one.accounts > 0),
|
|
551
|
+
counts: { chats: chatsMoved, mail: mailMoved, tasks: hot.tasks.length, meetings: upTo(meetings).length },
|
|
552
|
+
},
|
|
553
|
+
tasks: hot.counts,
|
|
554
|
+
health: health.sort((a, b) => healthRank(a) - healthRank(b)),
|
|
555
|
+
coverage,
|
|
556
|
+
sections,
|
|
557
|
+
untrusted: ["sections.items.who", "sections.items.excerpt", "sections.items.for"],
|
|
558
|
+
};
|
|
559
|
+
};
|
|
560
|
+
//# sourceMappingURL=digest.js.map
|