@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.
Files changed (87) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +372 -0
  3. package/bin/catalog.js +153 -0
  4. package/bin/cli.js +380 -0
  5. package/bin/installer.js +135 -0
  6. package/bin/prompts.js +371 -0
  7. package/checklists/phase-1-analysis.md +58 -0
  8. package/checklists/phase-2-planning.md +67 -0
  9. package/checklists/phase-3-restructuring.md +77 -0
  10. package/checklists/phase-4-documentation.md +111 -0
  11. package/checklists/phase-5-validation.md +91 -0
  12. package/examples/before-after/README.md +139 -0
  13. package/examples/ideal-monorepo/README.md +127 -0
  14. package/knowledge/agent-context-system/artifacts/guide.md +183 -0
  15. package/knowledge/agent-context-system/artifacts/knowledge.md +177 -0
  16. package/knowledge/agent-context-system/artifacts/skills.md +101 -0
  17. package/knowledge/agent-context-system/artifacts/workflows.md +143 -0
  18. package/knowledge/agent-context-system/metadata.json +26 -0
  19. package/knowledge/agent-context-system/timestamps.json +5 -0
  20. package/knowledge/agent-vulnerabilities/LICENSE +21 -0
  21. package/knowledge/agent-vulnerabilities/artifacts/stealth_injection.md +110 -0
  22. package/knowledge/agent-vulnerabilities/artifacts/vulnerabilities.md +232 -0
  23. package/knowledge/agent-vulnerabilities/metadata.json +14 -0
  24. package/knowledge/agent-vulnerabilities/timestamps.json +5 -0
  25. package/knowledge/power-words-dictionary/LICENSE +21 -0
  26. package/knowledge/power-words-dictionary/artifacts/dictionary.md +231 -0
  27. package/knowledge/power-words-dictionary/artifacts/prompt_amplifier.py +381 -0
  28. package/knowledge/power-words-dictionary/metadata.json +14 -0
  29. package/knowledge/power-words-dictionary/timestamps.json +5 -0
  30. package/package.json +77 -0
  31. package/roles/README.md +81 -0
  32. package/roles/architect.md +203 -0
  33. package/roles/inspector.md +232 -0
  34. package/roles/librarian.md +176 -0
  35. package/roles/scout.md +169 -0
  36. package/roles/surgeon.md +172 -0
  37. package/roles/tuner.md +204 -0
  38. package/skills/annotate-jsdoc/SKILL.md +262 -0
  39. package/skills/prompt-engineering/LICENSE +21 -0
  40. package/skills/prompt-engineering/SKILL.md +235 -0
  41. package/skills/prompt-engineering/scripts/extract_instructions.py +416 -0
  42. package/skills/prompt-engineering/scripts/prompt_amplifier.py +381 -0
  43. package/skills/prompt-engineering/scripts/prompt_diff_tracker.py +281 -0
  44. package/skills/prompt-engineering/scripts/prompt_dna_analyzer.py +692 -0
  45. package/skills/prompt-engineering/scripts/templates/code_review.md +47 -0
  46. package/skills/prompt-engineering/scripts/templates/dump_extraction.md +59 -0
  47. package/skills/prompt-engineering/scripts/templates/multi_agent_orchestration.md +100 -0
  48. package/skills/prompt-engineering/scripts/templates/prompt_audit.md +106 -0
  49. package/skills/prompt-engineering/scripts/templates/stealth_injection.md +110 -0
  50. package/skills/prompt-engineering/scripts/templates/task_automation.md +87 -0
  51. package/skills/prompt-engineering/workflows/amplify.md +36 -0
  52. package/skills/prompt-engineering/workflows/audit.md +55 -0
  53. package/skills/prompt-engineering/workflows/context-dump.md +90 -0
  54. package/skills/prompt-engineering/workflows/diff.md +44 -0
  55. package/strategy/bash-guide.md +134 -0
  56. package/strategy/context-exclusion.md +220 -0
  57. package/strategy/context-weight-theory.md +49 -0
  58. package/strategy/file-navigation-header.md +562 -0
  59. package/strategy/jsdoc-guide.md +596 -0
  60. package/strategy/monorepo_strategy.md +726 -0
  61. package/strategy/package-json-guide.md +541 -0
  62. package/templates/AGENTS.md.template +148 -0
  63. package/templates/antigravityignore.template +64 -0
  64. package/templates/cursorrules.template +7 -0
  65. package/templates/knowledge-item.template +44 -0
  66. package/templates/package-json-ideal.template +26 -0
  67. package/templates/package-readme.template +45 -0
  68. package/templates/publish-meta.template +34 -0
  69. package/templates/skill.template +50 -0
  70. package/templates/workflow.template +33 -0
  71. package/tools/analyze-package-json.sh +213 -0
  72. package/tools/analyze-structure.sh +101 -0
  73. package/tools/audit-jsdoc.sh +176 -0
  74. package/tools/check-fnh-freshness.sh +74 -0
  75. package/tools/detect-circular-deps.sh +147 -0
  76. package/tools/detect-god-files.sh +71 -0
  77. package/tools/enforce-god-files.sh +112 -0
  78. package/tools/enrich-package-json.js +311 -0
  79. package/tools/generate-jsdoc-headers.sh +109 -0
  80. package/tools/generate-source-map.sh +71 -0
  81. package/tools/lint-imports.sh +123 -0
  82. package/tools/measure-context-cost.sh +206 -0
  83. package/tools/scan-fnh.sh +174 -0
  84. package/tools/shared/config.sh +53 -0
  85. package/tools/validate-context-hygiene.sh +52 -0
  86. package/tools/validate-context-weight.sh +100 -0
  87. package/tools/validate-naming.sh +98 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ <!-- FNH: Legal — MIT License | SECTIONS: Permissions, Conditions, Disclaimer | DEPS: none -->
