create-pmos 0.407.0 → 0.409.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 +25 -25
- package/payload/KIT-VERSION +2 -2
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/board-programs-test.js +1 -1
- package/workspace/board-wf-shot.js +45 -0
- package/workspace/board-workflows-test.js +186 -0
- package/workspace/briefing-premium-board-test.js +2 -2
- package/workspace/briefing-premium-initiative-test.js +1 -1
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/board-workflows-facts.js +49 -0
- package/workspace/fixtures/workflows-facts.js +53 -0
- package/workspace/guide/home.md +2 -2
- package/workspace/guide/index.md +1 -0
- package/workspace/guide/workflows.md +58 -0
- package/workspace/home-other-product-test.js +94 -0
- package/workspace/ini-workflow-test.js +177 -0
- package/workspace/lib/board-premium.js +30 -5
- package/workspace/lib/board-trail.js +24 -7
- package/workspace/lib/briefing-premium-agent.js +3 -0
- package/workspace/lib/engine/boards.js +30 -2
- package/workspace/lib/engine/workflows.js +204 -0
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/programs.js +22 -7
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-boards.js +157 -7
- package/workspace/lib/routes-programs.js +5 -0
- package/workspace/lib/routes-workflows.js +105 -0
- package/workspace/lib/workflow-chat.js +26 -0
- package/workspace/lib/workflow-cli.js +141 -0
- package/workspace/lib/workflows-store.js +108 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/program-charter-test.js +243 -0
- package/workspace/program-panel-test.js +1 -1
- package/workspace/public/pm/bd-acts.js +10 -5
- package/workspace/public/pm/bd-asks.js +2 -2
- package/workspace/public/pm/bd-prog-panel.js +33 -14
- package/workspace/public/pm/bd-prog.js +11 -3
- package/workspace/public/pm/bd-views.js +128 -45
- package/workspace/public/pm/bd-wf.js +99 -0
- package/workspace/public/pm/cozy-board.css +67 -6
- package/workspace/public/pm/cozy-evmodel.js +1 -1
- package/workspace/public/pm/cozy-panel.css +12 -6
- package/workspace/public/pm/cozy-settings.js +4 -2
- package/workspace/public/pm/cozy-viewer.js +36 -9
- package/workspace/public/pm/cozy-vw-shell.css +8 -0
- package/workspace/public/pm/goal-chat.js +1 -1
- package/workspace/public/pm/home-app.js +50 -13
- package/workspace/public/pm/home-ini-model.js +2 -2
- package/workspace/public/pm/home-ini.css +30 -0
- package/workspace/public/pm/home-ini.js +52 -9
- package/workspace/public/pm/home-list.js +5 -3
- package/workspace/public/pm/home-today.js +4 -4
- package/workspace/public/pm/ini-wf-model.js +91 -0
- package/workspace/public/pm/ini-wf.js +160 -0
- package/workspace/public/pm/premium-board.js +98 -30
- package/workspace/public/pm/premium-initiative-head.js +18 -8
- package/workspace/public/pm/program-charter.css +135 -0
- package/workspace/public/pm/program-charter.js +333 -0
- package/workspace/public/pm/program-model.js +44 -4
- package/workspace/public/pm/wf-edit.js +119 -0
- package/workspace/public/pm/wf-model.js +48 -0
- package/workspace/public/pm/wf-page.css +162 -0
- package/workspace/public/pm/wf-page.js +398 -0
- package/workspace/public/pm/wf-stage.js +187 -0
- package/workspace/public/premium-workflows.html +31 -0
- package/workspace/public/premium.html +1 -0
- package/workspace/server.js +1 -1
- package/workspace/skills/workflow-setup.skill +57 -0
- package/workspace/test-lists/briefing-premium.json +3 -1
- package/workspace/test-lists/ini-workflow.json +6 -0
- package/workspace/test-lists/program-charter.json +9 -0
- package/workspace/test-lists/workflows-board.json +13 -0
- package/workspace/test-lists/workflows-setup.json +13 -0
- package/workspace/test-lists/workflows.json +5 -0
- package/workspace/workflows-setup-test.js +346 -0
|
@@ -0,0 +1,204 @@
|
|
|
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
|
+
* check(wf, { existing }) → { ok, workflow } | { ok:false, status, error } validate and normalise one workflow
|
|
7
|
+
* fold(lines) → { byId: Map, draft } the library (Product feature first)
|
|
8
|
+
* list(folded, counts?) → [workflow + { count }] Product feature first, archived last
|
|
9
|
+
* resolve(folded, id) → the workflow (Product feature when the id is unknown or missing)
|
|
10
|
+
* stageByRef(wf, ref) → the stage a key or a name names, or null
|
|
11
|
+
* switchTarget(from, to, stageKey) → the key an initiative lands on when it switches workflow
|
|
12
|
+
* removedInUse(before, after, standing)→ [{ id, stage }] initiatives that stand in a stage the edit removes
|
|
13
|
+
* stagesOf(wf, { judged, current }) → the initiative's own stages, each with its reading and status (the ONE function every surface reads)
|
|
14
|
+
* copyOf(wf, name, taken) → a new editable copy
|
|
15
|
+
*
|
|
16
|
+
* A WORKFLOW is { id, name, icon, builtin?, decide, archived?, stages: [STAGE] }.
|
|
17
|
+
* A STAGE is { key, name, cat, output: { name, kind, template? }, finish: [text], milestone, auto, when: { mode, text? }, then, unless: [{ text, to }] }.
|
|
18
|
+
* cat ∈ CATS (To do, In progress, Done). Won't do and Archived (ENDS) are in every workflow and are not stages.
|
|
19
|
+
* The first stage is always `triage`, in To do. `then` null means the next stage in the list. `unless` sends the initiative elsewhere
|
|
20
|
+
* when PMOS judges its plain words true. A key is the slug of the stage's first name and survives a rename.
|
|
21
|
+
*
|
|
22
|
+
* THE LEDGER (workflows.jsonl), one line per change, the last line for an id wins; nothing is deleted:
|
|
23
|
+
* wf-save { wf } create or edit (Product feature is never saved: it is built in)
|
|
24
|
+
* wf-archive { id, archived }
|
|
25
|
+
* wf-draft { draft | null, note? } the one open draft the chat wrote (null clears it)
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const { STAGES: LIFE, LABELS, OUTPUTS, MILESTONES } = require('./nine-stages');
|
|
29
|
+
|
|
30
|
+
const CATS = Object.freeze(['todo', 'doing', 'done']);
|
|
31
|
+
const CAT_LABEL = Object.freeze({ todo: 'To do', doing: 'In progress', done: 'Done', wontdo: "Won't do", archived: 'Archived' });
|
|
32
|
+
const ENDS = Object.freeze(['wontdo', 'archived']);
|
|
33
|
+
const OUTPUT_KINDS = Object.freeze(['doc', 'jira', 'signoff', 'checklist']);
|
|
34
|
+
const WHEN_MODES = Object.freeze(['always', 'optional', 'only']);
|
|
35
|
+
const DECIDE = Object.freeze(['pmos', 'confirm']);
|
|
36
|
+
const ICONS = Object.freeze(['feature', 'doc', 'cart', 'swap', 'people', 'shield', 'box', 'flag', 'build', 'chart']);
|
|
37
|
+
const PRODUCT_FEATURE_ID = 'product-feature';
|
|
38
|
+
const NAME_MAX = 60, TEXT_MAX = 300, FINISH_MAX = 20, STAGES_MAX = 30;
|
|
39
|
+
|
|
40
|
+
const slug = (s) => String(s || '').toLowerCase().normalize('NFKD').replace(/[^\x00-\x7f]/g, '').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 40).replace(/-+$/, '');
|
|
41
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
42
|
+
const oneLine = (v, max) => typeof v === 'string' && v.trim().length >= 1 && v.trim().length <= max && !/[\r\n\x00-\x08\x0b-\x1f]/.test(v);
|
|
43
|
+
|
|
44
|
+
// Product feature: the eight steps of scripts/nine-stages.js, each in its category, with the output that finishes it.
|
|
45
|
+
const PF_KIND = { triage: 'doc', discover: 'doc', plan: 'doc', prioritize: 'checklist', build: 'jira', deliver: 'signoff', monitor: 'doc', evaluate: 'signoff' };
|
|
46
|
+
const PRODUCT_FEATURE = Object.freeze({
|
|
47
|
+
id: PRODUCT_FEATURE_ID, name: 'Product feature', icon: 'feature', builtin: true, decide: 'pmos',
|
|
48
|
+
stages: Object.freeze(LIFE.map((k) => Object.freeze({
|
|
49
|
+
key: k, name: LABELS[k], cat: k === 'triage' ? 'todo' : k === 'evaluate' ? 'done' : 'doing',
|
|
50
|
+
output: Object.freeze({ name: OUTPUTS[k], kind: PF_KIND[k] }), finish: Object.freeze([]), milestone: MILESTONES.has(k), auto: false,
|
|
51
|
+
when: Object.freeze({ mode: 'always' }), then: null, unless: Object.freeze([]),
|
|
52
|
+
}))),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const bad = (error, status = 400) => ({ ok: false, status, error });
|
|
56
|
+
|
|
57
|
+
/** Validate and normalise one workflow. `existing` (the library's ids) only matters for a new id clashing with Product feature. */
|
|
58
|
+
function check(wf) {
|
|
59
|
+
if (!isObj(wf)) return bad('a workflow is an object { id?, name, icon?, decide?, stages }');
|
|
60
|
+
if (!oneLine(wf.name, NAME_MAX)) return bad(`a workflow needs a name of one line, at most ${NAME_MAX} characters`);
|
|
61
|
+
const name = wf.name.trim();
|
|
62
|
+
const id = typeof wf.id === 'string' && wf.id ? slug(wf.id) : slug(name);
|
|
63
|
+
if (!id) return bad('the name needs at least one letter or digit');
|
|
64
|
+
if (id === PRODUCT_FEATURE_ID) return bad('Product feature is built in and cannot be changed. Copy it to make your own.', 409);
|
|
65
|
+
const icon = ICONS.includes(wf.icon) ? wf.icon : 'flag';
|
|
66
|
+
const decide = wf.decide == null ? 'pmos' : wf.decide;
|
|
67
|
+
if (!DECIDE.includes(decide)) return bad(`decide is one of ${DECIDE.join(', ')}`);
|
|
68
|
+
if (!Array.isArray(wf.stages) || !wf.stages.length) return bad('a workflow needs at least one stage');
|
|
69
|
+
if (wf.stages.length > STAGES_MAX) return bad(`a workflow has at most ${STAGES_MAX} stages`);
|
|
70
|
+
const stages = [];
|
|
71
|
+
const keys = new Set();
|
|
72
|
+
for (let i = 0; i < wf.stages.length; i++) {
|
|
73
|
+
const s = wf.stages[i];
|
|
74
|
+
const at = `stage ${i + 1}`;
|
|
75
|
+
if (!isObj(s)) return bad(`${at} must be an object { name, cat, … }`);
|
|
76
|
+
if (!oneLine(s.name, NAME_MAX)) return bad(`${at} needs a name of one line, at most ${NAME_MAX} characters`);
|
|
77
|
+
const sname = s.name.trim();
|
|
78
|
+
let key = typeof s.key === 'string' && s.key ? slug(s.key) : slug(sname);
|
|
79
|
+
if (!key) return bad(`${at}: the name needs at least one letter or digit`);
|
|
80
|
+
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; }
|
|
81
|
+
if (!CATS.includes(s.cat)) return bad(`stage "${sname}": the category is one of To do (todo), In progress (doing), Done (done)`);
|
|
82
|
+
const o = isObj(s.output) ? s.output : {};
|
|
83
|
+
const kind = o.kind == null ? 'checklist' : o.kind;
|
|
84
|
+
if (!OUTPUT_KINDS.includes(kind)) return bad(`stage "${sname}": the output kind is one of ${OUTPUT_KINDS.join(', ')}`);
|
|
85
|
+
if (o.name != null && o.name !== '' && !oneLine(o.name, 120)) return bad(`stage "${sname}": the output is one line of at most 120 characters`);
|
|
86
|
+
if (o.template != null && o.template !== '' && !oneLine(o.template, 120)) return bad(`stage "${sname}": the template is one line of at most 120 characters`);
|
|
87
|
+
const finish = s.finish == null ? [] : s.finish;
|
|
88
|
+
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`);
|
|
89
|
+
const w = isObj(s.when) ? s.when : { mode: 'always' };
|
|
90
|
+
if (!WHEN_MODES.includes(w.mode)) return bad(`stage "${sname}": When it runs is one of ${WHEN_MODES.join(', ')}`);
|
|
91
|
+
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)`);
|
|
92
|
+
const unless = s.unless == null ? [] : s.unless;
|
|
93
|
+
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`);
|
|
94
|
+
keys.add(key);
|
|
95
|
+
stages.push({
|
|
96
|
+
key, name: sname, cat: s.cat,
|
|
97
|
+
output: { name: o.name ? o.name.trim() : '', kind, ...(o.template ? { template: o.template.trim() } : {}) },
|
|
98
|
+
finish: finish.map((x) => x.trim()), milestone: s.milestone === true, auto: s.auto === true,
|
|
99
|
+
when: w.mode === 'only' ? { mode: 'only', text: w.text.trim() } : { mode: w.mode },
|
|
100
|
+
then: typeof s.then === 'string' && s.then ? s.then : null,
|
|
101
|
+
unless: unless.map((u) => ({ text: u.text.trim(), to: u.to })),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// Triage is always first, in To do (WfAModel, wfRules).
|
|
105
|
+
if (stages[0].key !== 'triage' || stages[0].cat !== 'todo') return bad('Triage is always the first stage, in To do');
|
|
106
|
+
if (stages.slice(1).some((s) => s.key === 'triage')) return bad('only the first stage is Triage');
|
|
107
|
+
// Then and Unless name stages of this workflow (by key or by name).
|
|
108
|
+
const ref = (r) => (keys.has(r) ? r : (stages.find((s) => s.name.toLowerCase() === String(r).toLowerCase()) || {}).key || null);
|
|
109
|
+
for (const s of stages) {
|
|
110
|
+
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; }
|
|
111
|
+
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; }
|
|
112
|
+
}
|
|
113
|
+
return { ok: true, workflow: { id, name, icon, decide, stages } };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Fold workflows.jsonl (objects or JSON strings), oldest first. */
|
|
117
|
+
function fold(lines) {
|
|
118
|
+
const byId = new Map([[PRODUCT_FEATURE_ID, PRODUCT_FEATURE]]);
|
|
119
|
+
let draft = null;
|
|
120
|
+
for (const raw of lines || []) {
|
|
121
|
+
let e = raw;
|
|
122
|
+
if (typeof raw === 'string') { try { e = JSON.parse(raw); } catch { continue; } }
|
|
123
|
+
if (!isObj(e)) continue;
|
|
124
|
+
if (e.kind === 'wf-save' && isObj(e.wf)) {
|
|
125
|
+
const c = check(e.wf);
|
|
126
|
+
if (!c.ok) continue;
|
|
127
|
+
const was = byId.get(c.workflow.id);
|
|
128
|
+
byId.set(c.workflow.id, { ...c.workflow, ...(was && was.archived ? { archived: true } : {}), at: e.at || null });
|
|
129
|
+
} else if (e.kind === 'wf-archive' && typeof e.id === 'string' && byId.has(e.id) && e.id !== PRODUCT_FEATURE_ID) {
|
|
130
|
+
const w = { ...byId.get(e.id) };
|
|
131
|
+
if (e.archived) w.archived = true; else delete w.archived;
|
|
132
|
+
byId.set(e.id, w);
|
|
133
|
+
} else if (e.kind === 'wf-draft') {
|
|
134
|
+
draft = isObj(e.draft) ? { draft: e.draft, note: typeof e.note === 'string' ? e.note : '', at: e.at || null } : null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { byId, draft };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The library as a list: Product feature first, then by name, archived last. counts: { [id]: n } initiatives on each. */
|
|
141
|
+
function list(folded, counts = {}) {
|
|
142
|
+
const all = [...folded.byId.values()].map((w) => ({ ...w, count: counts[w.id] || 0 }));
|
|
143
|
+
const rank = (w) => (w.id === PRODUCT_FEATURE_ID ? 0 : w.archived ? 2 : 1);
|
|
144
|
+
return all.sort((a, b) => rank(a) - rank(b) || a.name.localeCompare(b.name));
|
|
145
|
+
}
|
|
146
|
+
const resolve = (folded, id) => (id && folded && folded.byId.get(id)) || PRODUCT_FEATURE;
|
|
147
|
+
|
|
148
|
+
/** The stage a key or a name names (old lifecycle names read too: Ideate → Discover, Strategize → Prioritize). */
|
|
149
|
+
function stageByRef(wf, ref) {
|
|
150
|
+
if (ref == null || !wf) return null;
|
|
151
|
+
const r = String(ref).trim().replace(/^◆\s*/, '');
|
|
152
|
+
const low = r.toLowerCase();
|
|
153
|
+
const old = { ideate: 'discover', strategize: 'prioritize' }[low];
|
|
154
|
+
return wf.stages.find((s) => s.key === r || s.key === old) || wf.stages.find((s) => s.name.toLowerCase() === low) || null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Switching workflow (WfAChange): a stage of the same name carries over, else the first stage of the same category, else the first stage. */
|
|
158
|
+
function switchTarget(from, to, stageRef) {
|
|
159
|
+
const cur = stageByRef(from, stageRef);
|
|
160
|
+
if (!cur) return to.stages[0].key;
|
|
161
|
+
const same = to.stages.find((s) => s.name.toLowerCase() === cur.name.toLowerCase());
|
|
162
|
+
if (same) return same.key;
|
|
163
|
+
const cat = to.stages.find((s) => s.cat === cur.cat);
|
|
164
|
+
return (cat || to.stages[0]).key;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** standing: [{ id, stage }] (stage = key). The ones whose stage the edit removes (WfARemove). */
|
|
168
|
+
function removedInUse(before, after, standing) {
|
|
169
|
+
const keep = new Set(after.stages.map((s) => s.key));
|
|
170
|
+
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 }));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The initiative's own stages: what the stage track, the stage card, the Viewer and the program milestones read.
|
|
174
|
+
* judged: { [stageKey]: { runs: true|false|null, why, cite } } (the agent's readings of Only-when stages, the last one per stage)
|
|
175
|
+
* current: the stage key the initiative stands in. Each stage gets n (1-based), of, status ('done' | 'current' | 'next' | 'skipped'), and
|
|
176
|
+
* 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
|
|
177
|
+
* only when a reading says so. */
|
|
178
|
+
function stagesOf(wf, { judged = {}, current = null } = {}) {
|
|
179
|
+
const w = wf || PRODUCT_FEATURE;
|
|
180
|
+
const at = w.stages.findIndex((s) => s.key === current);
|
|
181
|
+
return w.stages.map((s, i) => {
|
|
182
|
+
const j = judged && judged[s.key] ? judged[s.key] : null;
|
|
183
|
+
const skipped = !!j && j.runs === false;
|
|
184
|
+
const status = skipped ? 'skipped' : at < 0 ? (i === 0 ? 'current' : 'next') : i < at ? 'done' : i === at ? 'current' : 'next';
|
|
185
|
+
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,
|
|
186
|
+
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 };
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** A new editable copy of a workflow ("Copy of X", a free id). */
|
|
191
|
+
function copyOf(wf, name, taken) {
|
|
192
|
+
const n = oneLine(name, NAME_MAX) ? name.trim() : 'Copy of ' + wf.name;
|
|
193
|
+
let id = slug(n) || 'workflow', k = 2;
|
|
194
|
+
while ((taken && taken.has(id)) || id === PRODUCT_FEATURE_ID) id = slug(n) + '-' + k++;
|
|
195
|
+
return { id, name: n, icon: wf.icon, decide: wf.decide || 'pmos', stages: wf.stages.map((s) => ({ ...s, output: { ...s.output }, finish: [...s.finish], when: { ...s.when }, unless: s.unless.map((u) => ({ ...u })) })) };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The ◆ stages of a workflow: what a program milestone may wait on (D99 point 7). Product feature: Deliver first. */
|
|
199
|
+
const milestonesOf = (wf) => (wf || PRODUCT_FEATURE).stages.filter((s) => s.milestone).map((s) => ({ key: s.key, name: s.name }));
|
|
200
|
+
|
|
201
|
+
module.exports = {
|
|
202
|
+
CATS, CAT_LABEL, ENDS, OUTPUT_KINDS, WHEN_MODES, DECIDE, ICONS, PRODUCT_FEATURE_ID, PRODUCT_FEATURE,
|
|
203
|
+
slug, check, fold, list, resolve, stageByRef, switchTarget, removedInUse, stagesOf, copyOf, milestonesOf,
|
|
204
|
+
};
|
|
@@ -59,6 +59,9 @@ const VERBS = Object.freeze({
|
|
|
59
59
|
// Not a pm-os-absorb verb (run: null): the popup context work (premium-chat-session slice 7) added it through the same table.
|
|
60
60
|
lead: Object.freeze({ module: 'lead-cli.js', run: null, guide: 'briefing-premium.md',
|
|
61
61
|
help: 'pmos lead put|show|due — Claude\'s short lead for a popup, written ahead from stored reads (pmos lead help)' }),
|
|
62
|
+
// Not a pm-os-absorb verb (run: null): workflows-per-initiative (D99) added it through the same table.
|
|
63
|
+
workflow: Object.freeze({ module: 'workflow-cli.js', run: null, guide: 'workflows.md',
|
|
64
|
+
help: 'pmos workflow list|show|draft|show-draft|judge … — the workflows of this repository, the New workflow draft, and a reading of an Only-when stage (pmos workflow help)' }),
|
|
62
65
|
// Not a pm-os-absorb verb (run: null): c3-meet-extension added it through the same table.
|
|
63
66
|
extension: Object.freeze({ module: 'extension-cli.js', run: null, guide: 'console-calendar.md',
|
|
64
67
|
help: 'pmos extension — the folder of the Chrome extension for Google Meet, and the three steps to load it' }),
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* fold(lines) → { [id]: program } PURE. The program records of ONE workspace's ledger
|
|
5
5
|
* merge(perWs) → [program] PURE. perWs: [{ ws, lines }]; the same program id in two workspaces is one program
|
|
6
6
|
* program: { id, title, owner, goal, why, start, target, jira, from, milestones, members, tasks, home }
|
|
7
|
-
* validProgram(b) · validMilestone(m)
|
|
7
|
+
* validProgram(b) · validMilestone(m, taken) what a write accepts, or { error }; a milestone with no id gets one from its name
|
|
8
8
|
*
|
|
9
9
|
* WHERE A PROGRAM LIVES. A program spans products, and a product is a workspace with its own state folder. So there is no one folder a
|
|
10
10
|
* program "belongs" to: each workspace's <state>/programs.jsonl holds the program lines written FROM that workspace — the charter where the
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* `jira` is an optional key that is only read, never written to Jira.
|
|
14
14
|
*
|
|
15
15
|
* A LINE is one of:
|
|
16
|
-
* { kind: 'program', id, title, owner?, goal?, start?, target?, jira?, from?, milestones?: [{ id, name, date?, waits: [initiative id], done? }] } the last wins
|
|
16
|
+
* { kind: 'program', id, title, owner?, goal?, start?, target?, jira?, from?, milestones?: [{ id, name, date?, waits: [initiative id], stages?: { [initiative]: ◆ stage key }, done? }] } the last wins
|
|
17
17
|
* `from`: the initiative a turned program came from ("Turn into a program"), in the charter's workspace
|
|
18
18
|
* { kind: 'check', program, milestone, done: true|false } the PM marks a program check done (canvas PgMilestones); the last line wins
|
|
19
19
|
* { kind: 'member', program, initiative } the initiative (of the workspace whose ledger holds the line) joins the program
|
|
@@ -34,14 +34,26 @@ const str = (v, n) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, '
|
|
|
34
34
|
|
|
35
35
|
/** A program id from a title: "Project Ascent" → "project-ascent". */
|
|
36
36
|
const slug = (t) => String(t || '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60);
|
|
37
|
+
/** A milestone id from its name that no other milestone of the charter has: "Pilot live" → "pilot-live", then "pilot-live-2". */
|
|
38
|
+
function idOf(name, taken) {
|
|
39
|
+
const t = taken || new Set(), base = slug(name).slice(0, 50) || 'milestone';
|
|
40
|
+
let id = base;
|
|
41
|
+
for (let n = 2; t.has(id); n++) id = base + '-' + n;
|
|
42
|
+
return id;
|
|
43
|
+
}
|
|
37
44
|
|
|
38
|
-
function validMilestone(m,
|
|
45
|
+
function validMilestone(m, taken) {
|
|
39
46
|
if (!m || typeof m !== 'object') return { error: 'a milestone is { name, date?, waits }' };
|
|
40
47
|
const name = str(m.name, 80);
|
|
41
48
|
if (!name) return { error: 'name the milestone' };
|
|
42
49
|
if (m.date && !DAY_RE.test(String(m.date))) return { error: 'a milestone date is YYYY-MM-DD' };
|
|
43
50
|
const waits = (Array.isArray(m.waits) ? m.waits : []).map(String).filter((x) => INI_RE.test(x)).slice(0, 20);
|
|
44
|
-
|
|
51
|
+
// an id is the milestone's for good: the page makes one when it adds a row (the program check marks key on it). A line with none gets one from
|
|
52
|
+
// its name, never from its place in the list: a place moves when a milestone before it is deleted, and the marks would move with it
|
|
53
|
+
const out = { id: ID_RE.test(String(m.id || '')) ? String(m.id) : idOf(name, taken), name, date: m.date || '', waits };
|
|
54
|
+
// D99: which ◆ stage of its own workflow each initiative must pass (the charter picker lists that initiative's ◆ stages); none = the first ◆
|
|
55
|
+
const st = m.stages && typeof m.stages === 'object' && !Array.isArray(m.stages) ? Object.entries(m.stages).filter(([k, v]) => waits.includes(k) && typeof v === 'string' && /^[a-z0-9][a-z0-9-]{0,39}$/.test(v)) : [];
|
|
56
|
+
if (st.length) out.stages = Object.fromEntries(st);
|
|
45
57
|
if (!waits.length) out.done = m.done === true; // a program check: the PM marks it done; a milestone with initiatives is done when they are
|
|
46
58
|
return out;
|
|
47
59
|
}
|
|
@@ -54,9 +66,12 @@ function validProgram(b) {
|
|
|
54
66
|
if (b.target && !DAY_RE.test(String(b.target))) return { error: 'the target date is YYYY-MM-DD' };
|
|
55
67
|
if (b.start && !DAY_RE.test(String(b.start))) return { error: 'the start date is YYYY-MM-DD' };
|
|
56
68
|
if (b.start && b.target && String(b.start) > String(b.target)) return { error: 'the start date is after the target date' };
|
|
57
|
-
const milestones = [];
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
const milestones = [], list = (Array.isArray(b.milestones) ? b.milestones : []).slice(0, 12);
|
|
70
|
+
// the ids the lines name come first, so a made one never takes an id a later line names
|
|
71
|
+
const taken = new Set(list.map((m) => String((m && m.id) || '')).filter((x) => ID_RE.test(x)));
|
|
72
|
+
for (const m of list) {
|
|
73
|
+
const v = validMilestone(m, taken);
|
|
74
|
+
taken.add(v.id);
|
|
60
75
|
if (v.error) return v;
|
|
61
76
|
if (milestones.some((x) => x.id === v.id)) return { error: 'two milestones have the id ' + v.id };
|
|
62
77
|
milestones.push(v);
|
|
@@ -72,6 +72,7 @@ const MODULES = Object.freeze([
|
|
|
72
72
|
'routes-c3-reports', // console3 Reports dashboards: library, per-scope data, page-press layouts (layouts are the only write)
|
|
73
73
|
'routes-onboarding', // onboarding-scan-and-map slice 2: first run (scan read-only, structure, import into the overlay, undo, first Briefing)
|
|
74
74
|
'routes-boards', // c3-initiative-boards: Portfolio, Board, Backlog, Triage asks, workflows and moves (boards.jsonl)
|
|
75
|
+
'routes-workflows', // workflows-per-initiative (D99): the workflow library, save, copy, archive and the chat's draft (workflows.jsonl; page-press POST)
|
|
75
76
|
'routes-settings', // console3 Settings: the settings store for settings with no home of their own (GET; page-press POST)
|
|
76
77
|
'routes-hooks', // planning-flows run 7: CLI hook endpoints (session token, per-run JSONL)
|
|
77
78
|
'routes-sources', // workspace-data-freshness: how old each source is, Refresh now, the change detector switch
|
|
@@ -76,6 +76,8 @@ const routesInit = require('./routes-initiatives.js');
|
|
|
76
76
|
const jiraTickets = require('./jira-tickets.js');
|
|
77
77
|
const { repoScript } = require('./repo-script.js');
|
|
78
78
|
const B = require(repoScript('boards.js'));
|
|
79
|
+
const WF = require(repoScript('workflows.js'));
|
|
80
|
+
const WS = require('./workflows-store.js');
|
|
79
81
|
const intake = require(repoScript('intake.js'));
|
|
80
82
|
|
|
81
83
|
const LEDGER = 'boards.jsonl';
|
|
@@ -280,7 +282,38 @@ function epicsOf(base, folded) {
|
|
|
280
282
|
}
|
|
281
283
|
|
|
282
284
|
/** The PRD row of one base row on one board. */
|
|
283
|
-
|
|
285
|
+
/** D99: the workflow an initiative runs and where it stands in it. Product feature unless an ini-wf line set another (the PMOS-self
|
|
286
|
+
* board always runs Product feature, derived). Answers { wf, stage (key), stages (WF.stagesOf), ended }. The ONE place every surface
|
|
287
|
+
* (Board, track, stage card, Viewer, program milestones) gets an initiative's stages from. */
|
|
288
|
+
function workflowRowOf(board, base, folded, lib, legacyStage) {
|
|
289
|
+
const k = B.key(board.id, base.id);
|
|
290
|
+
const own = !(board && board.self) && folded && folded.iniWf ? folded.iniWf.get(k) : null;
|
|
291
|
+
const wf = WF.resolve(lib, own ? own.wf : null);
|
|
292
|
+
let cur = null;
|
|
293
|
+
if (own) {
|
|
294
|
+
const moved = folded.stages.get(k);
|
|
295
|
+
cur = (WF.stageByRef(wf, moved) || wf.stages[0]).key;
|
|
296
|
+
} else {
|
|
297
|
+
const byName = WF.stageByRef(wf, legacyStage);
|
|
298
|
+
cur = byName ? byName.key : (WF.stageByRef(wf, base.reading) || wf.stages[0]).key;
|
|
299
|
+
}
|
|
300
|
+
const judged = (folded && folded.judged && folded.judged.get(k)) || {};
|
|
301
|
+
const auto = (folded && folded.autoOver && folded.autoOver.get(k)) || {};
|
|
302
|
+
const stages = WF.stagesOf(wf, { judged, current: cur }).map((x) => (x.key in auto ? { ...x, auto: auto[x.key], autoOwn: true } : x));
|
|
303
|
+
const end = folded && folded.ends ? folded.ends.get(k) || null : null;
|
|
304
|
+
return { wf, own, stage: cur, stages, ended: end };
|
|
305
|
+
}
|
|
306
|
+
const wfRowFields = (x) => {
|
|
307
|
+
const st = x.stages.find((s) => s.key === x.stage) || x.stages[0];
|
|
308
|
+
return {
|
|
309
|
+
wf: { id: x.wf.id, name: x.wf.name, icon: x.wf.icon, ...(x.own && x.own.pmos ? { setBy: 'pmos', why: x.own.why, from: x.own.from || null } : {}) },
|
|
310
|
+
wfStage: { key: st.key, name: st.name, cat: st.cat, milestone: !!st.milestone, n: st.n, of: st.of },
|
|
311
|
+
wfStages: x.stages.map((s) => ({ key: s.key, name: s.name, cat: s.cat, milestone: !!s.milestone, auto: !!s.auto, when: s.when, status: s.status, reading: s.reading })),
|
|
312
|
+
ended: x.ended ? { as: x.ended.as, reason: x.ended.reason, note: x.ended.note, at: x.ended.at } : null,
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
function boardRow(board, base, folded, lib) {
|
|
284
317
|
const s = B.stageOf(board, base.id, base.reading, folded);
|
|
285
318
|
const wf = B.workflowOf(board, base.id, folded);
|
|
286
319
|
const cat = B.catOf({ workflow: wf }, s.stage);
|
|
@@ -292,6 +325,9 @@ function boardRow(board, base, folded) {
|
|
|
292
325
|
template: B.templateOf(board, base.id, folded), workflow: wf.map((x) => ({ name: x.name, cat: x.cat })),
|
|
293
326
|
...epicsOf(base, folded),
|
|
294
327
|
};
|
|
328
|
+
const wx = workflowRowOf(board, base, folded, lib || libOf(folded), s.stage);
|
|
329
|
+
Object.assign(row, wfRowFields(wx));
|
|
330
|
+
if (wx.own) { row.stage = (wx.stages.find((x) => x.key === wx.stage) || {}).name || row.stage; row.cat = null; row.stageSource = 'move'; }
|
|
295
331
|
const w = [];
|
|
296
332
|
if (s.source === 'move') {
|
|
297
333
|
const last = [...folded.moves].reverse().find((m) => m.board === board.id && m.id === base.id);
|
|
@@ -306,8 +342,13 @@ function boardRow(board, base, folded) {
|
|
|
306
342
|
function frameFor(ctx, w) {
|
|
307
343
|
const folded = B.fold(readLedger(ctx, w));
|
|
308
344
|
const boards = boardsOf(ctx, w, folded);
|
|
345
|
+
const d = ctx.stateDirFor ? ctx.stateDirFor(w) : null;
|
|
346
|
+
folded.wfLib = WS.library(d); // D99: the workflow library rides on the fold, so every boardRow call reads one copy
|
|
309
347
|
return { w, folded, boards };
|
|
310
348
|
}
|
|
349
|
+
/** A fresh fold with the workflow library on it (frameFor's, without the boards). */
|
|
350
|
+
function foldOf(ctx, w) { const f = B.fold(readLedger(ctx, w)); const d = ctx.stateDirFor ? ctx.stateDirFor(w) : null; f.wfLib = WS.library(d); return f; }
|
|
351
|
+
const libOf = (folded) => (folded && folded.wfLib) || WS.library(null);
|
|
311
352
|
function rowsOfBoard(fr, board, base) {
|
|
312
353
|
const rows = base.filter((r) => boardIdOf(r, fr.boards, fr.folded, fr.w) === board.id).map((r) => boardRow(board, r, fr.folded));
|
|
313
354
|
// c3-initiative-lifecycle: what was merged into each row, and the likely duplicates among the active rows of this board.
|
|
@@ -499,8 +540,10 @@ const READS = {
|
|
|
499
540
|
if (q) rows = rows.filter((x) => String(x.title).toLowerCase().includes(q) || x.id.includes(q));
|
|
500
541
|
if (owner) rows = rows.filter((x) => (owner === 'none' ? !x.owner : String(x.owner || '').toLowerCase() === owner.toLowerCase()));
|
|
501
542
|
rows = B.filterRows(rows, { view: 'all', sort: 'rank', limit: rows.length || 1, all: true }).rows;
|
|
543
|
+
// a row on a library workflow stands in that workflow's own stage, so a same-named stage ("Plan") does not count here (D99)
|
|
544
|
+
const onBoard = rows.filter((x) => !x.wf || x.wf.id === WF.PRODUCT_FEATURE_ID);
|
|
502
545
|
const columns = r.board.workflow.map((s) => {
|
|
503
|
-
const inCol =
|
|
546
|
+
const inCol = onBoard.filter((x) => x.stage === s.name);
|
|
504
547
|
return { stage: s.name, cat: s.cat, hint: s.hint || '', count: inCol.length, rows: inCol.slice(0, cap) };
|
|
505
548
|
});
|
|
506
549
|
ctx.json(res, { ok: true, ws: r.w.id, board: r.board.id, columns });
|
|
@@ -623,6 +666,27 @@ function settingsOf(body, board) {
|
|
|
623
666
|
return { value: v };
|
|
624
667
|
}
|
|
625
668
|
|
|
669
|
+
const WONTDO_REASONS = ['budget', 'scope', 'another', 'other']; // No budget · Out of scope · Done another way · Other (WfAWontDo)
|
|
670
|
+
/** A move of an initiative that runs a library workflow (D99): `to` is a stage key or name of ITS workflow; the key is stored. */
|
|
671
|
+
function moveOnWorkflow(ctx, res, body, g, p, own) {
|
|
672
|
+
if (body.why != null && (typeof body.why !== 'string' || body.why.length > 500)) return fail(ctx, res, 400, 'why is text of at most 500 characters');
|
|
673
|
+
if (!p.file) return fail(ctx, res, 409, NO_STATE);
|
|
674
|
+
const wf = WF.resolve(libOf(p.fr.folded), own.wf);
|
|
675
|
+
const t = WF.stageByRef(wf, body.to);
|
|
676
|
+
if (!t) return fail(ctx, res, 400, `"${body.to}" is not a stage of ${wf.name} (${wf.stages.map((s) => s.name).join(', ')})`);
|
|
677
|
+
const base = needRows(ctx, res, p.w);
|
|
678
|
+
if (!base) return;
|
|
679
|
+
const b0 = base.find((r) => r.id === body.id);
|
|
680
|
+
if (!b0 || boardIdOf(b0, p.fr.boards, p.fr.folded, p.w) !== p.board.id) return fail(ctx, res, 404, `no initiative ${body.id} on this board`);
|
|
681
|
+
const before = boardRow(p.board, b0, p.fr.folded);
|
|
682
|
+
const a = wf.stages.findIndex((s) => s.key === before.wfStage.key), b = wf.stages.findIndex((s) => s.key === t.key);
|
|
683
|
+
const warnings = [];
|
|
684
|
+
for (let i = a + 1; i < b; i++) { const sk = before.wfStages[i]; if (sk && sk.status !== 'skipped' && sk.when.mode !== 'optional') warnings.push('Skipped ' + sk.name); }
|
|
685
|
+
if (!before.anchor) warnings.push('No anchor');
|
|
686
|
+
append(p.file, g.actor, { kind: 'move', board: p.board.id, id: body.id, from: before.wfStage.key, to: t.key, why: body.why || '', warnings });
|
|
687
|
+
ctx.json(res, { ok: true, row: boardRow(p.board, b0, foldOf(ctx, p.w)), warnings });
|
|
688
|
+
}
|
|
689
|
+
|
|
626
690
|
const WRITES = {
|
|
627
691
|
'/api/boards/create': (ctx, res, body, g) => {
|
|
628
692
|
const p = postFrame(ctx, res, body, { needBoard: false });
|
|
@@ -669,6 +733,9 @@ const WRITES = {
|
|
|
669
733
|
const p = postFrame(ctx, res, body);
|
|
670
734
|
if (!p) return;
|
|
671
735
|
if (p.board.self) return fail(ctx, res, 409, SELF_REFUSAL);
|
|
736
|
+
// D99: an initiative on a workflow of the library moves between that workflow's stages (by key or name; the key is stored)
|
|
737
|
+
const own = typeof body.id === 'string' && p.fr.folded.iniWf ? p.fr.folded.iniWf.get(B.key(p.board.id, body.id)) : null;
|
|
738
|
+
if (own) return moveOnWorkflow(ctx, res, body, g, p, own);
|
|
672
739
|
const wfOwn = typeof body.id === 'string' ? B.workflowOf(p.board, body.id, p.fr.folded) : p.board.workflow;
|
|
673
740
|
if (typeof body.to !== 'string' || !wfOwn.some((s) => s.name === body.to)) {
|
|
674
741
|
return fail(ctx, res, 400, `"${body.to}" is not a stage of this ${wfOwn === p.board.workflow ? 'board' : 'initiative'}'s workflow (${wfOwn.map((s) => s.name).join(', ')})`);
|
|
@@ -683,7 +750,7 @@ const WRITES = {
|
|
|
683
750
|
const before = boardRow(p.board, b0, p.fr.folded);
|
|
684
751
|
const warnings = B.moveWarnings(p.board, before, before.stage, body.to, { hasSpec: b0.hasSpec });
|
|
685
752
|
append(p.file, g.actor, { kind: 'move', board: p.board.id, id: body.id, from: before.stage, to: body.to, why: body.why || '', warnings });
|
|
686
|
-
const row = boardRow(p.board, b0,
|
|
753
|
+
const row = boardRow(p.board, b0, foldOf(ctx, p.w));
|
|
687
754
|
ctx.json(res, { ok: true, row, warnings });
|
|
688
755
|
},
|
|
689
756
|
'/api/boards/assign': (ctx, res, body, g) => {
|
|
@@ -770,9 +837,92 @@ const WRITES = {
|
|
|
770
837
|
const ed = B.applyIniWorkflow(p.board, B.workflowOf(p.board, body.id, p.fr.folded), before.stage, body.template || null, stagesIn, body.moveTo);
|
|
771
838
|
if (!ed.ok) return fail(ctx, res, ed.status, ed.error);
|
|
772
839
|
append(p.file, g.actor, { kind: 'ini-workflow', board: p.board.id, id: body.id, template: ed.template, stages: ed.workflow, renamed: ed.renamed, moved: ed.moved });
|
|
773
|
-
const row = boardRow(p.board, b0,
|
|
840
|
+
const row = boardRow(p.board, b0, foldOf(ctx, p.w));
|
|
774
841
|
ctx.json(res, { ok: true, row, moved: ed.moved });
|
|
775
842
|
},
|
|
843
|
+
// ── D99 workflows per initiative ──────────────────────────────────────────────────────────────
|
|
844
|
+
'/api/boards/ini-wf': (ctx, res, body, g) => {
|
|
845
|
+
const p = postFrame(ctx, res, body);
|
|
846
|
+
if (!p) return;
|
|
847
|
+
if (p.board.self) return fail(ctx, res, 409, SELF_REFUSAL);
|
|
848
|
+
if (typeof body.id !== 'string' || !body.id) return fail(ctx, res, 400, 'id is required');
|
|
849
|
+
if (typeof body.wf !== 'string' || !body.wf) return fail(ctx, res, 400, 'wf (the workflow id) is required');
|
|
850
|
+
if (body.why != null && body.why !== '' && !ONE_LINE(body.why, 500)) return fail(ctx, res, 400, 'why is one line of at most 500 characters');
|
|
851
|
+
if (!p.file) return fail(ctx, res, 409, NO_STATE);
|
|
852
|
+
const lib = libOf(p.fr.folded);
|
|
853
|
+
const to = lib.byId.get(body.wf);
|
|
854
|
+
if (!to) return fail(ctx, res, 404, `no workflow ${body.wf}`);
|
|
855
|
+
if (to.archived) return fail(ctx, res, 409, `${to.name} is archived. Bring it back first.`);
|
|
856
|
+
const base = needRows(ctx, res, p.w);
|
|
857
|
+
if (!base) return;
|
|
858
|
+
const b0 = base.find((r) => r.id === body.id);
|
|
859
|
+
if (!b0 || boardIdOf(b0, p.fr.boards, p.fr.folded, p.w) !== p.board.id) return fail(ctx, res, 404, `no initiative ${body.id} on this board`);
|
|
860
|
+
const before = boardRow(p.board, b0, p.fr.folded);
|
|
861
|
+
const from = WF.resolve(lib, before.wf.id);
|
|
862
|
+
let target = WF.switchTarget(from, to, before.wfStage.key);
|
|
863
|
+
if (body.to != null) { const t = WF.stageByRef(to, body.to); if (!t) return fail(ctx, res, 400, `"${body.to}" is not a stage of ${to.name}`); target = t.key; }
|
|
864
|
+
const moved = { from: before.wfStage.key, to: target };
|
|
865
|
+
append(p.file, g.actor, { kind: 'ini-wf', board: p.board.id, id: body.id, wf: to.id, from: from.id, moved, why: body.why ? body.why.trim() : '', ...(body.pmos === true ? { pmos: true } : {}) });
|
|
866
|
+
const row = boardRow(p.board, b0, foldOf(ctx, p.w));
|
|
867
|
+
ctx.json(res, { ok: true, row, moved });
|
|
868
|
+
},
|
|
869
|
+
'/api/boards/wontdo': (ctx, res, body, g) => {
|
|
870
|
+
const p = postFrame(ctx, res, body);
|
|
871
|
+
if (!p) return;
|
|
872
|
+
if (typeof body.id !== 'string' || !body.id) return fail(ctx, res, 400, 'id is required');
|
|
873
|
+
if (!p.file) return fail(ctx, res, 409, NO_STATE);
|
|
874
|
+
const base = needRows(ctx, res, p.w);
|
|
875
|
+
if (!base) return;
|
|
876
|
+
const b0 = base.find((r) => r.id === body.id);
|
|
877
|
+
if (!b0 || boardIdOf(b0, p.fr.boards, p.fr.folded, p.w) !== p.board.id) return fail(ctx, res, 404, `no initiative ${body.id} on this board`);
|
|
878
|
+
const k = B.key(p.board.id, body.id);
|
|
879
|
+
const was = p.fr.folded.ends.get(k) || null;
|
|
880
|
+
if (body.back === true) {
|
|
881
|
+
if (!was) return fail(ctx, res, 409, `${body.id} is not in Won't do`);
|
|
882
|
+
append(p.file, g.actor, { kind: 'ini-end', board: p.board.id, id: body.id, back: true });
|
|
883
|
+
} else {
|
|
884
|
+
if (was) return fail(ctx, res, 409, `${body.id} is in Won't do already`);
|
|
885
|
+
if (!WONTDO_REASONS.includes(body.reason)) return fail(ctx, res, 400, `reason is one of ${WONTDO_REASONS.join(', ')}`);
|
|
886
|
+
if (body.note != null && body.note !== '' && !ONE_LINE(body.note, 300)) return fail(ctx, res, 400, 'note is one line of at most 300 characters');
|
|
887
|
+
if (body.reason === 'other' && !ONE_LINE(body.note, 300)) return fail(ctx, res, 400, 'Other needs a note saying why');
|
|
888
|
+
const before = boardRow(p.board, b0, p.fr.folded);
|
|
889
|
+
append(p.file, g.actor, { kind: 'ini-end', board: p.board.id, id: body.id, reason: body.reason, note: body.note ? body.note.trim() : '', stage: before.wfStage.key });
|
|
890
|
+
// the declined-work warning (D99 point 6): a Won't do is a declined line, as a declined ask is
|
|
891
|
+
if (ctx.runtimeDir) { try { const f = path.join(ctx.runtimeDir, 'corrections.jsonl'); fs.mkdirSync(path.dirname(f), { recursive: true }); fs.appendFileSync(f, JSON.stringify({ at: new Date().toISOString(), reason: 'wontdo', initiative: body.id, title: b0.title, why: body.reason + (body.note ? ': ' + body.note.trim() : '') }) + '\n'); } catch { /* the line in boards.jsonl is the record */ } }
|
|
892
|
+
}
|
|
893
|
+
const row = boardRow(p.board, b0, foldOf(ctx, p.w));
|
|
894
|
+
ctx.json(res, { ok: true, row });
|
|
895
|
+
},
|
|
896
|
+
'/api/boards/stage-judge': (ctx, res, body, g) => {
|
|
897
|
+
const p = postFrame(ctx, res, body);
|
|
898
|
+
if (!p) return;
|
|
899
|
+
if (typeof body.id !== 'string' || !body.id) return fail(ctx, res, 400, 'id is required');
|
|
900
|
+
const base = needRows(ctx, res, p.w);
|
|
901
|
+
if (!base) return;
|
|
902
|
+
const b0 = base.find((r) => r.id === body.id);
|
|
903
|
+
if (!b0 || boardIdOf(b0, p.fr.boards, p.fr.folded, p.w) !== p.board.id) return fail(ctx, res, 404, `no initiative ${body.id} on this board`);
|
|
904
|
+
const before = boardRow(p.board, b0, p.fr.folded);
|
|
905
|
+
if (!before.wfStages.some((x) => x.key === body.stage)) return fail(ctx, res, 400, `"${body.stage}" is not a stage of ${before.wf.name}`);
|
|
906
|
+
const r = WS.judge(ctx.stateDirFor ? ctx.stateDirFor(p.w) : null, { board: p.board.id, id: body.id, stage: body.stage, runs: body.runs, why: body.why, cite: body.cite, undo: body.undo }, g.actor);
|
|
907
|
+
if (!r.ok) return fail(ctx, res, r.status, r.error);
|
|
908
|
+
ctx.json(res, { ok: true, row: boardRow(p.board, b0, foldOf(ctx, p.w)) });
|
|
909
|
+
},
|
|
910
|
+
'/api/boards/ini-auto': (ctx, res, body, g) => {
|
|
911
|
+
const p = postFrame(ctx, res, body);
|
|
912
|
+
if (!p) return;
|
|
913
|
+
if (typeof body.id !== 'string' || !body.id) return fail(ctx, res, 400, 'id is required');
|
|
914
|
+
if (typeof body.auto !== 'boolean') return fail(ctx, res, 400, 'auto is true or false');
|
|
915
|
+
if (!p.file) return fail(ctx, res, 409, NO_STATE);
|
|
916
|
+
const base = needRows(ctx, res, p.w);
|
|
917
|
+
if (!base) return;
|
|
918
|
+
const b0 = base.find((r) => r.id === body.id);
|
|
919
|
+
if (!b0 || boardIdOf(b0, p.fr.boards, p.fr.folded, p.w) !== p.board.id) return fail(ctx, res, 404, `no initiative ${body.id} on this board`);
|
|
920
|
+
const before = boardRow(p.board, b0, p.fr.folded);
|
|
921
|
+
const stage = typeof body.stage === 'string' && body.stage ? body.stage : before.wfStage.key;
|
|
922
|
+
if (!before.wfStages.some((x) => x.key === stage)) return fail(ctx, res, 400, `"${stage}" is not a stage of ${before.wf.name}`);
|
|
923
|
+
append(p.file, g.actor, { kind: 'ini-auto', board: p.board.id, id: body.id, stage, auto: body.auto });
|
|
924
|
+
ctx.json(res, { ok: true, row: boardRow(p.board, b0, foldOf(ctx, p.w)) });
|
|
925
|
+
},
|
|
776
926
|
'/api/boards/ini-epics': (ctx, res, body, g) => {
|
|
777
927
|
const p = postFrame(ctx, res, body);
|
|
778
928
|
if (!p) return;
|
|
@@ -790,7 +940,7 @@ const WRITES = {
|
|
|
790
940
|
const b0 = base.find((r) => r.id === body.id);
|
|
791
941
|
if (!b0 || boardIdOf(b0, p.fr.boards, p.fr.folded, p.w) !== p.board.id) return fail(ctx, res, 404, `no initiative ${body.id} on this board`);
|
|
792
942
|
append(p.file, g.actor, { kind: 'ini-epics', board: p.board.id, id: body.id, epics });
|
|
793
|
-
const row = boardRow(p.board, b0,
|
|
943
|
+
const row = boardRow(p.board, b0, foldOf(ctx, p.w));
|
|
794
944
|
ctx.json(res, { ok: true, row });
|
|
795
945
|
},
|
|
796
946
|
'/api/boards/tasks/add': (ctx, res, body, g) => {
|
|
@@ -884,7 +1034,7 @@ const WRITES = {
|
|
|
884
1034
|
append(p.file, g.actor, body.archived
|
|
885
1035
|
? { kind: 'ini-archive', board: p.board.id, id: body.id, archived: true, reason: body.reason ? body.reason.trim() : '' }
|
|
886
1036
|
: { kind: 'ini-archive', board: p.board.id, id: body.id, archived: false });
|
|
887
|
-
const row = boardRow(p.board, b0,
|
|
1037
|
+
const row = boardRow(p.board, b0, foldOf(ctx, p.w));
|
|
888
1038
|
ctx.json(res, { ok: true, row });
|
|
889
1039
|
},
|
|
890
1040
|
'/api/boards/merge': (ctx, res, body, g) => {
|
|
@@ -1043,4 +1193,4 @@ function meetingBoards(ctx) {
|
|
|
1043
1193
|
return { list, detail };
|
|
1044
1194
|
}
|
|
1045
1195
|
|
|
1046
|
-
module.exports = { prefixes: ['/api/boards'], handle, move, boardIndex, appendScanAsk, scanDeclineSignal, createAndPlace, ledgerFile, append, frameFor, boardIdOf, meetingBoards, boardsOf, baseRows, boardRow, portfolio, SELF_REFUSAL, NO_STATE };
|
|
1196
|
+
module.exports = { prefixes: ['/api/boards'], handle, move, boardIndex, appendScanAsk, scanDeclineSignal, createAndPlace, ledgerFile, append, frameFor, boardIdOf, meetingBoards, boardsOf, baseRows, boardRow, workflowRowOf, foldOf, portfolio, SELF_REFUSAL, NO_STATE };
|
|
@@ -73,7 +73,12 @@ module.exports = {
|
|
|
73
73
|
if (v.error) return bad(v.error);
|
|
74
74
|
if (p === '/api/programs/turn' && known(v.id)) return bad('a program with this name exists already', 409);
|
|
75
75
|
// a turned program names the initiative it came from: its tasks from before the split wait for a level (canvas PgProgram, the sort card)
|
|
76
|
+
// a program check whose done the charter changes ("Open again" in the charter, canvas MsB7Done) gets a check line too: the check lines
|
|
77
|
+
// win over the charter's own done (lib/programs.js withChecks), so without one an older mark would still hold
|
|
78
|
+
const was = p === '/api/programs/save' ? known(v.id) : null;
|
|
79
|
+
const marks = was ? v.milestones.filter((m) => !m.waits.length && (was.milestones || []).some((x) => x.id === m.id && !(x.waits || []).length && !!x.done !== !!m.done)) : [];
|
|
76
80
|
add(p === '/api/programs/turn' ? { ...v, from: String(b.initiative) } : v);
|
|
81
|
+
for (const m of marks) add({ kind: 'check', program: v.id, milestone: m.id, done: !!m.done });
|
|
77
82
|
if (p === '/api/programs/turn') add({ kind: 'member', program: v.id, initiative: String(b.initiative) });
|
|
78
83
|
ctx.json(res, { ok: true, program: known(v.id) });
|
|
79
84
|
return true;
|