create-pmos 0.598.0 → 0.600.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.
Files changed (48) hide show
  1. package/package.json +27 -27
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/scripts/pmos-memory.js +42 -16
  6. package/payload/state/discoveries.md +1 -1
  7. package/workspace/changelog.json +26 -0
  8. package/workspace/guide/cli.md +9 -0
  9. package/workspace/guide/layout.md +10 -3
  10. package/workspace/lib/bg-queue.js +1 -0
  11. package/workspace/lib/briefing-premium-agent.js +12 -5
  12. package/workspace/lib/corrections-memory.js +9 -5
  13. package/workspace/lib/cos-chat.js +15 -1
  14. package/workspace/lib/driver.js +4 -1
  15. package/workspace/lib/engine/pmos-memory.js +42 -16
  16. package/workspace/lib/goal-loop.js +2 -1
  17. package/workspace/lib/headless.js +7 -3
  18. package/workspace/lib/initiative-premium.js +2 -2
  19. package/workspace/lib/job-graph.js +4 -0
  20. package/workspace/lib/owner-cli.js +30 -0
  21. package/workspace/lib/pmos-verbs.js +5 -0
  22. package/workspace/lib/route-modules.js +1 -0
  23. package/workspace/lib/routes-briefing-premium.js +3 -1
  24. package/workspace/lib/routes-home-desk.js +13 -1
  25. package/workspace/lib/routes-initiative-premium.js +11 -1
  26. package/workspace/lib/routes-proposals.js +1 -1
  27. package/workspace/lib/routes-units.js +52 -0
  28. package/workspace/lib/team-cli.js +16 -1
  29. package/workspace/lib/team-runs.js +5 -2
  30. package/workspace/lib/unit-memory.js +65 -0
  31. package/workspace/lib/unit-owner.js +185 -0
  32. package/workspace/lib/units-cli.js +45 -0
  33. package/workspace/lib/units-host.js +151 -0
  34. package/workspace/lib/units.js +88 -0
  35. package/workspace/package-lock.json +2 -2
  36. package/workspace/package.json +1 -1
  37. package/workspace/public/pm/cozy-home.css +76 -0
  38. package/workspace/public/pm/cozy-live-pill.js +4 -0
  39. package/workspace/public/pm/cozy-nav.js +26 -6
  40. package/workspace/public/pm/cozy-today.css +3 -0
  41. package/workspace/public/pm/home-app.js +60 -2
  42. package/workspace/public/pm/home-chat.js +17 -2
  43. package/workspace/public/pm/home-list.js +14 -2
  44. package/workspace/public/pm/home-today.js +7 -4
  45. package/workspace/public/pm/phone-chat-head.js +147 -0
  46. package/workspace/server.js +26 -1
  47. package/workspace/test-files.json +1 -0
  48. package/workspace/test-lists/roomier-phone-chat.json +9 -0
@@ -21,6 +21,8 @@
21
21
  * are Adler's ears over the phone button (AdP6): Your move is the one place that says what is yours.
22
22
  * THE CHAT (C5, board CsB): the tray's chat icon opens the one chat over the page you are on (pm/page-chat.js openCos), with a soft
23
23
  * "You are on …" chip. A page that has its own chat column (Home) passes opts.chat() and the icon focuses that chat instead.
24
+ * FROM THE TOP BAR (batch 31 item 5, board RcBmenu): openMenu({ anchor, rows }) opens the same menu under a page's own ⋯ (the phone
25
+ * chat has no round button). rows go on top of the places, each { label, icon, dot, go }; the menu closes and focus goes back to the anchor.
24
26
  */
25
27
  import { esc, svg, ICON, wsQ } from './cozy-evui.js';
26
28
  import { fabLabel, bannerOf } from './cozy-evmodel.js';
