Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/server/src/project/ProjectSetupScriptRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 13 additions & 2 deletions apps/server/src/project/ProjectSetupScriptRunner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { linkOriginIsFenced, ProjectId, type ProjectScript, ThreadId } from "@t3tools/contracts";
import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
import {
projectScriptRuntimeEnv,
projectScriptTerminalInput,
Expand Down Expand Up @@ -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) => {
Expand All @@ -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(
Expand Down
Loading