From c4e925d22c54e5b02882d7af7c5740b623e85223 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Thu, 13 Aug 2026 18:22:41 -0700 Subject: [PATCH] fix(cli): triage review findings from bugbot and coderabbit The seed prompt now always lives in prompt.md and the agent launches with a one-line pointer at it: Windows .cmd shims go through cmd.exe, which cannot carry the multiline playbook as argv. T3CODE_HOME is now honored as the --base-dir equivalent, matching t3 pair. The playbook opens prefilled issue URLs only after the user approves. Co-Authored-By: Claude Fable 5 --- .github/triage/PLAYBOOK.md | 3 ++- apps/server/src/cli/triage.ts | 24 ++++++++++++++++++------ apps/server/src/cli/triagePrompt.test.ts | 16 +++++++++++++++- apps/server/src/cli/triagePrompt.ts | 13 +++++++++++-- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/.github/triage/PLAYBOOK.md b/.github/triage/PLAYBOOK.md index 9eb89c613d..e52a5695d2 100644 --- a/.github/triage/PLAYBOOK.md +++ b/.github/triage/PLAYBOOK.md @@ -109,7 +109,8 @@ of `main` for that work, never the tag-pinned diagnosis clone. - Note at the end of the issue which model and agent produced it. - If `gh` is not authenticated, offer `gh auth login`, or build a prefilled https://github.com/pingdotgg/t3code/issues/new URL with title and body query - parameters and open it in their browser. + parameters; print the URL, and open it in their browser only after they + approve. - If the user pasted screenshots, remind them to drag the images into the issue after it is created; they cannot be attached from here. diff --git a/apps/server/src/cli/triage.ts b/apps/server/src/cli/triage.ts index f4e18819c1..767b1a5bd4 100644 --- a/apps/server/src/cli/triage.ts +++ b/apps/server/src/cli/triage.ts @@ -16,6 +16,7 @@ import * as NodeReadlinePromises from "node:readline/promises"; import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess"; import { isCommandAvailable, resolveSpawnCommand } from "@t3tools/shared/shell"; +import * as Config from "effect/Config"; import * as Console from "effect/Console"; import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; @@ -31,7 +32,11 @@ import { resolveBaseDir } from "../os-jank.ts"; import { readPersistedServerRuntimeState } from "../serverRuntimeState.ts"; import { baseDirFlag } from "./config.ts"; import { resolveCliCommand } from "./invocation.ts"; -import { buildTriageContext, buildTriageSeedPrompt } from "./triagePrompt.ts"; +import { + buildTriageContext, + buildTriageLaunchPrompt, + buildTriageSeedPrompt, +} from "./triagePrompt.ts"; interface TriageAgent { readonly id: "claude" | "codex"; @@ -172,7 +177,11 @@ export const triageCommand = Command.make("triage", { const path = yield* Path.Path; // Triage is a user-facing feature: always the userdata state, never dev. - const baseDir = yield* resolveBaseDir(Option.getOrUndefined(flags.baseDir)); + // --base-dir wins; T3CODE_HOME is its documented env equivalent (same + // precedence as `t3 pair`). + const explicitBaseDir = Option.getOrUndefined(flags.baseDir); + const envHome = yield* Config.string("T3CODE_HOME").pipe(Config.option); + const baseDir = yield* resolveBaseDir(explicitBaseDir ?? Option.getOrUndefined(envHome)); const paths = yield* ServerConfig.deriveServerPaths(baseDir, undefined, {}); const now = yield* DateTime.now; @@ -237,11 +246,14 @@ export const triageCommand = Command.make("triage", { selected = yield* pickAgent(installed); } - const seedPrompt = buildTriageSeedPrompt(contextFilePath); + // The full seed prompt always goes to disk. The agent is launched with a + // one-line pointer at it: Windows `.cmd` shims run through cmd.exe, + // which cannot carry the multiline playbook as an argv string, and with + // no agent installed the same file is the paste-anywhere fallback. + const promptFilePath = path.join(scratchDir, "prompt.md"); + yield* fs.writeFileString(promptFilePath, buildTriageSeedPrompt(contextFilePath)); if (selected === undefined) { - const promptFilePath = path.join(scratchDir, "prompt.md"); - yield* fs.writeFileString(promptFilePath, seedPrompt); yield* Console.log( [ "No supported agent CLI (claude, codex) was found on this machine.", @@ -259,7 +271,7 @@ export const triageCommand = Command.make("triage", { const model = Option.getOrUndefined(flags.model); const spawnSpec = yield* resolveSpawnCommand(selected.command, [ ...(model === undefined ? [] : ["--model", model]), - seedPrompt, + buildTriageLaunchPrompt(promptFilePath), ]); yield* Console.log(`Starting ${selected.label}. It will ask what went wrong.\n`); const exitCode = yield* runInteractiveSession({ ...spawnSpec, cwd: scratchDir }); diff --git a/apps/server/src/cli/triagePrompt.test.ts b/apps/server/src/cli/triagePrompt.test.ts index ec5a600dfc..bf1ac5dbbe 100644 --- a/apps/server/src/cli/triagePrompt.test.ts +++ b/apps/server/src/cli/triagePrompt.test.ts @@ -4,7 +4,12 @@ import * as NodePath from "node:path"; import { assert, it } from "@effect/vitest"; -import { buildTriageContext, buildTriageSeedPrompt, TRIAGE_PLAYBOOK } from "./triagePrompt.ts"; +import { + buildTriageContext, + buildTriageLaunchPrompt, + buildTriageSeedPrompt, + TRIAGE_PLAYBOOK, +} from "./triagePrompt.ts"; it("stays byte-identical to .github/triage/PLAYBOOK.md", () => { // Old releases fetch the repo copy from `main` and follow it when it differs @@ -24,6 +29,15 @@ it("seed prompt names the context file and embeds the playbook", () => { assert.include(prompt, TRIAGE_PLAYBOOK); }); +it("launch prompt stays a single argv-safe line naming the prompt file", () => { + // The launch argument goes through cmd.exe on Windows (.cmd shims), which + // cannot carry newlines; the playbook itself must stay on disk. + const launch = buildTriageLaunchPrompt(String.raw`C:\Users\a b\.t3\userdata\triage\x\prompt.md`); + assert.notInclude(launch, "\n"); + assert.include(launch, String.raw`C:\Users\a b\.t3\userdata\triage\x\prompt.md`); + assert.isBelow(launch.length, 1_000); +}); + it("context file carries every path the playbook depends on", () => { const context = buildTriageContext({ generatedAt: "2026-08-13T00:00:00.000Z", diff --git a/apps/server/src/cli/triagePrompt.ts b/apps/server/src/cli/triagePrompt.ts index c76a3c6bd3..5024b97ae4 100644 --- a/apps/server/src/cli/triagePrompt.ts +++ b/apps/server/src/cli/triagePrompt.ts @@ -121,7 +121,8 @@ of \`main\` for that work, never the tag-pinned diagnosis clone. - Note at the end of the issue which model and agent produced it. - If \`gh\` is not authenticated, offer \`gh auth login\`, or build a prefilled https://github.com/pingdotgg/t3code/issues/new URL with title and body query - parameters and open it in their browser. + parameters; print the URL, and open it in their browser only after they + approve. - If the user pasted screenshots, remind them to drag the images into the issue after it is created; they cannot be attached from here. @@ -138,7 +139,15 @@ user's environment and evidence instead of filing a new issue. A confirmed duplicate with fresh evidence is more useful than a second thread. `; -/** The prompt the interactive agent session is launched with. */ +/** + * The one-line argument the agent session is launched with. The real + * instructions live in `prompt.md` on disk: Windows `.cmd` shims run through + * cmd.exe, which cannot carry a multiline, multi-kilobyte argv string. + */ +export const buildTriageLaunchPrompt = (promptFilePath: string) => + `Read the file "${promptFilePath}" and follow its instructions exactly: it is your T3 Code triage playbook, and it starts with asking the user what went wrong.`; + +/** The full seed prompt, written to `prompt.md` in the triage scratch dir. */ export const buildTriageSeedPrompt = (contextFilePath: string) => `A T3 Code user is \ having a problem with their install and started this session with \`t3 triage\`.