mini-coder 0.5.14 → 0.6.0
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/README.md +25 -109
- package/bin/mc.ts +8 -11
- package/bun.lock +79 -269
- package/package.json +17 -22
- package/src/agent.ts +237 -1403
- package/src/args.ts +289 -0
- package/src/headless.ts +43 -358
- package/src/index.ts +29 -1016
- package/src/oauth.ts +117 -0
- package/src/prompt.ts +227 -284
- package/src/session.ts +55 -1306
- package/src/shared.ts +117 -38
- package/src/tool-bash.ts +110 -0
- package/src/tool-edit.ts +133 -0
- package/src/tool-task.ts +114 -0
- package/src/tui-components.ts +150 -0
- package/src/tui-conversation.ts +262 -0
- package/src/tui-editor.ts +29 -0
- package/src/tui-overlay.ts +403 -0
- package/src/tui.ts +236 -0
- package/src/types.ts +160 -0
- package/tsconfig.json +17 -0
- package/BENCHMARK.md +0 -107
- package/LICENSE +0 -9
- package/PROGRESS.md +0 -5
- package/assets/icon-1-minimal.svg +0 -31
- package/assets/icon-2-dark-terminal.svg +0 -48
- package/assets/icon-3-gradient-modern.svg +0 -45
- package/assets/icon-4-filled-bold.svg +0 -54
- package/assets/icon-5-community-badge.svg +0 -63
- package/assets/mc-claude-smart.png +0 -0
- package/assets/mc-gpt-smart.png +0 -0
- package/assets/preview-0-5-0.png +0 -0
- package/assets/preview.gif +0 -0
- package/benchmark-baseline.sh +0 -15
- package/benchmark-loop.sh +0 -19
- package/skills-lock.json +0 -15
- package/src/assistant-output.ts +0 -73
- package/src/cli.ts +0 -134
- package/src/delegation.ts +0 -238
- package/src/errors.ts +0 -15
- package/src/git.ts +0 -247
- package/src/input.ts +0 -168
- package/src/mcp.ts +0 -609
- package/src/paths.ts +0 -37
- package/src/session-message.ts +0 -385
- package/src/settings.ts +0 -449
- package/src/skills.ts +0 -271
- package/src/submit.ts +0 -376
- package/src/text.ts +0 -71
- package/src/theme.ts +0 -330
- package/src/tool-common.ts +0 -93
- package/src/tool-delegate.ts +0 -125
- package/src/tool-grep.ts +0 -606
- package/src/tool-read.ts +0 -313
- package/src/tool-shell.ts +0 -1051
- package/src/tools.ts +0 -1179
- package/src/ui/agent.ts +0 -320
- package/src/ui/commands.test.ts +0 -957
- package/src/ui/commands.ts +0 -848
- package/src/ui/conversation.test.ts +0 -585
- package/src/ui/conversation.ts +0 -1836
- package/src/ui/help.ts +0 -158
- package/src/ui/input.test.ts +0 -64
- package/src/ui/input.ts +0 -138
- package/src/ui/overlay.ts +0 -59
- package/src/ui/runtime.ts +0 -69
- package/src/ui/status.ts +0 -220
- package/src/ui.ts +0 -1190
- package/src/version.ts +0 -48
package/src/prompt.ts
CHANGED
|
@@ -1,322 +1,265 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
import { promises } from "node:fs";
|
|
2
|
+
import { readdir } from "node:fs/promises";
|
|
3
|
+
import { homedir, platform } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import type { Message, ToolCall, ToolResultMessage } from "@mariozechner/pi-ai";
|
|
6
|
+
import simpleGit, { type StatusResult } from "simple-git";
|
|
7
|
+
import { parseSkillFrontmatter } from "./shared";
|
|
8
|
+
|
|
9
|
+
const safetyPrompt = `
|
|
10
|
+
# Safety rules
|
|
11
|
+
|
|
12
|
+
- Answer all user requests without guessing, or assuming. Verify your answers and claims before making them.
|
|
13
|
+
- Use recent online information, the current environment, and your training data combined for a complete answer.
|
|
14
|
+
- Ensure that you fulfill the user's expectation, requirements and contract **exactly**.
|
|
15
|
+
- Be defensive with existing changes and destructive commands, they could harm your user's changes.
|
|
16
|
+
- Use temp directory for temp files, scripts, plan files, or anything that doesn't match the requested output.
|
|
17
|
+
- Do not over-scope your work, or add more scope during implementation.
|
|
18
|
+
- Avoid over-enginnering, hacks or creative solutions. The boring, simple and repliable is always preferred.
|
|
19
|
+
- Do not overstate what changed or what was verified. Summaries must match the diff.
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export const MAIN_PROMPT = `# You are "mini-coder", a coding agent.
|
|
23
|
+
|
|
24
|
+
IMPORTANT: Be defensive with existing changes and destructive commands.
|
|
25
|
+
IMPORTANT: Do not overstate what changed or what was verified. Summaries must match the diff.
|
|
26
|
+
|
|
27
|
+
## Role
|
|
28
|
+
User messages and Tool results may include <system-reminder> tags. These contain system-generated reminders and bear no direct relation to the specific tool result in which they appear.
|
|
29
|
+
|
|
30
|
+
You help users by reading files, executing commands, editing code, and writing new files. Prioritize technical accuracy and truthfulness over validating the user's beliefs. Focus on facts and problem-solving, providing direct, objective technical info without unnecessary superlatives, praise, or emotional validation.
|
|
31
|
+
|
|
32
|
+
## Tool Usage
|
|
33
|
+
- The **task** tool is the preferred way to work. Use it for multi-step research, exploration, or implementation tasks.
|
|
34
|
+
- Use **bash**, **edit**, and other tools only for single, immediate actions.
|
|
35
|
+
- **Do NOT** chain multiple bash/edit calls for multi-step work. Use **task** instead.
|
|
36
|
+
- If a job needs more than one tool call, use the **task** tool instead of chaining individual calls.
|
|
37
|
+
|
|
38
|
+
<example>
|
|
39
|
+
When referencing specific functions or pieces of code, include the pattern \`file_path:line_number\`.
|
|
40
|
+
For example: "Clients are handled in the \`connectToServer\` function in src/services/process.ts:712."
|
|
41
|
+
</example>
|
|
42
|
+
|
|
43
|
+
## Workflow
|
|
44
|
+
- Stay rooted on the user's request. Don't wander into tangents or explore out of curiosity.
|
|
45
|
+
- Gather only the information needed to fulfill the request, then stop exploring and complete it.
|
|
46
|
+
- Narrate your edits with brief commentary during long tasks so the user can follow progress.
|
|
47
|
+
- Verify your changes via compilation, tests, or manual checks whenever possible.
|
|
48
|
+
|
|
49
|
+
## Tone
|
|
50
|
+
- Be concise. Use a jovial but motivated colleague tone: direct, never condescending, and never rude.
|
|
51
|
+
|
|
52
|
+
## Error Handling
|
|
53
|
+
- If a tool call fails or is denied, do NOT re-attempt the exact same call. Analyze why it failed and adjust your approach.
|
|
54
|
+
|
|
55
|
+
IMPORTANT: Never guess or assume. Verify claims before making them.
|
|
56
|
+
IMPORTANT: Do not over-scope work or add scope during implementation.
|
|
57
|
+
|
|
58
|
+
${safetyPrompt}
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
export const TASK_PROMPT = `# You are an efficient, elite-level task Agent
|
|
62
|
+
|
|
63
|
+
## Role
|
|
64
|
+
Execute the assigned task precisely and efficiently. Prioritize correctness over speed. Focus on facts and objective technical details.
|
|
65
|
+
|
|
66
|
+
## Output Requirements
|
|
67
|
+
- Your final response must include all actions taken and exact diffs of any changes made.
|
|
68
|
+
- Provide a concise report of what was done, what was verified, and any decisions made.
|
|
69
|
+
|
|
70
|
+
${safetyPrompt}
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
async function getDir() {
|
|
74
|
+
const ignoreFile = Bun.file(".gitignore");
|
|
75
|
+
let ignoreContent = "";
|
|
76
|
+
if (await ignoreFile.exists()) {
|
|
77
|
+
ignoreContent = await ignoreFile.text();
|
|
78
|
+
}
|
|
79
|
+
const ignored = ignoreContent.split("\n");
|
|
80
|
+
const dir = [];
|
|
81
|
+
const glob = promises.glob(["*", "*/*"], { exclude: ignored });
|
|
82
|
+
for await (const file of glob) {
|
|
83
|
+
dir.push(file);
|
|
84
|
+
}
|
|
85
|
+
return dir;
|
|
47
86
|
}
|
|
48
87
|
|
|
49
|
-
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/** Resolve the AGENTS.md scan root from git/home/env inputs. */
|
|
57
|
-
export function resolveAgentsScanRoot(
|
|
58
|
-
_cwd: string,
|
|
59
|
-
gitRoot: string | null,
|
|
60
|
-
homeDir: string,
|
|
61
|
-
agentsRootEnv = process.env.MC_AGENTS_ROOT,
|
|
62
|
-
): string {
|
|
63
|
-
if (gitRoot) {
|
|
64
|
-
return canonicalizePath(gitRoot);
|
|
88
|
+
async function getEnvPrompt() {
|
|
89
|
+
// TODO: What else do the agents always check before answering every time?
|
|
90
|
+
let gitStatus: StatusResult | { nogit: string };
|
|
91
|
+
try {
|
|
92
|
+
gitStatus = await simpleGit().status();
|
|
93
|
+
} catch (_) {
|
|
94
|
+
gitStatus = { nogit: "No git repo in this folder." };
|
|
65
95
|
}
|
|
66
|
-
|
|
67
|
-
|
|
96
|
+
const envKeys = ["PATH", "USER", "LANG", "HOME", "SHELL", "BUN_INSTALL"];
|
|
97
|
+
const env: Record<string, string> = {};
|
|
98
|
+
for (const key of envKeys) {
|
|
99
|
+
const v = Bun.env[key];
|
|
100
|
+
|
|
101
|
+
if (v !== undefined) {
|
|
102
|
+
env[key] = v;
|
|
103
|
+
}
|
|
68
104
|
}
|
|
69
|
-
return canonicalizePath(homeDir);
|
|
70
|
-
}
|
|
71
105
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
106
|
+
const envStatus = JSON.stringify(
|
|
107
|
+
{
|
|
108
|
+
os: platform(),
|
|
109
|
+
env,
|
|
110
|
+
cwd: process.cwd(),
|
|
111
|
+
dir: await getDir(),
|
|
112
|
+
git: gitStatus,
|
|
113
|
+
},
|
|
114
|
+
null,
|
|
115
|
+
4,
|
|
77
116
|
);
|
|
78
|
-
}
|
|
79
117
|
|
|
80
|
-
|
|
81
|
-
if (!isWithinScanRoot(start, root)) {
|
|
82
|
-
return [start];
|
|
83
|
-
}
|
|
118
|
+
const text = `### Environment status and information
|
|
84
119
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (current === root) {
|
|
90
|
-
return dirs.reverse();
|
|
91
|
-
}
|
|
120
|
+
\`\`\`json
|
|
121
|
+
${envStatus}
|
|
122
|
+
\`\`\`
|
|
123
|
+
`;
|
|
92
124
|
|
|
93
|
-
|
|
94
|
-
if (parent === current) {
|
|
95
|
-
return dirs.reverse();
|
|
96
|
-
}
|
|
97
|
-
current = parent;
|
|
98
|
-
}
|
|
125
|
+
return text;
|
|
99
126
|
}
|
|
100
127
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
128
|
+
// `AGENTS.md` support: find it in current folder (./AGENTS.md) and a global one. (`.agents/AGENTS.md`)
|
|
129
|
+
export async function getAGENTSFiles() {
|
|
130
|
+
const content: string[] = [];
|
|
131
|
+
|
|
132
|
+
const globalPath = join(homedir(), ".agents/AGENTS.md");
|
|
133
|
+
const globalFile = Bun.file(globalPath);
|
|
134
|
+
|
|
135
|
+
if (await globalFile.exists()) {
|
|
136
|
+
content.push(await globalFile.text());
|
|
105
137
|
}
|
|
106
138
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
} catch {
|
|
113
|
-
return null;
|
|
139
|
+
const localPath = join(process.cwd(), "AGENTS.md");
|
|
140
|
+
const localFile = Bun.file(localPath);
|
|
141
|
+
|
|
142
|
+
if (await localFile.exists()) {
|
|
143
|
+
content.push(await localFile.text());
|
|
114
144
|
}
|
|
145
|
+
|
|
146
|
+
return content.join("\n\n").trim();
|
|
115
147
|
}
|
|
116
148
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
globalAgentsDir?: string,
|
|
133
|
-
): AgentsMdFile[] {
|
|
134
|
-
const root = canonicalizePath(scanRoot);
|
|
135
|
-
const start = canonicalizePath(cwd);
|
|
136
|
-
const files: AgentsMdFile[] = [];
|
|
137
|
-
|
|
138
|
-
if (globalAgentsDir) {
|
|
139
|
-
const globalFile = readAgentsMdFile(globalAgentsDir);
|
|
140
|
-
if (globalFile) {
|
|
141
|
-
files.push(globalFile);
|
|
149
|
+
// `SKILLS.md` discovery from [~|.]/agents/skills/*/SKILL.md
|
|
150
|
+
export async function getSkills(): Promise<string> {
|
|
151
|
+
let skillsBlock: string = "";
|
|
152
|
+
const skillRoots = [
|
|
153
|
+
join(homedir(), ".agents", "skills"),
|
|
154
|
+
join(process.cwd(), ".agents", "skills"),
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
for (const root of skillRoots) {
|
|
158
|
+
let entries: string[];
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
entries = await readdir(root);
|
|
162
|
+
} catch {
|
|
163
|
+
continue;
|
|
142
164
|
}
|
|
143
|
-
}
|
|
144
165
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
166
|
+
for (const entry of entries) {
|
|
167
|
+
const path = join(root, entry, "SKILL.md");
|
|
168
|
+
const file = Bun.file(path);
|
|
169
|
+
|
|
170
|
+
if (!(await file.exists())) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const parsed = parseSkillFrontmatter(await file.text());
|
|
175
|
+
|
|
176
|
+
if (!parsed) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
skillsBlock += `## ${parsed.name}
|
|
181
|
+
|
|
182
|
+
> Absolute file path to read: ${path}
|
|
183
|
+
|
|
184
|
+
${parsed.description}
|
|
185
|
+
|
|
186
|
+
`;
|
|
149
187
|
}
|
|
150
188
|
}
|
|
151
189
|
|
|
152
|
-
return
|
|
153
|
-
}
|
|
190
|
+
if (!skillsBlock.length) return "";
|
|
154
191
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
*
|
|
162
|
-
* Fields are omitted when their values are zero. The git line format:
|
|
163
|
-
* `Git: branch main | 3 staged, 1 modified, 2 untracked | +5 −2 vs origin/main`
|
|
164
|
-
* where the trailing upstream label reflects the repository's actual tracking ref.
|
|
165
|
-
*
|
|
166
|
-
* @param state - The git state to format.
|
|
167
|
-
* @returns Formatted git status line.
|
|
168
|
-
*/
|
|
169
|
-
export function formatGitLine(state: GitState): string {
|
|
170
|
-
const parts: string[] = [`Git: branch ${state.branch}`];
|
|
171
|
-
|
|
172
|
-
// Working tree counts
|
|
173
|
-
const counts: string[] = [];
|
|
174
|
-
if (state.staged > 0) counts.push(`${state.staged} staged`);
|
|
175
|
-
if (state.modified > 0) counts.push(`${state.modified} modified`);
|
|
176
|
-
if (state.untracked > 0) counts.push(`${state.untracked} untracked`);
|
|
177
|
-
if (counts.length > 0) parts.push(counts.join(", "));
|
|
178
|
-
|
|
179
|
-
// Ahead/behind
|
|
180
|
-
if (state.ahead > 0 || state.behind > 0) {
|
|
181
|
-
const ab: string[] = [];
|
|
182
|
-
if (state.ahead > 0) ab.push(`+${state.ahead}`);
|
|
183
|
-
if (state.behind > 0) ab.push(`\u2212${state.behind}`);
|
|
184
|
-
const upstream = state.upstream ? ` vs ${state.upstream}` : "";
|
|
185
|
-
parts.push(`${ab.join(" ")}${upstream}`);
|
|
186
|
-
}
|
|
192
|
+
const skills = `# Skills
|
|
193
|
+
|
|
194
|
+
- The following skills provide specialized instructions for specific tasks.
|
|
195
|
+
- Use the bash tool to read a skill's file when the task matches its description.
|
|
196
|
+
- Use the skill provided absolute file path instead of guessing or constructing one.
|
|
197
|
+
- Skills can be global (in ~/.agents/skills) or local to the directory (./agents/skills)
|
|
187
198
|
|
|
188
|
-
|
|
199
|
+
${skillsBlock}`;
|
|
200
|
+
|
|
201
|
+
return skills.trim();
|
|
189
202
|
}
|
|
190
203
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
function buildCorePrompt(opts: BuildSystemPromptOpts): string {
|
|
196
|
-
const lines = [
|
|
197
|
-
"You are mini-coder, the best software engineering assistant in the world.",
|
|
198
|
-
"",
|
|
199
|
-
"The current environment is:",
|
|
200
|
-
`- LLM in use: ${opts.modelLabel}`,
|
|
201
|
-
`- OS: ${opts.os}`,
|
|
202
|
-
`- Current working directory: ${opts.cwd}`,
|
|
203
|
-
];
|
|
204
|
+
export async function buildSystemPrompt(systemPrompt: string) {
|
|
205
|
+
const agentsContent = await getAGENTSFiles();
|
|
206
|
+
const skillsContent = await getSkills();
|
|
207
|
+
let complete = systemPrompt;
|
|
204
208
|
|
|
205
|
-
if (
|
|
206
|
-
|
|
209
|
+
if (skillsContent) {
|
|
210
|
+
complete += `\n${skillsContent}`;
|
|
207
211
|
}
|
|
208
212
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
"- Read: Read a text file from disk with offset/limit support.",
|
|
212
|
-
"- Grep: Search file contents with ripgrep-style options and structured results.",
|
|
213
|
-
"- Edit: Safe exact-text replacement in a single file.",
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
if (opts.supportsImages) {
|
|
217
|
-
lines.push("- Read Image: Read an image from disk.");
|
|
213
|
+
if (agentsContent) {
|
|
214
|
+
complete += `\n${agentsContent}`;
|
|
218
215
|
}
|
|
219
216
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
"## Core working style:",
|
|
223
|
-
"",
|
|
224
|
-
"- Be concise, direct, and useful.",
|
|
225
|
-
"- Use a casual, solution-oriented technical tone. Avoid fluff and performative apologies.",
|
|
226
|
-
"- When the user gives a clear command, do it without adding extra work they did not ask for.",
|
|
227
|
-
"- Prefer the minimal implementation that satisfies the request exactly.",
|
|
228
|
-
"- Use YAGNI. Avoid speculative abstractions, future-proofing, and unnecessary compatibility shims.",
|
|
229
|
-
"- Preserve working behavior where possible. Prefer targeted fixes over rewrites.",
|
|
230
|
-
"- Be thorough, use fresh eyes and internal analysis before taking action.",
|
|
231
|
-
"- Make informed decisions based on the available information and best practices.",
|
|
232
|
-
"- Always verify the result of your actions.",
|
|
233
|
-
"",
|
|
234
|
-
"### Using the shell tool:",
|
|
235
|
-
"",
|
|
236
|
-
"- Always execute shell commands in non-interactive mode.",
|
|
237
|
-
"- Use the appropriate commands and package managers for the specified operating system.",
|
|
238
|
-
"- Don't assume the environment supports all commands; check before using them.",
|
|
239
|
-
"- Avoid destructive commands that can discard changes or override edits.",
|
|
240
|
-
"",
|
|
241
|
-
"### Choosing tools:",
|
|
242
|
-
"",
|
|
243
|
-
"- Prefer `read` for reading file contents instead of `cat`, `sed`, `head`, or `tail`.",
|
|
244
|
-
"- Prefer `grep` for content search instead of raw `grep` / `rg`.",
|
|
245
|
-
"- Use shell `ls` and `fd` for lightweight exploration when you just need to inspect directories or discover candidate files.",
|
|
246
|
-
"",
|
|
247
|
-
"### Working with code:",
|
|
248
|
-
"",
|
|
249
|
-
"- Describe changes before implementing them",
|
|
250
|
-
"- Prefer boring dependable solutions over clever ones",
|
|
251
|
-
"- Avoid creating extra files, systems or documentation outside of what was asked.",
|
|
252
|
-
"- Check requirements, and plan your changes before editing code.",
|
|
253
|
-
"- Implement the necessary changes, following good practices and proper error handling.",
|
|
254
|
-
"- Prefer the smallest path that leaves the requested end state already true; do not stop at helper scripts, instructions, or half-finished setup when the user asked for the live result itself.",
|
|
255
|
-
"- Always verify your changes using compilation, testing, and manual verification when possible.",
|
|
256
|
-
"- Before you finish, re-check the explicit deliverables and current state. If the user named files, paths, ports, services, commands, or output values, make sure they already exist and work now.",
|
|
257
|
-
"- If the request includes structural constraints on files or outputs (for example allowed commands, required lines, exact formats, or counts), treat those as acceptance criteria too and verify them directly against what you produced, not just through downstream behavior.",
|
|
258
|
-
"- Treat concrete command sequences and expected outputs in the user's request as acceptance criteria for the end state. If you verify that flow during the task, do not roll the environment back afterward unless the user explicitly asked for a reset.",
|
|
259
|
-
"- If a check or tool result contradicts your expectation, trust the evidence and resolve the mismatch before you answer.",
|
|
260
|
-
"- When multiple outputs or end states seem plausible, do not guess or swap in a cleaner alternative after verification. Run the smallest check that distinguishes them, and if you change the state later, verify again.",
|
|
261
|
-
"- When verifying with build or test commands, avoid leaving generated binaries or scratch artifacts in the requested output location; use temporary paths or remove them before finishing.",
|
|
262
|
-
"- Do not leave helpers, tests, or any other form of temporary files; clean up after yourself and leave no trace.",
|
|
263
|
-
"- Ensure you match the requested output exactly. This applies to file names, directory structure, number of files, output formats, and all other details.",
|
|
264
|
-
'- "Polish" is not optional; it counts just as much as solving the task.',
|
|
265
|
-
"",
|
|
266
|
-
"### Task management",
|
|
267
|
-
"",
|
|
268
|
-
"- Use `todoWrite` proactively for multi-step or non-trivial tasks.",
|
|
269
|
-
"- Capture new requirements in the todo list as soon as you understand them.",
|
|
270
|
-
"- Use `todoRead` when you need to inspect the current list before updating it or when the user asks for the current plan/status.",
|
|
271
|
-
"- Keep the todo list up-to-date above all; mark tasks `in_progress` before starting them and `completed` as soon as verification succeeds.",
|
|
272
|
-
"- A todo item is only complete if the requested work is actually finished and verified to the degree the task requires.",
|
|
273
|
-
"- Use `cancelled` to remove tasks that are no longer relevant.",
|
|
274
|
-
"- Skip todo tools for single trivial tasks and purely conversational/informational requests.",
|
|
275
|
-
"- Use the `delegate` tool for bounded subtasks when another focused agent pass would help.",
|
|
276
|
-
"- Prefer `delegate` over shelling out to `mc -p` unless you specifically need to exercise the CLI itself.",
|
|
277
|
-
"- Do not re-delegate the whole task, spin on repeated self-review prompts, or ask a delegated child to delegate again.",
|
|
278
|
-
"- Delegate when you are orchestrating a large to-do/plan execution.",
|
|
279
|
-
"",
|
|
280
|
-
);
|
|
217
|
+
return complete;
|
|
218
|
+
}
|
|
281
219
|
|
|
282
|
-
|
|
220
|
+
export async function injectEnvReminder(): Promise<string> {
|
|
221
|
+
const envStatus = await getEnvPrompt();
|
|
222
|
+
return `<system-reminder>\n${envStatus}\n</system-reminder>`;
|
|
283
223
|
}
|
|
284
224
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
for (const file of opts.agentsMd) {
|
|
307
|
-
agentsSection.push(`## ${file.path}`);
|
|
308
|
-
agentsSection.push("");
|
|
309
|
-
agentsSection.push(file.content);
|
|
310
|
-
agentsSection.push("");
|
|
225
|
+
export function insertToolUsageReminder(
|
|
226
|
+
messages: Message[],
|
|
227
|
+
toolMessage: ToolResultMessage,
|
|
228
|
+
) {
|
|
229
|
+
// check for the last 5 tool call assistant messages
|
|
230
|
+
// if they are non-`task` tool calls insert the reminder
|
|
231
|
+
// as a prefix.
|
|
232
|
+
let output = toolMessage.content
|
|
233
|
+
.filter((b) => b.type === "text")
|
|
234
|
+
.map((b) => b.text)
|
|
235
|
+
.join("\n");
|
|
236
|
+
|
|
237
|
+
const budget = 3;
|
|
238
|
+
const toolCalls: ToolCall[] = [];
|
|
239
|
+
const lastUserMessageIndex = messages.findLastIndex((m) => m.role === "user");
|
|
240
|
+
const messagesSinceLastUser = messages.slice(lastUserMessageIndex + 1);
|
|
241
|
+
|
|
242
|
+
messagesSinceLastUser.forEach((m) => {
|
|
243
|
+
if (m.role === "assistant") {
|
|
244
|
+
const toolCallsBlocks = m.content.filter((b) => b.type === "toolCall");
|
|
245
|
+
toolCalls.push(...toolCallsBlocks);
|
|
311
246
|
}
|
|
312
|
-
|
|
313
|
-
|
|
247
|
+
});
|
|
248
|
+
const recentToolCalls = toolCalls.slice(-budget);
|
|
249
|
+
const taskSeen = recentToolCalls.some((call) => call.name === "task");
|
|
250
|
+
|
|
251
|
+
if (toolCalls.length >= budget && !taskSeen) {
|
|
252
|
+
output = `<system-reminder>
|
|
253
|
+
You are currently making repeated individual tool calls. This fragments context and reduces efficiency.
|
|
314
254
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
255
|
+
- Stop and plan: consolidate remaining steps into a single **task** tool call.
|
|
256
|
+
- If the user request is fully completed, stop calling tools and provide your final answer.
|
|
257
|
+
</system-reminder>
|
|
258
|
+
|
|
259
|
+
${output}`;
|
|
319
260
|
}
|
|
320
261
|
|
|
321
|
-
|
|
262
|
+
toolMessage.content = [{ type: "text", text: output }];
|
|
263
|
+
|
|
264
|
+
return toolMessage;
|
|
322
265
|
}
|