Skip to content

Route core CLI commands through sidecar entry#285

Merged
TraderSamwise merged 6 commits into
masterfrom
chore/core-sidecar-next-9
Jul 4, 2026
Merged

Route core CLI commands through sidecar entry#285
TraderSamwise merged 6 commits into
masterfrom
chore/core-sidecar-next-9

Conversation

@TraderSamwise

@TraderSamwise TraderSamwise commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • route daemon/status/projects/remote sidecar-owned CLI commands through a lean core entrypoint
  • keep tmux/runtime/agent lifecycle commands on the full CLI
  • add behavior and boundary coverage so the core entrypoint cannot import the TUI/runtime graph

Verification

  • yarn vitest run src/launcher-env.test.ts src/core-cli.test.ts src/core-sidecar-boundary.test.ts src/core-command-client.test.ts src/core-command-transport.test.ts
  • yarn typecheck
  • yarn lint
  • yarn vitest run
  • yarn build
  • isolated live check: AIMUX_HOME=$(mktemp -d) AIMUX_DAEMON_PORT=45678 node bin/aimux daemon status
  • push hook: yarn typecheck && yarn lint && yarn test

Summary by CodeRabbit

  • New Features
    • Added a dedicated core CLI flow for host status, daemon status/projects, project ensure, and remote status/enable/disable.
    • Added consistent JSON output options alongside human-readable summaries.
    • Enhanced command routing so core CLI is selected only for the supported core command set.
  • Bug Fixes
    • Improved handling when the daemon is unreachable by using local fallback info and clearer “not alive/off” reporting.
    • Hardened argument validation to prevent malformed core/remote operations from proceeding unexpectedly.
  • Tests
    • Expanded CLI routing, core-side behavior, and core/TUI boundary coverage.
  • Chores
    • Updated the installed shim to start the routed launcher entrypoint.

@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Jul 4, 2026 2:40am

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4d1ff22b-0a2a-49b0-93a4-6dc5af606bf1

📥 Commits

Reviewing files that changed from the base of the PR and between 7e211d6 and b2a2930.

📒 Files selected for processing (5)
  • src/core-cli-routing.ts
  • src/core-cli.test.ts
  • src/core-cli.ts
  • src/launcher-env.test.ts
  • src/launcher-env.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/launcher-env.test.ts
  • src/core-cli.test.ts

📝 Walkthrough

Walkthrough

Adds a core CLI entrypoint with command routing and handlers for host, daemon, projects, and remote operations. Launcher routing now sends core commands to the new entrypoint, and the shim/install path was updated accordingly. Tests cover command behavior and sidecar boundaries.

Changes

Core CLI feature

Layer / File(s) Summary
Core CLI argument routing
src/core-cli-routing.ts
Normalizes argv input, detects global logging flags, and parses or validates daemon project-ensure command shape and flags.
Core CLI command implementation
src/core-cli.ts
Adds runCoreCli, shared I/O and lookup helpers, and handlers for host, daemon, projects, and remote commands with JSON and human-readable output paths.
Launcher routing and shim entrypoint
src/launcher-env.ts, src/launcher-bin.ts, scripts/install.sh, src/launcher-env.test.ts, src/one-shot-node-inventory.test.ts
Routes core commands through core-cli.js, adds the launcher-bin entrypoint, updates the install shim target, and adjusts routing and inventory tests to match the new entrypoint.
Core CLI tests and boundary check
src/core-cli.test.ts, src/core-sidecar-boundary.test.ts
Adds CLI behavior coverage for success and failure paths plus a source-boundary check for runtime and TUI imports.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • TraderSamwise/aimux#271: Adds the core command-bus surface that this PR’s runCoreCli handlers and transport calls use.
  • TraderSamwise/aimux#273: Expands the core command contract for project and relay operations that this PR routes through.
  • TraderSamwise/aimux#283: Also enforces the core sidecar versus runtime/TUI boundary that this PR extends with a source check.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: routing core CLI commands through the new sidecar entrypoint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/core-sidecar-next-9

