@wirecat/wirecat 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +204 -0
- package/README.md +400 -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-YETGUQ2J.js +43 -0
- package/dist/bundle/chunk-3ME37WWB.js +31 -0
- package/dist/bundle/chunk-4WI3FO7T.js +395 -0
- package/dist/bundle/chunk-7O7XM37N.js +2 -0
- package/dist/bundle/chunk-DWQQRBQV.js +51 -0
- package/dist/bundle/chunk-FOWR5KJS.js +72 -0
- package/dist/bundle/chunk-GGRL6DTE.js +120 -0
- package/dist/bundle/chunk-KNFSW562.js +312 -0
- package/dist/bundle/chunk-KPJVVFQF.js +416 -0
- package/dist/bundle/chunk-WMPDRWVF.js +222 -0
- package/dist/bundle/chunk-X5OK73GU.js +807 -0
- package/dist/bundle/chunk-ZC4PRE6C.js +38 -0
- package/dist/bundle/entry-S4DSYEAY.js +64 -0
- package/dist/bundle/failure-FALOD7QW.js +19 -0
- package/dist/bundle/from-memo-XVOLSUOM.js +314 -0
- package/dist/bundle/program-XSZSINBU.js +14994 -0
- package/dist/bundle/server-GQ4NZUDL.js +303 -0
- package/dist/bundle/update-2EH5KHTV.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,175 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { CliError } from "@wirecat/cli-base";
|
|
4
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
5
|
+
import { backfillScheduleRun, isCalendar, LOCAL_WRITE, nextRun, readSchedule, runsBetween, SCHEDULE_DEFAULTS, scheduleFile, setExitCode, slotsOf, spentToday, } from "@wirecat/cli-core";
|
|
6
|
+
import { Option } from "commander";
|
|
7
|
+
import { answers, itemAnswer } from "../answer.js";
|
|
8
|
+
import { APP } from "../app.js";
|
|
9
|
+
import { fromAppOption, whoRuns } from "../author.js";
|
|
10
|
+
import { scheduleLimits } from "../config.js";
|
|
11
|
+
import { briefCommand } from "./brief.js";
|
|
12
|
+
import { digestCommands } from "./digest-commands.js";
|
|
13
|
+
import { agendaFlags, isDigest, readDefinition, windowStart } from "./digests.js";
|
|
14
|
+
import { historyCommand } from "./history.js";
|
|
15
|
+
import { DIGEST_SCHEDULE, digestSchedule, runTime } from "./tasks.js";
|
|
16
|
+
const DAY = 86_400_000;
|
|
17
|
+
const MINUTE = 60_000;
|
|
18
|
+
const DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
19
|
+
const localDate = (at) => {
|
|
20
|
+
const day = new Date(at);
|
|
21
|
+
return `${day.getFullYear()}-${String(day.getMonth() + 1).padStart(2, "0")}-${String(day.getDate()).padStart(2, "0")}`;
|
|
22
|
+
};
|
|
23
|
+
const dateOf = (value, flag) => {
|
|
24
|
+
const [, year, month, day] = DATE.exec(value) ?? [];
|
|
25
|
+
const date = new Date(Number(year), Number(month) - 1, Number(day));
|
|
26
|
+
if (!year || localDate(date.getTime()) !== value)
|
|
27
|
+
throw new CliError("validation_error", `${flag} takes a date, YYYY-MM-DD, not "${value}"`, { param: flag });
|
|
28
|
+
return date;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Each run the digest's timer would have started from the first day to the last, with the window it reads: from its
|
|
32
|
+
* previous time, so a weekly digest reads a week and one at 08:30 and 18:00 reads since the other time.
|
|
33
|
+
*/
|
|
34
|
+
const runsOf = (when, from, to) => {
|
|
35
|
+
const end = new Date(to);
|
|
36
|
+
end.setDate(end.getDate() + 1);
|
|
37
|
+
// Two runs on one day are told apart by their time; a digest that runs once a day keeps the plain date.
|
|
38
|
+
const timed = new Set(slotsOf(when).map((slot) => slot.at)).size > 1;
|
|
39
|
+
return runsBetween(when, from.getTime(), end.getTime()).map((at) => ({
|
|
40
|
+
date: localDate(at),
|
|
41
|
+
label: timed ? `${localDate(at)} ${new Date(at).toTimeString().slice(0, 5)}` : localDate(at),
|
|
42
|
+
at,
|
|
43
|
+
since: windowStart(when, at),
|
|
44
|
+
next: nextRun(when, at) ?? at + DAY,
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
/** What the agent reads first: which day it writes and the window its agenda reads, as the skill expects them. */
|
|
48
|
+
const inputOf = (date, at, since, sources) => `backfill: ${date}\nwindow: ${agendaFlags(since, sources)} --before-time ${new Date(at).toISOString()}\n`;
|
|
49
|
+
const usd = (value) => `$${value.toFixed(2)}`;
|
|
50
|
+
const cents = (value) => Math.round(value * 100) / 100;
|
|
51
|
+
/**
|
|
52
|
+
* `digest backfill`: the morning digest each past day would have had, built by the schedule's own agent with the
|
|
53
|
+
* agenda as of that day's run time, kept as that day's run and sent nowhere. Each day is a paid model call, so it
|
|
54
|
+
* prints the estimate unless --yes, and only the owner runs it.
|
|
55
|
+
*/
|
|
56
|
+
export const digestCommand = (program, streams, env) => {
|
|
57
|
+
const { print } = answers(program, streams, env);
|
|
58
|
+
const digest = program
|
|
59
|
+
.command("digest")
|
|
60
|
+
.description("your digests: each a name, its times, what it reads, where it is sent and your brief; run one now, pause it, " +
|
|
61
|
+
"build past days, and read the last reports with what became of each item")
|
|
62
|
+
.summary("your digests: times, sources, routes, brief, past days, history");
|
|
63
|
+
briefCommand(digest, print, env);
|
|
64
|
+
digestCommands(digest, print, env);
|
|
65
|
+
historyCommand(digest, print, streams, env);
|
|
66
|
+
fromAppOption(annotate(digest.command("backfill"), { effects: LOCAL_WRITE }))
|
|
67
|
+
.summary("build a digest's past runs, without sending them")
|
|
68
|
+
.description("build each past run a digest would have had: its schedule's agent runs as its timer does (the same skill, " +
|
|
69
|
+
"flags and cost caps), reading the agenda as of that run's time and from the digest's previous time, and the " +
|
|
70
|
+
"result is kept as that run, marked backfill, for WireCat Desktop's digests screen. It is never sent to " +
|
|
71
|
+
"Telegram or mail. A run that already has a digest is skipped. Without --yes it only prints what it would " +
|
|
72
|
+
"build and the estimate: the runs times the last run's cost. Each run is a paid model call: it stops once " +
|
|
73
|
+
"today's runs cost the schedule's daily cap or a run fails, and only you run it, never an agent. The store " +
|
|
74
|
+
"keeps what holds now, so a chat answered since reads as answered")
|
|
75
|
+
.argument("[digest]", `the digest's name, as \`wcat digest list\` shows it; ${DIGEST_SCHEDULE} when left out`)
|
|
76
|
+
.option("--since-time <time>", "the first day, YYYY-MM-DD")
|
|
77
|
+
.option("--until-time <time>", "the last day, YYYY-MM-DD; not a day whose run time is still ahead")
|
|
78
|
+
// WireCat Desktop before 0.131.73's rename sends these; kept so an older app still builds past days.
|
|
79
|
+
.addOption(new Option("--from <date>").hideHelp())
|
|
80
|
+
.addOption(new Option("--to <date>").hideHelp())
|
|
81
|
+
.option("--yes", "build them; without it, only the estimate is printed")
|
|
82
|
+
.option("--json", "print JSON")
|
|
83
|
+
.action(async (name, given, command) => {
|
|
84
|
+
const since = given.sinceTime ?? given.from;
|
|
85
|
+
const until = given.untilTime ?? given.to;
|
|
86
|
+
if (since === undefined || until === undefined)
|
|
87
|
+
throw new CliError("validation_error", "say which days: --since-time YYYY-MM-DD --until-time YYYY-MM-DD", {
|
|
88
|
+
param: since === undefined ? "--since-time" : "--until-time",
|
|
89
|
+
});
|
|
90
|
+
const from = dateOf(since, "--since-time");
|
|
91
|
+
const to = dateOf(until, "--until-time");
|
|
92
|
+
if (from > to)
|
|
93
|
+
throw new CliError("validation_error", "--since-time is after --until-time", { param: "--since-time" });
|
|
94
|
+
const digestName = name ?? DIGEST_SCHEDULE;
|
|
95
|
+
if (digestName !== DIGEST_SCHEDULE && !isDigest(env, digestName))
|
|
96
|
+
throw new CliError("not_found", `no digest ${digestName} — \`wcat digest list\` names them`, {
|
|
97
|
+
reason: "digest.not-found",
|
|
98
|
+
});
|
|
99
|
+
const { state, schedule } = digestSchedule(env, digestName);
|
|
100
|
+
if (!schedule)
|
|
101
|
+
throw new CliError("not_found", `no ${digestName} schedule to build from — wcat skill show morning-digest says how to make one`, { reason: "backfill.no-schedule" });
|
|
102
|
+
const file = scheduleFile(state, schedule.name);
|
|
103
|
+
const when = readSchedule(file).when;
|
|
104
|
+
if (!isCalendar(when))
|
|
105
|
+
throw new CliError("validation_error", `${schedule.name} does not run at set times, so it has no past runs`, {
|
|
106
|
+
reason: "backfill.not-daily",
|
|
107
|
+
schedule: schedule.name,
|
|
108
|
+
});
|
|
109
|
+
const sources = readDefinition(env, digestName)?.sources ?? [];
|
|
110
|
+
const all = runsOf(when, from, to);
|
|
111
|
+
if ((all.at(-1)?.at ?? 0) > Date.now())
|
|
112
|
+
throw new CliError("validation_error", `the ${until} digest's time has not come yet; --until-time an earlier day`, {
|
|
113
|
+
param: "--until-time",
|
|
114
|
+
});
|
|
115
|
+
const runs = join(file, "..", "runs");
|
|
116
|
+
const reported = (existsSync(runs) ? readdirSync(runs) : [])
|
|
117
|
+
.filter((file) => file.endsWith(".report.json"))
|
|
118
|
+
.map(runTime);
|
|
119
|
+
// A run its timer started late, or a backfill a minute off, still counts as that time's digest.
|
|
120
|
+
const done = (run) => reported.some((at) => at >= run.at - MINUTE && at < run.next);
|
|
121
|
+
const days = all.filter((day) => !done(day));
|
|
122
|
+
const skipped = all.filter(done).map((day) => day.label);
|
|
123
|
+
const lastCost = schedule.last?.costUsd;
|
|
124
|
+
const estimate = {
|
|
125
|
+
days: days.map((day) => day.label),
|
|
126
|
+
skipped,
|
|
127
|
+
estimateUsd: typeof lastCost === "number" ? cents(days.length * lastCost) : null,
|
|
128
|
+
};
|
|
129
|
+
const cap = readSchedule(file).maxCostPerDay ?? scheduleLimits(env).maxCostPerDay ?? SCHEDULE_DEFAULTS.maxCostPerDay;
|
|
130
|
+
if (!given.yes) {
|
|
131
|
+
const room = cap > 0 ? cap - spentToday(file) : Number.POSITIVE_INFINITY;
|
|
132
|
+
print(given.json, itemAnswer(estimate), [
|
|
133
|
+
`Would build ${days.length} day(s)${days.length ? `: ${estimate.days.join(", ")}` : ""}.`,
|
|
134
|
+
...(skipped.length ? [`Skipped, a digest exists: ${skipped.join(", ")}.`] : []),
|
|
135
|
+
estimate.estimateUsd === null
|
|
136
|
+
? "No digest run has a cost yet, so there is no estimate."
|
|
137
|
+
: `Estimate: ${usd(estimate.estimateUsd)} (${days.length} × the last run's ${usd(lastCost)}).`,
|
|
138
|
+
...(estimate.estimateUsd !== null && estimate.estimateUsd > room
|
|
139
|
+
? [`Today's cap leaves ${usd(Math.max(0, room))}: it stops there, and the rest waits for another day.`]
|
|
140
|
+
: []),
|
|
141
|
+
...(days.length ? ["Build them, sending nothing: add --yes."] : []),
|
|
142
|
+
].join("\n"));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const who = await whoRuns(command, env, { question: `spend about ${usd(estimate.estimateUsd ?? 0)}?` });
|
|
146
|
+
if (who !== "owner")
|
|
147
|
+
throw new CliError("permission_error", "a backfill spends the owner's money on model calls; the owner runs it at a terminal or in WireCat Desktop", { reason: "backfill.owner-only" });
|
|
148
|
+
const built = [];
|
|
149
|
+
const left = [];
|
|
150
|
+
for (const day of days) {
|
|
151
|
+
const failed = built.some((one) => one.exitCode !== 0);
|
|
152
|
+
if (left.length || failed || (cap > 0 && spentToday(file) >= cap)) {
|
|
153
|
+
left.push(day.label);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const run = await backfillScheduleRun(command, APP, env, file, {
|
|
157
|
+
at: new Date(day.at),
|
|
158
|
+
input: inputOf(day.date, day.at, day.since, sources),
|
|
159
|
+
});
|
|
160
|
+
built.push({ date: day.label, at: run.at, exitCode: run.exitCode, costUsd: run.costUsd ?? null });
|
|
161
|
+
}
|
|
162
|
+
const costUsd = cents(built.reduce((sum, one) => sum + (one.costUsd ?? 0), 0));
|
|
163
|
+
if (built.some((one) => one.exitCode !== 0))
|
|
164
|
+
setExitCode(command, 1);
|
|
165
|
+
print(given.json, itemAnswer({ ...estimate, built, left, costUsd }), [
|
|
166
|
+
...built.map((one) => `${one.date}: ${one.exitCode === 0 ? "built" : `failed (exit ${one.exitCode})`}${one.costUsd === null ? "" : `, ${usd(one.costUsd)}`}`),
|
|
167
|
+
...(skipped.length ? [`Skipped, a digest exists: ${skipped.join(", ")}.`] : []),
|
|
168
|
+
...(left.length
|
|
169
|
+
? [`Not built, after a failed day or once today's cap of ${usd(cap)} was spent: ${left.join(", ")}.`]
|
|
170
|
+
: []),
|
|
171
|
+
`Cost: ${usd(costUsd)}. Nothing was sent.`,
|
|
172
|
+
].join("\n"));
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
//# sourceMappingURL=backfill.js.map
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { CliError } from "@wirecat/cli-base";
|
|
6
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
7
|
+
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE, readSchedule, storePath, } from "@wirecat/cli-core";
|
|
8
|
+
import { Command, Option } from "commander";
|
|
9
|
+
import { itemAnswer, withStore } from "../answer.js";
|
|
10
|
+
import { authorOf } from "../author.js";
|
|
11
|
+
import { briefAddress, DIGEST_AGENDA, digestScheduleFile, isDigest, MORNING_DIGEST, readDefinition, runningDigest, windowFlags, } from "./digests.js";
|
|
12
|
+
/** A digest's brief address; the brief is kept in the templates table, beside the templates, with history and undo. */
|
|
13
|
+
const addressOf = (env, name) => {
|
|
14
|
+
const digest = name ?? MORNING_DIGEST;
|
|
15
|
+
if (digest !== MORNING_DIGEST && !isDigest(env, digest))
|
|
16
|
+
throw new CliError("not_found", `no digest ${digest} — \`wcat digest list\` names them`, {
|
|
17
|
+
reason: "digest.not-found",
|
|
18
|
+
});
|
|
19
|
+
return briefAddress(digest);
|
|
20
|
+
};
|
|
21
|
+
/** The brief goes into every scheduled run's prompt, so its size is its cost. */
|
|
22
|
+
export const BRIEF_LIMIT = 4000;
|
|
23
|
+
/** A digest's brief, or undefined; a machine with no store yet has none, and reading it creates no store. */
|
|
24
|
+
export const readBrief = async (env, name = MORNING_DIGEST) => {
|
|
25
|
+
if (!existsSync(storePath(env)))
|
|
26
|
+
return undefined;
|
|
27
|
+
return withStore(env, async (store) => store.templates.get(briefAddress(name))?.body);
|
|
28
|
+
};
|
|
29
|
+
/** Checks a brief the owner gives and saves it; the body it replaces stays in the history. */
|
|
30
|
+
export const checkedBrief = (given, kept = "") => {
|
|
31
|
+
const body = given.trim();
|
|
32
|
+
if (!body)
|
|
33
|
+
throw new CliError("validation_error", `the brief is empty; wcat digest brief reset removes it${kept}`, {
|
|
34
|
+
reason: "brief.empty",
|
|
35
|
+
});
|
|
36
|
+
if (body.length > BRIEF_LIMIT)
|
|
37
|
+
throw new CliError("validation_error", `the brief is ${body.length} characters; the limit is ${BRIEF_LIMIT}, because every run reads ` +
|
|
38
|
+
`it and pays for it. Nothing was saved${kept}`, { reason: "brief.too-long", chars: body.length, limit: BRIEF_LIMIT });
|
|
39
|
+
return body;
|
|
40
|
+
};
|
|
41
|
+
/** The morning-digest skill with the owner's brief after it, as the last word (NEED-2457). */
|
|
42
|
+
export const withBrief = (skill, brief, digest) => {
|
|
43
|
+
const shown = digest === undefined ? skill : `${skill}\n\n${digest}`;
|
|
44
|
+
return brief === undefined
|
|
45
|
+
? shown
|
|
46
|
+
: `${shown}\n\n## The owner's brief\n\n` +
|
|
47
|
+
"The owner wrote this himself: it adds to everything above, and where it contradicts a rule of this skill, " +
|
|
48
|
+
`the brief wins.\n\n${brief.trim()}`;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* What `skill show morning-digest` adds for the digest a scheduled run belongs to (`WCAT_SCHEDULED`): its window and
|
|
52
|
+
* sources when it is a named digest, and its brief. The morning digest made before names existed gets its brief alone.
|
|
53
|
+
*/
|
|
54
|
+
export const digestAddendum = async (env, now = Date.now()) => {
|
|
55
|
+
const name = runningDigest(env);
|
|
56
|
+
const brief = await readBrief(env, name);
|
|
57
|
+
const definition = readDefinition(env, name);
|
|
58
|
+
const file = digestScheduleFile(env, name);
|
|
59
|
+
if (!existsSync(file))
|
|
60
|
+
return { brief, digest: undefined };
|
|
61
|
+
const flags = windowFlags(env, name, readSchedule(file).when, now);
|
|
62
|
+
if (flags === undefined)
|
|
63
|
+
return { brief, digest: undefined };
|
|
64
|
+
const sources = definition?.sources ?? [];
|
|
65
|
+
return {
|
|
66
|
+
brief,
|
|
67
|
+
digest: `## This digest: ${definition?.title ?? "Morning digest"}\n\n` +
|
|
68
|
+
"Unless your input has a `backfill:` line, the agenda call is " +
|
|
69
|
+
`\`wcat ${DIGEST_AGENDA.join(" ")} ${flags}\`: this digest reads from its previous time` +
|
|
70
|
+
(sources.length ? `, and only ${sources.join(", ")}; leave everything else out of the report too.` : ".") +
|
|
71
|
+
" Where this skill says `--since-time 1d`, give that call the same `--since-time` instead. " +
|
|
72
|
+
`Keep \`"kind": "morning-digest"\` in the report: it names the report's shape, not the digest.`,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const systemEditor = (path, env) => {
|
|
76
|
+
const editor = env.VISUAL?.trim() || env.EDITOR?.trim();
|
|
77
|
+
if (!editor)
|
|
78
|
+
throw new CliError("validation_error", "set VISUAL or EDITOR, or pass the brief with --file", {
|
|
79
|
+
reason: "brief.no-editor",
|
|
80
|
+
});
|
|
81
|
+
const [program = editor, ...args] = editor.split(/\s+/);
|
|
82
|
+
const ran = spawnSync(program, [...args, path], { stdio: "inherit", env });
|
|
83
|
+
if (ran.status !== 0)
|
|
84
|
+
throw new CliError("validation_error", `the editor exited with ${ran.status ?? ran.signal}; nothing was saved`);
|
|
85
|
+
};
|
|
86
|
+
export const refuseAgent = (env) => {
|
|
87
|
+
// The brief may override the digest skill's rules, so an agent writing it could steer every later run.
|
|
88
|
+
if (authorOf(env) !== "owner")
|
|
89
|
+
throw new CliError("permission_error", "only the owner changes the digest brief, not an agent", {
|
|
90
|
+
reason: "brief.owner-only",
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
const historyOf = (store, address) => store.templates.history(address).map((entry) => ({
|
|
94
|
+
saved_at: new Date(entry.savedAt).toISOString(),
|
|
95
|
+
saved_by: entry.savedBy,
|
|
96
|
+
replaced_at: new Date(entry.replacedAt).toISOString(),
|
|
97
|
+
chars: entry.body.length,
|
|
98
|
+
}));
|
|
99
|
+
/** `digest brief`: the owner's own words on what the morning digest collects, added to its skill. */
|
|
100
|
+
export const briefCommand = (digest, print, env, editor = systemEditor) => {
|
|
101
|
+
const brief = annotate(new Command("brief"), { effects: LOCAL_READ })
|
|
102
|
+
.summary("your own instructions on what the morning digest collects")
|
|
103
|
+
.description("your own instructions on what the morning digest collects: projects, people, topics, what to skip, how many " +
|
|
104
|
+
"items. The morning-digest skill ends with them, and where they contradict its rules they win; the run " +
|
|
105
|
+
`stays read only, with wcat as its only tool and the schedule's cost cap. At most ${BRIEF_LIMIT} characters`);
|
|
106
|
+
digest.addCommand(brief);
|
|
107
|
+
annotate(brief.command("show"), { effects: LOCAL_READ })
|
|
108
|
+
.summary("the brief a digest follows, and the bodies your changes replaced")
|
|
109
|
+
.argument("[digest]", `the digest's name, as \`wcat digest list\` shows it; ${MORNING_DIGEST} when left out`)
|
|
110
|
+
.option("--json", "print JSON")
|
|
111
|
+
.action(async (name, given) => {
|
|
112
|
+
const address = addressOf(env, name);
|
|
113
|
+
const item = existsSync(storePath(env))
|
|
114
|
+
? await withStore(env, async (store) => {
|
|
115
|
+
const row = store.templates.get(address);
|
|
116
|
+
return {
|
|
117
|
+
body: row?.body ?? null,
|
|
118
|
+
chars: row?.body.length ?? 0,
|
|
119
|
+
limit: BRIEF_LIMIT,
|
|
120
|
+
updated_at: row ? new Date(row.updatedAt).toISOString() : null,
|
|
121
|
+
updated_by: row?.updatedBy ?? null,
|
|
122
|
+
history: historyOf(store, address),
|
|
123
|
+
};
|
|
124
|
+
})
|
|
125
|
+
: { body: null, chars: 0, limit: BRIEF_LIMIT, updated_at: null, updated_by: null, history: [] };
|
|
126
|
+
print(given.json, itemAnswer(item), item.body ?? "No brief: the digest follows its skill alone. `wcat digest brief edit` writes one.");
|
|
127
|
+
});
|
|
128
|
+
grantsAuthority(annotate(brief.command("edit"), { effects: LOCAL_WRITE }))
|
|
129
|
+
.summary("write the brief in $EDITOR or from --file; only you, never an agent")
|
|
130
|
+
.description(`write the brief in $EDITOR, or from --file; at most ${BRIEF_LIMIT} characters. The body it replaces is kept, ` +
|
|
131
|
+
"and --undo puts it back. Only you change it, never an agent or a read-only run")
|
|
132
|
+
.argument("[digest]", `the digest's name, as \`wcat digest list\` shows it; ${MORNING_DIGEST} when left out`)
|
|
133
|
+
.option("--file <file>", "take the brief from this file instead of opening an editor; - reads stdin")
|
|
134
|
+
.addOption(new Option("--undo", "put back the body your last change replaced").conflicts("file"))
|
|
135
|
+
.option("--json", "print JSON")
|
|
136
|
+
.action(async (name, given) => {
|
|
137
|
+
refuseAgent(env);
|
|
138
|
+
const address = addressOf(env, name);
|
|
139
|
+
const { current, previous } = await withStore(env, async (store) => ({
|
|
140
|
+
current: store.templates.get(address)?.body,
|
|
141
|
+
previous: store.templates.history(address, 1)[0]?.body,
|
|
142
|
+
}));
|
|
143
|
+
let draft;
|
|
144
|
+
let body;
|
|
145
|
+
if (given.undo) {
|
|
146
|
+
if (previous === undefined)
|
|
147
|
+
throw new CliError("validation_error", "the brief has no earlier body to put back", {
|
|
148
|
+
reason: "brief.no-history",
|
|
149
|
+
});
|
|
150
|
+
body = previous;
|
|
151
|
+
}
|
|
152
|
+
else if (given.file !== undefined) {
|
|
153
|
+
body = readFileSync(given.file === "-" ? 0 : given.file, "utf8");
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
draft = join(mkdtempSync(join(tmpdir(), "wcat-brief-")), "brief.md");
|
|
157
|
+
writeFileSync(draft, current ?? "", { mode: 0o600 });
|
|
158
|
+
editor(draft, env);
|
|
159
|
+
body = readFileSync(draft, "utf8");
|
|
160
|
+
}
|
|
161
|
+
const kept = draft ? `. Your text is in ${draft}; fix it and run again with --file ${draft}` : "";
|
|
162
|
+
body = checkedBrief(body, kept);
|
|
163
|
+
if (draft)
|
|
164
|
+
rmSync(join(draft, ".."), { recursive: true, force: true });
|
|
165
|
+
if (body === current) {
|
|
166
|
+
print(given.json, itemAnswer({ changed: false, chars: body.length }), "The brief is unchanged; nothing saved.");
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const saved = await withStore(env, async (store) => store.templates.save(address, body, "wcat"));
|
|
170
|
+
print(given.json, itemAnswer({
|
|
171
|
+
changed: true,
|
|
172
|
+
chars: body.length,
|
|
173
|
+
limit: BRIEF_LIMIT,
|
|
174
|
+
updated_at: new Date(saved.updatedAt).toISOString(),
|
|
175
|
+
}), `Saved the brief (${body.length} of ${BRIEF_LIMIT} characters); the digest's next run follows it.`);
|
|
176
|
+
});
|
|
177
|
+
grantsAuthority(annotate(brief.command("reset"), { effects: LOCAL_WRITE }))
|
|
178
|
+
.summary("remove the brief; edit --undo brings it back")
|
|
179
|
+
.description("remove the brief, so the digest follows its skill alone; edit --undo brings it back")
|
|
180
|
+
.argument("[digest]", `the digest's name, as \`wcat digest list\` shows it; ${MORNING_DIGEST} when left out`)
|
|
181
|
+
.option("--json", "print JSON")
|
|
182
|
+
.action(async (name, given) => {
|
|
183
|
+
refuseAgent(env);
|
|
184
|
+
const address = addressOf(env, name);
|
|
185
|
+
const changed = await withStore(env, async (store) => store.templates.reset(address));
|
|
186
|
+
print(given.json, itemAnswer({ changed }), changed ? "Removed the brief; wcat digest brief edit --undo brings it back." : "There was no brief.");
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=brief.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { resolvePaths, writeSecurely } from "@wirecat/cli-base";
|
|
4
|
+
import { APP } from "../app.js";
|
|
5
|
+
const recordFile = (env) => join(resolvePaths({ appName: APP.appName, prefix: APP.envPrefix, env }).state, "digest", "catch-up.json");
|
|
6
|
+
export const writeCatchUp = (env, runs) => {
|
|
7
|
+
if (runs.length === 0)
|
|
8
|
+
return;
|
|
9
|
+
const file = recordFile(env);
|
|
10
|
+
mkdirSync(join(file, ".."), { recursive: true, mode: 0o700 });
|
|
11
|
+
const kept = new Map([...readRuns(file), ...runs].map((run) => [`${run.app}/${run.schedule}`, run]));
|
|
12
|
+
writeSecurely(file, `${JSON.stringify({ runs: [...kept.values()] }, null, 2)}\n`, 0o600);
|
|
13
|
+
};
|
|
14
|
+
const readRuns = (file) => {
|
|
15
|
+
if (!existsSync(file))
|
|
16
|
+
return [];
|
|
17
|
+
try {
|
|
18
|
+
const runs = JSON.parse(readFileSync(file, "utf8"))?.runs;
|
|
19
|
+
return Array.isArray(runs) ? runs : [];
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/** The last catch-up run of each schedule, by `<app>/<schedule>`, in the shape a schedule's own last run has. */
|
|
26
|
+
export const catchUpRuns = (env) => new Map(readRuns(recordFile(env)).map((run) => [
|
|
27
|
+
`${run.app}/${run.schedule}`,
|
|
28
|
+
{ at: run.at, exitCode: run.exitCode, output: "", ...(run.reason ? { reason: run.reason } : {}) },
|
|
29
|
+
]));
|
|
30
|
+
//# sourceMappingURL=catch-up-record.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { resolvePaths } from "@wirecat/cli-base";
|
|
2
|
+
import { MESSENGER_TOOLS, runChild, toolBinary } from "../knowledge/messenger-sync.js";
|
|
3
|
+
import { catchUpRuns, writeCatchUp } from "./catch-up-record.js";
|
|
4
|
+
import { schedulesOf } from "./sync-health.js";
|
|
5
|
+
/** The `mail` CLI as `MAIL_CLI` names it; its syncs run every few minutes, so they are rarely due. */
|
|
6
|
+
const TOOLS = [...MESSENGER_TOOLS, { tool: "mail", appName: "mail-cli", envPrefix: "MAIL" }];
|
|
7
|
+
/** What the catch-up may take of a digest's run in all; the agent starts after it either way. */
|
|
8
|
+
export const CATCH_UP_MS = 4 * 60_000;
|
|
9
|
+
/** A sync that succeeded this recently is not run again. */
|
|
10
|
+
export const FRESH_MS = 60 * 60_000;
|
|
11
|
+
/** A run record's reason, not an error wcat raises. */
|
|
12
|
+
const NOT_INSTALLED = "catch-up.not-installed";
|
|
13
|
+
/** Leaves a sync time to save its last page and exit before the budget ends. */
|
|
14
|
+
const MARGIN_MS = 10_000;
|
|
15
|
+
/** The schedule's own argv with its `--timeout` set to what is left, so a sync stops in time and keeps its pages. */
|
|
16
|
+
export const withTimeout = (argv, seconds) => {
|
|
17
|
+
const value = `${seconds}s`;
|
|
18
|
+
const at = argv.indexOf("--timeout");
|
|
19
|
+
if (at >= 0 && at + 1 < argv.length)
|
|
20
|
+
return argv.map((word, index) => (index === at + 1 ? value : word));
|
|
21
|
+
const joined = argv.findIndex((word) => word.startsWith("--timeout="));
|
|
22
|
+
if (joined >= 0)
|
|
23
|
+
return argv.map((word, index) => (index === joined ? `--timeout=${value}` : word));
|
|
24
|
+
return [...argv, "--timeout", value];
|
|
25
|
+
};
|
|
26
|
+
const fresh = (run, now, freshMs) => run !== undefined && run.exitCode === 0 && now - Date.parse(run.at) < freshMs;
|
|
27
|
+
/**
|
|
28
|
+
* Before a digest reads the store, runs again each sync the owner put on a timer in tg, max, wa and mail, so the
|
|
29
|
+
* digest reads this morning's messages and not the night's. Each runs as its schedule says: its argv, its variables,
|
|
30
|
+
* its profile; wcat picks no profile and syncs no account the owner gave no schedule. A sync that succeeded within
|
|
31
|
+
* `freshMs` is left alone; the tools run side by side, a tool's schedules one after another, all within `budgetMs`.
|
|
32
|
+
*/
|
|
33
|
+
export const catchUp = async (env, { run = runChild, now = Date.now, budgetMs = CATCH_UP_MS, freshMs = FRESH_MS } = {}) => {
|
|
34
|
+
const ends = now() + budgetMs;
|
|
35
|
+
const stop = new AbortController();
|
|
36
|
+
const timer = setTimeout(() => stop.abort(), budgetMs);
|
|
37
|
+
const earlier = catchUpRuns(env);
|
|
38
|
+
try {
|
|
39
|
+
const perTool = await Promise.all(TOOLS.map(async (tool) => {
|
|
40
|
+
const state = resolvePaths({ appName: tool.appName, prefix: tool.envPrefix, env }).state;
|
|
41
|
+
const due = schedulesOf(state).filter((one) => one.kind === "command" &&
|
|
42
|
+
one.argv.includes("sync") &&
|
|
43
|
+
!one.repeats &&
|
|
44
|
+
!fresh(one.last, now(), freshMs) &&
|
|
45
|
+
!fresh(earlier.get(`${tool.appName}/${one.name}`), now(), freshMs));
|
|
46
|
+
const ran = [];
|
|
47
|
+
for (const one of due) {
|
|
48
|
+
// A timer's run has a bare PATH; each schedule keeps the PATH it was made with, as its own timer runs it.
|
|
49
|
+
const childEnv = { ...env, ...one.environment };
|
|
50
|
+
const bin = await toolBinary(tool, childEnv, run);
|
|
51
|
+
if (!bin) {
|
|
52
|
+
ran.push({
|
|
53
|
+
app: tool.appName,
|
|
54
|
+
schedule: one.name,
|
|
55
|
+
at: new Date(now()).toISOString(),
|
|
56
|
+
exitCode: 127,
|
|
57
|
+
reason: NOT_INSTALLED,
|
|
58
|
+
});
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const seconds = Math.floor((ends - now() - MARGIN_MS) / 1000);
|
|
62
|
+
if (stop.signal.aborted || seconds < 10)
|
|
63
|
+
break;
|
|
64
|
+
const done = await run(bin, withTimeout(one.argv, seconds), {
|
|
65
|
+
env: childEnv,
|
|
66
|
+
signal: stop.signal,
|
|
67
|
+
}).catch(() => ({ code: null, stdout: "" }));
|
|
68
|
+
ran.push({
|
|
69
|
+
app: tool.appName,
|
|
70
|
+
schedule: one.name,
|
|
71
|
+
at: new Date(now()).toISOString(),
|
|
72
|
+
exitCode: done.code ?? 1,
|
|
73
|
+
...(done.code === 0 ? {} : { reason: stop.signal.aborted ? "catch-up.budget" : `exit ${done.code}` }),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return ran;
|
|
77
|
+
}));
|
|
78
|
+
const runs = perTool.flat();
|
|
79
|
+
writeCatchUp(env, runs);
|
|
80
|
+
return runs;
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
clearTimeout(timer);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=catch-up.js.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { LOCAL_READ, parseDuration } from "@wirecat/cli-core";
|
|
4
|
+
import { itemAnswer, withStore } from "../answer.js";
|
|
5
|
+
import { APP } from "../app.js";
|
|
6
|
+
import { positive } from "../options.js";
|
|
7
|
+
import { gatherDigest, WATCH_TAG } from "./digest.js";
|
|
8
|
+
import { DIGEST_SOURCES, isDigest, readDefinition } from "./digests.js";
|
|
9
|
+
import { digestText, fitDigest } from "./text.js";
|
|
10
|
+
/** Roughly 10k tokens of mixed Russian and English: Cyrillic takes two bytes a letter and fewer letters a token. */
|
|
11
|
+
const COMPACT_BYTES = 40_000;
|
|
12
|
+
const FULL_BYTES = 80_000;
|
|
13
|
+
/** An owed reply older than this is left to `tasks agenda` and `review mail`, which read further back. */
|
|
14
|
+
const OWED_WITHIN = 7 * 86_400_000;
|
|
15
|
+
/** A digest's run keeps to the digest's sources even when its agent leaves out `--source`; other schedules do not. */
|
|
16
|
+
const scheduledSources = (env) => {
|
|
17
|
+
const scheduled = env[`${APP.envPrefix}_SCHEDULED`];
|
|
18
|
+
return scheduled && isDigest(env, scheduled) ? (readDefinition(env, scheduled)?.sources ?? []) : [];
|
|
19
|
+
};
|
|
20
|
+
/** `--source telegram,mail`, repeatable: what the agenda reads; each one a part it can leave out. */
|
|
21
|
+
export const sourcesOf = (value, before = []) => {
|
|
22
|
+
const words = value
|
|
23
|
+
.split(",")
|
|
24
|
+
.map((word) => word.trim().toLowerCase())
|
|
25
|
+
.filter(Boolean);
|
|
26
|
+
const unknown = words.filter((word) => !DIGEST_SOURCES.includes(word));
|
|
27
|
+
if (unknown.length)
|
|
28
|
+
throw new CliError("validation_error", `--source takes ${DIGEST_SOURCES.join(", ")}; not ${unknown.join(", ")}`, {
|
|
29
|
+
param: "source",
|
|
30
|
+
});
|
|
31
|
+
return [...new Set([...before, ...words])];
|
|
32
|
+
};
|
|
33
|
+
export const sinceOf = (value, now = Date.now()) => {
|
|
34
|
+
const since = /^\d{4}-\d{2}-\d{2}/.test(value) ? Date.parse(value) : now - parseDuration(value, "--since-time");
|
|
35
|
+
if (Number.isNaN(since))
|
|
36
|
+
throw new CliError("validation_error", `--since-time takes 12h, 7d or a date, not "${value}"`, {
|
|
37
|
+
param: "since-time",
|
|
38
|
+
});
|
|
39
|
+
return since;
|
|
40
|
+
};
|
|
41
|
+
/** A past moment, as an ISO time or a date (its local midnight); it must not be in the future. */
|
|
42
|
+
export const beforeOf = (value, now = Date.now()) => {
|
|
43
|
+
const at = /^\d{4}-\d{2}-\d{2}$/.test(value) ? new Date(`${value}T00:00:00`).getTime() : Date.parse(value);
|
|
44
|
+
if (!/^\d{4}-\d{2}-\d{2}/.test(value) || Number.isNaN(at))
|
|
45
|
+
throw new CliError("validation_error", `--before-time takes an ISO time or a date, not "${value}"`, {
|
|
46
|
+
param: "before-time",
|
|
47
|
+
});
|
|
48
|
+
if (at > now)
|
|
49
|
+
throw new CliError("validation_error", "--before-time is in the future; leave it out for now", {
|
|
50
|
+
param: "before-time",
|
|
51
|
+
});
|
|
52
|
+
return at;
|
|
53
|
+
};
|
|
54
|
+
/** `review agenda`: the morning digest an agent reads first, then follows only the `next` lines it prints. */
|
|
55
|
+
export const reviewAgendaCommand = (review, print, streams, env) => {
|
|
56
|
+
annotate(review.command("agenda"), { effects: LOCAL_READ })
|
|
57
|
+
.summary("morning digest: watched, owed, mail, meetings, calendar, Drive, CRM, tasks")
|
|
58
|
+
.description("the morning digest, from the store alone with no model call: everything new in what you tagged " +
|
|
59
|
+
`${WATCH_TAG} (chats, mail threads, people, projects, a meeting's series), replies you owe to people in ` +
|
|
60
|
+
"messengers and personal mail (not bots or service chats), new personal mail, meetings that ended, calendar " +
|
|
61
|
+
"events added, moved or cancelled and those starting within a day, Drive documents edited, CRM deals and leads " +
|
|
62
|
+
"the CRM changed (with a stage they moved to), tasks, " +
|
|
63
|
+
"projects that moved, memories and facts whose sources changed (source reviews raised since), proposals " +
|
|
64
|
+
"waiting. Tasks are the open ones created since the last morning-digest run (a " +
|
|
65
|
+
"day back when none ran) and those overdue, due today or due tomorrow, each with who asked and who does it. " +
|
|
66
|
+
"Replies owed reach back 7 days, and a dialog whose newest message the sync has not stored yet is listed " +
|
|
67
|
+
"there too, marked so; owed mail lists only senders you know (linked to a person with other identities, or " +
|
|
68
|
+
"written to before), and owed mail from new senders is listed under mail, marked so. " +
|
|
69
|
+
"Each item has its reference, who, when, one line of text and why it is there; a section cut by --limit or " +
|
|
70
|
+
"--max-output-bytes says how many it left out and the command that reads them. `scope` says what was read " +
|
|
71
|
+
"(the window, sources, counts), `tasks` counts each task group and, as `undated`, every open task with no due " +
|
|
72
|
+
"date, and `health` names each account whose sync failed, that nothing syncs, or that is quiet for longer " +
|
|
73
|
+
"than usual, or whose timer has not synced it for a day and a half (no reason, only how long), so an unsynced " +
|
|
74
|
+
"account does not read as a quiet day; an account stored or synced within a day is never named. A digest's " +
|
|
75
|
+
"scheduled run first runs again the syncs you put on a timer in tg, max, wa and mail that are more than an " +
|
|
76
|
+
"hour behind, as each schedule says, for up to 4 minutes")
|
|
77
|
+
.option("--since-time <time>", "how far back: hours or days (12h, 7d) or a start date (2026-11-01)", "1d")
|
|
78
|
+
.option("--before-time <time>", "build it as of this past ISO time or date, for a past day's digest: --since-time counts back from it, and " +
|
|
79
|
+
"what came later is left out; a chat or thread answered since reads as answered")
|
|
80
|
+
.option("--source <accounts>", `only these, comma-separated or repeated: ${DIGEST_SOURCES.join(", ")}; watched items, projects and proposals stay. ` +
|
|
81
|
+
"A digest's run reads the digest's own sources without it", sourcesOf)
|
|
82
|
+
.option("--limit <n>", "items per section before the size budget", positive, 25)
|
|
83
|
+
.option("--max-output-bytes <bytes>", "the text answer's size budget in bytes; 40000 with --compact, else 80000", positive)
|
|
84
|
+
.option("--compact", "one line per item, shorter excerpts, the smaller budget: for an agent")
|
|
85
|
+
.option("--json", "print JSON")
|
|
86
|
+
.action(async (given) => {
|
|
87
|
+
if (given.compact && given.json)
|
|
88
|
+
throw new CliError("validation_error", "--compact and --json ask for different output — pick one", {
|
|
89
|
+
reason: "output.conflict",
|
|
90
|
+
param: "--compact",
|
|
91
|
+
});
|
|
92
|
+
const until = given.beforeTime === undefined ? undefined : beforeOf(given.beforeTime);
|
|
93
|
+
const since = sinceOf(given.sinceTime, until);
|
|
94
|
+
const gathered = await withStore(env, (store) => gatherDigest(store, env, {
|
|
95
|
+
since,
|
|
96
|
+
...(until === undefined ? {} : { until }),
|
|
97
|
+
limit: given.limit,
|
|
98
|
+
excerpt: given.compact ? 100 : 200,
|
|
99
|
+
owedWithin: OWED_WITHIN,
|
|
100
|
+
sources: given.source ?? scheduledSources(env),
|
|
101
|
+
}));
|
|
102
|
+
const digest = fitDigest(gathered, given.maxOutputBytes ?? (given.compact ? COMPACT_BYTES : FULL_BYTES));
|
|
103
|
+
// Not `print` for the text: its compact renderer would draw the answer generically, without the sections.
|
|
104
|
+
if (given.json)
|
|
105
|
+
print(true, itemAnswer(digest));
|
|
106
|
+
else
|
|
107
|
+
streams.data(`${digestText(digest)}\n`);
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=command.js.map
|