Skip to content
Merged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This is a personal fork of [pingdotgg/t3code](https://github.com/pingdotgg/t3cod

- **Agent-requested worktree switches.** After creating a worktree, a Codex agent can call `switch_worktree` (Claude follows worktrees on its own; see Worktree-following Claude sessions). T3 waits for the turn, its final checkpoint, any subagents, and any commands or monitors the agent waits on, then moves the thread's checkout; your next message continues the same conversation there. Agents inspect or cancel a pending move with `worktree_switch_status` and `cancel_worktree_switch`, and return to the project checkout with the same switch tool. A new message, archiving, or a failed turn cancels it.

- **Open threads from links.** The desktop app opens `t3code://app/<environmentId>/<threadId>` links (`t3code-dev://` for Dev builds) from other apps and from pages in the built-in browser, whether it is already running or starts from the link. Use `primary` as the environment ID for the desktop's own environment. When tag hiding is off, archived threads open too, with an archived notice and an Unarchive button above the composer. A link to an unknown environment or thread shows a short error instead. Upstream's prompt links (`t3code://new`, `t3code://threads/…`) follow the same rules: each build answers only its own scheme, and a thread link opens in the active split pane.
- **Open threads from links.** The desktop app opens `t3code://app/<environmentId>/<threadId>` links (`t3code-dev://` for Dev builds) from other apps and from pages in the built-in browser, whether it is already running or starts from the link. Use `primary` as the environment ID for the desktop's own environment. When tag hiding is off, archived threads open too, with an archived notice and an Unarchive button above the composer. A link to an unknown environment or thread shows a short error instead. Upstream's links (`t3code://new`, `t3code://threads/…`) follow the same rules: each build answers only its own scheme, and a thread link gets the same checks and opens in the active split pane.

- **Archive when done.** Archiving a working thread, from its menu, the command palette, the archive shortcut, mobile, or the `/t3-archive` composer command, waits until the turn, its checkpoint, any subagents, and any commands or monitors the agent waits on finish. Automatic follow-ups such as subagent results don't cancel it; a new message does. A pending archive shows an archive icon on the thread's row, and the same actions cancel it. Archiving an idle thread that has queued messages, including messages held by Stop, always asks first and names the count, even with archive confirmation off; confirming archives it now and discards them. Agents can archive their own thread, or pass `threadId` to archive another one they have read and no longer need, with `archive_thread` (inspected or cancelled with `archive_thread_status` and `cancel_thread_archive`), optionally removing its clean worktree while keeping the branch (never an SP Labs lab). Requests survive restarts. Like a manual archive, it also archives the thread's side chats, and sending a message to an archived thread unarchives it and those side chats first. Agents can use `archive_thread` with `includeDescendants: true` to archive finished child and subagent threads in the same call; active descendants are skipped and reported. Shared-worktree refusals report the blocker count and up to ten thread ids, titles, and states.

Expand Down
3 changes: 1 addition & 2 deletions apps/desktop/src/app/DesktopApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import * as DesktopSshEnvironment from "../ssh/DesktopSshEnvironment.ts";
import * as DesktopSshPasswordPrompts from "../ssh/DesktopSshPasswordPrompts.ts";
import * as DesktopTelemetryPublisher from "../telemetry/DesktopTelemetryPublisher.ts";
import * as DesktopWebLinks from "./DesktopWebLinks.ts";
import * as DesktopThreadLinks from "./DesktopThreadLinks.ts";
import * as DesktopWslEnvironment from "../wsl/DesktopWslEnvironment.ts";
import * as ElectronMenu from "../electron/ElectronMenu.ts";
import * as ElectronShell from "../electron/ElectronShell.ts";
Expand Down Expand Up @@ -141,6 +140,7 @@ const runStubbedDesktop = (stub: StubbedDesktop) =>
}),
Effect.provideService(DesktopClerk.DesktopClerk, {
configure: Effect.void,
openThreadLink: () => false,
} as DesktopClerk.DesktopClerk["Service"]),
Effect.provideService(ElectronSafeStorage.ElectronSafeStorage, {
selectedStorageBackend: Effect.succeedNone,
Expand Down Expand Up @@ -234,7 +234,6 @@ const runStubbedDesktop = (stub: StubbedDesktop) =>
Layer.mock(DesktopSshPasswordPrompts.DesktopSshPasswordPrompts, {}),
Layer.mock(DesktopTelemetryPublisher.DesktopTelemetryPublisher, {}),
Layer.mock(DesktopWebLinks.DesktopWebLinks, {}),
Layer.mock(DesktopThreadLinks.DesktopThreadLinks, { start: Effect.void }),
Layer.mock(DesktopWslEnvironment.DesktopWslEnvironment, {}),
Layer.mock(ElectronMenu.ElectronMenu, {}),
Layer.mock(ElectronShell.ElectronShell, {}),
Expand Down
4 changes: 0 additions & 4 deletions apps/desktop/src/app/DesktopApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import * as DesktopAppIdentity from "./DesktopAppIdentity.ts";
import * as DesktopClerk from "./DesktopClerk.ts";
import * as DesktopCliShim from "./DesktopCliShim.ts";
import * as DesktopCliCommand from "./DesktopCliCommand.ts";
import * as DesktopThreadLinks from "./DesktopThreadLinks.ts";
import * as DesktopApplicationMenu from "../window/DesktopApplicationMenu.ts";
import * as DesktopWindow from "../window/DesktopWindow.ts";
import * as PreviewPasskeys from "../preview/Passkeys.ts";
Expand Down Expand Up @@ -338,7 +337,6 @@ const startup = Effect.gen(function* () {
const electronApp = yield* ElectronApp.ElectronApp;
const lifecycle = yield* DesktopLifecycle.DesktopLifecycle;
const linuxUrlHandler = yield* DesktopLinuxUrlHandler.DesktopLinuxUrlHandler;
const threadLinks = yield* DesktopThreadLinks.DesktopThreadLinks;
const clerk = yield* DesktopClerk.DesktopClerk;
const shellEnvironment = yield* DesktopShellEnvironment.DesktopShellEnvironment;
const desktopSettings = yield* DesktopAppSettings.DesktopAppSettings;
Expand Down Expand Up @@ -428,8 +426,6 @@ const startup = Effect.gen(function* () {
yield* bootstrap(backendStarted).pipe(
Effect.catchCause((cause) => fatalStartupCause("bootstrap", cause)),
);
// After bootstrap so revealing a linked thread never races the first window.
yield* threadLinks.start;
}).pipe(Effect.withSpan("desktop.startup"));

const scopedProgram = Effect.scoped(
Expand Down
23 changes: 22 additions & 1 deletion apps/desktop/src/app/DesktopClerk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,24 @@ describe("DesktopClerk", () => {
listeners.get("second-instance")?.({}, ["t3", first]);
listeners.get("second-instance")?.({}, ["t3", second]);
listeners.get("open-url")?.({ preventDefault: () => undefined }, launchPair);
// Fork: a macOS cold start hands the documented `app/` thread link to open-url.
listeners.get("open-url")?.(
{ preventDefault: () => undefined },
"t3code-dev://app/primary/t",
);
assert.deepEqual(received, []);

yield* clerk.configure;
listeners.get("second-instance")!({}, ["t3", later]);
yield* Effect.promise(() => delivered.promise);

assert.deepEqual(received, [launchPair, first, second, later]);
assert.deepEqual(received, [
launchPair,
"t3code-dev://threads/primary/t",
first,
second,
later,
]);
}).pipe(
Effect.scoped,
Effect.provide(layerDesktopClerk(true, [], "darwin", undefined, undefined, listeners)),
Expand Down Expand Up @@ -445,6 +456,7 @@ it.effect("hands web and app links to the renderer and leaves other links alone"
const pairLink = "t3code://pair?pairingUrl=https%3A%2F%2Fvps.example.com%2F%23token%3Dabc";
yield* Effect.gen(function* () {
const clerk = yield* DesktopClerk.DesktopClerk;
assert.isFalse(clerk.openThreadLink("t3code-dev://app/primary/thread-3"));
yield* clerk.configure;
const open = (url: string) => {
const event = { preventDefault: vi.fn() };
Expand All @@ -461,13 +473,22 @@ it.effect("hands web and app links to the renderer and leaves other links alone"
assert.strictEqual(open("t3code://pair"), 0);
assert.strictEqual(open("mailto:hello@example.com"), 0);
assert.strictEqual(open("t3code-dev://somewhere-else"), 0);
// Fork: the documented `app/` thread link, for this build only, also from previewed pages.
assert.strictEqual(open("t3code-dev://app/env-1/thread-2"), 1);
assert.strictEqual(open("t3code://app/env-1/thread-2"), 0);
assert.isTrue(clerk.openThreadLink("t3code-dev://app/primary/thread-3"));
assert.isFalse(clerk.openThreadLink("t3code-dev://threads/env-1/thread-1"));
assert.isFalse(clerk.openThreadLink("t3code://app/env-1/thread-2"));
assert.isFalse(clerk.openThreadLink("https://example.com/page"));
yield* Effect.yieldNow;
assert.deepStrictEqual(received, [
"https://example.com/page",
"http://localhost:3000/",
"t3code-dev://new?prompt=hi",
"t3code-dev://threads/env-1/thread-1",
pairLink,
"t3code-dev://threads/env-1/thread-2",
"t3code-dev://threads/primary/thread-3",
]);
}).pipe(
Effect.provide(layerDesktopClerk(true, [], "darwin", undefined, undefined, listeners)),
Expand Down
16 changes: 12 additions & 4 deletions apps/desktop/src/app/DesktopClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as ElectronProtocol from "../electron/ElectronProtocol.ts";
import * as ElectronWindow from "../electron/ElectronWindow.ts";
import * as DesktopUserData from "./DesktopUserData.ts";
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
import * as DesktopThreadLinks from "./DesktopThreadLinks.ts";
import { openClerkTokenStorage } from "./ClerkTokenStore.ts";
import * as DesktopWebLinks from "./DesktopWebLinks.ts";

Expand Down Expand Up @@ -63,6 +64,8 @@ export class DesktopClerk extends Context.Service<
| DesktopWebLinks.DesktopWebLinks
| Scope.Scope
>;
/** Fork: opens this build's `app/` thread link from a previewed page; false before configure. */
readonly openThreadLink: (url: string) => boolean;
}
>()("@t3tools/desktop/app/DesktopClerk") {}

Expand Down Expand Up @@ -138,6 +141,8 @@ export const make = Effect.gen(function* () {
yield* electronApp.on("open-url", (event: { preventDefault: () => void }, url: string) => {
if (handleOpenUrl(url)) event.preventDefault();
});
const scheme = ElectronProtocol.getDesktopScheme(environment.usesDevelopmentIdentity);
let openThreadLink = (_url: string) => false;

yield* Effect.acquireRelease(
Effect.try({
Expand Down Expand Up @@ -204,7 +209,6 @@ export const make = Effect.gen(function* () {
};
const resumeProviderAuth = (value: string | undefined) => {
const destination = providerAuthReturnUrl(value);
const scheme = ElectronProtocol.getDesktopScheme(environment.usesDevelopmentIdentity);
if (!destination?.startsWith(`${scheme}://app/`)) return false;
void runPromise(
Effect.gen(function* () {
Expand All @@ -220,13 +224,14 @@ export const make = Effect.gen(function* () {
);
return true;
};
const openAppLink = (value: string | undefined) => {
if (!value) return false;
const openAppLink = (link: string | undefined) => {
if (!link) return false;
// Fork: the documented `app/<environmentId>/<threadId>` form rides upstream's thread links.
const value = DesktopThreadLinks.appThreadLinkAsThreadsLink(link, scheme) ?? link;
const promptLink = promptLinkAppPath(value) !== null;
if (!promptLink && readPairingAppLink(value) === null) return false;
// Fork: prompt and thread links open only in this build's scheme (t3code:// vs
// t3code-dev://); pairing links are scheme-agnostic upstream.
const scheme = ElectronProtocol.getDesktopScheme(environment.usesDevelopmentIdentity);
if (
promptLink &&
/^t3code(?:-[a-z]+)?:/i.test(value) &&
Expand All @@ -237,6 +242,8 @@ export const make = Effect.gen(function* () {
void runPromise(webLinks.receive(value));
return true;
};
openThreadLink = (url) =>
DesktopThreadLinks.appThreadLinkAsThreadsLink(url, scheme) !== null && openAppLink(url);
const args = yield* HostProcess.Arguments;
args.some((value) => startProviderAuthHandoff(value) || openAppLink(value));
const openWebLink = (url: string) => {
Expand Down Expand Up @@ -272,6 +279,7 @@ export const make = Effect.gen(function* () {
};
for (const argv of pendingSecondInstances.splice(0)) handleSecondInstance(argv);
}).pipe(Effect.withSpan("desktop.clerk.configure")),
openThreadLink: (url) => openThreadLink(url),
});
});

Expand Down
Loading
Loading