@@ -35,7 +37,8 @@ export const PLACES = [
35
37
  export { fabLabel };
36
38
  const THEME_KEY = 'pmos.c3.theme';
37
39
  const CSS = new URL('./cozy-ev.css', import.meta.url).href;
38
- const N = { news: 0, stale: null, here: 'home', calls: 0, fresh: new Set() };
40
+ const N = { news: 0, stale: null, here: 'home', calls: 0, fresh: new Set(), extra: [], from: null };
41
+ let OPEN = null; // mountNav's own open(o): openMenu reaches the one menu of the page
39
42
  /* A place that just opened (onboarding B3, ObA4Gradual; GET /api/moments places[p].dot): its menu row gets one soft blue dot until the PM
40
43
  * first opens it. Reports live in Intelligence, so their dot is on the Intelligence row. */
41
44
  const ROW_OF = { board: 'board', insights: 'insights', reports: 'insights' };
@@ -54,10 +57,12 @@ export function setTheme(pick, doc = document, { keep = true } = {}) {
54
57
  doc.dispatchEvent(new CustomEvent('cz:theme', { detail: { pick: p, dark } }));
55
58
  }
56
59
 
57
- /** The menu's markup; pure, so a unit test can read it. here: home | board | insights. o: { news, stale: { text } | null } */
60
+ /** The menu's markup; pure, so a unit test can read it. here: home | board | insights. o: { news, stale: { text } | null, extra: rows }
61
+ * extra: the rows a page's own ⋯ puts on top ({ label, icon, dot }), as buttons data-cz-extra="i". */
58
62
  export function menuHtml(here, o = {}) {
59
63
  const calls = o.calls > 0, dot = (c) => `<i class="ev-md ${c}" aria-hidden="true"></i>`;
60
- return PLACES.map((p) => {
64
+ const extra = (o.extra || []).map((x, i) => `<button type="button" class="ev-mi ev-x" data-cz-extra="${i}">${x.icon ? svg(x.icon, 18) : ''}<span>${esc(x.label)}</span>${x.dot ? dot('you') : ''}</button>`).join('');
65
+ return extra + PLACES.map((p) => {
61
66
  const opened = p.key !== here && !!(o.fresh && o.fresh.has(p.key));
62
67
  const you = (p.key === 'home' && calls) || opened;
63
68
  const lab = p.key === 'home' && calls ? ` aria-label="${p.label}. ${o.calls === 1 ? 'One call is yours' : o.calls + ' calls are yours'} in Your move"` : opened ? ` aria-label="${p.label}. New: it has something to show now"` : '';
@@ -80,6 +85,9 @@ async function getj(p) { try { const r = await fetch(p, { credentials: 'same-ori
80
85
  /** What the button adds to its name while a call is the PM's: 'One call is yours' · '3 calls are yours'. */
81
86
  export const callWords = (n) => (n === 1 ? 'One call is yours' : n + ' calls are yours');
82
87
 
88
+ /** Open the page's one menu from its own button (the phone chat's ⋯): { anchor, rows: [{ label, icon, dot, go }] }. A second press closes it. */
89
+ export function openMenu(o = {}) { if (OPEN) OPEN(o); }
90
+
83
91
  /** Mount the menu once. `here` is home | board | insights. Returns the wrapper. */
84
92
  export function mountNav(here, doc = document, opts = {}) {
85
93
  const old = doc.getElementById('czNav'); if (old) return old;
@@ -98,7 +106,7 @@ export function mountNav(here, doc = document, opts = {}) {
98
106
  mountToastFaces(doc); loadPrefs();
99
107
  const fab = w.querySelector('#czFab'), menu = w.querySelector('#czMenu'), scrim = w.querySelector('#czScrim');
100
108
  const draw = () => {
101
- menu.innerHTML = menuHtml(here, { calls: N.calls, stale: N.stale, fresh: N.fresh });
109
+ menu.innerHTML = menuHtml(here, { calls: N.calls, stale: N.stale, fresh: N.fresh, extra: N.extra });
102
110
  const opened = [...N.fresh].some((k) => k !== here);
103
111
  // one dot: amber while a source needs the PM, else blue while a call is theirs or a place has something new
104
112
  w.querySelector('#czFdRisk').hidden = !N.stale || !menu.hidden;
@@ -106,23 +114,35 @@ export function mountNav(here, doc = document, opts = {}) {
106
114
  if (menu.hidden) fab.setAttribute('aria-label', fabLabel(here, false, N.stale) + (opened ? '. A place has something new to show' : '') + (N.calls > 0 ? '. ' + callWords(N.calls) : ''));
107
115
  };
108
116
  const set = (open) => {
117
+ if (!open && N.from) { N.from.setAttribute('aria-expanded', 'false'); N.from = null; N.extra = []; w.classList.remove('cz-top'); }
109
118
  menu.hidden = !open; scrim.hidden = !open; fab.setAttribute('aria-expanded', String(open));
110
119
  fab.setAttribute('aria-label', fabLabel(here, open, N.stale)); fab.innerHTML = svg(open ? ICON.close : ICON.menu, 22);
111
120
  draw();
112
121
  if (open) { const f = menu.querySelector('a, button'); if (f) f.focus(); }
113
122
  };
123
+ OPEN = (o) => {
124
+ const back = N.from;
125
+ if (!menu.hidden) { set(false); if (back === o.anchor) { if (back) back.focus(); return; } }
126
+ N.from = o.anchor || null; N.extra = o.rows || [];
127
+ w.classList.toggle('cz-top', !!N.from);
128
+ if (N.from) N.from.setAttribute('aria-expanded', 'true');
129
+ set(true);
130
+ };
114
131
  draw();
115
132
  fab.addEventListener('click', () => set(menu.hidden));
116
133
  scrim.addEventListener('click', () => set(false));
117
- doc.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !menu.hidden) { e.stopPropagation(); set(false); fab.focus(); } }, true);
134
+ doc.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !menu.hidden) { e.stopPropagation(); const back = N.from || fab; set(false); back.focus(); } }, true);
118
135
  // set() redraws the button's icon, so the pressed icon may be gone from the page by now: only a press still on the page closes the menu
119
- doc.addEventListener('click', (e) => { if (!menu.hidden && e.target.isConnected && !w.contains(e.target)) set(false); });
136
+ // (the ⋯ that opened it toggles it itself)
137
+ doc.addEventListener('click', (e) => { if (!menu.hidden && e.target.isConnected && !w.contains(e.target) && !(N.from && N.from.contains(e.target))) set(false); });
120
138
  menu.addEventListener('click', (e) => {
121
139
  // the page you are on, pressed again: a page that passes opts.here goes back to its start without a reload (Home: the list, no page open)
122
140
  const a = e.target.closest('a[aria-current="page"]');
123
141
  if (a && opts.here && !e.metaKey && !e.ctrlKey && !e.shiftKey) { e.preventDefault(); set(false); opts.here(); return; }
124
142
  const b = e.target.closest('button'); if (!b) return;
143
+ const x = 'czExtra' in b.dataset ? N.extra[+b.dataset.czExtra] : null;
125
144
  set(false);
145
+ if (x) { if (x.go) x.go(); return; }
126
146
  if ('czChat' in b.dataset) { if (opts.chat) opts.chat(); else import('./page-chat.js').then((M) => M.openCos({ here: opts.where ? opts.where() : PLACES.find((p) => p.key === here) ? PLACES.find((p) => p.key === here).label : '' })); }
127
147
  else if ('czSearch' in b.dataset) import('./cozy-search.js').then((M) => M.openSearch({ ...(opts.search ? { go: opts.search() } : {}), ...(opts.scope ? { scope: opts.scope() } : {}) }));
128
148
  // a stale source opens Settings at Connectors, the stale one first (FmA3Settings: open where it matters)
@@ -292,6 +292,9 @@ body.cz-home .hm-lsc { margin: 0 -12px; padding: 0 12px 4px; }
292
292
 
293
293
  /* the card and its one-line rows (HvAC .card, .row, .kid) */
294
294
  .hv-card { background: var(--cz-card); border-radius: 18px; padding: 3px 0; }
295
+ /* chief-unit-owners ✦2 + addendum: the group owner's one quiet line under the group's name; a press opens the unit's chat */
296
+ .hv-unit { display: block; margin: 0 14px 6px 44px; padding: 0; border: 0; background: none; font: inherit; font-size: var(--fs-meta); color: var(--cz-ink3); line-height: var(--lh-meta); text-align: left; cursor: pointer; }
297
+ .hv-unit:hover { color: var(--cz-ink2, var(--cz-ink3)); text-decoration: underline; }
295
298
  body.cz-home .hv-r { position: relative; display: flex; align-items: center; gap: 0; min-height: 0; margin: 0; border-radius: 14px; background: none; box-shadow: none; }
296
299
  body.cz-home .hv-r .hm-rm { flex: 1; min-width: 0; min-height: 44px; display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 6px; border-radius: 14px; }
297
300
  body.cz-home .hv-r .hm-ck + .hm-rm { padding-left: 8px; }
@@ -15,7 +15,8 @@
15
15
  * The models are in home-data.js and home-list.js (pure). This file reads the routes, draws, and wires the presses. Every write is the PM's
16
16
  * press (pmPost). Nothing here opens the old dialog or links to the console. */
17
17
  import './fetch-share.js'; // first: identical GETs in flight are asked once (page-open-speed)
18
- import { mountNav } from './cozy-nav.js';
18
+ import { mountNav, openMenu } from './cozy-nav.js';
19
+ import { mountPhoneHead } from './phone-chat-head.js'; // the phone chat's top bar: the context line, its sheet and ⋯ (batch 31 item 5)
19
20
  import { mountSetupChecklist } from './setup-checklist.js';
20
21
  import { mountOnboard } from './cozy-onboard.js';
21
22
  import { mountReveal, leftHtml as revealLeft } from './cozy-reveal.js';
@@ -979,6 +980,7 @@ function allRows() {
979
980
  const rowById = (id) => allRows().find((r) => r.id === id) || null;
980
981
 
981
982
  /* ── the top bar (phone) ── */
983
+ let PH = null; // the phone chat's top bar (mountPhoneHead, below)
982
984
  function drawTop() {
983
985
  const n = H.needsOf(S.D).length;
984
986
  const cur = S.cur || { title: 'Home', sub: '' };
@@ -992,6 +994,7 @@ function drawTop() {
992
994
  $('#hmNeedsN').textContent = !S.ready ? 'Reading' : n ? n + (n === 1 ? ' next step' : ' next steps') : 'Today';
993
995
  $('#hmNeeds').classList.toggle('loud', n > 0);
994
996
  document.title = 'PMOS · ' + (title || 'Home');
997
+ if (PH) PH.draw();
995
998
  }
996
999
  const SN = mountSesName({ esc, pmPost, toast, toastUndo: (m, u) => toastUndo(m, u), session: (sid) => S.D.sessions.find((x) => x.id === sid) || null, shown: (x) => H.nameOf(x),
997
1000
  changed: () => { drawTop(); chat.refresh(); drawList(); } });
@@ -1384,6 +1387,17 @@ function programTarget(id, task) {
1384
1387
  empty: 'Ask about ' + pr.title + '. PMOS reads the program and its initiatives in a real Claude Code session.',
1385
1388
  context: 'Program ' + pr.title + ' (' + id + ')' + (inis.length ? ', with the initiatives ' + inis.join(', ') : '') + '.' + (task ? ' The PM opened its task "' + task.name + '"' + (task.hint ? ' (' + task.hint + ')' : '') + '.' : ''), also: null };
1386
1389
  }
1390
+ /** chief-unit-owners addendum: a unit's own chat (chat:unit:<kind>:<id>), from the press on its Home line. The server opens it with the
1391
+ * chief's rule, the unit's newest brief and its last 3 lessons (lib/briefing-premium-agent.js). */
1392
+ function unitTarget(unit) {
1393
+ const [kind, ...rest] = String(unit).split(':'), id = rest.join(':');
1394
+ const pr = kind === 'program' ? (S.D.programs || []).find((p) => p && p.id === id) : null;
1395
+ const g = ((S.M && S.M.groups) || []).find((x) => x.unitLine && x.unitLine.key === unit);
1396
+ const name = pr ? pr.title : g ? g.name : id;
1397
+ return { key: 'chat:unit:' + unit, ws: WS || undefined, title: name, sub: kind === 'program' ? 'Program' : kind === 'project' ? 'Projects' : 'Product',
1398
+ scope: { text: name, icon: kind === 'program' ? TD.P.layers : GLOBE }, rich: false, role: CLAUDE, placeholder: 'Message PMOS about ' + name,
1399
+ empty: 'Ask about ' + name + '. PMOS reads its brief and its initiatives.', context: 'The unit ' + name + ' (' + unit + ').', also: null };
1400
+ }
1387
1401
  /** A chat Intelligence asks for (?ask=insights|verdict): titled from the goal it names (?label), scoped to the product's goals, never "ins:insights"
1388
1402
  * and never "All work" (workspace grill W4). */
1389
1403
  function insTarget(key) {
@@ -2162,7 +2176,8 @@ $('#hmList').onclick = (e) => { // delegated: every press on the list is a <bu
2162
2176
  if ('hmDay' in d) { day(!S.day); return; }
2163
2177
  if ('hmDayx' in d) { day(false); return; }
2164
2178
  if ('hmFlt' in d) { filterMenu(b); return; }
2165
- if (d.hmProg) { goProgram(d.hmProg); return; } // the program panel, in Home's Viewer (HbCProg)
2179
+ if (d.hmProg) { goProgram(d.hmProg); return; }
2180
+ if (d.hmUnit) { S.phoneChat = isPhone(); openTarget(unitTarget(d.hmUnit)); return; } // chief-unit-owners addendum: the unit's own chat // the program panel, in Home's Viewer (HbCProg)
2166
2181
  if (d.hmProdopen) { const g = ((S.M && S.M.groups) || []).find((x) => x.key === d.hmProdopen); if (g && !g.primary && g.product && g.product.ws) { goOtherProduct(g); return; } goIni('product'); return; }
2167
2182
  if (d.hmKids) { // the chevron of an initiative: what sits under it shows or hides
2168
2183
  if (b.getAttribute('aria-expanded') === 'true') { S.kids.delete(d.hmKids); S.kidsOff.add(d.hmKids); } else { S.kids.add(d.hmKids); S.kidsOff.delete(d.hmKids); }
@@ -2313,6 +2328,49 @@ const liveGo = (x) => {
2313
2328
  return true;
2314
2329
  };
2315
2330
  mountLivePill(document, { open: () => (S.cur && S.cur.ses) || null, go: liveGo });
2331
+ /* The phone chat's top bar (batch 31 item 5, boards RcB, RcBfiles, RcBmenu): the context line under the title, its sheet, and ⋯ for the
2332
+ * menu with Waiting on you and Live now on top. The initiative's files and pull requests come from its page model: the one Home holds
2333
+ * when it is that initiative, else one read of /api/initiative-premium kept for a minute (PHF). */
2334
+ const PHF = new Map();
2335
+ const iniOfTarget = (t) => { const m = /^init:([^:]+)/.exec((t && t.key) || ''); return (t && t.ini) || (m ? m[1] : null); };
2336
+ function phoneFacts(t) {
2337
+ const ini = iniOfTarget(t);
2338
+ if (!ini || ini === 'product' || !iniRowOf(ini)) return null;
2339
+ let M = S.IM && S.IMid === ini ? S.IM : null;
2340
+ if (!M) {
2341
+ const c = PHF.get(ini);
2342
+ if (c && c.M) M = c.M;
2343
+ if (!c || Date.now() - c.at > 60000) {
2344
+ PHF.set(ini, { M: c ? c.M : null, at: Date.now() });
2345
+ const oi = otherIni(ini);
2346
+ pmGet('/api/initiative-premium?id=' + encodeURIComponent(ini) + (oi && oi.ws ? '&ws=' + encodeURIComponent(oi.ws) : wsQ('&'))).then((r) => {
2347
+ if (r && r.ok && r.model) { PHF.set(ini, { M: r.model, at: Date.now() }); PH.draw(); } else if (r && r.state === 'reading') PHF.delete(ini);
2348
+ }).catch(() => {});
2349
+ }
2350
+ }
2351
+ const files = M && M.docs ? (M.docs.rows || []).filter((d) => d.path) : [];
2352
+ return { ini: { id: ini, title: iniTitle(ini), sub: (M && M.head && M.head.stage) || '' }, files, prs: (M && M.prs) || [] };
2353
+ }
2354
+ async function openIniFrom(id) {
2355
+ if (S.ini !== id) { S.ini = id; S.IM = null; S.IMid = null; S.doneOpen = false; S.stepsMore = false; }
2356
+ return id;
2357
+ }
2358
+ PH = mountPhoneHead({
2359
+ esc, phone: () => isPhone() && !document.body.classList.contains('hm-plist'),
2360
+ target: () => (chat.current ? chat.current() : null),
2361
+ facts: phoneFacts,
2362
+ openIni: async (id) => { await openIniFrom(id); iniPage(); },
2363
+ openFile: (f) => openFile(f),
2364
+ allFiles: async (id) => { await openIniFrom(id); if (S.IMid !== id) await loadIni(); iniOverview('docs'); },
2365
+ sendsTo: (anchor, t) => (t && t.to ? menu(anchor, toItems(t), 'Send your messages to') : menu(anchor, scopeItems(), 'Where this goes')),
2366
+ waiting: () => {
2367
+ const other = H.needsOf(S.D).filter((r) => !(S.sel && S.sel === r.id));
2368
+ const t = chat.current ? chat.current() : null;
2369
+ return { n: other.length, go: () => (t && t.also && t.also.go ? t.also.go() : other[0] ? select(other[0].id) : null) };
2370
+ },
2371
+ openMenu: (o) => openMenu(o),
2372
+ });
2373
+ PH.draw();
2316
2374
  /* The panels (batch 18 item 15, canvas TbT1Split…TbT9Divider): the chat and up to 3 Viewers side by side, the divider, open beside, ⧉, slide
2317
2375
  * over. A Live pill row opens in the chat (liveGo); a remembered Viewer of an initiative opens again here when Home has a view for it. */
2318
2376
  mountPanels({
@@ -14,6 +14,9 @@
14
14
  * The words are Claude Code's own transcript. A conversation is either a chat key (GET /api/briefing-premium/thread?key=, the session it
15
15
  * started, POST /ask and /press) or a session with no chat key (GET /api/sessions/conversation?id=, POST /api/session/say and /keys).
16
16
  * A loose session the host can place (host.suggestLink(target, firstText) → { id, title }) shows one chip: Link it (host.linkTo) or × (host.dismissLink).
17
+ * On a phone (batch 31 item 5) the stream is messages only: no avatar column and no name or time line (both still read out), and
18
+ * Copy, Retry and Make a work-item show on the newest message; an older one shows them on press and hold. The In:/To: chip and the
19
+ * waiting bar leave the box there: the top bar's context line and ⋯ hold them (pm/phone-chat-head.js).
17
20
  * Every write is the PM's press. mountChat(el, host) returns { open(target), refresh(), focus(), send(text) }.
18
21
  * target: { key?, sid?, title, scope: { text, icon, loose }, role: { name, initial }, intro?: { role, text, at, mood? (Adler as the avatar while the log is empty), pills: [{ label, primary, go }] },
19
22
  * ini?, rich, also?: { text, go, verb? ('Answer' when absent; 'Review' for Claude's ✦ proposal) } }
@@ -170,7 +173,7 @@ export function mountChat(el, host) {
170
173
  // a run that stopped: the divider sits where it finished, over Claude's last message, and the fix sits under it (canvas XcbOptions, Routine)
171
174
  const stopAt = R.stop && i === R.lastAgent;
172
175
  const av = last && isClaude(R.role) ? adlerAvHtml(asking || ak.block ? 'needs-you' : stopAt ? 'honest' : running() ? 'thinking' : 'handled') : avHtml(R.role);
173
- return (stopAt ? dividerHtml({ tone: R.stop.tone, text: R.stop.text }) : '') + `<div class="hm-a${asking ? ' ask' : ''}">${av}<div class="hm-ab"><p class="hm-who">${esc(R.role.name)} <span>${esc(hm(it.at))}</span></p>${rp.text ? verHtml(rp.text) : ''}${srcHtml(sr.src)}${goalBlockHtml(go.block, go)}${reportChipHtml(rp.block, it.mi)}${R.chips(it.mi)}`
176
+ return (stopAt ? dividerHtml({ tone: R.stop.tone, text: R.stop.text }) : '') + `<div class="hm-a${asking ? ' ask' : ''}${last ? ' last' : ''}">${av}<div class="hm-ab"><p class="hm-who">${esc(R.role.name)} <span>${esc(hm(it.at))}</span></p>${rp.text ? verHtml(rp.text) : ''}${srcHtml(sr.src)}${goalBlockHtml(go.block, go)}${reportChipHtml(rp.block, it.mi)}${R.chips(it.mi)}`
174
177
  + (asking ? '' : `<div class="hm-tools" role="group" aria-label="Message actions"><button type="button" data-hm-copy="${i}">Copy</button>${last && !running() && !(stopAt && R.stop.actions.length) ? `<button type="button" data-hm-retry>Retry</button>` : ''}<button type="button" data-hm-wi="${i}">Make a work-item</button></div>`) + '</div></div>'
175
178
  + (stopAt && R.stop.actions.length ? `<div class="hm-fix" role="group" aria-label="What to do next">${R.stop.actions.map((a, k) => iconBtn({ icon: a.icon, label: a.label, attr: a.data, pri: k === 0 })).join('')}</div>` : '')
176
179
  + blockAskHtml(ak.block, it, R);
@@ -189,7 +192,7 @@ export function mountChat(el, host) {
189
192
  if (!o) return '';
190
193
  const r = o.role || { name: 'PMOS', initial: 'P' };
191
194
  const card = o.card && typeof o.card.html === 'function' ? o.card.html() : '';
192
- return `<div class="hm-a">${o.mood && alone && isClaude(r) ? adlerAvHtml(o.mood) : avHtml(r)}<div class="hm-ab"><p class="hm-who"><b>${esc(r.name)}</b> <span class="hm-say">${esc(o.text)}</span></p>${card ? `<div class="hm-icard">${card}</div>` : ''}</div></div>`
195
+ return `<div class="hm-a hm-intro">${o.mood && alone && isClaude(r) ? adlerAvHtml(o.mood) : avHtml(r)}<div class="hm-ab"><p class="hm-who"><b>${esc(r.name)}</b> <span class="hm-say">${esc(o.text)}</span></p>${card ? `<div class="hm-icard">${card}</div>` : ''}</div></div>`
193
196
  + (o.pills && o.pills.length ? `<div class="hm-pills">${o.pills.map((p, i) => `<button type="button" class="${p.primary ? 'pri' : ''}" data-hm-pill="${i}"${p.disabled ? ' disabled' : ''}>${esc(p.label)}</button>`).join('')}</div>` : '');
194
197
  }
195
198
  /** Claude's question card (AskUserQuestion), answerable until the PM writes again. */
@@ -725,6 +728,18 @@ export function mountChat(el, host) {
725
728
  window.addEventListener('pmos:point', (e) => { if (!mine(e)) return; C.mark = { ...(C.mark || {}), point: e.detail.el || e.detail.label ? { el: e.detail.el || '', label: e.detail.label || '' } : null }; drawFoot({ role: role() }); const ta = foot.querySelector('textarea'); if (ta && C.mark.point) ta.focus(); });
726
729
  window.addEventListener('pmos:from', (e) => { if (!mine(e)) return; C.mark = { ...(C.mark || {}), from: Number(e.detail.n) || null }; drawFoot({ role: role() }); const ta = foot.querySelector('textarea'); if (ta) ta.focus(); });
727
730
  window.addEventListener('pmos:say', (e) => { if (!mine(e) || !e.detail.text) return; send(String(e.detail.text)); });
731
+ /* An older message's Copy, Retry and Make a work-item on a phone (batch 31 item 5): press and hold the message to show them (the CSS
732
+ * shows them on the newest message, and on focus for a keyboard). A tap elsewhere hides them again. */
733
+ let holdT = null;
734
+ const unhold = () => el.querySelectorAll('.hm-a.held').forEach((x) => x.classList.remove('held'));
735
+ el.addEventListener('pointerdown', (e) => {
736
+ clearTimeout(holdT);
737
+ const a = e.target.closest('.hm-a');
738
+ if (!a || a.classList.contains('last')) { if (!e.target.closest('.hm-tools')) unhold(); return; }
739
+ if (e.target.closest('button, a, input, textarea')) return;
740
+ holdT = setTimeout(() => { unhold(); a.classList.add('held'); }, 450);
741
+ });
742
+ for (const ev of ['pointerup', 'pointercancel', 'pointermove']) el.addEventListener(ev, (e) => { if (ev !== 'pointermove' || Math.abs(e.movementX) + Math.abs(e.movementY) > 6) clearTimeout(holdT); });
728
743
  el.addEventListener('change', (e) => { if (e.target.id === 'hmFile') { upload([...e.target.files]); e.target.value = ''; } });
729
744
  // a pasted file, or one dropped on the conversation, is attached like a picked one
730
745
  el.addEventListener('paste', (e) => { if (e.target.id !== 'hmIn' || !C.t || !C.t.key) return; const fs = e.clipboardData ? [...e.clipboardData.files] : []; if (!fs.length) return; e.preventDefault(); upload(fs); });
@@ -60,6 +60,17 @@ const prodOf = (x) => (x && x.product && x.product !== ACROSS ? x.product : '');
60
60
  * product's place with the board's own first, then the registered order (pm/cozy-pick.js tonesOf), so the chip and the group agree. */
61
61
  /** The pick's unticked test: true for a registered product that is not ticked; a product the pick does not list is never hidden. */
62
62
  const unticked = (D) => { const P = (D.pick && D.pick.products) || (D.brief && D.brief.products && D.brief.products.available) || []; return (ws) => !!ws && P.some((a) => a.ws === ws && !a.on); };
63
+ /** chief-unit-owners ✦2: the one quiet line a group shows from its owner's newest brief (GET /api/home-desk units), "3 done · 1 for you".
64
+ * key: the unit whose chat a press on the line opens (the program, or the product).
65
+ * A product group sums its product and project units. Zero is silence: '' when nothing was done and nothing waits. A failed run counts
66
+ * under done; its reasons go in the line's title, never as the PM's work. */
67
+ export function unitLineOf(D, keys) {
68
+ const U = (D && D.desk && D.desk.units) || {};
69
+ let done = 0, forYou = 0; const failed = [];
70
+ for (const k of keys) { const u = U[k]; if (!u) continue; done += u.done || 0; forYou += u.forYou || 0; failed.push(...(u.failed || [])); }
71
+ const line = [done ? done + ' done' : '', forYou ? forYou + ' for you' : ''].filter(Boolean).join(' · ');
72
+ return line ? { key: keys[0], line, why: failed.length ? failed.length + ' did not finish: ' + failed.map((f) => (f.ini ? f.ini + ', ' : '') + f.why).join('; ') : '' } : null;
73
+ }
63
74
  export function productsOf(D) {
64
75
  const out = [];
65
76
  const b = D.board && D.board.board;
@@ -204,7 +215,7 @@ export function programGroups(D, groups, products, o, now) {
204
215
  const msRow = msSub ? { id: 'ms:' + pr.id, kind: 'msreview', program: pr.id, name: pr.title, hint: msSub, state: 'needs' } : null;
205
216
  // the program's own chats sit in its header's pill, as a product's do, never under "Not in an initiative" (Wawan, 2026-11-02, batch 22 item 17)
206
217
  const kids = (D.sessions || []).filter((s) => listed(s) && isProgramChat(keyOfSession(s), pr.id)).map((s) => sessionRow(s, D.desk && D.desk.roles)).sort((a, b) => (RANK[b.state] || 0) - (RANK[a.state] || 0));
207
- out.push({ key: 'g:' + pr.id, kind: 'program', program: pr, st, name: pr.title, subs, inis, rest: [], tasks, count: inis.length, turnN, msRow, kids,
218
+ out.push({ key: 'g:' + pr.id, kind: 'program', program: pr, unitLine: unitLineOf(D, ['program:' + pr.id]), st, name: pr.title, subs, inis, rest: [], tasks, count: inis.length, turnN, msRow, kids,
208
219
  yours: inis.reduce((n, x) => n + x.yours, 0) + tasks.filter((t) => t.mine && t.late).length + (msRow ? 1 : 0) + kids.filter((k) => k.state === 'needs' || k.state === 'blocked').length, late: inis.some((x) => x.late) || tasks.some((t) => t.late),
209
220
  products: st.products, closedLine: closedOf(inis.length, turnN) });
210
221
  }
@@ -278,7 +289,8 @@ export function homeList(D, o = {}) {
278
289
  const shown = inis.filter((x) => x.turn);
279
290
  // the product's own chats (its heading's chat and its new sessions) sit in the header's pill, as an initiative's sit in its row's
280
291
  const kids = (D.sessions || []).filter((s) => listed(s) && isProductChat(keyOfSession(s), p)).map((s) => sessionRow(s, D.desk && D.desk.roles)).sort((a, b) => (RANK[b.state] || 0) - (RANK[a.state] || 0));
281
- groups.push({ key: 'p:' + p.key, kind: 'product', product: p, name: p.name, kids, initials: p.initials, tone: p.tone, primary: !!p.primary, goals: p.goals, flat, inis: shown, rest: inis.filter((x) => !shown.includes(x)),
292
+ const unitLine = unitLineOf(D, p.ws ? ['product:' + p.ws, 'project:' + p.ws] : []);
293
+ groups.push({ key: 'p:' + p.key, kind: 'product', product: p, unitLine, name: p.name, kids, initials: p.initials, tone: p.tone, primary: !!p.primary, goals: p.goals, flat, inis: shown, rest: inis.filter((x) => !shown.includes(x)),
282
294
  count: inis.length, turnN, yours: inis.reduce((n, x) => n + x.yours, 0) + flat.length + kids.filter((k) => k.state === 'needs' || k.state === 'blocked').length, late: inis.some((x) => x.late), closedLine: [inis.length ? plural(inis.length, 'initiative', 'initiatives') : '', turnN ? turnN + ' your turn' : ''].filter(Boolean).join(' · ') || 'Nothing open' });
283
295
  }
284
296
  // programs first (program-hierarchy P3): each program takes its initiatives out of their product groups, so an initiative shows once
@@ -166,6 +166,9 @@ function iniHtml(r, o, po) {
166
166
  const dots = (g) => (g.goals && g.goals.n ? `<span class="hv-gd" role="img" aria-label="${esc(g.goals.text)}">${g.goals.dots.map((ok) => `<i${ok ? '' : ' class="off"'}></i>`).join('')}</span>` : '');
167
167
  const nd = (g) => (g.yours ? '<span class="hv-nd"></span>' : g.late ? '<span class="hv-nd am"></span>' : '');
168
168
  const yoursWords = (g) => (g.yours ? (g.yours === 1 ? '1 is yours' : g.yours + ' are yours') : '');
169
+ // chief-unit-owners ✦2: the group owner's one line from today's brief ("3 done · 1 for you"); nothing when it has nothing to say.
170
+ // Addendum (Wawan 2026-11-18 12:32 SGT): it sits under the group's name, folded or open, and a press opens the unit's own chat.
171
+ const unitHtml = (g) => (g.unitLine ? `<button type="button" class="hv-unit" data-hm-unit="${esc(g.unitLine.key)}" aria-label="${esc(g.name)}: ${esc(g.unitLine.line)}. Open its chat"${g.unitLine.why ? ` title="${esc(g.unitLine.why)}"` : ''}>${esc(g.unitLine.line)}</button>` : '');
169
172
  function productHtml(g, o) {
170
173
  const open = o.pOpen(g);
171
174
  // open: the goal dots; folded: the tile's dot says something in it is yours (blue) or late (amber). No counts in words (HvAC)
@@ -175,8 +178,8 @@ function productHtml(g, o) {
175
178
  + `<span class="hv-tl t${g.tone}" aria-hidden="true" data-cz-rail-tile="${esc(g.key)}" data-cz-rail-name="${esc(g.name)}"${o.here === g.key ? ' data-cz-rail-here' : ''}>${esc(g.initials)}${open ? '' : nd(g)}</span><b>${esc(g.name)}</b></button>${prodPillHtml(g, o)}`
176
179
  + `<button type="button" class="hv-pf" data-hm-pg="${esc(g.key)}" aria-expanded="${open}" aria-label="${esc(say)}. ${open ? 'Close' : 'Open'} the group">${open ? dots(g) : ''}<span class="hv-cv">${svg(open ? P.chevD : P.chevR, 16)}</span></button>${prodPopHtml(g, o)}</div>`;
177
180
  const sec = `<section class="hm-pg hv-g" aria-label="${esc(g.name)}" data-po-id="${esc(prodKey(g.name))}">${SO.gripHtml(g.name)}`;
178
- if (!open) return `${sec}${head}</section>`;
179
- return `${sec}${head}<div class="hv-card">${productBody(g, o, true)}</div></section>`;
181
+ if (!open) return `${sec}${head}${unitHtml(g)}</section>`;
182
+ return `${sec}${head}${unitHtml(g)}<div class="hv-card">${productBody(g, o, true)}</div></section>`;
180
183
  }
181
184
  /** A fold line under a group (home-nav-rows-with-a-call): "N more" (· N running) opens the folded rows in place, "Fewer" folds them back. */
182
185
  function foldHtml(key, F) {
@@ -211,11 +214,11 @@ function programHtml(g, o) {
211
214
  + `<span class="hv-tl tp" aria-hidden="true" data-cz-rail-tile="${esc(g.key)}" data-cz-rail-name="${esc(g.name)}"${o.here === g.key ? ' data-cz-rail-here' : ''}>${svg(P.layers, 16)}${open ? '' : nd(g)}</span><b>${esc(g.name)}</b></button>${prodPillHtml(g, o)}${open && g.st ? sugHtml(g.program, g.st) : ''}`
212
215
  + `<button type="button" class="hv-pf" data-hm-pg="${esc(g.key)}" aria-expanded="${open}" aria-label="${esc(g.name)}. ${esc(line)}${g.yours ? '. ' + yoursWords(g) : ''}. ${open ? 'Close' : 'Open'} the group">${ms}<span class="hv-cv">${svg(open ? P.chevD : P.chevR, 16)}</span></button>${prodPopHtml(g, o)}</div>`;
213
216
  const sec = `<section class="hm-pg hv-g prg" aria-label="${esc(g.name)}" data-po-id="g:${esc(g.program.id)}">${SO.gripHtml(g.name)}`;
214
- if (!open) return `${sec}${head}</section>`;
217
+ if (!open) return `${sec}${head}${unitHtml(g)}</section>`;
215
218
  // the program's tasks are on its panel (On the program), not on Home: Home lists no tasks (Wawan, 2026-10-25)
216
219
  // a product's sub-heading only when the program's rows on Home come from two or more products (batch 12 item 6): one product repeated
217
220
  // under every program said nothing
218
- return `${sec}${head}<div class="hv-card">${programBody(g, o, true)}</div></section>`;
221
+ return `${sec}${head}${unitHtml(g)}<div class="hv-card">${programBody(g, o, true)}</div></section>`;
219
222
  }
220
223
  /** The next milestone in a program's header: its diamond and date, then one small diamond per initiative it waits on. */
221
224
  function msHtml(g) {
@@ -0,0 +1,147 @@
1
+ /* pm/phone-chat-head.js — the phone chat's top bar (batch 31 item 5, roomier-phone-chat; boards RcB, RcBfiles, RcBmenu).
2
+ *
3
+ * On a phone (max-width 760px) a conversation has three zones on one 16 px grid: the top bar, the stream and the box. The top bar is
4
+ * ← · the title over ONE context line · ⋯.
5
+ * The context line names what the chat is about: "<initiative> · N files · N PR". A kind with nothing is left out (zero is silence).
6
+ * In an initiative's own chat the title is its name, so the line starts "Initiative · <stage>".
7
+ * With no initiative, no files and no PR it says where the words go ("In: Everything", "To: Communicator"), because that chip
8
+ * left the box on a phone; a press opens the sheet.
9
+ * The sheet: the initiative (opens its page), its files (3 newest + "All N files"), its pull requests, and "Sends to" (what the
10
+ * box's In:/To: chip did).
11
+ * ⋯ opens the one nav menu (pm/cozy-nav.js openMenu) under the top bar, with "Waiting on you · N" and "Live now · N" on top; a
12
+ * row with zero is not drawn. A blue dot sits on ⋯ while something waits on you.
13
+ * Desktop never draws any of this (.hm-top is hidden there).
14
+ *
15
+ * ctxModel({ ini, files, prs, to, scope, title }) → { text, label, parts } | null PURE
16
+ * moreRows({ waiting, live }) → [{ key, label, dot }] PURE
17
+ * sheetHtml(m, esc) → string PURE
18
+ * newestFiles(rows, n) → rows PURE
19
+ * mountPhoneHead(host) → { draw() }
20
+ * host: { esc, phone(), target(), facts(t) → { ini: { id, title, sub } | null, files, prs } | null, openIni(id), openFile(f),
21
+ * allFiles(id), sendsTo(anchor, t), waiting() → { n, go }, openMenu(o) }
22
+ */
23
+ const SV = (d, w = 18) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">${d}</svg>`;
24
+ export const IC = {
25
+ ini: '<path d="M5 21V4M5 4h12l-2 4 2 4H5"/>',
26
+ file: '<path d="M7 3h7l5 5v13H7zM14 3v5h5"/>',
27
+ pr: '<circle cx="6" cy="6" r="2.2"/><circle cx="6" cy="18" r="2.2"/><circle cx="18" cy="18" r="2.2"/><path d="M6 8.2v7.6M18 15.8V10a3 3 0 0 0-3-3h-3"/>',
28
+ send: '<path d="M4 12l16-8-6 16-2-7z"/>',
29
+ wait: '<path d="M4 5h16v11H9l-5 4z"/>',
30
+ live: '<circle cx="12" cy="12" r="3"/><path d="M6 6a8.5 8.5 0 0 0 0 12M18 6a8.5 8.5 0 0 1 0 12"/>',
31
+ chev: '<path d="M9 6l6 6-6 6"/>',
32
+ down: '<path d="M7 10l5 5 5-5"/>',
33
+ more: '<circle cx="5" cy="12" r="1.2"/><circle cx="12" cy="12" r="1.2"/><circle cx="19" cy="12" r="1.2"/>',
34
+ };
35
+ /* the ⋯ rows' icons as path data (pm/cozy-evui.js svg draws the menu's own) */
36
+ const MENU_IC = { wait: 'M4 5h16v11H9l-5 4z', live: 'M12 9a3 3 0 1 0 0 6a3 3 0 1 0 0-6M6 6a8.5 8.5 0 0 0 0 12M18 6a8.5 8.5 0 0 1 0 12' };
37
+ const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
38
+
39
+ /** The 3 (n) newest files: the newest `at` first; a file with no time keeps its place after the dated ones. */
40
+ export function newestFiles(rows, n = 3) {
41
+ const list = (rows || []).filter((f) => f && f.path).map((f, i) => ({ f, i, t: Date.parse(f.at || '') || 0 }));
42
+ list.sort((a, b) => (b.t - a.t) || (a.i - b.i));
43
+ return list.slice(0, n).map((x) => x.f);
44
+ }
45
+
46
+ /** The context line and its sheet's facts. null: nothing to say (no initiative, no file, no PR and nowhere to send). */
47
+ export function ctxModel({ ini = null, files = [], prs = [], to = null, scope = null, title = '' } = {}) {
48
+ const fs = (files || []).filter((f) => f && f.path), ps = (prs || []).filter((p) => p && p.ref);
49
+ const parts = [];
50
+ // an initiative's own chat has its name as the title already (say it once): the line says what it is and its stage instead
51
+ if (ini && ini.title) parts.push(ini.title !== title ? ini.title : ['Initiative', ini.sub].filter(Boolean).join(' · '));
52
+ if (fs.length) parts.push(plural(fs.length, 'file', 'files'));
53
+ if (ps.length) parts.push(ps.length + ' PR');
54
+ const sends = to && to.name ? { text: 'To: ' + to.name, kind: 'to' } : scope && scope.text ? { text: 'In: ' + scope.text, kind: 'scope' } : null;
55
+ if (!parts.length && !sends) return null;
56
+ const text = parts.length ? parts.join(' · ') : sends.text;
57
+ const label = (parts.length ? 'About this chat: ' + parts.join(', ') : 'Where your messages go: ' + sends.text.replace(/^(In|To): /, '')) + '. Show';
58
+ return { text, label, parts, ini: ini && ini.title ? ini : null, files: fs, newest: newestFiles(fs, 3), prs: ps, sends };
59
+ }
60
+
61
+ /** The rows ⋯ adds on top of the nav menu; a row with zero is not drawn. */
62
+ export function moreRows({ waiting = 0, live = 0 } = {}) {
63
+ const out = [];
64
+ if (waiting > 0) out.push({ key: 'wait', label: 'Waiting on you · ' + waiting, icon: MENU_IC.wait, dot: true });
65
+ if (live > 0) out.push({ key: 'live', label: 'Live now · ' + live, icon: MENU_IC.live, dot: false });
66
+ return out;
67
+ }
68
+
69
+ const prName = (p) => { const m = /\/pull\/(\d+)/.exec(p.ref) || /^pr:#?(\d+)$/i.exec(p.ref); return (m ? 'Pull request #' + m[1] : 'Pull request') + (p.item ? ' · ' + p.item : ''); };
70
+ const isUrl = (s) => /^https?:\/\//.test(String(s || ''));
71
+
72
+ /** The sheet the context line opens. Every row is a button or a link with one job. */
73
+ export function sheetHtml(m, esc) {
74
+ if (!m) return '';
75
+ const row = (attrs, ic, title, sub, end) => `<button type="button" class="hm-csr" ${attrs}><span class="ic">${SV(ic)}</span><span class="t"><b>${esc(title)}</b>${sub ? `<small>${esc(sub)}</small>` : ''}</span>${end || ''}</button>`;
76
+ const chev = SV(IC.chev, 14);
77
+ const parts = [];
78
+ if (m.ini) parts.push(row(`data-cs-ini="${esc(m.ini.id)}"`, IC.ini, m.ini.title, ['Initiative', m.ini.sub].filter(Boolean).join(' · '), chev));
79
+ if (m.files.length) {
80
+ parts.push(`<p class="hm-csl">${esc(plural(m.files.length, 'file', 'files'))}</p>`
81
+ + m.newest.map((f) => row(`data-cs-file="${esc(f.path)}" data-cs-name="${esc(f.title || f.name || '')}"`, IC.file, f.title || f.name || f.path.split('/').pop(), f.state || '', f.when ? `<em>${esc(f.when)}</em>` : '')).join('')
82
+ + (m.files.length > m.newest.length && m.ini ? row(`data-cs-all="${esc(m.ini.id)}"`, IC.file, 'All ' + m.files.length + ' files', '', chev) : ''));
83
+ }
84
+ if (m.prs.length) {
85
+ parts.push(`<p class="hm-csl">${esc(plural(m.prs.length, 'pull request', 'pull requests'))}</p>`
86
+ + m.prs.map((p) => (isUrl(p.ref)
87
+ ? `<a class="hm-csr" href="${esc(p.ref)}" target="_blank" rel="noopener"><span class="ic">${SV(IC.pr)}</span><span class="t"><b>${esc(prName(p))}</b><small>${esc(p.state)}</small></span>${chev}</a>`
88
+ : `<div class="hm-csr"><span class="ic">${SV(IC.pr)}</span><span class="t"><b>${esc(prName(p))}</b><small>${esc(p.state)}</small></span></div>`)).join(''));
89
+ }
90
+ if (m.sends) parts.push(row('data-cs-sends', IC.send, 'Sends to', m.sends.text.replace(/^(In|To): /, ''), chev));
91
+ return '<div class="hm-csg" aria-hidden="true"></div>' + parts.join('<div class="hm-css" role="separator"></div>');
92
+ }
93
+
94
+ export function mountPhoneHead(host) {
95
+ const esc = host.esc;
96
+ const top = document.getElementById('hmTop'); if (!top) return { draw() {} };
97
+ const tt = top.querySelector('.hm-top-t');
98
+ tt.insertAdjacentHTML('beforeend', `<button type="button" class="hm-ctx" id="hmCtx" aria-haspopup="dialog" aria-expanded="false" aria-label="About this chat. Show" hidden><em></em>${SV(IC.down, 14)}</button>`);
99
+ top.insertAdjacentHTML('beforeend', `<button type="button" class="hm-ell" id="hmEll" aria-haspopup="menu" aria-expanded="false" aria-label="Menu" title="Menu">${SV(IC.more, 20)}<i aria-hidden="true" hidden></i></button>`);
100
+ document.body.insertAdjacentHTML('beforeend', '<div class="hm-csc" id="hmCsScrim" hidden></div><div class="hm-cs" id="hmCs" role="dialog" aria-label="About this chat" hidden></div>');
101
+ const ctx = top.querySelector('#hmCtx'), ell = top.querySelector('#hmEll'), dot = ell.querySelector('i'), sh = document.getElementById('hmCs'), scrim = document.getElementById('hmCsScrim');
102
+ const H = { m: null, live: 0, t: null };
103
+ document.addEventListener('cz:live-n', (e) => { H.live = (e.detail && e.detail.n) || 0; });
104
+
105
+ function draw() {
106
+ const t = host.phone() ? host.target() : null;
107
+ H.t = t;
108
+ const f = t ? host.facts(t) : null;
109
+ const m = t ? ctxModel({ ini: f && f.ini, files: f ? f.files : [], prs: f ? f.prs : [], to: t.to, scope: t.scope, title: t.title }) : null;
110
+ H.m = m;
111
+ ctx.hidden = !m;
112
+ if (m) {
113
+ const em = ctx.querySelector('em'); if (em.textContent !== m.text) em.textContent = m.text;
114
+ ctx.setAttribute('aria-label', m.label);
115
+ }
116
+ if (!sh.hidden) { if (m) sh.innerHTML = sheetHtml(m, esc); else open(false); }
117
+ const w = host.waiting();
118
+ dot.hidden = !(w && w.n > 0);
119
+ ell.setAttribute('aria-label', w && w.n > 0 ? 'Menu. ' + (w.n === 1 ? 'One thing waits' : w.n + ' things wait') + ' on you' : 'Menu');
120
+ }
121
+ function open(on) {
122
+ on = !!on && !!H.m;
123
+ sh.hidden = !on; scrim.hidden = !on; ctx.setAttribute('aria-expanded', String(on));
124
+ document.body.classList.toggle('hm-cs-on', on);
125
+ if (on) { sh.innerHTML = sheetHtml(H.m, esc); sh.setAttribute('data-esc-layer', ''); const b = sh.querySelector('button, a'); if (b) b.focus(); }
126
+ else { sh.removeAttribute('data-esc-layer'); if (sh.contains(document.activeElement)) ctx.focus(); }
127
+ }
128
+ ctx.onclick = () => open(sh.hidden);
129
+ scrim.onclick = () => open(false);
130
+ document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !sh.hidden) { e.stopPropagation(); open(false); ctx.focus(); } }, true);
131
+ sh.onclick = (e) => {
132
+ const b = e.target.closest('[data-cs-ini], [data-cs-file], [data-cs-all], [data-cs-sends], a'); if (!b) return;
133
+ const t = H.t, d = b.dataset;
134
+ open(false);
135
+ if (b.tagName === 'A') return; // a pull request opens on GitHub in a new tab
136
+ if (d.csIni) host.openIni(d.csIni);
137
+ else if (d.csFile) host.openFile({ path: d.csFile, name: d.csName || '' });
138
+ else if (d.csAll) host.allFiles(d.csAll);
139
+ else if ('csSends' in d) host.sendsTo(ctx, t);
140
+ };
141
+ ell.onclick = () => {
142
+ const w = host.waiting() || { n: 0 };
143
+ const rows = moreRows({ waiting: w.n, live: H.live }).map((r) => ({ ...r, go: r.key === 'wait' ? () => w.go && w.go() : () => document.dispatchEvent(new CustomEvent('cz:live-open')) }));
144
+ host.openMenu({ anchor: ell, rows });
145
+ };
146
+ return { draw, close: () => open(false) };
147
+ }
@@ -3081,6 +3081,21 @@ const teamRuns = require('./lib/team-runs.js').create({
3081
3081
  warn: (what, e) => warnWriteFail(what, e),
3082
3082
  });
3083
3083
  const teamTick = () => { try { teamRuns.tick({}); } catch (e) { warnWriteFail('team tick', e); } };
3084
+ // chief-unit-owners ✦1 ✦2 (Wawan 2026-11-18 "Build now", doc GCFCo233wHawPk7Ypjba4J): every initiative has ONE owner unit, derived (its program,
3085
+ // else its product, or project work), and each unit's owner is a record with a daily tick that writes one brief (lib/unit-owner.js). No new
3086
+ // session and no model call: the tick folds the workers' ledgers. lib/units.js stamp() puts the unit on every new team, driver and goal-loop line.
3087
+ const unitsHost = require('./lib/units-host.js').create({
3088
+ workspaces: () => [...workspaces.values()],
3089
+ stateDirFor: (w) => (isPlanNeedsTree(w) ? stateDirFor(w) : null),
3090
+ homeDir: () => { const h = homeWorkspace(); return h && isPlanNeedsTree(h) ? stateDirFor(h, { create: true }) : null; },
3091
+ programs: () => require('./lib/routes-programs.js').all(msReviewCtx()),
3092
+ rowsOf: (w) => { if (!isPlanNeedsTree(w)) return []; const r = require('./lib/routes-boards.js').baseRows(w); return r && r.pending ? null : r && r.ok ? r.rows : []; }, // null: still being read
3093
+ runtimeDir: STATE,
3094
+ memoryRoot: () => { const h = homeWorkspace(); return h ? h.root : null; },
3095
+ promote: (unit) => require('./lib/unit-memory.js').promote(unitsHost, unit),
3096
+ });
3097
+ require('./lib/units.js').setResolver((x) => unitsHost.resolve(x));
3098
+ const ownerTick = () => { try { unitsHost.tick({}); } catch (e) { warnWriteFail('unit owner tick', e); } };
3084
3099
  // batch 15 item 1 (canvas Iq8Suggest and Iq9Draft): Claude drafts metrics without being asked (lib/metric-draft-runs.js): a product with no North
3085
3100
  // Star, a program charter with no goal, an initiative that gets a PRD with no success metric, and next quarter's key results. The run's only
3086
3101
  // write is `pmos metrics draft`; the PM's ✓ keep writes the kr-metrics record. At most 2 at once, once per scope. PMOS_METRIC_DRAFT=off.
@@ -3396,6 +3411,7 @@ bgQueue.register('forecast', () => forecastTick());
3396
3411
  bgQueue.register('report-design', () => reportDesignTick());
3397
3412
  bgQueue.register('report-structure', () => reportStructureTick());
3398
3413
  bgQueue.register('team', () => teamTick());
3414
+ bgQueue.register('owner', () => ownerTick()); // chief-unit-owners ✦2: one brief a day per unit (lib/unit-owner.js)
3399
3415
  bgQueue.register('scan', (turn) => gated('scan', () => scanTick(turn))());
3400
3416
  // idle lab build E (lib/idle-lab-engine.js): while the PM is away Claude prototypes and scans for the initiatives, proves each result (a
3401
3417
  // specimen renders in a headless browser; every claim quotes what was read, through lib/ai-guard.js) and files it under the ✦. Step 5 of the
@@ -4714,6 +4730,13 @@ function learnConnectorTools(env, tools) {
4714
4730
  } catch (e) { warnWriteFail('connector tools', e); }
4715
4731
  }
4716
4732
 
4733
+ /** The memory scopes a run reads (lib/units.js): its initiative and the unit that owns it; none for a run on no initiative. */
4734
+ function memoryScopeOf(base) {
4735
+ const ini = base && base.initiative ? String(base.initiative) : null;
4736
+ if (!ini) return {};
4737
+ const u = require('./lib/units.js').resolve({ ws: base.ws, ini });
4738
+ return { ini, unit: u ? require('./lib/units.js').keyOf(u) : null };
4739
+ }
4717
4740
  function startHeadless(base, workdir, kind, launchArgs, env, initialInput, addDirs, onDone, writePaths) {
4718
4741
  const prompt = safeFirstInput(String(initialInput).replace(/\r+$/, ''));
4719
4742
  // report-design-studio: writePaths names the one render file a report-design run may write; for a skill run, the folders it may write in (lib/headless.js ignores it for every other kind).
@@ -4725,7 +4748,8 @@ function startHeadless(base, workdir, kind, launchArgs, env, initialInput, addDi
4725
4748
  budgetUsd: !env ? null : kind === 'grill' ? env.PMOS_GRILL_BUDGET : kind === 'lab-proto' || kind === 'lab-scan' ? env.PMOS_LAB_BUDGET : null,
4726
4749
  connectorTools: headlessLib.CONNECTOR_READ_KINDS.includes(kind) ? knownConnectorTools(env) : [],
4727
4750
  team: kind === 'team' && env ? { role: env.PMOS_TEAM_ROLE, mode: env.PMOS_TEAM_MODE } : null,
4728
- memory: headlessLib.memoryNote([workdir, ...(Array.isArray(addDirs) ? addDirs : [])], env) });
4751
+ // chief-unit-owners ✦4: a run on an initiative reads the workspace scope, its unit's lessons and its own, never another unit's
4752
+ memory: headlessLib.memoryNote([workdir, ...(Array.isArray(addDirs) ? addDirs : [])], env, memoryScopeOf(base)) });
4729
4753
  const s = { ...base, cwd: workdir, state: 'working', pty: null, tmux: null, headless: kind, child: null, ...(lean ? { lean: true } : {}),
4730
4754
  note: '', buf: '', cols: 80, rows: 24, clients: new Set(), created: nowISO(), lastOutputAt: Date.now() };
4731
4755
  const say = (text) => {
@@ -10920,6 +10944,7 @@ async function handleRequest(req, res) {
10920
10944
  runtimeDir: STATE, claudeSetup, registerWorkspace, pickFolder, broadcast, workspaceList: () => [...workspaces.values()], homeRoot: HOME_ENABLED ? SELF_ROOT : null, spawnSession, jevModelOpts, sendToSession, endSupersededRuns, proSettings,
10921
10945
  // premium-chat-session: every premium chat panel is an interactive Claude Code session the PM talks to (text as typed, `/` kept)
10922
10946
  chatSessions,
10947
+ unitsHost, // chief-unit-owners: GET /api/units, the chief's `pmos owner brief`, Home's group lines (lib/routes-units.js)
10923
10948
  // batch 20 item 13: "grill this" in an initiative's chat starts Claude's grill run at once (lib/grill-runs.js start, why 'ask')
10924
10949
  grillStart: (o) => grillRuns.start(o),
10925
10950
  // report-workspace: the schedule store a recurring report registers its draft-only schedule in, a skill's body, and the stop of a headless run
@@ -9,6 +9,7 @@
9
9
  ],
10
10
  "modules": [
11
11
  "find-browser.test.js",
12
+ "units.test.js",
12
13
  "program-worktree.test.js",
13
14
  "program-deleted.test.js",
14
15
  "own-profile.test.js",
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Initiative roomier-phone-chat (feedback batch 31 item 5; boards RcB, RcBfiles, RcBmenu): the phone chat's top bar. roomier-phone-chat.test.js is pure: pm/phone-chat-head.js, pm/cozy-nav.js menuHtml extra rows and lib/routes-initiative-premium.js prsOf.",
3
+ "modules": [
4
+ "roomier-phone-chat.test.js"
5
+ ],
6
+ "seconds": {
7
+ "roomier-phone-chat.test.js": 1
8
+ }
9
+ }