@juicesharp/rpiv-pi 0.4.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/LICENSE +21 -0
- package/README.md +178 -0
- package/agents/codebase-analyzer.md +121 -0
- package/agents/codebase-locator.md +107 -0
- package/agents/codebase-pattern-finder.md +207 -0
- package/agents/integration-scanner.md +97 -0
- package/agents/precedent-locator.md +130 -0
- package/agents/test-case-locator.md +121 -0
- package/agents/thoughts-analyzer.md +147 -0
- package/agents/thoughts-locator.md +138 -0
- package/agents/web-search-researcher.md +107 -0
- package/extensions/rpiv-core/agents.ts +312 -0
- package/extensions/rpiv-core/git-context.ts +81 -0
- package/extensions/rpiv-core/guidance.ts +213 -0
- package/extensions/rpiv-core/index.ts +275 -0
- package/extensions/rpiv-core/package-checks.ts +51 -0
- package/package.json +36 -0
- package/scripts/migrate.js +242 -0
- package/scripts/types.js +1 -0
- package/skills/annotate-guidance/SKILL.md +303 -0
- package/skills/annotate-guidance/examples/root-dotnet-clean-arch.md +38 -0
- package/skills/annotate-guidance/examples/root-nodejs-monorepo.md +42 -0
- package/skills/annotate-guidance/examples/subfolder-database-layer.md +81 -0
- package/skills/annotate-guidance/examples/subfolder-dotnet-application.md +64 -0
- package/skills/annotate-guidance/examples/subfolder-schemas-layer.md +50 -0
- package/skills/annotate-guidance/templates/root-architecture.md +46 -0
- package/skills/annotate-guidance/templates/subfolder-architecture.md +57 -0
- package/skills/annotate-inline/SKILL.md +299 -0
- package/skills/annotate-inline/examples/root-dotnet-clean-arch.md +38 -0
- package/skills/annotate-inline/examples/root-nodejs-monorepo.md +42 -0
- package/skills/annotate-inline/examples/subfolder-database-layer.md +81 -0
- package/skills/annotate-inline/examples/subfolder-dotnet-application.md +64 -0
- package/skills/annotate-inline/examples/subfolder-schemas-layer.md +50 -0
- package/skills/annotate-inline/templates/root-claude-md.md +46 -0
- package/skills/annotate-inline/templates/subfolder-claude-md.md +57 -0
- package/skills/code-review/SKILL.md +184 -0
- package/skills/commit/SKILL.md +65 -0
- package/skills/create-handoff/SKILL.md +91 -0
- package/skills/design/SKILL.md +416 -0
- package/skills/discover/SKILL.md +242 -0
- package/skills/explore/SKILL.md +261 -0
- package/skills/implement/SKILL.md +74 -0
- package/skills/migrate-to-guidance/SKILL.md +88 -0
- package/skills/outline-test-cases/SKILL.md +348 -0
- package/skills/outline-test-cases/templates/feature-meta.md +43 -0
- package/skills/outline-test-cases/templates/outline-readme.md +36 -0
- package/skills/plan/SKILL.md +281 -0
- package/skills/research/SKILL.md +304 -0
- package/skills/resume-handoff/SKILL.md +207 -0
- package/skills/revise/SKILL.md +242 -0
- package/skills/validate/SKILL.md +175 -0
- package/skills/write-test-cases/SKILL.md +322 -0
- package/skills/write-test-cases/examples/customer-auth-flow.md +50 -0
- package/skills/write-test-cases/examples/order-management-suite.md +57 -0
- package/skills/write-test-cases/examples/order-placement-flow.md +54 -0
- package/skills/write-test-cases/examples/team-management-flow.md +56 -0
- package/skills/write-test-cases/examples/team-management-suite.md +54 -0
- package/skills/write-test-cases/templates/coverage-map.md +64 -0
- package/skills/write-test-cases/templates/regression-suite.md +63 -0
- package/skills/write-test-cases/templates/test-case.md +65 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, unlinkSync, readdirSync, statSync } from 'fs';
|
|
2
|
+
import { join, dirname, relative, sep } from 'path';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
// --- CLI Argument Parsing ---
|
|
5
|
+
function parseArgs(argv) {
|
|
6
|
+
let projectDir = process.cwd();
|
|
7
|
+
let deleteOriginals = false;
|
|
8
|
+
let dryRun = false;
|
|
9
|
+
let force = false;
|
|
10
|
+
for (let i = 2; i < argv.length; i++) {
|
|
11
|
+
if (argv[i] === '--project-dir' && argv[i + 1]) {
|
|
12
|
+
projectDir = argv[++i];
|
|
13
|
+
}
|
|
14
|
+
else if (argv[i] === '--delete-originals') {
|
|
15
|
+
deleteOriginals = true;
|
|
16
|
+
}
|
|
17
|
+
else if (argv[i] === '--dry-run') {
|
|
18
|
+
dryRun = true;
|
|
19
|
+
}
|
|
20
|
+
else if (argv[i] === '--force') {
|
|
21
|
+
force = true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return { projectDir, deleteOriginals, dryRun, force };
|
|
25
|
+
}
|
|
26
|
+
// --- Discovery ---
|
|
27
|
+
const HARDCODED_EXCLUDES = new Set([
|
|
28
|
+
'node_modules', 'dist', 'build', '.git', 'vendor', '.rpiv',
|
|
29
|
+
'.next', '.nuxt', '.output', 'coverage', '__pycache__', '.venv',
|
|
30
|
+
]);
|
|
31
|
+
function discoverClaudeMdFiles(projectDir) {
|
|
32
|
+
const gitDir = join(projectDir, '.git');
|
|
33
|
+
if (existsSync(gitDir)) {
|
|
34
|
+
return discoverViaGit(projectDir);
|
|
35
|
+
}
|
|
36
|
+
return discoverViaWalk(projectDir);
|
|
37
|
+
}
|
|
38
|
+
function discoverViaGit(projectDir) {
|
|
39
|
+
try {
|
|
40
|
+
const output = execSync('git ls-files --cached --others --exclude-standard', {
|
|
41
|
+
cwd: projectDir,
|
|
42
|
+
encoding: 'utf-8',
|
|
43
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
44
|
+
});
|
|
45
|
+
return output
|
|
46
|
+
.split('\n')
|
|
47
|
+
.filter((f) => f.endsWith('/CLAUDE.md') || f === 'CLAUDE.md')
|
|
48
|
+
.filter((f) => !f.startsWith('.rpiv/'));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// git command failed — fall back to walk
|
|
52
|
+
return discoverViaWalk(projectDir);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function discoverViaWalk(projectDir) {
|
|
56
|
+
const results = [];
|
|
57
|
+
function walk(dir) {
|
|
58
|
+
let entries;
|
|
59
|
+
try {
|
|
60
|
+
entries = readdirSync(dir);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return; // permission error, skip
|
|
64
|
+
}
|
|
65
|
+
for (const entry of entries) {
|
|
66
|
+
if (HARDCODED_EXCLUDES.has(entry))
|
|
67
|
+
continue;
|
|
68
|
+
const fullPath = join(dir, entry);
|
|
69
|
+
let stat;
|
|
70
|
+
try {
|
|
71
|
+
stat = statSync(fullPath);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (stat.isDirectory()) {
|
|
77
|
+
walk(fullPath);
|
|
78
|
+
}
|
|
79
|
+
else if (entry === 'CLAUDE.md') {
|
|
80
|
+
const rel = relative(projectDir, fullPath).split(sep).join('/');
|
|
81
|
+
if (!rel.startsWith('.rpiv/')) {
|
|
82
|
+
results.push(rel);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
walk(projectDir);
|
|
88
|
+
return results;
|
|
89
|
+
}
|
|
90
|
+
// --- Path Mapping ---
|
|
91
|
+
function computeTargetPath(claudeMdRelative) {
|
|
92
|
+
const dir = dirname(claudeMdRelative);
|
|
93
|
+
if (dir === '.') {
|
|
94
|
+
return '.rpiv/guidance/architecture.md';
|
|
95
|
+
}
|
|
96
|
+
return join('.rpiv', 'guidance', dir, 'architecture.md').split(sep).join('/');
|
|
97
|
+
}
|
|
98
|
+
function transformContent(content, targetPath) {
|
|
99
|
+
let refsTransformed = 0;
|
|
100
|
+
const warnings = [];
|
|
101
|
+
// Pattern 1: Backtick-wrapped path references like `src/core/CLAUDE.md`
|
|
102
|
+
let transformed = content.replace(/`((?:[\w][\w./-]*\/)?CLAUDE\.md)`/g, (_match, claudePath) => {
|
|
103
|
+
const replacement = claudePathToGuidancePath(claudePath);
|
|
104
|
+
refsTransformed++;
|
|
105
|
+
return '`' + replacement + '`';
|
|
106
|
+
});
|
|
107
|
+
// Pattern 2: Bare path references (with directory prefix) not inside backticks
|
|
108
|
+
// Match things like "src/core/CLAUDE.md" but not already-backtick-wrapped
|
|
109
|
+
transformed = transformed.replace(/(?<!`)([\w][\w./-]*\/CLAUDE\.md)(?!`)/g, (_match, claudePath) => {
|
|
110
|
+
const replacement = claudePathToGuidancePath(claudePath);
|
|
111
|
+
refsTransformed++;
|
|
112
|
+
return replacement;
|
|
113
|
+
});
|
|
114
|
+
// Pattern 3: Standalone "CLAUDE.md" that references the root file
|
|
115
|
+
// Only match when it looks like a file reference (not part of a longer word)
|
|
116
|
+
// Avoid matching inside paths already transformed above
|
|
117
|
+
transformed = transformed.replace(/(?<![/\w`])CLAUDE\.md(?![/\w`])/g, () => {
|
|
118
|
+
refsTransformed++;
|
|
119
|
+
return '.rpiv/guidance/architecture.md';
|
|
120
|
+
});
|
|
121
|
+
// Scan for remaining prose references that might need manual attention
|
|
122
|
+
const lines = transformed.split('\n');
|
|
123
|
+
for (let i = 0; i < lines.length; i++) {
|
|
124
|
+
// Look for prose patterns like "see X CLAUDE.md" or "X layer CLAUDE.md"
|
|
125
|
+
if (/\b\w+\s+CLAUDE\.md\b/i.test(content.split('\n')[i] ?? '') &&
|
|
126
|
+
!/(src|lib|app|packages|apps)\//.test(content.split('\n')[i] ?? '')) {
|
|
127
|
+
// Check if this line still has an untransformed prose reference
|
|
128
|
+
if (/CLAUDE\.md/i.test(lines[i])) {
|
|
129
|
+
warnings.push({
|
|
130
|
+
file: targetPath,
|
|
131
|
+
line: i + 1,
|
|
132
|
+
message: `Prose reference to CLAUDE.md may need manual update: "${lines[i].trim()}"`,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { content: transformed, refsTransformed, warnings };
|
|
138
|
+
}
|
|
139
|
+
function claudePathToGuidancePath(claudePath) {
|
|
140
|
+
const dir = dirname(claudePath);
|
|
141
|
+
if (dir === '.') {
|
|
142
|
+
return '.rpiv/guidance/architecture.md';
|
|
143
|
+
}
|
|
144
|
+
return '.rpiv/guidance/' + dir + '/architecture.md';
|
|
145
|
+
}
|
|
146
|
+
// --- Main ---
|
|
147
|
+
function main() {
|
|
148
|
+
const { projectDir, deleteOriginals, dryRun, force } = parseArgs(process.argv);
|
|
149
|
+
process.stderr.write(`[rpiv:migrate] scanning ${projectDir} for CLAUDE.md files\n`);
|
|
150
|
+
const claudeFiles = discoverClaudeMdFiles(projectDir);
|
|
151
|
+
if (claudeFiles.length === 0) {
|
|
152
|
+
const report = {
|
|
153
|
+
migrated: [],
|
|
154
|
+
conflicts: [],
|
|
155
|
+
warnings: [],
|
|
156
|
+
originalsDeleted: false,
|
|
157
|
+
dryRun,
|
|
158
|
+
};
|
|
159
|
+
process.stdout.write(JSON.stringify(report, null, 2));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
process.stderr.write(`[rpiv:migrate] found ${claudeFiles.length} CLAUDE.md file(s)\n`);
|
|
163
|
+
const migrated = [];
|
|
164
|
+
const conflicts = [];
|
|
165
|
+
const allWarnings = [];
|
|
166
|
+
const writtenFiles = [];
|
|
167
|
+
for (const source of claudeFiles) {
|
|
168
|
+
const target = computeTargetPath(source);
|
|
169
|
+
const targetAbs = join(projectDir, target);
|
|
170
|
+
// Check for conflicts
|
|
171
|
+
if (existsSync(targetAbs) && !force) {
|
|
172
|
+
conflicts.push(target);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
// Read source content
|
|
176
|
+
const sourceAbs = join(projectDir, source);
|
|
177
|
+
let content;
|
|
178
|
+
try {
|
|
179
|
+
content = readFileSync(sourceAbs, 'utf-8');
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
allWarnings.push({
|
|
183
|
+
file: source,
|
|
184
|
+
line: 0,
|
|
185
|
+
message: `Failed to read: ${err instanceof Error ? err.message : String(err)}`,
|
|
186
|
+
});
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (content.trim().length === 0) {
|
|
190
|
+
allWarnings.push({
|
|
191
|
+
file: source,
|
|
192
|
+
line: 0,
|
|
193
|
+
message: 'Empty file, skipped',
|
|
194
|
+
});
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
// Transform content
|
|
198
|
+
const { content: transformed, refsTransformed, warnings } = transformContent(content, target);
|
|
199
|
+
const lines = transformed.split('\n').length;
|
|
200
|
+
migrated.push({ source, target, lines, refsTransformed });
|
|
201
|
+
allWarnings.push(...warnings);
|
|
202
|
+
if (!dryRun) {
|
|
203
|
+
writtenFiles.push({ targetAbs, content: transformed });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Write all files (all-or-nothing approach for safety)
|
|
207
|
+
if (!dryRun) {
|
|
208
|
+
for (const { targetAbs, content } of writtenFiles) {
|
|
209
|
+
mkdirSync(dirname(targetAbs), { recursive: true });
|
|
210
|
+
writeFileSync(targetAbs, content, 'utf-8');
|
|
211
|
+
}
|
|
212
|
+
process.stderr.write(`[rpiv:migrate] wrote ${writtenFiles.length} file(s)\n`);
|
|
213
|
+
}
|
|
214
|
+
// Delete originals only after all writes succeed
|
|
215
|
+
let originalsDeleted = false;
|
|
216
|
+
if (!dryRun && deleteOriginals && writtenFiles.length > 0) {
|
|
217
|
+
for (const entry of migrated) {
|
|
218
|
+
const sourceAbs = join(projectDir, entry.source);
|
|
219
|
+
try {
|
|
220
|
+
unlinkSync(sourceAbs);
|
|
221
|
+
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
allWarnings.push({
|
|
224
|
+
file: entry.source,
|
|
225
|
+
line: 0,
|
|
226
|
+
message: `Failed to delete original: ${err instanceof Error ? err.message : String(err)}`,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
originalsDeleted = true;
|
|
231
|
+
process.stderr.write(`[rpiv:migrate] deleted ${migrated.length} original CLAUDE.md file(s)\n`);
|
|
232
|
+
}
|
|
233
|
+
const report = {
|
|
234
|
+
migrated,
|
|
235
|
+
conflicts,
|
|
236
|
+
warnings: allWarnings,
|
|
237
|
+
originalsDeleted,
|
|
238
|
+
dryRun,
|
|
239
|
+
};
|
|
240
|
+
process.stdout.write(JSON.stringify(report, null, 2));
|
|
241
|
+
}
|
|
242
|
+
main();
|
package/scripts/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: annotate-guidance
|
|
3
|
+
description: Generate architecture.md guidance files in .rpiv/guidance/ by analyzing architecture and patterns in parallel. Auto-detects architecture, proposes locations, and batch-writes compact documentation. Use for onboarding or improving AI assistant context.
|
|
4
|
+
argument-hint: [target-directory]
|
|
5
|
+
allowed-tools: Agent, Read, Write, Glob, Grep
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Annotate Project
|
|
9
|
+
|
|
10
|
+
You are tasked with generating architecture guidance files for a brownfield project. You will map the project structure, auto-detect its architecture, analyze each architectural layer, and batch-write compact architecture.md files under `.rpiv/guidance/` mirroring the project's directory structure.
|
|
11
|
+
|
|
12
|
+
## Initial Setup:
|
|
13
|
+
|
|
14
|
+
Use the current working directory as the target project by default. If the user provides a specific directory path as an argument, use that instead.
|
|
15
|
+
|
|
16
|
+
## Steps to follow:
|
|
17
|
+
|
|
18
|
+
1. **Read any directly mentioned files first:**
|
|
19
|
+
- If the user mentions specific files (existing architecture.md, CLAUDE.md, architecture docs, READMEs), read them FULLY first
|
|
20
|
+
- **IMPORTANT**: Use the Read tool WITHOUT limit/offset parameters to read entire files
|
|
21
|
+
- **CRITICAL**: Read these files yourself in the main context before invoking any skills
|
|
22
|
+
- This ensures you have full context before decomposing the work
|
|
23
|
+
|
|
24
|
+
2. **Pass 1 — Map the project (parallel agents):**
|
|
25
|
+
- Spawn the following agents in parallel using the Agent tool:
|
|
26
|
+
|
|
27
|
+
**Agent A — Project tree mapping:**
|
|
28
|
+
- subagent_type: `codebase-locator`
|
|
29
|
+
- Prompt: "Map the full project tree structure for [target directory]. List all directories and their contents, respecting .gitignore. Focus on source code directories, configuration files, and build artifacts. Return a complete tree view."
|
|
30
|
+
|
|
31
|
+
**Agent B — Architecture and conventions:**
|
|
32
|
+
- subagent_type: `codebase-locator`
|
|
33
|
+
- Prompt: "Identify the architectural layers, folder roles, and framework conventions in [target directory]. Determine: What architecture pattern is used (clean architecture, MVC, monorepo, microservices, hexagonal, etc.)? What are the main layers/modules? What frameworks and languages are present? What build system is used? For each main layer/module, check if it contains internal sub-layers with distinct architectural roles. If it does, explicitly flag each sub-layer as a guidance target candidate with: (a) path, (b) role/responsibility, (c) approximate file count, (d) how its patterns differ from siblings. Frontend frameworks (Angular, React, Vue, etc.) almost always have distinct sub-layers — components, services, shared/base classes, state management — report each separately."
|
|
34
|
+
|
|
35
|
+
- While agents run, read .gitignore yourself to understand exclusion rules
|
|
36
|
+
|
|
37
|
+
3. **Wait for Pass 1 and determine guidance targets:**
|
|
38
|
+
- IMPORTANT: Wait for ALL agents from Pass 1 to complete before proceeding
|
|
39
|
+
- Synthesize the tree structure and architecture findings
|
|
40
|
+
- Auto-detect the architecture pattern (clean architecture, MVC, monorepo, microservices, etc.)
|
|
41
|
+
- Determine guidance targets using a two-pass process:
|
|
42
|
+
|
|
43
|
+
**Initial pass — identify top-level targets:**
|
|
44
|
+
- Apply the Guidance Depth Rules (see below) to top-level architectural layers
|
|
45
|
+
- This produces the initial target list (one per distinct layer/project)
|
|
46
|
+
|
|
47
|
+
**Decomposition pass — expand composite targets (ADD, never REPLACE):**
|
|
48
|
+
- For EACH initial target, review Agent B's sub-layer candidates
|
|
49
|
+
- If Agent B flagged sub-layers with distinct roles and file counts >10, ADD them as separate guidance targets alongside the parent — the parent stays in the list as an overview, sub-layers are added beneath it
|
|
50
|
+
- NEVER remove the parent when promoting sub-layers — decomposition expands the target list, it does not substitute entries
|
|
51
|
+
- Do NOT apply a blanket "sub-folders same as parent" skip — evaluate each sub-layer Agent B flagged individually against the Depth Rules
|
|
52
|
+
- Common decompositions: Angular/React/Vue apps → components/, services/, shared/; monorepo packages → per-package; large shared libraries → per-concern
|
|
53
|
+
|
|
54
|
+
- Present the proposed guidance locations to the user:
|
|
55
|
+
```
|
|
56
|
+
## Proposed Guidance Locations
|
|
57
|
+
|
|
58
|
+
Architecture detected: [pattern name]
|
|
59
|
+
|
|
60
|
+
Files will be written to `.rpiv/guidance/` mirroring the project structure.
|
|
61
|
+
|
|
62
|
+
### Folders that need architectural guidance:
|
|
63
|
+
- `/` (root) — Project overview (compact)
|
|
64
|
+
- `src/core/` — Core domain layer
|
|
65
|
+
- `src/services/` — Service layer
|
|
66
|
+
- [etc.]
|
|
67
|
+
|
|
68
|
+
### Folders to skip:
|
|
69
|
+
- `src/core/entities/` — Entity grouping, same pattern as parent
|
|
70
|
+
- [etc.]
|
|
71
|
+
|
|
72
|
+
Does this look right? Should I add or remove any locations?
|
|
73
|
+
```
|
|
74
|
+
- Use the `ask_user_question` tool with the following question: "[N] guidance targets across [M] layers. Proceed with analysis?". Options: "Proceed (Recommended)" (Analyze all proposed folders and write architecture.md files); "Add folders" (I want to add more folders to the target list); "Remove folders" (Some proposed folders should be skipped).
|
|
75
|
+
- Adjust the target list based on user feedback
|
|
76
|
+
|
|
77
|
+
4. **Pass 2 — Analyze each layer (parallel analyzer agents):**
|
|
78
|
+
- For each confirmed target folder, spawn agents in parallel:
|
|
79
|
+
|
|
80
|
+
**For each target folder, spawn TWO agents:**
|
|
81
|
+
|
|
82
|
+
**Analyzer agent:**
|
|
83
|
+
- subagent_type: `codebase-analyzer`
|
|
84
|
+
- Prompt: "Analyze [folder path] in detail. Determine: 1) What is this layer's responsibility? 2) What are its dependencies (what does it import/use)? 3) Who consumes it (what imports/uses it)? 4) What are the key architectural boundaries and constraints? 5) What is the module structure — list DIRECTORIES with their roles, base types, and naming conventions. Use architectural annotations (e.g., 'one repo per entity', 'one controller per resource') instead of listing individual filenames. The structure should remain valid when non-architectural files are added. 6) What naming conventions are used (prefixes, suffixes, base classes)?"
|
|
85
|
+
|
|
86
|
+
**Pattern finder agent:**
|
|
87
|
+
- subagent_type: `codebase-pattern-finder`
|
|
88
|
+
- Prompt: "Find all distinct code patterns used in [folder path]. For each pattern found: 1) Name the pattern with a descriptive heading (e.g., 'Repository Boundary (CRITICAL: Plain Types, NOT Result<T>)'). 2) Provide an IDIOMATIC code example — a generalized, representative version that shows the pattern's essential shape (constructor, key method signatures, return types, error handling). Do NOT copy-paste a single file verbatim; instead synthesize the typical usage across the layer. 3) Add inline comments highlighting important conventions (e.g., '// DB int → boolean', '// throws on error — service wraps in Result'). 4) If the pattern involves a boundary between layers, show both sides. 5) Identify any repeatable workflows for adding new elements to this layer — backend entities (repositories, services, controllers) AND frontend elements (components, services, pages/routes, directives). For example: creating a new repository requires extending BaseRepository + registering in factory; adding a new Angular component requires extending BaseComponent + adding to routes + creating the template. Return these as step-by-step checklists. Return patterns with full code block examples."
|
|
89
|
+
|
|
90
|
+
- Spawn 1 analyzer + 1 pattern finder per folder, all in parallel
|
|
91
|
+
- For the root architecture.md, use findings from ALL folders to create the overview
|
|
92
|
+
|
|
93
|
+
5. **Wait for Pass 2 and synthesize:**
|
|
94
|
+
- IMPORTANT: Wait for ALL agents from Pass 2 to complete before proceeding
|
|
95
|
+
- Compile all agent findings per folder
|
|
96
|
+
- **Do NOT draft architecture.md content yet** — proceed to developer checkpoint first (Step 6)
|
|
97
|
+
|
|
98
|
+
6. **Developer checkpoint — validate findings before drafting:**
|
|
99
|
+
|
|
100
|
+
Present a per-folder findings summary, then ask grounded questions. This pulls domain knowledge that agents can't discover from code alone — deprecated patterns, undocumented conventions, migration-in-progress situations, or cross-layer rules that only the developer knows.
|
|
101
|
+
|
|
102
|
+
**Findings summary** — one block per target folder, 2-3 lines each:
|
|
103
|
+
```
|
|
104
|
+
## Findings Summary
|
|
105
|
+
|
|
106
|
+
### src/core/
|
|
107
|
+
Patterns: Repository base class, Entity base with soft-delete, Value Objects
|
|
108
|
+
Dependencies: Database layer (outbound), Services layer (inbound)
|
|
109
|
+
Workflows detected: "Add new entity" (5 steps), "Add new value object" (2 steps)
|
|
110
|
+
|
|
111
|
+
### src/services/
|
|
112
|
+
Patterns: Result<T> wrapping, Transaction scope per operation
|
|
113
|
+
Dependencies: Core (outbound), Controllers (inbound)
|
|
114
|
+
Workflows detected: "Add new service" (4 steps)
|
|
115
|
+
|
|
116
|
+
[etc.]
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Then ask grounded questions — **one at a time**, waiting for the developer's answer before asking the next. Ask as many as the findings warrant — one per significant ambiguity or discovery gap. Use a **❓ Question:** prefix. Each question must reference real findings and pull NEW information from the developer — not confirm what you already found, and not ask about cosmetic issues (typos, formatting) or absences the developer can't add context to.
|
|
120
|
+
|
|
121
|
+
Only ask questions whose answer would change what gets written in an architecture.md file. Focus on:
|
|
122
|
+
- Competing patterns that need a canonical vs. legacy designation (which style should new code follow?)
|
|
123
|
+
- Cross-layer dependencies that look like violations but might be design decisions
|
|
124
|
+
- Undocumented architectural constraints not visible in code (ordering, idempotency, invariants)
|
|
125
|
+
|
|
126
|
+
Example grounded questions:
|
|
127
|
+
- "Found two different mapping approaches in `src/services/`: manual mapping in `OrderService` and AutoMapper in `UserService`. Which is the current convention, or is there a migration in progress I should document?"
|
|
128
|
+
- "The analyzer found no event/message patterns in `src/core/`. Is domain event publishing handled elsewhere, or is it not used in this project?"
|
|
129
|
+
- "Detected 3 different error-handling styles across layers. Is there a canonical approach, or are these intentional per-layer differences?"
|
|
130
|
+
|
|
131
|
+
**CRITICAL**: Ask ONE question at a time. Wait for the answer before asking the next. Lead with your most significant finding. The developer will redirect you if needed.
|
|
132
|
+
|
|
133
|
+
**Choosing question format:**
|
|
134
|
+
|
|
135
|
+
- **`ask_user_question` tool** — when your question has 2-4 concrete options from code analysis (pattern conflicts, integration choices, scope boundaries, priority overrides). The user can always pick "Other" for free-text. Example: Use the `ask_user_question` tool with the question "Found 2 mapping approaches — which should new code follow?". Options: "Manual mapping (Recommended)" (Used in OrderService (src/services/OrderService.ts:45) — 8 occurrences); "AutoMapper" (Used in UserService (src/services/UserService.ts:12) — 2 occurrences).
|
|
136
|
+
|
|
137
|
+
- **Free-text with ❓ Question: prefix** — when the question is open-ended and options can't be predicted (discovery, "what am I missing?", corrections). Example:
|
|
138
|
+
"❓ Question: Integration scanner found no background job registration for this area. Is that expected, or is there async processing I'm not seeing?"
|
|
139
|
+
|
|
140
|
+
**Batching**: When you have 2-4 independent questions (answers don't depend on each other), you MAY batch them in a single `ask_user_question` call. Keep dependent questions sequential.
|
|
141
|
+
|
|
142
|
+
**Incorporate developer input:**
|
|
143
|
+
|
|
144
|
+
**Corrections** ("that pattern is deprecated", "wrong — we use X"):
|
|
145
|
+
- Update synthesis. If the correction reveals a pattern that needs fresh analysis, re-prompt a targeted **codebase-analyzer** or **codebase-pattern-finder** (max 2 agents).
|
|
146
|
+
|
|
147
|
+
**Missing conventions** ("you missed the soft-delete convention", "all handlers must be idempotent"):
|
|
148
|
+
- Add directly to synthesis for the relevant folder.
|
|
149
|
+
|
|
150
|
+
**Migration context** ("we're moving from X to Y", "old pattern in these files, new pattern in those"):
|
|
151
|
+
- Record both old and new approaches in synthesis — architecture.md should document the canonical (new) way with a note about the legacy approach still present in specific areas.
|
|
152
|
+
|
|
153
|
+
**Scope adjustments** ("skip that layer, it's being rewritten", "add src/shared/"):
|
|
154
|
+
- Update target list. For new targets, run a targeted Pass 2 (analyzer + pattern-finder, max 2 agents), then fold results into synthesis.
|
|
155
|
+
|
|
156
|
+
**Confirmations** ("looks right", "yes that's correct"):
|
|
157
|
+
- Proceed to drafting.
|
|
158
|
+
|
|
159
|
+
After incorporating all input, proceed to Step 7.
|
|
160
|
+
|
|
161
|
+
7. **Draft architecture.md content:**
|
|
162
|
+
- Draft architecture.md content in this order — **subfolder files first, root last**:
|
|
163
|
+
- Subfolder: Use the **Subfolder Architecture Template** (detailed, max 100 lines)
|
|
164
|
+
- Root folder (LAST): Use the **Root Architecture Template** (compact overview). Draft root only after all subfolder files are finalized — this ensures the deduplication rule can be applied and cross-layer checklists can accurately reference subfolder content
|
|
165
|
+
- **Output directory convention:** All architecture.md files are written under `.rpiv/guidance/` at the project root, mirroring the project's directory structure. For a target folder at `src/core/`, the output path is `.rpiv/guidance/src/core/architecture.md`. For the root target, the output path is `.rpiv/guidance/architecture.md`. Create intermediate directories as needed.
|
|
166
|
+
- Enforce the 100-line limit on subfolder files — code examples are essential but keep them concise
|
|
167
|
+
- If the pattern-finder identified repeatable "add new entity" workflows, include them as `<important if="you are adding a new [entity] to this layer">` conditional sections
|
|
168
|
+
- If testing patterns were detected, include them as `<important if="you are writing or modifying tests for this layer">` conditional sections
|
|
169
|
+
- Conditional sections are optional — only include when the pattern-finder found clear evidence of a repeatable workflow
|
|
170
|
+
- Conditions must be narrow and action-specific (NOT "you are writing code" — too broad)
|
|
171
|
+
- Do NOT include conventions enforceable by linters, formatters, or pre-commit hooks (e.g., naming conventions, import ordering, indentation) — these add noise without value
|
|
172
|
+
- Do NOT include patterns easily discoverable from existing code — LLMs are in-context learners and will follow patterns after a few file reads. Only document conventions that are surprising, non-obvious, or span multiple layers
|
|
173
|
+
- If a pattern section would contain only prose or comments with no code example, either expand it with a real idiomatic example or omit it and reference the source file (e.g., "see `BaseModalComponent` for the modal pattern")
|
|
174
|
+
- Before writing, verify: no root conditional block duplicates content from a subfolder architecture.md. If a layer has its own subfolder file, remove its summary from root
|
|
175
|
+
- For cross-layer vertical-slice checklists in root, each step should reference the relevant subfolder architecture.md (e.g., "see `.rpiv/guidance/src/data/architecture.md`") rather than inlining the full procedure
|
|
176
|
+
- If an existing root architecture.md or CLAUDE.md was found:
|
|
177
|
+
- Review its content
|
|
178
|
+
- Redistribute any detailed layer-specific content to the appropriate subfolder architecture.md files
|
|
179
|
+
- Rewrite the root as a compact overview
|
|
180
|
+
|
|
181
|
+
8. **Self-review pass — verify every drafted file before writing:**
|
|
182
|
+
Walk through each drafted architecture.md and check every item below. Fix violations in-place before proceeding to writing.
|
|
183
|
+
|
|
184
|
+
**Dependencies** — for each listed dependency, ask: "does this library impose patterns, constraints, or conventions on the code?" If the answer is no (utility libraries like lodash, moment, xlsx, FontAwesome), remove it. Only frameworks and libraries that shape how you write code survive.
|
|
185
|
+
|
|
186
|
+
**Module Structure** — count top-level entries. If more than 7, group related directories on one line (e.g., `guards/, interceptors/, pipes/ — cross-cutting plumbing`). Target 4-7 entries.
|
|
187
|
+
|
|
188
|
+
**Pattern sections** — every pattern H2 must contain a fenced code block with an idiomatic example. If a section is prose-only or comment-only, either expand it with a real code example or replace the section with a one-line file reference (e.g., "see `TradeDeskMapping.cs` for the mapping pattern").
|
|
189
|
+
|
|
190
|
+
**Root deduplication** — for each root conditional block, verify it is NOT summarizing a layer that has its own subfolder architecture.md. If it is, remove the block. For cross-layer vertical-slice checklists, verify each step references the relevant subfolder file (e.g., "see `.rpiv/guidance/X/architecture.md`") rather than inlining the procedure.
|
|
191
|
+
|
|
192
|
+
**Frontend/UI conditional coverage** — for each frontend/UI layer, list every repeatable workflow the pattern-finder reported (components, services, pages/routes, directives, pipes, hooks, stores — whatever was detected). Then compare that list against the drafted `<important if>` conditional sections. Any workflow on the list without a matching conditional is a gap — draft and add the missing section before proceeding.
|
|
193
|
+
|
|
194
|
+
After fixing all violations, re-scan the corrected drafts to confirm every check passes. Only proceed to writing when all checks are clean. Present a brief summary of what was fixed:
|
|
195
|
+
```
|
|
196
|
+
## Self-review results
|
|
197
|
+
- [file]: removed 2 utility deps (moment, xlsx-js-style)
|
|
198
|
+
- [file]: grouped Module Structure from 11 → 6 entries
|
|
199
|
+
- [file]: added "Adding a New Service" conditional
|
|
200
|
+
- Root: no violations found
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
9. **Pass 3 — Write all architecture.md files:**
|
|
204
|
+
- Write each file to `.rpiv/guidance/{relative_path}/architecture.md`. For the root file, write to `.rpiv/guidance/architecture.md`. Create any intermediate directories that do not exist.
|
|
205
|
+
- Write ALL files at once using the Write tool
|
|
206
|
+
- Do NOT ask for confirmation before each file — batch mode
|
|
207
|
+
- After writing, present a summary:
|
|
208
|
+
```
|
|
209
|
+
## Architecture Guidance Files Created
|
|
210
|
+
|
|
211
|
+
| File | Lines | Description |
|
|
212
|
+
|------|-------|-------------|
|
|
213
|
+
| .rpiv/guidance/architecture.md | 45 | Root project overview |
|
|
214
|
+
| .rpiv/guidance/src/core/architecture.md | 78 | Core domain layer |
|
|
215
|
+
| .rpiv/guidance/src/services/architecture.md | 65 | Service layer |
|
|
216
|
+
| [etc.] | | |
|
|
217
|
+
|
|
218
|
+
Total: [N] files created/updated
|
|
219
|
+
|
|
220
|
+
Please review the files and let me know if you'd like any adjustments.
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
10. **Handle follow-up adjustments:**
|
|
224
|
+
- If the user requests changes to specific files, edit them directly using the Edit tool
|
|
225
|
+
- If the user wants additional folders annotated, run a targeted Pass 2 (analyzer + pattern finder) for those folders, then write
|
|
226
|
+
- If the user wants a file removed, note that they can delete it themselves
|
|
227
|
+
|
|
228
|
+
## Root Architecture Template (compact):
|
|
229
|
+
|
|
230
|
+
Read the full template at `templates/root-architecture.md`.
|
|
231
|
+
|
|
232
|
+
Key principles:
|
|
233
|
+
- Bare sections (Overview, Architecture, Commands, Business Context) are foundational — always included
|
|
234
|
+
- Cross-cutting patterns go in `<important if>` blocks with narrow conditions
|
|
235
|
+
- Deduplication rule: if a layer has a subfolder architecture.md, don't summarize it in root
|
|
236
|
+
- Root MAY include cross-layer vertical-slice checklists referencing subfolder files
|
|
237
|
+
|
|
238
|
+
### Root Architecture Reference Examples
|
|
239
|
+
|
|
240
|
+
See `examples/root-nodejs-monorepo.md` (Node.js monorepo) and `examples/root-dotnet-clean-arch.md` (.NET Clean Architecture) for well-formed root architecture.md examples.
|
|
241
|
+
|
|
242
|
+
What makes these examples good:
|
|
243
|
+
- **Bare sections** (Overview, Project map, Commands) are relevant to nearly every task — no wrapper needed
|
|
244
|
+
- **Each `<important if>` has a narrow trigger** — "adding a new API endpoint" not "writing backend code"
|
|
245
|
+
- **No linter territory** — formatting rules left to tooling
|
|
246
|
+
- **No code snippets** — uses file path references since patterns are better shown in subfolder architecture.md files
|
|
247
|
+
- **Same structure, different ecosystems** — the pattern works identically for Node.js and .NET
|
|
248
|
+
|
|
249
|
+
## Subfolder Architecture Template (max 100 lines):
|
|
250
|
+
|
|
251
|
+
Read the full template at `templates/subfolder-architecture.md`.
|
|
252
|
+
|
|
253
|
+
Key principles:
|
|
254
|
+
- Each distinct pattern gets its own H2 section with a fenced code block
|
|
255
|
+
- Module Structure: aim for 4-7 top-level entries, use architectural annotations
|
|
256
|
+
- Conditional sections (`<important if>`) are optional — only for detected repeatable workflows
|
|
257
|
+
- Conditional sections do NOT count toward the 100-line budget
|
|
258
|
+
|
|
259
|
+
### Reference Examples
|
|
260
|
+
|
|
261
|
+
See the following for well-formed subfolder architecture.md examples:
|
|
262
|
+
- `examples/subfolder-database-layer.md` — Database layer (~80 lines)
|
|
263
|
+
- `examples/subfolder-schemas-layer.md` — Schemas layer (~70 lines)
|
|
264
|
+
- `examples/subfolder-dotnet-application.md` — .NET Application layer (~65 lines)
|
|
265
|
+
|
|
266
|
+
### What makes these examples good:
|
|
267
|
+
- **Module Structure**: Compact, uses architectural annotations, groups related files on one line
|
|
268
|
+
- **Patterns as H2 sections**: Each pattern has a descriptive name, NOT a generic umbrella
|
|
269
|
+
- **Code examples are idiomatic**: Generalized to show the pattern's shape
|
|
270
|
+
- **Cross-boundary patterns**: Shows both sides of layer boundaries
|
|
271
|
+
- **Concise**: All fit well within 100 lines
|
|
272
|
+
- **Conditional blocks**: Wrap scenario-specific recipes with narrow conditions
|
|
273
|
+
|
|
274
|
+
## Guidance Depth Rules:
|
|
275
|
+
|
|
276
|
+
**CREATE architecture.md when:**
|
|
277
|
+
- Folder represents a distinct **architectural layer** (core, services, database, redis, ipc)
|
|
278
|
+
- Folder contains **unique organizational logic** not captured by parent
|
|
279
|
+
- Subfolder has **different patterns/constraints** than parent (e.g., `database/repositories/` vs `database/`)
|
|
280
|
+
- Folder has **its own responsibility** (e.g., `database/migrations/`)
|
|
281
|
+
- Folder is a **composite application root** (e.g., SPA, monorepo package) whose children represent distinct sub-layers with different patterns — apply Depth Rules recursively to its children
|
|
282
|
+
|
|
283
|
+
**SKIP architecture.md when:**
|
|
284
|
+
- Folder only groups entities/DTOs by domain boundary following the same pattern
|
|
285
|
+
- Folder content is fully described by parent architecture.md
|
|
286
|
+
- Folder is a simple grouping without unique constraints
|
|
287
|
+
|
|
288
|
+
## Important notes:
|
|
289
|
+
- Always use parallel Agent tool calls to maximize efficiency and minimize context usage
|
|
290
|
+
- **File reading**: Always read mentioned files FULLY (no limit/offset) before invoking skills
|
|
291
|
+
- **Critical ordering**: Follow the numbered steps exactly
|
|
292
|
+
- ALWAYS read mentioned files first before invoking skills (step 1)
|
|
293
|
+
- ALWAYS wait for all skills in a pass to complete before proceeding to the next step
|
|
294
|
+
- NEVER write architecture.md files with placeholder values — all content must come from skill findings
|
|
295
|
+
- NEVER proceed to Pass 2 without user confirmation of target locations
|
|
296
|
+
- NEVER skip the developer checkpoint (step 6) — developer input is the highest-value signal for architecture.md quality
|
|
297
|
+
- NEVER draft architecture.md content before completing the developer checkpoint
|
|
298
|
+
- **.gitignore compliance**: Skip directories excluded by .gitignore (node_modules, dist, build, .git, vendor, etc.)
|
|
299
|
+
- **Batch output mode**: Write all architecture.md files at once in Pass 3, do not ask for per-file confirmation
|
|
300
|
+
- **Existing file handling**: If an architecture.md already exists at any target location in `.rpiv/guidance/`, replace it entirely using the Write tool
|
|
301
|
+
- **Line budget**: Subfolder architecture.md files must not exceed 100 lines — code examples in Key Patterns are mandatory, keep them idiomatic and concise
|
|
302
|
+
- **No frontmatter**: architecture.md files are pure markdown, no YAML frontmatter
|
|
303
|
+
- Keep the main agent focused on synthesis, not deep file reading — delegate analysis to sub-agents
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Project Overview
|
|
2
|
+
|
|
3
|
+
ASP.NET Core 8 Web API with Clean Architecture (CQRS + MediatR).
|
|
4
|
+
|
|
5
|
+
## Project map
|
|
6
|
+
|
|
7
|
+
- `src/Api/` - ASP.NET Core controllers, middleware, DI setup
|
|
8
|
+
- `src/Application/` - MediatR handlers, validators, DTOs
|
|
9
|
+
- `src/Domain/` - Entities, value objects, domain events
|
|
10
|
+
- `src/Infrastructure/` - EF Core, external services, file storage
|
|
11
|
+
- `tests/` - Unit and integration tests
|
|
12
|
+
|
|
13
|
+
## Commands
|
|
14
|
+
|
|
15
|
+
| Command | What it does |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `dotnet build` | Build solution |
|
|
18
|
+
| `dotnet test` | Run all tests |
|
|
19
|
+
| `dotnet run --project src/Api` | Start API locally |
|
|
20
|
+
| `dotnet ef migrations add <Name> -p src/Infrastructure` | Create EF migration |
|
|
21
|
+
| `dotnet ef database update -p src/Infrastructure` | Apply migrations |
|
|
22
|
+
|
|
23
|
+
<important if="you are adding a new API endpoint">
|
|
24
|
+
- Add controller in `Api/Controllers/` inheriting `BaseApiController`
|
|
25
|
+
- Add command/query + handler + validator in `Application/Features/`
|
|
26
|
+
- See `Application/Features/Orders/Commands/CreateOrder/` for the pattern
|
|
27
|
+
</important>
|
|
28
|
+
|
|
29
|
+
<important if="you are adding or modifying EF Core migrations or database schema">
|
|
30
|
+
- Entities configured via `IEntityTypeConfiguration<T>` in `Infrastructure/Persistence/Configurations/`
|
|
31
|
+
- Always create a migration after schema changes — never modify existing migrations
|
|
32
|
+
</important>
|
|
33
|
+
|
|
34
|
+
<important if="you are writing or modifying tests">
|
|
35
|
+
- Unit tests: xUnit + NSubstitute, one test class per handler
|
|
36
|
+
- Integration tests: `WebApplicationFactory<Program>` with test database
|
|
37
|
+
- See `tests/Application.IntegrationTests/TestBase.cs` for setup
|
|
38
|
+
</important>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Project Overview
|
|
2
|
+
|
|
3
|
+
Express API + React frontend in a Turborepo monorepo.
|
|
4
|
+
|
|
5
|
+
## Project map
|
|
6
|
+
|
|
7
|
+
- `apps/api/` - Express REST API
|
|
8
|
+
- `apps/web/` - React SPA
|
|
9
|
+
- `packages/db/` - Prisma schema and client
|
|
10
|
+
- `packages/ui/` - Shared component library
|
|
11
|
+
- `packages/config/` - Shared configuration
|
|
12
|
+
|
|
13
|
+
## Commands
|
|
14
|
+
|
|
15
|
+
| Command | What it does |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `turbo build` | Build all packages |
|
|
18
|
+
| `turbo test` | Run all tests |
|
|
19
|
+
| `turbo lint` | Lint all packages |
|
|
20
|
+
| `turbo dev` | Start dev server |
|
|
21
|
+
| `turbo db:generate` | Regenerate Prisma client after schema changes |
|
|
22
|
+
| `turbo db:migrate` | Run database migrations |
|
|
23
|
+
|
|
24
|
+
<important if="you are adding or modifying API routes">
|
|
25
|
+
- All routes go in `apps/api/src/routes/`
|
|
26
|
+
- Use Zod for request validation — see `apps/api/src/routes/connections.ts` for the pattern
|
|
27
|
+
- Error responses follow RFC 7807 format
|
|
28
|
+
- Authentication via JWT middleware
|
|
29
|
+
</important>
|
|
30
|
+
|
|
31
|
+
<important if="you are writing or modifying tests">
|
|
32
|
+
- API: Jest + Supertest, Frontend: Vitest + Testing Library
|
|
33
|
+
- Test fixtures in `__fixtures__/` directories
|
|
34
|
+
- Use `createTestClient()` helper for API integration tests
|
|
35
|
+
- Mock database with `prismaMock` from `packages/db/test`
|
|
36
|
+
</important>
|
|
37
|
+
|
|
38
|
+
<important if="you are working with client-side state, stores, or data fetching">
|
|
39
|
+
- Zustand for global client state
|
|
40
|
+
- React Query for server state
|
|
41
|
+
- URL state via `nuqs`
|
|
42
|
+
</important>
|