Skip to content

fix(cli): replace hardcoded "--" with FLAG_TERMINATOR constant in getCommandPathInternal - #89897

Closed
whiteyzy wants to merge 8 commits into
openclaw:mainfrom
whiteyzy:fix/argv-flag-terminator-hardcoded-83902
Closed

whiteyzy wants to merge 8 commits into
openclaw:mainfrom
whiteyzy:fix/argv-flag-terminator-hardcoded-83902

Conversation

@whiteyzy

@whiteyzy whiteyzy commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replace the sole remaining hardcoded "--" literal in getCommandPathInternal with the FLAG_TERMINATOR constant already imported and used by every other function in argv.ts.

Prevents silent subcommand-routing divergence if FLAG_TERMINATOR is ever changed.

Addressed review feedback (ClawSweeper P3): Reworded the regression test comment to accurately describe what it proves (integration with the constant), since the test cannot independently detect a literal regression while FLAG_TERMINATOR remains "--". The companion contract test asserts the canonical value.

Linked context

Closes #83902

Real behavior proof (required for external PRs)

  • Behavior addressed: getCommandPathInternal used a hardcoded "--" string while all other functions in the same file use the FLAG_TERMINATOR constant.
  • Real environment tested: macOS, Node v22.22.3, latest upstream/main (050c081)
  • Exact steps or command run after this patch:
npx tsx proof-89897.mjs
  • Evidence after fix (copied live output):
=== Live Proof: #89897 / #83902 ===
FLAG_TERMINATOR constant: "--"

Case 1: getCommandPath([node, openclaw, channels, --, add], 2)
  Result: [channels]
  PASS: true

Case 2: getCommandPath([node, openclaw, channels, add], 2)
  Result: [channels, add]
  PASS: true

Case 3: getCommandPath([node, openclaw, config, --, set, --key, value], 2)
  Result: [config]
  PASS: true

Case 4: getCommandPathWithRootOptions([node, openclaw, --debug, status, --, extra], 2)
  Result: [status]
  PASS: true

Case 5: FLAG_TERMINATOR === "--"
  PASS: true

=== Live Proof #89897: ALL PASSED ===
  • Observed result after fix: FLAG_TERMINATOR correctly stops command-path parsing. Command-path resolution is consistent with all other argv helpers.
  • What was not tested: N/A — single-line refactor with focused regression tests and live CLI behavior proof.

Tests and validation

Which commands did you run?

node scripts/run-vitest.mjs run src/cli/argv.test.ts --reporter=verbose
# 112 passed (1 test file)

What regression coverage was added or updated?

  • "uses FLAG_TERMINATOR constant to stop command-path parsing" — exercises integration with the imported constant
  • "FLAG_TERMINATOR is the canonical -- string" — contract test asserting the canonical value

Risk checklist

Did user-visible behavior change? No
Did config, environment, or migration behavior change? No
Did security, auth, secrets, network, or tool execution behavior change? No
What is the highest-risk area? None — identical runtime behavior (same constant value "--").
How is that risk mitigated? 112 argv tests pass; the contract test explicitly asserts the canonical value.

Current review state

What is the next action? Requesting ClawSweeper re-review.
What is still waiting on author, maintainer, CI, or external proof? None — live CLI behavior proof added.


🤖 Generated with Claude Code
Co-Authored-By: Claude Code [email protected]

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 3, 2026
@clawsweeper

clawsweeper Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 6, 2026, 6:16 AM ET / 10:16 UTC.

Summary
This PR replaces the hardcoded flag terminator comparison in src/cli/argv.ts with FLAG_TERMINATOR and adds focused argv tests for that invariant.

PR surface: Source 0, Tests +14. Total +14 across 2 files.

Reproducibility: yes. Source inspection shows current main and v2026.6.11 still use arg === "--" in getCommandPathInternal while sibling helpers stop on FLAG_TERMINATOR; I did not mutate the constant in this read-only review.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #83902
Summary: This PR is the only currently open candidate fix for the canonical getCommandPathInternal terminator-constant mismatch issue; earlier duplicate fix attempts are closed unmerged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Refresh or rerun required checks after the unrelated packages/gateway-protocol unused-export failures are resolved.

Risk before merge

  • [P1] Required exact-head checks are not green, but the visible prod-types and lint failures are in packages/gateway-protocol/src/index.ts, outside this PR's touched CLI files; the branch still needs green required checks or a base refresh before merge.

