create-pmos 0.611.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.
Files changed (97) hide show
  1. package/package.json +86 -14
  2. package/payload/KIT-VERSION +2 -2
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/payload/state/log.md +1 -1
  7. package/workspace/briefing-premium-board-test.js +1 -1
  8. package/workspace/briefing-premium-calendar-2-test.js +3 -2
  9. package/workspace/briefing-premium-calendar-3-test.js +1 -1
  10. package/workspace/briefing-premium-calendar-test.js +1 -1
  11. package/workspace/briefing-premium-insights-test.js +1 -1
  12. package/workspace/briefing-premium-test.js +1 -1
  13. package/workspace/changelog.json +85 -0
  14. package/workspace/guide/layout.md +52 -18
  15. package/workspace/guide/programs.md +3 -3
  16. package/workspace/guide/routine.md +28 -13
  17. package/workspace/guide/settings-and-switches.md +1 -1
  18. package/workspace/lib/board-premium.js +12 -4
  19. package/workspace/lib/cos-chat.js +1 -0
  20. package/workspace/lib/doc-library.js +43 -12
  21. package/workspace/lib/doc-path.js +30 -0
  22. package/workspace/lib/engine/boards.js +4 -2
  23. package/workspace/lib/events-place.js +190 -38
  24. package/workspace/lib/events-stated.js +129 -0
  25. package/workspace/lib/initiative-chat.js +1 -0
  26. package/workspace/lib/insights-premium.js +13 -1
  27. package/workspace/lib/library-find.js +162 -0
  28. package/workspace/lib/library-items.js +196 -24
  29. package/workspace/lib/notes.js +3 -0
  30. package/workspace/lib/plan-items.js +17 -3
  31. package/workspace/lib/routes-artefacts.js +5 -2
  32. package/workspace/lib/routes-boards.js +6 -2
  33. package/workspace/lib/routes-doc-sheet.js +1 -0
  34. package/workspace/lib/routes-events-place.js +47 -10
  35. package/workspace/lib/routes-library.js +74 -8
  36. package/workspace/lib/routes-report-setups.js +13 -2
  37. package/workspace/lib/routine-reports.js +36 -4
  38. package/workspace/lib/status-when.js +36 -0
  39. package/workspace/lib/task-items.js +5 -3
  40. package/workspace/package-lock.json +2 -2
  41. package/workspace/package.json +1 -1
  42. package/workspace/premium-vw-meet-test.js +2 -1
  43. package/workspace/premium-vw-notes-test.js +3 -2
  44. package/workspace/public/pm/artefact-kind.js +87 -0
  45. package/workspace/public/pm/bd-ini-panel.js +6 -6
  46. package/workspace/public/pm/bd-span.js +5 -0
  47. package/workspace/public/pm/bd-work.css +62 -0
  48. package/workspace/public/pm/bd-work.js +195 -68
  49. package/workspace/public/pm/cozy-bar.css +11 -0
  50. package/workspace/public/pm/cozy-bar.js +99 -0
  51. package/workspace/public/pm/cozy-day-pick.css +27 -0
  52. package/workspace/public/pm/cozy-day-pick.js +97 -0
  53. package/workspace/public/pm/cozy-ev.css +0 -4
  54. package/workspace/public/pm/cozy-events-view.js +165 -33
  55. package/workspace/public/pm/cozy-events.css +75 -3
  56. package/workspace/public/pm/cozy-events.js +86 -18
  57. package/workspace/public/pm/cozy-goals.css +172 -0
  58. package/workspace/public/pm/cozy-library.css +106 -17
  59. package/workspace/public/pm/cozy-nav.js +2 -3
  60. package/workspace/public/pm/cozy-pick.css +3 -0
  61. package/workspace/public/pm/cozy-pop-work.css +83 -24
  62. package/workspace/public/pm/cozy-pop-work.js +313 -72
  63. package/workspace/public/pm/cozy-popup.css +11 -2
  64. package/workspace/public/pm/cozy-popup.js +67 -9
  65. package/workspace/public/pm/cozy-routine-job.js +203 -0
  66. package/workspace/public/pm/cozy-routine-model.js +139 -31
  67. package/workspace/public/pm/cozy-routine-pop.js +164 -42
  68. package/workspace/public/pm/cozy-routine.css +61 -8
  69. package/workspace/public/pm/cozy-routine.js +207 -28
  70. package/workspace/public/pm/cozy-settings.js +1 -5
  71. package/workspace/public/pm/cozy-status-when.js +48 -0
  72. package/workspace/public/pm/cozy-viewer.js +19 -8
  73. package/workspace/public/pm/cozy-vw-mtg.css +39 -0
  74. package/workspace/public/pm/goals-model.js +205 -0
  75. package/workspace/public/pm/goals-open.js +124 -0
  76. package/workspace/public/pm/home-chat.js +4 -2
  77. package/workspace/public/pm/home-ini.js +8 -6
  78. package/workspace/public/pm/ini-edit.js +3 -1
  79. package/workspace/public/pm/ini-view-model.js +1 -1
  80. package/workspace/public/pm/library-model.js +170 -42
  81. package/workspace/public/pm/library-open.js +8 -5
  82. package/workspace/public/pm/page-chat.js +12 -2
  83. package/workspace/public/pm/pop-work-model.js +199 -41
  84. package/workspace/public/pm/premium-board.js +108 -43
  85. package/workspace/public/pm/premium-goals.js +213 -0
  86. package/workspace/public/pm/premium-library.js +376 -62
  87. package/workspace/public/pm/premium-shell.js +1 -1
  88. package/workspace/public/pm/premium-vw-mtg.js +79 -1
  89. package/workspace/public/pm/scope-chip.js +204 -0
  90. package/workspace/public/premium-events.html +3 -1
  91. package/workspace/public/premium-goals.html +37 -0
  92. package/workspace/public/premium-library.html +15 -7
  93. package/workspace/public/premium-routine.html +2 -0
  94. package/workspace/server.js +2 -1
  95. package/workspace/test-lists/doc-path.json +9 -0
  96. package/workspace/test-lists/goals-place.json +9 -0
  97. package/workspace/test-lists/status-when.json +9 -0
