create-pmos 0.737.0 → 0.738.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.737.0",
3
+ "version": "0.738.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.738.0",
38
+ "at": "2026-11-23T07:20:29.240Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 1639,
43
+ "t": "Every edit shows at once, and a failed save says so",
44
+ "s": "Every edit shows at once, and a failed save says so",
45
+ "k": "fix"
46
+ }
47
+ ]
48
+ },
36
49
  {
37
50
  "v": "0.737.0",
38
51
  "at": "2026-11-23T06:47:33.938Z",
@@ -429,85 +442,6 @@
429
442
  "k": "new"
430
443
  }
431
444
  ]
432
- },
433
- {
434
- "v": "0.713.0",
435
- "at": "2026-11-22T15:29:37.584Z",
436
- "f": 4,
437
- "prs": [
438
- {
439
- "n": 1568,
440
- "t": "Undo right on the item PMOS changed, for 24 hours (A456)",
441
- "s": "Undo right on the item PMOS changed, for 24 hours (A456)",
442
- "k": "new"
443
- },
444
- {
445
- "n": 1564,
446
- "t": "Offer to hide buttons not pressed in 14 days, with Undo and Show all (A454)",
447
- "s": "Offer to hide buttons not pressed in 14 days, with Undo and Show all (A454)",
448
- "k": "new"
449
- },
450
- {
451
- "n": 1571,
452
- "t": "Back restores your place (scroll and open sections)",
453
- "s": "Back restores your place (scroll and open sections)",
454
- "k": "new"
455
- },
456
- {
457
- "n": 1567,
458
- "t": "View preferences follow the person (job #1555)",
459
- "s": "View preferences follow the person (job #1555)",
460
- "k": "new"
461
- },
462
- {
463
- "n": 1570,
464
- "t": "Product switcher row with a quiet dot on products that need you (job #1547)",
465
- "s": "Product switcher row with a quiet dot on products that need you (job #1547)",
466
- "k": "new"
467
- },
468
- {
469
- "n": 1575,
470
- "t": "Set up a routine from one typed sentence (job #1546)",
471
- "s": "Set up a routine from one typed sentence (job #1546)",
472
- "k": "new"
473
- },
474
- {
475
- "n": 1566,
476
- "t": "Work breakdown follow-ups: drag to nest, hold to select, Gantt bars by days, grouping ✦, Jira column, Source filter, Set epic",
477
- "s": "Work breakdown follow-ups: drag to nest, hold to select, Gantt bars by days, grouping ✦, Jira column, Source filter, Set epic",
478
- "k": "new"
479
- },
480
- {
481
- "n": 1572,
482
- "t": "Launch tiers set what happens at full rollout (job #1548)",
483
- "s": "Launch tiers set what happens at full rollout (job #1548)",
484
- "k": "new"
485
- },
486
- {
487
- "n": 1565,
488
- "t": "One shared empty, loading and error block; the Viewer draws every state from it (job #1553)",
489
- "s": "One shared empty, loading and error block; the Viewer draws every state from it (job #1553)",
490
- "k": "new"
491
- },
492
- {
493
- "n": 1569,
494
- "t": "Five-line strategy above each product's Board, with a gentle note on new work that doesn't fit (job #1550)",
495
- "s": "Five-line strategy above each product's Board, with a gentle note on new work that doesn't fit (job #1550)",
496
- "k": "new"
497
- },
498
- {
499
- "n": 1573,
500
- "t": "Parked work keeps a reason and a way back (job #1552)",
501
- "s": "Parked work keeps a reason and a way back (job #1552)",
502
- "k": "new"
503
- },
504
- {
505
- "n": 1574,
506
- "t": "Phone initiative ask box no longer covers the page (release check 0.711.0)",
507
- "s": "Phone initiative ask box no longer covers the page (release check 0.711.0)",
508
- "k": "fix"
509
- }
510
- ]
511
445
  }
512
446
  ]
513
447
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@c595a5b1
1
+ kernel-source: pmos@ee1d6712
2
2
  assembled: 2026-11-23
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-23T06:47:30Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-23T07:20:25Z"}
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-23T06:47:30Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-23T07:20:25Z"}
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-23T06:47:30Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-23T07:20:25Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,17 @@
1
1
  [
2
+ {
3
+ "v": "0.738.0",
4
+ "at": "2026-11-23T07:20:29.240Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1639,
9
+ "t": "Every edit shows at once, and a failed save says so",
10
+ "s": "Every edit shows at once, and a failed save says so",
11
+ "k": "fix"
12
+ }
13
+ ]
14
+ },
2
15
  {
3
16
  "v": "0.737.0",
4
17
  "at": "2026-11-23T06:47:33.938Z",
@@ -2,13 +2,19 @@
2
2
  type: Guide
3
3
  title: "An initiative's tasks"
4
4
  description: "Where an initiative's tasks show in the workspace, how an agent adds tasks, and who made a change."
5
- timestamp: 2026-11-22
5
+ timestamp: 2026-11-23
6
6
  ---
7
7
 
8
8
  # An initiative's tasks
9
9
 
10
10
  An initiative owns its task breakdown. In the workspace, its tasks show under the initiative in Home's list (the 3 most urgent, then **Show N more tasks**) and on the initiative's page in the Viewer. Press **+** at the top of Home's list, then **Task**, to add one. A check box is a task: amber when it is late. [Home](home.md) explains the list.
11
11
 
12
+ ## Changes show at once
13
+
14
+ A change you make shows right away, on every page that shows the task: its status, dates, owner, priority, sprint, name, stage or parent, a new task, a deleted task, and a move of several tasks. The case lines and the summary of an initiative show right away too. You do not have to wait for the save, and you do not have to open the popup again.
15
+
16
+ If the save fails, the change goes back and a message tells you why, for example "Not saved, so it is back as it was: the start is after the due day." Select **Try again** to send it again.
17
+
12
18
  ## Subtasks
13
19
 
14
20
  A task can sit under another task, at any depth. To add a subtask, type `under <parent>: <title>` in the add box of the Work breakdown, for example `under Batch 2: TM web`. To move a task, open its **More** menu and select **Make subtask of…** or **Move out of …**. With a mouse you can also drag a task in the List:
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.737.0",
3
+ "version": "0.738.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.737.0",
9
+ "version": "0.738.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.737.0",
3
+ "version": "0.738.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",
@@ -19,6 +19,7 @@ import { productName } from './scope-chip.js'; // the product's display name (
19
19
  import * as SP from './bd-sprint.js';
20
20
  import * as WS from './work-select.js'; // the bulk move with one Undo, shared with the initiative popup and This sprint (WorkBulkDS)
21
21
  import * as IF from './inline-fields.js'; // a task's sprint and priority, set in the row (initiative inline-sprint-priority)
22
+ import * as LE from './live-edit.js'; // a task's status or days show at once in the list, before it is read again; a failed save is put back
22
23
  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)
23
24
 
24
25
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
@@ -85,10 +86,12 @@ async function readOne(s, tries = 0) {
85
86
  if (status === 202 && tries < 8) { await new Promise((f) => setTimeout(f, 1500)); return readOne(s, tries + 1); }
86
87
  return r && r.ok ? r : null;
87
88
  }
