Skip to content

Commit 9b5b169

Browse files
t3dotggclaude
andcommitted
feat(triage): give triage drafts their own hero instead of toasts
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 918bfe4 commit 9b5b169

8 files changed

Lines changed: 104 additions & 51 deletions

File tree

‎apps/server/src/cli/triage.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const triageCommand = Command.make("triage", {
166166
selected = yield* pickAgent(installed);
167167
}
168168

169-
// The agent is launched with a one-line pointer at prompt.md: Windows
169+
// The agent is launched with a one-line pointer at the prompt file: Windows
170170
// `.cmd` shims run through cmd.exe, which cannot carry the multiline
171171
// playbook as an argv string, and with no agent installed the same file
172172
// is the paste-anywhere fallback.

‎apps/server/src/triage/triagePrompt.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";
2+
13
/**
24
* `TRIAGE_PLAYBOOK` must stay byte-identical to `.github/triage/PLAYBOOK.md`
35
* (only backticks and backslashes are escaped here).
@@ -157,18 +159,19 @@ export type TriageEntry =
157159

158160
/**
159161
* The one-line argument the agent session is launched with. The real
160-
* instructions live in `prompt.md` on disk: Windows `.cmd` shims run through
162+
* instructions live in the prompt file on disk: Windows `.cmd` shims run through
161163
* cmd.exe, which cannot carry a multiline, multi-kilobyte argv string.
162164
*/
163165
export const buildTriageLaunchPrompt = (promptFilePath: string) =>
164166
`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.`;
165167

166168
/**
167-
* The composer text an in-app session opens with. The user writes what went
168-
* wrong below it, so the first turn already carries the description.
169+
* The composer text an in-app session opens with. The file link renders as a
170+
* chip, and the user writes what went wrong after it, so the first turn
171+
* already carries the description.
169172
*/
170173
export const buildTriageAppPrompt = (promptFilePath: string) =>
171-
`Read the file "${promptFilePath}" and follow its instructions exactly: it is your T3 Code triage playbook. What went wrong, in my words:\n\n`;
174+
`Read ${serializeComposerFileLink(promptFilePath)} and follow it. `;
172175

173176
export const buildTriageSeedPrompt = (input: {
174177
readonly contextFilePath: string;

‎apps/server/src/triage/triageSession.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @effect-diagnostics nodeBuiltinImport:off
22
import * as NodeOS from "node:os";
33

4+
import { TRIAGE_PROMPT_FILE_NAME } from "@t3tools/contracts";
45
import * as HostProcess from "@t3tools/shared/HostProcess";
56
import * as DateTime from "effect/DateTime";
67
import * as Effect from "effect/Effect";
@@ -40,7 +41,7 @@ export const triageSourceCacheDir = (baseDir: string, path: Path.Path) =>
4041
path.join(baseDir, "source");
4142

4243
/**
43-
* Writes `context.md` and `prompt.md` into a fresh `<stateDir>/triage/<time>`
44+
* Writes `context.md` and the playbook prompt into a fresh `<stateDir>/triage/<time>`
4445
* folder. Both `t3 triage` and the in-app entry point start from these files.
4546
*/
4647
export const writeTriageSession = Effect.fn("triage.writeTriageSession")(function* (input: {
@@ -89,7 +90,7 @@ export const writeTriageSession = Effect.fn("triage.writeTriageSession")(functio
8990
}),
9091
);
9192

92-
const promptFilePath = path.join(sessionDir, "prompt.md");
93+
const promptFilePath = path.join(sessionDir, TRIAGE_PROMPT_FILE_NAME);
9394
yield* fs.writeFileString(
9495
promptFilePath,
9596
buildTriageSeedPrompt({ contextFilePath, entry: input.entry }),

‎apps/web/src/components/chat/DraftHeroHeadline.tsx‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { shortcutLabelForCommand } from "~/keybindings";
1212
import { primaryServerKeybindingsAtom } from "~/state/server";
1313
import { useNewThreadHandler } from "~/hooks/useHandleNewThread";
1414
import { useScratchProject } from "~/hooks/useScratchProject";
15+
import { isTriagePrompt } from "~/hooks/useStartTriage";
1516
import { useClientSettings } from "~/hooks/useSettings";
1617
import { hasExplicitComposerModelSelection } from "~/lib/chatThreadActions";
1718
import {
@@ -42,6 +43,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
4243
import { InlineButton } from "../ui/button";
4344
import { DraftProjectName } from "./DraftProjectName";
4445
import { DraftHeroProjectHeading } from "./DraftHeroProjectHeading";
46+
import { TriageDraftHero } from "./TriageDraftHero";
4547
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
4648

4749
const ADD_PROJECT_VALUE = "add-project";
@@ -72,6 +74,9 @@ export function DraftHeroHeadline({
7274
(store) => store.setLogicalProjectDraftThreadId,
7375
);
7476
const getComposerDraft = useComposerDraftStore((store) => store.getComposerDraft);
77+
const draftPrompt = useComposerDraftStore((store) =>
78+
draftId ? (store.getComposerDraft(draftId)?.prompt ?? "") : "",
79+
);
7580
const applyStickyState = useComposerDraftStore((store) => store.applyStickyState);
7681
const setModelSelection = useComposerDraftStore((store) => store.setModelSelection);
7782
const openAddProject = () => openCommandPalette({ open: "add-project" });
@@ -340,6 +345,18 @@ export function DraftHeroHeadline({
340345
</Tooltip>
341346
) : null;
342347

348+
if (isScratchDraft && isTriagePrompt(draftPrompt)) {
349+
const environment = environments.find(
350+
(entry) => entry.environmentId === activeProject.environmentId,
351+
);
352+
return (
353+
<TriageDraftHero
354+
machineLabel={environment?.label ?? null}
355+
serverVersion={environment?.serverConfig?.environment.serverVersion ?? null}
356+
/>
357+
);
358+
}
359+
343360
return (
344361
<div className="mx-auto flex w-full max-w-5xl flex-col items-center">
345362
{hasResolvedProject && !isScratchDraft ? (
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
2+
import { TRIAGE_CLI_COMMAND } from "~/hooks/useStartTriage";
3+
4+
import { InlineButton } from "../ui/button";
5+
6+
/** The empty-draft hero for a triage session, in place of "What should we work on?". */
7+
export function TriageDraftHero(props: {
8+
readonly machineLabel: string | null;
9+
readonly serverVersion: string | null;
10+
}) {
11+
const { copyToClipboard, isCopied } = useCopyToClipboard({ timeout: 1500, target: "command" });
12+
const where = props.machineLabel === null ? "this machine" : props.machineLabel;
13+
const version = props.serverVersion === null ? "" : ` (v${props.serverVersion})`;
14+
return (
15+
<div className="mx-auto flex w-full max-w-xl flex-col items-center text-center">
16+
<h1 className="font-normal text-2xl text-foreground tracking-tight sm:text-3xl">
17+
What went wrong?
18+
</h1>
19+
<p className="mt-2 text-muted-foreground text-sm">
20+
The agent checks the T3 Code logs and source on {where}
21+
{version}, then helps you file an issue. It asks before it changes anything.
22+
</p>
23+
<p className="mt-1 text-muted-foreground/70 text-xs">
24+
Not working here? Run{" "}
25+
<InlineButton
26+
tone="muted"
27+
className="pointer-events-auto"
28+
onClick={() => copyToClipboard(TRIAGE_CLI_COMMAND, undefined)}
29+
>
30+
<code className="font-mono">{isCopied ? "copied" : TRIAGE_CLI_COMMAND}</code>
31+
</InlineButton>{" "}
32+
in a terminal.
33+
</p>
34+
</div>
35+
);
36+
}

‎apps/web/src/hooks/useStartTriage.ts‎

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
isAtomCommandInterrupted,
55
squashAtomCommandFailure,
66
} from "@t3tools/client-runtime/state/runtime";
7-
import type { EnvironmentId } from "@t3tools/contracts";
7+
import { type EnvironmentId, TRIAGE_PROMPT_FILE_NAME } from "@t3tools/contracts";
88

99
import { stackedThreadToast, toastManager } from "~/components/ui/toast";
1010
import { useComposerDraftStore } from "~/composerDraftStore";
@@ -16,53 +16,49 @@ import { writeTextToClipboard } from "./useCopyToClipboard";
1616
import { useNewThreadHandler } from "./useHandleNewThread";
1717
import { useScratchProject } from "./useScratchProject";
1818

19-
const CLI_COMMAND = "npx t3 triage";
19+
export const TRIAGE_CLI_COMMAND = "npx t3 triage";
2020

21-
const copyCliCommandAction = {
22-
children: "Copy command",
23-
onClick: () => void writeTextToClipboard(CLI_COMMAND, "command"),
24-
};
21+
const copyTriageCliCommand = () => writeTextToClipboard(TRIAGE_CLI_COMMAND, "command");
22+
23+
/** A draft is a triage draft while its message still links the playbook file. */
24+
export const isTriagePrompt = (prompt: string) => prompt.includes(`[${TRIAGE_PROMPT_FILE_NAME}](`);
2525

2626
/**
27-
* In-app `t3 triage`: the server writes the session files and clones the
28-
* matching source, then a No project draft opens with the prompt filled in.
29-
* The user picks the provider in the composer and describes the problem.
27+
* In-app `t3 triage`: the server writes the session files and starts cloning
28+
* the matching source, then a No project draft opens with the playbook linked.
29+
* The draft hero explains the rest; the user picks a provider and describes
30+
* the problem.
3031
*/
3132
export function useStartTriage() {
3233
const { scratchWorkspaceRootFor } = useScratchProject();
3334
const handleNewThread = useNewThreadHandler();
3435
const prepare = useAtomCommand(serverEnvironment.prepareTriage, { reportFailure: false });
3536
const openScratch = useAtomCommand(projectEnvironment.openScratch, { reportFailure: false });
3637

37-
return async (environmentId: EnvironmentId) => {
38-
const toastId = toastManager.add({ type: "loading", title: "Preparing triage…" });
39-
const fail = (description: string) =>
40-
toastManager.update(
41-
toastId,
42-
stackedThreadToast({
43-
type: "error",
44-
title: "Could not start triage",
45-
description: `${description} Run ${CLI_COMMAND} in a terminal instead.`,
46-
timeout: 0,
47-
actionProps: copyCliCommandAction,
48-
}),
49-
);
38+
// With no draft to show, a toast is the only place to point at the CLI.
39+
const fail = (description: string) =>
40+
toastManager.add(
41+
stackedThreadToast({
42+
type: "error",
43+
title: "Could not start triage",
44+
description: `${description} Run ${TRIAGE_CLI_COMMAND} in a terminal instead.`,
45+
timeout: 0,
46+
actionProps: { children: "Copy command", onClick: () => void copyTriageCliCommand() },
47+
}),
48+
);
49+
const failWith = (
50+
result: Extract<AtomCommandResult<unknown, unknown>, { readonly _tag: "Failure" }>,
51+
) => {
52+
if (isAtomCommandInterrupted(result)) return;
53+
const error = squashAtomCommandFailure(result);
54+
fail(error instanceof Error ? error.message : "An error occurred.");
55+
};
5056

57+
return async (environmentId: EnvironmentId) => {
5158
if (scratchWorkspaceRootFor(environmentId) === null) {
5259
fail("This environment cannot start threads without a project.");
5360
return;
5461
}
55-
const failWith = (
56-
result: Extract<AtomCommandResult<unknown, unknown>, { readonly _tag: "Failure" }>,
57-
) => {
58-
if (isAtomCommandInterrupted(result)) {
59-
toastManager.close(toastId);
60-
return;
61-
}
62-
const error = squashAtomCommandFailure(result);
63-
fail(error instanceof Error ? error.message : "An error occurred.");
64-
};
65-
6662
const prepared = await prepare({
6763
environmentId,
6864
input: { client: currentClientMetadata() },
@@ -78,12 +74,5 @@ export function useStartTriage() {
7874
return;
7975
}
8076
useComposerDraftStore.getState().setPrompt(opened.draftId, prepared.value.prompt);
81-
toastManager.update(toastId, {
82-
type: "info",
83-
title: "Describe what went wrong, then send",
84-
description: `Pick any provider. If triage does not work here, run ${CLI_COMMAND} in a terminal.`,
85-
timeout: 10_000,
86-
actionProps: copyCliCommandAction,
87-
});
8877
};
8978
}

‎docs/user/triage.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ before it changes anything or posts anything.
77

88
## In the app
99

10-
Open the command palette and choose **Triage an issue**. T3 Code gets the source
11-
for the server's version, then opens a new thread with no project. Choose any
12-
provider, describe what went wrong below the prompt, and send.
10+
Open the command palette and choose **Triage an issue**. A new thread with no
11+
project opens, with the triage playbook linked in the message. Choose any
12+
provider, describe what went wrong after the link, and send. T3 Code gets the
13+
source for the server's version while you write.
1314

1415
Triage runs on the machine that you are looking at: the machine of the current
1516
thread, or else your primary machine. The agent runs inside that T3 Code

‎packages/contracts/src/server.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,15 @@ export const ServerPrepareTriageInput = Schema.Struct({
330330
export type ServerPrepareTriageInput = typeof ServerPrepareTriageInput.Type;
331331

332332
export const ServerPrepareTriageResult = Schema.Struct({
333-
/** Composer text that points the agent at the session's prompt file. */
333+
/** Composer text that links the session's prompt file. */
334334
prompt: Schema.String,
335335
});
336+
337+
/**
338+
* The prompt file links as a chip in the user's message; clients spot a triage
339+
* draft by it.
340+
*/
341+
export const TRIAGE_PROMPT_FILE_NAME = "triage-playbook.md";
336342
export type ServerPrepareTriageResult = typeof ServerPrepareTriageResult.Type;
337343

338344
export class ServerPrepareTriageError extends Schema.TaggedError<ServerPrepareTriageError>()(

0 commit comments

Comments
 (0)