ai-agentmanager 1.44.0 → 1.47.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/CHANGELOG.md +21 -0
- package/README.md +115 -0
- package/package.json +1 -1
- package/public/app.js +46 -1
- package/public/index.html +11 -1
- package/public/keys.js +4 -2
- package/public/news.js +167 -0
- package/public/plan.js +323 -0
- package/public/side.js +122 -2
- package/public/style.css +92 -0
- package/public/today.js +102 -2
- package/src/brief.js +68 -1
- package/src/calendar.js +385 -0
- package/src/cli.js +150 -0
- package/src/config.js +6 -0
- package/src/debt.js +276 -0
- package/src/decisions.js +188 -0
- package/src/engines/claude.js +7 -0
- package/src/manager.js +41 -4
- package/src/milestones.js +282 -0
- package/src/news.js +454 -0
- package/src/notify.js +1 -0
- package/src/server.js +118 -3
- package/src/today.js +3 -1
package/src/manager.js
CHANGED
|
@@ -32,6 +32,9 @@ import {
|
|
|
32
32
|
intentMarkdown,
|
|
33
33
|
intentPath,
|
|
34
34
|
readSpecDoc,
|
|
35
|
+
debugPath,
|
|
36
|
+
debugPrompt,
|
|
37
|
+
debugFixPrompt,
|
|
35
38
|
specDocsInfo,
|
|
36
39
|
specPath,
|
|
37
40
|
specPrompt,
|
|
@@ -830,10 +833,32 @@ export class AgentManager extends EventEmitter {
|
|
|
830
833
|
/** One of an agent's intent, spec and plan files. */
|
|
831
834
|
specDoc(ref, name) {
|
|
832
835
|
const agent = this.mustGet(ref);
|
|
833
|
-
if (!['intent', 'spec', 'plan', 'designdoc', 'benchmark'].includes(name)) throw Object.assign(new Error('Unknown file (intent, spec, plan, designdoc or
|
|
836
|
+
if (!['intent', 'spec', 'plan', 'designdoc', 'benchmark', 'debug'].includes(name)) throw Object.assign(new Error('Unknown file (intent, spec, plan, designdoc, benchmark or debug)'), { status: 400 });
|
|
834
837
|
return readSpecDoc(agent.id, name) ?? { name, markdown: null };
|
|
835
838
|
}
|
|
836
839
|
|
|
840
|
+
/**
|
|
841
|
+
* Debug: ask the agent to investigate something in its session and keep a report (DEBUG.md) with
|
|
842
|
+
* diagrams of the code path and data flow, findings and recommended fixes. `question`: what to
|
|
843
|
+
* debug, or a follow-up once there is a report. `fix`: apply the report's fixes (which ones, in
|
|
844
|
+
* words; true for the ones it recommends). The message waits in the agent's queue like any other.
|
|
845
|
+
*/
|
|
846
|
+
debug(ref, { question = '', fix = null } = {}) {
|
|
847
|
+
const agent = this.mustGet(ref);
|
|
848
|
+
if (!agent.workdir || agent.status === 'preparing') throw Object.assign(new Error('The agent has no folder to debug in yet'), { status: 409 });
|
|
849
|
+
const q = String(question ?? '').replace(/\s+/g, ' ').trim().slice(0, 2000);
|
|
850
|
+
const has = Boolean(readSpecDoc(agent.id, 'debug')?.markdown?.trim());
|
|
851
|
+
if (fix && !has) throw Object.assign(new Error('There is no debug report yet: say what to debug first'), { status: 409 });
|
|
852
|
+
if (!fix && q.length < 3) throw Object.assign(new Error('Say what to debug'), { status: 400 });
|
|
853
|
+
fs.mkdirSync(briefDir(agent.id), { recursive: true });
|
|
854
|
+
const file = path.join(fs.realpathSync(briefDir(agent.id)), path.basename(debugPath(agent.id)));
|
|
855
|
+
const which = fix === true ? '' : String(fix ?? '').replace(/\s+/g, ' ').trim().slice(0, 500);
|
|
856
|
+
this.tell(agent.id, fix ? debugFixPrompt(file, which) : debugPrompt(file, q, { again: has }), { source: 'debug' });
|
|
857
|
+
// What was asked, newest last, for the Debug tab.
|
|
858
|
+
const asks = [...(agent.debug?.asks ?? []), { text: fix ? `Apply fixes${which ? `: ${which}` : ''}` : q, kind: fix ? 'fix' : has ? 'follow-up' : 'debug', at: now() }].slice(-20);
|
|
859
|
+
return this.view(this.patch(agent.id, { debug: { asks, startedAt: agent.debug?.startedAt ?? now() } }));
|
|
860
|
+
}
|
|
861
|
+
|
|
837
862
|
/** The agent's sample demo page (HTML), once it has written one. */
|
|
838
863
|
demoPage(ref) {
|
|
839
864
|
const agent = this.mustGet(ref);
|
|
@@ -2324,6 +2349,14 @@ export class AgentManager extends EventEmitter {
|
|
|
2324
2349
|
// A new or revised plan waits for review again, unless it was already approved (then it's a progress update).
|
|
2325
2350
|
if (file) this.patch(id, { planReview: { ...agent.planReview, ...file, status: agent.planReview.status === 'approved' ? 'approved' : 'review' } });
|
|
2326
2351
|
}
|
|
2352
|
+
// A debug report written or updated: the page hears, and draws it.
|
|
2353
|
+
if (agent.debug) {
|
|
2354
|
+
let at = null;
|
|
2355
|
+
try {
|
|
2356
|
+
at = fs.statSync(debugPath(id)).mtime.toISOString();
|
|
2357
|
+
} catch {}
|
|
2358
|
+
if (at !== (agent.debug.reportAt ?? null)) this.patch(id, { debug: { ...this.store.get(id).debug, reportAt: at } });
|
|
2359
|
+
}
|
|
2327
2360
|
}
|
|
2328
2361
|
|
|
2329
2362
|
// -------------------------------------------------------------- plan review
|
|
@@ -2522,13 +2555,17 @@ export class AgentManager extends EventEmitter {
|
|
|
2522
2555
|
}
|
|
2523
2556
|
|
|
2524
2557
|
/** One tool-less, read-only call to an engine; resolves to its text output. */
|
|
2525
|
-
oneShot(agent, text, { engine, model, timeoutMs = 300_000, tools, cwd = paths.home }) {
|
|
2558
|
+
oneShot(agent, text, { engine, model, timeoutMs = 300_000, tools, web, cwd = paths.home }) {
|
|
2526
2559
|
// Some engines take the prompt as an argument instead of on stdin, and some need their extra
|
|
2527
2560
|
// arguments after a subcommand (oneShotExtra: they place them). `tools`: Claude Code only, a
|
|
2528
2561
|
// call that may use just these connector tools (and none of its own). `cwd`: where it runs, which
|
|
2529
|
-
// decides the project MCP servers it loads.
|
|
2562
|
+
// decides the project MCP servers it loads. `web`: Claude Code only, a call that may use just
|
|
2563
|
+
// these of its own tools (WebSearch, WebFetch).
|
|
2564
|
+
if (web && !engine.webArgs) return Promise.reject(new Error(`${engine.label} can't search the web here; Claude Code can`));
|
|
2530
2565
|
const extra = engine.extraArgs(this.config);
|
|
2531
|
-
const args =
|
|
2566
|
+
const args = web
|
|
2567
|
+
? [...extra, ...engine.webArgs(this.config, { model, tools: web })]
|
|
2568
|
+
: tools
|
|
2532
2569
|
? [...extra, ...engine.connectorArgs(this.config, { model, tools })]
|
|
2533
2570
|
: engine.oneShotExtra ? engine.oneShotArgs(this.config, { model, prompt: text, extra }) : [...extra, ...engine.oneShotArgs(this.config, { model, prompt: text })];
|
|
2534
2571
|
return new Promise((resolve, reject) => {
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// Dates: a project's commitments (code complete, release candidate, GA) and what stands between
|
|
2
|
+
// now and each. For every date it plans the reminders (14, 7, 3 and 1 days before, and the day)
|
|
3
|
+
// and keeps a checklist: what the app can see for itself (agents still working, backlog not done,
|
|
4
|
+
// pull requests open or failing, serious bugs open) and what only you can tick (release notes, the
|
|
5
|
+
// RC cut, docs), each of which an agent can be asked to do. A date close with work still open is
|
|
6
|
+
// "at risk"; one that has passed is "late". Reminders go to Slack (when alerts are on) and the
|
|
7
|
+
// dates show in Today as they come near.
|
|
8
|
+
|
|
9
|
+
const DAY = 86_400_000;
|
|
10
|
+
export const STAGES = [
|
|
11
|
+
['codeComplete', 'Code complete'],
|
|
12
|
+
['rc', 'Release candidate'],
|
|
13
|
+
['ga', 'GA'],
|
|
14
|
+
];
|
|
15
|
+
export const REMIND_DAYS = [14, 7, 3, 1, 0];
|
|
16
|
+
const OPEN_BACKLOG = new Set(['queued', 'active', 'review', 'blocked']);
|
|
17
|
+
|
|
18
|
+
const err = (status, message) => Object.assign(new Error(message), { status });
|
|
19
|
+
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
20
|
+
|
|
21
|
+
/** "2026-12-01" as that local day, or null. */
|
|
22
|
+
export function dayOf(s) {
|
|
23
|
+
const m = String(s ?? '').match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
24
|
+
if (!m) return null;
|
|
25
|
+
const d = new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
|
|
26
|
+
return d.getMonth() === Number(m[2]) - 1 && d.getDate() === Number(m[3]) ? d : null;
|
|
27
|
+
}
|
|
28
|
+
const dayIndex = (d) => Math.round(new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime() / DAY);
|
|
29
|
+
/** Whole days from `now` to the date: 0 today, negative once it has passed. */
|
|
30
|
+
export const daysLeft = (date, now = new Date()) => dayIndex(dayOf(date)) - dayIndex(now);
|
|
31
|
+
|
|
32
|
+
/** "in 12 days", "tomorrow", "today", "3 days late". */
|
|
33
|
+
export function leftWords(n) {
|
|
34
|
+
if (n < 0) return `${plural(-n, 'day')} late`;
|
|
35
|
+
if (n === 0) return 'today';
|
|
36
|
+
if (n === 1) return 'tomorrow';
|
|
37
|
+
return `in ${n} days`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The reminders planned for a date: [{ offset, on: "YYYY-MM-DD", label }], soonest last. */
|
|
41
|
+
export function remindersFor(date) {
|
|
42
|
+
const d = dayOf(date);
|
|
43
|
+
if (!d) return [];
|
|
44
|
+
return REMIND_DAYS.map((offset) => {
|
|
45
|
+
const on = new Date(d.getFullYear(), d.getMonth(), d.getDate() - offset);
|
|
46
|
+
const iso = `${on.getFullYear()}-${String(on.getMonth() + 1).padStart(2, '0')}-${String(on.getDate()).padStart(2, '0')}`;
|
|
47
|
+
return { offset, on: iso, label: offset === 0 ? 'the day' : offset === 1 ? 'the day before' : `${offset} days before` };
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A stage's checklist from the project's facts. `auto` items are counted by the app (ok at 0);
|
|
53
|
+
* the others are yours to tick, and `task` is what an agent is asked when you hand one over.
|
|
54
|
+
*/
|
|
55
|
+
export function checklistFor(stage, f, { name = 'the project', date = '' } = {}) {
|
|
56
|
+
const auto = (key, n, text, zero, names = [], go = null) => ({ key, auto: true, count: n, ok: n === 0, text: n ? text : zero, names: names.slice(0, 6), go });
|
|
57
|
+
const manual = (key, text, task) => ({ key, auto: false, text, task });
|
|
58
|
+
const serious = auto('bugs', f.bugs.length, `${plural(f.bugs.length, 'critical or high bug')} open`, 'No critical or high bugs open', f.bugs.map((b) => b.title), 'bugs');
|
|
59
|
+
if (stage === 'codeComplete') {
|
|
60
|
+
return [
|
|
61
|
+
auto('working', f.working.length, `${plural(f.working.length, 'agent')} still working`, 'No agent still working', f.working.map((a) => a.name), 'agents'),
|
|
62
|
+
auto('backlog', f.backlog.length, `${plural(f.backlog.length, 'backlog item')} not finished`, 'The backlog is finished', f.backlog.map((b) => b.title), 'backlog'),
|
|
63
|
+
auto('waiting', f.waiting.length, `${plural(f.waiting.length, 'thing')} waiting on you (plans, questions, prompts)`, 'Nothing waiting on you', f.waiting.map((a) => a.name), 'inbox'),
|
|
64
|
+
manual('scope', 'Scope agreed: what is in and what moved out', null),
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
if (stage === 'rc') {
|
|
68
|
+
return [
|
|
69
|
+
auto('prs', f.prs.length, `${plural(f.prs.length, 'pull request')} still open`, 'No pull requests open', f.prs.map((p) => `#${p.number ?? '?'} ${p.title ?? ''}`.trim()), 'land'),
|
|
70
|
+
auto('checks', f.failing.length, `${plural(f.failing.length, 'pull request')} with failing checks`, 'No failing checks', f.failing.map((p) => `#${p.number ?? '?'} ${p.title ?? ''}`.trim()), 'land'),
|
|
71
|
+
serious,
|
|
72
|
+
manual('notes', 'Release notes and changelog drafted', `Draft the release notes and the changelog entry for the ${name} release candidate${date ? ` (RC on ${date})` : ''}: read what was merged since the last release, group it by what users will notice, and call out breaking changes and upgrade steps. Open a pull request with the changelog.`),
|
|
73
|
+
manual('cut', 'Release candidate cut and smoke-tested', null),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
return [
|
|
77
|
+
serious,
|
|
78
|
+
auto('prs', f.prs.length, `${plural(f.prs.length, 'pull request')} still open`, 'No pull requests open', f.prs.map((p) => `#${p.number ?? '?'} ${p.title ?? ''}`.trim()), 'land'),
|
|
79
|
+
manual('docs', 'Docs and upgrade notes up to date', `Bring the docs of ${name} up to date for the GA release${date ? ` on ${date}` : ''}: compare the README and docs with what changed since the last release, fix what is out of date, and add upgrade notes for anything that changes behaviour. Open a pull request.`),
|
|
80
|
+
manual('final-notes', 'Release notes final', `Finish the release notes of ${name} for GA${date ? ` on ${date}` : ''}: check every entry against what was actually merged, in the words a user would use, with the breaking changes first. Open a pull request.`),
|
|
81
|
+
manual('publish', 'Version bumped, tagged and published', null),
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Where a date stands: reached, late, at-risk (a week or less with counted work open) or on-track. */
|
|
86
|
+
export function stageStatus({ n, reached, open }) {
|
|
87
|
+
if (reached) return 'reached';
|
|
88
|
+
if (n < 0) return 'late';
|
|
89
|
+
if (n <= 7 && open > 0) return 'at-risk';
|
|
90
|
+
return 'on-track';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The reminder that is due now: the nearest offset the date is within, or "late"; null when none yet. */
|
|
94
|
+
export function dueReminder(n) {
|
|
95
|
+
if (n < 0) return 'late';
|
|
96
|
+
const o = [...REMIND_DAYS].sort((a, b) => a - b).find((x) => n <= x);
|
|
97
|
+
return o === undefined ? null : String(o);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export class Milestones {
|
|
101
|
+
/** `facts(project)` gathers what's open in a project; `notify(text, plain)` sends a reminder; `queue(project, title)` hands a task to an agent. */
|
|
102
|
+
constructor({ store, projects, facts, notify = null, queue = null, onChange = () => {}, log = (m) => console.log(`[agentmgr] ${m}`), now = () => new Date(), timer = true }) {
|
|
103
|
+
Object.assign(this, { store, projects, facts, notify, queue, onChange, log, now });
|
|
104
|
+
if (timer) {
|
|
105
|
+
this.timer = setInterval(() => this.tick().catch((e) => this.log(`dates: ${e.message}`)), 30 * 60_000);
|
|
106
|
+
this.first = setTimeout(() => this.tick().catch(() => {}), 45_000);
|
|
107
|
+
this.timer.unref?.();
|
|
108
|
+
this.first.unref?.();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
close() {
|
|
113
|
+
clearInterval(this.timer);
|
|
114
|
+
clearTimeout(this.first);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
get all() {
|
|
118
|
+
return (this.store.data.milestones ??= {});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
project(ref) {
|
|
122
|
+
const r = String(ref ?? '').trim().replace(/^@/, '').toLowerCase();
|
|
123
|
+
const p = this.projects().find((x) => x.shortcut === r || x.key === ref || x.name.toLowerCase() === r);
|
|
124
|
+
if (!p) throw err(404, `No project matches "${ref}"`);
|
|
125
|
+
return p;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Set (or with null, clear) a project's dates: { codeComplete, rc, ga } as "YYYY-MM-DD", in that order. */
|
|
129
|
+
set(ref, dates = {}) {
|
|
130
|
+
const p = this.project(ref);
|
|
131
|
+
const rec = (this.all[p.key] ??= { dates: {}, done: {}, reached: {}, sent: {} });
|
|
132
|
+
const next = { ...rec.dates };
|
|
133
|
+
for (const [id, label] of STAGES) {
|
|
134
|
+
if (!(id in dates)) continue;
|
|
135
|
+
const v = dates[id];
|
|
136
|
+
if (v === null || v === '') delete next[id];
|
|
137
|
+
else if (!dayOf(v)) throw err(400, `${label}: a date like 2026-12-01`);
|
|
138
|
+
else next[id] = v;
|
|
139
|
+
}
|
|
140
|
+
const order = STAGES.map(([id]) => next[id]).filter(Boolean);
|
|
141
|
+
if (order.some((d, i) => i && d < order[i - 1])) throw err(400, 'The dates go in order: code complete, then the release candidate, then GA');
|
|
142
|
+
// A date that moved gets its reminders again.
|
|
143
|
+
for (const [id] of STAGES) if (next[id] !== rec.dates[id]) delete rec.sent[id];
|
|
144
|
+
rec.dates = next;
|
|
145
|
+
if (!Object.keys(next).length) delete this.all[p.key];
|
|
146
|
+
this.store.save();
|
|
147
|
+
this.onChange();
|
|
148
|
+
return this.view();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Tick (or untick) one of your checklist items. */
|
|
152
|
+
check(ref, stage, key, done = true) {
|
|
153
|
+
const rec = this.rec(ref, stage);
|
|
154
|
+
rec.done[`${stage}:${key}`] = done ? this.now().toISOString() : undefined;
|
|
155
|
+
this.store.save();
|
|
156
|
+
this.onChange();
|
|
157
|
+
return this.view();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The date was met (or, with false, not after all): no more reminders for it. */
|
|
161
|
+
reach(ref, stage, reached = true) {
|
|
162
|
+
const rec = this.rec(ref, stage);
|
|
163
|
+
rec.reached[stage] = reached ? this.now().toISOString() : undefined;
|
|
164
|
+
this.store.save();
|
|
165
|
+
this.onChange();
|
|
166
|
+
return this.view();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
rec(ref, stage) {
|
|
170
|
+
const p = this.project(ref);
|
|
171
|
+
const rec = this.all[p.key];
|
|
172
|
+
if (!rec?.dates?.[stage]) throw err(404, 'That date is not set for this project');
|
|
173
|
+
return rec;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Hand one of your checklist items to an agent (through the backlog). */
|
|
177
|
+
task(ref, stage, key) {
|
|
178
|
+
const p = this.project(ref);
|
|
179
|
+
const rec = this.rec(ref, stage);
|
|
180
|
+
const item = checklistFor(stage, this.facts(p), { name: p.name, date: rec.dates[stage] }).find((i) => i.key === key);
|
|
181
|
+
if (!item?.task) throw err(400, 'That item has nothing an agent can do');
|
|
182
|
+
if (!this.queue) throw err(409, 'The backlog is not available');
|
|
183
|
+
const added = this.queue(p, item.task);
|
|
184
|
+
rec.tasks = { ...rec.tasks, [`${stage}:${key}`]: { at: this.now().toISOString(), id: added?.id ?? null } };
|
|
185
|
+
this.store.save();
|
|
186
|
+
this.onChange();
|
|
187
|
+
return this.view();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
stages(p, now = this.now()) {
|
|
191
|
+
const rec = this.all[p.key];
|
|
192
|
+
if (!rec) return [];
|
|
193
|
+
const f = this.facts(p);
|
|
194
|
+
return STAGES.filter(([id]) => rec.dates[id]).map(([id, label]) => {
|
|
195
|
+
const date = rec.dates[id];
|
|
196
|
+
const n = daysLeft(date, now);
|
|
197
|
+
const reached = rec.reached?.[id] ?? null;
|
|
198
|
+
const checklist = checklistFor(id, f, { name: p.name, date }).map((i) => (i.auto ? i : { ...i, done: Boolean(rec.done?.[`${id}:${i.key}`]), asked: rec.tasks?.[`${id}:${i.key}`]?.at ?? null, task: Boolean(i.task) }));
|
|
199
|
+
const open = checklist.filter((i) => i.auto && !i.ok).reduce((s, i) => s + i.count, 0);
|
|
200
|
+
const todo = checklist.filter((i) => !i.auto && !i.done).length;
|
|
201
|
+
return {
|
|
202
|
+
id,
|
|
203
|
+
label,
|
|
204
|
+
date,
|
|
205
|
+
daysLeft: n,
|
|
206
|
+
words: reached ? 'reached' : leftWords(n),
|
|
207
|
+
status: stageStatus({ n, reached, open }),
|
|
208
|
+
reached,
|
|
209
|
+
open,
|
|
210
|
+
todo,
|
|
211
|
+
checklist,
|
|
212
|
+
reminders: remindersFor(date).map((r) => ({ ...r, sent: Boolean(rec.sent?.[id]?.[String(r.offset)]), past: daysLeft(r.on, now) < 0 })),
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
view() {
|
|
218
|
+
const now = this.now();
|
|
219
|
+
const list = this.projects();
|
|
220
|
+
const projects = list
|
|
221
|
+
.filter((p) => this.all[p.key])
|
|
222
|
+
.map((p) => {
|
|
223
|
+
const stages = this.stages(p, now);
|
|
224
|
+
return { key: p.key, shortcut: p.shortcut, name: p.name, stages, next: stages.find((s) => !s.reached) ?? null };
|
|
225
|
+
})
|
|
226
|
+
.sort((a, b) => (a.next?.daysLeft ?? 1e9) - (b.next?.daysLeft ?? 1e9) || a.name.localeCompare(b.name));
|
|
227
|
+
return { projects, others: list.filter((p) => !this.all[p.key]).map((p) => ({ key: p.key, shortcut: p.shortcut, name: p.name })), stages: STAGES.map(([id, label]) => ({ id, label })), remindDays: REMIND_DAYS };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** What's open for a date, in a few words: "2 agents still working, 3 pull requests still open". */
|
|
231
|
+
openWords(s) {
|
|
232
|
+
const parts = s.checklist.filter((i) => i.auto && !i.ok).map((i) => i.text);
|
|
233
|
+
const mine = s.checklist.filter((i) => !i.auto && !i.done).map((i) => i.text);
|
|
234
|
+
return [...parts, ...(mine.length ? [`yours: ${mine.join('; ')}`] : [])].join(', ');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** For Today: the dates within two weeks, and the late ones. */
|
|
238
|
+
todayItems() {
|
|
239
|
+
const out = [];
|
|
240
|
+
for (const p of this.view().projects) {
|
|
241
|
+
for (const s of p.stages) {
|
|
242
|
+
if (s.reached || s.daysLeft > 14) continue;
|
|
243
|
+
const score = s.daysLeft < 0 ? 12 : s.daysLeft <= 1 ? 18 : s.daysLeft <= 3 ? 30 : s.daysLeft <= 7 ? 46 : 58;
|
|
244
|
+
const open = this.openWords(s);
|
|
245
|
+
out.push({ id: `milestone:${p.key}:${s.id}`, kind: 'milestone', label: s.status === 'late' ? 'Late' : s.status === 'at-risk' ? 'At risk' : 'Date', title: `${p.name}: ${s.label} ${s.words} (${s.date})`, why: open || 'Nothing open that the app can see', score, at: null, due: dayOf(s.date).toISOString(), project: p.shortcut, stage: s.id });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return out;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Send the reminders that are due: one per date, for the nearest offset it has come within. */
|
|
252
|
+
async tick() {
|
|
253
|
+
const now = this.now();
|
|
254
|
+
if (now.getHours() < 8 || now.getHours() >= 20) return [];
|
|
255
|
+
const sent = [];
|
|
256
|
+
for (const p of this.projects()) {
|
|
257
|
+
const rec = this.all[p.key];
|
|
258
|
+
if (!rec) continue;
|
|
259
|
+
for (const s of this.stages(p, now)) {
|
|
260
|
+
if (s.reached) continue;
|
|
261
|
+
const due = dueReminder(s.daysLeft);
|
|
262
|
+
const had = (rec.sent[s.id] ??= {});
|
|
263
|
+
if (!due || had[due]) continue;
|
|
264
|
+
// Being within a nearer offset covers the further ones: they aren't sent late.
|
|
265
|
+
for (const o of REMIND_DAYS) if (due === 'late' || o >= Number(due)) had[String(o)] ??= now.toISOString();
|
|
266
|
+
had[due] = now.toISOString();
|
|
267
|
+
this.store.save();
|
|
268
|
+
const open = this.openWords(s);
|
|
269
|
+
const head = `${p.name}: ${s.label} ${s.words} (${s.date})`;
|
|
270
|
+
const mark = s.status === 'late' ? ':rotating_light:' : s.status === 'at-risk' ? ':warning:' : ':calendar:';
|
|
271
|
+
sent.push({ project: p.shortcut, stage: s.id, reminder: due });
|
|
272
|
+
try {
|
|
273
|
+
await this.notify?.(`${mark} *${head}*${open ? `\n${open}` : '\nNothing open that the app can see.'}`, `${head}${open ? `\n${open}` : ''}`);
|
|
274
|
+
} catch (e) {
|
|
275
|
+
this.log(`dates: ${head}: not sent: ${e.message}`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (sent.length) this.onChange();
|
|
280
|
+
return sent;
|
|
281
|
+
}
|
|
282
|
+
}
|