@neurocode-ai/core 1.18.8
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/bin/neurocode +199 -0
- package/bunfig.toml +2 -0
- package/drizzle.config.ts +10 -0
- package/package.json +131 -0
- package/schema.json +2071 -0
- package/script/fix-node-pty.ts +28 -0
- package/script/migration.ts +196 -0
- package/src/account/sql.ts +39 -0
- package/src/account.ts +101 -0
- package/src/agent.ts +111 -0
- package/src/aisdk.ts +235 -0
- package/src/background-job.ts +365 -0
- package/src/catalog.ts +301 -0
- package/src/command.ts +64 -0
- package/src/config/agent.ts +25 -0
- package/src/config/attachments.ts +15 -0
- package/src/config/command.ts +12 -0
- package/src/config/compaction.ts +15 -0
- package/src/config/experimental.ts +18 -0
- package/src/config/formatter.ts +12 -0
- package/src/config/lsp.ts +18 -0
- package/src/config/markdown.ts +36 -0
- package/src/config/mcp.ts +48 -0
- package/src/config/plugin/agent.ts +179 -0
- package/src/config/plugin/command.ts +83 -0
- package/src/config/plugin/external.ts +91 -0
- package/src/config/plugin/provider.ts +113 -0
- package/src/config/plugin/reference.ts +70 -0
- package/src/config/plugin/skill.ts +50 -0
- package/src/config/plugin.ts +13 -0
- package/src/config/provider.ts +71 -0
- package/src/config/reference.ts +22 -0
- package/src/config/tool-output.ts +9 -0
- package/src/config/watcher.ts +7 -0
- package/src/config.ts +227 -0
- package/src/control-plane/move-session.ts +148 -0
- package/src/control-plane/workspace.sql.ts +20 -0
- package/src/credential/sql.ts +14 -0
- package/src/credential.ts +138 -0
- package/src/cross-spawn-spawner.ts +507 -0
- package/src/data-migration.sql.ts +6 -0
- package/src/database/database.ts +57 -0
- package/src/database/migration/20260127222353_familiar_lady_ursula.ts +107 -0
- package/src/database/migration/20260211171708_add_project_commands.ts +11 -0
- package/src/database/migration/20260213144116_wakeful_the_professor.ts +23 -0
- package/src/database/migration/20260225215848_workspace.ts +19 -0
- package/src/database/migration/20260227213759_add_session_workspace_id.ts +12 -0
- package/src/database/migration/20260228203230_blue_harpoon.ts +30 -0
- package/src/database/migration/20260303231226_add_workspace_fields.ts +15 -0
- package/src/database/migration/20260309230000_move_org_to_state.ts +15 -0
- package/src/database/migration/20260312043431_session_message_cursor.ts +16 -0
- package/src/database/migration/20260323234822_events.ts +26 -0
- package/src/database/migration/20260410174513_workspace-name.ts +29 -0
- package/src/database/migration/20260413175956_chief_energizer.ts +24 -0
- package/src/database/migration/20260423070820_add_icon_url_override.ts +14 -0
- package/src/database/migration/20260427172553_slow_nightmare.ts +30 -0
- package/src/database/migration/20260428004200_add_session_path.ts +11 -0
- package/src/database/migration/20260501142318_next_venus.ts +12 -0
- package/src/database/migration/20260504145000_add_sync_owner.ts +11 -0
- package/src/database/migration/20260507164347_add_workspace_time.ts +11 -0
- package/src/database/migration/20260510033149_session_usage.ts +56 -0
- package/src/database/migration/20260511000411_data_migration_state.ts +16 -0
- package/src/database/migration/20260511173437_session-metadata.ts +16 -0
- package/src/database/migration/20260601010001_normalize_storage_paths.ts +22 -0
- package/src/database/migration/20260601202201_amazing_prowler.ts +11 -0
- package/src/database/migration/20260602002951_lowly_union_jack.ts +24 -0
- package/src/database/migration/20260602182828_add_project_directories.ts +20 -0
- package/src/database/migration/20260603001617_session_message_projection_indexes.ts +19 -0
- package/src/database/migration/20260603040000_session_message_projection_order.ts +19 -0
- package/src/database/migration/20260603141458_session_input_inbox.ts +25 -0
- package/src/database/migration/20260603160727_jittery_ezekiel_stane.ts +20 -0
- package/src/database/migration/20260604172448_event_sourced_session_input.ts +47 -0
- package/src/database/migration/20260605003541_add_session_context_snapshot.ts +21 -0
- package/src/database/migration/20260605042240_add_context_epoch_agent.ts +11 -0
- package/src/database/migration/20260611035744_credential.ts +25 -0
- package/src/database/migration/20260611192811_lush_chimera.ts +25 -0
- package/src/database/migration/20260612174303_project_dir_strategy.ts +29 -0
- package/src/database/migration/20260622142730_simplify_session_context_epoch.ts +13 -0
- package/src/database/migration/20260622170816_reset_v2_session_state.ts +17 -0
- package/src/database/migration/20260622202450_simplify_session_input.ts +17 -0
- package/src/database/migration.gen.ts +44 -0
- package/src/database/migration.ts +81 -0
- package/src/database/path.ts +91 -0
- package/src/database/schema.gen.ts +274 -0
- package/src/database/schema.sql.ts +10 -0
- package/src/database/sqlite.bun.ts +183 -0
- package/src/database/sqlite.node.ts +178 -0
- package/src/database/sqlite.ts +8 -0
- package/src/effect/app-node-builder.ts +23 -0
- package/src/effect/app-node-platform.ts +18 -0
- package/src/effect/app-node.ts +14 -0
- package/src/effect/dfdf +1 -0
- package/src/effect/keyed-mutex.ts +45 -0
- package/src/effect/layer-node.ts +333 -0
- package/src/effect/memo-map.ts +3 -0
- package/src/effect/runtime.ts +21 -0
- package/src/effect/service-use.ts +43 -0
- package/src/event/sql.ts +25 -0
- package/src/event.ts +638 -0
- package/src/file-mutation.ts +207 -0
- package/src/file.ts +6 -0
- package/src/filesystem/fff.bun.ts +140 -0
- package/src/filesystem/fff.node.ts +138 -0
- package/src/filesystem/ignore.ts +67 -0
- package/src/filesystem/protected.ts +53 -0
- package/src/filesystem/search.ts +239 -0
- package/src/filesystem/watcher.ts +140 -0
- package/src/filesystem.ts +118 -0
- package/src/flag/flag.ts +78 -0
- package/src/fs-util.ts +274 -0
- package/src/git.ts +987 -0
- package/src/github-copilot/README.md +5 -0
- package/src/github-copilot/chat/convert-to-openai-compatible-chat-messages.ts +170 -0
- package/src/github-copilot/chat/get-response-metadata.ts +15 -0
- package/src/github-copilot/chat/map-openai-compatible-finish-reason.ts +19 -0
- package/src/github-copilot/chat/openai-compatible-api-types.ts +64 -0
- package/src/github-copilot/chat/openai-compatible-chat-language-model.ts +815 -0
- package/src/github-copilot/chat/openai-compatible-chat-options.ts +28 -0
- package/src/github-copilot/chat/openai-compatible-metadata-extractor.ts +44 -0
- package/src/github-copilot/chat/openai-compatible-prepare-tools.ts +83 -0
- package/src/github-copilot/copilot-provider.ts +100 -0
- package/src/github-copilot/openai-compatible-error.ts +27 -0
- package/src/github-copilot/responses/convert-to-openai-responses-input.ts +335 -0
- package/src/github-copilot/responses/map-openai-responses-finish-reason.ts +22 -0
- package/src/github-copilot/responses/openai-config.ts +18 -0
- package/src/github-copilot/responses/openai-error.ts +22 -0
- package/src/github-copilot/responses/openai-responses-api-types.ts +214 -0
- package/src/github-copilot/responses/openai-responses-language-model.ts +1770 -0
- package/src/github-copilot/responses/openai-responses-prepare-tools.ts +173 -0
- package/src/github-copilot/responses/openai-responses-settings.ts +1 -0
- package/src/github-copilot/responses/tool/code-interpreter.ts +87 -0
- package/src/github-copilot/responses/tool/file-search.ts +127 -0
- package/src/github-copilot/responses/tool/image-generation.ts +114 -0
- package/src/github-copilot/responses/tool/local-shell.ts +64 -0
- package/src/github-copilot/responses/tool/web-search-preview.ts +103 -0
- package/src/github-copilot/responses/tool/web-search.ts +102 -0
- package/src/global.ts +87 -0
- package/src/id/id.ts +47 -0
- package/src/image/photon.ts +94 -0
- package/src/image.ts +81 -0
- package/src/installation/version.ts +8 -0
- package/src/instruction-context.ts +101 -0
- package/src/integration/connection.ts +12 -0
- package/src/integration.ts +520 -0
- package/src/location-mutation.ts +162 -0
- package/src/location-service-map.ts +18 -0
- package/src/location-services.ts +115 -0
- package/src/location.ts +39 -0
- package/src/markdown.d.ts +4 -0
- package/src/model.ts +41 -0
- package/src/models-dev.ts +260 -0
- package/src/npm-config.ts +40 -0
- package/src/npm.ts +269 -0
- package/src/oauth/page.ts +276 -0
- package/src/observability/logging.ts +71 -0
- package/src/observability/otlp.ts +79 -0
- package/src/observability/shared.ts +1 -0
- package/src/observability.ts +24 -0
- package/src/patch.ts +197 -0
- package/src/permission/saved.ts +79 -0
- package/src/permission/sql.ts +20 -0
- package/src/permission.ts +310 -0
- package/src/plugin/agent.ts +206 -0
- package/src/plugin/command/initialize.txt +65 -0
- package/src/plugin/command/review.txt +100 -0
- package/src/plugin/command.ts +25 -0
- package/src/plugin/host.ts +219 -0
- package/src/plugin/internal.ts +153 -0
- package/src/plugin/layer-map.example.ts +94 -0
- package/src/plugin/models-dev.ts +183 -0
- package/src/plugin/promise.ts +93 -0
- package/src/plugin/provider/alibaba.ts +15 -0
- package/src/plugin/provider/amazon-bedrock.ts +126 -0
- package/src/plugin/provider/anthropic.ts +27 -0
- package/src/plugin/provider/azure.ts +82 -0
- package/src/plugin/provider/cerebras.ts +26 -0
- package/src/plugin/provider/cloudflare-ai-gateway.ts +81 -0
- package/src/plugin/provider/cloudflare-workers-ai.ts +81 -0
- package/src/plugin/provider/cohere.ts +15 -0
- package/src/plugin/provider/deepinfra.ts +15 -0
- package/src/plugin/provider/dynamic.ts +31 -0
- package/src/plugin/provider/gateway.ts +15 -0
- package/src/plugin/provider/github-copilot.ts +52 -0
- package/src/plugin/provider/gitlab.ts +65 -0
- package/src/plugin/provider/google-vertex.ts +173 -0
- package/src/plugin/provider/google.ts +15 -0
- package/src/plugin/provider/groq.ts +15 -0
- package/src/plugin/provider/kilo.ts +21 -0
- package/src/plugin/provider/llmgateway.ts +26 -0
- package/src/plugin/provider/mistral.ts +15 -0
- package/src/plugin/provider/nvidia.ts +22 -0
- package/src/plugin/provider/openai-compatible.ts +17 -0
- package/src/plugin/provider/openai.ts +292 -0
- package/src/plugin/provider/opencode.ts +311 -0
- package/src/plugin/provider/openrouter.ts +36 -0
- package/src/plugin/provider/perplexity.ts +15 -0
- package/src/plugin/provider/sap-ai-core.ts +46 -0
- package/src/plugin/provider/snowflake-cortex.ts +89 -0
- package/src/plugin/provider/togetherai.ts +15 -0
- package/src/plugin/provider/venice.ts +15 -0
- package/src/plugin/provider/vercel.ts +27 -0
- package/src/plugin/provider/xai.ts +22 -0
- package/src/plugin/provider/zenmux.ts +21 -0
- package/src/plugin/provider.ts +71 -0
- package/src/plugin/skill/customize-neurocode.md +452 -0
- package/src/plugin/skill.ts +31 -0
- package/src/plugin/variant.ts +39 -0
- package/src/plugin.ts +167 -0
- package/src/policy.ts +49 -0
- package/src/process.ts +261 -0
- package/src/project/copy-strategies.ts +35 -0
- package/src/project/copy.ts +292 -0
- package/src/project/directories.ts +158 -0
- package/src/project/schema.ts +16 -0
- package/src/project/sql.ts +35 -0
- package/src/project.ts +136 -0
- package/src/provider.ts +25 -0
- package/src/pty/protocol.ts +37 -0
- package/src/pty/pty.bun.ts +26 -0
- package/src/pty/pty.node.ts +29 -0
- package/src/pty/pty.ts +25 -0
- package/src/pty/schema.ts +1 -0
- package/src/pty/ticket.ts +56 -0
- package/src/pty.ts +318 -0
- package/src/public-event-manifest.ts +7 -0
- package/src/question.ts +153 -0
- package/src/reference/guidance.ts +69 -0
- package/src/reference.ts +125 -0
- package/src/repository-cache.ts +259 -0
- package/src/repository.ts +214 -0
- package/src/ripgrep/binary.ts +132 -0
- package/src/ripgrep.ts +281 -0
- package/src/schema.ts +79 -0
- package/src/session/compaction.ts +241 -0
- package/src/session/context-epoch.ts +174 -0
- package/src/session/error.ts +24 -0
- package/src/session/event.ts +2 -0
- package/src/session/execution/local.ts +46 -0
- package/src/session/execution.ts +34 -0
- package/src/session/history.ts +101 -0
- package/src/session/info.ts +50 -0
- package/src/session/input.ts +288 -0
- package/src/session/message-updater.ts +397 -0
- package/src/session/message.ts +2 -0
- package/src/session/projector.ts +458 -0
- package/src/session/prompt.ts +1 -0
- package/src/session/revert.ts +121 -0
- package/src/session/run-coordinator.ts +104 -0
- package/src/session/runner/index.ts +28 -0
- package/src/session/runner/llm.ts +432 -0
- package/src/session/runner/max-steps.ts +16 -0
- package/src/session/runner/model.ts +218 -0
- package/src/session/runner/publish-llm-event.ts +423 -0
- package/src/session/runner/to-llm-message.ts +171 -0
- package/src/session/schema.ts +9 -0
- package/src/session/sql.ts +176 -0
- package/src/session/store.ts +63 -0
- package/src/session/todo.ts +78 -0
- package/src/session.ts +486 -0
- package/src/share/sql.ts +13 -0
- package/src/shell.ts +226 -0
- package/src/skill/discovery.ts +213 -0
- package/src/skill/guidance.ts +76 -0
- package/src/skill.ts +132 -0
- package/src/snapshot.ts +266 -0
- package/src/state.ts +128 -0
- package/src/system-context/builtins.ts +50 -0
- package/src/system-context/index.ts +320 -0
- package/src/system-context/registry.ts +49 -0
- package/src/tool/AGENTS.md +59 -0
- package/src/tool/application-tools.ts +57 -0
- package/src/tool/apply-patch.ts +219 -0
- package/src/tool/bash.ts +207 -0
- package/src/tool/builtins.ts +48 -0
- package/src/tool/edit.ts +223 -0
- package/src/tool/glob.ts +105 -0
- package/src/tool/grep.ts +137 -0
- package/src/tool/http-body.ts +30 -0
- package/src/tool/question.ts +94 -0
- package/src/tool/read-filesystem.ts +366 -0
- package/src/tool/read.ts +117 -0
- package/src/tool/registry.ts +147 -0
- package/src/tool/skill.ts +109 -0
- package/src/tool/todowrite.ts +62 -0
- package/src/tool/tool.ts +162 -0
- package/src/tool/tools.ts +13 -0
- package/src/tool/webfetch.ts +218 -0
- package/src/tool/websearch.ts +260 -0
- package/src/tool/write.ts +101 -0
- package/src/tool-output-store.ts +211 -0
- package/src/util/array.ts +10 -0
- package/src/util/binary.ts +41 -0
- package/src/util/effect-flock.ts +284 -0
- package/src/util/encode.ts +51 -0
- package/src/util/error.ts +70 -0
- package/src/util/flock.ts +358 -0
- package/src/util/glob.ts +34 -0
- package/src/util/hash.ts +11 -0
- package/src/util/identifier.ts +1 -0
- package/src/util/iife.ts +3 -0
- package/src/util/lazy.ts +11 -0
- package/src/util/module.ts +10 -0
- package/src/util/path.ts +37 -0
- package/src/util/retry.ts +42 -0
- package/src/util/slug.ts +74 -0
- package/src/util/token.ts +5 -0
- package/src/util/which.ts +14 -0
- package/src/util/wildcard.ts +14 -0
- package/src/v1/config/agent.ts +89 -0
- package/src/v1/config/attachment.ts +25 -0
- package/src/v1/config/command.ts +13 -0
- package/src/v1/config/config.ts +192 -0
- package/src/v1/config/console-state.ts +16 -0
- package/src/v1/config/error.ts +39 -0
- package/src/v1/config/formatter.ts +13 -0
- package/src/v1/config/layout.ts +6 -0
- package/src/v1/config/lsp.ts +80 -0
- package/src/v1/config/mcp.ts +63 -0
- package/src/v1/config/migrate.ts +254 -0
- package/src/v1/config/permission.ts +50 -0
- package/src/v1/config/plugin.ts +9 -0
- package/src/v1/config/provider-options.ts +227 -0
- package/src/v1/config/provider.ts +121 -0
- package/src/v1/config/server.ts +19 -0
- package/src/v1/config/skills.ts +13 -0
- package/src/v1/permission.ts +33 -0
- package/src/v1/session.ts +68 -0
- package/src/v2-schema.ts +3 -0
- package/src/workspace.ts +6 -0
- package/sst-env.d.ts +10 -0
- package/test/agent.test.ts +131 -0
- package/test/application-tools.test.ts +287 -0
- package/test/background-job.test.ts +106 -0
- package/test/catalog.test.ts +353 -0
- package/test/command.test.ts +56 -0
- package/test/config/agent.test.ts +349 -0
- package/test/config/command.test.ts +83 -0
- package/test/config/config.test.ts +798 -0
- package/test/config/fixtures/plugin/directory-plugin.ts +13 -0
- package/test/config/plugin.test.ts +248 -0
- package/test/config/provider-options.test.ts +224 -0
- package/test/config/provider.test.ts +269 -0
- package/test/config/skill.test.ts +80 -0
- package/test/credential.test.ts +36 -0
- package/test/database-migration.test.ts +644 -0
- package/test/effect/cross-spawn-spawner.test.ts +426 -0
- package/test/effect/keyed-mutex.test.ts +73 -0
- package/test/effect/layer-node/layer-node-types.test.ts +143 -0
- package/test/effect/layer-node/layer-node.test.ts +261 -0
- package/test/effect/layer-node/node-build.test.ts +125 -0
- package/test/effect/observability.test.ts +109 -0
- package/test/event.test.ts +1124 -0
- package/test/file-mutation.test.ts +368 -0
- package/test/filesystem/filesystem.test.ts +387 -0
- package/test/filesystem/ignore.test.ts +10 -0
- package/test/filesystem/search.test.ts +44 -0
- package/test/filesystem/watcher.test.ts +266 -0
- package/test/fixture/effect-flock-worker.ts +60 -0
- package/test/fixture/flock-worker.ts +72 -0
- package/test/fixture/git.ts +49 -0
- package/test/fixture/location.ts +26 -0
- package/test/fixture/tmpdir.ts +25 -0
- package/test/fixtures/recordings/session-runner/openai-chat-streams-text.json +27 -0
- package/test/git.test.ts +164 -0
- package/test/github-copilot/convert-to-copilot-messages.test.ts +523 -0
- package/test/github-copilot/copilot-chat-model.test.ts +592 -0
- package/test/github-copilot/openai-responses-language-model.test.ts +206 -0
- package/test/global.test.ts +16 -0
- package/test/instruction-context.test.ts +323 -0
- package/test/integration.test.ts +349 -0
- package/test/legacy-event-schema.test.ts +16 -0
- package/test/lib/effect.ts +53 -0
- package/test/lib/tool.ts +20 -0
- package/test/location-filesystem.test.ts +69 -0
- package/test/location-layer.test.ts +226 -0
- package/test/location-mutation.test.ts +178 -0
- package/test/location.test.ts +42 -0
- package/test/model.test.ts +23 -0
- package/test/models.test.ts +290 -0
- package/test/move-session.test.ts +235 -0
- package/test/npm-config.test.ts +51 -0
- package/test/npm.test.ts +84 -0
- package/test/oauth-page.test.ts +15 -0
- package/test/patch.test.ts +68 -0
- package/test/permission.test.ts +315 -0
- package/test/plugin/command.test.ts +47 -0
- package/test/plugin/fixture.ts +52 -0
- package/test/plugin/fixtures/config-effect-plugin.ts +15 -0
- package/test/plugin/fixtures/config-promise-plugin.ts +13 -0
- package/test/plugin/fixtures/invalid-plugin.ts +1 -0
- package/test/plugin/fixtures/models-dev.json +14 -0
- package/test/plugin/fixtures/provider-factory.ts +9 -0
- package/test/plugin/host.ts +303 -0
- package/test/plugin/models-dev.test.ts +170 -0
- package/test/plugin/promise.test.ts +67 -0
- package/test/plugin/provider-alibaba.test.ts +92 -0
- package/test/plugin/provider-amazon-bedrock.test.ts +622 -0
- package/test/plugin/provider-anthropic.test.ts +94 -0
- package/test/plugin/provider-azure-cognitive-services.test.ts +199 -0
- package/test/plugin/provider-azure.test.ts +293 -0
- package/test/plugin/provider-cerebras.test.ts +136 -0
- package/test/plugin/provider-cloudflare-ai-gateway.test.ts +426 -0
- package/test/plugin/provider-cloudflare-workers-ai.test.ts +279 -0
- package/test/plugin/provider-cohere.test.ts +123 -0
- package/test/plugin/provider-deepinfra.test.ts +159 -0
- package/test/plugin/provider-dynamic.test.ts +184 -0
- package/test/plugin/provider-gateway.test.ts +115 -0
- package/test/plugin/provider-github-copilot.test.ts +278 -0
- package/test/plugin/provider-gitlab.test.ts +308 -0
- package/test/plugin/provider-google-vertex-anthropic.test.ts +264 -0
- package/test/plugin/provider-google-vertex.test.ts +387 -0
- package/test/plugin/provider-google.test.ts +80 -0
- package/test/plugin/provider-groq.test.ts +121 -0
- package/test/plugin/provider-kilo.test.ts +99 -0
- package/test/plugin/provider-llmgateway.test.ts +80 -0
- package/test/plugin/provider-mistral.test.ts +129 -0
- package/test/plugin/provider-nvidia.test.ts +97 -0
- package/test/plugin/provider-openai-compatible.test.ts +107 -0
- package/test/plugin/provider-openai.test.ts +176 -0
- package/test/plugin/provider-opencode.test.ts +423 -0
- package/test/plugin/provider-openrouter.test.ts +113 -0
- package/test/plugin/provider-perplexity.test.ts +122 -0
- package/test/plugin/provider-sap-ai-core.test.ts +159 -0
- package/test/plugin/provider-snowflake-cortex.test.ts +261 -0
- package/test/plugin/provider-togetherai.test.ts +129 -0
- package/test/plugin/provider-venice.test.ts +115 -0
- package/test/plugin/provider-vercel.test.ts +83 -0
- package/test/plugin/provider-xai.test.ts +125 -0
- package/test/plugin/provider-zenmux.test.ts +110 -0
- package/test/plugin/skill.test.ts +25 -0
- package/test/plugin/variant.test.ts +67 -0
- package/test/plugin.test.ts +71 -0
- package/test/policy.test.ts +85 -0
- package/test/preload.ts +5 -0
- package/test/process/process.test.ts +368 -0
- package/test/project-copy.test.ts +400 -0
- package/test/project-directories.test.ts +61 -0
- package/test/project.test.ts +221 -0
- package/test/provider-mistral.test.ts +282 -0
- package/test/provider-xai-responses.test.ts +32 -0
- package/test/pty/info-schema.test.ts +32 -0
- package/test/pty/protocol.test.ts +27 -0
- package/test/pty/pty-session.test.ts +240 -0
- package/test/pty/ticket.test.ts +62 -0
- package/test/question.test.ts +114 -0
- package/test/reference-guidance.test.ts +76 -0
- package/test/reference.test.ts +78 -0
- package/test/repository-cache.test.ts +153 -0
- package/test/repository.test.ts +71 -0
- package/test/ripgrep.test.ts +65 -0
- package/test/session-compaction.test.ts +27 -0
- package/test/session-create.test.ts +425 -0
- package/test/session-history.test.ts +165 -0
- package/test/session-projector.test.ts +533 -0
- package/test/session-prompt.test.ts +584 -0
- package/test/session-run-coordinator.test.ts +418 -0
- package/test/session-runner-message.test.ts +501 -0
- package/test/session-runner-model.test.ts +347 -0
- package/test/session-runner-recorded.test.ts +193 -0
- package/test/session-runner-tool-events.test.ts +136 -0
- package/test/session-runner-tool-registry.test.ts +452 -0
- package/test/session-runner.test.ts +3365 -0
- package/test/session-todo.test.ts +94 -0
- package/test/session-tool-progress.test.ts +158 -0
- package/test/shared-schema.test.ts +206 -0
- package/test/shell.test.ts +108 -0
- package/test/skill/guidance.test.ts +144 -0
- package/test/skill-discovery.test.ts +165 -0
- package/test/skill.test.ts +125 -0
- package/test/snapshot.test.ts +178 -0
- package/test/state.test.ts +115 -0
- package/test/system-context/builtins.test.ts +129 -0
- package/test/system-context/index.test.ts +307 -0
- package/test/system-context/registry.test.ts +114 -0
- package/test/tool-apply-patch.test.ts +436 -0
- package/test/tool-bash.test.ts +437 -0
- package/test/tool-edit.test.ts +434 -0
- package/test/tool-output-store.test.ts +247 -0
- package/test/tool-question.test.ts +162 -0
- package/test/tool-read-filesystem.test.ts +118 -0
- package/test/tool-read.test.ts +674 -0
- package/test/tool-skill.test.ts +149 -0
- package/test/tool-todowrite.test.ts +125 -0
- package/test/tool-webfetch.test.ts +281 -0
- package/test/tool-websearch.test.ts +316 -0
- package/test/tool-write.test.ts +305 -0
- package/test/util/effect-flock.test.ts +392 -0
- package/test/util/flock.test.ts +428 -0
- package/test/util/which.test.ts +100 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, test } from "bun:test"
|
|
2
|
+
import { Effect, Layer, Schema } from "effect"
|
|
3
|
+
import { HttpClient, HttpClientResponse } from "effect/unstable/http"
|
|
4
|
+
import { AppNodeBuilder } from "@neurocode-ai/core/effect/app-node-builder"
|
|
5
|
+
import { LayerNode } from "@neurocode-ai/core/effect/layer-node"
|
|
6
|
+
import { LayerNodePlatform } from "@neurocode-ai/core/effect/app-node-platform"
|
|
7
|
+
import { PermissionV2 } from "@neurocode-ai/core/permission"
|
|
8
|
+
import { SessionV2 } from "@neurocode-ai/core/session"
|
|
9
|
+
import { ToolRegistry } from "@neurocode-ai/core/tool/registry"
|
|
10
|
+
import { WebSearchTool } from "@neurocode-ai/core/tool/websearch"
|
|
11
|
+
import { ToolOutputStore } from "@neurocode-ai/core/tool-output-store"
|
|
12
|
+
import { testEffect } from "./lib/effect"
|
|
13
|
+
import { toolIdentity, executeTool, settleTool, toolDefinitions } from "./lib/tool"
|
|
14
|
+
|
|
15
|
+
const sessionID = SessionV2.ID.make("ses_websearch_test")
|
|
16
|
+
const payload = (text: string) =>
|
|
17
|
+
JSON.stringify({
|
|
18
|
+
jsonrpc: "2.0",
|
|
19
|
+
id: 1,
|
|
20
|
+
result: { content: [{ type: "text", text }] },
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
describe("WebSearchTool provider selection", () => {
|
|
24
|
+
test("rejects out-of-range numeric controls", () => {
|
|
25
|
+
const decode = Schema.decodeUnknownSync(WebSearchTool.Input)
|
|
26
|
+
expect(() => decode({ query: "x", numResults: 0 })).toThrow()
|
|
27
|
+
expect(() => decode({ query: "x", numResults: WebSearchTool.MAX_NUM_RESULTS + 1 })).toThrow()
|
|
28
|
+
expect(() => decode({ query: "x", contextMaxCharacters: WebSearchTool.MAX_CONTEXT_CHARACTERS + 1 })).toThrow()
|
|
29
|
+
})
|
|
30
|
+
test("selects a stable provider per session", () => {
|
|
31
|
+
expect(WebSearchTool.selectProvider(sessionID)).toBe(WebSearchTool.selectProvider(sessionID))
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test("supports an explicit operational override", () => {
|
|
35
|
+
expect(WebSearchTool.selectProvider(sessionID, { enableExa: false, enableParallel: false }, "parallel")).toBe(
|
|
36
|
+
"parallel",
|
|
37
|
+
)
|
|
38
|
+
expect(WebSearchTool.selectProvider(sessionID, { enableExa: false, enableParallel: false }, "exa")).toBe("exa")
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test("prefers Parallel when both explicit flags are enabled", () => {
|
|
42
|
+
expect(WebSearchTool.selectProvider(sessionID, { enableExa: true, enableParallel: true })).toBe("parallel")
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test("prefers Exa when only its explicit flag is enabled", () => {
|
|
46
|
+
expect(WebSearchTool.selectProvider(sessionID, { enableExa: true, enableParallel: false })).toBe("exa")
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
describe("WebSearchTool MCP response parser", () => {
|
|
51
|
+
test("parses plain JSON-RPC responses", async () => {
|
|
52
|
+
expect(await Effect.runPromise(WebSearchTool.parseResponse(payload("search results")))).toBe("search results")
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test("parses SSE JSON-RPC responses and ignores non-JSON frames", async () => {
|
|
56
|
+
expect(
|
|
57
|
+
await Effect.runPromise(
|
|
58
|
+
WebSearchTool.parseResponse(`data: [DONE]\nevent: message\ndata: ${payload("search results")}\n\n`),
|
|
59
|
+
),
|
|
60
|
+
).toBe("search results")
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
interface Request {
|
|
65
|
+
readonly url: string
|
|
66
|
+
readonly headers: Record<string, string>
|
|
67
|
+
readonly body: unknown
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const requests: Request[] = []
|
|
71
|
+
const assertions: PermissionV2.AssertInput[] = []
|
|
72
|
+
let responseBody = payload("search results")
|
|
73
|
+
let makeResponse = () => new Response(responseBody, { status: 200 })
|
|
74
|
+
let config: WebSearchTool.Config = { enableExa: false, enableParallel: false }
|
|
75
|
+
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
responseBody = payload("search results")
|
|
78
|
+
makeResponse = () => new Response(responseBody, { status: 200 })
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const http = Layer.succeed(
|
|
82
|
+
HttpClient.HttpClient,
|
|
83
|
+
HttpClient.make((request) =>
|
|
84
|
+
Effect.sync(() => {
|
|
85
|
+
if (request.body._tag !== "Uint8Array") throw new Error(`Unexpected request body: ${request.body._tag}`)
|
|
86
|
+
requests.push({
|
|
87
|
+
url: request.url,
|
|
88
|
+
headers: request.headers,
|
|
89
|
+
body: JSON.parse(new TextDecoder().decode(request.body.body)),
|
|
90
|
+
})
|
|
91
|
+
return HttpClientResponse.fromWeb(request, makeResponse())
|
|
92
|
+
}),
|
|
93
|
+
),
|
|
94
|
+
)
|
|
95
|
+
const permission = Layer.succeed(
|
|
96
|
+
PermissionV2.Service,
|
|
97
|
+
PermissionV2.Service.of({
|
|
98
|
+
assert: (input) => Effect.sync(() => assertions.push(input)),
|
|
99
|
+
ask: () => Effect.die("unused"),
|
|
100
|
+
reply: () => Effect.die("unused"),
|
|
101
|
+
get: () => Effect.die("unused"),
|
|
102
|
+
forSession: () => Effect.die("unused"),
|
|
103
|
+
list: () => Effect.die("unused"),
|
|
104
|
+
}),
|
|
105
|
+
)
|
|
106
|
+
const websearchConfig = Layer.succeed(
|
|
107
|
+
WebSearchTool.ConfigService,
|
|
108
|
+
WebSearchTool.ConfigService.of({
|
|
109
|
+
get provider() {
|
|
110
|
+
return config.provider
|
|
111
|
+
},
|
|
112
|
+
get enableExa() {
|
|
113
|
+
return config.enableExa
|
|
114
|
+
},
|
|
115
|
+
get enableParallel() {
|
|
116
|
+
return config.enableParallel
|
|
117
|
+
},
|
|
118
|
+
get exaApiKey() {
|
|
119
|
+
return config.exaApiKey
|
|
120
|
+
},
|
|
121
|
+
get parallelApiKey() {
|
|
122
|
+
return config.parallelApiKey
|
|
123
|
+
},
|
|
124
|
+
}),
|
|
125
|
+
)
|
|
126
|
+
const it = testEffect(
|
|
127
|
+
AppNodeBuilder.build(
|
|
128
|
+
LayerNode.group([ToolRegistry.node, ToolRegistry.toolsNode, WebSearchTool.configNode, WebSearchTool.node]),
|
|
129
|
+
[
|
|
130
|
+
[PermissionV2.node, permission],
|
|
131
|
+
[LayerNodePlatform.httpClient, http],
|
|
132
|
+
[WebSearchTool.configNode, websearchConfig],
|
|
133
|
+
[ToolOutputStore.node, ToolOutputStore.nodeWithoutConfig],
|
|
134
|
+
],
|
|
135
|
+
),
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
describe("WebSearchTool registration", () => {
|
|
139
|
+
it.effect("registers websearch, asserts query permission, and calls Exa", () =>
|
|
140
|
+
Effect.gen(function* () {
|
|
141
|
+
requests.length = 0
|
|
142
|
+
assertions.length = 0
|
|
143
|
+
responseBody = payload("exa results")
|
|
144
|
+
config = { provider: "exa", enableExa: false, enableParallel: false }
|
|
145
|
+
const registry = yield* ToolRegistry.Service
|
|
146
|
+
|
|
147
|
+
expect((yield* toolDefinitions(registry)).map((tool) => tool.name)).toEqual(["websearch"])
|
|
148
|
+
expect(
|
|
149
|
+
yield* executeTool(registry, {
|
|
150
|
+
sessionID,
|
|
151
|
+
...toolIdentity,
|
|
152
|
+
call: {
|
|
153
|
+
type: "tool-call",
|
|
154
|
+
id: "call-exa",
|
|
155
|
+
name: "websearch",
|
|
156
|
+
input: {
|
|
157
|
+
query: "effect typescript",
|
|
158
|
+
numResults: 3,
|
|
159
|
+
livecrawl: "preferred",
|
|
160
|
+
type: "fast",
|
|
161
|
+
contextMaxCharacters: 2500,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
}),
|
|
165
|
+
).toEqual({ type: "text", value: "exa results" })
|
|
166
|
+
expect(assertions).toMatchObject([
|
|
167
|
+
{
|
|
168
|
+
sessionID,
|
|
169
|
+
action: "websearch",
|
|
170
|
+
resources: ["effect typescript"],
|
|
171
|
+
save: ["*"],
|
|
172
|
+
metadata: {
|
|
173
|
+
query: "effect typescript",
|
|
174
|
+
numResults: 3,
|
|
175
|
+
livecrawl: "preferred",
|
|
176
|
+
type: "fast",
|
|
177
|
+
contextMaxCharacters: 2500,
|
|
178
|
+
provider: "exa",
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
])
|
|
182
|
+
expect(requests).toEqual([
|
|
183
|
+
{
|
|
184
|
+
url: WebSearchTool.EXA_URL,
|
|
185
|
+
headers: expect.any(Object),
|
|
186
|
+
body: {
|
|
187
|
+
jsonrpc: "2.0",
|
|
188
|
+
id: 1,
|
|
189
|
+
method: "tools/call",
|
|
190
|
+
params: {
|
|
191
|
+
name: "web_search_exa",
|
|
192
|
+
arguments: {
|
|
193
|
+
query: "effect typescript",
|
|
194
|
+
type: "fast",
|
|
195
|
+
numResults: 3,
|
|
196
|
+
livecrawl: "preferred",
|
|
197
|
+
contextMaxCharacters: 2500,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
])
|
|
203
|
+
}),
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
it.effect("calls Parallel with session ID and keeps bearer credentials out of output", () =>
|
|
207
|
+
Effect.gen(function* () {
|
|
208
|
+
requests.length = 0
|
|
209
|
+
assertions.length = 0
|
|
210
|
+
responseBody = payload("parallel results")
|
|
211
|
+
config = { provider: "parallel", enableExa: false, enableParallel: false, parallelApiKey: "parallel-secret" }
|
|
212
|
+
const registry = yield* ToolRegistry.Service
|
|
213
|
+
|
|
214
|
+
const settled = yield* settleTool(registry, {
|
|
215
|
+
sessionID,
|
|
216
|
+
...toolIdentity,
|
|
217
|
+
call: { type: "tool-call", id: "call-parallel", name: "websearch", input: { query: "effect layers" } },
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
expect(requests[0]).toMatchObject({
|
|
221
|
+
url: WebSearchTool.PARALLEL_URL,
|
|
222
|
+
headers: { authorization: "Bearer parallel-secret" },
|
|
223
|
+
body: {
|
|
224
|
+
jsonrpc: "2.0",
|
|
225
|
+
id: 1,
|
|
226
|
+
method: "tools/call",
|
|
227
|
+
params: {
|
|
228
|
+
name: "web_search",
|
|
229
|
+
arguments: { objective: "effect layers", search_queries: ["effect layers"], session_id: sessionID },
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
})
|
|
233
|
+
expect(requests[0]?.body).not.toHaveProperty("params.arguments.model_name")
|
|
234
|
+
expect(settled).toEqual({
|
|
235
|
+
result: { type: "text", value: "parallel results" },
|
|
236
|
+
output: {
|
|
237
|
+
structured: { provider: "parallel", text: "parallel results" },
|
|
238
|
+
content: [{ type: "text", text: "parallel results" }],
|
|
239
|
+
},
|
|
240
|
+
})
|
|
241
|
+
expect(JSON.stringify(settled)).not.toContain("parallel-secret")
|
|
242
|
+
}),
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
it.effect("keeps an Exa credential in the transport URL and out of model output", () =>
|
|
246
|
+
Effect.gen(function* () {
|
|
247
|
+
requests.length = 0
|
|
248
|
+
assertions.length = 0
|
|
249
|
+
responseBody = payload("credentialed exa results")
|
|
250
|
+
config = { provider: "exa", enableExa: false, enableParallel: false, exaApiKey: "exa secret" }
|
|
251
|
+
const registry = yield* ToolRegistry.Service
|
|
252
|
+
|
|
253
|
+
const settled = yield* settleTool(registry, {
|
|
254
|
+
sessionID,
|
|
255
|
+
...toolIdentity,
|
|
256
|
+
call: { type: "tool-call", id: "call-exa-key", name: "websearch", input: { query: "effect schema" } },
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
expect(requests[0]?.url).toBe(`${WebSearchTool.EXA_URL}?exaApiKey=exa+secret`)
|
|
260
|
+
expect(JSON.stringify(settled)).not.toContain("exa secret")
|
|
261
|
+
}),
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
it.effect("returns the legacy no-results fallback as concise model text", () =>
|
|
265
|
+
Effect.gen(function* () {
|
|
266
|
+
requests.length = 0
|
|
267
|
+
assertions.length = 0
|
|
268
|
+
responseBody = ""
|
|
269
|
+
config = { provider: "exa", enableExa: false, enableParallel: false }
|
|
270
|
+
const registry = yield* ToolRegistry.Service
|
|
271
|
+
|
|
272
|
+
expect(
|
|
273
|
+
yield* executeTool(registry, {
|
|
274
|
+
sessionID,
|
|
275
|
+
...toolIdentity,
|
|
276
|
+
call: { type: "tool-call", id: "call-empty", name: "websearch", input: { query: "nothing" } },
|
|
277
|
+
}),
|
|
278
|
+
).toEqual({ type: "text", value: WebSearchTool.NO_RESULTS })
|
|
279
|
+
}),
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
it.effect("rejects oversized MCP response bodies", () =>
|
|
283
|
+
Effect.gen(function* () {
|
|
284
|
+
requests.length = 0
|
|
285
|
+
assertions.length = 0
|
|
286
|
+
let chunksRead = 0
|
|
287
|
+
let cancelled = false
|
|
288
|
+
makeResponse = () =>
|
|
289
|
+
new Response(
|
|
290
|
+
new ReadableStream({
|
|
291
|
+
pull(controller) {
|
|
292
|
+
chunksRead++
|
|
293
|
+
if (chunksRead === 10) throw new Error("response was not stopped at the byte limit")
|
|
294
|
+
controller.enqueue(new Uint8Array(64 * 1024))
|
|
295
|
+
},
|
|
296
|
+
cancel() {
|
|
297
|
+
cancelled = true
|
|
298
|
+
},
|
|
299
|
+
}),
|
|
300
|
+
{ status: 200 },
|
|
301
|
+
)
|
|
302
|
+
config = { provider: "exa", enableExa: false, enableParallel: false }
|
|
303
|
+
const registry = yield* ToolRegistry.Service
|
|
304
|
+
|
|
305
|
+
expect(
|
|
306
|
+
yield* executeTool(registry, {
|
|
307
|
+
sessionID,
|
|
308
|
+
...toolIdentity,
|
|
309
|
+
call: { type: "tool-call", id: "call-large-response", name: "websearch", input: { query: "too much" } },
|
|
310
|
+
}),
|
|
311
|
+
).toEqual({ type: "error", value: "Unable to search the web for too much" })
|
|
312
|
+
expect(chunksRead).toBeLessThan(10)
|
|
313
|
+
expect(cancelled).toBe(true)
|
|
314
|
+
}),
|
|
315
|
+
)
|
|
316
|
+
})
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import fs from "fs/promises"
|
|
2
|
+
import path from "path"
|
|
3
|
+
import { fileURLToPath } from "url"
|
|
4
|
+
import { describe, expect, test } from "bun:test"
|
|
5
|
+
import { Effect, Layer } from "effect"
|
|
6
|
+
import { FileMutation } from "@neurocode-ai/core/file-mutation"
|
|
7
|
+
import { AppNodeBuilder } from "@neurocode-ai/core/effect/app-node-builder"
|
|
8
|
+
import { LayerNode } from "@neurocode-ai/core/effect/layer-node"
|
|
9
|
+
import { FSUtil } from "@neurocode-ai/core/fs-util"
|
|
10
|
+
import { Location } from "@neurocode-ai/core/location"
|
|
11
|
+
import { LocationMutation } from "@neurocode-ai/core/location-mutation"
|
|
12
|
+
import { PermissionV2 } from "@neurocode-ai/core/permission"
|
|
13
|
+
import { AbsolutePath } from "@neurocode-ai/core/schema"
|
|
14
|
+
import { SessionV2 } from "@neurocode-ai/core/session"
|
|
15
|
+
import { ToolRegistry } from "@neurocode-ai/core/tool/registry"
|
|
16
|
+
import { ToolOutputStore } from "@neurocode-ai/core/tool-output-store"
|
|
17
|
+
import { WriteTool } from "@neurocode-ai/core/tool/write"
|
|
18
|
+
import { location } from "./fixture/location"
|
|
19
|
+
import { tmpdir } from "./fixture/tmpdir"
|
|
20
|
+
import { testEffect } from "./lib/effect"
|
|
21
|
+
import { toolIdentity, executeTool, settleTool, toolDefinitions } from "./lib/tool"
|
|
22
|
+
|
|
23
|
+
const sessionID = SessionV2.ID.make("ses_write_tool_test")
|
|
24
|
+
const assertions: PermissionV2.AssertInput[] = []
|
|
25
|
+
const writes: string[] = []
|
|
26
|
+
let denyAction: string | undefined
|
|
27
|
+
|
|
28
|
+
const permission = Layer.succeed(
|
|
29
|
+
PermissionV2.Service,
|
|
30
|
+
PermissionV2.Service.of({
|
|
31
|
+
assert: (input) =>
|
|
32
|
+
Effect.sync(() => assertions.push(input)).pipe(
|
|
33
|
+
Effect.andThen(
|
|
34
|
+
input.action === denyAction ? Effect.fail(new PermissionV2.BlockedError({ rules: [] })) : Effect.void,
|
|
35
|
+
),
|
|
36
|
+
),
|
|
37
|
+
ask: () => Effect.die("unused"),
|
|
38
|
+
reply: () => Effect.die("unused"),
|
|
39
|
+
get: () => Effect.die("unused"),
|
|
40
|
+
forSession: () => Effect.die("unused"),
|
|
41
|
+
list: () => Effect.die("unused"),
|
|
42
|
+
}),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
const reset = () => {
|
|
46
|
+
assertions.length = 0
|
|
47
|
+
writes.length = 0
|
|
48
|
+
denyAction = undefined
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const filesystem = Layer.effect(
|
|
52
|
+
FSUtil.Service,
|
|
53
|
+
Effect.gen(function* () {
|
|
54
|
+
const fs = yield* FSUtil.Service
|
|
55
|
+
return FSUtil.Service.of({
|
|
56
|
+
...fs,
|
|
57
|
+
writeWithDirs: (target, content, mode) =>
|
|
58
|
+
Effect.sync(() => writes.push(target)).pipe(Effect.andThen(fs.writeWithDirs(target, content, mode))),
|
|
59
|
+
})
|
|
60
|
+
}),
|
|
61
|
+
).pipe(Layer.provide(LayerNode.compile(FSUtil.node)))
|
|
62
|
+
|
|
63
|
+
const withTool = <A, E, R>(directory: string, body: (registry: ToolRegistry.Interface) => Effect.Effect<A, E, R>) => {
|
|
64
|
+
const activeLocation = Layer.succeed(
|
|
65
|
+
Location.Service,
|
|
66
|
+
Location.Service.of(location({ directory: AbsolutePath.make(directory) })),
|
|
67
|
+
)
|
|
68
|
+
return Effect.gen(function* () {
|
|
69
|
+
return yield* body(yield* ToolRegistry.Service)
|
|
70
|
+
}).pipe(
|
|
71
|
+
Effect.provide(
|
|
72
|
+
AppNodeBuilder.build(
|
|
73
|
+
LayerNode.group([
|
|
74
|
+
ToolRegistry.node,
|
|
75
|
+
ToolRegistry.toolsNode,
|
|
76
|
+
LocationMutation.node,
|
|
77
|
+
FileMutation.node,
|
|
78
|
+
WriteTool.node,
|
|
79
|
+
]),
|
|
80
|
+
[
|
|
81
|
+
[FSUtil.node, filesystem],
|
|
82
|
+
[Location.node, activeLocation],
|
|
83
|
+
[PermissionV2.node, permission],
|
|
84
|
+
[ToolOutputStore.node, ToolOutputStore.nodeWithoutConfig],
|
|
85
|
+
],
|
|
86
|
+
),
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const call = (input: typeof WriteTool.Input.Type, id = "call-write") => ({
|
|
92
|
+
sessionID,
|
|
93
|
+
...toolIdentity,
|
|
94
|
+
call: { type: "tool-call" as const, id, name: "write", input },
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const it = testEffect(Layer.empty)
|
|
98
|
+
|
|
99
|
+
describe("WriteTool", () => {
|
|
100
|
+
it.live("registers and creates a relative file through FileMutation once", () =>
|
|
101
|
+
Effect.acquireUseRelease(
|
|
102
|
+
Effect.promise(() => tmpdir()),
|
|
103
|
+
(tmp) => {
|
|
104
|
+
reset()
|
|
105
|
+
return withTool(tmp.path, (registry) =>
|
|
106
|
+
Effect.gen(function* () {
|
|
107
|
+
expect((yield* toolDefinitions(registry)).map((tool) => tool.name)).toEqual(["write"])
|
|
108
|
+
const settled = yield* settleTool(registry, call({ path: "src/new.txt", content: "created" }))
|
|
109
|
+
expect(settled).toEqual({
|
|
110
|
+
result: { type: "text", value: "Created file successfully: src/new.txt" },
|
|
111
|
+
output: {
|
|
112
|
+
structured: {
|
|
113
|
+
operation: "write",
|
|
114
|
+
target: path.join(yield* Effect.promise(() => fs.realpath(tmp.path)), "src", "new.txt"),
|
|
115
|
+
resource: "src/new.txt",
|
|
116
|
+
existed: false,
|
|
117
|
+
},
|
|
118
|
+
content: [{ type: "text", text: "Created file successfully: src/new.txt" }],
|
|
119
|
+
},
|
|
120
|
+
})
|
|
121
|
+
expect(yield* Effect.promise(() => fs.readFile(path.join(tmp.path, "src", "new.txt"), "utf8"))).toBe(
|
|
122
|
+
"created",
|
|
123
|
+
)
|
|
124
|
+
expect(assertions).toMatchObject([{ sessionID, action: "edit", resources: ["src/new.txt"], save: ["*"] }])
|
|
125
|
+
expect(writes).toEqual([path.join(yield* Effect.promise(() => fs.realpath(tmp.path)), "src", "new.txt")])
|
|
126
|
+
}),
|
|
127
|
+
)
|
|
128
|
+
},
|
|
129
|
+
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
130
|
+
),
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
it.live("overwrites a relative existing file and reports that it wrote the file", () =>
|
|
134
|
+
Effect.acquireUseRelease(
|
|
135
|
+
Effect.promise(() => tmpdir()),
|
|
136
|
+
(tmp) => {
|
|
137
|
+
reset()
|
|
138
|
+
return Effect.promise(() => fs.writeFile(path.join(tmp.path, "existing.txt"), "before")).pipe(
|
|
139
|
+
Effect.andThen(
|
|
140
|
+
withTool(tmp.path, (registry) => settleTool(registry, call({ path: "existing.txt", content: "after" }))),
|
|
141
|
+
),
|
|
142
|
+
Effect.andThen((settled) =>
|
|
143
|
+
Effect.gen(function* () {
|
|
144
|
+
expect(settled.result).toEqual({ type: "text", value: "Wrote file successfully: existing.txt" })
|
|
145
|
+
expect(settled.output?.structured).toMatchObject({ resource: "existing.txt", existed: true })
|
|
146
|
+
expect(yield* Effect.promise(() => fs.readFile(path.join(tmp.path, "existing.txt"), "utf8"))).toBe(
|
|
147
|
+
"after",
|
|
148
|
+
)
|
|
149
|
+
expect(writes).toHaveLength(1)
|
|
150
|
+
}),
|
|
151
|
+
),
|
|
152
|
+
)
|
|
153
|
+
},
|
|
154
|
+
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
155
|
+
),
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
it.live("preserves exactly one BOM when overwriting existing files", () =>
|
|
159
|
+
Effect.acquireUseRelease(
|
|
160
|
+
Effect.promise(() => tmpdir()),
|
|
161
|
+
(tmp) => {
|
|
162
|
+
reset()
|
|
163
|
+
const preserved = path.join(tmp.path, "preserved.txt")
|
|
164
|
+
const deduplicated = path.join(tmp.path, "deduplicated.txt")
|
|
165
|
+
return Effect.promise(() =>
|
|
166
|
+
Promise.all([fs.writeFile(preserved, "\uFEFFbefore"), fs.writeFile(deduplicated, "\uFEFFbefore")]),
|
|
167
|
+
).pipe(
|
|
168
|
+
Effect.andThen(
|
|
169
|
+
withTool(tmp.path, (registry) =>
|
|
170
|
+
Effect.gen(function* () {
|
|
171
|
+
yield* settleTool(registry, call({ path: "preserved.txt", content: "after" }, "call-preserved"))
|
|
172
|
+
yield* settleTool(
|
|
173
|
+
registry,
|
|
174
|
+
call({ path: "deduplicated.txt", content: "\uFEFFafter" }, "call-deduplicated"),
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
expect(yield* Effect.promise(() => fs.readFile(preserved, "utf8"))).toBe("\uFEFFafter")
|
|
178
|
+
expect(yield* Effect.promise(() => fs.readFile(deduplicated, "utf8"))).toBe("\uFEFFafter")
|
|
179
|
+
}),
|
|
180
|
+
),
|
|
181
|
+
),
|
|
182
|
+
)
|
|
183
|
+
},
|
|
184
|
+
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
185
|
+
),
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
it.live("accepts an absolute file path inside the active Location", () =>
|
|
189
|
+
Effect.acquireUseRelease(
|
|
190
|
+
Effect.promise(() => tmpdir()),
|
|
191
|
+
(tmp) => {
|
|
192
|
+
reset()
|
|
193
|
+
const target = path.join(tmp.path, "absolute.txt")
|
|
194
|
+
return withTool(tmp.path, (registry) => executeTool(registry, call({ path: target, content: "inside" }))).pipe(
|
|
195
|
+
Effect.andThen((result) =>
|
|
196
|
+
Effect.gen(function* () {
|
|
197
|
+
expect(result).toEqual({ type: "text", value: "Created file successfully: absolute.txt" })
|
|
198
|
+
expect(assertions.map((input) => input.action)).toEqual(["edit"])
|
|
199
|
+
expect(yield* Effect.promise(() => fs.readFile(target, "utf8"))).toBe("inside")
|
|
200
|
+
}),
|
|
201
|
+
),
|
|
202
|
+
)
|
|
203
|
+
},
|
|
204
|
+
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
205
|
+
),
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
it.live("approves an explicit external absolute path before edit", () =>
|
|
209
|
+
Effect.acquireUseRelease(
|
|
210
|
+
Effect.promise(() => Promise.all([tmpdir(), tmpdir()])),
|
|
211
|
+
([active, outside]) => {
|
|
212
|
+
reset()
|
|
213
|
+
const target = path.join(outside.path, "external.txt")
|
|
214
|
+
return withTool(active.path, (registry) =>
|
|
215
|
+
settleTool(registry, call({ path: target, content: "external" })),
|
|
216
|
+
).pipe(
|
|
217
|
+
Effect.andThen((settled) =>
|
|
218
|
+
Effect.gen(function* () {
|
|
219
|
+
const canonicalTarget = path.join(yield* Effect.promise(() => fs.realpath(outside.path)), "external.txt")
|
|
220
|
+
expect(assertions.map((input) => input.action)).toEqual(["external_directory", "edit"])
|
|
221
|
+
expect(assertions[0]).toMatchObject({
|
|
222
|
+
resources: [
|
|
223
|
+
path.join(yield* Effect.promise(() => fs.realpath(outside.path)), "*").replaceAll("\\", "/"),
|
|
224
|
+
],
|
|
225
|
+
})
|
|
226
|
+
expect(assertions[1]).toMatchObject({ resources: [canonicalTarget.replaceAll("\\", "/")], save: ["*"] })
|
|
227
|
+
expect(settled.output?.structured).toMatchObject({
|
|
228
|
+
target: canonicalTarget,
|
|
229
|
+
resource: canonicalTarget.replaceAll("\\", "/"),
|
|
230
|
+
existed: false,
|
|
231
|
+
})
|
|
232
|
+
expect(yield* Effect.promise(() => fs.readFile(target, "utf8"))).toBe("external")
|
|
233
|
+
expect(writes).toEqual([canonicalTarget])
|
|
234
|
+
}),
|
|
235
|
+
),
|
|
236
|
+
)
|
|
237
|
+
},
|
|
238
|
+
([active, outside]) =>
|
|
239
|
+
Effect.promise(() =>
|
|
240
|
+
Promise.all([active[Symbol.asyncDispose](), outside[Symbol.asyncDispose]()]).then(() => undefined),
|
|
241
|
+
),
|
|
242
|
+
),
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
it.live("does not write when external_directory or edit approval is denied", () =>
|
|
246
|
+
Effect.acquireUseRelease(
|
|
247
|
+
Effect.promise(() => Promise.all([tmpdir(), tmpdir()])),
|
|
248
|
+
([active, outside]) =>
|
|
249
|
+
Effect.gen(function* () {
|
|
250
|
+
const external = path.join(outside.path, "denied.txt")
|
|
251
|
+
reset()
|
|
252
|
+
denyAction = "external_directory"
|
|
253
|
+
expect(
|
|
254
|
+
yield* withTool(active.path, (registry) =>
|
|
255
|
+
executeTool(registry, call({ path: external, content: "blocked" })),
|
|
256
|
+
),
|
|
257
|
+
).toEqual({
|
|
258
|
+
type: "error",
|
|
259
|
+
value: `Unable to write ${external}`,
|
|
260
|
+
})
|
|
261
|
+
expect(assertions.map((input) => input.action)).toEqual(["external_directory"])
|
|
262
|
+
expect(writes).toEqual([])
|
|
263
|
+
|
|
264
|
+
reset()
|
|
265
|
+
denyAction = "edit"
|
|
266
|
+
expect(
|
|
267
|
+
yield* withTool(active.path, (registry) =>
|
|
268
|
+
executeTool(registry, call({ path: "denied.txt", content: "blocked" })),
|
|
269
|
+
),
|
|
270
|
+
).toEqual({
|
|
271
|
+
type: "error",
|
|
272
|
+
value: "Unable to write denied.txt",
|
|
273
|
+
})
|
|
274
|
+
expect(assertions.map((input) => input.action)).toEqual(["edit"])
|
|
275
|
+
expect(writes).toEqual([])
|
|
276
|
+
}),
|
|
277
|
+
([active, outside]) =>
|
|
278
|
+
Effect.promise(() =>
|
|
279
|
+
Promise.all([active[Symbol.asyncDispose](), outside[Symbol.asyncDispose]()]).then(() => undefined),
|
|
280
|
+
),
|
|
281
|
+
),
|
|
282
|
+
)
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
test("keeps the locked write schema, semantics docstring, and deferred UX TODOs visible", async () => {
|
|
286
|
+
const source = (await fs.readFile(new URL("../src/tool/write.ts", import.meta.url), "utf8")).replaceAll("\r\n", "\n")
|
|
287
|
+
const definition = await Effect.runPromise(
|
|
288
|
+
withTool(path.dirname(fileURLToPath(import.meta.url)), (registry) => toolDefinitions(registry)),
|
|
289
|
+
)
|
|
290
|
+
const schema = definition[0]?.inputSchema as { readonly properties?: Record<string, unknown> }
|
|
291
|
+
|
|
292
|
+
expect(Object.keys(schema.properties ?? {}).sort()).toEqual(["content", "path"])
|
|
293
|
+
expect(source).toContain(
|
|
294
|
+
"absolute external paths retain mutation capability through a separate\n * external_directory approval before edit approval.",
|
|
295
|
+
)
|
|
296
|
+
for (const todo of [
|
|
297
|
+
"Revisit whether model-facing mutation schemas should prefer absolute `filePath` naming for trained-in compatibility after evaluating model behavior.",
|
|
298
|
+
"Add formatter integration after V2 formatter runtime exists.",
|
|
299
|
+
"Publish watcher/file-edit events after V2 watcher integration exists.",
|
|
300
|
+
"Add snapshots / undo after design exists.",
|
|
301
|
+
"Add LSP notification and diagnostics after V2 LSP runtime exists.",
|
|
302
|
+
]) {
|
|
303
|
+
expect(source).toContain(`TODO: ${todo}`)
|
|
304
|
+
}
|
|
305
|
+
})
|