xonecas.io
64875
Mc

mini-coder / commit 0a17287

refactor: remove /ralph autonomous loop command

xonecas2026-03-14 0a172877929e950081f8e93565e36e51c1097aaa parent 1580443

12 files changed

README.md+1−1
@@ -47,7 +47,7 @@ Need more firepower? I connect to **MCP servers** over HTTP or stdio — bolt on
4747 - **Built-in web search** — set `EXA_API_KEY` and I expose `webSearch` + `webContent` tools.
4848 - **Session memory** — conversations are saved in a local SQLite database. Resume where you left off with `-c` or pick a specific session with `-r <id>`.
4949 - **Shell integration** — prefix with `!` to run shell commands inline. Use `@` to reference files in your prompt (with Tab completion).
50-- **Slash commands** — `/model` or `/models` to list/switch models, `/model effort <low|medium|high|xhigh|off>` for reasoning effort, `/reasoning [on|off]` to toggle reasoning display, `/context` to inspect or tune pruning/tool-result caps, `/plan` for read-only thinking mode, `/ralph` for autonomous looping, `/review` for a code review (global custom command, auto-created at `~/.agents/commands/review.md`), `/agent [name]` to set or clear an active primary agent, `/undo` to roll back a turn, …
50+- **Slash commands** — `/model` or `/models` to list/switch models, `/model effort <low|medium|high|xhigh|off>` for reasoning effort, `/reasoning [on|off]` to toggle reasoning display, `/context` to inspect or tune pruning/tool-result caps, `/plan` for read-only thinking mode, `/review` for a code review (global custom command, auto-created at `~/.agents/commands/review.md`), `/agent [name]` to set or clear an active primary agent, `/undo` to roll back a turn, `/new` for a clean session, `/mcp …
5151
5252 - **Custom commands** — drop a `.md` file in `.agents/commands/` and it becomes a `/command`. Claude-compatible `.claude/commands/` works too. Supports argument placeholders (`$ARGUMENTS`, `$1`…`$9`) and shell interpolation (`` !`cmd` ``). Global commands live in `~/.agents/commands/` and `~/.claude/commands/`. Custom commands take precedence over built-ins. → [docs/custom-commands.md](docs/custom-commands.md)
5353 - **Custom agents** — drop a `.md` file in `.agents/agents/` or `.claude/agents/` (or `~/.agents/agents/` / `~/.claude/agents/` globally) and activate it with `/agent [name]`. Agent definitions are also exposed to subagent delegation unless `mode: primary`. `@agent-name` is supported for completion and is a useful prompt convention. → [docs/custom-agents.md](docs/custom-agents.md)
docs/mini-coder.1.md+0−4
@@ -64,9 +64,6 @@ Inside the interactive session, the following slash commands are available:
6464 **/plan**
6565 : Toggle read-only planning mode.
6666
67-**/ralph**
68-: Toggle autonomous execution looping.
69-
7067 **/undo**
7168 : Revert the last turn and restore files.
7269
@@ -149,7 +146,6 @@ The agent has access to the following tools:
149146 * **Multi-Provider LLM Routing**: Automatically discovers API keys to route to OpenCode (Zen), Anthropic, OpenAI, Google/Gemini, or local Ollama instances.
150147 * **Session Memory**: Persists conversation history in a local SQLite database, allowing users to resume past sessions effortlessly.
151148 * **Subagent Delegation**: Includes a tool to spawn parallel instances of itself to tackle independent subtasks simultaneously (up to 10 levels deep).
152-* **Autonomous Mode (Ralph)**: An autonomous looping mode that runs tasks in an isolated context loop (up to 20 iterations) until completion.
153149 * **Plan Mode**: A read-only thinking mode utilizing read tools + MCP, safely analyzing code without making mutations or executing shell commands.
154150 * **Model Context Protocol (MCP)**: Native support for connecting external tools via MCP servers over HTTP or stdio.
155151 * **Prompt Caching**: Configurable caching behaviors for supported providers (OpenAI, Gemini).
src/agent/agent-helpers.ts+0−8
@@ -42,11 +42,3 @@ export function extractAssistantText(newMessages: CoreMessage[]): string {
4242 }
4343 return parts.join("\n");
4444 }
45-
46-export function hasRalphSignal(text: string): boolean {
47- return /\/ralph\b/.test(text);
48-}
49-
50-export function buildRalphIterationPrompt(goal: string): string {
51- return `${goal}\n\n<system-message>RALPH MODE: Work autonomously toward the goal. **Only when the task is fully complete**, output \`/ralph\` as your final message.</system-message>`;
52-}
src/agent/agent.test.ts+8−48
@@ -1,10 +1,6 @@
11 import { describe, expect, test } from "bun:test";
22 import type { CoreMessage } from "../llm-api/turn.ts";
3-import {
4- extractAssistantText,
5- hasRalphSignal,
6- makeInterruptMessage,
7-} from "./agent-helpers.ts";
3+import { extractAssistantText, makeInterruptMessage } from "./agent-helpers.ts";
84
95 // ─── extractAssistantText ─────────────────────────────────────────────────────
106
@@ -19,10 +15,8 @@ describe("extractAssistantText", () => {
1915 });
2016
2117 test("extracts string content from an assistant message", () => {
22- const msgs: CoreMessage[] = [
23- { role: "assistant", content: "All done. /ralph" },
24- ];
25- expect(extractAssistantText(msgs)).toBe("All done. /ralph");
18+ const msgs: CoreMessage[] = [{ role: "assistant", content: "All done." }];
19+ expect(extractAssistantText(msgs)).toBe("All done.");
2620 });
2721
2822 test("extracts text parts from array content", () => {
@@ -42,11 +36,9 @@ describe("extractAssistantText", () => {
4236 const msgs: CoreMessage[] = [
4337 { role: "user", content: "go" },
4438 { role: "assistant", content: "Fixing the bug." },
45- { role: "assistant", content: "All done. /ralph" },
39+ { role: "assistant", content: "All done." },
4640 ];
47- expect(extractAssistantText(msgs)).toBe(
48- "Fixing the bug.\nAll done. /ralph",
49- );
41+ expect(extractAssistantText(msgs)).toBe("Fixing the bug.\nAll done.");
5042 });
5143
5244 test("returns empty string when assistant message has no text parts", () => {
@@ -61,50 +53,18 @@ describe("extractAssistantText", () => {
6153 expect(extractAssistantText(msgs)).toBe("");
6254 });
6355
64- test("captures /ralph even when the last content part is a tool call", () => {
56+ test("extracts text from array content when last part is a tool call", () => {
6557 // Typical agentic pattern: text block followed by a trailing tool call
6658 const msgs: CoreMessage[] = [
6759 {
6860 role: "assistant",
6961 content: [
70- { type: "text", text: "Tests pass. /ralph" },
62+ { type: "text", text: "Tests pass." },
7163 { type: "tool-call", toolCallId: "1", toolName: "shell", input: {} },
7264 ],
7365 },
7466 ];
75- expect(extractAssistantText(msgs)).toBe("Tests pass. /ralph");
76- });
77-});
78-
79-// ─── hasRalphSignal ───────────────────────────────────────────────────────────
80-
81-describe("hasRalphSignal", () => {
82- test("returns false for empty string", () => {
83- expect(hasRalphSignal("")).toBe(false);
84- });
85-
86- test("returns true for bare /ralph", () => {
87- expect(hasRalphSignal("/ralph")).toBe(true);
88- });
89-
90- test("returns true when /ralph has trailing whitespace", () => {
91- expect(hasRalphSignal("/ralph \n")).toBe(true);
92- });
93-
94- test("returns true when /ralph is preceded by prose", () => {
95- expect(hasRalphSignal("All tests pass. /ralph")).toBe(true);
96- });
97-
98- test("returns true when /ralph appears mid-text", () => {
99- expect(hasRalphSignal("Done. /ralph\nSee you.")).toBe(true);
100- });
101-
102- test("returns false when /ralphy (not a word boundary)", () => {
103- expect(hasRalphSignal("/ralphy")).toBe(false);
104- });
105-
106- test("returns false for unrelated text", () => {
107- expect(hasRalphSignal("I finished the task.")).toBe(false);
67+ expect(extractAssistantText(msgs)).toBe("Tests pass.");
10868 });
10969 });
11070
src/agent/agent.ts+0−6
@@ -196,12 +196,6 @@ export async function initAgent(opts: AgentOptions): Promise<{
196196 runner.googleCachedContent = contentId;
197197 setPreferredGoogleCachedContent(contentId);
198198 },
199- get ralphMode() {
200- return runner.ralphMode;
201- },
202- setRalphMode: (v) => {
203- runner.ralphMode = v;
204- },
205199 cwd,
206200 runSubagent: (prompt, agentName?, model?, abortSignal?) =>
207201 runSubagent(prompt, agentName, model, abortSignal),
src/agent/reporter.ts+0−1
@@ -19,7 +19,6 @@ export interface StatusBarData {
1919 outputTokens: number;
2020 contextTokens: number;
2121 contextWindow: number;
22- ralphMode: boolean;
2322 thinkingEffort?: string | null;
2423 activeAgent?: string | null;
2524 showReasoning?: boolean;
src/agent/session-runner.ts+0−2
@@ -75,8 +75,6 @@ export class SessionRunner {
7575 }
7676 }
7777
78- public ralphMode = false;
79-
8078 public totalIn = 0;
8179 public totalOut = 0;
8280 public lastContextTokens = 0;
src/cli/commands.ts+0−19
@@ -299,17 +299,6 @@ function handleCache(ctx: CommandContext, args: string): void {
299299 writeln(`${PREFIX.error} usage: /cache <on|off|openai|gemini> ...`);
300300 }
301301
302-function handleRalph(ctx: CommandContext): void {
303- ctx.setRalphMode(!ctx.ralphMode);
304- if (ctx.ralphMode) {
305- writeln(
306- `${PREFIX.info} ${c.magenta("ralph mode")} ${c.dim("— loops until done, fresh context each iteration")}`,
307- );
308- } else {
309- writeln(`${PREFIX.info} ${c.dim("ralph mode off")}`);
310- }
311-}
312-
313302 async function handleUndo(ctx: CommandContext): Promise<void> {
314303 const ok = await ctx.undoLastTurn();
315304 if (ok) {
@@ -566,10 +555,6 @@ function handleHelp(
566555 ["/undo", "remove the last turn from conversation history"],
567556 ["/reasoning [on|off]", "toggle display of model reasoning output"],
568557 ["/context [prune|cap]", "configure context pruning and tool-result caps"],
569- [
570- "/ralph",
571- "toggle ralph mode (autonomous loop, fresh context each iteration)",
572- ],
573558 ["/agent [name]", "set or clear active primary agent"],
574559 ["/mcp list", "list MCP servers"],
575560 ["/mcp add <n> <t> [u]", "add an MCP server"],
@@ -683,10 +668,6 @@ export async function handleCommand(
683668 handleCache(ctx, args);
684669 return { type: "handled" };
685670
686- case "ralph":
687- handleRalph(ctx);
688- return { type: "handled" };
689-
690671 case "agent":
691672 handleAgent(ctx, args);
692673 return { type: "handled" };
src/cli/input-loop.ts+7−66
@@ -1,10 +1,7 @@
11 import * as c from "yoctocolors";
2-import {
3- buildRalphIterationPrompt,
4- hasRalphSignal,
5-} from "../agent/agent-helpers.ts";
62 import type { AgentReporter } from "../agent/reporter.ts";
73 import type { SessionRunner } from "../agent/session-runner.ts";
4+
85 import { getContextWindow } from "../llm-api/providers.ts";
96 import type { CoreMessage } from "../llm-api/turn.ts";
107 import { saveMessages } from "../session/db/index.ts";
@@ -12,7 +9,8 @@ import { getGitBranch, runShellPassthrough } from "./cli-helpers.ts";
129 import { handleCommand } from "./commands.ts";
1310 import { resolveFileRefs } from "./file-refs.ts";
1411 import { type InputResult, readline } from "./input.ts";
15-import { PREFIX, tildePath } from "./output.ts";
12+import { tildePath } from "./output.ts";
13+
1614 import type { CommandContext } from "./types.ts";
1715
1816 interface InputLoopOptions {
@@ -22,8 +20,6 @@ interface InputLoopOptions {
2220 runner: SessionRunner;
2321 }
2422
25-const RALPH_MAX_ITERATIONS = 20;
26-
2723 export async function runInputLoop(opts: InputLoopOptions): Promise<void> {
2824 const { cwd, reporter, cmdCtx, runner } = opts;
2925
@@ -43,7 +39,6 @@ export async function runInputLoop(opts: InputLoopOptions): Promise<void> {
4339 outputTokens: runner.totalOut,
4440 contextTokens: runner.lastContextTokens,
4541 contextWindow: getContextWindow(runner.currentModel) ?? 0,
46- ralphMode: runner.ralphMode,
4742 thinkingEffort: runner.currentThinkingEffort,
4843 activeAgent: cmdCtx.activeAgent,
4944 showReasoning: runner.showReasoning,
@@ -53,7 +48,6 @@ export async function runInputLoop(opts: InputLoopOptions): Promise<void> {
5348 try {
5449 input = await readline({
5550 cwd,
56- ralphMode: runner.ralphMode,
5751 });
5852 } catch {
5953 break;
@@ -107,63 +101,10 @@ export async function runInputLoop(opts: InputLoopOptions): Promise<void> {
107101 cwd,
108102 );
109103 const allImages = [...(input.images || []), ...refImages];
110-
111- if (!runner.ralphMode) {
112- try {
113- await runner.processUserInput(resolvedText, allImages);
114- } catch {
115- // Error already rendered by stream-render; continue the loop.
116- }
117- continue;
118- }
119-
120- // True ralph loop: each iteration is a fresh subprocess.
121- // State persists via the filesystem and git history — NOT the context window.
122- if (allImages.length > 0) {
123- reporter.writeText(
124- `${PREFIX.info} ${c.yellow("ralph")} ${c.dim("— image attachments are not supported and will be ignored")}`,
125- );
126- }
127- const ralphGoal = buildRalphIterationPrompt(resolvedText);
128-
129- for (
130- let iteration = 1;
131- iteration <= RALPH_MAX_ITERATIONS;
132- iteration++
133- ) {
134- reporter.writeText(
135- `${PREFIX.info} ${c.magenta("ralph")} ${c.dim(`— iteration ${String(iteration)}`)}`,
136- );
137-
138- let result: string;
139- try {
140- cmdCtx.startSpinner("ralph");
141- const output = await cmdCtx.runSubagent(ralphGoal);
142- result = output.result;
143- cmdCtx.stopSpinner();
144- } catch (err) {
145- cmdCtx.stopSpinner();
146- reporter.writeText(
147- `${PREFIX.info} ${c.yellow("ralph")} ${c.dim(`— iteration ${String(iteration)} failed: ${String(err)}`)}`,
148- );
149- runner.ralphMode = false;
150- break;
151- }
152-
153- if (hasRalphSignal(result)) {
154- reporter.writeText(
155- `${PREFIX.info} ${c.dim("ralph — task complete")}`,
156- );
157- runner.ralphMode = false;
158- break;
159- }
160-
161- if (iteration === RALPH_MAX_ITERATIONS) {
162- reporter.writeText(
163- `${PREFIX.info} ${c.yellow("ralph")} ${c.dim("— max iterations reached, stopping")}`,
164- );
165- runner.ralphMode = false;
166- }
104+ try {
105+ await runner.processUserInput(resolvedText, allImages);
106+ } catch {
107+ // Error already rendered by stream-render; continue the loop.
167108 }
168109 continue;
169110 }
src/cli/input.ts+3−7
@@ -384,14 +384,10 @@ export function buildPromptDisplay(
384384 // ─── Main readline function ───────────────────────────────────────────────────
385385
386386 const PROMPT = c.green("▶ ");
387-const PROMPT_RALPH = c.magenta("↻ ");
388387
389-const PROMPT_RAW_LEN = 2; // both prompts are 2 visible chars
388+const PROMPT_RAW_LEN = 2; // prompt is 2 visible chars
390389
391-export async function readline(opts: {
392- cwd?: string;
393- ralphMode?: boolean;
394-}): Promise<InputResult> {
390+export async function readline(opts: { cwd?: string }): Promise<InputResult> {
395391 const cwd = opts.cwd ?? process.cwd();
396392
397393 // Load history
@@ -448,7 +444,7 @@ export async function readline(opts: {
448444 Math.max(1, cols - PROMPT_RAW_LEN - 2),
449445 );
450446
451- const prompt = opts.ralphMode ? PROMPT_RALPH : PROMPT;
447+ const prompt = PROMPT;
452448
453449 process.stdout.write(
454450 `${CLEAR_LINE}${prompt}${display}${CSI}${PROMPT_RAW_LEN + displayCursor + 1}G`,
src/cli/status-bar.ts+0−2
@@ -41,7 +41,6 @@ export function renderStatusBar(opts: {
4141 outputTokens: number;
4242 contextTokens: number;
4343 contextWindow: number | null;
44- ralphMode?: boolean;
4544 thinkingEffort?: string | null;
4645 activeAgent?: string | null;
4746 showReasoning?: boolean;
@@ -54,7 +53,6 @@ export function renderStatusBar(opts: {
5453 if (opts.showReasoning) left.push(c.dim("🤔"));
5554 if (opts.provider && opts.provider !== "zen") left.push(c.dim(opts.provider));
5655 left.push(c.dim(opts.sessionId.slice(0, 8)));
57- if (opts.ralphMode) left.push(c.magenta("↻ ralph"));
5856 if (opts.activeAgent) left.push(c.green(`@${opts.activeAgent}`));
5957
6058 const right: string[] = [];
src/cli/types.ts+0−2
@@ -19,8 +19,6 @@ export interface CommandContext {
1919 setOpenAIPromptCacheRetention: (retention: "in_memory" | "24h") => void;
2020 googleCachedContent: string | null;
2121 setGoogleCachedContent: (contentId: string | null) => void;
22- ralphMode: boolean;
23- setRalphMode: (enabled: boolean) => void;
2422 undoLastTurn: () => Promise<boolean>;
2523 startNewSession: () => void;