@agentbrain/cli 1.2.0 → 1.3.1
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 +94 -13
- package/dist/commands/handoff.d.ts.map +1 -1
- package/dist/commands/handoff.js +35 -21
- package/dist/commands/handoff.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +87 -35
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/setup.d.ts +3 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/commands/setup.js +135 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,19 @@ npm install -g @agentbrain/cli
|
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
12
12
|
|
|
13
|
+
```bash
|
|
14
|
+
# ONE-TIME SETUP: Complete automated setup
|
|
15
|
+
cd /path/to/your/project
|
|
16
|
+
agentbrain setup
|
|
17
|
+
|
|
18
|
+
# That's it! AgentBrain now:
|
|
19
|
+
# ✓ Generates context automatically on commits
|
|
20
|
+
# ✓ Injects loading instructions into agent files
|
|
21
|
+
# ✓ Keeps everything in sync with your codebase
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Manual Setup (Advanced)
|
|
25
|
+
|
|
13
26
|
```bash
|
|
14
27
|
# Configure your API key
|
|
15
28
|
agentbrain config
|
|
@@ -27,6 +40,48 @@ agentbrain handoff
|
|
|
27
40
|
|
|
28
41
|
## Commands
|
|
29
42
|
|
|
43
|
+
### `agentbrain setup`
|
|
44
|
+
|
|
45
|
+
**One-command automated setup** for AgentBrain in your repository.
|
|
46
|
+
|
|
47
|
+
**Usage:**
|
|
48
|
+
```bash
|
|
49
|
+
agentbrain setup [options]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Options:**
|
|
53
|
+
- `--path <path>` - Repository path (default: current directory)
|
|
54
|
+
- `--skip-hooks` - Skip git hooks installation
|
|
55
|
+
- `--skip-agent-files` - Skip agent file injection
|
|
56
|
+
|
|
57
|
+
**What it does:**
|
|
58
|
+
1. Detects which agents you use (Claude Code, Cursor, Windsurf)
|
|
59
|
+
2. Generates initial context documentation
|
|
60
|
+
3. Injects context loading instructions into agent files
|
|
61
|
+
4. Installs smart git hooks for automatic regeneration
|
|
62
|
+
5. Sets up complete automation
|
|
63
|
+
|
|
64
|
+
**Output:**
|
|
65
|
+
- Creates `agentbrain/` directory with context docs
|
|
66
|
+
- Updates `CLAUDE.md`, `.cursorrules`, and/or `.windsurfrules`
|
|
67
|
+
- Installs `.git/hooks/post-commit` for smart auto-regeneration
|
|
68
|
+
|
|
69
|
+
**Example:**
|
|
70
|
+
```bash
|
|
71
|
+
# Complete automated setup
|
|
72
|
+
agentbrain setup
|
|
73
|
+
|
|
74
|
+
# Setup without git hooks
|
|
75
|
+
agentbrain setup --skip-hooks
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Cost:** ~$0.02-0.05 for initial generation (cached repeats are free)
|
|
79
|
+
|
|
80
|
+
**Smart Git Hooks:**
|
|
81
|
+
After setup, AgentBrain automatically regenerates context when you commit **source file changes**. It intelligently skips regeneration when only documentation or configuration files change, saving time and API costs.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
30
85
|
### `agentbrain init`
|
|
31
86
|
|
|
32
87
|
Generate comprehensive context documentation for your repository.
|
|
@@ -87,8 +142,8 @@ agentbrain standards [options]
|
|
|
87
142
|
|
|
88
143
|
**Output:**
|
|
89
144
|
Creates agent-specific files:
|
|
90
|
-
- `CLAUDE.md` - For Claude Code
|
|
91
|
-
- `.
|
|
145
|
+
- `CLAUDE.md` - For Claude Code CLI
|
|
146
|
+
- `.cursorrules` - For Cursor (also supports legacy `.cursor/rules`)
|
|
92
147
|
- `.windsurfrules` - For Windsurf
|
|
93
148
|
|
|
94
149
|
**Example:**
|
|
@@ -221,23 +276,29 @@ This stores the key securely at `~/.agentbrain/config.json` with 0600 permission
|
|
|
221
276
|
|
|
222
277
|
## Usage with AI Agents
|
|
223
278
|
|
|
224
|
-
|
|
279
|
+
After running `agentbrain setup`, your agents automatically load context at every session start.
|
|
225
280
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
@agentbrain/context.md
|
|
230
|
-
@agentbrain/dependency-map.md
|
|
231
|
-
@agentbrain/patterns.md
|
|
232
|
-
```
|
|
281
|
+
### Claude Code CLI
|
|
282
|
+
|
|
283
|
+
AgentBrain injects loading instructions into `CLAUDE.md`, which Claude Code CLI reads automatically from your project root. No manual action needed.
|
|
233
284
|
|
|
234
285
|
### Cursor
|
|
235
286
|
|
|
236
|
-
|
|
287
|
+
AgentBrain injects loading instructions into `.cursorrules` (or `.cursor/rules` for legacy setups), which Cursor reads automatically. No manual action needed.
|
|
237
288
|
|
|
238
289
|
### Windsurf
|
|
239
290
|
|
|
240
|
-
|
|
291
|
+
AgentBrain injects loading instructions into `.windsurfrules`, which Windsurf reads automatically. No manual action needed.
|
|
292
|
+
|
|
293
|
+
### Manual Loading (Advanced)
|
|
294
|
+
|
|
295
|
+
If not using `agentbrain setup`, you can manually reference context files:
|
|
296
|
+
```markdown
|
|
297
|
+
<!-- In agent prompt or rules file -->
|
|
298
|
+
@agentbrain/context.md
|
|
299
|
+
@agentbrain/dependency-map.md
|
|
300
|
+
@agentbrain/patterns.md
|
|
301
|
+
```
|
|
241
302
|
|
|
242
303
|
## Cost Estimates
|
|
243
304
|
|
|
@@ -255,6 +316,26 @@ All costs are approximate (as of January 2025):
|
|
|
255
316
|
|
|
256
317
|
## Workflow Example
|
|
257
318
|
|
|
319
|
+
### Recommended: Automated Setup
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
# 1. One-time setup (do once per repo)
|
|
323
|
+
cd /path/to/project
|
|
324
|
+
agentbrain setup
|
|
325
|
+
|
|
326
|
+
# 2. Start coding - context auto-updates on commits!
|
|
327
|
+
# ... make changes ...
|
|
328
|
+
git commit -m "Add feature"
|
|
329
|
+
# → AgentBrain automatically regenerates context (if source files changed)
|
|
330
|
+
|
|
331
|
+
# 3. Generate handoff when needed
|
|
332
|
+
agentbrain handoff --goal "Completed authentication feature"
|
|
333
|
+
|
|
334
|
+
# That's it! Everything else is automatic.
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Manual Setup (Advanced)
|
|
338
|
+
|
|
258
339
|
```bash
|
|
259
340
|
# 1. Initial setup
|
|
260
341
|
cd /path/to/project
|
|
@@ -271,7 +352,7 @@ agentbrain standards
|
|
|
271
352
|
# ... make changes ...
|
|
272
353
|
agentbrain handoff --goal "Add authentication feature"
|
|
273
354
|
|
|
274
|
-
# 5.
|
|
355
|
+
# 5. Manually regenerate context after changes
|
|
275
356
|
agentbrain init # Only costs money if git hash changed
|
|
276
357
|
```
|
|
277
358
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handoff.d.ts","sourceRoot":"","sources":["../../src/commands/handoff.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AASnC,wBAAgB,oBAAoB,IAAI,OAAO,
|
|
1
|
+
{"version":3,"file":"handoff.d.ts","sourceRoot":"","sources":["../../src/commands/handoff.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AASnC,wBAAgB,oBAAoB,IAAI,OAAO,CAmB9C"}
|
package/dist/commands/handoff.js
CHANGED
|
@@ -13,24 +13,34 @@ export function createHandoffCommand() {
|
|
|
13
13
|
.option('--path <path>', 'Repository path', process.cwd())
|
|
14
14
|
.option('--goal <goal>', 'Session goal or objective')
|
|
15
15
|
.option('--commits <number>', 'Number of recent commits to include (default: 5)', '5')
|
|
16
|
+
.option('--auto', 'Auto mode - skip prompts and banner (for git hooks)')
|
|
16
17
|
.action(async (options) => {
|
|
17
18
|
try {
|
|
18
19
|
await runHandoff(options);
|
|
19
20
|
}
|
|
20
21
|
catch (err) {
|
|
21
|
-
|
|
22
|
+
if (!options.auto) {
|
|
23
|
+
error(err instanceof Error ? err.message : 'Handoff generation failed');
|
|
24
|
+
}
|
|
22
25
|
process.exit(1);
|
|
23
26
|
}
|
|
24
27
|
});
|
|
25
28
|
return cmd;
|
|
26
29
|
}
|
|
27
30
|
async function runHandoff(options) {
|
|
28
|
-
|
|
31
|
+
const auto = options.auto;
|
|
32
|
+
if (!auto) {
|
|
33
|
+
displayBanner();
|
|
34
|
+
}
|
|
29
35
|
const repoPath = resolve(options.path);
|
|
30
|
-
|
|
36
|
+
if (!auto) {
|
|
37
|
+
info(`Repository: ${repoPath}`);
|
|
38
|
+
}
|
|
31
39
|
// Load AI config
|
|
32
40
|
const aiConfig = await loadAIConfig();
|
|
33
|
-
|
|
41
|
+
if (!auto) {
|
|
42
|
+
info(`Using ${aiConfig.provider} API\n`);
|
|
43
|
+
}
|
|
34
44
|
// Parse commit count
|
|
35
45
|
const commitCount = parseInt(options.commits, 10);
|
|
36
46
|
if (isNaN(commitCount) || commitCount < 1) {
|
|
@@ -38,21 +48,23 @@ async function runHandoff(options) {
|
|
|
38
48
|
}
|
|
39
49
|
// Get session goal if not provided
|
|
40
50
|
let goal = options.goal;
|
|
41
|
-
if (!goal) {
|
|
51
|
+
if (!goal && !auto) {
|
|
42
52
|
goal = await input({
|
|
43
53
|
message: 'Session goal (optional):',
|
|
44
54
|
default: '',
|
|
45
55
|
});
|
|
46
56
|
}
|
|
47
57
|
// Generate handoff
|
|
48
|
-
const spin = spinner('Analyzing changes and generating handoff...');
|
|
58
|
+
const spin = auto ? null : spinner('Analyzing changes and generating handoff...');
|
|
49
59
|
const result = await generateHandoff({
|
|
50
60
|
repoPath,
|
|
51
61
|
aiConfig,
|
|
52
62
|
goal: goal || undefined,
|
|
53
63
|
commitCount,
|
|
54
64
|
});
|
|
55
|
-
|
|
65
|
+
if (!auto) {
|
|
66
|
+
spin?.succeed('Handoff generation complete!');
|
|
67
|
+
}
|
|
56
68
|
// Write to disk
|
|
57
69
|
const outputDir = join(repoPath, 'agentbrain');
|
|
58
70
|
if (!existsSync(outputDir)) {
|
|
@@ -60,20 +72,22 @@ async function runHandoff(options) {
|
|
|
60
72
|
}
|
|
61
73
|
const filePath = join(outputDir, 'handoff.md');
|
|
62
74
|
await writeFile(filePath, result.doc.content, 'utf-8');
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
if (!auto) {
|
|
76
|
+
displayGeneratedFiles([
|
|
77
|
+
{ name: 'agentbrain/handoff.md', description: 'Session handoff document' },
|
|
78
|
+
]);
|
|
79
|
+
if (result.tokenCount > 0) {
|
|
80
|
+
const cost = aiConfig.provider === 'anthropic' ? (result.tokenCount / 1_000_000) * 3.0 : (result.tokenCount / 1_000_000) * 2.5;
|
|
81
|
+
info(`Tokens used: ${result.tokenCount.toLocaleString()} (~$${cost.toFixed(4)})`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
info('No AI tokens used (no changes detected)');
|
|
85
|
+
}
|
|
86
|
+
success('Handoff document generated!');
|
|
87
|
+
console.log('\n📌 Next steps:\n');
|
|
88
|
+
console.log(' • Share agentbrain/handoff.md with the next developer or session');
|
|
89
|
+
console.log(' • Reference it at the start of your next session for context');
|
|
90
|
+
console.log();
|
|
72
91
|
}
|
|
73
|
-
success('Handoff document generated!');
|
|
74
|
-
console.log('\n📌 Next steps:\n');
|
|
75
|
-
console.log(' • Share agentbrain/handoff.md with the next developer or session');
|
|
76
|
-
console.log(' • Reference it at the start of your next session for context');
|
|
77
|
-
console.log();
|
|
78
92
|
}
|
|
79
93
|
//# sourceMappingURL=handoff.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/commands/handoff.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAEtD,OAAO,EA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 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AA6BnC,wBAAgB,iBAAiB,IAAI,OAAO,CAsB3C"}
|
package/dist/commands/init.js
CHANGED
|
@@ -5,7 +5,7 @@ import { resolve } from 'node:path';
|
|
|
5
5
|
import { writeFile, mkdir } from 'node:fs/promises';
|
|
6
6
|
import { existsSync } from 'node:fs';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
|
-
import { loadAIConfig, generateContext, estimateContextCost, scanRepository, } from '@agentbrain/core';
|
|
8
|
+
import { loadAIConfig, generateContext, estimateContextCost, scanRepository, injectIntoAllAgents, detectAgents, AGENT_FILE_PATHS, } from '@agentbrain/core';
|
|
9
9
|
import { displayBanner, success, error, info, spinner, displayFileTable, displayCostEstimate, displayActualCost, displayGeneratedFiles, displayNextSteps, displayProviderInfo, } from '../display.js';
|
|
10
10
|
export function createInitCommand() {
|
|
11
11
|
const cmd = new Command('init')
|
|
@@ -14,51 +14,77 @@ export function createInitCommand() {
|
|
|
14
14
|
.option('--max-files <number>', 'Maximum files to analyze', '100')
|
|
15
15
|
.option('--no-cache', 'Skip cache and regenerate')
|
|
16
16
|
.option('--dry-run', 'Show what would be generated without actually generating')
|
|
17
|
+
.option('--silent', 'Suppress output (for git hooks)')
|
|
18
|
+
.option('--no-confirm', 'Skip confirmation prompts')
|
|
19
|
+
.option('--no-inject', 'Skip agent file injection')
|
|
17
20
|
.action(async (options) => {
|
|
18
21
|
try {
|
|
19
22
|
await runInit(options);
|
|
20
23
|
}
|
|
21
24
|
catch (err) {
|
|
22
|
-
|
|
25
|
+
if (!options.silent) {
|
|
26
|
+
error(err instanceof Error ? err.message : 'Initialization failed');
|
|
27
|
+
}
|
|
23
28
|
process.exit(1);
|
|
24
29
|
}
|
|
25
30
|
});
|
|
26
31
|
return cmd;
|
|
27
32
|
}
|
|
28
33
|
async function runInit(options) {
|
|
29
|
-
|
|
34
|
+
const silent = options.silent;
|
|
35
|
+
if (!silent) {
|
|
36
|
+
displayBanner();
|
|
37
|
+
}
|
|
30
38
|
const repoPath = resolve(options.path);
|
|
31
39
|
const maxFiles = parseInt(options.maxFiles, 10);
|
|
32
40
|
const useCache = options.cache;
|
|
33
|
-
|
|
41
|
+
const skipConfirm = !options.confirm;
|
|
42
|
+
const skipInject = !options.inject;
|
|
43
|
+
if (!silent) {
|
|
44
|
+
info(`Repository: ${repoPath}`);
|
|
45
|
+
}
|
|
34
46
|
// Load AI config
|
|
35
47
|
const aiConfig = await loadAIConfig();
|
|
36
|
-
|
|
48
|
+
if (!silent) {
|
|
49
|
+
displayProviderInfo(aiConfig.provider, aiConfig.models);
|
|
50
|
+
}
|
|
37
51
|
// Scan repository
|
|
38
|
-
const spin = spinner('Scanning repository...');
|
|
52
|
+
const spin = silent ? null : spinner('Scanning repository...');
|
|
39
53
|
const scanResult = await scanRepository(repoPath, { maxFiles });
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
if (!silent) {
|
|
55
|
+
spin?.succeed(`Found ${scanResult.totalFiles} files, selected ${scanResult.relevantFiles.length} relevant files`);
|
|
56
|
+
console.log();
|
|
57
|
+
displayFileTable(scanResult.relevantFiles, 8);
|
|
58
|
+
}
|
|
43
59
|
// Estimate cost
|
|
44
|
-
|
|
60
|
+
if (!silent) {
|
|
61
|
+
info('Estimating cost...');
|
|
62
|
+
}
|
|
45
63
|
const estimate = await estimateContextCost(repoPath, aiConfig, maxFiles);
|
|
46
|
-
|
|
64
|
+
if (!silent) {
|
|
65
|
+
displayCostEstimate(estimate);
|
|
66
|
+
}
|
|
47
67
|
if (options.dryRun) {
|
|
48
|
-
|
|
68
|
+
if (!silent) {
|
|
69
|
+
info('Dry run complete - no files generated');
|
|
70
|
+
}
|
|
49
71
|
return;
|
|
50
72
|
}
|
|
51
73
|
// Confirm generation
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
if (!skipConfirm) {
|
|
75
|
+
const confirmed = await confirm({
|
|
76
|
+
message: 'Generate context docs?',
|
|
77
|
+
default: true,
|
|
78
|
+
});
|
|
79
|
+
if (!confirmed) {
|
|
80
|
+
if (!silent) {
|
|
81
|
+
info('Cancelled');
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
59
85
|
}
|
|
60
86
|
// Generate context
|
|
61
|
-
const genSpin = spinner('Generating context documents...');
|
|
87
|
+
const genSpin = silent ? null : spinner('Generating context documents...');
|
|
62
88
|
let lastProgress = '';
|
|
63
89
|
const result = await generateContext({
|
|
64
90
|
repoPath,
|
|
@@ -66,13 +92,17 @@ async function runInit(options) {
|
|
|
66
92
|
maxFiles,
|
|
67
93
|
useCache,
|
|
68
94
|
onProgress: (msg) => {
|
|
69
|
-
if (msg !== lastProgress) {
|
|
70
|
-
genSpin
|
|
95
|
+
if (!silent && msg !== lastProgress) {
|
|
96
|
+
if (genSpin) {
|
|
97
|
+
genSpin.text = msg;
|
|
98
|
+
}
|
|
71
99
|
lastProgress = msg;
|
|
72
100
|
}
|
|
73
101
|
},
|
|
74
102
|
});
|
|
75
|
-
|
|
103
|
+
if (!silent) {
|
|
104
|
+
genSpin?.succeed('Context generation complete!');
|
|
105
|
+
}
|
|
76
106
|
// Write files to disk
|
|
77
107
|
const outputDir = join(repoPath, 'agentbrain');
|
|
78
108
|
if (!existsSync(outputDir)) {
|
|
@@ -83,18 +113,40 @@ async function runInit(options) {
|
|
|
83
113
|
const filePath = join(outputDir, fileName);
|
|
84
114
|
await writeFile(filePath, doc.content, 'utf-8');
|
|
85
115
|
}
|
|
116
|
+
// Inject into agent files
|
|
117
|
+
if (!skipInject) {
|
|
118
|
+
const agents = detectAgents(repoPath);
|
|
119
|
+
if (agents.length > 0) {
|
|
120
|
+
const gitHash = scanResult.gitHash;
|
|
121
|
+
const injectionResults = await injectIntoAllAgents(repoPath, gitHash);
|
|
122
|
+
if (!silent && injectionResults.length > 0) {
|
|
123
|
+
console.log();
|
|
124
|
+
info('Updated agent files with context loading instructions:');
|
|
125
|
+
for (const { agent, created, updated } of injectionResults) {
|
|
126
|
+
const action = created ? 'Created' : updated ? 'Updated' : 'Checked';
|
|
127
|
+
console.log(` ✓ ${action} ${AGENT_FILE_PATHS[agent]}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (!silent) {
|
|
132
|
+
console.log();
|
|
133
|
+
info('No agent files detected. Create CLAUDE.md, .cursor/rules, or .windsurfrules to enable auto-injection.');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
86
136
|
// Display summary
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
'
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
137
|
+
if (!silent) {
|
|
138
|
+
displayGeneratedFiles([
|
|
139
|
+
{ name: 'agentbrain/context.md', description: 'Full repo intelligence' },
|
|
140
|
+
{ name: 'agentbrain/dependency-map.md', description: 'Service relationships' },
|
|
141
|
+
{ name: 'agentbrain/patterns.md', description: 'Coding patterns' },
|
|
142
|
+
]);
|
|
143
|
+
displayActualCost(result.totalTokens, result.cost);
|
|
144
|
+
const nextSteps = ['Run "agentbrain setup" to install git hooks for auto-refresh'];
|
|
145
|
+
if (detectAgents(repoPath).length === 0) {
|
|
146
|
+
nextSteps.push('Create CLAUDE.md, .cursor/rules, or .windsurfrules for your agent');
|
|
147
|
+
}
|
|
148
|
+
displayNextSteps(nextSteps);
|
|
149
|
+
success('AgentBrain initialization complete!');
|
|
150
|
+
}
|
|
99
151
|
}
|
|
100
152
|
//# sourceMappingURL=init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,cAAc,
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,GACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,aAAa,EACb,OAAO,EACP,KAAK,EACL,IAAI,EACJ,OAAO,EACP,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,eAAe,CAAA;AAEtB,MAAM,UAA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MAAM,EAAE,CAAC;QACZ,qBAAqB,CAAC;YACpB,EAAE,IAAI,EAAE,uBAAuB,EAAE,WAAW,EAAE,wBAAwB,EAAE;YACxE,EAAE,IAAI,EAAE,8BAA8B,EAAE,WAAW,EAAE,uBAAuB,EAAE;YAC9E,EAAE,IAAI,EAAE,wBAAwB,EAAE,WAAW,EAAE,iBAAiB,EAAE;SACnE,CAAC,CAAA;QAEF,iBAAiB,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAElD,MAAM,SAAS,GAAG,CAAC,8DAA8D,CAAC,CAAA;QAElF,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxC,SAAS,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAA;QACrF,CAAC;QAED,gBAAgB,CAAC,SAAS,CAAC,CAAA;QAE3B,OAAO,CAAC,qCAAqC,CAAC,CAAA;IAChD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AA0BnC,wBAAgB,kBAAkB,IAAI,OAAO,CAgB5C"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Setup command - one-command complete setup
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { confirm, checkbox } from '@inquirer/prompts';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { isGitRepository, installAllHooks, detectAgents, loadAIConfig, generateContext, injectIntoAllAgents, AGENT_FILE_PATHS, } from '@agentbrain/core';
|
|
6
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { displayBanner, success, error, info, spinner, displayGeneratedFiles, displayActualCost, } from '../display.js';
|
|
10
|
+
export function createSetupCommand() {
|
|
11
|
+
const cmd = new Command('setup')
|
|
12
|
+
.description('One-command setup for AgentBrain (init + hooks + agent files)')
|
|
13
|
+
.option('--path <path>', 'Repository path', process.cwd())
|
|
14
|
+
.option('--skip-hooks', 'Skip git hooks installation')
|
|
15
|
+
.option('--skip-agent-files', 'Skip agent file injection')
|
|
16
|
+
.action(async (options) => {
|
|
17
|
+
try {
|
|
18
|
+
await runSetup(options);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
error(err instanceof Error ? err.message : 'Setup failed');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return cmd;
|
|
26
|
+
}
|
|
27
|
+
async function runSetup(options) {
|
|
28
|
+
displayBanner();
|
|
29
|
+
const repoPath = resolve(options.path);
|
|
30
|
+
info(`Repository: ${repoPath}`);
|
|
31
|
+
console.log();
|
|
32
|
+
// Check git repository
|
|
33
|
+
if (!isGitRepository(repoPath)) {
|
|
34
|
+
error('Not a git repository. Please run "git init" first.');
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
// Step 1: Detect or select agents
|
|
38
|
+
let selectedAgents = detectAgents(repoPath);
|
|
39
|
+
if (selectedAgents.length === 0 && !options.skipAgentFiles) {
|
|
40
|
+
info('No agent files detected. Which agent(s) do you use?\n');
|
|
41
|
+
const agents = await checkbox({
|
|
42
|
+
message: 'Select all that apply:',
|
|
43
|
+
choices: [
|
|
44
|
+
{ name: 'Claude Code (CLAUDE.md)', value: 'claude-code' },
|
|
45
|
+
{ name: 'Cursor (.cursor/rules)', value: 'cursor' },
|
|
46
|
+
{ name: 'Windsurf (.windsurfrules)', value: 'windsurf' },
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
selectedAgents = agents;
|
|
50
|
+
if (selectedAgents.length === 0) {
|
|
51
|
+
info('\nNo agents selected. Skipping agent file creation.');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Step 2: Load AI config
|
|
55
|
+
info('\nLoading AI configuration...');
|
|
56
|
+
const aiConfig = await loadAIConfig();
|
|
57
|
+
info(`✓ Using ${aiConfig.provider} API`);
|
|
58
|
+
// Step 3: Generate context
|
|
59
|
+
console.log();
|
|
60
|
+
const confirmed = await confirm({
|
|
61
|
+
message: 'Generate initial context documentation?',
|
|
62
|
+
default: true,
|
|
63
|
+
});
|
|
64
|
+
if (!confirmed) {
|
|
65
|
+
info('Skipping context generation.');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const spin = spinner('Generating context...');
|
|
69
|
+
const result = await generateContext({
|
|
70
|
+
repoPath,
|
|
71
|
+
aiConfig,
|
|
72
|
+
maxFiles: 100,
|
|
73
|
+
useCache: true,
|
|
74
|
+
onProgress: (msg) => {
|
|
75
|
+
spin.text = msg;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
spin.succeed('Context generated!');
|
|
79
|
+
// Write files
|
|
80
|
+
const outputDir = join(repoPath, 'agentbrain');
|
|
81
|
+
if (!existsSync(outputDir)) {
|
|
82
|
+
await mkdir(outputDir, { recursive: true });
|
|
83
|
+
}
|
|
84
|
+
for (const doc of result.docs) {
|
|
85
|
+
const fileName = `${doc.type}.md`;
|
|
86
|
+
const filePath = join(outputDir, fileName);
|
|
87
|
+
await writeFile(filePath, doc.content, 'utf-8');
|
|
88
|
+
}
|
|
89
|
+
// Get git hash from result
|
|
90
|
+
const gitHash = result.docs[0]?.gitHash || 'unknown';
|
|
91
|
+
// Step 4: Inject into agent files
|
|
92
|
+
if (!options.skipAgentFiles && selectedAgents.length > 0) {
|
|
93
|
+
console.log();
|
|
94
|
+
info('Updating agent files...');
|
|
95
|
+
for (const agent of selectedAgents) {
|
|
96
|
+
await injectIntoAllAgents(repoPath, gitHash);
|
|
97
|
+
const filePath = AGENT_FILE_PATHS[agent];
|
|
98
|
+
console.log(` ✓ Updated ${filePath}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Step 5: Install git hooks
|
|
102
|
+
if (!options.skipHooks) {
|
|
103
|
+
console.log();
|
|
104
|
+
const installHooks = await confirm({
|
|
105
|
+
message: 'Install git hooks for auto-refresh on commits?',
|
|
106
|
+
default: true,
|
|
107
|
+
});
|
|
108
|
+
if (installHooks) {
|
|
109
|
+
const { installed } = await installAllHooks(repoPath);
|
|
110
|
+
info('Git hooks installed:');
|
|
111
|
+
for (const hook of installed) {
|
|
112
|
+
console.log(` ✓ ${hook}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Summary
|
|
117
|
+
console.log();
|
|
118
|
+
displayGeneratedFiles([
|
|
119
|
+
{ name: 'agentbrain/context.md', description: 'Full repo intelligence' },
|
|
120
|
+
{ name: 'agentbrain/dependency-map.md', description: 'Service relationships' },
|
|
121
|
+
{ name: 'agentbrain/patterns.md', description: 'Coding patterns' },
|
|
122
|
+
]);
|
|
123
|
+
displayActualCost(result.totalTokens, result.cost);
|
|
124
|
+
console.log();
|
|
125
|
+
success('🎉 AgentBrain setup complete!');
|
|
126
|
+
console.log();
|
|
127
|
+
console.log('What happens now:');
|
|
128
|
+
console.log(' ✓ Your agent will automatically load context at session start');
|
|
129
|
+
console.log(' ✓ Context refreshes automatically after every commit');
|
|
130
|
+
console.log(' ✓ Handoff documents generated automatically');
|
|
131
|
+
console.log();
|
|
132
|
+
console.log('Just start coding - AgentBrain works invisibly in the background!');
|
|
133
|
+
console.log();
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,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AC,iEAAiE,CAAC,CAAA;IAC9E,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAA;IACrE,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAA;IAC5D,OAAO,CAAC,GAAG,EAAE,CAAA;IACb,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAA;IAChF,OAAO,CAAC,GAAG,EAAE,CAAA;AACf,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,12 +5,14 @@ import { createConfigCommand } from './commands/config.js';
|
|
|
5
5
|
import { createInitCommand } from './commands/init.js';
|
|
6
6
|
import { createStandardsCommand } from './commands/standards.js';
|
|
7
7
|
import { createHandoffCommand } from './commands/handoff.js';
|
|
8
|
+
import { createSetupCommand } from './commands/setup.js';
|
|
8
9
|
const program = new Command();
|
|
9
10
|
program
|
|
10
11
|
.name('agentbrain')
|
|
11
12
|
.description('Generate smart context docs for coding agents')
|
|
12
|
-
.version('1.
|
|
13
|
+
.version('1.3.1');
|
|
13
14
|
// Add commands
|
|
15
|
+
program.addCommand(createSetupCommand());
|
|
14
16
|
program.addCommand(createInitCommand());
|
|
15
17
|
program.addCommand(createStandardsCommand());
|
|
16
18
|
program.addCommand(createHandoffCommand());
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,6BAA6B;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,6BAA6B;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAExD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;AAE7B,OAAO;KACJ,IAAI,CAAC,YAAY,CAAC;KAClB,WAAW,CAAC,+CAA+C,CAAC;KAC5D,OAAO,CAAC,OAAO,CAAC,CAAA;AAEnB,eAAe;AACf,OAAO,CAAC,UAAU,CAAC,kBAAkB,EAAE,CAAC,CAAA;AACxC,OAAO,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAC,CAAA;AACvC,OAAO,CAAC,UAAU,CAAC,sBAAsB,EAAE,CAAC,CAAA;AAC5C,OAAO,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,CAAA;AAC1C,OAAO,CAAC,UAAU,CAAC,mBAAmB,EAAE,CAAC,CAAA;AAEzC,kBAAkB;AAClB,OAAO,CAAC,KAAK,EAAE,CAAA"}
|