create-pmos 0.546.0 → 0.548.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.
@@ -398,9 +398,10 @@ async function readMove() {
398
398
  return pmGet('/api/lab' + (q ? '?' + q : '')).then((r) => (r && r.ok && r.lab && (r.lab.loose || []).length ? { ws: L[i], board: b, n: r.lab.loose.length, say: r.lab.say || '' } : null)).catch(() => null); }));
399
399
  L.forEach((ws, i) => {
400
400
  const r = got[i], A = auto[i] && auto[i].ok ? auto[i] : null; if (!r || !r.ok) return;
401
- const done = A ? (A.done || []).map((d) => ({ ref: d.ref, ini: d.ini || '', said: d.title || 'done', at: d.at, via: 'autonomy' }))
401
+ const done = A ? (A.done || []).map((d) => ({ ref: d.ref, ini: d.ini || '', said: d.title || 'done', at: d.at, via: 'autonomy', reason: d.reason || '' }))
402
402
  : (r.done || []).map((d) => ({ ref: d.batch, ini: d.ini, board: d.board, said: d.said, at: d.at, via: 'proposals' }));
403
- next[ws] = { verdicts: r.verdicts || [], kr: r.kr || null, expired: r.expired || [], done, notices: A ? A.notices || [] : [] };
403
+ // agent-run (AwA, R4): the runs that stopped, one amber line in Claude did
404
+ next[ws] = { verdicts: r.verdicts || [], kr: r.kr || null, expired: r.expired || [], done, notices: A ? A.notices || [] : [], failed: A ? A.failed || [] : [] };
404
405
  });
405
406
  const ob = await pmGet('/api/outbox').catch(() => null);
406
407
  const outbox = ob && ob.ok && Array.isArray(ob.entries) ? ob.entries.filter((e) => e && (e.state === 'queued' || e.state === 'blocked')) : [];
@@ -498,7 +499,7 @@ function dayParts() {
498
499
  // Good morning (GM2): the goal data (the quarter, the PM's line, the morning snapshot, a goal tag per row) is GM1's, in S.gmGoals once it reads
499
500
  const G = GM.gmModel(Y, S.D, NOW(), { quarter: S.gmGoals && S.gmGoals.quarter, tags: S.gmGoals && S.gmGoals.tags, notes: noteRows(), picks: S.notePicks || {}, today: H.todayOf(S.D) });
500
501
  S.G = G;
501
- return { Y, P: YD.gmParts(Y, G, { moment: !!(isPhone() && PHC), now: NOW(), first: !!S.first, html: GM.gmHtml }) };
502
+ return { Y, P: YD.gmParts(Y, G, { moment: !!(isPhone() && PHC), now: NOW(), first: !!S.first, html: GM.gmHtml, didRow: GM.didRowHtml }) };
502
503
  }
503
504
  /** The quarter under Good morning (GET /api/morning-goals, GM1): goal states, the PM's line or Claude's ✦ line, the move since the
504
505
  * morning, and a goal tag per initiative. Read when Your day opens (never on Home's first draw: page speed). No answer, no strip. */
