neurastream 0.1.10 → 0.1.11

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 CHANGED
@@ -97,6 +97,8 @@ There are two modes:
97
97
  - 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.
98
98
  - 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.
99
99
 
100
+ 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.
101
+
100
102
  In both modes:
101
103
 
102
104
  - A note counts only if it was written after the threshold was crossed and is at most one hour old.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neurastream",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Guardrails for running many AI coding agents at once: plan queue, blockers, call budgets, provider caps, scoring, merge-verified close.",
5
5
  "keywords": ["ai-agents", "coding-agents", "orchestration", "guardrails", "omp", "bun", "cli"],
6
6
  "homepage": "https://github.com/umiddey/neurastream#readme",
@@ -1,7 +1,7 @@
1
1
  // `neurastream main [args…]`: runs the harness in a loop. Under this launcher (env
2
2
  // NEURASTREAM_MAIN_LAUNCHER=1) a session that is over the rollover size and idle writes
3
- // relaunch.json just before it exits; the launcher then starts a fresh harness whose only argument
4
- // is the handoff. Plain `omp` never gets the flag, so it never relaunches.
3
+ // relaunch.json just before it exits; the launcher then starts a fresh harness with the owner's
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
7
  import { mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
@@ -16,6 +16,53 @@ import { adapterLog } from "./index.ts";
16
16
  /** The harness the launcher runs. Tests pass another path through LaunchOptions. */
17
17
  export const OMP_BIN = "omp";
18
18
 
19
+ /** Flags that take the next argument as their value (omp 18.11.1 --help shows them as `--flag=<value>`). */
20
+ export const VALUE_FLAGS: Record<string, true> = {
21
+ "--model": true, "--smol": true, "--slow": true, "--plan": true, "--goal": true, "--prewalk-into": true,
22
+ "--plan-yolo-into": true, "--provider": true, "--api-key": true, "--system-prompt": true,
23
+ "--system-prompt-template": true, "--append-system-prompt": true, "--profile": true, "--alias": true,
24
+ "--cwd": true, "--mode": true, "--config": true, "--add-dir": true, "--restore": true, "--session-dir": true,
25
+ "--models": true, "--tools": true, "--thinking": true, "--service-tier": true, "--hook": true, "-e": true,
26
+ "--extension": true, "--skills": true, "--export": true, "--max-time": true, "--approval-mode": true,
27
+ "--plugin-dir": true,
28
+ };
29
+
30
+ /** Session-picking and one-shot flags: a relaunch never carries them, with their value if they take one. */
31
+ const DROPPED_FLAGS: Record<string, true> = {
32
+ "-r": true, "--resume": true, "--restore": true, "-c": true, "--continue": true, "--goal": true,
33
+ "--from-claude": true, "--from-codex": true, "--export": true, "--alias": true, "-p": true, "--print": true,
34
+ };
35
+
36
+ /** Whether `flag` takes `next` as its value: VALUE_FLAGS always do; `-r` only when `next` is not a flag. */
37
+ function takesValue(flag: string, next: string | undefined): boolean {
38
+ if (next === undefined) return false;
39
+ if (VALUE_FLAGS[flag] === true) return true;
40
+ return (flag === "-r" || flag === "--resume") && !next.startsWith("-");
41
+ }
42
+
43
+ /**
44
+ * The owner's flags for a relaunch, from the first run's args. Positional arguments (the first
45
+ * message) and session-picking or one-shot flags, with their values, are dropped; every other flag
46
+ * keeps its value. Everything after a bare `--` is positional.
47
+ */
48
+ export function carriedArgs(args: string[]): string[] {
49
+ const out: string[] = [];
50
+ for (let i = 0; i < args.length; i++) {
51
+ const arg = args[i] ?? "";
52
+ if (arg === "--") break;
53
+ if (!arg.startsWith("-")) continue;
54
+ const eq = arg.indexOf("=");
55
+ const flag = eq === -1 ? arg : arg.slice(0, eq);
56
+ const valued = eq === -1 && takesValue(flag, args[i + 1]);
57
+ if (DROPPED_FLAGS[flag] !== true) {
58
+ out.push(arg);
59
+ if (valued) out.push(args[i + 1] ?? "");
60
+ }
61
+ if (valued) i++;
62
+ }
63
+ return out;
64
+ }
65
+
19
66
  /** Handoffs up to this many bytes go in the first message; larger ones go to a file. */
20
67
  const MAX_INLINE_HANDOFF = 100_000;
21
68
 
@@ -36,6 +83,7 @@ interface RelaunchRequest {
36
83
  export async function runMainLauncher(args: string[], cfg: Config, opts: LaunchOptions = {}): Promise<number> {
37
84
  applyQueueEnv(cfg);
38
85
  const harness = opts.harness ?? OMP_BIN;
86
+ const carried = carriedArgs(args);
39
87
  let runArgs = args;
40
88
  for (;;) {
41
89
  rmSync(relaunchPath(), { force: true });
@@ -43,9 +91,9 @@ export async function runMainLauncher(args: string[], cfg: Config, opts: LaunchO
43
91
  const code = await runChild(harness, runArgs);
44
92
  const req = takeRequest(started, cfg);
45
93
  if (req === null) return code;
46
- const next = await nextArgs(req, cfg);
47
- if (next === null) return code;
48
- runArgs = next;
94
+ const message = await nextMessage(req, cfg);
95
+ if (message === null) return code;
96
+ runArgs = [...carried, message];
49
97
  }
50
98
  }
51
99
 
@@ -87,8 +135,8 @@ function takeRequest(since: number, cfg: Config): RelaunchRequest | null {
87
135
  }
88
136
  }
89
137
 
90
- /** The next run's arguments: the handoff inline, or a file the inline argument points at. */
91
- async function nextArgs(req: RelaunchRequest, cfg: Config): Promise<string[] | null> {
138
+ /** The next run's message: the handoff inline, or the pointer to a file that holds it. */
139
+ async function nextMessage(req: RelaunchRequest, cfg: Config): Promise<string | null> {
92
140
  let note: string;
93
141
  try {
94
142
  note = readFileSync(req.notePath, "utf8");
@@ -107,13 +155,11 @@ async function nextArgs(req: RelaunchRequest, cfg: Config): Promise<string[] | n
107
155
  const bytes = Buffer.byteLength(handoff);
108
156
  if (bytes <= MAX_INLINE_HANDOFF) {
109
157
  adapterLog(cfg, `rollover: relaunch from ${req.previousSessionFile} with the handoff inline (${bytes} bytes)`);
110
- return [handoff];
158
+ return handoff;
111
159
  }
112
160
  const file = join(dirname(req.notePath), `${basename(req.notePath, ".md")}.handoff.md`);
113
161
  mkdirSync(dirname(file), { recursive: true });
114
162
  writeFileSync(file, handoff);
115
163
  adapterLog(cfg, `rollover: relaunch from ${req.previousSessionFile} with the handoff in ${file} (${bytes} bytes)`);
116
- return [
117
- `Read ${file} first: it is the handoff from your previous session (too long for one message).`,
118
- ];
164
+ return `Read ${file} first: it is the handoff from your previous session (too long for one message).`;
119
165
  }