create-pmos 0.648.0 → 0.649.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.648.0",
3
+ "version": "0.649.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -33,6 +33,19 @@
33
33
  "audit"
34
34
  ],
35
35
  "pmosChanges": [
36
+ {
37
+ "v": "0.649.0",
38
+ "at": "2026-11-20T06:16:36.793Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 1431,
43
+ "t": "Work's Backlog tab ranks the work outside the sprint and is built from design system blocks",
44
+ "s": "Work's Backlog tab ranks the work outside the sprint and is built from design system blocks",
45
+ "k": "new"
46
+ }
47
+ ]
48
+ },
36
49
  {
37
50
  "v": "0.648.0",
38
51
  "at": "2026-11-20T05:58:53.312Z",
@@ -303,19 +316,6 @@
303
316
  "k": "fix"
304
317
  }
305
318
  ]
306
- },
307
- {
308
- "v": "0.622.0",
309
- "at": "2026-11-19T05:05:08.698Z",
310
- "f": 4,
311
- "prs": [
312
- {
313
- "n": 1403,
314
- "t": "Work breakdown back to stages with their tasks; no-stage tasks in the Backlog",
315
- "s": "Work breakdown back to stages with their tasks; no-stage tasks in the Backlog",
316
- "k": "fix"
317
- }
318
- ]
319
319
  }
320
320
  ]
321
321
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@9750136d
1
+ kernel-source: pmos@6a943aac
2
2
  assembled: 2026-11-20
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-20T05:58:50Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-20T06:16:33Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Health budgets"
4
4
  description: "Closed registry of health-budget anchors (D59), edited only by the PM."
5
- generated: {by: process:create-pmos, at: "2026-11-20T05:58:50Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-20T06:16:33Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-20T05:58:50Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-20T06:16:33Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,17 @@
1
1
  [
2
+ {
3
+ "v": "0.649.0",
4
+ "at": "2026-11-20T06:16:36.793Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1431,
9
+ "t": "Work's Backlog tab ranks the work outside the sprint and is built from design system blocks",
10
+ "s": "Work's Backlog tab ranks the work outside the sprint and is built from design system blocks",
11
+ "k": "new"
12
+ }
13
+ ]
14
+ },
2
15
  {
3
16
  "v": "0.648.0",
4
17
  "at": "2026-11-20T05:58:53.312Z",
@@ -94,6 +94,12 @@ On a computer, Work is built from the parts of the PMOS design system. The top l
94
94
  - **Initiatives.** A table with the columns you choose (the tune icon also sorts and filters). Press a column heading to sort by it. The timeline shows done in green, now in blue and planned in grey, with a red line for today. A milestone is a diamond on its initiative's row; a late one is red. Milestones less than 8 days apart are one numbered diamond: point at it to see them. Pick the scale with **Week**, **Month**, **Quarter**, **Year** or **Full**. Move the timeline with the arrows, with a sideways swipe on a trackpad, or by dragging it; the middle arrow goes back to today. A late date has a red badge, for example "8 days late". Closed initiatives fold into one line at the end.
95
95
  - **Next milestones.** The next five milestones of all initiatives on one line, on the same scale as the table, each with its date, its name and its initiative. Labels that are too close move down a row. A milestone after the end of the line is in the **+N** mark at the right: press it to move the line on. When the line has moved, a mark at the left moves it back. Press a diamond to open the milestone.
96
96
 
97
+ **Backlog** is the open work outside the sprint, in one rank across initiatives.
98
+
99
+ - **Where it stands.** A few lines: how many items wait, how many are ready to pull into the next sprint and from which initiatives, how many have not changed in 60 days, and how many have no initiative. An item is ready when it has an initiative and an owner, is not started, and PMOS is not working on it. Under it, PMOS suggests pulling the top ready items into the next sprint. ✓ gives the PMOS tasks the next sprint's dates (with Undo) and lists the Jira tickets for you to add in Jira, because PMOS does not change Jira. The pencil ticks the items on the **Ready** tab so you can change the pick first, and ✕ says not now.
100
+ - **Add to the backlog.** Type a line and press Enter. Name the initiative ("for Migration from Okta") or PMOS puts it in the closest one; when none is close, it asks.
101
+ - **Items.** A table grouped by initiative, each group with "n items · r ready". The tabs show **All**, **Ready**, **Needs detail** or **Untouched 60 days**. Drag a row by its grip to change the rank (with Undo); the number is its place in the one rank. **Last change** shows when the item last changed; an item untouched for 30 days or more has a badge, for example "79 days untouched". **Group** also groups the rows by what PMOS can do, with its ✓ buttons. Tick rows to change them together. The tune icon filters the rows.
102
+
97
103
  **This sprint** shows all work in the sprint's dates, in Jira and outside it. It holds every ticket of the active Jira sprint, done ones too, and every PMOS task whose dates meet the sprint's dates. A task under way with no date is in it too. Early stages often have no tickets, so their work still shows here.
98
104
 
99
105
  - **The sprint card.** The sprint's name, its end date and what it holds, for example "21 Jira tickets and 7 tasks outside Jira". Under it, "11 of 28 done" with a bar. Then four columns: **Sprint goal**, **In progress**, **To do** and **Done**, each with its count and its first tasks. PMOS drafts the goal from the sprint's work. Press the pencil to write your own; it can name work outside Jira, and PMOS does not write over it. When PMOS has a newer draft, ✓ uses it and ✕ keeps yours. Press the sprint's name to open a past sprint. The arrow icon reads Jira again; a red dot on it means the last read is old. Under the columns, PMOS shows one suggestion, for example to place tickets in an initiative, with **Why**, **PMOS will**, **What changes** and **Based on**. The pencil picks another initiative first, ✓ does it (with Undo) and ✕ says not now.
@@ -177,7 +177,7 @@ function foundOf(f) {
177
177
  }
178
178
  const KINDS = new Set(['board', 'workflow', 'move', 'assign', 'ask', 'ask-accept', 'ask-decline', 'ask-more', 'ini-workflow', 'task', 'task-update', 'task-remove', 'task-restore', 'ticket-note', 'ini-epics', 'ini-archive', 'ini-notdup', 'ini-wf', 'ini-end', 'stage-judge', 'ini-auto', 'task-section', 'task-milestone', 'task-pin', 'ticket-dates', 'task-order',
179
179
  // split or merge initiatives (feedback batch 11 item 14): a Jira ticket moved to another initiative, the split and merge records with their Undo, Claude's suggestion dismissed
180
- 'ticket-move', 'ini-split', 'ini-merge', 'ini-sm-undo', 'ini-suggest',
180
+ 'ticket-move', 'ini-split', 'ini-merge', 'ini-sm-undo', 'ini-suggest', 'backlog-rank',
181
181
  // Delete an initiative with its tasks, and its Undo (feedback batch 16 item 5d)
182
182
  'ini-delete', 'ini-restore']);
183
183
  // A task's state is its only stage (Wawan, 2026-10-25): the same five every workflow ends in. An old 'In review' reads as In progress (taskState).
@@ -227,6 +227,7 @@ function fold(events) {
227
227
  // split or merge (batch 11 item 14): Jira key → the initiative it moved to (a split or a merge; `to: null` sends it back to where Jira puts it),
228
228
  // op id → the ini-split / ini-merge line (its `undo` says how to put everything back), the ops undone, and the PM's ✕ on Claude's suggestion
229
229
  const ticketMoves = new Map();
230
+ const backlogRank = new Map(); // board → [task id], the Backlog's rank (backlog-rank lines)
230
231
  const smOps = new Map();
231
232
  const smUndone = new Set();
232
233
  const suggestNo = new Map(); // initiative id → { kind, fp, at } (the last ✕; a suggestion with another fingerprint shows again)
@@ -378,6 +379,10 @@ function fold(events) {
378
379
  const a = asks.get(e.ask);
379
380
  if (a.state !== 'open') continue;
380
381
  Object.assign(a, { state: 'declined', why: e.why || '', closedAt: e.at || null });
382
+ } else if (e.kind === 'backlog-rank' && b && Array.isArray(e.order)) {
383
+ // the Backlog's one rank across initiatives (D105; Work's Backlog, WorkBacklogDS): the board's open tasks, top first; [] clears it
384
+ const ids = [...new Set(e.order.filter((x) => typeof x === 'string' && x && x.length <= 120))];
385
+ if (ids.length) backlogRank.set(b, ids); else backlogRank.delete(b);
381
386
  } else if (e.kind === 'ticket-move' && typeof e.key === 'string' && JIRA_KEY_RE.test(e.key)) {
382
387
  if (typeof e.to === 'string' && e.to) ticketMoves.set(e.key.toUpperCase(), e.to); else ticketMoves.delete(e.key.toUpperCase());
383
388
  } else if ((e.kind === 'ini-split' || e.kind === 'ini-merge') && typeof e.op === 'string' && e.op && !smOps.has(e.op)) {
@@ -388,7 +393,7 @@ function fold(events) {
388
393
  suggestNo.set(e.id, { kind: e.of === 'merge' ? 'merge' : 'split', fp: e.fp, at: e.at || null });
389
394
  }
390
395
  }
391
- return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, removed, sections, orders, milestones, pins, ticketNotes, ticketDates, epics, archives, deleted, notDup, iniWf, ends, judged, autoOver, ticketMoves, smOps, smUndone, suggestNo, events: list };
396
+ return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, removed, sections, orders, milestones, pins, ticketNotes, ticketDates, epics, archives, deleted, notDup, iniWf, ends, judged, autoOver, ticketMoves, backlogRank, smOps, smUndone, suggestNo, events: list };
392
397
  }
