create-pmos 0.422.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 +13 -13
- 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/state/discoveries.md +1 -1
- package/workspace/board-programs-test.js +28 -0
- package/workspace/briefing-premium-adddoc-test.js +1 -1
- package/workspace/briefing-premium-board-test.js +12 -10
- package/workspace/briefing-premium-initiative-test.js +30 -38
- package/workspace/changelog.json +12 -0
- package/workspace/guide/briefing-premium.md +1 -1
- package/workspace/guide/home.md +9 -2
- package/workspace/guide/programs.md +1 -0
- package/workspace/guide/workflows.md +5 -1
- package/workspace/ini-workflow-test.js +4 -4
- package/workspace/lib/board-premium.js +3 -2
- package/workspace/lib/custom-docs.js +65 -3
- package/workspace/lib/engine/boards.js +25 -2
- package/workspace/lib/initiative-writer.js +63 -1
- package/workspace/lib/plan-items.js +36 -5
- package/workspace/lib/programs.js +11 -3
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-board-premium.js +22 -0
- package/workspace/lib/routes-boards.js +50 -10
- package/workspace/lib/routes-initiatives.js +12 -0
- package/workspace/lib/routes-task-links.js +329 -0
- package/workspace/lib/split-merge-suggest.js +162 -0
- package/workspace/lib/split-merge.js +379 -0
- package/workspace/lib/task-cli.js +58 -5
- package/workspace/lib/task-items.js +14 -2
- package/workspace/lib/task-links.js +422 -0
- 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-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-panel-test.js +1 -1
- package/workspace/public/pm/bd-ini-panel.js +16 -6
- package/workspace/public/pm/bd-prog.js +6 -1
- package/workspace/public/pm/bd-span.js +69 -15
- package/workspace/public/pm/bd-views.js +3 -2
- package/workspace/public/pm/cozy-board.css +10 -0
- package/workspace/public/pm/home-app.js +25 -8
- package/workspace/public/pm/home-ini-model.js +0 -34
- package/workspace/public/pm/home-ini.js +72 -204
- 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 +58 -22
- package/workspace/public/pm/ini-versions.js +14 -9
- package/workspace/public/pm/ini-view-model.js +88 -4
- package/workspace/public/pm/ini-view.css +259 -18
- package/workspace/public/pm/ini-view.js +140 -32
- package/workspace/public/pm/premium-board.js +54 -6
- 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.js +5 -3
- 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 +1 -1
- package/workspace/task-plans-test.js +6 -0
- package/workspace/task-views-test.js +1 -1
- package/workspace/test-lists/bd-ini-panel.json +8 -2
- package/workspace/test-lists/product-lane.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/tk-tasks-test.js +173 -57
- package/workspace/workflows-setup-test.js +4 -3
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-task-links.js — links between tasks that move together (feedback batch 11 item 15; canvas In development, row "Task
|
|
3
|
+
* dependencies"). The fold, the engine and the writer are lib/task-links.js; a task's dates change only through the board's own task edit
|
|
4
|
+
* (routes-boards taskEdit: boards.jsonl, or the plan-items ledger for a breakdown item). A Jira ticket is never written.
|
|
5
|
+
*
|
|
6
|
+
* GET /api/task-links?ws&board&initiative → { ok, links } links: lib/task-links.js viewOf (null: nothing to show)
|
|
7
|
+
* POST /api/task-links/link { ws, board, from, to, type?, lag?, source? } → { ok, from?, moved, cant, batch?, links }
|
|
8
|
+
* a link the PM made (drag a dot onto a bar's end, the search, the joint card's type and lag: the same
|
|
9
|
+
* pair again). Refused when it would loop back. What waits moves just enough at once (the PM's own act);
|
|
10
|
+
* `from` is the link as it was (Undo sends it back, or unlinks a new one)
|
|
11
|
+
* POST /api/task-links/unlink { ws, board, from, to } → { ok, from } `from`: the link as it was, for Undo
|
|
12
|
+
* POST /api/task-links/move { ws, board, task, start?, due? } → { ok, item, moved, cant, asks, batch?, pulled? }
|
|
13
|
+
* the PM's own move (a drag, the date picker) of a task with links: its dates, then what waits on it moves
|
|
14
|
+
* just enough; moving earlier moves nothing and files "Pull N tasks in" (pulled: the count)
|
|
15
|
+
* POST /api/task-links/accept { ws, board, initiative, ids: [id] } → { ok, linked, moved, batch?, links } ✓ or Add all
|
|
16
|
+
* POST /api/task-links/drop { ws, board, initiative, id } → { ok } ✕: a proposal or a recommendation, for good (same source)
|
|
17
|
+
* POST /api/task-links/ask { ws, board, initiative, id, answer: 'yes' | 'no' } → { ok, moved?, outbox?, batch? } Needs you
|
|
18
|
+
* POST /api/task-links/undo { ws, board, batch } → { ok, back, kept } Undo / Undo all (kept: a task changed since, left as it is)
|
|
19
|
+
* POST /api/task-links/sweep { ws, board, initiative } → { ok, moved, links } the quiet moves: when the Tasks section opens
|
|
20
|
+
* POST /api/task-links/quiet { ws, board, initiative, on } → { ok } · /seen { ws, board, initiative } → { ok }
|
|
21
|
+
*
|
|
22
|
+
* sweepFor(ctx, w, boardId, ini, g) the quiet pass, outside HTTP (`pmos task set` after a date change: a date changed outside a drag)
|
|
23
|
+
*
|
|
24
|
+
* Every POST passes pm-guard requirePagePress. With no state folder the read answers no links and every write answers 409. */
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const path = require('path');
|
|
27
|
+
const guard = require('./pm-guard.js');
|
|
28
|
+
const TL = require('./task-links.js');
|
|
29
|
+
const RB = require('./routes-boards.js');
|
|
30
|
+
|
|
31
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
32
|
+
const fail = (ctx, res, status, error, extra = {}) => { ctx.json(res, { ok: false, error, ...extra }, status); return true; };
|
|
33
|
+
const NO_STATE = 'This repository has no PMOS state folder (pmos/state, state or .pmos). Nothing is saved until the folder exists.';
|
|
34
|
+
const LOOP = 'That would loop back to this task';
|
|
35
|
+
const dirOf = (ctx, w) => (ctx.stateDirFor ? ctx.stateDirFor(w) : null);
|
|
36
|
+
const todayIso = () => { const d = new Date(); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
|
|
37
|
+
const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
|
|
38
|
+
|
|
39
|
+
/* ── what the engine reads: every work item on the board, and the sources Claude proposes from ── */
|
|
40
|
+
function frame(ctx, w, board, o = {}) {
|
|
41
|
+
let rows = RB.baseRows(w);
|
|
42
|
+
// outside the server (`pmos task`), rows still being read are derived now, as the CLI's other verbs do
|
|
43
|
+
if (rows.pending && o.derive) { try { require('./initiative-rows.js').deriveNow(w.root); } catch { /* answered below */ } rows = RB.baseRows(w); }
|
|
44
|
+
if (!rows.ok) return null;
|
|
45
|
+
const fr = RB.frameFor(ctx, w);
|
|
46
|
+
const mine = rows.rows.filter((r) => RB.boardIdOf(r, fr.boards, fr.folded, w) === board.id);
|
|
47
|
+
const items = RB.itemsOf(w, fr, board, mine);
|
|
48
|
+
const T = new Map(), byUid = new Map();
|
|
49
|
+
for (const x of items) { if (!x || x.kind === 'Epic' || !x.uid) continue; const t = TL.taskOf(x); T.set(t.uid, t); byUid.set(t.uid, x); }
|
|
50
|
+
const ends = new Map(); for (const r of mine) if (r.end) ends.set(r.id, TL.dn(r.end));
|
|
51
|
+
return { rows: mine, items, T, byUid, limit: (ini) => (ends.has(ini) ? ends.get(ini) : null) };
|
|
52
|
+
}
|
|
53
|
+
const PRD_CACHE = new Map(); // file → { m, text }
|
|
54
|
+
function prdText(root, ini) {
|
|
55
|
+
try {
|
|
56
|
+
const JT = require('./jira-tickets.js');
|
|
57
|
+
const rel = JT.prdOf(JT.recordFm(root, ini));
|
|
58
|
+
if (!rel) return '';
|
|
59
|
+
const file = path.resolve(root, rel.replace(/^\/+/, ''));
|
|
60
|
+
if (!file.startsWith(path.resolve(root))) return '';
|
|
61
|
+
const st = fs.statSync(file), c = PRD_CACHE.get(file);
|
|
62
|
+
if (c && c.m === st.mtimeMs) return c.text;
|
|
63
|
+
const text = st.size < 400000 ? fs.readFileSync(file, 'utf8') : '';
|
|
64
|
+
PRD_CACHE.set(file, { m: st.mtimeMs, text });
|
|
65
|
+
return text;
|
|
66
|
+
} catch { return ''; }
|
|
67
|
+
}
|
|
68
|
+
/** The sources Claude proposes links from, for one initiative: the PRD's words, the drafted Jira tickets' "depends", the plan's order. */
|
|
69
|
+
function sourcesOf(root, ini, items) {
|
|
70
|
+
let jira = [];
|
|
71
|
+
try { const d = require('./jira-tickets.js').readDraft(root, ini); jira = d ? (d.tickets || []).map((t) => ({ id: t.id, key: t.jira || '', depends: t.depends || [] })) : []; } catch { jira = []; }
|
|
72
|
+
const order = (items || []).filter((x) => x && x.ini === ini && x.store === 'item' && Number.isFinite(x.order)).map((x) => ({ uid: x.uid, order: x.order, section: x.section || x.itemStage || '' }));
|
|
73
|
+
return { prd: prdText(root, ini), jira, order };
|
|
74
|
+
}
|
|
75
|
+
function view(ctx, w, board, ini, f) {
|
|
76
|
+
const F = TL.read(dirOf(ctx, w));
|
|
77
|
+
f = f || frame(ctx, w, board);
|
|
78
|
+
if (!f) return null;
|
|
79
|
+
return TL.viewOf(F, ini, { T: f.T, today: todayIso(), limit: f.limit, src: sourcesOf(w.root, ini, f.items) });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* ── the writes: one task's dates through the board's own edit; a batch the Undo can take back ── */
|
|
83
|
+
function setDates(ctx, p, g, uid, start, due) {
|
|
84
|
+
const body = { ws: p.w.id, board: p.board.id, task: uid };
|
|
85
|
+
if (start !== undefined) body.start = start || '';
|
|
86
|
+
if (due !== undefined) body.due = due || '';
|
|
87
|
+
return RB.taskEdit(ctx, body, g);
|
|
88
|
+
}
|
|
89
|
+
/** Write the engine's moves, then one `moved` line. → [{ task, title, from, to }] the moves that landed. */
|
|
90
|
+
function apply(ctx, p, g, f, ini, moves, via, why) {
|
|
91
|
+
const done = [];
|
|
92
|
+
for (const m of moves) {
|
|
93
|
+
const t = f.T.get(m.uid), to = { start: TL.isoN(m.to.s), due: TL.isoN(m.to.e) }, from = { start: TL.isoN(m.from.s), due: TL.isoN(m.from.e) };
|
|
94
|
+
const x = f.byUid.get(m.uid) || {};
|
|
95
|
+
const r = setDates(ctx, p, g, m.uid, x.start ? to.start : undefined, to.due);
|
|
96
|
+
if (r.body && r.body.ok) done.push({ task: m.uid, title: t ? t.title : m.uid, from, to, why: why || ('waits on ' + ((f.T.get(m.after) || {}).title || m.after)) });
|
|
97
|
+
}
|
|
98
|
+
if (!done.length) return { done, batch: null };
|
|
99
|
+
const batch = TL.newBatch();
|
|
100
|
+
TL.append(dirOf(ctx, p.w), g.actor, { kind: 'moved', board: p.board.id, ini, batch, via, moves: done });
|
|
101
|
+
return { done, batch };
|
|
102
|
+
}
|
|
103
|
+
const cantOf = (S, f) => S.clashes.map((c) => ({ task: c.uid, kind: c.kind, title: (f.T.get(c.uid) || {}).title || c.uid }))
|
|
104
|
+
.concat(S.asks.map((a) => ({ task: a.uid, kind: a.why === 'milestone' ? 'milestone' : a.why, title: (f.T.get(a.uid) || {}).title || a.uid })));
|
|
105
|
+
|
|
106
|
+
/** The quiet pass for one initiative: keep the approved links after a date changed outside a drag. → { moved: n, batch } */
|
|
107
|
+
function sweep(ctx, p, g, ini, o = {}) {
|
|
108
|
+
const dir = dirOf(ctx, p.w), F = TL.read(dir);
|
|
109
|
+
if (!F.links.size || F.quiet.has(ini)) return { moved: 0, batch: null };
|
|
110
|
+
const f = frame(ctx, p.w, p.board, o); if (!f) return { moved: 0, batch: null };
|
|
111
|
+
const links = TL.linksOf(F).filter((l) => f.T.has(l.from) && f.T.has(l.to) && (f.T.get(l.from).ini === ini || f.T.get(l.to).ini === ini));
|
|
112
|
+
if (!links.length) return { moved: 0, batch: null };
|
|
113
|
+
const S = TL.settle(f.T, links, { today: TL.dn(todayIso()), ini, mode: 'quiet', limit: f.limit });
|
|
114
|
+
const mv = S.moves.filter((m) => f.T.get(m.uid).ini === ini);
|
|
115
|
+
if (!mv.length) return { moved: 0, batch: null };
|
|
116
|
+
const r = apply(ctx, p, g, f, ini, mv, 'quiet');
|
|
117
|
+
return { moved: r.done.length, batch: r.batch };
|
|
118
|
+
}
|
|
119
|
+
function sweepFor(ctx, w, boardId, ini, g) {
|
|
120
|
+
try {
|
|
121
|
+
if (!dirOf(ctx, w)) return { moved: 0 };
|
|
122
|
+
const fr = RB.frameFor(ctx, w), board = fr.boards.find((b) => b.id === boardId);
|
|
123
|
+
if (!board) return { moved: 0 };
|
|
124
|
+
return sweep(ctx, { w, fr, board, file: RB.ledgerFile(ctx, w) }, g, ini, { derive: true });
|
|
125
|
+
} catch { return { moved: 0 }; }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The PM's own act, then what waits on `seed` moves just enough (promises, Jira and Done stay; they come back as asks and clashes). */
|
|
129
|
+
function ownMove(ctx, p, g, seed, ini) {
|
|
130
|
+
const F = TL.read(dirOf(ctx, p.w)), f = frame(ctx, p.w, p.board);
|
|
131
|
+
if (!f || !f.T.has(seed)) return { moved: [], cant: [], batch: null };
|
|
132
|
+
const S = TL.settle(f.T, TL.linksOf(F).filter((l) => f.T.has(l.from) && f.T.has(l.to)), { seeds: [seed], today: TL.dn(todayIso()), ini, mode: 'own', limit: f.limit });
|
|
133
|
+
const r = apply(ctx, p, g, f, ini, S.moves, 'own');
|
|
134
|
+
return { moved: r.done, cant: cantOf(S, f), batch: r.batch };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const READS = {
|
|
138
|
+
'/api/task-links': (ctx, res, url) => {
|
|
139
|
+
const p = RB.postFrame(ctx, res, { ws: url.searchParams.get('ws') || null, board: url.searchParams.get('board') || '' });
|
|
140
|
+
if (!p) return;
|
|
141
|
+
const ini = url.searchParams.get('initiative') || '';
|
|
142
|
+
if (!ini) return fail(ctx, res, 400, 'initiative is required');
|
|
143
|
+
ctx.json(res, { ok: true, links: dirOf(ctx, p.w) ? view(ctx, p.w, p.board, ini) : null });
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const WRITES = {
|
|
148
|
+
'/api/task-links/link': (ctx, res, body, g, p) => {
|
|
149
|
+
const c = TL.cleanLink(body);
|
|
150
|
+
if (c.error) return fail(ctx, res, 400, c.error);
|
|
151
|
+
const f = frame(ctx, p.w, p.board);
|
|
152
|
+
if (!f) return fail(ctx, res, 202, 'The board is still being read. Try again in a moment.');
|
|
153
|
+
const a = f.T.get(c.link.from), b = f.T.get(c.link.to);
|
|
154
|
+
if (!a || !b) return fail(ctx, res, 404, `no task ${!a ? c.link.from : c.link.to} on this board`);
|
|
155
|
+
const dir = dirOf(ctx, p.w), F = TL.read(dir), k = TL.keyOf(c.link.from, c.link.to);
|
|
156
|
+
const others = TL.linksOf(F).filter((l) => TL.keyOf(l.from, l.to) !== k && TL.keyOf(l.to, l.from) !== k);
|
|
157
|
+
if (TL.loops(others, c.link.from, c.link.to)) return fail(ctx, res, 409, LOOP);
|
|
158
|
+
const was = F.links.get(k) || null, back = F.links.get(TL.keyOf(c.link.to, c.link.from)) || null;
|
|
159
|
+
if (back) TL.append(dir, g.actor, { kind: 'unlink', from: back.from, to: back.to });
|
|
160
|
+
const ini = b.ini || a.ini;
|
|
161
|
+
TL.append(dir, g.actor, { kind: 'link', board: p.board.id, ini, ...c.link, source: typeof body.source === 'string' && body.source ? body.source.slice(0, 20) : 'you' });
|
|
162
|
+
const m = ownMove(ctx, p, g, c.link.from, ini);
|
|
163
|
+
ctx.json(res, { ok: true, from: was ? { type: was.type, lag: was.lag } : null, swapped: !!back, moved: m.moved, cant: m.cant, batch: m.batch, links: view(ctx, p.w, p.board, ini) });
|
|
164
|
+
},
|
|
165
|
+
'/api/task-links/unlink': (ctx, res, body, g, p) => {
|
|
166
|
+
const from = String(body.from || ''), to = String(body.to || ''), dir = dirOf(ctx, p.w), F = TL.read(dir);
|
|
167
|
+
const was = F.links.get(TL.keyOf(from, to));
|
|
168
|
+
if (!was) return fail(ctx, res, 404, 'no such link');
|
|
169
|
+
TL.append(dir, g.actor, { kind: 'unlink', from, to });
|
|
170
|
+
ctx.json(res, { ok: true, from: { from, to, type: was.type, lag: was.lag, source: was.source } });
|
|
171
|
+
},
|
|
172
|
+
'/api/task-links/move': (ctx, res, body, g, p) => {
|
|
173
|
+
const uid = String(body.task || '');
|
|
174
|
+
const f = frame(ctx, p.w, p.board);
|
|
175
|
+
if (!f) return fail(ctx, res, 202, 'The board is still being read. Try again in a moment.');
|
|
176
|
+
const t0 = f.T.get(uid);
|
|
177
|
+
if (!t0) return fail(ctx, res, 404, `no task ${uid || '(none named)'} on this board`);
|
|
178
|
+
if (t0.jira) return fail(ctx, res, 409, 'Jira owns this ticket: its dates change in Jira');
|
|
179
|
+
const x0 = f.byUid.get(uid) || {};
|
|
180
|
+
const e = setDates(ctx, p, g, uid, body.start, body.due);
|
|
181
|
+
if (!e.body || e.body.ok !== true) return ctx.json(res, e.body || { ok: false, error: 'the write was refused' }, e.status || 500);
|
|
182
|
+
const from = { start: x0.start || '', due: x0.end || '' };
|
|
183
|
+
// later: what waits follows; earlier: nothing moves, Claude files "Pull N tasks in"
|
|
184
|
+
const s1 = body.start != null && body.start !== '' ? TL.dn(body.start) : t0.s, e1 = body.due != null && body.due !== '' ? TL.dn(body.due) : t0.e;
|
|
185
|
+
const shift = Math.max(e1 != null && t0.e != null ? e1 - t0.e : 0, s1 != null && t0.s != null && body.due == null ? s1 - t0.s : 0);
|
|
186
|
+
const early = Math.min(e1 != null && t0.e != null ? e1 - t0.e : 0, s1 != null && t0.s != null ? s1 - t0.s : 0);
|
|
187
|
+
let m = { moved: [], cant: [], batch: null }, pulled = 0;
|
|
188
|
+
if (shift > 0 || (s1 != null && t0.s != null && s1 > t0.s)) m = ownMove(ctx, p, g, uid, t0.ini);
|
|
189
|
+
else if (early < 0) {
|
|
190
|
+
const F = TL.read(dirOf(ctx, p.w)), T = new Map(f.T); T.set(uid, { ...t0, s: s1, e: e1 });
|
|
191
|
+
const P = TL.pullOf(T, TL.linksOf(F), uid, -early, TL.dn(todayIso()));
|
|
192
|
+
if (P.length) { TL.append(dirOf(ctx, p.w), g.actor, { kind: 'pull', board: p.board.id, ini: t0.ini, id: TL.newBatch().replace('mv-', 'pl-'), after: uid, days: -early, tasks: P.map((x) => x.uid) }); pulled = P.length; }
|
|
193
|
+
}
|
|
194
|
+
// one batch for Undo: the task's own change first, then what moved with it
|
|
195
|
+
const batch = TL.newBatch();
|
|
196
|
+
TL.append(dirOf(ctx, p.w), g.actor, { kind: 'moved', board: p.board.id, ini: t0.ini, batch, via: 'own', moves: [{ task: uid, title: t0.title, from, to: { start: body.start != null ? body.start : from.start, due: body.due != null ? body.due : from.due }, why: 'you moved it' }, ...m.moved] });
|
|
197
|
+
if (m.batch) TL.append(dirOf(ctx, p.w), g.actor, { kind: 'undo', batch: m.batch }); // folded into the one batch above
|
|
198
|
+
ctx.json(res, { ok: true, item: e.body.item || null, moved: m.moved, cant: m.cant, batch, pulled });
|
|
199
|
+
},
|
|
200
|
+
'/api/task-links/accept': (ctx, res, body, g, p) => {
|
|
201
|
+
const ini = String(body.initiative || ''), ids = Array.isArray(body.ids) ? body.ids.filter((x) => typeof x === 'string').slice(0, 40) : [];
|
|
202
|
+
if (!ini || !ids.length) return fail(ctx, res, 400, 'initiative and ids are required');
|
|
203
|
+
const f = frame(ctx, p.w, p.board);
|
|
204
|
+
if (!f) return fail(ctx, res, 202, 'The board is still being read. Try again in a moment.');
|
|
205
|
+
const v = view(ctx, p.w, p.board, ini, f), dir = dirOf(ctx, p.w);
|
|
206
|
+
const want = (v ? v.proposals : []).filter((x) => ids.includes(x.id));
|
|
207
|
+
if (!want.length) return fail(ctx, res, 409, 'Those proposals are no longer open');
|
|
208
|
+
const linked = [], moved = [];
|
|
209
|
+
let F = TL.read(dir);
|
|
210
|
+
for (const x of want) {
|
|
211
|
+
if (x.kind === 'link') {
|
|
212
|
+
if (TL.loops(TL.linksOf(F), x.from, x.to)) continue;
|
|
213
|
+
TL.append(dir, g.actor, { kind: 'link', board: p.board.id, ini, from: x.from, to: x.to, type: x.type, lag: x.lag || 0, source: x.source });
|
|
214
|
+
linked.push({ from: x.from, to: x.to }); F = TL.read(dir);
|
|
215
|
+
} else if (x.kind === 'pull') {
|
|
216
|
+
const f2 = frame(ctx, p.w, p.board);
|
|
217
|
+
const mv = x.tasks.map((u) => { const t = f2.T.get(u); const P = { uid: u, from: { s: t.s, e: t.e }, to: { s: t.s == null ? null : t.s - x.days, e: t.e == null ? null : t.e - x.days }, after: x.after }; return P; });
|
|
218
|
+
const r = apply(ctx, p, g, f2, ini, mv, 'ask', 'pulled in after ' + ((f2.T.get(x.after) || {}).title || x.after));
|
|
219
|
+
moved.push(...r.done); TL.append(dir, g.actor, { kind: 'drop', sig: x.id });
|
|
220
|
+
} else if (x.kind === 'move') {
|
|
221
|
+
const f2 = frame(ctx, p.w, p.board);
|
|
222
|
+
const mv = x.tasks.filter((m) => f2.T.has(m.task)).map((m) => ({ uid: m.task, from: { s: TL.dn(m.from.start), e: TL.dn(m.from.due) }, to: { s: TL.dn(m.to.start), e: TL.dn(m.to.due) } }));
|
|
223
|
+
const r = apply(ctx, p, g, f2, ini, mv, 'ask', 'to keep your links');
|
|
224
|
+
moved.push(...r.done);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// what the new links ask for now moves just enough (the PM's ✓ is the approval)
|
|
228
|
+
for (const l of linked) { const m = ownMove(ctx, p, g, l.from, ini); moved.push(...m.moved); }
|
|
229
|
+
ctx.json(res, { ok: true, linked, moved, links: view(ctx, p.w, p.board, ini) });
|
|
230
|
+
},
|
|
231
|
+
'/api/task-links/drop': (ctx, res, body, g, p) => {
|
|
232
|
+
const id = String(body.id || '');
|
|
233
|
+
if (!/^[pamju]:/.test(id) || id.length > 300) return fail(ctx, res, 400, 'id names a proposal or a recommendation');
|
|
234
|
+
TL.append(dirOf(ctx, p.w), g.actor, { kind: 'drop', sig: id });
|
|
235
|
+
ctx.json(res, { ok: true });
|
|
236
|
+
},
|
|
237
|
+
'/api/task-links/ask': (ctx, res, body, g, p) => {
|
|
238
|
+
const ini = String(body.initiative || ''), id = String(body.id || ''), yes = body.answer === 'yes';
|
|
239
|
+
if (!ini || !id || (body.answer !== 'yes' && body.answer !== 'no')) return fail(ctx, res, 400, 'initiative, id and answer (yes or no) are required');
|
|
240
|
+
const f = frame(ctx, p.w, p.board);
|
|
241
|
+
if (!f) return fail(ctx, res, 202, 'The board is still being read. Try again in a moment.');
|
|
242
|
+
const v = view(ctx, p.w, p.board, ini, f), a = v ? v.asks.find((x) => x.id === id) : null, dir = dirOf(ctx, p.w);
|
|
243
|
+
if (!a) return fail(ctx, res, 409, 'That is no longer waiting on you');
|
|
244
|
+
if (!yes) { TL.append(dir, g.actor, { kind: 'drop', sig: id }); return ctx.json(res, { ok: true }); }
|
|
245
|
+
if (a.kind === 'jira') {
|
|
246
|
+
let entry = null;
|
|
247
|
+
try {
|
|
248
|
+
const { repoScript } = require('./repo-script.js');
|
|
249
|
+
const outbox = require(repoScript('outbox.js')), store = require('./outbox-store.js');
|
|
250
|
+
const e = outbox.draftOutbox({ channel: 'jira-write', recipient: a.task, subject: 'Start date of ' + a.task, body: a.comment, origin: 'pm' });
|
|
251
|
+
entry = { id: 'out-' + require('crypto').randomBytes(6).toString('hex'), ...e };
|
|
252
|
+
store.appendEvent(ctx.runtimeDir, { event: 'queued', ...entry }, new Date());
|
|
253
|
+
} catch (err) { return fail(ctx, res, 500, 'The comment could not go to the outbox: ' + ((err && err.message) || err)); }
|
|
254
|
+
TL.append(dir, g.actor, { kind: 'outbox', sig: id, entry: entry.id });
|
|
255
|
+
TL.append(dir, g.actor, { kind: 'drop', sig: id });
|
|
256
|
+
return ctx.json(res, { ok: true, outbox: entry.id });
|
|
257
|
+
}
|
|
258
|
+
// a promise: the move Claude recommends, then what waits on it (the ✓ lets this one task move)
|
|
259
|
+
const x = f.byUid.get(a.task) || {};
|
|
260
|
+
const e = setDates(ctx, p, g, a.task, x.start ? a.to.start : undefined, a.to.due);
|
|
261
|
+
if (!e.body || e.body.ok !== true) return ctx.json(res, e.body || { ok: false, error: 'the write was refused' }, e.status || 500);
|
|
262
|
+
const t = f.T.get(a.task), m = ownMove(ctx, p, g, a.task, ini);
|
|
263
|
+
const batch = TL.newBatch();
|
|
264
|
+
TL.append(dir, g.actor, { kind: 'moved', board: p.board.id, ini, batch, via: 'ask', moves: [{ task: a.task, title: t.title, from: { start: x.start || '', due: x.end || '' }, to: a.to, why: 'you approved it' }, ...m.moved] });
|
|
265
|
+
if (m.batch) TL.append(dir, g.actor, { kind: 'undo', batch: m.batch });
|
|
266
|
+
ctx.json(res, { ok: true, moved: m.moved.length + 1, batch });
|
|
267
|
+
},
|
|
268
|
+
'/api/task-links/undo': (ctx, res, body, g, p) => {
|
|
269
|
+
const dir = dirOf(ctx, p.w), F = TL.read(dir), id = String(body.batch || '');
|
|
270
|
+
const b = F.moved.find((x) => x.batch === id);
|
|
271
|
+
if (!b || F.undone.has(id)) return fail(ctx, res, 409, 'Nothing to undo');
|
|
272
|
+
const f = frame(ctx, p.w, p.board);
|
|
273
|
+
if (!f) return fail(ctx, res, 202, 'The board is still being read. Try again in a moment.');
|
|
274
|
+
let back = 0, kept = 0;
|
|
275
|
+
for (const m of b.moves.slice().reverse()) {
|
|
276
|
+
const x = f.byUid.get(m.task);
|
|
277
|
+
// a task changed since keeps its dates: Undo never overwrites a later change
|
|
278
|
+
if (!x || (x.start || '') !== (m.to.start || x.start || '') || (x.end || '') !== (m.to.due || '')) { kept++; continue; }
|
|
279
|
+
const r = setDates(ctx, p, g, m.task, m.from.start !== undefined ? m.from.start : undefined, m.from.due);
|
|
280
|
+
if (r.body && r.body.ok) back++; else kept++;
|
|
281
|
+
}
|
|
282
|
+
TL.append(dir, g.actor, { kind: 'undo', batch: id });
|
|
283
|
+
ctx.json(res, { ok: true, back, kept });
|
|
284
|
+
},
|
|
285
|
+
'/api/task-links/sweep': (ctx, res, body, g, p) => {
|
|
286
|
+
const ini = String(body.initiative || '');
|
|
287
|
+
if (!ini) return fail(ctx, res, 400, 'initiative is required');
|
|
288
|
+
const r = sweep(ctx, p, g, ini);
|
|
289
|
+
ctx.json(res, { ok: true, moved: r.moved, links: r.moved ? view(ctx, p.w, p.board, ini) : undefined });
|
|
290
|
+
},
|
|
291
|
+
'/api/task-links/quiet': (ctx, res, body, g, p) => {
|
|
292
|
+
const ini = String(body.initiative || '');
|
|
293
|
+
if (!ini || typeof body.on !== 'boolean') return fail(ctx, res, 400, 'initiative and on (true or false) are required');
|
|
294
|
+
TL.append(dirOf(ctx, p.w), g.actor, { kind: 'quiet', ini, on: body.on });
|
|
295
|
+
ctx.json(res, { ok: true });
|
|
296
|
+
},
|
|
297
|
+
'/api/task-links/seen': (ctx, res, body, g, p) => {
|
|
298
|
+
const ini = String(body.initiative || '');
|
|
299
|
+
if (!ini) return fail(ctx, res, 400, 'initiative is required');
|
|
300
|
+
TL.append(dirOf(ctx, p.w), g.actor, { kind: 'seen', ini });
|
|
301
|
+
ctx.json(res, { ok: true });
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
module.exports = {
|
|
306
|
+
prefixes: ['/api/task-links'],
|
|
307
|
+
sweepFor, sourcesOf, frame, LOOP,
|
|
308
|
+
handle: async (req, res, url, ctx) => {
|
|
309
|
+
const p0 = url.pathname;
|
|
310
|
+
if (req.method === 'GET') {
|
|
311
|
+
const fn = READS[p0];
|
|
312
|
+
if (!fn) return fail(ctx, res, 404, 'not found');
|
|
313
|
+
fn(ctx, res, url);
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
if (req.method !== 'POST') return fail(ctx, res, 405, 'GET or POST only');
|
|
317
|
+
const fn = WRITES[p0];
|
|
318
|
+
if (!fn) return fail(ctx, res, 404, 'not found');
|
|
319
|
+
const got = await ctx.readJson(req);
|
|
320
|
+
if (!got.ok || !isObj(got.body)) return fail(ctx, res, 400, 'the body must be a JSON object');
|
|
321
|
+
const body = got.body, g = guard.requirePagePress(req, body);
|
|
322
|
+
if (!g.ok) return fail(ctx, res, g.status, g.error);
|
|
323
|
+
const p = RB.postFrame(ctx, res, body);
|
|
324
|
+
if (!p) return true;
|
|
325
|
+
if (!p.file || !dirOf(ctx, p.w)) return fail(ctx, res, 409, NO_STATE);
|
|
326
|
+
fn(ctx, res, body, g, p);
|
|
327
|
+
return true;
|
|
328
|
+
},
|
|
329
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* split-merge-suggest.js — Claude's suggestion to split an initiative or merge two (feedback batch 11 item 14, option A grilled; canvas
|
|
3
|
+
* XsmA1Suggest, XsmA4MergeSuggest, rules sticky xsplitR). PURE: it reads the Board's own rows and work items and writes nothing.
|
|
4
|
+
*
|
|
5
|
+
* suggest(rows, items, { dismissed, today }) → Map<initiative id, suggestion>
|
|
6
|
+
* rows the Board model's open rows (lib/board-premium.js rowOf: id, title, anchor, kr, epics, end, wfStage, status)
|
|
7
|
+
* items the board's work items (routes-boards itemsOf): PMOS tasks and Jira tickets, each with ini, status, owner, start, end, epic
|
|
8
|
+
* dismissed Map<id, { kind, fp }> the PM's ✕ Not now (the boards ledger's ini-suggest lines); the same fingerprint stays hidden
|
|
9
|
+
* fingerprint(list) → the 16 hex characters a suggestion is known by: it changes when the tasks or tickets it was made from change
|
|
10
|
+
*
|
|
11
|
+
* It runs on every read of the Board, so it follows the tasks and tickets as they change, never a timer. It only suggests: the card's ✓ is
|
|
12
|
+
* the PM's approval (lib/split-merge.js writes nothing without a page press). One card per initiative; a merge wins over a split.
|
|
13
|
+
*
|
|
14
|
+
* SPLIT when the open work falls into two groups that share no dates (two weeks or more between them), no owner and no Jira epic, and the
|
|
15
|
+
* later group is its own job: its own Jira ticket or its own owner. The later group moves; it is named from its one ticket, else the word
|
|
16
|
+
* its titles share, else its first task.
|
|
17
|
+
* → { kind: 'split', fp, title, why, name, tasks: [uid], tickets: [key], docs: [], counts, stays }
|
|
18
|
+
* MERGE when two open initiatives of one board (one product) link the same Jira epic, or most of their open tasks are alike (3 or more, and
|
|
19
|
+
* at least half of the smaller one's). The one further along stays, then the one with more open work; the card is on the one that closes.
|
|
20
|
+
* → { kind: 'merge', fp, title, why, into, intoTitle, reason, end, anchor }
|
|
21
|
+
* Honest limit: tasks have no dependencies yet, so "waits on nothing in the other" is not checked; and a program's initiatives on another
|
|
22
|
+
* product's board are not compared (a merge stays on one board). */
|
|
23
|
+
const crypto = require('crypto');
|
|
24
|
+
|
|
25
|
+
const OPEN = new Set(['To do', 'In progress', 'In review']);
|
|
26
|
+
const STOP = new Set(['the', 'and', 'for', 'with', 'from', 'into', 'onto', 'old', 'new', 'all', 'our', 'its', 'this', 'that', 'write', 'make', 'plan', 'add', 'set', 'get', 'list', 'run', 'draft', 'review', 'check', 'update', 'task', 'tasks', 'ticket']);
|
|
27
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
28
|
+
const DAY = 86400000;
|
|
29
|
+
const GAP_DAYS = 14;
|
|
30
|
+
|
|
31
|
+
const dayOf = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
32
|
+
const mon = (ms) => MON[new Date(ms).getUTCMonth()];
|
|
33
|
+
const monY = (ms) => mon(ms) + ' ' + new Date(ms).getUTCFullYear();
|
|
34
|
+
const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
|
|
35
|
+
const words = (t) => String(t || '').toLowerCase().split(/[^a-z0-9]+/).filter((w) => w.length >= 3 && !STOP.has(w));
|
|
36
|
+
const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
|
|
37
|
+
|
|
38
|
+
function fingerprint(list) {
|
|
39
|
+
return crypto.createHash('sha1').update(JSON.stringify(list)).digest('hex').slice(0, 16);
|
|
40
|
+
}
|
|
41
|
+
/** The open work of one initiative: its open PMOS tasks and open Jira tickets, each { id, kind, title, owner, epic, a, z }. */
|
|
42
|
+
function openWork(items, id) {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const x of items) {
|
|
45
|
+
if (!x || x.ini !== id || x.kind === 'Epic' || !OPEN.has(x.status)) continue;
|
|
46
|
+
const a = dayOf(x.start) || dayOf(x.end), z = dayOf(x.end) || dayOf(x.start);
|
|
47
|
+
out.push({ id: x.src === 'jira' ? x.key : x.uid, jira: x.src === 'jira', title: x.title || x.key || x.uid, owner: x.src === 'jira' ? '' : String(x.owner || '').trim(), epic: x.epic || null, a, z });
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
const fpOf = (work) => fingerprint(work.map((w) => [w.id, w.a, w.z, w.owner, w.epic]).sort((x, y) => String(x[0]).localeCompare(String(y[0]))));
|
|
52
|
+
const disjoint = (a, b) => { for (const x of a) if (b.has(x)) return false; return true; };
|
|
53
|
+
|
|
54
|
+
/** The name of the group that moves: its one Jira ticket, else a word two of its titles share and the other group's do not, else its first task. */
|
|
55
|
+
function nameOf(group, rest) {
|
|
56
|
+
const tk = group.filter((w) => w.jira);
|
|
57
|
+
if (tk.length === 1) return clip(tk[0].title.replace(/^[A-Z][A-Z0-9_]+-\d+\s*/, ''), 80);
|
|
58
|
+
const count = new Map(), other = new Set(rest.flatMap((w) => words(w.title)));
|
|
59
|
+
for (const w of group) for (const x of new Set(words(w.title))) if (!other.has(x)) count.set(x, (count.get(x) || 0) + 1);
|
|
60
|
+
const top = [...count.entries()].filter(([, n]) => n >= 2).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0];
|
|
61
|
+
const first = group.find((w) => !w.jira) || group[0];
|
|
62
|
+
if (top) {
|
|
63
|
+
const head = top[0].charAt(0).toUpperCase() + top[0].slice(1);
|
|
64
|
+
const tail = clip(first.title, 50);
|
|
65
|
+
return tail.toLowerCase().includes(top[0]) ? clip(tail.charAt(0).toUpperCase() + tail.slice(1), 80) : clip(head + ' — ' + tail.charAt(0).toLowerCase() + tail.slice(1), 80);
|
|
66
|
+
}
|
|
67
|
+
return clip(first.title, 80);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function splitOf(row, work) {
|
|
71
|
+
const dated = work.filter((w) => w.a != null).sort((x, y) => x.a - y.a || x.z - y.z);
|
|
72
|
+
if (dated.length < 4) return null;
|
|
73
|
+
let best = null;
|
|
74
|
+
for (let c = 2; c <= dated.length - 2; c++) {
|
|
75
|
+
const L = dated.slice(0, c), Rr = dated.slice(c);
|
|
76
|
+
const lz = Math.max(...L.map((w) => w.z)), ra = Math.min(...Rr.map((w) => w.a));
|
|
77
|
+
const gap = (ra - lz) / DAY;
|
|
78
|
+
if (gap < GAP_DAYS) continue;
|
|
79
|
+
const lo = new Set(L.map((w) => w.owner).filter(Boolean)), ro = new Set(Rr.map((w) => w.owner).filter(Boolean));
|
|
80
|
+
const le = new Set(L.map((w) => w.epic).filter(Boolean)), re = new Set(Rr.map((w) => w.epic).filter(Boolean));
|
|
81
|
+
if (!disjoint(lo, ro) || !disjoint(le, re)) continue;
|
|
82
|
+
const ownTicket = Rr.some((w) => w.jira), ownOwner = ro.size > 0;
|
|
83
|
+
if (!ownTicket && !ownOwner) continue;
|
|
84
|
+
if (!best || gap > best.gap) best = { L, R: Rr, gap, ownTicket, ownOwner };
|
|
85
|
+
}
|
|
86
|
+
if (!best) return null;
|
|
87
|
+
const undated = work.filter((w) => w.a == null);
|
|
88
|
+
const rest = best.L.concat(undated);
|
|
89
|
+
const name = nameOf(best.R, rest);
|
|
90
|
+
const a = Math.min(...best.R.map((w) => w.a)), z = Math.max(...best.R.map((w) => w.z));
|
|
91
|
+
const span = mon(a) === mon(z) && new Date(a).getUTCFullYear() === new Date(z).getUTCFullYear() ? mon(a) : mon(a) + '–' + mon(z);
|
|
92
|
+
const own = ['their own dates (' + span + ')'];
|
|
93
|
+
if (best.ownTicket) own.push(best.R.filter((w) => w.jira).length === 1 ? 'their own Jira ticket' : 'their own Jira tickets');
|
|
94
|
+
if (best.ownOwner) own.push('their own owner');
|
|
95
|
+
const n = best.R.length, all = work.length;
|
|
96
|
+
const share = n * 2 === all ? 'Half of the open tasks are' : n === 1 ? 'One open task is' : n + ' of the ' + all + ' open tasks are';
|
|
97
|
+
const tasks = best.R.filter((w) => !w.jira).map((w) => w.id), tickets = best.R.filter((w) => w.jira).map((w) => w.id);
|
|
98
|
+
const stays = rest.slice(0, 3).map((w) => clip(w.title, 28)).join(', ');
|
|
99
|
+
return {
|
|
100
|
+
kind: 'split', fp: fpOf(work), title: 'Split off ' + name + '?', why: share + ' on their own: ' + own.join(', ').replace(/, ([^,]*)$/, ' and $1') + '.',
|
|
101
|
+
name, tasks, tickets, docs: [], counts: { tasks: tasks.length, tickets: tickets.length, docs: 0 }, stays,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** How far along a row is: its stage's place in its workflow. */
|
|
106
|
+
const along = (r) => (r.wfStage && Number.isFinite(r.wfStage.n) ? r.wfStage.n : 0);
|
|
107
|
+
const norm = (t) => words(t).join(' ');
|
|
108
|
+
function alike(a, b) {
|
|
109
|
+
if (!a || !b) return false;
|
|
110
|
+
if (a === b) return true;
|
|
111
|
+
const A = new Set(a.split(' ')), Bs = new Set(b.split(' '));
|
|
112
|
+
let n = 0; for (const x of A) if (Bs.has(x)) n++;
|
|
113
|
+
return n / Math.max(A.size, Bs.size) >= 0.6;
|
|
114
|
+
}
|
|
115
|
+
function mergeOf(rows, workBy, items) {
|
|
116
|
+
const out = new Map();
|
|
117
|
+
const epicsOf = (r) => new Set([...(r.epics || []), ...items.filter((x) => x && x.ini === r.id && x.epic).map((x) => x.epic), ...items.filter((x) => x && x.ini === r.id && x.kind === 'Epic' && x.key).map((x) => x.key)]);
|
|
118
|
+
const open = rows.filter((r) => r && r.id && r.status !== 'done');
|
|
119
|
+
for (let i = 0; i < open.length; i++) {
|
|
120
|
+
for (let j = i + 1; j < open.length; j++) {
|
|
121
|
+
const A = open[i], B = open[j];
|
|
122
|
+
const ea = epicsOf(A), eb = epicsOf(B), shared = [...ea].filter((k) => eb.has(k));
|
|
123
|
+
const wa = workBy.get(A.id) || [], wb = workBy.get(B.id) || [];
|
|
124
|
+
const ta = wa.filter((w) => !w.jira).map((w) => norm(w.title)).filter(Boolean), tb = wb.filter((w) => !w.jira).map((w) => norm(w.title)).filter(Boolean);
|
|
125
|
+
const small = ta.length <= tb.length ? ta : tb, big = small === ta ? tb : ta;
|
|
126
|
+
const match = small.filter((t) => big.some((u) => alike(t, u))).length;
|
|
127
|
+
const many = match >= 3 && match * 2 >= small.length;
|
|
128
|
+
if (!shared.length && !many) continue;
|
|
129
|
+
// the one further along stays, then the one with more open work
|
|
130
|
+
const stay = along(A) !== along(B) ? (along(A) > along(B) ? A : B) : (wa.length !== wb.length ? (wa.length > wb.length ? A : B) : A);
|
|
131
|
+
const go = stay === A ? B : A;
|
|
132
|
+
if (out.has(go.id)) continue;
|
|
133
|
+
const reason = along(A) !== along(B) ? 'it is further along' : wa.length !== wb.length ? 'it has more open work' : 'it was listed first';
|
|
134
|
+
const goWork = workBy.get(go.id) || [], goTasks = goWork.filter((w) => !w.jira).length;
|
|
135
|
+
const why = [];
|
|
136
|
+
if (many) why.push(match + ' of its ' + plural(goTasks || small.length, 'task', 'tasks') + ' match ' + stay.title + '’s');
|
|
137
|
+
if (shared.length) why.push((many ? 'both' : 'Both') + ' link Jira epic ' + shared[0]);
|
|
138
|
+
const ends = [go.end, stay.end].map(dayOf).filter((x) => x != null);
|
|
139
|
+
const end = ends.length ? Math.max(...ends) : null;
|
|
140
|
+
out.set(go.id, {
|
|
141
|
+
kind: 'merge', fp: fingerprint([go.id, stay.id, fpOf(goWork), fpOf(workBy.get(stay.id) || []), shared]), title: 'Same work as ' + clip(stay.title.split(' — ')[0], 40) + '?',
|
|
142
|
+
why: why.join(', and ') + '.', into: stay.id, intoTitle: stay.title, reason, end: end ? monY(end) : null, anchor: stay.kr || stay.anchor || null,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function suggest(rows, items, { dismissed } = {}) {
|
|
150
|
+
const L = (rows || []).filter((r) => r && r.id), I = (items || []).filter(Boolean);
|
|
151
|
+
const workBy = new Map(L.map((r) => [r.id, openWork(I, r.id)]));
|
|
152
|
+
const out = mergeOf(L, workBy, I);
|
|
153
|
+
for (const r of L) {
|
|
154
|
+
if (out.has(r.id) || r.status === 'done') continue;
|
|
155
|
+
const s = splitOf(r, workBy.get(r.id) || []);
|
|
156
|
+
if (s) out.set(r.id, s);
|
|
157
|
+
}
|
|
158
|
+
if (dismissed && dismissed.size) for (const [id, s] of [...out]) { const d = dismissed.get(id); if (d && d.fp === s.fp) out.delete(id); }
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
module.exports = { suggest, fingerprint, openWork };
|