Skip to content

Route metadata CLI through daemon#320

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

Route metadata CLI through daemon#320
TraderSamwise merged 4 commits into
masterfrom
chore/core-sidecar-next-45

Conversation

@TraderSamwise

@TraderSamwise TraderSamwise commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • route installed aimux metadata ... commands through daemon /core/metadata-text instead of spawning one-shot Node on healthy installs
  • parse metadata CLI argv centrally and forward mutations to project-service runtime APIs
  • remove source CLI direct metadata-store writes and preserve context PR merge semantics in the service

Verification

  • sh -n scripts/installed-aimux-shim.sh
  • yarn typecheck
  • yarn lint
  • yarn vitest run src/metadata-cli-routing.test.ts src/daemon.test.ts src/installed-shim.test.ts src/core-command-ownership.test.ts src/metadata-server.test.ts
  • yarn vitest run
  • yarn build

Summary by CodeRabbit

  • New Features

    • Added support for runtime metadata commands, including viewing the live endpoint and sending metadata updates through the app.
    • Expanded metadata command options for richer session, status, context, progress, and service details.
  • Bug Fixes

    • Improved handling of metadata context updates so pull request details are merged more reliably.
    • Added validation for malformed metadata commands, with clearer error responses.

@vercel

vercel Bot commented Jul 5, 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 5, 2026 1:37pm

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1e6bb8ee-1fde-4e2e-9bb3-895377fb620d

📥 Commits

Reviewing files that changed from the base of the PR and between c4dad60 and e171c68.

📒 Files selected for processing (9)
  • scripts/installed-aimux-shim.sh
  • src/daemon.test.ts
  • src/daemon.ts
  • src/installed-shim.test.ts
  • src/main.ts
  • src/metadata-cli-routing.test.ts
  • src/metadata-cli-routing.ts
  • src/metadata-server.test.ts
  • src/metadata-server.ts
📝 Walkthrough

Walkthrough

Adds a new daemon route /core/metadata-text and a parseRuntimeMetadataCliArgs parser to route aimux metadata CLI commands over HTTP to the project service instead of mutating local state. Updates the installed shim script and main.ts, adjusts context-merge logic for PR fields, and adds tests/docs.

Changes

Metadata command routing

Layer / File(s) Summary
Core route contract and CLI arg parser
src/core-command-contract.ts, src/metadata-cli-routing.ts, src/metadata-cli-routing.test.ts
Adds CORE_API_ROUTES.metadataText and parseRuntimeMetadataCliArgs, parsing metadata subcommands (endpoint, event, set-status, set-progress, set-context, set-services, log, etc.) into route/body payloads, with unit tests.
Daemon metadata route handler
src/daemon.ts, src/metadata-server.ts, src/daemon.test.ts
Adds metadataTextRoute to serve endpoint text or forward mutations to the project service, wires it into routeRequest, fixes setContext PR-field merge, and adds daemon tests.
Installed shim fast-path support
scripts/installed-aimux-shim.sh, src/core-command-ownership.test.ts, src/installed-shim.test.ts
Adds aimux_post_get_query_text_route and aimux_try_metadata shim functions, wires the metadata dispatch case, and extends fixture/tests for the new fast path.
CLI metadata command rewiring and docs
src/main.ts, docs/command-ownership-inventory.md
Replaces local metadata mutation logic in aimux metadata * commands with HTTP posts via postRuntimeMetadata, resolves endpoint via getProjectServiceEndpoint, and updates the ownership inventory entry.

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

Sequence Diagram(s)

