← Back to PRs

#17770: refactor(cli): reuse shared option builders

by iyoda open 2026-02-16 05:21 View on GitHub →
channel: slack channel: telegram cli size: XL
## Summary Describe the problem and fix in 2–5 bullets: - Problem: Repeated CLI option definitions (`--json`, `--timeout`, `--verbose`, `--debug`) across many commands. - Why it matters: Duplicated option definitions are easy to drift and harder to update consistently. - What changed: Added shared option builders and applied them across CLI command registrations. - What did NOT change (scope boundary): No CLI behavior, defaults, or option names changed. ## Change Type (select all) - [ ] Bug fix - [ ] Feature - [x] Refactor - [ ] Docs - [ ] Security hardening - [ ] Chore/infra ## Scope (select all touched areas) - [ ] Gateway / orchestration - [ ] Skills / tool execution - [ ] Auth / tokens - [ ] Memory / storage - [ ] Integrations - [ ] API / contracts - [x] UI / DX - [ ] CI/CD / infra ## Linked Issue/PR - Closes # - Related # ## User-visible / Behavior Changes None. ## Security Impact (required) - New permissions/capabilities? (No) - Secrets/tokens handling changed? (No) - New/changed network calls? (No) - Command/tool execution surface changed? (No) - Data access scope changed? (No) - If any `Yes`, explain risk + mitigation: ## Repro + Verification ### Environment - OS: macOS (darwin) - Runtime/container: Node 24.13.1, pnpm 10.23.0 - Model/provider: N/A - Integration/channel (if any): N/A - Relevant config (redacted): N/A ### Steps 1. corepack pnpm tsgo 2. corepack pnpm build 3. corepack pnpm test src/cli ### Expected - All commands succeed. ### Actual - All commands succeeded. ## Evidence Attach at least one: - [x] Failing test/log before + passing after - [ ] Trace/log snippets - [ ] Screenshot/recording - [ ] Perf numbers (if relevant) ## Human Verification (required) What you personally verified (not just CI), and how: - Verified scenarios: tsgo/build/cli test suite passes - Edge cases checked: None (refactor-only) - What you did **not** verify: Manual CLI invocation ## Compatibility / Migration - Backward compatible? (Yes) - Config/env changes? (No) - Migration needed? (No) - If yes, exact upgrade steps: ## Failure Recovery (if this breaks) - How to disable/revert this change quickly: Revert the PR commits. - Files/config to restore: CLI command registration files in src/cli/. - Known bad symptoms reviewers should watch for: CLI option flags missing or mis-described. ## Risks and Mitigations None. <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR has two distinct refactoring efforts: 1. **CLI option builders**: Introduces shared helper functions (`addJsonOption`, `addTimeoutOption`, `addVerboseOption`, `addDebugOption`) in `src/cli/option-builders.ts` and applies them across 14 CLI command registration files. All option descriptions, default values, and flag names are preserved correctly. 2. **Allowlist candidate matcher**: Extracts the duplicated candidate-matching loop (previously in Slack's `allow-list.ts`) into a generic `resolveAllowlistMatchCandidates` function in `src/channels/allowlist-match.ts`, then reuses it in Slack, Telegram, and Line bot-access modules. - The CLI changes are purely structural — no behavior, defaults, or option names changed. - The allowlist refactoring is behavior-preserving; each channel's matching logic produces equivalent results through the shared function. - Minor issue: `src/line/bot-access.ts` has an import statement placed at the end of the file instead of at the top. <h3>Confidence Score: 4/5</h3> - This PR is safe to merge — it's a clean refactor with no behavior changes, aside from a minor import ordering issue in one file. - Score of 4 reflects that all CLI option refactoring is straightforward and behavior-preserving, and the allowlist candidate matcher correctly generalizes existing logic. Deducted one point only for the misplaced import in `src/line/bot-access.ts`, which is cosmetic but should be fixed. - `src/line/bot-access.ts` has an import at the bottom of the file that should be moved to the top. <sub>Last reviewed commit: 2ddc2bb</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs