create-pmos 0.600.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.
- package/package.json +20 -14
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +19 -0
- package/workspace/guide/settings-and-switches.md +24 -0
- package/workspace/lib/bg-queue.js +1 -0
- package/workspace/lib/event-relay.js +202 -0
- package/workspace/lib/job-graph.js +1 -0
- package/workspace/lib/refresh-run.js +171 -30
- package/workspace/lib/refresh.js +107 -20
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-refresh.js +12 -4
- package/workspace/lib/routes-relay.js +29 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-ev.css +9 -0
- package/workspace/public/pm/cozy-evmodel.js +14 -0
- package/workspace/public/pm/cozy-relay.js +80 -0
- package/workspace/public/pm/cozy-schedwork.js +52 -19
- package/workspace/public/pm/cozy-settings.js +11 -3
- package/workspace/server.js +15 -6
- package/workspace/skills/sources-read.skill +1 -1
- package/workspace/test-lists/event-relay.json +9 -0
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* GET /api/refresh?ws=<id> → { ok, ws, rules, quiet, window, rows: [row] } lib/refresh.js rowsOf
|
|
5
5
|
* POST /api/refresh/source { id, on?, schedule? } → { ok, source } on or off, and a skill source's schedule
|
|
6
6
|
* POST /api/refresh/rules { catchup?, retry?, tell?, max?, keep? } → { ok, rules }
|
|
7
|
-
* POST /api/refresh/
|
|
7
|
+
* POST /api/refresh/source { id: 'tools', svc, schedule|null } → { ok, source, svc } one service's own rhythm (null follows Your tools)
|
|
8
|
+
* POST /api/refresh/run { id, ws?, with_inputs?, svcs? } → { ok, source, started?|waiting?, inputs } Refresh now (svcs: some services of Your tools)
|
|
9
|
+
* POST /api/refresh/stop { id, ws?, again? } → { ok, stopped, again } Stop and read again (batch 31 item 6)
|
|
8
10
|
* POST /api/refresh/run-all { ws? } → { ok, started: [id], failed: [{ id, error }] } every source that is on
|
|
9
11
|
* GET /api/refresh/log?source=&result=&limit= → { ok, runs: [run] } newest first
|
|
10
12
|
* GET /api/refresh/log.csv → text/csv, every run kept
|
|
@@ -47,7 +49,7 @@ async function handle(req, res, url, ctx) {
|
|
|
47
49
|
return true;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
if (!['/api/refresh/source', '/api/refresh/rules', '/api/refresh/run', '/api/refresh/run-all'].includes(p)) return false;
|
|
52
|
+
if (!['/api/refresh/source', '/api/refresh/rules', '/api/refresh/run', '/api/refresh/run-all', '/api/refresh/stop'].includes(p)) return false;
|
|
51
53
|
if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
|
|
52
54
|
const got = await ctx.readJson(req);
|
|
53
55
|
if (!got.ok) { ctx.json(res, { ok: false, error: 'the body is not JSON' }, 400); return true; }
|
|
@@ -62,7 +64,7 @@ async function handle(req, res, url, ctx) {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
if (p === '/api/refresh/source') {
|
|
65
|
-
const r = run.setSource(String(body.id || ''), { on: body.on, schedule: body.schedule });
|
|
67
|
+
const r = run.setSource(String(body.id || ''), body.svc !== undefined ? { svc: body.svc, schedule: body.schedule } : { on: body.on, schedule: body.schedule });
|
|
66
68
|
ctx.json(res, r, r.ok ? 200 : 400);
|
|
67
69
|
return true;
|
|
68
70
|
}
|
|
@@ -74,7 +76,13 @@ async function handle(req, res, url, ctx) {
|
|
|
74
76
|
return true;
|
|
75
77
|
}
|
|
76
78
|
if (p === '/api/refresh/run') {
|
|
77
|
-
|
|
79
|
+
if (body.svcs !== undefined && !(Array.isArray(body.svcs) && body.svcs.every((x) => typeof x === 'string'))) { ctx.json(res, { ok: false, error: 'svcs must be a list of service ids' }, 400); return true; }
|
|
80
|
+
const r = run.runNow(String(body.id || ''), { ws, withInputs: body.with_inputs === true, svcs: body.svcs });
|
|
81
|
+
ctx.json(res, r, r.ok ? 200 : r.status || 400);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
if (p === '/api/refresh/stop') {
|
|
85
|
+
const r = run.stopAndRead(String(body.id || ''), { ws, again: body.again !== false });
|
|
78
86
|
ctx.json(res, r, r.ok ? 200 : r.status || 400);
|
|
79
87
|
return true;
|
|
80
88
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-relay.js — Settings › Connectors › Listening (initiative event-relay; D110). Page presses only; the host is never given a way in.
|
|
3
|
+
*
|
|
4
|
+
* GET /api/relay -> { ok, host, sources: { github, jira }, recent, last } (no secret, no key)
|
|
5
|
+
* POST /api/relay/setup { source } -> { ok, source, url, secret, steps } makes the address on the host; the PM pastes it into the service
|
|
6
|
+
* POST /api/relay/steps { source } -> { ok, source, url, secret, steps } shows the same steps again
|
|
7
|
+
* POST /api/relay/stop { source } -> { ok } the address and its queue are deleted on the host
|
|
8
|
+
* POST /api/relay/pull -> { ok, events, rang } pull now (the background queue pulls every minute)
|
|
9
|
+
* The secret goes only to this loopback page, for the PM to paste. Nothing here writes a record (D110 point 5). */
|
|
10
|
+
const relay = require('./event-relay.js');
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
prefixes: ['/api/relay'],
|
|
14
|
+
handle: async (req, res, url, ctx) => {
|
|
15
|
+
const p = url.pathname; const dir = ctx.runtimeDir;
|
|
16
|
+
if (p === '/api/relay' && req.method === 'GET') { ctx.json(res, { ok: true, ...relay.status(dir) }); return true; }
|
|
17
|
+
if (!['/api/relay/setup', '/api/relay/steps', '/api/relay/stop', '/api/relay/pull'].includes(p)) return false;
|
|
18
|
+
if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
|
|
19
|
+
const b = await ctx.readJson(req); const body = b && b.ok ? b.body || {} : {};
|
|
20
|
+
const source = String(body.source || '');
|
|
21
|
+
let r;
|
|
22
|
+
if (p === '/api/relay/setup') r = await relay.setup(dir, source, {});
|
|
23
|
+
else if (p === '/api/relay/steps') r = relay.steps(dir, source);
|
|
24
|
+
else if (p === '/api/relay/stop') r = await relay.stop(dir, source, {});
|
|
25
|
+
else r = await relay.pull(dir, { ring: ctx.refreshRun ? relay.doorbell(ctx.refreshRun) : null });
|
|
26
|
+
ctx.json(res, r, r.ok ? 200 : r.status || 400);
|
|
27
|
+
return true;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.601.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.601.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
|
@@ -423,6 +423,15 @@
|
|
|
423
423
|
.cz .ev-ls { display: flex; flex-direction: column; gap: 2px; }
|
|
424
424
|
.cz .ev-ls .ev-ms { color: var(--cz-late); }
|
|
425
425
|
.cz .ev-ls .ev-nx { color: var(--cz-blueink); }
|
|
426
|
+
/* Settings › Connectors › Listening (event-relay, D110; pm/cozy-relay.js) */
|
|
427
|
+
.ev-st .ev-rl-acts { display: flex; gap: 2px; }
|
|
428
|
+
.ev-st .ev-rl-steps { margin: 2px 0 10px 28px; padding: 10px 12px; border-radius: 12px; background: var(--cz-well); }
|
|
429
|
+
.ev-st .ev-rl-steps ol { margin: 0 0 8px; padding-left: 18px; }
|
|
430
|
+
.ev-st .ev-rl-steps li { margin: 3px 0; }
|
|
431
|
+
.ev-st .ev-rl-kv { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 6px; align-items: center; margin-top: 4px; }
|
|
432
|
+
.ev-st .ev-rl-kv code { overflow-wrap: anywhere; }
|
|
433
|
+
.ev-st .ev-rl-ev { margin: 4px 0 0 28px; padding: 0; list-style: none; }
|
|
434
|
+
.ev-st .ev-rl-ev li { padding: 2px 0; }
|
|
426
435
|
/* Settings › Connectors › Scheduled work (batch 31 item 2, agreed design SwC; pm/cozy-schedwork.js): the quiet entry, the list, and a
|
|
427
436
|
* job's page like the Claude app's scheduled task: Active, Next run, Repeats in one card, PMOS's ✦ rhythm, History, ▶ Read now */
|
|
428
437
|
.ev-st .ev-sw-ic { color: var(--cz-ink3); display: inline-flex; flex: none; }
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* (self-heal, feedback batch 26 item 7): null while Claude repairs a source by itself, or after it did
|
|
9
9
|
* sourceRows(sources, now) → [{ id, name, sub, when, risk, act: 'read' | 'connect' | '' }] the Sources table (EvSources)
|
|
10
10
|
* connectorRows(sources, health, now) → [{ id, name, trouble, why, when, act }] Settings › Connectors, design A (CnA): trouble first
|
|
11
|
+
* svcRow(svc, schedule, job, now) → one service of Your tools as a Connectors row (batch 31 item 6, StA)
|
|
11
12
|
* issueRow(issue) → { src, name, why } a harness-health issue split into a row's name and reason
|
|
12
13
|
* clockOf(iso, now) → '09:15' today · 'yesterday' · '3 Nov'
|
|
13
14
|
* partsOf(id) → what may be out of date when that source is old ('Board and the Jira-linked initiatives')
|
|
@@ -137,6 +138,17 @@ export function scheduleLine(s, now = Date.now()) {
|
|
|
137
138
|
const nx = sch.next_run ? nextOf(sch.next_run, now) : '';
|
|
138
139
|
return { text: everyLine(sch.cadence) + (nx ? ' · next ' + nx : ''), missed: false };
|
|
139
140
|
}
|
|
141
|
+
/** One service of Your tools as a Connectors row (batch 31 item 6). `id` is 'tools.<svc>', which ↻ and › read. */
|
|
142
|
+
export function svcRow(v, sch, job, now = Date.now()) {
|
|
143
|
+
const id = (job || 'tools') + '.' + v.id, base = { id, name: v.label, job: id, svc: v.id };
|
|
144
|
+
const st = sch.stall && v.reading && (!sch.stall.svcs || sch.stall.svcs.includes(v.id)) ? sch.stall : null;
|
|
145
|
+
if (st) return { ...base, trouble: 1, why: 'Stuck since ' + clockOf(st.since, now) + ' · ' + st.why.replace(/^./, (c) => c.toLowerCase()), when: '', act: null };
|
|
146
|
+
if (v.cadence === 'off') return { ...base, trouble: 0, why: 'Off', when: '', act: null };
|
|
147
|
+
if (v.last_state === 'not-reached' && !v.reading) return { ...base, trouble: 2, why: 'Not reached' + (v.last_why ? ': ' + v.last_why : '') + '.', when: '', act: { kind: 'read', label: 'Read ' + v.label + ' again' } };
|
|
148
|
+
if (v.missed_at && !v.reading) return { ...base, trouble: 4, why: (v.last_at ? 'Read ' + atOf(v.last_at, now) : 'Never read') + ' · missed ' + atOf(v.missed_at, now), when: '', act: { kind: 'read', label: 'Read ' + v.label + ' again' } };
|
|
149
|
+
const nx = v.next_run ? nextOf(v.next_run, now) : '';
|
|
150
|
+
return { ...base, trouble: 0, why: v.reading ? 'Reading now' : everyLine(v.cadence) + (nx ? ' · next ' + nx : ''), when: v.reading ? '' : v.last_at ? short(ago(v.last_at, now)) : 'Never read', act: null };
|
|
151
|
+
}
|
|
140
152
|
/**
|
|
141
153
|
* connectorRows(sources, health, now) → [{ id, name, trouble, why, when, act }] trouble rows first (needs you, then failed, then
|
|
142
154
|
* the other issues), then the quiet rows in the server's order.
|
|
@@ -169,6 +181,8 @@ export function connectorRows(sources, health, now = Date.now()) {
|
|
|
169
181
|
}
|
|
170
182
|
const mend = h && h.state === 'repairing' && (s.state === 'stale' || s.state === 'never');
|
|
171
183
|
const sch = s.schedule || {}, job = sch.refresh || null, line = scheduleLine(s, now);
|
|
184
|
+
// batch 31 item 6 (A): Your tools is one row per service, each with its own rhythm; a stuck read names why on the services it holds
|
|
185
|
+
if (Array.isArray(sch.svcs) && sch.svcs.length && sch.cadence !== 'off') { for (const v of sch.svcs) out.push(svcRow(v, sch, job, now)); continue; }
|
|
172
186
|
if (line && line.missed && !mend && s.state !== 'building' && s.state !== 'off') {
|
|
173
187
|
out.push({ id: s.id, name, trouble: 4, why: line.text, when: '', act: read, ...(job ? { job } : {}) });
|
|
174
188
|
continue;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/* cozy-relay.js — Settings › Connectors › Listening (initiative event-relay; D110; design "Connectors directory and events", board CnC).
|
|
2
|
+
*
|
|
3
|
+
* GitHub and Jira can send events to the central host; PMOS pulls them each minute and starts a read of that service. An event only starts a
|
|
4
|
+
* read: it never changes a record. Each row: the service, what it does now (Listening · the last event, or Reads on its schedule), and icon
|
|
5
|
+
* buttons: listen, show the steps again, stop. The steps show the address and the secret with a copy button each, for the PM to paste into
|
|
6
|
+
* GitHub or Jira; PMOS sends nothing to those services.
|
|
7
|
+
*
|
|
8
|
+
* relayState() -> a fresh state object for one Settings dialog
|
|
9
|
+
* relayLoad(R) GET /api/relay
|
|
10
|
+
* relayHtml(R) -> the Listening block (a slot under the Connectors rows)
|
|
11
|
+
* relayClick(e, R, redraw, toast) -> true when the press was one of this block's; runs the press
|
|
12
|
+
* Routes: lib/routes-relay.js. UI copy says PMOS. */
|
|
13
|
+
import { pmGet, pmPost } from './http.js';
|
|
14
|
+
import { esc, svg } from './cozy-evui.js';
|
|
15
|
+
|
|
16
|
+
const LABEL = { github: 'GitHub', jira: 'Jira' };
|
|
17
|
+
const BELL = 'M6 16V11a6 6 0 0 1 12 0v5l2 2H4zM10 20a2 2 0 0 0 4 0';
|
|
18
|
+
const OFF = 'M6 16V11a6 6 0 0 1 9.5-4.9M18 11v5l2 2H8M10 20a2 2 0 0 0 4 0M3 3l18 18';
|
|
19
|
+
const STEPS = 'M9 6h11M9 12h11M9 18h11M4 6h.01M4 12h.01M4 18h.01';
|
|
20
|
+
const COPY = 'M9 9h11v11H9zM5 15V5a1 1 0 0 1 1-1h10';
|
|
21
|
+
function ago(iso) {
|
|
22
|
+
const t = Date.parse(iso); if (!Number.isFinite(t)) return '';
|
|
23
|
+
const m = Math.round((Date.now() - t) / 60000);
|
|
24
|
+
if (m < 1) return 'just now'; if (m < 60) return m + ' min ago';
|
|
25
|
+
const h = Math.round(m / 60); if (h < 24) return h + ' h ago';
|
|
26
|
+
return Math.round(h / 24) + ' d ago';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function relayState() { return { st: null, open: null, steps: null, busy: false }; }
|
|
30
|
+
|
|
31
|
+
export async function relayLoad(R) {
|
|
32
|
+
const r = await pmGet('/api/relay');
|
|
33
|
+
R.st = r && r.ok ? r : { ok: false };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ib = (act, src, icon, label) => `<button type="button" class="ev-ib" data-rl="${act}" data-rls="${esc(src)}" aria-label="${esc(label)}" title="${esc(label)}">${svg(icon, 18)}</button>`;
|
|
37
|
+
|
|
38
|
+
export function relayHtml(R) {
|
|
39
|
+
const st = R.st;
|
|
40
|
+
if (st === null) return '';
|
|
41
|
+
const head = '<h4 id="evListen">Listening</h4>';
|
|
42
|
+
if (!st.ok) return `<div data-relay>${head}<p class="ev-small ev-mut">The listening settings could not be read.</p></div>`;
|
|
43
|
+
const rows = Object.keys(LABEL).map((k) => {
|
|
44
|
+
const s = (st.sources && st.sources[k]) || { listening: false };
|
|
45
|
+
const what = s.listening ? 'Listening · ' + (s.last ? 'last event ' + ago(s.last) : 'no event yet') : 'Reads on its schedule';
|
|
46
|
+
const acts = s.listening ? ib('steps', k, STEPS, 'Show the ' + LABEL[k] + ' steps') + ib('stop', k, OFF, 'Stop listening to ' + LABEL[k]) : ib('setup', k, BELL, 'Listen for ' + LABEL[k] + ' events');
|
|
47
|
+
let panel = '';
|
|
48
|
+
if (R.open === k && R.steps && R.steps.source === k) {
|
|
49
|
+
panel = `<div class="ev-rl-steps ev-small" data-rl-panel="${esc(k)}"><ol>${R.steps.steps.map((x) => `<li>${esc(x)}</li>`).join('')}</ol>`
|
|
50
|
+
+ `<div class="ev-rl-kv"><b>Address</b><code>${esc(R.steps.url)}</code>${ib('copy-url', k, COPY, 'Copy the address')}</div>`
|
|
51
|
+
+ `<div class="ev-rl-kv"><b>Secret</b><code>${esc(R.steps.secret)}</code>${ib('copy-secret', k, COPY, 'Copy the secret')}</div></div>`;
|
|
52
|
+
}
|
|
53
|
+
return `<div class="ev-trow ev-fr" data-rl-row="${esc(k)}"><span class="ev-gut">${s.listening ? '<i class="ev-dot ok" aria-hidden="true"></i>' : ''}</span><div class="ev-tx ev-grow"><span>${esc(LABEL[k])}</span><p class="ev-small ev-mut">${esc(what)}</p></div><span class="ev-rl-acts">${acts}</span></div>${panel}`;
|
|
54
|
+
}).join('');
|
|
55
|
+
const recent = (st.recent || []).slice(0, 5);
|
|
56
|
+
const ev = recent.length ? `<ul class="ev-rl-ev ev-small ev-mut" aria-label="Recent events">${recent.map((e) => `<li>${esc(LABEL[e.source] || e.source)} · ${esc(e.kind)}${e.key ? ' · ' + esc(e.key) : ''} · ${esc(ago(e.at))}</li>`).join('')}</ul>` : '';
|
|
57
|
+
const host = st.host ? '' : '<p class="ev-small ev-late">Listening needs the central host. Set its address in Board › Publish first.</p>';
|
|
58
|
+
return `<div data-relay>${head}<p class="ev-small ev-mut">A service that sends events is read within a minute of a change, even while this computer sleeps. An event only starts a read; it never changes your records.</p>${host}${rows}${ev}</div>`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function relayClick(e, R, redraw, toast) {
|
|
62
|
+
const b = e.target.closest('[data-rl]'); if (!b) return false;
|
|
63
|
+
if (R.busy) return true;
|
|
64
|
+
const act = b.dataset.rl, src = b.dataset.rls, name = LABEL[src] || src;
|
|
65
|
+
const say = (t) => { if (toast) toast(t); };
|
|
66
|
+
if (act === 'copy-url' || act === 'copy-secret') {
|
|
67
|
+
const v = R.steps ? (act === 'copy-url' ? R.steps.url : R.steps.secret) : '';
|
|
68
|
+
try { await navigator.clipboard.writeText(v); say(act === 'copy-url' ? 'Address copied.' : 'Secret copied.'); } catch { say('Select it and copy it by hand.'); }
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (act === 'steps' && R.open === src) { R.open = null; R.steps = null; redraw(); return true; }
|
|
72
|
+
R.busy = true;
|
|
73
|
+
const r = await pmPost('/api/relay/' + (act === 'setup' ? 'setup' : act === 'stop' ? 'stop' : 'steps'), { source: src });
|
|
74
|
+
R.busy = false;
|
|
75
|
+
if (!r || r.ok === false) { say((r && r.error) || 'Not done.'); return true; }
|
|
76
|
+
if (act === 'stop') { R.open = null; R.steps = null; say('PMOS stopped listening to ' + name + '. It reads it on its schedule.'); }
|
|
77
|
+
else { R.open = src; R.steps = r; if (act === 'setup') say('Paste the address and the secret into ' + name + '.'); }
|
|
78
|
+
await relayLoad(R); redraw();
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
@@ -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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
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(
|
|
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 = (
|
|
162
|
-
|
|
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 = (
|
|
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 (
|
|
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 = (
|
|
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
|
-
|
|
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; });
|
package/workspace/server.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
+
}
|