Skip to content
Open
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 @@ -4,7 +4,7 @@ import { HardDrives, Plus } from "@phosphor-icons/react";
import { Flex, Tooltip } from "@radix-ui/themes";
import { useTRPC } from "@renderer/trpc/client";
import { useQuery } from "@tanstack/react-query";
import { useState } from "react";
import { useEffect, useState } from "react";

interface EnvironmentSelectorProps {
repoPath: string | null;
Expand All @@ -29,6 +29,12 @@ export function EnvironmentSelector({
enabled: !!repoPath,
});

useEffect(() => {
if (value === null && environments.length > 0) {
onChange(environments[0].id);
}
}, [value, environments, onChange]);

const selectedEnvironment = environments.find((env) => env.id === value);
const displayText = selectedEnvironment?.name ?? "No environment";

Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/adapters/claude/claude-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import type {
ToolUseCache,
} from "./types";

const SESSION_VALIDATION_TIMEOUT_MS = 10_000;
const SESSION_VALIDATION_TIMEOUT_MS = 30_000;
const MAX_TITLE_LENGTH = 256;
const LOCAL_ONLY_COMMANDS = new Set(["/context", "/heapdump", "/extra-usage"]);

Expand Down
15 changes: 12 additions & 3 deletions packages/git/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,17 @@ export async function addToLocalExclude(
pattern: string,
options?: CreateGitClientOptions,
): Promise<void> {
const gitDir = await resolveGitDir(baseDir, options);
const excludePath = path.join(gitDir, "info", "exclude");
const manager = getGitOperationManager();
const excludePath = await manager.executeRead(
baseDir,
async (git) => {
// --git-path resolves to the correct location for both regular repos
// and worktrees (where info/exclude is shared via the common dir)
const rel = await git.revparse(["--git-path", "info/exclude"]);
return path.resolve(baseDir, rel);
},
{ signal: options?.abortSignal },
);

let content = "";
try {
Expand All @@ -961,7 +970,7 @@ export async function addToLocalExclude(
return;
}

const infoDir = path.join(gitDir, "info");
const infoDir = path.dirname(excludePath);
await fs.mkdir(infoDir, { recursive: true });

const newContent = content.trimEnd()
Expand Down
45 changes: 43 additions & 2 deletions packages/git/src/sagas/worktree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from "node:path";
import { GitSaga, type GitSagaInput } from "../git-saga";
import { addToLocalExclude, branchExists, getDefaultBranch } from "../queries";
import { safeSymlink } from "../utils";
import { processWorktreeInclude, runPostCheckoutHook } from "../worktree";

export interface CreateWorktreeInput extends GitSagaInput {
worktreePath: string;
Expand Down Expand Up @@ -35,7 +36,16 @@ export class CreateWorktreeSaga extends GitSaga<
await this.step({
name: "create-worktree",
execute: () =>
this.git.raw(["worktree", "add", "-b", branchName, worktreePath, base]),
this.git.raw([
"-c",
"core.hooksPath=/dev/null",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I assume this is to circumvent the husky hooks in the posthog/posthog repository right? Do we want to make it configurable if these hooks are enabled/disabled? Totally up to you

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, but not to circumvent, just to delay

we still run these later -- we just skip them here so the worktreeinclude and worktreelink processes can complete first, as the hooks may depend on them (ours do)

"worktree",
"add",
"-b",
branchName,
worktreePath,
base,
]),
rollback: async () => {
try {
await this.git.raw(["worktree", "remove", worktreePath, "--force"]);
Expand Down Expand Up @@ -86,6 +96,18 @@ export class CreateWorktreeSaga extends GitSaga<
},
});

await this.step({
name: "process-worktree-include",
execute: () => processWorktreeInclude(baseDir, worktreePath),
rollback: async () => {},
});

await this.step({
name: "run-post-checkout-hook",
execute: () => runPostCheckoutHook(baseDir, worktreePath),
rollback: async () => {},
});

return { worktreePath, branchName, baseBranch: base };
}
}
Expand Down Expand Up @@ -123,7 +145,14 @@ export class CreateWorktreeForBranchSaga extends GitSaga<
await this.step({
name: "create-worktree",
execute: () =>
this.git.raw(["worktree", "add", worktreePath, branchName]),
this.git.raw([
"-c",
"core.hooksPath=/dev/null",
"worktree",
"add",
worktreePath,
branchName,
]),
rollback: async () => {
try {
await this.git.raw(["worktree", "remove", worktreePath, "--force"]);
Expand Down Expand Up @@ -171,6 +200,18 @@ export class CreateWorktreeForBranchSaga extends GitSaga<
},
});

await this.step({
name: "process-worktree-include",
execute: () => processWorktreeInclude(baseDir, worktreePath),
rollback: async () => {},
});

await this.step({
name: "run-post-checkout-hook",
execute: () => runPostCheckoutHook(baseDir, worktreePath),
rollback: async () => {},
});

return { worktreePath, branchName };
}
}
Expand Down
49 changes: 49 additions & 0 deletions packages/git/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { execFile } from "node:child_process";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
Expand Down Expand Up @@ -58,6 +59,54 @@ export async function safeSymlink(
}
}

/**
* copy file or directory, use copy-on-write, fall back to cp
*/
export async function clonePath(
source: string,
destination: string,
): Promise<boolean> {
try {
await fs.access(source);
} catch {
return false;
}

const parentDir = path.dirname(destination);
await fs.mkdir(parentDir, { recursive: true });

const platform = os.platform();

try {
if (platform === "darwin") {
await execFileAsync("cp", ["-c", "-a", source, destination]);
} else {
await execFileAsync("cp", ["--reflink=auto", "-a", source, destination]);
}
return true;
} catch {
// CoW not supported, fall back to regular copy
}

await fs.cp(source, destination, { recursive: true });
return true;
}

function execFileAsync(
command: string,
args: string[],
): Promise<{ stdout: string; stderr: string }> {
return new Promise((resolve, reject) => {
execFile(command, args, (error, stdout, stderr) => {
if (error) {
reject(error);
return;
}
resolve({ stdout, stderr });
});
});
}

export function parseGitHubUrl(url: string): GitHubRepo | null {
// Trim whitespace/newlines that git commands may include
const trimmedUrl = url.trim();
Expand Down
Loading
Loading