- Add @t3tools/core package with Effect-based domain model - Add @t3tools/infra-sqlite package for SQLite persistence - Add CoreRuntime to server integrating the new packages - Remove client-side persistence (persistenceSchema.ts, store.test.ts) - Simplify web store by delegating persistence to server - Update contracts with new IPC and WebSocket message types
Unified · Split
| @@ -17,6 +17,9 @@ · 16 unmodified lines | ||
| 17 | 17 | "test": "vitest run" |
| 18 | 18 | }, |
| 19 | 19 | "dependencies": { |
| 20 | + "@t3tools/core": "workspace:*", | |
| 21 | + "@t3tools/infra-sqlite": "workspace:*", | |
| 22 | + "effect": "^3.18.4", | |
| 20 | 23 | "node-pty": "^1.1.0", |
| 21 | 24 | "open": "^10.1.0", |
| 22 | 25 | "ws": "^8.18.0" |
| @@ -0,0 +1,108 @@ | ||
| 1 | +import path from "node:path"; | |
| 2 | +import crypto from "node:crypto"; | |
| 3 | +import type { ProviderEvent, ProviderSession, TerminalEvent } from "@t3tools/contracts"; | |
| 4 | +import { EffectFanout, OrchestrationEngine, QueueProjector, type AppViewState } from "@t3tools/core"; | |
| 5 | +import { createSqliteStores } from "@t3tools/infra-sqlite"; | |
| 6 | + | |
| 7 | +import type { ProviderManager } from "./providerManager"; | |
| 8 | +import type { TerminalManager } from "./terminalManager"; | |
| 9 | + | |
| 10 | +function nowIso(): string { | |
| 11 | + return new Date().toISOString(); | |
| 12 | +} | |
| 13 | + | |
| 14 | +export class CoreRuntime { | |
| 15 | + private readonly fanout = new EffectFanout(); | |
| 16 | + private readonly stores; | |
| 17 | + private readonly projector: QueueProjector; | |
| 18 | + private readonly engine: OrchestrationEngine; | |
| 19 | + | |
| 20 | + constructor(dbDir: string) { | |
| 21 | + const dbPath = path.join(dbDir, "event-store.sqlite"); | |
| 22 | + this.stores = createSqliteStores(dbPath); | |
| 23 | + this.projector = new QueueProjector(this.stores.projectionStore, this.fanout); | |
| 24 | + this.engine = new OrchestrationEngine(this.stores.eventStore, this.stores.projectionStore, this.projector); | |
| 25 | + } | |
| 26 | + | |
| 27 | + async start(cwd: string, projectName: string): Promise<void> { | |
| 28 | + await this.engine.start(); | |
| 29 | + await this.engine.execute({ | |
| 30 | + id: crypto.randomUUID(), | |
| 31 | + type: "app.bootstrap", | |
| 32 | + issuedAt: nowIso(), | |
| 33 | + payload: { cwd, projectName }, | |
| 34 | + }); | |
| 35 | + } | |
| 36 | + | |
| 37 | + async stop(): Promise<void> { | |
| 38 | + await this.engine.stop(); | |
| 39 | + this.stores.db.close(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + async state(): Promise<AppViewState> { | |
| 43 | + return this.engine.currentState(); | |
| 44 | + } | |
| 45 | + | |
| 46 | + async dispatch(command: Parameters<OrchestrationEngine["execute"]>[0]): Promise<AppViewState> { | |
| 47 | + return this.engine.execute(command); | |
| 48 | + } | |
| 49 | + | |
| 50 | + subscribe() { | |
| 51 | + return this.fanout.subscribe(); | |
| 52 | + } | |
| 53 | + | |
| 54 | + bindProviderEvents(providerManager: ProviderManager): void { | |
| 55 | + providerManager.on("event", (event: ProviderEvent) => { | |
| 56 | + void this.ingestProviderEvent(event); | |
| 57 | + }); | |
| 58 | + } | |
| 59 | + | |
| 60 | + bindTerminalEvents(terminalManager: TerminalManager): void { | |
| 61 | + terminalManager.on("event", (event: TerminalEvent) => { | |
| 62 | + if (event.type !== "activity" && event.type !== "error" && event.type !== "exited") return; | |
| 63 | + void this.dispatch({ | |
| 64 | + id: crypto.randomUUID(), | |
| 65 | + type: "thread.setTerminalActivity", | |
| 66 | + issuedAt: event.createdAt, | |
| 67 | + payload: { | |
| 68 | + threadId: event.threadId, | |
| 69 | + terminalId: event.terminalId, | |
| 70 | + running: event.type === "activity" ? event.hasRunningSubprocess : false, | |
| 71 | + }, | |
| 72 | + }); | |
| 73 | + }); | |
| 74 | + } | |
| 75 | + | |
| 76 | + async bindProviderSession(threadId: string, session: ProviderSession): Promise<void> { | |
| 77 | + await this.dispatch({ | |
| 78 | + id: crypto.randomUUID(), | |
| 79 | + type: "thread.updateProviderSession", | |
| 80 | + issuedAt: nowIso(), | |
| 81 | + payload: { threadId, session }, | |
| 82 | + }); | |
| 83 | + } | |
| 84 | + | |
| 85 | + async clearProviderSession(threadId: string): Promise<void> { | |
| 86 | + await this.dispatch({ | |
| 87 | + id: crypto.randomUUID(), | |
| 88 | + type: "thread.updateProviderSession", | |
| 89 | + issuedAt: nowIso(), | |
| 90 | + payload: { threadId, session: null }, | |
| 91 | + }); | |
| 92 | + } | |
| 93 | + | |
| 94 | + async ingestProviderEvent(event: ProviderEvent): Promise<void> { | |
| 95 | + const state = await this.state(); | |
| 96 | + const target = state.threads.find((thread) => thread.session?.sessionId === event.sessionId); | |
| 97 | + if (!target) return; | |
| 98 | + await this.dispatch({ | |
| 99 | + id: crypto.randomUUID(), | |
| 100 | + type: "thread.recordProviderEvent", | |
| 101 | + issuedAt: event.createdAt, | |
| 102 | + payload: { | |
| 103 | + threadId: target.id, | |
| 104 | + event, | |
| 105 | + }, | |
| 106 | + }); | |
| 107 | + } | |
| 108 | +} | |
| @@ -121,6 +121,7 @@ async function main() { · 120 unmodified lines | ||
| 121 | 121 | staticDir, |
| 122 | 122 | devUrl, |
| 123 | 123 | projectRegistry, |
| 124 | + stateDir, | |
| 124 | 125 | authToken, |
| 125 | 126 | }); |
| 126 | 127 | await server.start(); |
| @@ -3,6 +3,7 @@ import fs from "node:fs"; · 2 unmodified lines | ||
| 3 | 3 | import http from "node:http"; |
| 4 | 4 | import os from "node:os"; |
| 5 | 5 | import path from "node:path"; |
| 6 | +import crypto from "node:crypto"; | |
| 6 | 7 | import type { Duplex } from "node:stream"; |
| 7 | 8 | |
| 8 | 9 | import { |
| @@ -33,6 +34,7 @@ import { · 24 unmodified lines | ||
| 33 | 34 | import { TerminalManager } from "./terminalManager"; |
| 34 | 35 | import { loadResolvedKeybindingsConfig, upsertKeybindingRule } from "./keybindings"; |
| 35 | 36 | import { searchWorkspaceEntries } from "./workspaceEntries"; |
| 37 | +import { CoreRuntime } from "./coreRuntime"; | |
| 36 | 38 | |
| 37 | 39 | const MIME_TYPES: Record<string, string> = { |
| 38 | 40 | ".html": "text/html; charset=utf-8", |
| @@ -57,6 +59,7 @@ export interface ServerOptions { · 18 unmodified lines | ||
| 57 | 59 | devUrl?: string | undefined; |
| 58 | 60 | logWebSocketEvents?: boolean | undefined; |
| 59 | 61 | projectRegistry?: ProjectRegistry | undefined; |
| 62 | + stateDir?: string | undefined; | |
| 60 | 63 | gitManager?: GitManager | undefined; |
| 61 | 64 | terminalManager?: TerminalManager | undefined; |
| 62 | 65 | authToken?: string | undefined; |
| @@ -79,6 +82,7 @@ export function createServer(options: ServerOptions) { · 16 unmodified lines | ||
| 79 | 82 | devUrl, |
| 80 | 83 | logWebSocketEvents: explicitLogWsEvents, |
| 81 | 84 | projectRegistry: providedRegistry, |
| 85 | + stateDir, | |
| 82 | 86 | gitManager: providedGitManager, |
| 83 | 87 | terminalManager: providedTerminalManager, |
| 84 | 88 | authToken, |
| @@ -88,8 +92,12 @@ export function createServer(options: ServerOptions) { · 3 unmodified lines | ||
| 88 | 92 | const projectRegistry = |
| 89 | 93 | providedRegistry ?? new ProjectRegistry(path.join(os.homedir(), ".t3", "userdata")); |
| 90 | 94 | const gitManager = providedGitManager ?? new GitManager(); |
| 95 | + const runtimeStateDir = stateDir ?? path.join(os.homedir(), ".t3", "userdata"); | |
| 96 | + const coreRuntime = new CoreRuntime(runtimeStateDir); | |
| 91 | 97 | const clients = new Set<WebSocket>(); |
| 92 | 98 | const logger = createLogger("ws"); |
| 99 | + const segments = cwd.split(/[/\\]/).filter(Boolean); | |
| 100 | + const projectName = segments[segments.length - 1] ?? "project"; | |
| 93 | 101 | const logWebSocketEvents = |
| 94 | 102 | explicitLogWsEvents ?? parseBooleanEnv(process.env.T3CODE_LOG_WS_EVENTS) ?? Boolean(devUrl); |
| 95 | 103 | let keybindingsConfig = loadResolvedKeybindingsConfig(logger); |
| @@ -103,13 +111,7 @@ export function createServer(options: ServerOptions) { · 7 unmodified lines | ||
| 103 | 111 | }); |
| 104 | 112 | } |
| 105 | 113 | |
| 106 | − // Forward provider events to all connected WebSocket clients | |
| 107 | − providerManager.on("event", (event) => { | |
| 108 | − const push: WsPush = { | |
| 109 | − type: "push", | |
| 110 | − channel: WS_CHANNELS.providerEvent, | |
| 111 | − data: event, | |
| 112 | − }; | |
| 114 | + function broadcastPush(push: WsPush): void { | |
| 113 | 115 | const message = JSON.stringify(push); |
| 114 | 116 | let recipients = 0; |
| 115 | 117 | for (const client of clients) { |
| @@ -119,25 +121,31 @@ export function createServer(options: ServerOptions) { · 3 unmodified lines | ||
| 119 | 121 | } |
| 120 | 122 | } |
| 121 | 123 | logOutgoingPush(push, recipients); |
| 122 | − }); | |
| 124 | + } | |
| 123 | 125 | |
| 124 | 126 | const onTerminalEvent = (event: TerminalEvent) => { |
| 125 | − const push: WsPush = { | |
| 127 | + broadcastPush({ | |
| 126 | 128 | type: "push", |
| 127 | 129 | channel: WS_CHANNELS.terminalEvent, |
| 128 | 130 | data: event, |
| 129 | − }; | |
| 130 | − const message = JSON.stringify(push); | |
| 131 | − let recipients = 0; | |
| 132 | − for (const client of clients) { | |
| 133 | − if (client.readyState === client.OPEN) { | |
| 134 | − client.send(message); | |
| 135 | − recipients += 1; | |
| 136 | − } | |
| 131 | + }); | |
| 132 | + if (event.type === "activity" || event.type === "exited" || event.type === "error") { | |
| 133 | + void coreRuntime.dispatch({ | |
| 134 | + id: crypto.randomUUID(), | |
| 135 | + type: "thread.setTerminalActivity", | |
| 136 | + issuedAt: event.createdAt, | |
| 137 | + payload: { | |
| 138 | + threadId: event.threadId, | |
| 139 | + terminalId: event.terminalId, | |
| 140 | + running: event.type === "activity" ? event.hasRunningSubprocess : false, | |
| 141 | + }, | |
| 142 | + }); | |
| 137 | 143 | } |
| 138 | − logOutgoingPush(push, recipients); | |
| 139 | 144 | }; |
| 140 | 145 | terminalManager.on("event", onTerminalEvent); |
| 146 | + coreRuntime.bindProviderEvents(providerManager); | |
| 147 | + let stateStreamStopped = false; | |
| 148 | + let stateStreamTask: Promise<void> | null = null; | |
| 141 | 149 | |
| 142 | 150 | // HTTP server — serves static files or redirects to Vite dev server |
| 143 | 151 | const httpServer = http.createServer((req, res) => { |
| @@ -235,10 +243,6 @@ export function createServer(options: ServerOptions) { · 91 unmodified lines | ||
| 235 | 243 | wss.on("connection", (ws) => { |
| 236 | 244 | clients.add(ws); |
| 237 | 245 | |
| 238 | − // Send welcome message with project info | |
| 239 | − const segments = cwd.split(/[/\\]/).filter(Boolean); | |
| 240 | − const projectName = segments[segments.length - 1] ?? "project"; | |
| 241 | − | |
| 242 | 246 | const welcome: WsPush = { |
| 243 | 247 | type: "push", |
| 244 | 248 | channel: WS_CHANNELS.serverWelcome, |
| @@ -289,12 +293,44 @@ export function createServer(options: ServerOptions) { · 44 unmodified lines | ||
| 289 | 293 | } |
| 290 | 294 | |
| 291 | 295 | async function routeRequest(request: WsRequest): Promise<unknown> { |
| 296 | + const requestNow = new Date().toISOString(); | |
| 297 | + const paramsObj = (request.params ?? {}) as Record<string, unknown>; | |
| 298 | + const state = await coreRuntime.state(); | |
| 299 | + const findThreadBySessionId = (sessionId: string | undefined) => | |
| 300 | + sessionId | |
| 301 | + ? state.threads.find((thread) => thread.session?.sessionId === sessionId) | |
| 302 | + : undefined; | |
| 303 | + | |
| 292 | 304 | switch (request.method) { |
| 293 | − case WS_METHODS.providersStartSession: | |
| 294 | − return providerManager.startSession(request.params as never); | |
| 305 | + case WS_METHODS.providersStartSession: { | |
| 306 | + const session = await providerManager.startSession(request.params as never); | |
| 307 | + const uiThreadId = typeof paramsObj.uiThreadId === "string" ? paramsObj.uiThreadId : undefined; | |
| 308 | + if (uiThreadId) { | |
| 309 | + await coreRuntime.bindProviderSession(uiThreadId, session); | |
| 310 | + } | |
| 311 | + return session; | |
| 312 | + } | |
| 295 | 313 | |
| 296 | − case WS_METHODS.providersSendTurn: | |
| 314 | + case WS_METHODS.providersSendTurn: { | |
| 315 | + const sessionId = typeof paramsObj.sessionId === "string" ? paramsObj.sessionId : undefined; | |
| 316 | + const uiThreadId = typeof paramsObj.uiThreadId === "string" ? paramsObj.uiThreadId : undefined; | |
| 317 | + const targetThread = uiThreadId ? state.threads.find((thread) => thread.id === uiThreadId) : findThreadBySessionId(sessionId); | |
| 318 | + const inputText = typeof paramsObj.input === "string" ? paramsObj.input : undefined; | |
| 319 | + if (targetThread && inputText && inputText.trim().length > 0) { | |
| 320 | + await coreRuntime.dispatch({ | |
| 321 | + id: crypto.randomUUID(), | |
| 322 | + type: "thread.addUserMessage", | |
| 323 | + issuedAt: requestNow, | |
| 324 | + payload: { | |
| 325 | + threadId: targetThread.id, | |
| 326 | + messageId: crypto.randomUUID(), | |
| 327 | + text: inputText, | |
| 328 | + createdAt: requestNow, | |
| 329 | + }, | |
| 330 | + }); | |
| 331 | + } | |
| 297 | 332 | return providerManager.sendTurn(request.params as never); |
| 333 | + } | |
| 298 | 334 | |
| 299 | 335 | case WS_METHODS.providersInterruptTurn: |
| 300 | 336 | return providerManager.interruptTurn(request.params as never); |
| @@ -303,7 +339,12 @@ export function createServer(options: ServerOptions) { · 2 unmodified lines | ||
| 303 | 339 | return providerManager.respondToRequest(request.params as never); |
| 304 | 340 | |
| 305 | 341 | case WS_METHODS.providersStopSession: { |
| 342 | + const sessionId = typeof paramsObj.sessionId === "string" ? paramsObj.sessionId : undefined; | |
| 343 | + const boundThread = findThreadBySessionId(sessionId); | |
| 306 | 344 | providerManager.stopSession(request.params as never); |
| 345 | + if (boundThread) { | |
| 346 | + await coreRuntime.clearProviderSession(boundThread.id); | |
| 347 | + } | |
| 307 | 348 | return undefined; |
| 308 | 349 | } |
| 309 | 350 | |
| @@ -323,16 +364,51 @@ export function createServer(options: ServerOptions) { · 13 unmodified lines | ||
| 323 | 364 | return projectRegistry.list(); |
| 324 | 365 | |
| 325 | 366 | case WS_METHODS.projectsAdd: |
| 326 | − return projectRegistry.add(request.params as never); | |
| 367 | + { | |
| 368 | + const result = projectRegistry.add(request.params as never); | |
| 369 | + await coreRuntime.dispatch({ | |
| 370 | + id: crypto.randomUUID(), | |
| 371 | + type: "project.add", | |
| 372 | + issuedAt: requestNow, | |
| 373 | + payload: { | |
| 374 | + id: result.project.id, | |
| 375 | + name: result.project.name, | |
| 376 | + cwd: result.project.cwd, | |
| 377 | + model: "gpt-5-codex", | |
| 378 | + scripts: result.project.scripts, | |
| 379 | + }, | |
| 380 | + }); | |
| 381 | + return result; | |
| 382 | + } | |
| 327 | 383 | |
| 328 | 384 | case WS_METHODS.projectsRemove: |
| 385 | + { | |
| 386 | + const projectId = typeof paramsObj.id === "string" ? paramsObj.id : undefined; | |
| 387 | + if (projectId) { | |
| 388 | + await coreRuntime.dispatch({ | |
| 389 | + id: crypto.randomUUID(), | |
| 390 | + type: "project.remove", | |
| 391 | + issuedAt: requestNow, | |
| 392 | + payload: { id: projectId }, | |
| 393 | + }); | |
| 394 | + } | |
| 329 | 395 | projectRegistry.remove(request.params as never); |
| 330 | 396 | return undefined; |
| 397 | + } | |
| 331 | 398 | |
| 332 | 399 | case WS_METHODS.projectsSearchEntries: |
| 333 | 400 | return searchWorkspaceEntries(request.params as never); |
| 334 | 401 | case WS_METHODS.projectsUpdateScripts: |
| 335 | − return projectRegistry.updateScripts(request.params as never); | |
| 402 | + { | |
| 403 | + const result = projectRegistry.updateScripts(request.params as never); | |
| 404 | + await coreRuntime.dispatch({ | |
| 405 | + id: crypto.randomUUID(), | |
| 406 | + type: "project.updateScripts", | |
| 407 | + issuedAt: requestNow, | |
| 408 | + payload: { id: result.project.id, scripts: result.project.scripts }, | |
| 409 | + }); | |
| 410 | + return result; | |
| 411 | + } | |
| 336 | 412 | |
| 337 | 413 | case WS_METHODS.shellOpenInEditor: { |
| 338 | 414 | const params = request.params as { |
| @@ -438,6 +514,61 @@ export function createServer(options: ServerOptions) { · 99 unmodified lines | ||
| 438 | 514 | keybindings: keybindingsConfig, |
| 439 | 515 | }; |
| 440 | 516 | |
| 517 | + case WS_METHODS.stateGetSnapshot: | |
| 518 | + return coreRuntime.state(); | |
| 519 | + | |
| 520 | + case WS_METHODS.stateCreateThread: { | |
| 521 | + const params = request.params as { | |
| 522 | + id: string; | |
| 523 | + projectId: string; | |
| 524 | + title: string; | |
| 525 | + model: string; | |
| 526 | + createdAt: string; | |
| 527 | + branch: string | null; | |
| 528 | + worktreePath: string | null; | |
| 529 | + }; | |
| 530 | + await coreRuntime.dispatch({ | |
| 531 | + id: crypto.randomUUID(), | |
| 532 | + type: "thread.create", | |
| 533 | + issuedAt: requestNow, | |
| 534 | + payload: params, | |
| 535 | + }); | |
| 536 | + return coreRuntime.state(); | |
| 537 | + } | |
| 538 | + | |
| 539 | + case WS_METHODS.stateDeleteThread: { | |
| 540 | + const params = request.params as { id: string }; | |
| 541 | + await coreRuntime.dispatch({ | |
| 542 | + id: crypto.randomUUID(), | |
| 543 | + type: "thread.delete", | |
| 544 | + issuedAt: requestNow, | |
| 545 | + payload: params, | |
| 546 | + }); | |
| 547 | + return coreRuntime.state(); | |
| 548 | + } | |
| 549 | + | |
| 550 | + case WS_METHODS.stateMarkThreadVisited: { | |
| 551 | + const params = request.params as { threadId: string; visitedAt?: string }; | |
| 552 | + await coreRuntime.dispatch({ | |
| 553 | + id: crypto.randomUUID(), | |
| 554 | + type: "thread.markVisited", | |
| 555 | + issuedAt: requestNow, | |
| 556 | + payload: { threadId: params.threadId, visitedAt: params.visitedAt ?? requestNow }, | |
| 557 | + }); | |
| 558 | + return undefined; | |
| 559 | + } | |
| 560 | + | |
| 561 | + case WS_METHODS.stateSetRuntimeMode: { | |
| 562 | + const params = request.params as { mode: "approval-required" | "full-access" }; | |
| 563 | + await coreRuntime.dispatch({ | |
| 564 | + id: crypto.randomUUID(), | |
| 565 | + type: "runtime.setMode", | |
| 566 | + issuedAt: requestNow, | |
| 567 | + payload: { mode: params.mode }, | |
| 568 | + }); | |
| 569 | + return coreRuntime.state(); | |
| 570 | + } | |
| 571 | + | |
| 441 | 572 | default: |
| 442 | 573 | throw new Error(`Unknown method: ${request.method}`); |
| 443 | 574 | } |
| @@ -452,7 +583,26 @@ export function createServer(options: ServerOptions) { · 8 unmodified lines | ||
| 452 | 583 | httpServer.once("error", onError); |
| 453 | 584 | const onListening = () => { |
| 454 | 585 | httpServer.off("error", onError); |
| 455 | − resolve(); | |
| 586 | + void (async () => { | |
| 587 | + try { | |
| 588 | + await coreRuntime.start(cwd, projectName); | |
| 589 | + stateStreamStopped = false; | |
| 590 | + stateStreamTask = (async () => { | |
| 591 | + const iterable = await coreRuntime.subscribe(); | |
| 592 | + for await (const update of iterable) { | |
| 593 | + if (stateStreamStopped) break; | |
| 594 | + broadcastPush({ | |
| 595 | + type: "push", | |
| 596 | + channel: WS_CHANNELS.stateUpdated, | |
| 597 | + data: update.state, | |
| 598 | + }); | |
| 599 | + } | |
| 600 | + })(); | |
| 601 | + resolve(); | |
| 602 | + } catch (error) { | |
| 603 | + reject(error as Error); | |
| 604 | + } | |
| 605 | + })(); | |
| 456 | 606 | }; |
| 457 | 607 | if (host) { |
| 458 | 608 | httpServer.listen(port, host, onListening); |
| @@ -463,6 +613,7 @@ export function createServer(options: ServerOptions) { · 4 unmodified lines | ||
| 463 | 613 | } |
| 464 | 614 | |
| 465 | 615 | async function stop(): Promise<void> { |
| 616 | + stateStreamStopped = true; | |
| 466 | 617 | terminalManager.off("event", onTerminalEvent); |
| 467 | 618 | providerManager.stopAll(); |
| 468 | 619 | providerManager.dispose(); |
| @@ -502,6 +653,10 @@ export function createServer(options: ServerOptions) { · 33 unmodified lines | ||
| 502 | 653 | }); |
| 503 | 654 | }); |
| 504 | 655 | |
| 656 | + if (stateStreamTask) { | |
| 657 | + await Promise.race([stateStreamTask, Promise.resolve()]); | |
| 658 | + } | |
| 659 | + await coreRuntime.stop(); | |
| 505 | 660 | await Promise.all([closeWebSocketServer, closeHttpServer]); |
| 506 | 661 | } |
| 507 | 662 | |
| @@ -1074,6 +1074,7 @@ export default function ChatView({ threadId }: ChatViewProps) { · 1073 unmodified lines | ||
| 1074 | 1074 | dispatch({ type: "SET_RUNTIME_MODE", mode }); |
| 1075 | 1075 | scheduleComposerFocus(); |
| 1076 | 1076 | if (!api) return; |
| 1077 | + await api.state.setRuntimeMode({ mode }); | |
| 1077 | 1078 | |
| 1078 | 1079 | const sessionIds = state.threads |
| 1079 | 1080 | .map((t) => t.session) |
| @@ -1524,6 +1525,7 @@ export default function ChatView({ threadId }: ChatViewProps) { · 444 unmodified lines | ||
| 1524 | 1525 | setIsConnecting(true); |
| 1525 | 1526 | try { |
| 1526 | 1527 | const session = await api.providers.startSession({ |
| 1528 | + uiThreadId: activeThread.id, | |
| 1527 | 1529 | provider: "codex", |
| 1528 | 1530 | cwd: cwdOverride ?? activeThread.worktreePath ?? activeProject.cwd, |
| 1529 | 1531 | model: selectedModel || undefined, |
| @@ -1799,6 +1801,7 @@ export default function ChatView({ threadId }: ChatViewProps) { · 269 unmodified lines | ||
| 1799 | 1801 | ).text |
| 1800 | 1802 | : trimmed || undefined; |
| 1801 | 1803 | await api.providers.sendTurn({ |
| 1804 | + uiThreadId: activeThread.id, | |
| 1802 | 1805 | sessionId: sessionInfo.sessionId, |
| 1803 | 1806 | ...(input ? { input } : {}), |
| 1804 | 1807 | ...(turnAttachments.length > 0 ? { attachments: turnAttachments } : {}), |
| @@ -10,7 +10,7 @@ import { DEFAULT_MODEL } from "../model-logic"; · 9 unmodified lines | ||
| 10 | 10 | import { derivePendingApprovals } from "../session-logic"; |
| 11 | 11 | import { useStore } from "../store"; |
| 12 | 12 | import { isChatNewLocalShortcut, isChatNewShortcut } from "../keybindings"; |
| 13 | −import { type Project, type Thread } from "../types"; | |
| 13 | +import { type Thread } from "../types"; | |
| 14 | 14 | import { useNativeApi } from "../hooks/useNativeApi"; |
| 15 | 15 | import { gitRemoveWorktreeMutationOptions } from "../lib/gitReactQuery"; |
| 16 | 16 | import { serverConfigQueryOptions } from "../lib/serverReactQuery"; |
| @@ -140,7 +140,7 @@ export default function Sidebar() { · 123 unmodified lines | ||
| 140 | 140 | }, [state.threads]); |
| 141 | 141 | |
| 142 | 142 | const handleNewThread = useCallback( |
| 143 | − ( | |
| 143 | + async ( | |
| 144 | 144 | projectId: string, |
| 145 | 145 | options?: { |
| 146 | 146 | branch?: string | null; |
| @@ -152,16 +152,21 @@ export default function Sidebar() { · 5 unmodified lines | ||
| 152 | 152 | branch: options?.branch ?? null, |
| 153 | 153 | worktreePath: options?.worktreePath ?? null, |
| 154 | 154 | }); |
| 155 | − dispatch({ | |
| 156 | − type: "ADD_THREAD", | |
| 157 | − thread, | |
| 155 | + await api?.state.createThread({ | |
| 156 | + id: thread.id, | |
| 157 | + projectId: thread.projectId, | |
| 158 | + title: thread.title, | |
| 159 | + model: thread.model, | |
| 160 | + createdAt: thread.createdAt, | |
| 161 | + branch: thread.branch, | |
| 162 | + worktreePath: thread.worktreePath, | |
| 158 | 163 | }); |
| 159 | 164 | void navigate({ |
| 160 | 165 | to: "/$threadId", |
| 161 | 166 | params: { threadId: thread.id }, |
| 162 | 167 | }); |
| 163 | 168 | }, |
| 164 | − [dispatch, navigate, state.projects], | |
| 169 | + [api, navigate, state.projects], | |
| 165 | 170 | ); |
| 166 | 171 | |
| 167 | 172 | const focusMostRecentThreadForProject = useCallback( |
| @@ -192,23 +197,11 @@ export default function Sidebar() { · 24 unmodified lines | ||
| 192 | 197 | try { |
| 193 | 198 | if (isElectron && api) { |
| 194 | 199 | const result = await api.projects.add({ cwd }); |
| 195 | − const project: Project = { | |
| 196 | − id: result.project.id, | |
| 197 | − name: result.project.name, | |
| 198 | − cwd: result.project.cwd, | |
| 199 | − model: DEFAULT_MODEL, | |
| 200 | − expanded: true, | |
| 201 | − scripts: result.project.scripts, | |
| 202 | − }; | |
| 203 | − const existingById = state.projects.find((p) => p.id === project.id); | |
| 204 | − const existingByCwd = state.projects.find((p) => p.cwd === project.cwd); | |
| 205 | − if (!existingById && !existingByCwd) { | |
| 206 | − dispatch({ type: "ADD_PROJECT", project }); | |
| 207 | − } | |
| 208 | − const resolvedProjectId = existingByCwd?.id ?? project.id; | |
| 200 | + const existingByCwd = state.projects.find((p) => p.cwd === result.project.cwd); | |
| 201 | + const resolvedProjectId = existingByCwd?.id ?? result.project.id; | |
| 209 | 202 | |
| 210 | 203 | if (result.created) { |
| 211 | − handleNewThread(resolvedProjectId); | |
| 204 | + await handleNewThread(resolvedProjectId); | |
| 212 | 205 | } else { |
| 213 | 206 | focusMostRecentThreadForProject(resolvedProjectId); |
| 214 | 207 | } |
| @@ -218,18 +211,9 @@ export default function Sidebar() { · 3 unmodified lines | ||
| 218 | 211 | focusMostRecentThreadForProject(existing.id); |
| 219 | 212 | return; |
| 220 | 213 | } |
| 221 | − | |
| 222 | − const name = inferProjectName(cwd); | |
| 223 | − const project: Project = { | |
| 224 | − id: crypto.randomUUID(), | |
| 225 | − name, | |
| 226 | − cwd, | |
| 227 | − model: DEFAULT_MODEL, | |
| 228 | − expanded: true, | |
| 229 | − scripts: [], | |
| 230 | − }; | |
| 231 | − dispatch({ type: "ADD_PROJECT", project }); | |
| 232 | − handleNewThread(project.id); | |
| 214 | + if (!api) return; | |
| 215 | + const result = await api.projects.add({ cwd }); | |
| 216 | + await handleNewThread(result.project.id); | |
| 233 | 217 | } |
| 234 | 218 | } finally { |
| 235 | 219 | setIsAddingProject(false); |
| @@ -321,7 +305,7 @@ export default function Sidebar() { · 85 unmodified lines | ||
| 321 | 305 | |
| 322 | 306 | const shouldNavigateToFallback = routeThreadId === threadId; |
| 323 | 307 | const fallbackThreadId = state.threads.find((entry) => entry.id !== threadId)?.id ?? null; |
| 324 | − dispatch({ type: "DELETE_THREAD", threadId }); | |
| 308 | + await api.state.deleteThread({ id: threadId }); | |
| 325 | 309 | if (shouldNavigateToFallback) { |
| 326 | 310 | if (fallbackThreadId) { |
| 327 | 311 | void navigate({ |
| @@ -411,7 +395,6 @@ export default function Sidebar() { · 83 unmodified lines | ||
| 411 | 395 | } |
| 412 | 396 | } |
| 413 | 397 | |
| 414 | − dispatch({ type: "DELETE_PROJECT", projectId }); | |
| 415 | 398 | }, |
| 416 | 399 | [api, dispatch, state.projects, state.threads], |
| 417 | 400 | ); |
| @@ -472,7 +455,7 @@ export default function Sidebar() { · 54 unmodified lines | ||
| 472 | 455 | return; |
| 473 | 456 | } |
| 474 | 457 | const firstProject = state.projects[0]; |
| 475 | − if (firstProject) handleNewThread(firstProject.id); | |
| 458 | + if (firstProject) void handleNewThread(firstProject.id); | |
| 476 | 459 | }} |
| 477 | 460 | > |
| 478 | 461 | <span className="text-foreground">+</span> |
| @@ -587,7 +570,9 @@ export default function Sidebar() { · 108 unmodified lines | ||
| 587 | 570 | <button |
| 588 | 571 | type="button" |
| 589 | 572 | className="flex w-full items-center gap-1 px-2 py-1 text-[10px] text-muted-foreground/60 transition-colors duration-150 hover:text-muted-foreground/80" |
| 590 | − onClick={() => handleNewThread(project.id)} | |
| 573 | + onClick={() => { | |
| 574 | + void handleNewThread(project.id); | |
| 575 | + }} | |
| 591 | 576 | > |
| 592 | 577 | <span>+</span> New thread |
| 593 | 578 | </button> |
| @@ -1,507 +0,0 @@ | ||
| 1 | −import { describe, expect, it } from "vitest"; | |
| 2 | − | |
| 3 | −import { DEFAULT_MODEL } from "./model-logic"; | |
| 4 | −import { hydratePersistedState, toPersistedState } from "./persistenceSchema"; | |
| 5 | −import { DEFAULT_THREAD_TERMINAL_HEIGHT, DEFAULT_THREAD_TERMINAL_ID } from "./types"; | |
| 6 | −import type { Thread } from "./types"; | |
| 7 | − | |
| 8 | −describe("hydratePersistedState", () => { | |
| 9 | − it("returns null for invalid payloads", () => { | |
| 10 | − expect(hydratePersistedState('{"projects":"bad"}', false)).toBeNull(); | |
| 11 | − expect(hydratePersistedState("not-json", false)).toBeNull(); | |
| 12 | − }); | |
| 13 | − | |
| 14 | − it("migrates the legacy default model to the current default", () => { | |
| 15 | − const payload = JSON.stringify({ | |
| 16 | − projects: [ | |
| 17 | − { | |
| 18 | − id: "p-1", | |
| 19 | − name: "Project", | |
| 20 | − cwd: "/tmp/project", | |
| 21 | − model: "gpt-5.2-codex", | |
| 22 | − expanded: true, | |
| 23 | − scripts: [], | |
| 24 | − }, | |
| 25 | − ], | |
| 26 | − threads: [ | |
| 27 | − { | |
| 28 | − id: "t-1", | |
| 29 | − projectId: "p-1", | |
| 30 | − title: "Thread", | |
| 31 | − model: "gpt-5.2-codex", | |
| 32 | − messages: [ | |
| 33 | − { | |
| 34 | − id: "m-1", | |
| 35 | − role: "assistant", | |
| 36 | − text: "Hello", | |
| 37 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 38 | − streaming: true, | |
| 39 | − }, | |
| 40 | − ], | |
| 41 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 42 | − }, | |
| 43 | − ], | |
| 44 | − activeThreadId: "t-1", | |
| 45 | − }); | |
| 46 | − | |
| 47 | − const hydrated = hydratePersistedState(payload, true); | |
| 48 | − expect(hydrated).not.toBeNull(); | |
| 49 | − expect(hydrated?.projects[0]?.model).toBe(DEFAULT_MODEL); | |
| 50 | − expect(hydrated?.threads[0]?.model).toBe(DEFAULT_MODEL); | |
| 51 | − expect(hydrated?.threads[0]?.codexThreadId).toBeNull(); | |
| 52 | − expect(hydrated?.threads[0]?.terminalOpen).toBe(false); | |
| 53 | − expect(hydrated?.threads[0]?.terminalHeight).toBe(DEFAULT_THREAD_TERMINAL_HEIGHT); | |
| 54 | − expect(hydrated?.threads[0]?.terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID]); | |
| 55 | − expect(hydrated?.threads[0]?.activeTerminalId).toBe(DEFAULT_THREAD_TERMINAL_ID); | |
| 56 | − expect(hydrated?.threads[0]?.terminalGroups).toEqual([ | |
| 57 | − { id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, terminalIds: [DEFAULT_THREAD_TERMINAL_ID] }, | |
| 58 | − ]); | |
| 59 | − expect(hydrated?.threads[0]?.activeTerminalGroupId).toBe(`group-${DEFAULT_THREAD_TERMINAL_ID}`); | |
| 60 | − expect(hydrated?.threads[0]?.messages[0]?.streaming).toBe(false); | |
| 61 | − expect(hydrated?.runtimeMode).toBe("full-access"); | |
| 62 | − }); | |
| 63 | − | |
| 64 | − it("filters unknown project references and repairs active thread", () => { | |
| 65 | − const payload = JSON.stringify({ | |
| 66 | − projects: [ | |
| 67 | − { | |
| 68 | − id: "p-1", | |
| 69 | − name: "Project", | |
| 70 | − cwd: "/tmp/project", | |
| 71 | − model: "gpt-5.3-codex", | |
| 72 | − expanded: false, | |
| 73 | − scripts: [], | |
| 74 | − }, | |
| 75 | − ], | |
| 76 | − threads: [ | |
| 77 | − { | |
| 78 | − id: "t-1", | |
| 79 | − projectId: "p-1", | |
| 80 | − title: "Valid thread", | |
| 81 | − model: "gpt-5.3-codex", | |
| 82 | − messages: [], | |
| 83 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 84 | − }, | |
| 85 | − { | |
| 86 | − id: "t-2", | |
| 87 | − projectId: "p-missing", | |
| 88 | − title: "Dangling thread", | |
| 89 | − model: "gpt-5.3-codex", | |
| 90 | − messages: [], | |
| 91 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 92 | − }, | |
| 93 | − ], | |
| 94 | − activeThreadId: "t-2", | |
| 95 | − }); | |
| 96 | − | |
| 97 | − const hydrated = hydratePersistedState(payload, false); | |
| 98 | − expect(hydrated).not.toBeNull(); | |
| 99 | − expect(hydrated?.threads.map((thread) => thread.id)).toEqual(["t-1"]); | |
| 100 | − expect(hydrated?.threads[0]?.codexThreadId).toBeNull(); | |
| 101 | − expect(hydrated?.threads[0]?.terminalOpen).toBe(false); | |
| 102 | − expect(hydrated?.threads[0]?.terminalHeight).toBe(DEFAULT_THREAD_TERMINAL_HEIGHT); | |
| 103 | − expect(hydrated?.threads[0]?.terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID]); | |
| 104 | − expect(hydrated?.threads[0]?.activeTerminalId).toBe(DEFAULT_THREAD_TERMINAL_ID); | |
| 105 | − expect(hydrated?.threads[0]?.terminalGroups).toEqual([ | |
| 106 | − { id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, terminalIds: [DEFAULT_THREAD_TERMINAL_ID] }, | |
| 107 | − ]); | |
| 108 | − expect(hydrated?.threads[0]?.activeTerminalGroupId).toBe(`group-${DEFAULT_THREAD_TERMINAL_ID}`); | |
| 109 | − expect(hydrated?.runtimeMode).toBe("full-access"); | |
| 110 | − }); | |
| 111 | − | |
| 112 | − it("hydrates runtime mode from v3 payload", () => { | |
| 113 | − const payload = JSON.stringify({ | |
| 114 | − version: 3, | |
| 115 | − runtimeMode: "approval-required", | |
| 116 | − projects: [ | |
| 117 | − { | |
| 118 | − id: "p-1", | |
| 119 | − name: "Project", | |
| 120 | − cwd: "/tmp/project", | |
| 121 | − model: "gpt-5.3-codex", | |
| 122 | − expanded: false, | |
| 123 | − scripts: [], | |
| 124 | − }, | |
| 125 | − ], | |
| 126 | − threads: [], | |
| 127 | − activeThreadId: null, | |
| 128 | − }); | |
| 129 | − | |
| 130 | − const hydrated = hydratePersistedState(payload, false); | |
| 131 | − expect(hydrated?.runtimeMode).toBe("approval-required"); | |
| 132 | − }); | |
| 133 | − | |
| 134 | − it("hydrates terminal fields from legacy v6 payload", () => { | |
| 135 | − const payload = JSON.stringify({ | |
| 136 | − version: 6, | |
| 137 | − runtimeMode: "full-access", | |
| 138 | − projects: [ | |
| 139 | − { | |
| 140 | − id: "p-1", | |
| 141 | − name: "Project", | |
| 142 | − cwd: "/tmp/project", | |
| 143 | − model: "gpt-5.3-codex", | |
| 144 | − expanded: true, | |
| 145 | − scripts: [], | |
| 146 | − }, | |
| 147 | − ], | |
| 148 | − threads: [ | |
| 149 | − { | |
| 150 | − id: "t-1", | |
| 151 | − codexThreadId: null, | |
| 152 | − projectId: "p-1", | |
| 153 | − title: "Thread", | |
| 154 | − model: "gpt-5.3-codex", | |
| 155 | − terminalOpen: true, | |
| 156 | − terminalHeight: 360, | |
| 157 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 158 | − activeTerminalId: "term-2", | |
| 159 | − terminalLayout: "tabs", | |
| 160 | − splitTerminalIds: [], | |
| 161 | − messages: [], | |
| 162 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 163 | − lastVisitedAt: "2026-02-08T10:01:00.000Z", | |
| 164 | − }, | |
| 165 | − ], | |
| 166 | − activeThreadId: "t-1", | |
| 167 | − }); | |
| 168 | − | |
| 169 | − const hydrated = hydratePersistedState(payload, false); | |
| 170 | − expect(hydrated?.threads[0]?.terminalOpen).toBe(true); | |
| 171 | − expect(hydrated?.threads[0]?.terminalHeight).toBe(360); | |
| 172 | − expect(hydrated?.threads[0]?.terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID, "term-2"]); | |
| 173 | − expect(hydrated?.threads[0]?.activeTerminalId).toBe("term-2"); | |
| 174 | − expect(hydrated?.threads[0]?.terminalGroups).toEqual([ | |
| 175 | − { id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, terminalIds: [DEFAULT_THREAD_TERMINAL_ID] }, | |
| 176 | − { id: "group-term-2", terminalIds: ["term-2"] }, | |
| 177 | − ]); | |
| 178 | − expect(hydrated?.threads[0]?.activeTerminalGroupId).toBe("group-term-2"); | |
| 179 | − expect(hydrated?.threads[0]?.lastVisitedAt).toBe("2026-02-08T10:01:00.000Z"); | |
| 180 | − }); | |
| 181 | − | |
| 182 | − it("hydrates legacy split layout into a grouped split", () => { | |
| 183 | − const payload = JSON.stringify({ | |
| 184 | − version: 6, | |
| 185 | − runtimeMode: "full-access", | |
| 186 | − projects: [ | |
| 187 | − { | |
| 188 | − id: "p-1", | |
| 189 | − name: "Project", | |
| 190 | − cwd: "/tmp/project", | |
| 191 | − model: "gpt-5.3-codex", | |
| 192 | − expanded: true, | |
| 193 | − scripts: [], | |
| 194 | − }, | |
| 195 | − ], | |
| 196 | − threads: [ | |
| 197 | − { | |
| 198 | − id: "t-1", | |
| 199 | − codexThreadId: null, | |
| 200 | − projectId: "p-1", | |
| 201 | − title: "Thread", | |
| 202 | − model: "gpt-5.3-codex", | |
| 203 | − terminalOpen: true, | |
| 204 | − terminalHeight: 360, | |
| 205 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2", "term-3"], | |
| 206 | − activeTerminalId: "term-2", | |
| 207 | − terminalLayout: "split", | |
| 208 | − splitTerminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 209 | − messages: [], | |
| 210 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 211 | − }, | |
| 212 | − ], | |
| 213 | − activeThreadId: "t-1", | |
| 214 | − }); | |
| 215 | − | |
| 216 | − const hydrated = hydratePersistedState(payload, false); | |
| 217 | − expect(hydrated?.threads[0]?.terminalGroups).toEqual([ | |
| 218 | − { | |
| 219 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 220 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 221 | − }, | |
| 222 | − { id: "group-term-3", terminalIds: ["term-3"] }, | |
| 223 | − ]); | |
| 224 | − expect(hydrated?.threads[0]?.activeTerminalGroupId).toBe(`group-${DEFAULT_THREAD_TERMINAL_ID}`); | |
| 225 | − }); | |
| 226 | − | |
| 227 | − it("defaults terminalHeight when hydrating v5 payloads", () => { | |
| 228 | − const payload = JSON.stringify({ | |
| 229 | − version: 5, | |
| 230 | − runtimeMode: "full-access", | |
| 231 | − projects: [ | |
| 232 | − { | |
| 233 | − id: "p-1", | |
| 234 | − name: "Project", | |
| 235 | − cwd: "/tmp/project", | |
| 236 | − model: "gpt-5.3-codex", | |
| 237 | − expanded: true, | |
| 238 | − scripts: [], | |
| 239 | − }, | |
| 240 | − ], | |
| 241 | − threads: [ | |
| 242 | − { | |
| 243 | − id: "t-1", | |
| 244 | − codexThreadId: null, | |
| 245 | − projectId: "p-1", | |
| 246 | − title: "Thread", | |
| 247 | − model: "gpt-5.3-codex", | |
| 248 | − terminalOpen: true, | |
| 249 | − messages: [], | |
| 250 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 251 | − }, | |
| 252 | − ], | |
| 253 | − activeThreadId: "t-1", | |
| 254 | − }); | |
| 255 | − | |
| 256 | − const hydrated = hydratePersistedState(payload, false); | |
| 257 | − expect(hydrated?.threads[0]?.terminalHeight).toBe(DEFAULT_THREAD_TERMINAL_HEIGHT); | |
| 258 | − expect(hydrated?.threads[0]?.terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID]); | |
| 259 | − expect(hydrated?.threads[0]?.activeTerminalId).toBe(DEFAULT_THREAD_TERMINAL_ID); | |
| 260 | − expect(hydrated?.threads[0]?.terminalGroups).toEqual([ | |
| 261 | − { id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, terminalIds: [DEFAULT_THREAD_TERMINAL_ID] }, | |
| 262 | − ]); | |
| 263 | − expect(hydrated?.threads[0]?.activeTerminalGroupId).toBe(`group-${DEFAULT_THREAD_TERMINAL_ID}`); | |
| 264 | − }); | |
| 265 | − | |
| 266 | − it("hydrates persisted turn diff summaries as metadata-only entries", () => { | |
| 267 | − const payload = JSON.stringify({ | |
| 268 | − version: 7, | |
| 269 | − runtimeMode: "full-access", | |
| 270 | − projects: [ | |
| 271 | − { | |
| 272 | − id: "p-1", | |
| 273 | − name: "Project", | |
| 274 | − cwd: "/tmp/project", | |
| 275 | − model: "gpt-5.3-codex", | |
| 276 | − expanded: true, | |
| 277 | − }, | |
| 278 | − ], | |
| 279 | − threads: [ | |
| 280 | − { | |
| 281 | − id: "t-1", | |
| 282 | − codexThreadId: "thr_1", | |
| 283 | − projectId: "p-1", | |
| 284 | − title: "Thread", | |
| 285 | − model: "gpt-5.3-codex", | |
| 286 | − messages: [], | |
| 287 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 288 | − turnDiffSummaries: [ | |
| 289 | − { | |
| 290 | − turnId: "turn-1", | |
| 291 | − completedAt: "2026-02-08T10:05:00.000Z", | |
| 292 | − checkpointTurnCount: 1, | |
| 293 | − files: [ | |
| 294 | − { | |
| 295 | − path: "src/app.ts", | |
| 296 | − kind: "modified", | |
| 297 | − additions: 3, | |
| 298 | − deletions: 1, | |
| 299 | − }, | |
| 300 | − ], | |
| 301 | − }, | |
| 302 | − ], | |
| 303 | − }, | |
| 304 | − ], | |
| 305 | − activeThreadId: "t-1", | |
| 306 | − }); | |
| 307 | − | |
| 308 | − const hydrated = hydratePersistedState(payload, false); | |
| 309 | − expect(hydrated?.threads[0]?.turnDiffSummaries).toEqual([ | |
| 310 | − { | |
| 311 | − turnId: "turn-1", | |
| 312 | − completedAt: "2026-02-08T10:05:00.000Z", | |
| 313 | − checkpointTurnCount: 1, | |
| 314 | − files: [ | |
| 315 | − { | |
| 316 | − path: "src/app.ts", | |
| 317 | − kind: "modified", | |
| 318 | − additions: 3, | |
| 319 | − deletions: 1, | |
| 320 | − }, | |
| 321 | − ], | |
| 322 | − }, | |
| 323 | − ]); | |
| 324 | − }); | |
| 325 | − | |
| 326 | − it("drops malformed persisted turn diff summaries instead of rejecting the whole snapshot", () => { | |
| 327 | − const payload = JSON.stringify({ | |
| 328 | − version: 7, | |
| 329 | − runtimeMode: "full-access", | |
| 330 | − projects: [ | |
| 331 | − { | |
| 332 | − id: "p-1", | |
| 333 | − name: "Project", | |
| 334 | − cwd: "/tmp/project", | |
| 335 | − model: "gpt-5.3-codex", | |
| 336 | − expanded: true, | |
| 337 | − }, | |
| 338 | − ], | |
| 339 | − threads: [ | |
| 340 | − { | |
| 341 | − id: "t-1", | |
| 342 | − codexThreadId: "thr_1", | |
| 343 | − projectId: "p-1", | |
| 344 | − title: "Thread", | |
| 345 | − model: "gpt-5.3-codex", | |
| 346 | − messages: [], | |
| 347 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 348 | − turnDiffSummaries: [ | |
| 349 | − { | |
| 350 | − turnId: "turn-1", | |
| 351 | − completedAt: "2026-02-08T10:05:00.000Z", | |
| 352 | − files: [{ path: 123 }], | |
| 353 | − }, | |
| 354 | − ], | |
| 355 | − }, | |
| 356 | − ], | |
| 357 | − activeThreadId: "t-1", | |
| 358 | − }); | |
| 359 | − | |
| 360 | − const hydrated = hydratePersistedState(payload, false); | |
| 361 | − expect(hydrated).not.toBeNull(); | |
| 362 | − expect(hydrated?.threads[0]?.id).toBe("t-1"); | |
| 363 | − expect(hydrated?.threads[0]?.turnDiffSummaries).toEqual([]); | |
| 364 | − }); | |
| 365 | −}); | |
| 366 | − | |
| 367 | −describe("toPersistedState", () => { | |
| 368 | − it("writes v7 payload and strips non-persisted thread fields", () => { | |
| 369 | − const thread: Thread = { | |
| 370 | − id: "t-1", | |
| 371 | − codexThreadId: "thr_1", | |
| 372 | − projectId: "p-1", | |
| 373 | − title: "Thread", | |
| 374 | − model: "gpt-5.3-codex", | |
| 375 | − terminalOpen: true, | |
| 376 | − terminalHeight: 320, | |
| 377 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 378 | − runningTerminalIds: [], | |
| 379 | − activeTerminalId: "term-2", | |
| 380 | − terminalGroups: [ | |
| 381 | − { id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, terminalIds: [DEFAULT_THREAD_TERMINAL_ID] }, | |
| 382 | − { id: "group-term-2", terminalIds: ["term-2"] }, | |
| 383 | − ], | |
| 384 | − activeTerminalGroupId: "group-term-2", | |
| 385 | − session: null, | |
| 386 | − messages: [ | |
| 387 | − { | |
| 388 | − id: "m-1", | |
| 389 | − role: "user", | |
| 390 | − text: "Hi", | |
| 391 | − attachments: [ | |
| 392 | − { | |
| 393 | − type: "image", | |
| 394 | − id: "img-1", | |
| 395 | − name: "diagram.png", | |
| 396 | − mimeType: "image/png", | |
| 397 | − sizeBytes: 4_096, | |
| 398 | − previewUrl: "blob:preview-1", | |
| 399 | − }, | |
| 400 | − ], | |
| 401 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 402 | − streaming: false, | |
| 403 | − }, | |
| 404 | − ], | |
| 405 | − events: [], | |
| 406 | − error: "boom", | |
| 407 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 408 | − lastVisitedAt: "2026-02-08T10:02:00.000Z", | |
| 409 | − branch: null, | |
| 410 | − worktreePath: null, | |
| 411 | − turnDiffSummaries: [ | |
| 412 | − { | |
| 413 | − turnId: "turn-1", | |
| 414 | − completedAt: "2026-02-08T10:05:00.000Z", | |
| 415 | − status: "completed", | |
| 416 | − checkpointTurnCount: 1, | |
| 417 | − files: [ | |
| 418 | − { | |
| 419 | − path: "src/app.ts", | |
| 420 | − kind: "modified", | |
| 421 | − additions: 3, | |
| 422 | − deletions: 1, | |
| 423 | − }, | |
| 424 | − ], | |
| 425 | − }, | |
| 426 | − ], | |
| 427 | − }; | |
| 428 | − | |
| 429 | − const persisted = toPersistedState({ | |
| 430 | − projects: [ | |
| 431 | − { | |
| 432 | − id: "p-1", | |
| 433 | − name: "Project", | |
| 434 | − cwd: "/tmp/project", | |
| 435 | − model: "gpt-5.3-codex", | |
| 436 | − expanded: true, | |
| 437 | − scripts: [], | |
| 438 | − }, | |
| 439 | − ], | |
| 440 | − threads: [thread], | |
| 441 | − runtimeMode: "full-access", | |
| 442 | − }); | |
| 443 | − | |
| 444 | − expect(persisted.version).toBe(7); | |
| 445 | − expect(persisted.runtimeMode).toBe("full-access"); | |
| 446 | − expect(persisted.threads[0]).toEqual({ | |
| 447 | − id: "t-1", | |
| 448 | − codexThreadId: "thr_1", | |
| 449 | − projectId: "p-1", | |
| 450 | − title: "Thread", | |
| 451 | − model: "gpt-5.3-codex", | |
| 452 | − terminalOpen: true, | |
| 453 | − terminalHeight: 320, | |
| 454 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 455 | − activeTerminalId: "term-2", | |
| 456 | − terminalGroups: [ | |
| 457 | − { id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, terminalIds: [DEFAULT_THREAD_TERMINAL_ID] }, | |
| 458 | − { id: "group-term-2", terminalIds: ["term-2"] }, | |
| 459 | − ], | |
| 460 | − activeTerminalGroupId: "group-term-2", | |
| 461 | − messages: [ | |
| 462 | − { | |
| 463 | − id: "m-1", | |
| 464 | − role: "user", | |
| 465 | − text: "Hi", | |
| 466 | − attachments: [ | |
| 467 | − { | |
| 468 | − type: "image", | |
| 469 | − id: "img-1", | |
| 470 | − name: "diagram.png", | |
| 471 | − mimeType: "image/png", | |
| 472 | − sizeBytes: 4_096, | |
| 473 | − }, | |
| 474 | − ], | |
| 475 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 476 | − streaming: false, | |
| 477 | − }, | |
| 478 | − ], | |
| 479 | − createdAt: thread.createdAt, | |
| 480 | − lastVisitedAt: thread.lastVisitedAt, | |
| 481 | − branch: null, | |
| 482 | − worktreePath: null, | |
| 483 | − turnDiffSummaries: [ | |
| 484 | − { | |
| 485 | − turnId: "turn-1", | |
| 486 | − completedAt: "2026-02-08T10:05:00.000Z", | |
| 487 | − status: "completed", | |
| 488 | − checkpointTurnCount: 1, | |
| 489 | − files: [ | |
| 490 | − { | |
| 491 | − path: "src/app.ts", | |
| 492 | − kind: "modified", | |
| 493 | − additions: 3, | |
| 494 | − deletions: 1, | |
| 495 | − }, | |
| 496 | − ], | |
| 497 | − }, | |
| 498 | − ], | |
| 499 | − }); | |
| 500 | − const persistedThread = persisted.threads[0]; | |
| 501 | − expect(persistedThread).toBeDefined(); | |
| 502 | − if (!persistedThread) return; | |
| 503 | − | |
| 504 | − expect("error" in persistedThread).toBe(false); | |
| 505 | − expect("session" in persistedThread).toBe(false); | |
| 506 | − }); | |
| 507 | −}); | |
| @@ -1,399 +0,0 @@ | ||
| 1 | −import { z } from "zod"; | |
| 2 | −import { projectScriptSchema } from "@t3tools/contracts"; | |
| 3 | − | |
| 4 | −import { DEFAULT_MODEL, resolveModelSlug } from "./model-logic"; | |
| 5 | −import { | |
| 6 | − DEFAULT_THREAD_TERMINAL_HEIGHT, | |
| 7 | − DEFAULT_THREAD_TERMINAL_ID, | |
| 8 | − DEFAULT_RUNTIME_MODE, | |
| 9 | − type Project, | |
| 10 | − type RuntimeMode, | |
| 11 | − type Thread, | |
| 12 | − type ThreadTerminalGroup, | |
| 13 | −} from "./types"; | |
| 14 | − | |
| 15 | −const LEGACY_DEFAULT_MODEL = "gpt-5.2-codex"; | |
| 16 | − | |
| 17 | −const persistedProjectSchema = z.object({ | |
| 18 | − id: z.string().min(1), | |
| 19 | − name: z.string().min(1), | |
| 20 | − cwd: z.string().min(1), | |
| 21 | − model: z.string().min(1), | |
| 22 | − expanded: z.boolean(), | |
| 23 | − scripts: z.array(projectScriptSchema).default([]), | |
| 24 | −}); | |
| 25 | − | |
| 26 | −const persistedMessageSchema = z.object({ | |
| 27 | − id: z.string().min(1), | |
| 28 | − role: z.enum(["user", "assistant"]), | |
| 29 | − text: z.string(), | |
| 30 | − attachments: z | |
| 31 | − .array( | |
| 32 | − z.object({ | |
| 33 | − type: z.literal("image"), | |
| 34 | − id: z.string().min(1), | |
| 35 | − name: z.string().min(1), | |
| 36 | − mimeType: z.string().min(1), | |
| 37 | − sizeBytes: z.number().int().min(1), | |
| 38 | − }), | |
| 39 | − ) | |
| 40 | − .optional(), | |
| 41 | − createdAt: z.string().min(1), | |
| 42 | − streaming: z.boolean(), | |
| 43 | −}); | |
| 44 | − | |
| 45 | −const persistedTerminalGroupSchema = z.object({ | |
| 46 | − id: z.string().trim().min(1), | |
| 47 | − terminalIds: z.array(z.string().trim().min(1)), | |
| 48 | −}); | |
| 49 | − | |
| 50 | −const persistedTurnDiffFileChangeSchema = z.object({ | |
| 51 | − path: z.string().min(1), | |
| 52 | − kind: z.string().min(1).optional(), | |
| 53 | − additions: z.number().int().min(0).optional(), | |
| 54 | − deletions: z.number().int().min(0).optional(), | |
| 55 | −}); | |
| 56 | − | |
| 57 | −const persistedTurnDiffSummarySchema = z.object({ | |
| 58 | − turnId: z.string().min(1), | |
| 59 | − completedAt: z.string().min(1), | |
| 60 | − status: z.string().min(1).optional(), | |
| 61 | − files: z.array(persistedTurnDiffFileChangeSchema), | |
| 62 | − assistantMessageId: z.string().min(1).optional(), | |
| 63 | − checkpointTurnCount: z.number().int().min(0).optional(), | |
| 64 | −}); | |
| 65 | − | |
| 66 | −const persistedThreadSchema = z.object({ | |
| 67 | − id: z.string().min(1), | |
| 68 | − codexThreadId: z.string().min(1).nullable().default(null), | |
| 69 | − projectId: z.string().min(1), | |
| 70 | − title: z.string().min(1), | |
| 71 | − model: z.string().min(1), | |
| 72 | − terminalOpen: z.boolean().default(false), | |
| 73 | − terminalHeight: z.number().int().min(120).max(4_096).default(DEFAULT_THREAD_TERMINAL_HEIGHT), | |
| 74 | − terminalIds: z.array(z.string().trim().min(1)).default([DEFAULT_THREAD_TERMINAL_ID]), | |
| 75 | − activeTerminalId: z.string().trim().min(1).default(DEFAULT_THREAD_TERMINAL_ID), | |
| 76 | − terminalGroups: z.array(persistedTerminalGroupSchema).default([]), | |
| 77 | − activeTerminalGroupId: z.string().trim().min(1).optional(), | |
| 78 | − // Legacy v6 and older fields retained for migration. | |
| 79 | − terminalLayout: z.enum(["single", "split", "tabs"]).optional(), | |
| 80 | − splitTerminalIds: z.array(z.string().trim().min(1)).optional(), | |
| 81 | − messages: z.array(persistedMessageSchema), | |
| 82 | − createdAt: z.string().min(1), | |
| 83 | − lastVisitedAt: z.string().min(1).optional(), | |
| 84 | − branch: z.string().min(1).nullable().optional(), | |
| 85 | − worktreePath: z.string().min(1).nullable().optional(), | |
| 86 | − turnDiffSummaries: z.array(persistedTurnDiffSummarySchema).catch([]).default([]), | |
| 87 | −}); | |
| 88 | − | |
| 89 | −const persistedStateBodySchema = z.object({ | |
| 90 | − projects: z.array(persistedProjectSchema), | |
| 91 | − threads: z.array(persistedThreadSchema), | |
| 92 | − activeThreadId: z.string().min(1).nullable().optional(), | |
| 93 | −}); | |
| 94 | − | |
| 95 | −const runtimeModeSchema = z.enum(["approval-required", "full-access"]); | |
| 96 | − | |
| 97 | −export const persistedStateV1Schema = persistedStateBodySchema.extend({ | |
| 98 | − version: z.literal(1).optional(), | |
| 99 | −}); | |
| 100 | − | |
| 101 | −export const persistedStateV2Schema = persistedStateBodySchema.extend({ | |
| 102 | − version: z.literal(2).optional(), | |
| 103 | −}); | |
| 104 | − | |
| 105 | −export const persistedStateV3Schema = persistedStateBodySchema.extend({ | |
| 106 | − runtimeMode: runtimeModeSchema.default(DEFAULT_RUNTIME_MODE), | |
| 107 | − version: z.literal(3).optional(), | |
| 108 | −}); | |
| 109 | − | |
| 110 | −export const persistedStateV4Schema = persistedStateBodySchema.extend({ | |
| 111 | − runtimeMode: runtimeModeSchema.default(DEFAULT_RUNTIME_MODE), | |
| 112 | − version: z.literal(4).optional(), | |
| 113 | −}); | |
| 114 | − | |
| 115 | −export const persistedStateV6Schema = persistedStateBodySchema.extend({ | |
| 116 | − runtimeMode: runtimeModeSchema.default(DEFAULT_RUNTIME_MODE), | |
| 117 | − version: z.literal(6).optional(), | |
| 118 | −}); | |
| 119 | − | |
| 120 | −export const persistedStateV7Schema = persistedStateBodySchema.extend({ | |
| 121 | − runtimeMode: runtimeModeSchema.default(DEFAULT_RUNTIME_MODE), | |
| 122 | − version: z.literal(7).optional(), | |
| 123 | −}); | |
| 124 | − | |
| 125 | −export const persistedStateV5Schema = persistedStateBodySchema.extend({ | |
| 126 | − runtimeMode: runtimeModeSchema.default(DEFAULT_RUNTIME_MODE), | |
| 127 | − version: z.literal(5).optional(), | |
| 128 | −}); | |
| 129 | − | |
| 130 | −const persistedStateSchema = z.union([ | |
| 131 | − persistedStateV7Schema, | |
| 132 | − persistedStateV6Schema, | |
| 133 | − persistedStateV5Schema, | |
| 134 | − persistedStateV4Schema, | |
| 135 | − persistedStateV3Schema, | |
| 136 | − persistedStateV2Schema, | |
| 137 | − persistedStateV1Schema, | |
| 138 | −]); | |
| 139 | − | |
| 140 | −export interface PersistedStoreSnapshot { | |
| 141 | − projects: Project[]; | |
| 142 | − threads: Thread[]; | |
| 143 | − runtimeMode: RuntimeMode; | |
| 144 | −} | |
| 145 | − | |
| 146 | −function maybeMigrateLegacyModel(model: string, isLegacyPayload: boolean): string { | |
| 147 | − if (!isLegacyPayload) { | |
| 148 | − return model; | |
| 149 | − } | |
| 150 | − | |
| 151 | − return model === LEGACY_DEFAULT_MODEL ? DEFAULT_MODEL : model; | |
| 152 | −} | |
| 153 | − | |
| 154 | −function hydrateProject( | |
| 155 | − project: z.infer<typeof persistedProjectSchema>, | |
| 156 | − isLegacyPayload: boolean, | |
| 157 | −): Project { | |
| 158 | − return { | |
| 159 | − ...project, | |
| 160 | − model: resolveModelSlug(maybeMigrateLegacyModel(project.model, isLegacyPayload)), | |
| 161 | − scripts: project.scripts, | |
| 162 | − }; | |
| 163 | −} | |
| 164 | − | |
| 165 | −function hydrateThread( | |
| 166 | − thread: z.infer<typeof persistedThreadSchema>, | |
| 167 | − isLegacyPayload: boolean, | |
| 168 | −): Thread { | |
| 169 | − const terminalIds = [ | |
| 170 | − ...new Set(thread.terminalIds.map((id) => id.trim()).filter((id) => id.length > 0)), | |
| 171 | − ]; | |
| 172 | − const safeTerminalIds = terminalIds.length > 0 ? terminalIds : [DEFAULT_THREAD_TERMINAL_ID]; | |
| 173 | − const activeTerminalId = safeTerminalIds.includes(thread.activeTerminalId) | |
| 174 | − ? thread.activeTerminalId | |
| 175 | − : (safeTerminalIds[0] ?? DEFAULT_THREAD_TERMINAL_ID); | |
| 176 | − const safeTerminalIdSet = new Set(safeTerminalIds); | |
| 177 | − const assignedTerminalIds = new Set<string>(); | |
| 178 | − const usedGroupIds = new Set<string>(); | |
| 179 | − const normalizedGroups: ThreadTerminalGroup[] = []; | |
| 180 | − const assignUniqueGroupId = (groupId: string): string => { | |
| 181 | − if (!usedGroupIds.has(groupId)) { | |
| 182 | − usedGroupIds.add(groupId); | |
| 183 | − return groupId; | |
| 184 | − } | |
| 185 | − let suffix = 2; | |
| 186 | − while (usedGroupIds.has(`${groupId}-${suffix}`)) { | |
| 187 | − suffix += 1; | |
| 188 | − } | |
| 189 | − const uniqueGroupId = `${groupId}-${suffix}`; | |
| 190 | − usedGroupIds.add(uniqueGroupId); | |
| 191 | − return uniqueGroupId; | |
| 192 | − }; | |
| 193 | − | |
| 194 | − for (const terminalGroup of thread.terminalGroups) { | |
| 195 | − const nextTerminalIds = [ | |
| 196 | − ...new Set(terminalGroup.terminalIds.map((id) => id.trim()).filter((id) => id.length > 0)), | |
| 197 | − ].filter((terminalId) => { | |
| 198 | − if (!safeTerminalIdSet.has(terminalId)) return false; | |
| 199 | − if (assignedTerminalIds.has(terminalId)) return false; | |
| 200 | − return true; | |
| 201 | − }); | |
| 202 | − if (nextTerminalIds.length === 0) continue; | |
| 203 | − for (const terminalId of nextTerminalIds) { | |
| 204 | − assignedTerminalIds.add(terminalId); | |
| 205 | − } | |
| 206 | − const baseGroupId = | |
| 207 | − terminalGroup.id.trim().length > 0 | |
| 208 | − ? terminalGroup.id.trim() | |
| 209 | − : `group-${nextTerminalIds[0] ?? DEFAULT_THREAD_TERMINAL_ID}`; | |
| 210 | − normalizedGroups.push({ | |
| 211 | − id: assignUniqueGroupId(baseGroupId), | |
| 212 | − terminalIds: nextTerminalIds, | |
| 213 | − }); | |
| 214 | − } | |
| 215 | − | |
| 216 | − if (normalizedGroups.length === 0 && thread.terminalLayout === "split") { | |
| 217 | − const splitTerminalIds = [ | |
| 218 | − ...new Set( | |
| 219 | − (thread.splitTerminalIds ?? []).map((id) => id.trim()).filter((id) => id.length > 0), | |
| 220 | − ), | |
| 221 | − ].filter((terminalId) => safeTerminalIdSet.has(terminalId)); | |
| 222 | − if (splitTerminalIds.length >= 2) { | |
| 223 | − const splitGroupTerminalIds = splitTerminalIds.slice(0, 2); | |
| 224 | − for (const terminalId of splitGroupTerminalIds) { | |
| 225 | − assignedTerminalIds.add(terminalId); | |
| 226 | − } | |
| 227 | − normalizedGroups.push({ | |
| 228 | − id: assignUniqueGroupId(`group-${splitGroupTerminalIds[0] ?? DEFAULT_THREAD_TERMINAL_ID}`), | |
| 229 | − terminalIds: splitGroupTerminalIds, | |
| 230 | − }); | |
| 231 | − } | |
| 232 | − } | |
| 233 | − | |
| 234 | − for (const terminalId of safeTerminalIds) { | |
| 235 | − if (assignedTerminalIds.has(terminalId)) continue; | |
| 236 | − normalizedGroups.push({ | |
| 237 | − id: assignUniqueGroupId(`group-${terminalId}`), | |
| 238 | − terminalIds: [terminalId], | |
| 239 | − }); | |
| 240 | − } | |
| 241 | − | |
| 242 | − const activeGroupIndexFromId = normalizedGroups.findIndex( | |
| 243 | − (terminalGroup) => terminalGroup.id === thread.activeTerminalGroupId, | |
| 244 | − ); | |
| 245 | − const activeGroupIndexFromTerminal = normalizedGroups.findIndex((terminalGroup) => | |
| 246 | − terminalGroup.terminalIds.includes(activeTerminalId), | |
| 247 | − ); | |
| 248 | − const activeGroupIndex = | |
| 249 | − activeGroupIndexFromId >= 0 | |
| 250 | − ? activeGroupIndexFromId | |
| 251 | − : activeGroupIndexFromTerminal >= 0 | |
| 252 | − ? activeGroupIndexFromTerminal | |
| 253 | − : 0; | |
| 254 | − const activeTerminalGroupId = | |
| 255 | − normalizedGroups[activeGroupIndex]?.id ?? | |
| 256 | − normalizedGroups[0]?.id ?? | |
| 257 | − `group-${DEFAULT_THREAD_TERMINAL_ID}`; | |
| 258 | − | |
| 259 | − return { | |
| 260 | − id: thread.id, | |
| 261 | − codexThreadId: thread.codexThreadId, | |
| 262 | − projectId: thread.projectId, | |
| 263 | − title: thread.title, | |
| 264 | − model: resolveModelSlug(maybeMigrateLegacyModel(thread.model, isLegacyPayload)), | |
| 265 | − terminalOpen: thread.terminalOpen ?? false, | |
| 266 | − terminalHeight: thread.terminalHeight ?? DEFAULT_THREAD_TERMINAL_HEIGHT, | |
| 267 | − terminalIds: safeTerminalIds, | |
| 268 | − runningTerminalIds: [], | |
| 269 | − activeTerminalId, | |
| 270 | − terminalGroups: normalizedGroups, | |
| 271 | − activeTerminalGroupId, | |
| 272 | − session: null, | |
| 273 | − messages: thread.messages.map((message) => { | |
| 274 | − const hydratedAttachments = message.attachments?.map((attachment) => ({ ...attachment })); | |
| 275 | − return { | |
| 276 | − id: message.id, | |
| 277 | − role: message.role, | |
| 278 | − text: message.text, | |
| 279 | − ...(hydratedAttachments && hydratedAttachments.length > 0 | |
| 280 | − ? { attachments: hydratedAttachments } | |
| 281 | − : {}), | |
| 282 | − createdAt: message.createdAt, | |
| 283 | − streaming: false, | |
| 284 | − }; | |
| 285 | − }), | |
| 286 | − events: [], | |
| 287 | − error: null, | |
| 288 | − createdAt: thread.createdAt, | |
| 289 | − lastVisitedAt: thread.lastVisitedAt, | |
| 290 | − branch: thread.branch ?? null, | |
| 291 | − worktreePath: thread.worktreePath ?? null, | |
| 292 | − turnDiffSummaries: thread.turnDiffSummaries.map((summary) => ({ | |
| 293 | − turnId: summary.turnId, | |
| 294 | − completedAt: summary.completedAt, | |
| 295 | − ...(summary.status ? { status: summary.status } : {}), | |
| 296 | − files: summary.files.map((file) => ({ | |
| 297 | − path: file.path, | |
| 298 | − ...(file.kind ? { kind: file.kind } : {}), | |
| 299 | − ...(typeof file.additions === "number" ? { additions: file.additions } : {}), | |
| 300 | − ...(typeof file.deletions === "number" ? { deletions: file.deletions } : {}), | |
| 301 | − })), | |
| 302 | − ...(summary.assistantMessageId ? { assistantMessageId: summary.assistantMessageId } : {}), | |
| 303 | − ...(typeof summary.checkpointTurnCount === "number" | |
| 304 | − ? { checkpointTurnCount: summary.checkpointTurnCount } | |
| 305 | − : {}), | |
| 306 | − })), | |
| 307 | − }; | |
| 308 | −} | |
| 309 | − | |
| 310 | −export function hydratePersistedState( | |
| 311 | − raw: string, | |
| 312 | − isLegacyPayload: boolean, | |
| 313 | −): PersistedStoreSnapshot | null { | |
| 314 | − let parsedJson: unknown; | |
| 315 | − try { | |
| 316 | − parsedJson = JSON.parse(raw); | |
| 317 | − } catch { | |
| 318 | − return null; | |
| 319 | − } | |
| 320 | − | |
| 321 | − const parsedState = persistedStateSchema.safeParse(parsedJson); | |
| 322 | − if (!parsedState.success) { | |
| 323 | − return null; | |
| 324 | − } | |
| 325 | − | |
| 326 | − const projects = parsedState.data.projects.map((project) => | |
| 327 | − hydrateProject(project, isLegacyPayload), | |
| 328 | − ); | |
| 329 | − const projectIds = new Set(projects.map((project) => project.id)); | |
| 330 | − const threads = parsedState.data.threads | |
| 331 | − .map((thread) => hydrateThread(thread, isLegacyPayload)) | |
| 332 | − .filter((thread) => projectIds.has(thread.projectId)); | |
| 333 | − return { | |
| 334 | − projects, | |
| 335 | − threads, | |
| 336 | − runtimeMode: | |
| 337 | − "runtimeMode" in parsedState.data ? parsedState.data.runtimeMode : DEFAULT_RUNTIME_MODE, | |
| 338 | − }; | |
| 339 | −} | |
| 340 | − | |
| 341 | −export function toPersistedState( | |
| 342 | − state: PersistedStoreSnapshot, | |
| 343 | −): z.infer<typeof persistedStateV7Schema> { | |
| 344 | − return { | |
| 345 | − version: 7, | |
| 346 | − projects: state.projects, | |
| 347 | − threads: state.threads.map((thread) => ({ | |
| 348 | − id: thread.id, | |
| 349 | − codexThreadId: thread.codexThreadId, | |
| 350 | − projectId: thread.projectId, | |
| 351 | − title: thread.title, | |
| 352 | − model: thread.model, | |
| 353 | − terminalOpen: thread.terminalOpen, | |
| 354 | − terminalHeight: thread.terminalHeight, | |
| 355 | − terminalIds: thread.terminalIds, | |
| 356 | − activeTerminalId: thread.activeTerminalId, | |
| 357 | − terminalGroups: thread.terminalGroups, | |
| 358 | − activeTerminalGroupId: thread.activeTerminalGroupId, | |
| 359 | − messages: thread.messages.map((message) => ({ | |
| 360 | − id: message.id, | |
| 361 | − role: message.role, | |
| 362 | − text: message.text, | |
| 363 | − ...(message.attachments && message.attachments.length > 0 | |
| 364 | − ? { | |
| 365 | − attachments: message.attachments.map((attachment) => ({ | |
| 366 | − type: attachment.type, | |
| 367 | − id: attachment.id, | |
| 368 | − name: attachment.name, | |
| 369 | − mimeType: attachment.mimeType, | |
| 370 | − sizeBytes: attachment.sizeBytes, | |
| 371 | − })), | |
| 372 | − } | |
| 373 | − : {}), | |
| 374 | − createdAt: message.createdAt, | |
| 375 | − streaming: message.streaming, | |
| 376 | − })), | |
| 377 | − createdAt: thread.createdAt, | |
| 378 | − ...(thread.lastVisitedAt ? { lastVisitedAt: thread.lastVisitedAt } : {}), | |
| 379 | − branch: thread.branch, | |
| 380 | − worktreePath: thread.worktreePath, | |
| 381 | − turnDiffSummaries: thread.turnDiffSummaries.map((summary) => ({ | |
| 382 | − turnId: summary.turnId, | |
| 383 | − completedAt: summary.completedAt, | |
| 384 | − ...(summary.status ? { status: summary.status } : {}), | |
| 385 | − files: summary.files.map((file) => ({ | |
| 386 | − path: file.path, | |
| 387 | − ...(file.kind ? { kind: file.kind } : {}), | |
| 388 | − ...(typeof file.additions === "number" ? { additions: file.additions } : {}), | |
| 389 | − ...(typeof file.deletions === "number" ? { deletions: file.deletions } : {}), | |
| 390 | − })), | |
| 391 | − ...(summary.assistantMessageId ? { assistantMessageId: summary.assistantMessageId } : {}), | |
| 392 | − ...(typeof summary.checkpointTurnCount === "number" | |
| 393 | − ? { checkpointTurnCount: summary.checkpointTurnCount } | |
| 394 | − : {}), | |
| 395 | − })), | |
| 396 | − })), | |
| 397 | − runtimeMode: state.runtimeMode, | |
| 398 | − }; | |
| 399 | −} | |
| @@ -4,18 +4,16 @@ import { · 3 unmodified lines | ||
| 4 | 4 | type ErrorComponentProps, |
| 5 | 5 | useParams, |
| 6 | 6 | } from "@tanstack/react-router"; |
| 7 | −import { useEffect, useRef } from "react"; | |
| 8 | −import { QueryClient, useQueryClient } from "@tanstack/react-query"; | |
| 7 | +import { useEffect } from "react"; | |
| 8 | +import { QueryClient } from "@tanstack/react-query"; | |
| 9 | 9 | |
| 10 | 10 | import { APP_DISPLAY_NAME } from "../branding"; |
| 11 | 11 | import { Button } from "../components/ui/button"; |
| 12 | 12 | import { AnchoredToastProvider, ToastProvider } from "../components/ui/toast"; |
| 13 | 13 | import { isElectron } from "../env"; |
| 14 | 14 | import { useNativeApi } from "../hooks/useNativeApi"; |
| 15 | −import { invalidateGitQueries } from "../lib/gitReactQuery"; | |
| 16 | −import { DEFAULT_MODEL } from "../model-logic"; | |
| 17 | −import { useStore } from "../store"; | |
| 18 | −import { onServerWelcome } from "../wsNativeApi"; | |
| 15 | +import { type AppState, useStore } from "../store"; | |
| 16 | +import { onServerStateUpdate, onServerWelcome } from "../wsNativeApi"; | |
| 19 | 17 | |
| 20 | 18 | export const Route = createRootRouteWithContext<{ |
| 21 | 19 | queryClient: QueryClient; |
| @@ -125,8 +123,6 @@ function errorDetails(error: unknown): string { · 103 unmodified lines | ||
| 125 | 123 | function EventRouter() { |
| 126 | 124 | const api = useNativeApi(); |
| 127 | 125 | const { dispatch } = useStore(); |
| 128 | − const queryClient = useQueryClient(); | |
| 129 | − const activeAssistantItemRef = useRef<string | null>(null); | |
| 130 | 126 | const activeThreadId = useParams({ |
| 131 | 127 | strict: false, |
| 132 | 128 | select: (params) => params.threadId, |
| @@ -134,91 +130,41 @@ function EventRouter() { · 1 unmodified line | ||
| 134 | 130 | |
| 135 | 131 | useEffect(() => { |
| 136 | 132 | if (!api) return; |
| 137 | − return api.providers.onEvent((event) => { | |
| 138 | − if (event.method === "turn/completed") { | |
| 139 | − void invalidateGitQueries(queryClient); | |
| 140 | − } | |
| 141 | − if (event.method === "checkpoint/captured") { | |
| 142 | − const payload = event.payload as { turnCount?: number } | undefined; | |
| 143 | − const turnCount = payload?.turnCount; | |
| 144 | − void queryClient.invalidateQueries({ | |
| 145 | − queryKey: ["providers", "checkpointDiff"] as const, | |
| 146 | − predicate: (query) => { | |
| 147 | − if (typeof turnCount !== "number") return true; | |
| 148 | − return query.queryKey[5] === turnCount; | |
| 149 | − }, | |
| 150 | − }); | |
| 151 | − } | |
| 152 | − if (!activeThreadId) return; | |
| 153 | − dispatch({ | |
| 154 | − type: "APPLY_EVENT", | |
| 155 | − event, | |
| 156 | − activeAssistantItemRef, | |
| 157 | − activeThreadId, | |
| 158 | − }); | |
| 133 | + let mounted = true; | |
| 134 | + void api.state.getSnapshot().then((snapshot) => { | |
| 135 | + if (!mounted) return; | |
| 136 | + dispatch({ type: "SET_SERVER_STATE", state: snapshot as AppState }); | |
| 159 | 137 | }); |
| 160 | − }, [activeThreadId, api, dispatch, queryClient]); | |
| 138 | + return () => { | |
| 139 | + mounted = false; | |
| 140 | + }; | |
| 141 | + }, [api, dispatch]); | |
| 161 | 142 | |
| 162 | 143 | useEffect(() => { |
| 163 | − if (!activeThreadId) return; | |
| 164 | − dispatch({ | |
| 165 | − type: "MARK_THREAD_VISITED", | |
| 166 | − threadId: activeThreadId, | |
| 167 | − visitedAt: new Date().toISOString(), | |
| 144 | + return onServerStateUpdate((snapshot) => { | |
| 145 | + dispatch({ type: "SET_SERVER_STATE", state: snapshot as AppState }); | |
| 168 | 146 | }); |
| 169 | − }, [activeThreadId, dispatch]); | |
| 147 | + }, [dispatch]); | |
| 170 | 148 | |
| 171 | 149 | useEffect(() => { |
| 150 | + if (!activeThreadId) return; | |
| 151 | + const visitedAt = new Date().toISOString(); | |
| 172 | 152 | if (!api) return; |
| 173 | − return api.terminal.onEvent((event) => { | |
| 174 | − dispatch({ | |
| 175 | − type: "APPLY_TERMINAL_EVENT", | |
| 176 | − event, | |
| 177 | − }); | |
| 178 | − }); | |
| 179 | − }, [api, dispatch]); | |
| 153 | + void api.state.markThreadVisited({ threadId: activeThreadId, visitedAt }); | |
| 154 | + }, [activeThreadId, api]); | |
| 180 | 155 | |
| 181 | 156 | return null; |
| 182 | 157 | } |
| 183 | 158 | |
| 184 | 159 | function AutoProjectBootstrap() { |
| 185 | − const { state, dispatch } = useStore(); | |
| 186 | − const bootstrappedRef = useRef(false); | |
| 160 | + const { dispatch } = useStore(); | |
| 187 | 161 | |
| 188 | 162 | useEffect(() => { |
| 189 | − // Browser mode bootstraps from server welcome. | |
| 190 | − // Electron bootstraps from persisted projects via DesktopProjectBootstrap. | |
| 191 | 163 | if (isElectron) return; |
| 192 | − | |
| 193 | − return onServerWelcome((payload) => { | |
| 194 | − if (bootstrappedRef.current) return; | |
| 195 | − | |
| 196 | − // Don't create duplicate projects for the same cwd | |
| 197 | − const existing = state.projects.find((project) => project.cwd === payload.cwd); | |
| 198 | − if (existing) { | |
| 199 | − bootstrappedRef.current = true; | |
| 200 | − dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true }); | |
| 201 | − return; | |
| 202 | − } | |
| 203 | − | |
| 204 | − bootstrappedRef.current = true; | |
| 205 | − | |
| 206 | − // Create project + thread from server cwd | |
| 207 | − const projectId = crypto.randomUUID(); | |
| 208 | − dispatch({ | |
| 209 | − type: "ADD_PROJECT", | |
| 210 | − project: { | |
| 211 | − id: projectId, | |
| 212 | − name: payload.projectName, | |
| 213 | − cwd: payload.cwd, | |
| 214 | − model: DEFAULT_MODEL, | |
| 215 | − expanded: true, | |
| 216 | − scripts: [], | |
| 217 | − }, | |
| 218 | − }); | |
| 164 | + return onServerWelcome(() => { | |
| 219 | 165 | dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true }); |
| 220 | 166 | }); |
| 221 | − }, [state.projects, dispatch]); | |
| 167 | + }, [dispatch]); | |
| 222 | 168 | |
| 223 | 169 | return null; |
| 224 | 170 | } |
| @@ -226,50 +172,10 @@ function AutoProjectBootstrap() { · 1 unmodified line | ||
| 226 | 172 | function DesktopProjectBootstrap() { |
| 227 | 173 | const api = useNativeApi(); |
| 228 | 174 | const { dispatch } = useStore(); |
| 229 | − const bootstrappedRef = useRef(false); | |
| 230 | 175 | |
| 231 | 176 | useEffect(() => { |
| 232 | − if (!isElectron || !api || bootstrappedRef.current) return; | |
| 233 | − | |
| 234 | − let disposed = false; | |
| 235 | − let retryDelayMs = 500; | |
| 236 | − let retryTimer: ReturnType<typeof setTimeout> | null = null; | |
| 237 | − | |
| 238 | − const attemptBootstrap = async () => { | |
| 239 | − try { | |
| 240 | − const projects = await api.projects.list(); | |
| 241 | − if (disposed) return; | |
| 242 | − dispatch({ | |
| 243 | − type: "SYNC_PROJECTS", | |
| 244 | − projects: projects.map((project) => ({ | |
| 245 | − id: project.id, | |
| 246 | − name: project.name, | |
| 247 | − cwd: project.cwd, | |
| 248 | − model: DEFAULT_MODEL, | |
| 249 | − expanded: true, | |
| 250 | − scripts: project.scripts, | |
| 251 | − })), | |
| 252 | − }); | |
| 253 | − dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true }); | |
| 254 | − bootstrappedRef.current = true; | |
| 255 | − } catch { | |
| 256 | − if (disposed) return; | |
| 257 | − retryTimer = setTimeout(() => { | |
| 258 | − retryTimer = null; | |
| 259 | − void attemptBootstrap(); | |
| 260 | − }, retryDelayMs); | |
| 261 | − retryDelayMs = Math.min(retryDelayMs * 2, 5_000); | |
| 262 | − } | |
| 263 | − }; | |
| 264 | − | |
| 265 | − void attemptBootstrap(); | |
| 266 | − | |
| 267 | − return () => { | |
| 268 | − disposed = true; | |
| 269 | − if (retryTimer) { | |
| 270 | − clearTimeout(retryTimer); | |
| 271 | − } | |
| 272 | − }; | |
| 177 | + if (!isElectron || !api) return; | |
| 178 | + dispatch({ type: "SET_THREADS_HYDRATED", hydrated: true }); | |
| 273 | 179 | }, [api, dispatch]); |
| 274 | 180 | |
| 275 | 181 | return null; |
| @@ -1,983 +0,0 @@ | ||
| 1 | −import type { ProviderEvent, ProviderSession, TerminalEvent } from "@t3tools/contracts"; | |
| 2 | −import { describe, expect, it } from "vitest"; | |
| 3 | − | |
| 4 | −import { type AppState, reducer } from "./store"; | |
| 5 | −import { | |
| 6 | − DEFAULT_THREAD_TERMINAL_HEIGHT, | |
| 7 | − DEFAULT_THREAD_TERMINAL_ID, | |
| 8 | − MAX_THREAD_TERMINAL_COUNT, | |
| 9 | −} from "./types"; | |
| 10 | −import type { Thread } from "./types"; | |
| 11 | − | |
| 12 | −type TerminalStartedEvent = Extract<TerminalEvent, { type: "started" }>; | |
| 13 | −type TerminalActivityEvent = Extract<TerminalEvent, { type: "activity" }>; | |
| 14 | − | |
| 15 | −function makeSession(overrides: Partial<ProviderSession> = {}): ProviderSession { | |
| 16 | − return { | |
| 17 | − sessionId: "sess-1", | |
| 18 | − provider: "codex", | |
| 19 | − status: "ready", | |
| 20 | − createdAt: "2026-02-09T00:00:00.000Z", | |
| 21 | − updatedAt: "2026-02-09T00:00:00.000Z", | |
| 22 | − ...overrides, | |
| 23 | − }; | |
| 24 | −} | |
| 25 | − | |
| 26 | −function makeEvent(overrides: Partial<ProviderEvent> = {}): ProviderEvent { | |
| 27 | − return { | |
| 28 | − id: "evt-1", | |
| 29 | − kind: "notification", | |
| 30 | − provider: "codex", | |
| 31 | − sessionId: "sess-1", | |
| 32 | − createdAt: "2026-02-09T00:00:01.000Z", | |
| 33 | − method: "thread/started", | |
| 34 | − ...overrides, | |
| 35 | − }; | |
| 36 | −} | |
| 37 | − | |
| 38 | −function makeThread(overrides: Partial<Thread> = {}): Thread { | |
| 39 | − return { | |
| 40 | − id: "thread-local-1", | |
| 41 | − codexThreadId: null, | |
| 42 | − projectId: "project-1", | |
| 43 | − title: "Thread", | |
| 44 | − model: "gpt-5.3-codex", | |
| 45 | − terminalOpen: false, | |
| 46 | − terminalHeight: DEFAULT_THREAD_TERMINAL_HEIGHT, | |
| 47 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID], | |
| 48 | − runningTerminalIds: [], | |
| 49 | − activeTerminalId: DEFAULT_THREAD_TERMINAL_ID, | |
| 50 | − terminalGroups: [ | |
| 51 | − { | |
| 52 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 53 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID], | |
| 54 | − }, | |
| 55 | − ], | |
| 56 | − activeTerminalGroupId: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 57 | − session: makeSession(), | |
| 58 | − messages: [], | |
| 59 | − events: [], | |
| 60 | − turnDiffSummaries: [], | |
| 61 | − error: null, | |
| 62 | − createdAt: "2026-02-09T00:00:00.000Z", | |
| 63 | − branch: null, | |
| 64 | − worktreePath: null, | |
| 65 | − ...overrides, | |
| 66 | − }; | |
| 67 | −} | |
| 68 | − | |
| 69 | −function makeState(thread: Thread): AppState { | |
| 70 | − return { | |
| 71 | − projects: [ | |
| 72 | − { | |
| 73 | − id: "project-1", | |
| 74 | − name: "Project", | |
| 75 | − cwd: "/tmp/project", | |
| 76 | − model: "gpt-5.3-codex", | |
| 77 | − expanded: true, | |
| 78 | − scripts: [], | |
| 79 | − }, | |
| 80 | − ], | |
| 81 | − threads: [thread], | |
| 82 | − threadsHydrated: true, | |
| 83 | − runtimeMode: "full-access", | |
| 84 | − }; | |
| 85 | −} | |
| 86 | − | |
| 87 | −function makeTerminalStartedEvent( | |
| 88 | − overrides: Partial<TerminalStartedEvent> = {}, | |
| 89 | −): TerminalStartedEvent { | |
| 90 | − return { | |
| 91 | − type: "started", | |
| 92 | − threadId: "thread-local-1", | |
| 93 | − terminalId: DEFAULT_THREAD_TERMINAL_ID, | |
| 94 | − createdAt: "2026-02-09T00:00:01.000Z", | |
| 95 | − snapshot: { | |
| 96 | − threadId: "thread-local-1", | |
| 97 | − terminalId: DEFAULT_THREAD_TERMINAL_ID, | |
| 98 | − cwd: "/tmp/project", | |
| 99 | − status: "running", | |
| 100 | − pid: 1234, | |
| 101 | − history: "", | |
| 102 | − exitCode: null, | |
| 103 | − exitSignal: null, | |
| 104 | − updatedAt: "2026-02-09T00:00:01.000Z", | |
| 105 | − }, | |
| 106 | − ...overrides, | |
| 107 | − }; | |
| 108 | −} | |
| 109 | − | |
| 110 | −function makeTerminalActivityEvent( | |
| 111 | − overrides: Partial<TerminalActivityEvent> = {}, | |
| 112 | −): TerminalActivityEvent { | |
| 113 | − return { | |
| 114 | − type: "activity", | |
| 115 | − threadId: "thread-local-1", | |
| 116 | − terminalId: DEFAULT_THREAD_TERMINAL_ID, | |
| 117 | − createdAt: "2026-02-09T00:00:02.000Z", | |
| 118 | − hasRunningSubprocess: true, | |
| 119 | − ...overrides, | |
| 120 | − }; | |
| 121 | −} | |
| 122 | − | |
| 123 | −describe("store reducer thread continuity", () => { | |
| 124 | − it("stores codexThreadId from UPDATE_SESSION", () => { | |
| 125 | − const state = makeState( | |
| 126 | − makeThread({ | |
| 127 | − session: null, | |
| 128 | − }), | |
| 129 | − ); | |
| 130 | − const next = reducer(state, { | |
| 131 | − type: "UPDATE_SESSION", | |
| 132 | − threadId: "thread-local-1", | |
| 133 | − session: makeSession({ threadId: "thr_123" }), | |
| 134 | − }); | |
| 135 | − | |
| 136 | − expect(next.threads[0]?.codexThreadId).toBe("thr_123"); | |
| 137 | − }); | |
| 138 | − | |
| 139 | − it("toggles terminal open state per thread", () => { | |
| 140 | − const state = makeState(makeThread({ terminalOpen: false })); | |
| 141 | − const next = reducer(state, { | |
| 142 | − type: "TOGGLE_THREAD_TERMINAL", | |
| 143 | − threadId: "thread-local-1", | |
| 144 | − }); | |
| 145 | − expect(next.threads[0]?.terminalOpen).toBe(true); | |
| 146 | − }); | |
| 147 | − | |
| 148 | − it("sets terminal open state per thread", () => { | |
| 149 | − const state = makeState(makeThread({ terminalOpen: true })); | |
| 150 | − const next = reducer(state, { | |
| 151 | − type: "SET_THREAD_TERMINAL_OPEN", | |
| 152 | − threadId: "thread-local-1", | |
| 153 | − open: false, | |
| 154 | − }); | |
| 155 | − expect(next.threads[0]?.terminalOpen).toBe(false); | |
| 156 | − }); | |
| 157 | − | |
| 158 | − it("sets terminal height per thread", () => { | |
| 159 | − const state = makeState(makeThread({ terminalHeight: 280 })); | |
| 160 | − const next = reducer(state, { | |
| 161 | − type: "SET_THREAD_TERMINAL_HEIGHT", | |
| 162 | − threadId: "thread-local-1", | |
| 163 | − height: 360, | |
| 164 | − }); | |
| 165 | − expect(next.threads[0]?.terminalHeight).toBe(360); | |
| 166 | − }); | |
| 167 | − | |
| 168 | − it("splits the active terminal into side-by-side mode", () => { | |
| 169 | − const state = makeState(makeThread()); | |
| 170 | − const next = reducer(state, { | |
| 171 | − type: "SPLIT_THREAD_TERMINAL", | |
| 172 | − threadId: "thread-local-1", | |
| 173 | − terminalId: "term-2", | |
| 174 | − }); | |
| 175 | − | |
| 176 | − expect(next.threads[0]?.terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID, "term-2"]); | |
| 177 | − expect(next.threads[0]?.activeTerminalId).toBe("term-2"); | |
| 178 | − expect(next.threads[0]?.terminalGroups).toEqual([ | |
| 179 | − { | |
| 180 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 181 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 182 | − }, | |
| 183 | − ]); | |
| 184 | − expect(next.threads[0]?.activeTerminalGroupId).toBe(`group-${DEFAULT_THREAD_TERMINAL_ID}`); | |
| 185 | − }); | |
| 186 | − | |
| 187 | − it("creates a new full-width terminal and switches to tab mode", () => { | |
| 188 | − const state = makeState(makeThread()); | |
| 189 | − const next = reducer(state, { | |
| 190 | − type: "NEW_THREAD_TERMINAL", | |
| 191 | − threadId: "thread-local-1", | |
| 192 | − terminalId: "term-2", | |
| 193 | − }); | |
| 194 | − | |
| 195 | − expect(next.threads[0]?.terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID, "term-2"]); | |
| 196 | − expect(next.threads[0]?.activeTerminalId).toBe("term-2"); | |
| 197 | − expect(next.threads[0]?.terminalGroups).toEqual([ | |
| 198 | − { | |
| 199 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 200 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID], | |
| 201 | − }, | |
| 202 | − { id: "group-term-2", terminalIds: ["term-2"] }, | |
| 203 | − ]); | |
| 204 | − expect(next.threads[0]?.activeTerminalGroupId).toBe("group-term-2"); | |
| 205 | − }); | |
| 206 | − | |
| 207 | − it("switches the active terminal and restores its owning group", () => { | |
| 208 | − const state = makeState( | |
| 209 | − makeThread({ | |
| 210 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2", "term-3"], | |
| 211 | − activeTerminalId: DEFAULT_THREAD_TERMINAL_ID, | |
| 212 | − terminalGroups: [ | |
| 213 | − { | |
| 214 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 215 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 216 | − }, | |
| 217 | − { id: "group-term-3", terminalIds: ["term-3"] }, | |
| 218 | − ], | |
| 219 | − activeTerminalGroupId: "group-term-3", | |
| 220 | − }), | |
| 221 | − ); | |
| 222 | − const next = reducer(state, { | |
| 223 | − type: "SET_THREAD_ACTIVE_TERMINAL", | |
| 224 | − threadId: "thread-local-1", | |
| 225 | − terminalId: "term-2", | |
| 226 | − }); | |
| 227 | − | |
| 228 | − expect(next.threads[0]?.activeTerminalId).toBe("term-2"); | |
| 229 | − expect(next.threads[0]?.activeTerminalGroupId).toBe(`group-${DEFAULT_THREAD_TERMINAL_ID}`); | |
| 230 | − }); | |
| 231 | − | |
| 232 | − it("supports splitting beyond two terminals in the same group", () => { | |
| 233 | − const state = makeState( | |
| 234 | − makeThread({ | |
| 235 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 236 | − activeTerminalId: "term-2", | |
| 237 | − terminalGroups: [ | |
| 238 | − { | |
| 239 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 240 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 241 | − }, | |
| 242 | − ], | |
| 243 | − activeTerminalGroupId: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 244 | − }), | |
| 245 | − ); | |
| 246 | − const next = reducer(state, { | |
| 247 | − type: "SPLIT_THREAD_TERMINAL", | |
| 248 | − threadId: "thread-local-1", | |
| 249 | − terminalId: "term-3", | |
| 250 | − }); | |
| 251 | − | |
| 252 | − expect(next.threads[0]?.terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID, "term-2", "term-3"]); | |
| 253 | − expect(next.threads[0]?.terminalGroups).toEqual([ | |
| 254 | − { | |
| 255 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 256 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2", "term-3"], | |
| 257 | − }, | |
| 258 | − ]); | |
| 259 | − expect(next.threads[0]?.activeTerminalId).toBe("term-3"); | |
| 260 | − expect(next.threads[0]?.activeTerminalGroupId).toBe(`group-${DEFAULT_THREAD_TERMINAL_ID}`); | |
| 261 | − }); | |
| 262 | − | |
| 263 | − it("caps split terminals at four per thread", () => { | |
| 264 | − const state = makeState( | |
| 265 | − makeThread({ | |
| 266 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2", "term-3", "term-4"], | |
| 267 | − activeTerminalId: "term-4", | |
| 268 | − terminalGroups: [ | |
| 269 | − { | |
| 270 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 271 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2", "term-3", "term-4"], | |
| 272 | − }, | |
| 273 | − ], | |
| 274 | − activeTerminalGroupId: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 275 | − }), | |
| 276 | − ); | |
| 277 | − const next = reducer(state, { | |
| 278 | − type: "SPLIT_THREAD_TERMINAL", | |
| 279 | − threadId: "thread-local-1", | |
| 280 | − terminalId: "term-5", | |
| 281 | − }); | |
| 282 | − | |
| 283 | − expect(next.threads[0]?.terminalIds).toHaveLength(MAX_THREAD_TERMINAL_COUNT); | |
| 284 | − expect(next.threads[0]?.terminalIds).toEqual([ | |
| 285 | − DEFAULT_THREAD_TERMINAL_ID, | |
| 286 | − "term-2", | |
| 287 | − "term-3", | |
| 288 | − "term-4", | |
| 289 | − ]); | |
| 290 | − expect(next.threads[0]?.activeTerminalId).toBe("term-4"); | |
| 291 | − }); | |
| 292 | − | |
| 293 | − it("caps new terminals at four per thread", () => { | |
| 294 | − const state = makeState( | |
| 295 | − makeThread({ | |
| 296 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2", "term-3", "term-4"], | |
| 297 | − activeTerminalId: "term-4", | |
| 298 | − terminalGroups: [ | |
| 299 | − { | |
| 300 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 301 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID], | |
| 302 | − }, | |
| 303 | − { id: "group-term-2", terminalIds: ["term-2"] }, | |
| 304 | − { id: "group-term-3", terminalIds: ["term-3"] }, | |
| 305 | − { id: "group-term-4", terminalIds: ["term-4"] }, | |
| 306 | − ], | |
| 307 | − activeTerminalGroupId: "group-term-4", | |
| 308 | − }), | |
| 309 | − ); | |
| 310 | − const next = reducer(state, { | |
| 311 | − type: "NEW_THREAD_TERMINAL", | |
| 312 | − threadId: "thread-local-1", | |
| 313 | − terminalId: "term-5", | |
| 314 | − }); | |
| 315 | − | |
| 316 | − expect(next.threads[0]?.terminalIds).toHaveLength(MAX_THREAD_TERMINAL_COUNT); | |
| 317 | − expect(next.threads[0]?.terminalIds).toEqual([ | |
| 318 | − DEFAULT_THREAD_TERMINAL_ID, | |
| 319 | − "term-2", | |
| 320 | − "term-3", | |
| 321 | − "term-4", | |
| 322 | − ]); | |
| 323 | − expect(next.threads[0]?.activeTerminalId).toBe("term-4"); | |
| 324 | − expect(next.threads[0]?.activeTerminalGroupId).toBe("group-term-4"); | |
| 325 | − }); | |
| 326 | − | |
| 327 | − it("closes a terminal and keeps grouped layout coherent", () => { | |
| 328 | − const state = makeState( | |
| 329 | − makeThread({ | |
| 330 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2", "term-3"], | |
| 331 | − activeTerminalId: "term-2", | |
| 332 | − terminalGroups: [ | |
| 333 | − { | |
| 334 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 335 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 336 | − }, | |
| 337 | − { id: "group-term-3", terminalIds: ["term-3"] }, | |
| 338 | − ], | |
| 339 | − activeTerminalGroupId: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 340 | − }), | |
| 341 | − ); | |
| 342 | − const next = reducer(state, { | |
| 343 | − type: "CLOSE_THREAD_TERMINAL", | |
| 344 | − threadId: "thread-local-1", | |
| 345 | − terminalId: "term-2", | |
| 346 | − }); | |
| 347 | − | |
| 348 | − expect(next.threads[0]?.terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID, "term-3"]); | |
| 349 | − expect(next.threads[0]?.activeTerminalId).toBe(DEFAULT_THREAD_TERMINAL_ID); | |
| 350 | − expect(next.threads[0]?.terminalGroups).toEqual([ | |
| 351 | − { | |
| 352 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 353 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID], | |
| 354 | − }, | |
| 355 | − { id: "group-term-3", terminalIds: ["term-3"] }, | |
| 356 | − ]); | |
| 357 | − }); | |
| 358 | − | |
| 359 | − it("closes the final terminal and hides the drawer", () => { | |
| 360 | − const state = makeState( | |
| 361 | − makeThread({ | |
| 362 | − terminalOpen: true, | |
| 363 | − runningTerminalIds: [DEFAULT_THREAD_TERMINAL_ID], | |
| 364 | − }), | |
| 365 | − ); | |
| 366 | − const next = reducer(state, { | |
| 367 | − type: "CLOSE_THREAD_TERMINAL", | |
| 368 | − threadId: "thread-local-1", | |
| 369 | − terminalId: DEFAULT_THREAD_TERMINAL_ID, | |
| 370 | − }); | |
| 371 | − | |
| 372 | − expect(next.threads[0]?.terminalOpen).toBe(false); | |
| 373 | − expect(next.threads[0]?.terminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID]); | |
| 374 | − expect(next.threads[0]?.runningTerminalIds).toEqual([]); | |
| 375 | − expect(next.threads[0]?.activeTerminalId).toBe(DEFAULT_THREAD_TERMINAL_ID); | |
| 376 | − expect(next.threads[0]?.terminalGroups).toEqual([ | |
| 377 | − { | |
| 378 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 379 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID], | |
| 380 | − }, | |
| 381 | − ]); | |
| 382 | − }); | |
| 383 | − | |
| 384 | − it("tracks running terminals from subprocess activity events", () => { | |
| 385 | − const state = makeState(makeThread()); | |
| 386 | − const started = reducer(state, { | |
| 387 | − type: "APPLY_TERMINAL_EVENT", | |
| 388 | − event: makeTerminalStartedEvent(), | |
| 389 | − }); | |
| 390 | − expect(started.threads[0]?.runningTerminalIds).toEqual([]); | |
| 391 | − | |
| 392 | − const active = reducer(started, { | |
| 393 | − type: "APPLY_TERMINAL_EVENT", | |
| 394 | − event: makeTerminalActivityEvent(), | |
| 395 | − }); | |
| 396 | − expect(active.threads[0]?.runningTerminalIds).toEqual([DEFAULT_THREAD_TERMINAL_ID]); | |
| 397 | − | |
| 398 | − const idle = reducer(active, { | |
| 399 | − type: "APPLY_TERMINAL_EVENT", | |
| 400 | − event: makeTerminalActivityEvent({ hasRunningSubprocess: false }), | |
| 401 | − }); | |
| 402 | − expect(idle.threads[0]?.runningTerminalIds).toEqual([]); | |
| 403 | − | |
| 404 | − const exited = reducer(active, { | |
| 405 | − type: "APPLY_TERMINAL_EVENT", | |
| 406 | − event: { | |
| 407 | − type: "exited", | |
| 408 | − threadId: "thread-local-1", | |
| 409 | − terminalId: DEFAULT_THREAD_TERMINAL_ID, | |
| 410 | − createdAt: "2026-02-09T00:00:05.000Z", | |
| 411 | − exitCode: 0, | |
| 412 | − exitSignal: null, | |
| 413 | − }, | |
| 414 | − }); | |
| 415 | − expect(exited.threads[0]?.runningTerminalIds).toEqual([]); | |
| 416 | − }); | |
| 417 | − | |
| 418 | − it("keeps running status when another terminal in the thread is still running", () => { | |
| 419 | − const state = makeState( | |
| 420 | − makeThread({ | |
| 421 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 422 | − runningTerminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 423 | − activeTerminalId: "term-2", | |
| 424 | − terminalGroups: [ | |
| 425 | − { | |
| 426 | − id: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 427 | − terminalIds: [DEFAULT_THREAD_TERMINAL_ID, "term-2"], | |
| 428 | − }, | |
| 429 | − ], | |
| 430 | − activeTerminalGroupId: `group-${DEFAULT_THREAD_TERMINAL_ID}`, | |
| 431 | − }), | |
| 432 | − ); | |
| 433 | − | |
| 434 | − const next = reducer(state, { | |
| 435 | − type: "APPLY_TERMINAL_EVENT", | |
| 436 | − event: { | |
| 437 | − type: "exited", | |
| 438 | − threadId: "thread-local-1", | |
| 439 | − terminalId: DEFAULT_THREAD_TERMINAL_ID, | |
| 440 | − createdAt: "2026-02-09T00:00:07.000Z", | |
| 441 | − exitCode: 0, | |
| 442 | − exitSignal: null, | |
| 443 | − }, | |
| 444 | − }); | |
| 445 | − | |
| 446 | − expect(next.threads[0]?.runningTerminalIds).toEqual(["term-2"]); | |
| 447 | − }); | |
| 448 | − | |
| 449 | − it("backfills codexThreadId from routed provider events", () => { | |
| 450 | − const state = makeState(makeThread({ codexThreadId: null })); | |
| 451 | − const next = reducer(state, { | |
| 452 | − type: "APPLY_EVENT", | |
| 453 | − event: makeEvent({ | |
| 454 | − method: "thread/started", | |
| 455 | − payload: { thread: { id: "thr_backfilled" } }, | |
| 456 | − }), | |
| 457 | − activeAssistantItemRef: { current: null }, | |
| 458 | − }); | |
| 459 | − | |
| 460 | − expect(next.threads[0]?.codexThreadId).toBe("thr_backfilled"); | |
| 461 | − }); | |
| 462 | − | |
| 463 | − it("ignores events from a foreign thread within the same session", () => { | |
| 464 | − const state = makeState(makeThread({ codexThreadId: "thr_expected" })); | |
| 465 | − const next = reducer(state, { | |
| 466 | − type: "APPLY_EVENT", | |
| 467 | − event: makeEvent({ | |
| 468 | − method: "turn/started", | |
| 469 | − threadId: "thr_unexpected", | |
| 470 | − payload: { turn: { id: "turn-1" } }, | |
| 471 | − }), | |
| 472 | − activeAssistantItemRef: { current: null }, | |
| 473 | − }); | |
| 474 | − | |
| 475 | − expect(next).toBe(state); | |
| 476 | − }); | |
| 477 | − | |
| 478 | − it("rebases thread identity on thread/started during connect", () => { | |
| 479 | − const state = makeState( | |
| 480 | − makeThread({ | |
| 481 | − codexThreadId: "thr_old", | |
| 482 | − session: makeSession({ | |
| 483 | − status: "connecting", | |
| 484 | − threadId: "thr_old", | |
| 485 | − }), | |
| 486 | − }), | |
| 487 | − ); | |
| 488 | − const next = reducer(state, { | |
| 489 | − type: "APPLY_EVENT", | |
| 490 | − event: makeEvent({ | |
| 491 | − method: "thread/started", | |
| 492 | − threadId: "thr_new", | |
| 493 | − payload: { thread: { id: "thr_new" } }, | |
| 494 | − }), | |
| 495 | − activeAssistantItemRef: { current: null }, | |
| 496 | − }); | |
| 497 | − | |
| 498 | − expect(next.threads[0]?.codexThreadId).toBe("thr_new"); | |
| 499 | − expect(next.threads[0]?.session?.threadId).toBe("thr_new"); | |
| 500 | − }); | |
| 501 | − | |
| 502 | − it("preserves persisted turn diffs when events were reset and appends new completed turn diffs", () => { | |
| 503 | − const state = makeState( | |
| 504 | − makeThread({ | |
| 505 | − events: [], | |
| 506 | − turnDiffSummaries: [ | |
| 507 | − { | |
| 508 | − turnId: "turn-1", | |
| 509 | − completedAt: "2026-02-09T00:00:01.000Z", | |
| 510 | − files: [{ path: "src/existing.ts", kind: "modified" }], | |
| 511 | − }, | |
| 512 | − ], | |
| 513 | − }), | |
| 514 | − ); | |
| 515 | − | |
| 516 | − const withFileChange = reducer(state, { | |
| 517 | − type: "APPLY_EVENT", | |
| 518 | − event: makeEvent({ | |
| 519 | − method: "item/completed", | |
| 520 | − turnId: "turn-2", | |
| 521 | − createdAt: "2026-02-09T00:00:02.000Z", | |
| 522 | − payload: { | |
| 523 | − item: { | |
| 524 | − type: "fileChange", | |
| 525 | − changes: [{ path: "src/new.ts", kind: "added" }], | |
| 526 | − }, | |
| 527 | − }, | |
| 528 | − }), | |
| 529 | − activeAssistantItemRef: { current: null }, | |
| 530 | − }); | |
| 531 | − | |
| 532 | − expect(withFileChange.threads[0]?.turnDiffSummaries.map((summary) => summary.turnId)).toEqual([ | |
| 533 | − "turn-1", | |
| 534 | − ]); | |
| 535 | − | |
| 536 | − const completed = reducer(withFileChange, { | |
| 537 | − type: "APPLY_EVENT", | |
| 538 | − event: makeEvent({ | |
| 539 | − method: "turn/completed", | |
| 540 | − turnId: "turn-2", | |
| 541 | − createdAt: "2026-02-09T00:00:03.000Z", | |
| 542 | − payload: { turn: { id: "turn-2", status: "completed" } }, | |
| 543 | − }), | |
| 544 | − activeAssistantItemRef: { current: null }, | |
| 545 | − }); | |
| 546 | − | |
| 547 | − expect(completed.threads[0]?.turnDiffSummaries.map((summary) => summary.turnId)).toEqual([ | |
| 548 | − "turn-2", | |
| 549 | − "turn-1", | |
| 550 | − ]); | |
| 551 | − }); | |
| 552 | − | |
| 553 | − it("infers checkpoint turn counts when deriving turn summaries from an empty baseline", () => { | |
| 554 | − const state = makeState(makeThread({ turnDiffSummaries: [] })); | |
| 555 | − const next = reducer(state, { | |
| 556 | − type: "APPLY_EVENT", | |
| 557 | − event: makeEvent({ | |
| 558 | − method: "turn/completed", | |
| 559 | − turnId: "turn-1", | |
| 560 | − createdAt: "2026-02-09T00:00:03.000Z", | |
| 561 | − payload: { turn: { id: "turn-1", status: "completed" } }, | |
| 562 | − }), | |
| 563 | − activeAssistantItemRef: { current: null }, | |
| 564 | − }); | |
| 565 | − | |
| 566 | − expect(next.threads[0]?.turnDiffSummaries[0]?.turnId).toBe("turn-1"); | |
| 567 | − expect(next.threads[0]?.turnDiffSummaries[0]?.checkpointTurnCount).toBe(1); | |
| 568 | − }); | |
| 569 | − | |
| 570 | − it("reconciles project ids by cwd when syncing backend projects", () => { | |
| 571 | − const state: AppState = { | |
| 572 | − projects: [ | |
| 573 | − { | |
| 574 | − id: "project-old-a", | |
| 575 | − name: "A", | |
| 576 | − cwd: "/tmp/a", | |
| 577 | − model: "gpt-5.3-codex", | |
| 578 | − expanded: false, | |
| 579 | − scripts: [], | |
| 580 | − }, | |
| 581 | − { | |
| 582 | − id: "project-old-b", | |
| 583 | − name: "B", | |
| 584 | − cwd: "/tmp/b", | |
| 585 | − model: "gpt-5.3-codex", | |
| 586 | − expanded: true, | |
| 587 | − scripts: [], | |
| 588 | − }, | |
| 589 | − ], | |
| 590 | − threads: [ | |
| 591 | − makeThread({ | |
| 592 | − id: "thread-a", | |
| 593 | − projectId: "project-old-a", | |
| 594 | − }), | |
| 595 | − makeThread({ | |
| 596 | − id: "thread-b", | |
| 597 | − projectId: "project-old-b", | |
| 598 | − }), | |
| 599 | − ], | |
| 600 | − threadsHydrated: true, | |
| 601 | − runtimeMode: "full-access", | |
| 602 | − }; | |
| 603 | − | |
| 604 | − const next = reducer(state, { | |
| 605 | − type: "SYNC_PROJECTS", | |
| 606 | − projects: [ | |
| 607 | − { | |
| 608 | − id: "project-new-a", | |
| 609 | − name: "A", | |
| 610 | − cwd: "/tmp/a", | |
| 611 | − model: "gpt-5.3-codex", | |
| 612 | − expanded: true, | |
| 613 | − scripts: [], | |
| 614 | − }, | |
| 615 | − ], | |
| 616 | − }); | |
| 617 | − | |
| 618 | − expect(next.projects).toHaveLength(1); | |
| 619 | − expect(next.projects[0]?.id).toBe("project-new-a"); | |
| 620 | − // Preserve existing project UI preferences by cwd | |
| 621 | − expect(next.projects[0]?.expanded).toBe(false); | |
| 622 | − expect(next.threads).toHaveLength(1); | |
| 623 | − expect(next.threads[0]?.id).toBe("thread-a"); | |
| 624 | − expect(next.threads[0]?.projectId).toBe("project-new-a"); | |
| 625 | − }); | |
| 626 | − | |
| 627 | − it("treats empty scripts from sync as authoritative", () => { | |
| 628 | − const state: AppState = { | |
| 629 | − projects: [ | |
| 630 | − { | |
| 631 | − id: "project-old-a", | |
| 632 | − name: "A", | |
| 633 | − cwd: "/tmp/a", | |
| 634 | − model: "gpt-5.3-codex", | |
| 635 | − expanded: true, | |
| 636 | − scripts: [ | |
| 637 | − { | |
| 638 | − id: "test", | |
| 639 | − name: "Test", | |
| 640 | − command: "bun test", | |
| 641 | − icon: "test", | |
| 642 | − runOnWorktreeCreate: false, | |
| 643 | − }, | |
| 644 | − ], | |
| 645 | − }, | |
| 646 | − ], | |
| 647 | − threads: [makeThread({ id: "thread-a", projectId: "project-old-a" })], | |
| 648 | − threadsHydrated: true, | |
| 649 | − runtimeMode: "full-access", | |
| 650 | − }; | |
| 651 | − | |
| 652 | − const next = reducer(state, { | |
| 653 | − type: "SYNC_PROJECTS", | |
| 654 | − projects: [ | |
| 655 | − { | |
| 656 | − id: "project-new-a", | |
| 657 | − name: "A", | |
| 658 | − cwd: "/tmp/a", | |
| 659 | − model: "gpt-5.3-codex", | |
| 660 | − expanded: false, | |
| 661 | − scripts: [], | |
| 662 | − }, | |
| 663 | − ], | |
| 664 | − }); | |
| 665 | − | |
| 666 | − expect(next.projects[0]?.scripts).toEqual([]); | |
| 667 | − }); | |
| 668 | − | |
| 669 | − it("updates project scripts", () => { | |
| 670 | − const state = makeState(makeThread()); | |
| 671 | − const next = reducer(state, { | |
| 672 | − type: "SET_PROJECT_SCRIPTS", | |
| 673 | − projectId: "project-1", | |
| 674 | − scripts: [ | |
| 675 | − { | |
| 676 | − id: "test", | |
| 677 | − name: "Test", | |
| 678 | − command: "bun test", | |
| 679 | − icon: "test", | |
| 680 | − runOnWorktreeCreate: false, | |
| 681 | − }, | |
| 682 | − ], | |
| 683 | − }); | |
| 684 | − | |
| 685 | − expect(next.projects[0]?.scripts).toEqual([ | |
| 686 | − { | |
| 687 | − id: "test", | |
| 688 | − name: "Test", | |
| 689 | − command: "bun test", | |
| 690 | − icon: "test", | |
| 691 | − runOnWorktreeCreate: false, | |
| 692 | − }, | |
| 693 | − ]); | |
| 694 | − }); | |
| 695 | − | |
| 696 | − it("marks threads hydration state", () => { | |
| 697 | − const state = makeState(makeThread()); | |
| 698 | − const next = reducer(state, { | |
| 699 | − type: "SET_THREADS_HYDRATED", | |
| 700 | − hydrated: false, | |
| 701 | − }); | |
| 702 | − | |
| 703 | − expect(next.threadsHydrated).toBe(false); | |
| 704 | − }); | |
| 705 | − | |
| 706 | − it("deletes a project and all of its threads", () => { | |
| 707 | − const state: AppState = { | |
| 708 | − projects: [ | |
| 709 | − { | |
| 710 | − id: "project-1", | |
| 711 | − name: "One", | |
| 712 | − cwd: "/tmp/one", | |
| 713 | − model: "gpt-5.3-codex", | |
| 714 | − expanded: true, | |
| 715 | − scripts: [], | |
| 716 | − }, | |
| 717 | − { | |
| 718 | − id: "project-2", | |
| 719 | − name: "Two", | |
| 720 | − cwd: "/tmp/two", | |
| 721 | − model: "gpt-5.3-codex", | |
| 722 | − expanded: true, | |
| 723 | − scripts: [], | |
| 724 | − }, | |
| 725 | − ], | |
| 726 | − threads: [ | |
| 727 | − makeThread({ | |
| 728 | − id: "thread-a", | |
| 729 | − projectId: "project-1", | |
| 730 | − }), | |
| 731 | − makeThread({ | |
| 732 | − id: "thread-b", | |
| 733 | − projectId: "project-2", | |
| 734 | − }), | |
| 735 | − ], | |
| 736 | − threadsHydrated: true, | |
| 737 | − runtimeMode: "full-access", | |
| 738 | − }; | |
| 739 | − | |
| 740 | − const next = reducer(state, { | |
| 741 | − type: "DELETE_PROJECT", | |
| 742 | − projectId: "project-1", | |
| 743 | − }); | |
| 744 | − | |
| 745 | − expect(next.projects).toHaveLength(1); | |
| 746 | − expect(next.projects[0]?.id).toBe("project-2"); | |
| 747 | − expect(next.threads).toHaveLength(1); | |
| 748 | − expect(next.threads[0]?.id).toBe("thread-b"); | |
| 749 | − }); | |
| 750 | − | |
| 751 | − it("marks completion as seen immediately for the active thread", () => { | |
| 752 | − const state = makeState( | |
| 753 | − makeThread({ | |
| 754 | − session: makeSession({ | |
| 755 | − status: "running", | |
| 756 | − activeTurnId: "turn-1", | |
| 757 | − }), | |
| 758 | − lastVisitedAt: "2026-02-08T10:00:00.000Z", | |
| 759 | − }), | |
| 760 | − ); | |
| 761 | − | |
| 762 | − const completedAt = "2026-02-08T10:00:10.000Z"; | |
| 763 | − const next = reducer(state, { | |
| 764 | − type: "APPLY_EVENT", | |
| 765 | − event: makeEvent({ | |
| 766 | − method: "turn/completed", | |
| 767 | − turnId: "turn-1", | |
| 768 | − createdAt: completedAt, | |
| 769 | − payload: { turn: { id: "turn-1", status: "completed" } }, | |
| 770 | − }), | |
| 771 | − activeAssistantItemRef: { current: null }, | |
| 772 | − activeThreadId: "thread-local-1", | |
| 773 | − }); | |
| 774 | − | |
| 775 | − expect(next.threads[0]?.latestTurnCompletedAt).toBe(completedAt); | |
| 776 | − expect(next.threads[0]?.lastVisitedAt).toBe(completedAt); | |
| 777 | − }); | |
| 778 | − | |
| 779 | − it("marks a thread as visited when selected", () => { | |
| 780 | − const state = makeState( | |
| 781 | − makeThread({ | |
| 782 | − latestTurnCompletedAt: "2026-02-08T10:00:10.000Z", | |
| 783 | − lastVisitedAt: "2026-02-08T10:00:00.000Z", | |
| 784 | − }), | |
| 785 | − ); | |
| 786 | − | |
| 787 | − const nextVisitedAt = "2026-02-08T10:00:20.000Z"; | |
| 788 | − const next = reducer(state, { | |
| 789 | − type: "MARK_THREAD_VISITED", | |
| 790 | − threadId: "thread-local-1", | |
| 791 | − visitedAt: nextVisitedAt, | |
| 792 | − }); | |
| 793 | − | |
| 794 | − expect(next.threads[0]?.lastVisitedAt).toBe(nextVisitedAt); | |
| 795 | − }); | |
| 796 | − | |
| 797 | − it("reverts thread state to a checkpoint snapshot", () => { | |
| 798 | − const state = makeState( | |
| 799 | − makeThread({ | |
| 800 | − codexThreadId: "thr_before", | |
| 801 | − session: makeSession({ | |
| 802 | − status: "running", | |
| 803 | − threadId: "thr_before", | |
| 804 | − activeTurnId: "turn-live", | |
| 805 | − }), | |
| 806 | − messages: [ | |
| 807 | − { | |
| 808 | − id: "m-1", | |
| 809 | − role: "user", | |
| 810 | − text: "First", | |
| 811 | − createdAt: "2026-02-08T10:00:00.000Z", | |
| 812 | − streaming: false, | |
| 813 | − }, | |
| 814 | − { | |
| 815 | − id: "m-2", | |
| 816 | − role: "assistant", | |
| 817 | − text: "First reply", | |
| 818 | − createdAt: "2026-02-08T10:00:01.000Z", | |
| 819 | − streaming: false, | |
| 820 | − }, | |
| 821 | − { | |
| 822 | − id: "m-3", | |
| 823 | − role: "user", | |
| 824 | − text: "Second", | |
| 825 | − createdAt: "2026-02-08T10:00:02.000Z", | |
| 826 | − streaming: false, | |
| 827 | − }, | |
| 828 | − ], | |
| 829 | − events: [ | |
| 830 | − makeEvent({ | |
| 831 | − method: "turn/started", | |
| 832 | − turnId: "turn-live", | |
| 833 | − }), | |
| 834 | − ], | |
| 835 | − turnDiffSummaries: [ | |
| 836 | − { | |
| 837 | − turnId: "turn_1", | |
| 838 | − completedAt: "2026-02-08T10:00:01.000Z", | |
| 839 | − files: [{ path: "src/first.ts", kind: "modified" }], | |
| 840 | − checkpointTurnCount: 1, | |
| 841 | − }, | |
| 842 | − { | |
| 843 | − turnId: "turn_2", | |
| 844 | − completedAt: "2026-02-08T10:00:03.000Z", | |
| 845 | − files: [{ path: "src/second.ts", kind: "modified" }], | |
| 846 | − checkpointTurnCount: 2, | |
| 847 | − }, | |
| 848 | − ], | |
| 849 | − error: "temporary failure", | |
| 850 | − latestTurnId: "turn-live", | |
| 851 | − latestTurnStartedAt: "2026-02-08T10:00:03.000Z", | |
| 852 | − }), | |
| 853 | − ); | |
| 854 | − | |
| 855 | − const next = reducer(state, { | |
| 856 | − type: "REVERT_TO_CHECKPOINT", | |
| 857 | − threadId: "thread-local-1", | |
| 858 | − sessionId: "sess-1", | |
| 859 | − threadRuntimeId: "thr_after", | |
| 860 | − turnCount: 1, | |
| 861 | − messageCount: 2, | |
| 862 | − }); | |
| 863 | − | |
| 864 | − expect(next.threads[0]?.codexThreadId).toBe("thr_after"); | |
| 865 | − expect(next.threads[0]?.messages.map((message) => message.id)).toEqual(["m-1", "m-2"]); | |
| 866 | − expect(next.threads[0]?.events).toEqual([]); | |
| 867 | − expect(next.threads[0]?.error).toBeNull(); | |
| 868 | − expect(next.threads[0]?.session?.status).toBe("ready"); | |
| 869 | − expect(next.threads[0]?.session?.activeTurnId).toBeUndefined(); | |
| 870 | − expect(next.threads[0]?.session?.threadId).toBe("thr_after"); | |
| 871 | − expect(next.threads[0]?.latestTurnId).toBeUndefined(); | |
| 872 | − expect(next.threads[0]?.turnDiffSummaries.map((summary) => summary.turnId)).toEqual(["turn_1"]); | |
| 873 | − }); | |
| 874 | − | |
| 875 | − it("keeps existing turn file metadata when later events for the same turn arrive", () => { | |
| 876 | − const state = makeState( | |
| 877 | − makeThread({ | |
| 878 | − turnDiffSummaries: [ | |
| 879 | − { | |
| 880 | − turnId: "turn-1", | |
| 881 | − completedAt: "2026-02-09T00:00:03.000Z", | |
| 882 | − files: [ | |
| 883 | − { | |
| 884 | − path: "src/from-checkpoint.ts", | |
| 885 | − additions: 1, | |
| 886 | − deletions: 1, | |
| 887 | − }, | |
| 888 | − ], | |
| 889 | − }, | |
| 890 | − ], | |
| 891 | − }), | |
| 892 | − ); | |
| 893 | − | |
| 894 | − const next = reducer(state, { | |
| 895 | − type: "APPLY_EVENT", | |
| 896 | − event: makeEvent({ | |
| 897 | − method: "turn/completed", | |
| 898 | − turnId: "turn-1", | |
| 899 | − createdAt: "2026-02-09T00:00:04.000Z", | |
| 900 | − payload: { turn: { id: "turn-1", status: "completed" } }, | |
| 901 | − }), | |
| 902 | − activeAssistantItemRef: { current: null }, | |
| 903 | − }); | |
| 904 | − | |
| 905 | − expect(next.threads[0]?.turnDiffSummaries[0]?.files.map((file) => file.path)).toEqual([ | |
| 906 | − "src/from-checkpoint.ts", | |
| 907 | − ]); | |
| 908 | − expect(next.threads[0]?.turnDiffSummaries[0]?.files[0]?.additions).toBe(1); | |
| 909 | − expect(next.threads[0]?.turnDiffSummaries[0]?.files[0]?.deletions).toBe(1); | |
| 910 | − }); | |
| 911 | − | |
| 912 | − it("updates checkpoint turn counts from authoritative checkpoint mappings", () => { | |
| 913 | − const state = makeState( | |
| 914 | − makeThread({ | |
| 915 | − turnDiffSummaries: [ | |
| 916 | − { | |
| 917 | − turnId: "turn-1", | |
| 918 | − completedAt: "2026-02-09T00:00:03.000Z", | |
| 919 | − files: [], | |
| 920 | − checkpointTurnCount: 1, | |
| 921 | − }, | |
| 922 | − { | |
| 923 | − turnId: "turn-2", | |
| 924 | − completedAt: "2026-02-09T00:00:04.000Z", | |
| 925 | − files: [], | |
| 926 | − checkpointTurnCount: 2, | |
| 927 | − }, | |
| 928 | − ], | |
| 929 | − }), | |
| 930 | − ); | |
| 931 | − | |
| 932 | − const next = reducer(state, { | |
| 933 | − type: "SET_THREAD_TURN_CHECKPOINT_COUNTS", | |
| 934 | − threadId: "thread-local-1", | |
| 935 | − checkpointTurnCountByTurnId: { | |
| 936 | − "turn-1": 2, | |
| 937 | − "turn-2": 3, | |
| 938 | − }, | |
| 939 | − }); | |
| 940 | − | |
| 941 | − expect(next.threads[0]?.turnDiffSummaries[0]?.checkpointTurnCount).toBe(2); | |
| 942 | − expect(next.threads[0]?.turnDiffSummaries[1]?.checkpointTurnCount).toBe(3); | |
| 943 | − }); | |
| 944 | − | |
| 945 | − it("does not rederive completed turn summaries from late turn diff events", () => { | |
| 946 | − const completed = reducer(makeState(makeThread()), { | |
| 947 | − type: "APPLY_EVENT", | |
| 948 | − event: makeEvent({ | |
| 949 | − method: "turn/completed", | |
| 950 | − turnId: "turn-1", | |
| 951 | − createdAt: "2026-02-09T00:00:03.000Z", | |
| 952 | − payload: { turn: { id: "turn-1", status: "completed" } }, | |
| 953 | − }), | |
| 954 | − activeAssistantItemRef: { current: null }, | |
| 955 | − }); | |
| 956 | − | |
| 957 | − expect(completed.threads[0]?.turnDiffSummaries[0]?.files).toEqual([]); | |
| 958 | − | |
| 959 | − const withLateDiff = reducer(completed, { | |
| 960 | − type: "APPLY_EVENT", | |
| 961 | − event: makeEvent({ | |
| 962 | − method: "turn/diff/updated", | |
| 963 | − turnId: "turn-1", | |
| 964 | − createdAt: "2026-02-09T00:00:04.000Z", | |
| 965 | − payload: { | |
| 966 | − diff: [ | |
| 967 | − "diff --git a/src/a.ts b/src/a.ts", | |
| 968 | − "@@ -1 +1 @@", | |
| 969 | − "-old", | |
| 970 | − "+new", | |
| 971 | − "diff --git a/src/b.ts b/src/b.ts", | |
| 972 | − "@@ -1 +1 @@", | |
| 973 | − "-old", | |
| 974 | − "+new", | |
| 975 | − ].join("\n"), | |
| 976 | − }, | |
| 977 | − }), | |
| 978 | − activeAssistantItemRef: { current: null }, | |
| 979 | − }); | |
| 980 | − | |
| 981 | − expect(withLateDiff.threads[0]?.turnDiffSummaries[0]?.files).toEqual([]); | |
| 982 | − }); | |
| 983 | −}); | |
| @@ -4,21 +4,11 @@ import { · 3 unmodified lines | ||
| 4 | 4 | createContext, |
| 5 | 5 | createElement, |
| 6 | 6 | useContext, |
| 7 | − useEffect, | |
| 8 | 7 | useReducer, |
| 9 | 8 | } from "react"; |
| 10 | 9 | |
| 11 | −import { type ProviderEvent, type ProviderSession, type TerminalEvent, normalizeProjectScripts } from "@t3tools/contracts"; | |
| 10 | +import { type ProviderSession, normalizeProjectScripts } from "@t3tools/contracts"; | |
| 12 | 11 | import { resolveModelSlug } from "./model-logic"; |
| 13 | −import { hydratePersistedState, toPersistedState } from "./persistenceSchema"; | |
| 14 | −import { | |
| 15 | − applyEventToMessages, | |
| 16 | − asObject, | |
| 17 | − asString, | |
| 18 | − deriveTurnDiffSummaries, | |
| 19 | − inferCheckpointTurnCountByTurnId, | |
| 20 | − evolveSession, | |
| 21 | −} from "./session-logic"; | |
| 22 | 12 | import { |
| 23 | 13 | type ChatAttachment, |
| 24 | 14 | DEFAULT_THREAD_TERMINAL_ID, |
| @@ -34,6 +24,7 @@ import { · 9 unmodified lines | ||
| 34 | 24 | // ── Actions ────────────────────────────────────────────────────────── |
| 35 | 25 | |
| 36 | 26 | type Action = |
| 27 | + | { type: "SET_SERVER_STATE"; state: AppState } | |
| 37 | 28 | | { type: "ADD_PROJECT"; project: Project } |
| 38 | 29 | | { type: "SET_PROJECT_SCRIPTS"; projectId: string; scripts: ProjectScript[] } |
| 39 | 30 | | { type: "SYNC_PROJECTS"; projects: Project[] } |
| @@ -48,13 +39,6 @@ type Action = · 8 unmodified lines | ||
| 48 | 39 | | { type: "NEW_THREAD_TERMINAL"; threadId: string; terminalId: string } |
| 49 | 40 | | { type: "SET_THREAD_ACTIVE_TERMINAL"; threadId: string; terminalId: string } |
| 50 | 41 | | { type: "CLOSE_THREAD_TERMINAL"; threadId: string; terminalId: string } |
| 51 | − | { | |
| 52 | − type: "APPLY_EVENT"; | |
| 53 | − event: ProviderEvent; | |
| 54 | − activeAssistantItemRef: { current: string | null }; | |
| 55 | − activeThreadId?: string | null; | |
| 56 | − } | |
| 57 | − | { type: "APPLY_TERMINAL_EVENT"; event: TerminalEvent } | |
| 58 | 42 | | { type: "UPDATE_SESSION"; threadId: string; session: ProviderSession } |
| 59 | 43 | | { |
| 60 | 44 | type: "PUSH_USER_MESSAGE"; |
| @@ -98,18 +82,6 @@ export interface AppState { · 37 unmodified lines | ||
| 98 | 82 | runtimeMode: RuntimeMode; |
| 99 | 83 | } |
| 100 | 84 | |
| 101 | −const PERSISTED_STATE_KEY = "t3code:renderer-state:v7"; | |
| 102 | −const LEGACY_PERSISTED_STATE_KEYS = [ | |
| 103 | − "t3code:renderer-state:v6", | |
| 104 | − "t3code:renderer-state:v5", | |
| 105 | − "t3code:renderer-state:v4", | |
| 106 | − "t3code:renderer-state:v3", | |
| 107 | − "codething:renderer-state:v4", | |
| 108 | − "codething:renderer-state:v3", | |
| 109 | − "codething:renderer-state:v2", | |
| 110 | − "codething:renderer-state:v1", | |
| 111 | −] as const; | |
| 112 | − | |
| 113 | 85 | const initialState: AppState = { |
| 114 | 86 | projects: [], |
| 115 | 87 | threads: [], |
| @@ -120,41 +92,11 @@ const initialState: AppState = { · 4 unmodified lines | ||
| 120 | 92 | // ── Helpers ────────────────────────────────────────────────────────── |
| 121 | 93 | |
| 122 | 94 | function readPersistedState(): AppState { |
| 123 | − if (typeof window === "undefined") return initialState; | |
| 124 | − | |
| 125 | − try { | |
| 126 | − const rawCurrent = window.localStorage.getItem(PERSISTED_STATE_KEY); | |
| 127 | − const legacyValues = LEGACY_PERSISTED_STATE_KEYS.map((key) => window.localStorage.getItem(key)); | |
| 128 | − const rawLegacy = legacyValues.find((value) => value !== null) ?? null; | |
| 129 | − const raw = rawCurrent ?? rawLegacy; | |
| 130 | − if (!raw) return initialState; | |
| 131 | − const rawCodethingV1 = window.localStorage.getItem("codething:renderer-state:v1"); | |
| 132 | − const hydrated = hydratePersistedState(raw, !rawCurrent && raw === rawCodethingV1); | |
| 133 | − if (!hydrated) return initialState; | |
| 134 | − | |
| 135 | − const threads = hydrated.threads.map((thread) => normalizeThreadTerminals(thread)); | |
| 136 | − | |
| 137 | − return { | |
| 138 | − ...hydrated, | |
| 139 | − threads, | |
| 140 | − threadsHydrated: threads.length > 0, | |
| 141 | − }; | |
| 142 | − } catch { | |
| 143 | − return initialState; | |
| 144 | − } | |
| 95 | + return initialState; | |
| 145 | 96 | } |
| 146 | 97 | |
| 147 | 98 | function persistState(state: AppState): void { |
| 148 | − if (typeof window === "undefined") return; | |
| 149 | − | |
| 150 | − try { | |
| 151 | − window.localStorage.setItem(PERSISTED_STATE_KEY, JSON.stringify(toPersistedState(state))); | |
| 152 | − for (const legacyKey of LEGACY_PERSISTED_STATE_KEYS) { | |
| 153 | − window.localStorage.removeItem(legacyKey); | |
| 154 | − } | |
| 155 | − } catch { | |
| 156 | − // Ignore quota/storage errors to avoid breaking chat UX. | |
| 157 | − } | |
| 99 | + void state; | |
| 158 | 100 | } |
| 159 | 101 | |
| 160 | 102 | function updateThread( |
| @@ -165,64 +107,6 @@ function updateThread( · 4 unmodified lines | ||
| 165 | 107 | return threads.map((t) => (t.id === threadId ? updater(t) : t)); |
| 166 | 108 | } |
| 167 | 109 | |
| 168 | −function mergeTurnDiffSummaries( | |
| 169 | − existing: Thread["turnDiffSummaries"], | |
| 170 | − next: Thread["turnDiffSummaries"], | |
| 171 | −): Thread["turnDiffSummaries"] { | |
| 172 | − if (next.length === 0) return existing; | |
| 173 | − | |
| 174 | − const existingByTurnId = new Map(existing.map((summary) => [summary.turnId, summary] as const)); | |
| 175 | − const merged = next.map((summary) => { | |
| 176 | − const previous = existingByTurnId.get(summary.turnId); | |
| 177 | − if (!previous) { | |
| 178 | − return summary; | |
| 179 | − } | |
| 180 | − | |
| 181 | − const files = | |
| 182 | − summary.files.length === 0 && previous.files.length > 0 ? previous.files : summary.files; | |
| 183 | − | |
| 184 | − return { | |
| 185 | − ...summary, | |
| 186 | − files, | |
| 187 | − ...(summary.assistantMessageId | |
| 188 | − ? {} | |
| 189 | − : previous.assistantMessageId | |
| 190 | − ? { assistantMessageId: previous.assistantMessageId } | |
| 191 | − : {}), | |
| 192 | − ...(typeof summary.checkpointTurnCount === "number" | |
| 193 | − ? {} | |
| 194 | − : typeof previous.checkpointTurnCount === "number" | |
| 195 | − ? { checkpointTurnCount: previous.checkpointTurnCount } | |
| 196 | − : {}), | |
| 197 | − }; | |
| 198 | − }); | |
| 199 | − | |
| 200 | − const mergedTurnIds = new Set(merged.map((summary) => summary.turnId)); | |
| 201 | − for (const summary of existing) { | |
| 202 | − if (!mergedTurnIds.has(summary.turnId)) { | |
| 203 | − merged.push(summary); | |
| 204 | − } | |
| 205 | − } | |
| 206 | − | |
| 207 | − const sorted = merged.toSorted((a, b) => { | |
| 208 | − const aTime = Date.parse(a.completedAt); | |
| 209 | − const bTime = Date.parse(b.completedAt); | |
| 210 | − if (Number.isNaN(aTime) || Number.isNaN(bTime)) { | |
| 211 | − return b.completedAt.localeCompare(a.completedAt); | |
| 212 | − } | |
| 213 | − return bTime - aTime; | |
| 214 | − }); | |
| 215 | − | |
| 216 | − const inferredTurnCountByTurnId = inferCheckpointTurnCountByTurnId(sorted); | |
| 217 | − return sorted.map((summary) => | |
| 218 | − typeof summary.checkpointTurnCount === "number" | |
| 219 | − ? summary | |
| 220 | − : Object.assign({}, summary, { | |
| 221 | − checkpointTurnCount: inferredTurnCountByTurnId[summary.turnId], | |
| 222 | − }), | |
| 223 | − ); | |
| 224 | −} | |
| 225 | − | |
| 226 | 110 | function normalizeTerminalIds(terminalIds: string[]): string[] { |
| 227 | 111 | const ids = terminalIds.map((id) => id.trim()).filter((id) => id.length > 0); |
| 228 | 112 | const unique = [...new Set(ids)].slice(0, MAX_THREAD_TERMINAL_COUNT); |
| @@ -409,93 +293,16 @@ function closeThreadTerminal(thread: Thread, terminalId: string): Thread { · 180 unmodified lines | ||
| 409 | 293 | }); |
| 410 | 294 | } |
| 411 | 295 | |
| 412 | −function findThreadBySessionId(threads: Thread[], sessionId: string): Thread | undefined { | |
| 413 | − return threads.find((t) => t.session?.sessionId === sessionId); | |
| 414 | −} | |
| 415 | − | |
| 416 | −function getEventTurnId(event: ProviderEvent): string | undefined { | |
| 417 | − if (event.turnId) return event.turnId; | |
| 418 | − const payload = asObject(event.payload); | |
| 419 | − const turn = asObject(payload?.turn); | |
| 420 | − return asString(turn?.id); | |
| 421 | −} | |
| 422 | − | |
| 423 | −function getEventThreadId(event: ProviderEvent): string | undefined { | |
| 424 | − if (event.threadId) return event.threadId; | |
| 425 | − const payload = asObject(event.payload); | |
| 426 | − const payloadThread = asObject(payload?.thread); | |
| 427 | − const payloadMessage = asObject(payload?.msg); | |
| 428 | − return ( | |
| 429 | − asString(payload?.threadId) ?? | |
| 430 | − asString(payloadThread?.id) ?? | |
| 431 | − asString(payload?.conversationId) ?? | |
| 432 | − asString(payload?.thread_id) ?? | |
| 433 | − asString(payloadMessage?.thread_id) | |
| 434 | − ); | |
| 435 | −} | |
| 436 | − | |
| 437 | −function shouldIgnoreForeignThreadEvent(thread: Thread, event: ProviderEvent): boolean { | |
| 438 | − const eventThreadId = getEventThreadId(event); | |
| 439 | − if (!eventThreadId) { | |
| 440 | − return false; | |
| 441 | − } | |
| 442 | − | |
| 443 | − const expectedThreadId = thread.session?.threadId ?? thread.codexThreadId; | |
| 444 | − if (!expectedThreadId || eventThreadId === expectedThreadId) { | |
| 445 | − return false; | |
| 446 | − } | |
| 447 | − | |
| 448 | − // During connect, accept a thread/started notification as an identity rebind. | |
| 449 | − if (event.method === "thread/started" && thread.session?.status === "connecting") { | |
| 450 | − return false; | |
| 451 | − } | |
| 452 | − | |
| 453 | − return true; | |
| 454 | −} | |
| 455 | − | |
| 456 | −function durationMs(startIso: string, endIso: string): number | undefined { | |
| 457 | − const start = Date.parse(startIso); | |
| 458 | − const end = Date.parse(endIso); | |
| 459 | − if (Number.isNaN(start) || Number.isNaN(end) || end < start) { | |
| 460 | − return undefined; | |
| 461 | − } | |
| 462 | − | |
| 463 | − return end - start; | |
| 464 | −} | |
| 465 | − | |
| 466 | −function updateTurnFields(thread: Thread, event: ProviderEvent): Partial<Thread> { | |
| 467 | − if (event.method === "turn/started") { | |
| 468 | − return { | |
| 469 | − latestTurnId: getEventTurnId(event) ?? thread.latestTurnId, | |
| 470 | − latestTurnStartedAt: event.createdAt, | |
| 471 | − latestTurnCompletedAt: undefined, | |
| 472 | − latestTurnDurationMs: undefined, | |
| 473 | − }; | |
| 474 | − } | |
| 475 | − | |
| 476 | − if (event.method === "turn/completed") { | |
| 477 | − const completedTurnId = getEventTurnId(event) ?? thread.latestTurnId; | |
| 478 | − const startedAt = | |
| 479 | − completedTurnId && completedTurnId === thread.latestTurnId | |
| 480 | − ? thread.latestTurnStartedAt | |
| 481 | − : undefined; | |
| 482 | − const elapsed = | |
| 483 | − startedAt && startedAt.length > 0 ? durationMs(startedAt, event.createdAt) : undefined; | |
| 484 | − | |
| 485 | − return { | |
| 486 | − latestTurnId: completedTurnId ?? thread.latestTurnId, | |
| 487 | − latestTurnCompletedAt: event.createdAt, | |
| 488 | − latestTurnDurationMs: elapsed, | |
| 489 | − }; | |
| 490 | − } | |
| 491 | − | |
| 492 | − return {}; | |
| 493 | −} | |
| 494 | − | |
| 495 | 296 | // ── Reducer ────────────────────────────────────────────────────────── |
| 496 | 297 | |
| 497 | 298 | export function reducer(state: AppState, action: Action): AppState { |
| 498 | 299 | switch (action.type) { |
| 300 | + case "SET_SERVER_STATE": | |
| 301 | + return { | |
| 302 | + ...action.state, | |
| 303 | + threads: action.state.threads.map((thread) => normalizeThreadTerminals(thread)), | |
| 304 | + }; | |
| 305 | + | |
| 499 | 306 | case "ADD_PROJECT": |
| 500 | 307 | if (state.projects.some((project) => project.cwd === action.project.cwd)) { |
| 501 | 308 | return state; |
| @@ -774,81 +581,6 @@ export function reducer(state: AppState, action: Action): AppState { · 272 unmodified lines | ||
| 774 | 581 | ), |
| 775 | 582 | }; |
| 776 | 583 | |
| 777 | − case "APPLY_TERMINAL_EVENT": | |
| 778 | − if (!state.threads.some((thread) => thread.id === action.event.threadId)) { | |
| 779 | − return state; | |
| 780 | − } | |
| 781 | − return { | |
| 782 | − ...state, | |
| 783 | − threads: updateThread(state.threads, action.event.threadId, (thread) => { | |
| 784 | − const normalizedThread = normalizeThreadTerminals(thread); | |
| 785 | − const runningTerminalIdSet = new Set(normalizedThread.runningTerminalIds); | |
| 786 | − if (action.event.type === "started" || action.event.type === "restarted") { | |
| 787 | − runningTerminalIdSet.delete(action.event.terminalId); | |
| 788 | − } else if (action.event.type === "activity") { | |
| 789 | − if (action.event.hasRunningSubprocess) { | |
| 790 | − runningTerminalIdSet.add(action.event.terminalId); | |
| 791 | − } else { | |
| 792 | − runningTerminalIdSet.delete(action.event.terminalId); | |
| 793 | − } | |
| 794 | − } else if (action.event.type === "exited" || action.event.type === "error") { | |
| 795 | − runningTerminalIdSet.delete(action.event.terminalId); | |
| 796 | − } | |
| 797 | − | |
| 798 | − return normalizeThreadTerminals({ | |
| 799 | − ...normalizedThread, | |
| 800 | − runningTerminalIds: [...runningTerminalIdSet], | |
| 801 | − }); | |
| 802 | − }), | |
| 803 | − }; | |
| 804 | − | |
| 805 | − case "APPLY_EVENT": { | |
| 806 | − const { event, activeAssistantItemRef, activeThreadId } = action; | |
| 807 | − const target = findThreadBySessionId(state.threads, event.sessionId); | |
| 808 | − if (!target) return state; | |
| 809 | − if (shouldIgnoreForeignThreadEvent(target, event)) return state; | |
| 810 | − | |
| 811 | − return { | |
| 812 | − ...state, | |
| 813 | − threads: updateThread(state.threads, target.id, (t) => { | |
| 814 | − const nextEvents = [event, ...t.events]; | |
| 815 | − const eventTurnId = getEventTurnId(event); | |
| 816 | − const hasCompletedSummaryForTurn = Boolean( | |
| 817 | − eventTurnId && t.turnDiffSummaries.some((summary) => summary.turnId === eventTurnId), | |
| 818 | − ); | |
| 819 | − const itemType = asString(asObject(asObject(event.payload)?.item)?.type); | |
| 820 | − const normalizedItemType = itemType?.replace(/[_-]/g, "").toLowerCase(); | |
| 821 | − const isMetadataItemCompleted = | |
| 822 | − event.method === "item/completed" && | |
| 823 | − (normalizedItemType === "agentmessage" || normalizedItemType === "filechange"); | |
| 824 | − const shouldRederiveDiffs = | |
| 825 | − event.method === "turn/completed" || | |
| 826 | − (hasCompletedSummaryForTurn && isMetadataItemCompleted); | |
| 827 | − const turnDiffSummaries = shouldRederiveDiffs | |
| 828 | − ? mergeTurnDiffSummaries(t.turnDiffSummaries, deriveTurnDiffSummaries(nextEvents)) | |
| 829 | − : t.turnDiffSummaries; | |
| 830 | − const eventThreadId = getEventThreadId(event); | |
| 831 | − const shouldRebindIdentity = | |
| 832 | − event.method === "thread/started" && t.session?.status === "connecting"; | |
| 833 | − return { | |
| 834 | − ...t, | |
| 835 | − codexThreadId: shouldRebindIdentity | |
| 836 | − ? (eventThreadId ?? t.codexThreadId) | |
| 837 | − : (t.codexThreadId ?? eventThreadId ?? null), | |
| 838 | − error: event.kind === "error" && event.message ? event.message : t.error, | |
| 839 | − session: t.session ? evolveSession(t.session, event) : t.session, | |
| 840 | − messages: applyEventToMessages(t.messages, event, activeAssistantItemRef), | |
| 841 | − events: nextEvents, | |
| 842 | − turnDiffSummaries, | |
| 843 | − ...updateTurnFields(t, event), | |
| 844 | − ...(event.method === "turn/completed" && t.id === activeThreadId | |
| 845 | − ? { lastVisitedAt: event.createdAt } | |
| 846 | − : {}), | |
| 847 | − }; | |
| 848 | − }), | |
| 849 | − }; | |
| 850 | − } | |
| 851 | − | |
| 852 | 584 | case "UPDATE_SESSION": |
| 853 | 585 | return { |
| 854 | 586 | ...state, |
| @@ -1035,10 +767,6 @@ const StoreContext = createContext<{ · 180 unmodified lines | ||
| 1035 | 767 | export function StoreProvider({ children }: { children: ReactNode }) { |
| 1036 | 768 | const [state, dispatch] = useReducer(reducer, undefined, readPersistedState); |
| 1037 | 769 | |
| 1038 | − useEffect(() => { | |
| 1039 | − persistState(state); | |
| 1040 | − }, [state]); | |
| 1041 | − | |
| 1042 | 770 | return createElement(StoreContext.Provider, { value: { state, dispatch } }, children); |
| 1043 | 771 | } |
| 1044 | 772 | |
| @@ -5,7 +5,9 @@ import { WsTransport } from "./wsTransport"; · 4 unmodified lines | ||
| 5 | 5 | |
| 6 | 6 | let instance: { api: NativeApi; transport: WsTransport } | null = null; |
| 7 | 7 | const welcomeListeners = new Set<(payload: WsWelcomePayload) => void>(); |
| 8 | +const stateListeners = new Set<(state: unknown) => void>(); | |
| 8 | 9 | let lastWelcome: WsWelcomePayload | null = null; |
| 10 | +let lastStateSnapshot: unknown = null; | |
| 9 | 11 | |
| 10 | 12 | /** |
| 11 | 13 | * Subscribe to the server welcome message. If a welcome was already received |
| @@ -29,6 +31,20 @@ export function onServerWelcome(listener: (payload: WsWelcomePayload) => void): · 17 unmodified lines | ||
| 29 | 31 | }; |
| 30 | 32 | } |
| 31 | 33 | |
| 34 | +export function onServerStateUpdate(listener: (state: unknown) => void): () => void { | |
| 35 | + stateListeners.add(listener); | |
| 36 | + if (lastStateSnapshot) { | |
| 37 | + try { | |
| 38 | + listener(lastStateSnapshot); | |
| 39 | + } catch { | |
| 40 | + // Swallow listener errors | |
| 41 | + } | |
| 42 | + } | |
| 43 | + return () => { | |
| 44 | + stateListeners.delete(listener); | |
| 45 | + }; | |
| 46 | +} | |
| 47 | + | |
| 32 | 48 | export function createWsNativeApi(): NativeApi { |
| 33 | 49 | if (instance) return instance.api; |
| 34 | 50 | |
| @@ -47,6 +63,16 @@ export function createWsNativeApi(): NativeApi { · 12 unmodified lines | ||
| 47 | 63 | } |
| 48 | 64 | } |
| 49 | 65 | }); |
| 66 | + transport.subscribe(WS_CHANNELS.stateUpdated, (data) => { | |
| 67 | + lastStateSnapshot = data; | |
| 68 | + for (const listener of stateListeners) { | |
| 69 | + try { | |
| 70 | + listener(data); | |
| 71 | + } catch { | |
| 72 | + // Swallow listener errors | |
| 73 | + } | |
| 74 | + } | |
| 75 | + }); | |
| 50 | 76 | |
| 51 | 77 | const api: NativeApi = { |
| 52 | 78 | todos: { |
| @@ -95,8 +121,7 @@ export function createWsNativeApi(): NativeApi { · 42 unmodified lines | ||
| 95 | 121 | getCheckpointDiff: (input) => transport.request(WS_METHODS.providersGetCheckpointDiff, input), |
| 96 | 122 | revertToCheckpoint: (input) => |
| 97 | 123 | transport.request(WS_METHODS.providersRevertToCheckpoint, input), |
| 98 | − onEvent: (callback) => | |
| 99 | − transport.subscribe(WS_CHANNELS.providerEvent, callback as (data: unknown) => void), | |
| 124 | + onEvent: () => () => {}, | |
| 100 | 125 | }, |
| 101 | 126 | projects: { |
| 102 | 127 | list: () => transport.request(WS_METHODS.projectsList), |
| @@ -149,6 +174,13 @@ export function createWsNativeApi(): NativeApi { · 46 unmodified lines | ||
| 149 | 174 | getConfig: () => transport.request(WS_METHODS.serverGetConfig), |
| 150 | 175 | upsertKeybinding: (input) => transport.request(WS_METHODS.serverUpsertKeybinding, input), |
| 151 | 176 | }, |
| 177 | + state: { | |
| 178 | + getSnapshot: () => transport.request(WS_METHODS.stateGetSnapshot), | |
| 179 | + createThread: (input) => transport.request(WS_METHODS.stateCreateThread, input), | |
| 180 | + deleteThread: (input) => transport.request(WS_METHODS.stateDeleteThread, input), | |
| 181 | + markThreadVisited: (input) => transport.request(WS_METHODS.stateMarkThreadVisited, input), | |
| 182 | + setRuntimeMode: (input) => transport.request(WS_METHODS.stateSetRuntimeMode, input), | |
| 183 | + }, | |
| 152 | 184 | }; |
| 153 | 185 | |
| 154 | 186 | instance = { api, transport }; |
| @@ -34,6 +34,9 @@ · 33 unmodified lines | ||
| 34 | 34 | "t3": "./dist/index.mjs", |
| 35 | 35 | }, |
| 36 | 36 | "dependencies": { |
| 37 | + "@t3tools/core": "workspace:*", | |
| 38 | + "@t3tools/infra-sqlite": "workspace:*", | |
| 39 | + "effect": "^3.18.4", | |
| 37 | 40 | "node-pty": "^1.1.0", |
| 38 | 41 | "open": "^10.1.0", |
| 39 | 42 | "ws": "^8.18.0", |
| @@ -94,6 +97,33 @@ · 54 unmodified lines | ||
| 94 | 97 | "typescript": "^5.7.3", |
| 95 | 98 | }, |
| 96 | 99 | }, |
| 100 | + "packages/core": { | |
| 101 | + "name": "@t3tools/core", | |
| 102 | + "version": "0.0.0", | |
| 103 | + "dependencies": { | |
| 104 | + "effect": "^3.18.4", | |
| 105 | + }, | |
| 106 | + "devDependencies": { | |
| 107 | + "@types/node": "^25.3.0", | |
| 108 | + "typescript": "^5.7.3", | |
| 109 | + "vitest": "^4.0.0", | |
| 110 | + }, | |
| 111 | + }, | |
| 112 | + "packages/infra-sqlite": { | |
| 113 | + "name": "@t3tools/infra-sqlite", | |
| 114 | + "version": "0.0.0", | |
| 115 | + "dependencies": { | |
| 116 | + "@effect/sql": "^0.49.0", | |
| 117 | + "@effect/sql-sqlite-node": "^0.50.1", | |
| 118 | + "@t3tools/core": "workspace:*", | |
| 119 | + "effect": "^3.18.4", | |
| 120 | + }, | |
| 121 | + "devDependencies": { | |
| 122 | + "@types/node": "^25.3.0", | |
| 123 | + "typescript": "^5.7.3", | |
| 124 | + "vitest": "^4.0.0", | |
| 125 | + }, | |
| 126 | + }, | |
| 97 | 127 | }, |
| 98 | 128 | "packages": { |
| 99 | 129 | "@babel/code-frame": ["@babel/code-frame@7.29.0", "", { "dependencies": { "@babel/helper-validator-identifier": "^7.28.5", "js-tokens": "^4.0.0", "picocolors": "^1.1.1" } }, "sha512-9NhCeYjq9+3uxgdtp20LSiJXJvN0FeCtNGpJxuMFZ1Kv3cWUNb6DOhJwUvcVCzKGR66cw4njwM6hrJLqgOwbcw=="], |
| @@ -144,6 +174,14 @@ · 44 unmodified lines | ||
| 144 | 174 | |
| 145 | 175 | "@base-ui/utils": ["@base-ui/utils@0.2.5", "", { "dependencies": { "@babel/runtime": "^7.28.6", "@floating-ui/utils": "^0.2.10", "reselect": "^5.1.1", "use-sync-external-store": "^1.6.0" }, "peerDependencies": { "@types/react": "^17 || ^18 || ^19", "react": "^17 || ^18 || ^19", "react-dom": "^17 || ^18 || ^19" }, "optionalPeers": ["@types/react"] }, "sha512-oYC7w0gp76RI5MxprlGLV0wze0SErZaRl3AAkeP3OnNB/UBMb6RqNf6ZSIlxOc9Qp68Ab3C2VOcJQyRs7Xc7Vw=="], |
| 146 | 176 | |
| 177 | + "@effect/experimental": ["@effect/experimental@0.58.0", "", { "dependencies": { "uuid": "^11.0.3" }, "peerDependencies": { "@effect/platform": "^0.94.0", "effect": "^3.19.13", "ioredis": "^5", "lmdb": "^3" }, "optionalPeers": ["ioredis", "lmdb"] }, "sha512-IEP9sapjF6rFy5TkoqDPc86st/fnqUfjT7Xa3pWJrFGr1hzaMXHo+mWsYOZS9LAOVKnpHuVziDK97EP5qsCHVA=="], | |
| 178 | + | |
| 179 | + "@effect/platform": ["@effect/platform@0.94.5", "", { "dependencies": { "find-my-way-ts": "^0.1.6", "msgpackr": "^1.11.4", "multipasta": "^0.2.7" }, "peerDependencies": { "effect": "^3.19.17" } }, "sha512-z05APUiDDPbodhTkH/RJqOLoCU11bU2IZLfcwLFrld03+ob1VeqRnELQlmueLIYm6NZifHAtjl32V+GRt34y4A=="], | |
| 180 | + | |
| 181 | + "@effect/sql": ["@effect/sql@0.49.0", "", { "dependencies": { "uuid": "^11.0.3" }, "peerDependencies": { "@effect/experimental": "^0.58.0", "@effect/platform": "^0.94.0", "effect": "^3.19.13" } }, "sha512-9UEKR+z+MrI/qMAmSvb/RiD9KlgIazjZUCDSpwNgm0lEK9/Q6ExEyfziiYFVCPiptp52cBw8uBHRic8hHnwqXA=="], | |
| 182 | + | |
| 183 | + "@effect/sql-sqlite-node": ["@effect/sql-sqlite-node@0.50.1", "", { "dependencies": { "better-sqlite3": "^12.6.2" }, "peerDependencies": { "@effect/experimental": "^0.58.0", "@effect/platform": "^0.94.4", "@effect/sql": "^0.49.0", "effect": "^3.19.16" } }, "sha512-L7DlHcOVl9/9V5stttFyv9wjvA9PBbaXwsp9pU+KN8KqokWgAVBNBEDf/dVfboUrynbDpDWwMU9SJmRJ1LXASQ=="], | |
| 184 | + | |
| 147 | 185 | "@electron/get": ["@electron/get@2.0.3", "", { "dependencies": { "debug": "^4.1.1", "env-paths": "^2.2.0", "fs-extra": "^8.1.0", "got": "^11.8.5", "progress": "^2.0.3", "semver": "^6.2.0", "sumchecker": "^3.0.1" }, "optionalDependencies": { "global-agent": "^3.0.0" } }, "sha512-Qkzpg2s9GnVV2I2BjRksUi43U5e6+zaQMcjoJy0C+C5oxaKl+fmckGDQFtRpZpZV0NQekuZZ+tGz7EA9TVnQtQ=="], |
| 148 | 186 | |
| 149 | 187 | "@emnapi/core": ["@emnapi/core@1.8.1", "", { "dependencies": { "@emnapi/wasi-threads": "1.1.0", "tslib": "^2.4.0" } }, "sha512-AvT9QFpxK0Zd8J0jopedNm+w/2fIzvtPKPjqyw9jwvBaReTTqPBk9Hixaz7KbjimP+QNz605/XnjFcDAL2pqBg=="], |
| @@ -244,6 +282,18 @@ · 94 unmodified lines | ||
| 244 | 282 | |
| 245 | 283 | "@jridgewell/trace-mapping": ["@jridgewell/trace-mapping@0.3.31", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw=="], |
| 246 | 284 | |
| 285 | + "@msgpackr-extract/msgpackr-extract-darwin-arm64": ["@msgpackr-extract/msgpackr-extract-darwin-arm64@3.0.3", "", { "os": "darwin", "cpu": "arm64" }, "sha512-QZHtlVgbAdy2zAqNA9Gu1UpIuI8Xvsd1v8ic6B2pZmeFnFcMWiPLfWXh7TVw4eGEZ/C9TH281KwhVoeQUKbyjw=="], | |
| 286 | + | |
| 287 | + "@msgpackr-extract/msgpackr-extract-darwin-x64": ["@msgpackr-extract/msgpackr-extract-darwin-x64@3.0.3", "", { "os": "darwin", "cpu": "x64" }, "sha512-mdzd3AVzYKuUmiWOQ8GNhl64/IoFGol569zNRdkLReh6LRLHOXxU4U8eq0JwaD8iFHdVGqSy4IjFL4reoWCDFw=="], | |
| 288 | + | |
| 289 | + "@msgpackr-extract/msgpackr-extract-linux-arm": ["@msgpackr-extract/msgpackr-extract-linux-arm@3.0.3", "", { "os": "linux", "cpu": "arm" }, "sha512-fg0uy/dG/nZEXfYilKoRe7yALaNmHoYeIoJuJ7KJ+YyU2bvY8vPv27f7UKhGRpY6euFYqEVhxCFZgAUNQBM3nw=="], | |
| 290 | + | |
| 291 | + "@msgpackr-extract/msgpackr-extract-linux-arm64": ["@msgpackr-extract/msgpackr-extract-linux-arm64@3.0.3", "", { "os": "linux", "cpu": "arm64" }, "sha512-YxQL+ax0XqBJDZiKimS2XQaf+2wDGVa1enVRGzEvLLVFeqa5kx2bWbtcSXgsxjQB7nRqqIGFIcLteF/sHeVtQg=="], | |
| 292 | + | |
| 293 | + "@msgpackr-extract/msgpackr-extract-linux-x64": ["@msgpackr-extract/msgpackr-extract-linux-x64@3.0.3", "", { "os": "linux", "cpu": "x64" }, "sha512-cvwNfbP07pKUfq1uH+S6KJ7dT9K8WOE4ZiAcsrSes+UY55E/0jLYc+vq+DO7jlmqRb5zAggExKm0H7O/CBaesg=="], | |
| 294 | + | |
| 295 | + "@msgpackr-extract/msgpackr-extract-win32-x64": ["@msgpackr-extract/msgpackr-extract-win32-x64@3.0.3", "", { "os": "win32", "cpu": "x64" }, "sha512-x0fWaQtYp4E6sktbsdAqnehxDgEc/VwM7uLsRCYWaiGu0ykYdZPiS8zCWdnjHwyiumousxfBm4SO31eXqwEZhQ=="], | |
| 296 | + | |
| 247 | 297 | "@mswjs/interceptors": ["@mswjs/interceptors@0.41.3", "", { "dependencies": { "@open-draft/deferred-promise": "^2.2.0", "@open-draft/logger": "^0.3.0", "@open-draft/until": "^2.0.0", "is-node-process": "^1.2.0", "outvariant": "^1.4.3", "strict-event-emitter": "^0.5.1" } }, "sha512-cXu86tF4VQVfwz8W1SPbhoRyHJkti6mjH/XJIxp40jhO4j2k1m4KYrEykxqWPkFF3vrK4rgQppBh//AwyGSXPA=="], |
| 248 | 298 | |
| 249 | 299 | "@napi-rs/wasm-runtime": ["@napi-rs/wasm-runtime@1.1.1", "", { "dependencies": { "@emnapi/core": "^1.7.1", "@emnapi/runtime": "^1.7.1", "@tybys/wasm-util": "^0.10.1" } }, "sha512-p64ah1M1ld8xjWv3qbvFwHiFVWrq1yFvV4f7w+mzaqiR4IlSgkqhcRdHwsGgomwzBH51sRY4NEowLxnaBjcW/A=="], |
| @@ -418,8 +468,12 @@ · 168 unmodified lines | ||
| 418 | 468 | |
| 419 | 469 | "@t3tools/contracts": ["@t3tools/contracts@workspace:packages/contracts"], |
| 420 | 470 | |
| 471 | + "@t3tools/core": ["@t3tools/core@workspace:packages/core"], | |
| 472 | + | |
| 421 | 473 | "@t3tools/desktop": ["@t3tools/desktop@workspace:apps/desktop"], |
| 422 | 474 | |
| 475 | + "@t3tools/infra-sqlite": ["@t3tools/infra-sqlite@workspace:packages/infra-sqlite"], | |
| 476 | + | |
| 423 | 477 | "@t3tools/web": ["@t3tools/web@workspace:apps/web"], |
| 424 | 478 | |
| 425 | 479 | "@tailwindcss/node": ["@tailwindcss/node@4.1.18", "", { "dependencies": { "@jridgewell/remapping": "^2.3.4", "enhanced-resolve": "^5.18.3", "jiti": "^2.6.1", "lightningcss": "1.30.2", "magic-string": "^0.30.21", "source-map-js": "^1.2.1", "tailwindcss": "4.1.18" } }, "sha512-DoR7U1P7iYhw16qJ49fgXUlry1t4CpXeErJHnQ44JgTSKMaZUdf17cfn5mHchfJ4KRBZRFA/Coo+MUF5+gOaCQ=="], |
| @@ -518,7 +572,7 @@ · 92 unmodified lines | ||
| 518 | 572 | |
| 519 | 573 | "@types/ms": ["@types/ms@2.1.0", "", {}, "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA=="], |
| 520 | 574 | |
| 521 | − "@types/node": ["@types/node@22.19.11", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-BH7YwL6rA93ReqeQS1c4bsPpcfOmJasG+Fkr6Y59q83f9M1WcBRHR2vM+P9eOisYRcN3ujQoiZY8uk5W+1WL8w=="], | |
| 575 | + "@types/node": ["@types/node@25.3.0", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-4K3bqJpXpqfg2XKGK9bpDTc6xO/xoUP/RBWS7AtRMug6zZFaRekiLzjVtAoZMquxoAbzBvy5nxQ7veS5eYzf8A=="], | |
| 522 | 576 | |
| 523 | 577 | "@types/react": ["@types/react@19.2.14", "", { "dependencies": { "csstype": "^3.2.2" } }, "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w=="], |
| 524 | 578 | |
| @@ -582,18 +636,28 @@ · 57 unmodified lines | ||
| 582 | 636 | |
| 583 | 637 | "bail": ["bail@2.0.2", "", {}, "sha512-0xO6mYd7JB2YesxDKplafRpsiOzPt9V02ddPCLbY1xYGPOX24NTyN50qnUxgCPcSoYMhKpAuBTjQoRZCAkUDRw=="], |
| 584 | 638 | |
| 639 | + "base64-js": ["base64-js@1.5.1", "", {}, "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="], | |
| 640 | + | |
| 585 | 641 | "baseline-browser-mapping": ["baseline-browser-mapping@2.9.19", "", { "bin": { "baseline-browser-mapping": "dist/cli.js" } }, "sha512-ipDqC8FrAl/76p2SSWKSI+H9tFwm7vYqXQrItCuiVPt26Km0jS+NzSsBWAaBusvSbQcfJG+JitdMm+wZAgTYqg=="], |
| 586 | 642 | |
| 643 | + "better-sqlite3": ["better-sqlite3@12.6.2", "", { "dependencies": { "bindings": "^1.5.0", "prebuild-install": "^7.1.1" } }, "sha512-8VYKM3MjCa9WcaSAI3hzwhmyHVlH8tiGFwf0RlTsZPWJ1I5MkzjiudCo4KC4DxOaL/53A5B1sI/IbldNFDbsKA=="], | |
| 644 | + | |
| 587 | 645 | "binary-extensions": ["binary-extensions@2.3.0", "", {}, "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw=="], |
| 588 | 646 | |
| 647 | + "bindings": ["bindings@1.5.0", "", { "dependencies": { "file-uri-to-path": "1.0.0" } }, "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ=="], | |
| 648 | + | |
| 589 | 649 | "birpc": ["birpc@4.0.0", "", {}, "sha512-LShSxJP0KTmd101b6DRyGBj57LZxSDYWKitQNW/mi8GRMvZb078Uf9+pveax1DrVL89vm7mWe+TovdI/UDOuPw=="], |
| 590 | 650 | |
| 651 | + "bl": ["bl@4.1.0", "", { "dependencies": { "buffer": "^5.5.0", "inherits": "^2.0.4", "readable-stream": "^3.4.0" } }, "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w=="], | |
| 652 | + | |
| 591 | 653 | "boolean": ["boolean@3.2.0", "", {}, "sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw=="], |
| 592 | 654 | |
| 593 | 655 | "braces": ["braces@3.0.3", "", { "dependencies": { "fill-range": "^7.1.1" } }, "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA=="], |
| 594 | 656 | |
| 595 | 657 | "browserslist": ["browserslist@4.28.1", "", { "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", "electron-to-chromium": "^1.5.263", "node-releases": "^2.0.27", "update-browserslist-db": "^1.2.0" }, "bin": { "browserslist": "cli.js" } }, "sha512-ZC5Bd0LgJXgwGqUknZY/vkUQ04r8NXnJZ3yYi4vDmSiZmC/pdSN0NbNRPxZpbtO4uAfDUAFffO8IZoM3Gj8IkA=="], |
| 596 | 658 | |
| 659 | + "buffer": ["buffer@5.7.1", "", { "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ=="], | |
| 660 | + | |
| 597 | 661 | "buffer-crc32": ["buffer-crc32@0.2.13", "", {}, "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ=="], |
| 598 | 662 | |
| 599 | 663 | "bundle-name": ["bundle-name@4.1.0", "", { "dependencies": { "run-applescript": "^7.0.0" } }, "sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q=="], |
| @@ -624,6 +688,8 @@ · 24 unmodified lines | ||
| 624 | 688 | |
| 625 | 689 | "chokidar": ["chokidar@3.6.0", "", { "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", "normalize-path": "~3.0.0", "readdirp": "~3.6.0" }, "optionalDependencies": { "fsevents": "~2.3.2" } }, "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw=="], |
| 626 | 690 | |
| 691 | + "chownr": ["chownr@1.1.4", "", {}, "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg=="], | |
| 692 | + | |
| 627 | 693 | "class-variance-authority": ["class-variance-authority@0.7.1", "", { "dependencies": { "clsx": "^2.1.1" } }, "sha512-Ka+9Trutv7G8M6WT6SeiRWz792K5qEqIGEGzXKhAE6xOWAY6pPH8U+9IY3oCMv6kqTmLsv7Xh/2w2RigkePMsg=="], |
| 628 | 694 | |
| 629 | 695 | "cli-width": ["cli-width@4.1.0", "", {}, "sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ=="], |
| @@ -656,6 +722,8 @@ · 26 unmodified lines | ||
| 656 | 722 | |
| 657 | 723 | "decompress-response": ["decompress-response@6.0.0", "", { "dependencies": { "mimic-response": "^3.1.0" } }, "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ=="], |
| 658 | 724 | |
| 725 | + "deep-extend": ["deep-extend@0.6.0", "", {}, "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA=="], | |
| 726 | + | |
| 659 | 727 | "default-browser": ["default-browser@5.5.0", "", { "dependencies": { "bundle-name": "^4.1.0", "default-browser-id": "^5.0.0" } }, "sha512-H9LMLr5zwIbSxrmvikGuI/5KGhZ8E2zH3stkMgM5LpOWDutGM2JZaj460Udnf1a+946zc7YBgrqEWwbk7zHvGw=="], |
| 660 | 728 | |
| 661 | 729 | "default-browser-id": ["default-browser-id@5.0.1", "", {}, "sha512-x1VCxdX4t+8wVfd1so/9w+vQ4vx7lKd2Qp5tDRutErwmR85OgmfX7RlLRMWafRMY7hbEiXIbudNrjOAPa/hL8Q=="], |
| @@ -686,6 +754,8 @@ · 24 unmodified lines | ||
| 686 | 754 | |
| 687 | 755 | "dunder-proto": ["dunder-proto@1.0.1", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", "gopd": "^1.2.0" } }, "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A=="], |
| 688 | 756 | |
| 757 | + "effect": ["effect@3.19.19", "", { "dependencies": { "@standard-schema/spec": "^1.0.0", "fast-check": "^3.23.1" } }, "sha512-Yc8U/SVXo2dHnaP7zNBlAo83h/nzSJpi7vph6Hzyl4ulgMBIgPmz3UzOjb9sBgpFE00gC0iETR244sfXDNLHRg=="], | |
| 758 | + | |
| 689 | 759 | "electron": ["electron@40.6.0", "", { "dependencies": { "@electron/get": "^2.0.0", "@types/node": "^24.9.0", "extract-zip": "^2.0.1" }, "bin": { "electron": "cli.js" } }, "sha512-ett8W+yOFGDuM0vhJMamYSkrbV3LoaffzJd9GfjI96zRAxyrNqUSKqBpf/WGbQCweDxX2pkUCUfrv4wwKpsFZA=="], |
| 690 | 760 | |
| 691 | 761 | "electron-to-chromium": ["electron-to-chromium@1.5.286", "", {}, "sha512-9tfDXhJ4RKFNerfjdCcZfufu49vg620741MNs26a9+bhLThdB+plgMeou98CAaHu/WATj2iHOOHTp1hWtABj2A=="], |
| @@ -726,22 +796,32 @@ · 34 unmodified lines | ||
| 726 | 796 | |
| 727 | 797 | "estree-walker": ["estree-walker@3.0.3", "", { "dependencies": { "@types/estree": "^1.0.0" } }, "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g=="], |
| 728 | 798 | |
| 799 | + "expand-template": ["expand-template@2.0.3", "", {}, "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg=="], | |
| 800 | + | |
| 729 | 801 | "expect-type": ["expect-type@1.3.0", "", {}, "sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA=="], |
| 730 | 802 | |
| 731 | 803 | "extend": ["extend@3.0.2", "", {}, "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g=="], |
| 732 | 804 | |
| 733 | 805 | "extract-zip": ["extract-zip@2.0.1", "", { "dependencies": { "debug": "^4.1.1", "get-stream": "^5.1.0", "yauzl": "^2.10.0" }, "optionalDependencies": { "@types/yauzl": "^2.9.1" }, "bin": { "extract-zip": "cli.js" } }, "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg=="], |
| 734 | 806 | |
| 807 | + "fast-check": ["fast-check@3.23.2", "", { "dependencies": { "pure-rand": "^6.1.0" } }, "sha512-h5+1OzzfCC3Ef7VbtKdcv7zsstUQwUDlYpUTvjeUsJAssPgLn7QzbboPtL5ro04Mq0rPOsMzl7q5hIbRs2wD1A=="], | |
| 808 | + | |
| 735 | 809 | "fd-slicer": ["fd-slicer@1.1.0", "", { "dependencies": { "pend": "~1.2.0" } }, "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g=="], |
| 736 | 810 | |
| 737 | 811 | "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], |
| 738 | 812 | |
| 813 | + "file-uri-to-path": ["file-uri-to-path@1.0.0", "", {}, "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="], | |
| 814 | + | |
| 739 | 815 | "fill-range": ["fill-range@7.1.1", "", { "dependencies": { "to-regex-range": "^5.0.1" } }, "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg=="], |
| 740 | 816 | |
| 817 | + "find-my-way-ts": ["find-my-way-ts@0.1.6", "", {}, "sha512-a85L9ZoXtNAey3Y6Z+eBWW658kO/MwR7zIafkIUPUMf3isZG0NCs2pjW2wtjxAKuJPxMAsHUIP4ZPGv0o5gyTA=="], | |
| 818 | + | |
| 741 | 819 | "follow-redirects": ["follow-redirects@1.15.11", "", {}, "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ=="], |
| 742 | 820 | |
| 743 | 821 | "form-data": ["form-data@4.0.5", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "hasown": "^2.0.2", "mime-types": "^2.1.12" } }, "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w=="], |
| 744 | 822 | |
| 823 | + "fs-constants": ["fs-constants@1.0.0", "", {}, "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow=="], | |
| 824 | + | |
| 745 | 825 | "fs-extra": ["fs-extra@8.1.0", "", { "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^4.0.0", "universalify": "^0.1.0" } }, "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g=="], |
| 746 | 826 | |
| 747 | 827 | "fsevents": ["fsevents@2.3.3", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], |
| @@ -760,6 +840,8 @@ · 12 unmodified lines | ||
| 760 | 840 | |
| 761 | 841 | "get-tsconfig": ["get-tsconfig@4.13.6", "", { "dependencies": { "resolve-pkg-maps": "^1.0.0" } }, "sha512-shZT/QMiSHc/YBLxxOkMtgSid5HFoauqCE3/exfsEcwg1WkeqjG+V40yBbBrsD+jW2HDXcs28xOfcbm2jI8Ddw=="], |
| 762 | 842 | |
| 843 | + "github-from-package": ["github-from-package@0.0.0", "", {}, "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw=="], | |
| 844 | + | |
| 763 | 845 | "glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="], |
| 764 | 846 | |
| 765 | 847 | "global-agent": ["global-agent@3.0.0", "", { "dependencies": { "boolean": "^3.0.1", "es6-error": "^4.1.1", "matcher": "^3.0.0", "roarr": "^2.15.3", "semver": "^7.3.2", "serialize-error": "^7.0.1" } }, "sha512-PT6XReJ+D07JvGoxQMkT6qji/jVNfX/h364XHZOWeRzy64sSFr+xJ5OX7LI3b4MPQzdL4H8Y8M0xzPpsVMwA8Q=="], |
| @@ -808,10 +890,16 @@ · 42 unmodified lines | ||
| 808 | 890 | |
| 809 | 891 | "http2-wrapper": ["http2-wrapper@1.0.3", "", { "dependencies": { "quick-lru": "^5.1.1", "resolve-alpn": "^1.0.0" } }, "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg=="], |
| 810 | 892 | |
| 893 | + "ieee754": ["ieee754@1.2.1", "", {}, "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="], | |
| 894 | + | |
| 811 | 895 | "import-from": ["import-from@3.0.0", "", { "dependencies": { "resolve-from": "^5.0.0" } }, "sha512-CiuXOFFSzkU5x/CR0+z7T91Iht4CXgfCxVOFRhh2Zyhg5wOpWvvDLQUsWl+gcN+QscYBjez8hDCt85O7RLDttQ=="], |
| 812 | 896 | |
| 813 | 897 | "import-without-cache": ["import-without-cache@0.2.5", "", {}, "sha512-B6Lc2s6yApwnD2/pMzFh/d5AVjdsDXjgkeJ766FmFuJELIGHNycKRj+l3A39yZPM4CchqNCB4RITEAYB1KUM6A=="], |
| 814 | 898 | |
| 899 | + "inherits": ["inherits@2.0.4", "", {}, "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="], | |
| 900 | + | |
| 901 | + "ini": ["ini@1.3.8", "", {}, "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew=="], | |
| 902 | + | |
| 815 | 903 | "inline-style-parser": ["inline-style-parser@0.2.7", "", {}, "sha512-Nb2ctOyNR8DqQoR0OwRG95uNWIC0C1lCgf5Naz5H6Ji72KZ8OcFZLz2P5sNgwlyoJ8Yif11oMuYs5pBQa86csA=="], |
| 816 | 904 | |
| 817 | 905 | "is-alphabetical": ["is-alphabetical@2.0.1", "", {}, "sha512-FWyyY60MeTNyeSRpkM2Iry0G9hpr7/9kD40mD/cGQEuilcZYS4okz8SN2Q6rLCJ8gbCt6fN+rC+6tMGS99LaxQ=="], |
| @@ -1006,16 +1094,30 @@ · 188 unmodified lines | ||
| 1006 | 1094 | |
| 1007 | 1095 | "minimist": ["minimist@1.2.8", "", {}, "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="], |
| 1008 | 1096 | |
| 1097 | + "mkdirp-classic": ["mkdirp-classic@0.5.3", "", {}, "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A=="], | |
| 1098 | + | |
| 1009 | 1099 | "ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="], |
| 1010 | 1100 | |
| 1101 | + "msgpackr": ["msgpackr@1.11.8", "", { "optionalDependencies": { "msgpackr-extract": "^3.0.2" } }, "sha512-bC4UGzHhVvgDNS7kn9tV8fAucIYUBuGojcaLiz7v+P63Lmtm0Xeji8B/8tYKddALXxJLpwIeBmUN3u64C4YkRA=="], | |
| 1102 | + | |
| 1103 | + "msgpackr-extract": ["msgpackr-extract@3.0.3", "", { "dependencies": { "node-gyp-build-optional-packages": "5.2.2" }, "optionalDependencies": { "@msgpackr-extract/msgpackr-extract-darwin-arm64": "3.0.3", "@msgpackr-extract/msgpackr-extract-darwin-x64": "3.0.3", "@msgpackr-extract/msgpackr-extract-linux-arm": "3.0.3", "@msgpackr-extract/msgpackr-extract-linux-arm64": "3.0.3", "@msgpackr-extract/msgpackr-extract-linux-x64": "3.0.3", "@msgpackr-extract/msgpackr-extract-win32-x64": "3.0.3" }, "bin": { "download-msgpackr-prebuilds": "bin/download-prebuilds.js" } }, "sha512-P0efT1C9jIdVRefqjzOQ9Xml57zpOXnIuS+csaB4MdZbTdmGDLo8XhzBG1N7aO11gKDDkJvBLULeFTo46wwreA=="], | |
| 1104 | + | |
| 1011 | 1105 | "msw": ["msw@2.12.10", "", { "dependencies": { "@inquirer/confirm": "^5.0.0", "@mswjs/interceptors": "^0.41.2", "@open-draft/deferred-promise": "^2.2.0", "@types/statuses": "^2.0.6", "cookie": "^1.0.2", "graphql": "^16.12.0", "headers-polyfill": "^4.0.2", "is-node-process": "^1.2.0", "outvariant": "^1.4.3", "path-to-regexp": "^6.3.0", "picocolors": "^1.1.1", "rettime": "^0.10.1", "statuses": "^2.0.2", "strict-event-emitter": "^0.5.1", "tough-cookie": "^6.0.0", "type-fest": "^5.2.0", "until-async": "^3.0.2", "yargs": "^17.7.2" }, "peerDependencies": { "typescript": ">= 4.8.x" }, "optionalPeers": ["typescript"], "bin": { "msw": "cli/index.js" } }, "sha512-G3VUymSE0/iegFnuipujpwyTM2GuZAKXNeerUSrG2+Eg391wW63xFs5ixWsK9MWzr1AGoSkYGmyAzNgbR3+urw=="], |
| 1012 | 1106 | |
| 1107 | + "multipasta": ["multipasta@0.2.7", "", {}, "sha512-KPA58d68KgGil15oDqXjkUBEBYc00XvbPj5/X+dyzeo/lWm9Nc25pQRlf1D+gv4OpK7NM0J1odrbu9JNNGvynA=="], | |
| 1108 | + | |
| 1013 | 1109 | "mute-stream": ["mute-stream@2.0.0", "", {}, "sha512-WWdIxpyjEn+FhQJQQv9aQAYlHoNVdzIzUySNV1gHUPDSdZJ3yZn7pAAbQcV7B56Mvu881q9FZV+0Vx2xC44VWA=="], |
| 1014 | 1110 | |
| 1015 | 1111 | "nanoid": ["nanoid@3.3.11", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w=="], |
| 1016 | 1112 | |
| 1113 | + "napi-build-utils": ["napi-build-utils@2.0.0", "", {}, "sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA=="], | |
| 1114 | + | |
| 1115 | + "node-abi": ["node-abi@3.87.0", "", { "dependencies": { "semver": "^7.3.5" } }, "sha512-+CGM1L1CgmtheLcBuleyYOn7NWPVu0s0EJH2C4puxgEZb9h8QpR9G2dBfZJOAUhi7VQxuBPMd0hiISWcTyiYyQ=="], | |
| 1116 | + | |
| 1017 | 1117 | "node-addon-api": ["node-addon-api@7.1.1", "", {}, "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ=="], |
| 1018 | 1118 | |
| 1119 | + "node-gyp-build-optional-packages": ["node-gyp-build-optional-packages@5.2.2", "", { "dependencies": { "detect-libc": "^2.0.1" }, "bin": { "node-gyp-build-optional-packages": "bin.js", "node-gyp-build-optional-packages-optional": "optional.js", "node-gyp-build-optional-packages-test": "build-test.js" } }, "sha512-s+w+rBWnpTMwSFbaE0UXsRlg7hU4FjekKU4eyAih5T8nJuNZT1nNsskXpxmeqSK9UzkBl6UgRlnKc8hz8IEqOw=="], | |
| 1120 | + | |
| 1019 | 1121 | "node-pty": ["node-pty@1.1.0", "", { "dependencies": { "node-addon-api": "^7.1.0" } }, "sha512-20JqtutY6JPXTUnL0ij1uad7Qe1baT46lyolh2sSENDd4sTzKZ4nmAFkeAARDKwmlLjPx6XKRlwRUxwjOy+lUg=="], |
| 1020 | 1122 | |
| 1021 | 1123 | "node-releases": ["node-releases@2.0.27", "", {}, "sha512-nmh3lCkYZ3grZvqcCH+fjmQ7X+H0OeZgP40OierEaAptX4XofMh5kwNbWh7lBduUzCcV/8kZ+NDLCwm2iorIlA=="], |
| @@ -1060,6 +1162,8 @@ · 38 unmodified lines | ||
| 1060 | 1162 | |
| 1061 | 1163 | "postcss": ["postcss@8.5.6", "", { "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } }, "sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg=="], |
| 1062 | 1164 | |
| 1165 | + "prebuild-install": ["prebuild-install@7.1.3", "", { "dependencies": { "detect-libc": "^2.0.0", "expand-template": "^2.0.3", "github-from-package": "0.0.0", "minimist": "^1.2.3", "mkdirp-classic": "^0.5.3", "napi-build-utils": "^2.0.0", "node-abi": "^3.3.0", "pump": "^3.0.0", "rc": "^1.2.7", "simple-get": "^4.0.0", "tar-fs": "^2.0.0", "tunnel-agent": "^0.6.0" }, "bin": { "prebuild-install": "bin.js" } }, "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug=="], | |
| 1166 | + | |
| 1063 | 1167 | "prettier": ["prettier@3.8.1", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg=="], |
| 1064 | 1168 | |
| 1065 | 1169 | "progress": ["progress@2.0.3", "", {}, "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA=="], |
| @@ -1070,10 +1174,14 @@ · 4 unmodified lines | ||
| 1070 | 1174 | |
| 1071 | 1175 | "pump": ["pump@3.0.3", "", { "dependencies": { "end-of-stream": "^1.1.0", "once": "^1.3.1" } }, "sha512-todwxLMY7/heScKmntwQG8CXVkWUOdYxIvY2s0VWAAMh/nd8SoYiRaKjlr7+iCs984f2P8zvrfWcDDYVb73NfA=="], |
| 1072 | 1176 | |
| 1177 | + "pure-rand": ["pure-rand@6.1.0", "", {}, "sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA=="], | |
| 1178 | + | |
| 1073 | 1179 | "quansync": ["quansync@1.0.0", "", {}, "sha512-5xZacEEufv3HSTPQuchrvV6soaiACMFnq1H8wkVioctoH3TRha9Sz66lOxRwPK/qZj7HPiSveih9yAyh98gvqA=="], |
| 1074 | 1180 | |
| 1075 | 1181 | "quick-lru": ["quick-lru@5.1.1", "", {}, "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA=="], |
| 1076 | 1182 | |
| 1183 | + "rc": ["rc@1.2.8", "", { "dependencies": { "deep-extend": "^0.6.0", "ini": "~1.3.0", "minimist": "^1.2.0", "strip-json-comments": "~2.0.1" }, "bin": { "rc": "./cli.js" } }, "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw=="], | |
| 1184 | + | |
| 1077 | 1185 | "react": ["react@19.2.4", "", {}, "sha512-9nfp2hYpCwOjAN+8TZFGhtWEwgvWHXqESH8qT89AT/lWklpLON22Lc8pEtnpsZz7VmawabSU0gCjnj8aC0euHQ=="], |
| 1078 | 1186 | |
| 1079 | 1187 | "react-dom": ["react-dom@19.2.4", "", { "dependencies": { "scheduler": "^0.27.0" }, "peerDependencies": { "react": "^19.2.4" } }, "sha512-AXJdLo8kgMbimY95O2aKQqsz2iWi9jMgKJhRBAxECE4IFxfcazB2LmzloIoibJI3C12IlY20+KFaLv+71bUJeQ=="], |
| @@ -1082,6 +1190,8 @@ · 2 unmodified lines | ||
| 1082 | 1190 | |
| 1083 | 1191 | "react-refresh": ["react-refresh@0.18.0", "", {}, "sha512-QgT5//D3jfjJb6Gsjxv0Slpj23ip+HtOpnNgnb2S5zU3CB26G/IDPGoy4RJB42wzFE46DRsstbW6tKHoKbhAxw=="], |
| 1084 | 1192 | |
| 1193 | + "readable-stream": ["readable-stream@3.6.2", "", { "dependencies": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", "util-deprecate": "^1.0.1" } }, "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA=="], | |
| 1194 | + | |
| 1085 | 1195 | "readdirp": ["readdirp@3.6.0", "", { "dependencies": { "picomatch": "^2.2.1" } }, "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA=="], |
| 1086 | 1196 | |
| 1087 | 1197 | "recast": ["recast@0.23.11", "", { "dependencies": { "ast-types": "^0.16.1", "esprima": "~4.0.0", "source-map": "~0.6.1", "tiny-invariant": "^1.3.3", "tslib": "^2.0.1" } }, "sha512-YTUo+Flmw4ZXiWfQKGcwwc11KnoRAYgzAE2E7mXKCjSviTKShtxBsN6YUUBB2gtaBzKzeKunxhUwNHQuRryhWA=="], |
| @@ -1132,6 +1242,8 @@ · 44 unmodified lines | ||
| 1132 | 1242 | |
| 1133 | 1243 | "rxjs": ["rxjs@7.8.2", "", { "dependencies": { "tslib": "^2.1.0" } }, "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA=="], |
| 1134 | 1244 | |
| 1245 | + "safe-buffer": ["safe-buffer@5.2.1", "", {}, "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="], | |
| 1246 | + | |
| 1135 | 1247 | "scheduler": ["scheduler@0.27.0", "", {}, "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q=="], |
| 1136 | 1248 | |
| 1137 | 1249 | "semver": ["semver@7.7.4", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA=="], |
| @@ -1150,6 +1262,10 @@ · 12 unmodified lines | ||
| 1150 | 1262 | |
| 1151 | 1263 | "signal-exit": ["signal-exit@4.1.0", "", {}, "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw=="], |
| 1152 | 1264 | |
| 1265 | + "simple-concat": ["simple-concat@1.0.1", "", {}, "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q=="], | |
| 1266 | + | |
| 1267 | + "simple-get": ["simple-get@4.0.1", "", { "dependencies": { "decompress-response": "^6.0.0", "once": "^1.3.1", "simple-concat": "^1.0.0" } }, "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA=="], | |
| 1268 | + | |
| 1153 | 1269 | "source-map": ["source-map@0.7.6", "", {}, "sha512-i5uvt8C3ikiWeNZSVZNWcfZPItFQOsYTUAOkcUPGd8DqDy1uOUikjt5dG+uRlwyvR108Fb9DOd4GvXfT0N2/uQ=="], |
| 1154 | 1270 | |
| 1155 | 1271 | "source-map-js": ["source-map-js@1.2.1", "", {}, "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA=="], |
| @@ -1168,10 +1284,14 @@ · 12 unmodified lines | ||
| 1168 | 1284 | |
| 1169 | 1285 | "string-width": ["string-width@4.2.3", "", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="], |
| 1170 | 1286 | |
| 1287 | + "string_decoder": ["string_decoder@1.3.0", "", { "dependencies": { "safe-buffer": "~5.2.0" } }, "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA=="], | |
| 1288 | + | |
| 1171 | 1289 | "stringify-entities": ["stringify-entities@4.0.4", "", { "dependencies": { "character-entities-html4": "^2.0.0", "character-entities-legacy": "^3.0.0" } }, "sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg=="], |
| 1172 | 1290 | |
| 1173 | 1291 | "strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="], |
| 1174 | 1292 | |
| 1293 | + "strip-json-comments": ["strip-json-comments@2.0.1", "", {}, "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ=="], | |
| 1294 | + | |
| 1175 | 1295 | "style-to-js": ["style-to-js@1.1.21", "", { "dependencies": { "style-to-object": "1.0.14" } }, "sha512-RjQetxJrrUJLQPHbLku6U/ocGtzyjbJMP9lCNK7Ag0CNh690nSH8woqWH9u16nMjYBAok+i7JO1NP2pOy8IsPQ=="], |
| 1176 | 1296 | |
| 1177 | 1297 | "style-to-object": ["style-to-object@1.0.14", "", { "dependencies": { "inline-style-parser": "0.2.7" } }, "sha512-LIN7rULI0jBscWQYaSswptyderlarFkjQ+t79nzty8tcIAceVomEVlLzH5VP4Cmsv6MtKhs7qaAiwlcp+Mgaxw=="], |
| @@ -1192,6 +1312,10 @@ · 14 unmodified lines | ||
| 1192 | 1312 | |
| 1193 | 1313 | "tapable": ["tapable@2.3.0", "", {}, "sha512-g9ljZiwki/LfxmQADO3dEY1CbpmXT5Hm2fJ+QaGKwSXUylMybePR7/67YW7jOrrvjEgL1Fmz5kzyAjWVWLlucg=="], |
| 1194 | 1314 | |
| 1315 | + "tar-fs": ["tar-fs@2.1.4", "", { "dependencies": { "chownr": "^1.1.1", "mkdirp-classic": "^0.5.2", "pump": "^3.0.0", "tar-stream": "^2.1.4" } }, "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ=="], | |
| 1316 | + | |
| 1317 | + "tar-stream": ["tar-stream@2.2.0", "", { "dependencies": { "bl": "^4.0.3", "end-of-stream": "^1.4.1", "fs-constants": "^1.0.0", "inherits": "^2.0.3", "readable-stream": "^3.1.1" } }, "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ=="], | |
| 1318 | + | |
| 1195 | 1319 | "tiny-invariant": ["tiny-invariant@1.3.3", "", {}, "sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg=="], |
| 1196 | 1320 | |
| 1197 | 1321 | "tiny-warning": ["tiny-warning@1.0.3", "", {}, "sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA=="], |
| @@ -1226,6 +1350,8 @@ · 28 unmodified lines | ||
| 1226 | 1350 | |
| 1227 | 1351 | "tsx": ["tsx@4.21.0", "", { "dependencies": { "esbuild": "~0.27.0", "get-tsconfig": "^4.7.5" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "bin": { "tsx": "dist/cli.mjs" } }, "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw=="], |
| 1228 | 1352 | |
| 1353 | + "tunnel-agent": ["tunnel-agent@0.6.0", "", { "dependencies": { "safe-buffer": "^5.0.1" } }, "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w=="], | |
| 1354 | + | |
| 1229 | 1355 | "turbo": ["turbo@2.8.7", "", { "optionalDependencies": { "turbo-darwin-64": "2.8.7", "turbo-darwin-arm64": "2.8.7", "turbo-linux-64": "2.8.7", "turbo-linux-arm64": "2.8.7", "turbo-windows-64": "2.8.7", "turbo-windows-arm64": "2.8.7" }, "bin": { "turbo": "bin/turbo" } }, "sha512-RBLh5caMAu1kFdTK1jgH2gH/z+jFsvX5rGbhgJ9nlIAWXSvxlzwId05uDlBA1+pBd3wO/UaKYzaQZQBXDd7kcA=="], |
| 1230 | 1356 | |
| 1231 | 1357 | "turbo-darwin-64": ["turbo-darwin-64@2.8.7", "", { "os": "darwin", "cpu": "x64" }, "sha512-Xr4TO/oDDwoozbDtBvunb66g//WK8uHRygl72vUthuwzmiw48pil4IuoG/QbMHd9RE8aBnVmzC0WZEWk/WWt3A=="], |
| @@ -1246,7 +1372,7 @@ · 14 unmodified lines | ||
| 1246 | 1372 | |
| 1247 | 1373 | "unconfig-core": ["unconfig-core@7.4.2", "", { "dependencies": { "@quansync/fs": "^1.0.0", "quansync": "^1.0.0" } }, "sha512-VgPCvLWugINbXvMQDf8Jh0mlbvNjNC6eSUziHsBCMpxR05OPrNrvDnyatdMjRgcHaaNsCqz+wjNXxNw1kRLHUg=="], |
| 1248 | 1374 | |
| 1249 | − "undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], | |
| 1375 | + "undici-types": ["undici-types@7.18.2", "", {}, "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w=="], | |
| 1250 | 1376 | |
| 1251 | 1377 | "unified": ["unified@11.0.5", "", { "dependencies": { "@types/unist": "^3.0.0", "bail": "^2.0.0", "devlop": "^1.0.0", "extend": "^3.0.0", "is-plain-obj": "^4.0.0", "trough": "^2.0.0", "vfile": "^6.0.0" } }, "sha512-xKvGhPWw3k84Qjh8bI3ZeJjqnyadK+GEFtazSfZv/rKeTkTjOJho6mFqh2SM96iIcZokxiOpg78GazTSg8+KHA=="], |
| 1252 | 1378 | |
| @@ -1276,6 +1402,10 @@ · 23 unmodified lines | ||
| 1276 | 1402 | |
| 1277 | 1403 | "use-sync-external-store": ["use-sync-external-store@1.6.0", "", { "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-Pp6GSwGP/NrPIrxVFAIkOQeyw8lFenOHijQWkUTrDvrF4ALqylP2C/KCkeS9dpUM3KvYRQhna5vt7IL95+ZQ9w=="], |
| 1278 | 1404 | |
| 1405 | + "util-deprecate": ["util-deprecate@1.0.2", "", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="], | |
| 1406 | + | |
| 1407 | + "uuid": ["uuid@11.1.0", "", { "bin": { "uuid": "dist/esm/bin/uuid" } }, "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A=="], | |
| 1408 | + | |
| 1279 | 1409 | "vfile": ["vfile@6.0.3", "", { "dependencies": { "@types/unist": "^3.0.0", "vfile-message": "^4.0.0" } }, "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q=="], |
| 1280 | 1410 | |
| 1281 | 1411 | "vfile-message": ["vfile-message@4.0.3", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-stringify-position": "^4.0.0" } }, "sha512-QTHzsGd1EhbZs4AsQ20JX1rC3cOlt/IWJruk893DfLRr57lcnOeMaWG4K0JrRta4mIJZKth2Au3mM3u03/JWKw=="], |
| @@ -1342,6 +1472,8 @@ · 60 unmodified lines | ||
| 1342 | 1472 | |
| 1343 | 1473 | "@electron/get/semver": ["semver@6.3.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="], |
| 1344 | 1474 | |
| 1475 | + "@t3tools/desktop/@types/node": ["@types/node@22.19.11", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-BH7YwL6rA93ReqeQS1c4bsPpcfOmJasG+Fkr6Y59q83f9M1WcBRHR2vM+P9eOisYRcN3ujQoiZY8uk5W+1WL8w=="], | |
| 1476 | + | |
| 1345 | 1477 | "@tailwindcss/node/lightningcss": ["lightningcss@1.30.2", "", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.30.2", "lightningcss-darwin-arm64": "1.30.2", "lightningcss-darwin-x64": "1.30.2", "lightningcss-freebsd-x64": "1.30.2", "lightningcss-linux-arm-gnueabihf": "1.30.2", "lightningcss-linux-arm64-gnu": "1.30.2", "lightningcss-linux-arm64-musl": "1.30.2", "lightningcss-linux-x64-gnu": "1.30.2", "lightningcss-linux-x64-musl": "1.30.2", "lightningcss-win32-arm64-msvc": "1.30.2", "lightningcss-win32-x64-msvc": "1.30.2" } }, "sha512-utfs7Pr5uJyyvDETitgsaqSyjCb2qNRAtuqUeWIAKztsOYdcACf2KtARYXg2pSvhkt+9NfoaNY7fxjl6nuMjIQ=="], |
| 1346 | 1478 | |
| 1347 | 1479 | "@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/core@1.8.1", "", { "dependencies": { "@emnapi/wasi-threads": "1.1.0", "tslib": "^2.4.0" }, "bundled": true }, "sha512-AvT9QFpxK0Zd8J0jopedNm+w/2fIzvtPKPjqyw9jwvBaReTTqPBk9Hixaz7KbjimP+QNz605/XnjFcDAL2pqBg=="], |
| @@ -1366,6 +1498,16 @@ · 18 unmodified lines | ||
| 1366 | 1498 | |
| 1367 | 1499 | "@types/babel__template/@babel/parser": ["@babel/parser@7.29.0", "", { "dependencies": { "@babel/types": "^7.29.0" }, "bin": "./bin/babel-parser.js" }, "sha512-IyDgFV5GeDUVX4YdF/3CPULtVGSXXMLh1xVIgdCgxApktqnQV0r7/8Nqthg+8YLGaAtdyIlo2qIdZrbCv4+7ww=="], |
| 1368 | 1500 | |
| 1501 | + "@types/cacheable-request/@types/node": ["@types/node@22.19.11", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-BH7YwL6rA93ReqeQS1c4bsPpcfOmJasG+Fkr6Y59q83f9M1WcBRHR2vM+P9eOisYRcN3ujQoiZY8uk5W+1WL8w=="], | |
| 1502 | + | |
| 1503 | + "@types/keyv/@types/node": ["@types/node@22.19.11", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-BH7YwL6rA93ReqeQS1c4bsPpcfOmJasG+Fkr6Y59q83f9M1WcBRHR2vM+P9eOisYRcN3ujQoiZY8uk5W+1WL8w=="], | |
| 1504 | + | |
| 1505 | + "@types/responselike/@types/node": ["@types/node@22.19.11", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-BH7YwL6rA93ReqeQS1c4bsPpcfOmJasG+Fkr6Y59q83f9M1WcBRHR2vM+P9eOisYRcN3ujQoiZY8uk5W+1WL8w=="], | |
| 1506 | + | |
| 1507 | + "@types/ws/@types/node": ["@types/node@22.19.11", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-BH7YwL6rA93ReqeQS1c4bsPpcfOmJasG+Fkr6Y59q83f9M1WcBRHR2vM+P9eOisYRcN3ujQoiZY8uk5W+1WL8w=="], | |
| 1508 | + | |
| 1509 | + "@types/yauzl/@types/node": ["@types/node@22.19.11", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-BH7YwL6rA93ReqeQS1c4bsPpcfOmJasG+Fkr6Y59q83f9M1WcBRHR2vM+P9eOisYRcN3ujQoiZY8uk5W+1WL8w=="], | |
| 1510 | + | |
| 1369 | 1511 | "@vitejs/plugin-react/vite": ["vite@7.3.1", "", { "dependencies": { "esbuild": "^0.27.0", "fdir": "^6.5.0", "picomatch": "^4.0.3", "postcss": "^8.5.6", "rollup": "^4.43.0", "tinyglobby": "^0.2.15" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "jiti": ">=1.21.0", "less": "^4.0.0", "lightningcss": "^1.21.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "jiti", "less", "lightningcss", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA=="], |
| 1370 | 1512 | |
| 1371 | 1513 | "anymatch/picomatch": ["picomatch@2.3.1", "", {}, "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="], |
| @@ -1392,6 +1534,8 @@ · 20 unmodified lines | ||
| 1392 | 1534 | |
| 1393 | 1535 | "serialize-error/type-fest": ["type-fest@0.13.1", "", {}, "sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg=="], |
| 1394 | 1536 | |
| 1537 | + "t3/@types/node": ["@types/node@22.19.11", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-BH7YwL6rA93ReqeQS1c4bsPpcfOmJasG+Fkr6Y59q83f9M1WcBRHR2vM+P9eOisYRcN3ujQoiZY8uk5W+1WL8w=="], | |
| 1538 | + | |
| 1395 | 1539 | "unixify/normalize-path": ["normalize-path@2.1.1", "", { "dependencies": { "remove-trailing-separator": "^1.0.1" } }, "sha512-3pKJwH184Xo/lnH6oyP1q2pMd7HcypqqmRs91/6/i2CGtWwIKGCkOOMTm/zXbgTEWHw1uNpNi/igc3ePOYHb6w=="], |
| 1396 | 1540 | |
| 1397 | 1541 | "vitest/vite": ["vite@7.3.1", "", { "dependencies": { "esbuild": "^0.27.0", "fdir": "^6.5.0", "picomatch": "^4.0.3", "postcss": "^8.5.6", "rollup": "^4.43.0", "tinyglobby": "^0.2.15" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "jiti": ">=1.21.0", "less": "^4.0.0", "lightningcss": "^1.21.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "jiti", "less", "lightningcss", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA=="], |
| @@ -1400,6 +1544,8 @@ · 2 unmodified lines | ||
| 1400 | 1544 | |
| 1401 | 1545 | "@babel/parser/@babel/types/@babel/helper-string-parser": ["@babel/helper-string-parser@8.0.0-rc.1", "", {}, "sha512-vi/pfmbrOtQmqgfboaBhaCU50G7mcySVu69VU8z+lYoPPB6WzI9VgV7WQfL908M4oeSH5fDkmoupIqoE0SdApw=="], |
| 1402 | 1546 | |
| 1547 | + "@t3tools/desktop/@types/node/undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], | |
| 1548 | + | |
| 1403 | 1549 | "@tailwindcss/node/lightningcss/lightningcss-android-arm64": ["lightningcss-android-arm64@1.30.2", "", { "os": "android", "cpu": "arm64" }, "sha512-BH9sEdOCahSgmkVhBLeU7Hc9DWeZ1Eb6wNS6Da8igvUwAe0sqROHddIlvU06q3WyXVEOYDZ6ykBZQnjTbmo4+A=="], |
| 1404 | 1550 | |
| 1405 | 1551 | "@tailwindcss/node/lightningcss/lightningcss-darwin-arm64": ["lightningcss-darwin-arm64@1.30.2", "", { "os": "darwin", "cpu": "arm64" }, "sha512-ylTcDJBN3Hp21TdhRT5zBOIi73P6/W0qwvlFEk22fkdXchtNTOU4Qc37SkzV+EKYxLouZ6M4LG9NfZ1qkhhBWA=="], |
| @@ -1422,8 +1568,20 @@ · 16 unmodified lines | ||
| 1422 | 1568 | |
| 1423 | 1569 | "@tailwindcss/node/lightningcss/lightningcss-win32-x64-msvc": ["lightningcss-win32-x64-msvc@1.30.2", "", { "os": "win32", "cpu": "x64" }, "sha512-5g1yc73p+iAkid5phb4oVFMB45417DkRevRbt/El/gKXJk4jid+vPFF/AXbxn05Aky8PapwzZrdJShv5C0avjw=="], |
| 1424 | 1570 | |
| 1571 | + "@types/cacheable-request/@types/node/undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], | |
| 1572 | + | |
| 1573 | + "@types/keyv/@types/node/undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], | |
| 1574 | + | |
| 1575 | + "@types/responselike/@types/node/undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], | |
| 1576 | + | |
| 1577 | + "@types/ws/@types/node/undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], | |
| 1578 | + | |
| 1579 | + "@types/yauzl/@types/node/undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], | |
| 1580 | + | |
| 1425 | 1581 | "electron/@types/node/undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="], |
| 1426 | 1582 | |
| 1427 | 1583 | "rolldown-plugin-dts/@babel/types/@babel/helper-string-parser": ["@babel/helper-string-parser@8.0.0-rc.1", "", {}, "sha512-vi/pfmbrOtQmqgfboaBhaCU50G7mcySVu69VU8z+lYoPPB6WzI9VgV7WQfL908M4oeSH5fDkmoupIqoE0SdApw=="], |
| 1584 | + | |
| 1585 | + "t3/@types/node/undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], | |
| 1428 | 1586 | } |
| 1429 | 1587 | } |
| @@ -42,6 +42,7 @@ import type { · 41 unmodified lines | ||
| 42 | 42 | ProjectUpdateScriptsResult, |
| 43 | 43 | } from "./project"; |
| 44 | 44 | import type { ServerConfig } from "./server"; |
| 45 | +type RuntimeMode = "approval-required" | "full-access"; | |
| 45 | 46 | import type { |
| 46 | 47 | TerminalClearInput, |
| 47 | 48 | TerminalCloseInput, |
| @@ -140,4 +141,19 @@ export interface NativeApi { · 92 unmodified lines | ||
| 140 | 141 | getConfig: () => Promise<ServerConfig>; |
| 141 | 142 | upsertKeybinding: (input: ServerUpsertKeybindingInput) => Promise<ServerUpsertKeybindingResult>; |
| 142 | 143 | }; |
| 144 | + state: { | |
| 145 | + getSnapshot: () => Promise<unknown>; | |
| 146 | + createThread: (input: { | |
| 147 | + id: string; | |
| 148 | + projectId: string; | |
| 149 | + title: string; | |
| 150 | + model: string; | |
| 151 | + createdAt: string; | |
| 152 | + branch: string | null; | |
| 153 | + worktreePath: string | null; | |
| 154 | + }) => Promise<unknown>; | |
| 155 | + deleteThread: (input: { id: string }) => Promise<unknown>; | |
| 156 | + markThreadVisited: (input: { threadId: string; visitedAt?: string }) => Promise<unknown>; | |
| 157 | + setRuntimeMode: (input: { mode: RuntimeMode }) => Promise<unknown>; | |
| 158 | + }; | |
| 143 | 159 | } |
| @@ -46,6 +46,7 @@ export const providerSessionSchema = z.object({ · 45 unmodified lines | ||
| 46 | 46 | }); |
| 47 | 47 | |
| 48 | 48 | export const providerSessionStartInputSchema = z.object({ |
| 49 | + uiThreadId: z.string().trim().min(1).optional(), | |
| 49 | 50 | provider: providerKindSchema.default("codex"), |
| 50 | 51 | cwd: z.string().min(1).optional(), |
| 51 | 52 | model: z.string().trim().min(1).optional(), |
| @@ -80,6 +81,7 @@ export const providerSendTurnAttachmentInputSchema = z.discriminatedUnion("type" · 28 unmodified lines | ||
| 80 | 81 | |
| 81 | 82 | export const providerSendTurnInputSchema = z |
| 82 | 83 | .object({ |
| 84 | + uiThreadId: z.string().trim().min(1).optional(), | |
| 83 | 85 | sessionId: z.string().min(1), |
| 84 | 86 | input: z.string().trim().min(1).max(PROVIDER_SEND_TURN_MAX_INPUT_CHARS).optional(), |
| 85 | 87 | attachments: z |
| @@ -46,6 +46,13 @@ export const WS_METHODS = { · 45 unmodified lines | ||
| 46 | 46 | // Server meta |
| 47 | 47 | serverGetConfig: "server.getConfig", |
| 48 | 48 | serverUpsertKeybinding: "server.upsertKeybinding", |
| 49 | + | |
| 50 | + // Server-authoritative state | |
| 51 | + stateGetSnapshot: "state.getSnapshot", | |
| 52 | + stateCreateThread: "state.createThread", | |
| 53 | + stateDeleteThread: "state.deleteThread", | |
| 54 | + stateMarkThreadVisited: "state.markThreadVisited", | |
| 55 | + stateSetRuntimeMode: "state.setRuntimeMode", | |
| 49 | 56 | } as const; |
| 50 | 57 | |
| 51 | 58 | // ── Push Event Channels ────────────────────────────────────────────── |
| @@ -54,6 +61,7 @@ export const WS_CHANNELS = { · 2 unmodified lines | ||
| 54 | 61 | providerEvent: "providers.event", |
| 55 | 62 | terminalEvent: "terminal.event", |
| 56 | 63 | serverWelcome: "server.welcome", |
| 64 | + stateUpdated: "state.updated", | |
| 57 | 65 | } as const; |
| 58 | 66 | |
| 59 | 67 | // ── Client → Server (request) ──────────────────────────────────────── |
| @@ -0,0 +1,26 @@ | ||
| 1 | +{ | |
| 2 | + "name": "@t3tools/core", | |
| 3 | + "version": "0.0.0", | |
| 4 | + "private": true, | |
| 5 | + "type": "module", | |
| 6 | + "main": "./src/index.ts", | |
| 7 | + "types": "./src/index.ts", | |
| 8 | + "exports": { | |
| 9 | + ".": { | |
| 10 | + "types": "./src/index.ts", | |
| 11 | + "import": "./src/index.ts" | |
| 12 | + } | |
| 13 | + }, | |
| 14 | + "scripts": { | |
| 15 | + "typecheck": "tsc --noEmit", | |
| 16 | + "test": "vitest run --passWithNoTests" | |
| 17 | + }, | |
| 18 | + "dependencies": { | |
| 19 | + "effect": "^3.18.4" | |
| 20 | + }, | |
| 21 | + "devDependencies": { | |
| 22 | + "@types/node": "^25.3.0", | |
| 23 | + "typescript": "^5.7.3", | |
| 24 | + "vitest": "^4.0.0" | |
| 25 | + } | |
| 26 | +} | |
| @@ -0,0 +1,78 @@ | ||
| 1 | +import type { AnyDomainCommand } from "../domain/commands"; | |
| 2 | +import type { NewDomainEvent } from "../domain/events"; | |
| 3 | +import type { AppViewState } from "../domain/models"; | |
| 4 | + | |
| 5 | +function eventFromCommand( | |
| 6 | + command: AnyDomainCommand, | |
| 7 | + eventType: NewDomainEvent["type"], | |
| 8 | + payload: NewDomainEvent["payload"], | |
| 9 | + streamId: string, | |
| 10 | +): NewDomainEvent { | |
| 11 | + return { | |
| 12 | + streamId, | |
| 13 | + type: eventType, | |
| 14 | + payload, | |
| 15 | + occurredAt: command.issuedAt, | |
| 16 | + ...(command.id ? { causationId: command.id } : {}), | |
| 17 | + ...(command.correlationId ? { correlationId: command.correlationId } : {}), | |
| 18 | + }; | |
| 19 | +} | |
| 20 | + | |
| 21 | +function streamIdFromCommand(command: AnyDomainCommand): string { | |
| 22 | + switch (command.type) { | |
| 23 | + case "app.bootstrap": | |
| 24 | + case "runtime.setMode": | |
| 25 | + return "app"; | |
| 26 | + case "project.add": | |
| 27 | + case "project.remove": | |
| 28 | + case "project.updateScripts": | |
| 29 | + return `project:${command.payload.id}`; | |
| 30 | + case "thread.create": | |
| 31 | + case "thread.delete": | |
| 32 | + return `thread:${command.payload.id}`; | |
| 33 | + case "thread.addUserMessage": | |
| 34 | + case "thread.updateProviderSession": | |
| 35 | + case "thread.recordProviderEvent": | |
| 36 | + case "thread.setBranch": | |
| 37 | + case "thread.setTerminalActivity": | |
| 38 | + case "thread.markVisited": | |
| 39 | + return `thread:${command.payload.threadId}`; | |
| 40 | + default: | |
| 41 | + return "app"; | |
| 42 | + } | |
| 43 | +} | |
| 44 | + | |
| 45 | +export function decide(command: AnyDomainCommand, currentState: AppViewState): ReadonlyArray<NewDomainEvent> { | |
| 46 | + switch (command.type) { | |
| 47 | + case "app.bootstrap": { | |
| 48 | + if (currentState.projects.length > 0) return []; | |
| 49 | + return [eventFromCommand(command, "app.bootstrapped", command.payload, streamIdFromCommand(command))]; | |
| 50 | + } | |
| 51 | + case "project.add": | |
| 52 | + return [eventFromCommand(command, "project.added", command.payload, streamIdFromCommand(command))]; | |
| 53 | + case "project.remove": | |
| 54 | + return [eventFromCommand(command, "project.removed", command.payload, streamIdFromCommand(command))]; | |
| 55 | + case "project.updateScripts": | |
| 56 | + return [eventFromCommand(command, "project.scriptsUpdated", command.payload, streamIdFromCommand(command))]; | |
| 57 | + case "thread.create": | |
| 58 | + return [eventFromCommand(command, "thread.created", command.payload, streamIdFromCommand(command))]; | |
| 59 | + case "thread.delete": | |
| 60 | + return [eventFromCommand(command, "thread.deleted", command.payload, streamIdFromCommand(command))]; | |
| 61 | + case "thread.addUserMessage": | |
| 62 | + return [eventFromCommand(command, "thread.userMessageAdded", command.payload, streamIdFromCommand(command))]; | |
| 63 | + case "thread.updateProviderSession": | |
| 64 | + return [eventFromCommand(command, "thread.providerSessionUpdated", command.payload, streamIdFromCommand(command))]; | |
| 65 | + case "thread.recordProviderEvent": | |
| 66 | + return [eventFromCommand(command, "thread.providerEventRecorded", command.payload, streamIdFromCommand(command))]; | |
| 67 | + case "thread.setBranch": | |
| 68 | + return [eventFromCommand(command, "thread.branchSet", command.payload, streamIdFromCommand(command))]; | |
| 69 | + case "thread.setTerminalActivity": | |
| 70 | + return [eventFromCommand(command, "thread.terminalActivitySet", command.payload, streamIdFromCommand(command))]; | |
| 71 | + case "thread.markVisited": | |
| 72 | + return [eventFromCommand(command, "thread.markVisited", command.payload, streamIdFromCommand(command))]; | |
| 73 | + case "runtime.setMode": | |
| 74 | + return [eventFromCommand(command, "runtime.modeSet", command.payload, streamIdFromCommand(command))]; | |
| 75 | + default: | |
| 76 | + return []; | |
| 77 | + } | |
| 78 | +} | |
| @@ -0,0 +1,49 @@ | ||
| 1 | +import { emptyAppViewState, type AppViewState } from "../domain/models"; | |
| 2 | +import type { AnyDomainCommand } from "../domain/commands"; | |
| 3 | +import { decide } from "./decide"; | |
| 4 | +import type { EventStorePort, ProjectionStorePort } from "../ports"; | |
| 5 | +import { QueueProjector } from "./projector"; | |
| 6 | +import { reduceEvents } from "../projections/reducer"; | |
| 7 | + | |
| 8 | +export class OrchestrationEngine { | |
| 9 | + constructor( | |
| 10 | + private readonly eventStore: EventStorePort, | |
| 11 | + projectionStore: ProjectionStorePort, | |
| 12 | + private readonly projector: QueueProjector, | |
| 13 | + ) { | |
| 14 | + this.projectionStore = projectionStore; | |
| 15 | + } | |
| 16 | + | |
| 17 | + private readonly projectionStore: ProjectionStorePort; | |
| 18 | + | |
| 19 | + async start(): Promise<void> { | |
| 20 | + const state = await this.projectionStore.readState(); | |
| 21 | + if (!state) { | |
| 22 | + const allEvents = await this.eventStore.loadAll(); | |
| 23 | + const next = allEvents.length === 0 ? emptyAppViewState() : reduceEvents(allEvents, emptyAppViewState()); | |
| 24 | + await this.projectionStore.writeState(next); | |
| 25 | + } | |
| 26 | + await this.projector.start(); | |
| 27 | + const pending = await this.eventStore.loadAfterPosition((await this.currentState()).lastPosition); | |
| 28 | + if (pending.length > 0) { | |
| 29 | + await this.projector.enqueue(pending); | |
| 30 | + } | |
| 31 | + } | |
| 32 | + | |
| 33 | + async stop(): Promise<void> { | |
| 34 | + await this.projector.stop(); | |
| 35 | + } | |
| 36 | + | |
| 37 | + async execute(command: AnyDomainCommand): Promise<AppViewState> { | |
| 38 | + const current = await this.currentState(); | |
| 39 | + const pending = decide(command, current); | |
| 40 | + if (pending.length === 0) return current; | |
| 41 | + const appended = await this.eventStore.append(pending); | |
| 42 | + await this.projector.enqueue(appended); | |
| 43 | + return this.currentState(); | |
| 44 | + } | |
| 45 | + | |
| 46 | + async currentState(): Promise<AppViewState> { | |
| 47 | + return this.projector.readState(); | |
| 48 | + } | |
| 49 | +} | |
| @@ -0,0 +1,64 @@ | ||
| 1 | +import type { StateUpdatedNotification } from "../domain/events"; | |
| 2 | +import type { FanoutPort } from "../ports"; | |
| 3 | + | |
| 4 | +interface Sink<T> { | |
| 5 | + push(value: T): void; | |
| 6 | + close(): void; | |
| 7 | + iterable: AsyncIterable<T>; | |
| 8 | +} | |
| 9 | + | |
| 10 | +function createSink<T>(): Sink<T> { | |
| 11 | + const queue: T[] = []; | |
| 12 | + const waiters: Array<(value: IteratorResult<T>) => void> = []; | |
| 13 | + let closed = false; | |
| 14 | + const push = (value: T) => { | |
| 15 | + if (closed) return; | |
| 16 | + const waiter = waiters.shift(); | |
| 17 | + if (waiter) { | |
| 18 | + waiter({ value, done: false }); | |
| 19 | + return; | |
| 20 | + } | |
| 21 | + queue.push(value); | |
| 22 | + }; | |
| 23 | + const close = () => { | |
| 24 | + closed = true; | |
| 25 | + while (waiters.length > 0) { | |
| 26 | + const waiter = waiters.shift(); | |
| 27 | + waiter?.({ value: undefined as never, done: true }); | |
| 28 | + } | |
| 29 | + }; | |
| 30 | + const iterable: AsyncIterable<T> = { | |
| 31 | + [Symbol.asyncIterator]() { | |
| 32 | + return { | |
| 33 | + async next() { | |
| 34 | + if (queue.length > 0) { | |
| 35 | + return { value: queue.shift() as T, done: false }; | |
| 36 | + } | |
| 37 | + if (closed) { | |
| 38 | + return { value: undefined as never, done: true }; | |
| 39 | + } | |
| 40 | + return new Promise<IteratorResult<T>>((resolve) => { | |
| 41 | + waiters.push(resolve); | |
| 42 | + }); | |
| 43 | + }, | |
| 44 | + }; | |
| 45 | + }, | |
| 46 | + }; | |
| 47 | + return { push, close, iterable }; | |
| 48 | +} | |
| 49 | + | |
| 50 | +export class EffectFanout implements FanoutPort { | |
| 51 | + private readonly sinks = new Set<Sink<StateUpdatedNotification>>(); | |
| 52 | + | |
| 53 | + async publish(notification: StateUpdatedNotification): Promise<void> { | |
| 54 | + for (const sink of this.sinks) { | |
| 55 | + sink.push(notification); | |
| 56 | + } | |
| 57 | + } | |
| 58 | + | |
| 59 | + async subscribe(): Promise<AsyncIterable<StateUpdatedNotification>> { | |
| 60 | + const sink = createSink<StateUpdatedNotification>(); | |
| 61 | + this.sinks.add(sink); | |
| 62 | + return sink.iterable; | |
| 63 | + } | |
| 64 | +} | |
| @@ -0,0 +1,51 @@ | ||
| 1 | +import type { DomainEventEnvelope } from "../domain/events"; | |
| 2 | +import { emptyAppViewState, type AppViewState } from "../domain/models"; | |
| 3 | +import type { FanoutPort, ProjectionStorePort } from "../ports"; | |
| 4 | +import { reduceEvents } from "../projections/reducer"; | |
| 5 | + | |
| 6 | +export class QueueProjector { | |
| 7 | + private readonly queue: ReadonlyArray<DomainEventEnvelope>[] = []; | |
| 8 | + private processing = false; | |
| 9 | + private stopSignal = false; | |
| 10 | + | |
| 11 | + constructor( | |
| 12 | + private readonly projectionStore: ProjectionStorePort, | |
| 13 | + private readonly fanout: FanoutPort, | |
| 14 | + ) {} | |
| 15 | + | |
| 16 | + async start(): Promise<void> { | |
| 17 | + if (this.processing) return; | |
| 18 | + this.stopSignal = false; | |
| 19 | + this.processing = true; | |
| 20 | + void this.drain(); | |
| 21 | + } | |
| 22 | + | |
| 23 | + async stop(): Promise<void> { | |
| 24 | + this.stopSignal = true; | |
| 25 | + this.processing = false; | |
| 26 | + } | |
| 27 | + | |
| 28 | + async enqueue(events: ReadonlyArray<DomainEventEnvelope>): Promise<void> { | |
| 29 | + if (events.length === 0) return; | |
| 30 | + this.queue.push(events); | |
| 31 | + if (this.processing) { | |
| 32 | + void this.drain(); | |
| 33 | + } | |
| 34 | + } | |
| 35 | + | |
| 36 | + async readState(): Promise<AppViewState> { | |
| 37 | + return (await this.projectionStore.readState()) ?? emptyAppViewState(); | |
| 38 | + } | |
| 39 | + | |
| 40 | + private async drain(): Promise<void> { | |
| 41 | + if (!this.processing) return; | |
| 42 | + while (!this.stopSignal && this.queue.length > 0) { | |
| 43 | + const chunk = this.queue.shift(); | |
| 44 | + if (!chunk || chunk.length === 0) continue; | |
| 45 | + const current = (await this.projectionStore.readState()) ?? emptyAppViewState(); | |
| 46 | + const next = reduceEvents(chunk, current); | |
| 47 | + await this.projectionStore.writeState(next); | |
| 48 | + await this.fanout.publish({ state: next, events: chunk }); | |
| 49 | + } | |
| 50 | + } | |
| 51 | +} | |
| @@ -0,0 +1,158 @@ | ||
| 1 | +import { Schema } from "effect"; | |
| 2 | + | |
| 3 | +import { ProjectScriptSchema, ProviderEventSchema, ProviderSessionViewSchema, RuntimeModeSchema } from "./models"; | |
| 4 | + | |
| 5 | +export const CommandTypeSchema = Schema.Literal( | |
| 6 | + "app.bootstrap", | |
| 7 | + "project.add", | |
| 8 | + "project.remove", | |
| 9 | + "project.updateScripts", | |
| 10 | + "thread.create", | |
| 11 | + "thread.delete", | |
| 12 | + "thread.addUserMessage", | |
| 13 | + "thread.updateProviderSession", | |
| 14 | + "thread.recordProviderEvent", | |
| 15 | + "thread.setBranch", | |
| 16 | + "thread.setTerminalActivity", | |
| 17 | + "thread.markVisited", | |
| 18 | + "runtime.setMode", | |
| 19 | +); | |
| 20 | +export type CommandType = Schema.Schema.Type<typeof CommandTypeSchema>; | |
| 21 | + | |
| 22 | +export interface DomainCommand<TPayload> { | |
| 23 | + readonly id: string; | |
| 24 | + readonly type: CommandType; | |
| 25 | + readonly payload: TPayload; | |
| 26 | + readonly issuedAt: string; | |
| 27 | + readonly correlationId?: string; | |
| 28 | +} | |
| 29 | + | |
| 30 | +export interface AppBootstrapCommand | |
| 31 | + extends DomainCommand<{ | |
| 32 | + cwd: string; | |
| 33 | + projectName: string; | |
| 34 | + }> { | |
| 35 | + readonly type: "app.bootstrap"; | |
| 36 | +} | |
| 37 | + | |
| 38 | +export interface ProjectAddCommand | |
| 39 | + extends DomainCommand<{ | |
| 40 | + id: string; | |
| 41 | + name: string; | |
| 42 | + cwd: string; | |
| 43 | + model: string; | |
| 44 | + scripts: Schema.Schema.Type<typeof ProjectScriptSchema>[]; | |
| 45 | + }> { | |
| 46 | + readonly type: "project.add"; | |
| 47 | +} | |
| 48 | + | |
| 49 | +export interface ProjectRemoveCommand extends DomainCommand<{ id: string }> { | |
| 50 | + readonly type: "project.remove"; | |
| 51 | +} | |
| 52 | + | |
| 53 | +export interface ProjectUpdateScriptsCommand | |
| 54 | + extends DomainCommand<{ | |
| 55 | + id: string; | |
| 56 | + scripts: Schema.Schema.Type<typeof ProjectScriptSchema>[]; | |
| 57 | + }> { | |
| 58 | + readonly type: "project.updateScripts"; | |
| 59 | +} | |
| 60 | + | |
| 61 | +export interface ThreadCreateCommand | |
| 62 | + extends DomainCommand<{ | |
| 63 | + id: string; | |
| 64 | + projectId: string; | |
| 65 | + title: string; | |
| 66 | + model: string; | |
| 67 | + createdAt: string; | |
| 68 | + branch: string | null; | |
| 69 | + worktreePath: string | null; | |
| 70 | + }> { | |
| 71 | + readonly type: "thread.create"; | |
| 72 | +} | |
| 73 | + | |
| 74 | +export interface ThreadDeleteCommand extends DomainCommand<{ id: string }> { | |
| 75 | + readonly type: "thread.delete"; | |
| 76 | +} | |
| 77 | + | |
| 78 | +export interface ThreadAddUserMessageCommand | |
| 79 | + extends DomainCommand<{ | |
| 80 | + threadId: string; | |
| 81 | + messageId: string; | |
| 82 | + text: string; | |
| 83 | + createdAt: string; | |
| 84 | + attachments?: Array<{ | |
| 85 | + type: "image"; | |
| 86 | + id: string; | |
| 87 | + name: string; | |
| 88 | + mimeType: string; | |
| 89 | + sizeBytes: number; | |
| 90 | + previewUrl?: string; | |
| 91 | + }>; | |
| 92 | + }> { | |
| 93 | + readonly type: "thread.addUserMessage"; | |
| 94 | +} | |
| 95 | + | |
| 96 | +export interface ThreadUpdateProviderSessionCommand | |
| 97 | + extends DomainCommand<{ | |
| 98 | + threadId: string; | |
| 99 | + session: Schema.Schema.Type<typeof ProviderSessionViewSchema> | null; | |
| 100 | + }> { | |
| 101 | + readonly type: "thread.updateProviderSession"; | |
| 102 | +} | |
| 103 | + | |
| 104 | +export interface ThreadRecordProviderEventCommand | |
| 105 | + extends DomainCommand<{ | |
| 106 | + threadId: string; | |
| 107 | + event: Schema.Schema.Type<typeof ProviderEventSchema>; | |
| 108 | + }> { | |
| 109 | + readonly type: "thread.recordProviderEvent"; | |
| 110 | +} | |
| 111 | + | |
| 112 | +export interface ThreadSetBranchCommand | |
| 113 | + extends DomainCommand<{ | |
| 114 | + threadId: string; | |
| 115 | + branch: string | null; | |
| 116 | + worktreePath: string | null; | |
| 117 | + }> { | |
| 118 | + readonly type: "thread.setBranch"; | |
| 119 | +} | |
| 120 | + | |
| 121 | +export interface ThreadSetTerminalActivityCommand | |
| 122 | + extends DomainCommand<{ | |
| 123 | + threadId: string; | |
| 124 | + terminalId: string; | |
| 125 | + running: boolean; | |
| 126 | + }> { | |
| 127 | + readonly type: "thread.setTerminalActivity"; | |
| 128 | +} | |
| 129 | + | |
| 130 | +export interface ThreadMarkVisitedCommand | |
| 131 | + extends DomainCommand<{ | |
| 132 | + threadId: string; | |
| 133 | + visitedAt: string; | |
| 134 | + }> { | |
| 135 | + readonly type: "thread.markVisited"; | |
| 136 | +} | |
| 137 | + | |
| 138 | +export interface RuntimeSetModeCommand | |
| 139 | + extends DomainCommand<{ | |
| 140 | + mode: Schema.Schema.Type<typeof RuntimeModeSchema>; | |
| 141 | + }> { | |
| 142 | + readonly type: "runtime.setMode"; | |
| 143 | +} | |
| 144 | + | |
| 145 | +export type AnyDomainCommand = | |
| 146 | + | AppBootstrapCommand | |
| 147 | + | ProjectAddCommand | |
| 148 | + | ProjectRemoveCommand | |
| 149 | + | ProjectUpdateScriptsCommand | |
| 150 | + | ThreadCreateCommand | |
| 151 | + | ThreadDeleteCommand | |
| 152 | + | ThreadAddUserMessageCommand | |
| 153 | + | ThreadUpdateProviderSessionCommand | |
| 154 | + | ThreadRecordProviderEventCommand | |
| 155 | + | ThreadSetBranchCommand | |
| 156 | + | ThreadSetTerminalActivityCommand | |
| 157 | + | ThreadMarkVisitedCommand | |
| 158 | + | RuntimeSetModeCommand; | |
| @@ -0,0 +1,149 @@ | ||
| 1 | +import { Schema } from "effect"; | |
| 2 | + | |
| 3 | +import { | |
| 4 | + type AppViewState, | |
| 5 | + ProjectScriptSchema, | |
| 6 | + ProviderEventSchema, | |
| 7 | + ProviderSessionViewSchema, | |
| 8 | + RuntimeModeSchema, | |
| 9 | +} from "./models"; | |
| 10 | + | |
| 11 | +export const DomainEventTypeSchema = Schema.Literal( | |
| 12 | + "app.bootstrapped", | |
| 13 | + "project.added", | |
| 14 | + "project.removed", | |
| 15 | + "project.scriptsUpdated", | |
| 16 | + "thread.created", | |
| 17 | + "thread.deleted", | |
| 18 | + "thread.userMessageAdded", | |
| 19 | + "thread.providerSessionUpdated", | |
| 20 | + "thread.providerEventRecorded", | |
| 21 | + "thread.branchSet", | |
| 22 | + "thread.terminalActivitySet", | |
| 23 | + "thread.markVisited", | |
| 24 | + "runtime.modeSet", | |
| 25 | +); | |
| 26 | +export type DomainEventType = Schema.Schema.Type<typeof DomainEventTypeSchema>; | |
| 27 | + | |
| 28 | +const AppBootstrappedPayloadSchema = Schema.Struct({ | |
| 29 | + cwd: Schema.String, | |
| 30 | + projectName: Schema.String, | |
| 31 | +}); | |
| 32 | + | |
| 33 | +const ProjectAddedPayloadSchema = Schema.Struct({ | |
| 34 | + id: Schema.String, | |
| 35 | + name: Schema.String, | |
| 36 | + cwd: Schema.String, | |
| 37 | + model: Schema.String, | |
| 38 | + scripts: Schema.Array(ProjectScriptSchema), | |
| 39 | +}); | |
| 40 | + | |
| 41 | +const ProjectRemovedPayloadSchema = Schema.Struct({ id: Schema.String }); | |
| 42 | + | |
| 43 | +const ProjectScriptsUpdatedPayloadSchema = Schema.Struct({ | |
| 44 | + id: Schema.String, | |
| 45 | + scripts: Schema.Array(ProjectScriptSchema), | |
| 46 | +}); | |
| 47 | + | |
| 48 | +const ThreadCreatedPayloadSchema = Schema.Struct({ | |
| 49 | + id: Schema.String, | |
| 50 | + projectId: Schema.String, | |
| 51 | + title: Schema.String, | |
| 52 | + model: Schema.String, | |
| 53 | + createdAt: Schema.String, | |
| 54 | + branch: Schema.NullOr(Schema.String), | |
| 55 | + worktreePath: Schema.NullOr(Schema.String), | |
| 56 | +}); | |
| 57 | + | |
| 58 | +const ThreadDeletedPayloadSchema = Schema.Struct({ id: Schema.String }); | |
| 59 | + | |
| 60 | +const ThreadUserMessageAddedPayloadSchema = Schema.Struct({ | |
| 61 | + threadId: Schema.String, | |
| 62 | + messageId: Schema.String, | |
| 63 | + text: Schema.String, | |
| 64 | + createdAt: Schema.String, | |
| 65 | + attachments: Schema.optional( | |
| 66 | + Schema.Array( | |
| 67 | + Schema.Struct({ | |
| 68 | + type: Schema.Literal("image"), | |
| 69 | + id: Schema.String, | |
| 70 | + name: Schema.String, | |
| 71 | + mimeType: Schema.String, | |
| 72 | + sizeBytes: Schema.Number, | |
| 73 | + previewUrl: Schema.optional(Schema.String), | |
| 74 | + }), | |
| 75 | + ), | |
| 76 | + ), | |
| 77 | +}); | |
| 78 | + | |
| 79 | +const ThreadProviderSessionUpdatedPayloadSchema = Schema.Struct({ | |
| 80 | + threadId: Schema.String, | |
| 81 | + session: Schema.NullOr(ProviderSessionViewSchema), | |
| 82 | +}); | |
| 83 | + | |
| 84 | +const ThreadProviderEventRecordedPayloadSchema = Schema.Struct({ | |
| 85 | + threadId: Schema.String, | |
| 86 | + event: ProviderEventSchema, | |
| 87 | +}); | |
| 88 | + | |
| 89 | +const ThreadBranchSetPayloadSchema = Schema.Struct({ | |
| 90 | + threadId: Schema.String, | |
| 91 | + branch: Schema.NullOr(Schema.String), | |
| 92 | + worktreePath: Schema.NullOr(Schema.String), | |
| 93 | +}); | |
| 94 | + | |
| 95 | +const ThreadTerminalActivitySetPayloadSchema = Schema.Struct({ | |
| 96 | + threadId: Schema.String, | |
| 97 | + terminalId: Schema.String, | |
| 98 | + running: Schema.Boolean, | |
| 99 | +}); | |
| 100 | + | |
| 101 | +const ThreadMarkVisitedPayloadSchema = Schema.Struct({ | |
| 102 | + threadId: Schema.String, | |
| 103 | + visitedAt: Schema.String, | |
| 104 | +}); | |
| 105 | + | |
| 106 | +const RuntimeModeSetPayloadSchema = Schema.Struct({ | |
| 107 | + mode: RuntimeModeSchema, | |
| 108 | +}); | |
| 109 | + | |
| 110 | +export type DomainEventPayload = | |
| 111 | + | Schema.Schema.Type<typeof AppBootstrappedPayloadSchema> | |
| 112 | + | Schema.Schema.Type<typeof ProjectAddedPayloadSchema> | |
| 113 | + | Schema.Schema.Type<typeof ProjectRemovedPayloadSchema> | |
| 114 | + | Schema.Schema.Type<typeof ProjectScriptsUpdatedPayloadSchema> | |
| 115 | + | Schema.Schema.Type<typeof ThreadCreatedPayloadSchema> | |
| 116 | + | Schema.Schema.Type<typeof ThreadDeletedPayloadSchema> | |
| 117 | + | Schema.Schema.Type<typeof ThreadUserMessageAddedPayloadSchema> | |
| 118 | + | Schema.Schema.Type<typeof ThreadProviderSessionUpdatedPayloadSchema> | |
| 119 | + | Schema.Schema.Type<typeof ThreadProviderEventRecordedPayloadSchema> | |
| 120 | + | Schema.Schema.Type<typeof ThreadBranchSetPayloadSchema> | |
| 121 | + | Schema.Schema.Type<typeof ThreadTerminalActivitySetPayloadSchema> | |
| 122 | + | Schema.Schema.Type<typeof ThreadMarkVisitedPayloadSchema> | |
| 123 | + | Schema.Schema.Type<typeof RuntimeModeSetPayloadSchema>; | |
| 124 | + | |
| 125 | +export interface DomainEventEnvelope { | |
| 126 | + readonly eventId: string; | |
| 127 | + readonly streamId: string; | |
| 128 | + readonly sequence: number; | |
| 129 | + readonly position: number; | |
| 130 | + readonly type: DomainEventType; | |
| 131 | + readonly occurredAt: string; | |
| 132 | + readonly payload: DomainEventPayload; | |
| 133 | + readonly causationId?: string; | |
| 134 | + readonly correlationId?: string; | |
| 135 | +} | |
| 136 | + | |
| 137 | +export interface NewDomainEvent { | |
| 138 | + readonly streamId: string; | |
| 139 | + readonly type: DomainEventType; | |
| 140 | + readonly payload: DomainEventPayload; | |
| 141 | + readonly occurredAt: string; | |
| 142 | + readonly causationId?: string; | |
| 143 | + readonly correlationId?: string; | |
| 144 | +} | |
| 145 | + | |
| 146 | +export interface StateUpdatedNotification { | |
| 147 | + readonly state: AppViewState; | |
| 148 | + readonly events: readonly DomainEventEnvelope[]; | |
| 149 | +} | |
| @@ -0,0 +1,152 @@ | ||
| 1 | +import { Schema } from "effect"; | |
| 2 | + | |
| 3 | +export const RuntimeModeSchema = Schema.Literal("approval-required", "full-access"); | |
| 4 | +export type RuntimeMode = Schema.Schema.Type<typeof RuntimeModeSchema>; | |
| 5 | + | |
| 6 | +export const ProjectScriptSchema = Schema.Struct({ | |
| 7 | + id: Schema.String, | |
| 8 | + name: Schema.String, | |
| 9 | + command: Schema.String, | |
| 10 | + keybinding: Schema.optional(Schema.String), | |
| 11 | +}); | |
| 12 | +export type ProjectScript = Schema.Schema.Type<typeof ProjectScriptSchema>; | |
| 13 | + | |
| 14 | +export const ProjectViewSchema = Schema.Struct({ | |
| 15 | + id: Schema.String, | |
| 16 | + name: Schema.String, | |
| 17 | + cwd: Schema.String, | |
| 18 | + model: Schema.String, | |
| 19 | + expanded: Schema.Boolean, | |
| 20 | + scripts: Schema.Array(ProjectScriptSchema), | |
| 21 | +}); | |
| 22 | +export type ProjectView = Schema.Schema.Type<typeof ProjectViewSchema>; | |
| 23 | + | |
| 24 | +export const ChatAttachmentSchema = Schema.Struct({ | |
| 25 | + type: Schema.Literal("image"), | |
| 26 | + id: Schema.String, | |
| 27 | + name: Schema.String, | |
| 28 | + mimeType: Schema.String, | |
| 29 | + sizeBytes: Schema.Number, | |
| 30 | + previewUrl: Schema.optional(Schema.String), | |
| 31 | +}); | |
| 32 | +export type ChatAttachment = Schema.Schema.Type<typeof ChatAttachmentSchema>; | |
| 33 | + | |
| 34 | +export const ChatMessageSchema = Schema.Struct({ | |
| 35 | + id: Schema.String, | |
| 36 | + role: Schema.Literal("user", "assistant"), | |
| 37 | + text: Schema.String, | |
| 38 | + attachments: Schema.optional(Schema.Array(ChatAttachmentSchema)), | |
| 39 | + createdAt: Schema.String, | |
| 40 | + streaming: Schema.Boolean, | |
| 41 | +}); | |
| 42 | +export type ChatMessage = Schema.Schema.Type<typeof ChatMessageSchema>; | |
| 43 | + | |
| 44 | +export const SessionStatusSchema = Schema.Literal( | |
| 45 | + "connecting", | |
| 46 | + "ready", | |
| 47 | + "running", | |
| 48 | + "error", | |
| 49 | + "closed", | |
| 50 | +); | |
| 51 | +export type SessionStatus = Schema.Schema.Type<typeof SessionStatusSchema>; | |
| 52 | + | |
| 53 | +export const ProviderSessionViewSchema = Schema.Struct({ | |
| 54 | + sessionId: Schema.String, | |
| 55 | + provider: Schema.Literal("codex", "claudeCode"), | |
| 56 | + status: SessionStatusSchema, | |
| 57 | + cwd: Schema.optional(Schema.String), | |
| 58 | + model: Schema.optional(Schema.String), | |
| 59 | + threadId: Schema.optional(Schema.String), | |
| 60 | + activeTurnId: Schema.optional(Schema.String), | |
| 61 | + createdAt: Schema.String, | |
| 62 | + updatedAt: Schema.String, | |
| 63 | + lastError: Schema.optional(Schema.String), | |
| 64 | +}); | |
| 65 | +export type ProviderSessionView = Schema.Schema.Type<typeof ProviderSessionViewSchema>; | |
| 66 | + | |
| 67 | +export const ProviderEventSchema = Schema.Struct({ | |
| 68 | + id: Schema.String, | |
| 69 | + kind: Schema.Literal("session", "notification", "request", "error"), | |
| 70 | + method: Schema.String, | |
| 71 | + payload: Schema.optional(Schema.Unknown), | |
| 72 | + createdAt: Schema.String, | |
| 73 | + sessionId: Schema.String, | |
| 74 | + threadId: Schema.optional(Schema.String), | |
| 75 | + turnId: Schema.optional(Schema.String), | |
| 76 | + itemId: Schema.optional(Schema.String), | |
| 77 | + textDelta: Schema.optional(Schema.String), | |
| 78 | + requestId: Schema.optional(Schema.String), | |
| 79 | + requestKind: Schema.optional(Schema.String), | |
| 80 | + message: Schema.optional(Schema.String), | |
| 81 | +}); | |
| 82 | +export type ProviderEvent = Schema.Schema.Type<typeof ProviderEventSchema>; | |
| 83 | + | |
| 84 | +export const TurnDiffFileChangeSchema = Schema.Struct({ | |
| 85 | + path: Schema.String, | |
| 86 | + kind: Schema.optional(Schema.String), | |
| 87 | + additions: Schema.optional(Schema.Number), | |
| 88 | + deletions: Schema.optional(Schema.Number), | |
| 89 | +}); | |
| 90 | +export type TurnDiffFileChange = Schema.Schema.Type<typeof TurnDiffFileChangeSchema>; | |
| 91 | + | |
| 92 | +export const TurnDiffSummarySchema = Schema.Struct({ | |
| 93 | + turnId: Schema.String, | |
| 94 | + completedAt: Schema.String, | |
| 95 | + status: Schema.optional(Schema.String), | |
| 96 | + files: Schema.Array(TurnDiffFileChangeSchema), | |
| 97 | + assistantMessageId: Schema.optional(Schema.String), | |
| 98 | + checkpointTurnCount: Schema.optional(Schema.Number), | |
| 99 | +}); | |
| 100 | +export type TurnDiffSummary = Schema.Schema.Type<typeof TurnDiffSummarySchema>; | |
| 101 | + | |
| 102 | +export const ThreadTerminalGroupSchema = Schema.Struct({ | |
| 103 | + id: Schema.String, | |
| 104 | + terminalIds: Schema.Array(Schema.String), | |
| 105 | +}); | |
| 106 | +export type ThreadTerminalGroup = Schema.Schema.Type<typeof ThreadTerminalGroupSchema>; | |
| 107 | + | |
| 108 | +export const ThreadViewSchema = Schema.Struct({ | |
| 109 | + id: Schema.String, | |
| 110 | + codexThreadId: Schema.NullOr(Schema.String), | |
| 111 | + projectId: Schema.String, | |
| 112 | + title: Schema.String, | |
| 113 | + model: Schema.String, | |
| 114 | + terminalOpen: Schema.Boolean, | |
| 115 | + terminalHeight: Schema.Number, | |
| 116 | + terminalIds: Schema.Array(Schema.String), | |
| 117 | + runningTerminalIds: Schema.Array(Schema.String), | |
| 118 | + activeTerminalId: Schema.String, | |
| 119 | + terminalGroups: Schema.Array(ThreadTerminalGroupSchema), | |
| 120 | + activeTerminalGroupId: Schema.String, | |
| 121 | + session: Schema.NullOr(ProviderSessionViewSchema), | |
| 122 | + messages: Schema.Array(ChatMessageSchema), | |
| 123 | + events: Schema.Array(ProviderEventSchema), | |
| 124 | + error: Schema.NullOr(Schema.String), | |
| 125 | + createdAt: Schema.String, | |
| 126 | + latestTurnId: Schema.optional(Schema.String), | |
| 127 | + latestTurnStartedAt: Schema.optional(Schema.String), | |
| 128 | + latestTurnCompletedAt: Schema.optional(Schema.String), | |
| 129 | + latestTurnDurationMs: Schema.optional(Schema.Number), | |
| 130 | + lastVisitedAt: Schema.optional(Schema.String), | |
| 131 | + branch: Schema.NullOr(Schema.String), | |
| 132 | + worktreePath: Schema.NullOr(Schema.String), | |
| 133 | + turnDiffSummaries: Schema.Array(TurnDiffSummarySchema), | |
| 134 | +}); | |
| 135 | +export type ThreadView = Schema.Schema.Type<typeof ThreadViewSchema>; | |
| 136 | + | |
| 137 | +export const AppViewStateSchema = Schema.Struct({ | |
| 138 | + projects: Schema.Array(ProjectViewSchema), | |
| 139 | + threads: Schema.Array(ThreadViewSchema), | |
| 140 | + threadsHydrated: Schema.Boolean, | |
| 141 | + runtimeMode: RuntimeModeSchema, | |
| 142 | + lastPosition: Schema.Number, | |
| 143 | +}); | |
| 144 | +export type AppViewState = Schema.Schema.Type<typeof AppViewStateSchema>; | |
| 145 | + | |
| 146 | +export const emptyAppViewState = (): AppViewState => ({ | |
| 147 | + projects: [], | |
| 148 | + threads: [], | |
| 149 | + threadsHydrated: false, | |
| 150 | + runtimeMode: "full-access", | |
| 151 | + lastPosition: 0, | |
| 152 | +}); | |
| @@ -0,0 +1,7 @@ | ||
| 1 | +import type { AppViewState } from "./models"; | |
| 2 | + | |
| 3 | +export type DomainQuery = { readonly type: "app.getState" }; | |
| 4 | + | |
| 5 | +export interface QueryResultMap { | |
| 6 | + "app.getState": AppViewState; | |
| 7 | +} | |
| @@ -0,0 +1,10 @@ | ||
| 1 | +export * from "./domain/models"; | |
| 2 | +export * from "./domain/commands"; | |
| 3 | +export * from "./domain/events"; | |
| 4 | +export * from "./domain/queries"; | |
| 5 | +export * from "./ports"; | |
| 6 | +export * from "./projections/reducer"; | |
| 7 | +export * from "./application/decide"; | |
| 8 | +export * from "./application/fanout"; | |
| 9 | +export * from "./application/projector"; | |
| 10 | +export * from "./application/engine"; | |
| @@ -0,0 +1,30 @@ | ||
| 1 | +import type { AnyDomainCommand } from "../domain/commands"; | |
| 2 | +import type { DomainEventEnvelope, NewDomainEvent, StateUpdatedNotification } from "../domain/events"; | |
| 3 | +import type { AppViewState } from "../domain/models"; | |
| 4 | + | |
| 5 | +export interface EventStorePort { | |
| 6 | + append(events: ReadonlyArray<NewDomainEvent>): Promise<ReadonlyArray<DomainEventEnvelope>>; | |
| 7 | + loadAll(): Promise<ReadonlyArray<DomainEventEnvelope>>; | |
| 8 | + loadAfterPosition(position: number): Promise<ReadonlyArray<DomainEventEnvelope>>; | |
| 9 | +} | |
| 10 | + | |
| 11 | +export interface ProjectionStorePort { | |
| 12 | + readState(): Promise<AppViewState | null>; | |
| 13 | + writeState(state: AppViewState): Promise<void>; | |
| 14 | +} | |
| 15 | + | |
| 16 | +export interface FanoutPort { | |
| 17 | + publish(notification: StateUpdatedNotification): Promise<void>; | |
| 18 | + subscribe(): Promise<AsyncIterable<StateUpdatedNotification>>; | |
| 19 | +} | |
| 20 | + | |
| 21 | +export interface DeterministicProjectorPort { | |
| 22 | + start(): Promise<void>; | |
| 23 | + stop(): Promise<void>; | |
| 24 | + enqueue(events: ReadonlyArray<DomainEventEnvelope>): Promise<void>; | |
| 25 | +} | |
| 26 | + | |
| 27 | +export interface CoreApplicationPort { | |
| 28 | + execute(command: AnyDomainCommand): Promise<AppViewState>; | |
| 29 | + currentState(): Promise<AppViewState>; | |
| 30 | +} | |
| @@ -0,0 +1,370 @@ | ||
| 1 | +import type { DomainEventEnvelope } from "../domain/events"; | |
| 2 | +import type { AppViewState, ChatMessage, ProviderEvent, ProviderSessionView, ThreadView } from "../domain/models"; | |
| 3 | +import { emptyAppViewState } from "../domain/models"; | |
| 4 | + | |
| 5 | +function asObject(value: unknown): Record<string, unknown> | undefined { | |
| 6 | + return value && typeof value === "object" ? (value as Record<string, unknown>) : undefined; | |
| 7 | +} | |
| 8 | + | |
| 9 | +function asString(value: unknown): string | undefined { | |
| 10 | + return typeof value === "string" ? value : undefined; | |
| 11 | +} | |
| 12 | + | |
| 13 | +function eventTurnId(event: ProviderEvent): string | undefined { | |
| 14 | + if (event.turnId) return event.turnId; | |
| 15 | + const turn = asObject(asObject(event.payload)?.turn); | |
| 16 | + return asString(turn?.id); | |
| 17 | +} | |
| 18 | + | |
| 19 | +function durationMs(startIso: string, endIso: string): number | undefined { | |
| 20 | + const start = Date.parse(startIso); | |
| 21 | + const end = Date.parse(endIso); | |
| 22 | + if (Number.isNaN(start) || Number.isNaN(end) || end < start) return undefined; | |
| 23 | + return end - start; | |
| 24 | +} | |
| 25 | + | |
| 26 | +function evolveSession(previous: ProviderSessionView, event: ProviderEvent): ProviderSessionView { | |
| 27 | + const payload = asObject(event.payload); | |
| 28 | + if (event.method === "thread/started") { | |
| 29 | + const thread = asObject(payload?.thread); | |
| 30 | + return { ...previous, threadId: asString(thread?.id) ?? event.threadId ?? previous.threadId, updatedAt: event.createdAt }; | |
| 31 | + } | |
| 32 | + if (event.method === "turn/started") { | |
| 33 | + const turn = asObject(payload?.turn); | |
| 34 | + return { | |
| 35 | + ...previous, | |
| 36 | + status: "running", | |
| 37 | + activeTurnId: asString(turn?.id) ?? event.turnId ?? previous.activeTurnId, | |
| 38 | + updatedAt: event.createdAt, | |
| 39 | + }; | |
| 40 | + } | |
| 41 | + if (event.method === "turn/completed") { | |
| 42 | + const turn = asObject(payload?.turn); | |
| 43 | + const status = asString(turn?.status); | |
| 44 | + const turnError = asObject(turn?.error); | |
| 45 | + return { | |
| 46 | + ...previous, | |
| 47 | + status: status === "failed" ? "error" : "ready", | |
| 48 | + activeTurnId: undefined, | |
| 49 | + lastError: asString(turnError?.message) ?? previous.lastError, | |
| 50 | + updatedAt: event.createdAt, | |
| 51 | + }; | |
| 52 | + } | |
| 53 | + if (event.kind === "error") { | |
| 54 | + return { | |
| 55 | + ...previous, | |
| 56 | + status: "error", | |
| 57 | + lastError: event.message ?? previous.lastError, | |
| 58 | + updatedAt: event.createdAt, | |
| 59 | + }; | |
| 60 | + } | |
| 61 | + if (event.method === "session/closed" || event.method === "session/exited") { | |
| 62 | + return { | |
| 63 | + ...previous, | |
| 64 | + status: "closed", | |
| 65 | + activeTurnId: undefined, | |
| 66 | + lastError: event.message ?? previous.lastError, | |
| 67 | + updatedAt: event.createdAt, | |
| 68 | + }; | |
| 69 | + } | |
| 70 | + return { ...previous, updatedAt: event.createdAt }; | |
| 71 | +} | |
| 72 | + | |
| 73 | +function applyEventToMessages(previous: ReadonlyArray<ChatMessage>, event: ProviderEvent): ChatMessage[] { | |
| 74 | + const payload = asObject(event.payload); | |
| 75 | + if (event.method === "item/started") { | |
| 76 | + const item = asObject(payload?.item); | |
| 77 | + if (asString(item?.type) !== "agentMessage") return [...previous]; | |
| 78 | + const itemId = asString(item?.id); | |
| 79 | + if (!itemId) return [...previous]; | |
| 80 | + const seedText = asString(item?.text) ?? ""; | |
| 81 | + return [ | |
| 82 | + ...previous.filter((entry) => entry.id !== itemId), | |
| 83 | + { id: itemId, role: "assistant", text: seedText, createdAt: event.createdAt, streaming: true }, | |
| 84 | + ]; | |
| 85 | + } | |
| 86 | + if (event.method === "item/agentMessage/delta") { | |
| 87 | + const itemId = event.itemId ?? asString(payload?.itemId); | |
| 88 | + const delta = event.textDelta ?? asString(payload?.delta) ?? ""; | |
| 89 | + if (!itemId || !delta) return [...previous]; | |
| 90 | + const idx = previous.findIndex((entry) => entry.id === itemId); | |
| 91 | + if (idx < 0) { | |
| 92 | + return [...previous, { id: itemId, role: "assistant", text: delta, createdAt: event.createdAt, streaming: true }]; | |
| 93 | + } | |
| 94 | + const next = [...previous]; | |
| 95 | + const current = next[idx]; | |
| 96 | + if (!current) return [...previous]; | |
| 97 | + next[idx] = { ...current, text: `${current.text}${delta}`, streaming: true }; | |
| 98 | + return next; | |
| 99 | + } | |
| 100 | + if (event.method === "item/completed") { | |
| 101 | + const item = asObject(payload?.item); | |
| 102 | + if (asString(item?.type) !== "agentMessage") return [...previous]; | |
| 103 | + const itemId = asString(item?.id); | |
| 104 | + if (!itemId) return [...previous]; | |
| 105 | + const fullText = asString(item?.text); | |
| 106 | + const idx = previous.findIndex((entry) => entry.id === itemId); | |
| 107 | + if (idx < 0) { | |
| 108 | + return [...previous, { id: itemId, role: "assistant", text: fullText ?? "", createdAt: event.createdAt, streaming: false }]; | |
| 109 | + } | |
| 110 | + const next = [...previous]; | |
| 111 | + const current = next[idx]; | |
| 112 | + if (!current) return [...previous]; | |
| 113 | + next[idx] = { ...current, text: fullText ?? current.text, streaming: false }; | |
| 114 | + return next; | |
| 115 | + } | |
| 116 | + if (event.method === "turn/completed") { | |
| 117 | + return previous.map((entry) => ({ ...entry, streaming: false })); | |
| 118 | + } | |
| 119 | + return [...previous]; | |
| 120 | +} | |
| 121 | + | |
| 122 | +function defaultThread(payload: { | |
| 123 | + id: string; | |
| 124 | + projectId: string; | |
| 125 | + title: string; | |
| 126 | + model: string; | |
| 127 | + createdAt: string; | |
| 128 | + branch: string | null; | |
| 129 | + worktreePath: string | null; | |
| 130 | +}): ThreadView { | |
| 131 | + return { | |
| 132 | + id: payload.id, | |
| 133 | + codexThreadId: null, | |
| 134 | + projectId: payload.projectId, | |
| 135 | + title: payload.title, | |
| 136 | + model: payload.model, | |
| 137 | + terminalOpen: false, | |
| 138 | + terminalHeight: 280, | |
| 139 | + terminalIds: ["default"], | |
| 140 | + runningTerminalIds: [], | |
| 141 | + activeTerminalId: "default", | |
| 142 | + terminalGroups: [{ id: "group-default", terminalIds: ["default"] }], | |
| 143 | + activeTerminalGroupId: "group-default", | |
| 144 | + session: null, | |
| 145 | + messages: [], | |
| 146 | + events: [], | |
| 147 | + error: null, | |
| 148 | + createdAt: payload.createdAt, | |
| 149 | + branch: payload.branch, | |
| 150 | + worktreePath: payload.worktreePath, | |
| 151 | + turnDiffSummaries: [], | |
| 152 | + }; | |
| 153 | +} | |
| 154 | + | |
| 155 | +export function applyDomainEvent(state: AppViewState, event: DomainEventEnvelope): AppViewState { | |
| 156 | + switch (event.type) { | |
| 157 | + case "app.bootstrapped": { | |
| 158 | + const payload = event.payload as { cwd: string; projectName: string }; | |
| 159 | + if (state.projects.length > 0) return { ...state, threadsHydrated: true, lastPosition: event.position }; | |
| 160 | + return { | |
| 161 | + ...state, | |
| 162 | + projects: [ | |
| 163 | + { | |
| 164 | + id: "bootstrap-project", | |
| 165 | + name: payload.projectName, | |
| 166 | + cwd: payload.cwd, | |
| 167 | + model: "gpt-5-codex", | |
| 168 | + expanded: true, | |
| 169 | + scripts: [], | |
| 170 | + }, | |
| 171 | + ], | |
| 172 | + threadsHydrated: true, | |
| 173 | + lastPosition: event.position, | |
| 174 | + }; | |
| 175 | + } | |
| 176 | + case "project.added": { | |
| 177 | + const payload = event.payload as { | |
| 178 | + id: string; | |
| 179 | + name: string; | |
| 180 | + cwd: string; | |
| 181 | + model: string; | |
| 182 | + scripts: Array<{ id: string; name: string; command: string; keybinding?: string }>; | |
| 183 | + }; | |
| 184 | + if (state.projects.some((project) => project.id === payload.id || project.cwd === payload.cwd)) { | |
| 185 | + return { ...state, lastPosition: event.position }; | |
| 186 | + } | |
| 187 | + return { | |
| 188 | + ...state, | |
| 189 | + projects: [...state.projects, { ...payload, expanded: true }], | |
| 190 | + lastPosition: event.position, | |
| 191 | + }; | |
| 192 | + } | |
| 193 | + case "project.removed": { | |
| 194 | + const payload = event.payload as { id: string }; | |
| 195 | + return { | |
| 196 | + ...state, | |
| 197 | + projects: state.projects.filter((project) => project.id !== payload.id), | |
| 198 | + threads: state.threads.filter((thread) => thread.projectId !== payload.id), | |
| 199 | + lastPosition: event.position, | |
| 200 | + }; | |
| 201 | + } | |
| 202 | + case "project.scriptsUpdated": { | |
| 203 | + const payload = event.payload as { | |
| 204 | + id: string; | |
| 205 | + scripts: Array<{ id: string; name: string; command: string; keybinding?: string }>; | |
| 206 | + }; | |
| 207 | + return { | |
| 208 | + ...state, | |
| 209 | + projects: state.projects.map((project) => | |
| 210 | + project.id === payload.id ? { ...project, scripts: payload.scripts } : project, | |
| 211 | + ), | |
| 212 | + lastPosition: event.position, | |
| 213 | + }; | |
| 214 | + } | |
| 215 | + case "thread.created": { | |
| 216 | + const payload = event.payload as { | |
| 217 | + id: string; | |
| 218 | + projectId: string; | |
| 219 | + title: string; | |
| 220 | + model: string; | |
| 221 | + createdAt: string; | |
| 222 | + branch: string | null; | |
| 223 | + worktreePath: string | null; | |
| 224 | + }; | |
| 225 | + if (state.threads.some((thread) => thread.id === payload.id)) { | |
| 226 | + return { ...state, lastPosition: event.position }; | |
| 227 | + } | |
| 228 | + return { ...state, threads: [...state.threads, defaultThread(payload)], lastPosition: event.position }; | |
| 229 | + } | |
| 230 | + case "thread.deleted": { | |
| 231 | + const payload = event.payload as { id: string }; | |
| 232 | + return { ...state, threads: state.threads.filter((thread) => thread.id !== payload.id), lastPosition: event.position }; | |
| 233 | + } | |
| 234 | + case "thread.userMessageAdded": { | |
| 235 | + const payload = event.payload as { | |
| 236 | + threadId: string; | |
| 237 | + messageId: string; | |
| 238 | + text: string; | |
| 239 | + createdAt: string; | |
| 240 | + attachments?: Array<{ | |
| 241 | + type: "image"; | |
| 242 | + id: string; | |
| 243 | + name: string; | |
| 244 | + mimeType: string; | |
| 245 | + sizeBytes: number; | |
| 246 | + previewUrl?: string; | |
| 247 | + }>; | |
| 248 | + }; | |
| 249 | + return { | |
| 250 | + ...state, | |
| 251 | + threads: state.threads.map((thread) => | |
| 252 | + thread.id === payload.threadId | |
| 253 | + ? { | |
| 254 | + ...thread, | |
| 255 | + messages: [ | |
| 256 | + ...thread.messages, | |
| 257 | + { | |
| 258 | + id: payload.messageId, | |
| 259 | + role: "user", | |
| 260 | + text: payload.text, | |
| 261 | + attachments: payload.attachments ? [...payload.attachments] : undefined, | |
| 262 | + createdAt: payload.createdAt, | |
| 263 | + streaming: false, | |
| 264 | + }, | |
| 265 | + ], | |
| 266 | + } | |
| 267 | + : thread, | |
| 268 | + ), | |
| 269 | + lastPosition: event.position, | |
| 270 | + }; | |
| 271 | + } | |
| 272 | + case "thread.providerSessionUpdated": { | |
| 273 | + const payload = event.payload as { threadId: string; session: ProviderSessionView | null }; | |
| 274 | + return { | |
| 275 | + ...state, | |
| 276 | + threads: state.threads.map((thread) => | |
| 277 | + thread.id === payload.threadId | |
| 278 | + ? { | |
| 279 | + ...thread, | |
| 280 | + session: payload.session, | |
| 281 | + codexThreadId: payload.session?.threadId ?? thread.codexThreadId, | |
| 282 | + ...(payload.session ? {} : { events: [], messages: [], turnDiffSummaries: [] }), | |
| 283 | + } | |
| 284 | + : thread, | |
| 285 | + ), | |
| 286 | + lastPosition: event.position, | |
| 287 | + }; | |
| 288 | + } | |
| 289 | + case "thread.providerEventRecorded": { | |
| 290 | + const payload = event.payload as { threadId: string; event: ProviderEvent }; | |
| 291 | + return { | |
| 292 | + ...state, | |
| 293 | + threads: state.threads.map((thread) => { | |
| 294 | + if (thread.id !== payload.threadId) return thread; | |
| 295 | + const nextEvents = [payload.event, ...thread.events]; | |
| 296 | + const nextSession = thread.session ? evolveSession(thread.session, payload.event) : thread.session; | |
| 297 | + const nextMessages = applyEventToMessages(thread.messages, payload.event); | |
| 298 | + const nextTurnId = payload.event.method === "turn/started" ? eventTurnId(payload.event) ?? thread.latestTurnId : thread.latestTurnId; | |
| 299 | + const nextTurnStartedAt = payload.event.method === "turn/started" ? payload.event.createdAt : thread.latestTurnStartedAt; | |
| 300 | + const nextTurnCompletedAt = payload.event.method === "turn/completed" ? payload.event.createdAt : thread.latestTurnCompletedAt; | |
| 301 | + const nextTurnDuration = | |
| 302 | + payload.event.method === "turn/completed" && thread.latestTurnStartedAt | |
| 303 | + ? durationMs(thread.latestTurnStartedAt, payload.event.createdAt) | |
| 304 | + : thread.latestTurnDurationMs; | |
| 305 | + return { | |
| 306 | + ...thread, | |
| 307 | + events: nextEvents, | |
| 308 | + messages: nextMessages, | |
| 309 | + session: nextSession, | |
| 310 | + error: payload.event.kind === "error" && payload.event.message ? payload.event.message : thread.error, | |
| 311 | + latestTurnId: nextTurnId, | |
| 312 | + latestTurnStartedAt: nextTurnStartedAt, | |
| 313 | + latestTurnCompletedAt: nextTurnCompletedAt, | |
| 314 | + latestTurnDurationMs: nextTurnDuration, | |
| 315 | + }; | |
| 316 | + }), | |
| 317 | + lastPosition: event.position, | |
| 318 | + }; | |
| 319 | + } | |
| 320 | + case "thread.branchSet": { | |
| 321 | + const payload = event.payload as { threadId: string; branch: string | null; worktreePath: string | null }; | |
| 322 | + return { | |
| 323 | + ...state, | |
| 324 | + threads: state.threads.map((thread) => | |
| 325 | + thread.id === payload.threadId | |
| 326 | + ? { ...thread, branch: payload.branch, worktreePath: payload.worktreePath } | |
| 327 | + : thread, | |
| 328 | + ), | |
| 329 | + lastPosition: event.position, | |
| 330 | + }; | |
| 331 | + } | |
| 332 | + case "thread.terminalActivitySet": { | |
| 333 | + const payload = event.payload as { threadId: string; terminalId: string; running: boolean }; | |
| 334 | + return { | |
| 335 | + ...state, | |
| 336 | + threads: state.threads.map((thread) => { | |
| 337 | + if (thread.id !== payload.threadId) return thread; | |
| 338 | + const running = new Set(thread.runningTerminalIds); | |
| 339 | + if (payload.running) running.add(payload.terminalId); | |
| 340 | + else running.delete(payload.terminalId); | |
| 341 | + const terminalIds = thread.terminalIds.includes(payload.terminalId) | |
| 342 | + ? thread.terminalIds | |
| 343 | + : [...thread.terminalIds, payload.terminalId]; | |
| 344 | + return { ...thread, terminalIds, runningTerminalIds: [...running] }; | |
| 345 | + }), | |
| 346 | + lastPosition: event.position, | |
| 347 | + }; | |
| 348 | + } | |
| 349 | + case "thread.markVisited": { | |
| 350 | + const payload = event.payload as { threadId: string; visitedAt: string }; | |
| 351 | + return { | |
| 352 | + ...state, | |
| 353 | + threads: state.threads.map((thread) => | |
| 354 | + thread.id === payload.threadId ? { ...thread, lastVisitedAt: payload.visitedAt } : thread, | |
| 355 | + ), | |
| 356 | + lastPosition: event.position, | |
| 357 | + }; | |
| 358 | + } | |
| 359 | + case "runtime.modeSet": { | |
| 360 | + const payload = event.payload as { mode: "approval-required" | "full-access" }; | |
| 361 | + return { ...state, runtimeMode: payload.mode, lastPosition: event.position }; | |
| 362 | + } | |
| 363 | + default: | |
| 364 | + return { ...state, lastPosition: event.position }; | |
| 365 | + } | |
| 366 | +} | |
| 367 | + | |
| 368 | +export function reduceEvents(events: ReadonlyArray<DomainEventEnvelope>, seed?: AppViewState): AppViewState { | |
| 369 | + return events.reduce((state, event) => applyDomainEvent(state, event), seed ?? emptyAppViewState()); | |
| 370 | +} | |
| @@ -0,0 +1,8 @@ | ||
| 1 | +{ | |
| 2 | + "extends": "../../tsconfig.base.json", | |
| 3 | + "compilerOptions": { | |
| 4 | + "lib": ["ES2023"], | |
| 5 | + "types": ["node"] | |
| 6 | + }, | |
| 7 | + "include": ["src/**/*.ts"] | |
| 8 | +} | |
| @@ -0,0 +1,29 @@ | ||
| 1 | +{ | |
| 2 | + "name": "@t3tools/infra-sqlite", | |
| 3 | + "version": "0.0.0", | |
| 4 | + "private": true, | |
| 5 | + "type": "module", | |
| 6 | + "main": "./src/index.ts", | |
| 7 | + "types": "./src/index.ts", | |
| 8 | + "exports": { | |
| 9 | + ".": { | |
| 10 | + "types": "./src/index.ts", | |
| 11 | + "import": "./src/index.ts" | |
| 12 | + } | |
| 13 | + }, | |
| 14 | + "scripts": { | |
| 15 | + "typecheck": "tsc --noEmit", | |
| 16 | + "test": "vitest run --passWithNoTests" | |
| 17 | + }, | |
| 18 | + "dependencies": { | |
| 19 | + "@effect/sql": "^0.49.0", | |
| 20 | + "@effect/sql-sqlite-node": "^0.50.1", | |
| 21 | + "@t3tools/core": "workspace:*", | |
| 22 | + "effect": "^3.18.4" | |
| 23 | + }, | |
| 24 | + "devDependencies": { | |
| 25 | + "@types/node": "^25.3.0", | |
| 26 | + "typescript": "^5.7.3", | |
| 27 | + "vitest": "^4.0.0" | |
| 28 | + } | |
| 29 | +} | |
| @@ -0,0 +1 @@ | ||
| 1 | +export * from "./sqliteStore"; | |
| @@ -0,0 +1,175 @@ | ||
| 1 | +import fs from "node:fs"; | |
| 2 | +import path from "node:path"; | |
| 3 | +import { DatabaseSync } from "node:sqlite"; | |
| 4 | +import crypto from "node:crypto"; | |
| 5 | + | |
| 6 | +import type { AppViewState, DomainEventEnvelope, EventStorePort, NewDomainEvent, ProjectionStorePort } from "@t3tools/core"; | |
| 7 | + | |
| 8 | +interface EventRow { | |
| 9 | + event_id: string; | |
| 10 | + stream_id: string; | |
| 11 | + sequence: number; | |
| 12 | + position: number; | |
| 13 | + type: string; | |
| 14 | + occurred_at: string; | |
| 15 | + payload_json: string; | |
| 16 | + causation_id: string | null; | |
| 17 | + correlation_id: string | null; | |
| 18 | +} | |
| 19 | + | |
| 20 | +function ensureDir(filePath: string): void { | |
| 21 | + fs.mkdirSync(path.dirname(filePath), { recursive: true }); | |
| 22 | +} | |
| 23 | + | |
| 24 | +function parseState(raw: string | null): AppViewState | null { | |
| 25 | + if (!raw) return null; | |
| 26 | + return JSON.parse(raw) as AppViewState; | |
| 27 | +} | |
| 28 | + | |
| 29 | +export class SqliteEventStore implements EventStorePort { | |
| 30 | + constructor(private readonly db: DatabaseSync) {} | |
| 31 | + | |
| 32 | + async append(events: ReadonlyArray<NewDomainEvent>): Promise<ReadonlyArray<DomainEventEnvelope>> { | |
| 33 | + if (events.length === 0) return []; | |
| 34 | + const out: DomainEventEnvelope[] = []; | |
| 35 | + this.db.exec("BEGIN IMMEDIATE TRANSACTION"); | |
| 36 | + try { | |
| 37 | + for (const event of events) { | |
| 38 | + const sequenceStmt = this.db.prepare( | |
| 39 | + "SELECT COALESCE(MAX(sequence), 0) + 1 AS nextSequence FROM events WHERE stream_id = ?", | |
| 40 | + ); | |
| 41 | + const sequenceRow = sequenceStmt.get(event.streamId) as { nextSequence: number }; | |
| 42 | + const insert = this.db.prepare( | |
| 43 | + [ | |
| 44 | + "INSERT INTO events(", | |
| 45 | + "event_id, stream_id, sequence, type, occurred_at, payload_json, causation_id, correlation_id", | |
| 46 | + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?)", | |
| 47 | + ].join(" "), | |
| 48 | + ); | |
| 49 | + const eventId = crypto.randomUUID(); | |
| 50 | + insert.run( | |
| 51 | + eventId, | |
| 52 | + event.streamId, | |
| 53 | + sequenceRow.nextSequence, | |
| 54 | + event.type, | |
| 55 | + event.occurredAt, | |
| 56 | + JSON.stringify(event.payload), | |
| 57 | + event.causationId ?? null, | |
| 58 | + event.correlationId ?? null, | |
| 59 | + ); | |
| 60 | + const positionRow = this.db | |
| 61 | + .prepare("SELECT position FROM events WHERE event_id = ?") | |
| 62 | + .get(eventId) as { position: number }; | |
| 63 | + out.push({ | |
| 64 | + eventId, | |
| 65 | + streamId: event.streamId, | |
| 66 | + sequence: sequenceRow.nextSequence, | |
| 67 | + position: positionRow.position, | |
| 68 | + type: event.type, | |
| 69 | + occurredAt: event.occurredAt, | |
| 70 | + payload: event.payload, | |
| 71 | + ...(event.causationId ? { causationId: event.causationId } : {}), | |
| 72 | + ...(event.correlationId ? { correlationId: event.correlationId } : {}), | |
| 73 | + }); | |
| 74 | + } | |
| 75 | + this.db.exec("COMMIT"); | |
| 76 | + return out; | |
| 77 | + } catch (error) { | |
| 78 | + this.db.exec("ROLLBACK"); | |
| 79 | + throw error; | |
| 80 | + } | |
| 81 | + } | |
| 82 | + | |
| 83 | + async loadAll(): Promise<ReadonlyArray<DomainEventEnvelope>> { | |
| 84 | + const stmt = this.db.prepare( | |
| 85 | + "SELECT event_id, stream_id, sequence, position, type, occurred_at, payload_json, causation_id, correlation_id FROM events ORDER BY position ASC", | |
| 86 | + ); | |
| 87 | + const rows = stmt.all() as unknown as EventRow[]; | |
| 88 | + return rows.map(mapEventRow); | |
| 89 | + } | |
| 90 | + | |
| 91 | + async loadAfterPosition(position: number): Promise<ReadonlyArray<DomainEventEnvelope>> { | |
| 92 | + const stmt = this.db.prepare( | |
| 93 | + "SELECT event_id, stream_id, sequence, position, type, occurred_at, payload_json, causation_id, correlation_id FROM events WHERE position > ? ORDER BY position ASC", | |
| 94 | + ); | |
| 95 | + const rows = stmt.all(position) as unknown as EventRow[]; | |
| 96 | + return rows.map(mapEventRow); | |
| 97 | + } | |
| 98 | +} | |
| 99 | + | |
| 100 | +function mapEventRow(row: EventRow): DomainEventEnvelope { | |
| 101 | + return { | |
| 102 | + eventId: row.event_id, | |
| 103 | + streamId: row.stream_id, | |
| 104 | + sequence: row.sequence, | |
| 105 | + position: row.position, | |
| 106 | + type: row.type as DomainEventEnvelope["type"], | |
| 107 | + occurredAt: row.occurred_at, | |
| 108 | + payload: JSON.parse(row.payload_json) as DomainEventEnvelope["payload"], | |
| 109 | + ...(row.causation_id ? { causationId: row.causation_id } : {}), | |
| 110 | + ...(row.correlation_id ? { correlationId: row.correlation_id } : {}), | |
| 111 | + }; | |
| 112 | +} | |
| 113 | + | |
| 114 | +export class SqliteProjectionStore implements ProjectionStorePort { | |
| 115 | + constructor(private readonly db: DatabaseSync) {} | |
| 116 | + | |
| 117 | + async readState(): Promise<AppViewState | null> { | |
| 118 | + const row = this.db | |
| 119 | + .prepare("SELECT state_json FROM projection_state WHERE projection_name = 'app_state'") | |
| 120 | + .get() as { state_json: string } | undefined; | |
| 121 | + return parseState(row?.state_json ?? null); | |
| 122 | + } | |
| 123 | + | |
| 124 | + async writeState(state: AppViewState): Promise<void> { | |
| 125 | + this.db | |
| 126 | + .prepare( | |
| 127 | + [ | |
| 128 | + "INSERT INTO projection_state(projection_name, state_json, updated_at)", | |
| 129 | + "VALUES('app_state', ?, ?)", | |
| 130 | + "ON CONFLICT(projection_name) DO UPDATE SET", | |
| 131 | + "state_json = excluded.state_json,", | |
| 132 | + "updated_at = excluded.updated_at", | |
| 133 | + ].join(" "), | |
| 134 | + ) | |
| 135 | + .run(JSON.stringify(state), new Date().toISOString()); | |
| 136 | + } | |
| 137 | +} | |
| 138 | + | |
| 139 | +export function createSqliteStores(dbPath: string): { | |
| 140 | + db: DatabaseSync; | |
| 141 | + eventStore: SqliteEventStore; | |
| 142 | + projectionStore: SqliteProjectionStore; | |
| 143 | +} { | |
| 144 | + ensureDir(dbPath); | |
| 145 | + const db = new DatabaseSync(dbPath); | |
| 146 | + db.exec("PRAGMA journal_mode = WAL;"); | |
| 147 | + db.exec("PRAGMA foreign_keys = ON;"); | |
| 148 | + db.exec( | |
| 149 | + [ | |
| 150 | + "CREATE TABLE IF NOT EXISTS events(", | |
| 151 | + "position INTEGER PRIMARY KEY AUTOINCREMENT,", | |
| 152 | + "event_id TEXT NOT NULL UNIQUE,", | |
| 153 | + "stream_id TEXT NOT NULL,", | |
| 154 | + "sequence INTEGER NOT NULL,", | |
| 155 | + "type TEXT NOT NULL,", | |
| 156 | + "occurred_at TEXT NOT NULL,", | |
| 157 | + "payload_json TEXT NOT NULL,", | |
| 158 | + "causation_id TEXT,", | |
| 159 | + "correlation_id TEXT,", | |
| 160 | + "UNIQUE(stream_id, sequence)", | |
| 161 | + ");", | |
| 162 | + "CREATE INDEX IF NOT EXISTS idx_events_stream_position ON events(stream_id, position);", | |
| 163 | + "CREATE TABLE IF NOT EXISTS projection_state(", | |
| 164 | + "projection_name TEXT PRIMARY KEY,", | |
| 165 | + "state_json TEXT NOT NULL,", | |
| 166 | + "updated_at TEXT NOT NULL", | |
| 167 | + ");", | |
| 168 | + ].join(" "), | |
| 169 | + ); | |
| 170 | + return { | |
| 171 | + db, | |
| 172 | + eventStore: new SqliteEventStore(db), | |
| 173 | + projectionStore: new SqliteProjectionStore(db), | |
| 174 | + }; | |
| 175 | +} | |
| @@ -0,0 +1,8 @@ | ||
| 1 | +{ | |
| 2 | + "extends": "../../tsconfig.base.json", | |
| 3 | + "compilerOptions": { | |
| 4 | + "lib": ["ES2023"], | |
| 5 | + "types": ["node"] | |
| 6 | + }, | |
| 7 | + "include": ["src/**/*.ts"] | |
| 8 | +} | |