@nodii/dev 0.6.209 → 0.6.210
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 +56 -0
- package/dist/accounts.js +17 -1
- package/dist/cli.js +10 -0
- package/dist/core.js +1 -1
- package/dist/drill-stub.js +213 -0
- package/dist/drill.js +1081 -0
- package/dist/lane-supervisor.js +17 -10
- package/dist/runtime-launcher.js +41 -6
- package/package.json +1 -1
package/dist/lane-supervisor.js
CHANGED
|
@@ -104,6 +104,8 @@ const FAILURE_SCAN_LINES = 40;
|
|
|
104
104
|
const NO_FAILURE = Object.freeze({ kind: null, resetAt: null, line: null });
|
|
105
105
|
|
|
106
106
|
const SUCCEEDED = Symbol("succeeded");
|
|
107
|
+
/** The account a stub run's failure is recorded against (DEV-PROCESS-1): never a real profile. */
|
|
108
|
+
export const STUB_ACCOUNT = "stub:drill";
|
|
107
109
|
|
|
108
110
|
/**
|
|
109
111
|
* The text of a log line the runtime itself wrote about its failure; null for
|
|
@@ -444,7 +446,8 @@ export async function reportLaneExit({ runId, laneKey, exitCode, signal, worktre
|
|
|
444
446
|
const readAccountFailure = async (logTail) => {
|
|
445
447
|
const failure = signal ? NO_FAILURE : classifyRuntimeFailure(logTail, { now: now() });
|
|
446
448
|
if (!failure.kind) return { failure, note: "" };
|
|
447
|
-
|
|
449
|
+
// The drill's stub has no account: its planted failures are recorded under a name no real profile has.
|
|
450
|
+
const account = runtime === "stub" ? profilePath(profile) || STUB_ACCOUNT : profilePath(profile) || join(home ?? homedir(), runtime === "codex" ? ".codex" : ".claude");
|
|
448
451
|
const until = failure.resetAt ?? new Date(now().getTime() + ACCOUNT_WAIT_MS[failure.kind]).toISOString();
|
|
449
452
|
accountFailure = { kind: failure.kind, resetAt: failure.resetAt, until, profile: account };
|
|
450
453
|
await markExhausted(account, { kind: failure.kind, resetAt: failure.resetAt, until, laneKey, runId, line: failure.line, recordedAt: now().toISOString() }).catch(() => {});
|
|
@@ -531,7 +534,11 @@ export async function markWatchedTerminal(runId, { home } = {}) {
|
|
|
531
534
|
await saveWatchedRun({ ...record, terminalSeenAt: new Date().toISOString(), registryPath });
|
|
532
535
|
}
|
|
533
536
|
|
|
534
|
-
|
|
537
|
+
// The drill's stub runtime writes Claude's records (DEV-PROCESS-1).
|
|
538
|
+
const SESSION_ID = { claude: /"session_id":"([0-9a-f-]{36})"/g, codex: /"thread_id":"([0-9a-f-]{36})"/g, stub: /"session_id":"([0-9a-f-]{36})"/g };
|
|
539
|
+
|
|
540
|
+
/** The runtime an invocation runs: its own name, or its command for one built before the stub (claude, codex). */
|
|
541
|
+
export const runtimeOf = (invocation) => invocation?.runtime ?? invocation?.command;
|
|
535
542
|
const LOG_SCAN_BYTES = 256 * 1024;
|
|
536
543
|
|
|
537
544
|
/** The runtime's session id, from the stream-json / --json lines it wrote to the run log. */
|
|
@@ -557,7 +564,7 @@ export async function sessionIdFromLog(logPath, runtime) {
|
|
|
557
564
|
|
|
558
565
|
/** The same session, resumed headless with the same model and permission mode. */
|
|
559
566
|
export function continuationInvocation(invocation, sessionId) {
|
|
560
|
-
if (
|
|
567
|
+
if (["claude", "stub"].includes(runtimeOf(invocation))) return { ...invocation, args: [...invocation.args, "--resume", sessionId] };
|
|
561
568
|
const model = invocation.args[invocation.args.indexOf("--model") + 1];
|
|
562
569
|
return { ...invocation, args: ["exec", "resume", "--json", "--dangerously-bypass-approvals-and-sandbox", "--model", model, sessionId, "-"] };
|
|
563
570
|
}
|
|
@@ -758,7 +765,7 @@ export async function superviseLane({
|
|
|
758
765
|
// child it stays unbeaten, so a hung run still goes Quiet and then Orphan.
|
|
759
766
|
// Codex's transcript is its --json stream, the run log itself.
|
|
760
767
|
let sessionId = null;
|
|
761
|
-
const transcripts = () => (invocation
|
|
768
|
+
const transcripts = () => (runtimeOf(invocation) === "claude" && sessionId ? claudeTranscripts(invocation, sessionId) : []);
|
|
762
769
|
const activity = runActivity({ logPath, transcripts });
|
|
763
770
|
// The lane's beat goes with each run beat. At NODII_DEV_STOP_ONLY_HEARTBEAT=0 the harness's tool-call hook beats the lane instead.
|
|
764
771
|
const beatLane = () => {
|
|
@@ -770,7 +777,7 @@ export async function superviseLane({
|
|
|
770
777
|
const at = activity();
|
|
771
778
|
const tool = at === null ? runningToolCall(child.pid, env) : null;
|
|
772
779
|
// A tool call still running writes nothing; it beats for at most OPEN_CALL_MAX_MS of silence.
|
|
773
|
-
const open = at === null && !tool ? openCallSince({ logPath, transcripts, runtime: invocation
|
|
780
|
+
const open = at === null && !tool ? openCallSince({ logPath, transcripts, runtime: runtimeOf(invocation) }) : null;
|
|
774
781
|
if (at !== null || tool || open !== null) {
|
|
775
782
|
const note = at !== null ? `last activity ${new Date(at).toISOString()}`
|
|
776
783
|
: tool ? `tool call running: ${redactRunText(tool.names)}, started ${new Date(Date.now() - tool.elapsedMs).toISOString().replace(/\.\d{3}Z$/, "Z")}`
|
|
@@ -779,8 +786,8 @@ export async function superviseLane({
|
|
|
779
786
|
beatLane();
|
|
780
787
|
}
|
|
781
788
|
// The session's transcript is found once its id is in the log.
|
|
782
|
-
if (!sessionId && invocation
|
|
783
|
-
sessionIdFromLog(logPath, invocation
|
|
789
|
+
if (!sessionId && runtimeOf(invocation) === "claude")
|
|
790
|
+
sessionIdFromLog(logPath, runtimeOf(invocation)).then((id) => { sessionId ??= id; }, () => {});
|
|
784
791
|
}, heartbeatInterval(env));
|
|
785
792
|
const closed = new Promise((resolve) => child.once("close", (exitCode, signal) => resolve({ exitCode, signal })));
|
|
786
793
|
child.once("error", (error) => {
|
|
@@ -824,7 +831,7 @@ export async function superviseLane({
|
|
|
824
831
|
let continued = 0;
|
|
825
832
|
// NODII-DEV-CLI-9: an early stop continues the same session before it is reported.
|
|
826
833
|
while (!stopping && !signal && continued < limit) {
|
|
827
|
-
const sessionId = await sessionIdFromLog(logPath, invocation
|
|
834
|
+
const sessionId = await sessionIdFromLog(logPath, runtimeOf(invocation)).catch(() => null);
|
|
828
835
|
if (!sessionId) break;
|
|
829
836
|
let lane;
|
|
830
837
|
try { lane = (await request("GET", `/api/v1/lanes/${encode(laneKey)}`)).data; } catch { break; }
|
|
@@ -863,8 +870,8 @@ export async function superviseLane({
|
|
|
863
870
|
}
|
|
864
871
|
clearInterval(heartbeat);
|
|
865
872
|
try {
|
|
866
|
-
const runtime = invocation
|
|
867
|
-
const profile = invocation.env?.[runtime === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR"] ?? null;
|
|
873
|
+
const runtime = runtimeOf(invocation);
|
|
874
|
+
const profile = runtime === "stub" ? invocation.stubAccount ?? null : invocation.env?.[runtime === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR"] ?? null;
|
|
868
875
|
const result = await report({ runId, laneKey, exitCode, signal, worktrees, logPath, continuations: continued, runtime, profile });
|
|
869
876
|
process.stderr.write(`nodii-dev: lane process exit reported to Dev (${result.outcome}, exit ${signal ?? exitCode}, lane ${result.laneStatus ?? "status unknown"}, worktree ${result.worktree}).\n`);
|
|
870
877
|
if (result.accountFailure)
|
package/dist/runtime-launcher.js
CHANGED
|
@@ -4,13 +4,32 @@ import { homedir } from "node:os";
|
|
|
4
4
|
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { configPath } from "./core.js";
|
|
7
|
+
import { stubEnv } from "./drill-stub.js";
|
|
7
8
|
import { laneConfigName } from "./lane-env.js";
|
|
8
9
|
import { recordWatchedRun } from "./watchdog.js";
|
|
9
10
|
import { laneSwitchOn } from "./lane-switches.js";
|
|
10
11
|
import { laneStepKeys, laneTrim } from "./plugin-trim.js";
|
|
11
12
|
import { continuationInvocation, continueTaskMessage, sessionIdFromLog, subagentBudgetLine } from "./lane-supervisor.js";
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
// DEV-PROCESS-1: "stub" is the drill's stub runtime shipped in this package
|
|
15
|
+
// (drill-stub.js). It runs no model and uses no account, so a drill lane
|
|
16
|
+
// resumed by anyone still starts only the stub.
|
|
17
|
+
const RUNTIMES = new Set(["codex", "claude", "stub"]);
|
|
18
|
+
export const STUB_ENTRY = fileURLToPath(new URL("drill-stub.js", import.meta.url));
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A stub account: a drill folder, under ~/.nodii/drill/, and nothing else. A
|
|
22
|
+
* real profile, or any folder outside the drill's, is refused, so a planted
|
|
23
|
+
* failure can never mark a real account exhausted.
|
|
24
|
+
*/
|
|
25
|
+
function stubAccount(profileHome, home) {
|
|
26
|
+
absolutePath(profileHome, "launch.profileHome");
|
|
27
|
+
const drills = join(resolve(home), ".nodii", "drill");
|
|
28
|
+
const inside = relative(drills, resolve(profileHome));
|
|
29
|
+
if (!inside || inside.startsWith("..") || isAbsolute(inside) || /(?:^|\/)\.(?:claude|codex)(?:[-_.]|\/|$)/.test(inside))
|
|
30
|
+
throw new TypeError("the stub runtime takes no real account: launch.profileHome must be a stub account folder under ~/.nodii/drill/");
|
|
31
|
+
return profileHome;
|
|
32
|
+
}
|
|
14
33
|
|
|
15
34
|
const requiredText = (value, name) => {
|
|
16
35
|
if (typeof value !== "string" || !value.trim())
|
|
@@ -53,7 +72,7 @@ function validateData(data) {
|
|
|
53
72
|
const laneKey = requiredText(data?.lane?.key, "lane.key");
|
|
54
73
|
const runtime = requiredText(data?.launch?.runtime, "launch.runtime");
|
|
55
74
|
if (!RUNTIMES.has(runtime))
|
|
56
|
-
throw new TypeError("launch.runtime must be codex or
|
|
75
|
+
throw new TypeError("launch.runtime must be codex, claude or stub");
|
|
57
76
|
const model = requiredText(data?.launch?.model, "launch.model");
|
|
58
77
|
const cwd = absolutePath(data?.launch?.cwd, "launch.cwd");
|
|
59
78
|
const addDirs = data?.launch?.addDirs ?? [];
|
|
@@ -69,7 +88,7 @@ function validateLaunch(options) {
|
|
|
69
88
|
throw new TypeError("runId is not a safe state-directory name");
|
|
70
89
|
const laneKey = requiredText(options?.laneKey, "laneKey");
|
|
71
90
|
const runtime = requiredText(options?.runtime, "runtime");
|
|
72
|
-
if (!RUNTIMES.has(runtime)) throw new TypeError("runtime must be codex or
|
|
91
|
+
if (!RUNTIMES.has(runtime)) throw new TypeError("runtime must be codex, claude or stub");
|
|
73
92
|
const model = requiredText(options?.model, "model");
|
|
74
93
|
const cwd = absolutePath(options?.cwd, "cwd");
|
|
75
94
|
const devConfigPath = laneConfig(options?.devConfigPath, laneKey, "devConfigPath");
|
|
@@ -77,11 +96,13 @@ function validateLaunch(options) {
|
|
|
77
96
|
if (!Array.isArray(addDirs)) throw new TypeError("addDirs must be an array");
|
|
78
97
|
for (const [index, path] of addDirs.entries()) absolutePath(path, `addDirs[${index}]`);
|
|
79
98
|
const prompt = requiredText(options?.prompt, "prompt");
|
|
80
|
-
return { runId, laneKey, runtime, model, cwd, devConfigPath, addDirs, prompt, profileHome: options.profileHome };
|
|
99
|
+
return { runId, laneKey, runtime, model, cwd, devConfigPath, addDirs, prompt, profileHome: options.profileHome, stubScript: options.stubScript };
|
|
81
100
|
}
|
|
82
101
|
|
|
83
102
|
function profileVariable(runtime, profileHome, home) {
|
|
84
103
|
if (profileHome === undefined || profileHome === null) return {};
|
|
104
|
+
// The stub runs on no real account: its profile, if any, is a stub account (a drill folder), passed as an argument, never as a profile variable.
|
|
105
|
+
if (runtime === "stub") throw new TypeError("the stub runtime takes no profile variable");
|
|
85
106
|
absolutePath(profileHome, "launch.profileHome");
|
|
86
107
|
absolutePath(home, "home");
|
|
87
108
|
const child = relative(home, profileHome);
|
|
@@ -272,7 +293,7 @@ export function buildRecoveryPrompt(data) {
|
|
|
272
293
|
export function buildRecoveryInvocation(data, { env = process.env, home = homedir(), trim = null } = {}) {
|
|
273
294
|
const { runId, laneKey, runtime, model, cwd, addDirs } = validateData(data);
|
|
274
295
|
const devConfigPath = laneConfig(data?.launch?.devConfigPath, laneKey, "launch.devConfigPath");
|
|
275
|
-
return buildInvocation({ runId, laneKey, runtime, model, cwd, addDirs, profileHome: data.launch.profileHome, devConfigPath, trim }, { env, home });
|
|
296
|
+
return buildInvocation({ runId, laneKey, runtime, model, cwd, addDirs, profileHome: data.launch.profileHome, devConfigPath, trim, stubScript: data.launch.stubScript }, { env, home });
|
|
276
297
|
}
|
|
277
298
|
|
|
278
299
|
/** NODII-DEV-CLI-191 change (8): a recovered lane's scope, from its Freeze boundaries and its steps. */
|
|
@@ -284,7 +305,7 @@ export function recoveryScope(data) {
|
|
|
284
305
|
}
|
|
285
306
|
|
|
286
307
|
function buildInvocation(options, { env = process.env, home = homedir() } = {}) {
|
|
287
|
-
const { runId, laneKey, runtime, model, cwd, addDirs, profileHome, devConfigPath, trim = null } = options;
|
|
308
|
+
const { runId, laneKey, runtime, model, cwd, addDirs, profileHome, devConfigPath, trim = null, stubScript } = options;
|
|
288
309
|
// NODII-DEV-CLI-191 change (8): plugins and connectors outside the lane's scope stay off.
|
|
289
310
|
const trimmed = runtime === "claude" && trim ? trim : null;
|
|
290
311
|
// A headless lane has nobody to approve a tool call, so it runs in the
|
|
@@ -292,6 +313,20 @@ function buildInvocation(options, { env = process.env, home = homedir() } = {})
|
|
|
292
313
|
// lane's own profile, with the harness safety hooks as the guard (they
|
|
293
314
|
// still run in this mode). Without it every Bash call, `nodii-dev lane
|
|
294
315
|
// gather` included, is refused "requires approval" (AGENT-HARNESS-43).
|
|
316
|
+
if (runtime === "stub") return {
|
|
317
|
+
command: process.execPath,
|
|
318
|
+
args: [STUB_ENTRY, "--script", absolutePath(stubScript, "stubScript"), "--model", model, ...(profileHome ? ["--account", stubAccount(profileHome, home)] : [])],
|
|
319
|
+
...(profileHome ? { stubAccount: profileHome } : {}),
|
|
320
|
+
runtime,
|
|
321
|
+
cwd,
|
|
322
|
+
env: {
|
|
323
|
+
// No account or credential reaches the stub or its steps: an inherited profile could otherwise be recorded exhausted by a drill's planted limit.
|
|
324
|
+
...stubEnv(env),
|
|
325
|
+
NODII_DEV_RUN_ID: runId,
|
|
326
|
+
NODII_DEV_LANE_KEY: laneKey,
|
|
327
|
+
NODII_DEV_CONFIG_PATH: devConfigPath,
|
|
328
|
+
},
|
|
329
|
+
};
|
|
295
330
|
const args = runtime === "codex"
|
|
296
331
|
? ["exec", "--json", "--dangerously-bypass-approvals-and-sandbox", "--cd", cwd, "--model", model, ...addDirs.flatMap((path) => ["--add-dir", path]), "-"]
|
|
297
332
|
// Claude Code refuses --print with stream-json unless --verbose is set.
|