xonecas.io
64875
Mc

mini-coder / commit 1232496

feat: persist active agent across sessions

This feature saves the active agent to the SQLite settings database when set via /agent and loads it automatically on startup. The active agent state correctly falls back to null if it has been overridden by CLI arguments, or if the stored custom agent has been deleted.

xonecas2026-03-11 12324963ac5dd843e5f6fd0a1d948e0f360c39e5 parent 691f28c

4 files changed

AGENTS.md+1−2
@@ -5,11 +5,10 @@
55 - README.md is cosmetic for users, don't edit unless asked to.
66 - Write minimal tests, focused on our code's logic. Never test dependencies. Never use mock servers or stubs.
77 - Keep the repo pristine: no failing tests, no lint, no build issues, no `nolint:` comments.
8-- Use `bun run jscpd && bun run knip && bun run typecheck && bun run format && bun run lint && bun test` to check your changes.
8+- Use `bun run jscpd && bun run knip && bun run typecheck && bun run format && bun run lint && bun run test` to check your changes.
99 - We care about performance.
1010 - Don't worry about formatting issues, formatting happens automatically on mutations. (see .agents/hooks)
1111 - Do not inline `import` calls. Don't duplicate code. Don't leave dead code behind.
1212 - Don't make random test files, if you need to test something, write a propper unit test.
1313 - If you make temp files, clean them up when you are done.
1414 - Use Conventional Commits formatting for commit messages.
15-
TODO.md+3−2
@@ -1,7 +1,8 @@
11 # TODO
22
3-- Investigate why orc subagent never calls subgents.
4-- Rememeber active agent accross sessions.
3+- Investigate why orc subagent never calls subagents.
4+- Remember active agent across sessions.
5+- When a command spawns a subagent, there is no spinner shown
56
67 ## Investigate error:
78
src/agent/agent.ts+15−1
@@ -6,7 +6,9 @@ import { getContextWindow, type ThinkingEffort } from "../llm-api/providers.ts";
66 import type { ToolDef } from "../llm-api/types.ts";
77 import { connectMcpServer } from "../mcp/client.ts";
88 import {
9+ getPreferredActiveAgent,
910 listMcpServers,
11+ setPreferredActiveAgent,
1012 setPreferredModel,
1113 setPreferredThinkingEffort,
1214 } from "../session/db/index.ts";
@@ -101,7 +103,18 @@ export async function runAgent(
101103 });
102104
103105 // Active primary agent state — name only; the system prompt is stored on runner.
104- let activeAgentName: string | null = null;
106+ let activeAgentName: string | null = getPreferredActiveAgent();
107+ if (opts.agentSystemPrompt) {
108+ activeAgentName = null;
109+ } else if (activeAgentName) {
110+ const agentCfg = agents.get(activeAgentName);
111+ if (agentCfg) {
112+ runner.extraSystemPrompt = agentCfg.systemPrompt;
113+ } else {
114+ activeAgentName = null;
115+ setPreferredActiveAgent(null);
116+ }
117+ }
105118
106119 const cmdCtx: CommandContext = {
107120 get currentModel() {
@@ -142,6 +155,7 @@ export async function runAgent(
142155 setActiveAgent: (name, systemPrompt?) => {
143156 activeAgentName = name;
144157 runner.extraSystemPrompt = systemPrompt;
158+ setPreferredActiveAgent(name);
145159 },
146160
147161 undoLastTurn: () =>
src/session/db/settings-repo.ts+11−0
@@ -42,3 +42,14 @@ export function setPreferredThinkingEffort(
4242 setSetting("preferred_thinking_effort", effort);
4343 }
4444 }
45+export function getPreferredActiveAgent(): string | null {
46+ return getSetting("preferred_active_agent");
47+}
48+
49+export function setPreferredActiveAgent(agent: string | null): void {
50+ if (agent === null) {
51+ getDb().run("DELETE FROM settings WHERE key = 'preferred_active_agent'");
52+ } else {
53+ setSetting("preferred_active_agent", agent);
54+ }
55+}