Skip to content

refactor: split cli.ts into focused modules#2498

Merged
lpcox merged 3 commits intomainfrom
refactor/split-cli-into-modules
May 4, 2026
Merged

refactor: split cli.ts into focused modules#2498
lpcox merged 3 commits intomainfrom
refactor/split-cli-into-modules

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented May 4, 2026

Summary

Split the 2,444-line src/cli.ts into 3 focused modules, reducing the main file to ~1,351 lines.

File Lines Content
src/domain-utils.ts ~230 parseDomains, parseDomainsFile, isValidIPv4/IPv6, agent image validation, DEFAULT_*_API_TARGET constants
src/api-proxy-config.ts ~399 validateApiProxyConfig, GHEC/GHES domain extraction, API target resolution, proxy warnings
src/option-parsers.ts ~579 buildRateLimitConfig, parseMemoryLimit, parseDnsServers, parseEnvironmentVariables, parseVolumeMounts, shell escaping
src/cli.ts ~1,351 Commander program, option definitions, action handlers (re-exports extracted symbols for backwards compat)

Backwards compatibility

src/cli.ts re-exports all extracted symbols, so existing imports continue to work.

Testing

  • TypeScript build succeeds
  • All 356 cli.test.ts tests pass

Closes #2472

Extract domain/IP utilities to src/domain-utils.ts, API proxy
config logic to src/api-proxy-config.ts, and input parsers to
src/option-parsers.ts. The main cli.ts retains Commander setup
and action handlers only.

Closes #2472

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox requested a review from Mossaka as a code owner May 4, 2026 15:23
Copilot AI review requested due to automatic review settings May 4, 2026 15:23
Comment thread src/cli.ts Fixed
Comment thread src/cli.ts Fixed
Comment thread src/option-parsers.ts Fixed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the CLI by moving parsing/validation helpers out of src/cli.ts into focused modules while keeping src/cli.ts as the main orchestration entrypoint and re-export surface.

Changes:

  • Extracted domain and agent-image helpers into src/domain-utils.ts.
  • Extracted API proxy validation/domain-resolution helpers into src/api-proxy-config.ts.
  • Extracted CLI option parsing/validation helpers into src/option-parsers.ts, with src/cli.ts re-exporting the moved symbols for compatibility.

Findings:

  • src/option-parsers.ts:1 introduces an unused top-level fs import while parseVolumeMounts still does its own require('fs'); this will fail the repo’s ESLint configuration because @typescript-eslint/no-unused-vars is enforced as an error for src/**/*.ts.
Show a summary per file
File Description
src/option-parsers.ts New module containing CLI flag parsing, validation, shell escaping, and mount/env parsing helpers.
src/domain-utils.ts New module containing domain parsing, IP validation, agent image validation, and default API target constants.
src/cli.ts Reduced main CLI module that now re-exports extracted helpers and imports the moved functions for local use.
src/api-proxy-config.ts New module containing API proxy validation, warning helpers, and GHEC/GHES/API-target allowlist resolution logic.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 4/4 changed files
  • Comments generated: 1

Comment thread src/option-parsers.ts Outdated
@@ -0,0 +1,578 @@
import * as fs from 'fs';
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox
Copy link
Copy Markdown
Collaborator Author

lpcox commented May 4, 2026

@copilot merge main and address the review feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

@copilot merge main and address the review feedback

Done. Merged main (commit 0c7f577) and addressed the CodeQL feedback (commit 8be56ed):

  • Removed the redundant import block for DEFAULT_OPENAI/ANTHROPIC/COPILOT/GEMINI_API_TARGET in src/cli.ts — these were already re-exported via export { ... } from './domain-utils' and were never used in the file body.
  • Removed hasRateLimitOptions and escapeShellArg from the src/cli.ts import block for the same reason.
  • Removed the unused top-level import * as fs from 'fs' in src/option-parsers.ts; the function already uses an inline require('fs').

All 356 tests pass and lint reports 0 errors.

Copilot finished work on behalf of lpcox May 4, 2026 16:11
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Smoke Test: Copilot BYOK — PASS ✅

Test Result
GitHub MCP (latest merged PR: "refactor: extract runWithSignalHandling helper")
GitHub.com connectivity (HTTP 200/301)
File write/read (smoke-test-copilot-byok-25329568556.txt)
BYOK inference (agent → api-proxy → api.githubcopilot.com)

Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com.

cc @lpcox (author) @Mossaka (reviewer)

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

🔥 Smoke Test Results — PR #2498

Test Result
GitHub MCP connectivity
GitHub.com HTTP (200)
File write/read

PR: refactor: split cli.ts into focused modules@lpcox, reviewer: @Mossaka

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Smoke Test Results:
✅ GitHub MCP: Retrieved 2 merged PRs (#2495, #2493)
✅ Playwright: GitHub page title verified
✅ File Writing: Test file created successfully
✅ Bash Verification: File content confirmed

Status: PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

refactor: extract createBaseAdapterConfig helper
refactor: extract runWithSignalHandling helper
GitHub MCP ✅
safeinputs-gh ❌
Playwright ✅
Tavily ❌
File write/read ✅
Discussion comment ❌
Build ✅
Overall: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color passed ✅ PASS
Go env passed ✅ PASS
Go uuid passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #2498 · ● 532.3K ·

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Smoke Test Results

Check Result
Redis PING ❌ timeout/no response
PostgreSQL pg_isready ❌ no response
PostgreSQL SELECT 1 ❌ failed

Overall: FAILhost.docker.internal is not reachable from this runner environment. Service containers may not be running or the hostname is not resolvable.

🔌 Service connectivity validated by Smoke Services

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3 ❌ NO
Node.js v24.14.1 v20.20.2 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

ALL_TESTS_PASSED: false — Python and Node.js versions differ between host and chroot environment.

Tested by Smoke Chroot

@lpcox lpcox merged commit 2188bbf into main May 4, 2026
62 of 66 checks passed
@lpcox lpcox deleted the refactor/split-cli-into-modules branch May 4, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactoring] Split src/cli.ts into focused modules

4 participants