create-pmos 0.600.0 → 0.602.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.
@@ -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; });
@@ -282,6 +282,7 @@ export function mountChat(el, host) {
282
282
  placeDivider(parts, items, goal);
283
283
  let html = (t.intro && !(t.intro.onlyEmpty && items.length) ? introHtml(t.intro, !items.length) : '') + parts.join('') + askHtml(R) + (R.stop && R.lastAgent < 0 ? dividerHtml(R.stop) : '') + pendHtml() + queuedHtml();
284
284
  html += GU.choiceHtml(); // /goal while a goal works here: In a new chat, or Here instead
285
+ for (const n of C.notes || []) if (t.ini && n.ini === t.ini) html += `<p class="hm-note hm-you">${esc(n.text)}</p>`;
285
286
  if (C.th && C.th.working) html += `<p class="hm-note" role="status">The agent is answering. You can write again when it has.</p>`;
286
287
  if (C.conv && C.conv.state === 'ended') html += '<p class="hm-note">This session has ended. Your conversation is kept here, and your next message picks it up.</p>';
287
288
  // an empty chat: Adler resting, because nothing runs here yet (canvas AdH1)
@@ -728,6 +729,9 @@ export function mountChat(el, host) {
728
729
  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(); });
729
730
  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(); });
730
731
  window.addEventListener('pmos:say', (e) => { if (!mine(e) || !e.detail.text) return; send(String(e.detail.text)); });
732
+ // a hand edit in the canvas's inspector (pm/cozy-proto.js 'pmos:note'): one quiet line in the conversation, so it shows on both sides.
733
+ // It lives on this page only; the next version reads the edit itself from edits.json.
734
+ window.addEventListener('pmos:note', (e) => { if (!mine(e) || !e.detail.text) return; C.notes = [...(C.notes || []).filter((n) => n.ini === C.t.ini), { ini: C.t.ini, text: String(e.detail.text).slice(0, 200) }].slice(-4); draw(); });
731
735
  /* 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
736
  * shows them on the newest message, and on focus for a keyboard). A tap elsewhere hides them again. */
733
737
  let holdT = null;
@@ -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
 
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Initiative event-relay (D110; planning/done-tests/event-relay.md T2 to T5): the signed event relay on the central host (board-host/src/relay.js) on an in-memory store, and the workspace's doorbell (lib/event-relay.js) with a fake refresh runner and a write spy.",
3
+ "modules": [
4
+ "event-relay.test.js"
5
+ ],
6
+ "seconds": {
7
+ "event-relay.test.js": 3
8
+ }
9
+ }