Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(team): keep the head of a response in stdoutSnippet

Jack Rudenko9a96b1974545
diff --git a/packages/cli/src/team-orchestrator.test.ts b/packages/cli/src/team-orchestrator.test.ts
index 2f05a678..01cc7141 100644
--- a/packages/cli/src/team-orchestrator.test.ts
+++ b/packages/cli/src/team-orchestrator.test.ts
@@ -105,6 +105,36 @@ afterEach(() => {
// ─── Tests ────────────────────────────────────────────────────────────────────
describe("team-orchestrator", () => {
+ describe("snippetHeadAndTail", () => {
+ it("returns short text unchanged without an elision marker", async () => {
+ const { snippetHeadAndTail } = await getOrchestrator();
+ const text = "Short diagnostic output\nwith its original line breaks.";
+
+ expect(snippetHeadAndTail(text)).toBe(text);
+ expect(snippetHeadAndTail(text)).not.toContain("bytes omitted");
+ });
+
+ it("keeps the first 600 and last 1400 bytes and reports the omitted count", async () => {
+ const { snippetHeadAndTail } = await getOrchestrator();
+ const head = "H".repeat(600);
+ const omitted = "M".repeat(37);
+ const tail = "T".repeat(1400);
+
+ expect(snippetHeadAndTail(`${head}${omitted}${tail}`)).toBe(
+ `${head}\n\n… [37 bytes omitted] …\n\n${tail}`
+ );
+ });
+
+ it("preserves a bolded FAIL verdict near-miss from the head of a long response", async () => {
+ const { snippetHeadAndTail } = await getOrchestrator();
+ const verdict = "**Verdict**: **FAIL**";
+ const response = `${verdict}\n${"Detailed analysis without a matching verdict. ".repeat(80)}Unrelated tail prose.`;
+
+ expect(response.match(/\*\*Verdict\*\*: (PASS|CONDITIONAL|FAIL)/)).toBeNull();
+ expect(snippetHeadAndTail(response)).toContain(verdict);
+ expect(snippetHeadAndTail(response)).toContain("Unrelated tail prose.");
+ });
+ });
// ── FR3 / FR5: Directory structure ────────────────────────────────────────
describe("setupSession — directory structure", () => {
diff --git a/packages/cli/src/team-orchestrator.ts b/packages/cli/src/team-orchestrator.ts
index fa0ce187..d6fc6ed7 100644
--- a/packages/cli/src/team-orchestrator.ts
+++ b/packages/cli/src/team-orchestrator.ts
@@ -429,6 +429,33 @@ export interface TeamVerdict {
*/
export const STDOUT_TAIL_LIMIT = 4000;
+/** Budget for the stdout snippet recorded in `status.json`. */
+const SNIPPET_LIMIT = 2000;
+
+/** Bytes of the snippet budget spent on the START of the text. */
+const SNIPPET_HEAD = 600;
+
+/**
+ * Keep the snippet within budget WITHOUT discarding the beginning.
+ *
+ * A plain `.slice(-2000)` threw away the first half of a 4000-byte tail that was
+ * already in hand, and the beginning is where a shape mismatch is usually
+ * legible: a `require_pattern` near-miss like `**Verdict**: **FAIL**` against
+ * `/\*\*Verdict\*\*: (PASS|CONDITIONAL|FAIL)/` is diagnosed the moment the
+ * reader sees the model's actual wording. Ending a report at the tail can show
+ * the reader the last 2000 bytes of prose and none of the line that explains it.
+ *
+ * Short text is returned whole, so the elision marker only ever appears when
+ * something really was dropped.
+ */
+export function snippetHeadAndTail(text: string): string {
+ if (text.length <= SNIPPET_LIMIT) return text;
+ const head = text.slice(0, SNIPPET_HEAD);
+ const tail = text.slice(-(SNIPPET_LIMIT - SNIPPET_HEAD));
+ const omitted = text.length - head.length - tail.length;
+ return `${head}\n\n… [${omitted} bytes omitted] …\n\n${tail}`;
+}
+
/** Claude Code prints API failures into its stdout and still exits 0. */
const API_ERROR_RE = /\[API Error:\s*([^\]]{0,300})\]/i;
@@ -1385,7 +1412,7 @@ export async function startModels(
// Redacted: these land in status.json on disk and are read back
// by anything inspecting the run.
stderrSnippet: stderr ? redactSecrets(stderr).slice(-2000) : undefined,
- stdoutSnippet: stdoutTail ? redactSecrets(stdoutTail).slice(-2000) : undefined,
+ stdoutSnippet: stdoutTail ? snippetHeadAndTail(redactSecrets(stdoutTail)) : undefined,
errorLogPath,
// Only when the child actually wrote one. Naming a file that does
// not exist sends a reader after evidence that was never captured.