@allthingsclaude/blueprints 0.2.0 → 0.3.0-beta.10
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/README.md +80 -12
- package/content/agents/audit.md +40 -25
- package/content/agents/bootstrap.md +25 -5
- package/content/agents/changelog.md +350 -0
- package/content/agents/cleanup.md +155 -0
- package/content/agents/commit.md +235 -0
- package/content/agents/debug.md +198 -0
- package/content/agents/docs.md +344 -0
- package/content/agents/{optimize.md → dry.md} +38 -15
- package/content/agents/explain.md +195 -0
- package/content/agents/finalize.md +20 -5
- package/content/agents/handoff.md +11 -5
- package/content/agents/imagine.md +2 -2
- package/content/agents/implement.md +54 -16
- package/content/agents/migrate.md +330 -0
- package/content/agents/parallelize.md +21 -4
- package/content/agents/plan.md +35 -5
- package/content/agents/refactor.md +156 -0
- package/content/agents/release.md +502 -0
- package/content/agents/research-codebase.md +160 -18
- package/content/agents/research-docs.md +135 -19
- package/content/agents/research-web.md +149 -19
- package/content/agents/secure.md +351 -0
- package/content/agents/storyboard.md +11 -5
- package/content/agents/test.md +181 -0
- package/content/commands/audit.md +15 -24
- package/content/commands/auto.md +361 -0
- package/content/commands/bootstrap.md +2 -2
- package/content/commands/brainstorm.md +63 -9
- package/content/commands/challenge.md +7 -0
- package/content/commands/changelog.md +50 -0
- package/content/commands/cleanup.md +14 -301
- package/content/commands/commit.md +45 -0
- package/content/commands/critique.md +7 -0
- package/content/commands/debug.md +9 -251
- package/content/commands/docs.md +48 -0
- package/content/commands/dry.md +48 -0
- package/content/commands/explain.md +12 -309
- package/content/commands/finalize.md +3 -3
- package/content/commands/flush.md +9 -14
- package/content/commands/handoff.md +1 -1
- package/content/commands/implement.md +5 -5
- package/content/commands/kickoff.md +7 -4
- package/content/commands/migrate.md +54 -0
- package/content/commands/parallelize.md +2 -2
- package/content/commands/pickup.md +1 -1
- package/content/commands/plan.md +2 -2
- package/content/commands/refactor.md +21 -379
- package/content/commands/release.md +63 -0
- package/content/commands/research.md +1 -1
- package/content/commands/secure.md +51 -0
- package/content/commands/storyboard.md +3 -3
- package/content/commands/test.md +15 -201
- package/content/commands/verify.md +7 -0
- package/dist/cli.js +47 -15
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts +29 -4
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +120 -17
- package/dist/installer.js.map +1 -1
- package/package.json +5 -1
- package/content/commands/optimize.md +0 -338
package/dist/installer.js
CHANGED
|
@@ -16,6 +16,36 @@ export const RESEARCH_AGENTS = [
|
|
|
16
16
|
'research-docs.md',
|
|
17
17
|
'research-web.md',
|
|
18
18
|
];
|
|
19
|
+
export const LIGHTWEIGHT_AGENTS = [
|
|
20
|
+
'commit.md',
|
|
21
|
+
'changelog.md',
|
|
22
|
+
'handoff.md',
|
|
23
|
+
'cleanup.md',
|
|
24
|
+
'imagine.md',
|
|
25
|
+
];
|
|
26
|
+
export const HEAVYWEIGHT_AGENTS = [
|
|
27
|
+
'audit.md',
|
|
28
|
+
'debug.md',
|
|
29
|
+
'secure.md',
|
|
30
|
+
];
|
|
31
|
+
export const DEFAULT_TASKS_DIR = 'tasks';
|
|
32
|
+
export function buildTemplateVars(tasksDir = DEFAULT_TASKS_DIR) {
|
|
33
|
+
return {
|
|
34
|
+
'{{TASKS_DIR}}': tasksDir,
|
|
35
|
+
'{{PLANS_DIR}}': `${tasksDir}/plans`,
|
|
36
|
+
'{{SESSIONS_DIR}}': `${tasksDir}/sessions`,
|
|
37
|
+
'{{STATE_FILE}}': `${tasksDir}/STATE.md`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export const TEMPLATE_VARS = buildTemplateVars();
|
|
41
|
+
export function replaceTemplateVars(content, tasksDir) {
|
|
42
|
+
const vars = tasksDir ? buildTemplateVars(tasksDir) : TEMPLATE_VARS;
|
|
43
|
+
let result = content;
|
|
44
|
+
for (const [key, value] of Object.entries(vars)) {
|
|
45
|
+
result = result.replaceAll(key, value);
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
19
49
|
/**
|
|
20
50
|
* Get the default Claude directory based on the operating system
|
|
21
51
|
*/
|
|
@@ -78,7 +108,7 @@ export function ensureDir(dirPath) {
|
|
|
78
108
|
/**
|
|
79
109
|
* Copy all files from source to destination directory
|
|
80
110
|
*/
|
|
81
|
-
export function copyDirectory(srcDir, destDir) {
|
|
111
|
+
export function copyDirectory(srcDir, destDir, tasksDir) {
|
|
82
112
|
ensureDir(destDir);
|
|
83
113
|
const files = fs.readdirSync(srcDir);
|
|
84
114
|
let copiedCount = 0;
|
|
@@ -86,35 +116,59 @@ export function copyDirectory(srcDir, destDir) {
|
|
|
86
116
|
const srcFile = path.join(srcDir, file);
|
|
87
117
|
const destFile = path.join(destDir, file);
|
|
88
118
|
const stat = fs.statSync(srcFile);
|
|
89
|
-
if (stat.isFile()) {
|
|
119
|
+
if (stat.isFile() && file.endsWith('.md')) {
|
|
120
|
+
const content = fs.readFileSync(srcFile, 'utf-8');
|
|
121
|
+
const updated = replaceTemplateVars(content, tasksDir);
|
|
122
|
+
fs.writeFileSync(destFile, updated, 'utf-8');
|
|
123
|
+
copiedCount++;
|
|
124
|
+
}
|
|
125
|
+
else if (stat.isFile()) {
|
|
90
126
|
fs.copyFileSync(srcFile, destFile);
|
|
91
127
|
copiedCount++;
|
|
92
128
|
}
|
|
93
129
|
else if (stat.isDirectory()) {
|
|
94
130
|
// Recursively copy subdirectories
|
|
95
|
-
copiedCount += copyDirectory(srcFile, path.join(destDir, file));
|
|
131
|
+
copiedCount += copyDirectory(srcFile, path.join(destDir, file), tasksDir);
|
|
96
132
|
}
|
|
97
133
|
}
|
|
98
134
|
return copiedCount;
|
|
99
135
|
}
|
|
100
136
|
/**
|
|
101
|
-
*
|
|
137
|
+
* Determine the tier for an agent based on its filename
|
|
138
|
+
*/
|
|
139
|
+
export function getAgentTier(filename) {
|
|
140
|
+
if (LIGHTWEIGHT_AGENTS.includes(filename))
|
|
141
|
+
return 'lightweight';
|
|
142
|
+
if (RESEARCH_AGENTS.includes(filename))
|
|
143
|
+
return 'research';
|
|
144
|
+
if (HEAVYWEIGHT_AGENTS.includes(filename))
|
|
145
|
+
return 'heavyweight';
|
|
146
|
+
return 'standard';
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get the model to use for a given agent file based on power level and tier
|
|
150
|
+
*
|
|
151
|
+
* Tiers:
|
|
152
|
+
* - lightweight: commit, changelog, handoff, cleanup, imagine (rote tasks)
|
|
153
|
+
* - research: codebase/docs/web research (search + synthesize)
|
|
154
|
+
* - standard: refactor, test, plan, implement, etc. (balanced)
|
|
155
|
+
* - heavyweight: audit, debug, secure (deep reasoning, high stakes)
|
|
102
156
|
*/
|
|
103
157
|
export function getModelForAgent(filename, powerLevel) {
|
|
104
|
-
const
|
|
158
|
+
const tier = getAgentTier(filename);
|
|
105
159
|
const modelMap = {
|
|
106
|
-
1: { research: 'haiku',
|
|
107
|
-
2: { research: 'haiku',
|
|
108
|
-
3: { research: 'sonnet',
|
|
109
|
-
4: {
|
|
110
|
-
5: { research: 'opus',
|
|
160
|
+
1: { lightweight: 'haiku', research: 'haiku', standard: 'haiku', heavyweight: 'sonnet' },
|
|
161
|
+
2: { lightweight: 'haiku', research: 'haiku', standard: 'sonnet', heavyweight: 'sonnet' },
|
|
162
|
+
3: { lightweight: 'sonnet', research: 'sonnet', standard: 'sonnet', heavyweight: 'sonnet' },
|
|
163
|
+
4: { lightweight: 'sonnet', research: 'opus', standard: 'opus', heavyweight: 'opus' },
|
|
164
|
+
5: { lightweight: 'opus', research: 'opus', standard: 'opus', heavyweight: 'opus' },
|
|
111
165
|
};
|
|
112
|
-
return
|
|
166
|
+
return modelMap[powerLevel][tier];
|
|
113
167
|
}
|
|
114
168
|
/**
|
|
115
169
|
* Copy agent files with model rewritten based on power level
|
|
116
170
|
*/
|
|
117
|
-
export function copyAgentsWithPowerLevel(srcDir, destDir, powerLevel) {
|
|
171
|
+
export function copyAgentsWithPowerLevel(srcDir, destDir, powerLevel, tasksDir) {
|
|
118
172
|
ensureDir(destDir);
|
|
119
173
|
const files = fs.readdirSync(srcDir);
|
|
120
174
|
let copiedCount = 0;
|
|
@@ -123,12 +177,13 @@ export function copyAgentsWithPowerLevel(srcDir, destDir, powerLevel) {
|
|
|
123
177
|
const destFile = path.join(destDir, file);
|
|
124
178
|
const stat = fs.statSync(srcFile);
|
|
125
179
|
if (stat.isDirectory()) {
|
|
126
|
-
copiedCount += copyAgentsWithPowerLevel(srcFile, path.join(destDir, file), powerLevel);
|
|
180
|
+
copiedCount += copyAgentsWithPowerLevel(srcFile, path.join(destDir, file), powerLevel, tasksDir);
|
|
127
181
|
}
|
|
128
182
|
else if (stat.isFile() && file.endsWith('.md')) {
|
|
129
183
|
const content = fs.readFileSync(srcFile, 'utf-8');
|
|
130
184
|
const model = getModelForAgent(file, powerLevel);
|
|
131
|
-
|
|
185
|
+
let updated = content.replace(/^(model:\s*).+$/m, `$1${model}`);
|
|
186
|
+
updated = replaceTemplateVars(updated, tasksDir);
|
|
132
187
|
fs.writeFileSync(destFile, updated, 'utf-8');
|
|
133
188
|
copiedCount++;
|
|
134
189
|
}
|
|
@@ -139,10 +194,52 @@ export function copyAgentsWithPowerLevel(srcDir, destDir, powerLevel) {
|
|
|
139
194
|
}
|
|
140
195
|
return copiedCount;
|
|
141
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Get the current package version
|
|
199
|
+
*/
|
|
200
|
+
export function getPackageVersion() {
|
|
201
|
+
const packageRoot = path.join(__dirname, '..');
|
|
202
|
+
const pkgPath = path.join(packageRoot, 'package.json');
|
|
203
|
+
try {
|
|
204
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
205
|
+
return pkg.version || 'unknown';
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return 'unknown';
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Remove files from a destination directory that no longer exist in the source
|
|
213
|
+
*/
|
|
214
|
+
export function cleanStaleFiles(srcDir, destDir) {
|
|
215
|
+
if (!fs.existsSync(destDir))
|
|
216
|
+
return 0;
|
|
217
|
+
let removedCount = 0;
|
|
218
|
+
const destFiles = fs.readdirSync(destDir);
|
|
219
|
+
for (const file of destFiles) {
|
|
220
|
+
const srcFile = path.join(srcDir, file);
|
|
221
|
+
const destFile = path.join(destDir, file);
|
|
222
|
+
const destStat = fs.statSync(destFile);
|
|
223
|
+
if (destStat.isDirectory()) {
|
|
224
|
+
if (fs.existsSync(srcFile)) {
|
|
225
|
+
removedCount += cleanStaleFiles(srcFile, destFile);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
fs.rmSync(destFile, { recursive: true });
|
|
229
|
+
removedCount++;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
else if (!fs.existsSync(srcFile)) {
|
|
233
|
+
fs.unlinkSync(destFile);
|
|
234
|
+
removedCount++;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return removedCount;
|
|
238
|
+
}
|
|
142
239
|
/**
|
|
143
240
|
* Install blueprints to the target path
|
|
144
241
|
*/
|
|
145
|
-
export async function installBlueprints(targetPath, powerLevel = 3) {
|
|
242
|
+
export async function installBlueprints(targetPath, powerLevel = 3, tasksDir = DEFAULT_TASKS_DIR) {
|
|
146
243
|
const sourcePaths = getSourcePaths();
|
|
147
244
|
const installPaths = getInstallPaths(targetPath);
|
|
148
245
|
// Verify source directories exist
|
|
@@ -154,10 +251,16 @@ export async function installBlueprints(targetPath, powerLevel = 3) {
|
|
|
154
251
|
}
|
|
155
252
|
// Ensure base .claude directory exists
|
|
156
253
|
ensureDir(installPaths.base);
|
|
254
|
+
// Clean stale files from previous installations
|
|
255
|
+
cleanStaleFiles(sourcePaths.commands, installPaths.commands);
|
|
256
|
+
cleanStaleFiles(sourcePaths.agents, installPaths.agents);
|
|
157
257
|
// Copy commands
|
|
158
|
-
const commandsCount = copyDirectory(sourcePaths.commands, installPaths.commands);
|
|
258
|
+
const commandsCount = copyDirectory(sourcePaths.commands, installPaths.commands, tasksDir);
|
|
159
259
|
// Copy agents with power level model overrides
|
|
160
|
-
const agentsCount = copyAgentsWithPowerLevel(sourcePaths.agents, installPaths.agents, powerLevel);
|
|
260
|
+
const agentsCount = copyAgentsWithPowerLevel(sourcePaths.agents, installPaths.agents, powerLevel, tasksDir);
|
|
261
|
+
// Write version marker
|
|
262
|
+
const version = getPackageVersion();
|
|
263
|
+
fs.writeFileSync(path.join(installPaths.base, '.blueprints-version'), JSON.stringify({ version, installedAt: new Date().toISOString(), powerLevel }, null, 2), 'utf-8');
|
|
161
264
|
return {
|
|
162
265
|
commands: commandsCount,
|
|
163
266
|
agents: agentsCount,
|
package/dist/installer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installer.js","sourceRoot":"","sources":["../src/installer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAsB3C,MAAM,CAAC,MAAM,kBAAkB,GAAoC;IACjE,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,UAAU;IACb,CAAC,EAAE,UAAU;IACb,CAAC,EAAE,UAAU;IACb,CAAC,EAAE,SAAS;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,sBAAsB;IACtB,kBAAkB;IAClB,iBAAiB;CAClB,CAAC;
|
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CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EACvF,OAAO,CACR,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,aAAa;QACvB,MAAM,EAAE,WAAW;QACnB,KAAK,EAAE,YAAY;QACnB,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAkB;IAC1D,MAAM,KAAK,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;IAE1C,OAAO;QACL,WAAW,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC;QACvF,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC;QACjF,YAAY,EAAE,KAAK,CAAC,QAAQ;QAC5B,UAAU,EAAE,KAAK,CAAC,MAAM;KACzB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allthingsclaude/blueprints",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-beta.10",
|
|
4
4
|
"description": "Claude Code commands and agents for enhanced AI-assisted development workflows",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
"test": "vitest run",
|
|
16
16
|
"test:watch": "vitest",
|
|
17
17
|
"prepublishOnly": "pnpm run build && pnpm run test",
|
|
18
|
+
"release:beta": "pnpm run build && pnpm run test && npm version prerelease --preid beta && git push && git push --tags",
|
|
19
|
+
"release:beta:patch": "pnpm run build && pnpm run test && npm version prepatch --preid beta && git push && git push --tags",
|
|
20
|
+
"release:beta:minor": "pnpm run build && pnpm run test && npm version preminor --preid beta && git push && git push --tags",
|
|
21
|
+
"release:beta:major": "pnpm run build && pnpm run test && npm version premajor --preid beta && git push && git push --tags",
|
|
18
22
|
"release:patch": "pnpm run build && pnpm run test && npm version patch && git push && git push --tags",
|
|
19
23
|
"release:minor": "pnpm run build && pnpm run test && npm version minor && git push && git push --tags",
|
|
20
24
|
"release:major": "pnpm run build && pnpm run test && npm version major && git push && git push --tags"
|
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Optimize code by eliminating DRY violations without changing behavior
|
|
3
|
-
argument-hint: [optional: file/folder path, "functions" | "components" | "hooks" | "types" | "constants"]
|
|
4
|
-
author: "@markoradak"
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# DRY Optimization Assistant
|
|
8
|
-
|
|
9
|
-
I'll find and eliminate DRY violations across your codebase, consolidating duplicated logic into single sources of truth while guaranteeing identical behavior.
|
|
10
|
-
|
|
11
|
-
## Current State
|
|
12
|
-
|
|
13
|
-
**Working Directory**: !`pwd`
|
|
14
|
-
|
|
15
|
-
**Branch**: !`git branch --show-current`
|
|
16
|
-
|
|
17
|
-
**Status**:
|
|
18
|
-
!`git status --short`
|
|
19
|
-
|
|
20
|
-
**Files to Analyze**:
|
|
21
|
-
!`find src -name "*.ts" -o -name "*.tsx" 2>/dev/null | wc -l` TypeScript files
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## Focus Area
|
|
26
|
-
|
|
27
|
-
$ARGUMENTS
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## Optimization Workflow
|
|
32
|
-
|
|
33
|
-
### Phase 1: Snapshot Baseline
|
|
34
|
-
|
|
35
|
-
Before any changes, capture the current state:
|
|
36
|
-
|
|
37
|
-
1. **Type safety**: Run `pnpm typecheck` — record result
|
|
38
|
-
2. **Lint compliance**: Run `pnpm lint` — record result
|
|
39
|
-
3. **Tests**: Run `pnpm test:run` — record result
|
|
40
|
-
4. **Build**: Run `pnpm build` — record result
|
|
41
|
-
|
|
42
|
-
All four MUST pass before and after optimization. If any fail before starting, stop and report.
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
### Phase 2: DRY Violation Scan
|
|
47
|
-
|
|
48
|
-
Based on the focus area, scan for specific duplication:
|
|
49
|
-
|
|
50
|
-
#### If "functions" or no argument:
|
|
51
|
-
- Find functions with identical or near-identical bodies across files
|
|
52
|
-
- Detect repeated inline logic (same 3+ line blocks)
|
|
53
|
-
- Identify utility patterns repeated instead of shared
|
|
54
|
-
|
|
55
|
-
#### If "components":
|
|
56
|
-
- Find components with overlapping JSX structures
|
|
57
|
-
- Detect repeated render patterns that differ only by props
|
|
58
|
-
- Identify components that could be parameterized into one
|
|
59
|
-
|
|
60
|
-
#### If "hooks":
|
|
61
|
-
- Find duplicated state + effect patterns across components
|
|
62
|
-
- Detect repeated data-fetching logic
|
|
63
|
-
- Identify shared lifecycle patterns not yet extracted
|
|
64
|
-
|
|
65
|
-
#### If "types":
|
|
66
|
-
- Find overlapping or identical type/interface definitions
|
|
67
|
-
- Detect types that are subsets of each other
|
|
68
|
-
- Identify repeated union types or utility type patterns
|
|
69
|
-
|
|
70
|
-
#### If "constants":
|
|
71
|
-
- Find magic values repeated across files
|
|
72
|
-
- Detect duplicate configuration objects
|
|
73
|
-
- Identify repeated string literals used as identifiers
|
|
74
|
-
|
|
75
|
-
#### If specific file/folder provided:
|
|
76
|
-
- Deep DRY analysis scoped to that area only
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
## Detection Strategies
|
|
81
|
-
|
|
82
|
-
### Exact Duplicates
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
# Find identical function bodies (same name, different files)
|
|
86
|
-
grep -rn "export function\|export const" src/ --include="*.ts" --include="*.tsx"
|
|
87
|
-
|
|
88
|
-
# Find repeated multi-line patterns
|
|
89
|
-
grep -rn "pattern" src/ --include="*.ts" --include="*.tsx"
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### Structural Duplicates
|
|
93
|
-
|
|
94
|
-
Look for code that follows the same shape but with different values:
|
|
95
|
-
|
|
96
|
-
- **Same control flow** with different variables
|
|
97
|
-
- **Same JSX structure** with different props/text
|
|
98
|
-
- **Same validation logic** with different fields
|
|
99
|
-
- **Same API call pattern** with different endpoints
|
|
100
|
-
|
|
101
|
-
### Logical Duplicates
|
|
102
|
-
|
|
103
|
-
Look for code that achieves the same outcome through different implementations:
|
|
104
|
-
|
|
105
|
-
- **Same business rule** expressed differently
|
|
106
|
-
- **Same computation** performed in multiple places
|
|
107
|
-
- **Same transformation** applied to different data shapes
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
## Optimization Strategies
|
|
112
|
-
|
|
113
|
-
### 1. Extract Shared Function
|
|
114
|
-
|
|
115
|
-
**When**: 3+ occurrences of identical or parameterizable logic
|
|
116
|
-
|
|
117
|
-
**How**:
|
|
118
|
-
- Identify the common core and the varying parts
|
|
119
|
-
- Create a function that takes the varying parts as parameters
|
|
120
|
-
- Replace all occurrences with calls to the shared function
|
|
121
|
-
|
|
122
|
-
**Location Rules**:
|
|
123
|
-
- Used within one file → private helper in same file
|
|
124
|
-
- Used across files in one feature → `lib/[feature].ts`
|
|
125
|
-
- Used across features → `lib/shared.ts` or `lib/utils/[name].ts`
|
|
126
|
-
|
|
127
|
-
### 2. Extract Shared Component
|
|
128
|
-
|
|
129
|
-
**When**: 2+ components share significant JSX structure
|
|
130
|
-
|
|
131
|
-
**How**:
|
|
132
|
-
- Identify the common layout and the varying slots/values
|
|
133
|
-
- Design a props interface that captures all variations
|
|
134
|
-
- Create one component that renders all cases via props
|
|
135
|
-
|
|
136
|
-
**Guard**: Only extract if the shared component is simpler than the sum of its parts. If the props interface becomes complex to cover all cases, the duplication may be justified.
|
|
137
|
-
|
|
138
|
-
### 3. Extract Custom Hook
|
|
139
|
-
|
|
140
|
-
**When**: 2+ components share state + effect logic
|
|
141
|
-
|
|
142
|
-
**How**:
|
|
143
|
-
- Identify the shared state shape and effect triggers
|
|
144
|
-
- Extract into `hooks/use[Name].ts`
|
|
145
|
-
- Return the same interface each component was using
|
|
146
|
-
|
|
147
|
-
### 4. Consolidate Types
|
|
148
|
-
|
|
149
|
-
**When**: Overlapping interfaces or repeated type patterns
|
|
150
|
-
|
|
151
|
-
**How**:
|
|
152
|
-
- Identify the superset type
|
|
153
|
-
- Use `Pick`, `Omit`, `Partial`, or `extends` to derive variants
|
|
154
|
-
- Place shared types in `types/[domain].ts`
|
|
155
|
-
|
|
156
|
-
### 5. Extract Constants
|
|
157
|
-
|
|
158
|
-
**When**: Same literal value appears in 3+ places
|
|
159
|
-
|
|
160
|
-
**How**:
|
|
161
|
-
- Create a named constant in `lib/constants.ts`
|
|
162
|
-
- Replace all occurrences with the constant reference
|
|
163
|
-
- Use `as const` for literal types
|
|
164
|
-
|
|
165
|
-
---
|
|
166
|
-
|
|
167
|
-
## DRY Optimization Report Format
|
|
168
|
-
|
|
169
|
-
```markdown
|
|
170
|
-
# DRY Optimization Report
|
|
171
|
-
|
|
172
|
-
**Scanned**: [X] files in [path]
|
|
173
|
-
**Focus**: [area or "all"]
|
|
174
|
-
**Baseline**: typecheck OK | lint OK | tests OK | build OK
|
|
175
|
-
|
|
176
|
-
---
|
|
177
|
-
|
|
178
|
-
## Violations Found
|
|
179
|
-
|
|
180
|
-
| # | Type | Occurrences | Lines Duplicated | Saveable Lines | Priority |
|
|
181
|
-
|---|------|-------------|------------------|----------------|----------|
|
|
182
|
-
| 1 | [exact/structural/logical] | X | Y | Z | High |
|
|
183
|
-
| 2 | ... | ... | ... | ... | Medium |
|
|
184
|
-
|
|
185
|
-
**Total Duplication**: ~[X] lines across [Y] files
|
|
186
|
-
**Estimated Reduction**: ~[Z] lines ([N]%)
|
|
187
|
-
|
|
188
|
-
---
|
|
189
|
-
|
|
190
|
-
## High Priority Optimizations
|
|
191
|
-
|
|
192
|
-
### 1. [Descriptive Name]
|
|
193
|
-
|
|
194
|
-
**Violation Type**: Exact / Structural / Logical
|
|
195
|
-
**Occurrences**: [count]
|
|
196
|
-
|
|
197
|
-
**Found In**:
|
|
198
|
-
- `src/path/A.tsx:23-45` (22 lines)
|
|
199
|
-
- `src/path/B.tsx:67-89` (22 lines)
|
|
200
|
-
- `src/path/C.ts:12-34` (22 lines)
|
|
201
|
-
|
|
202
|
-
**Duplicated Code** (from first occurrence):
|
|
203
|
-
```typescript
|
|
204
|
-
// The repeated code
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
**Optimization**:
|
|
208
|
-
|
|
209
|
-
**Strategy**: Extract Shared [Function/Component/Hook/Type]
|
|
210
|
-
**New Location**: `src/lib/[name].ts`
|
|
211
|
-
|
|
212
|
-
```typescript
|
|
213
|
-
// The consolidated version
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
**Replacement** (at each call site):
|
|
217
|
-
```typescript
|
|
218
|
-
// How each occurrence changes
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
**Savings**: -[X] lines, [Y] files touched
|
|
222
|
-
**Risk**: None — identical behavior guaranteed
|
|
223
|
-
|
|
224
|
-
---
|
|
225
|
-
|
|
226
|
-
## Medium Priority Optimizations
|
|
227
|
-
|
|
228
|
-
### 2. [Descriptive Name]
|
|
229
|
-
|
|
230
|
-
**Violation Type**: Structural
|
|
231
|
-
**Occurrences**: 2
|
|
232
|
-
|
|
233
|
-
**Options**:
|
|
234
|
-
1. **Parameterize now** — extract with config parameter
|
|
235
|
-
2. **Wait** — only 2 occurrences, may diverge
|
|
236
|
-
|
|
237
|
-
**Recommendation**: [Which and why]
|
|
238
|
-
|
|
239
|
-
---
|
|
240
|
-
|
|
241
|
-
## Constants to Extract
|
|
242
|
-
|
|
243
|
-
| Value | Occurrences | Suggested Name | Target File |
|
|
244
|
-
|-------|-------------|----------------|-------------|
|
|
245
|
-
| `"api/v1"` | 12 | `API_BASE_PATH` | `lib/constants.ts` |
|
|
246
|
-
| `30000` | 4 | `DEFAULT_TIMEOUT_MS` | `lib/constants.ts` |
|
|
247
|
-
|
|
248
|
-
---
|
|
249
|
-
|
|
250
|
-
## Types to Consolidate
|
|
251
|
-
|
|
252
|
-
| Type | Locations | Strategy |
|
|
253
|
-
|------|-----------|----------|
|
|
254
|
-
| `UserData` / `UserInfo` | 3 files | Merge into `types/user.ts` |
|
|
255
|
-
| `ApiResponse<T>` | 5 files | Single definition in `types/api.ts` |
|
|
256
|
-
|
|
257
|
-
---
|
|
258
|
-
|
|
259
|
-
## Summary
|
|
260
|
-
|
|
261
|
-
| Priority | Count | Lines Saved |
|
|
262
|
-
|----------|-------|-------------|
|
|
263
|
-
| High | X | ~Y |
|
|
264
|
-
| Medium | X | ~Y |
|
|
265
|
-
| Constants | X | ~Y |
|
|
266
|
-
| Types | X | ~Y |
|
|
267
|
-
| **Total** | **X** | **~Y** |
|
|
268
|
-
|
|
269
|
-
---
|
|
270
|
-
|
|
271
|
-
## Execution Plan
|
|
272
|
-
|
|
273
|
-
### Auto-apply (Safe)
|
|
274
|
-
|
|
275
|
-
1. [ ] Extract constants to shared location
|
|
276
|
-
2. [ ] Consolidate duplicate type definitions
|
|
277
|
-
3. [ ] Replace exact-duplicate functions with shared imports
|
|
278
|
-
|
|
279
|
-
### Requires Review
|
|
280
|
-
|
|
281
|
-
1. [ ] Structural duplications (confirm parameterization approach)
|
|
282
|
-
2. [ ] Component extractions (confirm props interface design)
|
|
283
|
-
3. [ ] Hook extractions (confirm return interface)
|
|
284
|
-
|
|
285
|
-
---
|
|
286
|
-
|
|
287
|
-
## Post-Optimization Verification
|
|
288
|
-
|
|
289
|
-
1. [ ] `pnpm typecheck` — MUST match baseline
|
|
290
|
-
2. [ ] `pnpm lint` — MUST match baseline
|
|
291
|
-
3. [ ] `pnpm test:run` — MUST match baseline
|
|
292
|
-
4. [ ] `pnpm build` — MUST match baseline
|
|
293
|
-
5. [ ] Manual spot-check of changed behavior paths
|
|
294
|
-
|
|
295
|
-
Would you like me to apply the high-priority optimizations?
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
---
|
|
299
|
-
|
|
300
|
-
## Behavior Preservation Rules
|
|
301
|
-
|
|
302
|
-
These rules are non-negotiable:
|
|
303
|
-
|
|
304
|
-
1. **No functional changes**: Every optimization MUST produce identical behavior
|
|
305
|
-
2. **Baseline before, baseline after**: All checks must pass before starting and after finishing
|
|
306
|
-
3. **One optimization at a time**: Apply, verify, then proceed to next
|
|
307
|
-
4. **Revert on failure**: If any verification fails after a change, revert immediately
|
|
308
|
-
5. **No premature abstraction**: Only extract when the duplication is clear and stable
|
|
309
|
-
|
|
310
|
-
### DO
|
|
311
|
-
- Extract when the duplication is exact or clearly parameterizable
|
|
312
|
-
- Keep extracted units focused — one responsibility per function/component/hook
|
|
313
|
-
- Name based on what it does, not where it came from
|
|
314
|
-
- Preserve original function signatures at call sites
|
|
315
|
-
- Run full verification after each change
|
|
316
|
-
|
|
317
|
-
### DON'T
|
|
318
|
-
- Extract 2-occurrence patterns unless they're exact duplicates
|
|
319
|
-
- Create god-functions that handle too many variations via params
|
|
320
|
-
- Change public API signatures unless all consumers are updated
|
|
321
|
-
- Optimize code that's about to be deleted or rewritten
|
|
322
|
-
- Bundle unrelated optimizations into a single change
|
|
323
|
-
- Sacrifice readability for fewer lines
|
|
324
|
-
|
|
325
|
-
---
|
|
326
|
-
|
|
327
|
-
## When to Stop
|
|
328
|
-
|
|
329
|
-
Not all duplication should be eliminated:
|
|
330
|
-
|
|
331
|
-
- **2 occurrences with likely divergence**: Leave them — premature abstraction is worse than duplication
|
|
332
|
-
- **Similar but semantically different**: Two functions that happen to look alike but serve different purposes should stay separate
|
|
333
|
-
- **Test code**: Some duplication in tests improves readability and independence
|
|
334
|
-
- **Configuration**: Repeated config values that might change independently should stay separate
|
|
335
|
-
|
|
336
|
-
---
|
|
337
|
-
|
|
338
|
-
Use the Task tool to launch the optimize agent (subagent_type="optimize") which will capture the baseline, scan for DRY violations, present a prioritized report, and — with user approval — apply optimizations one at a time with validation after each change.
|