mirror of
https://github.com/openclaw/openclaw.git
synced 2026-09-28 05:54:09 +08:00
* fix(startup): keep legacy state repair in doctor Separate current-state startup readiness from explicit Doctor migrations. Preserve current config recovery, quarantine, device identity checks, lease fencing and updater completion ownership. Remove automatic startup migration/checkpoint and node-host import paths. Keep shipped read-only context and roster projections unchanged. * test(doctor): align proof callers with repair ownership Keep survivor fixture setup in caller order and select the shared Doctor flow separately from the channel-specific proof. Include the complete isolated diagnostics dependency closure. Prove ordinary startup preserves legacy directories before explicit Doctor repair, and await SQLite worker closure before test cleanup. * test(startup): verify index repair through gateway maintenance * test(doctor): align cutover fixtures with state owners Reacquire the database after Doctor retires its generation, retain real session history for startup refusal, and keep pending reads at their actual owners. Distinguish the reused readonly reader from independent snapshot-token children and verify every child settles. * fix(doctor): preserve image activation and published migration receipts Run the shared noninteractive Doctor owner before default and Compose Gateway activation so retained Docker volumes keep their published upgrade path while ordinary Gateway startup stays readiness-only. Preserve root selectors and settle interrupted repair before executing the original command. Retain the path-wide tombstones emitted by the published restart-sentinel importer, including consumed notices, and validate completed source decisions before retiring recreated inputs. Add the root-image activation lane and causal receipt coverage without introducing a schema, option, or second importer. * test(docker): preserve release state pairs in upgrade proof Use the existing synthetic v2026.9.2 corpus instead of combining a July shared database with a later agent schema. Preserve its deletion journal, registry, both transcript payloads, paired backups, and unsafe-state controls. Register the two shell-launched helpers with Knip. * test(docker): normalize persisted schema snapshot rows Compare node:sqlite schema rows using the same plain-object representation as the saved JSON preimage. Keep strict schema, row, and value-type assertions intact. * fix(models): retain discovered models after refresh failures Record successful legacy catalog results at the producer boundary so unavailable refreshes retain the accepted inventory. Preserve explicit outcomes, advisory SDK fallback behavior, and first-discovery starter policy. * fix(models): preserve skipped catalog outcome semantics Mark bundled static, configured, and advisory catalog projections with explicit empty outcomes so legacy success inference cannot promote them to observed account inventory. Preserve live outcomes and helper types. Keep exact auth provenance histories and move existing fixture/policy code into focused owners where required by the line-cap ratchet. Validation: 447 producer and sibling cases, 56 shared self-hosted cases, 95 auth/policy cases, causal missing-outcome failures, maintained checks, and independent review. * test(plugin-sdk): keep discovery loader types acyclic Move the shared loader type into a leaf consumed by both discovery contract helpers. Preserve its public provider-test-contracts export without a child-to-parent type import cycle. Validation: maintained Madge check reports zero cycles; core, all core test graphs, extension test types, lint, formatting and independent review pass. Runtime behavior and previous catalog proof are unchanged. * fix(plugin-sdk): mark generated static catalogs explicitly Keep the generated non-live, non-strict catalog adapter from claiming successful acquisition for manifest or configured rows. Preserve null, errors, strict and custom callbacks, static catalogs, and public types. Validation: three existing controls fail before the correction; all49 owner and sibling cases pass afterward, with types, lint, line caps and fresh independent review clean. * test(gateway): cover restart import during state retirement Exercise canonical database close while a legacy notice read is paused. Verify admission rejection, retained canonical and source bytes, no migration receipt, and joined maintenance custody without changing the accepted sidecar-stop drain contract. * fix(test): drain sharing fixtures before removing state * test: bind retirement regression to its own worker * docs(docker): clarify automatic Doctor activation * test(doctor): keep readiness fixture runtime private * test: stabilize shared skill watcher fixture roots (cherry picked from commit15606be10e) * perf(tooling): share indexed scope parsing for artifact scans (cherry picked from commit6e6eef9f5b) * fix(team-reports): use source owners in scheduler tests The source barrel retired in #157819, but the scheduler tests still imported it, breaking the extension test typecheck on main. Import the Discord and GitHub owners directly, matching the production caller. Validated the original TS2307/TS7006 failure, the corrected extension type graph, all 36 scheduler tests, changed checks, and independent P2 review. (cherry picked from commit7c4866c73b) * test(install): isolate global npm configuration in version fixtures Use a controlled absent global config inside the fixture home so the release helper does not query the deliberately narrow npm stub. Keep predecessor selection, fresh-install behavior, and expected exits intact. (cherry picked from commit0a9eefc76c) * test(docker): verify the complete image activation entrypoint
192 lines
5.8 KiB
JavaScript
192 lines
5.8 KiB
JavaScript
/** CLI token that stops root option scanning and leaves following args positional. */
|
|
export const FLAG_TERMINATOR = "--";
|
|
|
|
const ROOT_BOOLEAN_FLAGS = new Set(["--dev", "--no-color"]);
|
|
const ROOT_VALUE_FLAGS = new Set(["--profile", "--log-level", "--container"]);
|
|
|
|
/** Returns whether a token can be consumed as a root option value. */
|
|
export function isValueToken(arg) {
|
|
if (!arg || arg === FLAG_TERMINATOR) {
|
|
return false;
|
|
}
|
|
if (!arg.startsWith("-")) {
|
|
return true;
|
|
}
|
|
return /^-\d+(?:\.\d+)?$/.test(arg);
|
|
}
|
|
|
|
/** Count root-option tokens conservatively for route matching. */
|
|
export function consumeRootOptionToken(args, index) {
|
|
const arg = args[index];
|
|
if (!arg) {
|
|
return 0;
|
|
}
|
|
if (ROOT_BOOLEAN_FLAGS.has(arg)) {
|
|
return 1;
|
|
}
|
|
if (
|
|
arg.startsWith("--profile=") ||
|
|
arg.startsWith("--log-level=") ||
|
|
arg.startsWith("--container=")
|
|
) {
|
|
return 1;
|
|
}
|
|
if (ROOT_VALUE_FLAGS.has(arg)) {
|
|
return isValueToken(args[index + 1]) ? 2 : 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/** Consume required root values by their Commander role before startup policy is selected. */
|
|
export function consumeRootCommandOptionToken(args, index) {
|
|
return consumeKnownOptionToken(args, index, ROOT_BOOLEAN_FLAGS, ROOT_VALUE_FLAGS, "command-path");
|
|
}
|
|
|
|
/** Read positional command tokens while accepting root options at any pre-terminator position. */
|
|
export function getRootOptionAwareCommandPath(argv, depth) {
|
|
const args = argv.slice(2);
|
|
const path = [];
|
|
let literal = false;
|
|
for (let index = 0; index < args.length; index += 1) {
|
|
const arg = args[index];
|
|
if (!arg) {
|
|
break;
|
|
}
|
|
if (!literal && arg === FLAG_TERMINATOR) {
|
|
// A leading terminator still leaves a command to discover; later operands belong to callers.
|
|
if (path.length > 0) {
|
|
break;
|
|
}
|
|
literal = true;
|
|
continue;
|
|
}
|
|
const consumed = literal ? 0 : consumeRootCommandOptionToken(args, index);
|
|
if (consumed > 0) {
|
|
index += consumed - 1;
|
|
continue;
|
|
}
|
|
if (!literal && arg.startsWith("-")) {
|
|
continue;
|
|
}
|
|
path.push(arg);
|
|
if (path.length >= depth) {
|
|
break;
|
|
}
|
|
}
|
|
return path;
|
|
}
|
|
|
|
function consumeKnownOptionToken(args, index, booleanFlags, valueFlags, mode) {
|
|
const arg = args[index];
|
|
if (!arg || arg === FLAG_TERMINATOR || !arg.startsWith("-")) {
|
|
return 0;
|
|
}
|
|
|
|
const equalsIndex = arg.indexOf("=");
|
|
const flag = equalsIndex === -1 ? arg : arg.slice(0, equalsIndex);
|
|
if (booleanFlags.has(flag)) {
|
|
return equalsIndex === -1 ? 1 : 0;
|
|
}
|
|
if (!valueFlags.has(flag)) {
|
|
return 0;
|
|
}
|
|
if (equalsIndex !== -1) {
|
|
return mode === "command-path" || arg.slice(equalsIndex + 1).trim() ? 1 : 0;
|
|
}
|
|
// Required Commander values include empty strings, flag-looking tokens, and `--`.
|
|
// Discovery must consume them before choosing startup policy; routes still validate values.
|
|
if (mode === "command-path") {
|
|
return args[index + 1] !== undefined ? 2 : 0;
|
|
}
|
|
return isValueToken(args[index + 1]) ? 2 : 0;
|
|
}
|
|
|
|
/** Parse command positionals while consuming known root and command options. */
|
|
export function getCommandPositionalsWithRootOptions(argv, options) {
|
|
return parseCommandArgsWithRootOptions(argv, options, false);
|
|
}
|
|
|
|
/** Preserve the leaf's raw arguments after consuming its root and parent options. */
|
|
export function getCommandArgsWithRootOptions(argv, options) {
|
|
return parseCommandArgsWithRootOptions(argv, options, true);
|
|
}
|
|
|
|
/** Keep option roles intact when another command must use the same root selectors. */
|
|
export function getCommandOptionsWithRootOptions(argv, options) {
|
|
return parseCommandArgsWithRootOptions(argv, options, false, true);
|
|
}
|
|
|
|
function parseCommandArgsWithRootOptions(argv, options, returnTail, returnOptions = false) {
|
|
const args = argv.slice(2);
|
|
const booleanFlags = new Set(options.booleanFlags ?? []);
|
|
const valueFlags = new Set(options.valueFlags ?? []);
|
|
const positionals = [];
|
|
const rootOptions = [];
|
|
const commandOptions = [];
|
|
let commandIndex = 0;
|
|
let literal = false;
|
|
|
|
for (let index = 0; index < args.length; index += 1) {
|
|
const arg = args[index];
|
|
if (arg === undefined) {
|
|
break;
|
|
}
|
|
if (!literal && arg === FLAG_TERMINATOR) {
|
|
if (options.mode !== "command-path") {
|
|
break;
|
|
}
|
|
literal = true;
|
|
continue;
|
|
}
|
|
const rootConsumed = literal
|
|
? 0
|
|
: options.mode === "command-path"
|
|
? consumeRootCommandOptionToken(args, index)
|
|
: consumeRootOptionToken(args, index);
|
|
if (rootConsumed > 0) {
|
|
// Gateway's post-command --dev bootstraps its workspace, not a root profile.
|
|
const destination = commandIndex > 0 && booleanFlags.has(arg) ? commandOptions : rootOptions;
|
|
destination.push(...args.slice(index, index + rootConsumed));
|
|
index += rootConsumed - 1;
|
|
continue;
|
|
}
|
|
if (!literal && arg.startsWith("-")) {
|
|
const optionConsumed = consumeKnownOptionToken(
|
|
args,
|
|
index,
|
|
booleanFlags,
|
|
valueFlags,
|
|
options.mode,
|
|
);
|
|
if (optionConsumed === 0 || commandIndex === 0) {
|
|
return null;
|
|
}
|
|
commandOptions.push(arg);
|
|
index += optionConsumed - 1;
|
|
continue;
|
|
}
|
|
if (commandIndex < options.commandPath.length) {
|
|
if (arg !== options.commandPath[commandIndex]) {
|
|
return null;
|
|
}
|
|
commandIndex += 1;
|
|
if (returnTail && commandIndex === options.commandPath.length) {
|
|
const tail = args.slice(index + 1);
|
|
// A downstream parser must not reactivate flags after an earlier literal boundary.
|
|
return literal ? [FLAG_TERMINATOR, ...tail] : tail;
|
|
}
|
|
continue;
|
|
}
|
|
positionals.push(arg);
|
|
if (!returnOptions && positionals.length === options.maxPositionals) {
|
|
return positionals;
|
|
}
|
|
}
|
|
|
|
return commandIndex < options.commandPath.length
|
|
? null
|
|
: returnOptions
|
|
? { rootOptions, commandOptions }
|
|
: positionals;
|
|
}
|