[codex] Align terminal Effect service modules (#3193)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
b17b6d50c5
commit
4e8ee13d8f
14 files changed
+2759
-2815
No files matched your search
@@ -6,7 +6,7 @@ import * as Layer from "effect/Layer";
|
||||
import * as Stream from "effect/Stream";
|
||||
|
||||
import { ProviderService } from "../../provider/Services/ProviderService.ts";
|
||||
import { TerminalManager } from "../../terminal/Services/Manager.ts";
|
||||
import * as TerminalManager from "../../terminal/Manager.ts";
|
||||
import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
|
||||
import {
|
||||
ThreadDeletionReactor,
|
||||
@@ -39,7 +39,7 @@ export const logCleanupCauseUnlessInterrupted = <R, E>({
|
||||
const make = Effect.gen(function* () {
|
||||
const orchestrationEngine = yield* OrchestrationEngineService;
|
||||
const providerService = yield* ProviderService;
|
||||
const terminalManager = yield* TerminalManager;
|
||||
const terminalManager = yield* TerminalManager.TerminalManager;
|
||||
|
||||
const stopProviderSession = (threadId: ThreadDeletedEvent["payload"]["threadId"]) =>
|
||||
logCleanupCauseUnlessInterrupted({
|
||||
|
||||
@@ -5,7 +5,7 @@ import * as Option from "effect/Option";
|
||||
import { describe, expect, it, vi } from "vite-plus/test";
|
||||
|
||||
import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import { TerminalManager } from "../../terminal/Services/Manager.ts";
|
||||
import * as TerminalManager from "../../terminal/Manager.ts";
|
||||
import { ProjectSetupScriptRunner } from "../Services/ProjectSetupScriptRunner.ts";
|
||||
import { ProjectSetupScriptRunnerLive } from "./ProjectSetupScriptRunner.ts";
|
||||
|
||||
@@ -52,7 +52,7 @@ describe("ProjectSetupScriptRunner", () => {
|
||||
ProjectSetupScriptRunnerLive.pipe(
|
||||
Layer.provideMerge(makeProjectionSnapshotQueryLayer(project)),
|
||||
Layer.provideMerge(
|
||||
Layer.succeed(TerminalManager, {
|
||||
Layer.succeed(TerminalManager.TerminalManager, {
|
||||
open,
|
||||
attachStream: () => Effect.die(new Error("unused")),
|
||||
write,
|
||||
@@ -114,7 +114,7 @@ describe("ProjectSetupScriptRunner", () => {
|
||||
ProjectSetupScriptRunnerLive.pipe(
|
||||
Layer.provideMerge(makeProjectionSnapshotQueryLayer(project)),
|
||||
Layer.provideMerge(
|
||||
Layer.succeed(TerminalManager, {
|
||||
Layer.succeed(TerminalManager.TerminalManager, {
|
||||
open,
|
||||
attachStream: () => Effect.die(new Error("unused")),
|
||||
write,
|
||||
|
||||
@@ -5,7 +5,7 @@ import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import { TerminalManager } from "../../terminal/Services/Manager.ts";
|
||||
import * as TerminalManager from "../../terminal/Manager.ts";
|
||||
import {
|
||||
type ProjectSetupScriptRunnerShape,
|
||||
ProjectSetupScriptRunner,
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
|
||||
const makeProjectSetupScriptRunner = Effect.gen(function* () {
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
const terminalManager = yield* TerminalManager;
|
||||
const terminalManager = yield* TerminalManager.TerminalManager;
|
||||
|
||||
const runForThread: ProjectSetupScriptRunnerShape["runForThread"] = (input) =>
|
||||
Effect.gen(function* () {
|
||||
|
||||
@@ -85,7 +85,7 @@ import { makeManualOnlyProviderMaintenanceCapabilities } from "./provider/provid
|
||||
import * as ServerLifecycleEvents from "./serverLifecycleEvents.ts";
|
||||
import * as ServerRuntimeStartup from "./serverRuntimeStartup.ts";
|
||||
import * as ServerSettings from "./serverSettings.ts";
|
||||
import * as TerminalManager from "./terminal/Services/Manager.ts";
|
||||
import * as TerminalManager from "./terminal/Manager.ts";
|
||||
import * as PreviewManager from "./preview/Manager.ts";
|
||||
import * as PortScanner from "./preview/PortScanner.ts";
|
||||
import * as BrowserTraceCollector from "./observability/BrowserTraceCollector.ts";
|
||||
|
||||
@@ -33,7 +33,7 @@ import * as GitHubCli from "./sourceControl/GitHubCli.ts";
|
||||
import * as GitLabCli from "./sourceControl/GitLabCli.ts";
|
||||
import * as TextGeneration from "./textGeneration/TextGeneration.ts";
|
||||
import { ProviderInstanceRegistryHydrationLive } from "./provider/Layers/ProviderInstanceRegistryHydration.ts";
|
||||
import { TerminalManagerLive } from "./terminal/Layers/Manager.ts";
|
||||
import * as TerminalManager from "./terminal/Manager.ts";
|
||||
import * as McpHttpServer from "./mcp/McpHttpServer.ts";
|
||||
import * as McpSessionRegistry from "./mcp/McpSessionRegistry.ts";
|
||||
import * as PreviewManager from "./preview/Manager.ts";
|
||||
@@ -101,11 +101,11 @@ const HTTP_PREEMPTIVE_SHUTDOWN_GRACE_MS = 0;
|
||||
const PtyAdapterLive = Layer.unwrap(
|
||||
Effect.gen(function* () {
|
||||
if (typeof Bun !== "undefined") {
|
||||
const BunPTY = yield* Effect.promise(() => import("./terminal/Layers/BunPTY.ts"));
|
||||
return BunPTY.layer;
|
||||
const BunPtyAdapter = yield* Effect.promise(() => import("./terminal/BunPtyAdapter.ts"));
|
||||
return BunPtyAdapter.layer;
|
||||
} else {
|
||||
const NodePTY = yield* Effect.promise(() => import("./terminal/Layers/NodePTY.ts"));
|
||||
return NodePTY.layer;
|
||||
const NodePtyAdapter = yield* Effect.promise(() => import("./terminal/NodePtyAdapter.ts"));
|
||||
return NodePtyAdapter.layer;
|
||||
}
|
||||
}),
|
||||
);
|
||||
@@ -238,7 +238,7 @@ const CheckpointingLayerLive = Layer.empty.pipe(
|
||||
|
||||
const PortScannerLayerLive = PortScanner.layer.pipe(Layer.provide(ProcessRunner.layer));
|
||||
|
||||
const TerminalLayerLive = TerminalManagerLive.pipe(
|
||||
const TerminalLayerLive = TerminalManager.layer.pipe(
|
||||
Layer.provide(PtyAdapterLive),
|
||||
Layer.provide(PortScannerLayerLive),
|
||||
);
|
||||
|
||||
+29
-22
@@ -3,12 +3,12 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
|
||||
import { PtyAdapter } from "../Services/PTY.ts";
|
||||
import type { PtyAdapterShape, PtyExitEvent, PtyProcess } from "../Services/PTY.ts";
|
||||
|
||||
class BunPtyProcess implements PtyProcess {
|
||||
import * as PtyAdapter from "./PtyAdapter.ts";
|
||||
|
||||
class BunPtyProcess implements PtyAdapter.PtyProcess {
|
||||
private readonly dataListeners = new Set<(data: string) => void>();
|
||||
private readonly exitListeners = new Set<(event: PtyExitEvent) => void>();
|
||||
private readonly exitListeners = new Set<(event: PtyAdapter.PtyExitEvent) => void>();
|
||||
private readonly decoder = new TextDecoder();
|
||||
private readonly process: Bun.Subprocess;
|
||||
private didExit = false;
|
||||
@@ -60,7 +60,7 @@ class BunPtyProcess implements PtyProcess {
|
||||
};
|
||||
}
|
||||
|
||||
onExit(callback: (event: PtyExitEvent) => void): () => void {
|
||||
onExit(callback: (event: PtyAdapter.PtyExitEvent) => void): () => void {
|
||||
this.exitListeners.add(callback);
|
||||
return () => {
|
||||
this.exitListeners.delete(callback);
|
||||
@@ -76,7 +76,7 @@ class BunPtyProcess implements PtyProcess {
|
||||
}
|
||||
}
|
||||
|
||||
private emitExit(event: PtyExitEvent): void {
|
||||
private emitExit(event: PtyAdapter.PtyExitEvent): void {
|
||||
if (this.didExit) return;
|
||||
this.didExit = true;
|
||||
|
||||
@@ -93,18 +93,17 @@ class BunPtyProcess implements PtyProcess {
|
||||
}
|
||||
}
|
||||
|
||||
export const layer = Layer.effect(
|
||||
PtyAdapter,
|
||||
Effect.gen(function* () {
|
||||
const platform = yield* HostProcessPlatform;
|
||||
if (platform === "win32") {
|
||||
return yield* Effect.die(
|
||||
"Bun PTY terminal support is unavailable on Windows. Please use Node.js (e.g. by running `npx t3`) instead.",
|
||||
);
|
||||
}
|
||||
return {
|
||||
spawn: (input) =>
|
||||
Effect.sync(() => {
|
||||
export const make = Effect.fn("BunPtyAdapter.make")(function* () {
|
||||
const platform = yield* HostProcessPlatform;
|
||||
if (platform === "win32") {
|
||||
return yield* Effect.die(
|
||||
"Bun PTY terminal support is unavailable on Windows. Please use Node.js (e.g. by running `npx t3`) instead.",
|
||||
);
|
||||
}
|
||||
return PtyAdapter.PtyAdapter.of({
|
||||
spawn: (input) =>
|
||||
Effect.try({
|
||||
try: () => {
|
||||
let processHandle: BunPtyProcess | null = null;
|
||||
const command = [input.shell, ...(input.args ?? [])];
|
||||
const subprocess = Bun.spawn(command, {
|
||||
@@ -120,7 +119,15 @@ export const layer = Layer.effect(
|
||||
});
|
||||
processHandle = new BunPtyProcess(subprocess);
|
||||
return processHandle;
|
||||
}),
|
||||
} satisfies PtyAdapterShape;
|
||||
}),
|
||||
);
|
||||
},
|
||||
catch: (cause) =>
|
||||
new PtyAdapter.PtySpawnError({
|
||||
adapter: "bun",
|
||||
shell: input.shell,
|
||||
cause,
|
||||
}),
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(PtyAdapter.PtyAdapter, make());
|
||||
File diff suppressed because it is too large.
Load diff
+19
-24
@@ -23,31 +23,24 @@ import * as Path from "effect/Path";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as Scope from "effect/Scope";
|
||||
import { TestClock } from "effect/testing";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
import { expect } from "vite-plus/test";
|
||||
|
||||
import * as ProcessRunner from "../../processRunner.ts";
|
||||
import type { TerminalManagerShape } from "../Services/Manager.ts";
|
||||
import {
|
||||
type PtyAdapterShape,
|
||||
type PtyExitEvent,
|
||||
type PtyProcess,
|
||||
type PtySpawnInput,
|
||||
PtySpawnError,
|
||||
} from "../Services/PTY.ts";
|
||||
import { makeTerminalManagerWithOptions } from "./Manager.ts";
|
||||
import * as ProcessRunner from "../processRunner.ts";
|
||||
import * as TerminalManager from "./Manager.ts";
|
||||
import * as PtyAdapter from "./PtyAdapter.ts";
|
||||
|
||||
class WaitForConditionError extends Data.TaggedError("WaitForConditionError")<{
|
||||
readonly message: string;
|
||||
}> {}
|
||||
|
||||
class FakePtyProcess implements PtyProcess {
|
||||
class FakePtyProcess implements PtyAdapter.PtyProcess {
|
||||
readonly writes: string[] = [];
|
||||
readonly resizeCalls: Array<{ cols: number; rows: number }> = [];
|
||||
readonly killSignals: Array<string | undefined> = [];
|
||||
readonly pid: number;
|
||||
private readonly dataListeners = new Set<(data: string) => void>();
|
||||
private readonly exitListeners = new Set<(event: PtyExitEvent) => void>();
|
||||
private readonly exitListeners = new Set<(event: PtyAdapter.PtyExitEvent) => void>();
|
||||
killed = false;
|
||||
|
||||
constructor(pid: number) {
|
||||
@@ -74,7 +67,7 @@ class FakePtyProcess implements PtyProcess {
|
||||
};
|
||||
}
|
||||
|
||||
onExit(callback: (event: PtyExitEvent) => void): () => void {
|
||||
onExit(callback: (event: PtyAdapter.PtyExitEvent) => void): () => void {
|
||||
this.exitListeners.add(callback);
|
||||
return () => {
|
||||
this.exitListeners.delete(callback);
|
||||
@@ -87,15 +80,15 @@ class FakePtyProcess implements PtyProcess {
|
||||
}
|
||||
}
|
||||
|
||||
emitExit(event: PtyExitEvent): void {
|
||||
emitExit(event: PtyAdapter.PtyExitEvent): void {
|
||||
for (const listener of this.exitListeners) {
|
||||
listener(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FakePtyAdapter implements PtyAdapterShape {
|
||||
readonly spawnInputs: PtySpawnInput[] = [];
|
||||
class FakePtyAdapter {
|
||||
readonly spawnInputs: PtyAdapter.PtySpawnInput[] = [];
|
||||
readonly processes: FakePtyProcess[] = [];
|
||||
readonly spawnFailures: Error[] = [];
|
||||
private readonly mode: "sync" | "async";
|
||||
@@ -105,14 +98,16 @@ class FakePtyAdapter implements PtyAdapterShape {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
spawn(input: PtySpawnInput): Effect.Effect<PtyProcess, PtySpawnError> {
|
||||
spawn(
|
||||
input: PtyAdapter.PtySpawnInput,
|
||||
): Effect.Effect<PtyAdapter.PtyProcess, PtyAdapter.PtySpawnError> {
|
||||
this.spawnInputs.push(input);
|
||||
const failure = this.spawnFailures.shift();
|
||||
if (failure) {
|
||||
return Effect.fail(
|
||||
new PtySpawnError({
|
||||
new PtyAdapter.PtySpawnError({
|
||||
adapter: "fake",
|
||||
message: "Failed to spawn PTY process",
|
||||
shell: input.shell,
|
||||
cause: failure,
|
||||
}),
|
||||
);
|
||||
@@ -123,9 +118,9 @@ class FakePtyAdapter implements PtyAdapterShape {
|
||||
return Effect.tryPromise({
|
||||
try: async () => process,
|
||||
catch: (cause) =>
|
||||
new PtySpawnError({
|
||||
new PtyAdapter.PtySpawnError({
|
||||
adapter: "fake",
|
||||
message: "Failed to spawn PTY process",
|
||||
shell: input.shell,
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
@@ -216,7 +211,7 @@ interface ManagerFixture {
|
||||
readonly baseDir: string;
|
||||
readonly logsDir: string;
|
||||
readonly ptyAdapter: FakePtyAdapter;
|
||||
readonly manager: TerminalManagerShape;
|
||||
readonly manager: TerminalManager.TerminalManager["Service"];
|
||||
readonly getEvents: Effect.Effect<ReadonlyArray<TerminalEvent>>;
|
||||
}
|
||||
|
||||
@@ -235,7 +230,7 @@ const createManager = (
|
||||
const logsDir = join(baseDir, "userdata", "logs", "terminals");
|
||||
const ptyAdapter = options.ptyAdapter ?? new FakePtyAdapter();
|
||||
|
||||
const manager = yield* makeTerminalManagerWithOptions({
|
||||
const manager = yield* TerminalManager.makeWithOptions({
|
||||
logsDir,
|
||||
historyLineLimit,
|
||||
ptyAdapter,
|
||||
File diff suppressed because it is too large.
Load diff
+4
-4
@@ -5,8 +5,8 @@ import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import { vi } from "vite-plus/test";
|
||||
|
||||
import { PtyAdapter } from "../Services/PTY.ts";
|
||||
import { layer } from "./NodePTY.ts";
|
||||
import * as NodePtyAdapter from "./NodePtyAdapter.ts";
|
||||
import * as PtyAdapter from "./PtyAdapter.ts";
|
||||
|
||||
const spawn = vi.fn(() => ({
|
||||
pid: 42,
|
||||
@@ -19,7 +19,7 @@ const spawn = vi.fn(() => ({
|
||||
|
||||
vi.mock("node-pty", () => ({ spawn }));
|
||||
|
||||
const testLayer = layer.pipe(
|
||||
const testLayer = NodePtyAdapter.layer.pipe(
|
||||
Layer.provide(
|
||||
Layer.mergeAll(
|
||||
NodeServices.layer,
|
||||
@@ -31,7 +31,7 @@ const testLayer = layer.pipe(
|
||||
|
||||
it.effect("spawns through the public adapter with the provided host references", () =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* PtyAdapter;
|
||||
const adapter = yield* PtyAdapter.PtyAdapter;
|
||||
const process = yield* adapter.spawn({
|
||||
shell: "powershell.exe",
|
||||
args: ["-NoLogo"],
|
||||
+44
-50
@@ -5,13 +5,8 @@ import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess";
|
||||
import { PtyAdapter } from "../Services/PTY.ts";
|
||||
import {
|
||||
PtySpawnError,
|
||||
type PtyAdapterShape,
|
||||
type PtyExitEvent,
|
||||
type PtyProcess,
|
||||
} from "../Services/PTY.ts";
|
||||
|
||||
import * as PtyAdapter from "./PtyAdapter.ts";
|
||||
|
||||
let didEnsureSpawnHelperExecutable = false;
|
||||
|
||||
@@ -56,7 +51,7 @@ const ensureNodePtySpawnHelperExecutable = Effect.fn(function* () {
|
||||
yield* fs.chmod(helperPath, 0o755).pipe(Effect.orElseSucceed(() => undefined));
|
||||
});
|
||||
|
||||
class NodePtyProcess implements PtyProcess {
|
||||
class NodePtyProcess implements PtyAdapter.PtyProcess {
|
||||
private readonly process: import("node-pty").IPty;
|
||||
|
||||
constructor(process: import("node-pty").IPty) {
|
||||
@@ -86,7 +81,7 @@ class NodePtyProcess implements PtyProcess {
|
||||
};
|
||||
}
|
||||
|
||||
onExit(callback: (event: PtyExitEvent) => void): () => void {
|
||||
onExit(callback: (event: PtyAdapter.PtyExitEvent) => void): () => void {
|
||||
const disposable = this.process.onExit((event) => {
|
||||
callback({
|
||||
exitCode: event.exitCode,
|
||||
@@ -99,47 +94,46 @@ class NodePtyProcess implements PtyProcess {
|
||||
}
|
||||
}
|
||||
|
||||
export const layer = Layer.effect(
|
||||
PtyAdapter,
|
||||
Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const platform = yield* HostProcessPlatform;
|
||||
const architecture = yield* HostProcessArchitecture;
|
||||
export const make = Effect.fn("NodePtyAdapter.make")(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const platform = yield* HostProcessPlatform;
|
||||
const architecture = yield* HostProcessArchitecture;
|
||||
|
||||
const nodePty = yield* Effect.promise(() => import("node-pty"));
|
||||
const nodePty = yield* Effect.promise(() => import("node-pty"));
|
||||
|
||||
const ensureNodePtySpawnHelperExecutableCached = yield* Effect.cached(
|
||||
ensureNodePtySpawnHelperExecutable().pipe(
|
||||
Effect.provideService(FileSystem.FileSystem, fs),
|
||||
Effect.provideService(Path.Path, path),
|
||||
Effect.provideService(HostProcessPlatform, platform),
|
||||
Effect.provideService(HostProcessArchitecture, architecture),
|
||||
Effect.orElseSucceed(() => undefined),
|
||||
),
|
||||
);
|
||||
const ensureNodePtySpawnHelperExecutableCached = yield* Effect.cached(
|
||||
ensureNodePtySpawnHelperExecutable().pipe(
|
||||
Effect.provideService(FileSystem.FileSystem, fs),
|
||||
Effect.provideService(Path.Path, path),
|
||||
Effect.provideService(HostProcessPlatform, platform),
|
||||
Effect.provideService(HostProcessArchitecture, architecture),
|
||||
Effect.orElseSucceed(() => undefined),
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
spawn: Effect.fn(function* (input) {
|
||||
yield* ensureNodePtySpawnHelperExecutableCached;
|
||||
const ptyProcess = yield* Effect.try({
|
||||
try: () =>
|
||||
nodePty.spawn(input.shell, input.args ?? [], {
|
||||
cwd: input.cwd,
|
||||
cols: input.cols,
|
||||
rows: input.rows,
|
||||
env: input.env,
|
||||
name: platform === "win32" ? "xterm-color" : "xterm-256color",
|
||||
}),
|
||||
catch: (cause) =>
|
||||
new PtySpawnError({
|
||||
adapter: "node-pty",
|
||||
message: cause instanceof Error ? cause.message : "Failed to spawn PTY process",
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
return new NodePtyProcess(ptyProcess);
|
||||
}),
|
||||
} satisfies PtyAdapterShape;
|
||||
}),
|
||||
);
|
||||
return PtyAdapter.PtyAdapter.of({
|
||||
spawn: Effect.fn("NodePtyAdapter.spawn")(function* (input) {
|
||||
yield* ensureNodePtySpawnHelperExecutableCached;
|
||||
const ptyProcess = yield* Effect.try({
|
||||
try: () =>
|
||||
nodePty.spawn(input.shell, input.args ?? [], {
|
||||
cwd: input.cwd,
|
||||
cols: input.cols,
|
||||
rows: input.rows,
|
||||
env: input.env,
|
||||
name: platform === "win32" ? "xterm-color" : "xterm-256color",
|
||||
}),
|
||||
catch: (cause) =>
|
||||
new PtyAdapter.PtySpawnError({
|
||||
adapter: "node-pty",
|
||||
shell: input.shell,
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
return new NodePtyProcess(ptyProcess);
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
export const layer = Layer.effect(PtyAdapter.PtyAdapter, make());
|
||||
@@ -6,18 +6,30 @@
|
||||
*
|
||||
* @module PtyAdapter
|
||||
*/
|
||||
import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Context from "effect/Context";
|
||||
|
||||
/**
|
||||
* PtyError - Error type for PTY adapter operations.
|
||||
* PtySpawnError - Error type for PTY spawn failures.
|
||||
*/
|
||||
export class PtySpawnError extends Schema.TaggedErrorClass<PtySpawnError>()("PtySpawnError", {
|
||||
adapter: Schema.String,
|
||||
message: Schema.String,
|
||||
shell: Schema.optional(Schema.String),
|
||||
attemptedShells: Schema.optional(Schema.Array(Schema.String)),
|
||||
cause: Schema.optional(Schema.Defect()),
|
||||
}) {}
|
||||
}) {
|
||||
override get message(): string {
|
||||
const shell = this.shell === undefined ? "" : ` '${this.shell}'`;
|
||||
const attemptedShells =
|
||||
this.attemptedShells === undefined || this.attemptedShells.length === 0
|
||||
? ""
|
||||
: ` Tried shells: ${this.attemptedShells.join(", ")}.`;
|
||||
const causeMessage =
|
||||
this.cause instanceof Error && this.cause.message.length > 0 ? ` ${this.cause.message}` : "";
|
||||
return `Failed to spawn PTY process${shell} with ${this.adapter}.${attemptedShells}${causeMessage}`;
|
||||
}
|
||||
}
|
||||
|
||||
export interface PtyExitEvent {
|
||||
exitCode: number;
|
||||
@@ -42,19 +54,15 @@ export interface PtySpawnInput {
|
||||
env: NodeJS.ProcessEnv;
|
||||
}
|
||||
|
||||
/**
|
||||
* PtyAdapterShape - Service API for spawning and controlling PTY processes.
|
||||
*/
|
||||
export interface PtyAdapterShape {
|
||||
/**
|
||||
* Spawn a PTY process for a terminal session.
|
||||
*/
|
||||
spawn(input: PtySpawnInput): Effect.Effect<PtyProcess, PtySpawnError>;
|
||||
}
|
||||
|
||||
/**
|
||||
* PtyAdapter - Service tag for PTY process integration.
|
||||
*/
|
||||
export class PtyAdapter extends Context.Service<PtyAdapter, PtyAdapterShape>()(
|
||||
"t3/terminal/Services/PTY/PtyAdapter",
|
||||
) {}
|
||||
export class PtyAdapter extends Context.Service<
|
||||
PtyAdapter,
|
||||
{
|
||||
/**
|
||||
* Spawn a PTY process for a terminal session.
|
||||
*/
|
||||
readonly spawn: (input: PtySpawnInput) => Effect.Effect<PtyProcess, PtySpawnError>;
|
||||
}
|
||||
>()("t3/terminal/PtyAdapter") {}
|
||||
@@ -1,150 +0,0 @@
|
||||
/**
|
||||
* TerminalManager - Terminal session orchestration service interface.
|
||||
*
|
||||
* Owns terminal lifecycle operations, output fanout, and session state
|
||||
* transitions for thread-scoped terminals.
|
||||
*
|
||||
* @module TerminalManager
|
||||
*/
|
||||
import {
|
||||
TerminalAttachInput,
|
||||
TerminalAttachStreamEvent,
|
||||
TerminalClearInput,
|
||||
TerminalCloseInput,
|
||||
TerminalEvent,
|
||||
TerminalCwdError,
|
||||
TerminalError,
|
||||
TerminalHistoryError,
|
||||
TerminalMetadataStreamEvent,
|
||||
TerminalNotRunningError,
|
||||
TerminalOpenInput,
|
||||
TerminalResizeInput,
|
||||
TerminalRestartInput,
|
||||
TerminalSessionSnapshot,
|
||||
TerminalSessionLookupError,
|
||||
TerminalSessionStatus,
|
||||
TerminalWriteInput,
|
||||
} from "@t3tools/contracts";
|
||||
import type { PtyProcess } from "./PTY.ts";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Context from "effect/Context";
|
||||
|
||||
export {
|
||||
TerminalCwdError,
|
||||
TerminalError,
|
||||
TerminalHistoryError,
|
||||
TerminalNotRunningError,
|
||||
TerminalSessionLookupError,
|
||||
};
|
||||
|
||||
export interface TerminalSessionState {
|
||||
threadId: string;
|
||||
terminalId: string;
|
||||
cwd: string;
|
||||
worktreePath: string | null;
|
||||
status: TerminalSessionStatus;
|
||||
pid: number | null;
|
||||
history: string;
|
||||
pendingHistoryControlSequence: string;
|
||||
exitCode: number | null;
|
||||
exitSignal: number | null;
|
||||
updatedAt: string;
|
||||
cols: number;
|
||||
rows: number;
|
||||
process: PtyProcess | null;
|
||||
unsubscribeData: (() => void) | null;
|
||||
unsubscribeExit: (() => void) | null;
|
||||
hasRunningSubprocess: boolean;
|
||||
runtimeEnv: Record<string, string> | null;
|
||||
}
|
||||
|
||||
export interface ShellCandidate {
|
||||
shell: string;
|
||||
args?: string[];
|
||||
}
|
||||
|
||||
export interface TerminalStartInput extends TerminalOpenInput {
|
||||
cols: number;
|
||||
rows: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* TerminalManagerShape - Service API for terminal session lifecycle operations.
|
||||
*/
|
||||
export interface TerminalManagerShape {
|
||||
/**
|
||||
* Open or attach to a terminal session.
|
||||
*
|
||||
* Reuses an existing session for the same thread/terminal id and restores
|
||||
* persisted history on first open.
|
||||
*/
|
||||
readonly open: (
|
||||
input: TerminalOpenInput,
|
||||
) => Effect.Effect<TerminalSessionSnapshot, TerminalError>;
|
||||
|
||||
/**
|
||||
* Attach to a terminal and stream its initial snapshot followed by live events.
|
||||
*
|
||||
* Returns an unsubscribe function.
|
||||
*/
|
||||
readonly attachStream: (
|
||||
input: TerminalAttachInput,
|
||||
listener: (event: TerminalAttachStreamEvent) => Effect.Effect<void>,
|
||||
) => Effect.Effect<() => void, TerminalError>;
|
||||
|
||||
/**
|
||||
* Write input bytes to a terminal session.
|
||||
*/
|
||||
readonly write: (input: TerminalWriteInput) => Effect.Effect<void, TerminalError>;
|
||||
|
||||
/**
|
||||
* Resize the PTY backing a terminal session.
|
||||
*/
|
||||
readonly resize: (input: TerminalResizeInput) => Effect.Effect<void, TerminalError>;
|
||||
|
||||
/**
|
||||
* Clear terminal output history.
|
||||
*/
|
||||
readonly clear: (input: TerminalClearInput) => Effect.Effect<void, TerminalError>;
|
||||
|
||||
/**
|
||||
* Restart a terminal session in place.
|
||||
*
|
||||
* Always resets history before spawning the new process.
|
||||
*/
|
||||
readonly restart: (
|
||||
input: TerminalRestartInput,
|
||||
) => Effect.Effect<TerminalSessionSnapshot, TerminalError>;
|
||||
|
||||
/**
|
||||
* Close an active terminal session.
|
||||
*
|
||||
* When `terminalId` is omitted, closes all sessions for the thread.
|
||||
*/
|
||||
readonly close: (input: TerminalCloseInput) => Effect.Effect<void, TerminalError>;
|
||||
|
||||
/**
|
||||
* Subscribe to terminal runtime events with a direct callback.
|
||||
*
|
||||
* Returns an unsubscribe function.
|
||||
*/
|
||||
readonly subscribe: (
|
||||
listener: (event: TerminalEvent) => Effect.Effect<void>,
|
||||
) => Effect.Effect<() => void>;
|
||||
|
||||
/**
|
||||
* Subscribe to lightweight terminal metadata with an initial full snapshot.
|
||||
*
|
||||
* Returns an unsubscribe function.
|
||||
*/
|
||||
readonly subscribeMetadata: (
|
||||
listener: (event: TerminalMetadataStreamEvent) => Effect.Effect<void>,
|
||||
) => Effect.Effect<() => void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* TerminalManager - Service tag for terminal session orchestration.
|
||||
*/
|
||||
export class TerminalManager extends Context.Service<TerminalManager, TerminalManagerShape>()(
|
||||
"t3/terminal/Services/Manager/TerminalManager",
|
||||
) {}
|
||||
+53
-46
@@ -56,45 +56,44 @@ import { clamp } from "effect/Number";
|
||||
import { HttpRouter, HttpServerRequest, HttpServerRespondable } from "effect/unstable/http";
|
||||
import { RpcSerialization, RpcServer } from "effect/unstable/rpc";
|
||||
|
||||
import { CheckpointDiffQuery } from "./checkpointing/Services/CheckpointDiffQuery.ts";
|
||||
import { ServerConfig } from "./config.ts";
|
||||
import { Keybindings } from "./keybindings.ts";
|
||||
import * as CheckpointDiffQuery from "./checkpointing/Services/CheckpointDiffQuery.ts";
|
||||
import * as ServerConfig from "./config.ts";
|
||||
import * as Keybindings from "./keybindings.ts";
|
||||
import * as ExternalLauncher from "./process/externalLauncher.ts";
|
||||
import { normalizeDispatchCommand } from "./orchestration/Normalizer.ts";
|
||||
import { OrchestrationEngineService } from "./orchestration/Services/OrchestrationEngine.ts";
|
||||
import { ProjectionSnapshotQuery } from "./orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import * as OrchestrationEngine from "./orchestration/Services/OrchestrationEngine.ts";
|
||||
import * as ProjectionSnapshotQuery from "./orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import {
|
||||
observeRpcEffect as instrumentRpcEffect,
|
||||
observeRpcStream as instrumentRpcStream,
|
||||
observeRpcStreamEffect as instrumentRpcStreamEffect,
|
||||
} from "./observability/RpcInstrumentation.ts";
|
||||
import { ProviderRegistry } from "./provider/Services/ProviderRegistry.ts";
|
||||
import * as ProviderRegistry from "./provider/Services/ProviderRegistry.ts";
|
||||
import * as ProviderMaintenanceRunner from "./provider/providerMaintenanceRunner.ts";
|
||||
import { ServerLifecycleEvents } from "./serverLifecycleEvents.ts";
|
||||
import { ServerRuntimeStartup } from "./serverRuntimeStartup.ts";
|
||||
import { redactServerSettingsForClient, ServerSettingsService } from "./serverSettings.ts";
|
||||
import { TerminalManager } from "./terminal/Services/Manager.ts";
|
||||
import * as ServerLifecycleEvents from "./serverLifecycleEvents.ts";
|
||||
import * as ServerRuntimeStartup from "./serverRuntimeStartup.ts";
|
||||
import * as ServerSettings from "./serverSettings.ts";
|
||||
import * as TerminalManager from "./terminal/Manager.ts";
|
||||
import * as PreviewAutomationBroker from "./mcp/PreviewAutomationBroker.ts";
|
||||
import * as PreviewManager from "./preview/Manager.ts";
|
||||
import { issueAssetUrl } from "./assets/AssetAccess.ts";
|
||||
import * as PortScanner from "./preview/PortScanner.ts";
|
||||
import * as WorkspaceEntries from "./workspace/WorkspaceEntries.ts";
|
||||
import { WorkspaceFileSystem } from "./workspace/Services/WorkspaceFileSystem.ts";
|
||||
import { WorkspacePathOutsideRootError } from "./workspace/Services/WorkspacePaths.ts";
|
||||
import { VcsStatusBroadcaster } from "./vcs/VcsStatusBroadcaster.ts";
|
||||
import { VcsProvisioningService } from "./vcs/VcsProvisioningService.ts";
|
||||
import { GitWorkflowService } from "./git/GitWorkflowService.ts";
|
||||
import { ReviewService } from "./review/ReviewService.ts";
|
||||
import { ProjectSetupScriptRunner } from "./project/Services/ProjectSetupScriptRunner.ts";
|
||||
import { RepositoryIdentityResolver } from "./project/Services/RepositoryIdentityResolver.ts";
|
||||
import { ServerEnvironment } from "./environment/Services/ServerEnvironment.ts";
|
||||
import * as WorkspaceFileSystem from "./workspace/Services/WorkspaceFileSystem.ts";
|
||||
import * as WorkspacePaths from "./workspace/Services/WorkspacePaths.ts";
|
||||
import * as VcsStatusBroadcaster from "./vcs/VcsStatusBroadcaster.ts";
|
||||
import * as VcsProvisioningService from "./vcs/VcsProvisioningService.ts";
|
||||
import * as GitWorkflowService from "./git/GitWorkflowService.ts";
|
||||
import * as ReviewService from "./review/ReviewService.ts";
|
||||
import * as ProjectSetupScriptRunner from "./project/Services/ProjectSetupScriptRunner.ts";
|
||||
import * as RepositoryIdentityResolver from "./project/Services/RepositoryIdentityResolver.ts";
|
||||
import * as ServerEnvironment from "./environment/Services/ServerEnvironment.ts";
|
||||
import * as EnvironmentAuth from "./auth/EnvironmentAuth.ts";
|
||||
import type { AuthenticatedSession } from "./auth/EnvironmentAuth.ts";
|
||||
import * as ProcessDiagnostics from "./diagnostics/ProcessDiagnostics.ts";
|
||||
import * as ProcessResourceMonitor from "./diagnostics/ProcessResourceMonitor.ts";
|
||||
import * as TraceDiagnostics from "./diagnostics/TraceDiagnostics.ts";
|
||||
import * as SourceControlDiscoveryLayer from "./sourceControl/SourceControlDiscovery.ts";
|
||||
import { SourceControlRepositoryService } from "./sourceControl/SourceControlRepositoryService.ts";
|
||||
import * as SourceControlRepositoryService from "./sourceControl/SourceControlRepositoryService.ts";
|
||||
import * as AzureDevOpsCli from "./sourceControl/AzureDevOpsCli.ts";
|
||||
import * as BitbucketApi from "./sourceControl/BitbucketApi.ts";
|
||||
import * as GitHubCli from "./sourceControl/GitHubCli.ts";
|
||||
@@ -109,7 +108,7 @@ import * as SessionStore from "./auth/SessionStore.ts";
|
||||
import { failEnvironmentAuthInvalid, failEnvironmentInternal } from "./auth/http.ts";
|
||||
import * as RelayClient from "@t3tools/shared/relayClient";
|
||||
const isOrchestrationDispatchCommandError = Schema.is(OrchestrationDispatchCommandError);
|
||||
const isWorkspacePathOutsideRootError = Schema.is(WorkspacePathOutsideRootError);
|
||||
const isWorkspacePathOutsideRootError = Schema.is(WorkspacePaths.WorkspacePathOutsideRootError);
|
||||
|
||||
const nowIso = Effect.map(DateTime.now, DateTime.formatIso);
|
||||
|
||||
@@ -248,35 +247,36 @@ function toAuthAccessStreamEvent(
|
||||
}
|
||||
}
|
||||
|
||||
const makeWsRpcLayer = (currentSession: AuthenticatedSession) =>
|
||||
const makeWsRpcLayer = (currentSession: EnvironmentAuth.AuthenticatedSession) =>
|
||||
WsRpcGroup.toLayer(
|
||||
Effect.gen(function* () {
|
||||
const currentSessionId = currentSession.sessionId;
|
||||
const crypto = yield* Crypto.Crypto;
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
const orchestrationEngine = yield* OrchestrationEngineService;
|
||||
const checkpointDiffQuery = yield* CheckpointDiffQuery;
|
||||
const keybindings = yield* Keybindings;
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;
|
||||
const orchestrationEngine = yield* OrchestrationEngine.OrchestrationEngineService;
|
||||
const checkpointDiffQuery = yield* CheckpointDiffQuery.CheckpointDiffQuery;
|
||||
const keybindings = yield* Keybindings.Keybindings;
|
||||
const externalLauncher = yield* ExternalLauncher.ExternalLauncher;
|
||||
const gitWorkflow = yield* GitWorkflowService;
|
||||
const review = yield* ReviewService;
|
||||
const vcsProvisioning = yield* VcsProvisioningService;
|
||||
const vcsStatusBroadcaster = yield* VcsStatusBroadcaster;
|
||||
const terminalManager = yield* TerminalManager;
|
||||
const gitWorkflow = yield* GitWorkflowService.GitWorkflowService;
|
||||
const review = yield* ReviewService.ReviewService;
|
||||
const vcsProvisioning = yield* VcsProvisioningService.VcsProvisioningService;
|
||||
const vcsStatusBroadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
|
||||
const terminalManager = yield* TerminalManager.TerminalManager;
|
||||
const previewAutomationBroker = yield* PreviewAutomationBroker.PreviewAutomationBroker;
|
||||
const previewManager = yield* PreviewManager.PreviewManager;
|
||||
const portDiscovery = yield* PortScanner.PortDiscovery;
|
||||
const providerRegistry = yield* ProviderRegistry;
|
||||
const providerRegistry = yield* ProviderRegistry.ProviderRegistry;
|
||||
const providerMaintenanceRunner = yield* ProviderMaintenanceRunner.ProviderMaintenanceRunner;
|
||||
const config = yield* ServerConfig;
|
||||
const lifecycleEvents = yield* ServerLifecycleEvents;
|
||||
const serverSettings = yield* ServerSettingsService;
|
||||
const startup = yield* ServerRuntimeStartup;
|
||||
const config = yield* ServerConfig.ServerConfig;
|
||||
const lifecycleEvents = yield* ServerLifecycleEvents.ServerLifecycleEvents;
|
||||
const serverSettings = yield* ServerSettings.ServerSettingsService;
|
||||
const startup = yield* ServerRuntimeStartup.ServerRuntimeStartup;
|
||||
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
|
||||
const workspaceFileSystem = yield* WorkspaceFileSystem;
|
||||
const projectSetupScriptRunner = yield* ProjectSetupScriptRunner;
|
||||
const repositoryIdentityResolver = yield* RepositoryIdentityResolver;
|
||||
const serverEnvironment = yield* ServerEnvironment;
|
||||
const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
|
||||
const projectSetupScriptRunner = yield* ProjectSetupScriptRunner.ProjectSetupScriptRunner;
|
||||
const repositoryIdentityResolver =
|
||||
yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
|
||||
const serverEnvironment = yield* ServerEnvironment.ServerEnvironment;
|
||||
const serverAuth = yield* EnvironmentAuth.EnvironmentAuth;
|
||||
const sourceControlDiscovery = yield* SourceControlDiscoveryLayer.SourceControlDiscovery;
|
||||
const automaticGitFetchInterval = serverSettings.getSettings.pipe(
|
||||
@@ -287,7 +287,8 @@ const makeWsRpcLayer = (currentSession: AuthenticatedSession) =>
|
||||
}).pipe(Effect.as(DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL)),
|
||||
),
|
||||
);
|
||||
const sourceControlRepositories = yield* SourceControlRepositoryService;
|
||||
const sourceControlRepositories =
|
||||
yield* SourceControlRepositoryService.SourceControlRepositoryService;
|
||||
const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
|
||||
const sessions = yield* SessionStore.SessionStore;
|
||||
const processDiagnostics = yield* ProcessDiagnostics.ProcessDiagnostics;
|
||||
@@ -766,7 +767,9 @@ const makeWsRpcLayer = (currentSession: AuthenticatedSession) =>
|
||||
const loadServerConfig = Effect.gen(function* () {
|
||||
const keybindingsConfig = yield* keybindings.loadConfigState;
|
||||
const providers = yield* providerRegistry.getProviders;
|
||||
const settings = redactServerSettingsForClient(yield* serverSettings.getSettings);
|
||||
const settings = ServerSettings.redactServerSettingsForClient(
|
||||
yield* serverSettings.getSettings,
|
||||
);
|
||||
const environment = yield* serverEnvironment.getDescriptor;
|
||||
const auth = yield* serverAuth.getDescriptor();
|
||||
|
||||
@@ -1068,7 +1071,9 @@ const makeWsRpcLayer = (currentSession: AuthenticatedSession) =>
|
||||
[WS_METHODS.serverGetSettings]: (_input) =>
|
||||
observeRpcEffect(
|
||||
WS_METHODS.serverGetSettings,
|
||||
serverSettings.getSettings.pipe(Effect.map(redactServerSettingsForClient)),
|
||||
serverSettings.getSettings.pipe(
|
||||
Effect.map(ServerSettings.redactServerSettingsForClient),
|
||||
),
|
||||
{
|
||||
"rpc.aggregate": "server",
|
||||
},
|
||||
@@ -1076,7 +1081,9 @@ const makeWsRpcLayer = (currentSession: AuthenticatedSession) =>
|
||||
[WS_METHODS.serverUpdateSettings]: ({ patch }) =>
|
||||
observeRpcEffect(
|
||||
WS_METHODS.serverUpdateSettings,
|
||||
serverSettings.updateSettings(patch).pipe(Effect.map(redactServerSettingsForClient)),
|
||||
serverSettings
|
||||
.updateSettings(patch)
|
||||
.pipe(Effect.map(ServerSettings.redactServerSettingsForClient)),
|
||||
{
|
||||
"rpc.aggregate": "server",
|
||||
},
|
||||
@@ -1559,7 +1566,7 @@ const makeWsRpcLayer = (currentSession: AuthenticatedSession) =>
|
||||
Stream.debounce(Duration.millis(PROVIDER_STATUS_DEBOUNCE_MS)),
|
||||
);
|
||||
const settingsUpdates = serverSettings.streamChanges.pipe(
|
||||
Stream.map((settings) => redactServerSettingsForClient(settings)),
|
||||
Stream.map((settings) => ServerSettings.redactServerSettingsForClient(settings)),
|
||||
Stream.map((settings) => ({
|
||||
version: 1 as const,
|
||||
type: "settingsUpdated" as const,
|
||||
|
||||
Reference in new issue
Block a user