engineering-behavior-observatory 0.2.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/LICENSE +202 -0
- package/README.md +151 -0
- package/contracts/codex-app-server-0.150.1/manifest.json +25 -0
- package/contracts/codex-app-server-0.150.1/schema/InitializeParams.json +84 -0
- package/contracts/codex-app-server-0.150.1/schema/JSONRPCMessage.json +137 -0
- package/contracts/codex-app-server-0.150.1/schema/v2/ThreadReadParams.json +17 -0
- package/contracts/codex-app-server-0.150.1/schema/v2/ThreadTokenUsageUpdatedNotification.json +82 -0
- package/contracts/codex-app-server-0.150.1/schema/v2/TurnInterruptParams.json +17 -0
- package/contracts/codex-app-server-0.150.1/types/AskForApproval.ts +5 -0
- package/contracts/codex-app-server-0.150.1/types/ClientNotification.ts +5 -0
- package/contracts/codex-app-server-0.150.1/types/SandboxMode.ts +5 -0
- package/contracts/codex-app-server-0.150.1/types/ThreadReadParams.ts +9 -0
- package/contracts/codex-app-server-0.150.1/types/TokenUsageBreakdown.ts +5 -0
- package/contracts/codex-app-server-0.150.1/types/TurnInterruptParams.ts +5 -0
- package/contracts/codex-app-server-0.153.4/manifest.json +27 -0
- package/contracts/codex-app-server-0.153.4/schema/JSONRPCMessage.json +137 -0
- package/contracts/codex-app-server-0.153.4/schema/v1/InitializeParams.json +84 -0
- package/contracts/codex-app-server-0.153.4/schema/v2/ThreadReadParams.json +17 -0
- package/contracts/codex-app-server-0.153.4/schema/v2/ThreadStartParams.json +515 -0
- package/contracts/codex-app-server-0.153.4/schema/v2/ThreadTokenUsageUpdatedNotification.json +82 -0
- package/contracts/codex-app-server-0.153.4/schema/v2/TurnInterruptParams.json +17 -0
- package/contracts/codex-app-server-0.153.4/schema/v2/TurnStartParams.json +921 -0
- package/contracts/codex-app-server-0.153.4/types/AskForApproval.ts +5 -0
- package/contracts/codex-app-server-0.153.4/types/ClientNotification.ts +5 -0
- package/contracts/codex-app-server-0.153.4/types/SandboxMode.ts +5 -0
- package/contracts/codex-app-server-0.153.4/types/ThreadReadParams.ts +12 -0
- package/contracts/codex-app-server-0.153.4/types/TokenUsageBreakdown.ts +5 -0
- package/contracts/codex-app-server-0.153.4/types/TurnInterruptParams.ts +5 -0
- package/contracts/openhands-agent-server-v1.44.1.json +65 -0
- package/contracts/openhands-agent-server-v1.46.0.json +46 -0
- package/dist/contracts/codex-app-server-0.153.4/types/AskForApproval.d.ts +9 -0
- package/dist/contracts/codex-app-server-0.153.4/types/AskForApproval.js +2 -0
- package/dist/contracts/codex-app-server-0.153.4/types/ClientNotification.d.ts +3 -0
- package/dist/contracts/codex-app-server-0.153.4/types/ClientNotification.js +2 -0
- package/dist/contracts/codex-app-server-0.153.4/types/SandboxMode.d.ts +1 -0
- package/dist/contracts/codex-app-server-0.153.4/types/SandboxMode.js +2 -0
- package/dist/contracts/codex-app-server-0.153.4/types/ThreadReadParams.d.ts +10 -0
- package/dist/contracts/codex-app-server-0.153.4/types/ThreadReadParams.js +2 -0
- package/dist/contracts/codex-app-server-0.153.4/types/TokenUsageBreakdown.d.ts +8 -0
- package/dist/contracts/codex-app-server-0.153.4/types/TokenUsageBreakdown.js +2 -0
- package/dist/contracts/codex-app-server-0.153.4/types/TurnInterruptParams.d.ts +4 -0
- package/dist/contracts/codex-app-server-0.153.4/types/TurnInterruptParams.js +2 -0
- package/dist/src/agent-sdk-normalizer.d.ts +22 -0
- package/dist/src/agent-sdk-normalizer.js +995 -0
- package/dist/src/agent-sdk-run.d.ts +31 -0
- package/dist/src/agent-sdk-run.js +242 -0
- package/dist/src/agent-sdk-runner.d.ts +96 -0
- package/dist/src/agent-sdk-runner.js +407 -0
- package/dist/src/agent-sdk.d.ts +294 -0
- package/dist/src/agent-sdk.js +644 -0
- package/dist/src/aggregation.d.ts +183 -0
- package/dist/src/aggregation.js +513 -0
- package/dist/src/artifacts.d.ts +36 -0
- package/dist/src/artifacts.js +1372 -0
- package/dist/src/atlas-grafana.d.ts +377 -0
- package/dist/src/atlas-grafana.js +47 -0
- package/dist/src/atlas-html.d.ts +2 -0
- package/dist/src/atlas-html.js +34 -0
- package/dist/src/atlas.d.ts +130 -0
- package/dist/src/atlas.js +235 -0
- package/dist/src/behavior-assertions.d.ts +95 -0
- package/dist/src/behavior-assertions.js +154 -0
- package/dist/src/cli.d.ts +5 -0
- package/dist/src/cli.js +957 -0
- package/dist/src/codex-judge.d.ts +44 -0
- package/dist/src/codex-judge.js +214 -0
- package/dist/src/codex-run.d.ts +114 -0
- package/dist/src/codex-run.js +519 -0
- package/dist/src/codex.d.ts +187 -0
- package/dist/src/codex.js +1028 -0
- package/dist/src/contracts.d.ts +155 -0
- package/dist/src/contracts.js +866 -0
- package/dist/src/corpus.d.ts +67 -0
- package/dist/src/corpus.js +540 -0
- package/dist/src/cursor-sdk-runner.d.ts +81 -0
- package/dist/src/cursor-sdk-runner.js +362 -0
- package/dist/src/cursor-sdk.d.ts +81 -0
- package/dist/src/cursor-sdk.js +1078 -0
- package/dist/src/deepseek-adapter.d.ts +152 -0
- package/dist/src/deepseek-adapter.js +777 -0
- package/dist/src/exports.d.ts +69 -0
- package/dist/src/exports.js +966 -0
- package/dist/src/human-calibration.d.ts +167 -0
- package/dist/src/human-calibration.js +618 -0
- package/dist/src/index.d.ts +71 -0
- package/dist/src/index.js +38 -0
- package/dist/src/lifecycle.d.ts +196 -0
- package/dist/src/lifecycle.js +1889 -0
- package/dist/src/normalization-integrity.d.ts +128 -0
- package/dist/src/normalization-integrity.js +429 -0
- package/dist/src/openhands-run.d.ts +36 -0
- package/dist/src/openhands-run.js +415 -0
- package/dist/src/openhands.d.ts +130 -0
- package/dist/src/openhands.js +859 -0
- package/dist/src/pi.d.ts +203 -0
- package/dist/src/pi.js +1345 -0
- package/dist/src/process-protocol.d.ts +245 -0
- package/dist/src/process-protocol.js +1261 -0
- package/dist/src/retained-evidence.d.ts +12 -0
- package/dist/src/retained-evidence.js +201 -0
- package/dist/src/run-bundles.d.ts +193 -0
- package/dist/src/run-bundles.js +993 -0
- package/dist/src/scheduler.d.ts +109 -0
- package/dist/src/scheduler.js +1080 -0
- package/dist/src/semantic-judge.d.ts +194 -0
- package/dist/src/semantic-judge.js +875 -0
- package/dist/src/structural-observations.d.ts +124 -0
- package/dist/src/structural-observations.js +671 -0
- package/dist/src/task-packets.d.ts +115 -0
- package/dist/src/task-packets.js +683 -0
- package/dist/src/uniform-events.d.ts +120 -0
- package/dist/src/uniform-events.js +158 -0
- package/dist/src/verifiers.d.ts +116 -0
- package/dist/src/verifiers.js +819 -0
- package/dist/src/workspaces.d.ts +56 -0
- package/dist/src/workspaces.js +1314 -0
- package/docs/README.md +60 -0
- package/docs/development/README.md +71 -0
- package/docs/development/documentation-sync.md +58 -0
- package/docs/development/extension-contracts.md +307 -0
- package/docs/evaluation/README.md +48 -0
- package/docs/evaluation/aggregation.md +112 -0
- package/docs/evaluation/behavior-assertions.md +45 -0
- package/docs/evaluation/human-calibration.md +170 -0
- package/docs/evaluation/normalization-integrity.md +80 -0
- package/docs/evaluation/semantic-judge.md +188 -0
- package/docs/evaluation/structural-observations.md +84 -0
- package/docs/evaluation/uniform-events.md +131 -0
- package/docs/guides/atlas.md +144 -0
- package/docs/guides/evidence-and-sharing.md +100 -0
- package/docs/guides/operator-guide.md +424 -0
- package/docs/guides/quickstart.md +152 -0
- package/docs/guides/telemetry.md +66 -0
- package/docs/harnesses/README.md +31 -0
- package/docs/harnesses/claude-agent-sdk.md +61 -0
- package/docs/harnesses/codex-harness.md +174 -0
- package/docs/harnesses/cursor-sdk.md +149 -0
- package/docs/harnesses/deepseek-harness.md +134 -0
- package/docs/harnesses/openhands-agent-server.md +153 -0
- package/docs/harnesses/pi-sdk.md +66 -0
- package/docs/reference/README.md +19 -0
- package/docs/reference/agent-sdk-operational-runner.md +118 -0
- package/docs/reference/cli.md +114 -0
- package/docs/reference/contracts.md +222 -0
- package/docs/reference/run-bundle-contract.md +354 -0
- package/docs/reference/run-lifecycle.md +54 -0
- package/examples/cursor-sdk/README.md +11 -0
- package/examples/cursor-sdk/capture-profile.json +1 -0
- package/examples/cursor-sdk/harness.json +1 -0
- package/examples/cursor-sdk/model.json +1 -0
- package/examples/cursor-sdk/native-limits.json +1 -0
- package/examples/cursor-sdk/native-tool-policy.json +1 -0
- package/ontology/behavior-categories.v1.json +46 -0
- package/package.json +66 -0
- package/release/0.1.0/KNOWN_LIMITATIONS.md +35 -0
- package/release/0.1.0/README.md +46 -0
- package/release/0.1.0/reproducibility.json +61 -0
- package/release/0.2.0/KNOWN_LIMITATIONS.md +40 -0
- package/release/0.2.0/README.md +42 -0
- package/release/0.2.0/reproducibility.json +73 -0
- package/release/0.2.1/KNOWN_LIMITATIONS.md +18 -0
- package/release/0.2.1/README.md +63 -0
- package/release/0.2.1/reproducibility.json +73 -0
- package/release/README.md +13 -0
- package/schemas/aggregation.v1.json +293 -0
- package/schemas/behavior-assertions.v1.json +220 -0
- package/schemas/deepseek-runtime-composition.v1.schema.json +122 -0
- package/schemas/experiment.v1.schema.json +188 -0
- package/schemas/human-calibration.v1.json +336 -0
- package/schemas/normalization-integrity.v1.json +302 -0
- package/schemas/run-bundles/v1.json +1040 -0
- package/schemas/run-queue.v1.schema.json +206 -0
- package/schemas/semantic-judge.v1.json +380 -0
- package/schemas/structural-observations.v1.json +131 -0
- package/schemas/task-packet-freeze.v1.schema.json +106 -0
- package/schemas/task-packet.v1.schema.json +234 -0
- package/schemas/uniform-events/v1.json +289 -0
- package/scripts/atlas-grafana.sh +18 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HookEvent } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import { type ClaudeAgentSdkCaptureReport, type ClaudeAgentSdkConfiguration, type ClaudeAgentSdkQuery } from "./agent-sdk.js";
|
|
3
|
+
import { type RunAttemptResult, type VerifierExecutionContext, type WorkspaceCoordinator } from "./lifecycle.js";
|
|
4
|
+
import { type CaptureQualificationReport, type CapturedWorkspaceOutcome, type RunBundleDefinition, type RunManifest } from "./run-bundles.js";
|
|
5
|
+
import type { VerifierResult } from "./verifiers.js";
|
|
6
|
+
export type CaptureClaudeAgentSdkVerifier = (context: VerifierExecutionContext, workspace: CapturedWorkspaceOutcome, workspacePath: string) => VerifierResult | Promise<VerifierResult>;
|
|
7
|
+
export type CaptureClaudeAgentSdkRunOptions = {
|
|
8
|
+
definition: RunBundleDefinition;
|
|
9
|
+
startingWorkspacePath: string;
|
|
10
|
+
workspace: WorkspaceCoordinator;
|
|
11
|
+
configuration: ClaudeAgentSdkConfiguration;
|
|
12
|
+
verifier?: CaptureClaudeAgentSdkVerifier;
|
|
13
|
+
workspaceOutcomeExcludedDirectoryNames?: readonly string[];
|
|
14
|
+
workspaceOutcomeRespectsGitignore?: boolean;
|
|
15
|
+
workspaceOutcomeOmitsEmptyDirectories?: boolean;
|
|
16
|
+
expectedHooks?: readonly HookEvent[];
|
|
17
|
+
query?: ClaudeAgentSdkQuery;
|
|
18
|
+
traceId?: string;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
maxWallClockMs?: number;
|
|
21
|
+
harnessBudgetMs?: number;
|
|
22
|
+
shutdownGraceMs?: number;
|
|
23
|
+
};
|
|
24
|
+
export type CaptureClaudeAgentSdkRunResult = {
|
|
25
|
+
attempt: RunAttemptResult;
|
|
26
|
+
manifest: RunManifest;
|
|
27
|
+
qualification: CaptureQualificationReport;
|
|
28
|
+
stream: ClaudeAgentSdkCaptureReport;
|
|
29
|
+
};
|
|
30
|
+
/** Execute and retain one caller-configured Agent SDK attempt without scheduling or retrying it. */
|
|
31
|
+
export declare function captureClaudeAgentSdkRun(options: CaptureClaudeAgentSdkRunOptions): Promise<CaptureClaudeAgentSdkRunResult>;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { executeClaudeAgentSdk, openClaudeAgentSdkHookCapture, openClaudeAgentSdkStreamCapture, probeClaudeAgentSdkCapabilities, } from "./agent-sdk.js";
|
|
3
|
+
import { createAttemptIdentity, createRunIdentity, executeRunAttempt, } from "./lifecycle.js";
|
|
4
|
+
import { createRunBundleAssembler, qualifyRunBundle, } from "./run-bundles.js";
|
|
5
|
+
/** Execute and retain one caller-configured Agent SDK attempt without scheduling or retrying it. */
|
|
6
|
+
export async function captureClaudeAgentSdkRun(options) {
|
|
7
|
+
if (options.definition.run.model.id !== options.configuration.model) {
|
|
8
|
+
throw new Error("The declared model must match the Agent SDK model configuration.");
|
|
9
|
+
}
|
|
10
|
+
const expectedHooks = [...new Set(options.expectedHooks ?? [])];
|
|
11
|
+
const capabilities = probeClaudeAgentSdkCapabilities();
|
|
12
|
+
const definition = withPinnedRuntime(options.definition, capabilities.sdkVersion, capabilities.claudeCodeVersion);
|
|
13
|
+
const assembler = await createRunBundleAssembler(definition);
|
|
14
|
+
const hookCapture = await openClaudeAgentSdkHookCapture(`${assembler.bundleRoot}/hooks.jsonl`);
|
|
15
|
+
const streamCapture = await openClaudeAgentSdkStreamCapture(`${assembler.bundleRoot}/session.jsonl`, {
|
|
16
|
+
message: () => undefined,
|
|
17
|
+
stderr: () => undefined,
|
|
18
|
+
hook: hookCapture.hook,
|
|
19
|
+
lifecycle: () => undefined,
|
|
20
|
+
flush: hookCapture.flush,
|
|
21
|
+
});
|
|
22
|
+
let workspace;
|
|
23
|
+
let workspaceOutcome;
|
|
24
|
+
let workspaceOutcomePromise;
|
|
25
|
+
let workspaceCaptureError;
|
|
26
|
+
let verifierResult;
|
|
27
|
+
let verifierError;
|
|
28
|
+
const captureWorkspace = async (verifierContext) => {
|
|
29
|
+
if (workspaceOutcome !== undefined)
|
|
30
|
+
return workspaceOutcome;
|
|
31
|
+
workspaceOutcomePromise ??= (async () => {
|
|
32
|
+
if (workspace?.status !== "ready" || workspace.path === undefined || workspace.artifactId === undefined) {
|
|
33
|
+
throw new Error("Agent SDK capture requires a retained ready workspace before outcome packaging.");
|
|
34
|
+
}
|
|
35
|
+
workspaceOutcome = await assembler.captureWorkspaceOutcome({
|
|
36
|
+
startPath: options.startingWorkspacePath,
|
|
37
|
+
finalPath: workspace.path,
|
|
38
|
+
id: workspace.artifactId,
|
|
39
|
+
...(options.workspaceOutcomeExcludedDirectoryNames === undefined ? {} : {
|
|
40
|
+
excludeDirectoryNames: options.workspaceOutcomeExcludedDirectoryNames,
|
|
41
|
+
}),
|
|
42
|
+
...(options.workspaceOutcomeRespectsGitignore === undefined ? {} : {
|
|
43
|
+
respectGitignore: options.workspaceOutcomeRespectsGitignore,
|
|
44
|
+
}),
|
|
45
|
+
...(options.workspaceOutcomeOmitsEmptyDirectories === undefined ? {} : {
|
|
46
|
+
omitEmptyDirectories: options.workspaceOutcomeOmitsEmptyDirectories,
|
|
47
|
+
}),
|
|
48
|
+
}, verifierContext === undefined || options.verifier === undefined
|
|
49
|
+
? undefined
|
|
50
|
+
: async (projectedPath, outcome) => {
|
|
51
|
+
try {
|
|
52
|
+
const aborted = Symbol("aborted");
|
|
53
|
+
let onAbort;
|
|
54
|
+
const verifierPromise = Promise.resolve(options.verifier(verifierContext, outcome, projectedPath));
|
|
55
|
+
const verifierOutcome = await Promise.race([
|
|
56
|
+
verifierPromise,
|
|
57
|
+
new Promise((resolvePromise) => {
|
|
58
|
+
onAbort = () => resolvePromise(aborted);
|
|
59
|
+
if (verifierContext.signal.aborted)
|
|
60
|
+
onAbort();
|
|
61
|
+
else
|
|
62
|
+
verifierContext.signal.addEventListener("abort", onAbort, { once: true });
|
|
63
|
+
}),
|
|
64
|
+
]);
|
|
65
|
+
if (onAbort !== undefined)
|
|
66
|
+
verifierContext.signal.removeEventListener("abort", onAbort);
|
|
67
|
+
if (verifierOutcome === aborted) {
|
|
68
|
+
let graceTimer;
|
|
69
|
+
const settled = await Promise.race([
|
|
70
|
+
verifierPromise.then((value) => ({ kind: "result", value }), (error) => ({ kind: "error", error })),
|
|
71
|
+
new Promise((resolvePromise) => {
|
|
72
|
+
graceTimer = setTimeout(() => resolvePromise({ kind: "timed-out" }), options.shutdownGraceMs ?? 250);
|
|
73
|
+
}),
|
|
74
|
+
]);
|
|
75
|
+
if (graceTimer !== undefined)
|
|
76
|
+
clearTimeout(graceTimer);
|
|
77
|
+
if (settled.kind === "result")
|
|
78
|
+
verifierResult = settled.value;
|
|
79
|
+
else if (settled.kind === "error")
|
|
80
|
+
verifierError = settled.error;
|
|
81
|
+
else
|
|
82
|
+
void verifierPromise.catch(() => undefined);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
verifierResult = verifierOutcome;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
verifierError = error;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return workspaceOutcome;
|
|
93
|
+
})().catch((error) => {
|
|
94
|
+
workspaceCaptureError = error instanceof Error ? error.message : String(error);
|
|
95
|
+
throw error;
|
|
96
|
+
});
|
|
97
|
+
return workspaceOutcomePromise;
|
|
98
|
+
};
|
|
99
|
+
const coordinatedWorkspace = {
|
|
100
|
+
setup: async (context) => {
|
|
101
|
+
workspace = await options.workspace.setup(context);
|
|
102
|
+
return workspace;
|
|
103
|
+
},
|
|
104
|
+
cleanup: async (context) => {
|
|
105
|
+
if (workspace?.status === "ready")
|
|
106
|
+
await captureWorkspace();
|
|
107
|
+
await options.workspace.cleanup?.(context);
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
const run = createRunIdentity({
|
|
111
|
+
id: definition.run.id,
|
|
112
|
+
taskId: definition.run.task.id,
|
|
113
|
+
modelId: definition.run.model.id,
|
|
114
|
+
harnessId: definition.run.harness.id,
|
|
115
|
+
});
|
|
116
|
+
const attemptIdentity = createAttemptIdentity(definition.run.id, definition.attempt.number, definition.attempt.id, definition.attempt.retryOf);
|
|
117
|
+
let attempt;
|
|
118
|
+
try {
|
|
119
|
+
attempt = await executeRunAttempt({
|
|
120
|
+
run,
|
|
121
|
+
assessmentMode: definition.run.assessmentMode,
|
|
122
|
+
attempt: attemptIdentity,
|
|
123
|
+
workspace: coordinatedWorkspace,
|
|
124
|
+
harness: (context) => executeClaudeAgentSdk(context, options.configuration, streamCapture, options.query),
|
|
125
|
+
...(options.verifier === undefined ? {} : {
|
|
126
|
+
verifier: async (context) => {
|
|
127
|
+
await captureWorkspace(context);
|
|
128
|
+
if (verifierError !== undefined)
|
|
129
|
+
throw verifierError;
|
|
130
|
+
if (verifierResult === undefined)
|
|
131
|
+
throw new Error("Agent SDK verifier did not return a result.");
|
|
132
|
+
const result = verifierResult;
|
|
133
|
+
await assembler.writeJsonArtifact({
|
|
134
|
+
id: "verifier",
|
|
135
|
+
source: "ebo-verifier",
|
|
136
|
+
kind: "verifier",
|
|
137
|
+
mediaType: "application/json",
|
|
138
|
+
sharingClass: "restricted",
|
|
139
|
+
relativePath: "verifier.json",
|
|
140
|
+
}, result);
|
|
141
|
+
return {
|
|
142
|
+
status: result.status,
|
|
143
|
+
...(result.error === undefined ? {} : { error: result.error }),
|
|
144
|
+
evidence: result,
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
evidence: streamCapture,
|
|
149
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
150
|
+
...(options.maxWallClockMs === undefined ? {} : { maxWallClockMs: options.maxWallClockMs }),
|
|
151
|
+
...(options.harnessBudgetMs === undefined ? {} : { harnessBudgetMs: options.harnessBudgetMs }),
|
|
152
|
+
...(options.shutdownGraceMs === undefined ? {} : { shutdownGraceMs: options.shutdownGraceMs }),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
await Promise.allSettled([streamCapture.close(), hookCapture.close()]);
|
|
157
|
+
}
|
|
158
|
+
if (workspace?.status === "ready")
|
|
159
|
+
await captureWorkspace().catch(() => undefined);
|
|
160
|
+
const stream = streamCapture.report();
|
|
161
|
+
if (await isNonemptyFile(streamCapture.path)) {
|
|
162
|
+
await assembler.registerArtifact({
|
|
163
|
+
id: "session",
|
|
164
|
+
source: "anthropic-agent-sdk",
|
|
165
|
+
kind: "session",
|
|
166
|
+
mediaType: "application/x-ndjson",
|
|
167
|
+
sharingClass: "restricted",
|
|
168
|
+
relativePath: "session.jsonl",
|
|
169
|
+
...(stream.capabilities.sessionIdentity.status === "available"
|
|
170
|
+
? { nativeReference: { type: "session", id: stream.capabilities.sessionIdentity.sessionId } }
|
|
171
|
+
: {}),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (await isNonemptyFile(hookCapture.path)) {
|
|
175
|
+
await assembler.registerArtifact({
|
|
176
|
+
id: "hooks",
|
|
177
|
+
source: "anthropic-agent-sdk",
|
|
178
|
+
kind: "hook",
|
|
179
|
+
mediaType: "application/x-ndjson",
|
|
180
|
+
sharingClass: "restricted",
|
|
181
|
+
relativePath: "hooks.jsonl",
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
const agentSdkEvidence = attempt.record.harness?.evidence;
|
|
185
|
+
if (agentSdkEvidence?.telemetry !== undefined || agentSdkEvidence?.usage !== undefined) {
|
|
186
|
+
await assembler.writeAgentSdkTelemetry({ evidence: agentSdkEvidence, ...(options.traceId === undefined ? {} : { traceId: options.traceId }) });
|
|
187
|
+
}
|
|
188
|
+
const missingEvidence = [
|
|
189
|
+
...(stream.status === "complete" ? [] : [{
|
|
190
|
+
kind: "session-completion",
|
|
191
|
+
reason: attempt.terminal.state === "interrupted" ? "process-interrupted" : "not-emitted",
|
|
192
|
+
affects: ["semantic"],
|
|
193
|
+
}]),
|
|
194
|
+
...(workspaceOutcome === undefined && workspaceCaptureError !== undefined ? [{
|
|
195
|
+
kind: "workspace",
|
|
196
|
+
reason: "not-collected",
|
|
197
|
+
affects: ["outcome"],
|
|
198
|
+
detail: workspaceCaptureError.slice(0, 4096),
|
|
199
|
+
}] : []),
|
|
200
|
+
];
|
|
201
|
+
const qualificationOptions = {
|
|
202
|
+
startingWorkspacePath: options.startingWorkspacePath,
|
|
203
|
+
...(options.workspaceOutcomeExcludedDirectoryNames === undefined ? {} : {
|
|
204
|
+
workspaceOutcomeExcludedDirectoryNames: options.workspaceOutcomeExcludedDirectoryNames,
|
|
205
|
+
}),
|
|
206
|
+
...(options.workspaceOutcomeRespectsGitignore === undefined ? {} : {
|
|
207
|
+
workspaceOutcomeRespectsGitignore: options.workspaceOutcomeRespectsGitignore,
|
|
208
|
+
}),
|
|
209
|
+
...(options.workspaceOutcomeOmitsEmptyDirectories === undefined ? {} : {
|
|
210
|
+
workspaceOutcomeOmitsEmptyDirectories: options.workspaceOutcomeOmitsEmptyDirectories,
|
|
211
|
+
}),
|
|
212
|
+
...(agentSdkEvidence === undefined ? {} : { agentSdkEvidence }),
|
|
213
|
+
hookCapabilities: capabilities,
|
|
214
|
+
expectedHooks,
|
|
215
|
+
};
|
|
216
|
+
const terminal = structuredClone(attempt.terminal);
|
|
217
|
+
if (workspaceOutcome === undefined)
|
|
218
|
+
delete terminal.workspaceArtifactId;
|
|
219
|
+
const manifest = await assembler.finalize({
|
|
220
|
+
terminal,
|
|
221
|
+
missingEvidence,
|
|
222
|
+
qualification: qualificationOptions,
|
|
223
|
+
});
|
|
224
|
+
const qualification = await qualifyRunBundle(assembler.bundleRoot, qualificationOptions);
|
|
225
|
+
return { attempt, manifest, qualification, stream };
|
|
226
|
+
}
|
|
227
|
+
async function isNonemptyFile(path) {
|
|
228
|
+
const size = (await stat(path).catch(() => undefined))?.size;
|
|
229
|
+
return size !== undefined && size > 0;
|
|
230
|
+
}
|
|
231
|
+
function withPinnedRuntime(definition, sdkVersion, claudeCodeVersion) {
|
|
232
|
+
const runtime = definition.run.runtime.filter((component) => !(component.source === "anthropic" && (component.name === "agent-sdk" || component.name === "agent-cli")));
|
|
233
|
+
runtime.push({ source: "anthropic", name: "agent-sdk", version: sdkVersion }, { source: "anthropic", name: "agent-cli", version: claudeCodeVersion });
|
|
234
|
+
return {
|
|
235
|
+
...structuredClone(definition),
|
|
236
|
+
run: {
|
|
237
|
+
...structuredClone(definition.run),
|
|
238
|
+
harness: { ...structuredClone(definition.run.harness), version: sdkVersion },
|
|
239
|
+
runtime,
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { PermissionMode } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import { type ClaudeAgentSdkQuery, type ClaudeAgentSdkTelemetryConfiguration } from "./agent-sdk.js";
|
|
3
|
+
import { type ArtifactReference } from "./contracts.js";
|
|
4
|
+
import type { AttemptClassificationKind, TerminalRecord } from "./lifecycle.js";
|
|
5
|
+
import type { CaptureQualificationStatus } from "./run-bundles.js";
|
|
6
|
+
import { type TaskPacket } from "./task-packets.js";
|
|
7
|
+
export declare const AGENT_SDK_CONFIG_SCHEMA_VERSION = "ebo.agent-sdk-config/v1";
|
|
8
|
+
export type AgentSdkModelConfiguration = {
|
|
9
|
+
schemaVersion: typeof AGENT_SDK_CONFIG_SCHEMA_VERSION;
|
|
10
|
+
kind: "model";
|
|
11
|
+
model: string;
|
|
12
|
+
};
|
|
13
|
+
export type AgentSdkHarnessConfiguration = {
|
|
14
|
+
schemaVersion: typeof AGENT_SDK_CONFIG_SCHEMA_VERSION;
|
|
15
|
+
kind: "harness";
|
|
16
|
+
adapter: "claude-agent-sdk";
|
|
17
|
+
};
|
|
18
|
+
export type AgentSdkNativeLimitsConfiguration = {
|
|
19
|
+
schemaVersion: typeof AGENT_SDK_CONFIG_SCHEMA_VERSION;
|
|
20
|
+
kind: "native-limits";
|
|
21
|
+
maxTurns?: number;
|
|
22
|
+
maxBudgetUsd?: number;
|
|
23
|
+
};
|
|
24
|
+
export type AgentSdkNativeToolPolicyConfiguration = {
|
|
25
|
+
schemaVersion: typeof AGENT_SDK_CONFIG_SCHEMA_VERSION;
|
|
26
|
+
kind: "native-tool-policy";
|
|
27
|
+
tools: string[];
|
|
28
|
+
allowedTools?: string[];
|
|
29
|
+
disallowedTools?: string[];
|
|
30
|
+
permissionMode: PermissionMode;
|
|
31
|
+
allowDangerouslySkipPermissions?: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type AgentSdkCaptureProfileConfiguration = {
|
|
34
|
+
schemaVersion: typeof AGENT_SDK_CONFIG_SCHEMA_VERSION;
|
|
35
|
+
kind: "capture-profile";
|
|
36
|
+
telemetry?: {
|
|
37
|
+
endpoint: string;
|
|
38
|
+
protocol?: "http/protobuf" | "http/json" | "grpc";
|
|
39
|
+
exportIntervalMs?: number;
|
|
40
|
+
logUserPrompts?: boolean;
|
|
41
|
+
logToolDetails?: boolean;
|
|
42
|
+
logToolContent?: boolean;
|
|
43
|
+
logRawApiBodies?: boolean;
|
|
44
|
+
};
|
|
45
|
+
workspaceOutcome?: {
|
|
46
|
+
excludeDirectoryNames: string[];
|
|
47
|
+
respectGitignore?: boolean;
|
|
48
|
+
omitEmptyDirectories?: boolean;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export type AgentSdkConfigurationRecord = AgentSdkModelConfiguration | AgentSdkHarnessConfiguration | AgentSdkNativeLimitsConfiguration | AgentSdkNativeToolPolicyConfiguration | AgentSdkCaptureProfileConfiguration;
|
|
52
|
+
export type AgentSdkConfigurationKind = AgentSdkConfigurationRecord["kind"];
|
|
53
|
+
export type RunAgentSdkQueueEntryOptions = {
|
|
54
|
+
bundleRoot: string;
|
|
55
|
+
queuePath: string;
|
|
56
|
+
runId: string;
|
|
57
|
+
outputRoot: string;
|
|
58
|
+
workspaceRoot?: string;
|
|
59
|
+
/** Deterministic attempt identity for tests or embedded callers; a fresh UUID otherwise. */
|
|
60
|
+
attemptId?: string;
|
|
61
|
+
/** Already-supported Agent SDK query seam for deterministic tests; never serialized configuration. */
|
|
62
|
+
query?: ClaudeAgentSdkQuery;
|
|
63
|
+
/** Already-supported collector receipt callback; never serialized configuration. */
|
|
64
|
+
checkTelemetryReceipt?: ClaudeAgentSdkTelemetryConfiguration["checkReceipt"];
|
|
65
|
+
signal?: AbortSignal;
|
|
66
|
+
};
|
|
67
|
+
export type AgentSdkRunSummary = {
|
|
68
|
+
runId: string;
|
|
69
|
+
attemptId: string;
|
|
70
|
+
bundlePath: string;
|
|
71
|
+
terminal: TerminalRecord;
|
|
72
|
+
classification: AttemptClassificationKind;
|
|
73
|
+
captureQualification: CaptureQualificationStatus;
|
|
74
|
+
assessmentMode: TaskPacket["assessmentMode"];
|
|
75
|
+
sessionId?: string;
|
|
76
|
+
traceId?: string;
|
|
77
|
+
/** Local path left by failed capture or cleanup; never itself a qualified artifact. */
|
|
78
|
+
retainedWorkspacePath?: string;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Execute exactly one frozen run-queue entry through the Claude Agent SDK and
|
|
82
|
+
* retain its run bundle under `<outputRoot>/<runId>/<attemptId>`. Preflight
|
|
83
|
+
* failures throw before any attempt evidence exists; once capture starts, the
|
|
84
|
+
* existing lifecycle retains complete or partial evidence without retrying.
|
|
85
|
+
*/
|
|
86
|
+
export declare function runAgentSdkQueueEntry(options: RunAgentSdkQueueEntryOptions): Promise<AgentSdkRunSummary>;
|
|
87
|
+
type AgentSdkConfigurationByKind = {
|
|
88
|
+
model: AgentSdkModelConfiguration;
|
|
89
|
+
harness: AgentSdkHarnessConfiguration;
|
|
90
|
+
"native-limits": AgentSdkNativeLimitsConfiguration;
|
|
91
|
+
"native-tool-policy": AgentSdkNativeToolPolicyConfiguration;
|
|
92
|
+
"capture-profile": AgentSdkCaptureProfileConfiguration;
|
|
93
|
+
};
|
|
94
|
+
/** Resolve one digest-pinned `ebo.agent-sdk-config/v1` record and validate it before SDK launch. */
|
|
95
|
+
export declare function resolveAgentSdkConfigurationRecord<Kind extends AgentSdkConfigurationKind>(bundleRoot: string, reference: ArtifactReference, kind: Kind): AgentSdkConfigurationByKind[Kind];
|
|
96
|
+
export {};
|