393
398
 
394
399
  /** The stages an initiative runs on a board: its own workflow when one is recorded, else the board's. */
@@ -19,6 +19,9 @@
19
19
  * lib/sprint-history.js detailOf. GET /api/backlog also carries sprintList (the picker, SpH1) and
20
20
  * sprintTrend (the carried-over line and bars), and sprintNow (This sprint: every task in the
21
21
  * active sprint's dates, Jira and not, done ones too; lib/sprint-now.js).
22
+ * POST /api/backlog/rank { ws, board, order: [id] } the Backlog's one rank across initiatives (a backlog-rank line on the board
23
+ * ledger; D105). GET /api/backlog carries it as backlogRank, each task's inSprint and touched (its last
24
+ * change), and sprintNext (the earliest future sprint, as Jira holds it).
22
25
  * POST /api/backlog/place { ws, board, key, to } a No home Jira ticket into an initiative (a ticket-move line on the board
23
26
  * ledger, as a split or merge writes it; Jira is not written to, D88). to '' takes it back out.
24
27
  *
@@ -98,6 +101,17 @@ function readingsOf(w, jiraStatus) {
98
101
  }
99
102
 
100
103
  /** One board's tasks, as GET /api/backlog answers them. → { ok, ... } | { pending } | { error, status } */
104
+ /** When a task was last touched: a PMOS task's last line on its ledger, a Jira ticket's last update as Jira gave it. → (task) → 'YYYY-MM-DD' | '' */
105
+ function touchedOf(folded, R) {
106
+ return (t) => {
107
+ if (t.src === 'jira') { const rd = R.get(String(t.key || t.id).toUpperCase()); return rd && rd.updated ? String(rd.updated).slice(0, 10) : ''; }
108
+ const f = folded && folded.get ? folded.get(t.id) : null;
109
+ if (!f) return '';
110
+ const ats = [f.at, ...(f.history || []).map((h) => h.at)].filter((x) => typeof x === 'string' && x).sort();
111
+ return ats.length ? ats[ats.length - 1].slice(0, 10) : '';
112
+ };
113
+ }
114
+
101
115
  function listOf(ctx, wsId, boardId, now) {
102
116
  const RB = require('./routes-boards.js');
103
117
  const jiraStatus = require('./jira-status.js');
@@ -133,7 +147,13 @@ function listOf(ctx, wsId, boardId, now) {
133
147
  try { sprintList = SH.listOf(sin); sprintTrend = SH.trendOf(sprintList); } catch { sprintList = []; sprintTrend = null; }
134
148
  // This sprint (WorkSprintDS): all work in the sprint's dates, Jira and not, done work too
135
149
  let sprintNow = []; try { sprintNow = SN.sprintsNowOf({ R, tasks, items, inis, projects: sin.projects, today, me: actorLib.PM_SLUG, pmName: pmNameOf() }); } catch { sprintNow = []; }
136
- return { ok: true, ws: w.id, board: board.id, product, mode, sprintNotes, sprintList, sprintTrend, sprintNow, _sin: sin, modeLabel: BL.MODE_LABEL[mode], kinds: BL.countKinds(inis.map((x) => x.kind)), factory, readAt, today,
150
+ // the Backlog (WorkBacklogDS): what waits outside the sprint, its one rank across initiatives, when each task was last touched, the next sprint
151
+ const inSprint = new Set(sprintNow.flatMap((sp) => sp.rows.map((r) => r.id)));
152
+ const touched = touchedOf(fr.folded.tasks, R);
153
+ for (const t of tasks) { t.inSprint = inSprint.has(t.id); const at = touched(t); if (at) t.touched = at; }
154
+ const backlogRank = (fr.folded.backlogRank && fr.folded.backlogRank.get(board.id)) || [];
155
+ let sprintNext = null; try { sprintNext = SN.nextSprintOf(R, sin.projects); } catch { sprintNext = null; }
156
+ return { ok: true, ws: w.id, board: board.id, product, mode, sprintNotes, sprintList, sprintTrend, sprintNow, sprintNext, backlogRank, _sin: sin, modeLabel: BL.MODE_LABEL[mode], kinds: BL.countKinds(inis.map((x) => x.kind)), factory, readAt, today,
137
157
  tasks, inis: inis.map((x) => ({ id: x.id, title: x.title, kind: x.kind })), _w: w, _RB: RB, _runTasks: runTasks };
138
158
  }
139
159
 
@@ -202,7 +222,7 @@ async function handle(req, res, url, ctx) {
202
222
  if (!d) return send(bad(404, 'PMOS knows no sprint of that name on this board'));
203
223
  return send({ status: 200, body: { ok: true, ws: L.ws, board: L.board, sprint: d } });
204
224
  }
205
- if (!['give', 'stop', 'decide', 'undo', 'decline', 'place', 'sprint-draft', 'sprint-note'].includes(sub)) return send(bad(404, 'no such route'));
225
+ if (!['give', 'stop', 'decide', 'undo', 'decline', 'place', 'rank', 'sprint-draft', 'sprint-note'].includes(sub)) return send(bad(404, 'no such route'));
206
226
  if (req.method !== 'POST') return send(bad(405, 'POST only'));
207
227
  const read = await ctx.readJson(req);
208
228
  if (!read.ok || !read.body || typeof read.body !== 'object') return send(bad(400, 'the body must be a JSON object'));
@@ -251,6 +271,16 @@ async function handle(req, res, url, ctx) {
251
271
  return send({ status: 200, body: { ok: true, key, to, from: was } });
252
272
  }
253
273
 
274
+ // the Backlog's one rank across initiatives (D105; WorkBacklogDS): a drag writes the board's whole order, top first; [] clears it
275
+ if (sub === 'rank') {
276
+ if (!Array.isArray(body.order) || body.order.length > 2000 || body.order.some((x) => typeof x !== 'string' || !x || x.length > 120)) return send(bad(400, 'order is a list of at most 2000 task ids, top first'));
277
+ const file = L._RB.ledgerFile(ctx, L._w);
278
+ if (!file) return send(bad(409, L._RB.NO_STATE));
279
+ const order = [...new Set(body.order)];
280
+ L._RB.append(file, g.actor, { kind: 'backlog-rank', board, order, why: order.length ? 'reranked in the Backlog' : 'rank taken out' });
281
+ return send({ status: 200, body: { ok: true, from: L.backlogRank || [] } });
282
+ }
283
+
254
284
  if (sub === 'give') {
255
285
  const ids = Array.isArray(body.tasks) ? body.tasks.map(text).filter(Boolean).slice(0, 50) : [text(body.task)].filter(Boolean);
256
286
  if (!ids.length) return send(bad(400, 'tasks is a list of task ids'));
@@ -11,6 +11,7 @@
11
11
  * title }], projects: [Jira project key] (empty = every project), today: 'YYYY-MM-DD', me, pmName }
