Skip to content

refactor(cli): standardize operational scripts on a shared command runner - #352

Draft
s6pa1rta3n-lab wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
s6pa1rta3n-lab:fix-issue-237
Draft

refactor(cli): standardize operational scripts on a shared command runner#352
s6pa1rta3n-lab wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
s6pa1rta3n-lab:fix-issue-237

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown
Contributor

Summary

Resolves #237.

This PR introduces @sub-rosa/command, a shared CLI and operational script command runner package, and migrates all root check scripts and service operational scripts to standardize lifecycle handling, signal termination, structured diagnostic logging, and deterministic exit codes.

Key Changes

  • Core Package (@sub-rosa/command):
    • Implements runCommand() with automatic node:util.parseArgs argument parsing and --help generation.
    • Exposes standard error hierarchy: CommandError, UsageError, ConfigError, DependencyError, and InterruptedError.
    • Provides execution context (CommandContext) with parsed options, positionals, repository root discovery (repoRoot), environment variables, and AbortSignal for graceful shutdown.
    • Automatically captures SIGINT and SIGTERM to trigger abort controllers, with timed fallback termination.
    • Formats output using @sub-rosa/logging and handles JSON error serialization when configured.
    • Full dual ESM/CJS compatibility and comprehensive TypeScript declarations (.d.ts).
    • Unit test suite in packages/command/test/runner.test.ts covering error classes, signal aborts, custom options, help text, and exit codes (11/11 pass).
  • Service & Package Script Standardization:
    • services/receipt-cli: Migrated all subcommands (verify, audit, export) to runCommand, eliminated raw process.exit invocations.
    • services/keeper: Migrated run.ts, watch.ts, serve.ts, queue.ts, and end-to-end scripts (keeper-e2e.ts, lifecycle-e2e.ts, mainnet-settle.ts, usdc-setup.ts).
    • packages/sdk: Migrated live-smoke.ts, mainnet-ready.ts, mainnet-verify.ts, and mainnet-micro.ts.
    • packages/tlock: Migrated recover-identities.cli.ts.
    • services/appraisal-api: Migrated usdc-setup.ts and x402-e2e.ts.
    • services/agent: Migrated usdc-setup.ts and agents-e2e.ts.
    • services/auction-template: Migrated sealed-auction.ts.
  • Root Check Scripts Migration:
    • Standardized all 8 root check scripts (check-links.js, check-deploy-docs.mjs, check-snapshots.mjs, check-threat-model-anchors.mjs, check-fixture-sizes.mjs, check-round-errors.mjs, check-direct-time-access.mjs, run-ts-coverage.mjs) on runCommand.
    • Migrated scripts/check-logging.mjs to runCommand.
  • Drift Guard & CI Integrity:
    • Implemented scripts/check-command-runner.mjs and scripts/check-command-runner.test.mjs.
    • Scans all 29 operational and check script targets to enforce @sub-rosa/command usage and prevent raw process.exit calls.
    • Added command:test, command:typecheck, command-runner:check, and command-runner:test to package.json.

Verification

  • pnpm command:typecheck passes with zero errors.
  • pnpm command:test passes all 11 test cases.
  • pnpm command-runner:check passes across all 29 target scripts.
  • pnpm command-runner:test passes all unit tests.
  • pnpm logging:check and pnpm logging:test pass.
  • pnpm receipt:typecheck and pnpm receipt:test pass (19/19 tests).
  • pnpm keeper:typecheck and pnpm keeper:test pass (73/73 tests).
  • pnpm --filter @sub-rosa/appraisal-api typecheck and test pass (49/49 tests).
  • pnpm --filter @sub-rosa/agent typecheck and test pass (21/21 tests).
  • pnpm --filter @sub-rosa/tlock typecheck and test pass (58/58 tests).
  • node scripts/run-ts-coverage.mjs passes weighted coverage gate at 78.78% (threshold: 70.00%).

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

…nner

- Create @sub-rosa/command package providing runCommand, context helpers, standard exit codes, signal handling, and structured diagnostics
- Migrate all root check scripts and operational service scripts to runCommand
- Eliminate raw process.exit calls in operational scripts, delegating process termination to the runner
- Add scripts/check-command-runner.mjs and test to guard against command runner drift
- Register command:test, command:typecheck, command-runner:check, and command-runner:test in root package.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(cli): standardize operational scripts on a shared command runner

1 participant