xonecas.io
64875
Mc

mini-coder / commit 789e20b

feat: adds new select component and dir information to prompt

xonecas2026-04-28 789e20b217bbc4df8ff952cd1a47ada3837da50e parent 1f02864

8 files changed

bun.lock+2−2
@@ -5,8 +5,8 @@
55 "": {
66 "name": "mini-coder-next",
77 "dependencies": {
8- "@cel-tui/components": "^0.8.2",
9- "@cel-tui/core": "^0.8.2",
8+ "@cel-tui/components": "^0.8.3",
9+ "@cel-tui/core": "^0.8.3",
1010 "@mariozechner/pi-ai": "^0.70.2",
1111 "diff": "^9.0.0",
1212 "simple-git": "^3.36.0",
src/prompt.ts+19−2
@@ -4,6 +4,7 @@ import { join } from "node:path";
44 import type { Message, ToolCall, ToolResultMessage } from "@mariozechner/pi-ai";
55 import simpleGit, { type StatusResult } from "simple-git";
66 import { parseSkillFrontmatter } from "./shared";
7+import { promises } from "node:fs";
78
89 const IDENTITY_PROMPT = `# You are "mini-coder", an efficient, elite coding agent.
910
@@ -66,6 +67,21 @@ export const TASK_PROMPT = `${IDENTITY_PROMPT}
6667 5. Your final message should include a summary of your actions and any diffs from your edits.
6768 `;
6869
70+async function getDir() {
71+ const ignoreFile = Bun.file(".gitignore")
72+ let ignoreContent = ""
73+ if (await ignoreFile.exists()) {
74+ ignoreContent = await ignoreFile.text()
75+ }
76+ const ignored = ignoreContent.split("\n")
77+ let dir = []
78+ const glob = promises.glob(["*", "*/*"], {exclude: ignored})
79+ for await (const file of glob) {
80+ dir.push(file)
81+ }
82+ return dir;
83+}
84+
6985 async function getEnvPrompt() {
7086 // TODO: What else do the agents always check before answering every time?
7187 let gitStatus: StatusResult | { nogit: string };
@@ -76,8 +92,9 @@ async function getEnvPrompt() {
7692 }
7793 const envStatus = JSON.stringify(
7894 {
79- cwd: process.cwd(),
8095 os: platform(),
96+ cwd: process.cwd(),
97+ dir: await getDir(),
8198 git: gitStatus,
8299 },
83100 null,
@@ -163,7 +180,7 @@ ${parsed.description}
163180 - The following skills provide specialized instructions for specific tasks.
164181 - Use the shell tool to read a skill's file when the task matches its description.
165182 - Use the skill provided absolute file path instead of guessing or constructing one.
166-- Skills can be global (in ~/.agents/skills) or locat to the directory (./agents/skills)
183+- Skills can be global (in ~/.agents/skills) or local to the directory (./agents/skills)
167184
168185 ${skillsBlock}`;
169186
src/tui-components.ts+2−45
@@ -28,51 +28,6 @@ export const theme = {
2828 bwhite: "color15" as Color,
2929 };
3030
31-// Momoization helper for cel-tui
32-// type NodeMemoKey = string | number | symbol;
33-
34-// type MemoizedNodeRenderer<T> = ((value: T) => Node) & {
35-// clear: () => void;
36-// delete: (value: T) => boolean;
37-// };
38-
39-// export function memoNodeByKey<T>(
40-// keyOf: (value: T) => NodeMemoKey,
41-// render: (value: T) => Node,
42-// options: { maxEntries?: number } = {},
43-// ): MemoizedNodeRenderer<T> {
44-// const maxEntries = options.maxEntries ?? 1000;
45-// const cache = new Map<NodeMemoKey, Node>();
46-
47-// const memoized = ((value: T): Node => {
48-// const key = keyOf(value);
49-// const cached = cache.get(key);
50-
51-// if (cached) {
52-// // Move to the end: simple LRU-ish behavior.
53-// cache.delete(key);
54-// cache.set(key, cached);
55-// return cached;
56-// }
57-
58-// const node = render(value);
59-// cache.set(key, node);
60-
61-// while (cache.size > maxEntries) {
62-// const oldest = cache.keys().next();
63-// if (oldest.done) break;
64-// cache.delete(oldest.value);
65-// }
66-
67-// return node;
68-// }) as MemoizedNodeRenderer<T>;
69-
70-// memoized.clear = () => cache.clear();
71-// memoized.delete = (value: T) => cache.delete(keyOf(value));
72-
73-// return memoized;
74-// }
75-
7631 export function TextPill(content: string, fgColor: Color, bgColor: Color) {
7732 return HStack({ gap: 1 }, [
7833 HStack({ bgColor, padding: { x: 1 } }, [
@@ -158,6 +113,8 @@ export function ContextPill(state: TUIState) {
158113 text = `~${percent}%`;
159114 }
160115
116+ text += ` (${state.options.model.contextWindow / 1000}k)`;
117+
161118 return TextPill(text, theme.bblack, bg);
162119 }
163120
src/tui-conversation.ts+80−31
@@ -11,43 +11,61 @@ import { TextPill, theme } from "./tui-components";
1111 import type { TUIState } from "./types";
1212
1313 function agentMessageNode(msg: AssistantMessage): Node {
14- const textBlocks: Node[] = msg.content.map((block) => {
15- if (block.type === "text") {
16- return SyntaxHighlight(block.text, "markdown");
17- }
18- if (block.type === "thinking") {
19- if (!block.thinking.length) return Text("");
20-
21- const tokens = estimateTokens(block.thinking);
14+ let thinking = "";
15+ let text = "";
16+ const toolCalls: Node[] = [];
2217
23- return Text(`Thinking... (~${tokens} tokens)`, {
24- fgColor: theme.bblack,
25- italic: true,
26- });
18+ for (const block of msg.content) {
19+ if (block.type === "thinking" && block.thinking.length > 0) {
20+ thinking += block.thinking;
2721 }
2822
29- let text = "";
30- let node: Node | undefined;
31- if ("path" in block.arguments) {
32- text = block.arguments.path;
33- node = Text(text);
34- } else if ("command" in block.arguments) {
35- text = block.arguments.command;
36- node = SyntaxHighlight(text, "bash");
37- } else if ("prompt" in block.arguments) {
38- text = block.arguments.prompt;
39- node = SyntaxHighlight(text, "markdown");
40- } else {
41- text = JSON.stringify(block.arguments);
42- node = Text(text);
23+ if (block.type === "text" && block.text.length > 0) {
24+ text += block.text;
4325 }
4426
45- return VStack({ padding: { x: 4 }, gap: 1 }, [
46- TextPill(block.name, theme.white, theme.bblack),
47- node,
48- ]);
49- });
27+ if (block.type === "toolCall" && block.arguments && block.name) {
28+ let text = "";
29+ let node: Node | undefined;
30+ if ("path" in block.arguments) {
31+ text = block.arguments.path;
32+ node = Text(text);
33+ } else if ("command" in block.arguments) {
34+ text = block.arguments.command;
35+ node = SyntaxHighlight(text, "bash");
36+ } else if ("prompt" in block.arguments) {
37+ text = block.arguments.prompt;
38+ node = SyntaxHighlight(text, "markdown");
39+ } else {
40+ text = JSON.stringify(block.arguments);
41+ node = Text(text);
42+ }
43+
44+ toolCalls.push(
45+ VStack({ padding: { x: 4 }, gap: 1 }, [
46+ TextPill(block.name, theme.white, theme.bblack),
47+ node,
48+ ]),
49+ );
50+ }
51+ }
52+ const textBlocks: Node[] = [];
53+ if (thinking.length > 0) {
54+ const tokens = estimateTokens(thinking);
5055
56+ textBlocks.push(
57+ Text(`Thinking... (~${tokens} tokens)`, {
58+ fgColor: theme.bblack,
59+ italic: true,
60+ }),
61+ );
62+ }
63+ if (text.length > 0) {
64+ textBlocks.push(SyntaxHighlight(text, "markdown"));
65+ }
66+ if (toolCalls.length > 0) {
67+ textBlocks.push(...toolCalls);
68+ }
5169 const error =
5270 ((msg.stopReason === "error" || msg.stopReason === "aborted") &&
5371 msg.errorMessage) ??
@@ -60,6 +78,16 @@ function agentMessageNode(msg: AssistantMessage): Node {
6078 ]),
6179 );
6280 }
81+
82+ if (textBlocks.length === 0) {
83+ textBlocks.push(
84+ Text("Loading...", {
85+ fgColor: theme.bblack,
86+ italic: true,
87+ }),
88+ );
89+ }
90+
6391 return VStack({ gap: 1 }, textBlocks);
6492 }
6593
@@ -125,6 +153,27 @@ function conversationMessageNode(msg: Message): Node {
125153 ]);
126154 }
127155
156+const colors = [
157+ theme.bgreen,
158+ theme.byellow,
159+ theme.bblue,
160+ theme.bcyan,
161+ theme.bmagenta,
162+ theme.bred,
163+];
164+const randColor = colors[Math.floor(Math.random() * colors.length)];
165+
166+export function emptyState(): Node {
167+ return HStack({ flex: 1, alignItems: "center" }, [
168+ VStack({ flex: 1, alignItems: "center" }, [
169+ HStack({ gap: 1 }, [
170+ Text("mini"),
171+ TextPill("coder", theme.black, randColor),
172+ ]),
173+ ]),
174+ ]);
175+}
176+
128177 export function Conversation(state: TUIState) {
129178 return VStack(
130179 {
src/tui-editor.ts+1−1
@@ -6,7 +6,7 @@ export function Editor(
66 onChange: (value: string) => void,
77 onKeyPress: (key: string) => void,
88 ) {
9- let isEditorFocused = true;
9+ let isEditorFocused = !state.overlay;
1010 return TextInput({
1111 value: state.prompt,
1212 minHeight: 3,
src/tui-overlay.ts+71−0
@@ -0,0 +1,71 @@
1+import { cel, HStack, Text, TextInput, VStack } from "@cel-tui/core";
2+import { TextPill, theme } from "./tui-components";
3+import type { TUIState } from "./types";
4+
5+function onOverlayKeyPress(state: TUIState) {
6+ return (key: string) => {
7+ if (key === "escape" || key === "ctrl+p") {
8+ state.overlay = false;
9+ }
10+ };
11+}
12+
13+function onChange() {}
14+function onEditorKeyPress(_key: string) {}
15+
16+export function SelectEditor(value: string) {
17+ let isEditorFocused = true;
18+ return TextInput({
19+ value,
20+ minHeight: 3,
21+ maxHeight: 10,
22+ padding: { x: 1 },
23+ placeholder: Text("Search...", { fgColor: theme.bblack, italic: true }),
24+ fgColor: theme.bblack,
25+ bgColor: theme.white,
26+ onChange,
27+ onKeyPress: onEditorKeyPress,
28+ // TODO: Update `cel-tui` with an autofocus prop to fix this pattern
29+ focused: isEditorFocused,
30+ onFocus: () => {
31+ isEditorFocused = true;
32+ cel.render();
33+ },
34+ onBlur: () => {
35+ isEditorFocused = false;
36+ cel.render();
37+ },
38+ });
39+}
40+
41+export function SelectOverlay(state: TUIState, filter: string, list: string[]) {
42+ return VStack(
43+ {
44+ height: "100%",
45+ justifyContent: "end",
46+ onKeyPress: onOverlayKeyPress(state),
47+ },
48+ [
49+ VStack(
50+ {
51+ bgColor: theme.white,
52+ fgColor: theme.bblack,
53+ gap: 1,
54+ padding: { x: 1, y: 1 },
55+ },
56+ [
57+ VStack(
58+ { flex: 1, minHeight: 5, maxHeight: 20, padding: {x: 1} },
59+ list.map((i) => {
60+ return Text(i);
61+ }),
62+ ), // list
63+ HStack({ width: "100%" }, [
64+ TextPill("SELECT", theme.bwhite, theme.bblack),
65+ ]),
66+ SelectEditor(filter),
67+ ],
68+ ),
69+ ],
70+ );
71+}
src/tui.ts+69−56
@@ -19,8 +19,9 @@ import {
1919 TextPill,
2020 theme,
2121 } from "./tui-components";
22-import { Conversation } from "./tui-conversation";
22+import { Conversation, emptyState } from "./tui-conversation";
2323 import { Editor } from "./tui-editor";
24+import { SelectOverlay } from "./tui-overlay";
2425 import type { AgentContex, ToolAndRunner, TUIState } from "./types";
2526
2627 const git = simpleGit();
@@ -55,62 +56,74 @@ export function initTUI(state: TUIState, leave: (s: string) => void) {
5556
5657 cel.init(new ProcessTerminal());
5758
58- cel.viewport(() =>
59- VStack(
60- {
61- height: "100%",
62- gap: 1,
63- padding: { x: 1, y: 1 },
64- onKeyPress: (key) => {
65- if (key === "ctrl+q" || key === "ctrl+c" || key === "ctrl+d") {
66- // Quit
67- clearInterval(baseFramerateIntervalId);
68- cel.stop();
69- leave("Done.");
70- } else if (key === "escape") {
71- // Abort or clear prompt
72- clearOrAbort(state);
73- }
59+ const onWindowKeyPress = (key: string) => {
60+ if (key === "ctrl+q" || key === "ctrl+c" || key === "ctrl+d") {
61+ // Quit
62+ clearInterval(baseFramerateIntervalId);
63+ cel.stop();
64+ leave("Done.");
65+ } else if (key === "escape") {
66+ // Abort or clear prompt
67+ clearOrAbort(state);
68+ } else if (key === "ctrl+p") {
69+ state.overlay = true;
70+ }
71+ };
72+
73+ const onChange = (value: string) => {
74+ state.prompt = value;
75+ };
76+
77+ const onEditorKeyPress = (key: string) => {
78+ // onKeyPress
79+ if (key === "enter") {
80+ if (state.prompt === ":q") {
81+ clearInterval(baseFramerateIntervalId);
82+ cel.stop();
83+ leave("Done. I like vim too.");
84+ return false;
85+ }
86+ const submit = async () => {
87+ await streamAgentTUI(state);
88+ };
89+ if (state.prompt && !state.streaming) submit();
90+ return false;
91+ }
92+ };
93+
94+ cel.viewport(() => {
95+ const layers = [
96+ VStack(
97+ {
98+ height: "100%",
99+ gap: 1,
100+ padding: { x: 1, y: 1 },
101+ onKeyPress: onWindowKeyPress,
74102 },
75- },
76- [
77- Conversation(state),
78-
79- HStack({ gap: 1 }, [
80- ModelPill(state),
81- TextPill(`../${state.cwd}`, theme.bwhite, theme.bblack),
82- GitPill(state),
83- VStack({ flex: 1 }, []),
84- ActivityPill(state, currentSpinner()),
85- ContextPill(state),
86- ]),
87-
88- Editor(
89- state,
90- (value: string) => {
91- // onChange
92- state.prompt = value;
93- },
94- (key: string) => {
95- // onKeyPress
96- if (key === "enter") {
97- if (state.prompt === ":q") {
98- clearInterval(baseFramerateIntervalId);
99- cel.stop();
100- leave("Done. I like vim too.");
101- return false;
102- }
103- const submit = async () => {
104- await streamAgentTUI(state);
105- };
106- if (state.prompt && !state.streaming) submit();
107- return false;
108- }
109- },
110- ),
111- ],
112- ),
113- );
103+ [
104+ state.messages.length ? Conversation(state) : emptyState(),
105+ HStack({ gap: 1 }, [
106+ ModelPill(state),
107+ TextPill(`../${state.cwd}`, theme.bwhite, theme.bblack),
108+ GitPill(state),
109+ VStack({ flex: 1 }, []),
110+ ActivityPill(state, currentSpinner()),
111+ ContextPill(state),
112+ ]),
113+
114+ Editor(state, onChange, onEditorKeyPress),
115+ ],
116+ ),
117+ ];
118+ if (state.overlay) {
119+ // TODO: Use the new select overlay for menus
120+ layers.push(SelectOverlay(state, state.prompt, [
121+ "> Models", "Effort"
122+ ]));
123+ }
124+
125+ return layers;
126+ });
114127 }
115128
116129 async function streamAgentTUI(state: TUIState) {
src/types.ts+1−0
@@ -82,6 +82,7 @@ export type TUIState = {
8282 abortController?: AbortController;
8383 cwd: string;
8484 gitBranch?: string;
85+ overlay?: boolean | undefined;
8586 };
8687
8788 export type AgentContex = {