12
12
  * row: { uid, id, src: jira|pmos, key, title, ini, iniTitle, who, state: To do|In progress|In review|Done, due, late (days), moved (other
13
13
  * sprints the ticket was in), url, open (the row is in the Backlog's task list, so it opens as a task) }
14
+ * nextSprintOf(R, projects) → { name, label, start, end } | null the earliest future sprint (the Backlog pulls work into it)
14
15
  */
15
16
  const BL = require('./backlog.js');
16
17
 
@@ -76,4 +77,20 @@ function sprintsNowOf(I) {
76
77
  }).sort((a, b) => b.total - a.total || a.name.localeCompare(b.name));
77
78
  }
78
79
 
79
- module.exports = { sprintsNowOf, labelOf };
80
+ /** The board's next sprint, as Jira holds it: the earliest future sprint of the board's projects. → { name, label, start, end } | null */
81
+ function nextSprintOf(R, projects) {
82
+ const P = (projects || []).length ? new Set(projects.map((p) => String(p).toUpperCase())) : null;
83
+ const by = new Map();
84
+ for (const rd of (R instanceof Map ? R.values() : [])) {
85
+ if (!rd || !rd.key || !rd.sprint || rd.sprint.state !== 'future' || !rd.sprint.name) continue;
86
+ if (P && !P.has(String(rd.key).toUpperCase().split('-')[0])) continue;
87
+ const n = String(rd.sprint.name);
88
+ if (!by.has(n)) by.set(n, { name: n, label: labelOf(n), start: null, end: null });
89
+ const x = by.get(n);
90
+ if (!x.start && rd.sprint.start) x.start = String(rd.sprint.start).slice(0, 10);
91
+ if (!x.end && rd.sprint.end) x.end = String(rd.sprint.end).slice(0, 10);
92
+ }
93
+ return [...by.values()].sort((a, b) => (a.start || '9999').localeCompare(b.start || '9999') || a.name.localeCompare(b.name))[0] || null;
94
+ }
95
+
96
+ module.exports = { sprintsNowOf, nextSprintOf, labelOf };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.648.0",
3
+ "version": "0.649.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.648.0",
9
+ "version": "0.649.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.648.0",
3
+ "version": "0.649.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -0,0 +1,176 @@
1
+ /* pm/bd-backlog-ds.js — the Backlog built from the design system's parts (initiative work-ds-backlog; Exploring 3 page "work", board
2
+ * WorkBacklogDS). Pure: HTML and numbers from data, no state, no fetch. pm/bd-backlog.js keeps the state and the presses.
3
+ *
4
+ * THE RULES, stated once (the guide says them too):
5
+ * · The Backlog is the open work outside the active sprint (GET /api/backlog marks each task inSprint; lib/sprint-now.js).
6
+ * · Ready = in an initiative, with an owner, not started, and PMOS is not working on it. Needs detail = the rest.
7
+ * · Untouched = no change for 60 days (a task's last ledger line; a Jira ticket's last update as Jira gave it). A row says how long from
8
+ * 30 days on.
9
+ * · The rank is one list across initiatives (D105): the board's backlog-rank line first, then the rest by initiative, due date and name.
10
+ * Groups follow their best-ranked row; "No initiative yet" goes last. A row's number is its place in that one list.
11
+ */
12
+ import { sugHtml } from './bd-stands.js';
13
+
14
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
15
+ const SV = (d, n = 16) => `<svg class="pm-ic" width="${n}" height="${n}" viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
16
+ const I = { star: 'M12 3l1.8 5.4L19 10.2l-5.2 1.8L12 17.4l-1.8-5.4L5 10.2l5.2-1.8z', grip: 'M9 6h.01M15 6h.01M9 12h.01M15 12h.01M9 18h.01M15 18h.01', down: 'M7 10l5 5 5-5' };
17
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
18
+ const DAY = 864e5;
19
+ const dayNum = (d) => { const t = Date.parse(String(d || '').slice(0, 10) + 'T00:00:00Z'); return Number.isFinite(t) ? Math.round(t / DAY) : null; };
20
+ export const dayText = (d) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(d || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
21
+ const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
22
+ const NOINI = '~';
23
+ export const STALE = 60; // Untouched 60 days
24
+ const SAY_FROM = 30; // a row says how long it sat from 30 days on
25
+
26
+ /** In the Backlog: open, outside the active sprint, not finished by PMOS today. */
27
+ export const inBacklog = (t) => !!t && !t.inSprint && !(t.agent && t.agent.state === 'done' && t.agent.today !== false) && t.state !== 'Done';
28
+ const pmosHas = (t) => !!(t.agent && t.agent.state !== 'failed');
29
+ /** Ready for a sprint: in an initiative, with an owner, not started, and PMOS is not working on it. */
30
+ export const isReady = (t) => !!t.ini && !!t.who && t.whoKind !== 'none' && t.state === 'To do' && !pmosHas(t);
31
+ /** Days since the task was last touched, or null when PMOS does not know. */
32
+ export const idleOf = (t, today) => { const a = dayNum(t.touched), b = dayNum(today); return a == null || b == null ? null : Math.max(0, b - a); };
33
+ export const isStale = (t, today) => { const d = idleOf(t, today); return d != null && d >= STALE; };
34
+
35
+ export const TABS = [['all', 'All'], ['ready', 'Ready'], ['detail', 'Needs detail'], ['stale', 'Untouched 60 days']];
36
+ export const GROUPS = [['ini', 'Initiative'], ['pmos', 'What PMOS can do'], ['none', 'None']];
37
+ export function keepsTab(t, tab, today) {
38
+ if (tab === 'ready') return isReady(t);
39
+ if (tab === 'detail') return !isReady(t);
40
+ if (tab === 'stale') return isStale(t, today);
41
+ return true;
42
+ }
43
+ export function countsOf(B, today) { const c = { all: B.length, ready: 0, detail: 0, stale: 0 }; for (const t of B) { if (isReady(t)) c.ready++; else c.detail++; if (isStale(t, today)) c.stale++; } return c; }
44
+
45
+ /** The one rank across initiatives. B: the backlog's tasks; rank: [task id] (the board's backlog-rank line); inis: [{ id, title }] in the
46
+ * board's order. → the tasks in rank order, grouped: the groups follow their best-ranked row, "No initiative yet" last. */
47
+ export function ranked(B, rank, inis) {
48
+ const at = new Map((rank || []).map((id, i) => [id, i]));
49
+ const io = new Map((inis || []).map((x, i) => [x.id, i]));
50
+ const base = B.slice().sort((a, b) => {
51
+ const ra = at.has(a.id) ? at.get(a.id) : Infinity, rb = at.has(b.id) ? at.get(b.id) : Infinity;
52
+ if (ra !== rb) return ra - rb;
53
+ const ia = a.ini && io.has(a.ini) ? io.get(a.ini) : a.ini ? 9e8 : 9e9, ib = b.ini && io.has(b.ini) ? io.get(b.ini) : b.ini ? 9e8 : 9e9;
54
+ return ia - ib || (a.due || '9999').localeCompare(b.due || '9999') || String(a.title).localeCompare(String(b.title));
55
+ });
56
+ const groups = new Map();
57
+ for (const t of base) { const k = t.ini || NOINI; if (!groups.has(k)) groups.set(k, []); groups.get(k).push(t); }
58
+ const keys = [...groups.keys()].filter((k) => k !== NOINI).concat(groups.has(NOINI) ? [NOINI] : []);
59
+ return keys.flatMap((k) => groups.get(k));
60
+ }
61
+ /** The order a drag writes: the ranked list with `id` moved before `before` (or to the end of its group's list when before is ''). */
62
+ export function moved(order, id, before) {
63
+ const L = order.filter((x) => x !== id);
64
+ const i = before ? L.indexOf(before) : -1;
65
+ if (i < 0) L.push(id); else L.splice(i, 0, id);
66
+ return L;
67
+ }
68
+
69
+ /** Where it stands: what waits, what is ready for the next sprint, what is stale, what has no owner. Zero is silence. → [sentence] */
70
+ export function standsOf(B, o = {}) {
71
+ if (!B.length) return [];
72
+ const R = B.filter(isReady), stale = B.filter((t) => isStale(t, o.today)).length, noIni = B.filter((t) => !t.ini).length;
73
+ const out = [plural(B.length, 'item waits', 'items wait') + ' outside a sprint.'];
74
+ if (R.length) {
75
+ const nx = o.next;
76
+ const into = nx ? ` to pull into ${nx.label || nx.name}${nx.start ? ', which starts ' + dayText(nx.start) : ''}` : ' for the next sprint';
77
+ const by = new Map(); for (const t of R) by.set(t.iniTitle || t.ini, (by.get(t.iniTitle || t.ini) || 0) + 1);
78
+ const top = [...by].sort((a, b) => b[1] - a[1]);
79
+ const most = top.length > 1 && top[0][1] + (top[1] ? top[1][1] : 0) > R.length / 2 ? (top[1][1] > 1 ? `${top[0][0]} and ${top[1][0]}` : top[0][0]) : top.length === 1 && R.length > 1 ? top[0][0] : '';
80
+ out.push(`${R.length === B.length ? (R.length === 1 ? 'It is' : 'All are') : R.length + (R.length === 1 ? ' is' : ' are')} ready${into}${most ? `; most of them are ${most} work` : ''}.`);
81
+ }
82
+ const tail = [stale ? `${stale} ${stale === 1 ? 'has' : 'have'} not been touched in ${STALE} days` : '', noIni ? `${noIni} ${noIni === 1 ? 'has' : 'have'} no initiative, so nobody owns ${noIni === 1 ? 'it' : 'them'} yet` : ''].filter(Boolean);
83
+ if (tail.length) out.push(tail.join(', and ').replace(/^./, (c) => c.toUpperCase()) + '.');
84
+ return out;
85
+ }
86
+
87
+ /** The Suggestion: pull the top ready items into the next sprint. PMOS tasks get the sprint's dates; a Jira ticket is named for the PM to
88
+ * move in Jira (PMOS does not write to Jira). No next sprint with dates, or no task PMOS can date: no Suggestion. → { s, ids } | null */
89
+ export function pullOf(order, next, n = 4) {
90
+ if (!next || !next.start || !next.end) return null;
91
+ const top = order.filter(isReady).slice(0, n);
92
+ const mine = top.filter((t) => t.src === 'pmos'), jira = top.filter((t) => t.src === 'jira');
93
+ if (!mine.length) return null;
94
+ const name = next.label || next.name, when = `${dayText(next.start)} to ${dayText(next.end)}`;
95
+ const names = (L) => (L.length <= 3 ? L.map((t) => t.title).join(', ').replace(/, ([^,]*)$/, ' and $1') : L.length + ' tasks');
96
+ const s = {
97
+ title: `Pull the ${top.length === 1 ? 'top ready item' : top.length + ' top ready items'} into ${name}`,
98
+ why: `${name} starts ${dayText(next.start)}. ${top.length === 1 ? 'This item is' : 'These are'} ranked highest of the ready work: in an initiative, with an owner, not started.`,
99
+ will: [`Give ${names(mine)} the dates of ${name} (${when})`].concat(jira.length ? [`List ${jira.map((t) => t.key).join(', ')} for you to add to ${name} in Jira`] : []),
100
+ changes: `${name} holds ${mine.length === 1 ? 'it' : 'them'} when it starts.${jira.length ? ' PMOS does not change Jira.' : ''} Nothing is sent to anyone.`,
101
+ basis: `The rank in this backlog, ${name}'s dates in Jira`,
102
+ };
103
+ return { s, ids: mine.map((t) => t.id), keys: jira.map((t) => t.key) };
104
+ }
105
+
106
+ /** The Where it stands block. → '' when there is nothing to say. */
107
+ export function standsHtml(B, o = {}) {
108
+ const S = standsOf(B, o);
109
+ const p = o.pull ? sugHtml(o.pull.s, `data-ids="${esc(o.pull.ids.join(' '))}"`, 'data-bksug') : '';
110
+ if (!S.length && !p) return '';
111
+ return `<section class="pm-block wk-stands" aria-label="Where it stands"><h2 class="pm-h-sm pm-row">${SV(I.star).replace('pm-ic', 'pm-ic pm-star')}Where it stands</h2>`
112
+ + (S.length ? `<p class="wk-say">${esc(S.join(' '))}</p>` : '') + p + '</section>';
113
+ }
114
+
115
+ /** The capture: which initiative a line names. The words "in <x>" or "for <x>" first, then the initiative sharing most words with the line.
116
+ * → { title, ini } | { title, ini: null } when nothing fits (the page asks). */
117
+ const WORDS = (s) => String(s || '').toLowerCase().match(/[a-z0-9]{3,}/g) || [];
118
+ const SMALL = new Set(['the', 'and', 'for', 'with', 'into', 'from', 'this', 'that', 'add']);
119
+ export function captureOf(line, inis) {
120
+ const text = String(line || '').trim();
121
+ if (!text) return null;
122
+ const L = inis || [];
123
+ const m = /^(.*?)\s+(?:in|for|under|to)\s+(.+?)\s*$/i.exec(text);
124
+ if (m) {
125
+ const want = m[2].toLowerCase();
126
+ const hit = L.find((x) => x.title.toLowerCase() === want) || L.find((x) => x.title.toLowerCase().startsWith(want)) || L.find((x) => x.title.toLowerCase().includes(want));
127
+ if (hit) return { title: m[1].trim(), ini: hit.id };
128
+ }
129
+ const w = new Set(WORDS(text).filter((x) => !SMALL.has(x)));
130
+ const best = L.map((x) => ({ x, n: WORDS(x.title).filter((y) => w.has(y)).length })).filter((s) => s.n > 0).sort((a, b) => b.n - a.n);
131
+ if (best.length && (best.length === 1 || best[0].n > best[1].n)) return { title: text, ini: best[0].x.id, guessed: true };
132
+ return { title: text, ini: null };
133
+ }
134
+
135
+ /** The Backlog block. o: { tab, group, menu, today, rank (number by id), sel: Set of uids, picking, act(t) → the row's action html,
136
+ * stateOf(t) → { text, tone } for PMOS's own states, groupsPmos(rows) → [{ k, n, rows, yes }], mode (the kind-of-work line's html) } */
137
+ export function tableHtml(order, o = {}) {
138
+ const c = countsOf(order, o.today), tab = o.tab || 'all', group = o.group || 'ini';
139
+ const tabs = `<div class="pm-tabs" role="tablist" aria-label="Show">${TABS.filter(([k]) => k === 'all' || c[k] || k === tab).map(([k, n]) => `<button type="button" class="pm-tab" role="tab" aria-selected="${k === tab}" data-bktab="${k}">${n} <span class="pm-meta">${c[k]}</span></button>`).join('')}</div>`;
140
+ const gname = (GROUPS.find(([k]) => k === group) || GROUPS[0])[1];
141
+ const menu = `<span class="wk-mw"><button type="button" class="pm-tab wk-gb" data-bkgroup aria-haspopup="menu" aria-expanded="${!!o.menu}">Group: ${gname}${SV(I.down, 14)}</button>`
142
+ + (o.menu ? `<div class="pm-menu wk-gm" role="menu" aria-label="Group">${GROUPS.map(([k, n]) => `<button type="button" role="menuitemradio" aria-checked="${k === group}" data-bkgrp="${k}">${n}</button>`).join('')}</div>` : '') + '</span>';
143
+ const tune = `<button type="button" class="pm-btn" data-bktune aria-label="Filter" title="Filter">${SV('M4 7h9M17 7h3M4 17h3M11 17h9M15 5v4M9 15v4')}</button>`;
144
+ const cap = '<input class="pm-input wk-cap" type="text" data-bkcap placeholder="Add to the backlog; say the initiative, or PMOS picks one" aria-label="Add to the backlog">';
145
+ const R = order.filter((t) => keepsTab(t, tab, o.today));
146
+ let G;
147
+ if (group === 'pmos' && o.groupsPmos) G = o.groupsPmos(R);
148
+ else if (group === 'none') G = [{ k: '', n: '', rows: R }];
149
+ else {
150
+ const m = new Map();
151
+ for (const t of R) { const k = t.ini || NOINI; if (!m.has(k)) m.set(k, { k, n: t.ini ? t.iniTitle || t.ini : 'No initiative yet', rows: [] }); m.get(k).rows.push(t); }
152
+ G = [...m.values()];
153
+ const whole = new Map(); for (const t of order) { const k = t.ini || NOINI; const e = whole.get(k) || { n: 0, r: 0 }; e.n++; if (isReady(t)) e.r++; whole.set(k, e); }
154
+ for (const g of G) { const e = whole.get(g.k); g.sub = `${plural(e.n, 'item', 'items')} · ${e.r} ready`; }
155
+ }
156
+ const drag = group !== 'pmos';
157
+ const body = G.map((g) => (g.n ? `<tr class="wk-g"><td colspan="7"><div class="pm-group"><b>${esc(g.n)}</b>${g.sub ? ` <span class="pm-meta">${esc(g.sub)}</span>` : ''}${g.yes || ''}</div></td></tr>` : '')
158
+ + g.rows.map((t) => rowHtml(t, o, drag)).join('')).join('');
159
+ const table = R.length ? `<table class="pm-table wk-bkt${o.picking ? ' picking' : ''}"><thead><tr><th class="wk-rk">Rank</th><th>Item</th><th>Who</th><th>State</th><th>Source</th><th>Last change</th><th class="wk-ac" aria-label="Actions"></th></tr></thead><tbody>${body}</tbody></table>`
160
+ : `<p class="pm-meta">${order.length ? 'Nothing here.' : 'Nothing waits outside the sprint.'}</p>`;
161
+ const foot = R.length && drag ? '<p class="pm-meta">Drag a row to change its rank. The rank is one list across initiatives; groups only show where each item belongs.</p>' : '';
162
+ return `<section class="pm-block wk-blk wk-bk" aria-label="Backlog"><div class="head"><h2 class="pm-h">Backlog</h2><span class="sp"></span>${tabs}${menu}${tune}</div>${cap}${o.said || ''}${table}${foot}${o.mode || ''}</section>`;
163
+ }
164
+ function rowHtml(t, o, drag) {
165
+ const u = t.ws + '|' + t.board + '|' + t.id, ck = o.sel && o.sel.has(u);
166
+ const ready = isReady(t), idle = idleOf(t, o.today);
167
+ const who = pmosHas(t) ? '<span class="pm-star">✦</span> PMOS' : t.who ? esc(t.who) : '<span class="pm-meta">no one</span>';
168
+ const ps = o.stateOf ? o.stateOf(t) : null;
169
+ const state = ps ? `<span class="pm-badge${ps.tone === 'late' ? ' alert' : ' blue'}" title="${esc(ps.title || ps.text)}">${esc(ps.text)}</span>` : `<span class="pm-badge${ready ? ' blue' : ''}">${ready ? 'Ready' : 'Needs detail'}</span>`;
170
+ const src = t.key ? `<span class="pm-meta code">${esc(t.key)}</span>` : '<span class="pm-chip">Not in Jira</span>';
171
+ const n = o.rank ? o.rank.get(t.id) : null;
172
+ return `<tr class="wk-br${ck ? ' sel' : ''}" data-bk="${esc(u)}" data-bkid="${esc(t.id)}"${drag ? ' draggable="true"' : ''}>`
173
+ + `<td class="wk-rk"><span class="pm-row">${drag ? `<span class="wk-grip" aria-hidden="true">${SV(I.grip, 14)}</span>` : ''}<input type="checkbox" class="wk-ck" data-bkck="${esc(u)}" aria-label="Tick ${esc(t.title)}"${ck ? ' checked' : ''}><span class="pm-meta">${n != null ? n + 1 : ''}</span></span></td>`
174
+ + `<td><button type="button" class="wk-tt" data-bkopen="${esc(u)}" title="${esc(t.title)}">${esc(t.title)}</button>${idle != null && idle >= SAY_FROM ? ` <span class="pm-badge">${idle} days untouched</span>` : ''}${t.late ? ` <span class="pm-badge alert">${plural(t.late, 'day late', 'days late')}</span>` : ''}</td>`
175
+ + `<td>${who}</td><td>${state}</td><td>${src}</td><td><span class="pm-meta code">${t.touched ? dayText(t.touched) : ''}</span></td><td class="wk-ac">${o.act ? o.act(t) : ''}</td></tr>`;
176
+ }
@@ -15,14 +15,15 @@
15
15
  * with Undo where the route has one. The words say PMOS, never the model's name. pm/premium-board.js calls sync() after each read of the board. */
