neurastream 0.3.33 → 0.3.35
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/package.json
CHANGED
|
@@ -52,7 +52,7 @@ import { createLimitWake } from "./limit-wake.ts";
|
|
|
52
52
|
import "./package-ops.ts";
|
|
53
53
|
import { createRateLimitController, limitProbeSpawn, recordProviderOutFromRateLimit, recordProviderOutFromTask } from "./rate-limit-controller.ts";
|
|
54
54
|
import { createRolloverController } from "./rollover-controller.ts";
|
|
55
|
-
import { defaultCompletedResults, defaultRunSource, runIdOf } from "./sessions.ts";
|
|
55
|
+
import { defaultCompletedResults, defaultRunSource, runIdOf, SPAWN_NAME_ENTRY } from "./sessions.ts";
|
|
56
56
|
import { parseTraceFile } from "./traces.ts";
|
|
57
57
|
import { asCtx, asRecord, asRolloverCtx, asString, call, isMain, lastAssistantIn, toExtensionResult, type EventReply, type ExtensionHost, type RolloverCtx } from "./types.ts";
|
|
58
58
|
|
|
@@ -422,6 +422,12 @@ export function createOmpAdapter(pi: ExtensionHost, initial: Config, freshConfig
|
|
|
422
422
|
|
|
423
423
|
pi.on("session_start", (_e, ctx) => {
|
|
424
424
|
const c = asCtx(ctx);
|
|
425
|
+
// A herdr-spawned helper names its own session file (plan 20261205_1947): without the
|
|
426
|
+
// marker the dated file builds as `MAIN hh-mm-ss`, kind main, and agent-score refuses
|
|
427
|
+
// the spawn --name. Task subs (no ROLE) and Main write nothing.
|
|
428
|
+
if (process.env.NEURASTREAM_ROLE === "sub" && process.env.NEURASTREAM_AGENT_ID) {
|
|
429
|
+
pi.appendEntry(SPAWN_NAME_ENTRY, { id: process.env.NEURASTREAM_AGENT_ID });
|
|
430
|
+
}
|
|
425
431
|
// Original: proceed only when no agent is set or it is the main session.
|
|
426
432
|
if (c.hasAgent && c.kind !== "main") return;
|
|
427
433
|
// One live Main session per id (plan 20261103_1146 P2): the first session_start in this
|
|
@@ -63,6 +63,11 @@ function costOf(m: Record<string, unknown>): number {
|
|
|
63
63
|
return c && typeof c.total === "number" ? c.total : 0;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/** Custom session-entry type that names a herdr-spawned helper (plan 20261205_1947): the
|
|
67
|
+
* extension host writes `{ id: <name> }` at session_start; `build` reads it back so
|
|
68
|
+
* `agent-score`/`agent-ledger` see the run as a named sub instead of `MAIN hh-mm-ss`. */
|
|
69
|
+
export const SPAWN_NAME_ENTRY = "neurastream.agent";
|
|
70
|
+
|
|
66
71
|
/** Ledger run id for a session file: `MAIN <HH-MM-SS>` for dated main files, stem otherwise. */
|
|
67
72
|
export function runIdOf(file: string): string {
|
|
68
73
|
const stem = basename(file).slice(0, -6);
|
|
@@ -124,8 +129,10 @@ function build(file: string, cfg: Config, mtime: number, agentsDir: string): Run
|
|
|
124
129
|
return null;
|
|
125
130
|
}
|
|
126
131
|
const stem = basename(file).slice(0, -6);
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
// A herdr-spawned helper's dated file carries the spawn-name marker (plan 20261205_1947);
|
|
133
|
+
// seeing it flips both below so the file builds as a named sub.
|
|
134
|
+
let isMain = /^\d{4}/.test(stem);
|
|
135
|
+
let id = runIdOf(file);
|
|
129
136
|
let model = "unknown";
|
|
130
137
|
let scoreModel = "unknown";
|
|
131
138
|
let sawProviderModel = false;
|
|
@@ -159,6 +166,15 @@ function build(file: string, cfg: Config, mtime: number, agentsDir: string): Run
|
|
|
159
166
|
} catch {
|
|
160
167
|
continue;
|
|
161
168
|
}
|
|
169
|
+
if (d.type === "custom" && d.customType === SPAWN_NAME_ENTRY) {
|
|
170
|
+
const named = asObj(d.data)?.id;
|
|
171
|
+
if (typeof named === "string" && named) {
|
|
172
|
+
// The spawn --name replaces the dated file's `MAIN hh-mm-ss` id; every
|
|
173
|
+
// isMain / id.startsWith("MAIN") check below now sees a sub.
|
|
174
|
+
id = named;
|
|
175
|
+
isMain = false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
162
178
|
const ts = typeof d.timestamp === "string" ? parseTs(d.timestamp) : null;
|
|
163
179
|
if (ts !== null) {
|
|
164
180
|
first = first ?? ts;
|
|
@@ -8,6 +8,8 @@ export interface ExtensionHost {
|
|
|
8
8
|
registerCommand(name: string, opts: { description?: string; handler: (args: unknown, ctx: unknown) => unknown }): void;
|
|
9
9
|
sendUserMessage(content: string | ({ type: "text"; text: string } | { type: "image"; data: string; mimeType: string })[]): void;
|
|
10
10
|
sendMessage(message: { customType: string; content: string; display: boolean }, options: { triggerTurn: boolean; deliverAs: "nextTurn" }): void;
|
|
11
|
+
/** Store a `custom` entry in the session file without entering model context (omp API). */
|
|
12
|
+
appendEntry(customType: string, data?: unknown): void;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
/** The parts of a harness call context the handlers look at. */
|
package/src/core/config.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { homedir } from "node:os";
|
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import type { WriteCheckConfig } from "./write-check.ts";
|
|
9
|
-
import { SPAWN_ROLES, type SpawnDirection, type SpawnProfileConfig, type SpawnRole } from "./runner.ts";
|
|
9
|
+
import { SPAWN_DIRECTIONS, SPAWN_ROLES, type SpawnDirection, type SpawnProfileConfig, type SpawnRole } from "./runner.ts";
|
|
10
10
|
import { teamConfigError } from "./team-labels.ts";
|
|
11
11
|
|
|
12
12
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
@@ -574,8 +574,8 @@ function checkSpawnConfig(spawn: Config["spawn"]): void {
|
|
|
574
574
|
if (typeof spawn.fallback_harness !== "string" || (spawn.fallback_harness !== "" && !SPAWN_SLUG_RE.test(spawn.fallback_harness))) {
|
|
575
575
|
throw new ConfigError("spawn.fallback_harness must be empty or a valid harness slug");
|
|
576
576
|
}
|
|
577
|
-
if (
|
|
578
|
-
throw new ConfigError('spawn.direction must be "right" or "
|
|
577
|
+
if (!SPAWN_DIRECTIONS.includes(spawn.direction)) {
|
|
578
|
+
throw new ConfigError('spawn.direction must be "right", "down" or "tab"');
|
|
579
579
|
}
|
|
580
580
|
if (typeof spawn.start_timeout_ms !== "number" || !Number.isFinite(spawn.start_timeout_ms) || !(spawn.start_timeout_ms > 0)) {
|
|
581
581
|
throw new ConfigError("spawn.start_timeout_ms must be a number > 0");
|
|
@@ -613,8 +613,8 @@ function checkSpawnConfig(spawn: Config["spawn"]): void {
|
|
|
613
613
|
if (raw.role !== undefined && (typeof raw.role !== "string" || !SPAWN_ROLES.includes(raw.role as SpawnRole))) {
|
|
614
614
|
throw new ConfigError(`${at}.role must be "implementer", "planner", or "reviewer"`);
|
|
615
615
|
}
|
|
616
|
-
if (raw.direction !== undefined &&
|
|
617
|
-
throw new ConfigError(`${at}.direction must be "right" or "
|
|
616
|
+
if (raw.direction !== undefined && !SPAWN_DIRECTIONS.includes(raw.direction as SpawnDirection)) {
|
|
617
|
+
throw new ConfigError(`${at}.direction must be "right", "down" or "tab"`);
|
|
618
618
|
}
|
|
619
619
|
if (raw.start_timeout_ms !== undefined && (typeof raw.start_timeout_ms !== "number" || !Number.isFinite(raw.start_timeout_ms) || !(raw.start_timeout_ms > 0))) {
|
|
620
620
|
throw new ConfigError(`${at}.start_timeout_ms must be a number > 0`);
|
package/src/core/runner.ts
CHANGED
|
@@ -6,8 +6,9 @@ import type { Config } from "./config.ts";
|
|
|
6
6
|
/** Normalized lifecycle state reported by an agent runner. */
|
|
7
7
|
export type AgentLifecycleState = "idle" | "working" | "blocked" | "done" | "unknown";
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
9
|
+
/** Where a helper opens: a pane split right/down of Main's pane, or its own new tab. */
|
|
10
|
+
export const SPAWN_DIRECTIONS = ["right", "down", "tab"] as const;
|
|
11
|
+
export type SpawnDirection = (typeof SPAWN_DIRECTIONS)[number];
|
|
11
12
|
|
|
12
13
|
/** Supported functional roles for spawn profiles used in cross-harness routing. */
|
|
13
14
|
export type SpawnRole = "implementer" | "planner" | "reviewer";
|
|
@@ -175,8 +176,8 @@ export function resolveSpawnProfile(agentName: string, cfg: Config, opts: Resolv
|
|
|
175
176
|
if (opts.knownRunners && !opts.knownRunners.includes(runner)) {
|
|
176
177
|
throw new Error(`spawn profile "${trimmed}": unknown runner "${runner}"; known: ${opts.knownRunners.join(", ")}`);
|
|
177
178
|
}
|
|
178
|
-
if (direction
|
|
179
|
-
throw new Error(`spawn profile "${trimmed}": direction must be "right" or "
|
|
179
|
+
if (!SPAWN_DIRECTIONS.includes(direction)) {
|
|
180
|
+
throw new Error(`spawn profile "${trimmed}": direction must be "right", "down" or "tab"`);
|
|
180
181
|
}
|
|
181
182
|
if (!Number.isFinite(startTimeoutMs) || startTimeoutMs <= 0) {
|
|
182
183
|
throw new Error(`spawn profile "${trimmed}": start_timeout_ms must be > 0`);
|
|
@@ -150,25 +150,22 @@ export function createHerdrRunner(opts: HerdrRunnerOptions = {}): AgentRunner {
|
|
|
150
150
|
if (checkEnv && activeEnv.HERDR_ENV !== "1") {
|
|
151
151
|
throw new Error("herdr start: HERDR_ENV=1 is required to split a pane inside Herdr");
|
|
152
152
|
}
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
"
|
|
156
|
-
"--current",
|
|
157
|
-
"--direction",
|
|
158
|
-
spec.direction ?? "right",
|
|
159
|
-
"--cwd",
|
|
160
|
-
spec.cwd,
|
|
161
|
-
];
|
|
153
|
+
const tab = spec.direction === "tab";
|
|
154
|
+
const openArgs = tab
|
|
155
|
+
? ["tab", "create", "--cwd", spec.cwd, "--label", name]
|
|
156
|
+
: ["pane", "split", "--current", "--direction", spec.direction ?? "right", "--cwd", spec.cwd];
|
|
162
157
|
for (const key of Object.keys(spec.env).sort()) {
|
|
163
|
-
|
|
158
|
+
openArgs.push("--env", `${key}=${spec.env[key] ?? ""}`);
|
|
164
159
|
}
|
|
165
|
-
|
|
160
|
+
openArgs.push("--no-focus");
|
|
166
161
|
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
const
|
|
162
|
+
const action = tab ? "tab create" : "pane split";
|
|
163
|
+
const openRes = await run(action, openArgs);
|
|
164
|
+
const result = asObj(parseJson(openRes.stdout)?.result);
|
|
165
|
+
const field = tab ? "root_pane" : "pane";
|
|
166
|
+
const parsedPaneId = asObj(result?.[field])?.pane_id;
|
|
170
167
|
if (typeof parsedPaneId !== "string" || parsedPaneId.trim() === "") {
|
|
171
|
-
throw new Error(`herdr
|
|
168
|
+
throw new Error(`herdr ${action} did not return .result.${field}.pane_id: ${openRes.stdout.trim()}`);
|
|
172
169
|
}
|
|
173
170
|
paneId = parsedPaneId;
|
|
174
171
|
createdPane = true;
|
package/templates/config.yml
CHANGED
|
@@ -28,7 +28,7 @@ harness: omp # the adapter that serves runs, traces, launch, install and docto
|
|
|
28
28
|
spawn:
|
|
29
29
|
default_runner: herdr # runner backend used when spawning helper panes
|
|
30
30
|
fallback_harness: "" # optional fallback harness used if primary harness fails to start
|
|
31
|
-
direction: right #
|
|
31
|
+
direction: right # where new helpers open: right or down (pane split beside Main) or tab (own new tab)
|
|
32
32
|
start_timeout_ms: 30000 # startup readiness timeout in milliseconds
|
|
33
33
|
timeout_ms: 600000 # default prompt and wait timeout in milliseconds
|
|
34
34
|
profiles: {} # per-agent overrides ({harness, fallback_harness, runner, model, provider, role, direction, start_timeout_ms, timeout_ms, args, env})
|