xonecas.io
64875
Mc

mini-coder / commit 87f5161

fix: first pass at prompt language. Fix session duplication

xonecas2026-04-29 87f516127342138c7b534fc5e38919481dd0596e parent f3af852

8 files changed

TODO.md+4−0
@@ -19,6 +19,10 @@ Focus on facts and problem-solving, providing direct, objective technical info
1919 without any unnecessary superlatives, praise, or emotional validation.
2020 ```
2121
22+More reading material:
23+
24+- https://arxiv.org/html/2601.16507v1#S3
25+-
2226 ---
2327
2428 # [Agent Name] Agent Prompt
src/prompt.ts+46−23
@@ -15,30 +15,57 @@ const safetyPrompt = `
1515 - Be defensive with existing changes and destructive commands, they could harm your user's changes.
1616 - Use temp directory for temp files, scripts, plan files, or anything that doesn't match the requested output.
1717 - 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 preffered.
18+- Avoid over-enginnering, hacks or creative solutions. The boring, simple and repliable is always preferred.
1919 - Do not overstate what changed or what was verified. Summaries must match the diff.
2020 `;
2121
22-export const MAIN_PROMPT = `# You are "mini-coder", an efficient and elite level coding agent.
22+export const MAIN_PROMPT = `# You are "mini-coder", an elite-level coding agent.
2323
24-## Behaviour:
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.
2526
26-- Be efficient, don't get lost with tangents or satisfying your curiosity, root yourself on the user request.
27-- Always prefer the task tool. It's the intended way of working.
28-- Keep other tools for single call actions, anything more, you should use the task tool.
29-- Narrate your edits with small commentary messages during long tasks.
30-- Focus on the user's request requirements to answer accurately and efficiently.
31-- Once you've gathered enough information to complete the request, stop exploring and complete it.
32-- Always verify your changes using compilation, testing, and manual verification when possible.
33-- Tone: use a jovial but motivated colleague, never condescending, persona. Be less verbose and more concise. Be direct without being rude.
27+## Role
28+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.
3457
3558 ${safetyPrompt}
3659 `;
3760
3861 export const TASK_PROMPT = `# You are an efficient, elite-level task Agent
3962
40-- Complete the given task with efficiency, and precicely.
41-- Your final response your include all actions and exact diffs of any changes you might have made. And a report of all actions taken.
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.
4269
4370 ${safetyPrompt}
4471 `;
@@ -218,18 +245,14 @@ export function insertToolUsageReminder(
218245 const taskSeen = recentToolCalls.some((call) => call.name === "task");
219246
220247 if (toolCalls.length >= budget && !taskSeen) {
221- output = `# System reminder:
222-
223-> You are in a shell or edit tool calling loop poluting your context.
248+ output = `<system-reminder>
249+You are currently making repeated individual tool calls. This fragments context and reduces efficiency.
224250
225-- Remember your tool choice heuristic.
226-- Plan your next actions, and use the task tool to continue.
227-- If you have completed the user request, complete your answer.
251+- Stop and plan: consolidate remaining steps into a single **task** tool call.
252+- If the user request is fully completed, stop calling tools and provide your final answer.
253+</system-reminder>
228254
229----
230-
231-${output}
232-`;
255+${output}`;
233256 }
234257
235258 toolMessage.content = [{ type: "text", text: output }];
src/session.ts+1−1
@@ -71,7 +71,7 @@ export async function saveSession(s: Session) {
7171 export async function updateSession(id: string, messages: Message[]) {
7272 const existing = await getSession(id);
7373 if (existing) {
74- existing.messages = [...existing.messages, ...messages];
74+ existing.messages = messages;
7575 await saveSession(existing);
7676 return;
7777 }
src/tool-bash.ts+13−10
@@ -5,22 +5,24 @@ import type { ToolRunnerEvent } from "./types";
55 const OUTPUT_THRESHOLD = 16000;
66 const description = `## Bash CLI tool
77
8-Best practices using this tool:
8+Execute shell commands on the user's environment.
9+
10+Best practices:
911
1012 - Use \`ls\` to list files.
1113 - Use \`fd\` or \`find\` to locate files/directories by name, type, size, time, permissions, etc.
1214 - Use \`rg\` or \`grep\` to search inside files for matching patterns.
1315 - Use \`cat -n\` or \`nl\` to read small files, or when you need the whole file.
14-- Use \`sed -n\` with ranges to read sections of files. Prefer targeted reads, avoid dumping very large (more than ~200 lines) files all at once.
16+- Use \`sed -n\` with ranges to read sections of files. Prefer targeted reads. Avoid dumping very large (more than ~200 lines) files all at once.
1517 - Use \`cp\`, \`mv\`, and \`mkdir\` for file and directory operations, and \`rm\` to remove files and directories.
1618 - Use \`curl\` for web access. Use redirection to temp files for targeted reads.
17-- Use development tools, like \`git\`, \`gh\`, \`jq\`, etc, when appropriate.
18-- Prefer \`cp -i\`, \`mv -i\`, \`rm -i\` when learning
19-- Be careful with destructive actions, and overwriting existing unsaved work.
20-- Chain commands **only** when failure should stop the flow. Avoid long chains of command, **2 to 3 maximum**.
21-- Avoid overly complex one-liners, readability matters.
22-- Quote filenames: use \`"$file"\` not \`$file\`
23-- Be careful with spaces in filenames
19+- Use development tools like \`git\`, \`gh\`, \`jq\`, etc, when appropriate.
20+- Prefer \`cp -i\`, \`mv -i\`, \`rm -i\` when learning.
21+- NEVER run destructive commands (\`rm -rf\`, \`git reset --hard\`, overwriting files) without confirming the target first.
22+- Chain commands **only** when failure should stop the flow. Avoid long chains, **2 to 3 maximum**.
23+- Avoid overly complex one-liners; readability matters.
24+- Quote filenames: use \`"$file"\` not \`$file\`.
25+- Be careful with spaces in filenames.
2426
2527 Commands run in: ${process.cwd()}
2628 `;
@@ -30,7 +32,8 @@ export const bash: Tool = {
3032 description,
3133 parameters: Type.Object({
3234 command: Type.String({
33- description: "The command you want to run on the user's environment.",
35+ description:
36+ "Shell command to execute. Prefer simple, focused commands over complex one-liners.",
3437 }),
3538 }),
3639 };
src/tool-edit.ts+27−5
@@ -5,10 +5,31 @@ import type { ToolRunnerEvent } from "./types";
55
66 const description = `## Edit tool
77
8-- This is your edit tool, use it to create or edit files safely. Always prefer this tool over bash editing methods.
9-- The tool will refuse to edit on multiple matches of \`oldText\` so be specific with your matching.
10-- Prefer patch-based edits for multi-line or semantic changes.
11-- Avoid reproducing whole files, use shell file operations for that instead (\`cp\`, \`mv\`, etc).
8+A find-and-replace file editor. Use it to create new files or modify existing ones safely. Always prefer this tool over bash editing methods (sed, awk, etc).
9+
10+### Rules
11+- The tool refuses to edit on multiple matches of \`oldText\`. Be specific with your matching text.
12+- Prefer patch-based edits (small targeted replacements) for multi-line or semantic changes.
13+- Do NOT reproduce entire files. Use shell file operations (\`cp\`, \`mv\`, etc) for wholesale file replacement instead.
14+
15+### Failure modes
16+- If \`oldText\` is not found, the edit fails. Verify the exact text first.
17+- If \`oldText\` matches multiple locations, the edit fails. Narrow your match and retry.
18+- If the file does not exist and \`oldText\` is non-empty, the edit fails.
19+
20+<example>
21+Edit a single line:
22+path: src/utils.ts
23+oldText: const MAX_RETRIES = 3;
24+newText: const MAX_RETRIES = 5;
25+</example>
26+
27+<example>
28+Patch-based edit (preferred for multi-line changes):
29+path: src/utils.ts
30+oldText: function oldHelper() {\n return 1;\n}
31+newText: function newHelper() {\n return 2;\n}\n\nfunction oldHelper() {\n return 1;\n}
32+</example>
1233 `;
1334
1435 export const edit: Tool = {
@@ -16,7 +37,8 @@ export const edit: Tool = {
1637 description,
1738 parameters: Type.Object({
1839 path: Type.String({
19- description: "File path (absolute or relative to cwd)",
40+ description:
41+ "File path. Absolute or relative to the current working directory.",
2042 }),
2143 oldText: Type.String({
2244 description:
src/tool-task.ts+7−6
@@ -13,13 +13,13 @@ import type {
1313
1414 const description = `## Task tool
1515
16-Best practices using this tool:
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.
1717
18-To explore the web, the local system, or codebase, use an eploration task, specify what you are looking for, and be explicit about the expected output, for example: "Explore the current git repo, find all files relevant to tests. Return the exact paths of the matching files and a description of each file and their contents.
18+Best practices:
1919
20-For edits, you should specify a collection of exact diffs that you want to apply and the file you want them applied to.
21-
22-For anything else, use a specific and detailed set of instructions and your expected results.
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.
2323 `;
2424
2525 export const task: Tool = {
@@ -27,7 +27,8 @@ export const task: Tool = {
2727 description,
2828 parameters: Type.Object({
2929 prompt: Type.String({
30- description: "The detailed description of the task you want complete.",
30+ description:
31+ "Detailed description of the work to perform. Be specific about expected outputs and any constraints.",
3132 }),
3233 }),
3334 };
src/tui-overlay.ts+2−0
@@ -9,6 +9,7 @@ import { getAvailableProviders } from "./oauth";
99 import { listSessionsForCwd } from "./session";
1010 import { TextPill, theme } from "./tui-components";
1111 import type { SelectOptions, SelectState, Session, TUIState } from "./types";
12+import { estimateTokens } from "./shared";
1213
1314 export function SelectOverlay(
1415 value: string,
@@ -318,6 +319,7 @@ export function mainMenu(state: TUIState) {
318319 state.sessionId = session.id;
319320 state.messages = session.messages;
320321 state.prompt = "";
322+ state.contextSize = estimateTokens(JSON.stringify(state.messages))
321323 state.scrollOffset = 0;
322324 state.stickToBottom = true;
323325 closeMenu(s);
src/tui.ts+1−0
@@ -89,6 +89,7 @@ export function initTUI(state: TUIState, leave: (s: string) => void) {
8989 state.sessionId = undefined;
9090 state.messages = [];
9191 state.prompt = "";
92+ state.contextSize = 0;
9293 state.scrollOffset = 0;
9394 state.stickToBottom = true;
9495 return false;