The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 06:15 UTC
Harden secret store and resolve catalog overrides (#1891)
Co-authored-by: codex <codex@users.noreply.github.com>
Julius Marminge committed
Apr 10, 2026 at 13:09 UTC
e3004ae806d4e9a81e03ff919f50d2d34c37ffe7
16 files changed
+106
-102
apps/server/scripts/cli.ts
+24
-2
@@ -14,6 +14,22 @@ import { resolveCatalogDependencies } from "../../../scripts/lib/resolve-catalog
14
import rootPackageJson from "../../../package.json" with { type: "json" };
15
import serverPackageJson from "../package.json" with { type: "json" };
16
17
+interface PackageJson {
18
+ name: string;
19
+ repository: {
20
+ type: string;
21
+ url: string;
22
+ directory: string;
23
+ };
24
+ bin: Record<string, string>;
25
+ type: string;
26
+ version: string;
27
+ engines: Record<string, string>;
28
+ files: string[];
29
+ dependencies: Record<string, string>;
30
+ overrides: Record<string, string>;
31
+}
32
+
33
class CliError extends Data.TaggedError("CliError")<{
34
readonly message: string;
35
readonly cause?: unknown;
@@ -192,7 +208,7 @@ const publishCmd = Command.make(
208
// Resolve catalog dependencies before any file mutations. If this throws,
209
// acquire fails and no release hook runs, so filesystem must still be untouched.
210
const version = Option.getOrElse(config.appVersion, () => serverPackageJson.version);
195
- const pkg = {
211
+ const pkg: PackageJson = {
212
name: serverPackageJson.name,
213
repository: serverPackageJson.repository,
214
bin: serverPackageJson.bin,
@@ -200,7 +216,8 @@ const publishCmd = Command.make(
216
version,
217
engines: serverPackageJson.engines,
218
files: serverPackageJson.files,
203
- dependencies: serverPackageJson.dependencies as Record<string, unknown>,
219
+ dependencies: serverPackageJson.dependencies,
220
+ overrides: rootPackageJson.overrides,
221
};
222
223
pkg.dependencies = resolveCatalogDependencies(
@@ -208,6 +225,11 @@ const publishCmd = Command.make(
225
rootPackageJson.workspaces.catalog,
226
"apps/server dependencies",
227
);
228
+ pkg.overrides = resolveCatalogDependencies(
229
+ pkg.overrides,
230
+ rootPackageJson.workspaces.catalog,
231
+ "root overrides",
232
+ );
233
234
const original = yield* fs.readFileString(packageJsonPath);
235
yield* fs.writeFileString(backupPath, original);
apps/server/src/auth/Layers/ServerSecretStore.ts
+6
-9
@@ -1,6 +1,6 @@
1
import * as Crypto from "node:crypto";
2
3
-import { Effect, FileSystem, Layer, Path } from "effect";
3
+import { Effect, FileSystem, Layer, Path, Predicate } from "effect";
4
import * as PlatformError from "effect/PlatformError";
5
6
import { ServerConfig } from "../../config.ts";
@@ -28,17 +28,14 @@ export const makeServerSecretStore = Effect.gen(function* () {
28
29
const resolveSecretPath = (name: string) => path.join(serverConfig.secretsDir, `${name}.bin`);
30
31
- const isMissingSecretFileError = (cause: unknown): cause is PlatformError.PlatformError =>
32
- cause instanceof PlatformError.PlatformError && cause.reason._tag === "NotFound";
33
-
34
- const isAlreadyExistsSecretFileError = (cause: unknown): cause is PlatformError.PlatformError =>
35
- cause instanceof PlatformError.PlatformError && cause.reason._tag === "AlreadyExists";
31
+ const isPlatformError = (u: unknown): u is PlatformError.PlatformError =>
32
+ Predicate.isTagged(u, "PlatformError");
33
34
const get: ServerSecretStoreShape["get"] = (name) =>
35
fileSystem.readFile(resolveSecretPath(name)).pipe(
36
Effect.map((bytes) => Uint8Array.from(bytes)),
37
Effect.catch((cause) =>
41
- isMissingSecretFileError(cause)
38
+ cause.reason._tag === "NotFound"
39
? Effect.succeed(null)
40
: Effect.fail(
41
new SecretStoreError({
@@ -108,7 +105,7 @@ export const makeServerSecretStore = Effect.gen(function* () {
105
return create(name, generated).pipe(
106
Effect.as(Uint8Array.from(generated)),
107
Effect.catchTag("SecretStoreError", (error) =>
111
- isAlreadyExistsSecretFileError(error.cause)
108
+ isPlatformError(error.cause) && error.cause.reason._tag === "AlreadyExists"
109
? get(name).pipe(
110
Effect.flatMap((created) =>
111
created !== null
@@ -129,7 +126,7 @@ export const makeServerSecretStore = Effect.gen(function* () {
126
const remove: ServerSecretStoreShape["remove"] = (name) =>
127
fileSystem.remove(resolveSecretPath(name)).pipe(
128
Effect.catch((cause) =>
132
- isMissingSecretFileError(cause)
129
+ cause.reason._tag === "NotFound"
130
? Effect.void
131
: Effect.fail(
132
new SecretStoreError({
apps/server/src/git/Layers/GitCore.ts
+1
-1
@@ -2001,7 +2001,7 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: {
2001
"GitCore.removeWorktree",
2002
input.cwd,
2003
args,
2004
- `${commandLabel(args)} failed (cwd: ${input.cwd}): ${error instanceof Error ? error.message : String(error)}`,
2004
+ `${commandLabel(args)} failed (cwd: ${input.cwd}): ${error.message}`,
2005
error,
2006
),
2007
),
apps/server/src/git/Layers/GitHubCli.ts
+2
-2
@@ -1,4 +1,4 @@
1
-import { Effect, Layer, Schema } from "effect";
1
+import { Effect, Layer, Schema, SchemaIssue } from "effect";
2
import { PositiveInt, TrimmedNonEmptyString } from "@t3tools/contracts";
3
4
import { runProcess } from "../../processRunner";
@@ -154,7 +154,7 @@ function decodeGitHubJson<S extends Schema.Top>(
154
(error) =>
155
new GitHubCliError({
156
operation,
157
- detail: error instanceof Error ? `${invalidDetail}: ${error.message}` : invalidDetail,
157
+ detail: `${invalidDetail}: ${SchemaIssue.makeFormatterDefault()(error.issue)}`,
158
cause: error,
159
}),
160
),
apps/server/src/provider/Layers/CodexAdapter.test.ts
-7
@@ -238,14 +238,7 @@ sessionErrorLayer("CodexAdapterLive session errors", (it) => {
238
.pipe(Effect.result);
239
240
assert.equal(result._tag, "Failure");
241
- if (result._tag !== "Failure") {
242
- return;
243
- }
244
-
241
assert.equal(result.failure._tag, "ProviderAdapterSessionNotFoundError");
246
- if (result.failure._tag !== "ProviderAdapterSessionNotFoundError") {
247
- return;
248
- }
242
assert.equal(result.failure.provider, "codex");
243
assert.equal(result.failure.threadId, "sess-missing");
244
assert.equal(result.failure.cause instanceof Error, true);
apps/server/src/provider/Layers/CodexAdapter.ts
+4
-11
@@ -51,18 +51,11 @@ export interface CodexAdapterLiveOptions {
51
readonly nativeEventLogger?: EventNdjsonLogger;
52
}
53
54
-function toMessage(cause: unknown, fallback: string): string {
55
- if (cause instanceof Error && cause.message.length > 0) {
56
- return cause.message;
57
- }
58
- return fallback;
59
-}
60
-
54
function toSessionError(
55
threadId: ThreadId,
56
cause: unknown,
57
): ProviderAdapterSessionNotFoundError | ProviderAdapterSessionClosedError | undefined {
65
- const normalized = toMessage(cause, "").toLowerCase();
58
+ const normalized = cause instanceof Error ? cause.message.toLowerCase() : "";
59
if (normalized.includes("unknown session") || normalized.includes("unknown provider session")) {
60
return new ProviderAdapterSessionNotFoundError({
61
provider: PROVIDER,
@@ -88,7 +81,7 @@ function toRequestError(threadId: ThreadId, method: string, cause: unknown): Pro
81
return new ProviderAdapterRequestError({
82
provider: PROVIDER,
83
method,
91
- detail: toMessage(cause, `${method} failed`),
84
+ detail: cause instanceof Error ? `${method} failed: ${cause.message}` : `${method} failed`,
85
cause,
86
});
87
}
@@ -1427,7 +1420,7 @@ const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (
1420
new ProviderAdapterProcessError({
1421
provider: PROVIDER,
1422
threadId: input.threadId,
1430
- detail: toMessage(cause, "Failed to start Codex adapter session."),
1423
+ detail: `Failed to start Codex adapter session: ${cause instanceof Error ? cause.message : String(cause)}.`,
1424
cause,
1425
}),
1426
});
@@ -1455,7 +1448,7 @@ const makeCodexAdapter = Effect.fn("makeCodexAdapter")(function* (
1448
new ProviderAdapterRequestError({
1449
provider: PROVIDER,
1450
method: "turn/start",
1458
- detail: toMessage(cause, "Failed to read attachment file."),
1451
+ detail: `Failed to read attachment file: ${cause.message}.`,
1452
cause,
1453
}),
1454
),
apps/server/src/provider/Layers/CodexProvider.ts
+2
-5
@@ -389,7 +389,7 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
389
auth: { status: "unknown" },
390
message: isCommandMissingCause(error)
391
? "Codex CLI (`codex`) is not installed or not on PATH."
392
- : `Failed to execute Codex CLI health check: ${error instanceof Error ? error.message : String(error)}.`,
392
+ : `Failed to execute Codex CLI health check: ${error.message}.`,
393
},
394
});
395
}
@@ -489,10 +489,7 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
489
version: parsedVersion,
490
status: "warning",
491
auth: { status: "unknown" },
492
- message:
493
- error instanceof Error
494
- ? `Could not verify Codex authentication status: ${error.message}.`
495
- : "Could not verify Codex authentication status.",
492
+ message: `Could not verify Codex authentication status: ${error.message}.`,
493
},
494
});
495
}
apps/server/src/provider/providerSnapshot.ts
+1
-2
@@ -32,8 +32,7 @@ export function nonEmptyTrimmed(value: string | undefined): string | undefined {
32
return trimmed.length > 0 ? trimmed : undefined;
33
}
34
35
-export function isCommandMissingCause(error: unknown): boolean {
36
- if (!(error instanceof Error)) return false;
35
+export function isCommandMissingCause(error: Error): boolean {
36
const lower = error.message.toLowerCase();
37
return lower.includes("enoent") || lower.includes("notfound");
38
}
apps/server/src/terminal/Layers/Manager.ts
+31
-26
@@ -8,7 +8,6 @@ import {
8
} from "@t3tools/contracts";
9
import { makeKeyedCoalescingWorker } from "@t3tools/shared/KeyedCoalescingWorker";
10
import {
11
- Data,
11
Effect,
12
Encoding,
13
Equal,
@@ -17,6 +16,7 @@ import {
16
FileSystem,
17
Layer,
18
Option,
19
+ Schema,
20
Scope,
21
Semaphore,
22
SynchronizedRef,
@@ -54,22 +54,28 @@ const DEFAULT_OPEN_COLS = 120;
54
const DEFAULT_OPEN_ROWS = 30;
55
const TERMINAL_ENV_BLOCKLIST = new Set(["PORT", "ELECTRON_RENDERER_PORT", "ELECTRON_RUN_AS_NODE"]);
56
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
+) {}
75
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
+}
79
80
interface ShellCandidate {
81
shell: string;
@@ -271,9 +277,8 @@ function isRetryableShellSpawnError(error: PtySpawnError): boolean {
277
278
if (current instanceof Error) {
279
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);
282
}
283
continue;
284
}
@@ -876,7 +881,7 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
881
Effect.logWarning("failed to persist terminal history", {
882
threadId,
883
terminalId,
879
- error: error instanceof Error ? error.message : String(error),
884
+ error,
885
}),
886
),
887
);
@@ -959,7 +964,7 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
964
Effect.catch((cleanupError) =>
965
Effect.logWarning("failed to remove legacy terminal history", {
966
threadId,
962
- error: cleanupError instanceof Error ? cleanupError.message : String(cleanupError),
967
+ error: cleanupError,
968
}),
969
),
970
);
@@ -975,7 +980,7 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
980
Effect.logWarning("failed to delete terminal history", {
981
threadId,
982
terminalId,
978
- error: error instanceof Error ? error.message : String(error),
983
+ error,
984
}),
985
),
986
);
@@ -985,7 +990,7 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
990
Effect.logWarning("failed to delete terminal history", {
991
threadId,
992
terminalId,
988
- error: error instanceof Error ? error.message : String(error),
993
+ error,
994
}),
995
),
996
);
@@ -1011,7 +1016,7 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
1016
Effect.catch((error) =>
1017
Effect.logWarning("failed to delete terminal histories for thread", {
1018
threadId,
1014
- error: error instanceof Error ? error.message : String(error),
1019
+ error,
1020
}),
1021
),
1022
),
@@ -1463,12 +1468,12 @@ export const makeTerminalManagerWithOptions = Effect.fn("makeTerminalManagerWith
1468
const terminalPid = session.pid;
1469
const hasRunningSubprocess = yield* subprocessChecker(terminalPid).pipe(
1470
Effect.map(Option.some),
1466
- Effect.catch((error) =>
1471
+ Effect.catch((reason) =>
1472
Effect.logWarning("failed to check terminal subprocess activity", {
1473
threadId: session.threadId,
1474
terminalId: session.terminalId,
1475
terminalPid,
1471
- error: error instanceof Error ? error.message : String(error),
1476
+ reason,
1477
}).pipe(Effect.as(Option.none<boolean>())),
1478
),
1479
);
apps/server/src/workspace/Layers/WorkspaceEntries.ts
+1
-4
@@ -214,9 +214,6 @@ function directoryAncestorsOf(relativePath: string): string[] {
214
return directories;
215
}
216
217
-const processErrorDetail = (cause: unknown): string =>
218
- cause instanceof Error ? cause.message : String(cause);
219
-
217
export const makeWorkspaceEntries = Effect.gen(function* () {
218
const path = yield* Path.Path;
219
const gitOption = yield* Effect.serviceOption(GitCore);
@@ -319,7 +316,7 @@ export const makeWorkspaceEntries = Effect.gen(function* () {
316
new WorkspaceEntriesError({
317
cwd,
318
operation: "workspaceEntries.readDirectoryEntries",
322
- detail: processErrorDetail(cause),
319
+ detail: cause instanceof Error ? cause.message : String(cause),
320
cause,
321
}),
322
}).pipe(
apps/server/src/ws.ts
+1
-4
@@ -313,10 +313,7 @@ const makeWsRpcLayer = (currentSessionId: AuthSessionId) =>
313
worktreePath: input.worktreePath,
314
scriptId: input.scriptId,
315
terminalId: input.terminalId,
316
- detail:
317
- error instanceof Error
318
- ? error.message
319
- : "Unknown setup activity dispatch failure.",
316
+ detail: error.message,
317
},
318
),
319
),
apps/web/src/environments/primary/auth.ts
+17
-19
@@ -16,6 +16,14 @@ import {
16
} from "../../pairingUrl";
17
18
import { resolvePrimaryEnvironmentHttpUrl } from "./target";
19
+import { Data, Predicate } from "effect";
20
+
21
+export class BootstrapHttpError extends Data.TaggedError("BootstrapHttpError")<{
22
+ readonly message: string;
23
+ readonly status: number;
24
+}> {}
25
+const isBootstrapHttpError = (u: unknown): u is BootstrapHttpError =>
26
+ Predicate.isTagged(u, "BootstrapHttpError");
27
28
export interface ServerPairingLinkRecord {
29
readonly id: string;
@@ -87,10 +95,10 @@ export async function fetchSessionState(): Promise<AuthSessionState> {
95
credentials: "include",
96
});
97
if (!response.ok) {
90
- throw new BootstrapHttpError(
91
- `Failed to load server auth session state (${response.status}).`,
92
- response.status,
93
- );
98
+ throw new BootstrapHttpError({
99
+ message: `Failed to load server auth session state (${response.status}).`,
100
+ status: response.status,
101
+ });
102
}
103
return (await response.json()) as AuthSessionState;
104
});
@@ -115,10 +123,10 @@ async function exchangeBootstrapCredential(credential: string): Promise<AuthBoot
123
124
if (!response.ok) {
125
const message = await response.text();
118
- throw new BootstrapHttpError(
119
- message || `Failed to bootstrap auth session (${response.status}).`,
120
- response.status,
121
- );
126
+ throw new BootstrapHttpError({
127
+ message: message || `Failed to bootstrap auth session (${response.status}).`,
128
+ status: response.status,
129
+ });
130
}
131
132
return (await response.json()) as AuthBootstrapResult;
@@ -146,16 +154,6 @@ const TRANSIENT_BOOTSTRAP_STATUS_CODES = new Set([502, 503, 504]);
154
const BOOTSTRAP_RETRY_TIMEOUT_MS = 15_000;
155
const BOOTSTRAP_RETRY_STEP_MS = 500;
156
149
-export class BootstrapHttpError extends Error {
150
- readonly status: number;
151
-
152
- constructor(message: string, status: number) {
153
- super(message);
154
- this.name = "BootstrapHttpError";
155
- this.status = status;
156
- }
157
-}
158
-
157
export async function retryTransientBootstrap<T>(operation: () => Promise<T>): Promise<T> {
158
const startedAt = Date.now();
159
while (true) {
@@ -182,7 +180,7 @@ function waitForBootstrapRetry(delayMs: number): Promise<void> {
180
}
181
182
function isTransientBootstrapError(error: unknown): boolean {
185
- if (error instanceof BootstrapHttpError) {
183
+ if (isBootstrapHttpError(error)) {
184
return TRANSIENT_BOOTSTRAP_STATUS_CODES.has(error.status);
185
}
186
apps/web/src/environments/primary/context.ts
+4
-4
@@ -52,10 +52,10 @@ async function fetchPrimaryEnvironmentDescriptor(): Promise<ExecutionEnvironment
52
resolvePrimaryEnvironmentHttpUrl(SERVER_ENVIRONMENT_DESCRIPTOR_PATH),
53
);
54
if (!response.ok) {
55
- throw new BootstrapHttpError(
56
- `Failed to load server environment descriptor (${response.status}).`,
57
- response.status,
58
- );
55
+ throw new BootstrapHttpError({
56
+ message: `Failed to load server environment descriptor (${response.status}).`,
57
+ status: response.status,
58
+ });
59
}
60
61
const descriptor = (await response.json()) as ExecutionEnvironmentDescriptor;
package.json
+6
@@ -62,7 +62,13 @@
62
"vitest": "catalog:"
63
},
64
"overrides": {
65
+ "@effect/atom-react": "catalog:",
66
+ "@effect/platform-bun": "catalog:",
67
+ "@effect/platform-node": "catalog:",
68
"@effect/platform-node-shared": "catalog:",
69
+ "@effect/sql-sqlite-bun": "catalog:",
70
+ "@effect/vitest": "catalog:",
71
+ "effect": "catalog:",
72
"vite": "^8.0.0"
73
},
74
"engines": {
scripts/build-desktop-artifact.ts
+3
-3
@@ -427,9 +427,9 @@ function validateBundledClientAssets(clientDir: string) {
427
}
428
429
function resolveDesktopRuntimeDependencies(
430
- dependencies: Record<string, unknown> | undefined,
431
- catalog: Record<string, unknown>,
432
-): Record<string, unknown> {
430
+ dependencies: Record<string, string> | undefined,
431
+ catalog: Record<string, string>,
432
+): Record<string, string> {
433
if (!dependencies || Object.keys(dependencies).length === 0) {
434
return {};
435
}
scripts/lib/resolve-catalog.ts
+3
-3
@@ -5,10 +5,10 @@
5
* the concrete version string found in `catalog`. Throws on missing entries.
6
*/
7
export function resolveCatalogDependencies(
8
- dependencies: Record<string, unknown>,
9
- catalog: Record<string, unknown>,
8
+ dependencies: Record<string, string>,
9
+ catalog: Record<string, string>,
10
label: string,
11
-): Record<string, unknown> {
11
+): Record<string, string> {
12
return Object.fromEntries(
13
Object.entries(dependencies).map(([name, spec]) => {
14
if (typeof spec !== "string" || !spec.startsWith("catalog:")) {