create-pmos 0.820.0 → 0.821.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.
@@ -4,6 +4,8 @@
4
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
5
  * pmos signoff answer <id> --answer "<what they said>" --source <pointer>
6
6
  * pmos signoff drop <id> [--why "<why it is no longer needed>"]
7
+ * pmos signoff evidence <id> --ref <file or Jira key> --quote "<the line, word for word>" [--doc <the document it agrees to>]
8
+ * where the yes is written (factory-signoffs-reach-you): Today's ✓ records it only when the quote is in the source
7
9
  * pmos signoff list [<initiative>] [--all]
8
10
  * every command: [--json] [--root <dir>]
9
11
  *
@@ -17,18 +19,19 @@ const { parseArgs } = require('./schedule-cli');
17
19
  const SO = require('./signoffs.js');
18
20
  const jiraTickets = require('./jira-tickets.js');
19
21
 
20
- const COMMANDS = { signoff: ['ask', 'answer', 'drop', 'list'] };
22
+ const COMMANDS = { signoff: ['ask', 'answer', 'drop', 'evidence', 'list'] };
21
23
  const USAGE = [
22
- 'usage: pmos signoff ask|answer|drop|list — the outside sign-offs an initiative waits on',
24
+ 'usage: pmos signoff ask|answer|drop|evidence|list — the outside sign-offs an initiative waits on',
23
25
  ' pmos signoff ask <initiative> --who "<name or team>" --what "<what they must say yes to>" [--asked <date>] [--due <date>] [--source <pointer>]',
24
26
  ' pmos signoff answer <id> --answer "<what they said>" --source <pointer> only with a pointer to where they said it',
25
27
  ' pmos signoff drop <id> [--why "<reason>"] the sign-off is no longer needed',
28
+ ' pmos signoff evidence <id> --ref <file or Jira key> --quote "<line>" [--doc <file>] where the yes is written; Today checks it before ✓',
26
29
  ' pmos signoff list [<initiative>] [--all] the open sign-offs (--all: answered and dropped too)',
27
30
  ' every command: [--json] [--root <dir>]',
28
31
  '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
32
  ];
30
33
  const BOOL = new Set(['json', 'help', 'all']);
31
- const VALUE = new Set(['who', 'what', 'asked', 'due', 'source', 'answer', 'why', 'root']);
34
+ const VALUE = new Set(['who', 'what', 'asked', 'due', 'source', 'answer', 'why', 'root', 'ref', 'quote', 'doc']);
32
35
 
33
36
  function repoRoot(cwd) {
34
37
  try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; }
@@ -80,6 +83,13 @@ function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), now } = {
80
83
  if (!r.ok) return fail(r.error);
81
84
  return out(r, [`dropped: ${lineOf(r.signoff)}`]);
82
85
  }
86
+ if (verb === 'evidence') {
87
+ if (!pos[0] || !flags.ref || !flags.quote) return need('<id> --ref <file or Jira key> --quote "<the line, word for word>" [--doc <file>]');
88
+ const r = SO.evidence(file, pos[0], { ref: flags.ref, quote: flags.quote, doc: flags.doc }, t);
89
+ if (!r.ok) return fail(r.error);
90
+ const c = require('./stage-signoffs.js').checkOf(root, r.signoff.ini, r.signoff.evidence, r.signoff.what);
91
+ return out({ ...r, check: c }, [`evidence: ${lineOf(r.signoff)}`, c.ok ? '✓ the quote is in its source: Today can record it' : `✗ Today cannot record it yet: ${c.why}`]);
92
+ }
83
93
  const L = SO.list(file, { ini: pos[0], open: !flags.all });
84
94
  return out({ ok: true, signoffs: L }, L.length ? L.map(lineOf) : [`no ${flags.all ? '' : 'open '}sign-off${pos[0] ? ` for ${pos[0]}` : ''}`]);
85
95
  }
@@ -10,12 +10,15 @@
10
10
  * ask(file, { ini, who, what, asked, due, source }, now) → { ok, signoff } | { ok: false, error }
11
11
  * answer(file, id, { answer, source }, now) → { ok, signoff } | { ok: false, error }
12
12
  * drop(file, id, { why }, now) → { ok, signoff } | { ok: false, error }
13
+ * evidence(file, id, { ref, quote, doc }, now) → { ok, signoff } | { ok: false, error } where the yes is written: a file or a
14
+ * Jira key, the line copied from it, and the document it agrees to (optional)
15
+ * reopen(file, id, now) → { ok, signoff } | { ok: false, error } the Undo of an answer
13
16
  * list(file, { ini, open }) → [signoff] the ledger folded, oldest ask first
14
17
  * partsOf(list, now) → [{ ini, id, text }] PURE: the open sign-offs to ask about today
15
18
  * fileOf(stateDir) → <state>/tracker/signoffs.jsonl
16
19
  *
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 }.
20
+ * THE LEDGER is append-only, one JSON line per act: { op: 'ask' | 'answer' | 'drop' | 'reopen' | 'evidence', id, … , at }. A signoff:
21
+ * { id, ini, who, what, asked, due, source, state: 'open' | 'answered' | 'dropped', answer, answerSource, answeredAt, why, evidence }.
19
22
  */
20
23
  const fs = require('fs');
21
24
  const path = require('path');
@@ -23,6 +26,7 @@ const crypto = require('crypto');
23
26
 
24
27
  const DAY = 864e5;
25
28
  const WAIT_DAYS = 3;
29
+ const STAGE_SOURCE = 'stage:'; // the source of a sign-off a workflow stage asks for (factory-signoffs-reach-you)
26
30
  const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
27
31
  const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
28
32
  const INI_RE = /^[a-z0-9][a-z0-9._-]{0,80}$/i;
@@ -54,7 +58,8 @@ function fold(lines) {
54
58
  const s = by.get(l.id); if (!s) continue;
55
59
  if (l.op === 'answer') Object.assign(s, { state: 'answered', answer: l.answer, answerSource: l.source || null, answeredAt: l.at });
56
60
  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 });
61
+ else if (l.op === 'reopen') Object.assign(s, { state: 'open', answer: undefined, answerSource: undefined, answeredAt: undefined, why: undefined });
62
+ else if (l.op === 'evidence') s.evidence = { ref: l.ref, quote: l.quote, doc: l.doc || null, at: l.at };
58
63
  }
59
64
  return [...by.values()];
60
65
  }
@@ -91,6 +96,20 @@ function answer(file, id, { answer: a, source } = {}, now = Date.now()) {
91
96
  return act(file, id, 'answer', { answer: text, source: one(source, 300) || null }, now);
92
97
  }
