Skip to content

feat(cli): support scoped monorepo init - #2684

Merged
riderx merged 8 commits into
mainfrom
codex/init-monorepo-targeting
Jul 15, 2026
Merged

feat(cli): support scoped monorepo init#2684
riderx merged 8 commits into
mainfrom
codex/init-monorepo-targeting

Conversation

@riderx

@riderx riderx commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary

  • add global --capacitor-config targeting for every CLI command that writes Capacitor config
  • preserve dynamic root config loading (for example CAP_APP) while writing only the selected app source
  • extend the same targeting to the MCP server lifetime and live-update onboarding
  • document dynamic-monorepo usage for init, upload, settings, keys, notifications, and MCP

Test plan

  • Run bun run cli:check
  • Run the compiled CLI against a temporary root config and selected TypeScript source
  • Start a real MCP server, generate encryption keys, and verify only the selected source changes
  • Verify the live-update onboarding tool accepts and retains capacitorConfig

Validation

  • bun run cli:check

Screenshots

Not applicable — this is CLI/MCP behavior with no visual UI change.

Checklist

  • Tests added for the regression
  • Customer-facing documentation updated
  • No unrelated workspace files included

Summary by CodeRabbit

  • New Features
    • Added monorepo-capable init target options: --package-json, --main-file, and --capacitor-config.
    • Added --capacitor-config <path> to config-changing commands, including bundle upload, app setting, key operations, notifications setup, and MCP tools/tooling.
  • Bug Fixes
    • Ensured config writes target the selected Capacitor config source without changing the root config.
    • Improved init/MCP resume behavior and scoped session/progress to the chosen config source.
  • Documentation
    • Updated init, app/bundle/key/notifications, MCP, and README docs for dynamic monorepos and --capacitor-config.
  • Tests
    • Added/expanded CLI and MCP integration tests for config-target resolution, key writing scoping, MCP config restoration on failure, and live-update onboarding validation/behavior.

Note

Medium Risk
Touches config read/write paths used by init, uploads, keys, and MCP; mistakes could write the wrong app’s Capacitor config in monorepos, though path validation and scoped MCP writes reduce that risk.

Overview
Adds global --capacitor-config so Capgo can read the active root Capacitor config (e.g. with CAP_APP) while writing only a chosen app-specific capacitor.config.* source. Config mutations go through loadConfigForWrite / getConfigForWrite, with AsyncLocalStorage scoping for concurrent MCP calls.

init gains --package-json, --main-file, and --capacitor-config, plus safer resume when checkpoints belong to a different app in the same workspace.

MCP / SDK: server startup keeps the config target for its lifetime; live-update onboarding tracks progress and session per config source; upload and encryption tools accept capacitorConfig / autoSetBundle.

Docs and skills describe dynamic-monorepo usage; new tests cover target resolution, init resume, and MCP isolation.

Reviewed by Cursor Bugbot for commit 000706d. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

capgo init, SDK methods, CLI commands, and MCP workflows now support explicit Capacitor config targets for monorepos. Target resolution, scoped writes, onboarding persistence, tests, and documentation were added.

Changes

Dynamic Capacitor config targeting

