@ivannikov-pro/ai-context-surgeon 1.0.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 +22 -0
- package/README.md +372 -0
- package/bin/catalog.js +153 -0
- package/bin/cli.js +380 -0
- package/bin/installer.js +135 -0
- package/bin/prompts.js +371 -0
- package/checklists/phase-1-analysis.md +58 -0
- package/checklists/phase-2-planning.md +67 -0
- package/checklists/phase-3-restructuring.md +77 -0
- package/checklists/phase-4-documentation.md +111 -0
- package/checklists/phase-5-validation.md +91 -0
- package/examples/before-after/README.md +139 -0
- package/examples/ideal-monorepo/README.md +127 -0
- package/knowledge/agent-context-system/artifacts/guide.md +183 -0
- package/knowledge/agent-context-system/artifacts/knowledge.md +177 -0
- package/knowledge/agent-context-system/artifacts/skills.md +101 -0
- package/knowledge/agent-context-system/artifacts/workflows.md +143 -0
- package/knowledge/agent-context-system/metadata.json +26 -0
- package/knowledge/agent-context-system/timestamps.json +5 -0
- package/knowledge/agent-vulnerabilities/LICENSE +21 -0
- package/knowledge/agent-vulnerabilities/artifacts/stealth_injection.md +110 -0
- package/knowledge/agent-vulnerabilities/artifacts/vulnerabilities.md +232 -0
- package/knowledge/agent-vulnerabilities/metadata.json +14 -0
- package/knowledge/agent-vulnerabilities/timestamps.json +5 -0
- package/knowledge/power-words-dictionary/LICENSE +21 -0
- package/knowledge/power-words-dictionary/artifacts/dictionary.md +231 -0
- package/knowledge/power-words-dictionary/artifacts/prompt_amplifier.py +381 -0
- package/knowledge/power-words-dictionary/metadata.json +14 -0
- package/knowledge/power-words-dictionary/timestamps.json +5 -0
- package/package.json +77 -0
- package/roles/README.md +81 -0
- package/roles/architect.md +203 -0
- package/roles/inspector.md +232 -0
- package/roles/librarian.md +176 -0
- package/roles/scout.md +169 -0
- package/roles/surgeon.md +172 -0
- package/roles/tuner.md +204 -0
- package/skills/annotate-jsdoc/SKILL.md +262 -0
- package/skills/prompt-engineering/LICENSE +21 -0
- package/skills/prompt-engineering/SKILL.md +235 -0
- package/skills/prompt-engineering/scripts/extract_instructions.py +416 -0
- package/skills/prompt-engineering/scripts/prompt_amplifier.py +381 -0
- package/skills/prompt-engineering/scripts/prompt_diff_tracker.py +281 -0
- package/skills/prompt-engineering/scripts/prompt_dna_analyzer.py +692 -0
- package/skills/prompt-engineering/scripts/templates/code_review.md +47 -0
- package/skills/prompt-engineering/scripts/templates/dump_extraction.md +59 -0
- package/skills/prompt-engineering/scripts/templates/multi_agent_orchestration.md +100 -0
- package/skills/prompt-engineering/scripts/templates/prompt_audit.md +106 -0
- package/skills/prompt-engineering/scripts/templates/stealth_injection.md +110 -0
- package/skills/prompt-engineering/scripts/templates/task_automation.md +87 -0
- package/skills/prompt-engineering/workflows/amplify.md +36 -0
- package/skills/prompt-engineering/workflows/audit.md +55 -0
- package/skills/prompt-engineering/workflows/context-dump.md +90 -0
- package/skills/prompt-engineering/workflows/diff.md +44 -0
- package/strategy/bash-guide.md +134 -0
- package/strategy/context-exclusion.md +220 -0
- package/strategy/context-weight-theory.md +49 -0
- package/strategy/file-navigation-header.md +562 -0
- package/strategy/jsdoc-guide.md +596 -0
- package/strategy/monorepo_strategy.md +726 -0
- package/strategy/package-json-guide.md +541 -0
- package/templates/AGENTS.md.template +148 -0
- package/templates/antigravityignore.template +64 -0
- package/templates/cursorrules.template +7 -0
- package/templates/knowledge-item.template +44 -0
- package/templates/package-json-ideal.template +26 -0
- package/templates/package-readme.template +45 -0
- package/templates/publish-meta.template +34 -0
- package/templates/skill.template +50 -0
- package/templates/workflow.template +33 -0
- package/tools/analyze-package-json.sh +213 -0
- package/tools/analyze-structure.sh +101 -0
- package/tools/audit-jsdoc.sh +176 -0
- package/tools/check-fnh-freshness.sh +74 -0
- package/tools/detect-circular-deps.sh +147 -0
- package/tools/detect-god-files.sh +71 -0
- package/tools/enforce-god-files.sh +112 -0
- package/tools/enrich-package-json.js +311 -0
- package/tools/generate-jsdoc-headers.sh +109 -0
- package/tools/generate-source-map.sh +71 -0
- package/tools/lint-imports.sh +123 -0
- package/tools/measure-context-cost.sh +206 -0
- package/tools/scan-fnh.sh +174 -0
- package/tools/shared/config.sh +53 -0
- package/tools/validate-context-hygiene.sh +52 -0
- package/tools/validate-context-weight.sh +100 -0
- package/tools/validate-naming.sh +98 -0
package/bin/prompts.js
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Category: Tool — Prompt Library for AI agents | EXPORTS: PROMPTS, listPrompts, getPrompt | DEPS: none */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Each prompt is a self-contained instruction that an AI agent can request
|
|
6
|
+
* via `npx @ivannikov-pro/ai-context-surgeon prompt <task>`
|
|
7
|
+
* and immediately apply without reading full strategy docs.
|
|
8
|
+
*
|
|
9
|
+
* This saves ~500-2000 tokens per task vs reading full strategy files.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const PROMPTS = {
|
|
13
|
+
fnh: {
|
|
14
|
+
name: "File Navigation Header (FNH)",
|
|
15
|
+
description: "How to create an FNH header for any file",
|
|
16
|
+
prompt: `## Task: Add FNH Header to a File
|
|
17
|
+
|
|
18
|
+
MANDATORY RULE: Every file MUST have a machine-readable identity descriptor on its FIRST line.
|
|
19
|
+
|
|
20
|
+
### Format by File Type
|
|
21
|
+
|
|
22
|
+
| Type | Line 1 Format | Example |
|
|
23
|
+
|----|----|----|
|
|
24
|
+
| .ts/.js | \`/** Category: Name — description | EXPORTS: ... | DEPS: ... */\` | \`/** Service: UserService — CRUD + auth | EXPORTS: create, getById | DEPS: prisma */\` |
|
|
25
|
+
| .md | \`<!-- FNH: Category — description | SECTIONS: ... | DEPS: ... -->\` | \`<!-- FNH: Guide — API conventions | SECTIONS: Errors, Auth | DEPS: none -->\` |
|
|
26
|
+
| .sh | Line 2 (after shebang): \`# Tool: name — description | DEPS: ...\` | \`# Tool: scan-fnh — repo map from headers | DEPS: none\` |
|
|
27
|
+
| .py | \`# Category: Name — description | EXPORTS: ... | DEPS: ...\` | \`# Service: DataLoader — batch ETL | EXPORTS: load, transform | DEPS: pandas\` |
|
|
28
|
+
| .css | \`/* Category: Name — description */\` | \`/* Styles: Dashboard — main layout + theme | SECTIONS: Layout, Cards, Nav */\` |
|
|
29
|
+
| .yaml | \`# Config: Name — description\` | \`# Config: CI pipeline — build + test on push\` |
|
|
30
|
+
| .sql | \`-- Migration: Name — description\` | \`-- Migration: 003_add_phone — adds phone column\` |
|
|
31
|
+
|
|
32
|
+
### 5 Mandatory Layers
|
|
33
|
+
|
|
34
|
+
1. **Category + Name + Purpose** — "Service: UserService — CRUD + auth"
|
|
35
|
+
2. **Exports / Public API** — "EXPORTS: create, getById, update, delete"
|
|
36
|
+
3. **Sections / Routes / Structure** — "ROUTES: GET /, POST /, DELETE /:id"
|
|
37
|
+
4. **Dependencies** — "DEPS: prisma, bcrypt, @project/shared"
|
|
38
|
+
5. **Gotchas** — "@throws Conflict | sends email | cached 60s"
|
|
39
|
+
|
|
40
|
+
### Scaling by File Size
|
|
41
|
+
|
|
42
|
+
| Size | Detail |
|
|
43
|
+
|----|----|
|
|
44
|
+
| <50 lines | All 5 layers in 1 line |
|
|
45
|
+
| 50-150 lines | 2-3 lines |
|
|
46
|
+
| 150-300 lines | 3-5 lines |
|
|
47
|
+
| 300+ lines | 5-8 lines + SPLIT THE FILE |
|
|
48
|
+
|
|
49
|
+
### Category Vocabulary
|
|
50
|
+
|
|
51
|
+
Service, Route, Middleware, Controller, Repository, Entity, Types, Utility,
|
|
52
|
+
Config, Schema, Hook, Component, Store, Factory, Adapter, Event, Guard,
|
|
53
|
+
Constants, Test, Script, Migration, Barrel, Package, Guide, Role, Checklist,
|
|
54
|
+
Knowledge, Architecture, Report, Skill
|
|
55
|
+
|
|
56
|
+
### FNH Freshness Rule
|
|
57
|
+
|
|
58
|
+
When you MODIFY a file, you MUST update its FNH:
|
|
59
|
+
- ADD export/function → add to FNH
|
|
60
|
+
- REMOVE export/function → remove from FNH
|
|
61
|
+
- RENAME anything → update in FNH
|
|
62
|
+
- A stale FNH is WORSE than no FNH`,
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
jsdoc: {
|
|
66
|
+
name: "JSDoc Annotation",
|
|
67
|
+
description: "How to write AI-optimized JSDoc headers",
|
|
68
|
+
prompt: `## Task: Annotate Files with AI-Optimized JSDoc
|
|
69
|
+
|
|
70
|
+
CRITICAL RULE: Do NOT change any code logic. ONLY add/modify comments.
|
|
71
|
+
|
|
72
|
+
### File Header (MANDATORY for every .ts/.js file)
|
|
73
|
+
|
|
74
|
+
\`\`\`typescript
|
|
75
|
+
/** Service: UserService — CRUD + auth for users | deps: prisma, bcrypt */
|
|
76
|
+
\`\`\`
|
|
77
|
+
|
|
78
|
+
### Function-Level JSDoc — ONLY for invisible information
|
|
79
|
+
|
|
80
|
+
✅ DO annotate:
|
|
81
|
+
- \`@throws {ErrorType}\` — every thrown error
|
|
82
|
+
- \`@deprecated\` — with migration path
|
|
83
|
+
- \`@mutates\` — what state it changes
|
|
84
|
+
- Side effects: "Sends email", "Writes to disk", "Clears cache"
|
|
85
|
+
|
|
86
|
+
❌ DO NOT annotate (TypeScript says it already):
|
|
87
|
+
- \`@param {type}\` in TypeScript files
|
|
88
|
+
- \`@returns {type}\` in TypeScript files
|
|
89
|
+
- \`@author\`, \`@since\`, \`@version\`, \`@fileoverview\`, \`@module\`
|
|
90
|
+
|
|
91
|
+
### Example: Before → After
|
|
92
|
+
|
|
93
|
+
BEFORE (220 tokens of noise):
|
|
94
|
+
\`\`\`typescript
|
|
95
|
+
/**
|
|
96
|
+
* @fileoverview User Service
|
|
97
|
+
* @author Jane Developer
|
|
98
|
+
* @since 2024-03-15
|
|
99
|
+
*/
|
|
100
|
+
export class UserService {
|
|
101
|
+
/** @param {CreateUserInput} input @returns {Promise<User>} */
|
|
102
|
+
async create(input: CreateUserInput): Promise<User> { ... }
|
|
103
|
+
}
|
|
104
|
+
\`\`\`
|
|
105
|
+
|
|
106
|
+
AFTER (40 tokens — 82% reduction):
|
|
107
|
+
\`\`\`typescript
|
|
108
|
+
/** Service: UserService — CRUD + auth | deps: prisma, bcrypt */
|
|
109
|
+
export class UserService {
|
|
110
|
+
/** @throws Conflict(email) | hashes pw bcrypt 12 | sends welcome email */
|
|
111
|
+
async create(input: CreateUserInput): Promise<User> { ... }
|
|
112
|
+
}
|
|
113
|
+
\`\`\`
|
|
114
|
+
|
|
115
|
+
### JavaScript files (non-TypeScript): @param types ARE needed
|
|
116
|
+
\`\`\`javascript
|
|
117
|
+
/** @param {string} id @returns {Promise<User|null>} @throws {NotFoundError} */
|
|
118
|
+
async function getUserById(id) { ... }
|
|
119
|
+
\`\`\``,
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
readme: {
|
|
123
|
+
name: "Package README",
|
|
124
|
+
description: "How to write a README with Source Structure for AI agents",
|
|
125
|
+
prompt: `## Task: Create an AI-Optimized Package README
|
|
126
|
+
|
|
127
|
+
### Structure Template
|
|
128
|
+
|
|
129
|
+
\`\`\`markdown
|
|
130
|
+
<!-- FNH: Package — @project/name description | EXPORTS: ... | DEPS: ... -->
|
|
131
|
+
|
|
132
|
+
# @project/name
|
|
133
|
+
|
|
134
|
+
> Package: description of what this package does
|
|
135
|
+
> EXPORTS: key exports listed
|
|
136
|
+
> DEPS: @project/shared, external-lib
|
|
137
|
+
> SCRIPTS: dev, build, test, lint
|
|
138
|
+
|
|
139
|
+
## Source Structure
|
|
140
|
+
|
|
141
|
+
\\\`\\\`\\\`text
|
|
142
|
+
src/
|
|
143
|
+
index.ts ← Public API (re-exports)
|
|
144
|
+
types.ts ← Type contracts
|
|
145
|
+
entities/
|
|
146
|
+
user.ts ← User entity (50 lines)
|
|
147
|
+
order.ts ← Order entity (40 lines)
|
|
148
|
+
services/
|
|
149
|
+
user.service.ts ← User CRUD + auth (120 lines)
|
|
150
|
+
order.service.ts ← Order lifecycle (100 lines)
|
|
151
|
+
\\\`\\\`\\\`
|
|
152
|
+
|
|
153
|
+
## Dependencies
|
|
154
|
+
|
|
155
|
+
| Package | Purpose |
|
|
156
|
+
|----|----|
|
|
157
|
+
| prisma | Database ORM |
|
|
158
|
+
| bcrypt | Password hashing |
|
|
159
|
+
|
|
160
|
+
## Scripts
|
|
161
|
+
|
|
162
|
+
| Command | Description |
|
|
163
|
+
|----|----|
|
|
164
|
+
| \\\`npm run dev\\\` | Start dev server |
|
|
165
|
+
| \\\`npm run build\\\` | Build for production |
|
|
166
|
+
| \\\`npm run test\\\` | Run tests |
|
|
167
|
+
\`\`\`
|
|
168
|
+
|
|
169
|
+
### Key Rules
|
|
170
|
+
|
|
171
|
+
1. Source Structure uses \`←\` descriptions for EVERY file
|
|
172
|
+
2. Include line counts for files >50 lines
|
|
173
|
+
3. List ALL directories with their purpose
|
|
174
|
+
4. Dependencies table shows WHY each dep is needed
|
|
175
|
+
5. Scripts table shows ALL available npm scripts
|
|
176
|
+
6. FNH blockquote after H1 lists EXPORTS and DEPS`,
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
"agent-rules": {
|
|
180
|
+
name: "AGENTS.md",
|
|
181
|
+
description: "How to write AGENTS.md rules file for a repository",
|
|
182
|
+
prompt: `## Task: Create AGENTS.md for a Repository
|
|
183
|
+
|
|
184
|
+
AGENTS.md is the HIGHEST PRIORITY file for AI agents. Place at \`.agents/AGENTS.md\` or project root.
|
|
185
|
+
|
|
186
|
+
### Mandatory Sections
|
|
187
|
+
|
|
188
|
+
1. **Language** — English for code/comments, user's language for responses
|
|
189
|
+
2. **Architecture Rules** — dependency direction, package boundaries
|
|
190
|
+
3. **Navigation Rules** (CRITICAL):
|
|
191
|
+
- Before modifying ANY package, ALWAYS read its README.md first
|
|
192
|
+
- Do NOT scan the entire monorepo — work within target package only
|
|
193
|
+
- Do NOT read more than 5 files before starting work
|
|
194
|
+
- Use grep_search to find specific code instead of reading entire files
|
|
195
|
+
4. **FNH Rules** — mandatory headers, freshness rule
|
|
196
|
+
5. **Context Exclusion** — .antigravityignore rules
|
|
197
|
+
6. **Code Conventions** — TS strict, validation lib, error handling
|
|
198
|
+
7. **Naming Conventions** — kebab-case files, PascalCase classes
|
|
199
|
+
8. **File Operations** — build/test commands
|
|
200
|
+
|
|
201
|
+
### Example Navigation Rules
|
|
202
|
+
|
|
203
|
+
\`\`\`markdown
|
|
204
|
+
## Navigation Rules (CRITICAL for context optimization)
|
|
205
|
+
- Before modifying ANY package, ALWAYS read its README.md first
|
|
206
|
+
- Do NOT scan the entire monorepo — work within the target package only
|
|
207
|
+
- If you need types from another package, read ONLY its src/types.ts or src/index.ts
|
|
208
|
+
- Do NOT read more than 5 files before starting work
|
|
209
|
+
- Use grep_search to find specific code instead of reading entire files
|
|
210
|
+
\`\`\`
|
|
211
|
+
|
|
212
|
+
### FNH Freshness Rule (MUST include)
|
|
213
|
+
|
|
214
|
+
\`\`\`markdown
|
|
215
|
+
## FNH Freshness Rule
|
|
216
|
+
When you modify a file, you MUST update its FNH to reflect changes:
|
|
217
|
+
- ADD a new export → add it to the FNH
|
|
218
|
+
- REMOVE an export → remove it from the FNH
|
|
219
|
+
- RENAME anything → update it in the FNH
|
|
220
|
+
\`\`\`
|
|
221
|
+
|
|
222
|
+
### Use {{PLACEHOLDER}} for project-specific values
|
|
223
|
+
\`{{BUILD_COMMAND}}\`, \`{{TEST_COMMAND}}\`, \`{{SCOPE}}\`, \`{{VALIDATION_LIB}}\``,
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
"context-exclusion": {
|
|
227
|
+
name: "Context Exclusion",
|
|
228
|
+
description: "How to set up .antigravityignore / .aiignore",
|
|
229
|
+
prompt: `## Task: Configure Context Exclusion for AI Agents
|
|
230
|
+
|
|
231
|
+
Context Exclusion prevents AI agents from wasting tokens on irrelevant files.
|
|
232
|
+
Create \`.antigravityignore\` (or \`.aiignore\`, \`.cursorignore\`) at project root.
|
|
233
|
+
|
|
234
|
+
### Template
|
|
235
|
+
|
|
236
|
+
\`\`\`gitignore
|
|
237
|
+
# Lock files (huge, zero value in context)
|
|
238
|
+
package-lock.json
|
|
239
|
+
yarn.lock
|
|
240
|
+
pnpm-lock.yaml
|
|
241
|
+
npm-shrinkwrap.json
|
|
242
|
+
|
|
243
|
+
# Build artifacts
|
|
244
|
+
dist/
|
|
245
|
+
build/
|
|
246
|
+
.next/
|
|
247
|
+
out/
|
|
248
|
+
coverage/
|
|
249
|
+
*.tsbuildinfo
|
|
250
|
+
|
|
251
|
+
# Cache
|
|
252
|
+
.turbo/
|
|
253
|
+
.cache/
|
|
254
|
+
.eslintcache
|
|
255
|
+
|
|
256
|
+
# Generated
|
|
257
|
+
*.d.ts
|
|
258
|
+
*.min.js
|
|
259
|
+
*.min.css
|
|
260
|
+
*.map
|
|
261
|
+
|
|
262
|
+
# Large binary/media
|
|
263
|
+
*.png
|
|
264
|
+
*.jpg
|
|
265
|
+
*.gif
|
|
266
|
+
*.ico
|
|
267
|
+
*.woff
|
|
268
|
+
*.woff2
|
|
269
|
+
*.ttf
|
|
270
|
+
*.eot
|
|
271
|
+
|
|
272
|
+
# IDE
|
|
273
|
+
.idea/
|
|
274
|
+
.vscode/
|
|
275
|
+
\`\`\`
|
|
276
|
+
|
|
277
|
+
### Rules
|
|
278
|
+
|
|
279
|
+
1. NEVER exclude source code (.ts, .js, .py, .rs)
|
|
280
|
+
2. NEVER exclude test files (*.test.ts, *.spec.ts)
|
|
281
|
+
3. NEVER exclude README.md or AGENTS.md
|
|
282
|
+
4. ALWAYS exclude lock files (zero context value, thousands of tokens)
|
|
283
|
+
5. ALWAYS exclude build artifacts (stale, generated)
|
|
284
|
+
6. ALWAYS exclude binary files (can't be read as text)
|
|
285
|
+
|
|
286
|
+
### Token Impact
|
|
287
|
+
|
|
288
|
+
| File | Tokens | Value |
|
|
289
|
+
|----|----|----|
|
|
290
|
+
| package-lock.json | ~50,000 | Zero |
|
|
291
|
+
| yarn.lock | ~30,000 | Zero |
|
|
292
|
+
| node_modules/ | ~millions | Zero |
|
|
293
|
+
| dist/ | varies | Zero (stale) |
|
|
294
|
+
| README.md | ~300 | Critical |
|
|
295
|
+
| src/types.ts | ~150 | Critical |`,
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
"god-file": {
|
|
299
|
+
name: "God File Splitting",
|
|
300
|
+
description: "How to split a god-file (>300 lines) into modules",
|
|
301
|
+
prompt: `## Task: Split a God-File into Modules
|
|
302
|
+
|
|
303
|
+
A God-File is any file exceeding 300 lines of code (or 300 Context Weight).
|
|
304
|
+
AI agents lose accuracy when processing files this large.
|
|
305
|
+
|
|
306
|
+
### Step-by-Step Process
|
|
307
|
+
|
|
308
|
+
1. **Identify boundaries**: Look for logical groups (by domain, by function type)
|
|
309
|
+
2. **Extract bottom-up**: Start with leaf functions (no internal deps), then services
|
|
310
|
+
3. **Build after each step**: Run build command after every extraction
|
|
311
|
+
4. **Update imports**: Fix all import paths in consuming files
|
|
312
|
+
5. **Add FNH**: Every new file gets an FNH header immediately
|
|
313
|
+
|
|
314
|
+
### Splitting Patterns
|
|
315
|
+
|
|
316
|
+
**Pattern A: Split by Domain**
|
|
317
|
+
\`\`\`
|
|
318
|
+
routes.ts (1200 lines) →
|
|
319
|
+
routes/users.ts (120 lines)
|
|
320
|
+
routes/orders.ts (150 lines)
|
|
321
|
+
routes/products.ts (100 lines)
|
|
322
|
+
routes/auth.ts (80 lines)
|
|
323
|
+
routes/index.ts (20 lines — re-exports)
|
|
324
|
+
\`\`\`
|
|
325
|
+
|
|
326
|
+
**Pattern B: Split by Layer**
|
|
327
|
+
\`\`\`
|
|
328
|
+
utils.ts (800 lines) →
|
|
329
|
+
utils/string.ts (60 lines)
|
|
330
|
+
utils/date.ts (40 lines)
|
|
331
|
+
utils/validation.ts (80 lines)
|
|
332
|
+
utils/response.ts (50 lines)
|
|
333
|
+
utils/index.ts (10 lines — barrel)
|
|
334
|
+
\`\`\`
|
|
335
|
+
|
|
336
|
+
**Pattern C: Extract Types**
|
|
337
|
+
\`\`\`
|
|
338
|
+
service.ts (400 lines) →
|
|
339
|
+
types.ts (80 lines — interfaces, DTOs)
|
|
340
|
+
service.ts (320 lines — logic only)
|
|
341
|
+
\`\`\`
|
|
342
|
+
|
|
343
|
+
### Rules
|
|
344
|
+
|
|
345
|
+
1. Each extracted file MUST be <300 lines
|
|
346
|
+
2. Each extracted file gets an FNH header
|
|
347
|
+
3. Barrel file (index.ts) re-exports everything
|
|
348
|
+
4. Build MUST pass after each extraction
|
|
349
|
+
5. No circular dependencies between extracted files
|
|
350
|
+
|
|
351
|
+
### Context Weight Formula
|
|
352
|
+
\`\`\`
|
|
353
|
+
Weight = LOC + (Local Imports × 20) + (Global Imports × 5)
|
|
354
|
+
|
|
355
|
+
< 100 W: Light — easy for AI
|
|
356
|
+
100-300 W: Moderate — manageable
|
|
357
|
+
> 300 W: Heavy — AI will lose context, split required
|
|
358
|
+
\`\`\``,
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
export function listPrompts() {
|
|
363
|
+
return Object.entries(PROMPTS).map(([key, val]) => ({
|
|
364
|
+
value: key,
|
|
365
|
+
label: `${val.name} — ${val.description}`,
|
|
366
|
+
}));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export function getPrompt(key) {
|
|
370
|
+
return PROMPTS[key] || null;
|
|
371
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<!-- FNH: Checklist — Phase 1 Analysis | ROLE: Scout | MODEL: Gemini 3 Flash -->
|
|
2
|
+
|
|
3
|
+
# Phase 1: Analysis — Checklist
|
|
4
|
+
|
|
5
|
+
> **Role:** Scout | **Model:** Gemini 3 Flash | **Mode:** Fast | **Goal:** Understand the monorepo's current state without modifying anything | **SECTIONS:** Environment, Dependencies, Structure, God Files, Circular Deps | **DEPS:** none
|
|
6
|
+
|
|
7
|
+
## Pre-flight
|
|
8
|
+
|
|
9
|
+
- [ ] Target repo path confirmed: `{{TARGET_REPO_PATH}}`
|
|
10
|
+
- [ ] Read `roles/scout.md` for full instructions
|
|
11
|
+
- [ ] No files will be modified (read-only phase)
|
|
12
|
+
|
|
13
|
+
## Structure Analysis
|
|
14
|
+
|
|
15
|
+
- [ ] Run `tools/analyze-structure.sh {{TARGET_REPO_PATH}}`
|
|
16
|
+
- [ ] Run `tools/detect-god-files.sh {{TARGET_REPO_PATH}}`
|
|
17
|
+
- [ ] Run `tools/detect-circular-deps.sh {{TARGET_REPO_PATH}}`
|
|
18
|
+
- [ ] Run `tools/measure-context-cost.sh` for top 5 largest packages
|
|
19
|
+
|
|
20
|
+
## Manual Inspection
|
|
21
|
+
|
|
22
|
+
- [ ] Read root `README.md` (if exists) — note what's missing
|
|
23
|
+
- [ ] Check if `packages/` or `apps/` structure exists
|
|
24
|
+
- [ ] Check if monorepo manager exists (turbo.json, nx.json, lerna.json, pnpm-workspace.yaml)
|
|
25
|
+
- [ ] Check for `.agents/` directory
|
|
26
|
+
- [ ] Check for `.agents/AGENTS.md`
|
|
27
|
+
- [ ] Check for `.agents/knowledge/` directory
|
|
28
|
+
- [ ] Check for `.agents/skills/` directory
|
|
29
|
+
- [ ] Check for `.agents/workflows/` directory
|
|
30
|
+
- [ ] Identify the top 3 largest/most complex packages
|
|
31
|
+
|
|
32
|
+
## Dependency Analysis
|
|
33
|
+
|
|
34
|
+
- [ ] Map package-to-package dependencies
|
|
35
|
+
- [ ] Check for imports bypassing `index.ts` (direct internal imports)
|
|
36
|
+
- [ ] Identify shared type definitions (where do they live?)
|
|
37
|
+
- [ ] Check dependency direction consistency
|
|
38
|
+
|
|
39
|
+
## Naming Analysis
|
|
40
|
+
|
|
41
|
+
- [ ] File naming convention (consistent? mixed?)
|
|
42
|
+
- [ ] Directory naming convention
|
|
43
|
+
- [ ] Package naming convention
|
|
44
|
+
- [ ] Variable/function naming convention
|
|
45
|
+
|
|
46
|
+
## Report Generation
|
|
47
|
+
|
|
48
|
+
- [ ] Create `scout-report.md` in target repo root
|
|
49
|
+
- [ ] Include all metrics from tools
|
|
50
|
+
- [ ] Include problem severity classification (🔴/🟡/🟢)
|
|
51
|
+
- [ ] Include per-package breakdown for top packages
|
|
52
|
+
- [ ] Include recommendations (but NOT solutions — that's Architect's job)
|
|
53
|
+
|
|
54
|
+
## Deliverable
|
|
55
|
+
|
|
56
|
+
- [ ] `{{TARGET_REPO_PATH}}/scout-report.md` created
|
|
57
|
+
- [ ] All metrics captured
|
|
58
|
+
- [ ] No files modified in target repo
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<!-- FNH: Checklist — Phase 2 Planning | ROLE: Architect | MODEL: Claude Opus 4.6 -->
|
|
2
|
+
|
|
3
|
+
# Phase 2: Planning — Checklist
|
|
4
|
+
|
|
5
|
+
> **Role:** Architect | **Model:** Claude Opus 4.6 | **Mode:** Planning | **Goal:** Design target structure and create migration plan | **SECTIONS:** Target Architecture, Domain Boundaries, Skill Design, Workflow Map | **DEPS:** Phase 1
|
|
6
|
+
|
|
7
|
+
## Pre-flight
|
|
8
|
+
|
|
9
|
+
- [ ] Read `roles/architect.md` for full instructions
|
|
10
|
+
- [ ] Read `strategy/monorepo_strategy.md` for reference
|
|
11
|
+
- [ ] Read `{{TARGET_REPO_PATH}}/scout-report.md` for current state
|
|
12
|
+
- [ ] No files will be modified (planning-only phase)
|
|
13
|
+
|
|
14
|
+
## Target Structure Design
|
|
15
|
+
|
|
16
|
+
- [ ] Define package boundaries (what goes where)
|
|
17
|
+
- [ ] Define public API for each package (`index.ts` exports)
|
|
18
|
+
- [ ] Define shared types location (`packages/shared/types/`)
|
|
19
|
+
- [ ] Define dependency direction (routes → services → repos → entities)
|
|
20
|
+
- [ ] Draw dependency graph (no cycles)
|
|
21
|
+
- [ ] Verify all god-files have decomposition plan
|
|
22
|
+
|
|
23
|
+
## God-File Decomposition
|
|
24
|
+
|
|
25
|
+
For each god-file from scout-report:
|
|
26
|
+
|
|
27
|
+
- [ ] Identify logical domains within the file
|
|
28
|
+
- [ ] Plan target files (name, location, responsibility)
|
|
29
|
+
- [ ] Plan barrel exports (index.ts re-exports)
|
|
30
|
+
- [ ] Estimate effort (simple move vs refactor)
|
|
31
|
+
|
|
32
|
+
## Naming Convention Decision
|
|
33
|
+
|
|
34
|
+
- [ ] Decide on file naming: `kebab-case.ts`
|
|
35
|
+
- [ ] Decide on directory naming: `kebab-case`
|
|
36
|
+
- [ ] Decide on class naming: `PascalCase`
|
|
37
|
+
- [ ] Decide on package naming: `@scope/kebab-case`
|
|
38
|
+
- [ ] Document any exceptions
|
|
39
|
+
|
|
40
|
+
## Documentation Plan
|
|
41
|
+
|
|
42
|
+
- [ ] List all README.md files to create
|
|
43
|
+
- [ ] List all Knowledge Items to create (topics)
|
|
44
|
+
- [ ] List all Skills to create (recurring tasks)
|
|
45
|
+
- [ ] List all Workflows to create (routine procedures)
|
|
46
|
+
- [ ] Ensure the plan requires FNH headers on ALL files (no threshold exceptions)
|
|
47
|
+
|
|
48
|
+
## Migration Plan
|
|
49
|
+
|
|
50
|
+
- [ ] Define migration order (leaves first → roots last)
|
|
51
|
+
- [ ] Define checkpoints (build + test after each step)
|
|
52
|
+
- [ ] Identify parallel-safe steps
|
|
53
|
+
- [ ] Identify high-risk steps and mitigations
|
|
54
|
+
- [ ] Estimate total number of Surgeon conversations needed
|
|
55
|
+
|
|
56
|
+
## Risk Assessment
|
|
57
|
+
|
|
58
|
+
- [ ] List breaking changes
|
|
59
|
+
- [ ] List rollback strategy for each phase
|
|
60
|
+
- [ ] Identify tests that must pass at each checkpoint
|
|
61
|
+
- [ ] Note any external integrations affected
|
|
62
|
+
|
|
63
|
+
## Deliverable
|
|
64
|
+
|
|
65
|
+
- [ ] `{{TARGET_REPO_PATH}}/architecture-plan.md` created
|
|
66
|
+
- [ ] All sections filled with concrete details
|
|
67
|
+
- [ ] Plan reviewed and approved by human
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<!-- FNH: Checklist — Phase 3 Restructuring | ROLE: Surgeon | MODEL: Gemini 3.1 Pro -->
|
|
2
|
+
|
|
3
|
+
# Phase 3: Restructuring — Checklist
|
|
4
|
+
|
|
5
|
+
> **Role:** Surgeon | **Model:** Gemini 3.1 Pro (High) | **Mode:** Fast | **Goal:** Execute restructuring strictly per architecture-plan.md | **SECTIONS:** Move Files, Update Imports, Cleanup, Naming Consistency | **DEPS:** Phase 2
|
|
6
|
+
|
|
7
|
+
## Pre-flight
|
|
8
|
+
|
|
9
|
+
- [ ] Read `roles/surgeon.md` for full instructions
|
|
10
|
+
- [ ] Read `{{TARGET_REPO_PATH}}/architecture-plan.md`
|
|
11
|
+
- [ ] Ensure build passes BEFORE starting: `{{BUILD_COMMAND}}`
|
|
12
|
+
- [ ] Ensure tests pass BEFORE starting: `{{TEST_COMMAND}}`
|
|
13
|
+
- [ ] Create git branch: `git checkout -b ai-context-surgeon/restructure`
|
|
14
|
+
|
|
15
|
+
## Phase 3a: Foundation (Shared Types & Entities)
|
|
16
|
+
|
|
17
|
+
- [ ] Create `packages/shared/` structure (if needed)
|
|
18
|
+
- [ ] Move shared types to `packages/shared/src/types/`
|
|
19
|
+
- [ ] Create `packages/shared/src/index.ts` with exports
|
|
20
|
+
- [ ] Update all imports across the monorepo
|
|
21
|
+
- [ ] **Checkpoint:** `{{BUILD_COMMAND}}` ✅
|
|
22
|
+
|
|
23
|
+
## Phase 3b: Core Logic
|
|
24
|
+
|
|
25
|
+
- [ ] Restructure `packages/core/` per plan
|
|
26
|
+
- [ ] Decompose god-files per plan
|
|
27
|
+
- [ ] Create `packages/core/src/index.ts` with public API
|
|
28
|
+
- [ ] Create `packages/core/src/types.ts` with contracts
|
|
29
|
+
- [ ] Update all imports
|
|
30
|
+
- [ ] **Checkpoint:** `{{BUILD_COMMAND}}` ✅
|
|
31
|
+
|
|
32
|
+
## Phase 3c: Service Layer
|
|
33
|
+
|
|
34
|
+
- [ ] Restructure service packages per plan
|
|
35
|
+
- [ ] Ensure services import from core via `index.ts` only
|
|
36
|
+
- [ ] Create `src/index.ts` and `src/types.ts` for each
|
|
37
|
+
- [ ] Update all imports
|
|
38
|
+
- [ ] **Checkpoint:** `{{BUILD_COMMAND}}` ✅
|
|
39
|
+
|
|
40
|
+
## Phase 3d: API / Presentation Layer
|
|
41
|
+
|
|
42
|
+
- [ ] Restructure API/web packages per plan
|
|
43
|
+
- [ ] Ensure routes/pages import from services via `index.ts` only
|
|
44
|
+
- [ ] Create `src/index.ts` for each
|
|
45
|
+
- [ ] Update all imports
|
|
46
|
+
- [ ] **Checkpoint:** `{{BUILD_COMMAND}}` ✅
|
|
47
|
+
|
|
48
|
+
## Phase 3e: Apps Layer
|
|
49
|
+
|
|
50
|
+
- [ ] Restructure apps per plan
|
|
51
|
+
- [ ] Verify all apps build
|
|
52
|
+
- [ ] **Checkpoint:** `{{BUILD_COMMAND}} && {{TEST_COMMAND}}` ✅
|
|
53
|
+
|
|
54
|
+
## Post-restructuring
|
|
55
|
+
|
|
56
|
+
- [ ] Full build: `{{BUILD_COMMAND}}` ✅
|
|
57
|
+
- [ ] Full tests: `{{TEST_COMMAND}}` ✅
|
|
58
|
+
- [ ] Type check: `tsc --noEmit` ✅
|
|
59
|
+
- [ ] No files left in wrong locations
|
|
60
|
+
- [ ] All god-files decomposed
|
|
61
|
+
- [ ] No circular dependencies: `tools/detect-circular-deps.sh`
|
|
62
|
+
- [ ] Git commit: `git add -A && git commit -m "ai-context-surgeon: restructure complete"`
|
|
63
|
+
|
|
64
|
+
## Rules During Restructuring
|
|
65
|
+
|
|
66
|
+
- ⚠️ After EVERY file move → update imports → build check
|
|
67
|
+
- ⚠️ If build breaks → fix IMMEDIATELY, don't proceed
|
|
68
|
+
- ⚠️ Never change business logic — only move and rename
|
|
69
|
+
- ⚠️ One logical step per conversation (if large)
|
|
70
|
+
- ⚠️ Follow plan exactly — no improvisation
|
|
71
|
+
|
|
72
|
+
## Deliverable
|
|
73
|
+
|
|
74
|
+
- [ ] All files restructured per architecture-plan.md
|
|
75
|
+
- [ ] Build passes
|
|
76
|
+
- [ ] Tests pass
|
|
77
|
+
- [ ] Clean git history on `ai-context-surgeon/restructure` branch
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<!-- FNH: Checklist — Phase 4 Documentation | ROLE: Librarian / Tuner | MODEL: Claude Sonnet / Opus -->
|
|
2
|
+
|
|
3
|
+
# Phase 4: Documentation — Checklist
|
|
4
|
+
|
|
5
|
+
> **Role:** Librarian / Tuner | **Model:** Claude Sonnet / Opus 4.6 | **Mode:** Planning | **Goal:** Create complete documentation and configuration | **SECTIONS:** FNH Headers, JSDoc, package.json, Strategy Docs, Templates | **DEPS:** Phase 3
|
|
6
|
+
|
|
7
|
+
## Pre-flight
|
|
8
|
+
|
|
9
|
+
- [ ] Read `roles/librarian.md` for documentation instructions
|
|
10
|
+
- [ ] Read `roles/tuner.md` for configuration instructions
|
|
11
|
+
- [ ] Read `{{TARGET_REPO_PATH}}/architecture-plan.md` "Documentation Plan" section
|
|
12
|
+
- [ ] Have templates from `ai-context-surgeon/templates/` ready
|
|
13
|
+
|
|
14
|
+
## 4a: READMEs (Librarian)
|
|
15
|
+
|
|
16
|
+
### Root README
|
|
17
|
+
|
|
18
|
+
- [ ] Create/update root `README.md`
|
|
19
|
+
- [ ] Include project description (2–3 sentences)
|
|
20
|
+
- [ ] Include architecture map (tree with `←` descriptions)
|
|
21
|
+
- [ ] Include key technology decisions
|
|
22
|
+
- [ ] Include getting started instructions
|
|
23
|
+
|
|
24
|
+
### Package READMEs
|
|
25
|
+
|
|
26
|
+
For each package in `packages/` and `apps/`:
|
|
27
|
+
|
|
28
|
+
- [ ] Create `README.md` using `templates/package-readme.template`
|
|
29
|
+
- [ ] Include Source Structure section with `←` descriptions
|
|
30
|
+
- [ ] Include dependencies table
|
|
31
|
+
- [ ] Include public API summary
|
|
32
|
+
- [ ] Include relevant environment variables
|
|
33
|
+
- [ ] Include build/test scripts
|
|
34
|
+
|
|
35
|
+
## 4b: Knowledge Items (Librarian)
|
|
36
|
+
|
|
37
|
+
- [ ] Create `.agents/knowledge/` directory structure
|
|
38
|
+
- [ ] Create KI: `database-schema` (if DB exists)
|
|
39
|
+
- [ ] Create KI: `api-conventions` (if API exists)
|
|
40
|
+
- [ ] Create KI: `auth-flow` (if auth exists)
|
|
41
|
+
- [ ] Create KI: `error-handling` (error patterns)
|
|
42
|
+
- [ ] Create KI: `deployment` (deploy process)
|
|
43
|
+
- [ ] Each KI has `metadata.json` + `artifacts/*.md`
|
|
44
|
+
- [ ] Each KI follows atomicity principle (one topic)
|
|
45
|
+
- [ ] Each KI is concrete and actionable (not vague)
|
|
46
|
+
- [ ] Content must be entirely in English
|
|
47
|
+
|
|
48
|
+
## 4c: Skills (Librarian)
|
|
49
|
+
|
|
50
|
+
- [ ] Create `.agents/skills/` directory structure
|
|
51
|
+
- [ ] Create Skill: `create-endpoint` (if API project)
|
|
52
|
+
- [ ] Create Skill: `create-package` (for new packages)
|
|
53
|
+
- [ ] Create Skill: `db-migration` (if DB exists)
|
|
54
|
+
- [ ] Each Skill has `SKILL.md` with frontmatter
|
|
55
|
+
- [ ] Each Skill has "When to Use" / "When NOT to Use"
|
|
56
|
+
- [ ] Each Skill has step-by-step instructions
|
|
57
|
+
- [ ] Each Skill has template code
|
|
58
|
+
- [ ] Content must be entirely in English
|
|
59
|
+
|
|
60
|
+
## 4d: Workflows (Librarian)
|
|
61
|
+
|
|
62
|
+
- [ ] Create `.agents/workflows/` directory structure
|
|
63
|
+
- [ ] Create Workflow: `test.md` — run tests for a package
|
|
64
|
+
- [ ] Create Workflow: `build.md` — build verification
|
|
65
|
+
- [ ] Create Workflow: `lint-fix.md` — auto-fix lint issues
|
|
66
|
+
- [ ] Each Workflow has `description:` frontmatter
|
|
67
|
+
- [ ] Each Workflow has explicit commands
|
|
68
|
+
- [ ] Appropriate `// turbo` annotations
|
|
69
|
+
- [ ] Content must be entirely in English
|
|
70
|
+
|
|
71
|
+
## 4e: FNH Headers (Librarian)
|
|
72
|
+
|
|
73
|
+
- [ ] Ensure EVERY source file has an FNH header
|
|
74
|
+
- [ ] Run `tools/check-fnh-freshness.sh` to preview gaps
|
|
75
|
+
- [ ] Headers must all be in English
|
|
76
|
+
- [ ] Headers must follow the 5 mandatory layers
|
|
77
|
+
|
|
78
|
+
## 4f: AGENTS.md (Tuner)
|
|
79
|
+
|
|
80
|
+
- [ ] Create `.agents/AGENTS.md` using `templates/AGENTS.md.template`
|
|
81
|
+
- [ ] Fill all placeholders with project-specific values
|
|
82
|
+
- [ ] Include "Read README first" rule
|
|
83
|
+
- [ ] Include "Stay within package" rule
|
|
84
|
+
- [ ] Include "Max 5 files before work" rule
|
|
85
|
+
- [ ] Include FNH freshness rule
|
|
86
|
+
- [ ] Include English-only content rule
|
|
87
|
+
- [ ] Include dependency direction rules
|
|
88
|
+
- [ ] Include naming conventions
|
|
89
|
+
- [ ] Include build/test commands
|
|
90
|
+
- [ ] Include package ownership table
|
|
91
|
+
- [ ] Review for contradictions or ambiguity
|
|
92
|
+
|
|
93
|
+
## 4g: Config Tuning (Tuner)
|
|
94
|
+
|
|
95
|
+
- [ ] Create root `.antigravityignore` excluding lock files and build artifacts
|
|
96
|
+
- [ ] Verify/update `turbo.json` or `nx.json` pipeline
|
|
97
|
+
- [ ] Verify/update root `tsconfig.json` project references
|
|
98
|
+
- [ ] Verify `.gitignore` includes ai-context-surgeon temp files
|
|
99
|
+
- [ ] Verify `package.json` scripts are correct
|
|
100
|
+
|
|
101
|
+
## Deliverable
|
|
102
|
+
|
|
103
|
+
- [ ] Root README.md ✅
|
|
104
|
+
- [ ] All package READMEs ✅
|
|
105
|
+
- [ ] Knowledge Items created ✅
|
|
106
|
+
- [ ] Skills created ✅
|
|
107
|
+
- [ ] Workflows created ✅
|
|
108
|
+
- [ ] FNH headers present on all files ✅
|
|
109
|
+
- [ ] AGENTS.md configured ✅
|
|
110
|
+
- [ ] .antigravityignore created ✅
|
|
111
|
+
- [ ] Build configs verified ✅
|