diff --git a/apps/server/src/project/ProjectSetupScriptRunner.test.ts b/apps/server/src/project/ProjectSetupScriptRunner.test.ts index 0628030b8f91c..c495feb4cef66 100644 --- a/apps/server/src/project/ProjectSetupScriptRunner.test.ts +++ b/apps/server/src/project/ProjectSetupScriptRunner.test.ts @@ -197,6 +197,16 @@ describe("ProjectSetupScriptRunner", () => { }), ); + it.effect("keeps emoji whole when capping a long output line or partial-line buffer", () => + Effect.gen(function* () { + const { outputLines, emit } = yield* setup(); + yield* emit({ ...event, type: "output", data: `x${"🙂".repeat(250)}\r\n` }); + yield* emit({ ...event, type: "output", data: `${"🙂".repeat(2_100)}x` }); + yield* emit({ ...event, type: "output", data: "\r\n" }); + expect(yield* Queue.takeAll(outputLines)).toEqual([`x${"🙂".repeat(199)}`, "🙂".repeat(200)]); + }), + ); + it.effect("types into a quiet shell that has no line editor", () => Effect.gen(function* () { const { writes } = yield* setup(); diff --git a/apps/server/src/project/ProjectSetupScriptRunner.ts b/apps/server/src/project/ProjectSetupScriptRunner.ts index 0f2e58d121402..1c94a3f118757 100644 --- a/apps/server/src/project/ProjectSetupScriptRunner.ts +++ b/apps/server/src/project/ProjectSetupScriptRunner.ts @@ -1,4 +1,5 @@ import { linkOriginIsFenced, ProjectId, type ProjectScript, ThreadId } from "@t3tools/contracts"; +import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations"; import { projectScriptRuntimeEnv, projectScriptTerminalInput, @@ -310,7 +311,14 @@ export const make = Effect.gen(function* () { ) { return Effect.void; } - return input.onOutputLine(cleaned.slice(0, OUTPUT_LINE_MAX_LENGTH)); + return input.onOutputLine( + cleaned.slice( + 0, + splitsSurrogatePair(cleaned, OUTPUT_LINE_MAX_LENGTH) + ? OUTPUT_LINE_MAX_LENGTH - 1 + : OUTPUT_LINE_MAX_LENGTH, + ), + ); }); const unsubscribe = yield* terminalManager.subscribe((event) => { @@ -324,7 +332,10 @@ export const make = Effect.gen(function* () { lineBuffer = lines.pop() ?? ""; // Bound newline-free output; the sentinel has its own line, so retaining the tail is safe. if (lineBuffer.length > PARTIAL_LINE_MAX_LENGTH) { - lineBuffer = lineBuffer.slice(-PARTIAL_LINE_MAX_LENGTH); + const start = lineBuffer.length - PARTIAL_LINE_MAX_LENGTH; + lineBuffer = lineBuffer.slice( + splitsSurrogatePair(lineBuffer, start) ? start + 1 : start, + ); } return Effect.forEach(lines, handleLine, { discard: true }).pipe( Effect.andThen(