Maintainer options:

  1. Decide the mitigation before merge
    Land this proof-backed narrow CLI parser fix once required checks are green, then close the linked canonical issue while keeping the already-closed duplicate attempts closed.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No ClawSweeper repair is needed because this branch already applies the narrow fix; maintainer merge handling should wait for required checks to clear.

Security
Cleared: The diff touches only local CLI argv parsing and a unit test, with no dependency, workflow, package, permission, secret, download, or supply-chain surface.

Review details

Best possible solution:

Land this proof-backed narrow CLI parser fix once required checks are green, then close the linked canonical issue while keeping the already-closed duplicate attempts closed.

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

Yes. Source inspection shows current main and v2026.6.11 still use arg === "--" in getCommandPathInternal while sibling helpers stop on FLAG_TERMINATOR; I did not mutate the constant in this read-only review.

Is this the best way to solve the issue?

Yes for the production fix. Replacing the outlier literal with the existing shared constant is the narrowest maintainable fix; the added source-shape test is a little brittle but acceptable for this source-level invariant and does not create a blocking defect.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 738654d20c7e.

Label changes

Label justifications:

  • P3: This is a low-risk CLI consistency fix with limited blast radius and no current user-visible divergence while the shared terminator value remains --.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied after-fix live output from a real macOS/Node setup exercising the command-path helper paths and showing the expected terminator behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied after-fix live output from a real macOS/Node setup exercising the command-path helper paths and showing the expected terminator behavior.
Evidence reviewed

PR surface:

Source 0, Tests +14. Total +14 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 1 15 1 +14
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 16 2 +14

What I checked:

  • Current main still has the mismatch: Current main imports FLAG_TERMINATOR and sibling argv helpers stop on it, but getCommandPathInternal still checks arg === "--", so the central problem is not implemented on main. (src/cli/argv.ts:461, 738654d20c7e)
  • PR head applies the production fix: The PR head changes the outlier comparison in getCommandPathInternal to arg === FLAG_TERMINATOR. (src/cli/argv.ts:461, 42eaa5ed2983)
  • PR head adds focused coverage: The PR test uses FLAG_TERMINATOR in the command-path table and adds a focused source-shape plus behavior assertion for the shared terminator contract. (src/cli/argv.test.ts:440, 42eaa5ed2983)
  • Caller path checked: resolveCliArgvInvocation, command-path policy resolution, and parse-error formatting all call through getCommandPathWithRootOptions, so this helper feeds pre-dispatch CLI routing and user-facing CLI hints. (src/cli/argv-invocation.ts:21, 738654d20c7e)
  • Latest release still has the old literal: Release v2026.6.11 still contains arg === "--" in getCommandPathInternal, so the fix is not shipped in the latest release either. (src/cli/argv.ts:461, e085fa1a3ffd)
  • Live related-item search: Live GitHub search now shows this PR as the only open PR mentioning the linked issue; prior duplicate attempts for the same source-level mismatch are closed unmerged.

Likely related people:

  • gumadeiras: The routed CLI startup work in enhancement: 3x faster CLI invocation, unify boolean/env parsing, streamline CLI startup paths #1195 was authored by gumadeiras, and later history shows the shared FLAG_TERMINATOR root-option helper was extracted in the same CLI area. (role: feature author and adjacent CLI root-option contributor; confidence: high; commits: d5c817219747, f26853f14c9b; files: src/cli/argv.ts, src/cli/argv.test.ts, src/infra/cli-root-options.ts)
  • steipete: Live PR metadata for enhancement: 3x faster CLI invocation, unify boolean/env parsing, streamline CLI startup paths #1195 shows steipete merged the routed CLI helper work, and the squash commit introducing the helper is authored by Peter Steinberger. (role: merger and commit author for routed CLI path; confidence: high; commits: d5c817219747; files: src/cli/argv.ts, src/cli/argv.test.ts)
  • zhangLei99586: Current blame for the relevant src/cli/argv.ts region points at a recent broad current-main commit authored by zhangLei99586, which carried this helper forward but did not specifically introduce the terminator mismatch. (role: recent area contributor; confidence: low; commits: 9f8bc7fa374f; files: src/cli/argv.ts, src/cli/argv.test.ts)
  • vincentkoc: Live metadata shows vincentkoc merged the recent broad commit that current blame points to for the file, making this a possible routing contact for current-main file ownership rather than root-cause authorship. (role: recent merger; confidence: low; commits: 9f8bc7fa374f; files: src/cli/argv.ts, src/cli/argv.test.ts)
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.

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.
Review history (1 earlier review cycle)
  • reviewed 2026-06-22T02:41:49.363Z sha 41ef0684e80a218c268e6adc3ec65fe01e9949ed :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jun 3, 2026
