create-pmos 0.767.0 → 0.768.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 +20 -14
- package/payload/AGENTS.md +3 -1
- 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/kind-sync.js +112 -0
- package/payload/scripts/workflow-state.js +20 -2
- package/payload/scripts/workflows.js +374 -0
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +19 -0
- package/workspace/guide/breakdown.md +5 -3
- package/workspace/lib/engine/workflow-state.js +20 -2
- package/workspace/lib/engine/workflows.js +27 -3
- package/workspace/lib/initiative-writer.js +12 -1
- package/workspace/lib/routes-boards.js +19 -2
- package/workspace/lib/vendor/scripts/workflow-state.js +20 -2
- package/workspace/lib/vendor/scripts/workflows.js +374 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-pop-work.css +7 -0
- package/workspace/public/pm/cozy-pop-work.js +27 -12
- package/workspace/public/pm/work-select.js +27 -5
- package/workspace/test-lists/gantt-drag-nest.json +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.768.0",
|
|
4
4
|
"description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,25 @@
|
|
|
33
33
|
"audit"
|
|
34
34
|
],
|
|
35
35
|
"pmosChanges": [
|
|
36
|
+
{
|
|
37
|
+
"v": "0.768.0",
|
|
38
|
+
"at": "2026-11-24T07:49:37.442Z",
|
|
39
|
+
"f": 4,
|
|
40
|
+
"prs": [
|
|
41
|
+
{
|
|
42
|
+
"n": 1731,
|
|
43
|
+
"t": "The workflow decides the kind of work, not a legacy type: feature",
|
|
44
|
+
"s": "The workflow decides the kind of work, not a legacy type: feature",
|
|
45
|
+
"k": "fix"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"n": 1730,
|
|
49
|
+
"t": "Drag to nest, take out and reorder in the Gantt, like the List",
|
|
50
|
+
"s": "Drag to nest, take out and reorder in the Gantt, like the List",
|
|
51
|
+
"k": "new"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
},
|
|
36
55
|
{
|
|
37
56
|
"v": "0.767.0",
|
|
38
57
|
"at": "2026-11-24T07:34:38.820Z",
|
|
@@ -357,19 +376,6 @@
|
|
|
357
376
|
"k": "new"
|
|
358
377
|
}
|
|
359
378
|
]
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
"v": "0.748.0",
|
|
363
|
-
"at": "2026-11-23T14:27:01.777Z",
|
|
364
|
-
"f": 4,
|
|
365
|
-
"prs": [
|
|
366
|
-
{
|
|
367
|
-
"n": 1677,
|
|
368
|
-
"t": "The work popup's date press opens the range picker; keep its focus",
|
|
369
|
-
"s": "The work popup's date press opens the range picker; keep its focus",
|
|
370
|
-
"k": "x"
|
|
371
|
-
}
|
|
372
|
-
]
|
|
373
379
|
}
|
|
374
380
|
]
|
|
375
381
|
}
|
package/payload/AGENTS.md
CHANGED
|
@@ -48,7 +48,7 @@ It refuses frontmatter, fenced and indented code, table rows, headings, delibera
|
|
|
48
48
|
| `log_friction` / `log_discovery` | append to `pmos/state/discoveries.md` (ISO date, `#friction` tag where applicable) |
|
|
49
49
|
| `get_agent_runs` / `get_friction` | read those same files (your episodic memory — consult before contracting) |
|
|
50
50
|
|
|
51
|
-
**Programs** (the level above initiatives, across products) are not an initiative key. A program is a line in `pmos/state/programs.jsonl`: `{"kind":"program",…}` is the charter and `{"kind":"member","program":"<id>","initiative":"<id>"}` puts an initiative in it. Never add `
|
|
51
|
+
**Programs** (the level above initiatives, across products) are not an initiative key. A program is a line in `pmos/state/programs.jsonl`: `{"kind":"program",…}` is the charter and `{"kind":"member","program":"<id>","initiative":"<id>"}` puts an initiative in it. Never add `program`, `programme`, `parent_program` or `parent_programme` to an initiative record: nothing reads them. (`kind:` is different: it is the kind of work, and the gate reads it. See below.) Never write `programs.jsonl` by hand. When the PM asks for a program change, or says yes to one you drafted, make it with `pmos program` (`new`, `charter`, `join`, `leave`, `milestone`, `check`, `task`, `order`, `archive`; `pmos program help`) and give the Undo it prints. The Board shows it when your turn ends.
|
|
52
52
|
|
|
53
53
|
State files are **append-only**: never rewrite or delete an existing line or initiative record; correct by appending. When a vendored skill names a hosted tool, apply this table — the skill bodies are single-sourced from the PMOS kernel and are not forked for file mode.
|
|
54
54
|
|
|
@@ -58,6 +58,8 @@ State files are **append-only**: never rewrite or delete an existing line or ini
|
|
|
58
58
|
|
|
59
59
|
## Work-type lanes (D56)
|
|
60
60
|
|
|
61
|
+
**The kind of work comes first.** Read `kind:` before `type:`. `kind:` is `product`, `project` or `sdlc`, and it follows the initiative's workflow: when the PM puts an initiative on a workflow, PMOS writes the workflow's kind on the record (a Migration, Decommission, Tender or Project workflow is `project`; Full SDLC is `sdlc`; Product feature and other product workflows are `product`). `kind: project` needs a dated plan (dated tasks with a ◇ milestone, or `plan_path`), never a PRD or a rubric. `kind: sdlc` needs a done test and a kill condition, never a PRD. Only `kind: product` (or no kind line) uses the lane rules below. A record with `done_test_path` and `kill:` passes in every kind (D107). Many older records carry `type: feature` only because it was the default before workflows existed: on a `project` or `sdlc` record it decides nothing. Never ask for a PRD or rubric because of it, and never suggest another lane (such as `chore`) to get round a PRD. When a record's kind does not match its workflow, run `node pmos/scripts/kind-sync.js --root .` to list it, and with the PM's yes `--fix --backup <dir>` to correct it (the backup holds an UNDO.sh).
|
|
62
|
+
|
|
61
63
|
Every initiative carries a `type` — the lane picks what the gate requires **before** work; the kernel (anchor — a KR **or** `health:<id>` from `planning/okrs/health-budgets.md` (D59) — eval-before-work in lane-appropriate form, human Acceptance, append-only state) holds in every lane. Unknown/missing type = `feature`, the strictest lane. The enum is closed — never invent a lane; a work shape with no lane escalates to the PM.
|
|
62
64
|
|
|
63
65
|
**A lane is not a workflow (D99).** A lane sets what the gate requires before work. A workflow is the list of stages an initiative goes through on the PM's page (Triage, Discover, Plan…), and the PM picks it per initiative. Read workflows only through pmos: `pmos workflow of <initiative>` gives the initiative's workflow and its stages, `pmos workflow show <id>` gives one workflow's stages, and `pmos workflow list` names every workflow the PM can pick. The workflow library is not in this repository's files (Settings › Workflows saves it in the PM's home workspace), so never search the files for a workflow. When pmos cannot find a workflow, tell the PM so. Never use a lane in place of a workflow.
|
package/payload/KIT-VERSION
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Eval calibration log"
|
|
4
4
|
description: "Append-only record of every PM override of an evaluator verdict."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-24T07:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-24T07:49:33Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Health budgets"
|
|
4
4
|
description: "Closed registry of health-budget anchors (D59), edited only by the PM."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-24T07:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-24T07:49:33Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/*
|
|
4
|
+
* kind-sync.js — make each initiative record's `kind:` follow the workflow it runs.
|
|
5
|
+
*
|
|
6
|
+
* node scripts/kind-sync.js --root <repo> list the records whose kind contradicts their workflow
|
|
7
|
+
* node scripts/kind-sync.js --root <repo> --fix --backup <dir> correct them; the originals and an UNDO.sh go to <dir>
|
|
8
|
+
* add --json for machine-readable output
|
|
9
|
+
*
|
|
10
|
+
* WHY (bug 2026-11-24, "Migration from Okta to Descope"): records written before workflows existed carry the old default
|
|
11
|
+
* `type: feature` and no `kind:` line, so they read as Product management and the gate asks them for a PRD and a rubric, even when
|
|
12
|
+
* the PM later put them on a Migration or Decommission workflow. The workflow is the PM's later, more specific choice. The
|
|
13
|
+
* workspace now writes `kind:` when an initiative starts on or switches workflow (lib/routes-boards.js kindFollowsWorkflow); this
|
|
14
|
+
* tool corrects the records written before that.
|
|
15
|
+
*
|
|
16
|
+
* What it changes: the `kind:` line only (added at the end of the front matter, or replaced). It never touches `type:`, `lane:`,
|
|
17
|
+
* paths or the body. A record on Product feature, or on no recorded workflow, is never changed. --fix without --backup refuses.
|
|
18
|
+
*/
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const path = require('path');
|
|
21
|
+
const WS = require('./workflow-state');
|
|
22
|
+
const WF = require('./workflows');
|
|
23
|
+
const jsonl = require('./read-jsonl');
|
|
24
|
+
|
|
25
|
+
function stateFile(root, name) {
|
|
26
|
+
return [['pmos', 'state'], ['state'], ['.pmos']].map((rel) => path.join(root, ...rel, name)).find((x) => fs.existsSync(x)) || null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Every record and the workflow it runs → [{ id, file, kind, has, wf, wfName, want }]; `want` differs from `kind` on a mismatch. */
|
|
30
|
+
function scan(root) {
|
|
31
|
+
const L = WS.layout(root);
|
|
32
|
+
const boards = stateFile(root, 'boards.jsonl');
|
|
33
|
+
if (!boards) return { ok: false, error: `no boards.jsonl under ${root} — this repository does not run initiatives on workflows` };
|
|
34
|
+
const wfOf = new Map();
|
|
35
|
+
for (const l of jsonl.readJsonl(boards).rows) if (l && l.kind === 'ini-wf' && typeof l.id === 'string' && typeof l.wf === 'string' && l.wf) wfOf.set(l.id, l.wf);
|
|
36
|
+
const wfFile = stateFile(root, 'workflows.jsonl');
|
|
37
|
+
const lib = WF.fold(wfFile ? jsonl.readJsonl(wfFile).rows : []);
|
|
38
|
+
const rows = [];
|
|
39
|
+
let names = [];
|
|
40
|
+
try { names = fs.readdirSync(L.initiatives).filter((n) => n.endsWith('.md') && n !== 'index.md' && n !== 'log.md' && n !== 'README.md'); } catch { /* none */ }
|
|
41
|
+
for (const n of names.sort()) {
|
|
42
|
+
const file = path.join(L.initiatives, n);
|
|
43
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
44
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
|
|
45
|
+
if (!m) continue;
|
|
46
|
+
const line = m[1].split(/\r?\n/).find((l) => /^kind:/.test(l));
|
|
47
|
+
const raw = line ? line.slice(5).trim().replace(/^["']|["']$/g, '') : '';
|
|
48
|
+
const kind = WF.WORK_KINDS.includes(raw) ? raw : 'product';
|
|
49
|
+
const id = n.slice(0, -3);
|
|
50
|
+
const wf = wfOf.has(id) ? WF.resolve(lib, wfOf.get(id)) : WF.defaultOf(lib);
|
|
51
|
+
rows.push({ id, file, kind, has: !!line, wf: wf.id, wfName: wf.name, want: WF.kindOf(wf) });
|
|
52
|
+
}
|
|
53
|
+
return { ok: true, rows, mismatches: rows.filter((r) => r.want !== r.kind) };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function setKindLine(file, kind) {
|
|
57
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
58
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---(\r?\n|$)/.exec(text);
|
|
59
|
+
if (!m) return false;
|
|
60
|
+
const lines = m[1].split(/\r?\n/);
|
|
61
|
+
const at = lines.findIndex((l) => /^kind:/.test(l));
|
|
62
|
+
if (at >= 0) lines[at] = 'kind: ' + kind; else lines.push('kind: ' + kind);
|
|
63
|
+
fs.writeFileSync(file, '---\n' + lines.join('\n') + '\n---' + m[2] + text.slice(m[0].length));
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const q = (s) => "'" + String(s).replace(/'/g, "'\\''") + "'";
|
|
68
|
+
|
|
69
|
+
function fix(root, backup) {
|
|
70
|
+
const s = scan(root);
|
|
71
|
+
if (!s.ok) return s;
|
|
72
|
+
if (!s.mismatches.length) return { ok: true, changed: [] };
|
|
73
|
+
const recDir = path.join(backup, 'initiatives');
|
|
74
|
+
fs.mkdirSync(recDir, { recursive: true });
|
|
75
|
+
const undo = ['#!/usr/bin/env bash', `# Puts back the ${s.mismatches.length} initiative record(s) kind-sync.js changed on ${new Date().toISOString()}.`, 'set -euo pipefail', `cd "$(dirname "$0")"`];
|
|
76
|
+
const changed = [];
|
|
77
|
+
for (const r of s.mismatches) {
|
|
78
|
+
fs.copyFileSync(r.file, path.join(recDir, path.basename(r.file)));
|
|
79
|
+
if (!setKindLine(r.file, r.want)) continue;
|
|
80
|
+
undo.push(`cp initiatives/${q(path.basename(r.file))} ${q(r.file)}`);
|
|
81
|
+
changed.push({ id: r.id, from: r.kind, to: r.want, workflow: r.wfName });
|
|
82
|
+
}
|
|
83
|
+
fs.writeFileSync(path.join(backup, 'UNDO.sh'), undo.join('\n') + '\n', { mode: 0o755 });
|
|
84
|
+
fs.writeFileSync(path.join(backup, 'changes.json'), JSON.stringify({ root, at: new Date().toISOString(), changed }, null, 2) + '\n');
|
|
85
|
+
return { ok: true, changed, backup };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function main(argv) {
|
|
89
|
+
const a = argv.slice(2);
|
|
90
|
+
const val = (k) => { const i = a.indexOf(k); return i >= 0 ? a[i + 1] : null; };
|
|
91
|
+
const root = path.resolve(val('--root') || process.cwd());
|
|
92
|
+
const json = a.includes('--json');
|
|
93
|
+
let out;
|
|
94
|
+
if (a.includes('--fix')) {
|
|
95
|
+
const b = val('--backup');
|
|
96
|
+
if (!b) { console.error('kind-sync: --fix needs --backup <dir> (the originals and UNDO.sh go there)'); return 2; }
|
|
97
|
+
out = fix(root, path.resolve(b));
|
|
98
|
+
} else out = scan(root);
|
|
99
|
+
if (!out.ok) { console.error('kind-sync: ' + out.error); return 1; }
|
|
100
|
+
if (json) { console.log(JSON.stringify(out.changed ? out : { ok: true, mismatches: out.mismatches.map(({ file: _f, ...r }) => r) }, null, 2)); return 0; }
|
|
101
|
+
if (out.changed) {
|
|
102
|
+
for (const c of out.changed) console.log(`${c.id}: ${c.from} → ${c.to} (runs ${c.workflow})`);
|
|
103
|
+
console.log(out.changed.length ? `${out.changed.length} changed. Undo: bash ${path.join(out.backup, 'UNDO.sh')}` : 'Nothing to change.');
|
|
104
|
+
} else {
|
|
105
|
+
for (const r of out.mismatches) console.log(`${r.id}: record reads ${r.kind}${r.has ? '' : ' (no kind line)'}, runs ${r.wfName} → ${r.want}`);
|
|
106
|
+
console.log(out.mismatches.length ? `${out.mismatches.length} to correct. Run again with --fix --backup <dir>.` : `All ${out.rows.length} records match their workflow.`);
|
|
107
|
+
}
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = { scan, fix };
|
|
112
|
+
if (require.main === module) process.exitCode = main(process.argv);
|
|
@@ -640,6 +640,24 @@ function workflowOf(root, id) {
|
|
|
640
640
|
}
|
|
641
641
|
return m.wf.get(id) || '';
|
|
642
642
|
}
|
|
643
|
+
/*
|
|
644
|
+
* workKindOf(root, id, fm) — the kind of work that sets the gate: the record's `kind:` line when it has one, else the kind of the workflow
|
|
645
|
+
* the initiative runs (scripts/workflows.js kindOf). Bug 2026-11-24: a Migration initiative kept the `type: feature` its record was born
|
|
646
|
+
* with before workflows existed, and the gate asked it for a PRD and a rubric. The workflow is the later, more specific choice, so it
|
|
647
|
+
* decides. No workflow (PMOS itself, a repository without boards) or Product feature keeps 'product', the lane rules.
|
|
648
|
+
*/
|
|
649
|
+
function workKindOf(root, id, fm) {
|
|
650
|
+
const k = String((fm && fm.kind) || '').trim().replace(/^["']|["']$/g, '');
|
|
651
|
+
if (k === 'sdlc' || k === 'project' || k === 'product') return k;
|
|
652
|
+
try {
|
|
653
|
+
const wfId = workflowOf(root, id);
|
|
654
|
+
if (wfId === null) return 'product';
|
|
655
|
+
const WF = require('./workflows');
|
|
656
|
+
const f = [['pmos', 'state'], ['state'], ['.pmos']].map((rel) => path.join(root, ...rel, 'workflows.jsonl')).find((x) => fs.existsSync(x));
|
|
657
|
+
const lib = WF.fold(f ? jsonl.readJsonl(f).rows : []);
|
|
658
|
+
return WF.kindOf(wfId ? WF.resolve(lib, wfId) : WF.defaultOf(lib));
|
|
659
|
+
} catch { return 'product'; }
|
|
660
|
+
}
|
|
643
661
|
/** The lanes a repository's initiatives may declare — what the lane picker offers and the lane write accepts. */
|
|
644
662
|
function laneNames(profile) { return laneDefs.laneNames(profile === 'pm-artifacts' ? 'pm-artifacts' : 'product-code'); }
|
|
645
663
|
function lanesFor(root) {
|
|
@@ -1019,7 +1037,7 @@ function computeWorkflowDerived(id, opts) {
|
|
|
1019
1037
|
// W5 (boards WfA/WfB/WfC, agreed 2026-11-12): the kind of work sets the gate. Full SDLC: a done test and a kill condition before the first
|
|
1020
1038
|
// pull request. Project: a dated plan (plan_path), never a PRD. Product management (and a record with no kind:) keeps the rules below. A
|
|
1021
1039
|
// PRD already on the record still satisfies the spec rung after a kind change: a gate already passed stays passed.
|
|
1022
|
-
const workKind = (
|
|
1040
|
+
const workKind = workKindOf(root, id, fm);
|
|
1023
1041
|
const planPath = String(fm.plan_path || '').trim();
|
|
1024
1042
|
const agentMode = agentEvalSet.isAgent(fm);
|
|
1025
1043
|
if (agentMode && !doneTest) {
|
|
@@ -1667,7 +1685,7 @@ function pmLadder({ id, fm, lane, effLane, knownLane, legacy, steps, root, L, re
|
|
|
1667
1685
|
// W6 (launch simulation rerun, 2026-11-15): the kind of work sets this ladder too, as it sets the product-code gate (W5) and the kit gate.
|
|
1668
1686
|
// Full SDLC: a done test and a kill condition, never a brief. Project: a dated plan (plan_path), never a brief. A brief already on the
|
|
1669
1687
|
// record still passes (a gate passed stays passed). Their deliverable is not a document: the pull requests, or the plan's milestones.
|
|
1670
|
-
const workKind = (
|
|
1688
|
+
const workKind = workKindOf(root, id, fm);
|
|
1671
1689
|
const planPath = String(fm.plan_path || '').trim();
|
|
1672
1690
|
const kindSpec = !doneTest && !exists(briefPath) && !foundBrief && (workKind === 'sdlc' || (workKind === 'project'));
|
|
1673
1691
|
const tasksPlan = kindSpec && workKind === 'project' && !planPath ? taskPlanOf(root, id) : null;
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* workflows.js — the workflows an initiative can run (D99, initiative workflows-per-initiative). Pure: no file, no clock.
|
|
3
|
+
* workspace/lib/routes-workflows.js does the I/O (<state dir>/workflows.jsonl) and lib/routes-boards.js reads an initiative's workflow.
|
|
4
|
+
*
|
|
5
|
+
* CATS · ENDS · OUTPUT_KINDS · WHEN_MODES · DECIDE · ICONS · PRODUCT_FEATURE_ID · PRODUCT_FEATURE
|
|
6
|
+
* kindOf(wf) → 'product' | 'sdlc' | 'project' the kind of work the workflow runs; it sets the gate (see below)
|
|
7
|
+
* check(wf, { existing }) → { ok, workflow } | { ok:false, status, error } validate and normalise one workflow
|
|
8
|
+
* PROJECT · FULL_SDLC · BUILTIN · KIND_WF the two workflows the kind of work starts on (W5, boards WfA/WfB/WfC), built in like Product feature
|
|
9
|
+
* forKind(folded, kind) · isKindDefault(folded, kind, wfId) the workflow a kind starts on; whether an initiative still runs it
|
|
10
|
+
* fold(lines) → { byId: Map, draft, defaultId } the library (the built-ins first)
|
|
11
|
+
* list(folded, counts?) → [workflow + { count, default? }] Product feature first, archived last
|
|
12
|
+
* defaultOf(folded) → the workflow a new initiative starts on (Product feature when none is set or it is archived)
|
|
13
|
+
* resolve(folded, id) → the workflow (Product feature when the id is unknown or missing)
|
|
14
|
+
* stageByRef(wf, ref) → the stage a key or a name names, or null
|
|
15
|
+
* switchTarget(from, to, stageKey) → the key an initiative lands on when it switches workflow (the bridge's stage, see mapOf)
|
|
16
|
+
* proposeBridge(from, to) → { [fromKey]: toKey } Claude's proposal of where each old stage goes (batch 20 item 3)
|
|
17
|
+
* mapOf(from, to, override?) → { [fromKey]: toKey } every old stage's new stage: the PM's override, the saved bridge, the proposal
|
|
18
|
+
* removedInUse(before, after, standing)→ [{ id, stage }] initiatives that stand in a stage the edit removes
|
|
19
|
+
* stagesOf(wf, { judged, current }) → the initiative's own stages, each with its reading and status (the ONE function every surface reads)
|
|
20
|
+
* copyOf(wf, name, taken) → a new editable copy
|
|
21
|
+
*
|
|
22
|
+
* A WORKFLOW is { id, name, icon, builtin?, decide, archived?, stages: [STAGE], bridge? }.
|
|
23
|
+
* bridge { from, map: { [fromStageKey]: stageKey } }: where each stage of the workflow it replaces lands (batch 20 item 3, canvas WmB).
|
|
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 }] }.
|
|
26
|
+
* cat ∈ CATS (To do, In progress, Done). Won't do and Archived (ENDS) are in every workflow and are not stages.
|
|
27
|
+
* The first stage is always `triage`, in To do. `then` null means the next stage in the list. `unless` sends the initiative elsewhere
|
|
28
|
+
* when PMOS judges its plain words true. A key is the slug of the stage's first name and survives a rename.
|
|
29
|
+
*
|
|
30
|
+
* THE LEDGER (workflows.jsonl), one line per change, the last line for an id wins; nothing is deleted:
|
|
31
|
+
* wf-save { wf } create or edit (Product feature is never saved: it is built in)
|
|
32
|
+
* wf-archive { id, archived }
|
|
33
|
+
* wf-draft { draft | null, note? } the one open draft the chat wrote (null clears it)
|
|
34
|
+
* wf-default { id } the workflow a new initiative starts on, for this workspace (batch 24 item 3, canvas DfA). The last
|
|
35
|
+
* line wins. Product feature can be the default. An unknown or archived id reads as Product feature.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
const { STAGES: LIFE, LABELS, OUTPUTS, MILESTONES } = require('./nine-stages');
|
|
39
|
+
|
|
40
|
+
const CATS = Object.freeze(['todo', 'doing', 'done']);
|
|
41
|
+
const CAT_LABEL = Object.freeze({ todo: 'To do', doing: 'In progress', done: 'Done', wontdo: "Won't do", archived: 'Archived' });
|
|
42
|
+
const ENDS = Object.freeze(['wontdo', 'archived']);
|
|
43
|
+
const OUTPUT_KINDS = Object.freeze(['doc', 'jira', 'signoff', 'checklist']);
|
|
44
|
+
const WHEN_MODES = Object.freeze(['always', 'optional', 'only']);
|
|
45
|
+
const DECIDE = Object.freeze(['pmos', 'confirm']);
|
|
46
|
+
const ICONS = Object.freeze(['feature', 'doc', 'cart', 'swap', 'people', 'shield', 'box', 'flag', 'build', 'chart']);
|
|
47
|
+
const PRODUCT_FEATURE_ID = 'product-feature';
|
|
48
|
+
const NAME_MAX = 60, TEXT_MAX = 300, FINISH_MAX = 20, STAGES_MAX = 30;
|
|
49
|
+
|
|
50
|
+
const slug = (s) => String(s || '').toLowerCase().normalize('NFKD').replace(/[^\x00-\x7f]/g, '').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 40).replace(/-+$/, '');
|
|
51
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
52
|
+
const oneLine = (v, max) => typeof v === 'string' && v.trim().length >= 1 && v.trim().length <= max && !/[\r\n\x00-\x08\x0b-\x1f]/.test(v);
|
|
53
|
+
|
|
54
|
+
// Product feature: the eight steps of scripts/nine-stages.js, each in its category, with the output that finishes it.
|
|
55
|
+
const PF_KIND = { triage: 'doc', discover: 'doc', plan: 'doc', prioritize: 'checklist', build: 'jira', deliver: 'signoff', monitor: 'doc', evaluate: 'signoff' };
|
|
56
|
+
const PRODUCT_FEATURE = Object.freeze({
|
|
57
|
+
id: PRODUCT_FEATURE_ID, name: 'Product feature', icon: 'feature', builtin: true, decide: 'pmos',
|
|
58
|
+
stages: Object.freeze(LIFE.map((k) => Object.freeze({
|
|
59
|
+
key: k, name: LABELS[k], cat: k === 'triage' ? 'todo' : k === 'evaluate' ? 'done' : 'doing',
|
|
60
|
+
output: Object.freeze({ name: OUTPUTS[k], kind: PF_KIND[k] }), finish: Object.freeze([]), milestone: MILESTONES.has(k), auto: false,
|
|
61
|
+
when: Object.freeze({ mode: 'always' }), then: null, unless: Object.freeze([]),
|
|
62
|
+
}))),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// The kind of work sets the default workflow (launch simulation W5, main canvas boards WfA, WfB, WfC; agreed by Wawan 2026-11-12). Two more
|
|
66
|
+
// workflows are built in beside Product feature and, like it, cannot be edited (copy one to make your own). Every workflow starts with the
|
|
67
|
+
// key `triage` (the first stage, in To do); these two name it for their work: Initiate, and Done test.
|
|
68
|
+
const st = (key, name, cat, out, kind, o = {}) => Object.freeze({ key, name, cat, output: Object.freeze({ name: out, kind }), finish: Object.freeze(o.finish || []),
|
|
69
|
+
milestone: !!o.milestone, auto: false, when: Object.freeze({ mode: 'always' }), then: null, unless: Object.freeze([]) });
|
|
70
|
+
const PROJECT_ID = 'project', FULL_SDLC_ID = 'full-sdlc';
|
|
71
|
+
const PROJECT = Object.freeze({
|
|
72
|
+
id: PROJECT_ID, name: 'Project', icon: 'flag', builtin: true, decide: 'pmos', kind: 'project',
|
|
73
|
+
stages: Object.freeze([
|
|
74
|
+
st('triage', 'Initiate', 'todo', 'The charter: the goal, the date and who owns it', 'doc'),
|
|
75
|
+
st('plan', 'Plan', 'doing', 'A dated plan: milestones with owners from People, go-live matching the KR date', 'checklist', { milestone: true }),
|
|
76
|
+
st('execute', 'Execute', 'doing', 'The tasks done against the baseline', 'checklist'),
|
|
77
|
+
st('monitor', 'Monitor', 'doing', 'Go-live reached; the dates watched against the baseline', 'checklist', { milestone: true }),
|
|
78
|
+
st('close', 'Close', 'done', 'The lessons, and the outcome check', 'signoff'),
|
|
79
|
+
]),
|
|
80
|
+
});
|
|
81
|
+
const FULL_SDLC = Object.freeze({
|
|
82
|
+
id: FULL_SDLC_ID, name: 'Full SDLC', icon: 'build', builtin: true, decide: 'pmos', kind: 'sdlc',
|
|
83
|
+
stages: Object.freeze([
|
|
84
|
+
st('triage', 'Done test', 'todo', 'The done test and the kill condition, dated before the first pull request', 'doc'),
|
|
85
|
+
st('pulls', 'Pull requests', 'doing', 'The pull requests of the PR plan', 'checklist'),
|
|
86
|
+
st('ci', 'CI', 'doing', 'Green required checks on every pull request of the plan', 'checklist'),
|
|
87
|
+
st('merge', 'Merge', 'doing', 'Every pull request merged; the done test passes on the merged branch', 'checklist', { milestone: true }),
|
|
88
|
+
st('release', 'Release', 'done', 'Released; the outcome check starts', 'signoff', { milestone: true }),
|
|
89
|
+
]),
|
|
90
|
+
});
|
|
91
|
+
const BUILTIN = Object.freeze({ [PRODUCT_FEATURE_ID]: PRODUCT_FEATURE, [PROJECT_ID]: PROJECT, [FULL_SDLC_ID]: FULL_SDLC });
|
|
92
|
+
const isBuiltin = (id) => Object.prototype.hasOwnProperty.call(BUILTIN, id);
|
|
93
|
+
/** The workflow each kind of work starts on (lib/work-kind.js KINDS). Product management: the workspace's default (defaultOf). */
|
|
94
|
+
const KIND_WF = Object.freeze({ product: PRODUCT_FEATURE_ID, sdlc: FULL_SDLC_ID, project: PROJECT_ID });
|
|
95
|
+
/* Switching between the built-in workflows maps stages BY MEANING (WfC): Plan to Plan, Build to Execute, Release to Close. The proposal
|
|
96
|
+
* (proposeBridge) cannot know that Deliver is a release, so the three are mapped here and mapOf reads this before the proposal. */
|
|
97
|
+
const MEANING = Object.freeze({
|
|
98
|
+
'product-feature>project': { triage: 'triage', discover: 'triage', plan: 'plan', prioritize: 'plan', build: 'execute', deliver: 'close', monitor: 'close', evaluate: 'close' },
|
|
99
|
+
'product-feature>full-sdlc': { triage: 'triage', discover: 'triage', plan: 'triage', prioritize: 'triage', build: 'pulls', deliver: 'release', monitor: 'release', evaluate: 'release' },
|
|
100
|
+
'project>product-feature': { triage: 'triage', plan: 'plan', execute: 'build', monitor: 'deliver', close: 'evaluate' },
|
|
101
|
+
'project>full-sdlc': { triage: 'triage', plan: 'triage', execute: 'pulls', monitor: 'merge', close: 'release' },
|
|
102
|
+
'full-sdlc>product-feature': { triage: 'plan', pulls: 'build', ci: 'build', merge: 'build', release: 'deliver' },
|
|
103
|
+
'full-sdlc>project': { triage: 'plan', pulls: 'execute', ci: 'execute', merge: 'monitor', release: 'close' },
|
|
104
|
+
});
|
|
105
|
+
/** What a gate of each kind asks before work leaves planning, said once (the switch line names what the new kind adds). */
|
|
106
|
+
const KIND_GATE = Object.freeze({
|
|
107
|
+
product: 'the Build gate reads the done test and kill condition, or a PRD',
|
|
108
|
+
sdlc: 'the first pull request now needs a done test and a kill condition, dated before the build',
|
|
109
|
+
project: 'the Plan gate now needs a dated plan, milestones with owners and a go-live date that matches the KR',
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const bad = (error, status = 400) => ({ ok: false, status, error });
|
|
113
|
+
|
|
114
|
+
/** Validate and normalise one workflow. `existing` (the library's ids) only matters for a new id clashing with Product feature. */
|
|
115
|
+
function check(wf) {
|
|
116
|
+
if (!isObj(wf)) return bad('a workflow is an object { id?, name, icon?, decide?, stages }');
|
|
117
|
+
if (!oneLine(wf.name, NAME_MAX)) return bad(`a workflow needs a name of one line, at most ${NAME_MAX} characters`);
|
|
118
|
+
const name = wf.name.trim();
|
|
119
|
+
const id = typeof wf.id === 'string' && wf.id ? slug(wf.id) : slug(name);
|
|
120
|
+
if (!id) return bad('the name needs at least one letter or digit');
|
|
121
|
+
if (isBuiltin(id)) return bad(`${BUILTIN[id].name} is built in and cannot be changed. Copy it to make your own.`, 409);
|
|
122
|
+
const icon = ICONS.includes(wf.icon) ? wf.icon : 'flag';
|
|
123
|
+
const decide = wf.decide == null ? 'pmos' : wf.decide;
|
|
124
|
+
if (!DECIDE.includes(decide)) return bad(`decide is one of ${DECIDE.join(', ')}`);
|
|
125
|
+
if (!Array.isArray(wf.stages) || !wf.stages.length) return bad('a workflow needs at least one stage');
|
|
126
|
+
if (wf.stages.length > STAGES_MAX) return bad(`a workflow has at most ${STAGES_MAX} stages`);
|
|
127
|
+
const stages = [];
|
|
128
|
+
const keys = new Set();
|
|
129
|
+
for (let i = 0; i < wf.stages.length; i++) {
|
|
130
|
+
const s = wf.stages[i];
|
|
131
|
+
const at = `stage ${i + 1}`;
|
|
132
|
+
if (!isObj(s)) return bad(`${at} must be an object { name, cat, … }`);
|
|
133
|
+
if (!oneLine(s.name, NAME_MAX)) return bad(`${at} needs a name of one line, at most ${NAME_MAX} characters`);
|
|
134
|
+
const sname = s.name.trim();
|
|
135
|
+
let key = typeof s.key === 'string' && s.key ? slug(s.key) : slug(sname);
|
|
136
|
+
if (!key) return bad(`${at}: the name needs at least one letter or digit`);
|
|
137
|
+
if (keys.has(key)) { if (typeof s.key === 'string' && s.key) return bad(`two stages share the key "${key}"`); let n = 2; while (keys.has(key + '-' + n)) n++; key = key + '-' + n; }
|
|
138
|
+
if (!CATS.includes(s.cat)) return bad(`stage "${sname}": the category is one of To do (todo), In progress (doing), Done (done)`);
|
|
139
|
+
const o = isObj(s.output) ? s.output : {};
|
|
140
|
+
const kind = o.kind == null ? 'checklist' : o.kind;
|
|
141
|
+
if (!OUTPUT_KINDS.includes(kind)) return bad(`stage "${sname}": the output kind is one of ${OUTPUT_KINDS.join(', ')}`);
|
|
142
|
+
if (o.name != null && o.name !== '' && !oneLine(o.name, 120)) return bad(`stage "${sname}": the output is one line of at most 120 characters`);
|
|
143
|
+
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
|
+
const finish = s.finish == null ? [] : s.finish;
|
|
145
|
+
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`);
|
|
146
|
+
const w = isObj(s.when) ? s.when : { mode: 'always' };
|
|
147
|
+
if (!WHEN_MODES.includes(w.mode)) return bad(`stage "${sname}": When it runs is one of ${WHEN_MODES.join(', ')}`);
|
|
148
|
+
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)`);
|
|
149
|
+
const unless = s.unless == null ? [] : s.unless;
|
|
150
|
+
if (!Array.isArray(unless) || unless.length > 5 || unless.some((u) => !isObj(u) || !oneLine(u.text, TEXT_MAX) || typeof u.to !== 'string')) return bad(`stage "${sname}": each Unless is { text, to } and there are at most 5`);
|
|
151
|
+
keys.add(key);
|
|
152
|
+
stages.push({
|
|
153
|
+
key, name: sname, cat: s.cat,
|
|
154
|
+
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,
|
|
156
|
+
when: w.mode === 'only' ? { mode: 'only', text: w.text.trim() } : { mode: w.mode },
|
|
157
|
+
then: typeof s.then === 'string' && s.then ? s.then : null,
|
|
158
|
+
unless: unless.map((u) => ({ text: u.text.trim(), to: u.to })),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
// Triage is always first, in To do (WfAModel, wfRules).
|
|
162
|
+
if (stages[0].key !== 'triage' || stages[0].cat !== 'todo') return bad('Triage is always the first stage, in To do');
|
|
163
|
+
if (stages.slice(1).some((s) => s.key === 'triage')) return bad('only the first stage is Triage');
|
|
164
|
+
// Then and Unless name stages of this workflow (by key or by name).
|
|
165
|
+
const ref = (r) => (keys.has(r) ? r : (stages.find((s) => s.name.toLowerCase() === String(r).toLowerCase()) || {}).key || null);
|
|
166
|
+
for (const s of stages) {
|
|
167
|
+
if (s.then) { const k = ref(s.then); if (!k || k === s.key) return bad(`stage "${s.name}": Then must name another stage of this workflow`); s.then = k; }
|
|
168
|
+
for (const u of s.unless) { const k = ref(u.to); if (!k || k === s.key) return bad(`stage "${s.name}": Unless must go to another stage of this workflow`); u.to = k; }
|
|
169
|
+
}
|
|
170
|
+
let bridge = null;
|
|
171
|
+
if (wf.bridge != null) {
|
|
172
|
+
const br = wf.bridge;
|
|
173
|
+
if (!isObj(br) || typeof br.from !== 'string' || !br.from || !isObj(br.map)) return bad('a bridge is { from: the workflow id it replaces, map: { old stage key: stage of this workflow } }');
|
|
174
|
+
const ent = Object.entries(br.map);
|
|
175
|
+
if (ent.length > STAGES_MAX) return bad(`a bridge maps at most ${STAGES_MAX} stages`);
|
|
176
|
+
const map = {};
|
|
177
|
+
for (const [k, v] of ent) {
|
|
178
|
+
// a stage the bridge sends to that an edit removed drops out: that old stage falls back to Claude's proposal (mapOf), the save goes on
|
|
179
|
+
const nk = typeof v === 'string' ? ref(v) : null;
|
|
180
|
+
if (slug(k) && nk) map[slug(k)] = nk;
|
|
181
|
+
}
|
|
182
|
+
if (Object.keys(map).length && slug(br.from) !== id) bridge = { from: slug(br.from), map };
|
|
183
|
+
}
|
|
184
|
+
if (wf.kind != null && wf.kind !== '' && !WORK_KINDS.includes(wf.kind)) return bad(`the kind of work is one of ${WORK_KINDS.join(', ')}`);
|
|
185
|
+
const kind = WORK_KINDS.includes(wf.kind) ? wf.kind : null;
|
|
186
|
+
return { ok: true, workflow: { id, name, icon, decide, ...(kind ? { kind } : {}), stages, ...(bridge ? { bridge } : {}) } };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/*
|
|
190
|
+
* kindOf(wf) — the kind of work a workflow runs: 'product' | 'sdlc' | 'project' (lib/work-kind.js KINDS).
|
|
191
|
+
*
|
|
192
|
+
* WHY (bug 2026-11-24, "Migration from Okta to Descope"): the gate read what an initiative must write from the record's old `type:`
|
|
193
|
+
* line, which the first records got as `feature` before workflows existed. Picking a Migration workflow later changed nothing, so the
|
|
194
|
+
* gate still asked a migration for a PRD and a rubric. The workflow is the PM's later and more specific choice, so the kind follows it.
|
|
195
|
+
* The built-ins say their kind. A saved workflow can say its own (`kind`). Else the name and the stage names decide, with the words
|
|
196
|
+
* lib/work-kind.js uses for a new initiative's name: a delivery word (migrate, cutover, decommission, rollout, tender, ...) reads as a
|
|
197
|
+
* Project; nothing reads as Product management, which keeps the lane rules, the old behaviour.
|
|
198
|
+
*/
|
|
199
|
+
const WORK_KINDS = Object.freeze(['product', 'sdlc', 'project']);
|
|
200
|
+
const PROJECT_CUES = ['migrate', 'migration', 'tender', 'rollout', 'roll out', 'vendor', 'procurement', 'rfp', 'cutover', 'decommission', 'switch off', 'hypercare', 'renewal', 'go-live', 'go live'];
|
|
201
|
+
const cueIn = (text) => PROJECT_CUES.find((w) => new RegExp('\\b' + w.replace(/[ -]/g, '[\\s-]+') + '\\b', 'i').test(text)) || '';
|
|
202
|
+
function kindOf(wf) {
|
|
203
|
+
if (!wf || typeof wf !== 'object') return 'product';
|
|
204
|
+
if (WORK_KINDS.includes(wf.kind)) return wf.kind;
|
|
205
|
+
if (wf.id === PRODUCT_FEATURE_ID) return 'product';
|
|
206
|
+
const words = [wf.name].concat((wf.stages || []).map((s) => s && s.name)).filter(Boolean).join(' · ');
|
|
207
|
+
return cueIn(words) ? 'project' : 'product';
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Fold workflows.jsonl (objects or JSON strings), oldest first. */
|
|
211
|
+
function fold(lines) {
|
|
212
|
+
const byId = new Map(Object.entries(BUILTIN));
|
|
213
|
+
let draft = null, defaultId = null;
|
|
214
|
+
for (const raw of lines || []) {
|
|
215
|
+
let e = raw;
|
|
216
|
+
if (typeof raw === 'string') { try { e = JSON.parse(raw); } catch { continue; } }
|
|
217
|
+
if (!isObj(e)) continue;
|
|
218
|
+
if (e.kind === 'wf-save' && isObj(e.wf)) {
|
|
219
|
+
const c = check(e.wf);
|
|
220
|
+
if (!c.ok) continue;
|
|
221
|
+
const was = byId.get(c.workflow.id);
|
|
222
|
+
// copiedFrom: the workflow it began as a copy of (Product feature cannot be edited, so a simpler one starts as its copy): the ✦ that moves
|
|
223
|
+
// the initiatives over reads it (batch 20 item 3)
|
|
224
|
+
const cf = typeof e.copiedFrom === 'string' ? e.copiedFrom : was && was.copiedFrom ? was.copiedFrom : null;
|
|
225
|
+
byId.set(c.workflow.id, { ...c.workflow, ...(was && was.archived ? { archived: true } : {}), ...(cf ? { copiedFrom: cf } : {}), at: e.at || null });
|
|
226
|
+
} else if (e.kind === 'wf-archive' && typeof e.id === 'string' && byId.has(e.id) && !isBuiltin(e.id)) {
|
|
227
|
+
const w = { ...byId.get(e.id) };
|
|
228
|
+
if (e.archived) w.archived = true; else delete w.archived;
|
|
229
|
+
byId.set(e.id, w);
|
|
230
|
+
} else if (e.kind === 'wf-draft') {
|
|
231
|
+
draft = isObj(e.draft) ? { draft: e.draft, note: typeof e.note === 'string' ? e.note : '', at: e.at || null } : null;
|
|
232
|
+
} else if (e.kind === 'wf-default' && typeof e.id === 'string' && e.id) {
|
|
233
|
+
defaultId = e.id;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return { byId, draft, defaultId };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** The workflow a new initiative starts on: the last wf-default line's workflow, or Product feature when none is set, the id is not in the
|
|
240
|
+
* library, or that workflow is archived. */
|
|
241
|
+
function defaultOf(folded) {
|
|
242
|
+
const w = folded && folded.defaultId ? folded.byId.get(folded.defaultId) : null;
|
|
243
|
+
return w && !w.archived ? w : PRODUCT_FEATURE;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** The library as a list: Product feature first, then by name, archived last. counts: { [id]: n } initiatives on each. */
|
|
247
|
+
function list(folded, counts = {}) {
|
|
248
|
+
const def = defaultOf(folded).id;
|
|
249
|
+
const all = [...folded.byId.values()].map((w) => ({ ...w, count: counts[w.id] || 0, ...(w.id === def ? { default: true } : {}) }));
|
|
250
|
+
const order = [PRODUCT_FEATURE_ID, PROJECT_ID, FULL_SDLC_ID];
|
|
251
|
+
const rank = (w) => (isBuiltin(w.id) ? order.indexOf(w.id) : w.archived ? 4 : 3);
|
|
252
|
+
return all.sort((a, b) => rank(a) - rank(b) || a.name.localeCompare(b.name));
|
|
253
|
+
}
|
|
254
|
+
const resolve = (folded, id) => (id && folded && folded.byId.get(id)) || PRODUCT_FEATURE;
|
|
255
|
+
|
|
256
|
+
/** The stage a key or a name names (old lifecycle names read too: Ideate → Discover, Strategize → Prioritize). */
|
|
257
|
+
function stageByRef(wf, ref) {
|
|
258
|
+
if (ref == null || !wf) return null;
|
|
259
|
+
const r = String(ref).trim().replace(/^◆\s*/, '');
|
|
260
|
+
const low = r.toLowerCase();
|
|
261
|
+
const old = { ideate: 'discover', strategize: 'prioritize' }[low];
|
|
262
|
+
return wf.stages.find((s) => s.key === r || s.key === old) || wf.stages.find((s) => s.name.toLowerCase() === low) || null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Claude's proposal of where each stage of `from` lands in `to` (batch 20 item 3, canvas WmB). Order is kept, so no stage is guessed out of
|
|
266
|
+
* sequence. Anchors first: the same key or name, the same stem in the same category ("Discover" → "Discovery"), the stage whose output is Jira tickets, the first
|
|
267
|
+
* stage to the first and the last to the last. Between two anchors an old stage stays with the earlier one until a ◆ milestone closes it
|
|
268
|
+
* (Build, ◆ Deliver → Implementation; Monitor → Evaluation); a wider gap spreads in order. → { [fromKey]: toKey } for every stage of from. */
|
|
269
|
+
function proposeBridge(from, to) {
|
|
270
|
+
const F = (from && from.stages) || [], T = (to && to.stages) || [];
|
|
271
|
+
const out = {};
|
|
272
|
+
if (!T.length) return out;
|
|
273
|
+
const low = (x) => String(x || '').toLowerCase().trim();
|
|
274
|
+
const stem = (x) => { const v = low(x).replace(/[^a-z0-9]/g, ''); return v.length >= 6 ? v.slice(0, 6) : null; };
|
|
275
|
+
const anchor = F.map((s) => {
|
|
276
|
+
let j = T.findIndex((t) => t.key === s.key || low(t.name) === low(s.name));
|
|
277
|
+
if (j < 0 && stem(s.name)) j = T.findIndex((t) => t.cat === s.cat && stem(t.name) === stem(s.name));
|
|
278
|
+
return j;
|
|
279
|
+
});
|
|
280
|
+
const tj = T.findIndex((t) => t.output && t.output.kind === 'jira');
|
|
281
|
+
if (tj >= 0 && !anchor.includes(tj)) { const i = F.findIndex((s, n) => anchor[n] < 0 && s.output && s.output.kind === 'jira'); if (i >= 0) anchor[i] = tj; }
|
|
282
|
+
if (F.length && anchor[0] < 0) anchor[0] = 0;
|
|
283
|
+
if (F.length > 1 && anchor[F.length - 1] < 0) anchor[F.length - 1] = T.length - 1;
|
|
284
|
+
// keep the order: an anchor that would go back is dropped
|
|
285
|
+
let hi = -1;
|
|
286
|
+
for (let i = 0; i < F.length; i++) { if (anchor[i] < 0) continue; if (anchor[i] < hi) anchor[i] = -1; else hi = anchor[i]; }
|
|
287
|
+
for (let i = 0; i < F.length;) {
|
|
288
|
+
if (anchor[i] >= 0) { out[F[i].key] = T[anchor[i]].key; i++; continue; }
|
|
289
|
+
let j = i; while (j < F.length && anchor[j] < 0) j++;
|
|
290
|
+
const a = i > 0 ? anchor[i - 1] : 0, b = j < F.length ? anchor[j] : a, n = j - i;
|
|
291
|
+
let closed = false;
|
|
292
|
+
for (let k = 0; k < n; k++) {
|
|
293
|
+
let t = a;
|
|
294
|
+
if (b - a === 1) { t = closed ? b : a; if (F[i + k].milestone) closed = true; }
|
|
295
|
+
else if (b - a > 1) t = Math.min(b, a + Math.round(((k + 1) * (b - a)) / (n + 1)));
|
|
296
|
+
out[F[i + k].key] = T[t].key;
|
|
297
|
+
}
|
|
298
|
+
i = j;
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Every stage of `from` and where it lands in `to`: the PM's own pick (override), the bridge saved with `to`, else Claude's proposal. */
|
|
304
|
+
function mapOf(from, to, override) {
|
|
305
|
+
const p = proposeBridge(from, to);
|
|
306
|
+
const br = to && to.bridge && from && to.bridge.from === from.id ? to.bridge.map : (from && to && MEANING[from.id + '>' + to.id]) || {};
|
|
307
|
+
const ok = (k) => !!k && !!(to.stages || []).find((s) => s.key === k);
|
|
308
|
+
const out = {};
|
|
309
|
+
for (const s of (from && from.stages) || []) {
|
|
310
|
+
const o = override && override[s.key];
|
|
311
|
+
out[s.key] = ok(o) ? o : ok(br[s.key]) ? br[s.key] : p[s.key];
|
|
312
|
+
}
|
|
313
|
+
return out;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Switching workflow (WfAChange): the stage the bridge (or Claude's proposal) sends the current stage to; no current stage, the first stage. */
|
|
317
|
+
function switchTarget(from, to, stageRef) {
|
|
318
|
+
const cur = stageByRef(from, stageRef);
|
|
319
|
+
if (!cur) return to.stages[0].key;
|
|
320
|
+
return mapOf(from, to)[cur.key] || to.stages[0].key;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** standing: [{ id, stage }] (stage = key). The ones whose stage the edit removes (WfARemove). */
|
|
324
|
+
function removedInUse(before, after, standing) {
|
|
325
|
+
const keep = new Set(after.stages.map((s) => s.key));
|
|
326
|
+
return (standing || []).filter((x) => { const s = stageByRef(before, x.stage); return s && !keep.has(s.key); }).map((x) => ({ id: x.id, stage: stageByRef(before, x.stage).key }));
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** The initiative's own stages: what the stage track, the stage card, the Viewer and the program milestones read.
|
|
330
|
+
* judged: { [stageKey]: { runs: true|false|null, why, cite } } (the agent's readings of Only-when stages, the last one per stage)
|
|
331
|
+
* current: the stage key the initiative stands in. Each stage gets n (1-based), of, status ('done' | 'current' | 'next' | 'skipped'), and
|
|
332
|
+
* for an Only-when stage its reading (null when PMOS has not read it yet). A skip is a reading of runs:false; an Optional stage is skipped
|
|
333
|
+
* only when a reading says so. */
|
|
334
|
+
function stagesOf(wf, { judged = {}, current = null } = {}) {
|
|
335
|
+
const w = wf || PRODUCT_FEATURE;
|
|
336
|
+
const at = w.stages.findIndex((s) => s.key === current);
|
|
337
|
+
return w.stages.map((s, i) => {
|
|
338
|
+
const j = judged && judged[s.key] ? judged[s.key] : null;
|
|
339
|
+
const skipped = !!j && j.runs === false;
|
|
340
|
+
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,
|
|
342
|
+
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
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** A new editable copy of a workflow ("Copy of X", a free id). */
|
|
347
|
+
function copyOf(wf, name, taken) {
|
|
348
|
+
const n = oneLine(name, NAME_MAX) ? name.trim() : 'Copy of ' + wf.name;
|
|
349
|
+
let id = slug(n) || 'workflow', k = 2;
|
|
350
|
+
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 })) })) };
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** The workflow a kind of work starts on: Project and Full SDLC their own; Product management the workspace's default (defaultOf). */
|
|
355
|
+
function forKind(folded, kind) {
|
|
356
|
+
const id = KIND_WF[kind];
|
|
357
|
+
if (!id || id === PRODUCT_FEATURE_ID) return defaultOf(folded);
|
|
358
|
+
return BUILTIN[id];
|
|
359
|
+
}
|
|
360
|
+
/** Whether an initiative on workflow `wfId` runs its kind's default: the kind's built-in, or for Product management Product feature or the
|
|
361
|
+
* workspace default. A workflow the PM picked by hand is not a kind's default, so a kind change leaves it alone. */
|
|
362
|
+
function isKindDefault(folded, kind, wfId) {
|
|
363
|
+
if (kind === 'product') return wfId === PRODUCT_FEATURE_ID || wfId === defaultOf(folded).id;
|
|
364
|
+
return wfId === KIND_WF[kind];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** The ◆ stages of a workflow: what a program milestone may wait on (D99 point 7). Product feature: Deliver first. */
|
|
368
|
+
const milestonesOf = (wf) => (wf || PRODUCT_FEATURE).stages.filter((s) => s.milestone).map((s) => ({ key: s.key, name: s.name }));
|
|
369
|
+
|
|
370
|
+
module.exports = {
|
|
371
|
+
CATS, CAT_LABEL, ENDS, OUTPUT_KINDS, WHEN_MODES, DECIDE, ICONS, PRODUCT_FEATURE_ID, PRODUCT_FEATURE,
|
|
372
|
+
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,
|
|
374
|
+
};
|