xonecas.io
64875
Mc

mini-coder / commit 65e50ca

chore: add knip to check for unused code

Adds knip to package.json scripts and fixes all currently unused exports and dead code detected by knip.

xonecas2026-03-08 65e50ca25188bfb3deeb8ec75aee861e22ef9bf8 parent 1d8ed9c

27 files changed

AGENTS.md+1−1
@@ -5,7 +5,7 @@
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 typecheck && bun run format && bun run lint && bun test` to check your changes.
8+- Use `bun run knip && bun run typecheck && bun run format && bun run lint && bun 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.
package.json+2−0
@@ -13,6 +13,7 @@
1313 "typecheck": "tsc --noEmit",
1414 "lint": "biome check src",
1515 "format": "biome format --write src",
16+ "knip": "knip",
1617 "test": "bun test"
1718 },
1819 "dependencies": {
@@ -30,6 +31,7 @@
3031 "devDependencies": {
3132 "@biomejs/biome": "^1.9.4",
3233 "@types/bun": "latest",
34+ "knip": "^5.86.0",
3335 "typescript": "^5.8.3"
3436 },
3537 "license": "MIT"
src/agent/agent.ts+1−1
@@ -22,7 +22,7 @@ import { getGitBranch } from "./agent-helpers.ts";
2222 import { runInputLoop } from "./input-loop.ts";
2323 import { SessionRunner } from "./session-runner.ts";
2424
25-export interface AgentOptions {
25+interface AgentOptions {
2626 model: string;
2727 cwd: string;
2828 initialThinkingEffort: ThinkingEffort | null;
src/agent/input-loop.ts+1−1
@@ -8,7 +8,7 @@ import { hasRalphSignal, runShellPassthrough } from "./agent-helpers.ts";
88 import type { AgentReporter } from "./reporter.ts";
99 import type { SessionRunner } from "./session-runner.ts";
1010
11-export interface InputLoopOptions {
11+interface InputLoopOptions {
1212 cwd: string;
1313 reporter: AgentReporter;
1414 cmdCtx: CommandContext;
src/agent/session-runner.ts+1−1
@@ -27,7 +27,7 @@ import type { AgentReporter } from "./reporter.ts";
2727 import { buildSystemPrompt } from "./system-prompt.ts";
2828 import { buildReadOnlyToolSet } from "./tools.ts";
2929
30-export interface SessionRunnerOptions {
30+interface SessionRunnerOptions {
3131 cwd: string;
3232 reporter: AgentReporter;
3333 tools: ToolDef[];
src/agent/system-prompt.ts+1−1
@@ -31,7 +31,7 @@ const CODEX_AUTONOMY = `
3131 - Do NOT ask "shall I proceed?", "shall I start?", "reply X to continue", or any equivalent. Just start.
3232 - If something is ambiguous, pick the most reasonable interpretation, implement it, and note the assumption at the end.`;
3333
34-export function isCodexModel(modelString: string): boolean {
34+function isCodexModel(modelString: string): boolean {
3535 const { modelId } = parseModelString(modelString);
3636 return modelId.includes("codex");
3737 }
src/agent/tools.ts+1−1
@@ -87,7 +87,7 @@ function withHooks<TInput extends { cwd?: string }, TOutput>(
8787
8888 // ─── Tool registry ────────────────────────────────────────────────────────────
8989
90-export const MAX_SUBAGENT_DEPTH = 3;
90+const MAX_SUBAGENT_DEPTH = 3;
9191
9292 // Names of all local tools that support hooks (MCP tools are excluded).
9393 const HOOKABLE_TOOLS = [
src/agent/undo-snapshot.ts+1−1
@@ -7,7 +7,7 @@ import {
77 } from "../tools/snapshot.ts";
88 import type { AgentReporter } from "./reporter.ts";
99
10-export interface UndoContext {
10+interface UndoContext {
1111 session: ActiveSession;
1212 coreHistory: CoreMessage[];
1313 snapshotStack: Array<number | null>;
src/cli/agents.ts+1−1
@@ -2,7 +2,7 @@
22
33 import { loadMarkdownConfigs } from "./load-markdown-configs.ts";
44
5-export interface AgentConfig {
5+interface AgentConfig {
66 name: string;
77 description: string;
88 /** Override model for this agent (optional) */
src/cli/commands.ts+1−1
@@ -41,7 +41,7 @@ export interface CommandContext {
4141 cwd: string;
4242 }
4343
44-export type CommandResult =
44+type CommandResult =
4545 | { type: "handled" }
4646 | { type: "unknown"; command: string }
4747 | { type: "exit" }
src/cli/image-types.ts+1−1
@@ -1,6 +1,6 @@
11 // ─── Shared image type constants ──────────────────────────────────────────────
22
3-export const IMAGE_EXTENSIONS = new Set([
3+const IMAGE_EXTENSIONS = new Set([
44 "png",
55 "jpg",
66 "jpeg",
src/cli/load-markdown-configs.ts+1−1
@@ -4,7 +4,7 @@ import { basename, join } from "node:path";
44 import { warnConventionConflicts } from "./config-conflicts.ts";
55 import { type Frontmatter, parseFrontmatter } from "./frontmatter.ts";
66
7-export interface MarkdownConfigLoaderOptions<T> {
7+interface MarkdownConfigLoaderOptions<T> {
88 type: "commands" | "skills" | "agents";
99 /** Strategy for file discovery: 'flat' reads dir/*.md, 'nested' reads dir/<name>/SKILL.md */
1010 strategy: "flat" | "nested";
src/cli/markdown.ts+0−22
@@ -139,25 +139,3 @@ export function renderMarkdown(text: string): string {
139139 })
140140 .join("\n");
141141 }
142-
143-/**
144- * Render a multi-line chunk of markdown given an initial fence state.
145- * Returns the ANSI-coloured output and the fence state after the last line.
146- * Use this for chunk-based streaming where each chunk is a complete paragraph
147- * or block (delimited by blank lines).
148- */
149-export function renderChunk(
150- text: string,
151- inFence: boolean,
152-): { output: string; inFence: boolean } {
153- let fence = inFence;
154- const output = text
155- .split("\n")
156- .map((raw) => {
157- const r = renderLine(raw, fence);
158- fence = r.inFence;
159- return r.output;
160- })
161- .join("\n");
162- return { output, inFence: fence };
163-}
src/cli/output.ts+0−2
@@ -88,8 +88,6 @@ export { renderTurn } from "./stream-render.ts";
8888 export {
8989 formatSubagentLabel,
9090 renderSubagentEvent,
91- renderToolResult,
92- renderToolCall,
9391 renderHook,
9492 } from "./tool-render.ts";
9593 export { renderStatusBar } from "./status-bar.ts";
src/cli/skills.ts+1−1
@@ -2,7 +2,7 @@
22
33 import { loadMarkdownConfigs } from "./load-markdown-configs.ts";
44
5-export interface Skill {
5+interface Skill {
66 name: string;
77 description: string;
88 /** Full content of the SKILL.md (frontmatter + body) */
src/cli/terminal-io.ts+1−3
@@ -1,6 +1,4 @@
1-export type SignalHandler = () => void;
2-
3-export class TerminalIO {
1+class TerminalIO {
42 private cleanupHandlers: Set<() => void> = new Set();
53 private rawModeEnabled = false;
64 private interruptHandler: (() => void) | null = null;
src/cli/tool-render.ts+5−5
@@ -8,7 +8,7 @@ import { G, writeln } from "./output.ts";
88 const HOME = homedir();
99
1010 /** Strip the `linenum:hash| ` prefix that hashline-formatted tool outputs include. */
11-export function stripHashlinePrefix(text: string): string {
11+function stripHashlinePrefix(text: string): string {
1212 return text.replace(/^\d+:[0-9a-f]{2}\| /, "");
1313 }
1414
@@ -25,7 +25,7 @@ function commonPrefix(paths: string[]): string {
2525 return prefix;
2626 }
2727
28-export function toolGlyph(name: string): string {
28+function toolGlyph(name: string): string {
2929 if (name === "glob" || name === "grep") return G.search;
3030 if (name === "read") return G.read;
3131 if (name === "create" || name === "replace" || name === "insert")
@@ -36,7 +36,7 @@ export function toolGlyph(name: string): string {
3636 return G.info;
3737 }
3838
39-export function toolCallLine(name: string, args: unknown): string {
39+function toolCallLine(name: string, args: unknown): string {
4040 const a =
4141 args && typeof args === "object" ? (args as Record<string, unknown>) : {};
4242
@@ -112,7 +112,7 @@ export function renderHook(
112112 }
113113 }
114114
115-export function renderDiff(diff: string): void {
115+function renderDiff(diff: string): void {
116116 if (!diff || diff === "(no changes)") return;
117117 for (const line of diff.split("\n")) {
118118 if (line.startsWith("+++") || line.startsWith("---")) {
@@ -129,7 +129,7 @@ export function renderDiff(diff: string): void {
129129 }
130130 }
131131
132-export function renderToolResultInline(
132+function renderToolResultInline(
133133 toolName: string,
134134 result: unknown,
135135 isError: boolean,
src/llm-api/model-info.ts+7−7
@@ -20,7 +20,7 @@ const PROVIDER_SYNC_KEY_PREFIX = "last_provider_sync_at:";
2020
2121 export const MODEL_INFO_TTL_MS = 7 * 24 * 60 * 60 * 1000;
2222
23-export interface ModelInfo {
23+interface ModelInfo {
2424 canonicalModelId: string | null;
2525 contextWindow: number | null;
2626 reasoning: boolean;
@@ -65,7 +65,7 @@ interface RuntimeCache {
6565 state: Map<string, string>;
6666 }
6767
68-export interface ModelMatchIndex {
68+interface ModelMatchIndex {
6969 exact: Map<string, string>;
7070 alias: Map<string, string | null>;
7171 }
@@ -256,7 +256,7 @@ export function isStaleTimestamp(
256256 return now - timestamp > ttlMs;
257257 }
258258
259-export function buildRuntimeCache(
259+function buildRuntimeCache(
260260 capabilityRows: ModelCapabilityRow[],
261261 providerRows: ProviderModelRow[],
262262 stateRows: Array<{ key: string; value: string }>,
@@ -355,7 +355,7 @@ export function getProvidersToRefreshFromEnv(
355355 return [...getRemoteProvidersFromEnv(env), "ollama"];
356356 }
357357
358-export function getVisibleProvidersForSnapshotFromEnv(
358+function getVisibleProvidersForSnapshotFromEnv(
359359 env: Record<string, string | undefined>,
360360 ): ReadonlySet<string> {
361361 return new Set(getProvidersToRefreshFromEnv(env));
@@ -380,7 +380,7 @@ function getProviderSyncKey(provider: string): string {
380380 return `${PROVIDER_SYNC_KEY_PREFIX}${provider}`;
381381 }
382382
383-export function isModelInfoStale(now = Date.now()): boolean {
383+function isModelInfoStale(now = Date.now()): boolean {
384384 ensureLoaded();
385385 if (isStaleTimestamp(parseStateInt(MODELS_DEV_SYNC_KEY), now)) return true;
386386 for (const provider of getProvidersRequiredForFreshness()) {
@@ -655,7 +655,7 @@ export function refreshModelInfoInBackground(opts?: {
655655 return refreshInFlight;
656656 }
657657
658-export function isModelInfoRefreshing(): boolean {
658+function isModelInfoRefreshing(): boolean {
659659 return refreshInFlight !== null;
660660 }
661661
@@ -719,7 +719,7 @@ function resolveModelInfoInCache(
719719 return null;
720720 }
721721
722-export function resolveModelInfo(modelString: string): ModelInfo | null {
722+function resolveModelInfo(modelString: string): ModelInfo | null {
723723 ensureLoaded();
724724 return resolveModelInfoInCache(modelString, runtimeCache);
725725 }
src/llm-api/providers.ts+1−18
@@ -8,7 +8,6 @@ import { createOllama } from "ollama-ai-provider";
88 import { logApiEvent } from "./api-log.ts";
99 import {
1010 type AvailableModelsSnapshot,
11- type LiveModel,
1211 fetchAvailableModelsSnapshot,
1312 getContextWindow as getContextWindowFromCache,
1413 supportsThinking as supportsThinkingFromCache,
@@ -177,7 +176,7 @@ export function parseModelString(modelString: string): {
177176
178177 export type ThinkingEffort = "low" | "medium" | "high" | "xhigh";
179178
180-export function supportsThinking(modelString: string): boolean {
179+function supportsThinking(modelString: string): boolean {
181180 return supportsThinkingFromCache(modelString);
182181 }
183182
@@ -373,24 +372,8 @@ export function autoDiscoverModel(): string {
373372 return "ollama/llama3.2";
374373 }
375374
376-/**
377- * List all providers that appear to be configured via ENV.
378- */
379-export function availableProviders(): string[] {
380- const providers: string[] = [];
381- if (process.env.OPENCODE_API_KEY) providers.push("zen");
382- if (process.env.ANTHROPIC_API_KEY) providers.push("anthropic");
383- if (process.env.OPENAI_API_KEY) providers.push("openai");
384- if (process.env.GOOGLE_API_KEY ?? process.env.GEMINI_API_KEY)
385- providers.push("google");
386- providers.push("ollama"); // always listed (local)
387- return providers;
388-}
389-
390375 // ─── Cached model listing ─────────────────────────────────────────────────────
391376
392-export type { LiveModel };
393-
394377 export async function fetchAvailableModels(): Promise<AvailableModelsSnapshot> {
395378 return fetchAvailableModelsSnapshot();
396379 }
src/llm-api/turn.ts+0−3
@@ -1,6 +1,5 @@
11 import { dynamicTool, jsonSchema, stepCountIs, streamText } from "ai";
22 import type { FlexibleSchema, StepResult } from "ai";
3-import { z } from "zod";
43 import { logApiEvent } from "./api-log.ts";
54 import { parseModelString } from "./providers.ts";
65 import {
@@ -276,5 +275,3 @@ export async function* runTurn(options: {
276275 };
277276 }
278277 }
279-
280-export { z };
src/mcp/client.ts+2−2
@@ -7,7 +7,7 @@ import type { ToolDef } from "../llm-api/types.ts";
77
88 // ─── Types ────────────────────────────────────────────────────────────────────
99
10-export interface McpServerConfig {
10+interface McpServerConfig {
1111 name: string;
1212 /** "http" uses StreamableHTTP (with SSE fallback); "stdio" spawns a process */
1313 transport: "http" | "stdio";
@@ -17,7 +17,7 @@ export interface McpServerConfig {
1717 env?: Record<string, string>;
1818 }
1919
20-export interface McpClient {
20+interface McpClient {
2121 name: string;
2222 tools: ToolDef[];
2323 close: () => Promise<void>;
src/session/db/mcp-repo.ts+1−1
@@ -1,6 +1,6 @@
11 import { getDb } from "./connection.ts";
22
3-export interface McpServerRow {
3+interface McpServerRow {
44 name: string;
55 transport: string;
66 url: string | null;
src/session/db/model-info-repo.ts+0−9
@@ -102,15 +102,6 @@ export function replaceProviderModels(
102102 run();
103103 }
104104
105-export function getModelInfoState(key: string): string | null {
106- const row = getDb()
107- .query<{ value: string }, [string]>(
108- "SELECT value FROM model_info_state WHERE key = ?",
109- )
110- .get(key);
111- return row?.value ?? null;
112-}
113-
114105 export function setModelInfoState(key: string, value: string): void {
115106 getDb().run(
116107 `INSERT INTO model_info_state (key, value) VALUES (?, ?)
src/session/db/settings-repo.ts+2−2
@@ -1,6 +1,6 @@
11 import { getDb } from "./connection.ts";
22
3-export function getSetting(key: string): string | null {
3+function getSetting(key: string): string | null {
44 const row = getDb()
55 .query<{ value: string }, [string]>(
66 "SELECT value FROM settings WHERE key = ?",
@@ -9,7 +9,7 @@ export function getSetting(key: string): string | null {
99 return row?.value ?? null;
1010 }
1111
12-export function setSetting(key: string, value: string): void {
12+function setSetting(key: string, value: string): void {
1313 getDb().run(
1414 `INSERT INTO settings (key, value) VALUES (?, ?)
1515 ON CONFLICT(key) DO UPDATE SET value = excluded.value`,
src/tools/scan-path.ts+1−1
@@ -1,6 +1,6 @@
11 import { relative, resolve, sep } from "node:path";
22
3-export interface ScanPathInfo {
3+interface ScanPathInfo {
44 absolute: string;
55 relativePath: string;
66 ignoreTargets: readonly string[];
src/tools/worktree.ts+1−1
@@ -218,7 +218,7 @@ export async function createWorktree(
218218 return path;
219219 }
220220
221-export type MergeWorktreeResult =
221+type MergeWorktreeResult =
222222 | { success: true }
223223 | { success: false; conflictFiles: string[] };
224224
tsconfig.json+23−23
@@ -1,25 +1,25 @@
11 {
2- "compilerOptions": {
3- "target": "ESNext",
4- "module": "ESNext",
5- "moduleResolution": "bundler",
6- "lib": ["ESNext"],
7- "types": ["bun-types"],
8- "strict": true,
9- "noUncheckedIndexedAccess": true,
10- "exactOptionalPropertyTypes": true,
11- "noImplicitReturns": true,
12- "noFallthroughCasesInSwitch": true,
13- "forceConsistentCasingInFileNames": true,
14- "skipLibCheck": true,
15- "allowImportingTsExtensions": true,
16- "noEmit": true,
17- "rootDir": "./src",
18- "baseUrl": ".",
19- "paths": {
20- "~/*": ["src/*"]
21- }
22- },
23- "include": ["src/**/*"],
24- "exclude": ["node_modules", "dist"]
2+ "compilerOptions": {
3+ "target": "ESNext",
4+ "module": "ESNext",
5+ "moduleResolution": "bundler",
6+ "lib": ["ESNext"],
7+ "types": ["bun"],
8+ "strict": true,
9+ "noUncheckedIndexedAccess": true,
10+ "exactOptionalPropertyTypes": true,
11+ "noImplicitReturns": true,
12+ "noFallthroughCasesInSwitch": true,
13+ "forceConsistentCasingInFileNames": true,
14+ "skipLibCheck": true,
15+ "allowImportingTsExtensions": true,
16+ "noEmit": true,
17+ "rootDir": "./src",
18+ "baseUrl": ".",
19+ "paths": {
20+ "~/*": ["src/*"]
21+ }
22+ },
23+ "include": ["src/**/*"],
24+ "exclude": ["node_modules", "dist"]
2525 }