create-pmos 0.767.0 → 0.768.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
+ };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.767.0",
3
+ "version": "0.768.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.767.0",
9
+ "version": "0.768.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.767.0",
3
+ "version": "0.768.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -352,6 +352,13 @@ button.pw-fv .grey { color: var(--cz-ink3); }
352
352
  .pw-chev:hover { color: inherit; }
353
353
  .pw-cnt { color: var(--cz-ink3); white-space: nowrap; }
354
354
  .pw-kr.sel { box-shadow: inset 3px 0 0 var(--blue); }
355
+ /* drag to nest, take out or reorder in the Gantt, like the List (Wawan 2026-11-24). Tokens only. */
356
+ .pw-kr .pw-it[draggable="true"] { cursor: grab; }
357
+ .pw-kr.dragging { opacity: .5; }
358
+ .pw-kr.drop-on, .pw-sr.drop-on { box-shadow: inset 0 0 0 2px var(--blue); background: var(--blue-tint); }
359
+ .pw-kr.drop-before { box-shadow: inset 0 2px 0 var(--blue); }
360
+ .pw-kr.drop-after { box-shadow: inset 0 -2px 0 var(--blue); }
361
+ .pw-kr.drop-left { box-shadow: inset 3px 0 0 var(--blue); }
355
362
  .pw-pbar { position: absolute; top: 50%; height: 10px; margin-top: -5px; border: 1.5px solid currentColor; border-radius: 3px; box-sizing: border-box; color: var(--cz-ink2); overflow: hidden; }
356
363
  .pw-pbar b { display: block; height: 100%; background: currentColor; }
357
364
  .pw-pbar.dn { opacity: .6; }
@@ -324,7 +324,7 @@ function rowHtml(x, W, C, sugRows) {
324
324
  // subtasks (WorkSubtasksDS): indent one step per level, a parent's fold and count; a Jira row's key chip and the epic check's dot (WorkJiraDS)
325
325
  const chev = x.kids ? `<button type="button" class="pw-chev" data-pw-sub="${esc(x.uid)}" aria-expanded="${!!x.open}" aria-label="${esc((x.open ? 'Fold ' : 'Open ') + x.title)}">${SVG(x.open ? P.down : P.right, 13)}</button>` : '';
326
326
  const more2 = (x.kids ? `<small class="pw-cnt">${esc(x.count)}</small>` : '') + (W.jc ? '' : chip(x));
327
- return `<div class="pw-tr pw-kr${x.done ? ' done' : ''}${x.lit ? ' lit' : ''}${x.kids ? ' par' : ''}${RSEL.has(String(x.uid)) ? ' sel' : ''}" role="row" data-pw-row="${esc(x.uid)}" data-pw-sec="${esc(x.sec)}"${x.depth ? ` style="--pw-d:${x.depth}"` : ''}><span class="pw-it">${chev}<i class="pw-bul${x.ms ? ' ms' : ''}" aria-hidden="true"></i>${title}${more2}${RO ? '' : ib(`data-pw-open="${esc(x.uid)}"`, 'Open the task', P.open, 'xs hov') + ib(`data-pw-row-more="${esc(x.uid)}" aria-haspopup="menu"`, 'More for ' + x.title, P.more, 'xs hov')}</span>${jc}${stc}${dtc}${tl}</div>`
327
+ return `<div class="pw-tr pw-kr${x.done ? ' done' : ''}${x.lit ? ' lit' : ''}${x.kids ? ' par' : ''}${RSEL.has(String(x.uid)) ? ' sel' : ''}" role="row" data-pw-row="${esc(x.uid)}" data-pw-sec="${esc(x.sec)}"${x.depth ? ` style="--pw-d:${x.depth}"` : ''}><span class="pw-it"${!x.jsub && canDrag() ? ' draggable="true"' : ''}>${chev}<i class="pw-bul${x.ms ? ' ms' : ''}" aria-hidden="true"></i>${title}${more2}${RO ? '' : ib(`data-pw-open="${esc(x.uid)}"`, 'Open the task', P.open, 'xs hov') + ib(`data-pw-row-more="${esc(x.uid)}" aria-haspopup="menu"`, 'More for ' + x.title, P.more, 'xs hov')}</span>${jc}${stc}${dtc}${tl}</div>`
328
328
  + (s ? `<div class="pw-tr pw-sugrow" role="row"><span class="pw-it">${sugLine(s, true)}</span></div>` : '');
329
329
  }
