create-pmos 0.396.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 +25 -25
- 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/scripts/nine-stages.js +49 -20
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +103 -74
- package/workspace/briefing-premium-board-test.js +316 -154
- package/workspace/briefing-premium-calendar-2-test.js +135 -195
- package/workspace/briefing-premium-calendar-3-test.js +143 -413
- package/workspace/briefing-premium-calendar-test.js +86 -185
- package/workspace/briefing-premium-doc-edit-test.js +95 -83
- package/workspace/briefing-premium-initiative-test.js +166 -294
- package/workspace/briefing-premium-insights-test.js +351 -214
- package/workspace/briefing-premium-metrics-test.js +53 -118
- package/workspace/briefing-premium-products-test.js +40 -27
- package/workspace/briefing-premium-sources-test.js +91 -52
- package/workspace/briefing-premium-test.js +150 -633
- package/workspace/briefing-premium-work-test.js +88 -269
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/board-premium-facts.js +2 -1
- package/workspace/fixtures/board-premium-jira.js +28 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/initiative-premium-facts.js +2 -1
- package/workspace/fixtures/initiatives-api/list.json +30 -42
- package/workspace/fixtures/initiatives-api/roadmap.json +40 -56
- package/workspace/fixtures/initiatives-api/sheet.json +10 -14
- package/workspace/fixtures/insights-premium-facts.js +11 -2
- 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 +2 -0
- package/workspace/guide/lifecycle.md +51 -0
- package/workspace/home-shot.js +38 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-premium.js +160 -3
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/engine/boards.js +15 -14
- package/workspace/lib/engine/nine-stages.js +49 -20
- package/workspace/lib/engine/signals/detectors.js +13 -11
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +126 -1
- 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-premium.js +3 -2
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-initiatives.js +1 -1
- package/workspace/lib/routes-insights-premium.js +19 -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/vendor/scripts/nine-stages.js +49 -20
- 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-agreed-viewer-shots.js +76 -0
- package/workspace/premium-board-actions-test.js +85 -73
- 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 -36
- package/workspace/premium-chat-context-test.js +22 -19
- package/workspace/premium-chat-goal-view-test.js +28 -26
- package/workspace/premium-chat-notes-test.js +29 -33
- package/workspace/premium-chat-report-tab-test.js +35 -25
- package/workspace/premium-chat-term-test.js +16 -14
- package/workspace/premium-chat-viewer-test.js +60 -53
- package/workspace/premium-core-doc-issue-test.js +50 -41
- package/workspace/premium-html-viewer-test.js +17 -18
- package/workspace/premium-phone-card-test.js +8 -2
- package/workspace/premium-phone-room-test.js +42 -31
- 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 -31
- package/workspace/premium-vw-cal-test.js +82 -123
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +12 -11
- package/workspace/premium-vw-item-test.js +50 -48
- package/workspace/premium-vw-jira-test.js +55 -26
- package/workspace/premium-vw-meet-test.js +118 -187
- package/workspace/premium-vw-notes-test.js +85 -107
- package/workspace/premium-vw-rec-test.js +72 -193
- package/workspace/premium-vw-slides-test.js +46 -50
- package/workspace/premium-welcome-test.js +3 -2
- package/workspace/premium-work-depth-test.js +63 -51
- package/workspace/public/pm/bd-acts.js +305 -0
- package/workspace/public/pm/bd-span.js +224 -0
- package/workspace/public/pm/bd-stages.js +47 -0
- 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 +640 -0
- package/workspace/public/pm/cozy-home.css +580 -0
- package/workspace/public/pm/cozy-home.js +172 -0
- package/workspace/public/pm/cozy-initiative.css +138 -0
- package/workspace/public/pm/cozy-insights.css +421 -0
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +65 -0
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-viewer.css +143 -0
- package/workspace/public/pm/cozy-viewer.js +144 -0
- package/workspace/public/pm/cozy-vw.css +485 -0
- package/workspace/public/pm/cozy.css +254 -0
- 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/lifecycle-lens-model.js +45 -27
- package/workspace/public/pm/lifecycle-lens.js +22 -11
- 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 +544 -253
- package/workspace/public/pm/premium-brief.js +1 -1
- package/workspace/public/pm/premium-chart-tab.js +110 -62
- package/workspace/public/pm/premium-chat.js +17 -10
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +25 -21
- package/workspace/public/pm/premium-initiative-head.js +138 -0
- package/workspace/public/pm/premium-initiative.js +28 -4
- package/workspace/public/pm/premium-insights.js +950 -440
- 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 +107 -124
- package/workspace/public/pm/premium-viewer.js +27 -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-jira-model.js +22 -5
- package/workspace/public/pm/premium-vw-jira.css +11 -0
- package/workspace/public/pm/premium-vw-jira.js +11 -4
- 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 -215
- 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 +57 -64
- package/workspace/public/premium-chat.html +7 -33
- package/workspace/public/premium-initiative.html +8 -41
- package/workspace/public/premium-insights.html +63 -62
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium-work.html +6 -72
- package/workspace/public/premium.html +21 -66
- package/workspace/public/vendor/nunito-var.woff2 +0 -0
- package/workspace/server.js +25 -3
- package/workspace/test-files.json +1 -0
- package/workspace/test-lists/home-libs.json +9 -0
- package/workspace/test-lists/premium-agreed-viewer.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/third-party/README.md +1 -0
- package/workspace/public/pm/premium-work.js +0 -719
- package/workspace/public/pm/premium.js +0 -1133
|
@@ -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 };
|
|
@@ -1,40 +1,63 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/*
|
|
3
|
-
* The
|
|
3
|
+
* The lifecycle label layer over the workflow engine's derived stage: six stages and two milestones
|
|
4
|
+
* (premium-agreed-design L1, PM decision 2026-10-22). The file keeps its old name and export names
|
|
5
|
+
* (`nineStages`, `STAGES`, `LABELS`, `LANE_STAGES`) so that every caller keeps working; the
|
|
6
|
+
* `nine_stages` field on a row keeps its name for the same reason. It now carries eight entries.
|
|
7
|
+
*
|
|
8
|
+
* Triage (BRD) → Discover (PRD) → Plan (scope, timeline, WBS; the PM's Commit pushes tickets to Jira)
|
|
9
|
+
* → Prioritize (ranked on the roadmap) → Build (features delivered, Jira) → ◆ Deliver (milestone:
|
|
10
|
+
* release shipped, PM sign-off) → Monitor (outcome report) → ◆ Evaluate (milestone: keep, iterate or stop)
|
|
4
11
|
*
|
|
5
12
|
* The engine derives one of six rungs (intake, spec, contract, build, eval, accepted) from the steps
|
|
6
|
-
* it found. This file names the
|
|
7
|
-
*
|
|
8
|
-
*
|
|
13
|
+
* it found. This file names the stages the PM sees and says which of them each lane uses. It never
|
|
14
|
+
* decides a stage itself: a stage is `done` only when a derived signal shows it, and a stage no record
|
|
15
|
+
* can yet show is `no-signal`, not guessed.
|
|
9
16
|
*
|
|
10
|
-
*
|
|
17
|
+
* Migration: the old nine had Ideate and Strategize. Stage is derived, never stored, so there is no
|
|
18
|
+
* stored stage to rewrite. Records that signalled Ideate (ideas, hypotheses) now count for Discover;
|
|
19
|
+
* records that signalled Strategize (decisions, bets) now count for Prioritize. `stageKey` maps an
|
|
20
|
+
* old key read from anywhere (a stored payload, a URL, a fixture) to its new key at read time.
|
|
11
21
|
*/
|
|
12
22
|
|
|
13
|
-
const STAGES = ['
|
|
23
|
+
const STAGES = ['triage', 'discover', 'plan', 'prioritize', 'build', 'deliver', 'monitor', 'evaluate'];
|
|
14
24
|
|
|
15
25
|
const LABELS = {
|
|
16
|
-
|
|
26
|
+
triage: 'Triage', discover: 'Discover', plan: 'Plan', prioritize: 'Prioritize',
|
|
17
27
|
build: 'Build', deliver: 'Deliver', monitor: 'Monitor', evaluate: 'Evaluate',
|
|
18
28
|
};
|
|
19
29
|
|
|
30
|
+
// What each stage produces (the PM's words on the Agreed design).
|
|
31
|
+
const OUTPUTS = {
|
|
32
|
+
triage: 'BRD', discover: 'PRD', plan: 'Scope, timeline and work breakdown', prioritize: 'Ranked on the roadmap',
|
|
33
|
+
build: 'Features delivered (Jira)', deliver: 'Release shipped, PM sign-off', monitor: 'Outcome report', evaluate: 'Keep, iterate or stop',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Deliver and Evaluate are milestones (drawn as a diamond), not stages with duration.
|
|
37
|
+
const MILESTONES = new Set(['deliver', 'evaluate']);
|
|
38
|
+
|
|
39
|
+
// The removed keys and where they went. Read-time only: nothing stored is rewritten.
|
|
40
|
+
const LEGACY = { ideate: 'discover', strategize: 'prioritize' };
|
|
41
|
+
const stageKey = (k) => (k == null ? k : LEGACY[k] || k);
|
|
42
|
+
|
|
20
43
|
// Which stages each product-code lane uses. Stages not listed read `skipped`.
|
|
21
44
|
const LANE_STAGES = {
|
|
22
45
|
feature: STAGES,
|
|
23
|
-
discovery: ['
|
|
24
|
-
chore: ['plan', 'build', 'evaluate'],
|
|
46
|
+
discovery: ['triage', 'discover', 'prioritize', 'evaluate'],
|
|
47
|
+
chore: ['plan', 'build', 'deliver', 'evaluate'],
|
|
25
48
|
incident: ['build', 'deliver', 'monitor', 'evaluate'],
|
|
26
|
-
content: ['
|
|
27
|
-
prototype: ['
|
|
49
|
+
content: ['discover', 'plan', 'build', 'deliver'],
|
|
50
|
+
prototype: ['triage', 'discover', 'evaluate'],
|
|
28
51
|
};
|
|
29
52
|
|
|
30
53
|
// Stages that have a derived signal today. Every other stage reads `no-signal` until its record exists.
|
|
31
|
-
const SIGNALLED = new Set(['discover', 'plan', 'build', 'evaluate']);
|
|
54
|
+
const SIGNALLED = new Set(['triage', 'discover', 'plan', 'build', 'evaluate']);
|
|
32
55
|
|
|
33
56
|
const RANK = { intake: 0, spec: 1, contract: 2, build: 3, eval: 4, accepted: 5 };
|
|
34
57
|
|
|
35
58
|
// Stages that gain a signal only when the caller passes the records (scripts/records readAll plus optional `releases`).
|
|
36
|
-
// With no records the output is exactly the
|
|
37
|
-
const RECORD_SIGNALLED = new Set(['
|
|
59
|
+
// With no records the output is exactly the records-free output, so the lifecycle-lens mirror stays equal.
|
|
60
|
+
const RECORD_SIGNALLED = new Set(['discover', 'prioritize', 'monitor', 'deliver']);
|
|
38
61
|
|
|
39
62
|
// records: { initiative?, anchor?, ideas, hypotheses, decisions, bets, 'kr-metrics', releases } (every list optional).
|
|
40
63
|
// The initiative id and anchor come from `derived` (id, anchor) or from records.initiative / records.anchor.
|
|
@@ -43,10 +66,12 @@ function recordSignals(derived, records, buildDone) {
|
|
|
43
66
|
const anchor = (derived && derived.anchor) || records.anchor || null;
|
|
44
67
|
const mine = (list) => (list || []).filter((r) => id && r.initiative === id);
|
|
45
68
|
const kr = (records['kr-metrics'] || []).filter((m) => anchor && (m.rid === anchor || m.parent_kr === anchor || 'kr:' + m.rid === anchor));
|
|
69
|
+
const ranked = mine(records.bets).some((b) => ['now', 'next', 'later'].includes(b.horizon) && Number.isInteger(b.rank));
|
|
46
70
|
return {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
71
|
+
// was Ideate: an idea or hypothesis on the initiative
|
|
72
|
+
discover: mine(records.ideas).length + mine(records.hypotheses).length > 0,
|
|
73
|
+
// was Strategize (a decision or bet) or the old Prioritize (a ranked bet)
|
|
74
|
+
prioritize: ranked || mine(records.decisions).length + mine(records.bets).length > 0,
|
|
50
75
|
monitor: !!buildDone && kr.some((m) => (m.readings || []).length > 0),
|
|
51
76
|
deliver: mine(records.releases).length > 0,
|
|
52
77
|
};
|
|
@@ -57,6 +82,7 @@ function nineStages(lane, derived, records) {
|
|
|
57
82
|
const rank = RANK[derived && derived.stage] ?? 0;
|
|
58
83
|
const step = (key) => (derived && derived.steps || []).find((s) => s.key === key);
|
|
59
84
|
const done = {
|
|
85
|
+
triage: rank >= 1,
|
|
60
86
|
discover: rank >= 1,
|
|
61
87
|
plan: rank >= 2,
|
|
62
88
|
build: rank >= 3 || (step('build') && step('build').status === 'done'),
|
|
@@ -64,18 +90,21 @@ function nineStages(lane, derived, records) {
|
|
|
64
90
|
};
|
|
65
91
|
const accepted = rank >= 5;
|
|
66
92
|
const fromRecords = records && typeof records === 'object' ? recordSignals(derived, records, done.build) : null;
|
|
93
|
+
const signalled = (key) => SIGNALLED.has(key) || (fromRecords && RECORD_SIGNALLED.has(key) && (key !== 'deliver' || fromRecords.deliver));
|
|
67
94
|
const out = [];
|
|
68
95
|
let currentSet = false;
|
|
69
96
|
for (const key of STAGES) {
|
|
70
97
|
let status;
|
|
71
98
|
if (!laneSet.has(key)) status = 'skipped';
|
|
72
|
-
else if (!
|
|
99
|
+
else if (!signalled(key)) status = 'no-signal';
|
|
73
100
|
else if (done[key] || (fromRecords && fromRecords[key])) status = 'done';
|
|
74
101
|
else status = 'pending';
|
|
75
102
|
if (status === 'pending' && !currentSet) { status = 'current'; currentSet = true; }
|
|
76
|
-
|
|
103
|
+
const entry = { key, label: LABELS[key], status, accepted: key === 'evaluate' ? accepted : undefined };
|
|
104
|
+
if (MILESTONES.has(key)) entry.milestone = true;
|
|
105
|
+
out.push(entry);
|
|
77
106
|
}
|
|
78
107
|
return out;
|
|
79
108
|
}
|
|
80
109
|
|
|
81
|
-
module.exports = { STAGES, LABELS, LANE_STAGES, nineStages };
|
|
110
|
+
module.exports = { STAGES, LABELS, OUTPUTS, MILESTONES, LEGACY, LANE_STAGES, stageKey, nineStages, lifecycleStages: nineStages };
|
|
@@ -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 };
|