@stigmer/runner 3.14.0 → 3.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/dist/.build-fingerprint +1 -1
- package/dist/__test-utils__/execution-record-fixture.d.ts +47 -0
- package/dist/__test-utils__/execution-record-fixture.js +68 -0
- package/dist/__test-utils__/execution-record-fixture.js.map +1 -0
- package/dist/__test-utils__/harness-contract/types.d.ts +166 -0
- package/dist/__test-utils__/harness-contract/types.js +49 -0
- package/dist/__test-utils__/harness-contract/types.js.map +1 -0
- package/dist/__test-utils__/hermetic-activity.d.ts +268 -0
- package/dist/__test-utils__/hermetic-activity.js +385 -0
- package/dist/__test-utils__/hermetic-activity.js.map +1 -0
- package/dist/__test-utils__/mock-client.d.ts +13 -0
- package/dist/__test-utils__/mock-client.js +45 -0
- package/dist/__test-utils__/mock-client.js.map +1 -0
- package/dist/__test-utils__/mock-workspace.d.ts +15 -0
- package/dist/__test-utils__/mock-workspace.js +21 -0
- package/dist/__test-utils__/mock-workspace.js.map +1 -0
- package/dist/__test-utils__/model-registry-fixture.d.ts +56 -0
- package/dist/__test-utils__/model-registry-fixture.js +66 -0
- package/dist/__test-utils__/model-registry-fixture.js.map +1 -0
- package/dist/__test-utils__/turn-input-fixture.d.ts +60 -0
- package/dist/__test-utils__/turn-input-fixture.js +118 -0
- package/dist/__test-utils__/turn-input-fixture.js.map +1 -0
- package/dist/activities/execute-cursor/__test-utils__/contract-subject.d.ts +107 -0
- package/dist/activities/execute-cursor/__test-utils__/contract-subject.js +344 -0
- package/dist/activities/execute-cursor/__test-utils__/contract-subject.js.map +1 -0
- package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.d.ts +20 -0
- package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js +58 -0
- package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js.map +1 -1
- package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.js +2 -32
- package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.js.map +1 -1
- package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.d.ts +148 -0
- package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js +257 -0
- package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js.map +1 -0
- package/dist/activities/execute-cursor/__test-utils__/scripted-agent.d.ts +183 -0
- package/dist/activities/execute-cursor/__test-utils__/scripted-agent.js +262 -0
- package/dist/activities/execute-cursor/__test-utils__/scripted-agent.js.map +1 -0
- package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.d.ts +138 -0
- package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.js +191 -0
- package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.js.map +1 -0
- package/dist/activities/execute-cursor/adapter.d.ts +55 -0
- package/dist/activities/execute-cursor/adapter.js +119 -0
- package/dist/activities/execute-cursor/adapter.js.map +1 -0
- package/dist/activities/execute-cursor/approval-state.d.ts +2 -2
- package/dist/activities/execute-cursor/approval-state.js.map +1 -1
- package/dist/activities/execute-cursor/capture-flow.d.ts +15 -30
- package/dist/activities/execute-cursor/capture-flow.js +17 -26
- package/dist/activities/execute-cursor/capture-flow.js.map +1 -1
- package/dist/activities/execute-cursor/cursor-capabilities.d.ts +23 -0
- package/dist/activities/execute-cursor/cursor-capabilities.js +33 -0
- package/dist/activities/execute-cursor/cursor-capabilities.js.map +1 -0
- package/dist/activities/execute-cursor/cursor-mcp-config.d.ts +2 -2
- package/dist/activities/execute-cursor/cursor-mcp-config.js.map +1 -1
- package/dist/activities/execute-cursor/fetch-interceptor.d.ts +15 -25
- package/dist/activities/execute-cursor/fetch-interceptor.js +39 -33
- package/dist/activities/execute-cursor/fetch-interceptor.js.map +1 -1
- package/dist/activities/execute-cursor/http2-interceptor.d.ts +21 -17
- package/dist/activities/execute-cursor/http2-interceptor.js +38 -31
- package/dist/activities/execute-cursor/http2-interceptor.js.map +1 -1
- package/dist/activities/execute-cursor/message-translator.d.ts +28 -19
- package/dist/activities/execute-cursor/message-translator.js +76 -27
- package/dist/activities/execute-cursor/message-translator.js.map +1 -1
- package/dist/activities/execute-cursor/prompt-builder.d.ts +180 -11
- package/dist/activities/execute-cursor/prompt-builder.js +171 -0
- package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
- package/dist/activities/execute-cursor/rejection-capture.d.ts +3 -6
- package/dist/activities/execute-cursor/rejection-capture.js +5 -7
- package/dist/activities/execute-cursor/rejection-capture.js.map +1 -1
- package/dist/activities/execute-cursor/session-lifecycle.d.ts +1 -4
- package/dist/activities/execute-cursor/session-lifecycle.js.map +1 -1
- package/dist/activities/execute-cursor/turn-boundary.d.ts +1 -1
- package/dist/activities/execute-cursor/turn-settle.d.ts +49 -0
- package/dist/activities/execute-cursor/turn-settle.js +507 -0
- package/dist/activities/execute-cursor/turn-settle.js.map +1 -0
- package/dist/activities/execute-cursor/turn-setup.d.ts +173 -0
- package/dist/activities/execute-cursor/turn-setup.js +496 -0
- package/dist/activities/execute-cursor/turn-setup.js.map +1 -0
- package/dist/activities/execute-cursor/turn-stream.d.ts +41 -71
- package/dist/activities/execute-cursor/turn-stream.js +70 -135
- package/dist/activities/execute-cursor/turn-stream.js.map +1 -1
- package/dist/activities/execute-cursor/turn.d.ts +43 -0
- package/dist/activities/execute-cursor/turn.js +222 -0
- package/dist/activities/execute-cursor/turn.js.map +1 -0
- package/dist/activities/execute-cursor/usage-pricing.d.ts +38 -0
- package/dist/activities/execute-cursor/usage-pricing.js +50 -0
- package/dist/activities/execute-cursor/usage-pricing.js.map +1 -0
- package/dist/activities/execute-deep-agent/approval-file-change.d.ts +1 -1
- package/dist/activities/execute-deep-agent/approval-file-change.js +1 -1
- package/dist/activities/execute-deep-agent/environment.js +1 -1
- package/dist/activities/execute-deep-agent/environment.js.map +1 -1
- package/dist/activities/execute-deep-agent/setup.js +3 -2
- package/dist/activities/execute-deep-agent/setup.js.map +1 -1
- package/dist/activities/hydrate-workflow-execution.js +1 -1
- package/dist/activities/hydrate-workflow-execution.js.map +1 -1
- package/dist/config.d.ts +15 -0
- package/dist/config.js.map +1 -1
- package/dist/harness/capabilities.d.ts +87 -0
- package/dist/harness/capabilities.js +37 -0
- package/dist/harness/capabilities.js.map +1 -0
- package/dist/harness/persist-chokepoint.d.ts +74 -0
- package/dist/harness/persist-chokepoint.js +88 -0
- package/dist/harness/persist-chokepoint.js.map +1 -0
- package/dist/harness/registry.d.ts +106 -0
- package/dist/harness/registry.js +168 -0
- package/dist/harness/registry.js.map +1 -0
- package/dist/harness/run-turn.d.ts +53 -0
- package/dist/harness/run-turn.js +528 -0
- package/dist/harness/run-turn.js.map +1 -0
- package/dist/harness/stop-controller.d.ts +50 -0
- package/dist/harness/stop-controller.js +62 -0
- package/dist/harness/stop-controller.js.map +1 -0
- package/dist/harness/terminal-table.d.ts +141 -0
- package/dist/harness/terminal-table.js +239 -0
- package/dist/harness/terminal-table.js.map +1 -0
- package/dist/harness/turn-context.d.ts +523 -0
- package/dist/harness/turn-context.js +739 -0
- package/dist/harness/turn-context.js.map +1 -0
- package/dist/harness/types.d.ts +448 -0
- package/dist/harness/types.js +64 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/harness/usage-accumulator.d.ts +68 -0
- package/dist/harness/usage-accumulator.js +101 -0
- package/dist/harness/usage-accumulator.js.map +1 -0
- package/dist/harness-adapters.d.ts +27 -0
- package/dist/harness-adapters.js +28 -0
- package/dist/harness-adapters.js.map +1 -0
- package/dist/main.js.map +1 -1
- package/dist/runner-manager.js +64 -48
- package/dist/runner-manager.js.map +1 -1
- package/dist/runner.d.ts +5 -4
- package/dist/runner.js +65 -64
- package/dist/runner.js.map +1 -1
- package/dist/shared/approval-policy.d.ts +1 -1
- package/dist/shared/approval-policy.js.map +1 -1
- package/dist/{activities/execute-cursor → shared}/attachment-resolver.d.ts +2 -2
- package/dist/{activities/execute-cursor → shared}/attachment-resolver.js +5 -5
- package/dist/shared/attachment-resolver.js.map +1 -0
- package/dist/{activities/execute-cursor → shared}/blueprint-resolver.d.ts +7 -5
- package/dist/{activities/execute-cursor → shared}/blueprint-resolver.js +3 -63
- package/dist/shared/blueprint-resolver.js.map +1 -0
- package/dist/shared/channel-attachment.d.ts +1 -1
- package/dist/shared/channel-attachment.js.map +1 -1
- package/dist/{activities/execute-cursor → shared}/cost-guard.d.ts +5 -1
- package/dist/{activities/execute-cursor → shared}/cost-guard.js +5 -1
- package/dist/shared/cost-guard.js.map +1 -0
- package/dist/{activities/execute-cursor → shared}/env-resolver.d.ts +1 -1
- package/dist/shared/env-resolver.js.map +1 -0
- package/dist/{activities/execute-cursor → shared}/exact-apply.d.ts +1 -1
- package/dist/{activities/execute-cursor → shared}/exact-apply.js +6 -6
- package/dist/shared/exact-apply.js.map +1 -0
- package/dist/shared/execution-context.d.ts +35 -0
- package/dist/shared/execution-context.js +38 -0
- package/dist/shared/execution-context.js.map +1 -0
- package/dist/{activities/execute-cursor → shared}/extract-structured-output.d.ts +5 -2
- package/dist/{activities/execute-cursor → shared}/extract-structured-output.js +9 -6
- package/dist/shared/extract-structured-output.js.map +1 -0
- package/dist/shared/filereview/capture.d.ts +1 -1
- package/dist/shared/filereview/capture.js +1 -1
- package/dist/shared/heartbeat.d.ts +13 -11
- package/dist/shared/heartbeat.js +14 -29
- package/dist/shared/heartbeat.js.map +1 -1
- package/dist/{activities/execute-cursor → shared}/persist-decision.d.ts +5 -2
- package/dist/{activities/execute-cursor → shared}/persist-decision.js +4 -1
- package/dist/shared/persist-decision.js.map +1 -0
- package/dist/{activities/execute-cursor → shared}/skill-resolver.d.ts +16 -3
- package/dist/{activities/execute-cursor → shared}/skill-resolver.js +12 -4
- package/dist/shared/skill-resolver.js.map +1 -0
- package/dist/shared/subagent-rows.d.ts +21 -0
- package/dist/shared/subagent-rows.js +34 -0
- package/dist/shared/subagent-rows.js.map +1 -0
- package/dist/shared/worker-shutdown.d.ts +43 -16
- package/dist/shared/worker-shutdown.js +28 -13
- package/dist/shared/worker-shutdown.js.map +1 -1
- package/dist/shared/workspace/platform-dir.d.ts +1 -1
- package/dist/shared/workspace/platform-dir.js +1 -1
- package/dist/shared/workspace/session-provision.d.ts +54 -0
- package/dist/{activities/execute-cursor/workspace-provision.js → shared/workspace/session-provision.js} +15 -12
- package/dist/shared/workspace/session-provision.js.map +1 -0
- package/package.json +4 -4
- package/src/__test-utils__/__tests__/harness-contract-self-check.test.ts +325 -0
- package/src/__test-utils__/config-fixture.ts +63 -0
- package/src/__test-utils__/execution-record-fixture.ts +104 -0
- package/src/__test-utils__/harness-boot-order-child.ts +58 -0
- package/src/__test-utils__/harness-contract/contract.ts +581 -0
- package/src/__test-utils__/harness-contract/recording-sink.ts +107 -0
- package/src/__test-utils__/harness-contract/runtime-contract.ts +666 -0
- package/src/__test-utils__/harness-contract/scripted-adapter.ts +349 -0
- package/src/__test-utils__/harness-contract/types.ts +176 -0
- package/src/__test-utils__/hermetic-activity.ts +502 -0
- package/src/__test-utils__/model-registry-fixture.ts +72 -0
- package/src/__test-utils__/module-specifiers.ts +82 -0
- package/src/__test-utils__/proto-helpers.ts +25 -0
- package/src/__test-utils__/turn-input-fixture.ts +155 -0
- package/src/__tests__/harness-boot-order.test.ts +77 -0
- package/src/__tests__/harness-contract.test.ts +27 -0
- package/src/__tests__/runner-manager.test.ts +18 -0
- package/src/activities/execute-cursor/__test-utils__/__tests__/scripted-double.test.ts +102 -0
- package/src/activities/execute-cursor/__test-utils__/contract-subject.ts +396 -0
- package/src/activities/execute-cursor/__test-utils__/cursor-hook-harness.ts +66 -0
- package/src/activities/execute-cursor/__test-utils__/gateway-substrate.ts +2 -43
- package/src/activities/execute-cursor/__test-utils__/hermetic-cursor.ts +342 -0
- package/src/activities/execute-cursor/__test-utils__/scripted-agent.ts +368 -0
- package/src/activities/execute-cursor/__test-utils__/scripted-sdk.ts +254 -0
- package/src/activities/execute-cursor/__tests__/adapter-is-temporal-free.test.ts +45 -0
- package/src/activities/execute-cursor/__tests__/approval-decisions-agree.test.ts +90 -0
- package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +7 -8
- package/src/activities/execute-cursor/__tests__/capture-flow.test.ts +28 -1
- package/src/activities/execute-cursor/__tests__/deny-gate-exact-apply.test.ts +1 -1
- package/src/activities/execute-cursor/__tests__/fetch-interceptor.test.ts +64 -6
- package/src/activities/execute-cursor/__tests__/hermetic/deny-and-retry.test.ts +228 -0
- package/src/activities/execute-cursor/__tests__/hermetic/file-review-capture.test.ts +180 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/cost-cap.status.json +53 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/deny-and-retry.turn1.status.json +55 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/deny-and-retry.turn2.status.json +77 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/file-review-capture.status.json +126 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/pause.status.json +40 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/plain-turn.status.json +48 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/platform-stop.status.json +56 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/recovery-fresh-agent.status.json +53 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/recovery-transport-timeout.status.json +48 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/resolution-error.status.json +18 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-cancelled.status.json +36 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/run-error-non-retryable.status.json +37 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/sdk-error-at-create.status.json +38 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/stall.status.json +59 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/tool-call.status.json +68 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/unattributed-hook-block.status.json +79 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/worker-shutdown.status.json +42 -0
- package/src/activities/execute-cursor/__tests__/hermetic/harness-contract.test.ts +170 -0
- package/src/activities/execute-cursor/__tests__/hermetic/pause-vs-shutdown.test.ts +205 -0
- package/src/activities/execute-cursor/__tests__/hermetic/plain-turn.test.ts +171 -0
- package/src/activities/execute-cursor/__tests__/hermetic/recovery-fresh-agent.test.ts +156 -0
- package/src/activities/execute-cursor/__tests__/hermetic/run-wait-arms.test.ts +286 -0
- package/src/activities/execute-cursor/__tests__/hermetic/stream-self-stop-arms.test.ts +332 -0
- package/src/activities/execute-cursor/__tests__/hermetic/thrown-error-arms.test.ts +193 -0
- package/src/activities/execute-cursor/__tests__/hermetic/tool-call.test.ts +137 -0
- package/src/activities/execute-cursor/__tests__/hermetic/unattributed-hook-block.test.ts +185 -0
- package/src/activities/execute-cursor/__tests__/hermetic/workspace-lock-timeout.test.ts +151 -0
- package/src/activities/execute-cursor/__tests__/http2-interceptor.test.ts +65 -35
- package/src/activities/execute-cursor/__tests__/message-translator.test.ts +0 -40
- package/src/activities/execute-cursor/__tests__/same-identity-reproposal.test.ts +171 -0
- package/src/activities/execute-cursor/__tests__/turn-stream.test.ts +118 -243
- package/src/activities/execute-cursor/__tests__/usage-pricing.test.ts +84 -0
- package/src/activities/execute-cursor/adapter.ts +138 -0
- package/src/activities/execute-cursor/approval-state.ts +2 -2
- package/src/activities/execute-cursor/capture-flow.ts +18 -41
- package/src/activities/execute-cursor/cursor-capabilities.ts +35 -0
- package/src/activities/execute-cursor/cursor-mcp-config.ts +2 -2
- package/src/activities/execute-cursor/fetch-interceptor.ts +48 -45
- package/src/activities/execute-cursor/http2-interceptor.ts +47 -34
- package/src/activities/execute-cursor/message-translator.ts +90 -45
- package/src/activities/execute-cursor/prompt-builder.ts +327 -12
- package/src/activities/execute-cursor/rejection-capture.ts +5 -12
- package/src/activities/execute-cursor/session-lifecycle.ts +1 -5
- package/src/activities/execute-cursor/turn-boundary.ts +1 -1
- package/src/activities/execute-cursor/turn-settle.ts +601 -0
- package/src/activities/execute-cursor/turn-setup.ts +645 -0
- package/src/activities/execute-cursor/turn-stream.ts +84 -210
- package/src/activities/execute-cursor/turn.ts +240 -0
- package/src/activities/execute-cursor/usage-pricing.ts +67 -0
- package/src/activities/execute-deep-agent/approval-file-change.ts +1 -1
- package/src/activities/execute-deep-agent/environment.ts +1 -1
- package/src/activities/execute-deep-agent/setup.ts +3 -2
- package/src/activities/hydrate-workflow-execution.ts +1 -1
- package/src/config.ts +13 -0
- package/src/harness/__tests__/import-direction.test.ts +168 -0
- package/src/harness/__tests__/persist-chokepoint.test.ts +146 -0
- package/src/harness/__tests__/registry.test.ts +168 -0
- package/src/harness/__tests__/run-turn.test.ts +165 -0
- package/src/harness/__tests__/stop-controller.test.ts +49 -0
- package/src/harness/__tests__/turn-context.test.ts +178 -0
- package/src/harness/__tests__/usage-accumulator.test.ts +83 -0
- package/src/harness/capabilities.ts +92 -0
- package/src/harness/persist-chokepoint.ts +112 -0
- package/src/harness/registry.ts +197 -0
- package/src/harness/run-turn.ts +618 -0
- package/src/harness/stop-controller.ts +83 -0
- package/src/harness/terminal-table.ts +276 -0
- package/src/harness/turn-context.ts +1028 -0
- package/src/harness/types.ts +473 -0
- package/src/harness/usage-accumulator.ts +122 -0
- package/src/harness-adapters.ts +30 -0
- package/src/main.ts +1 -1
- package/src/runner-manager.ts +68 -61
- package/src/runner.ts +67 -78
- package/src/shared/__tests__/attachment-naming.test.ts +1 -1
- package/src/{activities/execute-cursor → shared}/__tests__/attachment-resolver.test.ts +6 -4
- package/src/{activities/execute-cursor → shared}/__tests__/cost-guard.test.ts +2 -1
- package/src/{activities/execute-cursor → shared}/__tests__/exact-apply.test.ts +3 -3
- package/src/{activities/execute-cursor → shared}/__tests__/extract-structured-output.test.ts +8 -8
- package/src/{activities/execute-cursor → shared}/__tests__/persist-decision.test.ts +4 -2
- package/src/{activities/execute-cursor → shared}/__tests__/skill-resolver.test.ts +1 -1
- package/src/shared/__tests__/subagent-rows.test.ts +34 -0
- package/src/shared/__tests__/worker-shutdown.test.ts +44 -39
- package/src/shared/approval-policy.ts +1 -1
- package/src/{activities/execute-cursor → shared}/attachment-resolver.ts +6 -6
- package/src/{activities/execute-cursor → shared}/blueprint-resolver.ts +7 -78
- package/src/shared/channel-attachment.ts +1 -1
- package/src/{activities/execute-cursor → shared}/cost-guard.ts +5 -1
- package/src/{activities/execute-cursor → shared}/env-resolver.ts +1 -1
- package/src/{activities/execute-cursor → shared}/exact-apply.ts +7 -7
- package/src/shared/execution-context.ts +45 -0
- package/src/{activities/execute-cursor → shared}/extract-structured-output.ts +10 -7
- package/src/shared/filereview/capture.ts +1 -1
- package/src/shared/heartbeat.ts +13 -33
- package/src/{activities/execute-cursor → shared}/persist-decision.ts +5 -2
- package/src/{activities/execute-cursor → shared}/skill-resolver.ts +20 -6
- package/src/shared/subagent-rows.ts +39 -0
- package/src/shared/worker-shutdown.ts +55 -25
- package/src/{activities/execute-cursor/__tests__/workspace-provision.test.ts → shared/workspace/__tests__/session-provision.test.ts} +25 -28
- package/src/shared/workspace/platform-dir.ts +1 -1
- package/src/{activities/execute-cursor/workspace-provision.ts → shared/workspace/session-provision.ts} +29 -16
- package/dist/activities/execute-cursor/attachment-resolver.js.map +0 -1
- package/dist/activities/execute-cursor/blueprint-resolver.js.map +0 -1
- package/dist/activities/execute-cursor/cost-guard.js.map +0 -1
- package/dist/activities/execute-cursor/env-resolver.js.map +0 -1
- package/dist/activities/execute-cursor/exact-apply.js.map +0 -1
- package/dist/activities/execute-cursor/extract-structured-output.js.map +0 -1
- package/dist/activities/execute-cursor/index.d.ts +0 -209
- package/dist/activities/execute-cursor/index.js +0 -2345
- package/dist/activities/execute-cursor/index.js.map +0 -1
- package/dist/activities/execute-cursor/persist-decision.js.map +0 -1
- package/dist/activities/execute-cursor/skill-resolver.js.map +0 -1
- package/dist/activities/execute-cursor/usage-accumulator.d.ts +0 -89
- package/dist/activities/execute-cursor/usage-accumulator.js +0 -121
- package/dist/activities/execute-cursor/usage-accumulator.js.map +0 -1
- package/dist/activities/execute-cursor/workspace-provision.d.ts +0 -42
- package/dist/activities/execute-cursor/workspace-provision.js.map +0 -1
- package/src/activities/execute-cursor/__tests__/usage-accumulator.test.ts +0 -164
- package/src/activities/execute-cursor/index.ts +0 -2876
- package/src/activities/execute-cursor/usage-accumulator.ts +0 -169
- /package/dist/{activities/execute-cursor → shared}/env-resolver.js +0 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Cursor harness as a `HarnessContractSubject` — the REAL `createCursorAdapter()`
|
|
3
|
+
* driven through the harness contract kit, with the kit's engine-neutral
|
|
4
|
+
* scenario vocabulary translated onto S0's scripted `@cursor/sdk` double.
|
|
5
|
+
*
|
|
6
|
+
* The sibling of `gateway-substrate.ts` (the Cursor side of the approval
|
|
7
|
+
* contract kit): the kit owns the invariants and the runtime stand-in, this
|
|
8
|
+
* module owns the ENGINE — what the next turn of a session's agent will do —
|
|
9
|
+
* and reports what the double observed. The adapter under test is the
|
|
10
|
+
* production one, untouched; it imports no `@temporalio/*` (the fence test
|
|
11
|
+
* pins that), which is what lets the kit run it outside any activity
|
|
12
|
+
* context.
|
|
13
|
+
*
|
|
14
|
+
* ── The engine is per session ───────────────────────────────────────────────
|
|
15
|
+
* One scripted agent per session, minted when the kit first arranges a turn
|
|
16
|
+
* for it and handed out by the double's `Agent.create` for THAT session (keyed
|
|
17
|
+
* by the SDK's `platform.workspaceRef`, computed the way the adapter computes
|
|
18
|
+
* it), then parked by the real session cache across turns exactly as in a live
|
|
19
|
+
* worker. Arranging a turn REPLACES the agent's next script, so a turn the
|
|
20
|
+
* adapter interrupts before its `send()` leaves no stale script for the
|
|
21
|
+
* session's next turn. Every session also gets the workspace directory the
|
|
22
|
+
* runtime's provisioner would give it (`<workspaceRootDir>/sessions/<id>`), so
|
|
23
|
+
* both halves of the kit gate in the same directory shape; the hook's
|
|
24
|
+
* active-turn pointer is per workspace, so concurrent sessions cannot repoint
|
|
25
|
+
* each other's hook.
|
|
26
|
+
*
|
|
27
|
+
* ── The translation, one rule per word ──────────────────────────────────────
|
|
28
|
+
* - `say(text)` → an `assistant` event. A first send opens with the
|
|
29
|
+
* `system/init` event; a resumed send does not (the
|
|
30
|
+
* `deny-and-retry` turn-2 script is the precedent).
|
|
31
|
+
* - `propose(id, a)` → the STREAM tool call (`edit` / `shell` / `delete`, the
|
|
32
|
+
* kits' shared translation in `cursor-hook-harness.ts`),
|
|
33
|
+
* an `effect` that runs the REAL preToolUse hook the
|
|
34
|
+
* adapter installed against the session's workspace,
|
|
35
|
+
* and the call's completion event. `executionCount(id)`
|
|
36
|
+
* is the hook's `allow` answers for `id` — the SDK
|
|
37
|
+
* executes a tool iff the hook allows it, so this is the
|
|
38
|
+
* safety-critical observable. WHETHER the call is
|
|
39
|
+
* emitted is decided from the kit's view and this
|
|
40
|
+
* subject's own memory, as the model and the SDK would
|
|
41
|
+
* decide it (see {@link CursorContractSubject.proposeSteps}).
|
|
42
|
+
* - `read(id, path)` → the `read` tool call, the REAL hook (which allows it —
|
|
43
|
+
* a read is never gated) and the completion; counted as
|
|
44
|
+
* run. The discrete event the adapter's loop flushes a
|
|
45
|
+
* persist on.
|
|
46
|
+
* - `usage(delta)` → a `turn-ended` delta; the adapter prices it.
|
|
47
|
+
* - `hang` → an `effect` parked on the run's own `cancelled`
|
|
48
|
+
* status, which the adapter's stop-signal listener
|
|
49
|
+
* (`turn-stream.ts` `cancelOnStop`) produces. Never a
|
|
50
|
+
* timer. Resolves `whenHanging`.
|
|
51
|
+
* - `fail(msg, s)` → `engine`: the run ends `{ status: "error" }` and
|
|
52
|
+
* `run.wait()` carries the message; `internal`: an
|
|
53
|
+
* `effect` throws mid-stream (the adapter's catch
|
|
54
|
+
* classifies it). `actionable` is refused as a test bug:
|
|
55
|
+
* only the unattributed-hook-block path produces that
|
|
56
|
+
* surface, and the kit's invariants do not ask for it.
|
|
57
|
+
* - `cancelled` → an `effect` calling `run.cancel()` from the SDK side
|
|
58
|
+
* (the `run-cancelled` golden's shape).
|
|
59
|
+
* Every script that does not end in `fail`, `cancelled` or `hang` closes with
|
|
60
|
+
* `finished({ result: <last say> })` so `run.wait()` has an answer.
|
|
61
|
+
*
|
|
62
|
+
* ── Two modelling decisions (S2 M4, Q-M4-4) ─────────────────────────────────
|
|
63
|
+
* A `propose` for an id this subject has already seen the hook ALLOW emits
|
|
64
|
+
* nothing: the real SDK does not re-run a completed tool on resume — the parked
|
|
65
|
+
* agent's conversation already holds the tool's result. A `propose` whose id
|
|
66
|
+
* carries a SKIP or REJECT decision emits nothing either: the resume prompt
|
|
67
|
+
* tells the model the user declined the action and an obedient model moves
|
|
68
|
+
* on. Both are what "the engine re-reaches the same call" and "the turn
|
|
69
|
+
* continues" MEAN for a deny-and-retry harness; neither hides anything from
|
|
70
|
+
* the safety observable, because a fresh identical command from a
|
|
71
|
+
* disobedient model IS a new gated act and Cursor re-gates it — the subject
|
|
72
|
+
* file proves that with {@link CursorContractSubject.forceReissue}.
|
|
73
|
+
*
|
|
74
|
+
* The completion event a `propose` emits is scripted from the answer the hook
|
|
75
|
+
* is EXPECTED to give (deny for an undecided proposal, allow for an approved
|
|
76
|
+
* re-issue); the hook's actual answer is recorded at effect time and any
|
|
77
|
+
* disagreement is kept in {@link CursorContractSubject.hookDisagreements} for
|
|
78
|
+
* the subject file to assert empty — a hook that allows an undecided action
|
|
79
|
+
* would show up there AND in `executionCount`, never be papered over.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
import { mkdirSync } from "node:fs";
|
|
83
|
+
import { join } from "node:path";
|
|
84
|
+
import { ApprovalAction, ServiceTier, ThinkingMode } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
85
|
+
|
|
86
|
+
import type { Config } from "../../../config.js";
|
|
87
|
+
import type { HarnessAdapter } from "../../../harness/types.js";
|
|
88
|
+
import type { ProposedAction } from "../../../__test-utils__/approval-contract/types.js";
|
|
89
|
+
import type {
|
|
90
|
+
EngineView,
|
|
91
|
+
HarnessContractSubject,
|
|
92
|
+
ScenarioStep,
|
|
93
|
+
SubjectInputOverrides,
|
|
94
|
+
TurnScenario,
|
|
95
|
+
} from "../../../__test-utils__/harness-contract/types.js";
|
|
96
|
+
import type { HermeticEnvironment } from "../../../__test-utils__/hermetic-activity.js";
|
|
97
|
+
import { createCursorAdapter } from "../adapter.js";
|
|
98
|
+
import { resolvePlatformOptions } from "../session-lifecycle.js";
|
|
99
|
+
import { hookInputFor, streamArgsFor, STREAM_NAME, type GatedActionKind } from "./cursor-hook-harness.js";
|
|
100
|
+
import { FIXTURE, SDK_CATALOG, hermeticCursorConfig, runWorkspaceHook } from "./hermetic-cursor.js";
|
|
101
|
+
import { ScriptedCursorAgent, sdkEvents, step, type ScriptStep, type ScriptedRun } from "./scripted-agent.js";
|
|
102
|
+
import { ScriptedCursorSdk, bindScriptedSdk } from "./scripted-sdk.js";
|
|
103
|
+
|
|
104
|
+
/** The user's message every kit turn asks; the prompt builder needs one and the kit has none to give. */
|
|
105
|
+
const KIT_USER_MESSAGE = "Do what the scenario says.";
|
|
106
|
+
|
|
107
|
+
/** What the double records the SDK "returning" for an allowed tool call. */
|
|
108
|
+
const ALLOWED_RESULT = "ok (kit)";
|
|
109
|
+
|
|
110
|
+
/** The error the SDK surfaces on a hook-denied call, as the goldens script it. */
|
|
111
|
+
const HOOK_BLOCKED_RESULT = "Blocked by hook";
|
|
112
|
+
|
|
113
|
+
/** What this subject remembers about one proposal id across the turns of an execution. */
|
|
114
|
+
interface ProposalMemory {
|
|
115
|
+
/** How many times the call has been emitted; the first emission uses the kit's id, a re-issue a fresh one. */
|
|
116
|
+
emitted: number;
|
|
117
|
+
/** How many times the hook allowed it — the execution count. */
|
|
118
|
+
allowed: number;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface CursorContractSubject extends HarnessContractSubject {
|
|
122
|
+
readonly adapter: HarnessAdapter;
|
|
123
|
+
/** The SDK double the adapter is talking to, for the subject file's own observations. */
|
|
124
|
+
readonly sdk: ScriptedCursorSdk;
|
|
125
|
+
/** The scripted agent minted for a session, once the kit has arranged a turn for it. */
|
|
126
|
+
agentFor(sessionId: string): ScriptedCursorAgent | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Make the NEXT `propose` of `toolCallId` emit its call whatever the
|
|
129
|
+
* decision or the memory says — the disobedient model, for the observation
|
|
130
|
+
* the kit's vocabulary cannot express.
|
|
131
|
+
*/
|
|
132
|
+
forceReissue(toolCallId: string): void;
|
|
133
|
+
/** Every proposal at which the hook answered other than the script expected; the subject file asserts it stays empty. */
|
|
134
|
+
readonly hookDisagreements: readonly string[];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Build the subject over one hermetic environment (the temp `HOME` the gate's
|
|
139
|
+
* per-session HITL artifacts land under, the temp workspace root). The
|
|
140
|
+
* environment is the caller's to create before and dispose after; the SDK
|
|
141
|
+
* double is bound for the module here, so a file holds one subject.
|
|
142
|
+
*/
|
|
143
|
+
export function createCursorContractSubject(env: HermeticEnvironment): CursorContractSubject {
|
|
144
|
+
return new CursorSubject(env);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
class CursorSubject implements CursorContractSubject {
|
|
148
|
+
readonly name = "cursor";
|
|
149
|
+
readonly harness = "cursor" as const;
|
|
150
|
+
readonly adapter: HarnessAdapter;
|
|
151
|
+
readonly config: Config;
|
|
152
|
+
readonly sdk: ScriptedCursorSdk;
|
|
153
|
+
readonly hookDisagreements: string[] = [];
|
|
154
|
+
|
|
155
|
+
private readonly agents = new Map<string, ScriptedCursorAgent>();
|
|
156
|
+
private readonly agentsByWorkspaceRef = new Map<string, ScriptedCursorAgent>();
|
|
157
|
+
private readonly proposals = new Map<string, ProposalMemory>();
|
|
158
|
+
private readonly forcedReissues = new Set<string>();
|
|
159
|
+
private readonly hangWaiters: Array<() => void> = [];
|
|
160
|
+
private mintCounter = 0;
|
|
161
|
+
|
|
162
|
+
constructor(private readonly env: HermeticEnvironment) {
|
|
163
|
+
this.config = hermeticCursorConfig(env);
|
|
164
|
+
this.adapter = createCursorAdapter();
|
|
165
|
+
this.sdk = new ScriptedCursorSdk({
|
|
166
|
+
agents: [],
|
|
167
|
+
catalog: SDK_CATALOG,
|
|
168
|
+
agentForWorkspaceRef: (ref) => this.agentsByWorkspaceRef.get(ref),
|
|
169
|
+
});
|
|
170
|
+
bindScriptedSdk(this.sdk);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ── HarnessContractSubject ────────────────────────────────────────────────
|
|
174
|
+
|
|
175
|
+
arrange(turn: TurnScenario, view: EngineView): void {
|
|
176
|
+
const agent = this.agents.get(view.sessionId) ?? this.mintAgent(view.sessionId);
|
|
177
|
+
mkdirSync(this.workspaceRootOf(view.sessionId), { recursive: true });
|
|
178
|
+
agent.arrangeNextTurn(this.translate(turn, view, agent));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
inputOverrides(view: EngineView): SubjectInputOverrides {
|
|
182
|
+
return {
|
|
183
|
+
// The adapter validates the name against its catalog and prices against
|
|
184
|
+
// the registry fixture; both know exactly this model.
|
|
185
|
+
model: { requested: FIXTURE.model, serviceTier: ServiceTier.STANDARD, thinkingMode: ThinkingMode.DISABLED },
|
|
186
|
+
workspaceDir: this.workspaceRootOf(view.sessionId),
|
|
187
|
+
message: KIT_USER_MESSAGE,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
whenHanging(): Promise<void> {
|
|
192
|
+
return new Promise((resolve) => this.hangWaiters.push(resolve));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
executionCount(toolCallId: string): number {
|
|
196
|
+
return this.proposals.get(toolCallId)?.allowed ?? 0;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// ── The subject file's observations ──────────────────────────────────────
|
|
200
|
+
|
|
201
|
+
agentFor(sessionId: string): ScriptedCursorAgent | undefined {
|
|
202
|
+
return this.agents.get(sessionId);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
forceReissue(toolCallId: string): void {
|
|
206
|
+
this.forcedReissues.add(toolCallId);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ── The engine ────────────────────────────────────────────────────────────
|
|
210
|
+
|
|
211
|
+
/** The directory the runtime's provisioner gives a session with no workspace entries (`session-root.ts`). */
|
|
212
|
+
private workspaceRootOf(sessionId: string): string {
|
|
213
|
+
return join(this.env.workspaceRootDir, "sessions", sessionId);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private mintAgent(sessionId: string): ScriptedCursorAgent {
|
|
217
|
+
const agent = new ScriptedCursorAgent({ agentId: `agent-kit-${++this.mintCounter}`, turns: [] });
|
|
218
|
+
this.agents.set(sessionId, agent);
|
|
219
|
+
// The adapter asks the SDK to create an agent for the session under this
|
|
220
|
+
// ref; the double answers with this agent.
|
|
221
|
+
const { workspaceRef } = resolvePlatformOptions(sessionId, this.config.workspaceRootDir);
|
|
222
|
+
this.agentsByWorkspaceRef.set(workspaceRef, agent);
|
|
223
|
+
return agent;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private translate(turn: TurnScenario, view: EngineView, agent: ScriptedCursorAgent): ScriptStep[] {
|
|
227
|
+
const ev = sdkEvents(agent.agentId, agent.nextRunId);
|
|
228
|
+
const script: ScriptStep[] = [];
|
|
229
|
+
if (agent.sends.length === 0) script.push(step.event(ev.init()));
|
|
230
|
+
|
|
231
|
+
let lastSay = "";
|
|
232
|
+
let ended = false;
|
|
233
|
+
for (const s of turn) {
|
|
234
|
+
switch (s.kind) {
|
|
235
|
+
case "say":
|
|
236
|
+
script.push(step.event(ev.assistant(s.text)));
|
|
237
|
+
lastSay = s.text;
|
|
238
|
+
break;
|
|
239
|
+
case "propose":
|
|
240
|
+
script.push(...this.proposeSteps(s.toolCallId, s.action, view, ev));
|
|
241
|
+
break;
|
|
242
|
+
case "read":
|
|
243
|
+
script.push(...this.readSteps(s.toolCallId, s.path, view, ev));
|
|
244
|
+
break;
|
|
245
|
+
case "usage":
|
|
246
|
+
script.push(
|
|
247
|
+
step.turnEnded({
|
|
248
|
+
inputTokens: s.delta.inputTokens,
|
|
249
|
+
outputTokens: s.delta.outputTokens,
|
|
250
|
+
cacheReadTokens: s.delta.cacheReadTokens,
|
|
251
|
+
cacheWriteTokens: s.delta.cacheWriteTokens,
|
|
252
|
+
}),
|
|
253
|
+
);
|
|
254
|
+
break;
|
|
255
|
+
case "hang":
|
|
256
|
+
script.push(step.effect("kit: hang until the adapter cancels the run", ({ run }) => this.park(run)));
|
|
257
|
+
ended = true;
|
|
258
|
+
break;
|
|
259
|
+
case "fail":
|
|
260
|
+
switch (s.surface) {
|
|
261
|
+
case "engine":
|
|
262
|
+
script.push(step.errored({ result: s.message }));
|
|
263
|
+
break;
|
|
264
|
+
case "internal":
|
|
265
|
+
script.push(
|
|
266
|
+
step.effect("kit: the transport breaks mid-stream", () => {
|
|
267
|
+
throw new Error(s.message);
|
|
268
|
+
}),
|
|
269
|
+
);
|
|
270
|
+
break;
|
|
271
|
+
case "actionable":
|
|
272
|
+
throw new Error(`${this.name}: fail(..., "actionable") is not producible by this subject (only the unattributed hook block reaches that surface); test bug`);
|
|
273
|
+
default: {
|
|
274
|
+
const exhaustive: never = s.surface;
|
|
275
|
+
throw new Error(`${this.name}: unknown failure surface ${String(exhaustive)}`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
ended = true;
|
|
279
|
+
break;
|
|
280
|
+
case "cancelled":
|
|
281
|
+
script.push(step.effect("kit: the SDK cancels its own run", ({ run }) => run.cancel()));
|
|
282
|
+
ended = true;
|
|
283
|
+
break;
|
|
284
|
+
default: {
|
|
285
|
+
const exhaustive: never = s;
|
|
286
|
+
throw new Error(`${this.name}: unknown scenario step ${JSON.stringify(exhaustive)}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (!ended) script.push(step.finished({ result: lastSay, model: { id: FIXTURE.model, params: [] } }));
|
|
291
|
+
return script;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Whether the model emits the gated call this turn, and what the hook is
|
|
296
|
+
* expected to answer — one rule per case (see the header). `undefined`
|
|
297
|
+
* means "nothing is emitted".
|
|
298
|
+
*/
|
|
299
|
+
private emissionFor(toolCallId: string, view: EngineView): { readonly expectAllow: boolean } | undefined {
|
|
300
|
+
if (this.forcedReissues.delete(toolCallId)) {
|
|
301
|
+
// The disobedient model: emitted regardless; the hook decides on its own
|
|
302
|
+
// (a grant exists only for an APPROVE), so what to expect is the grant.
|
|
303
|
+
return { expectAllow: view.approvalDecisions.get(toolCallId) === ApprovalAction.APPROVE };
|
|
304
|
+
}
|
|
305
|
+
if ((this.proposals.get(toolCallId)?.allowed ?? 0) > 0) return undefined;
|
|
306
|
+
const decision = view.approvalDecisions.get(toolCallId) ?? ApprovalAction.UNSPECIFIED;
|
|
307
|
+
switch (decision) {
|
|
308
|
+
case ApprovalAction.UNSPECIFIED:
|
|
309
|
+
return { expectAllow: false };
|
|
310
|
+
case ApprovalAction.APPROVE:
|
|
311
|
+
case ApprovalAction.APPROVE_ALL:
|
|
312
|
+
return { expectAllow: true };
|
|
313
|
+
case ApprovalAction.SKIP:
|
|
314
|
+
case ApprovalAction.REJECT:
|
|
315
|
+
return undefined;
|
|
316
|
+
default: {
|
|
317
|
+
const exhaustive: never = decision;
|
|
318
|
+
throw new Error(`${this.name}: unknown approval action ${String(exhaustive)}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private proposeSteps(toolCallId: string, action: ProposedAction, view: EngineView, ev: ReturnType<typeof sdkEvents>): ScriptStep[] {
|
|
324
|
+
const emission = this.emissionFor(toolCallId, view);
|
|
325
|
+
if (!emission) return [];
|
|
326
|
+
if (action.kind === "read" || action.kind === "mcp") {
|
|
327
|
+
throw new Error(`${this.name}: propose(${action.kind}) is not a gated built-in on this harness; test bug`);
|
|
328
|
+
}
|
|
329
|
+
const gated: ProposedAction & { kind: GatedActionKind } = { ...action, kind: action.kind };
|
|
330
|
+
const memory = this.proposals.get(toolCallId) ?? { emitted: 0, allowed: 0 };
|
|
331
|
+
this.proposals.set(toolCallId, memory);
|
|
332
|
+
// The first emission carries the kit's id (the WAITING row the kit looks
|
|
333
|
+
// up); a re-issue carries a fresh call id, as the resumed SDK agent does,
|
|
334
|
+
// and the adapter reconciles it onto the committed row by identity.
|
|
335
|
+
const callId = memory.emitted === 0 ? toolCallId : `${toolCallId}#${memory.emitted}`;
|
|
336
|
+
memory.emitted += 1;
|
|
337
|
+
const name = STREAM_NAME[gated.kind];
|
|
338
|
+
const args = streamArgsFor(gated);
|
|
339
|
+
const workspaceRoot = this.workspaceRootOf(view.sessionId);
|
|
340
|
+
return [
|
|
341
|
+
step.event(ev.toolCall(callId, name, "running", args)),
|
|
342
|
+
step.effect(`kit: the real hook judges ${name} ${gated.resource}`, () => {
|
|
343
|
+
const { permission } = runWorkspaceHook(workspaceRoot, hookInputFor(gated));
|
|
344
|
+
if (permission === "allow") memory.allowed += 1;
|
|
345
|
+
if ((permission === "allow") !== emission.expectAllow) {
|
|
346
|
+
this.hookDisagreements.push(`${toolCallId}: expected ${emission.expectAllow ? "allow" : "deny"}, hook answered ${permission}`);
|
|
347
|
+
}
|
|
348
|
+
}),
|
|
349
|
+
emission.expectAllow
|
|
350
|
+
? step.event(ev.toolCall(callId, name, "completed", args, ALLOWED_RESULT))
|
|
351
|
+
: step.event(ev.toolCall(callId, name, "error", args, HOOK_BLOCKED_RESULT)),
|
|
352
|
+
];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* An ungated read: the stream tool call, the REAL hook (which allows every
|
|
357
|
+
* read — the gate's baked-in category set has no arm for it; asserted
|
|
358
|
+
* through the disagreement record like every other hook answer), and the
|
|
359
|
+
* completion with contents. The SDK executes what the hook allows, so the
|
|
360
|
+
* read counts as run.
|
|
361
|
+
*/
|
|
362
|
+
private readSteps(toolCallId: string, path: string, view: EngineView, ev: ReturnType<typeof sdkEvents>): ScriptStep[] {
|
|
363
|
+
const memory = this.proposals.get(toolCallId) ?? { emitted: 0, allowed: 0 };
|
|
364
|
+
this.proposals.set(toolCallId, memory);
|
|
365
|
+
memory.emitted += 1;
|
|
366
|
+
const args = { path };
|
|
367
|
+
const workspaceRoot = this.workspaceRootOf(view.sessionId);
|
|
368
|
+
return [
|
|
369
|
+
step.event(ev.toolCall(toolCallId, "read", "running", args)),
|
|
370
|
+
step.effect(`kit: the real hook judges read ${path}`, () => {
|
|
371
|
+
const { permission } = runWorkspaceHook(workspaceRoot, hookInputFor({ kind: "read", resource: path }));
|
|
372
|
+
if (permission === "allow") memory.allowed += 1;
|
|
373
|
+
else this.hookDisagreements.push(`${toolCallId}: expected allow for a read, hook answered ${permission}`);
|
|
374
|
+
}),
|
|
375
|
+
step.event(ev.toolCall(toolCallId, "read", "completed", args, `contents of ${path}`)),
|
|
376
|
+
];
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Park until the adapter cancels the run — the real shape of "the engine
|
|
381
|
+
* makes no progress until told to stop": the adapter's stop-signal listener
|
|
382
|
+
* calls `run.cancel()`, the double's status flips, and its stream breaks at
|
|
383
|
+
* the next step.
|
|
384
|
+
*/
|
|
385
|
+
private park(run: ScriptedRun): Promise<void> {
|
|
386
|
+
for (const waiter of this.hangWaiters.splice(0)) waiter();
|
|
387
|
+
if (run.status === "cancelled") return Promise.resolve();
|
|
388
|
+
return new Promise((resolve) => {
|
|
389
|
+
const unsubscribe = run.onDidChangeStatus((status) => {
|
|
390
|
+
if (status !== "cancelled") return;
|
|
391
|
+
unsubscribe();
|
|
392
|
+
resolve();
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
}
|
|
@@ -25,6 +25,7 @@ import { generateHookScript } from "../hook-script.js";
|
|
|
25
25
|
import { buildApprovalState, type ApprovalGrant, type McpToolPolicyEntry } from "../approval-state.js";
|
|
26
26
|
import type { MergedToolPolicy, ApprovalCategory } from "../approval-policy.js";
|
|
27
27
|
import { readCasObservations, type CasObservations } from "../cas-observations.js";
|
|
28
|
+
import type { ProposedAction } from "../../../__test-utils__/approval-contract/types.js";
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Whether `bash` is available on this machine. Hook tests must be skipped where
|
|
@@ -231,3 +232,68 @@ export const hookMcp = (name: string, input: Record<string, unknown> = {}) => ({
|
|
|
231
232
|
command: "npx -y srv mcp",
|
|
232
233
|
hook_event_name: "beforeMCPExecution",
|
|
233
234
|
});
|
|
235
|
+
|
|
236
|
+
// ── The contract kits' abstract action, in both of Cursor's taxonomies ──────
|
|
237
|
+
//
|
|
238
|
+
// Both kits (`approval-contract`, `harness-contract`) speak of a side effect as
|
|
239
|
+
// a taxonomy-free `ProposedAction`; Cursor sees the same act twice, as the
|
|
240
|
+
// STREAM tool call the SDK emits (`edit` / `shell` / `delete`, lowercase) and
|
|
241
|
+
// as the HOOK payload the preToolUse script judges (`Write` / `Shell` /
|
|
242
|
+
// `Delete`). One translation here, so every Cursor-side substrate and subject
|
|
243
|
+
// exercises the same category collapse that lets a stream-minted grant match a
|
|
244
|
+
// hook-named call.
|
|
245
|
+
|
|
246
|
+
/** Build the real preToolUse hook-input payload for an abstract action. */
|
|
247
|
+
export function hookInputFor(action: ProposedAction): object {
|
|
248
|
+
switch (action.kind) {
|
|
249
|
+
case "write":
|
|
250
|
+
return hookWrite(action.resource, action.content ?? "x");
|
|
251
|
+
case "shell":
|
|
252
|
+
return hookShell(action.resource);
|
|
253
|
+
case "delete":
|
|
254
|
+
return hookDelete(action.resource);
|
|
255
|
+
case "read":
|
|
256
|
+
return hookRead(action.resource);
|
|
257
|
+
case "mcp":
|
|
258
|
+
return hookMcp(action.mcpToolName ?? "mcp_tool");
|
|
259
|
+
default: {
|
|
260
|
+
const exhaustive: never = action.kind;
|
|
261
|
+
throw new Error(`hookInputFor: unknown action kind ${String(exhaustive)}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** The gated built-in categories: the only action kinds a grant is ever minted for. */
|
|
267
|
+
export type GatedActionKind = "write" | "shell" | "delete";
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Stream-side (SDK) tool name per gated category — deliberately the OTHER
|
|
271
|
+
* taxonomy from the hook input, so a grant minted from the stream matches a
|
|
272
|
+
* hook-named call only via the canonical category, not the raw name.
|
|
273
|
+
*/
|
|
274
|
+
export const STREAM_NAME: Record<GatedActionKind, string> = {
|
|
275
|
+
write: "edit",
|
|
276
|
+
shell: "shell",
|
|
277
|
+
delete: "delete",
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* The stream-side args of a gated action, mirroring {@link hookInputFor}: a
|
|
282
|
+
* write carries whole-file content (so its digest is content-exact and matches
|
|
283
|
+
* the hook's), a delete carries only a path, and a shell carries its command
|
|
284
|
+
* (the salient is already exact). The shapes the goldens' `edit` events use.
|
|
285
|
+
*/
|
|
286
|
+
export function streamArgsFor(action: ProposedAction & { kind: GatedActionKind }): Record<string, unknown> {
|
|
287
|
+
switch (action.kind) {
|
|
288
|
+
case "shell":
|
|
289
|
+
return { command: action.resource };
|
|
290
|
+
case "delete":
|
|
291
|
+
return { path: action.resource };
|
|
292
|
+
case "write":
|
|
293
|
+
return { path: action.resource, content: action.content ?? "x" };
|
|
294
|
+
default: {
|
|
295
|
+
const exhaustive: never = action.kind;
|
|
296
|
+
throw new Error(`streamArgsFor: unknown gated kind ${String(exhaustive)}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -15,15 +15,7 @@
|
|
|
15
15
|
* (`enforcesExactResource: true`) and implements `authorizeAfterGrant`.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import {
|
|
19
|
-
setupCursorHookHarness,
|
|
20
|
-
hasBash,
|
|
21
|
-
hookWrite,
|
|
22
|
-
hookShell,
|
|
23
|
-
hookDelete,
|
|
24
|
-
hookRead,
|
|
25
|
-
hookMcp,
|
|
26
|
-
} from "./cursor-hook-harness.js";
|
|
18
|
+
import { setupCursorHookHarness, hasBash, hookInputFor, streamArgsFor, STREAM_NAME } from "./cursor-hook-harness.js";
|
|
27
19
|
import { toolIdentity, type ApprovalGrant } from "../approval-state.js";
|
|
28
20
|
import { contentDigest } from "../../../shared/file-tools.js";
|
|
29
21
|
import type { ApprovalCategory } from "../approval-policy.js";
|
|
@@ -34,31 +26,6 @@ import type {
|
|
|
34
26
|
ProposedAction,
|
|
35
27
|
} from "../../../__test-utils__/approval-contract/types.js";
|
|
36
28
|
|
|
37
|
-
/** Build the real preToolUse hook-input payload for an abstract action. */
|
|
38
|
-
function hookInputFor(action: ProposedAction): object {
|
|
39
|
-
switch (action.kind) {
|
|
40
|
-
case "write":
|
|
41
|
-
return hookWrite(action.resource, action.content ?? "x");
|
|
42
|
-
case "shell":
|
|
43
|
-
return hookShell(action.resource);
|
|
44
|
-
case "delete":
|
|
45
|
-
return hookDelete(action.resource);
|
|
46
|
-
case "read":
|
|
47
|
-
return hookRead(action.resource);
|
|
48
|
-
case "mcp":
|
|
49
|
-
return hookMcp(action.mcpToolName ?? "mcp_tool");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Stream-side (SDK) tool name per gated category — deliberately the OTHER
|
|
54
|
-
// taxonomy from the hook input, so a grant minted here matches a hook-named call
|
|
55
|
-
// only via the canonical category, not the raw name.
|
|
56
|
-
const STREAM_NAME: Record<"write" | "shell" | "delete", string> = {
|
|
57
|
-
write: "edit",
|
|
58
|
-
shell: "shell",
|
|
59
|
-
delete: "delete",
|
|
60
|
-
};
|
|
61
|
-
|
|
62
29
|
/**
|
|
63
30
|
* Mint the approval grant for an action using its stream-side identity. Only the
|
|
64
31
|
* gated built-in categories are ever granted in the contract (read is never
|
|
@@ -69,15 +36,7 @@ function grantFor(action: ProposedAction): ApprovalGrant {
|
|
|
69
36
|
throw new Error(`grantFor: ${action.kind} actions are not granted in the contract`);
|
|
70
37
|
}
|
|
71
38
|
const streamName = STREAM_NAME[action.kind];
|
|
72
|
-
|
|
73
|
-
// content-exact and matches the hook's), a delete carries only a path (no
|
|
74
|
-
// content), and a shell carries its command (the salient is already exact).
|
|
75
|
-
const args: Record<string, unknown> =
|
|
76
|
-
action.kind === "shell"
|
|
77
|
-
? { command: action.resource }
|
|
78
|
-
: action.kind === "delete"
|
|
79
|
-
? { path: action.resource }
|
|
80
|
-
: { path: action.resource, content: action.content ?? "x" };
|
|
39
|
+
const args = streamArgsFor({ ...action, kind: action.kind });
|
|
81
40
|
const identity = toolIdentity(streamName, "", args);
|
|
82
41
|
return {
|
|
83
42
|
toolName: streamName,
|