330
330
  function breakdownHtml(W, C, mode, full, S) {
@@ -1024,17 +1024,30 @@ function parentMenu(btn, ids, c, h, x) {
1024
1024
  const kids = new Map(); for (const r of all) if (r.up) { if (!kids.has(r.up)) kids.set(r.up, []); kids.get(r.up).push(r.uid); }
1025
1025
  const walk = (u) => { for (const k of kids.get(u) || []) { under.add(k); walk(k); } };
1026
1026
  for (const u of ids) walk(u);
1027
- const L = all.filter((r) => !pick.has(r.uid) && !under.has(r.uid)).slice(0, 60);
1027
+ // the keyboard way beside the drag (Wawan 2026-11-24: "Bad UI to move as subtask"): the picked task's own stage first, a box to find one
1028
+ const sec0 = String((all.find((r) => r.uid === ids[0]) || {}).sec || '');
1029
+ const C0 = all.filter((r) => !pick.has(r.uid) && !under.has(r.uid));
1030
+ const L = C0.filter((r) => String(r.sec || '') === sec0).concat(C0.filter((r) => String(r.sec || '') !== sec0)).slice(0, 200);
1028
1031
  const n = ids.length;
1029
1032
  openPop(btn, 'pw-under', `<p class="hi-small">${esc('Move ' + (n === 1 ? 'it' : n + ' tasks') + ' under')}</p>`
1033
+ + (L.length > 8 ? `<input class="pm-input" data-pw-under-q type="search" placeholder="Find a task" aria-label="Find the parent task" autocomplete="off">` : '')
1030
1034
  + `<button type="button" class="hi-mi" role="menuitem" data-new>${SVG(P.plus, 14)} A new parent…</button>`
1031
- + L.map((r, i) => `<button type="button" class="hi-mi" role="menuitem" data-i="${i}" style="padding-left:${10 + Math.min(r.depth || 0, 3) * 14}px">${esc(r.title)}${r.kids ? ` <span class="hi-small">${esc(String(r.kids))}</span>` : ''}</button>`).join('')
1035
+ + L.map((r, i) => `<button type="button" class="hi-mi" role="menuitem" data-i="${i}" data-q="${esc(String(r.title || '').toLowerCase())}" style="padding-left:${10 + Math.min(r.depth || 0, 3) * 14}px${i >= 12 ? ';display:none' : ''}">${esc(r.title)}${r.kids ? ` <span class="hi-small">${esc(String(r.kids))}</span>` : ''}</button>`).join('')
1032
1036
  + `<button type="button" class="hi-mi" role="menuitem" data-top>Top level (no parent)</button>`, async (b) => {
1033
1037
  if ('new' in b.dataset) { newParent(btn, ids, all, c, h, x); return; }
1034
1038
  closePop();
1035
1039
  if ('top' in b.dataset) { await runBulk(ids, 'parent', '', c, h, x, 'the top level'); return; }
1036
1040
  const r = L[+b.dataset.i]; if (r) await runBulk(ids, 'parent', r.uid, c, h, x, r.title);
1037
1041
  }, { menu: true, label: 'Under a parent' });
1042
+ // typing narrows the list; with nothing typed it shows the first 12 (the picked task's stage first)
1043
+ const q = document.querySelector('[data-pw-under-q]');
1044
+ if (q) {
1045
+ q.addEventListener('input', () => {
1046
+ const t = q.value.trim().toLowerCase(); let shown = 0;
1047
+ for (const b of q.parentElement.querySelectorAll('[data-q]')) { const on = t ? b.dataset.q.includes(t) : shown < 12; b.style.display = on ? '' : 'none'; if (on) shown++; }
1048
+ });
1049
+ setTimeout(() => q.focus(), 0);
1050
+ }
1038
1051
  }
1039
1052
  /** A new parent: its name, then it is made in the stage of the first picked task and the picked tasks move under it. */
1040
1053
  function newParent(btn, ids, all, c, h, x) {
@@ -1166,25 +1179,27 @@ function wireMoves(body, cur, redraw) {
1166
1179
  const say = (h) => (m, u) => (u ? undoToast(m, u) : h.toast ? h.toast(m) : undoToast(m));
1167
1180
  const allOf = (c) => stagesOf(c.r, c.v, { ...((body.__pwx && body.__pwx.o()) || {}), today: c.W.today, subAll: true });
1168
1181
  const reload = (h) => async () => { if (h.reload) await h.reload(); else if (h.redraw) h.redraw(); };
1169
- // the List: HTML drag and drop (a mouse); onto a row nests, its top or bottom edge is between rows, a stage head is the stage, left is out
1182
+ // the List and the Gantt (Wawan 2026-11-24: "should be able to do it on gantt view"): HTML drag and drop (a mouse); onto a row nests,
1183
+ // its top or bottom edge puts it before or after that row (its parent, its stage and its place in the stage), a stage head is the stage, left is out
1170
1184
  let DR = null;
1171
1185
  const marks = () => body.querySelectorAll('.drop-on, .drop-before, .drop-after, .drop-left, .dragging').forEach((el) => el.classList.remove('drop-on', 'drop-before', 'drop-after', 'drop-left', 'dragging'));
1172
1186
  const zoneOf = (e) => {
1173
1187
  // a stage head (its fold press carries the stage key, its name is the bold text)
1174
- const sh = e.target.closest && e.target.closest('.pwd-gh[data-pw-fold]');
1175
- if (sh) return { el: sh, cls: 'drop-on', to: { zone: 'stage', key: sh.dataset.pwFold, name: (sh.querySelector('b') || {}).textContent || '' } };
1176
- const rw = e.target.closest && e.target.closest('.pwd-li[data-pw-row]'); if (!rw) return null;
1188
+ const sh = e.target.closest && (e.target.closest('.pwd-gh[data-pw-fold]') || e.target.closest('.pw-sr:not(.loose)'));
1189
+ const sk = sh && (sh.dataset.pwFold != null ? sh : sh.querySelector('[data-pw-fold]'));
1190
+ if (sk) return { el: sh, cls: 'drop-on', to: { zone: 'stage', key: sk.dataset.pwFold, name: (sk.querySelector('b') || {}).textContent || '' } };
1191
+ const rw = e.target.closest && e.target.closest('.pwd-li[data-pw-row], .pw-kr[data-pw-row]'); if (!rw) return null;
1177
1192
  const u = rw.dataset.pwRow;
1178
1193
  if (DR.ids.includes(u)) return e.clientX - DR.x0 < -32 ? { el: rw, cls: 'drop-left', to: { zone: 'left' } } : null;
1179
1194
  const r = rw.getBoundingClientRect(), y = (e.clientY - r.top) / Math.max(1, r.height);
1180
- return y < 0.25 ? { el: rw, cls: 'drop-before', to: { zone: 'between', uid: u } } : y > 0.75 ? { el: rw, cls: 'drop-after', to: { zone: 'between', uid: u } } : { el: rw, cls: 'drop-on', to: { zone: 'on', uid: u } };
1195
+ return y < 0.25 ? { el: rw, cls: 'drop-before', to: { zone: 'between', uid: u, edge: 'before' } } : y > 0.75 ? { el: rw, cls: 'drop-after', to: { zone: 'between', uid: u, edge: 'after' } } : { el: rw, cls: 'drop-on', to: { zone: 'on', uid: u } };
1181
1196
  };
1182
1197
  body.addEventListener('dragstart', (e) => {
1183
- const rw = e.target.closest && e.target.closest('.pwd-li[draggable="true"]'); if (!rw) return;
1184
- const c = cur(); if (!c) return;
1198
+ const dg = e.target.closest && e.target.closest('.pwd-li[draggable="true"], .pw-kr .pw-it[draggable="true"]'); if (!dg) return;
1199
+ const rw = dg.closest('[data-pw-row]'), c = cur(); if (!rw || !c) return;
1185
1200
  DR = { ids: SEL.dragIds(c.S.sel, rw.dataset.pwRow), x0: e.clientX };
1186
1201
  try { e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/plain', DR.ids.join(',')); } catch { /* an old browser */ }
1187
- for (const u of DR.ids) { const el = body.querySelector(`.pwd-li[data-pw-row="${window.CSS.escape(u)}"]`); if (el) el.classList.add('dragging'); }
1202
+ for (const u of DR.ids) for (const el of body.querySelectorAll(`.pwd-li[data-pw-row="${window.CSS.escape(u)}"], .pw-kr[data-pw-row="${window.CSS.escape(u)}"]`)) el.classList.add('dragging');
1188
1203
  });
1189
1204
  body.addEventListener('dragover', (e) => {
1190
1205
  if (!DR) return; const z = zoneOf(e);
@@ -1201,7 +1216,7 @@ function wireMoves(body, cur, redraw) {
1201
1216
  if (z.to.zone === 'on') { c.S.subOpen.add(z.to.uid); c.S.subShut.delete(z.to.uid); }
1202
1217
  c.S.sel.clear(); c.S.anchor = '';
1203
1218
  moveLog('drag-' + z.to.zone, ids.length);
1204
- await SEL.bulkSteps(pmPost, { ws: at.ws, board: at.board }, plan.steps, { say: say(h), reload: reload(h) }, plan.label);
1219
+ await SEL.bulkSteps(pmPost, { ws: at.ws, board: at.board, ini: at.ini || c.id }, plan.steps, { say: say(h), reload: reload(h) }, plan.label, plan.order);
1205
1220
  });
1206
1221
  // press and hold (a touch screen): the row is picked; after that a tap adds or takes out one row (the click handler's pick)
1207
1222
  let HOLD = null;
@@ -123,7 +123,22 @@ export function dropPlan(rows, ids, to) {
123
123
  for (const [gp, L] of g) add('parent', gp, L);
124
124
  label = g.size === 1 && [...g.keys()][0] ? ((by.get([...g.keys()][0]) || {}).title || '') : 'the top level';
125
125
  } else return null;
126
- return steps.length ? { steps, label } : null;
126
+ const order = to.zone === 'between' ? orderOf(T, I, by.get(String(to.uid)), to.edge) : null;
127
+ if (!steps.length && !order) return null;
128
+ return order ? { steps, label: steps.length ? label : '', order } : { steps, label };
129
+ }
130
+ /** The stage's new order after a drop between rows (Wawan 2026-11-24: reorder by drag, in the Gantt too): every task of the target's stage
131
+ * top to bottom, the dragged ones before or after the target; null when the order does not change or a Jira ticket keeps Jira's stage. */
132
+ function orderOf(T, I, tg, edge) {
133
+ if (!tg || tg.sec == null) return null;
134
+ const sec = String(tg.sec), moving = new Set(I), inSec = (x) => String(x.sec == null ? '' : x.sec) === sec;
135
+ const was = T.filter(inSec).map((x) => String(x.uid));
136
+ const kept = I.filter((u) => { const x = T.find((q) => String(q.uid) === u); return x && (inSec(x) || !x.jira); });
137
+ if (!kept.length) return null;
138
+ const rest = was.filter((u) => !moving.has(u)), at = rest.indexOf(String(tg.uid));
139
+ if (at < 0) return null;
140
+ const tasks = rest.slice(0, edge === 'before' ? at : at + 1).concat(kept, rest.slice(edge === 'before' ? at : at + 1));
141
+ return tasks.join('\u0000') === was.join('\u0000') ? null : { section: sec, tasks };
127
142
  }
128
143
  export function daysOf(dx, width, days) {
129
144
  if (!(width > 0) || !(days > 0)) return 0;
@@ -141,23 +156,30 @@ export function shiftIds(sel, uid, rows) {
141
156
  return [u];
142
157
  }
143
158
  /** A drop that changes parent and stage: each step is a bulk write; one message and one Undo put every step back, the last first. */
144
- export async function bulkSteps(post, at, steps, h = {}, label = '') {
159
+ export async function bulkSteps(post, at, steps, h = {}, label = '', order = null) {
145
160
  const done = [], skipped = [];
146
161
  for (const s of steps || []) {
147
162
  const r = await bulk(post, at, s.ids, s.op, s.value, {}, label).catch(() => null);
148
163
  if (r && r.runs) done.push(...r.runs);
149
164
  if (r) skipped.push(...(r.skipped || []));
150
165
  }
166
+ // the order inside the stage (POST /api/boards/tasks/order); its Undo sends the order it had back
167
+ let ord = null;
168
+ if (order && at.ini) {
169
+ const r = await post('/api/boards/tasks/order', { ws: at.ws, board: at.board, initiative: at.ini, section: order.section, tasks: order.tasks }).catch(() => null);
170
+ if (r && r.ok !== false) ord = { section: order.section, from: r.from || [] };
171
+ }
151
172
  const ids = new Set(done.flatMap((d) => d.undo.map((x) => x.task)));
152
173
  const n = ids.size;
153
174
  const text = n ? `${n === 1 ? '1 task' : n + ' tasks'} moved${label ? (label === 'the top level' ? ' to the top level' : ' to ' + label) : ''}.${skipped.length ? ' ' + skipped.length + ' not moved: ' + skipped[0].why + '.' : ''}`
154
- : (skipped[0] && skipped[0].why ? 'Nothing moved: ' + skipped[0].why + '.' : 'Nothing moved.');
155
- const undo = n ? async () => {
175
+ : ord ? 'Order changed.' : (skipped[0] && skipped[0].why ? 'Nothing moved: ' + skipped[0].why + '.' : 'Nothing moved.');
176
+ const undo = n || ord ? async () => {
177
+ if (ord) await post('/api/boards/tasks/order', { ws: at.ws, board: at.board, initiative: at.ini, section: ord.section, tasks: ord.from }).catch(() => null);
156
178
  for (const d of done.slice().reverse()) await post('/api/boards/tasks/bulk-undo', { ws: d.ws, board: d.board, undo: d.undo }).catch(() => null);
157
179
  if (h.say) h.say('Put back.');
158
180
  if (h.reload) await h.reload();
159
181
  } : null;
160
182
  if (h.say) h.say(text, undo);
161
183
  if (h.reload) await h.reload();
162
- return { moved: n, skipped };
184
+ return { moved: n, skipped, ordered: !!ord };
163
185
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Drag to nest, take out and reorder in the Gantt, like the List; the picker's stage-first order and find box (initiative gantt-drag-nest, done test G1-G5). Pure; no browser, server or network.",
3
+ "modules": [
4
+ "gantt-drag.test.js"
5
+ ],
6
+ "seconds": {
7
+ "gantt-drag.test.js": 1
8
+ }
9
+ }