create-pmos 0.766.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.
@@ -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
+ };
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-24T07:23:46Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-24T07:49:33Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,36 @@
1
1
  [
2
+ {
3
+ "v": "0.768.0",
4
+ "at": "2026-11-24T07:49:37.442Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1731,
9
+ "t": "The workflow decides the kind of work, not a legacy type: feature",
10
+ "s": "The workflow decides the kind of work, not a legacy type: feature",
11
+ "k": "fix"
12
+ },
13
+ {
14
+ "n": 1730,
15
+ "t": "Drag to nest, take out and reorder in the Gantt, like the List",
16
+ "s": "Drag to nest, take out and reorder in the Gantt, like the List",
17
+ "k": "new"
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "v": "0.767.0",
23
+ "at": "2026-11-24T07:34:38.820Z",
24
+ "f": 4,
25
+ "prs": [
26
+ {
27
+ "n": 1727,
28
+ "t": "Let the work breakdown Gantt scroll sideways",
29
+ "s": "Let the work breakdown Gantt scroll sideways",
30
+ "k": "fix"
31
+ }
32
+ ]
33
+ },
2
34
  {
3
35
  "v": "0.766.0",
4
36
  "at": "2026-11-24T07:23:50.157Z",
@@ -17,14 +17,16 @@ If the save fails, the change goes back and a message tells you why, for example
17
17
 
18
18
  ## Subtasks
19
19
 
20
- A task can sit under another task, at any depth. To add a subtask, type `under <parent>: <title>` in the add box of the Work breakdown, for example `under Batch 2: TM web`. To move a task, open its **More** menu and select **Make subtask of…** or **Move out of …**. With a mouse you can also drag a task in the List:
20
+ A task can sit under another task, at any depth. To add a subtask, type `under <parent>: <title>` in the add box of the Work breakdown, for example `under Batch 2: TM web`. To move a task, open its **More** menu and select **Make subtask of…** or **Move out of …**. With a mouse you can also drag a task, in the List or in the Gantt (hold its name):
21
21
 
22
22
  - Drop it on another task to put it under that task.
23
- - Drop it on the top or bottom edge of a row to put it next to that row, under the same parent and in the same stage.
23
+ - Drop it on the top or bottom edge of a row to put it just before or after that row, under the same parent and in the same stage. This is also how you change the order of tasks in a stage.
24
24
  - Drop it on a stage heading to move it to that stage, at the top level.
25
25
  - Drag it to the left to move it out of its parent, one level up.
26
26
 
27
- If you drag a selected task, all the selected tasks move. One **Undo** puts them back.
27
+ If you drag a selected task, all the selected tasks move. One **Undo** puts them back, and their order too.
28
+
29
+ In **Make subtask of…**, the tasks of the same stage come first. When the list is long, type in **Find a task** to narrow it.
28
30
 
29
31
  When a stage has 8 or more tasks and several of them share a go-live date, PMOS suggests groups, for example "Group the 12 tasks of Build into 3 batches?". Select ✓ to make one parent for each date and put the tasks under it. One **Undo** removes the parents again. PMOS does not group tasks without your ✓.
30
32
 
@@ -2,7 +2,7 @@
2
2
  type: Guide
3
3
  title: "Layout and first run: the places, the navigation, the Viewer, the launcher and Adler"
4
4
  description: "The places, the navigation at the left, the Viewer, the keys and the phone; the first run; when features appear; the PMOS app; and Adler."
5
- timestamp: 2026-11-23
5
+ timestamp: 2026-11-24
6
6
  ---
7
7
 
8
8
  # Layout and first run
@@ -188,7 +188,7 @@ Press the rest of a row, or a milestone, to open it as a full popup in place of
188
188
  On a phone, in a shared read-only copy and in a breakdown given the whole popup, the work side keeps the three parts below. They use the full width of the popup: in a wide popup the timeline gets the extra width. A done task shows in grey text, never struck through.
189
189
 
190
190
  - **Overview.** Three short lines from the initiative's own records: **Problem**, **Goal** (with the goal it serves, by name) and **Done when**. A line with no record says **Not written yet.** and offers a draft with ✓ and ✕. Press a line to change it; it saves when you leave the field, with **Undo**. Then one line on where it stands, **PMOS suggests** (at most three, each with ✓ and ✕), and **Details ›** for the facts: Stage, Status, Start, Target end, Next milestone, Goal, Product, Program, Workflow and Open. A fact with no value is not shown. Goal, Product, Program and Next milestone are in the link colour and open their thing; the others are plain text. An initiative that is closed or done but has open tasks shows one suggestion: **Close them** or **Reopen**.
191
- - **Work breakdown.** Each stage is a row that folds and says how much is done, for example "3 of 9 done". Only the stage in progress opens by itself, and a stage whose tasks are all done stays folded until you open it. In a stage, the tasks are in date order, a late task first; a done task stays in its place, in grey. In a long stage you see the late tasks, the tasks in progress and the next five, then **N more tasks**. The stages after the next one fold to one row. A task in no stage is not in the breakdown: it is in Work › Backlog, and one quiet line under the breakdown says how many, for example **2 tasks with no stage are in the Backlog ›**. A task with no date shows no date and is never late. The timeline is on the right, with **Today** on it. Drag the grip between the columns and the timeline to make the timeline wider or narrower; a double press puts it back. Choose its span (Quarter to Full) beside the tune icon, which shows or hides columns. The four-corners icon gives the breakdown the whole popup. Type in the last row of a stage to add a task; the **Task** choice beside it makes the next one a milestone.
191
+ - **Work breakdown.** Each stage is a row that folds and says how much is done, for example "3 of 9 done". Only the stage in progress opens by itself, and a stage whose tasks are all done stays folded until you open it. In a stage, the tasks are in date order, a late task first; a done task stays in its place, in grey. In a long stage you see the late tasks, the tasks in progress and the next five, then **N more tasks**. The stages after the next one fold to one row. A task in no stage is not in the breakdown: it is in Work › Backlog, and one quiet line under the breakdown says how many, for example **2 tasks with no stage are in the Backlog ›**. A task with no date shows no date and is never late. The timeline is on the right, with **Today** on it. Drag the grip between the columns and the timeline to make the timeline wider or narrower; a double press puts it back. Choose its span (Quarter to Full) beside the tune icon, which shows or hides columns. A span shorter than the work opens on the period that holds today; scroll the timeline sideways to see the rest, with a sideways swipe on a trackpad, Shift and the mouse wheel, or by dragging its empty part. The item, status and date columns stay in place, and a thin bar under the dates shows where you are. A program's or a product's initiatives scroll the same way. The four-corners icon gives the breakdown the whole popup. Type in the last row of a stage to add a task; the **Task** choice beside it makes the next one a milestone.
192
192
  - **Status.** Press a task's status and pick the new one. **When did this happen?** shows under the list, with **Today** chosen: press the status again, or Enter, to keep today. Press **Yesterday**, or **Pick a date**, when the work moved earlier than you noted it. A day in the future, or a day before the task's previous move, cannot be picked. The toast says both days, for example "Done on 14 Nov, noted today.", with **Undo**.
193
193
  - **Open the task.** The ↗ on a row, or **Open the task** in its ⋯, opens a small popup on top: Task or Milestone, the name (press it to rename), status, dates, owner and notes. Its status asks **When did this happen?** too. ↑ and ↓ go to the task before or after it, and ⋯ has **Make it a milestone**, **Archive** and **Delete**, each with **Undo**. A change shows on the task's row at once. Escape, × or a press outside closes only the small popup, and the task's row lights for a moment.
194
194
  - **Dates.** Press a task's date. **Task | Milestone** on top turns it into a milestone (one Date) or back into a task (Start and Due). Write a day as "15 Oct 2026", or press the calendar icon. The row's ⋯ also has **Make it a milestone** and **Open the task**.
@@ -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 = (() => { const k = String(fm.kind || '').trim().replace(/^["']|["']$/g, ''); return k === 'sdlc' || k === 'project' ? k : 'product'; })();
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 = (() => { const k = String(fm.kind || '').trim().replace(/^["']|["']$/g, ''); return k === 'sdlc' || k === 'project' ? k : 'product'; })();
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;
@@ -3,6 +3,7 @@
3
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
4
  *
5
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)
6
7
  * check(wf, { existing }) → { ok, workflow } | { ok:false, status, error } validate and normalise one workflow
7
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
8
9
  * forKind(folded, kind) · isKindDefault(folded, kind, wfId) the workflow a kind starts on; whether an initiative still runs it
@@ -180,7 +181,30 @@ function check(wf) {
180
181
  }
181
182
  if (Object.keys(map).length && slug(br.from) !== id) bridge = { from: slug(br.from), map };
182
183
  }
183
- return { ok: true, workflow: { id, name, icon, decide, stages, ...(bridge ? { bridge } : {}) } };
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';
184
208
  }
185
209
 
186
210
  /** Fold workflows.jsonl (objects or JSON strings), oldest first. */
@@ -324,7 +348,7 @@ function copyOf(wf, name, taken) {
324
348
  const n = oneLine(name, NAME_MAX) ? name.trim() : 'Copy of ' + wf.name;
325
349
  let id = slug(n) || 'workflow', k = 2;
326
350
  while ((taken && taken.has(id)) || isBuiltin(id)) id = slug(n) + '-' + k++;
327
- 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 })) })) };
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 })) })) };
328
352
  }
