Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a815adc8b | ||
|
|
35721d9a08 | ||
|
|
f4c9418d40 | ||
|
|
02dd47ea31 | ||
|
|
aca0fa4e5b | ||
|
|
0576820755 | ||
|
|
cb3211c8f3 | ||
|
|
826965978b | ||
|
|
623e471a02 |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
# T3 Code
|
||||
|
||||
T3 Code is a minimal web GUI for coding agents (currently Codex and Claude, more coming soon).
|
||||
T3 Code is a minimal web GUI for coding agents (currently Codex, Claude, and OpenCode, more coming soon).
|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/desktop",
|
||||
"version": "0.0.21",
|
||||
"version": "0.0.22",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "dist-electron/main.cjs",
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
|
||||
import {
|
||||
DEFAULT_THEME_PALETTE,
|
||||
EnvironmentId,
|
||||
type ClientSettings,
|
||||
type PersistedSavedEnvironmentRecord,
|
||||
@@ -63,6 +64,7 @@ const clientSettings: ClientSettings = {
|
||||
sidebarProjectSortOrder: "manual",
|
||||
sidebarThreadSortOrder: "created_at",
|
||||
timestampFormat: "24-hour",
|
||||
themePalette: DEFAULT_THEME_PALETTE,
|
||||
};
|
||||
|
||||
const savedRegistryRecord: PersistedSavedEnvironmentRecord = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "t3",
|
||||
"version": "0.0.21",
|
||||
"version": "0.0.22",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -19,7 +19,6 @@
|
||||
"build": "node scripts/cli.ts build",
|
||||
"build:bundle": "tsdown",
|
||||
"start": "node dist/bin.mjs",
|
||||
"prepare": "effect-language-service patch",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"test:process-reaper": "vitest run src/server.test.ts src/provider/Layers/ClaudeAdapter.test.ts src/provider/Layers/ProviderSessionDirectory.test.ts src/provider/Layers/ProviderSessionReaper.test.ts src/provider/Layers/CodexAdapter.test.ts"
|
||||
@@ -30,7 +29,7 @@
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/sql-sqlite-bun": "catalog:",
|
||||
"@opencode-ai/sdk": "^1.3.15",
|
||||
"@pierre/diffs": "^1.1.0-beta.16",
|
||||
"@pierre/diffs": "catalog:",
|
||||
"effect": "catalog:",
|
||||
"node-pty": "^1.1.0",
|
||||
"open": "^10.1.0"
|
||||
|
||||
@@ -86,10 +86,13 @@ describe("CheckpointDiffQueryLive", () => {
|
||||
Layer.provideMerge(Layer.succeed(CheckpointStore, checkpointStore)),
|
||||
Layer.provideMerge(
|
||||
Layer.succeed(ProjectionSnapshotQuery, {
|
||||
getCommandReadModel: () =>
|
||||
Effect.die("CheckpointDiffQuery should not request the command read model"),
|
||||
getSnapshot: () =>
|
||||
Effect.die("CheckpointDiffQuery should not request the full orchestration snapshot"),
|
||||
getShellSnapshot: () =>
|
||||
Effect.die("CheckpointDiffQuery should not request the orchestration shell snapshot"),
|
||||
getSnapshotSequence: () => Effect.succeed({ snapshotSequence: 0 }),
|
||||
getCounts: () => Effect.succeed({ projectCount: 0, threadCount: 0 }),
|
||||
getActiveProjectByWorkspaceRoot: () => Effect.succeed(Option.none()),
|
||||
getProjectShellById: () => Effect.succeed(Option.none()),
|
||||
@@ -163,10 +166,13 @@ describe("CheckpointDiffQueryLive", () => {
|
||||
Layer.provideMerge(Layer.succeed(CheckpointStore, checkpointStore)),
|
||||
Layer.provideMerge(
|
||||
Layer.succeed(ProjectionSnapshotQuery, {
|
||||
getCommandReadModel: () =>
|
||||
Effect.die("CheckpointDiffQuery should not request the command read model"),
|
||||
getSnapshot: () =>
|
||||
Effect.die("CheckpointDiffQuery should not request the full orchestration snapshot"),
|
||||
getShellSnapshot: () =>
|
||||
Effect.die("CheckpointDiffQuery should not request the orchestration shell snapshot"),
|
||||
getSnapshotSequence: () => Effect.succeed({ snapshotSequence: 0 }),
|
||||
getCounts: () => Effect.succeed({ projectCount: 0, threadCount: 0 }),
|
||||
getActiveProjectByWorkspaceRoot: () => Effect.succeed(Option.none()),
|
||||
getProjectShellById: () => Effect.succeed(Option.none()),
|
||||
@@ -208,10 +214,13 @@ describe("CheckpointDiffQueryLive", () => {
|
||||
Layer.provideMerge(Layer.succeed(CheckpointStore, checkpointStore)),
|
||||
Layer.provideMerge(
|
||||
Layer.succeed(ProjectionSnapshotQuery, {
|
||||
getCommandReadModel: () =>
|
||||
Effect.die("CheckpointDiffQuery should not request the command read model"),
|
||||
getSnapshot: () =>
|
||||
Effect.die("CheckpointDiffQuery should not request the full orchestration snapshot"),
|
||||
getShellSnapshot: () =>
|
||||
Effect.die("CheckpointDiffQuery should not request the orchestration shell snapshot"),
|
||||
getSnapshotSequence: () => Effect.succeed({ snapshotSequence: 0 }),
|
||||
getCounts: () => Effect.succeed({ projectCount: 0, threadCount: 0 }),
|
||||
getActiveProjectByWorkspaceRoot: () => Effect.succeed(Option.none()),
|
||||
getProjectShellById: () => Effect.succeed(Option.none()),
|
||||
|
||||
@@ -17,7 +17,6 @@ import { Command } from "effect/unstable/cli";
|
||||
|
||||
import { cli } from "./cli.ts";
|
||||
import { deriveServerPaths, ServerConfig, type ServerConfigShape } from "./config.ts";
|
||||
import { OrchestrationEngineService } from "./orchestration/Services/OrchestrationEngine.ts";
|
||||
import { ProjectionSnapshotQuery } from "./orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import { OrchestrationLayerLive } from "./orchestration/runtimeLayer.ts";
|
||||
import {
|
||||
@@ -316,8 +315,8 @@ it.layer(NodeServices.layer)("cli log-level parsing", (it) => {
|
||||
"--base-dir",
|
||||
baseDir,
|
||||
]);
|
||||
const orchestrationEngine = yield* OrchestrationEngineService;
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
const readModel = yield* projectionSnapshotQuery.getSnapshot();
|
||||
const addedProject = readModel.projects.find(
|
||||
(project) => project.workspaceRoot === workspaceRoot && project.deletedAt === null,
|
||||
);
|
||||
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
type OrchestrationEngineShape,
|
||||
} from "../Services/OrchestrationEngine.ts";
|
||||
import { CheckpointReactor } from "../Services/CheckpointReactor.ts";
|
||||
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
|
||||
import {
|
||||
ProviderService,
|
||||
type ProviderServiceShape,
|
||||
@@ -132,7 +133,14 @@ function createProviderServiceHarness(
|
||||
}
|
||||
|
||||
async function waitForThread(
|
||||
engine: OrchestrationEngineShape,
|
||||
readModel: () => Promise<{
|
||||
readonly threads: ReadonlyArray<{
|
||||
readonly id: ThreadId;
|
||||
readonly latestTurn: { readonly turnId: string } | null;
|
||||
readonly checkpoints: ReadonlyArray<{ readonly checkpointTurnCount: number }>;
|
||||
readonly activities: ReadonlyArray<{ readonly kind: string }>;
|
||||
}>;
|
||||
}>,
|
||||
predicate: (thread: {
|
||||
latestTurn: { turnId: string } | null;
|
||||
checkpoints: ReadonlyArray<{ checkpointTurnCount: number }>;
|
||||
@@ -146,8 +154,8 @@ async function waitForThread(
|
||||
checkpoints: ReadonlyArray<{ checkpointTurnCount: number }>;
|
||||
activities: ReadonlyArray<{ kind: string }>;
|
||||
}> => {
|
||||
const readModel = await Effect.runPromise(engine.getReadModel());
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
const snapshot = await readModel();
|
||||
const thread = snapshot.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
if (thread && predicate(thread)) {
|
||||
return thread;
|
||||
}
|
||||
@@ -231,7 +239,7 @@ async function waitForGitRefExists(cwd: string, ref: string, timeoutMs = 15_000)
|
||||
|
||||
describe("CheckpointReactor", () => {
|
||||
let runtime: ManagedRuntime.ManagedRuntime<
|
||||
OrchestrationEngineService | CheckpointReactor | CheckpointStore,
|
||||
OrchestrationEngineService | CheckpointReactor | CheckpointStore | ProjectionSnapshotQuery,
|
||||
unknown
|
||||
> | null = null;
|
||||
let scope: Scope.Closeable | null = null;
|
||||
@@ -279,6 +287,10 @@ describe("CheckpointReactor", () => {
|
||||
Layer.provide(RepositoryIdentityResolverLive),
|
||||
Layer.provide(SqlitePersistenceMemory),
|
||||
);
|
||||
const projectionSnapshotLayer = OrchestrationProjectionSnapshotQueryLive.pipe(
|
||||
Layer.provide(RepositoryIdentityResolverLive),
|
||||
Layer.provide(SqlitePersistenceMemory),
|
||||
);
|
||||
|
||||
const ServerConfigLayer = ServerConfig.layerTest(process.cwd(), {
|
||||
prefix: "t3-checkpoint-reactor-test-",
|
||||
@@ -304,6 +316,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
const layer = CheckpointReactorLive.pipe(
|
||||
Layer.provideMerge(orchestrationLayer),
|
||||
Layer.provideMerge(projectionSnapshotLayer),
|
||||
Layer.provideMerge(RuntimeReceiptBusLive),
|
||||
Layer.provideMerge(Layer.succeed(ProviderService, provider.service)),
|
||||
Layer.provideMerge(vcsStatusBroadcasterLayer),
|
||||
@@ -322,6 +335,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
runtime = ManagedRuntime.make(layer);
|
||||
const engine = await runtime.runPromise(Effect.service(OrchestrationEngineService));
|
||||
const snapshotQuery = await runtime.runPromise(Effect.service(ProjectionSnapshotQuery));
|
||||
const reactor = await runtime.runPromise(Effect.service(CheckpointReactor));
|
||||
const checkpointStore = await runtime.runPromise(Effect.service(CheckpointStore));
|
||||
scope = await Effect.runPromise(Scope.make("sequential"));
|
||||
@@ -387,6 +401,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
return {
|
||||
engine,
|
||||
readModel: () => Effect.runPromise(snapshotQuery.getSnapshot()),
|
||||
provider,
|
||||
cwd,
|
||||
drain,
|
||||
@@ -443,7 +458,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
await waitForEvent(harness.engine, (event) => event.type === "thread.turn-diff-completed");
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) => entry.latestTurn?.turnId === "turn-1" && entry.checkpoints.length === 1,
|
||||
);
|
||||
expect(thread.checkpoints[0]?.checkpointTurnCount).toBe(1);
|
||||
@@ -541,7 +556,7 @@ describe("CheckpointReactor", () => {
|
||||
});
|
||||
|
||||
await harness.drain();
|
||||
const midReadModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const midReadModel = await harness.readModel();
|
||||
const midThread = midReadModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(midThread?.checkpoints).toHaveLength(0);
|
||||
|
||||
@@ -557,7 +572,7 @@ describe("CheckpointReactor", () => {
|
||||
});
|
||||
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) => entry.latestTurn?.turnId === "turn-main" && entry.checkpoints.length === 1,
|
||||
);
|
||||
expect(thread.checkpoints[0]?.checkpointTurnCount).toBe(1);
|
||||
@@ -614,7 +629,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
await waitForEvent(harness.engine, (event) => event.type === "thread.turn-diff-completed");
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) => entry.latestTurn?.turnId === "turn-claude-1" && entry.checkpoints.length === 1,
|
||||
);
|
||||
|
||||
@@ -659,7 +674,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
await waitForEvent(harness.engine, (event) => event.type === "thread.turn-diff-completed");
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.checkpoints.length === 1 &&
|
||||
entry.activities.some((activity) => activity.kind === "checkpoint.capture.failed"),
|
||||
@@ -794,7 +809,7 @@ describe("CheckpointReactor", () => {
|
||||
});
|
||||
|
||||
await harness.drain();
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.checkpoints.some((checkpoint) => checkpoint.checkpointTurnCount === 3)).toBe(
|
||||
false,
|
||||
@@ -923,7 +938,10 @@ describe("CheckpointReactor", () => {
|
||||
);
|
||||
|
||||
await waitForEvent(harness.engine, (event) => event.type === "thread.reverted");
|
||||
const thread = await waitForThread(harness.engine, (entry) => entry.checkpoints.length === 1);
|
||||
const thread = await waitForThread(
|
||||
harness.readModel,
|
||||
(entry) => entry.checkpoints.length === 1,
|
||||
);
|
||||
|
||||
expect(thread.latestTurn?.turnId).toBe("turn-1");
|
||||
expect(thread.checkpoints).toHaveLength(1);
|
||||
@@ -1105,7 +1123,7 @@ describe("CheckpointReactor", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.activities.some((activity) => activity.kind === "checkpoint.revert.failed"),
|
||||
);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import { CheckpointStore } from "../../checkpointing/Services/CheckpointStore.ts
|
||||
import { ProviderService } from "../../provider/Services/ProviderService.ts";
|
||||
import { CheckpointReactor, type CheckpointReactorShape } from "../Services/CheckpointReactor.ts";
|
||||
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
|
||||
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
|
||||
import { RuntimeReceiptBus } from "../Services/RuntimeReceiptBus.ts";
|
||||
import type { CheckpointStoreError } from "../../checkpointing/Errors.ts";
|
||||
import type { OrchestrationDispatchError } from "../Errors.ts";
|
||||
@@ -66,6 +67,7 @@ const serverCommandId = (tag: string): CommandId =>
|
||||
|
||||
const make = Effect.gen(function* () {
|
||||
const orchestrationEngine = yield* OrchestrationEngineService;
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
const providerService = yield* ProviderService;
|
||||
const checkpointStore = yield* CheckpointStore;
|
||||
const receiptBus = yield* RuntimeReceiptBus;
|
||||
@@ -124,29 +126,26 @@ const make = Effect.gen(function* () {
|
||||
const resolveSessionRuntimeForThread = Effect.fn("resolveSessionRuntimeForThread")(function* (
|
||||
threadId: ThreadId,
|
||||
): Effect.fn.Return<Option.Option<{ readonly threadId: ThreadId; readonly cwd: string }>> {
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === threadId);
|
||||
|
||||
const sessions = yield* providerService.listSessions();
|
||||
const session = sessions.find((entry) => entry.threadId === threadId);
|
||||
return session?.cwd
|
||||
? Option.some({ threadId: session.threadId, cwd: session.cwd })
|
||||
: Option.none();
|
||||
});
|
||||
|
||||
const findSessionWithCwd = (
|
||||
session: (typeof sessions)[number] | undefined,
|
||||
): Option.Option<{ readonly threadId: ThreadId; readonly cwd: string }> => {
|
||||
if (!session?.cwd) {
|
||||
return Option.none();
|
||||
}
|
||||
return Option.some({ threadId: session.threadId, cwd: session.cwd });
|
||||
};
|
||||
const resolveThreadDetail = Effect.fn("resolveThreadDetail")(function* (threadId: ThreadId) {
|
||||
return yield* projectionSnapshotQuery
|
||||
.getThreadDetailById(threadId)
|
||||
.pipe(Effect.map(Option.getOrUndefined));
|
||||
});
|
||||
|
||||
if (thread) {
|
||||
const projectedSession = sessions.find((session) => session.threadId === thread.id);
|
||||
const fromProjected = findSessionWithCwd(projectedSession);
|
||||
if (Option.isSome(fromProjected)) {
|
||||
return fromProjected;
|
||||
}
|
||||
}
|
||||
|
||||
return Option.none();
|
||||
const resolveThreadProjects = Effect.fn("resolveThreadProjects")(function* (
|
||||
projectId: ProjectId,
|
||||
) {
|
||||
const project = yield* projectionSnapshotQuery
|
||||
.getProjectShellById(projectId)
|
||||
.pipe(Effect.map(Option.getOrUndefined));
|
||||
return project ? [project] : [];
|
||||
});
|
||||
|
||||
const isGitWorkspace = (cwd: string) => isGitRepository(cwd);
|
||||
@@ -331,8 +330,7 @@ const make = Effect.gen(function* () {
|
||||
return;
|
||||
}
|
||||
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === event.threadId);
|
||||
const thread = yield* resolveThreadDetail(event.threadId);
|
||||
if (!thread) {
|
||||
return;
|
||||
}
|
||||
@@ -353,10 +351,11 @@ const make = Effect.gen(function* () {
|
||||
return;
|
||||
}
|
||||
|
||||
const projects = yield* resolveThreadProjects(thread.projectId);
|
||||
const checkpointCwd = yield* resolveCheckpointCwd({
|
||||
threadId: thread.id,
|
||||
thread,
|
||||
projects: readModel.projects,
|
||||
projects,
|
||||
preferSessionRuntime: true,
|
||||
});
|
||||
if (!checkpointCwd) {
|
||||
@@ -407,8 +406,7 @@ const make = Effect.gen(function* () {
|
||||
return;
|
||||
}
|
||||
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === threadId);
|
||||
const thread = yield* resolveThreadDetail(threadId);
|
||||
if (!thread) {
|
||||
yield* Effect.logWarning("checkpoint capture from placeholder skipped: thread not found", {
|
||||
threadId,
|
||||
@@ -429,10 +427,11 @@ const make = Effect.gen(function* () {
|
||||
return;
|
||||
}
|
||||
|
||||
const projects = yield* resolveThreadProjects(thread.projectId);
|
||||
const checkpointCwd = yield* resolveCheckpointCwd({
|
||||
threadId,
|
||||
thread,
|
||||
projects: readModel.projects,
|
||||
projects,
|
||||
preferSessionRuntime: true,
|
||||
});
|
||||
if (!checkpointCwd) {
|
||||
@@ -458,16 +457,16 @@ const make = Effect.gen(function* () {
|
||||
return;
|
||||
}
|
||||
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === event.threadId);
|
||||
const thread = yield* resolveThreadDetail(event.threadId);
|
||||
if (!thread) {
|
||||
return;
|
||||
}
|
||||
|
||||
const projects = yield* resolveThreadProjects(thread.projectId);
|
||||
const checkpointCwd = yield* resolveCheckpointCwd({
|
||||
threadId: thread.id,
|
||||
thread,
|
||||
projects: readModel.projects,
|
||||
projects,
|
||||
preferSessionRuntime: false,
|
||||
});
|
||||
if (!checkpointCwd) {
|
||||
@@ -540,16 +539,16 @@ const make = Effect.gen(function* () {
|
||||
}
|
||||
|
||||
const threadId = event.payload.threadId;
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === threadId);
|
||||
const thread = yield* resolveThreadDetail(threadId);
|
||||
if (!thread) {
|
||||
return;
|
||||
}
|
||||
|
||||
const projects = yield* resolveThreadProjects(thread.projectId);
|
||||
const checkpointCwd = yield* resolveCheckpointCwd({
|
||||
threadId,
|
||||
thread,
|
||||
projects: readModel.projects,
|
||||
projects,
|
||||
preferSessionRuntime: false,
|
||||
});
|
||||
if (!checkpointCwd) {
|
||||
@@ -587,8 +586,7 @@ const make = Effect.gen(function* () {
|
||||
) {
|
||||
const now = new Date().toISOString();
|
||||
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === event.payload.threadId);
|
||||
const thread = yield* resolveThreadDetail(event.payload.threadId);
|
||||
if (!thread) {
|
||||
yield* appendRevertFailureActivity({
|
||||
threadId: event.payload.threadId,
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
TurnId,
|
||||
type OrchestrationEvent,
|
||||
ProviderInstanceId,
|
||||
type OrchestrationReadModel,
|
||||
} from "@t3tools/contracts";
|
||||
import { Effect, Layer, ManagedRuntime, Metric, Option, Queue, Stream } from "effect";
|
||||
import { describe, expect, it } from "vitest";
|
||||
@@ -42,9 +43,13 @@ async function createOrchestrationSystem() {
|
||||
const ServerConfigLayer = ServerConfig.layerTest(process.cwd(), {
|
||||
prefix: "t3-orchestration-engine-test-",
|
||||
});
|
||||
const orchestrationLayer = OrchestrationEngineLive.pipe(
|
||||
Layer.provide(OrchestrationProjectionSnapshotQueryLive),
|
||||
Layer.provide(OrchestrationProjectionPipelineLive),
|
||||
const orchestrationLayer = Layer.mergeAll(
|
||||
OrchestrationEngineLive.pipe(
|
||||
Layer.provide(OrchestrationProjectionSnapshotQueryLive),
|
||||
Layer.provide(OrchestrationProjectionPipelineLive),
|
||||
),
|
||||
OrchestrationProjectionSnapshotQueryLive,
|
||||
).pipe(
|
||||
Layer.provide(OrchestrationEventStoreLive),
|
||||
Layer.provide(OrchestrationCommandReceiptRepositoryLive),
|
||||
Layer.provide(RepositoryIdentityResolverLive),
|
||||
@@ -54,8 +59,10 @@ async function createOrchestrationSystem() {
|
||||
);
|
||||
const runtime = ManagedRuntime.make(orchestrationLayer);
|
||||
const engine = await runtime.runPromise(Effect.service(OrchestrationEngineService));
|
||||
const snapshotQuery = await runtime.runPromise(Effect.service(ProjectionSnapshotQuery));
|
||||
return {
|
||||
engine,
|
||||
readModel: () => runtime.runPromise(snapshotQuery.getSnapshot()),
|
||||
run: <A, E>(effect: Effect.Effect<A, E>) => runtime.runPromise(effect),
|
||||
dispose: () => runtime.dispose(),
|
||||
};
|
||||
@@ -77,15 +84,18 @@ const hasMetricSnapshot = (
|
||||
);
|
||||
|
||||
describe("OrchestrationEngine", () => {
|
||||
it("bootstraps the in-memory read model from persisted projections", async () => {
|
||||
const failOnHistoricalReplayStore: OrchestrationEventStoreShape = {
|
||||
append: () =>
|
||||
Effect.fail(
|
||||
new PersistenceSqlError({
|
||||
operation: "test.append",
|
||||
detail: "append should not be called during bootstrap",
|
||||
}),
|
||||
),
|
||||
it("bootstraps command handling from persisted projections without reading the full snapshot", async () => {
|
||||
let nextSequence = 8;
|
||||
const eventStore: OrchestrationEventStoreShape = {
|
||||
append: (event) =>
|
||||
Effect.sync(() => {
|
||||
const savedEvent = {
|
||||
...event,
|
||||
sequence: nextSequence,
|
||||
} as OrchestrationEvent;
|
||||
nextSequence += 1;
|
||||
return savedEvent;
|
||||
}),
|
||||
readFromSequence: () => Stream.empty,
|
||||
readAll: () =>
|
||||
Stream.fail(
|
||||
@@ -140,11 +150,27 @@ describe("OrchestrationEngine", () => {
|
||||
},
|
||||
],
|
||||
};
|
||||
const commandReadModel = {
|
||||
...projectionSnapshot,
|
||||
threads: projectionSnapshot.threads.map((thread) => ({
|
||||
...thread,
|
||||
messages: [],
|
||||
proposedPlans: [],
|
||||
activities: [],
|
||||
checkpoints: [],
|
||||
})),
|
||||
};
|
||||
let fullSnapshotReadCount = 0;
|
||||
|
||||
const layer = OrchestrationEngineLive.pipe(
|
||||
Layer.provide(
|
||||
Layer.succeed(ProjectionSnapshotQuery, {
|
||||
getSnapshot: () => Effect.succeed(projectionSnapshot),
|
||||
getCommandReadModel: () => Effect.succeed(commandReadModel),
|
||||
getSnapshot: () =>
|
||||
Effect.sync(() => {
|
||||
fullSnapshotReadCount += 1;
|
||||
return projectionSnapshot;
|
||||
}),
|
||||
getShellSnapshot: () =>
|
||||
Effect.succeed({
|
||||
snapshotSequence: projectionSnapshot.snapshotSequence,
|
||||
@@ -152,6 +178,8 @@ describe("OrchestrationEngine", () => {
|
||||
threads: [],
|
||||
updatedAt: projectionSnapshot.updatedAt,
|
||||
}),
|
||||
getSnapshotSequence: () =>
|
||||
Effect.succeed({ snapshotSequence: projectionSnapshot.snapshotSequence }),
|
||||
getCounts: () => Effect.succeed({ projectCount: 1, threadCount: 1 }),
|
||||
getActiveProjectByWorkspaceRoot: () => Effect.succeed(Option.none()),
|
||||
getProjectShellById: () => Effect.succeed(Option.none()),
|
||||
@@ -167,7 +195,7 @@ describe("OrchestrationEngine", () => {
|
||||
projectEvent: () => Effect.void,
|
||||
} satisfies OrchestrationProjectionPipelineShape),
|
||||
),
|
||||
Layer.provide(Layer.succeed(OrchestrationEventStore, failOnHistoricalReplayStore)),
|
||||
Layer.provide(Layer.succeed(OrchestrationEventStore, eventStore)),
|
||||
Layer.provide(OrchestrationCommandReceiptRepositoryLive),
|
||||
Layer.provide(SqlitePersistenceMemory),
|
||||
);
|
||||
@@ -175,18 +203,22 @@ describe("OrchestrationEngine", () => {
|
||||
const runtime = ManagedRuntime.make(layer);
|
||||
|
||||
const engine = await runtime.runPromise(Effect.service(OrchestrationEngineService));
|
||||
const readModel = await runtime.runPromise(engine.getReadModel());
|
||||
const result = await runtime.runPromise(
|
||||
engine.dispatch({
|
||||
type: "thread.meta.update",
|
||||
commandId: CommandId.make("cmd-bootstrap-thread-update"),
|
||||
threadId: ThreadId.make("thread-bootstrap"),
|
||||
title: "Updated Bootstrap Thread",
|
||||
}),
|
||||
);
|
||||
|
||||
expect(readModel.snapshotSequence).toBe(7);
|
||||
expect(readModel.projects).toHaveLength(1);
|
||||
expect(readModel.projects[0]?.title).toBe("Bootstrap Project");
|
||||
expect(readModel.threads).toHaveLength(1);
|
||||
expect(readModel.threads[0]?.title).toBe("Bootstrap Thread");
|
||||
expect(result.sequence).toBe(8);
|
||||
expect(fullSnapshotReadCount).toBe(0);
|
||||
|
||||
await runtime.dispose();
|
||||
});
|
||||
|
||||
it("returns deterministic read models for repeated reads", async () => {
|
||||
it("persists deterministic read models for repeated snapshot reads", async () => {
|
||||
const createdAt = now();
|
||||
const system = await createOrchestrationSystem();
|
||||
const { engine } = system;
|
||||
@@ -240,8 +272,8 @@ describe("OrchestrationEngine", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const readModelA = await system.run(engine.getReadModel());
|
||||
const readModelB = await system.run(engine.getReadModel());
|
||||
const readModelA = await system.readModel();
|
||||
const readModelB = await system.readModel();
|
||||
expect(readModelB).toEqual(readModelA);
|
||||
await system.dispose();
|
||||
});
|
||||
@@ -292,9 +324,8 @@ describe("OrchestrationEngine", () => {
|
||||
}),
|
||||
);
|
||||
expect(
|
||||
(await system.run(engine.getReadModel())).threads.find(
|
||||
(thread) => thread.id === "thread-archive",
|
||||
)?.archivedAt,
|
||||
(await system.readModel()).threads.find((thread) => thread.id === "thread-archive")
|
||||
?.archivedAt,
|
||||
).not.toBeNull();
|
||||
|
||||
await system.run(
|
||||
@@ -305,9 +336,8 @@ describe("OrchestrationEngine", () => {
|
||||
}),
|
||||
);
|
||||
expect(
|
||||
(await system.run(engine.getReadModel())).threads.find(
|
||||
(thread) => thread.id === "thread-archive",
|
||||
)?.archivedAt,
|
||||
(await system.readModel()).threads.find((thread) => thread.id === "thread-archive")
|
||||
?.archivedAt,
|
||||
).toBeNull();
|
||||
|
||||
await system.dispose();
|
||||
@@ -573,7 +603,7 @@ describe("OrchestrationEngine", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const thread = (await system.run(engine.getReadModel())).threads.find(
|
||||
const thread = (await system.readModel()).threads.find(
|
||||
(entry) => entry.id === "thread-turn-diff",
|
||||
);
|
||||
expect(thread?.checkpoints).toEqual([
|
||||
@@ -701,7 +731,15 @@ describe("OrchestrationEngine", () => {
|
||||
);
|
||||
|
||||
expect(result.sequence).toBe(2);
|
||||
expect((await runtime.runPromise(engine.getReadModel())).snapshotSequence).toBe(2);
|
||||
const eventsAfterRetry = await runtime.runPromise(
|
||||
Stream.runCollect(engine.readEvents(0)).pipe(
|
||||
Effect.map((chunk): OrchestrationEvent[] => Array.from(chunk)),
|
||||
),
|
||||
);
|
||||
expect(eventsAfterRetry.map((event) => event.type)).toEqual([
|
||||
"project.created",
|
||||
"thread.created",
|
||||
]);
|
||||
await runtime.dispose();
|
||||
});
|
||||
|
||||
@@ -801,7 +839,6 @@ describe("OrchestrationEngine", () => {
|
||||
"project.created",
|
||||
"thread.created",
|
||||
]);
|
||||
expect((await runtime.runPromise(engine.getReadModel())).snapshotSequence).toBe(2);
|
||||
|
||||
const retryResult = await runtime.runPromise(engine.dispatch(turnStartCommand));
|
||||
expect(retryResult.sequence).toBe(4);
|
||||
@@ -824,7 +861,7 @@ describe("OrchestrationEngine", () => {
|
||||
await runtime.dispose();
|
||||
});
|
||||
|
||||
it("reconciles in-memory state when append persists but projection fails", async () => {
|
||||
it("reconciles command state when append persists but projection fails", async () => {
|
||||
type StoredEvent =
|
||||
ReturnType<OrchestrationEventStoreShape["append"]> extends Effect.Effect<infer A, any, any>
|
||||
? A
|
||||
@@ -856,7 +893,7 @@ describe("OrchestrationEngine", () => {
|
||||
projectEvent: (event) => {
|
||||
if (
|
||||
shouldFailProjection &&
|
||||
event.commandId === CommandId.make("cmd-thread-meta-sync-fail")
|
||||
event.commandId === CommandId.make("cmd-thread-archive-sync-fail")
|
||||
) {
|
||||
shouldFailProjection = false;
|
||||
return Effect.fail(
|
||||
@@ -919,20 +956,22 @@ describe("OrchestrationEngine", () => {
|
||||
await expect(
|
||||
runtime.runPromise(
|
||||
engine.dispatch({
|
||||
type: "thread.meta.update",
|
||||
commandId: CommandId.make("cmd-thread-meta-sync-fail"),
|
||||
type: "thread.archive",
|
||||
commandId: CommandId.make("cmd-thread-archive-sync-fail"),
|
||||
threadId: ThreadId.make("thread-sync"),
|
||||
title: "sync-after-failed-projection",
|
||||
}),
|
||||
),
|
||||
).rejects.toThrow("projection failed");
|
||||
|
||||
const readModelAfterFailure = await runtime.runPromise(engine.getReadModel());
|
||||
const updatedThread = readModelAfterFailure.threads.find(
|
||||
(thread) => thread.id === "thread-sync",
|
||||
);
|
||||
expect(readModelAfterFailure.snapshotSequence).toBe(3);
|
||||
expect(updatedThread?.title).toBe("sync-after-failed-projection");
|
||||
await expect(
|
||||
runtime.runPromise(
|
||||
engine.dispatch({
|
||||
type: "thread.archive",
|
||||
commandId: CommandId.make("cmd-thread-archive-sync-retry"),
|
||||
threadId: ThreadId.make("thread-sync"),
|
||||
}),
|
||||
),
|
||||
).rejects.toThrow("already archived");
|
||||
|
||||
await runtime.dispose();
|
||||
});
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
OrchestrationCommandInvariantError,
|
||||
OrchestrationCommandPreviouslyRejectedError,
|
||||
type OrchestrationDispatchError,
|
||||
type OrchestrationProjectorDecodeError,
|
||||
} from "../Errors.ts";
|
||||
import { decideOrchestrationCommand } from "../decider.ts";
|
||||
import { createEmptyReadModel, projectEvent } from "../projector.ts";
|
||||
@@ -77,13 +78,25 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
|
||||
let readModel = createEmptyReadModel(new Date().toISOString());
|
||||
let commandReadModel = createEmptyReadModel(new Date().toISOString());
|
||||
|
||||
const commandQueue = yield* Queue.unbounded<CommandEnvelope>();
|
||||
const eventPubSub = yield* PubSub.unbounded<OrchestrationEvent>();
|
||||
|
||||
const projectEventsOntoReadModel = (
|
||||
baseReadModel: OrchestrationReadModel,
|
||||
events: ReadonlyArray<OrchestrationEvent>,
|
||||
): Effect.Effect<OrchestrationReadModel, OrchestrationProjectorDecodeError, never> =>
|
||||
Effect.gen(function* () {
|
||||
let nextReadModel = baseReadModel;
|
||||
for (const event of events) {
|
||||
nextReadModel = yield* projectEvent(nextReadModel, event);
|
||||
}
|
||||
return nextReadModel;
|
||||
});
|
||||
|
||||
const processEnvelope = (envelope: CommandEnvelope): Effect.Effect<void> => {
|
||||
const dispatchStartSequence = readModel.snapshotSequence;
|
||||
const dispatchStartSequence = commandReadModel.snapshotSequence;
|
||||
const processingStartedAtMs = Date.now();
|
||||
const aggregateRef = commandToAggregateRef(envelope.command);
|
||||
const baseMetricAttributes = {
|
||||
@@ -98,11 +111,7 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
return;
|
||||
}
|
||||
|
||||
let nextReadModel = readModel;
|
||||
for (const persistedEvent of persistedEvents) {
|
||||
nextReadModel = yield* projectEvent(nextReadModel, persistedEvent);
|
||||
}
|
||||
readModel = nextReadModel;
|
||||
commandReadModel = yield* projectEventsOntoReadModel(commandReadModel, persistedEvents);
|
||||
|
||||
for (const persistedEvent of persistedEvents) {
|
||||
yield* PubSub.publish(eventPubSub, persistedEvent);
|
||||
@@ -135,18 +144,18 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
|
||||
const eventBase = yield* decideOrchestrationCommand({
|
||||
command: envelope.command,
|
||||
readModel,
|
||||
readModel: commandReadModel,
|
||||
});
|
||||
const eventBases = Array.isArray(eventBase) ? eventBase : [eventBase];
|
||||
const committedCommand = yield* sql
|
||||
.withTransaction(
|
||||
Effect.gen(function* () {
|
||||
const committedEvents: OrchestrationEvent[] = [];
|
||||
let nextReadModel = readModel;
|
||||
let nextCommandReadModel = commandReadModel;
|
||||
|
||||
for (const nextEvent of eventBases) {
|
||||
const savedEvent = yield* eventStore.append(nextEvent);
|
||||
nextReadModel = yield* projectEvent(nextReadModel, savedEvent);
|
||||
nextCommandReadModel = yield* projectEvent(nextCommandReadModel, savedEvent);
|
||||
yield* projectionPipeline.projectEvent(savedEvent);
|
||||
committedEvents.push(savedEvent);
|
||||
}
|
||||
@@ -172,7 +181,7 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
return {
|
||||
committedEvents,
|
||||
lastSequence: lastSavedEvent.sequence,
|
||||
nextReadModel,
|
||||
nextCommandReadModel,
|
||||
} as const;
|
||||
}),
|
||||
)
|
||||
@@ -184,7 +193,7 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
),
|
||||
);
|
||||
|
||||
readModel = committedCommand.nextReadModel;
|
||||
commandReadModel = committedCommand.nextCommandReadModel;
|
||||
for (const [index, event] of committedCommand.committedEvents.entries()) {
|
||||
yield* PubSub.publish(eventPubSub, event);
|
||||
if (index === 0) {
|
||||
@@ -242,7 +251,7 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
).pipe(
|
||||
Effect.annotateLogs({
|
||||
commandId: envelope.command.commandId,
|
||||
snapshotSequence: readModel.snapshotSequence,
|
||||
snapshotSequence: commandReadModel.snapshotSequence,
|
||||
}),
|
||||
),
|
||||
),
|
||||
@@ -255,7 +264,7 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
aggregateKind: aggregateRef.aggregateKind,
|
||||
aggregateId: aggregateRef.aggregateId,
|
||||
acceptedAt: new Date().toISOString(),
|
||||
resultSequence: readModel.snapshotSequence,
|
||||
resultSequence: commandReadModel.snapshotSequence,
|
||||
status: "rejected",
|
||||
error: error.message,
|
||||
})
|
||||
@@ -270,17 +279,14 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
};
|
||||
|
||||
yield* projectionPipeline.bootstrap;
|
||||
readModel = yield* projectionSnapshotQuery.getSnapshot();
|
||||
commandReadModel = yield* projectionSnapshotQuery.getCommandReadModel();
|
||||
|
||||
const worker = Effect.forever(Queue.take(commandQueue).pipe(Effect.flatMap(processEnvelope)));
|
||||
yield* Effect.forkScoped(worker);
|
||||
yield* Effect.logDebug("orchestration engine started").pipe(
|
||||
Effect.annotateLogs({ sequence: readModel.snapshotSequence }),
|
||||
Effect.annotateLogs({ sequence: commandReadModel.snapshotSequence }),
|
||||
);
|
||||
|
||||
const getReadModel: OrchestrationEngineShape["getReadModel"] = () =>
|
||||
Effect.sync((): OrchestrationReadModel => readModel);
|
||||
|
||||
const readEvents: OrchestrationEngineShape["readEvents"] = (fromSequenceExclusive) =>
|
||||
eventStore.readFromSequence(fromSequenceExclusive);
|
||||
|
||||
@@ -292,7 +298,6 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
});
|
||||
|
||||
return {
|
||||
getReadModel,
|
||||
readEvents,
|
||||
dispatch,
|
||||
// Each access creates a fresh PubSub subscription so that multiple
|
||||
|
||||
@@ -739,9 +739,31 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
|
||||
if (Option.isNone(existingRow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const retainedTurns = yield* projectionTurnRepository.listByThreadId({
|
||||
threadId: event.payload.threadId,
|
||||
});
|
||||
let latestTurnId: ProjectionTurn["turnId"] = null;
|
||||
let latestCheckpointTurnCount = -1;
|
||||
for (let index = 0; index < retainedTurns.length; index += 1) {
|
||||
const turn = retainedTurns[index];
|
||||
if (
|
||||
!turn ||
|
||||
turn.turnId === null ||
|
||||
turn.checkpointTurnCount === null ||
|
||||
turn.checkpointTurnCount > event.payload.turnCount
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (turn.checkpointTurnCount > latestCheckpointTurnCount) {
|
||||
latestCheckpointTurnCount = turn.checkpointTurnCount;
|
||||
latestTurnId = turn.turnId;
|
||||
}
|
||||
}
|
||||
|
||||
yield* projectionThreadRepository.upsert({
|
||||
...existingRow.value,
|
||||
latestTurnId: null,
|
||||
latestTurnId,
|
||||
updatedAt: event.occurredAt,
|
||||
});
|
||||
yield* refreshThreadShellSummary(event.payload.threadId);
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Effect, Layer } from "effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
|
||||
import { RepositoryIdentityResolver } from "../../project/Services/RepositoryIdentityResolver.ts";
|
||||
import { RepositoryIdentityResolverLive } from "../../project/Layers/RepositoryIdentityResolver.ts";
|
||||
import { ORCHESTRATION_PROJECTOR_NAMES } from "./ProjectionPipeline.ts";
|
||||
import { OrchestrationProjectionSnapshotQueryLive } from "./ProjectionSnapshotQuery.ts";
|
||||
@@ -1029,4 +1030,378 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("uses projection_threads.latest_turn_id for bulk command and shell snapshots", () =>
|
||||
Effect.gen(function* () {
|
||||
const snapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* sql`DELETE FROM projection_projects`;
|
||||
yield* sql`DELETE FROM projection_threads`;
|
||||
yield* sql`DELETE FROM projection_turns`;
|
||||
yield* sql`DELETE FROM projection_state`;
|
||||
|
||||
yield* sql`
|
||||
INSERT INTO projection_projects (
|
||||
project_id,
|
||||
title,
|
||||
workspace_root,
|
||||
default_model_selection_json,
|
||||
scripts_json,
|
||||
created_at,
|
||||
updated_at,
|
||||
deleted_at
|
||||
)
|
||||
VALUES (
|
||||
'project-1',
|
||||
'Project 1',
|
||||
'/tmp/project-1',
|
||||
'{"provider":"codex","model":"gpt-5-codex"}',
|
||||
'[]',
|
||||
'2026-04-03T00:00:00.000Z',
|
||||
'2026-04-03T00:00:01.000Z',
|
||||
NULL
|
||||
)
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
INSERT INTO projection_threads (
|
||||
thread_id,
|
||||
project_id,
|
||||
title,
|
||||
model_selection_json,
|
||||
runtime_mode,
|
||||
interaction_mode,
|
||||
branch,
|
||||
worktree_path,
|
||||
latest_turn_id,
|
||||
latest_user_message_at,
|
||||
pending_approval_count,
|
||||
pending_user_input_count,
|
||||
has_actionable_proposed_plan,
|
||||
created_at,
|
||||
updated_at,
|
||||
archived_at,
|
||||
deleted_at
|
||||
)
|
||||
VALUES (
|
||||
'thread-1',
|
||||
'project-1',
|
||||
'Thread 1',
|
||||
'{"provider":"codex","model":"gpt-5-codex"}',
|
||||
'full-access',
|
||||
'default',
|
||||
NULL,
|
||||
NULL,
|
||||
'turn-running',
|
||||
'2026-04-03T00:00:04.000Z',
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'2026-04-03T00:00:02.000Z',
|
||||
'2026-04-03T00:00:03.000Z',
|
||||
NULL,
|
||||
NULL
|
||||
)
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
INSERT INTO projection_turns (
|
||||
thread_id,
|
||||
turn_id,
|
||||
pending_message_id,
|
||||
source_proposed_plan_thread_id,
|
||||
source_proposed_plan_id,
|
||||
assistant_message_id,
|
||||
state,
|
||||
requested_at,
|
||||
started_at,
|
||||
completed_at,
|
||||
checkpoint_turn_count,
|
||||
checkpoint_ref,
|
||||
checkpoint_status,
|
||||
checkpoint_files_json
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
'thread-1',
|
||||
'turn-running',
|
||||
'message-user-2',
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
'running',
|
||||
'2026-04-03T00:00:30.000Z',
|
||||
'2026-04-03T00:00:30.000Z',
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
'[]'
|
||||
),
|
||||
(
|
||||
'thread-1',
|
||||
'turn-completed',
|
||||
'message-user-1',
|
||||
NULL,
|
||||
NULL,
|
||||
'message-assistant-1',
|
||||
'completed',
|
||||
'2026-04-03T00:00:05.000Z',
|
||||
'2026-04-03T00:00:06.000Z',
|
||||
'2026-04-03T00:00:20.000Z',
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
'[]'
|
||||
)
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
INSERT INTO projection_state (projector, last_applied_sequence, updated_at)
|
||||
VALUES
|
||||
(${ORCHESTRATION_PROJECTOR_NAMES.projects}, 3, '2026-04-03T00:00:40.000Z'),
|
||||
(${ORCHESTRATION_PROJECTOR_NAMES.threads}, 3, '2026-04-03T00:00:40.000Z'),
|
||||
(${ORCHESTRATION_PROJECTOR_NAMES.threadMessages}, 3, '2026-04-03T00:00:40.000Z'),
|
||||
(${ORCHESTRATION_PROJECTOR_NAMES.threadProposedPlans}, 3, '2026-04-03T00:00:40.000Z'),
|
||||
(${ORCHESTRATION_PROJECTOR_NAMES.threadActivities}, 3, '2026-04-03T00:00:40.000Z'),
|
||||
(${ORCHESTRATION_PROJECTOR_NAMES.threadSessions}, 3, '2026-04-03T00:00:40.000Z'),
|
||||
(${ORCHESTRATION_PROJECTOR_NAMES.checkpoints}, 3, '2026-04-03T00:00:40.000Z')
|
||||
`;
|
||||
|
||||
const commandReadModel = yield* snapshotQuery.getCommandReadModel();
|
||||
assert.equal(commandReadModel.threads[0]?.latestTurn?.turnId, asTurnId("turn-running"));
|
||||
assert.equal(commandReadModel.threads[0]?.latestTurn?.state, "running");
|
||||
|
||||
const shellSnapshot = yield* snapshotQuery.getShellSnapshot();
|
||||
assert.equal(shellSnapshot.threads[0]?.latestTurn?.turnId, asTurnId("turn-running"));
|
||||
assert.equal(shellSnapshot.threads[0]?.latestTurn?.state, "running");
|
||||
|
||||
const fullSnapshot = yield* snapshotQuery.getSnapshot();
|
||||
assert.equal(fullSnapshot.threads[0]?.latestTurn?.turnId, asTurnId("turn-running"));
|
||||
assert.equal(fullSnapshot.threads[0]?.latestTurn?.state, "running");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("keeps deleted project and thread tombstones in the command read model", () =>
|
||||
Effect.gen(function* () {
|
||||
const snapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* sql`DELETE FROM projection_projects`;
|
||||
yield* sql`DELETE FROM projection_threads`;
|
||||
yield* sql`DELETE FROM projection_turns`;
|
||||
yield* sql`DELETE FROM projection_state`;
|
||||
|
||||
yield* sql`
|
||||
INSERT INTO projection_projects (
|
||||
project_id,
|
||||
title,
|
||||
workspace_root,
|
||||
default_model_selection_json,
|
||||
scripts_json,
|
||||
created_at,
|
||||
updated_at,
|
||||
deleted_at
|
||||
)
|
||||
VALUES (
|
||||
'project-deleted',
|
||||
'Deleted Project',
|
||||
'/tmp/deleted-project',
|
||||
'{"provider":"codex","model":"gpt-5-codex"}',
|
||||
'[]',
|
||||
'2026-04-05T00:00:00.000Z',
|
||||
'2026-04-05T00:00:01.000Z',
|
||||
'2026-04-05T00:00:02.000Z'
|
||||
)
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
INSERT INTO projection_threads (
|
||||
thread_id,
|
||||
project_id,
|
||||
title,
|
||||
model_selection_json,
|
||||
runtime_mode,
|
||||
interaction_mode,
|
||||
branch,
|
||||
worktree_path,
|
||||
latest_turn_id,
|
||||
latest_user_message_at,
|
||||
pending_approval_count,
|
||||
pending_user_input_count,
|
||||
has_actionable_proposed_plan,
|
||||
created_at,
|
||||
updated_at,
|
||||
archived_at,
|
||||
deleted_at
|
||||
)
|
||||
VALUES (
|
||||
'thread-deleted',
|
||||
'project-deleted',
|
||||
'Deleted Thread',
|
||||
'{"provider":"codex","model":"gpt-5-codex"}',
|
||||
'full-access',
|
||||
'default',
|
||||
NULL,
|
||||
NULL,
|
||||
'turn-deleted',
|
||||
NULL,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'2026-04-05T00:00:03.000Z',
|
||||
'2026-04-05T00:00:04.000Z',
|
||||
NULL,
|
||||
'2026-04-05T00:00:05.000Z'
|
||||
)
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
INSERT INTO projection_turns (
|
||||
thread_id,
|
||||
turn_id,
|
||||
pending_message_id,
|
||||
source_proposed_plan_thread_id,
|
||||
source_proposed_plan_id,
|
||||
assistant_message_id,
|
||||
state,
|
||||
requested_at,
|
||||
started_at,
|
||||
completed_at,
|
||||
checkpoint_turn_count,
|
||||
checkpoint_ref,
|
||||
checkpoint_status,
|
||||
checkpoint_files_json
|
||||
)
|
||||
VALUES (
|
||||
'thread-deleted',
|
||||
'turn-deleted',
|
||||
'message-deleted-user',
|
||||
NULL,
|
||||
NULL,
|
||||
'message-deleted-assistant',
|
||||
'completed',
|
||||
'2026-04-05T00:00:04.100Z',
|
||||
'2026-04-05T00:00:04.200Z',
|
||||
'2026-04-05T00:00:04.300Z',
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
'[]'
|
||||
)
|
||||
`;
|
||||
|
||||
const commandReadModel = yield* snapshotQuery.getCommandReadModel();
|
||||
assert.equal(commandReadModel.projects[0]?.id, asProjectId("project-deleted"));
|
||||
assert.equal(commandReadModel.projects[0]?.deletedAt, "2026-04-05T00:00:02.000Z");
|
||||
assert.equal(commandReadModel.threads[0]?.id, ThreadId.make("thread-deleted"));
|
||||
assert.equal(commandReadModel.threads[0]?.deletedAt, "2026-04-05T00:00:05.000Z");
|
||||
assert.equal(commandReadModel.threads[0]?.latestTurn?.turnId, asTurnId("turn-deleted"));
|
||||
assert.equal(commandReadModel.threads[0]?.latestTurn?.state, "completed");
|
||||
|
||||
const fullSnapshot = yield* snapshotQuery.getSnapshot();
|
||||
assert.equal(fullSnapshot.threads[0]?.id, ThreadId.make("thread-deleted"));
|
||||
assert.equal(fullSnapshot.threads[0]?.latestTurn?.turnId, asTurnId("turn-deleted"));
|
||||
assert.equal(fullSnapshot.threads[0]?.latestTurn?.state, "completed");
|
||||
|
||||
const shellSnapshot = yield* snapshotQuery.getShellSnapshot();
|
||||
assert.equal(shellSnapshot.projects.length, 0);
|
||||
assert.equal(shellSnapshot.threads.length, 0);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it.effect(
|
||||
"ProjectionSnapshotQuery dedupes repository identity resolution by workspace root and skips deleted projects for shell snapshots",
|
||||
() => {
|
||||
const resolveCalls: string[] = [];
|
||||
const layer = OrchestrationProjectionSnapshotQueryLive.pipe(
|
||||
Layer.provideMerge(
|
||||
Layer.succeed(RepositoryIdentityResolver, {
|
||||
resolve: (cwd: string) =>
|
||||
Effect.sync(() => {
|
||||
resolveCalls.push(cwd);
|
||||
return {
|
||||
canonicalKey: `github.com/acme${cwd}`,
|
||||
locator: {
|
||||
source: "git-remote" as const,
|
||||
remoteName: "origin",
|
||||
remoteUrl: `https://github.com/acme${cwd}.git`,
|
||||
},
|
||||
rootPath: cwd,
|
||||
};
|
||||
}),
|
||||
}),
|
||||
),
|
||||
Layer.provideMerge(SqlitePersistenceMemory),
|
||||
);
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const snapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* sql`DELETE FROM projection_projects`;
|
||||
yield* sql`DELETE FROM projection_threads`;
|
||||
yield* sql`DELETE FROM projection_turns`;
|
||||
yield* sql`DELETE FROM projection_state`;
|
||||
|
||||
yield* sql`
|
||||
INSERT INTO projection_projects (
|
||||
project_id,
|
||||
title,
|
||||
workspace_root,
|
||||
default_model_selection_json,
|
||||
scripts_json,
|
||||
created_at,
|
||||
updated_at,
|
||||
deleted_at
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
'project-1',
|
||||
'Shared Project 1',
|
||||
'/tmp/shared-root',
|
||||
'{"provider":"codex","model":"gpt-5-codex"}',
|
||||
'[]',
|
||||
'2026-04-04T00:00:00.000Z',
|
||||
'2026-04-04T00:00:01.000Z',
|
||||
NULL
|
||||
),
|
||||
(
|
||||
'project-2',
|
||||
'Shared Project 2',
|
||||
'/tmp/shared-root',
|
||||
'{"provider":"codex","model":"gpt-5-codex"}',
|
||||
'[]',
|
||||
'2026-04-04T00:00:02.000Z',
|
||||
'2026-04-04T00:00:03.000Z',
|
||||
NULL
|
||||
),
|
||||
(
|
||||
'project-3',
|
||||
'Deleted Project',
|
||||
'/tmp/deleted-root',
|
||||
'{"provider":"codex","model":"gpt-5-codex"}',
|
||||
'[]',
|
||||
'2026-04-04T00:00:04.000Z',
|
||||
'2026-04-04T00:00:05.000Z',
|
||||
'2026-04-04T00:00:06.000Z'
|
||||
)
|
||||
`;
|
||||
|
||||
const shellSnapshot = yield* snapshotQuery.getShellSnapshot();
|
||||
assert.deepStrictEqual(resolveCalls.toSorted(), ["/tmp/shared-root"]);
|
||||
assert.equal(shellSnapshot.projects.length, 2);
|
||||
assert.equal(shellSnapshot.projects[0]?.repositoryIdentity?.rootPath, "/tmp/shared-root");
|
||||
assert.equal(shellSnapshot.projects[1]?.repositoryIdentity?.rootPath, "/tmp/shared-root");
|
||||
|
||||
resolveCalls.length = 0;
|
||||
|
||||
const fullSnapshot = yield* snapshotQuery.getSnapshot();
|
||||
assert.deepStrictEqual(resolveCalls.toSorted(), ["/tmp/deleted-root", "/tmp/shared-root"]);
|
||||
assert.equal(fullSnapshot.projects.length, 3);
|
||||
assert.equal(fullSnapshot.projects[2]?.repositoryIdentity?.rootPath, "/tmp/deleted-root");
|
||||
}).pipe(Effect.provide(layer));
|
||||
},
|
||||
);
|
||||
@@ -219,6 +219,20 @@ function mapProjectShellRow(
|
||||
};
|
||||
}
|
||||
|
||||
function mapProposedPlanRow(
|
||||
row: Schema.Schema.Type<typeof ProjectionThreadProposedPlanDbRowSchema>,
|
||||
): OrchestrationProposedPlan {
|
||||
return {
|
||||
id: row.planId,
|
||||
turnId: row.turnId,
|
||||
planMarkdown: row.planMarkdown,
|
||||
implementedAt: row.implementedAt,
|
||||
implementationThreadId: row.implementationThreadId,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
function toPersistenceSqlOrDecodeError(sqlOperation: string, decodeOperation: string) {
|
||||
return (cause: unknown): ProjectionRepositoryError =>
|
||||
Schema.isSchemaError(cause)
|
||||
@@ -230,6 +244,37 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const repositoryIdentityResolver = yield* RepositoryIdentityResolver;
|
||||
const repositoryIdentityResolutionConcurrency = 4;
|
||||
const resolveRepositoryIdentitiesForProjects = Effect.fn(
|
||||
"ProjectionSnapshotQuery.resolveRepositoryIdentitiesForProjects",
|
||||
)(function* (
|
||||
projectRows: ReadonlyArray<Schema.Schema.Type<typeof ProjectionProjectDbRowSchema>>,
|
||||
options?: {
|
||||
readonly includeDeleted?: boolean;
|
||||
},
|
||||
) {
|
||||
const filteredProjectRows =
|
||||
options?.includeDeleted === true
|
||||
? projectRows
|
||||
: projectRows.filter((row) => row.deletedAt === null);
|
||||
const uniqueWorkspaceRoots = [...new Set(filteredProjectRows.map((row) => row.workspaceRoot))];
|
||||
const repositoryIdentityByWorkspaceRoot = new Map(
|
||||
yield* Effect.forEach(
|
||||
uniqueWorkspaceRoots,
|
||||
(workspaceRoot) =>
|
||||
repositoryIdentityResolver
|
||||
.resolve(workspaceRoot)
|
||||
.pipe(Effect.map((identity) => [workspaceRoot, identity] as const)),
|
||||
{ concurrency: repositoryIdentityResolutionConcurrency },
|
||||
),
|
||||
);
|
||||
|
||||
return new Map(
|
||||
filteredProjectRows.map((row) => [
|
||||
row.projectId,
|
||||
repositoryIdentityByWorkspaceRoot.get(row.workspaceRoot) ?? null,
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
const listProjectRows = SqlSchema.findAll({
|
||||
Request: Schema.Void,
|
||||
@@ -335,7 +380,6 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
FROM projection_thread_activities
|
||||
ORDER BY
|
||||
thread_id ASC,
|
||||
CASE WHEN sequence IS NULL THEN 0 ELSE 1 END ASC,
|
||||
sequence ASC,
|
||||
created_at ASC,
|
||||
activity_id ASC
|
||||
@@ -389,18 +433,46 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
execute: () =>
|
||||
sql`
|
||||
SELECT
|
||||
thread_id AS "threadId",
|
||||
turn_id AS "turnId",
|
||||
state,
|
||||
requested_at AS "requestedAt",
|
||||
started_at AS "startedAt",
|
||||
completed_at AS "completedAt",
|
||||
assistant_message_id AS "assistantMessageId",
|
||||
source_proposed_plan_thread_id AS "sourceProposedPlanThreadId",
|
||||
source_proposed_plan_id AS "sourceProposedPlanId"
|
||||
FROM projection_turns
|
||||
WHERE turn_id IS NOT NULL
|
||||
ORDER BY thread_id ASC, requested_at DESC, turn_id DESC
|
||||
turns.thread_id AS "threadId",
|
||||
turns.turn_id AS "turnId",
|
||||
turns.state,
|
||||
turns.requested_at AS "requestedAt",
|
||||
turns.started_at AS "startedAt",
|
||||
turns.completed_at AS "completedAt",
|
||||
turns.assistant_message_id AS "assistantMessageId",
|
||||
turns.source_proposed_plan_thread_id AS "sourceProposedPlanThreadId",
|
||||
turns.source_proposed_plan_id AS "sourceProposedPlanId"
|
||||
FROM projection_threads threads
|
||||
JOIN projection_turns turns
|
||||
ON turns.thread_id = threads.thread_id
|
||||
AND turns.turn_id = threads.latest_turn_id
|
||||
WHERE threads.latest_turn_id IS NOT NULL
|
||||
ORDER BY turns.thread_id ASC
|
||||
`,
|
||||
});
|
||||
|
||||
const listActiveLatestTurnRows = SqlSchema.findAll({
|
||||
Request: Schema.Void,
|
||||
Result: ProjectionLatestTurnDbRowSchema,
|
||||
execute: () =>
|
||||
sql`
|
||||
SELECT
|
||||
turns.thread_id AS "threadId",
|
||||
turns.turn_id AS "turnId",
|
||||
turns.state,
|
||||
turns.requested_at AS "requestedAt",
|
||||
turns.started_at AS "startedAt",
|
||||
turns.completed_at AS "completedAt",
|
||||
turns.assistant_message_id AS "assistantMessageId",
|
||||
turns.source_proposed_plan_thread_id AS "sourceProposedPlanThreadId",
|
||||
turns.source_proposed_plan_id AS "sourceProposedPlanId"
|
||||
FROM projection_threads threads
|
||||
JOIN projection_turns turns
|
||||
ON turns.thread_id = threads.thread_id
|
||||
AND turns.turn_id = threads.latest_turn_id
|
||||
WHERE threads.deleted_at IS NULL
|
||||
AND threads.latest_turn_id IS NOT NULL
|
||||
ORDER BY turns.thread_id ASC
|
||||
`,
|
||||
});
|
||||
|
||||
@@ -594,7 +666,6 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
FROM projection_thread_activities
|
||||
WHERE thread_id = ${threadId}
|
||||
ORDER BY
|
||||
CASE WHEN sequence IS NULL THEN 0 ELSE 1 END ASC,
|
||||
sequence ASC,
|
||||
created_at ASC,
|
||||
activity_id ASC
|
||||
@@ -892,15 +963,9 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
});
|
||||
}
|
||||
|
||||
const repositoryIdentities = new Map(
|
||||
yield* Effect.forEach(
|
||||
projectRows,
|
||||
(row) =>
|
||||
repositoryIdentityResolver
|
||||
.resolve(row.workspaceRoot)
|
||||
.pipe(Effect.map((identity) => [row.projectId, identity] as const)),
|
||||
{ concurrency: repositoryIdentityResolutionConcurrency },
|
||||
),
|
||||
const repositoryIdentities = yield* resolveRepositoryIdentitiesForProjects(
|
||||
projectRows,
|
||||
{ includeDeleted: true },
|
||||
);
|
||||
|
||||
const projects: ReadonlyArray<OrchestrationProject> = projectRows.map((row) => ({
|
||||
@@ -958,6 +1023,199 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
}),
|
||||
);
|
||||
|
||||
const getCommandReadModel: ProjectionSnapshotQueryShape["getCommandReadModel"] = () =>
|
||||
sql
|
||||
.withTransaction(
|
||||
Effect.all([
|
||||
listProjectRows(undefined).pipe(
|
||||
Effect.mapError(
|
||||
toPersistenceSqlOrDecodeError(
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listProjects:query",
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listProjects:decodeRows",
|
||||
),
|
||||
),
|
||||
),
|
||||
listThreadRows(undefined).pipe(
|
||||
Effect.mapError(
|
||||
toPersistenceSqlOrDecodeError(
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listThreads:query",
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listThreads:decodeRows",
|
||||
),
|
||||
),
|
||||
),
|
||||
listThreadProposedPlanRows(undefined).pipe(
|
||||
Effect.mapError(
|
||||
toPersistenceSqlOrDecodeError(
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listThreadProposedPlans:query",
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listThreadProposedPlans:decodeRows",
|
||||
),
|
||||
),
|
||||
),
|
||||
listThreadSessionRows(undefined).pipe(
|
||||
Effect.mapError(
|
||||
toPersistenceSqlOrDecodeError(
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listThreadSessions:query",
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listThreadSessions:decodeRows",
|
||||
),
|
||||
),
|
||||
),
|
||||
listLatestTurnRows(undefined).pipe(
|
||||
Effect.mapError(
|
||||
toPersistenceSqlOrDecodeError(
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listLatestTurns:query",
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listLatestTurns:decodeRows",
|
||||
),
|
||||
),
|
||||
),
|
||||
listProjectionStateRows(undefined).pipe(
|
||||
Effect.mapError(
|
||||
toPersistenceSqlOrDecodeError(
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listProjectionState:query",
|
||||
"ProjectionSnapshotQuery.getCommandReadModel:listProjectionState:decodeRows",
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
)
|
||||
.pipe(
|
||||
Effect.flatMap(
|
||||
([projectRows, threadRows, proposedPlanRows, sessionRows, latestTurnRows, stateRows]) =>
|
||||
Effect.sync(() => {
|
||||
let updatedAt: string | null = null;
|
||||
const projects: OrchestrationProject[] = [];
|
||||
const threads: OrchestrationThread[] = [];
|
||||
|
||||
for (let index = 0; index < projectRows.length; index += 1) {
|
||||
const row = projectRows[index];
|
||||
if (!row) {
|
||||
continue;
|
||||
}
|
||||
updatedAt = maxIso(updatedAt, row.updatedAt);
|
||||
projects.push({
|
||||
id: row.projectId,
|
||||
title: row.title,
|
||||
workspaceRoot: row.workspaceRoot,
|
||||
defaultModelSelection: row.defaultModelSelection,
|
||||
scripts: row.scripts,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
deletedAt: row.deletedAt,
|
||||
});
|
||||
}
|
||||
for (let index = 0; index < threadRows.length; index += 1) {
|
||||
const row = threadRows[index];
|
||||
if (!row) {
|
||||
continue;
|
||||
}
|
||||
updatedAt = maxIso(updatedAt, row.updatedAt);
|
||||
}
|
||||
for (let index = 0; index < proposedPlanRows.length; index += 1) {
|
||||
const row = proposedPlanRows[index];
|
||||
if (!row) {
|
||||
continue;
|
||||
}
|
||||
updatedAt = maxIso(updatedAt, row.updatedAt);
|
||||
}
|
||||
for (let index = 0; index < sessionRows.length; index += 1) {
|
||||
const row = sessionRows[index];
|
||||
if (!row) {
|
||||
continue;
|
||||
}
|
||||
updatedAt = maxIso(updatedAt, row.updatedAt);
|
||||
}
|
||||
for (let index = 0; index < latestTurnRows.length; index += 1) {
|
||||
const row = latestTurnRows[index];
|
||||
if (!row) {
|
||||
continue;
|
||||
}
|
||||
updatedAt = maxIso(updatedAt, row.requestedAt);
|
||||
if (row.startedAt !== null) {
|
||||
updatedAt = maxIso(updatedAt, row.startedAt);
|
||||
}
|
||||
if (row.completedAt !== null) {
|
||||
updatedAt = maxIso(updatedAt, row.completedAt);
|
||||
}
|
||||
}
|
||||
for (let index = 0; index < stateRows.length; index += 1) {
|
||||
const row = stateRows[index];
|
||||
if (!row) {
|
||||
continue;
|
||||
}
|
||||
updatedAt = maxIso(updatedAt, row.updatedAt);
|
||||
}
|
||||
|
||||
const latestTurnByThread = new Map<string, OrchestrationLatestTurn>();
|
||||
for (let index = 0; index < latestTurnRows.length; index += 1) {
|
||||
const row = latestTurnRows[index];
|
||||
if (!row) {
|
||||
continue;
|
||||
}
|
||||
latestTurnByThread.set(row.threadId, mapLatestTurn(row));
|
||||
}
|
||||
const proposedPlansByThread = new Map<string, Array<OrchestrationProposedPlan>>();
|
||||
const sessionByThread = new Map<string, OrchestrationSession>();
|
||||
|
||||
for (let index = 0; index < sessionRows.length; index += 1) {
|
||||
const row = sessionRows[index];
|
||||
if (!row) {
|
||||
continue;
|
||||
}
|
||||
sessionByThread.set(row.threadId, mapSessionRow(row));
|
||||
}
|
||||
|
||||
for (let index = 0; index < proposedPlanRows.length; index += 1) {
|
||||
const row = proposedPlanRows[index];
|
||||
if (!row) {
|
||||
continue;
|
||||
}
|
||||
const threadProposedPlans = proposedPlansByThread.get(row.threadId) ?? [];
|
||||
threadProposedPlans.push(mapProposedPlanRow(row));
|
||||
proposedPlansByThread.set(row.threadId, threadProposedPlans);
|
||||
}
|
||||
|
||||
for (let index = 0; index < threadRows.length; index += 1) {
|
||||
const row = threadRows[index];
|
||||
if (!row) {
|
||||
continue;
|
||||
}
|
||||
threads.push({
|
||||
id: row.threadId,
|
||||
projectId: row.projectId,
|
||||
title: row.title,
|
||||
modelSelection: row.modelSelection,
|
||||
runtimeMode: row.runtimeMode,
|
||||
interactionMode: row.interactionMode,
|
||||
branch: row.branch,
|
||||
worktreePath: row.worktreePath,
|
||||
latestTurn: latestTurnByThread.get(row.threadId) ?? null,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
archivedAt: row.archivedAt,
|
||||
deletedAt: row.deletedAt,
|
||||
messages: [],
|
||||
proposedPlans: proposedPlansByThread.get(row.threadId) ?? [],
|
||||
activities: [],
|
||||
checkpoints: [],
|
||||
session: sessionByThread.get(row.threadId) ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
snapshotSequence: computeSnapshotSequence(stateRows),
|
||||
projects,
|
||||
threads,
|
||||
updatedAt: updatedAt ?? new Date(0).toISOString(),
|
||||
} satisfies OrchestrationReadModel;
|
||||
}),
|
||||
),
|
||||
Effect.mapError((error) => {
|
||||
if (isPersistenceError(error)) {
|
||||
return error;
|
||||
}
|
||||
return toPersistenceSqlError("ProjectionSnapshotQuery.getCommandReadModel:query")(error);
|
||||
}),
|
||||
);
|
||||
|
||||
const getShellSnapshot: ProjectionSnapshotQueryShape["getShellSnapshot"] = () =>
|
||||
sql
|
||||
.withTransaction(
|
||||
@@ -986,7 +1244,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
),
|
||||
),
|
||||
),
|
||||
listLatestTurnRows(undefined).pipe(
|
||||
listActiveLatestTurnRows(undefined).pipe(
|
||||
Effect.mapError(
|
||||
toPersistenceSqlOrDecodeError(
|
||||
"ProjectionSnapshotQuery.getShellSnapshot:listLatestTurns:query",
|
||||
@@ -1030,16 +1288,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
updatedAt = maxIso(updatedAt, row.updatedAt);
|
||||
}
|
||||
|
||||
const repositoryIdentities = new Map(
|
||||
yield* Effect.forEach(
|
||||
projectRows,
|
||||
(row) =>
|
||||
repositoryIdentityResolver
|
||||
.resolve(row.workspaceRoot)
|
||||
.pipe(Effect.map((identity) => [row.projectId, identity] as const)),
|
||||
{ concurrency: repositoryIdentityResolutionConcurrency },
|
||||
),
|
||||
);
|
||||
const repositoryIdentities = yield* resolveRepositoryIdentitiesForProjects(projectRows);
|
||||
const latestTurnByThread = new Map(
|
||||
latestTurnRows.map((row) => [row.threadId, mapLatestTurn(row)] as const),
|
||||
);
|
||||
@@ -1097,6 +1346,19 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
}),
|
||||
);
|
||||
|
||||
const getSnapshotSequence: ProjectionSnapshotQueryShape["getSnapshotSequence"] = () =>
|
||||
listProjectionStateRows(undefined).pipe(
|
||||
Effect.mapError(
|
||||
toPersistenceSqlOrDecodeError(
|
||||
"ProjectionSnapshotQuery.getSnapshotSequence:query",
|
||||
"ProjectionSnapshotQuery.getSnapshotSequence:decodeRows",
|
||||
),
|
||||
),
|
||||
Effect.map((stateRows) => ({
|
||||
snapshotSequence: computeSnapshotSequence(stateRows),
|
||||
})),
|
||||
);
|
||||
|
||||
const getCounts: ProjectionSnapshotQueryShape["getCounts"] = () =>
|
||||
readProjectionCounts(undefined).pipe(
|
||||
Effect.mapError(
|
||||
@@ -1376,15 +1638,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
}
|
||||
return message;
|
||||
}),
|
||||
proposedPlans: proposedPlanRows.map((row) => ({
|
||||
id: row.planId,
|
||||
turnId: row.turnId,
|
||||
planMarkdown: row.planMarkdown,
|
||||
implementedAt: row.implementedAt,
|
||||
implementationThreadId: row.implementationThreadId,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
})),
|
||||
proposedPlans: proposedPlanRows.map(mapProposedPlanRow),
|
||||
activities: activityRows.map((row) => {
|
||||
const activity = {
|
||||
id: row.activityId,
|
||||
@@ -1422,8 +1676,10 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
});
|
||||
|
||||
return {
|
||||
getCommandReadModel,
|
||||
getSnapshot,
|
||||
getShellSnapshot,
|
||||
getSnapshotSequence,
|
||||
getCounts,
|
||||
getActiveProjectByWorkspaceRoot,
|
||||
getProjectShellById,
|
||||
|
||||
@@ -45,6 +45,7 @@ import {
|
||||
} from "./ProviderCommandReactor.ts";
|
||||
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
|
||||
import { ProviderCommandReactor } from "../Services/ProviderCommandReactor.ts";
|
||||
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { ServerSettingsService } from "../../serverSettings.ts";
|
||||
import { VcsStatusBroadcaster } from "../../vcs/VcsStatusBroadcaster.ts";
|
||||
@@ -79,7 +80,7 @@ async function waitFor(
|
||||
|
||||
describe("ProviderCommandReactor", () => {
|
||||
let runtime: ManagedRuntime.ManagedRuntime<
|
||||
OrchestrationEngineService | ProviderCommandReactor,
|
||||
OrchestrationEngineService | ProviderCommandReactor | ProjectionSnapshotQuery,
|
||||
unknown
|
||||
> | null = null;
|
||||
let scope: Scope.Closeable | null = null;
|
||||
@@ -318,8 +319,13 @@ describe("ProviderCommandReactor", () => {
|
||||
Layer.provide(RepositoryIdentityResolverLive),
|
||||
Layer.provide(SqlitePersistenceMemory),
|
||||
);
|
||||
const projectionSnapshotLayer = OrchestrationProjectionSnapshotQueryLive.pipe(
|
||||
Layer.provide(RepositoryIdentityResolverLive),
|
||||
Layer.provide(SqlitePersistenceMemory),
|
||||
);
|
||||
const layer = ProviderCommandReactorLive.pipe(
|
||||
Layer.provideMerge(orchestrationLayer),
|
||||
Layer.provideMerge(projectionSnapshotLayer),
|
||||
Layer.provideMerge(Layer.succeed(ProviderService, service)),
|
||||
Layer.provideMerge(
|
||||
Layer.mock(GitWorkflowService)({
|
||||
@@ -348,6 +354,7 @@ describe("ProviderCommandReactor", () => {
|
||||
runtime = ManagedRuntime.make(layer);
|
||||
|
||||
const engine = await runtime.runPromise(Effect.service(OrchestrationEngineService));
|
||||
const snapshotQuery = await runtime.runPromise(Effect.service(ProjectionSnapshotQuery));
|
||||
const reactor = await runtime.runPromise(Effect.service(ProviderCommandReactor));
|
||||
scope = await Effect.runPromise(Scope.make("sequential"));
|
||||
await Effect.runPromise(reactor.start().pipe(Scope.provide(scope)));
|
||||
@@ -382,6 +389,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
return {
|
||||
engine,
|
||||
readModel: () => Effect.runPromise(snapshotQuery.getSnapshot()),
|
||||
startSession,
|
||||
sendTurn,
|
||||
interruptTurn,
|
||||
@@ -431,7 +439,7 @@ describe("ProviderCommandReactor", () => {
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.session?.threadId).toBe("thread-1");
|
||||
expect(thread?.session?.runtimeMode).toBe("approval-required");
|
||||
@@ -476,13 +484,13 @@ describe("ProviderCommandReactor", () => {
|
||||
});
|
||||
|
||||
await waitFor(async () => {
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
return (
|
||||
readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"))?.title ===
|
||||
"Generated title"
|
||||
);
|
||||
});
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.title).toBe("Generated title");
|
||||
});
|
||||
@@ -522,7 +530,7 @@ describe("ProviderCommandReactor", () => {
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 1);
|
||||
expect(harness.generateThreadTitle).not.toHaveBeenCalled();
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.title).toBe("Keep this custom title");
|
||||
});
|
||||
@@ -566,14 +574,14 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
await waitFor(() => harness.generateThreadTitle.mock.calls.length === 1);
|
||||
await waitFor(async () => {
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
return (
|
||||
readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"))?.title ===
|
||||
"Reconnect spinner resume bug"
|
||||
);
|
||||
});
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.title).toBe("Reconnect spinner resume bug");
|
||||
});
|
||||
@@ -902,7 +910,7 @@ describe("ProviderCommandReactor", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.session?.providerName).toBe("claudeAgent");
|
||||
expect(thread?.session?.providerInstanceId).toBe(ProviderInstanceId.make("claudeAgent"));
|
||||
@@ -1014,7 +1022,7 @@ describe("ProviderCommandReactor", () => {
|
||||
resumeCursor: { opaque: "resume-1" },
|
||||
});
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.session?.providerInstanceId).toBe(ProviderInstanceId.make("codex_work"));
|
||||
});
|
||||
@@ -1205,7 +1213,7 @@ describe("ProviderCommandReactor", () => {
|
||||
);
|
||||
|
||||
await waitFor(async () => {
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
return thread?.runtimeMode === "approval-required";
|
||||
});
|
||||
@@ -1239,7 +1247,7 @@ describe("ProviderCommandReactor", () => {
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
});
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.session?.threadId).toBe("thread-1");
|
||||
expect(thread?.session?.runtimeMode).toBe("approval-required");
|
||||
@@ -1342,7 +1350,7 @@ describe("ProviderCommandReactor", () => {
|
||||
);
|
||||
|
||||
await waitFor(async () => {
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
return thread?.runtimeMode === "approval-required";
|
||||
});
|
||||
@@ -1352,7 +1360,7 @@ describe("ProviderCommandReactor", () => {
|
||||
expect(harness.stopSession.mock.calls.length).toBe(0);
|
||||
expect(harness.sendTurn.mock.calls.length).toBe(1);
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.session?.threadId).toBe("thread-1");
|
||||
expect(thread?.session?.runtimeMode).toBe("full-access");
|
||||
@@ -1404,7 +1412,7 @@ describe("ProviderCommandReactor", () => {
|
||||
);
|
||||
|
||||
await waitFor(async () => {
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
return (
|
||||
thread?.activities.some((activity) => activity.kind === "provider.turn.start.failed") ??
|
||||
@@ -1416,7 +1424,7 @@ describe("ProviderCommandReactor", () => {
|
||||
expect(harness.sendTurn.mock.calls.length).toBe(1);
|
||||
expect(harness.stopSession.mock.calls.length).toBe(0);
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.session?.threadId).toBe("thread-1");
|
||||
expect(thread?.session?.providerName).toBe("codex");
|
||||
@@ -1475,7 +1483,7 @@ describe("ProviderCommandReactor", () => {
|
||||
);
|
||||
|
||||
await waitFor(async () => {
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
return (
|
||||
thread?.activities.some((activity) => activity.kind === "provider.turn.start.failed") ??
|
||||
@@ -1485,7 +1493,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
expect(harness.startSession.mock.calls.length).toBe(0);
|
||||
expect(harness.sendTurn.mock.calls.length).toBe(0);
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(
|
||||
thread?.activities.find((activity) => activity.kind === "provider.turn.start.failed"),
|
||||
@@ -1639,7 +1647,7 @@ describe("ProviderCommandReactor", () => {
|
||||
);
|
||||
|
||||
await waitFor(async () => {
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
return (
|
||||
thread?.activities.some((activity) => activity.kind === "provider.turn.start.failed") ??
|
||||
@@ -1649,7 +1657,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
expect(harness.startSession.mock.calls.length).toBe(0);
|
||||
expect(harness.sendTurn.mock.calls.length).toBe(0);
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(
|
||||
thread?.activities.find((activity) => activity.kind === "provider.turn.start.failed"),
|
||||
@@ -1810,7 +1818,7 @@ describe("ProviderCommandReactor", () => {
|
||||
);
|
||||
|
||||
await waitFor(async () => {
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
if (!thread) return false;
|
||||
return thread.activities.some(
|
||||
@@ -1818,7 +1826,7 @@ describe("ProviderCommandReactor", () => {
|
||||
);
|
||||
});
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread).toBeDefined();
|
||||
|
||||
@@ -1919,7 +1927,7 @@ describe("ProviderCommandReactor", () => {
|
||||
);
|
||||
|
||||
await waitFor(async () => {
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
if (!thread) return false;
|
||||
return thread.activities.some(
|
||||
@@ -1927,7 +1935,7 @@ describe("ProviderCommandReactor", () => {
|
||||
);
|
||||
});
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread).toBeDefined();
|
||||
|
||||
@@ -1983,7 +1991,7 @@ describe("ProviderCommandReactor", () => {
|
||||
);
|
||||
|
||||
await waitFor(() => harness.stopSession.mock.calls.length === 1);
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.session).not.toBeNull();
|
||||
expect(thread?.session?.status).toBe("stopped");
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
type ModelSelection,
|
||||
type OrchestrationEvent,
|
||||
ProviderDriverKind,
|
||||
type ProjectId,
|
||||
type OrchestrationSession,
|
||||
ThreadId,
|
||||
type ProviderSession,
|
||||
@@ -22,6 +23,7 @@ import type { ProviderServiceError } from "../../provider/Errors.ts";
|
||||
import { TextGeneration } from "../../textGeneration/TextGeneration.ts";
|
||||
import { ProviderService } from "../../provider/Services/ProviderService.ts";
|
||||
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
|
||||
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
|
||||
import {
|
||||
ProviderCommandReactor,
|
||||
type ProviderCommandReactorShape,
|
||||
@@ -167,6 +169,7 @@ function buildGeneratedWorktreeBranchName(raw: string): string {
|
||||
|
||||
const make = Effect.gen(function* () {
|
||||
const orchestrationEngine = yield* OrchestrationEngineService;
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
const providerService = yield* ProviderService;
|
||||
const gitWorkflow = yield* GitWorkflowService;
|
||||
const vcsStatusBroadcaster = yield* VcsStatusBroadcaster;
|
||||
@@ -267,9 +270,16 @@ const make = Effect.gen(function* () {
|
||||
});
|
||||
});
|
||||
|
||||
const resolveProject = Effect.fnUntraced(function* (projectId: ProjectId) {
|
||||
return yield* projectionSnapshotQuery
|
||||
.getProjectShellById(projectId)
|
||||
.pipe(Effect.map(Option.getOrUndefined));
|
||||
});
|
||||
|
||||
const resolveThread = Effect.fnUntraced(function* (threadId: ThreadId) {
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
return readModel.threads.find((entry) => entry.id === threadId);
|
||||
return yield* projectionSnapshotQuery
|
||||
.getThreadDetailById(threadId)
|
||||
.pipe(Effect.map(Option.getOrUndefined));
|
||||
});
|
||||
|
||||
const ensureSessionForThread = Effect.fn("ensureSessionForThread")(function* (
|
||||
@@ -279,8 +289,7 @@ const make = Effect.gen(function* () {
|
||||
readonly modelSelection?: ModelSelection;
|
||||
},
|
||||
) {
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === threadId);
|
||||
const thread = yield* resolveThread(threadId);
|
||||
if (!thread) {
|
||||
return yield* Effect.die(new Error(`Thread '${threadId}' was not found in read model.`));
|
||||
}
|
||||
@@ -375,9 +384,10 @@ const make = Effect.gen(function* () {
|
||||
});
|
||||
}
|
||||
}
|
||||
const project = yield* resolveProject(thread.projectId);
|
||||
const effectiveCwd = resolveThreadWorkspaceCwd({
|
||||
thread,
|
||||
projects: readModel.projects,
|
||||
projects: project ? [project] : [],
|
||||
});
|
||||
|
||||
const startProviderSession = (input?: {
|
||||
@@ -682,10 +692,11 @@ const make = Effect.gen(function* () {
|
||||
const isFirstUserMessageTurn =
|
||||
thread.messages.filter((entry) => entry.role === "user").length === 1;
|
||||
if (isFirstUserMessageTurn) {
|
||||
const project = yield* resolveProject(thread.projectId);
|
||||
const generationCwd =
|
||||
resolveThreadWorkspaceCwd({
|
||||
thread,
|
||||
projects: (yield* orchestrationEngine.getReadModel()).projects,
|
||||
projects: project ? [project] : [],
|
||||
}) ?? process.cwd();
|
||||
const generationInput = {
|
||||
messageText: message.text,
|
||||
@@ -819,20 +830,16 @@ const make = Effect.gen(function* () {
|
||||
})
|
||||
.pipe(
|
||||
Effect.catchCause((cause) =>
|
||||
Effect.gen(function* () {
|
||||
yield* appendProviderFailureActivity({
|
||||
threadId: event.payload.threadId,
|
||||
kind: "provider.approval.respond.failed",
|
||||
summary: "Provider approval response failed",
|
||||
detail: isUnknownPendingApprovalRequestError(cause)
|
||||
? stalePendingRequestDetail("approval", event.payload.requestId)
|
||||
: Cause.pretty(cause),
|
||||
turnId: null,
|
||||
createdAt: event.payload.createdAt,
|
||||
requestId: event.payload.requestId,
|
||||
});
|
||||
|
||||
if (!isUnknownPendingApprovalRequestError(cause)) return;
|
||||
appendProviderFailureActivity({
|
||||
threadId: event.payload.threadId,
|
||||
kind: "provider.approval.respond.failed",
|
||||
summary: "Provider approval response failed",
|
||||
detail: isUnknownPendingApprovalRequestError(cause)
|
||||
? stalePendingRequestDetail("approval", event.payload.requestId)
|
||||
: Cause.pretty(cause),
|
||||
turnId: null,
|
||||
createdAt: event.payload.createdAt,
|
||||
requestId: event.payload.requestId,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -36,11 +36,9 @@ import { OrchestrationEngineLive } from "./OrchestrationEngine.ts";
|
||||
import { OrchestrationProjectionPipelineLive } from "./ProjectionPipeline.ts";
|
||||
import { OrchestrationProjectionSnapshotQueryLive } from "./ProjectionSnapshotQuery.ts";
|
||||
import { ProviderRuntimeIngestionLive } from "./ProviderRuntimeIngestion.ts";
|
||||
import {
|
||||
OrchestrationEngineService,
|
||||
type OrchestrationEngineShape,
|
||||
} from "../Services/OrchestrationEngine.ts";
|
||||
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
|
||||
import { ProviderRuntimeIngestionService } from "../Services/ProviderRuntimeIngestion.ts";
|
||||
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
import { ServerSettingsService } from "../../serverSettings.ts";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
@@ -154,16 +152,23 @@ function createProviderServiceHarness() {
|
||||
};
|
||||
}
|
||||
|
||||
type ProviderRuntimeTestReadModel = OrchestrationReadModel;
|
||||
type ProviderRuntimeTestThread = ProviderRuntimeTestReadModel["threads"][number];
|
||||
type ProviderRuntimeTestMessage = ProviderRuntimeTestThread["messages"][number];
|
||||
type ProviderRuntimeTestProposedPlan = ProviderRuntimeTestThread["proposedPlans"][number];
|
||||
type ProviderRuntimeTestActivity = ProviderRuntimeTestThread["activities"][number];
|
||||
type ProviderRuntimeTestCheckpoint = ProviderRuntimeTestThread["checkpoints"][number];
|
||||
|
||||
async function waitForThread(
|
||||
engine: OrchestrationEngineShape,
|
||||
readModel: () => Promise<ProviderRuntimeTestReadModel>,
|
||||
predicate: (thread: ProviderRuntimeTestThread) => boolean,
|
||||
timeoutMs = 2000,
|
||||
threadId: ThreadId = asThreadId("thread-1"),
|
||||
) {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
const poll = async (): Promise<ProviderRuntimeTestThread> => {
|
||||
const readModel = await Effect.runPromise(engine.getReadModel());
|
||||
const thread = readModel.threads.find((entry) => entry.id === threadId);
|
||||
const snapshot = await readModel();
|
||||
const thread = snapshot.threads.find((entry) => entry.id === threadId);
|
||||
if (thread && predicate(thread)) {
|
||||
return thread;
|
||||
}
|
||||
@@ -176,16 +181,9 @@ async function waitForThread(
|
||||
return poll();
|
||||
}
|
||||
|
||||
type ProviderRuntimeTestReadModel = OrchestrationReadModel;
|
||||
type ProviderRuntimeTestThread = ProviderRuntimeTestReadModel["threads"][number];
|
||||
type ProviderRuntimeTestMessage = ProviderRuntimeTestThread["messages"][number];
|
||||
type ProviderRuntimeTestProposedPlan = ProviderRuntimeTestThread["proposedPlans"][number];
|
||||
type ProviderRuntimeTestActivity = ProviderRuntimeTestThread["activities"][number];
|
||||
type ProviderRuntimeTestCheckpoint = ProviderRuntimeTestThread["checkpoints"][number];
|
||||
|
||||
describe("ProviderRuntimeIngestion", () => {
|
||||
let runtime: ManagedRuntime.ManagedRuntime<
|
||||
OrchestrationEngineService | ProviderRuntimeIngestionService,
|
||||
OrchestrationEngineService | ProviderRuntimeIngestionService | ProjectionSnapshotQuery,
|
||||
unknown
|
||||
> | null = null;
|
||||
let scope: Scope.Closeable | null = null;
|
||||
@@ -223,8 +221,13 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
Layer.provide(RepositoryIdentityResolverLive),
|
||||
Layer.provide(SqlitePersistenceMemory),
|
||||
);
|
||||
const projectionSnapshotLayer = OrchestrationProjectionSnapshotQueryLive.pipe(
|
||||
Layer.provide(RepositoryIdentityResolverLive),
|
||||
Layer.provide(SqlitePersistenceMemory),
|
||||
);
|
||||
const layer = ProviderRuntimeIngestionLive.pipe(
|
||||
Layer.provideMerge(orchestrationLayer),
|
||||
Layer.provideMerge(projectionSnapshotLayer),
|
||||
Layer.provideMerge(SqlitePersistenceMemory),
|
||||
Layer.provideMerge(Layer.succeed(ProviderService, provider.service)),
|
||||
Layer.provideMerge(makeTestServerSettingsLayer(options?.serverSettings)),
|
||||
@@ -233,6 +236,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
);
|
||||
runtime = ManagedRuntime.make(layer);
|
||||
const engine = await runtime.runPromise(Effect.service(OrchestrationEngineService));
|
||||
const snapshotQuery = await runtime.runPromise(Effect.service(ProjectionSnapshotQuery));
|
||||
const ingestion = await runtime.runPromise(Effect.service(ProviderRuntimeIngestionService));
|
||||
scope = await Effect.runPromise(Scope.make("sequential"));
|
||||
await Effect.runPromise(ingestion.start().pipe(Scope.provide(scope)));
|
||||
@@ -299,6 +303,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
return {
|
||||
engine,
|
||||
readModel: () => Effect.runPromise(snapshotQuery.getSnapshot()),
|
||||
emit: provider.emit,
|
||||
setProviderSession: provider.setSession,
|
||||
drain,
|
||||
@@ -319,7 +324,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) => thread.session?.status === "running" && thread.session?.activeTurnId === "turn-1",
|
||||
);
|
||||
|
||||
@@ -337,7 +342,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.session?.status === "error" &&
|
||||
entry.session?.activeTurnId === null &&
|
||||
@@ -364,7 +369,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
let thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) => entry.session?.status === "running" && entry.session?.activeTurnId === null,
|
||||
);
|
||||
expect(thread.session?.status).toBe("running");
|
||||
@@ -383,7 +388,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.session?.status === "error" &&
|
||||
entry.session?.activeTurnId === null &&
|
||||
@@ -404,7 +409,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.session?.status === "stopped" &&
|
||||
entry.session?.activeTurnId === null &&
|
||||
@@ -425,7 +430,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.session?.status === "ready" &&
|
||||
entry.session?.activeTurnId === null &&
|
||||
@@ -449,7 +454,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" &&
|
||||
thread.session?.activeTurnId === "turn-midturn-lifecycle",
|
||||
@@ -471,7 +476,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await harness.drain();
|
||||
const midReadModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const midReadModel = await harness.readModel();
|
||||
const midThread = midReadModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(midThread?.session?.status).toBe("running");
|
||||
expect(midThread?.session?.activeTurnId).toBe("turn-midturn-lifecycle");
|
||||
@@ -487,7 +492,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) => thread.session?.status === "ready" && thread.session?.activeTurnId === null,
|
||||
);
|
||||
});
|
||||
@@ -524,7 +529,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" &&
|
||||
thread.session?.activeTurnId === "turn-claude-placeholder",
|
||||
@@ -541,7 +546,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) => thread.session?.status === "ready" && thread.session?.activeTurnId === null,
|
||||
);
|
||||
});
|
||||
@@ -560,7 +565,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" && thread.session?.activeTurnId === "turn-primary",
|
||||
);
|
||||
@@ -576,7 +581,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await harness.drain();
|
||||
const midReadModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const midReadModel = await harness.readModel();
|
||||
const midThread = midReadModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(midThread?.session?.status).toBe("running");
|
||||
expect(midThread?.session?.activeTurnId).toBe("turn-primary");
|
||||
@@ -592,7 +597,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) => thread.session?.status === "ready" && thread.session?.activeTurnId === null,
|
||||
);
|
||||
});
|
||||
@@ -611,7 +616,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" &&
|
||||
thread.session?.activeTurnId === "turn-guarded-main",
|
||||
@@ -628,7 +633,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await harness.drain();
|
||||
const midReadModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const midReadModel = await harness.readModel();
|
||||
const midThread = midReadModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(midThread?.session?.status).toBe("running");
|
||||
expect(midThread?.session?.activeTurnId).toBe("turn-guarded-main");
|
||||
@@ -644,7 +649,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) => thread.session?.status === "ready" && thread.session?.activeTurnId === null,
|
||||
);
|
||||
});
|
||||
@@ -693,7 +698,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-1" && !message.streaming,
|
||||
@@ -725,7 +730,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-no-delta" && !message.streaming,
|
||||
@@ -764,7 +769,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-tool-completed-with-data",
|
||||
),
|
||||
@@ -819,7 +824,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-command-completed",
|
||||
),
|
||||
@@ -861,7 +866,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.id === "evt-read-path-completed",
|
||||
),
|
||||
@@ -894,7 +899,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.proposedPlans.some(
|
||||
(proposedPlan: ProviderRuntimeTestProposedPlan) =>
|
||||
proposedPlan.id === "plan:thread-1:turn:turn-plan-final",
|
||||
@@ -1009,7 +1014,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const sourceThreadWithPlan = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.proposedPlans.some(
|
||||
(proposedPlan: ProviderRuntimeTestProposedPlan) =>
|
||||
@@ -1050,7 +1055,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
);
|
||||
|
||||
const sourceThreadBeforeStart = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.proposedPlans.some(
|
||||
(proposedPlan: ProviderRuntimeTestProposedPlan) =>
|
||||
@@ -1076,7 +1081,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const sourceThreadAfterStart = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.proposedPlans.some(
|
||||
(proposedPlan: ProviderRuntimeTestProposedPlan) =>
|
||||
@@ -1158,7 +1163,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" && thread.session?.activeTurnId === activeTurnId,
|
||||
2_000,
|
||||
@@ -1178,7 +1183,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const sourceThreadWithPlan = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.proposedPlans.some(
|
||||
(proposedPlan: ProviderRuntimeTestProposedPlan) =>
|
||||
@@ -1229,7 +1234,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
await harness.drain();
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const sourceThreadAfterRejectedStart = readModel.threads.find(
|
||||
(entry) => entry.id === sourceThreadId,
|
||||
);
|
||||
@@ -1340,7 +1345,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const sourceThreadWithPlan = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.proposedPlans.some(
|
||||
(proposedPlan: ProviderRuntimeTestProposedPlan) =>
|
||||
@@ -1401,7 +1406,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
await harness.drain();
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const sourceThreadAfterUnrelatedStart = readModel.threads.find(
|
||||
(entry) => entry.id === sourceThreadId,
|
||||
);
|
||||
@@ -1427,7 +1432,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" && thread.session?.activeTurnId === "turn-plan-buffer",
|
||||
);
|
||||
@@ -1466,7 +1471,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.proposedPlans.some(
|
||||
(proposedPlan: ProviderRuntimeTestProposedPlan) =>
|
||||
proposedPlan.id === "plan:thread-1:turn:turn-plan-buffer",
|
||||
@@ -1492,7 +1497,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
turnId: asTurnId("turn-buffered"),
|
||||
});
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" && thread.session?.activeTurnId === "turn-buffered",
|
||||
);
|
||||
@@ -1512,7 +1517,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await harness.drain();
|
||||
const midReadModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const midReadModel = await harness.readModel();
|
||||
const midThread = midReadModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(
|
||||
midThread?.messages.some(
|
||||
@@ -1534,7 +1539,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-buffered" && !message.streaming,
|
||||
@@ -1560,7 +1565,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
turnId: asTurnId("turn-buffered-request-flush"),
|
||||
});
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" &&
|
||||
thread.session?.activeTurnId === "turn-buffered-request-flush",
|
||||
@@ -1593,7 +1598,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-buffered-request-flush" &&
|
||||
@@ -1620,7 +1625,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
turnId: asTurnId("turn-buffered-user-input-flush"),
|
||||
});
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" &&
|
||||
thread.session?.activeTurnId === "turn-buffered-user-input-flush",
|
||||
@@ -1659,7 +1664,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-buffered-user-input-flush" &&
|
||||
@@ -1688,7 +1693,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
turnId: asTurnId("turn-buffered-whitespace-request"),
|
||||
});
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" &&
|
||||
thread.session?.activeTurnId === "turn-buffered-whitespace-request",
|
||||
@@ -1721,7 +1726,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.kind === "approval.requested",
|
||||
),
|
||||
@@ -1750,7 +1755,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
turnId: asTurnId("turn-buffered-request-append"),
|
||||
});
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" &&
|
||||
thread.session?.activeTurnId === "turn-buffered-request-append",
|
||||
@@ -1783,7 +1788,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
await waitForThread(harness.engine, (entry) =>
|
||||
await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-buffered-request-append" &&
|
||||
@@ -1819,7 +1824,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-buffered-request-append:segment:1" &&
|
||||
@@ -1882,7 +1887,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
turnId: asTurnId("turn-streaming-request-segment"),
|
||||
});
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" &&
|
||||
thread.session?.activeTurnId === "turn-streaming-request-segment",
|
||||
@@ -1915,7 +1920,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
await waitForThread(harness.engine, (entry) =>
|
||||
await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-streaming-request-segment" &&
|
||||
@@ -1951,7 +1956,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-streaming-request-segment:segment:1" &&
|
||||
@@ -2004,7 +2009,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
turnId: asTurnId("turn-streaming-mode"),
|
||||
});
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" &&
|
||||
thread.session?.activeTurnId === "turn-streaming-mode",
|
||||
@@ -2024,7 +2029,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const liveThread = await waitForThread(harness.engine, (entry) =>
|
||||
const liveThread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-streaming-mode" &&
|
||||
@@ -2052,7 +2057,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const finalThread = await waitForThread(harness.engine, (entry) =>
|
||||
const finalThread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-streaming-mode" && !message.streaming,
|
||||
@@ -2079,7 +2084,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
turnId: asTurnId("turn-buffer-spill"),
|
||||
});
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" &&
|
||||
thread.session?.activeTurnId === "turn-buffer-spill",
|
||||
@@ -2112,7 +2117,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.messages.some(
|
||||
(message: ProviderRuntimeTestMessage) =>
|
||||
message.id === "assistant:item-buffer-spill" && !message.streaming,
|
||||
@@ -2140,7 +2145,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "running" &&
|
||||
thread.session?.activeTurnId === "turn-complete-dedup",
|
||||
@@ -2185,7 +2190,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(thread) =>
|
||||
thread.session?.status === "ready" &&
|
||||
thread.session?.activeTurnId === null &&
|
||||
@@ -2243,7 +2248,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.kind === "approval.requested",
|
||||
@@ -2253,7 +2258,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
),
|
||||
);
|
||||
|
||||
const readModel = await Effect.runPromise(harness.engine.getReadModel());
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread).toBeDefined();
|
||||
|
||||
@@ -2295,7 +2300,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.session?.status === "error" &&
|
||||
entry.session?.activeTurnId === "turn-3" &&
|
||||
@@ -2321,7 +2326,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.activities.some((activity) => activity.id === "evt-runtime-error-activity"),
|
||||
);
|
||||
const activity = thread.activities.find(
|
||||
@@ -2366,7 +2371,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.session?.status === "running" &&
|
||||
entry.session?.activeTurnId === "turn-warning" &&
|
||||
@@ -2415,7 +2420,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.session?.status === "ready" &&
|
||||
entry.session?.activeTurnId === null &&
|
||||
@@ -2508,7 +2513,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.title === "Renamed by provider" &&
|
||||
entry.activities.some(
|
||||
@@ -2595,7 +2600,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.kind === "context-window.updated",
|
||||
),
|
||||
@@ -2647,7 +2652,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.kind === "context-window.updated",
|
||||
),
|
||||
@@ -2697,7 +2702,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.kind === "context-window.updated",
|
||||
),
|
||||
@@ -2732,7 +2737,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const thread = await waitForThread(harness.engine, (entry) =>
|
||||
const thread = await waitForThread(harness.readModel, (entry) =>
|
||||
entry.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.kind === "context-compaction",
|
||||
),
|
||||
@@ -2802,7 +2807,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.kind === "task.completed",
|
||||
@@ -2893,7 +2898,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.activities.some(
|
||||
(activity: ProviderRuntimeTestActivity) => activity.kind === "user-input.requested",
|
||||
@@ -2952,7 +2957,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
});
|
||||
|
||||
const thread = await waitForThread(
|
||||
harness.engine,
|
||||
harness.readModel,
|
||||
(entry) =>
|
||||
entry.session?.status === "error" &&
|
||||
entry.session?.activeTurnId === "turn-after-failure" &&
|
||||
|
||||
@@ -4,12 +4,16 @@ import {
|
||||
CommandId,
|
||||
MessageId,
|
||||
type OrchestrationEvent,
|
||||
type OrchestrationMessage,
|
||||
type OrchestrationProposedPlanId,
|
||||
CheckpointRef,
|
||||
isToolLifecycleItemType,
|
||||
ThreadId,
|
||||
type ThreadTokenUsageSnapshot,
|
||||
TurnId,
|
||||
type OrchestrationCheckpointSummary,
|
||||
type OrchestrationProposedPlan,
|
||||
type OrchestrationThread,
|
||||
type OrchestrationThreadActivity,
|
||||
type ProviderRuntimeEvent,
|
||||
} from "@t3tools/contracts";
|
||||
@@ -19,9 +23,9 @@ import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
|
||||
import { ProviderService } from "../../provider/Services/ProviderService.ts";
|
||||
import { ProjectionTurnRepository } from "../../persistence/Services/ProjectionTurns.ts";
|
||||
import { ProjectionTurnRepositoryLive } from "../../persistence/Layers/ProjectionTurns.ts";
|
||||
import { resolveThreadWorkspaceCwd } from "../../checkpointing/Utils.ts";
|
||||
import { isGitRepository } from "../../git/Utils.ts";
|
||||
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
|
||||
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
|
||||
import {
|
||||
ProviderRuntimeIngestionService,
|
||||
type ProviderRuntimeIngestionShape,
|
||||
@@ -77,6 +81,82 @@ function sameId(left: string | null | undefined, right: string | null | undefine
|
||||
return left === right;
|
||||
}
|
||||
|
||||
function hasAssistantMessageForTurn(
|
||||
messages: ReadonlyArray<OrchestrationMessage>,
|
||||
turnId: TurnId,
|
||||
options?: { readonly streamingOnly?: boolean },
|
||||
): boolean {
|
||||
for (let index = 0; index < messages.length; index += 1) {
|
||||
const message = messages[index];
|
||||
if (!message) {
|
||||
continue;
|
||||
}
|
||||
if (message.role !== "assistant" || message.turnId !== turnId) {
|
||||
continue;
|
||||
}
|
||||
if (options?.streamingOnly === true && !message.streaming) {
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function findMessageById(
|
||||
messages: ReadonlyArray<OrchestrationMessage>,
|
||||
messageId: MessageId,
|
||||
): OrchestrationMessage | undefined {
|
||||
for (let index = 0; index < messages.length; index += 1) {
|
||||
const message = messages[index];
|
||||
if (message?.id === messageId) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function findProposedPlanById(
|
||||
proposedPlans: ReadonlyArray<
|
||||
Pick<OrchestrationProposedPlan, "id" | "createdAt" | "implementedAt" | "implementationThreadId">
|
||||
>,
|
||||
planId: string,
|
||||
):
|
||||
| Pick<OrchestrationProposedPlan, "id" | "createdAt" | "implementedAt" | "implementationThreadId">
|
||||
| undefined {
|
||||
for (let index = 0; index < proposedPlans.length; index += 1) {
|
||||
const proposedPlan = proposedPlans[index];
|
||||
if (proposedPlan?.id === planId) {
|
||||
return proposedPlan;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function hasCheckpointForTurn(
|
||||
checkpoints: ReadonlyArray<OrchestrationCheckpointSummary>,
|
||||
turnId: TurnId,
|
||||
): boolean {
|
||||
for (let index = 0; index < checkpoints.length; index += 1) {
|
||||
if (checkpoints[index]?.turnId === turnId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function maxCheckpointTurnCount(
|
||||
checkpoints: ReadonlyArray<OrchestrationCheckpointSummary>,
|
||||
): number {
|
||||
let maxTurnCount = 0;
|
||||
for (let index = 0; index < checkpoints.length; index += 1) {
|
||||
const checkpoint = checkpoints[index];
|
||||
if (checkpoint && checkpoint.checkpointTurnCount > maxTurnCount) {
|
||||
maxTurnCount = checkpoint.checkpointTurnCount;
|
||||
}
|
||||
}
|
||||
return maxTurnCount;
|
||||
}
|
||||
|
||||
function truncateDetail(value: string, limit = 180): string {
|
||||
return value.length > limit ? `${value.slice(0, limit - 3)}...` : value;
|
||||
}
|
||||
@@ -522,6 +602,7 @@ function runtimeEventToActivities(
|
||||
|
||||
const make = Effect.gen(function* () {
|
||||
const orchestrationEngine = yield* OrchestrationEngineService;
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
const providerService = yield* ProviderService;
|
||||
const projectionTurnRepository = yield* ProjectionTurnRepository;
|
||||
const serverSettingsService = yield* ServerSettingsService;
|
||||
@@ -553,20 +634,16 @@ const make = Effect.gen(function* () {
|
||||
lookup: () => Effect.succeed({ text: "", createdAt: "" }),
|
||||
});
|
||||
|
||||
const isGitRepoForThread = Effect.fn("isGitRepoForThread")(function* (threadId: ThreadId) {
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === threadId);
|
||||
if (!thread) {
|
||||
return false;
|
||||
}
|
||||
const workspaceCwd = resolveThreadWorkspaceCwd({
|
||||
thread,
|
||||
projects: readModel.projects,
|
||||
});
|
||||
if (!workspaceCwd) {
|
||||
return false;
|
||||
}
|
||||
return isGitRepository(workspaceCwd);
|
||||
const resolveThreadDetail = Effect.fn("resolveThreadDetail")(function* (threadId: ThreadId) {
|
||||
return yield* projectionSnapshotQuery
|
||||
.getThreadDetailById(threadId)
|
||||
.pipe(Effect.map(Option.getOrUndefined));
|
||||
});
|
||||
|
||||
const resolveThreadShell = Effect.fn("resolveThreadShell")(function* (threadId: ThreadId) {
|
||||
return yield* projectionSnapshotQuery
|
||||
.getThreadShellById(threadId)
|
||||
.pipe(Effect.map(Option.getOrUndefined));
|
||||
});
|
||||
|
||||
const rememberAssistantMessageId = (threadId: ThreadId, turnId: TurnId, messageId: MessageId) =>
|
||||
@@ -917,7 +994,7 @@ const make = Effect.gen(function* () {
|
||||
return;
|
||||
}
|
||||
|
||||
const existingPlan = input.threadProposedPlans.find((entry) => entry.id === input.planId);
|
||||
const existingPlan = findProposedPlanById(input.threadProposedPlans, input.planId);
|
||||
yield* orchestrationEngine.dispatch({
|
||||
type: "thread.proposed-plan.upsert",
|
||||
commandId: providerCommandId(input.event, "proposed-plan-upsert"),
|
||||
@@ -1070,8 +1147,7 @@ const make = Effect.gen(function* () {
|
||||
implementationThreadId: ThreadId,
|
||||
implementedAt: string,
|
||||
) {
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const sourceThread = readModel.threads.find((entry) => entry.id === sourceThreadId);
|
||||
const sourceThread = yield* resolveThreadDetail(sourceThreadId);
|
||||
const sourcePlan = sourceThread?.proposedPlans.find((entry) => entry.id === sourcePlanId);
|
||||
if (!sourceThread || !sourcePlan || sourcePlan.implementedAt !== null) {
|
||||
return;
|
||||
@@ -1096,10 +1172,19 @@ const make = Effect.gen(function* () {
|
||||
|
||||
const processRuntimeEvent = (event: ProviderRuntimeEvent) =>
|
||||
Effect.gen(function* () {
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === event.threadId);
|
||||
const thread = yield* resolveThreadShell(event.threadId);
|
||||
if (!thread) return;
|
||||
|
||||
let loadedThreadDetail: OrchestrationThread | null | undefined;
|
||||
const getLoadedThreadDetail = () =>
|
||||
Effect.gen(function* () {
|
||||
if (loadedThreadDetail !== undefined) {
|
||||
return loadedThreadDetail;
|
||||
}
|
||||
loadedThreadDetail = (yield* resolveThreadDetail(thread.id)) ?? null;
|
||||
return loadedThreadDetail;
|
||||
});
|
||||
|
||||
const now = event.createdAt;
|
||||
const eventTurnId = toTurnId(event.turnId);
|
||||
const activeTurnId = thread.session?.activeTurnId ?? null;
|
||||
@@ -1277,6 +1362,7 @@ const make = Effect.gen(function* () {
|
||||
? toTurnId(event.turnId)
|
||||
: undefined;
|
||||
if (pauseForUserTurnId) {
|
||||
const detailedThread = yield* getLoadedThreadDetail();
|
||||
const assistantDeliveryMode: AssistantDeliveryMode = yield* Effect.map(
|
||||
serverSettingsService.getSettings,
|
||||
(settings) => (settings.enableAssistantStreaming ? "streaming" : "buffered"),
|
||||
@@ -1307,10 +1393,11 @@ const make = Effect.gen(function* () {
|
||||
event.type === "request.opened"
|
||||
? "assistant-delta-finalize-on-request-opened"
|
||||
: "assistant-delta-finalize-on-user-input-requested",
|
||||
hasProjectedMessage: thread.messages.some(
|
||||
(entry) =>
|
||||
entry.role === "assistant" && entry.turnId === pauseForUserTurnId && entry.streaming,
|
||||
),
|
||||
hasProjectedMessage:
|
||||
detailedThread !== null &&
|
||||
hasAssistantMessageForTurn(detailedThread.messages, pauseForUserTurnId, {
|
||||
streamingOnly: true,
|
||||
}),
|
||||
flushedMessageIds,
|
||||
});
|
||||
}
|
||||
@@ -1339,21 +1426,19 @@ const make = Effect.gen(function* () {
|
||||
: undefined;
|
||||
|
||||
if (assistantCompletion) {
|
||||
const detailedThread = yield* getLoadedThreadDetail();
|
||||
const messages = detailedThread?.messages ?? [];
|
||||
const turnId = toTurnId(event.turnId);
|
||||
const activeAssistantMessageId = turnId
|
||||
? yield* getActiveAssistantMessageIdForTurn(thread.id, turnId)
|
||||
: Option.none<MessageId>();
|
||||
const hasAssistantMessagesForTurn =
|
||||
turnId !== undefined
|
||||
? thread.messages.some((entry) => entry.role === "assistant" && entry.turnId === turnId)
|
||||
: false;
|
||||
turnId !== undefined ? hasAssistantMessageForTurn(messages, turnId) : false;
|
||||
const assistantMessageId = Option.getOrElse(
|
||||
activeAssistantMessageId,
|
||||
() => assistantCompletion.messageId,
|
||||
);
|
||||
const existingAssistantMessage = thread.messages.find(
|
||||
(entry) => entry.id === assistantMessageId,
|
||||
);
|
||||
const existingAssistantMessage = findMessageById(messages, assistantMessageId);
|
||||
const shouldApplyFallbackCompletionText =
|
||||
!existingAssistantMessage || existingAssistantMessage.text.length === 0;
|
||||
|
||||
@@ -1393,10 +1478,11 @@ const make = Effect.gen(function* () {
|
||||
}
|
||||
|
||||
if (proposedPlanCompletion) {
|
||||
const detailedThread = yield* getLoadedThreadDetail();
|
||||
yield* finalizeBufferedProposedPlan({
|
||||
event,
|
||||
threadId: thread.id,
|
||||
threadProposedPlans: thread.proposedPlans,
|
||||
threadProposedPlans: detailedThread?.proposedPlans ?? [],
|
||||
planId: proposedPlanCompletion.planId,
|
||||
...(proposedPlanCompletion.turnId ? { turnId: proposedPlanCompletion.turnId } : {}),
|
||||
fallbackMarkdown: proposedPlanCompletion.planMarkdown,
|
||||
@@ -1405,6 +1491,9 @@ const make = Effect.gen(function* () {
|
||||
}
|
||||
|
||||
if (event.type === "turn.completed") {
|
||||
const detailedThread = yield* getLoadedThreadDetail();
|
||||
const messages = detailedThread?.messages ?? [];
|
||||
const proposedPlans = detailedThread?.proposedPlans ?? [];
|
||||
const turnId = toTurnId(event.turnId);
|
||||
if (turnId) {
|
||||
const assistantMessageIds = yield* getAssistantMessageIdsForTurn(thread.id, turnId);
|
||||
@@ -1419,9 +1508,7 @@ const make = Effect.gen(function* () {
|
||||
createdAt: now,
|
||||
commandTag: "assistant-complete-finalize",
|
||||
finalDeltaCommandTag: "assistant-delta-finalize-fallback",
|
||||
hasProjectedMessage: thread.messages.some(
|
||||
(entry) => entry.id === assistantMessageId,
|
||||
),
|
||||
hasProjectedMessage: findMessageById(messages, assistantMessageId) !== undefined,
|
||||
}),
|
||||
{ concurrency: 1 },
|
||||
).pipe(Effect.asVoid);
|
||||
@@ -1431,7 +1518,7 @@ const make = Effect.gen(function* () {
|
||||
yield* finalizeBufferedProposedPlan({
|
||||
event,
|
||||
threadId: thread.id,
|
||||
threadProposedPlans: thread.proposedPlans,
|
||||
threadProposedPlans: proposedPlans,
|
||||
planId: proposedPlanIdForTurn(thread.id, turnId),
|
||||
turnId,
|
||||
updatedAt: now,
|
||||
@@ -1483,21 +1570,24 @@ const make = Effect.gen(function* () {
|
||||
|
||||
if (event.type === "turn.diff.updated") {
|
||||
const turnId = toTurnId(event.turnId);
|
||||
if (turnId && (yield* isGitRepoForThread(thread.id))) {
|
||||
const checkpointContext = turnId
|
||||
? yield* projectionSnapshotQuery
|
||||
.getThreadCheckpointContext(thread.id)
|
||||
.pipe(Effect.map(Option.getOrUndefined))
|
||||
: undefined;
|
||||
const workspaceCwd =
|
||||
checkpointContext?.worktreePath ?? checkpointContext?.workspaceRoot ?? undefined;
|
||||
if (turnId && checkpointContext && workspaceCwd && isGitRepository(workspaceCwd)) {
|
||||
// Skip if a checkpoint already exists for this turn. A real
|
||||
// (non-placeholder) capture from CheckpointReactor should not
|
||||
// be clobbered, and dispatching a duplicate placeholder for the
|
||||
// same turnId would produce an unstable checkpointTurnCount.
|
||||
if (thread.checkpoints.some((c) => c.turnId === turnId)) {
|
||||
if (hasCheckpointForTurn(checkpointContext.checkpoints, turnId)) {
|
||||
// Already tracked; no-op.
|
||||
} else {
|
||||
const assistantMessageId = MessageId.make(
|
||||
`assistant:${event.itemId ?? event.turnId ?? event.eventId}`,
|
||||
);
|
||||
const maxTurnCount = thread.checkpoints.reduce(
|
||||
(max, c) => Math.max(max, c.checkpointTurnCount),
|
||||
0,
|
||||
);
|
||||
yield* orchestrationEngine.dispatch({
|
||||
type: "thread.turn.diff.complete",
|
||||
commandId: providerCommandId(event, "thread-turn-diff-complete"),
|
||||
@@ -1508,7 +1598,7 @@ const make = Effect.gen(function* () {
|
||||
status: "missing",
|
||||
files: [],
|
||||
assistantMessageId,
|
||||
checkpointTurnCount: maxTurnCount + 1,
|
||||
checkpointTurnCount: maxCheckpointTurnCount(checkpointContext.checkpoints) + 1,
|
||||
createdAt: now,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,11 +10,7 @@
|
||||
*
|
||||
* @module OrchestrationEngineService
|
||||
*/
|
||||
import type {
|
||||
OrchestrationCommand,
|
||||
OrchestrationEvent,
|
||||
OrchestrationReadModel,
|
||||
} from "@t3tools/contracts";
|
||||
import type { OrchestrationCommand, OrchestrationEvent } from "@t3tools/contracts";
|
||||
import { Context } from "effect";
|
||||
import type { Effect, Stream } from "effect";
|
||||
|
||||
@@ -25,13 +21,6 @@ import type { OrchestrationEventStoreError } from "../../persistence/Errors.ts";
|
||||
* OrchestrationEngineShape - Service API for orchestration command and event flow.
|
||||
*/
|
||||
export interface OrchestrationEngineShape {
|
||||
/**
|
||||
* Read the current in-memory orchestration read model.
|
||||
*
|
||||
* @returns Effect containing the latest read model.
|
||||
*/
|
||||
readonly getReadModel: () => Effect.Effect<OrchestrationReadModel, never, never>;
|
||||
|
||||
/**
|
||||
* Replay persisted orchestration events from an exclusive sequence cursor.
|
||||
*
|
||||
@@ -70,7 +59,7 @@ export interface OrchestrationEngineShape {
|
||||
* ```ts
|
||||
* const program = Effect.gen(function* () {
|
||||
* const engine = yield* OrchestrationEngineService
|
||||
* return yield* engine.getReadModel()
|
||||
* return yield* engine.dispatch(command)
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
|
||||
@@ -28,6 +28,10 @@ export interface ProjectionSnapshotCounts {
|
||||
readonly threadCount: number;
|
||||
}
|
||||
|
||||
export interface ProjectionSnapshotSequence {
|
||||
readonly snapshotSequence: number;
|
||||
}
|
||||
|
||||
export interface ProjectionThreadCheckpointContext {
|
||||
readonly threadId: ThreadId;
|
||||
readonly projectId: ProjectId;
|
||||
@@ -40,6 +44,15 @@ export interface ProjectionThreadCheckpointContext {
|
||||
* ProjectionSnapshotQueryShape - Service API for read-model snapshots.
|
||||
*/
|
||||
export interface ProjectionSnapshotQueryShape {
|
||||
/**
|
||||
* Read the lightweight command snapshot used to bootstrap the in-memory
|
||||
* orchestration engine without hydrating message/activity/checkpoint bodies.
|
||||
*/
|
||||
readonly getCommandReadModel: () => Effect.Effect<
|
||||
OrchestrationReadModel,
|
||||
ProjectionRepositoryError
|
||||
>;
|
||||
|
||||
/**
|
||||
* Read the latest orchestration projection snapshot.
|
||||
*
|
||||
@@ -59,6 +72,15 @@ export interface ProjectionSnapshotQueryShape {
|
||||
ProjectionRepositoryError
|
||||
>;
|
||||
|
||||
/**
|
||||
* Read the latest projection snapshot sequence without hydrating read-model
|
||||
* entities.
|
||||
*/
|
||||
readonly getSnapshotSequence: () => Effect.Effect<
|
||||
ProjectionSnapshotSequence,
|
||||
ProjectionRepositoryError
|
||||
>;
|
||||
|
||||
/**
|
||||
* Read aggregate projection counts without hydrating the full read model.
|
||||
*/
|
||||
|
||||
@@ -41,6 +41,7 @@ import Migration0025 from "./Migrations/025_CleanupInvalidProjectionPendingAppro
|
||||
import Migration0026 from "./Migrations/026_CanonicalizeModelSelectionOptions.ts";
|
||||
import Migration0027 from "./Migrations/027_ProviderSessionRuntimeInstanceId.ts";
|
||||
import Migration0028 from "./Migrations/028_ProjectionThreadSessionInstanceId.ts";
|
||||
import Migration0029 from "./Migrations/029_ProjectionThreadDetailOrderingIndexes.ts";
|
||||
|
||||
/**
|
||||
* Migration loader with all migrations defined inline.
|
||||
@@ -81,6 +82,7 @@ export const migrationEntries = [
|
||||
[26, "CanonicalizeModelSelectionOptions", Migration0026],
|
||||
[27, "ProviderSessionRuntimeInstanceId", Migration0027],
|
||||
[28, "ProjectionThreadSessionInstanceId", Migration0028],
|
||||
[29, "ProjectionThreadDetailOrderingIndexes", Migration0029],
|
||||
] as const;
|
||||
|
||||
export const makeMigrationLoader = (throughId?: number) =>
|
||||
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { Effect, Layer } from "effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
import { runMigrations } from "../Migrations.ts";
|
||||
import * as NodeSqliteClient from "../NodeSqliteClient.ts";
|
||||
|
||||
const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layerMemory()));
|
||||
|
||||
layer("029_ProjectionThreadDetailOrderingIndexes", (it) => {
|
||||
it.effect("creates indexes matching thread detail ordering queries", () =>
|
||||
Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* runMigrations({ toMigrationInclusive: 28 });
|
||||
yield* runMigrations({ toMigrationInclusive: 29 });
|
||||
|
||||
const activityIndexes = yield* sql<{
|
||||
readonly seq: number;
|
||||
readonly name: string;
|
||||
readonly unique: number;
|
||||
readonly origin: string;
|
||||
readonly partial: number;
|
||||
}>`
|
||||
PRAGMA index_list(projection_thread_activities)
|
||||
`;
|
||||
assert.ok(
|
||||
activityIndexes.some(
|
||||
(index) => index.name === "idx_projection_thread_activities_thread_sequence_created_id",
|
||||
),
|
||||
);
|
||||
|
||||
const activityIndexColumns = yield* sql<{
|
||||
readonly seqno: number;
|
||||
readonly cid: number;
|
||||
readonly name: string;
|
||||
}>`
|
||||
PRAGMA index_info('idx_projection_thread_activities_thread_sequence_created_id')
|
||||
`;
|
||||
assert.deepStrictEqual(
|
||||
activityIndexColumns.map((column) => column.name),
|
||||
["thread_id", "sequence", "created_at", "activity_id"],
|
||||
);
|
||||
|
||||
const messageIndexes = yield* sql<{
|
||||
readonly seq: number;
|
||||
readonly name: string;
|
||||
readonly unique: number;
|
||||
readonly origin: string;
|
||||
readonly partial: number;
|
||||
}>`
|
||||
PRAGMA index_list(projection_thread_messages)
|
||||
`;
|
||||
assert.ok(
|
||||
messageIndexes.some(
|
||||
(index) => index.name === "idx_projection_thread_messages_thread_created_id",
|
||||
),
|
||||
);
|
||||
|
||||
const messageIndexColumns = yield* sql<{
|
||||
readonly seqno: number;
|
||||
readonly cid: number;
|
||||
readonly name: string;
|
||||
}>`
|
||||
PRAGMA index_info('idx_projection_thread_messages_thread_created_id')
|
||||
`;
|
||||
assert.deepStrictEqual(
|
||||
messageIndexColumns.map((column) => column.name),
|
||||
["thread_id", "created_at", "message_id"],
|
||||
);
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
export default Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* sql`
|
||||
CREATE INDEX IF NOT EXISTS idx_projection_thread_activities_thread_sequence_created_id
|
||||
ON projection_thread_activities(thread_id, sequence, created_at, activity_id)
|
||||
`;
|
||||
|
||||
yield* sql`
|
||||
CREATE INDEX IF NOT EXISTS idx_projection_thread_messages_thread_created_id
|
||||
ON projection_thread_messages(thread_id, created_at, message_id)
|
||||
`;
|
||||
});
|
||||
@@ -1,53 +1,52 @@
|
||||
import { Effect, Layer, Stream } from "effect";
|
||||
import { ProjectId, type OrchestrationProject } from "@t3tools/contracts";
|
||||
import { Effect, Layer, Option } from "effect";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { OrchestrationReadModel } from "@t3tools/contracts";
|
||||
|
||||
import { OrchestrationEngineService } from "../../orchestration/Services/OrchestrationEngine.ts";
|
||||
import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import { TerminalManager } from "../../terminal/Services/Manager.ts";
|
||||
import { ProjectSetupScriptRunner } from "../Services/ProjectSetupScriptRunner.ts";
|
||||
import { ProjectSetupScriptRunnerLive } from "./ProjectSetupScriptRunner.ts";
|
||||
|
||||
const emptySnapshot = (
|
||||
scripts: OrchestrationReadModel["projects"][number]["scripts"],
|
||||
): OrchestrationReadModel =>
|
||||
({
|
||||
snapshotSequence: 1,
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
projects: [
|
||||
{
|
||||
id: "project-1",
|
||||
title: "Project",
|
||||
workspaceRoot: "/repo/project",
|
||||
defaultModelSelection: null,
|
||||
scripts,
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
deletedAt: null,
|
||||
},
|
||||
],
|
||||
threads: [],
|
||||
providerSessions: [],
|
||||
providerStatuses: [],
|
||||
pendingApprovals: [],
|
||||
latestTurnByThreadId: {},
|
||||
}) as unknown as OrchestrationReadModel;
|
||||
const makeProject = (scripts: OrchestrationProject["scripts"]): OrchestrationProject => ({
|
||||
id: ProjectId.make("project-1"),
|
||||
title: "Project",
|
||||
workspaceRoot: "/repo/project",
|
||||
defaultModelSelection: null,
|
||||
scripts,
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
updatedAt: "2026-01-01T00:00:00.000Z",
|
||||
deletedAt: null,
|
||||
});
|
||||
|
||||
const makeProjectionSnapshotQueryLayer = (project: OrchestrationProject) =>
|
||||
Layer.succeed(ProjectionSnapshotQuery, {
|
||||
getCommandReadModel: () => Effect.die("unused"),
|
||||
getSnapshot: () => Effect.die("unused"),
|
||||
getShellSnapshot: () => Effect.die("unused"),
|
||||
getSnapshotSequence: () => Effect.succeed({ snapshotSequence: 1 }),
|
||||
getCounts: () => Effect.die("unused"),
|
||||
getActiveProjectByWorkspaceRoot: (workspaceRoot) =>
|
||||
Effect.succeed(
|
||||
workspaceRoot === project.workspaceRoot ? Option.some(project) : Option.none(),
|
||||
),
|
||||
getProjectShellById: (projectId) =>
|
||||
Effect.succeed(projectId === project.id ? Option.some(project) : Option.none()),
|
||||
getFirstActiveThreadIdByProjectId: () => Effect.die("unused"),
|
||||
getThreadCheckpointContext: () => Effect.die("unused"),
|
||||
getThreadShellById: () => Effect.die("unused"),
|
||||
getThreadDetailById: () => Effect.die("unused"),
|
||||
});
|
||||
|
||||
describe("ProjectSetupScriptRunner", () => {
|
||||
it("returns no-script when no setup script exists", async () => {
|
||||
const open = vi.fn();
|
||||
const write = vi.fn();
|
||||
const project = makeProject([]);
|
||||
const runner = await Effect.runPromise(
|
||||
Effect.service(ProjectSetupScriptRunner).pipe(
|
||||
Effect.provide(
|
||||
ProjectSetupScriptRunnerLive.pipe(
|
||||
Layer.provideMerge(
|
||||
Layer.succeed(OrchestrationEngineService, {
|
||||
getReadModel: () => Effect.succeed(emptySnapshot([])),
|
||||
readEvents: () => Stream.empty,
|
||||
dispatch: () => Effect.die(new Error("unused")),
|
||||
streamDomainEvents: Stream.empty,
|
||||
}),
|
||||
),
|
||||
Layer.provideMerge(makeProjectionSnapshotQueryLayer(project)),
|
||||
Layer.provideMerge(
|
||||
Layer.succeed(TerminalManager, {
|
||||
open,
|
||||
@@ -93,29 +92,20 @@ describe("ProjectSetupScriptRunner", () => {
|
||||
}),
|
||||
);
|
||||
const write = vi.fn(() => Effect.void);
|
||||
const project = makeProject([
|
||||
{
|
||||
id: "setup",
|
||||
name: "Setup",
|
||||
command: "bun install",
|
||||
icon: "configure",
|
||||
runOnWorktreeCreate: true,
|
||||
},
|
||||
]);
|
||||
const runner = await Effect.runPromise(
|
||||
Effect.service(ProjectSetupScriptRunner).pipe(
|
||||
Effect.provide(
|
||||
ProjectSetupScriptRunnerLive.pipe(
|
||||
Layer.provideMerge(
|
||||
Layer.succeed(OrchestrationEngineService, {
|
||||
getReadModel: () =>
|
||||
Effect.succeed(
|
||||
emptySnapshot([
|
||||
{
|
||||
id: "setup",
|
||||
name: "Setup",
|
||||
command: "bun install",
|
||||
icon: "configure",
|
||||
runOnWorktreeCreate: true,
|
||||
},
|
||||
]),
|
||||
),
|
||||
readEvents: () => Stream.empty,
|
||||
dispatch: () => Effect.die(new Error("unused")),
|
||||
streamDomainEvents: Stream.empty,
|
||||
}),
|
||||
),
|
||||
Layer.provideMerge(makeProjectionSnapshotQueryLayer(project)),
|
||||
Layer.provideMerge(
|
||||
Layer.succeed(TerminalManager, {
|
||||
open,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { ProjectId } from "@t3tools/contracts";
|
||||
import { projectScriptRuntimeEnv, setupProjectScript } from "@t3tools/shared/projectScripts";
|
||||
import { Effect, Layer } from "effect";
|
||||
import { Effect, Layer, Option } from "effect";
|
||||
|
||||
import { OrchestrationEngineService } from "../../orchestration/Services/OrchestrationEngine.ts";
|
||||
import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import { TerminalManager } from "../../terminal/Services/Manager.ts";
|
||||
import {
|
||||
type ProjectSetupScriptRunnerShape,
|
||||
@@ -9,18 +10,21 @@ import {
|
||||
} from "../Services/ProjectSetupScriptRunner.ts";
|
||||
|
||||
const makeProjectSetupScriptRunner = Effect.gen(function* () {
|
||||
const orchestrationEngine = yield* OrchestrationEngineService;
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
const terminalManager = yield* TerminalManager;
|
||||
|
||||
const runForThread: ProjectSetupScriptRunnerShape["runForThread"] = (input) =>
|
||||
Effect.gen(function* () {
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const project =
|
||||
(input.projectId
|
||||
? readModel.projects.find((entry) => entry.id === input.projectId)
|
||||
? yield* projectionSnapshotQuery
|
||||
.getProjectShellById(ProjectId.make(input.projectId))
|
||||
.pipe(Effect.map(Option.getOrUndefined))
|
||||
: null) ??
|
||||
(input.projectCwd
|
||||
? readModel.projects.find((entry) => entry.workspaceRoot === input.projectCwd)
|
||||
? yield* projectionSnapshotQuery
|
||||
.getActiveProjectByWorkspaceRoot(input.projectCwd)
|
||||
.pipe(Effect.map(Option.getOrUndefined))
|
||||
: null) ??
|
||||
null;
|
||||
|
||||
|
||||
@@ -9,10 +9,7 @@ import {
|
||||
import { Effect, Exit, Layer, ManagedRuntime, Option, Scope, Stream } from "effect";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
OrchestrationEngineService,
|
||||
type OrchestrationEngineShape,
|
||||
} from "../../orchestration/Services/OrchestrationEngine.ts";
|
||||
import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
|
||||
import { ProviderSessionRuntimeRepositoryLive } from "../../persistence/Layers/ProviderSessionRuntime.ts";
|
||||
import { ProviderSessionRuntimeRepository } from "../../persistence/Services/ProviderSessionRuntime.ts";
|
||||
@@ -92,6 +89,10 @@ function makeReadModel(
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
archivedAt: null,
|
||||
latestUserMessageAt: null,
|
||||
hasPendingApprovals: false,
|
||||
hasPendingUserInput: false,
|
||||
hasActionableProposedPlan: false,
|
||||
latestTurn: null,
|
||||
messages: [],
|
||||
session: thread.session,
|
||||
@@ -163,13 +164,6 @@ describe("ProviderSessionReaper", () => {
|
||||
streamEvents: Stream.empty,
|
||||
};
|
||||
|
||||
const orchestrationEngine: OrchestrationEngineShape = {
|
||||
getReadModel: () => Effect.succeed(input.readModel),
|
||||
readEvents: () => Stream.empty,
|
||||
dispatch: () => unsupported(),
|
||||
streamDomainEvents: Stream.empty,
|
||||
};
|
||||
|
||||
const runtimeRepositoryLayer = ProviderSessionRuntimeRepositoryLive.pipe(
|
||||
Layer.provide(SqlitePersistenceMemory),
|
||||
);
|
||||
@@ -183,7 +177,27 @@ describe("ProviderSessionReaper", () => {
|
||||
Layer.provideMerge(providerSessionDirectoryLayer),
|
||||
Layer.provideMerge(runtimeRepositoryLayer),
|
||||
Layer.provideMerge(Layer.succeed(ProviderService, providerService)),
|
||||
Layer.provideMerge(Layer.succeed(OrchestrationEngineService, orchestrationEngine)),
|
||||
Layer.provideMerge(
|
||||
Layer.succeed(ProjectionSnapshotQuery, {
|
||||
getCommandReadModel: () => Effect.die("unused"),
|
||||
getSnapshot: () => Effect.die("unused"),
|
||||
getShellSnapshot: () => Effect.die("unused"),
|
||||
getSnapshotSequence: () =>
|
||||
Effect.succeed({ snapshotSequence: input.readModel.snapshotSequence }),
|
||||
getCounts: () => Effect.die("unused"),
|
||||
getActiveProjectByWorkspaceRoot: () => Effect.die("unused"),
|
||||
getProjectShellById: () => Effect.die("unused"),
|
||||
getFirstActiveThreadIdByProjectId: () => Effect.die("unused"),
|
||||
getThreadCheckpointContext: () => Effect.die("unused"),
|
||||
getThreadShellById: (threadId) =>
|
||||
Effect.succeed(
|
||||
input.readModel.threads.find((thread) => thread.id === threadId)
|
||||
? Option.some(input.readModel.threads.find((thread) => thread.id === threadId)!)
|
||||
: Option.none(),
|
||||
),
|
||||
getThreadDetailById: () => Effect.die("unused"),
|
||||
}),
|
||||
),
|
||||
Layer.provideMerge(NodeServices.layer),
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Duration, Effect, Layer, Schedule } from "effect";
|
||||
import { Duration, Effect, Layer, Option, Schedule } from "effect";
|
||||
|
||||
import { OrchestrationEngineService } from "../../orchestration/Services/OrchestrationEngine.ts";
|
||||
import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import { ProviderSessionDirectory } from "../Services/ProviderSessionDirectory.ts";
|
||||
import {
|
||||
ProviderSessionReaper,
|
||||
@@ -20,7 +20,7 @@ const makeProviderSessionReaper = (options?: ProviderSessionReaperLiveOptions) =
|
||||
Effect.gen(function* () {
|
||||
const providerService = yield* ProviderService;
|
||||
const directory = yield* ProviderSessionDirectory;
|
||||
const orchestrationEngine = yield* OrchestrationEngineService;
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
|
||||
const inactivityThresholdMs = Math.max(
|
||||
1,
|
||||
@@ -29,8 +29,6 @@ const makeProviderSessionReaper = (options?: ProviderSessionReaperLiveOptions) =
|
||||
const sweepIntervalMs = Math.max(1, options?.sweepIntervalMs ?? DEFAULT_SWEEP_INTERVAL_MS);
|
||||
|
||||
const sweep = Effect.gen(function* () {
|
||||
const readModel = yield* orchestrationEngine.getReadModel();
|
||||
const threadsById = new Map(readModel.threads.map((thread) => [thread.id, thread] as const));
|
||||
const bindings = yield* directory.listBindings();
|
||||
const now = Date.now();
|
||||
let reapedCount = 0;
|
||||
@@ -55,7 +53,9 @@ const makeProviderSessionReaper = (options?: ProviderSessionReaperLiveOptions) =
|
||||
continue;
|
||||
}
|
||||
|
||||
const thread = threadsById.get(binding.threadId);
|
||||
const thread = yield* projectionSnapshotQuery
|
||||
.getThreadShellById(binding.threadId)
|
||||
.pipe(Effect.map(Option.getOrUndefined));
|
||||
if (thread?.session?.activeTurnId != null) {
|
||||
yield* Effect.logDebug("provider.session.reaper.skipped-active-turn", {
|
||||
threadId: binding.threadId,
|
||||
|
||||
@@ -559,7 +559,6 @@ const buildAppUnderTest = (options?: {
|
||||
),
|
||||
Layer.provide(
|
||||
Layer.mock(OrchestrationEngineService)({
|
||||
getReadModel: () => Effect.succeed(makeDefaultOrchestrationReadModel()),
|
||||
readEvents: () => Stream.empty,
|
||||
dispatch: () => Effect.succeed({ sequence: 0 }),
|
||||
streamDomainEvents: Stream.empty,
|
||||
@@ -568,6 +567,7 @@ const buildAppUnderTest = (options?: {
|
||||
),
|
||||
Layer.provide(
|
||||
Layer.mock(ProjectionSnapshotQuery)({
|
||||
getCommandReadModel: () => Effect.succeed(makeDefaultOrchestrationReadModel()),
|
||||
getSnapshot: () => Effect.succeed(makeDefaultOrchestrationReadModel()),
|
||||
getShellSnapshot: () =>
|
||||
Effect.succeed({
|
||||
@@ -576,6 +576,7 @@ const buildAppUnderTest = (options?: {
|
||||
threads: [],
|
||||
updatedAt: new Date(0).toISOString(),
|
||||
}),
|
||||
getSnapshotSequence: () => Effect.succeed({ snapshotSequence: 0 }),
|
||||
getProjectShellById: () => Effect.succeed(Option.none()),
|
||||
getThreadShellById: () => Effect.succeed(Option.none()),
|
||||
getThreadDetailById: () => Effect.succeed(Option.none()),
|
||||
|
||||
@@ -77,8 +77,10 @@ it.effect("launchStartupHeartbeat does not block the caller while counts are loa
|
||||
|
||||
yield* launchStartupHeartbeat.pipe(
|
||||
Effect.provideService(ProjectionSnapshotQuery, {
|
||||
getCommandReadModel: () => Effect.die("unused"),
|
||||
getSnapshot: () => Effect.die("unused"),
|
||||
getShellSnapshot: () => Effect.die("unused"),
|
||||
getSnapshotSequence: () => Effect.die("unused"),
|
||||
getCounts: () =>
|
||||
Deferred.await(releaseCounts).pipe(
|
||||
Effect.as({
|
||||
@@ -129,8 +131,10 @@ it.effect("resolveAutoBootstrapWelcomeTargets returns existing project and threa
|
||||
autoBootstrapProjectFromCwd: true,
|
||||
} as never),
|
||||
Effect.provideService(ProjectionSnapshotQuery, {
|
||||
getCommandReadModel: () => Effect.die("unused"),
|
||||
getSnapshot: () => Effect.die("unused"),
|
||||
getShellSnapshot: () => Effect.die("unused"),
|
||||
getSnapshotSequence: () => Effect.die("unused"),
|
||||
getCounts: () => Effect.die("unused"),
|
||||
getActiveProjectByWorkspaceRoot: () =>
|
||||
Effect.succeed(
|
||||
@@ -152,7 +156,6 @@ it.effect("resolveAutoBootstrapWelcomeTargets returns existing project and threa
|
||||
getThreadDetailById: () => Effect.die("unused"),
|
||||
}),
|
||||
Effect.provideService(OrchestrationEngineService, {
|
||||
getReadModel: () => Effect.die("unused"),
|
||||
readEvents: () => Stream.empty,
|
||||
dispatch: (command) =>
|
||||
Ref.update(dispatchCalls, (calls) => [...calls, command.type]).pipe(
|
||||
@@ -180,8 +183,10 @@ it.effect("resolveAutoBootstrapWelcomeTargets creates a project and thread when
|
||||
autoBootstrapProjectFromCwd: true,
|
||||
} as never),
|
||||
Effect.provideService(ProjectionSnapshotQuery, {
|
||||
getCommandReadModel: () => Effect.die("unused"),
|
||||
getSnapshot: () => Effect.die("unused"),
|
||||
getShellSnapshot: () => Effect.die("unused"),
|
||||
getSnapshotSequence: () => Effect.die("unused"),
|
||||
getCounts: () => Effect.die("unused"),
|
||||
getActiveProjectByWorkspaceRoot: () => Effect.succeed(Option.none()),
|
||||
getProjectShellById: () => Effect.die("unused"),
|
||||
@@ -191,7 +196,6 @@ it.effect("resolveAutoBootstrapWelcomeTargets creates a project and thread when
|
||||
getThreadDetailById: () => Effect.die("unused"),
|
||||
}),
|
||||
Effect.provideService(OrchestrationEngineService, {
|
||||
getReadModel: () => Effect.die("unused"),
|
||||
readEvents: () => Stream.empty,
|
||||
dispatch: (command) =>
|
||||
Ref.update(dispatchCalls, (calls) => [...calls, command.type]).pipe(
|
||||
|
||||
@@ -287,7 +287,18 @@ it.effect("expands all-state pull request listing instead of relying on Bitbucke
|
||||
|
||||
it.effect("reads repository clone URLs and default branch", () => {
|
||||
const { layer } = makeLayer({
|
||||
response: () => Response.json(repositoryJson),
|
||||
response: (request) =>
|
||||
Response.json(
|
||||
request.url.endsWith("/branching-model")
|
||||
? {
|
||||
development: {
|
||||
branch: { name: "main" },
|
||||
name: "main",
|
||||
use_mainbranch: true,
|
||||
},
|
||||
}
|
||||
: repositoryJson,
|
||||
),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
@@ -307,6 +318,86 @@ it.effect("reads repository clone URLs and default branch", () => {
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
|
||||
it.effect(
|
||||
"prefers the Bitbucket branching model development branch as the default PR target",
|
||||
() => {
|
||||
const { execute, layer } = makeLayer({
|
||||
response: (request) =>
|
||||
Response.json(
|
||||
request.url.endsWith("/branching-model")
|
||||
? {
|
||||
development: {
|
||||
branch: { name: "develop" },
|
||||
name: "develop",
|
||||
use_mainbranch: false,
|
||||
},
|
||||
}
|
||||
: repositoryJson,
|
||||
),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const bitbucket = yield* BitbucketApi.BitbucketApi;
|
||||
const defaultBranch = yield* bitbucket.getDefaultBranch({ cwd: "/repo" });
|
||||
|
||||
assert.strictEqual(defaultBranch, "develop");
|
||||
assert.deepStrictEqual(
|
||||
execute.mock.calls.map((call) => call[0].url).toSorted(),
|
||||
[
|
||||
"https://api.test.local/2.0/repositories/pingdotgg/t3code",
|
||||
"https://api.test.local/2.0/repositories/pingdotgg/t3code/branching-model",
|
||||
].toSorted(),
|
||||
);
|
||||
}).pipe(Effect.provide(layer));
|
||||
},
|
||||
);
|
||||
|
||||
it.effect(
|
||||
"falls back to the repository main branch when the Bitbucket development branch is invalid",
|
||||
() => {
|
||||
const { layer } = makeLayer({
|
||||
response: (request) =>
|
||||
Response.json(
|
||||
request.url.endsWith("/branching-model")
|
||||
? {
|
||||
development: {
|
||||
name: "develop",
|
||||
use_mainbranch: false,
|
||||
is_valid: false,
|
||||
},
|
||||
}
|
||||
: repositoryJson,
|
||||
),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const bitbucket = yield* BitbucketApi.BitbucketApi;
|
||||
const defaultBranch = yield* bitbucket.getDefaultBranch({ cwd: "/repo" });
|
||||
|
||||
assert.strictEqual(defaultBranch, "main");
|
||||
}).pipe(Effect.provide(layer));
|
||||
},
|
||||
);
|
||||
|
||||
it.effect(
|
||||
"falls back to the repository main branch when the Bitbucket branching model is unavailable",
|
||||
() => {
|
||||
const { layer } = makeLayer({
|
||||
response: (request) =>
|
||||
request.url.endsWith("/branching-model")
|
||||
? Response.json({ error: { message: "Not found" } }, { status: 404 })
|
||||
: Response.json(repositoryJson),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const bitbucket = yield* BitbucketApi.BitbucketApi;
|
||||
const defaultBranch = yield* bitbucket.getDefaultBranch({ cwd: "/repo" });
|
||||
|
||||
assert.strictEqual(defaultBranch, "main");
|
||||
}).pipe(Effect.provide(layer));
|
||||
},
|
||||
);
|
||||
|
||||
it.effect("creates repositories through the Bitbucket REST API", () => {
|
||||
const { execute, layer } = makeLayer({
|
||||
response: () => Response.json(repositoryJson),
|
||||
|
||||
@@ -65,6 +65,23 @@ const RawBitbucketRepositorySchema = Schema.Struct({
|
||||
),
|
||||
});
|
||||
|
||||
const RawBitbucketBranchingModelSchema = Schema.Struct({
|
||||
development: Schema.optional(
|
||||
Schema.Struct({
|
||||
branch: Schema.optional(
|
||||
Schema.NullOr(
|
||||
Schema.Struct({
|
||||
name: Schema.optional(TrimmedNonEmptyString),
|
||||
}),
|
||||
),
|
||||
),
|
||||
is_valid: Schema.optional(Schema.Boolean),
|
||||
name: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
use_mainbranch: Schema.optional(Schema.Boolean),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
const BitbucketUserSchema = Schema.Struct({
|
||||
username: Schema.optional(TrimmedNonEmptyString),
|
||||
display_name: Schema.optional(TrimmedNonEmptyString),
|
||||
@@ -216,7 +233,7 @@ function parseBitbucketRemoteUrl(remoteUrl: string): BitbucketRepositoryLocator
|
||||
}
|
||||
|
||||
function normalizeRepositoryCloneUrls(
|
||||
raw: Schema.Schema.Type<typeof RawBitbucketRepositorySchema>,
|
||||
raw: typeof RawBitbucketRepositorySchema.Type,
|
||||
): SourceControlRepositoryCloneUrls {
|
||||
const httpClone =
|
||||
raw.links.clone?.find((entry) => entry.name.toLowerCase() === "https")?.href ??
|
||||
@@ -230,6 +247,24 @@ function normalizeRepositoryCloneUrls(
|
||||
};
|
||||
}
|
||||
|
||||
function defaultChangeRequestTargetBranch(input: {
|
||||
readonly repository: typeof RawBitbucketRepositorySchema.Type;
|
||||
readonly branchingModel: typeof RawBitbucketBranchingModelSchema.Type | null;
|
||||
}): string | null {
|
||||
const repositoryMainBranch = input.repository.mainbranch?.name ?? null;
|
||||
const development = input.branchingModel?.development;
|
||||
if (!development || development.use_mainbranch === true || development.is_valid === false) {
|
||||
return repositoryMainBranch;
|
||||
}
|
||||
|
||||
const developmentBranch = development.branch?.name?.trim() ?? development.name?.trim() ?? "";
|
||||
if (developmentBranch.length === 0 || developmentBranch === "null") {
|
||||
return repositoryMainBranch;
|
||||
}
|
||||
|
||||
return developmentBranch;
|
||||
}
|
||||
|
||||
function shouldPreferSshRemote(originRemoteUrl: string | null): boolean {
|
||||
const trimmed = originRemoteUrl?.trim() ?? "";
|
||||
return trimmed.startsWith("git@") || trimmed.startsWith("ssh://");
|
||||
@@ -430,23 +465,32 @@ export const make = Effect.fn("makeBitbucketApi")(function* () {
|
||||
});
|
||||
});
|
||||
|
||||
const getRepositoryFromLocator = (repository: BitbucketRepositoryLocator) =>
|
||||
executeJson(
|
||||
"getRepository",
|
||||
HttpClientRequest.get(
|
||||
apiUrl(
|
||||
`/repositories/${encodeURIComponent(repository.workspace)}/${encodeURIComponent(repository.repoSlug)}`,
|
||||
),
|
||||
),
|
||||
RawBitbucketRepositorySchema,
|
||||
);
|
||||
|
||||
const getRepository = (input: {
|
||||
readonly cwd: string;
|
||||
readonly context?: SourceControlProvider.SourceControlProviderContext;
|
||||
readonly repository?: string;
|
||||
}) =>
|
||||
resolveRepository(input).pipe(
|
||||
Effect.flatMap((repository) =>
|
||||
executeJson(
|
||||
"getRepository",
|
||||
HttpClientRequest.get(
|
||||
apiUrl(
|
||||
`/repositories/${encodeURIComponent(repository.workspace)}/${encodeURIComponent(repository.repoSlug)}`,
|
||||
),
|
||||
),
|
||||
RawBitbucketRepositorySchema,
|
||||
}) => resolveRepository(input).pipe(Effect.flatMap(getRepositoryFromLocator));
|
||||
|
||||
const getBranchingModelFromLocator = (repository: BitbucketRepositoryLocator) =>
|
||||
executeJson(
|
||||
"getBranchingModel",
|
||||
HttpClientRequest.get(
|
||||
apiUrl(
|
||||
`/repositories/${encodeURIComponent(repository.workspace)}/${encodeURIComponent(repository.repoSlug)}/branching-model`,
|
||||
),
|
||||
),
|
||||
RawBitbucketBranchingModelSchema,
|
||||
);
|
||||
|
||||
const getRawPullRequestFromRepository = (
|
||||
@@ -628,7 +672,22 @@ export const make = Effect.fn("makeBitbucketApi")(function* () {
|
||||
);
|
||||
}),
|
||||
getDefaultBranch: (input) =>
|
||||
getRepository(input).pipe(Effect.map((repository) => repository.mainbranch?.name ?? null)),
|
||||
resolveRepository(input).pipe(
|
||||
Effect.flatMap((locator) =>
|
||||
Effect.all(
|
||||
{
|
||||
repository: getRepositoryFromLocator(locator),
|
||||
branchingModel: getBranchingModelFromLocator(locator).pipe(
|
||||
Effect.catch(() =>
|
||||
Effect.succeed<typeof RawBitbucketBranchingModelSchema.Type | null>(null),
|
||||
),
|
||||
),
|
||||
},
|
||||
{ concurrency: "unbounded" },
|
||||
),
|
||||
),
|
||||
Effect.map(defaultChangeRequestTargetBranch),
|
||||
),
|
||||
// Bitbucket Cloud pull requests are Git-backed and Bitbucket does not provide
|
||||
// an official checkout CLI. This provider-local path uses GitVcsDriver as a
|
||||
// narrow escape hatch to materialize Bitbucket PR refs. Do not generalize this
|
||||
|
||||
+18
-7
@@ -236,9 +236,13 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
|
||||
return Effect.gen(function* () {
|
||||
const workspaceRoot =
|
||||
event.payload.workspaceRoot ??
|
||||
(yield* orchestrationEngine.getReadModel()).projects.find(
|
||||
(project) => project.id === event.payload.projectId,
|
||||
)?.workspaceRoot ??
|
||||
Option.match(
|
||||
yield* projectionSnapshotQuery.getProjectShellById(event.payload.projectId),
|
||||
{
|
||||
onNone: () => null,
|
||||
onSome: (project) => project.workspaceRoot,
|
||||
},
|
||||
) ??
|
||||
null;
|
||||
if (workspaceRoot === null) {
|
||||
return event;
|
||||
@@ -252,7 +256,7 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
|
||||
repositoryIdentity,
|
||||
},
|
||||
} satisfies OrchestrationEvent;
|
||||
});
|
||||
}).pipe(Effect.catch(() => Effect.succeed(event)));
|
||||
default:
|
||||
return Effect.succeed(event);
|
||||
}
|
||||
@@ -723,9 +727,16 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
|
||||
}),
|
||||
),
|
||||
),
|
||||
orchestrationEngine
|
||||
.getReadModel()
|
||||
.pipe(Effect.map((readModel) => readModel.snapshotSequence)),
|
||||
projectionSnapshotQuery.getSnapshotSequence().pipe(
|
||||
Effect.map(({ snapshotSequence }) => snapshotSequence),
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new OrchestrationGetSnapshotError({
|
||||
message: "Failed to load orchestration snapshot sequence",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
),
|
||||
]);
|
||||
|
||||
if (Option.isNone(threadDetail)) {
|
||||
|
||||
@@ -25,6 +25,20 @@
|
||||
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
const isDark = theme === "dark" || (theme === "system" && prefersDark);
|
||||
document.documentElement.classList.toggle("dark", isDark);
|
||||
const rawSettings = window.localStorage.getItem("t3code:client-settings:v1");
|
||||
const palette = rawSettings ? JSON.parse(rawSettings).themePalette : null;
|
||||
if (palette && /^#[0-9a-fA-F]{6}$/.test(palette.primaryColor)) {
|
||||
document.documentElement.style.setProperty(
|
||||
"--theme-primary-seed",
|
||||
palette.primaryColor.toLowerCase(),
|
||||
);
|
||||
}
|
||||
if (palette && /^#[0-9a-fA-F]{6}$/.test(palette.neutralColor)) {
|
||||
document.documentElement.style.setProperty(
|
||||
"--theme-neutral-seed",
|
||||
palette.neutralColor.toLowerCase(),
|
||||
);
|
||||
}
|
||||
const chromeColor = isDark ? DARK_BACKGROUND : LIGHT_BACKGROUND;
|
||||
document.documentElement.style.backgroundColor = chromeColor;
|
||||
themeColorMeta?.setAttribute("content", chromeColor);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
{
|
||||
"name": "@t3tools/web",
|
||||
"version": "0.0.21",
|
||||
"version": "0.0.22",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"prepare": "effect-language-service patch",
|
||||
"preview": "vite preview",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run --passWithNoTests",
|
||||
@@ -23,7 +22,7 @@
|
||||
"@formkit/auto-animate": "^0.9.0",
|
||||
"@legendapp/list": "3.0.0-beta.44",
|
||||
"@lexical/react": "^0.41.0",
|
||||
"@pierre/diffs": "^1.1.0-beta.16",
|
||||
"@pierre/diffs": "catalog:",
|
||||
"@t3tools/client-runtime": "workspace:*",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { EnvironmentId, type PersistedSavedEnvironmentRecord } from "@t3tools/contracts";
|
||||
import {
|
||||
DEFAULT_CLIENT_SETTINGS,
|
||||
DEFAULT_THEME_PALETTE,
|
||||
EnvironmentId,
|
||||
type PersistedSavedEnvironmentRecord,
|
||||
} from "@t3tools/contracts";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const testEnvironmentId = EnvironmentId.make("environment-1");
|
||||
@@ -55,6 +60,46 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("clientPersistenceStorage", () => {
|
||||
it("reads the persisted theme palette for boot-time theme application", async () => {
|
||||
const testWindow = getTestWindow();
|
||||
const { CLIENT_SETTINGS_STORAGE_KEY, readBootThemePalette } =
|
||||
await import("./clientPersistenceStorage");
|
||||
|
||||
testWindow.localStorage.setItem(
|
||||
CLIENT_SETTINGS_STORAGE_KEY,
|
||||
JSON.stringify({
|
||||
...DEFAULT_CLIENT_SETTINGS,
|
||||
themePalette: {
|
||||
primaryColor: "#db2777",
|
||||
neutralColor: "#0f172a",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(readBootThemePalette()).toEqual({
|
||||
primaryColor: "#db2777",
|
||||
neutralColor: "#0f172a",
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to the default theme palette when persisted data is invalid", async () => {
|
||||
const testWindow = getTestWindow();
|
||||
const { CLIENT_SETTINGS_STORAGE_KEY, readBootThemePalette } =
|
||||
await import("./clientPersistenceStorage");
|
||||
|
||||
testWindow.localStorage.setItem(
|
||||
CLIENT_SETTINGS_STORAGE_KEY,
|
||||
JSON.stringify({
|
||||
themePalette: {
|
||||
primaryColor: "pink",
|
||||
neutralColor: "#0f172a",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(readBootThemePalette()).toEqual(DEFAULT_THEME_PALETTE);
|
||||
});
|
||||
|
||||
it("stores browser secrets inline with the saved environment record", async () => {
|
||||
const testWindow = getTestWindow();
|
||||
const {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
ClientSettingsSchema,
|
||||
DEFAULT_THEME_PALETTE,
|
||||
EnvironmentId,
|
||||
type ClientSettings,
|
||||
type EnvironmentId as EnvironmentIdValue,
|
||||
@@ -12,6 +13,19 @@ import { getLocalStorageItem, setLocalStorageItem } from "./hooks/useLocalStorag
|
||||
export const CLIENT_SETTINGS_STORAGE_KEY = "t3code:client-settings:v1";
|
||||
export const SAVED_ENVIRONMENT_REGISTRY_STORAGE_KEY = "t3code:saved-environment-registry:v1";
|
||||
|
||||
export function readBootThemePalette(): ClientSettings["themePalette"] {
|
||||
if (!hasWindow()) {
|
||||
return DEFAULT_THEME_PALETTE;
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = getLocalStorageItem(CLIENT_SETTINGS_STORAGE_KEY, ClientSettingsSchema);
|
||||
return parsed?.themePalette ?? DEFAULT_THEME_PALETTE;
|
||||
} catch {
|
||||
return DEFAULT_THEME_PALETTE;
|
||||
}
|
||||
}
|
||||
|
||||
const BrowserSavedEnvironmentRecordSchema = Schema.Struct({
|
||||
environmentId: EnvironmentId,
|
||||
label: Schema.String,
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
"use client";
|
||||
|
||||
import { type ReactNode, useLayoutEffect, useRef, useState } from "react";
|
||||
import { type ReactNode, useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
|
||||
const HEIGHT_TRANSITION_FALLBACK_MS = 250;
|
||||
|
||||
export function AnimatedHeight({ children }: { readonly children: ReactNode }) {
|
||||
const contentRef = useRef<HTMLDivElement>(null);
|
||||
const [height, setHeight] = useState<number | null>(null);
|
||||
const [heightState, setHeightState] = useState<{
|
||||
readonly height: number | null;
|
||||
readonly isClipping: boolean;
|
||||
}>({ height: null, isClipping: false });
|
||||
|
||||
useEffect(() => {
|
||||
if (!heightState.isClipping) return;
|
||||
const timeoutId = window.setTimeout(() => {
|
||||
setHeightState((currentState) =>
|
||||
currentState.isClipping ? { ...currentState, isClipping: false } : currentState,
|
||||
);
|
||||
}, HEIGHT_TRANSITION_FALLBACK_MS);
|
||||
return () => window.clearTimeout(timeoutId);
|
||||
}, [heightState.height, heightState.isClipping]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const element = contentRef.current;
|
||||
@@ -14,7 +29,13 @@ export function AnimatedHeight({ children }: { readonly children: ReactNode }) {
|
||||
|
||||
const updateHeight = () => {
|
||||
const nextHeight = Math.ceil(element.scrollHeight || element.getBoundingClientRect().height);
|
||||
setHeight((currentHeight) => (currentHeight === nextHeight ? currentHeight : nextHeight));
|
||||
setHeightState((currentState) => {
|
||||
if (currentState.height === nextHeight) return currentState;
|
||||
return {
|
||||
height: nextHeight,
|
||||
isClipping: currentState.height !== null,
|
||||
};
|
||||
});
|
||||
};
|
||||
const cancelPendingFrames = () => {
|
||||
if (firstFrameId !== null) {
|
||||
@@ -50,8 +71,19 @@ export function AnimatedHeight({ children }: { readonly children: ReactNode }) {
|
||||
|
||||
return (
|
||||
<div
|
||||
className="overflow-hidden transition-[height] duration-200 ease-out motion-reduce:transition-none"
|
||||
style={height === null ? undefined : { height }}
|
||||
data-slot="animated-height"
|
||||
className="transition-[height] duration-200 ease-out motion-reduce:transition-none"
|
||||
style={
|
||||
heightState.height === null
|
||||
? undefined
|
||||
: { height: heightState.height, overflow: heightState.isClipping ? "hidden" : "visible" }
|
||||
}
|
||||
onTransitionEnd={(event) => {
|
||||
if (event.target !== event.currentTarget || event.propertyName !== "height") return;
|
||||
setHeightState((currentState) =>
|
||||
currentState.isClipping ? { ...currentState, isClipping: false } : currentState,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<div ref={contentRef}>{children}</div>
|
||||
</div>
|
||||
|
||||
@@ -211,6 +211,32 @@ function SuspenseShikiCodeBlock({
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<UncachedShikiCodeBlock
|
||||
code={code}
|
||||
language={language}
|
||||
themeName={themeName}
|
||||
cacheKey={cacheKey}
|
||||
isStreaming={isStreaming}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
interface UncachedShikiCodeBlockProps {
|
||||
code: string;
|
||||
language: string;
|
||||
themeName: DiffThemeName;
|
||||
cacheKey: string;
|
||||
isStreaming: boolean;
|
||||
}
|
||||
|
||||
function UncachedShikiCodeBlock({
|
||||
code,
|
||||
language,
|
||||
themeName,
|
||||
cacheKey,
|
||||
isStreaming,
|
||||
}: UncachedShikiCodeBlockProps) {
|
||||
const highlighter = use(getHighlighterPromise(language));
|
||||
const highlightedHtml = useMemo(() => {
|
||||
try {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useNavigate, useParams, useSearch } from "@tanstack/react-router";
|
||||
import { scopeThreadRef } from "@t3tools/client-runtime";
|
||||
import type { TurnId } from "@t3tools/contracts";
|
||||
import {
|
||||
ChevronDownIcon,
|
||||
ChevronLeftIcon,
|
||||
ChevronRightIcon,
|
||||
Columns2Icon,
|
||||
@@ -161,6 +162,21 @@ function buildFileDiffRenderKey(fileDiff: FileDiffMetadata): string {
|
||||
return fileDiff.cacheKey ?? `${fileDiff.prevName ?? "none"}:${fileDiff.name}`;
|
||||
}
|
||||
|
||||
function getDiffCollapseIconClassName(fileDiff: FileDiffMetadata): string {
|
||||
switch (fileDiff.type) {
|
||||
case "new":
|
||||
return "text-[var(--diffs-addition-base)]";
|
||||
case "deleted":
|
||||
return "text-[var(--diffs-deletion-base)]";
|
||||
case "change":
|
||||
case "rename-pure":
|
||||
case "rename-changed":
|
||||
return "text-[var(--diffs-modified-base)]";
|
||||
default:
|
||||
return "text-muted-foreground/80";
|
||||
}
|
||||
}
|
||||
|
||||
interface DiffPanelProps {
|
||||
mode?: DiffPanelMode;
|
||||
}
|
||||
@@ -174,6 +190,9 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
||||
const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
|
||||
const [diffWordWrap, setDiffWordWrap] = useState(settings.diffWordWrap);
|
||||
const [diffIgnoreWhitespace, setDiffIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);
|
||||
const [collapsedDiffFileKeys, setCollapsedDiffFileKeys] = useState<ReadonlySet<string>>(
|
||||
() => new Set(),
|
||||
);
|
||||
const patchViewportRef = useRef<HTMLDivElement>(null);
|
||||
const turnStripRef = useRef<HTMLDivElement>(null);
|
||||
const previousDiffOpenRef = useRef(false);
|
||||
@@ -317,6 +336,19 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
||||
);
|
||||
}, [renderablePatch]);
|
||||
|
||||
useEffect(() => {
|
||||
if (renderableFiles.length === 0) {
|
||||
setCollapsedDiffFileKeys((current) => (current.size === 0 ? current : new Set()));
|
||||
return;
|
||||
}
|
||||
|
||||
const visibleFileKeys = new Set(renderableFiles.map(buildFileDiffRenderKey));
|
||||
setCollapsedDiffFileKeys((current) => {
|
||||
const next = new Set([...current].filter((fileKey) => visibleFileKeys.has(fileKey)));
|
||||
return next.size === current.size ? current : next;
|
||||
});
|
||||
}, [renderableFiles]);
|
||||
|
||||
useEffect(() => {
|
||||
if (diffOpen && !previousDiffOpenRef.current) {
|
||||
setDiffWordWrap(settings.diffWordWrap);
|
||||
@@ -346,6 +378,17 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
||||
},
|
||||
[activeCwd],
|
||||
);
|
||||
const toggleDiffFileCollapsed = useCallback((fileKey: string) => {
|
||||
setCollapsedDiffFileKeys((current) => {
|
||||
const next = new Set(current);
|
||||
if (next.has(fileKey)) {
|
||||
next.delete(fileKey);
|
||||
} else {
|
||||
next.add(fileKey);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const selectTurn = (turnId: TurnId) => {
|
||||
if (!activeThread) return;
|
||||
@@ -620,11 +663,12 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
||||
const filePath = resolveFileDiffPath(fileDiff);
|
||||
const fileKey = buildFileDiffRenderKey(fileDiff);
|
||||
const themedFileKey = `${fileKey}:${resolvedTheme}`;
|
||||
const collapsed = collapsedDiffFileKeys.has(fileKey);
|
||||
return (
|
||||
<div
|
||||
key={themedFileKey}
|
||||
data-diff-file-path={filePath}
|
||||
className="diff-render-file mb-2 rounded-md first:mt-2 last:mb-0"
|
||||
className="diff-render-file group/diff-file mb-2 rounded-md first:mt-2 last:mb-0"
|
||||
onClickCapture={(event) => {
|
||||
const nativeEvent = event.nativeEvent as MouseEvent;
|
||||
const composedPath = nativeEvent.composedPath?.() ?? [];
|
||||
@@ -638,7 +682,30 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
|
||||
>
|
||||
<FileDiff
|
||||
fileDiff={fileDiff}
|
||||
renderHeaderPrefix={() => (
|
||||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
"inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent p-0 transition-colors hover:bg-foreground/10 focus-visible:outline-hidden",
|
||||
getDiffCollapseIconClassName(fileDiff),
|
||||
)}
|
||||
aria-label={collapsed ? `Expand ${filePath}` : `Collapse ${filePath}`}
|
||||
aria-expanded={!collapsed}
|
||||
title={collapsed ? "Expand diff" : "Collapse diff"}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
toggleDiffFileCollapsed(fileKey);
|
||||
}}
|
||||
>
|
||||
{collapsed ? (
|
||||
<ChevronRightIcon className="size-4" />
|
||||
) : (
|
||||
<ChevronDownIcon className="size-4" />
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
options={{
|
||||
collapsed,
|
||||
diffStyle: diffRenderMode === "split" ? "split" : "unified",
|
||||
lineDiffType: "none",
|
||||
overflow: diffWordWrap ? "wrap" : "scroll",
|
||||
|
||||
@@ -87,6 +87,8 @@ interface TimelineRowSharedState {
|
||||
}
|
||||
|
||||
const TimelineRowCtx = createContext<TimelineRowSharedState>(null!);
|
||||
const TIMELINE_LIST_HEADER = <div className="h-3 sm:h-4" />;
|
||||
const TIMELINE_LIST_FOOTER = <div className="h-3 sm:h-4" />;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Props (public API)
|
||||
@@ -261,8 +263,8 @@ export const MessagesTimeline = memo(function MessagesTimeline({
|
||||
maintainVisibleContentPosition
|
||||
onScroll={handleScroll}
|
||||
className="h-full overflow-x-hidden overscroll-y-contain px-3 sm:px-5"
|
||||
ListHeaderComponent={<div className="h-3 sm:h-4" />}
|
||||
ListFooterComponent={<div className="h-3 sm:h-4" />}
|
||||
ListHeaderComponent={TIMELINE_LIST_HEADER}
|
||||
ListFooterComponent={TIMELINE_LIST_FOOTER}
|
||||
/>
|
||||
</TimelineRowCtx.Provider>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ArchiveIcon, ArchiveX, LoaderIcon, PlusIcon, RefreshCwIcon } from "lucide-react";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useCallback, useMemo, useRef, useState } from "react";
|
||||
import { type CSSProperties, useCallback, useMemo, useRef, useState } from "react";
|
||||
import {
|
||||
defaultInstanceIdForDriver,
|
||||
type DesktopUpdateChannel,
|
||||
@@ -10,7 +10,11 @@ import {
|
||||
type ScopedThreadRef,
|
||||
} from "@t3tools/contracts";
|
||||
import { scopeThreadRef } from "@t3tools/client-runtime";
|
||||
import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
|
||||
import {
|
||||
DEFAULT_THEME_PALETTE,
|
||||
DEFAULT_UNIFIED_SETTINGS,
|
||||
type ThemePaletteSettings,
|
||||
} from "@t3tools/contracts/settings";
|
||||
import { createModelSelection } from "@t3tools/shared/model";
|
||||
import { Equal } from "effect";
|
||||
import { APP_VERSION } from "../../branding";
|
||||
@@ -40,7 +44,14 @@ import {
|
||||
deriveProviderInstanceEntries,
|
||||
sortProviderInstanceEntries,
|
||||
} from "../../providerInstances";
|
||||
import {
|
||||
getThemePaletteCustomProperties,
|
||||
normalizeThemePaletteColor,
|
||||
THEME_PALETTE_PREVIEW_SWATCHES,
|
||||
THEME_PALETTE_SWATCHES,
|
||||
} from "../../themePalette";
|
||||
import { ensureLocalApi, readLocalApi } from "../../localApi";
|
||||
import { cn } from "../../lib/utils";
|
||||
import { useShallow } from "zustand/react/shallow";
|
||||
import {
|
||||
selectProjectsAcrossEnvironments,
|
||||
@@ -117,6 +128,91 @@ const PROVIDER_SETTINGS = DRIVER_OPTIONS.map((definition) => ({
|
||||
provider: definition.value,
|
||||
}));
|
||||
|
||||
function ThemePaletteColorControl({
|
||||
label,
|
||||
value,
|
||||
fallbackColor,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
fallbackColor: string;
|
||||
onChange: (value: string) => void;
|
||||
}) {
|
||||
const normalizedValue = normalizeThemePaletteColor(value) ?? fallbackColor;
|
||||
|
||||
return (
|
||||
<div className="grid min-w-0 gap-2">
|
||||
<span className="text-xs font-medium text-foreground">{label}</span>
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={normalizedValue}
|
||||
onChange={(event) => onChange(event.target.value)}
|
||||
aria-label={`${label} theme color`}
|
||||
className="h-8 w-10 cursor-pointer rounded-xl border border-input bg-background p-0.5"
|
||||
/>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{THEME_PALETTE_SWATCHES.map((swatch) => {
|
||||
const selected = normalizedValue === swatch;
|
||||
return (
|
||||
<button
|
||||
key={swatch}
|
||||
type="button"
|
||||
className={cn(
|
||||
"size-6 cursor-pointer rounded-full border transition",
|
||||
selected
|
||||
? "scale-110 border-foreground ring-2 ring-ring ring-offset-1 ring-offset-background"
|
||||
: "border-black/10 hover:scale-105 dark:border-white/20",
|
||||
)}
|
||||
style={{ backgroundColor: swatch }}
|
||||
onClick={() => onChange(swatch)}
|
||||
aria-label={`Use ${swatch} ${label.toLowerCase()} theme color`}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ThemePalettePreview({ palette }: { palette: ThemePaletteSettings }) {
|
||||
const previewStyle = getThemePaletteCustomProperties(palette) as CSSProperties;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="mt-4 rounded-xl border bg-background p-3 text-foreground"
|
||||
style={previewStyle}
|
||||
aria-label="Generated theme palette preview"
|
||||
>
|
||||
<div className="grid gap-2 sm:grid-cols-4">
|
||||
{THEME_PALETTE_PREVIEW_SWATCHES.map((swatch) => (
|
||||
<div key={swatch.variable} className="grid gap-1.5">
|
||||
<span
|
||||
className="h-9 rounded-lg border border-border shadow-xs"
|
||||
style={{ backgroundColor: `var(${swatch.variable})` }}
|
||||
aria-hidden
|
||||
/>
|
||||
<span className="text-[11px] text-muted-foreground">{swatch.label}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-3 flex flex-wrap items-center gap-2">
|
||||
<span className="rounded-full bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground">
|
||||
Primary
|
||||
</span>
|
||||
<span className="rounded-full bg-accent px-2.5 py-1 text-xs font-medium text-accent-foreground">
|
||||
Accent
|
||||
</span>
|
||||
<span className="rounded-full bg-muted px-2.5 py-1 text-xs font-medium text-muted-foreground">
|
||||
Muted
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ProviderLastChecked({ lastCheckedAt }: { lastCheckedAt: string | null }) {
|
||||
useRelativeTimeTick();
|
||||
const lastCheckedRelative = lastCheckedAt ? formatRelativeTime(lastCheckedAt) : null;
|
||||
@@ -347,6 +443,10 @@ export function useSettingsRestore(onRestored?: () => void) {
|
||||
const settings = useSettings();
|
||||
const { resetSettings } = useUpdateSettings();
|
||||
|
||||
const themePaletteDirty = !Equal.equals(
|
||||
settings.themePalette,
|
||||
DEFAULT_UNIFIED_SETTINGS.themePalette,
|
||||
);
|
||||
const isGitWritingModelDirty = !Equal.equals(
|
||||
settings.textGenerationModelSelection ?? null,
|
||||
DEFAULT_UNIFIED_SETTINGS.textGenerationModelSelection ?? null,
|
||||
@@ -380,6 +480,7 @@ export function useSettingsRestore(onRestored?: () => void) {
|
||||
const changedSettingLabels = useMemo(
|
||||
() => [
|
||||
...(theme !== "system" ? ["Theme"] : []),
|
||||
...(themePaletteDirty ? ["Theme colors"] : []),
|
||||
...(settings.timestampFormat !== DEFAULT_UNIFIED_SETTINGS.timestampFormat
|
||||
? ["Time format"]
|
||||
: []),
|
||||
@@ -413,6 +514,7 @@ export function useSettingsRestore(onRestored?: () => void) {
|
||||
[
|
||||
areProviderSettingsDirty,
|
||||
isGitWritingModelDirty,
|
||||
themePaletteDirty,
|
||||
settings.autoOpenPlanSidebar,
|
||||
settings.confirmThreadArchive,
|
||||
settings.confirmThreadDelete,
|
||||
@@ -827,6 +929,53 @@ export function GeneralSettingsPanel() {
|
||||
}
|
||||
/>
|
||||
|
||||
<SettingsRow
|
||||
title="Theme colors"
|
||||
description="Choose brand and surface colors. T3 Code generates the palette from them."
|
||||
resetAction={
|
||||
!Equal.equals(settings.themePalette, DEFAULT_UNIFIED_SETTINGS.themePalette) ? (
|
||||
<SettingResetButton
|
||||
label="theme colors"
|
||||
onClick={() =>
|
||||
updateSettings({
|
||||
themePalette: DEFAULT_UNIFIED_SETTINGS.themePalette,
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
>
|
||||
<div className="mt-4 grid gap-4 sm:grid-cols-2">
|
||||
<ThemePaletteColorControl
|
||||
label="Primary color"
|
||||
value={settings.themePalette.primaryColor}
|
||||
fallbackColor={DEFAULT_THEME_PALETTE.primaryColor}
|
||||
onChange={(primaryColor) =>
|
||||
updateSettings({
|
||||
themePalette: {
|
||||
...settings.themePalette,
|
||||
primaryColor,
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
<ThemePaletteColorControl
|
||||
label="Neutral color"
|
||||
value={settings.themePalette.neutralColor}
|
||||
fallbackColor={DEFAULT_THEME_PALETTE.neutralColor}
|
||||
onChange={(neutralColor) =>
|
||||
updateSettings({
|
||||
themePalette: {
|
||||
...settings.themePalette,
|
||||
neutralColor,
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<ThemePalettePreview palette={settings.themePalette} />
|
||||
</SettingsRow>
|
||||
|
||||
<SettingsRow
|
||||
title="Time format"
|
||||
description="System default follows your browser or OS clock preference."
|
||||
|
||||
@@ -22,14 +22,14 @@ function createTestClient() {
|
||||
environmentId: EnvironmentId.make("env-1"),
|
||||
},
|
||||
})),
|
||||
subscribeConfig: (listener: (event: any) => void) => {
|
||||
subscribeConfig: vi.fn((listener: (event: any) => void) => {
|
||||
configListeners.add(listener);
|
||||
return () => configListeners.delete(listener);
|
||||
},
|
||||
subscribeLifecycle: (listener: (event: any) => void) => {
|
||||
}),
|
||||
subscribeLifecycle: vi.fn((listener: (event: any) => void) => {
|
||||
lifecycleListeners.add(listener);
|
||||
return () => lifecycleListeners.delete(listener);
|
||||
},
|
||||
}),
|
||||
subscribeAuthAccess: () => () => undefined,
|
||||
refreshProviders: vi.fn(async () => undefined),
|
||||
upsertKeybinding: vi.fn(async () => undefined),
|
||||
@@ -237,4 +237,33 @@ describe("createEnvironmentConnection", () => {
|
||||
|
||||
await connection.dispose();
|
||||
});
|
||||
|
||||
it("skips primary lifecycle/config subscriptions when no handlers are registered", async () => {
|
||||
const environmentId = EnvironmentId.make("env-1");
|
||||
const { client } = createTestClient();
|
||||
|
||||
const connection = createEnvironmentConnection({
|
||||
kind: "primary",
|
||||
knownEnvironment: {
|
||||
id: "env-1",
|
||||
label: "Local env",
|
||||
source: "manual",
|
||||
target: {
|
||||
httpBaseUrl: "http://example.test",
|
||||
wsBaseUrl: "ws://example.test",
|
||||
},
|
||||
environmentId,
|
||||
},
|
||||
client,
|
||||
applyShellEvent: vi.fn(),
|
||||
syncShellSnapshot: vi.fn(),
|
||||
applyTerminalEvent: vi.fn(),
|
||||
});
|
||||
|
||||
expect(client.server.subscribeLifecycle).not.toHaveBeenCalled();
|
||||
expect(client.server.subscribeConfig).not.toHaveBeenCalled();
|
||||
expect(client.orchestration.subscribeShell).toHaveBeenCalledOnce();
|
||||
|
||||
await connection.dispose();
|
||||
});
|
||||
});
|
||||
@@ -83,6 +83,8 @@ export function createEnvironmentConnection(
|
||||
|
||||
let disposed = false;
|
||||
const bootstrapGate = createBootstrapGate();
|
||||
const shouldObserveLifecycle = input.kind === "saved" || input.onWelcome !== undefined;
|
||||
const shouldObserveConfig = input.kind === "saved" || input.onConfigSnapshot !== undefined;
|
||||
|
||||
const observeEnvironmentIdentity = (nextEnvironmentId: EnvironmentId, source: string) => {
|
||||
if (environmentId !== nextEnvironmentId) {
|
||||
@@ -92,28 +94,35 @@ export function createEnvironmentConnection(
|
||||
}
|
||||
};
|
||||
|
||||
const unsubLifecycle = input.client.server.subscribeLifecycle(
|
||||
(event: Parameters<Parameters<WsRpcClient["server"]["subscribeLifecycle"]>[0]>[0]) => {
|
||||
if (event.type !== "welcome") {
|
||||
return;
|
||||
}
|
||||
observeEnvironmentIdentity(
|
||||
event.payload.environment.environmentId,
|
||||
"server lifecycle welcome",
|
||||
);
|
||||
input.onWelcome?.(event.payload);
|
||||
},
|
||||
);
|
||||
const unsubLifecycle = shouldObserveLifecycle
|
||||
? input.client.server.subscribeLifecycle(
|
||||
(event: Parameters<Parameters<WsRpcClient["server"]["subscribeLifecycle"]>[0]>[0]) => {
|
||||
if (event.type !== "welcome") {
|
||||
return;
|
||||
}
|
||||
observeEnvironmentIdentity(
|
||||
event.payload.environment.environmentId,
|
||||
"server lifecycle welcome",
|
||||
);
|
||||
input.onWelcome?.(event.payload);
|
||||
},
|
||||
)
|
||||
: () => undefined;
|
||||
|
||||
const unsubConfig = input.client.server.subscribeConfig(
|
||||
(event: Parameters<Parameters<WsRpcClient["server"]["subscribeConfig"]>[0]>[0]) => {
|
||||
if (event.type !== "snapshot") {
|
||||
return;
|
||||
}
|
||||
observeEnvironmentIdentity(event.config.environment.environmentId, "server config snapshot");
|
||||
input.onConfigSnapshot?.(event.config);
|
||||
},
|
||||
);
|
||||
const unsubConfig = shouldObserveConfig
|
||||
? input.client.server.subscribeConfig(
|
||||
(event: Parameters<Parameters<WsRpcClient["server"]["subscribeConfig"]>[0]>[0]) => {
|
||||
if (event.type !== "snapshot") {
|
||||
return;
|
||||
}
|
||||
observeEnvironmentIdentity(
|
||||
event.config.environment.environmentId,
|
||||
"server config snapshot",
|
||||
);
|
||||
input.onConfigSnapshot?.(event.config);
|
||||
},
|
||||
)
|
||||
: () => undefined;
|
||||
|
||||
const unsubShell = input.client.orchestration.subscribeShell(
|
||||
(item: Parameters<Parameters<WsRpcClient["orchestration"]["subscribeShell"]>[0]>[0]) => {
|
||||
|
||||
@@ -0,0 +1,326 @@
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import { EnvironmentId } from "@t3tools/contracts";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mockCreateEnvironmentConnection = vi.fn();
|
||||
const mockCreateWsRpcClient = vi.fn();
|
||||
const mockFetchRemoteSessionState = vi.fn();
|
||||
const mockWaitForSavedEnvironmentRegistryHydration = vi.fn();
|
||||
const mockListSavedEnvironmentRecords = vi.fn();
|
||||
const mockSavedEnvironmentRegistrySubscribe = vi.fn();
|
||||
const mockReadSavedEnvironmentBearerToken = vi.fn();
|
||||
const mockGetSavedEnvironmentRecord = vi.fn();
|
||||
|
||||
function MockWsTransport() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
vi.mock("../primary", () => ({
|
||||
getPrimaryKnownEnvironment: vi.fn(() => ({
|
||||
id: "env-1",
|
||||
label: "Primary environment",
|
||||
source: "window-origin",
|
||||
target: {
|
||||
httpBaseUrl: "http://127.0.0.1:3000/",
|
||||
wsBaseUrl: "ws://127.0.0.1:3000/",
|
||||
},
|
||||
environmentId: EnvironmentId.make("env-1"),
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("../remote/api", () => ({
|
||||
bootstrapRemoteBearerSession: vi.fn(),
|
||||
fetchRemoteEnvironmentDescriptor: vi.fn(),
|
||||
fetchRemoteSessionState: mockFetchRemoteSessionState,
|
||||
resolveRemoteWebSocketConnectionUrl: vi.fn(() => "ws://remote.example.test"),
|
||||
}));
|
||||
|
||||
vi.mock("./catalog", () => ({
|
||||
getSavedEnvironmentRecord: mockGetSavedEnvironmentRecord,
|
||||
hasSavedEnvironmentRegistryHydrated: vi.fn(() => true),
|
||||
listSavedEnvironmentRecords: mockListSavedEnvironmentRecords,
|
||||
persistSavedEnvironmentRecord: vi.fn(),
|
||||
readSavedEnvironmentBearerToken: mockReadSavedEnvironmentBearerToken,
|
||||
removeSavedEnvironmentBearerToken: vi.fn(),
|
||||
useSavedEnvironmentRegistryStore: {
|
||||
subscribe: mockSavedEnvironmentRegistrySubscribe,
|
||||
getState: () => ({
|
||||
upsert: vi.fn(),
|
||||
remove: vi.fn(),
|
||||
markConnected: vi.fn(),
|
||||
rename: vi.fn(),
|
||||
}),
|
||||
},
|
||||
useSavedEnvironmentRuntimeStore: {
|
||||
getState: () => ({
|
||||
ensure: vi.fn(),
|
||||
patch: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
}),
|
||||
},
|
||||
waitForSavedEnvironmentRegistryHydration: mockWaitForSavedEnvironmentRegistryHydration,
|
||||
writeSavedEnvironmentBearerToken: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./connection", () => ({
|
||||
createEnvironmentConnection: mockCreateEnvironmentConnection,
|
||||
}));
|
||||
|
||||
vi.mock("../../rpc/wsRpcClient", () => ({
|
||||
createWsRpcClient: mockCreateWsRpcClient,
|
||||
}));
|
||||
|
||||
vi.mock("../../rpc/wsTransport", () => ({
|
||||
WsTransport: MockWsTransport,
|
||||
}));
|
||||
|
||||
vi.mock("~/composerDraftStore", () => ({
|
||||
markPromotedDraftThreadByRef: vi.fn(),
|
||||
markPromotedDraftThreadsByRef: vi.fn(),
|
||||
useComposerDraftStore: {
|
||||
getState: () => ({
|
||||
getDraftThreadByRef: vi.fn(() => null),
|
||||
clearDraftThread: vi.fn(),
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("~/localApi", () => ({
|
||||
ensureLocalApi: vi.fn(() => ({
|
||||
persistence: {
|
||||
setSavedEnvironmentRegistry: vi.fn(async () => undefined),
|
||||
},
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("~/lib/terminalStateCleanup", () => ({
|
||||
collectActiveTerminalThreadIds: vi.fn(() => []),
|
||||
}));
|
||||
|
||||
vi.mock("~/orchestrationEventEffects", () => ({
|
||||
deriveOrchestrationBatchEffects: vi.fn(() => ({
|
||||
promotedThreadRefs: [],
|
||||
invalidatedProviderState: false,
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("~/lib/projectReactQuery", () => ({
|
||||
projectQueryKeys: {
|
||||
all: ["projects"],
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("~/lib/providerReactQuery", () => ({
|
||||
providerQueryKeys: {
|
||||
all: ["providers"],
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("~/store", () => ({
|
||||
useStore: {
|
||||
getState: () => ({
|
||||
syncServerShellSnapshot: vi.fn(),
|
||||
syncServerThreadDetail: vi.fn(),
|
||||
removeServerThreadDetail: vi.fn(),
|
||||
applyServerShellEvent: vi.fn(),
|
||||
}),
|
||||
},
|
||||
selectProjectsAcrossEnvironments: vi.fn(() => []),
|
||||
selectSidebarThreadSummaryByRef: vi.fn(() => null),
|
||||
selectThreadByRef: vi.fn(() => null),
|
||||
selectThreadsAcrossEnvironments: vi.fn(() => []),
|
||||
}));
|
||||
|
||||
vi.mock("~/terminalStateStore", () => ({
|
||||
useTerminalStateStore: {
|
||||
getState: () => ({
|
||||
applyTerminalEvent: vi.fn(),
|
||||
removeTerminalState: vi.fn(),
|
||||
clearTerminalSelection: vi.fn(),
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("~/uiStateStore", () => ({
|
||||
useUiStateStore: {
|
||||
getState: () => ({
|
||||
clearThreadUi: vi.fn(),
|
||||
syncPromotedDraftThreadRefs: vi.fn(),
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
||||
const savedRecord = {
|
||||
environmentId: EnvironmentId.make("env-saved"),
|
||||
label: "Remote environment",
|
||||
httpBaseUrl: "https://remote.example.test/",
|
||||
wsBaseUrl: "wss://remote.example.test/",
|
||||
};
|
||||
|
||||
const configSnapshot = {
|
||||
environment: {
|
||||
environmentId: savedRecord.environmentId,
|
||||
label: "Remote environment",
|
||||
},
|
||||
};
|
||||
|
||||
function createClient() {
|
||||
return {
|
||||
dispose: vi.fn(async () => undefined),
|
||||
reconnect: vi.fn(async () => undefined),
|
||||
server: {
|
||||
getConfig: vi.fn(async () => configSnapshot),
|
||||
subscribeConfig: vi.fn(() => () => undefined),
|
||||
subscribeLifecycle: vi.fn(() => () => undefined),
|
||||
subscribeAuthAccess: vi.fn(() => () => undefined),
|
||||
refreshProviders: vi.fn(async () => undefined),
|
||||
upsertKeybinding: vi.fn(async () => undefined),
|
||||
getSettings: vi.fn(async () => undefined),
|
||||
updateSettings: vi.fn(async () => undefined),
|
||||
},
|
||||
orchestration: {
|
||||
subscribeShell: vi.fn(() => () => undefined),
|
||||
subscribeThread: vi.fn(() => () => undefined),
|
||||
dispatchCommand: vi.fn(async () => undefined),
|
||||
getTurnDiff: vi.fn(async () => undefined),
|
||||
getFullThreadDiff: vi.fn(async () => undefined),
|
||||
},
|
||||
terminal: {
|
||||
open: vi.fn(async () => undefined),
|
||||
write: vi.fn(async () => undefined),
|
||||
resize: vi.fn(async () => undefined),
|
||||
clear: vi.fn(async () => undefined),
|
||||
restart: vi.fn(async () => undefined),
|
||||
close: vi.fn(async () => undefined),
|
||||
onEvent: vi.fn(() => () => undefined),
|
||||
},
|
||||
projects: {
|
||||
searchEntries: vi.fn(async () => []),
|
||||
writeFile: vi.fn(async () => undefined),
|
||||
},
|
||||
shell: {
|
||||
openInEditor: vi.fn(async () => undefined),
|
||||
},
|
||||
git: {
|
||||
pull: vi.fn(async () => undefined),
|
||||
refreshStatus: vi.fn(async () => undefined),
|
||||
onStatus: vi.fn(() => () => undefined),
|
||||
runStackedAction: vi.fn(async () => ({})),
|
||||
listBranches: vi.fn(async () => []),
|
||||
createWorktree: vi.fn(async () => undefined),
|
||||
removeWorktree: vi.fn(async () => undefined),
|
||||
createBranch: vi.fn(async () => undefined),
|
||||
checkout: vi.fn(async () => undefined),
|
||||
init: vi.fn(async () => undefined),
|
||||
resolvePullRequest: vi.fn(async () => undefined),
|
||||
preparePullRequestThread: vi.fn(async () => undefined),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("saved environment startup", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
vi.resetModules();
|
||||
vi.clearAllMocks();
|
||||
|
||||
mockFetchRemoteSessionState.mockResolvedValue({
|
||||
authenticated: true,
|
||||
role: "owner",
|
||||
});
|
||||
mockGetSavedEnvironmentRecord.mockImplementation((environmentId: EnvironmentId) =>
|
||||
environmentId === savedRecord.environmentId ? savedRecord : null,
|
||||
);
|
||||
mockListSavedEnvironmentRecords.mockReturnValue([savedRecord]);
|
||||
mockSavedEnvironmentRegistrySubscribe.mockReturnValue(() => undefined);
|
||||
mockWaitForSavedEnvironmentRegistryHydration.mockResolvedValue(undefined);
|
||||
mockReadSavedEnvironmentBearerToken.mockResolvedValue("saved-bearer-token");
|
||||
mockCreateWsRpcClient.mockImplementation(() => createClient());
|
||||
mockCreateEnvironmentConnection.mockImplementation((input) => {
|
||||
if (input.kind === "saved") {
|
||||
queueMicrotask(() => {
|
||||
input.onConfigSnapshot?.(configSnapshot);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
kind: input.kind,
|
||||
environmentId: input.knownEnvironment.environmentId,
|
||||
knownEnvironment: input.knownEnvironment,
|
||||
client: input.client,
|
||||
ensureBootstrapped: vi.fn(async () => undefined),
|
||||
reconnect: vi.fn(async () => undefined),
|
||||
dispose: vi.fn(async () => undefined),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const { resetEnvironmentServiceForTests } = await import("./service");
|
||||
await resetEnvironmentServiceForTests();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("uses the initial config snapshot instead of issuing an extra getConfig call", async () => {
|
||||
const { startEnvironmentConnectionService, resetEnvironmentServiceForTests } =
|
||||
await import("./service");
|
||||
|
||||
const stop = startEnvironmentConnectionService(new QueryClient());
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
const savedConnectionCall = mockCreateEnvironmentConnection.mock.calls.find(
|
||||
([input]) => input.kind === "saved",
|
||||
);
|
||||
expect(savedConnectionCall).toBeDefined();
|
||||
|
||||
const savedClient = savedConnectionCall?.[0]?.client;
|
||||
expect(savedClient.server.getConfig).not.toHaveBeenCalled();
|
||||
expect(mockFetchRemoteSessionState).toHaveBeenCalledTimes(1);
|
||||
|
||||
stop();
|
||||
await resetEnvironmentServiceForTests();
|
||||
});
|
||||
|
||||
it("coalesces hydration and registry sync so the initial saved connection only starts once", async () => {
|
||||
let finishHydration!: () => void;
|
||||
let finishTokenRead!: (token: string) => void;
|
||||
|
||||
mockWaitForSavedEnvironmentRegistryHydration.mockImplementation(
|
||||
() =>
|
||||
new Promise<void>((resolve) => {
|
||||
finishHydration = () => resolve();
|
||||
}),
|
||||
);
|
||||
mockReadSavedEnvironmentBearerToken.mockImplementation(
|
||||
() =>
|
||||
new Promise<string>((resolve) => {
|
||||
finishTokenRead = resolve;
|
||||
}),
|
||||
);
|
||||
|
||||
const { startEnvironmentConnectionService, resetEnvironmentServiceForTests } =
|
||||
await import("./service");
|
||||
|
||||
const stop = startEnvironmentConnectionService(new QueryClient());
|
||||
const registryListener = mockSavedEnvironmentRegistrySubscribe.mock.calls[0]?.[0];
|
||||
expect(registryListener).toBeTypeOf("function");
|
||||
|
||||
registryListener?.();
|
||||
finishHydration();
|
||||
await vi.waitFor(() => {
|
||||
expect(mockReadSavedEnvironmentBearerToken).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
finishTokenRead("saved-bearer-token");
|
||||
await vi.runAllTimersAsync();
|
||||
|
||||
const savedConnectionCalls = mockCreateEnvironmentConnection.mock.calls.filter(
|
||||
([input]) => input.kind === "saved",
|
||||
);
|
||||
expect(savedConnectionCalls).toHaveLength(1);
|
||||
expect(mockFetchRemoteSessionState).toHaveBeenCalledTimes(1);
|
||||
|
||||
stop();
|
||||
await resetEnvironmentServiceForTests();
|
||||
});
|
||||
});
|
||||
@@ -369,7 +369,9 @@ describe("retainThreadDetailSubscription", () => {
|
||||
listEnvironmentConnections().some((connection) => connection.environmentId === environmentId),
|
||||
).toBe(false);
|
||||
|
||||
await reconnectSavedEnvironment(environmentId);
|
||||
const reconnectPromise = reconnectSavedEnvironment(environmentId);
|
||||
await vi.advanceTimersByTimeAsync(200);
|
||||
await reconnectPromise;
|
||||
await vi.waitFor(() => {
|
||||
expect(mockCreateEnvironmentConnection).toHaveBeenCalledTimes(3);
|
||||
expect(mockSubscribeThread).toHaveBeenCalledTimes(2);
|
||||
|
||||
@@ -139,9 +139,70 @@ let lastBrowserResumeReconnectAt = Number.NEGATIVE_INFINITY;
|
||||
const THREAD_DETAIL_SUBSCRIPTION_IDLE_EVICTION_MS = 15 * 60 * 1000;
|
||||
const MAX_CACHED_THREAD_DETAIL_SUBSCRIPTIONS = 32;
|
||||
const BROWSER_RESUME_RECONNECT_COOLDOWN_MS = 2_000;
|
||||
const INITIAL_SERVER_CONFIG_SNAPSHOT_WAIT_MS = 150;
|
||||
const NOOP = () => undefined;
|
||||
const SSH_HTTP_STATUS_RE = /^\[ssh_http:(\d+)\]\s/u;
|
||||
|
||||
function createDeferredPromise<T>() {
|
||||
let resolve: ((value: T) => void) | null = null;
|
||||
const promise = new Promise<T>((nextResolve) => {
|
||||
resolve = nextResolve;
|
||||
});
|
||||
|
||||
return {
|
||||
promise,
|
||||
resolve: (value: T) => {
|
||||
resolve?.(value);
|
||||
resolve = null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function waitForConfigSnapshot(
|
||||
promise: Promise<ServerConfig>,
|
||||
timeoutMs: number,
|
||||
): Promise<ServerConfig | null> {
|
||||
return await new Promise<ServerConfig | null>((resolve) => {
|
||||
const timeoutId = globalThis.setTimeout(() => resolve(null), timeoutMs);
|
||||
promise.then(
|
||||
(config) => {
|
||||
clearTimeout(timeoutId);
|
||||
resolve(config);
|
||||
},
|
||||
() => {
|
||||
clearTimeout(timeoutId);
|
||||
resolve(null);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function createSavedEnvironmentSyncScheduler() {
|
||||
let activeSync: Promise<void> | null = null;
|
||||
let queued = false;
|
||||
|
||||
const run = async (): Promise<void> => {
|
||||
do {
|
||||
queued = false;
|
||||
await syncSavedEnvironmentConnections(listSavedEnvironmentRecords());
|
||||
} while (queued);
|
||||
};
|
||||
|
||||
return () => {
|
||||
if (activeSync) {
|
||||
queued = true;
|
||||
return activeSync;
|
||||
}
|
||||
|
||||
activeSync = run()
|
||||
.catch(() => undefined)
|
||||
.finally(() => {
|
||||
activeSync = null;
|
||||
});
|
||||
|
||||
return activeSync;
|
||||
};
|
||||
}
|
||||
function compareAppliedProjectionVersion(
|
||||
left: { readonly sequence: number; readonly updatedAt: string | null },
|
||||
right: { readonly sequence: number; readonly updatedAt: string | null },
|
||||
@@ -233,7 +294,6 @@ function markAppliedProjectionEvent(environmentId: EnvironmentId, sequence: numb
|
||||
updatedAt: currentVersion?.updatedAt ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
function getThreadDetailSubscriptionKey(environmentId: EnvironmentId, threadId: ThreadId): string {
|
||||
return scopedThreadKey(scopeThreadRef(environmentId, threadId));
|
||||
}
|
||||
@@ -1284,6 +1344,7 @@ async function ensureSavedEnvironmentConnection(
|
||||
const client =
|
||||
options?.client ??
|
||||
createSavedEnvironmentClient(activeRecord.environmentId, activeBearerToken);
|
||||
const initialConfigSnapshot = createDeferredPromise<ServerConfig>();
|
||||
const knownEnvironment = createKnownEnvironment({
|
||||
id: activeRecord.environmentId,
|
||||
label: activeRecord.label,
|
||||
@@ -1308,6 +1369,7 @@ async function ensureSavedEnvironmentConnection(
|
||||
);
|
||||
},
|
||||
onConfigSnapshot: (config) => {
|
||||
initialConfigSnapshot.resolve(config);
|
||||
useSavedEnvironmentRuntimeStore.getState().patch(activeRecord.environmentId, {
|
||||
descriptor: config.environment,
|
||||
serverConfig: config,
|
||||
@@ -1323,12 +1385,18 @@ async function ensureSavedEnvironmentConnection(
|
||||
|
||||
try {
|
||||
try {
|
||||
const initialServerConfig =
|
||||
options?.serverConfig ??
|
||||
(await waitForConfigSnapshot(
|
||||
initialConfigSnapshot.promise,
|
||||
INITIAL_SERVER_CONFIG_SNAPSHOT_WAIT_MS,
|
||||
));
|
||||
await refreshSavedEnvironmentMetadata(
|
||||
activeRecord.environmentId,
|
||||
activeBearerToken,
|
||||
client,
|
||||
roleHint,
|
||||
options?.serverConfig ?? null,
|
||||
initialServerConfig,
|
||||
);
|
||||
} catch (error) {
|
||||
const isAuthError = activeRecord.desktopSsh
|
||||
@@ -1699,6 +1767,7 @@ export function startEnvironmentConnectionService(queryClient: QueryClient): ()
|
||||
trailing: true,
|
||||
},
|
||||
);
|
||||
const requestSavedEnvironmentSync = createSavedEnvironmentSyncScheduler();
|
||||
|
||||
maybeCreatePrimaryEnvironmentConnection();
|
||||
|
||||
@@ -1706,11 +1775,11 @@ export function startEnvironmentConnectionService(queryClient: QueryClient): ()
|
||||
if (!hasSavedEnvironmentRegistryHydrated()) {
|
||||
return;
|
||||
}
|
||||
void syncSavedEnvironmentConnections(listSavedEnvironmentRecords());
|
||||
void requestSavedEnvironmentSync();
|
||||
});
|
||||
|
||||
void waitForSavedEnvironmentRegistryHydration()
|
||||
.then(() => syncSavedEnvironmentConnections(listSavedEnvironmentRecords()))
|
||||
.then(() => requestSavedEnvironmentSync())
|
||||
.catch(() => undefined);
|
||||
|
||||
const unsubscribeBrowserResumeReconnects = subscribeBrowserResumeReconnects();
|
||||
|
||||
@@ -22,6 +22,7 @@ import { ensureLocalApi } from "~/localApi";
|
||||
import { Struct } from "effect";
|
||||
import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
|
||||
import { applySettingsUpdated, getServerConfig, useServerSettings } from "~/rpc/serverState";
|
||||
import { applyThemePalette } from "~/themePalette";
|
||||
|
||||
const CLIENT_SETTINGS_PERSISTENCE_ERROR_SCOPE = "[CLIENT_SETTINGS]";
|
||||
|
||||
@@ -65,7 +66,9 @@ async function hydrateClientSettings(): Promise<void> {
|
||||
try {
|
||||
const persistedSettings = await ensureLocalApi().persistence.getClientSettings();
|
||||
if (persistedSettings) {
|
||||
replaceClientSettingsSnapshot({ ...DEFAULT_CLIENT_SETTINGS, ...persistedSettings });
|
||||
const nextSettings = { ...DEFAULT_CLIENT_SETTINGS, ...persistedSettings };
|
||||
replaceClientSettingsSnapshot(nextSettings);
|
||||
applyThemePalette(nextSettings.themePalette);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`${CLIENT_SETTINGS_PERSISTENCE_ERROR_SCOPE} hydrate failed`, error);
|
||||
@@ -86,6 +89,7 @@ async function hydrateClientSettings(): Promise<void> {
|
||||
|
||||
function persistClientSettings(settings: ClientSettings): void {
|
||||
replaceClientSettingsSnapshot(settings);
|
||||
applyThemePalette(settings.themePalette);
|
||||
void ensureLocalApi()
|
||||
.persistence.setClientSettings(settings)
|
||||
.catch((error) => {
|
||||
|
||||
+38
-36
@@ -86,28 +86,30 @@
|
||||
:root {
|
||||
color-scheme: light;
|
||||
--radius: 0.625rem;
|
||||
--background: var(--color-white);
|
||||
--theme-primary-seed: #3b5bdb;
|
||||
--theme-neutral-seed: #737373;
|
||||
--background: color-mix(in srgb, var(--theme-neutral-seed) 3%, var(--color-white));
|
||||
--app-chrome-background: var(--background);
|
||||
--foreground: var(--color-neutral-800);
|
||||
--card: var(--color-white);
|
||||
--card-foreground: var(--color-neutral-800);
|
||||
--popover: var(--color-white);
|
||||
--popover-foreground: var(--color-neutral-800);
|
||||
--primary: oklch(0.488 0.217 264);
|
||||
--foreground: color-mix(in srgb, var(--theme-neutral-seed) 35%, var(--color-neutral-950));
|
||||
--card: color-mix(in srgb, var(--theme-neutral-seed) 1.5%, var(--color-white));
|
||||
--card-foreground: var(--foreground);
|
||||
--popover: var(--card);
|
||||
--popover-foreground: var(--foreground);
|
||||
--primary: color-mix(in oklch, var(--theme-primary-seed) 88%, var(--color-black));
|
||||
--primary-foreground: var(--color-white);
|
||||
--secondary: --alpha(var(--color-black) / 4%);
|
||||
--secondary-foreground: var(--color-neutral-800);
|
||||
--muted: --alpha(var(--color-black) / 4%);
|
||||
--muted-foreground: color-mix(in srgb, var(--color-neutral-500) 90%, var(--color-black));
|
||||
--accent: --alpha(var(--color-black) / 4%);
|
||||
--accent-foreground: var(--color-neutral-800);
|
||||
--secondary: color-mix(in srgb, var(--theme-neutral-seed) 7%, transparent);
|
||||
--secondary-foreground: var(--foreground);
|
||||
--muted: color-mix(in srgb, var(--theme-neutral-seed) 7%, transparent);
|
||||
--muted-foreground: color-mix(in srgb, var(--theme-neutral-seed) 72%, var(--color-black));
|
||||
--accent: color-mix(in srgb, var(--theme-primary-seed) 8%, transparent);
|
||||
--accent-foreground: color-mix(in srgb, var(--theme-primary-seed) 38%, var(--foreground));
|
||||
--destructive: var(--color-red-500);
|
||||
--border: --alpha(var(--color-black) / 8%);
|
||||
--input: --alpha(var(--color-black) / 10%);
|
||||
--ring: oklch(0.488 0.217 264);
|
||||
--border: color-mix(in srgb, var(--theme-neutral-seed) 16%, transparent);
|
||||
--input: color-mix(in srgb, var(--theme-neutral-seed) 19%, transparent);
|
||||
--ring: color-mix(in oklch, var(--theme-primary-seed) 88%, var(--color-black));
|
||||
--destructive-foreground: var(--color-red-700);
|
||||
--info: var(--color-blue-500);
|
||||
--info-foreground: var(--color-blue-700);
|
||||
--info: color-mix(in oklch, var(--theme-primary-seed) 84%, var(--color-blue-500));
|
||||
--info-foreground: color-mix(in oklch, var(--theme-primary-seed) 80%, var(--color-blue-700));
|
||||
--success: var(--color-emerald-500);
|
||||
--success-foreground: var(--color-emerald-700);
|
||||
--warning: var(--color-amber-500);
|
||||
@@ -115,28 +117,28 @@
|
||||
|
||||
@variant dark {
|
||||
color-scheme: dark;
|
||||
--background: color-mix(in srgb, var(--color-neutral-950) 95%, var(--color-white));
|
||||
--background: color-mix(in srgb, var(--theme-neutral-seed) 10%, var(--color-neutral-950));
|
||||
--app-chrome-background: var(--background);
|
||||
--foreground: var(--color-neutral-100);
|
||||
--card: color-mix(in srgb, var(--background) 98%, var(--color-white));
|
||||
--card-foreground: var(--color-neutral-100);
|
||||
--popover: color-mix(in srgb, var(--background) 98%, var(--color-white));
|
||||
--popover-foreground: var(--color-neutral-100);
|
||||
--primary: oklch(0.588 0.217 264);
|
||||
--foreground: color-mix(in srgb, var(--theme-neutral-seed) 10%, var(--color-neutral-100));
|
||||
--card: color-mix(in srgb, var(--theme-neutral-seed) 14%, var(--background));
|
||||
--card-foreground: var(--foreground);
|
||||
--popover: var(--card);
|
||||
--popover-foreground: var(--foreground);
|
||||
--primary: color-mix(in oklch, var(--theme-primary-seed) 86%, var(--color-white));
|
||||
--primary-foreground: var(--color-white);
|
||||
--secondary: --alpha(var(--color-white) / 4%);
|
||||
--secondary-foreground: var(--color-neutral-100);
|
||||
--muted: --alpha(var(--color-white) / 4%);
|
||||
--muted-foreground: color-mix(in srgb, var(--color-neutral-500) 90%, var(--color-white));
|
||||
--accent: --alpha(var(--color-white) / 4%);
|
||||
--accent-foreground: var(--color-neutral-100);
|
||||
--secondary: color-mix(in srgb, var(--theme-neutral-seed) 13%, transparent);
|
||||
--secondary-foreground: var(--foreground);
|
||||
--muted: color-mix(in srgb, var(--theme-neutral-seed) 13%, transparent);
|
||||
--muted-foreground: color-mix(in srgb, var(--theme-neutral-seed) 58%, var(--color-neutral-100));
|
||||
--accent: color-mix(in srgb, var(--theme-primary-seed) 16%, transparent);
|
||||
--accent-foreground: color-mix(in srgb, var(--theme-primary-seed) 20%, var(--foreground));
|
||||
--destructive: color-mix(in srgb, var(--color-red-500) 90%, var(--color-white));
|
||||
--border: --alpha(var(--color-white) / 6%);
|
||||
--input: --alpha(var(--color-white) / 8%);
|
||||
--ring: oklch(0.588 0.217 264);
|
||||
--border: color-mix(in srgb, var(--theme-neutral-seed) 16%, transparent);
|
||||
--input: color-mix(in srgb, var(--theme-neutral-seed) 20%, transparent);
|
||||
--ring: color-mix(in oklch, var(--theme-primary-seed) 86%, var(--color-white));
|
||||
--destructive-foreground: var(--color-red-400);
|
||||
--info: var(--color-blue-500);
|
||||
--info-foreground: var(--color-blue-400);
|
||||
--info: color-mix(in oklch, var(--theme-primary-seed) 84%, var(--color-blue-400));
|
||||
--info-foreground: color-mix(in oklch, var(--theme-primary-seed) 70%, var(--color-blue-300));
|
||||
--success: var(--color-emerald-500);
|
||||
--success-foreground: var(--color-emerald-400);
|
||||
--warning: var(--color-amber-500);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
CommandId,
|
||||
DEFAULT_SERVER_SETTINGS,
|
||||
DEFAULT_THEME_PALETTE,
|
||||
type DesktopBridge,
|
||||
EnvironmentId,
|
||||
type VcsStatusResult,
|
||||
@@ -584,6 +585,7 @@ describe("wsApi", () => {
|
||||
sidebarProjectSortOrder: "manual" as const,
|
||||
sidebarThreadSortOrder: "created_at" as const,
|
||||
timestampFormat: "24-hour" as const,
|
||||
themePalette: DEFAULT_THEME_PALETTE,
|
||||
};
|
||||
const getClientSettings = vi.fn().mockResolvedValue({
|
||||
...clientSettings,
|
||||
@@ -645,6 +647,7 @@ describe("wsApi", () => {
|
||||
sidebarProjectSortOrder: "manual" as const,
|
||||
sidebarThreadSortOrder: "created_at" as const,
|
||||
timestampFormat: "24-hour" as const,
|
||||
themePalette: DEFAULT_THEME_PALETTE,
|
||||
};
|
||||
|
||||
await api.persistence.setClientSettings(clientSettings);
|
||||
|
||||
@@ -10,12 +10,15 @@ import { isElectron } from "./env";
|
||||
import { getRouter } from "./router";
|
||||
import { APP_DISPLAY_NAME } from "./branding";
|
||||
import { syncDocumentWindowControlsOverlayClass } from "./lib/windowControlsOverlay";
|
||||
import { applyStoredThemePalette } from "./themePalette";
|
||||
|
||||
// Electron loads the app from a file-backed shell, so hash history avoids path resolution issues.
|
||||
const history = isElectron ? createHashHistory() : createBrowserHistory();
|
||||
|
||||
const router = getRouter(history);
|
||||
|
||||
applyStoredThemePalette();
|
||||
|
||||
if (isElectron) {
|
||||
syncDocumentWindowControlsOverlayClass();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ const DiffPanel = lazy(() => import("../components/DiffPanel"));
|
||||
const DIFF_INLINE_SIDEBAR_WIDTH_STORAGE_KEY = "chat_diff_sidebar_width";
|
||||
const DIFF_INLINE_DEFAULT_WIDTH = "clamp(24rem,34vw,36rem)";
|
||||
const DIFF_INLINE_SIDEBAR_MIN_WIDTH = 22 * 16;
|
||||
const DIFF_INLINE_SIDEBAR_MAX_WIDTH = 36 * 16;
|
||||
const DIFF_INLINE_SIDEBAR_MAX_WIDTH = 256 * 16;
|
||||
const COMPOSER_COMPACT_MIN_LEFT_CONTROLS_WIDTH_PX = 208;
|
||||
|
||||
const DiffLoadingFallback = (props: { mode: DiffPanelMode }) => {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DEFAULT_THEME_PALETTE } from "@t3tools/contracts/settings";
|
||||
|
||||
import {
|
||||
getThemePaletteCustomProperties,
|
||||
normalizeThemePalette,
|
||||
normalizeThemePaletteColor,
|
||||
} from "./themePalette";
|
||||
|
||||
describe("themePalette", () => {
|
||||
it("normalizes valid hex colors and rejects invalid input", () => {
|
||||
expect(normalizeThemePaletteColor(" #Aa33f0 ")).toBe("#aa33f0");
|
||||
expect(normalizeThemePaletteColor("#abc")).toBeUndefined();
|
||||
expect(normalizeThemePaletteColor("rebeccapurple")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("generates CSS seed variables from selected colors", () => {
|
||||
const properties = getThemePaletteCustomProperties({
|
||||
primaryColor: "#ff0000",
|
||||
neutralColor: "#336699",
|
||||
});
|
||||
|
||||
expect(properties).toEqual({
|
||||
"--theme-primary-seed": "#ff0000",
|
||||
"--theme-neutral-seed": "#336699",
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to the default palette when persisted values are malformed", () => {
|
||||
const palette = normalizeThemePalette({
|
||||
primaryColor: "bad",
|
||||
neutralColor: "also-bad",
|
||||
});
|
||||
|
||||
expect(palette).toEqual(DEFAULT_THEME_PALETTE);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
import { DEFAULT_THEME_PALETTE, type ThemePaletteSettings } from "@t3tools/contracts/settings";
|
||||
|
||||
export const THEME_PALETTE_STORAGE_KEY = "t3code:client-settings:v1";
|
||||
|
||||
export const THEME_PALETTE_SWATCHES = [
|
||||
"#3b5bdb",
|
||||
"#7c3aed",
|
||||
"#db2777",
|
||||
"#dc2626",
|
||||
"#ea580c",
|
||||
"#ca8a04",
|
||||
"#16a34a",
|
||||
"#0891b2",
|
||||
] as const;
|
||||
|
||||
export const THEME_PALETTE_PREVIEW_SWATCHES = [
|
||||
{ label: "Primary", variable: "--primary" },
|
||||
{ label: "Surface", variable: "--background" },
|
||||
{ label: "Card", variable: "--card" },
|
||||
{ label: "Muted", variable: "--muted" },
|
||||
] as const;
|
||||
|
||||
const THEME_HEX_COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/u;
|
||||
const THEME_PALETTE_CUSTOM_PROPERTIES = ["--theme-primary-seed", "--theme-neutral-seed"] as const;
|
||||
|
||||
export function normalizeThemePaletteColor(value: string | undefined | null): string | undefined {
|
||||
const trimmed = value?.trim();
|
||||
if (!trimmed || !THEME_HEX_COLOR_PATTERN.test(trimmed)) {
|
||||
return undefined;
|
||||
}
|
||||
return trimmed.toLowerCase();
|
||||
}
|
||||
|
||||
export function normalizeThemePalette(
|
||||
value: Partial<ThemePaletteSettings> | null | undefined,
|
||||
): ThemePaletteSettings {
|
||||
return {
|
||||
primaryColor:
|
||||
normalizeThemePaletteColor(value?.primaryColor) ?? DEFAULT_THEME_PALETTE.primaryColor,
|
||||
neutralColor:
|
||||
normalizeThemePaletteColor(value?.neutralColor) ?? DEFAULT_THEME_PALETTE.neutralColor,
|
||||
};
|
||||
}
|
||||
|
||||
export function getThemePaletteCustomProperties(
|
||||
value: Partial<ThemePaletteSettings> | null | undefined,
|
||||
) {
|
||||
const palette = normalizeThemePalette(value);
|
||||
return {
|
||||
"--theme-primary-seed": palette.primaryColor,
|
||||
"--theme-neutral-seed": palette.neutralColor,
|
||||
} as const;
|
||||
}
|
||||
|
||||
export function applyThemePalette(value: Partial<ThemePaletteSettings> | null | undefined) {
|
||||
if (typeof document === "undefined") return;
|
||||
const properties = getThemePaletteCustomProperties(value);
|
||||
for (const propertyName of THEME_PALETTE_CUSTOM_PROPERTIES) {
|
||||
document.documentElement.style.setProperty(propertyName, properties[propertyName]);
|
||||
}
|
||||
}
|
||||
|
||||
export function readStoredThemePalette(): ThemePaletteSettings {
|
||||
if (typeof window === "undefined" || typeof localStorage === "undefined") {
|
||||
return DEFAULT_THEME_PALETTE;
|
||||
}
|
||||
|
||||
try {
|
||||
const raw = localStorage.getItem(THEME_PALETTE_STORAGE_KEY);
|
||||
if (!raw) {
|
||||
return DEFAULT_THEME_PALETTE;
|
||||
}
|
||||
const parsed = JSON.parse(raw) as { themePalette?: Partial<ThemePaletteSettings> };
|
||||
return normalizeThemePalette(parsed.themePalette);
|
||||
} catch {
|
||||
return DEFAULT_THEME_PALETTE;
|
||||
}
|
||||
}
|
||||
|
||||
export function applyStoredThemePalette() {
|
||||
applyThemePalette(readStoredThemePalette());
|
||||
}
|
||||
@@ -5,10 +5,12 @@
|
||||
"": {
|
||||
"name": "@t3tools/monorepo",
|
||||
"devDependencies": {
|
||||
"@effect/language-service": "catalog:",
|
||||
"@types/node": "catalog:",
|
||||
"oxfmt": "^0.40.0",
|
||||
"oxlint": "^1.55.0",
|
||||
"turbo": "^2.3.3",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:",
|
||||
},
|
||||
},
|
||||
@@ -57,7 +59,7 @@
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/sql-sqlite-bun": "catalog:",
|
||||
"@opencode-ai/sdk": "^1.3.15",
|
||||
"@pierre/diffs": "^1.1.0-beta.16",
|
||||
"@pierre/diffs": "catalog:",
|
||||
"effect": "catalog:",
|
||||
"node-pty": "^1.1.0",
|
||||
"open": "^10.1.0",
|
||||
@@ -91,7 +93,7 @@
|
||||
"@formkit/auto-animate": "^0.9.0",
|
||||
"@legendapp/list": "3.0.0-beta.44",
|
||||
"@lexical/react": "^0.41.0",
|
||||
"@pierre/diffs": "^1.1.0-beta.16",
|
||||
"@pierre/diffs": "catalog:",
|
||||
"@t3tools/client-runtime": "workspace:*",
|
||||
"@t3tools/contracts": "workspace:*",
|
||||
"@t3tools/shared": "workspace:*",
|
||||
@@ -279,6 +281,7 @@
|
||||
"@effect/platform-node-shared": "4.0.0-beta.59",
|
||||
"@effect/sql-sqlite-bun": "4.0.0-beta.59",
|
||||
"@effect/vitest": "4.0.0-beta.59",
|
||||
"@pierre/diffs": "1.1.20",
|
||||
"@types/bun": "^1.3.11",
|
||||
"@types/node": "^24.10.13",
|
||||
"effect": "4.0.0-beta.59",
|
||||
@@ -699,9 +702,9 @@
|
||||
|
||||
"@oxlint/binding-win32-x64-msvc": ["@oxlint/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-ZHa0clocjLmIDr+1LwoWtxRcoYniAvERotvwKUYKhH41NVfl0Y4LNbyQkwMZzwDvKklKGvGZ5+DAG58/Ik47tQ=="],
|
||||
|
||||
"@pierre/diffs": ["@pierre/[email protected]", "", { "dependencies": { "@pierre/theme": "0.0.22", "@shikijs/transformers": "^3.0.0", "diff": "8.0.3", "hast-util-to-html": "9.0.5", "lru_map": "0.4.1", "shiki": "^3.0.0" }, "peerDependencies": { "react": "^18.3.1 || ^19.0.0", "react-dom": "^18.3.1 || ^19.0.0" } }, "sha512-wbxrzcmanJuHZb81iir09j42uU9AnKxXDtAuEQJbAnti5f2UfYdCQYejawuHZStFrlsMacCZLh/dDHmqvAaQCw=="],
|
||||
"@pierre/diffs": ["@pierre/[email protected].20", "", { "dependencies": { "@pierre/theme": "0.0.28", "@shikijs/transformers": "^3.0.0", "diff": "8.0.3", "hast-util-to-html": "9.0.5", "lru_map": "0.4.1", "shiki": "^3.0.0" }, "peerDependencies": { "react": "^18.3.1 || ^19.0.0", "react-dom": "^18.3.1 || ^19.0.0" } }, "sha512-lLi+3sLCm3QDd5/aLO9pw+WbF6UzhrkWm2oTZ5WZJTGemOyUNRJ4DDhcEKmVusu4C4bXx9Nssh6fF+wQcapb5w=="],
|
||||
|
||||
"@pierre/theme": ["@pierre/[email protected]2", "", {}, "sha512-ePUIdQRNGjrveELTU7fY89Xa7YGHHEy5Po5jQy/18lm32eRn96+tnYJEtFooGdffrx55KBUtOXfvVy/7LDFFhA=="],
|
||||
"@pierre/theme": ["@pierre/[email protected]8", "", {}, "sha512-1j/H/fECBuc9dEvntdWI+l435HZapw+RCJTlqCA6BboQ5TjlnE005j/ROWutXIs8aq5OAc82JI2Kwk4A1WWBgw=="],
|
||||
|
||||
"@polka/url": ["@polka/[email protected]", "", {}, "sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww=="],
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"@effect/sql-sqlite-bun": "4.0.0-beta.59",
|
||||
"@effect/vitest": "4.0.0-beta.59",
|
||||
"@effect/language-service": "0.84.2",
|
||||
"@pierre/diffs": "1.1.20",
|
||||
"@types/bun": "^1.3.11",
|
||||
"@types/node": "^24.10.13",
|
||||
"tsdown": "^0.20.3",
|
||||
@@ -26,6 +27,7 @@
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"prepare": "effect-language-service patch",
|
||||
"dev": "node scripts/dev-runner.ts dev",
|
||||
"dev:server": "node scripts/dev-runner.ts dev:server",
|
||||
"dev:web": "node scripts/dev-runner.ts dev:web",
|
||||
@@ -58,10 +60,12 @@
|
||||
"sync:vscode-icons": "node scripts/sync-vscode-icons.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@effect/language-service": "catalog:",
|
||||
"@types/node": "catalog:",
|
||||
"oxfmt": "^0.40.0",
|
||||
"oxlint": "^1.55.0",
|
||||
"turbo": "^2.3.3",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:"
|
||||
},
|
||||
"overrides": {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "effect-language-service patch",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@t3tools/contracts",
|
||||
"version": "0.0.21",
|
||||
"version": "0.0.22",
|
||||
"private": true,
|
||||
"files": [
|
||||
"dist"
|
||||
@@ -24,7 +24,6 @@
|
||||
"scripts": {
|
||||
"dev": "tsdown src/index.ts --format esm,cjs --dts --watch --clean",
|
||||
"build": "tsdown src/index.ts --format esm,cjs --dts --clean",
|
||||
"prepare": "effect-language-service patch",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
|
||||
@@ -2,10 +2,36 @@ import { describe, expect, it } from "vitest";
|
||||
import { Schema } from "effect";
|
||||
|
||||
import { ProviderInstanceId } from "./providerInstance.ts";
|
||||
import { DEFAULT_SERVER_SETTINGS, ServerSettings, ServerSettingsPatch } from "./settings.ts";
|
||||
import {
|
||||
ClientSettingsSchema,
|
||||
DEFAULT_CLIENT_SETTINGS,
|
||||
DEFAULT_SERVER_SETTINGS,
|
||||
DEFAULT_THEME_PALETTE,
|
||||
ServerSettings,
|
||||
ServerSettingsPatch,
|
||||
} from "./settings.ts";
|
||||
|
||||
const decodeServerSettings = Schema.decodeUnknownSync(ServerSettings);
|
||||
const decodeServerSettingsPatch = Schema.decodeUnknownSync(ServerSettingsPatch);
|
||||
const decodeClientSettings = Schema.decodeUnknownSync(ClientSettingsSchema);
|
||||
|
||||
describe("ClientSettings.themePalette", () => {
|
||||
it("defaults theme palette colors for existing client settings", () => {
|
||||
expect(DEFAULT_CLIENT_SETTINGS.themePalette).toEqual(DEFAULT_THEME_PALETTE);
|
||||
expect(decodeClientSettings({}).themePalette).toEqual(DEFAULT_THEME_PALETTE);
|
||||
});
|
||||
|
||||
it("rejects invalid theme palette colors", () => {
|
||||
expect(() =>
|
||||
decodeClientSettings({
|
||||
themePalette: {
|
||||
primaryColor: "rebeccapurple",
|
||||
neutralColor: "#737373",
|
||||
},
|
||||
}),
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
|
||||
it("defaults to an empty record so legacy configs without the key still decode", () => {
|
||||
|
||||
@@ -28,6 +28,23 @@ export const SidebarProjectGroupingMode = Schema.Literals([
|
||||
export type SidebarProjectGroupingMode = typeof SidebarProjectGroupingMode.Type;
|
||||
export const DEFAULT_SIDEBAR_PROJECT_GROUPING_MODE: SidebarProjectGroupingMode = "repository";
|
||||
|
||||
const ThemeColor = TrimmedNonEmptyString.check(Schema.isPattern(/^#[0-9a-fA-F]{6}$/u));
|
||||
|
||||
export const DEFAULT_THEME_PALETTE = {
|
||||
primaryColor: "#3b5bdb",
|
||||
neutralColor: "#737373",
|
||||
} as const;
|
||||
|
||||
export const ThemePaletteSettings = Schema.Struct({
|
||||
primaryColor: ThemeColor.pipe(
|
||||
Schema.withDecodingDefault(Effect.succeed(DEFAULT_THEME_PALETTE.primaryColor)),
|
||||
),
|
||||
neutralColor: ThemeColor.pipe(
|
||||
Schema.withDecodingDefault(Effect.succeed(DEFAULT_THEME_PALETTE.neutralColor)),
|
||||
),
|
||||
}).pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_THEME_PALETTE)));
|
||||
export type ThemePaletteSettings = typeof ThemePaletteSettings.Type;
|
||||
|
||||
export const ClientSettingsSchema = Schema.Struct({
|
||||
autoOpenPlanSidebar: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
|
||||
confirmThreadArchive: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
|
||||
@@ -75,6 +92,7 @@ export const ClientSettingsSchema = Schema.Struct({
|
||||
timestampFormat: TimestampFormat.pipe(
|
||||
Schema.withDecodingDefault(Effect.succeed(DEFAULT_TIMESTAMP_FORMAT)),
|
||||
),
|
||||
themePalette: ThemePaletteSettings,
|
||||
});
|
||||
export type ClientSettings = typeof ClientSettingsSchema.Type;
|
||||
|
||||
@@ -482,5 +500,6 @@ export const ClientSettingsPatch = Schema.Struct({
|
||||
sidebarProjectSortOrder: Schema.optionalKey(SidebarProjectSortOrder),
|
||||
sidebarThreadSortOrder: Schema.optionalKey(SidebarThreadSortOrder),
|
||||
timestampFormat: Schema.optionalKey(TimestampFormat),
|
||||
themePalette: Schema.optionalKey(ThemePaletteSettings),
|
||||
});
|
||||
export type ClientSettingsPatch = typeof ClientSettingsPatch.Type;
|
||||
@@ -35,7 +35,6 @@
|
||||
"scripts": {
|
||||
"dev": "tsdown src/client.ts src/agent.ts src/_generated/schema.gen.ts src/rpc.ts src/protocol.ts src/terminal.ts --format esm,cjs --dts --watch --clean",
|
||||
"build": "tsdown src/client.ts src/agent.ts src/_generated/schema.gen.ts src/rpc.ts src/protocol.ts src/terminal.ts --format esm,cjs --dts --clean",
|
||||
"prepare": "effect-language-service patch",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"generate": "bun run scripts/generate.ts"
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
"scripts": {
|
||||
"dev": "tsdown src/client.ts src/rpc.ts src/protocol.ts src/schema.ts --format esm,cjs --dts --watch --clean",
|
||||
"build": "tsdown src/client.ts src/rpc.ts src/protocol.ts src/schema.ts --format esm,cjs --dts --clean",
|
||||
"prepare": "effect-language-service patch",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"generate": "bun run scripts/generate.ts",
|
||||
|
||||
@@ -82,7 +82,6 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "effect-language-service patch",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "effect-language-service patch",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "effect-language-service patch",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"prepare": "effect-language-service patch",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
|
||||
@@ -197,6 +197,8 @@ try {
|
||||
},
|
||||
);
|
||||
|
||||
rmSync(resolve(tempRoot, "bun.lock"), { force: true });
|
||||
|
||||
execFileSync("bun", ["install", "--ignore-scripts"], {
|
||||
cwd: tempRoot,
|
||||
stdio: "inherit",
|
||||
|
||||
Reference in new issue
Block a user