golem-cc 2.1.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/.claude/commands/golem/build.md +18 -0
  2. package/.claude/commands/golem/config.md +39 -0
  3. package/.claude/commands/golem/continue.md +73 -0
  4. package/.claude/commands/golem/doctor.md +46 -0
  5. package/.claude/commands/golem/document.md +138 -0
  6. package/.claude/commands/golem/help.md +58 -0
  7. package/.claude/commands/golem/pause.md +130 -0
  8. package/.claude/commands/golem/plan.md +111 -0
  9. package/.claude/commands/golem/review.md +166 -0
  10. package/.claude/commands/golem/security.md +186 -0
  11. package/.claude/commands/golem/simplify.md +76 -0
  12. package/.claude/commands/golem/spec.md +105 -0
  13. package/.claude/commands/golem/status.md +33 -0
  14. package/.golem/agents/code-simplifier.md +54 -0
  15. package/.golem/agents/review-architecture.md +59 -0
  16. package/.golem/agents/review-logic.md +50 -0
  17. package/.golem/agents/review-security.md +50 -0
  18. package/.golem/agents/review-style.md +48 -0
  19. package/.golem/agents/review-tests.md +48 -0
  20. package/.golem/agents/spec-builder.md +60 -0
  21. package/.golem/bin/golem.mjs +270 -0
  22. package/.golem/lib/build.mjs +557 -0
  23. package/.golem/lib/claude.mjs +95 -0
  24. package/.golem/lib/config.mjs +421 -0
  25. package/.golem/lib/display.mjs +191 -0
  26. package/.golem/lib/doctor.mjs +197 -0
  27. package/.golem/lib/document.mjs +792 -0
  28. package/.golem/lib/gates.mjs +78 -0
  29. package/.golem/lib/init.mjs +166 -0
  30. package/.golem/lib/output.mjs +40 -0
  31. package/.golem/lib/ratelimit.mjs +86 -0
  32. package/.golem/lib/security.mjs +603 -0
  33. package/.golem/lib/simplify.mjs +101 -0
  34. package/.golem/lib/tui.mjs +368 -0
  35. package/.golem/lib/usage.mjs +119 -0
  36. package/.golem/lib/worktree.mjs +509 -0
  37. package/.golem/prompts/build.md +23 -0
  38. package/.golem/prompts/document-inline.md +66 -0
  39. package/.golem/prompts/document-markdown.md +80 -0
  40. package/.golem/prompts/simplify.md +35 -0
  41. package/README.md +141 -142
  42. package/bin/golem-shim.mjs +36 -0
  43. package/bin/install.mjs +193 -0
  44. package/package.json +27 -32
  45. package/.env.example +0 -17
  46. package/bin/golem +0 -1040
  47. package/commands/golem/build.md +0 -235
  48. package/commands/golem/config.md +0 -55
  49. package/commands/golem/doctor.md +0 -137
  50. package/commands/golem/help.md +0 -212
  51. package/commands/golem/plan.md +0 -214
  52. package/commands/golem/review.md +0 -376
  53. package/commands/golem/security.md +0 -204
  54. package/commands/golem/simplify.md +0 -94
  55. package/commands/golem/spec.md +0 -226
  56. package/commands/golem/status.md +0 -60
  57. package/dist/api/freshworks.d.ts +0 -61
  58. package/dist/api/freshworks.d.ts.map +0 -1
  59. package/dist/api/freshworks.js +0 -119
  60. package/dist/api/freshworks.js.map +0 -1
  61. package/dist/api/gitea.d.ts +0 -96
  62. package/dist/api/gitea.d.ts.map +0 -1
  63. package/dist/api/gitea.js +0 -154
  64. package/dist/api/gitea.js.map +0 -1
  65. package/dist/cli/index.d.ts +0 -9
  66. package/dist/cli/index.d.ts.map +0 -1
  67. package/dist/cli/index.js +0 -352
  68. package/dist/cli/index.js.map +0 -1
  69. package/dist/sync/ticket-sync.d.ts +0 -53
  70. package/dist/sync/ticket-sync.d.ts.map +0 -1
  71. package/dist/sync/ticket-sync.js +0 -226
  72. package/dist/sync/ticket-sync.js.map +0 -1
  73. package/dist/types.d.ts +0 -125
  74. package/dist/types.d.ts.map +0 -1
  75. package/dist/types.js +0 -5
  76. package/dist/types.js.map +0 -1
  77. package/dist/worktree/manager.d.ts +0 -54
  78. package/dist/worktree/manager.d.ts.map +0 -1
  79. package/dist/worktree/manager.js +0 -190
  80. package/dist/worktree/manager.js.map +0 -1
  81. package/golem/agents/code-simplifier.md +0 -81
  82. package/golem/agents/spec-builder.md +0 -90
  83. package/golem/prompts/PROMPT_build.md +0 -71
  84. package/golem/prompts/PROMPT_plan.md +0 -102
