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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This is a personal fork of [pingdotgg/t3code](https://github.com/pingdotgg/t3cod

- **Snooze until it's done** — an "Until it's done" preset, offered while the agent is mid-turn or its subagents are still working, hides the thread until that work ends, including the agent's follow-up on the subagents' results. Watch loops such as a dev server don't hold it. The thread returns when the agent finishes, is interrupted, fails, or asks you something. Threads with queued messages can be snoozed too, and "Until it's done" covers the queued follow-ups as well. These rows sit at the top of the Snoozed section. Web, desktop, and mobile. On web and desktop, a thread that woke because its work ended shows a green Woke status; timer wakes stay orange.
- **Working and Monitoring** — when a turn ends while work it started keeps running, the thread list on web, desktop, and mobile shows **Working** for live subagents and workflows and **Monitoring** when only watch loops such as a monitor, a pull request watch, or a command left running (a test run, a dev server) remain.
- **Pull request watches wake on merge** — upstream ends a `watch_pull_request` watch silently when the pull request merges and lets the thread settle at once. The fork wakes the agent once with the merge and the base branch, as it already did for a closed pull request, so an agent waiting on auto-merge can clean up.
- **Pull request watches hold until merge** — upstream lets a thread settle once a watched pull request's checks pass. In the fork, every `watch_pull_request` watch keeps the thread working until the pull request merges or closes, or the agent unwatches it.
- **Conversation forking** — fork a whole conversation into a new thread from the thread menus, the chat header, the command palette, or mobile. Providers that can fork their native session, such as Claude, Codex, and OpenCode, keep the full history in the new thread; the others carry the conversation over as context. An imported Claude or Codex session can be forked right away; a thread carried over from before the v2 upgrade can be forked after its first new message. Forks are titled with a (🔱) prefix, keep that title when the first message is sent, and join the source thread's group.
- **Two-pane split view** — web and desktop can show a second thread beside the routed one, including a thread from a different environment. Open it from the chat header button or the command palette's "Open thread in split view..." action. Hovering the divider reveals controls to swap the two threads (also `mod+shift+\`), switch the right pane's thread, and close the split. Sidebar clicks, sidebar thread shortcuts (next, previous, numbered jumps), palette picks, palette project results, and forks open into the active pane; a draft opened while the right pane is focused closes the split. The sidebar highlights both open threads, marks them with pane glyphs, and clears filters that would hide either one. `mod+\` jumps between panes, and window shortcuts act only on the active pane. Each pane's header keeps its own panel toggles, and `mod+w` with no panel tab open closes the active pane's thread, leaving the other one as the only pane; snoozing either thread, or archiving it yourself, does the same. The divider drags and remembers its position. Tag hiding applies to both open panes.
- **Hideable panel toggles** — Settings → Extras → Panels can hide the terminal drawer and right panel toggles from the thread header, in single and split view, for keyboard-driven use; the header then stops reserving room for them and the shortcuts keep working. They show by default.
Expand Down
88 changes: 1 addition & 87 deletions apps/server/src/git/Utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,6 @@
// @effect-diagnostics nodeBuiltinImport:off
import { expect, it } from "@effect/vitest";
import * as NodeFS from "node:fs";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";

import {
isSameDirectory,
readCheckedOutBranch,
readGitCommonDir,
sanitizeGitRepositoryEnvironment,
} from "./Utils.ts";

function makeTempDir(): string {
return NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-git-utils-"));
}

it("reads the branch from a primary checkout", () => {
const root = makeTempDir();
NodeFS.mkdirSync(NodePath.join(root, ".git"));
NodeFS.writeFileSync(NodePath.join(root, ".git", "HEAD"), "ref: refs/heads/dev\n");

expect(readCheckedOutBranch(root)).toBe("dev");
});

it("follows a linked worktree's gitdir pointer to its own HEAD", () => {
const root = makeTempDir();
const gitDir = NodePath.join(root, "repo.git", "worktrees", "feature");
NodeFS.mkdirSync(gitDir, { recursive: true });
NodeFS.writeFileSync(NodePath.join(gitDir, "HEAD"), "ref: refs/heads/fix/nested/name\n");

const worktree = NodePath.join(root, "worktree");
NodeFS.mkdirSync(worktree);
NodeFS.writeFileSync(NodePath.join(worktree, ".git"), `gitdir: ${gitDir}\n`);

expect(readCheckedOutBranch(worktree)).toBe("fix/nested/name");
});

it("reports no branch for a detached HEAD, a non-repository, or a missing directory", () => {
const detached = makeTempDir();
NodeFS.mkdirSync(NodePath.join(detached, ".git"));
NodeFS.writeFileSync(
NodePath.join(detached, ".git", "HEAD"),
"9fceb02f1a3b4c5d6e7f8091a2b3c4d5e6f70819\n",
);

expect(readCheckedOutBranch(detached)).toBeNull();
expect(readCheckedOutBranch(makeTempDir())).toBeNull();
expect(readCheckedOutBranch(NodePath.join(makeTempDir(), "absent"))).toBeNull();
});

it("treats trailing separators and symlinked paths as the same directory", () => {
const root = makeTempDir();
const target = NodePath.join(root, "target");
NodeFS.mkdirSync(target);
const link = NodePath.join(root, "link");
NodeFS.symlinkSync(target, link);

expect(isSameDirectory(target, `${target}${NodePath.sep}`)).toBe(true);
expect(isSameDirectory(link, target)).toBe(true);
expect(isSameDirectory(target, NodePath.join(root, "other"))).toBe(false);
});

it("compares deleted directories textually", () => {
const removed = NodePath.join(makeTempDir(), "gone");

expect(isSameDirectory(removed, removed)).toBe(true);
expect(isSameDirectory(removed, `${removed}-other`)).toBe(false);
});
import { sanitizeGitRepositoryEnvironment } from "./Utils.ts";

it("removes repository-scoping Git variables without dropping ordinary configuration", () => {
expect(
Expand All @@ -83,23 +17,3 @@ it("removes repository-scoping Git variables without dropping ordinary configura
PATH: "/usr/bin",
});
});

it("resolves a linked worktree and its primary checkout to the same repository", () => {
const root = makeTempDir();
const repo = NodePath.join(root, "project");
NodeFS.mkdirSync(NodePath.join(repo, ".git", "worktrees", "feature"), { recursive: true });

const worktree = NodePath.join(root, "feature");
NodeFS.mkdirSync(worktree);
NodeFS.writeFileSync(
NodePath.join(worktree, ".git"),
`gitdir: ${NodePath.join(repo, ".git", "worktrees", "feature")}\n`,
);

const foreign = NodePath.join(root, "other-project");
NodeFS.mkdirSync(NodePath.join(foreign, ".git"), { recursive: true });

expect(readGitCommonDir(worktree)).toBe(readGitCommonDir(repo));
expect(readGitCommonDir(foreign)).not.toBe(readGitCommonDir(repo));
expect(readGitCommonDir(makeTempDir())).toBeNull();
});
82 changes: 0 additions & 82 deletions apps/server/src/git/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,3 @@
// @effect-diagnostics nodeBuiltinImport:off
import * as NodeFS from "node:fs";
import * as NodePath from "node:path";

/**
* Compare two directory paths for identity, resolving symlinks when both sides
* still exist. Falls back to a normalized textual comparison so a directory
* that has since been deleted can still be recognized.
*/
export function isSameDirectory(left: string, right: string): boolean {
if (NodePath.resolve(left) === NodePath.resolve(right)) return true;
return canonicalizeDirectory(left) === canonicalizeDirectory(right);
}

/**
* Falls back to a normalized path when the directory cannot be resolved. Persisted worktree paths
* are compared with strict equality, so storing an alias (`/tmp` for `/private/tmp`, a symlinked
* parent) makes later comparisons miss.
*/
function canonicalizeDirectory(value: string): string {
try {
return NodeFS.realpathSync(value);
} catch {
return NodePath.resolve(value);
}
}

/**
* The shared git directory backing `cwd`, or `null` when it is not a checkout. A linked
* worktree's `gitdir` sits under `<repo>/.git/worktrees/<name>`, two levels below it. Checkouts
* of the same repository share this value, unlike unrelated clones.
*/
export function readGitCommonDir(cwd: string): string | null {
try {
const dotGit = NodePath.join(cwd, ".git");
const stats = NodeFS.statSync(dotGit, { throwIfNoEntry: false });
if (!stats) return null;
if (stats.isDirectory()) return canonicalizeDirectory(dotGit);

const pointer = NodeFS.readFileSync(dotGit, "utf8").trim();
const match = /^gitdir:\s*(.+)$/.exec(pointer);
if (!match?.[1]) return null;
const target = match[1].trim();
const gitDir = NodePath.isAbsolute(target) ? target : NodePath.resolve(cwd, target);
const parent = NodePath.dirname(gitDir);
return NodePath.basename(parent) === "worktrees"
? canonicalizeDirectory(NodePath.dirname(parent))
: canonicalizeDirectory(gitDir);
} catch {
return null;
}
}

/**
* Reads `HEAD` without shelling out; `.git` is a directory in a primary checkout and a `gitdir:`
* file in a linked worktree. Returns `null` for a detached HEAD, a non-repository, or any
* unparseable layout: callers treat it as "branch unknown", never an error.
*/
export function readCheckedOutBranch(cwd: string): string | null {
try {
const dotGit = NodePath.join(cwd, ".git");
const stats = NodeFS.statSync(dotGit, { throwIfNoEntry: false });
if (!stats) return null;

let gitDir = dotGit;
if (!stats.isDirectory()) {
const pointer = NodeFS.readFileSync(dotGit, "utf8").trim();
const match = /^gitdir:\s*(.+)$/.exec(pointer);
if (!match?.[1]) return null;
const target = match[1].trim();
gitDir = NodePath.isAbsolute(target) ? target : NodePath.resolve(cwd, target);
}

const head = NodeFS.readFileSync(NodePath.join(gitDir, "HEAD"), "utf8").trim();
const ref = /^ref:\s*refs\/heads\/(.+)$/.exec(head);
const branch = ref?.[1]?.trim();
return branch && branch.length > 0 ? branch : null;
} catch {
return null;
}
}

const REPOSITORY_SCOPING_GIT_ENVIRONMENT_KEYS = [
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
"GIT_CEILING_DIRECTORIES",
Expand Down
15 changes: 15 additions & 0 deletions apps/server/src/orchestration-v2/ArchiveWorktreeRemoval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ it.layer(TestLayer)("archive worktree removal", (it) => {
}).pipe(Effect.scoped),
);

it.effect("removes a linked worktree whose .git git-annex replaced with a symlink", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const removal = yield* ArchiveWorktreeRemoval;
const { worktreePath } = yield* setup("feature/annexed");
const adminDir = yield* git(worktreePath, ["rev-parse", "--absolute-git-dir"]);
yield* fs.remove(path.join(worktreePath, ".git"));
yield* fs.symlink(adminDir, path.join(worktreePath, ".git"));
assert.isNull(yield* removal.blocker(threadId));
assert.isNull(yield* removal.remove({ threadId, worktreePath }));
assert.isFalse(yield* fs.exists(worktreePath));
}).pipe(Effect.scoped),
);

it.effect("keeps a dirty worktree, though a running turn may still clean it", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
Expand Down
7 changes: 4 additions & 3 deletions apps/server/src/orchestration-v2/ArchiveWorktreeRemoval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as SqlClient from "effect/sql/SqlClient";

import { mayBeSpLabWorktree } from "../labs/labWorktree.ts";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import { isLinkedWorktree } from "../vcs/worktreeRemoval.ts";
import {
canonicalWorkspacePath,
reserveWorkspace,
Expand Down Expand Up @@ -94,9 +95,9 @@ const make = Effect.gen(function* () {
beforeArchive = false,
) {
const root = yield* canonicalWorkspacePath(worktreePath);
// A linked worktree has a `.git` file; a main checkout has a directory.
const gitEntry = yield* fs.stat(path.join(root, ".git")).pipe(Effect.orElseSucceed(() => null));
if (gitEntry?.type !== "File") return WORKTREE_KEPT_DETAIL.notWorktree;
if (!(yield* isLinkedWorktree(root).pipe(Effect.orElseSucceed(() => false)))) {
return WORKTREE_KEPT_DETAIL.notWorktree;
}
if (yield* mayBeSpLabWorktree(fs, path, root)) return WORKTREE_KEPT_DETAIL.labWorktree;
const projectShells = yield* projects.listShells();
for (const project of projectShells) {
Expand Down
6 changes: 0 additions & 6 deletions apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,6 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc
);
}

/**
* Wakes a thread's agent when a watched pull request finishes checks, gets someone else's comment,
* starts to conflict, or merges or closes without the agent's own command. A two-minute pass reads
* each moved pull request once per project. Settling or archiving the thread, or a merge or close,
* ends a watch; each end is logged once.
*/
export class PullRequestWatchReactor extends Context.Service<
PullRequestWatchReactor,
{
Expand Down
37 changes: 31 additions & 6 deletions apps/server/src/orchestration-v2/SessionWorkspaceFollow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import * as Ref from "effect/Ref";
import * as Stream from "effect/Stream";
import { ChildProcess, ChildProcessSpawner } from "effect/process";

import * as ServerConfig from "../config.ts";
import * as SqlitePersistence from "../persistence/Sqlite.ts";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
import * as EffectWorker from "./EffectWorker.ts";
import * as EventSink from "./EventSink.ts";
Expand Down Expand Up @@ -383,6 +385,11 @@ it.live("a followed move keeps the session; a T3 move restarts it in the new wor
),
);

const platformLayer = GitVcsDriver.layer.pipe(
Layer.provideMerge(ServerConfig.layerTest(process.cwd(), { prefix: "t3-follow-config-" })),
Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
);

const makeRepository = Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
Expand All @@ -402,29 +409,47 @@ const makeRepository = Effect.gen(function* () {
.pipe(Effect.flatMap((code) => (Number(code) === 0 ? Effect.void : Effect.die(args))));
const root = path.join(scratch, "repo");
const worktree = path.join(scratch, "repo-feature");
const detached = path.join(scratch, "repo-detached");
const annexed = path.join(scratch, "repo-annexed");
const other = path.join(scratch, "other");
yield* fileSystem.makeDirectory(path.join(root, "src"), { recursive: true });
yield* fileSystem.makeDirectory(other);
yield* git(root, "init", "--quiet");
yield* git(root, "commit", "--allow-empty", "--quiet", "-m", "init");
yield* git(root, "worktree", "add", "--quiet", "-b", "feature", worktree);
yield* git(root, "worktree", "add", "--quiet", "--detach", detached);
yield* git(root, "worktree", "add", "--quiet", "-b", "annexed", annexed);
// git-annex replaces a linked worktree's `.git` file with a symlink to its admin directory.
yield* fileSystem.remove(path.join(annexed, ".git"));
yield* fileSystem.symlink(
path.join(root, ".git", "worktrees", "repo-annexed"),
path.join(annexed, ".git"),
);
yield* git(other, "init", "--quiet");
return { scratch, root, worktree, other, path };
return { scratch, root, worktree, detached, annexed, other, path };
});

it.effect("follows only into existing checkouts of the project's repository", () =>
Effect.gen(function* () {
const { scratch, root, worktree, other, path } = yield* makeRepository;
const { scratch, root, worktree, detached, annexed, other, path } = yield* makeRepository;
const follow = (cwd: string) => resolveFollowedWorkspace({ workspaceRoot: root, cwd });
assert.deepEqual(
yield* follow(worktree),
Option.some({ worktreePath: worktree, branch: "feature" }),
);
assert.deepEqual(
yield* follow(detached),
Option.some({ worktreePath: detached, branch: null }),
);
assert.deepEqual(
yield* follow(annexed),
Option.some({ worktreePath: annexed, branch: "annexed" }),
);
assert.deepEqual(yield* follow(root), Option.some({ worktreePath: null, branch: null }));
assert.isTrue(Option.isNone(yield* follow(path.join(root, "src"))));
assert.isTrue(Option.isNone(yield* follow(other)));
assert.isTrue(Option.isNone(yield* follow(path.join(scratch, "removed"))));
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
}).pipe(Effect.scoped, Effect.provide(platformLayer)),
);

it.effect("follows only for the process that moved, while the thread is open", () =>
Expand Down Expand Up @@ -489,7 +514,7 @@ it.effect("follows only for the process that moved, while the thread is open", (
yield* plan({ thread: { ...thread, worktreePath: worktree, branch: "feature" } }),
),
);
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
}).pipe(Effect.scoped, Effect.provide(platformLayer)),
);

it.live("the follow worker moves the thread for the live process only", () =>
Expand Down Expand Up @@ -633,7 +658,7 @@ it.live("the follow worker moves the thread for the live process only", () =>

assert.deepEqual((yield* Ref.get(state)).openedCwds, [root]);
}),
).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
).pipe(Effect.provide(platformLayer)),
);

// Fork (DECISIONS 2.5 x 5.8): a completed agent-requested switch is a T3 move,
Expand Down Expand Up @@ -807,5 +832,5 @@ it.live("a completed worktree switch restarts the session in the new worktree",
assert.deepEqual(captured.openedCwds, [root, worktree]);
assert.deepEqual(captured.startedCwds, [root, worktree]);
}),
).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
).pipe(Effect.provide(platformLayer)),
);
3 changes: 3 additions & 0 deletions apps/server/src/orchestration-v2/SessionWorkspaceFollow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as Path from "effect/Path";

import { isExistingDirectory } from "@t3tools/provider-core/server/pathExpansion";
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import * as Orchestrator from "./Orchestrator.ts";
import * as ProjectStore from "./ProjectStore.ts";
import {
Expand Down Expand Up @@ -96,6 +97,7 @@ export const workerLive = Layer.effectDiscard(
const ids = yield* IdAllocator.IdAllocatorV2;
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const git = yield* GitVcsDriver.GitVcsDriver;

const follow = Effect.fn("SessionWorkspaceFollow.follow")(function* (
observation: ProviderSessionCwdObservation,
Expand All @@ -116,6 +118,7 @@ export const workerLive = Layer.effectDiscard(
}).pipe(
Effect.provideService(FileSystem.FileSystem, fileSystem),
Effect.provideService(Path.Path, path),
Effect.provideService(GitVcsDriver.GitVcsDriver, git),
);
if (Option.isNone(plan)) {
yield* Effect.logDebug("orchestration-v2.session-workspace-follow.skipped", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as Stream from "effect/Stream";
import * as SqlClient from "effect/sql/SqlClient";

import { forkParked } from "../serverActivation.ts";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import { withWorkspaceLease } from "../workspace/workspaceLease.ts";
import { isThreadPayloadEvent } from "./DeferredArchive.ts";
import { evaluateWorktreeSwitch, pendingWorktreeSwitch } from "./DeferredWorktreeSwitch.ts";
Expand Down Expand Up @@ -84,10 +85,12 @@ export const make = Effect.gen(function* () {
const random = yield* SecureRandom.SecureRandom;
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const git = yield* GitVcsDriver.GitVcsDriver;
const providePlatform = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
effect.pipe(
Effect.provideService(FileSystem.FileSystem, fs),
Effect.provideService(Path.Path, path),
Effect.provideService(GitVcsDriver.GitVcsDriver, git),
);
const newCommandId = (prefix: string, threadId: ThreadId) =>
random
Expand Down
Loading
Loading