xonecas.io
64875
Mc

mini-coder / commit e423cf2

feat: Prompt and bash tool description

xonecas2026-04-22 e423cf2b3203633f33f9ba0388973ef1bd8a8e47 parent 742f1db

7 files changed

biome.json+1−13
@@ -14,19 +14,7 @@
1414 "linter": {
1515 "enabled": true,
1616 "rules": {
17- "recommended": true,
18- "style": {
19- "noNonNullAssertion": "off"
20- },
21- "complexity": {
22- "noExcessiveCognitiveComplexity": {
23- "level": "error",
24- "options": {
25- "maxAllowedComplexity": 10
26- }
27- },
28- "noExcessiveNestedTestSuites": "error"
29- }
17+ "recommended": true
3018 }
3119 },
3220 "files": {
package.json+1−1
@@ -11,7 +11,7 @@
1111 "check": "bun run lint && bun run typecheck",
1212 "lint": "bun run biome check --write .",
1313 "typecheck": "bun run tsc -p tsconfig.json --noEmit",
14- "format": "bun run prettier --write *.md && bunx biome format --write ."
14+ "format": "bun run prettier --write *.md && bun run biome format --write ."
1515 },
1616 "devDependencies": {
1717 "@biomejs/biome": "^2.4.12",
src/agent.ts+8−0
@@ -0,0 +1,8 @@
1+export const TASK_PROMPT = `# You are "mini-coder", an elite coding agent.
2+
3+Behaviour guidelines:
4+
5+- Answer all user questions without guessing, or assuming. Use recent online information and your training data combined for a complete answer.
6+- When completing a task, ensure that you fulfill the contract **exactly**.
7+- Tone: use a jovial but motivated colleague persona. Be less verbose and more concise. You are working with software engineers, act appropriate, no fluff, only direct talk.
8+`;
src/args.ts+12−2
@@ -1,4 +1,8 @@
1-import { getModels, KnownProvider } from "@mariozechner/pi-ai";
1+import {
2+ getModels,
3+ type KnownProvider,
4+ type ThinkingLevel,
5+} from "@mariozechner/pi-ai";
26 import { loginOAuth } from "./oauth";
37 import type { CliOptions } from "./types.ts";
48
@@ -12,11 +16,17 @@ function getModelConfig(modelName: string, provider: KnownProvider) {
1216 return model;
1317 }
1418
19+// TODO: For when the user set's thinking value.
20+// function _isThinkingLevel(value: string): value is ThinkingLevel {
21+// const THINKING_LEVELS = ["low", "medium", "minimal", "high", "xhigh"]
22+// return (THINKING_LEVELS as readonly string[]).includes(value);
23+// }
24+
1525 export async function handleArgv(argv: string[]): Promise<CliOptions> {
1626 // TODO: Fetch defaults from settings file
1727 let options: CliOptions = {
1828 model: getModelConfig("gpt-5.4", "openai-codex"),
19- effort: "xhigh",
29+ effort: "xhigh" as ThinkingLevel,
2030 };
2131
2232 for (let i = 0; i < argv.length; i++) {
src/headless.ts+17−28
@@ -1,5 +1,12 @@
1-import { complete, Context, stream, Tool, Type } from "@mariozechner/pi-ai";
1+import {
2+ type Context,
3+ completeSimple,
4+ streamSimple,
5+ type Tool,
6+} from "@mariozechner/pi-ai";
7+import { TASK_PROMPT } from "./agent";
28 import { getApiKey } from "./oauth";
9+import { bash, runBashTool } from "./tool-bash";
310 import type { CliOptions } from "./types";
411
512 export async function streamHeadless(
@@ -7,25 +14,9 @@ export async function streamHeadless(
714 leave: (s: string) => void,
815 ) {
916 const apiKey = await getApiKey(options);
10-
11- const tools: Tool[] = [
12- {
13- name: "bash",
14- description:
15- "This is your command line, runs commands in your user's environment.",
16- parameters: Type.Object({
17- command: Type.String({
18- description:
19- "The command you want to run, ex: `ls`, `fd`, `find`, `grep`, `rg`, `cat`, `sed`, `bun`, etc",
20- }),
21- }),
22- },
23- ];
24-
17+ const tools: Tool[] = [bash];
2518 const context: Context = {
26- // TODO: Centralize prompts
27- systemPrompt:
28- "You are friendly coding assistant, answer user questions and complete given tasks with accuracy.",
19+ systemPrompt: TASK_PROMPT,
2920 messages: [
3021 { content: options.prompt ?? "", role: "user", timestamp: Date.now() },
3122 ],
@@ -36,7 +27,7 @@ export async function streamHeadless(
3627 console.log("-------------------");
3728
3829 while (true) {
39- const s = stream(options.model, context, {
30+ const s = streamSimple(options.model, context, {
4031 apiKey,
4132 reasoning: options.effort,
4233 });
@@ -44,17 +35,17 @@ export async function streamHeadless(
4435 for await (const ev of s) {
4536 switch (ev.type) {
4637 case "text_start":
47- console.log("Answering...");
38+ console.log("> Answering...");
4839 break;
4940 case "thinking_start":
50- console.log("Thinking...");
41+ console.log("> Thinking...");
5142 break;
5243 case "toolcall_start":
53- console.log(`Calling tool...`);
44+ console.log(`> Calling tool...`);
5445 break;
5546 case "toolcall_end":
5647 console.log(
57- `${ev.toolCall.name}:\n\t${ev.toolCall.arguments.command}`,
48+ `> ${ev.toolCall.name}: ${ev.toolCall.arguments.command}`,
5849 );
5950 break;
6051 case "error":
@@ -73,9 +64,7 @@ export async function streamHeadless(
7364
7465 const toolCalls = finalMessage.content.filter((b) => b.type === "toolCall");
7566 for (const call of toolCalls) {
76- const proc = Bun.spawn(["bash", "-c", call.arguments.command]);
77- await proc.exited;
78- const result = await proc.stdout.text();
67+ const result = await runBashTool(call.arguments.command);
7968
8069 context.messages.push({
8170 role: "toolResult",
@@ -88,7 +77,7 @@ export async function streamHeadless(
8877 }
8978
9079 if (toolCalls.length > 0) {
91- const cont = await complete(options.model, context);
80+ const cont = await completeSimple(options.model, context);
9281 context.messages.push(cont);
9382 }
9483
src/tool-bash.ts+41−0
@@ -0,0 +1,41 @@
1+import { type Tool, Type } from "@mariozechner/pi-ai";
2+
3+const description = `## Bash CLI tool
4+
5+Best practices using this tool:
6+
7+- Use \`ls\` to list files.
8+- Use \`fd\` or \`find\` to locate files/directories by name, type, size, time, permissions, etc.
9+- Use \`rg\` or \`grep\` to search inside files for matching patterns.
10+- Use \`cat -n\` or \`nl\` to read small files, or when you need the whole file.
11+- 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.
12+- Use \`sed -i\` for exact edits and \`cat\` with redirection for new files. Prefer patch-based edits for multi-line or semantic changes.
13+- Use \`cp\`, \`mv\`, and \`mkdir\` for file and directory operations, and \`rm\` to remove files and directories.
14+- Use \`curl\` for web access. Use redirection to temp files for targeted reads.
15+- Use development tools, like \`git\`, \`gh\`, \`jq\`, etc, when appropriate.
16+- Prefer \`cp -i\`, \`mv -i\`, \`rm -i\` when learning
17+- Be careful with destructive actions, and overwriting existing unsaved work.
18+- Chain commands only when failure should stop the flow.
19+- Avoid overly complex one-liners, readability matters.
20+- Quote filenames: use \`"$file"\` not \`$file\`
21+- Be careful with spaces in filenames
22+`;
23+
24+export const bash: Tool = {
25+ name: "bash",
26+ description:
27+ "This is your command line, run commands in your user's environment.",
28+ parameters: Type.Object({
29+ command: Type.String({
30+ description,
31+ }),
32+ }),
33+};
34+
35+export async function runBashTool(command: string) {
36+ const proc = Bun.spawn(["bash", "-c", command]);
37+ await proc.exited;
38+ const result = await proc.stdout.text();
39+
40+ return result;
41+}
src/types.ts+2−2
@@ -1,10 +1,10 @@
1-import type { Model } from "@mariozechner/pi-ai";
1+import type { Model, ThinkingLevel } from "@mariozechner/pi-ai";
22 import type { OAuthCredentials } from "@mariozechner/pi-ai/oauth";
33
44 export type CliOptions = {
55 prompt?: string;
66 model: Model<never>;
7- effort: string;
7+ effort: ThinkingLevel;
88 };
99
1010 export type TUIOptions = {