create-pmos 0.360.0 → 0.361.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 +13 -13
- package/payload/KIT-VERSION +2 -2
- 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/payload/state/log.md +1 -1
- package/workspace/briefing-premium-sources-test.js +22 -0
- package/workspace/changelog.json +12 -0
- package/workspace/guide/briefing-premium.md +2 -0
- package/workspace/lib/first-input.js +44 -5
- package/workspace/lib/harness-health.js +95 -0
- package/workspace/lib/refresh-run.js +20 -0
- package/workspace/lib/refresh.js +38 -4
- package/workspace/lib/routes-sources.js +4 -2
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/premium-shell.js +12 -3
- package/workspace/public/pm/premium.css +6 -0
- package/workspace/server.js +56 -14
- package/workspace/test-lists/harness-health.json +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.361.0",
|
|
4
4
|
"description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -32,6 +32,18 @@
|
|
|
32
32
|
"audit"
|
|
33
33
|
],
|
|
34
34
|
"pmosChanges": [
|
|
35
|
+
{
|
|
36
|
+
"v": "0.361.0",
|
|
37
|
+
"at": "2026-10-21T00:14:19.012Z",
|
|
38
|
+
"f": 2,
|
|
39
|
+
"prs": [
|
|
40
|
+
{
|
|
41
|
+
"n": 960,
|
|
42
|
+
"t": "The morning brief runs on fresh sources; Sources says whether background work runs",
|
|
43
|
+
"s": "PMOS reads the pane after it presses Enter."
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
},
|
|
35
47
|
{
|
|
36
48
|
"v": "0.360.0",
|
|
37
49
|
"at": "2026-10-20T13:51:06.028Z",
|
|
@@ -279,18 +291,6 @@
|
|
|
279
291
|
"s": "The rows stay as two columns, one row per label, at every width."
|
|
280
292
|
}
|
|
281
293
|
]
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
"v": "0.341.0",
|
|
285
|
-
"at": "2026-10-20T03:46:04.473Z",
|
|
286
|
-
"f": 2,
|
|
287
|
-
"prs": [
|
|
288
|
-
{
|
|
289
|
-
"n": 936,
|
|
290
|
-
"t": "The premium chat panel draws Claude's markdown, hides paste tags and quiets tool lines",
|
|
291
|
-
"s": "Claude's turns render as markdown, the way Claude Code shows them."
|
|
292
|
-
}
|
|
293
|
-
]
|
|
294
294
|
}
|
|
295
295
|
]
|
|
296
296
|
}
|
package/payload/KIT-VERSION
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
kernel-source: pmos@
|
|
2
|
-
assembled: 2026-10-
|
|
1
|
+
kernel-source: pmos@48e14dd7
|
|
2
|
+
assembled: 2026-10-21
|
|
3
3
|
mode: vendor
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Eval calibration log"
|
|
4
4
|
description: "Append-only record of every PM override of an evaluator verdict."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-21T00:14:15Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Health budgets"
|
|
4
4
|
description: "Closed registry of health-budget anchors (D59), edited only by the PM."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-21T00:14:15Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Discoveries and friction log"
|
|
4
4
|
description: "Append-only record of what runs discovered and where the process rubbed."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-21T00:14:15Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/payload/state/log.md
CHANGED
|
@@ -116,6 +116,28 @@ const sh = (cwd, args) => spawnSync('git', args, { cwd, encoding: 'utf8' });
|
|
|
116
116
|
await ctx.close();
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
{ /* harness-health: the background line at the top of Sources, and the chip's dot takes its level */
|
|
120
|
+
const api = (await json('GET', '/api/sources')).body;
|
|
121
|
+
const h = api && api.health;
|
|
122
|
+
ok('H1 GET /api/sources carries the background health: a level, a line and the issues', h && ['ok', 'warn', 'bad'].includes(h.level) && typeof h.line === 'string' && h.line.length > 10 && Array.isArray(h.issues), JSON.stringify(h));
|
|
123
|
+
const shot = process.env.PMOS_SHOT_DIR || '';
|
|
124
|
+
for (const theme of ['light', 'dark']) {
|
|
125
|
+
const { ctx, page, errors } = await open({ theme, w: theme === 'dark' ? 390 : 1280, h: 844 });
|
|
126
|
+
await page.waitForFunction(() => /sdot (ok|warn|bad)/.test((document.querySelector('#srcDot') || {}).className || ''), null, { timeout: 15000 }).catch(() => {});
|
|
127
|
+
const dot = await page.$eval('#srcDot', (e) => e.className);
|
|
128
|
+
if (theme === 'light') await page.click('#srcChip'); else { await page.click('#moreBtn'); await page.click('#srcItem'); }
|
|
129
|
+
await page.waitForSelector('#srcHealth .hline', { timeout: 15000 }).catch(() => {});
|
|
130
|
+
const line = await page.$eval('#srcHealth', (e) => ({ text: e.textContent.trim(), dot: (e.querySelector('.sdot') || {}).className || '', w: Math.round(e.getBoundingClientRect().width), sw: document.documentElement.scrollWidth }));
|
|
131
|
+
if (theme === 'light') {
|
|
132
|
+
ok('H2 Sources opens with the background line on top, in the level\'s colour', line.text.startsWith(h.line.slice(0, 20)) && line.dot === 'sdot ' + (h.level === 'ok' ? 'ok' : h.level), JSON.stringify(line));
|
|
133
|
+
ok('H3 the chip\'s dot is red only when background work stopped', h.level === 'bad' ? dot === 'sdot bad' : dot !== 'sdot bad', dot);
|
|
134
|
+
} else ok('H4 on a phone the line fits: no sideways scroll', line.sw <= 390 && line.w > 0, JSON.stringify(line));
|
|
135
|
+
if (shot) { await sleep(1200); await page.screenshot({ path: path.join(shot, 'sources-health-' + theme + '.png') }); }
|
|
136
|
+
ok('H no page error (' + theme + ')', errors.length === 0, errors.join(' | '));
|
|
137
|
+
await ctx.close();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
119
141
|
{
|
|
120
142
|
const html = await (await fetch(BASE + '/')).text();
|
|
121
143
|
const nonce = (/<meta name="pmos-nonce" content="([^"]*)"/.exec(html) || [])[1] || '';
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.361.0",
|
|
4
|
+
"at": "2026-10-21T00:14:19.012Z",
|
|
5
|
+
"f": 2,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 960,
|
|
9
|
+
"t": "The morning brief runs on fresh sources; Sources says whether background work runs",
|
|
10
|
+
"s": "PMOS reads the pane after it presses Enter."
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
},
|
|
2
14
|
{
|
|
3
15
|
"v": "0.360.0",
|
|
4
16
|
"at": "2026-10-20T13:51:06.028Z",
|
|
@@ -26,6 +26,8 @@ Every premium page has the same top bar. On the left is where you are, then a ro
|
|
|
26
26
|
|
|
27
27
|
**Sources** is a dialog that lists each tracked source (Repository, Initiatives, Calendar, Jira status, My work and Tracker items) with its own state and the time it was last read. Each source except the repository has **Refresh**, and **Refresh all** reads them all again. Slack and email are read as part of My work, so they have no row of their own. A source PMOS does not track has no row: the dialog shows only what PMOS can say it read.
|
|
28
28
|
|
|
29
|
+
The first line of **Sources** says whether PMOS's background work is running. When everything is on time it reads like "Background on · brief 06:52 · sources 06:49": the time today's morning brief was saved and the time of the last source read. It turns orange when something is late, such as a source that missed its scheduled read by more than an hour, or Git sync that keeps failing. It turns red when something stopped: no morning brief 45 minutes after its time, a source whose last run failed, a session whose prompt was typed but not sent, or background checks that stopped. The line gives the reason in plain words, and other problems are listed under it. The Sources dot takes the same colour, and a stop is also added to the bell, once a day. When the morning brief is due, it first refreshes Calendar, Jira and My work if they are more than 2 hours old, then builds from them. It waits for them for at most 30 minutes.
|
|
30
|
+
|
|
29
31
|
**Sessions** lists every running session beside the chat. When a chat dialog is full screen on a desktop, it has three panels: the session list, the conversation and the viewer.
|
|
30
32
|
|
|
31
33
|
- **Groups.** **Goals** holds a chat whose goal is started or waiting on you. **Yours** holds the other sessions you started. **Started by PMOS** holds schedules, the day run, the Driver, the Checker, notes, document syncs and other background runs. A PMOS session shows only when it needs you. The rest fold into one line, "N more working on their own · Show".
|
|
@@ -12,8 +12,17 @@
|
|
|
12
12
|
* lines stay one prompt. Otherwise it is sent as typed text.
|
|
13
13
|
* 3. ENTER: SUBMIT_MS later, Enter alone. A bracketed-paste program that printed nothing after that Enter gets Enter once
|
|
14
14
|
* more after RETRY_MS, because the first one can land while the paste is still being read.
|
|
15
|
+
*
|
|
16
|
+
* THE SCREEN (harness-health, 2026-10-21). "Printed nothing" is not enough: on 2026-10-21 both 06:45 morning briefs sat with
|
|
17
|
+
* their whole prompt in Claude Code's input box, because an Enter that is swallowed still redraws the box. The ready test was
|
|
18
|
+
* also fooled: the shell that starts the agent turns bracketed paste on and goes quiet before Claude Code has drawn its box.
|
|
19
|
+
* Claude Code keeps what was typed while it started and shows it in its box, so a prompt typed early is not lost; only its Enter
|
|
20
|
+
* is. So when the caller passes `screen` (the pane's visible text, from tmux capture-pane), the box is read after the Enter, at
|
|
21
|
+
* each of CHECK_MS. When it still holds the prompt, Enter is pressed again. When it still does after the last check, the
|
|
22
|
+
* delivery ends as 'unsent' so the caller can say so instead of leaving the session idle. Without `screen` (a plain shell, a
|
|
23
|
+
* test) the plan is as before.
|
|
15
24
|
* The clock and the timers are injected, so the plan is tested without waiting. No I/O of its own: it writes only through
|
|
16
|
-
* `write`.
|
|
25
|
+
* `write` and reads only through `screen`.
|
|
17
26
|
*/
|
|
18
27
|
|
|
19
28
|
const MIN_MS = 1200;
|
|
@@ -23,6 +32,7 @@ const MAX_MS = 20000;
|
|
|
23
32
|
const POLL_MS = 200;
|
|
24
33
|
const SUBMIT_MS = 500;
|
|
25
34
|
const RETRY_MS = 1500;
|
|
35
|
+
const CHECK_MS = Object.freeze([4000, 12000]); // after the Enter: read the input box at these delays, Enter again if it still holds the prompt
|
|
26
36
|
const PASTE_ON = '\x1b[?2004h';
|
|
27
37
|
const PASTE_OFF = '\x1b[?2004l';
|
|
28
38
|
|
|
@@ -41,6 +51,22 @@ function ready({ now, t0, lastOutputAt, firstOut }) {
|
|
|
41
51
|
return now - lastOutputAt >= QUIET_MS;
|
|
42
52
|
}
|
|
43
53
|
|
|
54
|
+
const BOX = /^\s*❯(?:\s|$)/;
|
|
55
|
+
const squash = (t) => String(t || '').replace(/\s+/g, '');
|
|
56
|
+
/** The text in the agent's input box: what follows ❯ on the LAST such line of the visible screen, or null when there is no box. */
|
|
57
|
+
function boxText(screen) {
|
|
58
|
+
const lines = String(screen || '').split('\n');
|
|
59
|
+
for (let i = lines.length - 1; i >= 0; i--) if (BOX.test(lines[i])) return lines[i].replace(BOX, '').trim();
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
/** Does the input box still hold (part of) `text`? The box may show the start or, for a long prompt, a later part. Spaces are
|
|
63
|
+
* ignored because the box wraps the prompt at its own width. */
|
|
64
|
+
function stillInBox(screen, text) {
|
|
65
|
+
const b = squash(boxText(screen));
|
|
66
|
+
if (b.length < 8) return false;
|
|
67
|
+
return squash(text).includes(b.slice(0, 40));
|
|
68
|
+
}
|
|
69
|
+
|
|
44
70
|
/** Split a first input into the text and whether it ended with Enter. */
|
|
45
71
|
function splitInput(input) {
|
|
46
72
|
const s = String(input == null ? '' : input);
|
|
@@ -58,6 +84,8 @@ function deliver(s, input, o = {}) {
|
|
|
58
84
|
const now = o.now || (() => Date.now());
|
|
59
85
|
const later = o.setTimeout || setTimeout;
|
|
60
86
|
const done = typeof o.onDone === 'function' ? o.onDone : () => {};
|
|
87
|
+
const screenFn = typeof o.screen === 'function' ? o.screen : null;
|
|
88
|
+
const screen = () => { try { return String(screenFn() || ''); } catch { return ''; } };
|
|
61
89
|
const { text, enter } = splitInput(input);
|
|
62
90
|
if (!s || (!text && !enter)) { done('nothing'); return; }
|
|
63
91
|
const t0 = now();
|
|
@@ -65,6 +93,17 @@ function deliver(s, input, o = {}) {
|
|
|
65
93
|
let firstOut = 0;
|
|
66
94
|
const alive = () => s.pty && s.state !== 'exited';
|
|
67
95
|
const write = (d) => { try { s.pty.write(d); return true; } catch { return false; } };
|
|
96
|
+
// after the Enter: read the box at each CHECK_MS; Enter again while it still holds the prompt
|
|
97
|
+
const check = (i, outcome) => {
|
|
98
|
+
if (!screenFn || !text || i >= CHECK_MS.length) { done(outcome); return; }
|
|
99
|
+
later(() => {
|
|
100
|
+
if (!alive()) { done('gone'); return; }
|
|
101
|
+
if (!stillInBox(screen(), text)) { done(outcome); return; }
|
|
102
|
+
write('\r');
|
|
103
|
+
if (i + 1 < CHECK_MS.length) { check(i + 1, 'resubmitted'); return; }
|
|
104
|
+
later(() => { done(alive() && stillInBox(screen(), text) ? 'unsent' : 'resubmitted'); }, CHECK_MS[0]);
|
|
105
|
+
}, CHECK_MS[i] - (i ? CHECK_MS[i - 1] : 0));
|
|
106
|
+
};
|
|
68
107
|
const tick = () => {
|
|
69
108
|
if (!alive()) { done('gone'); return; }
|
|
70
109
|
if (!firstOut && (s.lastOutputAt || 0) > base) firstOut = s.lastOutputAt;
|
|
@@ -76,14 +115,14 @@ function deliver(s, input, o = {}) {
|
|
|
76
115
|
if (!alive()) { done('gone'); return; }
|
|
77
116
|
const before = s.lastOutputAt || 0;
|
|
78
117
|
write('\r');
|
|
79
|
-
if (!paste) {
|
|
118
|
+
if (!paste) { check(0, 'submitted'); return; }
|
|
80
119
|
later(() => {
|
|
81
|
-
if (alive() && (s.lastOutputAt || 0) <= before) { write('\r');
|
|
82
|
-
|
|
120
|
+
if (alive() && (s.lastOutputAt || 0) <= before) { write('\r'); check(0, 'resubmitted'); return; }
|
|
121
|
+
check(0, 'submitted');
|
|
83
122
|
}, RETRY_MS);
|
|
84
123
|
}, text ? SUBMIT_MS : 0);
|
|
85
124
|
};
|
|
86
125
|
later(tick, POLL_MS);
|
|
87
126
|
}
|
|
88
127
|
|
|
89
|
-
module.exports = { deliver, ready, pasteOn, splitInput, MIN_MS, QUIET_MS, SILENT_MS, MAX_MS, SUBMIT_MS, RETRY_MS };
|
|
128
|
+
module.exports = { deliver, ready, pasteOn, splitInput, boxText, stillInBox, MIN_MS, QUIET_MS, SILENT_MS, MAX_MS, SUBMIT_MS, RETRY_MS, CHECK_MS };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* harness-health.js — one line that says whether PMOS's background work is running (initiative harness-health).
|
|
3
|
+
*
|
|
4
|
+
* of({ now, settings, state, log, briefAt, sessions, lastTick, win }) → { level, line, issues: [{ level, key, text }] } PURE.
|
|
5
|
+
*
|
|
6
|
+
* The PM asked on 2026-10-21 "how do I know the agent harness is working": the morning brief had sat unsent since 06:45 and
|
|
7
|
+
* nothing on any page said so. This reads what the refresh engine already keeps (lib/refresh.js settings, state and log), the
|
|
8
|
+
* day's brief file and the live sessions, and answers with one level:
|
|
9
|
+
* ok every background run is on time. The line names the last brief and the last source read: "Background on · brief 06:52 · sources 06:49".
|
|
10
|
+
* warn something is late: a source missed its slot by more than an hour, or Git sync keeps failing.
|
|
11
|
+
* bad something stopped: the background tick is not running, today's brief is missing 45 minutes after its time, a source's
|
|
12
|
+
* last run failed, or a session's prompt was typed but never sent.
|
|
13
|
+
* Every issue is a plain sentence with a time; `line` is the worst one. Nothing here reads a file or the clock.
|
|
14
|
+
*
|
|
15
|
+
* now ms
|
|
16
|
+
* settings refresh.json, with defaults (lib/refresh.js withDefaults)
|
|
17
|
+
* state refresh-state.json
|
|
18
|
+
* log the folded log (lib/refresh.js foldLog)
|
|
19
|
+
* briefAt ms the brief for today was saved, or 0
|
|
20
|
+
* sessions [{ id, name, origin, state, firstInput: { result } }]: the live sessions
|
|
21
|
+
* lastTick ms of the last background tick, or 0 before the first
|
|
22
|
+
* win the working hours { start, end }
|
|
23
|
+
*/
|
|
24
|
+
const R = require('./refresh.js');
|
|
25
|
+
|
|
26
|
+
const MIN = 60000;
|
|
27
|
+
const TICK_LATE_MS = 5 * MIN; // the background tick runs every minute
|
|
28
|
+
const BRIEF_LATE_MS = 45 * MIN; // a brief takes a few minutes; 45 leaves room for the sources it refreshes first (at most 30)
|
|
29
|
+
const MISSED_MS = 60 * MIN; // a source slot with no run an hour on was missed
|
|
30
|
+
const RANK = { ok: 0, warn: 1, bad: 2 };
|
|
31
|
+
|
|
32
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
33
|
+
const hm = (ms) => { const d = new Date(ms); return pad(d.getHours()) + ':' + pad(d.getMinutes()); };
|
|
34
|
+
const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
|
|
35
|
+
const ms = (iso) => { const t = Date.parse(iso || ''); return Number.isFinite(t) ? t : 0; };
|
|
36
|
+
const sameDay = (a, b) => new Date(a).toDateString() === new Date(b).toDateString();
|
|
37
|
+
|
|
38
|
+
function of({ now, settings, state = {}, log, briefAt = 0, sessions = [], lastTick = 0, win } = {}) {
|
|
39
|
+
const issues = [];
|
|
40
|
+
const add = (level, key, text) => issues.push({ level, key, text });
|
|
41
|
+
const set = settings || R.withDefaults({});
|
|
42
|
+
const runs = (id) => (log ? log.runs(id, 10) : []).filter((r) => r.result !== 'skipped');
|
|
43
|
+
|
|
44
|
+
if (lastTick && now - lastTick > TICK_LATE_MS) add('bad', 'tick', `Background checks stopped at ${hm(lastTick)}. Restart PMOS to start them again.`);
|
|
45
|
+
|
|
46
|
+
for (const s of sessions) {
|
|
47
|
+
if (s.state !== 'exited' && s.firstInput && s.firstInput.result === 'unsent') add('bad', 'unsent:' + s.id, `${clip(s.name, 40)} is idle: its prompt was typed but not sent. Open it and press Enter.`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// today's morning brief
|
|
51
|
+
const bset = set.sources.brief;
|
|
52
|
+
const bslot = bset && bset.on ? R.lastSlot(bset.s, now, win) : null;
|
|
53
|
+
if (bslot != null && sameDay(bslot, now) && !(briefAt && sameDay(briefAt, now)) && now - bslot > BRIEF_LATE_MS) {
|
|
54
|
+
const bst = state.brief || {};
|
|
55
|
+
const open = Object.values(bst.open || {})[0];
|
|
56
|
+
const last = runs('brief').find((r) => ms(r.start_at) >= bslot - MIN);
|
|
57
|
+
let why;
|
|
58
|
+
if (open) why = `Morning brief started at ${hm(open.at)} and has not finished.`;
|
|
59
|
+
else if (bst.waiting_since) why = `Morning brief has waited for its sources since ${hm(bst.waiting_since)}.`;
|
|
60
|
+
else if (last && last.result && last.result !== 'done') why = `Morning brief ${last.result === 'interrupted' ? 'was stopped' : 'failed'} at ${hm(ms(last.end_at))}${last.error ? ': ' + clip(last.error, 90) : '.'}`;
|
|
61
|
+
else why = `Morning brief did not start at ${hm(bslot)}.`;
|
|
62
|
+
add('bad', 'brief', why);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// each skill source: a failed last run, or a slot that passed with no run
|
|
66
|
+
for (const src of R.SOURCES.filter((x) => x.run === 'skill' && x.id !== 'brief')) {
|
|
67
|
+
const x = set.sources[src.id]; if (!x || !x.on) continue;
|
|
68
|
+
const last = runs(src.id)[0];
|
|
69
|
+
if (last && last.end_at && ['failed', 'interrupted'].includes(last.result) && !(state[src.id] || {}).retry_at) {
|
|
70
|
+
add('bad', 'failed:' + src.id, `${src.label} ${last.result === 'interrupted' ? 'was stopped' : 'failed'} at ${hm(ms(last.end_at))}${last.error ? ': ' + clip(last.error, 90) : '.'}`);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const slot = R.lastSlot(x.s, now, win);
|
|
74
|
+
if (slot == null || now - slot < MISSED_MS) continue;
|
|
75
|
+
const st = state[src.id] || {};
|
|
76
|
+
const ran = Math.max(st.started_at || 0, ...runs(src.id).map((r) => ms(r.start_at)));
|
|
77
|
+
if (ran < slot && !Object.keys(st.open || {}).length) add('warn', 'missed:' + src.id, `${src.label} missed its ${hm(slot)} read.`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const sync = runs('sync')[0];
|
|
81
|
+
if (set.sources.sync && set.sources.sync.on && sync && sync.result === 'failed') {
|
|
82
|
+
const gone = /repository '(?:https?:\/\/[^/]+\/)?([^']+?)(?:\.git)?\/?' not found/.exec(sync.error || '');
|
|
83
|
+
add('warn', 'sync', gone ? `Git sync is failing: ${gone[1]} was not found. Check that remote's address or your access.` : `Git sync is failing: ${clip(sync.error || 'see Settings, Data refresh', 90)}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
issues.sort((a, b) => RANK[b.level] - RANK[a.level]);
|
|
87
|
+
const level = issues.length ? issues[0].level : 'ok';
|
|
88
|
+
if (issues.length) return { level, line: issues[0].text, issues };
|
|
89
|
+
const lastBrief = briefAt && sameDay(briefAt, now) ? 'brief ' + hm(briefAt) : 'no brief yet today';
|
|
90
|
+
const reads = R.SOURCES.filter((x) => x.run === 'skill' && x.id !== 'brief').map((x) => runs(x.id).find((r) => r.result === 'done')).filter(Boolean).map((r) => ms(r.end_at));
|
|
91
|
+
const src = reads.length ? 'sources ' + (sameDay(Math.max(...reads), now) ? hm(Math.max(...reads)) : 'read ' + new Date(Math.max(...reads)).toDateString().slice(4, 10)) : 'sources not read yet';
|
|
92
|
+
return { level, line: `Background on · ${lastBrief} · ${src}`, issues };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = { of, TICK_LATE_MS, BRIEF_LATE_MS, MISSED_MS };
|
|
@@ -29,6 +29,7 @@ function create(host) {
|
|
|
29
29
|
const expect = new Map(); // source id → { trigger, note, inputs } for the start the engine itself is making now
|
|
30
30
|
const jobWait = new Map(); // job id → ms it started waiting for an input
|
|
31
31
|
let lastPrune = 0;
|
|
32
|
+
let lastRetire = 0;
|
|
32
33
|
|
|
33
34
|
/* ── settings, with the one-time move of the seed schedules (R3) ── */
|
|
34
35
|
function settings() {
|
|
@@ -41,6 +42,12 @@ function create(host) {
|
|
|
41
42
|
s = R.withDefaults(m.settings);
|
|
42
43
|
} catch (e) { warn('refresh settings (moving the schedules)', e); }
|
|
43
44
|
}
|
|
45
|
+
// harness-health: a schedules.json entry of a managed skill that is still on (another workspace's morning brief) ends here.
|
|
46
|
+
if (s.migrated && now() - lastRetire >= 60000) {
|
|
47
|
+
lastRetire = now();
|
|
48
|
+
try { const r = R.retireLegacy(s, host.schedules.read()); if (r.retired.length) { host.schedules.write(r.schedules); warn('refresh settings', { message: 'ended the old schedules ' + r.retired.join(', ') + ': Settings › Data refresh runs them' }); } }
|
|
49
|
+
catch (e) { warn('refresh settings (ending old schedules)', e); }
|
|
50
|
+
}
|
|
44
51
|
// The day check's minutes have one home: the proactive settings.
|
|
45
52
|
const every = String(((host.proactive() || {}).dayCheck || {}).every || '60');
|
|
46
53
|
s.sources.daycheck.s = { kind: 'every', every: ['30', '60'].includes(every) ? every : '60', work: true };
|
|
@@ -173,6 +180,19 @@ function create(host) {
|
|
|
173
180
|
}
|
|
174
181
|
continue;
|
|
175
182
|
}
|
|
183
|
+
// harness-health: a scheduled run first refreshes its old inputs, then waits for them (the input wait above, at most 30 min).
|
|
184
|
+
if (['schedule', 'catch-up'].includes(d.trigger) && !(cur[src.id] || {}).waiting_since) {
|
|
185
|
+
const f = log();
|
|
186
|
+
const lastDone = (id) => { const runs = f.runs(id, 20) || []; const l = runs.find((r) => r.result === 'done'); return l ? Date.parse(l.end_at || l.start_at) || 0 : 0; };
|
|
187
|
+
const first = R.refreshFirst(src, { now: t, settings: set, inputState: inputStateFn(set, cur, t), lastDone });
|
|
188
|
+
const begun = first.filter((id) => { const x = R.BY_ID.get(id); return start(x, (set.sources[id] && set.sources[id].ws) || ws, { trigger: d.trigger, note: 'Refreshed first, before ' + src.label }).ok; });
|
|
189
|
+
if (begun.length) {
|
|
190
|
+
const nx = R.readState(dir);
|
|
191
|
+
nx[src.id] = { ...(nx[src.id] || {}), waiting_since: t, waiting_for: begun, waiting_why: null };
|
|
192
|
+
R.writeState(dir, nx);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
176
196
|
start(src, ws, { trigger: d.trigger, slot: d.slot, note: d.note });
|
|
177
197
|
}
|
|
178
198
|
if (t - lastPrune > PRUNE_EVERY_MS) {
|
package/workspace/lib/refresh.js
CHANGED
|
@@ -31,13 +31,14 @@ const SKILL_KINDS = Object.freeze(['manual', 'every', 'daily', 'weekdays', 'week
|
|
|
31
31
|
const EVERY = Object.freeze(['15', '30', '60', '120', '240']);
|
|
32
32
|
const WAIT_MS = 30 * 60 * 1000; // a refresh waits at most this long for its inputs
|
|
33
33
|
const LATE_MS = 15 * 60 * 1000; // a slot older than this when first seen was missed (PMOS was closed)
|
|
34
|
+
const FIRST_MS = 2 * 3600 * 1000; // harness-health: a scheduled run first refreshes its skill inputs whose last good read is older than this
|
|
34
35
|
const MAX_TIMES = 4;
|
|
35
36
|
|
|
36
37
|
/* The sources. `fresh` names the lib/freshness.js row whose age and detail this source shares; `copy` names the files a done run keeps. */
|
|
37
38
|
const SOURCES = Object.freeze([
|
|
38
39
|
{ id: 'calendar', label: 'Calendar', group: 'tools', ic: 'cal', run: 'skill', skill: 'calendar-sync', how: 'tool', fresh: 'calendar',
|
|
39
40
|
what: 'Events from your calendars, for Calendar, the phone day, meeting focus and meeting notes.', uses: [],
|
|
40
|
-
impact: 'Calendar, the phone day, meeting focus
|
|
41
|
+
impact: 'Calendar, the phone day, meeting focus, meeting notes and the Briefing\'s Today card show the last import.',
|
|
41
42
|
def: { kind: 'daily', times: ['06:30', '12:30'] } },
|
|
42
43
|
{ id: 'jira', label: 'Jira tickets and sprints', group: 'tools', ic: 'org', run: 'skill', skill: 'jira-sync', how: 'tool', fresh: 'jira', copy: 'jira',
|
|
43
44
|
what: 'The status of every pushed ticket, the active sprints, and each sprint\'s goal and team summary.', uses: [],
|
|
@@ -52,7 +53,7 @@ const SOURCES = Object.freeze([
|
|
|
52
53
|
impact: 'The bi-weekly report says the tracker was not refreshed.',
|
|
53
54
|
def: { kind: 'weekly', day: 'Fri', times: ['15:30'] } },
|
|
54
55
|
{ id: 'brief', label: 'Morning briefing', group: 'pmos', ic: 'sun', run: 'skill', skill: 'morning-brief', how: 'bg',
|
|
55
|
-
what: 'Your Briefing for the day, ranked by what needs you first.', uses: ['mywork'],
|
|
56
|
+
what: 'Your Briefing for the day, ranked by what needs you first. When it is due, the sources it is built on that are older than 2 hours are refreshed first.', uses: ['calendar', 'jira', 'mywork'],
|
|
56
57
|
impact: 'No new Briefing for the day, and the day check has nothing to update.',
|
|
57
58
|
def: { kind: 'daily', times: ['06:45'] } },
|
|
58
59
|
{ id: 'daycheck', label: 'Day check', group: 'pmos', ic: 'clock', run: 'job', how: 'bg',
|
|
@@ -212,6 +213,39 @@ function migrate(settings, schedules, { homeWs } = {}) {
|
|
|
212
213
|
return { settings: next, schedules: list, adopted };
|
|
213
214
|
}
|
|
214
215
|
|
|
216
|
+
/**
|
|
217
|
+
* The schedules.json entries that still run a managed skill after the move (harness-health). migrate() adopted the entries of ONE
|
|
218
|
+
* workspace; an entry of the same skill in another workspace stayed on and kept starting its own run, so two morning briefs started
|
|
219
|
+
* at 06:45 every day, outside the refresh order. Once the settings are migrated, every such entry ends with the same reason.
|
|
220
|
+
* → { schedules, retired: [id] }. Pure: the caller writes the list.
|
|
221
|
+
*/
|
|
222
|
+
function retireLegacy(settings, schedules) {
|
|
223
|
+
const list = (schedules || []).map((x) => ({ ...x }));
|
|
224
|
+
const retired = [];
|
|
225
|
+
if (!settings || !settings.migrated) return { schedules: list, retired };
|
|
226
|
+
for (const x of list) {
|
|
227
|
+
if (x.enabled === false || x.endedReason || !SKILL_OF.has(x.skill)) continue;
|
|
228
|
+
x.enabled = false; x.endedReason = 'Moved to Settings › Data refresh'; x.nextRun = null;
|
|
229
|
+
retired.push(x.id);
|
|
230
|
+
}
|
|
231
|
+
return { schedules: list, retired };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The inputs a scheduled run of `src` refreshes before it starts (harness-health): its skill inputs that are on, not running or
|
|
236
|
+
* waiting, and whose last good read is older than FIRST_MS. The morning brief at 06:45 read calendar, Jira and work assigned to you
|
|
237
|
+
* as they were at 09:00 the day before, because those refresh on their own later times. → [id]
|
|
238
|
+
* ctx { now, settings, inputState(id), lastDone(id) → ms|0 }
|
|
239
|
+
*/
|
|
240
|
+
function refreshFirst(src, ctx) {
|
|
241
|
+
return (src.uses || []).filter((id) => {
|
|
242
|
+
const x = BY_ID.get(id); const set = ctx.settings.sources[id];
|
|
243
|
+
if (!x || x.run !== 'skill' || !set || !set.on) return false;
|
|
244
|
+
if (ctx.inputState(id) !== 'ok') return false;
|
|
245
|
+
return ctx.now - (ctx.lastDone(id) || 0) > FIRST_MS;
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
215
249
|
/* ── the decision ── */
|
|
216
250
|
/**
|
|
217
251
|
* What the tick should do for skill source `src` now. → { act: 'start'|'skip'|'wait'|'none', trigger?, slot?, why?, note? }
|
|
@@ -458,7 +492,7 @@ function toCsv(runs) {
|
|
|
458
492
|
}
|
|
459
493
|
|
|
460
494
|
module.exports = {
|
|
461
|
-
SOURCES, BY_ID, SKILL_OF, SKILL_KINDS, EVERY, WAIT_MS, LATE_MS, RULE_DEFAULTS, RULE_OPTS,
|
|
462
|
-
usedBy, normalize, normalizeRules, withDefaults, migrate, lastSlot, nextSlot, slotsOfDay, inWindow, inQuiet, decide, jobGate, sourceOfOrigin, rowsOf, textOf,
|
|
495
|
+
SOURCES, BY_ID, SKILL_OF, SKILL_KINDS, EVERY, WAIT_MS, LATE_MS, FIRST_MS, RULE_DEFAULTS, RULE_OPTS,
|
|
496
|
+
usedBy, normalize, normalizeRules, withDefaults, migrate, retireLegacy, refreshFirst, lastSlot, nextSlot, slotsOfDay, inWindow, inQuiet, decide, jobGate, sourceOfOrigin, rowsOf, textOf,
|
|
463
497
|
files, readSettings, writeSettings, readState, writeState, newRun, append, readLog, foldLog, keepCopy, prune, toCsv,
|
|
464
498
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/* routes-sources.js — how old each source of a workspace is, and Refresh now (workspace-data-freshness R6, R7).
|
|
3
3
|
*
|
|
4
|
-
* GET /api/sources?ws=<id> → { ok, ws, version, sources: [row] } lib/freshness.js sources()
|
|
4
|
+
* GET /api/sources?ws=<id> → { ok, ws, version, sources: [row], health } lib/freshness.js sources(); health is
|
|
5
|
+
* lib/harness-health.js of(): { level, line, issues } or null
|
|
5
6
|
* POST /api/sources/refresh { ws, source } → { ok, source, started: 'rebuild'|'session', session? }
|
|
6
7
|
* POST /api/sources/watch { ws, on } → { ok, watch } the change detector on or off for this repository
|
|
7
8
|
*
|
|
@@ -28,7 +29,8 @@ async function handle(req, res, url, ctx) {
|
|
|
28
29
|
const w = wsOf(ctx, url.searchParams.get('ws'));
|
|
29
30
|
if (!w) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
|
|
30
31
|
const sources = F.sources({ id: w.id, root: w.root, repoStateDir: repoStateDir(ctx, w) });
|
|
31
|
-
|
|
32
|
+
let health = null; try { health = ctx.health ? ctx.health() : null; } catch { health = null; }
|
|
33
|
+
ctx.json(res, { ok: true, ws: w.id, version: F.versions()[w.id] || 0, sources, health });
|
|
32
34
|
return true;
|
|
33
35
|
}
|
|
34
36
|
if (p !== '/api/sources/refresh' && p !== '/api/sources/watch') return false;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.361.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.361.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/workspace/package.json
CHANGED
|
@@ -102,8 +102,16 @@ function tbDot() {
|
|
|
102
102
|
const d = $('#srcDot'), c = $('#srcChip'); if (!d || !c) return;
|
|
103
103
|
const behind = TB.src && TB.src.ok ? behindOf(lineItems(TB.src.sources)) : [];
|
|
104
104
|
const n = behind.length + TB.gaps, known = TB.src && TB.src.ok;
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
// harness-health: the background line sets the dot first; red when background work stopped, orange when it is late
|
|
106
|
+
const h = known && TB.src.health ? TB.src.health : null;
|
|
107
|
+
d.className = 'sdot ' + (h && h.level === 'bad' ? 'bad' : n || (TB.src && !TB.src.ok) || (h && h.level === 'warn') ? 'warn' : known ? 'ok' : '');
|
|
108
|
+
c.title = [h && h.level !== 'ok' ? h.line : '', TB.src && !TB.src.ok ? 'The sources could not be read' : n ? [behind.length ? behind.map((b) => b.text).join(', ') : '', TB.gaps ? TB.gaps + (TB.gaps === 1 ? ' source this page could not read' : ' sources this page could not read') : ''].filter(Boolean).join(' · ') : known && !(h && h.level !== 'ok') ? 'Every source was read recently' : known ? '' : 'Reading the sources'].filter(Boolean).join(' · ');
|
|
109
|
+
}
|
|
110
|
+
/** The background line at the top of Sources (harness-health): a dot, the line, and any further issues under it. */
|
|
111
|
+
function healthHtml() {
|
|
112
|
+
const h = TB.src && TB.src.ok ? TB.src.health : null; if (!h) return '';
|
|
113
|
+
const more = (h.issues || []).slice(1, 4);
|
|
114
|
+
return `<div class="hline ${esc(h.level)}" role="status"><b><i class="sdot ${h.level === 'bad' ? 'bad' : h.level === 'warn' ? 'warn' : 'ok'}" aria-hidden="true"></i>${esc(h.line)}</b>${more.length ? `<ul>${more.map((i) => `<li>${esc(i.text)}</li>`).join('')}</ul>` : ''}</div>`;
|
|
107
115
|
}
|
|
108
116
|
/** n: how many sources the page itself could not read (its header's missing list). */
|
|
109
117
|
export function setPageGaps(n) { TB.gaps = n || 0; tbDot(); }
|
|
@@ -121,9 +129,10 @@ export async function openSources() {
|
|
|
121
129
|
// the frame is drawn once; a re-read redraws only the rows, the button and the message, so the page's own part (the Briefing's picker) is left alone
|
|
122
130
|
const rowsHtml = () => { const s = TB.src; return !s ? '<p class="note">Reading the sources.</p>' : !s.ok ? '<p class="note err" role="alert">The sources could not be read.</p>' : s.sources.map(srcRow).join(''); };
|
|
123
131
|
const draw = () => {
|
|
124
|
-
if ($('#srcRows')) { $('#srcRows').innerHTML = rowsHtml(); $('#srcAll').disabled = TB.busy; $('#srcM').textContent = TB.msg; return; }
|
|
132
|
+
if ($('#srcRows')) { $('#srcRows').innerHTML = rowsHtml(); $('#srcHealth').innerHTML = healthHtml(); $('#srcAll').disabled = TB.busy; $('#srcM').textContent = TB.msg; return; }
|
|
125
133
|
park();
|
|
126
134
|
$('#oMain').innerHTML = `<article class="paper doc"><div class="addf">
|
|
135
|
+
<div id="srcHealth">${healthHtml()}</div>
|
|
127
136
|
<div class="srctop"><p class="note" style="margin:0">Each source is read on its own schedule, not live. Each row says when it was last read.</p><button type="button" class="cta" id="srcAll"${TB.busy ? ' disabled' : ''}>Refresh all</button></div>
|
|
128
137
|
<div>${TB.extra ? '<span class="label">Sources</span>' : ''}<div id="srcRows">${rowsHtml()}</div></div>
|
|
129
138
|
${TB.extra ? TB.extra.html() : ''}
|
|
@@ -2124,6 +2124,12 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
|
|
|
2124
2124
|
.sdot{width:8px;height:8px;border-radius:50%;background:var(--ink-3);flex:none;display:inline-block}
|
|
2125
2125
|
.sdot.ok{background:var(--ok)}
|
|
2126
2126
|
.sdot.warn{background:var(--ember)}
|
|
2127
|
+
.sdot.bad{background:var(--bad)}
|
|
2128
|
+
.hline{display:flex;flex-direction:column;gap:4px;padding:10px 12px;border-radius:12px;background:var(--well);font-size:var(--fs-2);color:var(--ink)}
|
|
2129
|
+
.hline b{display:inline-flex;align-items:center;gap:8px;font-weight:600}
|
|
2130
|
+
.hline.ok b{font-weight:500;color:var(--ink-2)}
|
|
2131
|
+
.hline ul{margin:0;padding:0 0 0 16px;color:var(--ink-2)}
|
|
2132
|
+
.hline:empty,#srcHealth:empty{display:none}
|
|
2127
2133
|
.sr .sn b{display:inline-flex;align-items:center;gap:8px}
|
|
2128
2134
|
.srctop{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}
|
|
2129
2135
|
.mwrap{position:relative;display:inline-flex}
|
package/workspace/server.js
CHANGED
|
@@ -84,6 +84,7 @@ const scanRunLib = require('./lib/scan-run.js'); // horizon-scan — the watch
|
|
|
84
84
|
const reportFinderLib = require('./lib/report-finder.js'); // report-workspace — the weekly look for the reports the PM already sends
|
|
85
85
|
const refreshLib = require('./lib/refresh.js'); // data-refresh-settings — the sources, their schedules and the refresh log
|
|
86
86
|
const refreshRunLib = require('./lib/refresh-run.js'); // data-refresh-settings — the engine bound to this server (created by the tick below)
|
|
87
|
+
const harnessHealthLib = require('./lib/harness-health.js'); // harness-health — one line on whether the background work runs
|
|
87
88
|
let refreshRun = null;
|
|
88
89
|
const driverRunLib = require('./lib/driver-run.js'); // initiative-driver — wakes, the unblock sweep and the runs, in the 60-second tick
|
|
89
90
|
const headlessLib = require('./lib/headless.js'); // workspace-headless-jobs — which jobs run as `claude -p`, and with which tools
|
|
@@ -2773,6 +2774,36 @@ const coreDocsTick = () => {
|
|
|
2773
2774
|
proSettings, inQuiet: (now, quiet) => proactiveLib.inQuietHours(now, quiet), isLead: (w) => isPlanNeedsTree(w) }, Number.isFinite(t) ? { now: t } : {});
|
|
2774
2775
|
} catch (e) { warnWriteFail('core documents tick', e); }
|
|
2775
2776
|
};
|
|
2777
|
+
/** One needs-you item, so it shows in the bell. */
|
|
2778
|
+
function tellNeed(ws, runId, label, question) {
|
|
2779
|
+
const w = getWs(ws || '') || homeWorkspace(); const nf = w ? needsFileFor(w) : null; if (!nf) return;
|
|
2780
|
+
let needs = []; try { needs = JSON.parse(fs.readFileSync(nf, 'utf8')); } catch { needs = []; }
|
|
2781
|
+
needs.push({ run_id: runId, kind: 'refresh', initiative_id: label, question });
|
|
2782
|
+
fs.writeFileSync(nf, JSON.stringify(needs)); invalidateNeedsAgg(w.id);
|
|
2783
|
+
}
|
|
2784
|
+
// harness-health: one line on whether the background work runs (lib/harness-health.js). GET /api/sources carries it, the Sources
|
|
2785
|
+
// chip's dot takes its colour, and a stop (no brief 45 minutes after its time, a prompt typed but not sent, the tick stopped) is
|
|
2786
|
+
// told once a day in the bell.
|
|
2787
|
+
let lastBgTick = 0;
|
|
2788
|
+
const healthTold = new Set();
|
|
2789
|
+
function harnessHealth(now = Date.now()) {
|
|
2790
|
+
const set = refreshRun.settings();
|
|
2791
|
+
const d = (proSettings() || {}).dayCheck || {};
|
|
2792
|
+
let briefAt = 0; try { briefAt = fs.statSync(path.join(STATE, 'briefs', briefLib.localDate(now) + '.json')).mtimeMs; } catch { /* no brief yet today */ }
|
|
2793
|
+
const live = [...sessions.values()].filter((x) => x.state !== 'exited').map((x) => ({ id: x.id, name: x.name, origin: x.origin, state: x.state, firstInput: x.firstInput || null }));
|
|
2794
|
+
return harnessHealthLib.of({ now, settings: set, state: refreshLib.readState(STATE), log: refreshLib.foldLog(refreshLib.readLog(STATE)), briefAt, sessions: live, lastTick: lastBgTick,
|
|
2795
|
+
win: { start: d.start || '08:00', end: d.end || '18:00' } });
|
|
2796
|
+
}
|
|
2797
|
+
function healthTick(now = Date.now()) {
|
|
2798
|
+
lastBgTick = now;
|
|
2799
|
+
const h = harnessHealth(now);
|
|
2800
|
+
const day = briefLib.localDate(now);
|
|
2801
|
+
for (const i of h.issues) {
|
|
2802
|
+
if (i.level !== 'bad' || !/^(brief|unsent:|tick)/.test(i.key) || healthTold.has(day + i.key)) continue;
|
|
2803
|
+
healthTold.add(day + i.key);
|
|
2804
|
+
tellNeed(null, `health-${i.key}-${now}`, 'Background work', i.text + ' See Sources.');
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2776
2807
|
// data-refresh-settings: the refresh engine. It starts the skill sources that are due (calendar, Jira, work assigned to you, tracker,
|
|
2777
2808
|
// the morning brief), writes the refresh log, and gates the job ticks below: a job that is off, or whose input is still running, waits.
|
|
2778
2809
|
const REFRESH_BOOT = Date.now();
|
|
@@ -2791,12 +2822,7 @@ refreshRun = refreshRunLib.create({
|
|
|
2791
2822
|
if (id === 'jira' && w) { let d = null; try { d = stateDirFor(w); } catch { d = null; } return d ? [path.join(d, 'tracker', 'jira')] : []; }
|
|
2792
2823
|
return [];
|
|
2793
2824
|
},
|
|
2794
|
-
tell: ({ source, label, error, ws }) => {
|
|
2795
|
-
const w = getWs(ws || '') || homeWorkspace(); const nf = w ? needsFileFor(w) : null; if (!nf) return;
|
|
2796
|
-
let needs = []; try { needs = JSON.parse(fs.readFileSync(nf, 'utf8')); } catch { needs = []; }
|
|
2797
|
-
needs.push({ run_id: `refresh-${source}-${Date.now()}`, kind: 'refresh', initiative_id: label, question: `${label} could not refresh: ${String(error).slice(0, 300)} See Settings, Data refresh.` });
|
|
2798
|
-
fs.writeFileSync(nf, JSON.stringify(needs)); invalidateNeedsAgg(w.id);
|
|
2799
|
-
},
|
|
2825
|
+
tell: ({ source, label, error, ws }) => tellNeed(ws, `refresh-${source}-${Date.now()}`, label, `${label} could not refresh: ${String(error).slice(0, 300)} See Settings, Data refresh.`),
|
|
2800
2826
|
setDayCheckEvery: (every) => {
|
|
2801
2827
|
let raw = {}; try { raw = JSON.parse(fs.readFileSync(PRO_SETTINGS(), 'utf8')); } catch { raw = {}; }
|
|
2802
2828
|
const cur = proSettings();
|
|
@@ -2832,7 +2858,7 @@ const gated = (id, fn) => () => { let g = { ok: true }; try { g = refreshRun.job
|
|
|
2832
2858
|
// data-refresh-settings: the seed schedules move to Settings › Data refresh (refreshRun.settings(), once) BEFORE checkDueSchedules reads
|
|
2833
2859
|
// schedules.json, so a schedule that is moving never fires once more from the old list on the first tick after an upgrade.
|
|
2834
2860
|
const scheduleOwner = require('./lib/schedule-owner.js').create({ port: PORT });
|
|
2835
|
-
try { const _tick = setInterval(() => { try { if (!scheduleOwner.mayRun()) return; } catch { /* no lock: run as before */ } try { refreshRun.settings(); } catch { /* the refresh tick tries again */ } checkDueSchedules(); proactiveTick(); try { prepareTick({ manual: false }); } catch { /* the next tick tries again */ } try { dayTick(); } catch (e) { warnWriteFail('day run tick', e); } try { refreshRun.tick(); } catch (e) { warnWriteFail('refresh tick', e); } gated('sync', () => autoSync.tick().catch(() => {}))(); dashboardScheduleTick(); orchTick(); gated('driver', driverTick)(); gated('scan', scanTick)(); gated('finder', reportFinderTick)(); gated('coredocs', coreDocsTick)(); reportDesignTick(); reportStructureTick(); }, TICK_MS); if (_tick.unref) _tick.unref(); } catch {}
|
|
2861
|
+
try { const _tick = setInterval(() => { try { if (!scheduleOwner.mayRun()) return; } catch { /* no lock: run as before */ } try { refreshRun.settings(); } catch { /* the refresh tick tries again */ } checkDueSchedules(); proactiveTick(); try { prepareTick({ manual: false }); } catch { /* the next tick tries again */ } try { dayTick(); } catch (e) { warnWriteFail('day run tick', e); } try { refreshRun.tick(); } catch (e) { warnWriteFail('refresh tick', e); } try { healthTick(); } catch (e) { warnWriteFail('health tick', e); } gated('sync', () => autoSync.tick().catch(() => {}))(); dashboardScheduleTick(); orchTick(); gated('driver', driverTick)(); gated('scan', scanTick)(); gated('finder', reportFinderTick)(); gated('coredocs', coreDocsTick)(); reportDesignTick(); reportStructureTick(); }, TICK_MS); if (_tick.unref) _tick.unref(); } catch {}
|
|
2836
2862
|
|
|
2837
2863
|
// ── Sessions: real PTYs, owned by the server, with disk-backed scrollback + metadata. ──
|
|
2838
2864
|
/** @type {Map<string, {id,ws,name,agent,cwd,state,note,created,pty,buf,cols,rows,clients:Set}>} */
|
|
@@ -3145,6 +3171,22 @@ function paneAsk(s, now = Date.now()) {
|
|
|
3145
3171
|
s.ask = r.status === 0 && r.stdout ? transcript.permissionAsk(r.stdout, scrub) : null;
|
|
3146
3172
|
return s.ask;
|
|
3147
3173
|
}
|
|
3174
|
+
// The pane's visible screen, plain text, or '' (no tmux pane). lib/first-input.js reads Claude Code's input box from it.
|
|
3175
|
+
function paneScreen(s) {
|
|
3176
|
+
if (!s || !s.tmux || !TMUX) return '';
|
|
3177
|
+
const r = tmuxCtl(['capture-pane', '-p', '-t', s.tmux]);
|
|
3178
|
+
return r.status === 0 && r.stdout ? String(r.stdout) : '';
|
|
3179
|
+
}
|
|
3180
|
+
/** Type `input` into session `s` (lib/first-input.js). A Claude Code pane is also read: the prompt is typed once its input box is
|
|
3181
|
+
* drawn, and Enter is pressed again while the box still holds the prompt (harness-health: the 2026-10-21 morning briefs sat
|
|
3182
|
+
* unsent). A prompt that is still not sent is written on the session, so the list and the health line say so. */
|
|
3183
|
+
function deliverInput(s, input) {
|
|
3184
|
+
const screen = s && s.agent === 'claude' && s.tmux && TMUX ? () => paneScreen(s) : null;
|
|
3185
|
+
firstInput.deliver(s, input, { screen, onDone: (why) => {
|
|
3186
|
+
if (why === 'resubmitted' || why === 'unsent') { try { s.firstInput = { result: why, at: Date.now() }; } catch { /* nothing to keep */ } }
|
|
3187
|
+
if (why === 'unsent') { s.note = 'its prompt was typed but not sent'; try { pushSessions(); } catch { /* the next list shows it */ } }
|
|
3188
|
+
} });
|
|
3189
|
+
}
|
|
3148
3190
|
function transcriptHarness(s) {
|
|
3149
3191
|
if (s.state === 'exited') return { missing: { all: 'the session has exited' } };
|
|
3150
3192
|
// A `shell` session is included: the PM launches `claude` INSIDE the default shell pane, so the
|
|
@@ -3784,7 +3826,7 @@ function sendToSession(id, text) {
|
|
|
3784
3826
|
if (!s || !s.pty || s.state === 'exited' || s.agent === 'shell') return false;
|
|
3785
3827
|
const t = String(text == null ? '' : text).replace(/[\r\n]+/g, ' ').trim();
|
|
3786
3828
|
if (!t) return false;
|
|
3787
|
-
try {
|
|
3829
|
+
try { deliverInput(s, safeFirstInput(t) + '\r'); return true; } catch { return false; }
|
|
3788
3830
|
}
|
|
3789
3831
|
|
|
3790
3832
|
/* premium-chat-session: what the premium chat panel needs from the session table. `type` keeps a leading `/`, so a slash command
|
|
@@ -3797,7 +3839,7 @@ const chatSessions = {
|
|
|
3797
3839
|
if (!s || !s.pty || s.state === 'exited') return false;
|
|
3798
3840
|
const t = String(text == null ? '' : text).replace(/[\r\n]+/g, ' ').trim();
|
|
3799
3841
|
if (!t) return false;
|
|
3800
|
-
try {
|
|
3842
|
+
try { deliverInput(s, t + '\r'); return true; } catch { return false; }
|
|
3801
3843
|
},
|
|
3802
3844
|
keys: (id, data) => { const s = sessions.get(String(id || '')); if (!s || !s.pty || s.state === 'exited') return false; try { s.pty.write(String(data)); return true; } catch { return false; } },
|
|
3803
3845
|
// slice 4 (PRD L3): the live chat sessions, so a new one can end the longest idle; busy = working or a permission prompt waits
|
|
@@ -3945,7 +3987,7 @@ function spawnSessionInner({ name, agent, cwd, ws, origin, initialInput, profile
|
|
|
3945
3987
|
// safeFirstInput: a first input that begins with `/` is read by the agent as a slash command, not as the task.
|
|
3946
3988
|
// firstInput.deliver waits until the agent is ready to read, types the prompt, then presses Enter as its own key
|
|
3947
3989
|
// (lib/first-input.js): a burst written at a fixed 700 ms was lost or left unsent while the agent was still starting.
|
|
3948
|
-
const feed = (s) => { if (initialInput && s && s.pty) { try {
|
|
3990
|
+
const feed = (s) => { if (initialInput && s && s.pty) { try { deliverInput(s, safeFirstInput(initialInput)); } catch {} } };
|
|
3949
3991
|
// shell gets a real fallback to `sh`; agent CLIs run as-is (harness untouched), NO fallback —
|
|
3950
3992
|
// falling back from `claude` to `sh` would be a lie.
|
|
3951
3993
|
const cmd = isShell ? (commandExists(SHELL) ? SHELL : 'sh') : agent;
|
|
@@ -4605,7 +4647,7 @@ function startDayTask(run, t, now) {
|
|
|
4605
4647
|
const step = t.mode === 'send' && dayRunLib.stepOf(t);
|
|
4606
4648
|
const prev = !step && t.prev_session && sessions.get(t.prev_session);
|
|
4607
4649
|
if (!sk.error && prev && prev.state !== 'exited' && prev.pty) {
|
|
4608
|
-
try {
|
|
4650
|
+
try { deliverInput(prev, line + '\r'); s = prev; } catch { s = null; }
|
|
4609
4651
|
}
|
|
4610
4652
|
if (!sk.error && !s) {
|
|
4611
4653
|
const prompt = `${sk.prompt}\n\n${line}`;
|
|
@@ -4654,7 +4696,7 @@ function startDayCheck(run, reason, now) {
|
|
|
4654
4696
|
const prev = run.checks.prev_session && sessions.get(run.checks.prev_session);
|
|
4655
4697
|
let s = null;
|
|
4656
4698
|
if (prev && prev.pty && prev.state !== 'exited' && harness.deriveState(prev.state, prev.lastOutputAt, now).state !== 'working') {
|
|
4657
|
-
try {
|
|
4699
|
+
try { deliverInput(prev, line + '\r'); s = prev; } catch { s = null; }
|
|
4658
4700
|
}
|
|
4659
4701
|
if (!s) {
|
|
4660
4702
|
s = spawnSession({ name: 'Daytime check', agent: sk.task.agent || 'claude', ws: sk.w ? sk.w.id : run.ws, origin: 'day-check', initialInput: `${sk.prompt}\n\n${line}\r`,
|
|
@@ -8922,7 +8964,7 @@ async function handleRequest(req, res) {
|
|
|
8922
8964
|
const sk = daySkillPrompt(run, 'morning-brief');
|
|
8923
8965
|
const s = sessions.get(run.brief_session.id);
|
|
8924
8966
|
if (!sk.error) {
|
|
8925
|
-
try {
|
|
8967
|
+
try { deliverInput(s, `${sk.prompt}\n\nThis run: prepare the day again. Read every source again and submit a new brief for today.\r`); } catch { /* typed below as a new session */ }
|
|
8926
8968
|
run.brief_session = { id: s.id, started_at: new Date(pnow).toISOString(), ended_at: null };
|
|
8927
8969
|
writeDayRun(run);
|
|
8928
8970
|
return json(res, { ok: true, started: true, reused: true, session: s.id, run, goals: open.length });
|
|
@@ -9643,7 +9685,7 @@ async function handleRequest(req, res) {
|
|
|
9643
9685
|
else if (x.pty) { if (x.tmux) tmuxKillSession(x.tmux); try { x.pty.kill(); } catch { /* already ended */ } }
|
|
9644
9686
|
},
|
|
9645
9687
|
// workspace-data-freshness: the source table, the facts rebuild and Refresh now's skill sessions
|
|
9646
|
-
freshness, factsRefresh: (root) => factsAsync.refresh(root, { force: true }), startSkill: startSkillSession,
|
|
9688
|
+
freshness, factsRefresh: (root) => factsAsync.refresh(root, { force: true }), startSkill: startSkillSession, health: () => harnessHealth(),
|
|
9647
9689
|
// c3-initiative-boards: the PMOS checkout this server is embedded in, whose default board keeps its derived ladder
|
|
9648
9690
|
selfRoot: EMBEDDED_SELF ? SELF_ROOT : null,
|
|
9649
9691
|
// horizon-scan-portfolio: Scan now, Stop and an approved research proposal start and end runs in the scanner; scanClock fixes its clock in the suites
|