Skip to content

Add Core command bus foundation#271

Merged
TraderSamwise merged 2 commits into
masterfrom
feat/core-command-bus
Jul 3, 2026
Merged

Add Core command bus foundation#271
TraderSamwise merged 2 commits into
masterfrom
feat/core-command-bus

Conversation

@TraderSamwise

@TraderSamwise TraderSamwise commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • add a typed Core command contract and daemon-local command route
  • add a Core command client wrapper for future CLI/TUI cutovers
  • inventory current one-shot Node runtime surfaces so the hard cut can track them down

Verification

  • yarn verify
  • yarn build

Summary by CodeRabbit

  • New Features
    • Added “core commands” support to the daemon API, including typed request/response handling for ping and status.
    • Introduced a new client helper to send core commands with optional timeouts and validate successful responses.
  • Bug Fixes
    • Improved validation so unknown or mismatched commands return clear error payloads (HTTP 400).
  • Tests
    • Added contract tests for core command routing and response structure.
    • Added an inventory consistency test to verify expected file contents via regex matching.

@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 3, 2026 5:08am

@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: c747ed7f-5782-4a36-8a88-d8c5634f7958

📥 Commits

Reviewing files that changed from the base of the PR and between 213edb7 and 8f78119.

📒 Files selected for processing (3)
  • src/core-command-contract.test.ts
  • src/core-command-contract.ts
  • src/daemon.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/core-command-contract.test.ts
  • src/core-command-contract.ts
  • src/daemon.ts

📝 Walkthrough

Walkthrough

This PR adds a typed core-command protocol for daemon requests, including shared contract types, a client helper, daemon routing for ping and status, and tests. It also adds a separate inventory test that checks several project files against regex expectations.

Changes

Core Command Protocol

Layer / File(s) Summary
Contract types and constants
src/core-command-contract.ts
Defines route and command-name constants, typed envelopes and responses, CoreStatusProject, command result maps, runtime validation, and an exhaustiveness helper.
Client helper for sending core commands
src/core-command-client.ts
Adds requestCoreCommand, which ensures the daemon is running, posts a typed envelope to CORE_API_ROUTES.commands, and validates the response.
Daemon-side core command routing
src/daemon.ts
Adds routeCoreCommand to validate envelopes and handle ping and status, and wires POST requests to CORE_API_ROUTES.commands into it.
Core command contract tests
src/core-command-contract.test.ts
Adds Vitest coverage for ping, status, and unknown-command routing through AimuxDaemon.routeRequest.

Node Runtime Spawn Inventory Test

Layer / File(s) Summary
Runtime spawn inventory test
src/one-shot-node-inventory.test.ts
Defines an 11-entry file/pattern inventory and asserts each referenced file matches its regex expectation.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

  • TraderSamwise/aimux#9: Both PRs modify src/daemon.ts and its request-routing path, so the daemon HTTP dispatch changes are directly connected.
🚥 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 accurately summarizes the main change: adding the Core command bus foundation and related routing/client contract pieces.
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 feat/core-command-bus

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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.

🧹 Nitpick comments (1)
src/daemon.ts (1)

1117-1157: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add exhaustive command handling instead of implicit if/else fallthrough.

The status branch is reached simply because command !== CORE_COMMAND_NAMES.ping, not because it was verified to equal CORE_COMMAND_NAMES.status. The return type here (CoreCommandResponse, not parameterized by the actual command) means TypeScript won't catch it if a third command is later added to CORE_COMMAND_NAMES without a corresponding branch — it would silently fall through and return status-shaped data under the new command's name. The client-side response.command !== command check in core-command-client.ts wouldn't catch this either, since the command name would still match.

Using a switch with an explicit never-exhaustiveness check on command in the default case would surface this at compile time as soon as CORE_COMMAND_NAMES grows.

♻️ Proposed refactor for exhaustive command routing
-    const issuedAt = new Date().toISOString();
-    if (command === CORE_COMMAND_NAMES.ping) {
-      return { status: 200, body: { ok: true, id, command, issuedAt, result: { pong: true } } };
-    }
-    return {
-      status: 200,
-      body: {
-        ok: true,
-        id,
-        command,
-        issuedAt,
-        result: {
-          daemon: {
-            pid: process.pid,
-            port: getDaemonPort(),
-            serviceInfo: getProjectServiceManifest(),
-          },
-          projects: this.listProjectsForRoute(),
-          updatedAt: this.state.updatedAt,
-        },
-      },
-    };
+    const issuedAt = new Date().toISOString();
+    switch (command) {
+      case CORE_COMMAND_NAMES.ping:
+        return { status: 200, body: { ok: true, id, command, issuedAt, result: { pong: true } } };
+      case CORE_COMMAND_NAMES.status:
+        return {
+          status: 200,
+          body: {
+            ok: true,
+            id,
+            command,
+            issuedAt,
+            result: {
+              daemon: {
+                pid: process.pid,
+                port: getDaemonPort(),
+                serviceInfo: getProjectServiceManifest(),
+              },
+              projects: this.listProjectsForRoute(),
+              updatedAt: this.state.updatedAt,
+            },
+          },
+        };
+      default: {
+        const _exhaustive: never = command;
+        return { status: 400, body: { ok: false, id, command: _exhaustive, error: "unhandled core command" } };
+      }
+    }
🤖 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/daemon.ts` around lines 1117 - 1157, The core command routing in
routeCoreCommand currently treats every non-ping command as the status response,
which can silently miss future CORE_COMMAND_NAMES additions. Replace the
implicit if/else fallthrough with an explicit switch on command that handles
CORE_COMMAND_NAMES.ping and CORE_COMMAND_NAMES.status separately, and add a
default branch with a never exhaustiveness check so new commands in
CoreCommandEnvelope/CoreCommandResponse are caught at compile time.
🤖 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.

Nitpick comments:
In `@src/daemon.ts`:
- Around line 1117-1157: The core command routing in routeCoreCommand currently
treats every non-ping command as the status response, which can silently miss
future CORE_COMMAND_NAMES additions. Replace the implicit if/else fallthrough
with an explicit switch on command that handles CORE_COMMAND_NAMES.ping and
CORE_COMMAND_NAMES.status separately, and add a default branch with a never
exhaustiveness check so new commands in CoreCommandEnvelope/CoreCommandResponse
are caught at compile time.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 558a0db8-0760-470e-90ba-cd808973f31d

📥 Commits

Reviewing files that changed from the base of the PR and between e54c50e and 213edb7.

📒 Files selected for processing (5)
  • src/core-command-client.ts
  • src/core-command-contract.test.ts
  • src/core-command-contract.ts
  • src/daemon.ts
  • src/one-shot-node-inventory.test.ts

@TraderSamwise

Copy link
Copy Markdown
Owner Author

Addressed CodeRabbit's exhaustive command routing finding in 8f78119 by switching Core command dispatch to an explicit switch with a never exhaustiveness guard.

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.

2 participants