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 21, 12:15 UTC
fix(server): guests of a forked thread can expand the commands it inherited (#29764)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Nov 15, 2026 at 15:46 UTC
1b9121ba59bb57af21e94de61e6c9eaef84163dc
2 files changed
+95
-7
apps/server/src/guest/GuestShareService.test.ts
+79
@@ -37,6 +37,7 @@ import {
37
resolveAttachmentPathById,
38
sweepStalePendingAttachments,
39
} from "../attachmentStore.ts";
40
+import { resolveAttachmentRelativePath } from "../attachmentPaths.ts";
41
import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
42
import { CloudManagedEndpointRuntime } from "../cloud/ManagedEndpointRuntime.ts";
43
import * as ServerConfig from "../config.ts";
@@ -449,6 +450,10 @@ const writeItem = (
450
| Pick<
451
Extract<OrchestrationV2TurnItem, { type: "file_change" }>,
452
"type" | "status" | "fileName" | "diffStr" | "oldStr" | "newStr"
453
+ >
454
+ | Pick<
455
+ Extract<OrchestrationV2TurnItem, { type: "dynamic_tool" }>,
456
+ "type" | "status" | "toolName" | "input" | "output"
457
>,
458
) =>
459
Effect.gen(function* () {
@@ -539,6 +544,80 @@ it.effect("gives the guest a command's detail and output, but no file diffs", ()
544
}).pipe(Effect.provide(layerTest)),
545
);
546
547
+it.effect("gives a fork's guest the commands the fork shows from its source thread", () =>
548
+ Effect.gen(function* () {
549
+ const { orchestrator, guestShares } = yield* shareThread;
550
+ const command = yield* writeItem("item:command", {
551
+ type: "command_execution",
552
+ status: "completed",
553
+ input: "ls /work/src",
554
+ output: "/work/src/auth.ts\n",
555
+ });
556
+ const { attachmentsDir } = yield* ServerConfig.ServerConfig;
557
+ const page = createAttachmentId(threadId, "html")!;
558
+ yield* (yield* FileSystem.FileSystem).writeFileString(
559
+ resolveAttachmentRelativePath({ attachmentsDir, relativePath: `${page}.html` })!,
560
+ "<p>Plan</p>",
561
+ );
562
+ const render = yield* writeItem("item:render", {
563
+ type: "dynamic_tool",
564
+ status: "completed",
565
+ toolName: "mcp__t3-code__html_render",
566
+ input: {},
567
+ output: [
568
+ {
569
+ type: "text",
570
+ text: JSON.stringify({ htmlRender: { attachmentId: page, title: "Plan", height: 300 } }),
571
+ },
572
+ ],
573
+ });
574
+ const eventSink = yield* EventSink.EventSinkV2;
575
+ const now = yield* DateTime.now;
576
+ const run = (yield* orchestrator.getThreadRecords(threadId, ["runs"])).runs[0]!;
577
+ yield* eventSink.write({
578
+ events: [
579
+ {
580
+ id: EventId.make("event:run-done"),
581
+ type: "run.updated",
582
+ threadId,
583
+ runId: run.id,
584
+ providerInstanceId: instanceId,
585
+ occurredAt: now,
586
+ payload: { ...run, status: "completed", completedAt: now },
587
+ },
588
+ ],
589
+ });
590
+ const forkId = ThreadId.make("thread:guest-share-fork");
591
+ yield* orchestrator.dispatch({
592
+ type: "thread.fork",
593
+ commandId: CommandId.make("fork"),
594
+ sourceThreadId: threadId,
595
+ targetThreadId: forkId,
596
+ sourcePoint: { type: "run", runId: run.id },
597
+ createdBy: "user",
598
+ creationSource: "web",
599
+ });
600
+ const { url } = yield* guestShares.create({ threadId: forkId });
601
+ const { token: session } = yield* guestShares.redeem({
602
+ credential: url.slice(url.indexOf("#") + 1),
603
+ name: "Sam",
604
+ });
605
+
606
+ const detail = (yield* guestShares.item(session, command)).item;
607
+ assert.deepInclude(detail, { input: "ls /work/src", output: "/work/src/auth.ts\n" });
608
+ const frames = Array.from(
609
+ yield* Stream.runCollect(yield* guestShares.commandOutput(session, command)),
610
+ );
611
+ assert.deepEqual(frames, [
612
+ { kind: "replace", text: "/work/src/auth.ts\n", truncated: false, running: false },
613
+ ]);
614
+ assert.deepEqual(yield* guestShares.render(session, render), {
615
+ path: resolveAttachmentPathById({ attachmentsDir, attachmentId: page })!,
616
+ title: "Plan",
617
+ });
618
+ }).pipe(Effect.provide(layerTest)),
619
+);
620
+
621
it.effect("pages the guest back through turns older than the stream's snapshot", () =>
622
Effect.gen(function* () {
623
const { guestShares, credential } = yield* shareThread;
apps/server/src/guest/GuestShareService.ts
+16
-7
@@ -639,17 +639,26 @@ const make = Effect.gen(function* () {
639
itemId: string,
640
) {
641
const { thread } = yield* authorize(session, "session");
642
- const item = yield* orchestrator
643
- .getTurnItem({ threadId: thread.id, itemId: TurnItemId.make(itemId) })
644
- .pipe(Effect.mapError(() => unavailable));
642
+ const id = TurnItemId.make(itemId);
643
+ const item =
644
+ (yield* orchestrator
645
+ .getTurnItem({ threadId: thread.id, itemId: id })
646
+ .pipe(Effect.mapError(() => unavailable))) ??
647
+ // A fork shows its source's earlier items, which stay in the source thread.
648
+ (thread.forkedFrom === null
649
+ ? null
650
+ : yield* orchestrator.getTimelinePage(thread.id, { itemId: id, limit: 1 }).pipe(
651
+ Effect.map((page) => page.items[0]?.item ?? null),
652
+ Effect.mapError(() => unavailable),
653
+ ));
654
return item === null ? yield* unavailable : { thread, item };
655
});
656
657
const render = Effect.fn("GuestShareService.render")(function* (session: string, itemId: string) {
649
- const { thread, item } = yield* threadItem(session, itemId);
658
+ const { item } = yield* threadItem(session, itemId);
659
if (item.type !== "dynamic_tool") return yield* unavailable;
660
const reference = htmlRenderFromToolItem(item);
652
- const [attachmentId] = threadHtmlRenderAttachmentIds(thread.id, [item]);
661
+ const [attachmentId] = threadHtmlRenderAttachmentIds(item.threadId, [item]);
662
const path =
663
attachmentId === undefined
664
? null
@@ -685,9 +694,9 @@ const make = Effect.gen(function* () {
694
session: string,
695
itemId: string,
696
) {
688
- const { thread, item } = yield* threadItem(session, itemId);
697
+ const { item } = yield* threadItem(session, itemId);
698
if (item.type !== "command_execution") return yield* unavailable;
690
- return commandOutputs.subscribe({ threadId: thread.id, itemId: item.id }).pipe(
699
+ return commandOutputs.subscribe({ threadId: item.threadId, itemId: item.id }).pipe(
700
// A lost hub stream ends the output; the row reloads it when reopened.
701
Stream.catchCause(() => Stream.empty),
702
Stream.interruptWhen(untilRevoked(session)),