16
16
  import * as BM from './bk-model.js';
17
17
  import { productName } from './scope-chip.js'; // the product's display name ("IDPF"), never its folder id
18
- import * as SP from './bd-sprint.js'; // the sprint overview while "This sprint" is on (initiative sprint-overview)
18
+ import * as SP from './bd-sprint.js';
19
+ import * as BD from './bd-backlog-ds.js'; // the Backlog from the system's parts (WorkBacklogDS) // the sprint overview while "This sprint" is on (initiative sprint-overview)
19
20
 
20
21
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
21
22
  const SV = (d, n) => `<svg viewBox="0 0 24 24"${n ? ` width="${n}" height="${n}"` : ''} aria-hidden="true"><path d="${d}"/></svg>`;
22
23
  const I = {
23
24
  chev: 'M9 6l6 6-6 6', down: 'M7 10l5 5 5-5', ok: 'M5 12.5l4.5 4.5L19 7', x: 'M6 6l12 12M18 6L6 18', more: 'M5 12h.01M12 12h.01M19 12h.01',
24
25
  undo: 'M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3', jira: 'M12 3l9 9-9 9-9-9z', task: 'M6 6h12v12H6z', ms: 'M12 4l8 8-8 8-8-8z', back: 'M15 6l-6 6 6 6',
25
- ext: 'M14 4h6v6M20 4l-9 9M10 6H5v13h13v-5', ret: 'M20 5v7a4 4 0 0 1-4 4H5M9 12l-4 4 4 4',
26
+ ext: 'M14 4h6v6M20 4l-9 9M10 6H5v13h13v-5', eye: 'M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12zM12 9a3 3 0 1 0 0 6 3 3 0 0 0 0-6z', ret: 'M20 5v7a4 4 0 0 1-4 4H5M9 12l-4 4 4 4',
26
27
  };
