create-pmos 0.599.0 → 0.601.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 (35) hide show
  1. package/package.json +33 -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/state/discoveries.md +1 -1
  6. package/workspace/changelog.json +32 -0
  7. package/workspace/guide/layout.md +10 -3
  8. package/workspace/guide/settings-and-switches.md +24 -0
  9. package/workspace/lib/bg-queue.js +1 -0
  10. package/workspace/lib/event-relay.js +202 -0
  11. package/workspace/lib/initiative-premium.js +2 -2
  12. package/workspace/lib/job-graph.js +1 -0
  13. package/workspace/lib/refresh-run.js +171 -30
  14. package/workspace/lib/refresh.js +107 -20
  15. package/workspace/lib/route-modules.js +1 -0
  16. package/workspace/lib/routes-initiative-premium.js +11 -1
  17. package/workspace/lib/routes-refresh.js +12 -4
  18. package/workspace/lib/routes-relay.js +29 -0
  19. package/workspace/package-lock.json +2 -2
  20. package/workspace/package.json +1 -1
  21. package/workspace/public/pm/cozy-ev.css +9 -0
  22. package/workspace/public/pm/cozy-evmodel.js +14 -0
  23. package/workspace/public/pm/cozy-home.css +76 -0
  24. package/workspace/public/pm/cozy-live-pill.js +4 -0
  25. package/workspace/public/pm/cozy-nav.js +26 -6
  26. package/workspace/public/pm/cozy-relay.js +80 -0
  27. package/workspace/public/pm/cozy-schedwork.js +52 -19
  28. package/workspace/public/pm/cozy-settings.js +11 -3
  29. package/workspace/public/pm/home-app.js +47 -1
  30. package/workspace/public/pm/home-chat.js +17 -2
  31. package/workspace/public/pm/phone-chat-head.js +147 -0
  32. package/workspace/server.js +15 -6
  33. package/workspace/skills/sources-read.skill +1 -1
  34. package/workspace/test-lists/event-relay.json +9 -0
  35. package/workspace/test-lists/roomier-phone-chat.json +9 -0
@@ -6,6 +6,9 @@
6
6
  * often and when it runs next. One quiet entry under the sources opens it (swEntry).
7
7
  * job:<id> one source or job (lib/refresh.js id), like the scheduled task page of the Claude app: Active, Next run, Repeats,
8
8
  * Working hours only, PMOS's ✦ rhythm proposal (✓ saves it, ✕ hides it for today), History and ▶ Read now.
9
+ * job:tools.<svc> one service of Your tools (batch 31 item 6, agreed design StA): its own rhythm or that of Your tools, Next run,
10
+ * History and ▶ Read now. A read that is stuck says why and how to fix it, with ↗ Open the session and ■ Stop and read again
11
+ * (POST /api/refresh/stop { id }). The list shows one row per service in place of Your tools.
9
12
  * task:<id> one of your scheduled tasks (schedules.json): Active, Next run, Repeats (Every hour is new), last run and ▶ Run now.
10
13
  * Reads GET /api/refresh?ws= (lib/routes-refresh.js: rows with next_at, missed_at, propose, runs) and GET /api/schedules?all=1. Writes are
11
14
  * the PM's presses: POST /api/refresh/source { id, on | schedule }, /api/refresh/run { id, ws }, /api/schedules/update, /api/schedules/run.
@@ -15,6 +18,7 @@ import { pmGet, pmPost } from './http.js';
15
18
  import { esc, svg, ICON, toast, wsParam } from './cozy-evui.js';
16
19
  import { nextOf, atOf, everyLine } from './cozy-evmodel.js';
17
20
 
21
+ const OPEN = 'M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5', STOP = 'M7 7h10v10H7z';
18
22
  const CHEV = 'M10 7l5 5-5 5', BACK = 'M15 18l-6-6 6-6', PLAY = 'M8 5l11 7-11 7z', SPARK = 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z', CLOCK = 'M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18M12 7v5l3 2';
19
23
  const S = { rows: null, win: null, tasks: null, err: '', busy: false, from: '', undo: null };
20
24
  const store = { get(k) { try { return localStorage.getItem(k); } catch { return null; } }, set(k, v) { try { localStorage.setItem(k, v); } catch { /* no storage */ } } };