@@ -207,6 +207,9 @@ function rowOf(n, now = Date.now(), resumeMs = RESUME_MS) {
207
207
  }
208
208
  /** What came out of a meeting (Library's "Came out of it", initiative library-place): the decisions and tasks among the agent's bullets. */
209
209
  function cameOf(n) {
210
+ // the final notes after Stop, as the meeting card reads them (premium-vw-meet.js partsOf); else the bullets caught live
211
+ const f = n.final_notes;
212
+ if (f && (Array.isArray(f.decisions) || Array.isArray(f.actions))) return { decisions: (f.decisions || []).length, tasks: (f.actions || []).length };
210
213
  const b = (n.bullets || []).filter((x) => x && !x.dropped);
211
214
  return { decisions: b.filter((x) => x.cat === 'decision').length, tasks: b.filter((x) => x.cat === 'action').length };
212
215
  }
@@ -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
  };
@@ -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.set(A.file(dir), { scope: b.scope, artefact: b.artefact, field: b.field, text: typeof b.text === 'string' ? b.text : '' }, g.actor);
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') };
@@ -6,10 +6,16 @@
6
6
  * Board reads: milestones, plan ends, tasks, forecasts), the calendar (lib/calendar-events.js), the report schedules and the drafts
7
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
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.
9
13
  * POST /api/events-place/mark { key, fixed } → { ok } a date is fixed (true) or not (false): Events never offers it a new date
10
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)
11
17
  *
12
- * STATE. <runtime>/events/marks.jsonl, append-only, one line per press: { at, by, kind: fixed | unfixed | no | unno, key | sig }. The fold
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
13
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
14
20
  * suggestion, a new day, +) goes through the routes that already make it: /api/boards/tasks/state, /api/boards/tasks/edit, /api/pm-items/*. */
