chore: effect rpc and layer based startup (#929)

Co-authored-by: codex <[email protected]>
Co-authored-by: Cursor Agent <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-03-31 23:58:35 -07:00
1 parent 64d6938cf4
commit d8aa2f85df
116 files changed
+6706 -6678

No files matched your search

+5
View File
@@ -24,3 +24,8 @@ export const OpenInEditorInput = Schema.Struct({
editor: EditorId,
});
export type OpenInEditorInput = typeof OpenInEditorInput.Type;
export class OpenError extends Schema.TaggedErrorClass<OpenError>()("OpenError", {
message: Schema.String,
cause: Schema.optional(Schema.Defect),
}) {}
+54
View File
@@ -223,6 +223,60 @@ export const GitPullResult = Schema.Struct({
});
export type GitPullResult = typeof GitPullResult.Type;
// RPC / domain errors
export class GitCommandError extends Schema.TaggedErrorClass<GitCommandError>()("GitCommandError", {
operation: Schema.String,
command: Schema.String,
cwd: Schema.String,
detail: Schema.String,
cause: Schema.optional(Schema.Defect),
}) {
override get message(): string {
return `Git command failed in ${this.operation}: ${this.command} (${this.cwd}) - ${this.detail}`;
}
}
export class GitHubCliError extends Schema.TaggedErrorClass<GitHubCliError>()("GitHubCliError", {
operation: Schema.String,
detail: Schema.String,
cause: Schema.optional(Schema.Defect),
}) {
override get message(): string {
return `GitHub CLI failed in ${this.operation}: ${this.detail}`;
}
}
export class TextGenerationError extends Schema.TaggedErrorClass<TextGenerationError>()(
"TextGenerationError",
{
operation: Schema.String,
detail: Schema.String,
cause: Schema.optional(Schema.Defect),
},
) {
override get message(): string {
return `Text generation failed in ${this.operation}: ${this.detail}`;
}
}
export class GitManagerError extends Schema.TaggedErrorClass<GitManagerError>()("GitManagerError", {
operation: Schema.String,
detail: Schema.String,
cause: Schema.optional(Schema.Defect),
}) {
override get message(): string {
return `Git manager failed in ${this.operation}: ${this.detail}`;
}
}
export const GitManagerServiceError = Schema.Union([
GitManagerError,
GitCommandError,
GitHubCliError,
TextGenerationError,
]);
export type GitManagerServiceError = typeof GitManagerServiceError.Type;
const GitActionProgressBase = Schema.Struct({
actionId: TrimmedNonEmptyStringSchema,
cwd: TrimmedNonEmptyStringSchema,
+1 -1
View File
@@ -4,7 +4,6 @@ export * from "./terminal";
export * from "./provider";
export * from "./providerRuntime";
export * from "./model";
export * from "./ws";
export * from "./keybindings";
export * from "./server";
export * from "./settings";
@@ -12,3 +11,4 @@ export * from "./git";
export * from "./orchestration";
export * from "./editor";
export * from "./project";
export * from "./rpc";
-5
View File
@@ -1,6 +1,5 @@
import type {
GitCheckoutInput,
GitActionProgressEvent,
GitCreateBranchInput,
GitPreparePullRequestThreadInput,
GitPreparePullRequestThreadResult,
@@ -14,8 +13,6 @@ import type {
GitPullResult,
GitRemoveWorktreeInput,
GitResolvePullRequestResult,
GitRunStackedActionInput,
GitRunStackedActionResult,
GitStatusInput,
GitStatusResult,
} from "./git";
@@ -161,8 +158,6 @@ export interface NativeApi {
// Stacked action API
pull: (input: GitPullInput) => Promise<GitPullResult>;
status: (input: GitStatusInput) => Promise<GitStatusResult>;
runStackedAction: (input: GitRunStackedActionInput) => Promise<GitRunStackedActionResult>;
onActionProgress: (callback: (event: GitActionProgressEvent) => void) => () => void;
};
contextMenu: {
show: <T extends string>(
+22 -6
View File
@@ -85,24 +85,27 @@ export const KeybindingShortcut = Schema.Struct({
});
export type KeybindingShortcut = typeof KeybindingShortcut.Type;
export const KeybindingWhenNode: Schema.Schema<KeybindingWhenNode> = Schema.Union([
const KeybindingWhenNodeRef = Schema.suspend(
(): Schema.Codec<KeybindingWhenNode> => KeybindingWhenNode,
);
export const KeybindingWhenNode = Schema.Union([
Schema.Struct({
type: Schema.Literal("identifier"),
name: Schema.NonEmptyString,
}),
Schema.Struct({
type: Schema.Literal("not"),
node: Schema.suspend((): Schema.Schema<KeybindingWhenNode> => KeybindingWhenNode),
node: KeybindingWhenNodeRef,
}),
Schema.Struct({
type: Schema.Literal("and"),
left: Schema.suspend((): Schema.Schema<KeybindingWhenNode> => KeybindingWhenNode),
right: Schema.suspend((): Schema.Schema<KeybindingWhenNode> => KeybindingWhenNode),
left: KeybindingWhenNodeRef,
right: KeybindingWhenNodeRef,
}),
Schema.Struct({
type: Schema.Literal("or"),
left: Schema.suspend((): Schema.Schema<KeybindingWhenNode> => KeybindingWhenNode),
right: Schema.suspend((): Schema.Schema<KeybindingWhenNode> => KeybindingWhenNode),
left: KeybindingWhenNodeRef,
right: KeybindingWhenNodeRef,
}),
]);
export type KeybindingWhenNode =
@@ -122,3 +125,16 @@ export const ResolvedKeybindingsConfig = Schema.Array(ResolvedKeybindingRule).ch
Schema.isMaxLength(MAX_KEYBINDINGS_COUNT),
);
export type ResolvedKeybindingsConfig = typeof ResolvedKeybindingsConfig.Type;
export class KeybindingsConfigError extends Schema.TaggedErrorClass<KeybindingsConfigError>()(
"KeybindingsConfigParseError",
{
configPath: Schema.String,
detail: Schema.String,
cause: Schema.optional(Schema.Defect),
},
) {
override get message(): string {
return `Unable to parse keybindings config at ${this.configPath}: ${this.detail}`;
}
}
+40 -4
View File
@@ -23,10 +23,6 @@ export const ORCHESTRATION_WS_METHODS = {
replayEvents: "orchestration.replayEvents",
} as const;
export const ORCHESTRATION_WS_CHANNELS = {
domainEvent: "orchestration.domainEvent",
} as const;
export const ProviderKind = Schema.Literals(["codex", "claudeAgent"]);
export type ProviderKind = typeof ProviderKind.Type;
export const ProviderApprovalPolicy = Schema.Literals([
@@ -1037,3 +1033,43 @@ export const OrchestrationRpcSchemas = {
output: OrchestrationReplayEventsResult,
},
} as const;
export class OrchestrationGetSnapshotError extends Schema.TaggedErrorClass<OrchestrationGetSnapshotError>()(
"OrchestrationGetSnapshotError",
{
message: TrimmedNonEmptyString,
cause: Schema.optional(Schema.Defect),
},
) {}
export class OrchestrationDispatchCommandError extends Schema.TaggedErrorClass<OrchestrationDispatchCommandError>()(
"OrchestrationDispatchCommandError",
{
message: TrimmedNonEmptyString,
cause: Schema.optional(Schema.Defect),
},
) {}
export class OrchestrationGetTurnDiffError extends Schema.TaggedErrorClass<OrchestrationGetTurnDiffError>()(
"OrchestrationGetTurnDiffError",
{
message: TrimmedNonEmptyString,
cause: Schema.optional(Schema.Defect),
},
) {}
export class OrchestrationGetFullThreadDiffError extends Schema.TaggedErrorClass<OrchestrationGetFullThreadDiffError>()(
"OrchestrationGetFullThreadDiffError",
{
message: TrimmedNonEmptyString,
cause: Schema.optional(Schema.Defect),
},
) {}
export class OrchestrationReplayEventsError extends Schema.TaggedErrorClass<OrchestrationReplayEventsError>()(
"OrchestrationReplayEventsError",
{
message: TrimmedNonEmptyString,
cause: Schema.optional(Schema.Defect),
},
) {}
+16
View File
@@ -26,6 +26,14 @@ export const ProjectSearchEntriesResult = Schema.Struct({
});
export type ProjectSearchEntriesResult = typeof ProjectSearchEntriesResult.Type;
export class ProjectSearchEntriesError extends Schema.TaggedErrorClass<ProjectSearchEntriesError>()(
"ProjectSearchEntriesError",
{
message: TrimmedNonEmptyString,
cause: Schema.optional(Schema.Defect),
},
) {}
export const ProjectWriteFileInput = Schema.Struct({
cwd: TrimmedNonEmptyString,
relativePath: TrimmedNonEmptyString.check(Schema.isMaxLength(PROJECT_WRITE_FILE_PATH_MAX_LENGTH)),
@@ -37,3 +45,11 @@ export const ProjectWriteFileResult = Schema.Struct({
relativePath: TrimmedNonEmptyString,
});
export type ProjectWriteFileResult = typeof ProjectWriteFileResult.Type;
export class ProjectWriteFileError extends Schema.TaggedErrorClass<ProjectWriteFileError>()(
"ProjectWriteFileError",
{
message: TrimmedNonEmptyString,
cause: Schema.optional(Schema.Defect),
},
) {}
+359
View File
@@ -0,0 +1,359 @@
import { Schema } from "effect";
import * as Rpc from "effect/unstable/rpc/Rpc";
import * as RpcGroup from "effect/unstable/rpc/RpcGroup";
import { OpenError, OpenInEditorInput } from "./editor";
import {
GitActionProgressEvent,
GitCheckoutInput,
GitCommandError,
GitCreateBranchInput,
GitCreateWorktreeInput,
GitCreateWorktreeResult,
GitInitInput,
GitListBranchesInput,
GitListBranchesResult,
GitManagerServiceError,
GitPreparePullRequestThreadInput,
GitPreparePullRequestThreadResult,
GitPullInput,
GitPullRequestRefInput,
GitPullResult,
GitRemoveWorktreeInput,
GitResolvePullRequestResult,
GitRunStackedActionInput,
GitStatusInput,
GitStatusResult,
} from "./git";
import { KeybindingsConfigError } from "./keybindings";
import {
ClientOrchestrationCommand,
OrchestrationEvent,
ORCHESTRATION_WS_METHODS,
OrchestrationDispatchCommandError,
OrchestrationGetFullThreadDiffError,
OrchestrationGetFullThreadDiffInput,
OrchestrationGetSnapshotError,
OrchestrationGetSnapshotInput,
OrchestrationGetTurnDiffError,
OrchestrationGetTurnDiffInput,
OrchestrationReplayEventsError,
OrchestrationReplayEventsInput,
OrchestrationRpcSchemas,
} from "./orchestration";
import {
ProjectSearchEntriesError,
ProjectSearchEntriesInput,
ProjectSearchEntriesResult,
ProjectWriteFileError,
ProjectWriteFileInput,
ProjectWriteFileResult,
} from "./project";
import {
TerminalClearInput,
TerminalCloseInput,
TerminalError,
TerminalEvent,
TerminalOpenInput,
TerminalResizeInput,
TerminalRestartInput,
TerminalSessionSnapshot,
TerminalWriteInput,
} from "./terminal";
import {
ServerConfigStreamEvent,
ServerConfig,
ServerLifecycleStreamEvent,
ServerProviderUpdatedPayload,
ServerUpsertKeybindingInput,
ServerUpsertKeybindingResult,
} from "./server";
import { ServerSettings, ServerSettingsError, ServerSettingsPatch } from "./settings";
export const WS_METHODS = {
// Project registry methods
projectsList: "projects.list",
projectsAdd: "projects.add",
projectsRemove: "projects.remove",
projectsSearchEntries: "projects.searchEntries",
projectsWriteFile: "projects.writeFile",
// Shell methods
shellOpenInEditor: "shell.openInEditor",
// Git methods
gitPull: "git.pull",
gitStatus: "git.status",
gitRunStackedAction: "git.runStackedAction",
gitListBranches: "git.listBranches",
gitCreateWorktree: "git.createWorktree",
gitRemoveWorktree: "git.removeWorktree",
gitCreateBranch: "git.createBranch",
gitCheckout: "git.checkout",
gitInit: "git.init",
gitResolvePullRequest: "git.resolvePullRequest",
gitPreparePullRequestThread: "git.preparePullRequestThread",
// Terminal methods
terminalOpen: "terminal.open",
terminalWrite: "terminal.write",
terminalResize: "terminal.resize",
terminalClear: "terminal.clear",
terminalRestart: "terminal.restart",
terminalClose: "terminal.close",
// Server meta
serverGetConfig: "server.getConfig",
serverRefreshProviders: "server.refreshProviders",
serverUpsertKeybinding: "server.upsertKeybinding",
serverGetSettings: "server.getSettings",
serverUpdateSettings: "server.updateSettings",
// Streaming subscriptions
subscribeOrchestrationDomainEvents: "subscribeOrchestrationDomainEvents",
subscribeTerminalEvents: "subscribeTerminalEvents",
subscribeServerConfig: "subscribeServerConfig",
subscribeServerLifecycle: "subscribeServerLifecycle",
} as const;
export const WsServerUpsertKeybindingRpc = Rpc.make(WS_METHODS.serverUpsertKeybinding, {
payload: ServerUpsertKeybindingInput,
success: ServerUpsertKeybindingResult,
error: KeybindingsConfigError,
});
export const WsServerGetConfigRpc = Rpc.make(WS_METHODS.serverGetConfig, {
payload: Schema.Struct({}),
success: ServerConfig,
error: Schema.Union([KeybindingsConfigError, ServerSettingsError]),
});
export const WsServerRefreshProvidersRpc = Rpc.make(WS_METHODS.serverRefreshProviders, {
payload: Schema.Struct({}),
success: ServerProviderUpdatedPayload,
});
export const WsServerGetSettingsRpc = Rpc.make(WS_METHODS.serverGetSettings, {
payload: Schema.Struct({}),
success: ServerSettings,
error: ServerSettingsError,
});
export const WsServerUpdateSettingsRpc = Rpc.make(WS_METHODS.serverUpdateSettings, {
payload: Schema.Struct({ patch: ServerSettingsPatch }),
success: ServerSettings,
error: ServerSettingsError,
});
export const WsProjectsSearchEntriesRpc = Rpc.make(WS_METHODS.projectsSearchEntries, {
payload: ProjectSearchEntriesInput,
success: ProjectSearchEntriesResult,
error: ProjectSearchEntriesError,
});
export const WsProjectsWriteFileRpc = Rpc.make(WS_METHODS.projectsWriteFile, {
payload: ProjectWriteFileInput,
success: ProjectWriteFileResult,
error: ProjectWriteFileError,
});
export const WsShellOpenInEditorRpc = Rpc.make(WS_METHODS.shellOpenInEditor, {
payload: OpenInEditorInput,
error: OpenError,
});
export const WsGitStatusRpc = Rpc.make(WS_METHODS.gitStatus, {
payload: GitStatusInput,
success: GitStatusResult,
error: GitManagerServiceError,
});
export const WsGitPullRpc = Rpc.make(WS_METHODS.gitPull, {
payload: GitPullInput,
success: GitPullResult,
error: GitCommandError,
});
export const WsGitRunStackedActionRpc = Rpc.make(WS_METHODS.gitRunStackedAction, {
payload: GitRunStackedActionInput,
success: GitActionProgressEvent,
error: GitManagerServiceError,
stream: true,
});
export const WsGitResolvePullRequestRpc = Rpc.make(WS_METHODS.gitResolvePullRequest, {
payload: GitPullRequestRefInput,
success: GitResolvePullRequestResult,
error: GitManagerServiceError,
});
export const WsGitPreparePullRequestThreadRpc = Rpc.make(WS_METHODS.gitPreparePullRequestThread, {
payload: GitPreparePullRequestThreadInput,
success: GitPreparePullRequestThreadResult,
error: GitManagerServiceError,
});
export const WsGitListBranchesRpc = Rpc.make(WS_METHODS.gitListBranches, {
payload: GitListBranchesInput,
success: GitListBranchesResult,
error: GitCommandError,
});
export const WsGitCreateWorktreeRpc = Rpc.make(WS_METHODS.gitCreateWorktree, {
payload: GitCreateWorktreeInput,
success: GitCreateWorktreeResult,
error: GitCommandError,
});
export const WsGitRemoveWorktreeRpc = Rpc.make(WS_METHODS.gitRemoveWorktree, {
payload: GitRemoveWorktreeInput,
error: GitCommandError,
});
export const WsGitCreateBranchRpc = Rpc.make(WS_METHODS.gitCreateBranch, {
payload: GitCreateBranchInput,
error: GitCommandError,
});
export const WsGitCheckoutRpc = Rpc.make(WS_METHODS.gitCheckout, {
payload: GitCheckoutInput,
error: GitCommandError,
});
export const WsGitInitRpc = Rpc.make(WS_METHODS.gitInit, {
payload: GitInitInput,
error: GitCommandError,
});
export const WsTerminalOpenRpc = Rpc.make(WS_METHODS.terminalOpen, {
payload: TerminalOpenInput,
success: TerminalSessionSnapshot,
error: TerminalError,
});
export const WsTerminalWriteRpc = Rpc.make(WS_METHODS.terminalWrite, {
payload: TerminalWriteInput,
error: TerminalError,
});
export const WsTerminalResizeRpc = Rpc.make(WS_METHODS.terminalResize, {
payload: TerminalResizeInput,
error: TerminalError,
});
export const WsTerminalClearRpc = Rpc.make(WS_METHODS.terminalClear, {
payload: TerminalClearInput,
error: TerminalError,
});
export const WsTerminalRestartRpc = Rpc.make(WS_METHODS.terminalRestart, {
payload: TerminalRestartInput,
success: TerminalSessionSnapshot,
error: TerminalError,
});
export const WsTerminalCloseRpc = Rpc.make(WS_METHODS.terminalClose, {
payload: TerminalCloseInput,
error: TerminalError,
});
export const WsOrchestrationGetSnapshotRpc = Rpc.make(ORCHESTRATION_WS_METHODS.getSnapshot, {
payload: OrchestrationGetSnapshotInput,
success: OrchestrationRpcSchemas.getSnapshot.output,
error: OrchestrationGetSnapshotError,
});
export const WsOrchestrationDispatchCommandRpc = Rpc.make(
ORCHESTRATION_WS_METHODS.dispatchCommand,
{
payload: ClientOrchestrationCommand,
success: OrchestrationRpcSchemas.dispatchCommand.output,
error: OrchestrationDispatchCommandError,
},
);
export const WsOrchestrationGetTurnDiffRpc = Rpc.make(ORCHESTRATION_WS_METHODS.getTurnDiff, {
payload: OrchestrationGetTurnDiffInput,
success: OrchestrationRpcSchemas.getTurnDiff.output,
error: OrchestrationGetTurnDiffError,
});
export const WsOrchestrationGetFullThreadDiffRpc = Rpc.make(
ORCHESTRATION_WS_METHODS.getFullThreadDiff,
{
payload: OrchestrationGetFullThreadDiffInput,
success: OrchestrationRpcSchemas.getFullThreadDiff.output,
error: OrchestrationGetFullThreadDiffError,
},
);
export const WsOrchestrationReplayEventsRpc = Rpc.make(ORCHESTRATION_WS_METHODS.replayEvents, {
payload: OrchestrationReplayEventsInput,
success: OrchestrationRpcSchemas.replayEvents.output,
error: OrchestrationReplayEventsError,
});
export const WsSubscribeOrchestrationDomainEventsRpc = Rpc.make(
WS_METHODS.subscribeOrchestrationDomainEvents,
{
payload: Schema.Struct({}),
success: OrchestrationEvent,
stream: true,
},
);
export const WsSubscribeTerminalEventsRpc = Rpc.make(WS_METHODS.subscribeTerminalEvents, {
payload: Schema.Struct({}),
success: TerminalEvent,
stream: true,
});
export const WsSubscribeServerConfigRpc = Rpc.make(WS_METHODS.subscribeServerConfig, {
payload: Schema.Struct({}),
success: ServerConfigStreamEvent,
error: Schema.Union([KeybindingsConfigError, ServerSettingsError]),
stream: true,
});
export const WsSubscribeServerLifecycleRpc = Rpc.make(WS_METHODS.subscribeServerLifecycle, {
payload: Schema.Struct({}),
success: ServerLifecycleStreamEvent,
stream: true,
});
export const WsRpcGroup = RpcGroup.make(
WsServerGetConfigRpc,
WsServerRefreshProvidersRpc,
WsServerUpsertKeybindingRpc,
WsServerGetSettingsRpc,
WsServerUpdateSettingsRpc,
WsProjectsSearchEntriesRpc,
WsProjectsWriteFileRpc,
WsShellOpenInEditorRpc,
WsGitStatusRpc,
WsGitPullRpc,
WsGitRunStackedActionRpc,
WsGitResolvePullRequestRpc,
WsGitPreparePullRequestThreadRpc,
WsGitListBranchesRpc,
WsGitCreateWorktreeRpc,
WsGitRemoveWorktreeRpc,
WsGitCreateBranchRpc,
WsGitCheckoutRpc,
WsGitInitRpc,
WsTerminalOpenRpc,
WsTerminalWriteRpc,
WsTerminalResizeRpc,
WsTerminalClearRpc,
WsTerminalRestartRpc,
WsTerminalCloseRpc,
WsSubscribeOrchestrationDomainEventsRpc,
WsSubscribeTerminalEventsRpc,
WsSubscribeServerConfigRpc,
WsSubscribeServerLifecycleRpc,
WsOrchestrationGetSnapshotRpc,
WsOrchestrationDispatchCommandRpc,
WsOrchestrationGetTurnDiffRpc,
WsOrchestrationGetFullThreadDiffRpc,
WsOrchestrationReplayEventsRpc,
);
+100 -2
View File
@@ -1,5 +1,11 @@
import { Schema } from "effect";
import { IsoDateTime, TrimmedNonEmptyString } from "./baseSchemas";
import {
IsoDateTime,
NonNegativeInt,
ProjectId,
ThreadId,
TrimmedNonEmptyString,
} from "./baseSchemas";
import { KeybindingRule, ResolvedKeybindingsConfig } from "./keybindings";
import { EditorId } from "./editor";
import { ModelCapabilities } from "./model";
@@ -63,7 +69,8 @@ export const ServerProvider = Schema.Struct({
});
export type ServerProvider = typeof ServerProvider.Type;
const ServerProviders = Schema.Array(ServerProvider);
export const ServerProviders = Schema.Array(ServerProvider);
export type ServerProviders = typeof ServerProviders.Type;
export const ServerConfig = Schema.Struct({
cwd: TrimmedNonEmptyString,
@@ -87,10 +94,101 @@ export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.T
export const ServerConfigUpdatedPayload = Schema.Struct({
issues: ServerConfigIssues,
providers: ServerProviders,
settings: Schema.optional(ServerSettings),
});
export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
issues: ServerConfigIssues,
});
export type ServerConfigKeybindingsUpdatedPayload =
typeof ServerConfigKeybindingsUpdatedPayload.Type;
export const ServerConfigProviderStatusesPayload = Schema.Struct({
providers: ServerProviders,
});
export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
settings: ServerSettings,
});
export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
export const ServerConfigStreamSnapshotEvent = Schema.Struct({
version: Schema.Literal(1),
type: Schema.Literal("snapshot"),
config: ServerConfig,
});
export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
version: Schema.Literal(1),
type: Schema.Literal("keybindingsUpdated"),
payload: ServerConfigKeybindingsUpdatedPayload,
});
export type ServerConfigStreamKeybindingsUpdatedEvent =
typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
version: Schema.Literal(1),
type: Schema.Literal("providerStatuses"),
payload: ServerConfigProviderStatusesPayload,
});
export type ServerConfigStreamProviderStatusesEvent =
typeof ServerConfigStreamProviderStatusesEvent.Type;
export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
version: Schema.Literal(1),
type: Schema.Literal("settingsUpdated"),
payload: ServerConfigSettingsUpdatedPayload,
});
export type ServerConfigStreamSettingsUpdatedEvent =
typeof ServerConfigStreamSettingsUpdatedEvent.Type;
export const ServerConfigStreamEvent = Schema.Union([
ServerConfigStreamSnapshotEvent,
ServerConfigStreamKeybindingsUpdatedEvent,
ServerConfigStreamProviderStatusesEvent,
ServerConfigStreamSettingsUpdatedEvent,
]);
export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
export const ServerLifecycleReadyPayload = Schema.Struct({
at: IsoDateTime,
});
export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
export const ServerLifecycleWelcomePayload = Schema.Struct({
cwd: TrimmedNonEmptyString,
projectName: TrimmedNonEmptyString,
bootstrapProjectId: Schema.optional(ProjectId),
bootstrapThreadId: Schema.optional(ThreadId),
});
export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
version: Schema.Literal(1),
sequence: NonNegativeInt,
type: Schema.Literal("welcome"),
payload: ServerLifecycleWelcomePayload,
});
export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
export const ServerLifecycleStreamReadyEvent = Schema.Struct({
version: Schema.Literal(1),
sequence: NonNegativeInt,
type: Schema.Literal("ready"),
payload: ServerLifecycleReadyPayload,
});
export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
export const ServerLifecycleStreamEvent = Schema.Union([
ServerLifecycleStreamWelcomeEvent,
ServerLifecycleStreamReadyEvent,
]);
export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
export const ServerProviderUpdatedPayload = Schema.Struct({
providers: ServerProviders,
});
+13
View File
@@ -93,6 +93,19 @@ export type ServerSettings = typeof ServerSettings.Type;
export const DEFAULT_SERVER_SETTINGS: ServerSettings = Schema.decodeSync(ServerSettings)({});
export class ServerSettingsError extends Schema.TaggedErrorClass<ServerSettingsError>()(
"ServerSettingsError",
{
settingsPath: Schema.String,
detail: Schema.String,
cause: Schema.optional(Schema.Defect),
},
) {
override get message(): string {
return `Server settings error at ${this.settingsPath}: ${this.detail}`;
}
}
// ── Unified type ─────────────────────────────────────────────────────
export type UnifiedSettings = ServerSettings & ClientSettings;
+71
View File
@@ -149,3 +149,74 @@ export const TerminalEvent = Schema.Union([
TerminalActivityEvent,
]);
export type TerminalEvent = typeof TerminalEvent.Type;
export class TerminalCwdError extends Schema.TaggedErrorClass<TerminalCwdError>()(
"TerminalCwdError",
{
cwd: Schema.String,
reason: Schema.Literals(["notFound", "notDirectory", "statFailed"]),
cause: Schema.optional(Schema.Defect),
},
) {
override get message() {
if (this.reason === "notDirectory") {
return `Terminal cwd is not a directory: ${this.cwd}`;
}
if (this.reason === "notFound") {
return `Terminal cwd does not exist: ${this.cwd}`;
}
const causeMessage =
this.cause && typeof this.cause === "object" && "message" in this.cause
? this.cause.message
: undefined;
return causeMessage
? `Failed to access terminal cwd: ${this.cwd} (${causeMessage})`
: `Failed to access terminal cwd: ${this.cwd}`;
}
}
export class TerminalHistoryError extends Schema.TaggedErrorClass<TerminalHistoryError>()(
"TerminalHistoryError",
{
operation: Schema.Literals(["read", "truncate", "migrate"]),
threadId: Schema.String,
terminalId: Schema.String,
cause: Schema.optional(Schema.Defect),
},
) {
override get message() {
return `Failed to ${this.operation} terminal history for thread: ${this.threadId}, terminal: ${this.terminalId}`;
}
}
export class TerminalSessionLookupError extends Schema.TaggedErrorClass<TerminalSessionLookupError>()(
"TerminalSessionLookupError",
{
threadId: Schema.String,
terminalId: Schema.String,
},
) {
override get message() {
return `Unknown terminal thread: ${this.threadId}, terminal: ${this.terminalId}`;
}
}
export class TerminalNotRunningError extends Schema.TaggedErrorClass<TerminalNotRunningError>()(
"TerminalNotRunningError",
{
threadId: Schema.String,
terminalId: Schema.String,
},
) {
override get message() {
return `Terminal is not running for thread: ${this.threadId}, terminal: ${this.terminalId}`;
}
}
export const TerminalError = Schema.Union([
TerminalCwdError,
TerminalHistoryError,
TerminalSessionLookupError,
TerminalNotRunningError,
]);
export type TerminalError = typeof TerminalError.Type;
-157
View File
@@ -1,157 +0,0 @@
import { assert, it } from "@effect/vitest";
import { Effect, Schema } from "effect";
import { ORCHESTRATION_WS_CHANNELS, ORCHESTRATION_WS_METHODS } from "./orchestration";
import { WebSocketRequest, WsResponse, WS_CHANNELS, WS_METHODS } from "./ws";
const decodeWebSocketRequest = Schema.decodeUnknownEffect(WebSocketRequest);
const decodeWsResponse = Schema.decodeUnknownEffect(WsResponse);
it.effect("accepts getTurnDiff requests when fromTurnCount <= toTurnCount", () =>
Effect.gen(function* () {
const parsed = yield* decodeWebSocketRequest({
id: "req-1",
body: {
_tag: ORCHESTRATION_WS_METHODS.getTurnDiff,
threadId: "thread-1",
fromTurnCount: 1,
toTurnCount: 2,
},
});
assert.strictEqual(parsed.body._tag, ORCHESTRATION_WS_METHODS.getTurnDiff);
}),
);
it.effect("rejects getTurnDiff requests when fromTurnCount > toTurnCount", () =>
Effect.gen(function* () {
const result = yield* Effect.exit(
decodeWebSocketRequest({
id: "req-1",
body: {
_tag: ORCHESTRATION_WS_METHODS.getTurnDiff,
threadId: "thread-1",
fromTurnCount: 3,
toTurnCount: 2,
},
}),
);
assert.strictEqual(result._tag, "Failure");
}),
);
it.effect("trims websocket request id and nested orchestration ids", () =>
Effect.gen(function* () {
const parsed = yield* decodeWebSocketRequest({
id: " req-1 ",
body: {
_tag: ORCHESTRATION_WS_METHODS.getTurnDiff,
threadId: " thread-1 ",
fromTurnCount: 0,
toTurnCount: 0,
},
});
assert.strictEqual(parsed.id, "req-1");
assert.strictEqual(parsed.body._tag, ORCHESTRATION_WS_METHODS.getTurnDiff);
if (parsed.body._tag === ORCHESTRATION_WS_METHODS.getTurnDiff) {
assert.strictEqual(parsed.body.threadId, "thread-1");
}
}),
);
it.effect("accepts git.preparePullRequestThread requests", () =>
Effect.gen(function* () {
const parsed = yield* decodeWebSocketRequest({
id: "req-pr-1",
body: {
_tag: WS_METHODS.gitPreparePullRequestThread,
cwd: "/repo",
reference: "#42",
mode: "worktree",
},
});
assert.strictEqual(parsed.body._tag, WS_METHODS.gitPreparePullRequestThread);
}),
);
it.effect("accepts typed websocket push envelopes with sequence", () =>
Effect.gen(function* () {
const parsed = yield* decodeWsResponse({
type: "push",
sequence: 1,
channel: WS_CHANNELS.serverWelcome,
data: {
cwd: "/tmp/workspace",
projectName: "workspace",
},
});
if (!("type" in parsed) || parsed.type !== "push") {
assert.fail("expected websocket response to decode as a push envelope");
}
assert.strictEqual(parsed.type, "push");
assert.strictEqual(parsed.sequence, 1);
assert.strictEqual(parsed.channel, WS_CHANNELS.serverWelcome);
}),
);
it.effect("accepts git.actionProgress push envelopes", () =>
Effect.gen(function* () {
const parsed = yield* decodeWsResponse({
type: "push",
sequence: 3,
channel: WS_CHANNELS.gitActionProgress,
data: {
actionId: "action-1",
cwd: "/repo",
action: "commit",
kind: "phase_started",
phase: "commit",
label: "Committing...",
},
});
if (!("type" in parsed) || parsed.type !== "push") {
assert.fail("expected websocket response to decode as a push envelope");
}
assert.strictEqual(parsed.channel, WS_CHANNELS.gitActionProgress);
}),
);
it.effect("accepts server.providersUpdated push envelopes", () =>
Effect.gen(function* () {
const parsed = yield* decodeWsResponse({
type: "push",
sequence: 4,
channel: WS_CHANNELS.serverProvidersUpdated,
data: {
providers: [],
},
});
if (!("type" in parsed) || parsed.type !== "push") {
assert.fail("expected websocket response to decode as a push envelope");
}
assert.strictEqual(parsed.channel, WS_CHANNELS.serverProvidersUpdated);
}),
);
it.effect("rejects push envelopes when channel payload does not match the channel schema", () =>
Effect.gen(function* () {
const result = yield* Effect.exit(
decodeWsResponse({
type: "push",
sequence: 2,
channel: ORCHESTRATION_WS_CHANNELS.domainEvent,
data: {
cwd: "/tmp/workspace",
projectName: "workspace",
},
}),
);
assert.strictEqual(result._tag, "Failure");
}),
);
-257
View File
@@ -1,257 +0,0 @@
import { Schema, Struct } from "effect";
import { NonNegativeInt, ProjectId, ThreadId, TrimmedNonEmptyString } from "./baseSchemas";
import {
ClientOrchestrationCommand,
OrchestrationEvent,
ORCHESTRATION_WS_CHANNELS,
OrchestrationGetFullThreadDiffInput,
ORCHESTRATION_WS_METHODS,
OrchestrationGetSnapshotInput,
OrchestrationGetTurnDiffInput,
OrchestrationReplayEventsInput,
} from "./orchestration";
import {
GitActionProgressEvent,
GitCheckoutInput,
GitCreateBranchInput,
GitPreparePullRequestThreadInput,
GitCreateWorktreeInput,
GitInitInput,
GitListBranchesInput,
GitPullInput,
GitPullRequestRefInput,
GitRemoveWorktreeInput,
GitRunStackedActionInput,
GitStatusInput,
} from "./git";
import {
TerminalClearInput,
TerminalCloseInput,
TerminalEvent,
TerminalOpenInput,
TerminalResizeInput,
TerminalRestartInput,
TerminalWriteInput,
} from "./terminal";
import { KeybindingRule } from "./keybindings";
import { ProjectSearchEntriesInput, ProjectWriteFileInput } from "./project";
import { OpenInEditorInput } from "./editor";
import { ServerConfigUpdatedPayload, ServerProviderUpdatedPayload } from "./server";
import { ServerSettingsPatch } from "./settings";
// ── WebSocket RPC Method Names ───────────────────────────────────────
export const WS_METHODS = {
// Project registry methods
projectsList: "projects.list",
projectsAdd: "projects.add",
projectsRemove: "projects.remove",
projectsSearchEntries: "projects.searchEntries",
projectsWriteFile: "projects.writeFile",
// Shell methods
shellOpenInEditor: "shell.openInEditor",
// Git methods
gitPull: "git.pull",
gitStatus: "git.status",
gitRunStackedAction: "git.runStackedAction",
gitListBranches: "git.listBranches",
gitCreateWorktree: "git.createWorktree",
gitRemoveWorktree: "git.removeWorktree",
gitCreateBranch: "git.createBranch",
gitCheckout: "git.checkout",
gitInit: "git.init",
gitResolvePullRequest: "git.resolvePullRequest",
gitPreparePullRequestThread: "git.preparePullRequestThread",
// Terminal methods
terminalOpen: "terminal.open",
terminalWrite: "terminal.write",
terminalResize: "terminal.resize",
terminalClear: "terminal.clear",
terminalRestart: "terminal.restart",
terminalClose: "terminal.close",
// Server meta
serverGetConfig: "server.getConfig",
serverRefreshProviders: "server.refreshProviders",
serverUpsertKeybinding: "server.upsertKeybinding",
serverGetSettings: "server.getSettings",
serverUpdateSettings: "server.updateSettings",
} as const;
// ── Push Event Channels ──────────────────────────────────────────────
export const WS_CHANNELS = {
gitActionProgress: "git.actionProgress",
terminalEvent: "terminal.event",
serverWelcome: "server.welcome",
serverConfigUpdated: "server.configUpdated",
serverProvidersUpdated: "server.providersUpdated",
} as const;
// -- Tagged Union of all request body schemas ─────────────────────────
const tagRequestBody = <const Tag extends string, const Fields extends Schema.Struct.Fields>(
tag: Tag,
schema: Schema.Struct<Fields>,
) =>
schema.mapFields(
Struct.assign({ _tag: Schema.tag(tag) }),
// PreserveChecks is safe here. No existing schema should have checks depending on the tag
{ unsafePreserveChecks: true },
);
const WebSocketRequestBody = Schema.Union([
// Orchestration methods
tagRequestBody(
ORCHESTRATION_WS_METHODS.dispatchCommand,
Schema.Struct({ command: ClientOrchestrationCommand }),
),
tagRequestBody(ORCHESTRATION_WS_METHODS.getSnapshot, OrchestrationGetSnapshotInput),
tagRequestBody(ORCHESTRATION_WS_METHODS.getTurnDiff, OrchestrationGetTurnDiffInput),
tagRequestBody(ORCHESTRATION_WS_METHODS.getFullThreadDiff, OrchestrationGetFullThreadDiffInput),
tagRequestBody(ORCHESTRATION_WS_METHODS.replayEvents, OrchestrationReplayEventsInput),
// Project Search
tagRequestBody(WS_METHODS.projectsSearchEntries, ProjectSearchEntriesInput),
tagRequestBody(WS_METHODS.projectsWriteFile, ProjectWriteFileInput),
// Shell methods
tagRequestBody(WS_METHODS.shellOpenInEditor, OpenInEditorInput),
// Git methods
tagRequestBody(WS_METHODS.gitPull, GitPullInput),
tagRequestBody(WS_METHODS.gitStatus, GitStatusInput),
tagRequestBody(WS_METHODS.gitRunStackedAction, GitRunStackedActionInput),
tagRequestBody(WS_METHODS.gitListBranches, GitListBranchesInput),
tagRequestBody(WS_METHODS.gitCreateWorktree, GitCreateWorktreeInput),
tagRequestBody(WS_METHODS.gitRemoveWorktree, GitRemoveWorktreeInput),
tagRequestBody(WS_METHODS.gitCreateBranch, GitCreateBranchInput),
tagRequestBody(WS_METHODS.gitCheckout, GitCheckoutInput),
tagRequestBody(WS_METHODS.gitInit, GitInitInput),
tagRequestBody(WS_METHODS.gitResolvePullRequest, GitPullRequestRefInput),
tagRequestBody(WS_METHODS.gitPreparePullRequestThread, GitPreparePullRequestThreadInput),
// Terminal methods
tagRequestBody(WS_METHODS.terminalOpen, TerminalOpenInput),
tagRequestBody(WS_METHODS.terminalWrite, TerminalWriteInput),
tagRequestBody(WS_METHODS.terminalResize, TerminalResizeInput),
tagRequestBody(WS_METHODS.terminalClear, TerminalClearInput),
tagRequestBody(WS_METHODS.terminalRestart, TerminalRestartInput),
tagRequestBody(WS_METHODS.terminalClose, TerminalCloseInput),
// Server meta
tagRequestBody(WS_METHODS.serverGetConfig, Schema.Struct({})),
tagRequestBody(WS_METHODS.serverRefreshProviders, Schema.Struct({})),
tagRequestBody(WS_METHODS.serverUpsertKeybinding, KeybindingRule),
tagRequestBody(WS_METHODS.serverGetSettings, Schema.Struct({})),
tagRequestBody(WS_METHODS.serverUpdateSettings, Schema.Struct({ patch: ServerSettingsPatch })),
]);
export const WebSocketRequest = Schema.Struct({
id: TrimmedNonEmptyString,
body: WebSocketRequestBody,
});
export type WebSocketRequest = typeof WebSocketRequest.Type;
export const WebSocketResponse = Schema.Struct({
id: TrimmedNonEmptyString,
result: Schema.optional(Schema.Unknown),
error: Schema.optional(
Schema.Struct({
message: Schema.String,
}),
),
});
export type WebSocketResponse = typeof WebSocketResponse.Type;
export const WsPushSequence = NonNegativeInt;
export type WsPushSequence = typeof WsPushSequence.Type;
export const WsWelcomePayload = Schema.Struct({
cwd: TrimmedNonEmptyString,
projectName: TrimmedNonEmptyString,
bootstrapProjectId: Schema.optional(ProjectId),
bootstrapThreadId: Schema.optional(ThreadId),
});
export type WsWelcomePayload = typeof WsWelcomePayload.Type;
export interface WsPushPayloadByChannel {
readonly [WS_CHANNELS.serverWelcome]: WsWelcomePayload;
readonly [WS_CHANNELS.serverConfigUpdated]: typeof ServerConfigUpdatedPayload.Type;
readonly [WS_CHANNELS.serverProvidersUpdated]: typeof ServerProviderUpdatedPayload.Type;
readonly [WS_CHANNELS.gitActionProgress]: typeof GitActionProgressEvent.Type;
readonly [WS_CHANNELS.terminalEvent]: typeof TerminalEvent.Type;
readonly [ORCHESTRATION_WS_CHANNELS.domainEvent]: OrchestrationEvent;
}
export type WsPushChannel = keyof WsPushPayloadByChannel;
export type WsPushData<C extends WsPushChannel> = WsPushPayloadByChannel[C];
const makeWsPushSchema = <const Channel extends string, Payload extends Schema.Schema<any>>(
channel: Channel,
payload: Payload,
) =>
Schema.Struct({
type: Schema.Literal("push"),
sequence: WsPushSequence,
channel: Schema.Literal(channel),
data: payload,
});
export const WsPushServerWelcome = makeWsPushSchema(WS_CHANNELS.serverWelcome, WsWelcomePayload);
export const WsPushServerConfigUpdated = makeWsPushSchema(
WS_CHANNELS.serverConfigUpdated,
ServerConfigUpdatedPayload,
);
export const WsPushServerProvidersUpdated = makeWsPushSchema(
WS_CHANNELS.serverProvidersUpdated,
ServerProviderUpdatedPayload,
);
export const WsPushGitActionProgress = makeWsPushSchema(
WS_CHANNELS.gitActionProgress,
GitActionProgressEvent,
);
export const WsPushTerminalEvent = makeWsPushSchema(WS_CHANNELS.terminalEvent, TerminalEvent);
export const WsPushOrchestrationDomainEvent = makeWsPushSchema(
ORCHESTRATION_WS_CHANNELS.domainEvent,
OrchestrationEvent,
);
export const WsPushChannelSchema = Schema.Literals([
WS_CHANNELS.gitActionProgress,
WS_CHANNELS.serverWelcome,
WS_CHANNELS.serverConfigUpdated,
WS_CHANNELS.serverProvidersUpdated,
WS_CHANNELS.terminalEvent,
ORCHESTRATION_WS_CHANNELS.domainEvent,
]);
export type WsPushChannelSchema = typeof WsPushChannelSchema.Type;
export const WsPush = Schema.Union([
WsPushServerWelcome,
WsPushServerConfigUpdated,
WsPushServerProvidersUpdated,
WsPushGitActionProgress,
WsPushTerminalEvent,
WsPushOrchestrationDomainEvent,
]);
export type WsPush = typeof WsPush.Type;
export type WsPushMessage<C extends WsPushChannel> = Extract<WsPush, { channel: C }>;
export const WsPushEnvelopeBase = Schema.Struct({
type: Schema.Literal("push"),
sequence: WsPushSequence,
channel: WsPushChannelSchema,
data: Schema.Unknown,
});
export type WsPushEnvelopeBase = typeof WsPushEnvelopeBase.Type;
// ── Union of all server → client messages ─────────────────────────────
export const WsResponse = Schema.Union([WebSocketResponse, WsPush]);
export type WsResponse = typeof WsResponse.Type;