GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(shared): keep pull request summary fields in compact tool output … · patroza/t3code@00fa6cd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • client-runtime/src
      • t3ToolSummary.test.ts
      • t3ToolSummary.ts
      • work-log
        • presentation.test.ts
        • presentation.ts
    • shared/src
      • toolOutput.test.ts
      • toolOutput.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/client-runtime/src/t3ToolSummary.test.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/t3ToolSummary.test.ts
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { compactT3McpToolOutput } from "@t3tools/shared/toolOutput";
12
import { describe, expect, it } from "vite-plus/test";
23

34
import { summarizeT3ToolCalls, type T3ToolSummaryCall } from "./t3ToolSummary.ts";
@@ -102,6 +103,66 @@ describe("summarizeT3ToolCalls", () => {
102103
);
103104
});
104105

106+
it("preserves pull request summary outcomes after MCP tool output compaction", () => {
107+
const createExisting = completed(
108+
{ title: "t" },
109+
compactT3McpToolOutput("t3-code.pull_request_create", {
110+
number: 1,
111+
repository: "o/r",
112+
url: "https://github.com/o/r/pull/1",
113+
created: false,
114+
}),
115+
);
116+
expect(summarizeT3ToolCalls("create-pr", [createExisting]).label).toBe(
117+
"Found 1 open pull request",
118+
);
119+
120+
const mergeQueued = completed(
121+
{ auto: false },
122+
compactT3McpToolOutput("t3-code.pull_request_merge", { number: 1, state: "open" }),
123+
);
124+
const mergeLanded = completed(
125+
{ auto: true },
126+
compactT3McpToolOutput("t3-code.pull_request_merge", { number: 2, state: "merged" }),
127+
);
128+
expect(summarizeT3ToolCalls("merge-pr", [mergeQueued]).label).toBe(
129+
"Queued 1 pull request to merge",
130+
);
131+
expect(summarizeT3ToolCalls("merge-pr", [mergeLanded]).label).toBe("Merged 1 pull request");
132+
133+
const guidesMixed = completed(
134+
{},
135+
compactT3McpToolOutput("t3-code.write_pull_request_guides", {
136+
guides: [
137+
{ number: 1, outcome: "started", detail: null },
138+
{ number: 2, outcome: "failed", detail: "Guides disabled" },
139+
],
140+
}),
141+
);
142+
expect(summarizeT3ToolCalls("write-pr-guides", [guidesMixed])).toEqual({
143+
label: "Started 1 review guide, 1 failed",
144+
failedCount: 1,
145+
});
146+
147+
const rerunMixed = completed(
148+
{},
149+
compactT3McpToolOutput("t3-code.ci_rerun", {
150+
checks: [
151+
{ name: "test", rerun: true, detail: null },
152+
{ name: "external", rerun: false, detail: "Cannot rerun" },
153+
],
154+
}),
155+
);
156+
const rerunEmpty = completed({}, compactT3McpToolOutput("t3-code.ci_rerun", { checks: [] }));
157+
expect(summarizeT3ToolCalls("ci-rerun", [rerunMixed])).toEqual({
158+
label: "Re-ran 1 check, 1 refused",
159+
failedCount: 1,
160+
});
161+
expect(summarizeT3ToolCalls("ci-rerun", [rerunEmpty]).label).toBe(
162+
"Found no failed checks to re-run",
163+
);
164+
});
165+
105166
it("excludes failed and unfinished sends even if the provider reports completed", () => {
106167
const calls: T3ToolSummaryCall[] = [
107168
completed({ threadId: "success" }, { messageId: "ok", threadId: "success" }),
Collapse file

‎packages/client-runtime/src/t3ToolSummary.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/t3ToolSummary.ts
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,37 @@ export function t3ToolResultIndicatesFailure(output: unknown): boolean {
7070
return readResult(output).failed;
7171
}
7272

73+
// A row's static past-tense verb ("Opened a pull request") is wrong when the call reports another outcome.
74+
export function t3ToolOutcomeLabel(
75+
action: T3McpToolSummaryAction,
76+
call: T3ToolSummaryCall,
77+
resolve: MFunctionType = mFallback,
78+
): string | undefined {
79+
if (
80+
action !== "create-pr" &&
81+
action !== "merge-pr" &&
82+
action !== "write-pr-guides" &&
83+
action !== "ci-rerun"
84+
) {
85+
return undefined;
86+
}
87+
const output = readResult(call.output).data;
88+
const contradicted =
89+
action === "create-pr"
90+
? output?.created === false
91+
: action === "merge-pr"
92+
? output?.state === undefined
93+
? readInput(call.input)?.auto === true
94+
: output.state !== "merged"
95+
: action === "write-pr-guides"
96+
? Array.isArray(output?.guides) &&
97+
output.guides.some((guide) => asRecord(guide)?.outcome === "failed")
98+
: Array.isArray(output?.checks) &&
99+
(output.checks.length === 0 ||
100+
output.checks.some((check) => asRecord(check)?.rerun !== true));
101+
return contradicted ? summarizeT3ToolCalls(action, [call], resolve).label : undefined;
102+
}
103+
73104
function countEntities(ids: ReadonlyArray<string | undefined>): number {
74105
return (
75106
new Set(ids.filter((value) => value !== undefined)).size +
Collapse file

‎packages/client-runtime/src/work-log/presentation.test.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/work-log/presentation.test.ts
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vite-plus/test";
22

33
import { ThreadId, TurnItemId, type OrchestrationV2TurnItem } from "@t3tools/contracts";
44
import * as DateTime from "effect/DateTime";
5+
import { compactT3McpToolOutput } from "@t3tools/shared/toolOutput";
56

67
import {
78
resolveViewedImageAsset,
@@ -160,6 +161,28 @@ describe("resolveWorkEntryToolPresentation", () => {
160161
).toEqual({ displayName: "Taking a snapshot of the preview page", icon: "browser" });
161162
});
162163

164+
it("names the reported outcome when it contradicts the row's verb", () => {
165+
const row = (tool: string, output: unknown) =>
166+
resolveWorkEntryToolPresentation({
167+
label: `T3-code.${tool}`,
168+
toolLifecycleStatus: "completed",
169+
toolData: { output: compactT3McpToolOutput(`t3-code.${tool}`, output) },
170+
})?.displayName;
171+
expect(row("pull_request_create", { number: 470, created: false })).toBe(
172+
"Found 1 open pull request",
173+
);
174+
expect(row("pull_request_create", { number: 470, created: true })).toBe(
175+
"Opened a pull request",
176+
);
177+
expect(row("ci_rerun", { number: 883, checks: [] })).toBe("Found no failed checks to re-run");
178+
expect(row("ci_rerun", { number: 883, checks: [{ name: "ci", rerun: true }] })).toBe(
179+
"Re-ran CI",
180+
);
181+
expect(row("pull_request_merge", { number: 1, state: "open" })).toBe(
182+
"Queued 1 pull request to merge",
183+
);
184+
});
185+
163186
it("uses the summary's state only when the provider omitted a lifecycle status", () => {
164187
const entry = { label: "T3-code.preview_click" };
165188
expect(resolveWorkEntryToolPresentation(entry, "inProgress")?.displayName).toBe(
Collapse file

‎packages/client-runtime/src/work-log/presentation.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/work-log/presentation.ts
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { toolOutputIndicatesFailure } from "@t3tools/shared/toolOutput";
2626

2727
import {
2828
summarizeT3ToolCalls,
29+
t3ToolOutcomeLabel,
2930
t3ToolResultIndicatesFailure,
3031
type T3ToolSummaryCall,
3132
} from "@t3tools/client-runtime/t3ToolSummary";
@@ -304,13 +305,24 @@ export function resolveWorkEntryToolPresentation(
304305
workEntryToolName(entry),
305306
workEntryToolInput(entry),
306307
);
308+
const output = workEntryToolOutput(entry);
309+
const failed = definition !== null && t3ToolResultIndicatesFailure(output);
307310
const status = entry.toolLifecycleStatus ?? fallbackStatus;
308-
return resolveT3McpToolPresentation(
311+
const presentation = resolveT3McpToolPresentation(
309312
definition,
310-
definition && t3ToolResultIndicatesFailure(workEntryToolOutput(entry)) ? "failed" : status,
313+
failed ? "failed" : status,
311314
entry.toolData,
312315
resolve,
313316
);
317+
if (definition === null || presentation === null || failed || status !== "completed") {
318+
return presentation;
319+
}
320+
const outcomeLabel = t3ToolOutcomeLabel(
321+
definition.summaryAction,
322+
{ input: workEntryToolInput(entry), output, outcome: "completed" },
323+
resolve,
324+
);
325+
return outcomeLabel === undefined ? presentation : { ...presentation, displayName: outcomeLabel };
314326
}
315327

316328
function asRecord(value: unknown): Record<string, unknown> | null {
Collapse file

‎packages/shared/src/toolOutput.test.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/toolOutput.test.ts
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,36 @@ describe("compactDynamicToolOutput", () => {
165165
threadId: "known",
166166
});
167167
});
168+
169+
it("keeps pull request summary outcomes without private details", () => {
170+
expect(
171+
compactDynamicToolOutput({
172+
number: 42,
173+
url: "https://github.com/acme/app/pull/42",
174+
created: false,
175+
state: "merged",
176+
}),
177+
).toEqual({ created: false, state: "merged" });
178+
expect(
179+
compactDynamicToolOutput({
180+
guides: [
181+
{ number: 1, outcome: "started", detail: null },
182+
{ number: 2, outcome: "failed", detail: "Private error" },
183+
],
184+
checks: [{ name: "external", rerun: false, detail: "Private refusal" }],
185+
}),
186+
).toEqual({
187+
guides: [{ outcome: "started" }, { outcome: "failed" }],
188+
checks: [{ rerun: false }],
189+
});
190+
expect(
191+
compactDynamicToolOutput({
192+
state: "draft",
193+
guides: [{ outcome: "started" }, { outcome: "unknown" }],
194+
checks: [{ rerun: true }, { name: "missing-rerun" }],
195+
}),
196+
).toBeUndefined();
197+
});
168198
});
169199

170200
describe("toolOutputIndicatesFailure", () => {
Collapse file

‎packages/shared/src/toolOutput.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/toolOutput.ts
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const MAX_PARSED_BYTES = 16_384;
2525
const MAX_METADATA_BYTES = 8_192;
2626
const MAX_ID_LENGTH = 256;
2727
const MAX_THREADS = 100;
28+
const MAX_PULL_REQUEST_ITEMS = 100;
2829
const MAX_CONTENT_BLOCKS = 32;
2930
const MAX_ENVELOPE_DEPTH = 4;
3031
const MAX_ENVELOPE_NODES = 128;
@@ -56,6 +57,10 @@ interface CompactToolOutput {
5657
threads?: Array<{ threadId?: string; status?: "rolled_back" }>;
5758
linkedCount?: number;
5859
unlinkedCount?: number;
60+
created?: boolean;
61+
state?: "open" | "closed" | "merged";
62+
guides?: Array<{ outcome: "started" | "running" | "failed" }>;
63+
checks?: Array<{ rerun: boolean }>;
5964
sentMessage?: string;
6065
}
6166

@@ -127,6 +132,21 @@ function boundedId(value: unknown): string | undefined {
127132
return Array.from(value).join("");
128133
}
129134

135+
// All or nothing: a partial list would make the summary report wrong counts.
136+
function readEntries<T>(
137+
value: unknown,
138+
read: (entry: { readonly [key: string]: unknown }) => T | undefined,
139+
): T[] | undefined {
140+
if (!Array.isArray(value) || value.length > MAX_PULL_REQUEST_ITEMS) return undefined;
141+
const entries: T[] = [];
142+
for (const entry of value) {
143+
const compact = Predicate.isObject(entry) ? read(entry) : undefined;
144+
if (compact === undefined) return undefined;
145+
entries.push(compact);
146+
}
147+
return entries;
148+
}
149+
130150
export function compactDynamicToolOutput(value: unknown): CompactToolOutput | undefined {
131151
const budget: ResultReadBudget = {
132152
remainingBytes: MAX_PARSED_BYTES,
@@ -146,6 +166,20 @@ export function compactDynamicToolOutput(value: unknown): CompactToolOutput | un
146166
const count = data[key];
147167
if (typeof count === "number" && Number.isSafeInteger(count)) output[key] = count;
148168
}
169+
if (typeof data.created === "boolean") output.created = data.created;
170+
if (data.state === "open" || data.state === "closed" || data.state === "merged") {
171+
output.state = data.state;
172+
}
173+
const guides = readEntries(data.guides, (entry) =>
174+
entry.outcome === "started" || entry.outcome === "running" || entry.outcome === "failed"
175+
? ({ outcome: entry.outcome } as const)
176+
: undefined,
177+
);
178+
if (guides !== undefined) output.guides = guides;
179+
const checks = readEntries(data.checks, (entry) =>
180+
typeof entry.rerun === "boolean" ? { rerun: entry.rerun } : undefined,
181+
);
182+
if (checks !== undefined) output.checks = checks;
149183
if (
150184
typeof data.sentMessage === "string" &&
151185
data.sentMessage.trim() !== "" &&
@@ -196,6 +230,8 @@ export function compactDynamicToolOutput(value: unknown): CompactToolOutput | un
196230
delete output.threads;
197231
delete output.threadId;
198232
delete output.status;
233+
delete output.guides;
234+
delete output.checks;
199235
}
200236
const app = output[MCP_APP_OUTPUT_KEY];
201237
if (app?.csp !== undefined && oversized()) {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.