claudenv 1.0.2 → 1.2.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/README.md +163 -11
- package/bin/cli.js +167 -1
- package/package.json +1 -1
- package/scaffold/.claude/commands/improve.md +60 -0
- package/scaffold/.claude/commands/setup-mcp.md +115 -0
- package/scaffold/.claude/commands/update-docs.md +1 -0
- package/scaffold/.claude/skills/doc-generator/SKILL.md +3 -0
- package/scaffold/.claude/skills/doc-generator/templates/mcp-servers.md +168 -0
- package/scaffold/global/.claude/commands/claudenv.md +50 -4
- package/scaffold/global/.claude/commands/improve.md +60 -0
- package/scaffold/global/.claude/commands/setup-mcp.md +115 -0
- package/scaffold/global/.claude/skills/claudenv/SKILL.md +11 -0
- package/scaffold/global/.claude/skills/claudenv/scaffold/.claude/commands/improve.md +60 -0
- package/scaffold/global/.claude/skills/claudenv/scaffold/.claude/commands/setup-mcp.md +115 -0
- package/scaffold/global/.claude/skills/claudenv/scaffold/.claude/commands/update-docs.md +1 -0
- package/scaffold/global/.claude/skills/claudenv/scaffold/.claude/skills/doc-generator/SKILL.md +3 -0
- package/scaffold/global/.claude/skills/claudenv/scaffold/.claude/skills/doc-generator/templates/mcp-servers.md +168 -0
- package/scaffold/global/.claude/skills/claudenv/templates/mcp-servers.md +168 -0
- package/src/autonomy.js +117 -0
- package/src/hooks-gen.js +279 -0
- package/src/index.js +4 -0
- package/src/installer.js +2 -0
- package/src/loop.js +617 -0
- package/src/profiles.js +113 -0
package/README.md
CHANGED
|
@@ -27,15 +27,18 @@ Claude AI will:
|
|
|
27
27
|
2. Detect your tech stack, frameworks, and tooling
|
|
28
28
|
3. Ask you about the project (description, deployment, conventions)
|
|
29
29
|
4. Generate all documentation files
|
|
30
|
-
5.
|
|
30
|
+
5. Search the [MCP Registry](https://registry.modelcontextprotocol.io) and configure MCP servers
|
|
31
|
+
6. Install slash commands for ongoing maintenance
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
You now have five commands available in Claude Code:
|
|
33
34
|
|
|
34
35
|
| Command | What it does |
|
|
35
36
|
|---------|-------------|
|
|
36
37
|
| `/init-docs` | Regenerate documentation from scratch |
|
|
37
38
|
| `/update-docs` | Scan for changes and propose updates |
|
|
38
39
|
| `/validate-docs` | Check that documentation is complete and correct |
|
|
40
|
+
| `/setup-mcp` | Recommend and configure MCP servers |
|
|
41
|
+
| `/improve` | Analyze and make one improvement |
|
|
39
42
|
|
|
40
43
|
## What Gets Generated
|
|
41
44
|
|
|
@@ -43,6 +46,7 @@ Claude AI will:
|
|
|
43
46
|
your-project/
|
|
44
47
|
├── CLAUDE.md # Project overview, commands, architecture
|
|
45
48
|
├── _state.md # Session memory (decisions, focus, issues)
|
|
49
|
+
├── .mcp.json # MCP server configuration
|
|
46
50
|
└── .claude/
|
|
47
51
|
├── rules/
|
|
48
52
|
│ ├── code-style.md # Coding conventions (scoped by file paths)
|
|
@@ -52,7 +56,9 @@ your-project/
|
|
|
52
56
|
├── commands/
|
|
53
57
|
│ ├── init-docs.md # /init-docs
|
|
54
58
|
│ ├── update-docs.md # /update-docs
|
|
55
|
-
│
|
|
59
|
+
│ ├── validate-docs.md # /validate-docs
|
|
60
|
+
│ ├── setup-mcp.md # /setup-mcp
|
|
61
|
+
│ └── improve.md # /improve
|
|
56
62
|
├── skills/
|
|
57
63
|
│ └── doc-generator/ # Auto-triggers when docs need updating
|
|
58
64
|
└── agents/
|
|
@@ -68,6 +74,145 @@ your-project/
|
|
|
68
74
|
| `.claude/rules/workflow.md` | Best practices: plan mode, `/compact`, subagents, git discipline |
|
|
69
75
|
| `.claude/rules/code-style.md` | Language and framework-specific coding conventions |
|
|
70
76
|
| `.claude/rules/testing.md` | Test framework patterns and commands |
|
|
77
|
+
| `.mcp.json` | MCP server configuration with `${ENV_VAR}` placeholders |
|
|
78
|
+
|
|
79
|
+
## MCP Server Recommendations
|
|
80
|
+
|
|
81
|
+
`/claudenv` automatically recommends MCP servers based on your tech stack. You can also run `/setup-mcp` independently at any time.
|
|
82
|
+
|
|
83
|
+
**How it works:**
|
|
84
|
+
|
|
85
|
+
1. Claude analyzes your project's dependencies, databases, cloud services, and tools
|
|
86
|
+
2. Searches the [official MCP Registry](https://registry.modelcontextprotocol.io) for matching servers
|
|
87
|
+
3. Verifies trust via npm download counts (filters out servers with <100 monthly downloads)
|
|
88
|
+
4. Presents recommendations grouped as **Essential** / **Recommended** / **Optional**
|
|
89
|
+
5. Generates `.mcp.json` with selected servers
|
|
90
|
+
|
|
91
|
+
**Example output** (`.mcp.json`):
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"mcpServers": {
|
|
96
|
+
"context7": {
|
|
97
|
+
"command": "npx",
|
|
98
|
+
"args": ["-y", "@upstash/context7-mcp@latest"],
|
|
99
|
+
"env": {}
|
|
100
|
+
},
|
|
101
|
+
"postgres": {
|
|
102
|
+
"command": "npx",
|
|
103
|
+
"args": ["-y", "@modelcontextprotocol/server-postgres@latest", "${POSTGRES_CONNECTION_STRING}"],
|
|
104
|
+
"env": {}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Secrets use `${ENV_VAR}` placeholders — configure them with:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
claude config set env.POSTGRES_CONNECTION_STRING "postgresql://..."
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`.mcp.json` is safe to commit — it never contains actual secrets.
|
|
117
|
+
|
|
118
|
+
Run `/setup-mcp --force` to auto-select Essential + Recommended servers without prompting.
|
|
119
|
+
|
|
120
|
+
## Iterative Improvement Loop
|
|
121
|
+
|
|
122
|
+
`claudenv loop` spawns Claude Code in headless mode to analyze and improve your project iteratively. Each run creates a git safety tag so you can always rollback.
|
|
123
|
+
|
|
124
|
+
**How it works:**
|
|
125
|
+
|
|
126
|
+
1. **Planning** (iteration 0) — Claude analyzes the project and generates `.claude/improvement-plan.md` with prioritized hypotheses
|
|
127
|
+
2. **Execution** (iterations 1-N) — each iteration picks the top unfinished item from the plan, implements it, runs tests, and commits
|
|
128
|
+
3. **Convergence** — the loop stops when the plan is complete, max iterations are reached, or the loop detects it's stuck
|
|
129
|
+
|
|
130
|
+
**Usage:**
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
claudenv loop # Interactive, pauses between iterations
|
|
134
|
+
claudenv loop --trust # Full trust, no pauses, no permission prompts
|
|
135
|
+
claudenv loop --trust -n 5 # 5 iterations in full trust
|
|
136
|
+
claudenv loop --goal "add test coverage" # Focused improvement
|
|
137
|
+
claudenv loop --trust --model opus -n 3 # Use Opus, 3 iterations
|
|
138
|
+
claudenv loop --budget 1.00 -n 10 # Budget cap per iteration
|
|
139
|
+
claudenv loop --rollback # Undo all loop changes
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
| Flag | Description |
|
|
143
|
+
|------|-------------|
|
|
144
|
+
| `-n, --iterations <n>` | Max iterations (default: unlimited) |
|
|
145
|
+
| `--trust` | Full trust mode — no pauses, skip permission prompts |
|
|
146
|
+
| `--goal <text>` | Focus area for improvements |
|
|
147
|
+
| `--profile <name>` | Autonomy profile: safe, moderate, full, ci |
|
|
148
|
+
| `--no-pause` | Don't pause between iterations |
|
|
149
|
+
| `--max-turns <n>` | Max agentic turns per iteration (default: 30) |
|
|
150
|
+
| `--model <model>` | Model to use (default: sonnet) |
|
|
151
|
+
| `--budget <usd>` | Budget cap per iteration in USD |
|
|
152
|
+
| `-d, --dir <path>` | Target project directory |
|
|
153
|
+
| `--allow-dirty` | Allow running with uncommitted changes |
|
|
154
|
+
| `--rollback` | Undo all changes from the most recent loop |
|
|
155
|
+
| `--unsafe` | Remove default tool restrictions |
|
|
156
|
+
|
|
157
|
+
**Git safety:** Before the first iteration, a `claudenv-loop-<timestamp>` git tag is created. Each iteration commits separately. Use `claudenv loop --rollback` to reset everything, or cherry-pick individual commits.
|
|
158
|
+
|
|
159
|
+
**Single iteration:** Use `/improve` inside Claude Code for a one-shot improvement without the full loop.
|
|
160
|
+
|
|
161
|
+
## Autonomous Agent Mode
|
|
162
|
+
|
|
163
|
+
`claudenv autonomy` configures Claude Code for autonomous operation with predefined security profiles. Inspired by [trailofbits/claude-code-config](https://github.com/trailofbits/claude-code-config).
|
|
164
|
+
|
|
165
|
+
**Usage:**
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
claudenv autonomy # Interactive profile selection
|
|
169
|
+
claudenv autonomy --profile moderate # Non-interactive, writes files directly
|
|
170
|
+
claudenv autonomy --profile moderate -y # Same — -y only needed for profile selection
|
|
171
|
+
claudenv autonomy --profile ci --dry-run # Preview generated files
|
|
172
|
+
claudenv autonomy --profile full # Full autonomy — requires typing "full" to confirm
|
|
173
|
+
claudenv autonomy --profile full --yes # Full autonomy, skip confirmation
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Profiles
|
|
177
|
+
|
|
178
|
+
| Profile | Description | Permissions | Credentials |
|
|
179
|
+
|---------|-------------|-------------|-------------|
|
|
180
|
+
| `safe` | Read-only + limited bash | Allow-list only | Blocked |
|
|
181
|
+
| `moderate` | Full dev with deny-list | Allow + deny lists | Blocked |
|
|
182
|
+
| `full` | Unrestricted + audit logging | `--dangerously-skip-permissions` | Warn-only |
|
|
183
|
+
| `ci` | Headless CI/CD (50 turns, $5 budget) | `--dangerously-skip-permissions` | Warn-only |
|
|
184
|
+
|
|
185
|
+
All profiles hard-block `rm -rf`, force push to main/master, and `sudo`.
|
|
186
|
+
|
|
187
|
+
### Generated files
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
.claude/
|
|
191
|
+
├── settings.json # Permissions + hooks config
|
|
192
|
+
├── hooks/
|
|
193
|
+
│ ├── pre-tool-use.sh # PreToolUse guard (blocks dangerous ops)
|
|
194
|
+
│ └── audit-log.sh # PostToolUse audit → audit-log.jsonl
|
|
195
|
+
└── aliases.sh # Shell aliases: claude-safe, claude-yolo, claude-ci, claude-local
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
CI profile also generates `.github/workflows/claude-ci.yml`.
|
|
199
|
+
|
|
200
|
+
### Loop integration
|
|
201
|
+
|
|
202
|
+
Use `--profile` with `claudenv loop` to apply profile settings:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
claudenv loop --profile moderate --goal "add types" # Uses profile's deny-list
|
|
206
|
+
claudenv loop --profile ci -n 5 # CI defaults: 50 turns, $5 budget
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
| Flag | Description |
|
|
210
|
+
|------|-------------|
|
|
211
|
+
| `-p, --profile <name>` | Profile: safe, moderate, full, ci |
|
|
212
|
+
| `-d, --dir <path>` | Project directory (default: `.`) |
|
|
213
|
+
| `--overwrite` | Overwrite existing files |
|
|
214
|
+
| `-y, --yes` | Skip prompts |
|
|
215
|
+
| `--dry-run` | Preview without writing |
|
|
71
216
|
|
|
72
217
|
## Tech Stack Detection
|
|
73
218
|
|
|
@@ -83,14 +228,21 @@ Claude AI reads your actual code, but the following are auto-detected for contex
|
|
|
83
228
|
## CLI Reference
|
|
84
229
|
|
|
85
230
|
```
|
|
86
|
-
claudenv
|
|
87
|
-
claudenv install
|
|
88
|
-
claudenv install -f
|
|
89
|
-
claudenv uninstall
|
|
90
|
-
claudenv init [dir]
|
|
91
|
-
claudenv init -y
|
|
92
|
-
claudenv generate
|
|
93
|
-
claudenv validate
|
|
231
|
+
claudenv Install /claudenv into ~/.claude/ (default)
|
|
232
|
+
claudenv install Same as above (explicit)
|
|
233
|
+
claudenv install -f Reinstall, overwriting existing files
|
|
234
|
+
claudenv uninstall Remove /claudenv from ~/.claude/
|
|
235
|
+
claudenv init [dir] Legacy: static analysis + terminal prompts (no AI)
|
|
236
|
+
claudenv init -y Legacy: skip prompts, auto-detect everything
|
|
237
|
+
claudenv generate Templates only, no scaffold
|
|
238
|
+
claudenv validate Check documentation completeness
|
|
239
|
+
claudenv loop Iterative improvement loop (spawns Claude)
|
|
240
|
+
claudenv loop --trust Full trust mode, no pauses
|
|
241
|
+
claudenv loop --profile moderate Use autonomy profile in loop
|
|
242
|
+
claudenv loop --rollback Undo all loop changes
|
|
243
|
+
claudenv autonomy Configure autonomous agent mode (interactive)
|
|
244
|
+
claudenv autonomy -p moderate Apply moderate profile
|
|
245
|
+
claudenv autonomy -p ci --dry-run Preview CI config without writing
|
|
94
246
|
```
|
|
95
247
|
|
|
96
248
|
## Alternative: Run Without Installing
|
package/bin/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import { resolve, join } from 'node:path';
|
|
5
|
-
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { readFile, chmod } from 'node:fs/promises';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { dirname } from 'node:path';
|
|
8
8
|
import { detectTechStack } from '../src/detector.js';
|
|
@@ -10,6 +10,9 @@ import { generateDocs, writeDocs, installScaffold } from '../src/generator.js';
|
|
|
10
10
|
import { validateClaudeMd, validateStructure, crossReferenceCheck } from '../src/validator.js';
|
|
11
11
|
import { runExistingProjectFlow, runColdStartFlow, buildDefaultConfig } from '../src/prompts.js';
|
|
12
12
|
import { installGlobal, uninstallGlobal } from '../src/installer.js';
|
|
13
|
+
import { runLoop, rollback, checkClaudeCli } from '../src/loop.js';
|
|
14
|
+
import { generateAutonomyConfig, printSecuritySummary, getFullModeWarning } from '../src/autonomy.js';
|
|
15
|
+
import { getProfile, listProfiles } from '../src/profiles.js';
|
|
13
16
|
|
|
14
17
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
18
|
const pkgJson = JSON.parse(await readFile(join(__dirname, '..', 'package.json'), 'utf-8'));
|
|
@@ -113,6 +116,92 @@ program
|
|
|
113
116
|
}
|
|
114
117
|
});
|
|
115
118
|
|
|
119
|
+
// --- loop ---
|
|
120
|
+
program
|
|
121
|
+
.command('loop')
|
|
122
|
+
.description('Iterative improvement loop — spawn Claude to analyze and improve the project')
|
|
123
|
+
.option('-n, --iterations <n>', 'Max iterations (default: unlimited)', parseInt)
|
|
124
|
+
.option('--trust', 'Full trust mode — no pauses, no permission prompts')
|
|
125
|
+
.option('--goal <text>', 'Focus area for improvements')
|
|
126
|
+
.option('--pause', 'Pause between iterations (default: on unless --trust)')
|
|
127
|
+
.option('--no-pause', 'Do not pause between iterations')
|
|
128
|
+
.option('--max-turns <n>', 'Max agentic turns per iteration (default: 30)', parseInt)
|
|
129
|
+
.option('--model <model>', 'Model to use (default: sonnet)')
|
|
130
|
+
.option('--budget <usd>', 'Budget cap per iteration in USD', parseFloat)
|
|
131
|
+
.option('-d, --dir <path>', 'Target project directory')
|
|
132
|
+
.option('--allow-dirty', 'Allow running with uncommitted git changes')
|
|
133
|
+
.option('--rollback', 'Undo all changes from the most recent loop run')
|
|
134
|
+
.option('--unsafe', 'Remove default tool restrictions (allows rm -rf)')
|
|
135
|
+
.option('--profile <name>', 'Autonomy profile: safe, moderate, full, ci')
|
|
136
|
+
.action(async (opts) => {
|
|
137
|
+
// --- Rollback mode ---
|
|
138
|
+
if (opts.rollback) {
|
|
139
|
+
await rollback({ cwd: opts.dir ? resolve(opts.dir) : process.cwd() });
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// --- Pre-flight: check Claude CLI ---
|
|
144
|
+
const cli = checkClaudeCli();
|
|
145
|
+
if (!cli.installed) {
|
|
146
|
+
console.error('\n Error: Claude CLI not found.');
|
|
147
|
+
console.error(' Install it from https://docs.anthropic.com/en/docs/claude-code\n');
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
console.log(`\n claudenv loop v${pkgJson.version}`);
|
|
151
|
+
console.log(` Claude CLI: ${cli.version}`);
|
|
152
|
+
|
|
153
|
+
// --- Load profile if specified ---
|
|
154
|
+
let profileDefaults = {};
|
|
155
|
+
if (opts.profile) {
|
|
156
|
+
const profile = getProfile(opts.profile);
|
|
157
|
+
profileDefaults = {
|
|
158
|
+
trust: profile.skipPermissions,
|
|
159
|
+
disallowedTools: profile.disallowedTools,
|
|
160
|
+
maxTurns: profile.maxTurns,
|
|
161
|
+
budget: profile.maxBudget,
|
|
162
|
+
};
|
|
163
|
+
console.log(` Profile: ${profile.name} — ${profile.description}`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// --- Config summary ---
|
|
167
|
+
const cwd = opts.dir ? resolve(opts.dir) : process.cwd();
|
|
168
|
+
const trust = opts.trust || profileDefaults.trust || false;
|
|
169
|
+
const pause = opts.pause !== undefined ? opts.pause : !trust;
|
|
170
|
+
|
|
171
|
+
console.log(` Directory: ${cwd}`);
|
|
172
|
+
console.log(` Mode: ${trust ? 'full trust (--dangerously-skip-permissions)' : 'interactive'}`);
|
|
173
|
+
if (opts.iterations) console.log(` Max iterations: ${opts.iterations}`);
|
|
174
|
+
if (opts.goal) console.log(` Goal: ${opts.goal}`);
|
|
175
|
+
if (opts.model) console.log(` Model: ${opts.model}`);
|
|
176
|
+
if (opts.budget || profileDefaults.budget) console.log(` Budget: $${opts.budget || profileDefaults.budget}/iteration`);
|
|
177
|
+
if (opts.maxTurns || profileDefaults.maxTurns) console.log(` Max turns: ${opts.maxTurns || profileDefaults.maxTurns}`);
|
|
178
|
+
|
|
179
|
+
await runLoop({
|
|
180
|
+
iterations: opts.iterations,
|
|
181
|
+
trust,
|
|
182
|
+
goal: opts.goal,
|
|
183
|
+
pause,
|
|
184
|
+
maxTurns: opts.maxTurns || profileDefaults.maxTurns || 30,
|
|
185
|
+
model: opts.model,
|
|
186
|
+
budget: opts.budget || profileDefaults.budget,
|
|
187
|
+
cwd,
|
|
188
|
+
allowDirty: opts.allowDirty || false,
|
|
189
|
+
unsafe: opts.unsafe || false,
|
|
190
|
+
disallowedTools: profileDefaults.disallowedTools,
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// --- autonomy ---
|
|
195
|
+
program
|
|
196
|
+
.command('autonomy')
|
|
197
|
+
.description('Configure autonomous agent mode with safety guardrails')
|
|
198
|
+
.option('-p, --profile <name>', 'Profile: safe, moderate, full, ci')
|
|
199
|
+
.option('-d, --dir <path>', 'Project directory', '.')
|
|
200
|
+
.option('--overwrite', 'Overwrite existing files')
|
|
201
|
+
.option('-y, --yes', 'Skip prompts')
|
|
202
|
+
.option('--dry-run', 'Preview without writing')
|
|
203
|
+
.action(runAutonomy);
|
|
204
|
+
|
|
116
205
|
// =============================================
|
|
117
206
|
// Install / Uninstall
|
|
118
207
|
// =============================================
|
|
@@ -263,4 +352,81 @@ function printValidation(label, result) {
|
|
|
263
352
|
}
|
|
264
353
|
}
|
|
265
354
|
|
|
355
|
+
// =============================================
|
|
356
|
+
// Autonomy
|
|
357
|
+
// =============================================
|
|
358
|
+
async function runAutonomy(opts) {
|
|
359
|
+
const { select, input } = await import('@inquirer/prompts');
|
|
360
|
+
const projectDir = resolve(opts.dir);
|
|
361
|
+
|
|
362
|
+
console.log(`\n claudenv autonomy v${pkgJson.version}\n`);
|
|
363
|
+
|
|
364
|
+
// --- Profile selection ---
|
|
365
|
+
let profileName = opts.profile;
|
|
366
|
+
if (!profileName && !opts.yes) {
|
|
367
|
+
const profiles = listProfiles();
|
|
368
|
+
profileName = await select({
|
|
369
|
+
message: 'Select autonomy profile:',
|
|
370
|
+
choices: profiles.map((p) => ({
|
|
371
|
+
name: `${p.name} — ${p.description}`,
|
|
372
|
+
value: p.name,
|
|
373
|
+
})),
|
|
374
|
+
});
|
|
375
|
+
} else if (!profileName) {
|
|
376
|
+
profileName = 'moderate';
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// --- Full mode confirmation ---
|
|
380
|
+
if (profileName === 'full') {
|
|
381
|
+
console.log(getFullModeWarning());
|
|
382
|
+
if (!opts.yes) {
|
|
383
|
+
const confirm = await input({ message: 'Type "full" to confirm:' });
|
|
384
|
+
if (confirm.trim() !== 'full') {
|
|
385
|
+
console.log(' Cancelled.\n');
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
console.log(' --yes flag set, proceeding without confirmation.\n');
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// --- Generate files ---
|
|
394
|
+
const { files, profile } = await generateAutonomyConfig(profileName, projectDir);
|
|
395
|
+
|
|
396
|
+
printSecuritySummary(profile);
|
|
397
|
+
|
|
398
|
+
if (opts.dryRun) {
|
|
399
|
+
console.log(' Dry run — files that would be generated:\n');
|
|
400
|
+
for (const f of files) {
|
|
401
|
+
console.log(` ── ${f.path} ──`);
|
|
402
|
+
console.log(f.content);
|
|
403
|
+
}
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// --- Write files ---
|
|
408
|
+
const { written, skipped } = await writeDocs(projectDir, files, {
|
|
409
|
+
overwrite: opts.overwrite || false,
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
// Make hook scripts executable
|
|
413
|
+
for (const f of files) {
|
|
414
|
+
if (f.path.endsWith('.sh')) {
|
|
415
|
+
try {
|
|
416
|
+
await chmod(join(projectDir, f.path), 0o755);
|
|
417
|
+
} catch { /* ignore */ }
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
printFileResults(written, skipped);
|
|
422
|
+
|
|
423
|
+
console.log(`
|
|
424
|
+
Next steps:
|
|
425
|
+
1. Review .claude/settings.json
|
|
426
|
+
2. Source aliases: source .claude/aliases.sh
|
|
427
|
+
3. ${profile.skipPermissions ? 'Run: claude --dangerously-skip-permissions' : 'Run: claude'}
|
|
428
|
+
4. git add .claude/ && git commit -m "Add autonomy config (${profileName})"
|
|
429
|
+
`);
|
|
430
|
+
}
|
|
431
|
+
|
|
266
432
|
program.parse();
|
package/package.json
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Analyze this project and make one high-impact improvement — fix bugs, add tests, improve code quality
|
|
3
|
+
allowed-tools: Read, Write, Glob, Grep, Bash
|
|
4
|
+
argument-hint: [area-to-improve]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# /improve — Single Improvement Iteration
|
|
8
|
+
|
|
9
|
+
You are an expert software engineer. Your job is to analyze this project and make one high-impact improvement.
|
|
10
|
+
|
|
11
|
+
## Step 1: Read Context
|
|
12
|
+
|
|
13
|
+
Read these files if they exist:
|
|
14
|
+
- `CLAUDE.md` — project overview and conventions
|
|
15
|
+
- `_state.md` — session memory
|
|
16
|
+
- `.claude/improvement-plan.md` — existing improvement plan (if any)
|
|
17
|
+
|
|
18
|
+
## Step 2: Choose What to Improve
|
|
19
|
+
|
|
20
|
+
**If `.claude/improvement-plan.md` exists:**
|
|
21
|
+
- Read the plan and pick the top unfinished item from the "## Pending" section
|
|
22
|
+
- If `$ARGUMENTS` is provided, use it as a focus area instead of the plan
|
|
23
|
+
|
|
24
|
+
**If no plan exists:**
|
|
25
|
+
- Analyze the project: read manifest files, scan source code, check test coverage
|
|
26
|
+
- If `$ARGUMENTS` is provided, focus on that area
|
|
27
|
+
- Identify the single highest-impact improvement you can make
|
|
28
|
+
|
|
29
|
+
## Step 3: Implement the Change
|
|
30
|
+
|
|
31
|
+
- Write the code changes
|
|
32
|
+
- Add or update tests if applicable
|
|
33
|
+
- Follow existing code style and conventions
|
|
34
|
+
|
|
35
|
+
## Step 4: Verify
|
|
36
|
+
|
|
37
|
+
- Run tests (if a test command is available)
|
|
38
|
+
- Run linter (if configured)
|
|
39
|
+
- Fix any issues found
|
|
40
|
+
|
|
41
|
+
## Step 5: Update Plan
|
|
42
|
+
|
|
43
|
+
If `.claude/improvement-plan.md` exists:
|
|
44
|
+
- Move the completed item from "## Pending" to "## Completed"
|
|
45
|
+
- Add the commit hash and notes about what was done
|
|
46
|
+
- If you discovered new issues, add them to "## Pending"
|
|
47
|
+
|
|
48
|
+
## Step 6: Commit and Report
|
|
49
|
+
|
|
50
|
+
- Commit all changes with a descriptive message
|
|
51
|
+
- Report:
|
|
52
|
+
- What you changed and why
|
|
53
|
+
- What tests were added/updated
|
|
54
|
+
- What's next (remaining plan items or suggested improvements)
|
|
55
|
+
|
|
56
|
+
## Important Rules
|
|
57
|
+
|
|
58
|
+
- Do NOT delete files unless the deletion IS the improvement
|
|
59
|
+
- Make exactly ONE improvement per invocation
|
|
60
|
+
- If there's nothing left to improve, output: NO_MORE_IMPROVEMENTS
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Recommend and configure MCP servers based on project analysis
|
|
3
|
+
allowed-tools: Read, Write, Glob, Grep, Bash(curl:*), Bash(find:*), Bash(cat:*)
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
argument-hint: [--force]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# MCP Server Setup
|
|
9
|
+
|
|
10
|
+
You are configuring MCP servers for this project. Analyze the tech stack, search the official MCP Registry, verify trust signals, and generate `.mcp.json`.
|
|
11
|
+
|
|
12
|
+
## Step 1: Analyze the Project
|
|
13
|
+
|
|
14
|
+
Understand what this project uses:
|
|
15
|
+
|
|
16
|
+
**Read existing documentation:**
|
|
17
|
+
- Read CLAUDE.md if it exists — it contains the tech stack summary
|
|
18
|
+
- Read _state.md if it exists
|
|
19
|
+
|
|
20
|
+
**Check for existing MCP config:**
|
|
21
|
+
- Read `.mcp.json` if it exists — you will merge new entries, not overwrite
|
|
22
|
+
|
|
23
|
+
**Scan manifest files:**
|
|
24
|
+
!`find . -maxdepth 3 \( -name "package.json" -o -name "pyproject.toml" -o -name "go.mod" -o -name "Cargo.toml" -o -name "Gemfile" -o -name "composer.json" -o -name "requirements.txt" \) -not -path "*/node_modules/*" -not -path "*/.venv/*" -not -path "*/vendor/*" 2>/dev/null | head -20`
|
|
25
|
+
|
|
26
|
+
**Scan framework and tooling configs:**
|
|
27
|
+
!`find . -maxdepth 2 \( -name "tsconfig*.json" -o -name "next.config.*" -o -name "vite.config.*" -o -name "docker-compose.*" -o -name "Dockerfile" -o -name ".env*" -o -name "prisma" -o -name "drizzle.config.*" \) -not -path "*/node_modules/*" 2>/dev/null | head -20`
|
|
28
|
+
|
|
29
|
+
Read the manifest files you found. Identify:
|
|
30
|
+
- Programming languages and frameworks
|
|
31
|
+
- Databases (PostgreSQL, MongoDB, Redis, etc.)
|
|
32
|
+
- Cloud services (AWS, GCP, Azure)
|
|
33
|
+
- External APIs (Stripe, Sentry, etc.)
|
|
34
|
+
- Dev tools (Docker, GitHub Actions, etc.)
|
|
35
|
+
|
|
36
|
+
## Step 2: Search the MCP Registry
|
|
37
|
+
|
|
38
|
+
Read the MCP server reference for search and evaluation guidance:
|
|
39
|
+
@.claude/skills/doc-generator/templates/mcp-servers.md
|
|
40
|
+
|
|
41
|
+
For each major technology in the project, search the official MCP Registry API:
|
|
42
|
+
```bash
|
|
43
|
+
curl -s 'https://registry.modelcontextprotocol.io/v0.1/servers?search=<tech>&version=latest&limit=10'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
For each candidate server with an npm package, verify trust by checking monthly downloads:
|
|
47
|
+
```bash
|
|
48
|
+
curl -s 'https://api.npmjs.org/downloads/point/last-month/<npm-package>'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Optionally check GitHub stars for additional trust signal:
|
|
52
|
+
```bash
|
|
53
|
+
curl -s 'https://api.github.com/repos/<owner>/<repo>'
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Filtering rules:**
|
|
57
|
+
- Remove servers with <100 monthly npm downloads
|
|
58
|
+
- Rank by: npm downloads (primary) + GitHub stars (secondary) + description relevance
|
|
59
|
+
- When multiple servers exist for the same technology, pick the one with the highest downloads
|
|
60
|
+
|
|
61
|
+
## Step 3: Present Recommendations
|
|
62
|
+
|
|
63
|
+
Group your recommendations into three tiers:
|
|
64
|
+
|
|
65
|
+
**Essential** — servers that directly support the project's core technologies (e.g., PostgreSQL server for a project using PostgreSQL)
|
|
66
|
+
|
|
67
|
+
**Recommended** — servers that enhance the development workflow (e.g., Context7 for library docs, GitHub for repo management)
|
|
68
|
+
|
|
69
|
+
**Optional** — servers that could be useful but aren't critical (e.g., Fetch for web content, Docker if Docker is used occasionally)
|
|
70
|
+
|
|
71
|
+
For each recommendation, explain:
|
|
72
|
+
- **What it does** and why it's relevant to THIS project
|
|
73
|
+
- **Monthly npm downloads** (trust signal)
|
|
74
|
+
- **Environment variables required** and whether they need secrets
|
|
75
|
+
|
|
76
|
+
Ask the user which servers to configure.
|
|
77
|
+
|
|
78
|
+
If `$ARGUMENTS` includes `--force`, auto-select all Essential and Recommended servers.
|
|
79
|
+
|
|
80
|
+
## Step 4: Generate .mcp.json
|
|
81
|
+
|
|
82
|
+
Build the `.mcp.json` file with the selected servers following the format in the MCP server reference.
|
|
83
|
+
|
|
84
|
+
**If `.mcp.json` already exists:**
|
|
85
|
+
- Read it and parse the existing `mcpServers` entries
|
|
86
|
+
- Merge new servers into the existing config — do NOT remove or overwrite existing entries
|
|
87
|
+
- If a server key already exists, skip it (preserve the user's existing config)
|
|
88
|
+
|
|
89
|
+
**Key rules:**
|
|
90
|
+
- Use `${ENV_VAR}` placeholders for ALL secret environment variables — NEVER literal values
|
|
91
|
+
- Non-secret env vars can use literal values when appropriate
|
|
92
|
+
- Use `npx -y <package>@latest` for stdio/npm servers
|
|
93
|
+
- Use the `type` and `url` from remotes for HTTP/SSE servers
|
|
94
|
+
|
|
95
|
+
Write the `.mcp.json` file.
|
|
96
|
+
|
|
97
|
+
## Step 5: Update CLAUDE.md
|
|
98
|
+
|
|
99
|
+
If CLAUDE.md exists, add or update an `## MCP Servers` section listing the configured servers and what they do. Keep it concise — one line per server.
|
|
100
|
+
|
|
101
|
+
If CLAUDE.md doesn't exist, skip this step and suggest running `/claudenv` first.
|
|
102
|
+
|
|
103
|
+
## Step 6: Environment Variables
|
|
104
|
+
|
|
105
|
+
List all required environment variables and how to configure them:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
To configure secrets, run:
|
|
109
|
+
claude config set env.VAR_NAME "your-value"
|
|
110
|
+
|
|
111
|
+
Required environment variables:
|
|
112
|
+
VAR_NAME — Description of what this is and where to get it
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Remind the user that `.mcp.json` is safe to commit — it only contains placeholders, not actual secrets.
|
|
@@ -34,6 +34,7 @@ Compare the current state against the existing documentation:
|
|
|
34
34
|
- **New directories** not covered in Architecture section
|
|
35
35
|
- **Stale references** to files or directories that no longer exist
|
|
36
36
|
- **Missing conventions** based on new config files (e.g., new linter added)
|
|
37
|
+
- **Missing or outdated `.mcp.json`** — if `.mcp.json` doesn't exist, or if new technologies have been added that could benefit from MCP servers, suggest running `/setup-mcp`
|
|
37
38
|
|
|
38
39
|
## Step 4: Propose Updates
|
|
39
40
|
|
|
@@ -12,6 +12,7 @@ allowed-tools: Read, Write, Glob, Grep, Bash(find:*), Bash(cat:*), Bash(node:*)
|
|
|
12
12
|
- New files detected that change the tech stack (new framework, test runner, etc.)
|
|
13
13
|
- After major refactoring that changes directory structure
|
|
14
14
|
- When CLAUDE.md references files or directories that no longer exist
|
|
15
|
+
- When `.mcp.json` is missing and the project has significant external dependencies
|
|
15
16
|
|
|
16
17
|
## Process
|
|
17
18
|
|
|
@@ -28,6 +29,7 @@ If CLAUDE.md already exists, read it and identify:
|
|
|
28
29
|
|
|
29
30
|
### 3. Generate or Update
|
|
30
31
|
- For new documentation: generate CLAUDE.md, _state.md, .claude/rules/code-style.md, .claude/rules/testing.md, .claude/rules/workflow.md
|
|
32
|
+
- For MCP configuration: suggest running `/setup-mcp` to search the MCP Registry and generate `.mcp.json`
|
|
31
33
|
- For updates: propose specific changes and wait for user approval
|
|
32
34
|
- Always present generated content for review before writing
|
|
33
35
|
- NEVER create .md files beyond the ones listed above unless the user explicitly asks
|
|
@@ -54,3 +56,4 @@ Generated CLAUDE.md should follow this structure:
|
|
|
54
56
|
Additionally generate:
|
|
55
57
|
- `_state.md` — project state tracking (decisions, focus, known issues)
|
|
56
58
|
- `.claude/rules/workflow.md` — Claude Code workflow best practices
|
|
59
|
+
- `.mcp.json` — MCP server configuration (via `/setup-mcp`)
|