Repository navigation
Expand file tree
/
Copy path100x
More file actions
executable file
·1129 lines (984 loc) · 46 KB
/
Copy path100x
File metadata and controls
executable file
·1129 lines (984 loc) · 46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# 100x — The Agentic Engineering Pipeline CLI
#
# Turn one developer into 100 through context engineering, multi-agent
# orchestration, NASA Power of 10 quality gates, and budget enforcement.
#
# Usage:
# 100x run "Add input validation to all API endpoints"
# 100x init
# 100x gate
# 100x parallel "task1" "task2" "task3"
# 100x dashboard
# 100x research "topic"
# 100x history
# 100x doctor
#
# Install:
# git clone https://github.com/theluckystrike/100xagenticdev.git
# ln -sf ~/100xagenticdev/100x /usr/local/bin/100x
#
# Based on: Karpathy's Context Engineering + RouteLLM + NASA P10
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
set -euo pipefail
VERSION="1.1.0"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CONFIG_FILE="${HOME}/.100x.json"
# ── Colors ─────────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m'
# ── Config Loading ────────────────────────────────────────────────────
load_config() {
if [ -f "$CONFIG_FILE" ]; then
BUDGET_MAX="${BUDGET_MAX:-$(jq -r '.budget_max // empty' "$CONFIG_FILE" 2>/dev/null || true)}"
AUTONOMOUS="${AUTONOMOUS:-$(jq -r '.autonomous // empty' "$CONFIG_FILE" 2>/dev/null || true)}"
SRC_DIR="${SRC_DIR:-$(jq -r '.src_dir // empty' "$CONFIG_FILE" 2>/dev/null || true)}"
fi
}
load_config
# ── Defaults ───────────────────────────────────────────────────────────
BUDGET_MAX="${BUDGET_MAX:-10.00}"
MAX_TURNS_ANALYZE="${MAX_TURNS_ANALYZE:-8}"
MAX_TURNS_IMPLEMENT="${MAX_TURNS_IMPLEMENT:-30}"
MAX_TURNS_TEST="${MAX_TURNS_TEST:-15}"
MAX_TURNS_REVIEW="${MAX_TURNS_REVIEW:-8}"
MAX_TURNS_RESEARCH="${MAX_TURNS_RESEARCH:-20}"
PARALLEL_BUDGET="${PARALLEL_BUDGET:-2.00}"
PARALLEL_MAX_TURNS="${PARALLEL_MAX_TURNS:-30}"
AUTONOMOUS="${AUTONOMOUS:-false}"
SRC_DIR="${SRC_DIR:-src}"
# ── Helpers ────────────────────────────────────────────────────────────
banner() {
echo -e "${PURPLE}${BOLD}"
echo " ╔══════════════════════════════════════════╗"
echo " ║ 100x Agentic Pipeline ║"
echo " ║ Context Engineering × Multi-Agent ║"
echo " ║ × NASA P10 Quality Gates ║"
echo " ╚══════════════════════════════════════════╝"
echo -e "${NC}"
}
log() { echo -e "${DIM}[$(date +%H:%M:%S)]${NC} $1"; }
ok() { echo -e "${GREEN}✓${NC} $1"; }
err() { echo -e "${RED}✗${NC} $1" >&2; }
warn(){ echo -e "${YELLOW}!${NC} $1"; }
info(){ echo -e "${BLUE}→${NC} $1"; }
check_claude() {
if ! command -v claude &>/dev/null; then
err "Claude CLI not found. Install: npm install -g @anthropic-ai/claude-code"
exit 1
fi
}
detect_project() {
PROJECT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
PROJECT_NAME="$(basename "$PROJECT_DIR")"
}
detect_src_dir() {
if [ -d "$PROJECT_DIR/src" ]; then SRC_DIR="src"
elif [ -d "$PROJECT_DIR/lib" ]; then SRC_DIR="lib"
elif [ -d "$PROJECT_DIR/app" ]; then SRC_DIR="app"
else SRC_DIR="."
fi
}
# Cross-platform open
open_file() {
local filepath="$1"
if command -v open &>/dev/null; then open "$filepath" 2>/dev/null || true
elif command -v xdg-open &>/dev/null; then xdg-open "$filepath" 2>/dev/null || true
elif command -v start &>/dev/null; then start "$filepath" 2>/dev/null || true
else info "Open: $filepath"
fi
}
# HTML-safe escaping via jq (no fragile sed)
html_escape() {
local text="$1"
echo "$text" | jq -Rs '.' | sed 's/^"//; s/"$//' | sed 's/\\n/\n/g; s/\\t/\t/g; s/&/\&/g; s/</\</g; s/>/\>/g'
}
# ── HARNESS: The System Prompt Injection ───────────────────────────────
build_harness() {
local task="$1"
local stage="${2:-implement}"
local harness=""
# Layer 1: NASA P10 rules (always)
harness+="RULES — You MUST follow these (NASA Power of 10):
- Functions under 60 lines. No exceptions.
- All loops have fixed upper bounds.
- No dynamic memory after init.
- Check every return value.
- Zero warnings policy — treat warnings as errors.
- No global mutable state.
- Maximum 2 levels of pointer/reference indirection.
- All code paths must be testable.
- Minimize scope of variables.
- Use assertions liberally at function boundaries.
"
# Layer 2: Context engineering (project-aware)
if [ -f "$PROJECT_DIR/CLAUDE.md" ]; then
harness+="PROJECT INSTRUCTIONS (from CLAUDE.md):
$(cat "$PROJECT_DIR/CLAUDE.md")
"
fi
# Layer 3: Stage-specific harness
case "$stage" in
analyze)
harness+="STAGE: ANALYSIS
You are the planning agent. Your job:
1. Read and understand the codebase structure
2. Identify ALL files that need to change for this task
3. Output a numbered implementation plan
4. Estimate complexity (trivial/moderate/complex) per file
5. Flag any risks or architectural concerns
6. Do NOT write code — only analyze and plan
Be thorough but concise. List exact file paths.
"
;;
implement)
harness+="STAGE: IMPLEMENTATION
You are the coding agent. Your job:
1. Follow the plan exactly
2. Write production-quality code
3. After each change, verify it compiles/parses
4. Fix any errors immediately
5. Use existing patterns from the codebase
6. Do NOT over-engineer — minimal changes only
7. Do NOT add comments unless logic is non-obvious
Surgical precision. Change only what's needed.
"
;;
test)
harness+="STAGE: TESTING
You are the test agent. Your job:
1. Run the existing test suite
2. Fix any failing tests caused by recent changes
3. Add tests for new/changed code paths
4. Ensure edge cases are covered
5. Verify no regressions
If no test framework exists, note it and move on.
"
;;
review)
harness+="STAGE: REVIEW
You are the review agent. Your job:
1. Review ALL changes shown below
2. Check for: security issues, edge cases, code quality
3. Verify NASA P10 compliance (60-line functions, bounded loops, etc.)
4. Check for OWASP Top 10 vulnerabilities
5. Flag any concerns with severity (Critical/High/Medium/Low)
6. Verify no secrets or credentials in code
Output a structured review: APPROVE, REQUEST_CHANGES, or BLOCK.
"
;;
research)
harness+="STAGE: RESEARCH
You are a research agent. Your job:
1. Thoroughly research the given topic
2. Use web search and available tools
3. Provide data-driven analysis with specific numbers
4. Cite sources where possible
5. Structure output with clear headers
6. Be thorough but concise — no filler
Deliver actionable insights, not generic advice.
"
;;
esac
harness+="
TASK: $task
"
echo "$harness"
}
# ── Budget Tracking (uses total_cost_usd from Claude CLI JSON) ────────
BUDGET_SPENT=0
track_cost() {
local result_file="$1"
local cost
cost=$(jq -r '.total_cost_usd // 0' "$result_file" 2>/dev/null || echo "0")
BUDGET_SPENT=$(echo "$BUDGET_SPENT + $cost" | bc 2>/dev/null || echo "$BUDGET_SPENT")
local remaining
remaining=$(echo "$BUDGET_MAX - $BUDGET_SPENT" | bc 2>/dev/null || echo "0")
log "Budget: ${CYAN}\$${BUDGET_SPENT}${NC} / \$${BUDGET_MAX} (remaining: \$${remaining})"
if (( $(echo "$BUDGET_SPENT >= $BUDGET_MAX" | bc -l 2>/dev/null || echo 0) )); then
err "BUDGET EXCEEDED — pipeline halted"
return 1
fi
}
# ── Build Claude CLI flags ────────────────────────────────────────────
build_claude_flags() {
local max_turns="$1"
local flags="--output-format json --max-turns $max_turns"
if [ "$AUTONOMOUS" = "true" ]; then
flags+=" --permission-mode bypassPermissions"
fi
echo "$flags"
}
# ── Stage Runner ──────────────────────────────────────────────────────
run_stage() {
local name="$1"
local task="$2"
local stage="$3"
local max_turns="${4:-10}"
local log_dir="$5"
local outfile="$log_dir/${name}.json"
echo ""
echo -e "${BOLD}━━━ Stage: ${CYAN}${name}${NC} ${BOLD}━━━${NC}"
info "Max turns: $max_turns | Budget remaining: \$$(echo "$BUDGET_MAX - $BUDGET_SPENT" | bc 2>/dev/null || echo "$BUDGET_MAX")"
local harness
harness="$(build_harness "$task" "$stage")"
local claude_flags
claude_flags="$(build_claude_flags "$max_turns")"
local start_time
start_time=$(date +%s)
# shellcheck disable=SC2086
claude -p "$harness" $claude_flags > "$outfile" 2>/dev/null || true
local end_time
end_time=$(date +%s)
local elapsed=$((end_time - start_time))
# Extract cost (Claude CLI uses total_cost_usd)
local cost_usd
cost_usd=$(jq -r '.total_cost_usd // 0' "$outfile" 2>/dev/null || echo "0")
ok "Stage ${BOLD}${name}${NC} complete (${elapsed}s, \$${cost_usd})"
track_cost "$outfile" || return 1
# Save stage metadata
jq -n \
--arg name "$name" \
--arg stage "$stage" \
--argjson elapsed "$elapsed" \
--arg cost "$cost_usd" \
--arg status "complete" \
'{name: $name, stage: $stage, elapsed_sec: $elapsed, cost_usd: ($cost|tonumber), status: $status}' \
> "$log_dir/${name}.meta.json" 2>/dev/null || true
}
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# COMMAND: init
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cmd_init() {
detect_project
banner
info "Initializing 100x pipeline in ${BOLD}$PROJECT_DIR${NC}"
# Copy CLAUDE.md if not present
if [ ! -f "$PROJECT_DIR/CLAUDE.md" ]; then
cp "$SCRIPT_DIR/CLAUDE.md" "$PROJECT_DIR/CLAUDE.md"
ok "Created CLAUDE.md with NASA P10 rules"
else
warn "CLAUDE.md already exists — skipping"
fi
# Create .100x directory
mkdir -p "$PROJECT_DIR/.100x/runs"
ok "Created .100x/ pipeline directory"
# Copy ESLint config if TypeScript/JavaScript project
if [ -f "$PROJECT_DIR/package.json" ]; then
if [ ! -f "$PROJECT_DIR/eslint.config.mjs" ]; then
cp "$SCRIPT_DIR/config/nasa-p10-eslint.config.mjs" "$PROJECT_DIR/eslint.config.mjs"
ok "Installed NASA P10 ESLint config"
else
warn "eslint.config.mjs already exists — skipping"
fi
fi
# Gitignore .100x logs
if [ -f "$PROJECT_DIR/.gitignore" ]; then
if ! grep -q "^\.100x/" "$PROJECT_DIR/.gitignore" 2>/dev/null; then
printf '\n# 100x pipeline logs\n.100x/\n' >> "$PROJECT_DIR/.gitignore"
ok "Added .100x/ to .gitignore"
fi
fi
echo ""
ok "Project initialized! Run: ${BOLD}100x run \"your task\"${NC}"
}
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# COMMAND: run — The Full 4-Stage Pipeline
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cmd_run() {
local task="${1:?Usage: 100x run 'task description'}"
check_claude
detect_project
banner
local timestamp
timestamp=$(date +%Y%m%d_%H%M%S)
local run_dir="$PROJECT_DIR/.100x/runs/$timestamp"
mkdir -p "$run_dir"
# Snapshot pre-run state for context chain
git diff HEAD --stat > "$run_dir/pre-state.txt" 2>/dev/null || true
git rev-parse HEAD > "$run_dir/pre-commit.txt" 2>/dev/null || true
info "Project: ${BOLD}$PROJECT_NAME${NC}"
info "Task: ${CYAN}$task${NC}"
info "Budget: \$$BUDGET_MAX"
info "Autonomous: $AUTONOMOUS"
info "Logs: $run_dir/"
echo ""
# Save run metadata
jq -n \
--arg task "$task" \
--arg project "$PROJECT_NAME" \
--arg dir "$PROJECT_DIR" \
--arg ts "$timestamp" \
--arg budget "$BUDGET_MAX" \
--arg auto "$AUTONOMOUS" \
'{task: $task, project: $project, project_dir: $dir, timestamp: $ts, budget_usd: ($budget|tonumber), autonomous: $auto, stages: []}' \
> "$run_dir/run.json"
local pipeline_start
pipeline_start=$(date +%s)
# ── Stage 1: Analyze ──
run_stage "01-analyze" "$task" "analyze" "$MAX_TURNS_ANALYZE" "$run_dir"
# ── Stage 2: Implement (feeds analysis result) ──
local plan
plan=$(jq -r '.result // ""' "$run_dir/01-analyze.json" 2>/dev/null || echo "")
run_stage "02-implement" "Execute this plan for: $task
ANALYSIS FROM PLANNING AGENT:
$plan" "implement" "$MAX_TURNS_IMPLEMENT" "$run_dir"
# ── Capture changes for context chain ──
local changes_diff=""
changes_diff=$(git diff HEAD 2>/dev/null || echo "No git diff available")
local changes_stat=""
changes_stat=$(git diff HEAD --stat 2>/dev/null || echo "")
# Save diff for later stages
echo "$changes_diff" > "$run_dir/changes.diff"
echo "$changes_stat" > "$run_dir/changes-stat.txt"
# ── Stage 3: Test (knows what changed) ──
run_stage "03-test" "Run all tests, fix failures, add coverage for changes made for: $task
FILES CHANGED BY IMPLEMENTATION AGENT:
$changes_stat
DIFF OF CHANGES:
$(echo "$changes_diff" | head -300)" "test" "$MAX_TURNS_TEST" "$run_dir"
# ── Stage 4: Review (knows what changed) ──
run_stage "04-review" "Review all changes made for: $task
FILES CHANGED:
$changes_stat
FULL DIFF TO REVIEW:
$(echo "$changes_diff" | head -500)" "review" "$MAX_TURNS_REVIEW" "$run_dir"
# ── Pipeline Complete ──
local pipeline_end
pipeline_end=$(date +%s)
local total_elapsed=$((pipeline_end - pipeline_start))
echo ""
echo -e "${BOLD}━━━ Pipeline Complete ━━━${NC}"
ok "Total time: ${total_elapsed}s"
ok "Total cost: \$${BUDGET_SPENT}"
ok "Logs: $run_dir/"
# Generate dashboard
generate_dashboard "$run_dir" "$task" "$total_elapsed"
ok "Dashboard: $run_dir/dashboard.html"
echo ""
info "Open dashboard: ${BOLD}open $run_dir/dashboard.html${NC}"
open_file "$run_dir/dashboard.html"
}
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# COMMAND: gate — Quality Gate Check
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cmd_gate() {
detect_project
detect_src_dir
banner
info "Running quality gates in ${BOLD}$PROJECT_DIR${NC} (src: $SRC_DIR)"
echo ""
local passed=0
local failed=0
local skipped=0
local gate_num=0
run_gate() {
local name="$1"
local cmd="$2"
gate_num=$((gate_num + 1))
echo -ne " ${DIM}[$gate_num]${NC} $name... "
# Capture exit code properly before conditional
local exit_code=0
eval "$cmd" >/dev/null 2>&1 || exit_code=$?
if [ $exit_code -eq 0 ]; then
echo -e "${GREEN}PASS${NC}"
passed=$((passed + 1))
elif [ $exit_code -eq 127 ]; then
echo -e "${YELLOW}SKIP${NC} (not installed)"
skipped=$((skipped + 1))
else
echo -e "${RED}FAIL${NC}"
failed=$((failed + 1))
fi
}
# Auto-detect project type and run appropriate gates
if [ -f "$PROJECT_DIR/package.json" ]; then
run_gate "Prettier (format)" "npx prettier --check '${SRC_DIR}/**/*.{ts,tsx,js,jsx}' 2>/dev/null"
run_gate "ESLint (lint)" "npx eslint --max-warnings 0 ${SRC_DIR}/ 2>/dev/null"
run_gate "TypeScript (types)" "npx tsc --noEmit 2>/dev/null"
run_gate "Tests" "npx vitest run 2>/dev/null || npm test 2>/dev/null"
run_gate "Semgrep (SAST)" "semgrep --config 'p/owasp-top-ten' --error ${SRC_DIR}/ 2>/dev/null"
run_gate "Gitleaks (secrets)" "gitleaks detect --source . --no-git --no-banner 2>/dev/null"
run_gate "npm audit (CVEs)" "npm audit --audit-level=high 2>/dev/null"
elif [ -f "$PROJECT_DIR/Cargo.toml" ]; then
run_gate "cargo fmt (format)" "cargo fmt -- --check 2>/dev/null"
run_gate "cargo clippy (lint)" "cargo clippy -- -D warnings 2>/dev/null"
run_gate "cargo test" "cargo test 2>/dev/null"
run_gate "cargo audit (CVEs)" "cargo audit 2>/dev/null"
run_gate "Gitleaks (secrets)" "gitleaks detect --source . --no-git --no-banner 2>/dev/null"
elif [ -f "$PROJECT_DIR/go.mod" ]; then
run_gate "gofmt (format)" "test -z \"\$(gofmt -l .)\" 2>/dev/null"
run_gate "go vet (lint)" "go vet ./... 2>/dev/null"
run_gate "go test" "go test ./... 2>/dev/null"
run_gate "govulncheck (CVEs)" "govulncheck ./... 2>/dev/null"
run_gate "Gitleaks (secrets)" "gitleaks detect --source . --no-git --no-banner 2>/dev/null"
elif [ -f "$PROJECT_DIR/pyproject.toml" ] || [ -f "$PROJECT_DIR/setup.py" ]; then
run_gate "ruff (lint)" "ruff check . 2>/dev/null"
run_gate "mypy (types)" "mypy . 2>/dev/null"
run_gate "pytest" "pytest 2>/dev/null || python3 -m pytest 2>/dev/null"
run_gate "Semgrep (SAST)" "semgrep --config 'p/owasp-top-ten' --error . 2>/dev/null"
run_gate "Gitleaks (secrets)" "gitleaks detect --source . --no-git --no-banner 2>/dev/null"
else
run_gate "Gitleaks (secrets)" "gitleaks detect --source . --no-git --no-banner 2>/dev/null"
warn "Unknown project type — only ran secret detection"
fi
echo ""
if [ $failed -eq 0 ]; then
ok "ALL GATES PASSED (${passed} pass, ${skipped} skip)"
else
err "${failed} GATE(S) FAILED (${passed} pass, ${skipped} skip)"
exit 1
fi
}
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# COMMAND: parallel — Multi-Agent Parallel Execution (with worktrees)
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cmd_parallel() {
if [ $# -eq 0 ]; then
err "Usage: 100x parallel 'task1' 'task2' 'task3'"
exit 1
fi
check_claude
detect_project
banner
# Verify we're in a git repo (required for worktrees)
if ! git rev-parse --show-toplevel &>/dev/null; then
err "Not a git repository. Parallel mode requires git for worktree isolation."
exit 1
fi
local timestamp
timestamp=$(date +%Y%m%d_%H%M%S)
local run_dir="$PROJECT_DIR/.100x/runs/parallel-$timestamp"
local worktree_base="$PROJECT_DIR/.100x/worktrees"
mkdir -p "$run_dir" "$worktree_base"
info "Launching ${BOLD}$#${NC} parallel agents with worktree isolation"
info "Budget per agent: \$$PARALLEL_BUDGET"
info "Max turns: $PARALLEL_MAX_TURNS"
echo ""
local pids=()
local tasks=("$@")
local claude_flags
claude_flags="$(build_claude_flags "$PARALLEL_MAX_TURNS")"
for i in "${!tasks[@]}"; do
local agent_id=$((i + 1))
local branch="100x-agent-${agent_id}-${timestamp}"
local worktree="$worktree_base/agent-${agent_id}"
# Clean stale worktree
git worktree remove "$worktree" --force 2>/dev/null || true
# Create isolated worktree
git worktree add "$worktree" -b "$branch" HEAD 2>/dev/null
(
cd "$worktree"
local harness
harness="$(build_harness "${tasks[$i]}" "implement")"
info "Agent $agent_id: ${tasks[$i]:0:60}..."
# shellcheck disable=SC2086
claude -p "$harness" $claude_flags \
> "$run_dir/agent-$agent_id.json" 2>/dev/null || true
# Auto-commit if there are changes
if ! git diff --quiet HEAD 2>/dev/null; then
git add -A 2>/dev/null || true
git commit -m "100x agent $agent_id: ${tasks[$i]:0:50}..." 2>/dev/null || true
fi
ok "Agent $agent_id complete"
) &
pids+=($!)
echo -e " Agent $agent_id launched on branch ${CYAN}$branch${NC}"
done
echo ""
info "Waiting for ${#pids[@]} agents..."
local agent_failed=0
for i in "${!pids[@]}"; do
if ! wait "${pids[$i]}"; then
err "Agent $((i + 1)) failed"
agent_failed=$((agent_failed + 1))
else
ok "Agent $((i + 1)) done"
fi
done
echo ""
echo -e "${BOLD}━━━ Parallel Execution Complete ━━━${NC}"
# Summary
local total_cost=0
for i in "${!tasks[@]}"; do
local agent_id=$((i + 1))
local cost
cost=$(jq -r '.total_cost_usd // 0' "$run_dir/agent-$agent_id.json" 2>/dev/null || echo "0")
total_cost=$(echo "$total_cost + $cost" | bc 2>/dev/null || echo "$total_cost")
echo -e " Agent $agent_id: \$$cost — ${tasks[$i]:0:50}"
done
echo ""
ok "Total cost: \$$total_cost"
# Cleanup worktrees
for i in "${!tasks[@]}"; do
local agent_id=$((i + 1))
git worktree remove "$worktree_base/agent-$agent_id" --force 2>/dev/null || true
done
ok "Worktrees cleaned up"
info "Review agent branches: ${BOLD}git log --all --oneline --graph${NC}"
BUDGET_SPENT="$total_cost"
generate_dashboard "$run_dir" "Parallel: ${#tasks[@]} agents" "0"
open_file "$run_dir/dashboard.html"
}
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# COMMAND: research — Deep Research (no double-harness)
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cmd_research() {
local topic="${1:?Usage: 100x research 'topic'}"
check_claude
detect_project
banner
local timestamp
timestamp=$(date +%Y%m%d_%H%M%S)
local run_dir="$PROJECT_DIR/.100x/runs/research-$timestamp"
mkdir -p "$run_dir"
info "Research topic: ${CYAN}$topic${NC}"
info "Budget: \$$BUDGET_MAX"
echo ""
# FIX: Pass raw topic to run_stage, let run_stage call build_harness once
run_stage "research" "Deep research: $topic. Search the web extensively. Cover multiple angles: technical, market, competitive, risks, opportunities. Provide data-driven analysis with specific numbers and sources. Structure with clear headers. Be thorough." "research" "$MAX_TURNS_RESEARCH" "$run_dir"
echo ""
ok "Research complete"
ok "Results: $run_dir/"
# Extract and display result
local result
result=$(jq -r '.result // "See log file"' "$run_dir/research.json" 2>/dev/null || echo "See log file")
echo ""
echo -e "${BOLD}━━━ Research Results ━━━${NC}"
echo "$result" | head -100
generate_dashboard "$run_dir" "Research: $topic" "0"
}
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# COMMAND: deepseek — Run DeepSeek Multi-Agent Pipeline
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cmd_deepseek() {
info "Running DeepSeek multi-agent pipeline"
cd "$SCRIPT_DIR/pipeline"
python3 runner.py "$@"
}
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# COMMAND: history — Show Past Pipeline Runs
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cmd_history() {
detect_project
local runs_dir="$PROJECT_DIR/.100x/runs"
if [ ! -d "$runs_dir" ] || [ -z "$(ls -A "$runs_dir" 2>/dev/null)" ]; then
err "No pipeline runs found. Run: 100x run 'your task'"
exit 1
fi
banner
echo -e "${BOLD}Pipeline History${NC} — $PROJECT_NAME"
echo ""
printf " ${DIM}%-18s %-10s %-8s %s${NC}\n" "TIMESTAMP" "COST" "TIME" "TASK"
printf " ${DIM}%-18s %-10s %-8s %s${NC}\n" "──────────────────" "──────────" "────────" "────────────────────────────────"
local total_cost=0
local total_runs=0
# shellcheck disable=SC2012,SC2045
for run_dir in $(ls -td "$runs_dir"/*/); do
[ -d "$run_dir" ] || continue
local ts
ts=$(basename "$run_dir")
local task="unknown"
local cost="0"
local elapsed="?"
if [ -f "$run_dir/run.json" ]; then
task=$(jq -r '.task // "unknown"' "$run_dir/run.json" 2>/dev/null || echo "unknown")
fi
# Sum costs from all stage JSON files
local run_cost=0
for stage_json in "$run_dir"/*.json; do
[ -f "$stage_json" ] || continue
local stage_cost
stage_cost=$(jq -r '.total_cost_usd // 0' "$stage_json" 2>/dev/null || echo "0")
run_cost=$(echo "$run_cost + $stage_cost" | bc 2>/dev/null || echo "$run_cost")
done
total_cost=$(echo "$total_cost + $run_cost" | bc 2>/dev/null || echo "$total_cost")
total_runs=$((total_runs + 1))
# Format timestamp
local display_ts
display_ts=$(echo "$ts" | sed 's/_/ /; s/\([0-9]\{4\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1-\2-\3/')
printf " %-18s ${GREEN}\$%-9s${NC} %-8s %s\n" "$display_ts" "$run_cost" "${elapsed}s" "${task:0:40}"
done
echo ""
echo -e " ${BOLD}Total: $total_runs runs, \$${total_cost}${NC}"
}
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# COMMAND: doctor — Check Prerequisites
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cmd_doctor() {
banner
echo -e "${BOLD}Prerequisite Check${NC}"
echo ""
local ok_count=0
local warn_count=0
local fail_count=0
check_tool() {
local name="$1"
local cmd="$2"
local required="$3"
local install_hint="$4"
echo -ne " $name... "
if command -v "$cmd" &>/dev/null; then
local ver
ver=$($cmd --version 2>&1 | head -1 | grep -oE '[0-9]+\.[0-9]+[.0-9]*' | head -1 || echo "?")
echo -e "${GREEN}OK${NC} (v$ver)"
ok_count=$((ok_count + 1))
elif [ "$required" = "required" ]; then
echo -e "${RED}MISSING${NC} — $install_hint"
fail_count=$((fail_count + 1))
else
echo -e "${YELLOW}OPTIONAL${NC} — $install_hint"
warn_count=$((warn_count + 1))
fi
}
echo -e " ${DIM}Required:${NC}"
check_tool "Claude CLI" "claude" "required" "npm install -g @anthropic-ai/claude-code"
check_tool "git" "git" "required" "brew install git"
check_tool "jq" "jq" "required" "brew install jq"
check_tool "bc" "bc" "required" "brew install bc"
echo ""
echo -e " ${DIM}Quality gates (JS/TS):${NC}"
check_tool "Node.js" "node" "optional" "brew install node"
check_tool "npx" "npx" "optional" "comes with Node.js"
echo ""
echo -e " ${DIM}Quality gates (Python):${NC}"
check_tool "Python 3" "python3" "optional" "brew install python3"
check_tool "ruff" "ruff" "optional" "pip install ruff"
echo ""
echo -e " ${DIM}Security tools:${NC}"
check_tool "Semgrep" "semgrep" "optional" "pip install semgrep"
check_tool "Gitleaks" "gitleaks" "optional" "brew install gitleaks"
echo ""
echo -e " ${DIM}DeepSeek pipeline:${NC}"
check_tool "httpx (Python)" "python3" "optional" "pip install httpx"
if [ -n "${DEEPSEEK_API_KEY:-}" ]; then
echo -e " DEEPSEEK_API_KEY... ${GREEN}SET${NC}"
ok_count=$((ok_count + 1))
else
echo -e " DEEPSEEK_API_KEY... ${YELLOW}NOT SET${NC} (needed for 100x deepseek)"
warn_count=$((warn_count + 1))
fi
echo ""
if [ $fail_count -eq 0 ]; then
ok "All required tools present (${ok_count} ok, ${warn_count} optional missing)"
else
err "${fail_count} required tool(s) missing. Install them and re-run."
exit 1
fi
}
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# COMMAND: config — Persistent Settings
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cmd_config() {
if [ $# -eq 0 ]; then
# Show current config
banner
echo -e "${BOLD}Configuration${NC} ($CONFIG_FILE)"
echo ""
if [ -f "$CONFIG_FILE" ]; then
jq '.' "$CONFIG_FILE"
else
echo " No config file. Using defaults."
fi
echo ""
echo -e " ${DIM}Usage:${NC}"
echo " 100x config set budget_max 25"
echo " 100x config set autonomous true"
echo " 100x config set src_dir lib"
return
fi
local action="${1:-}"
shift || true
case "$action" in
set)
local key="${1:?Usage: 100x config set <key> <value>}"
local value="${2:?Usage: 100x config set <key> <value>}"
# Create config if missing
if [ ! -f "$CONFIG_FILE" ]; then
echo '{}' > "$CONFIG_FILE"
fi
# Update key
local tmp
tmp=$(mktemp)
jq --arg k "$key" --arg v "$value" '.[$k] = $v' "$CONFIG_FILE" > "$tmp"
mv "$tmp" "$CONFIG_FILE"
ok "Set $key = $value"
;;
get)
local key="${1:?Usage: 100x config get <key>}"
if [ -f "$CONFIG_FILE" ]; then
jq -r --arg k "$key" '.[$k] // "not set"' "$CONFIG_FILE"
else
echo "not set"
fi
;;
*)
err "Unknown config action: $action (use set/get)"
exit 1
;;
esac
}
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# COMMAND: dashboard — Open Latest Dashboard
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cmd_dashboard() {
detect_project
local latest
# shellcheck disable=SC2012
latest=$(ls -td "$PROJECT_DIR/.100x/runs/"*/ 2>/dev/null | head -1)
if [ -z "$latest" ]; then
err "No pipeline runs found. Run: 100x run 'your task'"
exit 1
fi
if [ -f "${latest}dashboard.html" ]; then
info "Opening: ${latest}dashboard.html"
open_file "${latest}dashboard.html"
else
warn "No dashboard in latest run. Generating..."
BUDGET_SPENT="0"
generate_dashboard "$latest" "Unknown" "0"
open_file "${latest}dashboard.html"
fi
}
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# Dashboard HTML Generator (uses jq for safe escaping)
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
generate_dashboard() {
local run_dir="$1"
local task="$2"
local total_elapsed="${3:-0}"
local output="$run_dir/dashboard.html"
# Collect stage results safely via jq
local results_html=""
for stage_file in "$run_dir"/0*.json "$run_dir"/research.json; do
[ -f "$stage_file" ] || continue
local stage_name
stage_name=$(basename "$stage_file" .json)
local stage_result
stage_result=$(jq -r '.result // "No output"' "$stage_file" 2>/dev/null | head -200 || echo "Error reading")
# Escape HTML via jq
local escaped_result
escaped_result=$(printf '%s' "$stage_result" | jq -Rs '.' | sed 's/^"//;s/"$//' | sed 's/\\n/<br>/g; s/\\t/\ \ \ \ /g; s/</\</g; s/>/\>/g; s/<br>/<br>/g')
results_html+="<div class=\"stage-result\"><h3>$stage_name</h3><pre>$escaped_result</pre></div>"
done
# Calculate budget bar width dynamically
local budget_pct=0
if [ "$(echo "$BUDGET_MAX > 0" | bc -l 2>/dev/null || echo 0)" = "1" ]; then
budget_pct=$(echo "scale=0; $BUDGET_SPENT * 100 / $BUDGET_MAX" | bc 2>/dev/null || echo "0")
fi
local budget_class="low"
if [ "$budget_pct" -gt 80 ] 2>/dev/null; then budget_class="high"
elif [ "$budget_pct" -gt 50 ] 2>/dev/null; then budget_class="mid"
fi
# Escape task for HTML
local safe_task
safe_task=$(printf '%s' "$task" | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g')
# Write dashboard (static CSS block, then dynamic content)
cat > "$output" << 'CSSEOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>100x Pipeline Dashboard</title>
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:-apple-system,BlinkMacSystemFont,'SF Pro',system-ui,sans-serif;background:#0a0a0f;color:#e0e0e0;min-height:100vh}
.container{max-width:1400px;margin:0 auto;padding:24px}
.header{display:flex;align-items:center;gap:16px;margin-bottom:24px}
.header h1{font-size:24px;color:#fff}
.badge{background:#1a1a3a;color:#8b8bff;padding:4px 12px;border-radius:12px;font-size:12px;font-weight:600}
.subtitle{color:#666;font-size:13px;margin-bottom:8px}
.task-desc{color:#aaa;font-size:14px;background:#151520;padding:12px 16px;border-radius:8px;border-left:3px solid #8b8bff;margin-bottom:24px}
.kpi-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:12px;margin-bottom:24px}
.kpi{background:#151520;border:1px solid #252535;border-radius:10px;padding:16px;position:relative;overflow:hidden}
.kpi::before{content:'';position:absolute;top:0;left:0;right:0;height:2px}
.kpi.green::before{background:linear-gradient(90deg,#4ade80,#22c55e)}
.kpi.blue::before{background:linear-gradient(90deg,#60a5fa,#3b82f6)}
.kpi.yellow::before{background:linear-gradient(90deg,#facc15,#eab308)}
.kpi.purple::before{background:linear-gradient(90deg,#a78bfa,#8b5cf6)}
.kpi-label{font-size:11px;color:#666;text-transform:uppercase;letter-spacing:1.5px;font-weight:600}
.kpi-value{font-size:32px;font-weight:700;color:#fff;margin-top:4px;font-variant-numeric:tabular-nums}
.kpi-sub{font-size:11px;color:#555;margin-top:4px}
.pipeline-flow{display:flex;align-items:center;gap:8px;margin-bottom:24px;overflow-x:auto;padding:8px 0}
.pipeline-stage{background:#151520;border:1px solid #252535;border-radius:10px;padding:14px 20px;min-width:160px;text-align:center;position:relative}
.pipeline-stage.complete{border-color:#22c55e40}
.pipeline-stage.complete::after{content:'✓';position:absolute;top:8px;right:10px;color:#4ade80;font-size:14px;font-weight:bold}
.pipeline-stage .name{font-size:13px;font-weight:600;color:#ddd}
.pipeline-stage .meta{font-size:11px;color:#666;margin-top:4px}
.pipeline-arrow{color:#333;font-size:20px;flex-shrink:0}
.budget-container{margin-bottom:24px}
.budget-bar-outer{width:100%;height:6px;background:#252535;border-radius:3px;overflow:hidden}
.budget-bar-inner{height:100%;border-radius:3px;transition:width .5s ease}
.budget-bar-inner.low{background:linear-gradient(90deg,#4ade80,#22c55e)}
.budget-bar-inner.mid{background:linear-gradient(90deg,#facc15,#eab308)}
.budget-bar-inner.high{background:linear-gradient(90deg,#f87171,#ef4444)}
.tabs{display:flex;gap:2px;margin-bottom:0;background:#0d0d14;border-radius:8px 8px 0 0;padding:4px 4px 0}
.tab{padding:10px 20px;background:0 0;border:none;color:#666;font-size:13px;font-weight:500;cursor:pointer;border-radius:6px 6px 0 0;transition:all .2s}
.tab:hover{color:#aaa;background:#151520}
.tab.active{color:#8b8bff;background:#151520}
.tab-body{background:#151520;border:1px solid #252535;border-top:none;border-radius:0 0 8px 8px;padding:16px;min-height:300px}
.tab-content{display:none}
.tab-content.active{display:block}
.stage-result{margin-bottom:16px}
.stage-result h3{font-size:14px;color:#8b8bff;margin-bottom:8px;text-transform:uppercase;letter-spacing:1px}
.stage-result pre{background:#0d0d14;padding:16px;border-radius:8px;font-family:'SF Mono','Fira Code',monospace;font-size:12px;line-height:1.6;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word;max-height:500px;overflow-y:auto;color:#ccc}
.multipliers{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:12px}
.multiplier{background:#0d0d14;border:1px solid #252535;border-radius:8px;padding:16px}
.multiplier h4{color:#8b8bff;font-size:13px;margin-bottom:4px}
.multiplier .impact{font-size:20px;font-weight:700;color:#4ade80}
.multiplier .evidence{font-size:11px;color:#666;margin-top:4px}
.footer{text-align:center;margin-top:40px;padding:16px;color:#333;font-size:11px}
.footer a{color:#555;text-decoration:none}
.footer a:hover{color:#8b8bff}
@media(max-width:768px){.kpi-grid{grid-template-columns:repeat(2,1fr)}.pipeline-flow{flex-wrap:wrap}.kpi-value{font-size:24px}}
</style>
</head>
<body>
<div class="container">
<div class="header"><h1>100x Pipeline</h1><span class="badge">v1.1.0</span></div>
CSSEOF
# Inject dynamic content — using printf to avoid heredoc escaping issues
{
printf '<div class="subtitle">%s | Project: %s</div>\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$PROJECT_NAME"
printf '<div class="task-desc">%s</div>\n' "$safe_task"
cat << KPIEOF
<div class="kpi-grid">
<div class="kpi green"><div class="kpi-label">Total Cost</div><div class="kpi-value">\$${BUDGET_SPENT}</div><div class="kpi-sub">of \$${BUDGET_MAX} budget</div></div>
<div class="kpi blue"><div class="kpi-label">Duration</div><div class="kpi-value">${total_elapsed}s</div><div class="kpi-sub">wall clock</div></div>
<div class="kpi purple"><div class="kpi-label">Stages</div><div class="kpi-value">4</div><div class="kpi-sub">analyze → implement → test → review</div></div>
<div class="kpi yellow"><div class="kpi-label">Harness</div><div class="kpi-value">6-10x</div><div class="kpi-sub">multiplier active</div></div>
</div>
<div class="pipeline-flow">
<div class="pipeline-stage complete"><div class="name">Analyze</div><div class="meta">Plan & scope</div></div>
<div class="pipeline-arrow">→</div>