Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,51 @@ describe("tailClaudeTaskOutput", () => {
).pipe(Effect.provide(NodeServices.layer)),
);

it.live("does not follow a task id that would leave the session directory", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const { root, tasks } = yield* makeTaskFile;
// Claude's task ids are tokens, so a traversal id reaches this file instead of a task file.
const escaped = path.join(tasks, "..", "leak.output");
yield* fileSystem.makeDirectory(path.dirname(escaped), { recursive: true });
yield* fileSystem.writeFileString(escaped, "secret\n");
const chunks = yield* Queue.unbounded<string>();
const fiber = yield* tailClaudeTaskOutput({
root,
sessionId: SESSION_ID,
taskId: "../leak",
stop: yield* Deferred.make<void>(),
onChunk: (chunk) => Queue.offer(chunks, chunk),
}).pipe(Effect.forkScoped);
yield* Effect.sleep("200 millis");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the real-time waits from these tests

Both new traversal tests call Effect.sleep("200 millis") inside it.live, so the configured t3code/no-real-time-wait-in-tests rule reports them and check:changed cannot pass. Coordinate the fiber result with the queue or a deferred instead of using a wall-clock window; the second test repeats this at line 143.

AGENTS.md reference: AGENTS.md:L115-L123

Useful? React with 👍 / 👎.

assert.equal(yield* Queue.size(chunks), 0);
yield* Fiber.interrupt(fiber);
}).pipe(Effect.provide(NodeServices.layer)),
);

it.live("does not follow a session id that would leave the project directory", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const { root } = yield* makeTaskFile;
const escaped = path.join(root, SESSION_ID, "tasks", "leak.output");
yield* fileSystem.makeDirectory(path.dirname(escaped), { recursive: true });
yield* fileSystem.writeFileString(escaped, "secret\n");
const chunks = yield* Queue.unbounded<string>();
const fiber = yield* tailClaudeTaskOutput({
root,
sessionId: `../${SESSION_ID}`,
taskId: "leak",
stop: yield* Deferred.make<void>(),
onChunk: (chunk) => Queue.offer(chunks, chunk),
}).pipe(Effect.forkScoped);
yield* Effect.sleep("200 millis");
assert.equal(yield* Queue.size(chunks), 0);
yield* Fiber.interrupt(fiber);
}).pipe(Effect.provide(NodeServices.layer)),
);

it.effect("reads what was written last when the tool result stops it", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const MAX_LOCATE_ATTEMPTS = 40;
/** Skip ahead of fast writers; only the tail is displayed. */
const MAX_READ_BYTES = 256 * 1024;

/** Session and task ids arrive from the provider stream and become path segments below. */
const SAFE_TASK_OUTPUT_ID = /^[A-Za-z0-9_-]+$/;

/** Claude Code's per-user temp root, or none where it has no uid (Windows). */
export function claudeTaskOutputRoot(
environment: Readonly<Record<string, string | undefined>> | undefined,
Expand Down Expand Up @@ -65,6 +68,8 @@ export const tailClaudeTaskOutput = Effect.fn("ClaudeTaskOutputTail.tail")(funct
readonly stop: Deferred.Deferred<void>;
readonly onChunk: (chunk: string) => Effect.Effect<void>;
}) {
// A rejected id drops live output only; the tool result still carries the final read.
if (!SAFE_TASK_OUTPUT_ID.test(input.sessionId) || !SAFE_TASK_OUTPUT_ID.test(input.taskId)) return;
const fileSystem = yield* FileSystem.FileSystem;
const pause = Deferred.await(input.stop).pipe(
Effect.as(true),
Expand Down
Loading