93
98
  function drop(file, id, { why } = {}, now = Date.now()) { return act(file, id, 'drop', { why: one(why, 300) || null }, now); }
99
+ /** Where the yes is written. Recorded while the sign-off is open; the last one wins. */
100
+ function evidence(file, id, { ref, quote, doc } = {}, now = Date.now()) {
101
+ const r = one(ref, 300), q = one(quote, 600);
102
+ if (!r || !q) return { ok: false, error: 'evidence needs ref (a file path or a Jira key) and quote (a line copied word for word)' };
103
+ return act(file, id, 'evidence', { ref: r, quote: q, doc: one(doc, 300) || null }, now);
104
+ }
105
+ /** The Undo of an answer: the sign-off is open again. */
106
+ function reopen(file, id, now = Date.now()) {
107
+ const s = fold(readLines(file)).find((x) => x.id === id);
108
+ if (!s) return { ok: false, error: `no sign-off ${id}` };
109
+ if (s.state === 'open') return { ok: true, signoff: s, already: true };
110
+ append(file, { op: 'reopen', id, at: new Date(now).toISOString() });
111
+ return { ok: true, signoff: fold(readLines(file)).find((x) => x.id === id) };
112
+ }
94
113
 
95
114
  /** The open sign-offs to ask about today: waited WAIT_DAYS or more since asked, or past their due date. PURE. */