27
28
  const SPARK = '✦';
28
29
  const KEY = 'pmos.backlog.view';
@@ -41,10 +42,14 @@ let SEL = new Set(); // ticked rows: ws|board|id
41
42
  let host = null, sw = null;
42
43
  let iniApplied = false; // ?ini= is read once
43
44
  let SAID = null; // the one line after a Yes: { text, undo }
45
+ // the Backlog tab (WorkBacklogDS): its tab, its group, the Group menu, the pulls the PM said no to (kept in this browser)
46
+ let BMENU = false;
47
+ const PULLNO = 'pmos.backlog.pullno';
44
48
 
45
49
  const box = () => { try { return typeof localStorage !== 'undefined' ? localStorage : null; } catch { return null; } };
46
50
  const get = (k, d) => { try { const s = box(); const v = s ? JSON.parse(s.getItem(k) || 'null') : null; return v == null ? d : v; } catch { return d; } };
47
51
  const put = (k, v) => { try { const s = box(); if (s) s.setItem(k, JSON.stringify(v)); } catch { /* a private window keeps it for this page */ } };
52
+ const BV = (() => { const v = get('pmos.work.backlog', {}) || {}; return { tab: BD.TABS.some(([k]) => k === v.tab) ? v.tab : 'all', group: BD.GROUPS.some(([k]) => k === v.group) ? v.group : 'ini' }; })();
48
53
  const scopeKey = () => (A ? A.scope().map((s) => s.ws + '|' + (s.board || '')).sort().join(',') : '');
