@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,171 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { answerEntity, LOCAL_READ, LOCAL_WRITE, parseProposalIds, SOURCE_REVIEW_KIND, withQuery, } from "@wirecat/cli-core";
|
|
4
|
+
import { mailMark } from "@wirecat/cli-core/mail";
|
|
5
|
+
import * as v from "valibot";
|
|
6
|
+
import { answers, itemAnswer, listAnswer, plainText, withStore } from "../answer.js";
|
|
7
|
+
import { byOption, deciderOf } from "../author.js";
|
|
8
|
+
import { reviewAgendaCommand, sinceOf } from "../digest/command.js";
|
|
9
|
+
import { evidenceContext } from "../knowledge/project-actions.js";
|
|
10
|
+
import { positive, whole } from "../options.js";
|
|
11
|
+
import { PROPOSAL_ROW } from "../rows.js";
|
|
12
|
+
import { reviewOf } from "../store/guard.js";
|
|
13
|
+
import { decidedText, decisionOf, EVIDENCE_UNTRUSTED, listReview, REVIEW_QUERY, reviewSteps, reviewText, senderOf, showReview, sourceReviewDetail, } from "./review.js";
|
|
14
|
+
import { reviewStatus, reviewStatusText } from "./status.js";
|
|
15
|
+
/** Proposals counted by kind; `complete` false means at least `count`, past the pages read. */
|
|
16
|
+
const COUNTED = v.strictObject({
|
|
17
|
+
count: v.number(),
|
|
18
|
+
kinds: v.record(v.string(), v.number()),
|
|
19
|
+
complete: v.boolean(),
|
|
20
|
+
});
|
|
21
|
+
export const REVIEW_STATUS = v.strictObject({
|
|
22
|
+
since: v.string(),
|
|
23
|
+
at: v.string(),
|
|
24
|
+
/** Per mail account, `email:<address>`: threads with new mail since, owed and waiting ones, the agents' marks. */
|
|
25
|
+
mail: v.array(v.strictObject({
|
|
26
|
+
account: v.string(),
|
|
27
|
+
threads: v.number(),
|
|
28
|
+
owed: v.number(),
|
|
29
|
+
waiting: v.number(),
|
|
30
|
+
coverage: v.array(mailMark),
|
|
31
|
+
})),
|
|
32
|
+
/** Proposed since `since`, whatever became of them. */
|
|
33
|
+
proposed: COUNTED,
|
|
34
|
+
/** Waiting for the owner now. */
|
|
35
|
+
waiting: COUNTED,
|
|
36
|
+
quiet: v.boolean(),
|
|
37
|
+
});
|
|
38
|
+
const PROPOSAL = v.strictObject({
|
|
39
|
+
id: v.string(),
|
|
40
|
+
kind: v.string(),
|
|
41
|
+
status: v.picklist(["proposed", "confirmed", "rejected"]),
|
|
42
|
+
title: v.string(),
|
|
43
|
+
project: v.nullable(v.string()),
|
|
44
|
+
project_title: v.nullable(v.string()),
|
|
45
|
+
source: v.nullable(v.string()),
|
|
46
|
+
owner_only: v.boolean(),
|
|
47
|
+
subject: v.string(),
|
|
48
|
+
object: v.nullable(v.string()),
|
|
49
|
+
summary: v.nullable(v.string()),
|
|
50
|
+
proposer: v.string(),
|
|
51
|
+
proposed_by: v.unknown(),
|
|
52
|
+
reason: v.nullable(v.string()),
|
|
53
|
+
score: v.nullable(v.number()),
|
|
54
|
+
signals: v.unknown(),
|
|
55
|
+
evidence: v.array(v.string()),
|
|
56
|
+
parts: v.unknown(),
|
|
57
|
+
created_at: v.string(),
|
|
58
|
+
});
|
|
59
|
+
/** How the owner answers a source review, said wherever one is decided. */
|
|
60
|
+
export const SOURCE_REVIEW_HELP = "A memory_source_review is yours alone: confirm says the memory or fact still holds, reject dismisses the review; " +
|
|
61
|
+
"both sign its sources again as they are now, and an agent is refused. To correct it, add the right one with " +
|
|
62
|
+
"memories add --supersedes (or facts add --supersedes); to withdraw it, memories invalidate or facts reverse.";
|
|
63
|
+
const json = (command) => command.option("--json", "print JSON; --json=id,title keeps only those fields");
|
|
64
|
+
export const reviewCommand = (program, streams, env) => {
|
|
65
|
+
const { print } = answers(program, streams, env);
|
|
66
|
+
const review = program
|
|
67
|
+
.command("review")
|
|
68
|
+
.description("every proposal waiting for your decision, across projects: links, key documents, facts, invoices, payments and more")
|
|
69
|
+
.summary("every proposal waiting for your decision, across projects");
|
|
70
|
+
json(answerEntity(withQuery(annotate(review.command("list", { isDefault: true }), { effects: LOCAL_READ })
|
|
71
|
+
.description("what waits for the owner's decision, newest first, with titles, who proposed it, why and the evidence")
|
|
72
|
+
.summary("what waits for your decision, newest first, with titles and evidence"), REVIEW_QUERY), "memo_proposal", PROPOSAL, { row: PROPOSAL_ROW }))
|
|
73
|
+
.option("--limit <n>", "proposals per page, at most 50", positive, 20)
|
|
74
|
+
.option("--page <n>", "which page, from 1", positive, 1)
|
|
75
|
+
.option("--compact", "one line per proposal")
|
|
76
|
+
.action(async (words, given) => {
|
|
77
|
+
if (given.limit > 50)
|
|
78
|
+
throw new CliError("validation_error", "--limit is at most 50", { param: "limit" });
|
|
79
|
+
const found = await withStore(env, (store) => listReview(store, env, words, given));
|
|
80
|
+
const steps = reviewSteps(found.items);
|
|
81
|
+
const body = listAnswer("review list", {
|
|
82
|
+
items: found.items,
|
|
83
|
+
limit: given.limit,
|
|
84
|
+
page: given.page,
|
|
85
|
+
has_more: found.hasMore,
|
|
86
|
+
args: { query: words.join(" "), limit: given.limit },
|
|
87
|
+
...(steps.length ? { next: steps } : {}),
|
|
88
|
+
});
|
|
89
|
+
print(given.json, body, reviewText(found.items, found.hasMore), given.compact);
|
|
90
|
+
});
|
|
91
|
+
json(annotate(review.command("show"), { effects: LOCAL_READ }))
|
|
92
|
+
.description("one proposal with its titles, signals and the text around each piece of evidence; a memory_source_review " +
|
|
93
|
+
"also shows each source as it was cited and as it is now, and the command for each decision")
|
|
94
|
+
.summary("one proposal with its titles, signals and the text around each piece of evidence")
|
|
95
|
+
.addHelpText("after", `\n${SOURCE_REVIEW_HELP}`)
|
|
96
|
+
.argument("<id>", "the proposal's id, as review lists it: 17070, fact:512, memory:88, link:17, payment:4, close:Q-15")
|
|
97
|
+
.option("--brief", "only references and their titles, without excerpts or nearby text")
|
|
98
|
+
.option("--before-n <n>", "messages or document paragraphs before the evidence, at most 5", whole, 2)
|
|
99
|
+
.option("--after-n <n>", "messages or document paragraphs after the evidence, at most 5", whole, 2)
|
|
100
|
+
.option("--compact", "one line, as review prints it")
|
|
101
|
+
.action(async (id, given) => {
|
|
102
|
+
const body = await withStore(env, async (store) => {
|
|
103
|
+
const shown = await showReview(store, env, id);
|
|
104
|
+
const window = {
|
|
105
|
+
brief: given.brief === true,
|
|
106
|
+
before: Math.min(given.beforeN, 5),
|
|
107
|
+
after: Math.min(given.afterN, 5),
|
|
108
|
+
};
|
|
109
|
+
const evidence = await Promise.all(shown.evidence.map(async (one) => {
|
|
110
|
+
const sender = window.brief ? null : await senderOf(store, one.ref);
|
|
111
|
+
return {
|
|
112
|
+
...(window.brief ? {} : await evidenceContext(store, one.ref, null, shown.reason ?? "", window)),
|
|
113
|
+
...one,
|
|
114
|
+
...(sender === null ? {} : { sender }),
|
|
115
|
+
untrusted: EVIDENCE_UNTRUSTED,
|
|
116
|
+
};
|
|
117
|
+
}));
|
|
118
|
+
return itemAnswer({
|
|
119
|
+
...shown,
|
|
120
|
+
evidence,
|
|
121
|
+
...(shown.kind === SOURCE_REVIEW_KIND
|
|
122
|
+
? { sourceReview: await sourceReviewDetail(store, shown.id, shown.subject) }
|
|
123
|
+
: {}),
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
print(given.json, body, plainText(body), given.compact);
|
|
127
|
+
});
|
|
128
|
+
for (const name of ["confirm", "reject"]) {
|
|
129
|
+
const command = byOption(json(annotate(review.command(name), { effects: LOCAL_WRITE })))
|
|
130
|
+
.description(name === "confirm"
|
|
131
|
+
? "confirm proposals by id or range (17070-17079,fact:500-502,17080/f1); each is decided on its own, so a " +
|
|
132
|
+
"refusal leaves the others decided. An agent decides only with --reason, never its own or a scan's"
|
|
133
|
+
: "turn proposals down by id or range, with why; each is decided on its own")
|
|
134
|
+
.summary(name === "confirm" ? "confirm proposals by id or range; each on its own" : "turn proposals down, with why")
|
|
135
|
+
.argument("<ids...>", name === "confirm"
|
|
136
|
+
? "ids or ranges as review lists them; 17080/f1 accepts that finding and rejects the batch's others"
|
|
137
|
+
: "ids or ranges as review lists them; a batch is turned down whole");
|
|
138
|
+
if (name === "confirm")
|
|
139
|
+
command.option("--reason <text>", "why, in a few words; required when an agent decides");
|
|
140
|
+
else
|
|
141
|
+
command.requiredOption("--reason <text>", "why it is turned down, in a few words");
|
|
142
|
+
command.option("--compact", "one line per decision");
|
|
143
|
+
command.addHelpText("after", `\n${SOURCE_REVIEW_HELP}`);
|
|
144
|
+
command.action(async (words, given) => {
|
|
145
|
+
const ids = parseProposalIds(words);
|
|
146
|
+
const by = await deciderOf(command, env, {
|
|
147
|
+
...given,
|
|
148
|
+
question: `${name} ${ids.length} proposal${ids.length === 1 ? "" : "s"} as you, the owner?`,
|
|
149
|
+
});
|
|
150
|
+
const result = await withStore(env, async (store) => (await reviewOf(store, env)).decide(ids, decisionOf(name === "confirm", by, given.reason)));
|
|
151
|
+
const issues = result.refused.map((one) => ({
|
|
152
|
+
code: one.code,
|
|
153
|
+
source: one.id,
|
|
154
|
+
...(one.reason.includes(".") ? { reason: one.reason } : {}),
|
|
155
|
+
}));
|
|
156
|
+
print(given.json, itemAnswer(result, issues.length ? { meta: { complete: false, issues } } : undefined), decidedText(result), given.compact);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
reviewAgendaCommand(review, print, streams, env);
|
|
160
|
+
json(answerEntity(annotate(review.command("status"), { effects: LOCAL_READ }), "review_status", REVIEW_STATUS))
|
|
161
|
+
.summary("since yesterday: new mail, what is owed and waiting, what agents proposed")
|
|
162
|
+
.description("the owner's daily look, with no model call: per mail account the threads with new mail, what you owe and " +
|
|
163
|
+
"wait for, and how far each agent's processing mark has read; then what was proposed and what waits")
|
|
164
|
+
.option("--since-time <time>", "how far back: hours or days (12h, 7d) or a start date (2026-11-01)", "1d")
|
|
165
|
+
.action(async (given) => {
|
|
166
|
+
const since = sinceOf(given.sinceTime);
|
|
167
|
+
const status = await withStore(env, (store) => reviewStatus(store, env, since));
|
|
168
|
+
print(given.json, itemAnswer(status), reviewStatusText(status));
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { MAIL_FINDINGS_KIND, MEETING_FINDINGS_KIND, proposalRegistry, SOURCE_REVIEW_KIND, } from "@wirecat/cli-core";
|
|
2
|
+
/** Every kind `wcat review` shows, as `kind:` takes them. */
|
|
3
|
+
export const REVIEW_KINDS = [
|
|
4
|
+
"relationship",
|
|
5
|
+
"relationship_update",
|
|
6
|
+
"key_document",
|
|
7
|
+
"fact",
|
|
8
|
+
"memory",
|
|
9
|
+
SOURCE_REVIEW_KIND,
|
|
10
|
+
"findings",
|
|
11
|
+
"meeting_findings",
|
|
12
|
+
MAIL_FINDINGS_KIND,
|
|
13
|
+
"task_close",
|
|
14
|
+
"action",
|
|
15
|
+
"invoice",
|
|
16
|
+
"payment",
|
|
17
|
+
"order",
|
|
18
|
+
"contract",
|
|
19
|
+
"subscription",
|
|
20
|
+
"subscription_price",
|
|
21
|
+
"transaction",
|
|
22
|
+
"identity_link",
|
|
23
|
+
"identity_split",
|
|
24
|
+
];
|
|
25
|
+
const BY_ACCOUNT = [MEETING_FINDINGS_KIND, MAIL_FINDINGS_KIND];
|
|
26
|
+
/** cli-core's registry, with each mail and meeting batch grouped under the account it came from. */
|
|
27
|
+
export const reviewRegistry = (store) => {
|
|
28
|
+
const registry = proposalRegistry(store);
|
|
29
|
+
const sourced = async (row) => {
|
|
30
|
+
if (!BY_ACCOUNT.includes(row.kind))
|
|
31
|
+
return row;
|
|
32
|
+
const { account } = await store.proposedActions.get(row.id);
|
|
33
|
+
return { ...row, source: account === null ? null : `${account.provider}:${account.account}` };
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
...registry,
|
|
37
|
+
list: async (filter) => {
|
|
38
|
+
const found = await registry.list(filter);
|
|
39
|
+
return { ...found, items: await Promise.all(found.items.map(sourced)) };
|
|
40
|
+
},
|
|
41
|
+
get: async (id) => sourced(await registry.get(id)),
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=kinds.js.map
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { stepOf } from "@wirecat/cli-base/standards";
|
|
3
|
+
import { queryTerms, refLabel, SOURCE_REVIEW_KIND, termField, } from "@wirecat/cli-core";
|
|
4
|
+
import { showMail } from "@wirecat/cli-core/mail";
|
|
5
|
+
import { proposalsOf, reviewOf } from "../store/guard.js";
|
|
6
|
+
import { canonicalProject } from "../vocabulary/project.js";
|
|
7
|
+
import { REVIEW_KINDS, reviewRegistry } from "./kinds.js";
|
|
8
|
+
export { REVIEW_KINDS };
|
|
9
|
+
const STATUSES = ["proposed", "confirmed", "rejected", "all"];
|
|
10
|
+
export const REVIEW_QUERY = {
|
|
11
|
+
entity: "memo_proposal",
|
|
12
|
+
backend: "native",
|
|
13
|
+
fields: [
|
|
14
|
+
termField("project", "kw", "project:HRB"),
|
|
15
|
+
termField("kind", "kw", "kind:relationship,fact"),
|
|
16
|
+
termField("by", "kw", "by:agent"),
|
|
17
|
+
termField("status", "enum", "status:proposed", { values: STATUSES }),
|
|
18
|
+
termField("via", "ref", 'via:"chat:max/1/-100"', {
|
|
19
|
+
relation: "a reference among the evidence, such as the group a scan found its senders in",
|
|
20
|
+
}),
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
export const filterOf = async (store, words) => {
|
|
24
|
+
const terms = queryTerms(words, REVIEW_QUERY, "review");
|
|
25
|
+
const project = terms.get("project");
|
|
26
|
+
const kinds = terms
|
|
27
|
+
.get("kind")
|
|
28
|
+
?.split(",")
|
|
29
|
+
.map((one) => one.trim())
|
|
30
|
+
.filter(Boolean);
|
|
31
|
+
const unknown = kinds?.find((one) => !REVIEW_KINDS.includes(one));
|
|
32
|
+
if (unknown !== undefined)
|
|
33
|
+
throw new CliError("validation_error", `no proposal kind ${unknown}; kinds: ${REVIEW_KINDS.join(", ")}`, {
|
|
34
|
+
param: "kind",
|
|
35
|
+
});
|
|
36
|
+
const by = terms.get("by");
|
|
37
|
+
const via = terms.get("via");
|
|
38
|
+
return {
|
|
39
|
+
...(project === undefined ? {} : { project: await canonicalProject(store, project) }),
|
|
40
|
+
...(kinds?.length ? { kinds } : {}),
|
|
41
|
+
...(by === undefined ? {} : { by: by === "agent" || by === "rule" ? by : { bot: by } }),
|
|
42
|
+
...(via === undefined ? {} : { via }),
|
|
43
|
+
status: terms.get("status") ?? "proposed",
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export const proposerName = (proposer) => proposer.type === "agent" ? proposer.name : proposer.type === "person" ? "you" : "unknown";
|
|
47
|
+
/** Titles for every ref a page names, read in one batch; a ref the store does not know has none. */
|
|
48
|
+
export const labelsFor = async (store, refs) => {
|
|
49
|
+
const wanted = [...new Set(refs.filter((ref) => typeof ref === "string" && ref !== ""))];
|
|
50
|
+
const summaries = wanted.length ? await store.refs.summaries(wanted) : new Map();
|
|
51
|
+
return (ref) => {
|
|
52
|
+
if (ref === null)
|
|
53
|
+
return null;
|
|
54
|
+
const summary = summaries.get(ref);
|
|
55
|
+
return summary === undefined || summary.kind === "unknown" || summary.state === "unavailable"
|
|
56
|
+
? null
|
|
57
|
+
: refLabel(summary);
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const titleOf = (row, label) => {
|
|
61
|
+
const subject = label(row.subject) ?? row.subject;
|
|
62
|
+
const object = label(row.object) ?? row.object;
|
|
63
|
+
switch (row.kind) {
|
|
64
|
+
case "relationship":
|
|
65
|
+
return `${subject} → ${object}${row.summary ? ` as ${row.summary}` : ""}`;
|
|
66
|
+
case "relationship_update":
|
|
67
|
+
return `${subject}: ${row.summary ?? "change"}`;
|
|
68
|
+
case "key_document":
|
|
69
|
+
return `${subject} → key document of ${object}`;
|
|
70
|
+
case "fact":
|
|
71
|
+
return row.summary === null ? subject : `"${row.summary}"`;
|
|
72
|
+
case "findings":
|
|
73
|
+
case "meeting_findings":
|
|
74
|
+
case "mail_findings":
|
|
75
|
+
return `${row.summary ?? "findings"}${row.parts?.length ? `: ${row.parts.map((part) => part.kind).join(" · ")}` : ""}`;
|
|
76
|
+
case SOURCE_REVIEW_KIND:
|
|
77
|
+
return `${subject}: ${row.summary ?? "sources changed"}${object === null ? "" : ` → ${object}`}`;
|
|
78
|
+
case "task_close":
|
|
79
|
+
return row.summary ?? subject;
|
|
80
|
+
case "action":
|
|
81
|
+
return `${row.summary ?? "action"} ${subject}`;
|
|
82
|
+
case "invoice":
|
|
83
|
+
case "payment":
|
|
84
|
+
case "order":
|
|
85
|
+
case "contract":
|
|
86
|
+
case "subscription":
|
|
87
|
+
case "subscription_price":
|
|
88
|
+
case "transaction":
|
|
89
|
+
return row.summary ?? subject;
|
|
90
|
+
default:
|
|
91
|
+
return object === null ? subject : `${subject} → ${object}`;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
export const reviewItem = (row, label) => ({
|
|
95
|
+
id: row.id,
|
|
96
|
+
kind: row.kind,
|
|
97
|
+
status: row.status,
|
|
98
|
+
title: titleOf(row, label),
|
|
99
|
+
project: row.project,
|
|
100
|
+
projectTitle: label(row.project),
|
|
101
|
+
source: row.source ?? row.project,
|
|
102
|
+
ownerOnly: row.ownerOnly === true,
|
|
103
|
+
subject: row.subject,
|
|
104
|
+
object: row.object,
|
|
105
|
+
summary: row.summary,
|
|
106
|
+
proposer: proposerName(row.proposedBy),
|
|
107
|
+
proposedBy: row.proposedBy,
|
|
108
|
+
reason: row.reason,
|
|
109
|
+
score: row.score,
|
|
110
|
+
signals: row.signals,
|
|
111
|
+
evidence: row.evidence,
|
|
112
|
+
parts: row.parts,
|
|
113
|
+
createdAt: row.createdAt,
|
|
114
|
+
});
|
|
115
|
+
const rowRefs = (row) => [row.subject, row.object, row.project];
|
|
116
|
+
export const listReview = async (store, env, words, { limit, page }) => {
|
|
117
|
+
const filter = await filterOf(store, words);
|
|
118
|
+
const found = await (await reviewOf(store, env)).list({ ...filter, limit, offset: (page - 1) * limit });
|
|
119
|
+
const label = await labelsFor(store, found.items.flatMap(rowRefs));
|
|
120
|
+
return { items: found.items.map((row) => reviewItem(row, label)), hasMore: found.hasMore };
|
|
121
|
+
};
|
|
122
|
+
export const REVIEW_SOURCES = "wcat review list kind:memory_source_review";
|
|
123
|
+
/** One proposal as `review list` shows it, read by id. */
|
|
124
|
+
export const reviewItemOf = async (store, id) => {
|
|
125
|
+
const row = await reviewRegistry(store).get(id);
|
|
126
|
+
return reviewItem(row, await labelsFor(store, rowRefs(row)));
|
|
127
|
+
};
|
|
128
|
+
const TEXT_SHOWN = 2000;
|
|
129
|
+
const shown = (text) => text === null || text.length <= TEXT_SHOWN ? text : `${text.slice(0, TEXT_SHOWN - 1)}…`;
|
|
130
|
+
/**
|
|
131
|
+
* What a `memory_source_review` asks of the owner: each source as it was cited and as it is now, the challenges and
|
|
132
|
+
* suggestions, and the command for each decision. The review holds no source text; it is read here, as data.
|
|
133
|
+
*/
|
|
134
|
+
export const sourceReviewDetail = async (store, id, target) => {
|
|
135
|
+
const payload = (await store.proposedActions.get(id)).payload;
|
|
136
|
+
const texts = new Map((await store.knowledge.sourceReviewTexts(id)).map((one) => [one.link, one]));
|
|
137
|
+
const withdraw = target.startsWith("fact:") ? `wcat facts reverse ${target}` : `wcat memories invalidate ${target}`;
|
|
138
|
+
return {
|
|
139
|
+
cause: payload.cause,
|
|
140
|
+
raisedAt: payload.raisedAt,
|
|
141
|
+
sources: payload.sources.map((source) => {
|
|
142
|
+
const text = texts.get(source.link);
|
|
143
|
+
return {
|
|
144
|
+
ref: source.ref,
|
|
145
|
+
kind: source.kind ?? null,
|
|
146
|
+
cause: source.cause,
|
|
147
|
+
replacement: source.replacement ?? null,
|
|
148
|
+
quote: text?.quote ?? null,
|
|
149
|
+
cited: shown(text?.cited ?? null),
|
|
150
|
+
now: shown(text?.now ?? null),
|
|
151
|
+
};
|
|
152
|
+
}),
|
|
153
|
+
challenges: payload.challenges,
|
|
154
|
+
suggestions: (payload.suggestions ?? []).map(({ author, body, evidence, at }) => ({ author, body, evidence, at })),
|
|
155
|
+
decide: {
|
|
156
|
+
stillTrue: `wcat review confirm ${id}`,
|
|
157
|
+
dismiss: `wcat review reject ${id} --reason <why>`,
|
|
158
|
+
correct: `wcat ${target.startsWith("fact:") ? "facts" : "memories"} add <the right text and its options> --supersedes ${target}`,
|
|
159
|
+
withdraw,
|
|
160
|
+
},
|
|
161
|
+
untrusted: ["sources.quote", "sources.cited", "sources.now", "challenges.reason", "suggestions.body"],
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
export const showReview = async (store, env, id) => {
|
|
165
|
+
const row = await (await reviewOf(store, env)).get(id);
|
|
166
|
+
const label = await labelsFor(store, [...rowRefs(row), ...row.evidence]);
|
|
167
|
+
return {
|
|
168
|
+
...reviewItem(row, label),
|
|
169
|
+
evidence: row.evidence.map((ref) => ({ ref, title: label(ref) })),
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
/** Evidence text is written by others: an agent reads it as data, never as instructions. */
|
|
173
|
+
export const EVIDENCE_UNTRUSTED = ["title", "text", "around", "sender.name"];
|
|
174
|
+
/**
|
|
175
|
+
* Who sent an email cited as evidence: the sender's score, and whether the address is known — linked to a person
|
|
176
|
+
* who has another identity — so a stranger's "I am your accountant" stands out. `null` for anything not an email.
|
|
177
|
+
*/
|
|
178
|
+
export const senderOf = async (store, ref) => {
|
|
179
|
+
if (!ref.startsWith("msg:email/"))
|
|
180
|
+
return null;
|
|
181
|
+
const email = (await showMail(store, ref).catch(() => []))[0]?.email;
|
|
182
|
+
const from = email?.from;
|
|
183
|
+
if (!from)
|
|
184
|
+
return null;
|
|
185
|
+
const person = from.ref?.startsWith("person:") ? await store.people.personByUid(from.ref.slice(7)) : undefined;
|
|
186
|
+
const identities = person?.identities ?? [];
|
|
187
|
+
return {
|
|
188
|
+
address: from.address,
|
|
189
|
+
name: from.name,
|
|
190
|
+
person: from.ref,
|
|
191
|
+
known: identities.length > 1 || identities.some((one) => one.provider !== "email"),
|
|
192
|
+
score: email.senderScore?.score ?? null,
|
|
193
|
+
signals: email.senderScore?.signals ?? [],
|
|
194
|
+
demoted: email.senderScore?.demoted === true,
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
/** `17078,17079,17080,fact:5` → `17078-17080,fact:5`: what a confirm step names, short enough to read. */
|
|
198
|
+
export const idRanges = (ids) => {
|
|
199
|
+
const numbers = ids
|
|
200
|
+
.filter((id) => /^\d+$/.test(id))
|
|
201
|
+
.map(Number)
|
|
202
|
+
.sort((a, b) => a - b);
|
|
203
|
+
const spans = [];
|
|
204
|
+
for (let at = 0; at < numbers.length;) {
|
|
205
|
+
let end = at;
|
|
206
|
+
while (end + 1 < numbers.length && numbers[end + 1] === numbers[end] + 1)
|
|
207
|
+
end++;
|
|
208
|
+
spans.push(end === at ? String(numbers[at]) : `${numbers[at]}-${numbers[end]}`);
|
|
209
|
+
at = end + 1;
|
|
210
|
+
}
|
|
211
|
+
return [...spans, ...ids.filter((id) => !/^\d+$/.test(id))].join(",");
|
|
212
|
+
};
|
|
213
|
+
const CONFIRM_STEP = {
|
|
214
|
+
id: "review.confirm",
|
|
215
|
+
kind: "command",
|
|
216
|
+
command: "review confirm",
|
|
217
|
+
args: [{ name: "ids", required: true }],
|
|
218
|
+
why: "confirm the {count} listed; review reject <ids> --reason turns one down",
|
|
219
|
+
};
|
|
220
|
+
const SHOW_STEP = {
|
|
221
|
+
id: "review.show",
|
|
222
|
+
kind: "command",
|
|
223
|
+
command: "review show",
|
|
224
|
+
args: [{ name: "id", required: true }],
|
|
225
|
+
why: "one proposal with its evidence",
|
|
226
|
+
};
|
|
227
|
+
export const reviewSteps = (items) => {
|
|
228
|
+
const pending = items.filter((item) => item.status === "proposed");
|
|
229
|
+
const first = pending[0];
|
|
230
|
+
if (first === undefined)
|
|
231
|
+
return [];
|
|
232
|
+
return [
|
|
233
|
+
stepOf(CONFIRM_STEP, {
|
|
234
|
+
args: { ids: idRanges(pending.map((item) => item.id)) },
|
|
235
|
+
values: { count: pending.length },
|
|
236
|
+
}),
|
|
237
|
+
stepOf(SHOW_STEP, { args: { id: first.id } }),
|
|
238
|
+
];
|
|
239
|
+
};
|
|
240
|
+
const day = (iso) => iso.slice(5, 10);
|
|
241
|
+
const cut = (text, width) => {
|
|
242
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
243
|
+
return flat.length > width ? `${flat.slice(0, width - 1)}…` : flat;
|
|
244
|
+
};
|
|
245
|
+
const sourceOf = (item) => item.projectTitle ?? item.source ?? "no project or account";
|
|
246
|
+
/**
|
|
247
|
+
* Grouped by where each proposal came from, the group of the newest first; two lines a proposal, what it is, then
|
|
248
|
+
* why and the first evidence, and a batch's findings under it.
|
|
249
|
+
*/
|
|
250
|
+
export const reviewText = (items, hasMore) => {
|
|
251
|
+
if (!items.length)
|
|
252
|
+
return "nothing waits for a decision";
|
|
253
|
+
const width = items.reduce((most, item) => Math.max(most, item.id.length), 0);
|
|
254
|
+
const groups = new Map();
|
|
255
|
+
for (const item of items)
|
|
256
|
+
groups.set(sourceOf(item), [...(groups.get(sourceOf(item)) ?? []), item]);
|
|
257
|
+
const pad = " ".repeat(width);
|
|
258
|
+
const lines = [...groups].flatMap(([source, group], at) => [
|
|
259
|
+
...(at === 0 ? [] : [""]),
|
|
260
|
+
source,
|
|
261
|
+
...group.flatMap((item) => {
|
|
262
|
+
const head = [
|
|
263
|
+
item.id.padEnd(width),
|
|
264
|
+
item.kind,
|
|
265
|
+
cut(item.title, 90),
|
|
266
|
+
...(item.score === null ? [] : [item.score.toFixed(2)]),
|
|
267
|
+
item.proposer,
|
|
268
|
+
day(item.createdAt),
|
|
269
|
+
...(item.ownerOnly ? ["owner only"] : []),
|
|
270
|
+
...(item.status === "proposed" ? [] : [item.status]),
|
|
271
|
+
].join(" ");
|
|
272
|
+
const why = [item.reason && cut(item.reason, 100), item.evidence[0]].filter(Boolean).join(" · ");
|
|
273
|
+
const parts = (item.parts ?? []).map((part) => `${pad} ${item.id}/${part.id} ${part.kind} ${cut(part.summary, 80)}${part.outcome ? ` ${part.outcome}` : ""}`);
|
|
274
|
+
return [head, ...(why ? [`${pad} ${why}`] : []), ...parts];
|
|
275
|
+
}),
|
|
276
|
+
]);
|
|
277
|
+
return [...lines, `${items.length} shown${hasMore ? ", more with --page" : ""}`].join("\n");
|
|
278
|
+
};
|
|
279
|
+
export const decidedText = ({ decided, refused, }) => [
|
|
280
|
+
...decided.map((one) => `${one.status.padEnd(9)} ${one.id}${one.made.length ? ` → ${one.made.join(" ")}` : ""}`),
|
|
281
|
+
...refused.map((one) => `${"refused".padEnd(9)} ${one.id} · ${one.message} (${one.reason})`),
|
|
282
|
+
].join("\n") || "nothing decided";
|
|
283
|
+
/** An agent's reason already rides in `by`; given twice, a findings batch would keep it twice. */
|
|
284
|
+
export const decisionOf = (confirm, by, reason) => {
|
|
285
|
+
const why = reason?.trim();
|
|
286
|
+
return { confirm, by, ...(by === "owner" && why ? { reason: why } : {}) };
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* An old decide command's one proposal, through the same registry and check as `review confirm`: a refusal is
|
|
290
|
+
* thrown as the error the store would have raised.
|
|
291
|
+
*/
|
|
292
|
+
export const decideOne = async (store, env, id, decision) => {
|
|
293
|
+
const { decided, refused } = await (await proposalsOf(store, env)).decide([id], decision);
|
|
294
|
+
const refusal = refused[0];
|
|
295
|
+
if (refusal)
|
|
296
|
+
throw new CliError(refusal.code, refusal.message, { reason: refusal.reason });
|
|
297
|
+
return decided[0];
|
|
298
|
+
};
|
|
299
|
+
//# sourceMappingURL=review.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { mailTurn, markItem, marksOf, OWED_DAYS } from "@wirecat/cli-core/mail";
|
|
2
|
+
import { scopedAccounts } from "../store/group.js";
|
|
3
|
+
import { reviewOf } from "../store/guard.js";
|
|
4
|
+
/** Pages read to count proposals; past them the count says "at least". */
|
|
5
|
+
const MOST_PAGES = 10;
|
|
6
|
+
export const counted = async (store, env, filter, since) => {
|
|
7
|
+
const registry = await reviewOf(store, env);
|
|
8
|
+
const byKind = {};
|
|
9
|
+
let total = 0;
|
|
10
|
+
for (let page = 0; page < MOST_PAGES; page++) {
|
|
11
|
+
const found = await registry.list({ ...filter, limit: 50, offset: page * 50 });
|
|
12
|
+
const fresh = since === undefined ? found.items : found.items.filter((row) => Date.parse(row.createdAt) >= since);
|
|
13
|
+
for (const row of fresh)
|
|
14
|
+
byKind[row.kind] = (byKind[row.kind] ?? 0) + 1;
|
|
15
|
+
total += fresh.length;
|
|
16
|
+
if (!found.hasMore || fresh.length < found.items.length)
|
|
17
|
+
return { total, byKind, complete: true };
|
|
18
|
+
}
|
|
19
|
+
return { total, byKind, complete: false };
|
|
20
|
+
};
|
|
21
|
+
/** How many proposals wait for the owner about these references: as subject, linked object or project. */
|
|
22
|
+
export const waitingAbout = async (store, env, refs) => {
|
|
23
|
+
const wanted = new Set(refs);
|
|
24
|
+
const registry = await reviewOf(store, env);
|
|
25
|
+
const kinds = {};
|
|
26
|
+
let count = 0;
|
|
27
|
+
for (let page = 0; page < MOST_PAGES; page++) {
|
|
28
|
+
const found = await registry.list({ status: "proposed", limit: 50, offset: page * 50 });
|
|
29
|
+
for (const row of found.items)
|
|
30
|
+
if ([row.subject, row.object, row.project].some((ref) => ref !== null && wanted.has(ref))) {
|
|
31
|
+
kinds[row.kind] = (kinds[row.kind] ?? 0) + 1;
|
|
32
|
+
count++;
|
|
33
|
+
}
|
|
34
|
+
if (!found.hasMore)
|
|
35
|
+
return { count, kinds, complete: true };
|
|
36
|
+
}
|
|
37
|
+
return { count, kinds, complete: false };
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The owner's morning look, with no model call: per mail account the threads with new mail since `since`, what
|
|
41
|
+
* is owed and waiting now, and how far each agent has processed it; then what was proposed since, and what waits.
|
|
42
|
+
*/
|
|
43
|
+
export const reviewStatus = async (store, env, since, now = Date.now()) => {
|
|
44
|
+
const mail = [];
|
|
45
|
+
for (const key of (await scopedAccounts(store, env)).filter((one) => one.provider === "email")) {
|
|
46
|
+
const stored = await store.accounts.storedAccount(key);
|
|
47
|
+
const turns = (await store.mail.threadActivity(stored.id, now - OWED_DAYS * 86_400_000)).map((thread) => ({
|
|
48
|
+
at: thread.lastEmailAt,
|
|
49
|
+
turn: mailTurn(thread.newest),
|
|
50
|
+
}));
|
|
51
|
+
mail.push({
|
|
52
|
+
account: `${key.provider}:${key.account}`,
|
|
53
|
+
threads: turns.filter((one) => one.at > since).length,
|
|
54
|
+
owed: turns.filter((one) => one.turn === "owed").length,
|
|
55
|
+
waiting: turns.filter((one) => one.turn === "waiting").length,
|
|
56
|
+
coverage: (await marksOf(store, key)).map(markItem),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const proposed = await counted(store, env, { status: "all" }, since);
|
|
60
|
+
const pending = await counted(store, env, { status: "proposed" });
|
|
61
|
+
return {
|
|
62
|
+
since: new Date(since).toISOString(),
|
|
63
|
+
at: new Date(now).toISOString(),
|
|
64
|
+
mail,
|
|
65
|
+
proposed: { count: proposed.total, kinds: proposed.byKind, complete: proposed.complete },
|
|
66
|
+
waiting: { count: pending.total, kinds: pending.byKind, complete: pending.complete },
|
|
67
|
+
quiet: proposed.total === 0 &&
|
|
68
|
+
pending.total === 0 &&
|
|
69
|
+
mail.every((one) => one.threads === 0 && one.owed === 0 && one.waiting === 0),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export const kindsText = (kinds) => Object.entries(kinds)
|
|
73
|
+
.sort(([, a], [, b]) => b - a)
|
|
74
|
+
.map(([kind, count]) => `${kind} ${count}`)
|
|
75
|
+
.join(", ");
|
|
76
|
+
export const atLeast = (count, complete) => `${count}${complete ? "" : "+"}`;
|
|
77
|
+
export const reviewStatusText = (status) => {
|
|
78
|
+
const since = status.since.slice(0, 16).replace("T", " ");
|
|
79
|
+
if (status.quiet)
|
|
80
|
+
return `nothing came in, nothing was proposed and nothing waits since ${since}`;
|
|
81
|
+
return [
|
|
82
|
+
`since ${since}`,
|
|
83
|
+
...status.mail.map((one) => `${one.account} ${one.threads} thread${one.threads === 1 ? "" : "s"} with new mail · owed ${one.owed} · ` +
|
|
84
|
+
`waiting ${one.waiting} (last ${OWED_DAYS} days)`),
|
|
85
|
+
...status.mail.flatMap((one) => one.coverage.length === 0
|
|
86
|
+
? [` ${one.account}: no agent has a processing mark`]
|
|
87
|
+
: one.coverage.map((mark) => ` ${one.account}: ${mark.holder} through ${mark.through_received_at ?? mark.through_id}, ` +
|
|
88
|
+
`read ${mark.read}, held ${mark.held}`)),
|
|
89
|
+
`proposed ${atLeast(status.proposed.count, status.proposed.complete)}${status.proposed.count ? `: ${kindsText(status.proposed.kinds)}` : ""}`,
|
|
90
|
+
`waiting ${atLeast(status.waiting.count, status.waiting.complete)}${status.waiting.count ? `: ${kindsText(status.waiting.kinds)} — wcat review` : ""}`,
|
|
91
|
+
].join("\n");
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=status.js.map
|