Skip to content

Commit fb3f897

Browse files
AlbinoGeekclaude
andcommitted
refactor: unexport internal helpers, drop dead MCP_JSON_FORMAT_VERSION
Knip flagged 12 unused exports and 8 unused exported types — all were internal helpers that leaked public visibility by accident. No external callers existed; the module public API was always the narrow set of functions imported by tool files. Changes per file: - repo-paths.ts: realPathOrSelf (used only by isStrictlyUnderGitTop) - json.ts: drop MCP_JSON_FORMAT_VERSION (unreferenced dead code), unexport readPackageVersion (called only by readMcpServerVersion) - presets.ts: unexport PresetEntry/File/Load* types, splitPresetFileRaw, getPresetEntry, mergeNestedRoots, mergePairs - roots.ts: unexport uriToPath, listFileRoots, pathMatchesWorkspaceRootHint, resolveWorkspaceRoots, resolveRootsForPreset, RootPick/ResolveRootsResult/ GitAndRootsResult types Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 14551d8 commit fb3f897

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

src/repo-paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { realpathSync } from "node:fs";
22
import { isAbsolute, relative, resolve } from "node:path";
33

4-
export function realPathOrSelf(p: string): string {
4+
function realPathOrSelf(p: string): string {
55
try {
66
return realpathSync(p);
77
} catch {

src/server/json.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { readFileSync } from "node:fs";
22
import { dirname, join } from "node:path";
33
import { fileURLToPath } from "node:url";
44

5-
export const MCP_JSON_FORMAT_VERSION = "2" as const;
6-
7-
export function readPackageVersion(): string {
5+
function readPackageVersion(): string {
86
const here = dirname(fileURLToPath(import.meta.url));
97
const pkgPath = join(here, "..", "..", "package.json");
108
try {

src/server/presets.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@ const PresetEntrySchema = z.object({
2424

2525
const PresetFileSchema = z.record(z.string(), PresetEntrySchema);
2626

27-
export type PresetEntry = z.infer<typeof PresetEntrySchema>;
28-
export type PresetFile = z.infer<typeof PresetFileSchema>;
27+
type PresetEntry = z.infer<typeof PresetEntrySchema>;
28+
type PresetFile = z.infer<typeof PresetFileSchema>;
2929

3030
export const PRESET_FILE_PATH = ".rethunk/git-mcp-presets.json";
3131

32-
export type PresetLoadFail =
32+
type PresetLoadFail =
3333
| { ok: false; reason: "missing" }
3434
| { ok: false; reason: "invalid_json"; message: string }
3535
| { ok: false; reason: "schema"; issues: z.ZodIssue[] };
3636

37-
export type PresetLoadOk = { ok: true; data: PresetFile; schemaVersion?: string };
37+
type PresetLoadOk = { ok: true; data: PresetFile; schemaVersion?: string };
3838

39-
export type PresetLoadResult = PresetLoadOk | PresetLoadFail;
39+
type PresetLoadResult = PresetLoadOk | PresetLoadFail;
4040

4141
/**
4242
* Supports:
4343
* - Wrapped: `{ "schemaVersion": "1", "presets": { "name": { ... } } }`
4444
* - Legacy: `{ "name": { ... }, ... }` with optional top-level `schemaVersion` / `$schema` (editor hints).
4545
*/
46-
export function splitPresetFileRaw(raw: unknown): { mapRaw: unknown; schemaVersion?: string } {
46+
function splitPresetFileRaw(raw: unknown): { mapRaw: unknown; schemaVersion?: string } {
4747
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
4848
throw new Error("invalid_root");
4949
}
@@ -121,7 +121,7 @@ export function presetLoadErrorPayload(
121121
return { error: "preset_file_invalid", presetFile };
122122
}
123123

124-
export function getPresetEntry(
124+
function getPresetEntry(
125125
gitTop: string,
126126
presetName: string,
127127
):
@@ -155,7 +155,7 @@ export function getPresetEntry(
155155
return { ok: true, entry, presetSchemaVersion: loaded.schemaVersion };
156156
}
157157

158-
export function mergeNestedRoots(
158+
function mergeNestedRoots(
159159
preset: string[] | undefined,
160160
inline: string[] | undefined,
161161
): string[] | undefined {
@@ -173,7 +173,7 @@ export function mergeNestedRoots(
173173
return out;
174174
}
175175

176-
export function mergePairs<T extends { left: string; right: string; label?: string }>(
176+
function mergePairs<T extends { left: string; right: string; label?: string }>(
177177
preset: T[] | undefined,
178178
inline: T[] | undefined,
179179
): T[] | undefined {

src/server/roots.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { FastMCP } from "fastmcp";
66
import { gateGit, gitTopLevel } from "./git.js";
77
import { loadPresetsFromGitTop, presetLoadErrorPayload } from "./presets.js";
88

9-
export function uriToPath(uri: string): string | null {
9+
function uriToPath(uri: string): string | null {
1010
if (!uri.startsWith("file://")) return null;
1111
try {
1212
return fileURLToPath(uri);
@@ -15,7 +15,7 @@ export function uriToPath(uri: string): string | null {
1515
}
1616
}
1717

18-
export function listFileRoots(server: FastMCP): string[] {
18+
function listFileRoots(server: FastMCP): string[] {
1919
const sessions = server.sessions;
2020
const roots = sessions[0]?.roots ?? [];
2121
const paths: string[] = [];
@@ -27,7 +27,7 @@ export function listFileRoots(server: FastMCP): string[] {
2727
}
2828

2929
/** Basename or trailing path segment; compares using normalized slashes so Windows backslashes match. */
30-
export function pathMatchesWorkspaceRootHint(rootPath: string, hint: string): boolean {
30+
function pathMatchesWorkspaceRootHint(rootPath: string, hint: string): boolean {
3131
const h = hint.trim();
3232
if (!h) return true;
3333
const absRoot = resolve(rootPath);
@@ -39,17 +39,17 @@ export function pathMatchesWorkspaceRootHint(rootPath: string, hint: string): bo
3939
return basename(rootPath) === h;
4040
}
4141

42-
export type RootPick = {
42+
type RootPick = {
4343
workspaceRoot?: string;
4444
rootIndex?: number;
4545
allWorkspaceRoots?: boolean;
4646
};
4747

48-
export type ResolveRootsResult =
48+
type ResolveRootsResult =
4949
| { ok: true; roots: string[] }
5050
| { ok: false; error: Record<string, unknown> };
5151

52-
export function resolveWorkspaceRoots(server: FastMCP, args: RootPick): ResolveRootsResult {
52+
function resolveWorkspaceRoots(server: FastMCP, args: RootPick): ResolveRootsResult {
5353
if (args.workspaceRoot?.trim()) {
5454
return { ok: true, roots: [resolve(args.workspaceRoot.trim())] };
5555
}
@@ -80,7 +80,7 @@ export function resolveWorkspaceRoots(server: FastMCP, args: RootPick): ResolveR
8080
* When a preset name is requested and multiple MCP roots exist, pick the first root
8181
* whose git toplevel loads a preset file containing that name.
8282
*/
83-
export function resolveRootsForPreset(
83+
function resolveRootsForPreset(
8484
server: FastMCP,
8585
args: RootPick,
8686
presetName: string,
@@ -116,7 +116,7 @@ export function resolveRootsForPreset(
116116
return resolveWorkspaceRoots(server, args);
117117
}
118118

119-
export type GitAndRootsResult =
119+
type GitAndRootsResult =
120120
| { ok: true; roots: string[] }
121121
| { ok: false; error: Record<string, unknown> };
122122

0 commit comments

Comments
 (0)