15
21
  const fs = require('fs');
@@ -23,15 +29,17 @@ const reason = (e) => String((e && e.message) || e).slice(0, 160);
23
29
 
24
30
  /* ── the marks ── */
25
31
  const marksFile = (runtimeDir) => path.join(runtimeDir, 'events', 'marks.jsonl');
26
- /** The marks folded: { fixed: Set<key>, declined: Set<sig> }. PURE over the lines. */
32
+ /** The marks folded: { fixed: Set<key>, declined: Set<sig>, gone: Map<key, 'met' | 'dropped'> }. PURE over the lines. */
27
33
  function foldMarks(lines) {
28
- const fixed = new Map(), no = new Map();
34
+ const fixed = new Map(), no = new Map(), gone = new Map();
29
35
  for (const l of lines || []) {
30
36
  if (!l || typeof l !== 'object') continue;
31
37
  if ((l.kind === 'fixed' || l.kind === 'unfixed') && typeof l.key === 'string') fixed.set(l.key, l.kind === 'fixed');
32
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);
33
41
  }
34
- return { fixed: new Set([...fixed].filter(([, v]) => v).map(([k]) => k)), declined: new Set([...no].filter(([, v]) => v).map(([k]) => k)) };
42
+ return { gone, fixed: new Set([...fixed].filter(([, v]) => v).map(([k]) => k)), declined: new Set([...no].filter(([, v]) => v).map(([k]) => k)) };
35
43
  }
36
44
  function readMarks(runtimeDir) {
37
45
  let text = '';
@@ -44,7 +52,8 @@ function markLine(body, by, at) {
44
52
  const okStr = (s) => typeof s === 'string' && s.length > 0 && s.length <= MAX_LEN;
45
53
  if (okStr(b.key) && typeof b.fixed === 'boolean') return { at, by, kind: b.fixed ? 'fixed' : 'unfixed', key: b.key };
46
54
  if (okStr(b.sig) && typeof b.no === 'boolean') return { at, by, kind: b.no ? 'no' : 'unno', sig: b.sig };
47
- return { error: 'send { key, fixed: true | false } or { sig, no: true | false }' };
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 }" };
48
57
  }
49
58
 
50
59
  /* ── the readers ── */
@@ -104,6 +113,22 @@ function readDrafts(roots) {
104
113
  }
105
114
  return out;
106
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
+ }
107
132
  function readOwn(runtimeDir) {
108
133
  const P = require('./pm-items.js');
109
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 }));
@@ -121,13 +146,21 @@ async function handle(deps) {
121
146
  const schedules = tryRead('the report schedules', () => deps.readSchedules(), []);
122
147
  const drafts = tryRead('the report drafts', () => deps.readDrafts(boards), []);
123
148
  const own = tryRead('your items', () => deps.readOwn(), []);
124
- const marks = tryRead('your marks', () => deps.readMarks(), { fixed: new Set(), declined: new Set() });
125
- const model = EP.build({ today: deps.today, boards, meetings, schedules, drafts, own, marks });
126
- return { status: 200, body: { ok: true, state: 'ready', today: model.today, items: model.items, later: model.later, missing } };
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 } };
127
160
  }
128
161
 
129
162
  module.exports = {
130
- foldMarks, markLine, handlePure: handle, readers: { readSchedules, readDrafts, readOwn, readMarks },
163
+ foldMarks, markLine, handlePure: handle, readers: { readSchedules, readDrafts, readOwn, readMarks, readJira, readMeetings, calendarRead },
131
164
  prefixes: ['/api/events-place'],
132
165
  handle: async (req, res, url, ctx) => {
133
166
  if (url.pathname === '/api/events-place/mark') {
@@ -153,7 +186,11 @@ module.exports = {
153
186
  const out = await handle({
154
187
  today: localDay(now),
155
188
  readBoards: () => readBoards(req, ctx),
156
- readMeetings: () => (ctx.runtimeDir ? require('./calendar-events.js').readAll(ctx.runtimeDir, { now: now.getTime() }) : []),
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) : {}),
157
194
  readSchedules: () => readSchedules(now),
158
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 }))),
159
196
  readOwn: () => (ctx.runtimeDir ? readOwn(ctx.runtimeDir) : []),
