diff --git a/apps/server/integration/perf/seedPerfState.test.ts b/apps/server/integration/perf/seedPerfState.test.ts index 5a52c7d054..c50da3cc84 100644 --- a/apps/server/integration/perf/seedPerfState.test.ts +++ b/apps/server/integration/perf/seedPerfState.test.ts @@ -3,7 +3,7 @@ import { join } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; -import { PERF_CATALOG_IDS } from "@t3tools/shared/perf/scenarioCatalog"; +import { PERF_CATALOG_IDS, getPerfSeedScenario } from "@t3tools/shared/perf/scenarioCatalog"; import { seedPerfState } from "./seedPerfState.ts"; describe("seedPerfState", () => { @@ -20,18 +20,24 @@ describe("seedPerfState", () => { it("seeds large thread fixtures through the real event store and projection pipeline", async () => { const seeded = await seedPerfState("large_threads"); runParentDirsToCleanup.push(seeded.runParentDir); + const scenario = getPerfSeedScenario("large_threads"); - expect(seeded.snapshot.projects).toHaveLength(1); - expect(seeded.snapshot.threads).toHaveLength(12); + expect(seeded.snapshot.projects).toHaveLength(5); + expect(seeded.snapshot.threads).toHaveLength(30); expect(seeded.baseDir).toBe(join(seeded.runParentDir, "base")); + expect(new Set(seeded.snapshot.threads.map((thread) => thread.projectId)).size).toBe(5); const heavyThread = seeded.snapshot.threads.find( (thread) => thread.id === PERF_CATALOG_IDS.largeThreads.heavyAThreadId, ); + const heavyThreadScenario = scenario.threads.find( + (thread) => thread.id === PERF_CATALOG_IDS.largeThreads.heavyAThreadId, + ); expect(heavyThread?.messages).toHaveLength(2_000); + expect(heavyThreadScenario?.turnCount ?? Number.POSITIVE_INFINITY).toBeLessThan(100); expect((heavyThread?.activities.length ?? 0) > 0).toBe(true); expect((heavyThread?.proposedPlans.length ?? 0) > 0).toBe(true); - expect((heavyThread?.checkpoints.length ?? 0) >= 80).toBe(true); + expect((heavyThread?.checkpoints.length ?? 0) >= 20).toBe(true); expect((heavyThread?.checkpoints[0]?.files.length ?? 0) >= 12).toBe(true); }); diff --git a/apps/server/integration/perf/seedPerfState.ts b/apps/server/integration/perf/seedPerfState.ts index cd6dc79a62..79a5b92bf8 100644 --- a/apps/server/integration/perf/seedPerfState.ts +++ b/apps/server/integration/perf/seedPerfState.ts @@ -10,14 +10,17 @@ import { EventId, type OrchestrationEvent, type OrchestrationReadModel, + type ProjectId, } from "@t3tools/contracts"; import { Effect, Layer, ManagedRuntime } from "effect"; import { + buildPerfAssistantMessageCountPlan, getPerfSeedScenario, perfEventId, perfMessageIdForThread, perfTurnIdForThread, + type PerfProjectScenario, type PerfSeedScenario, type PerfSeedScenarioId, type PerfSeedThreadScenario, @@ -73,25 +76,25 @@ function makeCommandId(prefix: string, threadId: string, turnIndex: number): Com } function buildProjectEvent( - scenario: PerfSeedScenario, + project: PerfProjectScenario, workspaceRoot: string, createdAt: string, ): Omit { return { type: "project.created", - eventId: EventId.makeUnsafe(`perf-project-created:${String(scenario.project.id)}`), + eventId: EventId.makeUnsafe(`perf-project-created:${String(project.id)}`), aggregateKind: "project", - aggregateId: scenario.project.id, + aggregateId: project.id, occurredAt: createdAt, - commandId: CommandId.makeUnsafe(`perf-project-create:${String(scenario.project.id)}`), + commandId: CommandId.makeUnsafe(`perf-project-create:${String(project.id)}`), causationEventId: null, - correlationId: CommandId.makeUnsafe(`perf-project-create:${String(scenario.project.id)}`), + correlationId: CommandId.makeUnsafe(`perf-project-create:${String(project.id)}`), metadata: {}, payload: { - projectId: scenario.project.id, - title: scenario.project.title, + projectId: project.id, + title: project.title, workspaceRoot, - defaultModelSelection: scenario.project.defaultModelSelection, + defaultModelSelection: project.defaultModelSelection, scripts: [], createdAt, updatedAt: createdAt, @@ -101,7 +104,7 @@ function buildProjectEvent( function buildThreadCreatedEvent( thread: PerfSeedThreadScenario, - scenario: PerfSeedScenario, + project: PerfProjectScenario, createdAt: string, ): Omit { return { @@ -116,9 +119,9 @@ function buildThreadCreatedEvent( metadata: {}, payload: { threadId: thread.id, - projectId: scenario.project.id, + projectId: thread.projectId, title: thread.title, - modelSelection: scenario.project.defaultModelSelection, + modelSelection: project.defaultModelSelection, runtimeMode: "full-access", interactionMode: "default", branch: null, @@ -140,19 +143,36 @@ function buildUserMessageText(thread: PerfSeedThreadScenario, turnIndex: number) return base; } -function buildAssistantMessageText(thread: PerfSeedThreadScenario, turnIndex: number): string { - const prefix = `${thread.title} response ${turnIndex}: `; - const paragraphs = [ - "The render path stays stable when visible rows are capped and background work is batched.", - "Navigation remains predictable when thread metadata, message slices, and work log grouping avoid unnecessary churn.", - "Websocket-heavy turns should keep incremental UI updates small so the main thread is free for scrolling and input.", +function buildAssistantMessageText( + thread: PerfSeedThreadScenario, + turnIndex: number, + assistantMessageIndex: number, + assistantMessageCount: number, +): string { + const phaseLabel = + assistantMessageIndex === 1 + ? "Opening" + : assistantMessageIndex === assistantMessageCount + ? "Settled" + : assistantMessageIndex % 5 === 0 + ? "Checkpoint" + : "Loop"; + const focusTopics = [ + "checked the visible timeline window and sidebar ordering", + "trimmed redundant projection work before the next render pass", + "reviewed websocket fan-out and message grouping pressure", + "verified checkpoint rows stay bounded while hidden threads move", + "kept the active route stable while background threads kept streaming", ]; - const paragraphCount = turnIndex % 9 === 0 ? 3 : turnIndex % 4 === 0 ? 2 : 1; - return `${prefix}${paragraphs.slice(0, paragraphCount).join(" ")}${ - turnIndex % 13 === 0 - ? "\n\n- Keep virtual rows bounded\n- Avoid synchronous bursts\n- Preserve responsive thread switches" - : "" - }`; + const topic = focusTopics[(turnIndex + assistantMessageIndex) % focusTopics.length]!; + const threadBias = + thread.category === "heavy" + ? "The thread is still dense enough to stress virtualization." + : thread.category === "burst" + ? "This pass is still carrying live burst pressure." + : "Background churn is staying active without stealing focus."; + + return `${thread.title} ${phaseLabel.toLowerCase()} ${assistantMessageIndex}/${assistantMessageCount} for turn ${turnIndex}: ${topic}. ${threadBias}`; } function buildProposedPlanMarkdown(thread: PerfSeedThreadScenario, turnIndex: number): string { @@ -227,25 +247,41 @@ function buildCheckpointFiles( } function buildThreadTurnEvents( - scenario: PerfSeedScenario, thread: PerfSeedThreadScenario, threadOrdinal: number, projectStartMs: number, ): ReadonlyArray> { const events: Array> = []; const threadStartMs = projectStartMs + threadOrdinal * 60_000; + const assistantMessageCountPlan = buildPerfAssistantMessageCountPlan(thread); for (let turnIndex = 1; turnIndex <= thread.turnCount; turnIndex += 1) { const turnId = perfTurnIdForThread(thread, turnIndex); - const userMessageId = perfMessageIdForThread(thread, "user", turnIndex); - const assistantMessageId = perfMessageIdForThread(thread, "assistant", turnIndex); + const userMessageId = perfMessageIdForThread(thread, "user", turnIndex, 1); + const assistantMessageCount = assistantMessageCountPlan[turnIndex - 1] ?? 1; const turnBaseMs = threadStartMs + turnIndex * 1_000; const userOccurredAt = plusMs(turnBaseMs, 0); - const assistantOccurredAt = plusMs(turnBaseMs, 320); + const activityAssistantIndex = + thread.activityStride !== null && turnIndex % thread.activityStride === 0 + ? Math.max(2, Math.floor(assistantMessageCount * 0.35)) + : null; + const planAssistantIndex = + thread.planStride !== null && turnIndex % thread.planStride === 0 + ? Math.max(2, Math.floor(assistantMessageCount * 0.7)) + : null; + let lastAssistantMessageId = perfMessageIdForThread( + thread, + "assistant", + turnIndex, + assistantMessageCount, + ); + let turnEventOffset = 0; + const nextEventId = (prefix: string) => + perfEventId(prefix, thread.id, turnIndex * 100 + turnEventOffset++); events.push({ type: "thread.message-sent", - eventId: perfEventId("perf-user-message", thread.id, turnIndex * 10), + eventId: nextEventId("perf-user-message"), aggregateKind: "thread", aggregateId: thread.id, occurredAt: userOccurredAt, @@ -266,92 +302,113 @@ function buildThreadTurnEvents( }, }); - events.push({ - type: "thread.message-sent", - eventId: perfEventId("perf-assistant-message", thread.id, turnIndex * 10 + 1), - aggregateKind: "thread", - aggregateId: thread.id, - occurredAt: assistantOccurredAt, - commandId: makeCommandId("perf-assistant-message", String(thread.id), turnIndex), - causationEventId: null, - correlationId: makeCommandId("perf-turn", String(thread.id), turnIndex), - metadata: {}, - payload: { - threadId: thread.id, - messageId: assistantMessageId, - role: "assistant", - text: buildAssistantMessageText(thread, turnIndex), - attachments: [], - turnId, - streaming: false, - createdAt: assistantOccurredAt, - updatedAt: assistantOccurredAt, - }, - }); + for ( + let assistantMessageIndex = 1; + assistantMessageIndex <= assistantMessageCount; + assistantMessageIndex += 1 + ) { + const assistantOccurredAt = plusMs(turnBaseMs, 120 + assistantMessageIndex * 40); + const assistantMessageId = perfMessageIdForThread( + thread, + "assistant", + turnIndex, + assistantMessageIndex, + ); + lastAssistantMessageId = assistantMessageId; - if (thread.activityStride !== null && turnIndex % thread.activityStride === 0) { - const activityOccurredAt = plusMs(turnBaseMs, 520); events.push({ - type: "thread.activity-appended", - eventId: perfEventId("perf-activity", thread.id, turnIndex * 10 + 2), + type: "thread.message-sent", + eventId: nextEventId("perf-assistant-message"), aggregateKind: "thread", aggregateId: thread.id, - occurredAt: activityOccurredAt, - commandId: makeCommandId("perf-activity", String(thread.id), turnIndex), + occurredAt: assistantOccurredAt, + commandId: makeCommandId("perf-assistant-message", String(thread.id), turnIndex), causationEventId: null, correlationId: makeCommandId("perf-turn", String(thread.id), turnIndex), metadata: {}, payload: { threadId: thread.id, - activity: { - id: perfEventId("perf-activity-row", thread.id, turnIndex), - tone: "tool", - kind: "tool.completed", - summary: `Synthetic command batch ${turnIndex}`, - payload: { - command: "perf-simulated", - batch: turnIndex, - threadCategory: thread.category, + messageId: assistantMessageId, + role: "assistant", + text: buildAssistantMessageText( + thread, + turnIndex, + assistantMessageIndex, + assistantMessageCount, + ), + attachments: [], + turnId, + streaming: false, + createdAt: assistantOccurredAt, + updatedAt: assistantOccurredAt, + }, + }); + + if (activityAssistantIndex === assistantMessageIndex) { + const activityOccurredAt = plusMs(turnBaseMs, 132 + assistantMessageIndex * 40); + events.push({ + type: "thread.activity-appended", + eventId: nextEventId("perf-activity"), + aggregateKind: "thread", + aggregateId: thread.id, + occurredAt: activityOccurredAt, + commandId: makeCommandId("perf-activity", String(thread.id), turnIndex), + causationEventId: null, + correlationId: makeCommandId("perf-turn", String(thread.id), turnIndex), + metadata: {}, + payload: { + threadId: thread.id, + activity: { + id: perfEventId("perf-activity-row", thread.id, turnIndex), + tone: "tool", + kind: "tool.completed", + summary: `Synthetic command batch ${turnIndex}.${assistantMessageIndex}`, + payload: { + command: "perf-simulated", + batch: turnIndex, + loop: assistantMessageIndex, + threadCategory: thread.category, + }, + turnId, + createdAt: activityOccurredAt, }, - turnId, - createdAt: activityOccurredAt, }, - }, - }); - } + }); + } - if (thread.planStride !== null && turnIndex % thread.planStride === 0) { - const planOccurredAt = plusMs(turnBaseMs, 640); - events.push({ - type: "thread.proposed-plan-upserted", - eventId: perfEventId("perf-plan", thread.id, turnIndex * 10 + 3), - aggregateKind: "thread", - aggregateId: thread.id, - occurredAt: planOccurredAt, - commandId: makeCommandId("perf-plan", String(thread.id), turnIndex), - causationEventId: null, - correlationId: makeCommandId("perf-turn", String(thread.id), turnIndex), - metadata: {}, - payload: { - threadId: thread.id, - proposedPlan: { - id: `perf-plan:${String(thread.id)}:${turnIndex.toString().padStart(4, "0")}`, - turnId, - planMarkdown: buildProposedPlanMarkdown(thread, turnIndex), - implementedAt: null, - implementationThreadId: null, - createdAt: planOccurredAt, - updatedAt: planOccurredAt, + if (planAssistantIndex === assistantMessageIndex) { + const planOccurredAt = plusMs(turnBaseMs, 140 + assistantMessageIndex * 40); + events.push({ + type: "thread.proposed-plan-upserted", + eventId: nextEventId("perf-plan"), + aggregateKind: "thread", + aggregateId: thread.id, + occurredAt: planOccurredAt, + commandId: makeCommandId("perf-plan", String(thread.id), turnIndex), + causationEventId: null, + correlationId: makeCommandId("perf-turn", String(thread.id), turnIndex), + metadata: {}, + payload: { + threadId: thread.id, + proposedPlan: { + id: `perf-plan:${String(thread.id)}:${turnIndex.toString().padStart(4, "0")}`, + turnId, + planMarkdown: buildProposedPlanMarkdown(thread, turnIndex), + implementedAt: null, + implementationThreadId: null, + createdAt: planOccurredAt, + updatedAt: planOccurredAt, + }, }, - }, - }); + }); + } } if (thread.diffStride !== null && turnIndex % thread.diffStride === 0) { - const diffOccurredAt = plusMs(turnBaseMs, 760); + const diffOccurredAt = plusMs(turnBaseMs, 180 + assistantMessageCount * 40); events.push({ type: "thread.turn-diff-completed", - eventId: perfEventId("perf-diff", thread.id, turnIndex * 10 + 4), + eventId: nextEventId("perf-diff"), aggregateKind: "thread", aggregateId: thread.id, occurredAt: diffOccurredAt, @@ -368,7 +425,7 @@ function buildThreadTurnEvents( ), status: "ready", files: buildCheckpointFiles(thread, threadOrdinal, turnIndex), - assistantMessageId, + assistantMessageId: lastAssistantMessageId, completedAt: diffOccurredAt, }, }); @@ -380,27 +437,57 @@ function buildThreadTurnEvents( function buildScenarioEvents( scenario: PerfSeedScenario, - workspaceRoot: string, + workspaceRootsByProjectId: ReadonlyMap, ): ReadonlyArray> { const projectStartMs = Date.parse("2026-03-01T12:00:00.000Z"); - const projectCreatedAt = plusMs(projectStartMs, 0); - return [ - buildProjectEvent(scenario, workspaceRoot, projectCreatedAt), - ...scenario.threads.flatMap((thread, threadOrdinal) => { - const threadCreatedAt = plusMs(projectStartMs, threadOrdinal * 60_000 + 50); - return [ - buildThreadCreatedEvent(thread, scenario, threadCreatedAt), - ...buildThreadTurnEvents(scenario, thread, threadOrdinal, projectStartMs), - ]; - }), - ]; + const threadsByProjectId = new Map(); + for (const thread of scenario.threads) { + const existing = threadsByProjectId.get(thread.projectId) ?? []; + existing.push(thread); + threadsByProjectId.set(thread.projectId, existing); + } + + let globalThreadOrdinal = 0; + const events: Array> = []; + + for (const [projectOrdinal, project] of scenario.projects.entries()) { + const projectWorkspaceRoot = workspaceRootsByProjectId.get(project.id); + if (!projectWorkspaceRoot) { + throw new Error(`Missing workspace root for perf project '${String(project.id)}'.`); + } + const projectBaseMs = projectStartMs + projectOrdinal * 6 * 60_000; + const projectCreatedAt = plusMs(projectBaseMs, 0); + const projectThreads = threadsByProjectId.get(project.id) ?? []; + events.push(buildProjectEvent(project, projectWorkspaceRoot, projectCreatedAt)); + + for (const [threadOrdinalWithinProject, thread] of projectThreads.entries()) { + const threadCreatedAt = plusMs(projectBaseMs, threadOrdinalWithinProject * 45_000 + 50); + const threadEvents = buildThreadTurnEvents(thread, globalThreadOrdinal, projectBaseMs); + globalThreadOrdinal += 1; + events.push(buildThreadCreatedEvent(thread, project, threadCreatedAt), ...threadEvents); + } + } + + return events; } async function createTemplateDir(scenarioId: PerfSeedScenarioId): Promise { const scenario = getPerfSeedScenario(scenarioId); const baseDir = await mkdtemp(join(tmpdir(), `t3-perf-template-${scenarioId}-`)); - const workspaceRoot = join(baseDir, scenario.project.workspaceDirectoryName); - await initializeGitWorkspace(workspaceRoot); + const primaryProject = scenario.projects[0]; + if (!primaryProject) { + throw new Error(`Perf scenario '${scenarioId}' has no projects.`); + } + const workspaceRoot = join(baseDir, primaryProject.workspaceDirectoryName); + const workspaceRootsByProjectId = new Map( + scenario.projects.map((project) => [project.id, join(baseDir, project.workspaceDirectoryName)]), + ); + + await Promise.all( + scenario.projects.map((project) => + initializeGitWorkspace(join(baseDir, project.workspaceDirectoryName)), + ), + ); const seedLayer = Layer.empty.pipe( Layer.provideMerge(OrchestrationProjectionSnapshotQueryLive), @@ -424,7 +511,7 @@ async function createTemplateDir(scenarioId: PerfSeedScenarioId): Promise [project.id, project])); +const scenarioThreadById = new Map(scenario.threads.map((thread) => [thread.id, thread])); +const projectById = new Map(seeded.snapshot.projects.map((project) => [project.id, project])); const payload = JSON.stringify( { scenarioId: seeded.scenarioId, @@ -17,9 +24,22 @@ const payload = JSON.stringify( baseDir: seeded.baseDir, workspaceRoot: seeded.workspaceRoot, projectTitle: seeded.snapshot.projects[0]?.title ?? null, + projectSummaries: seeded.snapshot.projects.map((project) => ({ + id: project.id, + title: project.title, + workspaceRoot: + scenarioProjectById.get(project.id)?.workspaceDirectoryName !== undefined + ? join(seeded.baseDir, scenarioProjectById.get(project.id)?.workspaceDirectoryName ?? "") + : project.workspaceRoot, + threadCount: seeded.snapshot.threads.filter((thread) => thread.projectId === project.id) + .length, + })), threadSummaries: seeded.snapshot.threads.map((thread) => ({ id: thread.id, + projectId: thread.projectId, + projectTitle: projectById.get(thread.projectId)?.title ?? null, title: thread.title, + turnCount: scenarioThreadById.get(thread.id)?.turnCount ?? null, messageCount: thread.messages.length, activityCount: thread.activities.length, proposedPlanCount: thread.proposedPlans.length, diff --git a/apps/web/test/perf/appHarness.ts b/apps/web/test/perf/appHarness.ts index 548d5d2bc2..3f96d7ffdd 100644 --- a/apps/web/test/perf/appHarness.ts +++ b/apps/web/test/perf/appHarness.ts @@ -28,32 +28,42 @@ import { NoopServerSampler, type PerfServerSampler, } from "../../../../test/perf/support/serverSampler"; +import { buildPerfServerEnv } from "./serverEnv"; const repoRoot = fileURLToPath(new URL("../../../../", import.meta.url)); const serverBinPath = resolve(repoRoot, "apps/server/dist/bin.mjs"); const serverClientIndexPath = resolve(repoRoot, "apps/server/dist/client/index.html"); const PERF_ARTIFACT_DIR_ENV = "T3CODE_PERF_ARTIFACT_DIR"; const PERF_HEADFUL_ENV = "T3CODE_PERF_HEADFUL"; -const PERF_PROVIDER_ENV = "T3CODE_PERF_PROVIDER"; -const PERF_SCENARIO_ENV = "T3CODE_PERF_SCENARIO"; const PERF_SEED_JSON_START = "__T3_PERF_SEED_JSON_START__"; const PERF_SEED_JSON_END = "__T3_PERF_SEED_JSON_END__"; interface PerfSeedThreadSummary { readonly id: string; + readonly projectId: string; + readonly projectTitle: string | null; readonly title: string; + readonly turnCount: number | null; readonly messageCount: number; readonly activityCount: number; readonly proposedPlanCount: number; readonly checkpointCount: number; } +interface PerfSeedProjectSummary { + readonly id: string; + readonly title: string; + readonly workspaceRoot: string; + readonly threadCount: number; +} + export interface PerfSeededState { readonly scenarioId: PerfSeedScenarioId; readonly runParentDir: string; readonly baseDir: string; readonly workspaceRoot: string; readonly projectTitle: string | null; + readonly projectSummaries: ReadonlyArray; readonly threadSummaries: ReadonlyArray; } @@ -265,12 +275,7 @@ export async function startPerfAppHarness( const artifactDir = await ensureArtifactDir(options.suite, options.seedScenarioId); const port = await pickFreePort(); const url = `http://127.0.0.1:${port}/`; - const env = { - ...process.env, - T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD: "false", - [PERF_PROVIDER_ENV]: "1", - ...(options.providerScenarioId ? { [PERF_SCENARIO_ENV]: options.providerScenarioId } : {}), - }; + const env = buildPerfServerEnv(process.env, options.providerScenarioId); let stdoutBuffer = ""; let stderrBuffer = ""; @@ -318,7 +323,9 @@ export async function startPerfAppHarness( await page.goto(url, { waitUntil: "domcontentloaded" }); const firstProjectTitle = - seededState.projectTitle ?? getPerfSeedScenario(options.seedScenarioId).project.title; + seededState.projectSummaries[0]?.title ?? + seededState.projectTitle ?? + getPerfSeedScenario(options.seedScenarioId).projects[0]?.title; if (!firstProjectTitle) { throw new Error(`Seed scenario '${options.seedScenarioId}' produced no projects.`); } diff --git a/apps/web/test/perf/serverEnv.ts b/apps/web/test/perf/serverEnv.ts new file mode 100644 index 0000000000..b6799cb94e --- /dev/null +++ b/apps/web/test/perf/serverEnv.ts @@ -0,0 +1,27 @@ +import type { PerfProviderScenarioId } from "@t3tools/shared/perf/scenarioCatalog"; + +export const PERF_PROVIDER_ENV = "T3CODE_PERF_PROVIDER"; +export const PERF_SCENARIO_ENV = "T3CODE_PERF_SCENARIO"; +const AUTO_BOOTSTRAP_PROJECT_ENV = "T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD"; + +export function buildPerfServerEnv( + baseEnv: NodeJS.ProcessEnv, + providerScenarioId?: PerfProviderScenarioId, +): NodeJS.ProcessEnv { + const env: NodeJS.ProcessEnv = { + ...baseEnv, + [AUTO_BOOTSTRAP_PROJECT_ENV]: "false", + }; + + if (!providerScenarioId) { + delete env[PERF_PROVIDER_ENV]; + delete env[PERF_SCENARIO_ENV]; + return env; + } + + return { + ...env, + [PERF_PROVIDER_ENV]: "1", + [PERF_SCENARIO_ENV]: providerScenarioId, + }; +} diff --git a/apps/web/test/perf/supportHelpers.test.ts b/apps/web/test/perf/supportHelpers.test.ts index 2a91e215ef..00b574d601 100644 --- a/apps/web/test/perf/supportHelpers.test.ts +++ b/apps/web/test/perf/supportHelpers.test.ts @@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import { percentile } from "../../../../test/perf/support/artifact"; import { installBrowserPerfCollector } from "../../../../test/perf/support/browserMetrics"; +import { buildPerfServerEnv, PERF_PROVIDER_ENV, PERF_SCENARIO_ENV } from "./serverEnv"; describe("percentile", () => { it("returns the minimum value for the zero percentile", () => { @@ -50,3 +51,26 @@ describe("installBrowserPerfCollector", () => { expect(requestAnimationFrame).toHaveBeenCalledTimes(3); }); }); + +describe("buildPerfServerEnv", () => { + it("does not enable the perf provider when no live provider scenario is requested", () => { + const env = buildPerfServerEnv({ + [PERF_PROVIDER_ENV]: "1", + [PERF_SCENARIO_ENV]: "dense_assistant_stream", + KEEP_ME: "yes", + }); + + expect(env.T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD).toBe("false"); + expect(env[PERF_PROVIDER_ENV]).toBeUndefined(); + expect(env[PERF_SCENARIO_ENV]).toBeUndefined(); + expect(env.KEEP_ME).toBe("yes"); + }); + + it("enables the perf provider only when a live provider scenario is requested", () => { + const env = buildPerfServerEnv({}, "dense_assistant_stream"); + + expect(env.T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD).toBe("false"); + expect(env[PERF_PROVIDER_ENV]).toBe("1"); + expect(env[PERF_SCENARIO_ENV]).toBe("dense_assistant_stream"); + }); +}); diff --git a/apps/web/test/perf/virtualization.perf.test.ts b/apps/web/test/perf/virtualization.perf.test.ts index 10567ec8d9..34b3e8fd88 100644 --- a/apps/web/test/perf/virtualization.perf.test.ts +++ b/apps/web/test/perf/virtualization.perf.test.ts @@ -22,16 +22,26 @@ test("virtualization stays bounded and heavy thread switches remain snappy", asy seedScenarioId: "large_threads", }); - const projectTitle = harness.seededState.projectTitle ?? "Performance Workspace"; - const heavyThreadMessageCount = - harness.seededState.threadSummaries.find( - (thread) => thread.id === PERF_CATALOG_IDS.largeThreads.heavyAThreadId, - )?.messageCount ?? 0; + const heavyAThreadSummary = harness.seededState.threadSummaries.find( + (thread) => thread.id === PERF_CATALOG_IDS.largeThreads.heavyAThreadId, + ); + const heavyBThreadSummary = harness.seededState.threadSummaries.find( + (thread) => thread.id === PERF_CATALOG_IDS.largeThreads.heavyBThreadId, + ); + const heavyAProjectTitle = + heavyAThreadSummary?.projectTitle ?? PERF_CATALOG_IDS.largeThreads.heavyAProjectTitle; + const heavyBProjectTitle = + heavyBThreadSummary?.projectTitle ?? PERF_CATALOG_IDS.largeThreads.heavyBProjectTitle; + const heavyThreadMessageCount = heavyAThreadSummary?.messageCount ?? 0; + expect(heavyAThreadSummary).toBeDefined(); + expect(heavyBThreadSummary).toBeDefined(); expect(heavyThreadMessageCount).toBeGreaterThanOrEqual(2_000); + expect(heavyAThreadSummary?.turnCount ?? 0).toBeLessThan(100); + expect(heavyBThreadSummary?.turnCount ?? 0).toBeLessThan(100); await ensureThreadRowVisible( harness.page, - projectTitle, + heavyAProjectTitle, PERF_CATALOG_IDS.largeThreads.heavyAThreadId, ); await harness.page @@ -45,7 +55,7 @@ test("virtualization stays bounded and heavy thread switches remain snappy", asy await ensureThreadRowVisible( harness.page, - projectTitle, + heavyBProjectTitle, PERF_CATALOG_IDS.largeThreads.heavyBThreadId, ); await harness.page @@ -61,7 +71,7 @@ test("virtualization stays bounded and heavy thread switches remain snappy", asy await measureThreadSwitch(harness, { actionName: "thread-switch-warmup-a", - projectTitle, + projectTitle: heavyAProjectTitle, threadId: PERF_CATALOG_IDS.largeThreads.heavyAThreadId, messageId: PERF_CATALOG_IDS.largeThreads.heavyATerminalMessageId, }); @@ -105,7 +115,10 @@ test("virtualization stays bounded and heavy thread switches remain snappy", asy for (const target of measuredTargets) { await measureThreadSwitch(harness, { actionName: target.actionName, - projectTitle, + projectTitle: + target.threadId === PERF_CATALOG_IDS.largeThreads.heavyAThreadId + ? heavyAProjectTitle + : heavyBProjectTitle, threadId: target.threadId, messageId: target.messageId, }); diff --git a/docs/perf-benchmarks.md b/docs/perf-benchmarks.md index aa93df8782..1de3aa9179 100644 --- a/docs/perf-benchmarks.md +++ b/docs/perf-benchmarks.md @@ -45,21 +45,21 @@ The current implementation is browser-focused, but the harness already reserves Seeded app state used by the virtualization benchmark. -- 1 project -- 12 threads total +- 5 projects +- 30 threads total - 2 heavy threads - 1 burst thread -- 9 light filler threads +- 27 light filler threads spread across all projects The two heavy threads currently seed: -- `1,000` turns +- `84` and `96` turns - `2,000` messages - periodic worklog/activity rows - periodic proposed-plan rows - frequent checkpoint rows with larger changed-file trees -This means the timeline is not just alternating short user/assistant text. The heavy threads include the non-message rows that tend to stress grouping, virtualization, and diff-tree rendering. +This keeps the thread count and project list closer to a real workspace mix: many projects, many sidebar rows, and heavy conversations that stay under `100` turns while still retaining thousands of messages because each turn fans out into multiple assistant messages. The heavy timelines also include the non-message rows that tend to stress grouping, virtualization, and diff-tree rendering. ### `burst_base` @@ -199,7 +199,7 @@ For the websocket scenario, open the burst thread and send one message to start ### Inspect the seeded topology directly -The seed script prints the generated thread summaries as JSON: +The seed script prints the generated project and thread summaries as JSON: ```bash bun run apps/server/scripts/seedPerfState.ts large_threads diff --git a/packages/shared/src/perf/scenarioCatalog.ts b/packages/shared/src/perf/scenarioCatalog.ts index 20f549c4a8..c37c1dc29c 100644 --- a/packages/shared/src/perf/scenarioCatalog.ts +++ b/packages/shared/src/perf/scenarioCatalog.ts @@ -23,6 +23,7 @@ export interface PerfProjectScenario { export interface PerfSeedThreadScenario { readonly id: ThreadId; + readonly projectId: ProjectId; readonly title: string; readonly category: "heavy" | "burst" | "light"; readonly turnCount: number; @@ -36,7 +37,7 @@ export interface PerfSeedThreadScenario { export interface PerfSeedScenario { readonly id: PerfSeedScenarioId; - readonly project: PerfProjectScenario; + readonly projects: ReadonlyArray; readonly threads: ReadonlyArray; } @@ -63,18 +64,26 @@ const PERF_MODEL_SELECTION: ModelSelection = { model: DEFAULT_MODEL_BY_PROVIDER.codex, }; -const PERF_PROJECT: PerfProjectScenario = { - id: ProjectId.makeUnsafe("perf-project-primary"), - title: "Performance Workspace", - workspaceDirectoryName: "perf-workspace", +const makeProjectId = (slug: string) => ProjectId.makeUnsafe(`perf-project-${slug}`); +const makeProject = (slug: string, title: string): PerfProjectScenario => ({ + id: makeProjectId(slug), + title, + workspaceDirectoryName: `perf-workspace-${slug}`, defaultModelSelection: PERF_MODEL_SELECTION, -}; +}); const makeThreadId = (slug: string) => ThreadId.makeUnsafe(`perf-thread-${slug}`); const makeTurnId = (threadSlug: string, index: number) => TurnId.makeUnsafe(`perf-turn-${threadSlug}-${index.toString().padStart(4, "0")}`); -const makeMessageId = (threadSlug: string, role: "user" | "assistant", index: number) => - MessageId.makeUnsafe(`perf-message-${threadSlug}-${role}-${index.toString().padStart(4, "0")}`); +const makeMessageId = ( + threadSlug: string, + role: "user" | "assistant", + turnIndex: number, + messageIndex = 1, +) => + MessageId.makeUnsafe( + `perf-message-${threadSlug}-${role}-${turnIndex.toString().padStart(4, "0")}-${messageIndex.toString().padStart(2, "0")}`, + ); const makeLiveTurnId = (slug: string) => TurnId.makeUnsafe(`perf-live-turn-${slug}`); const makeLiveAssistantItemId = ( laneKey: string, @@ -82,6 +91,122 @@ const makeLiveAssistantItemId = ( segment: "intro" | "followup", ) => `perf-assistant-${laneKey}-${cycleIndex.toString().padStart(2, "0")}-${segment}`; const makeLiveAssistantMessageId = (itemId: string) => MessageId.makeUnsafe(`assistant:${itemId}`); +const threadSlugFromId = (threadId: ThreadId) => threadId.replace("perf-thread-", ""); + +function threadSeedValue(threadSlug: string): number { + return Array.from(threadSlug).reduce( + (sum, character, index) => sum + character.charCodeAt(0) * (index + 1), + 0, + ); +} + +function buildAssistantMessageCountPlan( + input: Pick & { + readonly threadSlug: string; + }, +): ReadonlyArray { + const assistantMessageCount = input.messageCount - input.turnCount; + if (assistantMessageCount < input.turnCount) { + throw new Error( + `Perf thread '${input.threadSlug}' must retain at least one assistant message per turn.`, + ); + } + + const averageAssistantMessages = Math.floor(assistantMessageCount / input.turnCount); + const minPerTurn = Math.max( + 1, + averageAssistantMessages - + (input.category === "heavy" ? 4 : input.category === "burst" ? 2 : 1), + ); + const residualAssistantMessages = assistantMessageCount - minPerTurn * input.turnCount; + const threadSeed = threadSeedValue(input.threadSlug); + const weights = Array.from({ length: input.turnCount }, (_, index) => { + const burstBias = input.category === "heavy" && index % 9 === 0 ? 3 : index % 6 === 0 ? 1 : 0; + return 1 + ((threadSeed + (index + 1) * 11) % 7) + burstBias; + }); + const weightTotal = weights.reduce((sum, weight) => sum + weight, 0); + const quotas = weights.map((weight) => (residualAssistantMessages * weight) / weightTotal); + const counts = quotas.map((quota) => minPerTurn + Math.floor(quota)); + let remainingMessages = assistantMessageCount - counts.reduce((sum, count) => sum + count, 0); + + if (remainingMessages > 0) { + const residualOrder = quotas + .map((quota, index) => ({ + index, + remainder: quota - Math.floor(quota), + })) + .toSorted((left, right) => right.remainder - left.remainder || right.index - left.index); + + for (let index = 0; index < residualOrder.length && remainingMessages > 0; index += 1) { + const targetIndex = residualOrder[index]?.index; + if (targetIndex === undefined) { + break; + } + counts[targetIndex] = (counts[targetIndex] ?? minPerTurn) + 1; + remainingMessages -= 1; + } + } + + return counts; +} + +export function buildPerfAssistantMessageCountPlan( + thread: Pick, +): ReadonlyArray { + return buildAssistantMessageCountPlan({ + threadSlug: threadSlugFromId(thread.id), + category: thread.category, + turnCount: thread.turnCount, + messageCount: thread.messageCount, + }); +} + +function makeSeedThreadScenario(input: { + readonly slug: string; + readonly projectId: ProjectId; + readonly title: string; + readonly category: PerfSeedThreadScenario["category"]; + readonly turnCount: number; + readonly messageCount: number; + readonly planStride: number | null; + readonly activityStride: number | null; + readonly diffStride: number | null; +}): PerfSeedThreadScenario { + const assistantMessageCountPlan = buildAssistantMessageCountPlan({ + threadSlug: input.slug, + category: input.category, + turnCount: input.turnCount, + messageCount: input.messageCount, + }); + + return { + id: makeThreadId(input.slug), + projectId: input.projectId, + title: input.title, + category: input.category, + turnCount: input.turnCount, + messageCount: input.messageCount, + anchorMessageId: makeMessageId(input.slug, "user", 1, 1), + terminalMessageId: makeMessageId( + input.slug, + "assistant", + input.turnCount, + assistantMessageCountPlan.at(-1) ?? 1, + ), + planStride: input.planStride, + activityStride: input.activityStride, + diffStride: input.diffStride, + }; +} + +const PERF_PROJECTS = { + inbox: makeProject("inbox", "Inbox Refactor Workspace"), + desktop: makeProject("desktop", "Desktop Release Workspace"), + runtime: makeProject("runtime", "Runtime Orchestration Workspace"), + marketing: makeProject("marketing", "Marketing Site Workspace"), + ops: makeProject("ops", "Ops Automation Workspace"), + burstBase: makeProject("burst-base", "Burst Harness Workspace"), +} as const; const PERF_PROVIDER_LIVE_TURNS = { navigation: makeLiveTurnId("navigation"), @@ -89,89 +214,159 @@ const PERF_PROVIDER_LIVE_TURNS = { } as const; const LARGE_THREAD_DEFINITIONS = { - heavyA: { - id: makeThreadId("heavy-a"), - title: "Large Thread A", + heavyA: makeSeedThreadScenario({ + slug: "heavy-a", + projectId: PERF_PROJECTS.inbox.id, + title: "Inbox Search Regression", category: "heavy", - turnCount: 1_000, + turnCount: 84, messageCount: 2_000, - anchorMessageId: makeMessageId("heavy-a", "user", 1), - terminalMessageId: makeMessageId("heavy-a", "assistant", 1_000), - planStride: 120, - activityStride: 32, - diffStride: 12, - }, - heavyB: { - id: makeThreadId("heavy-b"), - title: "Large Thread B", + planStride: 11, + activityStride: 4, + diffStride: 3, + }), + heavyB: makeSeedThreadScenario({ + slug: "heavy-b", + projectId: PERF_PROJECTS.desktop.id, + title: "Desktop Update Rollout", category: "heavy", - turnCount: 1_000, + turnCount: 96, messageCount: 2_000, - anchorMessageId: makeMessageId("heavy-b", "user", 1), - terminalMessageId: makeMessageId("heavy-b", "assistant", 1_000), - planStride: 125, - activityStride: 36, - diffStride: 14, - }, - burst: { - id: makeThreadId("burst"), - title: "Burst Target Thread", + planStride: 12, + activityStride: 5, + diffStride: 4, + }), + burst: makeSeedThreadScenario({ + slug: "large-burst", + projectId: PERF_PROJECTS.runtime.id, + title: "Runtime Burst Coordination", category: "burst", - turnCount: 120, - messageCount: 240, - anchorMessageId: makeMessageId("burst", "user", 1), - terminalMessageId: makeMessageId("burst", "assistant", 120), - planStride: 30, - activityStride: 10, - diffStride: 12, - }, + turnCount: 48, + messageCount: 640, + planStride: 12, + activityStride: 4, + diffStride: 5, + }), } as const satisfies Record; -const LIGHT_THREADS: ReadonlyArray = Array.from( - { length: 9 }, - (_, index) => { - const threadNumber = index + 1; - const slug = `light-${threadNumber.toString().padStart(2, "0")}`; - return { - id: makeThreadId(slug), - title: `Light Thread ${threadNumber}`, - category: "light", - turnCount: 12, - messageCount: 24, - anchorMessageId: makeMessageId(slug, "user", 1), - terminalMessageId: makeMessageId(slug, "assistant", 12), - planStride: null, - activityStride: 6, - diffStride: null, - } satisfies PerfSeedThreadScenario; +const LARGE_THREAD_LIGHT_LAYOUT = [ + { + project: PERF_PROJECTS.inbox, + label: "Inbox", + count: 5, }, -); + { + project: PERF_PROJECTS.desktop, + label: "Desktop", + count: 6, + }, + { + project: PERF_PROJECTS.runtime, + label: "Runtime", + count: 5, + }, + { + project: PERF_PROJECTS.marketing, + label: "Marketing", + count: 6, + }, + { + project: PERF_PROJECTS.ops, + label: "Ops", + count: 5, + }, +] as const; -const BURST_NAVIGATION_THREAD: PerfSeedThreadScenario = { - ...LIGHT_THREADS[0]!, - title: "Burst Navigation Thread", -}; +const LARGE_THREAD_LIGHT_THREADS: ReadonlyArray = + LARGE_THREAD_LIGHT_LAYOUT.flatMap((layout, projectIndex) => + Array.from({ length: layout.count }, (_, localIndex) => { + const globalIndex = + LARGE_THREAD_LIGHT_LAYOUT.slice(0, projectIndex).reduce( + (sum, entry) => sum + entry.count, + 0, + ) + localIndex; + const threadNumber = localIndex + 1; + const turnCount = 18 + ((globalIndex * 7 + projectIndex * 5 + localIndex * 3) % 8) * 7; + const messageDensity = 4 + ((globalIndex + projectIndex + localIndex) % 5); + const messageCount = Math.min( + 900, + turnCount * messageDensity + 48 + ((globalIndex + projectIndex) % 5) * 18, + ); -const BURST_FILLER_THREAD: PerfSeedThreadScenario = { - ...LIGHT_THREADS[1]!, - title: "Burst Filler Thread", -}; + return makeSeedThreadScenario({ + slug: `${layout.label.toLowerCase()}-light-${threadNumber.toString().padStart(2, "0")}`, + projectId: layout.project.id, + title: `${layout.label} Thread ${threadNumber}`, + category: "light", + turnCount, + messageCount, + planStride: globalIndex % 4 === 0 ? 14 + ((globalIndex + localIndex) % 5) : null, + activityStride: 5 + ((globalIndex + localIndex) % 4), + diffStride: globalIndex % 3 === 0 ? 6 + ((projectIndex + localIndex) % 4) : null, + }); + }), + ); + +const BURST_BASE_THREAD_DEFINITIONS = { + burst: makeSeedThreadScenario({ + slug: "burst", + projectId: PERF_PROJECTS.burstBase.id, + title: "Burst Target Thread", + category: "burst", + turnCount: 36, + messageCount: 220, + planStride: 12, + activityStride: 4, + diffStride: 6, + }), + navigation: makeSeedThreadScenario({ + slug: "burst-navigation", + projectId: PERF_PROJECTS.burstBase.id, + title: "Burst Navigation Thread", + category: "light", + turnCount: 28, + messageCount: 112, + planStride: null, + activityStride: 5, + diffStride: null, + }), + filler: makeSeedThreadScenario({ + slug: "burst-filler", + projectId: PERF_PROJECTS.burstBase.id, + title: "Burst Filler Thread", + category: "light", + turnCount: 24, + messageCount: 96, + planStride: null, + activityStride: 6, + diffStride: null, + }), +} as const satisfies Record; + +const BURST_NAVIGATION_THREAD = BURST_BASE_THREAD_DEFINITIONS.navigation; +const BURST_FILLER_THREAD = BURST_BASE_THREAD_DEFINITIONS.filler; export const PERF_SEED_SCENARIOS = { large_threads: { id: "large_threads", - project: PERF_PROJECT, + projects: [ + PERF_PROJECTS.inbox, + PERF_PROJECTS.desktop, + PERF_PROJECTS.runtime, + PERF_PROJECTS.marketing, + PERF_PROJECTS.ops, + ], threads: [ LARGE_THREAD_DEFINITIONS.heavyA, LARGE_THREAD_DEFINITIONS.heavyB, LARGE_THREAD_DEFINITIONS.burst, - ...LIGHT_THREADS, + ...LARGE_THREAD_LIGHT_THREADS, ], }, burst_base: { id: "burst_base", - project: PERF_PROJECT, - threads: [LARGE_THREAD_DEFINITIONS.burst, BURST_NAVIGATION_THREAD, BURST_FILLER_THREAD], + projects: [PERF_PROJECTS.burstBase], + threads: [BURST_BASE_THREAD_DEFINITIONS.burst, BURST_NAVIGATION_THREAD, BURST_FILLER_THREAD], }, } as const satisfies Record; @@ -899,19 +1094,25 @@ export const PERF_PROVIDER_SCENARIOS = { } as const satisfies Record; export const PERF_CATALOG_IDS = { - projectId: PERF_PROJECT.id, + projectId: PERF_PROJECTS.inbox.id, largeThreads: { heavyAThreadId: LARGE_THREAD_DEFINITIONS.heavyA.id, heavyBThreadId: LARGE_THREAD_DEFINITIONS.heavyB.id, + heavyAProjectId: LARGE_THREAD_DEFINITIONS.heavyA.projectId, + heavyBProjectId: LARGE_THREAD_DEFINITIONS.heavyB.projectId, + heavyAProjectTitle: PERF_PROJECTS.inbox.title, + heavyBProjectTitle: PERF_PROJECTS.desktop.title, heavyAAnchorMessageId: LARGE_THREAD_DEFINITIONS.heavyA.anchorMessageId, heavyBAnchorMessageId: LARGE_THREAD_DEFINITIONS.heavyB.anchorMessageId, heavyATerminalMessageId: LARGE_THREAD_DEFINITIONS.heavyA.terminalMessageId, heavyBTerminalMessageId: LARGE_THREAD_DEFINITIONS.heavyB.terminalMessageId, }, burstBase: { - burstThreadId: LARGE_THREAD_DEFINITIONS.burst.id, - burstAnchorMessageId: LARGE_THREAD_DEFINITIONS.burst.anchorMessageId, - burstTerminalMessageId: LARGE_THREAD_DEFINITIONS.burst.terminalMessageId, + burstProjectId: PERF_PROJECTS.burstBase.id, + burstProjectTitle: PERF_PROJECTS.burstBase.title, + burstThreadId: BURST_BASE_THREAD_DEFINITIONS.burst.id, + burstAnchorMessageId: BURST_BASE_THREAD_DEFINITIONS.burst.anchorMessageId, + burstTerminalMessageId: BURST_BASE_THREAD_DEFINITIONS.burst.terminalMessageId, navigationThreadId: BURST_NAVIGATION_THREAD.id, navigationAnchorMessageId: BURST_NAVIGATION_THREAD.anchorMessageId, navigationTerminalMessageId: BURST_NAVIGATION_THREAD.terminalMessageId, @@ -942,7 +1143,7 @@ export function getPerfProviderScenario(scenarioId: PerfProviderScenarioId): Per } export function perfTurnIdForThread(thread: PerfSeedThreadScenario, turnIndex: number): TurnId { - const threadSlug = thread.id.replace("perf-thread-", ""); + const threadSlug = threadSlugFromId(thread.id); return makeTurnId(threadSlug, turnIndex); } @@ -950,9 +1151,10 @@ export function perfMessageIdForThread( thread: PerfSeedThreadScenario, role: "user" | "assistant", turnIndex: number, + messageIndex = 1, ): MessageId { - const threadSlug = thread.id.replace("perf-thread-", ""); - return makeMessageId(threadSlug, role, turnIndex); + const threadSlug = threadSlugFromId(thread.id); + return makeMessageId(threadSlug, role, turnIndex, messageIndex); } export function perfEventId(prefix: string, threadId: ThreadId, index: number) { diff --git a/scripts/open-perf-app.ts b/scripts/open-perf-app.ts index 83dfd9dad2..ddb77629ce 100644 --- a/scripts/open-perf-app.ts +++ b/scripts/open-perf-app.ts @@ -18,19 +18,30 @@ type PerfProviderScenarioId = "dense_assistant_stream"; interface PerfSeedThreadSummary { readonly id: string; + readonly projectId: string; + readonly projectTitle: string | null; readonly title: string; + readonly turnCount: number | null; readonly messageCount: number; readonly activityCount: number; readonly proposedPlanCount: number; readonly checkpointCount: number; } +interface PerfSeedProjectSummary { + readonly id: string; + readonly title: string; + readonly workspaceRoot: string; + readonly threadCount: number; +} + interface PerfSeededState { readonly scenarioId: PerfSeedScenarioId; readonly runParentDir: string; readonly baseDir: string; readonly workspaceRoot: string; readonly projectTitle: string | null; + readonly projectSummaries: ReadonlyArray; readonly threadSummaries: ReadonlyArray; } @@ -279,15 +290,21 @@ function printSeedSummary( process.stdout.write(`\nPerf app ready at ${url}\n`); process.stdout.write(`Scenario: ${seededState.scenarioId}\n`); process.stdout.write(`Base dir: ${seededState.baseDir}\n`); - process.stdout.write(`Workspace: ${seededState.workspaceRoot}\n`); - process.stdout.write(`Project: ${seededState.projectTitle ?? ""}\n`); + process.stdout.write(`Primary workspace: ${seededState.workspaceRoot}\n`); + process.stdout.write("Projects:\n"); + for (const project of seededState.projectSummaries) { + process.stdout.write( + ` - ${project.title} (${project.id}): ${project.threadCount} threads, ${project.workspaceRoot}\n`, + ); + } + process.stdout.write("Threads:\n"); for (const thread of seededState.threadSummaries.toSorted( (left, right) => right.messageCount - left.messageCount || left.title.localeCompare(right.title), )) { process.stdout.write( - ` - ${thread.title} (${thread.id}): ${thread.messageCount} messages, ${thread.activityCount} worklog rows, ${thread.proposedPlanCount} plans, ${thread.checkpointCount} checkpoints\n`, + ` - ${thread.projectTitle ?? ""} / ${thread.title} (${thread.id}): ${thread.turnCount ?? "?"} turns, ${thread.messageCount} messages, ${thread.activityCount} worklog rows, ${thread.proposedPlanCount} plans, ${thread.checkpointCount} checkpoints\n`, ); }