@vimhead.dev/norn-cli 0.1.0-tip.43636209064.1 → 0.1.0-tip.43698584363.1
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/assets/docs/cli.md +5 -1
- package/assets/package.json +1 -1
- package/assets/packages/cli/src/bun/cli.ts +5 -2
- package/assets/packages/cli/src/cli.ts +76 -111
- package/assets/packages/cli/src/generated-build-info.ts +2 -2
- package/assets/packages/cli/src/internal/detached-executor.ts +99 -0
- package/assets/packages/cli/src/internal/engine.ts +5 -1
- package/assets/packages/cli/src/internal/executor-startup.ts +97 -0
- package/assets/packages/cli/src/internal/launch-request.ts +11 -0
- package/assets/packages/cli/src/internal/metrics.ts +17 -6
- package/assets/packages/cli/src/internal/run-lease.ts +10 -1
- package/assets/packages/cli/src/internal/run-state.ts +73 -11
- package/bin/norn.mjs +5 -2
- package/dist/cli.d.ts +7 -1
- package/dist/cli.js +60 -82
- package/dist/generated-build-info.d.ts +2 -2
- package/dist/generated-build-info.js +2 -2
- package/dist/internal/detached-executor.d.ts +14 -0
- package/dist/internal/detached-executor.js +95 -0
- package/dist/internal/engine.d.ts +1 -0
- package/dist/internal/engine.js +4 -1
- package/dist/internal/executor-startup.d.ts +40 -0
- package/dist/internal/executor-startup.js +103 -0
- package/dist/internal/launch-request.d.ts +1 -0
- package/dist/internal/launch-request.js +9 -0
- package/dist/internal/metrics.js +13 -6
- package/dist/internal/run-lease.js +10 -1
- package/dist/internal/run-state.js +41 -9
- package/package.json +2 -2
|
@@ -217,7 +217,16 @@ function parseRunLeaseOwner(value: unknown): NornRunLeaseOwner | undefined {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
function isRunLeaseStale(owner: NornRunLeaseOwner): boolean {
|
|
220
|
-
|
|
220
|
+
if (Date.now() - Date.parse(owner.heartbeatAt) > HEARTBEAT_TTL_MS)
|
|
221
|
+
return true;
|
|
222
|
+
if (owner.pid > 0) {
|
|
223
|
+
try {
|
|
224
|
+
process.kill(owner.pid, 0);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (isNodeError(error) && error.code === "ESRCH") return true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
221
230
|
}
|
|
222
231
|
|
|
223
232
|
async function isRunLeaseDirectoryStale(lockRoot: string): Promise<boolean> {
|
|
@@ -12,10 +12,16 @@ import type {
|
|
|
12
12
|
import { isNodeError } from "@vimhead.dev/norn-core/errors";
|
|
13
13
|
import {
|
|
14
14
|
readRunLaunchRequest,
|
|
15
|
+
readOptionalRunLaunchRequest,
|
|
16
|
+
type NornRunResumeRequest,
|
|
15
17
|
readOptionalRunResumeRequest,
|
|
16
18
|
RESUME_START_GRACE_MS,
|
|
17
19
|
} from "./launch-request.ts";
|
|
18
20
|
import { getRunLeaseHealth } from "./run-lease.ts";
|
|
21
|
+
import {
|
|
22
|
+
EXECUTOR_START_TIMEOUT_MS,
|
|
23
|
+
NornExecutorStartup,
|
|
24
|
+
} from "./executor-startup.ts";
|
|
19
25
|
import { writeJsonAtomically } from "@vimhead.dev/norn-core/atomic-files";
|
|
20
26
|
import {
|
|
21
27
|
createRunFileCoordinator,
|
|
@@ -401,6 +407,27 @@ export async function getRunInfo(runRoot: string): Promise<NornRunInfo> {
|
|
|
401
407
|
pendingResume.status === "fulfilled"
|
|
402
408
|
? pendingResume.request
|
|
403
409
|
: undefined;
|
|
410
|
+
const launchRequest =
|
|
411
|
+
state.status === "running"
|
|
412
|
+
? await readOptionalRunLaunchRequest(runRoot)
|
|
413
|
+
: undefined;
|
|
414
|
+
const startup = launchRequest
|
|
415
|
+
? await new NornExecutorStartup({
|
|
416
|
+
runRoot,
|
|
417
|
+
request: launchRequest,
|
|
418
|
+
}).readResult()
|
|
419
|
+
: undefined;
|
|
420
|
+
const startupFailure =
|
|
421
|
+
startup?.status === "failed"
|
|
422
|
+
? {
|
|
423
|
+
workflowId: state.entrypointWorkflowId,
|
|
424
|
+
error: startup.error,
|
|
425
|
+
failedAt: startup.at,
|
|
426
|
+
}
|
|
427
|
+
: undefined;
|
|
428
|
+
const isStartupOverdue =
|
|
429
|
+
startup?.status === "starting" &&
|
|
430
|
+
Date.now() - Date.parse(startup.at) >= EXECUTOR_START_TIMEOUT_MS;
|
|
404
431
|
return {
|
|
405
432
|
version: state.version,
|
|
406
433
|
id: state.id,
|
|
@@ -412,15 +439,22 @@ export async function getRunInfo(runRoot: string): Promise<NornRunInfo> {
|
|
|
412
439
|
},
|
|
413
440
|
entrypointWorkflowId: state.entrypointWorkflowId,
|
|
414
441
|
currentWorkflowId: state.current?.workflowId,
|
|
415
|
-
status:
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
442
|
+
status: startupFailure
|
|
443
|
+
? "failed"
|
|
444
|
+
: resumeRequest
|
|
445
|
+
? "running"
|
|
446
|
+
: state.status,
|
|
447
|
+
health:
|
|
448
|
+
startupFailure || isStartupOverdue
|
|
449
|
+
? "unhealthy"
|
|
450
|
+
: resumeRequest
|
|
451
|
+
? await getPendingResumeHealth(runRoot, resumeRequest)
|
|
452
|
+
: await runHealth(runRoot, state.status),
|
|
419
453
|
interruption: resumeRequest ? undefined : runInterruption(state),
|
|
420
454
|
outcome: runOutcome(state),
|
|
421
|
-
failed: runFailure(state),
|
|
455
|
+
failed: startupFailure ?? runFailure(state),
|
|
422
456
|
startedAt: state.startedAt,
|
|
423
|
-
updatedAt: state.updatedAt,
|
|
457
|
+
updatedAt: startupFailure?.failedAt ?? state.updatedAt,
|
|
424
458
|
};
|
|
425
459
|
} catch (error) {
|
|
426
460
|
if (!isNodeError(error) || error.code !== "ENOENT") throw error;
|
|
@@ -465,11 +499,21 @@ function runRootCandidates(sessionCwd: string, run: string): string[] {
|
|
|
465
499
|
|
|
466
500
|
async function getPendingResumeHealth(
|
|
467
501
|
runRoot: string,
|
|
468
|
-
|
|
502
|
+
request: NornRunResumeRequest,
|
|
469
503
|
): Promise<NornRunHealth> {
|
|
504
|
+
const startup = await new NornExecutorStartup({
|
|
505
|
+
runRoot,
|
|
506
|
+
request,
|
|
507
|
+
}).readResult();
|
|
508
|
+
if (
|
|
509
|
+
startup?.status === "failed" ||
|
|
510
|
+
(startup?.status === "starting" &&
|
|
511
|
+
Date.now() - Date.parse(startup.at) >= EXECUTOR_START_TIMEOUT_MS)
|
|
512
|
+
)
|
|
513
|
+
return "unhealthy";
|
|
470
514
|
const health = await getRunLeaseHealth(runRoot);
|
|
471
515
|
return health === "healthy" ||
|
|
472
|
-
Date.now() - Date.parse(
|
|
516
|
+
Date.now() - Date.parse(request.createdAt) < RESUME_START_GRACE_MS
|
|
473
517
|
? "healthy"
|
|
474
518
|
: "unhealthy";
|
|
475
519
|
}
|
|
@@ -495,6 +539,18 @@ async function readNornRunInfo(
|
|
|
495
539
|
|
|
496
540
|
async function getLaunchedRunInfo(runRoot: string): Promise<NornRunInfo> {
|
|
497
541
|
const launchRequest = await readRunLaunchRequest(runRoot);
|
|
542
|
+
const startup = await new NornExecutorStartup({
|
|
543
|
+
runRoot,
|
|
544
|
+
request: launchRequest,
|
|
545
|
+
}).readResult();
|
|
546
|
+
const failure =
|
|
547
|
+
startup?.status === "failed"
|
|
548
|
+
? {
|
|
549
|
+
workflowId: launchRequest.workflowId,
|
|
550
|
+
error: startup.error,
|
|
551
|
+
failedAt: startup.at,
|
|
552
|
+
}
|
|
553
|
+
: undefined;
|
|
498
554
|
return {
|
|
499
555
|
version: launchRequest.version,
|
|
500
556
|
id: launchRequest.id,
|
|
@@ -506,10 +562,16 @@ async function getLaunchedRunInfo(runRoot: string): Promise<NornRunInfo> {
|
|
|
506
562
|
},
|
|
507
563
|
entrypointWorkflowId: launchRequest.workflowId,
|
|
508
564
|
currentWorkflowId: launchRequest.workflowId,
|
|
509
|
-
status: "running",
|
|
510
|
-
health:
|
|
565
|
+
status: failure ? "failed" : "running",
|
|
566
|
+
health:
|
|
567
|
+
failure ||
|
|
568
|
+
Date.now() - Date.parse(launchRequest.createdAt) >=
|
|
569
|
+
EXECUTOR_START_TIMEOUT_MS
|
|
570
|
+
? "unhealthy"
|
|
571
|
+
: "healthy",
|
|
572
|
+
failed: failure,
|
|
511
573
|
startedAt: launchRequest.createdAt,
|
|
512
|
-
updatedAt: launchRequest.createdAt,
|
|
574
|
+
updatedAt: failure?.failedAt ?? launchRequest.createdAt,
|
|
513
575
|
};
|
|
514
576
|
}
|
|
515
577
|
|
package/bin/norn.mjs
CHANGED
|
@@ -14,6 +14,9 @@ process.env.NORN_AGENT_DIR = resolveNornAgentDirectory({
|
|
|
14
14
|
process.env.PI_CODING_AGENT_DIR = process.env.NORN_AGENT_DIR;
|
|
15
15
|
const cli = await import("../dist/cli.js");
|
|
16
16
|
await cli.main(process.argv.slice(2), {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
documentationSource: {
|
|
18
|
+
kind: "local",
|
|
19
|
+
root: fileURLToPath(new URL("../assets", import.meta.url)),
|
|
20
|
+
},
|
|
21
|
+
invocation: [process.execPath, fileURLToPath(import.meta.url)],
|
|
19
22
|
});
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import { type NornExecutorArgv } from "./internal/detached-executor.ts";
|
|
1
2
|
import { type NornDocumentationSource } from "./documentation.ts";
|
|
2
|
-
|
|
3
|
+
type NornCliContext = {
|
|
4
|
+
readonly documentationSource: NornDocumentationSource;
|
|
5
|
+
readonly invocation: NornExecutorArgv;
|
|
6
|
+
};
|
|
7
|
+
export declare function main(args: readonly string[], context: NornCliContext): Promise<void>;
|
|
8
|
+
export {};
|
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,14 @@ function isNodeError(error) {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// src/cli.ts
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
NornDetachedExecutor
|
|
12
|
+
} from "./internal/detached-executor.js";
|
|
13
|
+
import {
|
|
14
|
+
EXECUTOR_START_TIMEOUT_MS,
|
|
15
|
+
NornExecutorStartup,
|
|
16
|
+
NornExecutorStartupError
|
|
17
|
+
} from "./internal/executor-startup.js";
|
|
11
18
|
import { createHash, randomUUID } from "node:crypto";
|
|
12
19
|
import {
|
|
13
20
|
chmod,
|
|
@@ -19,9 +26,8 @@ import {
|
|
|
19
26
|
writeFile
|
|
20
27
|
} from "node:fs/promises";
|
|
21
28
|
import { homedir } from "node:os";
|
|
22
|
-
import { dirname,
|
|
29
|
+
import { dirname, join, resolve } from "node:path";
|
|
23
30
|
import { setTimeout as delay } from "node:timers/promises";
|
|
24
|
-
import { fileURLToPath } from "node:url";
|
|
25
31
|
import { Value } from "typebox/value";
|
|
26
32
|
import {
|
|
27
33
|
NORN_BUILD_INFO
|
|
@@ -40,7 +46,7 @@ import {
|
|
|
40
46
|
} from "./internal/errors.js";
|
|
41
47
|
import {
|
|
42
48
|
clearRunResumeRequest,
|
|
43
|
-
|
|
49
|
+
readOptionalRunLaunchRequest,
|
|
44
50
|
readRunResumeRequest,
|
|
45
51
|
writeRunLaunchRequest,
|
|
46
52
|
writeRunResumeRequest
|
|
@@ -131,7 +137,7 @@ var COMMANDS = [
|
|
|
131
137
|
usage: "norn docs inspect",
|
|
132
138
|
output: "JSON object under documentation with storage, version, commit, assetDigest, and absolute paths. NORN_DOCS_CACHE_DIR overrides the binary cache directory.",
|
|
133
139
|
examples: ["norn docs inspect"],
|
|
134
|
-
execute: async (args, documentationSource) => {
|
|
140
|
+
execute: async (args, { documentationSource }) => {
|
|
135
141
|
assertNoExtraArgs("docs inspect", args);
|
|
136
142
|
writeJson({
|
|
137
143
|
documentation: await resolveCliDocumentation(documentationSource)
|
|
@@ -145,15 +151,12 @@ var COMMANDS = [
|
|
|
145
151
|
usage: "norn docs intro",
|
|
146
152
|
output: "JSON object with introduction text under intro. Uses the same asset resolution and NORN_DOCS_CACHE_DIR override as docs inspect.",
|
|
147
153
|
examples: ["norn docs intro"],
|
|
148
|
-
execute: async (args, documentationSource) => {
|
|
154
|
+
execute: async (args, { documentationSource, invocation }) => {
|
|
149
155
|
assertNoExtraArgs("docs intro", args);
|
|
150
156
|
writeJson({
|
|
151
157
|
intro: renderNornDocumentationIntro({
|
|
152
158
|
documentation: await resolveCliDocumentation(documentationSource),
|
|
153
|
-
invocation
|
|
154
|
-
process.execPath,
|
|
155
|
-
fileURLToPath(new URL("../bin/norn.mjs", import.meta.url))
|
|
156
|
-
]
|
|
159
|
+
invocation
|
|
157
160
|
})
|
|
158
161
|
});
|
|
159
162
|
}
|
|
@@ -237,9 +240,9 @@ var COMMANDS = [
|
|
|
237
240
|
examples: [
|
|
238
241
|
`printf '{"args":{"task":"Add tests"}}' | norn runs start example.plan`
|
|
239
242
|
],
|
|
240
|
-
execute: async (args) => {
|
|
243
|
+
execute: async (args, { invocation }) => {
|
|
241
244
|
const workflowId = requiredArg("runs start", args, 0, "workflow id");
|
|
242
|
-
await startRun(workflowId, args.slice(1));
|
|
245
|
+
await startRun({ workflowId, commandArgs: args.slice(1), invocation });
|
|
243
246
|
}
|
|
244
247
|
},
|
|
245
248
|
{
|
|
@@ -253,9 +256,9 @@ var COMMANDS = [
|
|
|
253
256
|
examples: [
|
|
254
257
|
`printf '{"args":{"decision":"accept"}}' | norn runs resume quiet-river-lantern`
|
|
255
258
|
],
|
|
256
|
-
execute: async (args) => {
|
|
259
|
+
execute: async (args, { invocation }) => {
|
|
257
260
|
const run = requiredArg("runs resume", args, 0, "run");
|
|
258
|
-
await resumeRun(run, args.slice(1));
|
|
261
|
+
await resumeRun({ run, args: args.slice(1), invocation });
|
|
259
262
|
}
|
|
260
263
|
},
|
|
261
264
|
{
|
|
@@ -536,25 +539,26 @@ var HUMAN_COMMAND_SUMMARIES = {
|
|
|
536
539
|
version: "Print version/build info.",
|
|
537
540
|
help: "Show concise command help."
|
|
538
541
|
};
|
|
539
|
-
async function main(args,
|
|
542
|
+
async function main(args, context) {
|
|
540
543
|
if (args[0] === "pi") {
|
|
541
544
|
await runPi([...args.slice(1)]);
|
|
542
545
|
return;
|
|
543
546
|
}
|
|
544
547
|
try {
|
|
545
|
-
await runCommand(args,
|
|
548
|
+
await runCommand(args, context);
|
|
546
549
|
} catch (error) {
|
|
547
550
|
writeJson({
|
|
548
551
|
error: {
|
|
549
552
|
code: errorCode(error),
|
|
550
553
|
message: errorMessage(error),
|
|
554
|
+
...error instanceof NornExecutorStartupError ? error.details : {},
|
|
551
555
|
...error instanceof NornProjectLoadError ? { isComplete: error.isComplete, diagnostics: error.diagnostics } : {}
|
|
552
556
|
}
|
|
553
557
|
});
|
|
554
558
|
process.exitCode = 1;
|
|
555
559
|
}
|
|
556
560
|
}
|
|
557
|
-
async function runCommand(args,
|
|
561
|
+
async function runCommand(args, context) {
|
|
558
562
|
if (args.length === 0) {
|
|
559
563
|
writeCliHelp([]);
|
|
560
564
|
return;
|
|
@@ -570,7 +574,7 @@ async function runCommand(args, documentationSource) {
|
|
|
570
574
|
}
|
|
571
575
|
const command = findCliCommand(args);
|
|
572
576
|
if (!command) throw new Error(`Unknown norn command: ${args.join(" ")}`);
|
|
573
|
-
await command.execute(args.slice(command.path.length),
|
|
577
|
+
await command.execute(args.slice(command.path.length), context);
|
|
574
578
|
}
|
|
575
579
|
async function listCliCommands(args) {
|
|
576
580
|
assertKnownFlags("commands list", args, ["--all"]);
|
|
@@ -914,7 +918,11 @@ async function inspectProject() {
|
|
|
914
918
|
);
|
|
915
919
|
writeJson({ project, isComplete, diagnostics });
|
|
916
920
|
}
|
|
917
|
-
async function startRun(
|
|
921
|
+
async function startRun({
|
|
922
|
+
workflowId,
|
|
923
|
+
commandArgs,
|
|
924
|
+
invocation
|
|
925
|
+
}) {
|
|
918
926
|
assertNoStructuredInputArgs("runs start", commandArgs);
|
|
919
927
|
const project = await loadNornProject(process.cwd());
|
|
920
928
|
const workflow = project.registry.workflowById(workflowId);
|
|
@@ -930,7 +938,7 @@ async function startRun(workflowId, commandArgs) {
|
|
|
930
938
|
const runRoot = resolve(project.projectRoot, RUNS_ROOT, id);
|
|
931
939
|
await mkdir(runRoot, { recursive: true });
|
|
932
940
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
933
|
-
|
|
941
|
+
const request = {
|
|
934
942
|
version: 2,
|
|
935
943
|
type: "run",
|
|
936
944
|
id,
|
|
@@ -939,20 +947,19 @@ async function startRun(workflowId, commandArgs) {
|
|
|
939
947
|
args,
|
|
940
948
|
configOverride,
|
|
941
949
|
createdAt
|
|
942
|
-
}
|
|
943
|
-
await
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
runRoot,
|
|
950
|
-
projectRoot: project.projectRoot,
|
|
951
|
-
createdAt
|
|
952
|
-
})
|
|
953
|
-
});
|
|
950
|
+
};
|
|
951
|
+
await writeRunLaunchRequest(runRoot, request);
|
|
952
|
+
await new NornDetachedExecutor({
|
|
953
|
+
invocation,
|
|
954
|
+
startupTimeoutMs: EXECUTOR_START_TIMEOUT_MS
|
|
955
|
+
}).start({ projectRoot: project.projectRoot, runRoot, request });
|
|
956
|
+
writeJson({ run: await getRunInfo(runRoot) });
|
|
954
957
|
}
|
|
955
|
-
async function resumeRun(
|
|
958
|
+
async function resumeRun({
|
|
959
|
+
run,
|
|
960
|
+
args,
|
|
961
|
+
invocation
|
|
962
|
+
}) {
|
|
956
963
|
assertNoStructuredInputArgs("runs resume", args);
|
|
957
964
|
const project = await loadNornProject(process.cwd());
|
|
958
965
|
const runRoot = await resolveRunRoot(project.projectRoot, run);
|
|
@@ -976,7 +983,10 @@ async function resumeRun(run, args) {
|
|
|
976
983
|
await lease.release();
|
|
977
984
|
}
|
|
978
985
|
try {
|
|
979
|
-
await
|
|
986
|
+
await new NornDetachedExecutor({
|
|
987
|
+
invocation,
|
|
988
|
+
startupTimeoutMs: EXECUTOR_START_TIMEOUT_MS
|
|
989
|
+
}).start({ projectRoot: project.projectRoot, runRoot, request });
|
|
980
990
|
} catch (error) {
|
|
981
991
|
await removeResumeRequest({ runRoot, request });
|
|
982
992
|
throw error;
|
|
@@ -1094,6 +1104,8 @@ async function executeRun(runId) {
|
|
|
1094
1104
|
const location = await findNornProject(process.cwd());
|
|
1095
1105
|
const runRoot = resolve(location.projectRoot, RUNS_ROOT, runId);
|
|
1096
1106
|
const request = await readOptionalRunLaunchRequest(runRoot) ?? await readRunResumeRequest(runRoot);
|
|
1107
|
+
const startup = new NornExecutorStartup({ runRoot, request });
|
|
1108
|
+
let isExecutorReady = false;
|
|
1097
1109
|
try {
|
|
1098
1110
|
const agentDir = resolveNornAgentDirectory({
|
|
1099
1111
|
home: homedir(),
|
|
@@ -1106,7 +1118,11 @@ async function executeRun(runId) {
|
|
|
1106
1118
|
agentDir,
|
|
1107
1119
|
signal: abortController.signal,
|
|
1108
1120
|
gateMode: "pause",
|
|
1109
|
-
config: project.projectConfig
|
|
1121
|
+
config: project.projectConfig,
|
|
1122
|
+
onExecutorReady: async () => {
|
|
1123
|
+
await startup.acknowledge();
|
|
1124
|
+
isExecutorReady = true;
|
|
1125
|
+
}
|
|
1110
1126
|
});
|
|
1111
1127
|
engine.registerWorkflows(project.definitions);
|
|
1112
1128
|
if (request.type === "run") {
|
|
@@ -1120,10 +1136,14 @@ async function executeRun(runId) {
|
|
|
1120
1136
|
} else {
|
|
1121
1137
|
await engine.resumeRequestedWorkflow({ runRoot, request });
|
|
1122
1138
|
}
|
|
1139
|
+
} catch (error) {
|
|
1140
|
+
if (!isExecutorReady) await startup.fail(errorMessage(error));
|
|
1141
|
+
throw error;
|
|
1123
1142
|
} finally {
|
|
1124
|
-
if (request.type === "run")
|
|
1125
|
-
|
|
1126
|
-
|
|
1143
|
+
if (request.type === "run") {
|
|
1144
|
+
if (isExecutorReady)
|
|
1145
|
+
await rm(join(runRoot, "launch-request.json"), { force: true });
|
|
1146
|
+
} else await removeResumeRequest({ runRoot, request });
|
|
1127
1147
|
}
|
|
1128
1148
|
}
|
|
1129
1149
|
async function removeResumeRequest(input) {
|
|
@@ -1189,50 +1209,6 @@ async function writeRunLogs(run, options) {
|
|
|
1189
1209
|
await delay(1e3);
|
|
1190
1210
|
}
|
|
1191
1211
|
}
|
|
1192
|
-
async function startDetachedExecuteRun(runId, projectRoot) {
|
|
1193
|
-
const child = spawn(process.execPath, detachedExecuteRunArgs(runId), {
|
|
1194
|
-
cwd: projectRoot,
|
|
1195
|
-
detached: true,
|
|
1196
|
-
stdio: "ignore"
|
|
1197
|
-
});
|
|
1198
|
-
await new Promise((resolveSpawn, reject) => {
|
|
1199
|
-
child.once("spawn", resolveSpawn);
|
|
1200
|
-
child.once("error", reject);
|
|
1201
|
-
});
|
|
1202
|
-
child.unref();
|
|
1203
|
-
}
|
|
1204
|
-
function detachedExecuteRunArgs(runId) {
|
|
1205
|
-
if (NORN_BUILD_INFO.kind === "github-release-binary")
|
|
1206
|
-
return ["execute-run", runId];
|
|
1207
|
-
const scriptPath = process.argv[1];
|
|
1208
|
-
return scriptPath && isAbsolute(scriptPath) && /\.(?:c?m?js|ts)$/.test(scriptPath) ? [scriptPath, "execute-run", runId] : ["execute-run", runId];
|
|
1209
|
-
}
|
|
1210
|
-
function startedRunInfo(input) {
|
|
1211
|
-
return {
|
|
1212
|
-
version: 2,
|
|
1213
|
-
id: input.id,
|
|
1214
|
-
name: input.name,
|
|
1215
|
-
path: input.runRoot,
|
|
1216
|
-
paths: {
|
|
1217
|
-
project: input.projectRoot,
|
|
1218
|
-
workspace: join(input.runRoot, "current", "workspace")
|
|
1219
|
-
},
|
|
1220
|
-
entrypointWorkflowId: input.workflow.id,
|
|
1221
|
-
currentWorkflowId: input.workflow.id,
|
|
1222
|
-
status: "running",
|
|
1223
|
-
health: "healthy",
|
|
1224
|
-
startedAt: input.createdAt,
|
|
1225
|
-
updatedAt: input.createdAt
|
|
1226
|
-
};
|
|
1227
|
-
}
|
|
1228
|
-
async function readOptionalRunLaunchRequest(runRoot) {
|
|
1229
|
-
try {
|
|
1230
|
-
return await readRunLaunchRequest(runRoot);
|
|
1231
|
-
} catch (error) {
|
|
1232
|
-
if (isNodeError(error) && error.code === "ENOENT") return void 0;
|
|
1233
|
-
throw error;
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
1212
|
async function readRunEvents(runRoot) {
|
|
1237
1213
|
try {
|
|
1238
1214
|
const manifest = JSON.parse(
|
|
@@ -1316,6 +1292,8 @@ function writeJson(value) {
|
|
|
1316
1292
|
`);
|
|
1317
1293
|
}
|
|
1318
1294
|
function errorCode(error) {
|
|
1295
|
+
if (error instanceof NornExecutorStartupError)
|
|
1296
|
+
return "EXECUTOR_STARTUP_FAILED";
|
|
1319
1297
|
if (error instanceof NornProjectLoadError) return error.code;
|
|
1320
1298
|
if (error instanceof SyntaxError) return "INVALID_JSON";
|
|
1321
1299
|
return "NORN_ERROR";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const NORN_GENERATED_BUILD_INFO: {
|
|
2
2
|
readonly kind: "npm-registry";
|
|
3
|
-
readonly version: "0.1.0-tip.
|
|
4
|
-
readonly commit: "
|
|
3
|
+
readonly version: "0.1.0-tip.43698584363.1";
|
|
4
|
+
readonly commit: "e1b2d1939aba289ce196184c705548d66ba90149";
|
|
5
5
|
readonly packageSpec: "@vimhead.dev/norn-cli@tip";
|
|
6
6
|
readonly upgrade: {
|
|
7
7
|
readonly supported: false;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/generated-build-info.ts
|
|
2
2
|
var NORN_GENERATED_BUILD_INFO = {
|
|
3
3
|
"kind": "npm-registry",
|
|
4
|
-
"version": "0.1.0-tip.
|
|
5
|
-
"commit": "
|
|
4
|
+
"version": "0.1.0-tip.43698584363.1",
|
|
5
|
+
"commit": "e1b2d1939aba289ce196184c705548d66ba90149",
|
|
6
6
|
"packageSpec": "@vimhead.dev/norn-cli@tip",
|
|
7
7
|
"upgrade": {
|
|
8
8
|
"supported": false,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { NornRunLaunchRequest, NornRunResumeRequest } from "./launch-request.ts";
|
|
2
|
+
export type NornExecutorArgv = readonly [executable: string, ...args: string[]];
|
|
3
|
+
export declare class NornDetachedExecutor {
|
|
4
|
+
private readonly input;
|
|
5
|
+
constructor(input: {
|
|
6
|
+
readonly invocation: NornExecutorArgv;
|
|
7
|
+
readonly startupTimeoutMs: number;
|
|
8
|
+
});
|
|
9
|
+
start(input: {
|
|
10
|
+
readonly projectRoot: string;
|
|
11
|
+
readonly runRoot: string;
|
|
12
|
+
readonly request: NornRunLaunchRequest | NornRunResumeRequest;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// src/internal/detached-executor.ts
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { mkdir, open } from "node:fs/promises";
|
|
4
|
+
import { dirname } from "node:path";
|
|
5
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
6
|
+
|
|
7
|
+
// ../core/src/errors.ts
|
|
8
|
+
function isNodeError(error) {
|
|
9
|
+
return error instanceof Error && "code" in error;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/internal/detached-executor.ts
|
|
13
|
+
import { errorMessage } from "./errors.js";
|
|
14
|
+
import {
|
|
15
|
+
NornExecutorStartup,
|
|
16
|
+
NornExecutorStartupError
|
|
17
|
+
} from "./executor-startup.js";
|
|
18
|
+
var NornDetachedExecutor = class {
|
|
19
|
+
constructor(input) {
|
|
20
|
+
this.input = input;
|
|
21
|
+
}
|
|
22
|
+
input;
|
|
23
|
+
async start(input) {
|
|
24
|
+
const startup = new NornExecutorStartup(input);
|
|
25
|
+
await mkdir(dirname(startup.diagnosticsPath), { recursive: true });
|
|
26
|
+
const output = await open(startup.diagnosticsPath, "a", 384);
|
|
27
|
+
try {
|
|
28
|
+
await startup.begin();
|
|
29
|
+
const child = spawn(
|
|
30
|
+
this.input.invocation[0],
|
|
31
|
+
[...this.input.invocation.slice(1), "execute-run", input.request.id],
|
|
32
|
+
{
|
|
33
|
+
cwd: input.projectRoot,
|
|
34
|
+
detached: true,
|
|
35
|
+
stdio: ["ignore", output.fd, output.fd]
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
let exitReason;
|
|
39
|
+
const exited = new Promise((resolveExit) => {
|
|
40
|
+
child.once("error", (error) => {
|
|
41
|
+
exitReason = errorMessage(error);
|
|
42
|
+
resolveExit();
|
|
43
|
+
});
|
|
44
|
+
child.once("exit", (code, signal) => {
|
|
45
|
+
exitReason = `Executor exited before initialization (${signal ? `signal ${signal}` : `code ${code}`})`;
|
|
46
|
+
resolveExit();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
const deadline = Date.now() + this.input.startupTimeoutMs;
|
|
50
|
+
try {
|
|
51
|
+
while (true) {
|
|
52
|
+
const result = await startup.readResult();
|
|
53
|
+
if (result?.status === "ready") return;
|
|
54
|
+
if (exitReason !== void 0)
|
|
55
|
+
throw new Error(
|
|
56
|
+
result?.status === "failed" ? result.error : exitReason
|
|
57
|
+
);
|
|
58
|
+
if (Date.now() >= deadline)
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Executor did not initialize within ${this.input.startupTimeoutMs}ms`
|
|
61
|
+
);
|
|
62
|
+
await Promise.race([exited, delay(25)]);
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (exitReason === void 0 && child.pid !== void 0) {
|
|
66
|
+
try {
|
|
67
|
+
if (process.platform === "win32") child.kill("SIGKILL");
|
|
68
|
+
else process.kill(-child.pid, "SIGKILL");
|
|
69
|
+
} catch (killError) {
|
|
70
|
+
if (!isNodeError(killError) || killError.code !== "ESRCH")
|
|
71
|
+
throw killError;
|
|
72
|
+
}
|
|
73
|
+
await exited;
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
} finally {
|
|
77
|
+
child.unref();
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {
|
|
80
|
+
const reason = errorMessage(error);
|
|
81
|
+
await startup.fail(reason);
|
|
82
|
+
throw new NornExecutorStartupError({
|
|
83
|
+
runId: input.request.id,
|
|
84
|
+
runRoot: input.runRoot,
|
|
85
|
+
diagnosticsPath: startup.diagnosticsPath,
|
|
86
|
+
reason
|
|
87
|
+
});
|
|
88
|
+
} finally {
|
|
89
|
+
await output.close();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
export {
|
|
94
|
+
NornDetachedExecutor
|
|
95
|
+
};
|
|
@@ -9,6 +9,7 @@ export type NornEngineInput = {
|
|
|
9
9
|
readonly responseCollector?: NornAgentResponseCollector;
|
|
10
10
|
readonly gateMode?: "auto" | "pause";
|
|
11
11
|
readonly config?: Record<string, unknown>;
|
|
12
|
+
readonly onExecutorReady?: () => Promise<void>;
|
|
12
13
|
};
|
|
13
14
|
export declare class NornEngine {
|
|
14
15
|
private readonly input;
|
package/dist/internal/engine.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// src/internal/engine.ts
|
|
2
2
|
import { createRunFileCoordinator } from "./file-coordinator.js";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { mkdir } from "node:fs/promises";
|
|
4
|
+
import { mkdir, rm } from "node:fs/promises";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
6
|
import { Value } from "typebox/value";
|
|
7
7
|
import { NornAgentResponseCollector } from "./agent-response-tool.js";
|
|
8
8
|
import { errorMessage, NornRunStoppedError } from "./errors.js";
|
|
9
9
|
import {
|
|
10
10
|
clearRunResumeRequest,
|
|
11
|
+
LAUNCH_REQUEST_FILE_NAME,
|
|
11
12
|
matchesRunResumeRequest,
|
|
12
13
|
readOptionalRunResumeRequest,
|
|
13
14
|
RESUME_START_GRACE_MS
|
|
@@ -87,6 +88,7 @@ var NornEngine = class {
|
|
|
87
88
|
const state = await NornRunStateStore.load(stagedRunRoot);
|
|
88
89
|
await state.prepareForResumeAfterRollback();
|
|
89
90
|
});
|
|
91
|
+
await rm(join(runRoot, LAUNCH_REQUEST_FILE_NAME), { force: true });
|
|
90
92
|
if (pendingRequest)
|
|
91
93
|
await clearRunResumeRequest({
|
|
92
94
|
runRoot,
|
|
@@ -187,6 +189,7 @@ var NornEngine = class {
|
|
|
187
189
|
async runScheduler(session, initialStep) {
|
|
188
190
|
let currentStep = initialStep;
|
|
189
191
|
try {
|
|
192
|
+
await this.input.onExecutorReady?.();
|
|
190
193
|
for (let step = 1; step <= 1e3; step++) {
|
|
191
194
|
throwIfRunAborted(session.activeRun);
|
|
192
195
|
if (shouldPauseForGate(currentStep)) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { NornRunLaunchRequest, NornRunResumeRequest } from "./launch-request.ts";
|
|
2
|
+
export declare const EXECUTOR_START_TIMEOUT_MS = 60000;
|
|
3
|
+
type ExecutorStartupResult = {
|
|
4
|
+
readonly status: "starting";
|
|
5
|
+
readonly at: string;
|
|
6
|
+
} | {
|
|
7
|
+
readonly status: "ready";
|
|
8
|
+
readonly at: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly status: "failed";
|
|
11
|
+
readonly at: string;
|
|
12
|
+
readonly error: string;
|
|
13
|
+
};
|
|
14
|
+
export declare class NornExecutorStartup {
|
|
15
|
+
readonly resultPath: string;
|
|
16
|
+
readonly diagnosticsPath: string;
|
|
17
|
+
constructor(input: {
|
|
18
|
+
readonly runRoot: string;
|
|
19
|
+
readonly request: NornRunLaunchRequest | NornRunResumeRequest;
|
|
20
|
+
});
|
|
21
|
+
readResult(): Promise<ExecutorStartupResult | undefined>;
|
|
22
|
+
begin(): Promise<void>;
|
|
23
|
+
acknowledge(): Promise<void>;
|
|
24
|
+
fail(error: string): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export declare class NornExecutorStartupError extends Error {
|
|
27
|
+
readonly details: {
|
|
28
|
+
readonly runId: string;
|
|
29
|
+
readonly runRoot: string;
|
|
30
|
+
readonly diagnosticsPath: string;
|
|
31
|
+
readonly reason: string;
|
|
32
|
+
};
|
|
33
|
+
constructor(details: {
|
|
34
|
+
readonly runId: string;
|
|
35
|
+
readonly runRoot: string;
|
|
36
|
+
readonly diagnosticsPath: string;
|
|
37
|
+
readonly reason: string;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export {};
|