@link-assistant/agent 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/EXAMPLES.md +383 -0
  2. package/LICENSE +24 -0
  3. package/MODELS.md +95 -0
  4. package/README.md +388 -0
  5. package/TOOLS.md +134 -0
  6. package/package.json +89 -0
  7. package/src/agent/agent.ts +150 -0
  8. package/src/agent/generate.txt +75 -0
  9. package/src/auth/index.ts +64 -0
  10. package/src/bun/index.ts +96 -0
  11. package/src/bus/global.ts +10 -0
  12. package/src/bus/index.ts +119 -0
  13. package/src/cli/bootstrap.js +41 -0
  14. package/src/cli/bootstrap.ts +17 -0
  15. package/src/cli/cmd/agent.ts +165 -0
  16. package/src/cli/cmd/cmd.ts +5 -0
  17. package/src/cli/cmd/export.ts +88 -0
  18. package/src/cli/cmd/mcp.ts +80 -0
  19. package/src/cli/cmd/models.ts +58 -0
  20. package/src/cli/cmd/run.ts +359 -0
  21. package/src/cli/cmd/stats.ts +276 -0
  22. package/src/cli/error.ts +27 -0
  23. package/src/command/index.ts +73 -0
  24. package/src/command/template/initialize.txt +10 -0
  25. package/src/config/config.ts +705 -0
  26. package/src/config/markdown.ts +41 -0
  27. package/src/file/ripgrep.ts +391 -0
  28. package/src/file/time.ts +38 -0
  29. package/src/file/watcher.ts +75 -0
  30. package/src/file.ts +6 -0
  31. package/src/flag/flag.ts +19 -0
  32. package/src/format/formatter.ts +248 -0
  33. package/src/format/index.ts +137 -0
  34. package/src/global/index.ts +52 -0
  35. package/src/id/id.ts +72 -0
  36. package/src/index.js +371 -0
  37. package/src/mcp/index.ts +289 -0
  38. package/src/patch/index.ts +622 -0
  39. package/src/project/bootstrap.ts +22 -0
  40. package/src/project/instance.ts +67 -0
  41. package/src/project/project.ts +105 -0
  42. package/src/project/state.ts +65 -0
  43. package/src/provider/models-macro.ts +11 -0
  44. package/src/provider/models.ts +98 -0
  45. package/src/provider/opencode.js +47 -0
  46. package/src/provider/provider.ts +636 -0
  47. package/src/provider/transform.ts +241 -0
  48. package/src/server/project.ts +48 -0
  49. package/src/server/server.ts +249 -0
  50. package/src/session/agent.js +204 -0
  51. package/src/session/compaction.ts +249 -0
  52. package/src/session/index.ts +380 -0
  53. package/src/session/message-v2.ts +758 -0
  54. package/src/session/message.ts +189 -0
  55. package/src/session/processor.ts +356 -0
  56. package/src/session/prompt/anthropic-20250930.txt +166 -0
  57. package/src/session/prompt/anthropic.txt +105 -0
  58. package/src/session/prompt/anthropic_spoof.txt +1 -0
  59. package/src/session/prompt/beast.txt +147 -0
  60. package/src/session/prompt/build-switch.txt +5 -0
  61. package/src/session/prompt/codex.txt +318 -0
  62. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  63. package/src/session/prompt/gemini.txt +155 -0
  64. package/src/session/prompt/grok-code.txt +1 -0
  65. package/src/session/prompt/plan.txt +8 -0
  66. package/src/session/prompt/polaris.txt +107 -0
  67. package/src/session/prompt/qwen.txt +109 -0
  68. package/src/session/prompt/summarize-turn.txt +5 -0
  69. package/src/session/prompt/summarize.txt +10 -0
  70. package/src/session/prompt/title.txt +25 -0
  71. package/src/session/prompt.ts +1390 -0
  72. package/src/session/retry.ts +53 -0
  73. package/src/session/revert.ts +108 -0
  74. package/src/session/status.ts +75 -0
  75. package/src/session/summary.ts +179 -0
  76. package/src/session/system.ts +138 -0
  77. package/src/session/todo.ts +36 -0
  78. package/src/snapshot/index.ts +197 -0
  79. package/src/storage/storage.ts +226 -0
  80. package/src/tool/bash.ts +193 -0
  81. package/src/tool/bash.txt +121 -0
  82. package/src/tool/batch.ts +173 -0
  83. package/src/tool/batch.txt +28 -0
  84. package/src/tool/codesearch.ts +123 -0
  85. package/src/tool/codesearch.txt +12 -0
  86. package/src/tool/edit.ts +604 -0
  87. package/src/tool/edit.txt +10 -0
  88. package/src/tool/glob.ts +65 -0
  89. package/src/tool/glob.txt +6 -0
  90. package/src/tool/grep.ts +116 -0
  91. package/src/tool/grep.txt +8 -0
  92. package/src/tool/invalid.ts +17 -0
  93. package/src/tool/ls.ts +110 -0
  94. package/src/tool/ls.txt +1 -0
  95. package/src/tool/multiedit.ts +46 -0
  96. package/src/tool/multiedit.txt +41 -0
  97. package/src/tool/patch.ts +188 -0
  98. package/src/tool/patch.txt +1 -0
  99. package/src/tool/read.ts +201 -0
  100. package/src/tool/read.txt +12 -0
  101. package/src/tool/registry.ts +87 -0
  102. package/src/tool/task.ts +126 -0
  103. package/src/tool/task.txt +60 -0
  104. package/src/tool/todo.ts +39 -0
  105. package/src/tool/todoread.txt +14 -0
  106. package/src/tool/todowrite.txt +167 -0
  107. package/src/tool/tool.ts +66 -0
  108. package/src/tool/webfetch.ts +171 -0
  109. package/src/tool/webfetch.txt +14 -0
  110. package/src/tool/websearch.ts +133 -0
  111. package/src/tool/websearch.txt +11 -0
  112. package/src/tool/write.ts +33 -0
  113. package/src/tool/write.txt +8 -0
  114. package/src/util/binary.ts +41 -0
  115. package/src/util/context.ts +25 -0
  116. package/src/util/defer.ts +12 -0
  117. package/src/util/error.ts +54 -0
  118. package/src/util/eventloop.ts +20 -0
  119. package/src/util/filesystem.ts +69 -0
  120. package/src/util/fn.ts +11 -0
  121. package/src/util/iife.ts +3 -0
  122. package/src/util/keybind.ts +79 -0
  123. package/src/util/lazy.ts +11 -0
  124. package/src/util/locale.ts +39 -0
  125. package/src/util/lock.ts +98 -0
  126. package/src/util/log.ts +177 -0
  127. package/src/util/queue.ts +19 -0
  128. package/src/util/rpc.ts +42 -0
  129. package/src/util/scrap.ts +10 -0
  130. package/src/util/signal.ts +12 -0
  131. package/src/util/timeout.ts +14 -0
  132. package/src/util/token.ts +7 -0
  133. package/src/util/wildcard.ts +54 -0
