Skip to content

Commit dd0845d

Browse files
committed
refactor(config): skip agent setup when instruction files exist
Align `vp config` agent setup with `vp create`/`vp migrate`: - Skip agent setup entirely when agent instruction files already exist - Skip agent setup in non-interactive mode (no silent writes) - Use shared multiselect prompt and writeAgentInstructions() flow - Remove config-specific agent detection, MCP config, and skills linking - Delete config/agent.ts and its tests (superseded by utils/agent.ts)
1 parent fb7cc34 commit dd0845d

4 files changed

Lines changed: 30 additions & 320 deletions

File tree

packages/cli/src/config/__tests__/agent.spec.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.

packages/cli/src/config/agent.ts

Lines changed: 0 additions & 205 deletions
This file was deleted.

packages/cli/src/config/bin.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
// Unified `vp config` command — merges the old `vp prepare` (hooks setup) and
22
// `vp init` (agent integration) into a single entry point.
33
//
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.
67

78
import { existsSync } from 'node:fs';
89
import { join } from 'node:path';
910

1011
import mri from 'mri';
1112

1213
import { vitePlusHeader } from '../../binding/index.js';
14+
import {
15+
detectExistingAgentTargetPaths,
16+
selectAgentTargetPaths,
17+
writeAgentInstructions,
18+
} from '../utils/agent.js';
1319
import { renderCliDoc } from '../utils/help.js';
1420
import { defaultInteractive, promptGitHooks } from '../utils/prompts.js';
15-
import { linkSkillsForSpecificAgents } from '../utils/skills.js';
1621
import { log } from '../utils/terminal.js';
17-
import {
18-
resolveAgentSetup,
19-
hasExistingAgentInstructions,
20-
injectAgentBlock,
21-
setupMcpConfig,
22-
} from './agent.js';
2322
import { install } from './hooks.js';
2423

2524
async function main() {
@@ -81,15 +80,26 @@ async function main() {
8180
}
8281
}
8382

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+
});
8895

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+
}
93103
}
94104
}
95105
}

rfcs/config-and-staged-commands.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ Behavior:
100100
1. Built-in husky-compatible install logic (reimplementation of husky v9, not a bundled dependency)
101101
2. Sets `core.hooksPath` to `<hooks-dir>/_` (default: `.vite-hooks/_`)
102102
3. Creates hook scripts in `<hooks-dir>/_/` that source the user-defined hooks in `<hooks-dir>/`
103-
4. Agent integration: injects agent instructions and MCP config (skipped during `prepare` lifecycle — see point 9)
103+
4. Agent integration (interactive only): writes agent instructions to selected instruction files (aligned with `vp create`/`vp migrate`). Skipped entirely if agent instruction files already exist — never modifies user-maintained files.
104104
5. Safe to run multiple times (idempotent)
105105
6. Exits 0 and skips hooks if `VITE_GIT_HOOKS=0` or `HUSKY=0` environment variable is set (backwards compatible)
106106
7. Exits 0 and skips hooks if `.git` directory doesn't exist (safe during `npm install` in consumer projects)
107107
8. Exits 1 on real errors (git command not found, `git config` failed)
108108
9. `prepare` lifecycle detection: when `npm_lifecycle_event=prepare`, agent setup is skipped. This ensures `"prepare": "vp config"` only installs hooks during install — agent setup is handled by `vp create`/`vp migrate`
109-
10. Interactive mode: prompts on first run for hooks and agent setup; updates silently on subsequent runs
110-
11. Non-interactive mode: runs everything by default
109+
10. Interactive mode: prompts on first run for hooks; prompts for agent setup only if no agent instruction files exist (multiselect prompt, same as `vp create`/`vp migrate`). Skips agent setup silently if files already exist.
110+
11. Non-interactive mode: sets up hooks by default; skips agent setup entirely (no silent writes without user consent)
111111

112112
### `vp staged`
113113

0 commit comments

Comments
 (0)