Skip to content

split cli/utils.ts into focused modules and add shared logger/db helpers#14210

Merged
noanflaherty merged 1 commit into
mainfrom
do/split-cli-utils
Mar 7, 2026
Merged

split cli/utils.ts into focused modules and add shared logger/db helpers#14210
noanflaherty merged 1 commit into
mainfrom
do/split-cli-utils

Conversation

@noanflaherty
Copy link
Copy Markdown
Contributor

@noanflaherty noanflaherty commented Mar 7, 2026

Summary

  • Split monolithic cli/utils.ts into cli/output.ts (output formatting), cli/gateway-client.ts (gateway HTTP helpers), cli/logger.ts (shared CLI logger), and cli/db.ts (shared db init)
  • Updated 21 command files to import from the new focused modules, eliminating repeated const log = getCliLogger("cli") boilerplate across 13 files and shortening ../../memory/db.js imports in 6 files
  • Deleted the old catch-all cli/utils.ts

Original prompt

Split utils.ts into output.ts and gateway-client.ts, add shared logger.ts and db.ts helpers

🤖 Generated with Claude Code


Open with Devin

Replace the monolithic cli/utils.ts with four focused modules:
- cli/output.ts: writeOutput, shouldOutputJson, runRead (8 consumers)
- cli/gateway-client.ts: gatewayGet, gatewayPost, toQueryString, asRecord
- cli/logger.ts: shared CLI logger instance + getCliLogger re-export (14 consumers)
- cli/db.ts: initializeDb re-export from memory/db (7 consumers)

Update all 21 command files to import from the new modules instead of
the old utils.ts and ../../util/logger.js / ../../memory/db.js paths.

Co-Authored-By: Claude <noreply@anthropic.com>
@noanflaherty noanflaherty merged commit ddc8dae into main Mar 7, 2026
5 checks passed
@noanflaherty noanflaherty deleted the do/split-cli-utils branch March 7, 2026 23:16
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment on lines 13 to 14
return value as Record<string, unknown>;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Dead code (asRecord) retained in gateway-client.ts, violating AGENTS.md dead-code removal rule

The asRecord function is exported from assistant/src/cli/gateway-client.ts:9-14 but is never imported by any file in the codebase (verified via grep). It was carried over from the old utils.ts during this refactoring split. The root AGENTS.md mandates: "Proactively remove unused code during every change. Remove code your change makes unused, clean up adjacent dead code... Ask: 'After my change, is there any code that nothing calls, imports, or references?' If yes, delete it."

(Refers to lines 9-14)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +3 to +4
import { gatewayGet, toQueryString } from "../gateway-client.js";
import { runRead } from "../output.js";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚩 channels.ts continues to proxy through gateway HTTP API (pre-existing)

The channels.ts command imports gatewayGet from ../gateway-client.js and calls the gateway HTTP API (/v1/channels/readiness) rather than calling the service/store layer directly. The assistant/src/cli/AGENTS.md rule "Service calls — no gateway proxying" says CLI commands must call the service layer directly. However, this is pre-existing behavior — the PR only changed the import path from ../utils.js to ../gateway-client.js. Channel readiness may legitimately require the gateway to be running (the help text says "The assistant must be running — channel status is read from the live gateway"), so this may be an intentional exception. Worth reviewing whether a direct service call is feasible here.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant