@@ -64441,7 +64441,7 @@ var MCP_VERSION;
6444164441var init_version3 = __esm({
6444264442 "src/version.ts"() {
6444364443 "use strict";
64444- MCP_VERSION = true ? "1.103.1 " : "dev";
64444+ MCP_VERSION = true ? "1.103.2 " : "dev";
6444564445 }
6444664446});
6444764447
@@ -74192,6 +74192,16 @@ function branchExists(branch) {
7419274192}
7419374193function getMainlineBranch() {
7419474194 if (!isGitRepo()) return "main";
74195+ const originHead = tryRun([
74196+ "git",
74197+ "symbolic-ref",
74198+ "--short",
74199+ "refs/remotes/origin/HEAD"
74200+ ]);
74201+ if (originHead) {
74202+ const m2 = originHead.match(/^origin\/(.+)$/);
74203+ if (m2) return m2[1];
74204+ }
7419574205 for (const candidate of ["main", "master"]) {
7419674206 if (tryRun(["git", "rev-parse", "--verify", candidate])) return candidate;
7419774207 if (tryRun(["git", "rev-parse", "--verify", `origin/${candidate}`]))
@@ -74200,6 +74210,15 @@ function getMainlineBranch() {
7420074210 const configured = tryRun(["git", "config", "--get", "init.defaultBranch"]);
7420174211 return configured || "main";
7420274212}
74213+ function fetchOrigin() {
74214+ if (!isGitRepo()) return false;
74215+ try {
74216+ execFileSync("git", ["fetch", "--prune", "origin"], { stdio: "pipe" });
74217+ return true;
74218+ } catch {
74219+ return false;
74220+ }
74221+ }
7420374222function listIntentBranches() {
7420474223 if (!isGitRepo()) return [];
7420574224 const slugs = /* @__PURE__ */ new Set();
@@ -74306,14 +74325,21 @@ function isBranchMerged(branch, mainline) {
7430674325 }
7430774326 return false;
7430874327}
74309- function addTempWorktree(branch, label = "haiku-repair") {
74328+ function addTempWorktree(branch, label = "haiku-repair", preferRemote = false ) {
7431074329 if (!isGitRepo()) throw new Error("not a git repo");
7431174330 const path = join8(
7431274331 "/tmp",
7431374332 `${label}-${Date.now()}-${Math.floor(Math.random() * 1e6)}`
7431474333 );
74315- const localExists = tryRun(["git", "rev-parse", "--verify", branch]);
74316- const ref = localExists ? branch : `origin/${branch}`;
74334+ const localRef = tryRun(["git", "rev-parse", "--verify", branch]);
74335+ const remoteRef = tryRun(["git", "rev-parse", "--verify", `origin/${branch}`]);
74336+ let ref;
74337+ if (preferRemote) {
74338+ ref = remoteRef ? `origin/${branch}` : localRef ? branch : "";
74339+ } else {
74340+ ref = localRef ? branch : remoteRef ? `origin/${branch}` : "";
74341+ }
74342+ if (!ref) throw new Error(`branch '${branch}' not found locally or on origin`);
7431774343 run(["git", "worktree", "add", "--detach", path, ref]);
7431874344 return path;
7431974345}
@@ -74338,20 +74364,43 @@ function commitAndPushFromWorktree(worktreePath, branch, message) {
7433874364 pushError: err instanceof Error ? err.message : String(err)
7433974365 };
7434074366 }
74341- try {
74342- execFileSync(
74343- "git",
74344- ["-C", worktreePath, "push", "origin", `HEAD:refs/heads/${branch}`],
74345- { stdio: "pipe" }
74346- );
74347- return { committed: true, pushed: true };
74348- } catch (err) {
74349- return {
74350- committed: true,
74351- pushed: false,
74352- pushError: err instanceof Error ? err.message : String(err)
74353- };
74367+ const tryPush = () => {
74368+ try {
74369+ execFileSync(
74370+ "git",
74371+ ["-C", worktreePath, "push", "origin", `HEAD:refs/heads/${branch}`],
74372+ { stdio: "pipe" }
74373+ );
74374+ return { ok: true };
74375+ } catch (err) {
74376+ return {
74377+ ok: false,
74378+ error: err instanceof Error ? err.message : String(err)
74379+ };
74380+ }
74381+ };
74382+ const first = tryPush();
74383+ if (first.ok) return { committed: true, pushed: true };
74384+ const isNonFastForward = /non-fast-forward|fetch first|behind the remote/i.test(first.error ?? "");
74385+ if (isNonFastForward) {
74386+ tryRun(["git", "-C", worktreePath, "fetch", "origin", branch]);
74387+ try {
74388+ execFileSync("git", ["-C", worktreePath, "rebase", `origin/${branch}`], {
74389+ stdio: "pipe"
74390+ });
74391+ } catch (err) {
74392+ tryRun(["git", "-C", worktreePath, "rebase", "--abort"]);
74393+ return {
74394+ committed: true,
74395+ pushed: false,
74396+ pushError: `non-fast-forward; rebase onto origin/${branch} failed: ${err instanceof Error ? err.message : String(err)}`
74397+ };
74398+ }
74399+ const retry = tryPush();
74400+ if (retry.ok) return { committed: true, pushed: true };
74401+ return { committed: true, pushed: false, pushError: retry.error };
7435474402 }
74403+ return { committed: true, pushed: false, pushError: first.error };
7435574404}
7435674405function detectPrTool() {
7435774406 if (tryRun(["which", "gh"])) return "gh";
@@ -75895,6 +75944,7 @@ function buildRepairReport(result, headingPrefix = "") {
7589575944 return lines.join("\n");
7589675945}
7589775946function repairAllBranches(autoApply) {
75947+ fetchOrigin();
7589875948 const mainline = getMainlineBranch();
7589975949 const summaries = [];
7590075950 if (autoApply) {
@@ -75968,7 +76018,7 @@ function repairAllBranches(autoApply) {
7596876018 merged: false
7596976019 };
7597076020 try {
75971- worktreePath = addTempWorktree(branch, "haiku-repair");
76021+ worktreePath = addTempWorktree(branch, "haiku-repair", true );
7597276022 } catch (err) {
7597376023 summary.error = `Failed to create worktree: ${err instanceof Error ? err.message : String(err)}`;
7597476024 summaries.push(summary);
@@ -76052,7 +76102,7 @@ function repairArchivedOnMainline(activeBranches, mainline, autoApply) {
7605276102 };
7605376103 let worktreePath = "";
7605476104 try {
76055- worktreePath = addTempWorktree(mainline, "haiku-repair-archived");
76105+ worktreePath = addTempWorktree(mainline, "haiku-repair-archived", true );
7605676106 } catch (err) {
7605776107 summary.setupError = `Failed to create mainline worktree: ${err instanceof Error ? err.message : String(err)}`;
7605876108 return summary;
@@ -77403,7 +77453,7 @@ ${content}
7740377453 }
7740477454 // ── Review ──
7740577455 case "haiku_review": {
77406- let base = "main" ;
77456+ let base = getMainlineBranch() ;
7740777457 try {
7740877458 const upstream = spawnSync(
7740977459 "git",
0 commit comments