@stigmer/runner 3.15.0 → 3.15.2-dev.20260913223433
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 +2 -4
- package/dist/.build-fingerprint +1 -1
- package/dist/__test-utils__/execution-record-fixture.d.ts +14 -0
- package/dist/__test-utils__/execution-record-fixture.js +4 -0
- package/dist/__test-utils__/execution-record-fixture.js.map +1 -1
- package/dist/__test-utils__/file-review-projection.d.ts +40 -0
- package/dist/__test-utils__/file-review-projection.js +136 -0
- package/dist/__test-utils__/file-review-projection.js.map +1 -0
- package/dist/__test-utils__/harness-contract/types.d.ts +23 -1
- package/dist/__test-utils__/harness-contract/types.js +15 -0
- package/dist/__test-utils__/harness-contract/types.js.map +1 -1
- package/dist/__test-utils__/hermetic-activity.d.ts +44 -12
- package/dist/__test-utils__/hermetic-activity.js +52 -14
- package/dist/__test-utils__/hermetic-activity.js.map +1 -1
- package/dist/__test-utils__/model-registry-fixture.d.ts +32 -7
- package/dist/__test-utils__/model-registry-fixture.js +31 -7
- package/dist/__test-utils__/model-registry-fixture.js.map +1 -1
- package/dist/__test-utils__/turn-input-fixture.d.ts +1 -1
- package/dist/__test-utils__/turn-input-fixture.js +1 -1
- package/dist/__test-utils__/turn-input-fixture.js.map +1 -1
- package/dist/activities/call-agent.js +2 -2
- package/dist/activities/call-agent.js.map +1 -1
- package/dist/activities/execute-cursor/__test-utils__/contract-subject.js +45 -3
- package/dist/activities/execute-cursor/__test-utils__/contract-subject.js.map +1 -1
- package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.d.ts +0 -9
- package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js +2 -41
- package/dist/activities/execute-cursor/__test-utils__/hermetic-cursor.js.map +1 -1
- package/dist/activities/execute-cursor/adapter.d.ts +7 -5
- package/dist/activities/execute-cursor/adapter.js +7 -5
- package/dist/activities/execute-cursor/adapter.js.map +1 -1
- package/dist/activities/execute-cursor/approval-policy.d.ts +5 -2
- package/dist/activities/execute-cursor/approval-policy.js +5 -2
- package/dist/activities/execute-cursor/approval-policy.js.map +1 -1
- package/dist/activities/execute-cursor/approval-state.d.ts +16 -8
- package/dist/activities/execute-cursor/approval-state.js +6 -3
- package/dist/activities/execute-cursor/approval-state.js.map +1 -1
- package/dist/activities/execute-cursor/cas-observations.d.ts +14 -2
- package/dist/activities/execute-cursor/cas-observations.js +19 -2
- package/dist/activities/execute-cursor/cas-observations.js.map +1 -1
- package/dist/activities/execute-cursor/cursor-capabilities.d.ts +8 -4
- package/dist/activities/execute-cursor/cursor-capabilities.js +21 -4
- package/dist/activities/execute-cursor/cursor-capabilities.js.map +1 -1
- package/dist/activities/execute-cursor/message-translator.d.ts +12 -20
- package/dist/activities/execute-cursor/message-translator.js +19 -32
- package/dist/activities/execute-cursor/message-translator.js.map +1 -1
- package/dist/activities/execute-cursor/prompt-builder.d.ts +48 -58
- package/dist/activities/execute-cursor/prompt-builder.js +76 -95
- package/dist/activities/execute-cursor/prompt-builder.js.map +1 -1
- package/dist/activities/execute-cursor/turn-boundary.d.ts +27 -55
- package/dist/activities/execute-cursor/turn-boundary.js +30 -90
- package/dist/activities/execute-cursor/turn-boundary.js.map +1 -1
- package/dist/activities/execute-cursor/turn-settle.d.ts +11 -7
- package/dist/activities/execute-cursor/turn-settle.js +37 -49
- package/dist/activities/execute-cursor/turn-settle.js.map +1 -1
- package/dist/activities/execute-cursor/turn-setup.d.ts +16 -24
- package/dist/activities/execute-cursor/turn-setup.js +29 -59
- package/dist/activities/execute-cursor/turn-setup.js.map +1 -1
- package/dist/activities/execute-cursor/turn-stream.d.ts +3 -8
- package/dist/activities/execute-cursor/turn-stream.js +9 -22
- package/dist/activities/execute-cursor/turn-stream.js.map +1 -1
- package/dist/activities/execute-cursor/turn.js +5 -1
- package/dist/activities/execute-cursor/turn.js.map +1 -1
- package/dist/activities/execute-deep-agent/__test-utils__/contract-subject.d.ts +93 -0
- package/dist/activities/execute-deep-agent/__test-utils__/contract-subject.js +348 -0
- package/dist/activities/execute-deep-agent/__test-utils__/contract-subject.js.map +1 -0
- package/dist/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.d.ts +170 -0
- package/dist/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.js +225 -0
- package/dist/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.js.map +1 -0
- package/dist/activities/execute-deep-agent/__test-utils__/hitl-script.d.ts +24 -0
- package/dist/activities/execute-deep-agent/__test-utils__/hitl-script.js +41 -0
- package/dist/activities/execute-deep-agent/__test-utils__/hitl-script.js.map +1 -0
- package/dist/activities/execute-deep-agent/__test-utils__/scripted-model-module.d.ts +54 -0
- package/dist/activities/execute-deep-agent/__test-utils__/scripted-model-module.js +72 -0
- package/dist/activities/execute-deep-agent/__test-utils__/scripted-model-module.js.map +1 -0
- package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.d.ts +187 -23
- package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.js +238 -27
- package/dist/activities/execute-deep-agent/__test-utils__/scripted-model.js.map +1 -1
- package/dist/activities/execute-deep-agent/adapter.d.ts +41 -0
- package/dist/activities/execute-deep-agent/adapter.js +78 -0
- package/dist/activities/execute-deep-agent/adapter.js.map +1 -0
- package/dist/activities/execute-deep-agent/cas-capture-observer.d.ts +8 -0
- package/dist/activities/execute-deep-agent/cas-capture-observer.js +9 -0
- package/dist/activities/execute-deep-agent/cas-capture-observer.js.map +1 -1
- package/dist/activities/execute-deep-agent/deep-agent-capabilities.d.ts +31 -0
- package/dist/activities/execute-deep-agent/deep-agent-capabilities.js +40 -0
- package/dist/activities/execute-deep-agent/deep-agent-capabilities.js.map +1 -0
- package/dist/activities/execute-deep-agent/execution-state.d.ts +4 -11
- package/dist/activities/execute-deep-agent/execution-state.js +4 -12
- package/dist/activities/execute-deep-agent/execution-state.js.map +1 -1
- package/dist/activities/execute-deep-agent/hitl.d.ts +49 -47
- package/dist/activities/execute-deep-agent/hitl.js +77 -103
- package/dist/activities/execute-deep-agent/hitl.js.map +1 -1
- package/dist/activities/execute-deep-agent/prompt-builder.d.ts +51 -23
- package/dist/activities/execute-deep-agent/prompt-builder.js +115 -76
- package/dist/activities/execute-deep-agent/prompt-builder.js.map +1 -1
- package/dist/activities/execute-deep-agent/status-builder-shared.d.ts +18 -32
- package/dist/activities/execute-deep-agent/status-builder-shared.js +10 -65
- package/dist/activities/execute-deep-agent/status-builder-shared.js.map +1 -1
- package/dist/activities/execute-deep-agent/streaming-side-effects.d.ts +10 -8
- package/dist/activities/execute-deep-agent/streaming-side-effects.js +12 -14
- package/dist/activities/execute-deep-agent/streaming-side-effects.js.map +1 -1
- package/dist/activities/execute-deep-agent/subagent-tracker.d.ts +36 -13
- package/dist/activities/execute-deep-agent/subagent-tracker.js +76 -39
- package/dist/activities/execute-deep-agent/subagent-tracker.js.map +1 -1
- package/dist/activities/execute-deep-agent/subagent-transformer.d.ts +25 -28
- package/dist/activities/execute-deep-agent/subagent-transformer.js +29 -82
- package/dist/activities/execute-deep-agent/subagent-transformer.js.map +1 -1
- package/dist/activities/execute-deep-agent/subagent-wiring.d.ts +3 -2
- package/dist/activities/execute-deep-agent/subagent-wiring.js +2 -2
- package/dist/activities/execute-deep-agent/subagent-wiring.js.map +1 -1
- package/dist/activities/execute-deep-agent/turn-settle.d.ts +42 -0
- package/dist/activities/execute-deep-agent/turn-settle.js +146 -0
- package/dist/activities/execute-deep-agent/turn-settle.js.map +1 -0
- package/dist/activities/execute-deep-agent/turn-setup.d.ts +212 -0
- package/dist/activities/execute-deep-agent/turn-setup.js +430 -0
- package/dist/activities/execute-deep-agent/turn-setup.js.map +1 -0
- package/dist/activities/execute-deep-agent/turn-stream.d.ts +97 -0
- package/dist/activities/execute-deep-agent/turn-stream.js +242 -0
- package/dist/activities/execute-deep-agent/turn-stream.js.map +1 -0
- package/dist/activities/execute-deep-agent/turn.d.ts +42 -0
- package/dist/activities/execute-deep-agent/turn.js +116 -0
- package/dist/activities/execute-deep-agent/turn.js.map +1 -0
- package/dist/activities/execute-deep-agent/v3-event-recorder.d.ts +6 -5
- package/dist/activities/execute-deep-agent/v3-event-recorder.js +6 -5
- package/dist/activities/execute-deep-agent/v3-event-recorder.js.map +1 -1
- package/dist/activities/execute-deep-agent/v3-events.d.ts +1 -1
- package/dist/activities/execute-deep-agent/v3-events.js +1 -1
- package/dist/activities/execute-deep-agent/v3-status-builder.d.ts +60 -17
- package/dist/activities/execute-deep-agent/v3-status-builder.js +72 -57
- package/dist/activities/execute-deep-agent/v3-status-builder.js.map +1 -1
- package/dist/harness/approval-decisions.d.ts +61 -0
- package/dist/harness/approval-decisions.js +102 -0
- package/dist/harness/approval-decisions.js.map +1 -0
- package/dist/harness/capabilities.d.ts +16 -5
- package/dist/harness/capabilities.js +9 -0
- package/dist/harness/capabilities.js.map +1 -1
- package/dist/harness/capture.d.ts +144 -0
- package/dist/harness/capture.js +219 -0
- package/dist/harness/capture.js.map +1 -0
- package/dist/harness/persist-chokepoint.d.ts +19 -4
- package/dist/harness/persist-chokepoint.js +17 -4
- package/dist/harness/persist-chokepoint.js.map +1 -1
- package/dist/harness/run-turn.js +115 -29
- package/dist/harness/run-turn.js.map +1 -1
- package/dist/harness/terminal-table.d.ts +40 -11
- package/dist/harness/terminal-table.js +58 -19
- package/dist/harness/terminal-table.js.map +1 -1
- package/dist/harness/turn-context.d.ts +141 -76
- package/dist/harness/turn-context.js +194 -99
- package/dist/harness/turn-context.js.map +1 -1
- package/dist/harness/types.d.ts +65 -12
- package/dist/harness/types.js +8 -2
- package/dist/harness/types.js.map +1 -1
- package/dist/harness-adapters.d.ts +12 -8
- package/dist/harness-adapters.js +17 -9
- package/dist/harness-adapters.js.map +1 -1
- package/dist/middleware/approval-gate.d.ts +1 -1
- package/dist/middleware/approval-gate.js +1 -1
- package/dist/middleware/approval-gate.js.map +1 -1
- package/dist/middleware/cost-advisory.d.ts +39 -0
- package/dist/middleware/{cost-cap.js → cost-advisory.js} +37 -55
- package/dist/middleware/cost-advisory.js.map +1 -0
- package/dist/middleware/index.d.ts +23 -12
- package/dist/middleware/index.js +26 -18
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/types.d.ts +3 -2
- package/dist/runner-manager.js +1 -5
- package/dist/runner-manager.js.map +1 -1
- package/dist/runner.js +1 -5
- package/dist/runner.js.map +1 -1
- package/dist/shared/attachment-resolver.d.ts +41 -18
- package/dist/shared/attachment-resolver.js +178 -46
- package/dist/shared/attachment-resolver.js.map +1 -1
- package/dist/shared/attachment-zip.d.ts +85 -0
- package/dist/shared/attachment-zip.js +185 -0
- package/dist/shared/attachment-zip.js.map +1 -0
- package/dist/shared/connect-backfill.js +5 -4
- package/dist/shared/connect-backfill.js.map +1 -1
- package/dist/shared/cost-guard.d.ts +3 -3
- package/dist/shared/cost-guard.js +3 -3
- package/dist/shared/execution-status-writer.d.ts +5 -5
- package/dist/shared/execution-status-writer.js +5 -5
- package/dist/shared/extract-structured-output.d.ts +8 -7
- package/dist/shared/extract-structured-output.js +8 -7
- package/dist/shared/extract-structured-output.js.map +1 -1
- package/dist/shared/filereview/cas-progress.d.ts +1 -18
- package/dist/shared/filereview/cas-progress.js +4 -0
- package/dist/shared/filereview/cas-progress.js.map +1 -1
- package/dist/shared/filereview/cas-touched.d.ts +56 -0
- package/dist/shared/filereview/cas-touched.js +63 -0
- package/dist/shared/filereview/cas-touched.js.map +1 -0
- package/dist/shared/filereview/index.d.ts +2 -1
- package/dist/shared/filereview/index.js +2 -1
- package/dist/shared/filereview/index.js.map +1 -1
- package/dist/shared/mcp-resolver.d.ts +4 -5
- package/dist/shared/mcp-resolver.js +4 -5
- package/dist/shared/mcp-resolver.js.map +1 -1
- package/dist/shared/persist-decision.d.ts +3 -4
- package/dist/shared/persist-decision.js +3 -4
- package/dist/shared/persist-decision.js.map +1 -1
- package/dist/shared/plan-mode-permissions.d.ts +2 -2
- package/dist/shared/plan-mode-permissions.js +2 -2
- package/dist/shared/plan-mode-prompt.d.ts +1 -1
- package/dist/shared/plan-mode-prompt.js +1 -1
- package/dist/shared/prompt-sections.d.ts +163 -0
- package/dist/shared/prompt-sections.js +164 -0
- package/dist/shared/prompt-sections.js.map +1 -0
- package/dist/shared/skill-resolver.d.ts +4 -2
- package/dist/shared/skill-resolver.js +4 -2
- package/dist/shared/skill-resolver.js.map +1 -1
- package/dist/shared/tool-rounds.d.ts +32 -0
- package/dist/shared/tool-rounds.js +43 -0
- package/dist/shared/tool-rounds.js.map +1 -1
- package/dist/shared/tool-row.d.ts +34 -0
- package/dist/shared/tool-row.js +52 -0
- package/dist/shared/tool-row.js.map +1 -1
- package/dist/shared/workspace/session-provision.d.ts +3 -3
- package/dist/shared/workspace/session-provision.js +3 -3
- package/dist/shared/workspace/stigmer-link.d.ts +3 -3
- package/dist/shared/workspace/stigmer-link.js +3 -3
- package/dist/shared/workspace/writeback-coordinator.d.ts +15 -22
- package/dist/shared/workspace/writeback-coordinator.js +16 -53
- package/dist/shared/workspace/writeback-coordinator.js.map +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +1 -1
- package/package.json +4 -4
- package/src/__test-utils__/__tests__/harness-contract-self-check.test.ts +1 -0
- package/src/__test-utils__/execution-record-fixture.ts +18 -2
- package/src/__test-utils__/file-review-projection.ts +156 -0
- package/src/__test-utils__/git-workspace-fixture.ts +58 -0
- package/src/__test-utils__/harness-boot-order-child.ts +7 -2
- package/src/__test-utils__/harness-contract/contract.ts +33 -20
- package/src/__test-utils__/harness-contract/recording-sink.ts +11 -1
- package/src/__test-utils__/harness-contract/runtime-contract.ts +328 -10
- package/src/__test-utils__/harness-contract/scripted-adapter.ts +38 -6
- package/src/__test-utils__/harness-contract/types.ts +27 -3
- package/src/__test-utils__/hermetic-activity.ts +52 -14
- package/src/__test-utils__/model-registry-fixture.ts +32 -7
- package/src/__test-utils__/module-specifiers.ts +24 -0
- package/src/__test-utils__/turn-input-fixture.ts +2 -2
- package/src/__tests__/harness-boot-order.test.ts +9 -2
- package/src/activities/call-agent.ts +2 -2
- package/src/activities/execute-cursor/__test-utils__/contract-subject.ts +47 -3
- package/src/activities/execute-cursor/__test-utils__/hermetic-cursor.ts +2 -48
- package/src/activities/execute-cursor/__tests__/approval-decisions-agree.test.ts +1 -1
- package/src/activities/execute-cursor/__tests__/approval-gate.test.ts +6 -1
- package/src/activities/execute-cursor/__tests__/build-prompt.test.ts +52 -27
- package/src/activities/execute-cursor/__tests__/cas-observations.test.ts +25 -0
- package/src/activities/execute-cursor/__tests__/goldens/prompt.enhanced.everything.prompt.md +166 -0
- package/src/activities/execute-cursor/__tests__/goldens/prompt.enhanced.plan-mode.prompt.md +186 -0
- package/src/activities/execute-cursor/__tests__/goldens/prompt.hitl.recovery.prompt.md +191 -0
- package/src/activities/execute-cursor/__tests__/goldens/prompt.hitl.reinvocation.prompt.md +13 -0
- package/src/activities/execute-cursor/__tests__/goldens/prompt.resumed.prefixed.prompt.md +32 -0
- package/src/activities/execute-cursor/__tests__/goldens/prompt.resumed.raw.prompt.md +1 -0
- package/src/activities/execute-cursor/__tests__/hermetic/file-review-capture.test.ts +1 -2
- package/src/activities/execute-cursor/__tests__/hermetic/goldens/sdk-error-at-create.status.json +4 -0
- package/src/activities/execute-cursor/__tests__/hermetic/harness-contract.test.ts +24 -4
- package/src/activities/execute-cursor/__tests__/hermetic/stream-self-stop-arms.test.ts +6 -5
- package/src/activities/execute-cursor/__tests__/hermetic/thrown-error-arms.test.ts +9 -0
- package/src/activities/execute-cursor/__tests__/hitl-resume-history.test.ts +11 -8
- package/src/activities/execute-cursor/__tests__/prompt-goldens.test.ts +229 -0
- package/src/activities/execute-cursor/__tests__/same-identity-reproposal.test.ts +3 -3
- package/src/activities/execute-cursor/__tests__/sequential-gate-resume.test.ts +2 -2
- package/src/activities/execute-cursor/__tests__/turn-boundary.test.ts +78 -234
- package/src/activities/execute-cursor/__tests__/turn-stream.test.ts +1 -26
- package/src/activities/execute-cursor/adapter.ts +7 -5
- package/src/activities/execute-cursor/approval-policy.ts +5 -2
- package/src/activities/execute-cursor/approval-state.ts +16 -8
- package/src/activities/execute-cursor/cas-observations.ts +20 -2
- package/src/activities/execute-cursor/cursor-capabilities.ts +24 -5
- package/src/activities/execute-cursor/message-translator.ts +29 -41
- package/src/activities/execute-cursor/prompt-builder.ts +99 -157
- package/src/activities/execute-cursor/turn-boundary.ts +34 -140
- package/src/activities/execute-cursor/turn-settle.ts +37 -51
- package/src/activities/execute-cursor/turn-setup.ts +30 -70
- package/src/activities/execute-cursor/turn-stream.ts +8 -31
- package/src/activities/execute-cursor/turn.ts +5 -1
- package/src/activities/execute-deep-agent/__test-utils__/contract-subject.ts +391 -0
- package/src/activities/execute-deep-agent/__test-utils__/hermetic-deep-agent.ts +313 -0
- package/src/activities/execute-deep-agent/__test-utils__/hitl-script.ts +48 -0
- package/src/activities/execute-deep-agent/__test-utils__/scripted-model-module.ts +85 -0
- package/src/activities/execute-deep-agent/__test-utils__/scripted-model.ts +383 -36
- package/src/activities/execute-deep-agent/__tests__/adapter-graph-is-sdk-free.test.ts +76 -0
- package/src/activities/execute-deep-agent/__tests__/adapter-is-temporal-free.test.ts +47 -0
- package/src/activities/execute-deep-agent/__tests__/adapter.test.ts +80 -0
- package/src/activities/execute-deep-agent/__tests__/cas-capture-backend.test.ts +1 -1
- package/src/activities/execute-deep-agent/__tests__/execution-state-extended.test.ts +0 -2
- package/src/activities/execute-deep-agent/__tests__/execution-state.test.ts +0 -3
- package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.build-from-plan.prompt.md +172 -0
- package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.everything.prompt.md +167 -0
- package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.minimal.prompt.md +36 -0
- package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.plan-mode.prompt.md +178 -0
- package/src/activities/execute-deep-agent/__tests__/goldens/system-prompt.skills-below-threshold.prompt.md +158 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/file-review-capture.test.ts +210 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve-all-lease.turn1.status.json +74 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve-all-lease.turn2.status.json +104 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/approve.turn2.status.json +78 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/file-review-capture.status.json +138 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/gate.turn1.status.json +68 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/inline-artifact.turn1.status.json +154 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/inline-artifact.turn2.status.json +116 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/pause.loop.after-tool.status.json +69 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/pause.loop.mid-tool.status.json +67 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/plain-turn.status.json +47 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/platform-stop.status.json +68 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/recursion-limit.persisted.status.json +280 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/reject.turn2.status.json +77 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/resolution-error.status.json +18 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sequential-gates.turn2.status.json +99 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sequential-gates.turn3.status.json +109 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/skip.turn2.status.json +76 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.text-fallback.status.json +51 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.tier2.status.json +51 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/structured-output.tool-strategy.status.json +56 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/sub-agent-delegation.status.json +90 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/tool-call.status.json +70 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/goldens/worker-shutdown.status.json +71 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/harness-contract.test.ts +144 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/hitl-approve-all-lease.test.ts +184 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/hitl-round-trips.test.ts +203 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/hitl-sequential-gates.test.ts +170 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/inline-artifact-across-gate.test.ts +175 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/pause-vs-shutdown.test.ts +206 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/plain-turn.test.ts +142 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/platform-stop.test.ts +126 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/recursion-limit.test.ts +139 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/resolution-error.test.ts +122 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/structured-output.test.ts +236 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/sub-agent-delegation.test.ts +161 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/tool-call.test.ts +157 -0
- package/src/activities/execute-deep-agent/__tests__/hermetic/workspace-lock-timeout.test.ts +152 -0
- package/src/activities/execute-deep-agent/__tests__/hitl.test.ts +50 -122
- package/src/activities/execute-deep-agent/__tests__/inline-publisher.test.ts +8 -6
- package/src/activities/execute-deep-agent/__tests__/plan-mode-path-normalization.test.ts +2 -2
- package/src/activities/execute-deep-agent/__tests__/prompt-builder.test.ts +35 -35
- package/src/activities/execute-deep-agent/__tests__/prompt-goldens.test.ts +247 -0
- package/src/activities/execute-deep-agent/__tests__/scripted-model.test.ts +329 -0
- package/src/activities/execute-deep-agent/__tests__/status-builder-shared.test.ts +1 -20
- package/src/activities/execute-deep-agent/__tests__/streaming-side-effects.test.ts +78 -0
- package/src/activities/execute-deep-agent/__tests__/subagent-gitignored-capture.test.ts +1 -1
- package/src/activities/execute-deep-agent/__tests__/subagent-plan-mode-permissions.test.ts +2 -2
- package/src/activities/execute-deep-agent/__tests__/subagent-tracker.test.ts +57 -31
- package/src/activities/execute-deep-agent/__tests__/subagent-transformer.test.ts +19 -79
- package/src/activities/execute-deep-agent/__tests__/subagent-wiring.test.ts +15 -15
- package/src/activities/execute-deep-agent/__tests__/summarization-verification.test.ts +1 -1
- package/src/activities/execute-deep-agent/__tests__/turn-stream.test.ts +391 -0
- package/src/activities/execute-deep-agent/__tests__/v3-status-builder.test.ts +343 -38
- package/src/activities/execute-deep-agent/__tests__/vision-input.test.ts +5 -5
- package/src/activities/execute-deep-agent/adapter.ts +94 -0
- package/src/activities/execute-deep-agent/cas-capture-observer.ts +11 -0
- package/src/activities/execute-deep-agent/deep-agent-capabilities.ts +43 -0
- package/src/activities/execute-deep-agent/execution-state.ts +4 -13
- package/src/activities/execute-deep-agent/hitl.ts +100 -123
- package/src/activities/execute-deep-agent/prompt-builder.ts +141 -115
- package/src/activities/execute-deep-agent/status-builder-shared.ts +21 -84
- package/src/activities/execute-deep-agent/streaming-side-effects.ts +13 -19
- package/src/activities/execute-deep-agent/subagent-tracker.ts +77 -42
- package/src/activities/execute-deep-agent/subagent-transformer.ts +46 -105
- package/src/activities/execute-deep-agent/subagent-wiring.ts +5 -4
- package/src/activities/execute-deep-agent/turn-settle.ts +164 -0
- package/src/activities/execute-deep-agent/turn-setup.ts +541 -0
- package/src/activities/execute-deep-agent/turn-stream.ts +313 -0
- package/src/activities/execute-deep-agent/turn.ts +131 -0
- package/src/activities/execute-deep-agent/v3-event-recorder.ts +6 -5
- package/src/activities/execute-deep-agent/v3-events.ts +1 -1
- package/src/activities/execute-deep-agent/v3-status-builder.ts +84 -63
- package/src/harness/__tests__/approval-decisions.test.ts +116 -0
- package/src/harness/__tests__/capture.test.ts +268 -0
- package/src/harness/__tests__/mount-skills.test.ts +169 -0
- package/src/harness/__tests__/persist-chokepoint.test.ts +38 -2
- package/src/harness/__tests__/run-turn-deterministic.test.ts +94 -0
- package/src/harness/__tests__/run-turn.test.ts +39 -23
- package/src/harness/__tests__/turn-attachments-vision.test.ts +80 -0
- package/src/harness/__tests__/turn-context.test.ts +73 -26
- package/src/harness/approval-decisions.ts +104 -0
- package/src/harness/capabilities.ts +16 -5
- package/src/harness/capture.ts +301 -0
- package/src/harness/persist-chokepoint.ts +24 -4
- package/src/harness/run-turn.ts +120 -29
- package/src/harness/terminal-table.ts +61 -20
- package/src/harness/turn-context.ts +208 -111
- package/src/harness/types.ts +66 -12
- package/src/harness-adapters.ts +17 -9
- package/src/middleware/__tests__/approval-gate.test.ts +1 -1
- package/src/middleware/__tests__/cost-advisory.test.ts +113 -0
- package/src/middleware/approval-gate.ts +2 -2
- package/src/middleware/{cost-cap.ts → cost-advisory.ts} +40 -70
- package/src/middleware/index.ts +29 -29
- package/src/middleware/types.ts +3 -2
- package/src/runner-manager.ts +0 -8
- package/src/runner.ts +0 -8
- package/src/shared/__tests__/attachment-naming.test.ts +6 -19
- package/src/shared/__tests__/attachment-resolver.test.ts +158 -8
- package/src/shared/__tests__/attachment-zip.test.ts +236 -0
- package/src/shared/__tests__/bedrock-adapter.test.ts +1 -1
- package/src/shared/__tests__/blueprint-resolver.test.ts +43 -0
- package/src/shared/__tests__/cost-guard.test.ts +3 -3
- package/src/shared/__tests__/prompt-sections.test.ts +167 -0
- package/src/shared/__tests__/secret-leak-scan.test.ts +2 -2
- package/src/{activities/execute-deep-agent → shared}/__tests__/stamp-flowed-rows.test.ts +33 -10
- package/src/shared/__tests__/vertex-adapter.test.ts +1 -1
- package/src/shared/attachment-resolver.ts +218 -55
- package/src/shared/attachment-zip.ts +281 -0
- package/src/shared/connect-backfill.ts +9 -11
- package/src/shared/cost-guard.ts +3 -3
- package/src/shared/execution-status-writer.ts +5 -5
- package/src/shared/extract-structured-output.ts +8 -7
- package/src/shared/filereview/__tests__/capture.test.ts +86 -4
- package/src/shared/filereview/__tests__/cas-progress.test.ts +2 -1
- package/src/shared/filereview/cas-progress.ts +5 -19
- package/src/shared/filereview/cas-touched.ts +89 -0
- package/src/shared/filereview/index.ts +4 -2
- package/src/shared/mcp-resolver.ts +4 -5
- package/src/shared/persist-decision.ts +3 -4
- package/src/shared/plan-mode-permissions.ts +2 -2
- package/src/shared/plan-mode-prompt.ts +1 -1
- package/src/shared/prompt-sections.ts +256 -0
- package/src/shared/skill-resolver.ts +4 -2
- package/src/shared/tool-rounds.ts +48 -0
- package/src/shared/tool-row.ts +61 -0
- package/src/shared/workspace/__tests__/stigmer-link.test.ts +7 -22
- package/src/shared/workspace/__tests__/writeback-coordinator.test.ts +20 -61
- package/src/shared/workspace/session-provision.ts +3 -3
- package/src/shared/workspace/stigmer-link.ts +3 -3
- package/src/shared/workspace/writeback-coordinator.ts +16 -64
- package/src/tools/index.ts +1 -1
- package/dist/activities/execute-cursor/capture-flow.d.ts +0 -142
- package/dist/activities/execute-cursor/capture-flow.js +0 -285
- package/dist/activities/execute-cursor/capture-flow.js.map +0 -1
- package/dist/activities/execute-cursor/command-provenance.d.ts +0 -48
- package/dist/activities/execute-cursor/command-provenance.js +0 -38
- package/dist/activities/execute-cursor/command-provenance.js.map +0 -1
- package/dist/activities/execute-deep-agent/attachment-injector.d.ts +0 -134
- package/dist/activities/execute-deep-agent/attachment-injector.js +0 -386
- package/dist/activities/execute-deep-agent/attachment-injector.js.map +0 -1
- package/dist/activities/execute-deep-agent/command-provenance.d.ts +0 -61
- package/dist/activities/execute-deep-agent/command-provenance.js +0 -72
- package/dist/activities/execute-deep-agent/command-provenance.js.map +0 -1
- package/dist/activities/execute-deep-agent/environment.d.ts +0 -24
- package/dist/activities/execute-deep-agent/environment.js +0 -58
- package/dist/activities/execute-deep-agent/environment.js.map +0 -1
- package/dist/activities/execute-deep-agent/event-recorder.d.ts +0 -21
- package/dist/activities/execute-deep-agent/event-recorder.js +0 -67
- package/dist/activities/execute-deep-agent/event-recorder.js.map +0 -1
- package/dist/activities/execute-deep-agent/index.d.ts +0 -15
- package/dist/activities/execute-deep-agent/index.js +0 -918
- package/dist/activities/execute-deep-agent/index.js.map +0 -1
- package/dist/activities/execute-deep-agent/mcp-gate.d.ts +0 -28
- package/dist/activities/execute-deep-agent/mcp-gate.js +0 -22
- package/dist/activities/execute-deep-agent/mcp-gate.js.map +0 -1
- package/dist/activities/execute-deep-agent/post-stream.d.ts +0 -23
- package/dist/activities/execute-deep-agent/post-stream.js +0 -71
- package/dist/activities/execute-deep-agent/post-stream.js.map +0 -1
- package/dist/activities/execute-deep-agent/setup.d.ts +0 -136
- package/dist/activities/execute-deep-agent/setup.js +0 -767
- package/dist/activities/execute-deep-agent/setup.js.map +0 -1
- package/dist/activities/execute-deep-agent/stamp-flowed-rows.d.ts +0 -36
- package/dist/activities/execute-deep-agent/stamp-flowed-rows.js +0 -56
- package/dist/activities/execute-deep-agent/stamp-flowed-rows.js.map +0 -1
- package/dist/activities/execute-deep-agent/status-builder.d.ts +0 -93
- package/dist/activities/execute-deep-agent/status-builder.js +0 -365
- package/dist/activities/execute-deep-agent/status-builder.js.map +0 -1
- package/dist/activities/execute-deep-agent/streaming-terminal.d.ts +0 -21
- package/dist/activities/execute-deep-agent/streaming-terminal.js +0 -80
- package/dist/activities/execute-deep-agent/streaming-terminal.js.map +0 -1
- package/dist/activities/execute-deep-agent/streaming-v3.d.ts +0 -13
- package/dist/activities/execute-deep-agent/streaming-v3.js +0 -174
- package/dist/activities/execute-deep-agent/streaming-v3.js.map +0 -1
- package/dist/activities/execute-deep-agent/streaming.d.ts +0 -81
- package/dist/activities/execute-deep-agent/streaming.js +0 -160
- package/dist/activities/execute-deep-agent/streaming.js.map +0 -1
- package/dist/middleware/cost-cap.d.ts +0 -22
- package/dist/middleware/cost-cap.js.map +0 -1
- package/dist/middleware/graceful-stop.d.ts +0 -17
- package/dist/middleware/graceful-stop.js +0 -63
- package/dist/middleware/graceful-stop.js.map +0 -1
- package/dist/shared/skill-writer.d.ts +0 -75
- package/dist/shared/skill-writer.js +0 -207
- package/dist/shared/skill-writer.js.map +0 -1
- package/src/activities/execute-cursor/__tests__/capture-flow.test.ts +0 -1032
- package/src/activities/execute-cursor/__tests__/command-provenance.test.ts +0 -240
- package/src/activities/execute-cursor/__tests__/progress-substrate.test.ts +0 -169
- package/src/activities/execute-cursor/capture-flow.ts +0 -379
- package/src/activities/execute-cursor/command-provenance.ts +0 -73
- package/src/activities/execute-deep-agent/__tests__/attachment-injector.test.ts +0 -1161
- package/src/activities/execute-deep-agent/__tests__/command-provenance.test.ts +0 -252
- package/src/activities/execute-deep-agent/__tests__/environment.test.ts +0 -108
- package/src/activities/execute-deep-agent/__tests__/event-recorder.test.ts +0 -150
- package/src/activities/execute-deep-agent/__tests__/hitl-integration.test.ts +0 -226
- package/src/activities/execute-deep-agent/__tests__/hitl-reject.test.ts +0 -318
- package/src/activities/execute-deep-agent/__tests__/hitl-resume-approve-all.test.ts +0 -351
- package/src/activities/execute-deep-agent/__tests__/hitl-resume-history.test.ts +0 -293
- package/src/activities/execute-deep-agent/__tests__/index.test.ts +0 -99
- package/src/activities/execute-deep-agent/__tests__/mcp-gate.test.ts +0 -44
- package/src/activities/execute-deep-agent/__tests__/post-stream.test.ts +0 -112
- package/src/activities/execute-deep-agent/__tests__/sequential-gate-resume.test.ts +0 -358
- package/src/activities/execute-deep-agent/__tests__/status-builder.test.ts +0 -1933
- package/src/activities/execute-deep-agent/__tests__/streaming-terminal.test.ts +0 -40
- package/src/activities/execute-deep-agent/__tests__/streaming-v3.test.ts +0 -597
- package/src/activities/execute-deep-agent/__tests__/streaming.test.ts +0 -508
- package/src/activities/execute-deep-agent/attachment-injector.ts +0 -627
- package/src/activities/execute-deep-agent/command-provenance.ts +0 -102
- package/src/activities/execute-deep-agent/environment.ts +0 -76
- package/src/activities/execute-deep-agent/event-recorder.ts +0 -95
- package/src/activities/execute-deep-agent/index.ts +0 -1072
- package/src/activities/execute-deep-agent/mcp-gate.ts +0 -37
- package/src/activities/execute-deep-agent/post-stream.ts +0 -109
- package/src/activities/execute-deep-agent/setup.ts +0 -1081
- package/src/activities/execute-deep-agent/stamp-flowed-rows.ts +0 -64
- package/src/activities/execute-deep-agent/status-builder.ts +0 -481
- package/src/activities/execute-deep-agent/streaming-terminal.ts +0 -106
- package/src/activities/execute-deep-agent/streaming-v3.ts +0 -277
- package/src/activities/execute-deep-agent/streaming.ts +0 -313
- package/src/middleware/__tests__/cost-cap.test.ts +0 -192
- package/src/middleware/__tests__/graceful-stop.test.ts +0 -105
- package/src/middleware/graceful-stop.ts +0 -86
- package/src/shared/__tests__/skill-writer.test.ts +0 -372
- package/src/shared/skill-writer.ts +0 -266
|
@@ -3,45 +3,191 @@
|
|
|
3
3
|
* parent-checkpoint interrupt reader.
|
|
4
4
|
*
|
|
5
5
|
* These two helpers are what every "drive a real deepagents/LangGraph graph
|
|
6
|
-
* through the approval gate" test needs
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* through the approval gate" test needs. They are shared by the graph-level
|
|
7
|
+
* tests (`__tests__/subagent-approval-propagation.test.ts`,
|
|
8
|
+
* `shell-execute-gate.test.ts`, …), the gateway Contract Test Kit adapter
|
|
9
|
+
* (`gateway-substrate.ts`), and the hermetic activity driver
|
|
10
|
+
* (`hermetic-deep-agent.ts`), which runs the REAL `ExecuteDeepAgent` activity
|
|
11
|
+
* with this model as the only LLM. Keeping one copy means a change to how the
|
|
12
|
+
* runner reads pending interrupts (or how a scripted run is driven) updates
|
|
13
|
+
* every consumer at once.
|
|
12
14
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
+
* The one rule the model keeps: it is a PURE FUNCTION of (bound tools,
|
|
16
|
+
* transcript). A script is a sequence of turns per role, and the turn to play
|
|
17
|
+
* is chosen by how many tool rounds the transcript already holds (AI messages
|
|
18
|
+
* carrying `tool_calls`), never by a call counter. That is what lets one
|
|
19
|
+
* script serve both checkpointers the runner ships: under `memory` a HITL
|
|
20
|
+
* reinvocation REPLAYS the graph from the first message (the saver is
|
|
21
|
+
* recreated empty per invocation), so the same transcript indices produce the
|
|
22
|
+
* same proposals; under `sqlite` the graph RESUMES after the interrupt and the
|
|
23
|
+
* next call sees one more completed round. A call-counted script would emit
|
|
24
|
+
* the wrong turn on replay.
|
|
25
|
+
*
|
|
26
|
+
* A script may also be a {@link TurnPlayer}: a function of the whole
|
|
27
|
+
* transcript that returns the one turn to play now. The same rule, with the
|
|
28
|
+
* indexing left to the caller — for a consumer whose plan is not "turn k on
|
|
29
|
+
* round k" but "the first step the conversation does not yet show" (the
|
|
30
|
+
* harness contract kit's native subject, whose one execution spans many
|
|
31
|
+
* kit turns on one sqlite thread, S3 M3).
|
|
32
|
+
*
|
|
33
|
+
* A turn may END the model call instead of finishing the message
|
|
34
|
+
* ({@link TurnEnding}): `fail` throws after its chunks (a provider error
|
|
35
|
+
* mid-stream); `hang` parks on the call's abort signal after its chunks and
|
|
36
|
+
* throws the abort when it fires (a provider stream that stalls and is then
|
|
37
|
+
* cancelled). A hang never parks on a timer: `@langchain/core` hands the
|
|
38
|
+
* graph run's signal to `_streamResponseChunks` as `options.signal`
|
|
39
|
+
* (`_separateRunnableConfigFromCallOptionsCompat`), and LangGraph threads
|
|
40
|
+
* its composite abort signal into every task's config, so the runtime's one
|
|
41
|
+
* stop is what unparks it. The `onPark` hook is how a test learns the engine
|
|
42
|
+
* is silent before it stops the turn from the outside.
|
|
43
|
+
*
|
|
44
|
+
* The model STREAMS. With LangGraph's v3 messages handler attached, LangChain
|
|
45
|
+
* Core streams a model internally when it implements `_streamResponseChunks`
|
|
46
|
+
* and otherwise falls back to a synthesized final-message event sequence
|
|
47
|
+
* (`@langchain/langgraph` `pregel/messages-v2.js` `emitFinalMessage`). The
|
|
48
|
+
* fallback spreads a `tool_call` block's `args` OBJECT into the
|
|
49
|
+
* `tool_call_chunk` fields the runner's normalizer reads as a JSON STRING
|
|
50
|
+
* (`v3-protocol-normalizer.ts` `argsChunk`), which no real provider does.
|
|
51
|
+
* Streaming keeps the double on the production event path: `@langchain/core`
|
|
52
|
+
* `language_models/compat.js` `convertChunksToEvents` turns the chunks below
|
|
53
|
+
* into `message-start`, per-block `content-block-start` / `-delta` /
|
|
54
|
+
* `-finish`, and `message-finish` with usage — the same events `ChatAnthropic`
|
|
55
|
+
* produces. The chunk shapes are chosen from that converter: a string chunk
|
|
56
|
+
* opens block 0 and emits a text delta in one step; an array-content part
|
|
57
|
+
* opens its block with NO delta on first sight, so a reasoning block is sent
|
|
58
|
+
* as an empty opener followed by the text; a `tool_call_chunk` always emits a
|
|
59
|
+
* delta carrying the accumulated JSON args; `usage_metadata` rides the LAST
|
|
60
|
+
* chunk so it lands on `message-finish` (the one place the runner reads it),
|
|
61
|
+
* not on `message-start`.
|
|
15
62
|
*/
|
|
16
63
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
64
|
+
import type { BaseChatModelCallOptions } from "@langchain/core/language_models/chat_models";
|
|
65
|
+
import type { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
|
|
17
66
|
import { type BaseMessage } from "@langchain/core/messages";
|
|
18
|
-
import type
|
|
19
|
-
/** A single tool call the scripted model proposes on a
|
|
67
|
+
import { ChatGenerationChunk, type ChatResult } from "@langchain/core/outputs";
|
|
68
|
+
/** A single tool call the scripted model proposes on a turn. */
|
|
20
69
|
export interface ScriptedToolCall {
|
|
21
70
|
name: string;
|
|
22
71
|
args: Record<string, unknown>;
|
|
23
72
|
id: string;
|
|
24
73
|
}
|
|
25
74
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
75
|
+
* Token usage a turn reports; fixed round numbers keep `streamingUsage`
|
|
76
|
+
* legible in a golden. The cache buckets ride `input_token_details` the way
|
|
77
|
+
* the Anthropic adapter reports them (`cache_read`, `cache_creation`);
|
|
78
|
+
* `inputTokens` is the total the provider states, cache included.
|
|
79
|
+
*/
|
|
80
|
+
export interface ScriptedUsage {
|
|
81
|
+
readonly inputTokens: number;
|
|
82
|
+
readonly outputTokens: number;
|
|
83
|
+
readonly cacheReadTokens?: number;
|
|
84
|
+
readonly cacheWriteTokens?: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* How a turn ends the model call instead of finishing its message.
|
|
88
|
+
* - `fail`: throw `error` after the turn's chunks — a provider error
|
|
89
|
+
* mid-stream; the graph propagates it and the adapter classifies it.
|
|
90
|
+
* - `hang`: after the turn's chunks, park on the call's abort signal and
|
|
91
|
+
* throw the abort when it fires — a stalled provider stream, cancelled by
|
|
92
|
+
* the run's one stop. Refused (thrown, diagnosing) when the call carries
|
|
93
|
+
* no signal: a hang outside an abortable run would park forever.
|
|
94
|
+
*/
|
|
95
|
+
export type TurnEnding = {
|
|
96
|
+
readonly kind: "fail";
|
|
97
|
+
readonly error: Error;
|
|
98
|
+
} | {
|
|
99
|
+
readonly kind: "hang";
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* One assistant turn, rendered in the standard content-block shape a
|
|
103
|
+
* streaming provider produces: an optional leading reasoning block, an
|
|
104
|
+
* optional text block, and one `tool_call` per entry of `toolCalls` (which is
|
|
105
|
+
* also what the graph executes). A turn with neither text nor tool calls is
|
|
106
|
+
* an empty assistant message — legal, and what a script that has said all it
|
|
107
|
+
* has to say looks like. A turn with `ends` never finishes its message: its
|
|
108
|
+
* chunks are streamed, then the ending takes the call.
|
|
109
|
+
*/
|
|
110
|
+
export interface ScriptedTurn {
|
|
111
|
+
readonly reasoning?: string;
|
|
112
|
+
readonly text?: string;
|
|
113
|
+
readonly toolCalls?: readonly ScriptedToolCall[];
|
|
114
|
+
readonly usage?: ScriptedUsage;
|
|
115
|
+
readonly ends?: TurnEnding;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A role's script: `turns[k]` is played when the transcript already holds `k`
|
|
119
|
+
* completed tool rounds. Running past the end throws (a script that runs out
|
|
120
|
+
* is a test bug) unless `repeatLast` is set, in which case the final turn
|
|
121
|
+
* plays again — the shape of a model that keeps calling a tool until the
|
|
122
|
+
* graph's recursion limit stops it.
|
|
123
|
+
*/
|
|
124
|
+
export interface RoleScript {
|
|
125
|
+
readonly turns: readonly ScriptedTurn[];
|
|
126
|
+
readonly repeatLast?: boolean;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The two-turn sugar most graph-level tests use: propose `toolCalls` on the
|
|
130
|
+
* first round, then say `done` on every round after. Exactly
|
|
131
|
+
* `{ turns: [{ toolCalls }, { text: done }], repeatLast: true }`.
|
|
28
132
|
*/
|
|
29
133
|
export interface ScriptStep {
|
|
30
134
|
toolCalls: ScriptedToolCall[];
|
|
31
135
|
done: string;
|
|
32
136
|
}
|
|
33
137
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
138
|
+
* What a selector can tell one role from another by. `createDeepAgent` gives
|
|
139
|
+
* a declared sub-agent the SAME tool set as its parent (`task` included), so
|
|
140
|
+
* tool names alone cannot separate them; the system prompt can — it carries
|
|
141
|
+
* the role's own instructions.
|
|
38
142
|
*/
|
|
39
|
-
export
|
|
143
|
+
export interface ScriptRoleContext {
|
|
144
|
+
/** The transcript's leading system message, or "" when there is none. */
|
|
145
|
+
readonly systemPrompt: string;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* A script as a function of the whole transcript: called on every model turn
|
|
149
|
+
* with the messages the model was asked with, returns the turn to play. The
|
|
150
|
+
* round-indexed `RoleScript` is the common case; this is for a plan whose
|
|
151
|
+
* progress is read off the conversation itself (see the header).
|
|
152
|
+
*/
|
|
153
|
+
export type TurnPlayer = (transcript: readonly BaseMessage[]) => ScriptedTurn;
|
|
154
|
+
/** The three shapes a selector may answer with. */
|
|
155
|
+
export type Script = ScriptStep | RoleScript | TurnPlayer;
|
|
40
156
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* role
|
|
44
|
-
*
|
|
157
|
+
* Picks the script for the role being asked. A single-agent test ignores both
|
|
158
|
+
* arguments; a parent/sub-agent test keys the role on a tool unique to one
|
|
159
|
+
* role when there is one (a custom counting tool), or on the role's
|
|
160
|
+
* instructions in `context.systemPrompt` when both roles bind the same tools
|
|
161
|
+
* (the hermetic delegation arm). Called at `_generate` time, never at bind
|
|
162
|
+
* time, so a role that is compiled but never invoked (the default
|
|
163
|
+
* general-purpose sub-agent) needs no script.
|
|
164
|
+
*/
|
|
165
|
+
export type ScriptSelector = (boundToolNames: string[], context: ScriptRoleContext) => Script;
|
|
166
|
+
/** What the driver learns before a turn is rendered: which role, which round. */
|
|
167
|
+
export interface ScriptedTurnInfo {
|
|
168
|
+
readonly boundToolNames: readonly string[];
|
|
169
|
+
readonly round: number;
|
|
170
|
+
}
|
|
171
|
+
export interface ScriptedModelOptions {
|
|
172
|
+
/**
|
|
173
|
+
* Called once per model turn, before it is rendered. The hermetic driver
|
|
174
|
+
* ticks its clock here and runs a scenario's scheduled effect (a user pause,
|
|
175
|
+
* a worker shutdown) — from a model turn, never from a timer, so the
|
|
176
|
+
* interruption lands at the same instant every run.
|
|
177
|
+
*/
|
|
178
|
+
readonly onTurn?: (info: ScriptedTurnInfo) => void | Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Called the moment a `hang` turn parks on its abort signal — the engine
|
|
181
|
+
* is silent from here until the signal fires. A test that must stop the
|
|
182
|
+
* turn from the outside (the contract kit's `whenHanging`) listens here,
|
|
183
|
+
* so the stop lands in the hang and never in the adapter's setup.
|
|
184
|
+
*/
|
|
185
|
+
readonly onPark?: () => void;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* A deterministic chat model driven by a per-role script. No LLM, no network.
|
|
189
|
+
* The role is keyed on the bound tool names so the same instance drives a
|
|
190
|
+
* parent and its sub-agents.
|
|
45
191
|
*/
|
|
46
192
|
export declare class ScriptedModel extends BaseChatModel {
|
|
47
193
|
toolNames: string[];
|
|
@@ -54,11 +200,29 @@ export declare class ScriptedModel extends BaseChatModel {
|
|
|
54
200
|
*/
|
|
55
201
|
readonly boundTools: unknown[];
|
|
56
202
|
private readonly select;
|
|
57
|
-
|
|
203
|
+
private readonly options;
|
|
204
|
+
constructor(select: ScriptSelector, boundTools?: unknown[], options?: ScriptedModelOptions);
|
|
58
205
|
_llmType(): string;
|
|
59
206
|
bindTools(tools: unknown[]): this;
|
|
60
|
-
|
|
207
|
+
/** The turn for this transcript, after the driver hook has run. */
|
|
208
|
+
private turnFor;
|
|
209
|
+
/**
|
|
210
|
+
* The non-streaming path (`invoke` outside a graph — the runtime's tier-2
|
|
211
|
+
* structured-output extractor is the one caller): the SAME chunks the
|
|
212
|
+
* streaming path yields, merged, which is the `AIMessageChunk` a streaming
|
|
213
|
+
* provider's `invoke` returns. `@langchain/core`'s base `withStructuredOutput`
|
|
214
|
+
* pipeline reads exactly that shape (`AIMessageChunk.isInstance`, then
|
|
215
|
+
* `tool_calls`); a plain `AIMessage` here would fail it with "Input is not
|
|
216
|
+
* an AIMessageChunk" where the real provider succeeds. An ending turn ends
|
|
217
|
+
* this call the same way it ends the stream.
|
|
218
|
+
*/
|
|
219
|
+
_generate(messages: BaseMessage[], options: this["ParsedCallOptions"]): Promise<ChatResult>;
|
|
220
|
+
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"] & BaseChatModelCallOptions, _runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
|
221
|
+
/** Never returns: throws the ending's error, or parks on the signal and throws its abort. */
|
|
222
|
+
private takeEnding;
|
|
61
223
|
}
|
|
224
|
+
/** Tool rounds the transcript already holds: AI messages that proposed at least one tool call. */
|
|
225
|
+
export declare function completedToolRounds(messages: readonly BaseMessage[]): number;
|
|
62
226
|
/** A pending approval interrupt surfaced at the parent checkpoint. */
|
|
63
227
|
export interface PendingInterrupt {
|
|
64
228
|
taskId: string;
|
|
@@ -3,23 +3,70 @@
|
|
|
3
3
|
* parent-checkpoint interrupt reader.
|
|
4
4
|
*
|
|
5
5
|
* These two helpers are what every "drive a real deepagents/LangGraph graph
|
|
6
|
-
* through the approval gate" test needs
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* through the approval gate" test needs. They are shared by the graph-level
|
|
7
|
+
* tests (`__tests__/subagent-approval-propagation.test.ts`,
|
|
8
|
+
* `shell-execute-gate.test.ts`, …), the gateway Contract Test Kit adapter
|
|
9
|
+
* (`gateway-substrate.ts`), and the hermetic activity driver
|
|
10
|
+
* (`hermetic-deep-agent.ts`), which runs the REAL `ExecuteDeepAgent` activity
|
|
11
|
+
* with this model as the only LLM. Keeping one copy means a change to how the
|
|
12
|
+
* runner reads pending interrupts (or how a scripted run is driven) updates
|
|
13
|
+
* every consumer at once.
|
|
12
14
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
+
* The one rule the model keeps: it is a PURE FUNCTION of (bound tools,
|
|
16
|
+
* transcript). A script is a sequence of turns per role, and the turn to play
|
|
17
|
+
* is chosen by how many tool rounds the transcript already holds (AI messages
|
|
18
|
+
* carrying `tool_calls`), never by a call counter. That is what lets one
|
|
19
|
+
* script serve both checkpointers the runner ships: under `memory` a HITL
|
|
20
|
+
* reinvocation REPLAYS the graph from the first message (the saver is
|
|
21
|
+
* recreated empty per invocation), so the same transcript indices produce the
|
|
22
|
+
* same proposals; under `sqlite` the graph RESUMES after the interrupt and the
|
|
23
|
+
* next call sees one more completed round. A call-counted script would emit
|
|
24
|
+
* the wrong turn on replay.
|
|
25
|
+
*
|
|
26
|
+
* A script may also be a {@link TurnPlayer}: a function of the whole
|
|
27
|
+
* transcript that returns the one turn to play now. The same rule, with the
|
|
28
|
+
* indexing left to the caller — for a consumer whose plan is not "turn k on
|
|
29
|
+
* round k" but "the first step the conversation does not yet show" (the
|
|
30
|
+
* harness contract kit's native subject, whose one execution spans many
|
|
31
|
+
* kit turns on one sqlite thread, S3 M3).
|
|
32
|
+
*
|
|
33
|
+
* A turn may END the model call instead of finishing the message
|
|
34
|
+
* ({@link TurnEnding}): `fail` throws after its chunks (a provider error
|
|
35
|
+
* mid-stream); `hang` parks on the call's abort signal after its chunks and
|
|
36
|
+
* throws the abort when it fires (a provider stream that stalls and is then
|
|
37
|
+
* cancelled). A hang never parks on a timer: `@langchain/core` hands the
|
|
38
|
+
* graph run's signal to `_streamResponseChunks` as `options.signal`
|
|
39
|
+
* (`_separateRunnableConfigFromCallOptionsCompat`), and LangGraph threads
|
|
40
|
+
* its composite abort signal into every task's config, so the runtime's one
|
|
41
|
+
* stop is what unparks it. The `onPark` hook is how a test learns the engine
|
|
42
|
+
* is silent before it stops the turn from the outside.
|
|
43
|
+
*
|
|
44
|
+
* The model STREAMS. With LangGraph's v3 messages handler attached, LangChain
|
|
45
|
+
* Core streams a model internally when it implements `_streamResponseChunks`
|
|
46
|
+
* and otherwise falls back to a synthesized final-message event sequence
|
|
47
|
+
* (`@langchain/langgraph` `pregel/messages-v2.js` `emitFinalMessage`). The
|
|
48
|
+
* fallback spreads a `tool_call` block's `args` OBJECT into the
|
|
49
|
+
* `tool_call_chunk` fields the runner's normalizer reads as a JSON STRING
|
|
50
|
+
* (`v3-protocol-normalizer.ts` `argsChunk`), which no real provider does.
|
|
51
|
+
* Streaming keeps the double on the production event path: `@langchain/core`
|
|
52
|
+
* `language_models/compat.js` `convertChunksToEvents` turns the chunks below
|
|
53
|
+
* into `message-start`, per-block `content-block-start` / `-delta` /
|
|
54
|
+
* `-finish`, and `message-finish` with usage — the same events `ChatAnthropic`
|
|
55
|
+
* produces. The chunk shapes are chosen from that converter: a string chunk
|
|
56
|
+
* opens block 0 and emits a text delta in one step; an array-content part
|
|
57
|
+
* opens its block with NO delta on first sight, so a reasoning block is sent
|
|
58
|
+
* as an empty opener followed by the text; a `tool_call_chunk` always emits a
|
|
59
|
+
* delta carrying the accumulated JSON args; `usage_metadata` rides the LAST
|
|
60
|
+
* chunk so it lands on `message-finish` (the one place the runner reads it),
|
|
61
|
+
* not on `message-start`.
|
|
15
62
|
*/
|
|
16
63
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
17
|
-
import {
|
|
64
|
+
import { AIMessageChunk, isAIMessage, isSystemMessage, } from "@langchain/core/messages";
|
|
65
|
+
import { ChatGenerationChunk } from "@langchain/core/outputs";
|
|
18
66
|
/**
|
|
19
|
-
* A deterministic
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* tool names so the same model instance drives a parent and its sub-agents.
|
|
67
|
+
* A deterministic chat model driven by a per-role script. No LLM, no network.
|
|
68
|
+
* The role is keyed on the bound tool names so the same instance drives a
|
|
69
|
+
* parent and its sub-agents.
|
|
23
70
|
*/
|
|
24
71
|
export class ScriptedModel extends BaseChatModel {
|
|
25
72
|
toolNames = [];
|
|
@@ -32,33 +79,197 @@ export class ScriptedModel extends BaseChatModel {
|
|
|
32
79
|
*/
|
|
33
80
|
boundTools;
|
|
34
81
|
select;
|
|
35
|
-
|
|
82
|
+
options;
|
|
83
|
+
constructor(select, boundTools = [], options = {}) {
|
|
36
84
|
super({});
|
|
37
85
|
this.select = select;
|
|
38
86
|
this.boundTools = boundTools;
|
|
87
|
+
this.options = options;
|
|
39
88
|
}
|
|
40
89
|
_llmType() {
|
|
41
90
|
return "scripted";
|
|
42
91
|
}
|
|
43
92
|
bindTools(tools) {
|
|
44
|
-
const next = new ScriptedModel(this.select, this.boundTools);
|
|
45
|
-
next.toolNames = tools.map(
|
|
93
|
+
const next = new ScriptedModel(this.select, this.boundTools, this.options);
|
|
94
|
+
next.toolNames = tools.map(boundToolName);
|
|
46
95
|
this.boundTools.length = 0;
|
|
47
96
|
this.boundTools.push(...tools);
|
|
48
97
|
return next;
|
|
49
98
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
99
|
+
/** The turn for this transcript, after the driver hook has run. */
|
|
100
|
+
async turnFor(messages) {
|
|
101
|
+
const round = completedToolRounds(messages);
|
|
102
|
+
await this.options.onTurn?.({ boundToolNames: this.toolNames, round });
|
|
103
|
+
const context = { systemPrompt: systemPromptOf(messages) };
|
|
104
|
+
return resolveTurn(this.select(this.toolNames, context), { round, transcript: messages, toolNames: this.toolNames });
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The non-streaming path (`invoke` outside a graph — the runtime's tier-2
|
|
108
|
+
* structured-output extractor is the one caller): the SAME chunks the
|
|
109
|
+
* streaming path yields, merged, which is the `AIMessageChunk` a streaming
|
|
110
|
+
* provider's `invoke` returns. `@langchain/core`'s base `withStructuredOutput`
|
|
111
|
+
* pipeline reads exactly that shape (`AIMessageChunk.isInstance`, then
|
|
112
|
+
* `tool_calls`); a plain `AIMessage` here would fail it with "Input is not
|
|
113
|
+
* an AIMessageChunk" where the real provider succeeds. An ending turn ends
|
|
114
|
+
* this call the same way it ends the stream.
|
|
115
|
+
*/
|
|
116
|
+
async _generate(messages, options) {
|
|
117
|
+
const turn = await this.turnFor(messages);
|
|
118
|
+
if (turn.ends)
|
|
119
|
+
await this.takeEnding(turn.ends, options.signal);
|
|
120
|
+
const message = renderTurnChunks(turn).reduce((merged, chunk) => merged.concat(chunk));
|
|
121
|
+
return { generations: [{ message, text: turn.text ?? "" }] };
|
|
122
|
+
}
|
|
123
|
+
async *_streamResponseChunks(messages, options, _runManager) {
|
|
124
|
+
const turn = await this.turnFor(messages);
|
|
125
|
+
for (const chunk of renderTurnChunks(turn)) {
|
|
126
|
+
yield new ChatGenerationChunk({ message: chunk, text: typeof chunk.content === "string" ? chunk.content : "" });
|
|
127
|
+
}
|
|
128
|
+
if (turn.ends)
|
|
129
|
+
await this.takeEnding(turn.ends, options.signal);
|
|
130
|
+
}
|
|
131
|
+
/** Never returns: throws the ending's error, or parks on the signal and throws its abort. */
|
|
132
|
+
async takeEnding(ending, signal) {
|
|
133
|
+
switch (ending.kind) {
|
|
134
|
+
case "fail":
|
|
135
|
+
throw ending.error;
|
|
136
|
+
case "hang": {
|
|
137
|
+
if (!signal) {
|
|
138
|
+
throw new Error("ScriptedModel: a `hang` turn parks on the call's abort signal and this call carried none; " +
|
|
139
|
+
"a hang is only meaningful inside a run that can be aborted");
|
|
140
|
+
}
|
|
141
|
+
this.options.onPark?.();
|
|
142
|
+
if (!signal.aborted) {
|
|
143
|
+
await new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }));
|
|
144
|
+
}
|
|
145
|
+
throw abortErrorOf(signal);
|
|
146
|
+
}
|
|
147
|
+
default: {
|
|
148
|
+
const exhaustive = ending;
|
|
149
|
+
throw new Error(`ScriptedModel: unknown turn ending ${String(exhaustive)}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** What a provider SDK throws when its in-flight request is aborted: the signal's own reason, or an `AbortError` naming it. */
|
|
155
|
+
function abortErrorOf(signal) {
|
|
156
|
+
if (signal.reason instanceof Error)
|
|
157
|
+
return signal.reason;
|
|
158
|
+
const err = new Error(`ScriptedModel: the hang was aborted (${String(signal.reason)})`);
|
|
159
|
+
err.name = "AbortError";
|
|
160
|
+
return err;
|
|
161
|
+
}
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
// Script resolution
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
/**
|
|
166
|
+
* The name a bound tool answers to: a LangChain tool's `name`, or an
|
|
167
|
+
* OpenAI-style function definition's `function.name` (how langchain binds the
|
|
168
|
+
* structured-output schema tool of `toolStrategy`). A real provider client
|
|
169
|
+
* accepts both shapes; so does this double.
|
|
170
|
+
*/
|
|
171
|
+
function boundToolName(tool) {
|
|
172
|
+
const t = tool;
|
|
173
|
+
if (typeof t?.name === "string")
|
|
174
|
+
return t.name;
|
|
175
|
+
if (typeof t?.function?.name === "string")
|
|
176
|
+
return t.function.name;
|
|
177
|
+
return "";
|
|
178
|
+
}
|
|
179
|
+
function systemPromptOf(messages) {
|
|
180
|
+
const system = messages.find((m) => isSystemMessage(m));
|
|
181
|
+
if (!system)
|
|
182
|
+
return "";
|
|
183
|
+
return typeof system.content === "string" ? system.content : system.text;
|
|
184
|
+
}
|
|
185
|
+
function normalizeScript(script) {
|
|
186
|
+
if ("done" in script) {
|
|
187
|
+
return { turns: [{ toolCalls: script.toolCalls }, { text: script.done }], repeatLast: true };
|
|
188
|
+
}
|
|
189
|
+
return script;
|
|
190
|
+
}
|
|
191
|
+
/** Tool rounds the transcript already holds: AI messages that proposed at least one tool call. */
|
|
192
|
+
export function completedToolRounds(messages) {
|
|
193
|
+
let rounds = 0;
|
|
194
|
+
for (const m of messages) {
|
|
195
|
+
if (isAIMessage(m) && (m.tool_calls?.length ?? 0) > 0)
|
|
196
|
+
rounds += 1;
|
|
197
|
+
}
|
|
198
|
+
return rounds;
|
|
199
|
+
}
|
|
200
|
+
function resolveTurn(script, request) {
|
|
201
|
+
if (typeof script === "function")
|
|
202
|
+
return script(request.transcript);
|
|
203
|
+
const role = normalizeScript(script);
|
|
204
|
+
const { round, toolNames } = request;
|
|
205
|
+
if (round < role.turns.length)
|
|
206
|
+
return role.turns[round];
|
|
207
|
+
if (role.repeatLast && role.turns.length > 0)
|
|
208
|
+
return role.turns[role.turns.length - 1];
|
|
209
|
+
throw new Error(`ScriptedModel: the script for role [${toolNames.join(", ")}] has ${role.turns.length} turn(s) ` +
|
|
210
|
+
`but the transcript already holds ${round} completed tool round(s); ` +
|
|
211
|
+
"add a turn or set repeatLast.");
|
|
212
|
+
}
|
|
213
|
+
// ---------------------------------------------------------------------------
|
|
214
|
+
// Rendering: the chunk sequence (stream), merged into one message for invoke
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
function usageMetadataOf(usage) {
|
|
217
|
+
if (!usage)
|
|
218
|
+
return undefined;
|
|
219
|
+
const hasCacheBuckets = usage.cacheReadTokens !== undefined || usage.cacheWriteTokens !== undefined;
|
|
220
|
+
return {
|
|
221
|
+
input_tokens: usage.inputTokens,
|
|
222
|
+
output_tokens: usage.outputTokens,
|
|
223
|
+
total_tokens: usage.inputTokens + usage.outputTokens,
|
|
224
|
+
...(hasCacheBuckets
|
|
225
|
+
? { input_token_details: { cache_read: usage.cacheReadTokens ?? 0, cache_creation: usage.cacheWriteTokens ?? 0 } }
|
|
226
|
+
: {}),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function reasoningBlock(reasoning, index) {
|
|
230
|
+
return { type: "reasoning", reasoning, ...(index !== undefined ? { index } : {}) };
|
|
231
|
+
}
|
|
232
|
+
function textBlock(text, index) {
|
|
233
|
+
return { type: "text", text, ...(index !== undefined ? { index } : {}) };
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* The chunk sequence `convertChunksToEvents` turns into the production event
|
|
237
|
+
* stream (see the header). An ending turn gets NO closing chunk: its message
|
|
238
|
+
* never finishes — the ending takes the call after these chunks.
|
|
239
|
+
*/
|
|
240
|
+
function renderTurnChunks(turn) {
|
|
241
|
+
const chunks = [];
|
|
242
|
+
let nextIndex = 0;
|
|
243
|
+
if (turn.reasoning) {
|
|
244
|
+
const index = nextIndex++;
|
|
245
|
+
chunks.push(new AIMessageChunk({ content: [reasoningBlock("", index)] }));
|
|
246
|
+
chunks.push(new AIMessageChunk({ content: [reasoningBlock(turn.reasoning, index)] }));
|
|
247
|
+
}
|
|
248
|
+
if (turn.text) {
|
|
249
|
+
if (turn.reasoning) {
|
|
250
|
+
const index = nextIndex++;
|
|
251
|
+
chunks.push(new AIMessageChunk({ content: [textBlock("", index)] }));
|
|
252
|
+
chunks.push(new AIMessageChunk({ content: [textBlock(turn.text, index)] }));
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
nextIndex++;
|
|
256
|
+
chunks.push(new AIMessageChunk({ content: turn.text }));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
for (const tc of turn.toolCalls ?? []) {
|
|
260
|
+
const index = nextIndex++;
|
|
261
|
+
chunks.push(new AIMessageChunk({
|
|
262
|
+
content: "",
|
|
263
|
+
tool_call_chunks: [{ type: "tool_call_chunk", id: tc.id, name: tc.name, args: JSON.stringify(tc.args), index }],
|
|
264
|
+
}));
|
|
61
265
|
}
|
|
266
|
+
if (turn.ends)
|
|
267
|
+
return chunks;
|
|
268
|
+
const usage = usageMetadataOf(turn.usage);
|
|
269
|
+
// The closing chunk: carries usage onto message-finish, and guarantees at
|
|
270
|
+
// least one chunk so an empty turn is still a message.
|
|
271
|
+
chunks.push(new AIMessageChunk({ content: "", ...(usage ? { usage_metadata: usage } : {}) }));
|
|
272
|
+
return chunks;
|
|
62
273
|
}
|
|
63
274
|
/**
|
|
64
275
|
* Read the pending approval interrupts from a graph state, exactly as the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripted-model.js","sourceRoot":"","sources":["../../../../src/activities/execute-deep-agent/__test-utils__/scripted-model.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"scripted-model.js","sourceRoot":"","sources":["../../../../src/activities/execute-deep-agent/__test-utils__/scripted-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAG5E,OAAO,EACL,cAAc,EACd,WAAW,EACX,eAAe,GAIhB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAmB,MAAM,yBAAyB,CAAC;AAgI/E;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,aAAa;IAC9C,SAAS,GAAa,EAAE,CAAC;IACzB;;;;;;OAMG;IACM,UAAU,CAAY;IACd,MAAM,CAAiB;IACvB,OAAO,CAAuB;IAE/C,YAAY,MAAsB,EAAE,aAA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ACzC,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS;gBAAE,SAAS;YAC7C,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAA4B,CAAC;YACxD,GAAG,CAAC,IAAI,CAAC;gBACP,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,WAAW,EAAG,IAAI,CAAC,EAAa,IAAI,IAAI,CAAC,EAAE;gBAC3C,UAAU,EAAG,CAAC,CAAC,YAAuB,IAAI,EAAE;gBAC5C,QAAQ,EAAG,CAAC,CAAC,SAAoB,IAAI,EAAE;gBACvC,OAAO,EAAG,CAAC,CAAC,OAAkB,IAAI,EAAE;gBACpC,YAAY,EAAG,CAAC,CAAC,aAAwB,IAAI,EAAE;aAChD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The native deep-agent harness as a `HarnessAdapter` — the worker- and
|
|
3
|
+
* session-lifetime half of its LangGraph slice, behind the turn runtime's
|
|
4
|
+
* contract (`harness/types.ts`). One engine turn is `turn.ts`'s
|
|
5
|
+
* `runDeepAgentTurn`; this module boots and delegates.
|
|
6
|
+
*
|
|
7
|
+
* What this adapter owns: the deepagents harness profiles (worker lifetime,
|
|
8
|
+
* registered once before the first `createDeepAgent`), and one engine turn
|
|
9
|
+
* (`runTurn`, through `turn.ts`). Everything else about a turn is the
|
|
10
|
+
* runtime's (`harness/run-turn.ts`).
|
|
11
|
+
*
|
|
12
|
+
* THIS MODULE'S STATIC GRAPH IS SDK-FREE, ON PURPOSE. The composition roots
|
|
13
|
+
* import the harness table (`src/harness-adapters.ts`) BEFORE they boot it,
|
|
14
|
+
* and that table's static graph must stay connect- and SDK-free (the Cursor
|
|
15
|
+
* adapter's boot patches `node:http2` before anything dials the control
|
|
16
|
+
* plane). So `deepagents` and `@langchain/*` — this harness's whole engine —
|
|
17
|
+
* are loaded with a dynamic import INSIDE `boot`, after the profiles are
|
|
18
|
+
* registered; a worker that does not serve this harness never pays for
|
|
19
|
+
* LangChain. `__tests__/adapter-graph-is-sdk-free.test.ts` pins it.
|
|
20
|
+
*
|
|
21
|
+
* Nothing is parked per session, and the header says so where the contract
|
|
22
|
+
* asks: the sqlite saver is opened and closed per turn and the MCP
|
|
23
|
+
* subprocesses are connected and closed per turn (`turn.ts`), so
|
|
24
|
+
* `shutdown` and `releaseSession` resolve as no-ops.
|
|
25
|
+
*
|
|
26
|
+
* What this adapter never does: throw out of `runTurn` (an engine failure is
|
|
27
|
+
* `failed` on the `internal` surface; the recursion limit is
|
|
28
|
+
* `tool_call_limit`; a `CancelledFailure` never exists here), branch on why
|
|
29
|
+
* `stopSignal` aborted, write a phase or a terminal copy, bind a state id
|
|
30
|
+
* (the thread id is the runtime's, `deterministic`), or import
|
|
31
|
+
* `@temporalio/*` (`__tests__/adapter-is-temporal-free.test.ts`).
|
|
32
|
+
*
|
|
33
|
+
* Extracted from `index.ts` `createDeepAgentActivities` at S3 M2a on the
|
|
34
|
+
* Cursor adapter's layout (`execute-cursor/adapter.ts`).
|
|
35
|
+
*/
|
|
36
|
+
import type { Config } from "../../config.js";
|
|
37
|
+
import type { HarnessAdapter } from "../../harness/types.js";
|
|
38
|
+
import type { DeepAgentAdapterConfig } from "./turn-setup.js";
|
|
39
|
+
/** The config slice this adapter reads per turn, taken at `boot`; a whole `Config` satisfies it. */
|
|
40
|
+
export declare function resolveDeepAgentConfig(config: Config): DeepAgentAdapterConfig;
|
|
41
|
+
export declare function createDeepAgentAdapter(): HarnessAdapter;
|