2026-01-18 15:56:24 -05:00
|
|
|
const HELP_FLAGS = new Set(["-h", "--help"]);
|
2026-02-20 06:04:22 +04:00
|
|
|
const VERSION_FLAGS = new Set(["-V", "--version"]);
|
|
|
|
|
const ROOT_VERSION_ALIAS_FLAG = "-v";
|
|
|
|
|
const ROOT_BOOLEAN_FLAGS = new Set(["--dev", "--no-color"]);
|
|
|
|
|
const ROOT_VALUE_FLAGS = new Set(["--profile"]);
|
2026-01-18 23:28:09 +00:00
|
|
|
const FLAG_TERMINATOR = "--";
|
2026-01-18 15:56:24 -05:00
|
|
|
|
|
|
|
|
export function hasHelpOrVersion(argv: string[]): boolean {
|
2026-02-20 06:04:22 +04:00
|
|
|
return (
|
|
|
|
|
argv.some((arg) => HELP_FLAGS.has(arg) || VERSION_FLAGS.has(arg)) || hasRootVersionAlias(argv)
|
|
|
|
|
);
|
2026-01-18 15:56:24 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-18 23:28:09 +00:00
|
|
|
function isValueToken(arg: string | undefined): boolean {
|
2026-01-31 16:19:20 +09:00
|
|
|
if (!arg) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (arg === FLAG_TERMINATOR) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!arg.startsWith("-")) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2026-01-18 23:28:09 +00:00
|
|
|
return /^-\d+(?:\.\d+)?$/.test(arg);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 00:52:13 +00:00
|
|
|
function parsePositiveInt(value: string): number | undefined {
|
|
|
|
|
const parsed = Number.parseInt(value, 10);
|
2026-01-31 16:19:20 +09:00
|
|
|
if (Number.isNaN(parsed) || parsed <= 0) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
2026-01-19 00:52:13 +00:00
|
|
|
return parsed;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-18 23:28:09 +00:00
|
|
|
export function hasFlag(argv: string[], name: string): boolean {
|
|
|
|
|
const args = argv.slice(2);
|
|
|
|
|
for (const arg of args) {
|
2026-01-31 16:19:20 +09:00
|
|
|
if (arg === FLAG_TERMINATOR) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (arg === name) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2026-01-18 23:28:09 +00:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 06:04:22 +04:00
|
|
|
export function hasRootVersionAlias(argv: string[]): boolean {
|
|
|
|
|
const args = argv.slice(2);
|
|
|
|
|
let hasAlias = false;
|
|
|
|
|
for (let i = 0; i < args.length; i += 1) {
|
|
|
|
|
const arg = args[i];
|
|
|
|
|
if (!arg) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (arg === FLAG_TERMINATOR) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (arg === ROOT_VERSION_ALIAS_FLAG) {
|
|
|
|
|
hasAlias = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (ROOT_BOOLEAN_FLAGS.has(arg)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (arg.startsWith("--profile=")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (ROOT_VALUE_FLAGS.has(arg)) {
|
|
|
|
|
const next = args[i + 1];
|
|
|
|
|
if (isValueToken(next)) {
|
|
|
|
|
i += 1;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (arg.startsWith("-")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return hasAlias;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-18 23:28:09 +00:00
|
|
|
export function getFlagValue(argv: string[], name: string): string | null | undefined {
|
|
|
|
|
const args = argv.slice(2);
|
|
|
|
|
for (let i = 0; i < args.length; i += 1) {
|
|
|
|
|
const arg = args[i];
|
2026-01-31 16:19:20 +09:00
|
|
|
if (arg === FLAG_TERMINATOR) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-01-18 23:28:09 +00:00
|
|
|
if (arg === name) {
|
|
|
|
|
const next = args[i + 1];
|
|
|
|
|
return isValueToken(next) ? next : null;
|
|
|
|
|
}
|
|
|
|
|
if (arg.startsWith(`${name}=`)) {
|
|
|
|
|
const value = arg.slice(name.length + 1);
|
|
|
|
|
return value ? value : null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 01:11:42 +00:00
|
|
|
export function getVerboseFlag(argv: string[], options?: { includeDebug?: boolean }): boolean {
|
2026-01-31 16:19:20 +09:00
|
|
|
if (hasFlag(argv, "--verbose")) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (options?.includeDebug && hasFlag(argv, "--debug")) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2026-01-19 00:52:13 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 01:11:42 +00:00
|
|
|
export function getPositiveIntFlagValue(argv: string[], name: string): number | null | undefined {
|
2026-01-19 00:52:13 +00:00
|
|
|
const raw = getFlagValue(argv, name);
|
2026-01-31 16:19:20 +09:00
|
|
|
if (raw === null || raw === undefined) {
|
|
|
|
|
return raw;
|
|
|
|
|
}
|
2026-01-19 00:52:13 +00:00
|
|
|
return parsePositiveInt(raw);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-18 15:56:24 -05:00
|
|
|
export function getCommandPath(argv: string[], depth = 2): string[] {
|
|
|
|
|
const args = argv.slice(2);
|
|
|
|
|
const path: string[] = [];
|
|
|
|
|
for (let i = 0; i < args.length; i += 1) {
|
|
|
|
|
const arg = args[i];
|
2026-01-31 16:19:20 +09:00
|
|
|
if (!arg) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (arg === "--") {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (arg.startsWith("-")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-01-18 15:56:24 -05:00
|
|
|
path.push(arg);
|
2026-01-31 16:19:20 +09:00
|
|
|
if (path.length >= depth) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-01-18 15:56:24 -05:00
|
|
|
}
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getPrimaryCommand(argv: string[]): string | null {
|
|
|
|
|
const [primary] = getCommandPath(argv, 1);
|
|
|
|
|
return primary ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function buildParseArgv(params: {
|
|
|
|
|
programName?: string;
|
|
|
|
|
rawArgs?: string[];
|
|
|
|
|
fallbackArgv?: string[];
|
|
|
|
|
}): string[] {
|
|
|
|
|
const baseArgv =
|
|
|
|
|
params.rawArgs && params.rawArgs.length > 0
|
|
|
|
|
? params.rawArgs
|
|
|
|
|
: params.fallbackArgv && params.fallbackArgv.length > 0
|
|
|
|
|
? params.fallbackArgv
|
|
|
|
|
: process.argv;
|
|
|
|
|
const programName = params.programName ?? "";
|
|
|
|
|
const normalizedArgv =
|
|
|
|
|
programName && baseArgv[0] === programName
|
|
|
|
|
? baseArgv.slice(1)
|
Ironclaw rename: update CLI binary references, fix Next.js invocation, harden package resolution
Comprehensive update to complete the openclaw → ironclaw CLI rename across the
codebase, fix build/runtime issues, and add test coverage for infra modules.
CLI binary rename (openclaw → ironclaw):
- Update DEFAULT_CLI_NAME and all argv parsing to recognize "ironclaw" binary
- Extend package name sets (CORE_PACKAGE_NAMES, ALL_PACKAGE_NAMES) to include
both "ironclaw" and "openclaw" for backward compatibility
- Update NPM registry URL to fetch from ironclaw package
- Update gateway lock detection, port listener classification, and launchd/systemd
service scanning to recognize ironclaw-prefixed services and binaries
- Update daemon inspect markers and legacy detection for ironclaw
- Update voice-call extension core-bridge to resolve ironclaw package root
- Fix install instructions in embeddings error messages (npm i -g ironclaw@latest)
Web app / Next.js fixes:
- Replace fragile `npx next` invocations with direct `node next-bin` resolution
to avoid broken pnpm virtual-store symlinks in global installs
- Add resolveNextBin() helper that resolves apps/web/node_modules/next directly
Infra hardening:
- Workspace templates: compute both source and dist fallback paths for template
directory resolution (fixes templates not found in bundled builds)
- Control UI assets: recognize both "openclaw" and "ironclaw" package names
- Update-check, update-runner, update-cli: normalize ironclaw@ tag prefixes
New tests:
- Add openclaw-root.test.ts, ports-format.test.ts, update-global.test.ts
- Add workspace-templates.test.ts and control-ui-assets.test.ts coverage
- Add argv.test.ts coverage for ironclaw binary detection
Test fixes (28 failures → 0):
- Update all test assertions expecting "openclaw" CLI command output to "ironclaw"
- Fix version.test.ts package name from "openclaw" to "ironclaw"
- Fix camera/canvas temp path patterns in nodes-camera and program.nodes-media tests
- Fix pairing message, telegram bot, channels, daemon, onboard, gateway tool,
status, and profile test expectations
Version: 2026.2.10-1.2 (published to npm as ironclaw@2026.2.10-1.2)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 12:19:49 -08:00
|
|
|
: baseArgv[0]?.endsWith("openclaw") || baseArgv[0]?.endsWith("ironclaw")
|
2026-01-18 15:56:24 -05:00
|
|
|
? baseArgv.slice(1)
|
|
|
|
|
: baseArgv;
|
2026-01-22 22:11:15 -06:00
|
|
|
const executable = (normalizedArgv[0]?.split(/[/\\]/).pop() ?? "").toLowerCase();
|
2026-01-18 15:56:24 -05:00
|
|
|
const looksLikeNode =
|
2026-01-26 20:29:15 -05:00
|
|
|
normalizedArgv.length >= 2 && (isNodeExecutable(executable) || isBunExecutable(executable));
|
2026-01-31 16:19:20 +09:00
|
|
|
if (looksLikeNode) {
|
|
|
|
|
return normalizedArgv;
|
|
|
|
|
}
|
Ironclaw rename: update CLI binary references, fix Next.js invocation, harden package resolution
Comprehensive update to complete the openclaw → ironclaw CLI rename across the
codebase, fix build/runtime issues, and add test coverage for infra modules.
CLI binary rename (openclaw → ironclaw):
- Update DEFAULT_CLI_NAME and all argv parsing to recognize "ironclaw" binary
- Extend package name sets (CORE_PACKAGE_NAMES, ALL_PACKAGE_NAMES) to include
both "ironclaw" and "openclaw" for backward compatibility
- Update NPM registry URL to fetch from ironclaw package
- Update gateway lock detection, port listener classification, and launchd/systemd
service scanning to recognize ironclaw-prefixed services and binaries
- Update daemon inspect markers and legacy detection for ironclaw
- Update voice-call extension core-bridge to resolve ironclaw package root
- Fix install instructions in embeddings error messages (npm i -g ironclaw@latest)
Web app / Next.js fixes:
- Replace fragile `npx next` invocations with direct `node next-bin` resolution
to avoid broken pnpm virtual-store symlinks in global installs
- Add resolveNextBin() helper that resolves apps/web/node_modules/next directly
Infra hardening:
- Workspace templates: compute both source and dist fallback paths for template
directory resolution (fixes templates not found in bundled builds)
- Control UI assets: recognize both "openclaw" and "ironclaw" package names
- Update-check, update-runner, update-cli: normalize ironclaw@ tag prefixes
New tests:
- Add openclaw-root.test.ts, ports-format.test.ts, update-global.test.ts
- Add workspace-templates.test.ts and control-ui-assets.test.ts coverage
- Add argv.test.ts coverage for ironclaw binary detection
Test fixes (28 failures → 0):
- Update all test assertions expecting "openclaw" CLI command output to "ironclaw"
- Fix version.test.ts package name from "openclaw" to "ironclaw"
- Fix camera/canvas temp path patterns in nodes-camera and program.nodes-media tests
- Fix pairing message, telegram bot, channels, daemon, onboard, gateway tool,
status, and profile test expectations
Version: 2026.2.10-1.2 (published to npm as ironclaw@2026.2.10-1.2)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 12:19:49 -08:00
|
|
|
return ["node", programName || "ironclaw", ...normalizedArgv];
|
2026-01-18 15:56:24 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-26 20:29:15 -05:00
|
|
|
const nodeExecutablePattern = /^node-\d+(?:\.\d+)*(?:\.exe)?$/;
|
|
|
|
|
|
|
|
|
|
function isNodeExecutable(executable: string): boolean {
|
|
|
|
|
return (
|
|
|
|
|
executable === "node" ||
|
|
|
|
|
executable === "node.exe" ||
|
|
|
|
|
executable === "nodejs" ||
|
|
|
|
|
executable === "nodejs.exe" ||
|
|
|
|
|
nodeExecutablePattern.test(executable)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isBunExecutable(executable: string): boolean {
|
|
|
|
|
return executable === "bun" || executable === "bun.exe";
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-19 00:52:13 +00:00
|
|
|
export function shouldMigrateStateFromPath(path: string[]): boolean {
|
2026-01-31 16:19:20 +09:00
|
|
|
if (path.length === 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2026-01-18 15:56:24 -05:00
|
|
|
const [primary, secondary] = path;
|
2026-01-31 16:19:20 +09:00
|
|
|
if (primary === "health" || primary === "status" || primary === "sessions") {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-02-14 01:18:20 +00:00
|
|
|
if (primary === "config" && (secondary === "get" || secondary === "unset")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (primary === "models" && (secondary === "list" || secondary === "status")) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-01-31 16:19:20 +09:00
|
|
|
if (primary === "memory" && secondary === "status") {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (primary === "agent") {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-01-19 00:52:13 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function shouldMigrateState(argv: string[]): boolean {
|
|
|
|
|
return shouldMigrateStateFromPath(getCommandPath(argv, 2));
|
2026-01-18 15:56:24 -05:00
|
|
|
}
|