Open-source, local-first AI agent team for your desktop: multi-agent group chats, computer use, browser, MCP, routines and approvals. macOS, Windows, Linux + Android. Built on pi.
TypeScript agentai-agentai-agentsai-assistantandroidautomationchatgptcoding-agentcomputer-usedesktop-appelectronllmlocal-firstmcpmulti-agentollamaopenaiprivacyself-hostedtypescript
fix(git): say when Git is missing, and keep the bundled Git cache tidy
leen.zhouff03ed6a9a58
diff --git a/packages/execution/src/git/bundled-git.ts b/packages/execution/src/git/bundled-git.tsindex 50d6062..e8b830c 100644--- a/packages/execution/src/git/bundled-git.ts+++ b/packages/execution/src/git/bundled-git.ts@@ -93,7 +93,12 @@ export function bundledGitReady(git: BundledGit) {* exclusive lock file; the copy is built in a private temporary folder and renamed into place, so* a crash or a power cut never leaves a half-unpacked Git that looks complete.*/-export async function prepareBundledGit(git: BundledGit): Promise<string> {+export async function prepareBundledGit(+ git: BundledGit,+ onEvent?: (+ event: "unpack_started" | "unpack_finished" | "old_copy_removed" | "old_copy_remove_failed",+ ) => void,+): Promise<string> {const signal = AbortSignal.timeout(EXTRACT_DEADLINE_MS);const parent = win32.dirname(git.home);const name = win32.basename(git.home);@@ -118,12 +123,14 @@ export async function prepareBundledGit(git: BundledGit): Promise<string> {.writeFile(JSON.stringify({ pid: process.pid, at: Date.now() })).finally(() => handle.close());if (bundledGitReady(git)) return git.program;- await extract(git, parent, name, signal).catch(async (error) => {+ onEvent?.("unpack_started");+ await extract(git, parent, name, signal, onEvent).catch(async (error) => {await writeFile(failed, JSON.stringify({ at: Date.now() })).catch(() => {// Without the record the next need simply tries again; the failure itself is reported.});throw error;});+ onEvent?.("unpack_finished");return git.program;} finally {await rm(lock, { force: true });@@ -131,7 +138,15 @@ export async function prepareBundledGit(git: BundledGit): Promise<string> {}}-async function extract(git: BundledGit, parent: string, name: string, signal: AbortSignal) {+async function extract(+ git: BundledGit,+ parent: string,+ name: string,+ signal: AbortSignal,+ onEvent?: (+ event: "unpack_started" | "unpack_finished" | "old_copy_removed" | "old_copy_remove_failed",+ ) => void,+) {// Leftovers of an unpack that was killed: this lock holder is the only writer for this name.for (const entry of await readdir(parent))if (entry.startsWith(`${name}.tmp-`))@@ -152,6 +167,7 @@ async function extract(git: BundledGit, parent: string, name: string, signal: Ab// A folder without the marker is an older partial copy (or one a person emptied); replace it.await rm(git.home, { recursive: true, force: true });await renameWithRetry(temporary, git.home, signal);+ await removeOldCopies(parent, name, onEvent);} finally {await rm(temporary, { recursive: true, force: true });}@@ -221,3 +237,30 @@ function pause(ms: number, signal: AbortSignal) {signal.addEventListener("abort", done, { once: true });});}++async function removeOldCopies(+ parent: string,+ current: string,+ onEvent?: (+ event: "unpack_started" | "unpack_finished" | "old_copy_removed" | "old_copy_remove_failed",+ ) => void,+) {+ const entries = await readdir(parent, { withFileTypes: true });+ for (const entry of entries) {+ if (+ !entry.isDirectory() ||+ entry.name === current ||+ !/^\d+\.\d+\.\d+-[0-9a-f]{12}$/.test(entry.name)+ )+ continue;+ try {+ await rm(win32.join(parent, entry.name), { recursive: true, force: true });+ onEvent?.("old_copy_removed");+ } catch (error) {+ const code = error as NodeJS.ErrnoException;+ onEvent?.("old_copy_remove_failed");+ // The new copy is already installed. A running old Git may keep files locked on Windows.+ if (!code || !["EBUSY", "EPERM", "EACCES"].includes(code.code ?? "")) throw error;+ }+ }+}diff --git a/packages/execution/src/git/git-process.ts b/packages/execution/src/git/git-process.tsindex 37069c8..61cb079 100644--- a/packages/execution/src/git/git-process.ts+++ b/packages/execution/src/git/git-process.ts@@ -13,6 +13,9 @@ export interface GitProcessOptions {userHome: string;/** Packaged app resources; on Windows the bundled MinGit there is the last Git candidate. */resourcesDir?: string;+ onBundledGitEvent?: (+ event: "unpack_started" | "unpack_finished" | "old_copy_removed" | "old_copy_remove_failed",+ ) => void;}export interface GitProcessResult {@@ -26,7 +29,7 @@ export interface GitProcessResult {}export async function findGit(- options: Pick<GitProcessOptions, "platform" | "env" | "resourcesDir">,+ options: Pick<GitProcessOptions, "platform" | "env" | "resourcesDir" | "onBundledGitEvent">,) {for (const candidate of gitPrograms(options.platform, options.env, options.resourcesDir)) {try {@@ -45,11 +48,11 @@ export async function findGit(* turns); the next need after the failure backoff tries again.*/export async function unpackBundledGit(- options: Pick<GitProcessOptions, "platform" | "env" | "resourcesDir">,+ options: Pick<GitProcessOptions, "platform" | "env" | "resourcesDir" | "onBundledGitEvent">,) {const git = bundledGit(options.platform, options.env, options.resourcesDir);if (!git) return undefined;- return prepareBundledGit(git).catch(() => undefined);+ return prepareBundledGit(git, options.onBundledGitEvent).catch(() => undefined);}export function gitEnvironment(options: GitProcessOptions, executable: string): NodeJS.ProcessEnv {diff --git a/packages/workspaces-contract/src/i18n/changes.ts b/packages/workspaces-contract/src/i18n/changes.tsindex b0bc25a..9c6344e 100644--- a/packages/workspaces-contract/src/i18n/changes.ts+++ b/packages/workspaces-contract/src/i18n/changes.ts@@ -86,7 +86,7 @@ export const changesZh = {"changes.repo.worktreeOption": "{name}(工作区改动)","changes.repo.detached": "未在分支上","changes.repo.notRepo": "不是 Git 仓库",- "changes.repo.noGit": "没找到 Git",+ "changes.repo.noGit": "Git 未安装","changes.repo.noGitBody":"这台电脑上没找到 Git,所以只能看每一轮改了什么。装好 Git 后就能看全部未提交的改动、撤回和提交。","changes.repo.installGit": "下载 Git",@@ -501,7 +501,7 @@ export const changesEn: { [K in keyof typeof changesZh]: string } = {"changes.repo.worktreeOption": "{name} (workspace changes)","changes.repo.detached": "No branch","changes.repo.notRepo": "Not a Git repository",- "changes.repo.noGit": "Git not found",+ "changes.repo.noGit": "Git is not installed","changes.repo.noGitBody":"Git isn't installed on this computer, so only each turn's changes are shown. Install Git to see all uncommitted changes, discard and commit.","changes.repo.installGit": "Get Git",diff --git a/packages/workspaces/src/brain/changes/changes-service.ts b/packages/workspaces/src/brain/changes/changes-service.tsindex 522ca6b..1894d56 100644--- a/packages/workspaces/src/brain/changes/changes-service.ts+++ b/packages/workspaces/src/brain/changes/changes-service.ts@@ -89,6 +89,11 @@ export class ChangesService {env: local.deps.env,userHome: local.deps.userHome,resourcesDir: local.deps.resourcesDir,+ onBundledGitEvent: (event) => {+ const log =+ event === "old_copy_remove_failed" ? local.deps.logger.warn : local.deps.logger.info;+ log(JSON.stringify({ module: "git", event }));+ },});this.turn = new RunChanges({db: local.deps.db,diff --git a/packages/workspaces/src/brain/groups/group-step-prepare.ts b/packages/workspaces/src/brain/groups/group-step-prepare.tsindex 62b957f..5259cd8 100644--- a/packages/workspaces/src/brain/groups/group-step-prepare.ts+++ b/packages/workspaces/src/brain/groups/group-step-prepare.ts@@ -102,12 +102,9 @@ export async function prepareStepWorktree(const sharing = owner.turns.reason(folder);if (sharing) return turns(sharing);if (owner.cleanupPending([primary])) return turns(CLEANUP_PENDING);- // Retest 2026-11-21: an own workspace keeps the group folder as a read-only reference, and only- // the macOS sandbox can run commands beside one (local-run-authorization refuses elsewhere), so- // a test step there could never run its test. Taking turns in the folder keeps commands working.- if (!remote && local.deps.platform !== "darwin") return turns("readonly_commands_unsupported");- // Without Git nothing below can work. Checked first, so a step never waits for a folder lock- // another step holds only to learn that Git is missing (B2: the 120 s prepare limit).+ // Without Git nothing below can work. Checked before the platform isolation check so Linux+ // reports the missing prerequisite and offers the Git install card.+ // another step holds only to learn that Git is missing.if (!remote &&!(await findGit({@@ -117,6 +114,9 @@ export async function prepareStepWorktree(})))return turns("git_unavailable");+ // An own workspace keeps the group folder as a read-only reference. Only macOS can run+ // commands beside one, so other platforms take turns after Git availability is established.+ if (!remote && local.deps.platform !== "darwin") return turns("readonly_commands_unsupported");owner.stage(context.runId, "probe");const repository = (await host.isRepository(primary, signal).catch(() => false))? await host.inspect(primary, signal).catch(() => undefined)diff --git a/packages/workspaces/src/ui/changes/use-changes-pane.ts b/packages/workspaces/src/ui/changes/use-changes-pane.tsindex fe81713..40aa7c4 100644--- a/packages/workspaces/src/ui/changes/use-changes-pane.ts+++ b/packages/workspaces/src/ui/changes/use-changes-pane.ts@@ -78,6 +78,10 @@ export function useChangesPane(options: ChangesPaneOptions) {const [busy, setBusy] = useState(false);const [notice, setNotice] = useState<{ key: TranslationKey; error: boolean }>();const [committed, setCommitted] = useState<{ oid: string; subject: string }>();+ const gitState = git?.state === "none" ? git.reason : (git?.state ?? "");+ useEffect(() => {+ if (gitState) setNotice(undefined);+ }, [gitState]);const [historyRevision, setHistoryRevision] = useState(0);const [comments, updateComments] = useDraftComments(`${conversationKey}|${topicId ?? ""}`);