49
54
  const uidOf = (t) => t.ws + '|' + t.board + '|' + t.id;
50
55
 
@@ -87,6 +92,7 @@ export async function load() {
87
92
  // the oldest Jira read of the pick (the sprint band says when Jira was last read) and the PM's edits of each sprint's overview
88
93
  const reads = ok.map((r) => r.readAt).filter(Boolean).sort();
89
94
  DATA = { readAt: reads[0] || null, hist: ok.map((r) => ({ ws: r.ws, board: r.board, list: r.sprintList || [], trend: r.sprintTrend || null })),
95
+ rank: ok.flatMap((r) => r.backlogRank || []), next: (ok.find((r) => r.sprintNext) || {}).sprintNext || null, today: (ok[0] || {}).today || '',
90
96
  now: ok.flatMap((r) => (r.sprintNow || []).map((n) => ({ ...n, ws: r.ws, board: r.board, rows: (n.rows || []).map((x) => ({ ...x, ws: r.ws, board: r.board })) }))), notes: Object.fromEntries(ok.map((r) => [r.ws + '|' + r.board, r.sprintNotes || {}])), tasks: ok.flatMap((r) => r.tasks || []), modes: ok.map((r) => ({ product: productName(r.ws, r.product), mode: r.mode, label: r.modeLabel, kinds: r.kinds || null })), inis: ok.flatMap((r) => (r.inis || []).map((x) => ({ ...x, ws: r.ws, board: r.board, product: productName(r.ws, r.product) }))),
91
97
  err: ok.length ? (ok.length < S.length ? 'One product could not be read; its tasks are not here.' : '') : 'The tasks could not be read. Try again in a moment.', many: S.length > 1 };
92
98
  // ?ini=<initiative id> (the initiative popup's "Open in Backlog"): the Initiative facet starts on that initiative, once
@@ -133,6 +139,7 @@ function draw() {
133
139
  const said = SAID ? `<p class="bk-said" role="status">${esc(SAID.text)}${SAID.undo ? ' <button type="button" class="bk-lnk" data-bksaid>Undo</button>' : ''}</p>` : '';
134
140
  const sh = BM.showingLine(T, { chips: CHIPS, pick: PICK, partB: partB() });
135
141
  const showing = sh ? `<p class="bk-show">${esc(sh.text)}${sh.hidden ? ` · ${sh.hidden} hidden` : ''} · <button type="button" class="bk-lnk" data-bkall>Show all</button></p>` : '';
142
+ if (tabOf() === 'bk') { drawBk(); return; }
136
143
  // This sprint (WorkSprintDS): the Summary card and the Tasks Table, both pm/bd-sprint.js; a past sprint keeps its frozen view and list
137
144
  if (tabOf() === 'sp') {
138
145
  const card = SP.bandHtml({ tasks: T.filter(BM.isOpen), all: T, inis: DATA.inis, readAt: DATA.readAt, notes: DATA.notes, hist: DATA.hist, now: DATA.now }, spDeps());
@@ -157,6 +164,98 @@ function draw() {
157
164
  + (past != null ? past : `<div class="bk" role="table" aria-label="Backlog" style="--bk-cols: ${colsCss(cols)}">${head}${body}</div>`);
158
165
  drawBar();
159
166
  }
167
+ /* ── the Backlog tab (WorkBacklogDS): Where it stands with one Suggestion, then the Backlog block ───────────────────────── */
168
+ let ORDER = []; // the backlog in rank order, as drawn last
169
+ const backlogOf = () => DATA.tasks.filter(BD.inBacklog).filter((t) => BM.keeps(t, new Set(), PICK, partB()));
170
+ function pullFor(order) {
171
+ const p = BD.pullOf(order, DATA.next);
172
+ if (!p) return null;
173
+ const no = get(PULLNO, []) || [];
174
+ return no.includes(pullSig(p)) ? null : p;
175
+ }
176
+ const pullSig = (p) => (DATA.next ? DATA.next.name : '') + ':' + p.ids.concat(p.keys).join(',');
177
+ function drawBk() {
178
+ const B = backlogOf(), order = BD.ranked(B, DATA.rank, DATA.inis);
179
+ ORDER = order;
180
+ const rank = new Map(order.map((t, i) => [t.id, i]));
181
+ const sh = BM.showingLine(DATA.tasks, { chips: new Set(), pick: PICK, partB: partB() });
182
+ const showing = sh ? `<p class="pm-meta">${esc(sh.text)}${sh.hidden ? ` · ${sh.hidden} hidden` : ''} · <button type="button" class="wk-sa" data-bkall>Show all</button></p>` : '';
183
+ const said = SAID ? `<p class="pm-meta" role="status">${esc(SAID.text)}${SAID.undo ? ' <button type="button" class="wk-sa" data-bksaid>Undo</button>' : ''}</p>` : '';
184
+ const ml = BM.modeLine(DATA.modes);
185
+ const mode = ml ? `<p class="pm-meta">${esc(ml.lead)}<b>${esc(ml.label)}</b>${esc(ml.tail)}: ${esc(ml.what)} <button type="button" class="wk-sa" data-bkmode aria-haspopup="dialog">Change</button></p>` : '';
186
+ const pmosGroups = (R) => BM.groupsOf(R, { partB: partB(), sort: SORT }).map((g) => {
187
+ const can = yesRows(g, g.rows);
188
+ return { k: g.k, n: g.n, sub: g.sub, rows: g.rows, yes: can.length ? ` <button type="button" class="pm-btn" data-bkyes="${g.k}" aria-label="${esc(g.k === 'take' ? 'Give all ' + can.length + ' to PMOS' : 'Place all ' + can.length)}" title="${esc(g.k === 'take' ? 'Give all ' + can.length + ' to PMOS' : 'Place all ' + can.length)}">${SV(I.ok, 16)}</button>` : '' };
189
+ });
190
+ host.innerHTML = (DATA.err ? `<p class="bk-err">${esc(DATA.err)}</p>` : '')
191
+ + BD.standsHtml(B, { today: DATA.today, next: DATA.next, pull: pullFor(order) })
192
+ + BD.tableHtml(order, { tab: BV.tab, group: BV.group, menu: BMENU, today: DATA.today, rank, sel: SEL, picking: host.classList.contains('picking'),
193
+ act: (t) => actHtml(t, BM.groupOf(t, partB())), stateOf: (t) => { if (!t.agent) return null; const x = BM.stateOf(t); return { text: x.text, tone: x.tone, title: x.text + (x.note ? ' · ' + x.note : '') }; },
194
+ groupsPmos: pmosGroups, said: showing + said, mode });
195
+ drawBar();
196
+ }
197
+ const saveBv = () => put('pmos.work.backlog', BV);
198
+ /** A press only the Backlog tab has. → true when it was one. */
199
+ async function bkPress(e) {
200
+ const t0 = e.target, hit = (a) => t0.closest('[' + a + ']');
201
+ let b;
202
+ if ((b = hit('data-bktab'))) { BV.tab = b.dataset.bktab; saveBv(); draw(); const n = host.querySelector(`[data-bktab="${BV.tab}"]`); if (n) n.focus(); return true; }
203
+ if (hit('data-bkgroup')) { BMENU = !BMENU; draw(); const n = host.querySelector('[data-bkgrp][aria-checked="true"]'); if (BMENU && n) n.focus(); return true; }
204
+ if ((b = hit('data-bkgrp'))) { BV.group = b.dataset.bkgrp; BMENU = false; saveBv(); draw(); const n = host.querySelector('[data-bkgroup]'); if (n) n.focus(); return true; }
205
+ if (BMENU) { BMENU = false; draw(); }
206
+ if ((b = hit('data-bktune'))) { if (pop && pop.classList.contains('bk-tune')) closePop(); else tune(b); return true; }
207
+ if ((b = hit('data-bksug'))) {
208
+ const p = pullFor(ORDER); if (!p) return true;
209
+ const k = b.dataset.bksug, T = p.ids.map((id) => DATA.tasks.find((t) => t.id === id)).filter(Boolean);
210
+ if (k === 'no') { const no = get(PULLNO, []) || []; no.push(pullSig(p)); put(PULLNO, no.slice(-50)); AP().say('PMOS will not suggest this again.', () => { put(PULLNO, (get(PULLNO, []) || []).filter((x) => x !== pullSig(p))); draw(); }); draw(); return true; }
211
+ if (k === 'edit') { BV.tab = 'ready'; saveBv(); for (const t of T) SEL.add(uidOf(t)); draw(); AP().say(`Ticked ${T.length === 1 ? 'the item' : 'the ' + T.length + ' items'}. Change the ticks, then Set date.`); return true; }
212
+ await editMany(T, { start: DATA.next.start, due: DATA.next.end }, 'Into ' + (DATA.next.label || DATA.next.name) + (p.keys.length ? '. Add ' + p.keys.join(', ') + ' in Jira' : ''));
213
+ return true;
214
+ }
215
+ return false;
216
+ }
217
+ /** The capture: one line into the backlog, in the initiative it names, else the closest by its words, else PMOS asks. */
218
+ async function capture(inp) {
219
+ const line = inp.value.trim(); if (!line) return;
220
+ const L = DATA.inis || [], c = BD.captureOf(line, L);
221
+ const add = async (ini) => {
222
+ const x = L.find((y) => y.id === ini); if (!x) return;
223
+ const r = await post('/api/boards/tasks/add', { ws: x.ws, board: x.board, title: c.title.slice(0, 200), initiative: ini });
224
+ if (!r || r.ok === false || !r.item) { AP().say((r && r.error) || 'The task was not added.'); return; }
225
+ inp.value = '';
226
+ AP().say(`Added to ${x.title}: ${c.title}.`, async () => { await post('/api/boards/tasks/delete', { ws: x.ws, board: x.board, task: r.item.uid }); AP().say('Taken out.'); load(); AP().reload(); });
227
+ load(); AP().reload();
228
+ };
229
+ if (c.ini) { await add(c.ini); return; }
230
+ pickPop(inp, 'Which initiative?', L.map((x) => [x.id, x.title]), add);
231
+ }
232
+ /** A drag in the Backlog block: the row moves before the row it is dropped on, in the one rank; the board's order is written with Undo. */
233
+ let DRAG = '';
234
+ function dragWire() {
235
+ host.addEventListener('dragstart', (e) => { const r = e.target.closest && e.target.closest('tr.wk-br[draggable]'); if (!r) return; DRAG = r.dataset.bkid; r.classList.add('drag'); try { e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/plain', DRAG); } catch { /* old browser */ } });
236
+ host.addEventListener('dragend', () => { DRAG = ''; for (const n of host.querySelectorAll('.drag, .drop')) n.classList.remove('drag', 'drop'); });
237
+ host.addEventListener('dragover', (e) => { if (!DRAG) return; const r = e.target.closest('tr.wk-br'); if (!r) return; e.preventDefault(); for (const n of host.querySelectorAll('.drop')) if (n !== r) n.classList.remove('drop'); r.classList.add('drop'); });
238
+ host.addEventListener('drop', async (e) => {
239
+ const r = e.target.closest('tr.wk-br'); if (!DRAG || !r) return;
240
+ e.preventDefault();
241
+ const id = DRAG, before = r.dataset.bkid; DRAG = '';
242
+ if (id === before) { draw(); return; }
243
+ await rerank(BD.moved(ORDER.map((t) => t.id), id, before), ORDER.find((t) => t.id === id));
244
+ });
245
+ }
246
+ async function rerank(ids, t) {
247
+ if (!t) return;
248
+ const by = byBoard(ORDER), back = [];
249
+ for (const [, ts] of by) {
250
+ const mine = new Set(ts.map((x) => x.id));
251
+ const r = await post('/api/backlog/rank', { ws: ts[0].ws, board: ts[0].board, order: ids.filter((x) => mine.has(x)) });
252
+ if (!r || r.ok === false) { AP().say((r && r.error) || 'The rank was not changed.'); break; }
253
+ back.push({ ws: ts[0].ws, board: ts[0].board, from: r.from || [] });
254
+ }
255
+ if (back.length) AP().say('Reranked: ' + t.title + '.', async () => { for (const x of back) await post('/api/backlog/rank', { ws: x.ws, board: x.board, order: x.from }); AP().say('Put back.'); load(); });
256
+ DATA.rank = ids; draw(); load();
257
+ }
258
+
160
259
  /* ── the columns: Task first and the actions last, always; the ones between are a list, so the initiative popup can leave Initiative out ── */
161
260
  export const COLS = ['jira', 'epic', 'ini', 'who', 'state'];
162
261
  const COL = { jira: ['Jira ticket', '104px'], epic: ['Epic', 'minmax(80px, 130px)'], ini: ['Initiative', 'minmax(110px, 160px)'], who: ['Who', '76px'], due: ['Due', 'minmax(80px, 150px)'], state: ['State', 'minmax(200px, 290px)'] };
@@ -192,6 +291,16 @@ function whoHtml(t) {
192
291
  if (t.agent && t.agent.state !== 'failed') return `<span class="bk-pm">${SPARK} PMOS</span>`;
193
292
  return t.who ? esc(t.who) : '<span class="q">None</span>';
194
293
  }
294
+ /** The row's action, by its group: Review, ⋯ (PMOS is working), ✓ ✕ (PMOS can take it, or PMOS proposes a home), Undo (done today). */
295
+ function actHtml(t, gk) {
296
+ const u = uidOf(t);
297
+ let act = '';
298
+ if (gk === 'review') act = `<button type="button" class="bk-ib" data-bkrev="${esc(u)}" aria-label="Review what PMOS made: ${esc(t.title)}" title="Review">${SV(I.eye)}</button>`;
299
+ else if (gk === 'working') act = `<button type="button" class="bk-ib" data-bkmenu="${esc(u)}" aria-label="More for ${esc(t.title)}" title="More">${SV(I.more)}</button>`;
300
+ else if (gk === 'take' || (gk === 'nohome' && t.propose)) act = `<span class="bk-two"><button type="button" class="bk-ib" data-bkok="${esc(u)}" aria-label="${gk === 'take' ? 'Give to PMOS' : 'Put it in ' + esc(t.propose.title)}" title="${gk === 'take' ? 'Give to PMOS' : 'Put it there'}">${SV(I.ok)}</button><button type="button" class="bk-ib" data-bkno="${esc(u)}" aria-label="${gk === 'take' ? 'Not for PMOS' : 'Not there'}" title="${gk === 'take' ? 'Not for PMOS' : 'Not there'}">${SV(I.x)}</button></span>`;
301
+ else if (gk === 'done') act = `<button type="button" class="bk-ib" data-bkundo="${esc(u)}" aria-label="Undo: open ${esc(t.title)} again" title="Undo">${SV(I.undo)}</button>`;
302
+ return act;
303
+ }
195
304
  function rowHtml(t, gk, cols = COLS) {
196
305
  const u = uidOf(t), ck = SEL.has(u), s = BM.stateOf(t, gk, { noLate: cols.includes('due') });
197
306
  const icon = t.milestone ? `<i class="bk-ic ms" title="Milestone">${SV(I.ms)}</i>` : `<i class="bk-ic" title="Task">${SV(I.task)}</i>`;
@@ -199,11 +308,7 @@ function rowHtml(t, gk, cols = COLS) {
199
308
  const epic = t.src === 'jira' ? (t.epic ? `<span title="${esc(t.epic.name ? t.epic.name + ' (' + t.epic.key + ')' : t.epic.key)}">${esc(t.epic.name || t.epic.key)}</span>` : '<span class="q">No epic</span>') : '';
200
309
  const ini = t.ini ? `<span title="${esc(t.iniTitle)}">${esc(t.iniTitle)}</span>`
201
310
  : t.propose ? `<span class="bk-pm" title="${esc('PMOS proposes it: ' + t.propose.why)}">${SPARK} ${esc(t.propose.title)}</span>` : ''; // No home says it once, in its head
202
- let act = '';
203
- if (gk === 'review') act = `<button type="button" class="bk-rvb" data-bkrev="${esc(u)}">Review</button>`;
204
- else if (gk === 'working') act = `<button type="button" class="bk-ib" data-bkmenu="${esc(u)}" aria-label="More for ${esc(t.title)}" title="More">${SV(I.more)}</button>`;
205
- else if (gk === 'take' || (gk === 'nohome' && t.propose)) act = `<span class="bk-two"><button type="button" class="bk-ib" data-bkok="${esc(u)}" aria-label="${gk === 'take' ? 'Give to PMOS' : 'Put it in ' + esc(t.propose.title)}" title="${gk === 'take' ? 'Give to PMOS' : 'Put it there'}">${SV(I.ok)}</button><button type="button" class="bk-ib" data-bkno="${esc(u)}" aria-label="${gk === 'take' ? 'Not for PMOS' : 'Not there'}" title="${gk === 'take' ? 'Not for PMOS' : 'Not there'}">${SV(I.x)}</button></span>`;
206
- else if (gk === 'done') act = `<button type="button" class="bk-ib" data-bkundo="${esc(u)}" aria-label="Undo: open ${esc(t.title)} again" title="Undo">${SV(I.undo)}</button>`;
311
+ const act = actHtml(t, gk);
207
312
  const cell = {
208
313
  due: `<span class="c-due${t.late ? ' lt' : ''}">${t.due ? esc(dueText(t.due) + (t.late ? ' · ' + t.late + (t.late === 1 ? ' day late' : ' days late') : '')) : '<span class="q">No date</span>'}</span>`,
209
314
  jira: `<span class="c-jira">${jira}</span>`, epic: `<span class="c-epic">${epic}</span>`, ini: `<span class="c-ini">${ini}</span>`, who: `<span class="c-who">${whoHtml(t)}</span>`,
@@ -431,6 +536,7 @@ const taskOf = (u) => (SC ? SC.tasks() : DATA ? DATA.tasks : []).find((t) => uid
431
536
  async function press(e, emb) {
432
537
  const t0 = e.target;
433
538
  if (!emb && t0.closest('.sbo-band, .bk-past, [data-spall], .wk-sp, .wk-spt') && await SP.press(e, spDeps())) return;
539
+ if (!emb && tabOf() === 'bk' && await bkPress(e)) return;
434
540
  const chip = t0.closest('[data-bkchip]');
435
541
  if (chip) { const k = chip.dataset.bkchip; if (k === 'all') CHIPS.clear(); else if (CHIPS.has(k)) CHIPS.delete(k); else CHIPS.add(k); draw(); const n = host.querySelector(`[data-bkchip="${k}"]`); if (n) n.focus(); return; }
436
542
  if (t0.closest('[data-bkall]')) { CHIPS.clear(); PICK = {}; SP.clearTheme(); draw(); return; }
@@ -556,6 +662,8 @@ export function sync(api) {
556
662
  ib.insertAdjacentElement('afterend', host);
557
663
  host.addEventListener('click', (e) => { press(e); });
558
664
  host.addEventListener('change', (e) => { if (e.target.closest('[data-bkck]')) press(e); });
665
+ host.addEventListener('keydown', (e) => { const c = e.target.closest('[data-bkcap]'); if (c && e.key === 'Enter') { e.preventDefault(); capture(c); } });
666
+ dragWire();
559
667
  // a phone shows no tick boxes until a long press on a row (design check 1 h): the press ticks that row and shows the boxes
560
668
  let lp = null;
561
669
  const lpEnd = () => { if (lp) { clearTimeout(lp); lp = null; } };
@@ -136,6 +136,28 @@ body.bd-page.sp-on [id="bkBody"] { display: flex; flex-direction: column; gap: v
136
136
  .wk-spx .wk-due { gap: var(--space-8); flex-wrap: nowrap; }
137
137
  .wk-spx tr.wk-g td { padding: 0; }
138
138
 
139
+ /* ── Backlog (WorkBacklogDS): Where it stands, the capture, the ranked Table ── */
140
+ body.bd-page.bk-on [id="bdFilter"] { display: none; }
141
+ body.bd-page.bk-on [id="bkBody"] { display: flex; flex-direction: column; gap: var(--space-16); max-width: none; }
142
+ .wk-bk .wk-cap { margin: var(--space-4) 0; }
143
+ .wk-bkt td { white-space: nowrap; }
144
+ .wk-bkt td:nth-child(2) { white-space: normal; }
145
+ .wk-bkt th.wk-rk, .wk-bkt td.wk-rk { width: 64px; }
146
+ .wk-bkt td.wk-rk > .pm-row { gap: var(--space-4); flex-wrap: nowrap; }
147
+ .wk-bkt .wk-grip { color: var(--muted); cursor: grab; display: inline-flex; }
148
+ .wk-bkt .wk-ck { display: none; margin: 0; }
149
+ .wk-bkt tr:hover .wk-ck, .wk-bkt tr.sel .wk-ck, .wk-bkt.picking .wk-ck, .wk-bkt .wk-ck:focus-visible { display: inline-block; }
150
+ .wk-bkt tr:hover .wk-ck + .pm-meta, .wk-bkt tr.sel .wk-ck + .pm-meta, .wk-bkt.picking .wk-ck + .pm-meta { display: none; }
151
+ .wk-bkt .wk-tt { all: unset; cursor: pointer; font-weight: var(--fw-strong); }
152
+ .wk-bkt .wk-tt:hover { text-decoration: underline; }
153
+ .wk-bkt .wk-tt:focus-visible { box-shadow: var(--glow); border-radius: var(--radius-sm); }
154
+ .wk-bkt th.wk-ac, .wk-bkt td.wk-ac { width: 1%; text-align: right; }
155
+ .wk-bkt tr.drag td { opacity: .5; }
156
+ .wk-bkt tr.drop td { box-shadow: inset 0 2px 0 var(--blue); }
157
+ .wk-bkt tr.wk-g td { padding: 0; }
158
+ .wk-bkt .pm-group .pm-btn { margin-left: auto; }
159
+ .wk-bk > .pm-meta .wk-sa, .wk-bk .wk-sa { all: unset; cursor: pointer; color: var(--blue); }
160
+
139
161
  @media (max-width: 760px) {
140
162
  .wk-spcols { grid-template-columns: 1fr 1fr; }
141
163
  body.bd-page.wk-on .bd-hd, body.bd-page.bk-on .bd-hd { display: flex; }