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.
- package/package.json +33 -27
- 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 +32 -0
- package/workspace/guide/layout.md +10 -3
- 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/initiative-premium.js +2 -2
- 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-initiative-premium.js +11 -1
- 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-home.css +76 -0
- package/workspace/public/pm/cozy-live-pill.js +4 -0
- package/workspace/public/pm/cozy-nav.js +26 -6
- 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/public/pm/home-app.js +47 -1
- package/workspace/public/pm/home-chat.js +17 -2
- package/workspace/public/pm/phone-chat-head.js +147 -0
- package/workspace/server.js +15 -6
- package/workspace/skills/sources-read.skill +1 -1
- package/workspace/test-lists/event-relay.json +9 -0
- package/workspace/test-lists/roomier-phone-chat.json +9 -0
|
@@ -40,9 +40,12 @@ const R = require('./refresh.js');
|
|
|
40
40
|
const H = require('./source-heal.js');
|
|
41
41
|
const FP = require('./read-fingerprint.js');
|
|
42
42
|
const P = require('./refresh-probe.js');
|
|
43
|
+
const SR = require('./source-reads.js');
|
|
43
44
|
|
|
44
45
|
const PRUNE_EVERY_MS = 24 * 3600 * 1000;
|
|
45
46
|
const LOST_MS = 6 * 3600 * 1000; // a run with no live session and no end after this long is written as interrupted
|
|
47
|
+
const READ_MS = 30 * 60 * 1000; // batch 31 item 6: a read of a tool (how 'tool') is stopped after this long, with the reason, so the next slot can run
|
|
48
|
+
const SLOW_MS = 15 * 60 * 1000; // a read still working after this long shows as slow on its row
|
|
46
49
|
const ALL_MS = 3 * 3600 * 1000; // a Refresh all that has not ended after this long is over: a new press starts a new one
|
|
47
50
|
const DERIVED = Object.freeze(['leads', 'brief']); // what Refresh all writes again after the sources, in this order
|
|
48
51
|
const DERIVED_LIST = Object.freeze(['scan', 'coredocs', 'leads', 'brief']); // what Sources lists as derived content: built from stored reads, never a tool
|
|
@@ -56,7 +59,15 @@ function sourcesOfOrigin(origin, opts) {
|
|
|
56
59
|
const one = R.sourceOfOrigin(origin, opts);
|
|
57
60
|
return one ? [one] : [];
|
|
58
61
|
}
|
|
59
|
-
const sharedOrigin = (ids) => 'refresh:' + ids.join('+');
|
|
62
|
+
const sharedOrigin = (ids) => 'refresh:' + ids.join('+');
|
|
63
|
+
/** The words a run of Your tools adds to its prompt when it reads only some services (batch 31 item 6), or null when it reads all. */
|
|
64
|
+
function svcNote(svcs) {
|
|
65
|
+
const ids = Array.isArray(svcs) ? svcs.filter((x) => R.SVC_BY_ID.has(x)) : [];
|
|
66
|
+
if (!ids.length || ids.length >= R.TOOL_SVCS.length) return null;
|
|
67
|
+
const reads = ids.flatMap((x) => R.SVC_BY_ID.get(x).reads).concat('jira');
|
|
68
|
+
return `This run reads only these sources: ${reads.join(', ')} (Jira is its mentions). Leave every other source out of the reads file, so its stored read is kept.`;
|
|
69
|
+
}
|
|
70
|
+
const svcList = (svcs) => (svcs && typeof svcs === 'object' && !Array.isArray(svcs) ? Object.keys(svcs) : Array.isArray(svcs) ? svcs : null); // a run that failed on Claude's sign-in is tried once more after this (the token is usually refreshed by then)
|
|
60
71
|
|
|
61
72
|
function create(host) {
|
|
62
73
|
const now = () => (host.now ? host.now() : Date.now());
|
|
@@ -66,6 +77,7 @@ function create(host) {
|
|
|
66
77
|
const jobWait = new Map(); // job id → ms it started waiting for an input
|
|
67
78
|
let lastPrune = 0;
|
|
68
79
|
let lastRetire = 0;
|
|
80
|
+
const stopLater = new Set(); // sessions of reads stopped after 30 min, closed once no source holds them
|
|
69
81
|
|
|
70
82
|
/* ── settings, with the one-time move of the seed schedules (R3) ── */
|
|
71
83
|
function settings() {
|
|
@@ -112,6 +124,30 @@ function create(host) {
|
|
|
112
124
|
/* ── the state of each source between minutes ── */
|
|
113
125
|
const openOf = (st) => (st && st.open && typeof st.open === 'object' ? st.open : {});
|
|
114
126
|
const running = (st) => Object.keys(openOf(st)).length > 0;
|
|
127
|
+
/** The services the open runs of Your tools read now (a run with no list reads them all). */
|
|
128
|
+
const busySvcs = (st) => { const out = new Set(); for (const o of Object.values(openOf(st))) for (const x of (Array.isArray(o.svcs) ? o.svcs : R.TOOL_SVCS.map((y) => y.id))) out.add(x); return [...out]; };
|
|
129
|
+
/** A source's state as lib/refresh.js decide and rowsOf read it. */
|
|
130
|
+
const viewOf = (st) => ({ ...(st || {}), running: running(st), busy_svcs: running(st) ? busySvcs(st) : [] });
|
|
131
|
+
/**
|
|
132
|
+
* Why an open read has not ended (batch 31 item 6): from the session itself (lib/session-state.js, through host.sessionView).
|
|
133
|
+
* → { why, fix, kind, session, since } | null. Asks for permission or an answer at once; slow after SLOW_MS.
|
|
134
|
+
*/
|
|
135
|
+
function stallOfRun(sid, o, t) {
|
|
136
|
+
if (t - o.at < 60000) return null; // a read in its first minute is not stuck yet (and its session is not asked)
|
|
137
|
+
let v = null; try { v = host.sessionView ? host.sessionView(sid) : null; } catch { v = null; }
|
|
138
|
+
const shown = v && v.shown;
|
|
139
|
+
const base = { session: sid, since: new Date(o.at).toISOString(), mins: Math.max(1, Math.round((t - o.at) / 60000)) };
|
|
140
|
+
if (shown === 'blocked') return { ...base, kind: 'permission', why: 'Waiting for your permission', fix: 'A background read cannot ask you. Open the session and allow it, or stop it and read again.' };
|
|
141
|
+
if (shown === 'needs') return { ...base, kind: 'answer', why: 'Waiting for your answer', fix: 'Open the session and answer it, or stop it and read again.' };
|
|
142
|
+
if (t - o.at > SLOW_MS) return { ...base, kind: 'slow', why: 'Still reading after ' + base.mins + ' min', fix: 'PMOS stops it at 30 min so the next read starts on time. You can open it to see what it is doing, or stop it and read again.', ...(v && v.doing ? { doing: String(v.doing).slice(0, 160) } : {}) };
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
/** The stall of source `id`: its oldest open run that is stuck, or null. */
|
|
146
|
+
function stallOf(id, state, t) {
|
|
147
|
+
const open = Object.entries(openOf(state[id])).sort((a, b) => (a[1].at || 0) - (b[1].at || 0));
|
|
148
|
+
for (const [sid, o] of open) { const x = stallOfRun(sid, o, t); if (x) return { ...x, ...(Array.isArray(o.svcs) && o.svcs.length < R.TOOL_SVCS.length ? { svcs: o.svcs } : {}) }; }
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
115
151
|
function inputStateFn(set, state, t) {
|
|
116
152
|
return (id) => {
|
|
117
153
|
const x = set.sources[id]; const st = state[id] || {};
|
|
@@ -120,8 +156,8 @@ function create(host) {
|
|
|
120
156
|
if (st.waiting_since || st.pending) return 'waiting';
|
|
121
157
|
const src = R.BY_ID.get(id);
|
|
122
158
|
if (src && src.run === 'skill') {
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
159
|
+
const due = R.dueOf(src, x, st, t, win(), busyDay);
|
|
160
|
+
if (due && t - due.slot < 2 * 3600 * 1000) return 'due';
|
|
125
161
|
}
|
|
126
162
|
return 'ok';
|
|
127
163
|
};
|
|
@@ -151,10 +187,13 @@ function create(host) {
|
|
|
151
187
|
const run = R.newRun(id, t);
|
|
152
188
|
const trigger = ex.trigger || (String(s.origin).startsWith('schedule:') ? 'schedule' : String(s.origin).startsWith('refresh:') ? 'pressed' : 'schedule');
|
|
153
189
|
const inputs = snapshot(id, set, state, t);
|
|
154
|
-
|
|
155
|
-
|
|
190
|
+
const svcs = R.hasSvcs(R.BY_ID.get(id)) ? svcList(ex.svcs) || R.TOOL_SVCS.map((x) => x.id) : null;
|
|
191
|
+
state[id] = { ...st, open: { ...openOf(st), [s.id]: { run, at: t, trigger, ...(svcs ? { svcs } : {}) } }, started_at: t, trigger, waiting_since: null, waiting_for: [], pending: null };
|
|
192
|
+
// a run of every service passes the mark of each; a run of some passes only theirs
|
|
193
|
+
const marks = svcs ? Object.fromEntries(svcs.map((x) => [x, ex.svcs && !Array.isArray(ex.svcs) && ex.svcs[x] != null ? ex.svcs[x] : ex.slot != null ? ex.slot : t])) : null;
|
|
194
|
+
state[id] = R.marked(state[id], ex.slot != null && (!svcs || svcs.length === R.TOOL_SVCS.length) ? ex.slot : null, marks);
|
|
156
195
|
R.writeState(dir, state);
|
|
157
|
-
R.append(dir, { source: id, ws: s.ws || null, ev: 'start', run, trigger, session: s.id, inputs, ...(ex.note ? { note: ex.note } : {}), ...(shared ? { shared } : {}) }, t);
|
|
196
|
+
R.append(dir, { source: id, ws: s.ws || null, ev: 'start', run, trigger, session: s.id, inputs, ...(ex.note ? { note: ex.note } : {}), ...(shared ? { shared } : {}), ...(svcs && svcs.length < R.TOOL_SVCS.length ? { svcs } : {}) }, t);
|
|
158
197
|
}
|
|
159
198
|
/** End the open run of session `s`. `over` sets the result for a run whose session has no outcome of its own. */
|
|
160
199
|
function ended(s, over) {
|
|
@@ -182,6 +221,23 @@ function create(host) {
|
|
|
182
221
|
const at = r && r.as_of ? Date.parse(r.as_of) || 0 : 0;
|
|
183
222
|
return at >= since - 1000;
|
|
184
223
|
}
|
|
224
|
+
/** Your tools in a shared session: one of its services saved a read after the start, or the run asked and found it the same. */
|
|
225
|
+
function svcReadSince(ws, o) {
|
|
226
|
+
const rt = readDirs(ws).runtime || dir;
|
|
227
|
+
try { if (P.askedSince(rt, 'tools', o.at)) return true; } catch { /* not asked */ }
|
|
228
|
+
const ids = Array.isArray(o.svcs) && o.svcs.length ? o.svcs : R.TOOL_SVCS.map((x) => x.id);
|
|
229
|
+
return ids.some((x) => R.SVC_BY_ID.get(x).reads.some((k) => { const r = SR.read(rt, k); return !!r && (Date.parse(r.read_at) || 0) >= o.at - 1000; }));
|
|
230
|
+
}
|
|
231
|
+
/** The stored read of each service: { <svc>: { at, state, why } }, the newest of its records. */
|
|
232
|
+
function svcReads(ws) {
|
|
233
|
+
const rt = readDirs(ws).runtime || dir; const out = {};
|
|
234
|
+
for (const x of R.TOOL_SVCS) {
|
|
235
|
+
let best = null;
|
|
236
|
+
for (const k of x.reads) { const r = SR.read(rt, k); if (r && (!best || Date.parse(r.read_at) > Date.parse(best.read_at))) best = r; }
|
|
237
|
+
if (best) out[x.id] = { at: best.read_at, state: best.state, why: best.why || null };
|
|
238
|
+
}
|
|
239
|
+
return out;
|
|
240
|
+
}
|
|
185
241
|
/** The host shows a lib/freshness.js row for `id`: only then can a run be held to having saved its read. */
|
|
186
242
|
function hasRow(id, ws) {
|
|
187
243
|
const src = R.BY_ID.get(id); if (!src || !src.fresh) return false;
|
|
@@ -199,7 +255,7 @@ function create(host) {
|
|
|
199
255
|
else { result = /code 0\)$/.test(s.note || '') ? 'done' : 'failed'; error = result === 'failed' ? s.note || 'the session ended' : null; }
|
|
200
256
|
// a shared session has one outcome for several sources: each source is done only when its stored read is newer than the start
|
|
201
257
|
if (shared && !over && result !== 'interrupted') {
|
|
202
|
-
if (readSince(id, s.ws || null, o.at)) { result = 'done'; error = null; }
|
|
258
|
+
if (readSince(id, s.ws || null, o.at) || (id === 'tools' && svcReadSince(s.ws || null, o))) { result = 'done'; error = null; }
|
|
203
259
|
else { result = 'failed'; got = null; error = 'The shared refresh session did not save a new read of it' + (error ? ` (${error})` : '') + '.'; }
|
|
204
260
|
} else if (!over && result === 'done' && SAVES_READ.includes(id)) {
|
|
205
261
|
// batch 28 item 1: a read whose run ended well but saved nothing failed, with the run's own words as the reason. On the Mac a Jira
|
|
@@ -240,6 +296,7 @@ function create(host) {
|
|
|
240
296
|
const scheduled = ['schedule', 'catch-up', 'retry'].includes(o.trigger);
|
|
241
297
|
if (next.auth_retried && authFail && !st.auth_retried) { /* the sign-in retry above */ }
|
|
242
298
|
else if (result === 'failed' && scheduled && src && src.run === 'skill' && rules.retry !== 'no' && !st.retried) { next.retry_at = t + Number(rules.retry) * 60000; next.retried = true; }
|
|
299
|
+
if (next.retry_at && o.svcs) next.retry_svcs = o.svcs; else if (!next.retry_at) delete next.retry_svcs;
|
|
243
300
|
else if (result === 'failed' && o.trigger === 'retry') next.retry_at = null;
|
|
244
301
|
state[id] = next;
|
|
245
302
|
R.writeState(dir, state);
|
|
@@ -299,20 +356,31 @@ function create(host) {
|
|
|
299
356
|
if (!alive || t - o.at > LOST_MS) {
|
|
300
357
|
delete st.open[sid]; st.retry_at = null; changed = true;
|
|
301
358
|
R.append(dir, { source: id, ev: 'end', run: o.run, result: 'interrupted', took_ms: t - o.at, error: alive ? 'no end after 6 hours' : 'the session was gone (PMOS restarted, or the session was closed)' }, t);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
// batch 31 item 6: a read of a tool that has not ended after 30 min is stopped, with what it was doing, so the next slot can run
|
|
362
|
+
const src0 = R.BY_ID.get(id);
|
|
363
|
+
if (src0 && src0.how === 'tool' && t - o.at > READ_MS) {
|
|
364
|
+
const why = stallOfRun(sid, o, t);
|
|
365
|
+
delete st.open[sid]; st.retry_at = null; changed = true;
|
|
366
|
+
R.append(dir, { source: id, ev: 'end', run: o.run, result: 'interrupted', took_ms: t - o.at, error: 'Stopped after 30 min' + (why ? ': ' + why.why.toLowerCase() : '') + '. The next read starts on time.' }, t);
|
|
367
|
+
stopLater.add(sid);
|
|
302
368
|
}
|
|
303
369
|
}
|
|
304
370
|
}
|
|
305
371
|
if (changed) R.writeState(dir, state);
|
|
372
|
+
// a session is stopped once none of its sources holds it open (a shared session holds several)
|
|
373
|
+
for (const sid of stopLater) { if (!Object.values(state).some((x) => openOf(x)[sid])) { stopLater.delete(sid); try { if (host.stopSession) host.stopSession(sid); } catch (e) { warn('stop a read after 30 min', e); } } }
|
|
306
374
|
const first = !tick.seen; tick.seen = true;
|
|
307
375
|
shareDue(t, set, rules, first);
|
|
308
376
|
for (const src of R.SOURCES.filter((x) => x.run === 'skill')) {
|
|
309
377
|
const cur = R.readState(dir);
|
|
310
|
-
const st =
|
|
378
|
+
const st = viewOf(cur[src.id]);
|
|
311
379
|
const d = R.decide(src, st, { now: t, settings: set, rules, win: win(), busyDay, quiet: quiet(), runningCount: runningCount(cur), inputState: inputStateFn(set, cur, t), first });
|
|
312
380
|
if (d.act === 'none') continue;
|
|
313
381
|
const ws = (set.sources[src.id] && set.sources[src.id].ws) || (st.pending && st.pending.ws) || host.homeWs();
|
|
314
382
|
if (d.act === 'skip') {
|
|
315
|
-
cur[src.id] =
|
|
383
|
+
cur[src.id] = R.marked(cur[src.id], d.svcs && Object.keys(d.svcs).length < R.TOOL_SVCS.length ? null : d.slot, d.svcs);
|
|
316
384
|
R.writeState(dir, cur);
|
|
317
385
|
if (!d.quiet) R.append(dir, { source: src.id, ws, ev: 'skip', trigger: 'schedule', note: d.why }, t);
|
|
318
386
|
continue;
|
|
@@ -338,7 +406,7 @@ function create(host) {
|
|
|
338
406
|
continue;
|
|
339
407
|
}
|
|
340
408
|
}
|
|
341
|
-
start(src, ws, { trigger: d.trigger, slot: d.slot, note: d.note });
|
|
409
|
+
start(src, ws, { trigger: d.trigger, slot: d.slot, note: d.note, svcs: d.svcs });
|
|
342
410
|
}
|
|
343
411
|
// PMOS_SOURCE_HEAL=off stops the repairs (a suite about pressed and scheduled runs sets it, so no repair run races them)
|
|
344
412
|
if (process.env.PMOS_SOURCE_HEAL !== 'off') { try { healTick(t, set); } catch (e) { warn('source repair', e); } }
|
|
@@ -382,7 +450,8 @@ function create(host) {
|
|
|
382
450
|
if (runningCount(cur) >= Number(rules.max || 3)) return;
|
|
383
451
|
const due = [];
|
|
384
452
|
for (const src of R.SOURCES.filter((x) => x.run === 'skill' && x.group === 'tools')) {
|
|
385
|
-
const st =
|
|
453
|
+
const st = viewOf(cur[src.id]);
|
|
454
|
+
if (st.running) continue; // a source with a run going starts alone (Your tools, for its other services)
|
|
386
455
|
const d = R.decide(src, st, { now: t, settings: set, rules, win: win(), busyDay, quiet: quiet(), runningCount: runningCount(cur), inputState: inputStateFn(set, cur, t), first });
|
|
387
456
|
if (d.act === 'start' && AUTO.has(d.trigger) && !d.pressed) due.push({ src, d, ws: (set.sources[src.id] && set.sources[src.id].ws) || host.homeWs() });
|
|
388
457
|
}
|
|
@@ -390,7 +459,7 @@ function create(host) {
|
|
|
390
459
|
for (const x of due) { const a = byWs.get(x.ws) || []; a.push(x); byWs.set(x.ws, a); }
|
|
391
460
|
for (const [ws, list] of byWs) {
|
|
392
461
|
if (list.length < 2) continue; // one due source starts alone in the tick below
|
|
393
|
-
startTogether(list.map((x) => ({ src: x.src, trigger: x.d.trigger, slot: x.d.slot, note: x.d.note })), ws);
|
|
462
|
+
startTogether(list.map((x) => ({ src: x.src, trigger: x.d.trigger, slot: x.d.slot, note: x.d.note, svcs: x.d.svcs })), ws);
|
|
394
463
|
}
|
|
395
464
|
}
|
|
396
465
|
/** Start `srcs` (sources) for a scheduled run: in one shared session when two or more share a workspace and the host can, else each
|
|
@@ -411,15 +480,16 @@ function create(host) {
|
|
|
411
480
|
* failed run of each source, the same as start() does for one. */
|
|
412
481
|
function startTogether(items, ws) {
|
|
413
482
|
const ids = items.map((x) => x.src.id);
|
|
414
|
-
for (const x of items) expect.set(x.src.id, { trigger: x.trigger, slot: x.slot, note: x.note });
|
|
483
|
+
for (const x of items) expect.set(x.src.id, { trigger: x.trigger, slot: x.slot, note: x.note, svcs: x.svcs });
|
|
484
|
+
const notes = {}; for (const x of items) { const n = svcNote(svcList(x.svcs)); if (n) notes[x.src.skill] = n; }
|
|
415
485
|
let r;
|
|
416
|
-
try { r = host.startSkill(ws, items.map((x) => x.src.skill), items.map((x) => x.src.label).join(', ') + ' · refresh', sharedOrigin(ids)); }
|
|
486
|
+
try { r = host.startSkill(ws, items.map((x) => x.src.skill), items.map((x) => x.src.label).join(', ') + ' · refresh', sharedOrigin(ids), Object.keys(notes).length ? { notes } : undefined); }
|
|
417
487
|
catch (e) { r = { ok: false, error: String((e && e.message) || e) }; }
|
|
418
488
|
for (const x of items) {
|
|
419
489
|
if (!expect.has(x.src.id)) continue;
|
|
420
490
|
expect.delete(x.src.id);
|
|
421
491
|
const t = now(); const run = R.newRun(x.src.id, t); const cur = R.readState(dir);
|
|
422
|
-
cur[x.src.id] = { ...(cur[x.src.id]
|
|
492
|
+
cur[x.src.id] = { ...R.marked(cur[x.src.id], x.svcs && Object.keys(x.svcs).length < R.TOOL_SVCS.length ? null : x.slot, x.svcs), waiting_since: null, waiting_for: [], pending: null, last_result: 'failed' };
|
|
423
493
|
R.writeState(dir, cur);
|
|
424
494
|
R.append(dir, { source: x.src.id, ws, ev: 'start', run, trigger: x.trigger, shared: ids }, t);
|
|
425
495
|
R.append(dir, { source: x.src.id, ws, ev: 'end', run, result: 'failed', took_ms: 0, error: (r && r.error) || 'could not start' }, t);
|
|
@@ -428,15 +498,18 @@ function create(host) {
|
|
|
428
498
|
}
|
|
429
499
|
/** What /api/sources shows per source: the repair view, keyed by the lib/freshness.js id. */
|
|
430
500
|
const healView = () => H.viewAll(dir);
|
|
431
|
-
function start(src, ws, { trigger, slot, note }) {
|
|
432
|
-
expect.set(src.id, { trigger, slot, note });
|
|
501
|
+
function start(src, ws, { trigger, slot, note, svcs }) {
|
|
502
|
+
expect.set(src.id, { trigger, slot, note, svcs });
|
|
503
|
+
const n = R.hasSvcs(src) ? svcNote(svcList(svcs)) : null;
|
|
504
|
+
const label = R.hasSvcs(src) && n ? svcList(svcs).map((x) => R.SVC_BY_ID.get(x).label).join(', ') : src.label;
|
|
433
505
|
let r;
|
|
434
|
-
try { r = host.startSkill(ws, src.skill, `${
|
|
506
|
+
try { r = n ? host.startSkill(ws, src.skill, `${label} · refresh`, 'refresh:' + src.id, { notes: { [src.skill]: n } }) : host.startSkill(ws, src.skill, `${label} · refresh`, 'refresh:' + src.id); }
|
|
507
|
+
catch (e) { r = { ok: false, error: String((e && e.message) || e) }; }
|
|
435
508
|
if (expect.has(src.id)) {
|
|
436
509
|
// Nothing started (no session was made): write it as a failed run so it shows, and keep the slot so it is not tried every minute.
|
|
437
510
|
expect.delete(src.id);
|
|
438
511
|
const t = now(); const run = R.newRun(src.id, t); const cur = R.readState(dir);
|
|
439
|
-
cur[src.id] = { ...(cur[src.id]
|
|
512
|
+
cur[src.id] = { ...R.marked(cur[src.id], svcs && Object.keys(svcs).length < R.TOOL_SVCS.length ? null : slot, svcs && !Array.isArray(svcs) ? svcs : null), waiting_since: null, waiting_for: [], pending: null, last_result: 'failed' };
|
|
440
513
|
R.writeState(dir, cur);
|
|
441
514
|
R.append(dir, { source: src.id, ws, ev: 'start', run, trigger }, t);
|
|
442
515
|
R.append(dir, { source: src.id, ws, ev: 'end', run, result: 'failed', took_ms: 0, error: (r && r.error) || 'could not start' }, t);
|
|
@@ -454,7 +527,7 @@ function create(host) {
|
|
|
454
527
|
}
|
|
455
528
|
|
|
456
529
|
/* ── presses ── */
|
|
457
|
-
function runNow(id, { ws, withInputs } = {}) {
|
|
530
|
+
function runNow(id, { ws, withInputs, svcs } = {}) {
|
|
458
531
|
const src = R.BY_ID.get(id);
|
|
459
532
|
if (!src) return { ok: false, status: 400, error: 'source must be one of ' + R.SOURCES.map((x) => x.id).join(', ') };
|
|
460
533
|
const set = settings(); const t = now();
|
|
@@ -470,7 +543,14 @@ function create(host) {
|
|
|
470
543
|
}
|
|
471
544
|
if (src.run === 'skill') {
|
|
472
545
|
const state = R.readState(dir);
|
|
473
|
-
|
|
546
|
+
// Your tools: a press for some services starts beside a run that reads others
|
|
547
|
+
const want = R.hasSvcs(src) && Array.isArray(svcs) && svcs.length ? svcs.filter((x) => R.SVC_BY_ID.has(x)) : null;
|
|
548
|
+
if (want && !want.length) return { ok: false, status: 400, error: 'svcs must name services of ' + R.TOOL_SVCS.map((x) => x.id).join(', ') };
|
|
549
|
+
if (running(state[id]) && (!want || want.some((x) => busySvcs(state[id]).includes(x)))) return { ok: false, status: 409, error: `${want ? want.map((x) => R.SVC_BY_ID.get(x).label).join(', ') : src.label} is already refreshing` };
|
|
550
|
+
if (want) {
|
|
551
|
+
const r = start(src, ws || (set.sources[id] && set.sources[id].ws) || host.homeWs(), { trigger: 'pressed', svcs: want });
|
|
552
|
+
return r.ok ? { ok: true, source: id, started: 'session', session: r.session, svcs: want, inputs: startedInputs } : { ok: false, status: r.status || 500, error: r.error };
|
|
553
|
+
}
|
|
474
554
|
const busy = src.uses.filter((u) => ['running', 'waiting', 'due'].includes(inputStateFn(set, state, t)(u)));
|
|
475
555
|
if (busy.length) {
|
|
476
556
|
state[id] = { ...(state[id] || {}), pending: { trigger: 'pressed', at: t, ws: ws || null }, waiting_since: t, waiting_for: busy };
|
|
@@ -487,9 +567,42 @@ function create(host) {
|
|
|
487
567
|
if (!r || !r.ok) { expect.delete(id); return { ok: false, status: (r && r.status) || 409, error: (r && r.error) || 'it could not start' }; }
|
|
488
568
|
return { ok: true, source: id, started: r.started || 'job', ...(r.session ? { session: r.session } : {}), inputs: startedInputs };
|
|
489
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* Stop and read again (batch 31 item 6): end the open runs of source `id` as stopped by you, close their sessions, and start the same
|
|
572
|
+
* reads once more. → { ok, stopped: n, again } | { ok: false, status, error }
|
|
573
|
+
*/
|
|
574
|
+
function stopAndRead(id, { ws, again = true } = {}) {
|
|
575
|
+
const src = R.BY_ID.get(id);
|
|
576
|
+
if (!src || src.run !== 'skill') return { ok: false, status: 400, error: 'source must be one of ' + R.SOURCES.filter((x) => x.run === 'skill').map((x) => x.id).join(', ') };
|
|
577
|
+
const st0 = R.readState(dir)[id];
|
|
578
|
+
const open = Object.entries(openOf(st0));
|
|
579
|
+
if (!open.length) return { ok: false, status: 409, error: `${src.label} is not reading now` };
|
|
580
|
+
const svcs = new Set(); let all = false;
|
|
581
|
+
for (const [sid, o] of open) {
|
|
582
|
+
if (Array.isArray(o.svcs) && o.svcs.length < R.TOOL_SVCS.length) o.svcs.forEach((x) => svcs.add(x)); else all = true;
|
|
583
|
+
ended({ id: sid, ws: ws || null }, { result: 'interrupted', error: 'Stopped by you' });
|
|
584
|
+
try { if (host.stopSession) host.stopSession(sid); } catch (e) { warn('stop a read', e); }
|
|
585
|
+
}
|
|
586
|
+
if (!again) return { ok: true, stopped: open.length, again: null };
|
|
587
|
+
const r = runNow(id, { ws, svcs: R.hasSvcs(src) && !all ? [...svcs] : undefined });
|
|
588
|
+
return { ok: true, stopped: open.length, again: r.ok ? { ok: true, session: r.session || null, waiting: r.waiting || null } : { ok: false, error: r.error } };
|
|
589
|
+
}
|
|
490
590
|
function setSource(id, patch) {
|
|
491
591
|
const src = R.BY_ID.get(id);
|
|
492
592
|
if (!src) return { ok: false, error: 'source must be one of ' + R.SOURCES.map((x) => x.id).join(', ') };
|
|
593
|
+
// batch 31 item 6: the rhythm of one service of Your tools; null follows the rhythm of Your tools again
|
|
594
|
+
if (patch.svc !== undefined) {
|
|
595
|
+
if (!R.hasSvcs(src) || !R.SVC_BY_ID.has(String(patch.svc))) return { ok: false, error: 'svc must be one of ' + R.TOOL_SVCS.map((x) => x.id).join(', ') + ' (of tools)' };
|
|
596
|
+
let ns = null;
|
|
597
|
+
if (patch.schedule !== null) { const n = R.normalize(src, patch.schedule); if (!n.ok) return n; ns = n.s; }
|
|
598
|
+
const set = R.readSettings(dir); const cur = set.sources[id];
|
|
599
|
+
cur.svc = { ...(cur.svc || {}) };
|
|
600
|
+
if (ns) cur.svc[patch.svc] = ns; else delete cur.svc[patch.svc];
|
|
601
|
+
R.writeSettings(dir, set);
|
|
602
|
+
const st = R.readState(dir); const sl = R.lastSlot(ns || cur.s, now(), win(), busyDay);
|
|
603
|
+
st[id] = { ...(st[id] || {}), svc_slot: { ...((st[id] || {}).svc_slot || {}), [patch.svc]: sl != null ? sl : now() } }; R.writeState(dir, st);
|
|
604
|
+
return { ok: true, source: id, svc: patch.svc };
|
|
605
|
+
}
|
|
493
606
|
if (patch.on !== undefined && typeof patch.on !== 'boolean') return { ok: false, error: 'on must be true or false' };
|
|
494
607
|
let norm = null;
|
|
495
608
|
if (patch.schedule !== undefined) { norm = R.normalize(src, patch.schedule); if (!norm.ok) return norm; }
|
|
@@ -502,8 +615,17 @@ function create(host) {
|
|
|
502
615
|
if (id === 'repo' && typeof patch.on === 'boolean') { try { host.setRepoWatch(patch.on); } catch (e) { warn('repository watch', e); } }
|
|
503
616
|
R.writeSettings(dir, set);
|
|
504
617
|
// A schedule change starts the clock from now: a slot that passed before the change is not run late.
|
|
505
|
-
if (norm && id !== 'daycheck') {
|
|
506
|
-
|
|
618
|
+
if (norm && id !== 'daycheck') {
|
|
619
|
+
const st = R.readState(dir); const sl = R.lastSlot(norm.s, now(), win(), busyDay); st[id] = { ...(st[id] || {}), last_slot: sl, retry_at: null };
|
|
620
|
+
// the services that follow Your tools start their clock from now too
|
|
621
|
+
if (R.hasSvcs(src)) { const own = cur.svc || {}; const ss = { ...(st[id].svc_slot || {}) }; for (const x of R.TOOL_SVCS) if (!own[x.id]) ss[x.id] = sl != null ? sl : now(); st[id].svc_slot = ss; }
|
|
622
|
+
R.writeState(dir, st);
|
|
623
|
+
}
|
|
624
|
+
if (patch.on === true && src.run === 'skill') {
|
|
625
|
+
const st = R.readState(dir); const sl = R.lastSlot(cur.s, now(), win(), busyDay); st[id] = { ...(st[id] || {}), last_slot: sl };
|
|
626
|
+
if (R.hasSvcs(src)) st[id].svc_slot = Object.fromEntries(R.svcSchedules(cur).map((x) => { const l = R.lastSlot(x.s, now(), win(), busyDay); return [x.id, l != null ? l : now()]; }));
|
|
627
|
+
R.writeState(dir, st);
|
|
628
|
+
}
|
|
507
629
|
return { ok: true, source: id };
|
|
508
630
|
}
|
|
509
631
|
function setRules(patch) {
|
|
@@ -595,10 +717,11 @@ function create(host) {
|
|
|
595
717
|
function rowsFor(ws, set, t) {
|
|
596
718
|
const state = R.readState(dir);
|
|
597
719
|
const view = {};
|
|
598
|
-
for (const [k, v] of Object.entries(state)) view[k] =
|
|
720
|
+
for (const [k, v] of Object.entries(state)) view[k] = viewOf(v);
|
|
599
721
|
let fr = []; try { fr = host.freshRows(ws) || []; } catch { fr = []; }
|
|
600
722
|
const fresh = new Map(fr.filter((x) => FRESH_OF[x.id]).map((x) => [x.id, x]));
|
|
601
|
-
return R.rowsOf({ now: t, settings: set, state: view, log: log(), fresh, win: win(), busyDay, quiet: quiet(), jobSchedule: host.jobSchedule || null, ws
|
|
723
|
+
return R.rowsOf({ now: t, settings: set, state: view, log: log(), fresh, win: win(), busyDay, quiet: quiet(), jobSchedule: host.jobSchedule || null, ws,
|
|
724
|
+
svcReads: () => svcReads(ws), stallOf: (id) => stallOf(id, state, t) });
|
|
602
725
|
}
|
|
603
726
|
function rows(ws) { const set = settings(); return { rules: set.rules, quiet: quiet(), window: win(), rows: rowsFor(ws, set, now()) }; }
|
|
604
727
|
/** What lib/freshness.js shows as a skill's schedule, now that the schedule lives here. */
|
|
@@ -606,17 +729,35 @@ function create(host) {
|
|
|
606
729
|
const id = R.SKILL_OF.get(skill); if (!id) return null;
|
|
607
730
|
const set = settings(); const x = set.sources[id]; const st = R.readState(dir)[id] || {};
|
|
608
731
|
const l = log().lastRun(id);
|
|
609
|
-
const
|
|
610
|
-
const
|
|
732
|
+
const src = R.BY_ID.get(id);
|
|
733
|
+
const next = x.on ? R.nextOf(src, x, now(), win(), busyDay) : null;
|
|
734
|
+
// the services of Your tools, from this source's state only (this runs for every /api/sources row, so it reads no other source)
|
|
735
|
+
let svcRow = null;
|
|
736
|
+
if (R.hasSvcs(src) && x.on) {
|
|
737
|
+
const f = log(); const t0 = now(); const lastStart = l && l.start_at ? Date.parse(l.start_at) : NaN;
|
|
738
|
+
const skipped = (slot) => (f.runs(id, 5) || []).some((y) => y.result === 'skipped' && Date.parse(y.start_at) >= slot);
|
|
739
|
+
svcRow = { schedule: x.s, svcs: R.svcRows(src, x, viewOf(st), { now: t0, win: win(), busyDay, lastStart, skipped, reads: svcReads(null), busy: running(st) || !!st.pending || !!st.waiting_since }) };
|
|
740
|
+
}
|
|
741
|
+
const stall = running(st) ? stallOf(id, R.readState(dir), now()) : null;
|
|
742
|
+
const missed = svcRow ? (svcRow.missed_at ? Date.parse(svcRow.missed_at) : null) : x.on ? R.missedSlot(x.s, now(), win(), { lastStart: l && l.start_at ? Date.parse(l.start_at) : NaN, running: running(st) || !!st.pending || !!st.waiting_since, busyDay,
|
|
611
743
|
handled: st.last_slot, skipped: (slot) => log().runs(id, 5).some((y) => y.result === 'skipped' && Date.parse(y.start_at) >= slot) }) : null;
|
|
612
744
|
// batch 31 item 2: `refresh` names the Settings › Connectors item page; `missed_at` turns the row line amber and shows ↻
|
|
613
745
|
return { refresh: id, cadence: x.on ? R.textOf(x.s) : 'off', time: null, day: null, next_run: next ? new Date(next).toISOString() : null, missed_at: missed ? new Date(missed).toISOString() : null,
|
|
614
746
|
last_run: l ? l.start_at : null, last_status: l ? (l.result === 'failed' ? 'fail' : l.result === 'done' ? 'ok' : 'started') : st.last_result || null,
|
|
615
747
|
checked_at: st.seen && st.seen.at ? new Date(st.seen.at).toISOString() : null,
|
|
616
|
-
same_since: st.seen && st.seen.since && st.seen.at > st.seen.since ? new Date(st.seen.since).toISOString() : null
|
|
748
|
+
same_since: st.seen && st.seen.since && st.seen.at > st.seen.since ? new Date(st.seen.since).toISOString() : null,
|
|
749
|
+
...(svcRow ? { cadence: svcCadence(svcRow), svcs: svcRow.svcs.map((v) => ({ id: v.id, label: v.label, own: v.own, cadence: v.on ? R.textOf(v.schedule) : 'off', next_run: v.next_at, missed_at: v.missed_at, reading: v.reading,
|
|
750
|
+
last_at: v.last ? v.last.at : null, last_state: v.last ? v.last.state : null, last_why: v.last ? v.last.why : null })) } : {}),
|
|
751
|
+
...(stall ? { stall: { why: stall.why, fix: stall.fix, kind: stall.kind, since: stall.since, session: stall.session, ...(stall.svcs ? { svcs: stall.svcs } : {}) } } : {}) };
|
|
752
|
+
}
|
|
753
|
+
/** The rhythm line of Your tools when its services differ: "Every hour; Slack every 15 min; Figma daily at 09:00" (shortest first). */
|
|
754
|
+
function svcCadence(row) {
|
|
755
|
+
const own = (row.svcs || []).filter((x) => x.own);
|
|
756
|
+
if (!own.length) return R.textOf(row.schedule);
|
|
757
|
+
return R.textOf(row.schedule) + '; ' + own.map((x) => x.label + ' ' + R.textOf(x.schedule).replace(/, working hours only/, '').replace(/^Every/, 'every').replace(/^Daily/, 'daily').replace(/^Only when you press Refresh/, 'only when you press')).join('; ');
|
|
617
758
|
}
|
|
618
759
|
|
|
619
|
-
return { heal: healView, tick, started, ended, briefDone, codeRun, jobGate, runNow, refreshAll, allState, derived, setSource, setRules, ensureOn, rows, settings, log, scheduleOfSkill, managedSkill: (skill) => R.SKILL_OF.get(skill) || null };
|
|
760
|
+
return { heal: healView, tick, started, ended, briefDone, codeRun, jobGate, runNow, stopAndRead, refreshAll, allState, derived, setSource, setRules, ensureOn, rows, settings, log, scheduleOfSkill, managedSkill: (skill) => R.SKILL_OF.get(skill) || null };
|
|
620
761
|
}
|
|
621
762
|
|
|
622
|
-
module.exports = { create, sourcesOfOrigin, sharedOrigin };
|
|
763
|
+
module.exports = { create, sourcesOfOrigin, sharedOrigin, svcNote, READ_MS };
|
package/workspace/lib/refresh.js
CHANGED
|
@@ -99,6 +99,16 @@ const SOURCES = Object.freeze([
|
|
|
99
99
|
const BY_ID = new Map(SOURCES.map((s) => [s.id, s]));
|
|
100
100
|
const SKILL_OF = new Map(SOURCES.filter((s) => s.skill).map((s) => [s.skill, s.id]));
|
|
101
101
|
const usedBy = (id) => SOURCES.filter((s) => s.uses.includes(id)).map((s) => s.id);
|
|
102
|
+
/* batch 31 item 6 (Wawan 2026-11-18, "A build"): Your tools is one row per service, each with its own rhythm. `reads` names the
|
|
103
|
+
* lib/source-reads.js records the service saves. A service without its own rhythm follows the rhythm of Your tools. Services due at
|
|
104
|
+
* the same minute still share one session; Jira mentions are read with every run of Your tools. */
|
|
105
|
+
const TOOL_SVCS = Object.freeze([
|
|
106
|
+
{ id: 'mail', label: 'Mail', reads: ['mail'] }, { id: 'slack', label: 'Slack', reads: ['slack'] }, { id: 'wispr', label: 'Wispr Flow', reads: ['wispr'] },
|
|
107
|
+
{ id: 'confluence', label: 'Confluence', reads: ['confluence'] }, { id: 'github', label: 'GitHub', reads: ['github'] }, { id: 'drive', label: 'Drive', reads: ['drive'] },
|
|
108
|
+
{ id: 'figma', label: 'Figma', reads: ['figma'] }, { id: 'website', label: 'Your websites', reads: ['website', 'web'] },
|
|
109
|
+
]);
|
|
110
|
+
const SVC_BY_ID = new Map(TOOL_SVCS.map((x) => [x.id, x]));
|
|
111
|
+
const hasSvcs = (src) => !!src && src.id === 'tools';
|
|
102
112
|
|
|
103
113
|
// batch 18 items 7 + 9: the quick reads moved to "often, in working hours". A schedule still on its default from before (OLD_DEFS) moves to
|
|
104
114
|
// the new default once; the `cadence` mark is then saved with the settings, so a schedule the PM picks after this release stays as picked.
|
|
@@ -229,6 +239,11 @@ function withDefaults(raw) {
|
|
|
229
239
|
const n = src.run === 'skill' && x.s ? normalize(src, x.s) : null;
|
|
230
240
|
if (n && n.ok && !(r.cadence >= CADENCE) && sameSchedule(n.s, OLD_DEFS[src.id])) n.ok = false; // an old default moves to the new one (above)
|
|
231
241
|
sources[src.id] = { on, s: n && n.ok ? n.s : (src.def ? { ...src.def, ...(src.def.times ? { times: src.def.times.slice() } : {}) } : null), ws: typeof x.ws === 'string' ? x.ws : null };
|
|
242
|
+
if (hasSvcs(src)) {
|
|
243
|
+
const svc = {};
|
|
244
|
+
for (const [k, v] of Object.entries(x.svc && typeof x.svc === 'object' ? x.svc : {})) { if (!SVC_BY_ID.has(k)) continue; const m = normalize(src, v); if (m.ok) svc[k] = m.s; }
|
|
245
|
+
sources[src.id].svc = svc;
|
|
246
|
+
}
|
|
232
247
|
}
|
|
233
248
|
const rules = { ...RULE_DEFAULTS };
|
|
234
249
|
const rr = r.rules || {};
|
|
@@ -306,6 +321,52 @@ function refreshFirst(src, ctx) {
|
|
|
306
321
|
});
|
|
307
322
|
}
|
|
308
323
|
|
|
324
|
+
/* ── the services of Your tools ── */
|
|
325
|
+
/** The rhythm of each service: its own, or the rhythm of Your tools. → [{ id, label, s, own }] */
|
|
326
|
+
function svcSchedules(set) {
|
|
327
|
+
const own = (set && set.svc) || {};
|
|
328
|
+
return TOOL_SVCS.map((x) => ({ id: x.id, label: x.label, s: own[x.id] || (set && set.s) || null, own: !!own[x.id] }));
|
|
329
|
+
}
|
|
330
|
+
/** The slot a service last ran for: its own mark, else the mark of Your tools. */
|
|
331
|
+
const svcMark = (st, id) => (st && st.svc_slot && Number.isFinite(st.svc_slot[id]) ? st.svc_slot[id] : st && st.last_slot != null ? st.last_slot : null);
|
|
332
|
+
/**
|
|
333
|
+
* Is `src` due, and for which slot? → { slot, svcs } | null. For most sources: its last slot, when the state's last_slot is older.
|
|
334
|
+
* For Your tools: the services whose own last slot is newer than their mark, less the services a run is reading now (`busy`), and
|
|
335
|
+
* the newest of those slots. `svcs` maps each due service to its slot.
|
|
336
|
+
*/
|
|
337
|
+
function dueOf(src, set, st, now, win, busyDay, busy) {
|
|
338
|
+
st = st || {};
|
|
339
|
+
if (!hasSvcs(src)) {
|
|
340
|
+
const slot = lastSlot(set.s, now, win, busyDay);
|
|
341
|
+
if (slot == null || (st.last_slot != null && st.last_slot >= slot)) return null;
|
|
342
|
+
return { slot, svcs: null };
|
|
343
|
+
}
|
|
344
|
+
const svcs = {}; let slot = null;
|
|
345
|
+
for (const x of svcSchedules(set)) {
|
|
346
|
+
if (busy && busy.includes(x.id)) continue;
|
|
347
|
+
const l = lastSlot(x.s, now, win, busyDay);
|
|
348
|
+
if (l == null) continue;
|
|
349
|
+
const m = svcMark(st, x.id);
|
|
350
|
+
if (m != null && m >= l) continue;
|
|
351
|
+
svcs[x.id] = l; if (slot == null || l > slot) slot = l;
|
|
352
|
+
}
|
|
353
|
+
return slot == null ? null : { slot, svcs };
|
|
354
|
+
}
|
|
355
|
+
/** The next slot of `src`: for Your tools, the soonest of its services. */
|
|
356
|
+
function nextOf(src, set, now, win, busyDay) {
|
|
357
|
+
if (!hasSvcs(src)) return nextSlot(set.s, now, win, busyDay);
|
|
358
|
+
let n = null;
|
|
359
|
+
for (const x of svcSchedules(set)) { const v = nextSlot(x.s, now, win, busyDay); if (v != null && (n == null || v < n)) n = v; }
|
|
360
|
+
return n;
|
|
361
|
+
}
|
|
362
|
+
/** The state after a run (or a skip) for `slot` and, for Your tools, its services. */
|
|
363
|
+
function marked(st, slot, svcs) {
|
|
364
|
+
const out = { ...(st || {}) };
|
|
365
|
+
if (slot != null) out.last_slot = slot;
|
|
366
|
+
if (svcs && Object.keys(svcs).length) out.svc_slot = { ...(out.svc_slot || {}), ...svcs };
|
|
367
|
+
return out;
|
|
368
|
+
}
|
|
369
|
+
|
|
309
370
|
/* ── the decision ── */
|
|
310
371
|
/**
|
|
311
372
|
* What the tick should do for skill source `src` now. → { act: 'start'|'skip'|'wait'|'none', trigger?, slot?, why?, note? }
|
|
@@ -317,7 +378,8 @@ function decide(src, st, ctx) {
|
|
|
317
378
|
const set = ctx.settings.sources[src.id];
|
|
318
379
|
const now = ctx.now; const rules = ctx.rules;
|
|
319
380
|
st = st || {};
|
|
320
|
-
|
|
381
|
+
// Your tools: while a run reads some services, the other services that come due start a run of their own (a stuck read holds back only its services)
|
|
382
|
+
if (st.running && (!hasSvcs(src) || st.pending || !set || !set.on)) return { act: 'none', why: 'running' };
|
|
321
383
|
if (!set || !set.on) {
|
|
322
384
|
if (st.pending) return gateInputs(src, st, ctx, { trigger: st.pending.trigger || 'pressed', pressed: true });
|
|
323
385
|
return { act: 'none', why: 'off' };
|
|
@@ -325,29 +387,30 @@ function decide(src, st, ctx) {
|
|
|
325
387
|
// A pressed refresh that waits for its inputs.
|
|
326
388
|
if (st.pending) return gateInputs(src, st, ctx, { trigger: st.pending.trigger || 'pressed', pressed: true });
|
|
327
389
|
// A retry of a failed run.
|
|
328
|
-
if (st.retry_at && now >= st.retry_at) return gateInputs(src, st, ctx, { trigger: 'retry', slot: st.last_slot || null });
|
|
329
|
-
const
|
|
330
|
-
if (
|
|
331
|
-
|
|
390
|
+
if (st.retry_at && now >= st.retry_at && !st.running) return gateInputs(src, st, ctx, { trigger: 'retry', slot: st.last_slot || null, svcs: st.retry_svcs || null });
|
|
391
|
+
const due = dueOf(src, set, st, now, ctx.win, ctx.busyDay, st.busy_svcs);
|
|
392
|
+
if (!due) return { act: 'none', why: st.running ? 'running' : 'done' };
|
|
393
|
+
const slot = due.slot, svcs = due.svcs;
|
|
332
394
|
// A slot from before the last start (a run pressed after it) is done too.
|
|
333
|
-
if (st.started_at && st.started_at >= slot && !st.waiting_since) return { act: 'skip', slot, why: 'already refreshed after this slot', quiet: true };
|
|
395
|
+
if (st.started_at && st.started_at >= slot && !st.waiting_since && !st.running) return { act: 'skip', slot, svcs, why: 'already refreshed after this slot', quiet: true };
|
|
334
396
|
const late = now - slot > LATE_MS;
|
|
335
397
|
if (late && !st.waiting_since) {
|
|
336
|
-
if (!rules.catchup) return { act: 'skip', slot, why: 'PMOS was closed at ' + hm(slot) + ', and catch-up is off' };
|
|
337
|
-
if (inQuiet(now, ctx.quiet)) return { act: 'skip', slot, why: 'missed at ' + hm(slot) + ', and it is quiet hours now' };
|
|
338
|
-
return gateInputs(src, st, ctx, { trigger: 'catch-up', slot });
|
|
398
|
+
if (!rules.catchup) return { act: 'skip', slot, svcs, why: 'PMOS was closed at ' + hm(slot) + ', and catch-up is off' };
|
|
399
|
+
if (inQuiet(now, ctx.quiet)) return { act: 'skip', slot, svcs, why: 'missed at ' + hm(slot) + ', and it is quiet hours now' };
|
|
400
|
+
return gateInputs(src, st, ctx, { trigger: 'catch-up', slot, svcs });
|
|
339
401
|
}
|
|
340
|
-
if (inQuiet(now, ctx.quiet) && !st.waiting_since) return { act: 'skip', slot, why: 'quiet hours' };
|
|
341
|
-
return gateInputs(src, st, ctx, { trigger: 'schedule', slot });
|
|
402
|
+
if (inQuiet(now, ctx.quiet) && !st.waiting_since) return { act: 'skip', slot, svcs, why: 'quiet hours' };
|
|
403
|
+
return gateInputs(src, st, ctx, { trigger: 'schedule', slot, svcs });
|
|
342
404
|
}
|
|
343
|
-
function gateInputs(src, st, ctx, { trigger, slot, pressed }) {
|
|
405
|
+
function gateInputs(src, st, ctx, { trigger, slot, pressed, svcs }) {
|
|
344
406
|
const busy = src.uses.filter((id) => ['running', 'due', 'waiting'].includes(ctx.inputState(id)));
|
|
407
|
+
const sv = svcs ? { svcs } : {};
|
|
345
408
|
if (busy.length) {
|
|
346
409
|
const since = st.waiting_since || ctx.now;
|
|
347
|
-
if (ctx.now - since < WAIT_MS) return { act: 'wait', trigger, slot, waiting: busy, since };
|
|
348
|
-
return startOrHold(ctx, { act: 'start', trigger, slot, pressed, note: 'Waited 30 min for ' + busy.map(labelOf).join(', ') + ', then ran without it' });
|
|
410
|
+
if (ctx.now - since < WAIT_MS) return { act: 'wait', trigger, slot, waiting: busy, since, ...sv };
|
|
411
|
+
return startOrHold(ctx, { act: 'start', trigger, slot, pressed, note: 'Waited 30 min for ' + busy.map(labelOf).join(', ') + ', then ran without it', ...sv });
|
|
349
412
|
}
|
|
350
|
-
return startOrHold(ctx, { act: 'start', trigger, slot, pressed });
|
|
413
|
+
return startOrHold(ctx, { act: 'start', trigger, slot, pressed, ...sv });
|
|
351
414
|
}
|
|
352
415
|
function startOrHold(ctx, d) {
|
|
353
416
|
if (!d.pressed && ctx.runningCount >= Number(ctx.rules.max || 3)) return { ...d, act: 'wait', why: 'the run limit', waiting: [] };
|
|
@@ -404,10 +467,15 @@ function rowsOf(opts) {
|
|
|
404
467
|
else if (fr && fr.state === 'stale') stateName = 'old';
|
|
405
468
|
else if (!lastAt) stateName = 'never';
|
|
406
469
|
else stateName = staleOf(src, set, lastAt, now, win, busyDay) ? 'old' : 'recent';
|
|
407
|
-
const next = set.on && src.run === 'skill' ?
|
|
470
|
+
const next = set.on && src.run === 'skill' ? nextOf(src, set, now, win, busyDay) : null;
|
|
408
471
|
const lastStart = last && last.start_at ? Date.parse(last.start_at) : NaN;
|
|
409
472
|
const skipped = (slot) => (log.runs(src.id, 5) || []).some((x) => x.result === 'skipped' && Date.parse(x.start_at) >= slot);
|
|
410
|
-
const
|
|
473
|
+
const busyNow = stateName === 'running' || stateName === 'waiting';
|
|
474
|
+
const svcs = hasSvcs(src) ? svcRows(src, set, st, { now, win, busyDay, log, lastStart, skipped, reads: opts.svcReads ? opts.svcReads() : {}, busy: busyNow }) : null;
|
|
475
|
+
let missed = null;
|
|
476
|
+
if (svcs) { for (const x of svcs) if (x.missed_at && (missed == null || Date.parse(x.missed_at) > missed)) missed = Date.parse(x.missed_at); }
|
|
477
|
+
else if (set.on && src.run === 'skill') missed = missedSlot(set.s, now, win, { lastStart, running: busyNow, busyDay, handled: st.last_slot, skipped });
|
|
478
|
+
const stall = stateName === 'running' && opts.stallOf ? opts.stallOf(src.id) : null;
|
|
411
479
|
return {
|
|
412
480
|
id: src.id, label: src.label, group: src.group, ic: src.ic, run: src.run, how: src.how, what: src.what, uses: src.uses.slice(), used_by: usedBy(src.id), impact: src.impact,
|
|
413
481
|
on: set.on, schedule: src.run === 'skill' || src.id === 'daycheck' ? set.s : null, default: src.def || null, ws: set.ws,
|
|
@@ -421,7 +489,9 @@ function rowsOf(opts) {
|
|
|
421
489
|
missed_at: missed ? new Date(missed).toISOString() : null,
|
|
422
490
|
propose: proposalOf(src, set, now, busyDay),
|
|
423
491
|
waiting_for: st.waiting_for || [],
|
|
424
|
-
runs: log.runs(src.id, 5),
|
|
492
|
+
runs: log.runs(src.id, hasSvcs(src) ? 20 : 5),
|
|
493
|
+
...(svcs ? { svcs } : {}),
|
|
494
|
+
...(stall ? { stall } : {}),
|
|
425
495
|
};
|
|
426
496
|
});
|
|
427
497
|
// What each source was built on: an input that is failed, old or off now (R5, R9).
|
|
@@ -432,6 +502,23 @@ function rowsOf(opts) {
|
|
|
432
502
|
}
|
|
433
503
|
return rows;
|
|
434
504
|
}
|
|
505
|
+
/**
|
|
506
|
+
* One row per service of Your tools (batch 31 item 6): its rhythm (own, or that of Your tools), next slot, missed slot, last read
|
|
507
|
+
* and whether a run reads it now. `reads` maps a service id to { at, state, why } from its stored read.
|
|
508
|
+
*/
|
|
509
|
+
function svcRows(src, set, st, { now, win, busyDay, lastStart, skipped, reads, busy }) {
|
|
510
|
+
const reading = Array.isArray(st.busy_svcs) ? st.busy_svcs : [];
|
|
511
|
+
return svcSchedules(set).map((x) => {
|
|
512
|
+
const r = (reads && reads[x.id]) || null;
|
|
513
|
+
const on = !!set.on && !!x.s;
|
|
514
|
+
const run = reading.includes(x.id);
|
|
515
|
+
const next = on ? nextSlot(x.s, now, win, busyDay) : null;
|
|
516
|
+
const missed = on && !run ? missedSlot(x.s, now, win, { lastStart, running: run || (busy && !reading.length), busyDay, handled: svcMark(st, x.id), skipped }) : null;
|
|
517
|
+
return { id: x.id, label: x.label, own: x.own, schedule: x.s, schedule_text: textOf(x.s), on, reading: run,
|
|
518
|
+
next_at: next ? new Date(next).toISOString() : null, missed_at: missed ? new Date(missed).toISOString() : null,
|
|
519
|
+
last: r ? { at: r.at || null, state: r.state || null, why: r.why || null } : null };
|
|
520
|
+
});
|
|
521
|
+
}
|
|
435
522
|
/** Old: no refresh since the slot before the last one (a skill source), or older than a day (a job). */
|
|
436
523
|
function staleOf(src, set, lastAt, now, win, busyDay) {
|
|
437
524
|
const t = Date.parse(lastAt); if (!Number.isFinite(t)) return false;
|
|
@@ -513,7 +600,7 @@ function foldLines(lines) {
|
|
|
513
600
|
if (l.ev === 'skip') { const r = { run: l.run || 'skip-' + l.at, source: l.source, ws: l.ws || null, trigger: l.trigger || 'schedule', start_at: l.at, end_at: l.at, result: 'skipped', note: l.note || null, error: null }; byRun.set(r.run, r); order.push(r.run); continue; }
|
|
514
601
|
let r = byRun.get(l.run);
|
|
515
602
|
if (!r) { r = { run: l.run, source: l.source, ws: l.ws || null, trigger: l.trigger || null, start_at: null, end_at: null, result: null }; byRun.set(l.run, r); order.push(l.run); }
|
|
516
|
-
if (l.ev === 'start') { r.start_at = l.at; r.trigger = l.trigger || r.trigger; r.inputs = l.inputs || null; r.note = l.note || r.note || null; r.session = l.session || null; }
|
|
603
|
+
if (l.ev === 'start') { r.start_at = l.at; r.trigger = l.trigger || r.trigger; r.inputs = l.inputs || null; r.note = l.note || r.note || null; r.session = l.session || null; if (Array.isArray(l.svcs)) r.svcs = l.svcs; }
|
|
517
604
|
if (l.ev === 'end') { r.end_at = l.at; r.result = l.result || 'done'; r.took_ms = l.took_ms != null ? l.took_ms : (r.start_at ? Date.parse(l.at) - Date.parse(r.start_at) : null); r.got = l.got || null; r.error = l.error || null; if (l.copy) r.copy = l.copy; if (l.note) r.note = l.note; }
|
|
518
605
|
}
|
|
519
606
|
const runs = order.map((id) => byRun.get(id));
|
|
@@ -571,6 +658,6 @@ function toCsv(runs) {
|
|
|
571
658
|
|
|
572
659
|
module.exports = {
|
|
573
660
|
SOURCES, BY_ID, SKILL_OF, SKILL_KINDS, EVERY, WAIT_MS, LATE_MS, FIRST_MS, RULE_DEFAULTS, RULE_OPTS,
|
|
574
|
-
BUSY_MEETINGS, usedBy, normalize, normalizeRules, withDefaults, migrate, retireLegacy, refreshFirst, lastSlot, nextSlot, missedSlot, proposalOf, slotsOfDay, inWindow, inQuiet, decide, jobGate, sourceOfOrigin, rowsOf, textOf,
|
|
661
|
+
BUSY_MEETINGS, TOOL_SVCS, SVC_BY_ID, hasSvcs, svcSchedules, svcRows, svcMark, dueOf, nextOf, marked, usedBy, normalize, normalizeRules, withDefaults, migrate, retireLegacy, refreshFirst, lastSlot, nextSlot, missedSlot, proposalOf, slotsOfDay, inWindow, inQuiet, decide, jobGate, sourceOfOrigin, rowsOf, textOf,
|
|
575
662
|
files, readSettings, writeSettings, readState, writeState, newRun, append, readLog, foldLog, keepCopy, prune, toCsv,
|
|
576
663
|
};
|
|
@@ -67,6 +67,7 @@ const MODULES = Object.freeze([
|
|
|
67
67
|
'routes-initiative-premium', // briefing-premium-initiative: the premium initiative page's model from the Initiatives sheet's own routes (read-only)
|
|
68
68
|
'routes-initiative-layout', // premium-uncovered-features (Initiative): Moves on by itself, held stages, task groups and saved group sets (page press; file mode)
|
|
69
69
|
'routes-board-publish', // board-publish slice 2 (D103): publish a board to the central host, republish, turn off (page press; the host is never given a way in)
|
|
70
|
+
'routes-relay', // event-relay (D110): Settings › Connectors › Listening: set up, show steps, stop, pull now (page press; an event only starts a read)
|
|
70
71
|
'routes-programs', // program-hierarchy: programs above initiatives across products, their members, tasks and milestones (page press; file mode)
|
|
71
72
|
'routes-brief-page', // console3 Briefing as the brief: Today agenda, Needs you and Mentions (read-only; writes go through routes-pm-items)
|
|
72
73
|
'routes-mentions', // console3 Briefing Mentions: the PM's read marks (page press only)
|