Skip to content

feat(init): bridge to APM during init for cross-team distribution#94

Merged
danielmeppiel merged 1 commit intomicrosoft:mainfrom
danielmeppiel:feat/apm-init-bridge
Mar 31, 2026
Merged

feat(init): bridge to APM during init for cross-team distribution#94
danielmeppiel merged 1 commit intomicrosoft:mainfrom
danielmeppiel:feat/apm-init-bridge

Conversation

@danielmeppiel
Copy link
Copy Markdown
Contributor

@danielmeppiel danielmeppiel commented Mar 31, 2026

Summary

After generating instructions and configs, agentrc init now detects APM and bridges to it — enabling cross-team distribution of agent packages via apm install.

Closes #93
Part of #96

Behavior

APM state Interactive mode --yes (headless)
apm installed + no apm.yml Prompt: "Set up APM?" → apm init --yes Auto-runs apm init --yes (yes to everything)
apm installed + apm.yml exists Skip Skip
apm not installed Tip: "use APM to install shared agent packages..." Skip (quiet)
--json Skip Skip

--yes includes APM when installed — consistent with its "accept all defaults" semantic (same as npm init --yes). If APM is not installed, --yes silently skips.

Design

  • Delegation: agentrc never writes apm.yml — shells out to apm init --yes
  • Same I/O pattern: uses @inquirer/prompts confirm(), same as existing init prompts
  • 10s timeout on all subprocess calls; graceful failure with Warning: prefix
  • Respects flags: --json skips entirely, --quiet suppresses tip

Changes

  • src/commands/init.ts — APM detection, conditional prompt/auto-init, tip message (+62 lines)
  • src/services/__tests__/apm-init.test.ts — 7 unit tests covering all paths (new file)

Copilot AI review requested due to automatic review settings March 31, 2026 11:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an APM “bridge” to agentrc init so that, after scaffolding instructions/configs, the command can detect APM and optionally run apm init --yes to enable cross-team distribution via apm install.

Changes:

  • Detects whether apm is available and whether apm.yml already exists.
  • In interactive mode, prompts to initialize APM and shells out to apm init --yes.
  • When APM isn’t installed, prints an informational tip (subject to logging flags).

Comment thread src/commands/init.ts Outdated
Comment thread src/commands/init.ts
Comment thread src/commands/init.ts Outdated
Copilot AI review requested due to automatic review settings March 31, 2026 12:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread src/commands/init.ts Outdated
Comment thread src/commands/init.ts Outdated
@danielmeppiel danielmeppiel force-pushed the feat/apm-init-bridge branch 2 times, most recently from 3dc9b87 to 8492e8a Compare March 31, 2026 12:26
Copilot AI review requested due to automatic review settings March 31, 2026 12:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/commands/init.ts
@danielmeppiel
Copy link
Copy Markdown
Contributor Author

Part of epic #96

@danielmeppiel
Copy link
Copy Markdown
Contributor Author

Design question for @digitarald: Should --yes include APM initialization when apm is installed?

Currently --yes skips the APM step entirely (conservative: avoids running a third-party subprocess in automation). But --yes already auto-selects instructions + MCP + VS Code — the "set me up fully" semantic. And npm init --yes accepts everything, it does not skip features.

Option A (current): --yes skips APM — safe for CI, but users who want full setup still need interactive mode for APM.

Option B: --yes includes APM when apm is in PATH — consistent with "yes to everything" semantic. If APM is not installed, silently skip (no tip in headless mode).

I lean toward B but wanted your call since it means auto-running an external CLI in non-interactive mode.

After generating instructions and configs, agentrc init now detects APM
and offers to initialize it:

- APM installed + no apm.yml: interactive prompt to run `apm init --yes`
- APM installed + apm.yml exists: skip (already set up)
- APM not installed: light tip suggesting APM with link to repo
- --yes/--json mode: skip APM step entirely (non-interactive)

This respects tool boundaries — agentrc never writes apm.yml directly,
it delegates to `apm init` which handles auto-detection of project
metadata. The prompt follows the same @inquirer/prompts pattern already
used throughout the init command.

Closes microsoft#93

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 31, 2026 18:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/commands/init.ts:327

  • In the apm-not-installed branch, the tip is gated by shouldLog(options) but not by options.yes. Per the documented behavior, --yes/headless should skip quietly, so offerApmInit() should avoid emitting this tip when options.yes is true.
  } else if (shouldLog(options)) {
    process.stderr.write(
      "\nTip: use APM to install shared agent packages and distribute your instructions across repos.\n" +
        "     https://github.com/microsoft/apm\n"
    );

Comment thread src/commands/init.ts
Comment on lines +298 to +305
if (apmAvailable) {
const accepted = options.yes
? true
: await confirm({
message: "Set up APM to install and share agent packages across your team?",
default: false
});
if (accepted) {
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

offerApmInit() currently treats --yes as implicit acceptance (accepted = options.yes ? true : …), which causes agentrc init --yes to run apm init --yes. This conflicts with the documented behavior for --yes/headless mode (skip APM entirely) and introduces unexpected side effects in non-interactive runs. Consider returning early when options.yes is set so APM is neither prompted nor executed in headless mode.

This issue also appears on line 323 of the same file.

Copilot uses AI. Check for mistakes.
Comment on lines +56 to +61
it("auto-initializes APM when --yes is set and apm is installed", async () => {
mockApmInstalled();
await offerApmInit(repoPath, { yes: true });
expect(mockConfirm).not.toHaveBeenCalled();
expect(mockExecFile).toHaveBeenCalledTimes(2); // --version + init --yes
});
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

This test encodes behavior that contradicts the PR description: it expects --yes to auto-initialize APM when installed. The documented behavior says --yes/headless mode should skip APM entirely, so the expectation (and likely the implementation) should be updated accordingly.

Copilot uses AI. Check for mistakes.
@danielmeppiel danielmeppiel merged commit ac39cb4 into microsoft:main Mar 31, 2026
14 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.

feat(init): bridge to APM during init for cross-team distribution

2 participants