Skip to content

Commit 5b6134f

Browse files
committed
perf(mcp)\!: omit null/empty fields from git_inventory JSON
BREAKING CHANGE: InventoryEntryJson optional fields (`branchStatus`, `detached`, `headAbbrev`, `upstreamRef`, `ahead`, `behind`, `upstreamNote`) are now omitted when they would be empty/null/false instead of always emitted. Skip entries collapse to four fields (`label`, `path`, `upstreamMode`, `skipReason`) from twelve. JSON consumers must switch from `e.ahead \!= null` to `e.ahead \!== undefined` and tolerate missing keys. Markdown output unchanged for the common case; drops the `upstream:` line entirely when there is no note (was always empty string before).
1 parent fe5cca4 commit 5b6134f

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

src/server/inventory.ts

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ export const MAX_INVENTORY_ROOTS_DEFAULT = 64;
66
export type InventoryEntryJson = {
77
label: string;
88
path: string;
9-
branchStatus: string;
10-
detached: boolean;
11-
headAbbrev: string;
129
upstreamMode: "auto" | "fixed";
13-
upstreamRef: string | null;
14-
ahead: string | null;
15-
behind: string | null;
16-
upstreamNote: string;
10+
branchStatus?: string;
11+
detached?: true;
12+
headAbbrev?: string;
13+
upstreamRef?: string;
14+
ahead?: string;
15+
behind?: string;
16+
upstreamNote?: string;
1717
skipReason?: string;
1818
};
1919

@@ -28,19 +28,7 @@ export function makeSkipEntry(
2828
upstreamMode: "auto" | "fixed",
2929
skipReason: string,
3030
): InventoryEntryJson {
31-
return {
32-
label,
33-
path: abs,
34-
branchStatus: "",
35-
detached: false,
36-
headAbbrev: "",
37-
upstreamMode,
38-
upstreamRef: null,
39-
ahead: null,
40-
behind: null,
41-
upstreamNote: "",
42-
skipReason,
43-
};
31+
return { label, path: abs, upstreamMode, skipReason };
4432
}
4533

4634
export function buildInventorySectionMarkdown(e: InventoryEntryJson): string[] {
@@ -54,10 +42,10 @@ export function buildInventorySectionMarkdown(e: InventoryEntryJson): string[] {
5442
lines.push("branch: (detached HEAD)");
5543
lines.push("");
5644
}
57-
if (e.ahead != null && e.behind != null && e.upstreamRef) {
45+
if (e.ahead !== undefined && e.behind !== undefined && e.upstreamRef) {
5846
lines.push(`ahead_of_${e.upstreamRef.replace(/\//g, "_")}: ${e.ahead}`);
5947
lines.push(`behind_${e.upstreamRef.replace(/\//g, "_")}: ${e.behind}`);
60-
} else {
48+
} else if (e.upstreamNote) {
6149
lines.push(`upstream: ${e.upstreamNote}`);
6250
}
6351
return [`## ${e.label}`, `path: ${e.path}`, "```text", lines.join("\n"), "```", ``];
@@ -79,18 +67,19 @@ function buildEntry(params: {
7967
behind: string | null;
8068
upstreamNote: string;
8169
}): InventoryEntryJson {
82-
return {
70+
const out: InventoryEntryJson = {
8371
label: params.label,
8472
path: params.absPath,
85-
branchStatus: params.branchStatus,
86-
detached: params.detached,
87-
headAbbrev: params.headAbbrev || "(unknown)",
8873
upstreamMode: params.upstreamMode,
89-
upstreamRef: params.upstreamRef,
90-
ahead: params.ahead,
91-
behind: params.behind,
92-
upstreamNote: params.upstreamNote,
9374
};
75+
if (params.branchStatus) out.branchStatus = params.branchStatus;
76+
if (params.detached) out.detached = true;
77+
if (params.headAbbrev) out.headAbbrev = params.headAbbrev;
78+
if (params.upstreamRef !== null) out.upstreamRef = params.upstreamRef;
79+
if (params.ahead !== null) out.ahead = params.ahead;
80+
if (params.behind !== null) out.behind = params.behind;
81+
if (params.upstreamNote) out.upstreamNote = params.upstreamNote;
82+
return out;
9483
}
9584

9685
export async function collectInventoryEntry(

0 commit comments

Comments
 (0)