@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
660 lines • 28.9 kB
JavaScript
// BETA(omo-local-update): removable beta module - delete this file, all test/omo-local-update*
// files to drop the feature.
//
// Beta: on bare `senpi update`, compare a locally-installed OMO plugin (omo-senpi +
// senpi-task) against origin/dev of its source checkout and replace the LOCAL PLUGIN
// INSTALL only when different. The user's checkout receives ZERO git mutations: this module
// never runs checkout/branch/commit/merge/reset/clean/stash/push against the user's repo.
// Its only git writes are `git fetch origin dev` (remote-tracking ref update) plus
// worktree add/remove/prune registering the FEATURE-OWNED persistent build worktree under
// <agentDir>/omo-local-update/. `checkout --detach --force` is used exactly once and only
// inside that feature-owned worktree, which this module creates and owns exclusively.
// Builds run there; the install target (pluginPath) is swapped atomically by rename.
//
// Export policy: `runOmoLocalUpdateBeta` is the ONLY production API and the only symbol the
// CLI may import. Every other export in this module is /** exported for tests only */ so the
// single test file (test/omo-local-update.test.ts) can exercise helpers directly - no
// CLI-side helper imports, no logic duplication.
import { randomUUID } from "node:crypto";
import { cpSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join, relative, resolve } from "node:path";
import chalk from "chalk";
import { spawnProcess, waitForChildProcess } from "../utils/child-process.js";
import { canonicalizePath, isLocalPath, resolvePath } from "../utils/paths.js";
import { killProcessTree } from "../utils/shell.js";
import { collectArtifactInventory, currentRequiredBuildArtifactsExist, findMissingBuildArtifacts, } from "./omo-local-update-artifacts.js";
import { computeBuildInputsHashFromLsTree } from "./omo-local-update-fingerprint.js";
import { defaultSpawnWorker } from "./omo-local-update-worker.js";
/**
* exported for tests only
*
* Shared process seam for the whole module. spawnProcess/waitForChildProcess neither capture
* output nor enforce timeouts; this adds both. The child is spawned detached on POSIX so it
* owns a process group, and the timeout kill goes through killProcessTree (SIGKILL to the
* whole group) - without that, bun/git descendants would keep mutating the build worktree
* after the direct child died.
*/
export async function defaultRun(command, args, options) {
const child = spawnProcess(command, args, {
cwd: options.cwd,
stdio: ["ignore", "pipe", "pipe"],
env: { ...process.env, ...options.env },
detached: process.platform !== "win32",
windowsHide: true,
});
let stdout = "";
let stderr = "";
child.stdout.on("data", (chunk) => {
stdout += chunk.toString();
});
child.stderr.on("data", (chunk) => {
stderr += chunk.toString();
});
const abort = new AbortController();
let timedOut = false;
const pid = child.pid;
const timer = options.timeoutMs === undefined
? undefined
: setTimeout(() => {
timedOut = true;
if (pid !== undefined) {
killProcessTree(pid);
}
abort.abort();
}, options.timeoutMs);
try {
const code = await waitForChildProcess(child, { signal: abort.signal });
return { code, stdout, stderr, timedOut };
}
finally {
if (timer !== undefined) {
clearTimeout(timer);
}
}
}
/** exported for tests only */
export function isKillSwitched(env) {
return env.SENPI_OMO_LOCAL_UPDATE === "0";
}
function defaultReadJson(path) {
try {
return JSON.parse(readFileSync(path, "utf-8"));
}
catch {
return undefined;
}
}
function packageNameOf(json) {
if (typeof json !== "object" || json === null) {
return undefined;
}
const name = json.name;
return typeof name === "string" ? name : undefined;
}
/** Same semantics as package-manager.ts's private getHomeDir (HOME env wins over os.homedir). */
function homeDir() {
return process.env.HOME || homedir();
}
/**
* exported for tests only
*
* Three-part detection gate (ALL must hold, else silent no-op):
* 1. A global settings `packages` entry (string or object form) is a local path whose resolved
* dir's package.json name is `@code-yeongyu/omo-senpi`.
* 2. The derived repo root (pluginPath/../../..) contains both workspace packages
* `@oh-my-opencode/omo-senpi` and `@oh-my-opencode/senpi-task`.
* 3. `git -C <repoRoot> rev-parse --show-toplevel` succeeds AND its canonicalized output equals
* the canonicalized repo root - a mismatched toplevel would mean the derived root is not
* the checkout it claims to be.
*/
export async function detectOmoLocalInstall(options) {
const readJson = options.readJson ?? defaultReadJson;
const exists = options.exists ?? existsSync;
if (!options.packages) {
return undefined;
}
for (const entry of options.packages) {
const source = typeof entry === "string" ? entry : entry.source;
if (!isLocalPath(source)) {
continue;
}
const pluginPath = resolvePath(source, options.agentDir, { homeDir: homeDir(), trim: true });
if (packageNameOf(readJson(join(pluginPath, "package.json"))) !== "@code-yeongyu/omo-senpi") {
continue;
}
const repoRoot = resolve(pluginPath, "..", "..", "..");
const omoSenpiPkgPath = join(repoRoot, "packages", "omo-senpi", "package.json");
const senpiTaskPkgPath = join(repoRoot, "packages", "senpi-task", "package.json");
if (!exists(omoSenpiPkgPath) || packageNameOf(readJson(omoSenpiPkgPath)) !== "@oh-my-opencode/omo-senpi") {
continue;
}
if (!exists(senpiTaskPkgPath) || packageNameOf(readJson(senpiTaskPkgPath)) !== "@oh-my-opencode/senpi-task") {
continue;
}
let topLevel;
try {
const result = await options.run("git", ["-C", repoRoot, "rev-parse", "--show-toplevel"], {});
if (result.code !== 0) {
continue;
}
topLevel = result.stdout.trim();
}
catch {
continue;
}
if (topLevel === "" || canonicalizePath(topLevel) !== canonicalizePath(repoRoot)) {
continue;
}
return { pluginPath, repoRoot };
}
return undefined;
}
/** exported for tests only */
export function omoLocalUpdateStampPath(agentDir) {
return join(agentDir, "omo-local-update-state.json");
}
/** exported for tests only */
export function readStamp(agentDir) {
const json = defaultReadJson(omoLocalUpdateStampPath(agentDir));
if (typeof json !== "object" || json === null) {
return undefined;
}
const candidate = json;
if (typeof candidate.repoRoot !== "string" ||
typeof candidate.sha !== "string" ||
typeof candidate.omoSenpiTree !== "string" ||
typeof candidate.senpiTaskTree !== "string" ||
typeof candidate.buildInputsHash !== "string" ||
typeof candidate.installedAt !== "string" ||
!Array.isArray(candidate.artifacts)) {
return undefined;
}
const artifacts = [];
for (const artifact of candidate.artifacts) {
if (typeof artifact !== "string") {
return undefined;
}
artifacts.push(artifact);
}
return {
repoRoot: candidate.repoRoot,
sha: candidate.sha,
omoSenpiTree: candidate.omoSenpiTree,
senpiTaskTree: candidate.senpiTaskTree,
buildInputsHash: candidate.buildInputsHash,
installedAt: candidate.installedAt,
artifacts,
};
}
/** exported for tests only */
export function writeStamp(agentDir, stamp) {
mkdirSync(agentDir, { recursive: true });
writeFileSync(omoLocalUpdateStampPath(agentDir), `${JSON.stringify(stamp, null, 2)}\n`, "utf-8");
}
/**
* exported for tests only
*
* Skip decision (taken BEFORE any worktree op, install, or write): skip only when the stamp
* belongs to this repo root, matches the frozen remote by sha OR by build-input fingerprint
* (a moved sha whose build inputs are untouched cannot change the built plugin), recorded a
* non-empty artifact inventory, and every inventoried path still exists. A repoRoot mismatch
* always updates; an empty/absent inventory never skips; force always updates.
*/
export function shouldSkipUpdate(options) {
if (options.force) {
return false;
}
const stamp = options.stamp;
if (!stamp) {
return false;
}
if (stamp.repoRoot !== options.repoRoot) {
return false;
}
if (stamp.sha !== options.remoteSha && stamp.buildInputsHash !== options.remoteBuildInputsHash) {
return false;
}
if (stamp.artifacts.length === 0) {
return false;
}
return options.stampArtifactsExist;
}
/**
* exported for tests only
*
* Failure of one orchestrator-owned step (fetch/worktree/install/build/artifacts/swap/stamp).
* The stage feeds `OMO local plugin update failed (<stage>): ...`; `output` (combined
* stdout+stderr of the failed step) is echoed dim, last 40 lines.
*/
export class OmoLocalStepError extends Error {
constructor(stage, message, output) {
super(message);
this.name = "OmoLocalStepError";
this.stage = stage;
this.output = output;
}
}
function firstErrorLine(result) {
for (const text of [result.stderr, result.stdout]) {
for (const line of text.split("\n")) {
const trimmed = line.trim();
if (trimmed !== "") {
return trimmed;
}
}
}
return "unknown error";
}
/**
* exported for tests only
*
* Inspect the two packages' state ON ORIGIN/DEV: ONE `git fetch origin dev` (120s, read-only
* - the ONLY network/ref operation in the module), then rev-parse/log reads against the
* frozen `origin/dev` ref. A fetch failure throws an OmoLocalStepError with stage "fetch"
* before anything else is touched.
*/
export async function computeRemoteState(options) {
const { repoRoot, run } = options;
const git = (args, timeoutMs) => run("git", args, { cwd: repoRoot, timeoutMs });
const requireOk = async (args, timeoutMs) => {
const result = await git(args, timeoutMs);
if (result.timedOut) {
throw new OmoLocalStepError("fetch", `git ${args.join(" ")} timed out`);
}
if (result.code !== 0) {
throw new OmoLocalStepError("fetch", `git ${args.join(" ")}: ${firstErrorLine(result)}`, `${result.stdout}${result.stderr}`);
}
return result.stdout.trim();
};
await requireOk(["fetch", "origin", "dev"], 120_000);
const sha = await requireOk(["rev-parse", "origin/dev"]);
if (sha === "") {
throw new OmoLocalStepError("fetch", "git rev-parse origin/dev: empty output");
}
const subject = await requireOk(["log", "-1", "--format=%s", "origin/dev"]);
const omoSenpiTree = await requireOk(["rev-parse", "origin/dev:packages/omo-senpi"]);
const senpiTaskTree = await requireOk(["rev-parse", "origin/dev:packages/senpi-task"]);
const buildInputsHash = computeBuildInputsHashFromLsTree(await requireOk(["ls-tree", "-z", "origin/dev"]));
return { sha, subject, omoSenpiTree, senpiTaskTree, buildInputsHash };
}
/** exported for tests only */
export function omoLocalUpdateLockPath(agentDir) {
return join(agentDir, "omo-local-update.lock");
}
/** exported for tests only */
export function omoLocalUpdateBuildWorktreePath(agentDir) {
return join(agentDir, "omo-local-update", "build-worktree");
}
function readLockFile(path) {
try {
const json = JSON.parse(readFileSync(path, "utf-8"));
if (typeof json.pid !== "number" || typeof json.nonce !== "string") {
return undefined;
}
return { pid: json.pid, nonce: json.nonce };
}
catch {
return undefined;
}
}
function pidIsAlive(pid) {
try {
process.kill(pid, 0);
return true;
}
catch (error) {
// EPERM: the process exists but belongs to another user.
return error.code === "EPERM";
}
}
/**
* Atomic lock acquisition (concurrency guard): `wx` create writing {pid, nonce, startedAt}.
* On EEXIST: a LIVE pid wins unconditionally - dim line, NEVER take over regardless of age.
* A dead pid (or an unreadable lock) is unlinked and the `wx` create retried ONCE; a
* concurrent winner's fresh lock then loses us the retry, which is correct. Synchronous
* throughout, so in-process contenders cannot interleave mid-check.
*/
function acquireOmoLocalLock(agentDir, log) {
mkdirSync(agentDir, { recursive: true });
const path = omoLocalUpdateLockPath(agentDir);
const lock = { path, pid: process.pid, nonce: randomUUID() };
const payload = JSON.stringify({ pid: lock.pid, nonce: lock.nonce, startedAt: new Date().toISOString() });
const tryCreate = () => {
try {
writeFileSync(path, payload, { flag: "wx" });
return true;
}
catch (error) {
if (error.code === "EEXIST") {
return false;
}
throw error;
}
};
const reportBusy = () => {
const existing = readLockFile(path);
log(chalk.dim(`OMO local plugin update already running (pid ${existing?.pid ?? "unknown"}); skipping.`));
return undefined;
};
if (tryCreate()) {
return lock;
}
const existing = readLockFile(path);
if (existing !== undefined && pidIsAlive(existing.pid)) {
return reportBusy();
}
try {
rmSync(path);
}
catch {
// Another process reclaimed first; the single retry below loses correctly.
}
if (tryCreate()) {
return lock;
}
return reportBusy();
}
/** Owner-checked unlink: re-read and match our own pid+nonce before deleting. */
function releaseOmoLocalLock(lock) {
try {
const existing = readLockFile(lock.path);
if (existing !== undefined && existing.pid === lock.pid && existing.nonce === lock.nonce) {
rmSync(lock.path);
}
}
catch {
// Lock release must never throw.
}
}
/** Marker error: the bun binary is missing from PATH (spawn ENOENT). */
class OmoLocalBunMissingError extends Error {
constructor() {
super("bun not found on PATH");
this.name = "OmoLocalBunMissingError";
}
}
/**
* One bun step through the shared run seam, run INSIDE the build worktree (never the user's
* checkout). A missing binary (spawn ENOENT) gets the dedicated marker so the orchestrator
* can render the single yellow bun warning; any other failed start, non-zero exit, or
* timeout becomes an OmoLocalStepError carrying the combined output for the dim dump.
*/
async function runBunStep(stage, args, worktree, run, timeoutMs) {
let result;
try {
result = await run("bun", args, { cwd: worktree, timeoutMs });
}
catch (error) {
if (error.code === "ENOENT") {
throw new OmoLocalBunMissingError();
}
throw new OmoLocalStepError(stage, `bun ${args.join(" ")} failed to start: ${error instanceof Error ? error.message : String(error)}`);
}
const output = `${result.stdout}${result.stderr}`;
if (result.timedOut) {
throw new OmoLocalStepError(stage, `bun ${args.join(" ")} timed out after ${Math.round(timeoutMs / 1000)}s`, output);
}
if (result.code !== 0) {
throw new OmoLocalStepError(stage, `bun ${args.join(" ")} exited with code ${result.code ?? "unknown"}`, output);
}
}
/**
* exported for tests only
*
* Validate/reuse the FEATURE-OWNED persistent build worktree:
* - present AND owned by this repo (`git -C <wt> rev-parse --git-common-dir` realpath-equals
* realpath(repoRoot/.git)) -> reuse: `git -C <wt> checkout --detach --force <sha>`. The
* --force is SAFE here: this worktree is exclusively feature-owned, so it only discards
* our own previous build outputs, and untracked node_modules survives for incremental
* installs.
* - present but foreign/invalid -> `git -C repoRoot worktree remove --force <wt>` (fs rm
* fallback), then re-add.
* - absent -> `git -C repoRoot worktree add --detach <wt> <sha>`.
* These are the ONLY git mutations in the module besides `git fetch`, and they touch only
* the feature-owned worktree registration - never the user's checkout state.
*/
export async function ensureBuildWorktree(options) {
const { worktree, repoRoot, sha, run } = options;
if (existsSync(worktree)) {
const commonDir = await run("git", ["-C", worktree, "rev-parse", "--git-common-dir"], {});
const owned = commonDir.code === 0 &&
commonDir.stdout.trim() !== "" &&
canonicalizePath(resolve(worktree, commonDir.stdout.trim())) === canonicalizePath(join(repoRoot, ".git"));
if (owned) {
const checkout = await run("git", ["-C", worktree, "checkout", "--detach", "--force", sha], {});
if (checkout.code !== 0) {
throw new OmoLocalStepError("worktree", `git checkout --detach --force: ${firstErrorLine(checkout)}`, `${checkout.stdout}${checkout.stderr}`);
}
return;
}
// Foreign or invalid directory at the feature-owned path: remove it (registered
// worktree or not) and fall through to a fresh add.
const remove = await run("git", ["-C", repoRoot, "worktree", "remove", "--force", worktree], {});
if (remove.code !== 0 || existsSync(worktree)) {
rmSync(worktree, { recursive: true, force: true });
}
}
mkdirSync(dirname(worktree), { recursive: true });
const add = await run("git", ["-C", repoRoot, "worktree", "add", "--detach", worktree, sha], {});
if (add.code === 0) {
return;
}
// A stale registration whose directory vanished blocks the add; prune metadata and retry once.
await run("git", ["-C", repoRoot, "worktree", "prune"], {});
const retry = await run("git", ["-C", repoRoot, "worktree", "add", "--detach", worktree, sha], {});
if (retry.code !== 0) {
throw new OmoLocalStepError("worktree", `git worktree add: ${firstErrorLine(retry)}`, `${add.stdout}${add.stderr}${retry.stdout}${retry.stderr}`);
}
}
const defaultFsSeam = {
cpSync: (source, destination) => {
cpSync(source, destination, { recursive: true });
},
renameSync: (oldPath, newPath) => {
renameSync(oldPath, newPath);
},
rmSync: (path) => {
rmSync(path, { recursive: true, force: true });
},
};
let swapCounter = 0;
/**
* exported for tests only
*
* ATOMIC SWAP of the install target. staging/prev are siblings of pluginPath (same parent
* => same filesystem => atomic renames): copy the built tree to staging, move pluginPath
* aside to prev, move staging into place. If the staging rename fails, prev is restored
* and staging removed before the error propagates - the local install is never left
* half-swapped. On success prev is removed.
*/
export function swapPluginDir(options) {
const seam = options.fs ?? defaultFsSeam;
swapCounter += 1;
const tag = `${Date.now()}-${process.pid}-${swapCounter}`;
const staging = `${options.pluginPath}.staging-${tag}`;
const prev = `${options.pluginPath}.prev-${tag}`;
seam.cpSync(options.sourceDir, staging);
seam.renameSync(options.pluginPath, prev);
try {
seam.renameSync(staging, options.pluginPath);
}
catch (error) {
seam.renameSync(prev, options.pluginPath);
seam.rmSync(staging);
throw error;
}
seam.rmSync(prev);
}
function firstLine(text) {
for (const line of text.split("\n")) {
const trimmed = line.trim();
if (trimmed !== "") {
return trimmed;
}
}
return "unknown error";
}
function lastNonEmptyLines(text, count) {
const lines = [];
for (const line of text.split("\n")) {
if (line.trim() !== "") {
lines.push(line);
}
}
return lines.slice(-count);
}
/**
* Beta hook entry point, called from bare `senpi update` before the self-update.
*
* SINGLE owner of the ORDERED state machine: gate chain (kill-switch -> detection) ->
* atomic lock acquisition (held through fetch, worktree, build, swap, stamp AND notify;
* owner-checked unlink in `finally`) -> computeRemoteState (ONE read-only fetch + frozen
* rev-parse reads of origin/dev) -> skip decision BEFORE any worktree op, install, or
* write (skip on matching sha OR matching build-input fingerprint) -> in "dispatch" mode
* (bare `senpi update` foreground, unless SENPI_OMO_LOCAL_UPDATE_SYNC=1) a needed rebuild
* is handed to a detached worker spawn (omo-local-update-worker.ts) and the hook returns ->
* otherwise ("build": the default and the worker path) ensureBuildWorktree
* (feature-owned persistent worktree, reuse-or-recreate) ->
* `bun install` (600s, cwd = build worktree) -> `bun run build:senpi-plugin` (900s, cwd =
* build worktree) -> completeness check in the WORKTREE plugin dir -> atomic swap of the
* install target -> writeStamp (inventory from the NEW plugin dir) -> notify (green line
* + dim per-package tree comparison when an old stamp existed).
*
* HARD GUARANTEES: the user's checkout receives ZERO git mutations (no
* checkout/branch/commit/merge/reset/clean/stash/push anywhere; only `git fetch` and
* feature-owned worktree add/remove). Only pluginPath content is replaced. This hook NEVER
* throws and NEVER sets process.exitCode: every failure downgrades to a yellow warning +
* dim manual hint so the senpi self-update continues untouched.
*/
export async function runOmoLocalUpdateBeta(options) {
const log = options.log ??
((message) => {
console.log(message);
});
const run = options.run ?? defaultRun;
const dispatchRequested = (options.mode ?? "build") === "dispatch" && options.env.SENPI_OMO_LOCAL_UPDATE_SYNC !== "1";
let repoRoot;
try {
if (isKillSwitched(options.env)) {
return;
}
const install = await detectOmoLocalInstall({
packages: options.settings?.packages,
agentDir: options.agentDir,
run,
});
if (!install) {
return;
}
repoRoot = install.repoRoot;
const { pluginPath } = install;
const lock = acquireOmoLocalLock(options.agentDir, log);
if (lock === undefined) {
return;
}
try {
log(chalk.dim("Updating OMO local plugins: fetching origin/dev..."));
const remoteState = await computeRemoteState({ repoRoot, run });
// Skip decision FIRST: a skip touches NOTHING (no worktree ops, no install, no writes).
const stamp = readStamp(options.agentDir);
const stampArtifactsExist = (stamp?.artifacts.every((artifact) => existsSync(join(pluginPath, artifact))) ?? false) &&
currentRequiredBuildArtifactsExist(pluginPath);
if (shouldSkipUpdate({
stamp,
repoRoot,
remoteSha: remoteState.sha,
remoteBuildInputsHash: remoteState.buildInputsHash,
stampArtifactsExist,
force: options.force ?? false,
})) {
const shortSkip = remoteState.sha.slice(0, 7);
log(stamp?.sha === remoteState.sha
? chalk.dim(`OMO local plugins already at origin/dev @${shortSkip}; skipping rebuild.`)
: chalk.dim(`OMO local plugins already match origin/dev @${shortSkip} (build inputs unchanged); skipping rebuild.`));
return;
}
// Dispatch: hand the rebuild to a detached worker so the foreground never blocks on
// the 30s+ install/build. The lock is released BEFORE the spawn (release is
// owner-checked, so the finally re-release no-ops) or the worker's own lock
// acquisition would race the still-live foreground pid and give up.
if (dispatchRequested) {
releaseOmoLocalLock(lock);
const spawnWorker = options.spawnWorker ?? defaultSpawnWorker;
const spawned = spawnWorker({ agentDir: options.agentDir, force: options.force ?? false });
if (spawned.ok) {
log(chalk.dim(`Updating OMO local plugins in background: origin/dev @${remoteState.sha.slice(0, 7)} - ${remoteState.subject} (log: ${spawned.logPath})`));
}
else {
log(chalk.yellow(`OMO local plugin background update could not start: ${spawned.message}`));
log(chalk.dim("Run `senpi update` again, or set SENPI_OMO_LOCAL_UPDATE_SYNC=1 to update in the foreground."));
}
return;
}
// Build in the feature-owned persistent worktree - never in the user's checkout.
const worktree = omoLocalUpdateBuildWorktreePath(options.agentDir);
await ensureBuildWorktree({ worktree, repoRoot, sha: remoteState.sha, run });
try {
log(chalk.dim("Updating OMO local plugins: installing deps..."));
await runBunStep("install", ["install"], worktree, run, 600_000);
log(chalk.dim("Updating OMO local plugins: building plugin..."));
await runBunStep("build", ["run", "build:senpi-plugin"], worktree, run, 900_000);
}
catch (stepError) {
if (stepError instanceof OmoLocalBunMissingError) {
log(chalk.yellow("OMO local plugin update skipped: bun is required to install and build the plugin but was not found on PATH. Install bun and re-run `senpi update`."));
return;
}
throw stepError;
}
const worktreePluginDir = join(worktree, relative(repoRoot, pluginPath));
const missing = findMissingBuildArtifacts(worktreePluginDir);
if (missing.length > 0) {
throw new OmoLocalStepError("artifacts", `build incomplete - missing: ${missing.join(", ")}`);
}
// Atomic swap of the install target, then stamp from the NEW plugin dir inventory.
try {
swapPluginDir({ pluginPath, sourceDir: worktreePluginDir });
}
catch (swapError) {
throw new OmoLocalStepError("swap", `atomic swap failed: ${swapError instanceof Error ? swapError.message : String(swapError)}`);
}
writeStamp(options.agentDir, {
repoRoot,
sha: remoteState.sha,
omoSenpiTree: remoteState.omoSenpiTree,
senpiTaskTree: remoteState.senpiTaskTree,
buildInputsHash: remoteState.buildInputsHash,
installedAt: new Date().toISOString(),
artifacts: collectArtifactInventory(pluginPath),
});
const short = remoteState.sha.slice(0, 7);
log(chalk.green(`Updated OMO local plugins (omo-senpi + senpi-task) to origin/dev @${short} - ${remoteState.subject}`));
if (stamp !== undefined) {
const omoLine = stamp.omoSenpiTree === remoteState.omoSenpiTree ? "unchanged" : "updated";
const taskLine = stamp.senpiTaskTree === remoteState.senpiTaskTree ? "unchanged" : "updated";
log(chalk.dim(`omo-senpi: ${omoLine}, senpi-task: ${taskLine}`));
}
}
finally {
releaseOmoLocalLock(lock);
}
}
catch (error) {
// The hook NEVER throws and NEVER sets process.exitCode: render the yellow failure
// line (+ dim failed-step output tail + dim manual hint) and let the senpi
// self-update continue.
const stage = error instanceof OmoLocalStepError ? error.stage : "unknown";
const message = error instanceof Error ? error.message : String(error);
log(chalk.yellow(`OMO local plugin update failed (${stage}): ${firstLine(message)}`));
if (error instanceof OmoLocalStepError && error.output !== undefined) {
for (const line of lastNonEmptyLines(error.output, 40)) {
log(chalk.dim(line));
}
}
if (repoRoot !== undefined) {
log(chalk.dim(`To update manually: git -C ${repoRoot} pull origin dev && bun install && bun run build:senpi-plugin`));
}
}
}
//# sourceMappingURL=omo-local-update.js.map