ai-agentmanager 1.66.0 → 1.68.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 +14 -0
- package/README.md +28 -0
- package/package.json +1 -1
- package/public/app.js +2 -0
- package/public/groups.js +14 -8
- package/public/index.html +8 -0
- package/public/style.css +10 -0
- package/public/weekly.js +65 -0
- package/src/cli.js +17 -0
- package/src/server.js +7 -0
- package/src/weekly.js +331 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.68.0 (2026-11-24)
|
|
4
|
+
|
|
5
|
+
- **Weekly summary: technical, with no money amounts.** The AI cost and the dollar value are gone. Under each delivered piece the summary now says **How** it was done (from the agent's brief), what was **Changed** (files, lines, folders, test files) and how it was **Checked** (checks passed, commands recorded with their output, breaks caught by the tests, the scorecard, named risks avoided, reviews).
|
|
6
|
+
- **Technical summary for the week.** Files and lines changed, the areas of the code touched, verification, tests tested, the average review scorecard, risks named and avoided, change requests, and the engines and models used.
|
|
7
|
+
- **The hours estimate covers exactly the pieces listed**, and says how many of them it is for.
|
|
8
|
+
|
|
9
|
+
## 1.67.0 (2026-11-23)
|
|
10
|
+
|
|
11
|
+
- **Weekly summary for management.** **Work record → Weekly summary**, or `agentmgr weekly`, gives one page on a week's work and achievements: the week in one line, highlights, what merged and finished by project with links, bugs fixed, the numbers against the week before, the estimated value, how the merged work held up, what is in progress and what is blocked. Last week, or this week so far (`--current`).
|
|
12
|
+
- **Copy, download or save.** Copy it as Markdown, download it, or save it on this computer (`--save`, `-o <file>`). When a week is over its summary is also written to `~/.agentmanager/reports/weekly-<monday>.md`. Nothing is sent.
|
|
13
|
+
- **Private work is not described.** Work that is kept private is counted and listed as "(kept private)", with no title, link or description.
|
|
14
|
+
|
|
15
|
+
- **Split screen: a view that follows another fits when the other one resizes.** The same timing as the text size fix in 1.66.0, in the other place it applied: a following view could be measured before the terminal had taken the new size in, and stay too large without its note.
|
|
16
|
+
|
|
3
17
|
## 1.66.0 (2026-11-23)
|
|
4
18
|
|
|
5
19
|
- **Possibly patentable work is noticed without asking.** When an agent finishes, Insights is now made by itself, so the kind of idea (a task, worth a white paper, possibly patentable) is read for every finished task. `"insights": { "auto": false }` in config.json turns it off; it is one more model call per finished agent.
|
package/README.md
CHANGED
|
@@ -1429,6 +1429,34 @@ Agents started this way are marked **⚡ GitHub** or **⚡ webhook**, Slack aler
|
|
|
1429
1429
|
}
|
|
1430
1430
|
```
|
|
1431
1431
|
|
|
1432
|
+
## Weekly summary: the week's work and achievements, for management
|
|
1433
|
+
|
|
1434
|
+
**Work record → Weekly summary**, or `agentmgr weekly`, gives one page on a week that you can pass to your manager.
|
|
1435
|
+
|
|
1436
|
+
| Section | What it holds |
|
|
1437
|
+
| --- | --- |
|
|
1438
|
+
| The week in one line | Pull requests merged and across how many projects, tasks finished, bugs fixed, engineering hours delivered (an estimate) |
|
|
1439
|
+
| Highlights | The three largest pieces of work, each with a sentence on what it is and how it was done |
|
|
1440
|
+
| Achievements | What merged, by project, with links and bug keys; then what finished without a merge; bugs fixed; issues filed. Under each piece: **How** it was done, what was **Changed**, and how it was **Checked** |
|
|
1441
|
+
| Numbers | Merged, opened, bugs fixed, issues filed, tasks finished and hours to merge, against the week before; and the estimated size in engineering hours |
|
|
1442
|
+
| Technical summary | Files and lines changed, the areas of the code touched, checks passed and commands recorded, tests tested, the average review scorecard, risks named and avoided, change requests, and the engines and models used |
|
|
1443
|
+
| Quality | How many of the week's merged pull requests held up, and the ones reverted or fixed afterwards |
|
|
1444
|
+
| In progress | Open work by project: in review or in progress |
|
|
1445
|
+
| Blocked | What needs a decision or help, with what it waits for |
|
|
1446
|
+
|
|
1447
|
+
- **Which week.** Last week by default; **This week so far** or `--current` for the one running.
|
|
1448
|
+
- **Getting it out.** **Copy** (Markdown, for an email, a document or Slack), **Download**, or **Save on this computer** (`--save`, or `-o <file>`). When a week is over, its summary is also written by itself to `~/.agentmanager/reports/weekly-<monday>.md` (`"weekly": { "auto": false }` in config.json turns that off).
|
|
1449
|
+
- **Nothing is sent.** It is a draft for you to read and pass on.
|
|
1450
|
+
- **Private work stays private.** Work that is [kept private](#kept-private-possibly-patentable-work-is-not-sent-out) is counted and listed as "(kept private)", with no title, link or description.
|
|
1451
|
+
|
|
1452
|
+
**It is technical, with no money amounts.** Under each delivered piece:
|
|
1453
|
+
|
|
1454
|
+
- **How:** the first sentences of the Solution in the agent's brief.
|
|
1455
|
+
- **Changed:** files and lines of its merged pull request, the folders they are in, and how many are test files.
|
|
1456
|
+
- **Checked:** checks passed and failed, commands recorded with their output ([Proof](#proof-what-it-ran-and-what-it-did-not-do)), breaks caught ([Test the tests](#test-the-tests-would-they-notice-a-mistake)), the scorecard, named risks avoided, reviews and change requests.
|
|
1457
|
+
|
|
1458
|
+
It is put together from what is already recorded, with no model call: the [work record](#work-record), the agents' briefs, [Quality](#quality-what-happened-after-the-merge) for the files and lines of merged pull requests, and [Value](#value) for the sentence on each piece and its estimated engineering hours. A line appears only when there is something to say: an agent that was removed keeps what was recorded as its pull request merged, and loses the rest.
|
|
1459
|
+
|
|
1432
1460
|
## Value
|
|
1433
1461
|
|
|
1434
1462
|
**Value** in the top bar (or `v`) shows what the work delivered with agents is worth, for you and for management: by **Day**, **Week**, **Month**, **Quarter** or **Year**, with bars for the last periods and the items behind each.
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -60,6 +60,7 @@ import { morph } from '/morph.js';
|
|
|
60
60
|
import { acceptanceRow, acceptanceWaits, initAcceptance } from '/acceptance.js';
|
|
61
61
|
import { autoNeedHtml, autonomyNeeds, autonomyRow, initAutonomy, needsPermissionHint } from '/autonomy.js';
|
|
62
62
|
import { initProof, proofRows } from '/proof.js';
|
|
63
|
+
import { initWeekly } from '/weekly.js';
|
|
63
64
|
import { kindHtml, optionsRows, parseKind, parsePaths, parseValue, pathsHtml, privateRow, valueHtml } from '/valuelens.js';
|
|
64
65
|
|
|
65
66
|
const $ = (sel) => document.querySelector(sel);
|
|
@@ -221,6 +222,7 @@ const triggersUi = initTriggers({ api, esc, toast, $ });
|
|
|
221
222
|
initSpend({ api, esc, toast, $ });
|
|
222
223
|
const goalsUi = initGoals({ api, esc, toast, $, ago: (t) => ago(t), getProjects: () => projectsState, rerender: () => renderBacklog() });
|
|
223
224
|
initWorklog({ api, esc, toast, $ });
|
|
225
|
+
initWeekly({ api, esc, toast, $, md: (t) => md(t) });
|
|
224
226
|
initSetup({ api, esc, $ });
|
|
225
227
|
const updateUi = initUpdate({ api, esc, toast, $ });
|
|
226
228
|
initMenu({ api, esc, toast, $ });
|
package/public/groups.js
CHANGED
|
@@ -25,7 +25,18 @@ export function followSize(v, cols, rows, box) {
|
|
|
25
25
|
if (!(cols > 0 && rows > 0) || (cols === v.xterm.cols && rows === v.xterm.rows)) return;
|
|
26
26
|
v.follow = true;
|
|
27
27
|
v.xterm.resize(cols, rows);
|
|
28
|
-
|
|
28
|
+
fitSoon(v, box);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Fit a following view once xterm has taken a new size or font in, which takes it some frames:
|
|
33
|
+
* measured too early, the view would stay at the full size and no longer fit, with nothing to
|
|
34
|
+
* correct it. Fitting again is harmless once it does.
|
|
35
|
+
*/
|
|
36
|
+
function fitSoon(v, box) {
|
|
37
|
+
const again = () => scaleToFit(v, box);
|
|
38
|
+
requestAnimationFrame(again);
|
|
39
|
+
for (const ms of [120, 400, 1000]) setTimeout(again, ms);
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
/** While following: the font that fits the session's size into the panel. */
|
|
@@ -49,13 +60,8 @@ export function ownFont(v) {
|
|
|
49
60
|
/** The text size was changed in the menu. */
|
|
50
61
|
export function newFont(v, fit, box) {
|
|
51
62
|
v.xterm.options.fontSize = termFont();
|
|
52
|
-
if (v.follow)
|
|
53
|
-
|
|
54
|
-
// at the full size and no longer fit. Fitting again is harmless once it does.
|
|
55
|
-
const again = () => scaleToFit(v, box);
|
|
56
|
-
requestAnimationFrame(again);
|
|
57
|
-
for (const ms of [120, 400, 1000]) setTimeout(again, ms);
|
|
58
|
-
} else fit();
|
|
63
|
+
if (v.follow) fitSoon(v, box);
|
|
64
|
+
else fit();
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
/** This view sets the size again: its own font, fitted to its panel, sent to the session. */
|
package/public/index.html
CHANGED
|
@@ -884,12 +884,20 @@
|
|
|
884
884
|
</form>
|
|
885
885
|
</dialog>
|
|
886
886
|
|
|
887
|
+
<dialog id="weekly-dialog" class="update-dialog weekly-dialog" aria-label="Weekly summary">
|
|
888
|
+
<div class="issues-head"><h2>Weekly summary</h2><div class="chips" role="tablist" id="weekly-tabs"></div></div>
|
|
889
|
+
<div id="weekly-body"></div>
|
|
890
|
+
<p id="weekly-note" class="hint"></p>
|
|
891
|
+
<div class="dialog-actions"><button type="button" class="small primary" data-weekly="copy" title="As Markdown, to paste into an email, a document or Slack">Copy</button><button type="button" class="small" data-weekly="download">Download</button><button type="button" class="small" data-weekly="save" title="Write it to the reports folder on this computer">Save on this computer</button><span class="spacer"></span><button type="button" class="small" data-weekly="close">Close</button></div>
|
|
892
|
+
</dialog>
|
|
893
|
+
|
|
887
894
|
<dialog id="worklog-dialog">
|
|
888
895
|
<form method="dialog" class="alerts-body">
|
|
889
896
|
<h2>Work record <select id="worklog-days" class="inline-select"><option value="7">last 7 days</option><option value="30" selected>last 30 days</option><option value="90">last 90 days</option><option value="365">last year</option><option value="0">all time</option></select></h2>
|
|
890
897
|
<div id="worklog-body"></div>
|
|
891
898
|
<p id="worklog-files" class="hint"></p>
|
|
892
899
|
<div class="dialog-actions">
|
|
900
|
+
<button type="button" id="weekly-open" class="primary" title="One page on a week's work and achievements, written for management">Weekly summary</button>
|
|
893
901
|
<button type="button" id="worklog-copy" title="The period's totals and what was merged, fixed and filed, with links, as Markdown for a review or status update">Copy summary</button>
|
|
894
902
|
<button type="button" id="worklog-csv" class="ghost">Download events</button>
|
|
895
903
|
<button type="button" id="worklog-weekly" class="ghost">Download weekly</button>
|
package/public/style.css
CHANGED
|
@@ -388,6 +388,16 @@ body.term-max .term-agent, .term-wrap:fullscreen .term-agent { display: inline-b
|
|
|
388
388
|
.kept-private { margin: 6px 0 10px; padding: 8px 10px; border: 1px solid #e8590c; border-radius: 8px; font-size: 13px; overflow-wrap: anywhere; }
|
|
389
389
|
.kept-private p { margin: 4px 0 6px; }
|
|
390
390
|
.kept-private-off { margin: 4px 0; }
|
|
391
|
+
.weekly-dialog { width: min(820px, calc(100vw - 24px)); }
|
|
392
|
+
.weekly-dialog .dialog-actions, .weekly-dialog .issues-head { flex-wrap: wrap; gap: 6px; }
|
|
393
|
+
.weekly-dialog .spacer { flex: 1 1 0; min-width: 0; }
|
|
394
|
+
#weekly-note { overflow-wrap: anywhere; }
|
|
395
|
+
.weekly-md { max-height: min(62vh, 640px); overflow: auto; overflow-wrap: anywhere; font-size: 14px; }
|
|
396
|
+
.weekly-md table { border-collapse: collapse; margin: 6px 0 10px; }
|
|
397
|
+
.weekly-md th, .weekly-md td { border: 1px solid var(--border); padding: 3px 8px; text-align: left; }
|
|
398
|
+
.weekly-md h1 { font-size: 18px; }
|
|
399
|
+
.weekly-md h2 { font-size: 15px; margin: 14px 0 4px; }
|
|
400
|
+
.weekly-md h3 { font-size: 14px; margin: 10px 0 4px; }
|
|
391
401
|
@media (max-width: 1000px) { .insight-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
|
392
402
|
@media (max-width: 1000px) { .insight-wide { grid-template-columns: minmax(0, 1fr); } }
|
|
393
403
|
@media (max-width: 560px) { .insight-grid { grid-template-columns: minmax(0, 1fr); } }
|
package/public/weekly.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Weekly summary (Work record → Weekly summary): one page on a week's work and achievements, for
|
|
2
|
+
// management. Last week or this week so far; read it, copy it as Markdown, or save it as a file.
|
|
3
|
+
// It is a draft for you: nothing is sent from here.
|
|
4
|
+
|
|
5
|
+
export function initWeekly({ api, esc, toast, $, md }) {
|
|
6
|
+
const dlg = $('#weekly-dialog');
|
|
7
|
+
let current = false;
|
|
8
|
+
let report = null;
|
|
9
|
+
|
|
10
|
+
function render() {
|
|
11
|
+
$('#weekly-tabs').innerHTML = [[false, 'Last week'], [true, 'This week so far']]
|
|
12
|
+
.map(([v, label]) => `<button type="button" class="chip ${v === current ? 'active' : ''}" role="tab" aria-selected="${v === current}" data-weekly-current="${v ? 1 : 0}">${label}</button>`)
|
|
13
|
+
.join('');
|
|
14
|
+
$('#weekly-body').innerHTML = report ? `<div class="md weekly-md">${md(report.markdown)}</div>` : '<p class="hint">Loading…</p>';
|
|
15
|
+
$('#weekly-note').textContent = report
|
|
16
|
+
? `${report.saved ? `Saved as ${report.file}. ` : ''}Put together from the work record, Value and Quality; estimates are marked as estimates. Work that is kept private is listed without a description. Nothing is sent from here.`
|
|
17
|
+
: '';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function load() {
|
|
21
|
+
report = null;
|
|
22
|
+
render();
|
|
23
|
+
try {
|
|
24
|
+
report = await api('GET', `/weekly${current ? '?current=1' : ''}`);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
$('#weekly-body').innerHTML = `<p class="error">${esc(err.message)}</p>`;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
render();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
$('#weekly-open').onclick = () => {
|
|
33
|
+
dlg.showModal();
|
|
34
|
+
load();
|
|
35
|
+
};
|
|
36
|
+
dlg.addEventListener('click', async (e) => {
|
|
37
|
+
const tab = e.target.closest('[data-weekly-current]');
|
|
38
|
+
if (tab) {
|
|
39
|
+
current = tab.dataset.weeklyCurrent === '1';
|
|
40
|
+
return load();
|
|
41
|
+
}
|
|
42
|
+
const act = e.target.closest('[data-weekly]')?.dataset.weekly;
|
|
43
|
+
if (act === 'close') return dlg.close();
|
|
44
|
+
if (!report) return;
|
|
45
|
+
try {
|
|
46
|
+
if (act === 'copy') {
|
|
47
|
+
await navigator.clipboard.writeText(report.markdown);
|
|
48
|
+
toast(`Copied the summary for ${report.week.label}`);
|
|
49
|
+
} else if (act === 'save') {
|
|
50
|
+
report = await api('POST', '/weekly/save', { current });
|
|
51
|
+
toast(`Saved as ${report.file}`, 6000);
|
|
52
|
+
render();
|
|
53
|
+
} else if (act === 'download') {
|
|
54
|
+
const a = document.createElement('a');
|
|
55
|
+
a.href = URL.createObjectURL(new Blob([`${report.markdown}\n`], { type: 'text/markdown' }));
|
|
56
|
+
a.download = `weekly-${report.week.start}.md`;
|
|
57
|
+
a.click();
|
|
58
|
+
URL.revokeObjectURL(a.href);
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
toast(`Error: ${err.message}`, 6000);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return { isOpen: () => dlg.open };
|
|
65
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -831,6 +831,23 @@ export async function main(argv) {
|
|
|
831
831
|
console.log(`${green('✓')} ${r.existing ? 'pushed to' : 'opened'} ${r.url ?? '(no URL printed by gh)'}`);
|
|
832
832
|
});
|
|
833
833
|
|
|
834
|
+
program
|
|
835
|
+
.command('weekly')
|
|
836
|
+
.description("Weekly summary for management: a week's work and achievements on one page. The week in one line, highlights, what was merged and finished by project, bugs fixed, the numbers against the week before, estimated value, how the merged work held up, what is in progress and what is blocked. Work that is kept private is listed without a description. A draft: nothing is sent.")
|
|
837
|
+
.option('--current', 'this week so far (default: the week that just ended)')
|
|
838
|
+
.option('--save', 'also write it to the reports folder (~/.agentmanager/reports/weekly-<monday>.md)')
|
|
839
|
+
.option('-o, --out <file>', 'write it to this file')
|
|
840
|
+
.option('--json', 'print the facts as JSON')
|
|
841
|
+
.action(async (o) => {
|
|
842
|
+
await daemon();
|
|
843
|
+
const r = o.save ? await api('POST', '/weekly/save', { current: Boolean(o.current) }) : await api('GET', `/weekly${o.current ? '?current=1' : ''}`);
|
|
844
|
+
if (o.out) fs.writeFileSync(o.out, `${r.markdown}\n`);
|
|
845
|
+
if (o.json) return console.log(JSON.stringify(r.facts, null, 2));
|
|
846
|
+
console.log(r.markdown);
|
|
847
|
+
if (o.save) process.stderr.write(dim(`\nSaved as ${r.file}\n`));
|
|
848
|
+
if (o.out) process.stderr.write(dim(`\nWritten to ${o.out}\n`));
|
|
849
|
+
});
|
|
850
|
+
|
|
834
851
|
program
|
|
835
852
|
.command('worklog')
|
|
836
853
|
.description('Work record: pull requests opened and merged, bugs fixed, issues filed, agents finished; also appended to ~/.agentmanager/worklog.csv')
|
package/src/server.js
CHANGED
|
@@ -58,6 +58,7 @@ import { Standup } from './standup.js';
|
|
|
58
58
|
import { Value, valueSlack } from './value.js';
|
|
59
59
|
import { Quality } from './quality.js';
|
|
60
60
|
import { recordMarkdown } from './record.js';
|
|
61
|
+
import { Weekly } from './weekly.js';
|
|
61
62
|
import { PRIVATE_MESSAGE, keptPrivate, mustBeShareable } from './private.js';
|
|
62
63
|
import { Standards, runCheck } from './standards.js';
|
|
63
64
|
import { Proof, proofMarkdown } from './proof.js';
|
|
@@ -355,6 +356,8 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
355
356
|
const quality = new Quality({ manager, store, config, who: me, onChange: () => pushQuality() });
|
|
356
357
|
// Standards per repository: lessons from what went wrong, high-risk paths, and the quality bar (standards.js).
|
|
357
358
|
const standards = new Standards({ manager, store, config, quality, onChange: () => pushQuality() });
|
|
359
|
+
// A week's work and achievements on one page, for management (weekly.js); written as a draft file when the week is over.
|
|
360
|
+
const weekly = new Weekly({ manager, store, worklog, value, quality, who: me, config });
|
|
358
361
|
// AI News: the frontier labs' latest releases, summarized (news.js).
|
|
359
362
|
let pushNews = () => {};
|
|
360
363
|
const news = new News({
|
|
@@ -1257,6 +1260,9 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
1257
1260
|
api.get('/repeats', wrap(() => repeats.view()));
|
|
1258
1261
|
api.post('/repeats/dismiss', wrap((req) => repeats.dismiss(String(req.body?.key ?? ''))));
|
|
1259
1262
|
api.post('/playbooks/:id/run', wrap((req) => playbooks.run(req.params.id, { vars: req.body?.vars ?? {} })));
|
|
1263
|
+
// Weekly summary (weekly.js): a week's work and achievements on one page, for management. A draft: nothing is sent.
|
|
1264
|
+
api.get('/weekly', wrap((req) => weekly.report({ current: req.query.current === '1' })));
|
|
1265
|
+
api.post('/weekly/save', wrap((req) => weekly.save({ current: req.body?.current === true })));
|
|
1260
1266
|
api.get('/worklog', wrap(async (req) => (await worklog.record(), worklog.view({ days: Number(req.query.days ?? 30) || 0 }))));
|
|
1261
1267
|
api.get('/worklog/summary', wrap(async (req) => {
|
|
1262
1268
|
await worklog.record();
|
|
@@ -2106,6 +2112,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
2106
2112
|
standup.close();
|
|
2107
2113
|
value.close();
|
|
2108
2114
|
quality.close();
|
|
2115
|
+
weekly.close();
|
|
2109
2116
|
news.close();
|
|
2110
2117
|
system.close();
|
|
2111
2118
|
milestones.close();
|
package/src/weekly.js
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// Weekly summary: one page on a week's work and achievements, written for management. It is put
|
|
2
|
+
// together from what is already recorded, with no model call:
|
|
3
|
+
// the work record (worklog.js) - pull requests merged and opened, bugs fixed, issues filed
|
|
4
|
+
// Value (value.js) - what each delivered piece is, and the engineering hours estimated
|
|
5
|
+
// the agents' own briefs - how each piece was done, how it was checked, the risks named
|
|
6
|
+
// Quality (quality.js) - how the week's merged pull requests held up
|
|
7
|
+
// the agents as they are now - what is in progress, and what is blocked
|
|
8
|
+
// It is a technical summary: what was built and how it was verified. No money amounts are shown.
|
|
9
|
+
// Work that is kept private (private.js) is counted but not described: no title and no link.
|
|
10
|
+
// It is a draft for you: shown, copied or saved as a file. Nothing is sent to anyone.
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { paths } from './config.js';
|
|
14
|
+
import { dayKey } from './budgets.js';
|
|
15
|
+
import { keptPrivate } from './private.js';
|
|
16
|
+
import { totals as qualityTotals } from './quality.js';
|
|
17
|
+
import { itemValue } from './value.js';
|
|
18
|
+
import { weekRow, weekStart } from './worklog.js';
|
|
19
|
+
|
|
20
|
+
const DAY = 86_400_000;
|
|
21
|
+
const PRIVATE = '(kept private)';
|
|
22
|
+
const clip = (s, n = 140) => {
|
|
23
|
+
const t = String(s ?? '').replace(/\s+/g, ' ').trim();
|
|
24
|
+
return t.length > n ? `${t.slice(0, n - 1)}…` : t;
|
|
25
|
+
};
|
|
26
|
+
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
27
|
+
const dayLabel = (t) => new Date(t).toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
|
|
28
|
+
|
|
29
|
+
/** The first sentence or two of a text, cut to size: how a piece of work was done, from its brief's Solution. */
|
|
30
|
+
export function gist(text, max = 240) {
|
|
31
|
+
const t = String(text ?? '').replace(/```[\s\S]*?```/g, ' ').replace(/^\s*#.*$/gm, ' ').replace(/^[>*\-\s]+/gm, '').replace(/\s+/g, ' ').trim();
|
|
32
|
+
if (!t) return '';
|
|
33
|
+
const two = /^(.+?[.!?])(\s+.+?[.!?])?(?=\s|$)/.exec(t);
|
|
34
|
+
return clip(two ? two[0] : t, max);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The part of the code a file is in: its first two folders ("src/engines"), or "(top level)". */
|
|
38
|
+
export const areaOf = (file) => {
|
|
39
|
+
const parts = String(file).split('/');
|
|
40
|
+
return parts.length > 1 ? parts.slice(0, Math.min(2, parts.length - 1)).join('/') : '(top level)';
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The technical side of one piece of work, from the agent as it is now and from Quality's record
|
|
45
|
+
* of its merged pull request: how it was done, what it touched, and how it was checked.
|
|
46
|
+
*/
|
|
47
|
+
export function techOf(agent, q = null) {
|
|
48
|
+
const b = agent?.brief ?? {};
|
|
49
|
+
const checks = b.checks ?? [];
|
|
50
|
+
const sc = agent?.docs?.scorecard?.data;
|
|
51
|
+
const br = agent?.breaks?.baseline?.ok ? agent.breaks.breaks ?? [] : null;
|
|
52
|
+
const n = (st) => br.filter((x) => x.status === st).length;
|
|
53
|
+
const risks = b.risks ?? [];
|
|
54
|
+
const files = q?.facts?.files ?? [];
|
|
55
|
+
const areas = {};
|
|
56
|
+
for (const f of files) areas[areaOf(f)] = (areas[areaOf(f)] ?? 0) + 1;
|
|
57
|
+
return {
|
|
58
|
+
how: gist(b.solution),
|
|
59
|
+
files: files.length || null,
|
|
60
|
+
lines: q?.facts?.lines ?? null,
|
|
61
|
+
areas: Object.entries(areas).sort((x, y) => y[1] - x[1]).slice(0, 3).map(([k]) => k),
|
|
62
|
+
testFiles: files.filter((f) => /(^|\/)(tests?|__tests__|spec|specs)\/|[._-](test|spec)\.[a-z]+$|_test\.go$/i.test(f)).length,
|
|
63
|
+
checksPassed: checks.filter((c) => c.state === 'passed').length,
|
|
64
|
+
checksFailed: checks.filter((c) => c.state === 'failed').length,
|
|
65
|
+
proof: agent?.proofDoc?.commands ?? 0,
|
|
66
|
+
breaks: br && n('caught') + n('missed') ? { caught: n('caught'), tried: n('caught') + n('missed') } : q?.said?.breaks ?? null,
|
|
67
|
+
score: Number.isFinite(sc?.overall) ? sc.overall : q?.said?.score ?? null,
|
|
68
|
+
risks: risks.length ? { named: risks.length, avoided: risks.filter((r) => r.state === 'avoided').length, happened: risks.filter((r) => r.state === 'happened').length } : null,
|
|
69
|
+
reviews: q?.facts?.reviews ?? null,
|
|
70
|
+
changesRequested: q?.facts?.changesRequested ?? null,
|
|
71
|
+
engine: agent?.engine ?? q?.said?.engine ?? null,
|
|
72
|
+
model: agent?.model ?? q?.said?.model ?? null,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** How one piece was checked, in a line: "4 checks passed, 3 with recorded runs; tests tested: 5 of 6 breaks caught; scorecard 86". */
|
|
77
|
+
export function checkedLine(t) {
|
|
78
|
+
if (!t) return '';
|
|
79
|
+
const out = [];
|
|
80
|
+
if (t.checksPassed || t.checksFailed) out.push(`${plural(t.checksPassed, 'check')} passed${t.checksFailed ? `, ${t.checksFailed} failed` : ''}`);
|
|
81
|
+
if (t.proof) out.push(`${plural(t.proof, 'command')} recorded with ${t.proof === 1 ? 'its' : 'their'} output`);
|
|
82
|
+
if (t.breaks) out.push(`tests tested: ${t.breaks.caught} of ${plural(t.breaks.tried, 'break')} caught`);
|
|
83
|
+
if (t.score != null) out.push(`scorecard ${t.score}`);
|
|
84
|
+
if (t.risks) out.push(`${t.risks.avoided} of ${plural(t.risks.named, 'named risk')} avoided${t.risks.happened ? `, ${t.risks.happened} happened` : ''}`);
|
|
85
|
+
if (t.reviews) out.push(`${plural(t.reviews, 'review')}${t.changesRequested ? `, ${plural(t.changesRequested, 'change request')}` : ''}`);
|
|
86
|
+
return out.join('; ');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The Monday a week's summary starts on: the week before `t`, or the one `t` is in. */
|
|
90
|
+
export const weekOf = (t = Date.now(), { current = false } = {}) => (current ? weekStart(t) : weekStart(weekStart(t) - DAY));
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A week's facts. `events`: the work record's rows; `spend`: the spend ledger's days; `value` and
|
|
94
|
+
* `quality`: { items, settings } of those modules; `agents`: [{ agent, view }] as they are now.
|
|
95
|
+
*/
|
|
96
|
+
export function weeklyFacts({ start, events = [], spend = {}, value = null, quality = null, agents = [], t = Date.now() }) {
|
|
97
|
+
const end = start + 7 * DAY;
|
|
98
|
+
const inWeek = (iso) => Date.parse(iso) >= start && Date.parse(iso) < end;
|
|
99
|
+
const hidden = new Set(agents.filter((x) => keptPrivate(x.agent)).map((x) => x.agent.id));
|
|
100
|
+
const mine = events.filter((e) => inWeek(e.date));
|
|
101
|
+
const entry = (e) => (hidden.has(e.agent_id) ? { project: e.project || 'Other', title: PRIVATE, link: null, bugs: '', private: true } : { project: e.project || 'Other', title: clip(e.title), link: e.link || null, bugs: e.bugs || '', agentId: e.agent_id });
|
|
102
|
+
const of = (kind) => mine.filter((e) => e.event === kind).map(entry);
|
|
103
|
+
const merged = of('pr_merged');
|
|
104
|
+
// Finished without a merged pull request this week: an answer, a document, a change not merged yet.
|
|
105
|
+
const mergedBy = new Set(mine.filter((e) => e.event === 'pr_merged').map((e) => e.agent_id));
|
|
106
|
+
const finished = mine.filter((e) => e.event === 'agent_finished' && !mergedBy.has(e.agent_id)).map(entry);
|
|
107
|
+
|
|
108
|
+
// What each delivered piece is, in Value's words, with its estimate.
|
|
109
|
+
const vItems = (value?.items ?? []).filter((it) => !it.excluded && inWeek(it.deliveredAt));
|
|
110
|
+
const said = new Map(vItems.map((it) => [it.agentId, itemValue(it, value.settings)]));
|
|
111
|
+
for (const e of [...merged, ...finished]) {
|
|
112
|
+
const v = e.agentId && said.get(e.agentId);
|
|
113
|
+
if (v?.summary) e.summary = clip(v.summary, 200);
|
|
114
|
+
if (v?.humanHours != null) e.hours = v.humanHours;
|
|
115
|
+
}
|
|
116
|
+
// The technical side of each: how it was done, what it touched, how it was checked.
|
|
117
|
+
const byId = new Map(agents.map((x) => [x.agent.id, x.agent]));
|
|
118
|
+
const qBy = new Map((quality?.items ?? []).map((it) => [it.url, it]));
|
|
119
|
+
for (const e of [...merged, ...finished]) {
|
|
120
|
+
if (e.private || !e.agentId) continue;
|
|
121
|
+
const q = (e.link && qBy.get(e.link)) || null;
|
|
122
|
+
if (byId.get(e.agentId) || q) e.tech = techOf(byId.get(e.agentId), q);
|
|
123
|
+
}
|
|
124
|
+
const techs = [...merged, ...finished].map((e) => e.tech).filter(Boolean);
|
|
125
|
+
const sum = (f) => techs.reduce((n, t) => n + (f(t) || 0), 0);
|
|
126
|
+
const areaCount = {};
|
|
127
|
+
for (const e of merged) for (const f of (e.link && qBy.get(e.link)?.facts?.files) || []) if (!e.private) areaCount[areaOf(f)] = (areaCount[areaOf(f)] ?? 0) + 1;
|
|
128
|
+
const scores = techs.map((t) => t.score).filter(Number.isFinite);
|
|
129
|
+
const tested = techs.filter((t) => t.breaks);
|
|
130
|
+
const models = {};
|
|
131
|
+
for (const t of techs) if (t.engine) models[`${t.engine}${t.model ? ` · ${t.model}` : ''}`] = (models[`${t.engine}${t.model ? ` · ${t.model}` : ''}`] ?? 0) + 1;
|
|
132
|
+
const technical = techs.length
|
|
133
|
+
? {
|
|
134
|
+
pieces: techs.length,
|
|
135
|
+
files: sum((t) => t.files),
|
|
136
|
+
lines: sum((t) => t.lines),
|
|
137
|
+
testFiles: sum((t) => t.testFiles),
|
|
138
|
+
areas: Object.entries(areaCount).sort((x, y) => y[1] - x[1]).slice(0, 6).map(([area, files]) => ({ area, files })),
|
|
139
|
+
checksPassed: sum((t) => t.checksPassed),
|
|
140
|
+
checksFailed: sum((t) => t.checksFailed),
|
|
141
|
+
proof: sum((t) => t.proof),
|
|
142
|
+
tested: tested.length,
|
|
143
|
+
breaksCaught: tested.reduce((n, t) => n + t.breaks.caught, 0),
|
|
144
|
+
breaksTried: tested.reduce((n, t) => n + t.breaks.tried, 0),
|
|
145
|
+
score: scores.length ? Math.round(scores.reduce((a, b) => a + b, 0) / scores.length) : null,
|
|
146
|
+
scored: scores.length,
|
|
147
|
+
risksNamed: sum((t) => t.risks?.named),
|
|
148
|
+
risksAvoided: sum((t) => t.risks?.avoided),
|
|
149
|
+
risksHappened: sum((t) => t.risks?.happened),
|
|
150
|
+
changesRequested: sum((t) => t.changesRequested),
|
|
151
|
+
models: Object.entries(models).sort((x, y) => y[1] - x[1]).map(([name, n]) => ({ name, n })),
|
|
152
|
+
}
|
|
153
|
+
: null;
|
|
154
|
+
|
|
155
|
+
// The size of the week, over the pieces listed: the hours a person would have needed, as Value estimates them.
|
|
156
|
+
const listed = [...merged, ...finished].filter((e) => !e.private);
|
|
157
|
+
const sized = listed.filter((e) => e.hours != null);
|
|
158
|
+
const size = sized.length ? { hours: Math.round(sized.reduce((n, e) => n + e.hours, 0) * 10) / 10, estimated: sized.length, pieces: listed.length } : null;
|
|
159
|
+
// The three worth the most, as the week's highlights.
|
|
160
|
+
const highlights = [...merged, ...finished]
|
|
161
|
+
.filter((e) => !e.private && e.hours != null)
|
|
162
|
+
.sort((a, b) => b.hours - a.hours)
|
|
163
|
+
.slice(0, 3);
|
|
164
|
+
|
|
165
|
+
const qItems = (quality?.items ?? []).filter((it) => inWeek(it.mergedAt));
|
|
166
|
+
const held = quality && qItems.length ? qualityTotals(qItems, quality.settings, t) : null;
|
|
167
|
+
|
|
168
|
+
const open = agents
|
|
169
|
+
.filter(({ agent: a }) => a.kind === 'task' && !a.team && !(a.brief?.status === 'done' || a.brief?.results?.outcome === 'done'))
|
|
170
|
+
.map(({ agent: a, view: v }) => {
|
|
171
|
+
const pr = Object.values(a.prs ?? {}).find((p) => p.state === 'OPEN' && p.source !== 'mentioned');
|
|
172
|
+
const blocked = a.brief?.status === 'blocked' || a.brief?.results?.outcome === 'blocked';
|
|
173
|
+
return {
|
|
174
|
+
project: v?.projectInfo?.name ?? 'Other',
|
|
175
|
+
title: hidden.has(a.id) ? PRIVATE : clip(String(a.intent ?? a.name).split('\n')[0], 120),
|
|
176
|
+
state: blocked ? 'blocked' : pr ? 'in review' : 'in progress',
|
|
177
|
+
link: hidden.has(a.id) ? null : pr?.url ?? null,
|
|
178
|
+
blockers: blocked && !hidden.has(a.id) ? (a.brief?.results?.blockers ?? []).map((b) => clip(b, 160)) : [],
|
|
179
|
+
private: hidden.has(a.id),
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
start: dayKey(start),
|
|
185
|
+
end: dayKey(end - DAY),
|
|
186
|
+
label: `${dayLabel(start)} to ${dayLabel(end - DAY)}, ${new Date(end - DAY).getFullYear()}`,
|
|
187
|
+
complete: t >= end,
|
|
188
|
+
row: weekRow(start, events, spend),
|
|
189
|
+
prev: weekRow(start - 7 * DAY, events, spend),
|
|
190
|
+
merged,
|
|
191
|
+
finished,
|
|
192
|
+
bugs: of('bug_fixed'),
|
|
193
|
+
filed: of('issue_filed'),
|
|
194
|
+
highlights,
|
|
195
|
+
technical,
|
|
196
|
+
size,
|
|
197
|
+
quality: held,
|
|
198
|
+
problems: qItems.filter((it) => it.after?.reverted || it.after?.fixes?.length).map((it) => ({ title: hidden.has(it.agentId) ? PRIVATE : clip(it.title), link: hidden.has(it.agentId) ? null : it.url, what: it.after?.reverted ? 'reverted' : 'fixed afterwards' })),
|
|
199
|
+
blocked: open.filter((o) => o.state === 'blocked'),
|
|
200
|
+
open: open.filter((o) => o.state !== 'blocked'),
|
|
201
|
+
keptPrivate: [...merged, ...finished, ...open].filter((e) => e.private).length,
|
|
202
|
+
projects: [...new Set([...merged, ...finished].map((e) => e.project))],
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const item = (e) => `${e.link ? `[${e.title}](${e.link})` : e.title}${e.bugs ? ` (${e.bugs})` : ''}${e.summary ? `: ${e.summary}` : ''}`;
|
|
207
|
+
/** A delivered piece with its technical side under it: how it was done, what it touched, how it was checked. */
|
|
208
|
+
const piece = (e) => {
|
|
209
|
+
const t = e.tech;
|
|
210
|
+
if (!t) return item(e);
|
|
211
|
+
const touched = t.files ? `${plural(t.files, 'file')}${t.lines ? `, ${plural(t.lines, 'line')}` : ''}${t.areas.length ? ` in ${t.areas.join(', ')}` : ''}${t.testFiles ? `; ${plural(t.testFiles, 'test file')}` : ''}` : '';
|
|
212
|
+
const checked = checkedLine(t);
|
|
213
|
+
return [item(e), ...(t.how ? [` - How: ${t.how}`] : []), ...(touched ? [` - Changed: ${touched}`] : []), ...(checked ? [` - Checked: ${checked}`] : [])].join('\n');
|
|
214
|
+
};
|
|
215
|
+
const byProject = (list, each) => {
|
|
216
|
+
const out = [];
|
|
217
|
+
for (const p of [...new Set(list.map((e) => e.project))]) {
|
|
218
|
+
out.push(`**${p}**`, ...list.filter((e) => e.project === p).map((e) => `- ${each(e)}`), '');
|
|
219
|
+
}
|
|
220
|
+
return out;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/** The summary as Markdown: the week in a line, achievements, numbers, quality, what is next, and what is in the way. */
|
|
224
|
+
export function weeklyMarkdown(f, { who = '' } = {}) {
|
|
225
|
+
const r = f.row;
|
|
226
|
+
const out = [`# Weekly summary: ${f.label}`, '', `${who ? `${who} · ` : ''}${f.complete ? 'the week as it ended' : 'the week so far'}`, ''];
|
|
227
|
+
const done = f.merged.length + f.finished.length;
|
|
228
|
+
if (!done && !f.bugs.length && !r.prs_opened && !f.open.length && !f.blocked.length) return [...out, 'Nothing was recorded this week.'].join('\n');
|
|
229
|
+
|
|
230
|
+
// One line a manager can repeat.
|
|
231
|
+
const parts = [];
|
|
232
|
+
if (r.prs_merged) parts.push(`${plural(r.prs_merged, 'pull request')} merged${f.projects.length > 1 ? ` across ${f.projects.length} projects` : f.projects.length === 1 ? ` in ${f.projects[0]}` : ''}`);
|
|
233
|
+
if (f.finished.length) parts.push(`${plural(f.finished.length, 'more task')} finished`);
|
|
234
|
+
if (r.bugs_fixed) parts.push(`${plural(r.bugs_fixed, 'bug')} fixed`);
|
|
235
|
+
if (f.size) parts.push(`about ${f.size.hours} hours of engineering work delivered (an estimate)`);
|
|
236
|
+
out.push('## The week in one line', '', parts.length ? `${parts.join('; ')}.` : 'Work is in progress; nothing was delivered yet.', '');
|
|
237
|
+
|
|
238
|
+
if (f.highlights.length) out.push('## Highlights', '', ...f.highlights.map((e) => `- **${e.title}** (${e.project})${e.summary ? `: ${e.summary}` : ''}${e.tech?.how ? ` ${e.tech.how}` : ''}`), '');
|
|
239
|
+
|
|
240
|
+
if (done) {
|
|
241
|
+
out.push('## Achievements', '');
|
|
242
|
+
if (f.merged.length) out.push('### Merged', '', ...byProject(f.merged, piece));
|
|
243
|
+
if (f.finished.length) out.push('### Finished, not merged yet or with no pull request', '', ...byProject(f.finished, piece));
|
|
244
|
+
}
|
|
245
|
+
if (f.bugs.length) out.push('### Bugs fixed', '', ...f.bugs.map((e) => `- ${item(e)}`), '');
|
|
246
|
+
if (f.filed.length) out.push('### Issues filed', '', ...f.filed.map((e) => `- ${item(e)}`), '');
|
|
247
|
+
|
|
248
|
+
const p = f.prev;
|
|
249
|
+
const num = (label, a, b) => `| ${label} | ${a === '' || a == null ? '—' : a} | ${b === '' || b == null ? '—' : b} |`;
|
|
250
|
+
out.push('## Numbers', '', '| | This week | Week before |', '| --- | --- | --- |');
|
|
251
|
+
out.push(num('Pull requests merged', r.prs_merged, p.prs_merged), num('Pull requests opened', r.prs_opened, p.prs_opened), num('Bugs fixed', r.bugs_fixed, p.bugs_fixed), num('Issues filed', r.issues_filed, p.issues_filed), num('Tasks finished', r.agents_finished, p.agents_finished), num('Hours from opened to merged (median)', r.median_hours_to_merge, p.median_hours_to_merge), '');
|
|
252
|
+
if (f.size) out.push(`Estimated size: about ${f.size.hours} hours of engineering work for ${f.size.estimated} of the ${plural(f.size.pieces, 'piece')} listed. An estimate of what a person would have needed, not a measurement.`, '');
|
|
253
|
+
|
|
254
|
+
const k = f.technical;
|
|
255
|
+
if (k) {
|
|
256
|
+
out.push('## Technical summary', '');
|
|
257
|
+
if (k.files) out.push(`- **Code:** ${plural(k.files, 'file')} and ${plural(k.lines, 'line')} changed in merged pull requests${k.testFiles ? `, ${plural(k.testFiles, 'test file')} among them` : ''}.`);
|
|
258
|
+
if (k.areas.length) out.push(`- **Areas touched:** ${k.areas.map((a) => `${a.area} (${a.files})`).join(', ')}.`);
|
|
259
|
+
if (k.checksPassed || k.checksFailed) out.push(`- **Verification:** ${plural(k.checksPassed, 'check')} passed${k.checksFailed ? `, ${k.checksFailed} failed` : ''} across ${plural(k.pieces, 'piece')} of work${k.proof ? `; ${plural(k.proof, 'command')} recorded with ${k.proof === 1 ? 'its' : 'their'} output, so ${k.proof === 1 ? 'it' : 'they'} can be run again` : ''}.`);
|
|
260
|
+
if (k.tested) out.push(`- **Tests tested:** on ${plural(k.tested, 'piece')}, ${k.breaksCaught} of ${plural(k.breaksTried, 'deliberate break')} in the changed code ${k.breaksCaught === 1 ? 'was' : 'were'} caught by the tests.`);
|
|
261
|
+
if (k.scored) out.push(`- **Review scorecard:** ${k.score} of 100 on average over ${plural(k.scored, 'piece')}.`);
|
|
262
|
+
if (k.risksNamed) out.push(`- **Risks named before starting:** ${k.risksNamed}; ${k.risksAvoided} avoided${k.risksHappened ? `, ${k.risksHappened} happened` : ''}${k.risksNamed - k.risksAvoided - k.risksHappened ? `, ${k.risksNamed - k.risksAvoided - k.risksHappened} not checked` : ''}.`);
|
|
263
|
+
if (k.changesRequested) out.push(`- **Review:** changes were requested ${plural(k.changesRequested, 'time')} before merging.`);
|
|
264
|
+
if (k.models.length) out.push(`- **Done with:** ${k.models.map((m) => `${m.name} (${m.n})`).join(', ')}.`);
|
|
265
|
+
out.push('');
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (f.quality) {
|
|
269
|
+
out.push('## Quality', '', f.quality.checked ? `${f.quality.held} of ${plural(f.quality.checked, 'merged pull request')} looked at held up${f.quality.watching ? ` (${f.quality.watching} still watched)` : ''}.${f.quality.unchecked ? ` ${f.quality.unchecked} not looked at yet.` : ''}` : 'The merged pull requests have not been looked at yet.');
|
|
270
|
+
for (const x of f.problems) out.push(`- ${x.link ? `[${x.title}](${x.link})` : x.title}: ${x.what}`);
|
|
271
|
+
out.push('');
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (f.open.length) out.push('## In progress', '', ...byProject(f.open, (e) => `${e.link ? `[${e.title}](${e.link})` : e.title} (${e.state})`));
|
|
275
|
+
if (f.blocked.length) out.push('## Blocked: needs a decision or help', '', ...f.blocked.map((e) => `- **${e.project}**: ${e.title}${e.blockers.length ? `. ${e.blockers.join('; ')}` : ''}`), '');
|
|
276
|
+
if (f.keptPrivate) out.push(`${plural(f.keptPrivate, 'item')} above ${f.keptPrivate === 1 ? 'is' : 'are'} kept private and listed without a description.`, '');
|
|
277
|
+
return out.join('\n').trimEnd();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export class Weekly {
|
|
281
|
+
/** `worklog`, `value`, `quality`: the daemon's own; `who`: a promise or a name. */
|
|
282
|
+
constructor({ manager, store, worklog, value = null, quality = null, who = null, config = {}, dir = path.join(paths.home, 'reports') }) {
|
|
283
|
+
Object.assign(this, { manager, store, worklog, value, quality, who, config, dir });
|
|
284
|
+
this.timer = setInterval(() => this.rollOver().catch(() => {}), 30 * 60_000);
|
|
285
|
+
this.timer.unref?.();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
close() {
|
|
289
|
+
clearInterval(this.timer);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
fileFor(start) {
|
|
293
|
+
return path.join(this.dir, `weekly-${dayKey(start)}.md`);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async report({ current = false, t = Date.now() } = {}) {
|
|
297
|
+
await this.worklog.record(t).catch(() => {});
|
|
298
|
+
const start = weekOf(t, { current });
|
|
299
|
+
const facts = weeklyFacts({
|
|
300
|
+
start,
|
|
301
|
+
events: this.worklog.state.events,
|
|
302
|
+
spend: this.store.data.spend?.days ?? {},
|
|
303
|
+
value: this.value ? { items: Object.values(this.value.state.items), settings: this.value.settings } : null,
|
|
304
|
+
quality: this.quality ? { items: Object.values(this.quality.state.items), settings: this.quality.settings } : null,
|
|
305
|
+
agents: this.store.list().map((agent) => ({ agent, view: this.manager.view(agent) })),
|
|
306
|
+
t,
|
|
307
|
+
});
|
|
308
|
+
const file = this.fileFor(start);
|
|
309
|
+
return { week: { start: facts.start, end: facts.end, label: facts.label, complete: facts.complete }, facts, markdown: weeklyMarkdown(facts, { who: (await this.who) ?? '' }), file, saved: fs.existsSync(file) };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** Write the summary to its file (again: replaced). Nothing is sent. */
|
|
313
|
+
async save(opts = {}) {
|
|
314
|
+
const r = await this.report(opts);
|
|
315
|
+
fs.mkdirSync(this.dir, { recursive: true });
|
|
316
|
+
fs.writeFileSync(r.file, `${r.markdown}\n`);
|
|
317
|
+
return { ...r, saved: true };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** Once a week is over, its summary is written as a draft file, once. */
|
|
321
|
+
async rollOver(t = Date.now()) {
|
|
322
|
+
if (this.config.weekly?.auto === false) return null;
|
|
323
|
+
const start = weekOf(t);
|
|
324
|
+
const st = (this.store.data.weekly ??= {});
|
|
325
|
+
if (st.drafted === dayKey(start) || fs.existsSync(this.fileFor(start))) return null;
|
|
326
|
+
const r = await this.save({ t });
|
|
327
|
+
st.drafted = dayKey(start);
|
|
328
|
+
this.store.save();
|
|
329
|
+
return r;
|
|
330
|
+
}
|
|
331
|
+
}
|