@whiteyzy
whiteyzy force-pushed the fix/argv-flag-terminator-hardcoded-83902 branch from 36a5287 to 1000e2a Compare June 10, 2026 12:15
@whiteyzy

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated:

  • Reworded regression test comment per P3 review feedback (test now accurately describes what it proves)
  • Added live CLI proof script (proof-89897.mjs) demonstrating FLAG_TERMINATOR integration across 5 cases
  • Rebased on latest upstream/main
  • All 112 tests pass

@clawsweeper

clawsweeper Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 10, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 10, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: XS and removed size: S proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Jun 10, 2026
@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 10, 2026
@whiteyzy
whiteyzy force-pushed the fix/argv-flag-terminator-hardcoded-83902 branch from 0d8db51 to c0371eb Compare June 10, 2026 14:09
@whiteyzy

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated (per P3 review feedback):

  • Removed the fixed-value contract test ("FLAG_TERMINATOR is the canonical -- string")
  • The behavioral test ("uses FLAG_TERMINATOR constant to stop command-path parsing") remains
  • 111/111 tests pass
  • Rebased on latest upstream/main

@clawsweeper

clawsweeper Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 10, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 10, 2026
@whiteyzy
whiteyzy force-pushed the fix/argv-flag-terminator-hardcoded-83902 branch from c0371eb to b0f2e31 Compare June 10, 2026 15:09
@vincentkoc
vincentkoc force-pushed the fix/argv-flag-terminator-hardcoded-83902 branch 4 times, most recently from b3b8aff to 41ef068 Compare June 22, 2026 02:27
@vincentkoc
vincentkoc force-pushed the fix/argv-flag-terminator-hardcoded-83902 branch from 41ef068 to afab0f2 Compare July 6, 2026 09:32
secooond and others added 8 commits July 6, 2026 09:36
…CommandPathInternal

Every other function in argv.ts uses the imported FLAG_TERMINATOR
constant for the terminator check. getCommandPathInternal was the
sole outlier, using a hardcoded '--' literal. If FLAG_TERMINATOR
is ever changed, command-path resolution would silently diverge
from help/version detection, breaking subcommand routing.

Closes openclaw#83902
…CommandPathInternal

Every other function in argv.ts uses the imported FLAG_TERMINATOR
constant for the terminator check. getCommandPathInternal was the
sole outlier, using a hardcoded '--' literal. If FLAG_TERMINATOR
is ever changed, command-path resolution would silently diverge
from help/version detection, breaking subcommand routing.

Add two regression tests:
- getCommandPath respects the FLAG_TERMINATOR constant (not a literal)
- FLAG_TERMINATOR contract test asserts the canonical '--' value

Closes openclaw#83902
The test exercises FLAG_TERMINATOR integration but cannot independently
detect a literal regression because FLAG_TERMINATOR is currently '--'.
Reword the comment to be accurate about what the test proves; the
companion contract test asserts the canonical value.

Refs: openclaw#83902
The proof evidence is already recorded in the PR body. Keeping the
script in the repository root would add unsupported ad-hoc scaffolding.

Refs: openclaw#83902
Remove the test that asserts FLAG_TERMINATOR === '--'.  This test
couples the argv parser to the constant's current value and would
break on any intentional change to the centralized constant even
when all parsers correctly follow the new value.  Existing behavior
coverage already verifies command-path parsing stops at the
terminator.

Refs: openclaw#83902
@vincentkoc
vincentkoc force-pushed the fix/argv-flag-terminator-hardcoded-83902 branch from 4592de9 to 42eaa5e Compare July 6, 2026 09:36
@vincentkoc vincentkoc self-assigned this Jul 6, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Thanks for the careful cleanup and proof. I reviewed this against current main: FLAG_TERMINATOR is still the fixed "--" token, so the production change is behavior-neutral and only protects a hypothetical future contract change. The added source-shape/test maintenance costs more than this invariant is worth carrying. Closing this rather than spending another exact-head CI/rebase cycle on a mechanical one-line refactor.

@vincentkoc vincentkoc closed this Jul 6, 2026
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

2 participants