@zyro-sec/core 1.0.0 → 1.0.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/AGENTS.md +7 -0
- package/bunfig.toml +2 -0
- package/drizzle.config.ts +10 -0
- package/package.json +24 -30
- package/perf/location.bench.ts +44 -0
- package/perf/location.ts +140 -0
- package/perf/session.bench.ts +22 -0
- package/perf/snapshot.bench.ts +67 -0
- package/perf/snapshot.ts +423 -0
- package/schema.json +2763 -0
- package/script/build.ts +44 -0
- package/script/fix-node-pty.ts +28 -0
- package/script/generate-api-skill.ts +361 -0
- package/script/migration.ts +216 -0
- package/script/models-snapshot.ts +82 -0
- package/script/pack.ts +5 -0
- package/script/snapshot-parity-compare.ts +22 -0
- package/script/snapshot-parity-run.sh +20 -0
- package/script/snapshot-parity.ts +710 -0
- package/script/test.ts +53 -0
- package/script/update-models-snapshot.ts +14 -0
- package/script/wellknown-server.ts +112 -0
- package/src/account/sql.ts +36 -0
- package/src/agent.ts +115 -0
- package/src/aisdk-native.ts +397 -0
- package/src/aisdk.ts +1063 -0
- package/src/app.ts +31 -0
- package/src/artifact.ts +617 -0
- package/src/automation/author.ts +10 -0
- package/src/automation/code.ts +269 -0
- package/src/automation/event.ts +35 -0
- package/src/automation/shell.ts +82 -0
- package/src/automation/sql.ts +50 -0
- package/src/automation.ts +1293 -0
- package/src/blob-store.ts +115 -0
- package/src/bus.ts +909 -0
- package/src/codemode/api.ts +44 -0
- package/src/codemode/bun.ts +550 -0
- package/src/codemode/catalog.ts +177 -0
- package/src/codemode/diffs.ts +134 -0
- package/src/codemode/execution.ts +9 -0
- package/src/codemode/fetch.ts +179 -0
- package/src/codemode/instructions.ts +169 -0
- package/src/codemode/job.ts +144 -0
- package/src/codemode/path.ts +45 -0
- package/src/codemode/tool.ts +564 -0
- package/src/command.ts +109 -0
- package/src/config/discovery.ts +183 -0
- package/src/config/integration.ts +134 -0
- package/src/config/managed.ts +6 -0
- package/src/config/markdown.ts +123 -0
- package/src/config/normalize.ts +870 -0
- package/src/config/plugin/agent.ts +192 -0
- package/src/config/plugin/command.ts +229 -0
- package/src/config/plugin/compaction.ts +27 -0
- package/src/config/plugin/compatibility.ts +94 -0
- package/src/config/plugin/entry-observer.ts +79 -0
- package/src/config/plugin/formatter.ts +76 -0
- package/src/config/plugin/image.ts +29 -0
- package/src/config/plugin/instruction.ts +260 -0
- package/src/config/plugin/location-watcher.ts +22 -0
- package/src/config/plugin/mcp.ts +57 -0
- package/src/config/plugin/policy.ts +117 -0
- package/src/config/plugin/provider.ts +274 -0
- package/src/config/plugin/reference.ts +67 -0
- package/src/config/plugin/session-search.ts +21 -0
- package/src/config/plugin/shell.ts +20 -0
- package/src/config/plugin/skill-file.ts +62 -0
- package/src/config/plugin/skill-scan.ts +46 -0
- package/src/config/plugin/skill.ts +202 -0
- package/src/config/plugin/snapshot.ts +21 -0
- package/src/config/plugin/source.ts +194 -0
- package/src/config/plugin/tool-output.ts +24 -0
- package/src/config/plugin/websearch.ts +19 -0
- package/src/config/plugin/worktree.ts +35 -0
- package/src/config/variable.ts +84 -0
- package/src/config/watch.ts +73 -0
- package/src/config.ts +574 -0
- package/src/console-access.ts +22 -0
- package/src/credential/sql.ts +14 -0
- package/src/credential.ts +350 -0
- package/src/database/batch.ts +21 -0
- package/src/database/database.ts +126 -0
- package/src/database/drizzle/README.md +35 -0
- package/src/database/drizzle/effect-sqlite/driver.ts +78 -0
- package/src/database/drizzle/effect-sqlite/index.ts +4 -0
- package/src/database/drizzle/effect-sqlite/session.ts +252 -0
- package/src/database/drizzle/index.ts +5 -0
- package/src/database/drizzle/internal/drizzle-utils.ts +147 -0
- package/src/database/drizzle/sqlite-core/effect/count.ts +58 -0
- package/src/database/drizzle/sqlite-core/effect/db.ts +243 -0
- package/src/database/drizzle/sqlite-core/effect/delete.ts +261 -0
- package/src/database/drizzle/sqlite-core/effect/index.ts +10 -0
- package/src/database/drizzle/sqlite-core/effect/insert.ts +340 -0
- package/src/database/drizzle/sqlite-core/effect/query.ts +198 -0
- package/src/database/drizzle/sqlite-core/effect/raw.ts +49 -0
- package/src/database/drizzle/sqlite-core/effect/select.ts +278 -0
- package/src/database/drizzle/sqlite-core/effect/session.ts +421 -0
- package/src/database/drizzle/sqlite-core/effect/update.ts +402 -0
- package/src/database/drizzle.ts +1 -0
- package/src/database/migration/20260127222353_familiar_lady_ursula.ts +109 -0
- package/src/database/migration/20260211171708_add_project_commands.ts +13 -0
- package/src/database/migration/20260213144116_wakeful_the_professor.ts +25 -0
- package/src/database/migration/20260225215848_workspace.ts +21 -0
- package/src/database/migration/20260227213759_add_session_workspace_id.ts +14 -0
- package/src/database/migration/20260228203230_blue_harpoon.ts +32 -0
- package/src/database/migration/20260303231226_add_workspace_fields.ts +17 -0
- package/src/database/migration/20260309230000_move_org_to_state.ts +17 -0
- package/src/database/migration/20260312043431_session_message_cursor.ts +18 -0
- package/src/database/migration/20260323234822_events.ts +28 -0
- package/src/database/migration/20260410174513_workspace-name.ts +34 -0
- package/src/database/migration/20260413175956_chief_energizer.ts +26 -0
- package/src/database/migration/20260423070820_add_icon_url_override.ts +16 -0
- package/src/database/migration/20260427172553_slow_nightmare.ts +32 -0
- package/src/database/migration/20260428004200_add_session_path.ts +13 -0
- package/src/database/migration/20260501142318_next_venus.ts +14 -0
- package/src/database/migration/20260504145000_add_sync_owner.ts +13 -0
- package/src/database/migration/20260507164347_add_workspace_time.ts +13 -0
- package/src/database/migration/20260510033149_session_usage.ts +58 -0
- package/src/database/migration/20260511000411_data_migration_state.ts +18 -0
- package/src/database/migration/20260511173437_session-metadata.ts +18 -0
- package/src/database/migration/20260601010001_normalize_storage_paths.ts +24 -0
- package/src/database/migration/20260601202201_amazing_prowler.ts +13 -0
- package/src/database/migration/20260602002951_lowly_union_jack.ts +26 -0
- package/src/database/migration/20260602182828_add_project_directories.ts +22 -0
- package/src/database/migration/20260603001617_session_message_projection_indexes.ts +21 -0
- package/src/database/migration/20260603040000_session_message_projection_order.ts +21 -0
- package/src/database/migration/20260603141458_session_input_inbox.ts +27 -0
- package/src/database/migration/20260603160727_jittery_ezekiel_stane.ts +22 -0
- package/src/database/migration/20260604172448_event_sourced_session_input.ts +49 -0
- package/src/database/migration/20260605003541_add_session_context_snapshot.ts +23 -0
- package/src/database/migration/20260605042240_add_context_epoch_agent.ts +13 -0
- package/src/database/migration/20260611035744_credential.ts +27 -0
- package/src/database/migration/20260611192811_lush_chimera.ts +27 -0
- package/src/database/migration/20260612174303_project_dir_strategy.ts +31 -0
- package/src/database/migration/20260622142730_simplify_session_context_epoch.ts +15 -0
- package/src/database/migration/20260622170816_reset_v2_session_state.ts +17 -0
- package/src/database/migration/20260622202450_simplify_session_input.ts +19 -0
- package/src/database/migration/20260804233008_loose_psylocke.ts +173 -0
- package/src/database/migration/20260805200742_import_legacy_credentials.ts +109 -0
- package/src/database/migration/20260808023530_workspace_domain.ts +22 -0
- package/src/database/migration/20260811161259_execution_claim_attempts.ts +13 -0
- package/src/database/migration/20260812181746_session_inbox.ts +30 -0
- package/src/database/migration/20260812213948_worktree.ts +35 -0
- package/src/database/migration/20260819222447_session_viewed_state.ts +15 -0
- package/src/database/migration/20260823191254_nullable_workspace_binding.ts +27 -0
- package/src/database/migration/20260910120000_clear_v1_session_permission.ts +13 -0
- package/src/database/migration/20260923013825_project_time_active.ts +14 -0
- package/src/database/migration/20261007190000_azure_cli_external_credential.ts +21 -0
- package/src/database/migration/20261010180456_project_time_archived.ts +13 -0
- package/src/database/migration/20261024002554_session_allowance.ts +13 -0
- package/src/database/migration/20261024175301_drop_session_allowance.ts +13 -0
- package/src/database/migration/20261025123711_blob.ts +36 -0
- package/src/database/migration/20261025154125_drop_session_pending.ts +16 -0
- package/src/database/migration/20261026223005_schedule.ts +38 -0
- package/src/database/migration/20261029002625_session_part.ts +30 -0
- package/src/database/migration/20261029073502_session_time_busy.ts +13 -0
- package/src/database/migration/20261029165540_schedule_checks.ts +16 -0
- package/src/database/migration/20261030054400_job.ts +60 -0
- package/src/database/migration/20261116043204_automation.ts +83 -0
- package/src/database/migration/20261116181958_automation_event_position.ts +13 -0
- package/src/database/migration/20261116213417_automation_active_index.ts +16 -0
- package/src/database/migration/20261119211416_machine.ts +18 -0
- package/src/database/migration/20261120004954_machine-key.ts +14 -0
- package/src/database/migration.gen.ts +132 -0
- package/src/database/migration.ts +155 -0
- package/src/database/path.ts +98 -0
- package/src/database/schema.gen.ts +363 -0
- package/src/database/schema.sql.ts +10 -0
- package/src/database/sqlite.bun.ts +17 -0
- package/src/database/sqlite.node.ts +25 -0
- package/src/database/sqlite.workerd.ts +227 -0
- package/src/database/storage-failure.ts +58 -0
- package/src/database/v1-migration.bun.ts +1234 -0
- package/src/database/v1-migration.noop.ts +11 -0
- package/src/database/v1-migration.ts +2 -0
- package/src/effect/app-node-builder.ts +30 -0
- package/src/effect/app-node-platform.ts +71 -0
- package/src/effect/client-tls/client-tls.bun.ts +8 -0
- package/src/effect/client-tls/client-tls.node.ts +17 -0
- package/src/effect/client-tls/client-tls.ts +12 -0
- package/src/effect/client-tls/client-tls.workerd.ts +8 -0
- package/src/effect/keyed-mutex.ts +45 -0
- package/src/effect/websocket-constructor.ts +81 -0
- package/src/environment/driver.ts +68 -0
- package/src/environment/environment.ts +152 -0
- package/src/environment/environments.ts +78 -0
- package/src/environment/exec-defaults.ts +200 -0
- package/src/environment/files.ts +79 -0
- package/src/environment/index.ts +34 -0
- package/src/environment/local.ts +101 -0
- package/src/environment/memory.ts +186 -0
- package/src/environment/path.ts +68 -0
- package/src/environment/unavailable.ts +17 -0
- package/src/event/sql.ts +26 -0
- package/src/event-logger.ts +19 -0
- package/src/file-access.ts +352 -0
- package/src/file-mutation.ts +185 -0
- package/src/file-retention.ts +23 -0
- package/src/file-write.ts +110 -0
- package/src/filesystem/fff.bun.ts +15 -0
- package/src/filesystem/fff.node.ts +12 -0
- package/src/filesystem/fff.ts +67 -0
- package/src/filesystem/fff.workerd.ts +12 -0
- package/src/filesystem/file-watch.ts +164 -0
- package/src/filesystem/location-watcher-policy.ts +64 -0
- package/src/filesystem/location-watcher.ts +108 -0
- package/src/filesystem/protected.ts +31 -0
- package/src/filesystem/search.ts +251 -0
- package/src/filesystem/watcher-binding.ts +14 -0
- package/src/filesystem/watcher.ts +282 -0
- package/src/filesystem.ts +270 -0
- package/src/flag/resolve.ts +66 -0
- package/src/flag.ts +64 -0
- package/src/form.ts +370 -0
- package/src/formatter/builtins.ts +294 -0
- package/src/formatter.ts +108 -0
- package/src/generate.ts +397 -0
- package/src/git.ts +1609 -0
- package/src/github-copilot/models.ts +289 -0
- package/src/image/notice.ts +8 -0
- package/src/image/photon-normalize.ts +148 -0
- package/src/image/photon-wasm.bun.ts +4 -0
- package/src/image/photon-wasm.node.ts +4 -0
- package/src/image/photon-wasm.workerd.ts +4 -0
- package/src/image/photon-worker.ts +26 -0
- package/src/image/photon.ts +156 -0
- package/src/image.ts +95 -0
- package/src/instance/service.ts +21 -0
- package/src/instance.ts +191 -0
- package/src/instruction-discovery.ts +165 -0
- package/src/instructions/agent.ts +50 -0
- package/src/instructions/builtins.ts +103 -0
- package/src/instructions/index.ts +287 -0
- package/src/integration/connection.ts +26 -0
- package/src/integration.ts +869 -0
- package/src/job/list.ts +160 -0
- package/src/job/recovery.ts +51 -0
- package/src/job/sql.ts +27 -0
- package/src/job.ts +766 -0
- package/src/kv/sql.ts +9 -0
- package/src/kv.ts +92 -0
- package/src/location-activity.ts +130 -0
- package/src/location-lifecycle.ts +97 -0
- package/src/location-service-map.ts +50 -0
- package/src/location-services.ts +125 -0
- package/src/location.ts +44 -0
- package/src/machine/driver.ts +487 -0
- package/src/machine/frames.ts +133 -0
- package/src/machine/identity.ts +187 -0
- package/src/machine/index.ts +4 -0
- package/src/machine/instructions.ts +61 -0
- package/src/machine/iroh-binding.ts +18 -0
- package/src/machine/iroh.ts +157 -0
- package/src/machine/join.ts +54 -0
- package/src/machine/link.ts +313 -0
- package/src/machine/machines.ts +280 -0
- package/src/machine/noise.ts +326 -0
- package/src/machine/sql.ts +13 -0
- package/src/machine/wire.ts +140 -0
- package/src/machine/worker-client.ts +276 -0
- package/src/managed-policy.ts +65 -0
- package/src/markdown.d.ts +4 -0
- package/src/mcp/client.ts +1198 -0
- package/src/mcp/connection.ts +292 -0
- package/src/mcp/event-stream.ts +34 -0
- package/src/mcp/index.ts +1349 -0
- package/src/mcp/instructions.ts +108 -0
- package/src/mcp/oauth.ts +665 -0
- package/src/mcp/pool.ts +386 -0
- package/src/mcp/socket-client.ts +86 -0
- package/src/mcp/stdio.ts +227 -0
- package/src/mime.ts +75 -0
- package/src/modal/models.ts +150 -0
- package/src/model-resolver.ts +639 -0
- package/src/model-retry.ts +134 -0
- package/src/model.ts +373 -0
- package/src/models-dev/snapshot.txt +1 -0
- package/src/models-dev/v1.ts +203 -0
- package/src/models-dev.ts +899 -0
- package/src/node-ffi.d.ts +18 -0
- package/src/oauth/page.ts +260 -0
- package/src/oauth/redirect.ts +42 -0
- package/src/pentest/mcp-catalog.ts +144 -0
- package/src/permission/policy.ts +240 -0
- package/src/permission/saved.ts +140 -0
- package/src/permission/sql.ts +20 -0
- package/src/permission.ts +419 -0
- package/src/persistent-pty/binary.bun.ts +85 -0
- package/src/persistent-pty/binary.node.ts +5 -0
- package/src/persistent-pty/binary.workerd.ts +5 -0
- package/src/persistent-pty/daemon.ts +750 -0
- package/src/persistent-pty/index.ts +661 -0
- package/src/persistent-pty/pty-binding.ts +6 -0
- package/src/persistent-pty.ts +1 -0
- package/src/plugin/agent.ts +235 -0
- package/src/plugin/command/automation.txt +7 -0
- package/src/plugin/command/initialize.txt +65 -0
- package/src/plugin/command/review.txt +100 -0
- package/src/plugin/command.ts +113 -0
- package/src/plugin/fork-notice.ts +30 -0
- package/src/plugin/goal/continuation.txt +13 -0
- package/src/plugin/goal/judge.txt +20 -0
- package/src/plugin/goal/kickoff.txt +13 -0
- package/src/plugin/goal/reminder.txt +9 -0
- package/src/plugin/goal.ts +501 -0
- package/src/plugin/home-memory.ts +155 -0
- package/src/plugin/hooks.ts +108 -0
- package/src/plugin/host.ts +770 -0
- package/src/plugin/identity.ts +31 -0
- package/src/plugin/instance.ts +45 -0
- package/src/plugin/internal.ts +360 -0
- package/src/plugin/mcp-codemode-defaults.ts +41 -0
- package/src/plugin/mcp-skill.ts +171 -0
- package/src/plugin/models-dev.ts +128 -0
- package/src/plugin/module.ts +186 -0
- package/src/plugin/optimize.ts +97 -0
- package/src/plugin/plan.ts +52 -0
- package/src/plugin/promise.ts +3 -0
- package/src/plugin/provider/amazon-bedrock.ts +121 -0
- package/src/plugin/provider/azure.ts +568 -0
- package/src/plugin/provider/cerebras.ts +16 -0
- package/src/plugin/provider/chatgpt.ts +594 -0
- package/src/plugin/provider/claude-agent/aisdk.ts +36 -0
- package/src/plugin/provider/claude-agent/claude/accounts.ts +104 -0
- package/src/plugin/provider/claude-agent/claude/agent-sdk.ts +1 -0
- package/src/plugin/provider/claude-agent/claude/agent-sdk.workerd.ts +4 -0
- package/src/plugin/provider/claude-agent/claude/claude-folder-worker.ts +10 -0
- package/src/plugin/provider/claude-agent/claude/fork.ts +34 -0
- package/src/plugin/provider/claude-agent/claude/io.ts +88 -0
- package/src/plugin/provider/claude-agent/claude/probe.ts +124 -0
- package/src/plugin/provider/claude-agent/claude/query-options.ts +143 -0
- package/src/plugin/provider/claude-agent/claude/sdk.ts +17 -0
- package/src/plugin/provider/claude-agent/claude/session.ts +162 -0
- package/src/plugin/provider/claude-agent/claude/sessions.ts +508 -0
- package/src/plugin/provider/claude-agent/claude/status.ts +66 -0
- package/src/plugin/provider/claude-agent/claude/websearch.ts +96 -0
- package/src/plugin/provider/claude-agent/index.ts +63 -0
- package/src/plugin/provider/claude-agent/instructions.ts +54 -0
- package/src/plugin/provider/claude-agent/integration.ts +62 -0
- package/src/plugin/provider/claude-agent/language-model/claude-agent-error.ts +49 -0
- package/src/plugin/provider/claude-agent/language-model/claude-agent-language-model.ts +112 -0
- package/src/plugin/provider/claude-agent/language-model/convert-claude-stream.ts +139 -0
- package/src/plugin/provider/claude-agent/language-model/convert-to-claude-message.ts +55 -0
- package/src/plugin/provider/claude-agent/language-model/request-kind.ts +5 -0
- package/src/plugin/provider/claude-agent/language-model/system-prompt.ts +28 -0
- package/src/plugin/provider/claude-agent/language-model/usage.ts +58 -0
- package/src/plugin/provider/claude-agent/provider.ts +178 -0
- package/src/plugin/provider/claude-agent/session.ts +61 -0
- package/src/plugin/provider/claude-agent/sync/catch-up.ts +21 -0
- package/src/plugin/provider/claude-agent/sync/checkpoints.ts +41 -0
- package/src/plugin/provider/claude-agent/sync/decide.ts +58 -0
- package/src/plugin/provider/claude-agent/sync/fingerprint.ts +117 -0
- package/src/plugin/provider/claude-agent/sync/record.ts +42 -0
- package/src/plugin/provider/claude-agent/tools/hooks.ts +23 -0
- package/src/plugin/provider/claude-agent/tools/names.ts +30 -0
- package/src/plugin/provider/claude-agent/tools/pending.ts +72 -0
- package/src/plugin/provider/claude-agent/tools/result.ts +110 -0
- package/src/plugin/provider/claude-agent/tools/server.ts +34 -0
- package/src/plugin/provider/claude-agent/websearch.ts +57 -0
- package/src/plugin/provider/cloudflare-ai-gateway.ts +68 -0
- package/src/plugin/provider/cloudflare-workers-ai.ts +70 -0
- package/src/plugin/provider/configured.ts +18 -0
- package/src/plugin/provider/credential-settings.ts +77 -0
- package/src/plugin/provider/databricks.ts +31 -0
- package/src/plugin/provider/digitalocean.ts +197 -0
- package/src/plugin/provider/dynamic.ts +19 -0
- package/src/plugin/provider/github-copilot.ts +646 -0
- package/src/plugin/provider/gitlab.ts +496 -0
- package/src/plugin/provider/google-vertex.ts +231 -0
- package/src/plugin/provider/kilo.ts +17 -0
- package/src/plugin/provider/llmgateway.ts +27 -0
- package/src/plugin/provider/lmstudio.ts +52 -0
- package/src/plugin/provider/local.ts +240 -0
- package/src/plugin/provider/modal.ts +72 -0
- package/src/plugin/provider/neon.ts +12 -0
- package/src/plugin/provider/nvidia.ts +22 -0
- package/src/plugin/provider/ollama.ts +92 -0
- package/src/plugin/provider/openai-context-caps.ts +52 -0
- package/src/plugin/provider/openai-subscription-models.ts +59 -0
- package/src/plugin/provider/openai.ts +447 -0
- package/src/plugin/provider/opencode-artifacts.ts +216 -0
- package/src/plugin/provider/opencode-watches.ts +753 -0
- package/src/plugin/provider/opencode.ts +883 -0
- package/src/plugin/provider/openrouter.ts +30 -0
- package/src/plugin/provider/poe.ts +176 -0
- package/src/plugin/provider/prompt-cache-key.ts +37 -0
- package/src/plugin/provider/refresh.ts +80 -0
- package/src/plugin/provider/sap-ai-core.ts +39 -0
- package/src/plugin/provider/sdk-factory.ts +24 -0
- package/src/plugin/provider/snowflake-cortex.ts +266 -0
- package/src/plugin/provider/vllm.ts +34 -0
- package/src/plugin/provider/xai.ts +236 -0
- package/src/plugin/provider/zenmux.ts +21 -0
- package/src/plugin/provider.ts +64 -0
- package/src/plugin/sdk.ts +44 -0
- package/src/plugin/service.ts +42 -0
- package/src/plugin/skill/opencode/api/agent.md +18 -0
- package/src/plugin/skill/opencode/api/automation.md +63 -0
- package/src/plugin/skill/opencode/api/blob.md +10 -0
- package/src/plugin/skill/opencode/api/command.md +12 -0
- package/src/plugin/skill/opencode/api/form.md +22 -0
- package/src/plugin/skill/opencode/api/generate.md +96 -0
- package/src/plugin/skill/opencode/api/info.md +11 -0
- package/src/plugin/skill/opencode/api/location.md +17 -0
- package/src/plugin/skill/opencode/api/model.md +22 -0
- package/src/plugin/skill/opencode/api/permission.md +13 -0
- package/src/plugin/skill/opencode/api/project.md +29 -0
- package/src/plugin/skill/opencode/api/provider.md +18 -0
- package/src/plugin/skill/opencode/api/session.md +313 -0
- package/src/plugin/skill/opencode/api/skill.md +12 -0
- package/src/plugin/skill/opencode/api/vcs.md +60 -0
- package/src/plugin/skill/opencode/api/worktree.md +49 -0
- package/src/plugin/skill/opencode/api.md +119 -0
- package/src/plugin/skill/opencode/api.ts +40 -0
- package/src/plugin/skill/opencode-api.md +17 -0
- package/src/plugin/skill/opencode.md +154 -0
- package/src/plugin/skill/report.md +152 -0
- package/src/plugin/skill.ts +111 -0
- package/src/plugin/source-directory.ts +33 -0
- package/src/plugin/supervisor.ts +288 -0
- package/src/plugin/system-prompt/AGENTS.md +5 -0
- package/src/plugin/system-prompt/anthropic.txt +2 -0
- package/src/plugin/system-prompt/gpt-6.2.txt +71 -0
- package/src/plugin/system-prompt/gpt-astra.txt +46 -0
- package/src/plugin/system-prompt/gpt.txt +40 -0
- package/src/plugin/system-prompt/kimi.txt +96 -0
- package/src/plugin/system-prompt/meta.txt +56 -0
- package/src/plugin/system-prompt/trinity.txt +98 -0
- package/src/plugin/tool-input-repair.ts +232 -0
- package/src/plugin/update.ts +87 -0
- package/src/plugin/vcs/git.ts +802 -0
- package/src/plugin/vcs/hg.ts +234 -0
- package/src/plugin/verbosity.ts +58 -0
- package/src/plugin/warming.ts +224 -0
- package/src/plugin/websearch/exa.ts +69 -0
- package/src/plugin/websearch/firecrawl.ts +71 -0
- package/src/plugin/websearch/index.ts +13 -0
- package/src/plugin/websearch/mcp.ts +69 -0
- package/src/plugin/websearch/parallel.ts +90 -0
- package/src/plugin/websearch/provider.ts +44 -0
- package/src/plugin/websearch/tavily.ts +73 -0
- package/src/plugin/websearch/tinyfish.ts +131 -0
- package/src/plugin.ts +320 -0
- package/src/project/icon.ts +167 -0
- package/src/project/schema.ts +25 -0
- package/src/project/sql.ts +63 -0
- package/src/project.ts +536 -0
- package/src/provider.ts +553 -0
- package/src/pty/protocol.ts +37 -0
- package/src/pty/pty.bun.ts +44 -0
- package/src/pty/pty.node.ts +34 -0
- package/src/pty/pty.ts +25 -0
- package/src/pty/pty.workerd.ts +9 -0
- package/src/pty/ticket.ts +74 -0
- package/src/pty.ts +311 -0
- package/src/push/crypto.ts +39 -0
- package/src/push/list.ts +380 -0
- package/src/push/sender.ts +185 -0
- package/src/push/watcher.ts +169 -0
- package/src/reference/instructions.ts +82 -0
- package/src/reference.ts +129 -0
- package/src/repository-cache.ts +251 -0
- package/src/repository.ts +205 -0
- package/src/ripgrep/binary.ts +166 -0
- package/src/ripgrep.ts +311 -0
- package/src/rpc.ts +288 -0
- package/src/schema.ts +39 -0
- package/src/session/affinity.ts +8 -0
- package/src/session/background-result.ts +5 -0
- package/src/session/background.ts +125 -0
- package/src/session/blob.ts +503 -0
- package/src/session/command.ts +38 -0
- package/src/session/compaction-background.ts +55 -0
- package/src/session/compaction-subagents.ts +103 -0
- package/src/session/compaction.ts +1320 -0
- package/src/session/context.ts +296 -0
- package/src/session/cwd-instructions.ts +147 -0
- package/src/session/cwd-store.ts +66 -0
- package/src/session/cwd.ts +75 -0
- package/src/session/diff.ts +149 -0
- package/src/session/environment.ts +33 -0
- package/src/session/error.ts +105 -0
- package/src/session/event.ts +2 -0
- package/src/session/execution/restart.ts +558 -0
- package/src/session/execution/subagent-report.ts +203 -0
- package/src/session/execution.ts +241 -0
- package/src/session/generate.ts +78 -0
- package/src/session/history.ts +405 -0
- package/src/session/inbox.ts +625 -0
- package/src/session/info.ts +62 -0
- package/src/session/instruction-entry.ts +171 -0
- package/src/session/instruction-state.ts +277 -0
- package/src/session/instructions.ts +126 -0
- package/src/session/message-updater.ts +497 -0
- package/src/session/message.ts +2 -0
- package/src/session/model-request.ts +474 -0
- package/src/session/model-transport.ts +571 -0
- package/src/session/move.ts +199 -0
- package/src/session/projector.ts +1197 -0
- package/src/session/prompt.ts +253 -0
- package/src/session/recent-text.ts +93 -0
- package/src/session/revert.ts +112 -0
- package/src/session/run-coordinator.ts +198 -0
- package/src/session/runner/index.ts +46 -0
- package/src/session/runner/live-tool-metadata.ts +41 -0
- package/src/session/runner/llm.ts +481 -0
- package/src/session/runner/max-steps.ts +16 -0
- package/src/session/runner/model.ts +138 -0
- package/src/session/runner/prompt/system.txt +16 -0
- package/src/session/runner/publish-llm-event.ts +642 -0
- package/src/session/runner/retry.ts +78 -0
- package/src/session/runner/step.ts +401 -0
- package/src/session/runner/to-llm-message.ts +341 -0
- package/src/session/schema.ts +9 -0
- package/src/session/search-build.ts +116 -0
- package/src/session/search-index.ts +552 -0
- package/src/session/search.ts +672 -0
- package/src/session/session.ts +407 -0
- package/src/session/shell.ts +35 -0
- package/src/session/skill.ts +16 -0
- package/src/session/sql.ts +215 -0
- package/src/session/stats.ts +463 -0
- package/src/session/store.ts +323 -0
- package/src/session/stored.ts +44 -0
- package/src/session/subagent-completion.ts +95 -0
- package/src/session/subagent-depth.ts +21 -0
- package/src/session/subagent-job.ts +61 -0
- package/src/session/synthetic.ts +49 -0
- package/src/session/system-prompt.ts +28 -0
- package/src/session/title.ts +174 -0
- package/src/session/to-session-error.ts +179 -0
- package/src/session/transfer.ts +369 -0
- package/src/session/usage.ts +64 -0
- package/src/session.ts +602 -0
- package/src/shared-cache.ts +103 -0
- package/src/shell/parse.ts +645 -0
- package/src/shell/permissions.ts +60 -0
- package/src/shell/result.ts +115 -0
- package/src/shell/scan.ts +2585 -0
- package/src/shell/select.ts +241 -0
- package/src/shell.ts +1274 -0
- package/src/skill/discovery.ts +205 -0
- package/src/skill/instructions.ts +84 -0
- package/src/skill.ts +277 -0
- package/src/snapshot.ts +248 -0
- package/src/state.ts +271 -0
- package/src/tool/AGENTS.md +71 -0
- package/src/tool/html-markdown.ts +651 -0
- package/src/tool/http-body.ts +30 -0
- package/src/tool/mcp.ts +177 -0
- package/src/tool/model-policy.ts +38 -0
- package/src/tool/patch-grammar.txt +19 -0
- package/src/tool/patch.txt +33 -0
- package/src/tool/plugin/artifact.ts +171 -0
- package/src/tool/plugin/automation.ts +246 -0
- package/src/tool/plugin/cd.ts +103 -0
- package/src/tool/plugin/edit.ts +371 -0
- package/src/tool/plugin/file-diff.ts +42 -0
- package/src/tool/plugin/glob.ts +123 -0
- package/src/tool/plugin/grep.ts +152 -0
- package/src/tool/plugin/image-generate.ts +396 -0
- package/src/tool/plugin/machine.ts +36 -0
- package/src/tool/plugin/mcp-events.ts +72 -0
- package/src/tool/plugin/mcp-resource.ts +100 -0
- package/src/tool/plugin/opencode.ts +316 -0
- package/src/tool/plugin/patch.ts +358 -0
- package/src/tool/plugin/question.ts +130 -0
- package/src/tool/plugin/read.ts +413 -0
- package/src/tool/plugin/session-interrupt.ts +63 -0
- package/src/tool/plugin/session-search.ts +99 -0
- package/src/tool/plugin/shell.ts +594 -0
- package/src/tool/plugin/skill.ts +74 -0
- package/src/tool/plugin/subagent.ts +269 -0
- package/src/tool/plugin/todo.ts +83 -0
- package/src/tool/plugin/video-generate.ts +403 -0
- package/src/tool/plugin/webfetch.ts +214 -0
- package/src/tool/plugin/websearch.ts +196 -0
- package/src/tool/plugin/write.ts +72 -0
- package/src/tool/read-filesystem.ts +350 -0
- package/src/tool/runtime.ts +311 -0
- package/src/tool/search.ts +34 -0
- package/src/tool/todowrite.txt +7 -0
- package/src/tool-output.ts +220 -0
- package/src/tool.ts +579 -0
- package/src/usage-limits.ts +192 -0
- package/src/util/canonical-json.ts +11 -0
- package/src/util/error-summary.ts +33 -0
- package/src/util/git-executable.ts +59 -0
- package/src/util/lazy.ts +11 -0
- package/src/util/slug.ts +74 -0
- package/src/util/token.ts +5 -0
- package/src/util/which.ts +37 -0
- package/src/util/wildcard.ts +15 -0
- package/src/v1/config/agent.ts +69 -0
- package/src/v1/config/command.ts +13 -0
- package/src/v1/config/mcp.ts +69 -0
- package/src/v1/config/migrate.ts +269 -0
- package/src/v1/config/permission.ts +42 -0
- package/src/v1/config/plugin.ts +9 -0
- package/src/v1/config/provider-options.ts +59 -0
- package/src/v1/config/provider.ts +113 -0
- package/src/variant.ts +699 -0
- package/src/vcs/patch.ts +106 -0
- package/src/vcs.ts +262 -0
- package/src/video-generation.ts +344 -0
- package/src/voice.ts +194 -0
- package/src/websearch.ts +239 -0
- package/src/wellknown/plugin.ts +36 -0
- package/src/wellknown.ts +230 -0
- package/src/workspace/driver.ts +89 -0
- package/src/workspace/sql.ts +11 -0
- package/src/workspace.ts +566 -0
- package/src/worktree/directory.ts +16 -0
- package/src/worktree/git.ts +39 -0
- package/src/worktree/sql.ts +21 -0
- package/src/worktree/strategies.ts +74 -0
- package/src/worktree.ts +357 -0
- package/test/agent.test.ts +224 -0
- package/test/aisdk-native.test.ts +590 -0
- package/test/aisdk.test.ts +1259 -0
- package/test/app.test.ts +6 -0
- package/test/artifact.test.ts +216 -0
- package/test/automation-event.test.ts +688 -0
- package/test/automation-shell.test.ts +293 -0
- package/test/automation.test.ts +1950 -0
- package/test/blob-store.test.ts +37 -0
- package/test/boot-work.test.ts +215 -0
- package/test/browser-attach.test.ts +150 -0
- package/test/browser-idle.test.ts +107 -0
- package/test/bus-session-routing.test.ts +334 -0
- package/test/bus-unpersisted.test.ts +50 -0
- package/test/bus.test.ts +1347 -0
- package/test/catalog.test.ts +704 -0
- package/test/codemode/catalog.test.ts +339 -0
- package/test/codemode/diffs.test.ts +90 -0
- package/test/codemode/instructions.test.ts +123 -0
- package/test/codemode-execute-options.test.ts +172 -0
- package/test/codemode-script-diffs.test.ts +131 -0
- package/test/codemode.test.ts +132 -0
- package/test/command.test.ts +71 -0
- package/test/config/agent.test.ts +847 -0
- package/test/config/command-subagent.test.ts +165 -0
- package/test/config/command.test.ts +628 -0
- package/test/config/compaction.test.ts +184 -0
- package/test/config/config.test.ts +2113 -0
- package/test/config/discovery.test.ts +150 -0
- package/test/config/entry-observer.test.ts +51 -0
- package/test/config/fixture/skills/first-source/first/SKILL.md +6 -0
- package/test/config/fixture/skills/second-source/second/SKILL.md +6 -0
- package/test/config/image.test.ts +78 -0
- package/test/config/markdown.test.ts +129 -0
- package/test/config/model.test.ts +28 -0
- package/test/config/normalization.test.ts +854 -0
- package/test/config/overlay.test.ts +205 -0
- package/test/config/policy.test.ts +432 -0
- package/test/config/provider-options.test.ts +55 -0
- package/test/config/provider.test.ts +1338 -0
- package/test/config/reload.test.ts +526 -0
- package/test/config/session-search.test.ts +61 -0
- package/test/config/shell.test.ts +42 -0
- package/test/config/skill.test.ts +602 -0
- package/test/config/snapshot.test.ts +61 -0
- package/test/config/tool-output.test.ts +59 -0
- package/test/config/watch.test.ts +53 -0
- package/test/config/websearch.test.ts +45 -0
- package/test/credential-refresh.test.ts +113 -0
- package/test/credential.test.ts +271 -0
- package/test/database-drizzle.test.ts +228 -0
- package/test/database-migration.test.ts +783 -0
- package/test/database.test.ts +39 -0
- package/test/effect/cross-spawn-spawner.test.ts +522 -0
- package/test/effect/keyed-mutex.test.ts +73 -0
- package/test/effect/layer-node/layer-node-types.test.ts +230 -0
- package/test/effect/layer-node/layer-node.test.ts +467 -0
- package/test/effect/layer-node/node-build.test.ts +148 -0
- package/test/effect/observability.test.ts +141 -0
- package/test/effect-app-node-platform.test.ts +86 -0
- package/test/effect-simplification-types.test.ts +12 -0
- package/test/environment.test.ts +154 -0
- package/test/environments.test.ts +406 -0
- package/test/event-logger.test.ts +50 -0
- package/test/file-access-path.test.ts +336 -0
- package/test/file-access.test.ts +178 -0
- package/test/file-mutation.test.ts +244 -0
- package/test/filesystem/file-watch.test.ts +213 -0
- package/test/filesystem/filesystem.test.ts +383 -0
- package/test/filesystem/location-watcher-policy.test.ts +70 -0
- package/test/filesystem/search.test.ts +385 -0
- package/test/filesystem/watcher.test.ts +719 -0
- package/test/fixture/app-execution-alias.ts +17 -0
- package/test/fixture/codemode.ts +63 -0
- package/test/fixture/config-nodes.ts +40 -0
- package/test/fixture/durable-object-storage.ts +58 -0
- package/test/fixture/effect-flock-worker.ts +60 -0
- package/test/fixture/env.ts +22 -0
- package/test/fixture/environment.ts +52 -0
- package/test/fixture/event-server.ts +65 -0
- package/test/fixture/flock-worker.ts +72 -0
- package/test/fixture/git.ts +86 -0
- package/test/fixture/global.ts +26 -0
- package/test/fixture/held-stdio.cjs +36 -0
- package/test/fixture/html-markdown.ts +7 -0
- package/test/fixture/link-v1-transcript.json +27 -0
- package/test/fixture/location.ts +27 -0
- package/test/fixture/lock-worker.ts +53 -0
- package/test/fixture/machine-v2.json +66 -0
- package/test/fixture/machine-worker.ts +284 -0
- package/test/fixture/mcp-echo.ts +14 -0
- package/test/fixture/mcp-legacy-silent.ts +22 -0
- package/test/fixture/mcp-modern-stdio.ts +15 -0
- package/test/fixture/mcp-output-schema.ts +63 -0
- package/test/fixture/mcp-prompts.ts +29 -0
- package/test/fixture/mcp-timeout.ts +32 -0
- package/test/fixture/mcp-union-output-schema.ts +41 -0
- package/test/fixture/mcp.ts +44 -0
- package/test/fixture/models.ts +6 -0
- package/test/fixture/native/2.0.14-media.json +22 -0
- package/test/fixture/noise-xx-vectors.json +75 -0
- package/test/fixture/persistent-pty-daemon.ts +347 -0
- package/test/fixture/persistent-pty.ts +9 -0
- package/test/fixture/photon-crash-worker.ts +10 -0
- package/test/fixture/photon-exit.ts +29 -0
- package/test/fixture/photon-hang-worker.ts +2 -0
- package/test/fixture/policy.ts +98 -0
- package/test/fixture/prompt-location.ts +33 -0
- package/test/fixture/pty-windows.ts +69 -0
- package/test/fixture/selector.ts +12 -0
- package/test/fixture/shell-daemon.ts +122 -0
- package/test/fixture/spawn.ts +24 -0
- package/test/fixture/sqlite-node-client.ts +100 -0
- package/test/fixture/target-environment.ts +58 -0
- package/test/fixture/tmpdir.ts +44 -0
- package/test/fixture/v1-config/attachment.ts +25 -0
- package/test/fixture/v1-config/config.ts +182 -0
- package/test/fixture/v1-config/formatter.ts +13 -0
- package/test/fixture/v1-config/layout.ts +6 -0
- package/test/fixture/v1-config/lsp.ts +80 -0
- package/test/fixture/v1-config/server.ts +19 -0
- package/test/fixture/v1-config/skills.ts +13 -0
- package/test/fixtures/recordings/session-runner/openai-chat-streams-text.json +27 -0
- package/test/flag.test.ts +203 -0
- package/test/form.test.ts +357 -0
- package/test/formatter-target-environment.test.ts +138 -0
- package/test/formatter.test.ts +350 -0
- package/test/generate.test.ts +752 -0
- package/test/git.test.ts +666 -0
- package/test/github-copilot/models.test.ts +167 -0
- package/test/image-photon.test.ts +177 -0
- package/test/instance-vanilla.test.ts +124 -0
- package/test/instruction-discovery.test.ts +804 -0
- package/test/instruction-state.test.ts +537 -0
- package/test/instructions/builtins.test.ts +83 -0
- package/test/instructions/index.test.ts +248 -0
- package/test/integration-refresh.test.ts +118 -0
- package/test/integration.test.ts +716 -0
- package/test/job.test.ts +968 -0
- package/test/kv.test.ts +81 -0
- package/test/lib/clock.ts +43 -0
- package/test/lib/effect.ts +80 -0
- package/test/lib/environment-conformance.ts +204 -0
- package/test/lib/eventually.ts +20 -0
- package/test/lib/image.ts +7 -0
- package/test/lib/instructions.ts +47 -0
- package/test/lib/permission.ts +12 -0
- package/test/lib/project.ts +26 -0
- package/test/lib/session-message.ts +26 -0
- package/test/lib/tool.ts +102 -0
- package/test/lib/websearch.ts +63 -0
- package/test/lib/websocket-server.ts +73 -0
- package/test/location-activity.test.ts +315 -0
- package/test/location-filesystem.test.ts +332 -0
- package/test/location-layer.test.ts +784 -0
- package/test/location-missing-project.test.ts +71 -0
- package/test/location-retain.test.ts +98 -0
- package/test/location.test.ts +46 -0
- package/test/logging.test.ts +14 -0
- package/test/machine-frames.test.ts +768 -0
- package/test/machine-instructions.test.ts +135 -0
- package/test/machine-join.test.ts +223 -0
- package/test/machine-link.test.ts +527 -0
- package/test/machine-noise.test.ts +429 -0
- package/test/machine-path.test.ts +1202 -0
- package/test/machine.test.ts +786 -0
- package/test/machines.test.ts +730 -0
- package/test/mcp-attach.test.ts +403 -0
- package/test/mcp-events.test.ts +299 -0
- package/test/mcp-import-boundary.test.ts +44 -0
- package/test/mcp-instructions.test.ts +221 -0
- package/test/mcp-oauth.test.ts +1289 -0
- package/test/mcp-skills.test.ts +274 -0
- package/test/mcp-socket-client.test.ts +210 -0
- package/test/mcp-stdio.test.ts +145 -0
- package/test/mcp.test.ts +4196 -0
- package/test/mime.test.ts +80 -0
- package/test/modal/models.test.ts +137 -0
- package/test/model-free.test.ts +120 -0
- package/test/model-plugins.test.ts +469 -0
- package/test/model-resolver.test.ts +1695 -0
- package/test/model.test.ts +16 -0
- package/test/models.test.ts +1404 -0
- package/test/network-guard.test.ts +56 -0
- package/test/npm-config.test.ts +42 -0
- package/test/npm.test.ts +545 -0
- package/test/oauth-page.test.ts +15 -0
- package/test/opencode-api-skill.test.ts +16 -0
- package/test/patch.test.ts +509 -0
- package/test/permission.test.ts +1179 -0
- package/test/persistent-pty-daemon.test.ts +337 -0
- package/test/persistent-pty-session.test.ts +295 -0
- package/test/plugin/automation.test.ts +124 -0
- package/test/plugin/command.test.ts +137 -0
- package/test/plugin/fixture.ts +174 -0
- package/test/plugin/fixtures/greeting.ts +14 -0
- package/test/plugin/fixtures/models-dev-reasoning.json +811 -0
- package/test/plugin/fixtures/models-dev.json +92 -0
- package/test/plugin/fixtures/provider-factory.ts +9 -0
- package/test/plugin/goal-watchdog.test.ts +212 -0
- package/test/plugin/goal.test.ts +609 -0
- package/test/plugin/home-memory.test.ts +131 -0
- package/test/plugin/host-model.test.ts +34 -0
- package/test/plugin/host.ts +540 -0
- package/test/plugin/identity.test.ts +60 -0
- package/test/plugin/internal-flag.test.ts +101 -0
- package/test/plugin/mcp-codemode-defaults.test.ts +124 -0
- package/test/plugin/models-dev.test.ts +1406 -0
- package/test/plugin/module.test.ts +494 -0
- package/test/plugin/optimize.test.ts +343 -0
- package/test/plugin/permission-assert.test.ts +94 -0
- package/test/plugin/plan.test.ts +162 -0
- package/test/plugin/promise-tool-cancel.test.ts +279 -0
- package/test/plugin/promise-tool.test.ts +227 -0
- package/test/plugin/provider/claude-agent/claude/accounts.test.ts +326 -0
- package/test/plugin/provider/claude-agent/claude/branches.test.ts +300 -0
- package/test/plugin/provider/claude-agent/claude/probe.test.ts +99 -0
- package/test/plugin/provider/claude-agent/claude/recorder.test.ts +19 -0
- package/test/plugin/provider/claude-agent/claude/session.test.ts +30 -0
- package/test/plugin/provider/claude-agent/claude/sessions.test.ts +490 -0
- package/test/plugin/provider/claude-agent/claude/status.test.ts +67 -0
- package/test/plugin/provider/claude-agent/claude/sync.test.ts +70 -0
- package/test/plugin/provider/claude-agent/claude/tools.test.ts +382 -0
- package/test/plugin/provider/claude-agent/fixtures/marker.pdf +68 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/api-error.jsonl +16 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/controls.jsonl +107 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/max-steps.jsonl +133 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/startup-logged-out.jsonl +4 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/startup.jsonl +52 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/sync.jsonl +73 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/text-cancel.jsonl +37 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/text-resume.jsonl +21 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/text.jsonl +35 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools-abort.jsonl +62 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools-cancel.jsonl +63 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools-continue.jsonl +58 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools-media.jsonl +80 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools-waiting-cancel.jsonl +58 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/tools.jsonl +74 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/utility.jsonl +28 -0
- package/test/plugin/provider/claude-agent/fixtures/recordings/websearch.jsonl +13 -0
- package/test/plugin/provider/claude-agent/fixtures/red.png +0 -0
- package/test/plugin/provider/claude-agent/language-model/convert.test.ts +95 -0
- package/test/plugin/provider/claude-agent/language-model/error.test.ts +94 -0
- package/test/plugin/provider/claude-agent/lib/fake-claude.ts +411 -0
- package/test/plugin/provider/claude-agent/lib/fake-io.ts +20 -0
- package/test/plugin/provider/claude-agent/lib/recorder.ts +61 -0
- package/test/plugin/provider/claude-agent/lib/sessions.ts +126 -0
- package/test/plugin/provider/claude-agent/lib/tools.ts +95 -0
- package/test/plugin/provider/claude-agent/plugin.test.ts +651 -0
- package/test/plugin/provider/claude-agent/sync/sync.test.ts +213 -0
- package/test/plugin/provider/claude-agent/tools/tools.test.ts +85 -0
- package/test/plugin/provider/claude-agent/websearch.test.ts +106 -0
- package/test/plugin/provider-amazon-bedrock.test.ts +225 -0
- package/test/plugin/provider-azure.test.ts +793 -0
- package/test/plugin/provider-cerebras.test.ts +62 -0
- package/test/plugin/provider-chatgpt.test.ts +1278 -0
- package/test/plugin/provider-cloudflare-ai-gateway.test.ts +160 -0
- package/test/plugin/provider-cloudflare-workers-ai.test.ts +158 -0
- package/test/plugin/provider-databricks.test.ts +45 -0
- package/test/plugin/provider-digitalocean.test.ts +322 -0
- package/test/plugin/provider-dynamic.test.ts +179 -0
- package/test/plugin/provider-github-copilot.test.ts +806 -0
- package/test/plugin/provider-gitlab-oauth.test.ts +407 -0
- package/test/plugin/provider-gitlab.test.ts +546 -0
- package/test/plugin/provider-google-vertex.test.ts +288 -0
- package/test/plugin/provider-kilo.test.ts +66 -0
- package/test/plugin/provider-llmgateway.test.ts +72 -0
- package/test/plugin/provider-lmstudio.test.ts +487 -0
- package/test/plugin/provider-nvidia.test.ts +84 -0
- package/test/plugin/provider-ollama.test.ts +312 -0
- package/test/plugin/provider-openai-context-caps.test.ts +80 -0
- package/test/plugin/provider-openai.test.ts +447 -0
- package/test/plugin/provider-opencode-artifacts.test.ts +236 -0
- package/test/plugin/provider-opencode-watches.test.ts +1103 -0
- package/test/plugin/provider-opencode.test.ts +2590 -0
- package/test/plugin/provider-openrouter.test.ts +83 -0
- package/test/plugin/provider-poe.test.ts +360 -0
- package/test/plugin/provider-sap-ai-core.test.ts +138 -0
- package/test/plugin/provider-snowflake-cortex.test.ts +294 -0
- package/test/plugin/provider-vllm.test.ts +382 -0
- package/test/plugin/provider-xai.test.ts +92 -0
- package/test/plugin/provider-zenmux.test.ts +100 -0
- package/test/plugin/session-compact.test.ts +52 -0
- package/test/plugin/session-instructions.test.ts +197 -0
- package/test/plugin/session-list.test.ts +52 -0
- package/test/plugin/session-remove.test.ts +61 -0
- package/test/plugin/skill.test.ts +81 -0
- package/test/plugin/supervisor-reload.test.ts +401 -0
- package/test/plugin/supervisor.test.ts +485 -0
- package/test/plugin/tool-input-repair-integration.test.ts +296 -0
- package/test/plugin/tool-input-repair.test.ts +457 -0
- package/test/plugin/vcs-init.test.ts +48 -0
- package/test/plugin/verbosity.test.ts +163 -0
- package/test/plugin/warming.test.ts +314 -0
- package/test/plugin/websearch-fixture.ts +63 -0
- package/test/plugin/websearch.test.ts +368 -0
- package/test/plugin/worktree.test.ts +52 -0
- package/test/plugin-failure.test.ts +305 -0
- package/test/plugin.test.ts +756 -0
- package/test/preload.test.ts +32 -0
- package/test/preload.ts +2 -0
- package/test/process/process.test.ts +340 -0
- package/test/project-activate.test.ts +144 -0
- package/test/project-icon.test.ts +198 -0
- package/test/project.test.ts +754 -0
- package/test/provider.test.ts +92 -0
- package/test/pty/info-schema.test.ts +23 -0
- package/test/pty/protocol.test.ts +27 -0
- package/test/pty/pty-session.test.ts +224 -0
- package/test/pty/pty-windows.test.ts +41 -0
- package/test/pty/ticket.test.ts +76 -0
- package/test/push-list.test.ts +257 -0
- package/test/push-sender.test.ts +235 -0
- package/test/push-watcher.test.ts +359 -0
- package/test/reference-instructions.test.ts +112 -0
- package/test/reference.test.ts +209 -0
- package/test/repository-cache.test.ts +235 -0
- package/test/repository.test.ts +89 -0
- package/test/ripgrep.test.ts +253 -0
- package/test/rpc-handler-errors.test.ts +62 -0
- package/test/session-activation.test.ts +75 -0
- package/test/session-archive.test.ts +81 -0
- package/test/session-background.test.ts +97 -0
- package/test/session-checkpoint-transport.test.ts +168 -0
- package/test/session-compact.test.ts +171 -0
- package/test/session-compaction-transport.test.ts +131 -0
- package/test/session-compaction.test.ts +1871 -0
- package/test/session-create.test.ts +1643 -0
- package/test/session-cwd-instructions.test.ts +304 -0
- package/test/session-cwd.test.ts +484 -0
- package/test/session-diff.test.ts +207 -0
- package/test/session-environment.test.ts +30 -0
- package/test/session-error.test.ts +434 -0
- package/test/session-execution.test.ts +2298 -0
- package/test/session-generate.test.ts +502 -0
- package/test/session-instructions.test.ts +378 -0
- package/test/session-list.test.ts +72 -0
- package/test/session-live-tool-metadata.test.ts +43 -0
- package/test/session-log.test.ts +123 -0
- package/test/session-model-request-hooks.test.ts +270 -0
- package/test/session-model-request.test.ts +243 -0
- package/test/session-model-transport-live.test.ts +329 -0
- package/test/session-model-transport.test.ts +1109 -0
- package/test/session-move.test.ts +671 -0
- package/test/session-native-compaction.test.ts +425 -0
- package/test/session-native.test.ts +359 -0
- package/test/session-owned.test.ts +1073 -0
- package/test/session-projector.test.ts +2797 -0
- package/test/session-prompt.test.ts +1549 -0
- package/test/session-remove.test.ts +117 -0
- package/test/session-revert.test.ts +121 -0
- package/test/session-run-coordinator.test.ts +711 -0
- package/test/session-runner-message.test.ts +1574 -0
- package/test/session-runner-recorded.test.ts +288 -0
- package/test/session-runner-retry.test.ts +130 -0
- package/test/session-runner-tool-events.test.ts +662 -0
- package/test/session-runner.test.ts +7859 -0
- package/test/session-search-build.test.ts +214 -0
- package/test/session-search-index.test.ts +524 -0
- package/test/session-search.test.ts +375 -0
- package/test/session-shell.test.ts +437 -0
- package/test/session-skill.test.ts +228 -0
- package/test/session-sql.types.ts +25 -0
- package/test/session-stats.test.ts +429 -0
- package/test/session-step.test.ts +435 -0
- package/test/session-store.test.ts +543 -0
- package/test/session-system-prompt.test.ts +8 -0
- package/test/session-title.test.ts +767 -0
- package/test/session-tool-progress.test.ts +159 -0
- package/test/session-usage.test.ts +24 -0
- package/test/session-view.test.ts +218 -0
- package/test/session-wait.test.ts +41 -0
- package/test/shared-cache.test.ts +161 -0
- package/test/shared-schema.test.ts +187 -0
- package/test/shell-cleanup.test.ts +52 -0
- package/test/shell-daemon.test.ts +663 -0
- package/test/shell-parse-compatibility.test.ts +451 -0
- package/test/shell-parse-parity.test.ts +170 -0
- package/test/shell-parse-syntax.test.ts +201 -0
- package/test/shell-parse.test.ts +251 -0
- package/test/shell-restart.test.ts +268 -0
- package/test/shell-result.test.ts +65 -0
- package/test/shell-retention.test.ts +162 -0
- package/test/shell-scan/adversarial.test.ts +112 -0
- package/test/shell-scan/arithmetic.test.ts +143 -0
- package/test/shell-scan/bash-safety.test.ts +291 -0
- package/test/shell-scan/bash-syntax.test.ts +361 -0
- package/test/shell-scan/closure.test.ts +47 -0
- package/test/shell-scan/compound-parity.test.ts +131 -0
- package/test/shell-scan/generated.test.ts +201 -0
- package/test/shell-scan/oracle.test.ts +762 -0
- package/test/shell-scan/parity-regressions.test.ts +146 -0
- package/test/shell-scan/powershell-runtime.test.ts +604 -0
- package/test/shell-scan/powershell-safety.test.ts +470 -0
- package/test/shell-scan/powershell-syntax.test.ts +177 -0
- package/test/shell-scan/redirect.test.ts +168 -0
- package/test/shell-scan/scan.test.ts +496 -0
- package/test/shell.test.ts +140 -0
- package/test/skill/instructions.test.ts +216 -0
- package/test/skill-discovery.test.ts +154 -0
- package/test/skill.test.ts +297 -0
- package/test/snapshot.test.ts +488 -0
- package/test/sqlite-bundle.test.ts +53 -0
- package/test/sqlite-interrupt.test.ts +86 -0
- package/test/sqlite-node.test.ts +80 -0
- package/test/sqlite-workerd.test.ts +111 -0
- package/test/state-group.test.ts +138 -0
- package/test/state-replay.test.ts +207 -0
- package/test/state.test.ts +679 -0
- package/test/storage-failure.test.ts +88 -0
- package/test/subagent-completion.test.ts +170 -0
- package/test/subagent-idle-e2e.test.ts +825 -0
- package/test/subagent-lifetime.test.ts +146 -0
- package/test/subagent-report.test.ts +834 -0
- package/test/tool/file-diff.test.ts +45 -0
- package/test/tool-automation.test.ts +345 -0
- package/test/tool-cd.test.ts +372 -0
- package/test/tool-edit.test.ts +888 -0
- package/test/tool-execute.test.ts +1077 -0
- package/test/tool-html-markdown-budget.test.ts +68 -0
- package/test/tool-image-generate.test.ts +547 -0
- package/test/tool-machine.test.ts +84 -0
- package/test/tool-mcp-events.test.ts +90 -0
- package/test/tool-media-target-environment.test.ts +213 -0
- package/test/tool-model-policy.test.ts +289 -0
- package/test/tool-opencode.test.ts +303 -0
- package/test/tool-output.test.ts +334 -0
- package/test/tool-patch-target-environment.test.ts +239 -0
- package/test/tool-patch.test.ts +1265 -0
- package/test/tool-question.test.ts +260 -0
- package/test/tool-read-filesystem.test.ts +833 -0
- package/test/tool-read.test.ts +1341 -0
- package/test/tool-registry.test.ts +1662 -0
- package/test/tool-schema.test.ts +538 -0
- package/test/tool-search-target-environment.test.ts +103 -0
- package/test/tool-search.test.ts +411 -0
- package/test/tool-session-search.test.ts +178 -0
- package/test/tool-shell-target-environment.test.ts +193 -0
- package/test/tool-shell.test.ts +2650 -0
- package/test/tool-skill.test.ts +203 -0
- package/test/tool-subagent.test.ts +1046 -0
- package/test/tool-target-environment.test.ts +183 -0
- package/test/tool-todo.test.ts +75 -0
- package/test/tool-video-generate.test.ts +227 -0
- package/test/tool-webfetch.test.ts +737 -0
- package/test/tool-websearch.test.ts +482 -0
- package/test/tool-write.test.ts +440 -0
- package/test/usage-limits.test.ts +210 -0
- package/test/util/effect-flock.test.ts +331 -0
- package/test/util/error-summary.test.ts +19 -0
- package/test/util/flock.test.ts +326 -0
- package/test/util/fs-util.test.ts +50 -0
- package/test/util/git-executable.test.ts +80 -0
- package/test/util/which.test.ts +99 -0
- package/test/v1-migration.test.ts +1508 -0
- package/test/variant.test.ts +575 -0
- package/test/vcs-hg.test.ts +239 -0
- package/test/vcs.test.ts +1396 -0
- package/test/video-generation.test.ts +146 -0
- package/test/voice.test.ts +332 -0
- package/test/websearch.test.ts +593 -0
- package/test/wellknown.test.ts +132 -0
- package/test/worker-client.test.ts +529 -0
- package/test/workspace.test.ts +828 -0
- package/test/worktree.test.ts +944 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +18 -0
- package/tsconfig.tests.json +13 -0
|
@@ -0,0 +1,1662 @@
|
|
|
1
|
+
import { describe, expect } from "bun:test"
|
|
2
|
+
import { Agent } from "@zyro-sec/core/agent"
|
|
3
|
+
import { Permission } from "@zyro-sec/core/permission"
|
|
4
|
+
import { Flag } from "@zyro-sec/core/flag"
|
|
5
|
+
import { AppNodeBuilder } from "@zyro-sec/core/effect/app-node-builder"
|
|
6
|
+
import { Image } from "@zyro-sec/core/image"
|
|
7
|
+
import { PluginHooks } from "@zyro-sec/core/plugin/hooks"
|
|
8
|
+
import { Session } from "@zyro-sec/core/session"
|
|
9
|
+
import { SessionMessage } from "@zyro-sec/core/session/message"
|
|
10
|
+
import { State } from "@zyro-sec/core/state"
|
|
11
|
+
import { CodeModeJob } from "@zyro-sec/core/codemode/job"
|
|
12
|
+
import { Tool } from "@zyro-sec/core/tool"
|
|
13
|
+
import type { Info } from "@zyro-sec/schema/tool"
|
|
14
|
+
import { LayerNode } from "@zyro-sec/util/effect/layer-node"
|
|
15
|
+
import { codeModeListings, executeTool, toolDefinitions, toolNodeReplacements } from "./lib/tool"
|
|
16
|
+
import { Deferred, Effect, Exit, Fiber, Layer, Logger, Schema, SchemaGetter, SchemaIssue, Scope } from "effect"
|
|
17
|
+
import { z } from "zod"
|
|
18
|
+
import { testEffect } from "./lib/effect"
|
|
19
|
+
import { codeModeServices } from "./fixture/codemode"
|
|
20
|
+
|
|
21
|
+
const imageStore = Layer.mock(Image.Service, {
|
|
22
|
+
normalize: (resource, content) => {
|
|
23
|
+
if (resource === "corrupt.png") return Effect.fail(new Image.DecodeError({ resource }))
|
|
24
|
+
if (resource === "too-large.png")
|
|
25
|
+
return Effect.fail(
|
|
26
|
+
new Image.SizeError({
|
|
27
|
+
resource,
|
|
28
|
+
width: 9_000,
|
|
29
|
+
height: 9_000,
|
|
30
|
+
bytes: content.content.length,
|
|
31
|
+
maxWidth: 2_000,
|
|
32
|
+
maxHeight: 2_000,
|
|
33
|
+
maxBytes: 5,
|
|
34
|
+
}),
|
|
35
|
+
)
|
|
36
|
+
return Effect.succeed({
|
|
37
|
+
...content,
|
|
38
|
+
content: Buffer.from(`${Buffer.from(content.content, "base64").toString()} normalized`).toString("base64"),
|
|
39
|
+
mime: "image/jpeg",
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
const registryLayer = AppNodeBuilder.build(LayerNode.group([Tool.node, PluginHooks.node]), [
|
|
44
|
+
...toolNodeReplacements(),
|
|
45
|
+
Image.node.replace(imageStore),
|
|
46
|
+
])
|
|
47
|
+
const it = testEffect(registryLayer.pipe(Layer.provide(Layer.succeed(Flag.Overrides, undefined))))
|
|
48
|
+
const codeModeIt = testEffect(registryLayer.pipe(Layer.provide(Layer.succeed(Flag.Overrides, "full_codemode"))))
|
|
49
|
+
const identity = {
|
|
50
|
+
agent: Agent.ID.make("build"),
|
|
51
|
+
messageID: SessionMessage.ID.make("msg_registry"),
|
|
52
|
+
}
|
|
53
|
+
const sessionID = Session.ID.make("ses_registry")
|
|
54
|
+
const call = (name: string, id = `call-${name}`): Parameters<Tool.Snapshot["execute"]>[0] => ({
|
|
55
|
+
sessionID,
|
|
56
|
+
...identity,
|
|
57
|
+
call: { type: "tool-call", id, name, input: { text: name } },
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const make = (): Info => ({
|
|
61
|
+
name: "echo",
|
|
62
|
+
description: "Echo text",
|
|
63
|
+
input: Schema.Struct({ text: Schema.String }),
|
|
64
|
+
output: Schema.Struct({ text: Schema.String }),
|
|
65
|
+
execute: ({ text }) => Effect.succeed({ output: { text }, content: text }),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const constant = (text: string): Info => ({
|
|
69
|
+
name: "constant",
|
|
70
|
+
description: "Return text",
|
|
71
|
+
input: Schema.Struct({ text: Schema.String }),
|
|
72
|
+
output: Schema.Struct({ text: Schema.String }),
|
|
73
|
+
execute: () => Effect.succeed({ output: { text }, content: text }),
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const transform = (service: Tool.Interface, tools: Readonly<Record<string, Info>>, options?: Tool.Options) =>
|
|
77
|
+
service.transform((editor) =>
|
|
78
|
+
Object.entries(tools).forEach(([name, tool]) => editor.add({ ...tool, name, options: options ?? tool.options })),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
describe("Code Mode path and Bun", () => {
|
|
82
|
+
const types = Effect.gen(function* () {
|
|
83
|
+
const tools = yield* Tool.Service
|
|
84
|
+
const snapshot = yield* tools.snapshot(undefined, { services: codeModeServices("/session/dir") })
|
|
85
|
+
const result = yield* snapshot.execute({
|
|
86
|
+
...call("execute"),
|
|
87
|
+
call: {
|
|
88
|
+
type: "tool-call",
|
|
89
|
+
id: "call-globals",
|
|
90
|
+
name: "execute",
|
|
91
|
+
input: { code: `return [typeof path, typeof Bun]` },
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
return JSON.parse(result.output.output)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it.effect("are not available without full_codemode", () =>
|
|
98
|
+
Effect.gen(function* () {
|
|
99
|
+
expect(yield* types).toEqual(["undefined", "undefined"])
|
|
100
|
+
}),
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
codeModeIt.effect("are available with full_codemode", () =>
|
|
104
|
+
Effect.gen(function* () {
|
|
105
|
+
expect(yield* types).toEqual(["object", "object"])
|
|
106
|
+
}),
|
|
107
|
+
)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
describe("Tool", () => {
|
|
111
|
+
it.effect("reads the current editor tools by effective name", () =>
|
|
112
|
+
Effect.gen(function* () {
|
|
113
|
+
const service = yield* Tool.Service
|
|
114
|
+
yield* transform(service, { echo: make() }, { namespace: "acme", codemode: false })
|
|
115
|
+
yield* service.transform((editor) => {
|
|
116
|
+
expect(editor.list().map((tool) => tool.id)).toEqual(["acme_echo"])
|
|
117
|
+
expect(editor.get("acme_echo")?.id).toBe("acme_echo")
|
|
118
|
+
expect(editor.get("acme_echo")?.name).toBe("echo")
|
|
119
|
+
expect(editor.get("missing")).toBeUndefined()
|
|
120
|
+
})
|
|
121
|
+
}),
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
it.effect("replays mutations on refreshed sources and restores tools on disposal and scope cleanup", () =>
|
|
125
|
+
Effect.gen(function* () {
|
|
126
|
+
const service = yield* Tool.Service
|
|
127
|
+
let text = "original"
|
|
128
|
+
const source = yield* Scope.make()
|
|
129
|
+
yield* service
|
|
130
|
+
.transform((editor) => {
|
|
131
|
+
editor.add({ ...constant(text), name: "echo", options: { namespace: "acme", codemode: false } })
|
|
132
|
+
editor.add({ ...make(), name: "hidden" })
|
|
133
|
+
})
|
|
134
|
+
.pipe(Scope.provide(source))
|
|
135
|
+
const original = yield* service.snapshot()
|
|
136
|
+
const update = yield* service.transform((editor) => {
|
|
137
|
+
editor.update("missing", () => {
|
|
138
|
+
throw new Error("must not create a tool")
|
|
139
|
+
})
|
|
140
|
+
editor.remove("missing")
|
|
141
|
+
editor.update("acme_echo", (tool) => {
|
|
142
|
+
const execute = tool.execute
|
|
143
|
+
tool.description = "Updated"
|
|
144
|
+
tool.execute = (input, context) =>
|
|
145
|
+
execute(input, context).pipe(
|
|
146
|
+
Effect.map((result) => ({ ...result, output: { text: `${result.output.text} updated` } })),
|
|
147
|
+
)
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
const scope = yield* Scope.make()
|
|
151
|
+
yield* service.transform((editor) => editor.remove("hidden")).pipe(Scope.provide(scope))
|
|
152
|
+
expect((yield* service.snapshot()).codeModeCatalog?.tools).toEqual([])
|
|
153
|
+
expect((yield* executeTool(service, call("acme_echo"))).output).toEqual({ text: "original updated" })
|
|
154
|
+
|
|
155
|
+
text = "refreshed"
|
|
156
|
+
yield* service.reload()
|
|
157
|
+
const refreshed = yield* service.snapshot()
|
|
158
|
+
expect(refreshed.definitions[0]?.description).toBe("Updated")
|
|
159
|
+
expect(refreshed.codeModeCatalog?.tools).toEqual([])
|
|
160
|
+
expect((yield* refreshed.execute(call("acme_echo"))).output).toEqual({ text: "refreshed updated" })
|
|
161
|
+
expect((yield* original.execute(call("acme_echo"))).output).toEqual({ text: "original" })
|
|
162
|
+
|
|
163
|
+
yield* update.dispose
|
|
164
|
+
yield* update.dispose
|
|
165
|
+
expect((yield* executeTool(service, call("acme_echo"))).output).toEqual({ text: "refreshed" })
|
|
166
|
+
yield* Scope.close(scope, Exit.void)
|
|
167
|
+
expect(codeModeListings((yield* service.snapshot()).codeModeCatalog!).map((tool) => tool.path)).toEqual([
|
|
168
|
+
"hidden",
|
|
169
|
+
])
|
|
170
|
+
|
|
171
|
+
yield* service.transform((editor) =>
|
|
172
|
+
editor.update("acme_echo", (tool) => {
|
|
173
|
+
tool.description = "Updated again"
|
|
174
|
+
}),
|
|
175
|
+
)
|
|
176
|
+
yield* Scope.close(source, Exit.void)
|
|
177
|
+
expect((yield* service.snapshot()).definitions.map((tool) => tool.name)).toEqual(["execute"])
|
|
178
|
+
}),
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
it.effect("updates schemas and executors without renaming tools and applies removal in order", () =>
|
|
182
|
+
Effect.gen(function* () {
|
|
183
|
+
const service = yield* Tool.Service
|
|
184
|
+
yield* service.transform((editor) => {
|
|
185
|
+
editor.add({ ...make(), options: { namespace: "acme.tools", codemode: false } })
|
|
186
|
+
editor.add({ ...make(), name: "removed", options: { codemode: false } })
|
|
187
|
+
editor.remove("removed")
|
|
188
|
+
editor.update("removed", () => {
|
|
189
|
+
throw new Error("must not resurrect a tool")
|
|
190
|
+
})
|
|
191
|
+
editor.remove("acme_tools_echo")
|
|
192
|
+
editor.add({ ...make(), options: { namespace: "acme.tools", codemode: false } })
|
|
193
|
+
editor.update("acme_tools_echo", (tool) => {
|
|
194
|
+
tool.name = "renamed"
|
|
195
|
+
tool.options = { namespace: "other", codemode: false }
|
|
196
|
+
tool.input = Schema.Struct({ value: Schema.Finite })
|
|
197
|
+
tool.output = Schema.Finite
|
|
198
|
+
tool.execute = ({ value }) => Effect.succeed({ output: value + 1 })
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
const snapshot = yield* service.snapshot()
|
|
202
|
+
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["acme_tools_echo", "execute"])
|
|
203
|
+
expect(snapshot.definitions[0]?.inputSchema.properties).toEqual({ value: { type: "number" } })
|
|
204
|
+
expect(
|
|
205
|
+
(yield* snapshot.execute({
|
|
206
|
+
...call("acme_tools_echo"),
|
|
207
|
+
call: {
|
|
208
|
+
type: "tool-call",
|
|
209
|
+
id: "updated",
|
|
210
|
+
name: "acme_tools_echo",
|
|
211
|
+
input: { value: 2 },
|
|
212
|
+
},
|
|
213
|
+
})).output,
|
|
214
|
+
).toBe(3)
|
|
215
|
+
expect(yield* snapshot.execute(call("acme_tools_echo")).pipe(Effect.flip)).toBeInstanceOf(Tool.Error)
|
|
216
|
+
}),
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
it.effect("converts schemas at registration and reuses them in every snapshot", () =>
|
|
220
|
+
Effect.gen(function* () {
|
|
221
|
+
const service = yield* Tool.Service
|
|
222
|
+
let builds = 0
|
|
223
|
+
const portable = {
|
|
224
|
+
"~standard": {
|
|
225
|
+
version: 1,
|
|
226
|
+
vendor: "test",
|
|
227
|
+
validate: (value: unknown) => ({ value }),
|
|
228
|
+
jsonSchema: {
|
|
229
|
+
input: () => {
|
|
230
|
+
builds++
|
|
231
|
+
return { type: "object", properties: { text: { type: "string" } } }
|
|
232
|
+
},
|
|
233
|
+
output: () => ({ type: "string" }),
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
} as const
|
|
237
|
+
yield* transform(service, { portable: { ...make(), input: portable } }, { codemode: false })
|
|
238
|
+
const registered = builds
|
|
239
|
+
|
|
240
|
+
const first = yield* service.snapshot()
|
|
241
|
+
const second = yield* service.snapshot()
|
|
242
|
+
|
|
243
|
+
expect(builds).toBe(registered)
|
|
244
|
+
expect(second.definitions).toHaveLength(2)
|
|
245
|
+
second.definitions.forEach((item, index) => expect(item).toBe(first.definitions[index]))
|
|
246
|
+
}),
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
it.effect("skips invalid updates without dropping the existing definition", () =>
|
|
250
|
+
Effect.gen(function* () {
|
|
251
|
+
const service = yield* Tool.Service
|
|
252
|
+
yield* transform(service, { echo: make() }, { codemode: false })
|
|
253
|
+
yield* service.transform((editor) =>
|
|
254
|
+
editor.update("echo", (tool) => {
|
|
255
|
+
Object.assign(tool, { description: undefined })
|
|
256
|
+
}),
|
|
257
|
+
)
|
|
258
|
+
expect((yield* service.snapshot()).definitions[0]?.description).toBe("Echo text")
|
|
259
|
+
expect((yield* executeTool(service, call("echo"))).output).toEqual({ text: "echo" })
|
|
260
|
+
}),
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
it.effect("replays empty sources on reload and keeps advertised snapshots", () =>
|
|
264
|
+
Effect.gen(function* () {
|
|
265
|
+
const service = yield* Tool.Service
|
|
266
|
+
let source: Info[] = []
|
|
267
|
+
yield* service.transform((editor) => source.forEach((tool) => editor.add(tool)))
|
|
268
|
+
expect((yield* service.snapshot()).definitions.map((tool) => tool.name)).toEqual(["execute"])
|
|
269
|
+
|
|
270
|
+
const tool = { ...constant("first"), name: "echo", options: { codemode: false } }
|
|
271
|
+
source = [tool]
|
|
272
|
+
yield* service.reload()
|
|
273
|
+
const advertised = yield* service.snapshot()
|
|
274
|
+
expect((yield* advertised.execute(call("echo"))).output).toEqual({ text: "first" })
|
|
275
|
+
|
|
276
|
+
tool.execute = constant("second").execute
|
|
277
|
+
expect((yield* advertised.execute(call("echo"))).output).toEqual({ text: "first" })
|
|
278
|
+
yield* service.reload()
|
|
279
|
+
expect((yield* executeTool(service, call("echo"))).output).toEqual({ text: "second" })
|
|
280
|
+
expect((yield* advertised.execute(call("echo"))).output).toEqual({ text: "first" })
|
|
281
|
+
|
|
282
|
+
source = []
|
|
283
|
+
yield* service.reload()
|
|
284
|
+
expect((yield* service.snapshot()).definitions.map((tool) => tool.name)).toEqual(["execute"])
|
|
285
|
+
expect((yield* advertised.execute(call("echo"))).output).toEqual({ text: "first" })
|
|
286
|
+
}),
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
it.effect("disposes overlays once and replays remaining transforms in order", () =>
|
|
290
|
+
Effect.gen(function* () {
|
|
291
|
+
const service = yield* Tool.Service
|
|
292
|
+
const runs: string[] = []
|
|
293
|
+
yield* service.transform((editor) => {
|
|
294
|
+
runs.push("base")
|
|
295
|
+
editor.add({ ...constant("base"), name: "echo", options: { codemode: false } })
|
|
296
|
+
})
|
|
297
|
+
const scope = yield* Scope.make()
|
|
298
|
+
const overlay = yield* service
|
|
299
|
+
.transform((editor) => {
|
|
300
|
+
runs.push("overlay")
|
|
301
|
+
editor.add({ ...constant("overlay"), name: "echo", options: { codemode: false } })
|
|
302
|
+
})
|
|
303
|
+
.pipe(Scope.provide(scope))
|
|
304
|
+
// Each registration outside a batch notifies immediately, and every rebuild replays all transforms.
|
|
305
|
+
expect(runs).toEqual(["base", "base", "overlay"])
|
|
306
|
+
expect((yield* executeTool(service, call("echo"))).output).toEqual({ text: "overlay" })
|
|
307
|
+
|
|
308
|
+
yield* overlay.dispose
|
|
309
|
+
expect(runs).toEqual(["base", "base", "overlay", "base"])
|
|
310
|
+
expect((yield* executeTool(service, call("echo"))).output).toEqual({ text: "base" })
|
|
311
|
+
yield* overlay.dispose
|
|
312
|
+
yield* Scope.close(scope, Exit.void)
|
|
313
|
+
expect(runs).toEqual(["base", "base", "overlay", "base"])
|
|
314
|
+
}),
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
it.effect("reads pending tools inside a batch and suppresses terminal teardown replay", () =>
|
|
318
|
+
Effect.gen(function* () {
|
|
319
|
+
const service = yield* Tool.Service
|
|
320
|
+
const runs: string[] = []
|
|
321
|
+
const scope = yield* Scope.make()
|
|
322
|
+
yield* State.batch(
|
|
323
|
+
Effect.gen(function* () {
|
|
324
|
+
yield* service.transform((editor) => {
|
|
325
|
+
runs.push("base")
|
|
326
|
+
editor.add({ ...constant("base"), name: "echo", options: { codemode: false } })
|
|
327
|
+
})
|
|
328
|
+
yield* service.transform((editor) => {
|
|
329
|
+
runs.push("overlay")
|
|
330
|
+
editor.add({ ...constant("overlay"), name: "echo", options: { codemode: false } })
|
|
331
|
+
})
|
|
332
|
+
expect(runs).toEqual([])
|
|
333
|
+
expect((yield* service.snapshot()).definitions.map((tool) => tool.name)).toEqual(["echo", "execute"])
|
|
334
|
+
expect(runs).toEqual(["base", "overlay"])
|
|
335
|
+
}).pipe(Scope.provide(scope)),
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
expect(runs).toEqual(["base", "overlay"])
|
|
339
|
+
expect((yield* executeTool(service, call("echo"))).output).toEqual({ text: "overlay" })
|
|
340
|
+
yield* State.shutdown(Scope.close(scope, Exit.void))
|
|
341
|
+
expect(runs).toEqual(["base", "overlay"])
|
|
342
|
+
}),
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
it.effect("uses the last valid addition on replay and restores earlier transforms on disposal", () =>
|
|
346
|
+
Effect.gen(function* () {
|
|
347
|
+
const service = yield* Tool.Service
|
|
348
|
+
yield* transform(service, { echo_tool: constant("base") }, { codemode: false })
|
|
349
|
+
let source = [{ ...constant("overlay"), name: "echo.tool", options: { codemode: false } }]
|
|
350
|
+
const registration = yield* service.transform((editor) => source.forEach((tool) => editor.add(tool)))
|
|
351
|
+
expect((yield* executeTool(service, call("echo_tool"))).output).toEqual({ text: "overlay" })
|
|
352
|
+
|
|
353
|
+
source = [...source, { ...constant("collision"), name: "echo_tool", options: { codemode: false } }]
|
|
354
|
+
yield* service.reload()
|
|
355
|
+
expect((yield* executeTool(service, call("echo_tool"))).output).toEqual({ text: "collision" })
|
|
356
|
+
|
|
357
|
+
yield* registration.dispose
|
|
358
|
+
expect((yield* executeTool(service, call("echo_tool"))).output).toEqual({ text: "base" })
|
|
359
|
+
yield* service.transform((editor) => source.forEach((tool) => editor.add(tool)))
|
|
360
|
+
|
|
361
|
+
source = [{ ...constant("invalid"), name: "", options: { codemode: false } }]
|
|
362
|
+
yield* service.reload()
|
|
363
|
+
expect((yield* executeTool(service, call("echo_tool"))).output).toEqual({ text: "base" })
|
|
364
|
+
}),
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
it.effect("logs and skips invalid dotted namespaces", () => {
|
|
368
|
+
const output: unknown[] = []
|
|
369
|
+
const logger = Logger.map(Logger.formatStructured, (entry) => {
|
|
370
|
+
output.push(entry.message)
|
|
371
|
+
})
|
|
372
|
+
return Effect.gen(function* () {
|
|
373
|
+
const service = yield* Tool.Service
|
|
374
|
+
yield* transform(service, { echo: make() }, { namespace: "slack..admin" })
|
|
375
|
+
|
|
376
|
+
expect(output).toEqual([
|
|
377
|
+
[
|
|
378
|
+
"Skipping invalid tool registration",
|
|
379
|
+
{ name: "echo", namespace: "slack..admin", error: 'Invalid tool namespace: "slack..admin"' },
|
|
380
|
+
],
|
|
381
|
+
])
|
|
382
|
+
const snapshot = yield* service.snapshot()
|
|
383
|
+
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["execute"])
|
|
384
|
+
expect(snapshot.codeModeCatalog?.tools).toEqual([])
|
|
385
|
+
}).pipe(Effect.provide(Logger.layer([logger])))
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
it.effect("skips invalid and reserved names while letting the last normalized name win", () =>
|
|
389
|
+
Effect.gen(function* () {
|
|
390
|
+
const service = yield* Tool.Service
|
|
391
|
+
yield* transform(
|
|
392
|
+
service,
|
|
393
|
+
{
|
|
394
|
+
before: make(),
|
|
395
|
+
"": make(),
|
|
396
|
+
"echo.tool": constant("first"),
|
|
397
|
+
echo_tool: constant("last"),
|
|
398
|
+
execute: make(),
|
|
399
|
+
after: make(),
|
|
400
|
+
},
|
|
401
|
+
{ codemode: false },
|
|
402
|
+
)
|
|
403
|
+
const snapshot = yield* service.snapshot()
|
|
404
|
+
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["after", "before", "echo_tool", "execute"])
|
|
405
|
+
expect((yield* snapshot.execute(call("before"))).output).toEqual({ text: "before" })
|
|
406
|
+
expect((yield* snapshot.execute(call("after"))).output).toEqual({ text: "after" })
|
|
407
|
+
expect((yield* snapshot.execute(call("echo_tool"))).output).toEqual({ text: "last" })
|
|
408
|
+
expect(snapshot.codeModeCatalog?.tools).toEqual([])
|
|
409
|
+
}),
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
it.effect("executes native tools without requiring letter-leading names or namespace segments", () =>
|
|
413
|
+
Effect.gen(function* () {
|
|
414
|
+
const service = yield* Tool.Service
|
|
415
|
+
yield* transform(
|
|
416
|
+
service,
|
|
417
|
+
{ "2d_get_scene": make(), "123": make(), _lookup: make(), "-lookup": make() },
|
|
418
|
+
{ codemode: false },
|
|
419
|
+
)
|
|
420
|
+
yield* transform(service, { "2d_get_scene": make() }, { namespace: "123._private.-tools", codemode: false })
|
|
421
|
+
|
|
422
|
+
const snapshot = yield* service.snapshot()
|
|
423
|
+
expect(snapshot.definitions.map((tool) => tool.name)).toEqual([
|
|
424
|
+
"-lookup",
|
|
425
|
+
"123",
|
|
426
|
+
"123__private_-tools_2d_get_scene",
|
|
427
|
+
"2d_get_scene",
|
|
428
|
+
"_lookup",
|
|
429
|
+
"execute",
|
|
430
|
+
])
|
|
431
|
+
for (const name of ["2d_get_scene", "123", "_lookup", "-lookup", "123__private_-tools_2d_get_scene"]) {
|
|
432
|
+
expect((yield* snapshot.execute(call(name))).output).toEqual({ text: name })
|
|
433
|
+
}
|
|
434
|
+
}),
|
|
435
|
+
)
|
|
436
|
+
|
|
437
|
+
it.effect("executes Code Mode tools without requiring letter-leading names or namespace segments", () =>
|
|
438
|
+
Effect.gen(function* () {
|
|
439
|
+
const service = yield* Tool.Service
|
|
440
|
+
yield* transform(service, { "2d_get_scene": make(), "123": make(), _lookup: make(), "-lookup": make() })
|
|
441
|
+
yield* transform(service, { "2d_get_scene": make() }, { namespace: "123._private.-tools", codemode: true })
|
|
442
|
+
|
|
443
|
+
const snapshot = yield* service.snapshot()
|
|
444
|
+
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["execute"])
|
|
445
|
+
expect(codeModeListings(snapshot.codeModeCatalog!).map((tool) => tool.path)).toEqual([
|
|
446
|
+
"-lookup",
|
|
447
|
+
"123",
|
|
448
|
+
"123._private.-tools.2d_get_scene",
|
|
449
|
+
"2d_get_scene",
|
|
450
|
+
"_lookup",
|
|
451
|
+
])
|
|
452
|
+
const result = yield* snapshot.execute({
|
|
453
|
+
...call("execute"),
|
|
454
|
+
call: {
|
|
455
|
+
type: "tool-call",
|
|
456
|
+
id: "call-nonletter-names",
|
|
457
|
+
name: "execute",
|
|
458
|
+
input: {
|
|
459
|
+
code: `const results = await Promise.all([
|
|
460
|
+
tools["2d_get_scene"]({ text: "digit" }),
|
|
461
|
+
tools["123"]({ text: "numeric" }),
|
|
462
|
+
tools._lookup({ text: "underscore" }),
|
|
463
|
+
tools["-lookup"]({ text: "hyphen" }),
|
|
464
|
+
tools["123"]._private["-tools"]["2d_get_scene"]({ text: "namespaced" }),
|
|
465
|
+
]); return results.map(result => result.text).join(",");`,
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
})
|
|
469
|
+
expect(result.content).toEqual([{ type: "text", text: "digit,numeric,underscore,hyphen,namespaced" }])
|
|
470
|
+
}),
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
it.effect("keeps healthy tools when another namespace is invalid", () =>
|
|
474
|
+
Effect.gen(function* () {
|
|
475
|
+
const service = yield* Tool.Service
|
|
476
|
+
yield* service.transform((editor) => {
|
|
477
|
+
editor.namespace({ name: "invalid..namespace", description: "Invalid" })
|
|
478
|
+
editor.add({ ...make(), name: "first", options: { codemode: false } })
|
|
479
|
+
editor.add({ ...make(), name: "second", options: { namespace: "invalid..namespace", codemode: false } })
|
|
480
|
+
editor.add({ ...make(), name: "second", options: { namespace: "invalid__namespace" } })
|
|
481
|
+
})
|
|
482
|
+
|
|
483
|
+
const snapshot = yield* service.snapshot()
|
|
484
|
+
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["first", "execute"])
|
|
485
|
+
expect(codeModeListings(snapshot.codeModeCatalog!).map((tool) => tool.path)).toEqual([
|
|
486
|
+
"invalid__namespace.second",
|
|
487
|
+
])
|
|
488
|
+
}),
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
it.effect("keeps namespace descriptions beside catalog tools", () =>
|
|
492
|
+
Effect.gen(function* () {
|
|
493
|
+
const service = yield* Tool.Service
|
|
494
|
+
yield* service.transform((editor) => {
|
|
495
|
+
editor.namespace({ name: "registry", description: "Package publishing and discovery" })
|
|
496
|
+
editor.namespace({ name: "registry.search", description: "Pricing operations" })
|
|
497
|
+
editor.add({ ...make(), name: "plain", options: { namespace: "legacy" } })
|
|
498
|
+
editor.add({ ...make(), name: "direct", options: { namespace: "registry", codemode: false } })
|
|
499
|
+
editor.add({ ...make(), name: "search", description: "Search packages", options: { namespace: "registry" } })
|
|
500
|
+
editor.add({ ...make(), name: "sales", description: "Read sales", options: { namespace: "registry.search" } })
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
const snapshot = yield* service.snapshot()
|
|
504
|
+
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["registry_direct", "execute"])
|
|
505
|
+
expect(codeModeListings(snapshot.codeModeCatalog!).map((tool) => tool.path)).toEqual([
|
|
506
|
+
"legacy.plain",
|
|
507
|
+
"registry.search",
|
|
508
|
+
"registry.search.sales",
|
|
509
|
+
])
|
|
510
|
+
expect(snapshot.codeModeCatalog?.tools).toEqual([
|
|
511
|
+
{
|
|
512
|
+
type: "namespace",
|
|
513
|
+
name: "legacy",
|
|
514
|
+
tools: [expect.objectContaining({ type: "tool", name: "plain" })],
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
type: "namespace",
|
|
518
|
+
name: "registry",
|
|
519
|
+
description: "Package publishing and discovery",
|
|
520
|
+
tools: [
|
|
521
|
+
expect.objectContaining({ type: "tool", name: "search" }),
|
|
522
|
+
{
|
|
523
|
+
type: "namespace",
|
|
524
|
+
name: "search",
|
|
525
|
+
description: "Pricing operations",
|
|
526
|
+
tools: [expect.objectContaining({ type: "tool", name: "sales" })],
|
|
527
|
+
},
|
|
528
|
+
],
|
|
529
|
+
},
|
|
530
|
+
])
|
|
531
|
+
const result = yield* snapshot.execute({
|
|
532
|
+
...call("execute"),
|
|
533
|
+
call: {
|
|
534
|
+
type: "tool-call",
|
|
535
|
+
id: "namespace-search",
|
|
536
|
+
name: "execute",
|
|
537
|
+
input: { code: 'return search({ query: "pricing operations" })' },
|
|
538
|
+
},
|
|
539
|
+
})
|
|
540
|
+
expect(result.output).toMatchObject({ output: expect.stringContaining("tools.registry.search") })
|
|
541
|
+
const callable = yield* snapshot.execute({
|
|
542
|
+
...call("execute"),
|
|
543
|
+
call: {
|
|
544
|
+
type: "tool-call",
|
|
545
|
+
id: "callable-namespace",
|
|
546
|
+
name: "execute",
|
|
547
|
+
input: {
|
|
548
|
+
code: `return await Promise.all([
|
|
549
|
+
tools.registry.search({ text: "search" }),
|
|
550
|
+
tools.registry.search.sales({ text: "sales" }),
|
|
551
|
+
])`,
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
})
|
|
555
|
+
expect(callable.output).toMatchObject({
|
|
556
|
+
output: expect.stringContaining('"text":"sales"'),
|
|
557
|
+
toolCalls: [
|
|
558
|
+
{ tool: "registry.search", status: "completed" },
|
|
559
|
+
{ tool: "registry.search.sales", status: "completed" },
|
|
560
|
+
],
|
|
561
|
+
})
|
|
562
|
+
}),
|
|
563
|
+
)
|
|
564
|
+
|
|
565
|
+
it.effect("retains namespace descriptions in executable snapshots after appended transforms", () =>
|
|
566
|
+
Effect.gen(function* () {
|
|
567
|
+
const service = yield* Tool.Service
|
|
568
|
+
yield* service.transform((editor) => {
|
|
569
|
+
editor.namespace({ name: "acme", description: "Archival operations" })
|
|
570
|
+
editor.add({ ...make(), options: { namespace: "acme" } })
|
|
571
|
+
})
|
|
572
|
+
const advertised = yield* service.snapshot()
|
|
573
|
+
|
|
574
|
+
yield* service.transform((editor) => {
|
|
575
|
+
editor.namespace({ name: "acme", description: "Billing operations" })
|
|
576
|
+
})
|
|
577
|
+
const current = yield* service.snapshot()
|
|
578
|
+
expect(advertised.codeModeCatalog?.tools).toMatchObject([{ name: "acme", description: "Archival operations" }])
|
|
579
|
+
expect(current.codeModeCatalog?.tools).toMatchObject([{ name: "acme", description: "Billing operations" }])
|
|
580
|
+
|
|
581
|
+
const search = (snapshot: Tool.Snapshot, query: string) =>
|
|
582
|
+
snapshot.execute({
|
|
583
|
+
...call("execute"),
|
|
584
|
+
call: {
|
|
585
|
+
type: "tool-call",
|
|
586
|
+
id: `namespace-${query}`,
|
|
587
|
+
name: "execute",
|
|
588
|
+
input: {
|
|
589
|
+
code: `return search({ query: ${JSON.stringify(query)} }).items.map(item => item.path).join(",")`,
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
})
|
|
593
|
+
expect((yield* search(advertised, "archival")).output).toMatchObject({ output: "tools.acme.echo" })
|
|
594
|
+
expect((yield* search(advertised, "billing")).output).toMatchObject({ output: "" })
|
|
595
|
+
expect((yield* search(current, "archival")).output).toMatchObject({ output: "" })
|
|
596
|
+
expect((yield* search(current, "billing")).output).toMatchObject({ output: "tools.acme.echo" })
|
|
597
|
+
}),
|
|
598
|
+
)
|
|
599
|
+
|
|
600
|
+
it.effect("preserves a top-level tool that also has child tools", () =>
|
|
601
|
+
Effect.gen(function* () {
|
|
602
|
+
const service = yield* Tool.Service
|
|
603
|
+
yield* service.transform((editor) => {
|
|
604
|
+
editor.namespace({ name: "pricing", description: "Pricing operations" })
|
|
605
|
+
editor.add({ ...make(), name: "pricing" })
|
|
606
|
+
editor.add({ ...make(), name: "sales", options: { namespace: "pricing" } })
|
|
607
|
+
})
|
|
608
|
+
|
|
609
|
+
const snapshot = yield* service.snapshot()
|
|
610
|
+
expect(codeModeListings(snapshot.codeModeCatalog!).map((tool) => tool.path)).toEqual(["pricing", "pricing.sales"])
|
|
611
|
+
const result = yield* snapshot.execute({
|
|
612
|
+
...call("execute"),
|
|
613
|
+
call: {
|
|
614
|
+
type: "tool-call",
|
|
615
|
+
id: "top-level-callable",
|
|
616
|
+
name: "execute",
|
|
617
|
+
input: {
|
|
618
|
+
code: `return await Promise.all([
|
|
619
|
+
tools.pricing({ text: "pricing" }),
|
|
620
|
+
tools.pricing.sales({ text: "sales" }),
|
|
621
|
+
])`,
|
|
622
|
+
},
|
|
623
|
+
},
|
|
624
|
+
})
|
|
625
|
+
expect(result.output).toMatchObject({ output: expect.stringContaining('"text":"sales"') })
|
|
626
|
+
}),
|
|
627
|
+
)
|
|
628
|
+
|
|
629
|
+
it.effect("runs a call to a Code Mode tool's path or registry ID as a Code Mode call", () =>
|
|
630
|
+
Effect.gen(function* () {
|
|
631
|
+
const service = yield* Tool.Service
|
|
632
|
+
yield* transform(service, { echo: make(), "kebab-echo": make() }, { namespace: "acme.tools" })
|
|
633
|
+
yield* transform(service, {
|
|
634
|
+
fails: { ...make(), execute: () => Effect.fail(new Tool.Error({ message: "boom" })) },
|
|
635
|
+
})
|
|
636
|
+
const snapshot = yield* service.snapshot()
|
|
637
|
+
for (const name of ["acme.tools.echo", "acme_tools_echo", "acme.tools.kebab-echo"]) {
|
|
638
|
+
const result = yield* snapshot.execute(call(name))
|
|
639
|
+
expect(result.output).toEqual({ text: name })
|
|
640
|
+
}
|
|
641
|
+
expect((yield* snapshot.execute(call("fails")).pipe(Effect.flip)).message).toContain("boom")
|
|
642
|
+
// In a session drain it can move to the background, like an execute program, without execute's options.
|
|
643
|
+
const handoffs: Array<CodeModeJob.Options | undefined> = []
|
|
644
|
+
const handed = yield* snapshot
|
|
645
|
+
.execute(call("acme.tools.echo"))
|
|
646
|
+
.pipe(
|
|
647
|
+
Effect.provideService(CodeModeJob.Current, (context, run, options) =>
|
|
648
|
+
Effect.sync(() => handoffs.push(options)).pipe(Effect.andThen(run(context))),
|
|
649
|
+
),
|
|
650
|
+
)
|
|
651
|
+
expect(handed.output).toEqual({ text: "acme.tools.echo" })
|
|
652
|
+
expect(handoffs).toEqual([undefined])
|
|
653
|
+
// Not without execute, and not for a tool this request doesn't offer.
|
|
654
|
+
const withoutExecute = new Map(
|
|
655
|
+
snapshot.definitions.flatMap((definition) =>
|
|
656
|
+
definition.name === "execute" ? [] : [[definition.name, definition] as const],
|
|
657
|
+
),
|
|
658
|
+
)
|
|
659
|
+
expect(
|
|
660
|
+
(yield* snapshot.execute({ ...call("acme.tools.echo"), definitions: withoutExecute }).pipe(Effect.flip))
|
|
661
|
+
.message,
|
|
662
|
+
).toContain('No tool named "acme.tools.echo"')
|
|
663
|
+
const denied = yield* service.snapshot(
|
|
664
|
+
Permission.Policy.fromRules([{ action: "acme_tools_echo", resource: "*", effect: "deny" }]),
|
|
665
|
+
)
|
|
666
|
+
expect((yield* denied.execute(call("acme.tools.echo")).pipe(Effect.flip)).message).toContain(
|
|
667
|
+
'No tool named "acme.tools.echo"',
|
|
668
|
+
)
|
|
669
|
+
}),
|
|
670
|
+
)
|
|
671
|
+
|
|
672
|
+
it.effect("logs invalid tool definitions without dropping healthy tools", () => {
|
|
673
|
+
const output: unknown[] = []
|
|
674
|
+
const logger = Logger.map(Logger.formatStructured, (entry) => {
|
|
675
|
+
output.push(entry.message)
|
|
676
|
+
})
|
|
677
|
+
return Effect.gen(function* () {
|
|
678
|
+
const service = yield* Tool.Service
|
|
679
|
+
yield* service.transform((editor) => {
|
|
680
|
+
editor.add({ ...make(), name: "healthy", options: { codemode: false } })
|
|
681
|
+
editor.add({
|
|
682
|
+
name: "phone_type",
|
|
683
|
+
input: Schema.Struct({}),
|
|
684
|
+
execute: () => Effect.succeed({ content: "ok" }),
|
|
685
|
+
options: { codemode: false },
|
|
686
|
+
} as unknown as Info)
|
|
687
|
+
editor.add({ ...make(), name: "boolean_input", input: true, options: { codemode: false } } as unknown as Info)
|
|
688
|
+
editor.add({ ...make(), name: "codemode" })
|
|
689
|
+
})
|
|
690
|
+
|
|
691
|
+
expect(output).toEqual([
|
|
692
|
+
[
|
|
693
|
+
"Skipping invalid tool registration",
|
|
694
|
+
{
|
|
695
|
+
name: "phone_type",
|
|
696
|
+
namespace: undefined,
|
|
697
|
+
error: expect.stringContaining('Expected string\n at ["description"]'),
|
|
698
|
+
},
|
|
699
|
+
],
|
|
700
|
+
[
|
|
701
|
+
"Skipping invalid tool registration",
|
|
702
|
+
{
|
|
703
|
+
name: "boolean_input",
|
|
704
|
+
namespace: undefined,
|
|
705
|
+
error: "Invalid tool definition boolean_input: input must be a schema",
|
|
706
|
+
},
|
|
707
|
+
],
|
|
708
|
+
])
|
|
709
|
+
const snapshot = yield* service.snapshot()
|
|
710
|
+
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["healthy", "execute"])
|
|
711
|
+
expect(codeModeListings(snapshot.codeModeCatalog!).map((tool) => tool.path)).toEqual(["codemode"])
|
|
712
|
+
expect((yield* snapshot.execute(call("phone_type")).pipe(Effect.flip)).message).toBe(
|
|
713
|
+
'No tool named "phone_type" is currently available. Please use a tool from the available tool list.',
|
|
714
|
+
)
|
|
715
|
+
}).pipe(Effect.provide(Logger.layer([logger])))
|
|
716
|
+
})
|
|
717
|
+
|
|
718
|
+
it.effect("skipped registrations leave existing tools and scoped cleanup intact", () =>
|
|
719
|
+
Effect.gen(function* () {
|
|
720
|
+
const service = yield* Tool.Service
|
|
721
|
+
yield* transform(service, { echo: constant("original") }, { codemode: false })
|
|
722
|
+
yield* Effect.scoped(
|
|
723
|
+
Effect.gen(function* () {
|
|
724
|
+
yield* service.transform((editor) => {
|
|
725
|
+
editor.add({ ...constant("invalid"), name: "echo", description: undefined } as unknown as Info)
|
|
726
|
+
editor.add({ ...make(), name: "temporary", options: { codemode: false } })
|
|
727
|
+
})
|
|
728
|
+
const snapshot = yield* service.snapshot()
|
|
729
|
+
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["echo", "temporary", "execute"])
|
|
730
|
+
expect((yield* snapshot.execute(call("echo"))).output).toEqual({ text: "original" })
|
|
731
|
+
}),
|
|
732
|
+
)
|
|
733
|
+
expect((yield* service.snapshot()).definitions.map((tool) => tool.name)).toEqual(["echo", "execute"])
|
|
734
|
+
}),
|
|
735
|
+
)
|
|
736
|
+
|
|
737
|
+
it.effect("canonicalizes effective definitions and keeps Code Mode last", () =>
|
|
738
|
+
Effect.gen(function* () {
|
|
739
|
+
const service = yield* Tool.Service
|
|
740
|
+
const tool = make()
|
|
741
|
+
const capture = (tools: ReadonlyArray<Info>) =>
|
|
742
|
+
Effect.scoped(
|
|
743
|
+
Effect.gen(function* () {
|
|
744
|
+
yield* service.transform((editor) => tools.forEach(editor.add))
|
|
745
|
+
return (yield* service.snapshot()).definitions
|
|
746
|
+
}),
|
|
747
|
+
)
|
|
748
|
+
const first = yield* capture([
|
|
749
|
+
{ ...tool, name: "zeta", options: { codemode: false } },
|
|
750
|
+
{ ...tool, name: "alpha", options: { codemode: false } },
|
|
751
|
+
{ ...tool, name: "beta", options: { namespace: "alpha", codemode: false } },
|
|
752
|
+
{ ...tool, name: "echo" },
|
|
753
|
+
])
|
|
754
|
+
const second = yield* capture([
|
|
755
|
+
{ ...tool, name: "echo" },
|
|
756
|
+
{ ...tool, name: "beta", options: { namespace: "alpha", codemode: false } },
|
|
757
|
+
{ ...tool, name: "alpha", options: { codemode: false } },
|
|
758
|
+
{ ...tool, name: "zeta", options: { codemode: false } },
|
|
759
|
+
])
|
|
760
|
+
|
|
761
|
+
expect(first).toEqual(second)
|
|
762
|
+
expect(first.map((definition) => definition.name)).toEqual(["alpha", "alpha_beta", "zeta", "execute"])
|
|
763
|
+
}),
|
|
764
|
+
)
|
|
765
|
+
|
|
766
|
+
it.effect("snapshots external tools with missing input schemas", () =>
|
|
767
|
+
Effect.gen(function* () {
|
|
768
|
+
const service = yield* Tool.Service
|
|
769
|
+
yield* service.transform((editor) =>
|
|
770
|
+
editor.add({
|
|
771
|
+
...make(),
|
|
772
|
+
input: undefined,
|
|
773
|
+
} as unknown as Info),
|
|
774
|
+
)
|
|
775
|
+
yield* service.transform((editor) =>
|
|
776
|
+
editor.add({ ...make(), name: "direct", input: null, options: { codemode: false } } as unknown as Info),
|
|
777
|
+
)
|
|
778
|
+
|
|
779
|
+
const snapshot = yield* service.snapshot()
|
|
780
|
+
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["direct", "execute"])
|
|
781
|
+
expect(codeModeListings(snapshot.codeModeCatalog!)[0]?.line).toContain("tools.echo")
|
|
782
|
+
expect((yield* snapshot.execute(call("direct"))).output).toEqual({ text: "direct" })
|
|
783
|
+
}),
|
|
784
|
+
)
|
|
785
|
+
|
|
786
|
+
it.effect("keeps execute available without Code Mode tools unless explicitly denied", () =>
|
|
787
|
+
Effect.gen(function* () {
|
|
788
|
+
const service = yield* Tool.Service
|
|
789
|
+
|
|
790
|
+
const available = yield* service.snapshot()
|
|
791
|
+
expect(available.definitions.map((tool) => tool.name)).toEqual(["execute"])
|
|
792
|
+
expect(available.codeModeCatalog?.tools).toEqual([])
|
|
793
|
+
|
|
794
|
+
const denied = yield* service.snapshot(
|
|
795
|
+
Permission.Policy.fromRules([{ action: "execute", resource: "*", effect: "deny" }]),
|
|
796
|
+
)
|
|
797
|
+
expect(denied.definitions).toEqual([])
|
|
798
|
+
expect(denied.codeModeCatalog).toBeUndefined()
|
|
799
|
+
}),
|
|
800
|
+
)
|
|
801
|
+
|
|
802
|
+
it.effect(
|
|
803
|
+
"places tools with options.codemode overrides in Code Mode by default, honors direct policy demotion, and resolves pinned",
|
|
804
|
+
() =>
|
|
805
|
+
Effect.gen(function* () {
|
|
806
|
+
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false
|
|
807
|
+
|
|
808
|
+
const service = yield* Tool.Service
|
|
809
|
+
const hooks = yield* PluginHooks.Service
|
|
810
|
+
const hooked: Array<{ phase: string; tool: string; codemode: boolean; override: boolean }> = []
|
|
811
|
+
yield* hooks.register("tool", "execute.before", (event) =>
|
|
812
|
+
Effect.sync(() => {
|
|
813
|
+
hooked.push({
|
|
814
|
+
phase: "before",
|
|
815
|
+
tool: event.tool,
|
|
816
|
+
codemode: event.codemode,
|
|
817
|
+
override: typeof event.info?.options?.codemode === "object",
|
|
818
|
+
})
|
|
819
|
+
}),
|
|
820
|
+
)
|
|
821
|
+
yield* hooks.register("tool", "execute.after", (event) =>
|
|
822
|
+
Effect.sync(() => {
|
|
823
|
+
hooked.push({
|
|
824
|
+
phase: "after",
|
|
825
|
+
tool: event.tool,
|
|
826
|
+
codemode: event.codemode,
|
|
827
|
+
override: typeof event.info?.options?.codemode === "object",
|
|
828
|
+
})
|
|
829
|
+
}),
|
|
830
|
+
)
|
|
831
|
+
const directInput = Schema.Struct({ command: Schema.String, background: Schema.optionalKey(Schema.Boolean) })
|
|
832
|
+
const codemodeInput = Schema.Struct({ command: Schema.String })
|
|
833
|
+
const codemodeOutput = Schema.Struct({ summary: Schema.String })
|
|
834
|
+
yield* service.transform((editor) => {
|
|
835
|
+
editor.add({
|
|
836
|
+
name: "shell",
|
|
837
|
+
description: "Direct shell",
|
|
838
|
+
input: directInput,
|
|
839
|
+
output: Schema.String,
|
|
840
|
+
options: {
|
|
841
|
+
codemode: {
|
|
842
|
+
pinned: true,
|
|
843
|
+
description: "Code Mode shell",
|
|
844
|
+
input: codemodeInput,
|
|
845
|
+
output: codemodeOutput,
|
|
846
|
+
},
|
|
847
|
+
},
|
|
848
|
+
execute: (input, context) => {
|
|
849
|
+
const _inputExact: Equal<
|
|
850
|
+
typeof input,
|
|
851
|
+
{ readonly command: string; readonly background?: boolean } | { readonly command: string }
|
|
852
|
+
> = true
|
|
853
|
+
const background = "background" in input ? input.background : undefined
|
|
854
|
+
const _backgroundOptional: Equal<typeof background, boolean | undefined> = true
|
|
855
|
+
void _inputExact
|
|
856
|
+
void _backgroundOptional
|
|
857
|
+
const summary = `${input.command}:${"background" in input ? String(input.background) : "omitted"}:${String(Boolean(context.codemode))}`
|
|
858
|
+
return Effect.succeed({ output: context.codemode ? { summary } : summary })
|
|
859
|
+
},
|
|
860
|
+
})
|
|
861
|
+
editor.add({
|
|
862
|
+
name: "glob",
|
|
863
|
+
description: "Find files",
|
|
864
|
+
input: Schema.Struct({ pattern: Schema.String }),
|
|
865
|
+
output: Schema.String,
|
|
866
|
+
options: { codemode: false },
|
|
867
|
+
execute: (input) => {
|
|
868
|
+
const _unchanged: Equal<typeof input, { readonly pattern: string }> = true
|
|
869
|
+
void _unchanged
|
|
870
|
+
return Effect.succeed({ output: input.pattern })
|
|
871
|
+
},
|
|
872
|
+
})
|
|
873
|
+
editor.add({ ...make(), name: "mcp_search" })
|
|
874
|
+
editor.add({ ...make(), name: "legacy_pin", options: { pinned: true } })
|
|
875
|
+
editor.add({ ...make(), name: "unpinned_override", options: { codemode: { pinned: false }, pinned: true } })
|
|
876
|
+
})
|
|
877
|
+
|
|
878
|
+
const listed = (yield* service.list()).find((tool) => tool.id === "shell")
|
|
879
|
+
expect(listed?.description).toBe("Direct shell")
|
|
880
|
+
expect(typeof listed?.options?.codemode).toBe("object")
|
|
881
|
+
|
|
882
|
+
// An override object places the tool in Code Mode by default; codemode: false stays direct.
|
|
883
|
+
const defaultSnap = yield* service.snapshot()
|
|
884
|
+
expect(defaultSnap.definitions.map((tool) => tool.name)).toEqual(["glob", "execute"])
|
|
885
|
+
const listings = codeModeListings(defaultSnap.codeModeCatalog!)
|
|
886
|
+
expect(listings.map((tool) => tool.path)).toEqual(["legacy_pin", "mcp_search", "shell", "unpinned_override"])
|
|
887
|
+
const shellListing = listings.find((tool) => tool.path === "shell")!
|
|
888
|
+
expect(shellListing.line).toContain("Code Mode shell")
|
|
889
|
+
expect(shellListing.line).not.toContain("background")
|
|
890
|
+
expect(defaultSnap.codeModeCatalog?.tools.find((tool) => tool.name === "shell")).toMatchObject({ pinned: true })
|
|
891
|
+
expect(defaultSnap.codeModeCatalog?.tools.find((tool) => tool.name === "legacy_pin")).toMatchObject({
|
|
892
|
+
pinned: true,
|
|
893
|
+
})
|
|
894
|
+
expect(defaultSnap.codeModeCatalog?.tools.find((tool) => tool.name === "unpinned_override")).toMatchObject({
|
|
895
|
+
pinned: false,
|
|
896
|
+
})
|
|
897
|
+
|
|
898
|
+
// Decodes and encodes Code Mode calls with the Code Mode override schemas and passes context.codemode = true.
|
|
899
|
+
const executed = yield* defaultSnap.execute({
|
|
900
|
+
...call("execute"),
|
|
901
|
+
call: {
|
|
902
|
+
type: "tool-call",
|
|
903
|
+
id: "call-cm-shell",
|
|
904
|
+
name: "execute",
|
|
905
|
+
input: { code: 'return await tools.shell({ command: "ls", background: true })' },
|
|
906
|
+
},
|
|
907
|
+
})
|
|
908
|
+
expect(executed.output).toMatchObject({ output: JSON.stringify({ summary: "ls:omitted:true" }) })
|
|
909
|
+
expect(
|
|
910
|
+
yield* service.check({
|
|
911
|
+
code: 'return await tools.shell({ command: "build", background: true })',
|
|
912
|
+
tools: ["shell"],
|
|
913
|
+
bindings: {},
|
|
914
|
+
policy: Permission.Policy.empty,
|
|
915
|
+
limits: {},
|
|
916
|
+
context: { sessionID, ...identity, progress: () => Effect.void },
|
|
917
|
+
}),
|
|
918
|
+
).toMatchObject({ ok: true, value: { summary: "build:omitted:true" } })
|
|
919
|
+
expect(
|
|
920
|
+
yield* service.check({
|
|
921
|
+
code: 'return await tools.glob({ pattern: "*" })',
|
|
922
|
+
tools: ["glob"],
|
|
923
|
+
bindings: {},
|
|
924
|
+
policy: Permission.Policy.empty,
|
|
925
|
+
limits: {},
|
|
926
|
+
context: { sessionID, ...identity, progress: () => Effect.void },
|
|
927
|
+
}),
|
|
928
|
+
).toMatchObject({ ok: false, error: { kind: "UnknownTool" } })
|
|
929
|
+
|
|
930
|
+
// Policy `direct` keeps a Code Mode tool on the direct list with its direct description and schemas.
|
|
931
|
+
const demotePolicy = { hidden: new Set(["glob"]), direct: new Set(["shell"]) }
|
|
932
|
+
const demoted = yield* service.snapshot(undefined, { tools: demotePolicy })
|
|
933
|
+
expect(demoted.definitions.map((tool) => tool.name)).toEqual(["shell", "execute"])
|
|
934
|
+
expect(demoted.definitions.find((tool) => tool.name === "shell")?.description).toBe("Direct shell")
|
|
935
|
+
expect(demoted.definitions.find((tool) => tool.name === "shell")?.inputSchema.properties).toHaveProperty(
|
|
936
|
+
"background",
|
|
937
|
+
)
|
|
938
|
+
expect(
|
|
939
|
+
(yield* demoted.execute({
|
|
940
|
+
...call("shell"),
|
|
941
|
+
call: {
|
|
942
|
+
type: "tool-call",
|
|
943
|
+
id: "call-direct-shell",
|
|
944
|
+
name: "shell",
|
|
945
|
+
input: { command: "ls", background: true },
|
|
946
|
+
},
|
|
947
|
+
})).output,
|
|
948
|
+
).toBe("ls:true:false")
|
|
949
|
+
|
|
950
|
+
// When execute is denied, Code Mode tools fall back to their direct form while hidden tools stay hidden.
|
|
951
|
+
const denied = yield* service.snapshot(
|
|
952
|
+
Permission.Policy.fromRules([{ action: "execute", resource: "*", effect: "deny" }]),
|
|
953
|
+
{
|
|
954
|
+
tools: { hidden: new Set(["glob"]) },
|
|
955
|
+
},
|
|
956
|
+
)
|
|
957
|
+
expect(denied.codeModeCatalog).toBeUndefined()
|
|
958
|
+
expect(denied.definitions.map((tool) => tool.name)).toEqual([
|
|
959
|
+
"legacy_pin",
|
|
960
|
+
"mcp_search",
|
|
961
|
+
"shell",
|
|
962
|
+
"unpinned_override",
|
|
963
|
+
])
|
|
964
|
+
expect(denied.definitions.find((tool) => tool.name === "shell")?.description).toBe("Direct shell")
|
|
965
|
+
expect(denied.definitions.find((tool) => tool.name === "shell")?.inputSchema.properties).toHaveProperty(
|
|
966
|
+
"background",
|
|
967
|
+
)
|
|
968
|
+
|
|
969
|
+
// Plugin edits to tool.description only change the direct form; options.codemode stays intact.
|
|
970
|
+
yield* service.transform((editor) => {
|
|
971
|
+
expect(editor.get("shell")?.description).toBe("Direct shell")
|
|
972
|
+
editor.update("shell", (tool) => {
|
|
973
|
+
tool.description = "Edited direct shell"
|
|
974
|
+
})
|
|
975
|
+
})
|
|
976
|
+
expect(
|
|
977
|
+
(yield* service.snapshot(undefined, { tools: demotePolicy })).definitions.find(
|
|
978
|
+
(tool) => tool.name === "shell",
|
|
979
|
+
)?.description,
|
|
980
|
+
).toBe("Edited direct shell")
|
|
981
|
+
expect(
|
|
982
|
+
codeModeListings((yield* service.snapshot()).codeModeCatalog!).find((tool) => tool.path === "shell")?.line,
|
|
983
|
+
).toContain("Code Mode shell")
|
|
984
|
+
|
|
985
|
+
expect(hooked).toEqual([
|
|
986
|
+
{ phase: "before", tool: "execute", codemode: false, override: false },
|
|
987
|
+
{ phase: "before", tool: "shell", codemode: true, override: true },
|
|
988
|
+
{ phase: "after", tool: "shell", codemode: true, override: true },
|
|
989
|
+
{ phase: "after", tool: "execute", codemode: false, override: false },
|
|
990
|
+
{ phase: "before", tool: "shell", codemode: true, override: true },
|
|
991
|
+
{ phase: "after", tool: "shell", codemode: true, override: true },
|
|
992
|
+
{ phase: "before", tool: "shell", codemode: false, override: true },
|
|
993
|
+
{ phase: "after", tool: "shell", codemode: false, override: true },
|
|
994
|
+
])
|
|
995
|
+
}),
|
|
996
|
+
)
|
|
997
|
+
|
|
998
|
+
it.effect("caches the 5 most recently used Code Mode catalogs and invalidates on registry changes", () =>
|
|
999
|
+
Effect.gen(function* () {
|
|
1000
|
+
const service = yield* Tool.Service
|
|
1001
|
+
yield* transform(service, {
|
|
1002
|
+
t1: make(),
|
|
1003
|
+
t2: make(),
|
|
1004
|
+
t3: make(),
|
|
1005
|
+
t4: make(),
|
|
1006
|
+
t5: make(),
|
|
1007
|
+
t6: make(),
|
|
1008
|
+
})
|
|
1009
|
+
const deny = (action: string) => Permission.Policy.fromRules([{ action, resource: "*", effect: "deny" }])
|
|
1010
|
+
|
|
1011
|
+
const s1 = yield* service.snapshot(deny("t1"))
|
|
1012
|
+
const s2 = yield* service.snapshot(deny("t2"))
|
|
1013
|
+
const s3 = yield* service.snapshot(deny("t3"))
|
|
1014
|
+
const s4 = yield* service.snapshot(deny("t4"))
|
|
1015
|
+
const s5 = yield* service.snapshot(deny("t5"))
|
|
1016
|
+
|
|
1017
|
+
// Touch s1 so s2 becomes least recently used, then insert a 6th distinct tool set.
|
|
1018
|
+
expect((yield* service.snapshot(deny("t1"))).codeModeCatalog).toBe(s1.codeModeCatalog)
|
|
1019
|
+
const s6 = yield* service.snapshot(deny("t6"))
|
|
1020
|
+
|
|
1021
|
+
expect((yield* service.snapshot(deny("t1"))).codeModeCatalog).toBe(s1.codeModeCatalog)
|
|
1022
|
+
expect((yield* service.snapshot(deny("t3"))).codeModeCatalog).toBe(s3.codeModeCatalog)
|
|
1023
|
+
expect((yield* service.snapshot(deny("t4"))).codeModeCatalog).toBe(s4.codeModeCatalog)
|
|
1024
|
+
expect((yield* service.snapshot(deny("t5"))).codeModeCatalog).toBe(s5.codeModeCatalog)
|
|
1025
|
+
expect((yield* service.snapshot(deny("t6"))).codeModeCatalog).toBe(s6.codeModeCatalog)
|
|
1026
|
+
expect((yield* service.snapshot(deny("t2"))).codeModeCatalog).not.toBe(s2.codeModeCatalog)
|
|
1027
|
+
|
|
1028
|
+
// Invalidates inside State.batch before notify runs, as well as on reload.
|
|
1029
|
+
const beforeBatch = yield* service.snapshot(deny("t1"))
|
|
1030
|
+
yield* State.batch(
|
|
1031
|
+
Effect.gen(function* () {
|
|
1032
|
+
yield* transform(service, { extra: make() })
|
|
1033
|
+
expect((yield* service.snapshot(deny("t1"))).codeModeCatalog).not.toBe(beforeBatch.codeModeCatalog)
|
|
1034
|
+
}),
|
|
1035
|
+
)
|
|
1036
|
+
const afterBatch = yield* service.snapshot(deny("t1"))
|
|
1037
|
+
yield* service.reload()
|
|
1038
|
+
expect((yield* service.snapshot(deny("t1"))).codeModeCatalog).not.toBe(afterBatch.codeModeCatalog)
|
|
1039
|
+
}),
|
|
1040
|
+
)
|
|
1041
|
+
|
|
1042
|
+
it.effect("exposes Code Mode tools directly when execute is denied", () =>
|
|
1043
|
+
Effect.gen(function* () {
|
|
1044
|
+
const service = yield* Tool.Service
|
|
1045
|
+
yield* transform(service, { lookup: make() }, { namespace: "mcp" })
|
|
1046
|
+
yield* transform(service, { bash: make() }, { codemode: false })
|
|
1047
|
+
const denyExecute = Permission.Policy.fromRules([{ action: "execute", resource: "*", effect: "deny" }])
|
|
1048
|
+
|
|
1049
|
+
const snapshot = yield* service.snapshot(denyExecute)
|
|
1050
|
+
expect(snapshot.definitions.map((tool) => tool.name)).toEqual(["bash", "mcp_lookup"])
|
|
1051
|
+
expect(snapshot.codeModeCatalog).toBeUndefined()
|
|
1052
|
+
expect((yield* snapshot.execute(call("mcp_lookup"))).output).toEqual({ text: "mcp_lookup" })
|
|
1053
|
+
|
|
1054
|
+
const hidden = yield* service.snapshot(
|
|
1055
|
+
Permission.Policy.override(denyExecute, [{ action: "mcp_lookup", resource: "*", effect: "deny" }]),
|
|
1056
|
+
)
|
|
1057
|
+
expect(hidden.definitions.map((tool) => tool.name)).toEqual(["bash"])
|
|
1058
|
+
expect(yield* hidden.execute(call("mcp_lookup")).pipe(Effect.flip)).toBeInstanceOf(Tool.Error)
|
|
1059
|
+
}),
|
|
1060
|
+
)
|
|
1061
|
+
|
|
1062
|
+
it.effect("denies a nested-namespace tool by its flattened name in Code Mode and as a direct tool", () =>
|
|
1063
|
+
Effect.gen(function* () {
|
|
1064
|
+
const service = yield* Tool.Service
|
|
1065
|
+
yield* transform(service, { move: make(), rename: make() }, { namespace: "opencode.session" })
|
|
1066
|
+
const deny = Permission.Policy.fromRules([{ action: "opencode_session_move", resource: "*", effect: "deny" }])
|
|
1067
|
+
|
|
1068
|
+
const codeMode = yield* service.snapshot(deny)
|
|
1069
|
+
const paths = codeModeListings(codeMode.codeModeCatalog!).map((entry) => entry.path)
|
|
1070
|
+
expect(paths).toContain("opencode.session.rename")
|
|
1071
|
+
expect(paths).not.toContain("opencode.session.move")
|
|
1072
|
+
|
|
1073
|
+
const direct = yield* service.snapshot(
|
|
1074
|
+
Permission.Policy.override(deny, [{ action: "execute", resource: "*", effect: "deny" }]),
|
|
1075
|
+
)
|
|
1076
|
+
expect(direct.definitions.map((tool) => tool.name)).toEqual(["opencode_session_rename"])
|
|
1077
|
+
}),
|
|
1078
|
+
)
|
|
1079
|
+
|
|
1080
|
+
it.effect("filters disabled tools with edit aliases and ordered wildcard precedence", () =>
|
|
1081
|
+
Effect.gen(function* () {
|
|
1082
|
+
const service = yield* Tool.Service
|
|
1083
|
+
yield* transform(service, { question: make(), bash: make() }, { codemode: false })
|
|
1084
|
+
yield* transform(service, { edit: make(), write: make() }, { codemode: false, permission: "edit" })
|
|
1085
|
+
const names = (permissions: Permission.Ruleset) =>
|
|
1086
|
+
toolDefinitions(service, permissions).pipe(Effect.map((definitions) => definitions.map((tool) => tool.name)))
|
|
1087
|
+
|
|
1088
|
+
expect(yield* names([{ action: "question", resource: "*", effect: "deny" }])).toEqual([
|
|
1089
|
+
"bash",
|
|
1090
|
+
"edit",
|
|
1091
|
+
"write",
|
|
1092
|
+
"execute",
|
|
1093
|
+
])
|
|
1094
|
+
expect(
|
|
1095
|
+
yield* names([
|
|
1096
|
+
{ action: "*", resource: "*", effect: "deny" },
|
|
1097
|
+
{ action: "question", resource: "private", effect: "allow" },
|
|
1098
|
+
]),
|
|
1099
|
+
).toEqual(["question"])
|
|
1100
|
+
expect(
|
|
1101
|
+
yield* names([
|
|
1102
|
+
{ action: "question", resource: "private", effect: "allow" },
|
|
1103
|
+
{ action: "*", resource: "*", effect: "deny" },
|
|
1104
|
+
]),
|
|
1105
|
+
).toEqual([])
|
|
1106
|
+
expect(
|
|
1107
|
+
yield* names([
|
|
1108
|
+
{ action: "question", resource: "*", effect: "deny" },
|
|
1109
|
+
{ action: "question", resource: "private", effect: "deny" },
|
|
1110
|
+
]),
|
|
1111
|
+
).toEqual(["bash", "edit", "write", "execute"])
|
|
1112
|
+
expect(yield* names([{ action: "edit", resource: "*", effect: "deny" }])).toEqual(["bash", "question", "execute"])
|
|
1113
|
+
}),
|
|
1114
|
+
)
|
|
1115
|
+
|
|
1116
|
+
it.effect("keeps permission options isolated between registrations", () =>
|
|
1117
|
+
Effect.gen(function* () {
|
|
1118
|
+
const service = yield* Tool.Service
|
|
1119
|
+
const shared = make()
|
|
1120
|
+
yield* transform(service, { first: shared }, { codemode: false })
|
|
1121
|
+
yield* transform(service, { second: shared }, { codemode: false, permission: "edit" })
|
|
1122
|
+
|
|
1123
|
+
expect(
|
|
1124
|
+
(yield* toolDefinitions(service, [{ action: "edit", resource: "*", effect: "deny" }])).map((tool) => tool.name),
|
|
1125
|
+
).toEqual(["first", "execute"])
|
|
1126
|
+
}),
|
|
1127
|
+
)
|
|
1128
|
+
|
|
1129
|
+
it.effect("preserves an interrupted registration until its scope closes", () =>
|
|
1130
|
+
Effect.gen(function* () {
|
|
1131
|
+
const service = yield* Tool.Service
|
|
1132
|
+
const scope = yield* Scope.make()
|
|
1133
|
+
const registered = yield* Deferred.make<void>()
|
|
1134
|
+
const fiber = yield* transform(service, { echo: make() }, { codemode: false }).pipe(
|
|
1135
|
+
Effect.andThen(Deferred.succeed(registered, undefined)),
|
|
1136
|
+
Effect.andThen(Effect.never),
|
|
1137
|
+
Scope.provide(scope),
|
|
1138
|
+
Effect.forkChild,
|
|
1139
|
+
)
|
|
1140
|
+
yield* Deferred.await(registered)
|
|
1141
|
+
yield* Fiber.interrupt(fiber)
|
|
1142
|
+
|
|
1143
|
+
expect((yield* toolDefinitions(service)).map((tool) => tool.name)).toEqual(["echo", "execute"])
|
|
1144
|
+
yield* Scope.close(scope, Exit.void)
|
|
1145
|
+
expect((yield* toolDefinitions(service)).map((tool) => tool.name)).toEqual(["execute"])
|
|
1146
|
+
}),
|
|
1147
|
+
)
|
|
1148
|
+
|
|
1149
|
+
it.effect("returns model errors without swallowing interruption or defects", () =>
|
|
1150
|
+
Effect.gen(function* () {
|
|
1151
|
+
const service = yield* Tool.Service
|
|
1152
|
+
yield* transform(
|
|
1153
|
+
service,
|
|
1154
|
+
{
|
|
1155
|
+
failed: {
|
|
1156
|
+
name: "failed",
|
|
1157
|
+
description: "Failed",
|
|
1158
|
+
input: Schema.Struct({}),
|
|
1159
|
+
output: Schema.Struct({ ok: Schema.Boolean }),
|
|
1160
|
+
execute: () => Effect.fail(new Tool.Error({ message: "Denied" })),
|
|
1161
|
+
},
|
|
1162
|
+
},
|
|
1163
|
+
{ codemode: false },
|
|
1164
|
+
)
|
|
1165
|
+
expect(
|
|
1166
|
+
yield* executeTool(service, {
|
|
1167
|
+
sessionID,
|
|
1168
|
+
...identity,
|
|
1169
|
+
call: { type: "tool-call", id: "failed", name: "failed", input: {} },
|
|
1170
|
+
}),
|
|
1171
|
+
).toEqual({ status: "error", error: { type: "tool.execution", message: "Denied" } })
|
|
1172
|
+
expect(
|
|
1173
|
+
yield* executeTool(service, {
|
|
1174
|
+
sessionID,
|
|
1175
|
+
...identity,
|
|
1176
|
+
call: { type: "tool-call", id: "missing", name: "missing", input: {} },
|
|
1177
|
+
}),
|
|
1178
|
+
).toEqual({
|
|
1179
|
+
status: "error",
|
|
1180
|
+
error: {
|
|
1181
|
+
type: "tool.execution",
|
|
1182
|
+
message: 'No tool named "missing" is currently available. Please use a tool from the available tool list.',
|
|
1183
|
+
},
|
|
1184
|
+
})
|
|
1185
|
+
|
|
1186
|
+
yield* transform(
|
|
1187
|
+
service,
|
|
1188
|
+
{
|
|
1189
|
+
defect: {
|
|
1190
|
+
name: "defect",
|
|
1191
|
+
description: "Defect",
|
|
1192
|
+
input: Schema.Struct({}),
|
|
1193
|
+
output: Schema.Struct({}),
|
|
1194
|
+
execute: () => Effect.die("unexpected executor defect"),
|
|
1195
|
+
},
|
|
1196
|
+
},
|
|
1197
|
+
{ codemode: false },
|
|
1198
|
+
)
|
|
1199
|
+
expect(
|
|
1200
|
+
yield* service.snapshot().pipe(
|
|
1201
|
+
Effect.flatMap((toolSet) =>
|
|
1202
|
+
toolSet.execute({
|
|
1203
|
+
sessionID,
|
|
1204
|
+
...identity,
|
|
1205
|
+
call: { type: "tool-call", id: "defect", name: "defect", input: {} },
|
|
1206
|
+
}),
|
|
1207
|
+
),
|
|
1208
|
+
Effect.catchDefect(Effect.succeed),
|
|
1209
|
+
),
|
|
1210
|
+
).toBe("unexpected executor defect")
|
|
1211
|
+
}),
|
|
1212
|
+
)
|
|
1213
|
+
|
|
1214
|
+
it.effect("passes complete call identity to tool execution", () =>
|
|
1215
|
+
Effect.gen(function* () {
|
|
1216
|
+
const service = yield* Tool.Service
|
|
1217
|
+
const contexts: Tool.Context[] = []
|
|
1218
|
+
yield* transform(
|
|
1219
|
+
service,
|
|
1220
|
+
{
|
|
1221
|
+
context: {
|
|
1222
|
+
name: "context",
|
|
1223
|
+
description: "Context",
|
|
1224
|
+
input: Schema.Struct({}),
|
|
1225
|
+
output: Schema.Struct({ ok: Schema.Boolean }),
|
|
1226
|
+
execute: (_, context) =>
|
|
1227
|
+
Effect.sync(() => contexts.push(context)).pipe(Effect.as({ output: { ok: true } })),
|
|
1228
|
+
},
|
|
1229
|
+
},
|
|
1230
|
+
{ codemode: false },
|
|
1231
|
+
)
|
|
1232
|
+
yield* executeTool(service, {
|
|
1233
|
+
sessionID,
|
|
1234
|
+
...identity,
|
|
1235
|
+
call: { type: "tool-call", id: "call-context", name: "context", input: {} },
|
|
1236
|
+
})
|
|
1237
|
+
expect(contexts).toEqual([
|
|
1238
|
+
{ sessionID, ...identity, id: Tool.CallID.make("call-context"), progress: expect.any(Function) },
|
|
1239
|
+
])
|
|
1240
|
+
}),
|
|
1241
|
+
)
|
|
1242
|
+
it.effect("lists registered tools by effective name", () =>
|
|
1243
|
+
Effect.gen(function* () {
|
|
1244
|
+
const service = yield* Tool.Service
|
|
1245
|
+
yield* transform(service, { echo: make() }, { codemode: false })
|
|
1246
|
+
yield* transform(service, { count: { ...constant("1"), name: "count" } }, { namespace: "acme" })
|
|
1247
|
+
|
|
1248
|
+
expect((yield* service.list()).map((tool) => [tool.id, tool.name])).toEqual([
|
|
1249
|
+
["echo", "echo"],
|
|
1250
|
+
["acme_count", "count"],
|
|
1251
|
+
])
|
|
1252
|
+
|
|
1253
|
+
yield* service.transform((editor) => editor.remove("echo"))
|
|
1254
|
+
expect((yield* service.list()).map((tool) => tool.id)).toEqual(["acme_count"])
|
|
1255
|
+
}),
|
|
1256
|
+
)
|
|
1257
|
+
;[
|
|
1258
|
+
{ name: "string", content: "hooked", text: "hooked" },
|
|
1259
|
+
{ name: "empty string", content: "", text: "" },
|
|
1260
|
+
{ name: "missing content", content: undefined, text: '{"text":"hooked"}' },
|
|
1261
|
+
{ name: "empty content array", content: [], text: '{"text":"hooked"}' },
|
|
1262
|
+
].forEach((input) => {
|
|
1263
|
+
it.effect(`normalizes ${input.name} after the final tool hook`, () =>
|
|
1264
|
+
Effect.gen(function* () {
|
|
1265
|
+
const service = yield* Tool.Service
|
|
1266
|
+
const hooks = yield* PluginHooks.Service
|
|
1267
|
+
yield* transform(service, { echo: make() }, { codemode: false })
|
|
1268
|
+
yield* hooks.register("tool", "execute.after", (event) =>
|
|
1269
|
+
Effect.sync(() => {
|
|
1270
|
+
if (event.status !== "completed") return
|
|
1271
|
+
event.result = {
|
|
1272
|
+
output: { text: "hooked" },
|
|
1273
|
+
content: input.content,
|
|
1274
|
+
metadata: { source: "hook" },
|
|
1275
|
+
}
|
|
1276
|
+
}),
|
|
1277
|
+
)
|
|
1278
|
+
const snapshot = yield* service.snapshot()
|
|
1279
|
+
expect(yield* snapshot.execute(call("echo"))).toEqual({
|
|
1280
|
+
output: { text: "hooked" },
|
|
1281
|
+
content: [{ type: "text", text: input.text }],
|
|
1282
|
+
metadata: { source: "hook" },
|
|
1283
|
+
})
|
|
1284
|
+
}),
|
|
1285
|
+
)
|
|
1286
|
+
})
|
|
1287
|
+
|
|
1288
|
+
it.effect("a hook can rename a call inside a Code Mode program to another of its tools", () =>
|
|
1289
|
+
Effect.gen(function* () {
|
|
1290
|
+
const service = yield* Tool.Service
|
|
1291
|
+
const hooks = yield* PluginHooks.Service
|
|
1292
|
+
yield* transform(service, { echo: make(), constant: constant("renamed") })
|
|
1293
|
+
yield* transform(service, { direct: constant("direct") }, { codemode: false })
|
|
1294
|
+
const seen: string[] = []
|
|
1295
|
+
yield* hooks.register("tool", "execute.before", (event) =>
|
|
1296
|
+
Effect.sync(() => {
|
|
1297
|
+
if (event.tool !== "echo") return
|
|
1298
|
+
event.tool = Schema.is(Schema.Struct({ text: Schema.String }))(event.input) ? event.input.text : event.tool
|
|
1299
|
+
}),
|
|
1300
|
+
)
|
|
1301
|
+
yield* hooks.register("tool", "execute.after", (event) => Effect.sync(() => void seen.push(event.tool)))
|
|
1302
|
+
const snapshot = yield* service.snapshot()
|
|
1303
|
+
const program = (code: string) =>
|
|
1304
|
+
snapshot.execute({
|
|
1305
|
+
sessionID,
|
|
1306
|
+
...identity,
|
|
1307
|
+
call: { type: "tool-call", id: "call-program", name: "execute", input: { code } },
|
|
1308
|
+
})
|
|
1309
|
+
|
|
1310
|
+
expect((yield* program('return await tools.echo({ text: "constant" })')).output).toMatchObject({
|
|
1311
|
+
output: JSON.stringify({ text: "renamed" }),
|
|
1312
|
+
})
|
|
1313
|
+
expect(seen).toContain("constant")
|
|
1314
|
+
// A program can only reach its own tools, however the call is renamed.
|
|
1315
|
+
for (const name of ["direct", "missing"])
|
|
1316
|
+
expect(
|
|
1317
|
+
(yield* program(`try { await tools.echo({ text: "${name}" }) } catch (e) { return e.message }`)).output,
|
|
1318
|
+
).toMatchObject({ output: `Tool is not available for this request: ${name}` })
|
|
1319
|
+
|
|
1320
|
+
const check = (tools: string[]) =>
|
|
1321
|
+
service.check({
|
|
1322
|
+
code: 'return await tools.echo({ text: "constant" })',
|
|
1323
|
+
tools,
|
|
1324
|
+
bindings: {},
|
|
1325
|
+
policy: Permission.Policy.empty,
|
|
1326
|
+
limits: {},
|
|
1327
|
+
context: { sessionID, ...identity, progress: () => Effect.void },
|
|
1328
|
+
})
|
|
1329
|
+
expect(yield* check(["echo"])).toMatchObject({ ok: false })
|
|
1330
|
+
expect(yield* check(["echo", "constant"])).toMatchObject({ ok: true, value: { text: "renamed" } })
|
|
1331
|
+
}),
|
|
1332
|
+
)
|
|
1333
|
+
|
|
1334
|
+
it.effect("a call renamed inside a Code Mode program returns the renamed tool's structured output", () =>
|
|
1335
|
+
Effect.gen(function* () {
|
|
1336
|
+
const service = yield* Tool.Service
|
|
1337
|
+
const hooks = yield* PluginHooks.Service
|
|
1338
|
+
const plain: Info = {
|
|
1339
|
+
name: "plain",
|
|
1340
|
+
description: "Return text",
|
|
1341
|
+
input: Schema.Struct({ text: Schema.String }),
|
|
1342
|
+
execute: () => Effect.succeed({ content: "plain" }),
|
|
1343
|
+
}
|
|
1344
|
+
yield* transform(service, { plain, constant: constant("structured") })
|
|
1345
|
+
yield* hooks.register("tool", "execute.before", (event) =>
|
|
1346
|
+
Effect.sync(() => {
|
|
1347
|
+
if (event.tool === "plain") event.tool = "constant"
|
|
1348
|
+
}),
|
|
1349
|
+
)
|
|
1350
|
+
const snapshot = yield* service.snapshot()
|
|
1351
|
+
const result = yield* snapshot.execute({
|
|
1352
|
+
sessionID,
|
|
1353
|
+
...identity,
|
|
1354
|
+
call: {
|
|
1355
|
+
type: "tool-call",
|
|
1356
|
+
id: "call-program",
|
|
1357
|
+
name: "execute",
|
|
1358
|
+
input: { code: 'return await tools.plain({ text: "x" })' },
|
|
1359
|
+
},
|
|
1360
|
+
})
|
|
1361
|
+
expect(result.output).toMatchObject({ output: JSON.stringify({ text: "structured" }) })
|
|
1362
|
+
}),
|
|
1363
|
+
)
|
|
1364
|
+
|
|
1365
|
+
it.effect("hooks see one ID per call inside a Code Mode program", () =>
|
|
1366
|
+
Effect.gen(function* () {
|
|
1367
|
+
const service = yield* Tool.Service
|
|
1368
|
+
const hooks = yield* PluginHooks.Service
|
|
1369
|
+
yield* transform(service, { echo: make() })
|
|
1370
|
+
const before: string[] = []
|
|
1371
|
+
const after: string[] = []
|
|
1372
|
+
yield* hooks.register("tool", "execute.before", (event) =>
|
|
1373
|
+
Effect.sync(() => void (event.tool === "echo" && before.push(event.id))),
|
|
1374
|
+
)
|
|
1375
|
+
yield* hooks.register("tool", "execute.after", (event) =>
|
|
1376
|
+
Effect.sync(() => void (event.tool === "echo" && after.push(event.id))),
|
|
1377
|
+
)
|
|
1378
|
+
const snapshot = yield* service.snapshot()
|
|
1379
|
+
yield* snapshot.execute({
|
|
1380
|
+
sessionID,
|
|
1381
|
+
...identity,
|
|
1382
|
+
call: {
|
|
1383
|
+
type: "tool-call",
|
|
1384
|
+
id: "call-program",
|
|
1385
|
+
name: "execute",
|
|
1386
|
+
input: { code: 'await Promise.all([tools.echo({ text: "a" }), tools.echo({ text: "b" })])' },
|
|
1387
|
+
},
|
|
1388
|
+
})
|
|
1389
|
+
expect(new Set(before).size).toBe(2)
|
|
1390
|
+
expect(before).not.toContain("call-program")
|
|
1391
|
+
expect(after.toSorted()).toEqual(before.toSorted())
|
|
1392
|
+
}),
|
|
1393
|
+
)
|
|
1394
|
+
|
|
1395
|
+
it.effect("normalizes image tool output once and drops unresizable images", () =>
|
|
1396
|
+
Effect.gen(function* () {
|
|
1397
|
+
const service = yield* Tool.Service
|
|
1398
|
+
yield* transform(
|
|
1399
|
+
service,
|
|
1400
|
+
{
|
|
1401
|
+
snapshot: {
|
|
1402
|
+
name: "snapshot",
|
|
1403
|
+
description: "Return images",
|
|
1404
|
+
input: Schema.Struct({ text: Schema.String }),
|
|
1405
|
+
output: Schema.Struct({ text: Schema.String }),
|
|
1406
|
+
execute: ({ text }) =>
|
|
1407
|
+
Effect.succeed({
|
|
1408
|
+
output: { text },
|
|
1409
|
+
content: [
|
|
1410
|
+
{ type: "file", uri: "data:image/png;base64,aW1hZ2U=", mime: "image/png", name: "frame.png" },
|
|
1411
|
+
{
|
|
1412
|
+
type: "file",
|
|
1413
|
+
uri: "data:image/png;base64,aW1hZ2U=",
|
|
1414
|
+
mime: "image/png",
|
|
1415
|
+
name: "too-large.png",
|
|
1416
|
+
},
|
|
1417
|
+
{ type: "file", uri: "data:image/png;base64,aW1hZ2U=", mime: "image/png", name: "corrupt.png" },
|
|
1418
|
+
{ type: "text", text },
|
|
1419
|
+
],
|
|
1420
|
+
}),
|
|
1421
|
+
},
|
|
1422
|
+
},
|
|
1423
|
+
{ codemode: false },
|
|
1424
|
+
)
|
|
1425
|
+
|
|
1426
|
+
const execution = yield* executeTool(service, call("snapshot"))
|
|
1427
|
+
expect(execution.content).toEqual([
|
|
1428
|
+
{
|
|
1429
|
+
type: "file",
|
|
1430
|
+
uri: "data:image/jpeg;base64,aW1hZ2Ugbm9ybWFsaXplZA==",
|
|
1431
|
+
mime: "image/jpeg",
|
|
1432
|
+
name: "frame.png",
|
|
1433
|
+
},
|
|
1434
|
+
{ type: "text", text: "snapshot" },
|
|
1435
|
+
{ type: "text", text: "[1 image omitted: could not be decoded.]" },
|
|
1436
|
+
{ type: "text", text: "[1 image omitted: could not be resized below the image size limit.]" },
|
|
1437
|
+
])
|
|
1438
|
+
}),
|
|
1439
|
+
)
|
|
1440
|
+
|
|
1441
|
+
it.effect("publishes progress metadata unchanged", () =>
|
|
1442
|
+
Effect.gen(function* () {
|
|
1443
|
+
const service = yield* Tool.Service
|
|
1444
|
+
yield* transform(
|
|
1445
|
+
service,
|
|
1446
|
+
{
|
|
1447
|
+
progressive: {
|
|
1448
|
+
name: "progressive",
|
|
1449
|
+
description: "Emit image progress",
|
|
1450
|
+
input: Schema.Struct({ text: Schema.String }),
|
|
1451
|
+
output: Schema.Struct({ text: Schema.String }),
|
|
1452
|
+
execute: ({ text }, context) =>
|
|
1453
|
+
context.progress({ stage: "capture" }).pipe(Effect.as({ output: { text } })),
|
|
1454
|
+
},
|
|
1455
|
+
},
|
|
1456
|
+
{ codemode: false },
|
|
1457
|
+
)
|
|
1458
|
+
|
|
1459
|
+
const updates: Tool.Metadata[] = []
|
|
1460
|
+
yield* executeTool(service, {
|
|
1461
|
+
...call("progressive"),
|
|
1462
|
+
progress: (update) =>
|
|
1463
|
+
Effect.sync(() => {
|
|
1464
|
+
updates.push(update)
|
|
1465
|
+
}),
|
|
1466
|
+
})
|
|
1467
|
+
expect(updates).toEqual([{ stage: "capture" }])
|
|
1468
|
+
}),
|
|
1469
|
+
)
|
|
1470
|
+
|
|
1471
|
+
it.effect("enforces transformed codecs at execution and projection boundaries", () =>
|
|
1472
|
+
Effect.gen(function* () {
|
|
1473
|
+
const service = yield* Tool.Service
|
|
1474
|
+
const executed: string[] = []
|
|
1475
|
+
const Transformed = Schema.Boolean.pipe(
|
|
1476
|
+
Schema.decodeTo(Schema.String, {
|
|
1477
|
+
decode: SchemaGetter.transform((value) => (value ? "yes" : "no")),
|
|
1478
|
+
encode: SchemaGetter.transform((value) => value === "yes"),
|
|
1479
|
+
}),
|
|
1480
|
+
)
|
|
1481
|
+
yield* transform(
|
|
1482
|
+
service,
|
|
1483
|
+
{
|
|
1484
|
+
transformed: {
|
|
1485
|
+
name: "transformed",
|
|
1486
|
+
description: "Transform values",
|
|
1487
|
+
input: Schema.Struct({ value: Transformed }),
|
|
1488
|
+
output: Schema.Struct({ value: Transformed }),
|
|
1489
|
+
execute: ({ value }) =>
|
|
1490
|
+
Effect.sync(() => executed.push(value)).pipe(Effect.as({ output: { value }, content: String(value) })),
|
|
1491
|
+
},
|
|
1492
|
+
},
|
|
1493
|
+
{ codemode: false },
|
|
1494
|
+
)
|
|
1495
|
+
|
|
1496
|
+
// Canonical content observes the decoded domain value; Code Mode observes the encoded value.
|
|
1497
|
+
expect(
|
|
1498
|
+
yield* executeTool(service, {
|
|
1499
|
+
sessionID,
|
|
1500
|
+
...identity,
|
|
1501
|
+
call: { type: "tool-call", id: "transformed", name: "transformed", input: { value: true } },
|
|
1502
|
+
}),
|
|
1503
|
+
).toEqual({
|
|
1504
|
+
status: "completed",
|
|
1505
|
+
output: { value: true },
|
|
1506
|
+
content: [{ type: "text", text: "yes" }],
|
|
1507
|
+
})
|
|
1508
|
+
expect(executed).toEqual(["yes"])
|
|
1509
|
+
expect(
|
|
1510
|
+
yield* executeTool(service, {
|
|
1511
|
+
sessionID,
|
|
1512
|
+
...identity,
|
|
1513
|
+
call: { type: "tool-call", id: "invalid-input", name: "transformed", input: { value: "yes" } },
|
|
1514
|
+
}),
|
|
1515
|
+
).toMatchObject({
|
|
1516
|
+
status: "error",
|
|
1517
|
+
error: {
|
|
1518
|
+
type: "tool.execution",
|
|
1519
|
+
message:
|
|
1520
|
+
'Invalid arguments for tool "transformed":\n- value: Expected boolean\n\nArguments provided:\n{\n "value": "yes"\n}\n\nUpdate the arguments and call the tool again.',
|
|
1521
|
+
},
|
|
1522
|
+
})
|
|
1523
|
+
expect(executed).toEqual(["yes"])
|
|
1524
|
+
|
|
1525
|
+
yield* transform(
|
|
1526
|
+
service,
|
|
1527
|
+
{
|
|
1528
|
+
invalid_output: {
|
|
1529
|
+
name: "invalid_output",
|
|
1530
|
+
description: "Return invalid output",
|
|
1531
|
+
input: Schema.Struct({}),
|
|
1532
|
+
output: Schema.Struct({
|
|
1533
|
+
value: Schema.Boolean.pipe(
|
|
1534
|
+
Schema.decodeTo(Schema.String, {
|
|
1535
|
+
decode: SchemaGetter.transform((value) => String(value)),
|
|
1536
|
+
encode: SchemaGetter.transformEffect((value) =>
|
|
1537
|
+
value === "valid"
|
|
1538
|
+
? Effect.succeed(true)
|
|
1539
|
+
: Effect.fail(new SchemaIssue.InvalidValue({ message: "invalid output" }, value)),
|
|
1540
|
+
),
|
|
1541
|
+
}),
|
|
1542
|
+
),
|
|
1543
|
+
}),
|
|
1544
|
+
execute: () => Effect.succeed({ output: { value: "invalid" } }),
|
|
1545
|
+
},
|
|
1546
|
+
},
|
|
1547
|
+
{ codemode: false },
|
|
1548
|
+
)
|
|
1549
|
+
expect(
|
|
1550
|
+
yield* executeTool(service, {
|
|
1551
|
+
sessionID,
|
|
1552
|
+
...identity,
|
|
1553
|
+
call: { type: "tool-call", id: "invalid-output", name: "invalid_output", input: {} },
|
|
1554
|
+
}),
|
|
1555
|
+
).toMatchObject({
|
|
1556
|
+
status: "error",
|
|
1557
|
+
error: { type: "tool.execution", message: expect.stringContaining("invalid value for its output schema") },
|
|
1558
|
+
})
|
|
1559
|
+
}),
|
|
1560
|
+
)
|
|
1561
|
+
|
|
1562
|
+
it.effect("registers, advertises, and executes a Zod tool", () =>
|
|
1563
|
+
Effect.gen(function* () {
|
|
1564
|
+
const service = yield* Tool.Service
|
|
1565
|
+
yield* transform(
|
|
1566
|
+
service,
|
|
1567
|
+
{
|
|
1568
|
+
zod: {
|
|
1569
|
+
name: "zod",
|
|
1570
|
+
description: "Increment a parsed number",
|
|
1571
|
+
input: z.object({ count: z.string().transform(Number) }),
|
|
1572
|
+
output: z.object({ count: z.number() }),
|
|
1573
|
+
execute: ({ count }) => Effect.succeed({ output: { count: count + 1 } }),
|
|
1574
|
+
},
|
|
1575
|
+
},
|
|
1576
|
+
{ codemode: false },
|
|
1577
|
+
)
|
|
1578
|
+
|
|
1579
|
+
const snapshot = yield* service.snapshot()
|
|
1580
|
+
expect(snapshot.definitions.find((tool) => tool.name === "zod")?.inputSchema).toMatchObject({
|
|
1581
|
+
type: "object",
|
|
1582
|
+
properties: { count: { type: "string" } },
|
|
1583
|
+
required: ["count"],
|
|
1584
|
+
})
|
|
1585
|
+
expect(
|
|
1586
|
+
yield* snapshot.execute({
|
|
1587
|
+
sessionID,
|
|
1588
|
+
...identity,
|
|
1589
|
+
call: { type: "tool-call", id: "call-zod", name: "zod", input: { count: "41" } },
|
|
1590
|
+
}),
|
|
1591
|
+
).toMatchObject({ output: { count: 42 } })
|
|
1592
|
+
}),
|
|
1593
|
+
)
|
|
1594
|
+
|
|
1595
|
+
it.effect("executes the tool advertised in a model request", () =>
|
|
1596
|
+
Effect.gen(function* () {
|
|
1597
|
+
const service = yield* Tool.Service
|
|
1598
|
+
const scope = yield* Scope.make()
|
|
1599
|
+
yield* transform(service, { echo: constant("advertised") }, { codemode: false }).pipe(Scope.provide(scope))
|
|
1600
|
+
const request = yield* service.snapshot()
|
|
1601
|
+
yield* Scope.close(scope, Exit.void)
|
|
1602
|
+
yield* transform(service, { echo: constant("replacement") }, { codemode: false })
|
|
1603
|
+
|
|
1604
|
+
expect((yield* request.execute(call("echo"))).content).toEqual([{ type: "text", text: "advertised" }])
|
|
1605
|
+
expect((yield* executeTool(service, call("echo"))).content).toEqual([{ type: "text", text: "replacement" }])
|
|
1606
|
+
}),
|
|
1607
|
+
)
|
|
1608
|
+
|
|
1609
|
+
it.effect("executes and reports progress for codemode tools advertised in a model request", () =>
|
|
1610
|
+
Effect.gen(function* () {
|
|
1611
|
+
const service = yield* Tool.Service
|
|
1612
|
+
const executed: string[] = []
|
|
1613
|
+
const scope = yield* Scope.make()
|
|
1614
|
+
yield* transform(service, {
|
|
1615
|
+
echo: {
|
|
1616
|
+
name: "echo",
|
|
1617
|
+
description: "Echo text",
|
|
1618
|
+
input: Schema.Struct({ text: Schema.String }),
|
|
1619
|
+
output: Schema.Struct({ text: Schema.String }),
|
|
1620
|
+
execute: ({ text }, context) =>
|
|
1621
|
+
Effect.sync(() => executed.push(`old:${text}`)).pipe(
|
|
1622
|
+
Effect.andThen(context.progress({ stage: "old" })),
|
|
1623
|
+
Effect.as({ output: { text } }),
|
|
1624
|
+
),
|
|
1625
|
+
},
|
|
1626
|
+
}).pipe(Scope.provide(scope))
|
|
1627
|
+
const toolSet = yield* service.snapshot()
|
|
1628
|
+
const execute = toolSet.definitions.find((tool) => tool.name === "execute")
|
|
1629
|
+
expect(codeModeListings(toolSet.codeModeCatalog!)[0]?.line).toContain("tools.echo")
|
|
1630
|
+
expect(execute?.description).toContain("confined Code Mode runtime")
|
|
1631
|
+
expect(execute?.description).not.toContain("Echo text")
|
|
1632
|
+
yield* Scope.close(scope, Exit.void)
|
|
1633
|
+
yield* transform(service, {
|
|
1634
|
+
echo: {
|
|
1635
|
+
name: "echo",
|
|
1636
|
+
description: "Echo text",
|
|
1637
|
+
input: Schema.Struct({ text: Schema.String }),
|
|
1638
|
+
output: Schema.Struct({ text: Schema.String }),
|
|
1639
|
+
execute: ({ text }) => Effect.sync(() => executed.push(`new:${text}`)).pipe(Effect.as({ output: { text } })),
|
|
1640
|
+
},
|
|
1641
|
+
})
|
|
1642
|
+
|
|
1643
|
+
const progress: Tool.Metadata[] = []
|
|
1644
|
+
const execution = yield* toolSet.execute({
|
|
1645
|
+
...call("execute"),
|
|
1646
|
+
call: {
|
|
1647
|
+
type: "tool-call",
|
|
1648
|
+
id: "call-execute",
|
|
1649
|
+
name: "execute",
|
|
1650
|
+
input: { code: 'return await tools.echo({ text: "request" })' },
|
|
1651
|
+
},
|
|
1652
|
+
progress: (update) => Effect.sync(() => progress.push(update)),
|
|
1653
|
+
})
|
|
1654
|
+
|
|
1655
|
+
expect(execution).toMatchObject({ content: [{ type: "text" }] })
|
|
1656
|
+
expect(execution.metadata?.toolCalls).toEqual([{ tool: "echo", status: "completed", input: { text: "request" } }])
|
|
1657
|
+
expect(executed).toEqual(["old:request"])
|
|
1658
|
+
// The inner tool's own progress would replace the call rows, so it is not published.
|
|
1659
|
+
expect(progress).toEqual([{ toolCalls: [{ tool: "echo", status: "running", input: { text: "request" } }] }])
|
|
1660
|
+
}),
|
|
1661
|
+
)
|
|
1662
|
+
})
|