voratiq 0.1.0-beta.0
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/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/auth/providers/claude/constants.d.ts +7 -0
- package/dist/auth/providers/claude/constants.js +9 -0
- package/dist/auth/providers/claude/credentials.d.ts +5 -0
- package/dist/auth/providers/claude/credentials.js +112 -0
- package/dist/auth/providers/claude/error.d.ts +5 -0
- package/dist/auth/providers/claude/error.js +6 -0
- package/dist/auth/providers/claude/keychain.d.ts +4 -0
- package/dist/auth/providers/claude/keychain.js +158 -0
- package/dist/auth/providers/claude.d.ts +2 -0
- package/dist/auth/providers/claude.js +124 -0
- package/dist/auth/providers/codex.d.ts +2 -0
- package/dist/auth/providers/codex.js +93 -0
- package/dist/auth/providers/gemini.d.ts +2 -0
- package/dist/auth/providers/gemini.js +159 -0
- package/dist/auth/providers/index.d.ts +2 -0
- package/dist/auth/providers/index.js +16 -0
- package/dist/auth/providers/messages.d.ts +1 -0
- package/dist/auth/providers/messages.js +3 -0
- package/dist/auth/providers/secret-staging.d.ts +14 -0
- package/dist/auth/providers/secret-staging.js +72 -0
- package/dist/auth/providers/teardown.d.ts +2 -0
- package/dist/auth/providers/teardown.js +6 -0
- package/dist/auth/providers/types.d.ts +31 -0
- package/dist/auth/providers/types.js +1 -0
- package/dist/auth/providers/utils.d.ts +20 -0
- package/dist/auth/providers/utils.js +148 -0
- package/dist/auth/runtime.d.ts +2 -0
- package/dist/auth/runtime.js +17 -0
- package/dist/auth/staging.d.ts +8 -0
- package/dist/auth/staging.js +7 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +142 -0
- package/dist/cli/apply.d.ts +14 -0
- package/dist/cli/apply.js +38 -0
- package/dist/cli/commander-utils.d.ts +3 -0
- package/dist/cli/commander-utils.js +27 -0
- package/dist/cli/confirmation.d.ts +14 -0
- package/dist/cli/confirmation.js +16 -0
- package/dist/cli/errors.d.ts +5 -0
- package/dist/cli/errors.js +16 -0
- package/dist/cli/init.d.ts +10 -0
- package/dist/cli/init.js +41 -0
- package/dist/cli/list.d.ts +14 -0
- package/dist/cli/list.js +48 -0
- package/dist/cli/output.d.ts +14 -0
- package/dist/cli/output.js +62 -0
- package/dist/cli/prune.d.ts +14 -0
- package/dist/cli/prune.js +54 -0
- package/dist/cli/review.d.ts +12 -0
- package/dist/cli/review.js +33 -0
- package/dist/cli/run.d.ts +13 -0
- package/dist/cli/run.js +51 -0
- package/dist/commands/apply/command.d.ts +9 -0
- package/dist/commands/apply/command.js +135 -0
- package/dist/commands/apply/errors.d.ts +35 -0
- package/dist/commands/apply/errors.js +73 -0
- package/dist/commands/apply/types.d.ts +13 -0
- package/dist/commands/apply/types.js +1 -0
- package/dist/commands/errors.d.ts +4 -0
- package/dist/commands/errors.js +7 -0
- package/dist/commands/fetch.d.ts +8 -0
- package/dist/commands/fetch.js +25 -0
- package/dist/commands/init/agents.d.ts +3 -0
- package/dist/commands/init/agents.js +159 -0
- package/dist/commands/init/command.d.ts +2 -0
- package/dist/commands/init/command.js +40 -0
- package/dist/commands/init/environment.d.ts +2 -0
- package/dist/commands/init/environment.js +76 -0
- package/dist/commands/init/evals.d.ts +4 -0
- package/dist/commands/init/evals.js +219 -0
- package/dist/commands/init/types.d.ts +48 -0
- package/dist/commands/init/types.js +1 -0
- package/dist/commands/list/command.d.ts +13 -0
- package/dist/commands/list/command.js +60 -0
- package/dist/commands/prune/command.d.ts +2 -0
- package/dist/commands/prune/command.js +336 -0
- package/dist/commands/prune/errors.d.ts +20 -0
- package/dist/commands/prune/errors.js +39 -0
- package/dist/commands/prune/types.d.ts +42 -0
- package/dist/commands/prune/types.js +1 -0
- package/dist/commands/review/command.d.ts +10 -0
- package/dist/commands/review/command.js +26 -0
- package/dist/commands/run/agent-execution.d.ts +19 -0
- package/dist/commands/run/agent-execution.js +63 -0
- package/dist/commands/run/agents/auth-stage.d.ts +23 -0
- package/dist/commands/run/agents/auth-stage.js +108 -0
- package/dist/commands/run/agents/chat-preserver.d.ts +9 -0
- package/dist/commands/run/agents/chat-preserver.js +35 -0
- package/dist/commands/run/agents/eval-runner.d.ts +19 -0
- package/dist/commands/run/agents/eval-runner.js +27 -0
- package/dist/commands/run/agents/failures.d.ts +7 -0
- package/dist/commands/run/agents/failures.js +32 -0
- package/dist/commands/run/agents/lifecycle.d.ts +9 -0
- package/dist/commands/run/agents/lifecycle.js +157 -0
- package/dist/commands/run/agents/preparation.d.ts +2 -0
- package/dist/commands/run/agents/preparation.js +123 -0
- package/dist/commands/run/agents/run-context.d.ts +46 -0
- package/dist/commands/run/agents/run-context.js +193 -0
- package/dist/commands/run/agents/sandbox-launcher.d.ts +44 -0
- package/dist/commands/run/agents/sandbox-launcher.js +211 -0
- package/dist/commands/run/agents/types.d.ts +47 -0
- package/dist/commands/run/agents/types.js +1 -0
- package/dist/commands/run/agents/watchdog.d.ts +39 -0
- package/dist/commands/run/agents/watchdog.js +172 -0
- package/dist/commands/run/agents/workspace-prep.d.ts +17 -0
- package/dist/commands/run/agents/workspace-prep.js +78 -0
- package/dist/commands/run/agents.d.ts +14 -0
- package/dist/commands/run/agents.js +47 -0
- package/dist/commands/run/argv.d.ts +1 -0
- package/dist/commands/run/argv.js +19 -0
- package/dist/commands/run/command.d.ts +14 -0
- package/dist/commands/run/command.js +170 -0
- package/dist/commands/run/errors.d.ts +61 -0
- package/dist/commands/run/errors.js +86 -0
- package/dist/commands/run/id.d.ts +1 -0
- package/dist/commands/run/id.js +22 -0
- package/dist/commands/run/lifecycle.d.ts +19 -0
- package/dist/commands/run/lifecycle.js +186 -0
- package/dist/commands/run/phases.d.ts +11 -0
- package/dist/commands/run/phases.js +1 -0
- package/dist/commands/run/prompts.d.ts +4 -0
- package/dist/commands/run/prompts.js +16 -0
- package/dist/commands/run/record-init.d.ts +15 -0
- package/dist/commands/run/record-init.js +29 -0
- package/dist/commands/run/reports.d.ts +14 -0
- package/dist/commands/run/reports.js +63 -0
- package/dist/commands/run/sandbox-registry.d.ts +4 -0
- package/dist/commands/run/sandbox-registry.js +54 -0
- package/dist/commands/run/sandbox.d.ts +16 -0
- package/dist/commands/run/sandbox.js +96 -0
- package/dist/commands/run/shim/agent-manifest.d.ts +7 -0
- package/dist/commands/run/shim/agent-manifest.js +1 -0
- package/dist/commands/run/shim/run-agent-shim.d.ts +1 -0
- package/dist/commands/run/shim/run-agent-shim.js +232 -0
- package/dist/commands/run/shim/run-agent-shim.mjs +10 -0
- package/dist/commands/run/validation.d.ts +20 -0
- package/dist/commands/run/validation.js +60 -0
- package/dist/configs/agents/defaults.d.ts +9 -0
- package/dist/configs/agents/defaults.js +55 -0
- package/dist/configs/agents/errors.d.ts +40 -0
- package/dist/configs/agents/errors.js +78 -0
- package/dist/configs/agents/loader.d.ts +8 -0
- package/dist/configs/agents/loader.js +137 -0
- package/dist/configs/agents/types.d.ts +39 -0
- package/dist/configs/agents/types.js +31 -0
- package/dist/configs/environment/detect.d.ts +17 -0
- package/dist/configs/environment/detect.js +79 -0
- package/dist/configs/environment/errors.d.ts +12 -0
- package/dist/configs/environment/errors.js +26 -0
- package/dist/configs/environment/loader.d.ts +10 -0
- package/dist/configs/environment/loader.js +80 -0
- package/dist/configs/environment/types.d.ts +21 -0
- package/dist/configs/environment/types.js +98 -0
- package/dist/configs/evals/defaults.d.ts +8 -0
- package/dist/configs/evals/defaults.js +28 -0
- package/dist/configs/evals/detect.d.ts +10 -0
- package/dist/configs/evals/detect.js +224 -0
- package/dist/configs/evals/errors.d.ts +16 -0
- package/dist/configs/evals/errors.js +29 -0
- package/dist/configs/evals/loader.d.ts +9 -0
- package/dist/configs/evals/loader.js +46 -0
- package/dist/configs/evals/types.d.ts +42 -0
- package/dist/configs/evals/types.js +74 -0
- package/dist/configs/sandbox/defaults.d.ts +14 -0
- package/dist/configs/sandbox/defaults.js +54 -0
- package/dist/configs/sandbox/errors.d.ts +5 -0
- package/dist/configs/sandbox/errors.js +8 -0
- package/dist/configs/sandbox/loader.d.ts +6 -0
- package/dist/configs/sandbox/loader.js +192 -0
- package/dist/configs/sandbox/merge.d.ts +9 -0
- package/dist/configs/sandbox/merge.js +94 -0
- package/dist/configs/sandbox/schemas.d.ts +58 -0
- package/dist/configs/sandbox/schemas.js +72 -0
- package/dist/configs/sandbox/types.d.ts +34 -0
- package/dist/configs/sandbox/types.js +1 -0
- package/dist/configs/shared/loader-factory.d.ts +19 -0
- package/dist/configs/shared/loader-factory.js +33 -0
- package/dist/configs/shared/yaml-error-formatter.d.ts +40 -0
- package/dist/configs/shared/yaml-error-formatter.js +41 -0
- package/dist/evals/runner.d.ts +16 -0
- package/dist/evals/runner.js +132 -0
- package/dist/preflight/errors.d.ts +10 -0
- package/dist/preflight/errors.js +21 -0
- package/dist/preflight/index.d.ts +30 -0
- package/dist/preflight/index.js +157 -0
- package/dist/records/enhanced.d.ts +38 -0
- package/dist/records/enhanced.js +139 -0
- package/dist/records/errors.d.ts +23 -0
- package/dist/records/errors.js +43 -0
- package/dist/records/history-lock.d.ts +27 -0
- package/dist/records/history-lock.js +184 -0
- package/dist/records/mutators.d.ts +17 -0
- package/dist/records/mutators.js +144 -0
- package/dist/records/persistence.d.ts +95 -0
- package/dist/records/persistence.js +459 -0
- package/dist/records/types.d.ts +238 -0
- package/dist/records/types.js +131 -0
- package/dist/render/interactions/confirmation.d.ts +19 -0
- package/dist/render/interactions/confirmation.js +63 -0
- package/dist/render/transcripts/apply.d.ts +2 -0
- package/dist/render/transcripts/apply.js +52 -0
- package/dist/render/transcripts/init.d.ts +18 -0
- package/dist/render/transcripts/init.js +84 -0
- package/dist/render/transcripts/list.d.ts +3 -0
- package/dist/render/transcripts/list.js +44 -0
- package/dist/render/transcripts/prune.d.ts +16 -0
- package/dist/render/transcripts/prune.js +50 -0
- package/dist/render/transcripts/review.d.ts +2 -0
- package/dist/render/transcripts/review.js +36 -0
- package/dist/render/transcripts/run.d.ts +25 -0
- package/dist/render/transcripts/run.js +295 -0
- package/dist/render/transcripts/shared.d.ts +12 -0
- package/dist/render/transcripts/shared.js +41 -0
- package/dist/render/utils/agents.d.ts +28 -0
- package/dist/render/utils/agents.js +261 -0
- package/dist/render/utils/badges.d.ts +20 -0
- package/dist/render/utils/badges.js +37 -0
- package/dist/render/utils/errors.d.ts +2 -0
- package/dist/render/utils/errors.js +14 -0
- package/dist/render/utils/records.d.ts +1 -0
- package/dist/render/utils/records.js +32 -0
- package/dist/render/utils/runs.d.ts +16 -0
- package/dist/render/utils/runs.js +50 -0
- package/dist/render/utils/table.d.ts +12 -0
- package/dist/render/utils/table.js +32 -0
- package/dist/render/utils/transcript.d.ts +14 -0
- package/dist/render/utils/transcript.js +44 -0
- package/dist/status/colors.d.ts +10 -0
- package/dist/status/colors.js +33 -0
- package/dist/status/index.d.ts +37 -0
- package/dist/status/index.js +30 -0
- package/dist/testing/test-hooks.d.ts +7 -0
- package/dist/testing/test-hooks.js +16 -0
- package/dist/utils/binaries.d.ts +1 -0
- package/dist/utils/binaries.js +13 -0
- package/dist/utils/cli-root.d.ts +2 -0
- package/dist/utils/cli-root.js +42 -0
- package/dist/utils/colors.d.ts +2 -0
- package/dist/utils/colors.js +23 -0
- package/dist/utils/diff.d.ts +9 -0
- package/dist/utils/diff.js +61 -0
- package/dist/utils/env.d.ts +10 -0
- package/dist/utils/env.js +56 -0
- package/dist/utils/errors.d.ts +31 -0
- package/dist/utils/errors.js +53 -0
- package/dist/utils/fs.d.ts +13 -0
- package/dist/utils/fs.js +70 -0
- package/dist/utils/git.d.ts +40 -0
- package/dist/utils/git.js +126 -0
- package/dist/utils/output.d.ts +4 -0
- package/dist/utils/output.js +12 -0
- package/dist/utils/path.d.ts +11 -0
- package/dist/utils/path.js +84 -0
- package/dist/utils/process.d.ts +37 -0
- package/dist/utils/process.js +152 -0
- package/dist/utils/terminal.d.ts +5 -0
- package/dist/utils/terminal.js +5 -0
- package/dist/utils/validators.d.ts +1 -0
- package/dist/utils/validators.js +15 -0
- package/dist/utils/version.d.ts +1 -0
- package/dist/utils/version.js +25 -0
- package/dist/utils/yaml-reader.d.ts +14 -0
- package/dist/utils/yaml-reader.js +41 -0
- package/dist/utils/yaml.d.ts +33 -0
- package/dist/utils/yaml.js +75 -0
- package/dist/workspace/agents.d.ts +33 -0
- package/dist/workspace/agents.js +189 -0
- package/dist/workspace/chat/artifacts.d.ts +14 -0
- package/dist/workspace/chat/artifacts.js +157 -0
- package/dist/workspace/chat/sources.d.ts +5 -0
- package/dist/workspace/chat/sources.js +80 -0
- package/dist/workspace/chat/types.d.ts +1 -0
- package/dist/workspace/chat/types.js +1 -0
- package/dist/workspace/cleanup.d.ts +4 -0
- package/dist/workspace/cleanup.js +12 -0
- package/dist/workspace/credential-guard.d.ts +4 -0
- package/dist/workspace/credential-guard.js +71 -0
- package/dist/workspace/dependencies.d.ts +23 -0
- package/dist/workspace/dependencies.js +190 -0
- package/dist/workspace/errors.d.ts +16 -0
- package/dist/workspace/errors.js +43 -0
- package/dist/workspace/layout.d.ts +30 -0
- package/dist/workspace/layout.js +124 -0
- package/dist/workspace/prune.d.ts +8 -0
- package/dist/workspace/prune.js +29 -0
- package/dist/workspace/run.d.ts +14 -0
- package/dist/workspace/run.js +28 -0
- package/dist/workspace/sandbox-requirements.d.ts +17 -0
- package/dist/workspace/sandbox-requirements.js +69 -0
- package/dist/workspace/setup.d.ts +3 -0
- package/dist/workspace/setup.js +81 -0
- package/dist/workspace/shim.d.ts +4 -0
- package/dist/workspace/shim.js +65 -0
- package/dist/workspace/structure.d.ts +77 -0
- package/dist/workspace/structure.js +134 -0
- package/dist/workspace/templates.d.ts +9 -0
- package/dist/workspace/templates.js +66 -0
- package/dist/workspace/types.d.ts +4 -0
- package/dist/workspace/types.js +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { ensureWorkspaceError, prepareAgentWorkspace, } from "../../../workspace/agents.js";
|
|
2
|
+
import { buildAgentWorkspacePaths } from "../../../workspace/layout.js";
|
|
3
|
+
import { MissingAgentProviderError, RunCommandError } from "../errors.js";
|
|
4
|
+
import { registerStagedSandboxContext, teardownRegisteredSandboxContext, } from "../sandbox-registry.js";
|
|
5
|
+
import { stageAgentAuth } from "./auth-stage.js";
|
|
6
|
+
import { captureAgentChatTranscripts } from "./chat-preserver.js";
|
|
7
|
+
import { AgentRunContext } from "./run-context.js";
|
|
8
|
+
import { configureSandboxSettings } from "./sandbox-launcher.js";
|
|
9
|
+
import { writeAgentManifest } from "./workspace-prep.js";
|
|
10
|
+
export async function prepareAgentForExecution(context) {
|
|
11
|
+
const { agent, baseRevisionSha, runId, root, evalPlan, environment } = context;
|
|
12
|
+
const workspacePaths = buildAgentWorkspacePaths({
|
|
13
|
+
root,
|
|
14
|
+
runId,
|
|
15
|
+
agentId: agent.id,
|
|
16
|
+
});
|
|
17
|
+
const startedAt = new Date().toISOString();
|
|
18
|
+
const agentContext = new AgentRunContext({
|
|
19
|
+
agent,
|
|
20
|
+
runId,
|
|
21
|
+
startedAt,
|
|
22
|
+
evalPlan,
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
await prepareAgentWorkspace({
|
|
26
|
+
paths: workspacePaths,
|
|
27
|
+
baseRevisionSha,
|
|
28
|
+
root,
|
|
29
|
+
agentId: agent.id,
|
|
30
|
+
runId,
|
|
31
|
+
environment,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return {
|
|
36
|
+
status: "failed",
|
|
37
|
+
result: await agentContext.failWith(ensureWorkspaceFailure(error)),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
let authContext;
|
|
41
|
+
let manifestEnv = {};
|
|
42
|
+
try {
|
|
43
|
+
const staged = await stageAgentAuth({
|
|
44
|
+
agent,
|
|
45
|
+
agentRoot: workspacePaths.agentRoot,
|
|
46
|
+
runId,
|
|
47
|
+
root,
|
|
48
|
+
});
|
|
49
|
+
authContext = staged.context;
|
|
50
|
+
registerStagedSandboxContext(authContext);
|
|
51
|
+
manifestEnv = staged.env;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
return {
|
|
55
|
+
status: "failed",
|
|
56
|
+
result: await agentContext.failWith(ensureWorkspaceFailure(error)),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
manifestEnv = await writeAgentManifest({
|
|
61
|
+
agent,
|
|
62
|
+
workspacePaths,
|
|
63
|
+
env: manifestEnv,
|
|
64
|
+
environment,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
await captureAgentChatTranscripts({
|
|
69
|
+
agent,
|
|
70
|
+
agentContext,
|
|
71
|
+
agentRoot: workspacePaths.agentRoot,
|
|
72
|
+
reason: "pre-run",
|
|
73
|
+
});
|
|
74
|
+
await teardownRegisteredSandboxContext(authContext);
|
|
75
|
+
return {
|
|
76
|
+
status: "failed",
|
|
77
|
+
result: await agentContext.failWith(ensureWorkspaceFailure(error)),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const providerId = agent.provider;
|
|
82
|
+
if (!providerId) {
|
|
83
|
+
throw new MissingAgentProviderError(agent.id);
|
|
84
|
+
}
|
|
85
|
+
await configureSandboxSettings({
|
|
86
|
+
workspacePaths,
|
|
87
|
+
providerId,
|
|
88
|
+
root,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
await captureAgentChatTranscripts({
|
|
93
|
+
agent,
|
|
94
|
+
agentContext,
|
|
95
|
+
agentRoot: workspacePaths.agentRoot,
|
|
96
|
+
reason: "pre-run",
|
|
97
|
+
});
|
|
98
|
+
await teardownRegisteredSandboxContext(authContext);
|
|
99
|
+
return {
|
|
100
|
+
status: "failed",
|
|
101
|
+
result: await agentContext.failWith(ensureWorkspaceFailure(error)),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
status: "ready",
|
|
106
|
+
prepared: {
|
|
107
|
+
agent,
|
|
108
|
+
agentContext,
|
|
109
|
+
workspacePaths,
|
|
110
|
+
runtimeManifestPath: workspacePaths.runtimeManifestPath,
|
|
111
|
+
baseRevisionSha,
|
|
112
|
+
root,
|
|
113
|
+
runId,
|
|
114
|
+
evalPlan,
|
|
115
|
+
environment,
|
|
116
|
+
manifestEnv,
|
|
117
|
+
authContext,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function ensureWorkspaceFailure(error) {
|
|
122
|
+
return error instanceof RunCommandError ? error : ensureWorkspaceError(error);
|
|
123
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AgentDefinition } from "../../../configs/agents/types.js";
|
|
2
|
+
import type { AgentEvalResult, EvalDefinition } from "../../../configs/evals/types.js";
|
|
3
|
+
import type { AgentInvocationRecord, AgentStatus, WatchdogMetadata } from "../../../records/types.js";
|
|
4
|
+
import type { ArtifactCollectionResult } from "../../../workspace/agents.js";
|
|
5
|
+
import type { ChatArtifactFormat } from "../../../workspace/chat/types.js";
|
|
6
|
+
import type { RunCommandError } from "../errors.js";
|
|
7
|
+
import { type AgentExecutionResult, type AgentExecutionState } from "../reports.js";
|
|
8
|
+
export declare class AgentRunContext {
|
|
9
|
+
readonly state: AgentExecutionState;
|
|
10
|
+
status: AgentStatus;
|
|
11
|
+
commitSha: string | undefined;
|
|
12
|
+
evalResults: AgentEvalResult[];
|
|
13
|
+
errorMessage: string | undefined;
|
|
14
|
+
watchdogMetadata: WatchdogMetadata | undefined;
|
|
15
|
+
private completedAt;
|
|
16
|
+
private startedAt;
|
|
17
|
+
private readonly evalPlan;
|
|
18
|
+
private readonly runId;
|
|
19
|
+
private readonly agent;
|
|
20
|
+
private artifactState;
|
|
21
|
+
private evalWarnings;
|
|
22
|
+
constructor(params: {
|
|
23
|
+
agent: AgentDefinition;
|
|
24
|
+
runId: string;
|
|
25
|
+
startedAt: string;
|
|
26
|
+
evalPlan: readonly EvalDefinition[];
|
|
27
|
+
});
|
|
28
|
+
markFailure(error: RunCommandError): void;
|
|
29
|
+
failWith(error: RunCommandError): Promise<AgentExecutionResult>;
|
|
30
|
+
isFailed(): boolean;
|
|
31
|
+
setCompleted(): void;
|
|
32
|
+
markStarted(): void;
|
|
33
|
+
getStartedAt(): string | undefined;
|
|
34
|
+
applyArtifacts(result: ArtifactCollectionResult): void;
|
|
35
|
+
applyEvaluations(results: AgentEvalResult[]): void;
|
|
36
|
+
markChatArtifact(format: ChatArtifactFormat): void;
|
|
37
|
+
recordEvalWarnings(warnings: readonly string[]): void;
|
|
38
|
+
setWatchdogMetadata(metadata: WatchdogMetadata): void;
|
|
39
|
+
finalize(): AgentExecutionResult;
|
|
40
|
+
/**
|
|
41
|
+
* Build an early failure record for immediate UI surfacing when watchdog triggers.
|
|
42
|
+
* Includes placeholder evals so the record satisfies agentInvocationRecordSchema.
|
|
43
|
+
*/
|
|
44
|
+
buildEarlyFailureRecord(errorMessage: string): AgentInvocationRecord;
|
|
45
|
+
}
|
|
46
|
+
export declare function buildDefaultEvalResults(definitions: readonly EvalDefinition[]): AgentEvalResult[];
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { normalizeDiffStatistics } from "../../../utils/diff.js";
|
|
2
|
+
import { finalizeAgentResult, } from "../reports.js";
|
|
3
|
+
export class AgentRunContext {
|
|
4
|
+
state = {
|
|
5
|
+
diffAttempted: false,
|
|
6
|
+
diffCaptured: false,
|
|
7
|
+
diffStatistics: undefined,
|
|
8
|
+
};
|
|
9
|
+
status = "succeeded";
|
|
10
|
+
commitSha;
|
|
11
|
+
evalResults;
|
|
12
|
+
errorMessage;
|
|
13
|
+
watchdogMetadata;
|
|
14
|
+
completedAt;
|
|
15
|
+
startedAt;
|
|
16
|
+
evalPlan;
|
|
17
|
+
runId;
|
|
18
|
+
agent;
|
|
19
|
+
artifactState;
|
|
20
|
+
evalWarnings = [];
|
|
21
|
+
constructor(params) {
|
|
22
|
+
this.agent = params.agent;
|
|
23
|
+
this.runId = params.runId;
|
|
24
|
+
this.startedAt = params.startedAt;
|
|
25
|
+
this.evalPlan = params.evalPlan;
|
|
26
|
+
this.evalResults = buildDefaultEvalResults(this.evalPlan);
|
|
27
|
+
this.artifactState = {
|
|
28
|
+
diffAttempted: false,
|
|
29
|
+
diffCaptured: false,
|
|
30
|
+
stdoutCaptured: true,
|
|
31
|
+
stderrCaptured: true,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
markFailure(error) {
|
|
35
|
+
this.status = "failed";
|
|
36
|
+
this.errorMessage = error.messageForDisplay();
|
|
37
|
+
}
|
|
38
|
+
async failWith(error) {
|
|
39
|
+
this.markFailure(error);
|
|
40
|
+
this.setCompleted();
|
|
41
|
+
await Promise.resolve();
|
|
42
|
+
return this.finalize();
|
|
43
|
+
}
|
|
44
|
+
isFailed() {
|
|
45
|
+
return this.status === "failed";
|
|
46
|
+
}
|
|
47
|
+
setCompleted() {
|
|
48
|
+
if (!this.completedAt) {
|
|
49
|
+
this.completedAt = new Date().toISOString();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
markStarted() {
|
|
53
|
+
this.startedAt = new Date().toISOString();
|
|
54
|
+
}
|
|
55
|
+
getStartedAt() {
|
|
56
|
+
return this.startedAt;
|
|
57
|
+
}
|
|
58
|
+
applyArtifacts(result) {
|
|
59
|
+
if (result.summaryCaptured) {
|
|
60
|
+
this.artifactState.summaryCaptured = true;
|
|
61
|
+
}
|
|
62
|
+
if (result.diffAttempted) {
|
|
63
|
+
this.artifactState.diffAttempted = true;
|
|
64
|
+
}
|
|
65
|
+
if (result.diffCaptured) {
|
|
66
|
+
this.artifactState.diffCaptured = true;
|
|
67
|
+
}
|
|
68
|
+
if (result.commitSha) {
|
|
69
|
+
this.commitSha = result.commitSha;
|
|
70
|
+
}
|
|
71
|
+
const normalizedDiff = normalizeDiffStatistics(result.diffStatistics);
|
|
72
|
+
if (normalizedDiff) {
|
|
73
|
+
this.state.diffStatistics = normalizedDiff;
|
|
74
|
+
}
|
|
75
|
+
this.state.diffAttempted ||= result.diffAttempted;
|
|
76
|
+
this.state.diffCaptured ||= result.diffCaptured;
|
|
77
|
+
}
|
|
78
|
+
applyEvaluations(results) {
|
|
79
|
+
const defaults = buildDefaultEvalResults(this.evalPlan);
|
|
80
|
+
const bySlug = new Map(results.map((evaluation) => [evaluation.slug, evaluation]));
|
|
81
|
+
this.evalResults = defaults.map((fallback) => {
|
|
82
|
+
const evaluation = bySlug.get(fallback.slug);
|
|
83
|
+
return evaluation ?? fallback;
|
|
84
|
+
});
|
|
85
|
+
if (this.status === "failed") {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const hasErrored = this.evalResults.some((evaluation) => {
|
|
89
|
+
return evaluation.status === "errored";
|
|
90
|
+
});
|
|
91
|
+
const hasFailed = this.evalResults.some((evaluation) => evaluation.status === "failed");
|
|
92
|
+
if (hasErrored) {
|
|
93
|
+
this.status = "errored";
|
|
94
|
+
if (!this.errorMessage) {
|
|
95
|
+
const erroredEval = this.evalResults.find((evaluation) => evaluation.status === "errored" && evaluation.error);
|
|
96
|
+
if (erroredEval?.error) {
|
|
97
|
+
this.errorMessage = erroredEval.error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (hasFailed) {
|
|
103
|
+
this.status = "failed";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
markChatArtifact(format) {
|
|
107
|
+
this.artifactState.chatCaptured = true;
|
|
108
|
+
this.artifactState.chatFormat = format;
|
|
109
|
+
}
|
|
110
|
+
recordEvalWarnings(warnings) {
|
|
111
|
+
this.evalWarnings.push(...warnings);
|
|
112
|
+
}
|
|
113
|
+
setWatchdogMetadata(metadata) {
|
|
114
|
+
this.watchdogMetadata = metadata;
|
|
115
|
+
}
|
|
116
|
+
finalize() {
|
|
117
|
+
this.setCompleted();
|
|
118
|
+
const record = buildAgentRecord({
|
|
119
|
+
agent: this.agent,
|
|
120
|
+
commitSha: this.commitSha,
|
|
121
|
+
completedAt: this.completedAt ?? new Date().toISOString(),
|
|
122
|
+
errorMessage: this.errorMessage,
|
|
123
|
+
startedAt: this.startedAt,
|
|
124
|
+
status: this.status,
|
|
125
|
+
artifacts: this.artifactState,
|
|
126
|
+
evalResults: this.evalResults,
|
|
127
|
+
warnings: this.evalWarnings,
|
|
128
|
+
diffStatistics: this.state.diffStatistics,
|
|
129
|
+
watchdog: this.watchdogMetadata,
|
|
130
|
+
});
|
|
131
|
+
return finalizeAgentResult(this.runId, record, this.state);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Build an early failure record for immediate UI surfacing when watchdog triggers.
|
|
135
|
+
* Includes placeholder evals so the record satisfies agentInvocationRecordSchema.
|
|
136
|
+
*/
|
|
137
|
+
buildEarlyFailureRecord(errorMessage) {
|
|
138
|
+
return buildAgentRecord({
|
|
139
|
+
agent: this.agent,
|
|
140
|
+
commitSha: undefined,
|
|
141
|
+
completedAt: new Date().toISOString(),
|
|
142
|
+
errorMessage,
|
|
143
|
+
startedAt: this.startedAt,
|
|
144
|
+
status: "failed",
|
|
145
|
+
artifacts: this.artifactState,
|
|
146
|
+
evalResults: this.evalResults,
|
|
147
|
+
warnings: this.evalWarnings,
|
|
148
|
+
diffStatistics: undefined,
|
|
149
|
+
watchdog: this.watchdogMetadata,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export function buildDefaultEvalResults(definitions) {
|
|
154
|
+
return definitions.map(({ slug, command }) => ({
|
|
155
|
+
slug,
|
|
156
|
+
command,
|
|
157
|
+
status: "skipped",
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
function buildAgentRecord(options) {
|
|
161
|
+
const { agent, commitSha, completedAt, errorMessage, startedAt, status, artifacts, evalResults, warnings, diffStatistics, watchdog, } = options;
|
|
162
|
+
const snapshots = toEvalSnapshots(evalResults);
|
|
163
|
+
const artifactState = Object.keys(artifacts).length > 0 ? artifacts : undefined;
|
|
164
|
+
const normalizedWarnings = warnings.length > 0 ? Array.from(new Set(warnings)) : undefined;
|
|
165
|
+
const normalizedDiffStatistics = normalizeDiffStatistics(diffStatistics);
|
|
166
|
+
const record = {
|
|
167
|
+
agentId: agent.id,
|
|
168
|
+
model: agent.model,
|
|
169
|
+
startedAt,
|
|
170
|
+
completedAt,
|
|
171
|
+
status,
|
|
172
|
+
commitSha,
|
|
173
|
+
artifacts: artifactState,
|
|
174
|
+
evals: snapshots,
|
|
175
|
+
error: errorMessage,
|
|
176
|
+
warnings: normalizedWarnings,
|
|
177
|
+
watchdog,
|
|
178
|
+
};
|
|
179
|
+
if (normalizedDiffStatistics) {
|
|
180
|
+
record.diffStatistics = normalizedDiffStatistics;
|
|
181
|
+
}
|
|
182
|
+
return record;
|
|
183
|
+
}
|
|
184
|
+
function toEvalSnapshots(results) {
|
|
185
|
+
return results.map((evaluation) => ({
|
|
186
|
+
slug: evaluation.slug,
|
|
187
|
+
status: evaluation.status,
|
|
188
|
+
command: evaluation.command,
|
|
189
|
+
exitCode: evaluation.exitCode,
|
|
190
|
+
hasLog: evaluation.logPath !== undefined,
|
|
191
|
+
error: evaluation.error,
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { WatchdogMetadata } from "../../../records/types.js";
|
|
2
|
+
import type { AgentWorkspacePaths } from "../../../workspace/layout.js";
|
|
3
|
+
import { type WatchdogTrigger } from "./watchdog.js";
|
|
4
|
+
export interface AgentProcessOptions {
|
|
5
|
+
runtimeManifestPath: string;
|
|
6
|
+
agentRoot: string;
|
|
7
|
+
stdoutPath: string;
|
|
8
|
+
stderrPath: string;
|
|
9
|
+
sandboxSettingsPath: string;
|
|
10
|
+
resolveRunInvocation?: RunInvocationResolver;
|
|
11
|
+
/** Provider ID for watchdog fatal pattern matching. */
|
|
12
|
+
providerId?: string;
|
|
13
|
+
/** Callback fired immediately when watchdog triggers, before process exits. */
|
|
14
|
+
onWatchdogTrigger?: (trigger: WatchdogTrigger, reason: string) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface AgentProcessResult {
|
|
17
|
+
exitCode: number;
|
|
18
|
+
errorMessage?: string;
|
|
19
|
+
signal?: NodeJS.Signals | null;
|
|
20
|
+
/** Watchdog metadata showing enforced limits and trigger reason. */
|
|
21
|
+
watchdog?: WatchdogMetadata;
|
|
22
|
+
}
|
|
23
|
+
export interface RunInvocationContext {
|
|
24
|
+
agentRoot: string;
|
|
25
|
+
configArg: string;
|
|
26
|
+
settingsArg: string;
|
|
27
|
+
shimEntryPath: string;
|
|
28
|
+
}
|
|
29
|
+
export interface RunInvocation {
|
|
30
|
+
command: string;
|
|
31
|
+
args: string[];
|
|
32
|
+
}
|
|
33
|
+
export type RunInvocationResolver = (context: RunInvocationContext) => Promise<RunInvocation> | RunInvocation;
|
|
34
|
+
export interface SandboxSettingsInput {
|
|
35
|
+
workspacePaths: AgentWorkspacePaths;
|
|
36
|
+
providerId: string;
|
|
37
|
+
root: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function configureSandboxSettings(input: SandboxSettingsInput): Promise<void>;
|
|
40
|
+
export declare function getRunCommand(): Promise<string>;
|
|
41
|
+
export declare function runAgentProcess(options: AgentProcessOptions): Promise<AgentProcessResult>;
|
|
42
|
+
export declare function stageManifestForSandbox(options: {
|
|
43
|
+
runtimeManifestPath: string;
|
|
44
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { constants as fsConstants, createWriteStream, existsSync, } from "node:fs";
|
|
2
|
+
import { access, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, isAbsolute, relative as relativePath } from "node:path";
|
|
4
|
+
import { getCliAssetPath, resolveCliAssetRoot, } from "../../../utils/cli-root.js";
|
|
5
|
+
import { resolvePath } from "../../../utils/path.js";
|
|
6
|
+
import { spawnStreamingProcess } from "../../../utils/process.js";
|
|
7
|
+
import { ARTIFACTS_DIRNAME, EVALS_DIRNAME, } from "../../../workspace/structure.js";
|
|
8
|
+
import { AgentProcessError } from "../errors.js";
|
|
9
|
+
import { generateSandboxSettings, resolveSrtBinary, writeSandboxSettings, } from "../sandbox.js";
|
|
10
|
+
import { createWatchdog, WATCHDOG_DEFAULTS, } from "./watchdog.js";
|
|
11
|
+
const DEFAULT_SRT_ARGUMENTS = ["--debug"];
|
|
12
|
+
const SRT_BINARY_ENV = "VORATIQ_SRT_BINARY";
|
|
13
|
+
let cachedSrtBinaryPath;
|
|
14
|
+
export async function configureSandboxSettings(input) {
|
|
15
|
+
const { workspacePaths, providerId, root } = input;
|
|
16
|
+
const artifactsPath = resolvePath(workspacePaths.agentRoot, ARTIFACTS_DIRNAME);
|
|
17
|
+
const evalsPath = resolvePath(workspacePaths.agentRoot, EVALS_DIRNAME);
|
|
18
|
+
const sandboxSettings = generateSandboxSettings({
|
|
19
|
+
sandboxHomePath: workspacePaths.sandboxHomePath,
|
|
20
|
+
workspacePath: workspacePaths.workspacePath,
|
|
21
|
+
provider: providerId,
|
|
22
|
+
root,
|
|
23
|
+
sandboxSettingsPath: workspacePaths.sandboxSettingsPath,
|
|
24
|
+
runtimePath: workspacePaths.runtimePath,
|
|
25
|
+
artifactsPath,
|
|
26
|
+
evalsPath,
|
|
27
|
+
});
|
|
28
|
+
await writeSandboxSettings(workspacePaths.sandboxSettingsPath, sandboxSettings);
|
|
29
|
+
}
|
|
30
|
+
export async function getRunCommand() {
|
|
31
|
+
const { X_OK } = fsConstants;
|
|
32
|
+
const binaryPath = resolveSrtBinaryPath();
|
|
33
|
+
try {
|
|
34
|
+
await access(binaryPath, X_OK);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw new Error(`Sandbox Runtime binary not found or not executable at ${binaryPath}. Please reinstall dependencies with 'npm install'.`);
|
|
38
|
+
}
|
|
39
|
+
return binaryPath;
|
|
40
|
+
}
|
|
41
|
+
function getRunArgs(options) {
|
|
42
|
+
const { settingsArg, configArg, shimEntryPath } = options;
|
|
43
|
+
return [
|
|
44
|
+
...DEFAULT_SRT_ARGUMENTS,
|
|
45
|
+
"--settings",
|
|
46
|
+
settingsArg,
|
|
47
|
+
"--",
|
|
48
|
+
process.execPath,
|
|
49
|
+
shimEntryPath,
|
|
50
|
+
"--config",
|
|
51
|
+
configArg,
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
async function defaultResolveRunInvocation(context) {
|
|
55
|
+
const command = await getRunCommand();
|
|
56
|
+
const args = getRunArgs({
|
|
57
|
+
settingsArg: context.settingsArg,
|
|
58
|
+
configArg: context.configArg,
|
|
59
|
+
shimEntryPath: context.shimEntryPath,
|
|
60
|
+
});
|
|
61
|
+
return { command, args };
|
|
62
|
+
}
|
|
63
|
+
export async function runAgentProcess(options) {
|
|
64
|
+
const { runtimeManifestPath, agentRoot, stdoutPath, stderrPath, sandboxSettingsPath, resolveRunInvocation, providerId = "", onWatchdogTrigger, } = options;
|
|
65
|
+
const stdoutStream = createWriteStream(stdoutPath, { flags: "w" });
|
|
66
|
+
const stderrStream = createWriteStream(stderrPath, { flags: "w" });
|
|
67
|
+
const shimEntryPath = resolveShimEntryPath();
|
|
68
|
+
if (!existsSync(shimEntryPath)) {
|
|
69
|
+
throw new AgentProcessError({
|
|
70
|
+
detail: `Shim entry point missing at ${shimEntryPath}`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const manifestArgPath = await stageManifestForSandbox({
|
|
74
|
+
runtimeManifestPath,
|
|
75
|
+
});
|
|
76
|
+
const relativeConfig = relativePath(agentRoot, manifestArgPath);
|
|
77
|
+
const configArg = relativeConfig === "" ? manifestArgPath : relativeConfig;
|
|
78
|
+
const relativeSettings = relativePath(agentRoot, sandboxSettingsPath);
|
|
79
|
+
const settingsArg = relativeSettings === "" ? sandboxSettingsPath : relativeSettings;
|
|
80
|
+
const invocationResolver = resolveRunInvocation ?? defaultResolveRunInvocation;
|
|
81
|
+
const { command, args } = await invocationResolver({
|
|
82
|
+
agentRoot,
|
|
83
|
+
configArg,
|
|
84
|
+
settingsArg,
|
|
85
|
+
shimEntryPath,
|
|
86
|
+
});
|
|
87
|
+
let watchdogController;
|
|
88
|
+
// Track abort signal subscription for cleanup
|
|
89
|
+
let abortSignalHandler;
|
|
90
|
+
// Shared abort controller - watchdog will fire it, spawnStreamingProcess will listen
|
|
91
|
+
const forceAbortController = new AbortController();
|
|
92
|
+
let exitCode;
|
|
93
|
+
let signal;
|
|
94
|
+
let aborted = false;
|
|
95
|
+
try {
|
|
96
|
+
const result = await spawnStreamingProcess({
|
|
97
|
+
command,
|
|
98
|
+
args,
|
|
99
|
+
cwd: agentRoot,
|
|
100
|
+
stdout: { writable: stdoutStream },
|
|
101
|
+
stderr: { writable: stderrStream },
|
|
102
|
+
// Spawn in new process group to enable killing entire process tree
|
|
103
|
+
detached: true,
|
|
104
|
+
onSpawn: (child) => {
|
|
105
|
+
watchdogController = createWatchdog(child, stderrStream, {
|
|
106
|
+
providerId,
|
|
107
|
+
onWatchdogTrigger,
|
|
108
|
+
});
|
|
109
|
+
// Bridge watchdog's abort signal to our shared abort controller
|
|
110
|
+
abortSignalHandler = () => forceAbortController.abort();
|
|
111
|
+
watchdogController.abortSignal.addEventListener("abort", abortSignalHandler, { once: true });
|
|
112
|
+
},
|
|
113
|
+
onData: (chunk) => {
|
|
114
|
+
watchdogController?.handleOutput(chunk);
|
|
115
|
+
},
|
|
116
|
+
abortSignal: forceAbortController.signal,
|
|
117
|
+
});
|
|
118
|
+
exitCode = result.exitCode;
|
|
119
|
+
signal = result.signal;
|
|
120
|
+
aborted = result.aborted ?? false;
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
// Clean up abort signal listener
|
|
124
|
+
if (abortSignalHandler && watchdogController) {
|
|
125
|
+
watchdogController.abortSignal.removeEventListener("abort", abortSignalHandler);
|
|
126
|
+
}
|
|
127
|
+
watchdogController?.cleanup();
|
|
128
|
+
// Ensure streams are fully closed to prevent hanging on exit
|
|
129
|
+
if (!stdoutStream.closed) {
|
|
130
|
+
stdoutStream.end();
|
|
131
|
+
}
|
|
132
|
+
if (!stderrStream.closed) {
|
|
133
|
+
stderrStream.end();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const watchdogState = watchdogController?.getState();
|
|
137
|
+
const watchdogTrigger = watchdogState?.triggered ?? undefined;
|
|
138
|
+
let errorMessage;
|
|
139
|
+
if (watchdogTrigger && watchdogState?.triggeredReason) {
|
|
140
|
+
errorMessage = aborted
|
|
141
|
+
? `${watchdogState.triggeredReason} (force-aborted after unresponsive to signals)`
|
|
142
|
+
: watchdogState.triggeredReason;
|
|
143
|
+
}
|
|
144
|
+
else if (signal) {
|
|
145
|
+
errorMessage = `Agent terminated by signal ${signal}`;
|
|
146
|
+
}
|
|
147
|
+
else if (exitCode !== 0) {
|
|
148
|
+
errorMessage = `Agent exited with code ${exitCode}`;
|
|
149
|
+
}
|
|
150
|
+
const watchdog = {
|
|
151
|
+
silenceTimeoutMs: WATCHDOG_DEFAULTS.silenceTimeoutMs,
|
|
152
|
+
wallClockCapMs: WATCHDOG_DEFAULTS.wallClockCapMs,
|
|
153
|
+
trigger: watchdogTrigger,
|
|
154
|
+
};
|
|
155
|
+
return { exitCode, errorMessage, signal, watchdog };
|
|
156
|
+
}
|
|
157
|
+
export async function stageManifestForSandbox(options) {
|
|
158
|
+
const { runtimeManifestPath } = options;
|
|
159
|
+
let rawManifest;
|
|
160
|
+
try {
|
|
161
|
+
rawManifest = await readFile(runtimeManifestPath, "utf8");
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
165
|
+
throw new AgentProcessError({
|
|
166
|
+
detail: `Failed to read manifest at "${runtimeManifestPath}": ${detail}`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
let manifest;
|
|
170
|
+
try {
|
|
171
|
+
manifest = JSON.parse(rawManifest);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
175
|
+
throw new AgentProcessError({
|
|
176
|
+
detail: `Manifest JSON at "${runtimeManifestPath}" is invalid: ${detail}`,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const manifestDir = dirname(runtimeManifestPath);
|
|
180
|
+
const promptAbsolute = isAbsolute(manifest.promptPath)
|
|
181
|
+
? manifest.promptPath
|
|
182
|
+
: resolvePath(manifestDir, manifest.promptPath);
|
|
183
|
+
const workspaceAbsolute = isAbsolute(manifest.workspace)
|
|
184
|
+
? manifest.workspace
|
|
185
|
+
: resolvePath(manifestDir, manifest.workspace);
|
|
186
|
+
const manifestNeedsUpdate = manifest.promptPath !== promptAbsolute ||
|
|
187
|
+
manifest.workspace !== workspaceAbsolute;
|
|
188
|
+
if (manifestNeedsUpdate) {
|
|
189
|
+
const updatedManifest = {
|
|
190
|
+
...manifest,
|
|
191
|
+
promptPath: promptAbsolute,
|
|
192
|
+
workspace: workspaceAbsolute,
|
|
193
|
+
};
|
|
194
|
+
await writeFile(runtimeManifestPath, `${JSON.stringify(updatedManifest, null, 2)}\n`, "utf8");
|
|
195
|
+
}
|
|
196
|
+
return runtimeManifestPath;
|
|
197
|
+
}
|
|
198
|
+
function resolveSrtBinaryPath() {
|
|
199
|
+
const overridePath = process.env[SRT_BINARY_ENV];
|
|
200
|
+
if (overridePath && overridePath.length > 0) {
|
|
201
|
+
return overridePath;
|
|
202
|
+
}
|
|
203
|
+
if (!cachedSrtBinaryPath) {
|
|
204
|
+
const cliRoot = resolveCliAssetRoot();
|
|
205
|
+
cachedSrtBinaryPath = resolveSrtBinary(cliRoot);
|
|
206
|
+
}
|
|
207
|
+
return cachedSrtBinaryPath;
|
|
208
|
+
}
|
|
209
|
+
function resolveShimEntryPath() {
|
|
210
|
+
return getCliAssetPath("dist", "commands", "run", "shim", "run-agent-shim.mjs");
|
|
211
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AgentDefinition } from "../../../configs/agents/types.js";
|
|
2
|
+
import type { EnvironmentConfig } from "../../../configs/environment/types.js";
|
|
3
|
+
import type { EvalDefinition } from "../../../configs/evals/types.js";
|
|
4
|
+
import type { AgentInvocationRecord } from "../../../records/types.js";
|
|
5
|
+
import type { AgentWorkspacePaths } from "../../../workspace/layout.js";
|
|
6
|
+
import type { AgentExecutionResult } from "../reports.js";
|
|
7
|
+
import type { StagedAuthContext } from "./auth-stage.js";
|
|
8
|
+
import { AgentRunContext } from "./run-context.js";
|
|
9
|
+
export interface AgentExecutionContext {
|
|
10
|
+
agent: AgentDefinition;
|
|
11
|
+
baseRevisionSha: string;
|
|
12
|
+
runId: string;
|
|
13
|
+
root: string;
|
|
14
|
+
evalPlan: readonly EvalDefinition[];
|
|
15
|
+
environment: EnvironmentConfig;
|
|
16
|
+
}
|
|
17
|
+
export interface AgentProgressCallbacks {
|
|
18
|
+
onRunning?: (record: AgentInvocationRecord) => Promise<void> | void;
|
|
19
|
+
onCompleted?: (result: AgentExecutionResult) => Promise<void> | void;
|
|
20
|
+
/** Callback for early failure (e.g., watchdog trigger) before process fully exits. */
|
|
21
|
+
onEarlyFailure?: (record: AgentInvocationRecord) => Promise<void> | void;
|
|
22
|
+
}
|
|
23
|
+
export interface PreparedAgentExecution {
|
|
24
|
+
agent: AgentDefinition;
|
|
25
|
+
agentContext: AgentRunContext;
|
|
26
|
+
workspacePaths: AgentWorkspacePaths;
|
|
27
|
+
runtimeManifestPath: string;
|
|
28
|
+
baseRevisionSha: string;
|
|
29
|
+
root: string;
|
|
30
|
+
runId: string;
|
|
31
|
+
evalPlan: readonly EvalDefinition[];
|
|
32
|
+
environment: EnvironmentConfig;
|
|
33
|
+
manifestEnv: Record<string, string>;
|
|
34
|
+
progress?: AgentProgressCallbacks;
|
|
35
|
+
authContext?: StagedAuthContext;
|
|
36
|
+
}
|
|
37
|
+
export type AgentPreparationOutcome = {
|
|
38
|
+
status: "ready";
|
|
39
|
+
prepared: PreparedAgentExecution;
|
|
40
|
+
} | {
|
|
41
|
+
status: "failed";
|
|
42
|
+
result: AgentExecutionResult;
|
|
43
|
+
};
|
|
44
|
+
export interface AgentPreparationResult {
|
|
45
|
+
ready: PreparedAgentExecution[];
|
|
46
|
+
failures: AgentExecutionResult[];
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|