create-pmos 0.820.0 → 0.822.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.
- package/package.json +27 -3
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/scripts/workflows.js +26 -6
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +26 -2
- package/workspace/guide/agent-capabilities.md +1 -0
- package/workspace/guide/cli.md +4 -0
- package/workspace/lib/ai-cli.js +17 -2
- package/workspace/lib/driver.js +2 -0
- package/workspace/lib/engine/workflows.js +26 -6
- package/workspace/lib/line-driver.js +40 -12
- package/workspace/lib/line.js +30 -8
- package/workspace/lib/pmos-verbs.js +1 -1
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-boards.js +1 -1
- package/workspace/lib/routes-stage-signoffs.js +71 -0
- package/workspace/lib/routes-your-move.js +10 -1
- package/workspace/lib/signoff-cli.js +13 -3
- package/workspace/lib/signoffs.js +24 -4
- package/workspace/lib/stage-signoffs.js +207 -0
- package/workspace/lib/vendor/scripts/workflows.js +26 -6
- package/workspace/lib/worth-it.js +66 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-today-app.js +61 -1
- package/workspace/public/pm/cozy-today-model.js +20 -4
- package/workspace/public/pm/cozy-today-view.js +17 -2
- package/workspace/public/pm/home-app.js +1 -1
- package/workspace/test-lists/factory-signoffs-reach-you.json +9 -0
- package/workspace/test-lists/worth-it-by-kind.json +9 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-stage-signoffs.js — a stage's sign-offs as Today › Your move rows (initiative factory-signoffs-reach-you; lib/stage-signoffs.js).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/stage-signoffs?ws=<id> → { ok, ws, rows: [lib/stage-signoffs.js row], suggest: [suggestion] }
|
|
5
|
+
* POST /api/stage-signoffs/record { ws, ini, id } → { ok, signoff, moved, gate, undo } ✓: the answer, and the stage move when it
|
|
6
|
+
* was the last missing item (one press)
|
|
7
|
+
* POST /api/stage-signoffs/undo { ws, ini, id, from?, to? } → { ok, reopened, movedBack } one Undo for both
|
|
8
|
+
* POST /api/stage-signoffs/suggest { ws, wf, stage, act: 'keep' | 'change' | 'undo', by? } → { ok, line } the ✦ suggestion's answer
|
|
9
|
+
*
|
|
10
|
+
* The rows read the product's kept line (lib/routes-your-move.js lineRowsKept) and never wait for a first read, so the page opens at once. Every
|
|
11
|
+
* POST is a page press (lib/pm-guard.js requirePagePress). Nothing here sends anything: a row with no source drafts its question, and the
|
|
12
|
+
* page puts it in the outbox (POST /api/outbox/draft) only when the PM presses it. */
|
|
13
|
+
const SS = require('./stage-signoffs.js');
|
|
14
|
+
|
|
15
|
+
async function read(req, res, url, ctx, method) {
|
|
16
|
+
if (req.method !== method) { ctx.json(res, { ok: false, error: method + ' only' }, 405); return null; }
|
|
17
|
+
let body = {};
|
|
18
|
+
if (method === 'POST') {
|
|
19
|
+
const got = await ctx.readJson(req);
|
|
20
|
+
if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return null; }
|
|
21
|
+
body = got.body || {};
|
|
22
|
+
}
|
|
23
|
+
let w = null;
|
|
24
|
+
try { w = ctx.getWs((method === 'POST' ? body.ws : url.searchParams.get('ws')) || null); } catch { w = null; }
|
|
25
|
+
if (!w || !w.root) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return null; }
|
|
26
|
+
if (method === 'POST') {
|
|
27
|
+
const g = require('./pm-guard.js').requirePagePress(req, body);
|
|
28
|
+
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return null; }
|
|
29
|
+
return { w, body, actor: { by: (g.actor && g.actor.by) || 'pm', via: (g.actor && g.actor.via) || 'page' } };
|
|
30
|
+
}
|
|
31
|
+
return { w, body };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// the line row of one initiative: the rows the server already derived; a full read only when they are not ready
|
|
35
|
+
function lineRowOf(root, ini) {
|
|
36
|
+
const L = require('./line.js');
|
|
37
|
+
let r = L.lineOf(root, { only: ini, derive: false });
|
|
38
|
+
if (!r || r.pending) r = L.lineOf(root, { only: ini });
|
|
39
|
+
return r && r.ok ? r.rows[0] || null : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
prefixes: ['/api/stage-signoffs'],
|
|
44
|
+
handle: async (req, res, url, ctx) => {
|
|
45
|
+
const YM = require('./routes-your-move.js');
|
|
46
|
+
if (url.pathname === '/api/stage-signoffs') {
|
|
47
|
+
const r = await read(req, res, url, ctx, 'GET'); if (!r) return true;
|
|
48
|
+
// the kept line only: a first read of a large product takes a while, so this answers at once and the rows come on a later refresh
|
|
49
|
+
let rows = null;
|
|
50
|
+
try { rows = ctx.signoffLine ? await ctx.signoffLine(r.w) : YM.lineRowsKept(r.w); } catch (e) { ctx.json(res, { ok: false, error: 'the line could not be read: ' + (e && e.message) }, 500); return true; }
|
|
51
|
+
if (!rows) { ctx.json(res, { ok: true, ws: r.w.id, rows: [], suggest: [], reading: true }); return true; }
|
|
52
|
+
const S = SS.rowsOf(r.w.root, rows);
|
|
53
|
+
ctx.json(res, { ok: true, ws: r.w.id, rows: S.rows, suggest: S.suggest });
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
const act = url.pathname.slice('/api/stage-signoffs/'.length);
|
|
57
|
+
if (!['record', 'undo', 'suggest'].includes(act)) return false;
|
|
58
|
+
const r = await read(req, res, url, ctx, 'POST'); if (!r) return true;
|
|
59
|
+
const b = r.body;
|
|
60
|
+
let out;
|
|
61
|
+
if (act === 'record') out = SS.record(r.w.root, { ini: String(b.ini || ''), id: String(b.id || '') }, r.actor, { lineRow: ctx.signoffLineRow || lineRowOf });
|
|
62
|
+
else if (act === 'undo') out = SS.undo(r.w.root, { ini: String(b.ini || ''), id: String(b.id || ''), from: b.from ? String(b.from) : null, to: b.to ? String(b.to) : null }, r.actor);
|
|
63
|
+
else {
|
|
64
|
+
let dir = null; try { dir = require('./jira-tickets.js').stateDirOf(r.w.root); } catch { dir = null; }
|
|
65
|
+
out = SS.answerSuggestion(dir, { wf: b.wf, stage: b.stage, act: b.act, by: b.by }, r.actor);
|
|
66
|
+
}
|
|
67
|
+
if (out && out.ok) YM.forgetLine(r.w.id);
|
|
68
|
+
ctx.json(res, out, out && out.ok ? 200 : 400);
|
|
69
|
+
return true;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
@@ -154,6 +154,15 @@ async function lineRows(w, now = Date.now()) {
|
|
|
154
154
|
LINES.set(w.id, { at: c ? c.at : 0, rows: c ? c.rows : null, p });
|
|
155
155
|
return c && c.rows ? c.rows : p;
|
|
156
156
|
}
|
|
157
|
+
/** A press that moved a stage or recorded a sign-off: the next read of this product's line reads it again (the old rows serve meanwhile). */
|
|
158
|
+
function forgetLine(wsId) { const c = LINES.get(wsId); if (c) c.at = 0; }
|
|
159
|
+
/** The line's rows as kept now, without waiting: a stale or missing answer starts a new read in the background. null while nothing was read yet.
|
|
160
|
+
* For a row that may come a refresh later (Today's sign-offs), so a slow first read never holds a request open. */
|
|
161
|
+
function lineRowsKept(w, now = Date.now()) {
|
|
162
|
+
const c = LINES.get(w.id);
|
|
163
|
+
if (!c || now - c.at >= LINE_MS) lineRows(w, now).catch(() => {});
|
|
164
|
+
return c && c.rows ? c.rows : null;
|
|
165
|
+
}
|
|
157
166
|
/** The initiatives of a product that are in Your move: a question to the PM, or a check due today. */
|
|
158
167
|
function youOf(ctx, w, today) {
|
|
159
168
|
const out = new Set();
|
|
@@ -217,7 +226,7 @@ async function weekWentRoute(req, res, url, ctx) {
|
|
|
217
226
|
const digestParts = (ctx, w, now) => require('./digest-parts.js').partsOf(ctx, w, lineRows, now); // quiet-rows-digest (reads only)
|
|
218
227
|
|
|
219
228
|
module.exports = {
|
|
220
|
-
expire, questions, asksOf, lineRows, digestParts, quietRoute, weekWentRoute,
|
|
229
|
+
expire, questions, asksOf, lineRows, lineRowsKept, forgetLine, digestParts, quietRoute, weekWentRoute,
|
|
221
230
|
prefixes: ['/api/your-move', '/api/line', '/api/digest', '/api/quiet', '/api/week-went'],
|
|
222
231
|
handle: async (req, res, url, ctx) => {
|
|
223
232
|
if (url.pathname === '/api/week-went') return weekWentRoute(req, res, url, ctx);
|
|
@@ -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:
|
|
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
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* worth-it.js — is each kind of AI run worth what it costs? (initiative worth-it-by-kind, job #1884, idea A160). `pmos ai worth`.
|
|
3
|
+
*
|
|
4
|
+
* `pmos ai status` shows the background runs' cost per kind (lib/run-tokens.js) and, apart, the keep rate of each ✦ job
|
|
5
|
+
* (lib/orchestrator-keeprate.js). This puts them side by side for the month: what each kind of run cost, and how much of what it filed
|
|
6
|
+
* under ✦ the PM kept. It reads only. It pauses nothing; the PM decides with `pmos ai off <kind>`.
|
|
7
|
+
*
|
|
8
|
+
* monthStart(now) → epoch ms of the first of this month, 00:00 local
|
|
9
|
+
* worthOf({ runs, items, since }) PURE → { since, cost, rows: [row] }
|
|
10
|
+
* runs run-token lines ({ at, kind, origin, costUsd }) : a run's kind is its origin (propose, grill, …), else its headless kind
|
|
11
|
+
* items keep-rate items (orchestrator-keeprate readAll): a ✦ proposal's job, by its switch name (JOBS off), decided since `since`
|
|
12
|
+
* row { kind, runs, costUsd, share (of the month's cost, 0–1), decided, kept, keepRate | null, flag }
|
|
13
|
+
* flag share ≥ FLAG_SHARE and keepRate < FLAG_KEEP with decided ≥ MIN_DECIDED: costs most, kept least. Never for fewer decided.
|
|
14
|
+
* lines(W) PURE → [string] what `pmos ai worth` prints
|
|
15
|
+
* No line here writes, sends or calls a model. */
|
|
16
|
+
const FLAG_SHARE = 0.25;
|
|
17
|
+
const FLAG_KEEP = 0.5;
|
|
18
|
+
const MIN_DECIDED = 3;
|
|
19
|
+
|
|
20
|
+
function monthStart(now = Date.now()) { const d = new Date(now); return new Date(d.getFullYear(), d.getMonth(), 1).getTime(); }
|
|
21
|
+
const ms = (v) => (typeof v === 'number' ? v : Date.parse(v));
|
|
22
|
+
|
|
23
|
+
/** PURE. */
|
|
24
|
+
function worthOf({ runs = [], items = [], since = 0 } = {}) {
|
|
25
|
+
const K = require('./orchestrator-keeprate.js');
|
|
26
|
+
const offOf = new Map(K.JOBS.map((j) => [j.job, j.off || j.job]));
|
|
27
|
+
const by = new Map();
|
|
28
|
+
const row = (kind) => { if (!by.has(kind)) by.set(kind, { kind, runs: 0, costUsd: 0, decided: 0, kept: 0 }); return by.get(kind); };
|
|
29
|
+
for (const r of runs || []) {
|
|
30
|
+
if (!r || !(ms(r.at) >= since)) continue;
|
|
31
|
+
const kind = String(r.origin || r.kind || 'other');
|
|
32
|
+
const x = row(kind); x.runs += 1; x.costUsd += Number(r.costUsd) || 0;
|
|
33
|
+
}
|
|
34
|
+
for (const it of items || []) {
|
|
35
|
+
if (!it || it.src !== 'proposal' || it.outcome === 'open' || !(it.decidedAt >= since)) continue;
|
|
36
|
+
const kind = offOf.get(it.type); if (!kind) continue;
|
|
37
|
+
const x = row(kind); x.decided += 1; if (it.outcome === 'kept') x.kept += 1;
|
|
38
|
+
}
|
|
39
|
+
const cost = [...by.values()].reduce((a, x) => a + x.costUsd, 0);
|
|
40
|
+
const rows = [...by.values()].map((x) => {
|
|
41
|
+
const share = cost > 0 ? x.costUsd / cost : 0;
|
|
42
|
+
const keepRate = x.decided ? x.kept / x.decided : null;
|
|
43
|
+
return { ...x, costUsd: Math.round(x.costUsd * 100) / 100, share, keepRate,
|
|
44
|
+
flag: x.decided >= MIN_DECIDED && keepRate < FLAG_KEEP && share >= FLAG_SHARE };
|
|
45
|
+
}).sort((a, b) => b.costUsd - a.costUsd || b.runs - a.runs || a.kind.localeCompare(b.kind));
|
|
46
|
+
return { since, cost: Math.round(cost * 100) / 100, rows };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const pct = (r) => Math.round(r * 100) + '%';
|
|
50
|
+
const usd = (n) => '$' + n.toFixed(2);
|
|
51
|
+
/** PURE. */
|
|
52
|
+
function lines(W) {
|
|
53
|
+
const day = new Date(W.since);
|
|
54
|
+
const from = `${day.getDate()} ${['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][day.getMonth()]}`;
|
|
55
|
+
if (!W.rows.length) return [`No background run and no ✦ decided since ${from}.`];
|
|
56
|
+
const out = [`Each kind of AI run since ${from}: ${usd(W.cost)} in all. Cost next to what you kept of its ✦ proposals.`];
|
|
57
|
+
for (const r of W.rows) {
|
|
58
|
+
const cost = r.runs ? `${r.runs} run${r.runs === 1 ? '' : 's'}, ${usd(r.costUsd)}${W.cost > 0 ? ' (' + pct(r.share) + ')' : ''}` : 'no run logged';
|
|
59
|
+
const kept = r.decided ? `kept ${r.kept} of ${r.decided} (${pct(r.keepRate)})` : 'no ✦ decided to judge it on';
|
|
60
|
+
out.push(` ${r.kind}: ${cost} · ${kept}${r.flag ? ` · costs most, kept least: pause it? pmos ai off ${r.kind}` : ''}`);
|
|
61
|
+
}
|
|
62
|
+
if (W.rows.some((r) => r.flag)) out.push('You decide. PMOS pauses nothing by itself.');
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = { FLAG_SHARE, FLAG_KEEP, MIN_DECIDED, monthStart, worthOf, lines };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.822.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.822.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED