aidevops 2.52.1 → 2.53.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/README.md +1 -1
  2. package/VERSION +1 -1
  3. package/aidevops.sh +15 -9
  4. package/package.json +4 -4
  5. package/scripts/npm-postinstall.js +6 -7
  6. package/setup.sh +1 -1
  7. package/templates/deploy-templates.sh +144 -0
  8. package/templates/home/.agent/README.md +33 -0
  9. package/templates/home/AGENTS.md +96 -0
  10. package/templates/home/git/.agent/README.md +48 -0
  11. package/templates/home/git/AGENTS.md +97 -0
  12. package/templates/standard-functions.sh +179 -0
  13. package/templates/wordpress-performance-workflow.md +217 -0
  14. package/.agent/AGENTS.md +0 -614
  15. package/.agent/accounts.md +0 -65
  16. package/.agent/aidevops/add-new-mcp-to-aidevops.md +0 -456
  17. package/.agent/aidevops/api-integrations.md +0 -335
  18. package/.agent/aidevops/architecture.md +0 -510
  19. package/.agent/aidevops/configs.md +0 -274
  20. package/.agent/aidevops/docs.md +0 -244
  21. package/.agent/aidevops/extension.md +0 -311
  22. package/.agent/aidevops/mcp-integrations.md +0 -340
  23. package/.agent/aidevops/mcp-troubleshooting.md +0 -162
  24. package/.agent/aidevops/memory-patterns.md +0 -172
  25. package/.agent/aidevops/providers.md +0 -217
  26. package/.agent/aidevops/recommendations.md +0 -321
  27. package/.agent/aidevops/requirements.md +0 -301
  28. package/.agent/aidevops/resources.md +0 -214
  29. package/.agent/aidevops/security-requirements.md +0 -174
  30. package/.agent/aidevops/security.md +0 -350
  31. package/.agent/aidevops/service-links.md +0 -400
  32. package/.agent/aidevops/services.md +0 -357
  33. package/.agent/aidevops/setup.md +0 -153
  34. package/.agent/aidevops/troubleshooting.md +0 -389
  35. package/.agent/aidevops.md +0 -124
  36. package/.agent/build-plus.md +0 -244
  37. package/.agent/content/guidelines.md +0 -109
  38. package/.agent/content.md +0 -87
  39. package/.agent/health.md +0 -59
  40. package/.agent/legal.md +0 -59
  41. package/.agent/loop-state/full-loop.local.md +0 -16
  42. package/.agent/loop-state/ralph-loop.local.md +0 -10
  43. package/.agent/marketing.md +0 -440
  44. package/.agent/memory/README.md +0 -260
  45. package/.agent/onboarding.md +0 -796
  46. package/.agent/plan-plus.md +0 -245
  47. package/.agent/research.md +0 -100
  48. package/.agent/sales.md +0 -333
  49. package/.agent/scripts/101domains-helper.sh +0 -701
  50. package/.agent/scripts/add-missing-returns.sh +0 -140
  51. package/.agent/scripts/agent-browser-helper.sh +0 -311
  52. package/.agent/scripts/agno-setup.sh +0 -712
  53. package/.agent/scripts/ahrefs-mcp-wrapper.js +0 -168
  54. package/.agent/scripts/aidevops-update-check.sh +0 -71
  55. package/.agent/scripts/ampcode-cli.sh +0 -522
  56. package/.agent/scripts/auto-version-bump.sh +0 -156
  57. package/.agent/scripts/autogen-helper.sh +0 -512
  58. package/.agent/scripts/beads-sync-helper.sh +0 -596
  59. package/.agent/scripts/closte-helper.sh +0 -5
  60. package/.agent/scripts/cloudron-helper.sh +0 -321
  61. package/.agent/scripts/codacy-cli-chunked.sh +0 -581
  62. package/.agent/scripts/codacy-cli.sh +0 -442
  63. package/.agent/scripts/code-audit-helper.sh +0 -5
  64. package/.agent/scripts/coderabbit-cli.sh +0 -417
  65. package/.agent/scripts/coderabbit-pro-analysis.sh +0 -238
  66. package/.agent/scripts/commands/code-simplifier.md +0 -86
  67. package/.agent/scripts/commands/full-loop.md +0 -246
  68. package/.agent/scripts/commands/postflight-loop.md +0 -103
  69. package/.agent/scripts/commands/recall.md +0 -182
  70. package/.agent/scripts/commands/remember.md +0 -132
  71. package/.agent/scripts/commands/save-todo.md +0 -175
  72. package/.agent/scripts/commands/session-review.md +0 -154
  73. package/.agent/scripts/comprehensive-quality-fix.sh +0 -106
  74. package/.agent/scripts/context-builder-helper.sh +0 -522
  75. package/.agent/scripts/coolify-cli-helper.sh +0 -674
  76. package/.agent/scripts/coolify-helper.sh +0 -380
  77. package/.agent/scripts/crawl4ai-examples.sh +0 -401
  78. package/.agent/scripts/crawl4ai-helper.sh +0 -1078
  79. package/.agent/scripts/crewai-helper.sh +0 -681
  80. package/.agent/scripts/dev-browser-helper.sh +0 -513
  81. package/.agent/scripts/dns-helper.sh +0 -396
  82. package/.agent/scripts/domain-research-helper.sh +0 -917
  83. package/.agent/scripts/dspy-helper.sh +0 -285
  84. package/.agent/scripts/dspyground-helper.sh +0 -291
  85. package/.agent/scripts/eeat-score-helper.sh +0 -1242
  86. package/.agent/scripts/efficient-return-fix.sh +0 -92
  87. package/.agent/scripts/extract-opencode-prompts.sh +0 -128
  88. package/.agent/scripts/find-missing-returns.sh +0 -113
  89. package/.agent/scripts/fix-auth-headers.sh +0 -104
  90. package/.agent/scripts/fix-common-strings.sh +0 -254
  91. package/.agent/scripts/fix-content-type.sh +0 -100
  92. package/.agent/scripts/fix-error-messages.sh +0 -130
  93. package/.agent/scripts/fix-misplaced-returns.sh +0 -74
  94. package/.agent/scripts/fix-remaining-literals.sh +0 -152
  95. package/.agent/scripts/fix-return-statements.sh +0 -41
  96. package/.agent/scripts/fix-s131-default-cases.sh +0 -249
  97. package/.agent/scripts/fix-sc2155-simple.sh +0 -102
  98. package/.agent/scripts/fix-shellcheck-critical.sh +0 -187
  99. package/.agent/scripts/fix-string-literals.sh +0 -273
  100. package/.agent/scripts/full-loop-helper.sh +0 -773
  101. package/.agent/scripts/generate-opencode-agents.sh +0 -497
  102. package/.agent/scripts/generate-opencode-commands.sh +0 -1629
  103. package/.agent/scripts/generate-skills.sh +0 -366
  104. package/.agent/scripts/git-platforms-helper.sh +0 -640
  105. package/.agent/scripts/gitea-cli-helper.sh +0 -743
  106. package/.agent/scripts/github-cli-helper.sh +0 -702
  107. package/.agent/scripts/gitlab-cli-helper.sh +0 -682
  108. package/.agent/scripts/gsc-add-user-helper.sh +0 -325
  109. package/.agent/scripts/gsc-sitemap-helper.sh +0 -678
  110. package/.agent/scripts/hetzner-helper.sh +0 -485
  111. package/.agent/scripts/hostinger-helper.sh +0 -229
  112. package/.agent/scripts/keyword-research-helper.sh +0 -1815
  113. package/.agent/scripts/langflow-helper.sh +0 -544
  114. package/.agent/scripts/linkedin-automation.py +0 -241
  115. package/.agent/scripts/linter-manager.sh +0 -599
  116. package/.agent/scripts/linters-local.sh +0 -434
  117. package/.agent/scripts/list-keys-helper.sh +0 -488
  118. package/.agent/scripts/local-browser-automation.py +0 -339
  119. package/.agent/scripts/localhost-helper.sh +0 -744
  120. package/.agent/scripts/loop-common.sh +0 -806
  121. package/.agent/scripts/mainwp-helper.sh +0 -728
  122. package/.agent/scripts/markdown-formatter.sh +0 -338
  123. package/.agent/scripts/markdown-lint-fix.sh +0 -311
  124. package/.agent/scripts/mass-fix-returns.sh +0 -58
  125. package/.agent/scripts/mcp-diagnose.sh +0 -167
  126. package/.agent/scripts/mcp-inspector-helper.sh +0 -449
  127. package/.agent/scripts/memory-helper.sh +0 -650
  128. package/.agent/scripts/monitor-code-review.sh +0 -255
  129. package/.agent/scripts/onboarding-helper.sh +0 -706
  130. package/.agent/scripts/opencode-github-setup-helper.sh +0 -797
  131. package/.agent/scripts/opencode-test-helper.sh +0 -213
  132. package/.agent/scripts/pagespeed-helper.sh +0 -464
  133. package/.agent/scripts/pandoc-helper.sh +0 -362
  134. package/.agent/scripts/postflight-check.sh +0 -555
  135. package/.agent/scripts/pre-commit-hook.sh +0 -259
  136. package/.agent/scripts/pre-edit-check.sh +0 -169
  137. package/.agent/scripts/qlty-cli.sh +0 -356
  138. package/.agent/scripts/quality-cli-manager.sh +0 -525
  139. package/.agent/scripts/quality-feedback-helper.sh +0 -462
  140. package/.agent/scripts/quality-fix.sh +0 -263
  141. package/.agent/scripts/quality-loop-helper.sh +0 -1108
  142. package/.agent/scripts/ralph-loop-helper.sh +0 -836
  143. package/.agent/scripts/ralph-upstream-check.sh +0 -341
  144. package/.agent/scripts/secretlint-helper.sh +0 -847
  145. package/.agent/scripts/servers-helper.sh +0 -241
  146. package/.agent/scripts/ses-helper.sh +0 -619
  147. package/.agent/scripts/session-review-helper.sh +0 -404
  148. package/.agent/scripts/setup-linters-wizard.sh +0 -379
  149. package/.agent/scripts/setup-local-api-keys.sh +0 -330
  150. package/.agent/scripts/setup-mcp-integrations.sh +0 -472
  151. package/.agent/scripts/shared-constants.sh +0 -246
  152. package/.agent/scripts/site-crawler-helper.sh +0 -1487
  153. package/.agent/scripts/snyk-helper.sh +0 -940
  154. package/.agent/scripts/sonarcloud-autofix.sh +0 -193
  155. package/.agent/scripts/sonarcloud-cli.sh +0 -191
  156. package/.agent/scripts/sonarscanner-cli.sh +0 -455
  157. package/.agent/scripts/spaceship-helper.sh +0 -747
  158. package/.agent/scripts/stagehand-helper.sh +0 -321
  159. package/.agent/scripts/stagehand-python-helper.sh +0 -321
  160. package/.agent/scripts/stagehand-python-setup.sh +0 -441
  161. package/.agent/scripts/stagehand-setup.sh +0 -439
  162. package/.agent/scripts/system-cleanup.sh +0 -340
  163. package/.agent/scripts/terminal-title-helper.sh +0 -388
  164. package/.agent/scripts/terminal-title-setup.sh +0 -549
  165. package/.agent/scripts/test-stagehand-both-integration.sh +0 -317
  166. package/.agent/scripts/test-stagehand-integration.sh +0 -309
  167. package/.agent/scripts/test-stagehand-python-integration.sh +0 -341
  168. package/.agent/scripts/todo-ready.sh +0 -263
  169. package/.agent/scripts/tool-version-check.sh +0 -362
  170. package/.agent/scripts/toon-helper.sh +0 -469
  171. package/.agent/scripts/twilio-helper.sh +0 -917
  172. package/.agent/scripts/updown-helper.sh +0 -279
  173. package/.agent/scripts/validate-mcp-integrations.sh +0 -250
  174. package/.agent/scripts/validate-version-consistency.sh +0 -131
  175. package/.agent/scripts/vaultwarden-helper.sh +0 -597
  176. package/.agent/scripts/vercel-cli-helper.sh +0 -816
  177. package/.agent/scripts/verify-mirrors.sh +0 -169
  178. package/.agent/scripts/version-manager.sh +0 -831
  179. package/.agent/scripts/webhosting-helper.sh +0 -471
  180. package/.agent/scripts/webhosting-verify.sh +0 -238
  181. package/.agent/scripts/wordpress-mcp-helper.sh +0 -508
  182. package/.agent/scripts/worktree-helper.sh +0 -595
  183. package/.agent/scripts/worktree-sessions.sh +0 -577
  184. package/.agent/seo/dataforseo.md +0 -215
  185. package/.agent/seo/domain-research.md +0 -532
  186. package/.agent/seo/eeat-score.md +0 -659
  187. package/.agent/seo/google-search-console.md +0 -366
  188. package/.agent/seo/gsc-sitemaps.md +0 -282
  189. package/.agent/seo/keyword-research.md +0 -521
  190. package/.agent/seo/serper.md +0 -278
  191. package/.agent/seo/site-crawler.md +0 -387
  192. package/.agent/seo.md +0 -236
  193. package/.agent/services/accounting/quickfile.md +0 -159
  194. package/.agent/services/communications/telfon.md +0 -470
  195. package/.agent/services/communications/twilio.md +0 -569
  196. package/.agent/services/crm/fluentcrm.md +0 -449
  197. package/.agent/services/email/ses.md +0 -399
  198. package/.agent/services/hosting/101domains.md +0 -378
  199. package/.agent/services/hosting/closte.md +0 -177
  200. package/.agent/services/hosting/cloudflare.md +0 -251
  201. package/.agent/services/hosting/cloudron.md +0 -478
  202. package/.agent/services/hosting/dns-providers.md +0 -335
  203. package/.agent/services/hosting/domain-purchasing.md +0 -344
  204. package/.agent/services/hosting/hetzner.md +0 -327
  205. package/.agent/services/hosting/hostinger.md +0 -287
  206. package/.agent/services/hosting/localhost.md +0 -419
  207. package/.agent/services/hosting/spaceship.md +0 -353
  208. package/.agent/services/hosting/webhosting.md +0 -330
  209. package/.agent/social-media.md +0 -69
  210. package/.agent/templates/plans-template.md +0 -114
  211. package/.agent/templates/prd-template.md +0 -129
  212. package/.agent/templates/tasks-template.md +0 -108
  213. package/.agent/templates/todo-template.md +0 -89
  214. package/.agent/tools/ai-assistants/agno.md +0 -471
  215. package/.agent/tools/ai-assistants/capsolver.md +0 -326
  216. package/.agent/tools/ai-assistants/configuration.md +0 -221
  217. package/.agent/tools/ai-assistants/overview.md +0 -209
  218. package/.agent/tools/ai-assistants/status.md +0 -171
  219. package/.agent/tools/ai-assistants/windsurf.md +0 -193
  220. package/.agent/tools/ai-orchestration/autogen.md +0 -406
  221. package/.agent/tools/ai-orchestration/crewai.md +0 -445
  222. package/.agent/tools/ai-orchestration/langflow.md +0 -405
  223. package/.agent/tools/ai-orchestration/openprose.md +0 -487
  224. package/.agent/tools/ai-orchestration/overview.md +0 -362
  225. package/.agent/tools/ai-orchestration/packaging.md +0 -647
  226. package/.agent/tools/browser/agent-browser.md +0 -464
  227. package/.agent/tools/browser/browser-automation.md +0 -400
  228. package/.agent/tools/browser/chrome-devtools.md +0 -282
  229. package/.agent/tools/browser/crawl4ai-integration.md +0 -422
  230. package/.agent/tools/browser/crawl4ai-resources.md +0 -277
  231. package/.agent/tools/browser/crawl4ai-usage.md +0 -416
  232. package/.agent/tools/browser/crawl4ai.md +0 -585
  233. package/.agent/tools/browser/dev-browser.md +0 -341
  234. package/.agent/tools/browser/pagespeed.md +0 -260
  235. package/.agent/tools/browser/playwright.md +0 -266
  236. package/.agent/tools/browser/playwriter.md +0 -310
  237. package/.agent/tools/browser/stagehand-examples.md +0 -456
  238. package/.agent/tools/browser/stagehand-python.md +0 -483
  239. package/.agent/tools/browser/stagehand.md +0 -421
  240. package/.agent/tools/build-agent/agent-review.md +0 -224
  241. package/.agent/tools/build-agent/build-agent.md +0 -784
  242. package/.agent/tools/build-mcp/aidevops-plugin.md +0 -476
  243. package/.agent/tools/build-mcp/api-wrapper.md +0 -445
  244. package/.agent/tools/build-mcp/build-mcp.md +0 -240
  245. package/.agent/tools/build-mcp/deployment.md +0 -401
  246. package/.agent/tools/build-mcp/server-patterns.md +0 -632
  247. package/.agent/tools/build-mcp/transports.md +0 -366
  248. package/.agent/tools/code-review/auditing.md +0 -383
  249. package/.agent/tools/code-review/automation.md +0 -219
  250. package/.agent/tools/code-review/best-practices.md +0 -203
  251. package/.agent/tools/code-review/codacy.md +0 -151
  252. package/.agent/tools/code-review/code-simplifier.md +0 -174
  253. package/.agent/tools/code-review/code-standards.md +0 -309
  254. package/.agent/tools/code-review/coderabbit.md +0 -101
  255. package/.agent/tools/code-review/management.md +0 -155
  256. package/.agent/tools/code-review/qlty.md +0 -248
  257. package/.agent/tools/code-review/secretlint.md +0 -565
  258. package/.agent/tools/code-review/setup.md +0 -250
  259. package/.agent/tools/code-review/snyk.md +0 -563
  260. package/.agent/tools/code-review/tools.md +0 -230
  261. package/.agent/tools/content/summarize.md +0 -353
  262. package/.agent/tools/context/augment-context-engine.md +0 -468
  263. package/.agent/tools/context/context-builder-agent.md +0 -76
  264. package/.agent/tools/context/context-builder.md +0 -375
  265. package/.agent/tools/context/context7.md +0 -371
  266. package/.agent/tools/context/dspy.md +0 -302
  267. package/.agent/tools/context/dspyground.md +0 -374
  268. package/.agent/tools/context/llm-tldr.md +0 -219
  269. package/.agent/tools/context/osgrep.md +0 -488
  270. package/.agent/tools/context/prompt-optimization.md +0 -338
  271. package/.agent/tools/context/toon.md +0 -292
  272. package/.agent/tools/conversion/pandoc.md +0 -304
  273. package/.agent/tools/credentials/api-key-management.md +0 -154
  274. package/.agent/tools/credentials/api-key-setup.md +0 -224
  275. package/.agent/tools/credentials/environment-variables.md +0 -180
  276. package/.agent/tools/credentials/vaultwarden.md +0 -382
  277. package/.agent/tools/data-extraction/outscraper.md +0 -974
  278. package/.agent/tools/deployment/coolify-cli.md +0 -388
  279. package/.agent/tools/deployment/coolify-setup.md +0 -353
  280. package/.agent/tools/deployment/coolify.md +0 -345
  281. package/.agent/tools/deployment/vercel.md +0 -390
  282. package/.agent/tools/git/authentication.md +0 -132
  283. package/.agent/tools/git/gitea-cli.md +0 -193
  284. package/.agent/tools/git/github-actions.md +0 -207
  285. package/.agent/tools/git/github-cli.md +0 -223
  286. package/.agent/tools/git/gitlab-cli.md +0 -190
  287. package/.agent/tools/git/opencode-github-security.md +0 -350
  288. package/.agent/tools/git/opencode-github.md +0 -328
  289. package/.agent/tools/git/opencode-gitlab.md +0 -252
  290. package/.agent/tools/git/security.md +0 -196
  291. package/.agent/tools/git.md +0 -207
  292. package/.agent/tools/opencode/oh-my-opencode.md +0 -375
  293. package/.agent/tools/opencode/opencode-anthropic-auth.md +0 -446
  294. package/.agent/tools/opencode/opencode.md +0 -651
  295. package/.agent/tools/social-media/bird.md +0 -437
  296. package/.agent/tools/task-management/beads.md +0 -336
  297. package/.agent/tools/terminal/terminal-title.md +0 -251
  298. package/.agent/tools/ui/shadcn.md +0 -196
  299. package/.agent/tools/ui/ui-skills.md +0 -115
  300. package/.agent/tools/wordpress/localwp.md +0 -311
  301. package/.agent/tools/wordpress/mainwp.md +0 -391
  302. package/.agent/tools/wordpress/scf.md +0 -527
  303. package/.agent/tools/wordpress/wp-admin.md +0 -729
  304. package/.agent/tools/wordpress/wp-dev.md +0 -940
  305. package/.agent/tools/wordpress/wp-preferred.md +0 -398
  306. package/.agent/tools/wordpress.md +0 -95
  307. package/.agent/workflows/branch/bugfix.md +0 -63
  308. package/.agent/workflows/branch/chore.md +0 -95
  309. package/.agent/workflows/branch/experiment.md +0 -115
  310. package/.agent/workflows/branch/feature.md +0 -59
  311. package/.agent/workflows/branch/hotfix.md +0 -98
  312. package/.agent/workflows/branch/refactor.md +0 -92
  313. package/.agent/workflows/branch/release.md +0 -96
  314. package/.agent/workflows/branch.md +0 -347
  315. package/.agent/workflows/bug-fixing.md +0 -267
  316. package/.agent/workflows/changelog.md +0 -129
  317. package/.agent/workflows/code-audit-remote.md +0 -279
  318. package/.agent/workflows/conversation-starter.md +0 -69
  319. package/.agent/workflows/error-feedback.md +0 -578
  320. package/.agent/workflows/feature-development.md +0 -355
  321. package/.agent/workflows/git-workflow.md +0 -702
  322. package/.agent/workflows/multi-repo-workspace.md +0 -268
  323. package/.agent/workflows/plans.md +0 -709
  324. package/.agent/workflows/postflight.md +0 -604
  325. package/.agent/workflows/pr.md +0 -571
  326. package/.agent/workflows/preflight.md +0 -278
  327. package/.agent/workflows/ralph-loop.md +0 -773
  328. package/.agent/workflows/release.md +0 -498
  329. package/.agent/workflows/session-manager.md +0 -254
  330. package/.agent/workflows/session-review.md +0 -311
  331. package/.agent/workflows/sql-migrations.md +0 -631
  332. package/.agent/workflows/version-bump.md +0 -283
  333. package/.agent/workflows/wiki-update.md +0 -333
  334. package/.agent/workflows/worktree.md +0 -477