@@ -0,0 +1,201 @@
1
+ import z from "zod"
2
+ import * as fs from "fs"
3
+ import * as path from "path"
4
+ import { Tool } from "./tool"
5
+ import { FileTime } from "../file/time"
6
+ import DESCRIPTION from "./read.txt"
7
+ import { Filesystem } from "../util/filesystem"
8
+ import { Instance } from "../project/instance"
9
+ import { Provider } from "../provider/provider"
10
+ import { Identifier } from "../id/id"
11
+ import { iife } from "../util/iife"
12
+
13
+ const DEFAULT_READ_LIMIT = 2000
14
+ const MAX_LINE_LENGTH = 2000
15
+
16
+ export const ReadTool = Tool.define("read", {
17
+ description: DESCRIPTION,
18
+ parameters: z.object({
19
+ filePath: z.string().describe("The path to the file to read"),
20
+ offset: z.coerce.number().describe("The line number to start reading from (0-based)").optional(),
21
+ limit: z.coerce.number().describe("The number of lines to read (defaults to 2000)").optional(),
22
+ }),
23
+ async execute(params, ctx) {
24
+ let filepath = params.filePath
25
+ if (!path.isAbsolute(filepath)) {
26
+ filepath = path.join(process.cwd(), filepath)
27
+ }
28
+ const title = path.relative(Instance.worktree, filepath)
29
+
30
+ // No restrictions - unrestricted file read
31
+ const file = Bun.file(filepath)
32
+ if (!(await file.exists())) {
33
+ const dir = path.dirname(filepath)
34
+ const base = path.basename(filepath)
35
+
36
+ const dirEntries = fs.readdirSync(dir)
37
+ const suggestions = dirEntries
38
+ .filter(
39
+ (entry) =>
40
+ entry.toLowerCase().includes(base.toLowerCase()) || base.toLowerCase().includes(entry.toLowerCase()),
41
+ )
42
+ .map((entry) => path.join(dir, entry))
43
+ .slice(0, 3)
44
+
45
+ if (suggestions.length > 0) {
46
+ throw new Error(`File not found: ${filepath}\n\nDid you mean one of these?\n${suggestions.join("\n")}`)
47
+ }
48
+
49
+ throw new Error(`File not found: ${filepath}`)
50
+ }
51
+
52
+ const isImage = isImageFile(filepath)
53
+ const supportsImages = await (async () => {
54
+ if (!ctx.extra?.["providerID"] || !ctx.extra?.["modelID"]) return false
55
+ const providerID = ctx.extra["providerID"] as string
56
+ const modelID = ctx.extra["modelID"] as string
57
+ const model = await Provider.getModel(providerID, modelID).catch(() => undefined)
58
+ if (!model) return false
59
+ return model.info.modalities?.input?.includes("image") ?? false
60
+ })()
61
+ if (isImage) {
62
+ if (!supportsImages) {
63
+ throw new Error(`Failed to read image: ${filepath}, model may not be able to read images`)
64
+ }
65
+ const mime = file.type
66
+ const msg = "Image read successfully"
67
+ return {
68
+ title,
69
+ output: msg,
70
+ metadata: {
71
+ preview: msg,
72
+ },
73
+ attachments: [
74
+ {
75
+ id: Identifier.ascending("part"),
76
+ sessionID: ctx.sessionID,
77
+ messageID: ctx.messageID,
78
+ type: "file",
79
+ mime,
80
+ url: `data:${mime};base64,${Buffer.from(await file.bytes()).toString("base64")}`,
81
+ },
82
+ ],
83
+ }
84
+ }
85
+
86
+ const isBinary = await isBinaryFile(filepath, file)
87
+ if (isBinary) throw new Error(`Cannot read binary file: ${filepath}`)
88
+
89
+ const limit = params.limit ?? DEFAULT_READ_LIMIT
90
+ const offset = params.offset || 0
91
+ const lines = await file.text().then((text) => text.split("\n"))
92
+ const raw = lines.slice(offset, offset + limit).map((line) => {
93
+ return line.length > MAX_LINE_LENGTH ? line.substring(0, MAX_LINE_LENGTH) + "..." : line
94
+ })
95
+ const content = raw.map((line, index) => {
96
+ return `${(index + offset + 1).toString().padStart(5, "0")}| ${line}`
97
+ })
98
+ const preview = raw.slice(0, 20).join("\n")
99
+
100
+ let output = "<file>\n"
101
+ output += content.join("\n")
102
+
103
+ const totalLines = lines.length
104
+ const lastReadLine = offset + content.length
105
+ const hasMoreLines = totalLines > lastReadLine
106
+
107
+ if (hasMoreLines) {
108
+ output += `\n\n(File has more lines. Use 'offset' parameter to read beyond line ${lastReadLine})`
109
+ } else {
110
+ output += `\n\n(End of file - total ${totalLines} lines)`
111
+ }
112
+ output += "\n</file>"
113
+
114
+ // just warms the lsp client
115
+ FileTime.read(ctx.sessionID, filepath)
116
+
117
+ return {
118
+ title,
119
+ output,
120
+ metadata: {
121
+ preview,
122
+ },
123
+ }
124
+ },
125
+ })
126
+
127
+ function isImageFile(filePath: string): string | false {
128
+ const ext = path.extname(filePath).toLowerCase()
129
+ switch (ext) {
130
+ case ".jpg":
131
+ case ".jpeg":
132
+ return "JPEG"
133
+ case ".png":
134
+ return "PNG"
135
+ case ".gif":
136
+ return "GIF"
137
+ case ".bmp":
138
+ return "BMP"
139
+ case ".webp":
140
+ return "WebP"
141
+ default:
142
+ return false
143
+ }
144
+ }
145
+
146
+ async function isBinaryFile(filepath: string, file: Bun.BunFile): Promise<boolean> {
147
+ const ext = path.extname(filepath).toLowerCase()
148
+ // binary check for common non-text extensions
149
+ switch (ext) {
150
+ case ".zip":
151
+ case ".tar":
152
+ case ".gz":
153
+ case ".exe":
154
+ case ".dll":
155
+ case ".so":
156
+ case ".class":
157
+ case ".jar":
158
+ case ".war":
159
+ case ".7z":
160
+ case ".doc":
161
+ case ".docx":
162
+ case ".xls":
163
+ case ".xlsx":
164
+ case ".ppt":
165
+ case ".pptx":
166
+ case ".odt":
167
+ case ".ods":
168
+ case ".odp":
169
+ case ".bin":
170
+ case ".dat":
171
+ case ".obj":
172
+ case ".o":
173
+ case ".a":
174
+ case ".lib":
175
+ case ".wasm":
176
+ case ".pyc":
177
+ case ".pyo":
178
+ return true
179
+ default:
180
+ break
181
+ }
182
+
183
+ const stat = await file.stat()
184
+ const fileSize = stat.size
185
+ if (fileSize === 0) return false
186
+
187
+ const bufferSize = Math.min(4096, fileSize)
188
+ const buffer = await file.arrayBuffer()
189
+ if (buffer.byteLength === 0) return false
190
+ const bytes = new Uint8Array(buffer.slice(0, bufferSize))
191
+
192
+ let nonPrintableCount = 0
193
+ for (let i = 0; i < bytes.length; i++) {
194
+ if (bytes[i] === 0) return true
195
+ if (bytes[i] < 9 || (bytes[i] > 13 && bytes[i] < 32)) {
196
+ nonPrintableCount++
197
+ }
198
+ }
199
+ // If >30% non-printable characters, consider it binary
200
+ return nonPrintableCount / bytes.length > 0.3
201
+ }
@@ -0,0 +1,12 @@
1
+ Reads a file from the local filesystem. You can access any file directly by using this tool.
2
+ Assume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.
3
+
4
+ Usage:
5
+ - The filePath parameter must be an absolute path, not a relative path
6
+ - By default, it reads up to 2000 lines starting from the beginning of the file
7
+ - You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters
8
+ - Any lines longer than 2000 characters will be truncated
9
+ - Results are returned using cat -n format, with line numbers starting at 1
10
+ - You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.
11
+ - If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.
12
+ - You can read image files using this tool.
@@ -0,0 +1,87 @@
1
+ import { BashTool } from "./bash"
2
+ import { EditTool } from "./edit"
3
+ import { GlobTool } from "./glob"
4
+ import { GrepTool } from "./grep"
5
+ import { ListTool } from "./ls"
6
+ import { BatchTool } from "./batch"
7
+ import { ReadTool } from "./read"
8
+ import { TaskTool } from "./task"
9
+ import { TodoWriteTool, TodoReadTool } from "./todo"
10
+ import { WebFetchTool } from "./webfetch"
11
+ import { WriteTool } from "./write"
12
+ import { InvalidTool } from "./invalid"
13
+ import type { Agent } from "../agent/agent"
14
+ import { Tool } from "./tool"
15
+ import { Instance } from "../project/instance"
16
+ import { Config } from "../config/config"
17
+ import { WebSearchTool } from "./websearch"
18
+ import { CodeSearchTool } from "./codesearch"
19
+ import { Flag } from "../flag/flag"
20
+
21
+ export namespace ToolRegistry {
22
+ export const state = Instance.state(async () => {
23
+ const custom = [] as Tool.Info[]
24
+ return { custom }
25
+ })
26
+
27
+ export async function register(tool: Tool.Info) {
28
+ const { custom } = await state()
29
+ const idx = custom.findIndex((t) => t.id === tool.id)
30
+ if (idx >= 0) {
31
+ custom.splice(idx, 1, tool)
32
+ return
33
+ }
34
+ custom.push(tool)
35
+ }
36
+
37
+ async function all(): Promise<Tool.Info[]> {
38
+ const custom = await state().then((x) => x.custom)
39
+ const config = await Config.get()
40
+
41
+ return [
42
+ InvalidTool,
43
+ BashTool,
44
+ ReadTool,
45
+ GlobTool,
46
+ GrepTool,
47
+ ListTool,
48
+ EditTool,
49
+ WriteTool,
50
+ TaskTool,
51
+ WebFetchTool,
52
+ WebSearchTool,
53
+ CodeSearchTool,
54
+ BatchTool,
55
+ TodoWriteTool,
56
+ TodoReadTool,
57
+ ...custom,
58
+ ]
59
+ }
60
+
61
+ export async function ids() {
62
+ return all().then((x) => x.map((t) => t.id))
63
+ }
64
+
65
+ export async function tools(_providerID: string, _modelID: string) {
66
+ const tools = await all()
67
+ const result = await Promise.all(
68
+ tools.map(async (t) => ({
69
+ id: t.id,
70
+ ...(await t.init()),
71
+ })),
72
+ )
73
+ return result
74
+ }
75
+
76
+ export async function enabled(
77
+ _providerID: string,
78
+ _modelID: string,
79
+ agent: Agent.Info,
80
+ ): Promise<Record<string, boolean>> {
81
+ const result: Record<string, boolean> = {}
82
+
83
+ // Permission system removed - all tools enabled by default
84
+
85
+ return result
86
+ }
87
+ }
@@ -0,0 +1,126 @@
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
+
13
+ export const TaskTool = Tool.define("task", async () => {
14
+ const agents = await Agent.list().then((x) => x.filter((a) => a.mode !== "primary"))
15
+ const description = DESCRIPTION.replace(
16
+ "{agents}",
17
+ agents
18
+ .map((a) => `- ${a.name}: ${a.description ?? "This subagent should only be called manually by the user."}`)
19
+ .join("\n"),
20
+ )
21
+ return {
22
+ description,
23
+ parameters: z.object({
24
+ description: z.string().describe("A short (3-5 words) description of the task"),
25
+ prompt: z.string().describe("The task for the agent to perform"),
26
+ subagent_type: z.string().describe("The type of specialized agent to use for this task"),
27
+ session_id: z.string().describe("Existing Task session to continue").optional(),
28
+ }),
29
+ async execute(params, ctx) {
30
+ const agent = await Agent.get(params.subagent_type)
31
+ if (!agent) throw new Error(`Unknown agent type: ${params.subagent_type} is not a valid agent type`)
32
+ const session = await iife(async () => {
33
+ if (params.session_id) {
34
+ const found = await Session.get(params.session_id).catch(() => {})
35
+ if (found) return found
36
+ }
37
+
38
+ return await Session.create({
39
+ parentID: ctx.sessionID,
40
+ title: params.description + ` (@${agent.name} subagent)`,
41
+ })
42
+ })
43
+ // Try to get parent message for model info, but use defaults if not available
44
+ let parentModel: { modelID: string; providerID: string } | undefined
45
+ try {
46
+ const msg = await MessageV2.get({ sessionID: ctx.sessionID, messageID: ctx.messageID })
47
+ if (msg.info.role === "assistant") {
48
+ parentModel = {
49
+ modelID: msg.info.modelID,
50
+ providerID: msg.info.providerID,
51
+ }
52
+ }
53
+ } catch (e) {
54
+ // Parent message not in storage, will use agent model or default
55
+ }
56
+
57
+ ctx.metadata({
58
+ title: params.description,
59
+ metadata: {
60
+ sessionId: session.id,
61
+ },
62
+ })
63
+
64
+ const messageID = Identifier.ascending("message")
65
+ const parts: Record<string, MessageV2.ToolPart> = {}
66
+ const unsub = Bus.subscribe(MessageV2.Event.PartUpdated, async (evt) => {
67
+ if (evt.properties.part.sessionID !== session.id) return
68
+ if (evt.properties.part.messageID === messageID) return
69
+ if (evt.properties.part.type !== "tool") return
70
+ parts[evt.properties.part.id] = evt.properties.part
71
+ ctx.metadata({
72
+ title: params.description,
73
+ metadata: {
74
+ summary: Object.values(parts).sort((a, b) => a.id?.localeCompare(b.id)),
75
+ sessionId: session.id,
76
+ },
77
+ })
78
+ })
79
+
80
+ const model = agent.model ?? parentModel ?? {
81
+ modelID: "grok-code",
82
+ providerID: "opencode",
83
+ }
84
+
85
+ function cancel() {
86
+ SessionPrompt.cancel(session.id)
87
+ }
88
+ ctx.abort.addEventListener("abort", cancel)
89
+ using _ = defer(() => ctx.abort.removeEventListener("abort", cancel))
90
+ const promptParts = await SessionPrompt.resolvePromptParts(params.prompt)
91
+ const result = await SessionPrompt.prompt({
92
+ messageID,
93
+ sessionID: session.id,
94
+ model: {
95
+ modelID: model.modelID,
96
+ providerID: model.providerID,
97
+ },
98
+ agent: agent.name,
99
+ tools: {
100
+ todowrite: false,
101
+ todoread: false,
102
+ task: false,
103
+ ...agent.tools,
104
+ },
105
+ parts: promptParts,
106
+ })
107
+ unsub()
108
+ let all
109
+ all = await Session.messages({ sessionID: session.id })
110
+ all = all.filter((x) => x.info.role === "assistant")
111
+ all = all.flatMap((msg) => msg.parts.filter((x: any) => x.type === "tool") as MessageV2.ToolPart[])
112
+ const text = result.parts.findLast((x) => x.type === "text")?.text ?? ""
113
+
114
+ const output = text + "\n\n" + ["<task_metadata>", `session_id: ${session.id}`, "</task_metadata>"].join("\n")
115
+
116
+ return {
117
+ title: params.description,
118
+ metadata: {
119
+ summary: all,
120
+ sessionId: session.id,
121
+ },
122
+ output,
123
+ }
124
+ },
125
+ }
126
+ })
@@ -0,0 +1,60 @@
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 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.
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 write code 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
+ "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>
@@ -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