88} from "@t3tools/contracts" ;
99import { makeKeyedCoalescingWorker } from "@t3tools/shared/KeyedCoalescingWorker" ;
1010import {
11- Data ,
1211 Effect ,
1312 Encoding ,
1413 Equal ,
@@ -17,6 +16,7 @@ import {
1716 FileSystem ,
1817 Layer ,
1918 Option ,
19+ Schema ,
2020 Scope ,
2121 Semaphore ,
2222 SynchronizedRef ,
@@ -54,22 +54,28 @@ const DEFAULT_OPEN_COLS = 120;
5454const DEFAULT_OPEN_ROWS = 30 ;
5555const TERMINAL_ENV_BLOCKLIST = new Set ( [ "PORT" , "ELECTRON_RENDERER_PORT" , "ELECTRON_RUN_AS_NODE" ] ) ;
5656
57- type TerminalSubprocessChecker = (
58- terminalPid : number ,
59- ) => Effect . Effect < boolean , TerminalSubprocessCheckError > ;
60-
61- class TerminalSubprocessCheckError extends Data . TaggedError ( "TerminalSubprocessCheckError" ) < {
62- readonly message : string ;
63- readonly cause ?: unknown ;
64- readonly terminalPid : number ;
65- readonly command : "powershell" | "pgrep" | "ps" ;
66- } > { }
57+ class TerminalSubprocessCheckError extends Schema . TaggedErrorClass < TerminalSubprocessCheckError > ( ) (
58+ "TerminalSubprocessCheckError" ,
59+ {
60+ message : Schema . String ,
61+ cause : Schema . optional ( Schema . Defect ) ,
62+ terminalPid : Schema . Number ,
63+ command : Schema . Literals ( [ "powershell" , "pgrep" , "ps" ] ) ,
64+ } ,
65+ ) { }
66+
67+ class TerminalProcessSignalError extends Schema . TaggedErrorClass < TerminalProcessSignalError > ( ) (
68+ "TerminalProcessSignalError" ,
69+ {
70+ message : Schema . String ,
71+ cause : Schema . optional ( Schema . Defect ) ,
72+ signal : Schema . Literals ( [ "SIGTERM" , "SIGKILL" ] ) ,
73+ } ,
74+ ) { }
6775
68- class TerminalProcessSignalError extends Data . TaggedError ( "TerminalProcessSignalError" ) < {
69- readonly message : string ;
70- readonly cause ?: unknown ;
71- readonly signal : "SIGTERM" | "SIGKILL" ;
72- } > { }
76+ interface TerminalSubprocessChecker {
77+ ( terminalPid : number ) : Effect . Effect < boolean , TerminalSubprocessCheckError > ;
78+ }
7379
7480interface ShellCandidate {
7581 shell : string ;
@@ -271,9 +277,8 @@ function isRetryableShellSpawnError(error: PtySpawnError): boolean {
271277
272278 if ( current instanceof Error ) {
273279 messages . push ( current . message ) ;
274- const cause = ( current as { cause ?: unknown } ) . cause ;
275- if ( cause ) {
276- queue . push ( cause ) ;
280+ if ( current . cause ) {
281+ queue . push ( current . cause ) ;
277282 }
278283 continue ;
279284 }
@@ -876,7 +881,7 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
876881 Effect . logWarning ( "failed to persist terminal history" , {
877882 threadId,
878883 terminalId,
879- error : error instanceof Error ? error . message : String ( error ) ,
884+ error,
880885 } ) ,
881886 ) ,
882887 ) ;
@@ -959,7 +964,7 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
959964 Effect . catch ( ( cleanupError ) =>
960965 Effect . logWarning ( "failed to remove legacy terminal history" , {
961966 threadId,
962- error : cleanupError instanceof Error ? cleanupError . message : String ( cleanupError ) ,
967+ error : cleanupError ,
963968 } ) ,
964969 ) ,
965970 ) ;
@@ -975,7 +980,7 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
975980 Effect . logWarning ( "failed to delete terminal history" , {
976981 threadId,
977982 terminalId,
978- error : error instanceof Error ? error . message : String ( error ) ,
983+ error,
979984 } ) ,
980985 ) ,
981986 ) ;
@@ -985,7 +990,7 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
985990 Effect . logWarning ( "failed to delete terminal history" , {
986991 threadId,
987992 terminalId,
988- error : error instanceof Error ? error . message : String ( error ) ,
993+ error,
989994 } ) ,
990995 ) ,
991996 ) ;
@@ -1011,7 +1016,7 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
10111016 Effect . catch ( ( error ) =>
10121017 Effect . logWarning ( "failed to delete terminal histories for thread" , {
10131018 threadId,
1014- error : error instanceof Error ? error . message : String ( error ) ,
1019+ error,
10151020 } ) ,
10161021 ) ,
10171022 ) ,
@@ -1463,12 +1468,12 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
14631468 const terminalPid = session . pid ;
14641469 const hasRunningSubprocess = yield * subprocessChecker ( terminalPid ) . pipe (
14651470 Effect . map ( Option . some ) ,
1466- Effect . catch ( ( error ) =>
1471+ Effect . catch ( ( reason ) =>
14671472 Effect . logWarning ( "failed to check terminal subprocess activity" , {
14681473 threadId : session . threadId ,
14691474 terminalId : session . terminalId ,
14701475 terminalPid,
1471- error : error instanceof Error ? error . message : String ( error ) ,
1476+ reason ,
14721477 } ) . pipe ( Effect . as ( Option . none < boolean > ( ) ) ) ,
14731478 ) ,
14741479 ) ;
0 commit comments