@stigmer/runner 3.0.9-dev.20260615153829 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.build-fingerprint +1 -1
- package/dist/__test-utils__/approval-contract/types.d.ts +174 -0
- package/dist/__test-utils__/approval-contract/types.js +24 -0
- package/dist/__test-utils__/approval-contract/types.js.map +1 -0
- package/dist/activities/call-agent-status.d.ts +19 -1
- package/dist/activities/call-agent-status.js +64 -5
- package/dist/activities/call-agent-status.js.map +1 -1
- package/dist/activities/call-llm.js +19 -53
- package/dist/activities/call-llm.js.map +1 -1
- package/dist/activities/classify-tool-approvals.d.ts +24 -0
- package/dist/activities/classify-tool-approvals.js +69 -17
- package/dist/activities/classify-tool-approvals.js.map +1 -1
- package/dist/activities/discover-mcp-server.d.ts +7 -0
- package/dist/activities/discover-mcp-server.js +11 -1
- package/dist/activities/discover-mcp-server.js.map +1 -1
- package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.d.ts +140 -0
- package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js +130 -0
- package/dist/activities/execute-cursor/__test-utils__/cursor-hook-harness.js.map +1 -0
- package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.d.ts +18 -0
- package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.js +123 -0
- package/dist/activities/execute-cursor/__test-utils__/gateway-substrate.js.map +1 -0
- package/dist/activities/execute-cursor/approval-policy.d.ts +17 -61
- package/dist/activities/execute-cursor/approval-policy.js +8 -120
- package/dist/activities/execute-cursor/approval-policy.js.map +1 -1
- package/dist/activities/execute-cursor/approval-state.d.ts +219 -9
- package/dist/activities/execute-cursor/approval-state.js +233 -17
- package/dist/activities/execute-cursor/approval-state.js.map +1 -1
- package/dist/activities/execute-cursor/capture-flow.d.ts +127 -0
- package/dist/activities/execute-cursor/capture-flow.js +234 -0
- package/dist/activities/execute-cursor/capture-flow.js.map +1 -0
- package/dist/activities/execute-cursor/cas-observations.d.ts +96 -0
- package/dist/activities/execute-cursor/cas-observations.js +184 -0
- package/dist/activities/execute-cursor/cas-observations.js.map +1 -0
- package/dist/activities/execute-cursor/command-provenance.d.ts +62 -0
- package/dist/activities/execute-cursor/command-provenance.js +128 -0
- package/dist/activities/execute-cursor/command-provenance.js.map +1 -0
- package/dist/activities/execute-cursor/exact-apply.d.ts +110 -0
- package/dist/activities/execute-cursor/exact-apply.js +204 -0
- package/dist/activities/execute-cursor/exact-apply.js.map +1 -0
- package/dist/activities/execute-cursor/hook-script.d.ts +53 -24
- package/dist/activities/execute-cursor/hook-script.js +310 -47
- package/dist/activities/execute-cursor/hook-script.js.map +1 -1
- package/dist/activities/execute-cursor/index.d.ts +8 -1
- package/dist/activities/execute-cursor/index.js +500 -64
- package/dist/activities/execute-cursor/index.js.map +1 -1
- package/dist/activities/execute-cursor/message-translator.d.ts +258 -11
- package/dist/activities/execute-cursor/message-translator.js +836 -90
- package/dist/activities/execute-cursor/message-translator.js.map +1 -1
- package/dist/activities/execute-cursor/prompt-builder.d.ts +20 -23
- package/dist/activities/execute-cursor/prompt-builder.js +74 -15
- package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
- package/dist/activities/execute-cursor/workspace-setup.d.ts +17 -0
- package/dist/activities/execute-cursor/workspace-setup.js +212 -33
- package/dist/activities/execute-cursor/workspace-setup.js.map +1 -1
- package/dist/activities/execute-deep-agent/__test-utils__/gateway-substrate.d.ts +19 -0
- package/dist/activities/execute-deep-agent/__test-utils__/gateway-substrate.js +143 -0
- package/dist/activities/execute-deep-agent/__test-utils__/gateway-substrate.js.map +1 -0
- package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.d.ts +88 -0
- package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.js +81 -0
- package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.js.map +1 -0
- package/dist/activities/execute-deep-agent/approval-file-change.d.ts +47 -0
- package/dist/activities/execute-deep-agent/approval-file-change.js +68 -0
- package/dist/activities/execute-deep-agent/approval-file-change.js.map +1 -0
- package/dist/activities/execute-deep-agent/attachment-injector.d.ts +8 -1
- package/dist/activities/execute-deep-agent/attachment-injector.js +7 -7
- package/dist/activities/execute-deep-agent/attachment-injector.js.map +1 -1
- package/dist/activities/execute-deep-agent/cas-capture-backend.d.ts +42 -0
- package/dist/activities/execute-deep-agent/cas-capture-backend.js +47 -0
- package/dist/activities/execute-deep-agent/cas-capture-backend.js.map +1 -0
- package/dist/activities/execute-deep-agent/cas-capture-observer.d.ts +79 -0
- package/dist/activities/execute-deep-agent/cas-capture-observer.js +112 -0
- package/dist/activities/execute-deep-agent/cas-capture-observer.js.map +1 -0
- package/dist/activities/execute-deep-agent/hitl.d.ts +16 -3
- package/dist/activities/execute-deep-agent/hitl.js +11 -3
- package/dist/activities/execute-deep-agent/hitl.js.map +1 -1
- package/dist/activities/execute-deep-agent/index.d.ts +2 -1
- package/dist/activities/execute-deep-agent/index.js +393 -33
- package/dist/activities/execute-deep-agent/index.js.map +1 -1
- package/dist/activities/execute-deep-agent/inline-publisher.d.ts +7 -1
- package/dist/activities/execute-deep-agent/inline-publisher.js +23 -2
- package/dist/activities/execute-deep-agent/inline-publisher.js.map +1 -1
- package/dist/activities/execute-deep-agent/setup.d.ts +53 -2
- package/dist/activities/execute-deep-agent/setup.js +149 -92
- package/dist/activities/execute-deep-agent/setup.js.map +1 -1
- package/dist/activities/execute-deep-agent/stamp-flowed-rows.d.ts +36 -0
- package/dist/activities/execute-deep-agent/stamp-flowed-rows.js +56 -0
- package/dist/activities/execute-deep-agent/stamp-flowed-rows.js.map +1 -0
- package/dist/activities/execute-deep-agent/status-builder-shared.d.ts +34 -1
- package/dist/activities/execute-deep-agent/status-builder-shared.js +26 -25
- package/dist/activities/execute-deep-agent/status-builder-shared.js.map +1 -1
- package/dist/activities/execute-deep-agent/status-builder.d.ts +17 -5
- package/dist/activities/execute-deep-agent/status-builder.js +44 -3
- package/dist/activities/execute-deep-agent/status-builder.js.map +1 -1
- package/dist/activities/execute-deep-agent/streaming-side-effects.js +2 -19
- package/dist/activities/execute-deep-agent/streaming-side-effects.js.map +1 -1
- package/dist/activities/execute-deep-agent/streaming.js +3 -15
- package/dist/activities/execute-deep-agent/streaming.js.map +1 -1
- package/dist/activities/execute-deep-agent/subagent-transformer.d.ts +25 -7
- package/dist/activities/execute-deep-agent/subagent-transformer.js +23 -7
- package/dist/activities/execute-deep-agent/subagent-transformer.js.map +1 -1
- package/dist/activities/execute-deep-agent/subagent-wiring.d.ts +30 -3
- package/dist/activities/execute-deep-agent/subagent-wiring.js +29 -3
- package/dist/activities/execute-deep-agent/subagent-wiring.js.map +1 -1
- package/dist/activities/execute-deep-agent/v3-status-builder.js +32 -2
- package/dist/activities/execute-deep-agent/v3-status-builder.js.map +1 -1
- package/dist/claimcheck/payload-codec.js +9 -5
- package/dist/claimcheck/payload-codec.js.map +1 -1
- package/dist/client/stigmer-client.d.ts +2 -0
- package/dist/client/stigmer-client.js +2 -0
- package/dist/client/stigmer-client.js.map +1 -1
- package/dist/middleware/approval-gate.d.ts +85 -4
- package/dist/middleware/approval-gate.js +165 -38
- package/dist/middleware/approval-gate.js.map +1 -1
- package/dist/middleware/types.d.ts +2 -5
- package/dist/shared/activity-input.d.ts +43 -0
- package/dist/shared/activity-input.js +17 -0
- package/dist/shared/activity-input.js.map +1 -0
- package/dist/shared/approval-canonicalize.d.ts +19 -0
- package/dist/shared/approval-canonicalize.js +119 -0
- package/dist/shared/approval-canonicalize.js.map +1 -0
- package/dist/shared/approval-fingerprint.d.ts +106 -0
- package/dist/shared/approval-fingerprint.js +113 -0
- package/dist/shared/approval-fingerprint.js.map +1 -0
- package/dist/shared/approval-policy.d.ts +182 -12
- package/dist/shared/approval-policy.js +213 -27
- package/dist/shared/approval-policy.js.map +1 -1
- package/dist/shared/args-preview.d.ts +52 -0
- package/dist/shared/args-preview.js +93 -0
- package/dist/shared/args-preview.js.map +1 -0
- package/dist/shared/artifact-storage.d.ts +19 -1
- package/dist/shared/artifact-storage.js +48 -11
- package/dist/shared/artifact-storage.js.map +1 -1
- package/dist/shared/file-change.d.ts +44 -0
- package/dist/shared/file-change.js +57 -0
- package/dist/shared/file-change.js.map +1 -0
- package/dist/shared/file-tools.d.ts +107 -0
- package/dist/shared/file-tools.js +168 -0
- package/dist/shared/file-tools.js.map +1 -0
- package/dist/shared/filereview/capture.d.ts +202 -0
- package/dist/shared/filereview/capture.js +498 -0
- package/dist/shared/filereview/capture.js.map +1 -0
- package/dist/shared/filereview/cas-substrate.d.ts +190 -0
- package/dist/shared/filereview/cas-substrate.js +284 -0
- package/dist/shared/filereview/cas-substrate.js.map +1 -0
- package/dist/shared/filereview/digest.d.ts +40 -0
- package/dist/shared/filereview/digest.js +66 -0
- package/dist/shared/filereview/digest.js.map +1 -0
- package/dist/shared/filereview/events.d.ts +170 -0
- package/dist/shared/filereview/events.js +298 -0
- package/dist/shared/filereview/events.js.map +1 -0
- package/dist/shared/filereview/git-substrate.d.ts +175 -0
- package/dist/shared/filereview/git-substrate.js +439 -0
- package/dist/shared/filereview/git-substrate.js.map +1 -0
- package/dist/shared/filereview/index.d.ts +11 -0
- package/dist/shared/filereview/index.js +12 -0
- package/dist/shared/filereview/index.js.map +1 -0
- package/dist/shared/filereview/secret-paths.d.ts +63 -0
- package/dist/shared/filereview/secret-paths.js +105 -0
- package/dist/shared/filereview/secret-paths.js.map +1 -0
- package/dist/shared/fingerprint-secret.d.ts +26 -0
- package/dist/shared/fingerprint-secret.js +47 -0
- package/dist/shared/fingerprint-secret.js.map +1 -0
- package/dist/shared/model-client.d.ts +51 -0
- package/dist/shared/model-client.js +77 -0
- package/dist/shared/model-client.js.map +1 -0
- package/dist/shared/plan-artifact.js +0 -2
- package/dist/shared/plan-artifact.js.map +1 -1
- package/dist/shared/status-offload.d.ts +83 -9
- package/dist/shared/status-offload.js +399 -79
- package/dist/shared/status-offload.js.map +1 -1
- package/dist/shared/status.js +14 -1
- package/dist/shared/status.js.map +1 -1
- package/dist/shared/tool-kind.d.ts +19 -0
- package/dist/shared/tool-kind.js +13 -0
- package/dist/shared/tool-kind.js.map +1 -1
- package/dist/shared/tool-row.d.ts +88 -0
- package/dist/shared/tool-row.js +127 -0
- package/dist/shared/tool-row.js.map +1 -0
- package/dist/shared/workspace/platform-dir.d.ts +25 -0
- package/dist/shared/workspace/platform-dir.js +38 -2
- package/dist/shared/workspace/platform-dir.js.map +1 -1
- package/dist/workflows/call-agent-orchestrator.js +56 -7
- package/dist/workflows/call-agent-orchestrator.js.map +1 -1
- package/dist/workflows/connect-mcp-server.d.ts +50 -0
- package/dist/workflows/connect-mcp-server.js +136 -15
- package/dist/workflows/connect-mcp-server.js.map +1 -1
- package/dist/workflows/types.d.ts +8 -0
- package/package.json +2 -2
- package/src/__test-utils__/approval-contract/contract.ts +224 -0
- package/src/__test-utils__/approval-contract/types.ts +179 -0
- package/src/__test-utils__/fake-artifact-storage.ts +72 -0
- package/src/__tests__/approval-gateway-contract.test.ts +29 -0
- package/src/__tests__/claimcheck-codec.test.ts +16 -53
- package/src/__tests__/golden-e2e.test.ts +2 -0
- package/src/__tests__/runner-token-coordinator.test.ts +3 -3
- package/src/activities/__tests__/call-agent-status.test.ts +135 -0
- package/src/activities/__tests__/call-llm.test.ts +1 -1
- package/src/activities/__tests__/classify-tool-approvals.test.ts +208 -1
- package/src/activities/__tests__/discover-mcp-server.test.ts +30 -0
- package/src/activities/__tests__/workflow-event-activities.test.ts +2 -1
- package/src/activities/call-agent-status.ts +74 -4
- package/src/activities/call-llm.ts +18 -63
- package/src/activities/classify-tool-approvals.ts +101 -19
- package/src/activities/discover-mcp-server.ts +29 -1
- package/src/activities/execute-cursor/__test-utils__/cursor-hook-harness.ts +216 -0
- package/src/activities/execute-cursor/__test-utils__/gateway-substrate.ts +148 -0
- package/src/activities/execute-cursor/__tests__/approval-gate.test.ts +41 -9
- package/src/activities/execute-cursor/__tests__/approval-state.test.ts +292 -0
- package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +68 -1
- package/src/activities/execute-cursor/__tests__/capture-flow.test.ts +1005 -0
- package/src/activities/execute-cursor/__tests__/cas-observations.test.ts +187 -0
- package/src/activities/execute-cursor/__tests__/coarse-fingerprint.test.ts +97 -0
- package/src/activities/execute-cursor/__tests__/command-provenance.test.ts +240 -0
- package/src/activities/execute-cursor/__tests__/deny-gate-exact-apply.test.ts +203 -0
- package/src/activities/execute-cursor/__tests__/exact-apply.test.ts +375 -0
- package/src/activities/execute-cursor/__tests__/hitl-ledger.test.ts +1294 -24
- package/src/activities/execute-cursor/__tests__/hitl-resume-history.test.ts +446 -0
- package/src/activities/execute-cursor/__tests__/hook-script.test.ts +384 -110
- package/src/activities/execute-cursor/__tests__/message-translator.test.ts +171 -25
- package/src/activities/execute-cursor/__tests__/sequential-gate-resume.test.ts +189 -0
- package/src/activities/execute-cursor/__tests__/tool-result-image.test.ts +44 -23
- package/src/activities/execute-cursor/__tests__/workspace-setup.test.ts +190 -10
- package/src/activities/execute-cursor/approval-policy.ts +28 -159
- package/src/activities/execute-cursor/approval-state.ts +366 -18
- package/src/activities/execute-cursor/capture-flow.ts +323 -0
- package/src/activities/execute-cursor/cas-observations.ts +204 -0
- package/src/activities/execute-cursor/command-provenance.ts +168 -0
- package/src/activities/execute-cursor/exact-apply.ts +253 -0
- package/src/activities/execute-cursor/hook-script.ts +317 -51
- package/src/activities/execute-cursor/index.ts +575 -67
- package/src/activities/execute-cursor/message-translator.ts +963 -89
- package/src/activities/execute-cursor/prompt-builder.ts +80 -14
- package/src/activities/execute-cursor/workspace-setup.ts +257 -42
- package/src/activities/execute-deep-agent/__test-utils__/gateway-substrate.ts +180 -0
- package/src/activities/execute-deep-agent/__test-utils__/scripted-model.ts +134 -0
- package/src/activities/execute-deep-agent/__tests__/approval-file-change.test.ts +84 -0
- package/src/activities/execute-deep-agent/__tests__/attachment-injector.test.ts +11 -24
- package/src/activities/execute-deep-agent/__tests__/cas-capture-backend.test.ts +64 -0
- package/src/activities/execute-deep-agent/__tests__/cas-capture-observer.test.ts +163 -0
- package/src/activities/execute-deep-agent/__tests__/hitl-integration.test.ts +8 -5
- package/src/activities/execute-deep-agent/__tests__/hitl-resume-approve-all.test.ts +342 -0
- package/src/activities/execute-deep-agent/__tests__/hitl-resume-history.test.ts +284 -0
- package/src/activities/execute-deep-agent/__tests__/hitl.test.ts +14 -36
- package/src/activities/execute-deep-agent/__tests__/inline-publisher.test.ts +31 -13
- package/src/activities/execute-deep-agent/__tests__/sequential-gate-resume.test.ts +349 -0
- package/src/activities/execute-deep-agent/__tests__/stamp-flowed-rows.test.ts +119 -0
- package/src/activities/execute-deep-agent/__tests__/status-builder.test.ts +91 -10
- package/src/activities/execute-deep-agent/__tests__/streaming-v3.test.ts +9 -9
- package/src/activities/execute-deep-agent/__tests__/subagent-approval-propagation.test.ts +160 -0
- package/src/activities/execute-deep-agent/__tests__/subagent-gitignored-capture.test.ts +213 -0
- package/src/activities/execute-deep-agent/__tests__/subagent-transformer.test.ts +3 -6
- package/src/activities/execute-deep-agent/__tests__/subagent-wiring.test.ts +84 -1
- package/src/activities/execute-deep-agent/__tests__/v3-status-builder.test.ts +4 -1
- package/src/activities/execute-deep-agent/approval-file-change.ts +80 -0
- package/src/activities/execute-deep-agent/attachment-injector.ts +20 -11
- package/src/activities/execute-deep-agent/cas-capture-backend.ts +66 -0
- package/src/activities/execute-deep-agent/cas-capture-observer.ts +125 -0
- package/src/activities/execute-deep-agent/hitl.ts +23 -7
- package/src/activities/execute-deep-agent/index.ts +463 -40
- package/src/activities/execute-deep-agent/inline-publisher.ts +27 -4
- package/src/activities/execute-deep-agent/setup.ts +223 -125
- package/src/activities/execute-deep-agent/stamp-flowed-rows.ts +64 -0
- package/src/activities/execute-deep-agent/status-builder-shared.ts +62 -23
- package/src/activities/execute-deep-agent/status-builder.ts +63 -8
- package/src/activities/execute-deep-agent/streaming-side-effects.ts +2 -16
- package/src/activities/execute-deep-agent/streaming.ts +3 -13
- package/src/activities/execute-deep-agent/subagent-transformer.ts +53 -13
- package/src/activities/execute-deep-agent/subagent-wiring.ts +50 -3
- package/src/activities/execute-deep-agent/v3-status-builder.ts +36 -2
- package/src/claimcheck/payload-codec.ts +8 -8
- package/src/client/stigmer-client.ts +9 -1
- package/src/middleware/__tests__/approval-gate.test.ts +488 -4
- package/src/middleware/approval-gate.ts +247 -38
- package/src/middleware/types.ts +5 -5
- package/src/shared/__tests__/activity-input.test.ts +78 -0
- package/src/shared/__tests__/approval-canonicalize.test.ts +106 -0
- package/src/shared/__tests__/approval-fingerprint.test.ts +115 -0
- package/src/shared/__tests__/approval-policy.test.ts +274 -40
- package/src/shared/__tests__/args-preview.test.ts +78 -0
- package/src/shared/__tests__/artifact-storage-extended.test.ts +62 -10
- package/src/shared/__tests__/artifact-storage.test.ts +123 -11
- package/src/shared/__tests__/file-change.test.ts +85 -0
- package/src/shared/__tests__/file-tools.test.ts +90 -0
- package/src/shared/__tests__/fingerprint-secret.test.ts +51 -0
- package/src/shared/__tests__/lease-scope-corpus.test.ts +56 -0
- package/src/shared/__tests__/model-client.test.ts +162 -0
- package/src/shared/__tests__/plan-artifact.test.ts +11 -26
- package/src/shared/__tests__/policy-source-corpus.test.ts +58 -0
- package/src/shared/__tests__/status-offload.test.ts +573 -16
- package/src/shared/__tests__/status.test.ts +4 -5
- package/src/shared/__tests__/tool-kind.test.ts +24 -1
- package/src/shared/__tests__/tool-row.test.ts +221 -0
- package/src/shared/activity-input.ts +57 -0
- package/src/shared/approval-canonicalize.ts +159 -0
- package/src/shared/approval-fingerprint.ts +148 -0
- package/src/shared/approval-policy.ts +303 -27
- package/src/shared/args-preview.ts +98 -0
- package/src/shared/artifact-storage.ts +62 -11
- package/src/shared/checkpointer/__tests__/http-saver.test.ts +1 -2
- package/src/shared/file-change.ts +64 -0
- package/src/shared/file-tools.ts +169 -0
- package/src/shared/filereview/__tests__/capture.test.ts +856 -0
- package/src/shared/filereview/__tests__/cas-substrate.test.ts +404 -0
- package/src/shared/filereview/__tests__/digest.test.ts +100 -0
- package/src/shared/filereview/__tests__/events.test.ts +245 -0
- package/src/shared/filereview/__tests__/git-substrate.test.ts +362 -0
- package/src/shared/filereview/__tests__/proxy-reconcile.test.ts +286 -0
- package/src/shared/filereview/__tests__/secret-paths.test.ts +121 -0
- package/src/shared/filereview/capture.ts +727 -0
- package/src/shared/filereview/cas-substrate.ts +401 -0
- package/src/shared/filereview/digest.ts +83 -0
- package/src/shared/filereview/events.ts +449 -0
- package/src/shared/filereview/git-substrate.ts +555 -0
- package/src/shared/filereview/index.ts +60 -0
- package/src/shared/filereview/secret-paths.ts +121 -0
- package/src/shared/fingerprint-secret.ts +53 -0
- package/src/shared/model-client.ts +122 -0
- package/src/shared/plan-artifact.ts +0 -2
- package/src/shared/status-offload.ts +433 -77
- package/src/shared/status.ts +13 -0
- package/src/shared/tool-kind.ts +33 -0
- package/src/shared/tool-row.ts +135 -0
- package/src/shared/workspace/platform-dir.ts +41 -2
- package/src/workflow-engine/__tests__/golden-execution.test.ts +35 -18
- package/src/workflow-engine/__tests__/tasks/try.test.ts +1 -1
- package/src/workflows/__tests__/connect-mcp-server.test.ts +304 -29
- package/src/workflows/call-agent-orchestrator.ts +53 -6
- package/src/workflows/connect-mcp-server.ts +179 -24
- package/src/workflows/types.ts +8 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor deny-oracle adapter for the HITL gateway Contract Test Kit.
|
|
3
|
+
*
|
|
4
|
+
* Drives the REAL out-of-process gateway: the runner writes the approval state
|
|
5
|
+
* file (with any grants), then the generated bash preToolUse hook makes the
|
|
6
|
+
* allow/deny decision for the tool the agent would run inside cursor-agent. There
|
|
7
|
+
* is no in-process execution to observe, so `executed` means "the hook allowed
|
|
8
|
+
* it" and the substrate cannot count executions (`observesExecution: false`).
|
|
9
|
+
*
|
|
10
|
+
* Cross-taxonomy by construction: grants are minted from the STREAM-side identity
|
|
11
|
+
* (`edit`/`shell`/`delete`), while the hook is fed the HOOK-side payload
|
|
12
|
+
* (`Write`/`Shell`/`Delete`). So every approve drive exercises the category
|
|
13
|
+
* collapse that lets a stream-minted grant match a hook-named call. The grant
|
|
14
|
+
* token binds the exact resource, so this substrate enforces lease isolation
|
|
15
|
+
* (`enforcesExactResource: true`) and implements `authorizeAfterGrant`.
|
|
16
|
+
*/
|
|
17
|
+
import { setupCursorHookHarness, hasBash, hookWrite, hookShell, hookDelete, hookRead, hookMcp, } from "./cursor-hook-harness.js";
|
|
18
|
+
import { toolIdentity } from "../approval-state.js";
|
|
19
|
+
import { contentDigest } from "../../../shared/file-tools.js";
|
|
20
|
+
/** Build the real preToolUse hook-input payload for an abstract action. */
|
|
21
|
+
function hookInputFor(action) {
|
|
22
|
+
switch (action.kind) {
|
|
23
|
+
case "write":
|
|
24
|
+
return hookWrite(action.resource, action.content ?? "x");
|
|
25
|
+
case "shell":
|
|
26
|
+
return hookShell(action.resource);
|
|
27
|
+
case "delete":
|
|
28
|
+
return hookDelete(action.resource);
|
|
29
|
+
case "read":
|
|
30
|
+
return hookRead(action.resource);
|
|
31
|
+
case "mcp":
|
|
32
|
+
return hookMcp(action.mcpToolName ?? "mcp_tool");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Stream-side (SDK) tool name per gated category — deliberately the OTHER
|
|
36
|
+
// taxonomy from the hook input, so a grant minted here matches a hook-named call
|
|
37
|
+
// only via the canonical category, not the raw name.
|
|
38
|
+
const STREAM_NAME = {
|
|
39
|
+
write: "edit",
|
|
40
|
+
shell: "shell",
|
|
41
|
+
delete: "delete",
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Mint the approval grant for an action using its stream-side identity. Only the
|
|
45
|
+
* gated built-in categories are ever granted in the contract (read is never
|
|
46
|
+
* gated; the MCP cases under test are auto-approved, needing no grant).
|
|
47
|
+
*/
|
|
48
|
+
function grantFor(action) {
|
|
49
|
+
if (action.kind === "read" || action.kind === "mcp") {
|
|
50
|
+
throw new Error(`grantFor: ${action.kind} actions are not granted in the contract`);
|
|
51
|
+
}
|
|
52
|
+
const streamName = STREAM_NAME[action.kind];
|
|
53
|
+
// Mirror hookInputFor: a write carries whole-file content (so its digest is
|
|
54
|
+
// content-exact and matches the hook's), a delete carries only a path (no
|
|
55
|
+
// content), and a shell carries its command (the salient is already exact).
|
|
56
|
+
const args = action.kind === "shell"
|
|
57
|
+
? { command: action.resource }
|
|
58
|
+
: action.kind === "delete"
|
|
59
|
+
? { path: action.resource }
|
|
60
|
+
: { path: action.resource, content: action.content ?? "x" };
|
|
61
|
+
const identity = toolIdentity(streamName, "", args);
|
|
62
|
+
return {
|
|
63
|
+
toolName: streamName,
|
|
64
|
+
mcpServerSlug: "",
|
|
65
|
+
key: identity.key,
|
|
66
|
+
salient: identity.salient,
|
|
67
|
+
// Content-exact for a write (the sibling-isolation probe), coarse otherwise —
|
|
68
|
+
// matching how the runner grants from the authoritative captured args.
|
|
69
|
+
contentDigest: contentDigest(args),
|
|
70
|
+
sourceToolCallId: `consent-${action.kind}`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function decide(grants, action) {
|
|
74
|
+
// MCP cases under test are auto-approved: no policy entry, so the hook allows
|
|
75
|
+
// them. Built-ins are gated by the script's baked-in category set, not state.
|
|
76
|
+
const harness = setupCursorHookHarness({ grants });
|
|
77
|
+
const { permission } = harness.decide(hookInputFor(action));
|
|
78
|
+
const executed = permission === "allow";
|
|
79
|
+
return { executed, gated: !executed };
|
|
80
|
+
}
|
|
81
|
+
// A gated built-in's contract kind IS its approval category (write/shell/delete),
|
|
82
|
+
// so it doubles as the leasedCategories entry the hook reads.
|
|
83
|
+
function leaseCategoryOf(action) {
|
|
84
|
+
if (action.kind === "read" || action.kind === "mcp") {
|
|
85
|
+
throw new Error(`leaseCategoryOf: ${action.kind} is not a leasable built-in class`);
|
|
86
|
+
}
|
|
87
|
+
return action.kind;
|
|
88
|
+
}
|
|
89
|
+
export function createCursorSubstrate() {
|
|
90
|
+
return {
|
|
91
|
+
name: "cursor",
|
|
92
|
+
available: hasBash,
|
|
93
|
+
capabilities: {
|
|
94
|
+
observesExecution: false,
|
|
95
|
+
enforcesExactResource: true,
|
|
96
|
+
// The grant binds (category, path, contentDigest), so a DIFFERENT edit to
|
|
97
|
+
// the same file re-gates — the sibling-hole fix.
|
|
98
|
+
enforcesExactContent: true,
|
|
99
|
+
appliesRunLifetimeLease: true,
|
|
100
|
+
// The Cursor hook's deny decision does not carry approval_policy_source;
|
|
101
|
+
// provenance is projected at message-reconstruction time (message-translator)
|
|
102
|
+
// and asserted by the corpus + resolveApprovalProvenance suites instead.
|
|
103
|
+
surfacesGatePolicySource: false,
|
|
104
|
+
},
|
|
105
|
+
async authorize(action, decision) {
|
|
106
|
+
const grants = decision === "approve" ? [grantFor(action)] : [];
|
|
107
|
+
return decide(grants, action);
|
|
108
|
+
},
|
|
109
|
+
async authorizeAfterGrant(granted, probe) {
|
|
110
|
+
return decide([grantFor(granted)], probe);
|
|
111
|
+
},
|
|
112
|
+
async authorizeUnderClassLease(leased, probe) {
|
|
113
|
+
// A run-lifetime category lease is carried in the state file (no per-call
|
|
114
|
+
// grant), exactly as the runner writes it after an APPROVE_ALL; the hook
|
|
115
|
+
// allows a probe iff its category is leased.
|
|
116
|
+
const harness = setupCursorHookHarness({ leasedCategories: [leaseCategoryOf(leased)] });
|
|
117
|
+
const { permission } = harness.decide(hookInputFor(probe));
|
|
118
|
+
const executed = permission === "allow";
|
|
119
|
+
return { executed, gated: !executed };
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=gateway-substrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-substrate.js","sourceRoot":"","sources":["../../../../src/activities/execute-cursor/__test-utils__/gateway-substrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,sBAAsB,EACtB,OAAO,EACP,SAAS,EACT,SAAS,EACT,UAAU,EACV,QAAQ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CAAC"}
|
|
@@ -15,35 +15,27 @@
|
|
|
15
15
|
* allows or denies the call. For built-in Cursor tools (Shell, Read, etc.),
|
|
16
16
|
* a separate local policy applies.
|
|
17
17
|
*/
|
|
18
|
-
import type
|
|
19
|
-
|
|
18
|
+
import { toolApprovalCategory, type ToolApprovalCategory } from "../../shared/tool-kind.js";
|
|
19
|
+
export { mergeApprovalPolicies, lookupMcpToolPolicy, resolveApprovalMessage, POLICY_ENGINE_VERSION, } from "../../shared/approval-policy.js";
|
|
20
|
+
export type { MergedToolPolicy, PolicySource } from "../../shared/approval-policy.js";
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
export interface MergedToolPolicy {
|
|
24
|
-
toolName: string;
|
|
25
|
-
mcpServerSlug: string;
|
|
26
|
-
requiresApproval: boolean;
|
|
27
|
-
approvalMessage: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Canonical approval category for a gated tool, derived from EITHER taxonomy's
|
|
31
|
-
* name via the shared {@link classifyTool}.
|
|
22
|
+
* Canonical approval category for a gated tool.
|
|
32
23
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* reinvocation regardless of which taxonomy named it. `FILE_WRITE` and
|
|
39
|
-
* `FILE_EDIT` both map to `write` because the Cursor hook reports every file
|
|
40
|
-
* mutation — create or edit — as `Write`.
|
|
24
|
+
* This is the cross-substrate identity, and it lives in ONE place:
|
|
25
|
+
* {@link toolApprovalCategory} in shared/tool-kind.ts (shared with the deep-agent
|
|
26
|
+
* gateway). The names below are kept as the Cursor harness's public surface
|
|
27
|
+
* (`approvalCategory` / `ApprovalCategory`) so existing imports do not churn, but
|
|
28
|
+
* they are exact aliases — there is no second implementation to drift.
|
|
41
29
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
30
|
+
* Why this matters here: the hook (`Write`/`Shell`/`Delete`) and the stream
|
|
31
|
+
* (`edit`/`shell`/`delete`) name the same operation differently, so neither raw
|
|
32
|
+
* name is a stable cross-layer identity. The category collapses both onto one
|
|
33
|
+
* value so the denial ledger (recorded by the hook) correlates to the streamed
|
|
34
|
+
* tool call (read by the runner) and an approval grant matches the agent's
|
|
35
|
+
* re-attempt on reinvocation regardless of which taxonomy named it.
|
|
44
36
|
*/
|
|
45
|
-
export type ApprovalCategory =
|
|
46
|
-
export declare
|
|
37
|
+
export type ApprovalCategory = ToolApprovalCategory;
|
|
38
|
+
export declare const approvalCategory: typeof toolApprovalCategory;
|
|
47
39
|
/**
|
|
48
40
|
* Top-level tool-argument fields, in priority order, that identify the specific
|
|
49
41
|
* resource a built-in tool acts on. The list deliberately spans BOTH taxonomies'
|
|
@@ -105,39 +97,3 @@ export declare function getBuiltInApprovalMessage(toolName: string): string | un
|
|
|
105
97
|
* drift.
|
|
106
98
|
*/
|
|
107
99
|
export declare function extractArgKey(args: Record<string, unknown> | undefined): string;
|
|
108
|
-
/**
|
|
109
|
-
* Merge approval policies from all four levels into a single lookup map.
|
|
110
|
-
*
|
|
111
|
-
* Keys are the raw tool name (e.g., "apply_cloud_resource"). Each MCP server
|
|
112
|
-
* contributes its own set of policies, so the map is keyed by
|
|
113
|
-
* "serverSlug/toolName" to avoid collisions between servers.
|
|
114
|
-
*
|
|
115
|
-
* Policy chain (each level overrides the previous):
|
|
116
|
-
* 1. status.toolApprovals — presence means "requires approval"
|
|
117
|
-
* 2. spec.pinnedToolApprovals — presence means "requires approval" (overrides)
|
|
118
|
-
* 3. agent tool_approval_overrides — explicit boolean per tool
|
|
119
|
-
* 4. auto_approve_all — bypasses everything
|
|
120
|
-
*
|
|
121
|
-
* When auto_approve_all is true, the returned map is empty (no tool
|
|
122
|
-
* requires approval).
|
|
123
|
-
*/
|
|
124
|
-
export declare function mergeApprovalPolicies(resolvedServers: ResolvedMcpServer[], agentOverrides: ToolApprovalOverride[], autoApproveAll: boolean): Map<string, MergedToolPolicy>;
|
|
125
|
-
/**
|
|
126
|
-
* Look up whether an MCP tool requires approval.
|
|
127
|
-
*
|
|
128
|
-
* @param toolName - The actual MCP tool name (e.g., "apply_cloud_resource")
|
|
129
|
-
* @param mcpServerSlug - The MCP server slug (e.g., "planton")
|
|
130
|
-
* @param policies - The merged policy map from mergeApprovalPolicies()
|
|
131
|
-
* @returns The policy if approval is required, undefined if auto-approved
|
|
132
|
-
*/
|
|
133
|
-
export declare function lookupMcpToolPolicy(toolName: string, mcpServerSlug: string, policies: Map<string, MergedToolPolicy>): MergedToolPolicy | undefined;
|
|
134
|
-
/**
|
|
135
|
-
* Resolve {{args.field}} placeholders in an approval message using the
|
|
136
|
-
* tool's actual arguments.
|
|
137
|
-
*
|
|
138
|
-
* Placeholder syntax matches the proto-documented format:
|
|
139
|
-
* - {{args.field_name}} — replaced with the argument value
|
|
140
|
-
* - {{tool_name}} — replaced with the tool name
|
|
141
|
-
* - Missing fields are replaced with "<unknown>"
|
|
142
|
-
*/
|
|
143
|
-
export declare function resolveApprovalMessage(template: string, toolName: string, args: Record<string, unknown>): string;
|
|
@@ -15,8 +15,13 @@
|
|
|
15
15
|
* allows or denies the call. For built-in Cursor tools (Shell, Read, etc.),
|
|
16
16
|
* a separate local policy applies.
|
|
17
17
|
*/
|
|
18
|
-
import {
|
|
19
|
-
|
|
18
|
+
import { toolApprovalCategory } from "../../shared/tool-kind.js";
|
|
19
|
+
// The four-level MCP policy merge is harness-agnostic and lives in exactly one
|
|
20
|
+
// place (shared/approval-policy.ts) so the Cursor and native harnesses can never
|
|
21
|
+
// diverge. Re-exported here so existing Cursor-harness imports
|
|
22
|
+
// (`from "./approval-policy.js"`) keep working unchanged. This module now owns
|
|
23
|
+
// only the Cursor-specific built-in-tool gating helpers below.
|
|
24
|
+
export { mergeApprovalPolicies, lookupMcpToolPolicy, resolveApprovalMessage, POLICY_ENGINE_VERSION, } from "../../shared/approval-policy.js";
|
|
20
25
|
/**
|
|
21
26
|
* Built-in Cursor tools the preToolUse hook gates, named as the hook receives
|
|
22
27
|
* them.
|
|
@@ -36,19 +41,7 @@ const BUILT_IN_GATED = new Set([
|
|
|
36
41
|
"Shell",
|
|
37
42
|
"Delete",
|
|
38
43
|
]);
|
|
39
|
-
export
|
|
40
|
-
switch (classifyTool(toolName)) {
|
|
41
|
-
case ToolKind.FILE_WRITE:
|
|
42
|
-
case ToolKind.FILE_EDIT:
|
|
43
|
-
return "write";
|
|
44
|
-
case ToolKind.FILE_DELETE:
|
|
45
|
-
return "delete";
|
|
46
|
-
case ToolKind.SHELL:
|
|
47
|
-
return "shell";
|
|
48
|
-
default:
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
44
|
+
export const approvalCategory = toolApprovalCategory;
|
|
52
45
|
/**
|
|
53
46
|
* Human-readable approval-message template per canonical category. Keyed by
|
|
54
47
|
* category (not raw tool name) so a denial surfaced from either taxonomy renders
|
|
@@ -147,109 +140,4 @@ export function extractArgKey(args) {
|
|
|
147
140
|
}
|
|
148
141
|
return "";
|
|
149
142
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Merge approval policies from all four levels into a single lookup map.
|
|
152
|
-
*
|
|
153
|
-
* Keys are the raw tool name (e.g., "apply_cloud_resource"). Each MCP server
|
|
154
|
-
* contributes its own set of policies, so the map is keyed by
|
|
155
|
-
* "serverSlug/toolName" to avoid collisions between servers.
|
|
156
|
-
*
|
|
157
|
-
* Policy chain (each level overrides the previous):
|
|
158
|
-
* 1. status.toolApprovals — presence means "requires approval"
|
|
159
|
-
* 2. spec.pinnedToolApprovals — presence means "requires approval" (overrides)
|
|
160
|
-
* 3. agent tool_approval_overrides — explicit boolean per tool
|
|
161
|
-
* 4. auto_approve_all — bypasses everything
|
|
162
|
-
*
|
|
163
|
-
* When auto_approve_all is true, the returned map is empty (no tool
|
|
164
|
-
* requires approval).
|
|
165
|
-
*/
|
|
166
|
-
export function mergeApprovalPolicies(resolvedServers, agentOverrides, autoApproveAll) {
|
|
167
|
-
const merged = new Map();
|
|
168
|
-
if (autoApproveAll)
|
|
169
|
-
return merged;
|
|
170
|
-
for (const server of resolvedServers) {
|
|
171
|
-
const serverPolicies = new Map();
|
|
172
|
-
// Layer 1: system-generated defaults (presence = requires approval)
|
|
173
|
-
for (const policy of server.toolApprovals) {
|
|
174
|
-
if (!policy.toolName)
|
|
175
|
-
continue;
|
|
176
|
-
serverPolicies.set(policy.toolName, {
|
|
177
|
-
requiresApproval: true,
|
|
178
|
-
message: policy.message || `Execute tool: ${policy.toolName}`,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
// Layer 2: manual overrides (presence = requires approval, overrides layer 1)
|
|
182
|
-
for (const pinned of server.pinnedToolApprovals) {
|
|
183
|
-
if (!pinned.toolName)
|
|
184
|
-
continue;
|
|
185
|
-
serverPolicies.set(pinned.toolName, {
|
|
186
|
-
requiresApproval: true,
|
|
187
|
-
message: pinned.message || serverPolicies.get(pinned.toolName)?.message || `Execute tool: ${pinned.toolName}`,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
// Layer 3: per-agent overrides (explicit boolean, can enable or disable)
|
|
191
|
-
for (const override of agentOverrides) {
|
|
192
|
-
if (!override.toolName)
|
|
193
|
-
continue;
|
|
194
|
-
const existing = serverPolicies.get(override.toolName);
|
|
195
|
-
if (existing) {
|
|
196
|
-
existing.requiresApproval = override.requiresApproval;
|
|
197
|
-
if (override.message) {
|
|
198
|
-
existing.message = override.message;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
else if (override.requiresApproval) {
|
|
202
|
-
serverPolicies.set(override.toolName, {
|
|
203
|
-
requiresApproval: true,
|
|
204
|
-
message: override.message || `Execute tool: ${override.toolName}`,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
// Write merged policies into the result map
|
|
209
|
-
for (const [toolName, policy] of serverPolicies) {
|
|
210
|
-
if (!policy.requiresApproval)
|
|
211
|
-
continue;
|
|
212
|
-
const key = `${server.slug}/${toolName}`;
|
|
213
|
-
merged.set(key, {
|
|
214
|
-
toolName,
|
|
215
|
-
mcpServerSlug: server.slug,
|
|
216
|
-
requiresApproval: true,
|
|
217
|
-
approvalMessage: policy.message,
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return merged;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Look up whether an MCP tool requires approval.
|
|
225
|
-
*
|
|
226
|
-
* @param toolName - The actual MCP tool name (e.g., "apply_cloud_resource")
|
|
227
|
-
* @param mcpServerSlug - The MCP server slug (e.g., "planton")
|
|
228
|
-
* @param policies - The merged policy map from mergeApprovalPolicies()
|
|
229
|
-
* @returns The policy if approval is required, undefined if auto-approved
|
|
230
|
-
*/
|
|
231
|
-
export function lookupMcpToolPolicy(toolName, mcpServerSlug, policies) {
|
|
232
|
-
return policies.get(`${mcpServerSlug}/${toolName}`);
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Resolve {{args.field}} placeholders in an approval message using the
|
|
236
|
-
* tool's actual arguments.
|
|
237
|
-
*
|
|
238
|
-
* Placeholder syntax matches the proto-documented format:
|
|
239
|
-
* - {{args.field_name}} — replaced with the argument value
|
|
240
|
-
* - {{tool_name}} — replaced with the tool name
|
|
241
|
-
* - Missing fields are replaced with "<unknown>"
|
|
242
|
-
*/
|
|
243
|
-
export function resolveApprovalMessage(template, toolName, args) {
|
|
244
|
-
return template
|
|
245
|
-
.replace(/\{\{tool_name\}\}/g, toolName)
|
|
246
|
-
.replace(/\{\{args\.(\w+)\}\}/g, (_match, field) => {
|
|
247
|
-
const value = args[field];
|
|
248
|
-
if (value === undefined || value === null)
|
|
249
|
-
return "<unknown>";
|
|
250
|
-
if (typeof value === "string")
|
|
251
|
-
return value;
|
|
252
|
-
return JSON.stringify(value);
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
143
|
//# sourceMappingURL=approval-policy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-policy.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/approval-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;
|
|
1
|
+
{"version":3,"file":"approval-policy.js","sourceRoot":"","sources":["../../../src/activities/execute-cursor/approval-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,oBAAoB,EAA6B,MAAM,2BAA2B,CAAC;AAE5F,+EAA+E;AAC/E,iFAAiF;AACjF,+DAA+D;AAC/D,+EAA+E;AAC/E,+DAA+D;AAC/D,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,iCAAiC,CAAC;AAGzC;;;;;;;;;;;GAWG;AACH,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC;IAClD,OAAO;IACP,YAAY;IACZ,cAAc;IACd,OAAO;IACP,QAAQ;CACT,CAAC,CAAC;AAoBH,MAAM,CAAC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,yBAAyB,GAAqC;IAClE,KAAK,EAAE,2BAA2B;IAClC,MAAM,EAAE,uBAAuB;IAC/B,KAAK,EAAE,+BAA+B;CACvC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,SAAS,CAAU,CAAC;AAE/F;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAgB;IACtD,OAAO,gBAAgB,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,CAAC,GAAG,cAAc,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB;IACvC,MAAM,KAAK,GAAsC,EAAE,CAAC;IACpD,KAAK,MAAM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