neurastream 0.2.41 → 0.2.42
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 +14 -7
- 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/core/agents-md.ts +5 -26
- package/src/core/rollover.ts +2 -4
package/README.md
CHANGED
|
@@ -31,9 +31,18 @@ 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;
|
|
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
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. |
|
|
36
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
|
+
```
|
|
45
|
+
|
|
37
46
|
## Requirements
|
|
38
47
|
|
|
39
48
|
- [Bun](https://bun.sh) 1.x
|
|
@@ -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.
|
|
@@ -365,11 +373,10 @@ Live copies are never hand-edited. `neurastream doctor` names each hand-edited i
|
|
|
365
373
|
|
|
366
374
|
## AGENTS.md block
|
|
367
375
|
|
|
368
|
-
|
|
376
|
+
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
377
|
|
|
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.
|
|
378
|
+
- Yours: every line outside the markers. Install keeps it byte for byte; a file the strip leaves empty is removed.
|
|
379
|
+
- Leftover: markers still in the file, malformed ones included. Install leaves them alone; `neurastream doctor` reports `stale: neurastream block still in <file>`.
|
|
373
380
|
- 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
381
|
|
|
375
382
|
## 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/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/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
|
|