@stigmer/runner 3.14.1 → 3.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +28 -5
- package/dist/__test-utils__/hermetic-activity.js +23 -7
- package/dist/__test-utils__/hermetic-activity.js.map +1 -1
- 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 +38 -62
- package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js +47 -121
- package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js.map +1 -1
- package/dist/activities/execute-cursor/__test-utils__/scripted-agent.d.ts +17 -1
- package/dist/activities/execute-cursor/__test-utils__/scripted-agent.js +27 -4
- package/dist/activities/execute-cursor/__test-utils__/scripted-agent.js.map +1 -1
- package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.d.ts +52 -11
- package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.js +66 -7
- package/dist/activities/execute-cursor/__test-utils__/scripted-sdk.js.map +1 -1
- 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 +16 -0
- package/dist/harness/capabilities.js +1 -0
- package/dist/harness/capabilities.js.map +1 -1
- 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 +44 -5
- package/dist/harness/registry.js +61 -5
- package/dist/harness/registry.js.map +1 -1
- 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 +232 -52
- package/dist/harness/types.js +17 -8
- package/dist/harness/types.js.map +1 -1
- 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 +110 -14
- 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 +128 -83
- package/src/__test-utils__/harness-contract/recording-sink.ts +15 -4
- package/src/__test-utils__/harness-contract/runtime-contract.ts +666 -0
- package/src/__test-utils__/harness-contract/scripted-adapter.ts +92 -32
- package/src/__test-utils__/harness-contract/types.ts +85 -9
- package/src/__test-utils__/hermetic-activity.ts +33 -8
- package/src/__test-utils__/model-registry-fixture.ts +72 -0
- package/src/__test-utils__/module-specifiers.ts +82 -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 +7 -5
- 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 +65 -145
- package/src/activities/execute-cursor/__test-utils__/scripted-agent.ts +30 -4
- package/src/activities/execute-cursor/__test-utils__/scripted-sdk.ts +96 -8
- 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 +1 -1
- package/src/activities/execute-cursor/__tests__/hermetic/file-review-capture.test.ts +1 -1
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/cost-cap.status.json +53 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/pause.status.json +1 -6
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/platform-stop.status.json +56 -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/unattributed-hook-block.status.json +79 -0
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/worker-shutdown.status.json +2 -7
- 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 +22 -18
- package/src/activities/execute-cursor/__tests__/hermetic/plain-turn.test.ts +1 -1
- package/src/activities/execute-cursor/__tests__/hermetic/recovery-fresh-agent.test.ts +1 -1
- 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 +1 -1
- 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 +1 -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 +17 -0
- package/src/harness/persist-chokepoint.ts +112 -0
- package/src/harness/registry.ts +79 -5
- 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 +248 -53
- 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
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The Cursor harness's stream phase — the single per-event consumption loop that
|
|
3
3
|
* turns a live Cursor SDK run into the streamed transcript, mid-run progress, and
|
|
4
|
-
* the
|
|
4
|
+
* the one flag that decides how the turn goes on (the first-denial stop).
|
|
5
5
|
*
|
|
6
|
-
* Extracted from the activity entry point
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Extracted from the activity entry point so that BOTH the primary turn and
|
|
7
|
+
* the two recovery retries (poisoned-handle / transport-timeout) drive the
|
|
8
|
+
* exact same code. The retries previously re-implemented a stripped "bare"
|
|
9
9
|
* loop that dropped live persist, DD-32/DD-33 mid-run progress, sub-agent
|
|
10
|
-
* tracking, the first-denial early stop, and correct pause
|
|
10
|
+
* tracking, the first-denial early stop, and correct pause handling — so a
|
|
11
11
|
* retry froze the UI and mis-handled a mid-retry pause. One loop removes that
|
|
12
12
|
* drift by construction.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
* (
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
14
|
+
* What the loop asks of the runtime, through the sink (`harness/types.ts`):
|
|
15
|
+
* `recordActivity()` per event (with the tool name) and per delta, so the
|
|
16
|
+
* runtime's stall watchdog measures the engine; `reportUsage()` per
|
|
17
|
+
* `turn-ended` delta, priced here at the requested variant's rates
|
|
18
|
+
* (`usage-pricing.ts`), so the runtime accounts and enforces the cost cap;
|
|
19
|
+
* `requestPersist()` where a discrete change or the streaming cadence says
|
|
20
|
+
* so (`shared/persist-decision.ts` over this loop's own dirty flags), AWAITED,
|
|
21
|
+
* so a platform STOP the runtime reads from that write aborts the signal
|
|
22
|
+
* before the next event is pulled; and `stopSignal`, checked at every event
|
|
23
|
+
* boundary and listened to inside the pull, where an abort cancels the SDK
|
|
24
|
+
* run — the one way a wedged stream is unblocked, and the same act for every
|
|
25
|
+
* cause of stopping (the runtime knows why; this loop never does).
|
|
26
|
+
*
|
|
27
|
+
* Until S2 M3 this loop armed its own stall watchdog, enforced the cost cap,
|
|
28
|
+
* read STOP from its own persist, and told a pause from the activity's
|
|
29
|
+
* cancellation signal; every one of those is the runtime's now, and the loop
|
|
30
|
+
* reports only `completed`, `first-denial` or `interrupted`.
|
|
22
31
|
*/
|
|
23
|
-
import type { AgentExecutionStatus } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
|
|
24
|
-
import { ExecutionControlSignal } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
25
32
|
import type { SDKMessage, InteractionUpdate } from "@cursor/sdk";
|
|
26
|
-
import {
|
|
33
|
+
import type { TurnSink } from "../../harness/types.js";
|
|
27
34
|
import { type ProgressCaptureState, type ProgressSubstrate } from "../../shared/filereview/progress.js";
|
|
28
35
|
import type { MessageAccumulator } from "./message-translator.js";
|
|
29
36
|
import type { DeltaEnricher } from "./delta-enricher.js";
|
|
30
37
|
import type { TodoTracker } from "./todo-tracker.js";
|
|
31
38
|
import type { StreamingUpdateScheduler } from "../../shared/streaming-scheduler.js";
|
|
32
|
-
import type {
|
|
39
|
+
import type { CursorUsagePricer } from "./usage-pricing.js";
|
|
33
40
|
import type { createCursorEventRecorder } from "./cursor-event-recorder.js";
|
|
34
41
|
/**
|
|
35
42
|
* The subset of the Cursor SDK `Run` the stream phase consumes. Kept structural
|
|
@@ -42,75 +49,47 @@ export interface StreamableRun {
|
|
|
42
49
|
}
|
|
43
50
|
export type CursorTurnEventRecorder = ReturnType<typeof createCursorEventRecorder>;
|
|
44
51
|
/**
|
|
45
|
-
* Why the turn's stream ended.
|
|
46
|
-
*
|
|
47
|
-
* `
|
|
48
|
-
* terminals that return or throw.
|
|
52
|
+
* Why the turn's stream ended. `completed` and `first-denial` proceed to the
|
|
53
|
+
* turn boundary; `interrupted` is the runtime's stop, and the adapter settles
|
|
54
|
+
* `interrupted` (the runtime classifies the cause from its own evidence).
|
|
49
55
|
*/
|
|
50
|
-
export type TurnStreamReason = "completed" | "
|
|
56
|
+
export type TurnStreamReason = "completed" | "first-denial" | "interrupted";
|
|
51
57
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* one object (created once per turn, shared by every producer, the epilogue, and
|
|
57
|
-
* the outer catch/finally) makes ownership explicit and lets the primary turn and
|
|
58
|
-
* both recovery retries drive the identical stream code.
|
|
59
|
-
*
|
|
60
|
-
* Field ownership is annotated per field: exactly one primary writer, plus any
|
|
61
|
-
* documented producer/consumer handshakes.
|
|
58
|
+
* The flags the turn's stream produces that outlive the loop: created once per
|
|
59
|
+
* turn and shared by the primary stream, both recovery retries, the boundary
|
|
60
|
+
* and the settle, so every reader sees ONE source of truth. Field ownership
|
|
61
|
+
* is annotated per field: exactly one primary writer.
|
|
62
62
|
*/
|
|
63
63
|
export interface TurnStreamState {
|
|
64
|
-
/** Written by:
|
|
65
|
-
pauseDetected: boolean;
|
|
66
|
-
/** Written by: the stall-watchdog callback. Read by: the loop + epilogue. */
|
|
67
|
-
stallDetected: boolean;
|
|
68
|
-
stallError: StallTimeoutError | undefined;
|
|
69
|
-
/** Written by: the loop (on the first ledger entry). Read by: the loop, epilogue, settleRetryTurn. */
|
|
64
|
+
/** Written by: the loop (on the first ledger entry). Read by: the loop, the boundary, settleRetryTurn. */
|
|
70
65
|
firstDenialDetected: boolean;
|
|
71
66
|
/** Written by: the fs denial-watcher (→ true) + the loop (→ false after a read). Read by: the loop. */
|
|
72
67
|
denialLedgerDirty: boolean;
|
|
73
68
|
/** Written by: the loop (the first-denial run.cancel()). Read by: the turn boundary. */
|
|
74
69
|
denialCancelSettled: Promise<void> | undefined;
|
|
75
|
-
/** Written by: the loop (a platform STOP signal from persist). Read by: the loop + epilogue. */
|
|
76
|
-
platformStopSignaled: boolean;
|
|
77
|
-
/** Written by: onDelta (a turn-ended usage delta pushed the estimate past max_cost_usd). Read by: the loop (cancel + break) + epilogue. */
|
|
78
|
-
costCapExceeded: boolean;
|
|
79
70
|
/** Written by: the loop (a stream ERROR status event) + the retry setup (reset). Read by: error classification. */
|
|
80
71
|
streamErrorMessage: string | undefined;
|
|
81
|
-
/** Written by: the loop (each tool_call). Read by: the stall-watchdog (message enrichment). */
|
|
82
|
-
lastToolName: string | undefined;
|
|
83
72
|
/** Written by: the loop. Read by: the event recorder, the persist cadence, and logs. */
|
|
84
73
|
eventCount: number;
|
|
85
74
|
/** Written + read by: onDelta (log the first turn's context attribution exactly once). */
|
|
86
75
|
firstTurnAttributionLogged: boolean;
|
|
87
|
-
/** The stall watchdog for the CURRENT stream, armed by consumeCursorTurnStream; held so onDelta can reset it and the activity's finally can stop it. */
|
|
88
|
-
stallWatchdog: StallWatchdog | undefined;
|
|
89
76
|
}
|
|
90
77
|
export declare function newTurnStreamState(): TurnStreamState;
|
|
91
78
|
/**
|
|
92
79
|
* The subset of collaborators the shared onDelta needs. Broken out from
|
|
93
80
|
* CursorTurnStreamDeps because the primary send happens BEFORE the accumulator
|
|
94
|
-
* exists — onDelta only touches
|
|
81
|
+
* exists — onDelta only touches the sink, the pricer, the enricher, and state.
|
|
95
82
|
*/
|
|
96
83
|
export interface TurnOnDeltaDeps {
|
|
97
|
-
readonly
|
|
84
|
+
readonly sink: TurnSink;
|
|
85
|
+
/** This harness's pricing of a `turn-ended` delta at the requested variant's rates. */
|
|
86
|
+
readonly usagePricer: CursorUsagePricer;
|
|
98
87
|
readonly deltaEnricher: DeltaEnricher;
|
|
99
|
-
/** Temporal heartbeat. Injected so the callback is testable without Temporal. */
|
|
100
|
-
readonly heartbeat: () => void;
|
|
101
88
|
readonly promptEstimatedTokens: number;
|
|
102
89
|
readonly executionId: string;
|
|
103
90
|
readonly state: TurnStreamState;
|
|
104
|
-
/**
|
|
105
|
-
* ExecutionConfig.max_cost_usd — 0/unset disables the cap. Checked by
|
|
106
|
-
* onDelta after each turn-ended usage delta lands (the only point the
|
|
107
|
-
* running estimate advances); the loop performs the actual run.cancel().
|
|
108
|
-
* See cost-guard.ts for the semantics.
|
|
109
|
-
*/
|
|
110
|
-
readonly maxCostUsd: number;
|
|
111
91
|
}
|
|
112
92
|
export interface CursorTurnStreamDeps extends TurnOnDeltaDeps {
|
|
113
|
-
readonly status: AgentExecutionStatus;
|
|
114
93
|
readonly accumulator: MessageAccumulator;
|
|
115
94
|
readonly todoTracker: TodoTracker;
|
|
116
95
|
readonly eventRecorder: CursorTurnEventRecorder | undefined;
|
|
@@ -120,19 +99,12 @@ export interface CursorTurnStreamDeps extends TurnOnDeltaDeps {
|
|
|
120
99
|
readonly changeSetId: string;
|
|
121
100
|
/** Session HITL dir holding the denial ledger; undefined → no gate installed → no first-denial stop. */
|
|
122
101
|
readonly hitlDir: string | undefined;
|
|
123
|
-
readonly stallTimeoutMs: number;
|
|
124
|
-
/** The single size-bounded persist chokepoint. Returns the platform control signal. */
|
|
125
|
-
readonly persist: (status: AgentExecutionStatus) => Promise<ExecutionControlSignal>;
|
|
126
|
-
/** Temporal cancellation check. Injected so the loop is testable without Temporal. */
|
|
127
|
-
readonly isCancelled: () => boolean;
|
|
128
102
|
}
|
|
129
103
|
/**
|
|
130
104
|
* Build the shared onDelta callback. The Cursor SDK's fine-grained delta channel
|
|
131
105
|
* carries token usage, live shell output, and precise tool-call timings; it also
|
|
132
|
-
* fires far more often than discrete stream events, so it is where the
|
|
133
|
-
* timer is reset during a long model generation.
|
|
134
|
-
* here flags the pause so the loop and epilogue treat it as a user pause (the
|
|
135
|
-
* bare retry loops swallowed this — the cause of the mid-retry mislabel).
|
|
106
|
+
* fires far more often than discrete stream events, so it is where the runtime's
|
|
107
|
+
* stall timer is reset during a long model generation.
|
|
136
108
|
*/
|
|
137
109
|
export declare function makeCursorTurnOnDelta(deps: TurnOnDeltaDeps): (event: {
|
|
138
110
|
update: InteractionUpdate;
|
|
@@ -142,9 +114,7 @@ export declare function makeCursorTurnOnDelta(deps: TurnOnDeltaDeps): (event: {
|
|
|
142
114
|
* transcript, todos, sub-agent tracking, live persist, and DD-32/DD-33 mid-run
|
|
143
115
|
* progress, and reporting WHY the stream ended.
|
|
144
116
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* backstop). Mutates `deps.status` + `deps.state` in place. The caller owns the
|
|
148
|
-
* post-stream finalize and the terminal mapping.
|
|
117
|
+
* Mutates `deps.sink.status` + `deps.state` in place. The caller owns the
|
|
118
|
+
* post-stream finalize and the settle.
|
|
149
119
|
*/
|
|
150
120
|
export declare function consumeCursorTurnStream(run: StreamableRun, deps: CursorTurnStreamDeps): Promise<TurnStreamReason>;
|
|
@@ -1,78 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The Cursor harness's stream phase — the single per-event consumption loop that
|
|
3
3
|
* turns a live Cursor SDK run into the streamed transcript, mid-run progress, and
|
|
4
|
-
* the
|
|
4
|
+
* the one flag that decides how the turn goes on (the first-denial stop).
|
|
5
5
|
*
|
|
6
|
-
* Extracted from the activity entry point
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Extracted from the activity entry point so that BOTH the primary turn and
|
|
7
|
+
* the two recovery retries (poisoned-handle / transport-timeout) drive the
|
|
8
|
+
* exact same code. The retries previously re-implemented a stripped "bare"
|
|
9
9
|
* loop that dropped live persist, DD-32/DD-33 mid-run progress, sub-agent
|
|
10
|
-
* tracking, the first-denial early stop, and correct pause
|
|
10
|
+
* tracking, the first-denial early stop, and correct pause handling — so a
|
|
11
11
|
* retry froze the UI and mis-handled a mid-retry pause. One loop removes that
|
|
12
12
|
* drift by construction.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
* (
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
14
|
+
* What the loop asks of the runtime, through the sink (`harness/types.ts`):
|
|
15
|
+
* `recordActivity()` per event (with the tool name) and per delta, so the
|
|
16
|
+
* runtime's stall watchdog measures the engine; `reportUsage()` per
|
|
17
|
+
* `turn-ended` delta, priced here at the requested variant's rates
|
|
18
|
+
* (`usage-pricing.ts`), so the runtime accounts and enforces the cost cap;
|
|
19
|
+
* `requestPersist()` where a discrete change or the streaming cadence says
|
|
20
|
+
* so (`shared/persist-decision.ts` over this loop's own dirty flags), AWAITED,
|
|
21
|
+
* so a platform STOP the runtime reads from that write aborts the signal
|
|
22
|
+
* before the next event is pulled; and `stopSignal`, checked at every event
|
|
23
|
+
* boundary and listened to inside the pull, where an abort cancels the SDK
|
|
24
|
+
* run — the one way a wedged stream is unblocked, and the same act for every
|
|
25
|
+
* cause of stopping (the runtime knows why; this loop never does).
|
|
26
|
+
*
|
|
27
|
+
* Until S2 M3 this loop armed its own stall watchdog, enforced the cost cap,
|
|
28
|
+
* read STOP from its own persist, and told a pause from the activity's
|
|
29
|
+
* cancellation signal; every one of those is the runtime's now, and the loop
|
|
30
|
+
* reports only `completed`, `first-denial` or `interrupted`.
|
|
22
31
|
*/
|
|
23
|
-
import {
|
|
24
|
-
import { CancelledFailure } from "@temporalio/activity";
|
|
25
|
-
import { ExecutionControlSignal } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
26
|
-
import { StreamingUsageSummarySchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/usage_pb";
|
|
27
|
-
import { startStallWatchdog, StallTimeoutError, } from "../../shared/stall-watchdog.js";
|
|
28
|
-
import { shouldPersistStreamingStatus } from "./persist-decision.js";
|
|
32
|
+
import { shouldPersistStreamingStatus } from "../../shared/persist-decision.js";
|
|
29
33
|
import { approvalDenials, readDenialLedger } from "./approval-state.js";
|
|
30
34
|
import { captureFileChangeProgress, } from "../../shared/filereview/progress.js";
|
|
31
|
-
import { costCapExceeded } from "./cost-guard.js";
|
|
32
35
|
export function newTurnStreamState() {
|
|
33
36
|
return {
|
|
34
|
-
pauseDetected: false,
|
|
35
|
-
stallDetected: false,
|
|
36
|
-
stallError: undefined,
|
|
37
37
|
firstDenialDetected: false,
|
|
38
38
|
denialLedgerDirty: false,
|
|
39
39
|
denialCancelSettled: undefined,
|
|
40
|
-
platformStopSignaled: false,
|
|
41
|
-
costCapExceeded: false,
|
|
42
40
|
streamErrorMessage: undefined,
|
|
43
|
-
lastToolName: undefined,
|
|
44
41
|
eventCount: 0,
|
|
45
42
|
firstTurnAttributionLogged: false,
|
|
46
|
-
stallWatchdog: undefined,
|
|
47
43
|
};
|
|
48
44
|
}
|
|
49
45
|
/**
|
|
50
46
|
* Build the shared onDelta callback. The Cursor SDK's fine-grained delta channel
|
|
51
47
|
* carries token usage, live shell output, and precise tool-call timings; it also
|
|
52
|
-
* fires far more often than discrete stream events, so it is where the
|
|
53
|
-
* timer is reset during a long model generation.
|
|
54
|
-
* here flags the pause so the loop and epilogue treat it as a user pause (the
|
|
55
|
-
* bare retry loops swallowed this — the cause of the mid-retry mislabel).
|
|
48
|
+
* fires far more often than discrete stream events, so it is where the runtime's
|
|
49
|
+
* stall timer is reset during a long model generation.
|
|
56
50
|
*/
|
|
57
51
|
export function makeCursorTurnOnDelta(deps) {
|
|
58
|
-
const {
|
|
52
|
+
const { sink, usagePricer, deltaEnricher, promptEstimatedTokens, executionId, state } = deps;
|
|
59
53
|
return ({ update }) => {
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
|
|
54
|
+
// Progress on the delta channel too: a long model generation emits token
|
|
55
|
+
// deltas but few discrete stream events, and resetting only in the stream
|
|
56
|
+
// loop would false-positive a stall.
|
|
57
|
+
sink.recordActivity();
|
|
64
58
|
if (update.type === "turn-ended" && update.usage) {
|
|
65
|
-
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
// the run — the loop reads the flag and performs the clean cancel.
|
|
69
|
-
if (!state.costCapExceeded
|
|
70
|
-
&& costCapExceeded(maxCostUsd, usageAccumulator.snapshot().estimatedCostUsd)) {
|
|
71
|
-
state.costCapExceeded = true;
|
|
72
|
-
console.warn(`ExecuteCursor cost cap exceeded: execution=${executionId}, ` +
|
|
73
|
-
`estimatedCostUsd=${usageAccumulator.snapshot().estimatedCostUsd.toFixed(4)}, ` +
|
|
74
|
-
`maxCostUsd=${maxCostUsd.toFixed(2)}`);
|
|
75
|
-
}
|
|
59
|
+
// The running estimate advances only here; the runtime enforces the cap
|
|
60
|
+
// and aborts the signal, which the loop reads at the next boundary.
|
|
61
|
+
sink.reportUsage(usagePricer.price(update.usage));
|
|
76
62
|
if (!state.firstTurnAttributionLogged) {
|
|
77
63
|
state.firstTurnAttributionLogged = true;
|
|
78
64
|
const sdkInputTokens = update.usage.inputTokens ?? 0;
|
|
@@ -83,16 +69,6 @@ export function makeCursorTurnOnDelta(deps) {
|
|
|
83
69
|
}
|
|
84
70
|
}
|
|
85
71
|
deltaEnricher.processDelta(update);
|
|
86
|
-
try {
|
|
87
|
-
heartbeat();
|
|
88
|
-
}
|
|
89
|
-
catch (hbErr) {
|
|
90
|
-
if (hbErr instanceof CancelledFailure) {
|
|
91
|
-
state.pauseDetected = true;
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
throw hbErr;
|
|
95
|
-
}
|
|
96
72
|
};
|
|
97
73
|
}
|
|
98
74
|
/**
|
|
@@ -100,59 +76,38 @@ export function makeCursorTurnOnDelta(deps) {
|
|
|
100
76
|
* transcript, todos, sub-agent tracking, live persist, and DD-32/DD-33 mid-run
|
|
101
77
|
* progress, and reporting WHY the stream ended.
|
|
102
78
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* backstop). Mutates `deps.status` + `deps.state` in place. The caller owns the
|
|
106
|
-
* post-stream finalize and the terminal mapping.
|
|
79
|
+
* Mutates `deps.sink.status` + `deps.state` in place. The caller owns the
|
|
80
|
+
* post-stream finalize and the settle.
|
|
107
81
|
*/
|
|
108
82
|
export async function consumeCursorTurnStream(run, deps) {
|
|
109
|
-
const {
|
|
110
|
-
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
state.stallDetected = true;
|
|
119
|
-
state.stallError = new StallTimeoutError(idleMs, state.lastToolName ? `last tool: ${state.lastToolName}` : undefined);
|
|
120
|
-
console.warn(`ExecuteCursor stall detected: execution=${executionId}, idleMs=${idleMs}, lastTool=${state.lastToolName ?? "none"}`);
|
|
83
|
+
const { sink, accumulator, todoTracker, deltaEnricher, eventRecorder, scheduler, progressSubstrate, progressState, changeSetId, hitlDir, executionId, state, } = deps;
|
|
84
|
+
const { status, stopSignal } = sink;
|
|
85
|
+
// The runtime's stop, whatever its cause, ends the run through the SDK's
|
|
86
|
+
// own cancel: that is what unblocks a wedged `for await` (a stall), and it
|
|
87
|
+
// stops the engine's tools and deltas from outliving the turn on every
|
|
88
|
+
// other cause too. Guarded by supports("cancel") as the loop's own cancels
|
|
89
|
+
// are; the teardown rejection it can cause is swallowed below.
|
|
90
|
+
const cancelOnStop = () => {
|
|
91
|
+
console.log(`ExecuteCursor stopping stream on the runtime's stop signal: execution=${executionId}`);
|
|
121
92
|
if (run.supports?.("cancel")) {
|
|
122
93
|
void run.cancel().catch((cancelErr) => {
|
|
123
|
-
console.warn(`ExecuteCursor run.cancel() after
|
|
94
|
+
console.warn(`ExecuteCursor run.cancel() after stop failed (non-fatal): execution=${executionId}, ` +
|
|
124
95
|
`error=${cancelErr instanceof Error ? cancelErr.message : cancelErr}`);
|
|
125
96
|
});
|
|
126
97
|
}
|
|
127
|
-
}
|
|
98
|
+
};
|
|
99
|
+
if (stopSignal.aborted) {
|
|
100
|
+
cancelOnStop();
|
|
101
|
+
return "interrupted";
|
|
102
|
+
}
|
|
103
|
+
stopSignal.addEventListener("abort", cancelOnStop, { once: true });
|
|
128
104
|
try {
|
|
129
105
|
for await (const event of run.stream()) {
|
|
130
|
-
if (
|
|
131
|
-
state.pauseDetected = true;
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
if (state.stallDetected)
|
|
106
|
+
if (stopSignal.aborted)
|
|
135
107
|
break;
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
// here — nothing downstream waits on this turn's agent (unlike the
|
|
140
|
-
// first-denial stop, whose ledger read needs a stopped agent).
|
|
141
|
-
if (state.costCapExceeded) {
|
|
142
|
-
console.log(`ExecuteCursor stopping stream at cost cap: execution=${executionId}`);
|
|
143
|
-
if (run.supports?.("cancel")) {
|
|
144
|
-
void run.cancel().catch((cancelErr) => {
|
|
145
|
-
console.warn(`ExecuteCursor run.cancel() after cost cap failed (non-fatal): execution=${executionId}, ` +
|
|
146
|
-
`error=${cancelErr instanceof Error ? cancelErr.message : cancelErr}`);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
// Progress: reset the stall timer on every stream event.
|
|
152
|
-
state.stallWatchdog.recordActivity();
|
|
153
|
-
if (event.type === "tool_call" && typeof event.name === "string") {
|
|
154
|
-
state.lastToolName = event.name;
|
|
155
|
-
}
|
|
108
|
+
// Progress: reset the runtime's stall timer on every stream event,
|
|
109
|
+
// naming the tool so a stall's copy can say `last tool: shell`.
|
|
110
|
+
sink.recordActivity(event.type === "tool_call" && typeof event.name === "string" ? event.name : undefined);
|
|
156
111
|
eventRecorder?.record(event, state.eventCount);
|
|
157
112
|
accumulator.processEvent(event);
|
|
158
113
|
todoTracker.processEvent(event);
|
|
@@ -216,9 +171,6 @@ export async function consumeCursorTurnStream(run, deps) {
|
|
|
216
171
|
todosDirty: todoTracker.isDirty,
|
|
217
172
|
contentDirty: accumulator.isDirty,
|
|
218
173
|
}, scheduler, state.eventCount);
|
|
219
|
-
if (usageAccumulator.hasTurns) {
|
|
220
|
-
status.streamingUsage = create(StreamingUsageSummarySchema, usageAccumulator.snapshot());
|
|
221
|
-
}
|
|
222
174
|
if (shouldPersist) {
|
|
223
175
|
// Sync sub-agent executions into status before every persist so the live
|
|
224
176
|
// UI reflects delegation (including the IN_PROGRESS state) while the
|
|
@@ -236,54 +188,37 @@ export async function consumeCursorTurnStream(run, deps) {
|
|
|
236
188
|
state: progressState,
|
|
237
189
|
});
|
|
238
190
|
}
|
|
239
|
-
|
|
191
|
+
// Awaited: the runtime reads the control plane's answer to this write,
|
|
192
|
+
// and a STOP must be seen at the next event boundary, not one event late.
|
|
193
|
+
await sink.requestPersist();
|
|
240
194
|
deltaEnricher.markPersisted();
|
|
241
195
|
todoTracker.markPersisted();
|
|
242
196
|
accumulator.markPersisted();
|
|
243
197
|
scheduler.markUpdateSent(state.eventCount);
|
|
244
|
-
heartbeat();
|
|
245
|
-
if (signal === ExecutionControlSignal.STOP) {
|
|
246
|
-
state.platformStopSignaled = true;
|
|
247
|
-
console.warn(`ExecuteCursor platform stop signal received: execution=${executionId}`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
if (state.platformStopSignaled) {
|
|
251
|
-
console.log(`ExecuteCursor stopping stream due to platform stop signal: execution=${executionId}`);
|
|
252
|
-
break;
|
|
253
198
|
}
|
|
254
199
|
}
|
|
255
200
|
}
|
|
256
201
|
catch (streamErr) {
|
|
257
|
-
// run.cancel() — from the
|
|
258
|
-
//
|
|
259
|
-
//
|
|
260
|
-
//
|
|
261
|
-
|
|
262
|
-
if (!state.stallDetected && !state.firstDenialDetected && !state.costCapExceeded) {
|
|
202
|
+
// run.cancel() — from the runtime's stop or the first-denial stop — can
|
|
203
|
+
// make the stream iterator reject as it tears down; that is the expected
|
|
204
|
+
// teardown for both, so swallow it and fall through. Anything else is a
|
|
205
|
+
// genuine stream failure — rethrow it to the adapter's error handler.
|
|
206
|
+
if (!stopSignal.aborted && !state.firstDenialDetected) {
|
|
263
207
|
throw streamErr;
|
|
264
208
|
}
|
|
265
209
|
console.warn(`ExecuteCursor stream ended via cancel: execution=${executionId}, ` +
|
|
266
|
-
`
|
|
267
|
-
`costCap=${state.costCapExceeded}`);
|
|
210
|
+
`stopped=${stopSignal.aborted}, firstDenial=${state.firstDenialDetected}`);
|
|
268
211
|
}
|
|
269
212
|
finally {
|
|
270
|
-
|
|
213
|
+
stopSignal.removeEventListener("abort", cancelOnStop);
|
|
271
214
|
}
|
|
272
|
-
// Report why the stream ended
|
|
273
|
-
//
|
|
274
|
-
//
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (state.stallDetected)
|
|
278
|
-
return "stalled";
|
|
279
|
-
if (state.platformStopSignaled)
|
|
280
|
-
return "platform-stop";
|
|
281
|
-
if (state.costCapExceeded)
|
|
282
|
-
return "cost-cap";
|
|
215
|
+
// Report why the stream ended: the runtime's stop outranks a first denial
|
|
216
|
+
// (there is no review to open on a stopped turn), a first denial outranks a
|
|
217
|
+
// natural end.
|
|
218
|
+
if (stopSignal.aborted)
|
|
219
|
+
return "interrupted";
|
|
283
220
|
if (state.firstDenialDetected)
|
|
284
221
|
return "first-denial";
|
|
285
|
-
if (state.pauseDetected || isCancelled())
|
|
286
|
-
return "paused";
|
|
287
222
|
return "completed";
|
|
288
223
|
}
|
|
289
224
|
//# sourceMappingURL=turn-stream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-stream.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/turn-stream.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"turn-stream.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/turn-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAIH,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EACL,yBAAyB,GAG1B,MAAM,qCAAqC,CAAC;AAgD7C,MAAM,UAAU,kBAAkB;IAChC,OAAO;QACL,mBAAmB,EAAE,KAAK;QAC1B,iBAAiB,EAAE,KAAK;QACxB,mBAAmB,EAAE,SAAS;QAC9B,kBAAkB,EAAE,SAAS;QAC7B,UAAU,EAAE,CAAC;QACb,0BAA0B,EAAE,KAAK;KAClC,CAAC;AACJ,CAAC;AA6BD;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,IAAqB;IAErB,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,qBAAqB,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAC7F,OAAO,CAAC,EAAE,MAAM,EAAE,EAA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BACX,SAAS,EAAE,iBAAiB;wBAC5B,KAAK,EAAE,aAAa;qBACrB,CAAC,CAAC;gBACL,CAAC;gBACD,uEAAuE;gBACvE,0EAA0E;gBAC1E,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;gBAC5B,aAAa,CAAC,aAAa,EAAE,CAAC;gBAC9B,WAAW,CAAC,aAAa,EAAE,CAAC;gBAC5B,WAAW,CAAC,aAAa,EAAE,CAAC;gBAC5B,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,SAAS,EAAE,CAAC;QACnB,wEAAwE;QACxE,yEAAyE;QACzE,wEAAwE;QACxE,sEAAsE;QACtE,IAAI,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC;YACtD,MAAM,SAAS,CAAC;QAClB,CAAC;QACD,OAAO,CAAC,IAAI,CACV,oDAAoD,WAAW,IAAI;YACjE,WAAW,UAAU,CAAC,OAAO,iBAAiB,KAAK,CAAC,mBAAmB,EAAE,CAC5E,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACxD,CAAC;IAED,0EAA0E;IAC1E,4EAA4E;IAC5E,eAAe;IACf,IAAI,UAAU,CAAC,OAAO;QAAE,OAAO,aAAa,CAAC;IAC7C,IAAI,KAAK,CAAC,mBAAmB;QAAE,OAAO,cAAc,CAAC;IACrD,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One Cursor engine turn — the SDK slice of the Cursor harness, behind the
|
|
3
|
+
* turn runtime's contract (`harness/types.ts`).
|
|
4
|
+
*
|
|
5
|
+
* `runCursorTurn` is what `adapter.ts`'s `runTurn` delegates to: the HITL
|
|
6
|
+
* gate, the agent (parked, created or resumed), the prompt, the stream, the
|
|
7
|
+
* turn boundary, `run.wait()` and its recovery spines, and its own teardown
|
|
8
|
+
* (the denial watcher, the gate, the OTel span, and what becomes of the agent
|
|
9
|
+
* handle). Everything else about a turn is the runtime's
|
|
10
|
+
* (`harness/run-turn.ts`): the resolution phases, the persist chokepoint, the
|
|
11
|
+
* watchdog, the cost cap, the interruption table, the completion epilogue,
|
|
12
|
+
* the lock.
|
|
13
|
+
*
|
|
14
|
+
* This module is where `@cursor/sdk` enters the adapter's graph (through
|
|
15
|
+
* `turn-setup.ts` and its siblings), which is WHY it is a separate module
|
|
16
|
+
* from `adapter.ts` and is loaded there with a dynamic import inside `boot`:
|
|
17
|
+
* the adapter's HTTP/2 interceptor must patch `node:http2` before the SDK
|
|
18
|
+
* (and, through it, `@connectrpc/connect-node`) is first imported, and the
|
|
19
|
+
* composition roots import `adapter.ts` before they boot it. Nothing outside
|
|
20
|
+
* `adapter.ts` imports this module.
|
|
21
|
+
*
|
|
22
|
+
* Never throws out of `runCursorTurn` (an SDK failure is `failed` with the
|
|
23
|
+
* classifier's sentence; an unexpected exception is `failed` on the
|
|
24
|
+
* `internal` surface; a `CancelledFailure` never exists here), never branches
|
|
25
|
+
* on why `stopSignal` aborted, never writes a phase or a terminal copy, never
|
|
26
|
+
* imports `@temporalio/*` (`__tests__/adapter-is-temporal-free.test.ts`).
|
|
27
|
+
*
|
|
28
|
+
* Engine disposition, one rule per outcome (Q-S2-6): the agent is PARKED
|
|
29
|
+
* for the session's next turn on every exit but a failure — `completed`,
|
|
30
|
+
* `cancelled`, `awaiting_approval` and `interrupted` alike (a wedged handle
|
|
31
|
+
* after a stall is caught by the poisoned-handle recovery on the next turn;
|
|
32
|
+
* before S2 a pause, a shutdown and a stall dropped the handle, leaking the
|
|
33
|
+
* executor lease). A `failed` turn keeps the orchestrator's three
|
|
34
|
+
* dispositions: an engine-reported failure parks (a bad key is not a bad
|
|
35
|
+
* handle), a user-actionable failure closes, an internal failure drops.
|
|
36
|
+
*
|
|
37
|
+
* Extracted from `index.ts` `executeCursorInner` at S2 M3b and moved out of
|
|
38
|
+
* `adapter.ts` at S2 M5; the seventeen hermetic goldens under `__tests__/hermetic/`
|
|
39
|
+
* pin the result byte for byte.
|
|
40
|
+
*/
|
|
41
|
+
import type { TurnInput, TurnOutcome, TurnSink } from "../../harness/types.js";
|
|
42
|
+
import { type CursorAdapterConfig } from "./turn-setup.js";
|
|
43
|
+
export declare function runCursorTurn(input: TurnInput, sink: TurnSink, config: CursorAdapterConfig): Promise<TurnOutcome>;
|