create-pmos 0.421.0 → 0.423.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +25 -25
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/scripts/anchor-resolve.js +93 -15
- package/payload/state/discoveries.md +1 -1
- package/workspace/board-programs-test.js +87 -3
- package/workspace/briefing-premium-adddoc-test.js +1 -1
- package/workspace/briefing-premium-board-test.js +13 -11
- package/workspace/briefing-premium-initiative-test.js +30 -38
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/report-api/draft.json +2 -1
- package/workspace/guide/briefing-premium.md +2 -1
- package/workspace/guide/home.md +14 -4
- package/workspace/guide/programs.md +5 -3
- package/workspace/guide/workflows.md +5 -1
- package/workspace/home-other-product-test.js +55 -0
- package/workspace/ini-workflow-test.js +4 -4
- package/workspace/lib/board-premium.js +21 -6
- package/workspace/lib/custom-docs.js +65 -3
- package/workspace/lib/doc-live-root.js +37 -0
- package/workspace/lib/engine/anchor-resolve.js +93 -15
- package/workspace/lib/engine/boards.js +30 -2
- package/workspace/lib/engine/intake.js +1 -1
- package/workspace/lib/hold-spans.js +24 -10
- package/workspace/lib/initiative-writer.js +63 -1
- package/workspace/lib/kg.js +1 -1
- package/workspace/lib/plan-items.js +36 -5
- package/workspace/lib/programs.js +11 -3
- package/workspace/lib/report-draft.js +3 -0
- package/workspace/lib/route-modules.js +2 -0
- package/workspace/lib/routes-board-premium.js +28 -0
- package/workspace/lib/routes-boards.js +92 -13
- package/workspace/lib/routes-doc-sheet.js +29 -1
- package/workspace/lib/routes-initiatives.js +12 -0
- package/workspace/lib/routes-programs.js +44 -5
- package/workspace/lib/routes-task-links.js +329 -0
- package/workspace/lib/routes-task-plans.js +333 -0
- package/workspace/lib/split-merge-suggest.js +162 -0
- package/workspace/lib/split-merge.js +379 -0
- package/workspace/lib/task-cli.js +73 -13
- package/workspace/lib/task-items.js +15 -3
- package/workspace/lib/task-links.js +422 -0
- package/workspace/lib/task-plans.js +232 -0
- package/workspace/lib/vendor/scripts/anchor-resolve.js +93 -15
- package/workspace/lib/vendor/scripts/intake.js +1 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +2 -2
- package/workspace/premium-core-doc-issue-test.js +2 -2
- package/workspace/premium-vw-backlog-test.js +3 -3
- package/workspace/premium-vw-doc-test.js +26 -3
- package/workspace/premium-vw-item-test.js +3 -3
- package/workspace/premium-vw-jira-test.js +6 -6
- package/workspace/product-lane-test.js +165 -0
- package/workspace/program-leave-test.js +203 -0
- package/workspace/program-panel-test.js +1 -1
- package/workspace/public/pm/bd-acts.js +5 -2
- package/workspace/public/pm/bd-ini-panel.js +32 -9
- package/workspace/public/pm/bd-prog-panel.js +22 -7
- package/workspace/public/pm/bd-prog.js +6 -1
- package/workspace/public/pm/bd-span.js +234 -30
- package/workspace/public/pm/bd-views.js +3 -2
- package/workspace/public/pm/cozy-board.css +90 -0
- package/workspace/public/pm/cozy-home.css +3 -0
- package/workspace/public/pm/doc-follow.js +36 -0
- package/workspace/public/pm/home-app.js +62 -14
- package/workspace/public/pm/home-ini-model.js +0 -34
- package/workspace/public/pm/home-ini.js +81 -204
- package/workspace/public/pm/home-list.js +2 -2
- package/workspace/public/pm/home-today.js +3 -1
- package/workspace/public/pm/ini-groups.js +228 -0
- package/workspace/public/pm/ini-links.js +561 -0
- package/workspace/public/pm/ini-tasks.js +131 -30
- package/workspace/public/pm/ini-versions.js +348 -0
- package/workspace/public/pm/ini-view-model.js +113 -43
- package/workspace/public/pm/ini-view.css +341 -18
- package/workspace/public/pm/ini-view.js +153 -38
- package/workspace/public/pm/premium-board.js +160 -21
- package/workspace/public/pm/premium-report-read.js +20 -1
- package/workspace/public/pm/premium-shell.js +29 -4
- package/workspace/public/pm/premium-vw-doc.js +46 -11
- package/workspace/public/pm/prog-move.js +69 -0
- package/workspace/public/pm/split-merge.css +77 -0
- package/workspace/public/pm/split-merge.js +265 -0
- package/workspace/public/pm/stage-line.js +414 -0
- package/workspace/public/pm/task-card.css +3 -0
- package/workspace/public/pm/task-card.js +15 -6
- package/workspace/public/pm/wf-page.css +2 -0
- package/workspace/public/pm/wf-page.js +2 -0
- package/workspace/public/pm/wf-stage.js +2 -1
- package/workspace/server.js +15 -1
- package/workspace/split-merge-ui-test.js +175 -0
- package/workspace/stage-card-test.js +12 -11
- package/workspace/task-card-test.js +3 -2
- package/workspace/task-delete-test.js +126 -0
- package/workspace/task-links-test.js +227 -0
- package/workspace/task-milestones-test.js +176 -0
- package/workspace/task-plans-test.js +181 -0
- package/workspace/task-views-test.js +3 -3
- package/workspace/test-lists/bd-ini-panel.json +8 -2
- package/workspace/test-lists/product-lane.json +6 -0
- package/workspace/test-lists/program-leave.json +6 -0
- package/workspace/test-lists/split-merge.json +15 -0
- package/workspace/test-lists/task-delete.json +5 -0
- package/workspace/test-lists/task-links.json +6 -0
- package/workspace/test-lists/task-milestones.json +6 -0
- package/workspace/test-lists/task-plans.json +6 -0
- package/workspace/test-lists/viewer-live-file.json +9 -0
- package/workspace/timeline-holds-test.js +61 -4
- package/workspace/tk-tasks-test.js +173 -57
- package/workspace/workflows-setup-test.js +4 -3
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* split-merge.js — split one initiative in two, or merge two into one (feedback batch 11 item 14, option A grilled and agreed 2026-10-26;
|
|
3
|
+
* canvas In development, row "Split or merge initiatives": XsmA1Suggest to XsmA9PhoneSplit, rules sticky xsplitR).
|
|
4
|
+
*
|
|
5
|
+
* split(ctx, w, body, actor) POST /api/initiatives/split { ws, from, name, tasks[], tickets[], docs[], stage? }
|
|
6
|
+
* → { ok, id, title, board, counts: { tasks, tickets, docs }, undo }
|
|
7
|
+
* merge(ctx, w, body, actor) POST /api/initiatives/merge { ws, from, into, anchor? }
|
|
8
|
+
* → { ok, from, into, title, counts: { tasks, tickets, docs, chats, milestones }, undo }
|
|
9
|
+
* undo(ctx, w, body, actor) POST /api/initiatives/sm-undo { ws, undo } → { ok, kind, from, to }
|
|
10
|
+
* dismiss(ctx, w, body, actor) POST /api/initiatives/suggest { ws, id, of: split|merge, fp } Claude's suggestion, ✕ Not now
|
|
11
|
+
*
|
|
12
|
+
* Claude only suggests (lib/split-merge-suggest.js); every write here is a page press (pm-guard requirePagePress in the caller), so nothing
|
|
13
|
+
* splits or merges without the PM's ✓ or the editor's own button. All of it is file mode:
|
|
14
|
+
*
|
|
15
|
+
* SPLIT. initiative-writer makes the new record (same lane and anchor). The boards ledger puts it on the same board, on the same workflow, at
|
|
16
|
+
* the stage asked, else the earliest stage among the tasks that move, else where `from` stands. The picked Board tasks get a task-update
|
|
17
|
+
* line (`initiative`), each picked breakdown item is planned again under the new initiative and withdrawn from the old one (an item's id
|
|
18
|
+
* names its initiative, lib/plan-items.js), each picked Jira ticket gets a ticket-move line, each picked document a move line
|
|
19
|
+
* (lib/custom-docs.js). In a program, the new one joins it and goes in the program's order right after `from`. One ini-split line holds all
|
|
20
|
+
* of it, with what Undo needs, and gives each side a history line ("Split off …", "Split from …").
|
|
21
|
+
*
|
|
22
|
+
* MERGE. Everything of `from` goes to `into`: its tasks and breakdown items, its Jira epic links and tickets, its documents, its open chats
|
|
23
|
+
* (the session's initiative binding) and the program milestones that wait on it. Two PRDs: `into` keeps its own and the other joins its
|
|
24
|
+
* documents (one PRD alone joins too: the record of `into` is not rewritten). `anchor` keeps the closing one's anchor instead (the
|
|
25
|
+
* `parent_kr:` line of `into`). The end date is not a choice: it follows the tasks, so the later end comes with them. `from` is closed as
|
|
26
|
+
* Merged: archived, never deleted (an ini-archive line with `into`), and keeps its run log, closed chats, history and worktree. Jira is
|
|
27
|
+
* not written to.
|
|
28
|
+
*
|
|
29
|
+
* UNDO. The answer's `undo` is the op id of the ini-split or ini-merge line; one sm-undo puts back what that line moved, once, unless the
|
|
30
|
+
* PM has moved a thing on since. A split's record is taken back only while it holds exactly what the split wrote (initiative-writer
|
|
31
|
+
* withdrawSplit); otherwise the emptied new initiative is archived and the answer says so. */
|
|
32
|
+
const fs = require('fs');
|
|
33
|
+
const path = require('path');
|
|
34
|
+
const crypto = require('crypto');
|
|
35
|
+
const Placements = require('./placements.js');
|
|
36
|
+
const writer = require('./initiative-writer.js');
|
|
37
|
+
const Custom = require('./custom-docs.js');
|
|
38
|
+
const TI = require('./task-items.js');
|
|
39
|
+
const planItems = require('./plan-items.js');
|
|
40
|
+
const planTree = require('./plan-tree.js');
|
|
41
|
+
const pmItems = require('./pm-items.js');
|
|
42
|
+
const P = require('./programs.js');
|
|
43
|
+
const rowsLib = require('./initiative-rows.js');
|
|
44
|
+
|
|
45
|
+
const Boards = () => require('./routes-boards.js'); // lazy: routes-boards requires routes-initiatives, which requires this file
|
|
46
|
+
const Progs = () => require('./routes-programs.js');
|
|
47
|
+
const { repoScript } = require('./repo-script.js');
|
|
48
|
+
const Bm = () => require(repoScript('boards.js'));
|
|
49
|
+
|
|
50
|
+
const ONE_LINE = (v, max) => typeof v === 'string' && v.trim().length >= 1 && v.trim().length <= max && !/[\r\n\x00-\x08\x0b-\x1f]/.test(v);
|
|
51
|
+
const refuse = (status, error, extra = {}) => ({ ok: false, status, error, ...extra });
|
|
52
|
+
const ids = (v, n = 400) => (Array.isArray(v) ? [...new Set(v.filter((x) => typeof x === 'string' && x && x.length <= 120))].slice(0, n) : null);
|
|
53
|
+
const opId = () => 'sm-' + Date.now().toString(36) + '-' + crypto.randomBytes(3).toString('hex');
|
|
54
|
+
|
|
55
|
+
/** The frontmatter keys of a record that a split or a merge reads: parent_kr and prd_path. */
|
|
56
|
+
function fmOf(root, rel) {
|
|
57
|
+
if (!rel) return {};
|
|
58
|
+
let text = '';
|
|
59
|
+
try { text = fs.readFileSync(path.isAbsolute(rel) ? rel : path.join(root, rel), 'utf8'); } catch { return {}; }
|
|
60
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
|
|
61
|
+
const out = {};
|
|
62
|
+
if (!m) return out;
|
|
63
|
+
for (const line of m[1].split(/\r?\n/)) {
|
|
64
|
+
const k = /^(parent_kr|prd_path|lane):\s*(.*)$/.exec(line);
|
|
65
|
+
if (k) out[k[1]] = k[2].trim().replace(/^"(.*)"$/, '$1').replace(/^'(.*)'$/, '$1');
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** What one write needs: the frame, the base rows, the two board rows and the board they are on. → { …, error? } */
|
|
71
|
+
function frame(ctx, w) {
|
|
72
|
+
const R = Boards();
|
|
73
|
+
const base = R.baseRows(w);
|
|
74
|
+
if (base.pending) return refuse(202, 'The initiatives are being read. Ask again in a few seconds.', { pending: true });
|
|
75
|
+
if (!base.ok) return refuse(500, base.error || 'the initiatives could not be read');
|
|
76
|
+
const fr = R.frameFor(ctx, w);
|
|
77
|
+
const file = R.ledgerFile(ctx, w);
|
|
78
|
+
if (!file) return refuse(409, R.NO_STATE || 'this workspace has no state folder');
|
|
79
|
+
return { R, base: base.rows, fr, file };
|
|
80
|
+
}
|
|
81
|
+
const boardOf = (F, b0) => F.fr.boards.find((b) => b.id === F.R.boardIdOf(b0, F.fr.boards, F.fr.folded, F.fr.w)) || null;
|
|
82
|
+
const live = (F, id) => {
|
|
83
|
+
const b0 = F.base.find((r) => r.id === id);
|
|
84
|
+
if (!b0) return refuse(404, `no initiative ${id} in this workspace`);
|
|
85
|
+
if (F.fr.folded.archives.has(id)) return refuse(409, `${b0.title} is archived`);
|
|
86
|
+
return { ok: true, b0, board: boardOf(F, b0) };
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** The Jira items of an initiative on its board, as the Board lists them (routes-boards itemsOf, ticket moves applied). */
|
|
90
|
+
function jiraOf(F, board, id) {
|
|
91
|
+
const rows = F.R.rowsOfBoard(F.fr, board, F.base);
|
|
92
|
+
return F.R.itemsOf(F.fr.w, F.fr, board, rows).filter((x) => x.src === 'jira' && x.ini === id && x.key);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The program that holds the initiative in this workspace, or null. */
|
|
96
|
+
function programOf(ctx, w, id) {
|
|
97
|
+
let all = [];
|
|
98
|
+
try { all = Progs().all(ctx); } catch { all = []; }
|
|
99
|
+
return all.find((p) => !p.archived && (p.members || []).some((m) => m.initiative === id && (!m.ws || m.ws === w.id))) || null;
|
|
100
|
+
}
|
|
101
|
+
/** One programs.jsonl line in the workspace `home` (a charter or an order line goes where the charter is). */
|
|
102
|
+
function progLine(ctx, home, line) {
|
|
103
|
+
const hw = ctx.getWs ? ctx.getWs(home || null) : null;
|
|
104
|
+
const f = hw ? Progs().fileOf(ctx, hw) : null;
|
|
105
|
+
if (!f) return false;
|
|
106
|
+
pmItems.appendEvent(f, line, new Date());
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Breakdown items planned again under `to` (same title, owner, dates, flag, note, state) and withdrawn from where they were.
|
|
111
|
+
* → [{ from, to }] the old and the new item ids. Two writes: the new ids exist only once the planned lines are written. */
|
|
112
|
+
function copyItems(root, list, to, actor) {
|
|
113
|
+
if (!list.length) return [];
|
|
114
|
+
const stages = planTree.stagesFor(root, to) || [];
|
|
115
|
+
const stageOf = (s) => ((stages.find((x) => x.id === s) || stages[0] || {}).id || s);
|
|
116
|
+
const planned = list.map((it) => {
|
|
117
|
+
const ev = { ev: 'planned', initiative: to, title: it.title, stage: stageOf(it.stage), owner: it.owner || 'you', milestone: !!it.milestone };
|
|
118
|
+
if (it.start) ev.start = it.start;
|
|
119
|
+
if (it.due) ev.due = it.due;
|
|
120
|
+
if (it.note) ev.note = it.note;
|
|
121
|
+
return ev;
|
|
122
|
+
});
|
|
123
|
+
const a = TI.write(root, planned, actor);
|
|
124
|
+
if (!a.ok) throw new Error('the tasks could not be copied: ' + a.error);
|
|
125
|
+
const made = a.written.map((x) => x.item);
|
|
126
|
+
const after = [];
|
|
127
|
+
list.forEach((it, i) => {
|
|
128
|
+
if (it.state && it.state !== 'todo') after.push({ ev: 'moved', item: made[i], to: it.state === 'review' ? 'doing' : it.state });
|
|
129
|
+
if (it.blocked && it.blocked.reason) after.push({ ev: 'flagged', item: made[i], blocked: true, reason: it.blocked.reason });
|
|
130
|
+
after.push({ ev: 'withdrawn', item: it.id });
|
|
131
|
+
});
|
|
132
|
+
const b = TI.write(root, after, actor);
|
|
133
|
+
if (!b.ok) throw new Error('the tasks were copied but not all of them moved: ' + b.error);
|
|
134
|
+
return list.map((it, i) => ({ from: it.id, to: made[i] }));
|
|
135
|
+
}
|
|
136
|
+
const itemsOfIni = (root, id) => { try { const f = planItems.readFold(root); return Object.values(f.items || {}).filter((it) => it && it.initiative === id && !it.proposed); } catch { return []; } };
|
|
137
|
+
const openItem = (root, id) => { try { const f = planItems.readFold(root); return f.items[id] || null; } catch { return null; } };
|
|
138
|
+
|
|
139
|
+
/** The stage a split-off starts at: the earliest stage of the workflow among the tasks that move, else where `from` stands. */
|
|
140
|
+
function stageFor(F, board, b0, tasks, items, want) {
|
|
141
|
+
const R = F.R, folded = F.fr.folded;
|
|
142
|
+
const wx = R.workflowRowOf(board, b0, folded, folded.wfLib, Bm().stageOf(board, b0.id, b0.reading, folded).stage);
|
|
143
|
+
const st = wx.stages || [];
|
|
144
|
+
const at = (k) => st.findIndex((x) => x.key === k || String(x.name).toLowerCase() === String(k || '').toLowerCase());
|
|
145
|
+
if (want != null && want !== '') { const i = at(want); return i >= 0 ? { st: st[i], wx } : { error: `"${want}" is not a stage of ${b0.title}'s workflow` }; }
|
|
146
|
+
let best = -1;
|
|
147
|
+
for (const t of tasks) {
|
|
148
|
+
const k = folded.sections && folded.sections.has(t.id) ? folded.sections.get(t.id) : (t.from && t.from.stage) || null;
|
|
149
|
+
const i = k ? at(k) : -1; if (i >= 0 && (best < 0 || i < best)) best = i;
|
|
150
|
+
}
|
|
151
|
+
for (const it of items) { const i = it.stage ? at(it.stage) : -1; if (i >= 0 && (best < 0 || i < best)) best = i; }
|
|
152
|
+
if (best < 0) best = Math.max(0, at(wx.stage));
|
|
153
|
+
return { st: st[best] || st[0], wx };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function split(ctx, w, body, actor) {
|
|
157
|
+
const F = frame(ctx, w); if (F.ok === false) return F;
|
|
158
|
+
const from = String(body.from || '');
|
|
159
|
+
const s = live(F, from); if (!s.ok) return s;
|
|
160
|
+
const { b0, board } = s;
|
|
161
|
+
if (!board) return refuse(404, `${b0.title} is on no board`);
|
|
162
|
+
if (board.self) return refuse(409, F.R.SELF_REFUSAL || 'PMOS keeps its derived ladder');
|
|
163
|
+
if (!ONE_LINE(body.name, 120)) return refuse(400, 'give the new initiative a name of 1 to 120 characters on one line');
|
|
164
|
+
const name = body.name.trim();
|
|
165
|
+
const T = ids(body.tasks) || [], K = (ids(body.tickets) || []).map((k) => k.toUpperCase()), D = ids(body.docs) || [];
|
|
166
|
+
if (!T.length && !K.length) return refuse(400, 'pick at least one task or Jira ticket to move');
|
|
167
|
+
const folded = F.fr.folded;
|
|
168
|
+
const tasks = [], items = [];
|
|
169
|
+
for (const id of T) {
|
|
170
|
+
const t = Bm().taskOf(folded, id);
|
|
171
|
+
if (t && t.initiative === from) { tasks.push(t); continue; }
|
|
172
|
+
const it = TI.isItemId(id) ? openItem(w.root, id) : null;
|
|
173
|
+
if (it && it.initiative === from && !it.proposed) { items.push(it); continue; }
|
|
174
|
+
return refuse(400, `${id} is not a task of ${b0.title}`);
|
|
175
|
+
}
|
|
176
|
+
const jira = new Map(jiraOf(F, board, from).map((x) => [x.key, x]));
|
|
177
|
+
for (const k of K) if (!jira.has(k)) return refuse(400, `${k} is not a Jira ticket of ${b0.title}`);
|
|
178
|
+
const docs = Custom.list(w.root, 'initiative:' + from);
|
|
179
|
+
for (const d of D) if (!docs.some((x) => x.id === d)) return refuse(400, `${d} is not a document of ${b0.title}`);
|
|
180
|
+
const at = stageFor(F, board, b0, tasks, items, body.stage);
|
|
181
|
+
if (at.error) return refuse(400, at.error);
|
|
182
|
+
|
|
183
|
+
// the record: same lane and anchor as the one it came from (D59: never unanchored); a taken id gets -2, -3, …
|
|
184
|
+
const fm = fmOf(w.root, b0.record);
|
|
185
|
+
const anchor = fm.parent_kr || b0.anchor || '';
|
|
186
|
+
const input = { title: name, lane: b0.lane || fm.lane || 'feature', anchor };
|
|
187
|
+
if (input.lane === 'chore') input.intent = 'Split from ' + b0.title + '.';
|
|
188
|
+
const base = writer.slugOf(name) || 'split';
|
|
189
|
+
let made = null;
|
|
190
|
+
for (let n = 1; n <= 9 && !made; n++) {
|
|
191
|
+
const r = writer.createInitiative(w.root, { ...input, id: n === 1 ? base : (base.slice(0, 56) + '-' + n) }, { actor });
|
|
192
|
+
if (r.ok) made = r; else if (r.status !== 409) return refuse(r.status || 400, r.error, { field: r.field || null });
|
|
193
|
+
}
|
|
194
|
+
if (!made) return refuse(409, 'an initiative with this name exists already; give it another name');
|
|
195
|
+
const id = made.id, sha = writer.recordSha(w.root, id);
|
|
196
|
+
// the new one sits right after the old one on the Roadmap, in its horizon: a new record lands in Later, so a split of a Now initiative would
|
|
197
|
+
// leave the Board's list (it lists Now and Next). A refused line only leaves it in Later.
|
|
198
|
+
try { Placements.appendFromUi(w.root, [{ ev: 'placed', initiative: id, horizon: ['now', 'next', 'later'].includes(b0.horizon) ? b0.horizon : 'later', after: from }], { actor }); } catch { /* it stays in Later */ }
|
|
199
|
+
const R = F.R, file = F.file, why = 'split from ' + from;
|
|
200
|
+
const op = opId();
|
|
201
|
+
const undo = { tasks: [], items: [], tickets: [], docs: [], program: null, sha };
|
|
202
|
+
try {
|
|
203
|
+
R.append(file, actor, { kind: 'assign', board: board.id, id, to: board.id });
|
|
204
|
+
const k0 = Bm().key(board.id, from);
|
|
205
|
+
const own = folded.iniWf && folded.iniWf.get(k0);
|
|
206
|
+
const oldTpl = folded.iniWorkflows && folded.iniWorkflows.get(k0);
|
|
207
|
+
if (oldTpl) R.append(file, actor, { kind: 'ini-workflow', board: board.id, id, template: oldTpl.template, stages: oldTpl.stages, moved: null });
|
|
208
|
+
if (own) R.append(file, actor, { kind: 'ini-wf', board: board.id, id, wf: own.wf, from: own.wf, moved: null, why });
|
|
209
|
+
if (at.st) R.append(file, actor, { kind: 'move', board: board.id, id, from: null, to: own ? at.st.key : at.st.name, why, warnings: [] });
|
|
210
|
+
for (const t of tasks) { R.append(file, actor, { kind: 'task-update', board: t.board, task: t.id, initiative: id, why }); undo.tasks.push(t.id); }
|
|
211
|
+
undo.items = copyItems(w.root, items, id, actor);
|
|
212
|
+
for (const k of K) { R.append(file, actor, { kind: 'ticket-move', board: board.id, key: k, to: id, why }); undo.tickets.push({ key: k, was: (folded.ticketMoves && folded.ticketMoves.get(k)) || null }); }
|
|
213
|
+
if (D.length) undo.docs = Custom.move(w.root, D, 'initiative:' + id, actor).moved;
|
|
214
|
+
// in a program: the new one joins it and goes right after `from` in the program's order
|
|
215
|
+
const p = programOf(ctx, w, from);
|
|
216
|
+
if (p) {
|
|
217
|
+
progLine(ctx, w.id, { kind: 'member', program: p.id, initiative: id });
|
|
218
|
+
const was = (p.order || []).slice();
|
|
219
|
+
const list0 = was.length ? was.slice() : (p.members || []).map((m) => m.initiative);
|
|
220
|
+
const i = list0.indexOf(from);
|
|
221
|
+
const order = list0.filter((x) => x !== id);
|
|
222
|
+
order.splice(i >= 0 ? i + 1 : order.length, 0, id);
|
|
223
|
+
const v = P.validOrder(order);
|
|
224
|
+
if (!v.error) progLine(ctx, p.home, { kind: 'order', program: p.id, order: v });
|
|
225
|
+
undo.program = { id: p.id, home: p.home, was };
|
|
226
|
+
}
|
|
227
|
+
} catch (e) {
|
|
228
|
+
R.append(file, actor, { kind: 'ini-split', op, board: board.id, id: from, to: id, fromTitle: b0.title, toTitle: name, undo, partial: true });
|
|
229
|
+
R.invalidateRows(w);
|
|
230
|
+
return refuse(500, 'the split stopped part way: ' + String((e && e.message) || e).slice(0, 200) + '. Undo puts back what moved.', { undo: op });
|
|
231
|
+
}
|
|
232
|
+
R.append(file, actor, { kind: 'ini-split', op, board: board.id, id: from, to: id, fromTitle: b0.title, toTitle: name, undo });
|
|
233
|
+
R.invalidateRows(w);
|
|
234
|
+
if (ctx.invalidateNeedsAgg) ctx.invalidateNeedsAgg(w.id);
|
|
235
|
+
return { ok: true, id, title: name, board: board.id, stage: at.st ? at.st.name : null, counts: { tasks: tasks.length + items.length, tickets: K.length, docs: undo.docs.length }, undo: op };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function merge(ctx, w, body, actor) {
|
|
239
|
+
const F = frame(ctx, w); if (F.ok === false) return F;
|
|
240
|
+
const from = String(body.from || ''), into = String(body.into || '');
|
|
241
|
+
if (!from || !into) return refuse(400, 'from and into are required');
|
|
242
|
+
if (from === into) return refuse(400, 'an initiative cannot be merged into itself');
|
|
243
|
+
const a = live(F, from); if (!a.ok) return a;
|
|
244
|
+
const b = live(F, into); if (!b.ok) return refuse(b.status, b.status === 409 ? `${b.error}, so nothing can be merged into it` : b.error);
|
|
245
|
+
if (!a.board || !b.board || a.board.id !== b.board.id) return refuse(409, 'an initiative merges into one on the same board');
|
|
246
|
+
const board = a.board, R = F.R, file = F.file, folded = F.fr.folded;
|
|
247
|
+
if (board.self) return refuse(409, R.SELF_REFUSAL || 'PMOS keeps its derived ladder');
|
|
248
|
+
const fmA = fmOf(w.root, a.b0.record), fmB = fmOf(w.root, b.b0.record);
|
|
249
|
+
let anchor = null;
|
|
250
|
+
if (body.anchor != null && body.anchor !== '') {
|
|
251
|
+
if (!ONE_LINE(body.anchor, 120)) return refuse(400, 'anchor is one line');
|
|
252
|
+
anchor = body.anchor.trim();
|
|
253
|
+
}
|
|
254
|
+
const why = 'merge into ' + into, op = opId();
|
|
255
|
+
const undo = { tasks: [], items: [], epics: null, tickets: [], docs: [], prd: null, chats: [], waits: [], joined: null, anchor: null };
|
|
256
|
+
try {
|
|
257
|
+
if (anchor && anchor !== (fmB.parent_kr || '')) {
|
|
258
|
+
const r = writer.setAnchor(w.root, into, anchor, { actor });
|
|
259
|
+
if (!r.ok) return refuse(r.status || 400, r.error, { field: 'anchor' });
|
|
260
|
+
if (!r.same) undo.anchor = r.from;
|
|
261
|
+
}
|
|
262
|
+
// tasks: the Board tasks move, breakdown items are planned again under `into`
|
|
263
|
+
for (const t of folded.tasks.values()) if (t.initiative === from) { R.append(file, actor, { kind: 'task-update', board: t.board, task: t.id, initiative: into, why }); undo.tasks.push(t.id); }
|
|
264
|
+
undo.items = copyItems(w.root, itemsOfIni(w.root, from), into, actor);
|
|
265
|
+
// Jira: the epic links, then every ticket the Board lists under `from` (drafted ones too)
|
|
266
|
+
const ea = R.epicsOf(a.b0, folded).epics, eb = R.epicsOf(b.b0, folded).epics;
|
|
267
|
+
if (ea.length) {
|
|
268
|
+
R.append(file, actor, { kind: 'ini-epics', board: board.id, id: into, epics: [...new Set([...eb, ...ea])], why: 'merge ' + from });
|
|
269
|
+
R.append(file, actor, { kind: 'ini-epics', board: board.id, id: from, epics: [], why });
|
|
270
|
+
undo.epics = { from: ea, into: eb };
|
|
271
|
+
}
|
|
272
|
+
for (const x of jiraOf(F, board, from)) { R.append(file, actor, { kind: 'ticket-move', board: board.id, key: x.key, to: into, why }); undo.tickets.push({ key: x.key, was: (folded.ticketMoves && folded.ticketMoves.get(x.key)) || null }); }
|
|
273
|
+
// documents: the added ones move; the closing PRD joins the documents of the one that stays (its own PRD stays its PRD)
|
|
274
|
+
const docs = Custom.list(w.root, 'initiative:' + from).map((d) => d.id);
|
|
275
|
+
if (docs.length) undo.docs = Custom.move(w.root, docs, 'initiative:' + into, actor).moved;
|
|
276
|
+
if (fmA.prd_path) {
|
|
277
|
+
const d = Custom.addFile(w.root, { scope: 'initiative:' + into, title: 'PRD · ' + a.b0.title, file: fmA.prd_path }, actor);
|
|
278
|
+
if (d.ok) undo.prd = d.doc.id;
|
|
279
|
+
}
|
|
280
|
+
// open chats follow the work; closed ones stay with the initiative they ran for
|
|
281
|
+
if (ctx.rebindSessions) undo.chats = ctx.rebindSessions(w.id, from, into) || [];
|
|
282
|
+
// program milestones that wait on `from` wait on `into` instead (a milestone never waits on a closed initiative)
|
|
283
|
+
const p = programOf(ctx, w, from);
|
|
284
|
+
if (p) {
|
|
285
|
+
const ms = (p.milestones || []).map((m) => {
|
|
286
|
+
if (!(m.waits || []).includes(from)) return m;
|
|
287
|
+
const had = m.waits.includes(into), st = { ...(m.stages || {}) };
|
|
288
|
+
undo.waits.push({ program: p.id, milestone: m.id, had, stage: st[from] || null });
|
|
289
|
+
if (st[from] && !st[into]) st[into] = st[from];
|
|
290
|
+
delete st[from];
|
|
291
|
+
return { ...m, waits: [...new Set(m.waits.map((x) => (x === from ? into : x)))], stages: st };
|
|
292
|
+
});
|
|
293
|
+
if (undo.waits.length) { const v = P.validProgram({ ...p, milestones: ms }); if (!v.error) progLine(ctx, p.home, v); }
|
|
294
|
+
if (!programOf(ctx, w, into)) { progLine(ctx, w.id, { kind: 'member', program: p.id, initiative: into }); undo.joined = p.id; }
|
|
295
|
+
if (undo.waits.length || undo.joined) undo.program = { id: p.id, home: p.home };
|
|
296
|
+
}
|
|
297
|
+
} catch (e) {
|
|
298
|
+
R.append(file, actor, { kind: 'ini-merge', op, board: board.id, id: from, to: into, fromTitle: a.b0.title, toTitle: b.b0.title, undo, partial: true });
|
|
299
|
+
R.invalidateRows(w);
|
|
300
|
+
return refuse(500, 'the merge stopped part way: ' + String((e && e.message) || e).slice(0, 200) + '. Undo puts back what moved.', { undo: op });
|
|
301
|
+
}
|
|
302
|
+
R.append(file, actor, { kind: 'ini-archive', board: board.id, id: from, archived: true, into, reason: 'Merged into ' + b.b0.title, moved: { epics: undo.epics ? undo.epics.from : [], tasks: undo.tasks }, op });
|
|
303
|
+
R.append(file, actor, { kind: 'ini-merge', op, board: board.id, id: from, to: into, fromTitle: a.b0.title, toTitle: b.b0.title, undo });
|
|
304
|
+
R.invalidateRows(w);
|
|
305
|
+
if (ctx.invalidateNeedsAgg) ctx.invalidateNeedsAgg(w.id);
|
|
306
|
+
return { ok: true, from, into, title: b.b0.title, counts: { tasks: undo.tasks.length + undo.items.length, tickets: undo.tickets.length, docs: undo.docs.length + (fmA.prd_path ? 1 : 0), chats: undo.chats.length, milestones: undo.waits.length }, undo: op };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Breakdown items back where they came from: the copies (still open) are planned again under `to` and withdrawn. */
|
|
310
|
+
function itemsBack(root, pairs, to, actor) {
|
|
311
|
+
const list = pairs.map((x) => openItem(root, x.to)).filter(Boolean);
|
|
312
|
+
return copyItems(root, list, to, actor).length;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function undo(ctx, w, body, actor) {
|
|
316
|
+
const F = frame(ctx, w); if (F.ok === false) return F;
|
|
317
|
+
const op = String(body.undo || '');
|
|
318
|
+
const line = F.fr.folded.smOps && F.fr.folded.smOps.get(op);
|
|
319
|
+
if (!line) return refuse(404, 'nothing to undo for that press');
|
|
320
|
+
if (F.fr.folded.smUndone.has(op)) return refuse(409, 'that is undone already');
|
|
321
|
+
const R = F.R, file = F.file, folded = F.fr.folded, u = line.undo || {};
|
|
322
|
+
const from = line.id, to = line.to, why = 'undo ' + (line.kind === 'ini-split' ? 'split' : 'merge');
|
|
323
|
+
// the tasks, the tickets and the documents go back, unless the PM moved one on since
|
|
324
|
+
for (const tid of u.tasks || []) { const t = Bm().taskOf(folded, tid); if (t && t.initiative === to) R.append(file, actor, { kind: 'task-update', board: t.board, task: tid, initiative: from, why }); }
|
|
325
|
+
itemsBack(w.root, u.items || [], from, actor);
|
|
326
|
+
for (const x of u.tickets || []) if ((folded.ticketMoves && folded.ticketMoves.get(x.key)) === to) R.append(file, actor, { kind: 'ticket-move', board: line.board, key: x.key, to: x.was || null, why });
|
|
327
|
+
const back = (u.docs || []).filter((d) => Custom.list(w.root, 'initiative:' + to).some((x) => x.id === d.id));
|
|
328
|
+
for (const d of back) Custom.move(w.root, [d.id], d.from, actor);
|
|
329
|
+
let note = '';
|
|
330
|
+
if (line.kind === 'ini-split') {
|
|
331
|
+
const p = u.program;
|
|
332
|
+
if (p) { progLine(ctx, w.id, { kind: 'leave', program: p.id, initiative: to }); progLine(ctx, p.home, { kind: 'order', program: p.id, order: P.validOrder(p.was || []) }); }
|
|
333
|
+
const r = writer.withdrawSplit(w.root, to, u.sha, { actor });
|
|
334
|
+
if (!r.ok || !r.removed) { R.append(file, actor, { kind: 'ini-archive', board: line.board, id: to, archived: true, reason: 'Split undone' }); note = r.edited ? 'archived' : ''; }
|
|
335
|
+
} else {
|
|
336
|
+
if (u.epics) {
|
|
337
|
+
R.append(file, actor, { kind: 'ini-epics', board: line.board, id: to, epics: u.epics.into, why });
|
|
338
|
+
R.append(file, actor, { kind: 'ini-epics', board: line.board, id: from, epics: u.epics.from, why });
|
|
339
|
+
}
|
|
340
|
+
if (u.prd) Custom.drop(w.root, u.prd, actor);
|
|
341
|
+
if (u.chats && u.chats.length && ctx.rebindSessions) ctx.rebindSessions(w.id, to, from, u.chats);
|
|
342
|
+
if (u.anchor) writer.setAnchor(w.root, to, u.anchor, { actor });
|
|
343
|
+
if (u.program) {
|
|
344
|
+
let all = []; try { all = Progs().all(ctx); } catch { all = []; }
|
|
345
|
+
const p = all.find((x) => x.id === u.program.id);
|
|
346
|
+
if (p && u.waits && u.waits.length) {
|
|
347
|
+
const ms = (p.milestones || []).map((m) => {
|
|
348
|
+
const x = u.waits.find((y) => y.milestone === m.id && y.program === p.id);
|
|
349
|
+
if (!x) return m;
|
|
350
|
+
const st = { ...(m.stages || {}) };
|
|
351
|
+
if (x.stage) st[from] = x.stage;
|
|
352
|
+
const waits = m.waits.filter((y) => y !== to || x.had);
|
|
353
|
+
if (!x.had) delete st[to];
|
|
354
|
+
return { ...m, waits: [...new Set([...waits, from])], stages: st };
|
|
355
|
+
});
|
|
356
|
+
const v = P.validProgram({ ...p, milestones: ms }); if (!v.error) progLine(ctx, p.home, v);
|
|
357
|
+
}
|
|
358
|
+
if (u.joined) progLine(ctx, w.id, { kind: 'leave', program: u.joined, initiative: to });
|
|
359
|
+
}
|
|
360
|
+
R.append(file, actor, { kind: 'ini-archive', board: line.board, id: from, archived: false, op });
|
|
361
|
+
}
|
|
362
|
+
R.append(file, actor, { kind: 'ini-sm-undo', board: line.board, op });
|
|
363
|
+
R.invalidateRows(w);
|
|
364
|
+
if (ctx.invalidateNeedsAgg) ctx.invalidateNeedsAgg(w.id);
|
|
365
|
+
return { ok: true, kind: line.kind === 'ini-split' ? 'split' : 'merge', from, to, fromTitle: line.fromTitle, toTitle: line.toTitle, ...(note ? { note } : {}) };
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** ✕ Not now on Claude's suggestion: hidden until the tasks or tickets it was made from change (a new fingerprint). */
|
|
369
|
+
function dismiss(ctx, w, body, actor) {
|
|
370
|
+
const R = Boards(), file = R.ledgerFile(ctx, w);
|
|
371
|
+
if (!file) return refuse(409, R.NO_STATE || 'this workspace has no state folder');
|
|
372
|
+
const id = String(body.id || ''), fp = String(body.fp || '');
|
|
373
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/.test(id)) return refuse(400, 'id names an initiative');
|
|
374
|
+
if (!/^[0-9a-f]{8,64}$/.test(fp)) return refuse(400, 'fp is the suggestion\'s fingerprint');
|
|
375
|
+
R.append(file, actor, { kind: 'ini-suggest', id, of: body.of === 'merge' ? 'merge' : 'split', fp, answer: 'dismiss' });
|
|
376
|
+
return { ok: true };
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
module.exports = { split, merge, undo, dismiss, fmOf };
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* pmos task add <initiative> "<title>" [--stage <stage>] [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]
|
|
6
6
|
* a new task, by the same function as the page's Add a task (lib/routes-boards.js taskAdd, POST /api/boards/tasks/add)
|
|
7
7
|
* pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start …|none] [--owner <who>] [--notes <text>]
|
|
8
|
+
* [--milestone|--no-milestone]
|
|
8
9
|
* place tasks under a workflow stage of their initiative, or change their dates, owner or notes, by the same function as the Viewer's
|
|
9
10
|
* edit (lib/routes-boards.js taskEdit, POST /api/boards/tasks/edit). The Tasks section groups tasks by stage (feedback batch 6:
|
|
10
11
|
* an agent asked to group tasks by stage had no command for it).
|
|
@@ -12,6 +13,10 @@
|
|
|
12
13
|
* pmos task state <task> [<task> …] --to <state> [--why <text>]
|
|
13
14
|
* set each task's state: To do, In progress, Done, Won't do or Archived, by the same function as the Board's press
|
|
14
15
|
* (lib/routes-boards.js taskState, POST /api/boards/tasks/state), with the agent as the writer.
|
|
16
|
+
* pmos task link <from> <to> [--type fs|ss|ff|sf] [--lag <days>] [--propose --why <text>]
|
|
17
|
+
* pmos task unlink <from> <to>
|
|
18
|
+
* <to> waits on <from> (feedback batch 11 item 15, lib/task-links.js): a link only when the PM asks in chat; --propose files it for the
|
|
19
|
+
* PM to approve on the page instead. A date changed by `set` moves what waits on the task quietly, inside the approved links.
|
|
15
20
|
*
|
|
16
21
|
* ONE KIND OF TASK. The list holds the initiative's Board tasks, its breakdown items (the plan-items ledger, lib/task-items.js) and its
|
|
17
22
|
* current stage's To finish entries, which become tasks the first time they are read (routes-boards stageTasks). `state` closes any of
|
|
@@ -27,13 +32,15 @@ const B = require(repoScript('boards.js'));
|
|
|
27
32
|
const TI = require('./task-items.js');
|
|
28
33
|
const rowsLib = require('./initiative-rows.js');
|
|
29
34
|
|
|
30
|
-
const COMMANDS = { task: ['add', 'list', 'state', 'set', 'remove'] };
|
|
35
|
+
const COMMANDS = { task: ['add', 'list', 'state', 'set', 'remove', 'link', 'unlink'] };
|
|
31
36
|
const USAGE = [
|
|
32
37
|
'usage: pmos task add|list|state|set|remove — an initiative\'s tasks, the ones the PM sees in its Tasks section',
|
|
33
38
|
' pmos task add <initiative> "<title>" [--stage <stage>] [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]',
|
|
34
39
|
' Add a task. Every new task goes here; pmos item add is the older breakdown record.',
|
|
35
40
|
' pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start YYYY-MM-DD|none] [--owner <who>] [--notes <text>]',
|
|
41
|
+
' [--milestone|--no-milestone]',
|
|
36
42
|
' Group tasks under a stage of the initiative\'s workflow (key or name; none takes it out), or change dates, owner or notes.',
|
|
43
|
+
' --milestone makes a task a milestone: its due date shows as ◇ on the Board and the timeline. Set it only when the PM asks.',
|
|
37
44
|
' pmos task list <initiative> [--all] its open tasks; --all adds Done, Won\'t do and Archived',
|
|
38
45
|
' pmos task remove <task> [<task> …] [--why <text>]',
|
|
39
46
|
' Delete a task added by mistake (a placeholder, a duplicate) when the PM asks. It goes from every list; the page\'s Undo brings',
|
|
@@ -44,11 +51,16 @@ const USAGE = [
|
|
|
44
51
|
' There is one kind of task: Board tasks, breakdown items and the current stage\'s To finish tasks all list and close here.',
|
|
45
52
|
' The Tasks section groups tasks by the workflow\'s stages: --stage places a task there. It never changes the task\'s state or',
|
|
46
53
|
' moves the initiative. Move the initiative with pmos workflow move.',
|
|
54
|
+
' pmos task link <from> <to> [--type fs|ss|ff|sf] [--lag <days>] [--propose --why <text>]',
|
|
55
|
+
' <to> waits on <from>: fs finish → start (the default), ss start → start, ff finish → finish, sf start → finish; --lag adds days.',
|
|
56
|
+
' Link only when the PM asks. Else --propose: the PM approves it with ✓ on the page. A loop is refused. Moving a task later',
|
|
57
|
+
' moves what waits on it just enough; a ◇ milestone, another initiative\'s task or a Jira ticket waits for the PM instead.',
|
|
58
|
+
' pmos task unlink <from> <to>',
|
|
47
59
|
' every command: [--json] [--root <dir>]. Nothing is sent.',
|
|
48
60
|
];
|
|
49
|
-
const BOOL = new Set(['json', 'help', 'all']);
|
|
50
|
-
const VALUE = new Set(['to', 'why', 'root', 'due', 'start', 'owner', 'notes', 'stage']);
|
|
51
|
-
const ONLY = { add: ['due', 'start', 'owner', 'notes', 'stage'], list: ['all'], state: ['to', 'why'], remove: ['why'], set: ['due', 'start', 'owner', 'notes', 'stage'] };
|
|
61
|
+
const BOOL = new Set(['json', 'help', 'all', 'milestone', 'no-milestone', 'propose']);
|
|
62
|
+
const VALUE = new Set(['to', 'why', 'root', 'due', 'start', 'owner', 'notes', 'stage', 'type', 'lag']);
|
|
63
|
+
const ONLY = { add: ['due', 'start', 'owner', 'notes', 'stage'], list: ['all'], state: ['to', 'why'], remove: ['why'], set: ['due', 'start', 'owner', 'notes', 'stage'], link: ['type', 'lag', 'why'], unlink: [] };
|
|
52
64
|
const OPEN = new Set(['To do', 'In progress']);
|
|
53
65
|
/** The PM's words for a state: any case, with or without the apostrophe or the space. */
|
|
54
66
|
function stateOf(s) {
|
|
@@ -90,7 +102,7 @@ function boardsCtx(root, stateDir) {
|
|
|
90
102
|
const w = { id: driver.wsIdOf(root), name: path.basename(root), root };
|
|
91
103
|
return { w, ctx: { getWs: () => w, workspaceList: () => [w], stateDirFor: () => stateDir, selfRoot: path.resolve(__dirname, '..', '..') } };
|
|
92
104
|
}
|
|
93
|
-
const line = (t) => `${t.id} · ${t.state} · ${t.title}${t.kind === 'Epic' ? ' (epic)' : ''}${t.stage ? ' · under ' + t.stage : ''}${t.due ? ' · due ' + t.due : ''}`;
|
|
105
|
+
const line = (t) => `${t.id} · ${t.state} · ${t.title}${t.kind === 'Epic' ? ' (epic)' : ''}${t.milestone ? ' · ◇ milestone' : ''}${t.stage ? ' · under ' + t.stage : ''}${t.due ? ' · due ' + t.due : ''}`;
|
|
94
106
|
/** The workflow row of an initiative, deriving the rows when they are still being read. */
|
|
95
107
|
function rowOf(boards, ctx, w, id) {
|
|
96
108
|
let r = boards.initiativeWorkflow(ctx, w, id);
|
|
@@ -114,6 +126,9 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
114
126
|
const fail = (error, code = 1) => { if (json) say(JSON.stringify({ ok: false, error })); else say(`✗ ${error}`); return code; };
|
|
115
127
|
for (const k of Object.keys(flags)) if (VALUE.has(k) && k !== 'root' && !ONLY[verb].includes(k)) return fail(`--${k} is not an option of ${verb}`, 2);
|
|
116
128
|
if (flags.all && verb !== 'list') return fail(`--all is not an option of ${verb}`, 2);
|
|
129
|
+
for (const k of ['milestone', 'no-milestone']) if (flags[k] && verb !== 'set') return fail(`--${k} is not an option of ${verb}`, 2);
|
|
130
|
+
if (flags.milestone && flags['no-milestone']) return fail('--milestone and --no-milestone contradict each other', 2);
|
|
131
|
+
if (flags.propose && verb !== 'link') return fail(`--propose is not an option of ${verb}`, 2);
|
|
117
132
|
const root = flags.root ? path.resolve(cwd, flags.root) : repoRoot(cwd);
|
|
118
133
|
const stateDir = driver.stateDirOf(root, { create: verb !== 'list' });
|
|
119
134
|
if (!stateDir) return fail('this repository has no PMOS state folder (pmos/state, state or .pmos)');
|
|
@@ -126,10 +141,11 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
126
141
|
const tasksOf = (id) => {
|
|
127
142
|
const r = rowOf(boards, ctx, w, id);
|
|
128
143
|
const board = r.ok ? r.board.id : null;
|
|
129
|
-
const F = boards.foldOf(ctx, w), S = F.sections || new Map();
|
|
144
|
+
const F = boards.foldOf(ctx, w), S = F.sections || new Map(), MS = F.milestones || new Map();
|
|
145
|
+
const msOf = (tid, own) => (MS.has(tid) ? MS.get(tid) : !!own); // the PM's ◇ flag (feedback batch 11 item 3)
|
|
130
146
|
const stageOf = (tid, from) => (S.has(tid) ? S.get(tid) : (from && from.stage) || ''); // the group the Tasks section shows it under
|
|
131
|
-
const own = [...(F.tasks || new Map()).values()].filter((t) => t.initiative === id).map((t) => ({ ...t, stage: stageOf(t.id, t.from) }));
|
|
132
|
-
const items = TI.rowsOf(root, new Set([id]), board).map((x) => ({ id: x.uid, board, kind: 'Task', title: x.title, state: x.status, owner: x.owner, due: x.end, store: 'item', stage: stageOf(x.uid) }));
|
|
147
|
+
const own = [...(F.tasks || new Map()).values()].filter((t) => t.initiative === id).map((t) => ({ ...t, stage: stageOf(t.id, t.from), milestone: msOf(t.id) }));
|
|
148
|
+
const items = TI.rowsOf(root, new Set([id]), board).map((x) => ({ id: x.uid, board, kind: 'Task', title: x.title, state: x.status, owner: x.owner, due: x.end, store: 'item', stage: stageOf(x.uid), milestone: msOf(x.uid, x.milestone) }));
|
|
133
149
|
return own.concat(items);
|
|
134
150
|
};
|
|
135
151
|
|
|
@@ -160,7 +176,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
160
176
|
try { boards.seedInitiative(ctx, w, id); } catch { /* the To finish tasks are made on the next read */ }
|
|
161
177
|
const all = tasksOf(id);
|
|
162
178
|
const shown = flags.all ? all : all.filter((t) => OPEN.has(t.state));
|
|
163
|
-
if (json) { say(JSON.stringify({ ok: true, tasks: shown.map((t) => ({ id: t.id, board: t.board, kind: t.kind, title: t.title, state: t.state, owner: t.owner, due: t.due, stage: t.stage || '', ...(t.from ? { from: t.from } : {}) })) })); return 0; }
|
|
179
|
+
if (json) { say(JSON.stringify({ ok: true, tasks: shown.map((t) => ({ id: t.id, board: t.board, kind: t.kind, title: t.title, state: t.state, owner: t.owner, due: t.due, stage: t.stage || '', ...(t.milestone ? { milestone: true } : {}), ...(t.from ? { from: t.from } : {}) })) })); return 0; }
|
|
164
180
|
if (!shown.length) { say(all.length ? `No open task on ${id}. --all lists the ${all.length} closed.` : `No task on ${id}.`); return 0; }
|
|
165
181
|
for (const t of shown) say(line(t));
|
|
166
182
|
return 0;
|
|
@@ -178,8 +194,8 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
178
194
|
};
|
|
179
195
|
|
|
180
196
|
if (verb === 'set') {
|
|
181
|
-
const keys = ['stage', 'due', 'start', 'owner', 'notes'].filter((k) => flags[k] !== undefined);
|
|
182
|
-
if (!pos.length || !keys.length) { say('usage: pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start YYYY-MM-DD|none] [--owner <who>] [--notes <text>]'); return 2; }
|
|
197
|
+
const keys = ['stage', 'due', 'start', 'owner', 'notes'].filter((k) => flags[k] !== undefined).concat(flags.milestone || flags['no-milestone'] ? ['milestone'] : []);
|
|
198
|
+
if (!pos.length || !keys.length) { say('usage: pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start YYYY-MM-DD|none] [--owner <who>] [--notes <text>] [--milestone|--no-milestone]'); return 2; }
|
|
183
199
|
const folded = boards.foldOf(ctx, w);
|
|
184
200
|
const done = [], refused = [];
|
|
185
201
|
for (const id of pos) {
|
|
@@ -195,15 +211,23 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
195
211
|
}
|
|
196
212
|
for (const k of ['due', 'start']) if (flags[k] !== undefined) body[k] = String(flags[k]).toLowerCase() === 'none' ? '' : flags[k];
|
|
197
213
|
for (const k of ['owner', 'notes']) if (flags[k] !== undefined) body[k] = flags[k];
|
|
214
|
+
if (flags.milestone || flags['no-milestone']) body.milestone = !!flags.milestone;
|
|
198
215
|
const e = boards.taskEdit(ctx, body, g);
|
|
199
216
|
if (!e.body || e.body.ok !== true) refused.push({ task: id, error: (e.body && e.body.error) || 'the write was refused' });
|
|
200
217
|
else done.push({ task: id, title: t.title, set: Object.fromEntries(keys.map((k) => [k, k === 'stage' ? body.section : body[k]])) });
|
|
201
218
|
}
|
|
202
|
-
const what = (x) => Object.entries(x).map(([k, v]) => (k === 'stage' ? (v ? 'under ' + v : 'under no stage') : v === '' ? 'no ' + k : k + ' ' + v)).join(', ');
|
|
203
|
-
|
|
219
|
+
const what = (x) => Object.entries(x).map(([k, v]) => (k === 'stage' ? (v ? 'under ' + v : 'under no stage') : k === 'milestone' ? (v ? 'a milestone' : 'not a milestone') : v === '' ? 'no ' + k : k + ' ' + v)).join(', ');
|
|
220
|
+
// a date changed outside a drag: inside the approved links, what waits on it moves quietly (batch 11 item 15, the grey ✦ on the page)
|
|
221
|
+
let kept = 0;
|
|
222
|
+
if (done.length && (flags.due !== undefined || flags.start !== undefined)) {
|
|
223
|
+
const TLR = require('./routes-task-links.js'), F2 = boards.foldOf(ctx, w), seen = new Set();
|
|
224
|
+
for (const d of done) { const t = findTask(F2, d.task); const k = t ? t.board + '|' + t.initiative : ''; if (!t || seen.has(k)) continue; seen.add(k); kept += TLR.sweepFor(ctx, w, t.board, t.initiative, g).moved || 0; }
|
|
225
|
+
}
|
|
226
|
+
if (json) say(JSON.stringify({ ok: !refused.length, done, refused, ...(kept ? { moved: kept } : {}) }));
|
|
204
227
|
else {
|
|
205
228
|
for (const d of done) say(`✓ ${d.task} ${what(d.set)}: ${d.title}`);
|
|
206
229
|
for (const x of refused) say(`✗ ${x.task}: ${x.error}`);
|
|
230
|
+
if (kept) say(` Kept the links: ${kept === 1 ? '1 task that waits on it moved' : kept + ' tasks that wait on it moved'}. The page lists them under the grey ✦.`);
|
|
207
231
|
if (done.length) say(' The page shows it. Nothing was sent.');
|
|
208
232
|
}
|
|
209
233
|
return refused.length ? 1 : 0;
|
|
@@ -230,6 +254,42 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
230
254
|
return refused.length ? 1 : 0;
|
|
231
255
|
}
|
|
232
256
|
|
|
257
|
+
if (verb === 'link' || verb === 'unlink') {
|
|
258
|
+
// batch 11 item 15: <to> waits on <from>; the same writer as the page's link (lib/task-links.js)
|
|
259
|
+
if (pos.length !== 2) { say(verb === 'link' ? 'usage: pmos task link <from> <to> [--type fs|ss|ff|sf] [--lag <days>] [--propose --why <text>]' : 'usage: pmos task unlink <from> <to>'); return 2; }
|
|
260
|
+
const TL = require('./task-links.js'), TLR = require('./routes-task-links.js');
|
|
261
|
+
const [from, to] = pos, folded = boards.foldOf(ctx, w);
|
|
262
|
+
const t = findTask(folded, to) || findTask(folded, from);
|
|
263
|
+
if (!t) return fail(`no task ${to} or ${from}; pmos task list <initiative> names them`);
|
|
264
|
+
const board = (boards.frameFor(ctx, w).boards || []).find((b) => b.id === t.board);
|
|
265
|
+
const fr = board ? TLR.frame(ctx, w, board, { derive: true }) : null;
|
|
266
|
+
if (!fr) return fail('the board is still being read: try again in a moment');
|
|
267
|
+
for (const u of [from, to]) if (!fr.T.has(u)) return fail(`no task ${u} on the board ${t.board}`);
|
|
268
|
+
const F = TL.read(stateDir);
|
|
269
|
+
if (verb === 'unlink') {
|
|
270
|
+
if (!F.links.has(TL.keyOf(from, to))) return fail(`${to} does not wait on ${from}`);
|
|
271
|
+
TL.append(stateDir, g.actor, { kind: 'unlink', from, to });
|
|
272
|
+
if (json) say(JSON.stringify({ ok: true, unlinked: { from, to } })); else say(`✓ ${to} no longer waits on ${from}. The page shows it. Nothing was sent.`);
|
|
273
|
+
return 0;
|
|
274
|
+
}
|
|
275
|
+
const c = TL.cleanLink({ from, to, type: flags.type, lag: flags.lag });
|
|
276
|
+
if (c.error) return fail(c.error, 2);
|
|
277
|
+
if (TL.loops(TL.linksOf(F).filter((l) => TL.keyOf(l.from, l.to) !== TL.keyOf(to, from)), from, to)) return fail(TLR.LOOP);
|
|
278
|
+
const ini = fr.T.get(to).ini || fr.T.get(from).ini;
|
|
279
|
+
if (flags.propose) {
|
|
280
|
+
const why = typeof flags.why === 'string' ? flags.why.trim().slice(0, 200) : '';
|
|
281
|
+
if (!why) return fail('--propose needs --why: one line on what says the order (the PRD line, the meeting)', 2);
|
|
282
|
+
TL.append(stateDir, g.actor, { kind: 'propose', board: t.board, ini, ...c.link, source: 'agent', why });
|
|
283
|
+
if (json) say(JSON.stringify({ ok: true, proposed: { ...c.link } })); else say(`✓ proposed: ${to} waits on ${from} (${TL.TYPE_WORDS[c.link.type]}). The PM approves it with ✓ under the blue ✦ in Tasks. Nothing was sent.`);
|
|
284
|
+
return 0;
|
|
285
|
+
}
|
|
286
|
+
TL.append(stateDir, g.actor, { kind: 'link', board: t.board, ini, ...c.link, source: 'chat' });
|
|
287
|
+
const kept = TLR.sweepFor(ctx, w, t.board, ini, g).moved || 0;
|
|
288
|
+
if (json) say(JSON.stringify({ ok: true, linked: { ...c.link }, ...(kept ? { moved: kept } : {}) }));
|
|
289
|
+
else say(`✓ ${to} waits on ${from} (${TL.TYPE_WORDS[c.link.type]}${c.link.lag ? ', ' + (c.link.lag > 0 ? '+' : '') + c.link.lag + 'd' : ''}).${kept ? ` ${kept === 1 ? '1 task' : kept + ' tasks'} moved to keep it.` : ''} The page shows it. Nothing was sent.`);
|
|
290
|
+
return 0;
|
|
291
|
+
}
|
|
292
|
+
|
|
233
293
|
// state
|
|
234
294
|
if (!pos.length || !flags.to) { say('usage: pmos task state <task> [<task> …] --to <state> [--why <text>]'); return 2; }
|
|
235
295
|
const to = stateOf(flags.to);
|
|
@@ -9,11 +9,14 @@
|
|
|
9
9
|
* rowsOf(root, ids, board) → the items of those initiatives as work items (routes-boards itemsOf's shape, src 'pmos', store 'item')
|
|
10
10
|
* itemOf(root, id) → the folded item, or null (a withdrawn item is gone: it was Won't do)
|
|
11
11
|
* stateEvents(it, state, why) → the plan-items lines that set a task state: a move, or a withdraw for Won't do and Archived
|
|
12
|
+
* deleteEvents(it, why) · restoreEvents(id) → a Delete (a withdraw with why "deleted") and its Undo (batch 11 item 16)
|
|
13
|
+
* goneOf(root, id) → a withdrawn item as it was, or null: what a restore brings back
|
|
12
14
|
* editEvents(it, edit) → the lines of a rename, a reschedule or the Viewer's edits (title, owner, notes, start, due)
|
|
13
15
|
* write(root, events, actor, cli) → the plan-items writer's answer: appendFromCli for a `pmos` call (cli: { isTTY, env }), else appendFromUi
|
|
14
16
|
*
|
|
15
17
|
* The item keeps its store: its start and due still feed the timeline exactly as before (lib/board-fold.js, lib/item-spans.js), and
|
|
16
|
-
* `pmos item list` reads the same fold. Won't do is a withdraw,
|
|
18
|
+
* `pmos item list` reads the same fold. Won't do is a withdraw, so a closed item leaves the list; a Delete is a withdraw too, and its Undo
|
|
19
|
+
* is a `restored` line. */
|
|
17
20
|
const planItems = require('./plan-items.js');
|
|
18
21
|
const actorLib = require('./actor.js');
|
|
19
22
|
|
|
@@ -44,6 +47,9 @@ function itemsById(root) {
|
|
|
44
47
|
function itemOf(root, id) {
|
|
45
48
|
try { return planItems.readFold(root).items[id] || null; } catch { return null; }
|
|
46
49
|
}
|
|
50
|
+
function goneOf(root, id) {
|
|
51
|
+
try { return (planItems.readFold(root).withdrawnItems || {})[id] || null; } catch { return null; }
|
|
52
|
+
}
|
|
47
53
|
|
|
48
54
|
/** The breakdown items of the initiatives in `ids` (a Set), as work items. A proposed item is not a task yet. */
|
|
49
55
|
function rowsOf(root, ids, board) {
|
|
@@ -54,7 +60,7 @@ function rowsOf(root, ids, board) {
|
|
|
54
60
|
const it = f.items[id];
|
|
55
61
|
if (!it || it.proposed || !ids.has(it.initiative)) continue;
|
|
56
62
|
out.push({ uid: it.id, key: '', kind: 'Task', src: 'pmos', store: 'item', title: it.title, status: STATE_OF[it.state] || 'To do', blocked: !!it.blocked, owner: ownerName(it.owner),
|
|
57
|
-
notes: it.note || '', ini: it.initiative, epic: null, start: it.start || null, end: it.due || null, ref: it.id, board,
|
|
63
|
+
notes: it.note || '', ini: it.initiative, epic: null, start: it.start || null, end: it.due || null, ref: it.id, board, ...(it.milestone ? { milestone: true } : {}),
|
|
58
64
|
// the breakdown's own stage (plan-tree) and order: the one view places the item in the workflow stage of the same name
|
|
59
65
|
...(it.stage ? { itemStage: it.stage } : {}), ...(Number.isFinite(it.order) ? { order: it.order } : {}) });
|
|
60
66
|
}
|
|
@@ -73,6 +79,12 @@ function stateEvents(it, state, why) {
|
|
|
73
79
|
return { events: [ev] };
|
|
74
80
|
}
|
|
75
81
|
|
|
82
|
+
/** A Delete takes the item out of every list and every count; restoreEvents is its Undo, and the item comes back as it was. */
|
|
83
|
+
function deleteEvents(it, why) {
|
|
84
|
+
return { events: [{ ev: 'withdrawn', item: it.id, why: (typeof why === 'string' && why.trim() ? why.trim().replace(/\s+/g, ' ').slice(0, 200) : 'deleted') }] };
|
|
85
|
+
}
|
|
86
|
+
function restoreEvents(id) { return { events: [{ ev: 'restored', item: id }] }; }
|
|
87
|
+
|
|
76
88
|
/** edit: { title?, owner?, notes?, start?, due? } with '' clearing a day or the notes. → { events } | { error } */
|
|
77
89
|
function editEvents(it, edit) {
|
|
78
90
|
const fields = {};
|
|
@@ -89,4 +101,4 @@ function write(root, events, actor, cli) {
|
|
|
89
101
|
return planItems.appendFromUi(root, events, { actor: actor && actor.by ? { by: actor.by, via: 'ui' } : undefined });
|
|
90
102
|
}
|
|
91
103
|
|
|
92
|
-
module.exports = { STATE_OF, isItemId, ownerName, ownerOf, itemOf, itemsById, rowsOf, stateEvents, editEvents, write };
|
|
104
|
+
module.exports = { STATE_OF, isItemId, ownerName, ownerOf, itemOf, goneOf, itemsById, rowsOf, stateEvents, deleteEvents, restoreEvents, editEvents, write };
|