create-pmos 0.610.0 → 0.612.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 +135 -27
- 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/board-columns-test.js +2 -1
- package/workspace/board-deliveries-test.js +2 -1
- package/workspace/board-programs-test.js +7 -3
- package/workspace/board-publish-ui-test.js +2 -1
- package/workspace/board-shared-ui-test.js +2 -1
- package/workspace/board-workflows-test.js +2 -1
- package/workspace/briefing-premium-board-test.js +3 -2
- package/workspace/briefing-premium-calendar-2-test.js +3 -2
- package/workspace/briefing-premium-calendar-3-test.js +1 -1
- package/workspace/briefing-premium-calendar-test.js +1 -1
- package/workspace/briefing-premium-doc-edit-test.js +2 -1
- package/workspace/briefing-premium-insights-test.js +4 -3
- package/workspace/briefing-premium-test.js +3 -2
- package/workspace/calm-timeline-test.js +2 -1
- package/workspace/changelog.json +134 -0
- package/workspace/core-docs-workflow-test.js +2 -1
- package/workspace/ev-everywhere-test.js +3 -2
- package/workspace/guide/home.md +2 -2
- package/workspace/guide/index.md +4 -0
- package/workspace/guide/layout.md +97 -3
- package/workspace/guide/programs.md +16 -2
- package/workspace/guide/routine.md +65 -0
- package/workspace/guide/scheduled-tasks-and-cli.md +1 -1
- package/workspace/guide/settings-and-switches.md +2 -2
- package/workspace/impact-screens-test.js +3 -1
- package/workspace/ini-workflow-test.js +2 -1
- package/workspace/lib/board-premium.js +12 -4
- package/workspace/lib/classic-board.js +15 -0
- package/workspace/lib/cos-chat.js +1 -0
- package/workspace/lib/doc-library.js +43 -12
- package/workspace/lib/doc-path.js +30 -0
- package/workspace/lib/engine/boards.js +4 -2
- package/workspace/lib/events-place.js +368 -0
- package/workspace/lib/events-stated.js +129 -0
- package/workspace/lib/initiative-chat.js +1 -0
- package/workspace/lib/insights-premium.js +13 -1
- package/workspace/lib/library-find.js +162 -0
- package/workspace/lib/library-items.js +250 -0
- package/workspace/lib/notes.js +9 -1
- package/workspace/lib/plan-items.js +17 -3
- package/workspace/lib/route-modules.js +4 -0
- package/workspace/lib/routes-artefacts.js +5 -2
- package/workspace/lib/routes-boards.js +6 -2
- package/workspace/lib/routes-doc-sheet.js +1 -0
- package/workspace/lib/routes-events-place.js +203 -0
- package/workspace/lib/routes-library.js +155 -0
- package/workspace/lib/routes-pop-work.js +39 -0
- package/workspace/lib/routes-report-setups.js +32 -1
- package/workspace/lib/routes-today-log.js +48 -0
- package/workspace/lib/routine-reports.js +84 -0
- package/workspace/lib/status-when.js +36 -0
- package/workspace/lib/task-items.js +5 -3
- package/workspace/lib/today-log.js +131 -0
- package/workspace/live-pill-round-test.js +10 -7
- package/workspace/metric-drafts-ui-test.js +3 -1
- package/workspace/milestone-pins-test.js +2 -1
- package/workspace/milestone-suggest-test.js +3 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/panels-test.js +2 -1
- package/workspace/premium-board-actions-test.js +3 -1
- package/workspace/premium-rec-tab-test.js +2 -1
- package/workspace/premium-vw-backlog-test.js +3 -1
- package/workspace/premium-vw-item-test.js +3 -1
- package/workspace/premium-vw-jira-test.js +3 -1
- package/workspace/premium-vw-meet-test.js +2 -1
- package/workspace/premium-vw-notes-test.js +3 -2
- package/workspace/product-lane-test.js +2 -1
- package/workspace/program-charter-test.js +3 -1
- package/workspace/program-leave-test.js +2 -1
- package/workspace/program-order-test.js +2 -1
- package/workspace/program-panel-test.js +3 -1
- package/workspace/public/pm/artefact-kind.js +87 -0
- package/workspace/public/pm/bd-ini-panel.js +77 -12
- package/workspace/public/pm/bd-prog-panel.js +55 -8
- package/workspace/public/pm/bd-span.js +5 -0
- package/workspace/public/pm/bd-work.css +192 -0
- package/workspace/public/pm/bd-work.js +483 -0
- package/workspace/public/pm/cozy-bar.css +11 -0
- package/workspace/public/pm/cozy-bar.js +99 -0
- package/workspace/public/pm/cozy-day-pick.css +27 -0
- package/workspace/public/pm/cozy-day-pick.js +97 -0
- package/workspace/public/pm/cozy-ev.css +2 -5
- package/workspace/public/pm/cozy-events-view.js +274 -0
- package/workspace/public/pm/cozy-events.css +179 -0
- package/workspace/public/pm/cozy-events.js +278 -0
- package/workspace/public/pm/cozy-evmodel.js +1 -1
- package/workspace/public/pm/cozy-goals.css +172 -0
- package/workspace/public/pm/cozy-library.css +125 -0
- package/workspace/public/pm/cozy-live-pill.js +1 -0
- package/workspace/public/pm/cozy-nav.js +6 -7
- package/workspace/public/pm/cozy-pick.css +3 -0
- package/workspace/public/pm/cozy-pop-work.css +224 -0
- package/workspace/public/pm/cozy-pop-work.js +668 -0
- package/workspace/public/pm/cozy-popup.css +11 -2
- package/workspace/public/pm/cozy-popup.js +67 -9
- package/workspace/public/pm/cozy-routine-job.js +203 -0
- package/workspace/public/pm/cozy-routine-model.js +219 -0
- package/workspace/public/pm/cozy-routine-pop.js +318 -0
- package/workspace/public/pm/cozy-routine.css +155 -0
- package/workspace/public/pm/cozy-routine.js +335 -0
- package/workspace/public/pm/cozy-schedwork.js +6 -5
- package/workspace/public/pm/cozy-settings.js +1 -5
- package/workspace/public/pm/cozy-status-when.js +48 -0
- package/workspace/public/pm/cozy-today-app.js +236 -0
- package/workspace/public/pm/cozy-today-model.js +176 -0
- package/workspace/public/pm/cozy-today-page.css +100 -0
- package/workspace/public/pm/cozy-today-view.js +76 -0
- package/workspace/public/pm/cozy-viewer.js +19 -8
- package/workspace/public/pm/cozy-vw-mtg.css +39 -0
- package/workspace/public/pm/goals-model.js +205 -0
- package/workspace/public/pm/goals-open.js +124 -0
- package/workspace/public/pm/home-app.js +18 -3
- package/workspace/public/pm/home-chat.js +4 -2
- package/workspace/public/pm/home-ini.js +43 -10
- package/workspace/public/pm/ini-edit.js +3 -1
- package/workspace/public/pm/ini-view-model.js +1 -1
- package/workspace/public/pm/library-model.js +197 -0
- package/workspace/public/pm/library-open.js +37 -0
- package/workspace/public/pm/page-chat.js +12 -2
- package/workspace/public/pm/pop-work-model.js +493 -0
- package/workspace/public/pm/premium-board.js +204 -17
- package/workspace/public/pm/premium-goals.js +213 -0
- package/workspace/public/pm/premium-library.js +436 -0
- package/workspace/public/pm/premium-shell.js +1 -1
- package/workspace/public/pm/premium-vw-mtg.js +79 -1
- package/workspace/public/pm/scope-chip.js +204 -0
- package/workspace/public/premium-board.html +1 -0
- package/workspace/public/premium-events.html +44 -0
- package/workspace/public/premium-goals.html +37 -0
- package/workspace/public/premium-library.html +39 -0
- package/workspace/public/premium-routine.html +33 -0
- package/workspace/public/today.html +50 -0
- package/workspace/ready-dash-ui-test.js +3 -1
- package/workspace/rename-test.js +2 -1
- package/workspace/run-tests.js +4 -1
- package/workspace/server.js +4 -2
- package/workspace/sort-order-test.js +2 -1
- package/workspace/split-merge-ui-test.js +3 -1
- package/workspace/stage-card-tasks-test.js +3 -1
- package/workspace/stage-card-test.js +2 -1
- package/workspace/task-delete-test.js +2 -1
- package/workspace/task-links-test.js +2 -1
- package/workspace/task-milestones-test.js +4 -2
- package/workspace/task-plans-test.js +3 -1
- package/workspace/task-press-test.js +3 -1
- package/workspace/task-views-test.js +3 -1
- package/workspace/test-lists/doc-path.json +9 -0
- package/workspace/test-lists/events-place.json +11 -0
- package/workspace/test-lists/goals-place.json +9 -0
- package/workspace/test-lists/library-place.json +9 -0
- package/workspace/test-lists/pop-work.json +9 -0
- package/workspace/test-lists/routine-place.json +9 -0
- package/workspace/test-lists/status-when.json +9 -0
- package/workspace/test-lists/today-log.json +9 -0
- package/workspace/test-lists/work-view.json +9 -0
- package/workspace/timeline-holds-test.js +3 -1
- package/workspace/tk-tasks-test.js +2 -1
|
@@ -33,6 +33,7 @@ const path = require('path');
|
|
|
33
33
|
const crypto = require('crypto');
|
|
34
34
|
const { createSinkGuard } = require('./sink.js');
|
|
35
35
|
const planTree = require('./plan-tree.js');
|
|
36
|
+
const statusWhen = require('./status-when.js'); // the day a move really happened (popup round 3 point 18)
|
|
36
37
|
const consoleState = require('./console-state');
|
|
37
38
|
const actorLib = require('./actor.js');
|
|
38
39
|
|
|
@@ -212,6 +213,7 @@ function lineErr(r) {
|
|
|
212
213
|
if (!STATES.includes(r.to)) return 'to is not todo, doing, review or done';
|
|
213
214
|
if (r.evidence !== undefined && evidenceErr(r.evidence)) return evidenceErr(r.evidence);
|
|
214
215
|
if (r.override !== undefined && r.override !== true) return 'override is written only as true';
|
|
216
|
+
if (r.happened !== undefined && !/^\d{4}-\d{2}-\d{2}$/.test(String(r.happened))) return 'happened is a day, YYYY-MM-DD';
|
|
215
217
|
// The writer computes override for a pm: actor only, so an agent line that carries it was not written by the writer.
|
|
216
218
|
if (r.override !== undefined && !String(r.by).startsWith('pm:')) return 'override is written only on a pm: line';
|
|
217
219
|
return null;
|
|
@@ -278,11 +280,17 @@ function historyOf(rec) {
|
|
|
278
280
|
const h = { eid: rec.eid, ev: rec.ev, by: rec.by, via: rec.via, at: rec.at };
|
|
279
281
|
if (rec.ev === 'planned') h.stage = rec.stage;
|
|
280
282
|
if (rec.ev === 'set') h.fields = { ...rec.fields };
|
|
281
|
-
if (rec.ev === 'moved') { h.to = rec.to; if (rec.evidence) h.evidence = { ...rec.evidence }; if (rec.override) h.override = true; }
|
|
283
|
+
if (rec.ev === 'moved') { h.to = rec.to; if (rec.evidence) h.evidence = { ...rec.evidence }; if (rec.override) h.override = true; if (rec.happened) h.happened = rec.happened; }
|
|
282
284
|
if (rec.ev === 'flagged') { h.blocked = rec.blocked; if (rec.blocked) h.reason = rec.reason; }
|
|
283
285
|
if (rec.ev === 'withdrawn' && rec.why) h.why = rec.why;
|
|
284
286
|
return h;
|
|
285
287
|
}
|
|
288
|
+
/** The day of an item's last move, its real day first (round 3 point 18), else the day it was made: read from its history, so the
|
|
289
|
+
* item's own shape (the plan API's layout) does not change. */
|
|
290
|
+
function sinceOf(it) {
|
|
291
|
+
const m = (it.history || []).filter((h) => h.ev === 'moved').pop();
|
|
292
|
+
return m ? m.happened || String(m.at || '').slice(0, 10) : String(it.createdAt || '').slice(0, 10) || null;
|
|
293
|
+
}
|
|
286
294
|
const touch = (it, rec) => { it.updatedBy = rec.by; it.updatedVia = rec.via; it.updatedAt = rec.at; it.history.push(historyOf(rec)); };
|
|
287
295
|
|
|
288
296
|
/** A mutable fold state, so the writer can apply the events of one call to a working copy as it checks them. */
|
|
@@ -549,7 +557,7 @@ function buildRecord(ctx, ev, index) {
|
|
|
549
557
|
const allowed = {
|
|
550
558
|
planned: ['ev', 'initiative', 'title', 'stage', 'order', 'owner', 'after', 'start', 'due', 'milestone', 'note'],
|
|
551
559
|
set: ['ev', 'item', 'initiative', 'fields'],
|
|
552
|
-
moved: ['ev', 'item', 'initiative', 'to', 'evidence'],
|
|
560
|
+
moved: ['ev', 'item', 'initiative', 'to', 'evidence', 'happened'],
|
|
553
561
|
flagged: ['ev', 'item', 'initiative', 'blocked', 'reason'],
|
|
554
562
|
withdrawn: ['ev', 'item', 'initiative', 'why'],
|
|
555
563
|
restored: ['ev', 'item', 'initiative'],
|
|
@@ -673,9 +681,15 @@ function buildRecord(ctx, ev, index) {
|
|
|
673
681
|
if (e) return refuse(400, e, index);
|
|
674
682
|
evidence = { kind: evidence.kind, ref: evidence.ref };
|
|
675
683
|
}
|
|
684
|
+
// happened: the day the move really happened, when the person says it was earlier than now (lib/status-when.js)
|
|
685
|
+
if (ev.happened !== undefined && ev.happened !== null) {
|
|
686
|
+
const e = statusWhen.checkHappened(ev.happened, { floor: sinceOf(it) });
|
|
687
|
+
if (e) return refuse(400, e, index);
|
|
688
|
+
}
|
|
676
689
|
const rec = common(init, it.id, it.updatedAt);
|
|
677
690
|
rec.to = ev.to;
|
|
678
691
|
if (evidence) rec.evidence = evidence;
|
|
692
|
+
if (ev.happened != null) rec.happened = ev.happened;
|
|
679
693
|
// override: the PM moved an item the agent owns. Computed here, never accepted from a caller. Attaching
|
|
680
694
|
// evidence is not a move, so it is never an override.
|
|
681
695
|
if (actor.by.startsWith('pm:') && it.owner === 'agent' && !attach) rec.override = true;
|
|
@@ -938,6 +952,6 @@ function handoffPrompt(item, initiativeId, stageLabel) {
|
|
|
938
952
|
module.exports = {
|
|
939
953
|
LEDGER, EVENTS, STATES, PM_SLUG, ID_RE, INIT_RE, SESSION_RE,
|
|
940
954
|
ledgerRoot, ledgerPath, newItemId, newEventId, initiativeOf,
|
|
941
|
-
readLines, parseText, fold, readFold, readFoldShared, progressOf, progressLabel, lineErr,
|
|
955
|
+
readLines, parseText, fold, readFold, readFoldShared, progressOf, progressLabel, lineErr, sinceOf,
|
|
942
956
|
actorFromCli, appendFromUi, appendFromCli, needsFor, ledgerSigs, readLayout, handoffPrompt, parseEvidence,
|
|
943
957
|
};
|
|
@@ -45,11 +45,13 @@ const MODULES = Object.freeze([
|
|
|
45
45
|
'routes-my-work', // initiative my-work: the ranked list of work assigned to the PM, the brief, Read again
|
|
46
46
|
'routes-intake', // planning-flows run 4: one-line intake draft (drafts only)
|
|
47
47
|
'routes-pm-items', // planning-flows runs 1-2: the PM's own items and jobs to be done (add, edit, remove, undo)
|
|
48
|
+
'routes-today-log', // six-place navigation slice 5: Today's log, the PM's own entries and marks (today-log/log.jsonl; page-press POST)
|
|
48
49
|
'routes-runs', // console3 agent surfaces: runs grouped for the sessions panel, PM answers, corrections
|
|
49
50
|
'routes-doc-health', // console3 B2: the six document health checks, recomputed from text
|
|
50
51
|
'routes-outbox', // console3 B3: the outbox queue, hash-bound confirm (no channel connected)
|
|
51
52
|
'routes-waiting', // home-your-move-waiting: Waiting on others, derived from records, with its exit rule
|
|
52
53
|
'routes-calendar-views', // console3 C2: Day/Week/Month/Quarter/Year cells, Gantt and the strategy lens (read-only)
|
|
54
|
+
'routes-events-place', // events-place (nav slice 6): every date PMOS holds, grouped Late / Today / Coming up, and the PM's fixed marks and noes (events/marks.jsonl; page-press POST)
|
|
53
55
|
'routes-briefing', // console3 C1: the day-part Briefing cards from the signal engine (read-only)
|
|
54
56
|
'routes-briefing-premium', // briefing-premium: the premium Briefing's page model from repository state (read-only)
|
|
55
57
|
'routes-my-work-premium', // briefing-premium-work: the premium My work page's model from the Work page's own list (read-only)
|
|
@@ -110,7 +112,9 @@ const MODULES = Object.freeze([
|
|
|
110
112
|
'routes-report-setups', // report-workspace: recurring reports, the Ask box, the finder, the report documents and their export (report-setups.jsonl)
|
|
111
113
|
'routes-artefacts', // R18 (D107): the seven artefacts, read-only, and the lossless carry of the older records (artefacts.jsonl)
|
|
112
114
|
'routes-core-docs', // core-documents: the core documents of each level, Draft it (a core-doc run), Issue it and Drop (core-docs.jsonl)
|
|
115
|
+
'routes-pop-work', // popup-work-contents (slice 3): the summary of an initiative changed or confirmed in place (initiative-writer setDescription; page-press POST)
|
|
113
116
|
'routes-custom-docs', // briefing-premium-adddoc: the documents the PM adds beyond the core set, Add a document (custom-docs.jsonl)
|
|
117
|
+
'routes-library', // library-place (slice 7 of the six-place navigation): GET /api/library-items, what was made, every product (read only)
|
|
114
118
|
'routes-premium-dashboards', // briefing-premium-reports: the dashboards the PM makes on premium Insights (premium-dashboards.jsonl; page-press POST save)
|
|
115
119
|
'routes-board-metric-targets', // briefing-premium-metrics option C: the targets of the Board's four measures, set on premium Insights (board-metric-targets.jsonl; page-press POST save)
|
|
116
120
|
'routes-insights-records', // premium-agreed-design: Insights' New goal, steps, dashboards with their charts, Save chart, describe, verdicts, tile targets, Export (insights-records.jsonl, kr-metrics.jsonl)
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
* POST /api/artefacts/set { ws, scope, artefact, field, text } → { ok, line } the PM edits one line from the Viewer (board AwB: "You edit
|
|
23
23
|
* any line"). A page press (pm-guard requirePagePress); the actor is the PM, so Claude asks before it
|
|
24
24
|
* changes that line again (lib/artefacts.js pmEdited, lib/driver-decide.js autoApply).
|
|
25
|
+
* POST /api/artefacts/undo { ws, ref } → { ok, line } the Undo of that edit (the popup's Overview, nav slice 3 round 3): the PM's set line
|
|
26
|
+
* `ref` no longer counts. The same page press and PM-only rule as set; the mirror follows it.
|
|
25
27
|
*
|
|
26
28
|
* THE MIGRATION. Every read of a repository carries its older records (core documents, kept driver proposals,
|
|
27
29
|
* report drafts) under their artefacts: lib/artefacts.js migrateRepo. It is idempotent and only appends pointers; nothing is deleted or
|
|
@@ -43,7 +45,7 @@ const pageBy = (x) => (x && x.by ? { ...x, by: actorLib.pageName(x.by) } : x);
|
|
|
43
45
|
async function handle(req, res, url, ctx) {
|
|
44
46
|
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
45
47
|
const sub = url.pathname.replace(/^\/api\/artefacts\/?/, '');
|
|
46
|
-
if (sub === 'set' && req.method === 'POST') {
|
|
48
|
+
if ((sub === 'set' || sub === 'undo') && req.method === 'POST') {
|
|
47
49
|
const read = await ctx.readJson(req);
|
|
48
50
|
if (!read.ok) return send(400, { ok: false, error: 'the body is not JSON' });
|
|
49
51
|
const b = read.body || {};
|
|
@@ -54,7 +56,8 @@ async function handle(req, res, url, ctx) {
|
|
|
54
56
|
if (!w || !w.root) return send(404, { ok: false, error: 'no such workspace' });
|
|
55
57
|
let dir;
|
|
56
58
|
try { dir = A.dirOf(w.root); } catch (e) { return send(409, { ok: false, error: String((e && e.message) || e) }); }
|
|
57
|
-
const r = A.
|
|
59
|
+
const r = sub === 'undo' ? A.undo(A.file(dir), { ref: b.ref }, g.actor)
|
|
60
|
+
: A.set(A.file(dir), { scope: b.scope, artefact: b.artefact, field: b.field, text: typeof b.text === 'string' ? b.text : '' }, g.actor);
|
|
58
61
|
if (!r.ok) return send(r.status, { ok: false, error: r.error });
|
|
59
62
|
// a done test or kill condition lands on the record too, so the gates count it (launch simulation W6, lib/artefact-mirror.js)
|
|
60
63
|
const mirror = require('./artefact-mirror.js').after(w.root, r.line, A.file(dir));
|
|
@@ -99,6 +99,7 @@ const B = require(repoScript('boards.js'));
|
|
|
99
99
|
const WF = require(repoScript('workflows.js'));
|
|
100
100
|
const WS = require('./workflows-store.js');
|
|
101
101
|
const TI = require('./task-items.js');
|
|
102
|
+
const SW = require('./status-when.js');
|
|
102
103
|
const TS = require('./task-store.js');
|
|
103
104
|
const holdSpans = require('./hold-spans.js');
|
|
104
105
|
const ledgers = require('./plan-ledgers.js');
|
|
@@ -1466,12 +1467,15 @@ const WRITES = {
|
|
|
1466
1467
|
if (!state) return fail(ctx, res, 400, `state is one of ${B.TASK_STATES.join(', ')}`);
|
|
1467
1468
|
const it = itemOnBoard(ctx, res, p, body.task);
|
|
1468
1469
|
if (!it) return;
|
|
1469
|
-
return itemWrite(ctx, res, p, it, TI.stateEvents(it, state, body.why), g);
|
|
1470
|
+
return itemWrite(ctx, res, p, it, TI.stateEvents(it, state, body.why, body.happened || null), g);
|
|
1470
1471
|
}
|
|
1471
1472
|
if (!t || t.board !== p.board.id) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
|
|
1472
1473
|
if (!state) return fail(ctx, res, 400, `state is one of ${B.TASK_STATES.join(', ')}`);
|
|
1474
|
+
// happened: the day the move really happened (round 3 point 18), never in the future and never before the previous move
|
|
1475
|
+
const happened = body.happened == null || body.happened === '' ? null : body.happened;
|
|
1476
|
+
if (happened) { const e = SW.checkHappened(happened, { floor: SW.floorOf(t) }); if (e) return fail(ctx, res, 400, e); }
|
|
1473
1477
|
if (!p.file) return fail(ctx, res, 409, NO_STATE);
|
|
1474
|
-
append(p.file, g.actor, { kind: 'task-update', board: p.board.id, task: t.id, state, why: typeof body.why === 'string' && body.why.trim() ? body.why.trim().slice(0, 300) : 'status move' });
|
|
1478
|
+
append(p.file, g.actor, { kind: 'task-update', board: p.board.id, task: t.id, state, why: typeof body.why === 'string' && body.why.trim() ? body.why.trim().slice(0, 300) : 'status move', ...(happened ? { happened } : {}) });
|
|
1475
1479
|
const t2 = B.taskOf(B.fold(readLedger(ctx, p.w)), t.id);
|
|
1476
1480
|
ctx.json(res, { ok: true, item: B.rollupItems([B.taskItem(t2)])[0] });
|
|
1477
1481
|
},
|
|
@@ -62,6 +62,7 @@ function inside(root, full) {
|
|
|
62
62
|
// The same guard /api/doc/save uses: resolve under the root, markdown only, refuse anything outside.
|
|
63
63
|
function resolveDoc(root, rel) {
|
|
64
64
|
if (typeof rel !== 'string' || !rel.trim() || rel.includes('\0')) return { error: fail(400, 'path is required') };
|
|
65
|
+
rel = require('./doc-path.js').resolve(root, rel); // the same resolver as GET /api/doc: with or without the kit's "pmos/"
|
|
65
66
|
const full = path.resolve(root, rel);
|
|
66
67
|
if (!full.startsWith(path.resolve(root) + path.sep) || !inside(root, path.dirname(full))) return { error: fail(404, 'outside workspace') };
|
|
67
68
|
if (!/\.md$/i.test(full)) return { error: fail(400, 'only markdown documents are editable here') };
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-events-place.js — the Events place (slice 6 of the six-place navigation, initiative events-place).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/events-place → 200 { ok, state: 'ready', today, items, later, missing } | 202 { ok, state: 'reading' }
|
|
5
|
+
* every date PMOS holds, as lib/events-place.js build() makes it: each product's Board model (GET /api/board-premium, the route the
|
|
6
|
+
* Board reads: milestones, plan ends, tasks, forecasts), the calendar (lib/calendar-events.js), the report schedules and the drafts
|
|
7
|
+
* that wait (lib/report-needs.js), and the PM's own items (lib/pm-items.js). While a Board is still being read the answer is 202 and
|
|
8
|
+
* the page asks again. A source that cannot be read is named in `missing`, never read as nothing.
|
|
9
|
+
* Round 2 (events-round2.md) adds the Jira tickets assigned to the PM (<runtime>/my-work/read.json), the program milestones
|
|
10
|
+
* (lib/routes-programs.js all), the dates people state in the sources (lib/events-stated.js over lib/source-reads.js), the link the PM
|
|
11
|
+
* set on a meeting (lib/calendar-links.js, as Today reads it), `filters` (the products, programs and projects with a date) and
|
|
12
|
+
* `unread`: { meeting?: 'calendar not connected', deadline?: 'no source read yet' }, a type whose source PMOS does not read.
|
|
13
|
+
* POST /api/events-place/mark { key, fixed } → { ok } a date is fixed (true) or not (false): Events never offers it a new date
|
|
14
|
+
* POST /api/events-place/mark { sig, no } → { ok } the PM said no to a suggestion (no: true), or took the no back (no: false)
|
|
15
|
+
* POST /api/events-place/mark { key, gone } → { ok } a date PMOS cannot write is met ('met') or dropped ('dropped'): Events stops listing
|
|
16
|
+
* it; gone: false lists it again (Undo)
|
|
17
|
+
*
|
|
18
|
+
* STATE. <runtime>/events/marks.jsonl, append-only, one line per press: { at, by, kind: fixed | unfixed | no | unno | met | dropped | back, key | sig }. The fold
|
|
19
|
+
* keeps the last line of each key or sig. Writes pass pm-guard requirePagePress: the page only. Every other write of Events (✓ on a
|
|
20
|
+
* suggestion, a new day, +) goes through the routes that already make it: /api/boards/tasks/state, /api/boards/tasks/edit, /api/pm-items/*. */
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
const path = require('path');
|
|
23
|
+
const EP = require('./events-place.js');
|
|
24
|
+
|
|
25
|
+
const MAX_LEN = 400;
|
|
26
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
27
|
+
const localDay = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
28
|
+
const reason = (e) => String((e && e.message) || e).slice(0, 160);
|
|
29
|
+
|
|
30
|
+
/* ── the marks ── */
|
|
31
|
+
const marksFile = (runtimeDir) => path.join(runtimeDir, 'events', 'marks.jsonl');
|
|
32
|
+
/** The marks folded: { fixed: Set<key>, declined: Set<sig>, gone: Map<key, 'met' | 'dropped'> }. PURE over the lines. */
|
|
33
|
+
function foldMarks(lines) {
|
|
34
|
+
const fixed = new Map(), no = new Map(), gone = new Map();
|
|
35
|
+
for (const l of lines || []) {
|
|
36
|
+
if (!l || typeof l !== 'object') continue;
|
|
37
|
+
if ((l.kind === 'fixed' || l.kind === 'unfixed') && typeof l.key === 'string') fixed.set(l.key, l.kind === 'fixed');
|
|
38
|
+
if ((l.kind === 'no' || l.kind === 'unno') && typeof l.sig === 'string') no.set(l.sig, l.kind === 'no');
|
|
39
|
+
if ((l.kind === 'met' || l.kind === 'dropped') && typeof l.key === 'string') gone.set(l.key, l.kind);
|
|
40
|
+
if (l.kind === 'back' && typeof l.key === 'string') gone.delete(l.key);
|
|
41
|
+
}
|
|
42
|
+
return { gone, fixed: new Set([...fixed].filter(([, v]) => v).map(([k]) => k)), declined: new Set([...no].filter(([, v]) => v).map(([k]) => k)) };
|
|
43
|
+
}
|
|
44
|
+
function readMarks(runtimeDir) {
|
|
45
|
+
let text = '';
|
|
46
|
+
try { text = fs.readFileSync(marksFile(runtimeDir), 'utf8'); } catch { return foldMarks([]); }
|
|
47
|
+
return foldMarks(text.split('\n').filter(Boolean).map((s) => { try { return JSON.parse(s); } catch { return null; } }));
|
|
48
|
+
}
|
|
49
|
+
/** One mark line from a page press body, or { error }. PURE. */
|
|
50
|
+
function markLine(body, by, at) {
|
|
51
|
+
const b = body && typeof body === 'object' && !Array.isArray(body) ? body : {};
|
|
52
|
+
const okStr = (s) => typeof s === 'string' && s.length > 0 && s.length <= MAX_LEN;
|
|
53
|
+
if (okStr(b.key) && typeof b.fixed === 'boolean') return { at, by, kind: b.fixed ? 'fixed' : 'unfixed', key: b.key };
|
|
54
|
+
if (okStr(b.sig) && typeof b.no === 'boolean') return { at, by, kind: b.no ? 'no' : 'unno', sig: b.sig };
|
|
55
|
+
if (okStr(b.key) && (b.gone === 'met' || b.gone === 'dropped' || b.gone === false)) return { at, by, kind: b.gone || 'back', key: b.key };
|
|
56
|
+
return { error: "send { key, fixed: true | false }, { sig, no: true | false } or { key, gone: 'met' | 'dropped' | false }" };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* ── the readers ── */
|
|
60
|
+
async function via(mod, pathAndQuery, req, ctx) {
|
|
61
|
+
let out = { status: 500, body: null };
|
|
62
|
+
const c = Object.assign({}, ctx, { json: (res, obj, code) => { out = { status: code || 200, body: obj }; } });
|
|
63
|
+
const handled = await mod.handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, new URL('http://local' + pathAndQuery), c);
|
|
64
|
+
return handled === false ? { status: 404, body: null } : out;
|
|
65
|
+
}
|
|
66
|
+
/** Every product's Board model, the way the Board's All products reads them: { state: 'reading' } | { boards, missing }. */
|
|
67
|
+
async function readBoards(req, ctx) {
|
|
68
|
+
const BPR = require('./routes-board-premium.js');
|
|
69
|
+
const first = await via(BPR, '/api/board-premium', req, ctx);
|
|
70
|
+
if (first.status === 202 || (first.body && first.body.state === 'reading')) return { state: 'reading' };
|
|
71
|
+
if (!first.body || !first.body.ok || !first.body.model) return { boards: [], missing: ['the boards'] };
|
|
72
|
+
const home = first.body.model;
|
|
73
|
+
const nameOf = (m) => (m.board && (m.board.product || m.board.name)) || '';
|
|
74
|
+
const rowsOf = (m) => (m.initiatives && m.initiatives.list && m.initiatives.list.rows) || [];
|
|
75
|
+
const boards = [{ ws: home.board.ws || '', id: home.board.id || '', name: nameOf(home), rows: rowsOf(home) }];
|
|
76
|
+
const missing = [];
|
|
77
|
+
const others = (home.board.switcher || []).filter((b) => !(b.ws === home.board.ws && b.id === home.board.id));
|
|
78
|
+
const q = (b) => '?ws=' + encodeURIComponent(b.ws) + '&board=' + encodeURIComponent(b.id);
|
|
79
|
+
const got = await Promise.all(others.map((b) => via(BPR, '/api/board-premium' + q(b), req, ctx)));
|
|
80
|
+
if (got.some((g) => g.status === 202 || (g.body && g.body.state === 'reading'))) return { state: 'reading' };
|
|
81
|
+
got.forEach((g, i) => {
|
|
82
|
+
if (g.body && g.body.ok && g.body.model) boards.push({ ws: others[i].ws, id: others[i].id, name: nameOf(g.body.model) || others[i].name, rows: rowsOf(g.body.model) });
|
|
83
|
+
else missing.push((others[i].name || others[i].ws) + ' board');
|
|
84
|
+
});
|
|
85
|
+
return { boards, missing };
|
|
86
|
+
}
|
|
87
|
+
/** The enabled report schedules, each with the local day it fires next. */
|
|
88
|
+
function readSchedules(now) {
|
|
89
|
+
const RN = require('./report-needs.js');
|
|
90
|
+
const logic = require('./schedule-logic.js');
|
|
91
|
+
const out = [];
|
|
92
|
+
for (const s of RN.readSchedules()) {
|
|
93
|
+
if (!s || !s.enabled) continue;
|
|
94
|
+
const cadence = RN.cadenceOfSchedule(s);
|
|
95
|
+
if (!cadence) continue;
|
|
96
|
+
const next = logic.nextRun(s, now);
|
|
97
|
+
if (!next) continue;
|
|
98
|
+
out.push({ id: String(s.id || s.name || cadence), name: s.name || '', cadence, next: localDay(new Date(next)) });
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
/** The newest report of each cadence when it is a draft not issued: a draft that waits for the PM. */
|
|
103
|
+
function readDrafts(roots) {
|
|
104
|
+
const RN = require('./report-needs.js');
|
|
105
|
+
const out = [];
|
|
106
|
+
for (const { ws, root } of roots) {
|
|
107
|
+
const seen = new Set();
|
|
108
|
+
for (const r of RN.reportsOf(root).reports) { // newest slot first
|
|
109
|
+
if (/^scan-/.test(r.cadence) || seen.has(r.cadence)) continue;
|
|
110
|
+
seen.add(r.cadence);
|
|
111
|
+
if (r.status === 'draft' && !r.issued) { const fm = RN.frontmatter(path.join(root, r.path)); out.push({ ws, cadence: r.cadence, slot: r.slot, ...(fm.title ? { title: fm.title } : {}) }); }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
/** The Jira tickets assigned to the PM, as the last my-work read holds them. */
|
|
117
|
+
function readJira(runtimeDir) {
|
|
118
|
+
try { const r = JSON.parse(fs.readFileSync(path.join(runtimeDir, 'my-work', 'read.json'), 'utf8')); return r && Array.isArray(r.items) ? r.items.filter((x) => x && x.key) : []; } catch { return []; }
|
|
119
|
+
}
|
|
120
|
+
/** The calendar's meetings with the link the PM set on each (lib/calendar-links.js wins over the brief's guess, as on Today). */
|
|
121
|
+
function readMeetings(runtimeDir, now) {
|
|
122
|
+
const events = require('./calendar-events.js').readAll(runtimeDir, { now: now.getTime() });
|
|
123
|
+
let links = null;
|
|
124
|
+
try { const CL = require('./calendar-links.js'); links = CL.read(runtimeDir); for (const e of events) { const l = links.get(CL.keyOf(e)); if (l && l.kind === 'initiative' && l.initiative) e.initiative = l.initiative; } } catch { /* the brief's own link stays */ }
|
|
125
|
+
return events;
|
|
126
|
+
}
|
|
127
|
+
/** Does PMOS read a calendar at all: an import ledger, the remembered calendar, or a meeting in hand? */
|
|
128
|
+
function calendarRead(runtimeDir, meetings) {
|
|
129
|
+
if ((meetings || []).length) return true;
|
|
130
|
+
return ['calendar-import/events.jsonl', 'calendar-memory.json'].some((f) => { try { return fs.statSync(path.join(runtimeDir, f)).size > 0; } catch { return false; } });
|
|
131
|
+
}
|
|
132
|
+
function readOwn(runtimeDir) {
|
|
133
|
+
const P = require('./pm-items.js');
|
|
134
|
+
return P.fold(P.readLines(path.join(runtimeDir, 'pm-items', 'items.jsonl'))).map((o) => ({ id: o.id, title: o.title, due: o.due || null, done: !!o.done }));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The pure handler. deps: { today, readBoards() → { state } | { boards, missing }, readMeetings(), readSchedules(), readDrafts(boards), readOwn(),
|
|
138
|
+
* readMarks() }. A reader that throws names its source in `missing`. */
|
|
139
|
+
async function handle(deps) {
|
|
140
|
+
const b = await deps.readBoards();
|
|
141
|
+
if (b && b.state === 'reading') return { status: 202, body: { ok: true, state: 'reading' } };
|
|
142
|
+
const missing = [...((b && b.missing) || [])];
|
|
143
|
+
const boards = (b && b.boards) || [];
|
|
144
|
+
const tryRead = (name, fn, fallback) => { try { const v = fn(); return v == null ? fallback : v; } catch (e) { missing.push(name + ' (' + reason(e) + ')'); return fallback; } };
|
|
145
|
+
const meetings = tryRead('the calendar', () => deps.readMeetings(), []);
|
|
146
|
+
const schedules = tryRead('the report schedules', () => deps.readSchedules(), []);
|
|
147
|
+
const drafts = tryRead('the report drafts', () => deps.readDrafts(boards), []);
|
|
148
|
+
const own = tryRead('your items', () => deps.readOwn(), []);
|
|
149
|
+
const marks = tryRead('your marks', () => deps.readMarks(), { fixed: new Set(), declined: new Set(), gone: new Map() });
|
|
150
|
+
const jira = deps.readJira ? tryRead('your Jira tickets', () => deps.readJira(), []) : [];
|
|
151
|
+
const programs = deps.readPrograms ? tryRead('the programs', () => deps.readPrograms(), []) : [];
|
|
152
|
+
const reads = deps.readSources ? tryRead('the sources', () => deps.readSources(), {}) : {};
|
|
153
|
+
const stated = require('./events-stated.js').statedDates(reads, { today: deps.today });
|
|
154
|
+
const model = EP.build({ today: deps.today, boards, meetings, schedules, drafts, own, marks, jira, programs, stated });
|
|
155
|
+
// a type whose source PMOS does not read says so in the key, never as an empty tick (round 2, point 2)
|
|
156
|
+
const unread = {};
|
|
157
|
+
if (!(deps.calendarRead ? deps.calendarRead(meetings) : meetings.length)) unread.meeting = 'calendar not connected';
|
|
158
|
+
if (!Object.values(reads || {}).some((r) => r && r.state === 'read')) unread.deadline = 'no source read yet';
|
|
159
|
+
return { status: 200, body: { ok: true, state: 'ready', today: model.today, items: model.items, later: model.later, filters: model.filters, unread, missing } };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
module.exports = {
|
|
163
|
+
foldMarks, markLine, handlePure: handle, readers: { readSchedules, readDrafts, readOwn, readMarks, readJira, readMeetings, calendarRead },
|
|
164
|
+
prefixes: ['/api/events-place'],
|
|
165
|
+
handle: async (req, res, url, ctx) => {
|
|
166
|
+
if (url.pathname === '/api/events-place/mark') {
|
|
167
|
+
if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
|
|
168
|
+
const got = await ctx.readJson(req);
|
|
169
|
+
if (!got.ok) { ctx.json(res, { ok: false, error: 'the body must be JSON' }, 400); return true; }
|
|
170
|
+
const g = require('./pm-guard.js').requirePagePress(req, got.body);
|
|
171
|
+
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
|
|
172
|
+
if (!ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'this server has no runtime folder, so the mark cannot be kept' }, 409); return true; }
|
|
173
|
+
const line = markLine(got.body, g.actor && g.actor.by ? g.actor.by : 'pm', new Date().toISOString());
|
|
174
|
+
if (line.error) { ctx.json(res, { ok: false, error: line.error }, 400); return true; }
|
|
175
|
+
try {
|
|
176
|
+
fs.mkdirSync(path.dirname(marksFile(ctx.runtimeDir)), { recursive: true });
|
|
177
|
+
fs.appendFileSync(marksFile(ctx.runtimeDir), JSON.stringify(line) + '\n');
|
|
178
|
+
} catch (e) { ctx.json(res, { ok: false, error: 'the mark could not be kept: ' + reason(e) }, 500); return true; }
|
|
179
|
+
ctx.json(res, { ok: true });
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
if (url.pathname !== '/api/events-place') return false;
|
|
183
|
+
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
184
|
+
const now = new Date();
|
|
185
|
+
try {
|
|
186
|
+
const out = await handle({
|
|
187
|
+
today: localDay(now),
|
|
188
|
+
readBoards: () => readBoards(req, ctx),
|
|
189
|
+
readMeetings: () => (ctx.runtimeDir ? readMeetings(ctx.runtimeDir, now) : []),
|
|
190
|
+
calendarRead: (m) => (ctx.runtimeDir ? calendarRead(ctx.runtimeDir, m) : false),
|
|
191
|
+
readJira: () => (ctx.runtimeDir ? readJira(ctx.runtimeDir) : []),
|
|
192
|
+
readPrograms: () => require('./routes-programs.js').all(ctx),
|
|
193
|
+
readSources: () => (ctx.runtimeDir ? require('./source-reads.js').all(ctx.runtimeDir) : {}),
|
|
194
|
+
readSchedules: () => readSchedules(now),
|
|
195
|
+
readDrafts: (boards) => readDrafts([...new Set(boards.map((x) => x.ws))].map((ws) => ({ ws, w: ctx.getWs ? ctx.getWs(ws || null) : null })).filter((x) => x.w && x.w.root).map((x) => ({ ws: x.ws, root: x.w.root }))),
|
|
196
|
+
readOwn: () => (ctx.runtimeDir ? readOwn(ctx.runtimeDir) : []),
|
|
197
|
+
readMarks: () => (ctx.runtimeDir ? readMarks(ctx.runtimeDir) : foldMarks([])),
|
|
198
|
+
});
|
|
199
|
+
ctx.json(res, out.body, out.status);
|
|
200
|
+
} catch (e) { ctx.json(res, { ok: false, state: 'error', error: reason(e) }, 500); }
|
|
201
|
+
return true;
|
|
202
|
+
},
|
|
203
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-library.js — GET /api/library-items[?ws=<id>&initiative=<id>] (initiative library-place, slice 7 of the six-place navigation).
|
|
3
|
+
*
|
|
4
|
+
* The Library place reads every product; slice 3's Artefacts table reads one initiative. → { ok, items, programs } (lib/library-items.js ITEM),
|
|
5
|
+
* newest first. READ ONLY: it folds what is already recorded and writes nothing.
|
|
6
|
+
* files lib/doc-library.js library() — the tracked markdown files, attributed to the initiative that owns them (server.js initiativeIndex)
|
|
7
|
+
* links lib/custom-docs.js — the links the PM added to an initiative (Confluence, Google Docs, Google Slides)
|
|
8
|
+
* rounds lib/idle-lab.js roundsOf over lib/proposals.js — the prototype rounds of each initiative
|
|
9
|
+
* notes lib/notes.js list() — the meeting notes of the runtime directory
|
|
10
|
+
* programs lib/routes-programs.js all() — the program each initiative stands in (About is "Program › Initiative"); the answer lists them
|
|
11
|
+
* for the scope chip as { id, title }
|
|
12
|
+
* A source that cannot be read is left out, and the answer says which in `unread` (the page says nothing about it unless every source failed).
|
|
13
|
+
*
|
|
14
|
+
* GET /api/library-items/find?q=<words>[&ws=<id,id>][&rank=1] → { ok, q, ranked, why?, results: [{ id, passage, words? , idea? }] } search by meaning
|
|
15
|
+
* (lib/library-find.js): the items whose text holds the question's words, each with its passage; rank=1 asks one PMOS session to keep
|
|
16
|
+
* the ones about the question, best first, with the idea to show in bold. When it cannot, the word ranking comes back with `why`.
|
|
17
|
+
* GET /api/library-items/peek?ws=<id>&path=<p> → { ok, head: [line], from: [{ path, title }] } the record preview on a wide screen:
|
|
18
|
+
* the file's first lines and the files that link to it (the knowledge graph's links)
|
|
19
|
+
* (/api/library is the old file tree of one workspace, server.js; this route is a different one.) */
|
|
20
|
+
const Items = require('./library-items.js');
|
|
21
|
+
|
|
22
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,119}$/;
|
|
23
|
+
|
|
24
|
+
function titlesOf(w, ctx) {
|
|
25
|
+
const m = new Map();
|
|
26
|
+
try { const b = require('./routes-boards.js').baseRows(w, ctx); if (b && b.ok) for (const r of b.rows || []) if (r && r.id) m.set(r.id, r.title || r.id); } catch { /* none yet */ }
|
|
27
|
+
return m;
|
|
28
|
+
}
|
|
29
|
+
function ownersOf(ctx, root) {
|
|
30
|
+
const own = new Map();
|
|
31
|
+
if (typeof ctx.initiativeIndex !== 'function') return own;
|
|
32
|
+
for (const g of ctx.initiativeIndex(root).initiatives || []) {
|
|
33
|
+
for (const a of g.artifacts || []) { const rel = String(a.path).split(require('path').sep).join('/'); if (!a.shared && !own.has(rel)) own.set(rel, { id: g.id, title: g.title || g.id }); }
|
|
34
|
+
}
|
|
35
|
+
return own;
|
|
36
|
+
}
|
|
37
|
+
function roundsOf(dir) {
|
|
38
|
+
const PR = require('./proposals.js'), LAB = require('./idle-lab.js');
|
|
39
|
+
const P = PR.read(dir), all = [...P.props.values()];
|
|
40
|
+
const inis = [...new Set(all.filter((x) => x.group === 'prototyped' && x.ini).map((x) => x.ini))];
|
|
41
|
+
const out = [];
|
|
42
|
+
for (const ini of inis) {
|
|
43
|
+
const roots = new Map(all.filter((x) => x.group === 'prototyped' && x.ini === ini).map((x) => [x.id, x]));
|
|
44
|
+
for (const r of LAB.roundsOf(P, ini)) {
|
|
45
|
+
const root = roots.get(r.id) || all.find((x) => x.id === r.id) || {};
|
|
46
|
+
const of = (root.data && root.data.of) || r.id;
|
|
47
|
+
const top = roots.get(of) || root;
|
|
48
|
+
const brief = (top.data && top.data.live && top.data.live.brief) || String(top.title || '').replace(/^Round \d+ · [^:]*:\s*/, '');
|
|
49
|
+
const newest = all.filter((x) => x.group === 'improved' && x.ini === ini && x.data && x.data.of === of).reduce((a, x) => (String(x.at) > a ? String(x.at) : a), String(r.at || ''));
|
|
50
|
+
out.push({ id: r.id, ini, board: top.board || '', name: brief || 'Prototype', at: newest || r.at, made: r.rounds || r.made || 0 });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function gather(ctx, list) {
|
|
57
|
+
const unread = [];
|
|
58
|
+
const products = [];
|
|
59
|
+
for (const w of list) {
|
|
60
|
+
const p = { ws: w.id, name: w.label || w.name || w.id, titles: titlesOf(w, ctx), files: [], links: [], rounds: [] };
|
|
61
|
+
try {
|
|
62
|
+
const lib = require('./doc-library.js').library(w.root, { stateDir: ctx.runtimeDir, owners: () => ownersOf(ctx, w.root) });
|
|
63
|
+
if (lib.ok) {
|
|
64
|
+
p.files = lib.files.filter((f) => f.initiative);
|
|
65
|
+
for (const [id, t] of Object.entries(lib.initiatives || {})) if (!p.titles.has(id)) p.titles.set(id, t.title);
|
|
66
|
+
}
|
|
67
|
+
} catch { unread.push({ ws: w.id, source: 'documents' }); }
|
|
68
|
+
try {
|
|
69
|
+
const C = require('./custom-docs.js');
|
|
70
|
+
p.links = C.readLines(C.ledgerFile(w.root)).filter((l) => l.link && C.KINDS.includes(l.link.kind) && typeof l.link.url === 'string' && /^https?:\/\//i.test(l.link.url));
|
|
71
|
+
} catch { unread.push({ ws: w.id, source: 'links' }); }
|
|
72
|
+
try { const dir = ctx.stateDirFor ? ctx.stateDirFor(w) : null; if (dir) p.rounds = roundsOf(dir); } catch { unread.push({ ws: w.id, source: 'prototypes' }); }
|
|
73
|
+
products.push(p);
|
|
74
|
+
}
|
|
75
|
+
let notes = [];
|
|
76
|
+
try { const l = require('./notes.js').list(ctx.runtimeDir); notes = l.ok ? l.notes : []; } catch { unread.push({ ws: null, source: 'meeting notes' }); }
|
|
77
|
+
let programs = [];
|
|
78
|
+
try { programs = require('./routes-programs.js').all(ctx); } catch { programs = []; }
|
|
79
|
+
return { items: Items.build({ products, notes, programs }), unread, programs: programs.map((g) => ({ id: g.id, title: g.title || g.id })) };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The first lines of one listed file (no frontmatter), and the files that link to it. → { ok, head, from } */
|
|
83
|
+
function peek(ctx, w, rel) {
|
|
84
|
+
const lib = require('./doc-library.js').library(w.root, { stateDir: ctx.runtimeDir, owners: () => ownersOf(ctx, w.root) });
|
|
85
|
+
if (!lib.ok) return { ok: false, status: 404, error: lib.error };
|
|
86
|
+
const i = lib.files.findIndex((f) => f.path === rel);
|
|
87
|
+
if (i < 0) return { ok: false, status: 404, error: 'no such file in the Library' };
|
|
88
|
+
let text = '';
|
|
89
|
+
try { text = require('fs').readFileSync(require('path').join(w.root, rel), 'utf8').slice(0, 64 * 1024); } catch { text = ''; }
|
|
90
|
+
const body = text.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, '');
|
|
91
|
+
const head = [];
|
|
92
|
+
for (const l of body.split(/\r?\n/)) {
|
|
93
|
+
if (/^#\s/.test(l)) continue; // the page title repeats the name the preview already shows
|
|
94
|
+
const t = l.replace(/^\s*(?:#+|[-*+>]|\d+[.)])\s*/, '').replace(/\*\*|__|`/g, '').replace(/\[([^\]]*)\]\([^)]*\)/g, '$1').trim();
|
|
95
|
+
if (!t || /^\|?[\s:|-]*-{3,}[\s:|-]*$/.test(t) || /^<!--/.test(t)) continue;
|
|
96
|
+
// a table row reads as one line: "T1 · GET … · Unit test"
|
|
97
|
+
head.push(t.replace(/^\|\s*|\s*\|$/g, '').replace(/\s*\|\s*/g, ' · ').slice(0, 240));
|
|
98
|
+
if (head.length >= 6) break;
|
|
99
|
+
}
|
|
100
|
+
const seen = new Set(), from = [];
|
|
101
|
+
for (const [a, b] of lib.edges) {
|
|
102
|
+
if (b !== i || seen.has(a)) continue;
|
|
103
|
+
seen.add(a);
|
|
104
|
+
const f = lib.files[a];
|
|
105
|
+
from.push({ path: f.path, title: String(f.title || f.path) });
|
|
106
|
+
if (from.length >= 8) break;
|
|
107
|
+
}
|
|
108
|
+
return { ok: true, head, from };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function handle(req, res, url, ctx) {
|
|
112
|
+
const P = url.pathname;
|
|
113
|
+
if (P !== '/api/library-items' && P !== '/api/library-items/find' && P !== '/api/library-items/peek') return false;
|
|
114
|
+
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
115
|
+
let all = [];
|
|
116
|
+
try { all = typeof ctx.workspaceList === 'function' ? ctx.workspaceList() : []; } catch { all = []; }
|
|
117
|
+
if (P === '/api/library-items/peek') {
|
|
118
|
+
const w = all.find((x) => x.id === (url.searchParams.get('ws') || ''));
|
|
119
|
+
const rel = String(url.searchParams.get('path') || '');
|
|
120
|
+
if (!w || !w.root) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
|
|
121
|
+
if (!rel || rel.includes('..') || rel.startsWith('/')) { ctx.json(res, { ok: false, error: 'path names a file of the Library' }, 400); return true; }
|
|
122
|
+
let r; try { r = peek(ctx, w, rel); } catch (e) { r = { ok: false, status: 500, error: 'the file could not be read' }; }
|
|
123
|
+
ctx.json(res, r, r.ok ? 200 : r.status || 400);
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (P === '/api/library-items/find') {
|
|
127
|
+
// search by meaning (round 2, point 7): the shortlist by words; with rank=1, one PMOS session ranks it by meaning
|
|
128
|
+
const q = String(url.searchParams.get('q') || '').slice(0, 300).trim();
|
|
129
|
+
if (!q) { ctx.json(res, { ok: true, q, results: [], ranked: false }); return true; }
|
|
130
|
+
const F = require('./library-find.js');
|
|
131
|
+
// ws=<id,id>: the products the page shows (its product pick), so the shortlist is not spent on products the PM is not looking at
|
|
132
|
+
const only = new Set(String(url.searchParams.get('ws') || '').split(',').map((x) => x.trim()).filter(Boolean));
|
|
133
|
+
const among = only.size ? all.filter((w) => only.has(w.id)) : all;
|
|
134
|
+
const { items } = gather(ctx, among);
|
|
135
|
+
const list = F.shortlist({ roots: among.map((w) => ({ ws: w.id, root: w.root })), items, q });
|
|
136
|
+
if (url.searchParams.get('rank') !== '1') { ctx.json(res, { ok: true, q, ranked: false, results: list.map(({ id, passage, words }) => ({ id, passage, words })) }); return true; }
|
|
137
|
+
const r = await F.rank(ctx, q, list, items);
|
|
138
|
+
if (!r.ok) { ctx.json(res, { ok: true, q, ranked: false, why: r.why, results: list.map(({ id, passage, words }) => ({ id, passage, words })) }); return true; }
|
|
139
|
+
ctx.json(res, { ok: true, q, ranked: true, results: r.results });
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
const ws = url.searchParams.get('ws') || '', ini = url.searchParams.get('initiative') || '';
|
|
143
|
+
if (ini && !ID_RE.test(ini)) { ctx.json(res, { ok: false, error: 'initiative names an initiative' }, 400); return true; }
|
|
144
|
+
let list = all;
|
|
145
|
+
if (ws) {
|
|
146
|
+
const w = list.find((x) => x.id === ws);
|
|
147
|
+
if (!w) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
|
|
148
|
+
list = [w];
|
|
149
|
+
}
|
|
150
|
+
const { items, unread, programs } = gather(ctx, list);
|
|
151
|
+
ctx.json(res, { ok: true, items: Items.narrow(items, { ws: ws || null, initiative: ini || null }), programs, unread });
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = { prefixes: ['/api/library-items'], handle, gather, roundsOf, peek };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-pop-work.js — the summary of an initiative changed or confirmed in place, in the popup (initiative popup-work-contents, slice 3 of
|
|
3
|
+
* the six-place navigation; board 3: "You change a value where you see it: the summary … It saves when you leave, with Undo for a moment").
|
|
4
|
+
*
|
|
5
|
+
* POST /api/initiative/describe { ws, id, text } → { ok, id, from, text, same? } the record's description line
|
|
6
|
+
* POST /api/initiative/describe-undo { ws, id, from, to } → { ok, kept? } back to `from` while the line still says `to`
|
|
7
|
+
*
|
|
8
|
+
* The writer is lib/initiative-writer.js setDescription and restoreDescription, the same as `pmos initiative describe` and the ✓ on PMOS's
|
|
9
|
+
* description ✦ (lib/routes-proposals.js). Both POSTs pass pm-guard requirePagePress: the launch nonce and the page's origin, so an agent
|
|
10
|
+
* session cannot write here. A record the PM edited since the Undo was offered keeps its edit (→ { ok: true, kept: true }). */
|
|
11
|
+
const guard = require('./pm-guard.js');
|
|
12
|
+
const W = require('./initiative-writer.js');
|
|
13
|
+
|
|
14
|
+
const text = (v) => (typeof v === 'string' ? v : '');
|
|
15
|
+
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
16
|
+
|
|
17
|
+
async function handle(req, res, url, ctx) {
|
|
18
|
+
const send = (r) => { ctx.json(res, r.body, r.status); return true; };
|
|
19
|
+
const sub = url.pathname.replace(/^\/api\/initiative\/?/, '');
|
|
20
|
+
if (sub !== 'describe' && sub !== 'describe-undo') return send(bad(404, 'no such route'));
|
|
21
|
+
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
22
|
+
const read = await ctx.readJson(req);
|
|
23
|
+
if (!read.ok || !read.body || typeof read.body !== 'object') return send(bad(400, 'the body must be a JSON object'));
|
|
24
|
+
const body = read.body;
|
|
25
|
+
const g = guard.requirePagePress(req, body);
|
|
26
|
+
if (!g.ok) return send(bad(g.status, g.error));
|
|
27
|
+
const id = text(body.id);
|
|
28
|
+
if (!id || !W.ID_RE.test(id)) return send(bad(400, 'id must name an initiative'));
|
|
29
|
+
const w = ctx.getWs(text(body.ws) || null);
|
|
30
|
+
if (!w || (body.ws && w.id !== body.ws)) return send(bad(404, 'no such workspace'));
|
|
31
|
+
const r = sub === 'describe'
|
|
32
|
+
? W.setDescription(w.root, id, text(body.text), { actor: g.actor })
|
|
33
|
+
: W.restoreDescription(w.root, id, text(body.from), text(body.to), { actor: g.actor });
|
|
34
|
+
if (!r.ok) return send(bad(r.status || 400, r.error || 'nothing was saved'));
|
|
35
|
+
try { if (ctx.invalidateNeedsAgg) ctx.invalidateNeedsAgg(w.id); } catch { /* the next read catches up */ }
|
|
36
|
+
return send({ status: 200, body: sub === 'describe' ? { ok: true, id, from: r.from || '', text: r.text, ...(r.same ? { same: true } : {}) } : { ok: true, ...(r.kept ? { kept: true } : {}) } });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = { prefixes: ['/api/initiative/describe', '/api/initiative/describe-undo'], handle };
|