@@ -1,13 +1,21 @@
1
1
  'use strict';
2
2
  /* routes-library.js — GET /api/library-items[?ws=<id>&initiative=<id>] (initiative library-place, slice 7 of the six-place navigation).
3
3
  *
4
- * The Library place reads every product; slice 3's Artefacts table reads one initiative. → { ok, items } (lib/library-items.js ITEM),
4
+ * The Library place reads every product; slice 3's Artefacts table reads one initiative. → { ok, items, programs } (lib/library-items.js ITEM),
5
5
  * newest first. READ ONLY: it folds what is already recorded and writes nothing.
6
6
  * files lib/doc-library.js library() — the tracked markdown files, attributed to the initiative that owns them (server.js initiativeIndex)
7
7
  * links lib/custom-docs.js — the links the PM added to an initiative (Confluence, Google Docs, Google Slides)
8
8
  * rounds lib/idle-lab.js roundsOf over lib/proposals.js — the prototype rounds of each initiative
9
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 }
10
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)
11
19
  * (/api/library is the old file tree of one workspace, server.js; this route is a different one.) */
12
20
  const Items = require('./library-items.js');
13
21
 
@@ -66,24 +74,82 @@ function gather(ctx, list) {
66
74
  }
67
75
  let notes = [];
68
76
  try { const l = require('./notes.js').list(ctx.runtimeDir); notes = l.ok ? l.notes : []; } catch { unread.push({ ws: null, source: 'meeting notes' }); }
69
- return { items: Items.build({ products, notes }), unread };
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 };
70
109
  }
71
110
 
72
111
  async function handle(req, res, url, ctx) {
73
- if (url.pathname !== '/api/library-items') return false;
112
+ const P = url.pathname;
113
+ if (P !== '/api/library-items' && P !== '/api/library-items/find' && P !== '/api/library-items/peek') return false;
74
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
+ }
75
142
  const ws = url.searchParams.get('ws') || '', ini = url.searchParams.get('initiative') || '';
76
143
  if (ini && !ID_RE.test(ini)) { ctx.json(res, { ok: false, error: 'initiative names an initiative' }, 400); return true; }
77
- let list = [];
78
- try { list = typeof ctx.workspaceList === 'function' ? ctx.workspaceList() : []; } catch { list = []; }
144
+ let list = all;
79
145
  if (ws) {
80
146
  const w = list.find((x) => x.id === ws);
81
147
  if (!w) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
82
148
  list = [w];
83
149
  }
84
- const { items, unread } = gather(ctx, list);
85
- ctx.json(res, { ok: true, items: Items.narrow(items, { ws: ws || null, initiative: ini || null }), unread });
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 });
86
152
  return true;
87
153
  }
88
154
 
89
- module.exports = { prefixes: ['/api/library-items'], handle, gather, roundsOf };
155
+ module.exports = { prefixes: ['/api/library-items'], handle, gather, roundsOf, peek };
@@ -21,6 +21,8 @@
21
21
  * POST /api/report-setups/move { ws, id, to } → { ok, id, to, moved } ✦ Move to <product>: definition, drafts and setup go to
22
22
  * the workspace `to`; a report with an issued issue is 409 (redesign R)
23
23
  * POST /api/report-setups/remove { ws, id } → { ok } delete a TEMPLATE: its schedule stops; its drafts and issued reports stay (L2)
24
+ * POST /api/report-setups/drop { ws, id } → { ok } ✕ on a report PMOS proposes: its draft definition moves to
25
+ * definitions/.dropped/ (lib/routine-reports.js dropDefinition); a set-up report is 409
24
26
  * POST /api/report-setups/from-dashboard { ws, key, name, output, schedule, audience } → { ok, setup }
25
27
  * POST /api/report-setups/finder { ws, cadence?, sources? } → { ok, finder }