sequenceDiagram
  participant CLI as aimux CLI (main.ts / shim)
  participant Daemon as Daemon (metadataTextRoute)
  participant ProjectService as Project Service
  participant Metadata as metadata-server.ts

  CLI->>Daemon: POST /core/metadata-text (project, args)
  Daemon->>Daemon: parseRuntimeMetadataCliArgs(args)
  alt command = endpoint
    Daemon->>Daemon: ensure project running, load endpoint
    Daemon-->>CLI: 200 text (http://host:port)
  else other command
    Daemon->>ProjectService: postProjectServiceJson(routePath, body)
    ProjectService->>Metadata: update runtime.setContext / setStatus / etc.
    Metadata-->>ProjectService: merged metadata (pr merge logic)
    ProjectService-->>Daemon: ok / error
    Daemon-->>CLI: 200 empty / 400 / 503
  end
Loading

Possibly related PRs

  • TraderSamwise/aimux#271: Both PRs extend CORE_API_ROUTES in src/core-command-contract.ts and daemon request dispatch logic.
  • TraderSamwise/aimux#272: The new daemon metadata route's reliance on project service startup relates to the project service lifecycle management introduced in the retrieved PR.
  • TraderSamwise/aimux#298: Both PRs extend the same scripts/installed-aimux-shim.sh CLI dispatch and route-helper logic.
🚥 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: routing metadata CLI commands through the daemon.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/core-sidecar-next-45

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

@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 5, 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

Independent review findings resolved in c63d6a8:\n\n- Added /core/metadata-text to LOCAL_CLI_TEXT_ROUTES and covered relay/browser-origin denial for metadata text requests.\n- Bypassed the installed shim metadata fast path for -h/--help so Commander help still renders via the Node launcher instead of daemon parser errors.

@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 5, 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/metadata-server.ts (1)

3020-3041: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Missing optional chaining on body.context.pr regresses handling of a missing/null context.

current.context?.pr is optional-chained, but body.context.pr (both places) is not. If body.context is ever undefined/null — plausible for any direct (non-CLI) caller of this pre-existing public endpoint, since the request type isn't runtime-validated — this throws instead of degrading gracefully like the old spread-based merge did.

🐛 Proposed fix
         updateSessionMetadata(body.session, (current) => {
           const pr =
-            current.context?.pr || body.context.pr
+            current.context?.pr || body.context?.pr
               ? {
                   ...(current.context?.pr ?? {}),
-                  ...(body.context.pr ?? {}),
+                  ...(body.context?.pr ?? {}),
                 }
               : undefined;
           return {
             ...current,
             context: {
               ...(current.context ?? {}),
-              ...body.context,
+              ...(body.context ?? {}),
               ...(pr ? { pr } : {}),
             },
           };
         });
🤖 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/metadata-server.ts` around lines 3020 - 3041, The runtime.setContext
handler in metadata-server should tolerate a missing or null body.context
instead of dereferencing it directly. In the updateSessionMetadata merge logic,
update the current.context?.pr/body.context.pr handling so both accesses are
optional-chained and the PR merge only runs when body.context.pr exists,
preserving the previous graceful behavior for direct callers. Use the setContext
request parsing and the updateSessionMetadata callback as the main spots to
adjust.
🧹 Nitpick comments (1)
scripts/installed-aimux-shim.sh (1)

198-232: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Verified: -X POST --get combo works as intended.

Confirmed via curl semantics that explicit -X POST overrides the wire request-line method while --get still moves --data-urlencode pairs into the query string — this is a known technique, not a bug. The status/cleanup handling mirrors aimux_post_text_route exactly.

Note the near-duplication with aimux_post_text_route (lines 129-161): the only real difference is the --get "$@" on the curl invocation. Consider factoring the shared status-handling/cleanup logic into a common helper to avoid drift between the two routes as they evolve.
[optional_refactor_low_effort_low_reward_note]

🤖 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 `@scripts/installed-aimux-shim.sh` around lines 198 - 232, The status/cleanup
logic in aimux_post_get_query_text_route is duplicated from
aimux_post_text_route, so factor the shared curl result handling, body_file
cleanup, and trap reset into a common helper and have both route functions call
it, keeping only the request-specific curl options in each function.
🤖 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/daemon.ts`:
- Around line 2412-2415: `metadataTextRoute` is currently reachable without the
same CLI-only protection as the other text routes. Update the `Daemon` request
handling around `CORE_API_ROUTES.metadataText` so it is gated by
`LOCAL_CLI_TEXT_ROUTES` or the same loopback/Origin rejection used for the other
CLI text endpoints, preventing remote callers from reaching this metadata
mutation path.

In `@src/main.ts`:
- Around line 3431-3441: The direct CLI handler for metadataCmd.set-progress is
missing the same numeric validation used by parseRuntimeMetadataCliArgs, so
invalid current/total values can become NaN and be persisted as null. Update the
action callback for set-progress to validate Number(current) and Number(total)
with Number.isFinite before calling postRuntimeMetadata, and fail fast with a
clear error if either value is not finite. Keep the fix localized to the
metadataCmd command path so it matches the shim parser behavior.

---

Outside diff comments:
In `@src/metadata-server.ts`:
- Around line 3020-3041: The runtime.setContext handler in metadata-server
should tolerate a missing or null body.context instead of dereferencing it
directly. In the updateSessionMetadata merge logic, update the
current.context?.pr/body.context.pr handling so both accesses are
optional-chained and the PR merge only runs when body.context.pr exists,
preserving the previous graceful behavior for direct callers. Use the setContext
request parsing and the updateSessionMetadata callback as the main spots to
adjust.

---

Nitpick comments:
In `@scripts/installed-aimux-shim.sh`:
- Around line 198-232: The status/cleanup logic in
aimux_post_get_query_text_route is duplicated from aimux_post_text_route, so
factor the shared curl result handling, body_file cleanup, and trap reset into a
common helper and have both route functions call it, keeping only the
request-specific curl options in each function.
🪄 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: 2b835d34-1214-4378-b694-2fb0679fab4b

📥 Commits

Reviewing files that changed from the base of the PR and between 8959c21 and c4dad60.

📒 Files selected for processing (11)
  • docs/command-ownership-inventory.md
  • scripts/installed-aimux-shim.sh
  • src/core-command-contract.ts
  • src/core-command-ownership.test.ts
  • src/daemon.test.ts
  • src/daemon.ts
  • src/installed-shim.test.ts
  • src/main.ts
  • src/metadata-cli-routing.test.ts
  • src/metadata-cli-routing.ts
  • src/metadata-server.ts

Comment thread src/daemon.ts
Comment thread src/main.ts
@TraderSamwise

Copy link
Copy Markdown
Owner Author

Independent review round 2 resolved in b3ffa73: metadata help subcommands (for example aimux metadata help set-status) now fall through to Commander instead of the daemon fast path, with installed-shim coverage.

@TraderSamwise

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 5, 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

Review fixes landed in e171c68:

  • Added direct CLI numeric validation for metadata set-progress.
  • Made runtime set-context tolerate missing/null context payloads while preserving existing PR context.
  • Fixed independent-review edge cases for bare aimux metadata help fallback and dash-prefixed metadata values after --.
  • Left the low-value shell dedupe nit as-is to keep this PR scoped to the behavior cutover and bug fixes.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

@TraderSamwise Thanks for the update. I'll review the changes in e171c68.

✅ 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 d212046 into master Jul 5, 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