rird 1.0.200
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 +336 -0
- package/bin/pty-wrapper.js +285 -0
- package/bunfig.toml +4 -0
- package/facebook_ads_library.png +0 -0
- package/nul`nif +0 -0
- package/package.json +111 -0
- package/parsers-config.ts +239 -0
- package/rird-1.0.199.tgz +0 -0
- package/script/build-windows.ts +54 -0
- package/script/build.ts +167 -0
- package/script/postinstall.mjs +544 -0
- package/script/publish-registries.ts +187 -0
- package/script/publish.ts +72 -0
- package/script/schema.ts +47 -0
- package/src/acp/README.md +164 -0
- package/src/acp/agent.ts +1063 -0
- package/src/acp/session.ts +101 -0
- package/src/acp/types.ts +22 -0
- package/src/agent/agent.ts +367 -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 +10 -0
- package/src/agent/prompt/title.txt +36 -0
- package/src/auth/index.ts +70 -0
- package/src/bun/index.ts +114 -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 +88 -0
- package/src/cli/cmd/agent.ts +256 -0
- package/src/cli/cmd/auth.ts +391 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/debug/config.ts +15 -0
- package/src/cli/cmd/debug/file.ts +91 -0
- package/src/cli/cmd/debug/index.ts +43 -0
- package/src/cli/cmd/debug/lsp.ts +48 -0
- package/src/cli/cmd/debug/ripgrep.ts +83 -0
- package/src/cli/cmd/debug/scrap.ts +15 -0
- package/src/cli/cmd/debug/skill.ts +15 -0
- package/src/cli/cmd/debug/snapshot.ts +48 -0
- package/src/cli/cmd/export.ts +88 -0
- package/src/cli/cmd/generate.ts +38 -0
- package/src/cli/cmd/github.ts +1400 -0
- package/src/cli/cmd/import.ts +98 -0
- package/src/cli/cmd/mcp.ts +654 -0
- package/src/cli/cmd/models.ts +77 -0
- package/src/cli/cmd/pr.ts +112 -0
- package/src/cli/cmd/run.ts +368 -0
- package/src/cli/cmd/serve.ts +31 -0
- package/src/cli/cmd/session.ts +106 -0
- package/src/cli/cmd/stats.ts +298 -0
- package/src/cli/cmd/tui/app.tsx +696 -0
- package/src/cli/cmd/tui/attach.ts +30 -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 +124 -0
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-model.tsx +245 -0
- package/src/cli/cmd/tui/component/dialog-provider.tsx +224 -0
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +102 -0
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-stash.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-status.tsx +162 -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/did-you-know.tsx +85 -0
- package/src/cli/cmd/tui/component/logo.tsx +35 -0
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +574 -0
- package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
- package/src/cli/cmd/tui/component/prompt/index.tsx +1090 -0
- package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
- package/src/cli/cmd/tui/component/tips.ts +27 -0
- package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
- package/src/cli/cmd/tui/context/args.tsx +14 -0
- package/src/cli/cmd/tui/context/directory.ts +13 -0
- package/src/cli/cmd/tui/context/exit.tsx +23 -0
- package/src/cli/cmd/tui/context/helper.tsx +25 -0
- package/src/cli/cmd/tui/context/keybind.tsx +101 -0
- package/src/cli/cmd/tui/context/kv.tsx +49 -0
- package/src/cli/cmd/tui/context/local.tsx +354 -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 +74 -0
- package/src/cli/cmd/tui/context/sync.tsx +372 -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/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 +95 -0
- package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +227 -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 +245 -0
- package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
- package/src/cli/cmd/tui/context/theme/rird.json +245 -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 +1109 -0
- package/src/cli/cmd/tui/event.ts +40 -0
- package/src/cli/cmd/tui/routes/home.tsx +138 -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 +88 -0
- package/src/cli/cmd/tui/routes/session/header.tsx +125 -0
- package/src/cli/cmd/tui/routes/session/index.tsx +1864 -0
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +318 -0
- package/src/cli/cmd/tui/spawn.ts +60 -0
- package/src/cli/cmd/tui/thread.ts +142 -0
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
- package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
- package/src/cli/cmd/tui/ui/dialog-select.tsx +332 -0
- package/src/cli/cmd/tui/ui/dialog.tsx +170 -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 +127 -0
- package/src/cli/cmd/tui/util/editor.ts +32 -0
- package/src/cli/cmd/tui/util/terminal.ts +114 -0
- package/src/cli/cmd/tui/worker.ts +63 -0
- package/src/cli/cmd/uninstall.ts +344 -0
- package/src/cli/cmd/upgrade.ts +100 -0
- package/src/cli/cmd/web.ts +84 -0
- package/src/cli/error.ts +56 -0
- package/src/cli/ui.ts +84 -0
- package/src/cli/upgrade.ts +25 -0
- package/src/command/index.ts +80 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/command/template/review.txt +97 -0
- package/src/config/config.ts +995 -0
- package/src/config/markdown.ts +41 -0
- package/src/env/index.ts +26 -0
- package/src/file/ignore.ts +83 -0
- package/src/file/index.ts +328 -0
- package/src/file/ripgrep.ts +393 -0
- package/src/file/time.ts +64 -0
- package/src/file/watcher.ts +103 -0
- package/src/flag/flag.ts +46 -0
- package/src/format/formatter.ts +315 -0
- package/src/format/index.ts +137 -0
- package/src/global/index.ts +52 -0
- package/src/id/id.ts +73 -0
- package/src/ide/index.ts +76 -0
- package/src/index.ts +240 -0
- package/src/installation/index.ts +239 -0
- package/src/lsp/client.ts +229 -0
- package/src/lsp/index.ts +485 -0
- package/src/lsp/language.ts +116 -0
- package/src/lsp/server.ts +1895 -0
- package/src/mcp/auth.ts +135 -0
- package/src/mcp/index.ts +690 -0
- package/src/mcp/oauth-callback.ts +200 -0
- package/src/mcp/oauth-provider.ts +154 -0
- package/src/patch/index.ts +622 -0
- package/src/permission/index.ts +199 -0
- package/src/plugin/index.ts +91 -0
- package/src/project/bootstrap.ts +31 -0
- package/src/project/instance.ts +78 -0
- package/src/project/project.ts +221 -0
- package/src/project/state.ts +65 -0
- package/src/project/vcs.ts +76 -0
- package/src/provider/auth.ts +143 -0
- package/src/provider/models-macro.ts +11 -0
- package/src/provider/models.ts +106 -0
- package/src/provider/provider.ts +1071 -0
- package/src/provider/sdk/openai-compatible/src/README.md +5 -0
- package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
- package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
- package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
- package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1713 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
- package/src/provider/transform.ts +455 -0
- package/src/pty/index.ts +231 -0
- package/src/security/guardrails.test.ts +341 -0
- package/src/security/guardrails.ts +558 -0
- package/src/security/index.ts +19 -0
- package/src/server/error.ts +36 -0
- package/src/server/project.ts +79 -0
- package/src/server/server.ts +2642 -0
- package/src/server/tui.ts +71 -0
- package/src/session/compaction.ts +223 -0
- package/src/session/index.ts +461 -0
- package/src/session/llm.ts +201 -0
- package/src/session/message-v2.ts +690 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +409 -0
- package/src/session/prompt/act-switch.txt +5 -0
- package/src/session/prompt/anthropic-20250930.txt +166 -0
- package/src/session/prompt/anthropic.txt +85 -0
- package/src/session/prompt/anthropic_spoof.txt +1 -0
- package/src/session/prompt/beast.txt +103 -0
- package/src/session/prompt/codex.txt +304 -0
- package/src/session/prompt/copilot-gpt-5.txt +138 -0
- package/src/session/prompt/gemini.txt +85 -0
- package/src/session/prompt/max-steps.txt +16 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +35 -0
- package/src/session/prompt/plan.txt +24 -0
- package/src/session/prompt/polaris.txt +84 -0
- package/src/session/prompt/qwen.txt +106 -0
- package/src/session/prompt.ts +1509 -0
- package/src/session/retry.ts +86 -0
- package/src/session/revert.ts +108 -0
- package/src/session/sensitive-filter.test.ts +327 -0
- package/src/session/sensitive-filter.ts +466 -0
- package/src/session/status.ts +76 -0
- package/src/session/summary.ts +194 -0
- package/src/session/system.ts +120 -0
- package/src/session/todo.ts +37 -0
- package/src/share/share-next.ts +194 -0
- package/src/share/share.ts +87 -0
- package/src/shell/shell.ts +67 -0
- package/src/skill/index.ts +1 -0
- package/src/skill/skill.ts +83 -0
- package/src/snapshot/index.ts +197 -0
- package/src/storage/storage.ts +226 -0
- package/src/tests/agent.test.ts +308 -0
- package/src/tests/build-guards.test.ts +267 -0
- package/src/tests/config.test.ts +664 -0
- package/src/tests/tool-registry.test.ts +589 -0
- package/src/tool/bash.ts +317 -0
- package/src/tool/bash.txt +158 -0
- package/src/tool/batch.ts +175 -0
- package/src/tool/batch.txt +24 -0
- package/src/tool/codesearch.ts +168 -0
- package/src/tool/codesearch.txt +12 -0
- package/src/tool/edit.ts +675 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/glob.ts +65 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +121 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +17 -0
- package/src/tool/ls.ts +110 -0
- package/src/tool/ls.txt +1 -0
- package/src/tool/lsp-diagnostics.ts +26 -0
- package/src/tool/lsp-diagnostics.txt +1 -0
- package/src/tool/lsp-hover.ts +31 -0
- package/src/tool/lsp-hover.txt +1 -0
- package/src/tool/lsp.ts +87 -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/patch.ts +233 -0
- package/src/tool/patch.txt +1 -0
- package/src/tool/read.ts +219 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +162 -0
- package/src/tool/skill.ts +100 -0
- package/src/tool/task.ts +136 -0
- package/src/tool/task.txt +51 -0
- package/src/tool/todo.ts +39 -0
- package/src/tool/todoread.txt +14 -0
- package/src/tool/todowrite.txt +167 -0
- package/src/tool/tool.ts +71 -0
- package/src/tool/webfetch.ts +198 -0
- package/src/tool/webfetch.txt +13 -0
- package/src/tool/websearch.ts +180 -0
- package/src/tool/websearch.txt +11 -0
- package/src/tool/write.ts +110 -0
- package/src/tool/write.txt +8 -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 +83 -0
- package/src/util/fn.ts +11 -0
- package/src/util/iife.ts +3 -0
- package/src/util/keybind.ts +102 -0
- package/src/util/lazy.ts +11 -0
- package/src/util/license.ts +325 -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/queue.ts +32 -0
- package/src/util/rpc.ts +42 -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 +54 -0
- package/sst-env.d.ts +9 -0
- package/test/agent/agent.test.ts +146 -0
- package/test/bun.test.ts +53 -0
- package/test/cli/github-remote.test.ts +80 -0
- package/test/config/agent-color.test.ts +66 -0
- package/test/config/config.test.ts +535 -0
- package/test/config/markdown.test.ts +89 -0
- package/test/file/ignore.test.ts +10 -0
- package/test/fixture/fixture.ts +36 -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/patch/patch.test.ts +348 -0
- package/test/preload.ts +57 -0
- package/test/project/project.test.ts +72 -0
- package/test/provider/provider.test.ts +1809 -0
- package/test/provider/transform.test.ts +411 -0
- package/test/session/retry.test.ts +111 -0
- package/test/session/session.test.ts +71 -0
- package/test/skill/skill.test.ts +131 -0
- package/test/snapshot/snapshot.test.ts +939 -0
- package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
- package/test/tool/bash.test.ts +434 -0
- package/test/tool/grep.test.ts +108 -0
- package/test/tool/patch.test.ts +259 -0
- package/test/tool/read.test.ts +42 -0
- package/test/util/iife.test.ts +36 -0
- package/test/util/lazy.test.ts +50 -0
- package/test/util/timeout.test.ts +21 -0
- package/test/util/wildcard.test.ts +55 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import path from "path"
|
|
2
|
+
import z from "zod"
|
|
3
|
+
import { Tool } from "./tool"
|
|
4
|
+
import { Skill } from "../skill"
|
|
5
|
+
import { Agent } from "../agent/agent"
|
|
6
|
+
import { Permission } from "../permission"
|
|
7
|
+
import { Wildcard } from "../util/wildcard"
|
|
8
|
+
import { ConfigMarkdown } from "../config/markdown"
|
|
9
|
+
|
|
10
|
+
const parameters = z.object({
|
|
11
|
+
name: z.string().describe("The skill identifier from available_skills (e.g., 'review')"),
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export const SkillTool: Tool.Info<typeof parameters> = {
|
|
15
|
+
id: "skill",
|
|
16
|
+
async init(ctx) {
|
|
17
|
+
const skills = await Skill.all()
|
|
18
|
+
|
|
19
|
+
// Filter skills by agent permissions if agent provided
|
|
20
|
+
let accessibleSkills = skills
|
|
21
|
+
if (ctx?.agent) {
|
|
22
|
+
const permissions = ctx.agent.permission.skill
|
|
23
|
+
accessibleSkills = skills.filter((skill) => {
|
|
24
|
+
const action = Wildcard.all(skill.name, permissions)
|
|
25
|
+
return action !== "deny"
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
description: [
|
|
31
|
+
"Load a skill to get detailed instructions for a specific task.",
|
|
32
|
+
"Skills provide specialized knowledge and step-by-step guidance.",
|
|
33
|
+
"Use this when a task matches an available skill's description.",
|
|
34
|
+
"<available_skills>",
|
|
35
|
+
...accessibleSkills.flatMap((skill) => [
|
|
36
|
+
` <skill>`,
|
|
37
|
+
` <name>${skill.name}</name>`,
|
|
38
|
+
` <description>${skill.description}</description>`,
|
|
39
|
+
` </skill>`,
|
|
40
|
+
]),
|
|
41
|
+
"</available_skills>",
|
|
42
|
+
].join(" "),
|
|
43
|
+
parameters,
|
|
44
|
+
async execute(params, ctx) {
|
|
45
|
+
const agent = await Agent.get(ctx.agent)
|
|
46
|
+
|
|
47
|
+
const skill = await Skill.get(params.name)
|
|
48
|
+
|
|
49
|
+
if (!skill) {
|
|
50
|
+
const available = await Skill.all().then((x) => x.map((s) => s.name).join(", "))
|
|
51
|
+
throw new Error(`Skill "${params.name}" not found. Available skills: ${available || "none"}`)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Check permission using Wildcard.all on the skill name
|
|
55
|
+
const permissions = agent.permission.skill
|
|
56
|
+
const action = Wildcard.all(params.name, permissions)
|
|
57
|
+
|
|
58
|
+
if (action === "deny") {
|
|
59
|
+
throw new Permission.RejectedError(
|
|
60
|
+
ctx.sessionID,
|
|
61
|
+
"skill",
|
|
62
|
+
ctx.callID,
|
|
63
|
+
{ skill: params.name },
|
|
64
|
+
`Access to skill "${params.name}" is denied for agent "${agent.name}".`,
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (action === "ask") {
|
|
69
|
+
await Permission.ask({
|
|
70
|
+
type: "skill",
|
|
71
|
+
pattern: params.name,
|
|
72
|
+
sessionID: ctx.sessionID,
|
|
73
|
+
messageID: ctx.messageID,
|
|
74
|
+
callID: ctx.callID,
|
|
75
|
+
title: `Load skill: ${skill.name}`,
|
|
76
|
+
metadata: { name: skill.name, description: skill.description },
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Load and parse skill content
|
|
81
|
+
const parsed = await ConfigMarkdown.parse(skill.location)
|
|
82
|
+
const dir = path.dirname(skill.location)
|
|
83
|
+
|
|
84
|
+
// Format output similar to plugin pattern
|
|
85
|
+
const output = [`## Skill: ${skill.name}`, "", `**Base directory**: ${dir}`, "", parsed.content.trim()].join(
|
|
86
|
+
"\n",
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
title: `Loaded skill: ${skill.name}`,
|
|
91
|
+
output,
|
|
92
|
+
metadata: {
|
|
93
|
+
name: skill.name,
|
|
94
|
+
dir,
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
}
|
package/src/tool/task.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Tool } from "./tool"
|
|
2
|
+
import DESCRIPTION from "./task.txt"
|
|
3
|
+
import z from "zod"
|
|
4
|
+
import { Session } from "../session"
|
|
5
|
+
import { Bus } from "../bus"
|
|
6
|
+
import { MessageV2 } from "../session/message-v2"
|
|
7
|
+
import { Identifier } from "../id/id"
|
|
8
|
+
import { Agent } from "../agent/agent"
|
|
9
|
+
import { SessionPrompt } from "../session/prompt"
|
|
10
|
+
import { iife } from "@/util/iife"
|
|
11
|
+
import { defer } from "@/util/defer"
|
|
12
|
+
import { Config } from "../config/config"
|
|
13
|
+
|
|
14
|
+
export const TaskTool = Tool.define("task", async () => {
|
|
15
|
+
const agents = await Agent.list().then((x) => x.filter((a) => a.mode !== "primary"))
|
|
16
|
+
const description = DESCRIPTION.replace(
|
|
17
|
+
"{agents}",
|
|
18
|
+
agents
|
|
19
|
+
.map((a) => `- ${a.name}: ${a.description ?? "This subagent should only be called manually by the user."}`)
|
|
20
|
+
.join("\n"),
|
|
21
|
+
)
|
|
22
|
+
return {
|
|
23
|
+
description,
|
|
24
|
+
parameters: z.object({
|
|
25
|
+
description: z.string().describe("A short (3-5 words) description of the task"),
|
|
26
|
+
prompt: z.string().describe("The task for the agent to perform"),
|
|
27
|
+
subagent_type: z.string().describe("The type of specialized agent to use for this task"),
|
|
28
|
+
session_id: z.string().describe("Existing Task session to continue").optional(),
|
|
29
|
+
command: z.string().describe("The command that triggered this task").optional(),
|
|
30
|
+
}),
|
|
31
|
+
async execute(params, ctx) {
|
|
32
|
+
const agent = await Agent.get(params.subagent_type)
|
|
33
|
+
if (!agent) throw new Error(`Unknown agent type: ${params.subagent_type} is not a valid agent type`)
|
|
34
|
+
const session = await iife(async () => {
|
|
35
|
+
if (params.session_id) {
|
|
36
|
+
const found = await Session.get(params.session_id).catch(() => {})
|
|
37
|
+
if (found) return found
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return await Session.create({
|
|
41
|
+
parentID: ctx.sessionID,
|
|
42
|
+
title: params.description + ` (@${agent.name} subagent)`,
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
const msg = await MessageV2.get({ sessionID: ctx.sessionID, messageID: ctx.messageID })
|
|
46
|
+
if (msg.info.role !== "assistant") throw new Error("Not an assistant message")
|
|
47
|
+
|
|
48
|
+
ctx.metadata({
|
|
49
|
+
title: params.description,
|
|
50
|
+
metadata: {
|
|
51
|
+
sessionId: session.id,
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const messageID = Identifier.ascending("message")
|
|
56
|
+
const parts: Record<string, { id: string; tool: string; state: { status: string; title?: string } }> = {}
|
|
57
|
+
const unsub = Bus.subscribe(MessageV2.Event.PartUpdated, async (evt) => {
|
|
58
|
+
if (evt.properties.part.sessionID !== session.id) return
|
|
59
|
+
if (evt.properties.part.messageID === messageID) return
|
|
60
|
+
if (evt.properties.part.type !== "tool") return
|
|
61
|
+
const part = evt.properties.part
|
|
62
|
+
parts[part.id] = {
|
|
63
|
+
id: part.id,
|
|
64
|
+
tool: part.tool,
|
|
65
|
+
state: {
|
|
66
|
+
status: part.state.status,
|
|
67
|
+
title: part.state.status === "completed" ? part.state.title : undefined,
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
ctx.metadata({
|
|
71
|
+
title: params.description,
|
|
72
|
+
metadata: {
|
|
73
|
+
summary: Object.values(parts).sort((a, b) => a.id.localeCompare(b.id)),
|
|
74
|
+
sessionId: session.id,
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const model = agent.model ?? {
|
|
80
|
+
modelID: msg.info.modelID,
|
|
81
|
+
providerID: msg.info.providerID,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function cancel() {
|
|
85
|
+
SessionPrompt.cancel(session.id)
|
|
86
|
+
}
|
|
87
|
+
ctx.abort.addEventListener("abort", cancel)
|
|
88
|
+
using _ = defer(() => ctx.abort.removeEventListener("abort", cancel))
|
|
89
|
+
const promptParts = await SessionPrompt.resolvePromptParts(params.prompt)
|
|
90
|
+
|
|
91
|
+
const config = await Config.get()
|
|
92
|
+
const result = await SessionPrompt.prompt({
|
|
93
|
+
messageID,
|
|
94
|
+
sessionID: session.id,
|
|
95
|
+
model: {
|
|
96
|
+
modelID: model.modelID,
|
|
97
|
+
providerID: model.providerID,
|
|
98
|
+
},
|
|
99
|
+
agent: agent.name,
|
|
100
|
+
tools: {
|
|
101
|
+
todowrite: false,
|
|
102
|
+
todoread: false,
|
|
103
|
+
task: false,
|
|
104
|
+
...Object.fromEntries((config.experimental?.primary_tools ?? []).map((t) => [t, false])),
|
|
105
|
+
...agent.tools,
|
|
106
|
+
},
|
|
107
|
+
parts: promptParts,
|
|
108
|
+
})
|
|
109
|
+
unsub()
|
|
110
|
+
const messages = await Session.messages({ sessionID: session.id })
|
|
111
|
+
const summary = messages
|
|
112
|
+
.filter((x) => x.info.role === "assistant")
|
|
113
|
+
.flatMap((msg) => msg.parts.filter((x: any) => x.type === "tool") as MessageV2.ToolPart[])
|
|
114
|
+
.map((part) => ({
|
|
115
|
+
id: part.id,
|
|
116
|
+
tool: part.tool,
|
|
117
|
+
state: {
|
|
118
|
+
status: part.state.status,
|
|
119
|
+
title: part.state.status === "completed" ? part.state.title : undefined,
|
|
120
|
+
},
|
|
121
|
+
}))
|
|
122
|
+
const text = result.parts.findLast((x) => x.type === "text")?.text ?? ""
|
|
123
|
+
|
|
124
|
+
const output = text + "\n\n" + ["<task_metadata>", `session_id: ${session.id}`, "</task_metadata>"].join("\n")
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
title: params.description,
|
|
128
|
+
metadata: {
|
|
129
|
+
summary,
|
|
130
|
+
sessionId: session.id,
|
|
131
|
+
},
|
|
132
|
+
output,
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Launch a new agent to handle complex, multi-step 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 item like "class Foo", use the Glob tool instead, to find the match more quickly
|
|
14
|
+
- If you are searching 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.
|
|
21
|
+
3. Each agent invocation is stateless unless you provide a session_id. 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 make changes or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent
|
|
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
|
+
"task-reviewer": use this agent after you are done with a significant task
|
|
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 automate filling out the contact form on that website"
|
|
35
|
+
assistant: Sure let me automate filling out the contact form
|
|
36
|
+
assistant: First let me use the browser tools to navigate to the website
|
|
37
|
+
assistant: I'm going to navigate to the website and fill out the form
|
|
38
|
+
<commentary>
|
|
39
|
+
Since a significant task was completed, now use the task-reviewer agent to review the work
|
|
40
|
+
</commentary>
|
|
41
|
+
assistant: Now let me use the task-reviewer agent to review the automation
|
|
42
|
+
assistant: Uses the Task tool to launch the task-reviewer agent
|
|
43
|
+
</example>
|
|
44
|
+
|
|
45
|
+
<example>
|
|
46
|
+
user: "Hello"
|
|
47
|
+
<commentary>
|
|
48
|
+
Since the user is greeting, use the greeting-responder agent to respond with a friendly joke
|
|
49
|
+
</commentary>
|
|
50
|
+
assistant: "I'm going to use the Task tool to launch the with the greeting-responder agent"
|
|
51
|
+
</example>
|
package/src/tool/todo.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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, opts) {
|
|
12
|
+
await Todo.update({
|
|
13
|
+
sessionID: opts.sessionID,
|
|
14
|
+
todos: params.todos,
|
|
15
|
+
})
|
|
16
|
+
return {
|
|
17
|
+
title: `${params.todos.filter((x) => x.status !== "completed").length} todos`,
|
|
18
|
+
output: JSON.stringify(params.todos, null, 2),
|
|
19
|
+
metadata: {
|
|
20
|
+
todos: params.todos,
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export const TodoReadTool = Tool.define("todoread", {
|
|
27
|
+
description: "Use this tool to read your todo list",
|
|
28
|
+
parameters: z.object({}),
|
|
29
|
+
async execute(_params, opts) {
|
|
30
|
+
const todos = await Todo.get(opts.sessionID)
|
|
31
|
+
return {
|
|
32
|
+
title: `${todos.filter((x) => x.status !== "completed").length} todos`,
|
|
33
|
+
metadata: {
|
|
34
|
+
todos,
|
|
35
|
+
},
|
|
36
|
+
output: JSON.stringify(todos, null, 2),
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
})
|
|
@@ -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
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Use this tool to create and manage a structured task list for your current session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
|
|
2
|
+
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
3
|
+
|
|
4
|
+
## When to Use This Tool
|
|
5
|
+
Use this tool proactively in these scenarios:
|
|
6
|
+
|
|
7
|
+
1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
|
|
8
|
+
2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
|
|
9
|
+
3. User explicitly requests todo list - When the user directly asks you to use the todo list
|
|
10
|
+
4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
|
|
11
|
+
5. After receiving new instructions - Immediately capture user requirements as todos. Feel free to edit the todo list based on new information.
|
|
12
|
+
6. After completing a task - Mark it complete and add any new follow-up tasks
|
|
13
|
+
7. When you start working on a new task, mark the todo as in_progress. Ideally you should only have one todo as in_progress at a time. Complete existing tasks before starting new ones.
|
|
14
|
+
|
|
15
|
+
## When NOT to Use This Tool
|
|
16
|
+
|
|
17
|
+
Skip using this tool when:
|
|
18
|
+
1. There is only a single, straightforward task
|
|
19
|
+
2. The task is trivial and tracking it provides no organizational benefit
|
|
20
|
+
3. The task can be completed in less than 3 trivial steps
|
|
21
|
+
4. The task is purely conversational or informational
|
|
22
|
+
|
|
23
|
+
NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
|
|
24
|
+
|
|
25
|
+
## Examples of When to Use the Todo List
|
|
26
|
+
|
|
27
|
+
<example>
|
|
28
|
+
User: I want to add a dark mode toggle to the application settings. Make sure you run the tests and build when you're done!
|
|
29
|
+
Assistant: I'll help add a dark mode toggle to your application settings. Let me create a todo list to track this implementation.
|
|
30
|
+
*Creates todo list with the following items:*
|
|
31
|
+
1. Create dark mode toggle component in Settings page
|
|
32
|
+
2. Add dark mode state management (context/store)
|
|
33
|
+
3. Implement CSS-in-JS styles for dark theme
|
|
34
|
+
4. Update existing components to support theme switching
|
|
35
|
+
5. Run tests and build process, addressing any failures or errors that occur
|
|
36
|
+
*Begins working on the first task*
|
|
37
|
+
|
|
38
|
+
<reasoning>
|
|
39
|
+
The assistant used the todo list because:
|
|
40
|
+
1. Adding dark mode is a multi-step feature requiring UI, state management, and styling changes
|
|
41
|
+
2. The user explicitly requested tests and build be run afterward
|
|
42
|
+
3. The assistant inferred that tests and build need to pass by adding "Ensure tests and build succeed" as the final task
|
|
43
|
+
</reasoning>
|
|
44
|
+
</example>
|
|
45
|
+
|
|
46
|
+
<example>
|
|
47
|
+
User: Help me rename the function getCwd to getCurrentWorkingDirectory across my project
|
|
48
|
+
Assistant: Let me first search through your codebase to find all occurrences of 'getCwd'.
|
|
49
|
+
*Uses grep or search tools to locate all instances of getCwd in the codebase*
|
|
50
|
+
Assistant: I've found 15 instances of 'getCwd' across 8 different files. Let me create a todo list to track these changes.
|
|
51
|
+
*Creates todo list with specific items for each file that needs updating*
|
|
52
|
+
|
|
53
|
+
<reasoning>
|
|
54
|
+
The assistant used the todo list because:
|
|
55
|
+
1. First, the assistant searched to understand the scope of the task
|
|
56
|
+
2. Upon finding multiple occurrences across different files, it determined this was a complex task with multiple steps
|
|
57
|
+
3. The todo list helps ensure every instance is tracked and updated systematically
|
|
58
|
+
4. This approach prevents missing any occurrences and maintains code consistency
|
|
59
|
+
</reasoning>
|
|
60
|
+
</example>
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
<example>
|
|
64
|
+
User: I need to implement these features for my e-commerce site: user registration, product catalog, shopping cart, and checkout flow.
|
|
65
|
+
Assistant: I'll help implement these features. First, let's add all the features to the todo list.
|
|
66
|
+
*Creates a todo list breaking down each feature into specific tasks based on the project architecture*
|
|
67
|
+
Assistant: Let's start with user registration. This will involve creating database models, API endpoints, and frontend forms that integrate with your existing authentication system.
|
|
68
|
+
|
|
69
|
+
<reasoning>
|
|
70
|
+
The assistant used the todo list because:
|
|
71
|
+
1. The user provided multiple complex features to implement in a comma separated list
|
|
72
|
+
2. The todo list helps organize these large features into manageable tasks
|
|
73
|
+
3. This approach allows for tracking progress across the entire implementation
|
|
74
|
+
</reasoning>
|
|
75
|
+
</example>
|
|
76
|
+
|
|
77
|
+
<example>
|
|
78
|
+
User: Can you help optimize my React application? It's rendering slowly and has performance issues.</user>
|
|
79
|
+
Assistant: I'll help optimize your React application. First, let me examine your codebase to identify potential performance bottlenecks.
|
|
80
|
+
*Reviews component structure, render patterns, state management, and data fetching*
|
|
81
|
+
Assistant: After analyzing your codebase, I've identified several performance issues. Let me create a todo list to track our optimization efforts.
|
|
82
|
+
*Creates todo list with items like: 1) Implement memoization for expensive calculations in ProductList, 2) Add virtualization for long lists in Dashboard, 3) Optimize image loading in Gallery component, 4) Fix state update loops in ShoppingCart, 5) Review bundle size and implement code splitting*
|
|
83
|
+
Let's start by implementing memoization for the expensive calculations in your ProductList component.</assistant>
|
|
84
|
+
|
|
85
|
+
<reasoning>
|
|
86
|
+
The assistant used the todo list because:
|
|
87
|
+
1. First, the assistant examined the codebase to identify specific performance issues
|
|
88
|
+
2. Based on this analysis, it identified multiple optimization opportunities
|
|
89
|
+
3. Performance optimization is a non-trivial task requiring multiple steps
|
|
90
|
+
4. The todo list helps methodically track improvements across different components
|
|
91
|
+
5. This systematic approach ensures all performance bottlenecks are addressed
|
|
92
|
+
</reasoning>
|
|
93
|
+
</example>
|
|
94
|
+
|
|
95
|
+
## Examples of When NOT to Use the Todo List
|
|
96
|
+
|
|
97
|
+
<example>
|
|
98
|
+
User: How do I print 'Hello World' in Python?
|
|
99
|
+
Assistant: In Python, you can print "Hello World" with this simple code:
|
|
100
|
+
|
|
101
|
+
python
|
|
102
|
+
print("Hello World")
|
|
103
|
+
|
|
104
|
+
This will output the text "Hello World" to the console when executed.</assistant>
|
|
105
|
+
|
|
106
|
+
<reasoning>
|
|
107
|
+
The assistant did not use the todo list because this is a single, trivial task that can be completed in one step. There's no need to track multiple tasks or steps for such a straightforward request.
|
|
108
|
+
</reasoning>
|
|
109
|
+
</example>
|
|
110
|
+
|
|
111
|
+
<example>
|
|
112
|
+
User: What does the git status command do?
|
|
113
|
+
Assistant: The git status command shows the current state of your working directory and staging area. It displays which changes have been staged, which haven't, and which files aren't being tracked by Git. This is a fundamental command for understanding the current state of your repository before making commits.
|
|
114
|
+
|
|
115
|
+
<reasoning>
|
|
116
|
+
The assistant did not use the todo list because this is an informational request with no actual task to complete. The user is simply asking for an explanation, not for the assistant to perform multiple steps or tasks.
|
|
117
|
+
</reasoning>
|
|
118
|
+
</example>
|
|
119
|
+
|
|
120
|
+
<example>
|
|
121
|
+
User: Can you add a comment to the calculateTotal function to explain what it does?
|
|
122
|
+
Assistant: Sure, let me add a comment to the calculateTotal function to explain what it does.
|
|
123
|
+
* Uses the Edit tool to add a comment to the calculateTotal function *
|
|
124
|
+
|
|
125
|
+
<reasoning>
|
|
126
|
+
The assistant did not use the todo list because this is a single, straightforward task confined to one location in the code. Adding a comment doesn't require tracking multiple steps or systematic organization.
|
|
127
|
+
</reasoning>
|
|
128
|
+
</example>
|
|
129
|
+
|
|
130
|
+
<example>
|
|
131
|
+
User: Run npm install for me and tell me what happens.
|
|
132
|
+
Assistant: I'll run the npm install command for you.
|
|
133
|
+
|
|
134
|
+
*Executes: npm install*
|
|
135
|
+
|
|
136
|
+
The command completed successfully. Here's the output:
|
|
137
|
+
[Output of npm install command]
|
|
138
|
+
|
|
139
|
+
All dependencies have been installed according to your package.json file.
|
|
140
|
+
|
|
141
|
+
<reasoning>
|
|
142
|
+
The assistant did not use the todo list because this is a single command execution with immediate results. There are no multiple steps to track or organize, making the todo list unnecessary for this straightforward task.
|
|
143
|
+
</reasoning>
|
|
144
|
+
</example>
|
|
145
|
+
|
|
146
|
+
## Task States and Management
|
|
147
|
+
|
|
148
|
+
1. **Task States**: Use these states to track progress:
|
|
149
|
+
- pending: Task not yet started
|
|
150
|
+
- in_progress: Currently working on (limit to ONE task at a time)
|
|
151
|
+
- completed: Task finished successfully
|
|
152
|
+
- cancelled: Task no longer needed
|
|
153
|
+
|
|
154
|
+
2. **Task Management**:
|
|
155
|
+
- Update task status in real-time as you work
|
|
156
|
+
- Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
|
|
157
|
+
- Only have ONE task in_progress at any time
|
|
158
|
+
- Complete current tasks before starting new ones
|
|
159
|
+
- Cancel tasks that become irrelevant
|
|
160
|
+
|
|
161
|
+
3. **Task Breakdown**:
|
|
162
|
+
- Create specific, actionable items
|
|
163
|
+
- Break complex tasks into smaller, manageable steps
|
|
164
|
+
- Use clear, descriptive task names
|
|
165
|
+
|
|
166
|
+
When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.
|
|
167
|
+
|
package/src/tool/tool.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
import type { MessageV2 } from "../session/message-v2"
|
|
3
|
+
import type { Agent } from "../agent/agent"
|
|
4
|
+
|
|
5
|
+
export namespace Tool {
|
|
6
|
+
interface Metadata {
|
|
7
|
+
[key: string]: any
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface InitContext {
|
|
11
|
+
agent?: Agent.Info
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type Context<M extends Metadata = Metadata> = {
|
|
15
|
+
sessionID: string
|
|
16
|
+
messageID: string
|
|
17
|
+
agent: string
|
|
18
|
+
abort: AbortSignal
|
|
19
|
+
callID?: string
|
|
20
|
+
extra?: { [key: string]: any }
|
|
21
|
+
metadata(input: { title?: string; metadata?: M }): void
|
|
22
|
+
}
|
|
23
|
+
export interface Info<Parameters extends z.ZodType = z.ZodType, M extends Metadata = Metadata> {
|
|
24
|
+
id: string
|
|
25
|
+
init: (ctx?: InitContext) => Promise<{
|
|
26
|
+
description: string
|
|
27
|
+
parameters: Parameters
|
|
28
|
+
execute(
|
|
29
|
+
args: z.infer<Parameters>,
|
|
30
|
+
ctx: Context,
|
|
31
|
+
): Promise<{
|
|
32
|
+
title: string
|
|
33
|
+
metadata: M
|
|
34
|
+
output: string
|
|
35
|
+
attachments?: MessageV2.FilePart[]
|
|
36
|
+
}>
|
|
37
|
+
formatValidationError?(error: z.ZodError): string
|
|
38
|
+
}>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type InferParameters<T extends Info> = T extends Info<infer P> ? z.infer<P> : never
|
|
42
|
+
export type InferMetadata<T extends Info> = T extends Info<any, infer M> ? M : never
|
|
43
|
+
|
|
44
|
+
export function define<Parameters extends z.ZodType, Result extends Metadata>(
|
|
45
|
+
id: string,
|
|
46
|
+
init: Info<Parameters, Result>["init"] | Awaited<ReturnType<Info<Parameters, Result>["init"]>>,
|
|
47
|
+
): Info<Parameters, Result> {
|
|
48
|
+
return {
|
|
49
|
+
id,
|
|
50
|
+
init: async (ctx) => {
|
|
51
|
+
const toolInfo = init instanceof Function ? await init(ctx) : init
|
|
52
|
+
const execute = toolInfo.execute
|
|
53
|
+
toolInfo.execute = (args, ctx) => {
|
|
54
|
+
try {
|
|
55
|
+
toolInfo.parameters.parse(args)
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error instanceof z.ZodError && toolInfo.formatValidationError) {
|
|
58
|
+
throw new Error(toolInfo.formatValidationError(error), { cause: error })
|
|
59
|
+
}
|
|
60
|
+
throw new Error(
|
|
61
|
+
`The ${id} tool was called with invalid arguments: ${error}.\nPlease rewrite the input so it satisfies the expected schema.`,
|
|
62
|
+
{ cause: error },
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
return execute(args, ctx)
|
|
66
|
+
}
|
|
67
|
+
return toolInfo
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|