96
115
  function partsOf(signoffs, now = Date.now()) {
@@ -98,6 +117,7 @@ function partsOf(signoffs, now = Date.now()) {
98
117
  const out = [];
99
118
  for (const s of signoffs || []) {
100
119
  if (!isObj(s) || s.state !== 'open') continue;
120
+ if (String(s.source || '').startsWith(STAGE_SOURCE)) continue; // a stage's sign-off is its own Your move row (lib/stage-signoffs.js)
101
121
  const asked = s.asked ? dayMs(s.asked) : NaN, due = s.due ? dayMs(s.due) : NaN;
102
122
  const waited = Number.isFinite(asked) ? Math.floor((today - asked) / DAY) : null;
103
123
  const late = Number.isFinite(due) && due < today;
@@ -109,4 +129,4 @@ function partsOf(signoffs, now = Date.now()) {
109
129
  return out;
110
130
  }
111
131
 
112
- module.exports = { ask, answer, drop, list, partsOf, fileOf, fold, WAIT_DAYS };
132
+ module.exports = { ask, answer, drop, evidence, reopen, list, partsOf, fileOf, fold, WAIT_DAYS, STAGE_SOURCE };
@@ -0,0 +1,207 @@
1
+ 'use strict';
2
+ /* stage-signoffs.js — a stage's sign-offs reach the PM (initiative factory-signoffs-reach-you, Factory page slice A; boards LnYou4 and LnBy4
3
+ * on the Exploring 3 canvas, design agreed 2026-11-25).
4
+ *
5
+ * WHY. On IDPF no initiative changed stage from 19 Nov to 25 Nov. Every exit item still missing was a yes only a person can give (PRD
6
+ * Aligned, Plan approved), and the Driver raised each one as its own work: it wrote a note, woke a week later, and nothing reached the PM.
7
+ * A To finish line with `by:` (scripts/workflows.js) is a sign-off: lib/line.js lists it in `signoffs`, lib/line-driver.js leaves it out of
8
+ * the Driver's wake, and this file turns it into one Today › Your move row.
9
+ *
10
+ * suggestOf(stage) PURE → { [line]: 'PM' } the To finish lines of a stage with no `by:` that read as a person's yes
11
+ * keptLedger(stateDir) · keptFor(kept, wf, stage) the PM's answers to the suggestion (<state>/signoff-by.jsonl): { by } | null
12
+ * answerSuggestion(stateDir, { wf, stage, act: 'keep' | 'change', by }, actor, now) → { ok, line } Keep makes them sign-offs; Change
13
+ * says no to the suggestion (the PM edits the workflow), so it does not come back for that stage
14
+ * rowsOf(root, lineRows, { now }) → { rows: [row], suggest: [suggestion] } asks each open sign-off once in lib/signoffs.js
15
+ * checkOf(root, ini, evidence) → { ok, why, quote: { ok, why }, newer: { ok, why } } whether ✓ may record it
16
+ * record(root, { ini, id }, actor, { now, lineRow }) → { ok, signoff, moved: { from, to } | null, gate, undo } | { ok: false, error }
17
+ * undo(root, { ini, id, from, to }, actor, { now }) → { ok, reopened, movedBack }
18
+ *
19
+ * A ROW: { key, ini, title, stage: { key, name }, item, who, id, asked, evidence: { ref, quote, doc } | null, action: 'record' | 'open' |
20
+ * 'ask', why, ref, draft, recipient }. record: the source passes lib/line-driver.js quoteCheck and is newer than the document it agrees to.
21
+ * open: there is a source, but it fails; the row opens it so the PM checks it. ask: no source; the press puts `draft` in the outbox as a
22
+ * tracker comment (POST /api/outbox/draft, channel jira-write), and nothing is sent until the PM sends it there.
23
+ *
24
+ * THE MOVE. Recording the last missing item runs moveGate (every exit item quotes its record, or has a Done task) and moves the stage in
25
+ * the same call, as the PM's press. undo reopens the sign-off and moves it back, when it still stands where the move put it. */
26
+ const fs = require('fs');
27
+ const path = require('path');
28
+
29
+ const TAG = '[stage-signoffs]';
30
+ const LEDGER = 'signoff-by.jsonl';
31
+ // a line that reads as a person's yes, not as work PMOS can make
32
+ const SIGNOFF_RE = /\b(align(ed|ment)?|approv(ed|al|e)|agreed|sign(ed)?[- ]?off|prioriti[sz]ed|go\s*\/\s*no[- ]go|accepted|ratified|endorsed|buy[- ]?in)\b/i;
33
+ const KEY_RE = /^[A-Z][A-Z0-9_]{0,19}-\d{1,7}$/;
34
+ const lc = (s) => String(s == null ? '' : s).trim().toLowerCase();
35
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
36
+ const one = (v, n) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n);
37
+
38
+ /** The To finish lines of a stage that read as a person's yes, each signed off by the PM. {} when the stage already names any. PURE. */
39
+ function suggestOf(stage) {
40
+ const st = stage || {};
41
+ if (isObj(st.by) && Object.keys(st.by).length) return {};
42
+ const out = {};
43
+ for (const f of Array.isArray(st.finish) ? st.finish : []) if (typeof f === 'string' && SIGNOFF_RE.test(f)) out[f.trim()] = 'PM';
44
+ return out;
45
+ }
46
+
47
+ const ledgerFile = (stateDir) => path.join(stateDir, LEDGER);
48
+ /** The PM's answers to the suggestion, the last line per workflow stage: Map `${wf}|${stage}` → { act, by }. */
49
+ function keptLedger(stateDir) {
50
+ const out = new Map();
51
+ let txt = '';
52
+ try { txt = fs.readFileSync(ledgerFile(stateDir), 'utf8'); } catch { return out; }
53
+ for (const l of txt.split('\n')) {
54
+ let x; try { x = JSON.parse(l); } catch { continue; }
55
+ if (!isObj(x) || !x.wf || !x.stage || !['keep', 'change', 'undo'].includes(x.act)) continue;
56
+ if (x.act === 'undo') out.delete(`${x.wf}|${x.stage}`); else out.set(`${x.wf}|${x.stage}`, { act: x.act, by: isObj(x.by) ? x.by : {} });
57
+ }
58
+ return out;
59
+ }
60
+ /** The sign-off lines the PM kept for one workflow stage: { [line]: who }; {} after Change; null while the suggestion is unanswered. */
61
+ function keptFor(kept, wf, stage) {
62
+ const k = kept instanceof Map ? kept.get(`${wf}|${stage}`) : null;
63
+ if (!k) return null;
64
+ return k.act === 'keep' ? { ...k.by } : {};
65
+ }
66
+ function answerSuggestion(stateDir, { wf, stage, act, by } = {}, actor = {}, now = Date.now()) {
67
+ if (!stateDir) return { ok: false, error: 'this workspace has no state folder' };
68
+ if (!one(wf, 80) || !one(stage, 80)) return { ok: false, error: 'wf and stage name the workflow stage' };
69
+ if (!['keep', 'change', 'undo'].includes(act)) return { ok: false, error: 'act is keep, change or undo' };
70
+ const map = {};
71
+ if (act === 'keep') {
72
+ if (!isObj(by) || !Object.keys(by).length) return { ok: false, error: 'by names the lines and who signs each off' };
73
+ for (const [k, v] of Object.entries(by)) { const kk = one(k, 200), vv = one(v, 80); if (kk && vv && /\p{L}/u.test(vv)) map[kk] = vv; }
74
+ if (!Object.keys(map).length) return { ok: false, error: 'by names the lines and who signs each off' };
75
+ }
76
+ const line = { act, wf: one(wf, 80), stage: one(stage, 80), ...(act === 'keep' ? { by: map } : {}), by_actor: (actor && actor.by) || 'pm', at: new Date(now).toISOString() };
77
+ fs.mkdirSync(stateDir, { recursive: true });
78
+ fs.appendFileSync(ledgerFile(stateDir), JSON.stringify(line) + '\n');
79
+ console.info(`${TAG} suggestion ${act} ${line.wf}|${line.stage}`);
80
+ return { ok: true, line };
81
+ }
82
+
83
+ /** When a file or a Jira ticket last changed (ms), or null when PMOS cannot tell. */
84
+ function changedAt(root, initiative, ref) {
85
+ const r = String(ref || '').trim();
86
+ if (!r) return null;
87
+ if (KEY_RE.test(r)) {
88
+ try { const snap = require('./jira-status.js').readSnapshot(root, initiative); const t = snap && snap.tickets && snap.tickets.get ? snap.tickets.get(r) : null; const v = t ? Date.parse(t.updated || '') : NaN; return Number.isFinite(v) ? v : null; } catch { return null; }
89
+ }
90
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(r)) return null;
91
+ const rel = r.replace(/^\/+/, '').replace(/[#:]\d+(-\d+)?$/, '');
92
+ const abs = path.resolve(root, rel);
93
+ if (abs !== path.resolve(root) && !abs.startsWith(path.resolve(root) + path.sep)) return null;
94
+ // the file's own time on disk (no git command runs): an edit not yet committed is the newest change too
95
+ try { return fs.statSync(abs).mtimeMs; } catch { return null; }
96
+ }
97
+
98
+ /** Whether ✓ may record a sign-off: its quote is in its source word for word, and the source is newer than the document it agrees to. */
99
+ function checkOf(root, ini, ev, item = '') {
100
+ if (!ev || !ev.ref || !ev.quote) return { ok: false, why: 'no source yet', quote: { ok: false, why: 'no source yet' }, newer: { ok: false, why: 'no source yet' } };
101
+ const LD = require('./line-driver.js');
102
+ const q = LD.quoteCheck([{ item: item || 'sign-off', quote: ev.quote, ref: ev.ref }], LD.readerOf(root, ini)).checks[0] || { ok: false, why: 'not checked' };
103
+ let newer = { ok: true, why: 'it names no document it agrees to' };
104
+ if (ev.doc) {
105
+ const a = changedAt(root, ini, ev.ref), b = changedAt(root, ini, ev.doc);
106
+ if (a == null || b == null) newer = { ok: false, why: `PMOS cannot tell whether ${ev.ref} is newer than ${ev.doc}` };
107
+ else if (a < b) newer = { ok: false, why: `${ev.doc} changed after the yes in ${ev.ref}` };
108
+ else newer = { ok: true, why: `${ev.ref} is newer than ${ev.doc}` };
109
+ }
110
+ const ok = !!q.ok && newer.ok;
111
+ return { ok, why: ok ? 'the quote is in its source, and the source is current' : (!q.ok ? q.why : newer.why), quote: { ok: !!q.ok, why: q.why }, newer };
112
+ }
113
+
114
+ /** The question PMOS drafts when a sign-off has no source: one plain line to who gives it. */
115
+ function draftOf(r) {
116
+ return `${r.who}: can you confirm "${r.item}" for ${r.title}? Its ${r.stage.name} stage waits on your yes. A reply here is enough.`;
117
+ }
118
+
119
+ /** Today's sign-off rows of one product, and the suggestions still unanswered. lineRows: lib/line.js lineOf rows. Asks each open
120
+ * sign-off once in the ledger (lib/signoffs.js ask is idempotent), so the Driver and the Checker read the same list. */
121
+ function rowsOf(root, lineRows, { now = Date.now() } = {}) {
122
+ const SO = require('./signoffs.js');
123
+ let JT = null; try { JT = require('./jira-tickets.js'); } catch { JT = null; }
124
+ const dir = JT ? JT.stateDirOf(root) : null;
125
+ const file = dir ? SO.fileOf(dir) : null;
126
+ const rows = [], suggest = [], seenSug = new Set();
127
+ for (const p of lineRows || []) {
128
+ if (!p || !p.live || !p.station) continue;
129
+ if (p.suggestBy && !seenSug.has(`${p.suggestBy.wf}|${p.suggestBy.stage}`)) {
130
+ seenSug.add(`${p.suggestBy.wf}|${p.suggestBy.stage}`);
131
+ suggest.push({ key: `signoff-by:${p.suggestBy.wf}:${p.suggestBy.stage}`, ...p.suggestBy, ini: p.id, title: p.title });
132
+ }
133
+ if (!Array.isArray(p.signoffs) || !file) continue;
134
+ let epics = [];
135
+ try { epics = JT ? JT.epicKeysOf(root, p.id) || [] : []; } catch { epics = []; }
136
+ for (const x of p.signoffs) {
137
+ const a = SO.ask(file, { ini: p.id, who: x.by, what: x.item, source: SO.STAGE_SOURCE + p.station.key }, now);
138
+ if (!a.ok) continue;
139
+ const s = a.signoff;
140
+ const ev = s.evidence && s.evidence.ref ? s.evidence : null;
141
+ const c = checkOf(root, p.id, ev, x.item);
142
+ const r = { key: `signoff:${p.id}:${s.id}`, ini: p.id, title: p.title || p.id, stage: { key: p.station.key, name: p.station.name }, item: x.item, who: x.by,
143
+ id: s.id, asked: s.asked, evidence: ev, action: c.ok ? 'record' : ev ? 'open' : 'ask', why: c.why, ref: ev ? ev.ref : null };
144
+ if (!ev) { r.draft = draftOf(r); r.recipient = epics[0] || null; }
145
+ rows.push(r);
146
+ }
147
+ }
148
+ const unreadable = rows.filter((r) => r.evidence && /cannot read|cannot tell/.test(r.why)).length;
149
+ console.info(`${TAG} rows=${rows.length} record=${rows.filter((r) => r.action === 'record').length} open=${rows.filter((r) => r.action === 'open').length} ask=${rows.filter((r) => r.action === 'ask').length} unreadable=${unreadable} suggest=${suggest.length}`);
150
+ return { rows, suggest };
151
+ }
152
+
153
+ const lineRowOf = (root, ini) => { const L = require('./line.js').lineOf(root, { only: ini }); return L && L.ok ? L.rows[0] || null : null; };
154
+
155
+ /** ✓ on a sign-off row: the answer with its source, and, when it was the last missing item, the stage move through the gate. */
156
+ function record(root, { ini, id } = {}, actor = { by: 'pm' }, { now = Date.now(), lineRow = lineRowOf } = {}) {
157
+ const SO = require('./signoffs.js'), LD = require('./line-driver.js'), JT = require('./jira-tickets.js');
158
+ const file = SO.fileOf(JT.stateDirOf(root));
159
+ const s = SO.list(file, { ini }).find((x) => x.id === id);
160
+ if (!s) return { ok: false, error: `no sign-off ${id} on ${ini}` };
161
+ if (s.state !== 'open') return { ok: false, error: `that sign-off is already ${s.state}` };
162
+ const c = checkOf(root, ini, s.evidence, s.what);
163
+ if (!c.ok) return { ok: false, error: `not recorded: ${c.why}`, check: c };
164
+ const before = lineRow(root, ini);
165
+ const from = before && before.station ? before.station : null;
166
+ const a = SO.answer(file, id, { answer: `${s.who} said yes: "${one(s.evidence.quote, 400)}"`, source: s.evidence.ref }, now);
167
+ if (!a.ok) return a;
168
+ let moved = null, gate = null;
169
+ const after = lineRow(root, ini);
170
+ if (after && after.live && from && after.station && after.station.key === from.key && !(after.missing || []).length) {
171
+ const b = LD.boardRowOf(root, ini);
172
+ if (b.ok) {
173
+ const signed = SO.list(file, { ini }).filter((x) => x.state === 'answered' && x.evidence && String(x.source || '') === SO.STAGE_SOURCE + from.key);
174
+ const exits = signed.map((x) => ({ item: x.what, quote: x.evidence.quote, ref: x.evidence.ref }));
175
+ const has = new Set(exits.map((x) => lc(x.item)));
176
+ const done = LD.exitItemsOf(b.row).filter((n) => !has.has(lc(n)));
177
+ gate = LD.moveGate({ row: after, boardRow: b.row, exits, from: from.key, readText: LD.readerOf(root, ini), done });
178
+ if (gate.ok) {
179
+ const stages = b.row.wfStages || [];
180
+ const i = stages.findIndex((x) => x.key === from.key);
181
+ const next = stages.slice(i + 1).find((x) => x.status !== 'skipped');
182
+ if (next) {
183
+ const m = LD.boardMove(root, { id: ini, to: next.key, why: `every sign-off of ${from.name} is recorded` }, actor);
184
+ if (m && m.body && m.body.ok !== false) moved = { from: from.key, to: next.key, fromName: from.name, toName: next.name };
185
+ }
186
+ }
187
+ }
188
+ }
189
+ console.info(`${TAG} record ${ini} ${id} moved=${moved ? moved.from + '>' + moved.to : 'no'}${gate && !gate.ok ? ' gate=' + gate.why : ''}`);
190
+ return { ok: true, signoff: a.signoff, moved, gate, undo: { ini, id, ...(moved ? { from: moved.from, to: moved.to } : {}) } };
191
+ }
192
+
193
+ /** One Undo for both: the sign-off is open again, and the stage moves back when the initiative still stands where the move put it. */
194
+ function undo(root, { ini, id, from, to } = {}, actor = { by: 'pm' }, { now = Date.now() } = {}) {
195
+ const SO = require('./signoffs.js'), LD = require('./line-driver.js'), JT = require('./jira-tickets.js');
196
+ const r = SO.reopen(SO.fileOf(JT.stateDirOf(root)), id, now);
197
+ if (!r.ok) return r;
198
+ let movedBack = false;
199
+ if (from && to) {
200
+ const here = LD.stationNow(root, ini);
201
+ if (here && LD.sameStage(here, to)) { const m = LD.boardMove(root, { id: ini, to: from, why: 'Undo: the sign-off is open again' }, actor); movedBack = !!(m && m.body && m.body.ok !== false); }
202
+ }
203
+ console.info(`${TAG} undo ${ini} ${id} movedBack=${movedBack}`);
204
+ return { ok: true, reopened: true, movedBack, signoff: r.signoff };
205
+ }
206
+
207
+ module.exports = { TAG, LEDGER, SIGNOFF_RE, suggestOf, keptLedger, keptFor, answerSuggestion, changedAt, checkOf, draftOf, rowsOf, record, undo };
@@ -22,7 +22,9 @@
22
22
  * A WORKFLOW is { id, name, icon, builtin?, decide, archived?, stages: [STAGE], bridge? }.
23
23
  * bridge { from, map: { [fromStageKey]: stageKey } }: where each stage of the workflow it replaces lands (batch 20 item 3, canvas WmB).
24
24
  * It is saved with the new workflow, so every later switch from `from` uses it. Many old stages may land in one new stage.
25
- * A STAGE is { key, name, cat, output: { name, kind, template? }, finish: [text], milestone, auto, when: { mode, text? }, then, unless: [{ text, to }] }.
25
+ * A STAGE is { key, name, cat, output: { name, kind, template? }, finish: [text], by?, milestone, auto, when: { mode, text? }, then, unless: [{ text, to }] }.
26
+ * by { [finish line]: who }: the To finish lines only a person can give, and who gives each (factory-signoffs-reach-you). A line with
27
+ * `by` is a sign-off: PMOS asks for it and never works it. A line may be written "PRD Aligned (by: PM)"; check() splits it.
26
28
  * cat ∈ CATS (To do, In progress, Done). Won't do and Archived (ENDS) are in every workflow and are not stages.
27
29
  * The first stage is always `triage`, in To do. `then` null means the next stage in the list. `unless` sends the initiative elsewhere
28
30
  * when PMOS judges its plain words true. A key is the slug of the stage's first name and survives a rename.
@@ -45,7 +47,16 @@ const WHEN_MODES = Object.freeze(['always', 'optional', 'only']);
45
47
  const DECIDE = Object.freeze(['pmos', 'confirm']);
46
48
  const ICONS = Object.freeze(['feature', 'doc', 'cart', 'swap', 'people', 'shield', 'box', 'flag', 'build', 'chart']);
47
49
  const PRODUCT_FEATURE_ID = 'product-feature';
48
- const NAME_MAX = 60, TEXT_MAX = 300, FINISH_MAX = 20, STAGES_MAX = 30;
50
+ const NAME_MAX = 60, TEXT_MAX = 300, FINISH_MAX = 20, STAGES_MAX = 30, BY_MAX = 80;
51
+ // "PRD Aligned (by: PM)" or "PRD Aligned — by: PM": the line and who signs it off
52
+ const BY_IN_LINE = /\s*(?:\(\s*by:\s*([^()]+?)\s*\)|[—–-]+\s*by:\s*(.+?))\s*$/i;
53
+ /** A To finish line written with its sign-off: → { line, by } (by '' when the line names nobody). PURE. */
54
+ function splitBy(text) {
55
+ const t = String(text == null ? '' : text).trim();
56
+ const m = BY_IN_LINE.exec(t);
57
+ if (!m || m.index === 0) return { line: t, by: '' };
58
+ return { line: t.slice(0, m.index).trim(), by: String(m[1] || m[2] || '').trim() };
59
+ }
49
60
 
50
61
  const slug = (s) => String(s || '').toLowerCase().normalize('NFKD').replace(/[^\x00-\x7f]/g, '').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 40).replace(/-+$/, '');
51
62
  const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
@@ -143,6 +154,15 @@ function check(wf) {
143
154
  if (o.template != null && o.template !== '' && !oneLine(o.template, 120)) return bad(`stage "${sname}": the template is one line of at most 120 characters`);
144
155
  const finish = s.finish == null ? [] : s.finish;
145
156
  if (!Array.isArray(finish) || finish.length > FINISH_MAX || finish.some((x) => !oneLine(x, 200))) return bad(`stage "${sname}": To finish is a list of at most ${FINISH_MAX} lines of at most 200 characters`);
157
+ const by = {};
158
+ const lines = finish.map((x) => { const sp = splitBy(x); if (sp.by) by[sp.line] = sp.by; return sp.line; });
159
+ if (s.by != null && !isObj(s.by)) return bad(`stage "${sname}": by is { "<To finish line>": "<who signs it off>" }`);
160
+ for (const [k, v] of Object.entries(s.by || {})) {
161
+ if (!lines.includes(String(k).trim())) return bad(`stage "${sname}": by names "${k}", which is not one of its To finish lines`);
162
+ if (v == null || v === '') continue;
163
+ if (!oneLine(v, BY_MAX) || !/\p{L}/u.test(v)) return bad(`stage "${sname}": who signs off "${k}" is a person or a role, one line of at most ${BY_MAX} characters`);
164
+ if (!by[String(k).trim()]) by[String(k).trim()] = v.trim();
165
+ }
146
166
  const w = isObj(s.when) ? s.when : { mode: 'always' };
147
167
  if (!WHEN_MODES.includes(w.mode)) return bad(`stage "${sname}": When it runs is one of ${WHEN_MODES.join(', ')}`);
148
168
  if (w.mode === 'only' && !oneLine(w.text, TEXT_MAX)) return bad(`stage "${sname}": Only when needs the condition in your words (at most ${TEXT_MAX} characters)`);
@@ -152,7 +172,7 @@ function check(wf) {
152
172
  stages.push({
153
173
  key, name: sname, cat: s.cat,
154
174
  output: { name: o.name ? o.name.trim() : '', kind, ...(o.template ? { template: o.template.trim() } : {}) },
155
- finish: finish.map((x) => x.trim()), milestone: s.milestone === true, auto: s.auto === true,
175
+ finish: lines, ...(Object.keys(by).length ? { by } : {}), milestone: s.milestone === true, auto: s.auto === true,
156
176
  when: w.mode === 'only' ? { mode: 'only', text: w.text.trim() } : { mode: w.mode },
157
177
  then: typeof s.then === 'string' && s.then ? s.then : null,
158
178
  unless: unless.map((u) => ({ text: u.text.trim(), to: u.to })),
@@ -338,7 +358,7 @@ function stagesOf(wf, { judged = {}, current = null } = {}) {
338
358
  const j = judged && judged[s.key] ? judged[s.key] : null;
339
359
  const skipped = !!j && j.runs === false;
340
360
  const status = skipped ? 'skipped' : at < 0 ? (i === 0 ? 'current' : 'next') : i < at ? 'done' : i === at ? 'current' : 'next';
341
- return { key: s.key, name: s.name, cat: s.cat, milestone: s.milestone, auto: s.auto, output: s.output, finish: s.finish, when: s.when,
361
+ return { key: s.key, name: s.name, cat: s.cat, milestone: s.milestone, auto: s.auto, output: s.output, finish: s.finish, ...(s.by ? { by: { ...s.by } } : {}), when: s.when,
342
362
  then: s.then, unless: s.unless, n: i + 1, of: w.stages.length, status, reading: j ? { runs: j.runs, why: j.why || '', cite: j.cite || null } : null };
343
363
  });
344
364
  }
@@ -348,7 +368,7 @@ function copyOf(wf, name, taken) {
348
368
  const n = oneLine(name, NAME_MAX) ? name.trim() : 'Copy of ' + wf.name;
349
369
  let id = slug(n) || 'workflow', k = 2;
350
370
  while ((taken && taken.has(id)) || isBuiltin(id)) id = slug(n) + '-' + k++;
351
- return { id, name: n, icon: wf.icon, decide: wf.decide || 'pmos', ...(WORK_KINDS.includes(wf.kind) ? { kind: wf.kind } : {}), stages: wf.stages.map((s) => ({ ...s, output: { ...s.output }, finish: [...s.finish], when: { ...s.when }, unless: s.unless.map((u) => ({ ...u })) })) };
371
+ return { id, name: n, icon: wf.icon, decide: wf.decide || 'pmos', ...(WORK_KINDS.includes(wf.kind) ? { kind: wf.kind } : {}), stages: wf.stages.map((s) => ({ ...s, output: { ...s.output }, finish: [...s.finish], ...(s.by ? { by: { ...s.by } } : {}), when: { ...s.when }, unless: s.unless.map((u) => ({ ...u })) })) };
352
372
  }
353
373
 
354
374
  /** The workflow a kind of work starts on: Project and Full SDLC their own; Product management the workspace's default (defaultOf). */
@@ -370,5 +390,5 @@ const milestonesOf = (wf) => (wf || PRODUCT_FEATURE).stages.filter((s) => s.mile
370
390
  module.exports = {
371
391
  CATS, CAT_LABEL, ENDS, OUTPUT_KINDS, WHEN_MODES, DECIDE, ICONS, PRODUCT_FEATURE_ID, PRODUCT_FEATURE,
372
392
  PROJECT_ID, PROJECT, FULL_SDLC_ID, FULL_SDLC, BUILTIN, KIND_WF, KIND_GATE, MEANING, isBuiltin, forKind, isKindDefault,
373
- WORK_KINDS, kindOf, slug, check, fold, list, defaultOf, resolve, stageByRef, switchTarget, proposeBridge, mapOf, removedInUse, stagesOf, copyOf, milestonesOf,
393
+ WORK_KINDS, kindOf, slug, check, fold, list, defaultOf, resolve, stageByRef, switchTarget, proposeBridge, mapOf, removedInUse, stagesOf, copyOf, milestonesOf, splitBy,
374
394
  };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.820.0",
3
+ "version": "0.821.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.820.0",
9
+ "version": "0.821.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.820.0",
3
+ "version": "0.821.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -41,6 +41,7 @@ export function mountToday(ctx) {
41
41
  draw();
42
42
  readReports();
43
43
  readQuestions();
44
+ readSignoffs();
44
45
  readLine();
45
46
  readDigest();
46
47
  readSync();
@@ -59,6 +60,58 @@ export function mountToday(ctx) {
59
60
  X.questions = lines;
60
61
  draw();
61
62
  }
63
+ /* factory-signoffs-reach-you (boards LnYou4, LnBy4): each product's open stage sign-offs (GET /api/stage-signoffs), one Your move row each,
64
+ * and the ✦ rows that suggest a stage's sign-off lines. A product that does not answer is left out; nothing is guessed. */
65
+ async function readSignoffs() {
66
+ const P = ((ctx.S.M && ctx.S.M.products) || []).filter((p) => p && p.model);
67
+ const L = [...new Set((P.length ? P.map((p) => p.ws || ctx.boardWs() || '') : [ctx.boardWs() || '']))];
68
+ const got = await Promise.all(L.map((ws) => ctx.pmGet('/api/stage-signoffs' + (ws ? '?ws=' + encodeURIComponent(ws) : '')).catch(() => null)));
69
+ const rows = [], suggest = [];
70
+ got.forEach((r, i) => { if (!r || !r.ok) return; const ws = r.ws || L[i]; for (const x of r.rows || []) rows.push({ ...x, ws }); for (const g of r.suggest || []) suggest.push({ ...g, ws }); });
71
+ console.info('[stage-signoffs] products=' + L.length + ' rows=' + rows.length + ' suggest=' + suggest.length);
72
+ const next = JSON.stringify([rows, suggest]);
73
+ if (next === (X.soSeen || '[[],[]]')) return; // nothing new, and none at all: no redraw
74
+ X.soSeen = next; X.signoffs = rows; X.signoffSuggest = suggest;
75
+ draw();
76
+ }
77
+ /** ✓ on a sign-off row: recorded with its source; when it was the stage's last missing item the stage moves in the same press. One Undo. */
78
+ async function signoffRecord(r) {
79
+ const s = r.ref || {};
80
+ const res = await ctx.pmPost('/api/stage-signoffs/record', { ws: s.ws || undefined, ini: s.ini, id: s.id }).catch(() => null);
81
+ if (!res || !res.ok) return ctx.toast((res && res.error) || 'It did not go through. Nothing changed.');
82
+ const said = res.moved ? `Recorded ${s.who}’s yes. ${r.work || s.title} moved to ${res.moved.toName}.` : `Recorded ${s.who}’s yes on ${s.item}.`;
83
+ ctx.toastUndo(said, async () => { const u = await ctx.pmPost('/api/stage-signoffs/undo', { ws: s.ws || undefined, ...res.undo }).catch(() => null); await readSignoffs(); ctx.reload && ctx.reload(); return u || { ok: false }; });
84
+ await readSignoffs();
85
+ if (res.moved && ctx.reload) ctx.reload();
86
+ return after(true);
87
+ }
88
+ /** A sign-off whose source did not pass: it opens, so the PM reads it. A file opens in the Viewer; a ticket opens its initiative. */
89
+ function signoffOpen(r) {
90
+ const s = r.ref || {};
91
+ if (s.ref && !/^[A-Z][A-Z0-9_]{0,19}-\d{1,7}$/.test(s.ref) && ctx.openFile) { ctx.openFile({ path: s.ref.replace(/[#:]\d+(-\d+)?$/, ''), name: s.ref.split('/').pop() }); return; }
92
+ if (s.ini && ctx.hasIni(s.ini)) ctx.goIni(s.ini);
93
+ }
94
+ /** A sign-off with no source: PMOS's drafted question goes to the outbox as a tracker comment. It is sent from there, never from here. */
95
+ async function signoffAsk(r) {
96
+ const s = r.ref || {};
97
+ const res = await ctx.pmPost('/api/outbox/draft', { channel: 'jira-write', recipient: s.recipient || s.ini, body: s.draft || r.title }).catch(() => null);
98
+ if (!res || !res.ok) return ctx.toast((res && res.error) || 'The question was not drafted. Nothing changed.');
99
+ const id = res.entry && res.entry.id;
100
+ ctx.toastUndo('The question is in Today’s batch, ready to send to ' + s.who + '. Nothing is sent yet.', async () => { const u = id ? await ctx.pmPost('/api/outbox/discard', { id }).catch(() => null) : null; ctx.reload && ctx.reload(); return u || { ok: false }; });
101
+ if (ctx.reload) ctx.reload();
102
+ return after(true);
103
+ }
104
+ /** Keep or Change on PMOS's suggested sign-off lines (board LnBy4). Keep makes them sign-offs; Change opens the workflows to edit them. */
105
+ async function signoffSuggest(r, keep) {
106
+ const g = r.ref || {};
107
+ const res = await ctx.pmPost('/api/stage-signoffs/suggest', { ws: g.ws || undefined, wf: g.wf, stage: g.stage, act: keep ? 'keep' : 'change', ...(keep ? { by: g.by } : {}) }).catch(() => null);
108
+ if (!res || !res.ok) return ctx.toast((res && res.error) || 'It did not go through. Nothing changed.');
109
+ const undo = async () => { const u = await ctx.pmPost('/api/stage-signoffs/suggest', { ws: g.ws || undefined, wf: g.wf, stage: g.stage, act: 'undo' }).catch(() => null); await readSignoffs(); return u || { ok: false }; };
110
+ ctx.toastUndo(keep ? 'Kept. ' + Object.keys(g.by).join(', ') + ' are sign-offs now; PMOS asks for them on Today.' : 'PMOS will not suggest them again. Edit the sign-offs in Settings › Workflows.', undo);
111
+ if (!keep) import('./cozy-settings.js').then((M) => M.openSettings('workflows', { wf: g.wf })).catch(() => {}); // Settings › Workflows, in place
112
+ await readSignoffs();
113
+ return after(true);
114
+ }
62
115
  /* tracker-sync-on-today (board TrackerSyncDesk): each product's sync with its tracker (GET /api/tracker-sync). Only a product below 95%
63
116
  * gets a ✦ row (TM.syncSuggest); ✕ hides it until its number changes (kept in this browser). */
64
117
  const SYNC_NO = 'pmos.today.syncNo';
@@ -152,6 +205,7 @@ export function mountToday(ctx) {
152
205
  const lab = (S.lab || []).flatMap((l) => (l.items || []).map((f) => ({ ...f, ws: l.ws, board: l.board })));
153
206
  const L = TM.logModel({ rank: ctx.rank(), move, items: tdItems(), drafts, review: R && R.open && !R.done ? { title: 'Your weekly review' } : null,
154
207
  own: X.log.entries, marks: X.log.marks, lab, questions: X.questions || [], titleOf: ctx.titleOf, productOf, now, fixed: X.log.fixed || {},
208
+ signoffs: X.signoffs || [], signoffSuggest: X.signoffSuggest || [],
155
209
  // your-move (A468): an initiative's ship date is its board end date; a line with no default on work that ships soon blocks it
156
210
  shipOf: (id) => { const r = byId.get('i:' + id); return (r && r.board && r.board.end) || ''; } });
157
211
  if (L.move.length !== X.ymN) { X.ymN = L.move.length; console.info('[your-move] rows=' + L.move.length + ' shown=' + L.first.length + (L.move[0] ? ' first-tier=' + L.move[0].tier : '')); }
@@ -297,6 +351,8 @@ export function mountToday(ctx) {
297
351
  if (r.src === 'move') { if (ref.kind === 'task' && r.ini && ctx.hasIni(r.ini)) { ctx.goIni(r.ini, { task: (ref.task && ref.task.uid) || null }); return; } pop(r); ctx.select(r.key); if (ref.kind === 'session') chatPop(); return; }
298
352
  if (r.src === 'item') { if (r.ini && ctx.hasIni(r.ini)) { ctx.goIni(r.ini); return; } pop(r); import('./home-work.js').then((M) => M.openWorkItem(ref.key)).catch(() => {}); return; }
299
353
  if (r.src === 'question') { openQuestion(ref); return; }
354
+ if (r.src === 'signoff') { if (ref.ini && ctx.hasIni(ref.ini)) ctx.goIni(ref.ini); return; }
355
+ if (r.src === 'signoff-by') { if (ref.ini && ctx.hasIni(ref.ini)) ctx.goIni(ref.ini); return; }
300
356
  if (r.src === 'draft') { pop(r); ctx.openFinished(ref.fin); return; }
301
357
  if (r.src === 'review') { pop(r); ctx.openReviewVw(); return; }
302
358
  if (r.src === 'lab') { pop(r); ctx.openLab(ref); }
@@ -597,9 +653,10 @@ export function mountToday(ctx) {
597
653
  }
598
654
  if (act === 'open' && key === 'digest') { openDigest(); return; }
599
655
  const r = rowOf(key); if (!r) return;
600
- if (r.tier != null && (act === 'open' || act === 'done' || act === 'tomorrow')) noteUse('ym-act'); // your-move's health number
656
+ if (r.tier != null && (act === 'open' || act === 'done' || act === 'tomorrow' || /^(so|sb)-/.test(act))) noteUse('ym-act'); // your-move's health number
601
657
  if (act === 'q-remind') { remindQuestion(r.ref); return; }
602
658
  if (act === 'open') { open(r); return; }
659
+ if (act === 'so-open') { signoffOpen(r); return; }
603
660
  if (act === 'date') { chooseDate(r, b); return; }
604
661
  if (act === 'file') { chooseFile(r, b); return; } // capture-to-initiative: the filed chip's change
605
662
  if (X.busy.has(key)) return;
@@ -611,6 +668,9 @@ export function mountToday(ctx) {
611
668
  else if (act === 'keep') await keep(r);
612
669
  else if (act === 'plain') await plain(r);
613
670
  else if (act === 'lab-keep' || act === 'lab-drop') await lab(r, act === 'lab-keep');
671
+ else if (act === 'so-record') await signoffRecord(r);
672
+ else if (act === 'so-ask') await signoffAsk(r);
673
+ else if (act === 'sb-keep' || act === 'sb-change') await signoffSuggest(r, act === 'sb-keep');
614
674
  else if (act === 'lk-yes' || act === 'lk-no') await looks(r, act === 'lk-yes');
615
675
  else if (act === 'same-yes' || act === 'same-no') await same(r, act === 'same-yes');
616
676
  } finally { X.busy.delete(key); if (b.isConnected) b.disabled = false; }
@@ -143,7 +143,7 @@ function typeOf(r) {
143
143
  const ref = r.ref || {};
144
144
  if (r.bullet === 'note' || r.src === 'note') return 'Note';
145
145
  if (r.src === 'draft') return 'Report';
146
- if (r.src === 'lab' || r.src === 'question') return 'Decision';
146
+ if (r.src === 'lab' || r.src === 'question' || r.src === 'signoff' || r.src === 'signoff-by') return 'Decision';
147
147
  if (r.src !== 'ask') return 'Task';
148
148
  switch (ref.kind) {
149
149
  case 'mention': return 'Ask';
@@ -160,7 +160,8 @@ function typeOf(r) {
160
160
  * drafts: [{ id, title, ini? }], review: { title } | null, own: today-log entries, marks: today-log marks, lab: [{ ws, board, id, title, why }],
161
161
  * questions: GET /api/open-questions lines, each with its ws (open-questions-today), titleOf(ini) → the initiative's name,
162
162
  * shipOf(ini) → its ship date 'YYYY-MM-DD' or '' (Your move: a line with no default on work that ships soon blocks it), now,
163
- * fixed: GET /api/today-log fixed ({ [ws]: keys }, quiet-rows: the line rows Your move shows today per product) }
163
+ * fixed: GET /api/today-log fixed ({ [ws]: keys }, quiet-rows: the line rows Your move shows today per product),
164
+ * signoffs: GET /api/stage-signoffs rows, each with its ws; signoffSuggest: its suggest list (factory-signoffs-reach-you) }
164
165
  * quiet-rows: the drafts in the outbox are one row, Today's batch (pm/quiet-rows.js batchRow); Your move keeps at most 3 line rows a day per
165
166
  * product (capLine), the rest wait under Later (`held`), and `toFix` is what the page writes once to the day ledger.
166
167
  * A row: { key, src, bullet, first, title, work, ini, ws, job, when, late, carried, done, dates: 'task' | 'item' | 'mark', drop, ref }
@@ -257,6 +258,20 @@ export function logModel(o = {}) {
257
258
  // your-move (A468): every line waiting on the PM is one Decide row, so Your move can rank it; its age and its default ride along
258
259
  for (const q of Q.mine) put({ key: q.key, src: 'question', bullet: 'task', title: q.title, ini: iniOnly(q.ini), ws: q.ws, work: q.meta, job: 'Decide', carried: 0, late: false, when: '', reason: q.under,
259
260
  age: q.age || 0, due: q.due || '', hasDefault: !!(q.line && q.line.default), ref: q });
261
+ // factory-signoffs-reach-you (board LnYou4): one Decide row per open sign-off a workflow stage waits on, with who gives it and where, and
262
+ // one ✦ row per stage whose sign-off lines PMOS suggests (board LnBy4); both wait on the PM, so Your move ranks them
263
+ for (const s of o.signoffs || []) {
264
+ if (!s || !s.key) continue;
265
+ const age = s.asked ? Math.max(0, between(s.asked, today) || 0) : 0;
266
+ put({ key: s.key, src: 'signoff', bullet: 'task', title: s.who + ' signs off: ' + s.item, ini: iniOnly(s.ini), ws: s.ws || '', work: work(s.ini, s.title), job: 'Decide',
267
+ carried: 0, late: false, when: '', reason: s.stage && s.stage.name ? s.stage.name + ' waits on it' : '', age, ref: s });
268
+ }
269
+ for (const g of o.signoffSuggest || []) {
270
+ if (!g || !g.key || !g.by) continue;
271
+ const items = Object.keys(g.by);
272
+ put({ key: g.key, src: 'signoff-by', bullet: 'task', title: 'Sign-offs for ' + (g.stageName || g.stage) + ': ' + items.join(', '), ini: null, ws: g.ws || '', work: '', job: 'Decide',
273
+ carried: 0, late: false, when: '', reason: 'PMOS suggests ' + (items.length === 1 ? 'it is' : 'they are') + ' a person’s yes, by ' + [...new Set(Object.values(g.by))].join(', '), age: 0, ref: g });
274
+ }
260
275
  oneLine(out);
261
276
  // a row done today whose source has let it go keeps its × from what it said when it was done
262
277
  for (const [k, m] of Object.entries(marks)) {
@@ -433,10 +448,10 @@ export function costOf(r, today, shipOf = () => '') {
433
448
  if (r.type === 'Ask' && !(r.who && r.who.length)) return null; // nobody waits on the answer
434
449
  if (r.src === 'batch') return [2, r.left == null ? QR.LAPSE_DAYS : r.left, r.why]; // quiet-rows: Today's batch, a send today, soonest lapse first
435
450
  const ref = r.ref || {}, c = ref.call || null, ld = lateDays(r, today);
436
- const waits = r.src === 'ask' || r.src === 'question' || r.src === 'draft' || r.src === 'review' || (r.src === 'own' && r.first) || ld > 0;
451
+ const waits = r.src === 'ask' || r.src === 'question' || r.src === 'signoff' || r.src === 'signoff-by' || r.src === 'draft' || r.src === 'review' || (r.src === 'own' && r.first) || ld > 0;
437
452
  if (!waits) return null;
438
453
  if (r.src === 'own' && r.first) return [0, 0, 'You marked it first'];
439
- const age = r.src === 'question' ? r.age || 0 : r.carried || 0;
454
+ const age = r.src === 'question' || r.src === 'signoff' ? r.age || 0 : r.carried || 0;
440
455
  const ship = r.ini ? String(shipOf(r.ini) || '') : '', sd = ship ? between(today, ship) : null;
441
456
  const dflt = r.src === 'question' && r.hasDefault && r.due ? r.due : '';
442
457
  if (sd != null && sd >= 0 && sd <= SHIP_SOON && !dflt) return [1, sd, shipWhy(ship, today) + (r.src === 'question' ? '; no safe default' : '')];
@@ -446,6 +461,7 @@ export function costOf(r, today, shipOf = () => '') {
446
461
  if (r.type === 'Ask' && r.carried >= 1) return [3, -r.carried, names(r.who) + ' ' + (r.who.length > 1 ? 'wait' : 'waits') + ' on you ' + plural(r.carried, 'day', 'days')];
447
462
  if (c && c.kind === 'session' && (c.state === 'blocked' || c.state === 'needs')) return [3, 0, 'A session waits on you; its work stops until you answer'];
448
463
  if (r.src === 'question') return [4, -age, r.reason || 'Waits on you ' + plural(age, 'day', 'days')];
464
+ if (r.src === 'signoff' || r.src === 'signoff-by') return [4, -age, r.reason || 'Waits on you'];
449
465
  const w = whyOf(r, today);
450
466
  return [4, -age, w && !/^Waits on you$/.test(w) ? w : age ? 'Waits on you ' + plural(age, 'day', 'days') : 'Waits on you'];
451
467
  }