329
353
 
330
354
  /** The workflow a kind of work starts on: Project and Full SDLC their own; Product management the workspace's default (defaultOf). */
@@ -346,5 +370,5 @@ const milestonesOf = (wf) => (wf || PRODUCT_FEATURE).stages.filter((s) => s.mile
346
370
  module.exports = {
347
371
  CATS, CAT_LABEL, ENDS, OUTPUT_KINDS, WHEN_MODES, DECIDE, ICONS, PRODUCT_FEATURE_ID, PRODUCT_FEATURE,
348
372
  PROJECT_ID, PROJECT, FULL_SDLC_ID, FULL_SDLC, BUILTIN, KIND_WF, KIND_GATE, MEANING, isBuiltin, forKind, isKindDefault,
349
- slug, check, fold, list, defaultOf, resolve, stageByRef, switchTarget, proposeBridge, mapOf, removedInUse, stagesOf, copyOf, milestonesOf,
373
+ WORK_KINDS, kindOf, slug, check, fold, list, defaultOf, resolve, stageByRef, switchTarget, proposeBridge, mapOf, removedInUse, stagesOf, copyOf, milestonesOf,
350
374
  };
@@ -395,6 +395,17 @@ function setKind(root, id, kind, { actor } = {}) {
395
395
  return { ok: true, id, from, kind };
396
396
  }
397
397
 
398
+ /** The record's own `kind:` line, read: { ok, kind, has } (has false when the record has no line; kind then reads as Product management). */
399
+ function readKind(root, id) {
400
+ const f = recordFile(root, id);
401
+ if (!f.ok) return f;
402
+ let text = '';
403
+ try { text = fs.readFileSync(f.file, 'utf8'); } catch { return refuse(500, 'the record could not be read'); }
404
+ const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
405
+ const line = m ? m[1].split(/\r?\n/).find((l) => /^kind:/.test(l)) : null;
406
+ return { ok: true, kind: WK.kindOf(line ? line.slice(5) : ''), has: !!line };
407
+ }
408
+
398
409
  function withdrawSplit(root, id, want, { actor } = {}) {
399
410
  if (!actorLib.valid(actor)) return refuse(500, 'initiative-writer: the caller must pass the actor from pm-guard.js or actor.js');
400
411
  const f = recordFile(root, id);
@@ -406,4 +417,4 @@ function withdrawSplit(root, id, want, { actor } = {}) {
406
417
  return { ok: true, removed: true };
407
418
  }
408
419
 
409
- module.exports = { setKind, setRaisedBy, setDescription, restoreDescription, DESC_MAX, setOutcome, restoreOutcome, createInitiative, renameInitiative, setAnchor, restoreAnchor, withdrawSplit, recordSha, slugOf, ID_RE, INPUT_KEYS };
420
+ module.exports = { setKind, readKind, setRaisedBy, setDescription, restoreDescription, DESC_MAX, setOutcome, restoreOutcome, createInitiative, renameInitiative, setAnchor, restoreAnchor, withdrawSplit, recordSha, slugOf, ID_RE, INPUT_KEYS };