xonecas.io
64875
Mc

mini-coder / commit b0caa32

fix: post-rename cleanup and /new session reset

- insert.ts: update stale tool refs in description and error (edit->replace, write->create)
- agent.ts: reset lastContextTokens on /new, move status bar render to top of REPL loop
- output.ts: truncate session ID to 8 chars in status bar; fix status bar to stdout
- providers.ts: remove dead _zenGoogle const
- replace.ts: rename internal types EditSchema/Input/Output -> ReplaceSchema/Input/Output
- create.ts: rename internal types WriteSchema/Input/Output -> CreateSchema/Input/Output

xonecas2026-02-20 b0caa32c4bc9e0c6d9888d60932dd547294f56cf parent 4f63797

6 files changed

src/agent/agent.ts+13−4
@@ -327,11 +327,13 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
327327 turnIndex = 1;
328328 totalIn = 0;
329329 totalOut = 0;
330+ lastContextTokens = 0;
330331 },
331332 };
332333 const spinner = new Spinner();
333334 let totalIn = 0;
334335 let totalOut = 0;
336+ let lastContextTokens = 0;
335337
336338 // ── Handle initial prompt (non-interactive) ────────────────────────────────
337339 if (opts.initialPrompt) {
@@ -340,6 +342,10 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
340342
341343 // ── REPL ──────────────────────────────────────────────────────────────────
342344 while (true) {
345+ // Render the status bar to stdout before drawing the prompt so both are on
346+ // the same stream, guaranteeing correct ordering (no stderr/stdout race).
347+ await renderStatusBarForSession();
348+
343349 let input: InputResult;
344350 try {
345351 input = await readline({ cwd });
@@ -455,9 +461,12 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
455461
456462 totalIn += inputTokens;
457463 totalOut += outputTokens;
464+ lastContextTokens = contextTokens;
458465 touchActiveSession(session);
466+ }
459467
460- // Render status bar
468+ // ── Render status bar (called before each prompt) ──────────────────────────
469+ async function renderStatusBarForSession(): Promise<void> {
461470 const branch = await getGitBranch(cwd);
462471 const provider = currentModel.split("/")[0] ?? "";
463472 const modelShort = currentModel.split("/").slice(1).join("/");
@@ -471,9 +480,9 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
471480 cwd: cwdDisplay,
472481 gitBranch: branch,
473482 sessionId: session.id,
474- inputTokens,
475- outputTokens,
476- contextTokens,
483+ inputTokens: totalIn,
484+ outputTokens: totalOut,
485+ contextTokens: lastContextTokens,
477486 contextWindow: getContextWindow(currentModel),
478487 });
479488 }
src/cli/output.ts+5−4
@@ -458,7 +458,8 @@ export async function renderTurn(
458458 }
459459
460460 // ─── Status bar ───────────────────────────────────────────────────────────────
461-// Rendered to stderr so it doesn't pollute stdout / pipes.
461+// Rendered to stdout so it appears on the same stream as the prompt, guaranteeing
462+// it is flushed before readline draws the input line.
462463 // Format: model provider cwd ⎇branch ↑in ↓out
463464
464465 export function renderStatusBar(opts: {
@@ -472,12 +473,12 @@ export function renderStatusBar(opts: {
472473 contextTokens: number;
473474 contextWindow: number | null;
474475 }): void {
475- const cols = (process.stderr as NodeJS.WriteStream).columns ?? 80;
476+ const cols = (process.stdout as NodeJS.WriteStream).columns ?? 80;
476477
477478 // Build segments from right priority (rightmost items drop first)
478479 const left: string[] = [c.cyan(opts.model)];
479480 if (opts.provider && opts.provider !== "zen") left.push(c.dim(opts.provider));
480- left.push(c.dim(opts.sessionId));
481+ left.push(c.dim(opts.sessionId.slice(0, 8)));
481482
482483 const right: string[] = [];
483484 if (opts.inputTokens > 0 || opts.outputTokens > 0) {
@@ -514,7 +515,7 @@ export function renderStatusBar(opts: {
514515
515516 const out = visible.length > cols ? truncateAnsi(full, cols - 1) : full;
516517
517- process.stderr.write(`\r\x1B[2K${out}\n`);
518+ process.stdout.write(`${out}\n`);
518519 }
519520
520521 // ─── Banner ───────────────────────────────────────────────────────────────────
src/llm-api/providers.ts+0−1
@@ -45,7 +45,6 @@ const ZEN_GOOGLE_MODELS = new Set([
4545
4646 let _zenAnthropic: ReturnType<typeof createAnthropic> | null = null;
4747 let _zenOpenAI: ReturnType<typeof createOpenAI> | null = null;
48-const _zenGoogle: ReturnType<typeof createGoogleGenerativeAI> | null = null;
4948 let _zenCompat: ReturnType<typeof createOpenAICompatible> | null = null;
5049
5150 function getZenApiKey(): string {
src/tools/create.ts+5−5
@@ -4,26 +4,26 @@ import { z } from "zod";
44 import type { ToolDef } from "../llm-api/types.ts";
55 import { generateDiff } from "./diff.ts";
66
7-const WriteSchema = z.object({
7+const CreateSchema = z.object({
88 path: z.string().describe("File path to write (absolute or relative to cwd)"),
99 content: z.string().describe("Full content to write to the file"),
1010 });
1111
12-type WriteInput = z.infer<typeof WriteSchema> & { cwd?: string };
12+type CreateInput = z.infer<typeof CreateSchema> & { cwd?: string };
1313
14-export interface WriteOutput {
14+export interface CreateOutput {
1515 path: string;
1616 diff: string;
1717 created: boolean;
1818 }
1919
20-export const createTool: ToolDef<WriteInput, WriteOutput> = {
20+export const createTool: ToolDef<CreateInput, CreateOutput> = {
2121 name: "create",
2222 description:
2323 "Create a new file or fully overwrite an existing file with the given content. " +
2424 "Use this only for new files. " +
2525 "For targeted line edits on existing files, **use `replace` or `insert` instead**.",
26- schema: WriteSchema,
26+ schema: CreateSchema,
2727 execute: async (input) => {
2828 const cwd = input.cwd ?? process.cwd();
2929 const filePath = input.path.startsWith("/")
src/tools/insert.ts+2−2
@@ -31,7 +31,7 @@ export const insertTool: ToolDef<InsertInput, InsertOutput> = {
3131 "Insert new lines before or after an anchor line in an existing file. " +
3232 "The anchor line itself is not modified. " +
3333 'Anchors come from the `read` or `grep` tools (format: "line:hash", e.g. "11:a3"). ' +
34- "To replace or delete lines use `edit`. To create a file use `write`.",
34+ "To replace or delete lines use `replace`. To create a file use `create`.",
3535 schema: InsertSchema,
3636 execute: async (input) => {
3737 const cwd = input.cwd ?? process.cwd();
@@ -44,7 +44,7 @@ export const insertTool: ToolDef<InsertInput, InsertOutput> = {
4444 const file = Bun.file(filePath);
4545 if (!(await file.exists())) {
4646 throw new Error(
47- `File not found: "${relPath}". To create a new file use the \`write\` tool.`,
47+ `File not found: "${relPath}". To create a new file use the \`create\` tool.`,
4848 );
4949 }
5050
src/tools/replace.ts+5−5
@@ -4,7 +4,7 @@ import type { ToolDef } from "../llm-api/types.ts";
44 import { generateDiff } from "./diff.ts";
55 import { findLineByHash } from "./hashline.ts";
66
7-const EditSchema = z.object({
7+const ReplaceSchema = z.object({
88 path: z.string().describe("File path to edit (absolute or relative to cwd)"),
99 startAnchor: z
1010 .string()
@@ -23,9 +23,9 @@ const EditSchema = z.object({
2323 ),
2424 });
2525
26-type EditInput = z.infer<typeof EditSchema> & { cwd?: string };
26+type ReplaceInput = z.infer<typeof ReplaceSchema> & { cwd?: string };
2727
28-export interface EditOutput {
28+export interface ReplaceOutput {
2929 path: string;
3030 diff: string;
3131 }
@@ -33,7 +33,7 @@ export interface EditOutput {
3333 const HASH_NOT_FOUND_ERROR =
3434 "Hash not found. Re-read the file to get current anchors.";
3535
36-export const replaceTool: ToolDef<EditInput, EditOutput> = {
36+export const replaceTool: ToolDef<ReplaceInput, ReplaceOutput> = {
3737 name: "replace",
3838 description:
3939 "Replace or delete a range of lines in an existing file using hashline anchors. " +
@@ -41,7 +41,7 @@ export const replaceTool: ToolDef<EditInput, EditOutput> = {
4141 "Provide startAnchor alone to target a single line, or add endAnchor for a range. " +
4242 "Set newContent to the replacement text, or omit it to delete the range. " +
4343 "To create a file use `create`. To insert without replacing any lines use `insert`.",
44- schema: EditSchema,
44+ schema: ReplaceSchema,
4545 execute: async (input) => {
4646 const cwd = input.cwd ?? process.cwd();
4747 const filePath = input.path.startsWith("/")