|
1 | 1 | // Unified `vp config` command — merges the old `vp prepare` (hooks setup) and |
2 | 2 | // `vp init` (agent integration) into a single entry point. |
3 | 3 | // |
4 | | -// Interactive mode (TTY, no CI): prompts on first run, updates silently after. |
5 | | -// Non-interactive mode (scripts.prepare, CI, piped): runs everything by default. |
| 4 | +// Interactive mode (TTY, no CI): prompts on first run; prompts for agent setup |
| 5 | +// only if no agent instruction files exist. |
| 6 | +// Non-interactive mode (scripts.prepare, CI, piped): hooks only, agent setup skipped. |
6 | 7 |
|
7 | 8 | import { existsSync } from 'node:fs'; |
8 | 9 | import { join } from 'node:path'; |
9 | 10 |
|
10 | 11 | import mri from 'mri'; |
11 | 12 |
|
12 | 13 | import { vitePlusHeader } from '../../binding/index.js'; |
| 14 | +import { |
| 15 | + detectExistingAgentTargetPaths, |
| 16 | + selectAgentTargetPaths, |
| 17 | + writeAgentInstructions, |
| 18 | +} from '../utils/agent.js'; |
13 | 19 | import { renderCliDoc } from '../utils/help.js'; |
14 | 20 | import { defaultInteractive, promptGitHooks } from '../utils/prompts.js'; |
15 | | -import { linkSkillsForSpecificAgents } from '../utils/skills.js'; |
16 | 21 | import { log } from '../utils/terminal.js'; |
17 | | -import { |
18 | | - resolveAgentSetup, |
19 | | - hasExistingAgentInstructions, |
20 | | - injectAgentBlock, |
21 | | - setupMcpConfig, |
22 | | -} from './agent.js'; |
23 | 22 | import { install } from './hooks.js'; |
24 | 23 |
|
25 | 24 | async function main() { |
@@ -81,15 +80,26 @@ async function main() { |
81 | 80 | } |
82 | 81 | } |
83 | 82 |
|
84 | | - // --- Step 2: Agent setup (skipped with --hooks-only or during prepare lifecycle) --- |
85 | | - if (!hooksOnly && process.env.npm_lifecycle_event !== 'prepare') { |
86 | | - const isFirstAgentRun = !hasExistingAgentInstructions(root); |
87 | | - const agentSetup = await resolveAgentSetup(root, interactive && isFirstAgentRun); |
| 83 | + // --- Step 2: Agent setup (interactive only, skipped if files exist / --hooks-only / prepare) --- |
| 84 | + if (!hooksOnly && interactive && process.env.npm_lifecycle_event !== 'prepare') { |
| 85 | + // Skip entirely if any agent instruction files already exist |
| 86 | + const existingAgentTargetPaths = detectExistingAgentTargetPaths(root); |
| 87 | + if (existingAgentTargetPaths === undefined) { |
| 88 | + // No existing agent files — prompt for selection |
| 89 | + const selectedAgentTargetPaths = await selectAgentTargetPaths({ |
| 90 | + interactive, |
| 91 | + onCancel: () => { |
| 92 | + process.exit(0); |
| 93 | + }, |
| 94 | + }); |
88 | 95 |
|
89 | | - injectAgentBlock(root, agentSetup.instructionFilePath); |
90 | | - setupMcpConfig(root, agentSetup.agents); |
91 | | - if (agentSetup.agents.length > 0) { |
92 | | - linkSkillsForSpecificAgents(root, agentSetup.agents); |
| 96 | + if (selectedAgentTargetPaths && selectedAgentTargetPaths.length > 0) { |
| 97 | + await writeAgentInstructions({ |
| 98 | + projectRoot: root, |
| 99 | + targetPaths: selectedAgentTargetPaths, |
| 100 | + interactive, |
| 101 | + }); |
| 102 | + } |
93 | 103 | } |
94 | 104 | } |
95 | 105 | } |
|
0 commit comments