create-pmos 0.424.0 → 0.426.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 (110) hide show
  1. package/package.json +25 -25
  2. package/payload/KIT-VERSION +1 -1
  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/workspace/board-deliveries-test.js +153 -0
  7. package/workspace/board-programs-test.js +60 -36
  8. package/workspace/board-shot.js +4 -3
  9. package/workspace/briefing-premium-board-test.js +9 -6
  10. package/workspace/briefing-premium-insights-test.js +31 -15
  11. package/workspace/briefing-premium-products-test.js +46 -43
  12. package/workspace/calm-timeline-test.js +190 -0
  13. package/workspace/changelog.json +24 -0
  14. package/workspace/ev-everywhere-test.js +3 -1
  15. package/workspace/guide/briefing-premium.md +3 -2
  16. package/workspace/guide/claude-proposes.md +16 -1
  17. package/workspace/guide/home.md +2 -2
  18. package/workspace/guide/index.md +1 -0
  19. package/workspace/guide/notes.md +39 -1
  20. package/workspace/guide/present-in-a-meeting.md +57 -0
  21. package/workspace/guide/programs.md +4 -3
  22. package/workspace/lib/board-premium.js +3 -1
  23. package/workspace/lib/briefing-premium-products.js +18 -4
  24. package/workspace/lib/chat-file-locate.js +40 -2
  25. package/workspace/lib/engine/boards.js +8 -2
  26. package/workspace/lib/idle-close.js +60 -0
  27. package/workspace/lib/loose-proposals.js +302 -0
  28. package/workspace/lib/meeting-focus.js +64 -14
  29. package/workspace/lib/my-work-premium.js +1 -1
  30. package/workspace/lib/proposal-runs.js +77 -2
  31. package/workspace/lib/propose-cli.js +42 -1
  32. package/workspace/lib/route-modules.js +1 -0
  33. package/workspace/lib/routes-boards.js +16 -4
  34. package/workspace/lib/routes-brief-page.js +9 -1
  35. package/workspace/lib/routes-briefing-premium.js +19 -0
  36. package/workspace/lib/routes-loose.js +210 -0
  37. package/workspace/lib/routes-meeting-focus.js +28 -6
  38. package/workspace/lib/routes-pm-items.js +27 -17
  39. package/workspace/lib/settings-store.js +2 -1
  40. package/workspace/lib/task-cli.js +18 -11
  41. package/workspace/milestone-pins-test.js +170 -0
  42. package/workspace/package-lock.json +2 -2
  43. package/workspace/package.json +1 -1
  44. package/workspace/premium-board-actions-test.js +2 -1
  45. package/workspace/premium-briefing-depth-test.js +2 -2
  46. package/workspace/premium-chat-term-test.js +13 -2
  47. package/workspace/premium-core-doc-issue-test.js +1 -1
  48. package/workspace/premium-rec-now-test.js +153 -0
  49. package/workspace/premium-rec-tab-test.js +167 -0
  50. package/workspace/product-lane-test.js +30 -17
  51. package/workspace/public/pm/bd-acts.js +6 -3
  52. package/workspace/public/pm/bd-deliveries.js +218 -0
  53. package/workspace/public/pm/bd-pin-card.css +16 -0
  54. package/workspace/public/pm/bd-pin-card.js +80 -0
  55. package/workspace/public/pm/bd-pins.js +33 -0
  56. package/workspace/public/pm/bd-pop.js +2 -0
  57. package/workspace/public/pm/bd-prog.js +5 -4
  58. package/workspace/public/pm/bd-span.js +140 -102
  59. package/workspace/public/pm/cozy-aud.css +9 -0
  60. package/workspace/public/pm/cozy-aud.js +80 -0
  61. package/workspace/public/pm/cozy-board.css +73 -11
  62. package/workspace/public/pm/cozy-home.css +16 -1
  63. package/workspace/public/pm/cozy-live-pill.js +3 -0
  64. package/workspace/public/pm/cozy-pick.css +41 -0
  65. package/workspace/public/pm/cozy-pick.js +134 -0
  66. package/workspace/public/pm/cozy-rec-bridge.js +32 -0
  67. package/workspace/public/pm/cozy-rec-now.css +104 -0
  68. package/workspace/public/pm/cozy-rec-now.js +330 -0
  69. package/workspace/public/pm/cozy-rec-present.css +69 -0
  70. package/workspace/public/pm/cozy-rec-present.js +467 -0
  71. package/workspace/public/pm/cozy-rec-tab.css +90 -0
  72. package/workspace/public/pm/cozy-rec-tab.js +219 -0
  73. package/workspace/public/pm/cozy-settings.js +8 -2
  74. package/workspace/public/pm/cozy-today.css +4 -0
  75. package/workspace/public/pm/home-app.js +51 -22
  76. package/workspace/public/pm/home-data.js +5 -3
  77. package/workspace/public/pm/home-list.js +63 -15
  78. package/workspace/public/pm/home-more.js +2 -31
  79. package/workspace/public/pm/home-today.js +19 -9
  80. package/workspace/public/pm/ini-tasks.js +4 -1
  81. package/workspace/public/pm/live-model.js +1 -1
  82. package/workspace/public/pm/loose-props.css +54 -0
  83. package/workspace/public/pm/loose-props.js +262 -0
  84. package/workspace/public/pm/premium-board.js +65 -30
  85. package/workspace/public/pm/premium-insights.js +42 -24
  86. package/workspace/public/pm/premium-meeting.js +17 -4
  87. package/workspace/public/pm/premium-mtg-present.js +4 -3
  88. package/workspace/public/pm/premium-report-read.js +2 -0
  89. package/workspace/public/pm/premium-vw-mtg.js +15 -7
  90. package/workspace/public/pm/rec-state.js +13 -5
  91. package/workspace/public/pm/rec-tab-core.js +92 -0
  92. package/workspace/public/pm/term-view.js +81 -10
  93. package/workspace/public/pm/view-notes.js +9 -0
  94. package/workspace/public/premium-aud.html +22 -0
  95. package/workspace/public/premium-board.html +2 -0
  96. package/workspace/public/premium-insights.html +2 -1
  97. package/workspace/public/premium-rec.html +30 -0
  98. package/workspace/public/premium.html +1 -0
  99. package/workspace/rec-present-test.js +229 -0
  100. package/workspace/server.js +116 -7
  101. package/workspace/skills/loose-propose.skill +39 -0
  102. package/workspace/task-milestones-test.js +15 -6
  103. package/workspace/test-lists/board-deliveries.json +13 -0
  104. package/workspace/test-lists/calm-timeline.json +5 -0
  105. package/workspace/test-lists/loose-props.json +9 -0
  106. package/workspace/test-lists/milestone-pins.json +6 -0
  107. package/workspace/test-lists/rec-now.json +6 -0
  108. package/workspace/test-lists/rec-present.json +13 -0
  109. package/workspace/test-lists/recording-tab.json +13 -0
  110. package/workspace/timeline-holds-test.js +44 -42
@@ -9,14 +9,17 @@
9
9
  * pmos propose done --json <file|-> "looks done": the evidence says the work happened
10
10
  * pmos propose name --json <file|-> tidy names, before → after; the detail cut goes to the notes
11
11
  * pmos propose status what is open, kept and dropped on this initiative (read)
12
+ * pmos propose loose link|merge|finish|start --json <file|-> Home's clean-up of "Not in an initiative" (batch 13 item 3,
13
+ * lib/loose-proposals.js), only in the clean-up run (PMOS_PROPOSE_INI=~loose); `loose status` reads
12
14
  *