26
28
  * GET /api/report-setups/storyline?ws&board&scope&story? → { ok, storyline, defaults, checks, proposals } a report from Intelligence (batch 15 item 4,
@@ -67,7 +69,7 @@ const headless = require('./headless.js');
67
69
 
68
70
  const text = (v) => (typeof v === 'string' ? v : '');
69
71
  const bad = (status, error) => ({ status, body: { ok: false, error } });
70
- const POSTS = ['ask', 'change', 'cancel', 'setup', 'draft', 'dismiss', 'pause', 'resume', 'from-dashboard', 'finder', 'edit', 'remove', 'documents/discard', 'documents/archive', 'strip-dismiss', 'confirm', 'move'];
72
+ const POSTS = ['ask', 'change', 'cancel', 'setup', 'draft', 'dismiss', 'pause', 'resume', 'from-dashboard', 'finder', 'edit', 'remove', 'documents/discard', 'documents/archive', 'strip-dismiss', 'confirm', 'move', 'drop'];
71
73
  const IR = require('./intel-report.js');
72
74
  const MADE_BY = ['schedule', 'you', 'agent'];
73
75
 
@@ -350,7 +352,7 @@ async function handle(req, res, url, ctx) {
350
352
  const setups = [...RS.fold(RS.readLines(RS.ledgerFile(w.root))).setups.values()].map((s) => {
351
353
  let next = null;
352
354
  if (s.status === 'active' && s.schedule) { try { const n = RS.nextDraftAt(s.schedule, s.last_run, now); next = n ? n.toISOString() : null; } catch { next = null; } }
353
- return { id: s.id, name: s.name, purpose: s.purpose, audience: s.audience, source: s.source, output: s.output, schedule: s.schedule, label: RS.scheduleLabel(s.schedule), next_draft: next, status: s.status };
355
+ return { id: s.id, name: s.name, purpose: s.purpose, audience: s.audience, source: s.source, output: s.output, schedule: s.schedule, label: RS.scheduleLabel(s.schedule), next_draft: next, status: s.status, ...(s.ready ? { ready: s.ready } : {}) };
354
356
  });
355
357
  const reports = require('./routine-reports.js').routineReports({ setups, docs: documentsOf(ctx, w).docs, defs, boards, here: w.id });
356
358
  return send({ status: 200, body: { ok: true, ws: w.id, name: w.name || w.id, reports } });
@@ -553,6 +555,15 @@ async function handle(req, res, url, ctx) {
553
555
  if (ctx.invalidateNeedsAgg) ctx.invalidateNeedsAgg();
554
556
  return send({ status: 200, body: Object.assign({ to: t.id }, r) });
555
557
  }
558
+ if (sub === 'drop') {
559
+ const id = text(body.id);
560
+ const s = RS.fold(RS.readLines(file)).setups.get(id);
561
+ if (s && s.status !== 'removed') return send(bad(409, 'it is set up: pause or delete it instead'));
562
+ const r = require('./routine-reports.js').dropDefinition(root, id);
563
+ if (!r.ok) return fail(r);
564
+ if (ctx.invalidateNeedsAgg) ctx.invalidateNeedsAgg();
565
+ return send({ status: 200, body: { ok: true } });
566
+ }
556
567
  if (sub === 'remove') {
557
568
  const r = RS.remove(root, text(body.id), opts);
558
569
  if (!r.ok) return fail(r);
@@ -3,20 +3,26 @@
3
3
  * board 11 on Exploring 2; done test planning/done-tests/routine-place.md T1).
4
4
  *
5
5
  * routineReports({ setups, docs, defs, boards, here }) → [row] PURE
6
- * setups GET /api/report-setups setups (lib/routes-report-setups.js listAnswer): { id, name, purpose, audience, source, output, schedule,
6
+ * setups GET /api/report-setups setups (lib/routes-report-setups.js listAnswer): { id, name, purpose, audience, source, output, schedule, ready?,
7
7
  * label, next_draft, status: active | paused }
8
8
  * docs the report documents (routes-report-setups.js documentsOf docs): { path, setup, name, slot, state: draft | issued, archived, source, output }
9
9
  * defs the definitions (lib/report-setups.js definitionsOf): { id, title, audience, status, source, output }
10
10
  * boards [{ ws, name }] and here: the workspace the reports sit in (for the ✦ Move of lib/report-acts.js)
11
- * row: { id, name, audience, purpose, when, schedule, next, status: 'active' | 'paused' | null, output, source, act, issues, latest }
11
+ * row: { id, name, audience, purpose, when, schedule, next, status: 'active' | 'paused' | null, output, source, about, definition, act, issues, latest }
12
12
  * when the setup's schedule in words; '' when no setup says it (a definition drafted by a skill has no schedule here)
13
13
  * next the setup's next draft (ISO) while it is active, else null
14
14
  * act the report's one ✓ (lib/report-acts.js reportActOf): move | confirm | issue | resume, or null
15
15
  * issues its files, newest first: { path, slot, state, archived }; latest is the newest one not archived, or null
16
16
  *
17
17
  * A report is a row when it has a setup or at least one issue. A definition with neither is not drawn (zero is silence). Nothing is filled with a
18
- * guess: a field the records leave silent is '' or null. Read-only: nothing here writes.
18
+ * guess: a field the records leave silent is '' or null. routineReports only reads.
19
+ *
20
+ * dropDefinition(root, id) → { ok } | { ok: false, status, error } ✕ on a report PMOS proposes (Routine round 3 item 1): the definition
21
+ * moves to definitions/.dropped/<id>.md, so it is no longer read (definitionsOf reads *.md of definitions/ only) and nothing is lost: moving it
22
+ * back brings the proposal back. Only a proposed definition (status: draft) with no setup can be dropped; the route checks the setup.
19
23
  */
24
+ const fs = require('fs');
25
+ const path = require('path');
20
26
  const RA = require('./report-acts.js');
21
27
 
22
28
  const str = (v) => (typeof v === 'string' ? v : '');
@@ -42,6 +48,8 @@ function routineReports(f = {}) {
42
48
  when: s ? str(s.label) : '', schedule: s && s.schedule ? s.schedule : null, next: s && s.status === 'active' ? s.next_draft || null : null,
43
49
  status: s ? (s.status === 'paused' ? 'paused' : 'active') : null,
44
50
  output: str(s && s.output) || str(def && def.output) || str(named && named.output), source: str(s && s.source) || str(def && def.source) || str(named && named.source),
51
+ about: aboutOf(s), // the program or project (initiative) its setup is about, for Routine's chip; null for a product's report
52
+ definition: str(def && def.path) || null, // the definition file, whose body is the report's Instruction (round 3 item 3)
45
53
  act, issues, latest: issues.find((x) => !x.archived) || null,
46
54
  });
47
55
  }
@@ -49,4 +57,28 @@ function routineReports(f = {}) {
49
57
  return out.sort((a, b) => (a.status ? 0 : 1) - (b.status ? 0 : 1) || a.name.localeCompare(b.name));
50
58
  }
51
59
 
52
- module.exports = { routineReports };
60
+ /** What a setup is about, from the setup only: a ready-made report's scope, an initiative dashboard, or an Intelligence scope. */
61
+ function aboutOf(s) {
62
+ if (!s) return null;
63
+ const m = /^(program|initiative):(.+)$/.exec(String((s.ready && s.ready.scope) || ''))
64
+ || /^dashboard:(initiative):(.+)$/.exec(str(s.source)) || /^intelligence:(program|initiative):(.+)$/.exec(str(s.source));
65
+ return m ? { level: m[1], id: m[2] } : null;
66
+ }
67
+
68
+ const DEF_ID = /^[a-z][a-z0-9-]{0,39}$/;
69
+ function dropDefinition(root, id) {
70
+ if (!DEF_ID.test(String(id || ''))) return { ok: false, status: 400, error: 'no such proposal' };
71
+ const abs = path.resolve(String(root));
72
+ const dir = path.join(abs, require('./report-draft.js').stateRel(abs), 'reports', 'definitions');
73
+ const from = path.join(dir, id + '.md');
74
+ let txt;
75
+ try { txt = fs.readFileSync(from, 'utf8'); } catch { return { ok: false, status: 404, error: 'no such proposal' }; }
76
+ const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(txt);
77
+ const st = fm && /^status:\s*["']?([\w-]+)/m.exec(fm[1]);
78
+ if (!st || st[1] !== 'draft') return { ok: false, status: 409, error: 'it is not a proposal: it was confirmed, so pause or delete it instead' };
79
+ const to = path.join(dir, '.dropped');
80
+ try { fs.mkdirSync(to, { recursive: true }); fs.renameSync(from, path.join(to, id + '.md')); } catch (e) { return { ok: false, status: 500, error: 'it could not be dropped: ' + e.message }; }
81
+ return { ok: true };
82
+ }
83
+
84
+ module.exports = { routineReports, dropDefinition, aboutOf };
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+ /* lib/status-when.js — the day a status move really happened (popup round 3 point 18). A person often moves a task late, so the move can carry
3
+ * `happened` (YYYY-MM-DD) apart from `at`, the time it was recorded. The server checks it here; pm/cozy-status-when.js asks it on the page.
4
+ *
5
+ * checkHappened(v, { today, floor }) → null, or the refusal in plain words. v is a YYYY-MM-DD day, never after today (today is the server's
6
+ * UTC day; one day of slack lets a person east of UTC say their own today), never before floor (the
7
+ * previous move's day, or the day the task was made)
8
+ * floorOf(t) → that floor for a folded PMOS task: the day of its last move (its happened, else its at), else its at
9
+ * lateDays(due, done) → whole days a Done came after its due day (0 when on time or a day is missing) */
10
+ const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
11
+ const DAY = 864e5;
12
+ const ms = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
13
+ const iso = (n) => new Date(n).toISOString().slice(0, 10);
14
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
15
+ const words = (v) => { const d = new Date(ms(v)); return d.getUTCDate() + ' ' + MON[d.getUTCMonth()] + ' ' + d.getUTCFullYear(); };
16
+
17
+ function checkHappened(v, o = {}) {
18
+ if (typeof v !== 'string' || !DAY_RE.test(v) || iso(ms(v)) !== v) return 'happened is a day, YYYY-MM-DD';
19
+ const today = o.today || iso(Date.now());
20
+ if (ms(v) > ms(today) + DAY) return 'A move cannot happen in the future.';
21
+ const floor = o.floor && DAY_RE.test(String(o.floor).slice(0, 10)) ? String(o.floor).slice(0, 10) : null;
22
+ if (floor && v < floor) return 'The previous change was on ' + words(floor) + '. Pick that day or later.';
23
+ return null;
24
+ }
25
+ function floorOf(t) {
26
+ if (!t) return null;
27
+ const h = (t.history || []).filter((x) => x && x.state);
28
+ const last = h[h.length - 1];
29
+ const v = last ? last.happened || last.at : t.at;
30
+ return v ? String(v).slice(0, 10) : null;
31
+ }
32
+ function lateDays(due, done) {
33
+ const a = ms(due), b = ms(done);
34
+ return a == null || b == null || b <= a ? 0 : Math.round((b - a) / DAY);
35
+ }
36
+ module.exports = { checkHappened, floorOf, lateDays, DAY_RE };
@@ -8,7 +8,8 @@
8
8
  * STATE_OF[item.state] → its task state: todo To do · doing, review In progress · done Done
9
9
  * rowsOf(root, ids, board) → the items of those initiatives as work items (routes-boards itemsOf's shape, src 'pmos', store 'item')
10
10
  * itemOf(root, id) → the folded item, or null (a withdrawn item is gone: it was Won't do)
11
- * stateEvents(it, state, why) → the plan-items lines that set a task state: a move, or a withdraw for Won't do and Archived
11
+ * stateEvents(it, state, why, happened) → the plan-items lines that set a task state: a move (happened: the day it really happened), or a
12
+ * withdraw for Won't do and Archived
12
13
  * deleteEvents(it, why) · restoreEvents(id) → a Delete (a withdraw with why "deleted") and its Undo (batch 11 item 16)
13
14
  * goneOf(root, id) → a withdrawn item as it was, or null: what a restore brings back
14
15
  * editEvents(it, edit) → the lines of a rename, a reschedule or the Viewer's edits (title, owner, notes, start, due)
@@ -60,7 +61,7 @@ function rowsOf(root, ids, board) {
60
61
  const it = f.items[id];
61
62
  if (!it || it.proposed || !ids.has(it.initiative)) continue;
62
63
  out.push({ uid: it.id, key: '', kind: 'Task', src: 'pmos', store: 'item', title: it.title, status: STATE_OF[it.state] || 'To do', blocked: !!it.blocked, owner: ownerName(it.owner),
63
- notes: it.note || '', ini: it.initiative, epic: null, start: it.start || null, end: it.due || null, ref: it.id, board, ...(it.milestone ? { milestone: true } : {}),
64
+ notes: it.note || '', ini: it.initiative, epic: null, start: it.start || null, end: it.due || null, ref: it.id, board, ...(it.milestone ? { milestone: true } : {}), ...((it.history || []).some((h) => h.ev === 'moved') ? { since: planItems.sinceOf(it) } : {}),
64
65
  // the breakdown's own stage (plan-tree) and order: the one view places the item in the workflow stage of the same name
65
66
  ...(it.stage ? { itemStage: it.stage } : {}), ...(Number.isFinite(it.order) ? { order: it.order } : {}) });
66
67
  }
@@ -68,12 +69,13 @@ function rowsOf(root, ids, board) {
68
69
  }
69
70
 
70
71
  /** → { events } | { same: true } | { error } */
71
- function stateEvents(it, state, why) {
72
+ function stateEvents(it, state, why, happened) {
72
73
  if (state === "Won't do" || state === 'Archived') return { events: [{ ev: 'withdrawn', item: it.id }] };
73
74
  const to = MOVE_TO[state];
74
75
  if (!to) return { error: `state is one of ${Object.keys(MOVE_TO).concat("Won't do", 'Archived').join(', ')}` };
75
76
  if (STATE_OF[it.state] === state) return { same: true };
76
77
  const ev = { ev: 'moved', item: it.id, to };
78
+ if (happened) ev.happened = happened;
77
79
  // the reason a person gave is the Done's evidence: an agent Done with none goes to the PM to check (lib/plan-items.js noEvidence)
78
80
  if (to === 'done' && typeof why === 'string' && why.trim()) ev.evidence = { kind: 'note', ref: why.trim().replace(/\s+/g, ' ').slice(0, 200) };
79
81
  return { events: [ev] };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.611.0",
3
+ "version": "0.612.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.611.0",
9
+ "version": "0.612.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.611.0",
3
+ "version": "0.612.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -52,7 +52,8 @@ process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
52
52
  /* an ended meeting with notes and a recording */
53
53
  const A = await open('/premium-viewer.html?open=meeting&note=n1');
54
54
  const p = A.page;
55
- const up = await until(() => p.evaluate(() => !!document.querySelector('#czViewer .vz-mtg[data-mk="notes"]') && !!document.querySelector('#czViewer .czs-sum')), 15000);
55
+ // a held meeting opens in its notes view (board 34); its full card, which this suite reads, is one press away
56
+ const up = await until(() => p.evaluate(() => { const f = document.querySelector('#czViewer [data-a="h-full"]'); if (f) f.click(); return !!document.querySelector('#czViewer .vz-mtg[data-mk="notes"]') && !!document.querySelector('#czViewer .czs-sum'); }), 15000);
56
57
  ok('0 the meeting opens in the Viewer on its own page', up);
57
58
  if (!up) return finish(1);
58
59