@culture.dev/agents 0.0.0-stage → 0.15.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 +201 -0
- package/README.md +59 -2
- package/dist/contract-schemas/agent.json +128 -0
- package/dist/contract-schemas/allowlist.json +25 -0
- package/dist/contract-schemas/api.json +501 -0
- package/dist/contract-schemas/capabilities.json +208 -0
- package/dist/contract-schemas/common.json +123 -0
- package/dist/contract-schemas/control-action.json +279 -0
- package/dist/contract-schemas/error.json +269 -0
- package/dist/contract-schemas/event.json +316 -0
- package/dist/contract-schemas/run.json +336 -0
- package/dist/contract-schemas/session.json +77 -0
- package/dist/contract-schemas/version.json +22 -0
- package/dist/src/contract/api.d.ts +41 -0
- package/dist/src/contract/api.js +35 -0
- package/dist/src/contract/api.js.map +1 -0
- package/dist/src/contract/errors.d.ts +21 -0
- package/dist/src/contract/errors.js +25 -0
- package/dist/src/contract/errors.js.map +1 -0
- package/dist/src/contract/generated/agent.d.ts +31 -0
- package/dist/src/contract/generated/agent.js +3 -0
- package/dist/src/contract/generated/agent.js.map +1 -0
- package/dist/src/contract/generated/allowlist.d.ts +10 -0
- package/dist/src/contract/generated/allowlist.js +3 -0
- package/dist/src/contract/generated/allowlist.js.map +1 -0
- package/dist/src/contract/generated/capabilities.d.ts +46 -0
- package/dist/src/contract/generated/capabilities.js +3 -0
- package/dist/src/contract/generated/capabilities.js.map +1 -0
- package/dist/src/contract/generated/common.d.ts +40 -0
- package/dist/src/contract/generated/common.js +3 -0
- package/dist/src/contract/generated/common.js.map +1 -0
- package/dist/src/contract/generated/control-action.d.ts +73 -0
- package/dist/src/contract/generated/control-action.js +3 -0
- package/dist/src/contract/generated/control-action.js.map +1 -0
- package/dist/src/contract/generated/error.d.ts +25 -0
- package/dist/src/contract/generated/error.js +3 -0
- package/dist/src/contract/generated/error.js.map +1 -0
- package/dist/src/contract/generated/event.d.ts +80 -0
- package/dist/src/contract/generated/event.js +3 -0
- package/dist/src/contract/generated/event.js.map +1 -0
- package/dist/src/contract/generated/index.d.ts +81 -0
- package/dist/src/contract/generated/index.js +3 -0
- package/dist/src/contract/generated/index.js.map +1 -0
- package/dist/src/contract/generated/run.d.ts +63 -0
- package/dist/src/contract/generated/run.js +3 -0
- package/dist/src/contract/generated/run.js.map +1 -0
- package/dist/src/contract/generated/session.d.ts +12 -0
- package/dist/src/contract/generated/session.js +3 -0
- package/dist/src/contract/generated/session.js.map +1 -0
- package/dist/src/contract/generated/version.d.ts +9 -0
- package/dist/src/contract/generated/version.js +3 -0
- package/dist/src/contract/generated/version.js.map +1 -0
- package/dist/src/contract/ids.d.ts +36 -0
- package/dist/src/contract/ids.js +85 -0
- package/dist/src/contract/ids.js.map +1 -0
- package/dist/src/contract/index.d.ts +17 -0
- package/dist/src/contract/index.js +13 -0
- package/dist/src/contract/index.js.map +1 -0
- package/dist/src/contract/run-state.d.ts +13 -0
- package/dist/src/contract/run-state.js +24 -0
- package/dist/src/contract/run-state.js.map +1 -0
- package/dist/src/contract/schemas.d.ts +18 -0
- package/dist/src/contract/schemas.js +37 -0
- package/dist/src/contract/schemas.js.map +1 -0
- package/dist/src/contract/validate.d.ts +17 -0
- package/dist/src/contract/validate.js +68 -0
- package/dist/src/contract/validate.js.map +1 -0
- package/dist/src/daemon/allowlist.d.ts +23 -0
- package/dist/src/daemon/allowlist.js +57 -0
- package/dist/src/daemon/allowlist.js.map +1 -0
- package/dist/src/daemon/daemon.d.ts +31 -0
- package/dist/src/daemon/daemon.js +141 -0
- package/dist/src/daemon/daemon.js.map +1 -0
- package/dist/src/daemon/errors.d.ts +14 -0
- package/dist/src/daemon/errors.js +26 -0
- package/dist/src/daemon/errors.js.map +1 -0
- package/dist/src/daemon/harness-catalog.d.ts +11 -0
- package/dist/src/daemon/harness-catalog.js +21 -0
- package/dist/src/daemon/harness-catalog.js.map +1 -0
- package/dist/src/daemon/http.d.ts +15 -0
- package/dist/src/daemon/http.js +76 -0
- package/dist/src/daemon/http.js.map +1 -0
- package/dist/src/daemon/lock.d.ts +47 -0
- package/dist/src/daemon/lock.js +167 -0
- package/dist/src/daemon/lock.js.map +1 -0
- package/dist/src/daemon/main.d.ts +32 -0
- package/dist/src/daemon/main.js +204 -0
- package/dist/src/daemon/main.js.map +1 -0
- package/dist/src/daemon/paths.d.ts +29 -0
- package/dist/src/daemon/paths.js +26 -0
- package/dist/src/daemon/paths.js.map +1 -0
- package/dist/src/daemon/ports.d.ts +58 -0
- package/dist/src/daemon/ports.js +2 -0
- package/dist/src/daemon/ports.js.map +1 -0
- package/dist/src/daemon/routes.d.ts +15 -0
- package/dist/src/daemon/routes.js +259 -0
- package/dist/src/daemon/routes.js.map +1 -0
- package/dist/src/daemon/sse.d.ts +8 -0
- package/dist/src/daemon/sse.js +56 -0
- package/dist/src/daemon/sse.js.map +1 -0
- package/dist/src/harness/availability.d.ts +9 -0
- package/dist/src/harness/availability.js +52 -0
- package/dist/src/harness/availability.js.map +1 -0
- package/dist/src/harness/claude-code/agent.d.ts +4 -0
- package/dist/src/harness/claude-code/agent.js +33 -0
- package/dist/src/harness/claude-code/agent.js.map +1 -0
- package/dist/src/harness/claude-code/backend.d.ts +48 -0
- package/dist/src/harness/claude-code/backend.js +83 -0
- package/dist/src/harness/claude-code/backend.js.map +1 -0
- package/dist/src/harness/claude-code/capabilities.d.ts +7 -0
- package/dist/src/harness/claude-code/capabilities.js +11 -0
- package/dist/src/harness/claude-code/capabilities.js.map +1 -0
- package/dist/src/harness/claude-code/index.d.ts +15 -0
- package/dist/src/harness/claude-code/index.js +20 -0
- package/dist/src/harness/claude-code/index.js.map +1 -0
- package/dist/src/harness/claude-code/map.d.ts +30 -0
- package/dist/src/harness/claude-code/map.js +108 -0
- package/dist/src/harness/claude-code/map.js.map +1 -0
- package/dist/src/harness/common/capabilities.d.ts +34 -0
- package/dist/src/harness/common/capabilities.js +60 -0
- package/dist/src/harness/common/capabilities.js.map +1 -0
- package/dist/src/harness/common/guard.d.ts +18 -0
- package/dist/src/harness/common/guard.js +31 -0
- package/dist/src/harness/common/guard.js.map +1 -0
- package/dist/src/harness/common/processes.d.ts +21 -0
- package/dist/src/harness/common/processes.js +46 -0
- package/dist/src/harness/common/processes.js.map +1 -0
- package/dist/src/harness/common/queue.d.ts +20 -0
- package/dist/src/harness/common/queue.js +76 -0
- package/dist/src/harness/common/queue.js.map +1 -0
- package/dist/src/harness/common/run-driver.d.ts +88 -0
- package/dist/src/harness/common/run-driver.js +317 -0
- package/dist/src/harness/common/run-driver.js.map +1 -0
- package/dist/src/harness/common/sandbox-workspace.d.ts +72 -0
- package/dist/src/harness/common/sandbox-workspace.js +155 -0
- package/dist/src/harness/common/sandbox-workspace.js.map +1 -0
- package/dist/src/harness/common/text.d.ts +9 -0
- package/dist/src/harness/common/text.js +49 -0
- package/dist/src/harness/common/text.js.map +1 -0
- package/dist/src/harness/common/types.d.ts +111 -0
- package/dist/src/harness/common/types.js +2 -0
- package/dist/src/harness/common/types.js.map +1 -0
- package/dist/src/harness/config.d.ts +43 -0
- package/dist/src/harness/config.js +200 -0
- package/dist/src/harness/config.js.map +1 -0
- package/dist/src/harness/index.d.ts +21 -0
- package/dist/src/harness/index.js +89 -0
- package/dist/src/harness/index.js.map +1 -0
- package/dist/src/harness/opencode/backend.d.ts +37 -0
- package/dist/src/harness/opencode/backend.js +114 -0
- package/dist/src/harness/opencode/backend.js.map +1 -0
- package/dist/src/harness/opencode/capabilities.d.ts +8 -0
- package/dist/src/harness/opencode/capabilities.js +11 -0
- package/dist/src/harness/opencode/capabilities.js.map +1 -0
- package/dist/src/harness/opencode/client.d.ts +70 -0
- package/dist/src/harness/opencode/client.js +189 -0
- package/dist/src/harness/opencode/client.js.map +1 -0
- package/dist/src/harness/opencode/index.d.ts +13 -0
- package/dist/src/harness/opencode/index.js +19 -0
- package/dist/src/harness/opencode/index.js.map +1 -0
- package/dist/src/harness/opencode/lines.d.ts +14 -0
- package/dist/src/harness/opencode/lines.js +99 -0
- package/dist/src/harness/opencode/lines.js.map +1 -0
- package/dist/src/harness/opencode/map.d.ts +13 -0
- package/dist/src/harness/opencode/map.js +84 -0
- package/dist/src/harness/opencode/map.js.map +1 -0
- package/dist/src/harness/opencode/turn.d.ts +23 -0
- package/dist/src/harness/opencode/turn.js +143 -0
- package/dist/src/harness/opencode/turn.js.map +1 -0
- package/dist/src/harness/reclaim.d.ts +13 -0
- package/dist/src/harness/reclaim.js +18 -0
- package/dist/src/harness/reclaim.js.map +1 -0
- package/dist/src/harness/stub/backend.d.ts +11 -0
- package/dist/src/harness/stub/backend.js +125 -0
- package/dist/src/harness/stub/backend.js.map +1 -0
- package/dist/src/harness/stub/index.d.ts +18 -0
- package/dist/src/harness/stub/index.js +21 -0
- package/dist/src/harness/stub/index.js.map +1 -0
- package/dist/src/harness/stub/workspace.d.ts +29 -0
- package/dist/src/harness/stub/workspace.js +92 -0
- package/dist/src/harness/stub/workspace.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/runs/agents.d.ts +10 -0
- package/dist/src/runs/agents.js +49 -0
- package/dist/src/runs/agents.js.map +1 -0
- package/dist/src/runs/control.d.ts +31 -0
- package/dist/src/runs/control.js +105 -0
- package/dist/src/runs/control.js.map +1 -0
- package/dist/src/runs/index.d.ts +8 -0
- package/dist/src/runs/index.js +7 -0
- package/dist/src/runs/index.js.map +1 -0
- package/dist/src/runs/ports.d.ts +31 -0
- package/dist/src/runs/ports.js +5 -0
- package/dist/src/runs/ports.js.map +1 -0
- package/dist/src/runs/scan.d.ts +38 -0
- package/dist/src/runs/scan.js +149 -0
- package/dist/src/runs/scan.js.map +1 -0
- package/dist/src/runs/service.d.ts +70 -0
- package/dist/src/runs/service.js +239 -0
- package/dist/src/runs/service.js.map +1 -0
- package/dist/src/sandbox/harness-session.d.ts +11 -0
- package/dist/src/sandbox/harness-session.js +170 -0
- package/dist/src/sandbox/harness-session.js.map +1 -0
- package/dist/src/sandbox/host-command.d.ts +19 -0
- package/dist/src/sandbox/host-command.js +41 -0
- package/dist/src/sandbox/host-command.js.map +1 -0
- package/dist/src/sandbox/index.d.ts +11 -0
- package/dist/src/sandbox/index.js +15 -0
- package/dist/src/sandbox/index.js.map +1 -0
- package/dist/src/sandbox/naming.d.ts +49 -0
- package/dist/src/sandbox/naming.js +106 -0
- package/dist/src/sandbox/naming.js.map +1 -0
- package/dist/src/sandbox/openshell-client.d.ts +81 -0
- package/dist/src/sandbox/openshell-client.js +49 -0
- package/dist/src/sandbox/openshell-client.js.map +1 -0
- package/dist/src/sandbox/policy.d.ts +26 -0
- package/dist/src/sandbox/policy.js +100 -0
- package/dist/src/sandbox/policy.js.map +1 -0
- package/dist/src/sandbox/run-sandbox.d.ts +38 -0
- package/dist/src/sandbox/run-sandbox.js +247 -0
- package/dist/src/sandbox/run-sandbox.js.map +1 -0
- package/dist/src/sandbox/run-sandboxes.d.ts +18 -0
- package/dist/src/sandbox/run-sandboxes.js +225 -0
- package/dist/src/sandbox/run-sandboxes.js.map +1 -0
- package/dist/src/sandbox/timeout.d.ts +12 -0
- package/dist/src/sandbox/timeout.js +39 -0
- package/dist/src/sandbox/timeout.js.map +1 -0
- package/dist/src/sandbox/types.d.ts +125 -0
- package/dist/src/sandbox/types.js +15 -0
- package/dist/src/sandbox/types.js.map +1 -0
- package/dist/src/sandbox/worktree.d.ts +72 -0
- package/dist/src/sandbox/worktree.js +157 -0
- package/dist/src/sandbox/worktree.js.map +1 -0
- package/dist/src/store/derive.d.ts +39 -0
- package/dist/src/store/derive.js +68 -0
- package/dist/src/store/derive.js.map +1 -0
- package/dist/src/store/event-log.d.ts +79 -0
- package/dist/src/store/event-log.js +202 -0
- package/dist/src/store/event-log.js.map +1 -0
- package/dist/src/store/files.d.ts +51 -0
- package/dist/src/store/files.js +103 -0
- package/dist/src/store/files.js.map +1 -0
- package/dist/src/store/index.d.ts +15 -0
- package/dist/src/store/index.js +11 -0
- package/dist/src/store/index.js.map +1 -0
- package/dist/src/store/liveness.d.ts +61 -0
- package/dist/src/store/liveness.js +150 -0
- package/dist/src/store/liveness.js.map +1 -0
- package/dist/src/store/run-store.d.ts +67 -0
- package/dist/src/store/run-store.js +211 -0
- package/dist/src/store/run-store.js.map +1 -0
- package/dist/src/util/sequence.d.ts +58 -0
- package/dist/src/util/sequence.js +119 -0
- package/dist/src/util/sequence.js.map +1 -0
- package/dist/src/worker/control.d.ts +60 -0
- package/dist/src/worker/control.js +205 -0
- package/dist/src/worker/control.js.map +1 -0
- package/dist/src/worker/delivery.d.ts +17 -0
- package/dist/src/worker/delivery.js +43 -0
- package/dist/src/worker/delivery.js.map +1 -0
- package/dist/src/worker/driver.d.ts +88 -0
- package/dist/src/worker/driver.js +6 -0
- package/dist/src/worker/driver.js.map +1 -0
- package/dist/src/worker/fake-driver.d.ts +65 -0
- package/dist/src/worker/fake-driver.js +123 -0
- package/dist/src/worker/fake-driver.js.map +1 -0
- package/dist/src/worker/index.d.ts +15 -0
- package/dist/src/worker/index.js +11 -0
- package/dist/src/worker/index.js.map +1 -0
- package/dist/src/worker/main.d.ts +1 -0
- package/dist/src/worker/main.js +57 -0
- package/dist/src/worker/main.js.map +1 -0
- package/dist/src/worker/retained.d.ts +13 -0
- package/dist/src/worker/retained.js +40 -0
- package/dist/src/worker/retained.js.map +1 -0
- package/dist/src/worker/run-loop.d.ts +63 -0
- package/dist/src/worker/run-loop.js +325 -0
- package/dist/src/worker/run-loop.js.map +1 -0
- package/dist/src/worker/spawn.d.ts +68 -0
- package/dist/src/worker/spawn.js +201 -0
- package/dist/src/worker/spawn.js.map +1 -0
- package/image/Dockerfile +81 -0
- package/image/build.sh +62 -0
- package/image/pnpm-shim.sh +25 -0
- package/package.json +54 -4
- package/policy/profiles/culture-agents-claude-subscription.yaml +59 -0
- package/policy/profiles/culture-agents-local-gateway.yaml +49 -0
- package/policy/run-sandbox.policy.json +10 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code driver module. The worker loads it by path and calls `createDriver`; the options
|
|
3
|
+
* are `ClaudeCodeDriverOptions`, written by the registry into the run's `driver.json`.
|
|
4
|
+
*/
|
|
5
|
+
import type { Driver, DriverContext } from "../../worker/driver.js";
|
|
6
|
+
import { type SandboxSettings } from "../common/sandbox-workspace.js";
|
|
7
|
+
import type { ClaudeModel } from "../config.js";
|
|
8
|
+
export interface ClaudeCodeDriverOptions {
|
|
9
|
+
sandbox: SandboxSettings;
|
|
10
|
+
model: ClaudeModel;
|
|
11
|
+
stopSettleMs?: number;
|
|
12
|
+
/** Live-test recording: a file that receives every raw stream part. */
|
|
13
|
+
tap?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function createDriver(context: DriverContext): Driver;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { capabilityDocument } from "../common/capabilities.js";
|
|
2
|
+
import { guardDriver } from "../common/guard.js";
|
|
3
|
+
import { RunDriver } from "../common/run-driver.js";
|
|
4
|
+
import { SandboxWorkspaceFactory } from "../common/sandbox-workspace.js";
|
|
5
|
+
import { realAgentFactory } from "./agent.js";
|
|
6
|
+
import { ClaudeCodeBackend } from "./backend.js";
|
|
7
|
+
import { claudeCodeCore, CLAUDE_CODE_TRANSPORT } from "./capabilities.js";
|
|
8
|
+
export function createDriver(context) {
|
|
9
|
+
const options = context.options;
|
|
10
|
+
const run = context.run;
|
|
11
|
+
const driver = new RunDriver(new SandboxWorkspaceFactory(run.id, run.repo, options.sandbox), new ClaudeCodeBackend(run.id, options.model, realAgentFactory, options.tap), {
|
|
12
|
+
task: run.task,
|
|
13
|
+
commitMessage: `run ${run.id}: changes by claude-code`,
|
|
14
|
+
...(options.stopSettleMs === undefined ? {} : { stopSettleMs: options.stopSettleMs }),
|
|
15
|
+
...(options.sandbox.retainFailedSandboxDays === undefined ? {} : { retainFailedDays: options.sandbox.retainFailedSandboxDays }),
|
|
16
|
+
});
|
|
17
|
+
const doc = capabilityDocument({ harness: "claude-code", available: true, version: null, transport: CLAUDE_CODE_TRANSPORT, core: claudeCodeCore() });
|
|
18
|
+
return guardDriver(driver, doc);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/harness/claude-code/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAwB,MAAM,gCAAgC,CAAC;AAE/F,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAU1E,MAAM,UAAU,YAAY,CAAC,OAAsB;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAkC,CAAC;IAC3D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACxB,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B,IAAI,uBAAuB,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,EAC9D,IAAI,iBAAiB,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,EAC3E;QACE,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,aAAa,EAAE,OAAO,GAAG,CAAC,EAAE,0BAA0B;QACtD,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;QACrF,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,uBAAuB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC;KAChI,CACF,CAAC;IACF,MAAM,GAAG,GAAG,kBAAkB,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,qBAAqB,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC;IACrJ,OAAO,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { TurnEvent, TurnOutcome } from "../common/types.js";
|
|
2
|
+
/** The fields of a stream part this mapper reads. */
|
|
3
|
+
export interface StreamPart {
|
|
4
|
+
type: string;
|
|
5
|
+
text?: unknown;
|
|
6
|
+
toolName?: unknown;
|
|
7
|
+
input?: unknown;
|
|
8
|
+
output?: unknown;
|
|
9
|
+
error?: unknown;
|
|
10
|
+
finishReason?: unknown;
|
|
11
|
+
stepNumber?: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Finish reasons that mean the turn ended normally. The harness layer's unified set is `stop`,
|
|
15
|
+
* `length`, `content-filter`, `tool-calls`, `error`, `interrupted`, `other`
|
|
16
|
+
* (`harnessV1FinishReasonSchema` in @ai-sdk/harness 1.0.192). The Claude Code adapter (1.0.196)
|
|
17
|
+
* ends every turn that did not raise a terminal error with `stop`, including a turn whose last
|
|
18
|
+
* steps ran tools; it uses `tool-calls` only on a `finish-step` that waits for host input, never
|
|
19
|
+
* on the turn's `finish`. So `stop` is the whole set, and every other reason is an unfinished turn.
|
|
20
|
+
*/
|
|
21
|
+
export declare const COMPLETED_FINISH_REASONS: ReadonlySet<string>;
|
|
22
|
+
export declare class ClaudePartMapper {
|
|
23
|
+
private currentText;
|
|
24
|
+
private lastText;
|
|
25
|
+
private finishReason;
|
|
26
|
+
private aborted;
|
|
27
|
+
private readonly errors;
|
|
28
|
+
map(part: StreamPart): TurnEvent[];
|
|
29
|
+
outcome(): TurnOutcome;
|
|
30
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map AI SDK stream parts (as the Claude Code adapter emits them through `HarnessAgent.stream`)
|
|
3
|
+
* to normalized turn events, and decide the turn's outcome from the parts seen. Parts are read
|
|
4
|
+
* structurally, so no AI SDK type crosses into the rest of core.
|
|
5
|
+
*/
|
|
6
|
+
import { label, stringify } from "../common/text.js";
|
|
7
|
+
/**
|
|
8
|
+
* Finish reasons that mean the turn ended normally. The harness layer's unified set is `stop`,
|
|
9
|
+
* `length`, `content-filter`, `tool-calls`, `error`, `interrupted`, `other`
|
|
10
|
+
* (`harnessV1FinishReasonSchema` in @ai-sdk/harness 1.0.192). The Claude Code adapter (1.0.196)
|
|
11
|
+
* ends every turn that did not raise a terminal error with `stop`, including a turn whose last
|
|
12
|
+
* steps ran tools; it uses `tool-calls` only on a `finish-step` that waits for host input, never
|
|
13
|
+
* on the turn's `finish`. So `stop` is the whole set, and every other reason is an unfinished turn.
|
|
14
|
+
*/
|
|
15
|
+
export const COMPLETED_FINISH_REASONS = new Set(["stop"]);
|
|
16
|
+
const UNFINISHED = {
|
|
17
|
+
length: "the model's output limit cut the turn off",
|
|
18
|
+
"content-filter": "a content filter stopped the turn",
|
|
19
|
+
"tool-calls": "the turn ended waiting on tool calls that did not run",
|
|
20
|
+
interrupted: "the model stream ended without a completion signal",
|
|
21
|
+
};
|
|
22
|
+
/** The finish reason as a string, from the flattened form or the harness layer's `{ unified }`. */
|
|
23
|
+
function finishReasonOf(value) {
|
|
24
|
+
if (typeof value === "string" && value !== "")
|
|
25
|
+
return value.slice(0, 100);
|
|
26
|
+
const unified = value !== null && typeof value === "object" ? value.unified : undefined;
|
|
27
|
+
return typeof unified === "string" && unified !== "" ? unified.slice(0, 100) : "unknown";
|
|
28
|
+
}
|
|
29
|
+
/** The step number as text; `?` when the part carries none. */
|
|
30
|
+
const stepLabel = (step) => (step === undefined || step === null ? "?" : label(step));
|
|
31
|
+
/** Why a turn that did not complete ended, from its finish reason. */
|
|
32
|
+
function unfinishedReason(finishReason) {
|
|
33
|
+
if (finishReason === null)
|
|
34
|
+
return "the stream ended without a finish part";
|
|
35
|
+
const meaning = UNFINISHED[finishReason];
|
|
36
|
+
return meaning ? `finish reason ${finishReason} (${meaning})` : `finish reason ${finishReason}`;
|
|
37
|
+
}
|
|
38
|
+
const toolName = (part) => (typeof part.toolName === "string" && part.toolName !== "" ? part.toolName.slice(0, 200) : undefined);
|
|
39
|
+
export class ClaudePartMapper {
|
|
40
|
+
currentText = "";
|
|
41
|
+
lastText = "";
|
|
42
|
+
finishReason = null;
|
|
43
|
+
aborted = false;
|
|
44
|
+
errors = [];
|
|
45
|
+
map(part) {
|
|
46
|
+
switch (part.type) {
|
|
47
|
+
case "text-start":
|
|
48
|
+
this.currentText = "";
|
|
49
|
+
return [];
|
|
50
|
+
case "text-delta": {
|
|
51
|
+
const text = typeof part.text === "string" ? part.text : "";
|
|
52
|
+
this.currentText += text;
|
|
53
|
+
this.lastText = this.currentText;
|
|
54
|
+
return text ? [{ type: "output", data: { channel: "text", text } }] : [];
|
|
55
|
+
}
|
|
56
|
+
case "reasoning-delta": {
|
|
57
|
+
const text = typeof part.text === "string" ? part.text : "";
|
|
58
|
+
return text ? [{ type: "output", data: { channel: "reasoning", text } }] : [];
|
|
59
|
+
}
|
|
60
|
+
case "tool-call":
|
|
61
|
+
return [{ type: "output", data: withTool({ channel: "tool_call", text: stringify(part.input ?? {}) }, toolName(part)) }];
|
|
62
|
+
case "tool-result":
|
|
63
|
+
return [{ type: "output", data: withTool({ channel: "tool_result", text: stringify(part.output ?? "") }, toolName(part)) }];
|
|
64
|
+
case "tool-error":
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
type: "output",
|
|
68
|
+
data: withTool({ channel: "tool_result", text: `error: ${stringify(part.error)}`, extension: { error: true } }, toolName(part)),
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
case "tool-approval-request":
|
|
72
|
+
return [error("The harness asked for a tool approval; operator questions are not supported in D1.")];
|
|
73
|
+
case "steering-message":
|
|
74
|
+
return [{ type: "output", data: { channel: "diagnostic", text: `steer delivered to the harness (step ${stepLabel(part.stepNumber)})` } }];
|
|
75
|
+
case "error": {
|
|
76
|
+
const message = stringify(part.error, 1000);
|
|
77
|
+
this.errors.push(message);
|
|
78
|
+
return [error(`harness error: ${message}`)];
|
|
79
|
+
}
|
|
80
|
+
case "abort":
|
|
81
|
+
this.aborted = true;
|
|
82
|
+
return [];
|
|
83
|
+
case "finish":
|
|
84
|
+
this.finishReason = finishReasonOf(part.finishReason);
|
|
85
|
+
return [];
|
|
86
|
+
default:
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
outcome() {
|
|
91
|
+
if (this.aborted)
|
|
92
|
+
return { kind: "interrupted" };
|
|
93
|
+
if (this.finishReason !== null && COMPLETED_FINISH_REASONS.has(this.finishReason)) {
|
|
94
|
+
return this.lastText ? { kind: "completed", summary: this.lastText } : { kind: "completed" };
|
|
95
|
+
}
|
|
96
|
+
// A turn that did not finish normally is not committed or collected as a success.
|
|
97
|
+
const reason = unfinishedReason(this.finishReason);
|
|
98
|
+
const why = this.errors.length > 0 ? `${reason}; ${this.errors.join("; ")}` : reason;
|
|
99
|
+
return { kind: "failed", error: { code: "internal", message: `The Claude Code turn failed: ${why}`.slice(0, 2000), retryable: false } };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function withTool(data, tool) {
|
|
103
|
+
return tool === undefined ? data : { ...data, tool };
|
|
104
|
+
}
|
|
105
|
+
function error(message) {
|
|
106
|
+
return { type: "error", error: { code: "internal", message, retryable: false } };
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=map.js.map
|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AK,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;QACrF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,gCAAgC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC;IAC1I,CAAC;CACF;AAID,SAAS,QAAQ,CAAC,IAAgB,EAAE,IAAwB;IAC1D,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,KAAK,CAAC,OAAe;IAC5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability documents and honest refusal. Every harness reports the deferred capabilities as
|
|
3
|
+
* unsupported (contract README, "Deferred capabilities"), even where the harness itself could do
|
|
4
|
+
* them. A control action outside the document is refused with a typed `unsupported` error naming
|
|
5
|
+
* the capability, and never forwarded to the harness.
|
|
6
|
+
*/
|
|
7
|
+
import type { Capabilities, Capability, CapabilityName, CapabilitySet, ErrorBody } from "../../contract/index.js";
|
|
8
|
+
/** The deferred block, identical for every harness in this API version. */
|
|
9
|
+
export declare function deferredCapabilities(): Pick<CapabilitySet, "pause" | "resume" | "answer" | "continue_session" | "delegate" | "placement" | "reconnect" | "worktree_isolation">;
|
|
10
|
+
export declare const supported: (...caveats: string[]) => Capability;
|
|
11
|
+
export declare const unsupported: (reason: string) => Capability;
|
|
12
|
+
export interface CapabilityInput {
|
|
13
|
+
harness: string;
|
|
14
|
+
available: boolean;
|
|
15
|
+
version: string | null;
|
|
16
|
+
transport: string;
|
|
17
|
+
core: Pick<CapabilitySet, "submit" | "stream" | "steer" | "cancel">;
|
|
18
|
+
extension?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export declare function capabilityDocument(input: CapabilityInput): Capabilities;
|
|
21
|
+
/** The control actions that reach a driver, and the deferred ones that never do. */
|
|
22
|
+
export type ControlCapability = Extract<CapabilityName, "steer" | "cancel" | "pause" | "resume" | "answer">;
|
|
23
|
+
/** The `unsupported` error for `capability`, or null when the document supports it. */
|
|
24
|
+
export declare function refusalFor(doc: Capabilities, capability: CapabilityName): ErrorBody | null;
|
|
25
|
+
/** Thrown by a guarded driver for an action outside its capability document. */
|
|
26
|
+
export declare class UnsupportedCapabilityError extends Error {
|
|
27
|
+
readonly body: ErrorBody;
|
|
28
|
+
readonly name = "UnsupportedCapabilityError";
|
|
29
|
+
readonly code: "unsupported";
|
|
30
|
+
constructor(body: ErrorBody);
|
|
31
|
+
get capability(): CapabilityName;
|
|
32
|
+
}
|
|
33
|
+
/** Throw `UnsupportedCapabilityError` unless the document supports `capability`. */
|
|
34
|
+
export declare function assertSupported(doc: Capabilities, capability: CapabilityName): void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const deferred = (reason) => ({ supported: false, reason, caveats: [] });
|
|
2
|
+
/** The deferred block, identical for every harness in this API version. */
|
|
3
|
+
export function deferredCapabilities() {
|
|
4
|
+
return {
|
|
5
|
+
pause: deferred("Pausing a run is deferred beyond D1 for every harness."),
|
|
6
|
+
resume: deferred("Resuming a paused run is deferred beyond D1 for every harness."),
|
|
7
|
+
answer: deferred("Operator questions are deferred beyond D1; runs use allow-all permissions and never ask."),
|
|
8
|
+
continue_session: deferred("Continuing an earlier session is deferred beyond D1; every run starts a new session."),
|
|
9
|
+
delegate: deferred("Agent-to-agent delegation is deferred beyond D1."),
|
|
10
|
+
placement: deferred("D1 runs on a single host; placement on another node is deferred."),
|
|
11
|
+
reconnect: deferred("D1 cannot reattach live control to a worker that survived a core restart."),
|
|
12
|
+
worktree_isolation: deferred("One active run per repository in D1; concurrent runs in one repository are deferred."),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export const supported = (...caveats) => ({ supported: true, reason: null, caveats });
|
|
16
|
+
export const unsupported = (reason) => ({ supported: false, reason, caveats: [] });
|
|
17
|
+
export function capabilityDocument(input) {
|
|
18
|
+
const doc = {
|
|
19
|
+
harness: input.harness,
|
|
20
|
+
available: input.available,
|
|
21
|
+
version: input.version === null ? null : input.version.slice(0, 128),
|
|
22
|
+
transport: input.transport,
|
|
23
|
+
capabilities: { ...input.core, ...deferredCapabilities() },
|
|
24
|
+
};
|
|
25
|
+
if (input.extension)
|
|
26
|
+
doc.extension = input.extension;
|
|
27
|
+
return doc;
|
|
28
|
+
}
|
|
29
|
+
/** The `unsupported` error for `capability`, or null when the document supports it. */
|
|
30
|
+
export function refusalFor(doc, capability) {
|
|
31
|
+
const cap = doc.capabilities[capability];
|
|
32
|
+
if (cap.supported)
|
|
33
|
+
return null;
|
|
34
|
+
return {
|
|
35
|
+
code: "unsupported",
|
|
36
|
+
message: `The ${doc.harness} harness does not support ${capability}: ${cap.reason ?? "not supported"}`.slice(0, 2000),
|
|
37
|
+
retryable: false,
|
|
38
|
+
capability,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Thrown by a guarded driver for an action outside its capability document. */
|
|
42
|
+
export class UnsupportedCapabilityError extends Error {
|
|
43
|
+
body;
|
|
44
|
+
name = "UnsupportedCapabilityError";
|
|
45
|
+
code = "unsupported";
|
|
46
|
+
constructor(body) {
|
|
47
|
+
super(body.message);
|
|
48
|
+
this.body = body;
|
|
49
|
+
}
|
|
50
|
+
get capability() {
|
|
51
|
+
return this.body.capability;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Throw `UnsupportedCapabilityError` unless the document supports `capability`. */
|
|
55
|
+
export function assertSupported(doc, capability) {
|
|
56
|
+
const refusal = refusalFor(doc, capability);
|
|
57
|
+
if (refusal)
|
|
58
|
+
throw new UnsupportedCapabilityError(refusal);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../../src/harness/common/capabilities.ts"],"names":[],"mappings":"AAeA,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAY,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;AAE3F,2EAA2E;AAC3E,MAAM,UAAU,oBAAoB;IAIlC,OAAO;QACL,KAAK,EAAE,QAAQ,CAAC,wDAAwD,CAAC;QACzE,MAAM,EAAE,QAAQ,CAAC,gEAAgE,CAAC;QAClF,MAAM,EAAE,QAAQ,CAAC,0FAA0F,CAAC;QAC5G,gBAAgB,EAAE,QAAQ,CAAC,sFAAsF,CAAC;QAClH,QAAQ,EAAE,QAAQ,CAAC,kDAAkD,CAAC;QACtE,SAAS,EAAE,QAAQ,CAAC,kEAAkE,CAAC;QACvF,SAAS,EAAE,QAAQ,CAAC,2EAA2E,CAAC;QAChG,kBAAkB,EAAE,QAAQ,CAAC,sFAAsF,CAAC;KACrH,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG,OAAiB,EAAc,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAC5G,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAc,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;AAWvG,MAAM,UAAU,kBAAkB,CAAC,KAAsB;IACvD,MAAM,GAAG,GAAiB;QACxB,OAAO,EAAE,KAAK,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GAAiB,EAAE,UAA0B;IAC3E,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAC5C,IAAI,OAAO;QAAE,MAAM,IAAI,0BAA0B,CAAC,OAAO,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A driver wrapper that enforces a capability document: a control action the document does not
|
|
3
|
+
* support is refused with `UnsupportedCapabilityError` (an `unsupported` error naming the
|
|
4
|
+
* capability) and is not forwarded to the wrapped driver. The deferred control actions (pause,
|
|
5
|
+
* resume, answer) have no driver method at all, so they are always refused here.
|
|
6
|
+
*/
|
|
7
|
+
import type { Capabilities } from "../../contract/index.js";
|
|
8
|
+
import type { Driver } from "../../worker/driver.js";
|
|
9
|
+
import { type ControlCapability } from "./capabilities.js";
|
|
10
|
+
export interface GuardedDriver extends Driver {
|
|
11
|
+
/** The document the guard enforces. */
|
|
12
|
+
readonly capabilities: Capabilities;
|
|
13
|
+
/** The wrapped driver (tests read its reports). */
|
|
14
|
+
readonly inner: Driver;
|
|
15
|
+
/** Any control action by name; refused unless supported (steer and cancel forward). */
|
|
16
|
+
control(action: ControlCapability, payload?: string): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare function guardDriver(inner: Driver, doc: Capabilities): GuardedDriver;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { assertSupported } from "./capabilities.js";
|
|
2
|
+
export function guardDriver(inner, doc) {
|
|
3
|
+
const guarded = {
|
|
4
|
+
capabilities: doc,
|
|
5
|
+
inner,
|
|
6
|
+
start() {
|
|
7
|
+
assertSupported(doc, "submit");
|
|
8
|
+
return inner.start();
|
|
9
|
+
},
|
|
10
|
+
async steer(message) {
|
|
11
|
+
assertSupported(doc, "steer");
|
|
12
|
+
await inner.steer(message);
|
|
13
|
+
},
|
|
14
|
+
async cancel(reason) {
|
|
15
|
+
assertSupported(doc, "cancel");
|
|
16
|
+
await inner.cancel(reason);
|
|
17
|
+
},
|
|
18
|
+
dispose: () => inner.dispose(),
|
|
19
|
+
async control(action, payload = "") {
|
|
20
|
+
assertSupported(doc, action);
|
|
21
|
+
if (action === "steer")
|
|
22
|
+
return guarded.steer(payload);
|
|
23
|
+
if (action === "cancel")
|
|
24
|
+
return guarded.cancel(payload);
|
|
25
|
+
// A deferred action the document claims to support cannot happen (the schema forbids it).
|
|
26
|
+
throw new Error(`no driver path for ${action}`);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
return guarded;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../../../src/harness/common/guard.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAW5E,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,GAAiB;IAC1D,MAAM,OAAO,GAAkB;QAC7B,YAAY,EAAE,GAAG;QACjB,KAAK;QACL,KAAK;YACH,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC/B,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,OAAe;YACzB,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAC9B,MAAM,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,MAAc;YACzB,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC/B,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7B,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE;QAC9B,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,EAAE;YAChC,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAC7B,IAAI,MAAM,KAAK,OAAO;gBAAE,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACtD,IAAI,MAAM,KAAK,QAAQ;gBAAE,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACxD,0FAA0F;YAC1F,MAAM,IAAI,KAAK,CAAC,sBAAsB,MAAM,EAAE,CAAC,CAAC;QAClD,CAAC;KACF,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process listing for the after-cancel checks. The script prints its own shell pid on the first
|
|
3
|
+
* line, then `ps`. The check's own processes are told apart from what the harness left behind by
|
|
4
|
+
* that pid alone, never by what a command line looks like: a harness child controls its own
|
|
5
|
+
* argv, so anything matched by text is something it could imitate to stay out of the list.
|
|
6
|
+
*/
|
|
7
|
+
import type { Proc } from "./types.js";
|
|
8
|
+
/** Tag of the first output line, which carries the check's own shell pid. */
|
|
9
|
+
export declare const PS_SELF = "ca-self";
|
|
10
|
+
/** Prints `ca-self <shell pid>`, then `pid ppid stat args` for every process; zombies are filtered by the parser. */
|
|
11
|
+
export declare const PS_SCRIPT = "echo \"ca-self $$\"; ps -eo pid=,ppid=,stat=,args=";
|
|
12
|
+
/**
|
|
13
|
+
* Parse PS_SCRIPT output, dropping zombies and the check's own processes: the shell whose pid
|
|
14
|
+
* the first line reports, its descendants (the `ps`), and its ancestors up to (not including)
|
|
15
|
+
* pid 1 (the exec helpers that started it). Parent links come from the kernel, so no harness
|
|
16
|
+
* process can place itself in that chain. Throws when the first line is not the pid line.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parsePs(stdout: string): Proc[];
|
|
19
|
+
/** Processes in `now` that were not in `baseline` (by pid and command line). */
|
|
20
|
+
export declare function newProcesses(baseline: readonly Proc[], now: readonly Proc[]): Proc[];
|
|
21
|
+
export declare const describeProcs: (procs: readonly Proc[]) => string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Tag of the first output line, which carries the check's own shell pid. */
|
|
2
|
+
export const PS_SELF = "ca-self";
|
|
3
|
+
/** Prints `ca-self <shell pid>`, then `pid ppid stat args` for every process; zombies are filtered by the parser. */
|
|
4
|
+
export const PS_SCRIPT = `echo "${PS_SELF} $$"; ps -eo pid=,ppid=,stat=,args=`;
|
|
5
|
+
/**
|
|
6
|
+
* Parse PS_SCRIPT output, dropping zombies and the check's own processes: the shell whose pid
|
|
7
|
+
* the first line reports, its descendants (the `ps`), and its ancestors up to (not including)
|
|
8
|
+
* pid 1 (the exec helpers that started it). Parent links come from the kernel, so no harness
|
|
9
|
+
* process can place itself in that chain. Throws when the first line is not the pid line.
|
|
10
|
+
*/
|
|
11
|
+
export function parsePs(stdout) {
|
|
12
|
+
const lines = stdout.split("\n");
|
|
13
|
+
const self = new RegExp(String.raw `^${PS_SELF} (\d+)\s*$`).exec(lines[0] ?? "");
|
|
14
|
+
if (!self)
|
|
15
|
+
throw new Error("the process listing did not report its own pid");
|
|
16
|
+
const rows = [];
|
|
17
|
+
for (const line of lines.slice(1)) {
|
|
18
|
+
// The arguments start at a non-space character, so the space before them is matched one way only.
|
|
19
|
+
const m = /^\s*(\d+)\s+(\d+)\s+(\S+)\s+((?:\S.*)?)$/.exec(line);
|
|
20
|
+
if (!m)
|
|
21
|
+
continue;
|
|
22
|
+
rows.push({ pid: Number(m[1]), ppid: Number(m[2]), stat: m[3], args: m[4].trim() });
|
|
23
|
+
}
|
|
24
|
+
const byPid = new Map(rows.map((r) => [r.pid, r]));
|
|
25
|
+
const own = new Set([Number(self[1])]);
|
|
26
|
+
for (let cur = byPid.get(Number(self[1])); cur && cur.ppid > 1 && !own.has(cur.ppid); cur = byPid.get(cur.ppid))
|
|
27
|
+
own.add(cur.ppid);
|
|
28
|
+
const isOwn = (row) => {
|
|
29
|
+
// Walk up from the row; it is the check's when the walk reaches the check's shell.
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
for (let cur = row; cur && !seen.has(cur.pid); cur = byPid.get(cur.ppid)) {
|
|
32
|
+
if (cur.pid === Number(self[1]))
|
|
33
|
+
return true;
|
|
34
|
+
seen.add(cur.pid);
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
return rows.filter((r) => !own.has(r.pid) && !isOwn(r) && !r.stat.startsWith("Z")).map(({ pid, ppid, args }) => ({ pid, ppid, args }));
|
|
39
|
+
}
|
|
40
|
+
/** Processes in `now` that were not in `baseline` (by pid and command line). */
|
|
41
|
+
export function newProcesses(baseline, now) {
|
|
42
|
+
const seen = new Set(baseline.map((p) => `${p.pid}\0${p.args}`));
|
|
43
|
+
return now.filter((p) => !seen.has(`${p.pid}\0${p.args}`));
|
|
44
|
+
}
|
|
45
|
+
export const describeProcs = (procs) => procs.length === 0 ? "none" : procs.map((p) => `${p.pid} ${p.args.slice(0, 120)}`).join("; ");
|
|
46
|
+
//# sourceMappingURL=processes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processes.js","sourceRoot":"","sources":["../../../../src/harness/common/processes.ts"],"names":[],"mappings":"AAQA,6EAA6E;AAC7E,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC;AACjC,qHAAqH;AACrH,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,OAAO,qCAAqC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,MAAc;IACpC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAA,IAAI,OAAO,YAAY,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAChF,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IAC7E,MAAM,IAAI,GAAgC,EAAE,C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AE,CAC9D,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** A single-consumer async queue that ends once; pushes after the end are dropped. */
|
|
2
|
+
export declare class EventQueue<T> {
|
|
3
|
+
private readonly items;
|
|
4
|
+
private readonly waiters;
|
|
5
|
+
private ended;
|
|
6
|
+
private failure;
|
|
7
|
+
push(item: T): void;
|
|
8
|
+
end(error?: unknown): void;
|
|
9
|
+
get isEnded(): boolean;
|
|
10
|
+
private next;
|
|
11
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
12
|
+
}
|
|
13
|
+
/** Resolve after `ms`, or at once when `signal` aborts. Never rejects. */
|
|
14
|
+
export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Wait for `work` with a time limit; resolves `undefined` on timeout, or as soon as `signal`
|
|
17
|
+
* aborts (the work is left to finish).
|
|
18
|
+
*/
|
|
19
|
+
export declare function within<T>(ms: number, work: Promise<T>, signal?: AbortSignal): Promise<T | undefined>;
|
|
20
|
+
export declare const errorMessage: (err: unknown) => string;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** A single-consumer async queue that ends once; pushes after the end are dropped. */
|
|
2
|
+
export class EventQueue {
|
|
3
|
+
items = [];
|
|
4
|
+
waiters = [];
|
|
5
|
+
ended = false;
|
|
6
|
+
failure = undefined;
|
|
7
|
+
push(item) {
|
|
8
|
+
if (this.ended)
|
|
9
|
+
return;
|
|
10
|
+
const waiter = this.waiters.shift();
|
|
11
|
+
if (waiter)
|
|
12
|
+
waiter({ value: item, done: false });
|
|
13
|
+
else
|
|
14
|
+
this.items.push(item);
|
|
15
|
+
}
|
|
16
|
+
end(error) {
|
|
17
|
+
if (this.ended)
|
|
18
|
+
return;
|
|
19
|
+
this.ended = true;
|
|
20
|
+
this.failure = error;
|
|
21
|
+
if (this.items.length === 0)
|
|
22
|
+
for (const w of this.waiters.splice(0))
|
|
23
|
+
w({ value: undefined, done: true });
|
|
24
|
+
}
|
|
25
|
+
get isEnded() {
|
|
26
|
+
return this.ended;
|
|
27
|
+
}
|
|
28
|
+
next() {
|
|
29
|
+
const item = this.items.shift();
|
|
30
|
+
if (item !== undefined)
|
|
31
|
+
return Promise.resolve({ value: item, done: false });
|
|
32
|
+
if (this.ended) {
|
|
33
|
+
if (this.failure !== undefined) {
|
|
34
|
+
const failure = this.failure;
|
|
35
|
+
this.failure = undefined;
|
|
36
|
+
return Promise.reject(toError(failure));
|
|
37
|
+
}
|
|
38
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
39
|
+
}
|
|
40
|
+
return new Promise((resolve) => this.waiters.push(resolve));
|
|
41
|
+
}
|
|
42
|
+
[Symbol.asyncIterator]() {
|
|
43
|
+
return { next: () => this.next() };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Resolve after `ms`, or at once when `signal` aborts. Never rejects. */
|
|
47
|
+
export function sleep(ms, signal) {
|
|
48
|
+
return new Promise((resolve) => {
|
|
49
|
+
if (signal?.aborted)
|
|
50
|
+
return resolve();
|
|
51
|
+
const timer = setTimeout(done, ms);
|
|
52
|
+
function done() {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
signal?.removeEventListener("abort", done);
|
|
55
|
+
resolve();
|
|
56
|
+
}
|
|
57
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Wait for `work` with a time limit; resolves `undefined` on timeout, or as soon as `signal`
|
|
62
|
+
* aborts (the work is left to finish).
|
|
63
|
+
*/
|
|
64
|
+
export async function within(ms, work, signal) {
|
|
65
|
+
const stop = new AbortController();
|
|
66
|
+
const limit = sleep(ms, signal ? AbortSignal.any([signal, stop.signal]) : stop.signal).then(() => undefined);
|
|
67
|
+
try {
|
|
68
|
+
return await Promise.race([work, limit]);
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
stop.abort(); // clears the timer
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const toError = (err) => (err instanceof Error ? err : new Error(String(err)));
|
|
75
|
+
export const errorMessage = (err) => (err instanceof Error ? err.message : String(err));
|
|
76
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../src/harness/common/queue.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,MAAM,OAAO,UAAU;IACJ,KAAK,GAAQ,EAAE,CAAC;IAChB,OAAO,GAAuC,EAAE,CAAC;IAC1D,KAAK,GAAG,KAAK,CAAC;IACd,OAAO,GAAY,SAAS,CAAC;IAErC,IAAI,CAAC,IAAO;QACV,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACpC,IAAI,MAAM;YAAE,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;;YAC5C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,GAAG,CAAC,KAAe;QACjB,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MA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AO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { RETAIN_FAILED_SANDBOX_DAYS, type Driver, type DriverEvent } from "../../worker/driver.js";
|
|
2
|
+
import type { Collected, HarnessBackend, StopReport, Workspace, WorkspaceFactory } from "./types.js";
|
|
3
|
+
export interface RunDriverOptions {
|
|
4
|
+
task: string;
|
|
5
|
+
/** Commit message for changes the harness left uncommitted. */
|
|
6
|
+
commitMessage: string;
|
|
7
|
+
/** How long a stopped turn may take to wind down before the driver stops waiting. Default 15 s. */
|
|
8
|
+
stopSettleMs?: number;
|
|
9
|
+
/** Pause before each process listing after a stop (lets exiting processes go). Default 1.5 s. */
|
|
10
|
+
processSettleMs?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Days the workspace is kept when the turn completed but its work could not be committed or
|
|
13
|
+
* brought to the host. Default RETAIN_FAILED_SANDBOX_DAYS (7); 0 keeps nothing.
|
|
14
|
+
*/
|
|
15
|
+
retainFailedDays?: number;
|
|
16
|
+
/** The clock for the retention's end (tests). */
|
|
17
|
+
now?: () => number;
|
|
18
|
+
}
|
|
19
|
+
export { RETAIN_FAILED_SANDBOX_DAYS };
|
|
20
|
+
export declare class RunDriver<W extends Workspace> implements Driver {
|
|
21
|
+
private readonly factory;
|
|
22
|
+
private readonly backend;
|
|
23
|
+
private readonly options;
|
|
24
|
+
private readonly queue;
|
|
25
|
+
private readonly abort;
|
|
26
|
+
private workspace;
|
|
27
|
+
private session;
|
|
28
|
+
private turn;
|
|
29
|
+
private baseline;
|
|
30
|
+
private begun;
|
|
31
|
+
private turnOver;
|
|
32
|
+
private cancelRequested;
|
|
33
|
+
private disposed;
|
|
34
|
+
private forceStop;
|
|
35
|
+
private readonly forced;
|
|
36
|
+
private destroying;
|
|
37
|
+
/** The workspace is kept for recovery (a retention): nothing in this driver deletes it any more. */
|
|
38
|
+
private kept;
|
|
39
|
+
private stopTimer;
|
|
40
|
+
/** What `run` is doing, for the message of a failure there. */
|
|
41
|
+
private stage;
|
|
42
|
+
/** Set after a cancel: what the process checks saw. */
|
|
43
|
+
stopReport: StopReport | null;
|
|
44
|
+
/** Set after a completed turn: the commits brought to the host, if any. */
|
|
45
|
+
collected: Collected | null;
|
|
46
|
+
constructor(factory: WorkspaceFactory<W>, backend: HarnessBackend<W>, options: RunDriverOptions);
|
|
47
|
+
start(): AsyncIterable<DriverEvent>;
|
|
48
|
+
steer(message: string): Promise<void>;
|
|
49
|
+
cancel(): Promise<void>;
|
|
50
|
+
dispose(): Promise<void>;
|
|
51
|
+
private get stopping();
|
|
52
|
+
private error;
|
|
53
|
+
private onTurnEvent;
|
|
54
|
+
private finish;
|
|
55
|
+
private run;
|
|
56
|
+
/** The error of a turn that ended without completing. */
|
|
57
|
+
private turnFailure;
|
|
58
|
+
/**
|
|
59
|
+
* Commit what the harness left and bring the run's commits to the host. False when the run has
|
|
60
|
+
* ended here instead: stopped, or failed with its work kept in the workspace.
|
|
61
|
+
*/
|
|
62
|
+
private commitAndCollect;
|
|
63
|
+
/** The turn completed and its commits are on the host: report them, delete the workspace, finish. */
|
|
64
|
+
private complete;
|
|
65
|
+
/** `run` threw: stop when a stop was asked for, otherwise release everything and fail naming the stage. */
|
|
66
|
+
private failRun;
|
|
67
|
+
/**
|
|
68
|
+
* The turn completed but its work could not be committed or brought to the host. The workspace
|
|
69
|
+
* then holds the only copy of that work, so where it can be kept it is: the harness is closed
|
|
70
|
+
* and what it left running is killed as usual, the workspace is not destroyed, and the run
|
|
71
|
+
* fails saying where the work is, until when, and how to get it out. A cancelled run and a run
|
|
72
|
+
* whose turn failed never come here.
|
|
73
|
+
*/
|
|
74
|
+
private failAfterTurn;
|
|
75
|
+
/** Close the harness and destroy the workspace, swallowing errors (failure paths). */
|
|
76
|
+
private release;
|
|
77
|
+
private destroyWorkspace;
|
|
78
|
+
/** The new processes, or why they could not be listed (never an empty list standing in for a failure). */
|
|
79
|
+
private listNew;
|
|
80
|
+
/**
|
|
81
|
+
* The new processes once none is left, or what is still there (or the listing failure) after
|
|
82
|
+
* `maxMs`. Polled, so a harness that stops promptly does not hold the run in `cancelling` for
|
|
83
|
+
* the whole wait.
|
|
84
|
+
*/
|
|
85
|
+
private settled;
|
|
86
|
+
/** After a cancel: check processes, close the harness, kill leftovers, destroy, report `stopped`. */
|
|
87
|
+
private stopAll;
|
|
88
|
+
}
|