@stigmer/runner 3.10.0 → 3.11.1-dev.20260812192248
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/README.md +14 -1
- package/dist/.build-fingerprint +1 -1
- package/dist/activities/call-llm.js +9 -10
- package/dist/activities/call-llm.js.map +1 -1
- package/dist/activities/classify-tool-approvals.d.ts +2 -1
- package/dist/activities/classify-tool-approvals.js +28 -2
- package/dist/activities/classify-tool-approvals.js.map +1 -1
- package/dist/activities/discover-mcp-server.d.ts +39 -0
- package/dist/activities/discover-mcp-server.js +165 -28
- package/dist/activities/discover-mcp-server.js.map +1 -1
- package/dist/activities/emit-event.d.ts +14 -2
- package/dist/activities/emit-event.js +52 -17
- package/dist/activities/emit-event.js.map +1 -1
- package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.d.ts +8 -0
- package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js +1 -1
- package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js.map +1 -1
- package/dist/activities/execute-cursor/approval-state.d.ts +28 -2
- package/dist/activities/execute-cursor/approval-state.js +7 -1
- package/dist/activities/execute-cursor/approval-state.js.map +1 -1
- package/dist/activities/execute-cursor/attachment-resolver.d.ts +14 -0
- package/dist/activities/execute-cursor/attachment-resolver.js +18 -4
- package/dist/activities/execute-cursor/attachment-resolver.js.map +1 -1
- package/dist/activities/execute-cursor/blueprint-resolver.d.ts +1 -9
- package/dist/activities/execute-cursor/blueprint-resolver.js +6 -22
- package/dist/activities/execute-cursor/blueprint-resolver.js.map +1 -1
- package/dist/activities/execute-cursor/env-resolver.js +3 -1
- package/dist/activities/execute-cursor/env-resolver.js.map +1 -1
- package/dist/activities/execute-cursor/error-classifier.d.ts +59 -3
- package/dist/activities/execute-cursor/error-classifier.js +115 -6
- package/dist/activities/execute-cursor/error-classifier.js.map +1 -1
- package/dist/activities/execute-cursor/extract-structured-output.d.ts +29 -0
- package/dist/activities/execute-cursor/extract-structured-output.js +58 -0
- package/dist/activities/execute-cursor/extract-structured-output.js.map +1 -0
- package/dist/activities/execute-cursor/hook-script.d.ts +14 -3
- package/dist/activities/execute-cursor/hook-script.js +72 -10
- package/dist/activities/execute-cursor/hook-script.js.map +1 -1
- package/dist/activities/execute-cursor/index.d.ts +51 -11
- package/dist/activities/execute-cursor/index.js +177 -93
- package/dist/activities/execute-cursor/index.js.map +1 -1
- package/dist/activities/execute-cursor/mcp-resolver.d.ts +24 -1
- package/dist/activities/execute-cursor/mcp-resolver.js +5 -2
- package/dist/activities/execute-cursor/mcp-resolver.js.map +1 -1
- package/dist/activities/execute-cursor/model-pricing-data.d.ts +2 -0
- package/dist/activities/execute-cursor/model-pricing-data.js +13 -3
- package/dist/activities/execute-cursor/model-pricing-data.js.map +1 -1
- package/dist/activities/execute-cursor/prompt-builder.d.ts +51 -4
- package/dist/activities/execute-cursor/prompt-builder.js +49 -7
- package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
- package/dist/activities/execute-cursor/turn-recovery.d.ts +52 -0
- package/dist/activities/execute-cursor/turn-recovery.js +193 -0
- package/dist/activities/execute-cursor/turn-recovery.js.map +1 -0
- package/dist/activities/execute-cursor/turn-stream.js +4 -1
- package/dist/activities/execute-cursor/turn-stream.js.map +1 -1
- package/dist/activities/execute-deep-agent/attachment-injector.d.ts +18 -1
- package/dist/activities/execute-deep-agent/attachment-injector.js +68 -23
- package/dist/activities/execute-deep-agent/attachment-injector.js.map +1 -1
- package/dist/activities/execute-deep-agent/environment.js +3 -1
- package/dist/activities/execute-deep-agent/environment.js.map +1 -1
- package/dist/activities/execute-deep-agent/index.js +15 -0
- package/dist/activities/execute-deep-agent/index.js.map +1 -1
- package/dist/activities/execute-deep-agent/prompt-builder.d.ts +7 -7
- package/dist/activities/execute-deep-agent/prompt-builder.js +8 -2
- package/dist/activities/execute-deep-agent/prompt-builder.js.map +1 -1
- package/dist/activities/execute-deep-agent/setup.d.ts +10 -0
- package/dist/activities/execute-deep-agent/setup.js +65 -24
- package/dist/activities/execute-deep-agent/setup.js.map +1 -1
- package/dist/activities/execute-deep-agent/shell-env.d.ts +5 -1
- package/dist/activities/execute-deep-agent/shell-env.js +7 -9
- package/dist/activities/execute-deep-agent/shell-env.js.map +1 -1
- package/dist/activities/execute-deep-agent/subagent-transformer.d.ts +18 -1
- package/dist/activities/execute-deep-agent/subagent-transformer.js +15 -2
- package/dist/activities/execute-deep-agent/subagent-transformer.js.map +1 -1
- package/dist/activities/execute-deep-agent/subagent-wiring.d.ts +27 -6
- package/dist/activities/execute-deep-agent/subagent-wiring.js +26 -5
- package/dist/activities/execute-deep-agent/subagent-wiring.js.map +1 -1
- package/dist/activities/hydrate-workflow-execution.js +8 -3
- package/dist/activities/hydrate-workflow-execution.js.map +1 -1
- package/dist/activities/run-command.d.ts +5 -2
- package/dist/activities/run-command.js +22 -10
- package/dist/activities/run-command.js.map +1 -1
- package/dist/activities/run-env.d.ts +40 -0
- package/dist/activities/run-env.js +66 -0
- package/dist/activities/run-env.js.map +1 -0
- package/dist/activities/workflow-event-activities.d.ts +28 -10
- package/dist/activities/workflow-event-activities.js +87 -58
- package/dist/activities/workflow-event-activities.js.map +1 -1
- package/dist/bootstrap.js +5 -0
- package/dist/bootstrap.js.map +1 -1
- package/dist/claimcheck/payload-codec.js +21 -1
- package/dist/claimcheck/payload-codec.js.map +1 -1
- package/dist/client/stigmer-client.d.ts +83 -21
- package/dist/client/stigmer-client.js +106 -29
- package/dist/client/stigmer-client.js.map +1 -1
- package/dist/encryption/config.d.ts +64 -0
- package/dist/encryption/config.js +108 -0
- package/dist/encryption/config.js.map +1 -0
- package/dist/encryption/index.d.ts +3 -0
- package/dist/encryption/index.js +3 -0
- package/dist/encryption/index.js.map +1 -0
- package/dist/encryption/payload-codec.d.ts +41 -0
- package/dist/encryption/payload-codec.js +130 -0
- package/dist/encryption/payload-codec.js.map +1 -0
- package/dist/middleware/index.d.ts +3 -0
- package/dist/middleware/index.js +7 -0
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/path-normalization.d.ts +57 -0
- package/dist/middleware/path-normalization.js +109 -0
- package/dist/middleware/path-normalization.js.map +1 -0
- package/dist/middleware/types.d.ts +8 -0
- package/dist/payload-codecs.d.ts +17 -0
- package/dist/payload-codecs.js +42 -0
- package/dist/payload-codecs.js.map +1 -0
- package/dist/preflight.d.ts +31 -0
- package/dist/preflight.js +43 -0
- package/dist/preflight.js.map +1 -1
- package/dist/runner-manager.js +21 -17
- package/dist/runner-manager.js.map +1 -1
- package/dist/runner.js +11 -18
- package/dist/runner.js.map +1 -1
- package/dist/shared/approval-policy.d.ts +9 -3
- package/dist/shared/approval-policy.js +15 -6
- package/dist/shared/approval-policy.js.map +1 -1
- package/dist/shared/artifact-storage.d.ts +23 -1
- package/dist/shared/artifact-storage.js +51 -10
- package/dist/shared/artifact-storage.js.map +1 -1
- package/dist/shared/attachment-naming.d.ts +53 -0
- package/dist/shared/attachment-naming.js +59 -0
- package/dist/shared/attachment-naming.js.map +1 -0
- package/dist/shared/caller-identity.d.ts +23 -2
- package/dist/shared/caller-identity.js +36 -5
- package/dist/shared/caller-identity.js.map +1 -1
- package/dist/shared/channel-attachment.js +1 -0
- package/dist/shared/channel-attachment.js.map +1 -1
- package/dist/shared/checkpointer/http-saver.d.ts +26 -1
- package/dist/shared/checkpointer/http-saver.js +54 -8
- package/dist/shared/checkpointer/http-saver.js.map +1 -1
- package/dist/shared/conversation-attachment.js +1 -0
- package/dist/shared/conversation-attachment.js.map +1 -1
- package/dist/shared/conversation-catchup.d.ts +9 -2
- package/dist/shared/conversation-catchup.js +39 -6
- package/dist/shared/conversation-catchup.js.map +1 -1
- package/dist/shared/datastore-attachment.d.ts +50 -7
- package/dist/shared/datastore-attachment.js +93 -11
- package/dist/shared/datastore-attachment.js.map +1 -1
- package/dist/shared/grpc-retry.d.ts +5 -1
- package/dist/shared/grpc-retry.js +5 -1
- package/dist/shared/grpc-retry.js.map +1 -1
- package/dist/shared/http-retry.d.ts +85 -0
- package/dist/shared/http-retry.js +101 -0
- package/dist/shared/http-retry.js.map +1 -0
- package/dist/shared/llm-backend.d.ts +275 -0
- package/dist/shared/llm-backend.js +425 -0
- package/dist/shared/llm-backend.js.map +1 -0
- package/dist/shared/llm-proxy.d.ts +8 -0
- package/dist/shared/llm-proxy.js +15 -0
- package/dist/shared/llm-proxy.js.map +1 -1
- package/dist/shared/mcp-enabled-tools.d.ts +57 -0
- package/dist/shared/mcp-enabled-tools.js +86 -0
- package/dist/shared/mcp-enabled-tools.js.map +1 -0
- package/dist/shared/mcp-manager.d.ts +11 -5
- package/dist/shared/mcp-manager.js +47 -8
- package/dist/shared/mcp-manager.js.map +1 -1
- package/dist/shared/mcp-resolver.d.ts +39 -2
- package/dist/shared/mcp-resolver.js +38 -2
- package/dist/shared/mcp-resolver.js.map +1 -1
- package/dist/shared/mcp-schema-sanitizer.d.ts +70 -0
- package/dist/shared/mcp-schema-sanitizer.js +197 -0
- package/dist/shared/mcp-schema-sanitizer.js.map +1 -0
- package/dist/shared/model-client.d.ts +18 -5
- package/dist/shared/model-client.js +149 -18
- package/dist/shared/model-client.js.map +1 -1
- package/dist/shared/model-error.js +198 -5
- package/dist/shared/model-error.js.map +1 -1
- package/dist/shared/model-pricing-data.d.ts +2 -0
- package/dist/shared/model-pricing-data.js +13 -3
- package/dist/shared/model-pricing-data.js.map +1 -1
- package/dist/shared/model-registry.js +3 -2
- package/dist/shared/model-registry.js.map +1 -1
- package/dist/shared/plan-mode-permissions.d.ts +33 -0
- package/dist/shared/plan-mode-permissions.js +35 -0
- package/dist/shared/plan-mode-permissions.js.map +1 -0
- package/dist/shared/registry-endpoint.d.ts +20 -0
- package/dist/shared/registry-endpoint.js +25 -0
- package/dist/shared/registry-endpoint.js.map +1 -1
- package/dist/shared/runner-credential-keys.d.ts +24 -0
- package/dist/shared/runner-credential-keys.js +47 -0
- package/dist/shared/runner-credential-keys.js.map +1 -0
- package/dist/worker.d.ts +2 -1
- package/dist/worker.js +2 -4
- package/dist/worker.js.map +1 -1
- package/dist/workflow-engine/resolve.d.ts +19 -1
- package/dist/workflow-engine/resolve.js +37 -2
- package/dist/workflow-engine/resolve.js.map +1 -1
- package/dist/workflow-engine/types.d.ts +18 -0
- package/dist/workflow-engine/types.js.map +1 -1
- package/dist/workflows/call-agent-orchestrator.d.ts +9 -0
- package/dist/workflows/call-agent-orchestrator.js +1 -0
- package/dist/workflows/call-agent-orchestrator.js.map +1 -1
- package/dist/workflows/connect-mcp-server.js +9 -0
- package/dist/workflows/connect-mcp-server.js.map +1 -1
- package/dist/workflows/engine-core.js +23 -2
- package/dist/workflows/engine-core.js.map +1 -1
- package/dist/workflows/execute-from-execution.d.ts +1 -1
- package/dist/workflows/execute-from-execution.js +11 -1
- package/dist/workflows/execute-from-execution.js.map +1 -1
- package/dist/workflows/types.d.ts +8 -0
- package/package.json +9 -4
- package/src/__test-utils__/__tests__/vitest-global-setup.test.ts +37 -0
- package/src/__test-utils__/vitest-global-setup.ts +50 -0
- package/src/__tests__/bootstrap.test.ts +43 -0
- package/src/__tests__/claimcheck-codec.test.ts +36 -0
- package/src/__tests__/encryption-codec.test.ts +287 -0
- package/src/__tests__/fixtures/encrypted-payload-fixture.json +15 -0
- package/src/__tests__/history-encryption-e2e.test.ts +243 -0
- package/src/__tests__/preflight.test.ts +65 -2
- package/src/activities/__tests__/call-llm.test.ts +75 -0
- package/src/activities/__tests__/classify-tool-approvals.test.ts +117 -1
- package/src/activities/__tests__/discover-mcp-server.hang.test.ts +103 -0
- package/src/activities/__tests__/discover-mcp-server.test.ts +242 -1
- package/src/activities/__tests__/error-classifier.test.ts +94 -2
- package/src/activities/__tests__/run-command.test.ts +221 -0
- package/src/activities/__tests__/workflow-event-activities.test.ts +107 -8
- package/src/activities/call-llm.ts +9 -16
- package/src/activities/classify-tool-approvals.ts +34 -4
- package/src/activities/discover-mcp-server.ts +203 -31
- package/src/activities/emit-event.ts +65 -21
- package/src/activities/execute-cursor/__test-utils__/cursor-hook-harness.ts +9 -0
- package/src/activities/execute-cursor/__tests__/approval-gate.test.ts +14 -0
- package/src/activities/execute-cursor/__tests__/attachment-resolver.test.ts +53 -0
- package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +151 -16
- package/src/activities/execute-cursor/__tests__/error-classifier-extraction.test.ts +208 -0
- package/src/activities/execute-cursor/__tests__/extract-structured-output.test.ts +120 -0
- package/src/activities/execute-cursor/__tests__/hook-script.test.ts +93 -0
- package/src/activities/execute-cursor/__tests__/mcp-resolver.test.ts +125 -0
- package/src/activities/execute-cursor/__tests__/model-pricing.test.ts +62 -1
- package/src/activities/execute-cursor/__tests__/prompt-builder-delegation.test.ts +1 -1
- package/src/activities/execute-cursor/__tests__/turn-recovery.test.ts +160 -0
- package/src/activities/execute-cursor/__tests__/turn-stream.test.ts +13 -0
- package/src/activities/execute-cursor/approval-state.ts +30 -1
- package/src/activities/execute-cursor/attachment-resolver.ts +31 -3
- package/src/activities/execute-cursor/blueprint-resolver.ts +7 -27
- package/src/activities/execute-cursor/env-resolver.ts +3 -1
- package/src/activities/execute-cursor/error-classifier.ts +131 -7
- package/src/activities/execute-cursor/extract-structured-output.ts +72 -0
- package/src/activities/execute-cursor/hook-script.ts +74 -10
- package/src/activities/execute-cursor/index.ts +209 -109
- package/src/activities/execute-cursor/mcp-resolver.ts +36 -2
- package/src/activities/execute-cursor/model-pricing-data.ts +22 -3
- package/src/activities/execute-cursor/prompt-builder.ts +85 -9
- package/src/activities/execute-cursor/turn-recovery.ts +208 -0
- package/src/activities/execute-cursor/turn-stream.ts +5 -2
- package/src/activities/execute-deep-agent/__tests__/attachment-injector.test.ts +110 -8
- package/src/activities/execute-deep-agent/__tests__/datastore-degradation.test.ts +104 -0
- package/src/activities/execute-deep-agent/__tests__/hitl-reject.test.ts +2 -0
- package/src/activities/execute-deep-agent/__tests__/hitl-resume-approve-all.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/hitl-resume-history.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/plan-mode-path-normalization.test.ts +174 -0
- package/src/activities/execute-deep-agent/__tests__/prompt-builder.test.ts +34 -5
- package/src/activities/execute-deep-agent/__tests__/sequential-gate-resume.test.ts +1 -0
- package/src/activities/execute-deep-agent/__tests__/shell-env.test.ts +24 -10
- package/src/activities/execute-deep-agent/__tests__/subagent-plan-mode-permissions.test.ts +178 -0
- package/src/activities/execute-deep-agent/__tests__/subagent-wiring.test.ts +12 -7
- package/src/activities/execute-deep-agent/attachment-injector.ts +94 -30
- package/src/activities/execute-deep-agent/environment.ts +3 -1
- package/src/activities/execute-deep-agent/index.ts +20 -0
- package/src/activities/execute-deep-agent/prompt-builder.ts +20 -10
- package/src/activities/execute-deep-agent/setup.ts +85 -29
- package/src/activities/execute-deep-agent/shell-env.ts +8 -9
- package/src/activities/execute-deep-agent/subagent-transformer.ts +30 -2
- package/src/activities/execute-deep-agent/subagent-wiring.ts +39 -6
- package/src/activities/hydrate-workflow-execution.ts +8 -3
- package/src/activities/run-command.ts +25 -12
- package/src/activities/run-env.ts +79 -0
- package/src/activities/workflow-event-activities.ts +96 -69
- package/src/bootstrap.ts +5 -0
- package/src/claimcheck/payload-codec.ts +33 -1
- package/src/client/__tests__/stigmer-client.test.ts +110 -11
- package/src/client/stigmer-client.ts +150 -37
- package/src/encryption/config.ts +155 -0
- package/src/encryption/index.ts +3 -0
- package/src/encryption/payload-codec.ts +152 -0
- package/src/middleware/__tests__/path-normalization.test.ts +140 -0
- package/src/middleware/index.ts +8 -0
- package/src/middleware/path-normalization.ts +125 -0
- package/src/middleware/types.ts +11 -0
- package/src/payload-codecs.ts +62 -0
- package/src/preflight.ts +45 -0
- package/src/runner-manager.ts +26 -26
- package/src/runner.ts +12 -27
- package/src/shared/__tests__/approval-policy.test.ts +82 -39
- package/src/shared/__tests__/artifact-storage.test.ts +145 -2
- package/src/shared/__tests__/attachment-naming.test.ts +159 -0
- package/src/shared/__tests__/bedrock-adapter.test.ts +213 -0
- package/src/shared/__tests__/bedrock-seam.test.ts +390 -0
- package/src/shared/__tests__/caller-identity.test.ts +25 -0
- package/src/shared/__tests__/channel-attachment.test.ts +1 -1
- package/src/shared/__tests__/connect-backfill.test.ts +1 -0
- package/src/shared/__tests__/conversation-attachment.test.ts +1 -1
- package/src/shared/__tests__/conversation-catchup.test.ts +24 -0
- package/src/shared/__tests__/datastore-attachment.test.ts +129 -1
- package/src/shared/__tests__/foundry-adapter.test.ts +276 -0
- package/src/shared/__tests__/foundry-seam.test.ts +482 -0
- package/src/shared/__tests__/http-retry.test.ts +68 -0
- package/src/shared/__tests__/llm-backend.test.ts +616 -0
- package/src/shared/__tests__/mcp-enabled-tools.test.ts +86 -0
- package/src/shared/__tests__/mcp-manager.test.ts +137 -15
- package/src/shared/__tests__/mcp-resolver.test.ts +146 -3
- package/src/shared/__tests__/mcp-schema-sanitizer.test.ts +267 -0
- package/src/shared/__tests__/model-client.test.ts +200 -0
- package/src/shared/__tests__/model-error.test.ts +289 -1
- package/src/shared/__tests__/model-pricing.test.ts +62 -2
- package/src/shared/__tests__/model-registry.test.ts +22 -0
- package/src/shared/__tests__/synthesized-attachment.test.ts +1 -0
- package/src/shared/__tests__/vertex-adapter.test.ts +169 -0
- package/src/shared/__tests__/vertex-seam.test.ts +295 -0
- package/src/shared/approval-policy.ts +14 -7
- package/src/shared/artifact-storage.ts +75 -10
- package/src/shared/attachment-naming.ts +78 -0
- package/src/shared/caller-identity.ts +40 -5
- package/src/shared/channel-attachment.ts +1 -0
- package/src/shared/checkpointer/__tests__/http-saver.test.ts +196 -1
- package/src/shared/checkpointer/http-saver.ts +71 -8
- package/src/shared/conversation-attachment.ts +1 -0
- package/src/shared/conversation-catchup.ts +39 -6
- package/src/shared/datastore-attachment.ts +106 -11
- package/src/shared/grpc-retry.ts +5 -1
- package/src/shared/http-retry.ts +139 -0
- package/src/shared/llm-backend.ts +544 -0
- package/src/shared/llm-proxy.ts +15 -0
- package/src/shared/mcp-enabled-tools.ts +105 -0
- package/src/shared/mcp-manager.ts +56 -8
- package/src/shared/mcp-resolver.ts +73 -2
- package/src/shared/mcp-schema-sanitizer.ts +224 -0
- package/src/shared/model-client.ts +179 -19
- package/src/shared/model-error.ts +222 -4
- package/src/shared/model-pricing-data.ts +22 -3
- package/src/shared/model-registry.ts +7 -2
- package/src/shared/plan-mode-permissions.ts +37 -0
- package/src/shared/registry-endpoint.ts +27 -0
- package/src/shared/runner-credential-keys.ts +46 -0
- package/src/worker.ts +4 -5
- package/src/workflow-engine/__tests__/tasks/emit-event.test.ts +127 -49
- package/src/workflow-engine/resolve.ts +48 -2
- package/src/workflow-engine/types.ts +18 -0
- package/src/workflows/__tests__/connect-mcp-server.test.ts +25 -0
- package/src/workflows/__tests__/execute-serverless-workflow.test.ts +68 -2
- package/src/workflows/call-agent-orchestrator.ts +10 -0
- package/src/workflows/connect-mcp-server.ts +9 -0
- package/src/workflows/engine-core.ts +23 -2
- package/src/workflows/execute-from-execution.ts +12 -2
- package/src/workflows/types.ts +8 -0
- package/dist/activities/execute-cursor/mcp-config.d.ts +0 -30
- package/dist/activities/execute-cursor/mcp-config.js +0 -39
- package/dist/activities/execute-cursor/mcp-config.js.map +0 -1
- package/src/activities/execute-cursor/mcp-config.ts +0 -66
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* 3. Surface isRetryable for future workflow-level retry decisions
|
|
8
8
|
*
|
|
9
9
|
* Error detail can come from several sources (in priority order):
|
|
10
|
-
* -
|
|
11
|
-
*
|
|
10
|
+
* - Structured fields, either from a thrown CursorSdkError or lifted from a
|
|
11
|
+
* structured run.wait() error value (highest fidelity)
|
|
12
|
+
* - run.wait() error text (SDK-provided string, often bare/generic)
|
|
12
13
|
* - SDKStatusMessage with status "ERROR" from the stream
|
|
13
14
|
* - ConnectError captured from process unhandledRejection
|
|
14
15
|
* - Text extracted from the failing run.conversation() turn
|
|
@@ -28,7 +29,8 @@ export interface ClassifiedError {
|
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
30
31
|
* Structured fields lifted from a thrown CursorSdkError (errors.d.ts:
|
|
31
|
-
* { code, status, isRetryable, cause, endpoint, requestId, operation })
|
|
32
|
+
* { code, status, isRetryable, cause, endpoint, requestId, operation }) or
|
|
33
|
+
* from a structured run.wait() error value (see extractRunErrorSources).
|
|
32
34
|
* Only the fields used for classification are retained.
|
|
33
35
|
*/
|
|
34
36
|
export interface SdkErrorFields {
|
|
@@ -36,6 +38,60 @@ export interface SdkErrorFields {
|
|
|
36
38
|
status?: number;
|
|
37
39
|
message?: string;
|
|
38
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Error detail lifted from a run.wait() result, split by fidelity: structured
|
|
43
|
+
* values land in sdkError, plain text in sdkResultFields. At most one of the
|
|
44
|
+
* two is set; both undefined means the result carried nothing usable and the
|
|
45
|
+
* classifier's lower-priority sources should decide.
|
|
46
|
+
*/
|
|
47
|
+
export interface RunErrorSources {
|
|
48
|
+
sdkError: SdkErrorFields | undefined;
|
|
49
|
+
sdkResultFields: string | undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Lift error detail from a run.wait() result whose status is "error".
|
|
53
|
+
*
|
|
54
|
+
* The SDK types RunResult.result as `string`, but structured values (Error
|
|
55
|
+
* instances, { code, message } objects) have been observed at runtime, both
|
|
56
|
+
* in `result` and in the undeclared error/message/reason fields (oss#299).
|
|
57
|
+
* A bare String() on those yields "[object Object]", which both destroys the
|
|
58
|
+
* message users see and — worse — shadows the lower-priority classifier
|
|
59
|
+
* sources (stream, rejection, conversation introspection) that often hold
|
|
60
|
+
* the real reason.
|
|
61
|
+
*
|
|
62
|
+
* Walks the candidate fields in order and answers from the FIRST one that
|
|
63
|
+
* yields usable content: strings keep flowing to the string channel
|
|
64
|
+
* (sdkResultFields), structured values are lifted into the same structured
|
|
65
|
+
* channel a thrown CursorSdkError uses (sdkError), and hopeless values are
|
|
66
|
+
* skipped so a later candidate — or the classifier's fallback sources — can
|
|
67
|
+
* win. (The previous `??` chain stopped at the first non-nullish value, so a
|
|
68
|
+
* hopeless object or empty string hid usable text one field later.)
|
|
69
|
+
*
|
|
70
|
+
* Deliberately NO JSON.stringify fallback for unrecognized object shapes:
|
|
71
|
+
* the error arm already logs the raw result in full server-side, and a JSON
|
|
72
|
+
* blob shown to the user would shadow the introspection sources that exist
|
|
73
|
+
* precisely to recover the real reason.
|
|
74
|
+
*/
|
|
75
|
+
export declare function extractRunErrorSources(result: unknown): RunErrorSources;
|
|
76
|
+
/**
|
|
77
|
+
* Stable lead sentence of the detail-free fallback error (all five detail
|
|
78
|
+
* channels empty — empirically the shape of Cursor-side capacity rejections,
|
|
79
|
+
* oss#492). This is what end users read in embedded surfaces, so it must be
|
|
80
|
+
* actionable product copy, not a diagnostic; the diagnostic context follows
|
|
81
|
+
* in a parenthetical. Mirrors the COST_LIMIT_ERROR_PREFIX convention: a
|
|
82
|
+
* consumer that needs to recognize this failure can match on the prefix.
|
|
83
|
+
* Do not reword without checking consumers, and NEVER include the phrase
|
|
84
|
+
* "retry or resume" — sdk-react's isInterruptedError (MessageThread.tsx)
|
|
85
|
+
* reframes any error containing it as a neutral resumable notice instead of
|
|
86
|
+
* a failure alert.
|
|
87
|
+
*/
|
|
88
|
+
export declare const DETAIL_FREE_FALLBACK_USER_PREFIX = "The model may be temporarily overloaded \u2014 please retry, or switch to a different model.";
|
|
89
|
+
/**
|
|
90
|
+
* Stable lead sentence of the transport-timeout fallback error (0 messages,
|
|
91
|
+
* ~30s duration — the SDK's default timeout with no stream established).
|
|
92
|
+
* Same user-facing rules as DETAIL_FREE_FALLBACK_USER_PREFIX above.
|
|
93
|
+
*/
|
|
94
|
+
export declare const TRANSPORT_TIMEOUT_USER_PREFIX = "The connection to the model could not be established \u2014 please retry.";
|
|
39
95
|
interface SynthesizeErrorOpts {
|
|
40
96
|
/** Structured fields from a thrown CursorSdkError — highest-fidelity source. */
|
|
41
97
|
sdkError?: SdkErrorFields;
|
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* 3. Surface isRetryable for future workflow-level retry decisions
|
|
8
8
|
*
|
|
9
9
|
* Error detail can come from several sources (in priority order):
|
|
10
|
-
* -
|
|
11
|
-
*
|
|
10
|
+
* - Structured fields, either from a thrown CursorSdkError or lifted from a
|
|
11
|
+
* structured run.wait() error value (highest fidelity)
|
|
12
|
+
* - run.wait() error text (SDK-provided string, often bare/generic)
|
|
12
13
|
* - SDKStatusMessage with status "ERROR" from the stream
|
|
13
14
|
* - ConnectError captured from process unhandledRejection
|
|
14
15
|
* - Text extracted from the failing run.conversation() turn
|
|
@@ -18,6 +19,98 @@
|
|
|
18
19
|
* the agent was obtained via resume, the error is upgraded to "agent-stale"
|
|
19
20
|
* so that poisoned-handle recovery fires.
|
|
20
21
|
*/
|
|
22
|
+
/**
|
|
23
|
+
* What String() produces for any plain object. Carries zero signal, so it is
|
|
24
|
+
* refused everywhere: extraction never emits it, and classifyFromSources
|
|
25
|
+
* treats it as absent should any other producer leak it through.
|
|
26
|
+
*/
|
|
27
|
+
const OBJECT_JUNK_STRING = "[object Object]";
|
|
28
|
+
const NO_RUN_ERROR_SOURCES = {
|
|
29
|
+
sdkError: undefined,
|
|
30
|
+
sdkResultFields: undefined,
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Lift error detail from a run.wait() result whose status is "error".
|
|
34
|
+
*
|
|
35
|
+
* The SDK types RunResult.result as `string`, but structured values (Error
|
|
36
|
+
* instances, { code, message } objects) have been observed at runtime, both
|
|
37
|
+
* in `result` and in the undeclared error/message/reason fields (oss#299).
|
|
38
|
+
* A bare String() on those yields "[object Object]", which both destroys the
|
|
39
|
+
* message users see and — worse — shadows the lower-priority classifier
|
|
40
|
+
* sources (stream, rejection, conversation introspection) that often hold
|
|
41
|
+
* the real reason.
|
|
42
|
+
*
|
|
43
|
+
* Walks the candidate fields in order and answers from the FIRST one that
|
|
44
|
+
* yields usable content: strings keep flowing to the string channel
|
|
45
|
+
* (sdkResultFields), structured values are lifted into the same structured
|
|
46
|
+
* channel a thrown CursorSdkError uses (sdkError), and hopeless values are
|
|
47
|
+
* skipped so a later candidate — or the classifier's fallback sources — can
|
|
48
|
+
* win. (The previous `??` chain stopped at the first non-nullish value, so a
|
|
49
|
+
* hopeless object or empty string hid usable text one field later.)
|
|
50
|
+
*
|
|
51
|
+
* Deliberately NO JSON.stringify fallback for unrecognized object shapes:
|
|
52
|
+
* the error arm already logs the raw result in full server-side, and a JSON
|
|
53
|
+
* blob shown to the user would shadow the introspection sources that exist
|
|
54
|
+
* precisely to recover the real reason.
|
|
55
|
+
*/
|
|
56
|
+
export function extractRunErrorSources(result) {
|
|
57
|
+
if (result === null || typeof result !== "object")
|
|
58
|
+
return NO_RUN_ERROR_SOURCES;
|
|
59
|
+
const r = result;
|
|
60
|
+
for (const candidate of [r.result, r.error, r.message, r.reason]) {
|
|
61
|
+
const extracted = extractFromCandidate(candidate);
|
|
62
|
+
if (extracted)
|
|
63
|
+
return extracted;
|
|
64
|
+
}
|
|
65
|
+
return NO_RUN_ERROR_SOURCES;
|
|
66
|
+
}
|
|
67
|
+
function extractFromCandidate(v) {
|
|
68
|
+
if (v == null)
|
|
69
|
+
return undefined;
|
|
70
|
+
if (typeof v === "string") {
|
|
71
|
+
if (v.length === 0 || v === OBJECT_JUNK_STRING)
|
|
72
|
+
return undefined;
|
|
73
|
+
return { sdkError: undefined, sdkResultFields: v };
|
|
74
|
+
}
|
|
75
|
+
if (typeof v === "object") {
|
|
76
|
+
// Covers Error instances too: their message (and, on SDK/Node error
|
|
77
|
+
// shapes, code/status) are readable as plain properties.
|
|
78
|
+
const o = v;
|
|
79
|
+
const fields = {};
|
|
80
|
+
if (typeof o.code === "string" && o.code.length > 0)
|
|
81
|
+
fields.code = o.code;
|
|
82
|
+
if (typeof o.status === "number")
|
|
83
|
+
fields.status = o.status;
|
|
84
|
+
if (typeof o.message === "string" && o.message.length > 0)
|
|
85
|
+
fields.message = o.message;
|
|
86
|
+
if (fields.code !== undefined || fields.status !== undefined || fields.message !== undefined) {
|
|
87
|
+
return { sdkError: fields, sdkResultFields: undefined };
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
// Remaining primitives (number, boolean, ...) stringify losslessly.
|
|
92
|
+
const text = String(v);
|
|
93
|
+
return text.length > 0 ? { sdkError: undefined, sdkResultFields: text } : undefined;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Stable lead sentence of the detail-free fallback error (all five detail
|
|
97
|
+
* channels empty — empirically the shape of Cursor-side capacity rejections,
|
|
98
|
+
* oss#492). This is what end users read in embedded surfaces, so it must be
|
|
99
|
+
* actionable product copy, not a diagnostic; the diagnostic context follows
|
|
100
|
+
* in a parenthetical. Mirrors the COST_LIMIT_ERROR_PREFIX convention: a
|
|
101
|
+
* consumer that needs to recognize this failure can match on the prefix.
|
|
102
|
+
* Do not reword without checking consumers, and NEVER include the phrase
|
|
103
|
+
* "retry or resume" — sdk-react's isInterruptedError (MessageThread.tsx)
|
|
104
|
+
* reframes any error containing it as a neutral resumable notice instead of
|
|
105
|
+
* a failure alert.
|
|
106
|
+
*/
|
|
107
|
+
export const DETAIL_FREE_FALLBACK_USER_PREFIX = "The model may be temporarily overloaded — please retry, or switch to a different model.";
|
|
108
|
+
/**
|
|
109
|
+
* Stable lead sentence of the transport-timeout fallback error (0 messages,
|
|
110
|
+
* ~30s duration — the SDK's default timeout with no stream established).
|
|
111
|
+
* Same user-facing rules as DETAIL_FREE_FALLBACK_USER_PREFIX above.
|
|
112
|
+
*/
|
|
113
|
+
export const TRANSPORT_TIMEOUT_USER_PREFIX = "The connection to the model could not be established — please retry.";
|
|
21
114
|
const AUTH_PATTERNS = [
|
|
22
115
|
"unauthenticated", "unauthorized", "401", "forbidden",
|
|
23
116
|
"permission_denied", "invalid api key", "not logged in",
|
|
@@ -117,7 +210,11 @@ function classifyFromSources(opts) {
|
|
|
117
210
|
}
|
|
118
211
|
}
|
|
119
212
|
if (opts.sdkResultFields) {
|
|
120
|
-
|
|
213
|
+
// "Cursor run failed" is the SDK's bare generic; "[object Object]" is
|
|
214
|
+
// String()-coerced junk from any producer that bypassed the shape-aware
|
|
215
|
+
// extraction. Neither carries signal — fall through to better sources.
|
|
216
|
+
const isBareGeneric = opts.sdkResultFields === "Cursor run failed"
|
|
217
|
+
|| opts.sdkResultFields === OBJECT_JUNK_STRING;
|
|
121
218
|
if (!isBareGeneric) {
|
|
122
219
|
const { category, retryable } = classifyText(opts.sdkResultFields);
|
|
123
220
|
return {
|
|
@@ -171,7 +268,9 @@ function classifyFromSources(opts) {
|
|
|
171
268
|
const { model, mode, agentId } = opts.fallbackContext;
|
|
172
269
|
return {
|
|
173
270
|
category: "network",
|
|
174
|
-
message:
|
|
271
|
+
message: `${TRANSPORT_TIMEOUT_USER_PREFIX} ` +
|
|
272
|
+
`(Transport timeout: ${opts.durationMs}ms, 0 messages received. ` +
|
|
273
|
+
`Model=${model}, mode=${mode}, agentId=${agentId})`,
|
|
175
274
|
retryable: true,
|
|
176
275
|
source: "fallback",
|
|
177
276
|
};
|
|
@@ -184,11 +283,21 @@ function classifyFromSources(opts) {
|
|
|
184
283
|
source: "fallback",
|
|
185
284
|
};
|
|
186
285
|
}
|
|
286
|
+
// The honest last resort: every detail channel was empty. Observed in prod
|
|
287
|
+
// only during provider capacity incidents (oss#492: Composer 2.5 degradation
|
|
288
|
+
// — the SDK rejection that carries ERROR_RESOURCE_EXHAUSTED in Cursor's IDE
|
|
289
|
+
// arrives here detail-free), so the copy leads with the capacity hypothesis
|
|
290
|
+
// hedged ("may be"), and retryable is true: the observed cause is transient
|
|
291
|
+
// by nature, and nothing gates a recovery loop on unknown+retryable. The
|
|
292
|
+
// parenthetical keeps the exact Model=/mode=/agentId= tokens for log-grep
|
|
293
|
+
// continuity and the env integration test's matcher.
|
|
187
294
|
const { model, mode, agentId } = opts.fallbackContext;
|
|
188
295
|
return {
|
|
189
296
|
category: "unknown",
|
|
190
|
-
message:
|
|
191
|
-
|
|
297
|
+
message: `${DETAIL_FREE_FALLBACK_USER_PREFIX} ` +
|
|
298
|
+
`(No error detail from the Cursor SDK. ` +
|
|
299
|
+
`Model=${model}, mode=${mode}, agentId=${agentId})`,
|
|
300
|
+
retryable: true,
|
|
192
301
|
source: "fallback",
|
|
193
302
|
};
|
|
194
303
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-classifier.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/error-classifier.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"error-classifier.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/error-classifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAgCH;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAa7C,MAAM,oBAAoB,GAAoB;IAC5C,QAAQ,EAAE,SAAS;IACnB,eAAe,EAAE,SAAS;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAe;IACpD,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,oBAAoB,CAAC;IAC/E,MAAM,CAAC,GAAG,MAAiC,CAAC;IAC5C,KAAK,MAAM,SAAS,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;QACjE,MAAM,SAAS,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;QAClD,IAAI,SAAS;YAAE,OAAO,SAAS,CAAC;IAClC,CAAC;IACD,OAAO,oBAAoB,CAAC;AAC9B,CAAC;AAED,SAAS,oBAAoB,CAAC,CAAU;IACtC,IAAI,CAAC,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IAChC,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC1B,IAAI,CAAC,CAAC,M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AC,OAAO,cAAc,GAAG,CAAC,QAAQ,YAAY,GAAG,CAAC,MAAM,eAAe,GAAG,CAAC,SAAS,GAAG,CAAC;AACvG,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,GAAoB;IAC5D,OAAO,GAAG,CAAC,QAAQ,KAAK,aAAa,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tier-2 structured-output extraction for the Cursor harness.
|
|
3
|
+
*
|
|
4
|
+
* When tier-1 text extraction (shared/extract-json.ts) cannot find JSON in
|
|
5
|
+
* the agent's free-text response, this tier asks an economy-tier LLM to
|
|
6
|
+
* extract it via withStructuredOutput (function-calling), which guarantees
|
|
7
|
+
* schema-conformant output through the API's tool-use mechanism.
|
|
8
|
+
*
|
|
9
|
+
* Lives in its own module (rather than inside execute-cursor/index.ts) so
|
|
10
|
+
* the LangChain construction path stays out of the Cursor activity's module
|
|
11
|
+
* graph until a run actually needs tier 2 — index.ts imports this module
|
|
12
|
+
* lazily at the call site, mirroring its tier-1 import, which is what
|
|
13
|
+
* bundle-slim's deferred evaluation preserves.
|
|
14
|
+
*/
|
|
15
|
+
import type { Config } from "../../config.js";
|
|
16
|
+
/**
|
|
17
|
+
* Extract structured data from an agent's free-text response using an
|
|
18
|
+
* economy-tier LLM with withStructuredOutput (function-calling).
|
|
19
|
+
*
|
|
20
|
+
* Construction (registry-id resolution, provider inference, proxy wiring) is
|
|
21
|
+
* delegated to the shared buildChatModel so the economy model's registry id
|
|
22
|
+
* is always resolved to a provider API id before the call.
|
|
23
|
+
*
|
|
24
|
+
* Throws when no LLM is reachable (no proxy and no credential path for the
|
|
25
|
+
* extraction model's provider) — the caller treats any throw here as "tier 2
|
|
26
|
+
* unavailable", logs it, and returns the agent's text without structured
|
|
27
|
+
* output, so the failure mode is a diagnosable log line, never a lost run.
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractStructuredOutput(agentResponse: string, schema: Record<string, unknown>, config: Config, primaryModel: string): Promise<unknown | null>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tier-2 structured-output extraction for the Cursor harness.
|
|
3
|
+
*
|
|
4
|
+
* When tier-1 text extraction (shared/extract-json.ts) cannot find JSON in
|
|
5
|
+
* the agent's free-text response, this tier asks an economy-tier LLM to
|
|
6
|
+
* extract it via withStructuredOutput (function-calling), which guarantees
|
|
7
|
+
* schema-conformant output through the API's tool-use mechanism.
|
|
8
|
+
*
|
|
9
|
+
* Lives in its own module (rather than inside execute-cursor/index.ts) so
|
|
10
|
+
* the LangChain construction path stays out of the Cursor activity's module
|
|
11
|
+
* graph until a run actually needs tier 2 — index.ts imports this module
|
|
12
|
+
* lazily at the call site, mirroring its tier-1 import, which is what
|
|
13
|
+
* bundle-slim's deferred evaluation preserves.
|
|
14
|
+
*/
|
|
15
|
+
import { getEconomyModel } from "../../shared/model-registry.js";
|
|
16
|
+
import { buildChatModel } from "../../shared/model-client.js";
|
|
17
|
+
import { checkDirectCredentials } from "../../shared/llm-backend.js";
|
|
18
|
+
import { tryInferProvider } from "../../shared/llm-proxy.js";
|
|
19
|
+
import { jsonSchemaToZod } from "../../shared/json-schema-to-zod.js";
|
|
20
|
+
/**
|
|
21
|
+
* Extract structured data from an agent's free-text response using an
|
|
22
|
+
* economy-tier LLM with withStructuredOutput (function-calling).
|
|
23
|
+
*
|
|
24
|
+
* Construction (registry-id resolution, provider inference, proxy wiring) is
|
|
25
|
+
* delegated to the shared buildChatModel so the economy model's registry id
|
|
26
|
+
* is always resolved to a provider API id before the call.
|
|
27
|
+
*
|
|
28
|
+
* Throws when no LLM is reachable (no proxy and no credential path for the
|
|
29
|
+
* extraction model's provider) — the caller treats any throw here as "tier 2
|
|
30
|
+
* unavailable", logs it, and returns the agent's text without structured
|
|
31
|
+
* output, so the failure mode is a diagnosable log line, never a lost run.
|
|
32
|
+
*/
|
|
33
|
+
export async function extractStructuredOutput(agentResponse, schema, config, primaryModel) {
|
|
34
|
+
const extractionModel = await getEconomyModel(primaryModel);
|
|
35
|
+
const proxyEndpoint = config.proxyEndpoint ?? undefined;
|
|
36
|
+
if (!proxyEndpoint) {
|
|
37
|
+
const provider = tryInferProvider(extractionModel);
|
|
38
|
+
const missing = provider === null ? null : checkDirectCredentials(provider);
|
|
39
|
+
if (missing !== null) {
|
|
40
|
+
throw new Error(`Structured-output extraction needs the ${provider} model ` +
|
|
41
|
+
`'${extractionModel}' but has no credential path. ${missing}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const { model: llm } = await buildChatModel({
|
|
45
|
+
modelName: extractionModel,
|
|
46
|
+
proxyEndpoint,
|
|
47
|
+
stigmerToken: config.stigmerToken ?? undefined,
|
|
48
|
+
maxTokens: 4096,
|
|
49
|
+
});
|
|
50
|
+
const zodSchema = jsonSchemaToZod(schema);
|
|
51
|
+
const structured = llm.withStructuredOutput(zodSchema);
|
|
52
|
+
const result = await structured.invoke([
|
|
53
|
+
{ role: "system", content: "Extract the structured data from the agent's response. Return only the data that matches the schema." },
|
|
54
|
+
{ role: "user", content: agentResponse },
|
|
55
|
+
]);
|
|
56
|
+
return result ?? null;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=extract-structured-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-structured-output.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/extract-structured-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE;;;;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ret hard-block: the agent continues, no pause.
|
|
33
33
|
* - "capture-error" — CAS staging failed, write kept on the deny-gate.
|
|
34
34
|
* - "fail-closed" — approval state file missing, everything gated denies.
|
|
35
|
+
* - "disabled" — enabled_tools manifest exclusion (issue #350): the
|
|
36
|
+
* agent continues, no pause, permanent for the run.
|
|
35
37
|
* Only approval-kind records carry the captured tool_input: a secret write's
|
|
36
38
|
* content must never be persisted (DD-26), a capture-error's content is
|
|
37
39
|
* UNCLASSIFIED (the staging error means secret classification may never have
|
|
@@ -84,8 +86,16 @@
|
|
|
84
86
|
* set, allow the rest" — matching the native harness and avoiding denial of
|
|
85
87
|
* auto-approved MCP tools (which are absent from mcpToolPolicies):
|
|
86
88
|
* 0. Scope guard: not the runner's own agent → allow (never touch the ledger)
|
|
87
|
-
* 1. Missing state file → deny (fail-closed)
|
|
88
|
-
*
|
|
89
|
+
* 1. Missing state file → deny (fail-closed)
|
|
90
|
+
* 1a. beforeMCPExecution event → tool excluded by the server's
|
|
91
|
+
* mcpServerEnabledTools allow-list → record kind "disabled", deny.
|
|
92
|
+
* Deliberately BEFORE autoApproveAll and the grant checks: enabled_tools
|
|
93
|
+
* is a capability manifest, not an approval gate (issue #350) — no bypass
|
|
94
|
+
* may resurrect a disabled tool, and no human may be offered "approve" on
|
|
95
|
+
* one. Server-scoped via the payload's mcp_server_name; an absent slug in
|
|
96
|
+
* the map means unrestricted.
|
|
97
|
+
* 1b. autoApproveAll (the pre-armed spec.auto_approve_all global bypass) →
|
|
98
|
+
* allow
|
|
89
99
|
* 2. beforeMCPExecution event → MCP tool present in mcpToolPolicies
|
|
90
100
|
* (require-approval):
|
|
91
101
|
* a. name token in approvedGrantTokens → allow (reinvocation grant)
|
|
@@ -117,7 +127,8 @@
|
|
|
117
127
|
*
|
|
118
128
|
* From the pointer the script reads the current turn's approval-state file (the
|
|
119
129
|
* single source of truth for the dynamic inputs: autoApproveAll, leasedCategories,
|
|
120
|
-
* mcpToolPolicies, approvedGrantTokens), denial ledger,
|
|
130
|
+
* mcpToolPolicies, mcpServerEnabledTools, approvedGrantTokens), denial ledger,
|
|
131
|
+
* and runner PID. The
|
|
121
132
|
* static policy (which built-ins are gated, their categories, the salient arg
|
|
122
133
|
* fields) is baked at generation time from approval-policy.ts.
|
|
123
134
|
*
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
* - "secret" — DD-26 secret hard-block: the agent continues, no pause.
|
|
33
33
|
* - "capture-error" — CAS staging failed, write kept on the deny-gate.
|
|
34
34
|
* - "fail-closed" — approval state file missing, everything gated denies.
|
|
35
|
+
* - "disabled" — enabled_tools manifest exclusion (issue #350): the
|
|
36
|
+
* agent continues, no pause, permanent for the run.
|
|
35
37
|
* Only approval-kind records carry the captured tool_input: a secret write's
|
|
36
38
|
* content must never be persisted (DD-26), a capture-error's content is
|
|
37
39
|
* UNCLASSIFIED (the staging error means secret classification may never have
|
|
@@ -84,8 +86,16 @@
|
|
|
84
86
|
* set, allow the rest" — matching the native harness and avoiding denial of
|
|
85
87
|
* auto-approved MCP tools (which are absent from mcpToolPolicies):
|
|
86
88
|
* 0. Scope guard: not the runner's own agent → allow (never touch the ledger)
|
|
87
|
-
* 1. Missing state file → deny (fail-closed)
|
|
88
|
-
*
|
|
89
|
+
* 1. Missing state file → deny (fail-closed)
|
|
90
|
+
* 1a. beforeMCPExecution event → tool excluded by the server's
|
|
91
|
+
* mcpServerEnabledTools allow-list → record kind "disabled", deny.
|
|
92
|
+
* Deliberately BEFORE autoApproveAll and the grant checks: enabled_tools
|
|
93
|
+
* is a capability manifest, not an approval gate (issue #350) — no bypass
|
|
94
|
+
* may resurrect a disabled tool, and no human may be offered "approve" on
|
|
95
|
+
* one. Server-scoped via the payload's mcp_server_name; an absent slug in
|
|
96
|
+
* the map means unrestricted.
|
|
97
|
+
* 1b. autoApproveAll (the pre-armed spec.auto_approve_all global bypass) →
|
|
98
|
+
* allow
|
|
89
99
|
* 2. beforeMCPExecution event → MCP tool present in mcpToolPolicies
|
|
90
100
|
* (require-approval):
|
|
91
101
|
* a. name token in approvedGrantTokens → allow (reinvocation grant)
|
|
@@ -143,6 +153,21 @@ const SECRET_BLOCKED_AGENT_MESSAGE = "This file was blocked for security because
|
|
|
143
153
|
"misconfiguration, so never tell the user to change Cursor settings or enable " +
|
|
144
154
|
"hooks. Do not retry this write or attempt a workaround; the write will not be " +
|
|
145
155
|
"applied. Continue with the rest of the task.";
|
|
156
|
+
// Shown to the model when an MCP tool call is denied because the agent's
|
|
157
|
+
// enabled_tools manifest excludes the tool (issue #350). Like
|
|
158
|
+
// SECRET_BLOCKED_AGENT_MESSAGE this must NOT promise a resume — the exclusion
|
|
159
|
+
// is permanent for the run and mode-independent (it is a capability manifest,
|
|
160
|
+
// not an approval, so nothing can be granted). Same embedding constraint
|
|
161
|
+
// (single-quoted bash echo of a JSON object): no double quotes, apostrophes,
|
|
162
|
+
// or backslashes.
|
|
163
|
+
const DISABLED_TOOL_AGENT_MESSAGE = "This tool is not enabled for this agent: the MCP server exposes it, but the " +
|
|
164
|
+
"agent manifest (enabled_tools) excludes it. This is the platform capability " +
|
|
165
|
+
"manifest working as intended — it is not an error and not a Cursor " +
|
|
166
|
+
"misconfiguration, so never tell the user to change Cursor settings or enable " +
|
|
167
|
+
"hooks. Do not retry this tool or attempt a workaround; it will stay " +
|
|
168
|
+
"unavailable for this entire run. Use a different tool or adapt your plan, " +
|
|
169
|
+
"and if the task cannot proceed without it, tell the user plainly what was " +
|
|
170
|
+
"unavailable.";
|
|
146
171
|
/**
|
|
147
172
|
* Build the bash `case` arms that map an incoming hook `tool_name` to its
|
|
148
173
|
* canonical approval category. Generated from approval-policy.ts so the hook and
|
|
@@ -195,14 +220,17 @@ function buildContentDigestScript() {
|
|
|
195
220
|
* Build the inline Node.js identity extractor embedded in the hook script.
|
|
196
221
|
*
|
|
197
222
|
* Parses the hook's stdin JSON properly (the bash fallback's grep truncates
|
|
198
|
-
* string values at the first escaped quote) and emits
|
|
223
|
+
* string values at the first escaped quote) and emits NINE lines: tool_name,
|
|
199
224
|
* canonical category, coarse identity token, MCP name-token, hook_event_name
|
|
200
225
|
* (the event discriminator: `preToolUse` for built-ins, `beforeMCPExecution`
|
|
201
226
|
* for MCP), base64(JSON(tool_input)) — the authoritative pre-execution args the
|
|
202
|
-
* runner overlays onto the gated tool call for the approval preview —
|
|
227
|
+
* runner overlays onto the gated tool call for the approval preview — the
|
|
203
228
|
* CONTENT token (base64(category \n salient \n contentDigest), empty when the
|
|
204
|
-
* tool has no edit content)
|
|
205
|
-
*
|
|
229
|
+
* tool has no edit content), base64(salient), and mcp_server_name (the MCP
|
|
230
|
+
* server slug the beforeMCPExecution payload carries; empty for built-ins) —
|
|
231
|
+
* the server scope for the enabled_tools manifest arm. The token encodings
|
|
232
|
+
* must stay byte-identical to grantToken()/contentToken() in
|
|
233
|
+
* approval-state.ts.
|
|
206
234
|
*
|
|
207
235
|
* Authored as a single-quoted bash string, so the JS must not contain single
|
|
208
236
|
* quotes. The category map, salient field list, and edit/content field lists are
|
|
@@ -233,6 +261,7 @@ function buildNodeIdentityScript() {
|
|
|
233
261
|
// is "" for a non-edit tool, in which case the content token (line 7) is "".
|
|
234
262
|
buildContentDigestScript(),
|
|
235
263
|
`const ev=typeof t.hook_event_name==="string"?t.hook_event_name:"";`,
|
|
264
|
+
`const srv=typeof t.mcp_server_name==="string"?t.mcp_server_name:"";`,
|
|
236
265
|
// Line 6 is base64(JSON(tool_input)): the AUTHORITATIVE pre-execution args
|
|
237
266
|
// the runner overlays onto the gated tool call so the approval card can show
|
|
238
267
|
// the proposed change before the user approves. Base64 keeps the bash side
|
|
@@ -241,8 +270,10 @@ function buildNodeIdentityScript() {
|
|
|
241
270
|
// grant the runner authorizes for a file edit. Line 8 is base64(salient) —
|
|
242
271
|
// the raw resource value (file path / command) capture mode needs to run
|
|
243
272
|
// `git check-ignore` on a file path; base64 keeps newlines/quotes out of the
|
|
244
|
-
// line-oriented bash parse.
|
|
245
|
-
|
|
273
|
+
// line-oriented bash parse. Line 9 is mcp_server_name — the server scope
|
|
274
|
+
// the enabled_tools manifest arm matches against mcpServerEnabledTools
|
|
275
|
+
// (a bare slug, never quoted/escaped, so it rides as a plain line).
|
|
276
|
+
`process.stdout.write(name+"\\n"+cat+"\\n"+b(cat+"\\n"+s)+"\\n"+b(name+"\\n")+"\\n"+ev+"\\n"+b(JSON.stringify(a))+"\\n"+(dig?b(cat+"\\n"+s+"\\n"+dig):"")+"\\n"+b(s)+"\\n"+srv);`,
|
|
246
277
|
].join("");
|
|
247
278
|
}
|
|
248
279
|
/**
|
|
@@ -264,7 +295,8 @@ function buildNodeIdentityScript() {
|
|
|
264
295
|
*
|
|
265
296
|
* From the pointer the script reads the current turn's approval-state file (the
|
|
266
297
|
* single source of truth for the dynamic inputs: autoApproveAll, leasedCategories,
|
|
267
|
-
* mcpToolPolicies, approvedGrantTokens), denial ledger,
|
|
298
|
+
* mcpToolPolicies, mcpServerEnabledTools, approvedGrantTokens), denial ledger,
|
|
299
|
+
* and runner PID. The
|
|
268
300
|
* static policy (which built-ins are gated, their categories, the salient arg
|
|
269
301
|
* fields) is baked at generation time from approval-policy.ts.
|
|
270
302
|
*
|
|
@@ -425,6 +457,9 @@ if [ -n "$IDENTITY" ]; then
|
|
|
425
457
|
# Raw salient (base64) — the file path / command. Capture mode decodes it to
|
|
426
458
|
# run git check-ignore on a file path.
|
|
427
459
|
SALIENT=$(printf '%s\\n' "$IDENTITY" | sed -n 8p | base64 -d 2>/dev/null || true)
|
|
460
|
+
# MCP server slug (beforeMCPExecution payloads only; empty for built-ins) —
|
|
461
|
+
# the server scope for the enabled_tools manifest arm.
|
|
462
|
+
MCP_SERVER=$(printf '%s\\n' "$IDENTITY" | sed -n 9p)
|
|
428
463
|
else
|
|
429
464
|
# Fallback when the Node binary cannot run: grep/cut extraction. Best-effort
|
|
430
465
|
# only — '"field":"[^"]*"' truncates at the first JSON-escaped quote, so the
|
|
@@ -434,6 +469,10 @@ else
|
|
|
434
469
|
# would otherwise abort the script and emit no decision.
|
|
435
470
|
TOOL_NAME=$(echo "$INPUT" | grep -o '"tool_name":"[^"]*"' | head -1 | cut -d'"' -f4 || true)
|
|
436
471
|
HOOK_EVENT=$(echo "$INPUT" | grep -o '"hook_event_name":"[^"]*"' | head -1 | cut -d'"' -f4 || true)
|
|
472
|
+
# Server slugs are plain identifiers (no JSON-escaped quotes), so the grep
|
|
473
|
+
# fallback extracts mcp_server_name reliably — the manifest arm keeps its
|
|
474
|
+
# full precision even without the Node binary.
|
|
475
|
+
MCP_SERVER=$(echo "$INPUT" | grep -o '"mcp_server_name":"[^"]*"' | head -1 | cut -d'"' -f4 || true)
|
|
437
476
|
SALIENT=""
|
|
438
477
|
for field in ${salientFields}; do
|
|
439
478
|
v=$(echo "$INPUT" | grep -o "\\"$field\\":\\"[^\\"]*\\"" | head -1 | cut -d'"' -f4 || true)
|
|
@@ -573,7 +612,30 @@ if [ "$CAPTURE_IGNORED" = "true" ] && [ "$CATEGORY" = "write" ] && [ -n "$SALIEN
|
|
|
573
612
|
fi
|
|
574
613
|
fi
|
|
575
614
|
|
|
576
|
-
# ---
|
|
615
|
+
# --- 1a. MCP capability manifest: enabled_tools (issue #350) ---
|
|
616
|
+
# Runs BEFORE the auto-approve-all shortcut and every grant check because
|
|
617
|
+
# enabled_tools is a capability manifest, not an approval gate: no bypass may
|
|
618
|
+
# resurrect a disabled tool and no human may be offered approval on one.
|
|
619
|
+
# mcpServerEnabledTools holds ONLY restricted servers (an absent slug means
|
|
620
|
+
# unrestricted, so this arm is inert for the common case). Matching is
|
|
621
|
+
# server-scoped via the payload's mcp_server_name — equal tool names on
|
|
622
|
+
# different servers cannot cross-grant — and the quoted-name membership check
|
|
623
|
+
# is exact, never a substring match. Kind "disabled": attributable,
|
|
624
|
+
# non-pausing (the model adapts, same consumer semantics as "secret"), and
|
|
625
|
+
# permanent for the run.
|
|
626
|
+
if [ "$HOOK_EVENT" = "beforeMCPExecution" ] && [ -n "$MCP_SERVER" ] && [ -n "$TOOL_NAME" ]; then
|
|
627
|
+
ENABLED_MAP=$(echo "$STATE" | grep -o '"mcpServerEnabledTools":{[^}]*}' | head -1 || true)
|
|
628
|
+
if [ -n "$ENABLED_MAP" ]; then
|
|
629
|
+
SERVER_ENABLED=$(echo "$ENABLED_MAP" | grep -o "\\"$MCP_SERVER\\":\\[[^]]*\\]" | head -1 || true)
|
|
630
|
+
if [ -n "$SERVER_ENABLED" ] && ! echo "$SERVER_ENABLED" | grep -qF "\\"$TOOL_NAME\\""; then
|
|
631
|
+
record_denial "$MCP_TOKEN" "disabled"
|
|
632
|
+
echo '{"permission":"deny","agent_message":"${DISABLED_TOOL_AGENT_MESSAGE}","user_message":"Tool not enabled for this agent: '"$TOOL_NAME"'"}'
|
|
633
|
+
exit 0
|
|
634
|
+
fi
|
|
635
|
+
fi
|
|
636
|
+
fi
|
|
637
|
+
|
|
638
|
+
# --- 1b. Auto-approve all ---
|
|
577
639
|
if echo "$STATE" | grep -q '"autoApproveAll":true'; then
|
|
578
640
|
echo '{"permission":"allow"}'
|
|
579
641
|
exit 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-script.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/hook-script.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hook-script.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/hook-script.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6GG;AAEH,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EACL,eAAe,EACf,eAAe,EACf,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;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