viepilot 3.9.1 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -9,6 +9,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ---
11
11
 
12
+ ## [3.11.0] - 2026-05-25
13
+
14
+ ### Added
15
+ - ENH-100: New `/vp-qa` skill — scan-first QA agent team generator
16
+ - ENH-100: Phase 1 (Research) reads codebase structure, detects stack, samples source files,
17
+ reads stack reference docs, then LLM decides domains + agent count
18
+ - ENH-100: Phase 2 (Generate) — LLM writes agent files directly using Write tool;
19
+ content fully determined by research output (no templates)
20
+ - ENH-100: Adapter-specific output — Claude Code: `.claude/agents/` (multi-agent
21
+ orchestrator + subagents); Codex: `AGENTS.md` append; Cursor: `.cursor/rules/` MDC;
22
+ Antigravity: `.agents/skills/`; Copilot: `.github/agents/`
23
+ - ENH-100: `lib/qa-router.cjs` — adapter path mapping (resolveOutputSpec, expectedPaths)
24
+ - ENH-100: `agents/qa-templates/rules/` — stack reference docs for Node.js, Python,
25
+ Java, Go, Ruby (LLM reads during research phase for stack-specific anti-patterns)
26
+ - ENH-100: Generated `qa-orchestrator` creates `.viepilot/requests/BUG-{N}.md` entries
27
+ with AskUserQuestion accept/decline + `/vp-evolve` suggestion
28
+
29
+ ---
30
+
31
+ ## [3.10.0] - 2026-05-25
32
+
33
+ ### Added
34
+ - ENH-101: `vp-crystallize` now generates adapter-specific AI context files at Step 1F
35
+ - ENH-101: New `vp-tools context-files` subcommand generates CLAUDE.md (Claude Code),
36
+ GEMINI.md (Antigravity), AGENTS.md (Codex), .cursorrules + .cursor/rules/ (Cursor),
37
+ .github/copilot-instructions.md (Copilot) from `.viepilot/` sources
38
+ - ENH-101: `--all` flag generates all 5 adapter files simultaneously
39
+ - ENH-101: Content sourced from AI-GUIDE.md, PROJECT-CONTEXT.md, SYSTEM-RULES.md, STACKS.md
40
+
41
+ ---
42
+
12
43
  ## [3.9.1] - 2026-05-25
13
44
 
14
45
  ### Fixed
package/bin/vp-tools.cjs CHANGED
@@ -1210,6 +1210,44 @@ ${colors.cyan}Examples:${colors.reset}
1210
1210
  });
1211
1211
  },
1212
1212
 
