neurastream 0.2.32 → 0.2.33
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/README.md +2 -2
- package/package.json +1 -1
- package/src/adapters/omp/sessions.ts +74 -8
- package/src/core/agent-score.ts +25 -1
- package/src/core/owner-ui.ts +72 -10
- package/src/core/queue/lib.ts +51 -5
- package/templates/AGENTS.md +1 -0
- package/templates/queue/TEMPLATE.md +2 -0
package/README.md
CHANGED
|
@@ -104,7 +104,7 @@ Owner rule: never write a plan when another agent is doing the research or readi
|
|
|
104
104
|
|
|
105
105
|
## Queue holds
|
|
106
106
|
|
|
107
|
-
A plan parked for the owner has one line: `WAITING on owner: <what
|
|
107
|
+
A plan parked for the owner has one line: `WAITING on owner: <what to do> — blocked: <what stays stuck until then> — why you: <why Main cannot do it>` (`blocked` and `why you` may be omitted). That line is the only hold, and only Main writes it (plan-guard refuses subagents). The queue summary shows it as a flag on the plan, cut at 80 characters. Compaction and the rollover handoff read the same lines through `ownerHolds`: the compaction context lists each `<plan file>: WAITING on owner: <text>` line (or `none`) and says any other "needs the owner" or "paused" claim is unverified; the handoff's generated state carries the same lines. Main does not keep holds in a handoff note. A plan header may also carry `Summary: <one or two plain sentences>` under Branch (`templates/queue/TEMPLATE.md`); old plans without it still pass `queue-check`, and the phone page uses that line as the queue card's summary.
|
|
108
108
|
|
|
109
109
|
## Queue priority
|
|
110
110
|
|
|
@@ -118,7 +118,7 @@ One setting decides how much Main does without asking: `autonomy.tier` in the co
|
|
|
118
118
|
|
|
119
119
|
`neurastream ui on --login <tailscale login> [--port N]` does the whole setup in one sentence: it writes `ui.enabled: true` and `ui.owner_login` (plus `ui.port` with `--port`) into `~/.config/neurastream/config.yml` — every other line of the file is kept byte-for-byte — copies `templates/systemd/neurastream-ui.service` to `~/.config/systemd/user/neurastream-ui.service`, runs `systemctl --user daemon-reload`, `enable` and `restart`, then prints the phone link `http://<MagicDNS name>:<port>`. The login must be one the tailnet knows (`tailscale status --json`); when tailscale cannot answer, the check is skipped with a printed warning, never a refusal. `neurastream ui off` stops and disables the unit and sets `ui.enabled: false`, keeping `ui.owner_login` for the next `on`.
|
|
120
120
|
|
|
121
|
-
With `ui.enabled: true` and `ui.owner_login` set (`neurastream config`, `docs/config.md`), `neurastream ui` serves one page bound to this machine's tailnet address only (port `ui.port`, default 7787; `templates/systemd/neurastream-ui.service` runs it as a user unit). A sticky top bar holds the "ns" logo, four pill tabs — Now, Queue, Agents, Spend, each a server-rendered view (`/?tab=…`, an unknown value falls back to Now) — and the lock pill ("🔒 Off" / "🔓 12 min") that opens the guard unlock ("Unlock 15 min", "Unlock 30 min", "Lock now"; when `guards.chat_unlock` is off it says so in plain words with the exact config line). Now is the home tab: a Today tile card over the last 24 h (needs-you count in warn color, list-price spend with a sparkline and the Main/agents split, agent runs with running/died counts and a sparkline, open plans), then one card per open `WAITING on owner:` plan — the plan's `#` title,
|
|
121
|
+
With `ui.enabled: true` and `ui.owner_login` set (`neurastream config`, `docs/config.md`), `neurastream ui` serves one page bound to this machine's tailnet address only (port `ui.port`, default 7787; `templates/systemd/neurastream-ui.service` runs it as a user unit). A sticky top bar holds the "ns" logo, four pill tabs — Now, Queue, Agents, Spend, each a server-rendered view (`/?tab=…`, an unknown value falls back to Now) — and the lock pill ("🔒 Off" / "🔓 12 min") that opens the guard unlock ("Unlock 15 min", "Unlock 30 min", "Lock now"; when `guards.chat_unlock` is off it says so in plain words with the exact config line). Now is the home tab: a Today tile card over the last 24 h (needs-you count in warn color, list-price spend with a sparkline and the Main/agents split, agent runs with running/died counts and a sparkline, open plans), then one card per open `WAITING on owner:` plan that says why it needs him — the plan's `#` title, then Do (what to do), Stuck until then (what stays blocked, including plans this answer unblocks), and Why you (why Main cannot do it), with the goal folded into a Background block. A question ask gets "Yes"/"No"/"Reply…"; a task ask gets "Done". The answer shows as a one-time receipt ("Sent to Main · 08:12"); once the owner inbox already holds an answer for a plan, the card says so ("You answered ‘yes' · 14:19 — Main is on it") with a small change-answer link. The queue is one flat ranked list in `INDEX.md` order. Each card shows the plan title, a two-line summary from the plan's `Summary:` header (one or two plain sentences under Branch; if that line is missing, the first Goal bullet with a leading Owner or INCIDENT prefix cut off), and a status chip — waits you, waits on another plan, not started, phase K of N, or all N done. Drag a card by its ≡ handle, or tap "↑ top"/"↑"/"↓"; the drop rewrites `INDEX.md`, Main gets the move as a message and the page confirms "Moved to #2". Now shows the first 8 rows with a "Show all N ›" link to the Queue tab. The Agents tab lists working-now rows (a run that died before its first reply shows the model from the spawning agent's `model:` frontmatter, never "?"), the agent-score table, open incidents, recent merges/CI and machine health; the Spend tab pairs the spend tile with per-model spend over 24 h. The Now tab also has a "Tell Main" message box for a text note and up to four images; Main receives the text and pictures, and the page keeps a "Sent today" list for 12 hours before removing those messages and their image files. Light and dark follow the OS; there are no external assets and no build step — one server-rendered HTML string, inline CSS and one small inline script under a per-response CSP nonce (`bun scripts/ui-preview.ts <out.html> [--tab <name>]` renders a preview without a server). No chat, no plan editing, no shell.
|
|
122
122
|
|
|
123
123
|
A request is served only when the peer is a tailnet address that is neither loopback nor this machine's own tailnet IP, `tailscale whois` names the `ui.owner_login` login — and the Host header is this machine: the tailnet address or the MagicDNS name, with the served port. The Host check runs on every request before whois, and a POST's Origin must match it, so a DNS-rebinding page (foreign Host, matching Origin, owner's phone) gets a 403 like everyone else. Every request logs one `UI <method> <path> login=<l> → <code>` line to the guard log.
|
|
124
124
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
-
import { basename, join } from "node:path";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
3
|
import type { Config } from "../../core/config.ts";
|
|
4
4
|
import type { MainSession, Run, RunMessage, RunSource, RunStatus, TaskResult } from "../../core/adapter.ts";
|
|
5
5
|
import { nowSec } from "../../core/clock.ts";
|
|
@@ -68,7 +68,54 @@ export function runIdOf(file: string): string {
|
|
|
68
68
|
return /^\d{4}/.test(stem) ? `MAIN ${stem.slice(11, 19)}` : stem;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
function
|
|
71
|
+
function agentsDirOf(root: string, cfg: Config): string {
|
|
72
|
+
return cfg.adapter?.pins || join(dirname(root), "agents");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function frontmatterModel(agent: string, dir: string): string | null {
|
|
76
|
+
let text: string;
|
|
77
|
+
try {
|
|
78
|
+
text = readFileSync(join(dir, `${agent}.md`), "utf8");
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
|
|
83
|
+
const m = /^model:\s*(\S+)/m.exec(fm?.[1] ?? "");
|
|
84
|
+
return m?.[1] ?? null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function spawnedAgent(parentFile: string, stem: string): string | null {
|
|
88
|
+
let text: string;
|
|
89
|
+
try {
|
|
90
|
+
text = readFileSync(parentFile, "utf8");
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
for (const line of text.split("\n")) {
|
|
95
|
+
if (!line.includes(stem)) continue;
|
|
96
|
+
let d: Record<string, unknown> | null;
|
|
97
|
+
try {
|
|
98
|
+
d = asObj(JSON.parse(line) as unknown);
|
|
99
|
+
} catch {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (!d) continue;
|
|
103
|
+
const msg = asObj(d.message) ?? d;
|
|
104
|
+
const content = Array.isArray(msg.content) ? msg.content : [];
|
|
105
|
+
for (const part of content) {
|
|
106
|
+
const call = asObj(part);
|
|
107
|
+
if (!call || call.name !== "task") continue;
|
|
108
|
+
const args = asObj(call.arguments);
|
|
109
|
+
const tasks = args && Array.isArray(args.tasks) ? args.tasks : [];
|
|
110
|
+
for (const item of tasks) {
|
|
111
|
+
const task = asObj(item);
|
|
112
|
+
if (task && task.name === stem && typeof task.agent === "string" && task.agent) return task.agent;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
function build(file: string, cfg: Config, mtime: number, agentsDir: string): Run | null {
|
|
72
119
|
let text: string;
|
|
73
120
|
try {
|
|
74
121
|
text = readFileSync(file, "utf8");
|
|
@@ -78,8 +125,11 @@ function build(file: string, cfg: Config, mtime: number): Run | null {
|
|
|
78
125
|
const stem = basename(file).slice(0, -6);
|
|
79
126
|
const isMain = /^\d{4}/.test(stem);
|
|
80
127
|
const id = runIdOf(file);
|
|
81
|
-
let model = "
|
|
82
|
-
let scoreModel = "
|
|
128
|
+
let model = "unknown";
|
|
129
|
+
let scoreModel = "unknown";
|
|
130
|
+
let sawProviderModel = false;
|
|
131
|
+
let sawAssistant = false;
|
|
132
|
+
let parentSession = "";
|
|
83
133
|
let calls = 0;
|
|
84
134
|
let tokens = 0;
|
|
85
135
|
let cache = 0;
|
|
@@ -122,7 +172,9 @@ function build(file: string, cfg: Config, mtime: number): Run | null {
|
|
|
122
172
|
waiting = data.toolName === "wait" ? `WAITING: ${String(data.intent ?? "").slice(0, 40)}` : "";
|
|
123
173
|
}
|
|
124
174
|
const m = asObj(d.message) ?? d;
|
|
175
|
+
if (d.type === "session" && typeof d.parentSession === "string") parentSession = d.parentSession;
|
|
125
176
|
if (m.role === "assistant") {
|
|
177
|
+
sawAssistant = true;
|
|
126
178
|
exited = false;
|
|
127
179
|
yielded = false;
|
|
128
180
|
const content = Array.isArray(m.content) ? m.content : [];
|
|
@@ -136,6 +188,7 @@ function build(file: string, cfg: Config, mtime: number): Run | null {
|
|
|
136
188
|
if (m.model && m.provider) {
|
|
137
189
|
model = `${m.provider}/${m.model}`;
|
|
138
190
|
scoreModel = model;
|
|
191
|
+
sawProviderModel = true;
|
|
139
192
|
} else if (typeof m.model === "string" && m.model.includes("/")) {
|
|
140
193
|
model = m.model;
|
|
141
194
|
}
|
|
@@ -173,14 +226,27 @@ function build(file: string, cfg: Config, mtime: number): Run | null {
|
|
|
173
226
|
}
|
|
174
227
|
}
|
|
175
228
|
|
|
229
|
+
if (!sawProviderModel && model === "unknown" && !isMain && parentSession) {
|
|
230
|
+
const fromFile = frontmatterModel(spawnedAgent(parentSession, stem) ?? "", agentsDir);
|
|
231
|
+
if (fromFile) {
|
|
232
|
+
model = fromFile;
|
|
233
|
+
scoreModel = fromFile;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
176
237
|
const done = yielded || final;
|
|
238
|
+
const idle = Math.floor((nowSec() - mtime) / 60);
|
|
177
239
|
let state: string;
|
|
178
240
|
if (!id.startsWith("MAIN") && (yielded || final)) state = "done";
|
|
179
241
|
else if (!exited && !err) {
|
|
180
|
-
const idle = Math.floor((nowSec() - mtime) / 60);
|
|
181
242
|
state = (waiting || "RUNNING") + (idle >= cfg.ledger.idle_show_min ? ` (idle ${idle}m)` : "");
|
|
182
243
|
} else if (id.startsWith("MAIN")) state = "done";
|
|
183
244
|
else state = `DIED: ${err || "exited without a result"}`;
|
|
245
|
+
let neverReplied = false;
|
|
246
|
+
if (!isMain && !sawAssistant && state.startsWith("RUNNING") && idle >= cfg.ledger.idle_show_min) {
|
|
247
|
+
state = "DIED: never replied";
|
|
248
|
+
neverReplied = true;
|
|
249
|
+
}
|
|
184
250
|
if ((state.startsWith("RUNNING") || state.startsWith("WAITING")) && !id.startsWith("MAIN")) {
|
|
185
251
|
const cap = readBudgets(cfg.paths.queue_state)[id] ?? cfg.guards.sub_max_calls;
|
|
186
252
|
if (calls > cap) state += ` OVER-BUDGET(${calls}>${cap} calls)`;
|
|
@@ -209,8 +275,8 @@ function build(file: string, cfg: Config, mtime: number): Run | null {
|
|
|
209
275
|
scoreModel,
|
|
210
276
|
scoreCost,
|
|
211
277
|
scoreHours: ((last ?? 0) - (first ?? 0)) / 3600,
|
|
212
|
-
scoreRunning: !exited && !scoreErr && !done,
|
|
213
|
-
scoreSurvived: done && !scoreErr,
|
|
278
|
+
scoreRunning: neverReplied ? false : !exited && !scoreErr && !done,
|
|
279
|
+
scoreSurvived: neverReplied ? false : done && !scoreErr,
|
|
214
280
|
scoreEnd: scoreErr || (done ? "done" : "no final message"),
|
|
215
281
|
};
|
|
216
282
|
return run;
|
|
@@ -271,7 +337,7 @@ export function ompRunSource(root: string, cfg: Config): RunSource {
|
|
|
271
337
|
continue;
|
|
272
338
|
}
|
|
273
339
|
if (mtime < since) continue;
|
|
274
|
-
const run = build(file, cfg, mtime);
|
|
340
|
+
const run = build(file, cfg, mtime, agentsDirOf(root, cfg));
|
|
275
341
|
if (run) runs.push(run);
|
|
276
342
|
}
|
|
277
343
|
return runs;
|
package/src/core/agent-score.ts
CHANGED
|
@@ -215,6 +215,19 @@ function ocRuns(cfg: Config, cut: number): { agent: string; model: string; cost:
|
|
|
215
215
|
return out;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
/** scoreModel of the named sub-run in the score window, else the external-run log's model, else null. */
|
|
219
|
+
function namedRunModel(cfg: Config, source: RunSource, agent: string): string | null {
|
|
220
|
+
const cut = nowSec() - cfg.score.board_days * 86400;
|
|
221
|
+
const sub = source.listRuns(cut).find(r => r.kind === "sub" && r.id === agent);
|
|
222
|
+
if (sub) return sub.scoreModel;
|
|
223
|
+
const oc = ocRuns(cfg, cut).filter(r => r.agent === agent).at(-1);
|
|
224
|
+
return oc ? oc.model : null;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function unnamedRefusal(agent: string): number {
|
|
228
|
+
return exitText(`refused: no run named "${agent}" — use the task name (e.g. NsOneIndex3Glm), not the worker type`);
|
|
229
|
+
}
|
|
230
|
+
|
|
218
231
|
function steering(runs: Run[], names: string[]): Record<string, number> {
|
|
219
232
|
const ordered = names.slice().sort((a, b) => b.length - a.length);
|
|
220
233
|
const out: Record<string, number> = {};
|
|
@@ -419,10 +432,13 @@ export function agentScore(args: string[], cfg: Config, source: RunSource, trace
|
|
|
419
432
|
if (bad.length) return exitText(`refused: not on ${branch} yet (merge first): ${bad.join(" ")}`);
|
|
420
433
|
const { w, src } = weightFor(rest, plan, phase, cfg, null);
|
|
421
434
|
const units = Number(rest.includes("--units") ? needOpt(rest, "--units") : "1");
|
|
435
|
+
const model = namedRunModel(cfg, source, agent);
|
|
436
|
+
if (model === null) return unnamedRefusal(agent);
|
|
422
437
|
record({
|
|
423
438
|
type: "accept", agent, plan, phase, weight: w * units, unit_weight: w, units, weight_src: src,
|
|
424
439
|
repo, branch, commits, rework: rest.includes("--rework"), note: opt(rest, "--note") ?? "",
|
|
425
440
|
...wasteOf(traces, cfg, agent),
|
|
441
|
+
model,
|
|
426
442
|
}, cfg);
|
|
427
443
|
return 0;
|
|
428
444
|
}
|
|
@@ -435,9 +451,12 @@ export function agentScore(args: string[], cfg: Config, source: RunSource, trace
|
|
|
435
451
|
const ev = opt(rest, "--evidence");
|
|
436
452
|
if (!plan || !phase || !ev || !existsSync(ev)) return exitText("diagnose needs --plan, --phase and an existing --evidence file");
|
|
437
453
|
const weighted = rest.includes("--weight") ? weightFor(rest, plan, phase, cfg, cfg.score.diagnose_weight) : { w: cfg.score.diagnose_weight, src: "default" };
|
|
454
|
+
const model = namedRunModel(cfg, source, agent);
|
|
455
|
+
if (model === null) return unnamedRefusal(agent);
|
|
438
456
|
record({
|
|
439
457
|
type: "diagnose", agent, plan, phase, weight: weighted.w, weight_src: weighted.src, evidence: ev, note: opt(rest, "--note") ?? "",
|
|
440
458
|
...wasteOf(traces, cfg, agent),
|
|
459
|
+
model,
|
|
441
460
|
}, cfg);
|
|
442
461
|
return 0;
|
|
443
462
|
}
|
|
@@ -460,10 +479,13 @@ export function agentScore(args: string[], cfg: Config, source: RunSource, trace
|
|
|
460
479
|
if (labels.length === 0) return exitText(`refused: section cites no heavy-run label run by ${agent}`);
|
|
461
480
|
const scored = readEvents(cfg).some(e => (e.type === "accept" || e.type === "validate") && e.agent === agent && e.plan === plan && e.phase === phase);
|
|
462
481
|
if (scored) return exitText("refused: already scored");
|
|
482
|
+
const model = namedRunModel(cfg, source, agent);
|
|
483
|
+
if (model === null) return unnamedRefusal(agent);
|
|
463
484
|
record({
|
|
464
485
|
type: "validate", agent, plan, phase, weight: w, weight_src: src, evidence: ev, section,
|
|
465
486
|
labels, rework: rest.includes("--rework"), note: opt(rest, "--note") ?? "",
|
|
466
487
|
...wasteOf(traces, cfg, agent),
|
|
488
|
+
model,
|
|
467
489
|
}, cfg);
|
|
468
490
|
return 0;
|
|
469
491
|
}
|
|
@@ -475,7 +497,9 @@ export function agentScore(args: string[], cfg: Config, source: RunSource, trace
|
|
|
475
497
|
const note = opt(rest, "--note");
|
|
476
498
|
const kinds = Object.keys(cfg.score.penalties);
|
|
477
499
|
if (!kind || !kinds.includes(kind) || !note) return exitText(`penalty needs --kind ${kinds.join("|")} and --note`);
|
|
478
|
-
|
|
500
|
+
const model = namedRunModel(cfg, source, agent);
|
|
501
|
+
if (model === null) return unnamedRefusal(agent);
|
|
502
|
+
record({ type: "penalty", agent, kind, plan: opt(rest, "--plan") ?? "", note, model }, cfg);
|
|
479
503
|
return 0;
|
|
480
504
|
}
|
|
481
505
|
if (cmd === "exempt") {
|
package/src/core/owner-ui.ts
CHANGED
|
@@ -97,6 +97,14 @@ export interface QuestionRow {
|
|
|
97
97
|
title: string;
|
|
98
98
|
repo: string;
|
|
99
99
|
waitingLine: string;
|
|
100
|
+
/** What to do, from the WAITING line. */
|
|
101
|
+
waitingAsk: string;
|
|
102
|
+
/** What stays stuck until then, or null. */
|
|
103
|
+
waitingBlocked: string | null;
|
|
104
|
+
/** Why Main cannot do it, or null. */
|
|
105
|
+
waitingWhy: string | null;
|
|
106
|
+
/** Titles of other open plans whose Waits on names this plan. */
|
|
107
|
+
unblocks: string[];
|
|
100
108
|
goal: string[];
|
|
101
109
|
waitingMin: number;
|
|
102
110
|
/** The last answer this plan already got (from the owner inbox), so the card can say so. */
|
|
@@ -136,6 +144,10 @@ export interface QueueRow {
|
|
|
136
144
|
title: string;
|
|
137
145
|
status: string;
|
|
138
146
|
waiting: boolean;
|
|
147
|
+
/** `Summary:` header, else the first Goal bullet with a leading Owner/INCIDENT prefix cut off. */
|
|
148
|
+
summary: string | null;
|
|
149
|
+
/** Chip text: waits you, waits on a plan, not started, phase K of N, or all N done. */
|
|
150
|
+
state: string;
|
|
139
151
|
}
|
|
140
152
|
|
|
141
153
|
export interface CiRow {
|
|
@@ -168,7 +180,8 @@ export interface MachineRow {
|
|
|
168
180
|
|
|
169
181
|
export function questionRows(cfg: Config): QuestionRow[] {
|
|
170
182
|
const now = Date.now();
|
|
171
|
-
|
|
183
|
+
const plans = activePlans(cfg.paths.queue_index);
|
|
184
|
+
return plans
|
|
172
185
|
.filter(p => p.waiting && p.status === "open" && p.waitingLine)
|
|
173
186
|
.map(p => {
|
|
174
187
|
let waitingMin = 0;
|
|
@@ -180,6 +193,10 @@ export function questionRows(cfg: Config): QuestionRow[] {
|
|
|
180
193
|
title: p.title,
|
|
181
194
|
repo: basename(p.repo),
|
|
182
195
|
waitingLine: p.waitingLine ?? "",
|
|
196
|
+
waitingAsk: p.waitingAsk ?? p.waitingLine ?? "",
|
|
197
|
+
waitingBlocked: p.waitingBlocked,
|
|
198
|
+
waitingWhy: p.waitingWhy,
|
|
199
|
+
unblocks: plans.filter(o => o.status === "open" && o.file !== p.file && o.waitsOn.includes(p.file)).map(o => o.title),
|
|
183
200
|
goal: p.goal,
|
|
184
201
|
waitingMin,
|
|
185
202
|
answered: lastAnswerFor(p.file),
|
|
@@ -201,10 +218,40 @@ export function agentRows(cfg: Config, source: RunSource): AgentRow[] {
|
|
|
201
218
|
}));
|
|
202
219
|
}
|
|
203
220
|
|
|
221
|
+
/** Cut a leading `Owner (…):` or `INCIDENT <id>` prefix off a Goal bullet used as the card line. */
|
|
222
|
+
function goalSummary(line: string): string {
|
|
223
|
+
let s = line.trim();
|
|
224
|
+
for (;;) {
|
|
225
|
+
const next = s.replace(/^Owner\s*\([^)]*\):\s*/, "").replace(/^INCIDENT\s+\S+\.?\s*/, "").trim();
|
|
226
|
+
if (next === s) return s;
|
|
227
|
+
s = next;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function queueState(p: Plan, plans: Plan[]): string {
|
|
232
|
+
if (p.waiting) return "waits you";
|
|
233
|
+
const target = p.waitsOn[0];
|
|
234
|
+
if (target) {
|
|
235
|
+
const title = plans.find(w => w.file === target)?.title ?? target.split("/").pop()?.replace(/\.md$/, "") ?? target;
|
|
236
|
+
return `waits on ${title}`;
|
|
237
|
+
}
|
|
238
|
+
const { done, total } = p.phases;
|
|
239
|
+
if (done === total && total > 0) return `all ${total} done · checking`;
|
|
240
|
+
if (!p.started) return `not started · 0/${total}`;
|
|
241
|
+
return `phase ${Math.min(done + 1, total)} of ${total}`;
|
|
242
|
+
}
|
|
243
|
+
|
|
204
244
|
export function queueRows(cfg: Config): QueueRow[] {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
245
|
+
const plans = activePlans(cfg.paths.queue_index).filter(p => p.status === "open");
|
|
246
|
+
return plans.map(p => ({
|
|
247
|
+
repo: basename(p.repo),
|
|
248
|
+
file: p.file,
|
|
249
|
+
title: p.title,
|
|
250
|
+
status: p.status ?? "?",
|
|
251
|
+
waiting: p.waiting,
|
|
252
|
+
summary: p.summary ?? (goalSummary(p.goal[0] ?? "") || null),
|
|
253
|
+
state: queueState(p, plans),
|
|
254
|
+
}));
|
|
208
255
|
}
|
|
209
256
|
|
|
210
257
|
export function ciRows(cfg: Config): CiRow[] {
|
|
@@ -426,8 +473,16 @@ ${sent}
|
|
|
426
473
|
|
|
427
474
|
function needCard(row: QuestionRow, i: number, tab: string): string {
|
|
428
475
|
const goals = row.goal.map(g => `<li>${esc(g)}</li>`).join("");
|
|
429
|
-
const wait = row.waitingMin < 60 ? `waiting ${row.waitingMin} min` : `waiting ${Math.max(1, Math.round(row.waitingMin / 60))} h`;
|
|
430
476
|
const bg = row.goal.length ? `<details class="bg" id="bg-${i}"><summary>Background</summary><ul>${goals}</ul></details>` : "";
|
|
477
|
+
const ask = row.waitingAsk || row.waitingLine;
|
|
478
|
+
const parts: string[] = [];
|
|
479
|
+
if (ask) parts.push(`<p class="q"><b>Do</b> ${esc(ask)}</p>`);
|
|
480
|
+
if (row.waitingBlocked || row.unblocks.length) {
|
|
481
|
+
const extra = row.unblocks.length ? `also unblocks: ${row.unblocks.join(", ")}` : "";
|
|
482
|
+
const stuck = [row.waitingBlocked, extra].filter(Boolean).join(" ");
|
|
483
|
+
parts.push(`<p class="q"><b>Stuck until then</b> ${esc(stuck)}</p>`);
|
|
484
|
+
}
|
|
485
|
+
if (row.waitingWhy) parts.push(`<p class="q"><b>Why you</b> ${esc(row.waitingWhy)}</p>`);
|
|
431
486
|
let said = "";
|
|
432
487
|
if (row.answered) {
|
|
433
488
|
const text = row.answered.answer;
|
|
@@ -436,17 +491,23 @@ function needCard(row: QuestionRow, i: number, tab: string): string {
|
|
|
436
491
|
said = `<p class="answered">You ${verb} "${esc(quote)}" · ${esc(strftime(row.answered.at, "%H:%M"))} — Main is on it</p>
|
|
437
492
|
<button type="button" class="replybtn link">change answer</button>`;
|
|
438
493
|
}
|
|
494
|
+
const question = ask.endsWith("?");
|
|
439
495
|
const acts = row.answered
|
|
440
496
|
? said
|
|
441
|
-
:
|
|
497
|
+
: question
|
|
498
|
+
? `<div class="acts">
|
|
442
499
|
<button class="btn pri" type="submit" name="answer" value="yes">Yes</button>
|
|
443
500
|
<button class="btn" type="submit" name="answer" value="no">No</button>
|
|
444
501
|
<button type="button" class="btn replybtn">Reply…</button>
|
|
502
|
+
</div>`
|
|
503
|
+
: `<div class="acts">
|
|
504
|
+
<button class="btn pri" type="submit" name="answer" value="done">Done ✓</button>
|
|
505
|
+
<button type="button" class="btn replybtn">Reply…</button>
|
|
445
506
|
</div>`;
|
|
446
507
|
return `<article class="ask">
|
|
447
|
-
<p class="eyebrow">${esc(row.repo)}
|
|
508
|
+
<p class="eyebrow">${esc(row.repo)}</p>
|
|
448
509
|
<b>${esc(row.title)}</b>
|
|
449
|
-
|
|
510
|
+
${parts.join("\n")}
|
|
450
511
|
${bg}
|
|
451
512
|
<form method="post" action="/answer">
|
|
452
513
|
<input type="hidden" name="plan" value="${esc(row.plan)}">
|
|
@@ -472,8 +533,8 @@ function queueHtml(rows: QueueRow[], tab: string): string {
|
|
|
472
533
|
(r, i) => `<li class="qcard" data-plan="${esc(r.file)}">
|
|
473
534
|
<span class="qhandle" title="Drag to reorder" aria-label="Drag ${esc(r.title)}">≡</span>
|
|
474
535
|
<span class="qrank">${i + 1}</span>
|
|
475
|
-
<span class="qtitle">${esc(r.title)}</span>
|
|
476
|
-
${r.
|
|
536
|
+
<span class="qtitle">${esc(r.title)}${r.summary ? `<span class="qsum">${esc(r.summary)}</span>` : ""}</span>
|
|
537
|
+
<span class="chip ${r.state.startsWith("waits") ? "c-wait" : "c-ready"}">${esc(r.state)}</span>
|
|
477
538
|
<span class="qbtns"><button type="button" class="qmove" data-move="top">↑ top</button><button type="button" class="qmove" data-move="up">↑</button><button type="button" class="qmove" data-move="down">↓</button></span>
|
|
478
539
|
</li>`,
|
|
479
540
|
)
|
|
@@ -954,6 +1015,7 @@ details.bg ul{margin:4px 0 8px;padding-left:20px;color:var(--mut);font-size:13px
|
|
|
954
1015
|
.qhandle{color:var(--mut);font-size:18px;touch-action:none;padding:2px 2px;user-select:none;flex:none}
|
|
955
1016
|
.qrank{color:var(--mut);width:18px;font-size:13px;text-align:right;font-variant-numeric:tabular-nums;flex:none}
|
|
956
1017
|
.qtitle{flex:1 1 12em;min-width:0}
|
|
1018
|
+
.qsum{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;color:var(--mut);font-size:13px;font-weight:400}
|
|
957
1019
|
.chip{font-size:11px;padding:2px 8px;border-radius:999px;white-space:nowrap;flex:none}
|
|
958
1020
|
.c-wait{background:color-mix(in srgb,var(--warn) 18%,transparent);color:var(--warn)}
|
|
959
1021
|
.c-run{background:color-mix(in srgb,var(--teal) 18%,transparent);color:var(--teal)}
|
package/src/core/queue/lib.ts
CHANGED
|
@@ -49,12 +49,24 @@ export interface Plan {
|
|
|
49
49
|
appliesTo: string[];
|
|
50
50
|
waiting: boolean;
|
|
51
51
|
waitingLine: string | null;
|
|
52
|
+
/** What the owner should do. Null when the plan has no WAITING line. */
|
|
53
|
+
waitingAsk: string | null;
|
|
54
|
+
/** What stays stuck until then. Null when the line has no `— blocked:`. */
|
|
55
|
+
waitingBlocked: string | null;
|
|
56
|
+
/** Why Main cannot do it. Null when the line has no `— why you:`. */
|
|
57
|
+
waitingWhy: string | null;
|
|
52
58
|
waitsOn: string[];
|
|
53
59
|
priorityId: string | null;
|
|
54
60
|
/** First level-1 "# " heading in the plan, else the file basename. */
|
|
55
61
|
title: string;
|
|
56
62
|
/** Bullet lines under "## Goal", capped at 6. */
|
|
57
63
|
goal: string[];
|
|
64
|
+
/** Header line `Summary: <text>`, or null when the plan has none. */
|
|
65
|
+
summary: string | null;
|
|
66
|
+
/** Checkbox lines under `## Phases`: done is ticked `[x]`/`[X]`. */
|
|
67
|
+
phases: { done: number; total: number };
|
|
68
|
+
/** True when a phase is ticked, or `## Progress` has a real `- ` entry. */
|
|
69
|
+
started: boolean;
|
|
58
70
|
errors: string[];
|
|
59
71
|
}
|
|
60
72
|
|
|
@@ -117,6 +129,30 @@ export type ProgressTrim = { body: string; moved: string; count: number };
|
|
|
117
129
|
const POINTER_PREFIX = "- Older Progress entries:";
|
|
118
130
|
const MAIN_ONLY_LINE = /^\s*(?:[-*]\s+)?(Status:|WAITING on owner:|Waits on:|Cancelled by owner:|False positive:)/;
|
|
119
131
|
|
|
132
|
+
const WAITING_BLOCKED = " — blocked: ";
|
|
133
|
+
const WAITING_WHY = " — why you: ";
|
|
134
|
+
|
|
135
|
+
/** Split `WAITING on owner:` text. An old one-part line is ask only; a missing part is null. */
|
|
136
|
+
export function splitWaiting(line: string): { ask: string; blocked: string | null; why: string | null } {
|
|
137
|
+
const marks: { at: number; kind: "blocked" | "why"; len: number }[] = [];
|
|
138
|
+
const blockedAt = line.indexOf(WAITING_BLOCKED);
|
|
139
|
+
const whyAt = line.indexOf(WAITING_WHY);
|
|
140
|
+
if (blockedAt >= 0) marks.push({ at: blockedAt, kind: "blocked", len: WAITING_BLOCKED.length });
|
|
141
|
+
if (whyAt >= 0) marks.push({ at: whyAt, kind: "why", len: WAITING_WHY.length });
|
|
142
|
+
marks.sort((a, b) => a.at - b.at);
|
|
143
|
+
if (marks.length === 0) return { ask: line.trim(), blocked: null, why: null };
|
|
144
|
+
let blocked: string | null = null;
|
|
145
|
+
let why: string | null = null;
|
|
146
|
+
for (let i = 0; i < marks.length; i++) {
|
|
147
|
+
const mark = marks[i]!;
|
|
148
|
+
const end = i + 1 < marks.length ? marks[i + 1]!.at : line.length;
|
|
149
|
+
const text = line.slice(mark.at + mark.len, end).trim();
|
|
150
|
+
if (mark.kind === "blocked") blocked = text || null;
|
|
151
|
+
else why = text || null;
|
|
152
|
+
}
|
|
153
|
+
return { ask: line.slice(0, marks[0]!.at).trim(), blocked, why };
|
|
154
|
+
}
|
|
155
|
+
|
|
120
156
|
/** Keep the first `keep` entries (the file lists them newest first) and move the rest. Pure. */
|
|
121
157
|
export function trimProgressBody(body: string, keep: number, pointer: string): ProgressTrim | undefined {
|
|
122
158
|
const lines = body.split("\n").filter(l => !l.startsWith(POINTER_PREFIX));
|
|
@@ -184,7 +220,7 @@ function headerField(text: string, name: string): string | null {
|
|
|
184
220
|
}
|
|
185
221
|
|
|
186
222
|
export function parsePlan(repo: string, file: string, text: string | null, blockersDir = blockersDirPath()): Plan {
|
|
187
|
-
const empty = { repo, file, text: "", status: null, blockers: [], doneCheck: null, worktree: null, branch: null, appliesTo: [], waiting: false, waitingLine: null, waitsOn: [], priorityId: null, title: path.basename(file), goal: [] };
|
|
223
|
+
const empty = { repo, file, text: "", status: null, blockers: [], doneCheck: null, worktree: null, branch: null, appliesTo: [], waiting: false, waitingLine: null, waitingAsk: null, waitingBlocked: null, waitingWhy: null, waitsOn: [], priorityId: null, title: path.basename(file), goal: [], summary: null, phases: { done: 0, total: 0 }, started: false };
|
|
188
224
|
if (text === null) return { ...empty, errors: ["plan file listed in the index does not exist"] };
|
|
189
225
|
const errors: string[] = [];
|
|
190
226
|
const secs = sections(text);
|
|
@@ -208,15 +244,19 @@ export function parsePlan(repo: string, file: string, text: string | null, block
|
|
|
208
244
|
if (!executable(script)) errors.push(`blocker "${ref}": ${script} missing or not executable`);
|
|
209
245
|
blockers.push({ script, args });
|
|
210
246
|
}
|
|
211
|
-
const
|
|
212
|
-
if (secs.has("phases") && !
|
|
213
|
-
for (const p of
|
|
247
|
+
const phaseLines = items(secs.get("phases") ?? "").filter(l => /^\[[ xX]\]/.test(l));
|
|
248
|
+
if (secs.has("phases") && !phaseLines.length) errors.push('"## Phases" needs checkbox lines: "- [ ] P1 <what> — verify: `<command>`"');
|
|
249
|
+
for (const p of phaseLines) if (!/verify:\s*`[^`]+`/.test(p)) errors.push(`phase without "verify: \`<command>\`": ${p.slice(0, 60)}`);
|
|
250
|
+
const phases = { total: phaseLines.length, done: phaseLines.filter(l => /^\[[xX]\]/.test(l)).length };
|
|
251
|
+
const started = phases.done > 0 || progressBody(text).split("\n").some(l => /^- /.test(l) && !l.startsWith(POINTER_PREFIX) && !MAIN_ONLY_LINE.test(l));
|
|
214
252
|
const dc = (secs.get("done check") ?? "").match(/```[a-z]*\n([\s\S]*?)```|`([^`\n]+)`/);
|
|
215
253
|
const doneCheck = dc ? (dc[1] ?? dc[2] ?? "").trim() : null;
|
|
216
254
|
if (secs.has("done check") && !doneCheck) errors.push('"## Done check" needs one command in backticks (exit 0 = done)');
|
|
217
255
|
const bg = (secs.get("background") ?? "").split("\n").filter(l => l.trim()).length;
|
|
218
256
|
if (bg > BACKGROUND_MAX_LINES) errors.push(`"## Background" has ${bg} lines (max ${BACKGROUND_MAX_LINES}); link a separate file for long context`);
|
|
219
257
|
const wt = headerField(text, "Worktree");
|
|
258
|
+
const waitingLine = text.match(/^WAITING on owner:[ \t]*(.*)$/m)?.[1] ?? null;
|
|
259
|
+
const waitingParts = waitingLine === null ? { ask: null, blocked: null, why: null } : splitWaiting(waitingLine);
|
|
220
260
|
return {
|
|
221
261
|
repo,
|
|
222
262
|
file,
|
|
@@ -228,11 +268,17 @@ export function parsePlan(repo: string, file: string, text: string | null, block
|
|
|
228
268
|
branch: headerField(text, "Branch")?.replace(/^-$/, "") || null,
|
|
229
269
|
appliesTo: items(secs.get("applies to") ?? "").map(p => path.resolve(repo, expandHome(p.replace(/`/g, "")))),
|
|
230
270
|
waiting: /^WAITING on owner:/m.test(text),
|
|
231
|
-
waitingLine
|
|
271
|
+
waitingLine,
|
|
272
|
+
waitingAsk: waitingParts.ask,
|
|
273
|
+
waitingBlocked: waitingParts.blocked,
|
|
274
|
+
waitingWhy: waitingParts.why,
|
|
232
275
|
waitsOn: [...text.matchAll(/^[ \t]*(?:[-*][ \t]+)?Waits on:[ \t]*(.+)$/gm)].map(m => m[1]!.trim()),
|
|
233
276
|
priorityId: text.match(/^PRIORITY-ID:\s*`?([A-Z]{2}[0-9]{2})`?/m)?.[1] ?? null,
|
|
234
277
|
title: text.match(/^# (.+)$/m)?.[1]?.trim() || path.basename(file),
|
|
235
278
|
goal: items(secs.get("goal") ?? "").slice(0, 6),
|
|
279
|
+
summary: headerField(text, "Summary"),
|
|
280
|
+
phases,
|
|
281
|
+
started,
|
|
236
282
|
errors,
|
|
237
283
|
};
|
|
238
284
|
}
|
package/templates/AGENTS.md
CHANGED
|
@@ -5,6 +5,7 @@ You are Main, the orchestrator. Main plans, delegates, reviews and lands; implem
|
|
|
5
5
|
## Plans
|
|
6
6
|
- When the owner asks for work in a repo, write the plan to `<main checkout>/docs/plans/` and list its absolute path in the one index `{{AGENT_DIR}}/INDEX.md` (one plan file per line, never a repo directory). One plan = one worktree: the plan's Worktree line names a worktree no other open plan names.
|
|
7
7
|
- INDEX.md order is priority: free agents go to the top plans first. A lower plan goes first only when the higher one says `Waits on: <plan>`, is WAITING on owner, or the brief quotes the owner: `Priority skip: <plan> — owner: "<his words>"`.
|
|
8
|
+
- A hold is one line: `WAITING on owner: <what to do> — blocked: <what stays stuck until then> — why you: <why Main cannot do it>`. The phone page shows those three parts; a missing part is left out.
|
|
8
9
|
- Entering a repo: read its AGENTS.md first.
|
|
9
10
|
- Main writes every plan in `<repo>/docs/plans/`, shaped like `{{AGENT_DIR}}/queue/TEMPLATE.md`. Do the research yourself; never base a plan on another agent's findings.
|
|
10
11
|
- Phase 0 of every plan: blocker scripts that stop the implementer from going against the plan. They must exist before any spawn.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# <short title>
|
|
2
2
|
Worktree: <work root>/<repo>-<topic> (configure paths.work_roots, e.g. {{HOME}}/work)
|
|
3
3
|
Branch: <type>/<topic>
|
|
4
|
+
Summary: <one or two plain sentences: what this plan gives the owner>
|
|
4
5
|
PRIORITY-ID: <optional, e.g. PR01>
|
|
5
6
|
<!-- One plan = one worktree: this file lives in the main checkout (<main checkout>/docs/plans/), never
|
|
6
7
|
inside its worktree, and the main index (paths.queue_index) lists its absolute path, one line per plan. -->
|
|
@@ -32,6 +33,7 @@ PRIORITY-ID: <optional, e.g. PR01>
|
|
|
32
33
|
Status: open
|
|
33
34
|
<!-- The implementer may only append dated entries here: what was done, what was verified (command +
|
|
34
35
|
result), commits, what is next. It never changes the Status line or adds "WAITING on owner".
|
|
36
|
+
A hold is one line: `WAITING on owner: <what to do> — blocked: <what stays stuck until then> — why you: <why Main cannot do it>` (blocked and why you may be omitted).
|
|
35
37
|
Every new entry ends with a Findings line: "Findings: none", or one item per finding (bug,
|
|
36
38
|
workaround, improvement — any repo) with file:line evidence, items separated by ";". Plan-guard
|
|
37
39
|
restores an entry without it, and each item becomes an incident Main must plan or dismiss.
|