create-pmos 0.439.0 → 0.441.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 (66) hide show
  1. package/bin/create-pmos.js +5 -2
  2. package/package.json +25 -25
  3. package/payload/KIT-VERSION +1 -1
  4. package/payload/planning/evals/eval-calibration.md +1 -1
  5. package/payload/planning/okrs/health-budgets.md +1 -1
  6. package/payload/state/discoveries.md +1 -1
  7. package/workspace/briefing-premium-adddoc-test.js +16 -13
  8. package/workspace/briefing-premium-insights-test.js +1 -1
  9. package/workspace/briefing-premium-products-test.js +4 -4
  10. package/workspace/briefing-premium-sources-test.js +2 -2
  11. package/workspace/briefing-premium-test.js +29 -23
  12. package/workspace/changelog.json +24 -0
  13. package/workspace/guide/core-documents.md +2 -2
  14. package/workspace/guide/data-freshness.md +7 -5
  15. package/workspace/guide/home.md +4 -1
  16. package/workspace/guide/horizon-scan.md +1 -1
  17. package/workspace/guide/settings.md +2 -2
  18. package/workspace/lib/agent-inbox.js +20 -2
  19. package/workspace/lib/briefing-premium-sources.js +3 -0
  20. package/workspace/lib/briefing-premium.js +37 -7
  21. package/workspace/lib/driver-cli.js +1 -1
  22. package/workspace/lib/driver-run.js +15 -1
  23. package/workspace/lib/driver.js +31 -2
  24. package/workspace/lib/goal-status.js +2 -1
  25. package/workspace/lib/headless.js +18 -1
  26. package/workspace/lib/kit-update.js +2 -2
  27. package/workspace/lib/metric-draft-runs.js +10 -4
  28. package/workspace/lib/news-for-you.js +24 -9
  29. package/workspace/lib/pm-idle.js +12 -0
  30. package/workspace/lib/refresh.js +17 -8
  31. package/workspace/lib/routes-core-docs.js +1 -1
  32. package/workspace/lib/routes-metric-drafts.js +2 -2
  33. package/workspace/lib/routes-news.js +15 -1
  34. package/workspace/lib/routes-phone-day.js +6 -4
  35. package/workspace/need-shot.js +57 -0
  36. package/workspace/news-viewers-test.js +183 -0
  37. package/workspace/package-lock.json +2 -2
  38. package/workspace/package.json +1 -1
  39. package/workspace/premium-core-doc-issue-test.js +9 -8
  40. package/workspace/premium-phone-card-test.js +9 -6
  41. package/workspace/public/pm/bd-ini-panel.js +4 -11
  42. package/workspace/public/pm/cozy-ev.css +29 -0
  43. package/workspace/public/pm/cozy-live-pill.css +6 -0
  44. package/workspace/public/pm/cozy-news.js +186 -22
  45. package/workspace/public/pm/cozy-today.css +5 -0
  46. package/workspace/public/pm/cozy-viewer.js +4 -3
  47. package/workspace/public/pm/cozy-vw-shell.css +49 -0
  48. package/workspace/public/pm/home-adddoc.js +46 -26
  49. package/workspace/public/pm/home-app.js +137 -115
  50. package/workspace/public/pm/home-day.js +15 -11
  51. package/workspace/public/pm/home-draft.js +35 -23
  52. package/workspace/public/pm/home-ini.js +2 -2
  53. package/workspace/public/pm/home-need.js +336 -0
  54. package/workspace/public/pm/home-phone-card.js +4 -2
  55. package/workspace/public/pm/home-today.js +2 -2
  56. package/workspace/public/pm/home-work.js +51 -4
  57. package/workspace/public/pm/okr-list.js +8 -4
  58. package/workspace/public/pm/premium-insights.js +6 -5
  59. package/workspace/public/pm/small-vw.js +128 -0
  60. package/workspace/public/premium-intelligence.html +1 -1
  61. package/workspace/server.js +20 -11
  62. package/workspace/skills/initiative-drive.skill +4 -1
  63. package/workspace/test-lists/batch18-asks.json +5 -0
  64. package/workspace/test-lists/news-viewers.json +13 -0
  65. package/workspace/test-lists/small-viewers.json +5 -0
  66. package/workspace/test-run.js +3 -1
@@ -82,6 +82,16 @@ const skipped = { n: 0 };
82
82
  /** Two products can hold an initiative of the same name, so a lookup by id also names the workspace (none in a one-workspace read). */
83
83
  const idk = (x, id) => (x.ws || '') + '|' + id;
84
84
  const live = (i) => i && !i.accepted && !i.stopped && !i.legacy;
85
+ /** Who and what an ask's Viewer names (batch 18 item 2-A, OvA1Start): the initiative's name, its lane, its owner (the record's owner:) and the
86
+ * goal its anchor names (readInitiatives resolves it from the OKR files). A field the records do not hold is left out. */
87
+ const whoOf = (i) => {
88
+ const o = { title: clip(i.title, 120) };
89
+ if (i.lane) o.lane = i.lane;
90
+ if (i.fm && i.fm.owner) o.owner = clip(i.fm.owner, 60);
91
+ if (i.goal && i.goal.title) o.goal = i.goal;
92
+ if (i.ws) o.ws = i.ws;
93
+ return o;
94
+ };
85
95
 
86
96
  /* ── rows ─────────────────────────────────────────────────────────────────────────────────────────────────── */
