saeeol 1.2.9 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-typecheck.log +1 -0
- package/AGENTS.md +72 -0
- package/BUN_SHELL_MIGRATION_PLAN.md +136 -0
- package/Dockerfile +18 -0
- package/assets/saeeol.ico +0 -0
- package/bin/saeeol.cjs +0 -0
- package/database.db +0 -0
- package/drizzle.config.ts +10 -0
- package/git +0 -0
- package/migration/20260127222353_familiar_lady_ursula/migration.sql +90 -0
- package/migration/20260127222353_familiar_lady_ursula/snapshot.json +796 -0
- package/migration/20260211171708_add_project_commands/migration.sql +1 -0
- package/migration/20260211171708_add_project_commands/snapshot.json +806 -0
- package/migration/20260213144116_wakeful_the_professor/migration.sql +11 -0
- package/migration/20260213144116_wakeful_the_professor/snapshot.json +897 -0
- package/migration/20260225215848_workspace/migration.sql +7 -0
- package/migration/20260225215848_workspace/snapshot.json +959 -0
- package/migration/20260227213759_add_session_workspace_id/migration.sql +2 -0
- package/migration/20260227213759_add_session_workspace_id/snapshot.json +983 -0
- package/migration/20260228203230_blue_harpoon/migration.sql +17 -0
- package/migration/20260228203230_blue_harpoon/snapshot.json +1102 -0
- package/migration/20260303231226_add_workspace_fields/migration.sql +5 -0
- package/migration/20260303231226_add_workspace_fields/snapshot.json +1013 -0
- package/migration/20260309230000_move_org_to_state/migration.sql +3 -0
- package/migration/20260309230000_move_org_to_state/snapshot.json +1156 -0
- package/migration/20260312043431_session_message_cursor/migration.sql +4 -0
- package/migration/20260312043431_session_message_cursor/snapshot.json +1168 -0
- package/migration/20260323234822_events/migration.sql +13 -0
- package/migration/20260323234822_events/snapshot.json +1271 -0
- package/migration/20260410174513_workspace-name/migration.sql +16 -0
- package/migration/20260410174513_workspace-name/snapshot.json +1271 -0
- package/migration/20260413175956_chief_energizer/migration.sql +13 -0
- package/migration/20260413175956_chief_energizer/snapshot.json +1399 -0
- package/migration/20260423070820_add_icon_url_override/migration.sql +2 -0
- package/migration/20260423070820_add_icon_url_override/snapshot.json +1409 -0
- package/migration/20260428004200_add_session_path/migration.sql +1 -0
- package/migration/20260428004200_add_session_path/snapshot.json +1419 -0
- package/npm/bin/saeeol +42 -0
- package/npm/package.json +39 -0
- package/npm/postinstall.js +162 -0
- package/package.json +201 -207
- package/parsers-config.ts +289 -0
- package/script/build.ts +393 -0
- package/script/check-migrations.ts +16 -0
- package/script/fix-node-pty.ts +34 -0
- package/script/generate.ts +23 -0
- package/script/postinstall.mjs +189 -0
- package/script/publish.ts +200 -0
- package/script/run-workspace-server +106 -0
- package/script/schema.ts +63 -0
- package/script/test-runner.ts +420 -0
- package/script/time.ts +6 -0
- package/script/trace-imports.ts +153 -0
- package/script/upgrade-opentui.ts +64 -0
- package/scripts/diff-sdk-types.sh +52 -0
- package/specs/effect/facades.md +221 -0
- package/specs/effect/http-api.md +401 -0
- package/specs/effect/instance-context.md +309 -0
- package/specs/effect/loose-ends.md +34 -0
- package/specs/effect/migration.md +299 -0
- package/specs/effect/routes.md +64 -0
- package/specs/effect/schema.md +399 -0
- package/specs/effect/server-package.md +668 -0
- package/specs/effect/tools.md +90 -0
- package/specs/tui-plugins.md +433 -0
- package/specs/v2/api.ts +67 -0
- package/specs/v2/keymappings.md +10 -0
- package/specs/v2/message-shape.md +136 -0
- package/src/acp/agent-message.ts +1 -1
- package/src/acp/agent-utils.ts +1 -1
- package/src/boxes/ansi.ts +17 -0
- package/src/boxes/atomic-write.ts +35 -0
- package/src/boxes/b64.ts +58 -0
- package/src/boxes/bash-security.ts +129 -0
- package/src/boxes/bom.ts +18 -0
- package/src/boxes/cancel.ts +16 -0
- package/src/boxes/chop.ts +12 -0
- package/src/boxes/clamp.ts +3 -0
- package/src/boxes/compact.ts +9 -0
- package/src/boxes/cost-tracker.ts +116 -0
- package/src/boxes/dataurl.ts +29 -0
- package/src/boxes/delay.ts +27 -0
- package/src/boxes/diff-apply.ts +53 -0
- package/src/boxes/disposable.ts +13 -0
- package/src/boxes/err.ts +34 -0
- package/src/boxes/human.ts +47 -0
- package/src/boxes/iife.ts +9 -0
- package/src/boxes/latch.ts +8 -0
- package/src/boxes/memory.ts +198 -0
- package/src/boxes/net.ts +16 -0
- package/src/boxes/plural.ts +4 -0
- package/src/boxes/puny.ts +21 -0
- package/src/boxes/retry.ts +49 -0
- package/src/boxes/rwlock.ts +41 -0
- package/src/boxes/schedule.ts +71 -0
- package/src/boxes/scope.ts +21 -0
- package/src/boxes/tokens.ts +9 -0
- package/src/boxes/ttl-cache.ts +63 -0
- package/src/boxes/typed-event.ts +51 -0
- package/src/boxes/uid.ts +50 -0
- package/src/boxes/wave6.test.ts +296 -0
- package/src/boxes/wildcard.ts +58 -0
- package/src/bus/global.ts +1 -1
- package/src/cli/cmd/github-run-api.ts +2 -2
- package/src/cli/cmd/run-events.ts +2 -2
- package/src/cli/cmd/tui/component/logo.tsx +1 -1
- package/src/cli/cmd/tui/component/prompt/use-prompt-memos.ts +2 -2
- package/src/cli/cmd/tui/context/app/editor-zed.ts +1 -1
- package/src/cli/cmd/tui/context/app/editor.ts +1 -1
- package/src/cli/cmd/tui/context/app/helper.tsx +1 -0
- package/src/cli/cmd/tui/context/app/theme.tsx +1 -0
- package/src/cli/cmd/tui/util/revert-diff.ts +1 -1
- package/src/overlay/cli/cmd/roll-call-call.ts +1 -1
- package/src/overlay/cost-tracker/format.ts +1 -1
- package/src/overlay/cost-tracker/index.ts +4 -4
- package/src/overlay/cost-tracker/state.ts +2 -2
- package/src/overlay/cost-tracker/types.ts +2 -2
- package/src/overlay/memory/age.ts +1 -1
- package/src/overlay/memory/index.ts +4 -4
- package/src/overlay/memory/paths.ts +2 -2
- package/src/overlay/memory/scan.ts +1 -1
- package/src/overlay/memory/types.ts +2 -2
- package/src/overlay/tool/bash-security.ts +3 -3
- package/src/overlay/util/url.ts +1 -1
- package/src/plugin/codex-auth.ts +1 -1
- package/src/provider/model-cache.ts +2 -2
- package/src/provider/provider-resolve.ts +3 -3
- package/src/provider/transform-message.ts +1 -1
- package/src/server/routes/game.ts +284 -0
- package/src/server/server.ts +2 -0
- package/src/session/core/compaction/compaction-helpers.ts +1 -1
- package/src/session/core/compaction/compaction.ts +1 -1
- package/src/session/core/session-events.ts +50 -8
- package/src/session/core/session.ts +2 -0
- package/src/sessions/ingest-queue.ts +2 -2
- package/src/sessions/remote-ws.ts +1 -1
- package/src/tool/workflow/question.ts +1 -1
- package/src/util/abort.ts +1 -1
- package/src/util/bom.ts +2 -2
- package/src/util/color.ts +1 -1
- package/src/util/data-url.ts +1 -1
- package/src/util/defer.ts +1 -1
- package/src/util/error.ts +2 -2
- package/src/util/filesystem.ts +2 -2
- package/src/util/format.ts +1 -1
- package/src/util/iife.ts +1 -1
- package/src/util/local-context.ts +1 -1
- package/src/util/locale.ts +2 -2
- package/src/util/lock.ts +1 -1
- package/src/util/network.ts +1 -1
- package/src/util/signal.ts +1 -1
- package/src/util/token.ts +1 -1
- package/src/util/wildcard.ts +1 -1
- package/sst-env.d.ts +10 -0
- package/test/AGENTS.md +133 -0
- package/test/account/repo.test.ts +352 -0
- package/test/account/service.test.ts +456 -0
- package/test/acp/agent-interface.test.ts +51 -0
- package/test/acp/event-subscription.test.ts +725 -0
- package/test/agent/agent.test.ts +890 -0
- package/test/auth/auth.test.ts +86 -0
- package/test/bun/registry.test.ts +75 -0
- package/test/bus/bus-effect.test.ts +161 -0
- package/test/bus/bus-integration.test.ts +87 -0
- package/test/bus/bus.test.ts +219 -0
- package/test/cli/account.test.ts +26 -0
- package/test/cli/auto-mode.test.ts +75 -0
- package/test/cli/bin-saeeol.test.ts +8 -0
- package/test/cli/cmd/tui/prompt-part.test.ts +47 -0
- package/test/cli/cmd/tui/prompt-traits.test.ts +38 -0
- package/test/cli/cmd/tui/sync.test.tsx +159 -0
- package/test/cli/error.test.ts +18 -0
- package/test/cli/github-action.test.ts +198 -0
- package/test/cli/github-remote.test.ts +85 -0
- package/test/cli/import.test.ts +97 -0
- package/test/cli/install-artifact.test.ts +72 -0
- package/test/cli/plugin-auth-picker.test.ts +120 -0
- package/test/cli/pr.test.ts +59 -0
- package/test/cli/tui/editor-context-zed.test.ts +356 -0
- package/test/cli/tui/editor-context.test.tsx +228 -0
- package/test/cli/tui/keybind-plugin.test.ts +90 -0
- package/test/cli/tui/markdown.test.ts +161 -0
- package/test/cli/tui/plugin-add.test.ts +111 -0
- package/test/cli/tui/plugin-install.test.ts +87 -0
- package/test/cli/tui/plugin-lifecycle.test.ts +224 -0
- package/test/cli/tui/plugin-loader-entrypoint.test.ts +484 -0
- package/test/cli/tui/plugin-loader-pure.test.ts +71 -0
- package/test/cli/tui/plugin-loader.test.ts +816 -0
- package/test/cli/tui/plugin-toggle.test.ts +157 -0
- package/test/cli/tui/revert-diff.test.ts +35 -0
- package/test/cli/tui/slot-replace.test.tsx +47 -0
- package/test/cli/tui/theme-store.test.ts +54 -0
- package/test/cli/tui/thread.test.ts +28 -0
- package/test/cli/tui/transcript.test.ts +426 -0
- package/test/cli/tui/usage.test.ts +60 -0
- package/test/cli/tui/use-event.test.tsx +175 -0
- package/test/config/agent-color.test.ts +67 -0
- package/test/config/config.test.ts +2544 -0
- package/test/config/fixtures/empty-frontmatter.md +4 -0
- package/test/config/fixtures/frontmatter.md +28 -0
- package/test/config/fixtures/markdown-header.md +11 -0
- package/test/config/fixtures/no-frontmatter.md +1 -0
- package/test/config/fixtures/weird-model-id.md +13 -0
- package/test/config/lsp.test.ts +87 -0
- package/test/config/markdown.test.ts +228 -0
- package/test/config/plugin.test.ts +0 -0
- package/test/config/tui.test.ts +624 -0
- package/test/control-plane/adapters.test.ts +71 -0
- package/test/control-plane/workspace.test.ts +1526 -0
- package/test/effect/app-runtime-logger.test.ts +98 -0
- package/test/effect/config-service.test.ts +65 -0
- package/test/effect/instance-state.test.ts +394 -0
- package/test/effect/run-service.test.ts +89 -0
- package/test/effect/runner.test.ts +523 -0
- package/test/fake/provider.ts +82 -0
- package/test/file/fsmonitor.test.ts +68 -0
- package/test/file/ignore.test.ts +10 -0
- package/test/file/index.test.ts +954 -0
- package/test/file/path-traversal.test.ts +205 -0
- package/test/file/ripgrep.test.ts +226 -0
- package/test/file/watcher.test.ts +249 -0
- package/test/filesystem/filesystem.test.ts +319 -0
- package/test/fixture/db.ts +11 -0
- package/test/fixture/fixture.test.ts +26 -0
- package/test/fixture/fixture.ts +175 -0
- package/test/fixture/flock-worker.ts +72 -0
- package/test/fixture/log-init-worker.ts +62 -0
- package/test/fixture/lsp/fake-lsp-server.js +249 -0
- package/test/fixture/plug-worker.ts +93 -0
- package/test/fixture/plugin-meta-worker.ts +19 -0
- package/test/fixture/skills/agents-sdk/SKILL.md +152 -0
- package/test/fixture/skills/cloudflare/SKILL.md +211 -0
- package/test/fixture/skills/index.json +6 -0
- package/test/fixture/tui-plugin.ts +323 -0
- package/test/fixture/tui-runtime.ts +31 -0
- package/test/format/format.test.ts +272 -0
- package/test/git/git.test.ts +128 -0
- package/test/ide/ide.test.ts +82 -0
- package/test/installation/installation.test.ts +168 -0
- package/test/keybind.test.ts +421 -0
- package/test/lib/effect.ts +53 -0
- package/test/lib/filesystem.ts +10 -0
- package/test/lib/llm-server.ts +778 -0
- package/test/lib/websocket.ts +46 -0
- package/test/lsp/client.test.ts +482 -0
- package/test/lsp/index.test.ts +160 -0
- package/test/lsp/launch.test.ts +22 -0
- package/test/lsp/lifecycle.test.ts +184 -0
- package/test/ltm/ltm.test.ts +230 -0
- package/test/mcp/headers.test.ts +178 -0
- package/test/mcp/lifecycle.test.ts +787 -0
- package/test/mcp/oauth-auto-connect.test.ts +311 -0
- package/test/mcp/oauth-browser.test.ts +276 -0
- package/test/mcp/oauth-callback.test.ts +34 -0
- package/test/memory/abort-leak-webfetch.ts +49 -0
- package/test/memory/abort-leak.test.ts +128 -0
- package/test/patch/patch.test.ts +348 -0
- package/test/permission/arity.test.ts +33 -0
- package/test/permission/next.test.ts +1227 -0
- package/test/permission/next.toConfig.test.ts +110 -0
- package/test/permission-task.test.ts +326 -0
- package/test/plugin/auth-override.test.ts +79 -0
- package/test/plugin/cloudflare.test.ts +68 -0
- package/test/plugin/codex.test.ts +123 -0
- package/test/plugin/github-copilot-models.test.ts +261 -0
- package/test/plugin/install-concurrency.test.ts +140 -0
- package/test/plugin/install.test.ts +570 -0
- package/test/plugin/loader-shared.test.ts +1169 -0
- package/test/plugin/meta.test.ts +137 -0
- package/test/plugin/plugin-contract.test.ts +291 -0
- package/test/plugin/shared.test.ts +88 -0
- package/test/plugin/trigger.test.ts +102 -0
- package/test/plugin/workspace-adapter.test.ts +109 -0
- package/test/preload.ts +77 -0
- package/test/project/instance.test.ts +276 -0
- package/test/project/migrate-global.test.ts +152 -0
- package/test/project/project.test.ts +600 -0
- package/test/project/vcs.test.ts +286 -0
- package/test/project/worktree-remove.test.ts +126 -0
- package/test/project/worktree.test.ts +223 -0
- package/test/provider/amazon-bedrock.test.ts +462 -0
- package/test/provider/copilot/convert-to-copilot-messages.test.ts +523 -0
- package/test/provider/copilot/copilot-chat-model.test.ts +592 -0
- package/test/provider/gitlab-duo.test.ts +413 -0
- package/test/provider/local.test.ts +208 -0
- package/test/provider/models.test.ts +261 -0
- package/test/provider/provider-category.test.ts +190 -0
- package/test/provider/provider.test.ts +2758 -0
- package/test/provider/transform.test.ts +3681 -0
- package/test/pty/pty-output-isolation.test.ts +147 -0
- package/test/pty/pty-session.test.ts +102 -0
- package/test/pty/pty-shell.test.ts +104 -0
- package/test/question/question.test.ts +490 -0
- package/test/saeeol/agent-global-config-dirs.test.ts +24 -0
- package/test/saeeol/agent-manager-tool.test.ts +71 -0
- package/test/saeeol/agent-permission-overrides.test.ts +75 -0
- package/test/saeeol/agent-skill-permissions.test.ts +37 -0
- package/test/saeeol/ask-agent-permissions.test.ts +303 -0
- package/test/saeeol/bash-hierarchy.test.ts +64 -0
- package/test/saeeol/bash-permission-metadata.test.ts +66 -0
- package/test/saeeol/bash-security-extended.test.ts +243 -0
- package/test/saeeol/bedrock-claude-empty-content.test.ts +138 -0
- package/test/saeeol/boxes-integration.test.ts +415 -0
- package/test/saeeol/builtin-skills.test.ts +75 -0
- package/test/saeeol/cleanup.ts +28 -0
- package/test/saeeol/cli/dev-setup.test.ts +74 -0
- package/test/saeeol/cli/roll-call.test.ts +161 -0
- package/test/saeeol/cli-run-auto-helper.test.ts +58 -0
- package/test/saeeol/codex-auth-refresh.test.ts +124 -0
- package/test/saeeol/commit-message/generate.test.ts +188 -0
- package/test/saeeol/commit-message/git-context.test.ts +303 -0
- package/test/saeeol/commit-message-windows.test.ts +38 -0
- package/test/saeeol/compaction-payload-recovery.test.ts +406 -0
- package/test/saeeol/compaction-preservation-audit.test.ts +122 -0
- package/test/saeeol/compaction-skip-guard.test.ts +224 -0
- package/test/saeeol/compaction-smart-select.test.ts +100 -0
- package/test/saeeol/config/config.test.ts +166 -0
- package/test/saeeol/config/indexing-default-plugin.test.ts +82 -0
- package/test/saeeol/config/opentelemetry-default.test.ts +29 -0
- package/test/saeeol/config-gitignore.test.ts +70 -0
- package/test/saeeol/config-injector.test.ts +305 -0
- package/test/saeeol/config-resilience.test.ts +234 -0
- package/test/saeeol/config-validation.test.ts +183 -0
- package/test/saeeol/cost-propagation.test.ts +94 -0
- package/test/saeeol/cost-tracker-extended.test.ts +141 -0
- package/test/saeeol/cost-tracker.test.ts +64 -0
- package/test/saeeol/custom-provider-delete.test.ts +149 -0
- package/test/saeeol/diff-full.test.ts +226 -0
- package/test/saeeol/edit-permission-filediff.test.ts +223 -0
- package/test/saeeol/encoding.test.ts +364 -0
- package/test/saeeol/enhance-prompt.test.ts +61 -0
- package/test/saeeol/ensure-plan-dir.test.ts +32 -0
- package/test/saeeol/errors.test.ts +144 -0
- package/test/saeeol/external-directory-boundary.test.ts +96 -0
- package/test/saeeol/gateway-headers.test.ts +88 -0
- package/test/saeeol/help.test.ts +191 -0
- package/test/saeeol/ignore-migrator.test.ts +308 -0
- package/test/saeeol/indexing-auth.test.ts +45 -0
- package/test/saeeol/indexing-feature.test.ts +44 -0
- package/test/saeeol/indexing-label.test.ts +70 -0
- package/test/saeeol/indexing-startup.test.ts +381 -0
- package/test/saeeol/indexing-worktree.test.ts +73 -0
- package/test/saeeol/instruction.test.ts +136 -0
- package/test/saeeol/lancedb-runtime.test.ts +116 -0
- package/test/saeeol/loader-auth.test.ts +168 -0
- package/test/saeeol/local-model.test.ts +621 -0
- package/test/saeeol/logo.test.ts +31 -0
- package/test/saeeol/lsp-typescript-lightweight.test.ts +89 -0
- package/test/saeeol/mcp-branding.test.ts +33 -0
- package/test/saeeol/mcp-docker-rm.test.ts +32 -0
- package/test/saeeol/mcp-migrator.test.ts +736 -0
- package/test/saeeol/mcp-oauth-callback.test.ts +33 -0
- package/test/saeeol/memory-io.test.ts +198 -0
- package/test/saeeol/memory-paths.test.ts +87 -0
- package/test/saeeol/memory-security.test.ts +166 -0
- package/test/saeeol/model-cache-org.test.ts +164 -0
- package/test/saeeol/model-info-panel-utils.test.ts +52 -0
- package/test/saeeol/model-info-panel.types.test.ts +7 -0
- package/test/saeeol/models-401-fallback.test.ts +52 -0
- package/test/saeeol/modes-migrator.test.ts +320 -0
- package/test/saeeol/nvidia-headers.test.ts +74 -0
- package/test/saeeol/patch-jsonc.test.ts +73 -0
- package/test/saeeol/patch.test.ts +172 -0
- package/test/saeeol/paths.test.ts +265 -0
- package/test/saeeol/permission/config-paths.test.ts +174 -0
- package/test/saeeol/permission/env-read.test.ts +149 -0
- package/test/saeeol/permission/external-directory-allow.test.ts +327 -0
- package/test/saeeol/permission/next.always-rules.test.ts +882 -0
- package/test/saeeol/permission/next.reply-http.test.ts +205 -0
- package/test/saeeol/permission/next.reply-routing.test.ts +184 -0
- package/test/saeeol/plan-exit-detection.test.ts +494 -0
- package/test/saeeol/plan-followup.test.ts +1376 -0
- package/test/saeeol/project-config-update.test.ts +120 -0
- package/test/saeeol/project-id.test.ts +455 -0
- package/test/saeeol/provider-cost.test.ts +171 -0
- package/test/saeeol/provider-list-failed-state.test.ts +100 -0
- package/test/saeeol/question-dismiss-all.test.ts +174 -0
- package/test/saeeol/read-directory.test.ts +116 -0
- package/test/saeeol/rules-migrator.test.ts +257 -0
- package/test/saeeol/run-auto.test.ts +176 -0
- package/test/saeeol/run-network.test.ts +224 -0
- package/test/saeeol/semantic-search.test.ts +186 -0
- package/test/saeeol/server/permission-allow-everything.test.ts +125 -0
- package/test/saeeol/session/instruction-substitution.test.ts +72 -0
- package/test/saeeol/session/platform-attribution.test.ts +118 -0
- package/test/saeeol/session/session.test.ts +105 -0
- package/test/saeeol/session-compaction-cap.test.ts +399 -0
- package/test/saeeol/session-compaction-chunks.test.ts +501 -0
- package/test/saeeol/session-compaction-safety.test.ts +481 -0
- package/test/saeeol/session-fork-remap.test.ts +251 -0
- package/test/saeeol/session-import-service.test.ts +114 -0
- package/test/saeeol/session-list.test.ts +47 -0
- package/test/saeeol/session-message-metadata.test.ts +128 -0
- package/test/saeeol/session-overflow.test.ts +78 -0
- package/test/saeeol/session-processor-empty-tool-calls.test.ts +571 -0
- package/test/saeeol/session-processor-network-offline.test.ts +204 -0
- package/test/saeeol/session-processor-retry-limit.test.ts +238 -0
- package/test/saeeol/session-processor-review-telemetry.test.ts +82 -0
- package/test/saeeol/session-prompt-compaction-safety.test.ts +517 -0
- package/test/saeeol/session-prompt-queue.test.ts +815 -0
- package/test/saeeol/sessions/inflight-cache.test.ts +157 -0
- package/test/saeeol/sessions/ingest-queue.test.ts +402 -0
- package/test/saeeol/sessions/remote-protocol.test.ts +258 -0
- package/test/saeeol/sessions/remote-sender.test.ts +1036 -0
- package/test/saeeol/sessions/remote-ws.test.ts +367 -0
- package/test/saeeol/sessions/sessions-enable-remote.test.disable +181 -0
- package/test/saeeol/slot-prop-reactivity.test.ts +142 -0
- package/test/saeeol/snapshot-cache.test.ts +84 -0
- package/test/saeeol/snapshot-freeze-repro.test.ts +100 -0
- package/test/saeeol/snapshot-track-timeout.test.ts +519 -0
- package/test/saeeol/stats-subagent-cost.test.ts +123 -0
- package/test/saeeol/suggestion/auto-dismiss.test.ts +65 -0
- package/test/saeeol/suggestion/suggestion.test.ts +145 -0
- package/test/saeeol/suggestion/tool.test.ts +298 -0
- package/test/saeeol/summary-file-diff.test.ts +28 -0
- package/test/saeeol/system-prompt.test.ts +142 -0
- package/test/saeeol/task-nesting.test.ts +193 -0
- package/test/saeeol/telemetry/feedback.test.ts +8 -0
- package/test/saeeol/todo-view.test.ts +57 -0
- package/test/saeeol/tool-encoding.test.ts +455 -0
- package/test/saeeol/tool-registry-indexing-import-failure.test.ts +49 -0
- package/test/saeeol/tool-registry-indexing.test.ts +236 -0
- package/test/saeeol/tool-registry-semantic-import-failure.test.ts +55 -0
- package/test/saeeol/tool-task-model.test.ts +352 -0
- package/test/saeeol/transform-opus-4.7.test.ts +89 -0
- package/test/saeeol/tui-diff.test.ts +91 -0
- package/test/saeeol/tui-sync.test.ts +80 -0
- package/test/saeeol/util/url.test.ts +141 -0
- package/test/saeeol/workflows-migrator.test.ts +261 -0
- package/test/saeeol/worktree-diff-summary.test.ts +64 -0
- package/test/saeeol/worktree-diff.test.ts +223 -0
- package/test/saeeol/worktree-remove-lock.test.ts +82 -0
- package/test/server/AGENTS.md +15 -0
- package/test/server/contract.test.ts +357 -0
- package/test/server/experimental-session-list.test.ts +157 -0
- package/test/server/global-session-list.test.ts +155 -0
- package/test/server/httpapi-authorization.test.ts +103 -0
- package/test/server/httpapi-bridge.test.ts +440 -0
- package/test/server/httpapi-config.test.ts +67 -0
- package/test/server/httpapi-cors.test.ts +89 -0
- package/test/server/httpapi-event.test.ts +57 -0
- package/test/server/httpapi-experimental.test.ts +219 -0
- package/test/server/httpapi-file.test.ts +79 -0
- package/test/server/httpapi-instance-context.test.ts +237 -0
- package/test/server/httpapi-instance.legacy.test.ts +140 -0
- package/test/server/httpapi-instance.test.ts +83 -0
- package/test/server/httpapi-json-parity.test.ts +263 -0
- package/test/server/httpapi-mcp-oauth.test.ts +76 -0
- package/test/server/httpapi-mcp.test.ts +189 -0
- package/test/server/httpapi-provider.test.ts +153 -0
- package/test/server/httpapi-pty-websocket.test.ts +16 -0
- package/test/server/httpapi-pty.test.ts +175 -0
- package/test/server/httpapi-raw-route-auth.test.ts +89 -0
- package/test/server/httpapi-sdk.test.ts +681 -0
- package/test/server/httpapi-session.test.ts +464 -0
- package/test/server/httpapi-sync.test.ts +130 -0
- package/test/server/httpapi-tui.test.ts +121 -0
- package/test/server/httpapi-workspace-routing.test.ts +471 -0
- package/test/server/httpapi-workspace.test.ts +427 -0
- package/test/server/lib/conformance.ts +88 -0
- package/test/server/lib/stateful.ts +112 -0
- package/test/server/project-init-git.test.ts +113 -0
- package/test/server/proxy-util.test.ts +113 -0
- package/test/server/session-actions.test.ts +49 -0
- package/test/server/session-list.test.ts +238 -0
- package/test/server/session-messages.test.ts +167 -0
- package/test/server/session-select.test.ts +100 -0
- package/test/server/trace-attributes.test.ts +76 -0
- package/test/server/workspace-proxy.test.ts +165 -0
- package/test/server/workspace-routing.test.ts +85 -0
- package/test/session/compaction.test.ts +2420 -0
- package/test/session/instruction.test.ts +247 -0
- package/test/session/llm.test.ts +1273 -0
- package/test/session/message-v2.test.ts +1291 -0
- package/test/session/messages-pagination.test.ts +1173 -0
- package/test/session/network.test.ts +249 -0
- package/test/session/processor-effect.test.ts +847 -0
- package/test/session/prompt.test.ts +2131 -0
- package/test/session/retry.test.ts +340 -0
- package/test/session/revert-compact.test.ts +639 -0
- package/test/session/schema-decoding.test.ts +311 -0
- package/test/session/session-entry-stepper.test.ts +917 -0
- package/test/session/session-schema.test.ts +76 -0
- package/test/session/snapshot-tool-race.test.ts +257 -0
- package/test/session/structured-output-integration.test.ts +265 -0
- package/test/session/structured-output.test.ts +381 -0
- package/test/session/system.test.ts +73 -0
- package/test/share/share-next.test.ts +333 -0
- package/test/shell/shell.test.ts +99 -0
- package/test/skill/discovery.test.ts +116 -0
- package/test/skill/skill.test.ts +393 -0
- package/test/snapshot/snapshot.test.ts +1531 -0
- package/test/storage/db.test.ts +23 -0
- package/test/storage/json-migration.test.ts +832 -0
- package/test/storage/storage.test.ts +293 -0
- package/test/suggestion/suggestion.test.ts +1 -0
- package/test/sync/index.test.ts +256 -0
- package/test/tool/__snapshots__/parameters.test.ts.snap +500 -0
- package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
- package/test/tool/apply_patch.test.ts +614 -0
- package/test/tool/bash.test.ts +1225 -0
- package/test/tool/diagnostics-filter.test.ts +55 -0
- package/test/tool/edit.test.ts +754 -0
- package/test/tool/external-directory.test.ts +169 -0
- package/test/tool/fixtures/large-image.png +0 -0
- package/test/tool/fixtures/models-api.json +65179 -0
- package/test/tool/glob.test.ts +107 -0
- package/test/tool/grep.test.ts +114 -0
- package/test/tool/lsp.test.ts +187 -0
- package/test/tool/parameters.test.ts +243 -0
- package/test/tool/question.test.ts +129 -0
- package/test/tool/read.test.ts +500 -0
- package/test/tool/recall.test.ts +151 -0
- package/test/tool/registry.test.ts +203 -0
- package/test/tool/skill.test.ts +135 -0
- package/test/tool/suggest.test.ts +1 -0
- package/test/tool/task.test.ts +612 -0
- package/test/tool/tool-define.test.ts +99 -0
- package/test/tool/truncation.test.ts +260 -0
- package/test/tool/webfetch.test.ts +103 -0
- package/test/tool/write.test.ts +291 -0
- package/test/util/data-url.test.ts +14 -0
- package/test/util/effect-zod.test.ts +754 -0
- package/test/util/error.test.ts +38 -0
- package/test/util/filesystem.test.ts +656 -0
- package/test/util/format.test.ts +59 -0
- package/test/util/glob.test.ts +164 -0
- package/test/util/iife.test.ts +36 -0
- package/test/util/lazy.test.ts +50 -0
- package/test/util/lock.test.ts +72 -0
- package/test/util/log.test.ts +86 -0
- package/test/util/module.test.ts +59 -0
- package/test/util/process.test.ts +128 -0
- package/test/util/timeout.test.ts +21 -0
- package/test/util/which.test.ts +100 -0
- package/test/util/wildcard.test.ts +90 -0
- package/test/workspace/workspace-restore.test.ts +296 -0
- package/src/provider/models-snapshot.d.ts +0 -2
- package/src/provider/models-snapshot.js +0 -3
|
@@ -0,0 +1,2131 @@
|
|
|
1
|
+
import { NodeFileSystem } from "@effect/platform-node"
|
|
2
|
+
import { FetchHttpClient } from "effect/unstable/http"
|
|
3
|
+
import { afterEach, expect, mock, spyOn } from "bun:test"
|
|
4
|
+
import { Telemetry } from "@saeeol/telemetry"
|
|
5
|
+
import { Cause, Effect, Exit, Fiber, Layer } from "effect"
|
|
6
|
+
import path from "path"
|
|
7
|
+
import { fileURLToPath } from "url"
|
|
8
|
+
import { NamedError } from "@saeeol/core/util/error"
|
|
9
|
+
import { Agent as AgentSvc } from "../../src/agent/agent"
|
|
10
|
+
import { Bus } from "../../src/bus"
|
|
11
|
+
import { Command } from "../../src/command"
|
|
12
|
+
import { Config } from "@/config/config"
|
|
13
|
+
import { LSP } from "@/lsp/lsp"
|
|
14
|
+
import { MCP } from "../../src/mcp"
|
|
15
|
+
import { Permission } from "../../src/permission"
|
|
16
|
+
import { Plugin } from "../../src/plugin"
|
|
17
|
+
import { Provider as ProviderSvc } from "@/provider/provider"
|
|
18
|
+
import { Env } from "../../src/env"
|
|
19
|
+
import { ModelID, ProviderID } from "../../src/provider/schema"
|
|
20
|
+
import { Question } from "../../src/question"
|
|
21
|
+
import { Todo } from "../../src/session/todo"
|
|
22
|
+
import { Session } from "@/session/session"
|
|
23
|
+
import { LLM } from "../../src/session/llm"
|
|
24
|
+
import { MessageV2 } from "../../src/session/message-v2"
|
|
25
|
+
import { AppFileSystem } from "@saeeol/core/filesystem"
|
|
26
|
+
import { SessionCompaction } from "../../src/session/compaction"
|
|
27
|
+
import { SessionSummary } from "../../src/session/summary"
|
|
28
|
+
import { Instruction } from "../../src/session/instruction"
|
|
29
|
+
import { SessionProcessor } from "../../src/session/processor"
|
|
30
|
+
import { SessionPrompt } from "../../src/session/prompt"
|
|
31
|
+
import { SessionRevert } from "../../src/session/revert"
|
|
32
|
+
import { SessionRunState } from "../../src/session/run-state"
|
|
33
|
+
import { MessageID, PartID, SessionID } from "../../src/session/schema"
|
|
34
|
+
import { SessionStatus } from "../../src/session/status"
|
|
35
|
+
import { Skill } from "../../src/skill"
|
|
36
|
+
import { SystemPrompt } from "../../src/session/system"
|
|
37
|
+
import { Shell } from "../../src/shell/shell"
|
|
38
|
+
import { Snapshot } from "../../src/snapshot"
|
|
39
|
+
import { ToolRegistry } from "@/tool/registry"
|
|
40
|
+
import { Truncate } from "@/tool/truncate"
|
|
41
|
+
import { defaultLayer as resolveToolsLayer } from "../../src/session/resolve-tools"
|
|
42
|
+
import { defaultLayer as userPartLayer } from "../../src/session/user-part"
|
|
43
|
+
import { defaultLayer as subtaskLayer } from "../../src/session/subtask"
|
|
44
|
+
import { defaultLayer as shellLayer } from "../../src/session/shell-exec"
|
|
45
|
+
import * as Log from "@saeeol/core/util/log"
|
|
46
|
+
import { CrossSpawnSpawner } from "@saeeol/core/cross-spawn-spawner"
|
|
47
|
+
import { Ripgrep } from "../../src/file/ripgrep"
|
|
48
|
+
import { Format } from "../../src/format"
|
|
49
|
+
import { provideTmpdirInstance, provideTmpdirServer } from "../fixture/fixture"
|
|
50
|
+
import { testEffect } from "../lib/effect"
|
|
51
|
+
import { reply, TestLLMServer } from "../lib/llm-server"
|
|
52
|
+
|
|
53
|
+
void Log.init({ print: false })
|
|
54
|
+
const summary = Layer.succeed(
|
|
55
|
+
SessionSummary.Service,
|
|
56
|
+
SessionSummary.Service.of({
|
|
57
|
+
summarize: () => Effect.void,
|
|
58
|
+
diff: () => Effect.succeed([]),
|
|
59
|
+
computeDiff: () => Effect.succeed([]),
|
|
60
|
+
}),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
const ref = {
|
|
64
|
+
providerID: ProviderID.make("test"),
|
|
65
|
+
modelID: ModelID.make("test-model"),
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function defer<T>() {
|
|
69
|
+
let resolve!: (value: T | PromiseLike<T>) => void
|
|
70
|
+
const promise = new Promise<T>((done) => {
|
|
71
|
+
resolve = done
|
|
72
|
+
})
|
|
73
|
+
return { promise, resolve }
|
|
74
|
+
}
|
|
75
|
+
const waitFor = <A, E, R>(label: string, run: Effect.Effect<A | undefined, E, R>) =>
|
|
76
|
+
Effect.gen(function* () {
|
|
77
|
+
const end = Date.now() + 5_000
|
|
78
|
+
while (Date.now() < end) {
|
|
79
|
+
const result = yield* run
|
|
80
|
+
if (result !== undefined) return result
|
|
81
|
+
yield* Effect.sleep(20)
|
|
82
|
+
}
|
|
83
|
+
throw new Error(`timed out waiting for ${label}`)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
function withSh<A, E, R>(fx: () => Effect.Effect<A, E, R>) {
|
|
87
|
+
return Effect.acquireUseRelease(
|
|
88
|
+
Effect.sync(() => {
|
|
89
|
+
const prev = process.env.SHELL
|
|
90
|
+
process.env.SHELL = "/bin/sh"
|
|
91
|
+
Shell.preferred.reset()
|
|
92
|
+
return prev
|
|
93
|
+
}),
|
|
94
|
+
() => fx(),
|
|
95
|
+
(prev) =>
|
|
96
|
+
Effect.sync(() => {
|
|
97
|
+
if (prev === undefined) delete process.env.SHELL
|
|
98
|
+
else process.env.SHELL = prev
|
|
99
|
+
Shell.preferred.reset()
|
|
100
|
+
}),
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function toolPart(parts: MessageV2.Part[]) {
|
|
105
|
+
return parts.find((part): part is MessageV2.ToolPart => part.type === "tool")
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
type CompletedToolPart = MessageV2.ToolPart & { state: MessageV2.ToolStateCompleted }
|
|
109
|
+
type ErrorToolPart = MessageV2.ToolPart & { state: MessageV2.ToolStateError }
|
|
110
|
+
|
|
111
|
+
function completedTool(parts: MessageV2.Part[]) {
|
|
112
|
+
const part = toolPart(parts)
|
|
113
|
+
expect(part?.state.status).toBe("completed")
|
|
114
|
+
return part?.state.status === "completed" ? (part as CompletedToolPart) : undefined
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function errorTool(parts: MessageV2.Part[]) {
|
|
118
|
+
const part = toolPart(parts)
|
|
119
|
+
expect(part?.state.status).toBe("error")
|
|
120
|
+
return part?.state.status === "error" ? (part as ErrorToolPart) : undefined
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const mcp = Layer.succeed(
|
|
124
|
+
MCP.Service,
|
|
125
|
+
MCP.Service.of({
|
|
126
|
+
status: () => Effect.succeed({}),
|
|
127
|
+
clients: () => Effect.succeed({}),
|
|
128
|
+
tools: () => Effect.succeed({}),
|
|
129
|
+
prompts: () => Effect.succeed({}),
|
|
130
|
+
resources: () => Effect.succeed({}),
|
|
131
|
+
add: () => Effect.succeed({ status: { status: "disabled" as const } }),
|
|
132
|
+
connect: () => Effect.void,
|
|
133
|
+
disconnect: () => Effect.void,
|
|
134
|
+
getPrompt: () => Effect.succeed(undefined),
|
|
135
|
+
readResource: () => Effect.succeed(undefined),
|
|
136
|
+
startAuth: () => Effect.die("unexpected MCP auth in prompt-effect tests"),
|
|
137
|
+
authenticate: () => Effect.die("unexpected MCP auth in prompt-effect tests"),
|
|
138
|
+
finishAuth: () => Effect.die("unexpected MCP auth in prompt-effect tests"),
|
|
139
|
+
removeAuth: () => Effect.void,
|
|
140
|
+
supportsOAuth: () => Effect.succeed(false),
|
|
141
|
+
hasStoredTokens: () => Effect.succeed(false),
|
|
142
|
+
getAuthStatus: () => Effect.succeed("not_authenticated" as const),
|
|
143
|
+
}),
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
const lsp = Layer.succeed(
|
|
147
|
+
LSP.Service,
|
|
148
|
+
LSP.Service.of({
|
|
149
|
+
init: () => Effect.void,
|
|
150
|
+
status: () => Effect.succeed([]),
|
|
151
|
+
hasClients: () => Effect.succeed(false),
|
|
152
|
+
touchFile: () => Effect.void,
|
|
153
|
+
diagnostics: () => Effect.succeed({}),
|
|
154
|
+
hover: () => Effect.succeed(undefined),
|
|
155
|
+
definition: () => Effect.succeed([]),
|
|
156
|
+
references: () => Effect.succeed([]),
|
|
157
|
+
implementation: () => Effect.succeed([]),
|
|
158
|
+
documentSymbol: () => Effect.succeed([]),
|
|
159
|
+
workspaceSymbol: () => Effect.succeed([]),
|
|
160
|
+
prepareCallHierarchy: () => Effect.succeed([]),
|
|
161
|
+
incomingCalls: () => Effect.succeed([]),
|
|
162
|
+
outgoingCalls: () => Effect.succeed([]),
|
|
163
|
+
}),
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
const status = SessionStatus.layer.pipe(Layer.provideMerge(Bus.layer))
|
|
167
|
+
const run = SessionRunState.layer.pipe(Layer.provide(status))
|
|
168
|
+
const infra = Layer.mergeAll(NodeFileSystem.layer, CrossSpawnSpawner.defaultLayer)
|
|
169
|
+
function makeHttp() {
|
|
170
|
+
const deps = Layer.mergeAll(
|
|
171
|
+
Session.defaultLayer,
|
|
172
|
+
Snapshot.defaultLayer,
|
|
173
|
+
LLM.defaultLayer,
|
|
174
|
+
Env.defaultLayer,
|
|
175
|
+
AgentSvc.defaultLayer,
|
|
176
|
+
Command.defaultLayer,
|
|
177
|
+
Permission.defaultLayer,
|
|
178
|
+
Plugin.defaultLayer,
|
|
179
|
+
Config.defaultLayer,
|
|
180
|
+
ProviderSvc.defaultLayer,
|
|
181
|
+
lsp,
|
|
182
|
+
mcp,
|
|
183
|
+
AppFileSystem.defaultLayer,
|
|
184
|
+
status,
|
|
185
|
+
).pipe(Layer.provideMerge(infra))
|
|
186
|
+
const question = Question.layer.pipe(Layer.provideMerge(deps))
|
|
187
|
+
const todo = Todo.layer.pipe(Layer.provideMerge(deps))
|
|
188
|
+
const registry = ToolRegistry.layer.pipe(
|
|
189
|
+
Layer.provide(Skill.defaultLayer),
|
|
190
|
+
Layer.provide(FetchHttpClient.layer),
|
|
191
|
+
Layer.provide(CrossSpawnSpawner.defaultLayer),
|
|
192
|
+
Layer.provide(Ripgrep.defaultLayer),
|
|
193
|
+
Layer.provide(Format.defaultLayer),
|
|
194
|
+
Layer.provideMerge(todo),
|
|
195
|
+
Layer.provideMerge(question),
|
|
196
|
+
Layer.provideMerge(deps),
|
|
197
|
+
)
|
|
198
|
+
const trunc = Truncate.layer.pipe(Layer.provideMerge(deps))
|
|
199
|
+
const proc = SessionProcessor.layer.pipe(Layer.provide(summary), Layer.provideMerge(deps))
|
|
200
|
+
const compact = SessionCompaction.layer.pipe(Layer.provideMerge(proc), Layer.provideMerge(deps))
|
|
201
|
+
return Layer.mergeAll(
|
|
202
|
+
TestLLMServer.layer,
|
|
203
|
+
SessionPrompt.layer.pipe(
|
|
204
|
+
Layer.provide(resolveToolsLayer),
|
|
205
|
+
Layer.provide(userPartLayer),
|
|
206
|
+
Layer.provide(subtaskLayer),
|
|
207
|
+
Layer.provide(shellLayer),
|
|
208
|
+
Layer.provide(SessionRevert.defaultLayer),
|
|
209
|
+
Layer.provide(summary),
|
|
210
|
+
Layer.provideMerge(run),
|
|
211
|
+
Layer.provideMerge(compact),
|
|
212
|
+
Layer.provideMerge(proc),
|
|
213
|
+
Layer.provideMerge(registry),
|
|
214
|
+
Layer.provideMerge(trunc),
|
|
215
|
+
Layer.provide(Instruction.defaultLayer),
|
|
216
|
+
Layer.provide(SystemPrompt.defaultLayer),
|
|
217
|
+
Layer.provideMerge(deps),
|
|
218
|
+
),
|
|
219
|
+
).pipe(Layer.provide(summary))
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const it = testEffect(makeHttp())
|
|
223
|
+
const unix = process.platform !== "win32" ? it.live : it.live.skip
|
|
224
|
+
afterEach(() => {
|
|
225
|
+
mock.restore()
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
// Config that registers a custom "test" provider with a "test-model" model
|
|
229
|
+
// so provider model lookup succeeds inside the loop.
|
|
230
|
+
const cfg = {
|
|
231
|
+
provider: {
|
|
232
|
+
test: {
|
|
233
|
+
name: "Test",
|
|
234
|
+
id: "test",
|
|
235
|
+
env: [],
|
|
236
|
+
npm: "@ai-sdk/openai-compatible",
|
|
237
|
+
models: {
|
|
238
|
+
"test-model": {
|
|
239
|
+
id: "test-model",
|
|
240
|
+
name: "Test Model",
|
|
241
|
+
attachment: false,
|
|
242
|
+
reasoning: false,
|
|
243
|
+
temperature: false,
|
|
244
|
+
tool_call: true,
|
|
245
|
+
release_date: "2025-01-01",
|
|
246
|
+
limit: { context: 100000, output: 10000 },
|
|
247
|
+
cost: { input: 0, output: 0 },
|
|
248
|
+
options: {},
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
options: {
|
|
252
|
+
apiKey: "test-key",
|
|
253
|
+
baseURL: "http://localhost:1/v1",
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function providerCfg(url: string) {
|
|
260
|
+
return {
|
|
261
|
+
...cfg,
|
|
262
|
+
provider: {
|
|
263
|
+
...cfg.provider,
|
|
264
|
+
test: {
|
|
265
|
+
...cfg.provider.test,
|
|
266
|
+
options: {
|
|
267
|
+
...cfg.provider.test.options,
|
|
268
|
+
baseURL: url,
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const user = Effect.fn("test.user")(function* (sessionID: SessionID, text: string) {
|
|
276
|
+
const session = yield* Session.Service
|
|
277
|
+
const msg = yield* session.updateMessage({
|
|
278
|
+
id: MessageID.ascending(),
|
|
279
|
+
role: "user",
|
|
280
|
+
sessionID,
|
|
281
|
+
agent: "build",
|
|
282
|
+
model: ref,
|
|
283
|
+
time: { created: Date.now() },
|
|
284
|
+
})
|
|
285
|
+
yield* session.updatePart({
|
|
286
|
+
id: PartID.ascending(),
|
|
287
|
+
messageID: msg.id,
|
|
288
|
+
sessionID,
|
|
289
|
+
type: "text",
|
|
290
|
+
text,
|
|
291
|
+
})
|
|
292
|
+
return msg
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
const seed = Effect.fn("test.seed")(function* (sessionID: SessionID, opts?: { finish?: string }) {
|
|
296
|
+
const session = yield* Session.Service
|
|
297
|
+
const msg = yield* user(sessionID, "hello")
|
|
298
|
+
const assistant: MessageV2.Assistant = {
|
|
299
|
+
id: MessageID.ascending(),
|
|
300
|
+
role: "assistant",
|
|
301
|
+
parentID: msg.id,
|
|
302
|
+
sessionID,
|
|
303
|
+
mode: "build",
|
|
304
|
+
agent: "build",
|
|
305
|
+
cost: 0,
|
|
306
|
+
path: { cwd: "/tmp", root: "/tmp" },
|
|
307
|
+
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
308
|
+
modelID: ref.modelID,
|
|
309
|
+
providerID: ref.providerID,
|
|
310
|
+
time: { created: Date.now() },
|
|
311
|
+
...(opts?.finish ? { finish: opts.finish } : {}),
|
|
312
|
+
}
|
|
313
|
+
yield* session.updateMessage(assistant)
|
|
314
|
+
yield* session.updatePart({
|
|
315
|
+
id: PartID.ascending(),
|
|
316
|
+
messageID: assistant.id,
|
|
317
|
+
sessionID,
|
|
318
|
+
type: "text",
|
|
319
|
+
text: "hi there",
|
|
320
|
+
})
|
|
321
|
+
return { user: msg, assistant }
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
const addSubtask = (sessionID: SessionID, messageID: MessageID, model = ref) =>
|
|
325
|
+
Effect.gen(function* () {
|
|
326
|
+
const session = yield* Session.Service
|
|
327
|
+
yield* session.updatePart({
|
|
328
|
+
id: PartID.ascending(),
|
|
329
|
+
messageID,
|
|
330
|
+
sessionID,
|
|
331
|
+
type: "subtask",
|
|
332
|
+
prompt: "look into the cache key path",
|
|
333
|
+
description: "inspect bug",
|
|
334
|
+
agent: "general",
|
|
335
|
+
model,
|
|
336
|
+
})
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
const boot = Effect.fn("test.boot")(function* (input?: { title?: string }) {
|
|
340
|
+
const config = yield* Config.Service
|
|
341
|
+
const prompt = yield* SessionPrompt.Service
|
|
342
|
+
const run = yield* SessionRunState.Service
|
|
343
|
+
const sessions = yield* Session.Service
|
|
344
|
+
yield* config.get()
|
|
345
|
+
const chat = yield* sessions.create(input ?? { title: "Pinned" })
|
|
346
|
+
return { prompt, run, sessions, chat }
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
// Loop semantics
|
|
350
|
+
|
|
351
|
+
it.live("loop exits immediately when last assistant has stop finish", () =>
|
|
352
|
+
provideTmpdirServer(
|
|
353
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
354
|
+
const prompt = yield* SessionPrompt.Service
|
|
355
|
+
const sessions = yield* Session.Service
|
|
356
|
+
const chat = yield* sessions.create({ title: "Pinned" })
|
|
357
|
+
yield* seed(chat.id, { finish: "stop" })
|
|
358
|
+
|
|
359
|
+
const result = yield* prompt.loop({ sessionID: chat.id })
|
|
360
|
+
expect(result.info.role).toBe("assistant")
|
|
361
|
+
if (result.info.role === "assistant") expect(result.info.finish).toBe("stop")
|
|
362
|
+
expect(yield* llm.calls).toBe(0)
|
|
363
|
+
}),
|
|
364
|
+
{ git: true, config: providerCfg },
|
|
365
|
+
),
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
it.live("loop calls LLM and returns assistant message", () =>
|
|
369
|
+
provideTmpdirServer(
|
|
370
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
371
|
+
const prompt = yield* SessionPrompt.Service
|
|
372
|
+
const sessions = yield* Session.Service
|
|
373
|
+
const chat = yield* sessions.create({
|
|
374
|
+
title: "Pinned",
|
|
375
|
+
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
376
|
+
})
|
|
377
|
+
yield* prompt.prompt({
|
|
378
|
+
sessionID: chat.id,
|
|
379
|
+
agent: "build",
|
|
380
|
+
noReply: true,
|
|
381
|
+
parts: [{ type: "text", text: "hello" }],
|
|
382
|
+
})
|
|
383
|
+
yield* llm.text("world")
|
|
384
|
+
|
|
385
|
+
const result = yield* prompt.loop({ sessionID: chat.id })
|
|
386
|
+
expect(result.info.role).toBe("assistant")
|
|
387
|
+
const parts = result.parts.filter((p) => p.type === "text")
|
|
388
|
+
expect(parts.some((p) => p.type === "text" && p.text === "world")).toBe(true)
|
|
389
|
+
expect(yield* llm.hits).toHaveLength(1)
|
|
390
|
+
}),
|
|
391
|
+
{ git: true, config: providerCfg },
|
|
392
|
+
),
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
it.live("static loop returns assistant text through local provider", () =>
|
|
396
|
+
provideTmpdirServer(
|
|
397
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
398
|
+
const prompt = yield* SessionPrompt.Service
|
|
399
|
+
const sessions = yield* Session.Service
|
|
400
|
+
const session = yield* sessions.create({
|
|
401
|
+
title: "Prompt provider",
|
|
402
|
+
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
yield* prompt.prompt({
|
|
406
|
+
sessionID: session.id,
|
|
407
|
+
agent: "build",
|
|
408
|
+
noReply: true,
|
|
409
|
+
parts: [{ type: "text", text: "hello" }],
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
yield* llm.text("world")
|
|
413
|
+
|
|
414
|
+
const result = yield* prompt.loop({ sessionID: session.id })
|
|
415
|
+
expect(result.info.role).toBe("assistant")
|
|
416
|
+
expect(result.parts.some((part) => part.type === "text" && part.text === "world")).toBe(true)
|
|
417
|
+
expect(yield* llm.hits).toHaveLength(1)
|
|
418
|
+
expect(yield* llm.pending).toBe(0)
|
|
419
|
+
}),
|
|
420
|
+
{ git: true, config: providerCfg },
|
|
421
|
+
),
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
it.live("static loop consumes queued replies across turns", () =>
|
|
425
|
+
provideTmpdirServer(
|
|
426
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
427
|
+
const prompt = yield* SessionPrompt.Service
|
|
428
|
+
const sessions = yield* Session.Service
|
|
429
|
+
const session = yield* sessions.create({
|
|
430
|
+
title: "Prompt provider turns",
|
|
431
|
+
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
432
|
+
})
|
|
433
|
+
|
|
434
|
+
yield* prompt.prompt({
|
|
435
|
+
sessionID: session.id,
|
|
436
|
+
agent: "build",
|
|
437
|
+
noReply: true,
|
|
438
|
+
parts: [{ type: "text", text: "hello one" }],
|
|
439
|
+
})
|
|
440
|
+
|
|
441
|
+
yield* llm.text("world one")
|
|
442
|
+
|
|
443
|
+
const first = yield* prompt.loop({ sessionID: session.id })
|
|
444
|
+
expect(first.info.role).toBe("assistant")
|
|
445
|
+
expect(first.parts.some((part) => part.type === "text" && part.text === "world one")).toBe(true)
|
|
446
|
+
|
|
447
|
+
yield* prompt.prompt({
|
|
448
|
+
sessionID: session.id,
|
|
449
|
+
agent: "build",
|
|
450
|
+
noReply: true,
|
|
451
|
+
parts: [{ type: "text", text: "hello two" }],
|
|
452
|
+
})
|
|
453
|
+
|
|
454
|
+
yield* llm.text("world two")
|
|
455
|
+
|
|
456
|
+
const second = yield* prompt.loop({ sessionID: session.id })
|
|
457
|
+
expect(second.info.role).toBe("assistant")
|
|
458
|
+
expect(second.parts.some((part) => part.type === "text" && part.text === "world two")).toBe(true)
|
|
459
|
+
|
|
460
|
+
expect(yield* llm.hits).toHaveLength(2)
|
|
461
|
+
expect(yield* llm.pending).toBe(0)
|
|
462
|
+
}),
|
|
463
|
+
{ git: true, config: providerCfg },
|
|
464
|
+
),
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
it.live("loop continues when finish is tool-calls", () =>
|
|
468
|
+
provideTmpdirServer(
|
|
469
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
470
|
+
const prompt = yield* SessionPrompt.Service
|
|
471
|
+
const sessions = yield* Session.Service
|
|
472
|
+
const session = yield* sessions.create({
|
|
473
|
+
title: "Pinned",
|
|
474
|
+
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
475
|
+
})
|
|
476
|
+
yield* prompt.prompt({
|
|
477
|
+
sessionID: session.id,
|
|
478
|
+
agent: "build",
|
|
479
|
+
noReply: true,
|
|
480
|
+
parts: [{ type: "text", text: "hello" }],
|
|
481
|
+
})
|
|
482
|
+
yield* llm.tool("first", { value: "first" })
|
|
483
|
+
yield* llm.text("second")
|
|
484
|
+
|
|
485
|
+
const result = yield* prompt.loop({ sessionID: session.id })
|
|
486
|
+
expect(yield* llm.calls).toBe(2)
|
|
487
|
+
expect(result.info.role).toBe("assistant")
|
|
488
|
+
if (result.info.role === "assistant") {
|
|
489
|
+
expect(result.parts.some((part) => part.type === "text" && part.text === "second")).toBe(true)
|
|
490
|
+
expect(result.info.finish).toBe("stop")
|
|
491
|
+
}
|
|
492
|
+
}),
|
|
493
|
+
{ git: true, config: providerCfg },
|
|
494
|
+
),
|
|
495
|
+
)
|
|
496
|
+
it.live.skip("glob tool keeps instance context during prompt runs", () =>
|
|
497
|
+
provideTmpdirServer(
|
|
498
|
+
({ dir, llm }) =>
|
|
499
|
+
Effect.gen(function* () {
|
|
500
|
+
const prompt = yield* SessionPrompt.Service
|
|
501
|
+
const sessions = yield* Session.Service
|
|
502
|
+
const session = yield* sessions.create({
|
|
503
|
+
title: "Glob context",
|
|
504
|
+
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
505
|
+
})
|
|
506
|
+
const file = path.join(dir, "probe.txt")
|
|
507
|
+
yield* Effect.promise(() => Bun.write(file, "probe"))
|
|
508
|
+
|
|
509
|
+
yield* prompt.prompt({
|
|
510
|
+
sessionID: session.id,
|
|
511
|
+
agent: "build",
|
|
512
|
+
noReply: true,
|
|
513
|
+
parts: [{ type: "text", text: "find text files" }],
|
|
514
|
+
})
|
|
515
|
+
yield* llm.tool("glob", { pattern: "**/*.txt" })
|
|
516
|
+
yield* llm.text("done")
|
|
517
|
+
|
|
518
|
+
const result = yield* prompt.loop({ sessionID: session.id })
|
|
519
|
+
expect(result.info.role).toBe("assistant")
|
|
520
|
+
|
|
521
|
+
const msgs = yield* MessageV2.filterCompactedEffect(session.id)
|
|
522
|
+
const tool = msgs
|
|
523
|
+
.flatMap((msg) => msg.parts)
|
|
524
|
+
.find(
|
|
525
|
+
(part): part is CompletedToolPart =>
|
|
526
|
+
part.type === "tool" && part.tool === "glob" && part.state.status === "completed",
|
|
527
|
+
)
|
|
528
|
+
if (!tool) return
|
|
529
|
+
|
|
530
|
+
expect(tool.state.output).toContain(file)
|
|
531
|
+
expect(tool.state.output).not.toContain("No context found for instance")
|
|
532
|
+
expect(result.parts.some((part) => part.type === "text" && part.text === "done")).toBe(true)
|
|
533
|
+
}),
|
|
534
|
+
{ git: true, config: providerCfg },
|
|
535
|
+
),
|
|
536
|
+
)
|
|
537
|
+
|
|
538
|
+
it.live("loop continues when finish is stop but assistant has tool parts", () =>
|
|
539
|
+
provideTmpdirServer(
|
|
540
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
541
|
+
const prompt = yield* SessionPrompt.Service
|
|
542
|
+
const sessions = yield* Session.Service
|
|
543
|
+
const session = yield* sessions.create({
|
|
544
|
+
title: "Pinned",
|
|
545
|
+
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
546
|
+
})
|
|
547
|
+
yield* prompt.prompt({
|
|
548
|
+
sessionID: session.id,
|
|
549
|
+
agent: "build",
|
|
550
|
+
noReply: true,
|
|
551
|
+
parts: [{ type: "text", text: "hello" }],
|
|
552
|
+
})
|
|
553
|
+
yield* llm.push(reply().tool("first", { value: "first" }).stop())
|
|
554
|
+
yield* llm.text("second")
|
|
555
|
+
|
|
556
|
+
const result = yield* prompt.loop({ sessionID: session.id })
|
|
557
|
+
expect(yield* llm.calls).toBe(2)
|
|
558
|
+
expect(result.info.role).toBe("assistant")
|
|
559
|
+
if (result.info.role === "assistant") {
|
|
560
|
+
expect(result.parts.some((part) => part.type === "text" && part.text === "second")).toBe(true)
|
|
561
|
+
expect(result.info.finish).toBe("stop")
|
|
562
|
+
}
|
|
563
|
+
}),
|
|
564
|
+
{ git: true, config: providerCfg },
|
|
565
|
+
),
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
it.live("failed subtask preserves metadata on error tool state", () =>
|
|
569
|
+
provideTmpdirServer(
|
|
570
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
571
|
+
const prompt = yield* SessionPrompt.Service
|
|
572
|
+
const sessions = yield* Session.Service
|
|
573
|
+
const chat = yield* sessions.create({ title: "Pinned" })
|
|
574
|
+
yield* llm.tool("task", {
|
|
575
|
+
description: "inspect bug",
|
|
576
|
+
prompt: "look into the cache key path",
|
|
577
|
+
subagent_type: "general",
|
|
578
|
+
})
|
|
579
|
+
yield* llm.text("done")
|
|
580
|
+
const msg = yield* user(chat.id, "hello")
|
|
581
|
+
yield* addSubtask(chat.id, msg.id)
|
|
582
|
+
|
|
583
|
+
const result = yield* prompt.loop({ sessionID: chat.id })
|
|
584
|
+
expect(result.info.role).toBe("assistant")
|
|
585
|
+
expect(yield* llm.calls).toBe(2)
|
|
586
|
+
|
|
587
|
+
const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
|
|
588
|
+
const taskMsg = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
|
|
589
|
+
expect(taskMsg?.info.role).toBe("assistant")
|
|
590
|
+
if (!taskMsg || taskMsg.info.role !== "assistant") return
|
|
591
|
+
|
|
592
|
+
const tool = errorTool(taskMsg.parts)
|
|
593
|
+
if (!tool) return
|
|
594
|
+
|
|
595
|
+
expect(tool.state.error).toContain("Tool execution failed")
|
|
596
|
+
expect(tool.state.metadata).toBeDefined()
|
|
597
|
+
expect(tool.state.metadata?.sessionId).toBeDefined()
|
|
598
|
+
expect(tool.state.metadata?.model).toEqual({
|
|
599
|
+
providerID: ProviderID.make("test"),
|
|
600
|
+
modelID: ModelID.make("missing-model"),
|
|
601
|
+
})
|
|
602
|
+
}),
|
|
603
|
+
{
|
|
604
|
+
git: true,
|
|
605
|
+
config: (url) => ({
|
|
606
|
+
...providerCfg(url),
|
|
607
|
+
agent: {
|
|
608
|
+
general: {
|
|
609
|
+
model: "test/missing-model",
|
|
610
|
+
},
|
|
611
|
+
},
|
|
612
|
+
}),
|
|
613
|
+
},
|
|
614
|
+
),
|
|
615
|
+
)
|
|
616
|
+
|
|
617
|
+
it.live(
|
|
618
|
+
"running subtask preserves metadata after tool-call transition",
|
|
619
|
+
() =>
|
|
620
|
+
provideTmpdirServer(
|
|
621
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
622
|
+
const prompt = yield* SessionPrompt.Service
|
|
623
|
+
const sessions = yield* Session.Service
|
|
624
|
+
const chat = yield* sessions.create({ title: "Pinned" })
|
|
625
|
+
yield* llm.hang
|
|
626
|
+
const msg = yield* user(chat.id, "hello")
|
|
627
|
+
yield* addSubtask(chat.id, msg.id)
|
|
628
|
+
|
|
629
|
+
const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
630
|
+
|
|
631
|
+
const tool = yield* Effect.promise(async () => {
|
|
632
|
+
const end = Date.now() + 5_000
|
|
633
|
+
while (Date.now() < end) {
|
|
634
|
+
const msgs = await Effect.runPromise(MessageV2.filterCompactedEffect(chat.id))
|
|
635
|
+
const taskMsg = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
|
|
636
|
+
const tool = taskMsg?.parts.find((part): part is MessageV2.ToolPart => part.type === "tool")
|
|
637
|
+
if (tool?.state.status === "running" && tool.state.metadata?.sessionId) return tool
|
|
638
|
+
await new Promise((done) => setTimeout(done, 20))
|
|
639
|
+
}
|
|
640
|
+
throw new Error("timed out waiting for running subtask metadata")
|
|
641
|
+
})
|
|
642
|
+
|
|
643
|
+
if (tool.state.status !== "running") return
|
|
644
|
+
expect(typeof tool.state.metadata?.sessionId).toBe("string")
|
|
645
|
+
expect(tool.state.title).toBeDefined()
|
|
646
|
+
expect(tool.state.metadata?.model).toBeDefined()
|
|
647
|
+
|
|
648
|
+
yield* prompt.cancel(chat.id)
|
|
649
|
+
yield* Fiber.await(fiber)
|
|
650
|
+
}),
|
|
651
|
+
{ git: true, config: providerCfg },
|
|
652
|
+
),
|
|
653
|
+
5_000,
|
|
654
|
+
)
|
|
655
|
+
|
|
656
|
+
it.live(
|
|
657
|
+
"running task tool preserves metadata after tool-call transition",
|
|
658
|
+
() =>
|
|
659
|
+
provideTmpdirServer(
|
|
660
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
661
|
+
const prompt = yield* SessionPrompt.Service
|
|
662
|
+
const sessions = yield* Session.Service
|
|
663
|
+
const chat = yield* sessions.create({
|
|
664
|
+
title: "Pinned",
|
|
665
|
+
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
666
|
+
})
|
|
667
|
+
yield* llm.tool("task", {
|
|
668
|
+
description: "inspect bug",
|
|
669
|
+
prompt: "look into the cache key path",
|
|
670
|
+
subagent_type: "general",
|
|
671
|
+
})
|
|
672
|
+
yield* llm.hang
|
|
673
|
+
yield* user(chat.id, "hello")
|
|
674
|
+
|
|
675
|
+
const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
676
|
+
|
|
677
|
+
const tool = yield* Effect.promise(async () => {
|
|
678
|
+
const end = Date.now() + 5_000
|
|
679
|
+
while (Date.now() < end) {
|
|
680
|
+
const msgs = await Effect.runPromise(MessageV2.filterCompactedEffect(chat.id))
|
|
681
|
+
const assistant = msgs.findLast((item) => item.info.role === "assistant" && item.info.agent === "code")
|
|
682
|
+
const tool = assistant?.parts.find(
|
|
683
|
+
(part): part is MessageV2.ToolPart => part.type === "tool" && part.tool === "task",
|
|
684
|
+
)
|
|
685
|
+
if (tool?.state.status === "running" && tool.state.metadata?.sessionId) return tool
|
|
686
|
+
await new Promise((done) => setTimeout(done, 20))
|
|
687
|
+
}
|
|
688
|
+
throw new Error("timed out waiting for running task metadata")
|
|
689
|
+
})
|
|
690
|
+
|
|
691
|
+
if (tool.state.status !== "running") return
|
|
692
|
+
expect(typeof tool.state.metadata?.sessionId).toBe("string")
|
|
693
|
+
expect(tool.state.title).toBe("inspect bug")
|
|
694
|
+
expect(tool.state.metadata?.model).toBeDefined()
|
|
695
|
+
|
|
696
|
+
yield* prompt.cancel(chat.id)
|
|
697
|
+
yield* Fiber.await(fiber)
|
|
698
|
+
}),
|
|
699
|
+
{ git: true, config: providerCfg },
|
|
700
|
+
),
|
|
701
|
+
10_000,
|
|
702
|
+
)
|
|
703
|
+
|
|
704
|
+
it.live(
|
|
705
|
+
"loop sets status to busy then idle",
|
|
706
|
+
() =>
|
|
707
|
+
provideTmpdirServer(
|
|
708
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
709
|
+
const gate = defer<void>()
|
|
710
|
+
const prompt = yield* SessionPrompt.Service
|
|
711
|
+
const sessions = yield* Session.Service
|
|
712
|
+
const status = yield* SessionStatus.Service
|
|
713
|
+
|
|
714
|
+
yield* llm.push(reply().wait(gate.promise).text("done").stop())
|
|
715
|
+
|
|
716
|
+
const chat = yield* sessions.create({ title: "Pinned" })
|
|
717
|
+
yield* user(chat.id, "hi")
|
|
718
|
+
|
|
719
|
+
const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
720
|
+
yield* waitFor(
|
|
721
|
+
"busy status",
|
|
722
|
+
status.get(chat.id).pipe(Effect.map((item) => (item.type === "busy" ? item : undefined))),
|
|
723
|
+
)
|
|
724
|
+
gate.resolve()
|
|
725
|
+
yield* Fiber.await(fiber)
|
|
726
|
+
yield* waitFor(
|
|
727
|
+
"idle status",
|
|
728
|
+
status.get(chat.id).pipe(Effect.map((item) => (item.type === "idle" ? item : undefined))),
|
|
729
|
+
)
|
|
730
|
+
}),
|
|
731
|
+
{ git: true, config: providerCfg },
|
|
732
|
+
),
|
|
733
|
+
10_000,
|
|
734
|
+
)
|
|
735
|
+
|
|
736
|
+
// Cancel semantics
|
|
737
|
+
|
|
738
|
+
it.live(
|
|
739
|
+
"cancel interrupts loop and resolves with an assistant message",
|
|
740
|
+
() =>
|
|
741
|
+
provideTmpdirServer(
|
|
742
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
743
|
+
const prompt = yield* SessionPrompt.Service
|
|
744
|
+
const sessions = yield* Session.Service
|
|
745
|
+
const chat = yield* sessions.create({ title: "Pinned" })
|
|
746
|
+
yield* seed(chat.id)
|
|
747
|
+
|
|
748
|
+
yield* llm.hang
|
|
749
|
+
|
|
750
|
+
yield* user(chat.id, "more")
|
|
751
|
+
|
|
752
|
+
const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
753
|
+
yield* llm.wait(1)
|
|
754
|
+
yield* prompt.cancel(chat.id)
|
|
755
|
+
const exit = yield* Fiber.await(fiber)
|
|
756
|
+
expect(Exit.isSuccess(exit)).toBe(true)
|
|
757
|
+
if (Exit.isSuccess(exit)) {
|
|
758
|
+
expect(exit.value.info.role).toBe("assistant")
|
|
759
|
+
}
|
|
760
|
+
}),
|
|
761
|
+
{ git: true, config: providerCfg },
|
|
762
|
+
),
|
|
763
|
+
3_000,
|
|
764
|
+
)
|
|
765
|
+
|
|
766
|
+
unix(
|
|
767
|
+
"cancel records MessageAbortedError on interrupted process",
|
|
768
|
+
() =>
|
|
769
|
+
provideTmpdirServer(
|
|
770
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
771
|
+
const prompt = yield* SessionPrompt.Service
|
|
772
|
+
const sessions = yield* Session.Service
|
|
773
|
+
const chat = yield* sessions.create({ title: "Pinned" })
|
|
774
|
+
yield* llm.hang
|
|
775
|
+
yield* user(chat.id, "hello")
|
|
776
|
+
|
|
777
|
+
const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
778
|
+
yield* llm.wait(1)
|
|
779
|
+
yield* prompt.cancel(chat.id)
|
|
780
|
+
const exit = yield* Fiber.await(fiber)
|
|
781
|
+
expect(Exit.isSuccess(exit)).toBe(true)
|
|
782
|
+
if (Exit.isSuccess(exit)) {
|
|
783
|
+
const info = exit.value.info
|
|
784
|
+
if (info.role === "assistant") {
|
|
785
|
+
expect(info.error?.name).toBe("MessageAbortedError")
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}),
|
|
789
|
+
{ git: true, config: providerCfg },
|
|
790
|
+
),
|
|
791
|
+
3_000,
|
|
792
|
+
)
|
|
793
|
+
|
|
794
|
+
it.live(
|
|
795
|
+
"cancel finalizes subtask tool state",
|
|
796
|
+
() =>
|
|
797
|
+
provideTmpdirInstance(
|
|
798
|
+
() =>
|
|
799
|
+
Effect.gen(function* () {
|
|
800
|
+
const ready = defer<void>()
|
|
801
|
+
const aborted = defer<void>()
|
|
802
|
+
const registry = yield* ToolRegistry.Service
|
|
803
|
+
const { task } = yield* registry.named()
|
|
804
|
+
const original = task.execute
|
|
805
|
+
task.execute = (_args, ctx) =>
|
|
806
|
+
Effect.callback<never>((_resume) => {
|
|
807
|
+
ready.resolve()
|
|
808
|
+
ctx.abort.addEventListener("abort", () => aborted.resolve(), { once: true })
|
|
809
|
+
return Effect.sync(() => aborted.resolve())
|
|
810
|
+
})
|
|
811
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => void (task.execute = original)))
|
|
812
|
+
|
|
813
|
+
const { prompt, chat } = yield* boot()
|
|
814
|
+
const msg = yield* user(chat.id, "hello")
|
|
815
|
+
yield* addSubtask(chat.id, msg.id)
|
|
816
|
+
|
|
817
|
+
const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
818
|
+
yield* Effect.promise(() => ready.promise)
|
|
819
|
+
yield* prompt.cancel(chat.id)
|
|
820
|
+
yield* Effect.promise(() => aborted.promise)
|
|
821
|
+
|
|
822
|
+
const exit = yield* Fiber.await(fiber)
|
|
823
|
+
expect(Exit.isSuccess(exit)).toBe(true)
|
|
824
|
+
|
|
825
|
+
const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
|
|
826
|
+
const taskMsg = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
|
|
827
|
+
expect(taskMsg?.info.role).toBe("assistant")
|
|
828
|
+
if (!taskMsg || taskMsg.info.role !== "assistant") return
|
|
829
|
+
|
|
830
|
+
const tool = toolPart(taskMsg.parts)
|
|
831
|
+
expect(tool?.type).toBe("tool")
|
|
832
|
+
if (!tool) return
|
|
833
|
+
|
|
834
|
+
expect(tool.state.status).not.toBe("running")
|
|
835
|
+
expect(taskMsg.info.time.completed).toBeDefined()
|
|
836
|
+
expect(taskMsg.info.finish).toBeDefined()
|
|
837
|
+
}),
|
|
838
|
+
{ git: true, config: cfg },
|
|
839
|
+
),
|
|
840
|
+
30_000,
|
|
841
|
+
)
|
|
842
|
+
it.live(
|
|
843
|
+
"handleSubtask propagates subagent cost to wrapper message",
|
|
844
|
+
() =>
|
|
845
|
+
provideTmpdirServer(
|
|
846
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
847
|
+
const prompt = yield* SessionPrompt.Service
|
|
848
|
+
const sessions = yield* Session.Service
|
|
849
|
+
const registry = yield* ToolRegistry.Service
|
|
850
|
+
const { task } = yield* registry.named()
|
|
851
|
+
const original = task.execute
|
|
852
|
+
// Simulate task tool: create a child session, persist an assistant with cost, return metadata.
|
|
853
|
+
task.execute = (_args, ctx) =>
|
|
854
|
+
Effect.gen(function* () {
|
|
855
|
+
const child = yield* sessions.create({ parentID: ctx.sessionID, title: "subagent" })
|
|
856
|
+
const childAssistant: MessageV2.Assistant = {
|
|
857
|
+
id: MessageID.ascending(),
|
|
858
|
+
role: "assistant",
|
|
859
|
+
parentID: ctx.messageID,
|
|
860
|
+
sessionID: child.id,
|
|
861
|
+
mode: "general",
|
|
862
|
+
agent: "general",
|
|
863
|
+
cost: 0.42,
|
|
864
|
+
path: { cwd: "/tmp", root: "/tmp" },
|
|
865
|
+
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
866
|
+
modelID: ref.modelID,
|
|
867
|
+
providerID: ref.providerID,
|
|
868
|
+
time: { created: Date.now(), completed: Date.now() },
|
|
869
|
+
finish: "stop",
|
|
870
|
+
}
|
|
871
|
+
yield* sessions.updateMessage(childAssistant)
|
|
872
|
+
yield* ctx.metadata({
|
|
873
|
+
title: "done",
|
|
874
|
+
metadata: { sessionId: child.id, model: ref, variant: undefined },
|
|
875
|
+
})
|
|
876
|
+
return { title: "done", metadata: { sessionId: child.id, model: ref, variant: undefined }, output: "done" }
|
|
877
|
+
})
|
|
878
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => void (task.execute = original)))
|
|
879
|
+
|
|
880
|
+
const chat = yield* sessions.create({ title: "Pinned" })
|
|
881
|
+
const msg = yield* user(chat.id, "hello")
|
|
882
|
+
yield* addSubtask(chat.id, msg.id)
|
|
883
|
+
// The loop continues past handleSubtask into a normal LLM step; provide one response to exit.
|
|
884
|
+
yield* llm.text("wrapped")
|
|
885
|
+
|
|
886
|
+
yield* prompt.loop({ sessionID: chat.id })
|
|
887
|
+
|
|
888
|
+
const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
|
|
889
|
+
const wrapper = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
|
|
890
|
+
expect(wrapper?.info.role).toBe("assistant")
|
|
891
|
+
if (!wrapper || wrapper.info.role !== "assistant") return
|
|
892
|
+
expect(wrapper.info.cost).toBeCloseTo(0.42, 6)
|
|
893
|
+
}),
|
|
894
|
+
{ git: true, config: providerCfg },
|
|
895
|
+
),
|
|
896
|
+
30_000,
|
|
897
|
+
)
|
|
898
|
+
|
|
899
|
+
it.live(
|
|
900
|
+
"cancel with queued callers resolves all cleanly",
|
|
901
|
+
() =>
|
|
902
|
+
provideTmpdirServer(
|
|
903
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
904
|
+
const prompt = yield* SessionPrompt.Service
|
|
905
|
+
const sessions = yield* Session.Service
|
|
906
|
+
const chat = yield* sessions.create({ title: "Pinned" })
|
|
907
|
+
yield* llm.hang
|
|
908
|
+
yield* user(chat.id, "hello")
|
|
909
|
+
|
|
910
|
+
const a = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
911
|
+
yield* llm.wait(1)
|
|
912
|
+
const b = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
913
|
+
yield* Effect.sleep(50)
|
|
914
|
+
|
|
915
|
+
yield* prompt.cancel(chat.id)
|
|
916
|
+
const [exitA, exitB] = yield* Effect.all([Fiber.await(a), Fiber.await(b)])
|
|
917
|
+
expect(Exit.isSuccess(exitA)).toBe(true)
|
|
918
|
+
expect(Exit.isSuccess(exitB)).toBe(true)
|
|
919
|
+
if (Exit.isSuccess(exitA) && Exit.isSuccess(exitB)) {
|
|
920
|
+
expect(exitA.value.info.id).toBe(exitB.value.info.id)
|
|
921
|
+
}
|
|
922
|
+
}),
|
|
923
|
+
{ git: true, config: providerCfg },
|
|
924
|
+
),
|
|
925
|
+
3_000,
|
|
926
|
+
)
|
|
927
|
+
|
|
928
|
+
// Queue semantics
|
|
929
|
+
|
|
930
|
+
it.live("concurrent loop callers get same result", () =>
|
|
931
|
+
provideTmpdirInstance(
|
|
932
|
+
(_dir) =>
|
|
933
|
+
Effect.gen(function* () {
|
|
934
|
+
const { prompt, run, chat } = yield* boot()
|
|
935
|
+
yield* seed(chat.id, { finish: "stop" })
|
|
936
|
+
|
|
937
|
+
const [a, b] = yield* Effect.all([prompt.loop({ sessionID: chat.id }), prompt.loop({ sessionID: chat.id })], {
|
|
938
|
+
concurrency: "unbounded",
|
|
939
|
+
})
|
|
940
|
+
|
|
941
|
+
expect(a.info.id).toBe(b.info.id)
|
|
942
|
+
expect(a.info.role).toBe("assistant")
|
|
943
|
+
yield* run.assertNotBusy(chat.id)
|
|
944
|
+
}),
|
|
945
|
+
{ git: true },
|
|
946
|
+
),
|
|
947
|
+
)
|
|
948
|
+
|
|
949
|
+
it.live(
|
|
950
|
+
"concurrent loop callers all receive same error result",
|
|
951
|
+
() =>
|
|
952
|
+
provideTmpdirServer(
|
|
953
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
954
|
+
const gate = defer<void>()
|
|
955
|
+
const prompt = yield* SessionPrompt.Service
|
|
956
|
+
const sessions = yield* Session.Service
|
|
957
|
+
const chat = yield* sessions.create({ title: "Pinned" })
|
|
958
|
+
|
|
959
|
+
yield* llm.push(reply().wait(gate.promise).streamError("boom"))
|
|
960
|
+
yield* user(chat.id, "hello")
|
|
961
|
+
|
|
962
|
+
const a = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
963
|
+
yield* llm.wait(1)
|
|
964
|
+
const b = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
965
|
+
yield* Effect.sleep(50)
|
|
966
|
+
gate.resolve()
|
|
967
|
+
|
|
968
|
+
const [ea, eb] = yield* Effect.all([Fiber.await(a), Fiber.await(b)])
|
|
969
|
+
expect(Exit.isSuccess(ea)).toBe(true)
|
|
970
|
+
expect(Exit.isSuccess(eb)).toBe(true)
|
|
971
|
+
if (!Exit.isSuccess(ea) || !Exit.isSuccess(eb)) return
|
|
972
|
+
const [first, second] = [ea.value, eb.value]
|
|
973
|
+
expect(first.info.id).toBe(second.info.id)
|
|
974
|
+
expect(first.info.role).toBe("assistant")
|
|
975
|
+
}),
|
|
976
|
+
{ git: true, config: providerCfg },
|
|
977
|
+
),
|
|
978
|
+
10_000,
|
|
979
|
+
)
|
|
980
|
+
// loses Instance AsyncLocalStorage context in the second forked prompt, which
|
|
981
|
+
// surfaces as a "No context found for instance" die before the queue behavior
|
|
982
|
+
// can be exercised. The Saeeol queue semantics (in-flight stream drains, second
|
|
983
|
+
// LLM request ends with the queued user message) are covered end-to-end in
|
|
984
|
+
// packages/saeeol/test/saeeol/session-prompt-queue.test.ts — keep this
|
|
985
|
+
// upstream scaffold skipped so future Saeeol merges remain friction-free.
|
|
986
|
+
it.live.skip(
|
|
987
|
+
"prompt submitted during an active run is included in the next LLM input",
|
|
988
|
+
() =>
|
|
989
|
+
provideTmpdirServer(
|
|
990
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
991
|
+
const gate = defer<void>()
|
|
992
|
+
const prompt = yield* SessionPrompt.Service
|
|
993
|
+
const sessions = yield* Session.Service
|
|
994
|
+
const chat = yield* sessions.create({ title: "Pinned" })
|
|
995
|
+
|
|
996
|
+
yield* llm.hold("first", gate.promise)
|
|
997
|
+
yield* llm.text("second")
|
|
998
|
+
|
|
999
|
+
const a = yield* prompt
|
|
1000
|
+
.prompt({
|
|
1001
|
+
sessionID: chat.id,
|
|
1002
|
+
agent: "build",
|
|
1003
|
+
model: ref,
|
|
1004
|
+
parts: [{ type: "text", text: "first" }],
|
|
1005
|
+
})
|
|
1006
|
+
.pipe(Effect.forkChild)
|
|
1007
|
+
|
|
1008
|
+
yield* llm.wait(1)
|
|
1009
|
+
|
|
1010
|
+
const id = MessageID.ascending()
|
|
1011
|
+
const b = yield* prompt
|
|
1012
|
+
.prompt({
|
|
1013
|
+
sessionID: chat.id,
|
|
1014
|
+
messageID: id,
|
|
1015
|
+
agent: "build",
|
|
1016
|
+
model: ref,
|
|
1017
|
+
parts: [{ type: "text", text: "second" }],
|
|
1018
|
+
})
|
|
1019
|
+
.pipe(Effect.forkChild)
|
|
1020
|
+
|
|
1021
|
+
yield* Effect.promise(async () => {
|
|
1022
|
+
const end = Date.now() + 5000
|
|
1023
|
+
while (Date.now() < end) {
|
|
1024
|
+
const msgs = await Effect.runPromise(sessions.messages({ sessionID: chat.id }))
|
|
1025
|
+
if (msgs.some((msg) => msg.info.role === "user" && msg.info.id === id)) return
|
|
1026
|
+
await new Promise((done) => setTimeout(done, 20))
|
|
1027
|
+
}
|
|
1028
|
+
throw new Error("timed out waiting for second prompt to save")
|
|
1029
|
+
})
|
|
1030
|
+
|
|
1031
|
+
gate.resolve()
|
|
1032
|
+
|
|
1033
|
+
const [ea, eb] = yield* Effect.all([Fiber.await(a), Fiber.await(b)])
|
|
1034
|
+
expect(Exit.isSuccess(ea)).toBe(true)
|
|
1035
|
+
expect(Exit.isSuccess(eb)).toBe(true)
|
|
1036
|
+
expect(yield* llm.calls).toBe(2)
|
|
1037
|
+
|
|
1038
|
+
const msgs = yield* sessions.messages({ sessionID: chat.id })
|
|
1039
|
+
const assistants = msgs.filter((msg) => msg.info.role === "assistant")
|
|
1040
|
+
expect(assistants).toHaveLength(2)
|
|
1041
|
+
const last = assistants.at(-1)
|
|
1042
|
+
if (!last || last.info.role !== "assistant") throw new Error("expected second assistant")
|
|
1043
|
+
expect(last.info.parentID).toBe(id)
|
|
1044
|
+
expect(last.parts.some((part) => part.type === "text" && part.text === "second")).toBe(true)
|
|
1045
|
+
|
|
1046
|
+
const inputs = yield* llm.inputs
|
|
1047
|
+
expect(inputs).toHaveLength(2)
|
|
1048
|
+
expect(JSON.stringify(inputs.at(-1)?.messages)).toContain("second")
|
|
1049
|
+
}),
|
|
1050
|
+
{ git: true, config: providerCfg },
|
|
1051
|
+
),
|
|
1052
|
+
3_000,
|
|
1053
|
+
)
|
|
1054
|
+
|
|
1055
|
+
it.live(
|
|
1056
|
+
"assertNotBusy throws BusyError when loop running",
|
|
1057
|
+
() =>
|
|
1058
|
+
provideTmpdirServer(
|
|
1059
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
1060
|
+
const prompt = yield* SessionPrompt.Service
|
|
1061
|
+
const run = yield* SessionRunState.Service
|
|
1062
|
+
const sessions = yield* Session.Service
|
|
1063
|
+
yield* llm.hang
|
|
1064
|
+
|
|
1065
|
+
const chat = yield* sessions.create({})
|
|
1066
|
+
yield* user(chat.id, "hi")
|
|
1067
|
+
|
|
1068
|
+
const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
1069
|
+
yield* llm.wait(1)
|
|
1070
|
+
|
|
1071
|
+
const exit = yield* run.assertNotBusy(chat.id).pipe(Effect.exit)
|
|
1072
|
+
expect(Exit.isFailure(exit)).toBe(true)
|
|
1073
|
+
if (Exit.isFailure(exit)) {
|
|
1074
|
+
expect(Cause.squash(exit.cause)).toBeInstanceOf(Session.BusyError)
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
yield* prompt.cancel(chat.id)
|
|
1078
|
+
yield* Fiber.await(fiber)
|
|
1079
|
+
}),
|
|
1080
|
+
{ git: true, config: providerCfg },
|
|
1081
|
+
),
|
|
1082
|
+
3_000,
|
|
1083
|
+
)
|
|
1084
|
+
|
|
1085
|
+
it.live("assertNotBusy succeeds when idle", () =>
|
|
1086
|
+
provideTmpdirInstance(
|
|
1087
|
+
(_dir) =>
|
|
1088
|
+
Effect.gen(function* () {
|
|
1089
|
+
const run = yield* SessionRunState.Service
|
|
1090
|
+
const sessions = yield* Session.Service
|
|
1091
|
+
|
|
1092
|
+
const chat = yield* sessions.create({})
|
|
1093
|
+
const exit = yield* run.assertNotBusy(chat.id).pipe(Effect.exit)
|
|
1094
|
+
expect(Exit.isSuccess(exit)).toBe(true)
|
|
1095
|
+
}),
|
|
1096
|
+
{ git: true },
|
|
1097
|
+
),
|
|
1098
|
+
)
|
|
1099
|
+
|
|
1100
|
+
// Shell semantics
|
|
1101
|
+
|
|
1102
|
+
it.live(
|
|
1103
|
+
"shell rejects with BusyError when loop running",
|
|
1104
|
+
() =>
|
|
1105
|
+
provideTmpdirServer(
|
|
1106
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
1107
|
+
const prompt = yield* SessionPrompt.Service
|
|
1108
|
+
const sessions = yield* Session.Service
|
|
1109
|
+
const chat = yield* sessions.create({ title: "Pinned" })
|
|
1110
|
+
yield* llm.hang
|
|
1111
|
+
yield* user(chat.id, "hi")
|
|
1112
|
+
|
|
1113
|
+
const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
1114
|
+
yield* llm.wait(1)
|
|
1115
|
+
|
|
1116
|
+
const exit = yield* prompt.shell({ sessionID: chat.id, agent: "build", command: "echo hi" }).pipe(Effect.exit)
|
|
1117
|
+
expect(Exit.isFailure(exit)).toBe(true)
|
|
1118
|
+
if (Exit.isFailure(exit)) {
|
|
1119
|
+
expect(Cause.squash(exit.cause)).toBeInstanceOf(Session.BusyError)
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
yield* prompt.cancel(chat.id)
|
|
1123
|
+
yield* Fiber.await(fiber)
|
|
1124
|
+
}),
|
|
1125
|
+
{ git: true, config: providerCfg },
|
|
1126
|
+
),
|
|
1127
|
+
3_000,
|
|
1128
|
+
)
|
|
1129
|
+
|
|
1130
|
+
unix("shell captures stdout and stderr in completed tool output", () =>
|
|
1131
|
+
provideTmpdirInstance(
|
|
1132
|
+
(_dir) =>
|
|
1133
|
+
Effect.gen(function* () {
|
|
1134
|
+
const { prompt, run, chat } = yield* boot()
|
|
1135
|
+
const result = yield* prompt.shell({
|
|
1136
|
+
sessionID: chat.id,
|
|
1137
|
+
agent: "build",
|
|
1138
|
+
command: "printf out && printf err >&2",
|
|
1139
|
+
})
|
|
1140
|
+
|
|
1141
|
+
expect(result.info.role).toBe("assistant")
|
|
1142
|
+
const tool = completedTool(result.parts)
|
|
1143
|
+
if (!tool) return
|
|
1144
|
+
|
|
1145
|
+
expect(tool.state.output).toContain("out")
|
|
1146
|
+
expect(tool.state.output).toContain("err")
|
|
1147
|
+
expect(tool.state.metadata.output).toContain("out")
|
|
1148
|
+
expect(tool.state.metadata.output).toContain("err")
|
|
1149
|
+
yield* run.assertNotBusy(chat.id)
|
|
1150
|
+
}),
|
|
1151
|
+
{ git: true, config: cfg },
|
|
1152
|
+
),
|
|
1153
|
+
)
|
|
1154
|
+
|
|
1155
|
+
unix("shell completes a fast command on the preferred shell", () =>
|
|
1156
|
+
provideTmpdirInstance(
|
|
1157
|
+
(dir) =>
|
|
1158
|
+
Effect.gen(function* () {
|
|
1159
|
+
const { prompt, run, chat } = yield* boot()
|
|
1160
|
+
const result = yield* prompt.shell({
|
|
1161
|
+
sessionID: chat.id,
|
|
1162
|
+
agent: "build",
|
|
1163
|
+
command: "pwd",
|
|
1164
|
+
})
|
|
1165
|
+
|
|
1166
|
+
expect(result.info.role).toBe("assistant")
|
|
1167
|
+
const tool = completedTool(result.parts)
|
|
1168
|
+
if (!tool) return
|
|
1169
|
+
|
|
1170
|
+
expect(tool.state.input.command).toBe("pwd")
|
|
1171
|
+
expect(tool.state.output).toContain(dir)
|
|
1172
|
+
expect(tool.state.metadata.output).toContain(dir)
|
|
1173
|
+
yield* run.assertNotBusy(chat.id)
|
|
1174
|
+
}),
|
|
1175
|
+
{ git: true, config: cfg },
|
|
1176
|
+
),
|
|
1177
|
+
)
|
|
1178
|
+
|
|
1179
|
+
unix(
|
|
1180
|
+
"shell uses configured shell over env shell",
|
|
1181
|
+
() =>
|
|
1182
|
+
withSh(() =>
|
|
1183
|
+
provideTmpdirInstance(
|
|
1184
|
+
(_dir) =>
|
|
1185
|
+
Effect.gen(function* () {
|
|
1186
|
+
if (!Bun.which("bash")) return
|
|
1187
|
+
|
|
1188
|
+
const { prompt, chat } = yield* boot()
|
|
1189
|
+
const result = yield* prompt.shell({
|
|
1190
|
+
sessionID: chat.id,
|
|
1191
|
+
agent: "build",
|
|
1192
|
+
command: "[[ 1 -eq 1 ]] && printf configured",
|
|
1193
|
+
})
|
|
1194
|
+
|
|
1195
|
+
const tool = completedTool(result.parts)
|
|
1196
|
+
if (!tool) return
|
|
1197
|
+
expect(tool.state.output).toContain("configured")
|
|
1198
|
+
}),
|
|
1199
|
+
{ git: true, config: { ...cfg, shell: "bash" } },
|
|
1200
|
+
),
|
|
1201
|
+
),
|
|
1202
|
+
30_000,
|
|
1203
|
+
)
|
|
1204
|
+
|
|
1205
|
+
unix("shell commands can change directory after startup", () =>
|
|
1206
|
+
provideTmpdirInstance(
|
|
1207
|
+
(dir) =>
|
|
1208
|
+
Effect.gen(function* () {
|
|
1209
|
+
const { prompt, run, chat } = yield* boot()
|
|
1210
|
+
const parent = path.dirname(dir)
|
|
1211
|
+
const result = yield* prompt.shell({
|
|
1212
|
+
sessionID: chat.id,
|
|
1213
|
+
agent: "build",
|
|
1214
|
+
command: "cd .. && pwd",
|
|
1215
|
+
})
|
|
1216
|
+
|
|
1217
|
+
expect(result.info.role).toBe("assistant")
|
|
1218
|
+
const tool = completedTool(result.parts)
|
|
1219
|
+
if (!tool) return
|
|
1220
|
+
|
|
1221
|
+
expect(tool.state.output).toContain(parent)
|
|
1222
|
+
expect(tool.state.metadata.output).toContain(parent)
|
|
1223
|
+
yield* run.assertNotBusy(chat.id)
|
|
1224
|
+
}),
|
|
1225
|
+
{ git: true, config: cfg },
|
|
1226
|
+
),
|
|
1227
|
+
)
|
|
1228
|
+
|
|
1229
|
+
unix("shell lists files from the project directory", () =>
|
|
1230
|
+
provideTmpdirInstance(
|
|
1231
|
+
(dir) =>
|
|
1232
|
+
Effect.gen(function* () {
|
|
1233
|
+
const { prompt, run, chat } = yield* boot()
|
|
1234
|
+
yield* Effect.promise(() => Bun.write(path.join(dir, "README.md"), "# e2e\n"))
|
|
1235
|
+
|
|
1236
|
+
const result = yield* prompt.shell({
|
|
1237
|
+
sessionID: chat.id,
|
|
1238
|
+
agent: "build",
|
|
1239
|
+
command: "command ls",
|
|
1240
|
+
})
|
|
1241
|
+
|
|
1242
|
+
expect(result.info.role).toBe("assistant")
|
|
1243
|
+
const tool = completedTool(result.parts)
|
|
1244
|
+
if (!tool) return
|
|
1245
|
+
|
|
1246
|
+
expect(tool.state.input.command).toBe("command ls")
|
|
1247
|
+
expect(tool.state.output).toContain("README.md")
|
|
1248
|
+
expect(tool.state.metadata.output).toContain("README.md")
|
|
1249
|
+
yield* run.assertNotBusy(chat.id)
|
|
1250
|
+
}),
|
|
1251
|
+
{ git: true, config: cfg },
|
|
1252
|
+
),
|
|
1253
|
+
)
|
|
1254
|
+
|
|
1255
|
+
unix("shell captures stderr from a failing command", () =>
|
|
1256
|
+
provideTmpdirInstance(
|
|
1257
|
+
(_dir) =>
|
|
1258
|
+
Effect.gen(function* () {
|
|
1259
|
+
const { prompt, run, chat } = yield* boot()
|
|
1260
|
+
const result = yield* prompt.shell({
|
|
1261
|
+
sessionID: chat.id,
|
|
1262
|
+
agent: "build",
|
|
1263
|
+
command: "command -v __nonexistent_cmd_e2e__ || echo 'not found' >&2; exit 1",
|
|
1264
|
+
})
|
|
1265
|
+
|
|
1266
|
+
expect(result.info.role).toBe("assistant")
|
|
1267
|
+
const tool = completedTool(result.parts)
|
|
1268
|
+
if (!tool) return
|
|
1269
|
+
|
|
1270
|
+
expect(tool.state.output).toContain("not found")
|
|
1271
|
+
expect(tool.state.metadata.output).toContain("not found")
|
|
1272
|
+
yield* run.assertNotBusy(chat.id)
|
|
1273
|
+
}),
|
|
1274
|
+
{ git: true, config: cfg },
|
|
1275
|
+
),
|
|
1276
|
+
)
|
|
1277
|
+
|
|
1278
|
+
unix(
|
|
1279
|
+
"shell updates running metadata before process exit",
|
|
1280
|
+
() =>
|
|
1281
|
+
withSh(() =>
|
|
1282
|
+
provideTmpdirInstance(
|
|
1283
|
+
(_dir) =>
|
|
1284
|
+
Effect.gen(function* () {
|
|
1285
|
+
const { prompt, chat } = yield* boot()
|
|
1286
|
+
|
|
1287
|
+
const fiber = yield* prompt
|
|
1288
|
+
.shell({ sessionID: chat.id, agent: "build", command: "printf first && sleep 0.2 && printf second" })
|
|
1289
|
+
.pipe(Effect.forkChild)
|
|
1290
|
+
|
|
1291
|
+
yield* Effect.promise(async () => {
|
|
1292
|
+
const start = Date.now()
|
|
1293
|
+
while (Date.now() - start < 5000) {
|
|
1294
|
+
const msgs = await MessageV2.filterCompacted(MessageV2.stream(chat.id))
|
|
1295
|
+
const taskMsg = msgs.find((item) => item.info.role === "assistant")
|
|
1296
|
+
const tool = taskMsg ? toolPart(taskMsg.parts) : undefined
|
|
1297
|
+
if (tool?.state.status === "running" && tool.state.metadata?.output.includes("first")) return
|
|
1298
|
+
await new Promise((done) => setTimeout(done, 20))
|
|
1299
|
+
}
|
|
1300
|
+
throw new Error("timed out waiting for running shell metadata")
|
|
1301
|
+
})
|
|
1302
|
+
|
|
1303
|
+
const exit = yield* Fiber.await(fiber)
|
|
1304
|
+
expect(Exit.isSuccess(exit)).toBe(true)
|
|
1305
|
+
}),
|
|
1306
|
+
{ git: true, config: cfg },
|
|
1307
|
+
),
|
|
1308
|
+
),
|
|
1309
|
+
30_000,
|
|
1310
|
+
)
|
|
1311
|
+
|
|
1312
|
+
it.live(
|
|
1313
|
+
"loop waits while shell runs and starts after shell exits",
|
|
1314
|
+
() =>
|
|
1315
|
+
provideTmpdirServer(
|
|
1316
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
1317
|
+
const prompt = yield* SessionPrompt.Service
|
|
1318
|
+
const sessions = yield* Session.Service
|
|
1319
|
+
const status = yield* SessionStatus.Service
|
|
1320
|
+
const chat = yield* sessions.create({
|
|
1321
|
+
title: "Pinned",
|
|
1322
|
+
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
1323
|
+
})
|
|
1324
|
+
yield* llm.text("after-shell")
|
|
1325
|
+
|
|
1326
|
+
const sh = yield* prompt
|
|
1327
|
+
.shell({ sessionID: chat.id, agent: "build", command: "sleep 0.2" })
|
|
1328
|
+
.pipe(Effect.forkChild)
|
|
1329
|
+
yield* waitFor("shell busy", status.get(chat.id).pipe(Effect.map((s) => (s.type === "busy" ? s : undefined))))
|
|
1330
|
+
|
|
1331
|
+
const loop = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
1332
|
+
yield* Effect.sleep(50)
|
|
1333
|
+
|
|
1334
|
+
expect(yield* llm.calls).toBe(0)
|
|
1335
|
+
|
|
1336
|
+
yield* Fiber.await(sh)
|
|
1337
|
+
const exit = yield* Fiber.await(loop)
|
|
1338
|
+
|
|
1339
|
+
expect(Exit.isSuccess(exit)).toBe(true)
|
|
1340
|
+
if (Exit.isSuccess(exit)) {
|
|
1341
|
+
expect(exit.value.info.role).toBe("assistant")
|
|
1342
|
+
expect(exit.value.parts.some((part) => part.type === "text" && part.text === "after-shell")).toBe(true)
|
|
1343
|
+
}
|
|
1344
|
+
expect(yield* llm.calls).toBe(1)
|
|
1345
|
+
}),
|
|
1346
|
+
{ git: true, config: providerCfg },
|
|
1347
|
+
),
|
|
1348
|
+
30_000,
|
|
1349
|
+
)
|
|
1350
|
+
|
|
1351
|
+
it.live(
|
|
1352
|
+
"shell completion resumes queued loop callers",
|
|
1353
|
+
() =>
|
|
1354
|
+
provideTmpdirServer(
|
|
1355
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
1356
|
+
const prompt = yield* SessionPrompt.Service
|
|
1357
|
+
const sessions = yield* Session.Service
|
|
1358
|
+
const status = yield* SessionStatus.Service
|
|
1359
|
+
const chat = yield* sessions.create({
|
|
1360
|
+
title: "Pinned",
|
|
1361
|
+
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
1362
|
+
})
|
|
1363
|
+
yield* llm.text("done")
|
|
1364
|
+
|
|
1365
|
+
const sh = yield* prompt
|
|
1366
|
+
.shell({ sessionID: chat.id, agent: "build", command: "sleep 0.2" })
|
|
1367
|
+
.pipe(Effect.forkChild)
|
|
1368
|
+
yield* waitFor("shell busy", status.get(chat.id).pipe(Effect.map((s) => (s.type === "busy" ? s : undefined))))
|
|
1369
|
+
|
|
1370
|
+
const a = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
1371
|
+
const b = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
1372
|
+
yield* Effect.sleep(50)
|
|
1373
|
+
|
|
1374
|
+
expect(yield* llm.calls).toBe(0)
|
|
1375
|
+
|
|
1376
|
+
yield* Fiber.await(sh)
|
|
1377
|
+
const [ea, eb] = yield* Effect.all([Fiber.await(a), Fiber.await(b)])
|
|
1378
|
+
|
|
1379
|
+
expect(Exit.isSuccess(ea)).toBe(true)
|
|
1380
|
+
expect(Exit.isSuccess(eb)).toBe(true)
|
|
1381
|
+
if (Exit.isSuccess(ea) && Exit.isSuccess(eb)) {
|
|
1382
|
+
expect(ea.value.info.id).toBe(eb.value.info.id)
|
|
1383
|
+
expect(ea.value.info.role).toBe("assistant")
|
|
1384
|
+
}
|
|
1385
|
+
expect(yield* llm.calls).toBe(1)
|
|
1386
|
+
}),
|
|
1387
|
+
{ git: true, config: providerCfg },
|
|
1388
|
+
),
|
|
1389
|
+
30_000,
|
|
1390
|
+
)
|
|
1391
|
+
|
|
1392
|
+
unix(
|
|
1393
|
+
"command ! expansion uses configured shell over env shell",
|
|
1394
|
+
() =>
|
|
1395
|
+
withSh(() =>
|
|
1396
|
+
provideTmpdirServer(
|
|
1397
|
+
({ llm }) =>
|
|
1398
|
+
Effect.gen(function* () {
|
|
1399
|
+
if (!Bun.which("bash")) return
|
|
1400
|
+
|
|
1401
|
+
const { prompt, chat } = yield* boot()
|
|
1402
|
+
yield* llm.text("done")
|
|
1403
|
+
|
|
1404
|
+
const result = yield* prompt.command({
|
|
1405
|
+
sessionID: chat.id,
|
|
1406
|
+
command: "probe",
|
|
1407
|
+
arguments: "",
|
|
1408
|
+
})
|
|
1409
|
+
|
|
1410
|
+
expect(result.info.role).toBe("assistant")
|
|
1411
|
+
const inputs = yield* llm.inputs
|
|
1412
|
+
expect(JSON.stringify(inputs.at(-1)?.messages)).toContain("configured")
|
|
1413
|
+
}),
|
|
1414
|
+
{
|
|
1415
|
+
git: true,
|
|
1416
|
+
config: (url) => ({
|
|
1417
|
+
...providerCfg(url),
|
|
1418
|
+
shell: "bash",
|
|
1419
|
+
command: {
|
|
1420
|
+
probe: {
|
|
1421
|
+
template: "Probe: !`[[ 1 -eq 1 ]] && printf configured`",
|
|
1422
|
+
},
|
|
1423
|
+
},
|
|
1424
|
+
}),
|
|
1425
|
+
},
|
|
1426
|
+
),
|
|
1427
|
+
),
|
|
1428
|
+
30_000,
|
|
1429
|
+
)
|
|
1430
|
+
|
|
1431
|
+
unix(
|
|
1432
|
+
"cancel interrupts shell and resolves cleanly",
|
|
1433
|
+
() =>
|
|
1434
|
+
withSh(() =>
|
|
1435
|
+
provideTmpdirInstance(
|
|
1436
|
+
(_dir) =>
|
|
1437
|
+
Effect.gen(function* () {
|
|
1438
|
+
const { prompt, run, chat } = yield* boot()
|
|
1439
|
+
|
|
1440
|
+
const sh = yield* prompt
|
|
1441
|
+
.shell({ sessionID: chat.id, agent: "build", command: "sleep 30" })
|
|
1442
|
+
.pipe(Effect.forkChild)
|
|
1443
|
+
yield* Effect.sleep(50)
|
|
1444
|
+
|
|
1445
|
+
yield* prompt.cancel(chat.id)
|
|
1446
|
+
|
|
1447
|
+
const status = yield* SessionStatus.Service
|
|
1448
|
+
expect((yield* status.get(chat.id)).type).toBe("idle")
|
|
1449
|
+
const busy = yield* run.assertNotBusy(chat.id).pipe(Effect.exit)
|
|
1450
|
+
expect(Exit.isSuccess(busy)).toBe(true)
|
|
1451
|
+
|
|
1452
|
+
const exit = yield* Fiber.await(sh)
|
|
1453
|
+
expect(Exit.isSuccess(exit)).toBe(true)
|
|
1454
|
+
if (Exit.isSuccess(exit)) {
|
|
1455
|
+
expect(exit.value.info.role).toBe("assistant")
|
|
1456
|
+
const tool = completedTool(exit.value.parts)
|
|
1457
|
+
if (tool) {
|
|
1458
|
+
expect(tool.state.output).toContain("User aborted the command")
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}),
|
|
1462
|
+
{ git: true, config: cfg },
|
|
1463
|
+
),
|
|
1464
|
+
),
|
|
1465
|
+
30_000,
|
|
1466
|
+
)
|
|
1467
|
+
unix(
|
|
1468
|
+
"cancel persists aborted shell result when shell ignores TERM",
|
|
1469
|
+
() =>
|
|
1470
|
+
withSh(() =>
|
|
1471
|
+
provideTmpdirInstance(
|
|
1472
|
+
(_dir) =>
|
|
1473
|
+
Effect.gen(function* () {
|
|
1474
|
+
const { prompt, chat, sessions } = yield* boot()
|
|
1475
|
+
|
|
1476
|
+
const sh = yield* prompt
|
|
1477
|
+
.shell({
|
|
1478
|
+
sessionID: chat.id,
|
|
1479
|
+
agent: "build",
|
|
1480
|
+
command: "trap '' TERM; printf started; sleep 10; printf not-killed",
|
|
1481
|
+
})
|
|
1482
|
+
.pipe(Effect.forkChild)
|
|
1483
|
+
yield* waitFor(
|
|
1484
|
+
"shell start output",
|
|
1485
|
+
sessions
|
|
1486
|
+
.messages({ sessionID: chat.id })
|
|
1487
|
+
.pipe(
|
|
1488
|
+
Effect.map((msgs) =>
|
|
1489
|
+
msgs
|
|
1490
|
+
.flatMap((msg) => msg.parts)
|
|
1491
|
+
.find(
|
|
1492
|
+
(part) =>
|
|
1493
|
+
part.type === "tool" &&
|
|
1494
|
+
part.state.status === "running" &&
|
|
1495
|
+
(part.state.metadata?.output ?? "").includes("started"),
|
|
1496
|
+
),
|
|
1497
|
+
),
|
|
1498
|
+
),
|
|
1499
|
+
)
|
|
1500
|
+
|
|
1501
|
+
yield* prompt.cancel(chat.id)
|
|
1502
|
+
|
|
1503
|
+
const exit = yield* Fiber.await(sh)
|
|
1504
|
+
expect(Exit.isSuccess(exit)).toBe(true)
|
|
1505
|
+
if (Exit.isSuccess(exit)) {
|
|
1506
|
+
expect(exit.value.info.role).toBe("assistant")
|
|
1507
|
+
const tool = completedTool(exit.value.parts)
|
|
1508
|
+
if (tool) {
|
|
1509
|
+
expect(tool.state.output).toContain("started")
|
|
1510
|
+
expect(tool.state.output).toContain("User aborted the command")
|
|
1511
|
+
expect(tool.state.output).not.toContain("not-killed")
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
}),
|
|
1515
|
+
{ git: true, config: cfg },
|
|
1516
|
+
),
|
|
1517
|
+
),
|
|
1518
|
+
30_000,
|
|
1519
|
+
)
|
|
1520
|
+
|
|
1521
|
+
unix(
|
|
1522
|
+
"cancel finalizes interrupted bash tool output through normal truncation",
|
|
1523
|
+
() =>
|
|
1524
|
+
provideTmpdirServer(
|
|
1525
|
+
({ dir, llm }) =>
|
|
1526
|
+
Effect.gen(function* () {
|
|
1527
|
+
const prompt = yield* SessionPrompt.Service
|
|
1528
|
+
const sessions = yield* Session.Service
|
|
1529
|
+
const chat = yield* sessions.create({
|
|
1530
|
+
title: "Interrupted bash truncation",
|
|
1531
|
+
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
1532
|
+
})
|
|
1533
|
+
|
|
1534
|
+
yield* prompt.prompt({
|
|
1535
|
+
sessionID: chat.id,
|
|
1536
|
+
agent: "build",
|
|
1537
|
+
noReply: true,
|
|
1538
|
+
parts: [{ type: "text", text: "run bash" }],
|
|
1539
|
+
})
|
|
1540
|
+
|
|
1541
|
+
yield* llm.tool("bash", {
|
|
1542
|
+
command:
|
|
1543
|
+
'i=0; while [ "$i" -lt 4000 ]; do printf "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx %05d\\n" "$i"; i=$((i + 1)); done; sleep 30',
|
|
1544
|
+
description: "Print many lines",
|
|
1545
|
+
timeout: 30_000,
|
|
1546
|
+
workdir: path.resolve(dir),
|
|
1547
|
+
})
|
|
1548
|
+
|
|
1549
|
+
const run = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
1550
|
+
yield* llm.wait(1)
|
|
1551
|
+
yield* Effect.sleep(150)
|
|
1552
|
+
yield* prompt.cancel(chat.id)
|
|
1553
|
+
|
|
1554
|
+
const exit = yield* Fiber.await(run)
|
|
1555
|
+
expect(Exit.isSuccess(exit)).toBe(true)
|
|
1556
|
+
if (Exit.isFailure(exit)) return
|
|
1557
|
+
|
|
1558
|
+
const tool = completedTool(exit.value.parts)
|
|
1559
|
+
if (!tool) return
|
|
1560
|
+
|
|
1561
|
+
expect(tool.state.metadata.truncated).toBe(true)
|
|
1562
|
+
expect(typeof tool.state.metadata.outputPath).toBe("string")
|
|
1563
|
+
expect(tool.state.output).toMatch(/\.\.\.output truncated\.\.\./)
|
|
1564
|
+
expect(tool.state.output).toMatch(/Full output saved to:\s+\S+/)
|
|
1565
|
+
expect(tool.state.output).not.toContain("Tool execution aborted")
|
|
1566
|
+
}),
|
|
1567
|
+
{ git: true, config: providerCfg },
|
|
1568
|
+
),
|
|
1569
|
+
30_000,
|
|
1570
|
+
)
|
|
1571
|
+
|
|
1572
|
+
unix(
|
|
1573
|
+
"cancel interrupts loop queued behind shell",
|
|
1574
|
+
() =>
|
|
1575
|
+
provideTmpdirInstance(
|
|
1576
|
+
(_dir) =>
|
|
1577
|
+
Effect.gen(function* () {
|
|
1578
|
+
const { prompt, chat } = yield* boot()
|
|
1579
|
+
|
|
1580
|
+
const sh = yield* prompt
|
|
1581
|
+
.shell({ sessionID: chat.id, agent: "build", command: "sleep 30" })
|
|
1582
|
+
.pipe(Effect.forkChild)
|
|
1583
|
+
yield* Effect.sleep(50)
|
|
1584
|
+
|
|
1585
|
+
const loop = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
|
|
1586
|
+
yield* Effect.sleep(50)
|
|
1587
|
+
|
|
1588
|
+
yield* prompt.cancel(chat.id)
|
|
1589
|
+
|
|
1590
|
+
const exit = yield* Fiber.await(loop)
|
|
1591
|
+
expect(Exit.isSuccess(exit)).toBe(true)
|
|
1592
|
+
if (Exit.isSuccess(exit)) {
|
|
1593
|
+
const tool = completedTool(exit.value.parts)
|
|
1594
|
+
expect(tool?.state.output).toContain("User aborted the command")
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
yield* Fiber.await(sh)
|
|
1598
|
+
}),
|
|
1599
|
+
{ git: true, config: cfg },
|
|
1600
|
+
),
|
|
1601
|
+
30_000,
|
|
1602
|
+
)
|
|
1603
|
+
|
|
1604
|
+
unix(
|
|
1605
|
+
"shell rejects when another shell is already running",
|
|
1606
|
+
() =>
|
|
1607
|
+
withSh(() =>
|
|
1608
|
+
provideTmpdirInstance(
|
|
1609
|
+
(_dir) =>
|
|
1610
|
+
Effect.gen(function* () {
|
|
1611
|
+
const { prompt, chat } = yield* boot()
|
|
1612
|
+
|
|
1613
|
+
const a = yield* prompt
|
|
1614
|
+
.shell({ sessionID: chat.id, agent: "build", command: "sleep 30" })
|
|
1615
|
+
.pipe(Effect.forkChild)
|
|
1616
|
+
yield* Effect.sleep(50)
|
|
1617
|
+
|
|
1618
|
+
const exit = yield* prompt
|
|
1619
|
+
.shell({ sessionID: chat.id, agent: "build", command: "echo hi" })
|
|
1620
|
+
.pipe(Effect.exit)
|
|
1621
|
+
expect(Exit.isFailure(exit)).toBe(true)
|
|
1622
|
+
if (Exit.isFailure(exit)) {
|
|
1623
|
+
expect(Cause.squash(exit.cause)).toBeInstanceOf(Session.BusyError)
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
yield* prompt.cancel(chat.id)
|
|
1627
|
+
yield* Fiber.await(a)
|
|
1628
|
+
}),
|
|
1629
|
+
{ git: true, config: cfg },
|
|
1630
|
+
),
|
|
1631
|
+
),
|
|
1632
|
+
30_000,
|
|
1633
|
+
)
|
|
1634
|
+
|
|
1635
|
+
// Abort signal propagation tests for inline tool execution
|
|
1636
|
+
|
|
1637
|
+
/** Override a tool's execute to hang until aborted. Returns ready/aborted defers and a finalizer. */
|
|
1638
|
+
function hangUntilAborted(tool: { execute: (...args: any[]) => any }) {
|
|
1639
|
+
const ready = defer<void>()
|
|
1640
|
+
const aborted = defer<void>()
|
|
1641
|
+
const original = tool.execute
|
|
1642
|
+
tool.execute = (_args: any, ctx: any) => {
|
|
1643
|
+
ready.resolve()
|
|
1644
|
+
ctx.abort.addEventListener("abort", () => aborted.resolve(), { once: true })
|
|
1645
|
+
return Effect.callback<never>(() => {})
|
|
1646
|
+
}
|
|
1647
|
+
const restore = Effect.addFinalizer(() => Effect.sync(() => void (tool.execute = original)))
|
|
1648
|
+
return { ready, aborted, restore }
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
it.live(
|
|
1652
|
+
"interrupt propagates abort signal to read tool via file part (text/plain)",
|
|
1653
|
+
() =>
|
|
1654
|
+
provideTmpdirInstance(
|
|
1655
|
+
(dir) =>
|
|
1656
|
+
Effect.gen(function* () {
|
|
1657
|
+
const registry = yield* ToolRegistry.Service
|
|
1658
|
+
const { read } = yield* registry.named()
|
|
1659
|
+
const { ready, aborted, restore } = hangUntilAborted(read)
|
|
1660
|
+
yield* restore
|
|
1661
|
+
|
|
1662
|
+
const prompt = yield* SessionPrompt.Service
|
|
1663
|
+
const sessions = yield* Session.Service
|
|
1664
|
+
const chat = yield* sessions.create({ title: "Abort Test" })
|
|
1665
|
+
|
|
1666
|
+
const testFile = path.join(dir, "test.txt")
|
|
1667
|
+
yield* Effect.promise(() => Bun.write(testFile, "hello world"))
|
|
1668
|
+
|
|
1669
|
+
const fiber = yield* prompt
|
|
1670
|
+
.prompt({
|
|
1671
|
+
sessionID: chat.id,
|
|
1672
|
+
agent: "build",
|
|
1673
|
+
parts: [
|
|
1674
|
+
{ type: "text", text: "read this" },
|
|
1675
|
+
{ type: "file", url: `file://${testFile}`, filename: "test.txt", mime: "text/plain" },
|
|
1676
|
+
],
|
|
1677
|
+
})
|
|
1678
|
+
.pipe(Effect.forkChild)
|
|
1679
|
+
|
|
1680
|
+
yield* Effect.promise(() => ready.promise)
|
|
1681
|
+
yield* Fiber.interrupt(fiber)
|
|
1682
|
+
|
|
1683
|
+
yield* Effect.promise(() =>
|
|
1684
|
+
Promise.race([
|
|
1685
|
+
aborted.promise,
|
|
1686
|
+
new Promise<void>((_, reject) =>
|
|
1687
|
+
setTimeout(() => reject(new Error("abort signal not propagated within 2s")), 2_000),
|
|
1688
|
+
),
|
|
1689
|
+
]),
|
|
1690
|
+
)
|
|
1691
|
+
}),
|
|
1692
|
+
{ git: true, config: cfg },
|
|
1693
|
+
),
|
|
1694
|
+
30_000,
|
|
1695
|
+
)
|
|
1696
|
+
|
|
1697
|
+
it.live(
|
|
1698
|
+
"interrupt propagates abort signal to read tool via file part (directory)",
|
|
1699
|
+
() =>
|
|
1700
|
+
provideTmpdirInstance(
|
|
1701
|
+
(dir) =>
|
|
1702
|
+
Effect.gen(function* () {
|
|
1703
|
+
const registry = yield* ToolRegistry.Service
|
|
1704
|
+
const { read } = yield* registry.named()
|
|
1705
|
+
const { ready, aborted, restore } = hangUntilAborted(read)
|
|
1706
|
+
yield* restore
|
|
1707
|
+
|
|
1708
|
+
const prompt = yield* SessionPrompt.Service
|
|
1709
|
+
const sessions = yield* Session.Service
|
|
1710
|
+
const chat = yield* sessions.create({ title: "Abort Test" })
|
|
1711
|
+
|
|
1712
|
+
const fiber = yield* prompt
|
|
1713
|
+
.prompt({
|
|
1714
|
+
sessionID: chat.id,
|
|
1715
|
+
agent: "build",
|
|
1716
|
+
parts: [
|
|
1717
|
+
{ type: "text", text: "read this" },
|
|
1718
|
+
{ type: "file", url: `file://${dir}`, filename: "dir", mime: "application/x-directory" },
|
|
1719
|
+
],
|
|
1720
|
+
})
|
|
1721
|
+
.pipe(Effect.forkChild)
|
|
1722
|
+
|
|
1723
|
+
yield* Effect.promise(() => ready.promise)
|
|
1724
|
+
yield* Fiber.interrupt(fiber)
|
|
1725
|
+
|
|
1726
|
+
yield* Effect.promise(() =>
|
|
1727
|
+
Promise.race([
|
|
1728
|
+
aborted.promise,
|
|
1729
|
+
new Promise<void>((_, reject) =>
|
|
1730
|
+
setTimeout(() => reject(new Error("abort signal not propagated within 2s")), 2_000),
|
|
1731
|
+
),
|
|
1732
|
+
]),
|
|
1733
|
+
)
|
|
1734
|
+
}),
|
|
1735
|
+
{ git: true, config: cfg },
|
|
1736
|
+
),
|
|
1737
|
+
30_000,
|
|
1738
|
+
)
|
|
1739
|
+
|
|
1740
|
+
// Missing file handling
|
|
1741
|
+
|
|
1742
|
+
it.live("does not fail the prompt when a file part is missing", () =>
|
|
1743
|
+
provideTmpdirInstance(
|
|
1744
|
+
(dir) =>
|
|
1745
|
+
Effect.gen(function* () {
|
|
1746
|
+
const prompt = yield* SessionPrompt.Service
|
|
1747
|
+
const sessions = yield* Session.Service
|
|
1748
|
+
const session = yield* sessions.create({})
|
|
1749
|
+
|
|
1750
|
+
const missing = path.join(dir, "does-not-exist.ts")
|
|
1751
|
+
const msg = yield* prompt.prompt({
|
|
1752
|
+
sessionID: session.id,
|
|
1753
|
+
agent: "build",
|
|
1754
|
+
noReply: true,
|
|
1755
|
+
parts: [
|
|
1756
|
+
{ type: "text", text: "please review @does-not-exist.ts" },
|
|
1757
|
+
{
|
|
1758
|
+
type: "file",
|
|
1759
|
+
mime: "text/plain",
|
|
1760
|
+
url: `file://${missing}`,
|
|
1761
|
+
filename: "does-not-exist.ts",
|
|
1762
|
+
},
|
|
1763
|
+
],
|
|
1764
|
+
})
|
|
1765
|
+
|
|
1766
|
+
if (msg.info.role !== "user") throw new Error("expected user message")
|
|
1767
|
+
const hasFailure = msg.parts.some(
|
|
1768
|
+
(part) => part.type === "text" && part.synthetic && part.text.includes("Read tool failed to read"),
|
|
1769
|
+
)
|
|
1770
|
+
expect(hasFailure).toBe(true)
|
|
1771
|
+
|
|
1772
|
+
yield* sessions.remove(session.id)
|
|
1773
|
+
}),
|
|
1774
|
+
{ git: true, config: cfg },
|
|
1775
|
+
),
|
|
1776
|
+
)
|
|
1777
|
+
|
|
1778
|
+
it.live("keeps stored part order stable when file resolution is async", () =>
|
|
1779
|
+
provideTmpdirInstance(
|
|
1780
|
+
(dir) =>
|
|
1781
|
+
Effect.gen(function* () {
|
|
1782
|
+
const prompt = yield* SessionPrompt.Service
|
|
1783
|
+
const sessions = yield* Session.Service
|
|
1784
|
+
const session = yield* sessions.create({})
|
|
1785
|
+
|
|
1786
|
+
const missing = path.join(dir, "still-missing.ts")
|
|
1787
|
+
const msg = yield* prompt.prompt({
|
|
1788
|
+
sessionID: session.id,
|
|
1789
|
+
agent: "build",
|
|
1790
|
+
noReply: true,
|
|
1791
|
+
parts: [
|
|
1792
|
+
{
|
|
1793
|
+
type: "file",
|
|
1794
|
+
mime: "text/plain",
|
|
1795
|
+
url: `file://${missing}`,
|
|
1796
|
+
filename: "still-missing.ts",
|
|
1797
|
+
},
|
|
1798
|
+
{ type: "text", text: "after-file" },
|
|
1799
|
+
],
|
|
1800
|
+
})
|
|
1801
|
+
|
|
1802
|
+
if (msg.info.role !== "user") throw new Error("expected user message")
|
|
1803
|
+
|
|
1804
|
+
const stored = MessageV2.get({
|
|
1805
|
+
sessionID: session.id,
|
|
1806
|
+
messageID: msg.info.id,
|
|
1807
|
+
})
|
|
1808
|
+
const text = stored.parts.filter((part) => part.type === "text").map((part) => part.text)
|
|
1809
|
+
|
|
1810
|
+
expect(text[0]?.startsWith("Called the Read tool with the following input:")).toBe(true)
|
|
1811
|
+
expect(text[1]?.includes("Read tool failed to read")).toBe(true)
|
|
1812
|
+
expect(text[2]).toBe("after-file")
|
|
1813
|
+
|
|
1814
|
+
yield* sessions.remove(session.id)
|
|
1815
|
+
}),
|
|
1816
|
+
{ git: true, config: cfg },
|
|
1817
|
+
),
|
|
1818
|
+
)
|
|
1819
|
+
|
|
1820
|
+
// Special characters in filenames
|
|
1821
|
+
|
|
1822
|
+
it.live("handles filenames with # character", () =>
|
|
1823
|
+
provideTmpdirInstance(
|
|
1824
|
+
(dir) =>
|
|
1825
|
+
Effect.gen(function* () {
|
|
1826
|
+
yield* Effect.promise(() => Bun.write(path.join(dir, "file#name.txt"), "special content\n"))
|
|
1827
|
+
|
|
1828
|
+
const prompt = yield* SessionPrompt.Service
|
|
1829
|
+
const sessions = yield* Session.Service
|
|
1830
|
+
const session = yield* sessions.create({})
|
|
1831
|
+
const parts = yield* prompt.resolvePromptParts("Read @file#name.txt")
|
|
1832
|
+
const fileParts = parts.filter((part) => part.type === "file")
|
|
1833
|
+
|
|
1834
|
+
expect(fileParts.length).toBe(1)
|
|
1835
|
+
expect(fileParts[0].filename).toBe("file#name.txt")
|
|
1836
|
+
expect(fileParts[0].url).toContain("%23")
|
|
1837
|
+
|
|
1838
|
+
const decodedPath = fileURLToPath(fileParts[0].url)
|
|
1839
|
+
expect(decodedPath).toBe(path.join(dir, "file#name.txt"))
|
|
1840
|
+
|
|
1841
|
+
const message = yield* prompt.prompt({
|
|
1842
|
+
sessionID: session.id,
|
|
1843
|
+
parts,
|
|
1844
|
+
noReply: true,
|
|
1845
|
+
})
|
|
1846
|
+
const stored = MessageV2.get({ sessionID: session.id, messageID: message.info.id })
|
|
1847
|
+
const textParts = stored.parts.filter((part) => part.type === "text")
|
|
1848
|
+
const hasContent = textParts.some((part) => part.text.includes("special content"))
|
|
1849
|
+
expect(hasContent).toBe(true)
|
|
1850
|
+
|
|
1851
|
+
yield* sessions.remove(session.id)
|
|
1852
|
+
}),
|
|
1853
|
+
{ git: true, config: cfg },
|
|
1854
|
+
),
|
|
1855
|
+
)
|
|
1856
|
+
|
|
1857
|
+
// Regression: empty assistant turn loop
|
|
1858
|
+
|
|
1859
|
+
it.live("does not loop empty assistant turns for a simple reply", () =>
|
|
1860
|
+
provideTmpdirServer(
|
|
1861
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
1862
|
+
const prompt = yield* SessionPrompt.Service
|
|
1863
|
+
const sessions = yield* Session.Service
|
|
1864
|
+
const session = yield* sessions.create({ title: "Prompt regression" })
|
|
1865
|
+
|
|
1866
|
+
yield* llm.text("packages/saeeol/src/session/processor.ts")
|
|
1867
|
+
|
|
1868
|
+
const result = yield* prompt.prompt({
|
|
1869
|
+
sessionID: session.id,
|
|
1870
|
+
agent: "build",
|
|
1871
|
+
parts: [{ type: "text", text: "Where is SessionProcessor?" }],
|
|
1872
|
+
})
|
|
1873
|
+
|
|
1874
|
+
expect(result.info.role).toBe("assistant")
|
|
1875
|
+
expect(result.parts.some((part) => part.type === "text" && part.text.includes("processor.ts"))).toBe(true)
|
|
1876
|
+
|
|
1877
|
+
const msgs = yield* sessions.messages({ sessionID: session.id })
|
|
1878
|
+
expect(msgs.filter((msg) => msg.info.role === "assistant")).toHaveLength(1)
|
|
1879
|
+
expect(yield* llm.calls).toBe(1)
|
|
1880
|
+
}),
|
|
1881
|
+
{ git: true, config: providerCfg },
|
|
1882
|
+
),
|
|
1883
|
+
)
|
|
1884
|
+
|
|
1885
|
+
it.live(
|
|
1886
|
+
"records aborted errors when prompt is cancelled mid-stream",
|
|
1887
|
+
() =>
|
|
1888
|
+
provideTmpdirServer(
|
|
1889
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
1890
|
+
const prompt = yield* SessionPrompt.Service
|
|
1891
|
+
const sessions = yield* Session.Service
|
|
1892
|
+
const session = yield* sessions.create({ title: "Prompt cancel regression" })
|
|
1893
|
+
|
|
1894
|
+
yield* llm.hang
|
|
1895
|
+
|
|
1896
|
+
const fiber = yield* prompt
|
|
1897
|
+
.prompt({
|
|
1898
|
+
sessionID: session.id,
|
|
1899
|
+
agent: "build",
|
|
1900
|
+
parts: [{ type: "text", text: "Cancel me" }],
|
|
1901
|
+
})
|
|
1902
|
+
.pipe(Effect.forkChild)
|
|
1903
|
+
|
|
1904
|
+
yield* llm.wait(1)
|
|
1905
|
+
yield* prompt.cancel(session.id)
|
|
1906
|
+
|
|
1907
|
+
const exit = yield* Fiber.await(fiber)
|
|
1908
|
+
expect(Exit.isSuccess(exit)).toBe(true)
|
|
1909
|
+
if (Exit.isSuccess(exit)) {
|
|
1910
|
+
expect(exit.value.info.role).toBe("assistant")
|
|
1911
|
+
if (exit.value.info.role === "assistant") {
|
|
1912
|
+
expect(exit.value.info.error?.name).toBe("MessageAbortedError")
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
const msgs = yield* sessions.messages({ sessionID: session.id })
|
|
1917
|
+
const last = msgs.findLast((msg) => msg.info.role === "assistant")
|
|
1918
|
+
expect(last?.info.role).toBe("assistant")
|
|
1919
|
+
if (last?.info.role === "assistant") {
|
|
1920
|
+
expect(last.info.error?.name).toBe("MessageAbortedError")
|
|
1921
|
+
}
|
|
1922
|
+
}),
|
|
1923
|
+
{ git: true, config: providerCfg },
|
|
1924
|
+
),
|
|
1925
|
+
3_000,
|
|
1926
|
+
)
|
|
1927
|
+
|
|
1928
|
+
// Agent variant
|
|
1929
|
+
|
|
1930
|
+
it.live("applies agent variant only when using agent model", () =>
|
|
1931
|
+
provideTmpdirInstance(
|
|
1932
|
+
(_dir) =>
|
|
1933
|
+
Effect.gen(function* () {
|
|
1934
|
+
const prompt = yield* SessionPrompt.Service
|
|
1935
|
+
const sessions = yield* Session.Service
|
|
1936
|
+
const session = yield* sessions.create({})
|
|
1937
|
+
|
|
1938
|
+
const other = yield* prompt.prompt({
|
|
1939
|
+
sessionID: session.id,
|
|
1940
|
+
agent: "build",
|
|
1941
|
+
model: { providerID: ProviderID.make("saeeol"), modelID: ModelID.make("kimi-k2.5-free") },
|
|
1942
|
+
noReply: true,
|
|
1943
|
+
parts: [{ type: "text", text: "hello" }],
|
|
1944
|
+
})
|
|
1945
|
+
if (other.info.role !== "user") throw new Error("expected user message")
|
|
1946
|
+
expect(other.info.model.variant).toBeUndefined()
|
|
1947
|
+
|
|
1948
|
+
const match = yield* prompt.prompt({
|
|
1949
|
+
sessionID: session.id,
|
|
1950
|
+
agent: "build",
|
|
1951
|
+
noReply: true,
|
|
1952
|
+
parts: [{ type: "text", text: "hello again" }],
|
|
1953
|
+
})
|
|
1954
|
+
if (match.info.role !== "user") throw new Error("expected user message")
|
|
1955
|
+
expect(match.info.model).toEqual({
|
|
1956
|
+
providerID: ProviderID.make("test"),
|
|
1957
|
+
modelID: ModelID.make("test-model"),
|
|
1958
|
+
variant: "xhigh",
|
|
1959
|
+
})
|
|
1960
|
+
expect(match.info.model.variant).toBe("xhigh")
|
|
1961
|
+
|
|
1962
|
+
const override = yield* prompt.prompt({
|
|
1963
|
+
sessionID: session.id,
|
|
1964
|
+
agent: "build",
|
|
1965
|
+
noReply: true,
|
|
1966
|
+
variant: "high",
|
|
1967
|
+
parts: [{ type: "text", text: "hello third" }],
|
|
1968
|
+
})
|
|
1969
|
+
if (override.info.role !== "user") throw new Error("expected user message")
|
|
1970
|
+
expect(override.info.model.variant).toBe("high")
|
|
1971
|
+
|
|
1972
|
+
yield* sessions.remove(session.id)
|
|
1973
|
+
}),
|
|
1974
|
+
{
|
|
1975
|
+
git: true,
|
|
1976
|
+
config: {
|
|
1977
|
+
...cfg,
|
|
1978
|
+
provider: {
|
|
1979
|
+
...cfg.provider,
|
|
1980
|
+
test: {
|
|
1981
|
+
...cfg.provider.test,
|
|
1982
|
+
models: {
|
|
1983
|
+
"test-model": {
|
|
1984
|
+
...cfg.provider.test.models["test-model"],
|
|
1985
|
+
variants: { xhigh: {}, high: {} },
|
|
1986
|
+
},
|
|
1987
|
+
},
|
|
1988
|
+
},
|
|
1989
|
+
},
|
|
1990
|
+
agent: {
|
|
1991
|
+
build: {
|
|
1992
|
+
model: "test/test-model",
|
|
1993
|
+
variant: "xhigh",
|
|
1994
|
+
},
|
|
1995
|
+
},
|
|
1996
|
+
},
|
|
1997
|
+
},
|
|
1998
|
+
),
|
|
1999
|
+
)
|
|
2000
|
+
it.live(
|
|
2001
|
+
"review command marks child completions with review telemetry",
|
|
2002
|
+
() =>
|
|
2003
|
+
provideTmpdirServer(
|
|
2004
|
+
Effect.fnUntraced(function* ({ llm }) {
|
|
2005
|
+
const trackSpy = spyOn(Telemetry, "trackLlmCompletion")
|
|
2006
|
+
const prompt = yield* SessionPrompt.Service
|
|
2007
|
+
const sessions = yield* Session.Service
|
|
2008
|
+
const chat = yield* sessions.create({
|
|
2009
|
+
title: "Review telemetry",
|
|
2010
|
+
permission: [{ permission: "*", pattern: "*", action: "allow" }],
|
|
2011
|
+
})
|
|
2012
|
+
|
|
2013
|
+
// child subagent's first LLM step needs non-zero usage so trackStep fires
|
|
2014
|
+
yield* llm.text("review done", { usage: { input: 100, output: 50 } })
|
|
2015
|
+
|
|
2016
|
+
yield* prompt.command({
|
|
2017
|
+
sessionID: chat.id,
|
|
2018
|
+
command: "review",
|
|
2019
|
+
arguments: "",
|
|
2020
|
+
agent: "general",
|
|
2021
|
+
})
|
|
2022
|
+
|
|
2023
|
+
const tagged = trackSpy.mock.calls
|
|
2024
|
+
.map((args) => args[0] as Parameters<typeof Telemetry.trackLlmCompletion>[0])
|
|
2025
|
+
.find((p) => p.mode === "review" && p.feature === "code_reviews" && p.command === "review")
|
|
2026
|
+
expect(tagged).toBeDefined()
|
|
2027
|
+
}),
|
|
2028
|
+
{ git: true, config: providerCfg },
|
|
2029
|
+
),
|
|
2030
|
+
30_000,
|
|
2031
|
+
)
|
|
2032
|
+
|
|
2033
|
+
// Agent / command resolution errors
|
|
2034
|
+
|
|
2035
|
+
it.live(
|
|
2036
|
+
"unknown agent throws typed error",
|
|
2037
|
+
() =>
|
|
2038
|
+
provideTmpdirInstance(
|
|
2039
|
+
(_dir) =>
|
|
2040
|
+
Effect.gen(function* () {
|
|
2041
|
+
const prompt = yield* SessionPrompt.Service
|
|
2042
|
+
const sessions = yield* Session.Service
|
|
2043
|
+
const session = yield* sessions.create({})
|
|
2044
|
+
const exit = yield* prompt
|
|
2045
|
+
.prompt({
|
|
2046
|
+
sessionID: session.id,
|
|
2047
|
+
agent: "nonexistent-agent-xyz",
|
|
2048
|
+
noReply: true,
|
|
2049
|
+
parts: [{ type: "text", text: "hello" }],
|
|
2050
|
+
})
|
|
2051
|
+
.pipe(Effect.exit)
|
|
2052
|
+
|
|
2053
|
+
expect(Exit.isFailure(exit)).toBe(true)
|
|
2054
|
+
if (Exit.isFailure(exit)) {
|
|
2055
|
+
const err = Cause.squash(exit.cause)
|
|
2056
|
+
expect(err).not.toBeInstanceOf(TypeError)
|
|
2057
|
+
expect(NamedError.Unknown.isInstance(err)).toBe(true)
|
|
2058
|
+
if (NamedError.Unknown.isInstance(err)) {
|
|
2059
|
+
expect(err.data.message).toContain('Agent not found: "nonexistent-agent-xyz"')
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
}),
|
|
2063
|
+
{ git: true },
|
|
2064
|
+
),
|
|
2065
|
+
30_000,
|
|
2066
|
+
)
|
|
2067
|
+
|
|
2068
|
+
it.live(
|
|
2069
|
+
"unknown agent error includes available agent names",
|
|
2070
|
+
() =>
|
|
2071
|
+
provideTmpdirInstance(
|
|
2072
|
+
(_dir) =>
|
|
2073
|
+
Effect.gen(function* () {
|
|
2074
|
+
const prompt = yield* SessionPrompt.Service
|
|
2075
|
+
const sessions = yield* Session.Service
|
|
2076
|
+
const session = yield* sessions.create({})
|
|
2077
|
+
const exit = yield* prompt
|
|
2078
|
+
.prompt({
|
|
2079
|
+
sessionID: session.id,
|
|
2080
|
+
agent: "nonexistent-agent-xyz",
|
|
2081
|
+
noReply: true,
|
|
2082
|
+
parts: [{ type: "text", text: "hello" }],
|
|
2083
|
+
})
|
|
2084
|
+
.pipe(Effect.exit)
|
|
2085
|
+
|
|
2086
|
+
expect(Exit.isFailure(exit)).toBe(true)
|
|
2087
|
+
if (Exit.isFailure(exit)) {
|
|
2088
|
+
const err = Cause.squash(exit.cause)
|
|
2089
|
+
expect(NamedError.Unknown.isInstance(err)).toBe(true)
|
|
2090
|
+
if (NamedError.Unknown.isInstance(err)) {
|
|
2091
|
+
expect(err.data.message).toContain("code")
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
}),
|
|
2095
|
+
{ git: true },
|
|
2096
|
+
),
|
|
2097
|
+
30_000,
|
|
2098
|
+
)
|
|
2099
|
+
|
|
2100
|
+
it.live(
|
|
2101
|
+
"unknown command throws typed error with available names",
|
|
2102
|
+
() =>
|
|
2103
|
+
provideTmpdirInstance(
|
|
2104
|
+
(_dir) =>
|
|
2105
|
+
Effect.gen(function* () {
|
|
2106
|
+
const prompt = yield* SessionPrompt.Service
|
|
2107
|
+
const sessions = yield* Session.Service
|
|
2108
|
+
const session = yield* sessions.create({})
|
|
2109
|
+
const exit = yield* prompt
|
|
2110
|
+
.command({
|
|
2111
|
+
sessionID: session.id,
|
|
2112
|
+
command: "nonexistent-command-xyz",
|
|
2113
|
+
arguments: "",
|
|
2114
|
+
})
|
|
2115
|
+
.pipe(Effect.exit)
|
|
2116
|
+
|
|
2117
|
+
expect(Exit.isFailure(exit)).toBe(true)
|
|
2118
|
+
if (Exit.isFailure(exit)) {
|
|
2119
|
+
const err = Cause.squash(exit.cause)
|
|
2120
|
+
expect(err).not.toBeInstanceOf(TypeError)
|
|
2121
|
+
expect(NamedError.Unknown.isInstance(err)).toBe(true)
|
|
2122
|
+
if (NamedError.Unknown.isInstance(err)) {
|
|
2123
|
+
expect(err.data.message).toContain('Command not found: "nonexistent-command-xyz"')
|
|
2124
|
+
expect(err.data.message).toContain("init")
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
}),
|
|
2128
|
+
{ git: true },
|
|
2129
|
+
),
|
|
2130
|
+
30_000,
|
|
2131
|
+
)
|