create-pmos 0.665.0 → 0.667.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 (33) hide show
  1. package/package.json +28 -22
  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/changelog.json +27 -2
  7. package/workspace/guide/cli.md +13 -0
  8. package/workspace/guide/jira.md +19 -0
  9. package/workspace/guide/layout.md +1 -1
  10. package/workspace/lib/forecast.js +5 -2
  11. package/workspace/lib/headless.js +4 -1
  12. package/workspace/lib/jira-cli.js +36 -2
  13. package/workspace/lib/jira-status.js +32 -10
  14. package/workspace/lib/jira-tickets.js +101 -0
  15. package/workspace/lib/kind-control.js +10 -0
  16. package/workspace/lib/pmos-verbs.js +3 -0
  17. package/workspace/lib/question-batch.js +22 -8
  18. package/workspace/lib/refresh-run.js +9 -3
  19. package/workspace/lib/routes-boards.js +37 -2
  20. package/workspace/lib/routes-kind-control.js +7 -1
  21. package/workspace/lib/routes-your-move.js +23 -4
  22. package/workspace/lib/signoff-cli.js +87 -0
  23. package/workspace/lib/signoffs.js +112 -0
  24. package/workspace/lib/task-jira.js +138 -0
  25. package/workspace/lib/ticket-dry-run.js +164 -0
  26. package/workspace/package-lock.json +2 -2
  27. package/workspace/package.json +1 -1
  28. package/workspace/public/pm/cozy-library.css +1 -0
  29. package/workspace/public/pm/premium-library.js +9 -3
  30. package/workspace/run-tests.js +43 -1
  31. package/workspace/skills/initiative-drive.skill +8 -1
  32. package/workspace/skills/jira-sync.skill +1 -1
  33. package/workspace/test-lists/dry-run-tickets-before-build.json +11 -0
@@ -47,8 +47,10 @@ function partOf(p, hold) {
47
47
  return `${one(p.title || p.why || 'A change', 120)}?${only || ' PMOS found no source.'}`;
48
48
  }
49
49
 
