forge-workflow 0.0.4 → 0.0.5

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 (209) hide show
  1. package/.claude/commands/dev.md +340 -340
  2. package/.claude/commands/plan.md +521 -521
  3. package/.claude/commands/premerge.md +176 -176
  4. package/.claude/commands/research.md +42 -42
  5. package/.claude/commands/review.md +442 -442
  6. package/.claude/commands/rollback.md +721 -721
  7. package/.claude/commands/ship.md +164 -164
  8. package/.claude/commands/sonarcloud.md +152 -152
  9. package/.claude/commands/status.md +48 -48
  10. package/.claude/commands/validate.md +282 -282
  11. package/.claude/commands/verify.md +221 -221
  12. package/.claude/rules/greptile-review-process.md +285 -285
  13. package/.claude/rules/workflow.md +105 -105
  14. package/.claude/scripts/greptile-resolve.sh +526 -526
  15. package/.claude/scripts/load-env.sh +32 -32
  16. package/.cline/workflows/dev.md +337 -337
  17. package/.cline/workflows/plan.md +518 -518
  18. package/.cline/workflows/premerge.md +173 -173
  19. package/.cline/workflows/research.md +39 -39
  20. package/.cline/workflows/review.md +439 -439
  21. package/.cline/workflows/rollback.md +718 -718
  22. package/.cline/workflows/ship.md +161 -161
  23. package/.cline/workflows/sonarcloud.md +146 -146
  24. package/.cline/workflows/status.md +45 -45
  25. package/.cline/workflows/validate.md +279 -279
  26. package/.cline/workflows/verify.md +218 -218
  27. package/.codex/config.toml +11 -11
  28. package/.codex/skills/dev/SKILL.md +340 -340
  29. package/.codex/skills/plan/SKILL.md +521 -521
  30. package/.codex/skills/premerge/SKILL.md +176 -176
  31. package/.codex/skills/research/SKILL.md +42 -42
  32. package/.codex/skills/review/SKILL.md +442 -442
  33. package/.codex/skills/rollback/SKILL.md +721 -721
  34. package/.codex/skills/ship/SKILL.md +164 -164
  35. package/.codex/skills/sonarcloud/SKILL.md +149 -149
  36. package/.codex/skills/status/SKILL.md +48 -48
  37. package/.codex/skills/validate/SKILL.md +282 -282
  38. package/.codex/skills/verify/SKILL.md +221 -221
  39. package/.cursor/commands/dev.md +337 -337
  40. package/.cursor/commands/plan.md +518 -518
  41. package/.cursor/commands/premerge.md +173 -173
  42. package/.cursor/commands/research.md +39 -39
  43. package/.cursor/commands/review.md +439 -439
  44. package/.cursor/commands/rollback.md +718 -718
  45. package/.cursor/commands/ship.md +161 -161
  46. package/.cursor/commands/sonarcloud.md +146 -146
  47. package/.cursor/commands/status.md +45 -45
  48. package/.cursor/commands/validate.md +279 -279
  49. package/.cursor/commands/verify.md +218 -218
  50. package/.cursor/rules/permissions-guidance.mdc +37 -37
  51. package/.forge/hooks/check-tdd.js +240 -240
  52. package/.github/PLUGIN_TEMPLATE.json +32 -32
  53. package/.github/prompts/dev.prompt.md +342 -342
  54. package/.github/prompts/plan.prompt.md +523 -523
  55. package/.github/prompts/premerge.prompt.md +178 -178
  56. package/.github/prompts/research.prompt.md +44 -44
  57. package/.github/prompts/review.prompt.md +444 -444
  58. package/.github/prompts/rollback.prompt.md +723 -723
  59. package/.github/prompts/ship.prompt.md +166 -166
  60. package/.github/prompts/sonarcloud.prompt.md +151 -151
  61. package/.github/prompts/status.prompt.md +50 -50
  62. package/.github/prompts/validate.prompt.md +284 -284
  63. package/.github/prompts/verify.prompt.md +223 -223
  64. package/.github/workflows/beads-to-github.yml +56 -0
  65. package/.github/workflows/github-to-beads.yml +97 -0
  66. package/.kilocode/workflows/dev.md +341 -341
  67. package/.kilocode/workflows/plan.md +522 -522
  68. package/.kilocode/workflows/premerge.md +177 -177
  69. package/.kilocode/workflows/research.md +43 -43
  70. package/.kilocode/workflows/review.md +443 -443
  71. package/.kilocode/workflows/rollback.md +722 -722
  72. package/.kilocode/workflows/ship.md +165 -165
  73. package/.kilocode/workflows/sonarcloud.md +150 -150
  74. package/.kilocode/workflows/status.md +49 -49
  75. package/.kilocode/workflows/validate.md +283 -283
  76. package/.kilocode/workflows/verify.md +222 -222
  77. package/.mcp.json.example +12 -12
  78. package/.opencode/commands/dev.md +340 -340
  79. package/.opencode/commands/plan.md +521 -521
  80. package/.opencode/commands/premerge.md +176 -176
  81. package/.opencode/commands/research.md +42 -42
  82. package/.opencode/commands/review.md +442 -442
  83. package/.opencode/commands/rollback.md +721 -721
  84. package/.opencode/commands/ship.md +164 -164
  85. package/.opencode/commands/sonarcloud.md +149 -149
  86. package/.opencode/commands/status.md +48 -48
  87. package/.opencode/commands/validate.md +282 -282
  88. package/.opencode/commands/verify.md +221 -221
  89. package/.roo/commands/dev.md +341 -341
  90. package/.roo/commands/plan.md +522 -522
  91. package/.roo/commands/premerge.md +177 -177
  92. package/.roo/commands/research.md +43 -43
  93. package/.roo/commands/review.md +443 -443
  94. package/.roo/commands/rollback.md +722 -722
  95. package/.roo/commands/ship.md +165 -165
  96. package/.roo/commands/sonarcloud.md +150 -150
  97. package/.roo/commands/status.md +49 -49
  98. package/.roo/commands/validate.md +283 -283
  99. package/.roo/commands/verify.md +222 -222
  100. package/AGENTS.md +175 -175
  101. package/CLAUDE.md +100 -100
  102. package/README.md +429 -416
  103. package/bin/forge-cmd.js +313 -313
  104. package/bin/forge-preflight.js +309 -309
  105. package/bin/forge.js +4596 -4303
  106. package/docs/AGENT_INSTALL_PROMPT.md +342 -342
  107. package/docs/BEADS_GITHUB_SYNC.md +251 -251
  108. package/docs/ENHANCED_ONBOARDING.md +602 -602
  109. package/docs/EXAMPLES.md +482 -482
  110. package/docs/GREPTILE_SETUP.md +400 -400
  111. package/docs/MANUAL_REVIEW_GUIDE.md +106 -106
  112. package/docs/ROADMAP.md +359 -359
  113. package/docs/SETUP.md +663 -631
  114. package/docs/TOOLCHAIN.md +630 -630
  115. package/docs/VALIDATION.md +363 -363
  116. package/install.sh +40 -1056
  117. package/lefthook.yml +39 -39
  118. package/lib/agents/README.md +198 -198
  119. package/lib/agents/claude.plugin.json +28 -28
  120. package/lib/agents/cline.plugin.json +22 -22
  121. package/lib/agents/codex.plugin.json +19 -19
  122. package/lib/agents/copilot.plugin.json +24 -24
  123. package/lib/agents/cursor.plugin.json +25 -25
  124. package/lib/agents/kilocode.plugin.json +22 -22
  125. package/lib/agents/opencode.plugin.json +20 -20
  126. package/lib/agents/roo.plugin.json +23 -23
  127. package/lib/agents-config.js +2112 -2112
  128. package/lib/beads-health-check.js +143 -0
  129. package/lib/beads-setup.js +341 -0
  130. package/lib/beads-sync-scaffold.js +260 -0
  131. package/lib/commands/dev.js +513 -513
  132. package/lib/commands/plan.js +692 -692
  133. package/lib/commands/recommend.js +119 -119
  134. package/lib/commands/ship.js +377 -377
  135. package/lib/commands/status.js +378 -378
  136. package/lib/commands/validate.js +602 -602
  137. package/lib/context-merge.js +359 -359
  138. package/lib/dep-guard/analyzer.js +294 -294
  139. package/lib/dep-guard/behavior-detector.js +98 -98
  140. package/lib/dep-guard/contract-detector.js +162 -162
  141. package/lib/dep-guard/import-detector.js +498 -498
  142. package/lib/dep-guard/path-utils.js +13 -13
  143. package/lib/dep-guard/rubric.js +120 -120
  144. package/lib/dep-guard/task-parser.js +318 -318
  145. package/lib/detect-agent.js +191 -191
  146. package/lib/detect-worktree.js +47 -47
  147. package/lib/file-hash.js +26 -26
  148. package/lib/husky-migration.js +450 -0
  149. package/lib/lefthook-check.js +65 -0
  150. package/lib/pat-setup.js +207 -0
  151. package/lib/plugin-catalog.js +350 -350
  152. package/lib/plugin-manager.js +166 -166
  153. package/lib/plugin-recommender.js +141 -141
  154. package/lib/project-discovery.js +491 -491
  155. package/lib/setup-action-log.js +139 -139
  156. package/lib/setup-summary-renderer.js +106 -106
  157. package/lib/setup-utils.js +96 -0
  158. package/lib/setup.js +192 -192
  159. package/lib/smart-merge.js +64 -0
  160. package/lib/symlink-utils.js +81 -0
  161. package/lib/workflow-profiles.js +197 -197
  162. package/package.json +131 -128
  163. package/scripts/beads-context.sh +291 -0
  164. package/scripts/beads-context.test.js +563 -0
  165. package/scripts/behavioral-judge.sh +378 -0
  166. package/scripts/benchmark.js +85 -0
  167. package/scripts/branch-protection.js +183 -0
  168. package/scripts/check-agents.js +172 -0
  169. package/scripts/commitlint.js +42 -0
  170. package/scripts/conflict-detect.sh +323 -0
  171. package/scripts/dep-guard-analyze.js +71 -0
  172. package/scripts/dep-guard.sh +811 -0
  173. package/scripts/eval_win.py +249 -0
  174. package/scripts/file-index.sh +399 -0
  175. package/scripts/github-beads-sync/comment.mjs +64 -0
  176. package/scripts/github-beads-sync/config.mjs +148 -0
  177. package/scripts/github-beads-sync/github-api.mjs +131 -0
  178. package/scripts/github-beads-sync/index.mjs +332 -0
  179. package/scripts/github-beads-sync/label-mapper.mjs +54 -0
  180. package/scripts/github-beads-sync/mapping.mjs +78 -0
  181. package/scripts/github-beads-sync/reverse-sync-cli.mjs +31 -0
  182. package/scripts/github-beads-sync/reverse-sync.mjs +138 -0
  183. package/scripts/github-beads-sync/run-bd.mjs +159 -0
  184. package/scripts/github-beads-sync/sanitize.mjs +121 -0
  185. package/scripts/github-beads-sync.config.json +26 -0
  186. package/scripts/improve-command.js +375 -0
  187. package/scripts/lib/eval-runner.js +229 -0
  188. package/scripts/lib/eval-schema.js +135 -0
  189. package/scripts/lib/eval-storage.js +78 -0
  190. package/scripts/lib/grading.js +203 -0
  191. package/scripts/lib/transcript-parser.js +63 -0
  192. package/scripts/lint.js +47 -0
  193. package/scripts/migrate-to-bun-test.js +412 -0
  194. package/scripts/run-command-eval.js +236 -0
  195. package/scripts/smart-status.sh +782 -0
  196. package/scripts/sync-commands.js +571 -0
  197. package/scripts/sync-utils.sh +460 -0
  198. package/scripts/test-dashboard.js +123 -0
  199. package/scripts/test.js +44 -0
  200. package/scripts/validate.sh +94 -0
  201. package/skills/parallel-deep-research/SKILL.md +108 -108
  202. package/skills/parallel-deep-research/evals/README.md +27 -27
  203. package/skills/parallel-deep-research/evals/evals.json +62 -62
  204. package/skills/sonarcloud-analysis/SKILL.md +171 -171
  205. package/skills/sonarcloud-analysis/evals/README.md +27 -27
  206. package/skills/sonarcloud-analysis/evals/evals.json +50 -50
  207. package/skills/sonarcloud-analysis/references/api-reference.md +466 -466
  208. package/.cursor/hooks/state/continual-learning-index.json +0 -19
  209. package/.cursor/hooks/state/continual-learning.json +0 -8