@@ -1,836 +0,0 @@
1
- #!/bin/bash
2
- # =============================================================================
3
- # Ralph Loop Helper v2 - Cross-Tool Iterative AI Development
4
- # =============================================================================
5
- # Implementation of the Ralph Wiggum technique for iterative AI development.
6
- # Works with Claude Code, OpenCode, and other AI CLI tools.
7
- #
8
- # v2 Architecture (based on flow-next):
9
- # - Fresh context per iteration (external bash loop)
10
- # - File I/O as state (JSON-based, not transcript)
11
- # - Re-anchor from source of truth every iteration
12
- # - Receipt-based verification
13
- # - Memory integration for cross-session learning
14
- #
15
- # Usage:
16
- # ralph-loop-helper.sh setup "<prompt>" [--max-iterations N] [--completion-promise "TEXT"]
17
- # ralph-loop-helper.sh run "<prompt>" [options] --tool <tool> # v2: fresh sessions
18
- # ralph-loop-helper.sh external "<prompt>" [options] --tool <tool> # legacy alias
19
- # ralph-loop-helper.sh cancel
20
- # ralph-loop-helper.sh status [--all]
21
- # ralph-loop-helper.sh reanchor # Generate re-anchor prompt
22
- #
23
- # Reference: https://github.com/gmickel/gmickel-claude-marketplace/tree/main/plugins/flow-next
24
- # Original: https://ghuntley.com/ralph/
25
- #
26
- # Author: AI DevOps Framework
27
- # =============================================================================
28
-
29
- set -euo pipefail
30
-
31
- # =============================================================================
32
- # Constants
33
- # =============================================================================
34
-
35
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
36
- readonly SCRIPT_DIR
37
- readonly SCRIPT_NAME="ralph-loop-helper.sh"
38
-
39
- # Source shared loop infrastructure
40
- # shellcheck source=loop-common.sh
41
- if [[ -f "$SCRIPT_DIR/loop-common.sh" ]]; then
42
- source "$SCRIPT_DIR/loop-common.sh"
43
- fi
44
-
45
- # State directories
46
- readonly RALPH_STATE_DIR=".agent/loop-state"
47
- readonly RALPH_STATE_FILE="${RALPH_STATE_DIR}/ralph-loop.local.md"
48
-
49
- # Legacy state directory (for backward compatibility during migration)
50
- readonly RALPH_LEGACY_STATE_DIR=".claude"
51
- # shellcheck disable=SC2034 # Defined for documentation, used in status checks
52
- readonly RALPH_LEGACY_STATE_FILE="${RALPH_LEGACY_STATE_DIR}/ralph-loop.local.md"
53
-
54
- # Adaptive timing constants (evidence-based from PR #19 analysis)
55
- readonly RALPH_DELAY_BASE="${RALPH_DELAY_BASE:-2}"
56
- readonly RALPH_DELAY_MAX="${RALPH_DELAY_MAX:-30}"
57
- readonly RALPH_DELAY_MULTIPLIER="${RALPH_DELAY_MULTIPLIER:-1.5}"
58
-
59
- # v2 defaults
60
- readonly DEFAULT_MAX_ITERATIONS=50
61
- readonly DEFAULT_MAX_ATTEMPTS=5
62
-
63
- # Colors (fallback if loop-common.sh not loaded)
64
- readonly RED='\033[0;31m'
65
- readonly GREEN='\033[0;32m'
66
- readonly YELLOW='\033[1;33m'
67
- readonly BLUE='\033[0;34m'
68
- readonly CYAN='\033[0;36m'
69
- readonly BOLD='\033[1m'
70
- readonly NC='\033[0m'
71
-
72
- # =============================================================================
73
- # Helper Functions
74
- # =============================================================================
75
-
76
- print_error() {
77
- local message="$1"
78
- echo -e "${RED}[ralph] Error:${NC} ${message}" >&2
79
- return 0
80
- }
81
-
82
- print_success() {
83
- local message="$1"
84
- echo -e "${GREEN}[ralph]${NC} ${message}"
85
- return 0
86
- }
87
-
88
- print_warning() {
89
- local message="$1"
90
- echo -e "${YELLOW}[ralph]${NC} ${message}"
91
- return 0
92
- }
93
-
94
- print_info() {
95
- local message="$1"
96
- echo -e "${BLUE}[ralph]${NC} ${message}"
97
- return 0
98
- }
99
-
100
- print_step() {
101
- local message="$1"
102
- echo -e "${CYAN}[ralph]${NC} ${message}"
103
- return 0
104
- }
105
-
106
- show_help() {
107
- cat << 'EOF'
108
- Ralph Loop Helper v2 - Cross-Tool Iterative AI Development
109
-
110
- USAGE:
111
- ralph-loop-helper.sh <command> [options]
112
-
113
- COMMANDS:
114
- setup Create state file to start a Ralph loop (legacy mode)
115
- run Run external loop with fresh sessions per iteration (v2)
116
- external Alias for 'run' (backward compatibility)
117
- cancel Cancel the active Ralph loop
118
- status Show current loop status (use --all for all worktrees)
119
- reanchor Generate re-anchor prompt for current state
120
- check Check if output contains completion promise
121
- increment Increment iteration counter (legacy)
122
- help Show this help message
123
-
124
- RUN OPTIONS (v2 - Recommended):
125
- --tool <name> AI CLI tool (opencode, claude, aider)
126
- --max-iterations <n> Maximum iterations (default: 50)
127
- --completion-promise '<text>' Promise phrase to detect completion
128
- --max-attempts <n> Block task after N failed attempts (default: 5)
129
- --task-id <id> Task ID for tracking (auto-generated if omitted)
130
-
131
- SETUP OPTIONS (Legacy):
132
- --max-iterations <n> Maximum iterations (default: 0 = unlimited)
133
- --completion-promise '<text>' Promise phrase to detect completion
134
-
135
- STATUS OPTIONS:
136
- --all, -a Show loops across all git worktrees
137
-
138
- EXAMPLES:
139
- # v2: Fresh sessions per iteration (recommended)
140
- ralph-loop-helper.sh run "Build a REST API" --tool opencode --max-iterations 20
141
-
142
- # Legacy: Same-session loop (for tools with hook support)
143
- ralph-loop-helper.sh setup "Build a REST API" --max-iterations 20
144
-
145
- # Check status
146
- ralph-loop-helper.sh status --all
147
-
148
- # Generate re-anchor prompt
149
- ralph-loop-helper.sh reanchor
150
-
151
- v2 ARCHITECTURE:
152
- - Fresh context per iteration (no transcript accumulation)
153
- - Re-anchor from files at start of every iteration
154
- - Receipt-based verification (proof of work)
155
- - Memory integration (stores learnings across sessions)
156
- - Auto-block after N failed attempts
157
-
158
- COMPLETION:
159
- To signal completion, the AI must output: <promise>YOUR_PHRASE</promise>
160
- The promise must be TRUE - do not output false promises to escape.
161
-
162
- ENVIRONMENT VARIABLES:
163
- RALPH_DELAY_BASE Initial delay between iterations (default: 2s)
164
- RALPH_DELAY_MAX Maximum delay between iterations (default: 30s)
165
- RALPH_DELAY_MULTIPLIER Backoff multiplier (default: 1.5)
166
-
167
- LEARN MORE:
168
- Original technique: https://ghuntley.com/ralph/
169
- flow-next reference: https://github.com/gmickel/gmickel-claude-marketplace
170
- Documentation: ~/.aidevops/agents/workflows/ralph-loop.md
171
- EOF
172
- return 0
173
- }
174
-
175
- # =============================================================================
176
- # v2 Functions (Fresh Context Architecture)
177
- # =============================================================================
178
-
179
- # Run v2 loop with fresh sessions per iteration
180
- # Arguments:
181
- # $@ - Prompt and options
182
- # Returns: 0 on completion, 1 on error/max iterations
183
- run_v2_loop() {
184
- local prompt=""
185
- local max_iterations=$DEFAULT_MAX_ITERATIONS
186
- local completion_promise="TASK_COMPLETE"
187
- local tool="opencode"
188
- local max_attempts=$DEFAULT_MAX_ATTEMPTS
189
- local task_id=""
190
- local prompt_parts=()
191
-
192
- # Parse arguments
193
- while [[ $# -gt 0 ]]; do
194
- case $1 in
195
- --max-iterations)
196
- max_iterations="$2"
197
- shift 2
198
- ;;
199
- --completion-promise)
200
- completion_promise="$2"
201
- shift 2
202
- ;;
203
- --tool)
204
- tool="$2"
205
- shift 2
206
- ;;
207
- --max-attempts)
208
- max_attempts="$2"
209
- shift 2
210
- ;;
211
- --task-id)
212
- task_id="$2"
213
- shift 2
214
- ;;
215
- *)
216
- prompt_parts+=("$1")
217
- shift
218
- ;;
219
- esac
220
- done
221
-
222
- prompt="${prompt_parts[*]}"
223
-
224
- if [[ -z "$prompt" ]]; then
225
- print_error "No prompt provided"
226
- echo "Usage: $SCRIPT_NAME run \"<prompt>\" --tool <tool> [options]"
227
- return 1
228
- fi
229
-
230
- # Validate tool
231
- if ! command -v "$tool" &>/dev/null; then
232
- print_error "Tool '$tool' not found. Install it or use --tool to specify another."
233
- print_info "Available tools: opencode, claude, aider"
234
- return 1
235
- fi
236
-
237
- # Check for jq (required for v2)
238
- if ! command -v jq &>/dev/null; then
239
- print_error "jq is required for v2 loops. Install with: brew install jq"
240
- return 1
241
- fi
242
-
243
- # Initialize state using shared infrastructure
244
- if type loop_create_state &>/dev/null; then
245
- loop_create_state "ralph" "$prompt" "$max_iterations" "$completion_promise" "$task_id"
246
- else
247
- print_warning "loop-common.sh not loaded, using basic state"
248
- mkdir -p "$RALPH_STATE_DIR"
249
- fi
250
-
251
- print_info "Starting Ralph loop v2 with $tool"
252
- print_info "Architecture: Fresh context per iteration"
253
- echo ""
254
- echo "Prompt: $prompt"
255
- echo "Max iterations: $max_iterations"
256
- echo "Completion promise: $completion_promise"
257
- echo "Max attempts before block: $max_attempts"
258
- echo ""
259
-
260
- local iteration=1
261
- local output_file
262
- output_file=$(mktemp)
263
- trap 'rm -f "$output_file"' EXIT
264
-
265
- while [[ $iteration -le $max_iterations ]]; do
266
- print_step "=== Iteration $iteration/$max_iterations ==="
267
-
268
- # Update state
269
- if type loop_set_state &>/dev/null; then
270
- loop_set_state ".iteration" "$iteration"
271
- loop_set_state ".last_iteration_at" "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
272
- fi
273
-
274
- # Generate re-anchor prompt (key v2 feature)
275
- local reanchor_prompt=""
276
- if type loop_generate_reanchor &>/dev/null; then
277
- print_info "Generating re-anchor context..."
278
- reanchor_prompt=$(loop_generate_reanchor "$prompt")
279
- else
280
- # Fallback: basic prompt with iteration
281
- reanchor_prompt="[Ralph iteration $iteration/$max_iterations]
282
-
283
- $prompt
284
-
285
- To complete, output: <promise>$completion_promise</promise> (ONLY when TRUE)"
286
- fi
287
-
288
- # Run tool with fresh session
289
- local exit_code=0
290
- print_info "Spawning fresh $tool session..."
291
-
292
- case "$tool" in
293
- opencode)
294
- echo "$reanchor_prompt" | opencode --print > "$output_file" 2>&1 || exit_code=$?
295
- ;;
296
- claude)
297
- echo "$reanchor_prompt" | claude --print > "$output_file" 2>&1 || exit_code=$?
298
- ;;
299
- aider)
300
- aider --yes --message "$reanchor_prompt" > "$output_file" 2>&1 || exit_code=$?
301
- ;;
302
- *)
303
- print_error "Unknown tool: $tool"
304
- return 1
305
- ;;
306
- esac
307
-
308
- if [[ $exit_code -ne 0 ]]; then
309
- print_warning "Tool exited with code $exit_code (continuing)"
310
- fi
311
-
312
- # Check for completion promise
313
- if grep -q "<promise>$completion_promise</promise>" "$output_file" 2>/dev/null; then
314
- print_success "Completion promise detected!"
315
-
316
- # Create success receipt
317
- if type loop_create_receipt &>/dev/null; then
318
- loop_create_receipt "task" "success" '{"promise_fulfilled": true}'
319
- fi
320
-
321
- # Store success in memory
322
- if type loop_store_success &>/dev/null; then
323
- loop_store_success "Task completed after $iteration iterations"
324
- fi
325
-
326
- print_success "Ralph loop completed successfully after $iteration iterations"
327
- return 0
328
- fi
329
-
330
- # Track attempt and check for blocking
331
- if type loop_track_attempt &>/dev/null; then
332
- local attempts
333
- attempts=$(loop_track_attempt)
334
-
335
- if type loop_should_block &>/dev/null && loop_should_block "$max_attempts"; then
336
- print_error "Task blocked after $attempts failed attempts"
337
-
338
- if type loop_block_task &>/dev/null; then
339
- loop_block_task "Max attempts ($max_attempts) reached without completion"
340
- fi
341
-
342
- if type loop_store_failure &>/dev/null; then
343
- loop_store_failure "Task blocked" "Exceeded $max_attempts attempts"
344
- fi
345
-
346
- return 1
347
- fi
348
- fi
349
-
350
- # Create retry receipt
351
- if type loop_create_receipt &>/dev/null; then
352
- loop_create_receipt "task" "retry" "{\"iteration\": $iteration, \"exit_code\": $exit_code}"
353
- fi
354
-
355
- iteration=$((iteration + 1))
356
-
357
- # Adaptive delay
358
- local delay
359
- delay=$(calculate_delay "$iteration")
360
- print_info "Waiting ${delay}s before next iteration..."
361
- sleep "$delay"
362
- done
363
-
364
- print_warning "Max iterations ($max_iterations) reached without completion"
365
-
366
- if type loop_block_task &>/dev/null; then
367
- loop_block_task "Max iterations reached"
368
- fi
369
-
370
- return 1
371
- }
372
-
373
- # Calculate adaptive delay with exponential backoff
374
- # Arguments:
375
- # $1 - iteration number
376
- # Returns: 0
377
- # Output: delay in seconds
378
- calculate_delay() {
379
- local iteration="$1"
380
- local delay
381
-
382
- if command -v bc &>/dev/null; then
383
- delay=$(echo "scale=0; $RALPH_DELAY_BASE * ($RALPH_DELAY_MULTIPLIER ^ ($iteration - 1))" | bc 2>/dev/null || echo "$RALPH_DELAY_BASE")
384
- if [[ $(echo "$delay > $RALPH_DELAY_MAX" | bc 2>/dev/null || echo "0") -eq 1 ]]; then
385
- delay=$RALPH_DELAY_MAX
386
- fi
387
- else
388
- delay=$RALPH_DELAY_BASE
389
- local i=1
390
- while [[ $i -lt $iteration ]] && [[ $delay -lt $RALPH_DELAY_MAX ]]; do
391
- delay=$((delay * 2))
392
- ((i++))
393
- done
394
- [[ $delay -gt $RALPH_DELAY_MAX ]] && delay=$RALPH_DELAY_MAX
395
- fi
396
-
397
- echo "$delay"
398
- return 0
399
- }
400
-
401
- # =============================================================================
402
- # Legacy Functions (Backward Compatibility)
403
- # =============================================================================
404
-
405
- # Setup a new Ralph loop (legacy mode - same session)
406
- setup_loop() {
407
- local prompt=""
408
- local max_iterations=0
409
- local completion_promise="null"
410
- local prompt_parts=()
411
-
412
- while [[ $# -gt 0 ]]; do
413
- case $1 in
414
- --max-iterations)
415
- max_iterations="$2"
416
- shift 2
417
- ;;
418
- --completion-promise)
419
- completion_promise="$2"
420
- shift 2
421
- ;;
422
- *)
423
- prompt_parts+=("$1")
424
- shift
425
- ;;
426
- esac
427
- done
428
-
429
- prompt="${prompt_parts[*]}"
430
-
431
- if [[ -z "$prompt" ]]; then
432
- print_error "No prompt provided"
433
- echo "Usage: $SCRIPT_NAME setup \"<prompt>\" [--max-iterations N] [--completion-promise \"TEXT\"]"
434
- return 1
435
- fi
436
-
437
- mkdir -p "$RALPH_STATE_DIR"
438
-
439
- local completion_promise_yaml
440
- if [[ -n "$completion_promise" ]] && [[ "$completion_promise" != "null" ]]; then
441
- completion_promise_yaml="\"$completion_promise\""
442
- else
443
- completion_promise_yaml="null"
444
- fi
445
-
446
- cat > "$RALPH_STATE_FILE" << EOF
447
- ---
448
- active: true
449
- iteration: 1
450
- max_iterations: $max_iterations
451
- completion_promise: $completion_promise_yaml
452
- started_at: "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
453
- mode: legacy
454
- ---
455
-
456
- $prompt
457
- EOF
458
-
459
- check_other_loops
460
-
461
- echo ""
462
- print_success "Ralph loop activated (legacy mode)"
463
- print_warning "Note: Consider using 'run' command for v2 fresh-context architecture"
464
- echo ""
465
- echo "Iteration: 1"
466
- echo "Max iterations: $(if [[ $max_iterations -gt 0 ]]; then echo "$max_iterations"; else echo "unlimited"; fi)"
467
- echo "Completion promise: $(if [[ "$completion_promise" != "null" ]]; then echo "$completion_promise"; else echo "none"; fi)"
468
- echo ""
469
- echo "State file: $RALPH_STATE_FILE"
470
-
471
- if [[ "$completion_promise" != "null" ]]; then
472
- echo ""
473
- echo "================================================================"
474
- echo "To complete this loop, output: <promise>$completion_promise</promise>"
475
- echo "================================================================"
476
- fi
477
-
478
- echo ""
479
- echo "$prompt"
480
-
481
- return 0
482
- }
483
-
484
- # Cancel the active Ralph loop
485
- cancel_loop() {
486
- local cancelled=false
487
-
488
- # Cancel v2 state
489
- if type loop_cancel &>/dev/null && [[ -f "${RALPH_STATE_DIR}/loop-state.json" ]]; then
490
- loop_cancel
491
- cancelled=true
492
- fi
493
-
494
- # Cancel legacy state
495
- if [[ -f "$RALPH_STATE_FILE" ]]; then
496
- local iteration
497
- iteration=$(grep '^iteration:' "$RALPH_STATE_FILE" | sed 's/iteration: *//' || echo "unknown")
498
- rm "$RALPH_STATE_FILE"
499
- print_success "Cancelled legacy Ralph loop (was at iteration $iteration)"
500
- cancelled=true
501
- fi
502
-
503
- if [[ "$cancelled" == "false" ]]; then
504
- print_warning "No active Ralph loop found"
505
- fi
506
-
507
- return 0
508
- }
509
-
510
- # Show status
511
- show_status() {
512
- local show_all=false
513
-
514
- while [[ $# -gt 0 ]]; do
515
- case $1 in
516
- --all|-a)
517
- show_all=true
518
- shift
519
- ;;
520
- *)
521
- shift
522
- ;;
523
- esac
524
- done
525
-
526
- if [[ "$show_all" == "true" ]]; then
527
- show_status_all
528
- return 0
529
- fi
530
-
531
- # Check v2 state first
532
- if type loop_show_status &>/dev/null && [[ -f "${RALPH_STATE_DIR}/loop-state.json" ]]; then
533
- echo "=== Ralph Loop v2 Status ==="
534
- loop_show_status
535
- return 0
536
- fi
537
-
538
- # Fall back to legacy state
539
- if [[ -f "$RALPH_STATE_FILE" ]]; then
540
- echo "=== Ralph Loop Status (Legacy) ==="
541
- echo ""
542
-
543
- local frontmatter
544
- frontmatter=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$RALPH_STATE_FILE")
545
-
546
- local iteration max_iterations completion_promise started_at
547
- iteration=$(echo "$frontmatter" | grep '^iteration:' | sed 's/iteration: *//')
548
- max_iterations=$(echo "$frontmatter" | grep '^max_iterations:' | sed 's/max_iterations: *//')
549
- completion_promise=$(echo "$frontmatter" | grep '^completion_promise:' | sed 's/completion_promise: *//' | sed 's/^"\(.*\)"$/\1/')
550
- started_at=$(echo "$frontmatter" | grep '^started_at:' | sed 's/started_at: *//' | sed 's/^"\(.*\)"$/\1/')
551
-
552
- echo "Mode: legacy (same-session)"
553
- echo "Active: yes"
554
- echo "Iteration: $iteration"
555
- echo "Max iterations: $(if [[ "$max_iterations" == "0" ]]; then echo "unlimited"; else echo "$max_iterations"; fi)"
556
- echo "Completion promise: $(if [[ "$completion_promise" == "null" ]]; then echo "none"; else echo "$completion_promise"; fi)"
557
- echo "Started: $started_at"
558
- echo ""
559
- print_warning "Consider migrating to v2: ralph-loop-helper.sh run ..."
560
- return 0
561
- fi
562
-
563
- echo "No active Ralph loop in current directory."
564
- echo ""
565
- echo "Tip: Use 'status --all' to check all worktrees"
566
- return 0
567
- }
568
-
569
- # Show status across all worktrees
570
- show_status_all() {
571
- echo "Ralph Loop Status - All Worktrees"
572
- echo "=================================="
573
- echo ""
574
-
575
- if ! git rev-parse --git-dir &>/dev/null; then
576
- print_error "Not in a git repository"
577
- return 1
578
- fi
579
-
580
- local found_any=false
581
- local current_dir
582
- current_dir=$(pwd)
583
-
584
- while IFS= read -r line; do
585
- if [[ "$line" =~ ^worktree\ (.+)$ ]]; then
586
- local worktree_path="${BASH_REMATCH[1]}"
587
-
588
- # Check for v2 state (new location first, then legacy)
589
- local v2_state="$worktree_path/.agent/loop-state/loop-state.json"
590
- local v2_state_legacy="$worktree_path/.claude/loop-state.json"
591
- local legacy_state="$worktree_path/.agent/loop-state/ralph-loop.local.md"
592
- local legacy_state_old="$worktree_path/.claude/ralph-loop.local.md"
593
-
594
- # Check any of the state file locations
595
- if [[ -f "$v2_state" ]] || [[ -f "$v2_state_legacy" ]] || [[ -f "$legacy_state" ]] || [[ -f "$legacy_state_old" ]]; then
596
- found_any=true
597
-
598
- local branch
599
- branch=$(git -C "$worktree_path" branch --show-current 2>/dev/null || echo "unknown")
600
-
601
- local marker=""
602
- if [[ "$worktree_path" == "$current_dir" ]]; then
603
- marker=" ${GREEN}(current)${NC}"
604
- fi
605
-
606
- echo -e "${BOLD}$branch${NC}$marker"
607
- echo " Path: $worktree_path"
608
-
609
- # Determine which state file to read (prefer new location)
610
- local active_v2_state=""
611
- local active_legacy_state=""
612
- [[ -f "$v2_state" ]] && active_v2_state="$v2_state"
613
- [[ -z "$active_v2_state" && -f "$v2_state_legacy" ]] && active_v2_state="$v2_state_legacy"
614
- [[ -f "$legacy_state" ]] && active_legacy_state="$legacy_state"
615
- [[ -z "$active_legacy_state" && -f "$legacy_state_old" ]] && active_legacy_state="$legacy_state_old"
616
-
617
- if [[ -n "$active_v2_state" ]]; then
618
- local iteration max_iterations
619
- iteration=$(jq -r '.iteration // 0' "$active_v2_state" 2>/dev/null || echo "?")
620
- max_iterations=$(jq -r '.max_iterations // 0' "$active_v2_state" 2>/dev/null || echo "?")
621
- echo " Mode: v2 (fresh context)"
622
- echo " Iteration: $iteration / $max_iterations"
623
- elif [[ -n "$active_legacy_state" ]]; then
624
- local iteration max_iterations
625
- iteration=$(grep '^iteration:' "$active_legacy_state" | sed 's/iteration: *//')
626
- max_iterations=$(grep '^max_iterations:' "$active_legacy_state" | sed 's/max_iterations: *//')
627
- echo " Mode: legacy (same session)"
628
- echo " Iteration: $iteration / $(if [[ "$max_iterations" == "0" ]]; then echo "unlimited"; else echo "$max_iterations"; fi)"
629
- fi
630
- echo ""
631
- fi
632
- fi
633
- done < <(git worktree list --porcelain)
634
-
635
- if [[ "$found_any" == "false" ]]; then
636
- echo -e "${GREEN}No active Ralph loops in any worktree${NC}"
637
- fi
638
-
639
- return 0
640
- }
641
-
642
- # Check for other active loops
643
- check_other_loops() {
644
- if ! git rev-parse --git-dir &>/dev/null; then
645
- return 0
646
- fi
647
-
648
- local current_dir
649
- current_dir=$(pwd)
650
- local other_loops=()
651
-
652
- while IFS= read -r line; do
653
- if [[ "$line" =~ ^worktree\ (.+)$ ]]; then
654
- local worktree_path="${BASH_REMATCH[1]}"
655
-
656
- if [[ "$worktree_path" == "$current_dir" ]]; then
657
- continue
658
- fi
659
-
660
- # Check all possible state file locations (new and legacy)
661
- local v2_state="$worktree_path/.agent/loop-state/loop-state.json"
662
- local v2_state_legacy="$worktree_path/.claude/loop-state.json"
663
- local legacy_state="$worktree_path/.agent/loop-state/ralph-loop.local.md"
664
- local legacy_state_old="$worktree_path/.claude/ralph-loop.local.md"
665
-
666
- if [[ -f "$v2_state" ]] || [[ -f "$v2_state_legacy" ]] || [[ -f "$legacy_state" ]] || [[ -f "$legacy_state_old" ]]; then
667
- local branch
668
- branch=$(git -C "$worktree_path" branch --show-current 2>/dev/null || echo "unknown")
669
- local iteration="?"
670
-
671
- if [[ -f "$v2_state" ]]; then
672
- iteration=$(jq -r '.iteration // 0' "$v2_state" 2>/dev/null || echo "?")
673
- elif [[ -f "$v2_state_legacy" ]]; then
674
- iteration=$(jq -r '.iteration // 0' "$v2_state_legacy" 2>/dev/null || echo "?")
675
- elif [[ -f "$legacy_state" ]]; then
676
- iteration=$(grep '^iteration:' "$legacy_state" | sed 's/iteration: *//')
677
- elif [[ -f "$legacy_state_old" ]]; then
678
- iteration=$(grep '^iteration:' "$legacy_state_old" | sed 's/iteration: *//')
679
- fi
680
-
681
- other_loops+=("$branch (iteration $iteration)")
682
- fi
683
- fi
684
- done < <(git worktree list --porcelain)
685
-
686
- if [[ ${#other_loops[@]} -gt 0 ]]; then
687
- echo ""
688
- print_warning "Other active Ralph loops detected:"
689
- for loop in "${other_loops[@]}"; do
690
- echo " - $loop"
691
- done
692
- echo ""
693
- fi
694
-
695
- return 0
696
- }
697
-
698
- # Generate re-anchor prompt
699
- generate_reanchor() {
700
- if type loop_generate_reanchor &>/dev/null; then
701
- local keywords="${1:-}"
702
- loop_generate_reanchor "$keywords"
703
- else
704
- print_error "loop-common.sh not loaded"
705
- return 1
706
- fi
707
- }
708
-
709
- # Check completion (legacy)
710
- check_completion() {
711
- local output="$1"
712
- local completion_promise="${2:-}"
713
-
714
- if [[ -z "$completion_promise" ]] || [[ "$completion_promise" == "null" ]]; then
715
- echo "NO_PROMISE"
716
- return 0
717
- fi
718
-
719
- if grep -q "<promise>$completion_promise</promise>" <<< "$output" 2>/dev/null; then
720
- echo "COMPLETE"
721
- return 0
722
- fi
723
-
724
- echo "NOT_COMPLETE"
725
- return 0
726
- }
727
-
728
- # Increment iteration (legacy)
729
- increment_iteration() {
730
- if [[ ! -f "$RALPH_STATE_FILE" ]]; then
731
- print_error "No active Ralph loop to increment"
732
- return 1
733
- fi
734
-
735
- local current_iteration
736
- current_iteration=$(grep '^iteration:' "$RALPH_STATE_FILE" | sed 's/iteration: *//')
737
-
738
- if [[ ! "$current_iteration" =~ ^[0-9]+$ ]]; then
739
- print_error "State file corrupted"
740
- return 1
741
- fi
742
-
743
- local next_iteration=$((current_iteration + 1))
744
-
745
- local temp_file
746
- temp_file=$(mktemp)
747
- sed "s/^iteration: .*/iteration: $next_iteration/" "$RALPH_STATE_FILE" > "$temp_file"
748
- mv "$temp_file" "$RALPH_STATE_FILE"
749
-
750
- echo "$next_iteration"
751
- return 0
752
- }
753
-
754
- # Get prompt (legacy)
755
- get_prompt() {
756
- if [[ ! -f "$RALPH_STATE_FILE" ]]; then
757
- print_error "No active Ralph loop"
758
- return 1
759
- fi
760
-
761
- awk '/^---$/{i++; next} i>=2' "$RALPH_STATE_FILE"
762
- return 0
763
- }
764
-
765
- # Get completion promise (legacy)
766
- get_completion_promise() {
767
- if [[ ! -f "$RALPH_STATE_FILE" ]]; then
768
- echo "null"
769
- return 0
770
- fi
771
-
772
- local frontmatter
773
- frontmatter=$(sed -n '/^---$/,/^---$/{ /^---$/d; p; }' "$RALPH_STATE_FILE")
774
- echo "$frontmatter" | grep '^completion_promise:' | sed 's/completion_promise: *//' | sed 's/^"\(.*\)"$/\1/'
775
- return 0
776
- }
777
-
778
- # =============================================================================
779
- # Main
780
- # =============================================================================
781
-
782
- main() {
783
- local command="${1:-help}"
784
- shift || true
785
-
786
- case "$command" in
787
- run)
788
- run_v2_loop "$@"
789
- ;;
790
- external)
791
- # Legacy alias for 'run'
792
- run_v2_loop "$@"
793
- ;;
794
- setup)
795
- setup_loop "$@"
796
- ;;
797
- cancel)
798
- cancel_loop
799
- ;;
800
- status)
801
- show_status "$@"
802
- ;;
803
- reanchor)
804
- generate_reanchor "$@"
805
- ;;
806
- check|check-completion)
807
- if [[ $# -lt 1 ]]; then
808
- print_error "check requires output text as argument"
809
- return 1
810
- fi
811
- local output="$1"
812
- local promise="${2:-$(get_completion_promise)}"
813
- check_completion "$output" "$promise"
814
- ;;
815
- increment)
816
- increment_iteration
817
- ;;
818
- get-prompt)
819
- get_prompt
820
- ;;
821
- get-completion-promise)
822
- get_completion_promise
823
- ;;
824
- help|--help|-h)
825
- show_help
826
- ;;
827
- *)
828
- print_error "Unknown command: $command"
829
- echo ""
830
- show_help
831
- return 1
832
- ;;
833
- esac
834
- }
835
-
836
- main "$@"