xonecas.io
64875
Mc

mini-coder / commit 563e79b

fix: cache friendlyness

xonecas2026-04-29 563e79b54368e8c84e069e6a1e03bf54e5bc40e1 parent ccfcf47

6 files changed

TODO.md+13−6
@@ -7,12 +7,13 @@
77 Raw notes, references:
88
99 > good lessons from claude and general advice, seems good and grounded on real experience. Matches with learnings.
10-https://www.indiehackers.com/post/the-complete-guide-to-writing-agent-system-prompts-lessons-from-reverse-engineering-claude-code-6e18d54294
10+> https://www.indiehackers.com/post/the-complete-guide-to-writing-agent-system-prompts-lessons-from-reverse-engineering-claude-code-6e18d54294
1111
1212 > How pi coding agent does it, minimal and structured, a good approach, but we can be even more focused and minimal.
13-https://raw.githubusercontent.com/badlogic/pi-mono/refs/heads/main/packages/coding-agent/src/core/system-prompt.ts
13+> https://raw.githubusercontent.com/badlogic/pi-mono/refs/heads/main/packages/coding-agent/src/core/system-prompt.ts
1414
1515 > Key sentence to add:
16+
1617 ```
1718 Prioritize technical accuracy and truthfulness over validating the user's beliefs.
1819 Focus on facts and problem-solving, providing direct, objective technical info
@@ -22,33 +23,39 @@ without any unnecessary superlatives, praise, or emotional validation.
2223 More reading material:
2324
2425 - https://arxiv.org/html/2601.16507v1#S3
25--
26----
26+- ***
2727
2828 # [Agent Name] Agent Prompt
2929
3030 ## Role
31+
3132 [Define the agent's role, persona, and objective concisely.]
3233 Example: You are an expert Data Analyst. You write SQL queries to answer questions from the marketing department.
3334
3435 ## Tool Usage
36+
3537 [Provide supplementary instructions on how/when to use specific tools.]
36-*Note: Detailed technical specifications should be defined in the tool's description settings, but high-level logic goes here.*
38+_Note: Detailed technical specifications should be defined in the tool's description settings, but high-level logic goes here._
3739
3840 ## Input / Output
41+
3942 ### Input Variables
43+
4044 - `{{variable_name}}`: [Description of the variable]
4145
4246 ### Output Goals
47+
4348 - [Definition of the final deliverable]
4449
4550 ## Task Flow
51+
4652 1. [Task Name]
4753 - [Specific steps and decision criteria]
4854 2. [Task Name]
4955 - [Specific steps and decision criteria]
5056
5157 ## Constraints & Rules
58+
5259 - [Prohibitions and constraints]
5360 - [Tone and Manner instructions]
5461
@@ -139,4 +146,4 @@ The unit tests for the company_location type aren’t passing.
139146 It appears that the unit tests for company_location are throwing a JSONDecodeError.
140147 --> EXTEND PROMPT
141148 I am extending the company_location column. I must ensure that when a string is provided as input it doesn’t throw a JSONDecodeError.
142-```
149+```
src/headless.ts+7−2
@@ -1,6 +1,6 @@
11 import type { Message } from "@mariozechner/pi-ai";
22 import { streamAgent } from "./agent";
3-import { buildSystemPrompt, MAIN_PROMPT } from "./prompt";
3+import { buildSystemPrompt, injectEnvReminder, MAIN_PROMPT } from "./prompt";
44 import { bash, runBashTool } from "./tool-bash";
55 import { edit, runEditTool } from "./tool-edit";
66 import { runTaskTool, task } from "./tool-task";
@@ -18,8 +18,13 @@ export async function streamHeadless(
1818 runner: (args) => runTaskTool(options, args),
1919 },
2020 ];
21+ const envReminder = await injectEnvReminder();
2122 const messages: Message[] = [
22- { role: "user", content: options.prompt || "", timestamp: Date.now() },
23+ {
24+ role: "user",
25+ content: `${envReminder}\n\n${options.prompt || ""}`,
26+ timestamp: Date.now(),
27+ },
2328 ];
2429 console.log(JSON.stringify(messages[0]));
2530
src/prompt.ts+9−5
@@ -19,13 +19,13 @@ const safetyPrompt = `
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 elite-level coding agent.
22+export const MAIN_PROMPT = `# You are "mini-coder", a coding agent.
2323
2424 IMPORTANT: Be defensive with existing changes and destructive commands.
2525 IMPORTANT: Do not overstate what changed or what was verified. Summaries must match the diff.
2626
2727 ## 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.
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.
2929
3030 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.
3131
@@ -192,7 +192,7 @@ ${parsed.description}
192192 const skills = `# Skills
193193
194194 - The following skills provide specialized instructions for specific tasks.
195-- Use the shell tool to read a skill's file when the task matches its description.
195+- Use the bash tool to read a skill's file when the task matches its description.
196196 - Use the skill provided absolute file path instead of guessing or constructing one.
197197 - Skills can be global (in ~/.agents/skills) or local to the directory (./agents/skills)
198198
@@ -204,8 +204,7 @@ ${skillsBlock}`;
204204 export async function buildSystemPrompt(systemPrompt: string) {
205205 const agentsContent = await getAGENTSFiles();
206206 const skillsContent = await getSkills();
207- const envStatus = await getEnvPrompt();
208- let complete = systemPrompt + envStatus;
207+ let complete = systemPrompt;
209208
210209 if (skillsContent) {
211210 complete += `\n${skillsContent}`;
@@ -218,6 +217,11 @@ export async function buildSystemPrompt(systemPrompt: string) {
218217 return complete;
219218 }
220219
220+export async function injectEnvReminder(): Promise<string> {
221+ const envStatus = await getEnvPrompt();
222+ return `<system-reminder>\n${envStatus}\n</system-reminder>`;
223+}
224+
221225 export function insertToolUsageReminder(
222226 messages: Message[],
223227 toolMessage: ToolResultMessage,
src/tui-conversation.ts+6−0
@@ -102,6 +102,12 @@ function userMessageNode(msg: UserMessage): Node {
102102 .join("");
103103 }
104104
105+ // Remove any reminders we might have attached before render
106+ // Keep this fast, it runs on the render cycle.
107+ text = text
108+ .replaceAll(/<system-reminder>[\s\S]*?<\/system-reminder>/g, "")
109+ .trimStart();
110+
105111 return VStack(
106112 {
107113 padding: { x: 1, y: 1 },
src/tui-overlay.ts+7−8
@@ -1,17 +1,16 @@
11 import { HStack, Text, TextInput, VStack } from "@cel-tui/core";
22 import {
3- getModel,
43 getModels,
54 type KnownProvider,
65 type ThinkingLevel,
76 } from "@mariozechner/pi-ai";
87 import { getOAuthProviders } from "@mariozechner/pi-ai/oauth";
8+import { saveSettings } from "./args";
99 import { getAvailableProviders } from "./oauth";
1010 import { listSessionsForCwd } from "./session";
11+import { estimateTokens } from "./shared";
1112 import { TextPill, theme } from "./tui-components";
1213 import type { SelectOptions, SelectState, Session, TUIState } from "./types";
13-import { estimateTokens } from "./shared";
14-import { saveSettings } from "./args";
1514
1615 export function SelectOverlay(
1716 value: string,
@@ -321,7 +320,7 @@ export function mainMenu(state: TUIState) {
321320 state.sessionId = session.id;
322321 state.messages = session.messages;
323322 state.prompt = "";
324- state.contextSize = estimateTokens(JSON.stringify(state.messages))
323+ state.contextSize = estimateTokens(JSON.stringify(state.messages));
325324 state.scrollOffset = 0;
326325 state.stickToBottom = true;
327326 closeMenu(s);
@@ -354,8 +353,8 @@ export function mainMenu(state: TUIState) {
354353 saveSettings({
355354 provider: selectedProvider,
356355 model: model.id,
357- effort: state.options.effort
358- })
356+ effort: state.options.effort,
357+ });
359358 closeMenu(s);
360359 return;
361360 }
@@ -368,8 +367,8 @@ export function mainMenu(state: TUIState) {
368367 saveSettings({
369368 provider: state.options.provider,
370369 model: state.options.model.id,
371- effort: effort
372- })
370+ effort: effort,
371+ });
373372 closeMenu(s);
374373 }
375374 },
src/tui.ts+7−1
@@ -3,6 +3,7 @@ import simpleGit from "simple-git";
33 import { streamAgent } from "./agent";
44 import {
55 buildSystemPrompt,
6+ injectEnvReminder,
67 insertToolUsageReminder,
78 MAIN_PROMPT,
89 } from "./prompt";
@@ -152,9 +153,14 @@ async function streamAgentTUI(state: TUIState) {
152153 },
153154 ];
154155
156+ let userContent = state.prompt;
157+ if (state.messages.length === 0) {
158+ const envReminder = await injectEnvReminder();
159+ userContent = `${envReminder}\n\n${userContent}`;
160+ }
155161 state.messages.push({
156162 role: "user",
157- content: state.prompt,
163+ content: userContent,
158164 timestamp: Date.now(),
159165 });
160166 state.prompt = "";