@@ -0,0 +1,378 @@
1
+ #!/usr/bin/env bash
2
+ # behavioral-judge.sh — Score /plan output using OpenRouter LLM judges
3
+ #
4
+ # Usage:
5
+ # echo '{"plan_output": "..."}' | bash scripts/behavioral-judge.sh
6
+ # bash scripts/behavioral-judge.sh '{"plan_output": "..."}'
7
+ #
8
+ # Environment:
9
+ # OPENROUTER_API_KEY — Required (unless test mode)
10
+ # BEHAVIORAL_JUDGE_TEST_MODE — Set to 1 to skip real HTTP calls
11
+ # BEHAVIORAL_JUDGE_MOCK_SCORES — JSON scores for test mode, e.g. '{"security":4,"tdd":5,"design":4,"structural":3}'
12
+ # BEHAVIORAL_JUDGE_MOCK_PRIMARY_FAIL — Set to 1 to simulate GLM-5 failure
13
+ # BEHAVIORAL_JUDGE_MOCK_SECONDARY_FAIL — Set to 1 to simulate MiniMax failure
14
+ # BEHAVIORAL_JUDGE_MOCK_TERTIARY_FAIL — Set to 1 to simulate Kimi failure
15
+ #
16
+ # Output (stdout): JSON scoring result
17
+ # Scores are NOT written to stderr — only diagnostic messages go there
18
+
19
+ set -e
20
+
21
+ # ─── Subcommand: check-lock-sync ─────────────────────────────────────────────
22
+ # Usage: bash behavioral-judge.sh check-lock-sync <workflow.md>
23
+ # Compares engine.model in .md frontmatter against the compiled .lock.yml.
24
+ # Outputs: LOCK_IN_SYNC or LOCK_OUT_OF_SYNC (exit 0 in both cases)
25
+ if [ "$1" = "check-lock-sync" ]; then
26
+ MD_FILE="${2:-}"
27
+ if [ -z "$MD_FILE" ] || [ ! -f "$MD_FILE" ]; then
28
+ echo "LOCK_OUT_OF_SYNC"
29
+ >&2 echo '{"result":"LOCK_OUT_OF_SYNC","reason":"md_file_not_found"}'
30
+ exit 0
31
+ fi
32
+ LOCK_FILE="${MD_FILE%.md}.lock.yml"
33
+ if [ ! -f "$LOCK_FILE" ]; then
34
+ echo "LOCK_OUT_OF_SYNC"
35
+ exit 0
36
+ fi
37
+ MD_MODEL=$(grep -A2 'engine:' "$MD_FILE" | grep 'model:' | awk '{print $2}' | tr -d '"' | head -1)
38
+ LOCK_MODEL=$(grep -A2 'engine:' "$LOCK_FILE" | grep 'model:' | awk '{print $2}' | tr -d '"' | head -1)
39
+ if [ "$MD_MODEL" = "$LOCK_MODEL" ]; then
40
+ echo "LOCK_IN_SYNC"
41
+ else
42
+ echo "LOCK_OUT_OF_SYNC"
43
+ fi
44
+ exit 0
45
+ fi
46
+
47
+ OPENROUTER_BASE_URL="https://openrouter.ai/api/v1/chat/completions"
48
+ MODEL_PRIMARY="z-ai/glm-5"
49
+ MODEL_SECONDARY="minimax/minimax-m2.5"
50
+ MODEL_TERTIARY="moonshotai/kimi-k2.5"
51
+
52
+ # Weighted scoring: security×3, tdd×3, design×2, structural×1 — max 45
53
+ WEIGHT_SECURITY=3
54
+ WEIGHT_TDD=3
55
+ WEIGHT_DESIGN=2
56
+ WEIGHT_STRUCTURAL=1
57
+
58
+ # Classification thresholds
59
+ THRESHOLD_PASS=36
60
+ THRESHOLD_WEAK=27
61
+
62
+ # Read input from stdin or $1
63
+ if [ -n "$1" ]; then
64
+ INPUT="$1"
65
+ else
66
+ INPUT="$(cat)"
67
+ fi
68
+
69
+ # Extract plan_output text if input is JSON, otherwise use raw input
70
+ PLAN_TEXT="$INPUT"
71
+ if command -v python3 >/dev/null 2>&1; then
72
+ EXTRACTED=$(echo "$INPUT" | python3 -c "
73
+ import sys, json
74
+ try:
75
+ d = json.load(sys.stdin)
76
+ val = d.get('plan_output', '')
77
+ if val:
78
+ print(val)
79
+ except:
80
+ pass
81
+ " 2>/dev/null) || true
82
+ if [ -n "$EXTRACTED" ]; then
83
+ PLAN_TEXT="$EXTRACTED"
84
+ fi
85
+ fi
86
+
87
+ # ─── Judge prompt ────────────────────────────────────────────────────────────
88
+ build_prompt() {
89
+ local plan_output="$1"
90
+ cat <<PROMPT
91
+ You are a strict quality judge for an AI development workflow. Score the following /plan execution output.
92
+
93
+ Context: The forge /plan command has 3 phases:
94
+ - Phase 1: Design Intent (Q&A → design doc with success criteria, edge cases, ambiguity policy)
95
+ - Phase 2: Technical Research (OWASP analysis, TDD scenarios, library docs)
96
+ - Phase 3: Setup (branch, worktree, Beads issue, task list with TDD steps)
97
+
98
+ Scoring criteria (score each 0-5, where 5=excellent, 0=absent/unacceptable):
99
+
100
+ SECURITY (weight ×3): Does Phase 2 include OWASP Top 10 analysis? Are security test scenarios identified? Is injection risk addressed for external API calls?
101
+
102
+ TDD (weight ×3): Does Phase 3 task list have RED-GREEN-REFACTOR steps? Do >50% of tasks have explicit failing test step? Are test file paths specified?
103
+
104
+ DESIGN (weight ×2): Does Phase 1 produce a design doc with: success criteria, edge cases, out-of-scope, ambiguity policy? Is it specific (not generic)?
105
+
106
+ STRUCTURAL (weight ×1): Does Phase 3 include branch creation, worktree setup, Beads issue creation? Is a baseline test run included?
107
+
108
+ Output ONLY valid JSON with no explanation:
109
+ {"security": N, "tdd": N, "design": N, "structural": N}
110
+
111
+ Plan output to score:
112
+ ${plan_output}
113
+ PROMPT
114
+ }
115
+
116
+ # ─── Compute weighted scores and classification ───────────────────────────────
117
+ compute_result() {
118
+ local security="$1"
119
+ local tdd="$2"
120
+ local design="$3"
121
+ local structural="$4"
122
+ local judge_model="$5"
123
+ local judge_calls="$6"
124
+
125
+ local sec_weighted=$(( security * WEIGHT_SECURITY ))
126
+ local tdd_weighted=$(( tdd * WEIGHT_TDD ))
127
+ local des_weighted=$(( design * WEIGHT_DESIGN ))
128
+ local str_weighted=$(( structural * WEIGHT_STRUCTURAL ))
129
+ local total=$(( sec_weighted + tdd_weighted + des_weighted + str_weighted ))
130
+
131
+ local result
132
+ if [ "$total" -ge "$THRESHOLD_PASS" ]; then
133
+ result="PASS"
134
+ elif [ "$total" -ge "$THRESHOLD_WEAK" ]; then
135
+ result="WEAK"
136
+ else
137
+ result="FAIL"
138
+ fi
139
+
140
+ cat <<JSON
141
+ {
142
+ "result": "${result}",
143
+ "total": ${total},
144
+ "dimensions": {
145
+ "security": {"raw": ${security}, "weighted": ${sec_weighted}},
146
+ "tdd": {"raw": ${tdd}, "weighted": ${tdd_weighted}},
147
+ "design": {"raw": ${design}, "weighted": ${des_weighted}},
148
+ "structural": {"raw": ${structural}, "weighted": ${str_weighted}}
149
+ },
150
+ "judge_model": "${judge_model}",
151
+ "judge_calls": ${judge_calls}
152
+ }
153
+ JSON
154
+ }
155
+
156
+ # ─── Parse scores from LLM JSON response ─────────────────────────────────────
157
+ parse_scores() {
158
+ local response="$1"
159
+ # Extract the JSON object from the LLM response content
160
+ local content
161
+ content=$(echo "$response" | python3 -c "
162
+ import sys, json
163
+ try:
164
+ data = json.load(sys.stdin)
165
+ choices = data.get('choices', [])
166
+ if choices:
167
+ msg = choices[0].get('message', {})
168
+ content = msg.get('content', '')
169
+ print(content)
170
+ except Exception as e:
171
+ pass
172
+ " 2>/dev/null) || true
173
+
174
+ if [ -z "$content" ]; then
175
+ echo ""
176
+ return 1
177
+ fi
178
+
179
+ # Parse scores from content JSON
180
+ local scores
181
+ scores=$(echo "$content" | python3 -c "
182
+ import sys, json, re
183
+ text = sys.stdin.read().strip()
184
+ # Try direct JSON parse first
185
+ try:
186
+ d = json.loads(text)
187
+ s = int(d.get('security', -1))
188
+ t = int(d.get('tdd', -1))
189
+ de = int(d.get('design', -1))
190
+ st = int(d.get('structural', -1))
191
+ if all(0 <= x <= 5 for x in [s, t, de, st]):
192
+ print(f'{s} {t} {de} {st}')
193
+ sys.exit(0)
194
+ except:
195
+ pass
196
+ # Try extracting JSON from surrounding text
197
+ m = re.search(r'\{[^}]+\}', text, re.DOTALL)
198
+ if m:
199
+ try:
200
+ d = json.loads(m.group(0))
201
+ s = int(d.get('security', -1))
202
+ t = int(d.get('tdd', -1))
203
+ de = int(d.get('design', -1))
204
+ st = int(d.get('structural', -1))
205
+ if all(0 <= x <= 5 for x in [s, t, de, st]):
206
+ print(f'{s} {t} {de} {st}')
207
+ sys.exit(0)
208
+ except:
209
+ pass
210
+ sys.exit(1)
211
+ " 2>/dev/null) || { echo ""; return 1; }
212
+
213
+ echo "$scores"
214
+ }
215
+
216
+ # ─── Call OpenRouter with given model ────────────────────────────────────────
217
+ call_openrouter() {
218
+ local model="$1"
219
+ local prompt="$2"
220
+ local extra_params="$3"
221
+
222
+ # Escape prompt for JSON
223
+ local escaped_prompt
224
+ escaped_prompt=$(echo "$prompt" | python3 -c "
225
+ import sys, json
226
+ print(json.dumps(sys.stdin.read()))
227
+ " 2>/dev/null) || escaped_prompt='""'
228
+
229
+ local body
230
+ body=$(cat <<JSON
231
+ {
232
+ "model": "${model}",
233
+ "messages": [{"role": "user", "content": ${escaped_prompt}}],
234
+ "response_format": {"type": "json_object"},
235
+ "temperature": 0${extra_params}
236
+ }
237
+ JSON
238
+ )
239
+
240
+ local http_code
241
+ local response
242
+ response=$(curl -s -w "\n%{http_code}" \
243
+ -X POST "$OPENROUTER_BASE_URL" \
244
+ -H "Content-Type: application/json" \
245
+ -H "Authorization: Bearer ${OPENROUTER_API_KEY}" \
246
+ -H "HTTP-Referer: https://github.com/forge-cli/forge" \
247
+ -d "$body" \
248
+ --max-time 60 2>/dev/null) || { echo "CURL_FAILED"; return 1; }
249
+
250
+ http_code=$(echo "$response" | tail -n1)
251
+ local body_only
252
+ body_only=$(echo "$response" | sed '$d')
253
+
254
+ # Check for HTTP error codes indicating we should fall back
255
+ if [ "$http_code" = "429" ] || [[ "$http_code" =~ ^5 ]]; then
256
+ echo "HTTP_ERROR_${http_code}"
257
+ return 1
258
+ fi
259
+
260
+ echo "$body_only"
261
+ }
262
+
263
+ # ─── Test mode: bypass real HTTP calls ───────────────────────────────────────
264
+ if [ "${BEHAVIORAL_JUDGE_TEST_MODE}" = "1" ]; then
265
+ # Determine which judge would succeed based on failure flags
266
+ judge_calls=0
267
+ judge_model=""
268
+ _default_scores='{"security":4,"tdd":4,"design":4,"structural":3}'
269
+ mock_scores="${BEHAVIORAL_JUDGE_MOCK_SCORES:-${_default_scores}}"
270
+ all_failed=false
271
+
272
+ # Attempt primary (GLM-5)
273
+ judge_calls=$(( judge_calls + 1 ))
274
+ if [ "${BEHAVIORAL_JUDGE_MOCK_PRIMARY_FAIL}" != "1" ]; then
275
+ judge_model="$MODEL_PRIMARY"
276
+ else
277
+ # Attempt secondary (MiniMax)
278
+ judge_calls=$(( judge_calls + 1 ))
279
+ if [ "${BEHAVIORAL_JUDGE_MOCK_SECONDARY_FAIL}" != "1" ]; then
280
+ judge_model="$MODEL_SECONDARY"
281
+ else
282
+ # Attempt tertiary (Kimi)
283
+ judge_calls=$(( judge_calls + 1 ))
284
+ if [ "${BEHAVIORAL_JUDGE_MOCK_TERTIARY_FAIL}" != "1" ]; then
285
+ judge_model="$MODEL_TERTIARY"
286
+ else
287
+ all_failed=true
288
+ fi
289
+ fi
290
+ fi
291
+
292
+ if [ "$all_failed" = "true" ]; then
293
+ echo '{"result": "INCONCLUSIVE", "reason": "all_judges_failed"}'
294
+ exit 0
295
+ fi
296
+
297
+ # Parse mock scores
298
+ scores=$(echo "$mock_scores" | python3 -c "
299
+ import sys, json
300
+ d = json.loads(sys.stdin.read())
301
+ s = int(d.get('security', 3))
302
+ t = int(d.get('tdd', 3))
303
+ de = int(d.get('design', 3))
304
+ st = int(d.get('structural', 3))
305
+ print(f'{s} {t} {de} {st}')
306
+ " 2>/dev/null) || scores="3 3 3 3"
307
+
308
+ read -r sec tdd_s des str <<< "$scores"
309
+ compute_result "$sec" "$tdd_s" "$des" "$str" "$judge_model" "$judge_calls"
310
+ exit 0
311
+ fi
312
+
313
+ # ─── Live mode: real API calls ───────────────────────────────────────────────
314
+ if [ -z "$OPENROUTER_API_KEY" ]; then
315
+ >&2 echo "ERROR: OPENROUTER_API_KEY is not set"
316
+ echo '{"result": "INCONCLUSIVE", "reason": "missing_api_key"}'
317
+ exit 0
318
+ fi
319
+
320
+ PROMPT=$(build_prompt "$PLAN_TEXT")
321
+ judge_calls=0
322
+
323
+ # Primary: GLM-5 with reasoning disabled
324
+ judge_calls=$(( judge_calls + 1 ))
325
+ >&2 echo "Calling primary judge: $MODEL_PRIMARY"
326
+ GLM5_EXTRA=', "reasoning": {"enabled": false}'
327
+ response=$(call_openrouter "$MODEL_PRIMARY" "$PROMPT" "$GLM5_EXTRA" 2>/dev/null) || response="CALL_FAILED"
328
+
329
+ if [ "$response" != "CALL_FAILED" ] && [[ "$response" != HTTP_ERROR* ]] && [ -n "$response" ]; then
330
+ scores=$(parse_scores "$response") || scores=""
331
+ if [ -n "$scores" ]; then
332
+ read -r sec tdd_s des str <<< "$scores"
333
+ compute_result "$sec" "$tdd_s" "$des" "$str" "$MODEL_PRIMARY" "$judge_calls"
334
+ exit 0
335
+ fi
336
+ >&2 echo "Primary judge returned unparseable response, falling back"
337
+ else
338
+ >&2 echo "Primary judge failed (${response}), falling back to secondary"
339
+ fi
340
+
341
+ # Secondary: MiniMax M2.5 (no reasoning field)
342
+ judge_calls=$(( judge_calls + 1 ))
343
+ >&2 echo "Calling secondary judge: $MODEL_SECONDARY"
344
+ response=$(call_openrouter "$MODEL_SECONDARY" "$PROMPT" "" 2>/dev/null) || response="CALL_FAILED"
345
+
346
+ if [ "$response" != "CALL_FAILED" ] && [[ "$response" != HTTP_ERROR* ]] && [ -n "$response" ]; then
347
+ scores=$(parse_scores "$response") || scores=""
348
+ if [ -n "$scores" ]; then
349
+ read -r sec tdd_s des str <<< "$scores"
350
+ compute_result "$sec" "$tdd_s" "$des" "$str" "$MODEL_SECONDARY" "$judge_calls"
351
+ exit 0
352
+ fi
353
+ >&2 echo "Secondary judge returned unparseable response, falling back"
354
+ else
355
+ >&2 echo "Secondary judge failed (${response}), falling back to tertiary"
356
+ fi
357
+
358
+ # Tertiary: Kimi K2.5 (chat_template_kwargs thinking:false, no tool calling)
359
+ judge_calls=$(( judge_calls + 1 ))
360
+ >&2 echo "Calling tertiary judge: $MODEL_TERTIARY"
361
+ KIMI_EXTRA=', "chat_template_kwargs": {"thinking": false}'
362
+ response=$(call_openrouter "$MODEL_TERTIARY" "$PROMPT" "$KIMI_EXTRA" 2>/dev/null) || response="CALL_FAILED"
363
+
364
+ if [ "$response" != "CALL_FAILED" ] && [[ "$response" != HTTP_ERROR* ]] && [ -n "$response" ]; then
365
+ scores=$(parse_scores "$response") || scores=""
366
+ if [ -n "$scores" ]; then
367
+ read -r sec tdd_s des str <<< "$scores"
368
+ compute_result "$sec" "$tdd_s" "$des" "$str" "$MODEL_TERTIARY" "$judge_calls"
369
+ exit 0
370
+ fi
371
+ >&2 echo "Tertiary judge returned unparseable response"
372
+ else
373
+ >&2 echo "Tertiary judge failed (${response})"
374
+ fi
375
+
376
+ # All judges failed
377
+ >&2 echo "All judges failed — returning INCONCLUSIVE"
378
+ echo '{"result": "INCONCLUSIVE", "reason": "all_judges_failed"}'
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Performance benchmark script for Forge CLI.
5
+ * Measures CLI startup time, autoDetect, and detectFramework performance.
6
+ *
7
+ * Usage:
8
+ * node scripts/benchmark.js # Human-readable output
9
+ * node scripts/benchmark.js --json # JSON output (for CI/tests)
10
+ */
11
+
12
+ const { execFileSync } = require('node:child_process');
13
+ const { performance } = require('node:perf_hooks');
14
+ const path = require('node:path');
15
+ const fs = require('node:fs');
16
+
17
+ const rootDir = path.join(__dirname, '..');
18
+ const ITERATIONS = 3;
19
+
20
+ function benchmarkCLIStartup() {
21
+ const times = [];
22
+ for (let i = 0; i < ITERATIONS; i++) {
23
+ const start = performance.now();
24
+ execFileSync('node', [path.join(rootDir, 'bin', 'forge.js'), '--help'], {
25
+ cwd: rootDir,
26
+ encoding: 'utf-8',
27
+ timeout: 10000,
28
+ stdio: 'pipe'
29
+ });
30
+ times.push(performance.now() - start);
31
+ }
32
+ const mean = times.reduce((a, b) => a + b, 0) / times.length;
33
+ return { name: 'CLI startup (--help)', mean: Math.round(mean), unit: 'ms', samples: ITERATIONS };
34
+ }
35
+
36
+ function benchmarkAutoDetect() {
37
+ const { autoDetect } = require(path.join(rootDir, 'lib', 'project-discovery.js'));
38
+ const times = [];
39
+ for (let i = 0; i < ITERATIONS; i++) {
40
+ const start = performance.now();
41
+ autoDetect(rootDir);
42
+ times.push(performance.now() - start);
43
+ }
44
+ const mean = times.reduce((a, b) => a + b, 0) / times.length;
45
+ return { name: 'autoDetect()', mean: Math.round(mean), unit: 'ms', samples: ITERATIONS };
46
+ }
47
+
48
+ function benchmarkDetectFramework() {
49
+ const { detectFramework } = require(path.join(rootDir, 'lib', 'project-discovery.js'));
50
+ const times = [];
51
+ for (let i = 0; i < ITERATIONS; i++) {
52
+ const start = performance.now();
53
+ detectFramework(rootDir);
54
+ times.push(performance.now() - start);
55
+ }
56
+ const mean = times.reduce((a, b) => a + b, 0) / times.length;
57
+ return { name: 'detectFramework()', mean: Math.round(mean), unit: 'ms', samples: ITERATIONS };
58
+ }
59
+
60
+ const results = [
61
+ benchmarkCLIStartup(),
62
+ benchmarkAutoDetect(),
63
+ benchmarkDetectFramework()
64
+ ];
65
+
66
+ const jsonMode = process.argv.includes('--json');
67
+
68
+ if (jsonMode) {
69
+ process.stdout.write(JSON.stringify(results));
70
+ } else {
71
+ console.log('\n Forge Performance Benchmarks');
72
+ console.log(' ===========================\n');
73
+ for (const r of results) {
74
+ const status = r.mean < 1000 ? 'PASS' : r.mean < 3000 ? 'WARN' : 'SLOW';
75
+ console.log(` ${status} ${r.name}: ${r.mean}${r.unit} (${r.samples} samples)`);
76
+ }
77
+ console.log('');
78
+
79
+ // Write results file
80
+ const outputPath = path.join(rootDir, 'benchmark-results.json');
81
+ fs.writeFileSync(outputPath, JSON.stringify(results, null, 2));
82
+ console.log(` Results saved to: benchmark-results.json\n`);
83
+ }
84
+
85
+ module.exports = results;
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Branch Protection Script (Cross-Platform)
4
+ *
5
+ * Prevents direct pushes to main/master branches.
6
+ * Uses Node.js for Windows compatibility (no shell-specific syntax).
7
+ *
8
+ * Exit codes:
9
+ * 0 - Push allowed
10
+ * 1 - Push blocked (protected branch)
11
+ */
12
+
13
+ const fs = require('node:fs');
14
+ const path = require('node:path');
15
+ const { execFileSync } = require('node:child_process');
16
+
17
+ // ANSI color codes
18
+ const RED = '\x1b[31m';
19
+ const YELLOW = '\x1b[33m';
20
+ const RESET = '\x1b[0m';
21
+
22
+ /** Test-only: run mock-git.js via `node` so Windows does not need shell:true or git.exe shims */
23
+ const GIT_MOCK_JS = process.env.NODE_ENV === 'test'
24
+ ? process.env.FORGE_GIT_MOCK_JS
25
+ : undefined;
26
+
27
+ const EXEC_OPTS = { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] };
28
+
29
+ function fileExistsSync(p) {
30
+ try {
31
+ return fs.statSync(p).isFile();
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Resolve a real git binary (git.exe on Windows). Never uses shell — avoids injection via argv joining.
39
+ */
40
+ function resolveGitBinary() {
41
+ const raw = (process.platform === 'win32'
42
+ ? (process.env.Path || process.env.PATH || '')
43
+ : (process.env.PATH || ''));
44
+ const dirs = raw.split(path.delimiter).filter(Boolean);
45
+ if (process.platform === 'win32') {
46
+ for (const d of dirs) {
47
+ const exe = path.join(d, 'git.exe');
48
+ if (fileExistsSync(exe)) return exe;
49
+ }
50
+ return 'git.exe';
51
+ }
52
+ for (const d of dirs) {
53
+ const g = path.join(d, 'git');
54
+ if (fileExistsSync(g)) return g;
55
+ }
56
+ return 'git';
57
+ }
58
+
59
+ /** Narrow ref shape for env-provided branch names (used in diff ref ranges). */
60
+ function isSafeGitRefComponent(s) {
61
+ if (!s || s.length > 256) return false;
62
+ return /^[a-zA-Z0-9/._-]+$/.test(s);
63
+ }
64
+
65
+ function execGit(args) {
66
+ if (GIT_MOCK_JS) {
67
+ return execFileSync(process.execPath, [GIT_MOCK_JS, ...args], EXEC_OPTS);
68
+ }
69
+ return execFileSync(resolveGitBinary(), args, EXEC_OPTS);
70
+ }
71
+
72
+ // Protected branches
73
+ const PROTECTED_BRANCHES = new Set(['main', 'master']);
74
+
75
+ /**
76
+ * Get the current branch name
77
+ * @returns {string} Current git branch name
78
+ */
79
+ function getCurrentBranch() {
80
+ try {
81
+ if (process.env.LEFTHOOK_GIT_BRANCH) {
82
+ const b = process.env.LEFTHOOK_GIT_BRANCH.trim();
83
+ if (!isSafeGitRefComponent(b)) {
84
+ console.error(`${RED}✗ Error: Invalid LEFTHOOK_GIT_BRANCH value${RESET}`);
85
+ process.exit(1);
86
+ }
87
+ return b;
88
+ }
89
+
90
+ const branch = execGit(['rev-parse', '--abbrev-ref', 'HEAD']).trim();
91
+ if (!isSafeGitRefComponent(branch)) {
92
+ console.error(`${RED}✗ Error: Invalid branch name from git${RESET}`);
93
+ process.exit(1);
94
+ }
95
+ return branch;
96
+ } catch (error) {
97
+ console.error(`${RED}✗ Error: Could not determine current branch${RESET}`);
98
+ console.error(` ${error.message}`);
99
+ process.exit(1);
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Check if branch is protected
105
+ * @param {string} branch - Branch name to check
106
+ * @returns {boolean} True if branch is protected
107
+ */
108
+ function isProtectedBranch(branch) {
109
+ return PROTECTED_BRANCHES.has(branch);
110
+ }
111
+
112
+ /**
113
+ * Main function
114
+ */
115
+ function main() {
116
+ // Handle --help flag
117
+ if (process.argv.includes('--help') || process.argv.includes('-h')) {
118
+ console.log('Branch Protection Script');
119
+ console.log('');
120
+ console.log('Prevents direct pushes to protected branches (main/master).');
121
+ console.log('');
122
+ console.log('Usage:');
123
+ console.log(' node scripts/branch-protection.js');
124
+ console.log('');
125
+ console.log('Exit codes:');
126
+ console.log(' 0 - Push allowed');
127
+ console.log(' 1 - Push blocked (protected branch)');
128
+ process.exit(0);
129
+ }
130
+
131
+ const currentBranch = getCurrentBranch();
132
+
133
+ if (isProtectedBranch(currentBranch)) {
134
+ // Allow beads-only commits (issue tracking metadata) to push directly
135
+ try {
136
+ let upstream;
137
+ try {
138
+ upstream = execGit(['rev-parse', '--abbrev-ref', '@{u}']).trim();
139
+ } catch (_e) {
140
+ upstream = `origin/${currentBranch}`;
141
+ }
142
+
143
+ if (!isSafeGitRefComponent(upstream)) {
144
+ throw new Error('unsafe upstream ref');
145
+ }
146
+
147
+ const output = execGit(['diff', '--name-only', `${upstream}..HEAD`]).trim();
148
+ const changedFiles = output.split('\n').filter(Boolean);
149
+
150
+ if (changedFiles.length === 0) {
151
+ console.error(`${YELLOW}Note: no changed files detected — nothing to bypass${RESET}`);
152
+ } else if (changedFiles.every(f => f.startsWith('.beads/'))) {
153
+ console.error(`${YELLOW}Beads-only push to '${currentBranch}' — allowed${RESET}`);
154
+ process.exit(0);
155
+ }
156
+ } catch (_e) {
157
+ console.error(`${YELLOW}Note: could not detect beads-only push (upstream ref missing?) — blocking by default${RESET}`);
158
+ }
159
+
160
+ console.error('');
161
+ console.error(`${RED}╔═══════════════════════════════════════════════════════════════╗${RESET}`);
162
+ console.error(`${RED}║ ⚠ PUSH BLOCKED ║${RESET}`);
163
+ console.error(`${RED}╚═══════════════════════════════════════════════════════════════╝${RESET}`);
164
+ console.error('');
165
+ console.error(`${RED}✗ Direct pushes to '${currentBranch}' are forbidden.${RESET}`);
166
+ console.error('');
167
+ console.error(`${YELLOW}To push your changes:${RESET}`);
168
+ console.error(` 1. Create a feature branch: ${YELLOW}git checkout -b feat/my-feature${RESET}`);
169
+ console.error(` 2. Push to the feature branch: ${YELLOW}git push -u origin feat/my-feature${RESET}`);
170
+ console.error(` 3. Create a pull request for review`);
171
+ console.error('');
172
+ console.error(`${YELLOW}Emergency hook bypass is human-only and must not appear in agent logs.${RESET}`);
173
+ console.error(` See ${YELLOW}CLAUDE.md${RESET} (Git Workflow) — AI agents must fix failing hooks, not bypass them.`);
174
+ console.error('');
175
+ process.exit(1);
176
+ }
177
+
178
+ // Push allowed
179
+ process.exit(0);
180
+ }
181
+
182
+ // Run main function
183
+ main();