1213
+ /**
1214
+ * ENH-101: Generate adapter context files (CLAUDE.md, GEMINI.md, AGENTS.md, .cursorrules, .github/copilot-instructions.md)
1215
+ * Usage: vp-tools context-files [--all]
1216
+ */
1217
+ 'context-files': (args) => {
1218
+ const { generateAll, generateClaudeMd, generateGeminiMd, generateAgentsMd,
1219
+ generateCursorRules, generateCursorMdc, generateCopilotInstructions }
1220
+ = require('../lib/context-file-generators.cjs');
1221
+ const allFlag = args.includes('--all');
1222
+ const projectRoot = process.cwd();
1223
+
1224
+ // detect adapter
1225
+ const adapterCtx = require('../lib/adapter-context.cjs');
1226
+ const adapterId = adapterCtx.detectAdapter ? adapterCtx.detectAdapter() : 'claude-code';
1227
+
1228
+ const targets = allFlag ? generateAll(projectRoot) : (() => {
1229
+ const map = {
1230
+ 'claude-code': [{ path: 'CLAUDE.md', content: generateClaudeMd(projectRoot) }],
1231
+ 'antigravity': [{ path: 'GEMINI.md', content: generateGeminiMd(projectRoot) }],
1232
+ 'codex': [{ path: 'AGENTS.md', content: generateAgentsMd(projectRoot) }],
1233
+ 'cursor-agent': [
1234
+ { path: '.cursorrules', content: generateCursorRules(projectRoot) },
1235
+ { path: '.cursor/rules/viepilot-context.mdc', content: generateCursorMdc(projectRoot) },
1236
+ ],
1237
+ 'copilot': [{ path: '.github/copilot-instructions.md', content: generateCopilotInstructions(projectRoot) }],
1238
+ };
1239
+ return map[adapterId] || map['claude-code'];
1240
+ })();
1241
+
1242
+ for (const { path: relPath, content } of targets) {
1243
+ const absPath = require('path').join(projectRoot, relPath);
1244
+ require('fs').mkdirSync(require('path').dirname(absPath), { recursive: true });
1245
+ require('fs').writeFileSync(absPath, content, 'utf8');
1246
+ console.log(formatSuccess(`Written: ${relPath}`));
1247
+ }
1248
+ process.exit(0);
1249
+ },
1250
+
1213
1251
  /**
1214
1252
  * ENH-073: Manage cross-project personas.
1215
1253
  * persona get → print active persona JSON
@@ -1627,6 +1665,7 @@ ${colors.cyan}Commands:${colors.reset}
1627
1665
  ${colors.bold}get-registry${colors.reset} [--id <id>] Output global skill registry as JSON
1628
1666
  ${colors.bold}scan-skills${colors.reset} Scan installed skills → ~/.viepilot/skill-registry.json
1629
1667
  ${colors.bold}check-update${colors.reset} [--silent] Check for latest ViePilot version on npm (24h cached)
1668
+ ${colors.bold}context-files${colors.reset} [--all] Generate adapter context files (CLAUDE.md, GEMINI.md, etc.)
1630
1669
  ${colors.bold}persona${colors.reset} <op> Manage user personas (get|infer|list|set|auto-switch|context)
1631
1670
  ${colors.bold}detect-adapter${colors.reset} [--json] Detect active adapter (claude-code/cursor/antigravity/codex/copilot)
1632
1671
  ${colors.bold}validate${colors.reset} --adapter <id> Validate adapter capability requirements; exits 1 on critical gaps
@@ -0,0 +1,147 @@
1
+ 'use strict';
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ /**
6
+ * Read a .viepilot/ source file, return '' if missing.
7
+ */
8
+ function readSource(projectRoot, relPath) {
9
+ try {
10
+ return fs.readFileSync(path.join(projectRoot, relPath), 'utf8');
11
+ } catch { return ''; }
12
+ }
13
+
14
+ /**
15
+ * Build the shared core block used by all adapters.
16
+ * Sources: AI-GUIDE.md, PROJECT-CONTEXT.md, SYSTEM-RULES.md, STACKS.md
17
+ */
18
+ function buildCoreBlock(projectRoot) {
19
+ const meta = readSource(projectRoot, '.viepilot/PROJECT-META.md');
20
+ const guide = readSource(projectRoot, '.viepilot/AI-GUIDE.md');
21
+ const context = readSource(projectRoot, '.viepilot/PROJECT-CONTEXT.md');
22
+ const rules = readSource(projectRoot, '.viepilot/SYSTEM-RULES.md');
23
+ const stacks = readSource(projectRoot, '.viepilot/STACKS.md');
24
+
25
+ // Extract project name from PROJECT-META.md header or package.json
26
+ let projectName = 'Project';
27
+ const nameMatch = meta.match(/^#\s+(.+)/m);
28
+ if (nameMatch) projectName = nameMatch[1].trim();
29
+ else {
30
+ try {
31
+ projectName = require(path.join(projectRoot, 'package.json')).name || 'Project';
32
+ } catch { /* noop */ }
33
+ }
34
+
35
+ return { projectName, guide, context, rules, stacks };
36
+ }
37
+
38
+ /**
39
+ * CLAUDE.md — Claude Code context file (full Markdown, no frontmatter)
40
+ */
41
+ function generateClaudeMd(projectRoot) {
42
+ const { projectName, guide, context, rules, stacks } = buildCoreBlock(projectRoot);
43
+ const sections = [];
44
+ sections.push(`# ${projectName} — Claude Code Context\n`);
45
+ if (guide) sections.push(`## Navigation\n\n${guide}`);
46
+ if (context) sections.push(`## Domain Context\n\n${context}`);
47
+ if (rules) sections.push(`## Coding Standards\n\n${rules}`);
48
+ if (stacks) sections.push(`## Stack\n\n${stacks}`);
49
+ sections.push(`\n## ViePilot Workflow\n\n` +
50
+ `- Run \`/vp-auto\` to execute planned phases\n` +
51
+ `- Run \`/vp-request\` to log bugs or features\n` +
52
+ `- Current state: \`.viepilot/TRACKER.md\`\n`);
53
+ return sections.join('\n\n---\n\n');
54
+ }
55
+
56
+ /**
57
+ * GEMINI.md — Antigravity / Gemini CLI context file
58
+ */
59
+ function generateGeminiMd(projectRoot) {
60
+ // Same structure as CLAUDE.md; different header note
61
+ const content = generateClaudeMd(projectRoot);
62
+ return content.replace('Claude Code Context', 'Gemini / Antigravity Context');
63
+ }
64
+
65
+ /**
66
+ * AGENTS.md — Codex CLI context file
67
+ * Codex is patch-based + sequential; emphasize apply_patch conventions
68
+ */
69
+ function generateAgentsMd(projectRoot) {
70
+ const { projectName, context, rules, stacks } = buildCoreBlock(projectRoot);
71
+ const sections = [];
72
+ sections.push(`# ${projectName} — Codex Agent Instructions\n`);
73
+ sections.push(`## Conventions\n\n` +
74
+ `- Use \`apply_patch\` for all file edits\n` +
75
+ `- No interactive prompts — work sequentially\n` +
76
+ `- Commit after each logical unit\n`);
77
+ if (context) sections.push(`## Domain Context\n\n${context}`);
78
+ if (rules) sections.push(`## Coding Standards\n\n${rules}`);
79
+ if (stacks) sections.push(`## Stack\n\n${stacks}`);
80
+ sections.push(`\n## ViePilot\n\nPhase state: \`.viepilot/TRACKER.md\`\n`);
81
+ return sections.join('\n\n---\n\n');
82
+ }
83
+
84
+ /**
85
+ * .cursorrules — Cursor legacy flat-file format
86
+ */
87
+ function generateCursorRules(projectRoot) {
88
+ const { projectName, context, rules, stacks } = buildCoreBlock(projectRoot);
89
+ const parts = [`# ${projectName} — Cursor Rules\n`];
90
+ if (rules) parts.push(rules);
91
+ if (context) parts.push(`## Domain\n\n${context}`);
92
+ if (stacks) parts.push(`## Stack\n\n${stacks}`);
93
+ return parts.join('\n\n');
94
+ }
95
+
96
+ /**
97
+ * .cursor/rules/viepilot-context.mdc — Cursor new MDC format
98
+ */
99
+ function generateCursorMdc(projectRoot) {
100
+ const body = generateCursorRules(projectRoot)
101
+ .replace(/^# .+\n/, ''); // strip header — MDC description field covers it
102
+ const { projectName } = buildCoreBlock(projectRoot);
103
+ return `---
104
+ description: ${projectName} coding standards and architecture context
105
+ globs: ["**/*"]
106
+ alwaysApply: true
107
+ ---
108
+
109
+ ${body}`;
110
+ }
111
+
112
+ /**
113
+ * .github/copilot-instructions.md — GitHub Copilot
114
+ * Copilot has shorter context; be concise, focus on coding standards
115
+ */
116
+ function generateCopilotInstructions(projectRoot) {
117
+ const { projectName, rules, stacks } = buildCoreBlock(projectRoot);
118
+ const parts = [`# Copilot Instructions — ${projectName}\n`];
119
+ if (rules) parts.push(rules);
120
+ if (stacks) parts.push(`## Stack\n\n${stacks}`);
121
+ return parts.join('\n\n');
122
+ }
123
+
124
+ /**
125
+ * Generate all 5 adapter context files.
126
+ * Returns { path: string, content: string }[] — caller writes them.
127
+ */
128
+ function generateAll(projectRoot) {
129
+ return [
130
+ { path: 'CLAUDE.md', content: generateClaudeMd(projectRoot) },
131
+ { path: 'GEMINI.md', content: generateGeminiMd(projectRoot) },
132
+ { path: 'AGENTS.md', content: generateAgentsMd(projectRoot) },
133
+ { path: '.cursorrules', content: generateCursorRules(projectRoot) },
134
+ { path: '.cursor/rules/viepilot-context.mdc', content: generateCursorMdc(projectRoot) },
135
+ { path: '.github/copilot-instructions.md', content: generateCopilotInstructions(projectRoot) },
136
+ ];
137
+ }
138
+
139
+ module.exports = {
140
+ generateClaudeMd,
141
+ generateGeminiMd,
142
+ generateAgentsMd,
143
+ generateCursorRules,
144
+ generateCursorMdc,
145
+ generateCopilotInstructions,
146
+ generateAll,
147
+ };
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+ const path = require('path');
3
+
4
+ /**
5
+ * Resolve the output spec for QA agent files given an adapter.
6
+ *
7
+ * @param {string} adapterId - 'claude-code'|'cursor-agent'|'codex'|'antigravity'|'copilot'
8
+ * @param {string} projectRoot - Absolute path to the target project root
9
+ * @returns {object} outputSpec
10
+ */
11
+ function resolveOutputSpec(adapterId, projectRoot) {
12
+ switch (adapterId) {
13
+ case 'claude-code':
14
+ return {
15
+ mode: 'multi-file',
16
+ dir: path.join(projectRoot, '.claude', 'agents'),
17
+ orchestratorFile: 'qa-orchestrator.md',
18
+ subagentSuffix: '-scanner.md',
19
+ description: '.claude/agents/ (Claude Code native agents)',
20
+ };
21
+ case 'cursor-agent':
22
+ return {
23
+ mode: 'single-file',
24
+ dir: path.join(projectRoot, '.cursor', 'rules'),
25
+ file: 'qa-checklist.mdc',
26
+ frontmatterRequired: true,
27
+ description: '.cursor/rules/qa-checklist.mdc (Cursor MDC rule)',
28
+ };
29
+ case 'codex':
30
+ return {
31
+ mode: 'append',
32
+ dir: projectRoot,
33
+ file: 'AGENTS.md',
34
+ sectionHeader: '## QA Agent Instructions',
35
+ description: 'AGENTS.md (Codex system instructions)',
36
+ };
37
+ case 'antigravity':
38
+ return {
39
+ mode: 'multi-file',
40
+ dir: path.join(projectRoot, '.agents', 'skills'),
41
+ orchestratorFile: 'qa-orchestrator/SKILL.md',
42
+ description: '.agents/skills/ (Antigravity skills)',
43
+ };
44
+ case 'copilot':
45
+ return {
46
+ mode: 'single-file',
47
+ dir: path.join(projectRoot, '.github', 'agents'),
48
+ file: 'qa-orchestrator.agent.md',
49
+ description: '.github/agents/ (Copilot custom agent)',
50
+ };
51
+ default:
52
+ // Fallback to claude-code
53
+ return resolveOutputSpec('claude-code', projectRoot);
54
+ }
55
+ }
56
+
57
+ /**
58
+ * List the expected output file paths for a given adapter + domain list.
59
+ * Useful for pre-flight checks and test assertions.
60
+ */
61
+ function expectedPaths(adapterId, projectRoot, domains = []) {
62
+ const spec = resolveOutputSpec(adapterId, projectRoot);
63
+ if (spec.mode === 'multi-file') {
64
+ return [
65
+ path.join(spec.dir, spec.orchestratorFile),
66
+ ...domains.map(d => path.join(spec.dir, `qa-${d}${spec.subagentSuffix || '.md'}`)),
67
+ ];
68
+ }
69
+ return [path.join(spec.dir, spec.file)];
70
+ }
71
+
72
+ module.exports = { resolveOutputSpec, expectedPaths };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viepilot",
3
- "version": "3.9.1",
3
+ "version": "3.11.0",
4
4
  "description": "**Autonomous Vibe Coding Framework / Bộ khung phát triển tự động có kiểm soát**",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -0,0 +1,306 @@
1
+ ---
2
+ name: vp-qa
3
+ description: "LLM-driven QA agent team generator — research codebase, generate context-aware QA scanning agents"
4
+ version: 1.0.0
5
+ ---
6
+
7
+ <greeting>
8
+ ## Invocation Banner
9
+
10
+ Output this banner as the **first** thing on every invocation — before questions, work, or any other output:
11
+
12
+ ```
13
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
14
+ VIEPILOT ► VP-QA v1.0.0 (fw 2.19.0)
15
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
16
+ ```
17
+ </greeting>
18
+
19
+ <version_check>
20
+ ## Version Update Check (ENH-072)
21
+
22
+ After displaying the greeting banner, run:
23
+ ```bash
24
+ node "$HOME/.claude/viepilot/bin/vp-tools.cjs" check-update --silent
25
+ ```
26
+
27
+ **If exit code = 1** (update available — new version printed to stdout):
28
+ Display notice banner before any other output:
29
+ ```
30
+ ┌──────────────────────────────────────────────────────────────────┐
31
+ │ ✨ ViePilot {latest_version} available (installed: {current}) │
32
+ │ npm i -g viepilot && vp-tools install --target {adapter_id} │
33
+ └──────────────────────────────────────────────────────────────────┘
34
+ ```
35
+ Replace `{latest_version}` with stdout from the command, `{current}` with the installed
36
+ version, `{adapter_id}` with the active adapter (claude-code / cursor / antigravity / codex / copilot).
37
+
38
+ **If exit code = 0 or command unavailable**: silent, continue.
39
+
40
+ **Suppression rules:**
41
+ - `--no-update-check` flag on skill invocation → skip this step entirely
42
+ - `config.json` → `update.check: false` → skip this step entirely
43
+ - Show at most once per session (`update_check_done` session guard)
44
+ </version_check>
45
+
46
+ <persona_context>
47
+ ## Persona Context Injection (ENH-073)
48
+
49
+ At skill start, run:
50
+ ```bash
51
+ node "$HOME/.claude/viepilot/bin/vp-tools.cjs" persona auto-switch
52
+ node "$HOME/.claude/viepilot/bin/vp-tools.cjs" persona context
53
+ ```
54
+ Inject the output as `## User Persona` context before any task execution.
55
+ Silent if command unavailable or errors.
56
+ </persona_context>
57
+
58
+ <adapter id="claude-code">
59
+ ## A. Skill Invocation
60
+ - Skill được gọi khi user mention `vp-qa`, `/vp-qa`, "qa", "scan", "kiểm tra chất lượng"
61
+ - Treat all user text after the skill mention as `{{VP_ARGS}}`
62
+
63
+ ## B. User Prompting
64
+ Prompt user conversationally with numbered list options.
65
+
66
+ ## C. Tool Usage
67
+ Use Claude Code tools: `Bash` (shell), `Read` (file), `Edit` + `Write` (file write/patch),
68
+ `Grep` (search), `Glob` (file patterns), `LS`, `WebSearch`, `WebFetch`,
69
+ `Agent` (spawn subagent — multi-level nesting supported)
70
+ Interactive: `AskUserQuestion` (deferred — preload via ToolSearch before first call)
71
+
72
+ **Phase 1 research tools:**
73
+ - `Read` — parse .viepilot/PROJECT-META.md, STACKS.md, package.json, requirements.txt, etc.
74
+ - `Bash` — find backend directories, count files
75
+ - `Grep` — search for patterns in source code
76
+
77
+ **Phase 3 generation tools:**
78
+ - `Write` — create agent files directly (qa-orchestrator.md, qa-{domain}-scanner.md)
79
+ </adapter>
80
+
81
+ <adapter id="cursor-agent">
82
+ ## A. Skill Invocation
83
+ Same trigger keywords as claude-code adapter.
84
+
85
+ ## C. Tool Usage
86
+ Use Cursor tools: `run_terminal_cmd` (shell), `read_file` (read), `edit_file` (write/edit),
87
+ `grep_search` (search), `web_search`, `codebase_search`, `list_dir`, `file_search`
88
+ Interactive: text list fallback (AskQuestion available in Plan Mode only; Agent Mode = text)
89
+ Subagent: `/multitask` (user command, single-level only — not a callable tool)
90
+ MCP limit: 40 tools
91
+ </adapter>
92
+
93
+ <adapter id="antigravity">
94
+ ## A. Skill Invocation
95
+ Same trigger keywords as claude-code adapter.
96
+ Skill discovery: LLM-driven (automatic, no slash command needed).
97
+
98
+ ## C. Tool Usage
99
+ Use Antigravity tools: `shell` (cmd), `file_read`, `file_write`, MCP plugins
100
+ Interactive: text fallback (TUI-based; no formal AskUserQuestion)
101
+ Skill path: `.agents/skills/<skill>/SKILL.md` (project) or `~/.agents/skills/` (global)
102
+ </adapter>
103
+
104
+ <adapter id="codex">
105
+ ## A. Skill Invocation
106
+ Same trigger keywords as claude-code adapter.
107
+
108
+ ## C. Tool Usage
109
+ Use Codex tools: `container.exec` (sandboxed shell), `apply_patch` (file write), `web_search`
110
+ Interactive: text fallback (TUI Tab/Enter injection)
111
+ Config: `~/.codex/config.toml`
112
+ </adapter>
113
+
114
+ <adapter id="copilot">
115
+ ## A. Skill Invocation
116
+ Same trigger keywords as claude-code adapter.
117
+ Discovery: User-driven (`@agent-name` in GitHub Copilot Chat).
118
+
119
+ ## C. Tool Usage
120
+ Use Copilot tools: `runCommands` (shell), `read`/`readfile` (read), `edit`/`editFiles` (write),
121
+ `code_search`, `find_references`
122
+ Interactive: `askQuestions` (main agent only — NOT available in subagents; VS Code issue #293745)
123
+ Skill path: `.github/agents/<name>.agent.md`
124
+ </adapter>
125
+
126
+ <scope_policy>
127
+ ## ViePilot Namespace Guard (BUG-004)
128
+ - Default mode: only use and reference `vp-*` skills in ViePilot workflows.
129
+ - External skills (`non vp-*`) are out of framework scope unless user explicitly opts in.
130
+ - If external skills appear in runtime context, ignore them and route with the closest built-in `vp-*` skill.
131
+ </scope_policy>
132
+
133
+ <implementation_routing_guard>
134
+ ## Primary implementation lane (ENH-021)
135
+
136
+ - **`/vp-qa`** generates context-aware QA scanning agents for the current project.
137
+ - Output location determined by adapter via `lib/qa-router.cjs`.
138
+ - Generated agents invoke `qa-orchestrator` (claude-code) or execute sequential scans (others).
139
+ </implementation_routing_guard>
140
+
141
+ <objective>
142
+ Generate a team of QA scanning agents tailored to the project's stack, structure, and detected patterns.
143
+
144
+ **LLM-generates-directly approach:**
145
+ - Phase 1: LLM researches target codebase structure, stack, patterns, existing issues
146
+ - Phase 2: LLM determines output location via adapter routing (lib/qa-router.cjs)
147
+ - Phase 3: LLM writes agent files directly using Write tool (no template system)
148
+ - Phase 4: Show generated files and offer to run qa-orchestrator immediately (claude-code only)
149
+
150
+ **No templates:** Each agent's content is fully determined by research output. LLM tailors
151
+ scanning instructions to detected backend dirs, framework patterns, and known issues from `.viepilot/requests/`.
152
+
153
+ **After generation:** Generated agents (`qa-orchestrator` on claude-code or combined scanner on others)
154
+ will create `.viepilot/requests/BUG-{N}.md` for any QA issues found, and prompt user to accept/decline.
155
+ </objective>
156
+
157
+ <context>
158
+ Optional flags:
159
+ - `/vp-qa` — auto-detect adapter + stack, generate QA team
160
+ - `/vp-qa --run` — generate + immediately invoke qa-orchestrator
161
+ - `/vp-qa --focus sec` — bias research toward security domains
162
+ - `/vp-qa --focus perf` — bias research toward performance domains
163
+ - `/vp-qa --target <id>` — override adapter detection (claude-code / cursor-agent / antigravity / codex / copilot)
164
+ </context>
165
+
166
+ <process>
167
+ ### Phase 1: Research (REQUIRED — do not skip)
168
+
169
+ Before writing any agent file, understand the project:
170
+
171
+ 1. Read `.viepilot/PROJECT-META.md`, `STACKS.md`, `PROJECT-CONTEXT.md` (silent if missing)
172
+ 2. Detect stack from: `package.json` / `pom.xml` / `go.mod` / `requirements.txt` / `Gemfile`
173
+ 3. List backend directory structure: find `src/` `app/` `lib/` `services/` `api/` `routes/` (whichever exist)
174
+ 4. Read 5-10 representative source files from backend dirs (understand patterns)
175
+ 5. Count file sizes, service count, DB layer presence
176
+ 6. Read `.viepilot/requests/` to list known existing issues (avoid duplicate reporting)
177
+ 7. Read `agents/qa-templates/rules/{stack}.md` from project lib (if exists) for stack-specific patterns
178
+
179
+ **Build research summary:**
180
+ ```
181
+ - projectName: string
182
+ - stack: (node / python / java / go / ruby / etc.)
183
+ - stackVersion: string (from version file)
184
+ - backendDirs: string[] (actual dirs found in project)
185
+ - detectedPatterns: string[] (anti-patterns spotted in sampling)
186
+ - recommendedDomains: string[] (scan areas relevant to this project)
187
+ - recommendedAgentCount: number (2 for small, 4-5 for large/complex)
188
+ - knownIssues: string[] (from .viepilot/requests/, avoid duplicates)
189
+ ```
190
+
191
+ ### Phase 2: Determine Output Location
192
+
193
+ Use `lib/qa-router.cjs` to resolve adapter-specific output paths:
194
+ ```
195
+ - claude-code → .claude/agents/
196
+ - cursor-agent → .cursor/rules/
197
+ - codex → AGENTS.md (single file, append mode)
198
+ - antigravity → .agents/skills/
199
+ - copilot → .github/agents/
200
+ ```
201
+
202
+ Call or reference lib/qa-router.cjs to map the current adapter to output directory.
203
+
204
+ ### Phase 3: Generate Agent Files (LLM writes directly)
205
+
206
+ Based on research summary, generate agent content and write using Write tool.
207
+
208
+ **For claude-code (multi-agent):**
209
+ - Write `qa-orchestrator.md` — orchestrator that fan-outs to specialist subagents
210
+ - Name: "vp-qa orchestrator"
211
+ - Description: "Coordinate QA scanning across multiple domains for {projectName}"
212
+ - Model: claude-opus (or latest)
213
+ - maxTurns: 30
214
+ - Knows about backend dirs found, stack version, patterns to look for
215
+ - References each specialist subagent by name
216
+ - Receives domain reports, groups by severity
217
+ - Creates `.viepilot/requests/BUG-{N}.md` for accepted issues
218
+ - Uses AskUserQuestion for critical/high severity group acceptance
219
+ - Final AskUserQuestion: "N issues logged. Run /vp-evolve to plan fixes?"
220
+
221
+ - Write `qa-{domain}-scanner.md` for each recommended domain (e.g., qa-security-scanner, qa-performance-scanner)
222
+ - Name: "vp-qa {domain} scanner"
223
+ - Description: "Scan {projectName} for {domain} concerns"
224
+ - Model: claude-haiku-4 (efficient)
225
+ - maxTurns: 15
226
+ - Content references ACTUAL backend dirs found, ACTUAL patterns to look for
227
+ - Produces structured report of issues found in that domain
228
+ - Returns report to orchestrator
229
+
230
+ - Each file has correct YAML frontmatter (name, description, model, maxTurns, tools)
231
+ - Content NOT generic — references specific dirs, patterns, concerns found during Phase 1
232
+
233
+ **For other adapters (single-file mode):**
234
+ - Write one combined file with all domain instructions
235
+ - Sequential scanning procedure using that adapter's shell tools
236
+ - Same vp-request output format (BUG-{N}.md files)
237
+ - Single AskUserQuestion for all issues found at end
238
+
239
+ ### Phase 4: AskUserQuestion (claude-code only)
240
+
241
+ After writing files, show what was generated:
242
+ ```
243
+ Generated {N} agent files in {output_dir}:
244
+ - qa-orchestrator.md (coordinates scanning across domains)
245
+ - qa-security-scanner.md (scans for security concerns)
246
+ - qa-performance-scanner.md (scans for performance concerns)
247
+ ... (other domain files)
248
+ ```
249
+
250
+ **AskUserQuestion:**
251
+ ```
252
+ question: "What would you like to do next?"
253
+ options:
254
+ - label: "Run QA scan now"
255
+ description: "Invoke qa-orchestrator immediately to start scanning"
256
+ - label: "Done for now"
257
+ description: "Exit — agents are ready in {output_dir}"
258
+ ```
259
+
260
+ **On selection:**
261
+ - "Run QA scan now": invoke qa-orchestrator immediately (or equivalent for non-claude-code adapters)
262
+ - "Done for now": print "QA agents ready in {output_dir}. Run qa-orchestrator to start scanning." and exit
263
+
264
+ **Text fallback (Cursor/Codex/Copilot/Antigravity):**
265
+ ```
266
+ QA agents generated in {output_dir}
267
+
268
+ Next actions:
269
+ 1. Review generated agent files
270
+ 2. Run qa-orchestrator to start the QA scan
271
+ 3. Adjust scanning domains as needed
272
+ ```
273
+
274
+ ### Generated qa-orchestrator Behavior (in target project, when run)
275
+
276
+ When user runs the generated `qa-orchestrator`:
277
+ 1. Fan out to specialist subagents (claude-code) or scan sequentially (others)
278
+ 2. Collect issue reports from each domain scanner
279
+ 3. Group issues by severity (critical/high/medium/low)
280
+ 4. For critical/high: AskUserQuestion per group (accept → create vp-request BUG-{N}, decline → skip)
281
+ 5. For medium/low: one batch confirm
282
+ 6. Create `.viepilot/requests/BUG-{N}.md` for each accepted issue
283
+ 7. Final AskUserQuestion: "N issues logged. Run /vp-evolve to plan fixes?"
284
+ </process>
285
+
286
+ ## Adapter Compatibility
287
+
288
+ ### AskUserQuestion Tool (ENH-059)
289
+ After generation, use `AskUserQuestion` on Claude Code (terminal) for Phase 4 prompt.
290
+
291
+ | Adapter | Interactive Prompts | Notes |
292
+ |---------|---------------------|-------|
293
+ | Claude Code (terminal) | ✅ `AskUserQuestion` — **REQUIRED** at end of Phase 3 | Preload schema via ToolSearch first |
294
+ | Cursor / Codex / Copilot / Antigravity | ❌ Text fallback | Plain numbered list for next actions |
295
+
296
+ **Claude Code (terminal) — AUQ preload required (ENH-059):**
297
+ Before the first interactive prompt (Phase 4), call `ToolSearch` with `query: "select:AskUserQuestion"` to load the deferred tool schema. Only after `ToolSearch` succeeds can `AskUserQuestion` be invoked. If `ToolSearch` returns an error, fall back to plain-text numbered list for that session.
298
+
299
+ <success_criteria>
300
+ - [ ] Phase 1 research completed (read project structure, stack, patterns)
301
+ - [ ] Phase 2 output location determined via lib/qa-router.cjs
302
+ - [ ] Phase 3 agent files written using Write tool (content tailored to research output)
303
+ - [ ] Phase 4 AskUserQuestion shown (claude-code) or text fallback (others)
304
+ - [ ] Generated agents ready to execute qa-orchestrator
305
+ - [ ] Generated qa-orchestrator creates .viepilot/requests/BUG-{N}.md for found issues
306
+ </success_criteria>
@@ -2172,8 +2172,40 @@ Append to `.viepilot/PROJECT-CONTEXT.md`:
2172
2172
  **Lock semantics**: once written, `## Skills` is the authoritative skill decision for the project. `vp-auto` reads it and **never re-prompts**.
2173
2173
  </step>
2174
2174
 
2175
+ <step name="adapter_context_files">
2176
+ ## Step 1F: Generate Adapter Context Files (ENH-101)
2177
+
2178
+ Generate the native AI context file for the active adapter so it starts with full project context.
2179
+
2180
+ **Detect adapter and generate:**
2181
+ ```bash
2182
+ node bin/vp-tools.cjs context-files
2183
+ # or with --all to generate all 5 adapters at once:
2184
+ node bin/vp-tools.cjs context-files --all
2185
+ ```
2186
+
2187
+ **What gets generated:**
2188
+ | Adapter | File |
2189
+ |---------|------|
2190
+ | Claude Code | `CLAUDE.md` (project root) |
2191
+ | Cursor | `.cursorrules` + `.cursor/rules/viepilot-context.mdc` |
2192
+ | Codex | `AGENTS.md` (project root) |
2193
+ | Antigravity | `GEMINI.md` (project root) |
2194
+ | GitHub Copilot | `.github/copilot-instructions.md` |
2195
+
2196
+ **Content sources** (from `.viepilot/` — skip if not yet generated):
2197
+ - `AI-GUIDE.md` → navigation + architecture summary
2198
+ - `PROJECT-CONTEXT.md` → domain knowledge, business rules
2199
+ - `SYSTEM-RULES.md` → coding standards, patterns
2200
+ - `STACKS.md` → tech stack, versions
2201
+
2202
+ **Note**: Re-running overwrites existing files with latest `.viepilot/` content.
2203
+ Step 1F is non-blocking — if `.viepilot/` sources are incomplete, outputs a partial file
2204
+ with a `<!-- viepilot: incomplete -->` comment at the top as a re-run reminder.
2205
+ </step>
2206
+
2175
2207
  <step name="cross_reference_gate">
2176
- ## Step 1F: Cross-Reference Gate (ENH-064)
2208
+ ## Step 1G: Cross-Reference Gate (ENH-064)
2177
2209
 
2178
2210
  Run when BOTH `architect_read_complete: true` AND `ui_direction_read_complete: true` are set in working notes:
2179
2211
 
@@ -2208,9 +2240,9 @@ Run when BOTH `architect_read_complete: true` AND `ui_direction_read_complete: t
2208
2240
  <step name="stakeholder_review_gate">
2209
2241
  ---
2210
2242
 
2211
- ## Step 1G: Stakeholder Review Gate (ENH-098)
2243
+ ## Step 1H: Stakeholder Review Gate (ENH-098)
2212
2244
 
2213
- **Trigger**: Runs automatically after Step 1F, before Step 2.
2245
+ **Trigger**: Runs automatically after Step 1G, before Step 2.
2214
2246
 
2215
2247
  **Skip conditions**:
2216
2248
  - `--no-stakeholders` flag passed to `/vp-crystallize`