87
97
  function blockedRows(f) {
@@ -97,7 +107,7 @@ function blockedRows(f) {
97
107
  prepared: st.next ? 'Next step: ' + clip(st.next, 140) : 'No next step is on record.',
98
108
  skip: 'If you skip: ' + m.skip,
99
109
  from: [i.id], stepKey: st.key, order: [-(i.blockers || []).length, i.id],
100
- detail: { id: i.id, step: st.key, rule: st.rule || null, next: st.next == null ? null : String(st.next), record: i.record || null },
110
+ detail: { id: i.id, step: st.key, rule: st.rule || null, next: st.next == null ? null : String(st.next), record: i.record || null, ...whoOf(i) },
101
111
  dialog: tryD(() => ({
102
112
  eye: 'Unblock', logTitle: 'Read from the repository',
103
113
  log: ['Read the initiative record' + (i.record ? ' (' + i.record + ')' : ''), 'Ran the workflow order rules on it', 'Found the step that blocks it: ' + st.key],
@@ -132,7 +142,7 @@ function decisionRows(f) {
132
142
  prepared: 'No recommendation is on record.',
133
143
  skip: 'If you skip: ' + (mt ? 'the ' + hhmm(mt.start) + ' ' + mt.title + ' runs without a disposition.' : 'the prototype stays without a disposition.'),
134
144
  hero: 'the ' + shortName(i.title) + ' waits for your call', from: [i.id].concat(mt ? ['meeting:' + mt.title] : []),
135
- detail: { id: i.id, record: i.record || null },
145
+ detail: { id: i.id, record: i.record || null, ...whoOf(i), ...(mt ? { meeting: { at: hhmm(mt.start), title: mt.title } } : {}) },
136
146
  dialog: tryD(() => ({
137
147
  eye: 'Decide with evidence', logTitle: 'Read from the repository',
138
148
  log: ['Read the initiative record' + (i.record ? ' (' + i.record + ')' : ''), 'Checked the prototype lane rule (D60): a prototype needs your disposition', f.meetings === null ? 'The calendar could not be read, so no meeting was looked for' : mt ? 'Found a meeting that needs it: ' + hhmm(mt.start) + ' ' + mt.title : 'Looked for a meeting that needs it: none found'],
@@ -155,7 +165,7 @@ function decisionRows(f) {
155
165
  kind: 'decision', key: 'decision:' + t.id, title: 'Decide what the missed ' + t.id + ' date means', subject: clip(t.name, 90),
156
166
  prepared: 'No recommendation is on record.', skip: 'If you skip: no decision is on record and the tripwire stays fired.',
157
167
  hero: 'the ' + clip(short, 40) + ' tripwire missed its date', from: ['tripwire:' + t.id],
158
- detail: { id: t.id, date: t.date },
168
+ detail: { id: t.id, date: t.date, title: clip(short, 90) },
159
169
  dialog: tryD(() => ({
160
170
  eye: 'Decide with evidence', logTitle: 'Read from the repository',
161
171
  log: ['Read the kill condition (planning/okrs/kill-conditions.md · ' + t.id + ')', 'Checked pm-decisions.md for an entry on or after ' + t.date, 'Found none'],
@@ -187,7 +197,9 @@ function failedReviews(f) {
187
197
  for (const [id, v] of last) {
188
198
  const i = byId.get(id);
189
199
  if (v.verdict !== 'FAIL' || !live(i)) continue;
190
- out.push({ id, days: Math.floor((f.now - v.t) / DAY), score: v.score, thr: v.thr, lead: v.lead, title: i.title, anchor: i.anchor });
200
+ // the latest agent run of the initiative: its row in the Viewer opens that run's return (OvA3Waited)
201
+ const run = (f.runs || []).filter((r) => r && r.initiative_id === id && r.run_id && (!i.ws || !r.ws || r.ws === i.ws)).sort((a, b) => String(b.created_at || '').localeCompare(String(a.created_at || '')))[0];
202
+ out.push({ id, days: Math.floor((f.now - v.t) / DAY), score: v.score, thr: v.thr, lead: v.lead, title: i.title, anchor: i.anchor, run: run ? run.run_id : null, ws: i.ws || null });
191
203
  }
192
204
  return out;
193
205
  }
@@ -207,7 +219,8 @@ function waitedRows(f) {
207
219
  log: ['Read planning/runs/evals.jsonl', 'Kept the latest verdict of each initiative', 'Found ' + n + ' that failed and have no later review'],
208
220
  say: num(n)[0].toUpperCase() + num(n).slice(1) + ' ' + plural(n, 'review failed and none since has passed', 'reviews failed and none since has passed') + '. No proposal is on record for ' + plural(n, 'it', 'any of them') + '.',
209
221
  head: 'The reviews',
210
- items: fr.slice().sort((a, b) => b.days - a.days).map((x) => ({ t: clip(x.title || x.id, 80), m: x.days + ' days' + (x.anchor ? ' · ' + x.anchor : ''), s: x.score != null ? 'Scored ' + x.score + (x.thr != null ? ' of ' + x.thr : '') : 'No score recorded', lead: x.lead })),
222
+ items: fr.slice().sort((a, b) => b.days - a.days).map((x) => ({ t: clip(x.title || x.id, 80), m: x.days + ' days' + (x.anchor ? ' · ' + x.anchor : ''), s: x.score != null ? 'Scored ' + x.score + (x.thr != null ? ' of ' + x.thr : '') : 'No score recorded', lead: x.lead,
223
+ id: x.id, days: x.days, ...(x.run ? { run: x.run } : {}), ...(x.ws ? { ws: x.ws } : {}) })),
211
224
  pane: { label: n + ' failed ' + plural(n, 'review', 'reviews'), list: true },
212
225
  })),
213
226
  }];
@@ -491,19 +504,36 @@ function readFm(root, rel) {
491
504
  const m = /^---\n([\s\S]*?)\n---/.exec(t);
492
505
  if (!m) return null;
493
506
  const out = {};
494
- for (const k of ['lane', 'parent_kr', 'status']) {
507
+ for (const k of ['lane', 'parent_kr', 'status', 'owner']) {
495
508
  const r = new RegExp('^' + k + ':\\s*(.*)$', 'm').exec(m[1]);
496
509
  if (r && r[1].trim()) out[k] = r[1].trim().replace(/^"(.*)"$/, '$1');
497
510
  }
498
511
  return out;
499
512
  }
500
513
 
514
+ /** The goal an anchor names, in words, from the OKR files and the health budgets: { kind: 'kr'|'objective'|'health', title } or null when
515
+ * the files do not name it (an anchor read only as written is not a name). */
516
+ function goalOf(A, raw) {
517
+ if (!A || !raw) return null;
518
+ let r = null;
519
+ try { r = A.resolve(raw); } catch { return null; }
520
+ if (!r || r.status !== 'resolved' && r.kind !== 'health') return null;
521
+ if (r.kind === 'health') return { kind: 'health', title: String(r.anchor || '').replace(/^health:/, '').replace(/[-_]+/g, ' ') };
522
+ if ((r.kind === 'kr' || r.kind === 'objective') && r.title && r.title !== String(raw).trim()) return { kind: r.kind, title: clip(r.title, 90) };
523
+ return null;
524
+ }
501
525
  /** The slow read: every initiative's workflow state, from the engine (a git history walk). Runs at low priority so it does not starve the machine. null on failure. */
502
526
  async function readInitiatives({ root, engine }) {
503
527
  const wf = engine ? await run(process.execPath, [engine, '--json', '--root', root], { cwd: root, nice: 10 }) : null;
504
528
  let list;
505
529
  try { list = JSON.parse(wf).map((x) => ({ id: x.id, title: x.title, lane: x.lane, stage: x.stage, accepted: !!x.accepted, stopped: !!x.stopped, legacy: !!x.legacy, anchor: x.anchor, last_activity: x.last_activity, blockers: x.blockers || [], next: x.next, record: x.record, steps: (x.steps || []).map((s) => ({ key: s.key, status: s.status, next: s.next, rule: (s.basis && s.basis.rule) || s.rule, blocking: s.blocking })) })); } catch { return null; }
506
- for (const i of list) if (i.record && !i.accepted && (i.lane === 'prototype' || i.steps.some((x) => x.status === 'blocked'))) i.fm = readFm(root, i.record);
530
+ let A = null;
531
+ try { A = require('./initiative-rows.js').anchorsOf(root); } catch { A = null; }
532
+ for (const i of list) {
533
+ if (!(i.record && !i.accepted && (i.lane === 'prototype' || i.steps.some((x) => x.status === 'blocked')))) continue;
534
+ i.fm = readFm(root, i.record);
535
+ i.goal = goalOf(A, i.anchor || (i.fm && i.fm.parent_kr));
536
+ }
507
537
  return list;
508
538
  }
509
539
 
@@ -31,7 +31,7 @@ const COMMANDS = { driver: ['propose', 'status', 'keep', 'return', 'drop', 'paus
31
31
  const USAGE = [
32
32
  'usage: pmos driver propose|status|keep|return|drop|pause|resume|mode — the Initiative Driver',
33
33
  ' pmos driver propose <initiative|work> <id> --what <what> (--file <json|md> | --data "<text>") --why "<one line>" [--source label=ref …] [--confidence 0..1] [--recommended "<what you suggest>"] [--reversible true|false] [--effort S|M|L]',
34
- ' what: problem, evidence, sizing, assumption, stakeholders, move, note, doc (initiative) · next-step, follow-up, note (Work task)',
34
+ ' what: problem, evidence, sizing, assumption, stakeholders, move, note, doc, overlap (initiative) · next-step, follow-up, note (Work task)',
35
35
  ' pmos driver status <initiative|work> <id>',
36
36
  ' pmos driver keep <proposal> PM only',
37
37
  ' pmos driver return <proposal> --note "<what to change>" PM only',
@@ -55,6 +55,16 @@ const dayCheckOpen = (settings, now, inQuiet) => {
55
55
  const t = hhmm(now);
56
56
  return settings && settings.enabled === false ? false : (t >= dc.start && t < dc.end && !inQuiet(now, settings && settings.quiet));
57
57
  };
58
+ // feedback batch 18 item 9: deep work (Your impact, metric drafts and reads, the morning ✦ checks, core document drafts; the horizon scan keeps its own time)
59
+ // runs at night, DEEP_NIGHT, or at any hour once the PM has been idle for 30 minutes (lib/pm-idle.js). Quiet hours still hold it. Each run's
60
+ // own due rule keeps it to once a day, so a night that ran leaves nothing for the day; a night PMOS was closed is caught up when the PM steps away.
61
+ const DEEP_NIGHT = Object.freeze({ start: '01:00', end: '05:00' });
62
+ const deepOpen = (settings, now, inQuiet, idleMs = require('./pm-idle.js').idleFor(now)) => {
63
+ if (settings && settings.enabled === false) return false;
64
+ if (inQuiet(now, settings && settings.quiet)) return false;
65
+ const t = hhmm(now);
66
+ return (t >= DEEP_NIGHT.start && t < DEEP_NIGHT.end) || idleMs >= require('./pm-idle.js').IDLE_MS;
67
+ };
58
68
 
59
69
  /** The lines of a plain JSONL file that parse; a missing file is empty. */
60
70
  function readJsonl(f) {
@@ -105,6 +115,10 @@ function create(deps) {
105
115
  for (const p of retNotes) lines.push(`The PM sent back ${p.id} (${p.what}) with this note: "${p.note}". Revise it and file a new proposal.`);
106
116
  const mine = [...state.proposals.values()].filter((p) => D.targetKey(p.target) === D.targetKey(target));
107
117
  if (mine.length) lines.push(`Proposals so far: ${mine.map((p) => `${p.id} ${p.what} (${p.state})`).join('; ')}. Do not file one again.`);
118
+ // batch 18 item 2b: "Not an overlap" drops the proposal; the pair is never flagged again, from either side
119
+ const notOverlap = [...state.proposals.values()].filter((p) => p.what === 'overlap' && p.state === 'dropped' && p.data && p.target.ws === target.ws
120
+ && (p.target.id === target.id || p.data.with === target.id)).map((p) => (p.target.id === target.id ? p.data.with : p.target.id));
121
+ if (notOverlap.length) lines.push(`The PM marked these as not an overlap with this initiative: ${[...new Set(notOverlap)].join(', ')}. Do not file an overlap with them.`);
108
122
  return lines;
109
123
  }
110
124
 
@@ -247,4 +261,4 @@ function create(deps) {
247
261
  return { tick, active: () => [...active.keys()], loginHeld: (now = Date.now()) => !!(loginFailedAt && now - loginFailedAt < LOGIN_HOLD_MS) };
248
262
  }
249
263
 
250
- module.exports = { create, off, dayCheckOpen, loginFailure, LOGIN_HOLD_MS };
264
+ module.exports = { create, off, dayCheckOpen, deepOpen, DEEP_NIGHT, loginFailure, LOGIN_HOLD_MS };
@@ -50,7 +50,7 @@ const crypto = require('crypto');
50
50
  const LEDGER = 'driver.jsonl';
51
51
  const KINDS = Object.freeze(['initiative', 'work']);
52
52
  const WHATS = Object.freeze({
53
- initiative: Object.freeze(['problem', 'evidence', 'sizing', 'assumption', 'stakeholders', 'move', 'note', 'doc']),
53
+ initiative: Object.freeze(['problem', 'evidence', 'sizing', 'assumption', 'stakeholders', 'move', 'note', 'doc', 'overlap']),
54
54
  work: Object.freeze(['next-step', 'follow-up', 'note']),
55
55
  });
56
56
  // A claim without a pointer is not a proposal (PRD section 2: "Nothing without a pointer").
@@ -175,6 +175,12 @@ function checkProposal(input) {
175
175
  if (!e || !CD.draftable(e)) return { ok: false, error: `a doc proposal needs data.key: one of ${CD.SETS.initiative.filter(CD.draftable).map((x) => x.key).join(', ')}` };
176
176
  if (typeof data.slot !== 'string' || !SLOT_RE.test(data.slot)) return { ok: false, error: 'a doc proposal needs data.slot: the slot `pmos coredoc write` printed (YYYY-MM-DD, or YYYY-MM-DD-2)' };
177
177
  data = { key: data.key, slot: data.slot };
178
+ } else if (i.what === 'overlap') {
179
+ // batch 18 item 2b: a possible overlap with another open initiative. New for you shows both by name, how much overlaps and how sure,
180
+ // and the PM picks Keep both in this order, Merge or Not an overlap (pm/cozy-news.js). Every part but `with` is optional: absent stays absent.
181
+ const c = checkOverlap(data, t.target.id);
182
+ if (!c.ok) return c;
183
+ data = c.data;
178
184
  } else if (i.what === 'next-step') {
179
185
  if (!oneLine(data.text, 500)) return { ok: false, error: 'a next step needs data.text: one line of up to 500 characters' };
180
186
  if (data.due != null && !(typeof data.due === 'string' && DATE_RE.test(data.due))) return { ok: false, error: 'data.due is YYYY-MM-DD' };
@@ -201,6 +207,29 @@ function checkProposal(input) {
201
207
  return { ok: true, proposal: { target: t.target, what: i.what, data, why: i.why.trim(), sources, ...(Object.keys(facts).length ? { facts } : {}) } };
202
208
  }
203
209
 
210
+ /** The data of an overlap proposal (batch 18 item 2b). → { ok, data } | { ok: false, error }. Pure. */
211
+ const SURE = Object.freeze(['high', 'medium', 'low']);
212
+ function checkOverlap(d, self) {
213
+ if (typeof d.with !== 'string' || !ID_RE.test(d.with)) return { ok: false, error: 'an overlap needs data.with: the id of the other open initiative' };
214
+ if (d.with === self) return { ok: false, error: 'an overlap is with another initiative, not this one' };
215
+ const out = { with: d.with };
216
+ const n = (v) => Number.isInteger(v) && v >= 0 && v <= 99;
217
+ if (d.parts != null || d.of != null) {
218
+ if (!n(d.parts) || !n(d.of) || d.parts < 1 || d.parts > d.of) return { ok: false, error: 'data.parts and data.of are whole numbers: how many of this plan\'s parts overlap, of how many (1 ≤ parts ≤ of)' };
219
+ out.parts = d.parts; out.of = d.of;
220
+ }
221
+ if (d.items != null) {
222
+ if (!Array.isArray(d.items) || d.items.length > 12 || !d.items.every((x) => oneLine(x, 200))) return { ok: false, error: 'data.items is a list of at most 12 lines: the parts that overlap' };
223
+ out.items = d.items.map((x) => x.trim());
224
+ }
225
+ if (d.sure != null) { if (!SURE.includes(d.sure)) return { ok: false, error: `data.sure is one of ${SURE.join(', ')}` }; out.sure = d.sure; }
226
+ if (d.sureWhy != null) { if (!oneLine(d.sureWhy, 300)) return { ok: false, error: 'data.sureWhy is one line: why you are that sure' }; out.sureWhy = d.sureWhy.trim(); }
227
+ if (d.first != null) { if (d.first !== 'this' && d.first !== 'other') return { ok: false, error: 'data.first is this or other: which one should go first' }; out.first = d.first; }
228
+ if (d.text != null) { if (!oneLine(d.text, 500)) return { ok: false, error: 'data.text is one line: what overlaps, in plain words' }; out.text = d.text.trim(); }
229
+ if (d.firstWhy != null) { if (!oneLine(d.firstWhy, 300)) return { ok: false, error: 'data.firstWhy is one line: why that order' }; out.firstWhy = d.firstWhy.trim(); }
230
+ return { ok: true, data: out };
231
+ }
232
+
204
233
  // ── the fold ─────────────────────────────────────────────────────────────────────────────────────────
205
234
  function emptyState() {
206
235
  return { epoch: null, proposals: new Map(), order: [], paused: new Map(), modes: new Map(), runs: new Map(), bySession: new Map(),
@@ -449,6 +478,6 @@ function runOfSession(state, token) {
449
478
 
450
479
  module.exports = {
451
480
  LEDGER, KINDS, WHATS, NEEDS_SOURCE, MODES, DEFAULT_MODE, WAKES, EVENTS, BUDGET, DAY, PM_WAIT_MS, SWEEP_EVERY_MS, DEFAULT_STALLED_DAYS, ID_RE, WS_RE, PROPOSAL_RE, RUN_RE,
452
- stateDirOf, ledgerFile, append, readLines, newId, checkTarget, checkProposal, fold, modeOf, isPaused, openProposals, runsOnDay, admit, plan,
481
+ stateDirOf, ledgerFile, append, readLines, newId, checkTarget, checkProposal, checkOverlap, fold, modeOf, isPaused, openProposals, runsOnDay, admit, plan,
453
482
  detect, sweepLines, wakesFromLedgers, answeredWakes, runOfSession, moveHeld, localDay, targetKey, wsIdOf,
454
483
  };
@@ -122,7 +122,8 @@ function lineOf(o = {}) {
122
122
  const read = G.filter((g) => g.reading.dot !== 'none');
123
123
  if (!read.length) {
124
124
  if (drafts) return { head: 'I drafted ' + noun(drafts, 'fix', 'fixes') + ' so every goal can be read.', sub: 'Keep them all at once, or one by one. I test-read each one first.', tone: 'drafts', keepAll };
125
- return { head: G.length ? 'I have not read a goal yet. I read each one when it has a way to be read.' : 'This product has no goal yet. I draft a North Star when the next check runs.', sub: '', tone: 'drafts', keepAll: 0 };
125
+ // batch 18 item 4: no promise of "the next check". The page offers ✦ Draft them now (public/pm/okr-list.js lineOf).
126
+ return { head: G.length ? 'I have not read a goal yet. I read each one when it has a way to be read.' : 'This product has no goal yet.', sub: '', tone: 'drafts', keepAll: 0 };
126
127
  }
127
128
  if (drafts) return { head: 'I drafted ' + noun(drafts, 'fix', 'fixes') + ' for your goals.', sub: 'Keep them all at once, or one by one.', tone: 'drafts', keepAll };
128
129
  const close = G.filter((g) => g.reading.dot === 'close');
@@ -11,6 +11,7 @@
11
11
  * streamLines(line) → { log: [lines], result: object|null } one stream-json event, for the live log
12
12
  * logLines(result, exitCode) → the lines the read-only log pane shows at the end
13
13
  * outcomeOf(result, { code, signal, timedOut, stopped, timeoutMin }) → { ok, headline, why, turns, durationMs, denied } what the run card says
14
+ * runEnvOf(extra) → the variables of a run's spawn spec (spec.env) that reach its process: only RUN_ENV, only strings
14
15
  *
15
16
  * Pure: no I/O, no process. server.js spawnSession starts the child and keeps the session row.
16
17
  *
@@ -387,4 +388,20 @@ function logLines(r, exitCode) {
387
388
  return out;
388
389
  }
389
390
 
390
- module.exports = { HEADLESS_SKILLS, HEADLESS_ORIGINS, ASK_ORIGINS, DRIVE_ORIGINS, SCAN_WEB_ORIGINS, SCAN_REPO_ORIGINS, SCAN_RESEARCH_WEB_ORIGINS, SCAN_RESEARCH_REPO_ORIGINS, WEB_KINDS, REPORT_SETUP_ORIGINS, REPORT_FIND_ORIGINS, CORE_DOC_ORIGINS, REPORT_DESIGN_ORIGINS, REPORT_SAMPLE_FETCH_ORIGINS, REPORT_STRUCTURE_ORIGINS, REPORT_STRUCTURE_DRY_ORIGINS, METRIC_DRAFT_ORIGINS, IMPACT_ORIGINS, TOOLS, SKILL_WRITE_DIRS, DEFAULT_TIMEOUT_MS, kindFor, argsFor, skillWriteDirs, timeoutMs, parseResult, streamLines, outcomeOf, signedOut, SIGNED_OUT_WHY, logLines, switchedOff };
391
+ // The variables a background run's spawn spec may set (spec.env, server.js spawnSession extraEnv). Each one pins the run's one write to its
392
+ // ledger, its scope and its run id; its CLI refuses without them. Batch 18 item 4: the metric-draft, propose, impact, metric-read and
393
+ // ms-review keys were missing here, so those runs started, could file nothing, and ended "ok" with no draft. A key a lib/*.js spec sets
394
+ // that is not on this list fails headless.test.js.
395
+ const RUN_ENV = Object.freeze(['PMOS_SCAN_FILE', 'PMOS_SCAN_ORIGIN', 'PMOS_SCAN_RUN', 'PMOS_REPORT_FILE', 'PMOS_REPORT_RUN',
396
+ 'PMOS_CORE_DOC_SCOPE', 'PMOS_CORE_DOC_KEY', 'PMOS_CORE_DOC_KEYS',
397
+ 'PMOS_METRIC_DRAFT_FILE', 'PMOS_METRIC_DRAFT_WS', 'PMOS_METRIC_DRAFT_SCOPE', 'PMOS_METRIC_DRAFT_ID', 'PMOS_METRIC_DRAFT_RUN',
398
+ 'PMOS_METRIC_READ_FILE', 'PMOS_METRIC_READ_RECORDS', 'PMOS_METRIC_READ_DRAFTS', 'PMOS_METRIC_READ_WS', 'PMOS_METRIC_READ_RUN', 'PMOS_METRIC_READ_RIDS', 'PMOS_METRIC_READ_TEST',
399
+ 'PMOS_PROPOSE_FILE', 'PMOS_PROPOSE_WS', 'PMOS_PROPOSE_BOARD', 'PMOS_PROPOSE_INI', 'PMOS_PROPOSE_RUN',
400
+ 'PMOS_IMPACT_FILE', 'PMOS_IMPACT_RUN', 'PMOS_MS_REVIEW_FILE', 'PMOS_MS_REVIEW_RUN', 'PMOS_MS_REVIEW_PROGRAM']);
401
+ function runEnvOf(extra) {
402
+ const out = {};
403
+ if (extra && typeof extra === 'object') for (const k of RUN_ENV) if (typeof extra[k] === 'string') out[k] = extra[k];
404
+ return out;
405
+ }
406
+
407
+ module.exports = { HEADLESS_SKILLS, HEADLESS_ORIGINS, ASK_ORIGINS, DRIVE_ORIGINS, SCAN_WEB_ORIGINS, SCAN_REPO_ORIGINS, SCAN_RESEARCH_WEB_ORIGINS, SCAN_RESEARCH_REPO_ORIGINS, WEB_KINDS, REPORT_SETUP_ORIGINS, REPORT_FIND_ORIGINS, CORE_DOC_ORIGINS, REPORT_DESIGN_ORIGINS, REPORT_SAMPLE_FETCH_ORIGINS, REPORT_STRUCTURE_ORIGINS, REPORT_STRUCTURE_DRY_ORIGINS, METRIC_DRAFT_ORIGINS, IMPACT_ORIGINS, TOOLS, SKILL_WRITE_DIRS, DEFAULT_TIMEOUT_MS, kindFor, argsFor, skillWriteDirs, timeoutMs, parseResult, streamLines, outcomeOf, signedOut, SIGNED_OUT_WHY, logLines, switchedOff, RUN_ENV, runEnvOf };
@@ -276,7 +276,7 @@ function upgradeApp(root, { version, logFile, spawn = cp.spawn, env = updateEnv(
276
276
  fd = fs.openSync(logFile, 'w');
277
277
  fs.writeSync(fd, `${new Date().toISOString()} clearing npm cache…\n`);
278
278
  fs.writeSync(fd, `${new Date().toISOString()} ${NPM} cache clean --force\n`);
279
- fs.writeSync(fd, `${new Date().toISOString()} ${NPX} ${npxArgs(src, version, ['workspace', '--reinstall', String(root)]).join(' ')}\n`);
279
+ fs.writeSync(fd, `${new Date().toISOString()} ${NPX} ${npxArgs(src, version, ['workspace', '--reinstall', '--no-open', String(root)]).join(' ')}\n`);
280
280
  } catch (e) { return { ok: false, error: `Could not write the log file: ${e.message}` }; }
281
281
  try {
282
282
  // Clear npm cache synchronously before spawning the update, so npx downloads the fresh version
@@ -285,7 +285,7 @@ function upgradeApp(root, { version, logFile, spawn = cp.spawn, env = updateEnv(
285
285
  try { fs.appendFileSync(logFile, `Note: cache clear had an issue, but continuing: ${e.message}\n`); } catch { /* silent */ }
286
286
  }
287
287
  try {
288
- const child = spawn(NPX, npxArgs(src, version, ['workspace', '--reinstall', String(root)]),
288
+ const child = spawn(NPX, npxArgs(src, version, ['workspace', '--reinstall', '--no-open', String(root)]),
289
289
  { cwd: String(root), env, detached: true, stdio: ['ignore', fd, fd], windowsHide: true, shell: IS_WIN });
290
290
  // A child that could not start writes nothing itself: say why in the log, which the page names when it gives up.
291
291
  if (child && typeof child.on === 'function') {
@@ -38,6 +38,7 @@ const flagOff = (v) => /^(off|0|false|no)$/i.test(String(v || '').trim());
38
38
  const off = (env) => flagOff((env || process.env).PMOS_METRIC_DRAFT);
39
39
  const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
40
40
  const MAX = 2;
41
+ const NOTHING = 'The run ended without drafting anything.';
41
42
  const SCAN_MS = 10 * 60e3;
42
43
  const QUARTER_DAYS = 14;
43
44
  const localDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
@@ -133,8 +134,13 @@ function create(deps) {
133
134
  const s = MD.read(a.dir).scopes.get(MD.keyOf(a.scope, a.id));
134
135
  if (!s || !s.run || s.run.run !== run || s.run.ended) return; // `pmos metrics draft end` or ■ Stop wrote it already
135
136
  const res = (r && r.result) || {};
136
- const ok = !!(r && !r.timedOut && !r.stopped && r.code === 0 && res.ok !== false && !res.isError);
137
- try { MD.append(a.dir, null, { kind: 'end', scope: a.scope, id: a.id, run, ok, ...(ok ? {} : { error: one((r && r.note) || res.text || 'the run failed', 200) }) }, new Date(now).toISOString()); } catch (e) { warn('metric draft end', e); }
137
+ const exitOk = !!(r && !r.timedOut && !r.stopped && r.code === 0 && res.ok !== false && !res.isError);
138
+ // batch 18 item 4: a run that ended well but filed no row drafted nothing. It is not "ready": the page says so and offers Draft again.
139
+ const filed = [...s.rows.values()].some((x) => x.run === run);
140
+ const ok = exitOk && filed;
141
+ const error = ok ? '' : exitOk ? NOTHING : one((r && r.note) || res.text || 'the run failed', 200);
142
+ try { MD.append(a.dir, null, { kind: 'end', scope: a.scope, id: a.id, run, ok, ...(ok ? {} : { error }) }, new Date(now).toISOString()); } catch (e) { warn('metric draft end', e); }
143
+ return ok || (r && r.stopped) ? undefined : { failed: error };
138
144
  }
139
145
 
140
146
  /** Start one run now. → { ok, run } | { ok: false, error, held? } */
@@ -162,7 +168,7 @@ function create(deps) {
162
168
  active.set(run, { ws, scope, id, dir, session: null });
163
169
  let session = null;
164
170
  try {
165
- session = go({ name: 'Drafting metrics · ' + one(title, 60), ws, origin: `metric-draft:${ws}:${scope}:${id}:${run}`, initialInput: prompt + '\r', ...(scope === 'initiative' ? { initiative: id } : {}),
171
+ session = go({ name: 'Drafting metrics · ' + one(title, 60), ws, ...(press ? { byPm: true } : {}), origin: `metric-draft:${ws}:${scope}:${id}:${run}`, initialInput: prompt + '\r', ...(scope === 'initiative' ? { initiative: id } : {}),
166
172
  env: { PMOS_METRIC_DRAFT_FILE: MD.ledgerFile(dir), PMOS_METRIC_DRAFT_WS: ws, PMOS_METRIC_DRAFT_SCOPE: scope, PMOS_METRIC_DRAFT_ID: id, PMOS_METRIC_DRAFT_RUN: run }, onDone: (r) => ended(run, r) });
167
173
  } catch (e) { warn('metric draft run', e); }
168
174
  if (session && session.held) { active.delete(run); return { ok: false, held: true, error: 'Claude is busy with other runs. It tries again in a minute.' }; }
@@ -213,4 +219,4 @@ function create(deps) {
213
219
  return { tick, start, stop, active: () => [...active.keys()], runOf: (ws, scope, id) => { for (const [r, a] of active) if (a.ws === ws && a.scope === scope && a.id === id) return r; return null; } };
214
220
  }
215
221
 
216
- module.exports = { off, quarterOf, dueOf, gapsOf, promptOf, create, MAX, SCAN_MS, QUARTER_DAYS };
222
+ module.exports = { off, quarterOf, dueOf, gapsOf, promptOf, create, MAX, SCAN_MS, QUARTER_DAYS, NOTHING };
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
  /* news-for-you.js — New for you, which replaces the Inbox (initiative premium-uncovered-features, E2; canvas EvInbox, HmAround).
3
3
  *
4
- * build({ inbox, work, seen }) → { count, groups: [{ key, label, items }] } PURE
4
+ * build({ inbox, work, seen, name }) → { count, groups: [{ key, label, items }] } PURE
5
5
  * readSeen(runtimeDir) → Set of ids · appendSeen(runtimeDir, ids, now) · badSeen(body) → null | the reason
6
6
  *
7
- * New for you holds items for the PM's information only, in two groups (EvInbox):
7
+ * New for you holds items for the PM's information only, in three groups (EvInbox):
8
+ * propose Claude proposes: an agent's possible-overlap note between two open initiatives (batch 18 item 2b, OvA5), with its pick
8
9
  * given a task given to the PM: an open Work item that came from a source (Jira, the work breakdown), not one the PM typed
9
10
  * finished what the agents finished while the PM was away: the new items of the agent inbox (GET /api/inbox items)
10
11
  * An item leaves once it is seen: its id is in <runtime>/news-seen.jsonl. A passed review or a proposal is its initiative's next step, so it
@@ -15,7 +16,7 @@ const fs = require('fs');
15
16
  const path = require('path');
16
17
 
17
18
  const SEEN = 'news-seen.jsonl';
18
- const ID_RE = /^(men|task|prop|goal|work):[^\s]{1,200}$/;
19
+ const ID_RE = /^(men|task|prop|goal|work|fin):[^\s]{1,200}$/; // fin: a draft of Your day's Drafted for you, read and done with (batch 18 item 2)
19
20
  const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
20
21
  const SRC = { slack: 'Slack', jira: 'Jira', confluence: 'Confluence', mail: 'Mail', wbs: 'Work breakdown', gmail: 'Gmail', figma: 'Figma' };
21
22
  const srcName = (s) => SRC[s] || (s ? String(s)[0].toUpperCase() + String(s).slice(1) : '');
@@ -23,7 +24,7 @@ const FIN = { 'work-draft': 'Draft ready', 'work-stopped': 'Agent stopped', prop
23
24
  const at = (x) => { const t = Date.parse(x || ''); return Number.isFinite(t) ? t : null; };
24
25
 
25
26
  /** The open Work items that came from a source, from GET /api/pm-items' answer (its five lists). */
26
- function givenItems(v, seen) {
27
+ function givenItems(v, seen, name) {
27
28
  const w = (v && v.work) || {}, out = [], had = new Set();
28
29
  for (const k of ['inbox', 'today', 'upcoming', 'waiting', 'someday']) for (const it of w[k] || []) {
29
30
  if (!it || !it.id || it.done || had.has(it.id)) continue;
@@ -31,24 +32,38 @@ function givenItems(v, seen) {
31
32
  if (!(it.assigned === true || (src !== 'local' && src !== 'brief' && src !== 'work'))) continue;
32
33
  had.add(it.id);
33
34
  if (seen.has('task:' + it.id)) continue;
35
+ const a = it.agent && typeof it.agent === 'object' ? it.agent : null;
34
36
  out.push({ id: 'task:' + it.id, kind: 'task', tid: it.id, title: clip('New task: ' + (it.title || it.key || it.id), 160), from: srcName(src), key: it.key || '',
35
- due: it.due || null, initiative: it.initiative || null, link: it.url || it.link || null, at: at(it.created_at) });
37
+ due: it.due || null, initiative: it.initiative || null, iniTitle: (it.initiative && name(it.initiative)) || '', link: it.url || it.link || null, at: at(it.created_at),
38
+ status: it.status || '', list: k, why: clip(it.why, 300),
39
+ // the agent on it, only what really ran or is offered (batch 18 item 2, OvA6): ready with its draft's summary, working, or the suggestion
40
+ agent: a && ['suggest', 'queued', 'working', 'sending', 'ready', 'failed'].includes(a.state)
41
+ ? { state: a.state, suggest: clip(a.suggest, 200), draft: a.draft && a.draft.summary ? clip(a.draft.summary, 300) : '' } : null });
36
42
  }
37
43
  return out;
38
44
  }
45
+ /** An agent's possible-overlap note (batch 18 item 2b, OvA5): a ✦ Claude proposes item, never a given task. Both initiatives by name. */
46
+ function overlapItem(x, name) {
47
+ const o = x.overlap, a = x.target || {};
48
+ return { id: x.id, kind: 'overlap', title: 'Possible overlap', pid: x.pid, ws: x.pws || x.ws || '', product: x.product || '', at: Number.isFinite(x.at) ? x.at : null, why: clip(x.why, 500),
49
+ a: { id: a.id, title: a.title && a.title !== a.id ? a.title : name(a.id, x.pws) || '' }, b: { id: o.with, title: name(o.with, x.pws) || '' }, overlap: o };
50
+ }
39
51
  function finishedItems(inbox, seen) {
40
52
  const items = inbox && inbox.ok !== false && Array.isArray(inbox.items) ? inbox.items : [];
41
- return items.filter((x) => x && x.id && !seen.has(x.id)).map((x) => ({
53
+ return items.filter((x) => x && x.id && !x.overlap && !seen.has(x.id)).map((x) => ({
42
54
  id: x.id, kind: 'finished', what: FIN[x.kind] || 'Finished', title: clip(x.title, 160), product: x.product || '', target: x.target && x.target.title ? x.target.title : '',
43
55
  at: Number.isFinite(x.at) ? x.at : null, open: x.open || '', pws: x.pws || '', session: x.session || '', agentKind: x.kind || '',
44
56
  }));
45
57
  }
46
58
 
47
- /** The groups, newest first in each; an empty group is left out. inbox: GET /api/inbox; work: GET /api/pm-items. */
48
- function build({ inbox = null, work = null, seen = new Set() } = {}) {
59
+ /** The groups, newest first in each; an empty group is left out. inbox: GET /api/inbox; work: GET /api/pm-items; name(id, ws?) → an initiative's
60
+ * title, or '' (an id is never shown). */
61
+ function build({ inbox = null, work = null, seen = new Set(), name = () => '' } = {}) {
49
62
  const by = (a, b) => (b.at || 0) - (a.at || 0);
63
+ const ib = inbox && inbox.ok !== false && Array.isArray(inbox.items) ? inbox.items : [];
50
64
  const groups = [
51
- { key: 'given', label: 'Given to you', items: givenItems(work, seen).sort(by) },
65
+ { key: 'propose', label: 'Claude proposes', items: ib.filter((x) => x && x.id && x.overlap && x.overlap.with && !seen.has(x.id)).map((x) => overlapItem(x, name)).sort(by) },
66
+ { key: 'given', label: 'Given to you', items: givenItems(work, seen, name).sort(by) },
52
67
  { key: 'finished', label: 'Finished while you were away', items: finishedItems(inbox, seen).sort(by) },
53
68
  ].filter((g) => g.items.length);
54
69
  return { count: groups.reduce((n, g) => n + g.items.length, 0), groups, read: { inbox: !!(inbox && inbox.ok !== false), work: !!(work && work.ok !== false) } };
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+ /* pm-idle.js — how long the PM has been away from PMOS (feedback batch 18 item 9).
3
+ *
4
+ * The server calls touch() on every page press (a request that carries the launch nonce, so never an agent session) and on every key the
5
+ * PM types into a terminal. idleFor(now) is the time since the last of those, counted from when the server started. Deep work (lib/driver-run.js
6
+ * deepOpen) starts during the day only after IDLE_MS of it. Memory only: a restart counts as activity.
7
+ */
8
+ const IDLE_MS = 30 * 60 * 1000;
9
+ let last = Date.now();
10
+ const touch = (now = Date.now()) => { if (now > last) last = now; };
11
+ const idleFor = (now = Date.now()) => Math.max(0, now - last);
12
+ module.exports = { IDLE_MS, touch, idleFor };
@@ -39,24 +39,26 @@ const SOURCES = Object.freeze([
39
39
  { id: 'calendar', label: 'Calendar', group: 'tools', ic: 'cal', run: 'skill', skill: 'calendar-sync', how: 'tool', fresh: 'calendar',
40
40
  what: 'Events from your calendars, for Calendar, the phone day, meeting focus and meeting notes.', uses: [],
41
41
  impact: 'Calendar, the phone day, meeting focus, meeting notes and the Briefing\'s Today card show the last import.',
42
- def: { kind: 'daily', times: ['06:30', '12:30'] } },
42
+ def: { kind: 'every', every: '30', work: true } },
43
43
  { id: 'jira', label: 'Jira tickets and sprints', group: 'tools', ic: 'org', run: 'skill', skill: 'jira-sync', how: 'tool', fresh: 'jira', copy: 'jira',
44
44
  what: 'The status of every pushed ticket, the active sprints, and each sprint\'s goal and team summary.', uses: [],
45
45
  impact: 'Tickets keep their last status. Sprint summaries stop. The initiative driver cannot see ticket moves or blocked tickets, core documents write the sprint review from old data, and report drafts say Jira was not checked.',
46
- def: { kind: 'daily', times: ['06:30'] } },
46
+ def: { kind: 'every', every: '60', work: true } },
47
47
  { id: 'mywork', label: 'Work assigned to you', group: 'tools', ic: 'todo', run: 'skill', skill: 'my-work-read', how: 'tool', fresh: 'my-work', copy: 'mywork',
48
48
  what: 'Jira tickets assigned to you, for the Work page and the Briefing.', uses: [],
49
49
  impact: 'The Work page and the Briefing keep the last list of work assigned to you.',
50
- def: { kind: 'manual' } },
50
+ def: { kind: 'every', every: '60', work: true } },
51
51
  { id: 'tracker', label: 'Tracker files', group: 'tools', ic: 'sheet', run: 'skill', skill: 'tracker-refresh', how: 'code', fresh: 'tracker',
52
52
  what: 'Plan items brought up to date from the tracker files in the workspace.', uses: [],
53
53
  impact: 'The bi-weekly report says the tracker was not refreshed.',
54
54
  def: { kind: 'weekly', day: 'Fri', times: ['15:30'] } },
55
55
  // briefing-source-flow: the brief is derived content, so it reads these saved reads instead of the tools (lib/source-reads.js)
56
56
  { id: 'tools', label: 'Your tools', group: 'tools', ic: 'inbox', run: 'skill', skill: 'sources-read', how: 'tool', fresh: 'tools',
57
- what: 'Mail, Slack, Wispr Flow, Confluence, GitHub, Drive, Figma and your websites, saved as they are for the Briefing. It runs before the morning briefing.', uses: [],
57
+ what: 'Mail, Slack, Wispr Flow, Confluence, GitHub, Drive, Figma and your websites, saved as they are for the Briefing. It runs every hour in working hours, and before the morning briefing.', uses: [],
58
58
  impact: 'The Briefing is built from the last saved read of your tools.',
59
- def: { kind: 'manual' } },
59
+ // batch 18 items 7 + 9: once a day before the brief made the read 8 h old every afternoon, with nothing to read it again; every hour in
60
+ // working hours keeps it inside its stale window (lib/freshness.js stale_after_ms), so the amber line means a read really failed
61
+ def: { kind: 'every', every: '60', work: true } },
60
62
  { id: 'brief', label: 'Morning briefing', group: 'pmos', ic: 'sun', run: 'skill', skill: 'morning-brief', how: 'bg',
61
63
  what: 'Your Briefing for the day, ranked by what needs you first. When it is due, the sources it is built on that are older than 2 hours are refreshed first.', uses: ['calendar', 'jira', 'mywork', 'tools'],
62
64
  impact: 'No new Briefing for the day, and the day check has nothing to update.',
@@ -72,7 +74,7 @@ const SOURCES = Object.freeze([
72
74
  { id: 'scan', label: 'Horizon scan', group: 'pmos', ic: 'search', run: 'job', how: 'bg', setIn: 'Initiatives, Horizon scan',
73
75
  what: 'Reads the web and your repositories for changes that matter to your initiatives.', uses: ['repo'],
74
76
  impact: 'Core documents cite the older scan.' },
75
- { id: 'coredocs', label: 'Core documents', group: 'pmos', ic: 'doc', run: 'job', how: 'bg', fixed: 'Every 30 min in working hours, each document at most once a day',
77
+ { id: 'coredocs', label: 'Core documents', group: 'pmos', ic: 'doc', run: 'job', how: 'bg', fixed: 'At night, or when you are away for 30 min; each document at most once a day',
76
78
  what: 'Drafts the portfolio, board and initiative documents that are due, old or missing.', uses: ['repo', 'jira', 'scan'],
77
79
  impact: 'The initiative driver no longer sees documents that are due or old.' },
78
80
  { id: 'driver', label: 'Initiative driver', group: 'pmos', ic: 'bolt', run: 'job', how: 'bg', fixed: 'Every 30 min in working hours, and when an initiative moves',
@@ -95,6 +97,12 @@ const BY_ID = new Map(SOURCES.map((s) => [s.id, s]));
95
97
  const SKILL_OF = new Map(SOURCES.filter((s) => s.skill).map((s) => [s.skill, s.id]));
96
98
  const usedBy = (id) => SOURCES.filter((s) => s.uses.includes(id)).map((s) => s.id);
97
99
 
100
+ // batch 18 items 7 + 9: the quick reads moved to "often, in working hours". A schedule still on its default from before (OLD_DEFS) moves to
101
+ // the new default once; the `cadence` mark is then saved with the settings, so a schedule the PM picks after this release stays as picked.
102
+ const CADENCE = 1;
103
+ const OLD_DEFS = Object.freeze({ calendar: { kind: 'daily', times: ['06:30', '12:30'] }, jira: { kind: 'daily', times: ['06:30'] }, mywork: { kind: 'manual' }, tools: { kind: 'manual' } });
104
+ const sameSchedule = (a, b) => !!a && !!b && a.kind === b.kind && String(a.every || '') === String(b.every || '') && String(a.day || '') === String(b.day || '') && (a.times || []).join() === (b.times || []).join();
105
+
98
106
  const RULE_DEFAULTS = Object.freeze({ catchup: true, retry: '15', tell: 'brief', max: '3', keep: '90' });
99
107
  const RULE_OPTS = Object.freeze({ retry: ['15', '60', 'no'], tell: ['brief', 'here'], max: ['1', '2', '3', '5'], keep: ['30', '90', '365', 'forever'] });
100
108
 
@@ -180,13 +188,14 @@ function withDefaults(raw) {
180
188
  // briefing-source-flow: Your tools feeds the brief, so until the PM sets it, it is on whenever the brief is
181
189
  if ((src.id === 'tools' || src.id === 'leads') && typeof x.on !== 'boolean') on = !!(r.sources && r.sources.brief && r.sources.brief.on === true); // the popup leads follow the reads the same way
182
190
  const n = src.run === 'skill' && x.s ? normalize(src, x.s) : null;
191
+ if (n && n.ok && !(r.cadence >= CADENCE) && sameSchedule(n.s, OLD_DEFS[src.id])) n.ok = false; // an old default moves to the new one (above)
183
192
  sources[src.id] = { on, s: n && n.ok ? n.s : (src.def ? { ...src.def, ...(src.def.times ? { times: src.def.times.slice() } : {}) } : null), ws: typeof x.ws === 'string' ? x.ws : null };
184
193
  }
185
194
  const rules = { ...RULE_DEFAULTS };
186
195
  const rr = r.rules || {};
187
196
  if (typeof rr.catchup === 'boolean') rules.catchup = rr.catchup;
188
197
  for (const k of Object.keys(RULE_OPTS)) if (RULE_OPTS[k].includes(String(rr[k]))) rules[k] = String(rr[k]);
189
- return { sources, rules, migrated: !!r.migrated };
198
+ return { sources, rules, migrated: !!r.migrated, cadence: CADENCE };
190
199
  }
191
200
  /** Check a rules patch. → { ok, patch } | { ok: false, error } */
192
201
  function normalizeRules(p) {
@@ -417,7 +426,7 @@ function writeJson(f, v) {
417
426
  const tmp = `${f}.${process.pid}.tmp`; fs.writeFileSync(tmp, JSON.stringify(v, null, 1) + '\n'); fs.renameSync(tmp, f);
418
427
  }
419
428
  const readSettings = (dir) => withDefaults(readJson(files(dir).settings, null));
420
- const writeSettings = (dir, s) => writeJson(files(dir).settings, { sources: s.sources, rules: s.rules, migrated: !!s.migrated });
429
+ const writeSettings = (dir, s) => writeJson(files(dir).settings, { sources: s.sources, rules: s.rules, migrated: !!s.migrated, ...(s.cadence ? { cadence: s.cadence } : {}) });
421
430
  const readState = (dir) => { const s = readJson(files(dir).state, {}); return s && typeof s === 'object' && !Array.isArray(s) ? s : {}; };
422
431
  const writeState = (dir, s) => writeJson(files(dir).state, s);
423
432
 
@@ -133,7 +133,7 @@ function tick(ctx, { now = Date.now(), force = false } = {}) {
133
133
  if (!ctx || typeof ctx.getWs !== 'function') return [];
134
134
  if (!force && lastTick != null && now - lastTick < TICK_EVERY_MS) return [];
135
135
  const settings = (() => { try { return ctx.proSettings ? ctx.proSettings() : null; } catch { return null; } })();
136
- const open = require('./driver-run.js').dayCheckOpen(settings || {}, now, ctx.inQuiet || (() => false));
136
+ const open = ctx.deepOpen ? ctx.deepOpen(settings || {}, now) : require('./driver-run.js').dayCheckOpen(settings || {}, now, ctx.inQuiet || (() => false)); // batch 18 item 9: at night or when idle
137
137
  if (!open) return [];
138
138
  lastTick = now;
139
139
  if (headless.switchedOff(process.env) || /^(off|0|false|no)$/i.test(String(process.env.PMOS_CORE_DOCS || ''))) return []; // PMOS_CORE_DOCS=off: no scheduled drafts
@@ -13,7 +13,7 @@
13
13
  * POST /api/metric-drafts/drop { ws, scope, id, row } → { ok } ✕
14
14
  * POST /api/metric-drafts/edit { ws, scope, id, row, name?, target?, source? } → { ok, row } the inline edit of an open row (batch 16 item 1)
15
15
  * POST /api/metric-drafts/undo { ws, scope, id, row } → { ok } kept → open (its record edited { retired: true }); dropped → open
16
- * POST /api/metric-drafts/start { ws, scope, id } → { ok, run } Draft again
16
+ * POST /api/metric-drafts/start { ws, scope, id } → { ok, run, already? } Draft again (already: a run for it was going)
17
17
  * POST /api/metric-drafts/stop { ws, scope, id } → { ok } ■ Stop: the run ends; what it filed stays a draft
18
18
  *
19
19
  * WHICH LEDGER. A product's and an initiative's drafts are in the state folder of `ws`. A program's are in its charter's workspace (its home,
@@ -91,7 +91,7 @@ async function handle(req, res, url, ctx) {
91
91
  if (!ctx.metricDraftRuns) return send(bad(503, 'Claude\'s runs are off on this server.'));
92
92
  const r = ctx.metricDraftRuns.start({ ws: w.id, scope, id, why: 'press' });
93
93
  if (!r || !r.ok) return send(bad(409, (r && r.error) || 'Claude could not start drafting.'));
94
- return send({ status: 200, body: { ok: true, run: r.run } });
94
+ return send({ status: 200, body: { ok: true, run: r.run, ...(r.already ? { already: true } : {}) } });
95
95
  }
96
96
  if (what === 'stop') {
97
97
  const s = S();
@@ -18,6 +18,20 @@ async function ask(mod, req, ctx, p) {
18
18
  return body;
19
19
  }
20
20
 
21
+ /** name(id, ws?) → an initiative's title from the products the Briefing reads (lib/initiative-rows.js peek: the cache only, never a
22
+ * derivation), or '' when it is not known: New for you never shows an id (batch 18 item 2). */
23
+ function namesOf(ctx) {
24
+ const by = new Map();
25
+ let av = [];
26
+ try { av = require('./routes-briefing-premium.js').products(ctx).available || []; } catch { av = []; }
27
+ const rows = require('./initiative-rows.js');
28
+ for (const a of av) {
29
+ if (!a || !a.root) continue;
30
+ try { const r = rows.peek(a.root); if (r && r.ok) for (const x of r.rows) if (x && x.id && x.title) { by.set(a.ws + '|' + x.id, x.title); if (!by.has('|' + x.id)) by.set('|' + x.id, x.title); } } catch { /* its titles stay unknown */ }
31
+ }
32
+ return (id, ws) => (id ? by.get((ws || '') + '|' + id) || by.get('|' + id) || '' : '');
33
+ }
34
+
21
35
  module.exports = {
22
36
  prefixes: ['/api/news-for-you'],
23
37
  handle: async (req, res, url, ctx) => {
@@ -44,7 +58,7 @@ module.exports = {
44
58
  ask('./routes-inbox.js', req, ctx, '/api/inbox'),
45
59
  ask('./routes-pm-items.js', req, ctx, '/api/pm-items'),
46
60
  ]);
47
- const out = News.build({ inbox, work: work && work.ok !== false ? work : null, seen: ctx.runtimeDir ? News.readSeen(ctx.runtimeDir) : new Set() });
61
+ const out = News.build({ inbox, work: work && work.ok !== false ? work : null, seen: ctx.runtimeDir ? News.readSeen(ctx.runtimeDir) : new Set(), name: namesOf(ctx) });
48
62
  ctx.json(res, { ok: true, ...out });
49
63
  return true;
50
64
  },
@@ -5,7 +5,8 @@
5
5
  *
6
6
  * READ ONLY, and built only from what PMOS already holds. Nothing is invented. The companion reads it for three moments:
7
7
  * finished working hours, "Finished for you": the agent's tasks of today's day run (goals/<date>.run.json, lib/day-run.js) that have a
8
- * draft. { id, title, summary, body, at, status, link, source }; body keeps its lines (markdown, at most 8000 characters); status 'review' (waits for the PM's approval at the desk),
8
+ * draft. { id, title, summary, body, at, status, link, source, key, seen }; key is the draft's seen id (fin:<date>:<id>) and seen is true
9
+ * once the PM pressed "Done with it" (POST /api/news-for-you/seen); body keeps its lines (markdown, at most 8000 characters); status 'review' (waits for the PM's approval at the desk),
9
10
  * 'done' (an auto task) or 'sent'. Newest first, at most 5.
10
11
  * recap evening: how the day went. meetings = today's meetings that have ended; decided = the decisions of today's meetings that
11
12
  * the PM CONFIRMED in the meeting's Replay (lib/meeting-points.js); to_confirm = the decisions caught in today's notes that
@@ -57,7 +58,7 @@ function runOf(run) {
57
58
  failed: T.filter((t) => t.status === 'failed').slice(0, 3).map((t) => ({ id: t.id, title: clip(t.title, 200), error: clip(t.error, 200) })) };
58
59
  }
59
60
 
60
- /** deps: { events, items, run, notes: [note with final_notes], adapter, points: (noteId) → { [pointId]: 'confirmed' | 'wrong' } }
61
+ /** deps: { events, items, run, notes: [note with final_notes], adapter, points: (noteId) → { [pointId]: 'confirmed' | 'wrong' }, seen: Set of seen ids }
61
62
  * notes are today's non-private notes, read in full. A decision's point id is the Replay's (lib/meeting-replay.js): d1, d2, … in caughtOf order. */
62
63
  function build(query, deps = {}) {
63
64
  const q = query || {};
@@ -66,7 +67,8 @@ function build(query, deps = {}) {
66
67
  const today = localDate(now);
67
68
  const events = deps.events || []; const items = deps.items || [];
68
69
  const agenda = todayAgenda(events, items, now, deps.adapter || {});
69
- const finished = finishedOf(deps.run);
70
+ // seen: the PM pressed "Done with it" in the Finished Viewer (batch 18 item 2, OvA7); its key is New for you's seen id for a draft
71
+ const finished = finishedOf(deps.run).map((t) => { const key = 'fin:' + today + ':' + t.id; return { ...t, key, seen: !!(deps.seen && deps.seen.has(key)) }; });
70
72
  const decisions = []; let toConfirm = 0;
71
73
  for (const n of deps.notes || []) {
72
74
  if (!n || n.private) continue;
@@ -115,7 +117,7 @@ module.exports = {
115
117
  const today = localDate(now);
116
118
  const events = dir ? require('./calendar-events.js').readAll(dir, { now: now.getTime() }) : [];
117
119
  const items = dir ? pmItems.fold(pmItems.readLines(path.join(dir, 'pm-items', 'items.jsonl'))) : [];
118
- const out = build({ now: now.toISOString() }, { events, items, run: dir ? readRun(dir, today) : null, notes: dir ? todaysNotes(dir, today) : [], adapter: dir ? notesAdapter(dir) : {}, points: (id) => meetingPoints.pointsOf(dir, id) });
120
+ const out = build({ now: now.toISOString() }, { events, items, run: dir ? readRun(dir, today) : null, notes: dir ? todaysNotes(dir, today) : [], adapter: dir ? notesAdapter(dir) : {}, points: (id) => meetingPoints.pointsOf(dir, id), seen: dir ? require('./news-for-you.js').readSeen(dir) : null });
119
121
  ctx.json(res, out.body, out.status);
120
122
  } catch (e) {
121
123
  ctx.json(res, { ok: false, error: 'your day could not be read: ' + (e && e.message ? e.message : String(e)) }, 500);