Layer / File(s) Summary
Config target resolution and CLI wiring
cli/src/config/index.ts, cli/src/index.ts, cli/src/bundle/upload.ts, cli/src/capacitor-cli.ts
Adds target-path state and resolution, exposes --capacitor-config across config-writing commands, and reports the selected config path in bundle upload logs.
Monorepo init path handling and config writes
cli/src/init/command.ts, cli/src/key.ts, cli/src/init/mcp/engine.ts
Init validates explicit targets, loads configuration from the derived directory, preserves selected targets across resume flows, uses explicit main files, and writes key configuration to the selected config.
SDK schemas and targeted configuration operations
cli/src/schemas/sdk.ts, cli/src/sdk.ts
Adds capacitorConfig to SDK option schemas and scopes bundle, key, and app-setting operations to resolved config targets.
MCP target lifecycle and onboarding
cli/src/mcp/server.ts, cli/src/init/mcp/*, cli/src/schemas/live-update-onboarding.ts
MCP applies and restores config targets across server and onboarding flows, with typed inputs and config-scoped sessions and progress.
Validation, scripts, and documentation
cli/test/*, cli/package.json, cli/webdocs/*, cli/skills/*, cli/README.md
Tests cover init, CLI, SDK, MCP, and target persistence; scripts and documentation describe the new options and behavior.

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

Suggested labels: codex

Suggested reviewers: dalanir, wcaleniewolny

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title is related, but it narrows the change to init while the PR mainly adds scoped --capacitor-config targeting across CLI and MCP.
Description check ✅ Passed The description includes the required Summary, Test plan, Screenshots, and Checklist sections with concrete validation details.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@codspeed-hq

codspeed-hq Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing codex/init-monorepo-targeting (000706d) with main (eb19148)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@riderx
riderx marked this pull request as ready for review July 14, 2026 13:02
@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_6af7b250-9c11-4924-93b2-fcc41a1cef37)

@cursor
cursor Bot requested review from Dalanir and WcaleNieWolny July 14, 2026 13:03

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

Stale comment

Risk: low. Not approving because Cursor Bugbot did not complete successfully (usage limit reached), so automated review is incomplete. Human review is needed; reviewers assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@coderabbitai coderabbitai Bot added the codex label Jul 14, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 3

🤖 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 `@cli/src/init/command.ts`:
- Around line 4560-4575: Preserve the explicit package target through the resume
fallback: update the state flow around globalPathToPackageJson and
discardResumedState() so discarding stale resume data cannot clear the
user-provided package JSON path while the capacitor config, main file, and
config write target remain selected. Reapply or store the explicit target
separately after discardResumedState() before installation/versioning continues.
- Around line 122-129: Update resolveInitTargetPath to validate that the
resolved path is a regular file, not merely an existing path: use
statSync(resolved).isFile() alongside the existing existence check, and throw
the same labeled validation error when the target is missing or a directory.
- Around line 2559-2563: Update the main-file selection and injection flow
around mainFilePath so an explicit globalMainFilePath (--main-file) is honored
for Nuxt projects before the Nuxt-specific plugins/capacitorUpdater.client.*
path runs. Route the explicit target through the existing injection logic, or
explicitly reject the option for Nuxt; do not silently modify the default Nuxt
plugin when a target was provided.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6be38093-c690-4261-821e-78457ec44ec4

📥 Commits

Reviewing files that changed from the base of the PR and between 1145e26 and 4113d90.

📒 Files selected for processing (6)
  • cli/package.json
  • cli/src/config/index.ts
  • cli/src/index.ts
  • cli/src/init/command.ts
  • cli/test/test-init-monorepo-targeting.mjs
  • cli/webdocs/init.mdx
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

Comment thread cli/src/init/command.ts
Comment thread cli/src/init/command.ts
Comment thread cli/src/init/command.ts Outdated
@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_a60c902c-6685-445c-9049-c3041dd0d538)

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

Stale comment

Risk: low. Not approving because Cursor Bugbot did not complete successfully (usage limit reached), so automated review is incomplete. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

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

Stale comment

Risk: medium. Not approving because Cursor Bugbot did not complete successfully (skipping/usage limit reached), so automated review remains incomplete. Human review is still needed; reviewers Dalanir and WcaleNieWolny are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

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

Stale comment

Risk: medium. Not approving: Cursor Bugbot was present but skipped (usage limit reached), so automated review did not complete. Human review is needed before merge.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@riderx
riderx marked this pull request as draft July 14, 2026 13:38
@riderx
riderx marked this pull request as ready for review July 14, 2026 14:24
@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_3d88ef05-24ae-406b-9b3b-2eaa940617b0)

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

Stale comment

Risk: medium. Not approving because Cursor Bugbot was present but skipped (usage limit reached), so automated review did not complete. Human review is still needed; reviewers Dalanir and WcaleNieWolny are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

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

Stale comment

Risk: medium. Not approving because Cursor Bugbot was present but skipped (usage limit reached), so automated review did not complete. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 4

🤖 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 `@cli/src/mcp/server.ts`:
- Around line 40-42: The startup failure boundary in startMcpServer must cover
all work after setConfigWriteTarget, including stdout setup, SDK initialization,
tool registration, onboarding registration, and server.connect. Add or reuse an
idempotent config-target restore helper, invoking it from both the server
onclose handler and catch, so every failure restores previousConfigWriteTarget
exactly once.

In `@cli/src/schemas/live-update-onboarding.ts`:
- Around line 4-6: Update liveUpdateStartSchema’s capacitorConfig validation to
reject empty strings while continuing to allow the field to be omitted. Use the
schema-level non-empty string constraint so the onboarding handler cannot
receive a value that resolves to undefined and clears the existing server
target.

In `@cli/webdocs/mcp.mdx`:
- Around line 29-40: The “Available tools exposed via MCP” section is
incomplete. Update the list to include capgo_probe, capgo_login, capgo_whoami,
capgo_logout, and the gated onboarding tools exposed by the MCP server, or
explicitly label the section as a subset if it is intentionally non-exhaustive.
- Around line 26-28: Remove the duplicated monorepo explanation in the MCP
documentation, retaining a single copy of the two sentences about the active
root config and live-update onboarding’s capacitorConfig behavior.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 807ba88f-f6c5-47c4-8c65-2c079be286a4

📥 Commits

Reviewing files that changed from the base of the PR and between a4f8f92 and 304ee4c.

📒 Files selected for processing (18)
  • cli/package.json
  • cli/skills/release-management/SKILL.md
  • cli/skills/usage/SKILL.md
  • cli/src/bundle/upload.ts
  • cli/src/config/index.ts
  • cli/src/index.ts
  • cli/src/init/command.ts
  • cli/src/init/mcp/live-update-tools.ts
  • cli/src/mcp/server.ts
  • cli/src/schemas/live-update-onboarding.ts
  • cli/test/test-capacitor-config-target.mjs
  • cli/test/test-mcp-live-update-onboarding.mjs
  • cli/webdocs/app.mdx
  • cli/webdocs/bundle.mdx
  • cli/webdocs/init.mdx
  • cli/webdocs/key.mdx
  • cli/webdocs/mcp.mdx
  • cli/webdocs/notifications.mdx
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

Comment thread cli/src/mcp/server.ts
Comment thread cli/src/schemas/live-update-onboarding.ts
Comment thread cli/webdocs/mcp.mdx Outdated
Comment thread cli/webdocs/mcp.mdx Outdated
@riderx
riderx marked this pull request as draft July 14, 2026 14:45
@riderx
riderx force-pushed the codex/init-monorepo-targeting branch from 304ee4c to 81d6944 Compare July 14, 2026 15:41
@riderx
riderx marked this pull request as ready for review July 14, 2026 23:28
@riderx

riderx commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor
✅ 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.

Comment thread cli/src/init/mcp/live-update-tools.ts
Comment thread cli/src/init/mcp/engine.ts

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

Stale comment

Risk: medium. Not approving: Cursor Bugbot completed as skipped and reported 2 unresolved findings on the latest commit. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

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

Risk: medium. Not approving because Cursor Bugbot completed as skipped and reported 2 unresolved medium-severity findings. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 3

🤖 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 `@cli/src/config/index.ts`:
- Around line 66-73: Update loadConfig so it always obtains the general read
configuration through the root loadConfigCap() flow, preserving dynamic
selectors, shared defaults, and root-level merging. Use a separate
target-snapshot loader only when preparing the write target returned in config,
rather than having getConfigWriteTarget cause direct loadConfigTarget evaluation
for ordinary reads.

In `@cli/src/init/command.ts`:
- Around line 149-177: Update resolveResumedInitTargets to reject stale resumes
when any persisted target cannot be restored: do not swallow failures from
resolveInitTargetPath, resolveCapacitorConfigTargetPath,
resolveInitDirectoryPath, or main-file validation, and signal that the saved
resume is invalid so onboarding restarts safely instead of returning partial
targets. Preserve successful restoration of all valid targets.
- Around line 4815-4822: Update discardResumedState to invalidate or recompute
all derived project state after clearing the resumed targets, including
selectedProjectDir, extConfig, localConfig, and the local appId. Prefer moving
resume rejection before these values are read; otherwise reload them from
initialTargets so later platform, build, and update steps use current project
data.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 41690505-4eee-4f4a-a422-95c2806d0c07

📥 Commits

Reviewing files that changed from the base of the PR and between 81d6944 and 41822bf.

📒 Files selected for processing (17)
  • cli/README.md
  • cli/src/capacitor-cli.ts
  • cli/src/config/index.ts
  • cli/src/init/command.ts
  • cli/src/init/mcp/engine.ts
  • cli/src/init/mcp/live-update-tools.ts
  • cli/src/init/mcp/progress.ts
  • cli/src/init/mcp/session-state.ts
  • cli/src/key.ts
  • cli/src/mcp/server.ts
  • cli/src/schemas/live-update-onboarding.ts
  • cli/src/schemas/sdk.ts
  • cli/src/sdk.ts
  • cli/test/test-capacitor-config-target.mjs
  • cli/test/test-init-monorepo-targeting.mjs
  • cli/test/test-mcp-live-update-onboarding.mjs
  • cli/webdocs/mcp.mdx
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

Comment thread cli/src/config/index.ts
Comment thread cli/src/init/command.ts Outdated
Comment thread cli/src/init/command.ts Outdated
@riderx
riderx marked this pull request as draft July 14, 2026 23:38
@riderx
riderx marked this pull request as ready for review July 15, 2026 00:17

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

Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 00a807f. Configure here.

Comment thread cli/src/init/mcp/live-update-tools.ts
Comment thread cli/src/init/command.ts
Comment thread cli/src/config/index.ts Outdated
Comment thread cli/src/init/command.ts

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

Stale comment

Risk: medium. Not approving because Cursor Bugbot completed as skipped (usage limit reached) and reported unresolved findings on the latest commit. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

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

Risk: medium. Not approving because Cursor Bugbot completed as skipped and reported 3 unresolved findings on the latest commit. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@cursor

cursor Bot commented Jul 15, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_38715cbc-ffaa-482e-8489-452487411359)

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

Risk: medium. Not approving because Cursor Bugbot completed as skipped (usage limit reached) on the latest commit, and there is 1 unresolved Bugbot finding plus prior unresolved review signal. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

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

Risk: medium. Not approving because Cursor Bugbot completed as skipped on this commit and there is 1 unresolved finding. Human review is still needed; Dalanir and WcaleNieWolny are already assigned as reviewers.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@sonarqubecloud

Copy link
Copy Markdown

@riderx
riderx merged commit b150144 into main Jul 15, 2026
46 of 64 checks passed
@riderx
riderx deleted the codex/init-monorepo-targeting branch July 15, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant