Turn on noUnusedLocals/noUnusedParameters so the compiler keeps flagging dead symbols, then clear the 737 findings it reports: unused imports across src/, unused parameters, unreachable locals, and the copy-pasted 135-line import prologues in the seal tool modules (each tool file now imports only what it uses). Also applies the equivalent-safe lint rewrites (Array.from instead of new Array(n).fill, non-null assertions in tests after toBeDefined, simplified spreads, unused catch params) that oxlint will gate in a later commit.
89 lines
2.4 KiB
TypeScript
89 lines
2.4 KiB
TypeScript
import { existsSync, symlinkSync } from "node:fs";
|
|
import { homedir } from "node:os";
|
|
import { basename, dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { syncGlobalSkillIfPresent } from "./embedded-skill.js";
|
|
|
|
export function isCompiledBinary(execPath = process.execPath, metaUrl = import.meta.url): boolean {
|
|
if (metaUrl.includes("/$bunfs/") || metaUrl.includes("\\$bunfs\\")) {
|
|
return true;
|
|
}
|
|
const lower = execPath.toLowerCase().replace(/\\/g, "/");
|
|
return !lower.endsWith("/bun") && !lower.endsWith("/bun.exe") && !lower.endsWith("/node") && !lower.endsWith("/node.exe");
|
|
}
|
|
|
|
export function resolveAppRoot(entryFile?: string, isCompiled = isCompiledBinary()): string {
|
|
if (isCompiled) {
|
|
return process.cwd();
|
|
}
|
|
const file = entryFile || fileURLToPath(import.meta.url);
|
|
return dirname(dirname(file));
|
|
}
|
|
|
|
export type LauncherConfig = {
|
|
command: string;
|
|
args?: string[];
|
|
};
|
|
|
|
export function resolveDefaultLauncher(
|
|
entryFile: string,
|
|
isCompiled = isCompiledBinary(),
|
|
execPath = process.execPath
|
|
): LauncherConfig {
|
|
if (isCompiled) {
|
|
return {
|
|
command: execPath,
|
|
args: []
|
|
};
|
|
}
|
|
return {
|
|
command: execPath,
|
|
args: [entryFile]
|
|
};
|
|
}
|
|
|
|
export function performRuntimeSelfHealing(): {
|
|
binaryHealed?: boolean;
|
|
skillHealed?: boolean;
|
|
} {
|
|
const result: { binaryHealed?: boolean; skillHealed?: boolean } = {};
|
|
|
|
// 1. Binary executable alias self-healing
|
|
try {
|
|
if (isCompiledBinary()) {
|
|
const execPath = process.execPath;
|
|
const base = basename(execPath);
|
|
const isWin = process.platform === "win32";
|
|
const legacyName = isWin ? "seal-home.exe" : "seal-home";
|
|
const primaryName = isWin ? "seal-use.exe" : "seal-use";
|
|
|
|
if (base === legacyName) {
|
|
const primaryPath = join(dirname(execPath), primaryName);
|
|
if (!existsSync(primaryPath)) {
|
|
try {
|
|
symlinkSync(execPath, primaryPath);
|
|
result.binaryHealed = true;
|
|
} catch {
|
|
// ignore if permissions do not allow
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch {
|
|
// ignore
|
|
}
|
|
|
|
// 2. Legacy skill cutover self-healing
|
|
try {
|
|
const legacySkillDir = join(homedir(), ".agents", "skills", "seal-home");
|
|
if (existsSync(legacySkillDir)) {
|
|
syncGlobalSkillIfPresent();
|
|
result.skillHealed = true;
|
|
}
|
|
} catch {
|
|
// ignore
|
|
}
|
|
|
|
return result;
|
|
}
|