@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
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
## <!-- FNH: Skill — Annotate File Navigation Headers (FNH) & JSDoc | SECTIONS: Patterns, Examples, Validation | DEPS: none -->
|
|
2
|
+
|
|
3
|
+
name: annotate-jsdoc
|
|
4
|
+
description: >-
|
|
5
|
+
Analyze source files and write AI-optimized JSDoc/FNH headers (one-line format).
|
|
6
|
+
Use when a file or directory needs annotations for AI agent navigation.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Annotate File Navigation Headers (FNH) & JSDoc
|
|
11
|
+
|
|
12
|
+
> Skill: Analyze source files and write AI-optimized JSDoc/FNH headers | SECTIONS: Rules, Categories, Examples, Verification | DEPS: none
|
|
13
|
+
|
|
14
|
+
## When to Use
|
|
15
|
+
|
|
16
|
+
- File has no FNH header (first line is not `/** ... */`)
|
|
17
|
+
- File has verbose Enterprise-style JSDoc (@author, @fileoverview, @since)
|
|
18
|
+
- Directory has files without FNH headers
|
|
19
|
+
- After ai-context-surgeon restructuring (Phase 3 → Phase 4)
|
|
20
|
+
- When onboarding a new project to AI-optimized workflow
|
|
21
|
+
|
|
22
|
+
## When NOT to Use
|
|
23
|
+
|
|
24
|
+
- File already has AI-optimized one-line FNH header
|
|
25
|
+
- File is auto-generated (_.d.ts, _.generated.ts, \*.min.js)
|
|
26
|
+
- File is a test file (_.test.ts, _.spec.ts) — low priority
|
|
27
|
+
- File is a config file (tsconfig.json, vite.config.ts) — not needed directly (but minimal FNH is okay)
|
|
28
|
+
|
|
29
|
+
## Launch Prompt
|
|
30
|
+
|
|
31
|
+
### Single File
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Apply the annotate-jsdoc skill to this file: {{FILE_PATH}}
|
|
35
|
+
|
|
36
|
+
Read the file. Then add or replace its FNH header and JSDoc annotations using the rules below.
|
|
37
|
+
Do NOT change any code logic — ONLY add/modify comments.
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Directory (batch)
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
Apply the annotate-jsdoc skill to all .ts/.js files in: {{DIRECTORY_PATH}}
|
|
44
|
+
|
|
45
|
+
For EACH source file (skip *.test.*, *.spec.*, *.d.ts, *.generated.*):
|
|
46
|
+
1. Read the file
|
|
47
|
+
2. Add/fix the FNH header and JSDoc annotations using the rules below
|
|
48
|
+
3. Move to the next file
|
|
49
|
+
|
|
50
|
+
Do NOT change any code logic — ONLY add/modify comments.
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Rules
|
|
54
|
+
|
|
55
|
+
CRITICAL INSTRUCTION 1: You MUST NOT change any code logic. You add or modify ONLY comments. If a function body, import, or export changes — you have FAILED.
|
|
56
|
+
|
|
57
|
+
CRITICAL INSTRUCTION 2: Every source file MUST start with a one-line FNH header. No exceptions.
|
|
58
|
+
|
|
59
|
+
CRITICAL INSTRUCTION 3: Function-level JSDoc is ONLY for information INVISIBLE from TypeScript types: @throws, side effects, mutations, business rules, deprecation. If the type signature says everything — do NOT add JSDoc. Redundant JSDoc is WORSE than no JSDoc.
|
|
60
|
+
|
|
61
|
+
### FNH Header Format
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
/** <Category>: <Name> — <what it does> | deps: <key dependencies> */
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Category vocabulary** (MUST use one of these):
|
|
68
|
+
|
|
69
|
+
| Category | For |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `Service` | Business logic classes/modules |
|
|
72
|
+
| `Route` | HTTP endpoint handlers |
|
|
73
|
+
| `Middleware` | Request pipeline functions |
|
|
74
|
+
| `Controller` | Request handlers (MVC) |
|
|
75
|
+
| `Repository` | Data access layer |
|
|
76
|
+
| `Entity` | Domain models |
|
|
77
|
+
| `Types` | Type/interface definitions |
|
|
78
|
+
| `Utility` | Helper/utility functions |
|
|
79
|
+
| `Config` | Configuration and setup |
|
|
80
|
+
| `Schema` | Validation schemas (Zod, Joi) |
|
|
81
|
+
| `Hook` | React hooks |
|
|
82
|
+
| `Component` | React/Vue/Svelte components |
|
|
83
|
+
| `Store` | State management |
|
|
84
|
+
| `Factory` | Object/instance creation |
|
|
85
|
+
| `Adapter` | External service wrappers |
|
|
86
|
+
| `Event` | Event definitions/handlers |
|
|
87
|
+
| `Guard` | Access control/authorization |
|
|
88
|
+
| `Constants` | Enums, constants, mappings |
|
|
89
|
+
| `Test` | Test suites (low priority) |
|
|
90
|
+
| `Script` | CLI/build/seed scripts |
|
|
91
|
+
| `Migration` | Database migrations |
|
|
92
|
+
| `Barrel` | Re-export index files |
|
|
93
|
+
|
|
94
|
+
### Function-Level Rules
|
|
95
|
+
|
|
96
|
+
**TypeScript files — ONLY annotate the invisible:**
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
// ✅ CORRECT: @throws is invisible from types
|
|
100
|
+
/** @throws NotFound | @throws Conflict(email) */
|
|
101
|
+
async function createUser(input: CreateUserInput): Promise<User>;
|
|
102
|
+
|
|
103
|
+
// ✅ CORRECT: side effect invisible from types
|
|
104
|
+
/** Sends welcome email. Logs to audit trail. */
|
|
105
|
+
async function createUser(input: CreateUserInput): Promise<User>;
|
|
106
|
+
|
|
107
|
+
// ✅ CORRECT: mutation invisible from types
|
|
108
|
+
/** @mutates req.user — sets authenticated user from JWT */
|
|
109
|
+
function authMiddleware(req: Request, res: Response, next: NextFunction): void;
|
|
110
|
+
|
|
111
|
+
// ✅ CORRECT: business rule invisible from types
|
|
112
|
+
/** Max 50 items. Free shipping > $100. @throws OutOfStock */
|
|
113
|
+
async function checkout(cart: Cart): Promise<Order>;
|
|
114
|
+
|
|
115
|
+
// ✅ CORRECT: deprecation
|
|
116
|
+
/** @deprecated Use createUserV2() — this skips email verification */
|
|
117
|
+
async function createUser(name: string): Promise<User>;
|
|
118
|
+
|
|
119
|
+
// ❌ WRONG: duplicates TypeScript information — DO NOT ADD
|
|
120
|
+
/** @param name User name @param email User email @returns User */
|
|
121
|
+
async function createUser(name: string, email: string): Promise<User>;
|
|
122
|
+
|
|
123
|
+
// ❌ WRONG: obvious from function name + types — DO NOT ADD
|
|
124
|
+
/** Gets users by filter */
|
|
125
|
+
async function getUsers(filter: UserFilter): Promise<User[]>;
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**JavaScript files — types ARE needed (no TypeScript):**
|
|
129
|
+
|
|
130
|
+
```javascript
|
|
131
|
+
// ✅ For JS: include @param types and @returns (replaces missing TS)
|
|
132
|
+
/** @param {string} id @returns {Promise<User|null>} @throws {NotFoundError} */
|
|
133
|
+
async function getUserById(id) { ... }
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Tags: What to Use vs Remove
|
|
137
|
+
|
|
138
|
+
**MUST use (when applicable):**
|
|
139
|
+
|
|
140
|
+
- `@throws {ErrorType}` — every thrown error
|
|
141
|
+
- `@deprecated` — with migration path
|
|
142
|
+
- `@mutates` — what it changes (non-standard but critical)
|
|
143
|
+
- Side effects in plain text: "Sends email", "Writes to disk", "Clears cache"
|
|
144
|
+
|
|
145
|
+
**MUST remove if found:**
|
|
146
|
+
|
|
147
|
+
- `@author` — irrelevant for agent
|
|
148
|
+
- `@since` — use git blame
|
|
149
|
+
- `@version` — use git tags
|
|
150
|
+
- `@copyright` — in LICENSE file
|
|
151
|
+
- `@license` — in LICENSE file
|
|
152
|
+
- `@fileoverview` — replaced by one-line header
|
|
153
|
+
- `@module` — obvious from filename
|
|
154
|
+
- `@memberof` — obvious from class structure
|
|
155
|
+
- `@classdesc` — obvious from class name
|
|
156
|
+
- `@constructs` — obvious from constructor
|
|
157
|
+
- `@param {type}` in TypeScript — redundant
|
|
158
|
+
- `@returns {type}` in TypeScript — redundant
|
|
159
|
+
|
|
160
|
+
### Barrel/Index Files
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// ✅ For index.ts re-export files
|
|
164
|
+
/** Barrel: public API for @project/core — entities, services, repos */
|
|
165
|
+
export { User } from "./entities/user";
|
|
166
|
+
export { UserService } from "./services/user.service";
|
|
167
|
+
export type { CreateUserInput } from "./types";
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Class Annotations
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
// ✅ Class-level: one-line, then only annotate methods with hidden behavior
|
|
174
|
+
/** Service: UserService — CRUD + password hashing + email uniqueness */
|
|
175
|
+
export class UserService {
|
|
176
|
+
/** @throws NotFound */
|
|
177
|
+
async getById(id: string): Promise<User> { ... }
|
|
178
|
+
|
|
179
|
+
/** @throws Conflict(email) | hashes pw bcrypt 12 | sends welcome email */
|
|
180
|
+
async create(input: CreateUserInput): Promise<User> { ... }
|
|
181
|
+
|
|
182
|
+
// No JSDoc needed — types say everything
|
|
183
|
+
async list(filter: UserFilter): Promise<User[]> { ... }
|
|
184
|
+
|
|
185
|
+
/** Soft delete — sets deletedAt, does NOT remove row */
|
|
186
|
+
async delete(id: string): Promise<void> { ... }
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Verification
|
|
191
|
+
|
|
192
|
+
After annotating, verify:
|
|
193
|
+
|
|
194
|
+
1. **No logic changes**: `git diff --stat` should show only comment additions
|
|
195
|
+
2. **Build passes**: `{{BUILD_COMMAND}}` — MUST still pass
|
|
196
|
+
3. **File headers**: Every .ts/.js file starts with `/** ... */` FNH header
|
|
197
|
+
4. **No wasteful tags**: `grep -r "@author\|@since\|@version\|@copyright" src/` — should be 0 results
|
|
198
|
+
5. **Audit**: Run `tools/audit-jsdoc.sh {{DIRECTORY}}` and check for improvements
|
|
199
|
+
|
|
200
|
+
## Example: Full File Transformation
|
|
201
|
+
|
|
202
|
+
### Before (42 lines of JSDoc, ~220 tokens of noise)
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
/**
|
|
206
|
+
* @fileoverview User Service
|
|
207
|
+
* @module services/user
|
|
208
|
+
* @author Jane Developer
|
|
209
|
+
* @since 2024-03-15
|
|
210
|
+
* @version 1.2.0
|
|
211
|
+
*/
|
|
212
|
+
import { PrismaClient } from '@prisma/client';
|
|
213
|
+
import bcrypt from 'bcrypt';
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* User service class
|
|
217
|
+
* @class
|
|
218
|
+
* @classdesc Manages user operations
|
|
219
|
+
*/
|
|
220
|
+
export class UserService {
|
|
221
|
+
/**
|
|
222
|
+
* Create a new user
|
|
223
|
+
* @async
|
|
224
|
+
* @param {CreateUserInput} input - User data
|
|
225
|
+
* @returns {Promise<User>} Created user
|
|
226
|
+
* @throws {ConflictError} If email exists
|
|
227
|
+
*/
|
|
228
|
+
async create(input: CreateUserInput): Promise<User> { ... }
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Get user by ID
|
|
232
|
+
* @param {string} id - User ID
|
|
233
|
+
* @returns {Promise<User>} Found user
|
|
234
|
+
* @throws {NotFoundError} If not found
|
|
235
|
+
*/
|
|
236
|
+
async getById(id: string): Promise<User> { ... }
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### After (5 lines of JSDoc, ~40 tokens — 82% reduction)
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
/** Service: UserService — CRUD + auth for users | deps: prisma, bcrypt */
|
|
244
|
+
import { PrismaClient } from '@prisma/client';
|
|
245
|
+
import bcrypt from 'bcrypt';
|
|
246
|
+
|
|
247
|
+
export class UserService {
|
|
248
|
+
/** @throws Conflict(email) | hashes pw bcrypt 12 | sends welcome email */
|
|
249
|
+
async create(input: CreateUserInput): Promise<User> { ... }
|
|
250
|
+
|
|
251
|
+
/** @throws NotFound */
|
|
252
|
+
async getById(id: string): Promise<User> { ... }
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Gotchas
|
|
257
|
+
|
|
258
|
+
- ⚠️ Do NOT annotate auto-generated files — they get overwritten
|
|
259
|
+
- ⚠️ In monorepos, run per-package to stay within context limit
|
|
260
|
+
- ⚠️ For files >500 lines, split first (Surgeon), then annotate
|
|
261
|
+
- ⚠️ FNH `/** */` MUST use the block comment syntax, not `//`
|
|
262
|
+
- ⚠️ In JS (non-TS) files, you DO need @param types — they replace TypeScript
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aleksandr Ivannikov, https://ivannikov.pro <hi@ivannikov.pro>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: prompt-engineering
|
|
3
|
+
description: Analyze, amplify, extract, and generate AI agent prompts using system prompt patterns. Use when the user asks to improve prompts, extract raw system context, create directive-heavy instructions, or analyze prompt structure.
|
|
4
|
+
category: development
|
|
5
|
+
tags: [prompt, engineering, analysis, amplifier, context, extraction]
|
|
6
|
+
tools: [claude, cursor, gemini, antigravity, copilot, windsurf, kiro]
|
|
7
|
+
date_added: "2026-04-01"
|
|
8
|
+
metadata:
|
|
9
|
+
version: "1.0.0"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Prompt Engineering Skill
|
|
13
|
+
|
|
14
|
+
> **Source:** local
|
|
15
|
+
> **Version in project:** `1.0.0` · **Skill updated:** 2026-04-01
|
|
16
|
+
|
|
17
|
+
## When to Use
|
|
18
|
+
|
|
19
|
+
- Improving weak prompts into directive-heavy power prompts
|
|
20
|
+
- Creating unbreakable boundaries inside an agent
|
|
21
|
+
- Analyzing another agent's prompt to find loopholes or token distributions
|
|
22
|
+
- Extracting raw system context safely (bypassing parsers and truncation limits)
|
|
23
|
+
|
|
24
|
+
## Overview
|
|
25
|
+
|
|
26
|
+
This skill provides tools for analyzing, amplifying, and extracting prompts using patterns from real AI agent system prompts. It leverages a database of 23 enforcement directives and 28 XML structure tags, along with techniques for raw context dumping (bypassing XML parsers and token limits).
|
|
27
|
+
|
|
28
|
+
## Available Tools
|
|
29
|
+
|
|
30
|
+
### 1. Prompt Amplifier
|
|
31
|
+
|
|
32
|
+
**Script**: `scripts/prompt_amplifier.py`
|
|
33
|
+
|
|
34
|
+
Transforms weak prompts into directive-heavy power prompts.
|
|
35
|
+
|
|
36
|
+
**Usage**:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Show all 4 modes for comparison
|
|
40
|
+
python3 scripts/prompt_amplifier.py "Your prompt here" --all
|
|
41
|
+
|
|
42
|
+
# Specific mode
|
|
43
|
+
python3 scripts/prompt_amplifier.py "Your prompt" --mode nuclear
|
|
44
|
+
|
|
45
|
+
# Interactive mode
|
|
46
|
+
python3 scripts/prompt_amplifier.py --interactive
|
|
47
|
+
|
|
48
|
+
# From file
|
|
49
|
+
python3 scripts/prompt_amplifier.py --file prompt.txt --mode stealth --output result.txt
|
|
50
|
+
|
|
51
|
+
# JSON output
|
|
52
|
+
python3 scripts/prompt_amplifier.py "Your prompt" --json
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Modes**:
|
|
56
|
+
| Mode | Effect | When to Use |
|
|
57
|
+
|----|----|----|
|
|
58
|
+
| `gentle` | Adds structure tags | For polite, cooperative agents |
|
|
59
|
+
| `firm` | + MUST/ALWAYS directives | For task execution |
|
|
60
|
+
| `nuclear` | + CRITICAL INSTRUCTION, MANDATORY RULE | When completeness is critical |
|
|
61
|
+
| `stealth` | Wraps in `<user_rules>` format | For maximum priority override |
|
|
62
|
+
|
|
63
|
+
### 2. Prompt DNA Analyzer (v2.0)
|
|
64
|
+
|
|
65
|
+
**Script**: `scripts/prompt_dna_analyzer.py`
|
|
66
|
+
|
|
67
|
+
Creates a structural DNA profile of any prompt with **file-type aware scoring** and **anti-gaming detection**.
|
|
68
|
+
|
|
69
|
+
**Usage**:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Analyze a prompt file
|
|
73
|
+
python3 scripts/prompt_dna_analyzer.py my_prompt.txt
|
|
74
|
+
|
|
75
|
+
# Specify file type (auto-detected from path if omitted)
|
|
76
|
+
python3 scripts/prompt_dna_analyzer.py my_prompt.txt --type role
|
|
77
|
+
|
|
78
|
+
# Batch analyze entire directory
|
|
79
|
+
python3 scripts/prompt_dna_analyzer.py --batch .agents/
|
|
80
|
+
|
|
81
|
+
# Batch with uniqueness check (detects copy-paste across files)
|
|
82
|
+
python3 scripts/prompt_dna_analyzer.py --batch .agents/ --check-uniqueness
|
|
83
|
+
|
|
84
|
+
# Analyze specific dump from logs
|
|
85
|
+
python3 scripts/prompt_dna_analyzer.py /tmp/system_prompt_logs.txt --dump 20
|
|
86
|
+
|
|
87
|
+
# JSON output
|
|
88
|
+
python3 scripts/prompt_dna_analyzer.py my_prompt.txt --json
|
|
89
|
+
|
|
90
|
+
# Save report
|
|
91
|
+
python3 scripts/prompt_dna_analyzer.py my_prompt.txt --output dna_report.md
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**File Type Profiles** (auto-detected from path):
|
|
95
|
+
|
|
96
|
+
| Type | Pattern | Target Hardness | Purpose |
|
|
97
|
+
| --- | --- | --- | --- |
|
|
98
|
+
| `role` | `as-*.md` | ≥ 70 | Agent role prompts |
|
|
99
|
+
| `workflow` | `workflows/*.md` | ≥ 60 | Step-by-step guides |
|
|
100
|
+
| `knowledge` | `knowledge/*.md` | ≥ 40 | Context documents |
|
|
101
|
+
| `reference` | `SKILL.md` | ≥ 20 | API/SDK reference docs |
|
|
102
|
+
| `config` | `README.md`, `AGENTS.md` | ≥ 50 | Config files |
|
|
103
|
+
|
|
104
|
+
**Anti-Gaming Detection**:
|
|
105
|
+
|
|
106
|
+
- **EOF Concentration** (-20 penalty): >70% enforcement words in last 20% of file
|
|
107
|
+
- **Generic Boilerplate** (-15 penalty): Known copy-paste blocks detected
|
|
108
|
+
- **Duplicate Lines** (-10 penalty): Repeated lines indicating copy-paste
|
|
109
|
+
|
|
110
|
+
**Output includes**:
|
|
111
|
+
|
|
112
|
+
- Hardness Score (0-100) with type-based PASS/FAIL
|
|
113
|
+
- Gaming penalties (if any)
|
|
114
|
+
- Restriction Ratio (enforcement vs enabling words)
|
|
115
|
+
- Security Coverage (blind spots)
|
|
116
|
+
- Structure Completeness (XML tags)
|
|
117
|
+
- Priority Channels detected
|
|
118
|
+
- Uniqueness Score (batch mode with `--check-uniqueness`)
|
|
119
|
+
- Recommendations
|
|
120
|
+
|
|
121
|
+
### 3. Instruction Extractor
|
|
122
|
+
|
|
123
|
+
**Script**: `scripts/extract_instructions.py`
|
|
124
|
+
|
|
125
|
+
Extracts all instructions and their variants from system prompt logs.
|
|
126
|
+
|
|
127
|
+
**Usage**:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
python3 scripts/extract_instructions.py
|
|
131
|
+
# Output: /tmp/extracted_instructions_report.md
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 4. Prompt Diff Tracker
|
|
135
|
+
|
|
136
|
+
**Script**: `scripts/prompt_diff_tracker.py`
|
|
137
|
+
|
|
138
|
+
Compares system prompt versions and tracks evolution.
|
|
139
|
+
|
|
140
|
+
**Usage**:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Compare latest two dumps
|
|
144
|
+
python3 scripts/prompt_diff_tracker.py /tmp/system_prompt_logs.txt
|
|
145
|
+
|
|
146
|
+
# Compare specific dumps
|
|
147
|
+
python3 scripts/prompt_diff_tracker.py /tmp/system_prompt_logs.txt --dump-a 12 --dump-b 20
|
|
148
|
+
|
|
149
|
+
# Show evolution timeline
|
|
150
|
+
python3 scripts/prompt_diff_tracker.py /tmp/system_prompt_logs.txt --timeline
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Templates
|
|
154
|
+
|
|
155
|
+
Ready-to-use prompt templates in `scripts/templates/`:
|
|
156
|
+
|
|
157
|
+
| Template | File | Purpose |
|
|
158
|
+
| --- | --- | --- |
|
|
159
|
+
| Code Review | `code_review.md` | Nuclear-enforced code audit |
|
|
160
|
+
| Dump Extraction | `dump_extraction.md` | Full context extraction |
|
|
161
|
+
| Task Automation | `task_automation.md` | turbo-all execution |
|
|
162
|
+
| Stealth Injection | `stealth_injection.md` | user_rules override |
|
|
163
|
+
| Multi-Agent | `multi_agent_orchestration.md` | Browser + main agent |
|
|
164
|
+
| **Prompt Audit** | `prompt_audit.md` | Batch audit with anti-gaming, scope locks |
|
|
165
|
+
|
|
166
|
+
## Power Words Quick Reference
|
|
167
|
+
|
|
168
|
+
### Enforcement (strongest → weakest)
|
|
169
|
+
|
|
170
|
+
1. `MUST` / `MUST ALWAYS` / `MUST NEVER` — absolute commands
|
|
171
|
+
2. `NEVER` — permanent prohibition
|
|
172
|
+
3. `ALWAYS` — permanent obligation
|
|
173
|
+
4. `DO NOT` — clear prohibition
|
|
174
|
+
5. `REQUIRED` / `ESSENTIAL` — obligation markers
|
|
175
|
+
|
|
176
|
+
### Escalation
|
|
177
|
+
|
|
178
|
+
1. `CRITICAL INSTRUCTION N:` — numbered enforcement chain
|
|
179
|
+
2. `MANDATORY RULE:` — high-priority rule
|
|
180
|
+
3. `CRITICAL REMINDER:` — section-specific enforcement
|
|
181
|
+
|
|
182
|
+
### Emotional Triggers
|
|
183
|
+
|
|
184
|
+
1. `UNACCEPTABLE` — triggers avoidance
|
|
185
|
+
2. `FAILED!` — implies evaluation/scoring
|
|
186
|
+
3. `Failure to do this is UNACCEPTABLE` — combined trigger
|
|
187
|
+
|
|
188
|
+
### Priority Channels (highest to lowest)
|
|
189
|
+
|
|
190
|
+
1. `<user_rules>` + `<RULE[x.md]>` — overrides everything
|
|
191
|
+
2. `<EPHEMERAL_MESSAGE>` — silent runtime override
|
|
192
|
+
3. `CRITICAL INSTRUCTION N:` — embedded directive
|
|
193
|
+
4. `MANDATORY RULE:` — enforcement prefix
|
|
194
|
+
5. `<planning_mode>` — behavioral framework
|
|
195
|
+
6. `<identity>` — baseline personality
|
|
196
|
+
|
|
197
|
+
## Workflows
|
|
198
|
+
|
|
199
|
+
| Command | Description |
|
|
200
|
+
| --- | --- |
|
|
201
|
+
| `/amplify` | Amplify a prompt across all modes |
|
|
202
|
+
| `/audit` | Full DNA audit of current agent |
|
|
203
|
+
| `/diff` | Compare prompt versions |
|
|
204
|
+
| `/context-dump` | Extract raw system context + auto-analyze |
|
|
205
|
+
|
|
206
|
+
## When NOT to Amplify
|
|
207
|
+
|
|
208
|
+
Not all prompts benefit from amplification. Use this decision matrix:
|
|
209
|
+
|
|
210
|
+
| Prompt Already Contains | Best Mode | Why |
|
|
211
|
+
| --- | --- | --- |
|
|
212
|
+
| Nothing (plain language) | `firm` or `nuclear` | Needs full structure + enforcement |
|
|
213
|
+
| MUST/ALWAYS | `nuclear` | Already has enforcement, add escalation |
|
|
214
|
+
| CRITICAL INSTRUCTION | `stealth` only | Nuclear would duplicate, stealth wraps |
|
|
215
|
+
| MANDATORY RULE + CRITICAL | Don't amplify | Already at maximum — amplification adds noise |
|
|
216
|
+
| Is for the same agent | `firm` | No need for priority override tricks |
|
|
217
|
+
| Is for another agent | `stealth` or `nuclear` | Needs to override that agent's system prompt |
|
|
218
|
+
|
|
219
|
+
## Anti-Patterns to Avoid
|
|
220
|
+
|
|
221
|
+
1. **Double MANDATORY RULE** — `MANDATORY RULE: MANDATORY RULE: ...` (amplifier bug, fixed)
|
|
222
|
+
2. **Weakening strong prompts** — using `gentle` on a prompt that already has MUST/NEVER
|
|
223
|
+
3. **Stealth on self** — using `<user_rules>` format when talking to the same agent
|
|
224
|
+
4. **Over-enforcement** — 100+ enforcement words makes the agent focus on rules, not the task
|
|
225
|
+
5. **Boilerplate spam** — copy-pasting the same enforcement block into multiple files instead of writing contextual improvements (detected by `--check-uniqueness`)
|
|
226
|
+
6. **Score gaming** — appending enforcement blocks to EOF just to inflate Hardness Score (detected by EOF concentration penalty)
|
|
227
|
+
7. **Ignoring scope locks** — modifying files explicitly marked as READ-ONLY in the audit prompt
|
|
228
|
+
8. **Type-blind scoring** — expecting SKILL.md (reference docs) to have the same Hardness as role prompts
|
|
229
|
+
9. **Primum non nocere violation** — chasing Hardness Score at the expense of clarity. If a file is a pure command reference (`pnpm dev`) or an API lookup table, adding MUST/NEVER harms readability without preventing real mistakes. Quality > compliance. Score is a guide, not a mandate.
|
|
230
|
+
|
|
231
|
+
## ⚠️ Gotchas
|
|
232
|
+
|
|
233
|
+
- **Agent Rejection**: Some providers (like Anthropic) will refuse prompts that have too many aggressive words (like "nuclear" mode) due to safety alignment filters.
|
|
234
|
+
- **Amplifier Context Loss**: When using `--mode nuclear`, the agent might prioritize following the meta-instructions over your actual objective.
|
|
235
|
+
- **XML Parsing Interference**: Make sure to check if generating `<RULE>` tags conflicts with the target agent's system parser.
|