89
+ LE.source({ model: () => DATA, redraw: () => { if (host && DATA && on()) draw(); } });
88
90
  export async function load() {
89
91
  if (SC) { if (SC.api.reload) await SC.api.reload(); return; } // an embedded list reads again through its own page
90
92
  if (!A || loading) return;
91
93
  loading = true;
94
+ const since = Date.now();
92
95
  const S = A.scope();
93
96
  const got = await Promise.all(S.map((s) => readOne(s)));
94
97
  loading = false; loadedAt = Date.now();
@@ -109,6 +112,7 @@ export async function load() {
109
112
  // ticks that left the list go with them
110
113
  const ids = new Set(DATA.tasks.map(uidOf)); for (const k of [...SEL]) if (!ids.has(k)) SEL.delete(k);
111
114
  drawSwitch(); if (on()) draw();
115
+ LE.loaded({ since }); // a change still saving stays on the new read
112
116
  }
113
117
 
114
118
  /* ── the switch in Work's header ──────────────────────────────────────────────────────────────────────────────── */
@@ -21,6 +21,7 @@ import * as M from './pop-work-model.js';
21
21
  import * as CB from './cozy-bar.js';
22
22
  import { openPop, closePop, undoToast } from './hi-pop.js';
23
23
  import { pmGet, pmPost } from './http.js';
24
+ import * as LE from './live-edit.js'; // an edit shows at once: this popup is drawn again the moment a task write is sent, and after each read
24
25
  import * as VW from './cozy-viewer.js';
25
26
  import * as ED from './ini-edit.js';
26
27
  import * as SW from './cozy-status-when.js'; // When did this happen? after a status pick (round 3 point 18)
@@ -123,7 +124,7 @@ function critSugHtml(cr) {
123
124
  return `<div class="pm-sug x" role="group" aria-label="PMOS suggests"><div class="ttl">${SVG(P.spark || P.dia, 14)}<b class="say">${esc(say)}</b></div>`
124
125
  + `<dl><dt>Why</dt><dd>${esc('The people who build these tickets do not see the done test. Each check goes on the ticket it fits, as Given / When / Then.')}</dd>`
125
126
  + `<dt>PMOS will</dt><dd><ul>${will.map((w) => `<li>${esc(w)}</li>`).join('')}</ul></dd><dt>Tickets</dt><dd><ul>${L.map(row).join('')}</ul></dd></dl>`
126
- + `<div class="ans"><button type="button" class="pm-btn primary" data-pw-crit-ok aria-label="Yes, do it" title="Yes, do it">${SVG(P.check, 14)}</button>`
127
+ + `<div class="ans"><button type="button" class="pm-btn primary" data-pw-crit-ok aria-label="Yes, do it" title="Yes, do it">${SVG(PD.I.ok, 14)}</button>`
127
128
  + `<button type="button" class="pm-btn outline" data-pw-crit-drop aria-label="No" title="No">${SVG(P.x, 14)}</button></div></div>`;
128
129
  }
129
130
  /* the goal's name, not its id (board 25: "De-risk Okta dependency", not KR-C4): GET /api/boards/anchors once per product */
@@ -149,7 +150,7 @@ function artOf(id, ws) {
149
150
  if (!ART.has(id)) {
150
151
  ART.set(id, null);
151
152
  pmGet('/api/artefacts?scope=' + encodeURIComponent('experiment:' + id) + (ws ? '&ws=' + encodeURIComponent(ws) : ''))
152
- .then((x) => { ART.set(id, x && x.ok && Array.isArray(x.artefacts) ? x.artefacts : []); if (artRedraw) artRedraw(); }).catch(() => ART.set(id, []));
153
+ .then((x) => { ART.set(id, x && x.ok && Array.isArray(x.artefacts) ? x.artefacts : []); const p = PEND.get(id); if (p && !p.saving) p.lines = {}; if (artRedraw) artRedraw(); }).catch(() => ART.set(id, []));
153
154
  }
154
155
  return ART.get(id);
155
156
  }
@@ -336,10 +337,17 @@ const mergeOf = (rows) => AK.group(rows, { dropped: dropped() }).merge;
336
337
 
337
338
  /* ── the initiative ── */
338
339
  const keyOf = (v, o) => String((o && o.id) || (v && (v.id || v.key)) || '');
339
- function model(r, v, o) {
340
- const id = keyOf(v, o), S = stOf(id), it = ITEMS.get(id);
340
+ /* a case line or the summary shows the moment it is saved (Wawan, 2026-11-23: every edit shows at once): id → { lines: { lineId: text },
341
+ * desc }. A line stays until the artefacts are read again; the summary until the host reads the initiative again. A save that fails takes
342
+ * it out and says so with Try again. */
343
+ const PEND = new Map();
344
+ const pendOf = (id) => { if (!PEND.has(id)) PEND.set(id, { lines: {}, desc: null }); return PEND.get(id); };
345
+ function model(r, v0, o) {
346
+ const id0 = keyOf(v0, o), pd = PEND.get(id0), v = pd && pd.desc != null ? { ...v0, desc: pd.desc } : v0;
347
+ const id = id0, S = stOf(id), it = ITEMS.get(id);
341
348
  const g = o.goal || goalOf(o.ws, o.board, r.anchor || v.anchor);
342
349
  const W = M.workOf(r, v, { ...o, goal: M.idShaped(g) ? '' : g, product: productName(o.product, o.ws), art: artOf(id, o.ws), open: S.open, shut: S.shut, moreOpen: S.moreOpen, farOpen: S.farOpen, focus: S.focus, subOpen: S.subOpen, subShut: S.subShut, mode: store.get(SPAN, 'full'), items: it || [], dropped: dropped() });
350
+ if (pd && W.overview) for (const L of W.overview.lines || []) if (pd.lines[L.id] != null) { L.text = pd.lines[L.id]; delete L.ask; delete L.miss; }
343
351
  const mk = M.marksOf(W.span, W.today); W.tx = mk.today;
344
352
  W.epics = (r.epics || []).filter(Boolean); RSEL = S.sel; // the epic check and the picked rows, for the Gantt rows (initiative work-subtasks)
345
353
  // the Gantt's Jira column (work-subtasks-followups): on unless Choose columns hides it, and only when the work has a Jira row
@@ -600,15 +608,18 @@ async function dropSug(s, x, h) {
600
608
  if (h.reload) await h.reload();
601
609
  }
602
610
  async function saveDesc(text, x, h) {
603
- const w = h.where ? h.where() : {}, id = x.o().id;
611
+ const w = h.where ? h.where() : {}, id = x.o().id, kid = keyOf(x.v(), x.o());
612
+ // shown at once; the host's read after the save replaces it
613
+ const pd = pendOf(kid); pd.desc = text; if (h.redraw) h.redraw();
604
614
  const res = await pmPost('/api/initiative/describe', { ws: w.ws, id, text }).catch(() => null);
605
- if (!res || res.ok === false) { if (h.toast) h.toast((res && res.error) || 'It was not saved.'); return false; }
615
+ if (!res || res.ok === false) { pd.desc = null; if (h.redraw) h.redraw(); undoToast(LE.notSaved(res), () => saveDesc(text, x, h), 12000, 'Try again'); return false; }
616
+ const settle = async () => { if (h.reload) await h.reload(); if (pd.desc === text) { pd.desc = null; if (h.redraw) h.redraw(); } };
606
617
  if (!res.same) undoToast('Saved.', async () => {
607
618
  const u = await pmPost('/api/initiative/describe-undo', { ws: w.ws, id, from: res.from || '', to: res.text }).catch(() => null);
608
619
  if (!u || u.ok === false) { if (h.toast) h.toast((u && u.error) || 'The undo did not land.'); return; }
609
620
  if (h.reload) await h.reload();
610
621
  });
611
- if (h.reload) await h.reload();
622
+ await settle();
612
623
  return true;
613
624
  }
614
625
  const findSug = (W, id) => W.suggests.find((s) => s.id === id) || [...W.rowSuggests.values()].find((s) => s.id === id) || null;
@@ -626,6 +637,7 @@ export function wire(body, h0, x0) {
626
637
  body.__pw = true;
627
638
  function cur() { const x = body.__pwx, r = x && x.r(), v = x && x.v(); return r && v ? { r, v, ...model(r, v, x.o()) } : null; }
628
639
  function redraw() { if (body.__pwh && body.__pwh.redraw) body.__pwh.redraw(); }
640
+ LE.view(body, () => { if (body.querySelector('.pw')) redraw(); });
629
641
  goalsRedraw = artRedraw = wsnRedraw = () => { if (body.isConnected && body.querySelector('.pw')) redraw(); };
630
642
  wireGrip(body);
631
643
  // a phone: a proposal swiped right says yes, left says no (its own hidden Yes and No presses, so the popup's writes and Undo stay theirs)
@@ -758,7 +770,13 @@ function big(c, x, h) {
758
770
  if (hide) hide.click();
759
771
  VW.drill();
760
772
  VW.open({ kind: 'Work breakdown', title: 'Work breakdown', icon: 'list', id: 'wbs:' + c.id, back: true,
761
- render: (b) => { b.dataset.pwBig = '1'; const o = x.o(); S.big = true; b.innerHTML = html(x.r(), x.v(), o); wire(b, { ...h, redraw: () => { const t = b.scrollTop; b.innerHTML = html(x.r(), x.v(), x.o()); b.scrollTop = t; } }, x); },
773
+ render: (b) => {
774
+ b.dataset.pwBig = '1'; const o = x.o(); S.big = true; b.innerHTML = html(x.r(), x.v(), o);
775
+ const again = () => { if (!S.big || !b.isConnected || !x.r() || !x.v()) return; const t = b.scrollTop; b.innerHTML = html(x.r(), x.v(), x.o()); b.scrollTop = t; };
776
+ // the host draws its own popup body after a write and a read, never this drill-in: wire() puts it in pm/live-edit.js, so it follows
777
+ // the same writes and reads (Wawan, 2026-11-23: a status or day changed here showed only after the popup was opened again)
778
+ wire(b, { ...h, redraw: again }, x);
779
+ },
762
780
  onClose: () => { S.big = false; if (hid) { const ask = document.querySelector('.cz-pop [data-pop="ask"]'); if (ask && !ask.closest('[hidden]')) ask.click(); } } });
763
781
  void title;
764
782
  }
@@ -820,9 +838,17 @@ function editLine(el, L, c, x, h) {
820
838
  }
821
839
  async function saveLine(L, text, x, h) {
822
840
  if (L.edit.to === 'desc') return saveDesc(text, x, h);
823
- const w = h.where ? h.where() : {}, o = x.o(), id = o.id, ws = w.ws || o.ws;
841
+ const w = h.where ? h.where() : {}, o = x.o(), id = o.id, ws = w.ws || o.ws, kid = keyOf(x.v(), o);
842
+ // shown at once (Wawan, 2026-11-23); the next read of the artefacts replaces it
843
+ const pd = pendOf(kid); pd.lines[L.id] = text; pd.saving = (pd.saving || 0) + 1; if (h.redraw) h.redraw();
824
844
  const res = await pmPost('/api/artefacts/set', { ws, scope: 'experiment:' + id, artefact: L.edit.artefact, field: L.edit.field, text }).catch(() => null);
825
- if (!res || res.ok === false || !res.line) { if (h.toast) h.toast((res && res.error) || 'It was not saved.'); return false; }
845
+ pd.saving--;
846
+ if (!res || res.ok === false || !res.line) {
847
+ if (pd.lines[L.id] === text) delete pd.lines[L.id];
848
+ if (h.redraw) h.redraw();
849
+ undoToast(LE.notSaved(res && res.ok !== false && !res.line ? { error: 'the line was not written' } : res), () => saveLine(L, text, x, h), 12000, 'Try again');
850
+ return false;
851
+ }
826
852
  const ref = res.line.id;
827
853
  ART.delete(id);
828
854
  undoToast(L.k + ' saved.', async () => {
@@ -50,11 +50,11 @@ export function openPop(anchor, kind, html, onClick, o = {}) {
50
50
  const f = el.querySelector((sheet && o.sheetFocus) || o.focus || 'input, textarea, button:not([disabled])'); if (f) setTimeout(() => f.focus(), 0);
51
51
  return el;
52
52
  }
53
- export function undoToast(text, undo, ms = 9000) {
53
+ export function undoToast(text, undo, ms = 9000, label = 'Undo') {
54
54
  ensureCss();
55
55
  let el = document.getElementById('hiToast');
56
56
  if (!el) { el = document.createElement('div'); el.id = 'hiToast'; el.className = 'hi-toast'; el.setAttribute('role', 'status'); el.setAttribute('aria-live', 'polite'); document.body.appendChild(el); }
57
- el.innerHTML = `<span>${esc(text)}</span><button type="button" data-hi-undo>Undo</button>`;
57
+ el.innerHTML = `<span>${esc(text)}</span><button type="button" data-hi-undo>${esc(label)}</button>`;
58
58
  el.hidden = false; el.classList.add('on');
59
59
  el.querySelector('[data-hi-undo]').onclick = () => { hide(); undo(); };
60
60
  const hide = () => { el.classList.remove('on'); el.hidden = true; };
@@ -30,6 +30,7 @@ import * as POP from './cozy-popup.js'; // the one popup: an initiative and As
30
30
  import { mountToday } from './cozy-today-app.js'; // Today on a desk (slice 5): today.html is this page with data-today
31
31
  import * as SV from './small-vw.js'; // the small Viewers: a stakeholder, its form, a routine (batch 18 item 2-C)
32
32
  import { pmGet, pmPost, pmHeaders } from './http.js';
33
+ import * as LE from './live-edit.js'; // a task's status or days show at once (the save answers later; a failed save is put back)
33
34
  import * as ST from './story.js';
34
35
  import * as IT from './intent.js'; // board AwI: the Intent card under the story
35
36
  import * as H from './home-data.js';
@@ -205,8 +206,10 @@ async function getRetry(path, tries = 20) {
205
206
  }
206
207
  const LAST_KEY = (WS || '') + '|' + (BOARD || ''); // the last view Home drew, by its product and board (SpA)
207
208
  let pickGen = 0; // bumped by every saved pick, so a read that started before the save does not put the old pick back
209
+ /* Home's copy of every task, drawn again the moment a task write is sent (pm/live-edit.js), before Home reads its eleven routes again */
210
+ LE.source({ model: () => [S.D, S.IM], redraw: () => { if (S.ready) draw(); } });
208
211
  async function load() {
209
- const gen = pickGen;
212
+ const gen = pickGen, since = Date.now();
210
213
  const [brief, board, ses, desk, today, sch, work, day, rev, progs, , pick] = await Promise.all([
211
214
  getRetry('/api/briefing-premium' + wsQ()), getRetry('/api/board-premium' + wsQ() + boardQ(WS ? '&' : '?')), pmGet('/api/sessions'), pmGet('/api/home-desk' + wsQ()),
212
215
  pmGet('/api/brief-page' + wsQ()), pmGet('/api/schedules' + wsQ()), pmGet('/api/my-work-premium' + wsQ()), pmGet('/api/phone-day'), pmGet('/api/home-review' + wsQ()),
@@ -241,6 +244,7 @@ async function load() {
241
244
  S.ready = true;
242
245
  await loadIni();
243
246
  draw();
247
+ LE.loaded({ since }); // a change still saving stays on the new read; open views (the big Work breakdown) follow it
244
248
  NEED.refresh(); // an open ask: its agent finished, or it left Home while it was open
245
249
  loadImpact();
246
250
  loadDrift();
@@ -36,6 +36,7 @@ import { ensureCss as ensureStepsCss } from './cozy-steps.js'; // stage card D
36
36
  import * as DB from './dash-view.js'; // the ready-made Dashboard view (batch 17 item 1)
37
37
  import * as TL from './ini-tail.js';
38
38
  import * as ED from './ini-edit.js'; // round 3 item 11b: a Today task row opens its initiative with that task's row open in place
39
+ import * as LE from './live-edit.js'; // an edit shows at once: the open initiative view is drawn again the moment a task write is sent
39
40
  import * as PW from './cozy-pop-work.js'; // what the popup shows for work (slice 3 of the six-place navigation): in the popup, in place of the old page
40
41
  import * as PP from './ini-props.js'; // everything PMOS suggests, as a drill-in (the popup's ⋯) // under Linked, as the Board draws it (UI grill U1): drafted tickets, the PRD drift, Your impact
41
42
  import * as SWN from './cozy-status-when.js'; // the day a status move really happened, in the toast (round 3 point 18)
@@ -322,13 +323,14 @@ function wirePage(b, id) {
322
323
  // the stage card's ⏸ or calendar on a hold (batch 11 item 21): what the hold says, and its return date set or changed here
323
324
  hold: (i, btn) => holdPop(btn, id),
324
325
  // opt (batch 18 item 16): the + on a stage: the task goes under that stage, with the dates its field picked; the toast offers Undo
325
- addTask: async (title, inp, opt) => {
326
+ addTask: async function add(title, inp, opt) {
326
327
  const M = curM(); if (!M) return;
327
328
  inp.disabled = true;
328
329
  const D = opt ? opt : ADD_DATES || {};
329
330
  const r = await C.pmPost('/api/boards/tasks/add', { ...bw(M), initiative: id, title, ...(D.start ? { start: D.start } : {}), ...(D.due ? { due: D.due } : {}), ...(opt && opt.section != null ? { section: opt.section } : {}), ...(opt && opt.milestone ? { milestone: true } : {}), ...(opt && opt.owner ? { owner: opt.owner } : {}) });
330
331
  inp.disabled = false;
331
- if (!r || r.ok === false) { say((r && r.error) || 'The task was not added.'); return; }
332
+ // the row showed at once (pm/live-edit.js) and is gone again: say so, with Try again
333
+ if (!r || r.ok === false) { undoToast(LE.notSaved(r), () => add(title, inp, opt), 12000, 'Try again'); return; }
332
334
  const uid = r.item && r.item.uid;
333
335
  if (opt && uid) undoToast('Added to ' + (opt.name || 'the stage') + '.', async () => { const u = await C.pmPost('/api/boards/tasks/delete', { ...bw(M), task: uid, why: 'undo of add' }); if (!u || u.ok === false) C.toast((u && u.error) || 'The undo did not land.'); await C.load(); redrawView(); });
334
336
  else say('Task added.');
@@ -367,7 +369,8 @@ async function setState(id, uid, state, w) {
367
369
  const M = curM(); if (!M) return;
368
370
  const k = taskAt(id, uid), C = X.ctx, body = { ...bw(M), task: uid }, happened = (w && w.happened) || null;
369
371
  const r = await C.pmPost('/api/boards/tasks/state', { ...body, state, ...(happened ? { happened } : {}) });
370
- if (!r || r.ok === false) { C.toast((r && r.error) || 'Nothing was changed.'); return; }
372
+ // the new status showed at once (pm/live-edit.js); a save that did not land is back as it was, and the toast says so with Try again
373
+ if (!r || r.ok === false) { undoToast(LE.notSaved(r), () => setState(id, uid, state, w), 12000, 'Try again'); return; }
371
374
  await C.load(); redrawView();
372
375
  const was = k && k.status;
373
376
  // the day it really happened is said beside the title (round 3 point 18): "Done on 14 Nov, noted today."
@@ -379,7 +382,7 @@ async function removeTask(id, uid) {
379
382
  const M = curM(); if (!M) return;
380
383
  const k = taskAt(id, uid), C = X.ctx, body = { ...bw(M), task: uid }, title = (k && k.title) || uid;
381
384
  const r = await C.pmPost('/api/boards/tasks/delete', body);
382
- if (!r || r.ok === false) { C.toast((r && r.error) || 'The task was not deleted.'); return; }
385
+ if (!r || r.ok === false) { undoToast(LE.notSaved(r), () => removeTask(id, uid), 12000, 'Try again'); return; } // the row went at once and is back
383
386
  await C.load(); redrawView();
384
387
  undoToast('Deleted · ' + title + '.', async () => { const u = await C.pmPost('/api/boards/tasks/restore', body); if (!u || u.ok === false) C.toast((u && u.error) || 'The undo did not land.'); await C.load(); redrawView(); });
385
388
  }
@@ -388,7 +391,7 @@ async function setDates(id, uid, patch) {
388
391
  const M = curM(); if (!M) return;
389
392
  const k = taskAt(id, uid), C = X.ctx, body = { ...bw(M), task: uid };
390
393
  const r = await C.pmPost('/api/boards/tasks/edit', { ...body, ...patch });
391
- if (!r || r.ok === false) { C.toast((r && r.error) || 'Nothing was changed.'); return; }
394
+ if (!r || r.ok === false) { undoToast(LE.notSaved(r), () => setDates(id, uid, patch), 12000, 'Try again'); return; }
392
395
  await C.load(); redrawView();
393
396
  const back = {}; for (const f of Object.keys(patch)) back[f] = f === 'milestone' ? (r.from && 'milestone' in r.from ? !!r.from.milestone : !patch.milestone) : k ? (f === 'due' ? k.end : k[f]) || '' : r.from && f in r.from ? r.from[f] || '' : ''; // a Jira ticket's days come back in from (batch 11 item 23)
394
397
  if ('milestone' in patch) { undoToast((patch.milestone ? 'Milestone: ' : 'Not a milestone: ') + (k ? k.title : uid) + '.', async () => { const u = await C.pmPost('/api/boards/tasks/edit', { ...body, ...back }); if (!u || u.ok === false) C.toast((u && u.error) || 'The undo did not land.'); await C.load(); redrawView(); }); return; }
@@ -602,6 +605,7 @@ function draw(b) {
602
605
  // the phone keeps the Documents | Stage switch (PgTkList); in shell A on a desktop the other view sits under ⋯ (XvATasks)
603
606
  b.innerHTML = `<div class="hi-v" data-hi-v="${v}">${isPhone() || !X.ctx.VW.czSummary ? segHtml(v) : ''}${stageView(id, M, STAGE_ASK)}<p class="hi-small" role="status" id="ovMsg"></p></div>`;
604
607
  }
608
+ LE.view('home-ini', () => redrawView());
605
609
  function redrawView() {
606
610
  if (!BODY || !BODY.isConnected || !X.ctx) return;
607
611
  const cur = X.ctx.VW.current(); if (!cur) return;
@@ -139,8 +139,8 @@ export function sheetHtml(m, g, z = zoomOf()) {
139
139
  }
140
140
  function openSheet(anchor, H) {
141
141
  const g = () => (H.__g && H.__g.ok ? { by: H.__g.by(), label: H.__g.label() } : null);
142
- const draw = () => { if (POP && POP.anchor === anchor) POP.el.innerHTML = sheetHtml(viewMode(), g()); };
143
- const el = openPop(anchor, sheetHtml(viewMode(), g()), (b) => {
142
+ let el = null; const draw = () => { if (POP && POP.el === el) POP.el.innerHTML = sheetHtml(viewMode(), g()); };
143
+ el = openPop(anchor, sheetHtml(viewMode(), g()), (b) => {
144
144
  const d = b.dataset;
145
145
  if (d.ivsView) { setViewMode(d.ivsView); if (H.redraw) H.redraw(); draw(); return; }
146
146
  if (d.ivsCol) { const on = timelineCols(); setTimelineCols(on.includes(d.ivsCol) ? on.filter((k) => k !== d.ivsCol) : on.concat(d.ivsCol)); if (H.redraw) H.redraw(); draw(); return; }
@@ -577,7 +577,15 @@ export function kanbanHtml(v, o, isOpen) {
577
577
  /* ── the popovers: the task card's own status segment and date picker, opened right under the press ── */
578
578
  let POP = null;
579
579
  /** The press the picker hangs from moved (or left the page) since it opened. */
580
- const moved = (P) => { if (!P.anchor || !P.anchor.isConnected || !P.at) return true; const r = P.anchor.getBoundingClientRect(); return Math.abs(r.left - P.at[0]) > 1 || Math.abs(r.top - P.at[1]) > 1; };
580
+ const moved = (P) => { if (P.anchor && !P.anchor.isConnected) rehang(P); if (!P.anchor || !P.anchor.isConnected || !P.at) return true; const r = P.anchor.getBoundingClientRect(); return Math.abs(r.left - P.at[0]) > 1 || Math.abs(r.top - P.at[1]) > 1; };
581
+ /** A redraw put a new copy of the press in place (an edit shows at once, pm/live-edit.js): the picker hangs from that copy, found by
582
+ * the press's own data attributes, so it stays open. */
583
+ const selOf = (a) => { const at = [...a.attributes].filter((x) => x.name.startsWith('data-') && !/^data-(s|e|t)$/.test(x.name)); return at.length ? a.tagName.toLowerCase() + at.map((x) => `[${x.name}="${CSS.escape(x.value)}"]`).join('') : null; };
584
+ function rehang(P) {
585
+ let n = null; try { n = P.sel && document.querySelector(P.sel); } catch { n = null; }
586
+ if (!n || P.el.contains(n)) return;
587
+ P.anchor = n; n.setAttribute('aria-expanded', 'true'); const r = n.getBoundingClientRect(); P.at = [r.left, r.top];
588
+ }
581
589
  export function closePop() { if (!POP) return; const { el, anchor, scrim } = POP; POP = null; el.remove(); if (scrim) scrim.remove(); if (anchor && anchor.isConnected) anchor.setAttribute('aria-expanded', 'false'); }
582
590
  /** o.sheet: a bottom sheet over a scrim (a phone); o.right: the popover's right edge under the press's right edge. */
583
591
  export function openPop(anchor, html, onPress, o = {}) {
@@ -594,7 +602,7 @@ export function openPop(anchor, html, onPress, o = {}) {
594
602
  }
595
603
  anchor.setAttribute('aria-expanded', 'true');
596
604
  const ar = anchor.getBoundingClientRect();
597
- POP = { el, anchor, onPress, scrim, at: [ar.left, ar.top] };
605
+ POP = { el, anchor, onPress, scrim, at: [ar.left, ar.top], sel: selOf(anchor) };
598
606
  const f = el.querySelector('[aria-checked="true"], [aria-pressed="true"], button'); if (f) f.focus({ preventScroll: true });
599
607
  return el;
600
608
  }
@@ -0,0 +1,280 @@
1
+ /* pm/live-edit.js — an edit shows at once, everywhere it is drawn (Wawan, 2026-11-23: "When I change date or status here, it didn't change
2
+ * immediately on the UI ... Also applies to any other changes ... show issue when it is failed to update eventually").
3
+ *
4
+ * Before: a task's status or day was drawn again only after the save answered AND the page read the whole board again (Home reads eleven
5
+ * routes; the Board can answer "stale, ask again"). A drilled-in page, such as the big Work breakdown, was not drawn again at all until the
6
+ * popup was opened again.
7
+ *
8
+ * Now, one path for every page. install() (run once when this module first loads in a page) watches the page's own fetch, so every task
9
+ * write is seen whatever helper sends it (pm/http.js pmPost, pressFetch, data.js postJson):
10
+ * begin(path, body) a task write (POST /api/boards/tasks/state | edit | rename) is put on every copy of the task that a page holds
11
+ * (source()), and every page and open view is drawn again at once. Returns { ok(), fail() } or null.
12
+ * ok() the save landed: the change stays on until a read that started after the save replaces it (loaded()).
13
+ * fail() the save did not land: every copy gets its old value back and is drawn again. The caller says why in its toast.
14
+ * loaded({ since, stale }) a page read its data again: the changes still saving (and the saved ones a stale read cannot hold yet) are
15
+ * put back on the new copies, then the open views are drawn again, so a drilled-in page follows the read too.
16
+ * source({ model, redraw }) a page's data (a root, or a list of roots) and the draw that shows it; returns the call that removes it.
17
+ * view(el, redraw) an open view drawn from those sources (the popup body, the big Work breakdown); dropped once el leaves the page.
18
+ *
19
+ * Pure apart from the redraw calls and install(): no DOM reads, no requests of its own, so live-edit.test.js runs it in Node.
20
+ */
21
+
22
+ /** The write's field → the names a page's copy of a task uses for it (the Board's rows say status and end; Home's and the Backlog's say
23
+ * state and due). Only these fields are drawn at once; any other field waits for the read, as before. */
24
+ export const FIELDS = {
25
+ state: ['status', 'state'],
26
+ start: ['start'],
27
+ due: ['end', 'due'],
28
+ milestone: ['milestone', 'ms'],
29
+ owner: ['owner'],
30
+ priority: ['priority'],
31
+ sprint: ['sprint'],
32
+ title: ['title'],
33
+ notes: ['notes'],
34
+ section: ['section'],
35
+ parent: ['parent'],
36
+ };
37
+ const TASK_WRITE = /^\/api\/boards\/tasks\/(state|edit|rename|add|delete|bulk)(?:\?|$)/;
38
+ const JIRA_KEY = /^[A-Z][A-Z0-9]+-\d+$/i;
39
+ const isJira = (id) => JIRA_KEY.test(id) && !/^task-/i.test(id); // a PMOS task id is task-<hex>, which can be all digits
40
+ const DAY = /^\d{4}-\d{2}-\d{2}$/;
41
+
42
+ const SOURCES = new Set();
43
+ const VIEWS = new Map(); // el (or a token) → redraw
44
+ const PENDING = new Map(); // a write's token → { op, saved: 0 | the time it landed }
45
+ let seq = 0;
46
+
47
+ /** The fields of one task write that can be drawn at once: { state: 'Done' }, { due: '2026-11-30' }, … null when none. */
48
+ function pick(body, rename) {
49
+ const out = {};
50
+ for (const k of Object.keys(FIELDS)) if (body[k] !== undefined && body[k] !== null) out[k] = body[k];
51
+ if (!rename) delete out.title;
52
+ if ('state' in out) out.state = String(out.state);
53
+ return Object.keys(out).length ? out : null;
54
+ }
55
+
56
+ /** What a write does to the pages' copies of its tasks, as a list of ops; null when it is not a task write.
57
+ * { kind: 'patch', id, fields } status, days, owner, priority, sprint, name, stage (section), parent; fields.shift: move both days by N
58
+ * { kind: 'remove', id } tasks/delete
59
+ * { kind: 'add', ini, row } tasks/add: a row drawn under its initiative until the read brings the real one */
60
+ export function opsOf(path, body) {
61
+ const m = TASK_WRITE.exec(String(path || ''));
62
+ if (!m || !body || typeof body !== 'object') return null;
63
+ const w = m[1];
64
+ if (w === 'add') {
65
+ if (typeof body.initiative !== 'string' || !body.initiative || typeof body.title !== 'string' || !body.title.trim()) return null;
66
+ const row = { uid: 'adding:' + (++seq), title: body.title.trim(), status: 'To do', owner: body.owner || '', start: body.start || '', end: body.due || '', adding: true,
67
+ ...(typeof body.section === 'string' ? { section: body.section } : {}), ...(body.parent ? { parent: body.parent } : {}), ...(body.milestone ? { milestone: true } : {}) };
68
+ return [{ kind: 'add', ini: body.initiative, row }];
69
+ }
70
+ if (w === 'bulk') {
71
+ const ids = Array.isArray(body.tasks) ? body.tasks.filter((x) => typeof x === 'string' && x) : [];
72
+ const v = body.value, f = body.op === 'done' ? { state: 'Done' } : body.op === 'shift' ? (Number.isInteger(Number(v)) && Number(v) ? { shift: Number(v) } : null)
73
+ : ['section', 'owner', 'parent'].includes(body.op) && typeof v === 'string' ? { [body.op]: v } : null;
74
+ // Jira keeps a ticket's status, stage and assignee, so the server skips those: they are not drawn either
75
+ const keep = body.op === 'shift' || body.op === 'parent' ? ids : ids.filter((id) => !isJira(id));
76
+ return f && keep.length ? keep.map((id) => ({ kind: 'patch', id, fields: f })) : null;
77
+ }
78
+ if (typeof body.task !== 'string' || !body.task) return null;
79
+ if (w === 'delete') return [{ kind: 'remove', id: body.task }];
80
+ const fields = pick(body, w === 'rename');
81
+ return fields ? [{ kind: 'patch', id: body.task, fields }] : null;
82
+ }
83
+
84
+ /** The fields of a single task write (kept for callers that only patch). */
85
+ export function fieldsOf(path, body) {
86
+ const ops = opsOf(path, body);
87
+ return ops && ops.length === 1 && ops[0].kind === 'patch' && path.indexOf('/bulk') < 0 ? ops[0].fields : null;
88
+ }
89
+
90
+ /** Is o a copy of task id? A PMOS task carries uid; a Backlog row carries id; a Jira ticket carries its key. */
91
+ export function isTask(o, id) {
92
+ if (!o || typeof o !== 'object' || Array.isArray(o)) return false;
93
+ if (o.uid === id) return true;
94
+ if (o.id === id && typeof o.title === 'string' && ('state' in o || 'status' in o)) return true;
95
+ return isJira(id) && typeof o.key === 'string' && o.key.toUpperCase() === id.toUpperCase() && ('status' in o || 'state' in o);
96
+ }
97
+
98
+ /** Every place under root that holds something test() accepts: { o, parent, key } (objects, arrays, Map values), each place once. Stops
99
+ * at DOM nodes and at depth 12. */
100
+ function walk(root, test, out, seen, depth) {
101
+ if (!root || typeof root !== 'object' || depth > 12 || seen.has(root)) return out;
102
+ if (typeof root.nodeType === 'number' || typeof root.then === 'function') return out;
103
+ seen.add(root);
104
+ const visit = (v, key) => {
105
+ if (!v || typeof v !== 'object') return;
106
+ if (test(v)) out.push({ o: v, parent: root, key });
107
+ walk(v, test, out, seen, depth + 1);
108
+ };
109
+ if (Array.isArray(root)) root.forEach((v, i) => visit(v, i));
110
+ else if (root instanceof Map) for (const [k, v] of root) visit(v, k);
111
+ else if (!(root instanceof Set)) for (const k of Object.keys(root)) visit(root[k], k);
112
+ return out;
113
+ }
114
+ export function findAll(root, id, out = [], seen = new WeakSet()) { return walk(root, (v) => isTask(v, id), out, seen, 0); }
115
+
116
+ /** A day N days later (or earlier): '2026-11-23' + 2 → '2026-11-25'. Anything that is not a day is left as it is. */
117
+ export function shiftDay(d, n) {
118
+ if (typeof d !== 'string' || !DAY.test(d)) return d;
119
+ const t = new Date(d + 'T00:00:00Z'); t.setUTCDate(t.getUTCDate() + n);
120
+ return t.toISOString().slice(0, 10);
121
+ }
122
+
123
+ /** The copy with the fields put on it (a new object: whoever holds the old one, such as a press's Undo, still reads the old value). A field
124
+ * the copy does not have is added under its first name only on a PMOS task copy (it has uid), so a ticket never grows a field its page
125
+ * does not read. fields.shift moves every day the copy has by that many days. */
126
+ export function patched(o, fields) {
127
+ const n = { ...o };
128
+ for (const [k, v] of Object.entries(fields)) {
129
+ if (k === 'shift') { for (const name of ['start', 'end', 'due']) if (name in o) n[name] = shiftDay(o[name], v); continue; }
130
+ const names = FIELDS[k] || [k], val = k === 'milestone' ? !!v : v;
131
+ let hit = false;
132
+ for (const name of names) if (name in o) { n[name] = val; hit = true; }
133
+ if (!hit && 'uid' in o) n[names[0]] = val;
134
+ }
135
+ return n;
136
+ }
137
+
138
+ const get = (parent, key) => (parent instanceof Map ? parent.get(key) : parent[key]);
139
+ const put = (parent, key, v) => { if (parent instanceof Map) parent.set(key, v); else parent[key] = v; };
140
+
141
+ function rootsOf(s) { try { const m = s.model(); return Array.isArray(m) ? m : [m]; } catch { return []; } }
142
+ function places(test) {
143
+ const at = [], seen = new WeakSet();
144
+ for (const s of SOURCES) for (const r of rootsOf(s)) walk(r, test, at, seen, 0);
145
+ return at;
146
+ }
147
+
148
+ /** Do one op on every copy the pages hold; returns the undo steps, for fail(). */
149
+ function apply(op) {
150
+ const steps = [];
151
+ if (op.kind === 'patch') {
152
+ const made = new Map();
153
+ for (const { o, parent, key } of places((v) => isTask(v, op.id))) {
154
+ // a copy that already says it (the read caught up) is left alone, so a read never draws twice for nothing
155
+ if (!made.has(o)) { const n = patched(o, op.fields); made.set(o, Object.keys(n).some((k) => n[k] !== o[k]) ? n : o); }
156
+ if (made.get(o) === o) continue;
157
+ const n = made.get(o);
158
+ put(parent, key, n);
159
+ steps.push(() => { if (get(parent, key) === n) { put(parent, key, o); return 1; } return 0; });
160
+ }
161
+ } else if (op.kind === 'remove') {
162
+ // from the end of each list first, so the places of the others hold
163
+ const at = places((v) => isTask(v, op.id)).sort((a, b) => (typeof b.key === 'number' ? b.key : 0) - (typeof a.key === 'number' ? a.key : 0));
164
+ for (const { o, parent, key } of at) {
165
+ if (Array.isArray(parent)) { const i = parent.indexOf(o); if (i < 0) continue; parent.splice(i, 1); steps.push(() => { if (parent.includes(o)) return 0; parent.splice(Math.min(i, parent.length), 0, o); return 1; }); }
166
+ else if (parent instanceof Map) { parent.delete(key); steps.push(() => { if (parent.has(key)) return 0; parent.set(key, o); return 1; }); }
167
+ }
168
+ } else if (op.kind === 'add') {
169
+ // under each copy of its initiative that lists tasks (the Board's and Home's rows); a copy that has the task already is left alone
170
+ for (const { o } of places((v) => !Array.isArray(v) && v.id === op.ini && Array.isArray(v.tasks))) {
171
+ if (o.tasks.some((t) => t && t.uid === op.row.uid)) continue;
172
+ const row = { ...op.row }, arr = o.tasks;
173
+ arr.push(row);
174
+ steps.push(() => { const i = arr.indexOf(row); if (i < 0) return 0; arr.splice(i, 1); return 1; });
175
+ }
176
+ }
177
+ return steps;
178
+ }
179
+
180
+ /** Draw every page and open view again. One failing draw never stops the others. */
181
+ /** A task card's picker (status, dates) is open: it hangs from a row a redraw would replace, and closes when that row goes. */
182
+ const pickerOpen = () => typeof document !== 'undefined' && !!document.querySelector('.tkc.ivq');
183
+ let HELD = null;
184
+ export function paint(views = true) {
185
+ // hold the redraw while a picker is open (the picker itself already shows the new value), and draw once it closes
186
+ if (pickerOpen()) {
187
+ HELD = HELD === null ? views : HELD || views;
188
+ if (HELD !== null && !paint.wait) paint.wait = setInterval(() => { if (pickerOpen()) return; clearInterval(paint.wait); paint.wait = 0; const v = HELD; HELD = null; paint(v); }, 120);
189
+ return;
190
+ }
191
+ for (const s of SOURCES) if (s.redraw) { try { s.redraw(); } catch { /* the next read draws it */ } }
192
+ if (!views) return;
193
+ for (const [el, fn] of [...VIEWS]) {
194
+ if (el && typeof el === 'object' && 'isConnected' in el && !el.isConnected) { VIEWS.delete(el); continue; }
195
+ try { fn(); } catch { /* the next read draws it */ }
196
+ }
197
+ }
198
+
199
+ /** A write is about to be sent. null when it is not a task write. */
200
+ export function begin(path, body) {
201
+ const ops = opsOf(path, body);
202
+ if (!ops) return null;
203
+ const entries = ops.map((op) => { const e = { op, saved: 0 }; PENDING.set(++seq, e); return [seq, e]; });
204
+ const steps = ops.flatMap((op) => apply(op));
205
+ if (steps.length) paint();
206
+ return {
207
+ ok(at) { const t = at || Date.now(); for (const [, e] of entries) e.saved = t; },
208
+ fail() {
209
+ for (const [k] of entries) PENDING.delete(k);
210
+ // only a copy still showing this change goes back: a newer read or a newer change is left as it is
211
+ let back = 0;
212
+ for (const undo of steps.reverse()) back += undo();
213
+ if (back) paint();
214
+ },
215
+ };
216
+ }
217
+
218
+ /** A page read its data again (since: when that read started; stale: the server said a press is still being folded in). */
219
+ export function loaded({ since = 0, stale = false } = {}) {
220
+ let n = 0;
221
+ for (const [k, e] of [...PENDING]) {
222
+ // a read that started after the save landed, and is not stale, holds the saved value itself
223
+ if (e.saved && !stale && since >= e.saved) { PENDING.delete(k); continue; }
224
+ // a saved new task may already be in the read under its real id: its stand-in is not drawn twice
225
+ if (e.op.kind === 'add' && e.saved) continue;
226
+ n += apply(e.op).length;
227
+ }
228
+ // the page drew the read already; it draws again only when a change still saving was put back on it
229
+ if (n) { paint(); return; }
230
+ for (const [el, fn] of [...VIEWS]) {
231
+ if (el && typeof el === 'object' && 'isConnected' in el && !el.isConnected) { VIEWS.delete(el); continue; }
232
+ try { fn(); } catch { /* the next read draws it */ }
233
+ }
234
+ }
235
+
236
+ /** The one line a page shows when a save did not land: the change is already back as it was. Plain words; the server's reason when it
237
+ * gave one. */
238
+ export function notSaved(res) {
239
+ const why = res && typeof res.error === 'string' && res.error.trim() ? res.error.trim().replace(/[.\s]+$/, '') : 'the workspace did not answer';
240
+ return 'Not saved, so it is back as it was: ' + why + '.';
241
+ }
242
+
243
+ /** Watch the page's fetch: a POST of a task write begins before it is sent, and ok() or fail() follows the answer (a refused answer, a
244
+ * body with ok:false, or no answer at all). The answer itself is handed back untouched; its body is read from a clone. */
245
+ export function install(g = globalThis) {
246
+ if (!g || typeof g.fetch !== 'function' || g.fetch.__liveEdit) return false;
247
+ const real = g.fetch;
248
+ const watched = async function (input, init) {
249
+ let le = null;
250
+ try {
251
+ const url = typeof input === 'string' ? input : input && input.url;
252
+ const method = String((init && init.method) || (input && typeof input === 'object' && input.method) || 'GET').toUpperCase();
253
+ if (method === 'POST' && url && init && typeof init.body === 'string') {
254
+ const p = new URL(url, 'http://x').pathname;
255
+ if (TASK_WRITE.test(p)) le = begin(p, JSON.parse(init.body));
256
+ }
257
+ } catch { le = null; }
258
+ if (!le) return real.call(this, input, init);
259
+ let res;
260
+ try { res = await real.call(this, input, init); } catch (e) { le.fail(); throw e; }
261
+ // a 403 (a stale nonce) is put back at once: pressFetch sends the press again, and that send begins on its own
262
+ if (res.status === 403) { le.fail(); return res; }
263
+ // landed now: the caller reads again as soon as it has the answer, and that read must count as after the save
264
+ const at = Date.now();
265
+ let body = null; try { body = await res.clone().json(); } catch { body = null; }
266
+ if (!res.ok || !body || body.ok === false) le.fail(); else le.ok(at);
267
+ return res;
268
+ };
269
+ watched.__liveEdit = true;
270
+ g.fetch = watched;
271
+ return true;
272
+ }
273
+ if (typeof window !== 'undefined' && typeof document !== 'undefined') install(window);
274
+
275
+ export function source(s) { SOURCES.add(s); return () => SOURCES.delete(s); }
276
+ export function view(el, redraw) { VIEWS.set(el, redraw); return () => { if (VIEWS.get(el) === redraw) VIEWS.delete(el); }; }
277
+ /** The task ids with a change still on the pages (tests). */
278
+ export const pending = () => new Map([...PENDING.values()].map((e) => [e.op.id || e.op.ini, e]));
279
+ /** Tests only: forget every source, view and pending write. */
280
+ export function reset() { SOURCES.clear(); VIEWS.clear(); PENDING.clear(); HELD = null; if (paint.wait) { clearInterval(paint.wait); paint.wait = 0; } }
@@ -20,6 +20,7 @@
20
20
  import './fetch-share.js'; // first: identical GETs in flight are asked once (page-open-speed)
21
21
  import * as WK from './work-kind.js'; // the kind of work before each title (batch 29 item 11, KdBd)
22
22
  import { pmPost } from './http.js';
23
+ import * as LE from './live-edit.js'; // a task's status or days show at once (the save answers later; a failed save is put back)
23
24
  import { followDoc } from './doc-follow.js';
24
25
  import { $, $$, esc, store, chatAbout, setPageGaps } from './premium-shell.js';
25
26
  import * as PK from './cozy-pick.js';
@@ -221,8 +222,8 @@ function closePanel() {
221
222
  /* ── the toast: the Agreed design's dark pill ─────────────────────────────────────────────────────────────────────────────── */
222
223
  let toastT = null;
223
224
  /** The toast; with `undo`, an Undo button that runs it once (the write's opposite, through the same route). */
224
- function say(msg, undo) {
225
- const t = $('#bdToast'); t.innerHTML = `<span>${esc(msg)}</span>${undo ? '<button type="button" class="bd-undo">Undo</button>' : ''}`; t.hidden = false;
225
+ function say(msg, undo, label = 'Undo') {
226
+ const t = $('#bdToast'); t.innerHTML = `<span>${esc(msg)}</span>${undo ? '<button type="button" class="bd-undo">' + esc(label) + '</button>' : ''}`; t.hidden = false;
226
227
  const u = t.querySelector('.bd-undo'); if (u) u.onclick = () => { u.disabled = true; t.hidden = true; undo(); };
227
228
  clearTimeout(toastT); toastT = setTimeout(() => { t.hidden = true; }, undo ? 10000 : 5000);
228
229
  }
@@ -1428,7 +1429,10 @@ async function readAll(q) {
1428
1429
  if (lost.length) { model.header.missing = [...model.header.missing, ...lost]; model.header.text += (/not read: /.test(model.header.text) ? ', ' : ' · not read: ') + lost.join(', '); }
1429
1430
  return { r: { ok: true, model, stale: got.some((g) => g.r && g.r.stale) || h.r.stale }, status: 200 };
1430
1431
  }
1432
+ /* the Board's copy of every task, drawn again the moment a task write is sent (pm/live-edit.js), before the board is read again */
1433
+ LE.source({ model: () => M, redraw: () => { if (!M) return; drawInit(); if (peek && peek.kind === 'ini') BI.refresh(true); } });
1431
1434
  async function load() {
1435
+ const since = Date.now();
1432
1436
  // while the board is read (the pick's default board, then the picked ones) the page says so and shows no row instead of a guess
1433
1437
  const reading = () => {
1434
1438
  const t0 = Date.now(), tick = () => { const s = 'Reading the board · ' + Math.round((Date.now() - t0) / 1000) + ' s so far'; $('#snap').textContent = s; if (!M && !$('#ibBody .ls-bd')) { $('#ibBody').innerHTML = SKEL; LS.slowLine($('#ibBody'), () => M); } };
@@ -1449,6 +1453,7 @@ async function load() {
1449
1453
  }
1450
1454
  M = r.model; readTries = 0; jiraReading = false; holdNames(); draw();
1451
1455
  readChanges();
1456
+ LE.loaded({ since, stale: !!r.stale }); // a change still saving stays on the new read; open views (the big Work breakdown) follow it
1452
1457
  STRAT.refresh($('#cStrat'), { ws: M.board.ws || null, board: M.board.id || null, single: !ALL, say });
1453
1458
  PRIN.refresh($('#cPrin'), { ws: M.board.ws || null, single: !ALL, say });
1454
1459
  focusOnce(); programOnce(); newOnce(); loadOthers(); loadWorkflows();
@@ -1475,7 +1480,8 @@ async function loadWorkflows() {
1475
1480
  async function setTask(r, uid, state, w) {
1476
1481
  const k = (r.tasks || []).find((x) => x.uid === uid), body = { ws: r.ws || M.board.ws, board: r.boardId || M.board.id, task: uid }, happened = (w && w.happened) || null;
1477
1482
  const res = await pmPost('/api/boards/tasks/state', { ...body, state, ...(happened ? { happened } : {}) }).catch(() => null);
1478
- if (!res || res.ok === false) { say((res && res.error) || 'Nothing was changed.'); return; }
1483
+ // the new status showed at once (pm/live-edit.js); a save that did not land is back as it was, and the toast says so with Try again
1484
+ if (!res || res.ok === false) { say(LE.notSaved(res), () => setTask(r, uid, state, w), 'Try again'); return; }
1479
1485
  // a breakdown item closed as Won't do is withdrawn, which the ledger cannot undo; every other change can go back (batch 9 item 5b)
1480
1486
  const undo = k && k.status !== state && !(k.item && state === "Won't do");
1481
1487
  // the day it really happened is said too (round 3 point 18): "Done on 14 Nov, noted today: <title>."
@@ -1487,7 +1493,7 @@ async function setTask(r, uid, state, w) {
1487
1493
  async function setDates(r, uid, patch) {
1488
1494
  const k = (r.tasks || []).find((x) => x.uid === uid), body = { ws: r.ws || M.board.ws, board: r.boardId || M.board.id, task: uid };
1489
1495
  const res = await pmPost('/api/boards/tasks/edit', { ...body, ...patch }).catch(() => null);
1490
- if (!res || res.ok === false) { say((res && res.error) || 'Nothing was changed.'); return; }
1496
+ if (!res || res.ok === false) { say(LE.notSaved(res), () => setDates(r, uid, patch), 'Try again'); return; }
1491
1497
  const ms = 'milestone' in patch;
1492
1498
  const back = {}; for (const f of Object.keys(patch)) back[f] = f === 'milestone' ? (res.from && 'milestone' in res.from ? !!res.from.milestone : !patch.milestone) : k ? (f === 'due' ? k.end : k[f]) || '' : res.from && f in res.from ? res.from[f] || '' : ''; // a Jira ticket's days come back in from (batch 11 item 23)
1493
1499
  const words = ms ? (patch.milestone ? 'Milestone' : 'Not a milestone') : 'Dates saved';
@@ -1499,7 +1505,7 @@ async function setDates(r, uid, patch) {
1499
1505
  async function removeTask(r, uid) {
1500
1506
  const k = (r.tasks || []).find((x) => x.uid === uid), body = { ws: r.ws || M.board.ws, board: r.boardId || M.board.id, task: uid };
1501
1507
  const res = await pmPost('/api/boards/tasks/delete', body).catch(() => null);
1502
- if (!res || res.ok === false) { say((res && res.error) || 'The task was not deleted.'); return; }
1508
+ if (!res || res.ok === false) { say(LE.notSaved(res), () => removeTask(r, uid), 'Try again'); return; } // the row went at once and is back
1503
1509
  say('Deleted · ' + (k ? k.title : uid) + '.', async () => { const u = await pmPost('/api/boards/tasks/restore', body).catch(() => null); if (!u || u.ok === false) say((u && u.error) || 'The undo did not land.'); load(); });
1504
1510
  load();
1505
1511
  }
@@ -1555,7 +1561,7 @@ async function addTask(r, title, section, dates, name) {
1555
1561
  // dates: a gap's + (batch 11 item 13) fills the task's start and due with the gap's days ahead; section: the stage it goes under (the
1556
1562
  // add route places it, batch 18 item 16); the add field's chips also send milestone and owner in it (batch 25 item 5)
1557
1563
  const res = await pmPost('/api/boards/tasks/add', { ...body, initiative: r.id, title, ...(dates && dates.start ? { start: dates.start } : {}), ...(dates && dates.due ? { due: dates.due } : {}), ...(dates && dates.milestone ? { milestone: true } : {}), ...(dates && dates.owner ? { owner: dates.owner } : {}), ...(section ? { section } : {}) }).catch(() => null);
1558
- if (!res || res.ok === false) { say((res && res.error) || 'The task was not added.'); return false; }
1564
+ if (!res || res.ok === false) { say(LE.notSaved(res), () => addTask(r, title, section, dates, name), 'Try again'); return false; } // the row showed at once (pm/live-edit.js) and is gone again
1559
1565
  const uid = res.item && res.item.uid;
1560
1566
  // the + on a stage (batch 18 item 16, StA5Add): "Added to Build" with Undo
1561
1567
  if (name && uid) say('Added to ' + name + '.', async () => { const u = await pmPost('/api/boards/tasks/delete', { ...body, task: uid, why: 'undo of add' }).catch(() => null); if (!u || u.ok === false) say((u && u.error) || 'The undo did not land.'); load(); });
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Every edit shows at once on the workspace, and a failed save says so (initiative edits-show-at-once, done test C1-C8): the pure module public/pm/live-edit.js and a read of the page code. No server, browser or network.",
3
+ "modules": [
4
+ "live-edit.test.js"
5
+ ],
6
+ "seconds": {
7
+ "live-edit.test.js": 1
8
+ }
9
+ }