feat(mcp): suggest the closest command on an unknown command - #1868
Conversation
When a command is mistyped, the CLI now offers a "did you mean" hint: `Unknown command: staus. Did you mean ` + "`status`" + `? Run ...`. The suggestion is the nearest known command by Levenshtein distance, within a small budget that scales with input length, so unrelated input gets no misleading suggestion (the base "Run --help" guidance is unchanged). Tests cover near-miss typos resolving to status/version/config/doctor, and the existing unrelated-input case still gets only the --help guidance.
|
Tip 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 ✅ Gittensory review result - approve/merge recommendedReview updated: 2026-06-30 19:06:47 UTC
✅ Suggested Action - Approve/Merge
Review summary Nits — 3 non-blocking
Review context
Contributor next steps
Signal definitions
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
Summary
When a command is mistyped, the CLI now offers a "did you mean" hint — the ergonomic that
git,npm, andcargoall have:The suggestion is the nearest known top-level command by Levenshtein distance, within a small edit-distance budget that scales with input length (
max(2, floor(len/3))), so unrelated input gets no misleading suggestion and the baseRun --helpguidance is unchanged.Behavior / compatibility
Unknown command: … Run --helpmessage is preserved; theDid you mean …?clause is only inserted when a close match exists.bogus-command) gets only the--helpguidance, exactly as before.Scope
packages/gittensory-mcp/bin/gittensory-mcp.js—suggestCommand()+ a smalllevenshteinDistance()helper (driven by the existingCLI_COMMAND_SPEC), wired into the unknown-command throw.test/unit/mcp-cli-basics.test.ts— near-miss typos resolving tostatus/version/config/doctor, plus the unchanged unrelated-input case.Packages-only; no
src/**, UI, schema, migration, or OpenAPI changes. No README change — this refines an error message, not a command surface.Validation
Run locally on Node v24.18.0 (engine floor is 22):
npm run build:mcp→ passnpm run typecheck→ pass, 0 errors (full project)npx vitest run test/unit/mcp-cli-basics.test.ts→ 20/20 pass, including the newsuggests the closest command for a near-miss typoand the unchangedguides unknown commands to --helpnpm pack --workspace @jsonbored/gittensory-mcp --dry-run→ package file list unchanged (allowed set; no new files, no secrets)staus→status,verison→version,confi→config,doctr→doctor;bogus-command→ no suggestionNote:
npm run test:mcp-packcan't run on my Windows box (its harnessspawnSync("npm", …)can't resolvenpm.cmdwithout a shell) — verified package contents withnpm pack --dry-runinstead. It passes on CI.Safety
No auth, cookie, CORS, GitHub App output, identity, contributor-evidence, or scoring changes. No secrets/wallets/hotkeys/trust/reward terms. The suggestion is drawn only from the static known-command list.
Why no issue
This is an intentional no-issue PR: a small, self-contained CLI error-message refinement (a "did you mean" hint on an unknown command) with no public-behavior, auth, schema, deploy, or API-contract change. Per CONTRIBUTING this class of change does not require a tracking issue; happy to file one if maintainers prefer.