50
- /** One question per owner and initiative, the PM's first, then by initiative. PURE. */
51
- function questionsOf(held, { pm = 'PM' } = {}) {
50
+ /** One question per owner and initiative, the PM's first, then by initiative. PURE.
51
+ * extra: other open asks on the same card (initiative dry-run-tickets-before-build): [{ ini, id, text, title?, board?, owner? }] — the
52
+ * dry-run gaps of a ticket (lib/ticket-dry-run.js) and the outside sign-offs with no answer (lib/signoffs.js). */
53
+ function questionsOf(held, { pm = 'PM', extra = [] } = {}) {
52
54
  const by = new Map();
53
55
  for (const h of held || []) {
54
56
  if (!isObj(h) || !isObj(h.prop) || !h.ini) continue;
@@ -58,10 +60,20 @@ function questionsOf(held, { pm = 'PM' } = {}) {
58
60
  q.ids.push(h.prop.id);
59
61
  q.parts.push(partOf(h.prop, h.hold));
60
62
  }
63
+ for (const x of extra || []) {
64
+ if (!isObj(x) || !x.ini || !x.id || !x.text) continue;
65
+ const owner = one(x.owner || '', 60), key = (owner || '') + '|' + x.ini;
66
+ if (!by.has(key)) by.set(key, { key, owner: owner || pm, toPm: !owner, ini: x.ini, title: x.title || x.ini, board: x.board || '', parts: [], ids: [] });
67
+ const q = by.get(key);
68
+ q.ids.push(x.id);
69
+ q.parts.push(one(x.text, 400));
70
+ q.asks = (q.asks || 0) + 1;
71
+ }
61
72
  const out = [...by.values()].map((q) => {
62
73
  const shown = q.parts.slice(0, 3), more = q.parts.length - shown.length;
74
+ const moreWord = q.asks ? plural(more, 'more question', 'more questions') : plural(more, 'more change', 'more changes');
63
75
  return { key: q.key, owner: q.owner, toPm: q.toPm, ini: q.ini, title: q.title, board: q.board, ids: q.ids, n: q.ids.length,
64
- text: shown.join(' ') + (more > 0 ? ` And ${plural(more, 'more change', 'more changes')}.` : '') };
76
+ text: shown.join(' ') + (more > 0 ? ` And ${moreWord}.` : '') };
65
77
  });
66
78
  return out.sort((a, b) => (a.toPm === b.toPm ? 0 : a.toPm ? -1 : 1) || a.title.localeCompare(b.title) || a.owner.localeCompare(b.owner));
67
79
  }
@@ -75,17 +87,19 @@ function readDays(stateDir) {
75
87
  }
76
88
 
77
89
  /** The list fixed for `day`. The first read of a day writes its line; later reads that day keep it. */
78
- function today(stateDir, held, { day, pm, now } = {}) {
90
+ function today(stateDir, held, { day, pm, now, extra = [] } = {}) {
79
91
  const list = (held || []).filter((h) => isObj(h) && isObj(h.prop) && h.prop.id);
80
- if (!day) return { day: '', questions: questionsOf(list, { pm }), later: 0 };
92
+ const asks = (extra || []).filter((x) => isObj(x) && x.id && x.ini && x.text);
93
+ if (!day) return { day: '', questions: questionsOf(list, { pm, extra: asks }), later: 0 };
81
94
  let fixed = stateDir ? readDays(stateDir).filter((l) => l.day === day).pop() : null;
82
- if (!fixed && stateDir && list.length) {
83
- fixed = { day, at: new Date(now == null ? Date.now() : now).toISOString(), ids: [...new Set(list.map((h) => h.prop.id))].slice(0, MAX_IDS) };
95
+ if (!fixed && stateDir && (list.length || asks.length)) {
96
+ fixed = { day, at: new Date(now == null ? Date.now() : now).toISOString(), ids: [...new Set([...list.map((h) => h.prop.id), ...asks.map((x) => x.id)])].slice(0, MAX_IDS) };
84
97
  try { fs.mkdirSync(stateDir, { recursive: true }); fs.appendFileSync(path.join(stateDir, LEDGER), JSON.stringify(fixed) + '\n'); } catch { /* the list still shows; tomorrow tries again */ }
85
98
  }
86
99
  const on = new Set(fixed ? fixed.ids : []);
87
100
  const mine = fixed ? list.filter((h) => on.has(h.prop.id)) : list;
88
- return { day, questions: questionsOf(mine, { pm }), later: list.length - mine.length };
101
+ const mineAsks = fixed ? asks.filter((x) => on.has(x.id)) : asks;
102
+ return { day, questions: questionsOf(mine, { pm, extra: mineAsks }), later: list.length - mine.length + asks.length - mineAsks.length };
89
103
  }
90
104
 
91
105
  module.exports = { questionsOf, today, ownerOf, partOf, LEDGER };
@@ -49,6 +49,7 @@ const LOST_MS = 6 * 3600 * 1000; // a run with no live session and no end afte
49
49
  const READ_MS = 30 * 60 * 1000; // batch 31 item 6: a read of a tool (how 'tool') is stopped after this long, with the reason, so the next slot can run
50
50
  const SLOW_MS = 15 * 60 * 1000; // a read still working after this long shows as slow on its row
51
51
  const ALL_MS = 3 * 3600 * 1000; // a Refresh all that has not ended after this long is over: a new press starts a new one
52
+ const DAILY_MS = 20 * 3600 * 1000; // tracker-daily: a product workspace the pinned Jira read does not cover is read again once its last read is this old
52
53
  const DERIVED = Object.freeze(['leads', 'brief']); // what Refresh all writes again after the sources, in this order
53
54
  const DERIVED_LIST = Object.freeze(['scan', 'coredocs', 'leads', 'brief']); // what Sources lists as derived content: built from stored reads, never a tool
54
55
  const AUTH_RETRY_MS = 2 * 60 * 1000;
@@ -129,11 +130,16 @@ function create(host) {
129
130
  * initiative has a Jira ticket. It failed every morning ("The shared refresh session did not save a new read of it", "No initiative
130
131
  * has a Jira ticket or linked epic yet") while the workspace that holds the tickets was never read.
131
132
  */
132
- function wsFor(id, first) {
133
+ function wsFor(id, first, { only = false } = {}) {
133
134
  let list = null;
134
135
  if (host.sourceWs) { try { const l = host.sourceWs(id); if (Array.isArray(l)) list = [...new Set(l.filter(Boolean))]; } catch (e) { warn('source workspaces', e); } }
135
136
  if (!list) return first ? [first] : [];
136
- return first && list.includes(first) ? [first] : list;
137
+ if (!first || !list.includes(first)) return list;
138
+ if (only) return [first];
139
+ // tracker-daily (bet 1, proofs A77, 2026-11-22): a pinned workspace kept the read to one product, so the other products' tickets were
140
+ // never read again after their import. The pinned one keeps its rhythm; every other one is read when its last read is a day old.
141
+ const t = now();
142
+ return [first, ...list.filter((w) => w !== first && !readSince(id, w, t - DAILY_MS))];
137
143
  }
138
144
  const NOTHING_TO_READ = 'No initiative in any workspace has a Jira ticket or a linked epic yet, so there is nothing to read.';
139
145
 
@@ -590,7 +596,7 @@ function create(host) {
590
596
  R.writeState(dir, state);
591
597
  return { ok: true, source: id, waiting: busy, inputs: startedInputs };
592
598
  }
593
- const wss = wsFor(id, ws || (set.sources[id] && set.sources[id].ws) || host.homeWs());
599
+ const wss = wsFor(id, ws || (set.sources[id] && set.sources[id].ws) || host.homeWs(), { only: !!ws }); // a press in a workspace reads that one
594
600
  if (!wss.length) return { ok: false, status: 409, error: NOTHING_TO_READ };
595
601
  let r = null;
596
602
  for (const w of wss) { const r1 = start(src, w, { trigger: 'pressed' }); if (!r || (!r.ok && r1.ok)) r = r1; }
@@ -99,6 +99,7 @@ const B = require(repoScript('boards.js'));
99
99
  const WF = require(repoScript('workflows.js'));
100
100
  const WS = require('./workflows-store.js');
101
101
  const TI = require('./task-items.js');
102
+ const TJ = require('./task-jira.js'); // tracker-daily: imported tasks follow their Jira tickets
102
103
  const SW = require('./status-when.js');
103
104
  const TS = require('./task-store.js');
104
105
  const holdSpans = require('./hold-spans.js');
@@ -142,7 +143,7 @@ function readLedger(ctx, w) {
142
143
  const store = TS.storeFor(w && w.root);
143
144
  const key = statKey(f) + '|' + (store ? statKey(store.file) : 'none');
144
145
  const hit = ledgerMemo.get(f);
145
- if (hit && hit.key === key) return hit.lines.slice();
146
+ if (hit && hit.key === key) return withTracker(w, f, key, hit.lines);
146
147
  const board = readBoardLines(f);
147
148
  let lines = board;
148
149
  if (store) {
@@ -158,7 +159,26 @@ function readLedger(ctx, w) {
158
159
  }
159
160
  if (ledgerMemo.size > 100) ledgerMemo.clear();
160
161
  ledgerMemo.set(f, { key: statKey(f) + '|' + (store ? statKey(store.file) : 'none'), lines });
161
- return lines.slice();
162
+ return withTracker(w, f, key, lines);
163
+ }
164
+ /* tracker-daily (bet 1, proofs A77): a task whose title names a Jira key takes the state of the last Jira read when that read is newer
165
+ * (lib/task-jira.js trackerLines). The lines are added in memory, after the ledger's own lines, and never written; they change again
166
+ * with each read. Kept per ledger and per set of Jira snapshots. */
167
+ const trackerMemo = new Map();
168
+ function jiraSig(w) {
169
+ try { const d = jiraTickets.jiraDir(w.root); return fs.readdirSync(d).filter((n) => n.endsWith('.md') && !n.endsWith('-tickets.md') && !n.startsWith('_')).sort().map((n) => n + ':' + fs.statSync(path.join(d, n)).mtimeMs).join(','); } catch { return 'none'; }
170
+ }
171
+ function withTracker(w, f, key, lines) {
172
+ if (!w || !w.root) return lines.slice();
173
+ const k = key + '|' + jiraSig(w);
174
+ const hit = trackerMemo.get(f);
175
+ if (hit && hit.key === k) return hit.lines.slice();
176
+ let extra = [];
177
+ try { extra = TJ.trackerLines(lines, (ini) => jiraStatus.readSnapshot(w.root, ini)); } catch { extra = []; }
178
+ const all = extra.length ? lines.concat(extra) : lines;
179
+ if (trackerMemo.size > 100) trackerMemo.clear();
180
+ trackerMemo.set(f, { key: k, lines: all });
181
+ return all.slice();
162
182
  }
163
183
  function append(file, actor, ev) {
164
184
  const line = { at: new Date().toISOString(), by: actor.by, ...ev };
@@ -797,6 +817,7 @@ function itemsOf(w, fr, board, rows) {
797
817
  }
798
818
  for (const t of fr.folded.tasks.values()) if (t.board === board.id && ids.has(t.initiative)) out.push(B.taskItem(t));
799
819
  out.push(...TI.rowsOf(w.root, ids, board.id)); // one kind of task: an initiative's breakdown items show as its tasks (lib/task-items.js)
820
+ trackerMarks(w, out);
800
821
  for (const x of out) if (x.src === 'jira') x.notes = (fr.folded.ticketNotes && fr.folded.ticketNotes.get(board.id + '\u0000' + x.key)) || ''; // the PM's notes (canvas XetX1Jira)
801
822
  // the PM's own days for a Jira ticket (batch 11 item 23): kept in PMOS, they win over Jira's, and the row says so
802
823
  const TD = fr.folded.ticketDates || new Map();
@@ -841,6 +862,20 @@ function itemsOf(w, fr, board, rows) {
841
862
  return B.rollupItems(out);
842
863
  }
843
864
 
865
+ /** tracker-daily: a PMOS task that names a Jira key carries `tracker` { key, status, readAt, stale }: Jira's status at the last read, and
866
+ * stale when that read is older than a day or did not return the ticket (lib/task-jira.js staleOf). Its state is already the read's
867
+ * (readLedger). A page or a forecast says "not read since" instead of trusting a stale state. */
868
+ function trackerMarks(w, items) {
869
+ const snaps = new Map(), now = Date.now();
870
+ for (const x of items) {
871
+ if (x.src !== 'pmos' || x.kind === 'Epic') continue;
872
+ const key = TJ.keyOf(x.title);
873
+ if (!key) continue;
874
+ if (!snaps.has(x.ini)) { let sn = null; try { sn = jiraStatus.readSnapshot(w.root, x.ini); } catch { sn = null; } snaps.set(x.ini, sn); }
875
+ const sn = snaps.get(x.ini), rd = sn && sn.tickets ? sn.tickets.get(key) : null;
876
+ x.tracker = { key, status: (rd && rd.status) || null, readAt: (sn && sn.fetchedAt) || null, stale: TJ.staleOf([key], sn, now).stale };
877
+ }
878
+ }
844
879
  /** The Jira items of an initiative PMOS pushed nothing for: its linked epics and the issues under them, from the last
845
880
  * read of the Jira status check (lib/jira-status.js, epic mode). An issue under no linked epic hangs under the first. */
846
881
  function epicItems(row, board, snap, seen, out) {
@@ -77,8 +77,14 @@ function control(ctx, q, o = {}) {
77
77
  try { const f = require('./routes-boards.js').ledgerFile(ctx, w); if (f) lines.push(...readJsonl(f).filter((e) => e && (e.kind === 'task' || e.kind === 'task-update'))); } catch { /* none */ }
78
78
  lines.sort((a, b) => String(a.at || '').localeCompare(String(b.at || '')));
79
79
  const baseline = KC.baselineOf(lines, new Set(tasks.map((x) => x.uid || x.key)), baselineAt);
80
+ // tracker-daily: whether the tasks that name Jira tickets rest on a stale read (lib/task-jira.js)
81
+ let stale = null;
82
+ try {
83
+ const TJ = require('./task-jira.js'), keys = tasks.filter((x) => x.status !== 'Done' && x.status !== "Won't do" && x.status !== 'Archived').map((x) => TJ.keyOf(x.title)).filter(Boolean);
84
+ if (keys.length) stale = TJ.staleOf(keys, require('./jira-status.js').readSnapshot(w.root, id), o.now || Date.now());
85
+ } catch { stale = null; }
80
86
  const m = KC.project({ today, title: fm.title || (row && row.title) || id, goal: goal ? { id: goal.id, title: goal.title, byAt: goal.byAt } : null, end: row && row.end,
81
- record: fm, tasks, links: snap.links || [], baseline, baselineAt, people });
87
+ record: fm, tasks, links: snap.links || [], baseline, baselineAt, people, stale });
82
88
  return okBody({ ...m, ...(line ? { line } : {}) });
83
89
  }
84
90
 
@@ -15,7 +15,8 @@
15
15
  * staleOf), and `expired` lists the ones of the last 7 days, so Your move says it once. Idempotent: an expired proposal folds as dropped.
16
16
  * DONE (C2, board CsD): what an agent kept by itself in the last 14 days, one line per batch with its Undo (lib/done-feed.js).
17
17
  * QUESTIONS (act-alone-only-with-a-source): { day, questions: [lib/question-batch.js question], later } — the changes PMOS holds for want
18
- * of a source, one question per owner and initiative, the PM's first; the list is fixed for the day (one line in question-days.jsonl). */
18
+ * of a source, one question per owner and initiative, the PM's first; the list is fixed for the day (one line in question-days.jsonl).
19
+ * On the same card (dry-run-tickets-before-build): the dry-run gaps of drafted tickets and the outside sign-offs with no answer. */
19
20
  const YM = require('./your-move.js');
20
21
 
21
22
  const localDay = (ms = Date.now()) => { const d = new Date(ms); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
@@ -69,12 +70,30 @@ function expire(ctx, w, now = Date.now()) {
69
70
  * initiative, fixed once a day (lib/question-batch.js). Questions for teammates are drafts: nothing is sent. */
70
71
  function questions(ctx, w, today) {
71
72
  const dir = ctx.stateDirFor ? ctx.stateDirFor(w) : null;
72
- const held = require('./routes-proposals.js').heldOf(ctx, w);
73
- return require('./question-batch.js').today(dir, held, { day: today });
73
+ let held = [];
74
+ try { held = require('./routes-proposals.js').heldOf(ctx, w); } catch { held = []; }
75
+ let extra = [];
76
+ try { extra = asksOf(w.root); } catch { extra = []; }
77
+ return require('./question-batch.js').today(dir, held, { day: today, extra });
78
+ }
79
+
80
+ /** The other asks on the same card (dry-run-tickets-before-build): each ticket's dry-run gaps nobody answered (lib/ticket-dry-run.js),
81
+ * and the outside sign-offs that waited too long (lib/signoffs.js). Both are the PM's to chase: nothing is sent. */
82
+ function asksOf(root, now = Date.now()) {
83
+ const JT = require('./jira-tickets.js'), SO = require('./signoffs.js');
84
+ const out = [];
85
+ for (const ini of JT.dryRunInitiatives(root)) {
86
+ const title = (JT.recordFm(root, ini) || {}).title || ini;
87
+ for (const g of JT.dryRunGaps(root, ini)) out.push({ ini, title, id: `dry:${ini}:${g.ticket}:${g.n}`, text: `Ticket ${g.ticket}: ${/[?.]$/.test(g.q) ? g.q : g.q + '?'}` });
88
+ }
89
+ for (const p of SO.partsOf(SO.list(SO.fileOf(JT.stateDirOf(root)), { open: true }), now)) {
90
+ out.push({ ini: p.ini, title: (JT.recordFm(root, p.ini) || {}).title || p.ini, id: p.id, text: p.text });
91
+ }
92
+ return out;
74
93
  }
75
94
 
76
95
  module.exports = {
77
- expire, questions,
96
+ expire, questions, asksOf,
78
97
  prefixes: ['/api/your-move'],
79
98
  handle: async (req, res, url, ctx) => {
80
99
  if (url.pathname !== '/api/your-move') return false;
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+ /* signoff-cli.js — `pmos signoff …`: the outside sign-offs an initiative waits on (initiative dry-run-tickets-before-build; A188).
3
+ *
4
+ * pmos signoff ask <initiative> --who "<name or team>" --what "<what they must say yes to>" [--asked YYYY-MM-DD] [--due YYYY-MM-DD] [--source <pointer>]
5
+ * pmos signoff answer <id> --answer "<what they said>" --source <pointer>
6
+ * pmos signoff drop <id> [--why "<why it is no longer needed>"]
7
+ * pmos signoff list [<initiative>] [--all]
8
+ * every command: [--json] [--root <dir>]
9
+ *
10
+ * The ledger is <state>/tracker/signoffs.jsonl (lib/signoffs.js). An open sign-off that waited 3 days, or is past its due date, goes
11
+ * on the PM's question list for the day (GET /api/your-move questions), beside the dry-run gaps. This command sends nothing.
12
+ * Exit codes: 0 done, 1 refused, 2 usage.
13
+ */
14
+ const path = require('path');
15
+ const { execFileSync } = require('child_process');
16
+ const { parseArgs } = require('./schedule-cli');
17
+ const SO = require('./signoffs.js');
18
+ const jiraTickets = require('./jira-tickets.js');
19
+
20
+ const COMMANDS = { signoff: ['ask', 'answer', 'drop', 'list'] };
21
+ const USAGE = [
22
+ 'usage: pmos signoff ask|answer|drop|list — the outside sign-offs an initiative waits on',
23
+ ' pmos signoff ask <initiative> --who "<name or team>" --what "<what they must say yes to>" [--asked <date>] [--due <date>] [--source <pointer>]',
24
+ ' pmos signoff answer <id> --answer "<what they said>" --source <pointer> only with a pointer to where they said it',
25
+ ' pmos signoff drop <id> [--why "<reason>"] the sign-off is no longer needed',
26
+ ' pmos signoff list [<initiative>] [--all] the open sign-offs (--all: answered and dropped too)',
27
+ ' every command: [--json] [--root <dir>]',
28
+ 'An open sign-off that waited 3 days, or is past its due date, goes on your question list for the day. Nothing is sent.',
29
+ ];
30
+ const BOOL = new Set(['json', 'help', 'all']);
31
+ const VALUE = new Set(['who', 'what', 'asked', 'due', 'source', 'answer', 'why', 'root']);
32
+
33
+ function repoRoot(cwd) {
34
+ try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; }
35
+ catch { return cwd; }
36
+ }
37
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
38
+ const md = (d) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(d || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
39
+ const lineOf = (s) => `${s.id} · ${s.ini} · ${s.who}: ${s.what} · asked ${md(s.asked)}${s.due ? ` · due ${md(s.due)}` : ''}${s.state === 'answered' ? ` · answered: ${s.answer}` : s.state === 'dropped' ? ' · dropped' : ''}`;
40
+
41
+ function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), now } = {}) {
42
+ const args = argv[0] === 'signoff' ? argv.slice(1) : argv.slice();
43
+ const verb = args[0];
44
+ const rest = [], bools = {};
45
+ for (const a of args.slice(1)) { if (a.startsWith('--') && BOOL.has(a.slice(2))) bools[a.slice(2)] = true; else rest.push(a); }
46
+ const { pos, flags: f0 } = parseArgs(rest);
47
+ const flags = { ...f0, ...bools };
48
+ if (!verb || verb === 'help' || verb === '--help' || flags.help) { for (const l of USAGE) say(l); return verb ? 0 : 2; }
49
+ if (!COMMANDS.signoff.includes(verb)) { say(`unknown signoff command "${verb}" — one of ${COMMANDS.signoff.join(', ')}`); return 2; }
50
+ for (const k of Object.keys(flags)) {
51
+ if (!BOOL.has(k) && !VALUE.has(k)) { say(`unknown option --${k}`); return 2; }
52
+ if (VALUE.has(k) && flags[k] === '') { say(`--${k} needs a value`); return 2; }
53
+ }
54
+ const json = !!flags.json;
55
+ const root = flags.root ? path.resolve(cwd, flags.root) : repoRoot(cwd);
56
+ const t = now == null ? Date.now() : typeof now === 'function' ? +now() : +now;
57
+ const fail = (error, code = 1) => { if (json) say(JSON.stringify({ ok: false, error })); else say(`✗ ${error}`); return code; };
58
+ const out = (r, lines) => { if (json) say(JSON.stringify(r)); else for (const l of lines) say(l); return 0; };
59
+ const need = (what) => { say(`usage: pmos signoff ${verb} ${what}`); return 2; };
60
+ let file;
61
+ try { file = SO.fileOf(jiraTickets.stateDirOf(root)); } catch (e) { return fail(String((e && e.message) || e)); }
62
+
63
+ if (verb === 'ask') {
64
+ const ini = pos[0];
65
+ if (!ini || !flags.who || !flags.what) return need('<initiative> --who "<name or team>" --what "<what they must say yes to>" [--asked <date>] [--due <date>] [--source <pointer>]');
66
+ if (!jiraTickets.recordFm(root, ini)) return fail(`no initiative ${ini} in this repository`);
67
+ const r = SO.ask(file, { ini, who: flags.who, what: flags.what, asked: flags.asked, due: flags.due, source: flags.source }, t);
68
+ if (!r.ok) return fail(r.error);
69
+ return out(r, [`${r.already ? 'already open' : 'recorded'}: ${lineOf(r.signoff)}`]);
70
+ }
71
+ if (verb === 'answer') {
72
+ if (!pos[0] || !flags.answer || !flags.source) return need('<id> --answer "<what they said>" --source <pointer>');
73
+ const r = SO.answer(file, pos[0], { answer: flags.answer, source: flags.source }, t);
74
+ if (!r.ok) return fail(r.error);
75
+ return out(r, [`answered: ${lineOf(r.signoff)}`]);
76
+ }
77
+ if (verb === 'drop') {
78
+ if (!pos[0]) return need('<id> [--why "<reason>"]');
79
+ const r = SO.drop(file, pos[0], { why: flags.why }, t);
80
+ if (!r.ok) return fail(r.error);
81
+ return out(r, [`dropped: ${lineOf(r.signoff)}`]);
82
+ }
83
+ const L = SO.list(file, { ini: pos[0], open: !flags.all });
84
+ return out({ ok: true, signoffs: L }, L.length ? L.map(lineOf) : [`no ${flags.all ? '' : 'open '}sign-off${pos[0] ? ` for ${pos[0]}` : ''}`]);
85
+ }
86
+
87
+ module.exports = { run, COMMANDS, USAGE };
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+ /* signoffs.js — outside sign-offs: who outside the team must say yes before the work can go on (initiative
3
+ * dry-run-tickets-before-build; A188 in pmos-ideas/proofs). On the PSLE launch, 4 sign-offs (scope from Marketing, contract wording,
4
+ * Commerce's go or no-go, the add-on price) sat under a launch 5 days away with no answer recorded and nothing chasing them.
5
+ *
6
+ * One line per sign-off: who, what, asked on, due, and the answer. The Driver records them from the PRD and the notes, and records an
7
+ * answer only with a pointer to where it was given. An open sign-off that has waited WAIT_DAYS, or whose due date passed, goes on the
8
+ * owner's daily question list (lib/question-batch.js), on the same card as the dry-run gaps. Nothing here sends anything.
9
+ *
10
+ * ask(file, { ini, who, what, asked, due, source }, now) → { ok, signoff } | { ok: false, error }
11
+ * answer(file, id, { answer, source }, now) → { ok, signoff } | { ok: false, error }
12
+ * drop(file, id, { why }, now) → { ok, signoff } | { ok: false, error }
13
+ * list(file, { ini, open }) → [signoff] the ledger folded, oldest ask first
14
+ * partsOf(list, now) → [{ ini, id, text }] PURE: the open sign-offs to ask about today
15
+ * fileOf(stateDir) → <state>/tracker/signoffs.jsonl
16
+ *
17
+ * THE LEDGER is append-only, one JSON line per act: { op: 'ask' | 'answer' | 'drop', id, … , at }. A signoff:
18
+ * { id, ini, who, what, asked, due, source, state: 'open' | 'answered' | 'dropped', answer, answerSource, answeredAt, why }.
19
+ */
20
+ const fs = require('fs');
21
+ const path = require('path');
22
+ const crypto = require('crypto');
23
+
24
+ const DAY = 864e5;
25
+ const WAIT_DAYS = 3;
26
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
27
+ const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
28
+ const INI_RE = /^[a-z0-9][a-z0-9._-]{0,80}$/i;
29
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
30
+ const one = (v, n) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n);
31
+ const isoDay = (t) => new Date(t).toISOString().slice(0, 10);
32
+ const md = (d) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(d || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
33
+ const dayMs = (d) => Date.parse(String(d) + 'T00:00:00Z');
34
+
35
+ function fileOf(stateDir) { return path.join(stateDir, 'tracker', 'signoffs.jsonl'); }
36
+
37
+ function readLines(file) {
38
+ let text = '';
39
+ try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
40
+ const out = [];
41
+ for (const raw of text.split('\n')) { if (!raw.trim()) continue; try { const l = JSON.parse(raw); if (isObj(l) && l.id && l.op) out.push(l); } catch { /* a torn line is skipped */ } }
42
+ return out;
43
+ }
44
+ function append(file, line) {
45
+ fs.mkdirSync(path.dirname(file), { recursive: true });
46
+ fs.appendFileSync(file, JSON.stringify(line) + '\n');
47
+ }
48
+
49
+ /** The ledger folded into one sign-off per id. */
50
+ function fold(lines) {
51
+ const by = new Map();
52
+ for (const l of lines) {
53
+ if (l.op === 'ask') { if (!by.has(l.id)) by.set(l.id, { id: l.id, ini: l.ini, who: l.who, what: l.what, asked: l.asked || null, due: l.due || null, source: l.source || null, state: 'open', at: l.at }); continue; }
54
+ const s = by.get(l.id); if (!s) continue;
55
+ if (l.op === 'answer') Object.assign(s, { state: 'answered', answer: l.answer, answerSource: l.source || null, answeredAt: l.at });
56
+ else if (l.op === 'drop') Object.assign(s, { state: 'dropped', why: l.why || null, droppedAt: l.at });
57
+ else if (l.op === 'reopen') Object.assign(s, { state: 'open', answer: undefined, answerSource: undefined, answeredAt: undefined });
58
+ }
59
+ return [...by.values()];
60
+ }
61
+
62
+ function list(file, { ini, open } = {}) {
63
+ return fold(readLines(file)).filter((s) => (!ini || s.ini === ini) && (!open || s.state === 'open'))
64
+ .sort((a, b) => String(a.asked || a.at).localeCompare(String(b.asked || b.at)));
65
+ }
66
+
67
+ function ask(file, { ini, who, what, asked, due, source } = {}, now = Date.now()) {
68
+ const I = one(ini, 81), W = one(who, 80), X = one(what, 200);
69
+ if (!INI_RE.test(I)) return { ok: false, error: 'a sign-off needs the initiative it holds up' };
70
+ if (!W || !/\p{L}/u.test(W)) return { ok: false, error: 'a sign-off needs who must give it (a name or a team)' };
71
+ if (!X) return { ok: false, error: 'a sign-off needs what they must say yes to' };
72
+ for (const [k, v] of [['asked', asked], ['due', due]]) if (v != null && v !== '' && !DATE_RE.test(String(v))) return { ok: false, error: `--${k} is a date like 2026-11-06` };
73
+ const id = 's-' + crypto.createHash('sha1').update(I + '|' + W.toLowerCase() + '|' + X.toLowerCase()).digest('hex').slice(0, 8);
74
+ const have = fold(readLines(file)).find((s) => s.id === id);
75
+ if (have && have.state === 'open') return { ok: true, signoff: have, already: true };
76
+ const line = { op: 'ask', id, ini: I, who: W, what: X, asked: asked || isoDay(now), due: due || null, source: one(source, 300) || null, at: new Date(now).toISOString() };
77
+ if (have) append(file, { op: 'reopen', id, at: line.at }); else append(file, line);
78
+ return { ok: true, signoff: fold(readLines(file)).find((s) => s.id === id) };
79
+ }
80
+
81
+ function act(file, id, op, extra, now) {
82
+ const s = fold(readLines(file)).find((x) => x.id === id);
83
+ if (!s) return { ok: false, error: `no sign-off ${id}` };
84
+ if (s.state !== 'open') return { ok: false, error: `sign-off ${id} is already ${s.state}` };
85
+ append(file, { op, id, ...extra, at: new Date(now).toISOString() });
86
+ return { ok: true, signoff: fold(readLines(file)).find((x) => x.id === id) };
87
+ }
88
+ function answer(file, id, { answer: a, source } = {}, now = Date.now()) {
89
+ const text = one(a, 500);
90
+ if (!text) return { ok: false, error: 'an answer needs what they said' };
91
+ return act(file, id, 'answer', { answer: text, source: one(source, 300) || null }, now);
92
+ }
93
+ function drop(file, id, { why } = {}, now = Date.now()) { return act(file, id, 'drop', { why: one(why, 300) || null }, now); }
94
+
95
+ /** The open sign-offs to ask about today: waited WAIT_DAYS or more since asked, or past their due date. PURE. */
96
+ function partsOf(signoffs, now = Date.now()) {
97
+ const today = dayMs(isoDay(now));
98
+ const out = [];
99
+ for (const s of signoffs || []) {
100
+ if (!isObj(s) || s.state !== 'open') continue;
101
+ const asked = s.asked ? dayMs(s.asked) : NaN, due = s.due ? dayMs(s.due) : NaN;
102
+ const waited = Number.isFinite(asked) ? Math.floor((today - asked) / DAY) : null;
103
+ const late = Number.isFinite(due) && due < today;
104
+ if (!late && !(waited != null && waited >= WAIT_DAYS)) continue;
105
+ const text = late ? `${s.who}'s yes on "${s.what}" was due ${md(s.due)}. Did it come?`
106
+ : `Did ${s.who} answer "${s.what}"? Asked ${md(s.asked)}, ${waited} days ago.`;
107
+ out.push({ ini: s.ini, id: 'signoff:' + s.id, text, signoff: s.id });
108
+ }
109
+ return out;
110
+ }
111
+
112
+ module.exports = { ask, answer, drop, list, partsOf, fileOf, fold, WAIT_DAYS };
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+ /* task-jira.js — a PMOS task that names a Jira ticket follows the ticket's state (bet 1, "read the tracker daily and never forecast
3
+ * from stale states"; proofs A77-states and A77-five-products, 2026-11-22).
4
+ *
5
+ * WHY. Tasks imported from Jira carry the ticket key at the start of their title ("IDPF-2746 · Send verification email"). PMOS read
6
+ * Jira only for the tickets it pushed itself or the issues under a linked epic, so these tasks kept the state of the day they were
7
+ * imported. On 22 Nov PMOS showed as open 69 of 109 such Scarlet tasks, 5 of 16 on OOH Digital and 142 of 359 on idpf that Jira had
8
+ * closed, and forecast from them. CAS matched (0 of 13). Here such a task joins the Jira read, and the read sets its state.
9
+ *
10
+ * keyOf(title) → 'IDPF-2746' | null the Jira key a title starts with
11
+ * keyedTasks(lines) PURE → Map task id → { task, initiative, key, state, stateAt } from task ledger lines
12
+ * keysByInitiative(lines) PURE → Map initiative → [key] the keys a Jira read must cover (lib/jira-status.js queryFor)
13
+ * readKeys(root) → the same, from the repository's task ledger (lib/task-store.js)
14
+ * stateOf(reading) PURE → 'To do' | 'In progress' | 'Done' | "Won't do" a Jira reading as a task state
15
+ * trackerLines(lines, snapOf) PURE → [task-update line] the state changes the last Jira read makes (see THE RULE). They are
16
+ * added to the folded lines in memory (lib/routes-boards.js readLedger) and never written to a file
17
+ * staleOf(keys, snap, now) PURE → { stale, since, keys } whether the read these keys rest on is older than STALE_MS
18
+ *
19
+ * THE RULE. The read sets the state of a task nobody changed since it was made or imported. When someone changed the state in PMOS, the
20
+ * read wins only when it is newer and Jira moved the ticket after that change (its last update or its resolution day); a read with
21
+ * neither time may only close the task. So a task the PM reopened stays open until Jira moves. A reading the search did not return
22
+ * (marked stale) changes nothing.
23
+ * STALE. The Jira read is due every day: a read older than 26 hours (lib/freshness.js, jira stale_after_ms) is stale, and so is a task
24
+ * key no read has covered yet. A forecast never rests on a stale read (lib/forecast.js, lib/kind-control.js).
25
+ *
26
+ * BOUNDARY. No network, no write: the only input is the ledger lines and the stored Jira snapshots.
27
+ */
28
+ const H = 3600 * 1000;
29
+ const STALE_MS = 26 * H;
30
+ const BY = 'tracker:jira';
31
+ const LEAD_KEY = /^\s*\[?([A-Z][A-Z0-9_]{0,19}-\d{1,7})\]?(?![A-Za-z0-9-])/;
32
+ const CLOSED_NOT_DONE = /invalid|not an issue|won'?t|cancel|duplicate|reject|obsolete|not (?:needed|required|a bug)|declined|abandon/i;
33
+ const TASK_KINDS = new Set(['task', 'task-update', 'task-remove', 'task-restore']);
34
+
35
+ /** The Jira key a task title starts with, upper case; null when it names none. */
36
+ const NOT_TICKETS = /^(CVE|CWE|GHSA|RFC|ISO|SOC|PCI|COVID|ES|TLS|SHA|UTF|AES|RSA|HTTP)-/; // advisory, standard and version ids, not tickets
37
+ function keyOf(title) {
38
+ const m = LEAD_KEY.exec(String(title == null ? '' : title));
39
+ return m && !NOT_TICKETS.test(m[1]) ? m[1] : null;
40
+ }
41
+ const ms = (s) => { const t = Date.parse(String(s || '')); return Number.isFinite(t) ? t : 0; };
42
+
43
+ /** Every task of the ledger lines whose title names a Jira key, folded the way scripts/boards.js folds tasks (first `task` line wins,
44
+ * `task-update` changes it, `task-remove` takes it out and `task-restore` puts it back). */
45
+ function keyedTasks(lines) {
46
+ const all = new Map(); const removed = new Map();
47
+ for (const e of lines || []) {
48
+ if (!e || typeof e !== 'object' || !TASK_KINDS.has(e.kind) || typeof e.task !== 'string') continue;
49
+ if (e.kind === 'task') {
50
+ if (all.has(e.task) || typeof e.initiative !== 'string') continue;
51
+ // stateAt is the time someone CHANGED the state: the state a task was created (or imported) with is no decision
52
+ all.set(e.task, { task: e.task, initiative: e.initiative, title: String(e.title || ''), state: e.state || 'To do', stateAt: null });
53
+ } else if (e.kind === 'task-update') {
54
+ const t = all.get(e.task); if (!t) continue;
55
+ if (typeof e.initiative === 'string' && e.initiative) t.initiative = e.initiative;
56
+ if (typeof e.title === 'string' && e.title.trim()) t.title = e.title.trim();
57
+ if (typeof e.state === 'string' && e.state) { t.state = e.state === 'In review' ? 'In progress' : e.state; t.stateAt = e.at || t.stateAt; }
58
+ } else if (e.kind === 'task-remove') {
59
+ if (all.has(e.task)) { removed.set(e.task, all.get(e.task)); all.delete(e.task); }
60
+ } else if (e.kind === 'task-restore') {
61
+ if (removed.has(e.task) && !all.has(e.task)) { all.set(e.task, removed.get(e.task)); removed.delete(e.task); }
62
+ }
63
+ }
64
+ const out = new Map();
65
+ for (const t of all.values()) { const key = keyOf(t.title); if (key) out.set(t.task, { ...t, key }); }
66
+ return out;
67
+ }
68
+
69
+ /** The keys each initiative's tasks name, sorted. Archived tasks are left out: nobody plans them. */
70
+ function keysByInitiative(lines) {
71
+ const by = new Map();
72
+ for (const t of keyedTasks(lines).values()) {
73
+ if (t.state === 'Archived') continue;
74
+ if (!by.has(t.initiative)) by.set(t.initiative, new Set());
75
+ by.get(t.initiative).add(t.key);
76
+ }
77
+ return new Map([...by].map(([k, v]) => [k, [...v].sort()]));
78
+ }
79
+ /** keysByInitiative from the repository's own task ledger; an empty Map when it cannot be read. */
80
+ function readKeys(root) {
81
+ let raw = null;
82
+ try { raw = require('./task-store.js').readStore(root); } catch { raw = null; }
83
+ const lines = [];
84
+ for (const x of raw || []) { if (typeof x !== 'string') { lines.push(x); continue; } try { lines.push(JSON.parse(x)); } catch { /* a torn line */ } }
85
+ return keysByInitiative(lines);
86
+ }
87
+
88
+ /** A Jira reading as a task state. */
89
+ function stateOf(rd) {
90
+ if (!rd) return null;
91
+ const s = String(rd.status || ''), cat = String(rd.category || '').toLowerCase();
92
+ const done = cat === 'done' || /\b(done|closed|resolved|released|complete|shipped|deployed)\b/i.test(s) || CLOSED_NOT_DONE.test(s);
93
+ if (done) return CLOSED_NOT_DONE.test(s) ? "Won't do" : 'Done';
94
+ if (cat === 'doing' || cat === 'indeterminate' || /progress|doing|review|\bqa\b|test|block|started|verif|\buat\b/i.test(s)) return 'In progress';
95
+ return 'To do';
96
+ }
97
+
98
+ /**
99
+ * The task-update lines the last Jira read makes. snapOf(initiative) → { fetchedAt, tickets: Map } | null (lib/jira-status.js
100
+ * readSnapshot). Each line is { at: the read's time, by: 'tracker:jira', kind: 'task-update', task, state, why, tracker: true }.
101
+ */
102
+ function trackerLines(lines, snapOf) {
103
+ const out = []; const snaps = new Map();
104
+ const snap = (ini) => { if (!snaps.has(ini)) { let s = null; try { s = snapOf(ini) || null; } catch { s = null; } snaps.set(ini, s); } return snaps.get(ini); };
105
+ for (const t of keyedTasks(lines).values()) {
106
+ if (t.state === 'Archived') continue;
107
+ const s = snap(t.initiative);
108
+ if (!s || !s.fetchedAt || !s.tickets || !s.tickets.get) continue;
109
+ const rd = s.tickets.get(t.key);
110
+ if (!rd || rd.stale) continue;
111
+ const want = stateOf(rd);
112
+ if (!want || want === t.state) continue;
113
+ const readAt = ms(s.fetchedAt), changed = ms(t.stateAt);
114
+ if (!readAt || readAt <= changed) continue; // the PM (or an agent) changed the task after the read
115
+ if (changed) {
116
+ // someone changed the state in PMOS: Jira wins only when it moved after that (its last update or resolution), or, when the read
117
+ // carries neither time, only to close the task
118
+ const jiraAt = Math.max(ms(rd.updated), ms(rd.resolved));
119
+ const closes = want === 'Done' || want === "Won't do";
120
+ if (jiraAt ? jiraAt <= changed : !closes) continue;
121
+ }
122
+ out.push({ at: s.fetchedAt, by: BY, kind: 'task-update', task: t.task, state: want, tracker: true,
123
+ why: `Jira says ${String(rd.status || want).slice(0, 40)} (${t.key}, read ${String(s.fetchedAt).slice(0, 16).replace('T', ' ')} UTC)` });
124
+ }
125
+ return out.sort((a, b) => String(a.at).localeCompare(String(b.at)));
126
+ }
127
+
128
+ /** Whether the read `keys` rest on is stale: no read, a read older than STALE_MS, or keys the read did not return. */
129
+ function staleOf(keys, snap, now = Date.now()) {
130
+ const list = [...new Set((keys || []).filter(Boolean))];
131
+ if (!list.length) return { stale: false, since: null, keys: [] };
132
+ if (!snap || !snap.fetchedAt) return { stale: true, since: null, keys: list };
133
+ const old = now - ms(snap.fetchedAt) > STALE_MS;
134
+ const missing = list.filter((k) => { const r = snap.tickets && snap.tickets.get ? snap.tickets.get(k) : null; return !r || r.stale; });
135
+ return { stale: old || missing.length > 0, since: snap.fetchedAt, keys: old ? list : missing };
136
+ }
137
+
138
+ module.exports = { STALE_MS, BY, keyOf, keyedTasks, keysByInitiative, readKeys, stateOf, trackerLines, staleOf };