fix(cli): only run init when it is the first operand, not when an option value reads "init" - #9
Open
eastagiletracker wants to merge 1 commit into
Conversation
The pre-connect dispatch scanned all of process.argv for the token "init", so any option value spelled that way was mistaken for the subcommand: `bitrefill help init` and `bitrefill search-products --query init` both ran the init flow, which rewrites ~/.openclaw/openclaw.json and clears the saved session via clearOAuthStore(). Resolve the subcommand as the first non-option operand instead, in a new src/argv.ts so it can be unit tested without importing the entry point.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR proposes a fix so that
bitrefillonly runs theinitflow wheninitis the first operand, instead of whenever any argument happens to readinit. We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/496. You can sign in with your GitHub ID to claim ownership of the project.What is wrong
The pre-connect dispatch in
src/index.tsdecides whether the invocation isinitby scanning the whole ofprocess.argv:Any token that reads
initmatches, including an option value. Two ordinary invocations therefore run setup instead of the command that was typed, and sincehandleInit()finishes withclearOAuthStore(), both of them delete~/.config/bitrefill-cli/<host>.v1.json— the signed-in session is gone, and~/.openclaw/openclaw.jsonis rewritten on the way:bitrefill help init— thehelp [command]form thatbitrefill --helpitself advertisesbitrefill search-products --query init— a catalog search whose query happens to be that wordReproducing it on
master(635c341)Both paths short-circuit before the MCP connection, so this needs no network and no account — only a scratch
HOMEso your real state is untouched:Observed at
635c341:npx tsx src/index.ts search-products --query initprints the same banner, performs no search, and deletes the session file the same way.The change
detectInitInvocationnow resolves the subcommand the way commander does — the first token that is not an option — so an option value can never be mistaken for it. The helper moves into a newsrc/argv.tsbecausesrc/index.tsexecutesmain()on import and so cannot be pulled into a test; that matches howtools.ts,output.tsandmanifest.tsalready keep testable logic beside a colocated*.test.ts. Nothing aboutinititself changes:init,init --openclaw,--json initandinit --helpall take exactly the path they took before, andhelp initnow falls through to commander, which prints the help for that command.Verifying it
src/argv.test.tscovers both directions, and its two regression cases fail against the previous scan and pass with this change:Full checks before and after, on the same machine:
pnpm test38 passed → 45 passed,pnpm buildclean,pnpm formatreportsAll matched files use Prettier code style!. Nothing was failing before this change and nothing fails after it.End to end against a local MCP server standing in for
api.bitrefill.com/mcp, with a session file seeded as above:help initprints the help forinitand leaves the session in place,search-products --query initreturns the search result for the queryinit, andinit,--json initandinit --helpbehave exactly as they do onmaster.How this was managed
We tracked this work on a board built from your own issues and pull requests — 8 stories and 2 labels imported from
bitrefill/cli. The story behind this PR is bitrefill help init runs the init flow instead of showing help, on the board at https://eastagiletracker.com/projects/496.If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com