mini-coder 0.6.0 → 0.6.2

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/src/tool-task.ts DELETED
@@ -1,114 +0,0 @@
1
- import { type Message, type Tool, Type } from "@mariozechner/pi-ai";
2
- import { streamAgent } from "./agent";
3
- import { buildSystemPrompt, TASK_PROMPT } from "./prompt";
4
- import { estimateTokens, formatTimestamp } from "./shared";
5
- import { bash, runBashTool } from "./tool-bash";
6
- import { edit, runEditTool } from "./tool-edit";
7
- import type {
8
- AgentContex,
9
- CliOptions,
10
- ToolAndRunner,
11
- ToolRunnerEvent,
12
- } from "./types";
13
-
14
- const description = `## Task tool
15
-
16
- Use this tool for multi-step work that would otherwise require multiple individual tool calls. The tool executes a detailed plan and returns results.
17
-
18
- Best practices:
19
-
20
- - For exploration (codebase, filesystem, web), specify exactly what you are looking for and the expected output format. For example: "Find all files relevant to tests. Return the exact paths and a description of each file."
21
- - For edits, specify exact diffs and the target file for each change.
22
- - For anything else, provide a specific, detailed set of instructions and your expected results.
23
- `;
24
-
25
- export const task: Tool = {
26
- name: "task",
27
- description,
28
- parameters: Type.Object({
29
- prompt: Type.String({
30
- description:
31
- "Detailed description of the work to perform. Be specific about expected outputs and any constraints.",
32
- }),
33
- }),
34
- };
35
-
36
- export async function* runTaskTool(
37
- options: CliOptions,
38
- args: Record<string, any>,
39
- signal?: AbortSignal,
40
- ): AsyncGenerator<ToolRunnerEvent> {
41
- const tools: ToolAndRunner[] = [
42
- { tool: bash, runner: runBashTool },
43
- { tool: edit, runner: runEditTool },
44
- ];
45
- const messages: Message[] = [
46
- { role: "user", content: args.prompt || "", timestamp: Date.now() },
47
- ];
48
-
49
- const systemPrompt = await buildSystemPrompt(TASK_PROMPT);
50
- const ctx: AgentContex = {
51
- systemPrompt,
52
- tools,
53
- messages,
54
- options,
55
- signal,
56
- };
57
-
58
- let output = "";
59
- const agent = streamAgent(ctx);
60
- for await (const ev of agent) {
61
- switch (ev.type) {
62
- case "message_start": {
63
- const text = `[${formatTimestamp(ev.partial.timestamp)}] Working...`;
64
- output += text;
65
- yield { type: "output", text };
66
- break;
67
- }
68
- case "message_end": {
69
- const thinking = ev.message.content
70
- .filter((b) => b.type === "thinking")
71
- .map((b) => b.thinking)
72
- .join("");
73
- const messageText = ev.message.content
74
- .filter((b) => b.type === "text")
75
- .map((b) => b.text)
76
- .join("");
77
- const calls = ev.message.content
78
- .filter((b) => b.type === "toolCall")
79
- .map((b) => b.name);
80
-
81
- let text = `[${formatTimestamp(ev.message.timestamp)}]`;
82
- if (thinking.length > 0) {
83
- const thinkingTokens = estimateTokens(thinking);
84
- text += `Thinking... (${thinkingTokens} tokens)`;
85
- }
86
- if (messageText.length > 0) {
87
- text += `\n\n${messageText}\n`;
88
- }
89
- if (calls.length > 0) {
90
- text += ` \nTool calls:`;
91
- for (const c of calls) {
92
- text += `\n${c}`;
93
- }
94
- }
95
-
96
- output += text;
97
- yield { type: "output", text };
98
- break;
99
- }
100
- case "tool_message_end": {
101
- const ts = formatTimestamp(ev.message.timestamp);
102
- const name = ev.message.toolName;
103
- const symbol = !ev.message.isError ? "✓ " : "✗ ";
104
- const text = `[${ts}] ${name} ${symbol}`;
105
-
106
- output += text;
107
- yield { type: "output", text };
108
- break;
109
- }
110
- }
111
- }
112
-
113
- yield { type: "result", text: output };
114
- }