golem-cc 0.1.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/bin/golem ADDED
@@ -0,0 +1,555 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Golem - Autonomous coding loop
4
+ #
5
+ # Usage:
6
+ # golem Launch interactive session
7
+ # golem --yolo Launch with --dangerously-skip-permissions
8
+ # golem --install Install golem to current project
9
+ # golem spec Build specs through conversation
10
+ # golem run plan Create implementation plan
11
+ # golem run build Run autonomous build loop
12
+ # golem simplify [path] Run code simplifier
13
+ # golem status Show project status
14
+ #
15
+ set -euo pipefail
16
+
17
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
18
+ # When installed globally, GOLEM_DIR is ~/.golem
19
+ # When run from source, it's the parent of bin/
20
+ if [[ -d "$HOME/.golem/golem" ]]; then
21
+ GOLEM_DIR="$HOME/.golem"
22
+ else
23
+ GOLEM_DIR="$(dirname "$SCRIPT_DIR")"
24
+ fi
25
+
26
+ # Colors
27
+ RED='\033[0;31m'
28
+ GREEN='\033[0;32m'
29
+ YELLOW='\033[0;33m'
30
+ BLUE='\033[0;34m'
31
+ CYAN='\033[0;36m'
32
+ DIM='\033[2m'
33
+ NC='\033[0m'
34
+
35
+ print_banner() {
36
+ echo -e "${CYAN}"
37
+ echo " ██████╗ ██████╗ ██╗ ███████╗███╗ ███╗"
38
+ echo " ██╔════╝ ██╔═══██╗██║ ██╔════╝████╗ ████║"
39
+ echo " ██║ ███╗██║ ██║██║ █████╗ ██╔████╔██║"
40
+ echo " ██║ ██║██║ ██║██║ ██╔══╝ ██║╚██╔╝██║"
41
+ echo " ╚██████╔╝╚██████╔╝███████╗███████╗██║ ╚═╝ ██║"
42
+ echo " ╚═════╝ ╚═════╝ ╚══════╝╚══════╝╚═╝ ╚═╝"
43
+ echo -e "${NC}"
44
+ echo -e " ${DIM}Autonomous Coding Loop${NC}"
45
+ echo ""
46
+ }
47
+
48
+ print_usage() {
49
+ echo -e "${BLUE}Usage:${NC} golem <command> [options]"
50
+ echo ""
51
+ echo -e "${BLUE}Commands:${NC}"
52
+ echo " spec Build specs through guided conversation"
53
+ echo " run plan Create implementation plan from specs"
54
+ echo " run build Run autonomous build loop"
55
+ echo " simplify [path] Run code simplifier"
56
+ echo " status Show project status"
57
+ echo ""
58
+ echo -e "${BLUE}Options:${NC}"
59
+ echo " --install Install golem to current project"
60
+ echo " --yolo Launch with --dangerously-skip-permissions"
61
+ echo " --iterations N Limit build loop to N iterations"
62
+ echo " --no-simplify Skip code simplification in build loop"
63
+ echo ""
64
+ echo -e "${BLUE}Workflow:${NC}"
65
+ echo " 1. golem spec Define requirements"
66
+ echo " 2. golem run plan Generate task list"
67
+ echo " 3. golem run build Autonomous implementation"
68
+ }
69
+
70
+ # Check if golem is installed in current project
71
+ check_installed() {
72
+ if [[ ! -d ".golem" ]]; then
73
+ echo -e "${RED}Error: Golem not installed in this project.${NC}"
74
+ echo -e "Run: ${CYAN}golem --install${NC}"
75
+ exit 1
76
+ fi
77
+ }
78
+
79
+ # Install golem to current project
80
+ cmd_install() {
81
+ print_banner
82
+ echo -e "${BLUE}Installing golem...${NC}"
83
+ echo ""
84
+
85
+ # Create directories
86
+ mkdir -p .golem/prompts
87
+ mkdir -p .golem/agents
88
+ mkdir -p specs
89
+
90
+ # Copy prompts and agents
91
+ if [[ -d "$GOLEM_DIR/golem" ]]; then
92
+ cp "$GOLEM_DIR/golem/prompts/"*.md .golem/prompts/ 2>/dev/null || true
93
+ cp "$GOLEM_DIR/golem/agents/"*.md .golem/agents/ 2>/dev/null || true
94
+ fi
95
+
96
+ # Create AGENTS.md if it doesn't exist
97
+ if [[ ! -f "AGENTS.md" ]]; then
98
+ cat > AGENTS.md << 'EOF'
99
+ # Operational Guide
100
+
101
+ ## Commands
102
+
103
+ ### Testing
104
+ ```bash
105
+ npm test
106
+ ```
107
+
108
+ ### Type Checking
109
+ ```bash
110
+ npm run typecheck
111
+ ```
112
+
113
+ ### Linting
114
+ ```bash
115
+ npm run lint
116
+ ```
117
+
118
+ ### Build
119
+ ```bash
120
+ npm run build
121
+ ```
122
+
123
+ ## Learnings
124
+ <!-- Updated during build iterations -->
125
+ EOF
126
+ echo -e "${GREEN}✓${NC} Created AGENTS.md"
127
+ fi
128
+
129
+ # Auto-detect project type
130
+ detect_project
131
+
132
+ echo -e "${GREEN}✓${NC} Created .golem/ directory"
133
+ echo -e "${GREEN}✓${NC} Created specs/ directory"
134
+ echo ""
135
+ echo -e "${BLUE}Next steps:${NC}"
136
+ echo " 1. Run ${CYAN}golem spec${NC} to define requirements"
137
+ echo " 2. Run ${CYAN}golem run plan${NC} to create implementation plan"
138
+ echo " 3. Run ${CYAN}golem run build${NC} to start autonomous coding"
139
+ }
140
+
141
+ detect_project() {
142
+ # Detect and update AGENTS.md based on project type
143
+ if [[ -f "package.json" ]]; then
144
+ echo -e "${GREEN}✓${NC} Detected Node.js project"
145
+
146
+ # Extract actual scripts from package.json
147
+ local test_cmd="npm test"
148
+ local typecheck_cmd=""
149
+ local lint_cmd=""
150
+ local build_cmd=""
151
+
152
+ if command -v jq &>/dev/null; then
153
+ [[ $(jq -r '.scripts.test // empty' package.json 2>/dev/null) ]] && test_cmd="npm test"
154
+ [[ $(jq -r '.scripts.typecheck // empty' package.json 2>/dev/null) ]] && typecheck_cmd="npm run typecheck"
155
+ [[ $(jq -r '.scripts.lint // empty' package.json 2>/dev/null) ]] && lint_cmd="npm run lint"
156
+ [[ $(jq -r '.scripts.build // empty' package.json 2>/dev/null) ]] && build_cmd="npm run build"
157
+ fi
158
+
159
+ # Update AGENTS.md with detected commands
160
+ cat > AGENTS.md << EOF
161
+ # Operational Guide
162
+
163
+ ## Commands
164
+
165
+ ### Testing
166
+ \`\`\`bash
167
+ ${test_cmd}
168
+ \`\`\`
169
+ EOF
170
+ [[ -n "$typecheck_cmd" ]] && cat >> AGENTS.md << EOF
171
+
172
+ ### Type Checking
173
+ \`\`\`bash
174
+ ${typecheck_cmd}
175
+ \`\`\`
176
+ EOF
177
+ [[ -n "$lint_cmd" ]] && cat >> AGENTS.md << EOF
178
+
179
+ ### Linting
180
+ \`\`\`bash
181
+ ${lint_cmd}
182
+ \`\`\`
183
+ EOF
184
+ [[ -n "$build_cmd" ]] && cat >> AGENTS.md << EOF
185
+
186
+ ### Build
187
+ \`\`\`bash
188
+ ${build_cmd}
189
+ \`\`\`
190
+ EOF
191
+ cat >> AGENTS.md << 'EOF'
192
+
193
+ ## Learnings
194
+ <!-- Updated during build iterations -->
195
+ EOF
196
+ elif [[ -f "pyproject.toml" ]] || [[ -f "requirements.txt" ]]; then
197
+ echo -e "${GREEN}✓${NC} Detected Python project"
198
+ elif [[ -f "go.mod" ]]; then
199
+ echo -e "${GREEN}✓${NC} Detected Go project"
200
+ fi
201
+ }
202
+
203
+ # Build specs through conversation
204
+ cmd_spec() {
205
+ check_installed
206
+ print_banner
207
+ echo -e "${BLUE}Launching spec-building conversation...${NC}"
208
+ echo -e "${DIM}This will guide you through defining your project requirements.${NC}"
209
+ echo ""
210
+
211
+ # Launch with spec-builder agent
212
+ if [[ -f ".golem/agents/spec-builder.md" ]]; then
213
+ claude --agent .golem/agents/spec-builder.md
214
+ else
215
+ claude "Help me define specs for this project. Ask me about what I'm building, break it into topics of concern, and create spec files in specs/ directory. Also set up AGENTS.md with test/build commands."
216
+ fi
217
+ }
218
+
219
+ # Run the loop (plan or build mode)
220
+ cmd_run() {
221
+ local mode="${1:-build}"
222
+ shift || true
223
+
224
+ local max_iterations=""
225
+ local simplify="true"
226
+
227
+ # Parse options
228
+ while [[ $# -gt 0 ]]; do
229
+ case $1 in
230
+ --iterations)
231
+ max_iterations="$2"
232
+ shift 2
233
+ ;;
234
+ --no-simplify)
235
+ simplify="false"
236
+ shift
237
+ ;;
238
+ *)
239
+ echo -e "${RED}Unknown option: $1${NC}"
240
+ exit 1
241
+ ;;
242
+ esac
243
+ done
244
+
245
+ check_installed
246
+
247
+ case "$mode" in
248
+ plan)
249
+ run_plan_mode
250
+ ;;
251
+ build)
252
+ run_build_loop "$max_iterations" "$simplify"
253
+ ;;
254
+ *)
255
+ echo -e "${RED}Unknown mode: $mode. Use 'plan' or 'build'.${NC}"
256
+ exit 1
257
+ ;;
258
+ esac
259
+ }
260
+
261
+ run_plan_mode() {
262
+ print_banner
263
+ echo -e "${BLUE}Running planning mode...${NC}"
264
+ echo -e "${DIM}Analyzing specs and creating implementation plan.${NC}"
265
+ echo ""
266
+
267
+ # Build context
268
+ local context=""
269
+ context+="You are in PLANNING MODE. Analyze the specs and create IMPLEMENTATION_PLAN.md.\n\n"
270
+ context+="DO NOT implement anything. Only create the plan.\n\n"
271
+
272
+ # Add prompts if available
273
+ if [[ -f ".golem/prompts/PROMPT_plan.md" ]]; then
274
+ context+="$(cat .golem/prompts/PROMPT_plan.md)\n\n"
275
+ fi
276
+
277
+ context+="---\n\n# Specs\n\n"
278
+ for spec in specs/*.md; do
279
+ if [[ -f "$spec" ]]; then
280
+ context+="## $(basename "$spec" .md)\n\n"
281
+ context+="$(cat "$spec")\n\n"
282
+ fi
283
+ done
284
+
285
+ if [[ -f "AGENTS.md" ]]; then
286
+ context+="\n---\n\n# Operational Guide\n\n$(cat AGENTS.md)\n"
287
+ fi
288
+
289
+ # Run single planning iteration
290
+ echo -e "$context" | claude --print --dangerously-skip-permissions
291
+
292
+ echo ""
293
+ echo -e "${GREEN}Planning complete.${NC}"
294
+ echo -e "Run ${CYAN}golem run build${NC} to start implementation."
295
+ }
296
+
297
+ run_build_loop() {
298
+ local max_iterations="$1"
299
+ local simplify="$2"
300
+
301
+ print_banner
302
+
303
+ # Verify prerequisites
304
+ if [[ ! -f "IMPLEMENTATION_PLAN.md" ]]; then
305
+ echo -e "${YELLOW}No implementation plan found.${NC}"
306
+ echo -e "Run ${CYAN}golem run plan${NC} first."
307
+ exit 1
308
+ fi
309
+
310
+ if [[ ! -d "specs" ]] || [[ -z "$(ls -A specs/*.md 2>/dev/null)" ]]; then
311
+ echo -e "${YELLOW}No specs found.${NC}"
312
+ echo -e "Run ${CYAN}golem spec${NC} first."
313
+ exit 1
314
+ fi
315
+
316
+ echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
317
+ echo -e "${CYAN} BUILD LOOP STARTED${NC}"
318
+ if [[ "$simplify" == "true" ]]; then
319
+ echo -e "${CYAN} Mode: Implement → Simplify (2 steps per iteration)${NC}"
320
+ fi
321
+ echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
322
+
323
+ local iteration=0
324
+ local start_time=$(date +%s)
325
+
326
+ while true; do
327
+ iteration=$((iteration + 1))
328
+
329
+ # Check iteration limit
330
+ if [[ -n "$max_iterations" ]] && [[ $iteration -gt $max_iterations ]]; then
331
+ echo -e "${YELLOW}Reached iteration limit ($max_iterations). Stopping.${NC}"
332
+ break
333
+ fi
334
+
335
+ # Check remaining tasks
336
+ local remaining=$(grep -c '^\- \[ \]' IMPLEMENTATION_PLAN.md 2>/dev/null || echo "0")
337
+ if [[ "$remaining" == "0" ]]; then
338
+ echo -e "${GREEN}All tasks completed!${NC}"
339
+ break
340
+ fi
341
+
342
+ echo ""
343
+ echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
344
+ echo -e "${BLUE} ITERATION $iteration │ $remaining tasks remaining${NC}"
345
+ echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
346
+
347
+ # Get the current task (first incomplete) for context
348
+ local current_task=$(grep -A3 '^\- \[ \]' IMPLEMENTATION_PLAN.md 2>/dev/null | head -4)
349
+
350
+ # ═══════════════════════════════════════════════════════════
351
+ # STEP 1: IMPLEMENT
352
+ # ═══════════════════════════════════════════════════════════
353
+ echo ""
354
+ echo -e "${GREEN}▶ Step 1: Implement${NC}"
355
+
356
+ local context=""
357
+ context+="You are in BUILD MODE. Complete ONE task from the plan.\n\n"
358
+ context+="DO NOT commit - just implement, test, update plan, and stage changes.\n"
359
+ context+="The commit will happen after simplification.\n\n"
360
+
361
+ # Add build prompt if available
362
+ if [[ -f ".golem/prompts/PROMPT_build.md" ]]; then
363
+ context+="$(cat .golem/prompts/PROMPT_build.md)\n\n"
364
+ fi
365
+
366
+ context+="---\n\n# Specs\n\n"
367
+ for spec in specs/*.md; do
368
+ if [[ -f "$spec" ]]; then
369
+ context+="## $(basename "$spec" .md)\n\n"
370
+ context+="$(cat "$spec")\n\n"
371
+ fi
372
+ done
373
+
374
+ if [[ -f "AGENTS.md" ]]; then
375
+ context+="\n---\n\n# Operational Guide\n\n$(cat AGENTS.md)\n"
376
+ fi
377
+
378
+ context+="\n---\n\n# Implementation Plan\n\n$(cat IMPLEMENTATION_PLAN.md)\n"
379
+
380
+ # Run implementation step
381
+ echo -e "$context" | claude --print --dangerously-skip-permissions
382
+
383
+ local exit_code=$?
384
+ if [[ $exit_code -ne 0 ]]; then
385
+ echo -e "${RED}Implementation step exited with error code $exit_code${NC}"
386
+ fi
387
+
388
+ # ═══════════════════════════════════════════════════════════
389
+ # STEP 2: SIMPLIFY + COMMIT
390
+ # ═══════════════════════════════════════════════════════════
391
+ echo ""
392
+ echo -e "${GREEN}▶ Step 2: Simplify + Commit${NC}"
393
+
394
+ # Get staged files
395
+ local staged_files=$(git diff --cached --name-only 2>/dev/null | grep -E '\.(ts|tsx|js|jsx|py|go|rs)$' | grep -v '\.test\.' | grep -v '\.spec\.' | head -10)
396
+
397
+ local simplify_context=""
398
+ simplify_context+="You are in SIMPLIFY + COMMIT MODE.\n\n"
399
+
400
+ if [[ "$simplify" == "true" ]] && [[ -n "$staged_files" ]]; then
401
+ simplify_context+="1. Simplify the staged source files (not tests)\n"
402
+ simplify_context+="2. Run tests to verify no regressions\n"
403
+ simplify_context+="3. Stage any changes from simplification\n"
404
+ simplify_context+="4. Create a single commit with a comprehensive message\n\n"
405
+
406
+ # Add code-simplifier agent if available
407
+ if [[ -f ".golem/agents/code-simplifier.md" ]]; then
408
+ simplify_context+="$(cat .golem/agents/code-simplifier.md)\n\n"
409
+ fi
410
+
411
+ simplify_context+="---\n\n# Staged source files to simplify\n\n"
412
+ simplify_context+="$staged_files\n\n"
413
+ else
414
+ simplify_context+="No source files to simplify. Just create the commit.\n\n"
415
+ simplify_context+="Use conventional commit format with a descriptive body.\n\n"
416
+ fi
417
+
418
+ simplify_context+="---\n\n# Task that was just completed\n\n"
419
+ simplify_context+="$current_task\n\n"
420
+
421
+ if [[ -f "AGENTS.md" ]]; then
422
+ simplify_context+="---\n\n# Operational Guide (for running tests)\n\n$(cat AGENTS.md)\n"
423
+ fi
424
+
425
+ # Run simplification + commit step
426
+ echo -e "$simplify_context" | claude --print --dangerously-skip-permissions
427
+
428
+ exit_code=$?
429
+ if [[ $exit_code -ne 0 ]]; then
430
+ echo -e "${RED}Simplify + commit step exited with error code $exit_code${NC}"
431
+ fi
432
+
433
+ # Brief pause between iterations
434
+ sleep 2
435
+ done
436
+
437
+ local end_time=$(date +%s)
438
+ local duration=$((end_time - start_time))
439
+ local minutes=$((duration / 60))
440
+ local seconds=$((duration % 60))
441
+
442
+ echo ""
443
+ echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
444
+ echo -e "${CYAN} BUILD LOOP COMPLETE${NC}"
445
+ echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
446
+ echo -e " Iterations: $iteration"
447
+ echo -e " Duration: ${minutes}m ${seconds}s"
448
+
449
+ if [[ -f "IMPLEMENTATION_PLAN.md" ]]; then
450
+ local total=$(grep -c '^\- \[' IMPLEMENTATION_PLAN.md 2>/dev/null || echo "0")
451
+ local done=$(grep -c '^\- \[x\]' IMPLEMENTATION_PLAN.md 2>/dev/null || echo "0")
452
+ echo -e " Tasks: $done / $total completed"
453
+ fi
454
+ echo ""
455
+ }
456
+
457
+ cmd_simplify() {
458
+ local target="${1:-.}"
459
+ check_installed
460
+ print_banner
461
+ echo -e "${BLUE}Running code simplifier on: $target${NC}"
462
+ echo ""
463
+
464
+ if [[ -f ".golem/agents/code-simplifier.md" ]]; then
465
+ claude --agent .golem/agents/code-simplifier.md "Simplify the code in: $target"
466
+ else
467
+ claude "Simplify the code in $target. Remove unnecessary comments, flatten nested conditionals, improve naming. Preserve all behavior. Run tests after."
468
+ fi
469
+ }
470
+
471
+ cmd_status() {
472
+ check_installed
473
+ print_banner
474
+
475
+ echo -e "${BLUE}PROJECT STATUS${NC}"
476
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
477
+ echo ""
478
+
479
+ # Specs
480
+ echo -e "${BLUE}Specs${NC}"
481
+ if [[ -d "specs" ]]; then
482
+ local count=$(ls -1 specs/*.md 2>/dev/null | wc -l | tr -d ' ')
483
+ echo " Files: $count"
484
+ for f in specs/*.md; do
485
+ [[ -f "$f" ]] && echo " • $(basename "$f" .md)"
486
+ done
487
+ else
488
+ echo " No specs/ directory"
489
+ fi
490
+ echo ""
491
+
492
+ # Plan
493
+ echo -e "${BLUE}Implementation Plan${NC}"
494
+ if [[ -f "IMPLEMENTATION_PLAN.md" ]]; then
495
+ local total=$(grep -c '^\- \[' IMPLEMENTATION_PLAN.md 2>/dev/null || echo "0")
496
+ local done=$(grep -c '^\- \[x\]' IMPLEMENTATION_PLAN.md 2>/dev/null || echo "0")
497
+ local remaining=$((total - done))
498
+ echo " Total: $total tasks"
499
+ echo " Completed: $done"
500
+ echo " Remaining: $remaining"
501
+ else
502
+ echo " No plan yet - run 'golem run plan'"
503
+ fi
504
+ echo ""
505
+
506
+ # Git
507
+ if git rev-parse --is-inside-work-tree &>/dev/null; then
508
+ echo -e "${BLUE}Recent Commits${NC}"
509
+ git log --oneline -5 2>/dev/null || echo " No commits yet"
510
+ fi
511
+ echo ""
512
+ }
513
+
514
+ # Main entry point
515
+ main() {
516
+ local command="${1:-}"
517
+
518
+ case "$command" in
519
+ --install)
520
+ cmd_install
521
+ ;;
522
+ --yolo)
523
+ shift
524
+ claude --dangerously-skip-permissions "$@"
525
+ ;;
526
+ --help|-h|help)
527
+ print_banner
528
+ print_usage
529
+ ;;
530
+ spec)
531
+ cmd_spec
532
+ ;;
533
+ run)
534
+ shift
535
+ cmd_run "$@"
536
+ ;;
537
+ simplify)
538
+ shift
539
+ cmd_simplify "$@"
540
+ ;;
541
+ status)
542
+ cmd_status
543
+ ;;
544
+ "")
545
+ # No command - just launch claude
546
+ claude
547
+ ;;
548
+ *)
549
+ # Pass through to claude
550
+ claude "$@"
551
+ ;;
552
+ esac
553
+ }
554
+
555
+ main "$@"