@bastani/atomic 0.9.16-alpha.2 → 0.9.16-alpha.4
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/CHANGELOG.md +14 -0
- package/dist/builtin/intercom/broker/spawn.ts +22 -2
- package/dist/builtin/intercom/index.bundle.mjs +61756 -0
- package/dist/builtin/intercom/package.json +3 -3
- package/dist/builtin/mcp/index.bundle.mjs +64963 -0
- package/dist/builtin/mcp/package.json +2 -2
- package/dist/builtin/subagents/package.json +2 -2
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +85733 -0
- package/dist/builtin/web-access/index.bundle.mjs +67475 -0
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/package.json +3 -3
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +76480 -96363
- package/dist/builtin/workflows/src/index.bundle.mjs +73306 -0
- package/dist/config-package-identity.d.ts +22 -0
- package/dist/config-package-identity.d.ts.map +1 -0
- package/dist/config-package-identity.js +73 -0
- package/dist/config-package-identity.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -10
- package/dist/config.js.map +1 -1
- package/dist/core/builtin-install-layout.d.ts +22 -0
- package/dist/core/builtin-install-layout.d.ts.map +1 -0
- package/dist/core/builtin-install-layout.js +23 -0
- package/dist/core/builtin-install-layout.js.map +1 -0
- package/dist/core/builtin-packages.d.ts.map +1 -1
- package/dist/core/builtin-packages.js +8 -32
- package/dist/core/builtin-packages.js.map +1 -1
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
- package/dist/builtin/intercom/closed-workflow-stage-message.ts +0 -66
- package/dist/builtin/intercom/config.ts +0 -121
- package/dist/builtin/intercom/contact-supervisor-tool.ts +0 -328
- package/dist/builtin/intercom/foreground-detach-handoff.ts +0 -164
- package/dist/builtin/intercom/group.ts +0 -85
- package/dist/builtin/intercom/inbound-idle-queue.ts +0 -82
- package/dist/builtin/intercom/inbound-message-admission.ts +0 -79
- package/dist/builtin/intercom/incoming-message-delivery.ts +0 -49
- package/dist/builtin/intercom/index-heavy.ts +0 -539
- package/dist/builtin/intercom/index.ts +0 -503
- package/dist/builtin/intercom/intercom-test-seams.ts +0 -6
- package/dist/builtin/intercom/intercom-tool.ts +0 -602
- package/dist/builtin/intercom/intercom-utils.ts +0 -427
- package/dist/builtin/intercom/late-stage-message-router.ts +0 -148
- package/dist/builtin/intercom/lazy-heavy-proxy.ts +0 -108
- package/dist/builtin/intercom/lazy-subagent-ack.ts +0 -25
- package/dist/builtin/intercom/lazy-tool-execution.ts +0 -39
- package/dist/builtin/intercom/lifecycle-lease.ts +0 -51
- package/dist/builtin/intercom/lifecycle.ts +0 -144
- package/dist/builtin/intercom/overlay.ts +0 -96
- package/dist/builtin/intercom/parent-ask-handoff.ts +0 -72
- package/dist/builtin/intercom/reconnect-backoff.ts +0 -6
- package/dist/builtin/intercom/reply-routing.ts +0 -17
- package/dist/builtin/intercom/reply-tracker.ts +0 -110
- package/dist/builtin/intercom/reply-waiter.ts +0 -115
- package/dist/builtin/intercom/result-renderers.ts +0 -77
- package/dist/builtin/intercom/runtime-group.ts +0 -13
- package/dist/builtin/intercom/session-target.ts +0 -54
- package/dist/builtin/intercom/source-ownership.ts +0 -31
- package/dist/builtin/intercom/stable-delivery-retry.ts +0 -32
- package/dist/builtin/intercom/subagent-relay.ts +0 -290
- package/dist/builtin/intercom/supervisor-authorization-registry.ts +0 -22
- package/dist/builtin/intercom/terminal-ordering-barrier.ts +0 -247
- package/dist/builtin/intercom/types.ts +0 -66
- package/dist/builtin/intercom/ui/compose.ts +0 -159
- package/dist/builtin/intercom/ui/inline-message.ts +0 -78
- package/dist/builtin/intercom/ui/session-list.ts +0 -195
- package/dist/builtin/intercom/workflow-reply-tracker.ts +0 -19
- package/dist/builtin/intercom/workflow-stage-admission.ts +0 -43
- package/dist/builtin/intercom/workflow-stage-delivery-failure.ts +0 -77
- package/dist/builtin/mcp/agent-dir.ts +0 -30
- package/dist/builtin/mcp/apps-cancellation.ts +0 -32
- package/dist/builtin/mcp/call-tool-result.ts +0 -9
- package/dist/builtin/mcp/caller-wait.ts +0 -50
- package/dist/builtin/mcp/cli.js +0 -191
- package/dist/builtin/mcp/command-registration.ts +0 -82
- package/dist/builtin/mcp/commands.ts +0 -424
- package/dist/builtin/mcp/config-write-utils.ts +0 -104
- package/dist/builtin/mcp/config.ts +0 -498
- package/dist/builtin/mcp/consent-manager.ts +0 -64
- package/dist/builtin/mcp/direct-tool-executor.ts +0 -280
- package/dist/builtin/mcp/direct-tools.ts +0 -216
- package/dist/builtin/mcp/errors.ts +0 -219
- package/dist/builtin/mcp/glimpse-ui.ts +0 -81
- package/dist/builtin/mcp/host-html-template.ts +0 -426
- package/dist/builtin/mcp/index.ts +0 -443
- package/dist/builtin/mcp/init.ts +0 -319
- package/dist/builtin/mcp/lifecycle.ts +0 -93
- package/dist/builtin/mcp/logger.ts +0 -169
- package/dist/builtin/mcp/mcp-auth-flow.ts +0 -372
- package/dist/builtin/mcp/mcp-auth.ts +0 -297
- package/dist/builtin/mcp/mcp-callback-server.ts +0 -306
- package/dist/builtin/mcp/mcp-oauth-provider.ts +0 -324
- package/dist/builtin/mcp/mcp-panel-renderer.ts +0 -243
- package/dist/builtin/mcp/mcp-panel-state.ts +0 -227
- package/dist/builtin/mcp/mcp-panel-types.ts +0 -86
- package/dist/builtin/mcp/mcp-panel.ts +0 -393
- package/dist/builtin/mcp/mcp-setup-panel.ts +0 -502
- package/dist/builtin/mcp/metadata-cache.ts +0 -201
- package/dist/builtin/mcp/metadata-hydration.ts +0 -52
- package/dist/builtin/mcp/npx-resolver.ts +0 -425
- package/dist/builtin/mcp/oauth-handler.ts +0 -60
- package/dist/builtin/mcp/onboarding-state.ts +0 -68
- package/dist/builtin/mcp/proxy-auth.ts +0 -61
- package/dist/builtin/mcp/proxy-call.ts +0 -447
- package/dist/builtin/mcp/proxy-connect.ts +0 -78
- package/dist/builtin/mcp/proxy-info-modes.ts +0 -409
- package/dist/builtin/mcp/proxy-modes.ts +0 -3
- package/dist/builtin/mcp/proxy-types.ts +0 -3
- package/dist/builtin/mcp/resource-tools.ts +0 -17
- package/dist/builtin/mcp/sampling-handler.ts +0 -273
- package/dist/builtin/mcp/server-manager.ts +0 -372
- package/dist/builtin/mcp/session-cleanup-barrier.ts +0 -43
- package/dist/builtin/mcp/startup-warmup.ts +0 -110
- package/dist/builtin/mcp/state-lease.ts +0 -12
- package/dist/builtin/mcp/state.ts +0 -41
- package/dist/builtin/mcp/tool-call-timeout.ts +0 -101
- package/dist/builtin/mcp/tool-metadata.ts +0 -152
- package/dist/builtin/mcp/tool-registrar.ts +0 -46
- package/dist/builtin/mcp/tool-result-renderer.ts +0 -66
- package/dist/builtin/mcp/types.ts +0 -445
- package/dist/builtin/mcp/ui-resource-handler.ts +0 -145
- package/dist/builtin/mcp/ui-server-http.ts +0 -81
- package/dist/builtin/mcp/ui-server.ts +0 -499
- package/dist/builtin/mcp/ui-session.ts +0 -378
- package/dist/builtin/mcp/ui-stream-types.ts +0 -89
- package/dist/builtin/mcp/utils.ts +0 -165
- package/dist/builtin/subagents/src/agents/agent-discovery.ts +0 -116
- package/dist/builtin/subagents/src/agents/agent-loaders.ts +0 -216
- package/dist/builtin/subagents/src/agents/agent-management-helpers.ts +0 -221
- package/dist/builtin/subagents/src/agents/agent-management.ts +0 -315
- package/dist/builtin/subagents/src/agents/agent-overrides.ts +0 -450
- package/dist/builtin/subagents/src/agents/agent-paths.ts +0 -69
- package/dist/builtin/subagents/src/agents/agent-scope.ts +0 -6
- package/dist/builtin/subagents/src/agents/agent-selection.ts +0 -23
- package/dist/builtin/subagents/src/agents/agent-serializer.ts +0 -113
- package/dist/builtin/subagents/src/agents/agent-types.ts +0 -97
- package/dist/builtin/subagents/src/agents/agents.ts +0 -25
- package/dist/builtin/subagents/src/agents/frontmatter.ts +0 -74
- package/dist/builtin/subagents/src/agents/identity.ts +0 -37
- package/dist/builtin/subagents/src/agents/skills-paths.ts +0 -380
- package/dist/builtin/subagents/src/agents/skills.ts +0 -398
- package/dist/builtin/subagents/src/extension/api-lifecycle.ts +0 -64
- package/dist/builtin/subagents/src/extension/config.ts +0 -16
- package/dist/builtin/subagents/src/extension/control-notices.ts +0 -91
- package/dist/builtin/subagents/src/extension/index.ts +0 -420
- package/dist/builtin/subagents/src/extension/notification-content.ts +0 -85
- package/dist/builtin/subagents/src/extension/prompt-guidance.ts +0 -11
- package/dist/builtin/subagents/src/extension/schemas.ts +0 -208
- package/dist/builtin/subagents/src/extension/startup-maintenance.ts +0 -133
- package/dist/builtin/subagents/src/extension/tool-description.ts +0 -17
- package/dist/builtin/subagents/src/extension/tool-rendering.ts +0 -53
- package/dist/builtin/subagents/src/intercom/intercom-bridge.ts +0 -376
- package/dist/builtin/subagents/src/intercom/result-intercom.ts +0 -246
- package/dist/builtin/subagents/src/intercom/supervisor-authorization.ts +0 -30
- package/dist/builtin/subagents/src/runs/foreground/completion-notification.ts +0 -42
- package/dist/builtin/subagents/src/runs/foreground/detached-cleanup-barrier.ts +0 -26
- package/dist/builtin/subagents/src/runs/foreground/execution-detach-reservations.ts +0 -58
- package/dist/builtin/subagents/src/runs/foreground/execution-detach-route.ts +0 -19
- package/dist/builtin/subagents/src/runs/foreground/execution-intercom-detach.ts +0 -51
- package/dist/builtin/subagents/src/runs/foreground/execution-parent-ask-handoff.ts +0 -78
- package/dist/builtin/subagents/src/runs/foreground/execution-run-sync.ts +0 -1
- package/dist/builtin/subagents/src/runs/foreground/execution-updates.ts +0 -26
- package/dist/builtin/subagents/src/runs/foreground/execution-utils.ts +0 -61
- package/dist/builtin/subagents/src/runs/foreground/execution.ts +0 -6
- package/dist/builtin/subagents/src/runs/foreground/inprocess-run-sync.ts +0 -512
- package/dist/builtin/subagents/src/runs/foreground/notify.ts +0 -355
- package/dist/builtin/subagents/src/runs/foreground/parent-ask-output.ts +0 -48
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-burst-display.ts +0 -46
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-burst.ts +0 -403
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-context.ts +0 -223
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-cwd.ts +0 -6
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-input.ts +0 -139
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-live-update.ts +0 -11
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel-task.ts +0 -268
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel.ts +0 -327
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parent-ask-projection.ts +0 -11
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-runtime.ts +0 -12
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +0 -350
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-status.ts +0 -246
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-types.ts +0 -131
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-worktree.ts +0 -102
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +0 -217
- package/dist/builtin/subagents/src/runs/inprocess/child-policy.ts +0 -27
- package/dist/builtin/subagents/src/runs/inprocess/control-registry.ts +0 -55
- package/dist/builtin/subagents/src/runs/inprocess/control-status.ts +0 -72
- package/dist/builtin/subagents/src/runs/inprocess/index.ts +0 -27
- package/dist/builtin/subagents/src/runs/inprocess/prompt-behavior.ts +0 -168
- package/dist/builtin/subagents/src/runs/inprocess/runner.ts +0 -1280
- package/dist/builtin/subagents/src/runs/inprocess/runtime-support/temp-cleanup.ts +0 -69
- package/dist/builtin/subagents/src/runs/inprocess.ts +0 -1
- package/dist/builtin/subagents/src/runs/shared/intercom-group.ts +0 -67
- package/dist/builtin/subagents/src/runs/shared/long-running-guard.ts +0 -182
- package/dist/builtin/subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -391
- package/dist/builtin/subagents/src/runs/shared/model-candidate-filter.ts +0 -56
- package/dist/builtin/subagents/src/runs/shared/model-fallback.ts +0 -88
- package/dist/builtin/subagents/src/runs/shared/parallel-utils.ts +0 -70
- package/dist/builtin/subagents/src/runs/shared/progress-trend.ts +0 -69
- package/dist/builtin/subagents/src/runs/shared/run-history.ts +0 -64
- package/dist/builtin/subagents/src/runs/shared/single-output.ts +0 -169
- package/dist/builtin/subagents/src/runs/shared/subagent-control.ts +0 -234
- package/dist/builtin/subagents/src/runs/shared/worktree-post-create.ts +0 -111
- package/dist/builtin/subagents/src/runs/shared/worktree-root.ts +0 -67
- package/dist/builtin/subagents/src/runs/shared/worktree.ts +0 -552
- package/dist/builtin/subagents/src/shared/artifacts.ts +0 -240
- package/dist/builtin/subagents/src/shared/atomic-json.ts +0 -16
- package/dist/builtin/subagents/src/shared/event-jsonl-writer.ts +0 -330
- package/dist/builtin/subagents/src/shared/exclusive-file-publication.ts +0 -44
- package/dist/builtin/subagents/src/shared/fast-mode.ts +0 -87
- package/dist/builtin/subagents/src/shared/file-coalescer.ts +0 -40
- package/dist/builtin/subagents/src/shared/fork-context.ts +0 -79
- package/dist/builtin/subagents/src/shared/formatters.ts +0 -89
- package/dist/builtin/subagents/src/shared/jsonl-writer.ts +0 -83
- package/dist/builtin/subagents/src/shared/model-info.ts +0 -101
- package/dist/builtin/subagents/src/shared/model-resolution.ts +0 -78
- package/dist/builtin/subagents/src/shared/session-identity.ts +0 -10
- package/dist/builtin/subagents/src/shared/session-tokens.ts +0 -45
- package/dist/builtin/subagents/src/shared/settings.ts +0 -118
- package/dist/builtin/subagents/src/shared/status-format.ts +0 -50
- package/dist/builtin/subagents/src/shared/types-config.ts +0 -206
- package/dist/builtin/subagents/src/shared/types-depth.ts +0 -46
- package/dist/builtin/subagents/src/shared/types-foreground-state.ts +0 -48
- package/dist/builtin/subagents/src/shared/types-output.ts +0 -63
- package/dist/builtin/subagents/src/shared/types-results.ts +0 -259
- package/dist/builtin/subagents/src/shared/types-runtime.ts +0 -115
- package/dist/builtin/subagents/src/shared/types.ts +0 -13
- package/dist/builtin/subagents/src/shared/utils.ts +0 -342
- package/dist/builtin/subagents/src/slash/bridge-settlement.ts +0 -87
- package/dist/builtin/subagents/src/slash/prompt-template-bridge.ts +0 -455
- package/dist/builtin/subagents/src/slash/slash-bridge.ts +0 -194
- package/dist/builtin/subagents/src/slash/slash-commands.ts +0 -5
- package/dist/builtin/subagents/src/slash/slash-live-state.ts +0 -259
- package/dist/builtin/subagents/src/tui/render-event-formatting.ts +0 -7
- package/dist/builtin/subagents/src/tui/render-helpers.ts +0 -90
- package/dist/builtin/subagents/src/tui/render-layout.ts +0 -157
- package/dist/builtin/subagents/src/tui/render-progress.ts +0 -89
- package/dist/builtin/subagents/src/tui/render-result-animation.ts +0 -47
- package/dist/builtin/subagents/src/tui/render-result-compact.ts +0 -248
- package/dist/builtin/subagents/src/tui/render-result.ts +0 -438
- package/dist/builtin/subagents/src/tui/render-stable-output.ts +0 -50
- package/dist/builtin/subagents/src/tui/render-status-progress.ts +0 -168
- package/dist/builtin/subagents/src/tui/render.ts +0 -23
- package/dist/builtin/web-access/activity.ts +0 -101
- package/dist/builtin/web-access/chrome-cookies.ts +0 -323
- package/dist/builtin/web-access/code-search.ts +0 -107
- package/dist/builtin/web-access/config-paths.ts +0 -11
- package/dist/builtin/web-access/content-tools.ts +0 -354
- package/dist/builtin/web-access/curator-page-assets/script-1.ts +0 -400
- package/dist/builtin/web-access/curator-page-assets/script-2.ts +0 -400
- package/dist/builtin/web-access/curator-page-assets/script-3.ts +0 -400
- package/dist/builtin/web-access/curator-page-assets/script-4.ts +0 -400
- package/dist/builtin/web-access/curator-page-assets/script-5.ts +0 -398
- package/dist/builtin/web-access/curator-page-assets/styles-1.ts +0 -394
- package/dist/builtin/web-access/curator-page-assets/styles-2.ts +0 -394
- package/dist/builtin/web-access/curator-page-assets/styles-3.ts +0 -393
- package/dist/builtin/web-access/curator-page.ts +0 -196
- package/dist/builtin/web-access/curator-server-helpers.ts +0 -115
- package/dist/builtin/web-access/curator-server.ts +0 -494
- package/dist/builtin/web-access/exa-mcp.ts +0 -218
- package/dist/builtin/web-access/exa.ts +0 -317
- package/dist/builtin/web-access/extract-frames.ts +0 -229
- package/dist/builtin/web-access/extract.ts +0 -500
- package/dist/builtin/web-access/flat-string.ts +0 -37
- package/dist/builtin/web-access/gemini-api.ts +0 -111
- package/dist/builtin/web-access/gemini-search.ts +0 -363
- package/dist/builtin/web-access/gemini-url-context.ts +0 -126
- package/dist/builtin/web-access/gemini-web-config.ts +0 -53
- package/dist/builtin/web-access/gemini-web.ts +0 -397
- package/dist/builtin/web-access/github-api.ts +0 -198
- package/dist/builtin/web-access/github-config.ts +0 -156
- package/dist/builtin/web-access/github-extract.ts +0 -487
- package/dist/builtin/web-access/index-heavy.ts +0 -164
- package/dist/builtin/web-access/index.ts +0 -401
- package/dist/builtin/web-access/lifecycle-lease.ts +0 -38
- package/dist/builtin/web-access/pdf-extract.ts +0 -192
- package/dist/builtin/web-access/perplexity.ts +0 -194
- package/dist/builtin/web-access/result-renderers.ts +0 -366
- package/dist/builtin/web-access/rsc-extract.ts +0 -338
- package/dist/builtin/web-access/storage.ts +0 -72
- package/dist/builtin/web-access/subprocess.ts +0 -102
- package/dist/builtin/web-access/summary-review.ts +0 -287
- package/dist/builtin/web-access/utils.ts +0 -44
- package/dist/builtin/web-access/video-extract.ts +0 -375
- package/dist/builtin/web-access/web-search-activity.ts +0 -102
- package/dist/builtin/web-access/web-search-browser.ts +0 -124
- package/dist/builtin/web-access/web-search-command.ts +0 -242
- package/dist/builtin/web-access/web-search-config.ts +0 -157
- package/dist/builtin/web-access/web-search-curator.ts +0 -214
- package/dist/builtin/web-access/web-search-features.ts +0 -181
- package/dist/builtin/web-access/web-search-formatting.ts +0 -117
- package/dist/builtin/web-access/web-search-return.ts +0 -143
- package/dist/builtin/web-access/web-search-summary.ts +0 -177
- package/dist/builtin/web-access/web-search-tool.ts +0 -286
- package/dist/builtin/web-access/web-search-types.ts +0 -50
- package/dist/builtin/web-access/web-search-workflow.ts +0 -10
- package/dist/builtin/web-access/youtube-extract.ts +0 -309
- package/dist/builtin/workflows/src/authoring/keep-context.ts +0 -46
- package/dist/builtin/workflows/src/authoring/typebox-defaults.d.ts +0 -41
- package/dist/builtin/workflows/src/authoring/typebox-defaults.ts +0 -180
- package/dist/builtin/workflows/src/authoring/workflow.ts +0 -206
- package/dist/builtin/workflows/src/durable/backend.ts +0 -598
- package/dist/builtin/workflows/src/durable/boundary-lifecycle.ts +0 -172
- package/dist/builtin/workflows/src/durable/boundary-topology.ts +0 -475
- package/dist/builtin/workflows/src/durable/child-invocation.ts +0 -14
- package/dist/builtin/workflows/src/durable/child-primitive.ts +0 -124
- package/dist/builtin/workflows/src/durable/completed-catalog-stage-groups.ts +0 -385
- package/dist/builtin/workflows/src/durable/completed-catalog.ts +0 -685
- package/dist/builtin/workflows/src/durable/completed-inspection.ts +0 -157
- package/dist/builtin/workflows/src/durable/completed-subtree.ts +0 -50
- package/dist/builtin/workflows/src/durable/dbos-backend.ts +0 -580
- package/dist/builtin/workflows/src/durable/dbos-embedded-postgres-root.ts +0 -681
- package/dist/builtin/workflows/src/durable/dbos-embedded-postgres.ts +0 -717
- package/dist/builtin/workflows/src/durable/dbos-envelope.ts +0 -516
- package/dist/builtin/workflows/src/durable/dbos-lifecycle.ts +0 -208
- package/dist/builtin/workflows/src/durable/dbos-local-postgres.ts +0 -166
- package/dist/builtin/workflows/src/durable/dbos-metadata.ts +0 -196
- package/dist/builtin/workflows/src/durable/dbos-process-owner.ts +0 -87
- package/dist/builtin/workflows/src/durable/dbos-prompt-reservations.ts +0 -377
- package/dist/builtin/workflows/src/durable/dbos-registration-diagnostics.ts +0 -113
- package/dist/builtin/workflows/src/durable/dbos-sdk-handle.ts +0 -182
- package/dist/builtin/workflows/src/durable/dbos-status-transition.ts +0 -67
- package/dist/builtin/workflows/src/durable/dbos-tombstone.ts +0 -27
- package/dist/builtin/workflows/src/durable/durable-hash.ts +0 -18
- package/dist/builtin/workflows/src/durable/factory.ts +0 -93
- package/dist/builtin/workflows/src/durable/format-version.ts +0 -6
- package/dist/builtin/workflows/src/durable/index.ts +0 -82
- package/dist/builtin/workflows/src/durable/local-command.ts +0 -135
- package/dist/builtin/workflows/src/durable/prompt-reservation-state.ts +0 -184
- package/dist/builtin/workflows/src/durable/prompt-reservations.ts +0 -36
- package/dist/builtin/workflows/src/durable/resume-catalog.ts +0 -20
- package/dist/builtin/workflows/src/durable/resume-eligibility.ts +0 -106
- package/dist/builtin/workflows/src/durable/resume-runtime.ts +0 -344
- package/dist/builtin/workflows/src/durable/retention-policy.ts +0 -43
- package/dist/builtin/workflows/src/durable/run-timing.ts +0 -151
- package/dist/builtin/workflows/src/durable/scoped-backend.ts +0 -308
- package/dist/builtin/workflows/src/durable/stage-primitive.ts +0 -553
- package/dist/builtin/workflows/src/durable/stage-topology-validation.ts +0 -247
- package/dist/builtin/workflows/src/durable/stage-topology.ts +0 -53
- package/dist/builtin/workflows/src/durable/targeted-inspection.ts +0 -110
- package/dist/builtin/workflows/src/durable/tool-failure-checkpoint.ts +0 -54
- package/dist/builtin/workflows/src/durable/tool-outcome.ts +0 -130
- package/dist/builtin/workflows/src/durable/tool-primitive.ts +0 -861
- package/dist/builtin/workflows/src/durable/types.ts +0 -343
- package/dist/builtin/workflows/src/durable/ui-primitive.ts +0 -263
- package/dist/builtin/workflows/src/durable/workflow-child-result.ts +0 -63
- package/dist/builtin/workflows/src/durable/workflow-heartbeat-anchor.ts +0 -153
- package/dist/builtin/workflows/src/durable/workflow-status-transition.ts +0 -31
- package/dist/builtin/workflows/src/engine/graph-inference.ts +0 -100
- package/dist/builtin/workflows/src/engine/options.ts +0 -44
- package/dist/builtin/workflows/src/engine/primitives/chain.ts +0 -34
- package/dist/builtin/workflows/src/engine/primitives/exit.ts +0 -2
- package/dist/builtin/workflows/src/engine/primitives/parallel.ts +0 -74
- package/dist/builtin/workflows/src/engine/primitives/task.ts +0 -127
- package/dist/builtin/workflows/src/engine/primitives/ui.ts +0 -54
- package/dist/builtin/workflows/src/engine/primitives/workflow.ts +0 -219
- package/dist/builtin/workflows/src/engine/replay.ts +0 -8
- package/dist/builtin/workflows/src/engine/run-budget.ts +0 -308
- package/dist/builtin/workflows/src/engine/run-durable-admission.ts +0 -50
- package/dist/builtin/workflows/src/engine/run-durable-finalize.ts +0 -97
- package/dist/builtin/workflows/src/engine/run-durable-stage-session.ts +0 -65
- package/dist/builtin/workflows/src/engine/run-durable-topology.ts +0 -295
- package/dist/builtin/workflows/src/engine/run-returned-status.ts +0 -86
- package/dist/builtin/workflows/src/engine/run-terminal-event.ts +0 -39
- package/dist/builtin/workflows/src/engine/run-terminal-failure.ts +0 -53
- package/dist/builtin/workflows/src/engine/run-tool-admission-boundary.ts +0 -99
- package/dist/builtin/workflows/src/engine/run-tool-control-registry.ts +0 -187
- package/dist/builtin/workflows/src/engine/run-tool-execution-tracker.ts +0 -164
- package/dist/builtin/workflows/src/engine/run-tool-node-lifecycle.ts +0 -158
- package/dist/builtin/workflows/src/engine/run.ts +0 -841
- package/dist/builtin/workflows/src/engine/runtime.ts +0 -220
- package/dist/builtin/workflows/src/engine/workflow-activity.ts +0 -13
- package/dist/builtin/workflows/src/engine/workflow-tool-abort.ts +0 -92
- package/dist/builtin/workflows/src/extension/adopt-session-run-state.ts +0 -20
- package/dist/builtin/workflows/src/extension/atomic-stage-session.ts +0 -168
- package/dist/builtin/workflows/src/extension/background-ui-adapter.ts +0 -154
- package/dist/builtin/workflows/src/extension/companions.ts +0 -210
- package/dist/builtin/workflows/src/extension/completed-stage-intercom-ask.ts +0 -167
- package/dist/builtin/workflows/src/extension/config-file-loader.ts +0 -185
- package/dist/builtin/workflows/src/extension/config-loader.ts +0 -439
- package/dist/builtin/workflows/src/extension/discovery-loaders.ts +0 -112
- package/dist/builtin/workflows/src/extension/discovery.ts +0 -424
- package/dist/builtin/workflows/src/extension/dispatcher.ts +0 -273
- package/dist/builtin/workflows/src/extension/extension-factory.ts +0 -133
- package/dist/builtin/workflows/src/extension/extension-lifecycle.ts +0 -174
- package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +0 -596
- package/dist/builtin/workflows/src/extension/hil-answer-notifications.ts +0 -367
- package/dist/builtin/workflows/src/extension/index.ts +0 -42
- package/dist/builtin/workflows/src/extension/lifecycle-notification-delivery.ts +0 -83
- package/dist/builtin/workflows/src/extension/lifecycle-notifications.ts +0 -849
- package/dist/builtin/workflows/src/extension/mcp.ts +0 -121
- package/dist/builtin/workflows/src/extension/postmortem-deps.ts +0 -70
- package/dist/builtin/workflows/src/extension/public-types.ts +0 -234
- package/dist/builtin/workflows/src/extension/render-call.ts +0 -115
- package/dist/builtin/workflows/src/extension/render-component.ts +0 -12
- package/dist/builtin/workflows/src/extension/render-result.ts +0 -558
- package/dist/builtin/workflows/src/extension/renderers.ts +0 -89
- package/dist/builtin/workflows/src/extension/runtime-active-block-claim.ts +0 -78
- package/dist/builtin/workflows/src/extension/runtime-durable-resume.ts +0 -174
- package/dist/builtin/workflows/src/extension/runtime.ts +0 -439
- package/dist/builtin/workflows/src/extension/status-writer.ts +0 -182
- package/dist/builtin/workflows/src/extension/ui-surface.ts +0 -387
- package/dist/builtin/workflows/src/extension/wiring.ts +0 -490
- package/dist/builtin/workflows/src/extension/workflow-command-completions.ts +0 -129
- package/dist/builtin/workflows/src/extension/workflow-command-registration.ts +0 -296
- package/dist/builtin/workflows/src/extension/workflow-command-surfaces.ts +0 -114
- package/dist/builtin/workflows/src/extension/workflow-command-utils.ts +0 -175
- package/dist/builtin/workflows/src/extension/workflow-durable-resume-command.ts +0 -270
- package/dist/builtin/workflows/src/extension/workflow-heartbeat-delivery.ts +0 -241
- package/dist/builtin/workflows/src/extension/workflow-heartbeat-notice.ts +0 -115
- package/dist/builtin/workflows/src/extension/workflow-heartbeat-scheduler.ts +0 -962
- package/dist/builtin/workflows/src/extension/workflow-model-catalog.ts +0 -24
- package/dist/builtin/workflows/src/extension/workflow-module-loader.ts +0 -162
- package/dist/builtin/workflows/src/extension/workflow-policy.ts +0 -13
- package/dist/builtin/workflows/src/extension/workflow-ports.ts +0 -45
- package/dist/builtin/workflows/src/extension/workflow-prompts.ts +0 -73
- package/dist/builtin/workflows/src/extension/workflow-reload-coordinator.ts +0 -66
- package/dist/builtin/workflows/src/extension/workflow-reload-report.ts +0 -42
- package/dist/builtin/workflows/src/extension/workflow-request-abort.ts +0 -15
- package/dist/builtin/workflows/src/extension/workflow-resume-picker-rows.ts +0 -96
- package/dist/builtin/workflows/src/extension/workflow-resume-shadow.ts +0 -53
- package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +0 -562
- package/dist/builtin/workflows/src/extension/workflow-schema.ts +0 -192
- package/dist/builtin/workflows/src/extension/workflow-stage-results.ts +0 -252
- package/dist/builtin/workflows/src/extension/workflow-status-summary.ts +0 -276
- package/dist/builtin/workflows/src/extension/workflow-targets.ts +0 -210
- package/dist/builtin/workflows/src/extension/workflow-tool-content.ts +0 -265
- package/dist/builtin/workflows/src/extension/workflow-tool-control.ts +0 -547
- package/dist/builtin/workflows/src/extension/workflow-tool-inspection.ts +0 -153
- package/dist/builtin/workflows/src/extension/workflow-tool-registration.ts +0 -145
- package/dist/builtin/workflows/src/extension/workflow-tool-send.ts +0 -488
- package/dist/builtin/workflows/src/extension/workflow-tool.ts +0 -188
- package/dist/builtin/workflows/src/index.ts +0 -8
- package/dist/builtin/workflows/src/intercom/intercom-bridge.ts +0 -90
- package/dist/builtin/workflows/src/intercom/intercom-routing.ts +0 -131
- package/dist/builtin/workflows/src/intercom/result-intercom.ts +0 -271
- package/dist/builtin/workflows/src/runs/background/cancellation-registry.ts +0 -135
- package/dist/builtin/workflows/src/runs/background/durable-resume-transition.ts +0 -63
- package/dist/builtin/workflows/src/runs/background/job-tracker.ts +0 -125
- package/dist/builtin/workflows/src/runs/background/quit-tool-node.ts +0 -71
- package/dist/builtin/workflows/src/runs/background/quit.ts +0 -417
- package/dist/builtin/workflows/src/runs/background/resume-acknowledgements.ts +0 -99
- package/dist/builtin/workflows/src/runs/background/run-inspect.ts +0 -126
- package/dist/builtin/workflows/src/runs/background/runner.ts +0 -185
- package/dist/builtin/workflows/src/runs/background/startup-admission.ts +0 -73
- package/dist/builtin/workflows/src/runs/background/status.ts +0 -511
- package/dist/builtin/workflows/src/runs/background/workflow-lifecycle-aggregate.ts +0 -43
- package/dist/builtin/workflows/src/runs/foreground/executor-abort.ts +0 -441
- package/dist/builtin/workflows/src/runs/foreground/executor-child-boundary.ts +0 -263
- package/dist/builtin/workflows/src/runs/foreground/executor-child-helpers.ts +0 -79
- package/dist/builtin/workflows/src/runs/foreground/executor-child-workflow.ts +0 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-continuation.ts +0 -207
- package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +0 -321
- package/dist/builtin/workflows/src/runs/foreground/executor-exit-manager.ts +0 -224
- package/dist/builtin/workflows/src/runs/foreground/executor-hil.ts +0 -403
- package/dist/builtin/workflows/src/runs/foreground/executor-inputs.ts +0 -86
- package/dist/builtin/workflows/src/runs/foreground/executor-lifecycle.ts +0 -491
- package/dist/builtin/workflows/src/runs/foreground/executor-outputs.ts +0 -156
- package/dist/builtin/workflows/src/runs/foreground/executor-prompt-nodes.ts +0 -379
- package/dist/builtin/workflows/src/runs/foreground/executor-queued-user-message.ts +0 -75
- package/dist/builtin/workflows/src/runs/foreground/executor-run-finalizers.ts +0 -144
- package/dist/builtin/workflows/src/runs/foreground/executor-run.ts +0 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-scheduler.ts +0 -206
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +0 -434
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-context.ts +0 -153
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-control.ts +0 -225
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-factory.ts +0 -473
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts +0 -156
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-types.ts +0 -72
- package/dist/builtin/workflows/src/runs/foreground/executor-task-context.ts +0 -2
- package/dist/builtin/workflows/src/runs/foreground/executor-task-prompts.ts +0 -226
- package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +0 -186
- package/dist/builtin/workflows/src/runs/foreground/executor.ts +0 -25
- package/dist/builtin/workflows/src/runs/foreground/postmortem-stage-chat.ts +0 -245
- package/dist/builtin/workflows/src/runs/foreground/stage-control-registry.ts +0 -466
- package/dist/builtin/workflows/src/runs/foreground/stage-delivery-activity.ts +0 -86
- package/dist/builtin/workflows/src/runs/foreground/stage-queued-user-messages.ts +0 -95
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-candidate.ts +0 -21
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-context.ts +0 -330
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +0 -1472
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-message-admission.ts +0 -196
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-messages.ts +0 -177
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts +0 -97
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-output.ts +0 -278
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-pause.ts +0 -206
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-replacement.ts +0 -41
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-send-user-message.ts +0 -134
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-session-options.ts +0 -38
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-session.ts +0 -66
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-structured-output.ts +0 -120
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-types.ts +0 -211
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-unresolved-overflow.ts +0 -42
- package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +0 -22
- package/dist/builtin/workflows/src/runs/foreground/stage-session-heartbeat.ts +0 -88
- package/dist/builtin/workflows/src/runs/foreground/stage-tool-execution-buffer.ts +0 -49
- package/dist/builtin/workflows/src/runs/shared/concurrency.ts +0 -76
- package/dist/builtin/workflows/src/runs/shared/graph-inference.ts +0 -2
- package/dist/builtin/workflows/src/runs/shared/model-fallback-candidates.ts +0 -325
- package/dist/builtin/workflows/src/runs/shared/model-fallback-failures.ts +0 -19
- package/dist/builtin/workflows/src/runs/shared/model-fallback.ts +0 -2
- package/dist/builtin/workflows/src/runs/shared/prompt-callsite.ts +0 -96
- package/dist/builtin/workflows/src/runs/shared/retry.ts +0 -44
- package/dist/builtin/workflows/src/runs/shared/validate-inputs.ts +0 -111
- package/dist/builtin/workflows/src/runs/shared/worktree-cache-lifecycle.ts +0 -23
- package/dist/builtin/workflows/src/runs/shared/worktree-cwd.ts +0 -116
- package/dist/builtin/workflows/src/runs/shared/worktree-diff.ts +0 -172
- package/dist/builtin/workflows/src/runs/shared/worktree-generation.ts +0 -57
- package/dist/builtin/workflows/src/runs/shared/worktree-git-runner.ts +0 -107
- package/dist/builtin/workflows/src/runs/shared/worktree-git.ts +0 -407
- package/dist/builtin/workflows/src/runs/shared/worktree-post-create.ts +0 -137
- package/dist/builtin/workflows/src/runs/shared/worktree-root.ts +0 -84
- package/dist/builtin/workflows/src/runs/shared/worktree-setup.ts +0 -372
- package/dist/builtin/workflows/src/runs/shared/worktree-types.ts +0 -102
- package/dist/builtin/workflows/src/runs/shared/worktree.ts +0 -21
- package/dist/builtin/workflows/src/sdk-surface.ts +0 -70
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +0 -403
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.ts +0 -489
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +0 -327
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +0 -437
- package/dist/builtin/workflows/src/shared/budget-meter.ts +0 -34
- package/dist/builtin/workflows/src/shared/budget.d.ts +0 -67
- package/dist/builtin/workflows/src/shared/budget.ts +0 -127
- package/dist/builtin/workflows/src/shared/expanded-workflow-graph.ts +0 -434
- package/dist/builtin/workflows/src/shared/flat-string.ts +0 -33
- package/dist/builtin/workflows/src/shared/graph-store-snapshot.ts +0 -188
- package/dist/builtin/workflows/src/shared/intercom-group.ts +0 -58
- package/dist/builtin/workflows/src/shared/persistence-compaction-policy.ts +0 -72
- package/dist/builtin/workflows/src/shared/persistence-restore-helpers.ts +0 -613
- package/dist/builtin/workflows/src/shared/persistence-restore.ts +0 -306
- package/dist/builtin/workflows/src/shared/persistence-session-entries.ts +0 -303
- package/dist/builtin/workflows/src/shared/prompt-answer.ts +0 -130
- package/dist/builtin/workflows/src/shared/prompt-callsite-context.ts +0 -13
- package/dist/builtin/workflows/src/shared/render-inputs-schema.ts +0 -161
- package/dist/builtin/workflows/src/shared/resume-continuation.ts +0 -2
- package/dist/builtin/workflows/src/shared/returned-run-status.ts +0 -164
- package/dist/builtin/workflows/src/shared/run-id.ts +0 -36
- package/dist/builtin/workflows/src/shared/run-indicator-status.ts +0 -75
- package/dist/builtin/workflows/src/shared/run-visibility.ts +0 -9
- package/dist/builtin/workflows/src/shared/schema-introspection.ts +0 -111
- package/dist/builtin/workflows/src/shared/serializable.ts +0 -118
- package/dist/builtin/workflows/src/shared/session-scoped-singleton.ts +0 -98
- package/dist/builtin/workflows/src/shared/session-transcript.ts +0 -79
- package/dist/builtin/workflows/src/shared/stage-prompt.ts +0 -338
- package/dist/builtin/workflows/src/shared/stage-ui-broker.ts +0 -340
- package/dist/builtin/workflows/src/shared/store-factory.ts +0 -26
- package/dist/builtin/workflows/src/shared/store-internal.ts +0 -252
- package/dist/builtin/workflows/src/shared/store-observation.ts +0 -10
- package/dist/builtin/workflows/src/shared/store-prompt-methods.ts +0 -215
- package/dist/builtin/workflows/src/shared/store-public-types.ts +0 -282
- package/dist/builtin/workflows/src/shared/store-run-methods.ts +0 -305
- package/dist/builtin/workflows/src/shared/store-stage-methods.ts +0 -331
- package/dist/builtin/workflows/src/shared/store-tool-node-methods.ts +0 -60
- package/dist/builtin/workflows/src/shared/store-types.ts +0 -439
- package/dist/builtin/workflows/src/shared/store.ts +0 -15
- package/dist/builtin/workflows/src/shared/timing.ts +0 -71
- package/dist/builtin/workflows/src/shared/tool-payload-bounds.ts +0 -576
- package/dist/builtin/workflows/src/shared/types.ts +0 -523
- package/dist/builtin/workflows/src/shared/workflow-artifact-env.ts +0 -21
- package/dist/builtin/workflows/src/shared/workflow-artifacts.ts +0 -259
- package/dist/builtin/workflows/src/shared/workflow-authoring-types.d.ts +0 -60
- package/dist/builtin/workflows/src/shared/workflow-authoring-types.ts +0 -111
- package/dist/builtin/workflows/src/shared/workflow-failures-classifier.ts +0 -292
- package/dist/builtin/workflows/src/shared/workflow-failures-contract.ts +0 -74
- package/dist/builtin/workflows/src/shared/workflow-failures-decisions.ts +0 -458
- package/dist/builtin/workflows/src/shared/workflow-failures-signals.ts +0 -303
- package/dist/builtin/workflows/src/shared/workflow-failures.ts +0 -13
- package/dist/builtin/workflows/src/shared/workflow-heartbeat-contract.d.ts +0 -21
- package/dist/builtin/workflows/src/shared/workflow-heartbeat-contract.ts +0 -25
- package/dist/builtin/workflows/src/shared/workflow-run-ownership.ts +0 -49
- package/dist/builtin/workflows/src/tui/chat-surface-message.ts +0 -319
- package/dist/builtin/workflows/src/tui/chat-surface.ts +0 -477
- package/dist/builtin/workflows/src/tui/color-utils.ts +0 -55
- package/dist/builtin/workflows/src/tui/connectors.ts +0 -84
- package/dist/builtin/workflows/src/tui/dispatch-confirm.ts +0 -334
- package/dist/builtin/workflows/src/tui/edge.ts +0 -25
- package/dist/builtin/workflows/src/tui/graph-canvas.ts +0 -185
- package/dist/builtin/workflows/src/tui/graph-theme.ts +0 -292
- package/dist/builtin/workflows/src/tui/graph-view-constants.ts +0 -49
- package/dist/builtin/workflows/src/tui/graph-view-graph-render.ts +0 -157
- package/dist/builtin/workflows/src/tui/graph-view-input.ts +0 -427
- package/dist/builtin/workflows/src/tui/graph-view-layout.ts +0 -297
- package/dist/builtin/workflows/src/tui/graph-view-render-helpers.ts +0 -294
- package/dist/builtin/workflows/src/tui/graph-view-render.ts +0 -361
- package/dist/builtin/workflows/src/tui/graph-view-state.ts +0 -547
- package/dist/builtin/workflows/src/tui/graph-view-types.ts +0 -79
- package/dist/builtin/workflows/src/tui/graph-view.ts +0 -25
- package/dist/builtin/workflows/src/tui/header.ts +0 -210
- package/dist/builtin/workflows/src/tui/host-input-form.ts +0 -64
- package/dist/builtin/workflows/src/tui/inline-form-card.ts +0 -438
- package/dist/builtin/workflows/src/tui/inline-form-editor-text.ts +0 -120
- package/dist/builtin/workflows/src/tui/inline-form-editor.ts +0 -496
- package/dist/builtin/workflows/src/tui/inline-form-overlay.ts +0 -317
- package/dist/builtin/workflows/src/tui/inline-form-store.ts +0 -90
- package/dist/builtin/workflows/src/tui/inputs-overlay.ts +0 -185
- package/dist/builtin/workflows/src/tui/inputs-picker-editing.ts +0 -147
- package/dist/builtin/workflows/src/tui/inputs-picker-input.ts +0 -357
- package/dist/builtin/workflows/src/tui/inputs-picker-render.ts +0 -312
- package/dist/builtin/workflows/src/tui/inputs-picker-types.ts +0 -161
- package/dist/builtin/workflows/src/tui/inputs-picker.ts +0 -20
- package/dist/builtin/workflows/src/tui/keybindings-adapter.ts +0 -167
- package/dist/builtin/workflows/src/tui/layout.ts +0 -150
- package/dist/builtin/workflows/src/tui/mouse-input.ts +0 -61
- package/dist/builtin/workflows/src/tui/node-card.ts +0 -357
- package/dist/builtin/workflows/src/tui/overlay-adapter.ts +0 -449
- package/dist/builtin/workflows/src/tui/overlay-terminal-modes.ts +0 -39
- package/dist/builtin/workflows/src/tui/prompt-card-input.ts +0 -215
- package/dist/builtin/workflows/src/tui/prompt-card-render.ts +0 -584
- package/dist/builtin/workflows/src/tui/prompt-card-select.ts +0 -94
- package/dist/builtin/workflows/src/tui/prompt-card-state.ts +0 -61
- package/dist/builtin/workflows/src/tui/prompt-card-text.ts +0 -122
- package/dist/builtin/workflows/src/tui/prompt-card.ts +0 -12
- package/dist/builtin/workflows/src/tui/renderers.ts +0 -14
- package/dist/builtin/workflows/src/tui/run-detail.ts +0 -438
- package/dist/builtin/workflows/src/tui/run-identity-rows.ts +0 -97
- package/dist/builtin/workflows/src/tui/session-list.ts +0 -38
- package/dist/builtin/workflows/src/tui/session-overlays.ts +0 -161
- package/dist/builtin/workflows/src/tui/session-picker.ts +0 -482
- package/dist/builtin/workflows/src/tui/stage-chat-composer-drafts.ts +0 -19
- package/dist/builtin/workflows/src/tui/stage-chat-layout.ts +0 -81
- package/dist/builtin/workflows/src/tui/stage-chat-view-archive-history.ts +0 -462
- package/dist/builtin/workflows/src/tui/stage-chat-view-custom-ui.ts +0 -115
- package/dist/builtin/workflows/src/tui/stage-chat-view-delivery-activity.ts +0 -113
- package/dist/builtin/workflows/src/tui/stage-chat-view-footer-status.ts +0 -219
- package/dist/builtin/workflows/src/tui/stage-chat-view-input.ts +0 -216
- package/dist/builtin/workflows/src/tui/stage-chat-view-live-events.ts +0 -65
- package/dist/builtin/workflows/src/tui/stage-chat-view-pending-tools.ts +0 -7
- package/dist/builtin/workflows/src/tui/stage-chat-view-render-helpers.ts +0 -149
- package/dist/builtin/workflows/src/tui/stage-chat-view-render-settings.ts +0 -49
- package/dist/builtin/workflows/src/tui/stage-chat-view-state.ts +0 -575
- package/dist/builtin/workflows/src/tui/stage-chat-view-status.ts +0 -35
- package/dist/builtin/workflows/src/tui/stage-chat-view-transcript.ts +0 -226
- package/dist/builtin/workflows/src/tui/stage-chat-view-types.ts +0 -156
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +0 -309
- package/dist/builtin/workflows/src/tui/status-helpers.ts +0 -85
- package/dist/builtin/workflows/src/tui/status-list.ts +0 -447
- package/dist/builtin/workflows/src/tui/store-widget-installer.ts +0 -338
- package/dist/builtin/workflows/src/tui/submit-pane.ts +0 -148
- package/dist/builtin/workflows/src/tui/switcher.ts +0 -172
- package/dist/builtin/workflows/src/tui/text-helpers.ts +0 -208
- package/dist/builtin/workflows/src/tui/tool-detail.ts +0 -367
- package/dist/builtin/workflows/src/tui/widget.ts +0 -427
- package/dist/builtin/workflows/src/tui/workflow-attach-pane-handle.ts +0 -21
- package/dist/builtin/workflows/src/tui/workflow-attach-pane-types.ts +0 -77
- package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +0 -477
- package/dist/builtin/workflows/src/tui/workflow-list.ts +0 -189
- package/dist/builtin/workflows/src/tui/workflow-notice-card.ts +0 -167
- package/dist/builtin/workflows/src/tui/workflow-resume-selector.ts +0 -334
- package/dist/builtin/workflows/src/tui/workflow-status.ts +0 -12
- package/dist/builtin/workflows/src/workflows/identity.ts +0 -39
- package/dist/builtin/workflows/src/workflows/registry.ts +0 -115
|
@@ -1,1472 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AgentSession,
|
|
3
|
-
type CreateAgentSessionOptions,
|
|
4
|
-
convertToLlm,
|
|
5
|
-
type PromptOptions,
|
|
6
|
-
type StructuredOutputCapture,
|
|
7
|
-
shouldApplyCodexFastModeForScope,
|
|
8
|
-
} from "@bastani/atomic";
|
|
9
|
-
import type {
|
|
10
|
-
StageContext,
|
|
11
|
-
StageExecutionMeta,
|
|
12
|
-
StageOptions,
|
|
13
|
-
StageSendUserMessageOptions,
|
|
14
|
-
StageUserMessageContent,
|
|
15
|
-
WorkflowModelAttempt,
|
|
16
|
-
WorkflowModelCatalogPort,
|
|
17
|
-
WorkflowModelUsage,
|
|
18
|
-
} from "../../shared/types.js";
|
|
19
|
-
import {
|
|
20
|
-
buildModelCandidatesFromCatalog,
|
|
21
|
-
errorMessage,
|
|
22
|
-
isRetryableModelFailure,
|
|
23
|
-
isRetryableSameModelFailure,
|
|
24
|
-
type WorkflowResolvedModelCandidate,
|
|
25
|
-
workflowModelId,
|
|
26
|
-
} from "../shared/model-fallback.js";
|
|
27
|
-
import { nextRetryDecision, sleepOrAbort } from "../shared/retry.js";
|
|
28
|
-
import { StageDeliveryActivity, type StageDeliveryActivityListener } from "./stage-delivery-activity.js";
|
|
29
|
-
import { stageSessionQueueUpdateEvent } from "./stage-queued-user-messages.js";
|
|
30
|
-
import { candidateLabel, effectiveCandidateReasoning, modelAttemptReasoning } from "./stage-runner-candidate.js";
|
|
31
|
-
import { StageMessageAdmission } from "./stage-runner-message-admission.js";
|
|
32
|
-
import {
|
|
33
|
-
lastAssistantTextFromSession,
|
|
34
|
-
latestTerminalAssistantFailureSince,
|
|
35
|
-
WorkflowPromptModelFailure,
|
|
36
|
-
} from "./stage-runner-messages.js";
|
|
37
|
-
import { missingAdapter, stripWorkflowOnlyOptions, unavailableSync } from "./stage-runner-options.js";
|
|
38
|
-
import { StageSessionPause, type StageSessionPauseResumeResult } from "./stage-runner-pause.js";
|
|
39
|
-
import { StageSessionReplacement } from "./stage-runner-replacement.js";
|
|
40
|
-
import { sendStageUserMessage } from "./stage-runner-send-user-message.js";
|
|
41
|
-
import {
|
|
42
|
-
asAgentSession,
|
|
43
|
-
attachCreatedStageSession,
|
|
44
|
-
disposeStageSession,
|
|
45
|
-
normalizeSessionCreateResult,
|
|
46
|
-
} from "./stage-runner-session.js";
|
|
47
|
-
import { buildStageSessionOptions } from "./stage-runner-session-options.js";
|
|
48
|
-
import { structuredOutputToolErrorFromEvent } from "./stage-runner-structured-output.js";
|
|
49
|
-
import type {
|
|
50
|
-
AgentSessionConsumer,
|
|
51
|
-
StageModelFallbackMeta,
|
|
52
|
-
StageRunnerOpts,
|
|
53
|
-
StageSessionCreateOptions,
|
|
54
|
-
StageSessionCreateResult,
|
|
55
|
-
StageSessionEvent,
|
|
56
|
-
StageSessionRuntime,
|
|
57
|
-
StageUserMessagePreparation,
|
|
58
|
-
WorkflowFastModeSettingsManager,
|
|
59
|
-
WorkflowRetrySettings,
|
|
60
|
-
} from "./stage-runner-types.js";
|
|
61
|
-
import {
|
|
62
|
-
isUnresolvedContextOverflowFailure,
|
|
63
|
-
nextResumedContextOverflowFallbackIndex,
|
|
64
|
-
terminatingToolCallId,
|
|
65
|
-
unresolvedContextOverflowFailure,
|
|
66
|
-
unresolvedContextOverflowMessage,
|
|
67
|
-
} from "./stage-runner-unresolved-overflow.js";
|
|
68
|
-
|
|
69
|
-
type RetryPauseResume = NonNullable<ReturnType<StageSessionPause["currentResume"]>>;
|
|
70
|
-
|
|
71
|
-
type StageMessage = StageSessionRuntime["messages"][number];
|
|
72
|
-
type StageAssistantMessage = Extract<StageMessage, { role: "assistant" }>;
|
|
73
|
-
|
|
74
|
-
type AttemptUsageTotals = {
|
|
75
|
-
input: number;
|
|
76
|
-
output: number;
|
|
77
|
-
cacheRead: number;
|
|
78
|
-
cacheWrite: number;
|
|
79
|
-
cost: number;
|
|
80
|
-
turns: number;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* A present usage object is meaningful when any token bucket, the total token
|
|
85
|
-
* count, or the provider-reported total cost is positive. Reject the entire
|
|
86
|
-
* provider record when any aggregated value is non-finite or negative so
|
|
87
|
-
* malformed telemetry cannot poison a durable stage checkpoint.
|
|
88
|
-
*/
|
|
89
|
-
function hasMeaningfulUsage(usage: StageAssistantMessage["usage"] | undefined): boolean {
|
|
90
|
-
if (usage === undefined) return false;
|
|
91
|
-
const values = [usage.input, usage.output, usage.cacheRead, usage.cacheWrite, usage.totalTokens, usage.cost.total];
|
|
92
|
-
return values.every((value) => Number.isFinite(value) && value >= 0) && values.some((value) => value > 0);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Aggregate the assistant-message usage admitted since the latched attempt
|
|
97
|
-
* boundary, plus usage accrued from error assistants that a retry restoration
|
|
98
|
-
* removed from the live transcript. Returns undefined when nothing meaningful
|
|
99
|
-
* was seen, so no `usage: undefined` enters the serializable attempt record.
|
|
100
|
-
*/
|
|
101
|
-
function usageForAttempt(
|
|
102
|
-
messages: readonly StageMessage[],
|
|
103
|
-
start: number,
|
|
104
|
-
discarded: AttemptUsageTotals,
|
|
105
|
-
): WorkflowModelUsage | undefined {
|
|
106
|
-
const totals = { ...discarded };
|
|
107
|
-
let meaningful = totals.turns > 0;
|
|
108
|
-
|
|
109
|
-
for (const message of messages.slice(start)) {
|
|
110
|
-
if (message.role !== "assistant" || !hasMeaningfulUsage(message.usage)) continue;
|
|
111
|
-
totals.input += message.usage.input;
|
|
112
|
-
totals.output += message.usage.output;
|
|
113
|
-
totals.cacheRead += message.usage.cacheRead;
|
|
114
|
-
totals.cacheWrite += message.usage.cacheWrite;
|
|
115
|
-
totals.cost += message.usage.cost.total;
|
|
116
|
-
totals.turns += 1;
|
|
117
|
-
meaningful = true;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return meaningful ? totals : undefined;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
interface ThrownErrorRetryState {
|
|
124
|
-
readonly controller: AbortController;
|
|
125
|
-
pauseResume?: RetryPauseResume;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** Observes a controlled pause raised while a session creation is in flight. */
|
|
129
|
-
interface CreationPauseObserver {
|
|
130
|
-
pauseResume?: RetryPauseResume;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
interface SessionCreationPauseResult {
|
|
134
|
-
readonly kind: "paused";
|
|
135
|
-
readonly resumeMessage?: string;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function isSessionCreationPauseResult(
|
|
139
|
-
value: StageSessionRuntime | SessionCreationPauseResult,
|
|
140
|
-
): value is SessionCreationPauseResult {
|
|
141
|
-
return "kind" in value && value.kind === "paused";
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
class StageSessionCreationCancelled extends Error {
|
|
145
|
-
constructor() {
|
|
146
|
-
super("atomic-workflows: stage session creation was cancelled while paused");
|
|
147
|
-
this.name = "StageSessionCreationCancelled";
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function stageUserMessageText(message: StageSessionRuntime["messages"][number]): string | undefined {
|
|
152
|
-
if (message.role !== "user") return undefined;
|
|
153
|
-
if (typeof message.content === "string") return message.content;
|
|
154
|
-
return message.content
|
|
155
|
-
.filter((part) => part.type === "text")
|
|
156
|
-
.map((part) => part.text)
|
|
157
|
-
.join("");
|
|
158
|
-
}
|
|
159
|
-
function retrySettingsManagerFromError(error: unknown): WorkflowFastModeSettingsManager | undefined {
|
|
160
|
-
if (error === null || typeof error !== "object") return undefined;
|
|
161
|
-
const manager = (error as { readonly settingsManager?: unknown }).settingsManager;
|
|
162
|
-
if (manager === null || typeof manager !== "object") return undefined;
|
|
163
|
-
const candidate = manager as Partial<WorkflowFastModeSettingsManager>;
|
|
164
|
-
return typeof candidate.getCodexFastModeSettings === "function"
|
|
165
|
-
? (candidate as WorkflowFastModeSettingsManager)
|
|
166
|
-
: undefined;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
type RetryableAgentSession = AgentSession & {
|
|
170
|
-
_runAgentContinue(): Promise<void>;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
function retryableAgentSession(activeSession: StageSessionRuntime): RetryableAgentSession | undefined {
|
|
174
|
-
const session = asAgentSession(activeSession);
|
|
175
|
-
if (session === undefined) return undefined;
|
|
176
|
-
const candidate = session as AgentSession & { readonly _runAgentContinue?: unknown };
|
|
177
|
-
return typeof candidate._runAgentContinue === "function" ? (session as RetryableAgentSession) : undefined;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* pi-agent-core requires the last message of a continued transcript to convert
|
|
182
|
-
* to a `user` or `toolResult` provider message (`agent-loop.js` `agentLoopContinue`);
|
|
183
|
-
* anything else is rejected once the request reaches the provider.
|
|
184
|
-
*
|
|
185
|
-
* The raw tail is not enough to answer that. A retry that restored live state
|
|
186
|
-
* can leave a retained non-error assistant, or a `custom`/`bashExecution`/
|
|
187
|
-
* `branchSummary` message that Atomic's converter drops when it is excluded
|
|
188
|
-
* from context or empty — leaving an assistant as the converted tail. Evaluate
|
|
189
|
-
* the same `convertToLlm()` result Atomic sends.
|
|
190
|
-
*/
|
|
191
|
-
function canContinueFromTranscript(activeSession: StageSessionRuntime): boolean {
|
|
192
|
-
const converted = convertToLlm([...activeSession.messages]);
|
|
193
|
-
const last = converted[converted.length - 1];
|
|
194
|
-
return last !== undefined && (last.role === "user" || last.role === "toolResult");
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
class ThrownErrorRetryPaused extends Error {
|
|
198
|
-
constructor(readonly resume: RetryPauseResume) {
|
|
199
|
-
super("atomic-workflows: thrown-error retry paused");
|
|
200
|
-
this.name = "ThrownErrorRetryPaused";
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export class StageSessionController {
|
|
205
|
-
private session: StageSessionRuntime | undefined;
|
|
206
|
-
private activeCreation: Promise<StageSessionRuntime> | undefined;
|
|
207
|
-
/** The creation promise a candidate walk still owns, if one is advancing. */
|
|
208
|
-
private ownedCreationPromise: Promise<StageSessionRuntime> | undefined;
|
|
209
|
-
private abortGeneration = 0;
|
|
210
|
-
private abortReason: Error | DOMException | string | undefined;
|
|
211
|
-
private abortReasonGeneration = 0;
|
|
212
|
-
private sessionPromise: Promise<StageSessionRuntime> | undefined;
|
|
213
|
-
private reattachSessionFile: string | undefined;
|
|
214
|
-
private lastPromptStartIndex: number | undefined;
|
|
215
|
-
/** Message index latched once per high-level candidate prompt; never re-read later. */
|
|
216
|
-
private attemptUsageStartIndex: number | undefined;
|
|
217
|
-
/** Usage accrued from error assistants removed by retry restoration. */
|
|
218
|
-
private discardedAttemptUsage: AttemptUsageTotals = {
|
|
219
|
-
input: 0,
|
|
220
|
-
output: 0,
|
|
221
|
-
cacheRead: 0,
|
|
222
|
-
cacheWrite: 0,
|
|
223
|
-
cost: 0,
|
|
224
|
-
turns: 0,
|
|
225
|
-
};
|
|
226
|
-
private readonly terminatingToolCallIds = new Set<string>();
|
|
227
|
-
private latestStructuredOutputToolErrorValue: string | undefined;
|
|
228
|
-
private unsubscribeTerminateWatcher: (() => void) | undefined;
|
|
229
|
-
private unresolvedContextOverflowMessage: string | undefined;
|
|
230
|
-
private generationSealed = false;
|
|
231
|
-
private disposed = false;
|
|
232
|
-
private pendingDisposal = false;
|
|
233
|
-
private disposalPromise: Promise<void> | undefined;
|
|
234
|
-
private pendingThinkingLevel: Parameters<StageContext["setThinkingLevel"]>[0] | undefined;
|
|
235
|
-
private readonly pendingListeners = new Set<(event: StageSessionEvent) => void>();
|
|
236
|
-
private readonly listenerUnsubscribes = new Map<(event: StageSessionEvent) => void, () => void>();
|
|
237
|
-
private readonly pauseControl = new StageSessionPause(() => this.session);
|
|
238
|
-
private readonly hasExplicitModelFallbackConfig: boolean;
|
|
239
|
-
private candidatesPromise: Promise<WorkflowResolvedModelCandidate[]> | undefined;
|
|
240
|
-
private activeCandidateIndex: number | undefined;
|
|
241
|
-
private selectedModel: string | undefined;
|
|
242
|
-
private sharedModelRuntime: CreateAgentSessionOptions["modelRuntime"];
|
|
243
|
-
private sharedOrchestrationContext: CreateAgentSessionOptions["orchestrationContext"];
|
|
244
|
-
private resumeCurrentSession = false;
|
|
245
|
-
private readonly modelAttempts: WorkflowModelAttempt[] = [];
|
|
246
|
-
private readonly modelWarnings: string[] = [];
|
|
247
|
-
private readonly pendingFallbackWarnings: string[] = [];
|
|
248
|
-
private readonly modelCatalog: WorkflowModelCatalogPort | undefined;
|
|
249
|
-
private sessionSettingsManager: WorkflowFastModeSettingsManager | undefined;
|
|
250
|
-
private readonly thrownErrorRetryStates = new Set<ThrownErrorRetryState>();
|
|
251
|
-
private readonly creationPauseObservers = new Set<CreationPauseObserver>();
|
|
252
|
-
private readonly replacement = new StageSessionReplacement();
|
|
253
|
-
private pendingCreationResumeMessage: string | undefined;
|
|
254
|
-
private readonly messageAdmission = new StageMessageAdmission();
|
|
255
|
-
private readonly deliveryActivity = new StageDeliveryActivity();
|
|
256
|
-
|
|
257
|
-
constructor(
|
|
258
|
-
private readonly opts: StageRunnerOpts,
|
|
259
|
-
private readonly meta: StageExecutionMeta,
|
|
260
|
-
private readonly effectiveStageOptions: StageOptions | undefined,
|
|
261
|
-
private readonly structuredOutputCapture: StructuredOutputCapture<unknown> | undefined,
|
|
262
|
-
) {
|
|
263
|
-
this.hasExplicitModelFallbackConfig =
|
|
264
|
-
effectiveStageOptions?.model !== undefined || (effectiveStageOptions?.fallbackModels?.length ?? 0) > 0;
|
|
265
|
-
this.modelCatalog =
|
|
266
|
-
opts.models === undefined
|
|
267
|
-
? undefined
|
|
268
|
-
: ({
|
|
269
|
-
...opts.models,
|
|
270
|
-
recordWarning: (warning: string): void => {
|
|
271
|
-
this.modelWarnings.push(warning);
|
|
272
|
-
opts.models?.recordWarning?.(warning);
|
|
273
|
-
},
|
|
274
|
-
} satisfies WorkflowModelCatalogPort);
|
|
275
|
-
this.bindAbortSignal();
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
get currentSession(): StageSessionRuntime | undefined {
|
|
279
|
-
return this.session;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
get currentPromptStartIndex(): number | undefined {
|
|
283
|
-
return this.lastPromptStartIndex;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
get latestStructuredOutputToolError(): string | undefined {
|
|
287
|
-
return this.latestStructuredOutputToolErrorValue;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
resetStructuredOutputToolError(): void {
|
|
291
|
-
this.latestStructuredOutputToolErrorValue = undefined;
|
|
292
|
-
}
|
|
293
|
-
requireSession(property: string): StageSessionRuntime {
|
|
294
|
-
if (!this.session) unavailableSync(property);
|
|
295
|
-
return this.session;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
lastAssistantText(fallback: string | undefined): string | undefined {
|
|
299
|
-
return lastAssistantTextFromSession(this.session, fallback, this.terminatingToolCallIds);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
subscribe(listener: (event: StageSessionEvent) => void): () => void {
|
|
303
|
-
this.pendingListeners.add(listener);
|
|
304
|
-
if (this.session) this.listenerUnsubscribes.set(listener, this.session.subscribe(listener));
|
|
305
|
-
return () => {
|
|
306
|
-
this.pendingListeners.delete(listener);
|
|
307
|
-
const unsubscribe = this.listenerUnsubscribes.get(listener);
|
|
308
|
-
this.listenerUnsubscribes.delete(listener);
|
|
309
|
-
unsubscribe?.();
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
setThinkingLevel(level: Parameters<StageContext["setThinkingLevel"]>[0]): void {
|
|
314
|
-
this.pendingThinkingLevel = level;
|
|
315
|
-
this.session?.setThinkingLevel(level);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
async ensureSession(consumer: AgentSessionConsumer = "prompt"): Promise<StageSessionRuntime> {
|
|
319
|
-
if (this.disposed) throw new Error(`atomic-workflows: stage "${this.opts.stageName}" session has been disposed`);
|
|
320
|
-
if (this.session !== undefined) return this.session;
|
|
321
|
-
if (!this.sessionPromise) {
|
|
322
|
-
const pending = this.createInitialSession(consumer);
|
|
323
|
-
this.sessionPromise = pending;
|
|
324
|
-
// One creation gate: the walk owns this promise while it advances
|
|
325
|
-
// candidates, so a concurrent caller joins it instead of racing it.
|
|
326
|
-
this.ownedCreationPromise = pending;
|
|
327
|
-
const release = (): void => {
|
|
328
|
-
if (this.ownedCreationPromise === pending) this.ownedCreationPromise = undefined;
|
|
329
|
-
};
|
|
330
|
-
// A terminal creation failure must not be replayed to every later
|
|
331
|
-
// caller. Clear by identity so a walk that replaced the promise, or a
|
|
332
|
-
// cancellation that already cleared it, is left alone.
|
|
333
|
-
pending.then(release, () => {
|
|
334
|
-
release();
|
|
335
|
-
if (this.sessionPromise === pending) this.sessionPromise = undefined;
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
return this.sessionPromise;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
async ensureSessionFromFile(
|
|
342
|
-
sessionFile: string,
|
|
343
|
-
consumer: AgentSessionConsumer = "prompt",
|
|
344
|
-
): Promise<StageSessionRuntime> {
|
|
345
|
-
if (!this.sessionPromise && !this.session) this.reattachSessionFile = sessionFile;
|
|
346
|
-
const session = await this.ensureSession(consumer);
|
|
347
|
-
await session.closeWorkflowStageGeneration?.();
|
|
348
|
-
return session;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
async sendUserMessage(
|
|
352
|
-
content: StageUserMessageContent,
|
|
353
|
-
options?: StageSendUserMessageOptions,
|
|
354
|
-
beforeDelivery?: () => void,
|
|
355
|
-
preparation?: StageUserMessagePreparation,
|
|
356
|
-
): Promise<Awaited<ReturnType<typeof sendStageUserMessage>>> {
|
|
357
|
-
return this.messageAdmission.run(async (release) => {
|
|
358
|
-
const pausedDelivery = this.pauseControl.deferRunnerOwnedDelivery(() =>
|
|
359
|
-
this.sendUserMessage(content, options, beforeDelivery, preparation),
|
|
360
|
-
);
|
|
361
|
-
if (pausedDelivery !== undefined) {
|
|
362
|
-
release();
|
|
363
|
-
return pausedDelivery;
|
|
364
|
-
}
|
|
365
|
-
preparation?.beforePreparation?.();
|
|
366
|
-
const sessionFile = preparation?.sessionFile;
|
|
367
|
-
const deliver = async (activity?: StageDeliveryActivity) => {
|
|
368
|
-
const activeSession =
|
|
369
|
-
sessionFile === undefined
|
|
370
|
-
? await this.ensureSession("prompt")
|
|
371
|
-
: await this.ensureSessionFromFile(sessionFile, "prompt");
|
|
372
|
-
const pausedDelivery = this.pauseControl.deferRunnerOwnedDelivery(() =>
|
|
373
|
-
sendStageUserMessage(
|
|
374
|
-
activeSession,
|
|
375
|
-
content,
|
|
376
|
-
options,
|
|
377
|
-
beforeDelivery,
|
|
378
|
-
release,
|
|
379
|
-
this.messageAdmission,
|
|
380
|
-
activity,
|
|
381
|
-
),
|
|
382
|
-
);
|
|
383
|
-
if (pausedDelivery !== undefined) {
|
|
384
|
-
release();
|
|
385
|
-
return pausedDelivery;
|
|
386
|
-
}
|
|
387
|
-
return sendStageUserMessage(
|
|
388
|
-
activeSession,
|
|
389
|
-
content,
|
|
390
|
-
options,
|
|
391
|
-
beforeDelivery,
|
|
392
|
-
release,
|
|
393
|
-
this.messageAdmission,
|
|
394
|
-
activity,
|
|
395
|
-
);
|
|
396
|
-
};
|
|
397
|
-
if (this.session === undefined || sessionFile !== undefined)
|
|
398
|
-
return this.deliveryActivity.runWithLease(() => deliver());
|
|
399
|
-
return deliver(this.deliveryActivity);
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
/** Internal pre-stream delivery lifecycle consumed by an attached stage chat. */
|
|
403
|
-
subscribeDeliveryActivity(listener: StageDeliveryActivityListener): () => void {
|
|
404
|
-
return this.deliveryActivity.subscribe(listener);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
sealGeneration(): void {
|
|
408
|
-
this.generationSealed = true;
|
|
409
|
-
this.sharedOrchestrationContext?.messageAdmission?.boundary.seal();
|
|
410
|
-
this.session?.sealWorkflowStageGeneration?.();
|
|
411
|
-
}
|
|
412
|
-
async closeGeneration(): Promise<void> {
|
|
413
|
-
this.sealGeneration();
|
|
414
|
-
const pending = this.activeCreation ?? this.sessionPromise;
|
|
415
|
-
const session = pending ? await pending : this.session;
|
|
416
|
-
await session?.closeWorkflowStageGeneration?.();
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
async promptWithFallback(
|
|
420
|
-
text: string,
|
|
421
|
-
sdkOptions: PromptOptions | undefined,
|
|
422
|
-
consumer: AgentSessionConsumer = "prompt",
|
|
423
|
-
): Promise<void> {
|
|
424
|
-
if (!this.hasExplicitModelFallbackConfig) {
|
|
425
|
-
try {
|
|
426
|
-
const activeSession = await this.ensureSession(consumer);
|
|
427
|
-
const resumedText = this.pendingCreationResumeMessage;
|
|
428
|
-
this.pendingCreationResumeMessage = undefined;
|
|
429
|
-
const value = activeSession.model ?? "default";
|
|
430
|
-
const candidate = { id: workflowModelId(value) ?? "default", value };
|
|
431
|
-
this.beginAttemptUsage(activeSession);
|
|
432
|
-
try {
|
|
433
|
-
await this.promptWithThrownErrorRetry(activeSession, resumedText ?? text, sdkOptions);
|
|
434
|
-
} catch (error) {
|
|
435
|
-
await this.handleCandidateFailure(error, candidate, [candidate], 0);
|
|
436
|
-
throw error;
|
|
437
|
-
}
|
|
438
|
-
this.recordSuccessfulAttempt(candidate);
|
|
439
|
-
} catch (error) {
|
|
440
|
-
if (error instanceof StageSessionCreationCancelled) return;
|
|
441
|
-
throw error;
|
|
442
|
-
}
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
const candidates = await this.modelCandidates();
|
|
447
|
-
if (candidates.length === 0) {
|
|
448
|
-
try {
|
|
449
|
-
const activeSession = await this.ensureSession(consumer);
|
|
450
|
-
const resumedText = this.pendingCreationResumeMessage;
|
|
451
|
-
this.pendingCreationResumeMessage = undefined;
|
|
452
|
-
await this.promptWithThrownErrorRetry(activeSession, resumedText ?? text, sdkOptions);
|
|
453
|
-
} catch (error) {
|
|
454
|
-
if (error instanceof StageSessionCreationCancelled) return;
|
|
455
|
-
throw error;
|
|
456
|
-
}
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
// A creation already in flight — an eager walk, or a concurrent caller —
|
|
461
|
-
// owns the candidate chain. Join it rather than starting a second walk that
|
|
462
|
-
// would duplicate provider work and leak whichever session lost the race.
|
|
463
|
-
if (this.session === undefined && this.sessionPromise !== undefined) {
|
|
464
|
-
try {
|
|
465
|
-
await this.sessionPromise;
|
|
466
|
-
} catch (error) {
|
|
467
|
-
if (error instanceof StageSessionCreationCancelled) return;
|
|
468
|
-
// The exhausted walk cleared its own promise by identity; fall through
|
|
469
|
-
// and let the walk below report the failure for this prompt.
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// A paused creation resumed with a replacement objective: that text is
|
|
474
|
-
// authoritative for this prompt and must not be dropped here.
|
|
475
|
-
const resumedText = this.pendingCreationResumeMessage;
|
|
476
|
-
this.pendingCreationResumeMessage = undefined;
|
|
477
|
-
let promptText = resumedText ?? text;
|
|
478
|
-
if (await this.tryResumeCurrentSession(promptText, sdkOptions, candidates)) return;
|
|
479
|
-
let index = this.activeCandidateIndex ?? 0;
|
|
480
|
-
while (index < candidates.length) {
|
|
481
|
-
const candidate = candidates[index]!;
|
|
482
|
-
try {
|
|
483
|
-
const created =
|
|
484
|
-
this.session && this.activeCandidateIndex === index
|
|
485
|
-
? this.session
|
|
486
|
-
: await this.createSessionWithThrownErrorRetry(candidate, consumer);
|
|
487
|
-
if (isSessionCreationPauseResult(created)) {
|
|
488
|
-
if (created.resumeMessage === undefined) return;
|
|
489
|
-
promptText = created.resumeMessage;
|
|
490
|
-
continue;
|
|
491
|
-
}
|
|
492
|
-
const activeSession = created;
|
|
493
|
-
this.activeCandidateIndex = index;
|
|
494
|
-
this.selectedModel = candidate.id;
|
|
495
|
-
this.notifyModelFallbackMetaChange();
|
|
496
|
-
this.beginAttemptUsage(activeSession);
|
|
497
|
-
const { terminalScanStartIndex } = await this.promptWithThrownErrorRetry(
|
|
498
|
-
activeSession,
|
|
499
|
-
promptText,
|
|
500
|
-
sdkOptions,
|
|
501
|
-
);
|
|
502
|
-
const terminalFailure = latestTerminalAssistantFailureSince(activeSession.messages, terminalScanStartIndex);
|
|
503
|
-
if (terminalFailure !== undefined) {
|
|
504
|
-
if (this.capturedStructuredOutputForAttempt()) {
|
|
505
|
-
this.recordSuccessfulAttempt(candidate);
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
throw new WorkflowPromptModelFailure(terminalFailure);
|
|
509
|
-
}
|
|
510
|
-
this.recordSuccessfulAttempt(candidate);
|
|
511
|
-
return;
|
|
512
|
-
} catch (err) {
|
|
513
|
-
const failure = await this.handleCandidateFailure(err, candidate, candidates, index);
|
|
514
|
-
if (failure === "handled") return;
|
|
515
|
-
if (failure === "throw") throw err;
|
|
516
|
-
index += 1;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
currentModelFallbackMeta(): StageModelFallbackMeta {
|
|
522
|
-
const attemptedModels = this.modelAttempts.map((attempt) => attempt.model);
|
|
523
|
-
const model = this.selectedModel ?? workflowModelId(this.session?.model);
|
|
524
|
-
const fastMode = this.isWorkflowFastModeEnabled();
|
|
525
|
-
return {
|
|
526
|
-
...(model !== undefined ? { model } : {}),
|
|
527
|
-
...(fastMode !== undefined ? { fastMode } : {}),
|
|
528
|
-
...(attemptedModels.length > 0 ? { attemptedModels } : {}),
|
|
529
|
-
...(this.modelAttempts.length > 0 ? { modelAttempts: [...this.modelAttempts] } : {}),
|
|
530
|
-
...(this.modelWarnings.length > 0 ? { warnings: [...this.modelWarnings] } : {}),
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
async disposeAll(): Promise<void> {
|
|
535
|
-
if (this.disposalPromise !== undefined) return this.disposalPromise;
|
|
536
|
-
if (this.pauseControl.isConfirmedPaused()) {
|
|
537
|
-
this.pendingDisposal = true;
|
|
538
|
-
return;
|
|
539
|
-
}
|
|
540
|
-
this.pendingDisposal = false;
|
|
541
|
-
this.disposalPromise = this.finishDisposeAll();
|
|
542
|
-
return this.disposalPromise;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
private async finishDisposeAll(): Promise<void> {
|
|
546
|
-
this.disposed = true;
|
|
547
|
-
const reason = new Error(`atomic-workflows: stage "${this.opts.stageName}" session has been disposed`);
|
|
548
|
-
this.markAbort(reason);
|
|
549
|
-
this.pauseControl.reject(reason);
|
|
550
|
-
for (const unsubscribe of this.listenerUnsubscribes.values()) unsubscribe();
|
|
551
|
-
this.listenerUnsubscribes.clear();
|
|
552
|
-
this.pendingListeners.clear();
|
|
553
|
-
this.unsubscribeTerminateWatcher?.();
|
|
554
|
-
this.unsubscribeTerminateWatcher = undefined;
|
|
555
|
-
this.terminatingToolCallIds.clear();
|
|
556
|
-
this.messageAdmission.dispose();
|
|
557
|
-
this.deliveryActivity.dispose();
|
|
558
|
-
await this.replacement.dispose();
|
|
559
|
-
await disposeStageSession(this.session);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* A disposal deferred by a confirmed pause still has to happen once that
|
|
564
|
-
* pause is gone. Abort/kill rejects the parked waiter, so the session and its
|
|
565
|
-
* listeners must be torn down here rather than leaked.
|
|
566
|
-
*/
|
|
567
|
-
private async drainPendingDisposal(): Promise<void> {
|
|
568
|
-
if (!this.pendingDisposal) return;
|
|
569
|
-
await this.disposeAll();
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
async abort(): Promise<void> {
|
|
573
|
-
const reason = new DOMException("stage aborted", "AbortError");
|
|
574
|
-
this.markAbort(reason);
|
|
575
|
-
this.pauseControl.reject(reason);
|
|
576
|
-
try {
|
|
577
|
-
await this.session?.abort();
|
|
578
|
-
} finally {
|
|
579
|
-
await this.drainPendingDisposal();
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
requestPause(): Promise<void> {
|
|
583
|
-
const pause = this.pauseControl.requestPause();
|
|
584
|
-
const resume = this.pauseControl.currentResume();
|
|
585
|
-
if (resume !== undefined) {
|
|
586
|
-
this.pauseThrownErrorRetries(resume);
|
|
587
|
-
// A creation in flight cannot see the pause request itself, because
|
|
588
|
-
// completing the resume clears it before creation settles.
|
|
589
|
-
for (const observer of this.creationPauseObservers) {
|
|
590
|
-
if (observer.pauseResume !== undefined) continue;
|
|
591
|
-
observer.pauseResume = resume;
|
|
592
|
-
this.latchCreationResume(resume);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
return pause;
|
|
596
|
-
}
|
|
597
|
-
resume(
|
|
598
|
-
message?: string,
|
|
599
|
-
beforeResolve?: (result: StageSessionPauseResumeResult) => void,
|
|
600
|
-
beforeRelease?: () => void,
|
|
601
|
-
): Promise<StageSessionPauseResumeResult> {
|
|
602
|
-
return this.pauseControl.resume(message, beforeResolve, beforeRelease).then((result) => {
|
|
603
|
-
// Ownership has returned to live execution, but a handle released while
|
|
604
|
-
// paused may already be gone from the registry. Keep the deferred-disposal
|
|
605
|
-
// marker so terminal teardown can drain it for this ownerless execution.
|
|
606
|
-
return result;
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
isPaused(): boolean {
|
|
610
|
-
return this.pauseControl.isPaused();
|
|
611
|
-
}
|
|
612
|
-
sessionMeta(): { sessionId: string | undefined; sessionFile: string | undefined } {
|
|
613
|
-
return { sessionId: this.session?.sessionId, sessionFile: this.session?.sessionFile };
|
|
614
|
-
}
|
|
615
|
-
agentSession(): AgentSession | undefined {
|
|
616
|
-
return asAgentSession(this.session);
|
|
617
|
-
}
|
|
618
|
-
pendingMessageCount(): number {
|
|
619
|
-
return typeof this.session?.pendingMessageCount === "number" ? this.session.pendingMessageCount : 0;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
private bindAbortSignal(): void {
|
|
623
|
-
const { signal } = this.opts;
|
|
624
|
-
if (!signal) return;
|
|
625
|
-
const abortReason = (): Error | DOMException | string => {
|
|
626
|
-
const reason = signal.reason;
|
|
627
|
-
if (reason instanceof Error || reason instanceof DOMException || typeof reason === "string") return reason;
|
|
628
|
-
return new DOMException("workflow killed", "AbortError");
|
|
629
|
-
};
|
|
630
|
-
const onAbort = (): void => {
|
|
631
|
-
const reason = abortReason();
|
|
632
|
-
this.markAbort(reason);
|
|
633
|
-
void this.session?.abort().catch(() => {});
|
|
634
|
-
this.pauseControl.reject(reason);
|
|
635
|
-
void this.drainPendingDisposal().catch(() => {});
|
|
636
|
-
};
|
|
637
|
-
if (signal.aborted) onAbort();
|
|
638
|
-
else signal.addEventListener("abort", onAbort, { once: true });
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
private markAbort(reason: Error | DOMException | string): void {
|
|
642
|
-
this.abortGeneration += 1;
|
|
643
|
-
this.abortReason = reason;
|
|
644
|
-
this.abortReasonGeneration = this.abortGeneration;
|
|
645
|
-
this.abortThrownErrorRetries(reason);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
private pauseThrownErrorRetries(resume: RetryPauseResume): void {
|
|
649
|
-
for (const state of this.thrownErrorRetryStates) {
|
|
650
|
-
if (state.pauseResume !== undefined) continue;
|
|
651
|
-
state.pauseResume = resume;
|
|
652
|
-
state.controller.abort(new ThrownErrorRetryPaused(resume));
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
private abortThrownErrorRetries(reason?: Error | DOMException | string): void {
|
|
657
|
-
for (const state of this.thrownErrorRetryStates) state.controller.abort(reason);
|
|
658
|
-
this.thrownErrorRetryStates.clear();
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
private retrySettings(): WorkflowRetrySettings | undefined {
|
|
662
|
-
const managers = [
|
|
663
|
-
this.sessionSettingsManager,
|
|
664
|
-
this.session?.settingsManager,
|
|
665
|
-
this.effectiveStageOptions?.settingsManager,
|
|
666
|
-
];
|
|
667
|
-
for (const manager of managers) {
|
|
668
|
-
if (manager === undefined || typeof manager.getRetrySettings !== "function") continue;
|
|
669
|
-
return manager.getRetrySettings();
|
|
670
|
-
}
|
|
671
|
-
return undefined;
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Latch a fresh high-level usage window against the active session. The
|
|
675
|
-
* boundary is the message length before the candidate prompt, so retries,
|
|
676
|
-
* pause/re-prompts, and recording never re-read a later index.
|
|
677
|
-
*/
|
|
678
|
-
private beginAttemptUsage(session: StageSessionRuntime): void {
|
|
679
|
-
this.attemptUsageStartIndex = session.messages.length;
|
|
680
|
-
this.discardedAttemptUsage = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
/**
|
|
684
|
-
* Consume the current window exactly once. A session-creation failure has no
|
|
685
|
-
* window: clear the latch instead of reading a previous session's messages.
|
|
686
|
-
*/
|
|
687
|
-
private takeAttemptUsage(session: StageSessionRuntime | undefined): WorkflowModelUsage | undefined {
|
|
688
|
-
const start = this.attemptUsageStartIndex;
|
|
689
|
-
const usage =
|
|
690
|
-
session === undefined || start === undefined
|
|
691
|
-
? undefined
|
|
692
|
-
: usageForAttempt(session.messages, start, this.discardedAttemptUsage);
|
|
693
|
-
this.clearAttemptUsage();
|
|
694
|
-
return usage;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
private clearAttemptUsage(): void {
|
|
698
|
-
this.attemptUsageStartIndex = undefined;
|
|
699
|
-
this.discardedAttemptUsage = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* Keep the usage of an error assistant that a retry restoration is about to
|
|
704
|
-
* remove from the live transcript, so the final attempt total still counts it.
|
|
705
|
-
*/
|
|
706
|
-
private accrueDiscardedAttemptUsage(message: StageAssistantMessage): void {
|
|
707
|
-
if (!hasMeaningfulUsage(message.usage)) return;
|
|
708
|
-
this.discardedAttemptUsage.input += message.usage.input;
|
|
709
|
-
this.discardedAttemptUsage.output += message.usage.output;
|
|
710
|
-
this.discardedAttemptUsage.cacheRead += message.usage.cacheRead;
|
|
711
|
-
this.discardedAttemptUsage.cacheWrite += message.usage.cacheWrite;
|
|
712
|
-
this.discardedAttemptUsage.cost += message.usage.cost.total;
|
|
713
|
-
this.discardedAttemptUsage.turns += 1;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
/**
|
|
717
|
-
* Drop this attempt's failed input from live state before a same-candidate
|
|
718
|
-
* retry, keeping unrelated concurrent messages. The durable transcript keeps
|
|
719
|
-
* everything; this mirrors main-chat retry, which also only edits live state.
|
|
720
|
-
*
|
|
721
|
-
* `keepPrompt` retains the admitted stage prompt because the continuation
|
|
722
|
-
* path resumes the existing turn with `_runAgentContinue()`, and pi-agent-core
|
|
723
|
-
* rejects a transcript that does not end in a user or tool-result message.
|
|
724
|
-
* Returns the retained prompt so a later re-`prompt()` can drop it.
|
|
725
|
-
*/
|
|
726
|
-
private restoreSessionMessages(
|
|
727
|
-
session: StageSessionRuntime,
|
|
728
|
-
snapshot: StageSessionRuntime["messages"],
|
|
729
|
-
promptText: string,
|
|
730
|
-
keepPrompt: boolean,
|
|
731
|
-
): StageSessionRuntime["messages"][number] | undefined {
|
|
732
|
-
const snapshotMessages = new Set(snapshot);
|
|
733
|
-
const admitted = session.messages.filter((message) => !snapshotMessages.has(message));
|
|
734
|
-
// Error assistants the filter below removes still carry real provider
|
|
735
|
-
// usage; accrue it before the splice so the retry total keeps it.
|
|
736
|
-
for (const message of admitted) {
|
|
737
|
-
if (message.role !== "assistant" || message.stopReason !== "error") continue;
|
|
738
|
-
this.accrueDiscardedAttemptUsage(message);
|
|
739
|
-
}
|
|
740
|
-
const failedAssistantIndex = admitted.findLastIndex(
|
|
741
|
-
(message) => message.role === "assistant" && message.stopReason === "error",
|
|
742
|
-
);
|
|
743
|
-
const promptUser = admitted
|
|
744
|
-
.slice(0, failedAssistantIndex < 0 ? admitted.length : failedAssistantIndex)
|
|
745
|
-
.findLast((message) => message.role === "user" && stageUserMessageText(message) === promptText);
|
|
746
|
-
const retainedMessages = admitted.filter((message) => {
|
|
747
|
-
if (message === promptUser) return keepPrompt;
|
|
748
|
-
if (message.role === "assistant") return message.stopReason !== "error";
|
|
749
|
-
return ["user", "toolResult", "custom", "bashExecution", "branchSummary"].includes(message.role);
|
|
750
|
-
});
|
|
751
|
-
session.messages.splice(0, session.messages.length, ...snapshot, ...retainedMessages);
|
|
752
|
-
return keepPrompt ? promptUser : undefined;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
/** Remove a prompt retained for a continuation that will not happen. */
|
|
756
|
-
private dropRetainedPrompt(
|
|
757
|
-
session: StageSessionRuntime,
|
|
758
|
-
retained: StageSessionRuntime["messages"][number] | undefined,
|
|
759
|
-
): void {
|
|
760
|
-
if (retained === undefined) return;
|
|
761
|
-
const index = session.messages.indexOf(retained);
|
|
762
|
-
if (index >= 0) session.messages.splice(index, 1);
|
|
763
|
-
}
|
|
764
|
-
private async sleepForThrownErrorRetry(delayMs: number, state: ThrownErrorRetryState): Promise<void> {
|
|
765
|
-
this.thrownErrorRetryStates.add(state);
|
|
766
|
-
const currentResume = this.pauseControl.currentResume();
|
|
767
|
-
if (currentResume !== undefined) {
|
|
768
|
-
state.pauseResume = currentResume;
|
|
769
|
-
state.controller.abort(new ThrownErrorRetryPaused(currentResume));
|
|
770
|
-
}
|
|
771
|
-
try {
|
|
772
|
-
await sleepOrAbort(delayMs, state.controller.signal);
|
|
773
|
-
} finally {
|
|
774
|
-
this.thrownErrorRetryStates.delete(state);
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
/**
|
|
779
|
-
* Resume the existing turn under the same pause rules as a prompt.
|
|
780
|
-
*
|
|
781
|
-
* A controlled pause aborts the in-flight request, which must not be mistaken
|
|
782
|
-
* for a terminal model failure: the stage would advance a candidate and become
|
|
783
|
-
* unrecoverable by resume.
|
|
784
|
-
*/
|
|
785
|
-
private async continueWithPauseResume(
|
|
786
|
-
continuationSession: RetryableAgentSession,
|
|
787
|
-
): Promise<{ readonly kind: "continued" } | { readonly kind: "paused"; readonly message?: string }> {
|
|
788
|
-
const settlePause = async (resume: RetryPauseResume): Promise<{ kind: "paused"; message?: string }> => {
|
|
789
|
-
const resumed = await resume;
|
|
790
|
-
await resumed.runnerOwnedDeliverySettlement;
|
|
791
|
-
return { kind: "paused", ...(resumed.message === undefined ? {} : { message: resumed.message }) };
|
|
792
|
-
};
|
|
793
|
-
const pauseBeforeContinue = this.pauseControl.currentResume();
|
|
794
|
-
if (pauseBeforeContinue !== undefined) return settlePause(pauseBeforeContinue);
|
|
795
|
-
|
|
796
|
-
const state: ThrownErrorRetryState = { controller: new AbortController() };
|
|
797
|
-
this.thrownErrorRetryStates.add(state);
|
|
798
|
-
try {
|
|
799
|
-
await continuationSession._runAgentContinue();
|
|
800
|
-
} catch (error) {
|
|
801
|
-
const resume = state.pauseResume ?? this.pauseControl.currentResume();
|
|
802
|
-
if (resume === undefined) throw error;
|
|
803
|
-
return settlePause(resume);
|
|
804
|
-
} finally {
|
|
805
|
-
this.thrownErrorRetryStates.delete(state);
|
|
806
|
-
}
|
|
807
|
-
const pauseAfterContinue = state.pauseResume ?? this.pauseControl.currentResume();
|
|
808
|
-
if (pauseAfterContinue !== undefined) return settlePause(pauseAfterContinue);
|
|
809
|
-
return { kind: "continued" };
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
private async promptWithThrownErrorRetry(
|
|
813
|
-
activeSession: StageSessionRuntime,
|
|
814
|
-
text: string,
|
|
815
|
-
sdkOptions: PromptOptions | undefined,
|
|
816
|
-
): Promise<{ readonly terminalScanStartIndex: number }> {
|
|
817
|
-
let retryAttempt = 0;
|
|
818
|
-
let nextText = text;
|
|
819
|
-
let retryAdmittedPrompt = false;
|
|
820
|
-
let retainedPrompt: StageSessionRuntime["messages"][number] | undefined;
|
|
821
|
-
let terminalScanStartIndex: number | undefined;
|
|
822
|
-
while (true) {
|
|
823
|
-
const messagesBeforeAttempt = [...activeSession.messages];
|
|
824
|
-
try {
|
|
825
|
-
if (retryAdmittedPrompt) {
|
|
826
|
-
const continuationSession = retryableAgentSession(activeSession);
|
|
827
|
-
if (continuationSession !== undefined) {
|
|
828
|
-
const outcome = await this.continueWithPauseResume(continuationSession);
|
|
829
|
-
if (outcome.kind === "continued") {
|
|
830
|
-
return {
|
|
831
|
-
terminalScanStartIndex:
|
|
832
|
-
terminalScanStartIndex ?? this.lastPromptStartIndex ?? messagesBeforeAttempt.length,
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
// A controlled pause interrupted the continuation. The resumed
|
|
836
|
-
// objective owns the turn from here, so re-prompt with it rather
|
|
837
|
-
// than resuming a turn the operator replaced.
|
|
838
|
-
this.dropRetainedPrompt(activeSession, retainedPrompt);
|
|
839
|
-
retainedPrompt = undefined;
|
|
840
|
-
retryAdmittedPrompt = false;
|
|
841
|
-
retryAttempt = 0;
|
|
842
|
-
terminalScanStartIndex = undefined;
|
|
843
|
-
if (outcome.message === undefined) {
|
|
844
|
-
return { terminalScanStartIndex: activeSession.messages.length };
|
|
845
|
-
}
|
|
846
|
-
nextText = outcome.message;
|
|
847
|
-
continue;
|
|
848
|
-
}
|
|
849
|
-
// No continuation is possible after all, so the retained prompt
|
|
850
|
-
// must not survive into the re-prompt below.
|
|
851
|
-
this.dropRetainedPrompt(activeSession, retainedPrompt);
|
|
852
|
-
retainedPrompt = undefined;
|
|
853
|
-
retryAdmittedPrompt = false;
|
|
854
|
-
}
|
|
855
|
-
const result = await this.promptWithPauseResume(activeSession, nextText, sdkOptions);
|
|
856
|
-
return {
|
|
857
|
-
terminalScanStartIndex: terminalScanStartIndex ?? result.terminalScanStartIndex,
|
|
858
|
-
};
|
|
859
|
-
} catch (error) {
|
|
860
|
-
const errorSettingsManager = retrySettingsManagerFromError(error);
|
|
861
|
-
if (errorSettingsManager !== undefined) this.sessionSettingsManager = errorSettingsManager;
|
|
862
|
-
// An already-unresolved context overflow is terminal for this model:
|
|
863
|
-
// compaction has run and failed, so another identical request cannot
|
|
864
|
-
// help. It stays fallbackable so `handleCandidateFailure()` advances.
|
|
865
|
-
// Same-model retry eligibility is narrower than fallback eligibility:
|
|
866
|
-
// auth, model-unavailable, and request-incompatible failures advance
|
|
867
|
-
// to the next candidate immediately instead of burning the retry
|
|
868
|
-
// budget on a request the same model has already rejected.
|
|
869
|
-
const retryableFailure = isRetryableModelFailure(error);
|
|
870
|
-
const sameCandidateRetryable =
|
|
871
|
-
isRetryableSameModelFailure(error) && !isUnresolvedContextOverflowFailure(error);
|
|
872
|
-
const decision = nextRetryDecision(this.retrySettings(), retryAttempt, sameCandidateRetryable);
|
|
873
|
-
const continuationSession = retryableAgentSession(activeSession);
|
|
874
|
-
const admittedMessages = activeSession.messages.length > messagesBeforeAttempt.length;
|
|
875
|
-
const willRetry =
|
|
876
|
-
decision !== undefined &&
|
|
877
|
-
!this.disposed &&
|
|
878
|
-
this.opts.signal?.aborted !== true &&
|
|
879
|
-
!this.capturedStructuredOutputForAttempt();
|
|
880
|
-
// The continuation path resumes the same turn, so it needs the
|
|
881
|
-
// admitted prompt to stay; the re-prompt path re-sends it.
|
|
882
|
-
const willContinue = continuationSession !== undefined && admittedMessages;
|
|
883
|
-
if (retryableFailure && willRetry) {
|
|
884
|
-
retainedPrompt =
|
|
885
|
-
this.restoreSessionMessages(activeSession, messagesBeforeAttempt, nextText, willContinue) ??
|
|
886
|
-
retainedPrompt;
|
|
887
|
-
}
|
|
888
|
-
if (!willRetry) throw error;
|
|
889
|
-
terminalScanStartIndex ??= this.lastPromptStartIndex ?? messagesBeforeAttempt.length;
|
|
890
|
-
retryAttempt = decision.attempt;
|
|
891
|
-
const state: ThrownErrorRetryState = { controller: new AbortController() };
|
|
892
|
-
let pauseResume: RetryPauseResume | undefined;
|
|
893
|
-
try {
|
|
894
|
-
await this.sleepForThrownErrorRetry(decision.delayMs, state);
|
|
895
|
-
} catch (sleepError) {
|
|
896
|
-
if (sleepError instanceof ThrownErrorRetryPaused) pauseResume = sleepError.resume;
|
|
897
|
-
else {
|
|
898
|
-
if (this.opts.signal?.aborted) throw this.workflowAbortReason();
|
|
899
|
-
if (this.disposed)
|
|
900
|
-
throw new Error(`atomic-workflows: stage "${this.opts.stageName}" session has been disposed`);
|
|
901
|
-
throw sleepError;
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
if (pauseResume !== undefined) {
|
|
905
|
-
const resumed = await pauseResume;
|
|
906
|
-
retryAttempt = 0;
|
|
907
|
-
retryAdmittedPrompt = false;
|
|
908
|
-
terminalScanStartIndex = undefined;
|
|
909
|
-
// A resumed prompt re-sends its text, so the retained input would
|
|
910
|
-
// otherwise be duplicated.
|
|
911
|
-
this.dropRetainedPrompt(activeSession, retainedPrompt);
|
|
912
|
-
retainedPrompt = undefined;
|
|
913
|
-
if (resumed.message === undefined) {
|
|
914
|
-
return { terminalScanStartIndex: activeSession.messages.length };
|
|
915
|
-
}
|
|
916
|
-
nextText = resumed.message;
|
|
917
|
-
continue;
|
|
918
|
-
}
|
|
919
|
-
if (this.disposed)
|
|
920
|
-
throw new Error(`atomic-workflows: stage "${this.opts.stageName}" session has been disposed`);
|
|
921
|
-
if (this.opts.signal?.aborted) throw this.workflowAbortReason();
|
|
922
|
-
// Only resume the existing turn when the restored transcript still
|
|
923
|
-
// satisfies pi-agent-core's continuation contract. A retained
|
|
924
|
-
// non-error assistant tail would otherwise be rejected, so fall back
|
|
925
|
-
// to re-prompting and drop the input that path re-sends.
|
|
926
|
-
retryAdmittedPrompt = willContinue && canContinueFromTranscript(activeSession);
|
|
927
|
-
if (!retryAdmittedPrompt) {
|
|
928
|
-
this.dropRetainedPrompt(activeSession, retainedPrompt);
|
|
929
|
-
retainedPrompt = undefined;
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
private workflowAbortReason(): Error | DOMException | string {
|
|
936
|
-
const reason = this.opts.signal?.reason;
|
|
937
|
-
if (reason instanceof Error || reason instanceof DOMException || typeof reason === "string") return reason;
|
|
938
|
-
return new DOMException("workflow killed", "AbortError");
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
private staleCreationReason(startGeneration: number): Error | DOMException | string {
|
|
942
|
-
if (this.opts.signal?.aborted) return this.workflowAbortReason();
|
|
943
|
-
if (this.abortReasonGeneration > startGeneration && this.abortReason !== undefined) return this.abortReason;
|
|
944
|
-
return new DOMException("stage aborted", "AbortError");
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
private modelCandidates(): Promise<WorkflowResolvedModelCandidate[]> {
|
|
948
|
-
if (!this.candidatesPromise) {
|
|
949
|
-
this.candidatesPromise = buildModelCandidatesFromCatalog({
|
|
950
|
-
primaryModel: this.effectiveStageOptions?.model,
|
|
951
|
-
fallbackModels: this.effectiveStageOptions?.fallbackModels,
|
|
952
|
-
fallbackThinkingLevels: this.effectiveStageOptions?.fallbackThinkingLevels,
|
|
953
|
-
catalog: this.modelCatalog,
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
return this.candidatesPromise;
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
private async createInitialSession(consumer: AgentSessionConsumer): Promise<StageSessionRuntime> {
|
|
960
|
-
if (!this.hasExplicitModelFallbackConfig) {
|
|
961
|
-
return this.createSessionObservingPause(undefined, consumer).catch((error) =>
|
|
962
|
-
this.createInitialSessionWithRetry(undefined, consumer, { error }),
|
|
963
|
-
);
|
|
964
|
-
}
|
|
965
|
-
const candidates = await this.modelCandidates();
|
|
966
|
-
const first = candidates[0];
|
|
967
|
-
if (first === undefined) {
|
|
968
|
-
return this.createSessionObservingPause(undefined, consumer).catch((error) =>
|
|
969
|
-
this.createInitialSessionWithRetry(undefined, consumer, { error }),
|
|
970
|
-
);
|
|
971
|
-
}
|
|
972
|
-
if (this.reattachSessionFile !== undefined) {
|
|
973
|
-
const resumed = await this.createSession(undefined, consumer, { restoreSavedModel: true });
|
|
974
|
-
const restoredId = workflowModelId(resumed.model);
|
|
975
|
-
const restoredIndex = restoredId === undefined ? -1 : candidates.findIndex((entry) => entry.id === restoredId);
|
|
976
|
-
this.activeCandidateIndex = restoredIndex >= 0 ? restoredIndex : undefined;
|
|
977
|
-
this.selectedModel = restoredId ?? first.id;
|
|
978
|
-
this.resumeCurrentSession = true;
|
|
979
|
-
return resumed;
|
|
980
|
-
}
|
|
981
|
-
this.activeCandidateIndex = 0;
|
|
982
|
-
this.selectedModel = first.id;
|
|
983
|
-
return this.createSessionObservingPause(first, consumer).catch((error) =>
|
|
984
|
-
this.createInitialSessionCandidateWalk(candidates, consumer, 0, { error }),
|
|
985
|
-
);
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
/**
|
|
989
|
-
* Creation-only version of the prompt candidate walk.
|
|
990
|
-
*
|
|
991
|
-
* An eagerly created session (`ctx.__ensureSession()`, an eager stage call, a
|
|
992
|
-
* control attach) has no prompt to drive `promptWithFallback()`, so without
|
|
993
|
-
* this a candidate whose creation keeps failing would exhaust its retries and
|
|
994
|
-
* throw while the configured fallbacks were never tried.
|
|
995
|
-
*/
|
|
996
|
-
private async createInitialSessionCandidateWalk(
|
|
997
|
-
candidates: readonly WorkflowResolvedModelCandidate[],
|
|
998
|
-
consumer: AgentSessionConsumer,
|
|
999
|
-
startIndex: number,
|
|
1000
|
-
initialFailure: { readonly error: unknown } | undefined,
|
|
1001
|
-
): Promise<StageSessionRuntime> {
|
|
1002
|
-
let index = startIndex;
|
|
1003
|
-
let pendingFailure = initialFailure;
|
|
1004
|
-
let lastError: unknown = initialFailure?.error;
|
|
1005
|
-
while (index < candidates.length) {
|
|
1006
|
-
const candidate = candidates[index]!;
|
|
1007
|
-
this.activeCandidateIndex = index;
|
|
1008
|
-
this.selectedModel = candidate.id;
|
|
1009
|
-
try {
|
|
1010
|
-
const created = await this.createSessionWithThrownErrorRetry(candidate, consumer, pendingFailure);
|
|
1011
|
-
pendingFailure = undefined;
|
|
1012
|
-
if (!isSessionCreationPauseResult(created)) {
|
|
1013
|
-
this.notifyModelFallbackMetaChange();
|
|
1014
|
-
return created;
|
|
1015
|
-
}
|
|
1016
|
-
if (created.resumeMessage === undefined) {
|
|
1017
|
-
// A pause without a replacement objective cancels this pending
|
|
1018
|
-
// creation. Let the next prompt start a fresh creation attempt.
|
|
1019
|
-
this.pendingCreationResumeMessage = undefined;
|
|
1020
|
-
this.sessionPromise = undefined;
|
|
1021
|
-
throw new StageSessionCreationCancelled();
|
|
1022
|
-
}
|
|
1023
|
-
// The replacement objective belongs to the next prompt; this
|
|
1024
|
-
// candidate is still the one being created.
|
|
1025
|
-
this.pendingCreationResumeMessage = created.resumeMessage;
|
|
1026
|
-
} catch (error) {
|
|
1027
|
-
if (error instanceof StageSessionCreationCancelled) throw error;
|
|
1028
|
-
pendingFailure = undefined;
|
|
1029
|
-
lastError = error;
|
|
1030
|
-
if ((await this.handleCandidateFailure(error, candidate, candidates, index)) !== "retry") throw error;
|
|
1031
|
-
index += 1;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
throw lastError ?? new Error(`atomic-workflows: stage "${this.opts.stageName}" has no usable model candidate`);
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
private async createInitialSessionWithRetry(
|
|
1038
|
-
candidate: WorkflowResolvedModelCandidate | undefined,
|
|
1039
|
-
consumer: AgentSessionConsumer,
|
|
1040
|
-
initialFailure?: { readonly error: unknown },
|
|
1041
|
-
): Promise<StageSessionRuntime> {
|
|
1042
|
-
let pendingFailure = initialFailure;
|
|
1043
|
-
while (true) {
|
|
1044
|
-
const created = await this.createSessionWithThrownErrorRetry(candidate, consumer, pendingFailure);
|
|
1045
|
-
pendingFailure = undefined;
|
|
1046
|
-
if (!isSessionCreationPauseResult(created)) return created;
|
|
1047
|
-
if (created.resumeMessage === undefined) {
|
|
1048
|
-
// A pause without a replacement objective cancels this pending
|
|
1049
|
-
// creation. Let the next prompt start a fresh creation attempt.
|
|
1050
|
-
this.pendingCreationResumeMessage = undefined;
|
|
1051
|
-
this.sessionPromise = undefined;
|
|
1052
|
-
throw new StageSessionCreationCancelled();
|
|
1053
|
-
}
|
|
1054
|
-
this.pendingCreationResumeMessage = created.resumeMessage;
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
/**
|
|
1059
|
-
* Latch a paused creation's replacement objective for the next prompt.
|
|
1060
|
-
*
|
|
1061
|
-
* The created session is already attached, so the pause cannot cancel it
|
|
1062
|
-
* without leaking it; the replacement text becomes the next prompt's input.
|
|
1063
|
-
*/
|
|
1064
|
-
private latchCreationResume(resume: RetryPauseResume): void {
|
|
1065
|
-
void resume
|
|
1066
|
-
.then(async (resolved) => {
|
|
1067
|
-
await resolved.runnerOwnedDeliverySettlement;
|
|
1068
|
-
if (resolved.message !== undefined) this.pendingCreationResumeMessage = resolved.message;
|
|
1069
|
-
})
|
|
1070
|
-
.catch(() => {});
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
/**
|
|
1074
|
-
* Create while a controlled pause can still be observed.
|
|
1075
|
-
*
|
|
1076
|
-
* `requestPause()` latches its resume into every registered creation observer,
|
|
1077
|
-
* so a pause that both starts and finishes while the adapter is still in
|
|
1078
|
-
* flight is caught. Checking `currentResume()` after the await would miss it,
|
|
1079
|
-
* because completing a resume clears the pause request.
|
|
1080
|
-
*
|
|
1081
|
-
* The creation promise is returned untouched, and observers are kept out of
|
|
1082
|
-
* the thrown-retry set: this must add no microtask hop and must not alter
|
|
1083
|
-
* abort or backoff semantics. An attached stream stays observable in the
|
|
1084
|
-
* caller's own turn.
|
|
1085
|
-
*/
|
|
1086
|
-
private createSessionObservingPause(
|
|
1087
|
-
candidate: WorkflowResolvedModelCandidate | undefined,
|
|
1088
|
-
consumer: AgentSessionConsumer,
|
|
1089
|
-
): Promise<StageSessionRuntime> {
|
|
1090
|
-
const activePause = this.pauseControl.currentResume();
|
|
1091
|
-
const observer: CreationPauseObserver = { pauseResume: activePause };
|
|
1092
|
-
if (activePause !== undefined) this.latchCreationResume(activePause);
|
|
1093
|
-
this.creationPauseObservers.add(observer);
|
|
1094
|
-
const creation = this.createSession(candidate, consumer);
|
|
1095
|
-
const settle = (): void => {
|
|
1096
|
-
this.creationPauseObservers.delete(observer);
|
|
1097
|
-
};
|
|
1098
|
-
creation.then(settle, settle);
|
|
1099
|
-
return creation;
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
private async createSessionWithThrownErrorRetry(
|
|
1103
|
-
candidate: WorkflowResolvedModelCandidate | undefined,
|
|
1104
|
-
consumer: AgentSessionConsumer,
|
|
1105
|
-
initialFailure?: { readonly error: unknown },
|
|
1106
|
-
): Promise<StageSessionRuntime | SessionCreationPauseResult> {
|
|
1107
|
-
let retryAttempt = 0;
|
|
1108
|
-
let pendingFailure = initialFailure;
|
|
1109
|
-
while (true) {
|
|
1110
|
-
try {
|
|
1111
|
-
if (pendingFailure !== undefined) {
|
|
1112
|
-
const failure = pendingFailure;
|
|
1113
|
-
pendingFailure = undefined;
|
|
1114
|
-
throw failure.error;
|
|
1115
|
-
}
|
|
1116
|
-
return await this.createSessionObservingPause(candidate, consumer);
|
|
1117
|
-
} catch (error) {
|
|
1118
|
-
const errorSettingsManager = retrySettingsManagerFromError(error);
|
|
1119
|
-
if (errorSettingsManager !== undefined) this.sessionSettingsManager = errorSettingsManager;
|
|
1120
|
-
const decision = nextRetryDecision(this.retrySettings(), retryAttempt, isRetryableSameModelFailure(error));
|
|
1121
|
-
if (
|
|
1122
|
-
decision === undefined ||
|
|
1123
|
-
this.disposed ||
|
|
1124
|
-
this.opts.signal?.aborted === true ||
|
|
1125
|
-
this.capturedStructuredOutputForAttempt()
|
|
1126
|
-
) {
|
|
1127
|
-
throw error;
|
|
1128
|
-
}
|
|
1129
|
-
retryAttempt = decision.attempt;
|
|
1130
|
-
const state: ThrownErrorRetryState = { controller: new AbortController() };
|
|
1131
|
-
try {
|
|
1132
|
-
await this.sleepForThrownErrorRetry(decision.delayMs, state);
|
|
1133
|
-
} catch (sleepError) {
|
|
1134
|
-
if (sleepError instanceof ThrownErrorRetryPaused) {
|
|
1135
|
-
const resumed = await sleepError.resume;
|
|
1136
|
-
return {
|
|
1137
|
-
kind: "paused",
|
|
1138
|
-
...(resumed.message === undefined ? {} : { resumeMessage: resumed.message }),
|
|
1139
|
-
};
|
|
1140
|
-
}
|
|
1141
|
-
if (this.opts.signal?.aborted) throw this.workflowAbortReason();
|
|
1142
|
-
if (this.disposed)
|
|
1143
|
-
throw new Error(`atomic-workflows: stage "${this.opts.stageName}" session has been disposed`);
|
|
1144
|
-
throw sleepError;
|
|
1145
|
-
}
|
|
1146
|
-
if (this.disposed)
|
|
1147
|
-
throw new Error(`atomic-workflows: stage "${this.opts.stageName}" session has been disposed`);
|
|
1148
|
-
if (this.opts.signal?.aborted) throw this.workflowAbortReason();
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
private createSession(
|
|
1154
|
-
candidate: WorkflowResolvedModelCandidate | undefined,
|
|
1155
|
-
consumer: AgentSessionConsumer,
|
|
1156
|
-
resumeOptions?: { restoreSavedModel?: boolean },
|
|
1157
|
-
): Promise<StageSessionRuntime> {
|
|
1158
|
-
const creation = this.createSessionAttempt(candidate, consumer, resumeOptions);
|
|
1159
|
-
this.activeCreation = creation;
|
|
1160
|
-
void creation
|
|
1161
|
-
.finally(() => {
|
|
1162
|
-
if (this.activeCreation === creation) this.activeCreation = undefined;
|
|
1163
|
-
})
|
|
1164
|
-
.catch(() => {});
|
|
1165
|
-
return creation;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
private async createSessionAttempt(
|
|
1169
|
-
candidate: WorkflowResolvedModelCandidate | undefined,
|
|
1170
|
-
consumer: AgentSessionConsumer,
|
|
1171
|
-
resumeOptions?: { restoreSavedModel?: boolean },
|
|
1172
|
-
): Promise<StageSessionRuntime> {
|
|
1173
|
-
const startGeneration = this.abortGeneration;
|
|
1174
|
-
this.applyCandidateThinking(candidate);
|
|
1175
|
-
const stageOptions = buildStageSessionOptions({
|
|
1176
|
-
effectiveStageOptions: this.effectiveStageOptions,
|
|
1177
|
-
candidate,
|
|
1178
|
-
restoreSavedModel: resumeOptions?.restoreSavedModel,
|
|
1179
|
-
reattachSessionFile: this.reattachSessionFile,
|
|
1180
|
-
sharedModelRuntime: this.sharedModelRuntime,
|
|
1181
|
-
});
|
|
1182
|
-
let created: StageSessionRuntime | StageSessionCreateResult;
|
|
1183
|
-
try {
|
|
1184
|
-
created = this.opts.adapters.agentSession
|
|
1185
|
-
? await this.opts.adapters.agentSession.create(
|
|
1186
|
-
stripWorkflowOnlyOptions(
|
|
1187
|
-
stageOptions,
|
|
1188
|
-
this.opts.defaultSessionDir,
|
|
1189
|
-
this.meta,
|
|
1190
|
-
) as StageSessionCreateOptions,
|
|
1191
|
-
{
|
|
1192
|
-
...this.meta,
|
|
1193
|
-
stageOptions,
|
|
1194
|
-
...(this.sharedOrchestrationContext !== undefined
|
|
1195
|
-
? { orchestrationContext: this.sharedOrchestrationContext }
|
|
1196
|
-
: {}),
|
|
1197
|
-
},
|
|
1198
|
-
)
|
|
1199
|
-
: missingAdapter(consumer);
|
|
1200
|
-
} catch (error) {
|
|
1201
|
-
if (this.disposed || this.opts.signal?.aborted === true || this.abortGeneration !== startGeneration)
|
|
1202
|
-
throw this.disposed
|
|
1203
|
-
? new Error(`atomic-workflows: stage "${this.opts.stageName}" session has been disposed`)
|
|
1204
|
-
: this.staleCreationReason(startGeneration);
|
|
1205
|
-
throw error;
|
|
1206
|
-
}
|
|
1207
|
-
if (this.disposed || this.opts.signal?.aborted === true || this.abortGeneration !== startGeneration) {
|
|
1208
|
-
await disposeStageSession(normalizeSessionCreateResult(created).session).catch(() => {});
|
|
1209
|
-
if (this.disposed)
|
|
1210
|
-
throw new Error(`atomic-workflows: stage "${this.opts.stageName}" session has been disposed`);
|
|
1211
|
-
throw this.staleCreationReason(startGeneration);
|
|
1212
|
-
}
|
|
1213
|
-
const session = attachCreatedStageSession(created, this.disposed, this.opts.stageName, (result) =>
|
|
1214
|
-
this.attachSession(result),
|
|
1215
|
-
);
|
|
1216
|
-
if (session instanceof Promise) return await session;
|
|
1217
|
-
await this.opts.onSessionReady?.();
|
|
1218
|
-
return session;
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
private attachSession(created: StageSessionRuntime | StageSessionCreateResult): StageSessionRuntime {
|
|
1222
|
-
const result = normalizeSessionCreateResult(created);
|
|
1223
|
-
const orchestrationContext = asAgentSession(result.session)?.orchestrationContext;
|
|
1224
|
-
if (this.sharedOrchestrationContext === undefined && orchestrationContext !== undefined) {
|
|
1225
|
-
this.sharedOrchestrationContext = orchestrationContext;
|
|
1226
|
-
}
|
|
1227
|
-
if (this.generationSealed) result.session.sealWorkflowStageGeneration?.();
|
|
1228
|
-
this.replacement.adopt(result.session);
|
|
1229
|
-
this.session = result.session;
|
|
1230
|
-
if (this.sharedModelRuntime === undefined) {
|
|
1231
|
-
const withRegistry = result.session as Partial<Pick<AgentSession, "modelRuntime">>;
|
|
1232
|
-
if (withRegistry.modelRuntime !== undefined) this.sharedModelRuntime = withRegistry.modelRuntime;
|
|
1233
|
-
}
|
|
1234
|
-
this.sessionSettingsManager = result.settingsManager ?? result.session.settingsManager;
|
|
1235
|
-
if (this.pendingThinkingLevel !== undefined) result.session.setThinkingLevel(this.pendingThinkingLevel);
|
|
1236
|
-
for (const listener of this.pendingListeners) {
|
|
1237
|
-
this.listenerUnsubscribes.set(listener, result.session.subscribe(listener));
|
|
1238
|
-
}
|
|
1239
|
-
// The session may already hold a queue — transferred from the session it
|
|
1240
|
-
// just replaced, or restored with it — and it published that queue while
|
|
1241
|
-
// these listeners were bound to nothing. Replay the one snapshot they
|
|
1242
|
-
// missed, so a handle's projection and any mounted chat start from the
|
|
1243
|
-
// session's real pending state rather than from empty.
|
|
1244
|
-
const missedQueueUpdate = stageSessionQueueUpdateEvent(result.session);
|
|
1245
|
-
if (missedQueueUpdate !== undefined) {
|
|
1246
|
-
for (const listener of this.pendingListeners) listener(missedQueueUpdate);
|
|
1247
|
-
}
|
|
1248
|
-
this.unsubscribeTerminateWatcher?.();
|
|
1249
|
-
this.unsubscribeTerminateWatcher = result.session.subscribe((event) => {
|
|
1250
|
-
const terminatingId = terminatingToolCallId(event);
|
|
1251
|
-
if (terminatingId !== undefined) this.terminatingToolCallIds.add(terminatingId);
|
|
1252
|
-
this.unresolvedContextOverflowMessage =
|
|
1253
|
-
unresolvedContextOverflowMessage(event) ?? this.unresolvedContextOverflowMessage;
|
|
1254
|
-
this.latestStructuredOutputToolErrorValue =
|
|
1255
|
-
structuredOutputToolErrorFromEvent(event) ?? this.latestStructuredOutputToolErrorValue;
|
|
1256
|
-
});
|
|
1257
|
-
return result.session;
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
private async disposeCurrentSession(): Promise<void> {
|
|
1261
|
-
this.abortThrownErrorRetries(new Error(`atomic-workflows: stage "${this.opts.stageName}" session was replaced`));
|
|
1262
|
-
const current = this.session;
|
|
1263
|
-
this.messageAdmission.reset();
|
|
1264
|
-
this.replacement.retire(current);
|
|
1265
|
-
this.session = undefined;
|
|
1266
|
-
// A candidate walk still advancing owns the shared creation promise: clearing
|
|
1267
|
-
// it here would let a concurrent caller start a second walk, duplicating
|
|
1268
|
-
// provider work and leaking whichever session lost the race.
|
|
1269
|
-
if (this.sessionPromise !== this.ownedCreationPromise) this.sessionPromise = undefined;
|
|
1270
|
-
this.sessionSettingsManager = undefined;
|
|
1271
|
-
this.resumeCurrentSession = false;
|
|
1272
|
-
for (const unsubscribe of this.listenerUnsubscribes.values()) unsubscribe();
|
|
1273
|
-
this.listenerUnsubscribes.clear();
|
|
1274
|
-
this.unsubscribeTerminateWatcher?.();
|
|
1275
|
-
this.unsubscribeTerminateWatcher = undefined;
|
|
1276
|
-
this.terminatingToolCallIds.clear();
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
private async promptWithPauseResume(
|
|
1280
|
-
activeSession: StageSessionRuntime,
|
|
1281
|
-
initialText: string,
|
|
1282
|
-
sdkOptions: PromptOptions | undefined,
|
|
1283
|
-
): Promise<{ readonly terminalScanStartIndex: number }> {
|
|
1284
|
-
let nextText: string | undefined = initialText;
|
|
1285
|
-
while (nextText !== undefined) {
|
|
1286
|
-
const pendingPauseBeforePrompt = this.pauseControl.currentResume();
|
|
1287
|
-
if (pendingPauseBeforePrompt) {
|
|
1288
|
-
const resumed = await pendingPauseBeforePrompt;
|
|
1289
|
-
await resumed.runnerOwnedDeliverySettlement;
|
|
1290
|
-
nextText = resumed.message;
|
|
1291
|
-
if (nextText === undefined) return { terminalScanStartIndex: activeSession.messages.length };
|
|
1292
|
-
continue;
|
|
1293
|
-
}
|
|
1294
|
-
const promptStartIndex = activeSession.messages.length;
|
|
1295
|
-
this.lastPromptStartIndex = promptStartIndex;
|
|
1296
|
-
this.unresolvedContextOverflowMessage = undefined;
|
|
1297
|
-
try {
|
|
1298
|
-
await activeSession.prompt(nextText, sdkOptions);
|
|
1299
|
-
const pendingPauseAfterPrompt = this.pauseControl.currentResume();
|
|
1300
|
-
if (pendingPauseAfterPrompt) {
|
|
1301
|
-
const resumed = await pendingPauseAfterPrompt;
|
|
1302
|
-
await resumed.runnerOwnedDeliverySettlement;
|
|
1303
|
-
this.throwUnresolvedContextOverflowIfPresent();
|
|
1304
|
-
nextText = resumed.message;
|
|
1305
|
-
if (nextText === undefined) return { terminalScanStartIndex: activeSession.messages.length };
|
|
1306
|
-
continue;
|
|
1307
|
-
}
|
|
1308
|
-
this.throwUnresolvedContextOverflowIfPresent();
|
|
1309
|
-
return { terminalScanStartIndex: promptStartIndex };
|
|
1310
|
-
} catch (err) {
|
|
1311
|
-
const pendingPauseAfterThrow = this.pauseControl.currentResume();
|
|
1312
|
-
if (pendingPauseAfterThrow) {
|
|
1313
|
-
const resumed = await pendingPauseAfterThrow;
|
|
1314
|
-
await resumed.runnerOwnedDeliverySettlement;
|
|
1315
|
-
this.throwUnresolvedContextOverflowIfPresent();
|
|
1316
|
-
nextText = resumed.message;
|
|
1317
|
-
if (nextText === undefined) return { terminalScanStartIndex: activeSession.messages.length };
|
|
1318
|
-
continue;
|
|
1319
|
-
}
|
|
1320
|
-
this.throwUnresolvedContextOverflowIfPresent();
|
|
1321
|
-
throw err;
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
return { terminalScanStartIndex: activeSession.messages.length };
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
private async tryResumeCurrentSession(
|
|
1328
|
-
text: string,
|
|
1329
|
-
sdkOptions: PromptOptions | undefined,
|
|
1330
|
-
candidates: readonly WorkflowResolvedModelCandidate[],
|
|
1331
|
-
): Promise<boolean> {
|
|
1332
|
-
if (!this.resumeCurrentSession || this.session === undefined) return false;
|
|
1333
|
-
this.resumeCurrentSession = false;
|
|
1334
|
-
const resumedSession = this.session;
|
|
1335
|
-
const resumedLabel = this.selectedModel ?? workflowModelId(resumedSession.model) ?? candidates[0]!.id;
|
|
1336
|
-
this.notifyModelFallbackMetaChange();
|
|
1337
|
-
this.beginAttemptUsage(resumedSession);
|
|
1338
|
-
try {
|
|
1339
|
-
const { terminalScanStartIndex } = await this.promptWithThrownErrorRetry(resumedSession, text, sdkOptions);
|
|
1340
|
-
const terminalFailure = latestTerminalAssistantFailureSince(resumedSession.messages, terminalScanStartIndex);
|
|
1341
|
-
if (terminalFailure === undefined || this.capturedStructuredOutputForAttempt()) {
|
|
1342
|
-
const usage = this.takeAttemptUsage(resumedSession);
|
|
1343
|
-
this.modelAttempts.push({
|
|
1344
|
-
model: resumedLabel,
|
|
1345
|
-
success: true,
|
|
1346
|
-
...(usage === undefined ? {} : { usage }),
|
|
1347
|
-
});
|
|
1348
|
-
this.pendingFallbackWarnings.length = 0;
|
|
1349
|
-
this.resumeCurrentSession = true;
|
|
1350
|
-
return true;
|
|
1351
|
-
}
|
|
1352
|
-
throw new WorkflowPromptModelFailure(terminalFailure);
|
|
1353
|
-
} catch (err) {
|
|
1354
|
-
if (this.capturedStructuredOutputForAttempt() && isRetryableModelFailure(err)) {
|
|
1355
|
-
const usage = this.takeAttemptUsage(resumedSession);
|
|
1356
|
-
this.modelAttempts.push({
|
|
1357
|
-
model: resumedLabel,
|
|
1358
|
-
success: true,
|
|
1359
|
-
...(usage === undefined ? {} : { usage }),
|
|
1360
|
-
});
|
|
1361
|
-
this.pendingFallbackWarnings.length = 0;
|
|
1362
|
-
this.resumeCurrentSession = true;
|
|
1363
|
-
return true;
|
|
1364
|
-
}
|
|
1365
|
-
const message = errorMessage(err);
|
|
1366
|
-
const usage = this.takeAttemptUsage(resumedSession);
|
|
1367
|
-
this.modelAttempts.push({
|
|
1368
|
-
model: resumedLabel,
|
|
1369
|
-
success: false,
|
|
1370
|
-
...(usage === undefined ? {} : { usage }),
|
|
1371
|
-
error: message,
|
|
1372
|
-
});
|
|
1373
|
-
if (this.opts.signal?.aborted || !isRetryableModelFailure(err)) {
|
|
1374
|
-
this.modelWarnings.push(...this.pendingFallbackWarnings);
|
|
1375
|
-
this.pendingFallbackWarnings.length = 0;
|
|
1376
|
-
this.notifyModelFallbackMetaChange();
|
|
1377
|
-
throw err;
|
|
1378
|
-
}
|
|
1379
|
-
const resumedOverflowNextIndex = nextResumedContextOverflowFallbackIndex(
|
|
1380
|
-
err,
|
|
1381
|
-
this.activeCandidateIndex,
|
|
1382
|
-
candidates.length,
|
|
1383
|
-
);
|
|
1384
|
-
if (resumedOverflowNextIndex === "terminal") {
|
|
1385
|
-
this.modelWarnings.push(...this.pendingFallbackWarnings);
|
|
1386
|
-
this.pendingFallbackWarnings.length = 0;
|
|
1387
|
-
this.notifyModelFallbackMetaChange();
|
|
1388
|
-
throw err;
|
|
1389
|
-
}
|
|
1390
|
-
this.pendingFallbackWarnings.push(
|
|
1391
|
-
resumedOverflowNextIndex === undefined
|
|
1392
|
-
? `[fallback] resume on ${resumedLabel} failed: ${message}. Restarting fallback from ${candidateLabel(candidates[0]!)}.`
|
|
1393
|
-
: `[fallback] resume on ${resumedLabel} failed: ${message}. Retrying with ${candidateLabel(candidates[resumedOverflowNextIndex]!)}.`,
|
|
1394
|
-
);
|
|
1395
|
-
await this.disposeCurrentSession();
|
|
1396
|
-
this.activeCandidateIndex = resumedOverflowNextIndex;
|
|
1397
|
-
return false;
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
private async handleCandidateFailure(
|
|
1402
|
-
err: unknown,
|
|
1403
|
-
candidate: WorkflowResolvedModelCandidate,
|
|
1404
|
-
candidates: readonly WorkflowResolvedModelCandidate[],
|
|
1405
|
-
index: number,
|
|
1406
|
-
): Promise<"handled" | "retry" | "throw"> {
|
|
1407
|
-
const message = errorMessage(err);
|
|
1408
|
-
if (this.capturedStructuredOutputForAttempt() && isRetryableModelFailure(err)) {
|
|
1409
|
-
this.recordSuccessfulAttempt(candidate);
|
|
1410
|
-
return "handled";
|
|
1411
|
-
}
|
|
1412
|
-
const usage = this.takeAttemptUsage(this.session);
|
|
1413
|
-
this.modelAttempts.push({
|
|
1414
|
-
model: candidate.id,
|
|
1415
|
-
success: false,
|
|
1416
|
-
...modelAttemptReasoning(candidate, this.effectiveStageOptions?.thinkingLevel),
|
|
1417
|
-
...(usage === undefined ? {} : { usage }),
|
|
1418
|
-
error: message,
|
|
1419
|
-
});
|
|
1420
|
-
if (this.opts.signal?.aborted || !isRetryableModelFailure(err) || index === candidates.length - 1) {
|
|
1421
|
-
this.modelWarnings.push(...this.pendingFallbackWarnings);
|
|
1422
|
-
this.pendingFallbackWarnings.length = 0;
|
|
1423
|
-
this.notifyModelFallbackMetaChange();
|
|
1424
|
-
return "throw";
|
|
1425
|
-
}
|
|
1426
|
-
const nextCandidate = candidates[index + 1]!;
|
|
1427
|
-
this.pendingFallbackWarnings.push(
|
|
1428
|
-
`[fallback] ${candidateLabel(candidate)} failed: ${message}. Retrying with ${candidateLabel(nextCandidate)}.`,
|
|
1429
|
-
);
|
|
1430
|
-
await this.disposeCurrentSession();
|
|
1431
|
-
return "retry";
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
private capturedStructuredOutputForAttempt(): boolean {
|
|
1435
|
-
return this.structuredOutputCapture?.called === true && this.opts.signal?.aborted !== true;
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
private recordSuccessfulAttempt(candidate: WorkflowResolvedModelCandidate): void {
|
|
1439
|
-
const usage = this.takeAttemptUsage(this.session);
|
|
1440
|
-
this.modelAttempts.push({
|
|
1441
|
-
model: candidate.id,
|
|
1442
|
-
success: true,
|
|
1443
|
-
...modelAttemptReasoning(candidate, this.effectiveStageOptions?.thinkingLevel),
|
|
1444
|
-
...(usage === undefined ? {} : { usage }),
|
|
1445
|
-
});
|
|
1446
|
-
this.pendingFallbackWarnings.length = 0;
|
|
1447
|
-
this.resumeCurrentSession = true;
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
private notifyModelFallbackMetaChange(): void {
|
|
1451
|
-
this.opts.onModelFallbackMetaChange?.(this.currentModelFallbackMeta());
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
private applyCandidateThinking(candidate: WorkflowResolvedModelCandidate | undefined): void {
|
|
1455
|
-
this.pendingThinkingLevel =
|
|
1456
|
-
candidate === undefined
|
|
1457
|
-
? this.effectiveStageOptions?.thinkingLevel
|
|
1458
|
-
: effectiveCandidateReasoning(candidate, this.effectiveStageOptions?.thinkingLevel);
|
|
1459
|
-
}
|
|
1460
|
-
private isWorkflowFastModeEnabled(): boolean | undefined {
|
|
1461
|
-
const model = this.session?.model;
|
|
1462
|
-
const settingsManager = this.sessionSettingsManager ?? this.effectiveStageOptions?.settingsManager;
|
|
1463
|
-
return model === undefined || settingsManager === undefined
|
|
1464
|
-
? undefined
|
|
1465
|
-
: shouldApplyCodexFastModeForScope(model, settingsManager.getCodexFastModeSettings(), "workflow");
|
|
1466
|
-
}
|
|
1467
|
-
private throwUnresolvedContextOverflowIfPresent(): void {
|
|
1468
|
-
const message = this.unresolvedContextOverflowMessage;
|
|
1469
|
-
this.unresolvedContextOverflowMessage = undefined;
|
|
1470
|
-
if (message !== undefined) throw unresolvedContextOverflowFailure(message);
|
|
1471
|
-
}
|
|
1472
|
-
}
|