neurastream 0.2.31 → 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/index.ts +55 -0
- package/src/adapters/omp/adapter.ts +28 -0
- package/src/adapters/omp/index.ts +2 -5
- package/src/adapters/omp/launch.ts +9 -8
- package/src/adapters/omp/sessions.ts +78 -12
- package/src/adapters/omp/traces.ts +4 -11
- package/src/cli/commands.ts +8 -7
- package/src/cli/dispatch.ts +3 -4
- package/src/cli/metrics.ts +11 -10
- package/src/cli/pages.ts +2 -2
- package/src/cli/runtime.ts +2 -2
- package/src/cli/traces.ts +19 -17
- package/src/cli/ui.ts +2 -2
- package/src/core/adapter.ts +39 -0
- package/src/core/agent-score.ts +25 -1
- package/src/core/config.ts +3 -0
- package/src/core/owner-ui.ts +72 -10
- package/src/core/queue/lib.ts +51 -5
- package/templates/AGENTS.md +1 -0
- package/templates/config.yml +3 -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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// The one door from src/cli to a harness (plan 20261026_0010 P2). Every adapter import in the
|
|
2
|
+
// CLI goes through this file, and tests/host-neutral.test.ts holds that line. Adding a harness
|
|
3
|
+
// is one folder under src/adapters plus one entry in ADAPTERS below — zero core changes
|
|
4
|
+
// (docs/adapter.md, "Adding a harness").
|
|
5
|
+
|
|
6
|
+
import type { DumpRef, LaunchOptions, RelatedTrace, RunSource, TaskResult, TraceRun, TraceSource } from "../core/adapter.ts";
|
|
7
|
+
import type { Config } from "../core/config.ts";
|
|
8
|
+
import type { DumpParts, DumpTokens } from "../core/trace-bloat.ts";
|
|
9
|
+
import type { SpawnBrief } from "../core/trace-briefs.ts";
|
|
10
|
+
import { ompAdapter } from "./omp/adapter.ts";
|
|
11
|
+
|
|
12
|
+
export interface HarnessAdapter {
|
|
13
|
+
name: string;
|
|
14
|
+
/** Session reader: the runs and the main session (docs/adapter.md). */
|
|
15
|
+
runSource(cfg: Config): RunSource;
|
|
16
|
+
/** Completed subagent task-results announced in the newest main session file. */
|
|
17
|
+
completedResults(cfg: Config): TaskResult[];
|
|
18
|
+
/** TraceSource for agent-score, over the config's sessions root. */
|
|
19
|
+
scoreTraces(cfg: Config): TraceSource;
|
|
20
|
+
/** Every run id with a trace under the root, each mapped to its newest file. */
|
|
21
|
+
traceRuns(root: string): TraceRun[];
|
|
22
|
+
traceSource(root: string): TraceSource;
|
|
23
|
+
/** Read only the session banner at the start of a trace; null means it is unreadable. */
|
|
24
|
+
traceStart(file: string): number | null;
|
|
25
|
+
/** Every failed-request dump under the harness log dir, oldest first. */
|
|
26
|
+
dumps(home: string): DumpRef[];
|
|
27
|
+
/** Model requested by a failed request dump, if the JSON contains one. */
|
|
28
|
+
dumpModel(file: string): string | undefined;
|
|
29
|
+
/** What a dumped request's prompt is made of (src/core/trace-bloat.ts). */
|
|
30
|
+
dumpParts(file: string): DumpParts;
|
|
31
|
+
/** The prompt tokens a dump states itself, when it does. */
|
|
32
|
+
dumpPromptTokens(file: string): DumpTokens | null;
|
|
33
|
+
/** The spawn briefs in one session file. */
|
|
34
|
+
spawnBriefsIn(file: string, runId: string): SpawnBrief[];
|
|
35
|
+
/** The subagent runs of one main run. */
|
|
36
|
+
subagentTraces(root: string, mainRunId: string): RelatedTrace[];
|
|
37
|
+
launchMain(args: string[], cfg: Config, opts?: LaunchOptions): Promise<number>;
|
|
38
|
+
/** `neurastream adapter install <name>` — validates its own args. */
|
|
39
|
+
install(args: string[]): number;
|
|
40
|
+
/** `neurastream doctor`. */
|
|
41
|
+
doctor(): number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const ADAPTERS: Record<string, HarnessAdapter> = {
|
|
45
|
+
[ompAdapter.name]: ompAdapter,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** The adapter the config names (`harness:`; without a config, the shipped default). An unknown
|
|
49
|
+
* name throws, so a typo fails loudly instead of silently reading another harness's files. */
|
|
50
|
+
export function getAdapter(cfg?: Pick<Config, "harness">): HarnessAdapter {
|
|
51
|
+
const name = cfg?.harness ?? "omp";
|
|
52
|
+
const adapter = ADAPTERS[name];
|
|
53
|
+
if (!adapter) throw new Error(`unknown harness "${name}"; known: ${Object.keys(ADAPTERS).join(", ")}`);
|
|
54
|
+
return adapter;
|
|
55
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// The shipped adapter's HarnessAdapter implementation: thin wiring over this folder's readers,
|
|
2
|
+
// launcher, installer and doctor. Only src/adapters may name the harness.
|
|
3
|
+
|
|
4
|
+
import type { HarnessAdapter } from "../index.ts";
|
|
5
|
+
import { runDoctor } from "./doctor.ts";
|
|
6
|
+
import { runAdapterInstall } from "./install.ts";
|
|
7
|
+
import { runMainLauncher } from "./launch.ts";
|
|
8
|
+
import { defaultCompletedResults, defaultRunSource } from "./sessions.ts";
|
|
9
|
+
import { dumpModel, dumpParts, dumpPromptTokens, ompDumps, ompScoreTraces, ompTraceRuns, ompTraceSource, ompTraceStart, spawnBriefsIn, subagentTraces } from "./traces.ts";
|
|
10
|
+
|
|
11
|
+
export const ompAdapter: HarnessAdapter = {
|
|
12
|
+
name: "omp",
|
|
13
|
+
runSource: defaultRunSource,
|
|
14
|
+
completedResults: defaultCompletedResults,
|
|
15
|
+
scoreTraces: ompScoreTraces,
|
|
16
|
+
traceRuns: ompTraceRuns,
|
|
17
|
+
traceSource: ompTraceSource,
|
|
18
|
+
traceStart: ompTraceStart,
|
|
19
|
+
dumps: ompDumps,
|
|
20
|
+
dumpModel,
|
|
21
|
+
dumpParts,
|
|
22
|
+
dumpPromptTokens,
|
|
23
|
+
spawnBriefsIn,
|
|
24
|
+
subagentTraces,
|
|
25
|
+
launchMain: runMainLauncher,
|
|
26
|
+
install: runAdapterInstall,
|
|
27
|
+
doctor: runDoctor,
|
|
28
|
+
};
|
|
@@ -35,6 +35,7 @@ import { mainStartText, runDailyCheck } from "../../core/main-start.ts";
|
|
|
35
35
|
import { readBlocks } from "../../core/metrics.ts";
|
|
36
36
|
import { buildHandoff, holdsBlock, notePath, noteRequest, OWNER_AWAY, ownerText, relaunchPath, rolloverState, spawnRefusal, type RolloverState } from "../../core/rollover.ts";
|
|
37
37
|
import { defaultCompletedResults, defaultRunSource, runIdOf } from "./sessions.ts";
|
|
38
|
+
import { adapterLog } from "./launch.ts";
|
|
38
39
|
import { parseTraceFile } from "./traces.ts";
|
|
39
40
|
import { packageJsonPath, packageVersion } from "./package-root.ts";
|
|
40
41
|
import * as q from "../../core/queue/lib.ts";
|
|
@@ -130,11 +131,7 @@ const PUSH_MERGE = /\bgit\b[^\n;|&]*\bpush\b|\b(glab\s+mr|gh\s+pr)\s+merge\b/;
|
|
|
130
131
|
|
|
131
132
|
// The installed package and its version: see ./package-root.ts.
|
|
132
133
|
|
|
133
|
-
export
|
|
134
|
-
try {
|
|
135
|
-
appendFileSync(cfg.paths.guard_log, `${new Date().toISOString()} ${line}\n`);
|
|
136
|
-
} catch {}
|
|
137
|
-
}
|
|
134
|
+
export { adapterLog };
|
|
138
135
|
|
|
139
136
|
/**
|
|
140
137
|
* Real-time incident detectors (plan 20261022_2330 P3) at Main's prompt and after each Main bash
|
|
@@ -4,18 +4,25 @@
|
|
|
4
4
|
// flags (carriedArgs) and the handoff as its message. Plain `omp` never gets the flag, so it never relaunches.
|
|
5
5
|
|
|
6
6
|
import { spawn } from "node:child_process";
|
|
7
|
-
import { mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { appendFileSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { basename, dirname, join } from "node:path";
|
|
9
|
+
import type { LaunchOptions } from "../../core/adapter.ts";
|
|
9
10
|
import type { Config } from "../../core/config.ts";
|
|
10
11
|
import { mainStartText } from "../../core/main-start.ts";
|
|
11
12
|
import { applyQueueEnv } from "../../core/queue/env.ts";
|
|
12
13
|
import * as q from "../../core/queue/lib.ts";
|
|
13
14
|
import { buildHandoff, holdsBlock, MAX_NOTE_AGE_MS, OWNER_AWAY, relaunchPath } from "../../core/rollover.ts";
|
|
14
15
|
import { PROXY_BIN, proxyOnPath } from "../../core/secret-redact.ts";
|
|
15
|
-
import { adapterLog } from "./index.ts";
|
|
16
16
|
import { PACKAGE_ROOT, packageJsonPath, packageVersion } from "./package-root.ts";
|
|
17
17
|
import { defaultCompletedResults, defaultRunSource } from "./sessions.ts";
|
|
18
18
|
|
|
19
|
+
/** One line in the guard log: the adapter's own trace of what it did (relaunches, detectors). */
|
|
20
|
+
export function adapterLog(cfg: Config, line: string): void {
|
|
21
|
+
try {
|
|
22
|
+
appendFileSync(cfg.paths.guard_log, `${new Date().toISOString()} ${line}\n`);
|
|
23
|
+
} catch {}
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
/** The harness the launcher runs. Tests pass another path through LaunchOptions. */
|
|
20
27
|
export const OMP_BIN = "omp";
|
|
21
28
|
|
|
@@ -111,12 +118,6 @@ function hasPositional(args: string[]): boolean {
|
|
|
111
118
|
return false;
|
|
112
119
|
}
|
|
113
120
|
|
|
114
|
-
export interface LaunchOptions {
|
|
115
|
-
harness?: string;
|
|
116
|
-
/** The main-start text generator for the handoff (default: src/core/main-start.ts). Tests inject a failing one. */
|
|
117
|
-
mainStart?: typeof mainStartText;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
121
|
interface RelaunchRequest {
|
|
121
122
|
previousSessionFile: string;
|
|
122
123
|
notePath: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
import type { MainSession, Run, RunMessage, RunSource, RunStatus } from "../../core/adapter.ts";
|
|
4
|
+
import type { MainSession, Run, RunMessage, RunSource, RunStatus, TaskResult } from "../../core/adapter.ts";
|
|
5
5
|
import { nowSec } from "../../core/clock.ts";
|
|
6
6
|
import { readBudgets } from "../../core/guards.ts";
|
|
7
7
|
import { pyDumps } from "../../core/pyjson.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;
|
|
@@ -312,8 +378,8 @@ export function defaultRunSource(cfg: Config): RunSource {
|
|
|
312
378
|
* wait were invisible here, so D1 never saw them). A line without a readable timestamp is
|
|
313
379
|
* skipped — without one the contradiction grace cannot be aged.
|
|
314
380
|
*/
|
|
315
|
-
export function completedResults(text: string):
|
|
316
|
-
const out:
|
|
381
|
+
export function completedResults(text: string): TaskResult[] {
|
|
382
|
+
const out: TaskResult[] = [];
|
|
317
383
|
for (const line of text.split("\n")) {
|
|
318
384
|
const isAsync = line.includes('"async-result"');
|
|
319
385
|
const isWait = line.includes('"toolName":"wait"');
|
|
@@ -349,7 +415,7 @@ export function completedResults(text: string): { agent: string; ts: number }[]
|
|
|
349
415
|
}
|
|
350
416
|
|
|
351
417
|
/** `completedResults` of the newest Main session file (the one `mainSession()` picks). */
|
|
352
|
-
export function defaultCompletedResults(cfg: Config):
|
|
418
|
+
export function defaultCompletedResults(cfg: Config): TaskResult[] {
|
|
353
419
|
try {
|
|
354
420
|
const s = defaultRunSource(cfg).mainSession();
|
|
355
421
|
return s ? completedResults(readFileSync(s.file, "utf8")) : [];
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { closeSync, openSync, readFileSync, readSync, readdirSync, statSync } from "node:fs";
|
|
9
9
|
import { dirname, join } from "node:path";
|
|
10
10
|
import type { Config } from "../../core/config.ts";
|
|
11
|
-
import type { TraceEvent, TraceSource, TraceUsage } from "../../core/adapter.ts";
|
|
11
|
+
import type { DumpRef, RelatedTrace, TraceEvent, TraceRun, TraceSource, TraceUsage } from "../../core/adapter.ts";
|
|
12
12
|
import type { DumpParts, DumpTokens } from "../../core/trace-bloat.ts";
|
|
13
13
|
import type { SpawnBrief } from "../../core/trace-briefs.ts";
|
|
14
14
|
import { asObj, jsonlAt, parseTs, runIdOf } from "./sessions.ts";
|
|
@@ -135,7 +135,7 @@ export function parseTraceFile(file: string, runId: string): TraceEvent[] {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
/** Every run id with a trace under the root, each mapped to its newest file. */
|
|
138
|
-
export function ompTraceRuns(root: string):
|
|
138
|
+
export function ompTraceRuns(root: string): TraceRun[] {
|
|
139
139
|
const newest: Record<string, { file: string; mtimeSec: number }> = {};
|
|
140
140
|
for (const file of [...jsonlAt(root, 1), ...jsonlAt(root, 2)]) {
|
|
141
141
|
let mt: number;
|
|
@@ -208,14 +208,14 @@ export function ompDumpDir(home: string): string {
|
|
|
208
208
|
* Every request dump under the harness log dir, oldest first. Dumps are named
|
|
209
209
|
* `<epoch ms of the failed request>-<request id>.json`; anything else in the dir is not a dump.
|
|
210
210
|
*/
|
|
211
|
-
export function ompDumps(home: string):
|
|
211
|
+
export function ompDumps(home: string): DumpRef[] {
|
|
212
212
|
let names: string[];
|
|
213
213
|
try {
|
|
214
214
|
names = readdirSync(ompDumpDir(home));
|
|
215
215
|
} catch {
|
|
216
216
|
return [];
|
|
217
217
|
}
|
|
218
|
-
const out:
|
|
218
|
+
const out: DumpRef[] = [];
|
|
219
219
|
for (const name of names) {
|
|
220
220
|
const m = /^(\d+)-[A-Za-z0-9]+\.json$/.exec(name);
|
|
221
221
|
if (m) out.push({ file: join(ompDumpDir(home), name), ms: Number(m[1]) });
|
|
@@ -318,13 +318,6 @@ export function ompScoreTraces(cfg: Config): TraceSource {
|
|
|
318
318
|
return ompTraceSource(cfg.adapter?.sessions || join(cfg.paths.home, ".omp", "agent", "sessions"));
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
-
export interface RelatedTrace {
|
|
322
|
-
/** The subagent run's trace run id — the agent name. */
|
|
323
|
-
name: string;
|
|
324
|
-
mtimeSec: number;
|
|
325
|
-
events: TraceEvent[];
|
|
326
|
-
}
|
|
327
|
-
|
|
328
321
|
/**
|
|
329
322
|
* The subagent runs of one Main run: the depth-2 session files under the Main file's session
|
|
330
323
|
* dir (plan 20261024_0301 P5) — the runs Main spawned there, whose results Main's report cites.
|
package/src/cli/commands.ts
CHANGED
|
@@ -18,9 +18,7 @@ import { wipBackup } from "../core/wip-backup.ts";
|
|
|
18
18
|
import { wipCheck } from "../core/wip-check.ts";
|
|
19
19
|
import { wipSnapshot } from "../core/wip-snapshot.ts";
|
|
20
20
|
import { runtime } from "./runtime.ts";
|
|
21
|
-
import {
|
|
22
|
-
import { defaultCompletedResults, defaultRunSource } from "../adapters/omp/sessions.ts";
|
|
23
|
-
import { ompScoreTraces } from "../adapters/omp/traces.ts";
|
|
21
|
+
import { getAdapter } from "../adapters/index.ts";
|
|
24
22
|
|
|
25
23
|
export const PORTED = [
|
|
26
24
|
"agent-score",
|
|
@@ -45,14 +43,15 @@ export const PORTED = [
|
|
|
45
43
|
] as const;
|
|
46
44
|
|
|
47
45
|
export async function runMain(args: string[]): Promise<number> {
|
|
48
|
-
|
|
46
|
+
const cfg = runtime().cfg;
|
|
47
|
+
return getAdapter(cfg).launchMain(args, cfg);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
export async function runPorted(cmd: string, args: string[]): Promise<number> {
|
|
52
51
|
const rt = runtime();
|
|
53
52
|
switch (cmd) {
|
|
54
53
|
case "agent-score":
|
|
55
|
-
return agentScore(args, rt.cfg, rt.source,
|
|
54
|
+
return agentScore(args, rt.cfg, rt.source, getAdapter(rt.cfg).scoreTraces(rt.cfg));
|
|
56
55
|
case "agent-ledger":
|
|
57
56
|
return agentLedger(args, rt.cfg, rt.source);
|
|
58
57
|
case "brief-lint":
|
|
@@ -75,8 +74,10 @@ export async function runPorted(cmd: string, args: string[]): Promise<number> {
|
|
|
75
74
|
return queueClose(args, rt.cfg);
|
|
76
75
|
case "queue-cancel":
|
|
77
76
|
return queueCancel(args, rt.cfg);
|
|
78
|
-
case "main-start":
|
|
79
|
-
|
|
77
|
+
case "main-start": {
|
|
78
|
+
const a = getAdapter(rt.cfg);
|
|
79
|
+
return mainStart(args, rt.cfg, { source: a.runSource(rt.cfg), results: a.completedResults(rt.cfg) });
|
|
80
|
+
}
|
|
80
81
|
case "machine-guard":
|
|
81
82
|
return machineGuard(args, rt.cfg);
|
|
82
83
|
case "quota-reset":
|
package/src/cli/dispatch.ts
CHANGED
|
@@ -4,8 +4,7 @@ import { ConfigError, configFile, loadConfig, type Config } from "../core/config
|
|
|
4
4
|
import { postReply } from "../core/notify.ts";
|
|
5
5
|
import { loadKnownSecrets, redactSecrets, redactSummary } from "../core/secret-redact.ts";
|
|
6
6
|
import { applyQueueEnv } from "../core/queue/env.ts";
|
|
7
|
-
import {
|
|
8
|
-
import { runDoctor } from "../adapters/omp/doctor.ts";
|
|
7
|
+
import { getAdapter } from "../adapters/index.ts";
|
|
9
8
|
import { GUARD_USAGE, runGuard } from "./guard.ts";
|
|
10
9
|
import { runInit } from "./init.ts";
|
|
11
10
|
import { PORTED, runMain, runPorted } from "./commands.ts";
|
|
@@ -110,7 +109,7 @@ export async function run(cmd: string, args: string[]): Promise<number> {
|
|
|
110
109
|
if (cmd === "traces") return runTraces(args);
|
|
111
110
|
if (cmd === "ui") return runUi(args);
|
|
112
111
|
if (cmd === "pages") return runPages(args);
|
|
113
|
-
if (cmd === "adapter") return
|
|
112
|
+
if (cmd === "adapter") return getAdapter().install(args);
|
|
114
113
|
if (cmd === "config") {
|
|
115
114
|
try {
|
|
116
115
|
const cfg = loadConfig();
|
|
@@ -123,7 +122,7 @@ export async function run(cmd: string, args: string[]): Promise<number> {
|
|
|
123
122
|
}
|
|
124
123
|
if (cmd === "doctor") {
|
|
125
124
|
for (const warning of pagesDoctor()) console.warn(`warning: ${warning}`);
|
|
126
|
-
return
|
|
125
|
+
return getAdapter().doctor();
|
|
127
126
|
}
|
|
128
127
|
if (cmd === "notify") return runNotify(args);
|
|
129
128
|
if (cmd === "redact") return runRedact(args);
|
package/src/cli/metrics.ts
CHANGED
|
@@ -11,8 +11,7 @@ import type { RunSource } from "../core/adapter.ts";
|
|
|
11
11
|
import { buildReport, type BloatSummary, type ProviderSummary } from "../core/report.ts";
|
|
12
12
|
import { providerFindings } from "../core/trace-provider.ts";
|
|
13
13
|
import { bloatRules } from "../core/trace-bloat.ts";
|
|
14
|
-
import {
|
|
15
|
-
import { ompDumps, ompTraceRuns, ompTraceSource } from "../adapters/omp/traces.ts";
|
|
14
|
+
import { getAdapter } from "../adapters/index.ts";
|
|
16
15
|
import { assignDumps, bloatReport } from "./traces.ts";
|
|
17
16
|
|
|
18
17
|
export const METRICS_USAGE = [
|
|
@@ -97,12 +96,13 @@ export function recordRule(cfg: Config, text: string, decision: "approved" | "re
|
|
|
97
96
|
* rules of src/core/trace-provider.ts under the config's provider rules and price table. */
|
|
98
97
|
function providerSummary(cfg: Config, now: number, days: number): ProviderSummary {
|
|
99
98
|
const root = cfg.adapter?.sessions || join(cfg.paths.home, ".omp", "agent", "sessions");
|
|
99
|
+
const a = getAdapter(cfg);
|
|
100
100
|
const cutoff = now - days * 86400;
|
|
101
|
-
const src =
|
|
101
|
+
const src = a.traceSource(root);
|
|
102
102
|
const rules = cfg.traces.provider;
|
|
103
103
|
const byKind: Record<string, number> = {};
|
|
104
104
|
let runs = 0;
|
|
105
|
-
for (const r of
|
|
105
|
+
for (const r of a.traceRuns(root)) {
|
|
106
106
|
if (r.mtimeSec < cutoff) continue;
|
|
107
107
|
runs++;
|
|
108
108
|
for (const f of providerFindings(src.events(r.runId), rules, rules.prices)) byKind[f.kind] = (byKind[f.kind] ?? 0) + 1;
|
|
@@ -115,20 +115,21 @@ function providerSummary(cfg: Config, now: number, days: number): ProviderSummar
|
|
|
115
115
|
* rejected call flags only through its dump). */
|
|
116
116
|
function bloatSummary(cfg: Config, now: number, days: number): BloatSummary {
|
|
117
117
|
const root = cfg.adapter?.sessions || join(cfg.paths.home, ".omp", "agent", "sessions");
|
|
118
|
+
const a = getAdapter(cfg);
|
|
118
119
|
const cutoff = now - days * 86400;
|
|
119
|
-
const src =
|
|
120
|
+
const src = a.traceSource(root);
|
|
120
121
|
const rules = bloatRules(cfg);
|
|
121
|
-
const dumps =
|
|
122
|
+
const dumps = a.dumps(cfg.paths.home);
|
|
122
123
|
let runs = 0;
|
|
123
124
|
let flagged = 0;
|
|
124
125
|
let largest: BloatSummary["largest"] = null;
|
|
125
|
-
const allRuns =
|
|
126
|
-
const { owners, events: assignmentEvents } = assignDumps(allRuns, src, dumps);
|
|
126
|
+
const allRuns = a.traceRuns(root);
|
|
127
|
+
const { owners, events: assignmentEvents } = assignDumps(allRuns, src, dumps, a);
|
|
127
128
|
for (const r of allRuns) {
|
|
128
129
|
if (r.mtimeSec < cutoff) continue;
|
|
129
130
|
runs++;
|
|
130
131
|
const owned = dumps.filter((dump) => owners.get(dump.file) === r.runId);
|
|
131
|
-
const rep = bloatReport(src, r.runId, rules, cfg.traces.bloat.tool_group, owned, r.mtimeSec, assignmentEvents.get(r.runId));
|
|
132
|
+
const rep = bloatReport(src, r.runId, rules, cfg.traces.bloat.tool_group, owned, r.mtimeSec, a, assignmentEvents.get(r.runId));
|
|
132
133
|
if (rep.findings.length === 0) continue;
|
|
133
134
|
flagged++;
|
|
134
135
|
const firstCall = Math.max(rep.firstPrompt ?? 0, rep.dumpPrompt?.tokens ?? 0);
|
|
@@ -163,7 +164,7 @@ export async function runMetrics(args: string[]): Promise<number> {
|
|
|
163
164
|
const [sub = "", ...rest] = args;
|
|
164
165
|
const now = nowSec();
|
|
165
166
|
if (sub === "ci") return recordCi(cfg, rest[0] ?? "", rest[1] ?? "", now);
|
|
166
|
-
if (sub === "report") return reportCmd(cfg,
|
|
167
|
+
if (sub === "report") return reportCmd(cfg, getAdapter(cfg).runSource(cfg), rest, now);
|
|
167
168
|
if (sub === "false-alarm") return recordFalseAlarm(cfg, rest[0] ?? "", flagValue(rest, "--why") ?? "", now);
|
|
168
169
|
if (sub === "rule") {
|
|
169
170
|
const approved = rest.includes("--approved");
|
package/src/cli/pages.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readdirSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
|
-
import {
|
|
3
|
+
import { getAdapter } from "../adapters/index.ts";
|
|
4
4
|
import { loadConfig } from "../core/config.ts";
|
|
5
5
|
import { readExpiry, sweepPages } from "../core/pages-expiry.ts";
|
|
6
6
|
import { startPagesServer } from "../core/pages.ts";
|
|
@@ -19,7 +19,7 @@ export async function runPages(args: string[] = [], deps: PagesDeps = {}): Promi
|
|
|
19
19
|
if (args[0] === "serve" && args.length === 1) {
|
|
20
20
|
if (!cfg.pages.enabled) throw new Error("pages.enabled is false");
|
|
21
21
|
sweepPages(cfg.pages.dir, cfg.pages.keep_days, clock());
|
|
22
|
-
startPagesServer({ cfg, tailscale: deps.tailscale ?? realTailscale, source:
|
|
22
|
+
startPagesServer({ cfg, tailscale: deps.tailscale ?? realTailscale, source: getAdapter(cfg).runSource(cfg) });
|
|
23
23
|
setInterval(() => { try { sweepPages(cfg.pages.dir, cfg.pages.keep_days, clock()); } catch (e) { console.error(e instanceof Error ? e.message : String(e)); } }, HOUR_MS);
|
|
24
24
|
return new Promise<number>(() => {});
|
|
25
25
|
}
|
package/src/cli/runtime.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { loadConfig, type Config } from "../core/config.ts";
|
|
2
2
|
import type { RunSource } from "../core/adapter.ts";
|
|
3
|
-
import {
|
|
3
|
+
import { getAdapter } from "../adapters/index.ts";
|
|
4
4
|
|
|
5
5
|
export interface Runtime {
|
|
6
6
|
cfg: Config;
|
|
@@ -9,5 +9,5 @@ export interface Runtime {
|
|
|
9
9
|
|
|
10
10
|
export function runtime(): Runtime {
|
|
11
11
|
const cfg = loadConfig();
|
|
12
|
-
return { cfg, source:
|
|
12
|
+
return { cfg, source: getAdapter(cfg).runSource(cfg) };
|
|
13
13
|
}
|
package/src/cli/traces.ts
CHANGED
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
import { join } from "node:path";
|
|
16
16
|
import { nowSec } from "../core/clock.ts";
|
|
17
|
-
import type { TraceEvent, TraceSource } from "../core/adapter.ts";
|
|
17
|
+
import type { DumpRef, TraceEvent, TraceSource } from "../core/adapter.ts";
|
|
18
|
+
import { getAdapter, type HarnessAdapter } from "../adapters/index.ts";
|
|
18
19
|
import { ConfigError, loadConfig, type Config } from "../core/config.ts";
|
|
19
20
|
import { claimUnbacked } from "../core/incident-detectors.ts";
|
|
20
21
|
import { claimsFromEvents, type RelatedRun } from "../core/trace-claims.ts";
|
|
@@ -22,7 +23,6 @@ import { actionsRules, suspiciousActions, type ActionsRules, type SuspiciousActi
|
|
|
22
23
|
import { bloatBreakdown, bloatFindings, bloatRules, callSizes, dumpFinding, type BloatBreakdown, type BloatRules } from "../core/trace-bloat.ts";
|
|
23
24
|
import { efficiencyRules, runEfficiency, RULE_ORDER, type EfficiencyRules, type WasteRule } from "../core/trace-efficiency.ts";
|
|
24
25
|
import { pyPercent0 } from "../core/pyfmt.ts";
|
|
25
|
-
import { dumpModel, dumpParts, dumpPromptTokens, ompDumps, ompTraceRuns, ompTraceSource, ompTraceStart, spawnBriefsIn, subagentTraces } from "../adapters/omp/traces.ts";
|
|
26
26
|
import { briefReport, briefRows, type SideStat } from "../core/trace-briefs.ts";
|
|
27
27
|
import { readEvents } from "../core/agent-score.ts";
|
|
28
28
|
|
|
@@ -111,16 +111,16 @@ export interface DumpAssignmentRun { runId: string; file: string; mtimeSec: numb
|
|
|
111
111
|
export interface DumpAssignment { owners: Map<string, string>; unmatched: { file: string; ms: number }[]; events: Map<string, TraceEvent[]> }
|
|
112
112
|
|
|
113
113
|
/** Assign each dump once, parsing only traces whose session start and mtime contain it. */
|
|
114
|
-
export function assignDumps(runs: DumpAssignmentRun[], src: TraceSource, dumps:
|
|
114
|
+
export function assignDumps(runs: DumpAssignmentRun[], src: TraceSource, dumps: DumpRef[], a: Pick<HarnessAdapter, "dumpModel" | "traceStart"> = getAdapter()): DumpAssignment {
|
|
115
115
|
const owners = new Map<string, string>();
|
|
116
|
-
const unmatched:
|
|
116
|
+
const unmatched: DumpRef[] = [];
|
|
117
117
|
const cached = new Map<string, ReturnType<TraceSource["events"]>>();
|
|
118
118
|
for (const dump of dumps) {
|
|
119
|
-
const model = dumpModel(dump.file);
|
|
119
|
+
const model = a.dumpModel(dump.file);
|
|
120
120
|
const eligible: { ts: number; runId: string }[] = [];
|
|
121
121
|
for (const run of runs) {
|
|
122
122
|
if (dump.ms > Math.round(run.mtimeSec * 1000)) continue;
|
|
123
|
-
const start =
|
|
123
|
+
const start = a.traceStart(run.file);
|
|
124
124
|
if (start !== null && dump.ms < start * 1000) continue;
|
|
125
125
|
let events = cached.get(run.runId);
|
|
126
126
|
if (!events) {
|
|
@@ -144,7 +144,7 @@ export function assignDumps(runs: DumpAssignmentRun[], src: TraceSource, dumps:
|
|
|
144
144
|
return { owners, unmatched, events: cached };
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
export function bloatReport(src: TraceSource, runId: string, rules: BloatRules, groupRegex: string, dumps:
|
|
147
|
+
export function bloatReport(src: TraceSource, runId: string, rules: BloatRules, groupRegex: string, dumps: DumpRef[], mtimeSec: number, a: Pick<HarnessAdapter, "dumpParts" | "dumpPromptTokens"> = getAdapter(), parsedEvents?: TraceEvent[]): RunBloatReport {
|
|
148
148
|
const events = parsedEvents ?? src.events(runId);
|
|
149
149
|
const sizes = callSizes(events, rules.aggregate_apis);
|
|
150
150
|
const findings = bloatFindings(events, rules);
|
|
@@ -161,8 +161,8 @@ export function bloatReport(src: TraceSource, runId: string, rules: BloatRules,
|
|
|
161
161
|
if (first !== undefined) {
|
|
162
162
|
const dump = dumps.find((d) => d.ms >= first * 1000 && d.ms <= Math.round(mtimeSec * 1000));
|
|
163
163
|
if (dump) {
|
|
164
|
-
breakdown = bloatBreakdown(dumpParts(dump.file), groupRegex);
|
|
165
|
-
const stated = dumpPromptTokens(dump.file);
|
|
164
|
+
breakdown = bloatBreakdown(a.dumpParts(dump.file), groupRegex);
|
|
165
|
+
const stated = a.dumpPromptTokens(dump.file);
|
|
166
166
|
if (stated) {
|
|
167
167
|
dumpPrompt = { tokens: stated.tokens, ...(stated.limit !== undefined ? { limit: stated.limit } : {}) };
|
|
168
168
|
if (findings.length === 0) {
|
|
@@ -208,10 +208,11 @@ function briefsCommand(cfg: Config, root: string, rest: string[]): number {
|
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
const cutoff = nowSec() - windowSec;
|
|
211
|
-
const
|
|
211
|
+
const a = getAdapter(cfg);
|
|
212
|
+
const briefs = a.traceRuns(root)
|
|
212
213
|
.filter((r) => r.mtimeSec >= cutoff)
|
|
213
|
-
.flatMap((r) => spawnBriefsIn(r.file, r.runId));
|
|
214
|
-
const rows = briefRows(briefs,
|
|
214
|
+
.flatMap((r) => a.spawnBriefsIn(r.file, r.runId));
|
|
215
|
+
const rows = briefRows(briefs, a.traceSource(root), readEvents(cfg), { brief: cfg.traces.briefs, efficiency: efficiencyRules(cfg) });
|
|
215
216
|
const summary = briefReport(rows, { min_n: cfg.traces.briefs.min_n, char_buckets: cfg.traces.briefs.char_buckets });
|
|
216
217
|
if (json) {
|
|
217
218
|
console.log(JSON.stringify(report ? summary : rows, null, 2));
|
|
@@ -279,15 +280,16 @@ export async function runTraces(args: string[], opts: { home?: string } = {}): P
|
|
|
279
280
|
console.error(TRACES_USAGE);
|
|
280
281
|
return 2;
|
|
281
282
|
}
|
|
282
|
-
const
|
|
283
|
-
const
|
|
283
|
+
const a = getAdapter(cfg);
|
|
284
|
+
const runs = a.traceRuns(root);
|
|
285
|
+
const src = a.traceSource(root);
|
|
284
286
|
const rules: ActionsRules | EfficiencyRules | BloatRules | null = sub === "actions" ? actionsRules(cfg) : sub === "efficiency" ? efficiencyRules(cfg) : sub === "bloat" ? bloatRules(cfg) : null;
|
|
285
287
|
// A Main run's report cites its subagents' results: their traces under the Main session dir
|
|
286
288
|
// back the pure result-line claims (P5). No time filter — the text match is the guard, and
|
|
287
289
|
// a sub's file keeps being written while its Main run lives, inside whatever window.
|
|
288
290
|
const relatedOf = (id: string): RelatedRun[] =>
|
|
289
|
-
sub === "claims" ? subagentTraces(root, id).map(({ name, events }) => ({ name, events })) : [];
|
|
290
|
-
const dumps = sub === "bloat" ?
|
|
291
|
+
sub === "claims" ? a.subagentTraces(root, id).map(({ name, events }) => ({ name, events })) : [];
|
|
292
|
+
const dumps = sub === "bloat" ? a.dumps(cfg.paths.home) : [];
|
|
291
293
|
const assignment = sub === "bloat" ? assignDumps(runs, src, dumps) : { owners: new Map<string, string>(), unmatched: [] as { file: string; ms: number }[], events: new Map<string, TraceEvent[]>() };
|
|
292
294
|
const dumpOwners = assignment.owners;
|
|
293
295
|
const unmatchedDumps = assignment.unmatched;
|
|
@@ -298,7 +300,7 @@ export async function runTraces(args: string[], opts: { home?: string } = {}): P
|
|
|
298
300
|
if (sub === "claims") return claimsReport(src, id, relatedOf(id));
|
|
299
301
|
if (sub === "actions") return actionsReport(src, id, rules as ActionsRules);
|
|
300
302
|
if (sub === "efficiency") return efficiencyReport(src, id, rules as EfficiencyRules);
|
|
301
|
-
return bloatReport(src, id, rules as BloatRules, cfg.traces.bloat.tool_group, assignedDumps(id), mtimeOf(id), assignment.events.get(id));
|
|
303
|
+
return bloatReport(src, id, rules as BloatRules, cfg.traces.bloat.tool_group, assignedDumps(id), mtimeOf(id), a, assignment.events.get(id));
|
|
302
304
|
};
|
|
303
305
|
if (windowSec !== undefined) {
|
|
304
306
|
const cutoff = nowSec() - windowSec;
|
package/src/cli/ui.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// `ui on --login <email> [--port N]` / `ui off` set up and undo that whole setup in one command
|
|
5
5
|
// (the core lives in src/core/ui-setup.ts); plain `neurastream ui` keeps serving as today.
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { getAdapter } from "../adapters/index.ts";
|
|
8
8
|
import { ConfigError, loadConfig, type Config } from "../core/config.ts";
|
|
9
9
|
import { startOwnerUi, type OwnerUiOptions, type OwnerUiServer } from "../core/owner-ui.ts";
|
|
10
10
|
import { applyQueueEnv } from "../core/queue/env.ts";
|
|
@@ -84,7 +84,7 @@ export async function runUi(args: string[] = [], deps: UiDeps = {}): Promise<num
|
|
|
84
84
|
console.error("neurastream ui: ui.owner_login is empty — set the tailscale login that may open the page");
|
|
85
85
|
return 1;
|
|
86
86
|
}
|
|
87
|
-
(deps.start ?? startOwnerUi)({ cfg, tailscale: realTailscale, source:
|
|
87
|
+
(deps.start ?? startOwnerUi)({ cfg, tailscale: realTailscale, source: getAdapter(cfg).runSource(cfg) });
|
|
88
88
|
// src/cli/main.ts exits with the code this returns, which would kill the server: serving
|
|
89
89
|
// never resolves, and the process runs until systemd or a signal stops it.
|
|
90
90
|
return new Promise<number>(() => {});
|
package/src/core/adapter.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Guard decisions and run data. No harness names. See docs/adapter.md.
|
|
2
2
|
|
|
3
|
+
import type { mainStartText } from "./main-start.ts";
|
|
4
|
+
|
|
3
5
|
export type RunStatus = "running" | "waiting" | "done" | "died";
|
|
4
6
|
|
|
5
7
|
export interface RunMessage {
|
|
@@ -137,3 +139,40 @@ export interface StopEvent {
|
|
|
137
139
|
|
|
138
140
|
export const GUARD_EVENTS = ["pre-tool", "inject", "spawn", "plan-edit", "stop"] as const;
|
|
139
141
|
export type GuardEvent = (typeof GUARD_EVENTS)[number];
|
|
142
|
+
|
|
143
|
+
// Shapes the registry (src/adapters/index.ts) and the CLI share. No harness names — only
|
|
144
|
+
// src/adapters may name one.
|
|
145
|
+
|
|
146
|
+
/** Every run id with a trace under a sessions root, each mapped to its newest file. */
|
|
147
|
+
export interface TraceRun {
|
|
148
|
+
runId: string;
|
|
149
|
+
file: string;
|
|
150
|
+
mtimeSec: number;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** One failed-request dump file: its path plus the epoch-ms stamp in its name. */
|
|
154
|
+
export interface DumpRef {
|
|
155
|
+
file: string;
|
|
156
|
+
ms: number;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** One subagent run's trace under one main run's session dir. */
|
|
160
|
+
export interface RelatedTrace {
|
|
161
|
+
/** The subagent run's trace run id — the agent name. */
|
|
162
|
+
name: string;
|
|
163
|
+
mtimeSec: number;
|
|
164
|
+
events: TraceEvent[];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** One finished subagent task-result announced in the newest main session file. */
|
|
168
|
+
export interface TaskResult {
|
|
169
|
+
agent: string;
|
|
170
|
+
ts: number;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Options for launching the harness binary; tests inject another path and a failing generator. */
|
|
174
|
+
export interface LaunchOptions {
|
|
175
|
+
harness?: string;
|
|
176
|
+
/** The main-start text generator for the handoff (default: src/core/main-start.ts). Tests inject a failing one. */
|
|
177
|
+
mainStart?: typeof mainStartText;
|
|
178
|
+
}
|
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/config.ts
CHANGED
|
@@ -17,6 +17,8 @@ export class ConfigError extends Error {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface Config {
|
|
20
|
+
/** Which adapter (src/adapters/index.ts) serves runs, traces, launch, install and doctor. The template ships the only one; a second harness adds its name here (docs/adapter.md). */
|
|
21
|
+
harness: string;
|
|
20
22
|
paths: {
|
|
21
23
|
home: string;
|
|
22
24
|
work_roots: string[];
|
|
@@ -387,6 +389,7 @@ function applyEnv(cfg: Record<string, unknown>, env: NodeJS.ProcessEnv): void {
|
|
|
387
389
|
}
|
|
388
390
|
|
|
389
391
|
function check(cfg: Config): void {
|
|
392
|
+
if (typeof cfg.harness !== "string" || cfg.harness === "") throw new ConfigError("harness must be a non-empty string");
|
|
390
393
|
try {
|
|
391
394
|
const pattern = cfg.quota.reset_pattern;
|
|
392
395
|
new RegExp(pattern);
|
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.
|
package/templates/config.yml
CHANGED
|
@@ -21,6 +21,9 @@ paths:
|
|
|
21
21
|
alert_state: "~/.cache/resource-alerts"
|
|
22
22
|
snapshot_lock: "~/.cache/tmp-snapshot.lock"
|
|
23
23
|
|
|
24
|
+
# Which adapter (docs/adapter.md) serves runs, traces, launch, install and doctor.
|
|
25
|
+
harness: omp
|
|
26
|
+
|
|
24
27
|
score:
|
|
25
28
|
default_repo: ""
|
|
26
29
|
default_branch: "" # no default: pass --branch (agent-score refuses to guess a branch)
|
|
@@ -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.
|