@@ -0,0 +1,35 @@
1
+ You are a code simplifier. Your job is to reduce complexity without changing behavior.
2
+
3
+ ## Rules
4
+
5
+ - NEVER change behavior — input/output must remain identical
6
+ - NEVER touch test files, type definitions, config files, generated files, or lock files
7
+ - NEVER add, remove, or modify any comments — leave all comments exactly as they are
8
+ - NEVER add docstrings, type annotations, or new dependencies
9
+ - ONE change at a time — validate between each
10
+ - Run tests after EVERY file modification
11
+ - Revert immediately if tests fail
12
+
13
+ ## Priority Order
14
+
15
+ 1. **Reduce complexity** — flatten nesting, use early returns, extract boolean expressions
16
+ 2. **Improve clarity** — rename unclear variables, remove dead code, simplify abstractions
17
+ 3. **Structural** — extract functions >50 lines, inline trivial one-use functions
18
+ 4. **Remove dead code** — defensive checks that can't trigger, unreachable branches
19
+
20
+ ## Target Files
21
+
22
+ Simplify ONLY these files, one at a time. Do NOT read, edit, or modify any other files in the project:
23
+
24
+ {{FILES}}
25
+
26
+ ## Process
27
+
28
+ For each file:
29
+ 1. Read the file
30
+ 2. Identify simplifications using the priority order above
31
+ 3. Make ONE change
32
+ 4. Run tests
33
+ 5. If tests fail, revert and move on
34
+ 6. If tests pass, repeat from step 2 until no more simplifications remain
35
+ 7. Move to the next file
package/README.md CHANGED
@@ -1,210 +1,209 @@
1
- # Golem
1
+ # golem-cc
2
2
 
3
- Personal agentic workflow manager. Integrates Freshservice tickets, Gitea issues, and Claude Code for a unified development workflow.
3
+ Project-scoped autonomous coding agent framework for Claude Code CLI.
4
+
5
+ Golem provides structured workflows for speccing, planning, building, reviewing, and hardening software projects — with a rich terminal UI for the build loop and deep Claude Code integration via slash commands.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  ```bash
8
- # Bootstrap (one command)
10
+ # Install into an existing project
9
11
  pnpm dlx golem-cc
12
+
13
+ # Or with npx
14
+ npx golem-cc
10
15
  ```
11
16
 
12
- This copies everything to `~/.golem/`, links binaries to `~/.local/bin/`, and wires up Claude slash-commands.
17
+ This copies `.golem/` and `.claude/commands/golem/` into your project, detects your framework (Nuxt/Next), and generates `AGENTS.md` with your test/build/lint commands.
13
18
 
14
- After installing, restart your shell and configure:
19
+ After installing, configure for your project:
15
20
 
16
21
  ```bash
17
- # Verify setup
18
- golem doctor
19
-
20
- # Edit credentials
21
- vim ~/.golem/.env
22
-
23
- # Initialize a project
24
- cd your-project && golem init
22
+ npx golem init
25
23
  ```
26
24
 
27
- ### Updating
25
+ ## Prerequisites
28
26
 