@@ -352,14 +352,19 @@ export function dayParts(Y, o = {}) {
352
352
  * Drafted for you, Can wait, Now (a phone's moment card) and This week. Nothing is dropped. → { gm, sections, night } */
353
353
  export function gmParts(Y, G, o = {}) {
354
354
  const now = o.now || Date.now(), sections = [];
355
- const rest = Y.rank ? Y.rank.rows.filter((r) => !G.move.some((m) => m.key === r.key) && !(G.call && r.kind === 'call' && r.call && r.call.id === G.call.id)) : [];
356
- if (G.state !== 'evening' && (rest.length || (Y.rank && (Y.rank.expired || []).length))) {
357
- const mv = moveSection({ rows: rest, expired: Y.rank.expired, wait: Y.rank.wait });
358
- if (mv) sections.push({ ...mv, id: 'more', title: 'More in Your move', open: false });
355
+ // agent-run (AwA): the fold under Your move holds only the rest of the PM's calls (Can wait is gone: Claude acts on the rest), and the
356
+ // fold under Claude did the rest of what Claude did, each with its reason and Undo (o.didRow: good-morning.js didRowHtml)
357
+ const calls = G.rest || [];
358
+ if (calls.length || (Y.rank && (Y.rank.expired || []).length)) {
359
+ const mv = moveSection({ rows: calls, expired: Y.rank && Y.rank.expired });
360
+ if (mv) sections.push({ ...mv, id: 'more', title: 'More of your calls', open: false });
359
361
  }
360
362
  if (Y.drafts.length) sections.push({ id: 'drafts', title: 'Drafted for you', count: Y.drafts.length, html: `<div class="hv-card">${Y.drafts.map((d, i) => draftRow(d, i)).join('')}</div>` });
361
- { const w = waitSection(Y.rank, Y.wait); if (w) sections.push(w); }
362
- { const d = doneSection(Y.rank); if (d) sections.push(d); }
363
+ const dr = (G.did || []).slice(5);
364
+ if ((dr.length && o.didRow) || ((Y.rank && Y.rank.notices) || []).length) {
365
+ const nt = ((Y.rank && Y.rank.notices) || []).map((n) => `<p class="yd-exp">${esc(n.text || ((n.job || 'A job') + ' asks again before it changes anything, until ' + String(n.until || '').slice(0, 10) + '.'))}</p>`).join('');
366
+ sections.push({ id: 'done', title: 'More Claude did', count: dr.length, open: !!nt, html: nt + (o.didRow ? `<div class="gm-didl">${dr.map(o.didRow).join('')}</div>` : '') });
367
+ }
363
368
  if (o.moment) sections.push({ id: 'now', title: 'Now', open: true, html: '<div class="hd-now"></div>' });
364
369
  sections.push(weekSection(Y));
365
370
  // one Adler per screen: the morning scene on the day's first open before noon, else his face on the lead
@@ -0,0 +1,164 @@
1
+ /* pm/ini-agent.js — the agent's part of the initiative Viewer (agent-run workspace, board AwB on the main canvas, In development; agreed by
2
+ * Wawan 2026-11-10; requirements R4, R5, R7, R12, R17, R18 and decision D107). Pure parts first: Node imports them (ini-agent.test.js).
3
+ *
4
+ * agentModel(art, auto, id, o) → M | null what the Viewer shows, from GET /api/artefacts?scope=experiment:<id> and GET /api/autonomy
5
+ * expHtml(M) · workHtml(M) · sectionsHtml(M) the Experiment section and Claude's work (with its amber line and Coming up), or ''
6
+ * comingUp(v) → { date, text } | null the next dated thing of the initiative, from the Viewer's own model (ini-view-model.js)
7
+ * gateOf(M) → { label, parts } | null D107: the gate to Build reads the done test and the kill condition, not PRD and rubric
8
+ * want(ws, id, done) · cached(id) · edit(body, btn) · save(body, form) · undo(btn) the reads and presses (the page only)
9
+ *
10
+ * THE EXPERIMENT (R12, R18): we bet (hypothesis), stop if (kill), budget, who builds (executor, R17), specimens (the kept one, or how many
11
+ * attempts) and done when (the done test's checks). Claude writes it from the record; a field nobody wrote is left out, and with nothing
12
+ * written there is no section (zero is silence). The PM edits a one-line field in place (POST /api/artefacts/set); Claude then asks before
13
+ * it changes that line again (lib/artefacts.js pmEdited).
14
+ * CLAUDE'S WORK (R7): the changes Claude made here by itself in the last 14 days (GET /api/autonomy done, by initiative), each with its
15
+ * one-line reason, its day and Undo; a run that stopped is one amber line (R4); one Coming up line names the next dated thing (R5).
16
+ * Icon-only presses carry their words in aria-label and title. */
17
+ import { pmGet, pmPost } from './http.js';
18
+
19
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
20
+ const SVG = (d, w = 16, sw = 1.8) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
21
+ const P = { undo: 'M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3', check: 'M5 12l5 5 9-10', warn: 'M12 8v5M12 16.5v.01M10.3 3.9L2.6 17.5A2 2 0 0 0 4.3 20.5h15.4a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0z',
22
+ clock: 'M12 7.5V12l3 2M12 3.5a8.5 8.5 0 1 0 0 17a8.5 8.5 0 1 0 0-17', x: 'M6 6l12 12M18 6L6 18', right: 'M10 7l5 5-5 5' };
23
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
24
+ const dm = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
25
+ const DAY = 864e5, SHOW = 3;
26
+ export const WHO = { factory: 'Claude builds it (the factory).', team: 'The team builds it. Claude writes the done test.', 'team-agents': 'The team’s agents build it. Claude writes the done test.' };
27
+
28
+ const art = (A, key) => ((A && A.artefacts) || []).find((a) => a.key === key) || null;
29
+ const one = (a, f) => { const v = a && a.fields && a.fields[f]; return v && !Array.isArray(v) && v.text ? v : null; };
30
+ const list = (a, f) => { const v = a && a.fields && a.fields[f]; return Array.isArray(v) ? v.filter((x) => x && x.text) : []; };
31
+ const carried = (a, f) => ((a && a.carried) || []).filter((c) => c.field === f && c.text);
32
+
33
+ /** The Viewer's model. art: GET /api/artefacts answer for scope experiment:<id>; auto: GET /api/autonomy answer; o: { now }. */
34
+ export function agentModel(A, U, id, o = {}) {
35
+ const now = o.now || Date.now();
36
+ const X = art(A, 'experiment'), S = art(A, 'specimens'), T = art(A, 'done-test');
37
+ const row = (key, label, v, edit) => (v ? { key, label, text: v.text, by: v.by || '', at: v.at || '', edit: edit || null } : null);
38
+ const hyp = one(X, 'hypothesis') || (carried(X, 'hypothesis')[0] ? { text: carried(X, 'hypothesis')[0].text } : null);
39
+ const kill = one(X, 'kill'), budget = one(X, 'budget'), ex = one(X, 'executor');
40
+ const kept = one(S, 'kept'), tries = list(S, 'specimen'), checks = list(T, 'check'), result = one(T, 'result');
41
+ const rows = [
42
+ row('hypothesis', 'We bet', hyp, { artefact: 'experiment', field: 'hypothesis' }),
43
+ row('kill', 'Stop if', kill, { artefact: 'experiment', field: 'kill' }),
44
+ row('budget', 'Budget', budget, { artefact: 'experiment', field: 'budget' }),
45
+ ex ? { key: 'executor', label: 'Who builds', text: WHO[ex.text] || ex.text, value: ex.text, by: ex.by || '', at: ex.at || '', edit: { artefact: 'experiment', field: 'executor', pick: Object.keys(WHO) } } : null,
46
+ kept ? row('specimens', 'Specimens', { ...kept, text: 'Kept: ' + kept.text + (tries.length > 1 ? ' (of ' + tries.length + ' attempts)' : '') })
47
+ : tries.length ? row('specimens', 'Specimens', { text: tries.length + (tries.length === 1 ? ' attempt' : ' attempts') + ', none kept yet: ' + tries[tries.length - 1].text, at: tries[tries.length - 1].at }) : null,
48
+ checks.length ? { key: 'done', label: 'Done when', text: checks.map((c) => c.text).join(' · '), sub: result ? 'Result: ' + result.text : '', at: checks[checks.length - 1].at || '', edit: null } : null,
49
+ ].filter(Boolean);
50
+ // the newest line Claude wrote dates the section: "Claude keeps it · 3 Nov"
51
+ const dates = rows.map((r) => r.at).filter(Boolean).sort();
52
+ const exp = rows.length ? { rows, at: dates.length ? dates[dates.length - 1] : '' } : null;
53
+ const gate = rows.length ? { kill: !!kill, done: checks.length > 0 } : null;
54
+ // Claude's work: this initiative's changes, newest first, and its runs that stopped
55
+ const mine = ((U && U.done) || []).filter((d) => d && d.ini === id);
56
+ const work = mine.map((d) => ({ ref: d.ref, title: d.title || 'A change', reason: d.reason || '', at: d.at || '', ws: (U && U.ws) || '' }));
57
+ const fl = ((U && U.failed) || []).filter((f) => f && f.ini === id && now - Date.parse(f.at || '') <= 7 * DAY);
58
+ const failed = fl.length ? { n: fl.length, at: fl[0].at, why: fl[0].why || '' } : null;
59
+ const week = work.filter((w) => now - Date.parse(w.at) <= 7 * DAY).length;
60
+ return { id, ws: (U && U.ws) || (A && A.ws) || '', exp, gate, work, week, failed };
61
+ }
62
+
63
+ /** D107: with an experiment on record, the gate to Build is its done test and its kill condition (not the PRD and the rubric). */
64
+ export function gateOf(M) {
65
+ if (!M || !M.gate) return null;
66
+ return { label: 'Gate to Build', parts: [{ text: 'done test', ok: M.gate.done, ...(M.gate.done ? {} : { note: 'No done test is written yet' }) }, { text: 'kill condition', ok: M.gate.kill, ...(M.gate.kill ? {} : { note: 'No kill condition is written yet' }) }] };
67
+ }
68
+
69
+ /** The next dated thing of the initiative (R5), from the Viewer's model: the nearest open milestone ahead, else the plan's end. */
70
+ export function comingUp(v) {
71
+ const st = v && v.stage;
72
+ if (!st) return null;
73
+ const g = ((st.gates && st.gates.open) || []).find((x) => !x.late && x.date);
74
+ if (g) return { date: g.date, text: g.name + (g.left === 0 ? ' is due today.' : g.left === 1 ? ' is due tomorrow.' : ' is due.') };
75
+ const D = st.dates;
76
+ if (D && D.end && !D.over && D.left) return { date: D.end, text: 'The plan ends (' + D.left + ').' };
77
+ return null;
78
+ }
79
+
80
+ const failLine = (F) => `<div class="ia-fl" role="status">${SVG(P.warn, 14, 2)}<span>${esc((F.n === 1 ? 'The ' + dm(F.at) + ' run' : F.n + ' runs') + ' ended with an error.' + (F.why ? ' ' + String(F.why).replace(/\.?$/, '.') : '') + ' Claude runs ' + (F.n === 1 ? 'it' : 'them') + ' again on the next wake. Nothing ' + (F.n === 1 ? 'it' : 'they') + ' made was kept.')}</span></div>`;
81
+
82
+ export function expHtml(M) {
83
+ if (!M || !M.exp) return '';
84
+ const rowHtml = (r) => {
85
+ const val = `<span class="ia-v">${esc(r.text)}${r.sub ? `<small>${esc(r.sub)}</small>` : ''}</span>`;
86
+ return r.edit ? `<button type="button" class="ia-xr" data-ia-edit="${esc(r.key)}" aria-label="${esc(r.label + ': ' + r.text + '. Edit')}" title="Edit"><b>${esc(r.label)}</b>${val}</button>`
87
+ : `<div class="ia-xr"><b>${esc(r.label)}</b>${val}</div>`;
88
+ };
89
+ return `<section class="ia-sec" aria-label="Experiment" data-ia-exp><div class="ia-th"><b>Experiment</b><span class="n">${esc('Claude keeps it' + (M.exp.at ? ' · ' + dm(M.exp.at) : ''))}</span></div>`
90
+ + `<div class="iv-folds">${M.exp.rows.map(rowHtml).join('')}<p class="ia-note">Press a line to edit it. Claude asks before it changes one you edited.</p></div></section>`;
91
+ }
92
+
93
+ export function workHtml(M, up, o = {}) {
94
+ if (!M || (!M.work.length && !M.failed && !up)) return '';
95
+ const all = !!o.all, shown = all ? M.work : M.work.slice(0, SHOW), more = M.work.length - shown.length;
96
+ const row = (w) => `<div class="ia-dr" data-ref="${esc(w.ref)}"><span class="ck" aria-hidden="true">${SVG(P.check, 12, 2.6)}</span><span><b>${esc(w.title)}</b><em>${esc([w.reason, dm(w.at)].filter(Boolean).join(' · '))}</em></span>`
97
+ + `<button type="button" class="yd-alt sm" data-ia-undo="${esc(w.ref)}" data-ws="${esc(w.ws)}" aria-label="${esc('Undo: ' + w.title)}" title="Undo">${SVG(P.undo, 16, 2)}</button></div>`;
98
+ const list = M.work.length || M.failed ? `<div class="iv-folds">${M.failed ? failLine(M.failed) : ''}${shown.map(row).join('')}`
99
+ + (more > 0 ? `<button type="button" class="iv-fr" data-ia-more aria-expanded="false"><b>${more} more</b><span class="iv-cv" aria-hidden="true">${SVG(P.right, 14, 2)}</span></button>` : '') + '</div>' : '';
100
+ const cu = up ? `<p class="ia-cu">${SVG(P.clock, 14, 2)}<span><b>${esc('Coming up · ' + up.date + '.')}</b> ${esc(up.text)}</span></p>` : '';
101
+ const n = M.week ? M.week + ' this week' : M.work.length ? M.work.length + ' in 14 days' : '';
102
+ return `<section class="ia-sec" aria-label="Claude’s work" data-ia-work><div class="ia-th"><b>Claude’s work</b>${n ? `<span class="n">${esc(n)}</span>` : ''}</div>${list}${cu}</section>`;
103
+ }
104
+
105
+ /** Both sections in one holder the page can swap when the reads arrive. */
106
+ export function sectionsHtml(M, v, id, o = {}) {
107
+ return `<div class="ia" data-ia="${esc(id)}">${expHtml(M)}${workHtml(M, comingUp(v), o)}</div>`;
108
+ }
109
+
110
+ /* ── the reads and the presses (the page only) ── */
111
+ const CACHE = new Map(), WANT = new Map(), OPEN = new Set();
112
+ const FRESH_MS = 30e3;
113
+ export const cached = (id) => (CACHE.get(id) || {}).M || null;
114
+ export const allOpen = (id) => OPEN.has(id);
115
+ /** Read the experiment and Claude's work for one initiative, at most every 30 s; done() runs when the answer changed what shows. */
116
+ export function want(ws, id, done) {
117
+ if (!id) return;
118
+ const c = CACHE.get(id), k = ws + '|' + id;
119
+ if (c && Date.now() - c.at < FRESH_MS) return;
120
+ if (WANT.has(k)) return;
121
+ const q = ws ? 'ws=' + encodeURIComponent(ws) + '&' : '';
122
+ const p = Promise.all([pmGet('/api/artefacts?' + q + 'scope=' + encodeURIComponent('experiment:' + id)).catch(() => null), pmGet('/api/autonomy' + (ws ? '?ws=' + encodeURIComponent(ws) : '')).catch(() => null)])
123
+ .then(([a, u]) => {
124
+ const M = agentModel(a && a.ok ? a : null, u && u.ok ? u : null, id);
125
+ const was = JSON.stringify(cached(id));
126
+ CACHE.set(id, { M, at: Date.now() });
127
+ if (JSON.stringify(M) !== was && done) done();
128
+ }).finally(() => WANT.delete(k));
129
+ WANT.set(k, p);
130
+ }
131
+ const forget = (id) => { const c = CACHE.get(id); if (c) c.at = 0; };
132
+ export function toggleMore(id) { if (OPEN.has(id)) OPEN.delete(id); else OPEN.add(id); }
133
+
134
+ /** A press on a field: the line turns into its editor (a text field, or the three builders for Who builds). */
135
+ export function edit(btn) {
136
+ const sec = btn.closest('[data-ia]'), id = sec && sec.dataset.ia, M = cached(id);
137
+ const r = M && M.exp && M.exp.rows.find((x) => x.key === btn.dataset.iaEdit);
138
+ if (!r || !r.edit) return;
139
+ const field = r.edit.pick ? `<select name="v" aria-label="${esc(r.label)}">${r.edit.pick.map((p) => `<option value="${esc(p)}"${p === r.value ? ' selected' : ''}>${esc(WHO[p])}</option>`).join('')}</select>`
140
+ : `<textarea name="v" rows="2" aria-label="${esc(r.label)}">${esc(r.text)}</textarea>`;
141
+ const f = document.createElement('form');
142
+ f.className = 'ia-xr ia-ed'; f.dataset.iaKey = r.key;
143
+ f.innerHTML = `<b>${esc(r.label)}</b><span class="ia-v">${field}<span class="ia-eb"><button type="submit" class="yd-ok sm" aria-label="Save" title="Save">${SVG(P.check, 16, 2.6)}</button><button type="button" class="yd-alt sm" data-ia-cancel aria-label="Cancel" title="Cancel">${SVG(P.x, 16, 2)}</button></span></span>`;
144
+ btn.replaceWith(f);
145
+ const el = f.querySelector('[name="v"]'); if (el) el.focus();
146
+ }
147
+ /** Save the PM's edit of one line; then read again and draw. */
148
+ export async function save(form, ws, redraw, toast) {
149
+ const id = form.closest('[data-ia]').dataset.ia, M = cached(id), r = M && M.exp && M.exp.rows.find((x) => x.key === form.dataset.iaKey);
150
+ const v = String(form.querySelector('[name="v"]').value || '').trim();
151
+ if (!r || !v) { redraw(); return; }
152
+ const res = await pmPost('/api/artefacts/set', { ws: ws || undefined, scope: 'experiment:' + id, artefact: r.edit.artefact, field: r.edit.field, text: v }).catch(() => null);
153
+ if (!res || !res.ok) { if (toast) toast((res && res.error) || 'It could not be saved. Nothing changed.'); redraw(); return; }
154
+ forget(id); want(ws, id, redraw);
155
+ }
156
+ /** Undo one change Claude made here (POST /api/autonomy/undo); then read again and draw. */
157
+ export async function undo(btn, ws, redraw, toast) {
158
+ if (btn.disabled) return; btn.disabled = true;
159
+ const id = btn.closest('[data-ia]').dataset.ia;
160
+ const res = await pmPost('/api/autonomy/undo', { ws: btn.dataset.ws || ws || undefined, ref: btn.dataset.iaUndo }).catch(() => null);
161
+ if (!res || !res.ok) { btn.disabled = false; if (toast) toast((res && res.error) || 'It could not be undone. Nothing changed.'); return; }
162
+ if (toast) toast('Undone.');
163
+ forget(id); want(ws, id, redraw);
164
+ }
@@ -169,9 +169,9 @@ button.iv-wf:hover, .iv-prog:hover { background: var(--cz-well2) !important; col
169
169
  }
170
170
 
171
171
  /* Tasks: the WBS, one section per stage */
172
- .iv-th { display: flex; align-items: center; gap: 8px; padding: 4px 2px 0; }
173
- .iv-th b { font-size: var(--fs-row); font-weight: var(--fw-strong); line-height: var(--lh-row); }
174
- .iv-th .n { font-size: var(--fs-label); color: var(--cz-ink3); font-weight: var(--fw-strong); line-height: var(--lh-label); }
172
+ .iv-th, .ia-th { display: flex; align-items: center; gap: 8px; padding: 4px 2px 0; }
173
+ .iv-th b, .ia-th b { font-size: var(--fs-row); font-weight: var(--fw-strong); line-height: var(--lh-row); }
174
+ .iv-th .n, .ia-th .n { font-size: var(--fs-label); color: var(--cz-ink3); font-weight: var(--fw-strong); line-height: var(--lh-label); }
175
175
  .iv-th .iv-ib { margin-left: auto; }
176
176
  .iv-wbs { display: flex; flex-direction: column; border-radius: 18px; border: 1px solid var(--cz-hair); overflow: hidden; }
177
177
  .iv-ws { display: flex !important; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 4px 12px 4px 14px !important; position: relative; }
@@ -1324,3 +1324,32 @@ body.iv-dragging { user-select: none; -webkit-user-select: none; cursor: grabbin
1324
1324
  .bp-say { flex: 1 1 100%; min-height: 40px; border-radius: 12px; border: 1px solid var(--cz-hair); background: var(--cz-card); color: var(--cz-ink); padding: 0 12px; font: inherit; }
1325
1325
  .bp-full { display: flex; align-items: center; gap: 8px; min-height: 44px; margin-top: 12px; border: 0; background: none; color: var(--cz-ink3); font: inherit; font-size: var(--fs-meta); cursor: pointer; }
1326
1326
  .bp-full:hover { color: var(--cz-blueink); }
1327
+
1328
+ /* agent-run (board AwB, agreed 2026-11-10): the Experiment, Claude's work with its reasons and Undo, one Coming up line (pm/ini-agent.js) */
1329
+ .ia { display: contents; }
1330
+ .ia-sec { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
1331
+ .ia-xr, .iv button.ia-xr { display: flex; gap: 12px; width: 100%; padding: 11px 14px; position: relative; border: 0; background: none; text-align: left; font: inherit; font-size: var(--fs-meta); line-height: 1.45; color: var(--cz-ink); }
1332
+ button.ia-xr { cursor: pointer; }
1333
+ button.ia-xr:hover { background: var(--cz-well); }
1334
+ .ia-xr + .ia-xr::before { content: ""; position: absolute; left: 14px; right: 12px; top: 0; height: 1px; background: var(--cz-hair); }
1335
+ .ia-xr > b { flex: none; width: 112px; font-weight: var(--fw-strong); color: var(--cz-ink2); }
1336
+ .ia-v { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
1337
+ .ia-v small { display: block; font-size: var(--fs-label); color: var(--cz-ink3); }
1338
+ .ia-ed textarea, .ia-ed select { width: 100%; box-sizing: border-box; font: inherit; color: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--cz-hair); background: var(--cz-card); }
1339
+ .ia-eb { display: flex; gap: 6px; }
1340
+ .ia-note { margin: 0; padding: 4px 14px 11px; font-size: var(--fs-label); color: var(--cz-ink3); line-height: 1.45; }
1341
+ .ia-dr { display: flex; align-items: flex-start; gap: 10px; padding: 8px 8px 8px 14px; position: relative; font-size: var(--fs-meta); line-height: 1.45; }
1342
+ .ia-dr + .ia-dr::before, .ia-fl + .ia-dr::before { content: ""; position: absolute; left: 14px; right: 12px; top: 0; height: 1px; background: var(--cz-hair); }
1343
+ .ia-dr .ck { flex: none; width: 20px; height: 20px; border-radius: 10px; margin-top: 1px; background: var(--cz-blueink); color: var(--cz-onsolid); display: inline-flex; align-items: center; justify-content: center; }
1344
+ .ia-dr > span:not(.ck) { flex: 1; min-width: 0; }
1345
+ .ia-dr b { font-weight: var(--fw-strong); }
1346
+ .ia-dr em { display: block; font-style: normal; font-size: var(--fs-label); color: var(--cz-ink3); }
1347
+ .ia-dr .yd-alt.sm { flex: none; width: 36px; height: 36px; }
1348
+ .ia-fl { display: flex; gap: 8px; align-items: flex-start; margin: 8px 8px 4px; padding: 9px 12px; border-radius: 12px; background: var(--cz-latebg); color: var(--cz-late); font-size: var(--fs-label); line-height: 1.45; }
1349
+ .ia-fl svg, .ia-cu svg { flex: none; margin-top: 2px; }
1350
+ .ia-cu { display: flex; gap: 8px; align-items: flex-start; margin: 0; padding: 10px 14px; font-size: var(--fs-label); color: var(--cz-blueink); line-height: 1.45; }
1351
+ @media (max-width: 760px) { .ia-xr { flex-direction: column; gap: 2px; } .ia-xr > b { width: auto; } }
1352
+ .ia .yd-ok, .ia .yd-alt { flex: none; border: 0; padding: 0; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font: inherit; width: 36px; height: 36px; border-radius: 18px; }
1353
+ .ia .yd-ok { background: var(--cz-blue); color: var(--cz-onsolid); }
1354
+ .ia .yd-alt { background: var(--cz-well); color: var(--cz-ink2); }
1355
+ .ia .yd-alt:disabled { opacity: .5; cursor: default; }
@@ -47,6 +47,7 @@ import * as AB from './ini-about.js'; // About: the description and the succes
47
47
  import { headerFlags } from './grill-words.js'; // the grill findings on the header (workspace grill W3)
48
48
  import * as ED from './ini-edit.js'; // a task changed where it sits in the List: open in place, ⋯, + per stage, drag (batch 18 item 16)
49
49
  import { ticks } from './ini-view-model.js'; // W1: a task group ticks only when every task in it is done
50
+ import * as IA from './ini-agent.js'; // agent-run (board AwB): the Experiment, Claude's work with Undo, Coming up; the D107 gate
50
51
 
51
52
  const CSS = new URL('./ini-view.css', import.meta.url).href;
52
53
  if (typeof document !== 'undefined' && document.head && !document.querySelector(`link[href="${CSS}"]`)) {
@@ -409,12 +410,15 @@ function foldsHtml(v, o) {
409
410
  const VIEWED = new Map(); // initiative id → the view drawn last (the ✦ in the Viewer's header reads it)
410
411
  const OPTS = new Map(); // initiative id → the options it was drawn with, so About can draw alone when its description arrives
411
412
  export function viewHtml(v, o = {}) {
413
+ // agent-run (AwB): with an experiment on record the gate to Build reads its done test and kill condition (D107), not PRD and rubric
414
+ const AM = v && v.id ? IA.cached(v.id) : null, ag = IA.gateOf(AM);
415
+ if (ag && v.stage) v = { ...v, stage: { ...v.stage, gate: ag } };
412
416
  if (v && v.id) { VIEWED.set(v.id, v); OPTS.set(v.id, o); }
413
417
  // a merged initiative leads with where its work went, and draws no stage or tasks (they moved; its folds stay); an open one shows Claude's split or merge card under the summary (batch 11 item 14)
414
418
  if (v.merged) return `<div class="iv" data-iv="${esc(v.id || v.key || '')}"><div class="iv-cols"><div class="iv-cl">${smMerged(v.merged)}</div><div class="iv-cr">${foldsHtml(v, o)}${o.tail || ''}</div></div></div>`;
415
419
  // One reading column: summary, milestones and proposals, then content-sized Tasks and document folds.
416
420
  return `<div class="iv" data-iv="${esc(v.id || v.key || '')}"><div class="iv-cols"><div class="iv-cl">${ctrlHtml(v, o)}${o.sm !== false ? smCard(v.suggest, v.title) : ''}</div>`
417
- + `<div class="iv-cr"><section class="iv-tasks" aria-label="Tasks">${tasksHtml(v, o)}</section>${foldsHtml(v, o)}${o.tail || ''}</div></div></div>`;
421
+ + `<div class="iv-cr">${v.id ? IA.sectionsHtml(AM, v, v.id, { all: IA.allOpen(v.id) }) : ''}<section class="iv-tasks" aria-label="Tasks">${tasksHtml(v, o)}</section>${foldsHtml(v, o)}${o.tail || ''}</div></div></div>`;
418
422
  }
419
423
 
420
424
  /* ── the presses ── */
@@ -423,7 +427,19 @@ export function wireView(body, h) {
423
427
  const idOf = () => { const n = body.querySelector('[data-iv]'); return n ? n.dataset.iv : null; };
424
428
  body.__iv = LK.wrap(VS.wrap(ED.writes({ ...h, __id: idOf }), body, (id) => SHOWN.get(id)), idOf);
425
429
  // the one blue ✦ after the title (pm/ini-props.js), drawn again with each draw of the initiative
426
- const chip = () => { const id = idOf(); if (id && VIEWED.has(id)) PP.sync(VIEWED.get(id), body.__iv || {}); drafts(id); about(id); fitMission(body); };
430
+ const chip = () => { const id = idOf(); if (id && VIEWED.has(id)) PP.sync(VIEWED.get(id), body.__iv || {}); drafts(id); about(id); agent(id); fitMission(body); };
431
+ // agent-run (AwB): the experiment and Claude's work, read every 30 s at most; they draw alone (and the gate with them) when they change
432
+ const wsOf = () => { const H = body.__iv || {}; return ((H.where && H.where()) || {}).ws || ''; };
433
+ const agent = (id) => { if (id && VIEWED.has(id)) IA.want(wsOf(), id, () => paintAgent(id)); };
434
+ const paintAgent = (id) => {
435
+ if (idOf() !== id || !VIEWED.has(id)) return;
436
+ const v0 = VIEWED.get(id), M = IA.cached(id), g = IA.gateOf(M), v = g ? { ...v0, stage: { ...v0.stage, gate: g } } : v0;
437
+ VIEWED.set(id, v);
438
+ // replace only what changed: a node another press holds (a task card's day picker) is never swapped for an identical copy
439
+ const swap = (n, html) => { const t = document.createElement('template'); t.innerHTML = html; const x = t.content.firstElementChild; if (!x || !x.isEqualNode(n)) n.outerHTML = html; };
440
+ const at = body.querySelector('[data-ia]'); if (at) swap(at, IA.sectionsHtml(M, v, id, { all: IA.allOpen(id) }));
441
+ if (g) for (const n of body.querySelectorAll('.iv-gate')) swap(n, srcGateHtml({ gate: g }));
442
+ };
427
443
  // the success measure Claude drafted: read once per page load, the view draws again when it arrives
428
444
  const drafts = (id) => { const H = body.__iv || {}; if (id && VIEWED.has(id)) MD.want(((H.where && H.where()) || {}).ws || '', 'initiative', id, () => { if (idOf() === id && H.redraw) H.redraw(); }); };
429
445
  // the description: the PRD, read once per path through /api/doc; the view draws again when it arrives
@@ -465,6 +481,11 @@ export function wireView(body, h) {
465
481
  const root = b.closest('[data-iv]'); if (!root) return;
466
482
  const id = root.dataset.iv;
467
483
  const d = b.dataset;
484
+ // agent-run (AwB): edit a line of the experiment, Undo a change of Claude's, the rest of Claude's work
485
+ if (d.iaEdit) { e.preventDefault(); IA.edit(b); return; }
486
+ if ('iaCancel' in d) { e.preventDefault(); paintAgent(id); return; }
487
+ if (d.iaUndo) { e.preventDefault(); IA.undo(b, wsOf(), () => paintAgent(id), H.toast); return; }
488
+ if ('iaMore' in d) { e.preventDefault(); IA.toggleMore(id); paintAgent(id); return; }
468
489
  if (d.ivMc) { e.preventDefault(); const M = MD.measuresOf(id); mcToggle(id, d.ivMc, { proposal: !!(M && M.mode === 'open') }); if (H.redraw) H.redraw(); later(b, (r) => r.querySelector(`[data-iv-mc="${d.ivMc}"]`), true); return; }
469
490
  if (d.abMore && AB.pressMore(b, H.redraw)) { e.preventDefault(); return; }
470
491
  if (d.md && MD.press(b, { redraw: H.redraw, toast: H.toast })) { e.preventDefault(); return; }
@@ -497,6 +518,8 @@ export function wireView(body, h) {
497
518
  });
498
519
  // the inline add (the Tasks + icon): Enter adds, Esc puts the + back
499
520
  body.addEventListener('submit', (e) => {
521
+ const ed = e.target.closest('form.ia-ed');
522
+ if (ed) { e.preventDefault(); const r = ed.closest('[data-iv]'); IA.save(ed, wsOf(), () => paintAgent(r && r.dataset.iv), (body.__iv || {}).toast); return; }
500
523
  const f = e.target.closest('[data-iv-addform]'); if (!f) return;
501
524
  e.preventDefault(); const H = body.__iv || {}, inp = f.querySelector('input'), t = inp ? inp.value.trim() : '';
502
525
  if (t && H.addTask) H.addTask(t, inp);
@@ -36,7 +36,8 @@
36
36
  * rows, mentions: GET /api/mentions waiting, outbox: GET /api/outbox entries, now }
37
37
  * → { rows (at most CAP), wait (Can wait, ranked), older: [] (kept for old callers), expired: [{ ini, title, why, at, name }],
38
38
  * done: [{ ref, via: 'autonomy' | 'proposals', ini, board, ws, at, said, name }] (C2: what Claude finished by itself, with Undo),
39
- * notices: [{ job, product, until, text?, ws }] (a job demoted to propose, said once), n }
39
+ * notices: [{ job, product, until, text?, ws }] (a job demoted to propose, said once), failed: [{ run, ini, at, why, ws, name }] (agent-run
40
+ * R4: the runs that stopped, GET /api/autonomy failed), n }
40
41
  * A row: { key, rank, kind, title, sub, tag, at, age, older, ws, board, ini, program, props: [{ ws, board, ini, ids, sigs }], ms: { program,
41
42
  * keys } | null, verdict: { ini, board, verdict, text } | null, yes: label | '', alt: label | '', call } */
42
43
  import { findingOf } from './grill-words.js';
@@ -201,13 +202,15 @@ export function rankMove(o = {}) {
201
202
  rows.sort((a, b) => a.rank - b.rank || (a.at == null) - (b.at == null) || (a.at || 0) - (b.at || 0) || a.key.localeCompare(b.key));
202
203
  // C3: at most CAP show; the rest can wait, in the same order. The expired ✦ of the last 7 days, said once.
203
204
  // C2: what Claude finished by itself (lib/done-feed.js), one line per batch with its initiative's name and one Undo
204
- const expired = [], done = [], notices = [];
205
+ const expired = [], done = [], notices = [], failed = [];
205
206
  for (const P of o.products || []) {
206
207
  const M = (o.move && o.move[P.ws || '']) || {}, nameOf = (ini) => { const r = (P.rows || []).find((x) => x && x.id === ini); return (r && (r.title || r.id)) || ini || ''; };
207
208
  for (const x of M.expired || []) expired.push({ ...x, ws: P.ws || '', name: nameOf(x.ini) });
208
209
  for (const x of M.done || []) done.push({ ...x, ws: P.ws || '', board: x.board || P.board || '', name: x.ini ? nameOf(x.ini) : '' });
209
210
  for (const x of M.notices || []) notices.push({ ...x, ws: P.ws || '' });
211
+ for (const x of M.failed || []) failed.push({ ...x, ws: P.ws || '', name: P.name || '', iniName: x.ini ? nameOf(x.ini) : '' }); // agent-run R4: a run that stopped
210
212
  }
211
213
  done.sort((a, b) => String(b.at).localeCompare(String(a.at)));
212
- return { rows: rows.slice(0, CAP), wait: rows.slice(CAP), older: [], expired, done, notices, n: rows.length };
214
+ failed.sort((a, b) => String(b.at).localeCompare(String(a.at)));
215
+ return { rows: rows.slice(0, CAP), wait: rows.slice(CAP), older: [], expired, done, notices, failed, n: rows.length };
213
216
  }
@@ -237,6 +237,9 @@ const TICKETS = [{ key: 'IDPF-3387', title: 'Refactor the AppAuthService', statu
237
237
  ok('S7 ⋯ Milestone makes it a milestone and clears its start (one date), keeping the due day', ms && ms.body.task === 'task-b3' && ms.body.start === '' && ms.body.due == null, JSON.stringify(ms));
238
238
  const one7 = await until(() => p.evaluate(() => { const r = document.querySelector('#czViewer .iv-ed[data-iv-open="task-b3"]'); if (!r) return null; const d = [...r.querySelectorAll('.iv-edd')]; return d.length === 1 && d[0].dataset.one === '1' ? d[0].getAttribute('aria-label') : null; }));
239
239
  ok('S7 the open row then shows one ◇ date chip, no Start and Due', one7 === 'Milestone date: Nov 12. Change', one7);
240
+ // the Viewer's Experiment and Claude's work sit above Tasks, so the row may sit below the fold: bring it in first and let that scroll
241
+ // settle, or its late scroll event closes the picker the click just opened (a scroll outside the picker closes it)
242
+ await p.$eval('#czViewer .iv-ed .iv-edd', (n) => n.scrollIntoView({ block: 'center' })); await p.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
240
243
  await p.click('#czViewer .iv-ed .iv-edd');
241
244
  const op7 = await until(() => p.evaluate(() => { const q = document.querySelector('.tkc.ivq .tkc-dp'); return q ? { tabs: q.querySelectorAll('[data-tkc-field]').length, head: (q.querySelector('.ivd-h b') || {}).textContent, sub: (q.querySelector('.ivd-s') || {}).textContent } : null; }));
242
245
  ok('S7 its picker is one date: "◇ Date", no Start and Due tabs', op7 && op7.tabs === 0 && op7.head === 'Date' && /one date: the milestone/.test(op7.sub || ''), JSON.stringify(op7));
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Agent-run workspace (boards AwA, AwB): the initiative Viewer's Experiment, Claude's work with Undo, Coming up and the D107 gate (pure, node): pm/ini-agent.js.",
3
+ "modules": [
4
+ "ini-agent.test.js"
5
+ ],
6
+ "seconds": {
7
+ "ini-agent.test.js": 1
8
+ }
9
+ }