Compare commits
22
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8effcf380a | ||
|
|
9e8363ceca | ||
|
|
080752a3f7 | ||
|
|
cd685c9a64 | ||
|
|
a8d0e9b06b | ||
|
|
7276b75dd6 | ||
|
|
bb2164c945 | ||
|
|
8c91aa5570 | ||
|
|
6db8257b1e | ||
|
|
f6e7166e79 | ||
|
|
2da8290040 | ||
|
|
4d6e8e1ca5 | ||
|
|
7e4da5b157 | ||
|
|
9acce6ddaa | ||
|
|
8054a32417 | ||
|
|
ed3958daa8 | ||
|
|
9d5c515680 | ||
|
|
0e9677965c | ||
|
|
cc29ceea80 | ||
|
|
32a17b9109 | ||
|
|
e119e18ed3 | ||
|
|
001902c881 |
No files matched your search
@@ -3,6 +3,7 @@ import fs from "node:fs";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||||
import { Effect, Exit, Layer, PubSub, Scope, Stream } from "effect";
|
import { Effect, Exit, Layer, PubSub, Scope, Stream } from "effect";
|
||||||
import { describe, expect, it, afterEach, vi } from "vitest";
|
import { describe, expect, it, afterEach, vi } from "vitest";
|
||||||
import { createServer } from "./wsServer";
|
import { createServer } from "./wsServer";
|
||||||
@@ -38,7 +39,7 @@ import type {
|
|||||||
TerminalWriteInput,
|
TerminalWriteInput,
|
||||||
} from "@t3tools/contracts";
|
} from "@t3tools/contracts";
|
||||||
import { TerminalManager, type TerminalManagerShape } from "./terminal/Services/Manager";
|
import { TerminalManager, type TerminalManagerShape } from "./terminal/Services/Manager";
|
||||||
import { SqlitePersistenceMemory } from "./persistence/Layers/Sqlite";
|
import { makeSqlitePersistenceLive, SqlitePersistenceMemory } from "./persistence/Layers/Sqlite";
|
||||||
import { SqlClient } from "effect/unstable/sql";
|
import { SqlClient } from "effect/unstable/sql";
|
||||||
import { ProviderService, type ProviderServiceShape } from "./provider/Services/ProviderService";
|
import { ProviderService, type ProviderServiceShape } from "./provider/Services/ProviderService";
|
||||||
import { Open, type OpenShape } from "./open";
|
import { Open, type OpenShape } from "./open";
|
||||||
@@ -448,23 +449,117 @@ describe("WebSocket Server", () => {
|
|||||||
|
|
||||||
const ws = await connectWs(port);
|
const ws = await connectWs(port);
|
||||||
connections.push(ws);
|
connections.push(ws);
|
||||||
await waitForMessage(ws); // welcome
|
const welcome = (await waitForMessage(ws)) as WsPush; // welcome
|
||||||
|
expect(welcome.channel).toBe(WS_CHANNELS.serverWelcome);
|
||||||
|
expect(welcome.data).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
cwd: "/test/bootstrap-workspace",
|
||||||
|
projectName: "bootstrap-workspace",
|
||||||
|
bootstrapProjectId: expect.any(String),
|
||||||
|
bootstrapThreadId: expect.any(String),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const snapshotResponse = await sendRequest(ws, ORCHESTRATION_WS_METHODS.getSnapshot);
|
const snapshotResponse = await sendRequest(ws, ORCHESTRATION_WS_METHODS.getSnapshot);
|
||||||
expect(snapshotResponse.error).toBeUndefined();
|
expect(snapshotResponse.error).toBeUndefined();
|
||||||
const snapshot = snapshotResponse.result as {
|
const snapshot = snapshotResponse.result as {
|
||||||
projects: Array<{ workspaceRoot: string; title: string; defaultModel: string | null }>;
|
projects: Array<{
|
||||||
|
id: string;
|
||||||
|
workspaceRoot: string;
|
||||||
|
title: string;
|
||||||
|
defaultModel: string | null;
|
||||||
|
}>;
|
||||||
|
threads: Array<{
|
||||||
|
id: string;
|
||||||
|
projectId: string;
|
||||||
|
title: string;
|
||||||
|
model: string;
|
||||||
|
branch: string | null;
|
||||||
|
worktreePath: string | null;
|
||||||
|
}>;
|
||||||
};
|
};
|
||||||
|
const bootstrapProjectId = (welcome.data as { bootstrapProjectId?: string }).bootstrapProjectId;
|
||||||
|
const bootstrapThreadId = (welcome.data as { bootstrapThreadId?: string }).bootstrapThreadId;
|
||||||
|
expect(bootstrapProjectId).toBeDefined();
|
||||||
|
expect(bootstrapThreadId).toBeDefined();
|
||||||
|
|
||||||
expect(snapshot.projects).toEqual(
|
expect(snapshot.projects).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
|
id: bootstrapProjectId,
|
||||||
workspaceRoot: "/test/bootstrap-workspace",
|
workspaceRoot: "/test/bootstrap-workspace",
|
||||||
title: "bootstrap-workspace",
|
title: "bootstrap-workspace",
|
||||||
defaultModel: "gpt-5-codex",
|
defaultModel: "gpt-5-codex",
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
expect(snapshot.threads).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: bootstrapThreadId,
|
||||||
|
projectId: bootstrapProjectId,
|
||||||
|
title: "New thread",
|
||||||
|
model: "gpt-5-codex",
|
||||||
|
branch: null,
|
||||||
|
worktreePath: null,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("includes bootstrap ids in welcome when cwd project and thread already exist", async () => {
|
||||||
|
const stateDir = makeTempDir("t3code-state-bootstrap-existing-");
|
||||||
|
const persistenceLayer = makeSqlitePersistenceLive(
|
||||||
|
path.join(stateDir, "state.sqlite"),
|
||||||
|
).pipe(Layer.provide(NodeServices.layer)) as unknown as Layer.Layer<SqlClient.SqlClient, never>;
|
||||||
|
const cwd = "/test/bootstrap-existing";
|
||||||
|
|
||||||
|
server = await createTestServer({
|
||||||
|
cwd,
|
||||||
|
stateDir,
|
||||||
|
persistenceLayer,
|
||||||
|
autoBootstrapProjectFromCwd: true,
|
||||||
|
});
|
||||||
|
let addr = server.address();
|
||||||
|
let port = typeof addr === "object" && addr !== null ? addr.port : 0;
|
||||||
|
expect(port).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
const firstWs = await connectWs(port);
|
||||||
|
connections.push(firstWs);
|
||||||
|
const firstWelcome = (await waitForMessage(firstWs)) as WsPush;
|
||||||
|
const firstBootstrapProjectId = (firstWelcome.data as { bootstrapProjectId?: string })
|
||||||
|
.bootstrapProjectId;
|
||||||
|
const firstBootstrapThreadId = (firstWelcome.data as { bootstrapThreadId?: string })
|
||||||
|
.bootstrapThreadId;
|
||||||
|
expect(firstBootstrapProjectId).toBeDefined();
|
||||||
|
expect(firstBootstrapThreadId).toBeDefined();
|
||||||
|
|
||||||
|
firstWs.close();
|
||||||
|
await closeTestServer();
|
||||||
|
server = null;
|
||||||
|
|
||||||
|
server = await createTestServer({
|
||||||
|
cwd,
|
||||||
|
stateDir,
|
||||||
|
persistenceLayer,
|
||||||
|
autoBootstrapProjectFromCwd: true,
|
||||||
|
});
|
||||||
|
addr = server.address();
|
||||||
|
port = typeof addr === "object" && addr !== null ? addr.port : 0;
|
||||||
|
expect(port).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
const secondWs = await connectWs(port);
|
||||||
|
connections.push(secondWs);
|
||||||
|
const secondWelcome = (await waitForMessage(secondWs)) as WsPush;
|
||||||
|
expect(secondWelcome.channel).toBe(WS_CHANNELS.serverWelcome);
|
||||||
|
expect(secondWelcome.data).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
cwd,
|
||||||
|
projectName: "bootstrap-existing",
|
||||||
|
bootstrapProjectId: firstBootstrapProjectId,
|
||||||
|
bootstrapThreadId: firstBootstrapThreadId,
|
||||||
|
}),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("logs outbound websocket push events in dev mode", async () => {
|
it("logs outbound websocket push events in dev mode", async () => {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
ORCHESTRATION_WS_CHANNELS,
|
ORCHESTRATION_WS_CHANNELS,
|
||||||
ORCHESTRATION_WS_METHODS,
|
ORCHESTRATION_WS_METHODS,
|
||||||
ProjectId,
|
ProjectId,
|
||||||
|
ThreadId,
|
||||||
TerminalEvent,
|
TerminalEvent,
|
||||||
WS_CHANNELS,
|
WS_CHANNELS,
|
||||||
WS_METHODS,
|
WS_METHODS,
|
||||||
@@ -337,22 +338,59 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
|||||||
|
|
||||||
yield* Scope.provide(orchestrationReactor.start, subscriptionsScope);
|
yield* Scope.provide(orchestrationReactor.start, subscriptionsScope);
|
||||||
|
|
||||||
|
let welcomeBootstrapProjectId: ProjectId | undefined;
|
||||||
|
let welcomeBootstrapThreadId: ThreadId | undefined;
|
||||||
|
|
||||||
if (autoBootstrapProjectFromCwd) {
|
if (autoBootstrapProjectFromCwd) {
|
||||||
yield* Effect.gen(function* () {
|
yield* Effect.gen(function* () {
|
||||||
const snapshot = yield* projectionReadModelQuery.getSnapshot();
|
const snapshot = yield* projectionReadModelQuery.getSnapshot();
|
||||||
const existing = snapshot.projects.find((project) => project.workspaceRoot === cwd);
|
const existingProject = snapshot.projects.find(
|
||||||
if (!existing) {
|
(project) => project.workspaceRoot === cwd && project.deletedAt === null,
|
||||||
|
);
|
||||||
|
let bootstrapProjectId: ProjectId;
|
||||||
|
let bootstrapProjectDefaultModel: string;
|
||||||
|
|
||||||
|
if (!existingProject) {
|
||||||
const createdAt = new Date().toISOString();
|
const createdAt = new Date().toISOString();
|
||||||
const projectName = path.basename(cwd) || "project";
|
bootstrapProjectId = ProjectId.makeUnsafe(crypto.randomUUID());
|
||||||
|
const bootstrapProjectTitle = path.basename(cwd) || "project";
|
||||||
|
bootstrapProjectDefaultModel = "gpt-5-codex";
|
||||||
yield* orchestrationEngine.dispatch({
|
yield* orchestrationEngine.dispatch({
|
||||||
type: "project.create",
|
type: "project.create",
|
||||||
commandId: CommandId.makeUnsafe(crypto.randomUUID()),
|
commandId: CommandId.makeUnsafe(crypto.randomUUID()),
|
||||||
projectId: ProjectId.makeUnsafe(crypto.randomUUID()),
|
projectId: bootstrapProjectId,
|
||||||
title: projectName,
|
title: bootstrapProjectTitle,
|
||||||
workspaceRoot: cwd,
|
workspaceRoot: cwd,
|
||||||
defaultModel: "gpt-5-codex",
|
defaultModel: bootstrapProjectDefaultModel,
|
||||||
createdAt,
|
createdAt,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
bootstrapProjectId = existingProject.id;
|
||||||
|
bootstrapProjectDefaultModel = existingProject.defaultModel ?? "gpt-5-codex";
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingThread = snapshot.threads.find(
|
||||||
|
(thread) => thread.projectId === bootstrapProjectId && thread.deletedAt === null,
|
||||||
|
);
|
||||||
|
if (!existingThread) {
|
||||||
|
const createdAt = new Date().toISOString();
|
||||||
|
const threadId = ThreadId.makeUnsafe(crypto.randomUUID());
|
||||||
|
yield* orchestrationEngine.dispatch({
|
||||||
|
type: "thread.create",
|
||||||
|
commandId: CommandId.makeUnsafe(crypto.randomUUID()),
|
||||||
|
threadId,
|
||||||
|
projectId: bootstrapProjectId,
|
||||||
|
title: "New thread",
|
||||||
|
model: bootstrapProjectDefaultModel,
|
||||||
|
branch: null,
|
||||||
|
worktreePath: null,
|
||||||
|
createdAt,
|
||||||
|
});
|
||||||
|
welcomeBootstrapProjectId = bootstrapProjectId;
|
||||||
|
welcomeBootstrapThreadId = threadId;
|
||||||
|
} else {
|
||||||
|
welcomeBootstrapProjectId = bootstrapProjectId;
|
||||||
|
welcomeBootstrapThreadId = existingThread.id;
|
||||||
}
|
}
|
||||||
}).pipe(
|
}).pipe(
|
||||||
Effect.mapError(
|
Effect.mapError(
|
||||||
@@ -581,7 +619,12 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
|||||||
const welcome: WsPush = {
|
const welcome: WsPush = {
|
||||||
type: "push",
|
type: "push",
|
||||||
channel: WS_CHANNELS.serverWelcome,
|
channel: WS_CHANNELS.serverWelcome,
|
||||||
data: { cwd, projectName },
|
data: {
|
||||||
|
cwd,
|
||||||
|
projectName,
|
||||||
|
...(welcomeBootstrapProjectId ? { bootstrapProjectId: welcomeBootstrapProjectId } : {}),
|
||||||
|
...(welcomeBootstrapThreadId ? { bootstrapThreadId: welcomeBootstrapThreadId } : {}),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
logOutgoingPush(welcome, 1);
|
logOutgoingPush(welcome, 1);
|
||||||
ws.send(JSON.stringify(welcome));
|
ws.send(JSON.stringify(welcome));
|
||||||
|
|||||||
@@ -368,6 +368,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||||
const composerCommandInputRef = useRef<HTMLInputElement>(null);
|
const composerCommandInputRef = useRef<HTMLInputElement>(null);
|
||||||
const composerImagesRef = useRef<ComposerImageAttachment[]>([]);
|
const composerImagesRef = useRef<ComposerImageAttachment[]>([]);
|
||||||
|
const sendInFlightRef = useRef(false);
|
||||||
const dragDepthRef = useRef(0);
|
const dragDepthRef = useRef(0);
|
||||||
const terminalOpenByThreadRef = useRef<Record<string, boolean>>({});
|
const terminalOpenByThreadRef = useRef<Record<string, boolean>>({});
|
||||||
|
|
||||||
@@ -1391,7 +1392,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
const onSend = async (e: React.SubmitEvent | React.KeyboardEvent) => {
|
const onSend = async (e: React.SubmitEvent | React.KeyboardEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const api = readNativeApi();
|
const api = readNativeApi();
|
||||||
if (!api || !activeThread || isSendBusy || isConnecting) return;
|
if (!api || !activeThread || isSendBusy || isConnecting || sendInFlightRef.current) return;
|
||||||
const trimmed = prompt.trim();
|
const trimmed = prompt.trim();
|
||||||
if (!trimmed && composerImages.length === 0) return;
|
if (!trimmed && composerImages.length === 0) return;
|
||||||
if (!activeProject) return;
|
if (!activeProject) return;
|
||||||
@@ -1401,6 +1402,23 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
isFirstMessage && envMode === "worktree" && !activeThread.worktreePath
|
isFirstMessage && envMode === "worktree" && !activeThread.worktreePath
|
||||||
? activeThread.branch
|
? activeThread.branch
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
// In worktree mode, require an explicit base branch so we don't silently
|
||||||
|
// fall back to local execution when branch selection is missing.
|
||||||
|
const shouldCreateWorktree =
|
||||||
|
isFirstMessage && envMode === "worktree" && !activeThread.worktreePath;
|
||||||
|
if (shouldCreateWorktree && !activeThread.branch) {
|
||||||
|
dispatch({
|
||||||
|
type: "SET_ERROR",
|
||||||
|
threadId: threadIdForSend,
|
||||||
|
error: "Select a base branch before sending in New worktree mode.",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendInFlightRef.current = true;
|
||||||
|
setSendPhase(baseBranchForWorktree ? "preparing-worktree" : "sending-turn");
|
||||||
|
|
||||||
const composerImagesSnapshot = [...composerImages];
|
const composerImagesSnapshot = [...composerImages];
|
||||||
const messageIdForSend = newMessageId();
|
const messageIdForSend = newMessageId();
|
||||||
const messageCreatedAt = new Date().toISOString();
|
const messageCreatedAt = new Date().toISOString();
|
||||||
@@ -1449,9 +1467,17 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
branch: result.worktree.branch,
|
branch: result.worktree.branch,
|
||||||
worktreePath: result.worktree.path,
|
worktreePath: result.worktree.path,
|
||||||
});
|
});
|
||||||
|
// Keep local thread state in sync immediately so terminal drawer opens
|
||||||
|
// with the worktree cwd/env instead of briefly using the project root.
|
||||||
|
dispatch({
|
||||||
|
type: "SET_THREAD_BRANCH",
|
||||||
|
threadId: threadIdForSend,
|
||||||
|
branch: result.worktree.branch,
|
||||||
|
worktreePath: result.worktree.path,
|
||||||
|
});
|
||||||
const setupScript = setupProjectScript(activeProject.scripts);
|
const setupScript = setupProjectScript(activeProject.scripts);
|
||||||
if (setupScript) {
|
if (setupScript) {
|
||||||
void runProjectScript(setupScript, {
|
await runProjectScript(setupScript, {
|
||||||
cwd: result.worktree.path,
|
cwd: result.worktree.path,
|
||||||
worktreePath: result.worktree.path,
|
worktreePath: result.worktree.path,
|
||||||
rememberAsLastInvoked: false,
|
rememberAsLastInvoked: false,
|
||||||
@@ -1530,6 +1556,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
|||||||
err instanceof Error ? err.message : "Failed to send message.",
|
err instanceof Error ? err.message : "Failed to send message.",
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
|
sendInFlightRef.current = false;
|
||||||
setSendPhase("idle");
|
setSendPhase("idle");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import { ThreadId } from "@t3tools/contracts";
|
import { ThreadId } from "@t3tools/contracts";
|
||||||
import { Outlet, createRootRouteWithContext, type ErrorComponentProps } from "@tanstack/react-router";
|
import {
|
||||||
|
Outlet,
|
||||||
|
createRootRouteWithContext,
|
||||||
|
type ErrorComponentProps,
|
||||||
|
useNavigate,
|
||||||
|
useRouterState,
|
||||||
|
} from "@tanstack/react-router";
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { QueryClient, useQueryClient } from "@tanstack/react-query";
|
import { QueryClient, useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
@@ -119,7 +125,12 @@ function errorDetails(error: unknown): string {
|
|||||||
function EventRouter() {
|
function EventRouter() {
|
||||||
const { dispatch } = useStore();
|
const { dispatch } = useStore();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const pathname = useRouterState({ select: (state) => state.location.pathname });
|
||||||
|
const pathnameRef = useRef(pathname);
|
||||||
const lastConfigIssuesSignatureRef = useRef<string | null>(null);
|
const lastConfigIssuesSignatureRef = useRef<string | null>(null);
|
||||||
|
const handledBootstrapThreadIdRef = useRef<string | null>(null);
|
||||||
|
pathnameRef.current = pathname;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const api = readNativeApi();
|
const api = readNativeApi();
|
||||||
@@ -180,8 +191,35 @@ function EventRouter() {
|
|||||||
hasRunningSubprocess,
|
hasRunningSubprocess,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const unsubWelcome = onServerWelcome(() => {
|
const unsubWelcome = onServerWelcome((payload) => {
|
||||||
void syncSnapshot();
|
void (async () => {
|
||||||
|
await syncSnapshot();
|
||||||
|
if (disposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!payload.bootstrapProjectId || !payload.bootstrapThreadId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dispatch({
|
||||||
|
type: "SET_PROJECT_EXPANDED",
|
||||||
|
projectId: payload.bootstrapProjectId,
|
||||||
|
expanded: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (pathnameRef.current !== "/") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (handledBootstrapThreadIdRef.current === payload.bootstrapThreadId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await navigate({
|
||||||
|
to: "/$threadId",
|
||||||
|
params: { threadId: payload.bootstrapThreadId },
|
||||||
|
replace: true,
|
||||||
|
});
|
||||||
|
handledBootstrapThreadIdRef.current = payload.bootstrapThreadId;
|
||||||
|
})().catch(() => undefined);
|
||||||
});
|
});
|
||||||
const unsubServerConfigUpdated = onServerConfigUpdated((payload) => {
|
const unsubServerConfigUpdated = onServerConfigUpdated((payload) => {
|
||||||
const signature = JSON.stringify(payload.issues);
|
const signature = JSON.stringify(payload.issues);
|
||||||
@@ -232,7 +270,7 @@ function EventRouter() {
|
|||||||
unsubWelcome();
|
unsubWelcome();
|
||||||
unsubServerConfigUpdated();
|
unsubServerConfigUpdated();
|
||||||
};
|
};
|
||||||
}, [dispatch, queryClient]);
|
}, [dispatch, navigate, queryClient]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ type Action =
|
|||||||
terminalId: string;
|
terminalId: string;
|
||||||
hasRunningSubprocess: boolean;
|
hasRunningSubprocess: boolean;
|
||||||
}
|
}
|
||||||
|
| { type: "SET_PROJECT_EXPANDED"; projectId: Project["id"]; expanded: boolean }
|
||||||
| { type: "TOGGLE_THREAD_TERMINAL"; threadId: ThreadId }
|
| { type: "TOGGLE_THREAD_TERMINAL"; threadId: ThreadId }
|
||||||
| { type: "SET_THREAD_TERMINAL_OPEN"; threadId: ThreadId; open: boolean }
|
| { type: "SET_THREAD_TERMINAL_OPEN"; threadId: ThreadId; open: boolean }
|
||||||
| { type: "SET_THREAD_TERMINAL_HEIGHT"; threadId: ThreadId; height: number }
|
| { type: "SET_THREAD_TERMINAL_HEIGHT"; threadId: ThreadId; height: number }
|
||||||
@@ -571,6 +572,14 @@ export function reducer(state: AppState, action: Action): AppState {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
case "SET_PROJECT_EXPANDED":
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
projects: state.projects.map((p) =>
|
||||||
|
p.id === action.projectId ? { ...p, expanded: action.expanded } : p,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
case "TOGGLE_THREAD_TERMINAL":
|
case "TOGGLE_THREAD_TERMINAL":
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|||||||
@@ -65,16 +65,41 @@ describe("wsNativeApi", () => {
|
|||||||
emitPush(WS_CHANNELS.serverWelcome, payload);
|
emitPush(WS_CHANNELS.serverWelcome, payload);
|
||||||
|
|
||||||
expect(listener).toHaveBeenCalledTimes(1);
|
expect(listener).toHaveBeenCalledTimes(1);
|
||||||
expect(listener).toHaveBeenCalledWith(payload);
|
expect(listener).toHaveBeenCalledWith(expect.objectContaining(payload));
|
||||||
|
|
||||||
const lateListener = vi.fn();
|
const lateListener = vi.fn();
|
||||||
onServerWelcome(lateListener);
|
onServerWelcome(lateListener);
|
||||||
|
|
||||||
expect(lateListener).toHaveBeenCalledTimes(1);
|
expect(lateListener).toHaveBeenCalledTimes(1);
|
||||||
expect(lateListener).toHaveBeenCalledWith(payload);
|
expect(lateListener).toHaveBeenCalledWith(expect.objectContaining(payload));
|
||||||
expect(warnSpy).not.toHaveBeenCalled();
|
expect(warnSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("preserves bootstrap ids from server.welcome payloads", async () => {
|
||||||
|
const { createWsNativeApi, onServerWelcome } = await import("./wsNativeApi");
|
||||||
|
|
||||||
|
createWsNativeApi();
|
||||||
|
const listener = vi.fn();
|
||||||
|
onServerWelcome(listener);
|
||||||
|
|
||||||
|
emitPush(WS_CHANNELS.serverWelcome, {
|
||||||
|
cwd: "/tmp/workspace",
|
||||||
|
projectName: "t3-code",
|
||||||
|
bootstrapProjectId: "project-1",
|
||||||
|
bootstrapThreadId: "thread-1",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(listener).toHaveBeenCalledTimes(1);
|
||||||
|
expect(listener).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
cwd: "/tmp/workspace",
|
||||||
|
projectName: "t3-code",
|
||||||
|
bootstrapProjectId: "project-1",
|
||||||
|
bootstrapThreadId: "thread-1",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("ignores invalid server.welcome payloads and keeps subscription active", async () => {
|
it("ignores invalid server.welcome payloads and keeps subscription active", async () => {
|
||||||
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||||
const { createWsNativeApi, onServerWelcome } = await import("./wsNativeApi");
|
const { createWsNativeApi, onServerWelcome } = await import("./wsNativeApi");
|
||||||
@@ -87,7 +112,9 @@ describe("wsNativeApi", () => {
|
|||||||
emitPush(WS_CHANNELS.serverWelcome, { cwd: "/tmp/workspace", projectName: "t3-code" });
|
emitPush(WS_CHANNELS.serverWelcome, { cwd: "/tmp/workspace", projectName: "t3-code" });
|
||||||
|
|
||||||
expect(listener).toHaveBeenCalledTimes(1);
|
expect(listener).toHaveBeenCalledTimes(1);
|
||||||
expect(listener).toHaveBeenCalledWith({ cwd: "/tmp/workspace", projectName: "t3-code" });
|
expect(listener).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ cwd: "/tmp/workspace", projectName: "t3-code" }),
|
||||||
|
);
|
||||||
expect(warnSpy).toHaveBeenCalledTimes(1);
|
expect(warnSpy).toHaveBeenCalledTimes(1);
|
||||||
expect(warnSpy).toHaveBeenCalledWith("Dropped inbound WebSocket push payload", {
|
expect(warnSpy).toHaveBeenCalledWith("Dropped inbound WebSocket push payload", {
|
||||||
reason: "decode-failed",
|
reason: "decode-failed",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Schema, Struct } from "effect";
|
import { Schema, Struct } from "effect";
|
||||||
import { TrimmedNonEmptyString } from "./baseSchemas";
|
import { ProjectId, ThreadId, TrimmedNonEmptyString } from "./baseSchemas";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ClientOrchestrationCommand,
|
ClientOrchestrationCommand,
|
||||||
@@ -163,5 +163,7 @@ export type WsResponse = typeof WsResponse.Type;
|
|||||||
export const WsWelcomePayload = Schema.Struct({
|
export const WsWelcomePayload = Schema.Struct({
|
||||||
cwd: TrimmedNonEmptyString,
|
cwd: TrimmedNonEmptyString,
|
||||||
projectName: TrimmedNonEmptyString,
|
projectName: TrimmedNonEmptyString,
|
||||||
|
bootstrapProjectId: Schema.optional(ProjectId),
|
||||||
|
bootstrapThreadId: Schema.optional(ThreadId),
|
||||||
});
|
});
|
||||||
export type WsWelcomePayload = typeof WsWelcomePayload.Type;
|
export type WsWelcomePayload = typeof WsWelcomePayload.Type;
|
||||||
Reference in new issue
Block a user