neurastream 0.2.41 → 0.2.43
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 +17 -8
- package/package.json +1 -1
- package/src/adapters/omp/doctor.ts +4 -4
- package/src/adapters/omp/index.ts +35 -55
- package/src/adapters/omp/install.ts +14 -12
- package/src/adapters/omp/launch.ts +9 -1
- package/src/cli/incident.ts +19 -1
- package/src/core/agents-md.ts +5 -26
- package/src/core/incidents.ts +55 -11
- package/src/core/owner-ui.ts +75 -20
- package/src/core/rollover.ts +2 -4
package/README.md
CHANGED
|
@@ -31,8 +31,17 @@ flowchart LR
|
|
|
31
31
|
| Brief lint (`brief-lint`) | Refuses a helper brief that misses a required rule (acceptance, stop condition, no push, call budget). |
|
|
32
32
|
| Machine health (`machine-guard`, `main-start`, `heavy-run`) | Load, free memory, disk and `/tmp` limits; one heavy test run at a time. |
|
|
33
33
|
| Unlanded work (`wip-check`, `wip-snapshot`, `wip-backup`) | Lists branches on no remote and dirty worktrees; snapshots them as hidden commits; can push them to a backup repo. |
|
|
34
|
-
| Session rollover | When the main session file passes 5 MB, or the installed neurastream version differs from the running plugin, Main writes a handoff note;
|
|
35
|
-
| Owner page (`neurastream ui`) | One phone-sized page over Tailscale (`ui.*` config): the plans waiting on the owner with answer buttons, the guard unlock, running agents, the queue, recent merges/CI, open incidents, agent scores, machine health. Serves only a tailnet peer whose `tailscale whois` login equals `ui.owner_login`, only with a Host header naming the tailnet address or the MagicDNS name — DNS rebinding and every other visitor get a 403. Answers land in the owner inbox and reach Main once each; agents cannot start the page or write the inbox. |
|
|
34
|
+
| Session rollover | When the main session file passes 5 MB, or the installed neurastream version differs from the running plugin, Main writes a handoff note; a fresh session then starts on its own under `neurastream main`. |
|
|
35
|
+
| Owner page (`neurastream ui`) | One phone-sized page over Tailscale (`ui.*` config): the plans waiting on the owner with answer buttons, the guard unlock, running agents, the queue, recent merges/CI, open incidents (a finding carries Main's reason and False alarm / It's a bug buttons), agent scores, machine health. Serves only a tailnet peer whose `tailscale whois` login equals `ui.owner_login`, only with a Host header naming the tailnet address or the MagicDNS name — DNS rebinding and every other visitor get a 403. Answers land in the owner inbox and reach Main once each; agents cannot start the page or write the inbox. |
|
|
36
|
+
|
|
37
|
+
## Main vs plain omp
|
|
38
|
+
|
|
39
|
+
neurastream runs only under `neurastream main`. That launcher sets `NEURASTREAM_MAIN_LAUNCHER=1` for the omp it starts, and only then does the adapter register its hooks and commands. Plain `omp` runs with no guard, queue summary, rules or rollover, as if neurastream were not installed.
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
neurastream main # Main: guards, queue, rules, rollover
|
|
43
|
+
omp -p "say hi" # plain omp: no neurastream hook, no guard-log line
|
|
44
|
+
```
|
|
36
45
|
|
|
37
46
|
## Requirements
|
|
38
47
|
|
|
@@ -139,7 +148,6 @@ Main's session file grows with every turn. When it reaches `rollover.max_session
|
|
|
139
148
|
There are two modes:
|
|
140
149
|
|
|
141
150
|
- Under `neurastream main` (the launcher) the rollover is automatic. Once the note is written and no own jobs (subagents included) are still running, omp writes `relaunch.json` and exits. The launcher starts a fresh omp whose first message is the handoff: the note verbatim, the generated `main-start` state (including the owner holds), the owner's unsent draft if there is one, and a line that the owner is away. Nobody types anything. A handoff over 100000 bytes goes to `<queue_state>/rollover/<session id>.handoff.md`, and the first message points at that file.
|
|
142
|
-
- Under plain `omp` the switch is never automatic. The owner's next plain message closes the session and starts a fresh one; the fresh session opens with the note verbatim, the generated state, and then the owner's message.
|
|
143
151
|
|
|
144
152
|
A relaunch keeps the flags of the first run (`--model`, `--session-dir`, …) and drops only the first message and the session-picking and one-shot flags (`-r`, `-c`, `--restore`, `--goal`, `-p`, …), so the fresh omp stays on the same model and session directory.
|
|
145
153
|
|
|
@@ -153,7 +161,7 @@ In both modes:
|
|
|
153
161
|
- While a rollover is pending (no fresh note, own jobs still running, or the handoff is ready and waiting for idle), Main cannot start new subagents: a `task` call is refused until the running jobs finish and the session rolls over.
|
|
154
162
|
- While own jobs (subagents included) are still running, the switch waits: a rollover would cancel them.
|
|
155
163
|
- While a rollover is pending, the stop guard does not apply: Main may stop in `ready` or `wait-jobs`, and in `need-note` the stop is blocked only by the note request.
|
|
156
|
-
- `/main-rollover <message>` does the same by hand. It refuses below the threshold, without a fresh note, or while jobs run. Under neurastream main it is refused and the owner's next message starts the rollover
|
|
164
|
+
- `/main-rollover <message>` does the same by hand. It refuses below the threshold, without a fresh note, or while jobs run. Under neurastream main it is refused and the owner's next message starts the rollover.
|
|
157
165
|
- `/main-rollover` shows a notice at once and gathers `main-start` in the background, so omp keeps repainting and reading keys until the new session opens.
|
|
158
166
|
- The previous session file stays where it is.
|
|
159
167
|
- `rollover.enabled: false` turns the feature off.
|
|
@@ -352,6 +360,8 @@ Five sources feed it:
|
|
|
352
360
|
|
|
353
361
|
While an incident is open (no plan, dismissal or fixed record), every Main prompt carries one `INCIDENT <id> [<source>/<kind>]: <summary>` line per open incident, Main's `task` spawns and bypass launches are refused unless the brief names a plan citing `INCIDENT <id>`, and Main cannot stop with an incident that has neither. A stop reply that only offers to plan is refused too: the reply Main stops with is matched against `guards.plan_offer` (case-insensitive; "want me to write a plan?", "should I plan") and a hit answers "don't offer it — write the plan and index it" — the two-idle-stops release does not lift that block. The loop closes three ways: `neurastream incident plan <id> <plan.md>` (the plan must exist, be listed in the main index, cite `INCIDENT <id>`, and carry a fail-before phase — its regression test has to fail on the old code), `neurastream incident dismiss <id> --why "<text>"` (a finding incident — `agent-finding` or `main-finding` — is dismissed only with the owner's own words: `--owner "<quote>"`, a substring of an owner message the inject hook saw in the last 24 h, so the agent that found the bug cannot also wave it away), and `fixed` — written by the queue itself when it closes a plan that cites the incident. `neurastream metrics report` shows M6: incidents opened / planned / dismissed / fixed and the median hours from open to fixed.
|
|
354
362
|
|
|
363
|
+
A finding incident (`agent-finding`, `main-finding`) shows on the Agents tab with Main's latest reason and two buttons. Main writes the reason with `neurastream incident propose <id> --why "<file:line and reason>"`; the why must cite the proof as `file:line`, and the incident stays open. The owner taps **False alarm** (the incident closes; the reason is recorded as the dismissal with the owner's login) or **It's a bug — plan it** (the incident stays open and one message goes to Main's inbox). A finding with no reason yet says "Main has not said why yet".
|
|
364
|
+
|
|
355
365
|
## Changing a script
|
|
356
366
|
|
|
357
367
|
Edit the script in this repo. Green is `bun run typecheck` and `bun test`, both exit 0. Main tags the release. The publish workflow puts that tag on npm. Then:
|
|
@@ -365,11 +375,10 @@ Live copies are never hand-edited. `neurastream doctor` names each hand-edited i
|
|
|
365
375
|
|
|
366
376
|
## AGENTS.md block
|
|
367
377
|
|
|
368
|
-
|
|
378
|
+
Main's rules are not written into `~/.omp/agent/AGENTS.md`. Under `neurastream main` they ride Main's system prompt on each turn, built from `templates/AGENTS.md` with the agent dir from your config. Install strips a block an older install left between the markers `<!-- neurastream:begin (managed by neurastream; edit the package, not this block) -->` and `<!-- neurastream:end -->`.
|
|
369
379
|
|
|
370
|
-
-
|
|
371
|
-
-
|
|
372
|
-
- Drift: `neurastream doctor` reports `stale:` when the text between the markers differs from the package's block, and `missing:` when the markers are absent. Edits outside the markers are never reported.
|
|
380
|
+
- Yours: every line outside the markers. Install keeps it byte for byte; a file the strip leaves empty is removed.
|
|
381
|
+
- Leftover: markers still in the file, malformed ones included. Install leaves them alone; `neurastream doctor` reports `stale: neurastream block still in <file>`.
|
|
373
382
|
- Edit limit: the project-file changes Main gets per window come from the config, not from the block text: `guards.main_edit_limit` per `guards.main_window_min` in tier `opinionated`, `autonomy.strict_edit_limit` in tier `strict`, no cap in tier `full`.
|
|
374
383
|
|
|
375
384
|
## Project rules
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync, statSyn
|
|
|
9
9
|
import { homedir } from "node:os";
|
|
10
10
|
import { dirname, join, relative, resolve } from "node:path";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
|
-
import {
|
|
12
|
+
import { stripBlock } from "../../core/agents-md.ts";
|
|
13
13
|
import { loadConfig } from "../../core/config.ts";
|
|
14
14
|
import { notifyFindings } from "../../core/notify.ts";
|
|
15
15
|
import { loadKnownSecrets, proxyOnPath } from "../../core/secret-redact.ts";
|
|
@@ -211,9 +211,9 @@ export function doctorReport(home: string, env: NodeJS.ProcessEnv = process.env,
|
|
|
211
211
|
: [];
|
|
212
212
|
if (repoDirs.length)
|
|
213
213
|
problems.push(`${idx} still lists ${repoDirs.length} repo director${repoDirs.length === 1 ? "y" : "ies"} (${repoDirs.join(", ")}); run neurastream queue migrate`);
|
|
214
|
-
|
|
215
|
-
if (state === "
|
|
216
|
-
else problems.push(
|
|
214
|
+
// The block is no longer written here: markers left in the owner's file are stale.
|
|
215
|
+
if (stripBlock(text).state === "missing") ok.push(`${agents} no neurastream block`);
|
|
216
|
+
else problems.push(`stale: neurastream block still in ${agents}`);
|
|
217
217
|
const warnings: string[] = [];
|
|
218
218
|
const notify = notifyFindings(cfg);
|
|
219
219
|
problems.push(...notify.problems);
|
|
@@ -19,7 +19,7 @@ import { execFileSync, spawn } from "node:child_process";
|
|
|
19
19
|
import { appendFileSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
20
20
|
import { basename, dirname, join, resolve } from "node:path";
|
|
21
21
|
import type { Decision } from "../../core/adapter.ts";
|
|
22
|
-
import { AGENTS_TEMPLATE } from "../../core/agents-md.ts";
|
|
22
|
+
import { AGENTS_TEMPLATE, renderBlock } from "../../core/agents-md.ts";
|
|
23
23
|
import { chatGo, chatTier, type Tier } from "../../core/autonomy.ts";
|
|
24
24
|
import { burdenRule, repoRules, rulesChanged } from "../../core/repo-rules.ts";
|
|
25
25
|
import { loadConfig, type Config } from "../../core/config.ts";
|
|
@@ -37,7 +37,7 @@ import { mainStartText, runDailyCheck } from "../../core/main-start.ts";
|
|
|
37
37
|
import { readBlocks } from "../../core/metrics.ts";
|
|
38
38
|
import { buildHandoff, holdsBlock, notePath, noteRequest, OWNER_AWAY, ownerText, relaunchPath, rolloverState, spawnRefusal, type RolloverState } from "../../core/rollover.ts";
|
|
39
39
|
import { defaultCompletedResults, defaultRunSource, runIdOf } from "./sessions.ts";
|
|
40
|
-
import { adapterLog } from "./launch.ts";
|
|
40
|
+
import { adapterLog, MAIN_ENV } from "./launch.ts";
|
|
41
41
|
import { parseTraceFile } from "./traces.ts";
|
|
42
42
|
import { packageJsonPath, packageVersion } from "./package-root.ts";
|
|
43
43
|
import * as q from "../../core/queue/lib.ts";
|
|
@@ -552,6 +552,8 @@ export function deliverOwnerInbox(pi: ExtensionHost, cfg: Config): void {
|
|
|
552
552
|
export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
553
553
|
// The queue library resolves its paths from env snapshots; point them at this config first.
|
|
554
554
|
applyQueueEnv(cfg);
|
|
555
|
+
// Main's rules ride its system prompt each turn; they are never written into the owner's AGENTS.md.
|
|
556
|
+
const mainRules = renderBlock(cfg);
|
|
555
557
|
|
|
556
558
|
let callsSinceStop = 0;
|
|
557
559
|
let idleStops = 0;
|
|
@@ -795,7 +797,9 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
795
797
|
if (r && rulesChanged(cfg, asString(c.id) || "main", r.path, r.text)) rules.push(`Repo rules (${r.path}):\n${r.text}`);
|
|
796
798
|
}
|
|
797
799
|
pendingRules.clear();
|
|
800
|
+
const hostPrompt = asRecord(event).systemPrompt;
|
|
798
801
|
return {
|
|
802
|
+
systemPrompt: [...(Array.isArray(hostPrompt) ? hostPrompt : []), mainRules],
|
|
799
803
|
message: {
|
|
800
804
|
customType: "main-guard.queue",
|
|
801
805
|
content: [d.inject, notice, ...rules].filter(Boolean).join("\n\n"),
|
|
@@ -992,9 +996,8 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
992
996
|
}
|
|
993
997
|
if (snap.state === "ready" || snap.state === "wait-jobs") {
|
|
994
998
|
adapterLog(cfg, `ALLOW stop: rollover ${snap.state}`);
|
|
995
|
-
// Under the launcher a ready rollover starts now (not a hand-back to the owner)
|
|
996
|
-
|
|
997
|
-
const handsToOwner = !(snap.state === "ready" && process.env.NEURASTREAM_MAIN_LAUNCHER === "1" && requestRelaunch(rc, notePath(rc.sessionId)));
|
|
999
|
+
// Under the launcher a ready rollover starts now (not a hand-back to the owner).
|
|
1000
|
+
const handsToOwner = !(snap.state === "ready" && requestRelaunch(rc, notePath(rc.sessionId)));
|
|
998
1001
|
if (handsToOwner) notifyHandback(reply, "allowed session_stop");
|
|
999
1002
|
else adapterLog(cfg, "notify: skipped (relaunch requested)");
|
|
1000
1003
|
return undefined;
|
|
@@ -1058,7 +1061,7 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
1058
1061
|
// The note request for a state. A stale install names both versions in place of the size line.
|
|
1059
1062
|
const noteRequestFor = (c: RolloverCtx, snap: { stale: boolean; liveVersion: string | null }): string => {
|
|
1060
1063
|
const reason = snap.stale ? `neurastream on disk is ${snap.liveVersion ?? "unknown"}, this session runs ${loadedVersion ?? "unknown"}` : undefined;
|
|
1061
|
-
return noteRequest(notePath(c.sessionId),
|
|
1064
|
+
return noteRequest(notePath(c.sessionId), reason);
|
|
1062
1065
|
};
|
|
1063
1066
|
|
|
1064
1067
|
let relaunched = false;
|
|
@@ -1081,12 +1084,13 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
1081
1084
|
};
|
|
1082
1085
|
};
|
|
1083
1086
|
|
|
1084
|
-
// One
|
|
1087
|
+
// One in-process rollover at a time: while it waits for idle, the size check must not start
|
|
1088
|
+
// a relaunch over it.
|
|
1085
1089
|
let flight: string[] | null = null;
|
|
1086
1090
|
|
|
1087
|
-
// The one in-process rollover,
|
|
1088
|
-
//
|
|
1089
|
-
//
|
|
1091
|
+
// The one in-process rollover, the exit-grace fallback: gather the generated state, wait for
|
|
1092
|
+
// idle, then start a fresh session whose first message is the handoff. A state change during
|
|
1093
|
+
// the wait sends the owner's text to this session as an ordinary message.
|
|
1090
1094
|
const rolloverInProcess = async (c: RolloverCtx, owner: string[], notice: string): Promise<void> => {
|
|
1091
1095
|
const previous = c.sessionFile;
|
|
1092
1096
|
const path = notePath(c.sessionId);
|
|
@@ -1186,8 +1190,8 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
1186
1190
|
{ customType: "main-guard.rollover", content: noteRequestFor(c, snap), display: false },
|
|
1187
1191
|
{ triggerTurn: true, deliverAs: "nextTurn" },
|
|
1188
1192
|
);
|
|
1189
|
-
} else if (terminal && snap.state === "ready" &&
|
|
1190
|
-
// flight !== null: an in-process rollover (fallback
|
|
1193
|
+
} else if (terminal && snap.state === "ready" && !relaunched && flight === null) {
|
|
1194
|
+
// flight !== null: an in-process rollover (the fallback) owns this session's end.
|
|
1191
1195
|
requestRelaunch(c, notePath(c.sessionId));
|
|
1192
1196
|
} else if (terminal && relaunched) {
|
|
1193
1197
|
// A tool result mid-run never restarts the session (I-20261024-4), and omp's interactive
|
|
@@ -1401,67 +1405,43 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
1401
1405
|
return changed ? { messages: mapped } : undefined;
|
|
1402
1406
|
});
|
|
1403
1407
|
|
|
1404
|
-
//
|
|
1405
|
-
//
|
|
1406
|
-
// `/main-rollover <text>`: the message becomes the owner's first message of the new session.
|
|
1408
|
+
// The relaunch is the only rollover path: a plain interactive message in the ready state
|
|
1409
|
+
// requests it, and every such message joins the pending request's draft, in order.
|
|
1407
1410
|
pi.on("input", (event, ctx) => {
|
|
1408
1411
|
const e = asRecord(event);
|
|
1409
1412
|
const c = asRolloverCtx(ctx);
|
|
1410
1413
|
const text = asString(e.text);
|
|
1411
1414
|
if (!cfg.rollover.enabled || !c || !isMain(ctx)) return undefined;
|
|
1412
1415
|
if (asString(e.source) !== "interactive" || text === "" || text.startsWith("/")) return undefined;
|
|
1413
|
-
if (
|
|
1414
|
-
if (
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
if (!requestRelaunch(c, notePath(c.sessionId), "")) return undefined;
|
|
1418
|
-
}
|
|
1419
|
-
if (appendToRelaunch(text)) c.notify("rollover in progress: your message goes to the new session");
|
|
1420
|
-
else c.notify("rollover in progress: your message could not be saved and was not sent; send it again after the rollover");
|
|
1421
|
-
// omp re-checks its deferred exit only when shutdown() is called again: re-arm per message.
|
|
1422
|
-
c.shutdown();
|
|
1423
|
-
return { handled: true };
|
|
1416
|
+
if (!relaunched) {
|
|
1417
|
+
if (rolloverSnapshot(c).state !== "ready") return undefined;
|
|
1418
|
+
// The message is the request's first owner text, so the editor draft is not carried.
|
|
1419
|
+
if (!requestRelaunch(c, notePath(c.sessionId), "")) return undefined;
|
|
1424
1420
|
}
|
|
1425
|
-
if (
|
|
1426
|
-
|
|
1421
|
+
if (appendToRelaunch(text)) c.notify("rollover in progress: your message goes to the new session");
|
|
1422
|
+
else c.notify("rollover in progress: your message could not be saved and was not sent; send it again after the rollover");
|
|
1423
|
+
// omp re-checks its deferred exit only when shutdown() is called again: re-arm per message.
|
|
1424
|
+
c.shutdown();
|
|
1425
|
+
return { handled: true };
|
|
1427
1426
|
});
|
|
1428
1427
|
|
|
1429
|
-
//
|
|
1428
|
+
// The rollover starts on its own (size + idle), and the owner's next message joins the
|
|
1429
|
+
// pending relaunch; the command only says so.
|
|
1430
1430
|
pi.registerCommand("main-rollover", {
|
|
1431
1431
|
description: "Start a fresh session from Main's handoff note; the rest of the message is the owner's first message",
|
|
1432
|
-
handler: async (
|
|
1432
|
+
handler: async (_args: unknown, ctx: unknown) => {
|
|
1433
1433
|
const c = asRolloverCtx(ctx);
|
|
1434
1434
|
if (!c) return;
|
|
1435
|
-
|
|
1436
|
-
if (process.env.NEURASTREAM_MAIN_LAUNCHER === "1") {
|
|
1437
|
-
c.notify("main-rollover: under neurastream main the rollover starts from your next message, not from this command.");
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
if (flight) {
|
|
1441
|
-
flight.push(text);
|
|
1442
|
-
c.notify("main-rollover: a rollover is already in progress; your message is added to its handoff.");
|
|
1443
|
-
return;
|
|
1444
|
-
}
|
|
1445
|
-
const path = notePath(c.sessionId);
|
|
1446
|
-
const state = rolloverSnapshot(c).state;
|
|
1447
|
-
if (state === "below") {
|
|
1448
|
-
c.notify("main-rollover: this session is below rollover.max_session_mb; nothing to roll over.");
|
|
1449
|
-
return;
|
|
1450
|
-
}
|
|
1451
|
-
if (state === "need-note") {
|
|
1452
|
-
c.notify(`main-rollover: no fresh handoff note at ${path}; Main must write it first.`);
|
|
1453
|
-
return;
|
|
1454
|
-
}
|
|
1455
|
-
if (state === "wait-jobs") {
|
|
1456
|
-
c.notify(`main-rollover: own jobs are still running (${c.runningJobs().join(", ")}); a rollover would cancel them.`);
|
|
1457
|
-
return;
|
|
1458
|
-
}
|
|
1459
|
-
await rolloverInProcess(c, [text], "main-rollover: collecting main-start state for the handoff (this can take a minute)…");
|
|
1435
|
+
c.notify("main-rollover: under neurastream main the rollover starts from your next message, not from this command.");
|
|
1460
1436
|
},
|
|
1461
1437
|
});
|
|
1462
1438
|
}
|
|
1463
1439
|
|
|
1464
1440
|
/** package.json omp.extensions entry. */
|
|
1465
1441
|
export default function ompExtension(pi: ExtensionHost): void {
|
|
1442
|
+
// The one switch (MAIN_ENV): plain `omp` runs nothing of neurastream — no hook, no command,
|
|
1443
|
+
// no config read. `neurastream main` sets it for its child (launch.ts), so anything the Main
|
|
1444
|
+
// session spawns inherits it and stays guarded.
|
|
1445
|
+
if (process.env[MAIN_ENV] !== "1") return;
|
|
1466
1446
|
createOmpAdapter(pi, loadConfig());
|
|
1467
1447
|
}
|
|
@@ -7,8 +7,8 @@ import { copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, readdirSync, re
|
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
import { dirname, join, resolve } from "node:path";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
|
-
import {
|
|
11
|
-
import { configFile
|
|
10
|
+
import { stripBlock } from "../../core/agents-md.ts";
|
|
11
|
+
import { configFile } from "../../core/config.ts";
|
|
12
12
|
|
|
13
13
|
import { adapterLiveFiles, liveAgentsMd } from "./doctor.ts";
|
|
14
14
|
// Registers the plugin-command matcher into core's writeTargets (side effect).
|
|
@@ -39,7 +39,7 @@ export interface InstallResult {
|
|
|
39
39
|
/** Left alone: not interactive, or answered no. */
|
|
40
40
|
skillsSkipped: string[];
|
|
41
41
|
overlay: "written" | "unchanged";
|
|
42
|
-
agentsMd: "
|
|
42
|
+
agentsMd: "removed" | "unchanged";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function ensureLink(link: string, target: string): void {
|
|
@@ -280,15 +280,17 @@ export function writeOverlay(file: string): "written" | "unchanged" {
|
|
|
280
280
|
return "written";
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
-
//
|
|
284
|
-
|
|
283
|
+
// Strips the managed block an older install wrote into the owner's AGENTS.md: Main gets the rules
|
|
284
|
+
// in its system prompt now. Bytes outside the markers stay; a file the strip leaves empty is removed.
|
|
285
|
+
// A malformed block is left alone; doctor reports it.
|
|
286
|
+
function removeAgentsMd(home: string): "removed" | "unchanged" {
|
|
285
287
|
const file = liveAgentsMd(home);
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
writeFileSync(file,
|
|
291
|
-
return "
|
|
288
|
+
if (!existsSync(file)) return "unchanged";
|
|
289
|
+
const { text, state } = stripBlock(readFileSync(file, "utf8"));
|
|
290
|
+
if (state !== "ok") return "unchanged";
|
|
291
|
+
if (text === "") unlinkSync(file);
|
|
292
|
+
else writeFileSync(file, text);
|
|
293
|
+
return "removed";
|
|
292
294
|
}
|
|
293
295
|
|
|
294
296
|
function linkPlugin(home: string): string {
|
|
@@ -331,7 +333,7 @@ export function installOmp(home: string, ask: ((question: string) => string) | n
|
|
|
331
333
|
linkInstalled(home);
|
|
332
334
|
const plugin = linkPlugin(home);
|
|
333
335
|
const overlay = writeOverlay(file);
|
|
334
|
-
const agentsMd =
|
|
336
|
+
const agentsMd = removeAgentsMd(home);
|
|
335
337
|
const skills = syncSkills(home, ask);
|
|
336
338
|
return {
|
|
337
339
|
plugin,
|
|
@@ -26,6 +26,13 @@ export function adapterLog(cfg: Config, line: string): void {
|
|
|
26
26
|
/** The harness the launcher runs. Tests pass another path through LaunchOptions. */
|
|
27
27
|
export const OMP_BIN = "omp";
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* The one main-only switch, and why an env var and not a flag or config key: children inherit
|
|
31
|
+
* the environment, so a tool starting `omp` from inside a Main session stays guarded — a flag
|
|
32
|
+
* would not travel. The adapter is dead without it (ompExtension in ./index.ts).
|
|
33
|
+
*/
|
|
34
|
+
export const MAIN_ENV = "NEURASTREAM_MAIN_LAUNCHER";
|
|
35
|
+
|
|
29
36
|
export interface ProxyPlan {
|
|
30
37
|
/** The command to spawn. */
|
|
31
38
|
cmd: string;
|
|
@@ -171,7 +178,8 @@ export async function runMainLauncher(args: string[], cfg: Config, opts: LaunchO
|
|
|
171
178
|
}
|
|
172
179
|
for (;;) {
|
|
173
180
|
const started = Date.now();
|
|
174
|
-
|
|
181
|
+
// The env, not a flag: the child inherits it, so an omp started from inside Main stays guarded.
|
|
182
|
+
const code = await runChild(proxy.cmd, [...proxy.prefix, ...runArgs], { ...process.env, [MAIN_ENV]: "1" });
|
|
175
183
|
const req = readRequest(started, cfg);
|
|
176
184
|
if (req === null) return code;
|
|
177
185
|
const installed = packageVersion(packageJsonPath());
|
package/src/cli/incident.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// `neurastream incident …`: the incident list Main must act on (store: src/core/incidents.ts).
|
|
2
2
|
// `list` prints incidents (--open: only the ones with no plan/dismiss/fixed yet; --json: the full
|
|
3
3
|
// records); `add` records Main's own finding (source "main"); `plan` records the plan that fixes
|
|
4
|
-
// an incident; `dismiss` records why an incident is not a bug
|
|
4
|
+
// an incident; `dismiss` records why an incident is not a bug; `propose` records Main's written reason
|
|
5
|
+
// (file:line proof) for a finding, which leaves the incident open.
|
|
5
6
|
|
|
6
7
|
import { ConfigError, loadConfig, type Config } from "../core/config.ts";
|
|
7
8
|
import {
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
dismissIncident,
|
|
10
11
|
openIncidents,
|
|
11
12
|
planIncident,
|
|
13
|
+
proposeIncident,
|
|
12
14
|
readIncidents,
|
|
13
15
|
type IncidentView,
|
|
14
16
|
} from "../core/incidents.ts";
|
|
@@ -16,6 +18,7 @@ import {
|
|
|
16
18
|
export const INCIDENT_USAGE = [
|
|
17
19
|
"usage: neurastream incident list [--open] [--json]",
|
|
18
20
|
' neurastream incident add "<summary>" --kind <k> [--evidence <text>]',
|
|
21
|
+
' neurastream incident propose <id> --why "<file:line and reason>"',
|
|
19
22
|
" neurastream incident plan <id> <plan.md>",
|
|
20
23
|
' neurastream incident dismiss <id> --why "<text>" [--owner "<quote>"]',
|
|
21
24
|
].join("\n");
|
|
@@ -91,6 +94,20 @@ export function dismissIncidentCmd(cfg: Config, id: string, why: string | undefi
|
|
|
91
94
|
return 0;
|
|
92
95
|
}
|
|
93
96
|
|
|
97
|
+
export function proposeIncidentCmd(cfg: Config, id: string, why: string | undefined): number {
|
|
98
|
+
if (!id || why === undefined) {
|
|
99
|
+
console.error(INCIDENT_USAGE);
|
|
100
|
+
return 2;
|
|
101
|
+
}
|
|
102
|
+
const problem = proposeIncident(cfg, id, why);
|
|
103
|
+
if (problem) {
|
|
104
|
+
console.error(problem);
|
|
105
|
+
return 1;
|
|
106
|
+
}
|
|
107
|
+
console.log(`incident ${id}: proposal recorded (still open)`);
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
94
111
|
export async function runIncident(args: string[]): Promise<number> {
|
|
95
112
|
let cfg: Config;
|
|
96
113
|
try {
|
|
@@ -104,6 +121,7 @@ export async function runIncident(args: string[]): Promise<number> {
|
|
|
104
121
|
if (sub === "add") return addIncidentCmd(cfg, rest);
|
|
105
122
|
if (sub === "plan") return planIncidentCmd(cfg, rest[0] ?? "", rest[1] ?? "");
|
|
106
123
|
if (sub === "dismiss") return dismissIncidentCmd(cfg, rest[0] ?? "", flagValue(rest, "--why"), flagValue(rest, "--owner"));
|
|
124
|
+
if (sub === "propose") return proposeIncidentCmd(cfg, rest[0] ?? "", flagValue(rest, "--why"));
|
|
107
125
|
console.error(INCIDENT_USAGE);
|
|
108
126
|
return 2;
|
|
109
127
|
}
|
package/src/core/agents-md.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// The managed block
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// The managed block: the rules from templates/AGENTS.md with the config's agent dir filled in,
|
|
2
|
+
// between two markers. Main puts them in its system prompt; install only strips an old copy from
|
|
3
|
+
// the owner's AGENTS.md, and everything outside the markers stays the owner's.
|
|
4
4
|
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
@@ -37,29 +37,8 @@ function span(text: string): { start: number; end: number } | null {
|
|
|
37
37
|
return { start: begin, end: end + END_MARK.length };
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
const at = span(fileText);
|
|
43
|
-
if (at) return fileText.slice(0, at.start) + block + fileText.slice(at.end);
|
|
44
|
-
if (fileText === "") return `${block}\n`;
|
|
45
|
-
return `${fileText}\n${block}\n`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// "missing": no block in the file. "stale": the block differs, or its markers are malformed.
|
|
49
|
-
export function blockState(fileText: string, block: string): "ok" | "stale" | "missing" {
|
|
50
|
-
let at: { start: number; end: number } | null;
|
|
51
|
-
try {
|
|
52
|
-
at = span(fileText);
|
|
53
|
-
} catch {
|
|
54
|
-
return "stale";
|
|
55
|
-
}
|
|
56
|
-
if (!at) return "missing";
|
|
57
|
-
return fileText.slice(at.start, at.end) === block ? "ok" : "stale";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Remove the marked block, keeping every byte outside the markers (uninstall's inverse of
|
|
61
|
-
// upsertBlock). "missing": there was no block. "stale": the markers are malformed — the text
|
|
62
|
-
// comes back untouched.
|
|
40
|
+
// Remove the marked block, keeping every byte outside the markers. "missing": there was no block.
|
|
41
|
+
// "stale": the markers are malformed, and the text comes back untouched.
|
|
63
42
|
export function stripBlock(fileText: string): { text: string; state: "ok" | "stale" | "missing" } {
|
|
64
43
|
let at: { start: number; end: number } | null;
|
|
65
44
|
try {
|
package/src/core/incidents.ts
CHANGED
|
@@ -34,9 +34,19 @@ export type ResolutionRec =
|
|
|
34
34
|
/** `ts` is the close time; older records (written before plan P5) may lack it. */
|
|
35
35
|
| { type: "fixed"; id: string; plan: string; ts?: number };
|
|
36
36
|
|
|
37
|
+
/** Main's written reason that a finding is or is not a bug (`incident propose`). Not a resolution: the incident stays open. */
|
|
38
|
+
export interface ProposalRec {
|
|
39
|
+
type: "propose";
|
|
40
|
+
id: string;
|
|
41
|
+
why: string;
|
|
42
|
+
ts: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
37
45
|
export interface IncidentView extends IncidentRec {
|
|
38
46
|
/** Last resolution record for the id; null while the incident is open. */
|
|
39
47
|
resolution: ResolutionRec | null;
|
|
48
|
+
/** Main's latest proposal for the id (`incident propose`); null when none. */
|
|
49
|
+
proposal: ProposalRec | null;
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
export interface IncidentInput {
|
|
@@ -57,7 +67,7 @@ export function defaultFingerprint(input: Pick<IncidentInput, "source" | "kind"
|
|
|
57
67
|
return q.sha(`${input.source}|${input.kind}|${input.summary.replace(/\s+/g, " ").trim().toLowerCase()}`);
|
|
58
68
|
}
|
|
59
69
|
|
|
60
|
-
function parseLine(line: string): IncidentRec | ResolutionRec | null {
|
|
70
|
+
function parseLine(line: string): IncidentRec | ResolutionRec | ProposalRec | null {
|
|
61
71
|
let rec: Record<string, unknown>;
|
|
62
72
|
try {
|
|
63
73
|
const parsed: unknown = JSON.parse(line);
|
|
@@ -77,6 +87,10 @@ function parseLine(line: string): IncidentRec | ResolutionRec | null {
|
|
|
77
87
|
if (typeof rec.why !== "string") return null;
|
|
78
88
|
return { type: "dismiss", id: rec.id, why: rec.why };
|
|
79
89
|
}
|
|
90
|
+
if (rec.type === "propose") {
|
|
91
|
+
if (typeof rec.why !== "string" || typeof rec.ts !== "number") return null;
|
|
92
|
+
return { type: "propose", id: rec.id, why: rec.why, ts: rec.ts };
|
|
93
|
+
}
|
|
80
94
|
if (rec.type !== undefined) return null;
|
|
81
95
|
if (typeof rec.fingerprint !== "string" || typeof rec.kind !== "string" || typeof rec.summary !== "string" || typeof rec.ts !== "number")
|
|
82
96
|
return null;
|
|
@@ -94,20 +108,22 @@ function parseLine(line: string): IncidentRec | ResolutionRec | null {
|
|
|
94
108
|
};
|
|
95
109
|
}
|
|
96
110
|
|
|
97
|
-
function readStore(file: string): { incidents: IncidentRec[]; resolutions: ResolutionRec[]; lines: string[] } {
|
|
111
|
+
function readStore(file: string): { incidents: IncidentRec[]; resolutions: ResolutionRec[]; proposals: ProposalRec[]; lines: string[] } {
|
|
98
112
|
let lines: string[] = [];
|
|
99
113
|
try {
|
|
100
114
|
lines = readFileSync(file, "utf8").split("\n").filter(l => l.trim());
|
|
101
115
|
} catch {}
|
|
102
116
|
const incidents: IncidentRec[] = [];
|
|
103
117
|
const resolutions: ResolutionRec[] = [];
|
|
118
|
+
const proposals: ProposalRec[] = [];
|
|
104
119
|
for (const line of lines) {
|
|
105
120
|
const rec = parseLine(line);
|
|
106
121
|
if (!rec) continue;
|
|
107
|
-
if ("type" in rec)
|
|
108
|
-
else
|
|
122
|
+
if (!("type" in rec)) incidents.push(rec);
|
|
123
|
+
else if (rec.type === "propose") proposals.push(rec);
|
|
124
|
+
else resolutions.push(rec);
|
|
109
125
|
}
|
|
110
|
-
return { incidents, resolutions, lines };
|
|
126
|
+
return { incidents, resolutions, proposals, lines };
|
|
111
127
|
}
|
|
112
128
|
|
|
113
129
|
function writeFile(cfg: Config, file: string, lines: string[]): void {
|
|
@@ -119,11 +135,16 @@ function writeFile(cfg: Config, file: string, lines: string[]): void {
|
|
|
119
135
|
export function readIncidents(cfg: Config): IncidentView[] {
|
|
120
136
|
const store = readStore(incidentsFile(cfg));
|
|
121
137
|
const views = new Map<string, IncidentView>();
|
|
122
|
-
for (const rec of store.incidents) views.set(rec.id, { ...rec, resolution: null });
|
|
138
|
+
for (const rec of store.incidents) views.set(rec.id, { ...rec, resolution: null, proposal: null });
|
|
123
139
|
for (const res of store.resolutions) {
|
|
124
140
|
const v = views.get(res.id);
|
|
125
141
|
if (v) v.resolution = res;
|
|
126
142
|
}
|
|
143
|
+
// A later propose replaces an earlier one: file order, last wins.
|
|
144
|
+
for (const p of store.proposals) {
|
|
145
|
+
const v = views.get(p.id);
|
|
146
|
+
if (v) v.proposal = p;
|
|
147
|
+
}
|
|
127
148
|
return [...views.values()];
|
|
128
149
|
}
|
|
129
150
|
|
|
@@ -148,7 +169,7 @@ export function addIncident(cfg: Config, input: IncidentInput, now = nowSec()):
|
|
|
148
169
|
return rec && !("type" in rec) && rec.id === open.id ? JSON.stringify(open) : line;
|
|
149
170
|
});
|
|
150
171
|
writeFile(cfg, file, lines);
|
|
151
|
-
return { incident: { ...open, resolution: null }, deduped: true };
|
|
172
|
+
return { incident: { ...open, resolution: null, proposal: null }, deduped: true };
|
|
152
173
|
}
|
|
153
174
|
const day = strftime(now, "%Y%m%d");
|
|
154
175
|
const prefix = `I-${day}-`;
|
|
@@ -166,7 +187,7 @@ export function addIncident(cfg: Config, input: IncidentInput, now = nowSec()):
|
|
|
166
187
|
};
|
|
167
188
|
mkdirSync(dirname(file), { recursive: true });
|
|
168
189
|
appendFileSync(file, `${JSON.stringify(rec)}\n`);
|
|
169
|
-
return { incident: { ...rec, resolution: null }, deduped: false };
|
|
190
|
+
return { incident: { ...rec, resolution: null, proposal: null }, deduped: false };
|
|
170
191
|
}
|
|
171
192
|
|
|
172
193
|
/**
|
|
@@ -202,6 +223,10 @@ export function planIncident(cfg: Config, id: string, planPath: string): string
|
|
|
202
223
|
/** The kinds plan-guard's recordFindings writes; only the owner's own words dismiss them. */
|
|
203
224
|
const FINDING_KINDS: Record<string, true> = { "agent-finding": true, "main-finding": true };
|
|
204
225
|
|
|
226
|
+
export function isFindingKind(kind: string): boolean {
|
|
227
|
+
return Object.hasOwn(FINDING_KINDS, kind);
|
|
228
|
+
}
|
|
229
|
+
|
|
205
230
|
export interface OwnerMessage {
|
|
206
231
|
at: number;
|
|
207
232
|
text: string;
|
|
@@ -226,11 +251,30 @@ export function ownerSaid(words: string, messages: OwnerMessage[], now: number):
|
|
|
226
251
|
return messages.some(m => now - m.at >= 0 && now - m.at <= 86400 && m.text.toLowerCase().replace(/\s+/g, " ").includes(quote));
|
|
227
252
|
}
|
|
228
253
|
|
|
254
|
+
/** The proof a proposal must cite: a file and a line, e.g. `src/core/guards.ts:40`. */
|
|
255
|
+
const PROOF_REF = /\S+:\d+/;
|
|
256
|
+
|
|
257
|
+
/** Records Main's reason that a finding is or is not a bug. A finding stays open after a proposal: the
|
|
258
|
+
* owner taps it on the phone page or a plan closes it. A newer proposal replaces the older one. */
|
|
259
|
+
export function proposeIncident(cfg: Config, id: string, why: string, now = nowSec()): string | null {
|
|
260
|
+
const file = incidentsFile(cfg);
|
|
261
|
+
const store = readStore(file);
|
|
262
|
+
const rec = store.incidents.find(i => i.id === id);
|
|
263
|
+
if (!rec) return `unknown incident ${id}`;
|
|
264
|
+
if (store.resolutions.some(r => r.id === id)) return `incident ${id} already has a resolution record`;
|
|
265
|
+
if (!isFindingKind(rec.kind)) return `refused: propose is for finding incidents (agent-finding, main-finding); ${id} is ${rec.kind}`;
|
|
266
|
+
if (!PROOF_REF.test(why)) return "refused: the why must cite the proof as file:line, e.g. src/core/guards.ts:40";
|
|
267
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
268
|
+
appendFileSync(file, `${JSON.stringify({ type: "propose", id, why: why.trim(), ts: now })}\n`);
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
|
|
229
272
|
/** Records why an incident is not a bug (or not worth fixing); an empty why is refused. A finding
|
|
230
273
|
* incident (kind "agent-finding"/"main-finding") is dismissed only with `owner` — a quote
|
|
231
274
|
* `ownerSaid` matches against the owner's own messages of the last 24 h (20261028_0900 P3: the
|
|
232
|
-
* agent that found the bug cannot also wave it away).
|
|
233
|
-
|
|
275
|
+
* agent that found the bug cannot also wave it away). `tapLogin` is the owner's login from the
|
|
276
|
+
* owner page's authenticated POST /incident ("false alarm" tap); only that handler passes it. */
|
|
277
|
+
export function dismissIncident(cfg: Config, id: string, why: string, owner?: string, tapLogin?: string): string | null {
|
|
234
278
|
const file = incidentsFile(cfg);
|
|
235
279
|
const store = readStore(file);
|
|
236
280
|
const rec = store.incidents.find(i => i.id === id);
|
|
@@ -238,7 +282,7 @@ export function dismissIncident(cfg: Config, id: string, why: string, owner?: st
|
|
|
238
282
|
const res = store.resolutions.filter(r => r.id === id).at(-1);
|
|
239
283
|
if (res) return `incident ${id} already has a ${res.type} record`;
|
|
240
284
|
if (!why.trim()) return "refused: an empty --why would hide the incident without a recorded reason";
|
|
241
|
-
if (
|
|
285
|
+
if (isFindingKind(rec.kind) && tapLogin === undefined) {
|
|
242
286
|
if (owner === undefined)
|
|
243
287
|
return `refused: a ${rec.kind} is dismissed only with the owner's words: --owner "<quote>" (part of an owner message of the last 24 h)`;
|
|
244
288
|
if (!ownerSaid(owner, readOwnerMessages(), nowSec()))
|
package/src/core/owner-ui.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { chatTier, currentTier, type Tier } from "./autonomy.ts";
|
|
|
16
16
|
import type { Config } from "./config.ts";
|
|
17
17
|
import { nowSec, strftime } from "./clock.ts";
|
|
18
18
|
import { cpuCount } from "./host.ts";
|
|
19
|
-
import { openIncidents } from "./incidents.ts";
|
|
19
|
+
import { dismissIncident, isFindingKind, openIncidents } from "./incidents.ts";
|
|
20
20
|
import { byText, knowledgeManifest, readKnowledgeTopicFile, urlField, urlValue, type KnowledgeEntry } from "./knowledge.ts";
|
|
21
21
|
import { log } from "./guards.ts";
|
|
22
22
|
import { readMetricEvents } from "./metrics.ts";
|
|
@@ -165,6 +165,8 @@ export interface IncidentRow {
|
|
|
165
165
|
kind: string;
|
|
166
166
|
summary: string;
|
|
167
167
|
count: number;
|
|
168
|
+
/** Main's latest written reason for a finding incident; null when none or not a finding. */
|
|
169
|
+
proposal: string | null;
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
/** A markdown table from the ranking board plus every non-table line, kept in order. */
|
|
@@ -267,7 +269,13 @@ export function ciRows(cfg: Config): CiRow[] {
|
|
|
267
269
|
}
|
|
268
270
|
|
|
269
271
|
export function incidentRows(cfg: Config): IncidentRow[] {
|
|
270
|
-
return openIncidents(cfg).map(i => ({
|
|
272
|
+
return openIncidents(cfg).map(i => ({
|
|
273
|
+
id: i.id,
|
|
274
|
+
kind: i.kind,
|
|
275
|
+
summary: i.summary,
|
|
276
|
+
count: i.count,
|
|
277
|
+
proposal: isFindingKind(i.kind) ? (i.proposal?.why ?? null) : null,
|
|
278
|
+
}));
|
|
271
279
|
}
|
|
272
280
|
|
|
273
281
|
export function scoresData(cfg: Config): ScoresData {
|
|
@@ -563,9 +571,20 @@ function ciHtml(rows: CiRow[]): string {
|
|
|
563
571
|
.join("")}</ul>`;
|
|
564
572
|
}
|
|
565
573
|
|
|
566
|
-
function incidentsHtml(rows: IncidentRow[]): string {
|
|
574
|
+
function incidentsHtml(rows: IncidentRow[], tab: string): string {
|
|
567
575
|
return `<ul class="incidents">${rows
|
|
568
|
-
.map(r =>
|
|
576
|
+
.map(r => {
|
|
577
|
+
const head = `<span class="mono">${esc(r.id)}</span> <span class="chip bad">${esc(r.kind)}</span> ${esc(r.summary)}${r.count > 1 ? ` · ${r.count}x` : ""}`;
|
|
578
|
+
if (!isFindingKind(r.kind)) return `<li>${head}</li>`;
|
|
579
|
+
const why = r.proposal === null ? `<em>Main has not said why yet</em>` : esc(r.proposal);
|
|
580
|
+
return `<li>${head}<div class="sub">${why}</div>
|
|
581
|
+
<form method="post" action="/incident" class="inline">
|
|
582
|
+
<input type="hidden" name="id" value="${esc(r.id)}">
|
|
583
|
+
<input type="hidden" name="tab" value="${esc(tab)}">
|
|
584
|
+
<button class="btn" type="submit" name="choice" value="bug">It's a bug — plan it</button>
|
|
585
|
+
<button class="btn" type="submit" name="choice" value="false">False alarm</button>
|
|
586
|
+
</form></li>`;
|
|
587
|
+
})
|
|
569
588
|
.join("")}</ul>`;
|
|
570
589
|
}
|
|
571
590
|
|
|
@@ -667,6 +686,12 @@ function receiptText(sent: string, params: URLSearchParams): string | null {
|
|
|
667
686
|
case "message":
|
|
668
687
|
text = `Sent to Main · ${strftime(nowSec(), "%H:%M")}`;
|
|
669
688
|
break;
|
|
689
|
+
case "incident-closed":
|
|
690
|
+
text = `Marked as a false alarm · ${strftime(nowSec(), "%H:%M")}`;
|
|
691
|
+
break;
|
|
692
|
+
case "incident-bug":
|
|
693
|
+
text = `Sent to Main to plan the fix · ${strftime(nowSec(), "%H:%M")}`;
|
|
694
|
+
break;
|
|
670
695
|
case "unlock": {
|
|
671
696
|
const minutes = Number(params.get("minutes"));
|
|
672
697
|
text = Number.isInteger(minutes) && minutes > 0 ? `Unlocked for ${minutes} min` : "Unlocked";
|
|
@@ -935,7 +960,7 @@ export function renderPage(cfg: Config, data: PageData, params: URLSearchParams,
|
|
|
935
960
|
const working =
|
|
936
961
|
data.agents === null ? na("Working now") : data.agents.length ? `<ul class="agents">${data.agents.map(agentRowHtml).join("")}</ul>` : `<p class="empty">No agents running</p>`;
|
|
937
962
|
const scores = data.scores === null ? na("Agent scores") : scoresHtml(data.scores);
|
|
938
|
-
const incidents = data.incidents === null ? na("Incidents") : data.incidents.length ? incidentsHtml(data.incidents) : `<p class="empty">No open incidents</p>`;
|
|
963
|
+
const incidents = data.incidents === null ? na("Incidents") : data.incidents.length ? incidentsHtml(data.incidents, tab) : `<p class="empty">No open incidents</p>`;
|
|
939
964
|
const merges = data.ci === null ? na("Merges") : data.ci.length ? ciHtml(data.ci) : `<p class="empty">No CI runs recorded</p>`;
|
|
940
965
|
const machine = data.machine === null ? na("Machine") : machineHtml(cfg, data.machine);
|
|
941
966
|
const body =
|
|
@@ -1177,6 +1202,47 @@ function handleAnswer(cfg: Config, source: RunSource, fields: Record<string, str
|
|
|
1177
1202
|
return redirect(sentTo(fields.tab ?? "", "sent=answer"));
|
|
1178
1203
|
}
|
|
1179
1204
|
|
|
1205
|
+
// ---- POST /incident (plan P3): the owner's tap on a finding: "false alarm" closes it, "bug" plans it ----
|
|
1206
|
+
|
|
1207
|
+
function handleIncident(cfg: Config, fields: Record<string, string>, login: string, wantsJson: boolean): Response {
|
|
1208
|
+
const id = (fields.id ?? "").trim();
|
|
1209
|
+
const choice = (fields.choice ?? "").trim();
|
|
1210
|
+
const fail = (error: string, status: number): Response => (wantsJson ? jsonFail(error, status) : textRes(error, status));
|
|
1211
|
+
if (choice !== "bug" && choice !== "false") return fail("choice must be bug or false", 400);
|
|
1212
|
+
const view = openIncidents(cfg).find(i => i.id === id);
|
|
1213
|
+
if (!view) return fail("incident is not open", 409);
|
|
1214
|
+
if (!isFindingKind(view.kind)) return fail("only a finding is tapped here", 409);
|
|
1215
|
+
if (choice === "false") {
|
|
1216
|
+
const why = `owner tapped "false alarm" on the phone page (${login}): ${view.proposal?.why ?? "no reason given"}`;
|
|
1217
|
+
const err = dismissIncident(cfg, id, why, undefined, login);
|
|
1218
|
+
if (err) return fail(err, 409);
|
|
1219
|
+
if (wantsJson) return jsonSent("incident-closed", receiptText("incident-closed", new URLSearchParams()));
|
|
1220
|
+
return redirect(sentTo(fields.tab ?? "", "sent=incident-closed"));
|
|
1221
|
+
}
|
|
1222
|
+
storeOwnerMessage(`${id}: it's a bug — plan it`, login, []);
|
|
1223
|
+
if (wantsJson) return jsonSent("incident-bug", receiptText("incident-bug", new URLSearchParams()));
|
|
1224
|
+
return redirect(sentTo(fields.tab ?? "", "sent=incident-bug"));
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/** Stores an owner message (text and images) under a new id and inboxes it for Main (P13/P14). */
|
|
1228
|
+
function storeOwnerMessage(text: string, login: string, images: { bytes: Uint8Array; kind: string }[]): void {
|
|
1229
|
+
const ts = nowSec();
|
|
1230
|
+
// The dir name starts with a whole-second ts: the sweep and the image route both parse it.
|
|
1231
|
+
const id = `${Math.floor(ts)}-${randomUUID().slice(0, 6)}`;
|
|
1232
|
+
const dir = `${ownerMessagesDir()}/${id}`;
|
|
1233
|
+
mkdirSync(dir, { recursive: true });
|
|
1234
|
+
const names: string[] = [];
|
|
1235
|
+
for (let i = 0; i < images.length; i++) {
|
|
1236
|
+
const name = `${i + 1}.${IMAGE_EXT[images[i]!.kind]}`;
|
|
1237
|
+
writeFileSync(`${dir}/${name}`, images[i]!.bytes);
|
|
1238
|
+
names.push(name);
|
|
1239
|
+
}
|
|
1240
|
+
writeFileSync(`${dir}/message.json`, `${JSON.stringify({ ts, text, login, images: names })}\n`);
|
|
1241
|
+
mkdirSync(stateDirPath(), { recursive: true });
|
|
1242
|
+
// The text stays out of owner-inbox.jsonl; Main reads message.json through the id (P14).
|
|
1243
|
+
appendFileSync(inboxPath(), `${JSON.stringify({ ts, kind: "message", id, login })}\n`);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1180
1246
|
// ---- POST /message (plan P13): the owner's one-way note plus images, inboxed by id ----
|
|
1181
1247
|
|
|
1182
1248
|
async function handleMessage(req: Request, login: string, wantsJson: boolean): Promise<Response> {
|
|
@@ -1204,21 +1270,7 @@ async function handleMessage(req: Request, login: string, wantsJson: boolean): P
|
|
|
1204
1270
|
if (!kind) return fail("attachments must be PNG, JPEG, GIF or WEBP images — the type is read from the file itself");
|
|
1205
1271
|
images.push({ bytes: data, kind });
|
|
1206
1272
|
}
|
|
1207
|
-
|
|
1208
|
-
// The dir name starts with a whole-second ts: the sweep and the image route both parse it.
|
|
1209
|
-
const id = `${Math.floor(ts)}-${randomUUID().slice(0, 6)}`;
|
|
1210
|
-
const dir = `${ownerMessagesDir()}/${id}`;
|
|
1211
|
-
mkdirSync(dir, { recursive: true });
|
|
1212
|
-
const names: string[] = [];
|
|
1213
|
-
for (let i = 0; i < images.length; i++) {
|
|
1214
|
-
const name = `${i + 1}.${IMAGE_EXT[images[i]!.kind]}`;
|
|
1215
|
-
writeFileSync(`${dir}/${name}`, images[i]!.bytes);
|
|
1216
|
-
names.push(name);
|
|
1217
|
-
}
|
|
1218
|
-
writeFileSync(`${dir}/message.json`, `${JSON.stringify({ ts, text, login, images: names })}\n`);
|
|
1219
|
-
mkdirSync(stateDirPath(), { recursive: true });
|
|
1220
|
-
// The text stays out of owner-inbox.jsonl; Main reads message.json through the id (P14).
|
|
1221
|
-
appendFileSync(inboxPath(), `${JSON.stringify({ ts, kind: "message", id, login })}\n`);
|
|
1273
|
+
storeOwnerMessage(text, login, images);
|
|
1222
1274
|
if (wantsJson) return jsonSent("message", receiptText("message", new URLSearchParams()));
|
|
1223
1275
|
return redirect("/?sent=message");
|
|
1224
1276
|
}
|
|
@@ -1463,6 +1515,9 @@ export function startOwnerUi(opts: OwnerUiOptions): OwnerUiServer {
|
|
|
1463
1515
|
if (url.pathname === "/message") {
|
|
1464
1516
|
res = await handleMessage(req, login, wantsJson);
|
|
1465
1517
|
code = res.status;
|
|
1518
|
+
} else if (url.pathname === "/incident") {
|
|
1519
|
+
res = handleIncident(cfg, await fieldsOf(req), login, wantsJson);
|
|
1520
|
+
code = res.status;
|
|
1466
1521
|
} else if (url.pathname === "/answer") {
|
|
1467
1522
|
res = handleAnswer(cfg, source, await fieldsOf(req), login, wantsJson);
|
|
1468
1523
|
code = res.status;
|
package/src/core/rollover.ts
CHANGED
|
@@ -112,7 +112,7 @@ export const OWNER_AWAY =
|
|
|
112
112
|
"Owner away (automatic rollover). Continue the work in the note and the queue; the owner reads results later.";
|
|
113
113
|
|
|
114
114
|
/** The one-time note instruction for Main's next turn. `reason` (a stale install) names both versions and replaces the size line. */
|
|
115
|
-
export function noteRequest(path: string,
|
|
115
|
+
export function noteRequest(path: string, reason = ""): string {
|
|
116
116
|
return [
|
|
117
117
|
reason
|
|
118
118
|
? `${NOTE_REQUEST_PREFIX} a new neurastream version is installed (${reason}).`
|
|
@@ -120,9 +120,7 @@ export function noteRequest(path: string, auto = false, reason = ""): string {
|
|
|
120
120
|
`Write a handoff note to ${path} (overwrite it). Cover the work in progress and its state, the decisions made and why, the next step, and the files involved.`,
|
|
121
121
|
"Do not list holds or owner blockers in the note; they come from the plans' WAITING on owner lines.",
|
|
122
122
|
"Do not state which agents or providers are rate-limited or free; that comes from agent-ledger --cap.",
|
|
123
|
-
|
|
124
|
-
? "As soon as this note is written and no own jobs run, this session restarts into a fresh one that starts from this note verbatim plus the generated main-start state."
|
|
125
|
-
: "When the owner's next message arrives, this session closes and a fresh one starts from that note verbatim plus the generated main-start state.",
|
|
123
|
+
"As soon as this note is written and none of its own jobs are running, this session restarts into a fresh one that starts from this note verbatim plus the generated main-start state.",
|
|
126
124
|
].join("\n");
|
|
127
125
|
}
|
|
128
126
|
|