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
21 changes: 18 additions & 3 deletions .opencode/plugins/fm-primary-watch-arm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawn } from "node:child_process";
import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
import { existsSync, lstatSync, readFileSync, readdirSync, realpathSync } from "node:fs";
import { resolve } from "node:path";

const COORDINATOR_KEY = "__firstmateOpenCodeWatchArm";
Expand Down Expand Up @@ -81,11 +81,26 @@ function effectivePaths(root) {
return { root: fmRoot, home: fmHome, state, config };
}

function isSecondmateHome(root, home) {
const rootReal = resolvePath(root);
const homeReal = resolvePath(home);
if (rootReal !== homeReal) return false;
const marker = `${rootReal}/.fm-secondmate-home`;
try {
const markerStat = lstatSync(marker);
if (!markerStat.isFile() || markerStat.isSymbolicLink()) return false;
const firstLine = readFileSync(marker, "utf8").split(/\r?\n/, 1)[0];
const id = firstLine.replace(/[ \t\v\f\r]/g, "");
return /^[A-Za-z0-9._-]+$/.test(id);
} catch {
return false;
}
}

async function isPrimaryRoot(root, home) {
if (!root) return false;
if (!existsSync(`${root}/AGENTS.md`) || !existsSync(`${root}/bin`)) return false;
if (existsSync(`${root}/.fm-secondmate-home`)) return false;
if (home && home !== root && existsSync(`${home}/.fm-secondmate-home`)) return false;
if (isSecondmateHome(root, home)) return true;
const gitDir = await runProcess("git", ["-C", root, "rev-parse", "--git-dir"]);
const commonDir = await runProcess("git", ["-C", root, "rev-parse", "--git-common-dir"]);
if (gitDir.code !== 0 || commonDir.code !== 0) return false;
Expand Down
Loading
Loading