@stigmer/runner 3.0.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/README.md +212 -0
- package/dist/.build-fingerprint +1 -0
- package/dist/activities/call-agent-status.d.ts +37 -0
- package/dist/activities/call-agent-status.js +91 -0
- package/dist/activities/call-agent-status.js.map +1 -0
- package/dist/activities/call-agent.d.ts +25 -0
- package/dist/activities/call-agent.js +233 -0
- package/dist/activities/call-agent.js.map +1 -0
- package/dist/activities/call-eval.d.ts +50 -0
- package/dist/activities/call-eval.js +244 -0
- package/dist/activities/call-eval.js.map +1 -0
- package/dist/activities/call-function.d.ts +21 -0
- package/dist/activities/call-function.js +54 -0
- package/dist/activities/call-function.js.map +1 -0
- package/dist/activities/call-grpc.d.ts +22 -0
- package/dist/activities/call-grpc.js +101 -0
- package/dist/activities/call-grpc.js.map +1 -0
- package/dist/activities/call-http.d.ts +32 -0
- package/dist/activities/call-http.js +134 -0
- package/dist/activities/call-http.js.map +1 -0
- package/dist/activities/call-llm.d.ts +39 -0
- package/dist/activities/call-llm.js +260 -0
- package/dist/activities/call-llm.js.map +1 -0
- package/dist/activities/call-transform.d.ts +20 -0
- package/dist/activities/call-transform.js +33 -0
- package/dist/activities/call-transform.js.map +1 -0
- package/dist/activities/call-validate.d.ts +41 -0
- package/dist/activities/call-validate.js +163 -0
- package/dist/activities/call-validate.js.map +1 -0
- package/dist/activities/classify-tool-approvals.d.ts +47 -0
- package/dist/activities/classify-tool-approvals.js +207 -0
- package/dist/activities/classify-tool-approvals.js.map +1 -0
- package/dist/activities/discover-mcp-server.d.ts +65 -0
- package/dist/activities/discover-mcp-server.js +269 -0
- package/dist/activities/discover-mcp-server.js.map +1 -0
- package/dist/activities/emit-event.d.ts +46 -0
- package/dist/activities/emit-event.js +125 -0
- package/dist/activities/emit-event.js.map +1 -0
- package/dist/activities/ensure-thread.d.ts +24 -0
- package/dist/activities/ensure-thread.js +44 -0
- package/dist/activities/ensure-thread.js.map +1 -0
- package/dist/activities/evaluate-expressions.d.ts +21 -0
- package/dist/activities/evaluate-expressions.js +39 -0
- package/dist/activities/evaluate-expressions.js.map +1 -0
- package/dist/activities/execute-cursor/approval-policy.d.ts +104 -0
- package/dist/activities/execute-cursor/approval-policy.js +193 -0
- package/dist/activities/execute-cursor/approval-policy.js.map +1 -0
- package/dist/activities/execute-cursor/approval-state.d.ts +157 -0
- package/dist/activities/execute-cursor/approval-state.js +223 -0
- package/dist/activities/execute-cursor/approval-state.js.map +1 -0
- package/dist/activities/execute-cursor/attachment-resolver.d.ts +19 -0
- package/dist/activities/execute-cursor/attachment-resolver.js +52 -0
- package/dist/activities/execute-cursor/attachment-resolver.js.map +1 -0
- package/dist/activities/execute-cursor/blueprint-resolver.d.ts +66 -0
- package/dist/activities/execute-cursor/blueprint-resolver.js +169 -0
- package/dist/activities/execute-cursor/blueprint-resolver.js.map +1 -0
- package/dist/activities/execute-cursor/connect-backfill.d.ts +18 -0
- package/dist/activities/execute-cursor/connect-backfill.js +27 -0
- package/dist/activities/execute-cursor/connect-backfill.js.map +1 -0
- package/dist/activities/execute-cursor/cursor-event-recorder.d.ts +24 -0
- package/dist/activities/execute-cursor/cursor-event-recorder.js +66 -0
- package/dist/activities/execute-cursor/cursor-event-recorder.js.map +1 -0
- package/dist/activities/execute-cursor/cursor-mode.d.ts +32 -0
- package/dist/activities/execute-cursor/cursor-mode.js +36 -0
- package/dist/activities/execute-cursor/cursor-mode.js.map +1 -0
- package/dist/activities/execute-cursor/delta-enricher.d.ts +87 -0
- package/dist/activities/execute-cursor/delta-enricher.js +265 -0
- package/dist/activities/execute-cursor/delta-enricher.js.map +1 -0
- package/dist/activities/execute-cursor/env-resolver.d.ts +19 -0
- package/dist/activities/execute-cursor/env-resolver.js +47 -0
- package/dist/activities/execute-cursor/env-resolver.js.map +1 -0
- package/dist/activities/execute-cursor/error-classifier.d.ts +73 -0
- package/dist/activities/execute-cursor/error-classifier.js +185 -0
- package/dist/activities/execute-cursor/error-classifier.js.map +1 -0
- package/dist/activities/execute-cursor/fetch-interceptor.d.ts +59 -0
- package/dist/activities/execute-cursor/fetch-interceptor.js +317 -0
- package/dist/activities/execute-cursor/fetch-interceptor.js.map +1 -0
- package/dist/activities/execute-cursor/hitl-diagnostics.d.ts +32 -0
- package/dist/activities/execute-cursor/hitl-diagnostics.js +73 -0
- package/dist/activities/execute-cursor/hitl-diagnostics.js.map +1 -0
- package/dist/activities/execute-cursor/hook-script.d.ts +47 -0
- package/dist/activities/execute-cursor/hook-script.js +156 -0
- package/dist/activities/execute-cursor/hook-script.js.map +1 -0
- package/dist/activities/execute-cursor/http2-interceptor.d.ts +94 -0
- package/dist/activities/execute-cursor/http2-interceptor.js +209 -0
- package/dist/activities/execute-cursor/http2-interceptor.js.map +1 -0
- package/dist/activities/execute-cursor/index.d.ts +67 -0
- package/dist/activities/execute-cursor/index.js +1176 -0
- package/dist/activities/execute-cursor/index.js.map +1 -0
- package/dist/activities/execute-cursor/mcp-config.d.ts +30 -0
- package/dist/activities/execute-cursor/mcp-config.js +39 -0
- package/dist/activities/execute-cursor/mcp-config.js.map +1 -0
- package/dist/activities/execute-cursor/mcp-resolver.d.ts +91 -0
- package/dist/activities/execute-cursor/mcp-resolver.js +178 -0
- package/dist/activities/execute-cursor/mcp-resolver.js.map +1 -0
- package/dist/activities/execute-cursor/message-translator.d.ts +211 -0
- package/dist/activities/execute-cursor/message-translator.js +786 -0
- package/dist/activities/execute-cursor/message-translator.js.map +1 -0
- package/dist/activities/execute-cursor/model-pricing-data.d.ts +40 -0
- package/dist/activities/execute-cursor/model-pricing-data.js +114 -0
- package/dist/activities/execute-cursor/model-pricing-data.js.map +1 -0
- package/dist/activities/execute-cursor/model-pricing.d.ts +42 -0
- package/dist/activities/execute-cursor/model-pricing.js +141 -0
- package/dist/activities/execute-cursor/model-pricing.js.map +1 -0
- package/dist/activities/execute-cursor/placeholder-resolver.d.ts +34 -0
- package/dist/activities/execute-cursor/placeholder-resolver.js +82 -0
- package/dist/activities/execute-cursor/placeholder-resolver.js.map +1 -0
- package/dist/activities/execute-cursor/prompt-builder.d.ts +80 -0
- package/dist/activities/execute-cursor/prompt-builder.js +280 -0
- package/dist/activities/execute-cursor/prompt-builder.js.map +1 -0
- package/dist/activities/execute-cursor/rejection-capture.d.ts +30 -0
- package/dist/activities/execute-cursor/rejection-capture.js +80 -0
- package/dist/activities/execute-cursor/rejection-capture.js.map +1 -0
- package/dist/activities/execute-cursor/session-lifecycle.d.ts +189 -0
- package/dist/activities/execute-cursor/session-lifecycle.js +285 -0
- package/dist/activities/execute-cursor/session-lifecycle.js.map +1 -0
- package/dist/activities/execute-cursor/skill-resolver.d.ts +29 -0
- package/dist/activities/execute-cursor/skill-resolver.js +134 -0
- package/dist/activities/execute-cursor/skill-resolver.js.map +1 -0
- package/dist/activities/execute-cursor/subagent-config.d.ts +34 -0
- package/dist/activities/execute-cursor/subagent-config.js +55 -0
- package/dist/activities/execute-cursor/subagent-config.js.map +1 -0
- package/dist/activities/execute-cursor/todo-tracker.d.ts +35 -0
- package/dist/activities/execute-cursor/todo-tracker.js +108 -0
- package/dist/activities/execute-cursor/todo-tracker.js.map +1 -0
- package/dist/activities/execute-cursor/usage-accumulator.d.ts +55 -0
- package/dist/activities/execute-cursor/usage-accumulator.js +89 -0
- package/dist/activities/execute-cursor/usage-accumulator.js.map +1 -0
- package/dist/activities/execute-cursor/workspace-provision.d.ts +22 -0
- package/dist/activities/execute-cursor/workspace-provision.js +37 -0
- package/dist/activities/execute-cursor/workspace-provision.js.map +1 -0
- package/dist/activities/execute-cursor/workspace-setup.d.ts +27 -0
- package/dist/activities/execute-cursor/workspace-setup.js +61 -0
- package/dist/activities/execute-cursor/workspace-setup.js.map +1 -0
- package/dist/activities/execute-deep-agent/__test-utils__/v3-event-fixtures.d.ts +71 -0
- package/dist/activities/execute-deep-agent/__test-utils__/v3-event-fixtures.js +182 -0
- package/dist/activities/execute-deep-agent/__test-utils__/v3-event-fixtures.js.map +1 -0
- package/dist/activities/execute-deep-agent/attachment-injector.d.ts +67 -0
- package/dist/activities/execute-deep-agent/attachment-injector.js +306 -0
- package/dist/activities/execute-deep-agent/attachment-injector.js.map +1 -0
- package/dist/activities/execute-deep-agent/auto-publish.d.ts +17 -0
- package/dist/activities/execute-deep-agent/auto-publish.js +71 -0
- package/dist/activities/execute-deep-agent/auto-publish.js.map +1 -0
- package/dist/activities/execute-deep-agent/environment.d.ts +24 -0
- package/dist/activities/execute-deep-agent/environment.js +50 -0
- package/dist/activities/execute-deep-agent/environment.js.map +1 -0
- package/dist/activities/execute-deep-agent/event-recorder.d.ts +21 -0
- package/dist/activities/execute-deep-agent/event-recorder.js +67 -0
- package/dist/activities/execute-deep-agent/event-recorder.js.map +1 -0
- package/dist/activities/execute-deep-agent/execution-state.d.ts +61 -0
- package/dist/activities/execute-deep-agent/execution-state.js +76 -0
- package/dist/activities/execute-deep-agent/execution-state.js.map +1 -0
- package/dist/activities/execute-deep-agent/execution-status-writer.d.ts +17 -0
- package/dist/activities/execute-deep-agent/execution-status-writer.js +9 -0
- package/dist/activities/execute-deep-agent/execution-status-writer.js.map +1 -0
- package/dist/activities/execute-deep-agent/hitl.d.ts +58 -0
- package/dist/activities/execute-deep-agent/hitl.js +155 -0
- package/dist/activities/execute-deep-agent/hitl.js.map +1 -0
- package/dist/activities/execute-deep-agent/index.d.ts +14 -0
- package/dist/activities/execute-deep-agent/index.js +286 -0
- package/dist/activities/execute-deep-agent/index.js.map +1 -0
- package/dist/activities/execute-deep-agent/inline-publisher.d.ts +36 -0
- package/dist/activities/execute-deep-agent/inline-publisher.js +105 -0
- package/dist/activities/execute-deep-agent/inline-publisher.js.map +1 -0
- package/dist/activities/execute-deep-agent/post-stream.d.ts +23 -0
- package/dist/activities/execute-deep-agent/post-stream.js +71 -0
- package/dist/activities/execute-deep-agent/post-stream.js.map +1 -0
- package/dist/activities/execute-deep-agent/prompt-builder.d.ts +27 -0
- package/dist/activities/execute-deep-agent/prompt-builder.js +200 -0
- package/dist/activities/execute-deep-agent/prompt-builder.js.map +1 -0
- package/dist/activities/execute-deep-agent/setup.d.ts +55 -0
- package/dist/activities/execute-deep-agent/setup.js +411 -0
- package/dist/activities/execute-deep-agent/setup.js.map +1 -0
- package/dist/activities/execute-deep-agent/status-builder-shared.d.ts +39 -0
- package/dist/activities/execute-deep-agent/status-builder-shared.js +120 -0
- package/dist/activities/execute-deep-agent/status-builder-shared.js.map +1 -0
- package/dist/activities/execute-deep-agent/status-builder.d.ts +81 -0
- package/dist/activities/execute-deep-agent/status-builder.js +312 -0
- package/dist/activities/execute-deep-agent/status-builder.js.map +1 -0
- package/dist/activities/execute-deep-agent/streaming-scheduler.d.ts +60 -0
- package/dist/activities/execute-deep-agent/streaming-scheduler.js +114 -0
- package/dist/activities/execute-deep-agent/streaming-scheduler.js.map +1 -0
- package/dist/activities/execute-deep-agent/streaming-side-effects.d.ts +22 -0
- package/dist/activities/execute-deep-agent/streaming-side-effects.js +83 -0
- package/dist/activities/execute-deep-agent/streaming-side-effects.js.map +1 -0
- package/dist/activities/execute-deep-agent/streaming-terminal.d.ts +12 -0
- package/dist/activities/execute-deep-agent/streaming-terminal.js +71 -0
- package/dist/activities/execute-deep-agent/streaming-terminal.js.map +1 -0
- package/dist/activities/execute-deep-agent/streaming-v3.d.ts +13 -0
- package/dist/activities/execute-deep-agent/streaming-v3.js +170 -0
- package/dist/activities/execute-deep-agent/streaming-v3.js.map +1 -0
- package/dist/activities/execute-deep-agent/streaming.d.ts +66 -0
- package/dist/activities/execute-deep-agent/streaming.js +169 -0
- package/dist/activities/execute-deep-agent/streaming.js.map +1 -0
- package/dist/activities/execute-deep-agent/subagent-tracker.d.ts +90 -0
- package/dist/activities/execute-deep-agent/subagent-tracker.js +364 -0
- package/dist/activities/execute-deep-agent/subagent-tracker.js.map +1 -0
- package/dist/activities/execute-deep-agent/subagent-transformer.d.ts +150 -0
- package/dist/activities/execute-deep-agent/subagent-transformer.js +450 -0
- package/dist/activities/execute-deep-agent/subagent-transformer.js.map +1 -0
- package/dist/activities/execute-deep-agent/subagent-wiring.d.ts +28 -0
- package/dist/activities/execute-deep-agent/subagent-wiring.js +40 -0
- package/dist/activities/execute-deep-agent/subagent-wiring.js.map +1 -0
- package/dist/activities/execute-deep-agent/v3-event-recorder.d.ts +31 -0
- package/dist/activities/execute-deep-agent/v3-event-recorder.js +71 -0
- package/dist/activities/execute-deep-agent/v3-event-recorder.js.map +1 -0
- package/dist/activities/execute-deep-agent/v3-events.d.ts +102 -0
- package/dist/activities/execute-deep-agent/v3-events.js +35 -0
- package/dist/activities/execute-deep-agent/v3-events.js.map +1 -0
- package/dist/activities/execute-deep-agent/v3-protocol-normalizer.d.ts +15 -0
- package/dist/activities/execute-deep-agent/v3-protocol-normalizer.js +235 -0
- package/dist/activities/execute-deep-agent/v3-protocol-normalizer.js.map +1 -0
- package/dist/activities/execute-deep-agent/v3-status-builder.d.ts +68 -0
- package/dist/activities/execute-deep-agent/v3-status-builder.js +394 -0
- package/dist/activities/execute-deep-agent/v3-status-builder.js.map +1 -0
- package/dist/activities/execute-deep-agent/writeback-coordinator.d.ts +71 -0
- package/dist/activities/execute-deep-agent/writeback-coordinator.js +295 -0
- package/dist/activities/execute-deep-agent/writeback-coordinator.js.map +1 -0
- package/dist/activities/hydrate-workflow-execution.d.ts +32 -0
- package/dist/activities/hydrate-workflow-execution.js +212 -0
- package/dist/activities/hydrate-workflow-execution.js.map +1 -0
- package/dist/activities/notification.d.ts +19 -0
- package/dist/activities/notification.js +47 -0
- package/dist/activities/notification.js.map +1 -0
- package/dist/activities/promote-task-output.d.ts +38 -0
- package/dist/activities/promote-task-output.js +90 -0
- package/dist/activities/promote-task-output.js.map +1 -0
- package/dist/activities/run-command.d.ts +15 -0
- package/dist/activities/run-command.js +123 -0
- package/dist/activities/run-command.js.map +1 -0
- package/dist/activities/workflow-event-activities.d.ts +48 -0
- package/dist/activities/workflow-event-activities.js +415 -0
- package/dist/activities/workflow-event-activities.js.map +1 -0
- package/dist/bootstrap.d.ts +80 -0
- package/dist/bootstrap.js +114 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/budget/index.d.ts +1 -0
- package/dist/budget/index.js +2 -0
- package/dist/budget/index.js.map +1 -0
- package/dist/budget/tracker.d.ts +52 -0
- package/dist/budget/tracker.js +123 -0
- package/dist/budget/tracker.js.map +1 -0
- package/dist/claimcheck/compressor.d.ts +2 -0
- package/dist/claimcheck/compressor.js +8 -0
- package/dist/claimcheck/compressor.js.map +1 -0
- package/dist/claimcheck/config.d.ts +7 -0
- package/dist/claimcheck/config.js +10 -0
- package/dist/claimcheck/config.js.map +1 -0
- package/dist/claimcheck/index.d.ts +3 -0
- package/dist/claimcheck/index.js +4 -0
- package/dist/claimcheck/index.js.map +1 -0
- package/dist/claimcheck/payload-codec.d.ts +23 -0
- package/dist/claimcheck/payload-codec.js +81 -0
- package/dist/claimcheck/payload-codec.js.map +1 -0
- package/dist/client/server-contracts.d.ts +52 -0
- package/dist/client/server-contracts.js +72 -0
- package/dist/client/server-contracts.js.map +1 -0
- package/dist/client/stigmer-client.d.ts +131 -0
- package/dist/client/stigmer-client.js +239 -0
- package/dist/client/stigmer-client.js.map +1 -0
- package/dist/config.d.ts +64 -0
- package/dist/config.js +123 -0
- package/dist/config.js.map +1 -0
- package/dist/idle-watchdog.d.ts +11 -0
- package/dist/idle-watchdog.js +24 -0
- package/dist/idle-watchdog.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/workflow-metrics-sink.d.ts +11 -0
- package/dist/interceptors/workflow-metrics-sink.js +51 -0
- package/dist/interceptors/workflow-metrics-sink.js.map +1 -0
- package/dist/ipc-protocol-fixtures.d.ts +32 -0
- package/dist/ipc-protocol-fixtures.js +69 -0
- package/dist/ipc-protocol-fixtures.js.map +1 -0
- package/dist/ipc-protocol.d.ts +60 -0
- package/dist/ipc-protocol.js +19 -0
- package/dist/ipc-protocol.js.map +1 -0
- package/dist/main.d.ts +19 -0
- package/dist/main.js +292 -0
- package/dist/main.js.map +1 -0
- package/dist/middleware/approval-gate.d.ts +30 -0
- package/dist/middleware/approval-gate.js +125 -0
- package/dist/middleware/approval-gate.js.map +1 -0
- package/dist/middleware/cost-cap.d.ts +22 -0
- package/dist/middleware/cost-cap.js +159 -0
- package/dist/middleware/cost-cap.js.map +1 -0
- package/dist/middleware/error-hints.d.ts +27 -0
- package/dist/middleware/error-hints.js +116 -0
- package/dist/middleware/error-hints.js.map +1 -0
- package/dist/middleware/execution-budget.d.ts +20 -0
- package/dist/middleware/execution-budget.js +151 -0
- package/dist/middleware/execution-budget.js.map +1 -0
- package/dist/middleware/graceful-stop.d.ts +17 -0
- package/dist/middleware/graceful-stop.js +63 -0
- package/dist/middleware/graceful-stop.js.map +1 -0
- package/dist/middleware/index.d.ts +27 -0
- package/dist/middleware/index.js +45 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/loop-detection.d.ts +14 -0
- package/dist/middleware/loop-detection.js +156 -0
- package/dist/middleware/loop-detection.js.map +1 -0
- package/dist/middleware/otel-spans.d.ts +11 -0
- package/dist/middleware/otel-spans.js +177 -0
- package/dist/middleware/otel-spans.js.map +1 -0
- package/dist/middleware/think-tool.d.ts +23 -0
- package/dist/middleware/think-tool.js +33 -0
- package/dist/middleware/think-tool.js.map +1 -0
- package/dist/middleware/tool-truncation.d.ts +16 -0
- package/dist/middleware/tool-truncation.js +67 -0
- package/dist/middleware/tool-truncation.js.map +1 -0
- package/dist/middleware/types.d.ts +100 -0
- package/dist/middleware/types.js +9 -0
- package/dist/middleware/types.js.map +1 -0
- package/dist/notification/index.d.ts +2 -0
- package/dist/notification/index.js +6 -0
- package/dist/notification/index.js.map +1 -0
- package/dist/notification/provider.d.ts +29 -0
- package/dist/notification/provider.js +25 -0
- package/dist/notification/provider.js.map +1 -0
- package/dist/notification/webhook.d.ts +13 -0
- package/dist/notification/webhook.js +55 -0
- package/dist/notification/webhook.js.map +1 -0
- package/dist/otel-metrics.d.ts +21 -0
- package/dist/otel-metrics.js +54 -0
- package/dist/otel-metrics.js.map +1 -0
- package/dist/otel.d.ts +57 -0
- package/dist/otel.js +164 -0
- package/dist/otel.js.map +1 -0
- package/dist/runner-manager.d.ts +113 -0
- package/dist/runner-manager.js +412 -0
- package/dist/runner-manager.js.map +1 -0
- package/dist/runner-token-coordinator.d.ts +56 -0
- package/dist/runner-token-coordinator.js +84 -0
- package/dist/runner-token-coordinator.js.map +1 -0
- package/dist/runner.d.ts +104 -0
- package/dist/runner.js +234 -0
- package/dist/runner.js.map +1 -0
- package/dist/shared/approval-policy.d.ts +45 -0
- package/dist/shared/approval-policy.js +122 -0
- package/dist/shared/approval-policy.js.map +1 -0
- package/dist/shared/artifact-storage.d.ts +44 -0
- package/dist/shared/artifact-storage.js +162 -0
- package/dist/shared/artifact-storage.js.map +1 -0
- package/dist/shared/checkpointer/factory.d.ts +28 -0
- package/dist/shared/checkpointer/factory.js +55 -0
- package/dist/shared/checkpointer/factory.js.map +1 -0
- package/dist/shared/checkpointer/http-saver.d.ts +34 -0
- package/dist/shared/checkpointer/http-saver.js +274 -0
- package/dist/shared/checkpointer/http-saver.js.map +1 -0
- package/dist/shared/checkpointer/types.d.ts +12 -0
- package/dist/shared/checkpointer/types.js +2 -0
- package/dist/shared/checkpointer/types.js.map +1 -0
- package/dist/shared/connect-backfill.d.ts +58 -0
- package/dist/shared/connect-backfill.js +119 -0
- package/dist/shared/connect-backfill.js.map +1 -0
- package/dist/shared/extract-json.d.ts +26 -0
- package/dist/shared/extract-json.js +140 -0
- package/dist/shared/extract-json.js.map +1 -0
- package/dist/shared/grpc-retry.d.ts +35 -0
- package/dist/shared/grpc-retry.js +78 -0
- package/dist/shared/grpc-retry.js.map +1 -0
- package/dist/shared/heartbeat.d.ts +22 -0
- package/dist/shared/heartbeat.js +55 -0
- package/dist/shared/heartbeat.js.map +1 -0
- package/dist/shared/json-schema-to-zod.d.ts +13 -0
- package/dist/shared/json-schema-to-zod.js +49 -0
- package/dist/shared/json-schema-to-zod.js.map +1 -0
- package/dist/shared/llm-proxy.d.ts +57 -0
- package/dist/shared/llm-proxy.js +116 -0
- package/dist/shared/llm-proxy.js.map +1 -0
- package/dist/shared/mcp-manager.d.ts +47 -0
- package/dist/shared/mcp-manager.js +118 -0
- package/dist/shared/mcp-manager.js.map +1 -0
- package/dist/shared/mcp-resolver.d.ts +41 -0
- package/dist/shared/mcp-resolver.js +96 -0
- package/dist/shared/mcp-resolver.js.map +1 -0
- package/dist/shared/model-pricing-data.d.ts +18 -0
- package/dist/shared/model-pricing-data.js +78 -0
- package/dist/shared/model-pricing-data.js.map +1 -0
- package/dist/shared/model-pricing.d.ts +24 -0
- package/dist/shared/model-pricing.js +58 -0
- package/dist/shared/model-pricing.js.map +1 -0
- package/dist/shared/model-registry.d.ts +55 -0
- package/dist/shared/model-registry.js +178 -0
- package/dist/shared/model-registry.js.map +1 -0
- package/dist/shared/placeholder-resolver.d.ts +27 -0
- package/dist/shared/placeholder-resolver.js +75 -0
- package/dist/shared/placeholder-resolver.js.map +1 -0
- package/dist/shared/plan-artifact.d.ts +56 -0
- package/dist/shared/plan-artifact.js +98 -0
- package/dist/shared/plan-artifact.js.map +1 -0
- package/dist/shared/skill-relevance.d.ts +65 -0
- package/dist/shared/skill-relevance.js +175 -0
- package/dist/shared/skill-relevance.js.map +1 -0
- package/dist/shared/skill-writer.d.ts +73 -0
- package/dist/shared/skill-writer.js +230 -0
- package/dist/shared/skill-writer.js.map +1 -0
- package/dist/shared/status.d.ts +37 -0
- package/dist/shared/status.js +73 -0
- package/dist/shared/status.js.map +1 -0
- package/dist/shared/subagent-gate.d.ts +41 -0
- package/dist/shared/subagent-gate.js +93 -0
- package/dist/shared/subagent-gate.js.map +1 -0
- package/dist/shared/tool-kind.d.ts +22 -0
- package/dist/shared/tool-kind.js +79 -0
- package/dist/shared/tool-kind.js.map +1 -0
- package/dist/shared/workspace/file-tree.d.ts +13 -0
- package/dist/shared/workspace/file-tree.js +101 -0
- package/dist/shared/workspace/file-tree.js.map +1 -0
- package/dist/shared/workspace/local-backend.d.ts +41 -0
- package/dist/shared/workspace/local-backend.js +113 -0
- package/dist/shared/workspace/local-backend.js.map +1 -0
- package/dist/shared/workspace/platform-dir.d.ts +25 -0
- package/dist/shared/workspace/platform-dir.js +36 -0
- package/dist/shared/workspace/platform-dir.js.map +1 -0
- package/dist/shared/workspace/platform-mount.d.ts +95 -0
- package/dist/shared/workspace/platform-mount.js +157 -0
- package/dist/shared/workspace/platform-mount.js.map +1 -0
- package/dist/shared/workspace/provisioner.d.ts +47 -0
- package/dist/shared/workspace/provisioner.js +84 -0
- package/dist/shared/workspace/provisioner.js.map +1 -0
- package/dist/shared/workspace/sources/empty.d.ts +8 -0
- package/dist/shared/workspace/sources/empty.js +18 -0
- package/dist/shared/workspace/sources/empty.js.map +1 -0
- package/dist/shared/workspace/sources/git.d.ts +22 -0
- package/dist/shared/workspace/sources/git.js +207 -0
- package/dist/shared/workspace/sources/git.js.map +1 -0
- package/dist/shared/workspace/sources/local-path.d.ts +17 -0
- package/dist/shared/workspace/sources/local-path.js +57 -0
- package/dist/shared/workspace/sources/local-path.js.map +1 -0
- package/dist/shared/workspace/types.d.ts +58 -0
- package/dist/shared/workspace/types.js +25 -0
- package/dist/shared/workspace/types.js.map +1 -0
- package/dist/shared/zip-extract.d.ts +30 -0
- package/dist/shared/zip-extract.js +150 -0
- package/dist/shared/zip-extract.js.map +1 -0
- package/dist/worker.d.ts +27 -0
- package/dist/worker.js +65 -0
- package/dist/worker.js.map +1 -0
- package/dist/workflow-engine/clone.d.ts +11 -0
- package/dist/workflow-engine/clone.js +21 -0
- package/dist/workflow-engine/clone.js.map +1 -0
- package/dist/workflow-engine/do-executor.d.ts +27 -0
- package/dist/workflow-engine/do-executor.js +418 -0
- package/dist/workflow-engine/do-executor.js.map +1 -0
- package/dist/workflow-engine/duration.d.ts +12 -0
- package/dist/workflow-engine/duration.js +25 -0
- package/dist/workflow-engine/duration.js.map +1 -0
- package/dist/workflow-engine/error-utils.d.ts +42 -0
- package/dist/workflow-engine/error-utils.js +77 -0
- package/dist/workflow-engine/error-utils.js.map +1 -0
- package/dist/workflow-engine/errors.d.ts +46 -0
- package/dist/workflow-engine/errors.js +105 -0
- package/dist/workflow-engine/errors.js.map +1 -0
- package/dist/workflow-engine/expression-utils.d.ts +60 -0
- package/dist/workflow-engine/expression-utils.js +108 -0
- package/dist/workflow-engine/expression-utils.js.map +1 -0
- package/dist/workflow-engine/expression.d.ts +132 -0
- package/dist/workflow-engine/expression.js +366 -0
- package/dist/workflow-engine/expression.js.map +1 -0
- package/dist/workflow-engine/loader.d.ts +23 -0
- package/dist/workflow-engine/loader.js +429 -0
- package/dist/workflow-engine/loader.js.map +1 -0
- package/dist/workflow-engine/recovery.d.ts +53 -0
- package/dist/workflow-engine/recovery.js +46 -0
- package/dist/workflow-engine/recovery.js.map +1 -0
- package/dist/workflow-engine/resolve.d.ts +83 -0
- package/dist/workflow-engine/resolve.js +257 -0
- package/dist/workflow-engine/resolve.js.map +1 -0
- package/dist/workflow-engine/retry.d.ts +30 -0
- package/dist/workflow-engine/retry.js +97 -0
- package/dist/workflow-engine/retry.js.map +1 -0
- package/dist/workflow-engine/state.d.ts +26 -0
- package/dist/workflow-engine/state.js +49 -0
- package/dist/workflow-engine/state.js.map +1 -0
- package/dist/workflow-engine/task-factory.d.ts +20 -0
- package/dist/workflow-engine/task-factory.js +133 -0
- package/dist/workflow-engine/task-factory.js.map +1 -0
- package/dist/workflow-engine/task-status-accumulator.d.ts +59 -0
- package/dist/workflow-engine/task-status-accumulator.js +164 -0
- package/dist/workflow-engine/task-status-accumulator.js.map +1 -0
- package/dist/workflow-engine/tasks/call-agent-output.d.ts +26 -0
- package/dist/workflow-engine/tasks/call-agent-output.js +109 -0
- package/dist/workflow-engine/tasks/call-agent-output.js.map +1 -0
- package/dist/workflow-engine/tasks/call-agent.d.ts +31 -0
- package/dist/workflow-engine/tasks/call-agent.js +161 -0
- package/dist/workflow-engine/tasks/call-agent.js.map +1 -0
- package/dist/workflow-engine/tasks/call-function.d.ts +19 -0
- package/dist/workflow-engine/tasks/call-function.js +64 -0
- package/dist/workflow-engine/tasks/call-function.js.map +1 -0
- package/dist/workflow-engine/tasks/call-grpc.d.ts +15 -0
- package/dist/workflow-engine/tasks/call-grpc.js +27 -0
- package/dist/workflow-engine/tasks/call-grpc.js.map +1 -0
- package/dist/workflow-engine/tasks/call-http.d.ts +19 -0
- package/dist/workflow-engine/tasks/call-http.js +31 -0
- package/dist/workflow-engine/tasks/call-http.js.map +1 -0
- package/dist/workflow-engine/tasks/for.d.ts +39 -0
- package/dist/workflow-engine/tasks/for.js +154 -0
- package/dist/workflow-engine/tasks/for.js.map +1 -0
- package/dist/workflow-engine/tasks/fork.d.ts +42 -0
- package/dist/workflow-engine/tasks/fork.js +142 -0
- package/dist/workflow-engine/tasks/fork.js.map +1 -0
- package/dist/workflow-engine/tasks/human-input.d.ts +33 -0
- package/dist/workflow-engine/tasks/human-input.js +109 -0
- package/dist/workflow-engine/tasks/human-input.js.map +1 -0
- package/dist/workflow-engine/tasks/listen.d.ts +34 -0
- package/dist/workflow-engine/tasks/listen.js +119 -0
- package/dist/workflow-engine/tasks/listen.js.map +1 -0
- package/dist/workflow-engine/tasks/raise.d.ts +18 -0
- package/dist/workflow-engine/tasks/raise.js +60 -0
- package/dist/workflow-engine/tasks/raise.js.map +1 -0
- package/dist/workflow-engine/tasks/run.d.ts +39 -0
- package/dist/workflow-engine/tasks/run.js +114 -0
- package/dist/workflow-engine/tasks/run.js.map +1 -0
- package/dist/workflow-engine/tasks/set.d.ts +15 -0
- package/dist/workflow-engine/tasks/set.js +31 -0
- package/dist/workflow-engine/tasks/set.js.map +1 -0
- package/dist/workflow-engine/tasks/switch.d.ts +25 -0
- package/dist/workflow-engine/tasks/switch.js +76 -0
- package/dist/workflow-engine/tasks/switch.js.map +1 -0
- package/dist/workflow-engine/tasks/try.d.ts +49 -0
- package/dist/workflow-engine/tasks/try.js +189 -0
- package/dist/workflow-engine/tasks/try.js.map +1 -0
- package/dist/workflow-engine/tasks/wait.d.ts +24 -0
- package/dist/workflow-engine/tasks/wait.js +39 -0
- package/dist/workflow-engine/tasks/wait.js.map +1 -0
- package/dist/workflow-engine/types.d.ts +682 -0
- package/dist/workflow-engine/types.js +47 -0
- package/dist/workflow-engine/types.js.map +1 -0
- package/dist/workflows/call-agent-orchestrator.d.ts +31 -0
- package/dist/workflows/call-agent-orchestrator.js +214 -0
- package/dist/workflows/call-agent-orchestrator.js.map +1 -0
- package/dist/workflows/connect-mcp-server.d.ts +20 -0
- package/dist/workflows/connect-mcp-server.js +113 -0
- package/dist/workflows/connect-mcp-server.js.map +1 -0
- package/dist/workflows/engine-core.d.ts +36 -0
- package/dist/workflows/engine-core.js +272 -0
- package/dist/workflows/engine-core.js.map +1 -0
- package/dist/workflows/execute-from-execution.d.ts +32 -0
- package/dist/workflows/execute-from-execution.js +71 -0
- package/dist/workflows/execute-from-execution.js.map +1 -0
- package/dist/workflows/execute-serverless-workflow.d.ts +32 -0
- package/dist/workflows/execute-serverless-workflow.js +36 -0
- package/dist/workflows/execute-serverless-workflow.js.map +1 -0
- package/dist/workflows/human-input-orchestrator.d.ts +19 -0
- package/dist/workflows/human-input-orchestrator.js +59 -0
- package/dist/workflows/human-input-orchestrator.js.map +1 -0
- package/dist/workflows/index.d.ts +22 -0
- package/dist/workflows/index.js +23 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/listen-orchestrator.d.ts +29 -0
- package/dist/workflows/listen-orchestrator.js +143 -0
- package/dist/workflows/listen-orchestrator.js.map +1 -0
- package/dist/workflows/metrics-sink.d.ts +33 -0
- package/dist/workflows/metrics-sink.js +21 -0
- package/dist/workflows/metrics-sink.js.map +1 -0
- package/dist/workflows/run-orchestrator.d.ts +15 -0
- package/dist/workflows/run-orchestrator.js +27 -0
- package/dist/workflows/run-orchestrator.js.map +1 -0
- package/dist/workflows/types.d.ts +46 -0
- package/dist/workflows/types.js +15 -0
- package/dist/workflows/types.js.map +1 -0
- package/dist/workflows/workflow-signals.d.ts +29 -0
- package/dist/workflows/workflow-signals.js +46 -0
- package/dist/workflows/workflow-signals.js.map +1 -0
- package/package.json +108 -0
- package/src/__test-utils__/__tests__/replay-fetch.test.ts +155 -0
- package/src/__test-utils__/mock-client.ts +44 -0
- package/src/__test-utils__/mock-workspace.ts +28 -0
- package/src/__test-utils__/proto-helpers.ts +41 -0
- package/src/__test-utils__/replay-fetch.ts +523 -0
- package/src/__tests__/bootstrap.test.ts +221 -0
- package/src/__tests__/claimcheck-codec.test.ts +257 -0
- package/src/__tests__/config.test.ts +150 -0
- package/src/__tests__/deterministic-eval-llm.test.ts +269 -0
- package/src/__tests__/deterministic-mcp-hitl.test.ts +405 -0
- package/src/__tests__/golden-e2e.test.ts +250 -0
- package/src/__tests__/ipc-protocol-fixtures.test.ts +66 -0
- package/src/__tests__/ipc-protocol.test.ts +32 -0
- package/src/__tests__/otel-metrics.test.ts +40 -0
- package/src/__tests__/runner-manager.test.ts +55 -0
- package/src/__tests__/runner-token-coordinator.test.ts +166 -0
- package/src/__tests__/runner.test.ts +182 -0
- package/src/__tests__/worker.test.ts +18 -0
- package/src/activities/__tests__/call-agent-contracts.test.ts +483 -0
- package/src/activities/__tests__/call-agent.test.ts +263 -0
- package/src/activities/__tests__/call-function.test.ts +47 -0
- package/src/activities/__tests__/call-grpc.test.ts +39 -0
- package/src/activities/__tests__/call-http.test.ts +288 -0
- package/src/activities/__tests__/call-llm.test.ts +301 -0
- package/src/activities/__tests__/classify-tool-approvals.test.ts +430 -0
- package/src/activities/__tests__/discover-mcp-server.test.ts +641 -0
- package/src/activities/__tests__/ensure-thread.test.ts +96 -0
- package/src/activities/__tests__/error-classifier.test.ts +372 -0
- package/src/activities/__tests__/evaluate-expressions.test.ts +114 -0
- package/src/activities/__tests__/hydrate-workflow-execution.test.ts +321 -0
- package/src/activities/__tests__/notification.test.ts +151 -0
- package/src/activities/__tests__/workflow-event-activities.test.ts +664 -0
- package/src/activities/call-agent-status.ts +130 -0
- package/src/activities/call-agent.ts +302 -0
- package/src/activities/call-eval.ts +333 -0
- package/src/activities/call-function.ts +73 -0
- package/src/activities/call-grpc.ts +140 -0
- package/src/activities/call-http.ts +185 -0
- package/src/activities/call-llm.ts +379 -0
- package/src/activities/call-transform.ts +54 -0
- package/src/activities/call-validate.ts +223 -0
- package/src/activities/classify-tool-approvals.ts +319 -0
- package/src/activities/discover-mcp-server.ts +411 -0
- package/src/activities/emit-event.ts +195 -0
- package/src/activities/ensure-thread.ts +45 -0
- package/src/activities/evaluate-expressions.ts +47 -0
- package/src/activities/execute-cursor/__tests__/approval-gate.test.ts +188 -0
- package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +111 -0
- package/src/activities/execute-cursor/__tests__/cursor-baseurl-routing.test.ts +86 -0
- package/src/activities/execute-cursor/__tests__/cursor-fetch-interceptor-bypass.test.ts +64 -0
- package/src/activities/execute-cursor/__tests__/cursor-mode.test.ts +95 -0
- package/src/activities/execute-cursor/__tests__/cursor-sdk-auth-smoke.test.ts +90 -0
- package/src/activities/execute-cursor/__tests__/delta-enricher.test.ts +242 -0
- package/src/activities/execute-cursor/__tests__/error-classifier-introspection.test.ts +156 -0
- package/src/activities/execute-cursor/__tests__/fetch-interceptor.test.ts +211 -0
- package/src/activities/execute-cursor/__tests__/hitl-ledger.test.ts +298 -0
- package/src/activities/execute-cursor/__tests__/http2-interceptor.test.ts +360 -0
- package/src/activities/execute-cursor/__tests__/message-translator.test.ts +657 -0
- package/src/activities/execute-cursor/__tests__/model-pricing.test.ts +92 -0
- package/src/activities/execute-cursor/__tests__/prompt-builder-delegation.test.ts +101 -0
- package/src/activities/execute-cursor/__tests__/runner-error-regressions.test.ts +144 -0
- package/src/activities/execute-cursor/__tests__/session-lifecycle.test.ts +65 -0
- package/src/activities/execute-cursor/__tests__/skill-resolver.test.ts +265 -0
- package/src/activities/execute-cursor/__tests__/subagent-config.test.ts +107 -0
- package/src/activities/execute-cursor/__tests__/todo-tracker.test.ts +498 -0
- package/src/activities/execute-cursor/__tests__/workspace-provision.test.ts +283 -0
- package/src/activities/execute-cursor/approval-policy.ts +224 -0
- package/src/activities/execute-cursor/approval-state.ts +311 -0
- package/src/activities/execute-cursor/attachment-resolver.ts +78 -0
- package/src/activities/execute-cursor/blueprint-resolver.ts +234 -0
- package/src/activities/execute-cursor/connect-backfill.ts +49 -0
- package/src/activities/execute-cursor/cursor-event-recorder.ts +83 -0
- package/src/activities/execute-cursor/cursor-mode.ts +42 -0
- package/src/activities/execute-cursor/delta-enricher.ts +307 -0
- package/src/activities/execute-cursor/env-resolver.ts +64 -0
- package/src/activities/execute-cursor/error-classifier.ts +247 -0
- package/src/activities/execute-cursor/fetch-interceptor.ts +382 -0
- package/src/activities/execute-cursor/hitl-diagnostics.ts +82 -0
- package/src/activities/execute-cursor/hook-script.ts +159 -0
- package/src/activities/execute-cursor/http2-interceptor.ts +253 -0
- package/src/activities/execute-cursor/index.ts +1439 -0
- package/src/activities/execute-cursor/mcp-config.ts +66 -0
- package/src/activities/execute-cursor/mcp-resolver.ts +271 -0
- package/src/activities/execute-cursor/message-translator.ts +896 -0
- package/src/activities/execute-cursor/model-pricing-data.ts +167 -0
- package/src/activities/execute-cursor/model-pricing.ts +167 -0
- package/src/activities/execute-cursor/placeholder-resolver.ts +109 -0
- package/src/activities/execute-cursor/prompt-builder.ts +349 -0
- package/src/activities/execute-cursor/rejection-capture.ts +100 -0
- package/src/activities/execute-cursor/session-lifecycle.ts +429 -0
- package/src/activities/execute-cursor/skill-resolver.ts +176 -0
- package/src/activities/execute-cursor/subagent-config.ts +62 -0
- package/src/activities/execute-cursor/todo-tracker.ts +133 -0
- package/src/activities/execute-cursor/usage-accumulator.ts +126 -0
- package/src/activities/execute-cursor/workspace-provision.ts +55 -0
- package/src/activities/execute-cursor/workspace-setup.ts +75 -0
- package/src/activities/execute-deep-agent/__test-utils__/v3-event-fixtures.ts +281 -0
- package/src/activities/execute-deep-agent/__tests__/attachment-injector.test.ts +720 -0
- package/src/activities/execute-deep-agent/__tests__/auto-publish.test.ts +146 -0
- package/src/activities/execute-deep-agent/__tests__/environment.test.ts +103 -0
- package/src/activities/execute-deep-agent/__tests__/event-recorder.test.ts +150 -0
- package/src/activities/execute-deep-agent/__tests__/execution-state-extended.test.ts +150 -0
- package/src/activities/execute-deep-agent/__tests__/execution-state.test.ts +157 -0
- package/src/activities/execute-deep-agent/__tests__/hitl-integration.test.ts +223 -0
- package/src/activities/execute-deep-agent/__tests__/hitl.test.ts +244 -0
- package/src/activities/execute-deep-agent/__tests__/index.test.ts +91 -0
- package/src/activities/execute-deep-agent/__tests__/inline-publisher.test.ts +240 -0
- package/src/activities/execute-deep-agent/__tests__/post-stream.test.ts +112 -0
- package/src/activities/execute-deep-agent/__tests__/prompt-builder.test.ts +208 -0
- package/src/activities/execute-deep-agent/__tests__/status-builder.test.ts +1771 -0
- package/src/activities/execute-deep-agent/__tests__/streaming-scheduler.test.ts +199 -0
- package/src/activities/execute-deep-agent/__tests__/streaming-v3.test.ts +527 -0
- package/src/activities/execute-deep-agent/__tests__/streaming.test.ts +508 -0
- package/src/activities/execute-deep-agent/__tests__/subagent-tracker.test.ts +474 -0
- package/src/activities/execute-deep-agent/__tests__/subagent-transformer.test.ts +734 -0
- package/src/activities/execute-deep-agent/__tests__/subagent-wiring.test.ts +71 -0
- package/src/activities/execute-deep-agent/__tests__/summarization-verification.test.ts +323 -0
- package/src/activities/execute-deep-agent/__tests__/v3-event-recorder.test.ts +186 -0
- package/src/activities/execute-deep-agent/__tests__/v3-protocol-normalizer.test.ts +324 -0
- package/src/activities/execute-deep-agent/__tests__/v3-status-builder.test.ts +504 -0
- package/src/activities/execute-deep-agent/__tests__/writeback-coordinator.test.ts +399 -0
- package/src/activities/execute-deep-agent/attachment-injector.ts +470 -0
- package/src/activities/execute-deep-agent/auto-publish.ts +80 -0
- package/src/activities/execute-deep-agent/environment.ts +67 -0
- package/src/activities/execute-deep-agent/event-recorder.ts +95 -0
- package/src/activities/execute-deep-agent/execution-state.ts +87 -0
- package/src/activities/execute-deep-agent/execution-status-writer.ts +19 -0
- package/src/activities/execute-deep-agent/hitl.ts +221 -0
- package/src/activities/execute-deep-agent/index.ts +342 -0
- package/src/activities/execute-deep-agent/inline-publisher.ts +134 -0
- package/src/activities/execute-deep-agent/post-stream.ts +109 -0
- package/src/activities/execute-deep-agent/prompt-builder.ts +264 -0
- package/src/activities/execute-deep-agent/setup.ts +599 -0
- package/src/activities/execute-deep-agent/status-builder-shared.ts +136 -0
- package/src/activities/execute-deep-agent/status-builder.ts +412 -0
- package/src/activities/execute-deep-agent/streaming-scheduler.ts +159 -0
- package/src/activities/execute-deep-agent/streaming-side-effects.ts +89 -0
- package/src/activities/execute-deep-agent/streaming-terminal.ts +96 -0
- package/src/activities/execute-deep-agent/streaming-v3.ts +272 -0
- package/src/activities/execute-deep-agent/streaming.ts +303 -0
- package/src/activities/execute-deep-agent/subagent-tracker.ts +445 -0
- package/src/activities/execute-deep-agent/subagent-transformer.ts +648 -0
- package/src/activities/execute-deep-agent/subagent-wiring.ts +56 -0
- package/src/activities/execute-deep-agent/v3-event-recorder.ts +111 -0
- package/src/activities/execute-deep-agent/v3-events.ts +153 -0
- package/src/activities/execute-deep-agent/v3-protocol-normalizer.ts +264 -0
- package/src/activities/execute-deep-agent/v3-status-builder.ts +490 -0
- package/src/activities/execute-deep-agent/writeback-coordinator.ts +420 -0
- package/src/activities/hydrate-workflow-execution.ts +306 -0
- package/src/activities/notification.ts +71 -0
- package/src/activities/promote-task-output.ts +126 -0
- package/src/activities/run-command.ts +148 -0
- package/src/activities/workflow-event-activities.ts +481 -0
- package/src/bootstrap.ts +173 -0
- package/src/budget/__tests__/tracker.test.ts +293 -0
- package/src/budget/index.ts +9 -0
- package/src/budget/tracker.ts +171 -0
- package/src/claimcheck/compressor.ts +9 -0
- package/src/claimcheck/config.ts +20 -0
- package/src/claimcheck/index.ts +3 -0
- package/src/claimcheck/payload-codec.ts +107 -0
- package/src/client/__tests__/server-contracts.test.ts +149 -0
- package/src/client/__tests__/stigmer-client.test.ts +142 -0
- package/src/client/server-contracts.ts +125 -0
- package/src/client/stigmer-client.ts +339 -0
- package/src/config.ts +185 -0
- package/src/idle-watchdog.ts +28 -0
- package/src/index.ts +48 -0
- package/src/interceptors/workflow-metrics-sink.ts +56 -0
- package/src/ipc-protocol-fixtures.ts +117 -0
- package/src/ipc-protocol.ts +113 -0
- package/src/main.ts +324 -0
- package/src/middleware/__tests__/approval-gate.test.ts +231 -0
- package/src/middleware/__tests__/cost-cap.test.ts +192 -0
- package/src/middleware/__tests__/error-hints.test.ts +90 -0
- package/src/middleware/__tests__/execution-budget.test.ts +138 -0
- package/src/middleware/__tests__/graceful-stop.test.ts +105 -0
- package/src/middleware/__tests__/loop-detection.test.ts +137 -0
- package/src/middleware/__tests__/otel-spans.test.ts +89 -0
- package/src/middleware/__tests__/think-tool.test.ts +26 -0
- package/src/middleware/__tests__/tool-truncation.test.ts +112 -0
- package/src/middleware/approval-gate.ts +179 -0
- package/src/middleware/cost-cap.ts +213 -0
- package/src/middleware/error-hints.ts +136 -0
- package/src/middleware/execution-budget.ts +176 -0
- package/src/middleware/graceful-stop.ts +86 -0
- package/src/middleware/index.ts +70 -0
- package/src/middleware/loop-detection.ts +192 -0
- package/src/middleware/otel-spans.ts +205 -0
- package/src/middleware/think-tool.ts +38 -0
- package/src/middleware/tool-truncation.ts +94 -0
- package/src/middleware/types.ts +114 -0
- package/src/notification/__tests__/provider.test.ts +85 -0
- package/src/notification/__tests__/webhook.test.ts +127 -0
- package/src/notification/index.ts +15 -0
- package/src/notification/provider.ts +52 -0
- package/src/notification/webhook.ts +61 -0
- package/src/otel-metrics.ts +73 -0
- package/src/otel.ts +194 -0
- package/src/runner-manager.ts +652 -0
- package/src/runner-token-coordinator.ts +135 -0
- package/src/runner.ts +380 -0
- package/src/shared/__tests__/approval-policy.test.ts +256 -0
- package/src/shared/__tests__/artifact-storage-extended.test.ts +208 -0
- package/src/shared/__tests__/artifact-storage.test.ts +365 -0
- package/src/shared/__tests__/connect-backfill.test.ts +346 -0
- package/src/shared/__tests__/extract-json.test.ts +153 -0
- package/src/shared/__tests__/grpc-retry-extended.test.ts +176 -0
- package/src/shared/__tests__/grpc-retry.test.ts +172 -0
- package/src/shared/__tests__/json-schema-to-zod.test.ts +227 -0
- package/src/shared/__tests__/llm-proxy.test.ts +179 -0
- package/src/shared/__tests__/mcp-manager.test.ts +154 -0
- package/src/shared/__tests__/model-pricing.test.ts +85 -0
- package/src/shared/__tests__/model-registry.test.ts +197 -0
- package/src/shared/__tests__/placeholder-resolver.test.ts +210 -0
- package/src/shared/__tests__/plan-artifact.test.ts +142 -0
- package/src/shared/__tests__/skill-relevance.test.ts +292 -0
- package/src/shared/__tests__/skill-writer.test.ts +349 -0
- package/src/shared/__tests__/status.test.ts +142 -0
- package/src/shared/__tests__/subagent-gate.test.ts +112 -0
- package/src/shared/__tests__/tool-kind.test.ts +58 -0
- package/src/shared/__tests__/zip-extract.test.ts +204 -0
- package/src/shared/approval-policy.ts +146 -0
- package/src/shared/artifact-storage.ts +207 -0
- package/src/shared/checkpointer/__tests__/factory.test.ts +42 -0
- package/src/shared/checkpointer/__tests__/http-saver.test.ts +176 -0
- package/src/shared/checkpointer/factory.ts +73 -0
- package/src/shared/checkpointer/http-saver.ts +349 -0
- package/src/shared/checkpointer/types.ts +12 -0
- package/src/shared/connect-backfill.ts +162 -0
- package/src/shared/extract-json.ts +153 -0
- package/src/shared/grpc-retry.ts +113 -0
- package/src/shared/heartbeat.ts +70 -0
- package/src/shared/json-schema-to-zod.ts +53 -0
- package/src/shared/llm-proxy.ts +138 -0
- package/src/shared/mcp-manager.ts +150 -0
- package/src/shared/mcp-resolver.ts +150 -0
- package/src/shared/model-pricing-data.ts +109 -0
- package/src/shared/model-pricing.ts +81 -0
- package/src/shared/model-registry.ts +214 -0
- package/src/shared/placeholder-resolver.ts +102 -0
- package/src/shared/plan-artifact.ts +120 -0
- package/src/shared/skill-relevance.ts +222 -0
- package/src/shared/skill-writer.ts +300 -0
- package/src/shared/status.ts +94 -0
- package/src/shared/subagent-gate.ts +117 -0
- package/src/shared/tool-kind.ts +91 -0
- package/src/shared/workspace/__tests__/file-tree.test.ts +210 -0
- package/src/shared/workspace/__tests__/git-source.test.ts +423 -0
- package/src/shared/workspace/__tests__/local-backend-platform.test.ts +259 -0
- package/src/shared/workspace/__tests__/local-backend.test.ts +154 -0
- package/src/shared/workspace/__tests__/platform-mount.test.ts +378 -0
- package/src/shared/workspace/__tests__/provisioner.test.ts +145 -0
- package/src/shared/workspace/file-tree.ts +116 -0
- package/src/shared/workspace/local-backend.ts +140 -0
- package/src/shared/workspace/platform-dir.ts +38 -0
- package/src/shared/workspace/platform-mount.ts +190 -0
- package/src/shared/workspace/provisioner.ts +150 -0
- package/src/shared/workspace/sources/empty.ts +20 -0
- package/src/shared/workspace/sources/git.ts +285 -0
- package/src/shared/workspace/sources/local-path.ts +89 -0
- package/src/shared/workspace/types.ts +69 -0
- package/src/shared/zip-extract.ts +193 -0
- package/src/worker.ts +98 -0
- package/src/workflow-engine/__tests__/do-executor-recovery.test.ts +382 -0
- package/src/workflow-engine/__tests__/do-executor.test.ts +963 -0
- package/src/workflow-engine/__tests__/errors.test.ts +174 -0
- package/src/workflow-engine/__tests__/expression.test.ts +776 -0
- package/src/workflow-engine/__tests__/for.test.ts +575 -0
- package/src/workflow-engine/__tests__/fork.test.ts +838 -0
- package/src/workflow-engine/__tests__/golden-execution.test.ts +1085 -0
- package/src/workflow-engine/__tests__/jq-wasm-spike.test.ts +90 -0
- package/src/workflow-engine/__tests__/loader.test.ts +1393 -0
- package/src/workflow-engine/__tests__/pause-resume.test.ts +267 -0
- package/src/workflow-engine/__tests__/recovery.test.ts +115 -0
- package/src/workflow-engine/__tests__/resolve.test.ts +432 -0
- package/src/workflow-engine/__tests__/retry.test.ts +306 -0
- package/src/workflow-engine/__tests__/state.test.ts +174 -0
- package/src/workflow-engine/__tests__/task-status-accumulator.test.ts +373 -0
- package/src/workflow-engine/__tests__/tasks/call-agent-output.test.ts +120 -0
- package/src/workflow-engine/__tests__/tasks/call-agent.test.ts +816 -0
- package/src/workflow-engine/__tests__/tasks/call-function.test.ts +205 -0
- package/src/workflow-engine/__tests__/tasks/call-grpc.test.ts +133 -0
- package/src/workflow-engine/__tests__/tasks/call-http.test.ts +150 -0
- package/src/workflow-engine/__tests__/tasks/emit-event.test.ts +322 -0
- package/src/workflow-engine/__tests__/tasks/human-input.test.ts +416 -0
- package/src/workflow-engine/__tests__/tasks/listen.test.ts +422 -0
- package/src/workflow-engine/__tests__/tasks/raise.test.ts +166 -0
- package/src/workflow-engine/__tests__/tasks/run.test.ts +272 -0
- package/src/workflow-engine/__tests__/tasks/set.test.ts +127 -0
- package/src/workflow-engine/__tests__/tasks/switch.test.ts +277 -0
- package/src/workflow-engine/__tests__/tasks/try.test.ts +590 -0
- package/src/workflow-engine/__tests__/tasks/wait.test.ts +173 -0
- package/src/workflow-engine/clone.ts +18 -0
- package/src/workflow-engine/do-executor.ts +569 -0
- package/src/workflow-engine/duration.ts +22 -0
- package/src/workflow-engine/error-utils.ts +97 -0
- package/src/workflow-engine/errors.ts +130 -0
- package/src/workflow-engine/expression-utils.ts +129 -0
- package/src/workflow-engine/expression.ts +430 -0
- package/src/workflow-engine/loader.ts +524 -0
- package/src/workflow-engine/recovery.ts +80 -0
- package/src/workflow-engine/resolve.ts +342 -0
- package/src/workflow-engine/retry.ts +109 -0
- package/src/workflow-engine/state.ts +56 -0
- package/src/workflow-engine/task-factory.ts +160 -0
- package/src/workflow-engine/task-status-accumulator.ts +204 -0
- package/src/workflow-engine/tasks/call-agent-output.ts +132 -0
- package/src/workflow-engine/tasks/call-agent.ts +221 -0
- package/src/workflow-engine/tasks/call-function.ts +107 -0
- package/src/workflow-engine/tasks/call-grpc.ts +47 -0
- package/src/workflow-engine/tasks/call-http.ts +51 -0
- package/src/workflow-engine/tasks/for.ts +244 -0
- package/src/workflow-engine/tasks/fork.ts +228 -0
- package/src/workflow-engine/tasks/human-input.ts +147 -0
- package/src/workflow-engine/tasks/listen.ts +166 -0
- package/src/workflow-engine/tasks/raise.ts +81 -0
- package/src/workflow-engine/tasks/run.ts +142 -0
- package/src/workflow-engine/tasks/set.ts +47 -0
- package/src/workflow-engine/tasks/switch.ts +102 -0
- package/src/workflow-engine/tasks/try.ts +274 -0
- package/src/workflow-engine/tasks/wait.ts +53 -0
- package/src/workflow-engine/types.ts +911 -0
- package/src/workflows/__tests__/connect-mcp-server.test.ts +359 -0
- package/src/workflows/__tests__/execute-serverless-workflow.test.ts +277 -0
- package/src/workflows/call-agent-orchestrator.ts +283 -0
- package/src/workflows/connect-mcp-server.ts +152 -0
- package/src/workflows/engine-core.ts +406 -0
- package/src/workflows/execute-from-execution.ts +101 -0
- package/src/workflows/execute-serverless-workflow.ts +60 -0
- package/src/workflows/human-input-orchestrator.ts +76 -0
- package/src/workflows/index.ts +32 -0
- package/src/workflows/listen-orchestrator.ts +200 -0
- package/src/workflows/metrics-sink.ts +48 -0
- package/src/workflows/run-orchestrator.ts +34 -0
- package/src/workflows/types.ts +64 -0
- package/src/workflows/workflow-signals.ts +55 -0
|
@@ -0,0 +1,786 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translates Cursor SDK streaming events into Stigmer AgentMessage protos.
|
|
3
|
+
*
|
|
4
|
+
* The Cursor SDK emits SDKMessage events during a Run. This module provides
|
|
5
|
+
* both stateless translation (translateEvent) and stateful accumulation
|
|
6
|
+
* (MessageAccumulator) for building coherent messages from token-level
|
|
7
|
+
* streaming events.
|
|
8
|
+
*
|
|
9
|
+
* The Cursor SDK emits one SDKAssistantMessage per token chunk — a single
|
|
10
|
+
* LLM turn produces dozens of events. MessageAccumulator merges them into
|
|
11
|
+
* a single AgentMessage per turn, matching the Python agent-runner's
|
|
12
|
+
* proven pattern (see chat_model.py handle_chat_model_stream).
|
|
13
|
+
*
|
|
14
|
+
* Tool calls are attached to the most recent MESSAGE_AI message rather
|
|
15
|
+
* than emitted as standalone MESSAGE_TOOL messages. This matches:
|
|
16
|
+
* - The proto model (AgentMessage.tool_calls repeated field)
|
|
17
|
+
* - The Python agent-runner's StatusBuilder pattern
|
|
18
|
+
* - The UI's MessageThread expectation (tool calls on AI messages)
|
|
19
|
+
*
|
|
20
|
+
* Task (sub-agent) tool calls additionally produce SubAgentExecution
|
|
21
|
+
* protos accessible via MessageAccumulator.subAgentExecutions.
|
|
22
|
+
*
|
|
23
|
+
* MCP tool enrichment:
|
|
24
|
+
* Cursor reports MCP tool calls with name="mcp" and the actual details
|
|
25
|
+
* (providerIdentifier, toolName, args) inside event.args. This module
|
|
26
|
+
* extracts those details to populate the ToolCall proto with:
|
|
27
|
+
* - name: the actual MCP tool name (e.g., "search_services")
|
|
28
|
+
* - mcpServerSlug: the MCP server identifier (e.g., "planton")
|
|
29
|
+
* - requiresApproval: from the merged policy chain
|
|
30
|
+
* - approvalMessage: from the policy, with placeholder resolution
|
|
31
|
+
*/
|
|
32
|
+
import { create } from "@bufbuild/protobuf";
|
|
33
|
+
import { AgentMessageSchema, ToolCallSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/message_pb";
|
|
34
|
+
import { SubAgentExecutionSchema } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/subagent_pb";
|
|
35
|
+
import { MessageType, ToolCallStatus, SubAgentStatus } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
36
|
+
import { lookupMcpToolPolicy, resolveApprovalMessage, builtInRequiresApproval, getBuiltInApprovalMessage, extractArgKey } from "./approval-policy.js";
|
|
37
|
+
import { grantToken } from "./approval-state.js";
|
|
38
|
+
import { utcTimestamp } from "../../shared/status.js";
|
|
39
|
+
import { classifyTool } from "../../shared/tool-kind.js";
|
|
40
|
+
export { utcTimestamp };
|
|
41
|
+
const SUPPRESSED_TOOL_NAMES = new Set(["TodoWrite", "updateTodos"]);
|
|
42
|
+
/**
|
|
43
|
+
* Try to extract MCP tool details from a tool_call event.
|
|
44
|
+
* Returns undefined if the event is not an MCP tool call.
|
|
45
|
+
*/
|
|
46
|
+
export function extractMcpToolDetails(event) {
|
|
47
|
+
if (event.name !== "mcp")
|
|
48
|
+
return undefined;
|
|
49
|
+
const args = event.args;
|
|
50
|
+
if (args == null || typeof args !== "object")
|
|
51
|
+
return undefined;
|
|
52
|
+
const obj = args;
|
|
53
|
+
const providerIdentifier = typeof obj.providerIdentifier === "string" ? obj.providerIdentifier : "";
|
|
54
|
+
const toolName = typeof obj.toolName === "string" ? obj.toolName : "";
|
|
55
|
+
if (!toolName)
|
|
56
|
+
return undefined;
|
|
57
|
+
const innerArgs = (typeof obj.args === "object" && obj.args !== null)
|
|
58
|
+
? obj.args
|
|
59
|
+
: {};
|
|
60
|
+
return { providerIdentifier, toolName, innerArgs };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Translate a single Cursor SDKMessage into zero or more Stigmer AgentMessages.
|
|
64
|
+
*
|
|
65
|
+
* Most events produce exactly one message. Some (like system init) are
|
|
66
|
+
* informational and produce none.
|
|
67
|
+
*
|
|
68
|
+
* Note: for production streaming, use MessageAccumulator instead — it
|
|
69
|
+
* merges token-level events and attaches tool calls to their parent AI
|
|
70
|
+
* messages. This stateless function is retained for unit testing and
|
|
71
|
+
* simple single-event translation.
|
|
72
|
+
*/
|
|
73
|
+
export function translateEvent(event) {
|
|
74
|
+
switch (event.type) {
|
|
75
|
+
case "assistant":
|
|
76
|
+
return [translateAssistant(event)];
|
|
77
|
+
case "thinking":
|
|
78
|
+
return [translateThinking(event)];
|
|
79
|
+
case "tool_call":
|
|
80
|
+
return [translateToolCall(event)];
|
|
81
|
+
case "task":
|
|
82
|
+
return event.text ? [translateTask(event)] : [];
|
|
83
|
+
case "system":
|
|
84
|
+
case "status":
|
|
85
|
+
case "user":
|
|
86
|
+
case "request":
|
|
87
|
+
return [];
|
|
88
|
+
default:
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function translateAssistant(event) {
|
|
93
|
+
const textBlocks = event.message.content
|
|
94
|
+
.filter((b) => b.type === "text")
|
|
95
|
+
.map((b) => b.text);
|
|
96
|
+
return create(AgentMessageSchema, {
|
|
97
|
+
type: MessageType.MESSAGE_AI,
|
|
98
|
+
content: textBlocks.join(""),
|
|
99
|
+
timestamp: utcTimestamp(),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function translateThinking(event) {
|
|
103
|
+
return create(AgentMessageSchema, {
|
|
104
|
+
type: MessageType.MESSAGE_THINKING,
|
|
105
|
+
content: event.text,
|
|
106
|
+
timestamp: utcTimestamp(),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Stateless translation of a tool_call event into a standalone MESSAGE_TOOL
|
|
111
|
+
* message. Retained for backward compatibility with translateEvent() and
|
|
112
|
+
* tests that use the stateless API.
|
|
113
|
+
*/
|
|
114
|
+
function translateToolCall(event) {
|
|
115
|
+
const toolCall = buildToolCallProto(event);
|
|
116
|
+
const displayName = toolCall.mcpServerSlug
|
|
117
|
+
? `${toolCall.mcpServerSlug}/${toolCall.name}`
|
|
118
|
+
: toolCall.name;
|
|
119
|
+
return create(AgentMessageSchema, {
|
|
120
|
+
type: MessageType.MESSAGE_TOOL,
|
|
121
|
+
content: `Tool: ${displayName} [${event.status}]`,
|
|
122
|
+
timestamp: utcTimestamp(),
|
|
123
|
+
toolCalls: [toolCall],
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Build a ToolCall proto from a Cursor SDK tool_call event.
|
|
128
|
+
*
|
|
129
|
+
* For MCP tools (event.name === "mcp"), extracts the actual tool name
|
|
130
|
+
* and server slug from event.args. For built-in tools, uses the event
|
|
131
|
+
* name directly.
|
|
132
|
+
*
|
|
133
|
+
* Approval fields are populated when mergedPolicies are provided.
|
|
134
|
+
* Without policies, only basic fields are set (backward compatible).
|
|
135
|
+
*/
|
|
136
|
+
export function buildToolCallProto(event, mergedPolicies) {
|
|
137
|
+
const status = mapToolCallStatus(event.status);
|
|
138
|
+
const mcpDetails = extractMcpToolDetails(event);
|
|
139
|
+
const actualName = mcpDetails?.toolName ?? event.name;
|
|
140
|
+
const mcpServerSlug = mcpDetails?.providerIdentifier ?? "";
|
|
141
|
+
const toolCall = create(ToolCallSchema, {
|
|
142
|
+
id: event.call_id,
|
|
143
|
+
name: actualName,
|
|
144
|
+
status,
|
|
145
|
+
startedAt: status === ToolCallStatus.TOOL_CALL_RUNNING ? utcTimestamp() : "",
|
|
146
|
+
completedAt: isTerminalToolStatus(status) ? utcTimestamp() : "",
|
|
147
|
+
result: typeof event.result === "string" ? event.result : JSON.stringify(event.result ?? ""),
|
|
148
|
+
error: status === ToolCallStatus.TOOL_CALL_FAILED
|
|
149
|
+
? (typeof event.result === "string" ? event.result : "Tool call failed")
|
|
150
|
+
: "",
|
|
151
|
+
mcpServerSlug,
|
|
152
|
+
toolKind: classifyTool(actualName, mcpServerSlug),
|
|
153
|
+
});
|
|
154
|
+
if (event.args != null) {
|
|
155
|
+
toolCall.argsPreview = typeof event.args === "string"
|
|
156
|
+
? event.args
|
|
157
|
+
: JSON.stringify(event.args);
|
|
158
|
+
}
|
|
159
|
+
const argsObj = mcpDetails?.innerArgs ?? (typeof event.args === "object" && event.args !== null
|
|
160
|
+
? event.args
|
|
161
|
+
: undefined);
|
|
162
|
+
if (argsObj && typeof argsObj === "object") {
|
|
163
|
+
toolCall.args = argsObj;
|
|
164
|
+
}
|
|
165
|
+
// Populate approval fields from the merged policy chain
|
|
166
|
+
if (mergedPolicies && mcpDetails) {
|
|
167
|
+
const policy = lookupMcpToolPolicy(actualName, mcpServerSlug, mergedPolicies);
|
|
168
|
+
if (policy) {
|
|
169
|
+
toolCall.requiresApproval = true;
|
|
170
|
+
toolCall.approvalMessage = resolveApprovalMessage(policy.approvalMessage, actualName, mcpDetails.innerArgs);
|
|
171
|
+
if (status === ToolCallStatus.TOOL_CALL_FAILED) {
|
|
172
|
+
toolCall.approvalRequestedAt = utcTimestamp();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else if (mergedPolicies && !mcpDetails) {
|
|
177
|
+
const requires = builtInRequiresApproval(actualName);
|
|
178
|
+
toolCall.requiresApproval = requires;
|
|
179
|
+
if (requires) {
|
|
180
|
+
const template = getBuiltInApprovalMessage(actualName);
|
|
181
|
+
if (template) {
|
|
182
|
+
toolCall.approvalMessage = resolveApprovalMessage(template, actualName, argsObj ?? {});
|
|
183
|
+
if (status === ToolCallStatus.TOOL_CALL_FAILED) {
|
|
184
|
+
toolCall.approvalRequestedAt = utcTimestamp();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return toolCall;
|
|
190
|
+
}
|
|
191
|
+
function translateTask(event) {
|
|
192
|
+
return create(AgentMessageSchema, {
|
|
193
|
+
type: MessageType.MESSAGE_SYSTEM,
|
|
194
|
+
content: event.text ?? "",
|
|
195
|
+
timestamp: utcTimestamp(),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function mapToolCallStatus(cursorStatus) {
|
|
199
|
+
switch (cursorStatus) {
|
|
200
|
+
case "running":
|
|
201
|
+
return ToolCallStatus.TOOL_CALL_RUNNING;
|
|
202
|
+
case "completed":
|
|
203
|
+
return ToolCallStatus.TOOL_CALL_COMPLETED;
|
|
204
|
+
case "error":
|
|
205
|
+
return ToolCallStatus.TOOL_CALL_FAILED;
|
|
206
|
+
default:
|
|
207
|
+
return ToolCallStatus.TOOL_CALL_STATUS_UNSPECIFIED;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function mapSubAgentStatus(cursorStatus) {
|
|
211
|
+
switch (cursorStatus) {
|
|
212
|
+
case "running":
|
|
213
|
+
return SubAgentStatus.SUB_AGENT_IN_PROGRESS;
|
|
214
|
+
case "completed":
|
|
215
|
+
return SubAgentStatus.SUB_AGENT_COMPLETED;
|
|
216
|
+
case "error":
|
|
217
|
+
return SubAgentStatus.SUB_AGENT_FAILED;
|
|
218
|
+
default:
|
|
219
|
+
return SubAgentStatus.SUB_AGENT_PENDING;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function isTerminalToolStatus(status) {
|
|
223
|
+
return (status === ToolCallStatus.TOOL_CALL_COMPLETED ||
|
|
224
|
+
status === ToolCallStatus.TOOL_CALL_FAILED ||
|
|
225
|
+
status === ToolCallStatus.TOOL_CALL_SKIPPED);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Extract sub-agent name from task tool args, handling both the
|
|
229
|
+
* legacy string format (`"generalPurpose"`) and the current SDK
|
|
230
|
+
* object format (`{ kind: "generalPurpose", name?: "..." }`).
|
|
231
|
+
*
|
|
232
|
+
* Falls back to `description` (always populated by the SDK) before
|
|
233
|
+
* returning the generic `"task"`. The `kind` value `"unspecified"`
|
|
234
|
+
* is treated as absent since the Cursor SDK uses it as a default
|
|
235
|
+
* when the sub-agent type is not specified in the blueprint.
|
|
236
|
+
*/
|
|
237
|
+
function extractSubagentName(args) {
|
|
238
|
+
if (args == null || typeof args !== "object")
|
|
239
|
+
return "task";
|
|
240
|
+
const obj = args;
|
|
241
|
+
const subagentType = obj.subagentType ?? obj.subagent_type;
|
|
242
|
+
if (typeof subagentType === "string" && subagentType)
|
|
243
|
+
return subagentType;
|
|
244
|
+
if (subagentType != null && typeof subagentType === "object") {
|
|
245
|
+
const typed = subagentType;
|
|
246
|
+
if (typeof typed.name === "string" && typed.name)
|
|
247
|
+
return typed.name;
|
|
248
|
+
if (typeof typed.kind === "string" && typed.kind && typed.kind !== "unspecified") {
|
|
249
|
+
return typed.kind;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (typeof obj.description === "string" && obj.description)
|
|
253
|
+
return obj.description;
|
|
254
|
+
return "task";
|
|
255
|
+
}
|
|
256
|
+
function safeString(obj, key) {
|
|
257
|
+
if (obj != null && typeof obj === "object" && key in obj) {
|
|
258
|
+
const val = obj[key];
|
|
259
|
+
return typeof val === "string" ? val : "";
|
|
260
|
+
}
|
|
261
|
+
return "";
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Parse the task tool's completed result into AgentMessages.
|
|
265
|
+
*
|
|
266
|
+
* The Cursor SDK returns sub-agent work as a blob in the task tool's
|
|
267
|
+
* completed event (not as streaming events with a distinct agent_id).
|
|
268
|
+
* The result shape is:
|
|
269
|
+
*
|
|
270
|
+
* { status: "success", value: { conversationSteps: ConversationStep[] } }
|
|
271
|
+
*
|
|
272
|
+
* where ConversationStep is a discriminated union:
|
|
273
|
+
* - { type: "thinkingMessage", message: { text, thinkingDurationMs? } }
|
|
274
|
+
* - { type: "assistantMessage", message: { text } }
|
|
275
|
+
* - { type: "toolCall", message: { type, args, result?, ... } }
|
|
276
|
+
*
|
|
277
|
+
* This function defensively parses whatever steps are present and
|
|
278
|
+
* appends corresponding AgentMessage protos to the output array.
|
|
279
|
+
* Unknown step types are silently skipped for forward compatibility.
|
|
280
|
+
*/
|
|
281
|
+
export function extractConversationSteps(result, out) {
|
|
282
|
+
if (result == null || typeof result !== "object")
|
|
283
|
+
return;
|
|
284
|
+
const r = result;
|
|
285
|
+
const value = r.value ?? r;
|
|
286
|
+
if (value == null || typeof value !== "object")
|
|
287
|
+
return;
|
|
288
|
+
const v = value;
|
|
289
|
+
const steps = v.conversationSteps;
|
|
290
|
+
if (!Array.isArray(steps))
|
|
291
|
+
return;
|
|
292
|
+
for (const step of steps) {
|
|
293
|
+
if (step == null || typeof step !== "object")
|
|
294
|
+
continue;
|
|
295
|
+
const s = step;
|
|
296
|
+
const type = s.type;
|
|
297
|
+
if (type === "thinkingMessage" || s.thinkingMessage != null) {
|
|
298
|
+
const msg = (type === "thinkingMessage" ? s.message : s.thinkingMessage);
|
|
299
|
+
const text = typeof msg?.text === "string" ? msg.text : "";
|
|
300
|
+
if (text) {
|
|
301
|
+
out.push(create(AgentMessageSchema, {
|
|
302
|
+
type: MessageType.MESSAGE_THINKING,
|
|
303
|
+
content: text,
|
|
304
|
+
timestamp: utcTimestamp(),
|
|
305
|
+
}));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else if (type === "assistantMessage" || s.assistantMessage != null) {
|
|
309
|
+
const msg = (type === "assistantMessage" ? s.message : s.assistantMessage);
|
|
310
|
+
const text = typeof msg?.text === "string" ? msg.text : "";
|
|
311
|
+
if (text) {
|
|
312
|
+
out.push(create(AgentMessageSchema, {
|
|
313
|
+
type: MessageType.MESSAGE_AI,
|
|
314
|
+
content: text,
|
|
315
|
+
timestamp: utcTimestamp(),
|
|
316
|
+
}));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
else if (type === "toolCall") {
|
|
320
|
+
const msg = s.message;
|
|
321
|
+
if (msg) {
|
|
322
|
+
const toolName = typeof msg.type === "string" ? msg.type : "unknown";
|
|
323
|
+
const toolArgs = msg.args != null ? JSON.stringify(msg.args) : "";
|
|
324
|
+
let toolResult = "";
|
|
325
|
+
if (msg.result != null) {
|
|
326
|
+
const resultObj = msg.result;
|
|
327
|
+
if (resultObj.status === "success" && resultObj.value != null) {
|
|
328
|
+
toolResult = typeof resultObj.value === "string"
|
|
329
|
+
? resultObj.value
|
|
330
|
+
: JSON.stringify(resultObj.value);
|
|
331
|
+
}
|
|
332
|
+
else if (resultObj.status === "error") {
|
|
333
|
+
toolResult = typeof resultObj.error === "string"
|
|
334
|
+
? resultObj.error
|
|
335
|
+
: JSON.stringify(resultObj);
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
toolResult = JSON.stringify(msg.result);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const aiMsg = create(AgentMessageSchema, {
|
|
342
|
+
type: MessageType.MESSAGE_AI,
|
|
343
|
+
content: "",
|
|
344
|
+
timestamp: utcTimestamp(),
|
|
345
|
+
toolCalls: [create(ToolCallSchema, {
|
|
346
|
+
id: `sub-${toolName}-${out.length}`,
|
|
347
|
+
name: toolName,
|
|
348
|
+
status: ToolCallStatus.TOOL_CALL_COMPLETED,
|
|
349
|
+
argsPreview: toolArgs,
|
|
350
|
+
result: toolResult,
|
|
351
|
+
startedAt: utcTimestamp(),
|
|
352
|
+
completedAt: utcTimestamp(),
|
|
353
|
+
toolKind: classifyTool(toolName),
|
|
354
|
+
})],
|
|
355
|
+
});
|
|
356
|
+
out.push(aiMsg);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Stateful accumulator that merges per-token SDK events into coherent
|
|
363
|
+
* AgentMessages.
|
|
364
|
+
*
|
|
365
|
+
* The Cursor SDK emits one `assistant` event per token chunk (validated:
|
|
366
|
+
* a 2-sentence response produces ~41 events). Without accumulation each
|
|
367
|
+
* chunk becomes a separate AgentMessage, causing the UI to render each
|
|
368
|
+
* word on its own line.
|
|
369
|
+
*
|
|
370
|
+
* MessageAccumulator tracks the active AI and thinking messages per
|
|
371
|
+
* run_id. Consecutive assistant events for the same run_id append to
|
|
372
|
+
* the existing message's content instead of creating new ones.
|
|
373
|
+
*
|
|
374
|
+
* Tool calls are attached to the most recent MESSAGE_AI message's
|
|
375
|
+
* toolCalls array — matching the Python agent-runner's StatusBuilder
|
|
376
|
+
* pattern and the UI's MessageThread expectations.
|
|
377
|
+
*
|
|
378
|
+
* Tool call lifecycle is tracked via a `toolCallIndex` map (keyed by
|
|
379
|
+
* call_id), mirroring the native harness's `ExecutionState.toolCalls`.
|
|
380
|
+
* This ensures completion events always find the correct ToolCall proto
|
|
381
|
+
* regardless of which AI message it was originally attached to — the
|
|
382
|
+
* index stores the same object reference that lives in the message's
|
|
383
|
+
* `toolCalls[]` array, so mutations propagate directly to the proto.
|
|
384
|
+
*
|
|
385
|
+
* Task (sub-agent) tool calls additionally produce SubAgentExecution
|
|
386
|
+
* protos, accessible via the subAgentExecutions getter.
|
|
387
|
+
*/
|
|
388
|
+
/**
|
|
389
|
+
* Transition any non-terminal sub-agent (IN_PROGRESS or PENDING) in the given
|
|
390
|
+
* proto array to CANCELLED with a completion timestamp, in place.
|
|
391
|
+
*
|
|
392
|
+
* Operates directly on the status array (not the accumulator) because the
|
|
393
|
+
* Cursor cancellation exception unwinds out of the streaming loop into the
|
|
394
|
+
* activity's catch block, where the MessageAccumulator is out of scope. Returns
|
|
395
|
+
* true if any sub-agent changed.
|
|
396
|
+
*/
|
|
397
|
+
export function cancelInProgressSubAgentProtos(subAgents) {
|
|
398
|
+
let changed = false;
|
|
399
|
+
for (const sub of subAgents) {
|
|
400
|
+
if (sub.status === SubAgentStatus.SUB_AGENT_IN_PROGRESS ||
|
|
401
|
+
sub.status === SubAgentStatus.SUB_AGENT_PENDING) {
|
|
402
|
+
sub.status = SubAgentStatus.SUB_AGENT_CANCELLED;
|
|
403
|
+
sub.completedAt = utcTimestamp();
|
|
404
|
+
changed = true;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return changed;
|
|
408
|
+
}
|
|
409
|
+
export class MessageAccumulator {
|
|
410
|
+
messages;
|
|
411
|
+
activeAiByRunId = new Map();
|
|
412
|
+
activeThinkingByRunId = new Map();
|
|
413
|
+
_subAgentExecutions = [];
|
|
414
|
+
subAgentMap = new Map();
|
|
415
|
+
mergedPolicies;
|
|
416
|
+
toolCallIndex = new Map();
|
|
417
|
+
_subAgentDirty = false;
|
|
418
|
+
constructor(messages, options) {
|
|
419
|
+
this.messages = messages;
|
|
420
|
+
this.mergedPolicies = options?.mergedPolicies;
|
|
421
|
+
}
|
|
422
|
+
get subAgentExecutions() {
|
|
423
|
+
return this._subAgentExecutions;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* True when a sub-agent execution has been created or updated since the last
|
|
427
|
+
* markSubAgentPersisted(). The streaming loop uses this to trigger a persist
|
|
428
|
+
* promptly when delegation begins (the "task" running event), so the live UI
|
|
429
|
+
* surfaces the sub-agent's IN_PROGRESS state instead of showing no activity
|
|
430
|
+
* until the parent finalizes.
|
|
431
|
+
*/
|
|
432
|
+
get subAgentDirty() {
|
|
433
|
+
return this._subAgentDirty;
|
|
434
|
+
}
|
|
435
|
+
/** Clears the sub-agent dirty flag after the latest status has been persisted. */
|
|
436
|
+
markSubAgentPersisted() {
|
|
437
|
+
this._subAgentDirty = false;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Transition any non-terminal sub-agent (IN_PROGRESS or PENDING) to CANCELLED.
|
|
441
|
+
*
|
|
442
|
+
* Called when the parent run is aborted (pause / cancel / worker shutdown):
|
|
443
|
+
* the Cursor SDK run stops, so a delegated sub-agent is no longer executing.
|
|
444
|
+
* Without this, the final snapshot would show a permanent "Running" zombie
|
|
445
|
+
* sub-agent. Mirrors the native harness's cancelSubAgents().
|
|
446
|
+
*/
|
|
447
|
+
cancelInProgressSubAgents() {
|
|
448
|
+
if (cancelInProgressSubAgentProtos(this._subAgentExecutions)) {
|
|
449
|
+
this._subAgentDirty = true;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
processEvent(event) {
|
|
453
|
+
switch (event.type) {
|
|
454
|
+
case "assistant":
|
|
455
|
+
this.accumulateAssistant(event);
|
|
456
|
+
break;
|
|
457
|
+
case "thinking":
|
|
458
|
+
this.accumulateThinking(event);
|
|
459
|
+
break;
|
|
460
|
+
case "tool_call":
|
|
461
|
+
this.finalizeStreaming(event.run_id);
|
|
462
|
+
this.attachToolCallToLastAi(event);
|
|
463
|
+
break;
|
|
464
|
+
case "task":
|
|
465
|
+
if (event.text) {
|
|
466
|
+
this.messages.push(translateTask(event));
|
|
467
|
+
}
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
finalize() {
|
|
472
|
+
for (const msg of this.activeAiByRunId.values()) {
|
|
473
|
+
msg.isStreaming = false;
|
|
474
|
+
}
|
|
475
|
+
for (const msg of this.activeThinkingByRunId.values()) {
|
|
476
|
+
msg.isStreaming = false;
|
|
477
|
+
}
|
|
478
|
+
this.activeAiByRunId.clear();
|
|
479
|
+
this.activeThinkingByRunId.clear();
|
|
480
|
+
}
|
|
481
|
+
attachToolCallToLastAi(event) {
|
|
482
|
+
if (SUPPRESSED_TOOL_NAMES.has(event.name))
|
|
483
|
+
return;
|
|
484
|
+
const status = mapToolCallStatus(event.status);
|
|
485
|
+
if (event.status === "running") {
|
|
486
|
+
const aiMsg = this.findOrCreateLastAiMessage();
|
|
487
|
+
const tc = buildToolCallProto(event, this.mergedPolicies);
|
|
488
|
+
aiMsg.toolCalls.push(tc);
|
|
489
|
+
this.toolCallIndex.set(event.call_id, tc);
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
const existing = this.toolCallIndex.get(event.call_id);
|
|
493
|
+
if (existing) {
|
|
494
|
+
existing.status = status;
|
|
495
|
+
if (isTerminalToolStatus(status)) {
|
|
496
|
+
existing.completedAt = utcTimestamp();
|
|
497
|
+
}
|
|
498
|
+
if (event.result != null) {
|
|
499
|
+
existing.result = typeof event.result === "string"
|
|
500
|
+
? event.result
|
|
501
|
+
: JSON.stringify(event.result);
|
|
502
|
+
}
|
|
503
|
+
if (status === ToolCallStatus.TOOL_CALL_FAILED) {
|
|
504
|
+
existing.error = typeof event.result === "string"
|
|
505
|
+
? event.result
|
|
506
|
+
: "Tool call failed";
|
|
507
|
+
if (existing.requiresApproval) {
|
|
508
|
+
existing.approvalRequestedAt = utcTimestamp();
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (event.args != null && !existing.argsPreview) {
|
|
512
|
+
existing.argsPreview = typeof event.args === "string"
|
|
513
|
+
? event.args
|
|
514
|
+
: JSON.stringify(event.args);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
const aiMsg = this.findOrCreateLastAiMessage();
|
|
519
|
+
const tc = buildToolCallProto(event, this.mergedPolicies);
|
|
520
|
+
aiMsg.toolCalls.push(tc);
|
|
521
|
+
this.toolCallIndex.set(event.call_id, tc);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
findOrCreateLastAiMessage() {
|
|
526
|
+
for (let i = this.messages.length - 1; i >= 0; i--) {
|
|
527
|
+
if (this.messages[i].type === MessageType.MESSAGE_AI) {
|
|
528
|
+
return this.messages[i];
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
const msg = create(AgentMessageSchema, {
|
|
532
|
+
type: MessageType.MESSAGE_AI,
|
|
533
|
+
content: "",
|
|
534
|
+
timestamp: utcTimestamp(),
|
|
535
|
+
});
|
|
536
|
+
this.messages.push(msg);
|
|
537
|
+
return msg;
|
|
538
|
+
}
|
|
539
|
+
trackSubAgentExecution(event) {
|
|
540
|
+
const existing = this.subAgentMap.get(event.call_id);
|
|
541
|
+
if (existing) {
|
|
542
|
+
existing.status = mapSubAgentStatus(event.status);
|
|
543
|
+
if (event.status === "completed" || event.status === "error") {
|
|
544
|
+
existing.completedAt = utcTimestamp();
|
|
545
|
+
}
|
|
546
|
+
if (event.status === "completed" && event.result != null) {
|
|
547
|
+
existing.output = typeof event.result === "string"
|
|
548
|
+
? event.result
|
|
549
|
+
: JSON.stringify(event.result);
|
|
550
|
+
extractConversationSteps(event.result, existing.messages);
|
|
551
|
+
}
|
|
552
|
+
if (event.status === "error") {
|
|
553
|
+
existing.error = typeof event.result === "string"
|
|
554
|
+
? event.result
|
|
555
|
+
: "Sub-agent failed";
|
|
556
|
+
}
|
|
557
|
+
this._subAgentDirty = true;
|
|
558
|
+
return existing;
|
|
559
|
+
}
|
|
560
|
+
const sub = create(SubAgentExecutionSchema, {
|
|
561
|
+
id: event.call_id,
|
|
562
|
+
name: extractSubagentName(event.args),
|
|
563
|
+
subject: safeString(event.args, "description"),
|
|
564
|
+
input: safeString(event.args, "prompt"),
|
|
565
|
+
status: mapSubAgentStatus(event.status),
|
|
566
|
+
startedAt: utcTimestamp(),
|
|
567
|
+
});
|
|
568
|
+
this._subAgentExecutions.push(sub);
|
|
569
|
+
this.subAgentMap.set(event.call_id, sub);
|
|
570
|
+
this._subAgentDirty = true;
|
|
571
|
+
return sub;
|
|
572
|
+
}
|
|
573
|
+
accumulateAssistant(event) {
|
|
574
|
+
const text = event.message.content
|
|
575
|
+
.filter((b) => b.type === "text")
|
|
576
|
+
.map((b) => b.text)
|
|
577
|
+
.join("");
|
|
578
|
+
if (!text)
|
|
579
|
+
return;
|
|
580
|
+
const existing = this.activeAiByRunId.get(event.run_id);
|
|
581
|
+
if (existing) {
|
|
582
|
+
existing.content += text;
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const msg = create(AgentMessageSchema, {
|
|
586
|
+
type: MessageType.MESSAGE_AI,
|
|
587
|
+
content: text,
|
|
588
|
+
timestamp: utcTimestamp(),
|
|
589
|
+
isStreaming: true,
|
|
590
|
+
});
|
|
591
|
+
this.messages.push(msg);
|
|
592
|
+
this.activeAiByRunId.set(event.run_id, msg);
|
|
593
|
+
}
|
|
594
|
+
accumulateThinking(event) {
|
|
595
|
+
if (!event.text)
|
|
596
|
+
return;
|
|
597
|
+
const existing = this.activeThinkingByRunId.get(event.run_id);
|
|
598
|
+
if (existing) {
|
|
599
|
+
existing.content += event.text;
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
const msg = create(AgentMessageSchema, {
|
|
603
|
+
type: MessageType.MESSAGE_THINKING,
|
|
604
|
+
content: event.text,
|
|
605
|
+
timestamp: utcTimestamp(),
|
|
606
|
+
isStreaming: true,
|
|
607
|
+
});
|
|
608
|
+
this.messages.push(msg);
|
|
609
|
+
this.activeThinkingByRunId.set(event.run_id, msg);
|
|
610
|
+
}
|
|
611
|
+
finalizeStreaming(runId) {
|
|
612
|
+
const ai = this.activeAiByRunId.get(runId);
|
|
613
|
+
if (ai) {
|
|
614
|
+
ai.isStreaming = false;
|
|
615
|
+
this.activeAiByRunId.delete(runId);
|
|
616
|
+
}
|
|
617
|
+
const thinking = this.activeThinkingByRunId.get(runId);
|
|
618
|
+
if (thinking) {
|
|
619
|
+
thinking.isStreaming = false;
|
|
620
|
+
this.activeThinkingByRunId.delete(runId);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Reconcile the denial ledger written by the preToolUse hook against the tool
|
|
626
|
+
* calls accumulated from the stream, marking each denied call as
|
|
627
|
+
* WAITING_APPROVAL.
|
|
628
|
+
*
|
|
629
|
+
* This is the cursor analog of the native harness synthesizing WAITING_APPROVAL
|
|
630
|
+
* tool calls from LangGraph interrupts (execute-deep-agent/index.ts). The hook
|
|
631
|
+
* ledger — not the SDK-reported tool status — is the authoritative record of
|
|
632
|
+
* what was gated, because the hook is the only component that makes the per-call
|
|
633
|
+
* allow/deny decision. The backend then projects pending_approvals from these
|
|
634
|
+
* WAITING_APPROVAL tool calls (PendingApprovalComputer), so the approval surface
|
|
635
|
+
* is driven entirely by tool-call status, exactly like the native harness.
|
|
636
|
+
*
|
|
637
|
+
* Correlation is by tool identity token (the same space as approvedGrantTokens),
|
|
638
|
+
* not by call id: a denied tool's identity is stable, and a single resource
|
|
639
|
+
* approved once should produce one approval regardless of how many times the
|
|
640
|
+
* agent re-attempted it within the turn.
|
|
641
|
+
*
|
|
642
|
+
* If a ledger denial has no matching streamed tool call (rare — Cursor normally
|
|
643
|
+
* emits a tool_call event for every attempt), a placeholder WAITING_APPROVAL
|
|
644
|
+
* tool call is synthesized so the gate still surfaces and never renders as a
|
|
645
|
+
* silent success.
|
|
646
|
+
*
|
|
647
|
+
* Returns the tool calls now marked WAITING_APPROVAL (overlaid + synthesized).
|
|
648
|
+
*/
|
|
649
|
+
export function reconcileDeniedToolCalls(messages, ledger, mergedPolicies) {
|
|
650
|
+
if (ledger.length === 0)
|
|
651
|
+
return [];
|
|
652
|
+
// One approval per denied identity; a resource re-attempted within the turn
|
|
653
|
+
// is gated under the same token and collapses to a single approval.
|
|
654
|
+
const deniedTokens = new Set(ledger.map((e) => e.token));
|
|
655
|
+
const matched = new Set();
|
|
656
|
+
const result = [];
|
|
657
|
+
// 1. Overlay WAITING_APPROVAL onto the streamed tool calls that were denied.
|
|
658
|
+
for (const msg of messages) {
|
|
659
|
+
for (const tc of msg.toolCalls) {
|
|
660
|
+
const token = toolCallIdentityToken(tc);
|
|
661
|
+
if (!deniedTokens.has(token) || matched.has(token))
|
|
662
|
+
continue;
|
|
663
|
+
markWaitingApproval(tc, mergedPolicies);
|
|
664
|
+
matched.add(token);
|
|
665
|
+
result.push(tc);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
// 2. Synthesize a tool call for any denial that never produced a stream event.
|
|
669
|
+
for (const entry of ledger) {
|
|
670
|
+
if (matched.has(entry.token))
|
|
671
|
+
continue;
|
|
672
|
+
const decoded = decodeIdentityToken(entry.token);
|
|
673
|
+
const name = decoded?.name || entry.toolName || "tool";
|
|
674
|
+
const argKey = decoded?.argKey ?? "";
|
|
675
|
+
const tc = synthesizeWaitingApprovalToolCall(name, argKey, mergedPolicies);
|
|
676
|
+
appendToolCallToLastAiMessage(messages, tc);
|
|
677
|
+
matched.add(entry.token);
|
|
678
|
+
result.push(tc);
|
|
679
|
+
}
|
|
680
|
+
return result;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Compute a tool call's identity token in the same space the preToolUse hook
|
|
684
|
+
* uses (grantToken: base64 of `toolName \n salientArg`). Mirrors the hook's
|
|
685
|
+
* choice: MCP tools are name-only (no top-level salient arg in the hook input,
|
|
686
|
+
* matching the grant convention); built-in tools key on their salient arg.
|
|
687
|
+
*/
|
|
688
|
+
function toolCallIdentityToken(tc) {
|
|
689
|
+
const argKey = tc.mcpServerSlug ? "" : extractArgKey(toolCallArgs(tc));
|
|
690
|
+
return grantToken(tc.name, argKey);
|
|
691
|
+
}
|
|
692
|
+
/** Decode a `grantToken` back into its (name, argKey) for synthesis fallback. */
|
|
693
|
+
function decodeIdentityToken(token) {
|
|
694
|
+
try {
|
|
695
|
+
const decoded = Buffer.from(token, "base64").toString("utf-8");
|
|
696
|
+
const nl = decoded.indexOf("\n");
|
|
697
|
+
if (nl < 0)
|
|
698
|
+
return undefined;
|
|
699
|
+
return { name: decoded.slice(0, nl), argKey: decoded.slice(nl + 1) };
|
|
700
|
+
}
|
|
701
|
+
catch {
|
|
702
|
+
return undefined;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
/** Best-effort args record for a tool call (proto struct, else parsed preview). */
|
|
706
|
+
function toolCallArgs(tc) {
|
|
707
|
+
if (tc.args && typeof tc.args === "object") {
|
|
708
|
+
return tc.args;
|
|
709
|
+
}
|
|
710
|
+
if (tc.argsPreview) {
|
|
711
|
+
try {
|
|
712
|
+
const parsed = JSON.parse(tc.argsPreview);
|
|
713
|
+
if (parsed && typeof parsed === "object")
|
|
714
|
+
return parsed;
|
|
715
|
+
}
|
|
716
|
+
catch {
|
|
717
|
+
// fall through
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return {};
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Mark a denied tool call as awaiting approval, clearing the result/terminal
|
|
724
|
+
* fields the stream may have set (the tool never actually ran — it was gated).
|
|
725
|
+
*/
|
|
726
|
+
function markWaitingApproval(tc, mergedPolicies) {
|
|
727
|
+
tc.status = ToolCallStatus.TOOL_CALL_WAITING_APPROVAL;
|
|
728
|
+
tc.requiresApproval = true;
|
|
729
|
+
if (!tc.approvalMessage) {
|
|
730
|
+
tc.approvalMessage = resolveDeniedApprovalMessage(tc.name, tc.mcpServerSlug, toolCallArgs(tc), mergedPolicies);
|
|
731
|
+
}
|
|
732
|
+
if (!tc.approvalRequestedAt)
|
|
733
|
+
tc.approvalRequestedAt = utcTimestamp();
|
|
734
|
+
tc.completedAt = "";
|
|
735
|
+
tc.error = "";
|
|
736
|
+
tc.result = "";
|
|
737
|
+
}
|
|
738
|
+
function synthesizeWaitingApprovalToolCall(name, argKey, mergedPolicies) {
|
|
739
|
+
const tc = create(ToolCallSchema, {
|
|
740
|
+
id: `approval:${grantToken(name, argKey)}`,
|
|
741
|
+
name,
|
|
742
|
+
status: ToolCallStatus.TOOL_CALL_WAITING_APPROVAL,
|
|
743
|
+
requiresApproval: true,
|
|
744
|
+
startedAt: utcTimestamp(),
|
|
745
|
+
approvalRequestedAt: utcTimestamp(),
|
|
746
|
+
toolKind: classifyTool(name),
|
|
747
|
+
});
|
|
748
|
+
tc.approvalMessage = argKey
|
|
749
|
+
? `Tool requires approval: ${name} (${argKey})`
|
|
750
|
+
: resolveDeniedApprovalMessage(name, "", {}, mergedPolicies);
|
|
751
|
+
return tc;
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Resolve a human-readable approval message for a denied tool, preferring the
|
|
755
|
+
* MCP policy template, then the built-in template, then a generic fallback.
|
|
756
|
+
*/
|
|
757
|
+
function resolveDeniedApprovalMessage(name, mcpServerSlug, args, mergedPolicies) {
|
|
758
|
+
if (mergedPolicies && mcpServerSlug) {
|
|
759
|
+
const policy = lookupMcpToolPolicy(name, mcpServerSlug, mergedPolicies);
|
|
760
|
+
if (policy)
|
|
761
|
+
return resolveApprovalMessage(policy.approvalMessage, name, args);
|
|
762
|
+
}
|
|
763
|
+
if (!mcpServerSlug) {
|
|
764
|
+
const template = getBuiltInApprovalMessage(name);
|
|
765
|
+
if (template)
|
|
766
|
+
return resolveApprovalMessage(template, name, args);
|
|
767
|
+
}
|
|
768
|
+
return `Tool requires approval: ${name}`;
|
|
769
|
+
}
|
|
770
|
+
/** Append a tool call to the last AI message, creating one if none exists. */
|
|
771
|
+
function appendToolCallToLastAiMessage(messages, tc) {
|
|
772
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
773
|
+
if (messages[i].type === MessageType.MESSAGE_AI) {
|
|
774
|
+
messages[i].toolCalls.push(tc);
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
const msg = create(AgentMessageSchema, {
|
|
779
|
+
type: MessageType.MESSAGE_AI,
|
|
780
|
+
content: "",
|
|
781
|
+
timestamp: utcTimestamp(),
|
|
782
|
+
toolCalls: [tc],
|
|
783
|
+
});
|
|
784
|
+
messages.push(msg);
|
|
785
|
+
}
|
|
786
|
+
//# sourceMappingURL=message-translator.js.map
|