Add runtime detection and unified mcp and probe CLI commands

This commit is contained in:
gitea committed 2026-08-25 13:49:00 +08:00
1 parent 551fb9177f
commit b109f3f49f
8 files changed
+118 -19

No files matched your search

+2
View File
@@ -44,6 +44,8 @@ describe("CLI version & help handling", () => {
expect(result.status).toBe(0);
expect(result.stdout).toContain("seal-home CLI");
expect(result.stdout).toContain("Usage:");
expect(result.stdout).toContain("seal-home mcp");
expect(result.stdout).toContain("seal-home probe [<corpId>]");
expect(result.stdout).toContain("seal-home users search <keyword>");
expect(result.stdout).toContain("seal-home users delegation <userIdOrPhone|name>");
expect(result.stdout).toContain("seal-home webhook get|find <idOrName>");
+5 -6
View File
@@ -1,19 +1,18 @@
#!/usr/bin/env bun
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { runCli } from "./cli/runner.js";
import { isCompiledBinary, resolveAppRoot, resolveDefaultLauncher } from "./core/runtime.js";
const entryFile = fileURLToPath(import.meta.url);
const appRoot = dirname(dirname(entryFile));
const isCompiled = isCompiledBinary();
const appRoot = resolveAppRoot(entryFile, isCompiled);
const launcher = resolveDefaultLauncher(entryFile, isCompiled);
const result = await runCli(Bun.argv.slice(2), {
appRoot,
entryFile,
launcher: {
command: process.execPath,
args: [entryFile]
}
launcher
});
if (result.stdout) process.stdout.write(result.stdout);
+19 -1
View File
@@ -24,6 +24,8 @@ import { clearCorpTokenCache } from "../core/auth/token-store.js";
import { getHoseProvisionalAuthLink } from "../core/auth/hose.js";
import { VERSION } from "../version.js";
import { runServiceCommand, serviceStatus, type ServiceConfig } from "./service.js";
import { startServer } from "../server.js";
import { runProbe } from "../probe.js";
const DEFAULT_APP_ROOT = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
const STATE_DIR = join(homedir(), ".config", "seal-home");
@@ -50,7 +52,10 @@ const KNOWN_AREAS = new Set([
"context",
"rules",
"approval-runs",
"simulation"
"simulation",
"mcp",
"server",
"probe"
]);
type ParsedArgs = {
@@ -198,6 +203,17 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
return;
}
if (area === "mcp" || area === "server") {
await startServer();
return;
}
if (area === "probe") {
const corpId = maybeName ?? stringOption(args.options.corp) ?? (action && action !== "--corp" ? action : undefined);
await runProbe({ corpId });
return;
}
if (area === "service") {
const result = await runServiceCommand(action, {
appRoot: runtime.appRoot,
@@ -1561,6 +1577,8 @@ function printHelp() {
Usage:
seal-home version
seal-home mcp
seal-home probe [<corpId>]
seal-home config paths
seal-home config get
seal-home config mode <stateful|stateless> [--corp <corpId>]
+5 -1
View File
@@ -133,7 +133,11 @@ function isSealHomeProcess(pid: number, appRoot: string) {
try {
const command = execFileSync("ps", ["-p", String(pid), "-o", "command="], { encoding: "utf8" });
return command.includes(appRoot) && command.includes("service") && command.includes("run");
const matchesTarget =
command.includes(appRoot) ||
command.includes("seal-home") ||
command.includes("src/cli.ts");
return matchesTarget && command.includes("service") && command.includes("run");
} catch {
return false;
}
+33
View File
@@ -0,0 +1,33 @@
import { describe, expect, test } from "bun:test";
import { isCompiledBinary, resolveAppRoot, resolveDefaultLauncher } from "./runtime.js";
describe("runtime detection and launcher", () => {
test("isCompiledBinary detects bun runtime executable vs standalone binary", () => {
expect(isCompiledBinary("/Users/user/.bun/bin/bun", "file:///Users/user/code/src/cli.ts")).toBe(false);
expect(isCompiledBinary("C:\\Users\\user\\.bun\\bin\\bun.exe", "file:///C:/code/src/cli.ts")).toBe(false);
expect(isCompiledBinary("/usr/local/bin/seal-home", "file:///Users/user/code/src/cli.ts")).toBe(true);
expect(isCompiledBinary("/Users/user/.bun/bin/bun", "file:///$bunfs/root/src/cli.ts")).toBe(true);
});
test("resolveAppRoot returns cwd for compiled binary and project root for source", () => {
const sourceRoot = resolveAppRoot("/Users/user/code/src/cli.ts", false);
expect(sourceRoot).toBe("/Users/user/code");
const binaryRoot = resolveAppRoot(undefined, true);
expect(binaryRoot).toBe(process.cwd());
});
test("resolveDefaultLauncher configures args based on compiled mode", () => {
const sourceLauncher = resolveDefaultLauncher("/Users/user/code/src/cli.ts", false, "/path/to/bun");
expect(sourceLauncher).toEqual({
command: "/path/to/bun",
args: ["/Users/user/code/src/cli.ts"]
});
const binaryLauncher = resolveDefaultLauncher("/ignored", true, "/usr/local/bin/seal-home");
expect(binaryLauncher).toEqual({
command: "/usr/local/bin/seal-home",
args: []
});
});
});
+40
View File
@@ -0,0 +1,40 @@
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
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");
}
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]
};
}
+10 -8
View File
@@ -4,9 +4,7 @@ import { createSealClient } from "./core/http/factory.js";
import { resolveLiveSealEnterpriseConfig } from "./domains/seal/source.js";
import { getApprovalContext } from "./domains/seal/api.js";
async function main() {
const args = Bun.argv.slice(2);
const corpId = args[0] === "--corp" ? args[1] : args[0];
export async function runProbe(options: { corpId?: string } = {}) {
const corps = loadCorpConfigs();
const globalConfig = loadGlobalConfig();
const corp = resolveCorpConfig(
@@ -14,7 +12,7 @@ async function main() {
{
stateful: globalConfig.stateful,
defaultCorpId: globalConfig.defaultCorpId,
corpId
corpId: options.corpId
},
getEnterprisesDirCandidates()
);
@@ -43,7 +41,11 @@ async function main() {
}, null, 2));
}
main().catch((error) => {
console.error(error instanceof Error ? error.message : error);
process.exit(1);
});
if (import.meta.main) {
const args = process.argv.slice(2);
const corpId = args[0] === "--corp" ? args[1] : args[0];
runProbe({ corpId }).catch((error) => {
console.error(error instanceof Error ? error.message : error);
process.exit(1);
});
}
+4 -3
View File
@@ -199,9 +199,10 @@ async function runEmbeddedCli() {
process.exitCode = result.exitCode;
}
const isMainModule = process.argv[1]
? resolve(process.argv[1]) === resolve(serverEntryFile)
: false;
const isMainModule = Boolean(
(import.meta as any).main ||
(!import.meta.url.includes("$bunfs") && process.argv[1] && resolve(process.argv[1]) === resolve(serverEntryFile))
);
if (isMainModule) {
if (process.argv[2] === "--seal-home-cli") {