Comment @coderabbitai help to get the list of available commands.

@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/core-cli.ts (1)

169-180: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Near-duplicate project-listing logic.

runDaemonProjects and runProjectsList both fetch CORE_COMMAND_NAMES.projectsList and render a name badge path line, differing only in badge text ("service"/"idle" vs "live"/"idle") and the empty-list message. Consider extracting a shared formatter parameterized by badge labels to avoid drift if the format changes later.

Also applies to: 198-214

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core-cli.ts` around lines 169 - 180, The project-listing logic in
runDaemonProjects and runProjectsList is duplicated and likely to drift. Extract
a shared helper around the CORE_COMMAND_NAMES.projectsList fetch and the common
name/badge/path rendering, and parameterize the badge labels so
runDaemonProjects can use “service/idle” while runProjectsList uses “live/idle”
and its empty-list message. Keep the shared formatting close to the existing
runDaemonProjects and runProjectsList flow so both callers use the same
formatter instead of maintaining separate copy-pasted loops.
src/core-sidecar-boundary.test.ts (1)

58-65: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Boundary check only covers direct string literals in core-cli.ts, not transitive imports.

This substring check on core-cli.ts's own source won't catch a forbidden module being pulled in transitively through one of core-cli.ts's own imports (e.g., if worktree.js or daemon-state.js later imports ./main.js). For a stronger guarantee that the core CLI graph excludes the TUI/runtime, consider walking the import graph (or asserting against the built dist/ bundle) rather than just the entry file's literal text.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core-sidecar-boundary.test.ts` around lines 58 - 65, The current boundary
test in core-sidecar-boundary.test.ts only checks literal substrings in
core-cli.ts, so it can miss forbidden modules brought in transitively through
imports like worktree.js or daemon-state.js. Update the test around source() and
the coreCli assertion to validate the full import graph from core-cli.ts, or
switch it to assert against the built dist bundle, so it fails whenever
./main.js, ./multiplexer/, ./tmux/, ./dashboard/, or ./local-ui-server.js are
reachable indirectly.
src/core-cli.test.ts (1)

167-185: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test doesn't exercise the fallback projects mapping.

