opencode-v2 1.1.53
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 +27 -0
- package/Dockerfile +18 -0
- package/README.md +15 -0
- package/bin/opencode +84 -0
- package/bunfig.toml +5 -0
- package/package.json +126 -0
- package/parsers-config.ts +253 -0
- package/script/build.ts +193 -0
- package/script/postinstall.mjs +125 -0
- package/script/publish.ts +181 -0
- package/script/schema.ts +47 -0
- package/script/seed-e2e.ts +50 -0
- package/src/acp/README.md +164 -0
- package/src/acp/agent.ts +1676 -0
- package/src/acp/session.ts +117 -0
- package/src/acp/types.ts +23 -0
- package/src/agent/agent.ts +414 -0
- package/src/agent/generate.txt +75 -0
- package/src/agent/prompt/compaction.txt +12 -0
- package/src/agent/prompt/explore.txt +18 -0
- package/src/agent/prompt/summary.txt +11 -0
- package/src/agent/prompt/title.txt +44 -0
- package/src/auth/index.ts +70 -0
- package/src/bun/index.ts +137 -0
- package/src/bun/registry.ts +48 -0
- package/src/bus/bus-event.ts +43 -0
- package/src/bus/global.ts +10 -0
- package/src/bus/index.ts +105 -0
- package/src/cli/bootstrap.ts +17 -0
- package/src/cli/cmd/acp.ts +70 -0
- package/src/cli/cmd/agent.ts +257 -0
- package/src/cli/cmd/auth.ts +400 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/debug/agent.ts +167 -0
- package/src/cli/cmd/debug/config.ts +16 -0
- package/src/cli/cmd/debug/file.ts +97 -0
- package/src/cli/cmd/debug/index.ts +48 -0
- package/src/cli/cmd/debug/lsp.ts +52 -0
- package/src/cli/cmd/debug/ripgrep.ts +87 -0
- package/src/cli/cmd/debug/scrap.ts +16 -0
- package/src/cli/cmd/debug/skill.ts +16 -0
- package/src/cli/cmd/debug/snapshot.ts +52 -0
- package/src/cli/cmd/export.ts +88 -0
- package/src/cli/cmd/generate.ts +38 -0
- package/src/cli/cmd/github.ts +1540 -0
- package/src/cli/cmd/import.ts +147 -0
- package/src/cli/cmd/mcp.ts +755 -0
- package/src/cli/cmd/models.ts +77 -0
- package/src/cli/cmd/pr.ts +112 -0
- package/src/cli/cmd/run.ts +617 -0
- package/src/cli/cmd/serve.ts +20 -0
- package/src/cli/cmd/session.ts +135 -0
- package/src/cli/cmd/stats.ts +426 -0
- package/src/cli/cmd/tui/app.tsx +801 -0
- package/src/cli/cmd/tui/attach.ts +52 -0
- package/src/cli/cmd/tui/component/border.tsx +21 -0
- package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-command.tsx +148 -0
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-model.tsx +234 -0
- package/src/cli/cmd/tui/component/dialog-provider.tsx +266 -0
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +108 -0
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-skill.tsx +36 -0
- package/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
- package/src/cli/cmd/tui/component/dialog-status.tsx +177 -0
- package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
- package/src/cli/cmd/tui/component/logo.tsx +85 -0
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +666 -0
- package/src/cli/cmd/tui/component/prompt/frecency.tsx +89 -0
- package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
- package/src/cli/cmd/tui/component/prompt/index.tsx +1132 -0
- package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
- package/src/cli/cmd/tui/component/spinner.tsx +24 -0
- package/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
- package/src/cli/cmd/tui/component/tips.tsx +153 -0
- package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
- package/src/cli/cmd/tui/context/args.tsx +15 -0
- package/src/cli/cmd/tui/context/directory.ts +13 -0
- package/src/cli/cmd/tui/context/exit.tsx +52 -0
- package/src/cli/cmd/tui/context/helper.tsx +25 -0
- package/src/cli/cmd/tui/context/keybind.tsx +100 -0
- package/src/cli/cmd/tui/context/kv.tsx +52 -0
- package/src/cli/cmd/tui/context/local.tsx +409 -0
- package/src/cli/cmd/tui/context/prompt.tsx +18 -0
- package/src/cli/cmd/tui/context/route.tsx +46 -0
- package/src/cli/cmd/tui/context/sdk.tsx +101 -0
- package/src/cli/cmd/tui/context/sync.tsx +470 -0
- package/src/cli/cmd/tui/context/theme/aura.json +69 -0
- package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
- package/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
- package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
- package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
- package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
- package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
- package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
- package/src/cli/cmd/tui/context/theme/github.json +233 -0
- package/src/cli/cmd/tui/context/theme/gruvbox.json +242 -0
- package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
- package/src/cli/cmd/tui/context/theme/material.json +235 -0
- package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
- package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
- package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
- package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
- package/src/cli/cmd/tui/context/theme/nord.json +223 -0
- package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
- package/src/cli/cmd/tui/context/theme/orng.json +249 -0
- package/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
- package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
- package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
- package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
- package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
- package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
- package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
- package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
- package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
- package/src/cli/cmd/tui/context/theme.tsx +1152 -0
- package/src/cli/cmd/tui/event.ts +48 -0
- package/src/cli/cmd/tui/routes/home.tsx +140 -0
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
- package/src/cli/cmd/tui/routes/session/footer.tsx +91 -0
- package/src/cli/cmd/tui/routes/session/header.tsx +142 -0
- package/src/cli/cmd/tui/routes/session/index.tsx +2126 -0
- package/src/cli/cmd/tui/routes/session/permission.tsx +508 -0
- package/src/cli/cmd/tui/routes/session/question.tsx +466 -0
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +313 -0
- package/src/cli/cmd/tui/thread.ts +175 -0
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +68 -0
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +93 -0
- package/src/cli/cmd/tui/ui/dialog-export-options.tsx +215 -0
- package/src/cli/cmd/tui/ui/dialog-help.tsx +49 -0
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +88 -0
- package/src/cli/cmd/tui/ui/dialog-select.tsx +399 -0
- package/src/cli/cmd/tui/ui/dialog.tsx +167 -0
- package/src/cli/cmd/tui/ui/link.tsx +28 -0
- package/src/cli/cmd/tui/ui/spinner.ts +368 -0
- package/src/cli/cmd/tui/ui/toast.tsx +100 -0
- package/src/cli/cmd/tui/util/clipboard.ts +159 -0
- package/src/cli/cmd/tui/util/editor.ts +32 -0
- package/src/cli/cmd/tui/util/signal.ts +7 -0
- package/src/cli/cmd/tui/util/terminal.ts +114 -0
- package/src/cli/cmd/tui/util/transcript.ts +98 -0
- package/src/cli/cmd/tui/worker.ts +152 -0
- package/src/cli/cmd/uninstall.ts +357 -0
- package/src/cli/cmd/upgrade.ts +73 -0
- package/src/cli/cmd/web.ts +81 -0
- package/src/cli/error.ts +57 -0
- package/src/cli/logo.ts +6 -0
- package/src/cli/network.ts +60 -0
- package/src/cli/ui.ts +113 -0
- package/src/cli/upgrade.ts +25 -0
- package/src/command/index.ts +150 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/command/template/review.txt +99 -0
- package/src/config/config.ts +1477 -0
- package/src/config/markdown.ts +98 -0
- package/src/env/index.ts +28 -0
- package/src/file/ignore.ts +83 -0
- package/src/file/index.ts +583 -0
- package/src/file/ripgrep.ts +375 -0
- package/src/file/time.ts +69 -0
- package/src/file/watcher.ts +127 -0
- package/src/flag/flag.ts +97 -0
- package/src/format/formatter.ts +366 -0
- package/src/format/index.ts +137 -0
- package/src/global/index.ts +55 -0
- package/src/id/id.ts +83 -0
- package/src/ide/index.ts +76 -0
- package/src/index.ts +159 -0
- package/src/installation/index.ts +246 -0
- package/src/lsp/client.ts +252 -0
- package/src/lsp/index.ts +485 -0
- package/src/lsp/language.ts +119 -0
- package/src/lsp/server.ts +2046 -0
- package/src/mcp/auth.ts +132 -0
- package/src/mcp/index.ts +934 -0
- package/src/mcp/oauth-callback.ts +200 -0
- package/src/mcp/oauth-provider.ts +154 -0
- package/src/patch/index.ts +680 -0
- package/src/permission/arity.ts +163 -0
- package/src/permission/index.ts +210 -0
- package/src/permission/next.ts +280 -0
- package/src/plugin/codex.ts +624 -0
- package/src/plugin/copilot.ts +327 -0
- package/src/plugin/index.ts +138 -0
- package/src/project/bootstrap.ts +35 -0
- package/src/project/instance.ts +114 -0
- package/src/project/project.ts +371 -0
- package/src/project/state.ts +70 -0
- package/src/project/vcs.ts +76 -0
- package/src/provider/auth.ts +147 -0
- package/src/provider/models.ts +133 -0
- package/src/provider/provider.ts +1262 -0
- package/src/provider/sdk/copilot/README.md +5 -0
- package/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +164 -0
- package/src/provider/sdk/copilot/chat/get-response-metadata.ts +15 -0
- package/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +17 -0
- package/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +64 -0
- package/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +780 -0
- package/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +28 -0
- package/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +44 -0
- package/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +87 -0
- package/src/provider/sdk/copilot/copilot-provider.ts +100 -0
- package/src/provider/sdk/copilot/index.ts +2 -0
- package/src/provider/sdk/copilot/openai-compatible-error.ts +27 -0
- package/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +303 -0
- package/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +22 -0
- package/src/provider/sdk/copilot/responses/openai-config.ts +18 -0
- package/src/provider/sdk/copilot/responses/openai-error.ts +22 -0
- package/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +207 -0
- package/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +1732 -0
- package/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +177 -0
- package/src/provider/sdk/copilot/responses/openai-responses-settings.ts +1 -0
- package/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +88 -0
- package/src/provider/sdk/copilot/responses/tool/file-search.ts +128 -0
- package/src/provider/sdk/copilot/responses/tool/image-generation.ts +115 -0
- package/src/provider/sdk/copilot/responses/tool/local-shell.ts +65 -0
- package/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +104 -0
- package/src/provider/sdk/copilot/responses/tool/web-search.ts +103 -0
- package/src/provider/transform.ts +828 -0
- package/src/pty/index.ts +250 -0
- package/src/question/index.ts +171 -0
- package/src/scheduler/index.ts +61 -0
- package/src/server/error.ts +36 -0
- package/src/server/event.ts +7 -0
- package/src/server/mdns.ts +60 -0
- package/src/server/routes/config.ts +92 -0
- package/src/server/routes/experimental.ts +208 -0
- package/src/server/routes/file.ts +197 -0
- package/src/server/routes/global.ts +183 -0
- package/src/server/routes/mcp.ts +225 -0
- package/src/server/routes/permission.ts +68 -0
- package/src/server/routes/project.ts +82 -0
- package/src/server/routes/provider.ts +165 -0
- package/src/server/routes/pty.ts +169 -0
- package/src/server/routes/question.ts +98 -0
- package/src/server/routes/session.ts +939 -0
- package/src/server/routes/tui.ts +379 -0
- package/src/server/server.ts +613 -0
- package/src/session/compaction.ts +226 -0
- package/src/session/index.ts +524 -0
- package/src/session/instruction.ts +197 -0
- package/src/session/llm.ts +289 -0
- package/src/session/message-v2.ts +802 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +407 -0
- package/src/session/prompt/agent.txt +43 -0
- package/src/session/prompt/anthropic-20250930.txt +166 -0
- package/src/session/prompt/anthropic.txt +105 -0
- package/src/session/prompt/beast.txt +147 -0
- package/src/session/prompt/build-switch.txt +5 -0
- package/src/session/prompt/codex_header.txt +79 -0
- package/src/session/prompt/copilot-gpt-5.txt +143 -0
- package/src/session/prompt/gemini.txt +155 -0
- package/src/session/prompt/max-steps.txt +16 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
- package/src/session/prompt/plan.txt +26 -0
- package/src/session/prompt/qwen.txt +109 -0
- package/src/session/prompt/research.txt +81 -0
- package/src/session/prompt/trinity.txt +97 -0
- package/src/session/prompt.ts +1952 -0
- package/src/session/retry.ts +97 -0
- package/src/session/revert.ts +121 -0
- package/src/session/status.ts +76 -0
- package/src/session/summary.ts +217 -0
- package/src/session/system.ts +54 -0
- package/src/session/todo.ts +37 -0
- package/src/share/share-next.ts +200 -0
- package/src/share/share.ts +92 -0
- package/src/shell/shell.ts +67 -0
- package/src/skill/discovery.ts +97 -0
- package/src/skill/index.ts +1 -0
- package/src/skill/skill.ts +188 -0
- package/src/snapshot/index.ts +255 -0
- package/src/storage/storage.ts +227 -0
- package/src/tool/agent-enter.txt +1 -0
- package/src/tool/agent-exit.txt +1 -0
- package/src/tool/agent.ts +237 -0
- package/src/tool/apply_patch.ts +281 -0
- package/src/tool/apply_patch.txt +33 -0
- package/src/tool/bash.ts +269 -0
- package/src/tool/bash.txt +115 -0
- package/src/tool/batch.ts +175 -0
- package/src/tool/batch.txt +24 -0
- package/src/tool/chat-enter.txt +15 -0
- package/src/tool/chat-exit.txt +7 -0
- package/src/tool/chat.ts +217 -0
- package/src/tool/codesearch.ts +132 -0
- package/src/tool/codesearch.txt +12 -0
- package/src/tool/edit.ts +655 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/external-directory.ts +32 -0
- package/src/tool/glob.ts +78 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +147 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +17 -0
- package/src/tool/ls.ts +121 -0
- package/src/tool/ls.txt +1 -0
- package/src/tool/lsp.ts +96 -0
- package/src/tool/lsp.txt +19 -0
- package/src/tool/multiedit.ts +46 -0
- package/src/tool/multiedit.txt +41 -0
- package/src/tool/plan-enter.txt +14 -0
- package/src/tool/plan-exit.txt +13 -0
- package/src/tool/plan.ts +130 -0
- package/src/tool/question.ts +33 -0
- package/src/tool/question.txt +10 -0
- package/src/tool/read.ts +211 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +167 -0
- package/src/tool/research-enter.txt +1 -0
- package/src/tool/research-exit.txt +1 -0
- package/src/tool/research.ts +134 -0
- package/src/tool/skill.ts +123 -0
- package/src/tool/task.ts +165 -0
- package/src/tool/task.txt +60 -0
- package/src/tool/todo.ts +53 -0
- package/src/tool/todoread.txt +14 -0
- package/src/tool/todowrite.txt +167 -0
- package/src/tool/tool.ts +89 -0
- package/src/tool/truncation.ts +106 -0
- package/src/tool/webfetch.ts +186 -0
- package/src/tool/webfetch.txt +13 -0
- package/src/tool/websearch.ts +150 -0
- package/src/tool/websearch.txt +14 -0
- package/src/tool/write.ts +85 -0
- package/src/tool/write.txt +8 -0
- package/src/util/abort.ts +35 -0
- package/src/util/archive.ts +16 -0
- package/src/util/color.ts +19 -0
- package/src/util/context.ts +25 -0
- package/src/util/defer.ts +12 -0
- package/src/util/eventloop.ts +20 -0
- package/src/util/filesystem.ts +93 -0
- package/src/util/fn.ts +11 -0
- package/src/util/format.ts +20 -0
- package/src/util/iife.ts +3 -0
- package/src/util/keybind.ts +103 -0
- package/src/util/lazy.ts +18 -0
- package/src/util/locale.ts +81 -0
- package/src/util/lock.ts +98 -0
- package/src/util/log.ts +180 -0
- package/src/util/proxied.ts +3 -0
- package/src/util/queue.ts +32 -0
- package/src/util/rpc.ts +66 -0
- package/src/util/scrap.ts +10 -0
- package/src/util/signal.ts +12 -0
- package/src/util/timeout.ts +14 -0
- package/src/util/token.ts +7 -0
- package/src/util/wildcard.ts +56 -0
- package/src/worktree/index.ts +574 -0
- package/sst-env.d.ts +9 -0
- package/test/acp/agent-interface.test.ts +51 -0
- package/test/acp/event-subscription.test.ts +436 -0
- package/test/agent/agent.test.ts +675 -0
- package/test/bun.test.ts +53 -0
- package/test/cli/github-action.test.ts +161 -0
- package/test/cli/github-remote.test.ts +80 -0
- package/test/cli/import.test.ts +38 -0
- package/test/cli/tui/transcript.test.ts +322 -0
- package/test/config/agent-color.test.ts +71 -0
- package/test/config/config.test.ts +1802 -0
- package/test/config/fixtures/empty-frontmatter.md +4 -0
- package/test/config/fixtures/frontmatter.md +28 -0
- package/test/config/fixtures/markdown-header.md +11 -0
- package/test/config/fixtures/no-frontmatter.md +1 -0
- package/test/config/fixtures/weird-model-id.md +13 -0
- package/test/config/markdown.test.ts +228 -0
- package/test/file/ignore.test.ts +10 -0
- package/test/file/path-traversal.test.ts +198 -0
- package/test/file/ripgrep.test.ts +39 -0
- package/test/fixture/fixture.ts +45 -0
- package/test/fixture/lsp/fake-lsp-server.js +77 -0
- package/test/ide/ide.test.ts +82 -0
- package/test/keybind.test.ts +421 -0
- package/test/lsp/client.test.ts +95 -0
- package/test/mcp/headers.test.ts +153 -0
- package/test/mcp/oauth-browser.test.ts +249 -0
- package/test/memory/abort-leak.test.ts +136 -0
- package/test/patch/patch.test.ts +348 -0
- package/test/permission/arity.test.ts +33 -0
- package/test/permission/next.test.ts +690 -0
- package/test/permission-task.test.ts +319 -0
- package/test/plugin/auth-override.test.ts +44 -0
- package/test/plugin/codex.test.ts +123 -0
- package/test/preload.ts +63 -0
- package/test/project/project.test.ts +120 -0
- package/test/provider/amazon-bedrock.test.ts +445 -0
- package/test/provider/copilot/convert-to-copilot-messages.test.ts +523 -0
- package/test/provider/copilot/copilot-chat-model.test.ts +592 -0
- package/test/provider/gitlab-duo.test.ts +262 -0
- package/test/provider/provider.test.ts +2129 -0
- package/test/provider/transform.test.ts +2022 -0
- package/test/question/question.test.ts +300 -0
- package/test/scheduler.test.ts +73 -0
- package/test/server/session-list.test.ts +39 -0
- package/test/server/session-select.test.ts +78 -0
- package/test/session/compaction.test.ts +293 -0
- package/test/session/instruction.test.ts +170 -0
- package/test/session/llm.test.ts +691 -0
- package/test/session/message-v2.test.ts +786 -0
- package/test/session/prompt-missing-file.test.ts +53 -0
- package/test/session/prompt-special-chars.test.ts +56 -0
- package/test/session/prompt-variant.test.ts +60 -0
- package/test/session/retry.test.ts +179 -0
- package/test/session/revert-compact.test.ts +285 -0
- package/test/session/session.test.ts +71 -0
- package/test/skill/discovery.test.ts +60 -0
- package/test/skill/skill.test.ts +388 -0
- package/test/snapshot/snapshot.test.ts +1040 -0
- package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
- package/test/tool/apply_patch.test.ts +559 -0
- package/test/tool/bash.test.ts +399 -0
- package/test/tool/external-directory.test.ts +127 -0
- package/test/tool/fixtures/large-image.png +0 -0
- package/test/tool/fixtures/models-api.json +38413 -0
- package/test/tool/grep.test.ts +110 -0
- package/test/tool/question.test.ts +107 -0
- package/test/tool/read.test.ts +358 -0
- package/test/tool/registry.test.ts +122 -0
- package/test/tool/skill.test.ts +112 -0
- package/test/tool/truncation.test.ts +159 -0
- package/test/util/filesystem.test.ts +39 -0
- package/test/util/format.test.ts +59 -0
- package/test/util/iife.test.ts +36 -0
- package/test/util/lazy.test.ts +50 -0
- package/test/util/lock.test.ts +72 -0
- package/test/util/timeout.test.ts +21 -0
- package/test/util/wildcard.test.ts +75 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
import path from "path"
|
|
3
|
+
import { Tool } from "./tool"
|
|
4
|
+
import { Question } from "../question"
|
|
5
|
+
import { Session } from "../session"
|
|
6
|
+
import { MessageV2 } from "../session/message-v2"
|
|
7
|
+
import { Identifier } from "../id/id"
|
|
8
|
+
import { Provider } from "../provider/provider"
|
|
9
|
+
import { Instance } from "../project/instance"
|
|
10
|
+
import EXIT_DESCRIPTION from "./research-exit.txt"
|
|
11
|
+
import ENTER_DESCRIPTION from "./research-enter.txt"
|
|
12
|
+
|
|
13
|
+
async function getLastModel(sessionID: string) {
|
|
14
|
+
for await (const item of MessageV2.stream(sessionID)) {
|
|
15
|
+
if (item.info.role === "user" && item.info.model) return item.info.model
|
|
16
|
+
}
|
|
17
|
+
return Provider.defaultModel()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function researchFile(session: Session.Info): string {
|
|
21
|
+
return path.join(Instance.worktree, ".opencode", "research", `${session.id}.md`)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const ResearchExitTool = Tool.define("research_exit", {
|
|
25
|
+
description: EXIT_DESCRIPTION,
|
|
26
|
+
parameters: z.object({}),
|
|
27
|
+
async execute(_params, ctx) {
|
|
28
|
+
const session = await Session.get(ctx.sessionID)
|
|
29
|
+
const research = path.relative(Instance.worktree, researchFile(session))
|
|
30
|
+
const answers = await Question.ask({
|
|
31
|
+
sessionID: ctx.sessionID,
|
|
32
|
+
questions: [
|
|
33
|
+
{
|
|
34
|
+
question: `Research at ${research} is complete. Would you like to switch to the build agent and start implementing?`,
|
|
35
|
+
header: "Build Agent",
|
|
36
|
+
custom: false,
|
|
37
|
+
options: [
|
|
38
|
+
{ label: "Yes", description: "Switch to build agent and implement findings" },
|
|
39
|
+
{ label: "No", description: "Stay with research agent to continue researching" },
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
tool: ctx.callID ? { messageID: ctx.messageID, callID: ctx.callID } : undefined,
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const answer = answers[0]?.[0]
|
|
47
|
+
if (answer === "No") throw new Question.RejectedError()
|
|
48
|
+
|
|
49
|
+
const model = await getLastModel(ctx.sessionID)
|
|
50
|
+
|
|
51
|
+
const userMsg: MessageV2.User = {
|
|
52
|
+
id: Identifier.ascending("message"),
|
|
53
|
+
sessionID: ctx.sessionID,
|
|
54
|
+
role: "user",
|
|
55
|
+
time: {
|
|
56
|
+
created: Date.now(),
|
|
57
|
+
},
|
|
58
|
+
agent: "build",
|
|
59
|
+
model,
|
|
60
|
+
}
|
|
61
|
+
await Session.updateMessage(userMsg)
|
|
62
|
+
await Session.updatePart({
|
|
63
|
+
id: Identifier.ascending("part"),
|
|
64
|
+
messageID: userMsg.id,
|
|
65
|
+
sessionID: ctx.sessionID,
|
|
66
|
+
type: "text",
|
|
67
|
+
text: `Research at ${research} is complete. Implement the research findings.`,
|
|
68
|
+
synthetic: true,
|
|
69
|
+
} satisfies MessageV2.TextPart)
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
title: "Switching to build agent",
|
|
73
|
+
output: "User approved switching to build agent. Wait for further instructions.",
|
|
74
|
+
metadata: {},
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
export const ResearchEnterTool = Tool.define("research_enter", {
|
|
80
|
+
description: ENTER_DESCRIPTION,
|
|
81
|
+
parameters: z.object({}),
|
|
82
|
+
async execute(_params, ctx) {
|
|
83
|
+
const session = await Session.get(ctx.sessionID)
|
|
84
|
+
const research = path.relative(Instance.worktree, researchFile(session))
|
|
85
|
+
|
|
86
|
+
const answers = await Question.ask({
|
|
87
|
+
sessionID: ctx.sessionID,
|
|
88
|
+
questions: [
|
|
89
|
+
{
|
|
90
|
+
question: `Would you like to switch to the research agent and create a research report saved to ${research}?`,
|
|
91
|
+
header: "Research Mode",
|
|
92
|
+
custom: false,
|
|
93
|
+
options: [
|
|
94
|
+
{ label: "Yes", description: "Switch to research agent for systematic web research" },
|
|
95
|
+
{ label: "No", description: "Stay with current agent" },
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
tool: ctx.callID ? { messageID: ctx.messageID, callID: ctx.callID } : undefined,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const answer = answers[0]?.[0]
|
|
103
|
+
|
|
104
|
+
if (answer === "No") throw new Question.RejectedError()
|
|
105
|
+
|
|
106
|
+
const model = await getLastModel(ctx.sessionID)
|
|
107
|
+
|
|
108
|
+
const userMsg: MessageV2.User = {
|
|
109
|
+
id: Identifier.ascending("message"),
|
|
110
|
+
sessionID: ctx.sessionID,
|
|
111
|
+
role: "user",
|
|
112
|
+
time: {
|
|
113
|
+
created: Date.now(),
|
|
114
|
+
},
|
|
115
|
+
agent: "research",
|
|
116
|
+
model,
|
|
117
|
+
}
|
|
118
|
+
await Session.updateMessage(userMsg)
|
|
119
|
+
await Session.updatePart({
|
|
120
|
+
id: Identifier.ascending("part"),
|
|
121
|
+
messageID: userMsg.id,
|
|
122
|
+
sessionID: ctx.sessionID,
|
|
123
|
+
type: "text",
|
|
124
|
+
text: "User has requested to enter research mode. Switch to research mode and begin systematic web research.",
|
|
125
|
+
synthetic: true,
|
|
126
|
+
} satisfies MessageV2.TextPart)
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
title: "Switching to research agent",
|
|
130
|
+
output: `User confirmed to switch to research mode. A new message has been created to switch you to research mode. The research file will be at ${research}. Begin research.`,
|
|
131
|
+
metadata: {},
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
})
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import path from "path"
|
|
2
|
+
import { pathToFileURL } from "url"
|
|
3
|
+
import z from "zod"
|
|
4
|
+
import { Tool } from "./tool"
|
|
5
|
+
import { Skill } from "../skill"
|
|
6
|
+
import { PermissionNext } from "../permission/next"
|
|
7
|
+
import { Ripgrep } from "../file/ripgrep"
|
|
8
|
+
import { iife } from "@/util/iife"
|
|
9
|
+
|
|
10
|
+
export const SkillTool = Tool.define("skill", async (ctx) => {
|
|
11
|
+
const skills = await Skill.all()
|
|
12
|
+
|
|
13
|
+
// Filter skills by agent permissions if agent provided
|
|
14
|
+
const agent = ctx?.agent
|
|
15
|
+
const accessibleSkills = agent
|
|
16
|
+
? skills.filter((skill) => {
|
|
17
|
+
const rule = PermissionNext.evaluate("skill", skill.name, agent.permission)
|
|
18
|
+
return rule.action !== "deny"
|
|
19
|
+
})
|
|
20
|
+
: skills
|
|
21
|
+
|
|
22
|
+
const description =
|
|
23
|
+
accessibleSkills.length === 0
|
|
24
|
+
? "Load a specialized skill that provides domain-specific instructions and workflows. No skills are currently available."
|
|
25
|
+
: [
|
|
26
|
+
"Load a specialized skill that provides domain-specific instructions and workflows.",
|
|
27
|
+
"",
|
|
28
|
+
"When you recognize that a task matches one of the available skills listed below, use this tool to load the full skill instructions.",
|
|
29
|
+
"",
|
|
30
|
+
"The skill will inject detailed instructions, workflows, and access to bundled resources (scripts, references, templates) into the conversation context.",
|
|
31
|
+
"",
|
|
32
|
+
'Tool output includes a `<skill_content name="...">` block with the loaded content.',
|
|
33
|
+
"",
|
|
34
|
+
"The following skills provide specialized sets of instructions for particular tasks",
|
|
35
|
+
"Invoke this tool to load a skill when a task matches one of the available skills listed below:",
|
|
36
|
+
"",
|
|
37
|
+
"<available_skills>",
|
|
38
|
+
...accessibleSkills.flatMap((skill) => [
|
|
39
|
+
` <skill>`,
|
|
40
|
+
` <name>${skill.name}</name>`,
|
|
41
|
+
` <description>${skill.description}</description>`,
|
|
42
|
+
` <location>${pathToFileURL(skill.location).href}</location>`,
|
|
43
|
+
` </skill>`,
|
|
44
|
+
]),
|
|
45
|
+
"</available_skills>",
|
|
46
|
+
].join("\n")
|
|
47
|
+
|
|
48
|
+
const examples = accessibleSkills
|
|
49
|
+
.map((skill) => `'${skill.name}'`)
|
|
50
|
+
.slice(0, 3)
|
|
51
|
+
.join(", ")
|
|
52
|
+
const hint = examples.length > 0 ? ` (e.g., ${examples}, ...)` : ""
|
|
53
|
+
|
|
54
|
+
const parameters = z.object({
|
|
55
|
+
name: z.string().describe(`The name of the skill from available_skills${hint}`),
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
description,
|
|
60
|
+
parameters,
|
|
61
|
+
async execute(params: z.infer<typeof parameters>, ctx) {
|
|
62
|
+
const skill = await Skill.get(params.name)
|
|
63
|
+
|
|
64
|
+
if (!skill) {
|
|
65
|
+
const available = await Skill.all().then((x) => Object.keys(x).join(", "))
|
|
66
|
+
throw new Error(`Skill "${params.name}" not found. Available skills: ${available || "none"}`)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
await ctx.ask({
|
|
70
|
+
permission: "skill",
|
|
71
|
+
patterns: [params.name],
|
|
72
|
+
always: [params.name],
|
|
73
|
+
metadata: {},
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const dir = path.dirname(skill.location)
|
|
77
|
+
const base = pathToFileURL(dir).href
|
|
78
|
+
|
|
79
|
+
const limit = 10
|
|
80
|
+
const files = await iife(async () => {
|
|
81
|
+
const arr = []
|
|
82
|
+
for await (const file of Ripgrep.files({
|
|
83
|
+
cwd: dir,
|
|
84
|
+
follow: false,
|
|
85
|
+
hidden: true,
|
|
86
|
+
signal: ctx.abort,
|
|
87
|
+
})) {
|
|
88
|
+
if (file.includes("SKILL.md")) {
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
91
|
+
arr.push(path.resolve(dir, file))
|
|
92
|
+
if (arr.length >= limit) {
|
|
93
|
+
break
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return arr
|
|
97
|
+
}).then((f) => f.map((file) => `<file>${file}</file>`).join("\n"))
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
title: `Loaded skill: ${skill.name}`,
|
|
101
|
+
output: [
|
|
102
|
+
`<skill_content name="${skill.name}">`,
|
|
103
|
+
`# Skill: ${skill.name}`,
|
|
104
|
+
"",
|
|
105
|
+
skill.content.trim(),
|
|
106
|
+
"",
|
|
107
|
+
`Base directory for this skill: ${base}`,
|
|
108
|
+
"Relative paths in this skill (e.g., scripts/, reference/) are relative to this base directory.",
|
|
109
|
+
"Note: file list is sampled.",
|
|
110
|
+
"",
|
|
111
|
+
"<skill_files>",
|
|
112
|
+
files,
|
|
113
|
+
"</skill_files>",
|
|
114
|
+
"</skill_content>",
|
|
115
|
+
].join("\n"),
|
|
116
|
+
metadata: {
|
|
117
|
+
name: skill.name,
|
|
118
|
+
dir,
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
}
|
|
123
|
+
})
|
package/src/tool/task.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Tool } from "./tool"
|
|
2
|
+
import DESCRIPTION from "./task.txt"
|
|
3
|
+
import z from "zod"
|
|
4
|
+
import { Session } from "../session"
|
|
5
|
+
import { MessageV2 } from "../session/message-v2"
|
|
6
|
+
import { Identifier } from "../id/id"
|
|
7
|
+
import { Agent } from "../agent/agent"
|
|
8
|
+
import { SessionPrompt } from "../session/prompt"
|
|
9
|
+
import { iife } from "@/util/iife"
|
|
10
|
+
import { defer } from "@/util/defer"
|
|
11
|
+
import { Config } from "../config/config"
|
|
12
|
+
import { PermissionNext } from "@/permission/next"
|
|
13
|
+
|
|
14
|
+
const parameters = z.object({
|
|
15
|
+
description: z.string().describe("A short (3-5 words) description of the task"),
|
|
16
|
+
prompt: z.string().describe("The task for the agent to perform"),
|
|
17
|
+
subagent_type: z.string().describe("The type of specialized agent to use for this task"),
|
|
18
|
+
task_id: z
|
|
19
|
+
.string()
|
|
20
|
+
.describe(
|
|
21
|
+
"This should only be set if you mean to resume a previous task (you can pass a prior task_id and the task will continue the same subagent session as before instead of creating a fresh one)",
|
|
22
|
+
)
|
|
23
|
+
.optional(),
|
|
24
|
+
command: z.string().describe("The command that triggered this task").optional(),
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export const TaskTool = Tool.define("task", async (ctx) => {
|
|
28
|
+
const agents = await Agent.list().then((x) => x.filter((a) => a.mode !== "primary"))
|
|
29
|
+
|
|
30
|
+
// Filter agents by permissions if agent provided
|
|
31
|
+
const caller = ctx?.agent
|
|
32
|
+
const accessibleAgents = caller
|
|
33
|
+
? agents.filter((a) => PermissionNext.evaluate("task", a.name, caller.permission).action !== "deny")
|
|
34
|
+
: agents
|
|
35
|
+
|
|
36
|
+
const description = DESCRIPTION.replace(
|
|
37
|
+
"{agents}",
|
|
38
|
+
accessibleAgents
|
|
39
|
+
.map((a) => `- ${a.name}: ${a.description ?? "This subagent should only be called manually by the user."}`)
|
|
40
|
+
.join("\n"),
|
|
41
|
+
)
|
|
42
|
+
return {
|
|
43
|
+
description,
|
|
44
|
+
parameters,
|
|
45
|
+
async execute(params: z.infer<typeof parameters>, ctx) {
|
|
46
|
+
const config = await Config.get()
|
|
47
|
+
|
|
48
|
+
// Skip permission check when user explicitly invoked via @ or command subtask
|
|
49
|
+
if (!ctx.extra?.bypassAgentCheck) {
|
|
50
|
+
await ctx.ask({
|
|
51
|
+
permission: "task",
|
|
52
|
+
patterns: [params.subagent_type],
|
|
53
|
+
always: ["*"],
|
|
54
|
+
metadata: {
|
|
55
|
+
description: params.description,
|
|
56
|
+
subagent_type: params.subagent_type,
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const agent = await Agent.get(params.subagent_type)
|
|
62
|
+
if (!agent) throw new Error(`Unknown agent type: ${params.subagent_type} is not a valid agent type`)
|
|
63
|
+
|
|
64
|
+
const hasTaskPermission = agent.permission.some((rule) => rule.permission === "task")
|
|
65
|
+
|
|
66
|
+
const session = await iife(async () => {
|
|
67
|
+
if (params.task_id) {
|
|
68
|
+
const found = await Session.get(params.task_id).catch(() => {})
|
|
69
|
+
if (found) return found
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return await Session.create({
|
|
73
|
+
parentID: ctx.sessionID,
|
|
74
|
+
title: params.description + ` (@${agent.name} subagent)`,
|
|
75
|
+
permission: [
|
|
76
|
+
{
|
|
77
|
+
permission: "todowrite",
|
|
78
|
+
pattern: "*",
|
|
79
|
+
action: "deny",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
permission: "todoread",
|
|
83
|
+
pattern: "*",
|
|
84
|
+
action: "deny",
|
|
85
|
+
},
|
|
86
|
+
...(hasTaskPermission
|
|
87
|
+
? []
|
|
88
|
+
: [
|
|
89
|
+
{
|
|
90
|
+
permission: "task" as const,
|
|
91
|
+
pattern: "*" as const,
|
|
92
|
+
action: "deny" as const,
|
|
93
|
+
},
|
|
94
|
+
]),
|
|
95
|
+
...(config.experimental?.primary_tools?.map((t) => ({
|
|
96
|
+
pattern: "*",
|
|
97
|
+
action: "allow" as const,
|
|
98
|
+
permission: t,
|
|
99
|
+
})) ?? []),
|
|
100
|
+
],
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
const msg = await MessageV2.get({ sessionID: ctx.sessionID, messageID: ctx.messageID })
|
|
104
|
+
if (msg.info.role !== "assistant") throw new Error("Not an assistant message")
|
|
105
|
+
|
|
106
|
+
const model = agent.model ?? {
|
|
107
|
+
modelID: msg.info.modelID,
|
|
108
|
+
providerID: msg.info.providerID,
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
ctx.metadata({
|
|
112
|
+
title: params.description,
|
|
113
|
+
metadata: {
|
|
114
|
+
sessionId: session.id,
|
|
115
|
+
model,
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
const messageID = Identifier.ascending("message")
|
|
120
|
+
|
|
121
|
+
function cancel() {
|
|
122
|
+
SessionPrompt.cancel(session.id)
|
|
123
|
+
}
|
|
124
|
+
ctx.abort.addEventListener("abort", cancel)
|
|
125
|
+
using _ = defer(() => ctx.abort.removeEventListener("abort", cancel))
|
|
126
|
+
const promptParts = await SessionPrompt.resolvePromptParts(params.prompt)
|
|
127
|
+
|
|
128
|
+
const result = await SessionPrompt.prompt({
|
|
129
|
+
messageID,
|
|
130
|
+
sessionID: session.id,
|
|
131
|
+
model: {
|
|
132
|
+
modelID: model.modelID,
|
|
133
|
+
providerID: model.providerID,
|
|
134
|
+
},
|
|
135
|
+
agent: agent.name,
|
|
136
|
+
tools: {
|
|
137
|
+
todowrite: false,
|
|
138
|
+
todoread: false,
|
|
139
|
+
...(hasTaskPermission ? {} : { task: false }),
|
|
140
|
+
...Object.fromEntries((config.experimental?.primary_tools ?? []).map((t) => [t, false])),
|
|
141
|
+
},
|
|
142
|
+
parts: promptParts,
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
const text = result.parts.findLast((x) => x.type === "text")?.text ?? ""
|
|
146
|
+
|
|
147
|
+
const output = [
|
|
148
|
+
`task_id: ${session.id} (for resuming to continue this task if needed)`,
|
|
149
|
+
"",
|
|
150
|
+
"<task_result>",
|
|
151
|
+
text,
|
|
152
|
+
"</task_result>",
|
|
153
|
+
].join("\n")
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
title: params.description,
|
|
157
|
+
metadata: {
|
|
158
|
+
sessionId: session.id,
|
|
159
|
+
model,
|
|
160
|
+
},
|
|
161
|
+
output,
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
})
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Launch a new agent to handle complex, multistep tasks autonomously.
|
|
2
|
+
|
|
3
|
+
Available agent types and the tools they have access to:
|
|
4
|
+
{agents}
|
|
5
|
+
|
|
6
|
+
When using the Task tool, you must specify a subagent_type parameter to select which agent type to use.
|
|
7
|
+
|
|
8
|
+
When to use the Task tool:
|
|
9
|
+
- When you are instructed to execute custom slash commands. Use the Task tool with the slash command invocation as the entire prompt. The slash command can take arguments. For example: Task(description="Check the file", prompt="/check-file path/to/file.py")
|
|
10
|
+
|
|
11
|
+
When NOT to use the Task tool:
|
|
12
|
+
- If you want to read a specific file path, use the Read or Glob tool instead of the Task tool, to find the match more quickly
|
|
13
|
+
- If you are searching for a specific class definition like "class Foo", use the Glob tool instead, to find the match more quickly
|
|
14
|
+
- If you are searching for code within a specific file or set of 2-3 files, use the Read tool instead of the Task tool, to find the match more quickly
|
|
15
|
+
- Other tasks that are not related to the agent descriptions above
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
Usage notes:
|
|
19
|
+
1. Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
|
|
20
|
+
2. When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result. The output includes a task_id you can reuse later to continue the same subagent session.
|
|
21
|
+
3. Each agent invocation starts with a fresh context unless you provide task_id to resume the same subagent session (which continues with its previous messages and tool outputs). When starting fresh, your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you.
|
|
22
|
+
4. The agent's outputs should generally be trusted
|
|
23
|
+
5. Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent. Tell it how to verify its work if possible (e.g., relevant test commands).
|
|
24
|
+
6. If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.
|
|
25
|
+
|
|
26
|
+
Example usage (NOTE: The agents below are fictional examples for illustration only - use the actual agents listed above):
|
|
27
|
+
|
|
28
|
+
<example_agent_descriptions>
|
|
29
|
+
"code-reviewer": use this agent after you are done writing a significant piece of code
|
|
30
|
+
"greeting-responder": use this agent when to respond to user greetings with a friendly joke
|
|
31
|
+
</example_agent_description>
|
|
32
|
+
|
|
33
|
+
<example>
|
|
34
|
+
user: "Please write a function that checks if a number is prime"
|
|
35
|
+
assistant: Sure let me write a function that checks if a number is prime
|
|
36
|
+
assistant: First let me use the Write tool to write a function that checks if a number is prime
|
|
37
|
+
assistant: I'm going to use the Write tool to write the following code:
|
|
38
|
+
<code>
|
|
39
|
+
function isPrime(n) {
|
|
40
|
+
if (n <= 1) return false
|
|
41
|
+
for (let i = 2; i * i <= n; i++) {
|
|
42
|
+
if (n % i === 0) return false
|
|
43
|
+
}
|
|
44
|
+
return true
|
|
45
|
+
}
|
|
46
|
+
</code>
|
|
47
|
+
<commentary>
|
|
48
|
+
Since a significant piece of code was written and the task was completed, now use the code-reviewer agent to review the code
|
|
49
|
+
</commentary>
|
|
50
|
+
assistant: Now let me use the code-reviewer agent to review the code
|
|
51
|
+
assistant: Uses the Task tool to launch the code-reviewer agent
|
|
52
|
+
</example>
|
|
53
|
+
|
|
54
|
+
<example>
|
|
55
|
+
user: "Hello"
|
|
56
|
+
<commentary>
|
|
57
|
+
Since the user is greeting, use the greeting-responder agent to respond with a friendly joke
|
|
58
|
+
</commentary>
|
|
59
|
+
assistant: "I'm going to use the Task tool to launch the with the greeting-responder agent"
|
|
60
|
+
</example>
|
package/src/tool/todo.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
import { Tool } from "./tool"
|
|
3
|
+
import DESCRIPTION_WRITE from "./todowrite.txt"
|
|
4
|
+
import { Todo } from "../session/todo"
|
|
5
|
+
|
|
6
|
+
export const TodoWriteTool = Tool.define("todowrite", {
|
|
7
|
+
description: DESCRIPTION_WRITE,
|
|
8
|
+
parameters: z.object({
|
|
9
|
+
todos: z.array(z.object(Todo.Info.shape)).describe("The updated todo list"),
|
|
10
|
+
}),
|
|
11
|
+
async execute(params, ctx) {
|
|
12
|
+
await ctx.ask({
|
|
13
|
+
permission: "todowrite",
|
|
14
|
+
patterns: ["*"],
|
|
15
|
+
always: ["*"],
|
|
16
|
+
metadata: {},
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
await Todo.update({
|
|
20
|
+
sessionID: ctx.sessionID,
|
|
21
|
+
todos: params.todos,
|
|
22
|
+
})
|
|
23
|
+
return {
|
|
24
|
+
title: `${params.todos.filter((x) => x.status !== "completed").length} todos`,
|
|
25
|
+
output: JSON.stringify(params.todos, null, 2),
|
|
26
|
+
metadata: {
|
|
27
|
+
todos: params.todos,
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
export const TodoReadTool = Tool.define("todoread", {
|
|
34
|
+
description: "Use this tool to read your todo list",
|
|
35
|
+
parameters: z.object({}),
|
|
36
|
+
async execute(_params, ctx) {
|
|
37
|
+
await ctx.ask({
|
|
38
|
+
permission: "todoread",
|
|
39
|
+
patterns: ["*"],
|
|
40
|
+
always: ["*"],
|
|
41
|
+
metadata: {},
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const todos = await Todo.get(ctx.sessionID)
|
|
45
|
+
return {
|
|
46
|
+
title: `${todos.filter((x) => x.status !== "completed").length} todos`,
|
|
47
|
+
metadata: {
|
|
48
|
+
todos,
|
|
49
|
+
},
|
|
50
|
+
output: JSON.stringify(todos, null, 2),
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Use this tool to read the current to-do list for the session. This tool should be used proactively and frequently to ensure that you are aware of
|
|
2
|
+
the status of the current task list. You should make use of this tool as often as possible, especially in the following situations:
|
|
3
|
+
- At the beginning of conversations to see what's pending
|
|
4
|
+
- Before starting new tasks to prioritize work
|
|
5
|
+
- When the user asks about previous tasks or plans
|
|
6
|
+
- Whenever you're uncertain about what to do next
|
|
7
|
+
- After completing tasks to update your understanding of remaining work
|
|
8
|
+
- After every few messages to ensure you're on track
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
- This tool takes in no parameters. So leave the input blank or empty. DO NOT include a dummy object, placeholder string or a key like "input" or "empty". LEAVE IT BLANK.
|
|
12
|
+
- Returns a list of todo items with their status, priority, and content
|
|
13
|
+
- Use this information to track progress and plan next steps
|
|
14
|
+
- If no todos exist yet, an empty list will be returned
|