Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions apps/server/src/project/AgentSessionScanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3074,6 +3074,50 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
}),
);

it.effect("titles a long Claude import from the first request after a bare command", () =>
Effect.gen(function* () {
const path = yield* Path.Path;
const nowMs = Date.parse("2026-08-24T12:00:00.000Z");
yield* TestClock.setTime(nowMs);
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
const workspace = yield* makeTempDir("t3code-workspace-");
const sessionId = "62c057bb-b316-4b29-be2c-140090d71254";
const record = (role: "user" | "assistant", content: string) =>
encodeTranscriptRecord({
type: role,
cwd: workspace,
sessionId,
message: { role, content },
});

yield* writeTranscript({
filePath: path.join(claudeHomePath, "projects", "-slug", `${sessionId}.jsonl`),
contents: [
record(
"user",
"<command-name>/effort</command-name><command-message>effort</command-message><command-args></command-args>",
),
record("user", "Fix the login redirect"),
...Array.from({ length: 100 }, (_, index) => [
record("assistant", `Update ${index + 1}`),
record("user", `Review deployment check ${index + 1}`),
]).flat(),
record("assistant", "The deployment checks passed"),
].join("\n"),
mtimeMs: nowMs - 60_000,
});

const [thread] = yield* runRecentThreads({
claudeHomePath,
codexHomePath,
workspaceRoot: workspace,
});

expect(thread?.title).toBe("Fix the login redirect");
}),
);

it.effect("imports long Claude history beyond the selected-history and record limits", () =>
Effect.gen(function* () {
const path = yield* Path.Path;
Expand Down
13 changes: 12 additions & 1 deletion apps/server/src/project/AgentSessionScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,15 @@ interface ClaudeFields {
readonly sessionId: string | undefined;
readonly title: string | undefined;
readonly customTitle: string | null;
readonly firstRequestTitle: string | undefined;
readonly model: string | undefined;
}

const emptyClaudeFields: ClaudeFields = {
sessionId: undefined,
title: undefined,
customTitle: null,
firstRequestTitle: undefined,
model: undefined,
};

Expand All @@ -376,9 +378,18 @@ const CLAUDE_SYNTHETIC_MODEL = "<synthetic>";
function foldClaudeFields(fields: ClaudeFields, record: DecodedTranscriptRecord): ClaudeFields {
if (isHiddenClaudeRecord(record)) return fields;
const model = record.message?.model?.trim();
const requestTitle =
fields.firstRequestTitle === undefined && record.type === "user"
? deriveTitle("claudeAgent", claudeVisibleText(record).titleText)
: undefined;
return {
sessionId: record.sessionId?.trim() || fields.sessionId,
title: claudeTitle(record.aiTitle) ?? fields.title,
// Copy the title so a slice cannot keep an evicted prompt's backing string alive.
firstRequestTitle:
requestTitle === undefined
? fields.firstRequestTitle
: Buffer.from(requestTitle, "utf16le").toString("utf16le"),
// Claude flushes the AI title after the user's rename; an empty rename clears it.
customTitle:
record.customTitle === undefined
Expand Down Expand Up @@ -541,7 +552,7 @@ function parseAgentSessionRecords(
? records.findLast((record) => record.type === "session_info")?.name?.trim() || null
: (claudeFields.title ?? null);
let model = claudeFields.model ?? null;
let derivedTitle: string | undefined;
let derivedTitle = claudeFields.firstRequestTitle;
// Names a session whose only request was a bare command, such as `/review`.
let bareCommandTitle: string | undefined;
let hasAssistantMessage = false;
Expand Down
Loading