@@ -29,6 +33,7 @@ const kv = (icon, k, v) => `<div class="ev-trow ev-sw-kv"><span class="ev-sw-ic"
29
33
  export function swLine(r, now = Date.now()) {
30
34
  if (!r) return { text: '', missed: false };
31
35
  if (!r.on) return { text: 'Off', missed: false };
36
+ if (r.stall) return { text: 'Stuck since ' + atOf(r.stall.since, now) + ' · ' + r.stall.why.replace(/^./, (c) => c.toLowerCase()), missed: true };
32
37
  if (r.missed_at) return { text: 'Missed ' + atOf(r.missed_at, now) + (r.last && r.last.at ? ' · read ' + atOf(r.last.at, now) : ' · never read'), missed: true };
33
38
  if (r.state === 'running') return { text: 'Running now', missed: false };
34
39
  const nx = r.next_at ? nextOf(r.next_at, now) : '';
@@ -42,9 +47,12 @@ export function repeatOpts(r) {
42
47
  const s = r && r.schedule; if (!s) return [];
43
48
  const cur = s.kind === 'every' ? 'every:' + s.every : s.kind;
44
49
  const out = [];
45
- if ((r.kinds || []).includes('manual')) out.push(['manual', 'Only when you press read', cur === 'manual']);
46
- for (const v of r.every || []) out.push(['every:' + v, EVERY_WORD[v] || 'Every ' + v + ' min', cur === 'every:' + v]);
47
- if ((r.kinds || []).includes('daily')) for (const [k, l] of [['daily', 'Every day'], ['weekdays', 'Working days'], ['weekly', 'Once a week']]) out.push([k, l, cur === k]);
50
+ // a service of Your tools can follow the rhythm of Your tools (batch 31 item 6)
51
+ if (r.svc) out.push(['same', 'Same as Your tools (' + everyLine(r.parent_text || '').replace(/^Every/, 'every').replace(/^Only/, 'only') + ')', !r.own]);
52
+ const pick = (v) => !r.svc || r.own ? cur === v : false;
53
+ if ((r.kinds || []).includes('manual')) out.push(['manual', 'Only when you press read', pick('manual')]);
54
+ for (const v of r.every || []) out.push(['every:' + v, EVERY_WORD[v] || 'Every ' + v + ' min', pick('every:' + v)]);
55
+ if ((r.kinds || []).includes('daily')) for (const [k, l] of [['daily', 'Every day'], ['weekdays', 'Working days'], ['weekly', 'Once a week']]) out.push([k, l, pick(k)]);
48
56
  return out;
49
57
  }
50
58
  const TASK_CAD = [['hourly', 'Every hour'], ['daily', 'Every day'], ['weekly', 'Every week'], ['bi-weekly', 'Every 2 weeks'], ['monthly', 'Every month']];
@@ -71,6 +79,22 @@ export async function swLoad(draw) {
71
79
  }
72
80
  export const swReset = () => { S.rows = null; S.tasks = null; S.err = ''; S.from = ''; };
73
81
  const shown = () => (S.rows || []).filter((r) => r.run !== 'change');
82
+ /**
83
+ * A service of Your tools as a row of its own (batch 31 item 6): 'tools.slack' → { id, svc, parent, label, schedule, own, next_at, missed_at,
84
+ * state, last, runs (the runs that read it), stall (when the stuck run reads it) }, with the kinds and choices of Your tools. Pure.
85
+ */
86
+ export function svcOf(rows, id) {
87
+ const m = /^([a-z]+)\.([a-z]+)$/.exec(String(id || '')); if (!m) return null;
88
+ const p = (rows || []).find((r) => r.id === m[1]); const v = p && (p.svcs || []).find((x) => x.id === m[2]);
89
+ if (!v) return null;
90
+ const reads = (x) => !Array.isArray(x.svcs) || x.svcs.includes(v.id);
91
+ const stall = p.stall && v.reading && (!p.stall.svcs || p.stall.svcs.includes(v.id)) ? p.stall : null;
92
+ return { id, svc: v.id, parent: p.id, label: v.label, run: 'skill', on: p.on, own: v.own, schedule: v.schedule, schedule_text: v.schedule_text, parent_text: p.schedule_text,
93
+ kinds: p.kinds, every: p.every, next_at: v.next_at, missed_at: v.missed_at, state: v.reading ? 'running' : p.state === 'off' ? 'off' : 'recent',
94
+ last: v.last ? { at: v.last.at, state: v.last.state, why: v.last.why } : null, runs: (p.runs || []).filter(reads).slice(0, 5), ...(stall ? { stall } : {}),
95
+ what: 'PMOS reads ' + v.label + ' for the Briefing. ' + (v.own ? 'It has a rhythm of its own.' : 'It follows the rhythm of Your tools.') + ' Services due at the same minute share one session.' };
96
+ }
97
+ const rowOf = (id) => (S.rows || []).find((r) => r.id === id) || svcOf(S.rows, id);
74
98
  /** The quiet entry under the sources: "Scheduled work · 9 jobs". */
75
99
  export function swEntry() {
76
100
  const n = S.rows ? shown().filter((r) => r.on).length + (S.tasks || []).filter((x) => x.enabled !== false).length : null;
@@ -86,17 +110,20 @@ function listHtml(now) {
86
110
  const tasks = (S.tasks || []).map((s) => `<div class="ev-trow ev-fr"><span class="ev-gut"></span><div class="ev-tx ev-grow"><span>${esc(s.name || s.skill)}</span><p class="ev-small ev-mut">${esc(taskLine(s, now))}</p></div>${ib(`data-ev-sw="task:${esc(s.id)}"`, 'Open ' + (s.name || s.skill), CHEV)}</div>`);
87
111
  return head('Scheduled work', '', 'Back to Connectors')
88
112
  + (S.err ? `<p class="ev-small ev-mut">${esc(S.err)}</p>` : '')
89
- + grp('PMOS reads', rows.filter((r) => r.run === 'skill').map(row))
113
+ + grp('PMOS reads', rows.filter((r) => r.run === 'skill').flatMap((r) => (r.svcs && r.svcs.length ? r.svcs.map((v) => row(svcOf(S.rows, r.id + '.' + v.id))) : [row(r)])))
90
114
  + grp('PMOS’s own jobs', rows.filter((r) => r.run === 'job').map(row))
91
115
  + grp('Your scheduled tasks', tasks)
92
116
  + (S.tasks && !S.tasks.length ? '<p class="ev-small ev-mut">You have no scheduled tasks of your own.</p>' : '');
93
117
  }
94
118
  const RESULT = { done: 'done', failed: 'failed', skipped: 'skipped', interrupted: 'stopped', running: 'running' };
95
119
  function jobHtml(r, now) {
96
- const back = S.from === 'list' ? 'list' : '', backLabel = S.from === 'list' ? 'Back to Scheduled work' : 'Back to Connectors';
120
+ const back = S.from === 'list' ? 'list' : /^job:/.test(S.from) ? S.from : '', backLabel = S.from === 'list' ? 'Back to Scheduled work' : /^job:/.test(S.from) ? 'Back to Your tools' : 'Back to Connectors';
97
121
  if (!r) return head('Scheduled work', back, backLabel) + '<p class="ev-small ev-mut">This job could not be read.</p>';
98
122
  const s = r.schedule, skip = r.missed_at ? (r.runs || []).find((x) => x.result === 'skipped' && Date.parse(x.start_at) >= Date.parse(r.missed_at)) : null;
99
- const warn = r.missed_at ? `<div class="ev-warn ev-line ev-sw-warn"><i class="ev-dot risk" aria-hidden="true"></i><p class="ev-grow">${esc((r.last && r.last.at ? 'Last read ' + at(r.last.at, now) + '. ' : 'Never read. ') + 'PMOS missed ' + atOf(r.missed_at, now) + (skip && skip.note ? ': ' + skip.note + '.' : ', because PMOS was not running then or your computer slept.'))}</p></div>` : '';
123
+ const stuck = r.stall ? `<div class="ev-warn ev-line ev-sw-warn ev-sw-stall"><i class="ev-dot risk" aria-hidden="true"></i><div class="ev-grow"><p><b>${esc(r.stall.why)}.</b> It started ${esc(at(r.stall.since, now))}.</p><p class="ev-small">${esc(r.stall.fix)}</p>${r.stall.doing ? `<p class="ev-small ev-mut">Last: ${esc(r.stall.doing)}</p>` : ''}</div>`
124
+ + `<a class="ev-ib" href="/premium.html?session=${encodeURIComponent(r.stall.session)}" aria-label="Open the session" title="Open the session">${svg(OPEN, 18)}</a>`
125
+ + ib(`data-ev-sw-stop="${esc(r.parent || r.id)}"`, 'Stop and read again', STOP) + '</div>' : '';
126
+ const warn = r.stall ? stuck : r.missed_at ? `<div class="ev-warn ev-line ev-sw-warn"><i class="ev-dot risk" aria-hidden="true"></i><p class="ev-grow">${esc((r.last && r.last.at ? 'Last read ' + at(r.last.at, now) + '. ' : 'Never read. ') + 'PMOS missed ' + atOf(r.missed_at, now) + (skip && skip.note ? ': ' + skip.note + '.' : ', because PMOS was not running then or your computer slept.'))}</p></div>` : '';
100
127
  const opts = repeatOpts(r);
101
128
  const rep = opts.length ? `<label class="ev-vh" for="evSwRep">Repeats</label><select id="evSwRep" class="ev-inp" data-ev-sw-rep="${esc(r.id)}"${S.busy ? ' disabled' : ''}>${opts.map(([v, l, on]) => `<option value="${esc(v)}"${on ? ' selected' : ''}>${esc(l)}</option>`).join('')}</select>`
102
129
  : `<span class="ev-small ev-mut">${esc(everyLine(r.schedule_text) || 'Not set here')}</span>`;
@@ -104,18 +131,19 @@ function jobHtml(r, now) {
104
131
  const times = s && ['daily', 'weekdays', 'weekly'].includes(s.kind) ? kv(CLOCK, 'At', `<label class="ev-vh" for="evSwAt">At</label><input id="evSwAt" class="ev-inp ev-sw-at" type="time" value="${esc((s.times || ['09:00'])[0])}" data-ev-sw-at="${esc(r.id)}">`)
105
132
  + (s.kind === 'weekly' ? kv(ICON.cal, 'On', `<label class="ev-vh" for="evSwDay">On</label><select id="evSwDay" class="ev-inp" data-ev-sw-day="${esc(r.id)}">${DAYS.map((d) => `<option value="${d}"${s.day === d ? ' selected' : ''}>${esc(DAYN[d])}</option>`).join('')}</select>`) : '')
106
133
  + ((s.times || []).length > 1 ? `<p class="ev-small ev-mut ev-sw-more">Also at ${esc(s.times.slice(1).join(' and '))}.</p>` : '') : '';
107
- const work = s && s.kind === 'every' && r.run === 'skill' ? kv(CLOCK, 'Working hours only' + (S.win ? ' (' + S.win.start + ' to ' + S.win.end + ')' : ''), swc(s.work, `data-ev-sw-work="${esc(r.id)}"`, 'Working hours only')) : '';
108
- const nx = !r.on ? 'Off' : r.missed_at ? 'Now, when you press ▶' : r.state === 'running' ? 'Running now' : r.next_at ? nextOf(r.next_at, now) : r.run === 'skill' ? 'Only when you press' : everyLine(r.schedule_text) || '—';
134
+ const work = s && s.kind === 'every' && r.run === 'skill' && (!r.svc || r.own) ? kv(CLOCK, 'Working hours only' + (S.win ? ' (' + S.win.start + ' to ' + S.win.end + ')' : ''), swc(s.work, `data-ev-sw-work="${esc(r.id)}"`, 'Working hours only')) : '';
135
+ const nx = !r.on ? 'Off' : r.stall ? 'When this one ends' : r.missed_at ? 'Now, when you press ▶' : r.state === 'running' ? 'Running now' : r.next_at ? nextOf(r.next_at, now) : r.run === 'skill' ? 'Only when you press' : everyLine(r.schedule_text) || '—';
109
136
  const p = r.propose && store.get(NOPE(r.id)) !== today() ? r.propose : null;
110
137
  const span = p && p.s.work && S.win ? ' from ' + S.win.start + ' to ' + S.win.end : '';
111
138
  const prop = p ? `<div class="ev-card ev-sw-prop"><span class="ev-av sp" aria-hidden="true">${svg(SPARK, 15)}</span><div class="ev-grow"><b>Read it more often on meeting days</b><p class="ev-small">Every ${esc(p.every)} min${esc(span)} on days with ${p.meetings} or more meetings. Today has ${p.today}. Other days stay at ${esc(EVERY_WORD[p.s.every] ? EVERY_WORD[p.s.every].replace(/^Every /, '') : p.s.every + ' min')}.</p></div>`
112
139
  + ib(`data-ev-sw-nope="${esc(r.id)}"`, 'Not now', ICON.close) + ib(`data-ev-sw-yes="${esc(r.id)}"`, 'Use this', ICON.check, 'ev-ib ev-jl-pri') + '</div>' : '';
113
- const runs = (r.runs || []).slice(0, 5).map((x) => `<div class="ev-sw-h"><span>${esc(at(x.start_at, now))}</span><span class="ev-mut">${esc([RESULT[x.result] || x.result || '', x.took_ms != null ? Math.max(1, Math.round(x.took_ms / 60000)) + ' min' : '', x.note || x.error || x.got || ''].filter(Boolean).join(' · '))}</span></div>`).join('');
140
+ const runs = (r.runs || []).slice(0, 5).map((x) => `<div class="ev-sw-h"><span>${esc(at(x.start_at, now))}</span><span class="ev-mut">${esc([RESULT[x.result || (x.end_at ? 'done' : 'running')] || x.result || '', x.took_ms != null ? Math.max(1, Math.round(x.took_ms / 60000)) + ' min' : '', x.note || x.error || x.got || ''].filter(Boolean).join(' · '))}</span></div>`).join('');
114
141
  const canRun = r.run === 'skill' || r.run === 'job';
115
142
  return head(r.label, back, backLabel) + `<p class="ev-small ev-mut ev-sw-what">${esc(r.what || '')}</p>` + warn
116
- + `<div class="ev-sw-card">${kv(CLOCK, 'Active', swc(r.on, `data-ev-sw-on="${esc(r.id)}"`, r.label + ': active'))}${kv(ICON.cal, 'Next run', `<span class="ev-small ev-mut">${esc(nx)}</span>`)}${kv(ICON.refresh, 'Repeats', rep)}${times}${work}</div>`
143
+ + `<div class="ev-sw-card">${r.svc ? '' : kv(CLOCK, 'Active', swc(r.on, `data-ev-sw-on="${esc(r.id)}"`, r.label + ': active'))}${kv(ICON.cal, 'Next run', `<span class="ev-small ev-mut">${esc(nx)}</span>`)}${kv(ICON.refresh, 'Repeats', rep)}${times}${work}</div>`
117
144
  + (S.undo && S.undo.id === r.id ? `<div class="ev-trow ev-sw-undo"><p class="ev-small ev-grow">Saved. PMOS reads it more often on meeting days.</p><button type="button" class="ev-btn sm" data-ev-sw-undo="${esc(r.id)}">Undo</button></div>` : '')
118
145
  + prop
146
+ + (r.svcs && r.svcs.length ? `<p class="ev-mlbl ev-sw-grp">Services</p>` + r.svcs.map((v) => { const x = svcOf(S.rows, r.id + '.' + v.id), l = swLine(x, now); return `<div class="ev-trow ev-fr"><span class="ev-gut">${l.missed ? '<i class="ev-dot risk" aria-hidden="true"></i>' : ''}</span><div class="ev-tx ev-grow"><span>${esc(x.label)}</span><p class="ev-small ${l.missed ? 'ev-late' : 'ev-mut'}">${esc(l.text)}</p></div>${ib(`data-ev-sw="job:${esc(x.id)}" data-ev-sw-from="job:${esc(r.id)}"`, 'Open ' + x.label, CHEV)}</div>`; }).join('') : '')
119
147
  + `<p class="ev-mlbl ev-sw-grp">History</p>` + (runs ? `<div class="ev-sw-hist">${runs}</div>` : '<p class="ev-small ev-mut">No runs yet.</p>')
120
148
  + (canRun ? `<div class="ev-sw-run">${ib(`data-ev-sw-run="${esc(r.id)}"`, r.run === 'skill' ? 'Read now' : 'Run now', PLAY, 'ev-ib ev-sw-play')}</div>` : '');
121
149
  }
@@ -135,7 +163,7 @@ export function swBody(sub) {
135
163
  const k = String(sub || '').slice(3), now = Date.now();
136
164
  if (S.rows === null) return head('Scheduled work', k === 'list' ? '' : 'list', 'Back') + '<p class="ev-small ev-mut">Reading the schedules.</p>';
137
165
  if (k === 'list') return listHtml(now);
138
- if (k.startsWith('job:')) return jobHtml(S.rows.find((r) => r.id === k.slice(4)), now);
166
+ if (k.startsWith('job:')) return jobHtml(rowOf(k.slice(4)), now);
139
167
  if (k.startsWith('task:')) return taskHtml((S.tasks || []).find((x) => x.id === k.slice(5)), now);
140
168
  return '';
141
169
  }
@@ -152,14 +180,18 @@ export async function swPress(t, { go, say, draw, fresh }) {
152
180
  if (k && S.rows === null) swLoad(draw);
153
181
  return true;
154
182
  }
155
- const id = d.evSwOn || d.evSwWork || d.evSwYes || d.evSwNope || d.evSwRun || d.evSwTon || d.evSwTrun || d.evSwUndo;
183
+ const id = d.evSwOn || d.evSwWork || d.evSwYes || d.evSwNope || d.evSwRun || d.evSwTon || d.evSwTrun || d.evSwUndo || d.evSwStop;
156
184
  if (!id) return false;
157
185
  if (d.evSwNope) { store.set(NOPE(id), today()); say('Hidden for today. PMOS keeps the rhythm you have.'); draw(); return true; }
158
186
  if (S.busy) return true;
159
187
  S.busy = true;
160
188
  try {
161
- const r = (S.rows || []).find((x) => x.id === id);
162
- if (d.evSwOn && r) { const on = !r.on, x = await pmPost('/api/refresh/source', { id, on }); say(said(x, on ? r.label + ' is on.' : r.label + ' is off. PMOS does not run it on its own.')); }
189
+ const r = rowOf(id);
190
+ const ws = wsParam() || undefined;
191
+ if (d.evSwStop) { const x = await pmPost('/api/refresh/stop', { id, ws }); say(x && x.ok ? (x.again && x.again.ok ? 'Stopped. It reads again now.' : 'Stopped. It did not start again: ' + ((x.again && x.again.error) || 'the server did not answer') + '.') : 'Not stopped: ' + ((x && x.error) || 'the server did not answer') + '.'); if (x && x.ok) toast('Stopped. Reading again.'); }
192
+ else if (d.evSwWork && r && r.svc) { const x = await pmPost('/api/refresh/source', { id: r.parent, svc: r.svc, schedule: { ...r.schedule, work: !r.schedule.work } }); say(said(x, r.schedule.work ? 'Saved. ' + r.label + ' is read all day.' : 'Saved. ' + r.label + ' is read in working hours only.')); }
193
+ else if (d.evSwRun && r && r.svc) { const x = await pmPost('/api/refresh/run', { id: r.parent, svcs: [r.svc], ws }); say(x && x.ok ? 'Started. PMOS reads ' + r.label + ' now.' : 'It did not start: ' + ((x && x.error) || 'the server did not answer') + '.'); if (x && x.ok) toast('Started.'); }
194
+ else if (d.evSwOn && r) { const on = !r.on, x = await pmPost('/api/refresh/source', { id, on }); say(said(x, on ? r.label + ' is on.' : r.label + ' is off. PMOS does not run it on its own.')); }
163
195
  else if (d.evSwWork && r) { const x = await pmPost('/api/refresh/source', { id, schedule: { ...r.schedule, work: !r.schedule.work } }); say(said(x, r.schedule.work ? 'Saved. It runs all day.' : 'Saved. It runs in working hours only.')); }
164
196
  else if (d.evSwYes && r && r.propose) { const old = r.schedule, x = await pmPost('/api/refresh/source', { id, schedule: r.propose.s }); if (x && x.ok) S.undo = { id, s: old }; say(said(x, 'Saved. PMOS reads ' + r.label + ' every ' + r.propose.every + ' min on meeting days.')); }
165
197
  else if (d.evSwUndo && S.undo && S.undo.id === id) { const x = await pmPost('/api/refresh/source', { id, schedule: S.undo.s }); if (x && x.ok) S.undo = null; say(said(x, 'Undone. The rhythm is as it was.')); }
@@ -175,21 +207,22 @@ export async function swPress(t, { go, say, draw, fresh }) {
175
207
  export async function swChange(x, { say, draw, fresh }) {
176
208
  const id = x.dataset.evSwRep || x.dataset.evSwCad || x.dataset.evSwAt || x.dataset.evSwDay;
177
209
  if (!id) return false;
178
- if (S.busy) return true;
210
+ if (S.busy) { if (draw) draw(); return true; } // a change while another saves: the field shows what is saved, not what was dropped
179
211
  S.busy = true;
180
212
  try {
181
213
  if (x.dataset.evSwRep) {
182
- const r = (S.rows || []).find((y) => y.id === id); if (!r) return true;
214
+ const r = rowOf(id); if (!r) return true;
183
215
  const v = x.value, cur = r.schedule || {}, times = cur.times && cur.times.length ? cur.times : ['09:00'];
184
216
  let sch;
185
- if (x.dataset.evSwAt) { if (!/^\d\d:\d\d$/.test(v)) return true; sch = { ...cur, times: [v, ...times.slice(1).filter((y) => y !== v)] }; }
217
+ if (r.svc && v === 'same' && !x.dataset.evSwAt && !x.dataset.evSwDay) sch = null;
218
+ else if (x.dataset.evSwAt) { if (!/^\d\d:\d\d$/.test(v)) return true; sch = { ...cur, times: [v, ...times.slice(1).filter((y) => y !== v)] }; }
186
219
  else if (x.dataset.evSwDay) sch = { ...cur, day: v };
187
220
  else if (v === 'manual') sch = { kind: 'manual' };
188
221
  else if (v.startsWith('every:')) sch = { kind: 'every', every: v.slice(6), work: cur.kind === 'every' ? !!cur.work : true, ...(cur.busy ? { busy: cur.busy } : {}) };
189
222
  else sch = { kind: v, times: v === 'weekly' ? times.slice(0, 1) : times, ...(v === 'weekly' ? { day: cur.day || 'Mon' } : {}) };
190
- const res = await pmPost('/api/refresh/source', { id, schedule: sch });
223
+ const res = await pmPost('/api/refresh/source', r.svc ? { id: r.parent, svc: r.svc, schedule: sch } : { id, schedule: sch });
191
224
  await swLoad();
192
- const nr = (S.rows || []).find((y) => y.id === id);
225
+ const nr = rowOf(id);
193
226
  say(said(res, 'Saved. ' + r.label + ': ' + (nr ? everyLine(nr.schedule_text).toLowerCase() : 'saved') + '.'));
194
227
  } else {
195
228
  const s = (S.tasks || []).find((y) => y.id === id); if (!s) return true;
@@ -17,7 +17,7 @@
17
17
  * › Dress for the day (adler.dress.*, canvas AsSet1, batch 18 item 8): the master switch, where you are, one switch per group,
18
18
  * "More festivals" with one switch per day, big sports and your colours, exam season, your days, Wear now (pm/cozy-seasons.js).
19
19
  * openSettings('dress') opens it straight away (the › in Adler's tap popover, AsSet2Tap).
20
- * Connectors design A (batch 28 item 1, canvas CnA): one list, trouble first (GET /api/sources, pm/cozy-evmodel.js connectorRows). Each
20
+ * Connectors Listening at the end (event-relay, D110, pm/cozy-relay.js): GitHub and Jira can ring PMOS's doorbell. design A (batch 28 item 1, canvas CnA): one list, trouble first (GET /api/sources, pm/cozy-evmodel.js connectorRows). Each
21
21
  * source says its status once, on its own row: a trouble row has the amber dot, one reason and one icon action (↻ POST
22
22
  * /api/sources/refresh, or the place to fix it); a quiet row has its name and time, and "Checked 10:42 · same since 09:15"
23
23
  * where a measured read applies (SrSee R3). Claude's failed background work and the Git sync failure are rows too. ↻ in the
@@ -56,6 +56,8 @@ import * as SW from './cozy-schedwork.js';
56
56
  import * as AD from './cozy-adler.js';
57
57
  import * as SE from './cozy-seasons.js';
58
58
  import { weeksOf, lineOf, storiesOf } from './upd-weeks.js';
59
+ import { relayState, relayLoad, relayHtml, relayClick } from './cozy-relay.js'; // event-relay (D110): Connectors › Listening
60
+ const RL = relayState();
59
61
 
60
62
  /** PUT or DELETE with the page's launch nonce (pressFetch). Only the key row needs them. */
61
63
  async function pmSend(method, path, body) {
@@ -274,7 +276,8 @@ function connectors() {
274
276
  const search = `<label class="ev-cn-search"><span class="ev-vh">Search connectors</span>${svg(ICON.search, 16)}<input type="search" class="ev-inp" id="evConQ" placeholder="Search connectors" value="${esc(T.q || '')}" autocomplete="off"></label>`;
275
277
  const chips = `<div class="ev-cn-chips" role="group" aria-label="Category">${CD.CATS.map(([k, l]) => `<button type="button" class="ev-chip${T.cat === k ? ' on' : ''}" data-ev-ccat="${k}" aria-pressed="${T.cat === k}">${esc(l)}</button>`).join('')}</div>`;
276
278
  return info + readsHtml() + propCards() + `<div class="ev-cn">${search}${chips}<div id="evConList">${connList()}</div>`
277
- + `<p class="ev-small ev-mut ev-cn-foot">PMOS keeps no passwords or keys. A connector is added in your Claude account: + opens that page, and PMOS notices when it is there.</p></div>`;
279
+ + `<p class="ev-small ev-mut ev-cn-foot">PMOS keeps no passwords or keys. A connector is added in your Claude account: + opens that page, and PMOS notices when it is there.</p></div>`
280
+ + relayHtml(RL);
278
281
  }
279
282
  /** The directory's read; after a +, again every 5 s with the probe until the connector shows or 2 minutes pass. */
280
283
  async function readDir(probe) {
@@ -554,6 +557,7 @@ async function press(e) {
554
557
  if (t.dataset.evPok || t.dataset.evPno) { if (T.busy) return; T.busy = true; try { await decideProp(t.dataset.evPok || t.dataset.evPno, !!t.dataset.evPok); } finally { T.busy = false; } return; }
555
558
  if (t.dataset.evSec) { e.preventDefault(); const m = MOVED[t.dataset.evSec]; T.sec = m ? m[0] : t.dataset.evSec; T.sub = m ? m[1] : ''; T.msg = ''; T.dress = false; draw(); const f = T.el.querySelector(`[data-ev-sec="${T.sec}"]`); if (f) f.focus(); openCheck(); return; }
556
559
  if ('evClose' in t.dataset) { closeSettings(); return; }
560
+ if (await relayClick(e, RL, draw, toast)) return;
557
561
  if (t.dataset.evWk) { const k = t.dataset.evWk; if (T.wkOpen.has(k)) T.wkOpen.delete(k); else T.wkOpen.add(k); draw(); return; }
558
562
  if ('evArc' in t.dataset) { T.arc = !T.arc; draw(); return; }
559
563
  if ('evInfo' in t.dataset) { T.info = !T.info; draw(); return; }
@@ -679,7 +683,10 @@ async function readAgain(id) {
679
683
  if (T.reading) return;
680
684
  const ws = (T.fresh && T.fresh.ws) || wsParam() || '';
681
685
  T.reading = id || 'all'; draw();
682
- const r = await pmPost(id ? '/api/sources/refresh' : '/api/sources/refresh-all', id ? { ws, source: id } : { ws });
686
+ // batch 31 item 6: a service of Your tools ('tools.slack') is read on its own
687
+ const svc = /^tools\.([a-z]+)$/.exec(id || '');
688
+ const r = svc ? await pmPost('/api/refresh/run', { id: 'tools', svcs: [svc[1]], ...(ws ? { ws } : {}) })
689
+ : await pmPost(id ? '/api/sources/refresh' : '/api/sources/refresh-all', id ? { ws, source: id } : { ws });
683
690
  T.reading = '';
684
691
  if (id) {
685
692
  T.note[id] = r && r.ok ? (r.started === 'session' ? 'An agent session started to read it, with your own connection.' : 'Reading it again on this machine.') : 'It did not start: ' + ((r && r.error) || 'the server did not answer') + '.';
@@ -689,6 +696,7 @@ async function readAgain(id) {
689
696
  }
690
697
  async function load() {
691
698
  readFresh();
699
+ RL.st = null; RL.open = null; RL.steps = null; relayLoad(RL).then(draw).catch(() => {});
692
700
  SW.swLoad(draw);
693
701
  pmGet('/api/autonomy/kinds').then((k) => { T.ck = k && k.ok ? k : { ok: false, error: (k && k.error) || '' }; draw(); }).catch(() => { T.ck = { ok: false }; draw(); });
694
702
  pmGet('/api/artefacts/lessons').then((l) => { T.ls = l && l.ok ? l : null; draw(); }).catch(() => { T.ls = null; });
@@ -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(); } });
@@ -2325,6 +2328,49 @@ const liveGo = (x) => {
2325
2328
  return true;
2326
2329
  };
2327
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();
2328
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
2329
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. */
2330
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); });
@@ -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
+ }
@@ -3313,7 +3313,9 @@ refreshRun = refreshRunLib.create({
3313
3313
  homeWs: () => { const h = homeWorkspace(); return h ? h.id : null; },
3314
3314
  proactive: () => proSettings(),
3315
3315
  schedules: { read: readSchedules, write: writeSchedules },
3316
- startSkill: (wsId, skill, name, origin) => startSkillSession(wsId, skill, name, origin),
3316
+ startSkill: (wsId, skill, name, origin, opts) => startSkillSession(wsId, skill, name, origin, opts),
3317
+ // batch 31 item 6: what a read's session is doing (needs, blocked, working, quiet), so a stalled read says why
3318
+ sessionView: (id) => { const x = sessions.get(String(id || '')); return x ? describePeer(x, Date.now()) : null; },
3317
3319
  // a terminal session stuck at Claude's sign-in screen (the login it runs under expired): read from its pane, ended by the engine
3318
3320
  sessionSignedOut: (id) => { const x = sessions.get(String(id || '')); return !!x && !!x.tmux && x.state !== 'exited' && require('./lib/claude-signin.js').paneSignedOut(paneScreen(x)); },
3319
3321
  stopSession: (id) => { const x = sessions.get(String(id || '')); if (x && x.tmux) tmuxKillSession(x.tmux); },
@@ -3386,6 +3388,10 @@ bgQueue.register('day', () => { try { dayTick(); } catch (e) { warnWriteFail('da
3386
3388
  bgQueue.register('refresh', () => { try { refreshRun.tick(); } catch (e) { warnWriteFail('refresh tick', e); } });
3387
3389
  bgQueue.register('reports', () => dashboardScheduleTick());
3388
3390
  bgQueue.register('sync', gated('sync', () => autoSync.tick().catch(() => {})));
3391
+ // event-relay (D110): pull the signed event queue each minute; an event only rings the doorbell (starts the read of its source)
3392
+ const relayPuller = require('./lib/event-relay.js').puller({
3393
+ dir: STATE, refreshRun: () => refreshRun, register: (fn) => bgQueue.register('relay', fn),
3394
+ });
3389
3395
  bgQueue.register('driver', gated('driver', driverTick));
3390
3396
  // D106: long-running goals (lib/goal-loop.js, `pmos loop`): each tick closes a round whose run is gone (a restart) and starts the next round
3391
3397
  // of every running goal, through the capacity governor. `pmos ai off` and PMOS_AUTONOMY=off stop every loop.
@@ -5681,13 +5687,15 @@ function myWorkRead(wsId) {
5681
5687
  return { ok: true, session: s.id };
5682
5688
  }
5683
5689
  /** Refresh now (workspace-data-freshness R7): start skill `skillId` in a session of repository `wsId`, as myWorkRead does. */
5684
- function startSkillSession(wsId, skillId, name, origin) {
5685
- if (Array.isArray(skillId)) return startSharedRefreshSession(wsId, skillId, name, origin); // smart refresh step 2: several due sources, one session
5690
+ function startSkillSession(wsId, skillId, name, origin, opts) {
5691
+ if (Array.isArray(skillId)) return startSharedRefreshSession(wsId, skillId, name, origin, opts); // smart refresh step 2: several due sources, one session
5686
5692
  const w = getWs(wsId);
5687
5693
  if (!w) return { ok: false, status: 400, error: 'no workspace' };
5688
5694
  const task = taskById(skillId, w.root);
5689
5695
  if (!task || task.kind !== 'agent' || !task.prompt) return { ok: false, status: 409, error: `the ${skillId} skill is not installed for this repository` };
5690
- const prompt = skillStore.retargetFiling(task.prompt, filingContract(w));
5696
+ // batch 31 item 6: a read of some services of Your tools names them after the skill's own prompt
5697
+ const note = opts && opts.notes && opts.notes[skillId];
5698
+ const prompt = skillStore.retargetFiling(task.prompt, filingContract(w)) + (note ? '\n\n' + note : '');
5691
5699
  // data-refresh-settings: a refresh of a source runs as `refresh:<source>`, so the refresh log records it whoever pressed it.
5692
5700
  const src = refreshLib.SKILL_OF.get(skillId);
5693
5701
  const s = spawnSession({ name, agent: task.agent || 'claude', ws: w.id, origin: origin || (src ? 'refresh:' + src : 'source-refresh'), initialInput: prompt + '\r',
@@ -5697,14 +5705,15 @@ function startSkillSession(wsId, skillId, name, origin) {
5697
5705
  }
5698
5706
  /** Smart refresh step 2: ONE session that reads several due sources, one after another. Each part is that skill's own prompt, unchanged;
5699
5707
  * the refresh engine ends each source by whether its stored read is newer than the start (lib/refresh-run.js). */
5700
- function startSharedRefreshSession(wsId, skills, name, origin) {
5708
+ function startSharedRefreshSession(wsId, skills, name, origin, opts) {
5701
5709
  const w = getWs(wsId);
5702
5710
  if (!w) return { ok: false, status: 400, error: 'no workspace' };
5703
5711
  const parts = [];
5704
5712
  for (const skillId of skills || []) {
5705
5713
  const task = taskById(skillId, w.root);
5706
5714
  if (!task || task.kind !== 'agent' || !task.prompt) return { ok: false, status: 409, error: `the ${skillId} skill is not installed for this repository` };
5707
- parts.push({ skill: skillId, prompt: skillStore.retargetFiling(task.prompt, filingContract(w)), tier: task.tier || null });
5715
+ const note = opts && opts.notes && opts.notes[skillId];
5716
+ parts.push({ skill: skillId, prompt: skillStore.retargetFiling(task.prompt, filingContract(w)) + (note ? '\n\n' + note : ''), tier: task.tier || null });
5708
5717
  }
5709
5718
  if (parts.length < 2) return { ok: false, status: 400, error: 'a shared refresh needs two or more skills' };
5710
5719
  const head = `This session refreshes ${parts.length} sources, one after another: ${parts.map((x) => x.skill).join(', ')}. Do each part in order, as its own task, with its own rules and its own output sections. A part that fails or cannot reach its tool does not stop the next part. Do not wait for the PM between parts.`;
@@ -53,7 +53,7 @@ Procedure:
53
53
  {"source": "figma", "state": "off"},
54
54
  {"source": "drive", "state": "not-reached", "why": "the Drive connector is not connected"}]}
55
55
  ```
56
- Sources: mail, slack, wispr, jira, confluence, github, drive, figma, website. Give every source a record, even when it is off, except a source that step 2 found unchanged: leave it out, so its stored read is kept. Limits: 60 items, 30 digests and 200 places per source; title 140 characters, about 480, ask 240, a thread message 280, at most 4 thread messages. Leave out a field you cannot fill.
56
+ Sources: mail, slack, wispr, jira, confluence, github, drive, figma, website. Give every source a record, even when it is off, except a source that step 2 found unchanged: leave it out, so its stored read is kept. When this run names the sources it reads ("This run reads only these sources"), read and save only those, and leave the others out too. Limits: 60 items, 30 digests and 200 places per source; title 140 characters, about 480, ask 240, a thread message 280, at most 4 thread messages. Leave out a field you cannot fill.
57
57
  5. Run `pmos source save --file <that file>`. If it is refused, read the reason, fix the file and save once more. Do not work around a refusal.
58
58
  6. Finish with the output contract: under Read, each source and its number of items; under Not reached, each source and why; under Off, the sources that are off.
59
59