Skip to content

fix(cli): use FLAG_TERMINATOR constant in getCommandPathInternal (#83902) - #84066

Closed
hclsys wants to merge 1 commit into
openclaw:mainfrom
hclsys:fix-getCommandPath-flag-terminator-const-83902
Closed

hclsys wants to merge 1 commit into
openclaw:mainfrom
hclsys:fix-getCommandPath-flag-terminator-const-83902

Conversation

@hclsys

@hclsys hclsys commented May 19, 2026

Copy link
Copy Markdown

Fixes #83902.

getCommandPathInternal (src/cli/argv.ts:225) was the sole helper in argv.ts comparing arg === "--" against the string literal instead of the imported FLAG_TERMINATOR constant from infra/cli-root-options.ts. Every other helper in the same file (isHelpOrVersionInvocation, hasFlag, hasRootVersionAlias, isRootInvocationForFlags, getFlagValue, getCommandPositionals, etc.) routes its terminator check through FLAG_TERMINATOR. Under the current value ("--") the two paths agree, but any future change to the constant would silently desync command-path resolution from help/version detection — subcommand routing would break in a way that's hard to trace.

Changes

  • src/cli/argv.ts: replace if (arg === "--") in getCommandPathInternal with if (arg === FLAG_TERMINATOR) (single-line fix as the issue recommended). Add a short comment explaining the consistency requirement.
  • src/cli/argv.test.ts: regression test that pulls the live FLAG_TERMINATOR constant from infra/cli-root-options.ts and asserts both getCommandPath and getCommandPathWithRootOptions stop at it. The test will fail if the constant changes without a corresponding update here.

Diff stat: 2 files, +24 / -1.

Real behavior proof

  • Behavior or issue addressed: Sanitized issue evidence — argv.ts:4 imports FLAG_TERMINATOR and uses it in every helper except getCommandPathInternal at line 225, which compares against the string literal "--". The issue's reasoning section notes that any future redefinition of FLAG_TERMINATOR would silently break command-path resolution while help/version detection continues to track the new value.

  • Real environment tested: Local Node 22.x. Probe at /tmp/probe_83902.mjs (a) parses the patched argv.ts and verifies the comparison now uses FLAG_TERMINATOR, no remaining arg === "--" string-literal in getCommandPathInternal, and that === FLAG_TERMINATOR is used 8 times across the file (parser-wide consistency), and (b) replays both the patched and pre-fix shapes against the current "--" terminator (both produce ["status"] — no observable difference under the default config) and a hypothetical "++" terminator (patched correctly stops at "++" and returns ["status"]; buggy ignores the redefined constant and returns ["status", "++"]).

  • Exact steps or command run after this patch: node /tmp/probe_83902.mjs

  • Evidence after fix:

PASS: comparison uses the imported FLAG_TERMINATOR constant
PASS: no remaining `arg === "--"` string-literal comparison
PASS: FLAG_TERMINATOR comparison used 8 times across argv.ts (parser-wide consistency)
PASS: replay (current terminator): patched stops at '--' → ['status']
PASS: replay (current terminator): buggy also stops at '--' → ['status'] — no observable difference under default config
PASS: replay (hypothetical FLAG_TERMINATOR=++): patched correctly stops at '++' → ['status']
PASS: replay (hypothetical FLAG_TERMINATOR=++): buggy ignores the new terminator and treats it as a positional → diverges from patched ['status']

ALL CASES PASS
  • Observed result after fix: Under the current FLAG_TERMINATOR = "--" value, behavior is unchanged (the existing "terminator cuts parsing" test still passes). Under any hypothetical change to the constant, getCommandPath / getCommandPathWithRootOptions track the new value in lock-step with the rest of the parser instead of silently using the old literal.

  • What was not tested: A live build that physically changes FLAG_TERMINATOR to a non-"--" value — the regression test pins the assertion against the imported constant via await import("../infra/cli-root-options.js") so the relationship is enforced at test time, and the source-level probe verifies the comparison shape.

Audit (per CLAUDE rules — all 5 steps)

  • Existing-helper check: Reuses the already-imported FLAG_TERMINATOR constant. No new helper or import. PASS
  • Shared-helper caller check: FLAG_TERMINATOR has 8 usage sites across argv.ts after this patch (was 7); the new one is the same comparison shape as all the others. getCommandPath and getCommandPathWithRootOptions are exported and called by command-path.ts and other CLI plumbing — the behavior change is invisible under the current "--" value and matches the existing usage convention across the parser. PASS
  • Broader-fix rival scan: gh pr list --search '83902 in:title,body' and gh pr list --search 'FLAG_TERMINATOR in:title,body' return no open PRs. PASS
  • Recent-merge audit: git log --oneline -5 -- src/cli/argv.ts shows e1061a8b46 test(live): tolerate provider drift in release checks — unrelated. PASS
  • Prototype-pollution scan: N/A — string comparison.

…nclaw#83902)

`getCommandPathInternal` compared `arg === "--"` directly, while every
other helper in `argv.ts` (`isHelpOrVersionInvocation`, `hasFlag`,
`hasRootVersionAlias`, `isRootInvocationForFlags`, `getFlagValue`,
`getCommandPositionals`, etc.) routes its terminator check through the
imported `FLAG_TERMINATOR` constant from `infra/cli-root-options.ts`.
Under the current value (`"--"`) the two paths agree, but any future
change to the constant would silently desync command-path resolution
from help/version detection — subcommand routing would break in a way
that's hard to trace because the rest of the parser would still pick up
the new terminator.

Replace the hardcoded literal with `FLAG_TERMINATOR` and pin a regression
test that pulls the live constant through the same module-resolution
path the production code uses.

Closes openclaw#83902.
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels May 19, 2026
@clawsweeper

clawsweeper Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Workflow note: Future ClawSweeper reviews update this same comment in place.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Summary
The PR replaces a hardcoded -- check in src/cli/argv.ts with FLAG_TERMINATOR and adds a focused argv test for command-path terminator handling.

Reproducibility: yes. at source level: current main still imports FLAG_TERMINATOR but getCommandPathInternal checks the literal -- while neighboring argv helpers use the constant. I did not run the PR branch test in this read-only sweep.

PR rating
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Summary: The patch is small and correct with useful copied runtime output, while final confidence still depends on CI or a targeted test run.

Rank-up moves:

  • Run the targeted argv test or rely on CI before merge, because this read-only review did not execute the PR branch.
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

PR egg
✨ Hatched: 🥚 common Cosmic Review Wisp

        .--^^^^--.           
     .-'  o    o  '-.        
    /       \__/      \      
   |    /\  ____  /\   |     
   |   /  \/____\/  \  |     
    \  \_.------._/  /       
     '._  `----'  _.'        
        '-.____.-'           
       _/|_|  |_|\_          
      /__|      |__\         
       .-----------.         
      '-------------'        

Rarity: 🥚 common.
Trait: finds missing screenshots.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Cosmic Review Wisp in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • How to hatch it: reach status: 👀 ready for maintainer look or status: 🚀 automerge armed; that usually means sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

Real behavior proof
Sufficient (live_output): The PR body includes copied after-patch Node probe output that checks the source shape and replayed parser behavior for current and hypothetical terminators.

Risk before merge
Why this matters: - This read-only review did not execute the PR branch test; merge confidence should still come from CI or a targeted argv test run before landing.

Maintainer options:

  1. Decide the mitigation before merge
    Land the small code/test fix after normal CI if maintainers accept keeping FLAG_TERMINATOR as the single argv terminator source of truth.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge
No fix lane is needed; the PR already contains the narrow code/test change, so the remaining action is normal maintainer review and CI.

Security
Cleared: The diff only changes a CLI parser comparison and a colocated unit test, with no dependency, workflow, secret, install, or supply-chain surface touched.

Review details

Best possible solution:

Land the small code/test fix after normal CI if maintainers accept keeping FLAG_TERMINATOR as the single argv terminator source of truth.

Do we have a high-confidence way to reproduce the issue?

Yes at source level: current main still imports FLAG_TERMINATOR but getCommandPathInternal checks the literal -- while neighboring argv helpers use the constant. I did not run the PR branch test in this read-only sweep.

Is this the best way to solve the issue?

Yes: replacing the literal with the existing imported constant is the narrowest maintainable fix. The added test is useful guard coverage, with CI still needed for execution proof.

Label justifications:

  • P3: This is a low-risk CLI parser consistency fix with no behavior change under the current shipped -- terminator.

What I checked:

  • Current main still has the inconsistency: getCommandPathInternal imports FLAG_TERMINATOR through the file header but still checks arg === "--" directly at the command-path terminator branch. (src/cli/argv.ts:225, aef93881af5f)
  • Central terminator contract exists: FLAG_TERMINATOR is exported as the shared CLI sentinel, and other argv helpers in the same file use that constant for terminator checks. (src/infra/cli-root-options.ts:1, aef93881af5f)
  • PR patch matches the intended boundary: The provided PR diff changes the command-path comparison to FLAG_TERMINATOR and adds a colocated argv test; it does not touch package, dependency, workflow, or runtime ownership surfaces. (src/cli/argv.ts:225, 5ac45e774d9b)
  • Existing tests already cover current default behavior: Current main has a terminator cuts parsing test for getCommandPath with the shipped -- sentinel, so the PR is primarily enforcing consistency with the imported constant rather than changing default behavior. (src/cli/argv.test.ts:223, aef93881af5f)
  • Feature-history provenance: git blame attributes the current getCommandPathInternal block to commit 1c3ff34d..., while git show d5c817... shows the earlier routed CLI helper also carried a local terminator constant plus a hardcoded -- in getCommandPath. (src/cli/argv.ts:213, 1c3ff34d752f)
  • Contributor proof supplied: The PR body includes copied Node 22 probe output showing the patched source uses FLAG_TERMINATOR, no longer has the literal in getCommandPathInternal, and diverges from the buggy shape when replayed with a hypothetical non--- sentinel. (5ac45e774d9b)

Likely related people:

  • @steipete: git blame points the current getCommandPathInternal block to 1c3ff34d..., and earlier routed CLI path work in d5c817... also touched this helper family. (role: introduced current helper implementation and recent area contributor; confidence: high; commits: 1c3ff34d752f, d5c817219747; files: src/cli/argv.ts, src/cli/argv.test.ts, src/infra/cli-root-options.ts)
  • @gumadeiras: Commit 15a0455... authored the routed config positional parsing work in the same argv helper/test surface, and d5c817... credits related routed CLI path optimization context. (role: adjacent CLI argv contributor; confidence: medium; commits: 15a0455d040f, d5c817219747; files: src/cli/argv.ts, src/cli/argv.test.ts)
  • @vincentkoc: Commit 38da2d... added root help fast-path and argv tests in the same helper family that the PR keeps aligned with command-path parsing. (role: adjacent root help/version argv contributor; confidence: medium; commits: 38da2d076c8a; files: src/cli/argv.ts, src/cli/argv.test.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against aef93881af5f.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels May 19, 2026
@hclsys

This comment was marked as low quality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getCommandPathInternal uses hardcoded "--" instead of FLAG_TERMINATOR constant

1 participant