13
15
  * The server pins the initiative, the board, the run and the ledger in the run's environment (PMOS_PROPOSE_INI, _BOARD, _RUN, _FILE);
14
16
  * outside such a run the verb refuses: the PM keeps and drops on the page. It writes `src` and `propose` lines only. A proposal the PM
15
17
  * dropped from the same evidence answers `dropped`. Exit codes: 0 filed, 1 refused, 2 usage. Nothing is sent. */
16
18
  const fs = require('fs');
17
19
  const PR = require('./proposals.js');
20
+ const LP = require('./loose-proposals.js');
18
21
 
19
- const COMMANDS = { propose: ['look', 'found', 'date', 'done', 'name', 'status'] };
22
+ const COMMANDS = { propose: ['look', 'found', 'date', 'done', 'name', 'status', 'loose'] };
20
23
  const USAGE = [
21
24
  'usage: pmos propose look|found|date|done|name|status — what Claude proposes on an initiative, under its ✦',
22
25
  ' pmos propose look <source> --reading | --found <n> --what "<5 documents>" | --none',
@@ -32,8 +35,44 @@ const USAGE = [
32
35
  ' pmos propose name --json <file|-> { "why", "sources", "items": [{ "task", "to", "notes"? }] } verb first, sentence case, about 7 words,',
33
36
  ' the WBS number kept, no "+" and no brackets; the cut detail goes in notes',
34
37
  ' pmos propose status',
38
+ ' pmos propose loose link --json - { "initiative", "title", "why", "items": [{ "row" }] } rows that belong to one open initiative',
39
+ ' pmos propose loose merge --json - { "into": "w:<item>", "why", "items": [{ "row": "c:<chat>" }] } a chat that doubles the PM\'s own item',
40
+ ' pmos propose loose finish --json - { "why", "items": [{ "row", "quote", "at": "YYYY-MM-DD" }] } the message that closed the work; no quote, no finish',
41
+ ' pmos propose loose start --json - { "title", "intent", "anchor", "why", "items": [{ "row" }, …3 or more] } one new thing, not an open initiative',
42
+ ' pmos propose loose status',
35
43
  'Every proposal carries its source. It waits for the PM\'s ✓ on the page. Nothing is sent.',
36
44
  ];
45
+ const LOOSE_TYPES = { link: ['link', 'ini'], merge: ['tidy', 'merge'], finish: ['tidy', 'finish'], start: ['start', 'new'] };
46
+ /** `pmos propose loose …`: Home's clean-up run files what the ✦ on "Not in an initiative" proposes. */
47
+ function loose(args, { say, stdin, file, runId }) {
48
+ const sub = args[1];
49
+ const F = LP.fold(LP.readLines(file));
50
+ if (sub === 'status') {
51
+ const kept = new Set(F.kept.filter((k) => !F.undone.has(k.batch)).flatMap((k) => k.ids));
52
+ if (!F.props.size) say('nothing filed');
53
+ for (const p of F.props.values()) say(`${kept.has(p.id) ? 'kept' : 'open'} ${p.group}/${p.type} ${p.id} · ${p.items.length} rows · ${p.why}`);
54
+ return 0;
55
+ }
56
+ if (!LOOSE_TYPES[sub]) { say('usage: pmos propose loose link|merge|finish|start --json <file|-> or pmos propose loose status'); return 2; }
57
+ const L = LP.lastLook(F);
58
+ if (!L || L.run !== runId || L.ended) { say('✗ this run is not looking now (it ended, or the PM pressed Stop)'); return 1; }
59
+ const jsonAt = args.indexOf('--json'), src = jsonAt >= 0 ? args[jsonAt + 1] : null;
60
+ if (!src) { say(`usage: pmos propose loose ${sub} --json <file|->`); return 2; }
61
+ const r = readJson(src, stdin); if (r.error) { say('✗ ' + r.error); return 1; }
62
+ const [group, type] = LOOSE_TYPES[sub];
63
+ let bad = 0;
64
+ for (const x of Array.isArray(r.body) ? r.body : [r.body]) {
65
+ const c = LP.clean(group, type, x);
66
+ if (c.error) { say(`✗ refused: ${c.error}`); bad++; continue; }
67
+ // rule 6: a row the PM dropped or left out in this group is not proposed again
68
+ const scope = LP.scopeOf(group), was = c.prop.items.length;
69
+ c.prop.items = c.prop.items.filter((it) => !F.drops.has(scope + '|' + it.row));
70
+ if (!c.prop.items.length) { say(`dropped ${c.prop.id}: the PM left these rows out`); continue; }
71
+ fs.appendFileSync(file, JSON.stringify({ at: new Date().toISOString(), by: null, kind: 'propose', run: runId, ...c.prop }) + '\n');
72
+ say(`filed ${c.prop.id} · ${group}/${type} · ${c.prop.items.length} rows${was > c.prop.items.length ? ' (' + (was - c.prop.items.length) + ' left out by the PM)' : ''}`);
73
+ }
74
+ return bad ? 1 : 0;
75
+ }
37
76
  const GROUP = { found: 'found', date: 'dates', done: 'status', name: 'names' };
38
77
 
39
78
  function readJson(src, stdin) {
@@ -50,6 +89,8 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, stdin
50
89
  if (!COMMANDS.propose.includes(verb)) { say(`unknown propose command "${verb}" — one of ${COMMANDS.propose.join(', ')}`); return 2; }
51
90
  const file = env.PMOS_PROPOSE_FILE, runId = env.PMOS_PROPOSE_RUN, ini = env.PMOS_PROPOSE_INI, board = env.PMOS_PROPOSE_BOARD || '';
52
91
  if (!file || !runId || !ini) { say('✗ pmos propose is for Claude\'s proposal run. The PM keeps and drops proposals on the page, under the initiative\'s ✦'); return 1; }
92
+ if ((verb === 'loose') !== (ini === '~loose')) { say(verb === 'loose' ? '✗ pmos propose loose is for Home\'s clean-up run' : '✗ this is Home\'s clean-up run: file with pmos propose loose'); return 1; }
93
+ if (verb === 'loose') return loose(args, { say, stdin, file, runId });
53
94
  const F = PR.fold(PR.readLines(file));
54
95
  const line = (ev) => { fs.appendFileSync(file, JSON.stringify({ at: new Date().toISOString(), by: null, ...ev }) + '\n'); };
55
96
 
@@ -76,6 +76,7 @@ const MODULES = Object.freeze([
76
76
  'routes-task-plans', // batch 11 item 8: drafts of an initiative's tasks, saved plans, Make live (task-plans.jsonl; page-press POST)
77
77
  'routes-task-links', // batch 11 item 15: links between tasks, Claude's proposals, the quiet moves (task-links.jsonl; page-press POST)
78
78
  'routes-proposals', // batch 12 items 2, 3 and 4: everything Claude proposes on an initiative, under its one ✦ (proposals.jsonl; page-press POST)
79
+ 'routes-loose', // batch 13 item 3: Claude's clean-up of Home's "Not in an initiative" under the group's ✦ (loose-props/; page-press POST)
79
80
  'routes-workflows', // workflows-per-initiative (D99): the workflow library, save, copy, archive and the chat's draft (workflows.jsonl; page-press POST)
80
81
  'routes-settings', // console3 Settings: the settings store for settings with no home of their own (GET; page-press POST)
81
82
  'routes-hooks', // planning-flows run 7: CLI hook endpoints (session token, per-run JSONL)
@@ -29,8 +29,9 @@
29
29
  * POST /api/boards/tasks/reschedule { ws, board, task, days } → { ok, item }
30
30
  * POST /api/boards/tasks/undo-add { ws, board, task } → { ok } takes back a task added in the last 2 minutes, still To do
31
31
  * POST /api/boards/tasks/rename { ws, board, task, title } → { ok, from, item } only the title changes
32
- * POST /api/boards/tasks/edit { ws, board, task, owner?, notes?, start?, due?, initiative?, section?, milestone? } → { ok, from, item } the Viewer's edits in place
32
+ * POST /api/boards/tasks/edit { ws, board, task, owner?, notes?, start?, due?, initiative?, section?, milestone?, pinned? } → { ok, from, item } the Viewer's edits in place
33
33
  * (milestone: true | false, the ◇ flag of batch 11 item 3; a Jira key takes the flag only)
34
+ * (pinned: true | false | null, a milestone's pin on the Board timeline, batch 13 item 4; null = the rule, the last one only)
34
35
  * (section: the task's place in the breakdown, a stage key of its initiative's workflow or '' — a task-section line)
35
36
  * (canvas XetX1Rest); `from` holds the fields as they were, so Undo is the same call with `from`
36
37
  * POST /api/boards/tickets/note { ws, board, ref, notes } → { ok, from, notes } the PM's notes on a Jira ticket
@@ -547,6 +548,9 @@ function itemsOf(w, fr, board, rows) {
547
548
  // a task flagged as a milestone (feedback batch 11 item 3): the PM's flag on the board ledger, else a breakdown item's own plan-items flag
548
549
  const MS = fr.folded.milestones || new Map();
549
550
  for (const x of out) if (x.kind !== 'Epic') { const on = MS.has(x.uid) ? MS.get(x.uid) : !!x.milestone; if (on) x.milestone = true; else delete x.milestone; }
551
+ // the PM's pin on a milestone (batch 13 item 4, XcalmA5Milestones): carried only when set, so an unset one follows the rule (the last one shows)
552
+ const PN = fr.folded.pins || new Map();
553
+ if (PN.size) for (const x of out) if (x.kind !== 'Epic' && PN.has(x.uid)) x.pinned = PN.get(x.uid);
550
554
  return B.rollupItems(out);
551
555
  }
552
556
 
@@ -1228,11 +1232,14 @@ const WRITES = {
1228
1232
  const p = postFrame(ctx, res, body);
1229
1233
  if (!p) return;
1230
1234
  if (body.milestone != null && typeof body.milestone !== 'boolean') return fail(ctx, res, 400, 'milestone is true or false');
1235
+ if (body.pinned !== undefined && body.pinned !== null && typeof body.pinned !== 'boolean') return fail(ctx, res, 400, 'pinned is true, false, or null for the rule (the last milestone only)');
1236
+ const pinWas = (id) => { const PN = p.fr.folded.pins || new Map(); return PN.has(id) ? PN.get(id) : null; };
1237
+ const pinLine = (id) => ({ kind: 'task-pin', board: p.board.id, task: id, pinned: body.pinned, why: body.pinned === true ? 'pinned to the timeline' : body.pinned === false ? 'taken off the timeline' : 'pin back to the rule' });
1231
1238
  // a Jira ticket takes the milestone flag (feedback batch 11 item 3) and the PM's own start and due days, kept in PMOS only (item 23):
1232
1239
  // Jira keeps its title, status and assignee, and nothing is written to Jira
1233
1240
  if (typeof body.task === 'string' && B.JIRA_KEY_RE.test(body.task) && !B.taskOf(p.fr.folded, body.task)) {
1234
- if (['owner', 'notes', 'initiative', 'section'].some((k) => body[k] != null)) return fail(ctx, res, 409, 'Jira owns this ticket: only its dates and its milestone flag change here');
1235
- if (body.milestone == null && body.start == null && body.due == null) return fail(ctx, res, 400, 'nothing to change: send start, due or milestone');
1241
+ if (['owner', 'notes', 'initiative', 'section'].some((k) => body[k] != null)) return fail(ctx, res, 409, 'Jira owns this ticket: only its dates, its milestone flag and its pin change here');
1242
+ if (body.milestone == null && body.start == null && body.due == null && body.pinned === undefined) return fail(ctx, res, 400, 'nothing to change: send start, due, milestone or pinned');
1236
1243
  for (const k of ['start', 'due']) if (body[k] != null && body[k] !== '' && !/^\d{4}-\d{2}-\d{2}$/.test(String(body[k]))) return fail(ctx, res, 400, `${k} is a day, YYYY-MM-DD, or '' for none`);
1237
1244
  if (!p.file) return fail(ctx, res, 409, NO_STATE);
1238
1245
  const from = {}, ref = body.task.toUpperCase();
@@ -1249,6 +1256,7 @@ const WRITES = {
1249
1256
  from.milestone = !!MS0.get(body.task);
1250
1257
  append(p.file, g.actor, { kind: 'task-milestone', board: p.board.id, task: body.task, milestone: body.milestone, why: body.milestone ? 'made a milestone' : 'no longer a milestone' });
1251
1258
  }
1259
+ if (body.pinned !== undefined) { from.pinned = pinWas(body.task); append(p.file, g.actor, pinLine(body.task)); }
1252
1260
  return ctx.json(res, { ok: true, from, item: null });
1253
1261
  }
1254
1262
  const t0 = B.taskOf(p.fr.folded, body.task);
@@ -1298,9 +1306,13 @@ const WRITES = {
1298
1306
  const MS0 = p.fr.folded.milestones || new Map();
1299
1307
  ms = body.milestone; from.milestone = MS0.has(t.id) ? MS0.get(t.id) : !!t.milestone;
1300
1308
  }
1301
- if (!Object.keys(ev).length && sec == null && ms == null) return fail(ctx, res, 400, 'nothing to change: send owner, notes, start, due, initiative, section or milestone');
1309
+ // the pin (batch 13 item 4): a board-ledger line like the milestone flag
1310
+ const pin = body.pinned !== undefined;
1311
+ if (pin) { if (!p.file) return fail(ctx, res, 409, NO_STATE); from.pinned = pinWas(t.id); }
1312
+ if (!Object.keys(ev).length && sec == null && ms == null && !pin) return fail(ctx, res, 400, 'nothing to change: send owner, notes, start, due, initiative, section, milestone or pinned');
1302
1313
  if (sec != null) append(p.file, g.actor, { kind: 'task-section', board: p.board.id, task: t.id, section: sec, why: sec ? 'placed under ' + sec : 'placed under no stage' });
1303
1314
  if (ms != null) append(p.file, g.actor, { kind: 'task-milestone', board: p.board.id, task: t.id, milestone: ms, why: ms ? 'made a milestone' : 'no longer a milestone' });
1315
+ if (pin) append(p.file, g.actor, pinLine(t.id));
1304
1316
  if (!Object.keys(ev).length) {
1305
1317
  const items = itemsOf(p.w, { ...p.fr, folded: B.fold(readLedger(ctx, p.w)) }, p.board, (needRows(ctx, res, p.w) || []).filter((r) => r.id === t.initiative));
1306
1318
  return ctx.json(res, { ok: true, from, item: items.find((x) => x.uid === t.id) || null });
@@ -73,7 +73,9 @@ function todayAgenda(events, items, now, notes = {}) {
73
73
  const before = open.filter((i) => (i.meeting_id && i.meeting_id === e.id) || (i.event_id && i.event_id === e.id) || (t.length >= 6 && norm(i.title).includes(t)))
74
74
  .map((i) => ({ id: i.id, title: i.title, due: i.due || null, done: !!i.done }));
75
75
  return { id: e.id, title: e.title, start: s.toISOString(), end: new Date(endMs).toISOString(), startLocal: hhmm(s), minutes: Math.max(0, Math.round((endMs - s.getTime()) / 60000)),
76
- people: Array.isArray(e.attendees) ? e.attendees.slice(0, 12) : [], initiative: e.initiative || null, prepared, before, _s: s.getTime(), _e: endMs };
76
+ people: Array.isArray(e.attendees) ? e.attendees.slice(0, 12) : [],
77
+ // the link the PM set on the meeting (lib/calendar-links.js, every occurrence of it) wins; Home's clean-up writes one (batch 13 item 3)
78
+ initiative: (notes.linkOf && notes.linkOf(e)) || e.initiative || null, ...(e.series ? { series: String(e.series).slice(0, 300) } : {}), prepared, before, _s: s.getTime(), _e: endMs };
77
79
  });
78
80
  let nextDone = false;
79
81
  for (const r of rows) {
@@ -212,7 +214,13 @@ function build(query, deps = {}) {
212
214
  function notesAdapter(runtimeDir) {
213
215
  let notes; try { notes = require('./notes.js'); } catch { return {}; }
214
216
  const rows = () => { try { const l = notes.list(runtimeDir); return l && l.ok ? l.notes.filter((n) => !n.private) : []; } catch { return []; } };
217
+ let links = null;
215
218
  return {
219
+ linkOf: (e) => {
220
+ if (!links) { try { links = require('./calendar-links.js').read(runtimeDir); } catch { links = new Map(); } }
221
+ const l = links.get(require('./calendar-links.js').keyOf(e));
222
+ return l && l.kind === 'initiative' ? l.initiative : null;
223
+ },
216
224
  findByEvent: (e) => { try { const n = notes.findByEvent(runtimeDir, { event_id: e.id, start: e.at, title: e.title }); return n && !n.private ? { id: n.id, title: n.title || 'Untitled note' } : null; } catch { return null; } },
217
225
  lastBefore: (e) => {
218
226
  const t = norm(e.title);
@@ -245,6 +245,25 @@ module.exports = {
245
245
  if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
246
246
  return post(req, res, url, ctx);
247
247
  }
248
+ if (url.pathname === '/api/briefing-premium/products') {
249
+ // the one product pick Home, Board and Insights share (batch 12 item 5): GET every registered product with on; POST { on: [ws…] } saves the ticks
250
+ // primary: the workspace a page opens with no ws (Home's own board), so every page tints the tiles in the same order
251
+ let def = null; try { def = ctx.getWs ? ctx.getWs(null) : null; } catch { def = null; }
252
+ // with no pick saved (the default), the workspace a page opens with stays ticked, as every page showed it before the pick
253
+ const pub = (sel) => { const chosen = Array.isArray(settings.get(ctx.runtimeDir, 'ws.briefing.include', null)); return { ok: true, all: !!sel.all, chosen, products: sel.available.map((a) => { const primary = !!def && def.id === a.ws; return { ws: a.ws, name: a.name, home: a.home, primary, initials: a.initials || null, on: a.on || (!chosen && primary) }; }) }; };
254
+ if (req.method === 'GET') { ctx.json(res, pub(products(ctx))); return true; }
255
+ if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'GET or POST only' }, 405); return true; }
256
+ const got = await ctx.readJson(req);
257
+ if (!got.ok || !got.body || typeof got.body !== 'object' || !Array.isArray(got.body.on)) { ctx.json(res, { ok: false, error: 'body must be JSON with on, the ticked workspace ids' }, 400); return true; }
258
+ const g = guard.requirePagePress(req, got.body);
259
+ if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
260
+ const v = Prod.pickFor(products(ctx).available, got.body.on);
261
+ if (v.error) { ctx.json(res, { ok: false, error: v.error }, 400); return true; }
262
+ const w = v.value === null ? settings.reset(ctx.runtimeDir, 'ws.briefing.include') : settings.set(ctx.runtimeDir, 'ws.briefing.include', v.value);
263
+ if (!w || w.ok === false) { ctx.json(res, { ok: false, error: (w && w.error) || 'the pick was not saved' }, 500); return true; }
264
+ ctx.json(res, pub(products(ctx)));
265
+ return true;
266
+ }
248
267
  if (url.pathname === '/api/briefing-premium/goals') { // premium-session-list L1: every conversation's goal state, for the session list's Goals group
249
268
  if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
250
269
  ctx.json(res, { ok: true, goals: ctx.runtimeDir ? Goal.statesAt(ctx.runtimeDir) : {} });
@@ -0,0 +1,210 @@
1
+ 'use strict';
2
+ /* routes-loose.js — Claude's clean-up of Home's "Not in an initiative" (feedback batch 13 item 3, option A; canvas In development, XlcA0Grill to
3
+ * XlcA4Pick). The fold and the view are lib/loose-proposals.js. Every write goes through the store that already holds it: a chat's initiative
4
+ * through the session record (ctx.looseSessions, the same field POST /api/session/initiative sets), the PM's own item through pm-items' edit
5
+ * (routes-pm-items pressAs), a meeting through lib/calendar-links.js (every occurrence of it), a new initiative through the Board's own Add an
6
+ * ask and Accept (routes-boards writeAs). Nothing is written before the PM's ✓ (rule 12), and nothing is deleted: a chat put away keeps its
7
+ * transcript, Search finds it, and the PM's next message in it brings it back (rule 10).
8
+ *
9
+ * GET /api/loose-props → { ok, props, history, sig } sig: the page's signature of the rows it last sent props: lib/loose-proposals.js viewOf (null: nothing to show)
10
+ * POST /api/loose-props/rows { rows, inis, today? } → { ok, props, history } what Home shows loose now and the open initiatives it knows;
11
+ * when the group passed 10 rows Claude looks at once (rule 7)
12
+ * POST /api/loose-props/close { sid } → closes one session that is idle and safe (the pill menu's ✓); { batch, said } for Undo
13
+ * POST /api/loose-props/keep { ids?: [id] | all: true, out?: [row], choices?: { <row>: { ini, title?, ws? } | { new: true, ws, board, anchor } },
14
+ * where?: { ws, board }, today? } → { ok, batch, said, props, history } ✓ on one proposal, or the header's ✓
15
+ * (all). A row's tile can name another initiative or a new one (rule 1); `out` are rows left out (✕)
16
+ * POST /api/loose-props/drop { scope, rows } → { ok } ✕: those rows are not proposed again in that group (rule 6)
17
+ * POST /api/loose-props/undrop { scope, rows } → { ok } the Undo of a row's ✕
18
+ * POST /api/loose-props/undo { batch } → { ok, back, kept } one approval, from the toast or the History fold (rule 9)
19
+ * POST /api/loose-props/look { } → { ok, started } Claude looks now
20
+ * Every POST passes pm-guard requirePagePress. */
21
+ const LP = require('./loose-proposals.js');
22
+ const guard = require('./pm-guard.js');
23
+
24
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
25
+ const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/;
26
+ const fail = (ctx, res, status, error) => { ctx.json(res, { ok: false, error }, status); return true; };
27
+ const pad = (n) => String(n).padStart(2, '0');
28
+ const localDay = (d = new Date()) => d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate());
29
+ const dayOf = (body) => (body && /^\d{4}-\d{2}-\d{2}$/.test(String(body.today || '')) ? String(body.today) : localDay());
30
+
31
+ function viewNow(ctx, dir, today) {
32
+ const snap = LP.readRows(dir), F = LP.read(dir);
33
+ const inis = snap.inis.length ? new Map(snap.inis.map((i) => [i.id, i])) : null;
34
+ const closable = ctx.looseSessions && ctx.looseSessions.closable ? (() => { try { return ctx.looseSessions.closable(); } catch { return []; } })() : [];
35
+ return { props: LP.viewOf(F, snap.rows, { today, inis, closable }), history: LP.historyOf(F).slice(0, 20), sig: snap.sig };
36
+ }
37
+
38
+ /* ── the writes, each with what it was before ── */
39
+ const CL = () => require('./calendar-links.js');
40
+ const PMI = () => require('./routes-pm-items.js');
41
+ function linkRow(ctx, row, ini, g) {
42
+ if (row.kind === 'session') {
43
+ if (!ctx.looseSessions) return null;
44
+ const prev = ctx.looseSessions.bind(row.sids, row.key || null, ini.id);
45
+ return prev.length ? { op: 'bind', row: row.id, sids: row.sids, ...(row.key ? { key: row.key } : {}), ini: ini.id, prev } : null;
46
+ }
47
+ if (row.kind === 'item') {
48
+ const was = PMI().itemOf(ctx, row.item);
49
+ const r = PMI().pressAs(ctx, 'POST /api/pm-items/edit', { id: row.item, fields: { initiative: ini.id } });
50
+ return r.status === 200 ? { op: 'item', row: row.id, item: row.item, ini: ini.id, prev: (was && was.initiative) || null } : null;
51
+ }
52
+ if (row.kind === 'meeting') {
53
+ const prev = CL().read(ctx.runtimeDir).get(CL().keyOf(row.event)) || null;
54
+ const r = CL().append(ctx.runtimeDir, { event: row.event, kind: 'initiative', initiative: ini.id, ...(ini.ws ? { ws: ini.ws } : {}), title: ini.title }, g.actor && g.actor.by);
55
+ return r.ok ? { op: 'meet', row: row.id, event: row.event, ini: ini.id, ...(ini.ws ? { ws: ini.ws } : {}), prev } : null;
56
+ }
57
+ return null;
58
+ }
59
+ function awayRow(ctx, row, why, into) {
60
+ if (row.kind !== 'session' || !ctx.looseSessions) return null;
61
+ const v = { at: new Date().toISOString(), why, ...(into ? { into } : {}) };
62
+ const ids = ctx.looseSessions.away(row.sids, row.key || null, v);
63
+ return ids.length ? { op: 'away', row: row.id, sids: row.sids, ...(row.key ? { key: row.key } : {}), why, ...(into ? { into } : {}) } : null;
64
+ }
65
+ /** Closes a session that is still idle and safe (batch 13 item 7). The server checks again: one that woke up or got work since is held. */
66
+ function closeRow(ctx, x) {
67
+ if (!ctx.looseSessions || !ctx.looseSessions.close) return { error: 'Sessions cannot be closed here' };
68
+ const r = ctx.looseSessions.close(x.sids || [], x.key || null, { at: new Date().toISOString(), why: 'closed' });
69
+ if (!r.closed.length) return { error: (r.held[0] && r.held[0].say) || 'It is no longer idle' };
70
+ return { op: 'close', row: x.row, sids: r.closed, ...(x.key ? { key: x.key } : {}), title: x.title };
71
+ }
72
+ /** A new initiative from rows (rule 11, and a tile's "+ New initiative from this row"): the Board's own Add an ask and Accept. → { id, write } | { error } */
73
+ function createIni(ctx, g, at, title, anchor, intent) {
74
+ const RB = require('./routes-boards.js');
75
+ if (!at || !ID_RE.test(String(at.ws || '')) || !ID_RE.test(String(at.board || ''))) return { error: 'the product to start it in is not known' };
76
+ if (!anchor) return { error: 'a new initiative needs what it counts toward' };
77
+ const a = RB.writeAs(ctx, '/api/boards/asks/add', { ws: at.ws, board: at.board, line: String(title).slice(0, 480), source: 'Home clean-up, approved by you' }, g);
78
+ if (!a.body || !a.body.ok) return { error: (a.body && a.body.error) || 'the ask was not added' };
79
+ const r = RB.writeAs(ctx, '/api/boards/asks/accept', { ws: at.ws, board: at.board, ask: a.body.ask.id, title, lane: 'feature', anchor, ...(intent ? { intent } : {}) }, g);
80
+ if (!r.body || !r.body.ok) return { error: (r.body && r.body.error) || 'the initiative was not started' };
81
+ const id = r.body.initiative && r.body.initiative.id;
82
+ return { id, write: { op: 'create', ini: id, title, ws: at.ws, board: at.board, stage: r.body.stage || '' } };
83
+ }
84
+
85
+ const WRITES = {
86
+ '/api/loose-props/rows': (ctx, res, body, g, dir) => {
87
+ if (!Array.isArray(body.rows)) return fail(ctx, res, 400, 'rows is the list Home shows under "Not in an initiative"');
88
+ const s = LP.saveRows(dir, body.rows, Date.now(), Array.isArray(body.inis) ? body.inis : undefined, body.sig);
89
+ // rule 7: the group passed 10 rows, so Claude looks now, not tomorrow morning
90
+ if (s.over10 && ctx.proposalRuns && ctx.proposalRuns.looseDue) {
91
+ try { if (ctx.proposalRuns.looseDue(Date.now(), false) === 'many') ctx.proposalRuns.startLoose({ why: 'many', press: false }); } catch { /* the tick tries again */ }
92
+ }
93
+ ctx.json(res, { ok: true, ...viewNow(ctx, dir, dayOf(body)) });
94
+ },
95
+ '/api/loose-props/keep': (ctx, res, body, g, dir) => {
96
+ const today = dayOf(body), v = viewNow(ctx, dir, today).props;
97
+ const all = v ? v.groups.flatMap((x) => x.props) : [];
98
+ const ids = Array.isArray(body.ids) ? body.ids.filter((x) => typeof x === 'string').slice(0, 60) : [];
99
+ if (!ids.length && body.all !== true) return fail(ctx, res, 400, 'ids names the proposals to approve, or all: true');
100
+ const want = body.all === true ? all : all.filter((p) => ids.includes(p.id));
101
+ if (!want.length) return fail(ctx, res, 409, 'Those proposals are no longer open');
102
+ const out = new Set(Array.isArray(body.out) ? body.out.filter((x) => typeof x === 'string') : []);
103
+ const choices = isObj(body.choices) ? body.choices : {};
104
+ const snap = LP.readRows(dir), byId = new Map(snap.rows.map((r) => [r.id, r])), inis = new Map(snap.inis.map((i) => [i.id, i]));
105
+ const wrote = [], keptIds = [], errors = [];
106
+ const made = new Map(); // one new initiative per title, so a start and a tile's "new" do not make two
107
+ const newIni = (title, at, anchor, intent) => {
108
+ const k = String(title).toLowerCase(); if (made.has(k)) return made.get(k);
109
+ const r = createIni(ctx, g, at, title, anchor, intent);
110
+ if (r.error) { errors.push(r.error); made.set(k, null); return null; }
111
+ wrote.push(r.write); const ini = { id: r.id, title, ws: at.ws }; made.set(k, ini); return ini;
112
+ };
113
+ for (const p of want) {
114
+ let any = false;
115
+ for (const x of p.rows) {
116
+ const row = p.type === 'close' ? x : byId.get(x.row); if (!row || out.has(row.id || row.row)) continue;
117
+ let w = null;
118
+ if (p.type === 'ini' || p.type === 'new') {
119
+ // rule 1: the row's tile may name another initiative, or a new one from this row
120
+ const c = isObj(choices[row.id]) ? choices[row.id] : null;
121
+ let ini = null;
122
+ if (c && c.new === true) ini = newIni(row.title, { ws: c.ws, board: c.board }, String(c.anchor || ''), '');
123
+ else if (c && ID_RE.test(String(c.ini || ''))) ini = inis.get(c.ini) || { id: c.ini, title: String(c.title || c.ini).slice(0, 140), ...(c.ws ? { ws: String(c.ws) } : {}) };
124
+ else if (p.type === 'ini') ini = inis.get(p.data.ini) || { id: p.data.ini, title: p.data.title || p.data.ini, ...(p.data.ws ? { ws: p.data.ws } : {}) };
125
+ else ini = newIni(p.data.title, isObj(body.where) ? body.where : null, p.data.anchor, p.data.why);
126
+ if (ini) w = linkRow(ctx, row, ini, g);
127
+ } else if (p.type === 'merge') w = awayRow(ctx, row, 'merged', p.data.into);
128
+ else if (p.type === 'finish') w = awayRow(ctx, row, 'done');
129
+ else if (p.type === 'away') w = awayRow(ctx, row, 'idle');
130
+ else if (p.type === 'close') { const c = closeRow(ctx, row); if (c.error) errors.push(c.error); else w = c; }
131
+ if (w) { wrote.push({ ...w, why: p.why, group: p.type }); any = true; }
132
+ }
133
+ if (any) keptIds.push(p.id);
134
+ }
135
+ if (!wrote.length) return fail(ctx, res, 409, errors[0] || 'Nothing could be placed');
136
+ const batch = LP.newBatch(), said = LP.saidOf(wrote);
137
+ LP.append(dir, g.actor, { kind: 'keep', batch, ids: keptIds, said, wrote });
138
+ ctx.json(res, { ok: true, batch, said, ...(errors.length ? { warn: errors[0] } : {}), ...viewNow(ctx, dir, today) });
139
+ },
140
+ // the pill menu's ✓ on one session (batch 13 item 7): the same keep, for one row of the close proposal
141
+ '/api/loose-props/close': (ctx, res, body, g, dir) => {
142
+ const sid = String(body.sid || '');
143
+ const c = (ctx.looseSessions && ctx.looseSessions.closable ? ctx.looseSessions.closable() : []).find((x) => x.sid === sid);
144
+ if (!c) return fail(ctx, res, 409, 'That session is no longer idle and safe to close');
145
+ const row = LP.closeOf([c]).rows[0];
146
+ const w = closeRow(ctx, row);
147
+ if (w.error) return fail(ctx, res, 409, w.error);
148
+ const batch = LP.newBatch(), said = 'Closed "' + row.title + '". Its transcript is kept';
149
+ LP.append(dir, g.actor, { kind: 'keep', batch, ids: ['lp-close'], said, wrote: [{ ...w, why: 'pill', group: 'close' }] });
150
+ ctx.json(res, { ok: true, batch, said, ...viewNow(ctx, dir, dayOf(body)) });
151
+ },
152
+ '/api/loose-props/drop': (ctx, res, body, g, dir) => dropLine(ctx, res, body, g, dir, 'drop'),
153
+ '/api/loose-props/undrop': (ctx, res, body, g, dir) => dropLine(ctx, res, body, g, dir, 'undrop'),
154
+ '/api/loose-props/undo': (ctx, res, body, g, dir) => {
155
+ const F = LP.read(dir), id = String(body.batch || ''), k = F.kept.find((x) => x.batch === id);
156
+ if (!k || F.undone.has(id)) return fail(ctx, res, 409, 'Nothing to undo');
157
+ let back = 0, kept = 0;
158
+ for (const w of k.wrote.slice().reverse()) {
159
+ try {
160
+ if (w.op === 'bind' && ctx.looseSessions) { for (const p of w.prev || []) ctx.looseSessions.bind([p.sid], null, p.ini); back++; }
161
+ else if (w.op === 'item') { const r = PMI().pressAs(ctx, 'POST /api/pm-items/edit', { id: w.item, fields: { initiative: w.prev || null } }); if (r.status === 200) back++; else kept++; }
162
+ else if (w.op === 'meet') {
163
+ const p = w.prev;
164
+ const r = CL().append(ctx.runtimeDir, p ? { event: w.event, kind: p.kind, ...(p.ws ? { ws: p.ws } : {}), ...(p.board ? { board: p.board } : {}), ...(p.initiative ? { initiative: p.initiative } : {}), ...(p.title ? { title: p.title } : {}) } : { event: w.event, kind: 'none' }, g.actor && g.actor.by);
165
+ if (r.ok) back++; else kept++;
166
+ } else if ((w.op === 'away' || w.op === 'close') && ctx.looseSessions) { ctx.looseSessions.away(w.sids, w.key || null, null); back++; } // a closed chat is back on Home and resumes on its next message
167
+ else if (w.op === 'create') kept++; // a started initiative stays: close it on the Board if it should not be there
168
+ } catch { kept++; }
169
+ }
170
+ LP.append(dir, g.actor, { kind: 'undo', batch: id });
171
+ ctx.json(res, { ok: true, back, kept, ...viewNow(ctx, dir, dayOf(body)) });
172
+ },
173
+ '/api/loose-props/look': (ctx, res, body, g) => {
174
+ if (!ctx.proposalRuns || !ctx.proposalRuns.startLoose) return fail(ctx, res, 503, 'Claude\'s runs are off on this server');
175
+ const r = ctx.proposalRuns.startLoose({ why: 'check', press: true });
176
+ if (!r || !r.ok) return fail(ctx, res, 409, (r && r.error) || 'Claude could not start looking');
177
+ ctx.json(res, { ok: true, started: r.run });
178
+ },
179
+ };
180
+ function dropLine(ctx, res, body, g, dir, kind) {
181
+ const scope = ['link', 'tidy', 'start'].includes(body.scope) ? body.scope : null;
182
+ const rows = Array.isArray(body.rows) ? body.rows.filter((x) => typeof x === 'string' && /^(c|s|w|m):/.test(x)).slice(0, 60) : [];
183
+ if (!scope || !rows.length) return fail(ctx, res, 400, 'scope is link, tidy or start; rows names the rows');
184
+ LP.append(dir, g.actor, { kind, scope, rows });
185
+ ctx.json(res, { ok: true });
186
+ }
187
+
188
+ module.exports = {
189
+ prefixes: ['/api/loose-props'],
190
+ handle: async (req, res, url, ctx) => {
191
+ const p = url.pathname;
192
+ const dir = LP.dirOf(ctx.runtimeDir);
193
+ if (req.method === 'GET') {
194
+ if (p !== '/api/loose-props') return fail(ctx, res, 404, 'not found');
195
+ if (!dir) { ctx.json(res, { ok: true, props: null, history: [] }); return true; }
196
+ ctx.json(res, { ok: true, ...viewNow(ctx, dir, /^\d{4}-\d{2}-\d{2}$/.test(url.searchParams.get('today') || '') ? url.searchParams.get('today') : localDay()) });
197
+ return true;
198
+ }
199
+ if (req.method !== 'POST') return fail(ctx, res, 405, 'GET or POST only');
200
+ const fn = WRITES[p];
201
+ if (!fn) return fail(ctx, res, 404, 'not found');
202
+ const got = await ctx.readJson(req);
203
+ if (!got.ok || !isObj(got.body)) return fail(ctx, res, 400, 'the body must be a JSON object');
204
+ const g = guard.requirePagePress(req, got.body);
205
+ if (!g.ok) return fail(ctx, res, g.status, g.error);
206
+ if (!dir) return fail(ctx, res, 409, 'PMOS has no runtime folder');
207
+ fn(ctx, res, got.body, g, dir);
208
+ return true;
209
+ },
210
+ };
@@ -2,7 +2,7 @@
2
2
  /* routes-meeting-focus.js — the Meeting focus page's server side (initiative c3-meeting-focus; lib/route-modules.js).
3
3
  *
4
4
  * GET /api/meeting-focus?event=<id>&date=YYYY-MM-DD[&ws=]
5
- * → { ok, now_ms, event, brief, material, note, topics, current, runs, tail, captured, gist, chips, notes, asks, companion }
5
+ * → { ok, now_ms, event, brief, material, note, topics, current, runs, tail, captured, gist, chips, notes, raise, asks, companion }
6
6
  * The meeting (the calendar read for that day), its brief (lib/calendar-layers.js briefOf), the note linked to it, the last
7
7
  * minutes of that note's transcript with who said them, the decisions, actions and questions so far, and the companion's state.
8
8
  * An unknown meeting is a 404. The read also starts the companion when lib/meeting-focus.js shouldRun says it may: the note
@@ -13,10 +13,11 @@
13
13
  * (lib/meeting-focus.js pickNow). It reads the same calendar as the read above and writes nothing.
14
14
  * POST /api/meeting-focus/topic { event | note, date?, action: 'set'|'add'|'park', topic } page press; the PM's correction, appended to the state
15
15
  * POST /api/meeting-focus/ask { event, note?, date?, question } page press; one headless read-only run with the PM's question
16
+ * POST /api/meeting-focus/raise { event | note, date?, id, action: 'raised'|'skip' } page press; the PM's ✓ or ✗ on a Raise now item (the recording tab's Now panel)
16
17
  * GET /api/meeting-focus/ask?id= → { ok, id, state: working | answered | failed, error? } the answer itself comes back as a note in GET /api/meeting-focus
17
18
  *
18
19
  * The companion runs as origin `focus-companion:<key>` (lib/headless.js 'ask': Read, Glob and Grep only). It sends nothing to anyone and
19
- * writes nothing: its answer is parsed here and appended to <runtimeDir>/focus/<note id or event id>.jsonl. Handlers are pure over
20
+ * writes nothing. It reads the talk, the brief and the text of the latest shots of the shared screen (never a private note's). Its answer is parsed here and appended to <runtimeDir>/focus/<note id or event id>.jsonl. Handlers are pure over
20
21
  * (req, body, ctx): ctx = { runtimeDir, spawnSession, w, readEvents?, briefFor?, env?, now? }, so a test needs no server.
21
22
  */
22
23
  const fs = require('fs');
@@ -137,11 +138,18 @@ function settleRun(ctx, key, done, now) {
137
138
  return append(ctx.runtimeDir, key + '.jsonl', F.outLine(parsed, at));
138
139
  }
139
140
 
141
+ /** The shots of the shared screen the companion may read: none for a private note. */
142
+ function framesOf(runtimeDir, note) {
143
+ if (!note || note.private) return [];
144
+ try { return require('./notes-screen.js').list(runtimeDir, note.id); } catch { return []; }
145
+ }
140
146
  function inputFor(ctx, ev, brief, note, state, topics, question) {
141
147
  const now = ctx.nowMs;
142
148
  const names = new Map(state.topics.map((t) => [t.id, t.text]));
149
+ const frames = framesOf(ctx.runtimeDir, note);
143
150
  return { event: ev, brief: brief || {}, topics: state.topics.length ? state.topics : topics, current: state.current ? names.get(state.current) : null,
144
- tail: note ? F.tailOf(note, { now }) : [], earlier: state.notes, question: question || null, now };
151
+ tail: note ? F.tailOf(note, { now }) : [], earlier: state.notes, question: question || null, now,
152
+ screen: F.screenOf(frames), shots: frames.length, raised: state.raised || [] };
145
153
  }
146
154
 
147
155
  function startRun(ctx, key, ev, brief, note, state, topics, now) {
@@ -206,7 +214,7 @@ async function read(q, ctx) {
206
214
  note: note ? { id: note.id, title: note.title || ev.title, state: note.state, recorded_from: note.recorded_from || null, lines: (note.transcript || []).length, sessions } : null,
207
215
  topics: fresh.topics, current: fresh.current, runs: fresh.runs,
208
216
  tail: note ? F.tailOf(note, { now: nowMs }) : [], captured: F.capturedFrom(note),
209
- gist: fresh.gist, chips: fresh.chips, notes: fresh.notes, asks: fresh.asks,
217
+ gist: fresh.gist, chips: fresh.chips, notes: fresh.notes, raise: fresh.raise, asks: fresh.asks,
210
218
  companion: { on: !F.off(env) && kindOk() && typeof ctx.spawnSession === 'function', running: !!fresh.pending, started, reason: call.reason, last_run_at: fresh.last_run_at || null, error: fresh.error },
211
219
  } };
212
220
  }
@@ -235,6 +243,20 @@ async function topic(req, body, ctx) {
235
243
  append(ctx.runtimeDir, key.key + '.jsonl', F.moveLine(action, text, now));
236
244
  return { status: 200, body: { ok: true, key: key.key } };
237
245
  }
246
+ /* ── POST /api/meeting-focus/raise ────────────────────────────────────────────────────────────────────────────────── */
247
+
248
+ async function raise(req, body, ctx) {
249
+ const g = guard.requirePagePress(req, body); if (!g.ok) return fail(g.status, g.error);
250
+ const action = String(body.action || '');
251
+ if (!['raised', 'skip'].includes(action)) return fail(400, 'action must be raised or skip');
252
+ const id = F.str(body.id, 80);
253
+ if (!id) return fail(400, 'id is required');
254
+ const key = await keyFromBody(body, ctx); if (key.error) return key.error;
255
+ const now = typeof ctx.now === 'function' ? ctx.now() : Date.now();
256
+ append(ctx.runtimeDir, key.key + '.jsonl', F.raiseLine(id, action, now));
257
+ return { status: 200, body: { ok: true, key: key.key } };
258
+ }
259
+
238
260
  /** The state file a body names: its note, else its event. */
239
261
  async function keyFromBody(body, ctx) {
240
262
  if (body.note) {
@@ -320,7 +342,7 @@ const respond = (ctx, res, r) => { ctx.json(res, r.body, r.status); return true;
320
342
 
321
343
  module.exports = {
322
344
  prefixes: ['/api/meeting-focus'],
323
- read, now: nowRoute, topic, ask, askState, settleAsk, settleRun, findEvent, keyOf, linesOf, noteFor, noteEvent, realBrief,
345
+ read, now: nowRoute, topic, raise, ask, askState, settleAsk, settleRun, findEvent, keyOf, linesOf, noteFor, noteEvent, realBrief,
324
346
  handle: async (req, res, url, ctx) => {
325
347
  const p = url.pathname;
326
348
  const wsId = url.searchParams.get('ws');
@@ -329,7 +351,7 @@ module.exports = {
329
351
  if (req.method === 'GET' && p === '/api/meeting-focus') return respond(ctx, res, await read(Object.fromEntries(url.searchParams), base));
330
352
  if (req.method === 'GET' && p === '/api/meeting-focus/now') return respond(ctx, res, nowRoute(Object.fromEntries(url.searchParams), base));
331
353
  if (req.method === 'GET' && p === '/api/meeting-focus/ask') return respond(ctx, res, askState(Object.fromEntries(url.searchParams), base));
332
- const fn = req.method === 'POST' && { '/api/meeting-focus/topic': topic, '/api/meeting-focus/ask': ask }[p];
354
+ const fn = req.method === 'POST' && { '/api/meeting-focus/topic': topic, '/api/meeting-focus/raise': raise, '/api/meeting-focus/ask': ask }[p];
333
355
  if (!fn) return false;
334
356
  const got = await ctx.readJson(req);
335
357
  if (!got.ok) return respond(ctx, res, fail(400, 'invalid JSON body'));
@@ -10,7 +10,8 @@
10
10
  * GET /api/pm-items?counts=1 → { ok, today, counts } the counts alone (the console's Work tab badge)
11
11
  * POST /api/pm-items/add { line } → { ok, item } one line: the parser (lib/pm-items.js) reads the parts
12
12
  * POST /api/pm-items/edit { id, fields }→ { ok, item } fields: title, due, priority, waiting_on, job,
13
- * defer, flagged, resolves, kind, person, evidence, outcome
13
+ * defer, flagged, resolves, kind, person, evidence, outcome, initiative (the initiative it belongs to:
14
+ * Home lists it under that initiative, not under "Not in an initiative"; batch 13 item 3)
14
15
  * POST /api/pm-items/remove { id } → { ok, undo_ms } deleted (created here) or dropped (imported)
15
16
  * POST /api/pm-items/undo { id } → { ok, item } | 409 restores the last removal inside the 8 s window
16
17
  * POST /api/pm-items/done { id, outcome?, how? } → { ok } folds to item.done + done_at (+ outcome, one line; + done_how: you|agent|confirmed); /reopen undoes it
@@ -51,8 +52,8 @@ const steps = require('./item-steps.js');
51
52
  const assigned = require('./work-assigned.js');
52
53
  const { repoScript } = require('./repo-script.js');
53
54
 
54
- const FIELDS = ['title', 'due', 'priority', 'waiting_on', 'job', 'defer', 'flagged', 'resolves', 'kind', 'person', 'evidence', 'outcome'];
55
- const STRING_OR_NULL = ['resolves', 'person', 'evidence', 'outcome'];
55
+ const FIELDS = ['title', 'due', 'priority', 'waiting_on', 'job', 'defer', 'flagged', 'resolves', 'kind', 'person', 'evidence', 'outcome', 'initiative'];
56
+ const STRING_OR_NULL = ['resolves', 'person', 'evidence', 'outcome', 'initiative'];
56
57
  const NOT_YET = ['later-today', 'tomorrow', 'next-week'];
57
58
  const JOB_FIELDS = ['when', 'want', 'so'];
58
59
  const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
@@ -147,6 +148,7 @@ function checkFields(fields, allowed) {
147
148
  if ('priority' in fields && fields.priority !== null && !/^P[1-3]$/.test(String(fields.priority))) return 'priority must be P1, P2, P3 or null';
148
149
  if ('defer' in fields && fields.defer !== null && !DATE_RE.test(String(fields.defer))) return 'defer must be YYYY-MM-DD or null';
149
150
  if ('flagged' in fields && typeof fields.flagged !== 'boolean') return 'flagged must be true or false';
151
+ if ('initiative' in fields && fields.initiative !== null && !/^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/.test(String(fields.initiative))) return 'initiative must be an initiative id or null';
150
152
  if ('kind' in fields && fields.kind !== null && fields.kind !== 'offline') return 'kind must be offline or null';
151
153
  for (const k of STRING_OR_NULL) {
152
154
  if (k in fields && fields[k] !== null && typeof fields[k] !== 'string') return `${k} must be a string or null`;
@@ -371,21 +373,29 @@ module.exports = {
371
373
  const body = got.body || {};
372
374
  const g = guard.requirePagePress(req, body);
373
375
  if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
374
- const c = prepare(ctx);
375
- // the first press on assigned or suggested work puts it in the PM's ledger, with its source, before the press itself
376
- if (typeof body.id === 'string' && VIRTUAL_ID.test(body.id) && !findItem(c.itemLines, body.id)) {
377
- const v = assigned.addable(assignedSync(ctx, c.now), c.itemLines).find((x) => x.id === body.id);
378
- if (v) { const ev = assigned.createdEvent(v); pmItems.appendEvent(itemsFile(ctx), ev, c.now); c.itemLines.push({ ...ev, at: c.now.toISOString() }); }
379
- }
380
- const r = ROUTES[key](body, c);
381
- if (r.status === 200 && r.events) {
382
- for (const ev of r.events) {
383
- const which = ev._file || r.file;
384
- const { _file, ...line } = ev;
385
- pmItems.appendEvent(which === 'jobs' ? jobsFile(ctx) : which === 'steps' ? stepsFile(ctx) : which === 'focus' ? focusFile(ctx) : itemsFile(ctx), line, c.now);
386
- }
387
- }
376
+ const r = pressAs(ctx, key, body);
388
377
  ctx.json(res, r.body, r.status);
389
378
  return true;
390
379
  },
391
380
  };
381
+ /** One press, as the page's POST runs it (the Home clean-up's ✓ links an item to an initiative through it, batch 13 item 3).
382
+ * key: 'POST /api/pm-items/<verb>'. The caller has checked the press. → { status, body } */
383
+ function pressAs(ctx, key, body) {
384
+ const c = prepare(ctx);
385
+ // the first press on assigned or suggested work puts it in the PM's ledger, with its source, before the press itself
386
+ if (typeof body.id === 'string' && VIRTUAL_ID.test(body.id) && !findItem(c.itemLines, body.id)) {
387
+ const v = assigned.addable(assignedSync(ctx, c.now), c.itemLines).find((x) => x.id === body.id);
388
+ if (v) { const ev = assigned.createdEvent(v); pmItems.appendEvent(itemsFile(ctx), ev, c.now); c.itemLines.push({ ...ev, at: c.now.toISOString() }); }
389
+ }
390
+ const r = ROUTES[key](body, c);
391
+ if (r.status === 200 && r.events) {
392
+ for (const ev of r.events) {
393
+ const which = ev._file || r.file;
394
+ const { _file, ...line } = ev;
395
+ pmItems.appendEvent(which === 'jobs' ? jobsFile(ctx) : which === 'steps' ? stepsFile(ctx) : which === 'focus' ? focusFile(ctx) : itemsFile(ctx), line, c.now);
396
+ }
397
+ }
398
+ return r;
399
+ }
400
+ module.exports.pressAs = pressAs;
401
+ module.exports.itemOf = (ctx, id) => findItem(prepare(ctx).itemLines, id) || null;
@@ -125,7 +125,8 @@ function validate(key, value) {
125
125
  if (typeof value !== 'string' || value.length > 64) return `${key} must be a time zone such as Asia/Jakarta, or empty for this computer's`;
126
126
  try { new Intl.DateTimeFormat('en', { timeZone: value }); return null; } catch { return `${value} is not a time zone this computer knows`; }
127
127
  }
128
- case 'ids': return value === null || Array.isArray(value) && value.length <= d.max && value.every((x) => typeof x === 'string' && WS_ID.test(x)) && new Set(value).size === value.length ? null : `${key} must list at most ${d.max} workspace ids, each once`;
128
+ // ['*'] alone is every workspace (the product picker's All, lib/briefing-premium-products.js)
129
+ case 'ids': return value === null || Array.isArray(value) && (value.length === 1 && value[0] === '*' || value.length <= d.max && value.every((x) => typeof x === 'string' && WS_ID.test(x)) && new Set(value).size === value.length) ? null : `${key} must list at most ${d.max} workspace ids, each once, or ['*'] for every one`;
129
130
  case 'templates': {
130
131
  if (!value || typeof value !== 'object' || Array.isArray(value)) return `${key} must name the templates`;
131
132
  const ids = Object.keys(value);