2
+ MIT License
3
+
4
+ Copyright (c) 2026 Aleksandr Ivannikov, https://ivannikov.pro <hi@ivannikov.pro>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,372 @@
1
+ <!-- FNH: Project — ai-context-surgeon AI-native Knowledge API | SECTIONS: Quick Start, For AI Agents, Catalog, CLI, Tools, Roles, Prompts, Workflows, Strategy, Source Structure | DEPS: none -->
2
+
3
+ # ai-context-surgeon
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@ivannikov-pro/ai-context-surgeon.svg)](https://www.npmjs.com/package/@ivannikov-pro/ai-context-surgeon)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ > Toolkit: ai-context-surgeon — an AI-native Knowledge API for autonomous agents doing surgical monorepo restructuring. Roles, strategies, prompts, skills, templates, and analysis tools — all accessible on-demand via CLI. No install required. | SECTIONS: Quick Start, For AI Agents, Catalog, CLI, Tools, Roles, Prompts, Workflows, Strategy, Source Structure | DEPS: none
9
+
10
+ **ai-context-surgeon** is a Knowledge API, not a traditional CLI tool. It provides on-demand access to roles, strategies, prompts, skills, templates, and analysis tools — everything an AI agent needs to optimize a monorepo's context for minimal token consumption.
11
+
12
+ ---
13
+
14
+ ## 🚀 Quick Start
15
+
16
+ ```bash
17
+ # Browse everything available
18
+ npx -y @ivannikov-pro/ai-context-surgeon@latest catalog
19
+
20
+ # Run repo analysis
21
+ npx -y @ivannikov-pro/ai-context-surgeon@latest radar
22
+
23
+ # Get a role prompt for the AI agent to follow
24
+ npx -y @ivannikov-pro/ai-context-surgeon@latest role scout
25
+
26
+ # Get condensed task instructions (~60 tokens instead of ~2800)
27
+ npx -y @ivannikov-pro/ai-context-surgeon@latest prompt fnh
28
+
29
+ # Lightweight project setup
30
+ npx -y @ivannikov-pro/ai-context-surgeon@latest init
31
+ ```
32
+
33
+ ---
34
+
35
+ ## 🤖 For AI Agents
36
+
37
+ The npm package IS the knowledge base. The CLI IS the API.
38
+ No files to copy. No install to maintain. Always the latest version.
39
+
40
+ ```bash
41
+ # Step 1: Discover everything available
42
+ npx @ivannikov-pro/ai-context-surgeon@latest catalog
43
+
44
+ # Step 2: Read a role prompt and follow its instructions
45
+ npx @ivannikov-pro/ai-context-surgeon@latest role scout
46
+
47
+ # Step 3: Run analysis tools
48
+ npx @ivannikov-pro/ai-context-surgeon@latest radar
49
+ npx @ivannikov-pro/ai-context-surgeon@latest context-weight
50
+
51
+ # Step 4: Get specific instructions for a task (saves 95% tokens)
52
+ npx @ivannikov-pro/ai-context-surgeon@latest prompt fnh # How to create FNH headers
53
+ npx @ivannikov-pro/ai-context-surgeon@latest prompt jsdoc # How to write JSDoc
54
+ npx @ivannikov-pro/ai-context-surgeon@latest prompt god-file # How to split large files
55
+ npx @ivannikov-pro/ai-context-surgeon@latest prompt readme # How to write package READMEs
56
+ npx @ivannikov-pro/ai-context-surgeon@latest prompt agent-rules # How to write AGENTS.md
57
+ npx @ivannikov-pro/ai-context-surgeon@latest prompt context-exclusion # How to set up .antigravityignore
58
+
59
+ # Step 5: Read strategy docs when needed (full reference)
60
+ npx @ivannikov-pro/ai-context-surgeon@latest strategy fnh
61
+ npx @ivannikov-pro/ai-context-surgeon@latest strategy monorepo
62
+
63
+ # Step 6: Delegate — output a role prompt and send to another agent
64
+ npx @ivannikov-pro/ai-context-surgeon@latest role architect --output .agents/architect-prompt.md
65
+ ```
66
+
67
+ ---
68
+
69
+ ## 📈 Token Savings: Before / After
70
+
71
+ ```text
72
+ ╔═══════════════════════════════════════════════════════════════╗
73
+ ║ LEVEL 1: Blind Navigation (No rules) ║
74
+ ║ Agent reads 10 files ~3,300 lines ≈ 8,000 tokens ║
75
+ ╠═══════════════════════════════════════════════════════════════╣
76
+ ║ LEVEL 2: Traditional Docs (Reading markdown files) ║
77
+ ║ Agent reads strategy doc ~560 lines ≈ 2,800 tokens ║
78
+ ╠═══════════════════════════════════════════════════════════════╣
79
+ ║ LEVEL 3: ai-context-surgeon (Knowledge API) ║
80
+ ║ Agent calls `prompt fnh` ≈ 60 tokens ║
81
+ ╠═══════════════════════════════════════════════════════════════╣
82
+ ║ SAVINGS: 99.3% (from 8,000 → 60 tokens per task) ║
83
+ ╚═══════════════════════════════════════════════════════════════╝
84
+ ```
85
+
86
+ | Scenario | Tokens | Method |
87
+ | --- | ---: | --- |
88
+ | Blind repo navigation | ~8,000 | Agent reads random files |
89
+ | Traditional Markdown Docs | ~2,800 | Agent reads `strategy/file-navigation-header.md` |
90
+ | **Knowledge API** | **~60** | Agent calls `prompt fnh` |
91
+
92
+ **JSDoc annotation example:**
93
+
94
+ ```typescript
95
+ // BEFORE (220 tokens of noise):
96
+ /**
97
+ * @fileoverview User Service
98
+ * @author Jane Developer
99
+ * @since 2024-03-15
100
+ */
101
+ export class UserService {
102
+ /** @param {CreateUserInput} input @returns {Promise<User>} */
103
+ async create(input: CreateUserInput): Promise<User> { ... }
104
+ }
105
+
106
+ // AFTER (40 tokens — 82% reduction):
107
+ /** Service: UserService — CRUD + auth | deps: prisma, bcrypt */
108
+ export class UserService {
109
+ /** @throws Conflict(email) | hashes pw bcrypt 12 | sends welcome email */
110
+ async create(input: CreateUserInput): Promise<User> { ... }
111
+ }
112
+ ```
113
+
114
+ ---
115
+
116
+ ## 📋 Catalog
117
+
118
+ ```bash
119
+ npx @ivannikov-pro/ai-context-surgeon@latest catalog
120
+ ```
121
+
122
+ | Category | Command | Count | Description |
123
+ | --- | --- | ---: | --- |
124
+ | 🔧 Tools | `radar`, `godfiles`, `circular`, `context-weight`, `sourcemaps` | 5 | Run analysis directly against any repo |
125
+ | 🎭 Roles | `role <name>` | 6 | Agent role prompts (scout → inspector) |
126
+ | 📖 Strategies | `strategy <name>` | 7 | Full reference docs (FNH, monorepo, JSDoc, ...) |
127
+ | 💡 Prompts | `prompt <task>` | 6 | Condensed task instructions (~60 tokens each) |
128
+ | 🧩 Skills | `skill <name>` | 2 | Reusable agent procedures |
129
+ | 📝 Templates | `template <name>` | 9 | File seeds (AGENTS.md, README, package.json, ...) |
130
+ | 📋 Checklists | `checklist <n>` | 5 | Phase task lists (1–5) |
131
+ | 🧠 Knowledge | `knowledge <name>` | 3 | Reference knowledge items |
132
+
133
+ ---
134
+
135
+ ## 🖥️ CLI Commands
136
+
137
+ ### Content Access
138
+
139
+ | Command | Description |
140
+ | --- | --- |
141
+ | `catalog` | List all available content across all categories |
142
+ | `role <name>` | Output an agent role prompt |
143
+ | `strategy <name>` | Output a strategy document |
144
+ | `prompt <task>` | Output a condensed task prompt |
145
+ | `skill <name>` | Output a skill procedure |
146
+ | `template <name>` | Output a file template |
147
+ | `checklist <n>` | Output a phase checklist (1–5) |
148
+ | `knowledge <name>` | Output a knowledge item |
149
+
150
+ All content commands support `--output <path>` to save to a file:
151
+ ```bash
152
+ npx @ivannikov-pro/ai-context-surgeon@latest role scout --output .agents/scout.md
153
+ npx @ivannikov-pro/ai-context-surgeon@latest checklist 1 --output .agents/phase-1.md
154
+ ```
155
+
156
+ ### Tool Execution
157
+
158
+ | Command | Script | Description |
159
+ | --- | --- | --- |
160
+ | `radar` | `scan-fnh.sh` | Semantic FNH map of any repository |
161
+ | `godfiles` | `detect-god-files.sh` | Find files exceeding LOC thresholds |
162
+ | `circular` | `detect-circular-deps.sh` | Detect circular dependencies |
163
+ | `context-weight` | `validate-context-weight.sh` | Identify files with high cognitive load (LOC + Fan-out) |
164
+ | `sourcemaps` | `generate-source-map.sh` | Generate AI-friendly structure trees |
165
+
166
+ ### Project Setup
167
+
168
+ | Command | Description |
169
+ | --- | --- |
170
+ | `init` | Creates `AGENTS.md`, `.antigravityignore`, and injects CI scripts into `package.json` |
171
+
172
+ After `init`, these CI gates are available in `package.json`:
173
+ ```bash
174
+ npm run check:hygiene # FNH radar scan
175
+ npm run check:god-files # God file detection
176
+ ```
177
+
178
+ ---
179
+
180
+ ## 💡 Prompt Library
181
+
182
+ Available via `prompt <task>` — each prompt is ~60 tokens vs ~2800 for the full strategy doc.
183
+
184
+ | Key | Name | Description |
185
+ | --- | --- | --- |
186
+ | `fnh` | File Navigation Header | How to create FNH headers for any file type (all 5 mandatory layers) |
187
+ | `jsdoc` | JSDoc Annotation | How to write AI-optimized JSDoc (what to annotate, what to skip) |
188
+ | `readme` | Package README | How to write a README with Source Structure for AI agents |
189
+ | `agent-rules` | AGENTS.md | How to write an AGENTS.md for any repository |
190
+ | `context-exclusion` | Context Exclusion | How to configure `.antigravityignore` / `.aiignore` |
191
+ | `god-file` | God File Splitting | How to split files >300 lines into focused modules |
192
+
193
+ **Examples:**
194
+ ```bash
195
+ npx @ivannikov-pro/ai-context-surgeon@latest prompt fnh
196
+ npx @ivannikov-pro/ai-context-surgeon@latest prompt god-file
197
+ npx @ivannikov-pro/ai-context-surgeon@latest prompt jsdoc --output /tmp/jsdoc-task.md
198
+ ```
199
+
200
+ ---
201
+
202
+ ## 🎭 Agent Roles
203
+
204
+ 6 specialized roles for the 5-phase optimization pipeline:
205
+
206
+ | Role | Phase | Description | Model | Mode |
207
+ | --- | --- | --- | --- | --- |
208
+ | **Scout** | 1 — Analysis | Context reconnaissance, FNH radar, telemetry gathering | Gemini 3 Flash | Fast |
209
+ | **Architect** | 2 — Planning | Design decisions, refactoring plan, package boundaries | Claude Opus 4.6 / Gemini 3.1 Pro | Planning |
210
+ | **Surgeon** | 3 — Restructuring | Surgical code splitting, import fixing, god-file extraction | Gemini 3.1 Pro (High) | Fast |
211
+ | **Librarian** | 4a — Documentation | FNH headers, JSDoc, package READMEs, Source Structure | Claude Sonnet 4.6 | Planning |
212
+ | **Tuner** | 4b — Configuration | AGENTS.md, `.antigravityignore`, package.json, CI scripts | Claude Opus 4.6 | Planning |
213
+ | **Inspector** | 5 — Validation | Scoring, health checks, before/after comparison, sign-off | Gemini 3.1 Pro (High) | Planning |
214
+
215
+ ```bash
216
+ # Load a role into the current agent
217
+ npx @ivannikov-pro/ai-context-surgeon@latest role scout
218
+
219
+ # Full pipeline delegation
220
+ npx @ivannikov-pro/ai-context-surgeon@latest role scout # → reconnaissance
221
+ npx @ivannikov-pro/ai-context-surgeon@latest role architect # → plan
222
+ npx @ivannikov-pro/ai-context-surgeon@latest role surgeon # → execute
223
+ npx @ivannikov-pro/ai-context-surgeon@latest role librarian # → document
224
+ npx @ivannikov-pro/ai-context-surgeon@latest role tuner # → configure
225
+ npx @ivannikov-pro/ai-context-surgeon@latest role inspector # → validate
226
+ ```
227
+
228
+ ---
229
+
230
+ ## 🔧 Analysis Tools
231
+
232
+ All 16 shell scripts in `tools/` plus one Node.js enrichment tool:
233
+
234
+ | Tool | CLI Command | Description |
235
+ | --- | --- | --- |
236
+ | `scan-fnh.sh` | `radar` | Extract FNH headers from all files — semantic repo map |
237
+ | `detect-god-files.sh` | `godfiles` | Flag files exceeding LOC thresholds (default >300) |
238
+ | `detect-circular-deps.sh` | `circular` | Find circular import chains between packages |
239
+ | `validate-context-weight.sh` | `context-weight` | Compute cognitive load (LOC + Fan-out × 20 formula) |
240
+ | `generate-source-map.sh` | `sourcemaps` | Build Source Structure block for README |
241
+ | `analyze-structure.sh` | — | Full monorepo structure metrics and overview |
242
+ | `analyze-package-json.sh` | — | Rate package.json AI-readiness (Tier 1–4 scoring) |
243
+ | `audit-jsdoc.sh` | — | Analyze JSDoc coverage and quality |
244
+ | `check-fnh-freshness.sh` | — | Warn when source changed but FNH header wasn't updated |
245
+ | `lint-imports.sh` | — | Detect cross-package boundary violations |
246
+ | `measure-context-cost.sh` | — | Estimate AI agent context cost for a package |
247
+ | `generate-jsdoc-headers.sh` | — | Add JSDoc navigation headers to source files |
248
+ | `enforce-god-files.sh` | — | CI gate — fail build if files exceed line thresholds |
249
+ | `validate-context-hygiene.sh` | — | CI gate — ensure all packages have README and ignores |
250
+ | `validate-naming.sh` | — | Check kebab-case and naming conventions |
251
+ | `enrich-package-json.js` | — | Lean/Enrich workflow — inject publish metadata before `npm publish` |
252
+
253
+ ---
254
+
255
+ ## 🔄 Full-Pipeline Workflow Summary
256
+
257
+ | Phase | Role | Checklist | Tools Used | Output |
258
+ | --- | --- | --- | --- | --- |
259
+ | 1 — Analysis | Scout | `checklist 1` | `radar`, `godfiles`, `context-weight`, `circular` | Telemetry report |
260
+ | 2 — Planning | Architect | `checklist 2` | `analyze-structure.sh`, `analyze-package-json.sh` | Refactoring plan |
261
+ | 3 — Restructuring | Surgeon | `checklist 3` | `lint-imports.sh`, `check-fnh-freshness.sh` | Split files, fixed imports |
262
+ | 4a — Documentation | Librarian | `checklist 4` | `audit-jsdoc.sh`, `generate-jsdoc-headers.sh` | FNH headers, JSDoc, READMEs |
263
+ | 4b — Configuration | Tuner | `checklist 4` | `validate-naming.sh`, `validate-context-hygiene.sh` | AGENTS.md, CI scripts |
264
+ | 5 — Validation | Inspector | `checklist 5` | `radar`, `context-weight`, `enforce-god-files.sh` | Score report, sign-off |
265
+
266
+ Invoke the full pipeline via workflow:
267
+ ```bash
268
+ # Analyzes a target repo (requires target path argument)
269
+ npx @ivannikov-pro/ai-context-surgeon@latest # → interactive menu
270
+ ```
271
+
272
+ Or use pre-built agent workflows (defined in `.agents/workflows/`):
273
+ - `/analyze-repo` — Quick analysis using Scout + tools
274
+ - `/full-pipeline` — Complete 5-phase cascade
275
+ - `/self-check` — Validate ai-context-surgeon's own integrity
276
+
277
+ ---
278
+
279
+ ## 📖 Strategy Docs
280
+
281
+ All accessible via `strategy <key>` — read on-demand, no install:
282
+
283
+ | Key | Document | Size | Description |
284
+ | --- | --- | --- | --- |
285
+ | `fnh` | File Navigation Headers | ~560 lines | Universal header format for every file type |
286
+ | `monorepo` | Monorepo Strategy | ~700 lines | Architectural patterns and package boundaries |
287
+ | `jsdoc` | JSDoc Guide | ~600 lines | Token-efficient annotation standards |
288
+ | `package-json` | package.json Guide | ~540 lines | Tier 1–4 field priority, Lean+Enrich workflow |
289
+ | `context-exclusion` | Context Exclusion | ~200 lines | .antigravityignore patterns and philosophy |
290
+ | `bash` | Bash Guide | ~180 lines | Writing POSIX scripts for AI agents |
291
+ | `context-weight` | Context Weight Theory | ~120 lines | LOC + Fan-out cognitive load formula |
292
+
293
+ ---
294
+
295
+ ## 🧩 Skills
296
+
297
+ Reusable agent procedures — a skill is a self-contained, step-by-step instruction set:
298
+
299
+ | Key | Name | Description |
300
+ | --- | --- | --- |
301
+ | `annotate-jsdoc` | Annotate JSDoc | Reusable JSDoc/FNH injection procedure |
302
+ | `prompt-engineering` | Prompt Engineering | Prompt analysis, amplification, and extraction |
303
+
304
+ ```bash
305
+ npx @ivannikov-pro/ai-context-surgeon@latest skill annotate-jsdoc
306
+ ```
307
+
308
+ ---
309
+
310
+ ## 📝 Templates
311
+
312
+ File seeds for new projects — all use `{{UPPER_SNAKE_CASE}}` placeholders:
313
+
314
+ | Key | Template | Description |
315
+ | --- | --- | --- |
316
+ | `agents` | `AGENTS.md.template` | Agent rules with Navigation Rules, FNH, ai-context-surgeon Quick Reference |
317
+ | `readme` | `package-readme.template` | Package README with Source Structure and Scripts |
318
+ | `package-json` | `package-json-ideal.template` | Lean package.json (Tier 1 order, ≤30 lines) |
319
+ | `workflow` | `workflow.template` | Executable workflow with `// turbo` annotations |
320
+ | `skill` | `skill.template` | Skill definition with When/When-Not/Steps/Verify |
321
+ | `knowledge` | `knowledge-item.template` | Knowledge item (metadata.json + artifacts/) |
322
+ | `publish-meta` | `publish-meta.template` | Publish metadata for Lean+Enrich workflow |
323
+ | `antigravityignore` | `antigravityignore.template` | Context exclusion rules |
324
+ | `cursorrules` | `cursorrules.template` | Cursor / Windsurf IDE agent rules |
325
+
326
+ ```bash
327
+ npx @ivannikov-pro/ai-context-surgeon@latest template agents
328
+ npx @ivannikov-pro/ai-context-surgeon@latest template agents --output AGENTS.md
329
+ ```
330
+
331
+ ---
332
+
333
+ ## 🧠 Knowledge Items
334
+
335
+ Pre-loaded reference knowledge for agents:
336
+
337
+ | Key | Name | Description |
338
+ | --- | --- | --- |
339
+ | `agent-context` | Agent Context System | How Knowledge/Skills/Workflows work in AI agents |
340
+ | `vulnerabilities` | Agent Vulnerabilities | AI agent vulnerability patterns and bypass techniques |
341
+ | `power-words` | Power Words Dictionary | Enforcement directive vocabulary for AI prompts |
342
+
343
+ ```bash
344
+ npx @ivannikov-pro/ai-context-surgeon@latest knowledge agent-context
345
+ ```
346
+
347
+ ---
348
+
349
+ ## 📂 Source Structure
350
+
351
+ See [STRUCTURE.md](STRUCTURE.md) for the complete verbose file and directory map.
352
+
353
+ ---
354
+
355
+ ## 🛡️ CI/CD Integration
356
+
357
+ After `init`, inject these gates into your CI pipeline:
358
+
359
+ ```bash
360
+ npm run check:hygiene # FNH radar scan — verifies all files have headers
361
+ npm run check:god-files # God file detection — fails if any file exceeds 300 LOC
362
+ ```
363
+
364
+ Or run tools directly against any target repo:
365
+ ```bash
366
+ npx @ivannikov-pro/ai-context-surgeon@latest radar /path/to/repo
367
+ npx @ivannikov-pro/ai-context-surgeon@latest godfiles /path/to/repo
368
+ ```
369
+
370
+ ---
371
+
372
+ _ai-context-surgeon | [MIT](LICENSE) | [npm](https://www.npmjs.com/package/@ivannikov-pro/ai-context-surgeon) | [GitHub](https://github.com/ivannikov-pro/ai-context-surgeon)_
package/bin/catalog.js ADDED
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env node
2
+ /** Category: Registry — Central catalog of all ai-context-surgeon content | EXPORTS: CATALOG, getContent, listCategory, listAll | DEPS: fs, path */
3
+
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ const ROOT = path.resolve(__dirname, "..");
11
+
12
+ /**
13
+ * Central catalog — maps human-friendly keys to files within the package.
14
+ * This is the single source of truth for all content.
15
+ */
16
+ export const CATALOG = {
17
+ tools: {
18
+ radar: { name: "Radar Scan", description: "Semantic FNH map of any repository", command: "radar" },
19
+ godfiles: { name: "God Files", description: "Find files exceeding LOC thresholds", command: "godfiles" },
20
+ circular: { name: "Circular Deps", description: "Detect circular dependencies", command: "circular" },
21
+ "context-weight": { name: "Context Weight", description: "Identify files with high cognitive load", command: "context-weight" },
22
+ sourcemaps: { name: "Source Maps", description: "Generate AI-friendly structure trees", command: "sourcemaps" },
23
+ },
24
+
25
+ roles: {
26
+ scout: { name: "Scout", description: "Phase 1: Context reconnaissance and telemetry gathering", file: "roles/scout.md" },
27
+ architect: { name: "Architect", description: "Phase 2: Design and strategic planning", file: "roles/architect.md" },
28
+ surgeon: { name: "Surgeon", description: "Phase 3: Surgical code and structural modifications", file: "roles/surgeon.md" },
29
+ librarian: { name: "Librarian", description: "Phase 4a: Update docstrings, FNH, and READMEs", file: "roles/librarian.md" },
30
+ tuner: { name: "Tuner", description: "Phase 4b: Adjust config files, rules, and rulesets", file: "roles/tuner.md" },
31
+ inspector: { name: "Inspector", description: "Phase 5: Pipeline validation and health checks", file: "roles/inspector.md" },
32
+ },
33
+
34
+ strategies: {
35
+ fnh: { name: "File Navigation Header", description: "Universal header format for every file", file: "strategy/file-navigation-header.md" },
36
+ monorepo: { name: "Monorepo Strategy", description: "Architectural patterns and package boundaries", file: "strategy/monorepo_strategy.md" },
37
+ jsdoc: { name: "JSDoc Guide", description: "Token-efficient annotation standards", file: "strategy/jsdoc-guide.md" },
38
+ "package-json": { name: "package.json Guide", description: "Tier system for lean manifests", file: "strategy/package-json-guide.md" },
39
+ "context-exclusion": { name: "Context Exclusion", description: ".antigravityignore patterns", file: "strategy/context-exclusion.md" },
40
+ bash: { name: "Bash Guide", description: "Writing POSIX scripts for AI agents", file: "strategy/bash-guide.md" },
41
+ "context-weight": { name: "Context Weight Theory", description: "LOC + Fan-out cognitive load formula", file: "strategy/context-weight-theory.md" },
42
+ },
43
+
44
+ skills: {
45
+ "annotate-jsdoc": { name: "Annotate JSDoc", description: "Reusable JSDoc/FNH injection procedure", file: "skills/annotate-jsdoc/SKILL.md" },
46
+ "prompt-engineering": { name: "Prompt Engineering", description: "Prompt analysis, amplification, extraction", file: "skills/prompt-engineering/SKILL.md" },
47
+ },
48
+
49
+ templates: {
50
+ agents: { name: "AGENTS.md", description: "Agent rules template", file: "templates/AGENTS.md.template" },
51
+ readme: { name: "Package README", description: "Package README template", file: "templates/package-readme.template" },
52
+ "package-json": { name: "package.json", description: "Ideal package.json template", file: "templates/package-json-ideal.template" },
53
+ workflow: { name: "Workflow", description: "Workflow template", file: "templates/workflow.template" },
54
+ skill: { name: "Skill", description: "Skill template", file: "templates/skill.template" },
55
+ knowledge: { name: "Knowledge Item", description: "Knowledge item template", file: "templates/knowledge-item.template" },
56
+ "publish-meta": { name: "Publish Meta", description: "Publish metadata template", file: "templates/publish-meta.template" },
57
+ antigravityignore: { name: "Antigravityignore", description: "Context exclusion template", file: "templates/antigravityignore.template" },
58
+ cursorrules: { name: "Cursor/Windsurf Rules", description: "IDE agent rules template", file: "templates/cursorrules.template" },
59
+ },
60
+
61
+ checklists: {
62
+ 1: { name: "Phase 1: Analysis", description: "Tasks for Scout role", file: "checklists/phase-1-analysis.md" },
63
+ 2: { name: "Phase 2: Planning", description: "Tasks for Architect role", file: "checklists/phase-2-planning.md" },
64
+ 3: { name: "Phase 3: Restructuring", description: "Tasks for Surgeon role", file: "checklists/phase-3-restructuring.md" },
65
+ 4: { name: "Phase 4: Documentation", description: "Tasks for Librarian/Tuner roles", file: "checklists/phase-4-documentation.md" },
66
+ 5: { name: "Phase 5: Validation", description: "Tasks for Inspector role", file: "checklists/phase-5-validation.md" },
67
+ },
68
+
69
+ knowledge: {
70
+ "agent-context": { name: "Agent Context System", description: "How Knowledge/Skills/Workflows work in AI agents", dir: "knowledge/agent-context-system" },
71
+ vulnerabilities: { name: "Agent Vulnerabilities", description: "AI agent vulnerability patterns", dir: "knowledge/agent-vulnerabilities" },
72
+ "power-words": { name: "Power Words Dictionary", description: "Enforcement directive vocabulary", dir: "knowledge/power-words-dictionary" },
73
+ },
74
+ };
75
+
76
+ /**
77
+ * Read content of a catalog item by category and key.
78
+ * For knowledge items (which are directories), reads all artifacts.
79
+ * @param {string} category
80
+ * @param {string} key
81
+ * @returns {string|null} File content or null if not found
82
+ */
83
+ export function getContent(category, key) {
84
+ const cat = CATALOG[category];
85
+ if (!cat) return null;
86
+
87
+ const item = cat[key];
88
+ if (!item) return null;
89
+
90
+ // Tools don't have file content — they are commands
91
+ if (category === "tools") return null;
92
+
93
+ // Knowledge items are directories with multiple artifacts
94
+ if (item.dir) {
95
+ const dirPath = path.join(ROOT, item.dir);
96
+ if (!fs.existsSync(dirPath)) return null;
97
+
98
+ let output = "";
99
+
100
+ // Read metadata.json
101
+ const metaPath = path.join(dirPath, "metadata.json");
102
+ if (fs.existsSync(metaPath)) {
103
+ const meta = JSON.parse(fs.readFileSync(metaPath, "utf8"));
104
+ output += `# ${meta.title}\n\n> ${meta.summary}\n\n---\n\n`;
105
+ }
106
+
107
+ // Read all artifacts
108
+ const artifactsDir = path.join(dirPath, "artifacts");
109
+ if (fs.existsSync(artifactsDir)) {
110
+ const files = fs.readdirSync(artifactsDir).filter((f) => !f.startsWith("."));
111
+ for (const file of files) {
112
+ const content = fs.readFileSync(path.join(artifactsDir, file), "utf8");
113
+ output += `## ${file}\n\n${content}\n\n---\n\n`;
114
+ }
115
+ }
116
+
117
+ return output || null;
118
+ }
119
+
120
+ // Regular file items
121
+ const filePath = path.join(ROOT, item.file);
122
+ if (!fs.existsSync(filePath)) return null;
123
+
124
+ return fs.readFileSync(filePath, "utf8");
125
+ }
126
+
127
+ /**
128
+ * List all items in a category.
129
+ * @param {string} category
130
+ * @returns {Array<{key: string, name: string, description: string}>}
131
+ */
132
+ export function listCategory(category) {
133
+ const cat = CATALOG[category];
134
+ if (!cat) return [];
135
+
136
+ return Object.entries(cat).map(([key, val]) => ({
137
+ key: String(key),
138
+ name: val.name,
139
+ description: val.description,
140
+ }));
141
+ }
142
+
143
+ /**
144
+ * List all categories and their items.
145
+ * @returns {Object<string, Array>}
146
+ */
147
+ export function listAll() {
148
+ const result = {};
149
+ for (const category of Object.keys(CATALOG)) {
150
+ result[category] = listCategory(category);
151
+ }
152
+ return result;
153
+ }