29
- ```bash
30
- # From a running install
31
- golem install
32
-
33
- # Or from a local checkout (dev workflow)
34
- golem install --from /path/to/golem-cc
35
- ```
36
-
37
- ## Architecture
38
-
39
- ```
40
- ┌─────────────────────────────────────────────────────────────────────┐
41
- │ GOLEM WORKFLOW │
42
- ├─────────────────────────────────────────────────────────────────────┤
43
- │ │
44
- │ Freshservice Local State Gitea │
45
- │ ┌─────────┐ ┌───────────┐ ┌─────────┐ │
46
- │ │ INC-123 │◄──────►│.golem/ │◄──────►│ Issue │ │
47
- │ │ Ticket │ │tickets/ │ │ #47 │ │
48
- │ └─────────┘ │INC-123.yml│ └─────────┘ │
49
- │ └───────────┘ │
50
- │ │ │
51
- │ ▼ │
52
- │ ┌───────────┐ │
53
- │ │ Worktree │ │
54
- │ │ fix/INC- │ │
55
- │ │ 123-slug │ │
56
- │ └───────────┘ │
57
- │ │ │
58
- │ ┌───────────────┼───────────────┐ │
59
- │ ▼ ▼ ▼ │
60
- │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
61
- │ │/golem: │ │/golem: │ │/golem: │ │
62
- │ │spec │──►│plan │──►│build │ │
63
- │ └──────────┘ └──────────┘ └──────────┘ │
64
- │ │ │ │ │
65
- │ ▼ ▼ ▼ │
66
- │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
67
- │ │.golem/ │ │IMPLEMENT-│ │ wip: │ │
68
- │ │specs/ │ │ATION_ │ │ commits │──► squash │
69
- │ │*.md │ │PLAN.md │ └──────────┘ per stage │
70
- │ └──────────┘ └──────────┘ │
71
- │ │
72
- └─────────────────────────────────────────────────────────────────────┘
73
- ```
74
-
75
- ## Quick Start
76
-
77
- ### 1. Initialize a project
27
+ - **Node.js >= 18**
28
+ - **Claude Code CLI** — [install instructions](https://docs.anthropic.com/en/docs/claude-code)
29
+ - **pnpm** (recommended) or npm
30
+ - **git** configured with user.name and user.email
78
31
 
79
- ```bash
80
- cd your-project
81
- golem init
82
- ```
32
+ Optional (for security scanning):
33
+ - `gitleaks` — `brew install gitleaks`
34
+ - `semgrep` — `brew install semgrep`
35
+ - `trivy` — `brew install trivy`
83
36
 
84
- ### 2. Get a ticket
37
+ ## Workflow
85
38
 
86
- ```bash
87
- # Import existing Freshservice ticket
88
- golem import INC-1234
39
+ The typical golem workflow:
89
40
 
90
- # Or create new ticket
91
- golem new "Fix API timeout issue"
92
41
  ```
93
-
94
- ### 3. Create worktree
95
-
96
- ```bash
97
- golem worktree INC-1234
98
- cd .golem/worktrees/fix/INC-1234-api-timeout
42
+ 1. /golem:spec → Build specs through guided conversation
43
+ 2. /golem:plan → Generate staged implementation plan
44
+ 3. npx golem build → Autonomous build loop with TUI
45
+ 4. /golem:review → Parallel code review (6 agents)
46
+ 5. /golem:security → Security scan before shipping
99
47
  ```
100
48
 
101
- ### 4. Define specs (in Claude Code)
49
+ ### 1. Write Specs
50
+
51
+ Inside Claude Code CLI:
102
52
 
103
53
  ```
104
54
  /golem:spec
105
55
  ```
106
56
 
107
- Interactive conversation to define requirements, tests, and constraints.
57
+ This runs a guided conversation with three perspectives (UX Advocate, Architect, Devil's Advocate) to produce spec files in `.golem/specs/`.
108
58
 
109
- ### 5. Create plan (in Claude Code)
59
+ ### 2. Generate Plan
110
60
 
111
61
  ```
112
62
  /golem:plan
113
63
  ```
114
64
 
115
- Generates `.golem/IMPLEMENTATION_PLAN.md` with staged tasks.
65
+ Reads all specs, analyzes the codebase, and generates `.golem/IMPLEMENTATION_PLAN.md` with staged tasks.
116
66
 
117
- ### 6. Build (CLI loop or Claude Code)
67
+ ### 3. Build
118
68
 
119
69
  ```bash
120
- # CLI - loops until done
121
- golem build
70
+ # Full autonomous build loop with TUI
71
+ npx golem build
122
72
 
123
- # Or in Claude Code - one task at a time
124
- /golem:build
73
+ # Limit to N iterations
74
+ npx golem build --iterations 3
75
+
76
+ # Preview next task without executing
77
+ npx golem build --dry-run
78
+
79
+ # Skip simplification pass
80
+ npx golem build --no-simplify
125
81
  ```
126
82
 
127
- Each task gets a WIP commit. Each stage gets squashed.
83
+ The build loop reads the implementation plan, finds the next incomplete task, spawns Claude with a focused prompt, streams output through a full-screen TUI with progress bar and usage sparklines, then commits on success.
128
84
 
129
- ### 7. Create PR
85
+ ### 4. Review
86
+
87
+ ```
88
+ /golem:review
89
+ ```
90
+
91
+ Spawns 6 parallel review agents (security, logic, style, tests, architecture, devil's advocate) and produces `.golem/REVIEW_REPORT.md`.
92
+
93
+ ### 5. Security Scan
130
94
 
131
95
  ```bash
132
- golem pr
96
+ # Default scan (gitleaks + semgrep + pnpm audit + env checks)
97
+ npx golem security
98
+
99
+ # Full scan (adds git history, trivy, outdated deps, file perms, headers)
100
+ npx golem security --full
101
+
102
+ # Auto-install missing security tools
103
+ npx golem security --fix
104
+
105
+ # Install pre-commit hook for gitleaks
106
+ npx golem security --pre-commit
133
107
  ```
134
108
 
135
109
  ## Commands
136
110
 
137
- ### Terminal
111
+ ### Terminal (npx golem)
138
112
 
139
113
  | Command | Description |
140
114
  |---------|-------------|
141
- | `golem new <subject>` | Create new ticket |
142
- | `golem import <INC-XXX>` | Import Freshservice ticket |
143
- | `golem list` | List tracked tickets |
144
- | `golem status [ticket]` | Show ticket or project status |
145
- | `golem worktree [ticket]` | Create/show worktree |
146
- | `golem worktrees` | List all worktrees |
147
- | `golem build` | Run autonomous build loop |
148
- | `golem plan` | Generate implementation plan |
149
- | `golem simplify [files]` | Run code simplifier |
150
- | `golem squash` | Squash stage commits |
151
- | `golem pr` | Create pull request |
152
- | `golem sync` | Sync status to Freshservice/Gitea |
153
- | `golem config` | Show current configuration |
154
- | `golem doctor` | Diagnose setup issues |
155
- | `golem init` | Initialize golem in current project |
156
- | `golem help` | Show help |
157
-
158
- ### Claude Code
115
+ | `build` | Run autonomous build loop with TUI |
116
+ | `security` | Run security scans |
117
+ | `simplify [path]` | Run code simplifier (defaults to last commit) |
118
+ | `doctor` | Diagnose setup issues |
119
+ | `config show` | Display current configuration |
120
+ | `config set <key> <value>` | Set a config value |
121
+ | `init` | Initialize golem for this project |
122
+ | `status` | Show plan progress |
123
+ | `help` | Show all commands |
124
+
125
+ ### Claude Code Slash Commands
159
126
 
160
127
  | Command | Description |
161
128
  |---------|-------------|
162
- | `/golem:spec` | Define specs interactively |
163
- | `/golem:plan` | Generate implementation plan |
164
- | `/golem:build` | Run one build iteration |
129
+ | `/golem:spec` | Build specs through guided conversation |
130
+ | `/golem:plan` | Generate implementation plan from specs |
131
+ | `/golem:build` | Shows build instructions (redirects to terminal) |
132
+ | `/golem:review` | Run parallel code review |
133
+ | `/golem:security` | Run security scan |
165
134
  | `/golem:simplify` | Run code simplifier |
166
- | `/golem:status` | Show current status |
167
- | `/golem:config` | Show configuration |
135
+ | `/golem:status` | Show project status |
168
136
  | `/golem:doctor` | Diagnose setup issues |
169
- | `/golem:help` | Show help |
137
+ | `/golem:config` | Show configuration |
138
+ | `/golem:help` | Show all commands |
170
139
 
171
140
  ## Configuration
172
141
 
173
- ### Environment Variables
142
+ Configuration lives in `.golem/config.json`:
174
143
 
175
- ```bash
176
- # ~/.golem/.env
144
+ ```json
145
+ {
146
+ "model": "opus",
147
+ "autoCommit": true,
148
+ "simplifyOnBuild": true
149
+ }
150
+ ```
177
151
 
178
- # Freshservice
179
- FRESH_DOMAIN=yourcompany.freshservice.com
180
- FRESH_API_KEY=your_api_key
181
- FRESH_DEFAULT_GROUP_ID=12345 # Optional
182
- FRESH_DEFAULT_CATEGORY=Applications # Optional
183
- FRESH_SOURCE_ID=1002 # Optional
184
- FRESH_DEFAULT_EMAIL=bot@example.com # Optional
152
+ | Key | Default | Description |
153
+ |-----|---------|-------------|
154
+ | `model` | `opus` | Claude model for build loop |
155
+ | `autoCommit` | `true` | Auto-commit after each task |
156
+ | `simplifyOnBuild` | `true` | Run simplifier after building |
185
157
 
186
- # Gitea
187
- GITEA_URL=https://gitea.example.com
188
- GITEA_TOKEN=your_token
189
- GITEA_ORG=your-org
190
- GITEA_REPO=default-repo # Can be overridden per-project
158
+ ```bash
159
+ npx golem config set model sonnet
160
+ npx golem config set autoCommit false
191
161
  ```
192
162
 
193
- ### Project Structure
163
+ ## Project Structure
194
164
 
195
165
  ```
196
166
  .golem/
197
- ├── tickets/ # Local ticket state (YAML)
198
- │ └── INC-1234.yaml
199
- ├── specs/ # Requirement specs
200
- │ ├── feature.md
201
- └── validation.md
202
- ├── worktrees/ # Git worktrees per ticket
203
- └── fix/INC-1234-api-timeout/
204
- ├── AGENTS.md # Operational commands (test/build/lint)
205
- └── IMPLEMENTATION_PLAN.md # Current task list
167
+ ├── bin/golem.mjs # CLI entry point
168
+ ├── lib/ # Core modules
169
+ ├── build.mjs # Build loop orchestrator
170
+ │ ├── claude.mjs # Claude CLI wrapper
171
+ ├── config.mjs # Configuration
172
+ ├── display.mjs # Stream display
173
+ ├── doctor.mjs # Health checks
174
+ ├── init.mjs # Project initialization
175
+ │ ├── output.mjs # chalk/ora output helpers
176
+ │ ├── security.mjs # Security scanning
177
+ │ ├── simplify.mjs # Code simplifier
178
+ │ ├── tui.mjs # Full-screen terminal UI
179
+ │ └── usage.mjs # Token usage reader
180
+ ├── prompts/ # Build/simplify prompts
181
+ ├── agents/ # Agent definitions
182
+ ├── specs/ # Project specs (created by /golem:spec)
183
+ ├── config.json # Project configuration
184
+ ├── AGENTS.md # Operational commands
185
+ └── IMPLEMENTATION_PLAN.md # Task plan (created by /golem:plan)
186
+
187
+ .claude/commands/golem/ # Slash commands for Claude Code CLI
188
+ ```
189
+
190
+ ## Troubleshooting
191
+
192
+ Run the doctor to check your setup:
193
+
194
+ ```bash
195
+ npx golem doctor
196
+
197
+ # Auto-fix common issues
198
+ npx golem doctor --fix
206
199
  ```
207
200
 
201
+ Common issues:
202
+ - **Claude CLI not found** — Install from https://docs.anthropic.com/en/docs/claude-code
203
+ - **No implementation plan** — Run `/golem:plan` in Claude Code first
204
+ - **Empty specs directory** — Run `/golem:spec` in Claude Code first
205
+ - **Security tools missing** — Run `npx golem security --fix` to auto-install
206
+
208
207
  ## License
209
208
 
210
- MIT
209
+ ISC
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync } from 'node:fs';
3
+ import { join, dirname } from 'node:path';
4
+ import { execFileSync } from 'node:child_process';
5
+
6
+ // Walk up from cwd to find .golem/bin/golem.mjs
7
+ function findGolemProject(startDir) {
8
+ let currentDir = startDir;
9
+ while (true) {
10
+ const golemPath = join(currentDir, '.golem', 'bin', 'golem.mjs');
11
+ if (existsSync(golemPath)) {
12
+ return { projectRoot: currentDir, golemPath };
13
+ }
14
+ if (currentDir === '/') return null;
15
+ currentDir = dirname(currentDir);
16
+ }
17
+ }
18
+
19
+ const result = findGolemProject(process.cwd());
20
+
21
+ if (!result) {
22
+ console.error('No golem project found. Run `pnpm dlx golem-cc` to set one up.');
23
+ process.exit(1);
24
+ }
25
+
26
+ const { projectRoot, golemPath } = result;
27
+
28
+ if (process.env.GOLEM_DEBUG === '1') {
29
+ console.log(`[golem-shim] Resolved project root: ${projectRoot}`);
30
+ }
31
+
32
+ try {
33
+ execFileSync('node', [golemPath, ...process.argv.slice(2)], { stdio: 'inherit' });
34
+ } catch (error) {
35
+ process.exit(error.status ?? 1);
36
+ }
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { existsSync, cpSync, mkdirSync, readFileSync, writeFileSync, unlinkSync, rmSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const pkgRoot = join(fileURLToPath(import.meta.url), '..', '..');
8
+ const cwd = process.cwd();
9
+
10
+ // Don't install into ourselves
11
+ if (cwd === pkgRoot) {
12
+ console.error('Cannot install golem into its own package directory.');
13
+ process.exit(1);
14
+ }
15
+
16
+ console.log('◆ Installing golem-cc...\n');
17
+
18
+ // --- Copy .golem/ directory ---
19
+ const golemSrc = join(pkgRoot, '.golem');
20
+ const golemDest = join(cwd, '.golem');
21
+
22
+ if (existsSync(golemDest)) {
23
+ console.log(' ⚠ .golem/ already exists — skipping copy (run golem init to reconfigure)');
24
+ } else {
25
+ cpSync(golemSrc, golemDest, { recursive: true });
26
+ // Remove source-specific files that shouldn't be in a fresh install
27
+ for (const f of ['config.json', 'SECURITY_REPORT.md', 'REVIEW_REPORT.md', 'golem.log', 'AGENTS.md', 'IMPLEMENTATION_PLAN.md', 'HANDOFF.md']) {
28
+ const p = join(golemDest, f);
29
+ if (existsSync(p)) unlinkSync(p);
30
+ }
31
+ // Remove specs (project-specific)
32
+ const specsDir = join(golemDest, 'specs');
33
+ if (existsSync(specsDir)) rmSync(specsDir, { recursive: true, force: true });
34
+ mkdirSync(join(golemDest, 'specs'), { recursive: true });
35
+ console.log(' ✓ Copied .golem/ directory');
36
+ }
37
+
38
+ // --- Copy .claude/commands/golem/ ---
39
+ const cmdsSrc = join(pkgRoot, '.claude', 'commands', 'golem');
40
+ const cmdsDest = join(cwd, '.claude', 'commands', 'golem');
41
+
42
+ if (existsSync(cmdsDest)) {
43
+ console.log(' ⚠ .claude/commands/golem/ already exists — skipping');
44
+ } else {
45
+ mkdirSync(cmdsDest, { recursive: true });
46
+ cpSync(cmdsSrc, cmdsDest, { recursive: true });
47
+ console.log(' ✓ Copied .claude/commands/golem/ slash commands');
48
+ }
49
+
50
+ // --- Detect framework ---
51
+ const framework = detectFramework(cwd);
52
+ if (framework) {
53
+ console.log(` ✓ Detected framework: ${framework}`);
54
+ } else {
55
+ console.log(' ℹ No framework detected (plain Node.js project)');
56
+ }
57
+
58
+ // --- Generate AGENTS.md ---
59
+ const agentsPath = join(cwd, '.golem', 'AGENTS.md');
60
+ if (existsSync(agentsPath)) {
61
+ console.log(' ⚠ AGENTS.md already exists — skipping');
62
+ } else {
63
+ writeFileSync(agentsPath, generateAgentsMd(cwd, framework));
64
+ console.log(' ✓ Generated AGENTS.md');
65
+ }
66
+
67
+ // --- Ensure .gitignore has golem entries ---
68
+ ensureGitignore(cwd);
69
+
70
+ // --- Add golem-cc as devDependency ---
71
+ addDevDependency(cwd);
72
+
73
+ console.log('\n◆ Done! Next steps:');
74
+ console.log(' 1. Run /golem:spec in Claude Code to build your specs');
75
+ console.log(' 2. Run /golem:plan to generate an implementation plan');
76
+ console.log(' 3. Run npx golem build to start building\n');
77
+
78
+
79
+ // --- Helpers ---
80
+
81
+ function readPkg(dir) {
82
+ try { return JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8')); }
83
+ catch { return null; }
84
+ }
85
+
86
+ function detectFramework(dir) {
87
+ const checks = [
88
+ { file: 'nuxt.config.ts', framework: 'nuxt' },
89
+ { file: 'nuxt.config.js', framework: 'nuxt' },
90
+ { file: 'next.config.ts', framework: 'next' },
91
+ { file: 'next.config.js', framework: 'next' },
92
+ { file: 'next.config.mjs', framework: 'next' },
93
+ ];
94
+ for (const { file, framework } of checks) {
95
+ if (existsSync(join(dir, file))) return framework;
96
+ }
97
+ return null;
98
+ }
99
+
100
+ function detectTestCommand(dir) {
101
+ const pkg = readPkg(dir);
102
+ const testScript = pkg?.scripts?.test;
103
+ if (testScript && testScript !== 'echo "Error: no test specified" && exit 1') return testScript;
104
+ if (existsSync(join(dir, 'vitest.config.ts')) || existsSync(join(dir, 'vitest.config.js'))) return 'npx vitest run';
105
+ if (existsSync(join(dir, 'jest.config.ts')) || existsSync(join(dir, 'jest.config.js'))) return 'npx jest';
106
+ return 'node --test';
107
+ }
108
+
109
+ function detectBuildCommand(dir, framework) {
110
+ if (framework === 'nuxt') return 'npx nuxt build';
111
+ if (framework === 'next') return 'npx next build';
112
+ if (readPkg(dir)?.scripts?.build) return 'npm run build';
113
+ return '# No build step — ESM modules run directly';
114
+ }
115
+
116
+ function detectLintCommand(dir) {
117
+ if (readPkg(dir)?.scripts?.lint) return 'npm run lint';
118
+ for (const f of ['eslint.config.js', 'eslint.config.mjs', '.eslintrc.json', '.eslintrc.js']) {
119
+ if (existsSync(join(dir, f))) return 'npx eslint .';
120
+ }
121
+ return '# TBD — will be set up during implementation';
122
+ }
123
+
124
+ function generateAgentsMd(dir, framework) {
125
+ const testCmd = detectTestCommand(dir);
126
+ const buildCmd = detectBuildCommand(dir, framework);
127
+ const lintCmd = detectLintCommand(dir);
128
+ const typeCheck = existsSync(join(dir, 'tsconfig.json')) ? 'npx tsc --noEmit' : '# N/A — plain JavaScript (ESM), no TypeScript';
129
+
130
+ return `# Operational Commands
131
+
132
+ ## Testing
133
+
134
+ \`\`\`bash
135
+ ${testCmd}
136
+ \`\`\`
137
+
138
+ ## Type Checking
139
+
140
+ \`\`\`bash
141
+ ${typeCheck}
142
+ \`\`\`
143
+
144
+ ## Linting
145
+
146
+ \`\`\`bash
147
+ ${lintCmd}
148
+ \`\`\`
149
+
150
+ ## Build
151
+
152
+ \`\`\`bash
153
+ ${buildCmd}
154
+ \`\`\`
155
+
156
+ ## Learnings
157
+
158
+ - ${framework ? `Project uses ${framework} framework` : 'Project uses ESM (type: module in package.json)'}
159
+ - CLI entry point is .golem/bin/golem.mjs
160
+ `;
161
+ }
162
+
163
+ function ensureGitignore(dir) {
164
+ const giPath = join(dir, '.gitignore');
165
+ const entries = ['.env', '.claude/*', '!.claude/commands/', '!.claude/commands/**'];
166
+ let content = '';
167
+
168
+ if (existsSync(giPath)) {
169
+ content = readFileSync(giPath, 'utf-8');
170
+ }
171
+
172
+ const lines = content.split('\n');
173
+ const missing = entries.filter(e => !lines.some(l => l.trim() === e));
174
+
175
+ if (missing.length > 0) {
176
+ const addition = '\n# Golem\n' + missing.join('\n') + '\n';
177
+ writeFileSync(giPath, content.trimEnd() + addition);
178
+ console.log(' ✓ Updated .gitignore');
179
+ }
180
+ }
181
+
182
+ function addDevDependency(dir) {
183
+ const pkg = readPkg(dir);
184
+ if (!pkg) { console.log(' ⚠ No package.json found — skipping devDependency'); return; }
185
+ if (pkg.devDependencies?.['golem-cc'] || pkg.dependencies?.['golem-cc']) {
186
+ console.log(' ⚠ golem-cc already in dependencies — skipping');
187
+ return;
188
+ }
189
+ pkg.devDependencies = pkg.devDependencies || {};
190
+ pkg.devDependencies['golem-cc'] = 'latest';
191
+ writeFileSync(join(dir, 'package.json'), JSON.stringify(pkg, null, 2) + '\n');
192
+ console.log(' ✓ Added golem-cc as devDependency');
193
+ }