The best way to control Claude Code, Codex and more from any computer or phone
kewl
Julius Marminge committed
Feb 27, 2026 at 20:48 UTC
6f92f0a66855ef6745814b0a91cffc2d588e0777
2 files changed
+21
-29
apps/server/src/orchestration/Layers/ProjectionPipeline.ts
+20
-26
@@ -1,3 +1,4 @@
1
+import Mime from "@effect/platform-node/Mime";
2
import {
3
ApprovalRequestId,
4
type ChatAttachment,
@@ -112,20 +113,13 @@ function parseBase64DataUrl(
113
}
114
115
function inferImageExtension(attachment: Extract<ChatAttachment, { type: "image" }>): string {
115
- const normalizedMimeType = attachment.mimeType.trim().toLowerCase();
116
+ const normalizedMimeType = attachment.mimeType.toLowerCase();
117
if (normalizedMimeType.startsWith("image/")) {
118
const fromMime = IMAGE_EXTENSION_BY_MIME_TYPE[normalizedMimeType];
118
- if (fromMime) {
119
- return fromMime;
120
- }
121
- }
122
-
123
- const fromName = attachment.name.includes(".")
124
- ? `.${attachment.name.split(".").slice(-1)[0]?.toLowerCase() ?? ""}`
125
- : "";
126
- if (/^\.[a-z0-9]{1,12}$/.test(fromName) && SAFE_IMAGE_FILE_EXTENSIONS.has(fromName)) {
127
- return fromName;
119
+ if (fromMime) return fromMime;
120
}
121
+ const ext = Mime.getExtension(attachment.mimeType);
122
+ if (ext && SAFE_IMAGE_FILE_EXTENSIONS.has(ext)) return ext;
123
return ".bin";
124
}
125
@@ -135,14 +129,10 @@ const materializeAttachmentsForProjection = Effect.fn(function* (input: {
129
readonly attachments: ReadonlyArray<ChatAttachment>;
130
readonly stageFileWrite: (pendingWrite: PendingAttachmentWrite) => void;
131
}) {
138
- if (input.attachments.length === 0) {
139
- return [] as ReadonlyArray<ChatAttachment>;
140
- }
132
+ if (input.attachments.length === 0) return [];
133
134
const serverConfig = yield* Effect.serviceOption(ServerConfig);
143
- if (Option.isNone(serverConfig)) {
144
- return input.attachments;
145
- }
135
+ if (Option.isNone(serverConfig)) return input.attachments;
136
137
const path = yield* Path.Path;
138
const attachmentsRootDir = path.join(serverConfig.value.stateDir, ATTACHMENTS_STATE_SUBDIRECTORY);
@@ -166,9 +156,7 @@ const materializeAttachmentsForProjection = Effect.fn(function* (input: {
156
}
157
158
const bytes = Buffer.from(parsed.base64, "base64");
169
- if (bytes.byteLength === 0) {
170
- return attachment;
171
- }
159
+ if (bytes.byteLength === 0) return attachment;
160
161
const fileName = `${index}${inferImageExtension({
162
...attachment,
@@ -375,9 +363,7 @@ const runAttachmentSideEffects = Effect.fn(function* (input: {
363
entries,
364
(entry) =>
365
Effect.gen(function* () {
378
- const threadRelativePath = entry
379
- .replace(/^[/\\]+/, "")
380
- .replace(/\\/g, "/");
366
+ const threadRelativePath = entry.replace(/^[/\\]+/, "").replace(/\\/g, "/");
367
if (threadRelativePath.length === 0 || threadRelativePath.startsWith("..")) {
368
return;
369
}
@@ -411,7 +397,9 @@ const runAttachmentSideEffects = Effect.fn(function* (input: {
397
writesByPath.entries(),
398
([absolutePath, bytes]) =>
399
Effect.gen(function* () {
414
- yield* input.fileSystem.makeDirectory(input.path.dirname(absolutePath), { recursive: true });
400
+ yield* input.fileSystem.makeDirectory(input.path.dirname(absolutePath), {
401
+ recursive: true,
402
+ });
403
const alreadyExists = yield* input.fileSystem
404
.exists(absolutePath)
405
.pipe(Effect.catch(() => Effect.succeed(false)));
@@ -615,7 +603,10 @@ const makeOrchestrationProjectionPipeline = Effect.gen(function* () {
603
}
604
});
605
618
- const applyThreadMessagesProjection: ProjectorDefinition["apply"] = (event, attachmentSideEffects) =>
606
+ const applyThreadMessagesProjection: ProjectorDefinition["apply"] = (
607
+ event,
608
+ attachmentSideEffects,
609
+ ) =>
610
Effect.gen(function* () {
611
switch (event.type) {
612
case "thread.message-sent": {
@@ -778,7 +769,10 @@ const makeOrchestrationProjectionPipeline = Effect.gen(function* () {
769
});
770
});
771
781
- const applyThreadTurnsProjection: ProjectorDefinition["apply"] = (event, _attachmentSideEffects) =>
772
+ const applyThreadTurnsProjection: ProjectorDefinition["apply"] = (
773
+ event,
774
+ _attachmentSideEffects,
775
+ ) =>
776
Effect.gen(function* () {
777
switch (event.type) {
778
case "thread.turn-start-requested": {
apps/server/src/wsServer.ts
+1
-3
@@ -330,9 +330,7 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
330
const staticRequestPath = url.pathname === "/" ? "/index.html" : url.pathname;
331
const rawStaticRelativePath = staticRequestPath.replace(/^[/\\]+/, "");
332
const hasRawLeadingParentSegment = rawStaticRelativePath.startsWith("..");
333
- const staticRelativePath = path
334
- .normalize(rawStaticRelativePath)
335
- .replace(/^[/\\]+/, "");
333
+ const staticRelativePath = path.normalize(rawStaticRelativePath).replace(/^[/\\]+/, "");
334
const hasPathTraversalSegment = staticRelativePath.startsWith("..");
335
if (
336
staticRelativePath.length === 0 ||