create-pmos 0.397.0 → 0.398.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/package.json +13 -13
- package/payload/KIT-VERSION +2 -2
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +101 -52
- package/workspace/briefing-premium-board-test.js +252 -128
- package/workspace/briefing-premium-calendar-2-test.js +135 -198
- package/workspace/briefing-premium-calendar-3-test.js +143 -418
- package/workspace/briefing-premium-calendar-test.js +86 -196
- package/workspace/briefing-premium-doc-edit-test.js +95 -83
- package/workspace/briefing-premium-initiative-test.js +159 -296
- package/workspace/briefing-premium-insights-test.js +337 -219
- package/workspace/briefing-premium-metrics-test.js +53 -97
- package/workspace/briefing-premium-products-test.js +40 -27
- package/workspace/briefing-premium-sources-test.js +66 -48
- package/workspace/briefing-premium-test.js +150 -647
- package/workspace/briefing-premium-work-test.js +88 -283
- package/workspace/changelog.json +12 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/premium-viewer-fixtures.js +182 -0
- package/workspace/guide/briefing-premium.md +3 -1
- package/workspace/guide/home.md +47 -0
- package/workspace/guide/index.md +1 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-premium.js +85 -19
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +62 -14
- package/workspace/lib/insights-records.js +101 -0
- package/workspace/lib/jira-tickets.js +1 -1
- package/workspace/lib/route-modules.js +4 -0
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-insights-premium.js +12 -3
- package/workspace/lib/routes-insights-records.js +129 -0
- package/workspace/lib/routes-notes.js +1 -0
- package/workspace/lib/routes-viewer.js +108 -0
- package/workspace/lib/transcript-steps.js +123 -0
- package/workspace/lib/viewer-meeting.js +205 -0
- package/workspace/lib/viewer-report.js +89 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +85 -75
- package/workspace/premium-briefing-depth-test.js +66 -53
- package/workspace/premium-chat-attach-test.js +54 -63
- package/workspace/premium-chat-chart-tab-test.js +35 -37
- package/workspace/premium-chat-context-test.js +19 -18
- package/workspace/premium-chat-goal-view-test.js +23 -23
- package/workspace/premium-chat-notes-test.js +26 -31
- package/workspace/premium-chat-report-tab-test.js +32 -28
- package/workspace/premium-chat-term-test.js +16 -16
- package/workspace/premium-chat-viewer-test.js +60 -59
- package/workspace/premium-core-doc-issue-test.js +50 -43
- package/workspace/premium-html-viewer-test.js +14 -17
- package/workspace/premium-phone-card-test.js +7 -2
- package/workspace/premium-phone-room-test.js +41 -35
- package/workspace/premium-report-read-test.js +115 -197
- package/workspace/premium-viewer-download-test.js +19 -22
- package/workspace/premium-viewer-flicker-test.js +11 -16
- package/workspace/premium-viewer-share-test.js +6 -9
- package/workspace/premium-viewer-test.js +41 -60
- package/workspace/premium-vw-backlog-test.js +53 -33
- package/workspace/premium-vw-cal-test.js +82 -128
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +11 -10
- package/workspace/premium-vw-item-test.js +50 -49
- package/workspace/premium-vw-jira-test.js +53 -27
- package/workspace/premium-vw-meet-test.js +118 -187
- package/workspace/premium-vw-notes-test.js +85 -108
- package/workspace/premium-vw-rec-test.js +72 -194
- package/workspace/premium-vw-slides-test.js +46 -50
- package/workspace/premium-welcome-test.js +3 -2
- package/workspace/premium-work-depth-test.js +61 -53
- package/workspace/public/pm/bd-acts.js +305 -0
- package/workspace/public/pm/bd-span.js +186 -82
- package/workspace/public/pm/bd-stages.js +25 -11
- package/workspace/public/pm/c3-doc-sheet.js +1 -1
- package/workspace/public/pm/c3-md.js +3 -395
- package/workspace/public/pm/c3-phone-detail.js +1 -1
- package/workspace/public/pm/c3-phone-model.js +3 -68
- package/workspace/public/pm/chat-term.js +3 -3
- package/workspace/public/pm/cozy-board.css +497 -230
- package/workspace/public/pm/cozy-home.css +570 -142
- package/workspace/public/pm/cozy-home.js +5 -3
- package/workspace/public/pm/cozy-insights.css +296 -167
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +17 -6
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-viewer.css +3 -3
- package/workspace/public/pm/cozy-viewer.js +144 -0
- package/workspace/public/pm/cozy-vw.css +485 -0
- package/workspace/public/pm/cozy.css +83 -1
- package/workspace/public/pm/home-adddoc.js +48 -0
- package/workspace/public/pm/home-app.js +905 -0
- package/workspace/public/pm/home-around.js +515 -0
- package/workspace/public/pm/home-chat.js +459 -0
- package/workspace/public/pm/home-data.js +312 -0
- package/workspace/public/pm/home-draft.js +68 -0
- package/workspace/public/pm/home-more.js +249 -0
- package/workspace/public/pm/home-phone-card.js +109 -0
- package/workspace/public/pm/home-work.js +519 -0
- package/workspace/public/pm/phone-moment.js +69 -0
- package/workspace/public/pm/pm-work-view.js +1 -1
- package/workspace/public/pm/premium-attach.js +4 -0
- package/workspace/public/pm/premium-board.js +423 -394
- package/workspace/public/pm/premium-chart-tab.js +110 -62
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +25 -21
- package/workspace/public/pm/premium-insights.js +792 -568
- package/workspace/public/pm/premium-meeting.js +61 -549
- package/workspace/public/pm/premium-notes.js +1 -1
- package/workspace/public/pm/premium-report-frame.css +20 -0
- package/workspace/public/pm/premium-report-read.js +509 -480
- package/workspace/public/pm/premium-report-tab.js +87 -63
- package/workspace/public/pm/premium-shell.js +72 -119
- package/workspace/public/pm/premium-viewer.js +22 -1
- package/workspace/public/pm/premium-vw-cal.js +187 -48
- package/workspace/public/pm/premium-vw-doc.css +6 -0
- package/workspace/public/pm/premium-vw-doc.js +40 -2
- package/workspace/public/pm/premium-vw-file.js +2 -2
- package/workspace/public/pm/premium-vw-meet.js +6 -83
- package/workspace/public/pm/premium-vw-mtg.js +731 -0
- package/workspace/public/pm/premium-vw-notes.js +56 -69
- package/workspace/public/pm/premium-vw-open.js +35 -0
- package/workspace/public/pm/premium-vw-page.js +16 -0
- package/workspace/public/pm/premium-vw-rec.js +11 -218
- package/workspace/public/pm/premium-vw-slides.css +5 -0
- package/workspace/public/pm/premium-vw-slides.js +44 -8
- package/workspace/public/pm/term-view.js +22 -0
- package/workspace/public/premium-board.html +28 -70
- package/workspace/public/premium-initiative.html +8 -48
- package/workspace/public/premium-insights.html +22 -60
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium.html +16 -107
- package/workspace/server.js +18 -3
- package/workspace/test-files.json +1 -0
- package/workspace/test-lists/home-libs.json +9 -0
- package/workspace/test-lists/premium-report-read.json +1 -1
- package/workspace/test-lists/premium-vw-agreed.json +9 -0
- package/workspace/test-lists/premium-vw-notes.json +1 -1
- package/workspace/public/pm/premium-work.js +0 -729
- package/workspace/public/pm/premium.js +0 -1146
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-insights-records.js — the presses of the premium Insights page that the Agreed design adds (initiative premium-agreed-design G1, G2).
|
|
3
|
+
*
|
|
4
|
+
* POST /api/insights-records/goal { ws, name, type, direction, baseline, target, due, period_kind, period_label, objective, source, owner, guardrail, steps, limit, always_on }
|
|
5
|
+
* → { ok, rid } one KR metric record (planning/records/kr-metrics.jsonl, through scripts/records); lib/insights-goals.js goalFields says what is kept
|
|
6
|
+
* POST /api/insights-records/steps { ws, rid, done: [bool] } → { ok } a Done-or-not goal's steps ticked: one edit of its steps and one reading (steps done)
|
|
7
|
+
* POST /api/insights-records/dashboard { ws, board, id?, name, purpose, charts: [{ goal, form }], range, pin }
|
|
8
|
+
* → { ok, dashboard } the dashboard (lib/premium-dashboards.js save), one chart line per goal and, with pin, a pin line
|
|
9
|
+
* POST /api/insights-records/chart { ws, board, dash, goal, form, range, compare, target, forecast, note, add } → { ok }
|
|
10
|
+
* one chart line (lib/insights-records.js); with add, the goal is first added to the dashboard
|
|
11
|
+
* POST /api/insights-records/describe { ws, text } → { ok, name, question, goals, range, said } reads the goals; writes nothing
|
|
12
|
+
* POST /api/insights-records/verdict { ws, board, ini, verdict, learned, goal } → { ok, verdict } one verdict line; the Board is not changed
|
|
13
|
+
* POST /api/insights-records/target { ws, key: late | scope, target } → { ok, targets }
|
|
14
|
+
* GET /api/insights-records/export?ws=&board= → text/csv of the goals the page shows
|
|
15
|
+
*
|
|
16
|
+
* WHO WRITES. As routes-premium-dashboards.js: an agent session header is refused (403), and pm-guard requirePagePress checks the launch nonce and the
|
|
17
|
+
* page's origin. Describe and Export write nothing. */
|
|
18
|
+
const guard = require('./pm-guard.js');
|
|
19
|
+
const IG = require('./insights-goals.js');
|
|
20
|
+
const IR = require('./insights-records.js');
|
|
21
|
+
const PD = require('./premium-dashboards.js');
|
|
22
|
+
const dashRoutes = require('./routes-premium-dashboards.js');
|
|
23
|
+
const { repoScript } = require('./repo-script.js');
|
|
24
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
25
|
+
|
|
26
|
+
const text = (v) => (typeof v === 'string' ? v : '');
|
|
27
|
+
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
28
|
+
const today = () => new Date().toISOString().slice(0, 10);
|
|
29
|
+
const records = () => require(repoScript('records/index.js'));
|
|
30
|
+
const UI = () => require(repoScript('trust/ledger.js')).actorFrom({ ui: true });
|
|
31
|
+
const krList = (ctx, ws) => records().list(recordsDirFor(ctx, ws), 'kr-metrics');
|
|
32
|
+
|
|
33
|
+
/** The Insights model, through the page's own read, so Export says what the page shows. */
|
|
34
|
+
async function modelOf(req, ctx, ws, board) {
|
|
35
|
+
let out = null;
|
|
36
|
+
const c = Object.assign({}, ctx, { json: (res, obj) => { out = obj; } });
|
|
37
|
+
const u = new URL('http://local/api/insights-premium?' + new URLSearchParams(Object.entries({ ws, board }).filter(([, v]) => v)).toString());
|
|
38
|
+
await require('./routes-insights-premium.js').handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, u, c);
|
|
39
|
+
return out && out.ok ? out.model : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function handle(req, res, url, ctx) {
|
|
43
|
+
const send = (r) => { ctx.json(res, r.body, r.status); return true; };
|
|
44
|
+
const what = url.pathname.replace(/^\/api\/insights-records\/?/, '');
|
|
45
|
+
if (what === 'export') {
|
|
46
|
+
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
47
|
+
const m = await modelOf(req, ctx, url.searchParams.get('ws'), url.searchParams.get('board'));
|
|
48
|
+
if (!m) return send(bad(500, 'The goals could not be read, so there is nothing to export.'));
|
|
49
|
+
res.writeHead(200, { 'Content-Type': 'text/csv; charset=utf-8', 'Content-Disposition': 'attachment; filename="insights-goals.csv"', 'Cache-Control': 'no-store' });
|
|
50
|
+
res.end(IG.exportCsv(m.goals || []));
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
if (!['goal', 'steps', 'dashboard', 'chart', 'describe', 'verdict', 'target'].includes(what)) return send(bad(404, 'no such insights-records route'));
|
|
54
|
+
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
55
|
+
const read = await ctx.readJson(req);
|
|
56
|
+
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
57
|
+
const body = read.body || {};
|
|
58
|
+
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot change Insights. Only a press on the page does'));
|
|
59
|
+
const g = guard.requirePagePress(req, body);
|
|
60
|
+
if (!g.ok) return send(bad(g.status, g.error));
|
|
61
|
+
const w = dashRoutes.wsOf(ctx, text(body.ws));
|
|
62
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
63
|
+
const now = Date.now();
|
|
64
|
+
|
|
65
|
+
if (what === 'describe') {
|
|
66
|
+
let list;
|
|
67
|
+
try { list = krList(ctx, w.id).map((k) => ({ id: k.rid, title: k.metric, pillar: k.pillar || '' })); } catch { return send(bad(503, 'The goals could not be read, so nothing is filled in.')); }
|
|
68
|
+
const d = IG.describe(body.text, list);
|
|
69
|
+
return send(d.ok ? { status: 200, body: d } : bad(400, d.error));
|
|
70
|
+
}
|
|
71
|
+
if (what === 'goal') {
|
|
72
|
+
const f = IG.goalFields(body, { today: today() });
|
|
73
|
+
if (!f.ok) return send(bad(400, f.error));
|
|
74
|
+
const r = records().add(recordsDirFor(ctx, w.id), 'kr-metrics', f.fields, UI(), 'New goal from Insights');
|
|
75
|
+
return send(r.ok ? { status: 200, body: { ok: true, rid: r.rid, fields: f.fields } } : bad(400, r.reasons.join('; ')));
|
|
76
|
+
}
|
|
77
|
+
if (what === 'steps') {
|
|
78
|
+
let cur;
|
|
79
|
+
try { cur = krList(ctx, w.id).find((k) => k.rid === text(body.rid)); } catch { return send(bad(503, 'The goals could not be read.')); }
|
|
80
|
+
if (!cur || !Array.isArray(cur.steps) || !cur.steps.length) return send(bad(404, 'That goal has no steps.'));
|
|
81
|
+
if (!Array.isArray(body.done) || body.done.length !== cur.steps.length) return send(bad(400, 'Say which of its steps are done.'));
|
|
82
|
+
const steps = cur.steps.map((s, i) => ({ text: s.text, done: body.done[i] === true })), n = steps.filter((s) => s.done).length, root = recordsDirFor(ctx, w.id);
|
|
83
|
+
const e = records().edit(root, 'kr-metrics', cur.rid, { steps }, UI(), 'Steps ticked on Insights');
|
|
84
|
+
if (!e.ok) return send(bad(400, e.reasons.join('; ')));
|
|
85
|
+
const r = records().addReading(root, cur.rid, { at: today(), value: n }, UI(), 'Steps done, from Insights');
|
|
86
|
+
return send(r.ok ? { status: 200, body: { ok: true, done: n } } : bad(400, r.reasons.join('; ')));
|
|
87
|
+
}
|
|
88
|
+
if (what === 'target') {
|
|
89
|
+
const r = IR.append(w.root, 'target', body, g.actor, { now });
|
|
90
|
+
return send(r.ok ? { status: 200, body: { ok: true, targets: IR.read(w.root).targets } } : bad(r.status, r.error));
|
|
91
|
+
}
|
|
92
|
+
const ids = dashRoutes.boardIds(ctx, w);
|
|
93
|
+
if (!ids) return send(bad(503, 'The boards could not be read. Try again in a moment.'));
|
|
94
|
+
if (!ids.has(text(body.board))) return send(bad(404, 'no such board in this workspace'));
|
|
95
|
+
if (what === 'verdict') {
|
|
96
|
+
const r = IR.append(w.root, 'verdict', body, g.actor, { now });
|
|
97
|
+
return send(r.ok ? { status: 200, body: { ok: true, verdict: r.line } } : bad(r.status, r.error));
|
|
98
|
+
}
|
|
99
|
+
const ks = dashRoutes.krIds(ctx, w.id);
|
|
100
|
+
if (!ks) return send(bad(503, 'The KR metric records could not be read, so the charts cannot be checked.'));
|
|
101
|
+
if (what === 'chart') {
|
|
102
|
+
const c = IR.checkChart(body);
|
|
103
|
+
if (!c.ok) return send(bad(c.status, c.error));
|
|
104
|
+
if (!ks.has(c.value.goal)) return send(bad(400, 'No KR metric record is called “' + c.value.goal + '” in this workspace.'));
|
|
105
|
+
const D = PD.list(w.root, c.value.board).find((d) => d.id === c.value.dash);
|
|
106
|
+
if (!D) return send(bad(404, 'That dashboard is not on this board.'));
|
|
107
|
+
if (!D.charts.includes(c.value.goal)) {
|
|
108
|
+
if (body.add !== true) return send(bad(400, 'That goal is not on ' + D.name + '.'));
|
|
109
|
+
const s = PD.save(w.root, { id: D.id, board: D.board, name: D.name, purpose: D.purpose, charts: D.charts.concat(c.value.goal), main: D.main }, g.actor, { now, known: { charts: ks } });
|
|
110
|
+
if (!s.ok) return send(bad(s.status, s.error));
|
|
111
|
+
}
|
|
112
|
+
const r = IR.append(w.root, 'chart', c.value, g.actor, { now });
|
|
113
|
+
return send(r.ok ? { status: 200, body: { ok: true, chart: r.line } } : bad(r.status, r.error));
|
|
114
|
+
}
|
|
115
|
+
// dashboard: the dashboard itself, then each chart's form and the range, then the pin
|
|
116
|
+
const list = Array.isArray(body.charts) ? body.charts : [];
|
|
117
|
+
const goals = list.map((x) => (typeof x === 'string' ? x : x && x.goal));
|
|
118
|
+
const range = IR.RANGES.includes(body.range) ? body.range : 'Quarter';
|
|
119
|
+
for (const x of list) { const form = typeof x === 'string' ? 'Line' : x && x.form; if (!IR.FORMS.includes(form || 'Line')) return send(bad(400, 'Pick a form for each chart: ' + IR.FORMS.join(', ') + '.')); }
|
|
120
|
+
const s = PD.save(w.root, { id: body.id, board: body.board, name: body.name, purpose: body.purpose, charts: goals, main: false }, g.actor, { now, known: { charts: ks } });
|
|
121
|
+
if (!s.ok) return send(bad(s.status, s.error));
|
|
122
|
+
const D = s.dashboard;
|
|
123
|
+
list.forEach((x, i) => { IR.append(w.root, 'chart', { board: D.board, dash: D.id, goal: goals[i], form: (x && x.form) || 'Line', range, compare: '', target: true, forecast: false, note: '' }, g.actor, { now }); });
|
|
124
|
+
let pinned = null;
|
|
125
|
+
if (body.pin === true) { const p = PD.pin(w.root, { board: D.board, id: D.id }, g.actor, { now }); if (p.ok) pinned = p.pinned; }
|
|
126
|
+
return send({ status: 200, body: { ok: true, id: D.id, dashboard: D, pinned } });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = { prefixes: ['/api/insights-records'], handle };
|
|
@@ -933,6 +933,7 @@ async function handle(req, res, url, ctx) {
|
|
|
933
933
|
if (note.note.private) return done({ ok: false, status: 409, error: 'this note is marked private, so nothing more is kept in it' });
|
|
934
934
|
if (!note.note.recorded_from) return done({ ok: false, status: 409, error: 'press Listen first' });
|
|
935
935
|
if (!notesScreen.getOn(dir)) return done({ ok: false, status: 409, error: 'Capture the shared screen is switched off in Settings' });
|
|
936
|
+
if (require('./viewer-meeting.js').shotsPaused(dir, id)) return done({ ok: false, status: 423, error: 'screen shots are paused for this note' }); // the Viewer's Pause shots: 423, not 409, so the page's capture keeps running and resumes with Resume shots
|
|
936
937
|
const own = notesCapture.owns(dir, id, { token: body.cap });
|
|
937
938
|
if (!own.ok) return done(own);
|
|
938
939
|
if (typeof body.t !== 'number' || !Number.isFinite(body.t) || body.t < 0) return done({ ok: false, status: 400, error: 'a screenshot needs its meeting time' });
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-viewer.js — the routes of the Viewer's meeting and report panel that no other module answered (initiative premium-agreed-design,
|
|
3
|
+
* area viewer; lib/route-modules.js). The data is kept by lib/viewer-meeting.js and read by lib/viewer-report.js.
|
|
4
|
+
*
|
|
5
|
+
* GET /api/viewer-meeting?note=&event=&series=&title=&length=&topic=…(repeated)
|
|
6
|
+
* → { ok, agenda: { key, topics: [{ n, text, min, set }], total }, capture: { app, shots }, steps: { links: { [stepKey]: ticketId }, tasks: [stepKey] } }
|
|
7
|
+
* agenda: the topics the page sends (the meeting's agenda), each with its minutes. capture and steps need a note.
|
|
8
|
+
* steps.links are the next steps that became a ticket Drafted in PMOS; steps.tasks the ones Make task made a task of (plan-items).
|
|
9
|
+
* POST /api/viewer-meeting/agenda { key, topic, min } → { ok } the minutes of one topic (0 forgets them)
|
|
10
|
+
* POST /api/viewer-meeting/capture { id, app?, shots? } → { ok, capture } what recording listens to; shots on | paused
|
|
11
|
+
* POST /api/viewer-meeting/work-item { note, step: { text, owner?, due? } } → { ok, ticket, created }
|
|
12
|
+
* A next step becomes a ticket Drafted in PMOS on the note's initiative (lib/jira-tickets.js's draft file). It is not approved and not pushed:
|
|
13
|
+
* only the Commit gate pushes a ticket to Jira.
|
|
14
|
+
* GET /api/viewer-report/checks?ws=&path=&slot= → { ok, checks: [{ id, ok, text }] } the three checks before Issue (lib/viewer-report.js)
|
|
15
|
+
* Every POST is a page press (lib/pm-guard.js requirePagePress). Handlers are pure over (q | body, ctx) so a test needs no server. */
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const VM = require('./viewer-meeting.js');
|
|
19
|
+
const VR = require('./viewer-report.js');
|
|
20
|
+
const guard = require('./pm-guard.js');
|
|
21
|
+
|
|
22
|
+
const fail = (status, error) => ({ status, body: { ok: false, error } });
|
|
23
|
+
const okBody = (body) => ({ status: 200, body: { ok: true, ...body } });
|
|
24
|
+
const str = (v, n) => String(v == null ? '' : v).trim().slice(0, n || 300);
|
|
25
|
+
|
|
26
|
+
function noteOf(ctx, id) {
|
|
27
|
+
if (!ctx.runtimeDir || !/^[A-Za-z0-9_-]{1,80}$/.test(String(id || ''))) return null;
|
|
28
|
+
try { const r = require('./notes.js').read(ctx.runtimeDir, String(id)); return r && r.ok ? r.note : null; } catch { return null; }
|
|
29
|
+
}
|
|
30
|
+
function rootOf(ctx, ws) {
|
|
31
|
+
try { const w = ctx.getWs ? ctx.getWs(ws || null) : null; return w && w.root ? w : null; } catch { return null; }
|
|
32
|
+
}
|
|
33
|
+
/** The step keys Make task made a task of: plan items of the initiative whose note names this meeting note's title (premium-meeting.js taskEvent). */
|
|
34
|
+
function tasksOf(root, initiative, title) {
|
|
35
|
+
try {
|
|
36
|
+
const fold = require('./plan-items.js').readFold(root);
|
|
37
|
+
const want = 'From the meeting note "' + (title || 'Untitled note') + '"';
|
|
38
|
+
return (fold.order || []).map((id) => fold.items[id]).filter((it) => it && it.initiative === initiative && it.note === want && it.state !== 'withdrawn').map((it) => VM.stepKey(it.title));
|
|
39
|
+
} catch { return []; }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function meeting(q, ctx) {
|
|
43
|
+
const n = q.note ? noteOf(ctx, q.note) : null;
|
|
44
|
+
const ev = n && n.meeting ? n.meeting : {};
|
|
45
|
+
const key = VM.keyOf({ series: q.series || (n && n.series_pm !== 'off' && n.series && n.series.key) || '', event: q.event || ev.event_id || '', title: q.title || ev.title || (n && n.title) || '' });
|
|
46
|
+
const topics = [].concat(q.topic || []).map((t) => str(t, 300)).filter(Boolean);
|
|
47
|
+
const agenda = { key, ...VM.agendaOf(ctx.runtimeDir, { key, topics, length_min: Number(q.length) || 0 }) };
|
|
48
|
+
const out = { agenda, capture: n ? VM.captureOf(ctx.runtimeDir, n.id) : { app: null, shots: 'on' }, steps: { links: {}, tasks: [] } };
|
|
49
|
+
const ini = n && n.initiative && n.initiative.id ? n.initiative : null;
|
|
50
|
+
const w = ini ? rootOf(ctx, ini.ws || n.ws) : null;
|
|
51
|
+
if (ini && w) out.steps = { links: VM.stepLinks(w.root, ini.id, n.id), tasks: tasksOf(w.root, ini.id, n.title) };
|
|
52
|
+
return okBody(out);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function post(p, req, body, ctx) {
|
|
56
|
+
const g = guard.requirePagePress(req, body);
|
|
57
|
+
if (!g.ok) return fail(g.status, g.error);
|
|
58
|
+
if (p === '/api/viewer-meeting/agenda') { const r = VM.setAgenda(ctx.runtimeDir, body); return r.ok ? okBody({}) : fail(r.status || 400, r.error); }
|
|
59
|
+
if (p === '/api/viewer-meeting/capture') { const r = VM.setCapture(ctx.runtimeDir, body); return r.ok ? okBody({ capture: r.capture }) : fail(r.status || 400, r.error); }
|
|
60
|
+
if (p === '/api/viewer-meeting/work-item') {
|
|
61
|
+
const n = noteOf(ctx, body.note);
|
|
62
|
+
if (!n) return fail(404, 'that note could not be found');
|
|
63
|
+
if (n.private) return fail(409, 'the note is private, so its steps are not kept');
|
|
64
|
+
const ini = n.initiative && n.initiative.id ? n.initiative : null;
|
|
65
|
+
if (!ini) return fail(409, 'link the note to an initiative first: the step becomes a ticket of that initiative');
|
|
66
|
+
const w = rootOf(ctx, ini.ws || n.ws);
|
|
67
|
+
if (!w) return fail(409, 'the initiative\'s repository is not registered in this workspace');
|
|
68
|
+
const start = (n.meeting && n.meeting.start) || n.created_at || '';
|
|
69
|
+
const day = /^\d{4}-\d{2}-\d{2}/.test(start) ? start.slice(0, 10) : '';
|
|
70
|
+
const r = VM.makeWorkItem(w.root, ini.id, { note: { id: n.id, title: n.title, day }, step: body.step || {} });
|
|
71
|
+
if (r.ok && r.created && typeof ctx.invalidateNeedsAgg === 'function') { try { ctx.invalidateNeedsAgg(w.id); } catch { /* a cache that cannot be cleared refreshes on its own */ } }
|
|
72
|
+
return r.ok ? okBody({ ticket: r.ticket, created: r.created }) : fail(r.status || 400, r.error);
|
|
73
|
+
}
|
|
74
|
+
return fail(404, 'no such route');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function checks(q, ctx) {
|
|
78
|
+
const w = rootOf(ctx, q.ws);
|
|
79
|
+
if (!w) return fail(404, 'no such workspace');
|
|
80
|
+
const rel = str(q.path, 400);
|
|
81
|
+
if (!/\.md$/.test(rel) || path.isAbsolute(rel) || !/(^|\/)reports\//.test(rel)) return fail(400, 'path is a report file under reports/');
|
|
82
|
+
const full = path.resolve(w.root, rel), back = path.relative(w.root, full);
|
|
83
|
+
if (!back || back.startsWith('..') || path.isAbsolute(back)) return fail(400, 'path is outside the workspace');
|
|
84
|
+
let text = '';
|
|
85
|
+
try { text = fs.readFileSync(full, 'utf8'); } catch { return fail(404, 'the report file could not be read'); }
|
|
86
|
+
const slot = str(q.slot, 10) || ((/(\d{4}-\d{2}-\d{2})\.md$/.exec(rel) || [])[1] || '');
|
|
87
|
+
return okBody({ checks: VR.issueChecks(text, { slot }) });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const respond = (ctx, res, r) => { ctx.json(res, r.body, r.status); return true; };
|
|
91
|
+
|
|
92
|
+
module.exports = {
|
|
93
|
+
prefixes: ['/api/viewer-meeting', '/api/viewer-report'],
|
|
94
|
+
meeting, post, checks,
|
|
95
|
+
handle: async (req, res, url, ctx) => {
|
|
96
|
+
const p = url.pathname;
|
|
97
|
+
if (p === '/api/viewer-meeting' || p === '/api/viewer-report/checks') {
|
|
98
|
+
if (req.method !== 'GET') return respond(ctx, res, fail(405, 'GET only'));
|
|
99
|
+
const q = Object.fromEntries(url.searchParams); q.topic = url.searchParams.getAll('topic');
|
|
100
|
+
return respond(ctx, res, p === '/api/viewer-meeting' ? meeting(q, ctx) : checks(q, ctx));
|
|
101
|
+
}
|
|
102
|
+
if (!['/api/viewer-meeting/agenda', '/api/viewer-meeting/capture', '/api/viewer-meeting/work-item'].includes(p)) return false;
|
|
103
|
+
if (req.method !== 'POST') return respond(ctx, res, fail(405, 'POST only'));
|
|
104
|
+
const got = await ctx.readJson(req);
|
|
105
|
+
if (!got.ok || !got.body || typeof got.body !== 'object' || Array.isArray(got.body)) return respond(ctx, res, fail(400, 'the body must be a JSON object'));
|
|
106
|
+
return respond(ctx, res, post(p, req, got.body, ctx));
|
|
107
|
+
},
|
|
108
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* transcript-steps.js — what Home's chat draws while an agent works, read from the session's own transcript
|
|
3
|
+
* (initiative premium-agreed-design, Home: the agent step checklist, the run strip and the permission card's before → after).
|
|
4
|
+
*
|
|
5
|
+
* readSteps(file, clean, root) → { steps: [{ text, state: done|now|next }] | null, stepsAt, change: { system, what, from, to, tool } | null }
|
|
6
|
+
*
|
|
7
|
+
* steps the newest TodoWrite list of the session (Claude Code's own plan of its turn): completed → done, in_progress → now,
|
|
8
|
+
* pending → next. null when the session never wrote one: the chat then draws no checklist, never an invented one.
|
|
9
|
+
* A step also carries what the transcript holds about it, and nothing more: a done step that was seen in progress has
|
|
10
|
+
* `sub` ("3 tool calls · 9s", its calls and the time from in progress to completed), and the step in progress has `call`, its
|
|
11
|
+
* newest tool call ("jira.search project = PAY"). Neither is set when the transcript does not show it.
|
|
12
|
+
* change the input of the newest tool call that has no result yet, as a change the PM can read before Allow: the system
|
|
13
|
+
* (File, Jira, Confluence, Slack, Terminal, or the tool's server), the item, and the value before and after where the
|
|
14
|
+
* input holds both (Edit: the old and the new text; a Jira edit: the field's new value). null when no call is open.
|
|
15
|
+
* Only the named fields of an input are read, every string goes through `clean` (server.js scrub, D08), and each is cut short. */
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
const MAX_BYTES = 4 * 1024 * 1024;
|
|
20
|
+
const cut = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1) + '…' : t; };
|
|
21
|
+
|
|
22
|
+
function tail(file) {
|
|
23
|
+
const st = fs.statSync(file);
|
|
24
|
+
const start = Math.max(0, st.size - MAX_BYTES);
|
|
25
|
+
const fd = fs.openSync(file, 'r');
|
|
26
|
+
try {
|
|
27
|
+
const buf = Buffer.allocUnsafe(st.size - start);
|
|
28
|
+
fs.readSync(fd, buf, 0, buf.length, start);
|
|
29
|
+
let raw = buf.toString('utf8');
|
|
30
|
+
if (start > 0) raw = raw.slice(raw.indexOf('\n') + 1);
|
|
31
|
+
return raw;
|
|
32
|
+
} finally { fs.closeSync(fd); }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** One open call's input as a change. Pure. */
|
|
36
|
+
function changeOf(name, input, clean = (x) => x, root = null) {
|
|
37
|
+
const i = input && typeof input === 'object' ? input : {};
|
|
38
|
+
const n = String(name || '');
|
|
39
|
+
const rel = (p) => { const s = String(p || ''); const r = root && path.isAbsolute(s) ? path.relative(root, s) : ''; return r && !r.startsWith('..') ? r : s; };
|
|
40
|
+
const out = (system, what, from, to) => ({ system, what: clean(cut(what, 160)), from: from ? clean(cut(from, 120)) : '', to: to ? clean(cut(to, 120)) : '', tool: clean(cut(n, 80)) });
|
|
41
|
+
if (n === 'Edit' || n === 'MultiEdit') {
|
|
42
|
+
const e = n === 'MultiEdit' && Array.isArray(i.edits) && i.edits[0] ? i.edits[0] : i;
|
|
43
|
+
return out('File', rel(i.file_path), String(e.old_string || '').split('\n')[0], String(e.new_string || '').split('\n')[0]);
|
|
44
|
+
}
|
|
45
|
+
if (n === 'Write') return out('File', rel(i.file_path), '', 'New content · ' + String(i.content || '').split('\n').length + ' lines');
|
|
46
|
+
if (n === 'Bash') return out('Terminal', String(i.command || '').split('\n')[0], '', '');
|
|
47
|
+
const m = /^mcp__(.+?)__(.+)$/.exec(n);
|
|
48
|
+
if (m) {
|
|
49
|
+
const server = m[1].replace(/_/g, ' '), verb = m[2];
|
|
50
|
+
const key = i.issueIdOrKey || i.issueKey || i.issue_key || i.pageId || i.channel_id || i.channel || '';
|
|
51
|
+
if (/jira/i.test(verb) || /atlassian/i.test(server) && key && /^[A-Z][A-Z0-9]+-\d+$/.test(String(key))) {
|
|
52
|
+
if (/transition/i.test(verb)) return out('Jira', key, '', 'Status · ' + ((i.transition && (i.transition.name || i.transition.id)) || i.transitionId || 'a new status'));
|
|
53
|
+
const f = i.fields && typeof i.fields === 'object' ? i.fields : {};
|
|
54
|
+
const k0 = Object.keys(f)[0];
|
|
55
|
+
const v0 = k0 == null ? '' : typeof f[k0] === 'object' ? (f[k0] && (f[k0].name || f[k0].value || f[k0].id)) || JSON.stringify(f[k0]) : f[k0];
|
|
56
|
+
return out('Jira', (key ? key + ' · ' : '') + (i.summary || (k0 ? k0 : verb)), '', v0 ? String(v0) : '');
|
|
57
|
+
}
|
|
58
|
+
if (/confluence/i.test(verb)) return out('Confluence', i.title || key || verb, '', '');
|
|
59
|
+
if (/slack/i.test(server) || /slack/i.test(verb)) return out('Slack', key ? '#' + key : verb, '', cut(i.text || i.message || '', 120));
|
|
60
|
+
return out(server.charAt(0).toUpperCase() + server.slice(1), key || verb, '', '');
|
|
61
|
+
}
|
|
62
|
+
return out(n || 'Tool', i.file_path ? rel(i.file_path) : i.path ? rel(i.path) : i.url || i.pattern || '', '', '');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A call as one short line: the tool ("jira.search" for an MCP tool, else its name) and its main input. */
|
|
66
|
+
function callLine(name, input, clean = (x) => x, root = null) {
|
|
67
|
+
const i = input && typeof input === 'object' ? input : {};
|
|
68
|
+
const n = String(name || '');
|
|
69
|
+
const m = /^mcp__(.+?)__(.+)$/.exec(n);
|
|
70
|
+
const tool = m ? m[1].toLowerCase().replace(/[^a-z0-9]+/g, '') + '.' + m[2].replace(/^(jira|confluence|slack)_?/i, '').replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase().split('_')[0] : n;
|
|
71
|
+
const rel = (p) => { const x = String(p || ''); const r = root && path.isAbsolute(x) ? path.relative(root, x) : ''; return r && !r.startsWith('..') ? r : x; };
|
|
72
|
+
const arg = i.command ? String(i.command).split('\n')[0] : i.file_path ? rel(i.file_path) : i.path ? rel(i.path) : i.jql || i.query || i.cql || i.pattern || i.url || i.issueIdOrKey || i.issueKey || i.pageId || '';
|
|
73
|
+
return clean(cut(tool + (arg ? ' ' + arg : ''), 90));
|
|
74
|
+
}
|
|
75
|
+
const secs = (a, b) => { const t = (Date.parse(b) - Date.parse(a)) / 1000; return Number.isFinite(t) && t >= 0 ? (t < 60 ? Math.round(t) + 's' : t < 3600 ? Math.round(t / 60) + ' min' : Math.floor(t / 3600) + ' h ' + Math.round((t % 3600) / 60) + ' min') : ''; };
|
|
76
|
+
|
|
77
|
+
/** The steps and the open change from a transcript's text. Pure over the text. */
|
|
78
|
+
function stepsOf(raw, clean = (x) => x, root = null) {
|
|
79
|
+
let todos = null, todosAt = null;
|
|
80
|
+
const open = new Map();
|
|
81
|
+
const seen = new Map(); // a step's content → { start, end, calls, last }: what the transcript shows of it
|
|
82
|
+
let doing = null; // the content of the step in progress now
|
|
83
|
+
for (const line of String(raw || '').split('\n')) {
|
|
84
|
+
if (!line) continue;
|
|
85
|
+
let r; try { r = JSON.parse(line); } catch { continue; }
|
|
86
|
+
if (r.isSidechain) continue;
|
|
87
|
+
const content = r.message && Array.isArray(r.message.content) ? r.message.content : [];
|
|
88
|
+
if (r.type === 'user') { for (const c of content) if (c && c.type === 'tool_result' && c.tool_use_id) open.delete(c.tool_use_id); continue; }
|
|
89
|
+
if (r.type !== 'assistant') continue;
|
|
90
|
+
for (const c of content) {
|
|
91
|
+
if (!c || c.type !== 'tool_use') continue;
|
|
92
|
+
if (c.name === 'TodoWrite' && c.input && Array.isArray(c.input.todos)) {
|
|
93
|
+
todos = c.input.todos; todosAt = r.timestamp || null; doing = null;
|
|
94
|
+
for (const t of todos) {
|
|
95
|
+
if (!t || !t.content) continue;
|
|
96
|
+
const k = String(t.content), st = seen.get(k) || {};
|
|
97
|
+
if (t.status === 'in_progress') { if (!st.start) st.start = r.timestamp || null; doing = k; }
|
|
98
|
+
if (t.status === 'completed' && st.start && !st.end) st.end = r.timestamp || null;
|
|
99
|
+
seen.set(k, st);
|
|
100
|
+
}
|
|
101
|
+
} else if (doing && c.name !== 'AskUserQuestion') { const st = seen.get(doing); st.calls = (st.calls || 0) + 1; st.last = { name: c.name, input: c.input }; }
|
|
102
|
+
if (c.id) open.set(c.id, { name: c.name, input: c.input });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const steps = todos ? todos.slice(0, 12).map((t) => {
|
|
106
|
+
const s = { text: clean(cut(t && (t.status === 'in_progress' && t.activeForm ? t.activeForm : t.content), 140)),
|
|
107
|
+
state: t && t.status === 'completed' ? 'done' : t && t.status === 'in_progress' ? 'now' : 'next' };
|
|
108
|
+
const st = t && t.content ? seen.get(String(t.content)) : null;
|
|
109
|
+
if (st && s.state === 'done' && st.start && st.end) s.sub = [st.calls ? st.calls + (st.calls === 1 ? ' tool call' : ' tool calls') : '', secs(st.start, st.end)].filter(Boolean).join(' · ');
|
|
110
|
+
if (st && s.state === 'now' && st.last) s.call = callLine(st.last.name, st.last.input, clean, root);
|
|
111
|
+
if (!s.sub) delete s.sub;
|
|
112
|
+
return s;
|
|
113
|
+
}).filter((s) => s.text) : null;
|
|
114
|
+
let last = null; for (const [, v] of open) last = v;
|
|
115
|
+
const change = last && last.name !== 'TodoWrite' && last.name !== 'AskUserQuestion' ? changeOf(last.name, last.input, clean, root) : null;
|
|
116
|
+
return { steps: steps && steps.length ? steps : null, stepsAt: todosAt, change };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function readSteps(file, clean = (x) => x, root = null) {
|
|
120
|
+
try { return stepsOf(tail(file), clean, root); } catch { return { steps: null, stepsAt: null, change: null }; }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
module.exports = { readSteps, stepsOf, changeOf };
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* viewer-meeting.js — the data the Viewer's meeting needs that no other record held (initiative premium-agreed-design, area viewer).
|
|
3
|
+
* The Agreed design (Main.dc.html, AgPrep / AgMeetLive / AgMeeting) draws four things PMOS kept nowhere. Each is kept here, file mode,
|
|
4
|
+
* in the per-user runtime folder beside the notes (lib/notes.js keeps its notes there too):
|
|
5
|
+
*
|
|
6
|
+
* AGENDA MINUTES "Agenda · 3 topics · 30 min" with the minutes of each topic.
|
|
7
|
+
* agendaOf(dir, { key, topics, length_min }) → { topics: [{ n, text, min, set }], total }
|
|
8
|
+
* A topic's minutes are, in order: what the PM set for it (setAgenda), the minutes its own text names ("5 min: what changed"),
|
|
9
|
+
* else an even share of what the meeting has left, rounded to 5 minutes (set: false says it is that share).
|
|
10
|
+
* setAgenda(dir, { key, topic, min }) → { ok } one line of <runtime>/viewer-agenda.jsonl; min 0 forgets it
|
|
11
|
+
* The key is the meeting's series when it has one, else its calendar event id, else its title (keyOf).
|
|
12
|
+
*
|
|
13
|
+
* WHAT RECORDING LISTENS TO "Listening to Zoom app · microphone and meeting · Change" and "4 screen shots · Pause shots".
|
|
14
|
+
* captureOf(dir, id) → { app, shots } setCapture(dir, { id, app?, shots? }) → { ok, capture } shotsPaused(dir, id) → boolean
|
|
15
|
+
* One line of <runtime>/viewer-capture.jsonl per change. While shots are paused, POST /api/notes/screen keeps no frame for the note
|
|
16
|
+
* (lib/routes-notes.js asks shotsPaused). app is one of listen-sources.js APPS (zoom, meet, other).
|
|
17
|
+
*
|
|
18
|
+
* A NEXT STEP THAT BECOMES A WORK-ITEM "Becomes V.4" (PM 2026-10-22: a ticket Drafted in PMOS, shown on the Board's Drafted in PMOS,
|
|
19
|
+
* never pushed to Jira without the Commit gate).
|
|
20
|
+
* stepKey(text) → 8 hex the step's key: its words, folded
|
|
21
|
+
* stepLinks(root, initiative, noteId) → { [stepKey]: ticketId } derived from the ticket draft: a ticket made from a step names the note
|
|
22
|
+
* and the step in its Refs ("- Meeting note: <id> · step <key>"). Nothing else is stored.
|
|
23
|
+
* makeWorkItem(root, initiative, { note, step }) → { ok, ticket, created } appends one ticket to <state>/tracker/jira/<initiative>-tickets.md
|
|
24
|
+
* (lib/jira-tickets.js's draft file) with no Jira key and no approval. A second press on the same step
|
|
25
|
+
* answers the ticket it already made.
|
|
26
|
+
* nextTicketId(ids, title) → 'V.4' the next id in the draft's own numbering, or the initiative's initial and 1.
|
|
27
|
+
*
|
|
28
|
+
* Nothing here sends anything, and nothing here writes the calendar. */
|
|
29
|
+
const fs = require('fs');
|
|
30
|
+
const path = require('path');
|
|
31
|
+
const crypto = require('crypto');
|
|
32
|
+
|
|
33
|
+
const AGENDA = 'viewer-agenda.jsonl';
|
|
34
|
+
const CAPTURE = 'viewer-capture.jsonl';
|
|
35
|
+
const APPS = ['zoom', 'meet', 'other'];
|
|
36
|
+
const NOTE_ID = /^[A-Za-z0-9_-]{1,80}$/;
|
|
37
|
+
const str = (v, n) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n || 300);
|
|
38
|
+
const norm = (s) => str(s, 400).toLowerCase().replace(/[^a-z0-9 ]+/g, ' ').replace(/\s+/g, ' ').trim();
|
|
39
|
+
|
|
40
|
+
function readLines(file) {
|
|
41
|
+
let text = '';
|
|
42
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const l of text.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && typeof o === 'object') out.push(o); } catch { /* a torn line is skipped */ } }
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
function append(file, line) {
|
|
48
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
49
|
+
fs.appendFileSync(file, JSON.stringify({ v: 1, ...line, at: new Date().toISOString() }) + '\n');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* ── agenda minutes ─────────────────────────────────────────────────────────────────────────────────────────── */
|
|
53
|
+
|
|
54
|
+
/** The key the minutes of a meeting are kept under: its series, else its event id, else its title. '' when none is given. */
|
|
55
|
+
function keyOf({ series, event, title } = {}) {
|
|
56
|
+
if (str(series, 200)) return 's:' + str(series, 200);
|
|
57
|
+
if (str(event, 120)) return 'e:' + str(event, 120);
|
|
58
|
+
if (norm(title)) return 't:' + norm(title).slice(0, 200);
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
/** "5 min: what changed", "What changed (5 min)", "What changed - 5m" → { text, min }; a text with no minutes → { text, min: null }. */
|
|
62
|
+
function parseTopic(raw) {
|
|
63
|
+
const t = str(raw, 300);
|
|
64
|
+
let m = /^(\d{1,3})\s*(?:min|mins|minutes|m)\b\s*[:·\-–—]?\s*(.+)$/i.exec(t);
|
|
65
|
+
if (m) return { text: m[2].trim(), min: +m[1] };
|
|
66
|
+
m = /^(.+?)\s*[(\[·\-–—,]\s*(\d{1,3})\s*(?:min|mins|minutes|m)\s*[)\]]?\s*$/i.exec(t);
|
|
67
|
+
if (m) return { text: m[1].trim(), min: +m[2] };
|
|
68
|
+
return { text: t, min: null };
|
|
69
|
+
}
|
|
70
|
+
/** What the PM set, per topic, for one key: { [norm(topic)]: min }. A later line wins; 0 forgets. */
|
|
71
|
+
function setMinutes(dir, key) {
|
|
72
|
+
const out = {};
|
|
73
|
+
for (const l of readLines(path.join(dir, AGENDA))) {
|
|
74
|
+
if (l.key !== key || !l.topic) continue;
|
|
75
|
+
if (l.min > 0) out[norm(l.topic)] = l.min; else delete out[norm(l.topic)];
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
const round5 = (n) => Math.max(5, Math.round(n / 5) * 5);
|
|
80
|
+
/** The agenda with each topic's minutes. topics are strings (or { text }); length_min is the meeting's length, when known. */
|
|
81
|
+
function agendaOf(dir, { key, topics, length_min } = {}) {
|
|
82
|
+
const set = dir && key ? setMinutes(dir, key) : {};
|
|
83
|
+
const list = (Array.isArray(topics) ? topics : []).map((x) => (x && typeof x === 'object' ? x.text : x)).filter((x) => str(x)).slice(0, 20).map(parseTopic);
|
|
84
|
+
const rows = list.map((t, i) => {
|
|
85
|
+
const pm = set[norm(t.text)];
|
|
86
|
+
return { n: i + 1, text: t.text, min: pm || t.min || null, set: !!(pm || t.min) };
|
|
87
|
+
});
|
|
88
|
+
const known = rows.filter((r) => r.min).reduce((a, r) => a + r.min, 0), open = rows.filter((r) => !r.min);
|
|
89
|
+
const len = Number(length_min) > 0 ? Number(length_min) : 0;
|
|
90
|
+
if (open.length && len > known) { const share = round5((len - known) / open.length); open.forEach((r) => { r.min = share; }); }
|
|
91
|
+
return { topics: rows, total: rows.reduce((a, r) => a + (r.min || 0), 0) };
|
|
92
|
+
}
|
|
93
|
+
function setAgenda(dir, { key, topic, min } = {}) {
|
|
94
|
+
if (!dir) return { ok: false, status: 409, error: 'this server has no runtime folder, so the minutes cannot be kept' };
|
|
95
|
+
if (!str(key, 260)) return { ok: false, status: 400, error: 'key is required: the meeting\'s series, event or title' };
|
|
96
|
+
if (!str(topic, 300)) return { ok: false, status: 400, error: 'topic is required' };
|
|
97
|
+
const m = Number(min);
|
|
98
|
+
if (!Number.isInteger(m) || m < 0 || m > 600) return { ok: false, status: 400, error: 'min is a whole number of minutes, 0 to 600' };
|
|
99
|
+
append(path.join(dir, AGENDA), { key: str(key, 260), topic: str(topic, 300), min: m });
|
|
100
|
+
return { ok: true };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* ── what recording listens to ──────────────────────────────────────────────────────────────────────────────── */
|
|
104
|
+
|
|
105
|
+
function captureOf(dir, id) {
|
|
106
|
+
const out = { app: null, shots: 'on' };
|
|
107
|
+
if (!dir || !NOTE_ID.test(String(id || ''))) return out;
|
|
108
|
+
for (const l of readLines(path.join(dir, CAPTURE))) {
|
|
109
|
+
if (l.id !== id) continue;
|
|
110
|
+
if (APPS.includes(l.app)) out.app = l.app;
|
|
111
|
+
if (l.shots === 'on' || l.shots === 'paused') out.shots = l.shots;
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
const shotsPaused = (dir, id) => captureOf(dir, id).shots === 'paused';
|
|
116
|
+
function setCapture(dir, { id, app, shots } = {}) {
|
|
117
|
+
if (!dir) return { ok: false, status: 409, error: 'this server has no runtime folder' };
|
|
118
|
+
if (!NOTE_ID.test(String(id || ''))) return { ok: false, status: 400, error: 'id is the note\'s id' };
|
|
119
|
+
const line = { id };
|
|
120
|
+
if (app !== undefined) { if (!APPS.includes(app)) return { ok: false, status: 400, error: 'app is one of ' + APPS.join(', ') }; line.app = app; }
|
|
121
|
+
if (shots !== undefined) { if (shots !== 'on' && shots !== 'paused') return { ok: false, status: 400, error: 'shots is on or paused' }; line.shots = shots; }
|
|
122
|
+
if (line.app === undefined && line.shots === undefined) return { ok: false, status: 400, error: 'nothing to change: send app or shots' };
|
|
123
|
+
append(path.join(dir, CAPTURE), line);
|
|
124
|
+
return { ok: true, capture: captureOf(dir, id) };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* ── a next step that becomes a work-item ───────────────────────────────────────────────────────────────────── */
|
|
128
|
+
|
|
129
|
+
const stepKey = (text) => crypto.createHash('sha256').update(norm(text)).digest('hex').slice(0, 8);
|
|
130
|
+
const REF_RE = /^- Meeting note: ([A-Za-z0-9_-]{1,80}) · step ([0-9a-f]{8})\b/m;
|
|
131
|
+
const jt = () => require('./jira-tickets.js');
|
|
132
|
+
|
|
133
|
+
/** { [stepKey]: ticketId } for the tickets of `initiative` made from a step of note `noteId`. */
|
|
134
|
+
function stepLinks(root, initiative, noteId) {
|
|
135
|
+
const out = {};
|
|
136
|
+
let d = null;
|
|
137
|
+
try { d = jt().readDraft(root, initiative); } catch { d = null; }
|
|
138
|
+
for (const t of (d && d.tickets) || []) {
|
|
139
|
+
const m = REF_RE.exec(String((t.sections && t.sections.refs) || ''));
|
|
140
|
+
if (m && m[1] === noteId && !out[m[2]]) out[m[2]] = t.id;
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
/** The next ticket id: the draft's most used "<prefix><n>" plus one, keeping its padding; with no ticket, the initiative's initial, a dot and 1. */
|
|
145
|
+
function nextTicketId(ids, title) {
|
|
146
|
+
const seen = new Map();
|
|
147
|
+
for (const id of ids || []) {
|
|
148
|
+
const m = /^(.*?)(\d+)$/.exec(String(id || ''));
|
|
149
|
+
if (!m) continue;
|
|
150
|
+
const k = m[1], v = seen.get(k) || { n: 0, max: 0, pad: m[2].length };
|
|
151
|
+
v.n++; v.max = Math.max(v.max, +m[2]); v.pad = Math.max(v.pad, m[2].length); seen.set(k, v);
|
|
152
|
+
}
|
|
153
|
+
if (seen.size) {
|
|
154
|
+
const [pre, v] = [...seen.entries()].sort((a, b) => b[1].n - a[1].n)[0];
|
|
155
|
+
return pre + String(v.max + 1).padStart(v.pad, '0');
|
|
156
|
+
}
|
|
157
|
+
const init = (String(title || '').match(/[A-Za-z]/) || ['T'])[0].toUpperCase();
|
|
158
|
+
return init + '.1';
|
|
159
|
+
}
|
|
160
|
+
const oneLine = (s) => str(s, 250);
|
|
161
|
+
/** The ticket block, in the draft file's own form (lib/jira-tickets.js renderDraft): fields, then the seven sections, "—" for an empty one. */
|
|
162
|
+
function ticketBlock(t) {
|
|
163
|
+
const lines = [`## ${t.id} · ${oneLine(t.summary)}`, `- type: ${t.type}`, `- priority: ${t.priority}`, `- drafted: ${t.drafted}`, ''];
|
|
164
|
+
for (const [k, head] of jt().SECTIONS) lines.push(`### ${head}`, '', String(t.sections[k] || '').trim() || '—', '');
|
|
165
|
+
return lines.join('\n');
|
|
166
|
+
}
|
|
167
|
+
function makeWorkItem(root, initiative, { note, step } = {}) {
|
|
168
|
+
const T = jt();
|
|
169
|
+
if (!root) return { ok: false, status: 409, error: 'the note\'s repository is not registered here' };
|
|
170
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/.test(String(initiative || ''))) return { ok: false, status: 400, error: 'the note is not linked to an initiative' };
|
|
171
|
+
if (!note || !NOTE_ID.test(String(note.id || ''))) return { ok: false, status: 400, error: 'note is { id, title }' };
|
|
172
|
+
const text = oneLine(step && step.text);
|
|
173
|
+
if (!text) return { ok: false, status: 400, error: 'step.text is required' };
|
|
174
|
+
const rfm = T.recordFm(root, initiative);
|
|
175
|
+
if (!rfm) return { ok: false, status: 404, error: `no initiative ${initiative} in this repository` };
|
|
176
|
+
const key = stepKey(text);
|
|
177
|
+
const had = stepLinks(root, initiative, note.id)[key];
|
|
178
|
+
if (had) return { ok: true, ticket: had, created: false };
|
|
179
|
+
const d = T.readDraft(root, initiative);
|
|
180
|
+
const id = nextTicketId(d ? d.tickets.map((x) => x.id) : [], rfm.title || initiative);
|
|
181
|
+
const day = str(note.day, 40);
|
|
182
|
+
const who = [str(step.owner, 60) && 'Owner: ' + str(step.owner, 60), /^\d{4}-\d{2}-\d{2}$/.test(String(step.due || '')) && 'Due: ' + step.due].filter(Boolean).join(' · ');
|
|
183
|
+
const t = { id, summary: text, type: 'Task', priority: 'Medium', estimate: null, depends: [], sections: {} };
|
|
184
|
+
for (const [k] of T.SECTIONS) t.sections[k] = '';
|
|
185
|
+
t.sections.context = `A next step of the meeting "${str(note.title, 160) || 'Untitled note'}"${day ? ' (' + day + ')' : ''}.${who ? ' ' + who + '.' : ''}`;
|
|
186
|
+
t.sections.refs = `- Meeting note: ${note.id} · step ${key}`;
|
|
187
|
+
t.drafted = T.contentHash(t);
|
|
188
|
+
const file = T.draftPath(root, initiative);
|
|
189
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
190
|
+
let text0 = '';
|
|
191
|
+
try { text0 = fs.readFileSync(file, 'utf8'); } catch { text0 = ''; }
|
|
192
|
+
if (!text0) {
|
|
193
|
+
const ts = new Date().toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
194
|
+
text0 = ['---', 'type: Reference', `title: "Jira tickets: ${initiative}"`, `timestamp: ${ts}`, '---', '', `# Jira tickets: ${initiative}`, '',
|
|
195
|
+
'Drafted in PMOS. Read and edit them on the initiative\'s Jira tickets tab, or here. Check the ones that are ready and press Push: only checked tickets are sent.', '',
|
|
196
|
+
'PMOS owns the text of these tickets and Jira owns their status.', ''].join('\n');
|
|
197
|
+
}
|
|
198
|
+
const out = text0.replace(/\n*$/, '\n') + '\n' + ticketBlock(t);
|
|
199
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
200
|
+
fs.writeFileSync(tmp, out);
|
|
201
|
+
fs.renameSync(tmp, file);
|
|
202
|
+
return { ok: true, ticket: id, created: true, draft: T.draftRel(root, initiative) };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
module.exports = { AGENDA, CAPTURE, APPS, keyOf, parseTopic, agendaOf, setAgenda, captureOf, setCapture, shotsPaused, stepKey, stepLinks, nextTicketId, makeWorkItem };
|