This test sets mocks.daemonState.projects.repo but since mocks.daemonInfo is also null, runDaemonStatus's text-output path short-circuits at the !daemon check (core-cli.ts Line 152-155) before ever printing Known projects/Live project services, so the populated daemonState.projects fallback mapping (core-cli.ts Line 141-146) is never actually asserted. Consider adding a --json assertion (or setting daemonInfo non-null with the fetch still rejecting) to verify the merged fallback projects array is correct.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core-cli.test.ts` around lines 167 - 185, The daemon status test is only
covering the offline text fallback and never verifies the merged fallback
projects mapping. Update the `runDaemonStatus` coverage in
`src/core-cli.test.ts` so it actually exercises the `daemonState.projects`
fallback in `runDaemonStatus` and asserts the resulting `projects` data, either
by adding a `--json` case or by keeping `daemonInfo` non-null while
`requestCoreCommand` still rejects. Use the `runDaemonStatus` and
`mocks.daemonState.projects` symbols to locate the relevant setup and
expectations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core-cli.ts`:
- Around line 25-38: The command argument filtering in commandArgs is duplicated
and can drift between core-cli and launcher-env, causing routing and parsing
mismatches. Extract the shared global-flag stripping logic into a single
reusable helper module (for example, a shared CLI args utility) and have both
commandArgs call sites use that same function so cliEntryFor and runCoreCli stay
consistent when flags change.

In `@src/launcher-env.ts`:
- Around line 39-50: `isCoreCliCommand` is duplicating the core-command routing
list from `runCoreCli`, so keep them in lockstep by extracting the
command/subcommand contract into a shared source and using it in both
`src/launcher-env.ts` and `src/core-cli.ts`. Update the routing logic around
`isCoreCliCommand` and the `runCoreCli` dispatch so they read from the same
centralized list of supported pairs, preventing one side from accepting a
command the other rejects.

---

Nitpick comments:
In `@src/core-cli.test.ts`:
- Around line 167-185: The daemon status test is only covering the offline text
fallback and never verifies the merged fallback projects mapping. Update the
`runDaemonStatus` coverage in `src/core-cli.test.ts` so it actually exercises
the `daemonState.projects` fallback in `runDaemonStatus` and asserts the
resulting `projects` data, either by adding a `--json` case or by keeping
`daemonInfo` non-null while `requestCoreCommand` still rejects. Use the
`runDaemonStatus` and `mocks.daemonState.projects` symbols to locate the
relevant setup and expectations.

In `@src/core-cli.ts`:
- Around line 169-180: The project-listing logic in runDaemonProjects and
runProjectsList is duplicated and likely to drift. Extract a shared helper
around the CORE_COMMAND_NAMES.projectsList fetch and the common name/badge/path
rendering, and parameterize the badge labels so runDaemonProjects can use
“service/idle” while runProjectsList uses “live/idle” and its empty-list
message. Keep the shared formatting close to the existing runDaemonProjects and
runProjectsList flow so both callers use the same formatter instead of
maintaining separate copy-pasted loops.

In `@src/core-sidecar-boundary.test.ts`:
- Around line 58-65: The current boundary test in core-sidecar-boundary.test.ts
only checks literal substrings in core-cli.ts, so it can miss forbidden modules
brought in transitively through imports like worktree.js or daemon-state.js.
Update the test around source() and the coreCli assertion to validate the full
import graph from core-cli.ts, or switch it to assert against the built dist
bundle, so it fails whenever ./main.js, ./multiplexer/, ./tmux/, ./dashboard/,
or ./local-ui-server.js are reachable indirectly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d74caa05-5dc8-4012-a943-fe11fa7df68b

📥 Commits

Reviewing files that changed from the base of the PR and between 6a2f18b and d76ff10.

📒 Files selected for processing (5)
  • src/core-cli.test.ts
  • src/core-cli.ts
  • src/core-sidecar-boundary.test.ts
  • src/launcher-env.test.ts
  • src/launcher-env.ts

Comment thread src/core-cli.ts Outdated
Comment thread src/launcher-env.ts Outdated
@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core-cli-routing.ts`:
- Around line 23-29: The CLI argument guards in hasOnlyFlags and hasNoOptions
are still treating stray positional tokens as valid, so core routing can
silently accept malformed commands. Update these helpers in
src/core-cli-routing.ts so hasOnlyFlags permits only recognized flags and
rejects any non-flag positional arguments, and hasNoOptions requires the args
list to be empty rather than merely free of flags. This should make commands
routed through the core CLI handlers fail fast for inputs like host status foo,
projects list bar, and remote enable baz instead of ignoring the extra token.
- Around line 31-51: Update isValidCoreProjectEnsureArgs and hasProjectOption in
core-cli-routing so daemon project-ensure accepts both --project value and
--project=value. Right now hasProjectOption only checks for a separate next
token and the validation loop in isValidCoreProjectEnsureArgs rejects the equals
form before readOption() can handle it; adjust both checks to recognize the
inline assignment while still allowing only the supported flags and the
daemon/project-ensure prefix.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 322e3d67-7740-4c97-a8a4-a41169d9de67

📥 Commits

Reviewing files that changed from the base of the PR and between d76ff10 and 7e211d6.

📒 Files selected for processing (8)
  • scripts/install.sh
  • src/core-cli-routing.ts
  • src/core-cli.test.ts
  • src/core-cli.ts
  • src/launcher-bin.ts
  • src/launcher-env.test.ts
  • src/launcher-env.ts
  • src/one-shot-node-inventory.test.ts

Comment thread src/core-cli-routing.ts Outdated
Comment thread src/core-cli-routing.ts Outdated
@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@TraderSamwise
TraderSamwise merged commit 006d34c into master Jul 4, 2026
3 checks passed
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