oh-my-claude-sisyphus 3.3.10 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/README.md +3 -3
  2. package/agents/explore-high.md +195 -0
  3. package/agents/qa-tester-high.md +141 -0
  4. package/agents/templates/README.md +110 -0
  5. package/agents/templates/base-agent.md +54 -0
  6. package/agents/templates/tier-instructions.md +94 -0
  7. package/commands/ecomode.md +60 -0
  8. package/commands/help.md +1 -1
  9. package/commands/mcp-setup.md +7 -6
  10. package/commands/ralplan.md +8 -1
  11. package/commands/ultrapilot.md +158 -0
  12. package/commands/ultrawork.md +1 -0
  13. package/dist/__tests__/delegation-enforcer-integration.test.d.ts +6 -0
  14. package/dist/__tests__/delegation-enforcer-integration.test.d.ts.map +1 -0
  15. package/dist/__tests__/delegation-enforcer-integration.test.js +136 -0
  16. package/dist/__tests__/delegation-enforcer-integration.test.js.map +1 -0
  17. package/dist/__tests__/delegation-enforcer.test.d.ts +5 -0
  18. package/dist/__tests__/delegation-enforcer.test.d.ts.map +1 -0
  19. package/dist/__tests__/delegation-enforcer.test.js +208 -0
  20. package/dist/__tests__/delegation-enforcer.test.js.map +1 -0
  21. package/dist/__tests__/hooks.test.js +2 -2
  22. package/dist/__tests__/hooks.test.js.map +1 -1
  23. package/dist/__tests__/installer.test.js +4 -6
  24. package/dist/__tests__/installer.test.js.map +1 -1
  25. package/dist/__tests__/ralph-prd.test.js +1 -1
  26. package/dist/__tests__/ralph-prd.test.js.map +1 -1
  27. package/dist/__tests__/ralph-progress.test.js +1 -1
  28. package/dist/__tests__/ralph-progress.test.js.map +1 -1
  29. package/dist/__tests__/skills.test.js +31 -24
  30. package/dist/__tests__/skills.test.js.map +1 -1
  31. package/dist/agents/analyst.d.ts.map +1 -1
  32. package/dist/agents/analyst.js +1 -0
  33. package/dist/agents/analyst.js.map +1 -1
  34. package/dist/agents/architect.d.ts.map +1 -1
  35. package/dist/agents/architect.js +1 -0
  36. package/dist/agents/architect.js.map +1 -1
  37. package/dist/agents/critic.d.ts.map +1 -1
  38. package/dist/agents/critic.js +1 -0
  39. package/dist/agents/critic.js.map +1 -1
  40. package/dist/agents/definitions.d.ts +5 -1
  41. package/dist/agents/definitions.d.ts.map +1 -1
  42. package/dist/agents/definitions.js +53 -155
  43. package/dist/agents/definitions.js.map +1 -1
  44. package/dist/agents/designer.d.ts.map +1 -1
  45. package/dist/agents/designer.js +1 -0
  46. package/dist/agents/designer.js.map +1 -1
  47. package/dist/agents/executor.d.ts.map +1 -1
  48. package/dist/agents/executor.js +1 -0
  49. package/dist/agents/executor.js.map +1 -1
  50. package/dist/agents/explore.d.ts.map +1 -1
  51. package/dist/agents/explore.js +1 -0
  52. package/dist/agents/explore.js.map +1 -1
  53. package/dist/agents/planner.d.ts.map +1 -1
  54. package/dist/agents/planner.js +1 -0
  55. package/dist/agents/planner.js.map +1 -1
  56. package/dist/agents/qa-tester.d.ts.map +1 -1
  57. package/dist/agents/qa-tester.js +1 -0
  58. package/dist/agents/qa-tester.js.map +1 -1
  59. package/dist/agents/researcher.d.ts.map +1 -1
  60. package/dist/agents/researcher.js +1 -0
  61. package/dist/agents/researcher.js.map +1 -1
  62. package/dist/agents/scientist.d.ts.map +1 -1
  63. package/dist/agents/scientist.js +1 -0
  64. package/dist/agents/scientist.js.map +1 -1
  65. package/dist/agents/types.d.ts +2 -0
  66. package/dist/agents/types.d.ts.map +1 -1
  67. package/dist/agents/types.js.map +1 -1
  68. package/dist/agents/vision.d.ts.map +1 -1
  69. package/dist/agents/vision.js +1 -0
  70. package/dist/agents/vision.js.map +1 -1
  71. package/dist/agents/writer.d.ts.map +1 -1
  72. package/dist/agents/writer.js +1 -0
  73. package/dist/agents/writer.js.map +1 -1
  74. package/dist/cli/index.js +0 -3
  75. package/dist/cli/index.js.map +1 -1
  76. package/dist/config/loader.d.ts.map +1 -1
  77. package/dist/config/loader.js +1 -6
  78. package/dist/config/loader.js.map +1 -1
  79. package/dist/features/delegation-enforcer.d.ts +71 -0
  80. package/dist/features/delegation-enforcer.d.ts.map +1 -0
  81. package/dist/features/delegation-enforcer.js +128 -0
  82. package/dist/features/delegation-enforcer.js.map +1 -0
  83. package/dist/features/index.d.ts +3 -0
  84. package/dist/features/index.d.ts.map +1 -1
  85. package/dist/features/index.js +18 -0
  86. package/dist/features/index.js.map +1 -1
  87. package/dist/features/state-manager/index.d.ts +100 -0
  88. package/dist/features/state-manager/index.d.ts.map +1 -0
  89. package/dist/features/state-manager/index.js +407 -0
  90. package/dist/features/state-manager/index.js.map +1 -0
  91. package/dist/features/state-manager/types.d.ts +147 -0
  92. package/dist/features/state-manager/types.d.ts.map +1 -0
  93. package/dist/features/state-manager/types.js +30 -0
  94. package/dist/features/state-manager/types.js.map +1 -0
  95. package/dist/features/task-decomposer/index.d.ts +33 -0
  96. package/dist/features/task-decomposer/index.d.ts.map +1 -0
  97. package/dist/features/task-decomposer/index.js +698 -0
  98. package/dist/features/task-decomposer/index.js.map +1 -0
  99. package/dist/features/task-decomposer/types.d.ts +133 -0
  100. package/dist/features/task-decomposer/types.d.ts.map +1 -0
  101. package/dist/features/task-decomposer/types.js +8 -0
  102. package/dist/features/task-decomposer/types.js.map +1 -0
  103. package/dist/features/verification/example.d.ts +49 -0
  104. package/dist/features/verification/example.d.ts.map +1 -0
  105. package/dist/features/verification/example.js +235 -0
  106. package/dist/features/verification/example.js.map +1 -0
  107. package/dist/features/verification/index.d.ts +97 -0
  108. package/dist/features/verification/index.d.ts.map +1 -0
  109. package/dist/features/verification/index.js +439 -0
  110. package/dist/features/verification/index.js.map +1 -0
  111. package/dist/features/verification/types.d.ts +142 -0
  112. package/dist/features/verification/types.d.ts.map +1 -0
  113. package/dist/features/verification/types.js +7 -0
  114. package/dist/features/verification/types.js.map +1 -0
  115. package/dist/hooks/agent-usage-reminder/constants.d.ts.map +1 -1
  116. package/dist/hooks/agent-usage-reminder/constants.js +0 -1
  117. package/dist/hooks/agent-usage-reminder/constants.js.map +1 -1
  118. package/dist/hooks/autopilot/__tests__/cancel.test.js +4 -4
  119. package/dist/hooks/autopilot/__tests__/cancel.test.js.map +1 -1
  120. package/dist/hooks/autopilot/__tests__/summary.test.js +1 -1
  121. package/dist/hooks/autopilot/__tests__/summary.test.js.map +1 -1
  122. package/dist/hooks/autopilot/__tests__/transition.test.js +1 -2
  123. package/dist/hooks/autopilot/__tests__/transition.test.js.map +1 -1
  124. package/dist/hooks/autopilot/cancel.js +2 -2
  125. package/dist/hooks/autopilot/cancel.js.map +1 -1
  126. package/dist/hooks/autopilot/enforcement.d.ts +16 -2
  127. package/dist/hooks/autopilot/enforcement.d.ts.map +1 -1
  128. package/dist/hooks/autopilot/enforcement.js +78 -4
  129. package/dist/hooks/autopilot/enforcement.js.map +1 -1
  130. package/dist/hooks/autopilot/index.d.ts +3 -6
  131. package/dist/hooks/autopilot/index.d.ts.map +1 -1
  132. package/dist/hooks/autopilot/index.js +6 -12
  133. package/dist/hooks/autopilot/index.js.map +1 -1
  134. package/dist/hooks/autopilot/state.d.ts +36 -2
  135. package/dist/hooks/autopilot/state.d.ts.map +1 -1
  136. package/dist/hooks/autopilot/state.js +216 -2
  137. package/dist/hooks/autopilot/state.js.map +1 -1
  138. package/dist/hooks/autopilot/validation.d.ts +23 -2
  139. package/dist/hooks/autopilot/validation.d.ts.map +1 -1
  140. package/dist/hooks/autopilot/validation.js +158 -1
  141. package/dist/hooks/autopilot/validation.js.map +1 -1
  142. package/dist/hooks/bridge.js +3 -3
  143. package/dist/hooks/bridge.js.map +1 -1
  144. package/dist/hooks/index.d.ts +5 -9
  145. package/dist/hooks/index.d.ts.map +1 -1
  146. package/dist/hooks/index.js +31 -21
  147. package/dist/hooks/index.js.map +1 -1
  148. package/dist/hooks/learner/promotion.js +1 -1
  149. package/dist/hooks/learner/promotion.js.map +1 -1
  150. package/dist/hooks/persistent-mode/index.d.ts.map +1 -1
  151. package/dist/hooks/persistent-mode/index.js +2 -3
  152. package/dist/hooks/persistent-mode/index.js.map +1 -1
  153. package/dist/hooks/ralph/index.d.ts +11 -0
  154. package/dist/hooks/ralph/index.d.ts.map +1 -0
  155. package/dist/hooks/ralph/index.js +53 -0
  156. package/dist/hooks/ralph/index.js.map +1 -0
  157. package/dist/hooks/ralph/loop.d.ts +116 -0
  158. package/dist/hooks/ralph/loop.d.ts.map +1 -0
  159. package/dist/hooks/ralph/loop.js +322 -0
  160. package/dist/hooks/ralph/loop.js.map +1 -0
  161. package/dist/hooks/ralph/prd.d.ts +130 -0
  162. package/dist/hooks/ralph/prd.d.ts.map +1 -0
  163. package/dist/hooks/ralph/prd.js +310 -0
  164. package/dist/hooks/ralph/prd.js.map +1 -0
  165. package/dist/hooks/ralph/progress.d.ts +102 -0
  166. package/dist/hooks/ralph/progress.d.ts.map +1 -0
  167. package/dist/hooks/ralph/progress.js +408 -0
  168. package/dist/hooks/ralph/progress.js.map +1 -0
  169. package/dist/hooks/ralph/verifier.d.ts +72 -0
  170. package/dist/hooks/ralph/verifier.d.ts.map +1 -0
  171. package/dist/hooks/ralph/verifier.js +223 -0
  172. package/dist/hooks/ralph/verifier.js.map +1 -0
  173. package/dist/hooks/recovery/constants.d.ts +114 -0
  174. package/dist/hooks/recovery/constants.d.ts.map +1 -0
  175. package/dist/hooks/recovery/constants.js +227 -0
  176. package/dist/hooks/recovery/constants.js.map +1 -0
  177. package/dist/hooks/recovery/context-window.d.ts +24 -0
  178. package/dist/hooks/recovery/context-window.d.ts.map +1 -0
  179. package/dist/hooks/recovery/context-window.js +321 -0
  180. package/dist/hooks/recovery/context-window.js.map +1 -0
  181. package/dist/hooks/recovery/edit-error.d.ts +24 -0
  182. package/dist/hooks/recovery/edit-error.d.ts.map +1 -0
  183. package/dist/hooks/recovery/edit-error.js +56 -0
  184. package/dist/hooks/recovery/edit-error.js.map +1 -0
  185. package/dist/hooks/recovery/index.d.ts +102 -0
  186. package/dist/hooks/recovery/index.d.ts.map +1 -0
  187. package/dist/hooks/recovery/index.js +166 -0
  188. package/dist/hooks/recovery/index.js.map +1 -0
  189. package/dist/hooks/recovery/session-recovery.d.ts +24 -0
  190. package/dist/hooks/recovery/session-recovery.d.ts.map +1 -0
  191. package/dist/hooks/recovery/session-recovery.js +281 -0
  192. package/dist/hooks/recovery/session-recovery.js.map +1 -0
  193. package/dist/hooks/recovery/storage.d.ts +75 -0
  194. package/dist/hooks/recovery/storage.d.ts.map +1 -0
  195. package/dist/hooks/recovery/storage.js +382 -0
  196. package/dist/hooks/recovery/storage.js.map +1 -0
  197. package/dist/hooks/recovery/types.d.ts +196 -0
  198. package/dist/hooks/recovery/types.d.ts.map +1 -0
  199. package/dist/hooks/recovery/types.js +32 -0
  200. package/dist/hooks/recovery/types.js.map +1 -0
  201. package/dist/hooks/ultrapilot/index.d.ts +90 -0
  202. package/dist/hooks/ultrapilot/index.d.ts.map +1 -0
  203. package/dist/hooks/ultrapilot/index.js +310 -0
  204. package/dist/hooks/ultrapilot/index.js.map +1 -0
  205. package/dist/hooks/ultrapilot/state.d.ts +72 -0
  206. package/dist/hooks/ultrapilot/state.d.ts.map +1 -0
  207. package/dist/hooks/ultrapilot/state.js +258 -0
  208. package/dist/hooks/ultrapilot/state.js.map +1 -0
  209. package/dist/hooks/ultrapilot/types.d.ts +113 -0
  210. package/dist/hooks/ultrapilot/types.d.ts.map +1 -0
  211. package/dist/hooks/ultrapilot/types.js +36 -0
  212. package/dist/hooks/ultrapilot/types.js.map +1 -0
  213. package/dist/hooks/ultraqa/index.d.ts +94 -0
  214. package/dist/hooks/ultraqa/index.d.ts.map +1 -0
  215. package/dist/hooks/ultraqa/index.js +216 -0
  216. package/dist/hooks/ultraqa/index.js.map +1 -0
  217. package/dist/hooks/ultrawork/index.d.ts +62 -0
  218. package/dist/hooks/ultrawork/index.d.ts.map +1 -0
  219. package/dist/hooks/ultrawork/index.js +208 -0
  220. package/dist/hooks/ultrawork/index.js.map +1 -0
  221. package/dist/index.d.ts.map +1 -1
  222. package/dist/index.js +1 -2
  223. package/dist/index.js.map +1 -1
  224. package/dist/installer/index.d.ts +1 -1
  225. package/dist/installer/index.d.ts.map +1 -1
  226. package/dist/installer/index.js +1 -1
  227. package/dist/installer/index.js.map +1 -1
  228. package/dist/mcp/index.d.ts +1 -1
  229. package/dist/mcp/index.d.ts.map +1 -1
  230. package/dist/mcp/index.js +1 -1
  231. package/dist/mcp/index.js.map +1 -1
  232. package/dist/mcp/servers.d.ts +2 -18
  233. package/dist/mcp/servers.d.ts.map +1 -1
  234. package/dist/mcp/servers.js +4 -36
  235. package/dist/mcp/servers.js.map +1 -1
  236. package/dist/shared/types.d.ts +1 -3
  237. package/dist/shared/types.d.ts.map +1 -1
  238. package/docs/CLAUDE.md +170 -44
  239. package/docs/DELEGATION-ENFORCER.md +282 -0
  240. package/docs/FULL-README.md +1 -1
  241. package/docs/LOCAL_PLUGIN_INSTALL.md +1 -1
  242. package/docs/MIGRATION.md +298 -104
  243. package/package.json +2 -2
  244. package/scripts/test-mutual-exclusion.ts +1 -1
  245. package/skills/analyze/SKILL.md +0 -1
  246. package/skills/autopilot/SKILL.md +0 -1
  247. package/skills/cancel/SKILL.md +580 -0
  248. package/skills/cancel-autopilot/SKILL.md +0 -1
  249. package/skills/cancel-ecomode/SKILL.md +41 -0
  250. package/skills/cancel-ralph/SKILL.md +0 -1
  251. package/skills/cancel-ultraqa/SKILL.md +0 -1
  252. package/skills/cancel-ultrawork/SKILL.md +0 -1
  253. package/skills/deepinit/SKILL.md +0 -1
  254. package/skills/deepsearch/SKILL.md +0 -1
  255. package/skills/doctor/SKILL.md +0 -1
  256. package/skills/ecomode/SKILL.md +128 -0
  257. package/skills/frontend-ui-ux/SKILL.md +0 -1
  258. package/skills/git-master/SKILL.md +0 -1
  259. package/skills/help/SKILL.md +1 -2
  260. package/skills/hud/SKILL.md +0 -1
  261. package/skills/learner/SKILL.md +0 -1
  262. package/skills/mcp-setup/SKILL.md +8 -7
  263. package/skills/note/SKILL.md +0 -1
  264. package/skills/omc-default/SKILL.md +0 -1
  265. package/skills/omc-default-global/SKILL.md +0 -1
  266. package/skills/omc-setup/SKILL.md +176 -10
  267. package/skills/orchestrate/SKILL.md +0 -1
  268. package/skills/pipeline/SKILL.md +417 -0
  269. package/skills/plan/SKILL.md +138 -21
  270. package/skills/planner/SKILL.md +0 -1
  271. package/skills/ralph/SKILL.md +65 -1
  272. package/skills/ralph-init/SKILL.md +0 -1
  273. package/skills/ralplan/SKILL.md +0 -1
  274. package/skills/release/SKILL.md +0 -1
  275. package/skills/research/SKILL.md +0 -1
  276. package/skills/review/SKILL.md +0 -1
  277. package/skills/swarm/SKILL.md +349 -0
  278. package/skills/tdd/SKILL.md +0 -1
  279. package/skills/ultrapilot/SKILL.md +563 -0
  280. package/skills/ultraqa/SKILL.md +0 -1
  281. package/skills/ultrawork/SKILL.md +0 -1
  282. package/docs/MIGRATION-v3.md +0 -186
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Ralph Verifier
3
+ *
4
+ * Adds architect verification to ralph completion claims.
5
+ * When ralph outputs a completion promise, instead of immediately
6
+ * accepting it, we trigger an architect verification phase.
7
+ *
8
+ * Flow:
9
+ * 1. Ralph outputs <promise>TASK_COMPLETE</promise>
10
+ * 2. System detects this and enters verification mode
11
+ * 3. Architect agent is invoked to verify the work
12
+ * 4. If architect approves -> truly complete
13
+ * 5. If architect finds flaws -> continue ralph with architect feedback
14
+ */
15
+ import { existsSync, readFileSync, writeFileSync, unlinkSync, mkdirSync } from 'fs';
16
+ import { join } from 'path';
17
+ const DEFAULT_MAX_VERIFICATION_ATTEMPTS = 3;
18
+ /**
19
+ * Get verification state file path
20
+ */
21
+ function getVerificationStatePath(directory) {
22
+ return join(directory, '.omc', 'ralph-verification.json');
23
+ }
24
+ /**
25
+ * Read verification state
26
+ */
27
+ export function readVerificationState(directory) {
28
+ const statePath = getVerificationStatePath(directory);
29
+ if (!existsSync(statePath)) {
30
+ return null;
31
+ }
32
+ try {
33
+ return JSON.parse(readFileSync(statePath, 'utf-8'));
34
+ }
35
+ catch {
36
+ return null;
37
+ }
38
+ }
39
+ /**
40
+ * Write verification state
41
+ */
42
+ export function writeVerificationState(directory, state) {
43
+ const statePath = getVerificationStatePath(directory);
44
+ const stateDir = join(directory, '.omc');
45
+ if (!existsSync(stateDir)) {
46
+ try {
47
+ mkdirSync(stateDir, { recursive: true });
48
+ }
49
+ catch {
50
+ return false;
51
+ }
52
+ }
53
+ try {
54
+ writeFileSync(statePath, JSON.stringify(state, null, 2));
55
+ return true;
56
+ }
57
+ catch {
58
+ return false;
59
+ }
60
+ }
61
+ /**
62
+ * Clear verification state
63
+ */
64
+ export function clearVerificationState(directory) {
65
+ const statePath = getVerificationStatePath(directory);
66
+ if (existsSync(statePath)) {
67
+ try {
68
+ unlinkSync(statePath);
69
+ return true;
70
+ }
71
+ catch {
72
+ return false;
73
+ }
74
+ }
75
+ return true;
76
+ }
77
+ /**
78
+ * Start verification process
79
+ */
80
+ export function startVerification(directory, completionClaim, originalTask) {
81
+ const state = {
82
+ pending: true,
83
+ completion_claim: completionClaim,
84
+ verification_attempts: 0,
85
+ max_verification_attempts: DEFAULT_MAX_VERIFICATION_ATTEMPTS,
86
+ requested_at: new Date().toISOString(),
87
+ original_task: originalTask
88
+ };
89
+ writeVerificationState(directory, state);
90
+ return state;
91
+ }
92
+ /**
93
+ * Record architect feedback
94
+ */
95
+ export function recordArchitectFeedback(directory, approved, feedback) {
96
+ const state = readVerificationState(directory);
97
+ if (!state) {
98
+ return null;
99
+ }
100
+ state.verification_attempts += 1;
101
+ state.architect_approved = approved;
102
+ state.architect_feedback = feedback;
103
+ if (approved) {
104
+ // Clear state on approval
105
+ clearVerificationState(directory);
106
+ return { ...state, pending: false };
107
+ }
108
+ // Check if max attempts reached
109
+ if (state.verification_attempts >= state.max_verification_attempts) {
110
+ clearVerificationState(directory);
111
+ return { ...state, pending: false };
112
+ }
113
+ // Continue verification loop
114
+ writeVerificationState(directory, state);
115
+ return state;
116
+ }
117
+ /**
118
+ * Generate architect verification prompt
119
+ */
120
+ export function getArchitectVerificationPrompt(state) {
121
+ return `<ralph-verification>
122
+
123
+ [ARCHITECT VERIFICATION REQUIRED - Attempt ${state.verification_attempts + 1}/${state.max_verification_attempts}]
124
+
125
+ The agent claims the task is complete. Before accepting, YOU MUST verify with Architect.
126
+
127
+ **Original Task:**
128
+ ${state.original_task}
129
+
130
+ **Completion Claim:**
131
+ ${state.completion_claim}
132
+
133
+ ${state.architect_feedback ? `**Previous Architect Feedback (rejected):**\n${state.architect_feedback}\n` : ''}
134
+
135
+ ## MANDATORY VERIFICATION STEPS
136
+
137
+ 1. **Spawn Architect Agent** for verification:
138
+ \`\`\`
139
+ Task(subagent_type="architect", prompt="Verify this task completion claim...")
140
+ \`\`\`
141
+
142
+ 2. **Architect must check:**
143
+ - Are ALL requirements from the original task met?
144
+ - Is the implementation complete, not partial?
145
+ - Are there any obvious bugs or issues?
146
+ - Does the code compile/run without errors?
147
+ - Are tests passing (if applicable)?
148
+
149
+ 3. **Based on Architect's response:**
150
+ - If APPROVED: Output \`<architect-approved>VERIFIED_COMPLETE</architect-approved>\`
151
+ - If REJECTED: Continue working on the identified issues
152
+
153
+ DO NOT output the completion promise again until Architect approves.
154
+
155
+ </ralph-verification>
156
+
157
+ ---
158
+
159
+ `;
160
+ }
161
+ /**
162
+ * Generate continuation prompt after architect rejection
163
+ */
164
+ export function getArchitectRejectionContinuationPrompt(state) {
165
+ return `<ralph-continuation-after-rejection>
166
+
167
+ [ARCHITECT REJECTED - Continue Working]
168
+
169
+ Architect found issues with your completion claim. You must address them.
170
+
171
+ **Architect Feedback:**
172
+ ${state.architect_feedback}
173
+
174
+ **Original Task:**
175
+ ${state.original_task}
176
+
177
+ ## INSTRUCTIONS
178
+
179
+ 1. Address ALL issues identified by Architect
180
+ 2. Do NOT claim completion again until issues are fixed
181
+ 3. When truly done, output the completion promise again
182
+ 4. Another Architect verification will be triggered
183
+
184
+ Continue working now.
185
+
186
+ </ralph-continuation-after-rejection>
187
+
188
+ ---
189
+
190
+ `;
191
+ }
192
+ /**
193
+ * Check if text contains architect approval
194
+ */
195
+ export function detectArchitectApproval(text) {
196
+ return /<architect-approved>.*?VERIFIED_COMPLETE.*?<\/architect-approved>/is.test(text);
197
+ }
198
+ /**
199
+ * Check if text contains architect rejection indicators
200
+ */
201
+ export function detectArchitectRejection(text) {
202
+ // Look for explicit rejection patterns
203
+ const rejectionPatterns = [
204
+ /architect.*?(rejected|found issues|not complete|incomplete)/i,
205
+ /issues? (found|identified|detected)/i,
206
+ /not yet complete/i,
207
+ /missing.*?(implementation|feature|test)/i,
208
+ /bug.*?(found|detected|identified)/i,
209
+ /error.*?(found|detected|identified)/i
210
+ ];
211
+ for (const pattern of rejectionPatterns) {
212
+ if (pattern.test(text)) {
213
+ // Extract feedback (rough heuristic)
214
+ const feedbackMatch = text.match(/(?:architect|feedback|issue|problem|error|bug)[:\s]+([^.]+\.)/i);
215
+ return {
216
+ rejected: true,
217
+ feedback: feedbackMatch ? feedbackMatch[1] : 'Architect found issues with the implementation.'
218
+ };
219
+ }
220
+ }
221
+ return { rejected: false, feedback: '' };
222
+ }
223
+ //# sourceMappingURL=verifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../../src/hooks/ralph/verifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpF,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAqB5B,MAAM,iCAAiC,GAAG,CAAC,CAAC;AAE5C;;GAEG;AACH,SAAS,wBAAwB,CAAC,SAAiB;IACjD,OAAO,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,yBAAyB,CAAC,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAAiB;IACrD,MAAM,SAAS,GAAG,wBAAw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EAAE,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Unified Recovery Constants
3
+ *
4
+ * Constants, messages, and patterns for all recovery mechanisms.
5
+ */
6
+ export declare const CLAUDE_CODE_STORAGE: string;
7
+ export declare const MESSAGE_STORAGE: string;
8
+ export declare const PART_STORAGE: string;
9
+ /**
10
+ * Debug logging configuration
11
+ */
12
+ export declare const DEBUG: boolean;
13
+ export declare const DEBUG_FILE: string;
14
+ /**
15
+ * Part type sets for categorization
16
+ */
17
+ export declare const THINKING_TYPES: Set<string>;
18
+ export declare const META_TYPES: Set<string>;
19
+ export declare const CONTENT_TYPES: Set<string>;
20
+ /**
21
+ * Placeholder text for empty content
22
+ */
23
+ export declare const PLACEHOLDER_TEXT = "[user interrupted]";
24
+ /**
25
+ * ============================================================================
26
+ * CONTEXT WINDOW LIMIT RECOVERY
27
+ * ============================================================================
28
+ */
29
+ /**
30
+ * Recovery message when context window limit is hit
31
+ */
32
+ export declare const CONTEXT_LIMIT_RECOVERY_MESSAGE = "CONTEXT WINDOW LIMIT REACHED - IMMEDIATE ACTION REQUIRED\n\nThe conversation has exceeded the model's context window limit. To continue working effectively, you must take one of these actions:\n\n1. SUMMARIZE THE CONVERSATION\n - Use the /compact command if available\n - Or provide a concise summary of what has been accomplished so far\n - Include key decisions, code changes, and remaining tasks\n\n2. START A FRESH CONTEXT\n - If summarization isn't sufficient, suggest starting a new session\n - Provide a handoff message with essential context\n\n3. REDUCE OUTPUT SIZE\n - When showing code, show only relevant portions\n - Use file paths and line numbers instead of full code blocks\n - Be more concise in explanations\n\nIMPORTANT: Do not attempt to continue without addressing this limit.\nThe API will reject further requests until the context is reduced.\n\nCurrent Status:\n- Context limit exceeded\n- Further API calls will fail until context is reduced\n- Action required before continuing\n";
33
+ /**
34
+ * Short notification for context limit
35
+ */
36
+ export declare const CONTEXT_LIMIT_SHORT_MESSAGE = "Context window limit reached. Please use /compact to summarize the conversation or start a new session.";
37
+ /**
38
+ * Recovery message for non-empty content errors
39
+ */
40
+ export declare const NON_EMPTY_CONTENT_RECOVERY_MESSAGE = "API ERROR: Non-empty content validation failed.\n\nThis error typically occurs when:\n- A message has empty text content\n- The conversation structure is invalid\n\nSuggested actions:\n1. Continue with a new message\n2. If the error persists, start a new session\n\nThe system will attempt automatic recovery.\n";
41
+ /**
42
+ * Recovery message when truncation was applied
43
+ */
44
+ export declare const TRUNCATION_APPLIED_MESSAGE = "CONTEXT OPTIMIZATION APPLIED\n\nSome tool outputs have been truncated to fit within the context window.\nThe conversation can now continue normally.\n\nIf you need to see the full output of a previous tool call, you can:\n- Re-run the specific command\n- Ask to see a particular file or section\n\nContinuing with the current task...\n";
45
+ /**
46
+ * Message when recovery fails
47
+ */
48
+ export declare const RECOVERY_FAILED_MESSAGE = "CONTEXT RECOVERY FAILED\n\nAll automatic recovery attempts have been exhausted.\nPlease start a new session to continue.\n\nBefore starting a new session:\n1. Note what has been accomplished\n2. Save any important code changes\n3. Document the current state of the task\n\nYou can copy this conversation summary to continue in a new session.\n";
49
+ /**
50
+ * Patterns to extract token counts from error messages
51
+ */
52
+ export declare const TOKEN_LIMIT_PATTERNS: RegExp[];
53
+ /**
54
+ * Keywords indicating token limit errors
55
+ */
56
+ export declare const TOKEN_LIMIT_KEYWORDS: string[];
57
+ /**
58
+ * ============================================================================
59
+ * EDIT ERROR RECOVERY
60
+ * ============================================================================
61
+ */
62
+ /**
63
+ * Known Edit tool error patterns that indicate the AI made a mistake
64
+ */
65
+ export declare const EDIT_ERROR_PATTERNS: readonly ["oldString and newString must be different", "oldString not found", "oldString found multiple times", "old_string not found", "old_string and new_string must be different"];
66
+ /**
67
+ * System reminder injected when Edit tool fails due to AI mistake
68
+ * Short, direct, and commanding - forces immediate corrective action
69
+ */
70
+ export declare const EDIT_ERROR_REMINDER = "\n[EDIT ERROR - IMMEDIATE ACTION REQUIRED]\n\nYou made an Edit mistake. STOP and do this NOW:\n\n1. READ the file immediately to see its ACTUAL current state\n2. VERIFY what the content really looks like (your assumption was wrong)\n3. APOLOGIZE briefly to the user for the error\n4. CONTINUE with corrected action based on the real file content\n\nDO NOT attempt another edit until you've read and verified the file state.\n";
71
+ /**
72
+ * ============================================================================
73
+ * SESSION RECOVERY
74
+ * ============================================================================
75
+ */
76
+ /**
77
+ * Recovery messages for different error types
78
+ */
79
+ export declare const RECOVERY_MESSAGES: {
80
+ readonly tool_result_missing: {
81
+ readonly title: "Tool Crash Recovery";
82
+ readonly message: "Injecting cancelled tool results...";
83
+ };
84
+ readonly thinking_block_order: {
85
+ readonly title: "Thinking Block Recovery";
86
+ readonly message: "Fixing message structure...";
87
+ };
88
+ readonly thinking_disabled_violation: {
89
+ readonly title: "Thinking Strip Recovery";
90
+ readonly message: "Stripping thinking blocks...";
91
+ };
92
+ readonly empty_content: {
93
+ readonly title: "Empty Content Recovery";
94
+ readonly message: "Adding placeholder content...";
95
+ };
96
+ readonly context_window_limit: {
97
+ readonly title: "Context Window Limit";
98
+ readonly message: "Context limit reached - recovery required";
99
+ };
100
+ readonly edit_error: {
101
+ readonly title: "Edit Error";
102
+ readonly message: "Edit operation failed - corrective action needed";
103
+ };
104
+ };
105
+ /**
106
+ * Recovery error patterns
107
+ */
108
+ export declare const ERROR_PATTERNS: {
109
+ readonly tool_result_missing: readonly ["tool_use", "tool_result"];
110
+ readonly thinking_block_order: readonly ["thinking", "first block", "must start with", "preceeding", "final block", "cannot be thinking"];
111
+ readonly thinking_disabled_violation: readonly ["thinking is disabled", "cannot contain"];
112
+ readonly empty_content: readonly ["empty", "content", "message"];
113
+ };
114
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/hooks/recovery/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoBH,eAAO,MAAM,mBAAmB,QAA4B,CAAC;AAC7D,eAAO,MAAM,eAAe,QAAuC,CAAC;AACpE,eAAO,MAAM,YAAY,QAAoC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,KAAK,SAG0B,CAAC;AAE7C,eAAO,MAAM,UAAU,QAAuC,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,cAAc,aAA0D,CAAC;AACtF,eAAO,MAAM,UAAU,aAAyC,CAAC;AACjE,eAAO,MAAM,aAAa,aAAuD,CAAC;AAElF;;GAEG;AACH,eAAO,MAAM,gBAAgB,uBAAuB,CAAC;AAErD;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,8BAA8B,kgCAyB1C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,4GAA4G,CAAC;AAErJ;;GAEG;AACH,eAAO,MAAM,kCAAkC,4TAW9C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,0BAA0B,oVAUtC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,4VAWnC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,UAMhC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,UAShC,CAAC;AAEF;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,mBAAmB,wLAMtB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,mBAAmB,8aAW/B,CAAC;AAEF;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;CAyBpB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;CAYjB,CAAC"}
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Unified Recovery Constants
3
+ *
4
+ * Constants, messages, and patterns for all recovery mechanisms.
5
+ */
6
+ import { join } from 'node:path';
7
+ import { homedir, tmpdir } from 'node:os';
8
+ /**
9
+ * Get the data directory for Claude Code storage
10
+ * Follows XDG Base Directory specification
11
+ */
12
+ function getDataDir() {
13
+ return process.env.XDG_DATA_HOME ?? join(homedir(), '.local', 'share');
14
+ }
15
+ /**
16
+ * Get the Claude Code storage directory
17
+ */
18
+ function getClaudeCodeStorageDir() {
19
+ return join(getDataDir(), 'claude-code', 'storage');
20
+ }
21
+ export const CLAUDE_CODE_STORAGE = getClaudeCodeStorageDir();
22
+ export const MESSAGE_STORAGE = join(CLAUDE_CODE_STORAGE, 'message');
23
+ export const PART_STORAGE = join(CLAUDE_CODE_STORAGE, 'part');
24
+ /**
25
+ * Debug logging configuration
26
+ */
27
+ export const DEBUG = process.env.RECOVERY_DEBUG === '1' ||
28
+ process.env.CONTEXT_LIMIT_RECOVERY_DEBUG === '1' ||
29
+ process.env.SESSION_RECOVERY_DEBUG === '1';
30
+ export const DEBUG_FILE = join(tmpdir(), 'recovery-debug.log');
31
+ /**
32
+ * Part type sets for categorization
33
+ */
34
+ export const THINKING_TYPES = new Set(['thinking', 'redacted_thinking', 'reasoning']);
35
+ export const META_TYPES = new Set(['step-start', 'step-finish']);
36
+ export const CONTENT_TYPES = new Set(['text', 'tool', 'tool_use', 'tool_result']);
37
+ /**
38
+ * Placeholder text for empty content
39
+ */
40
+ export const PLACEHOLDER_TEXT = '[user interrupted]';
41
+ /**
42
+ * ============================================================================
43
+ * CONTEXT WINDOW LIMIT RECOVERY
44
+ * ============================================================================
45
+ */
46
+ /**
47
+ * Recovery message when context window limit is hit
48
+ */
49
+ export const CONTEXT_LIMIT_RECOVERY_MESSAGE = `CONTEXT WINDOW LIMIT REACHED - IMMEDIATE ACTION REQUIRED
50
+
51
+ The conversation has exceeded the model's context window limit. To continue working effectively, you must take one of these actions:
52
+
53
+ 1. SUMMARIZE THE CONVERSATION
54
+ - Use the /compact command if available
55
+ - Or provide a concise summary of what has been accomplished so far
56
+ - Include key decisions, code changes, and remaining tasks
57
+
58
+ 2. START A FRESH CONTEXT
59
+ - If summarization isn't sufficient, suggest starting a new session
60
+ - Provide a handoff message with essential context
61
+
62
+ 3. REDUCE OUTPUT SIZE
63
+ - When showing code, show only relevant portions
64
+ - Use file paths and line numbers instead of full code blocks
65
+ - Be more concise in explanations
66
+
67
+ IMPORTANT: Do not attempt to continue without addressing this limit.
68
+ The API will reject further requests until the context is reduced.
69
+
70
+ Current Status:
71
+ - Context limit exceeded
72
+ - Further API calls will fail until context is reduced
73
+ - Action required before continuing
74
+ `;
75
+ /**
76
+ * Short notification for context limit
77
+ */
78
+ export const CONTEXT_LIMIT_SHORT_MESSAGE = `Context window limit reached. Please use /compact to summarize the conversation or start a new session.`;
79
+ /**
80
+ * Recovery message for non-empty content errors
81
+ */
82
+ export const NON_EMPTY_CONTENT_RECOVERY_MESSAGE = `API ERROR: Non-empty content validation failed.
83
+
84
+ This error typically occurs when:
85
+ - A message has empty text content
86
+ - The conversation structure is invalid
87
+
88
+ Suggested actions:
89
+ 1. Continue with a new message
90
+ 2. If the error persists, start a new session
91
+
92
+ The system will attempt automatic recovery.
93
+ `;
94
+ /**
95
+ * Recovery message when truncation was applied
96
+ */
97
+ export const TRUNCATION_APPLIED_MESSAGE = `CONTEXT OPTIMIZATION APPLIED
98
+
99
+ Some tool outputs have been truncated to fit within the context window.
100
+ The conversation can now continue normally.
101
+
102
+ If you need to see the full output of a previous tool call, you can:
103
+ - Re-run the specific command
104
+ - Ask to see a particular file or section
105
+
106
+ Continuing with the current task...
107
+ `;
108
+ /**
109
+ * Message when recovery fails
110
+ */
111
+ export const RECOVERY_FAILED_MESSAGE = `CONTEXT RECOVERY FAILED
112
+
113
+ All automatic recovery attempts have been exhausted.
114
+ Please start a new session to continue.
115
+
116
+ Before starting a new session:
117
+ 1. Note what has been accomplished
118
+ 2. Save any important code changes
119
+ 3. Document the current state of the task
120
+
121
+ You can copy this conversation summary to continue in a new session.
122
+ `;
123
+ /**
124
+ * Patterns to extract token counts from error messages
125
+ */
126
+ export const TOKEN_LIMIT_PATTERNS = [
127
+ /(\d+)\s*tokens?\s*>\s*(\d+)\s*maximum/i,
128
+ /prompt.*?(\d+).*?tokens.*?exceeds.*?(\d+)/i,
129
+ /(\d+).*?tokens.*?limit.*?(\d+)/i,
130
+ /context.*?length.*?(\d+).*?maximum.*?(\d+)/i,
131
+ /max.*?context.*?(\d+).*?but.*?(\d+)/i,
132
+ ];
133
+ /**
134
+ * Keywords indicating token limit errors
135
+ */
136
+ export const TOKEN_LIMIT_KEYWORDS = [
137
+ 'prompt is too long',
138
+ 'is too long',
139
+ 'context_length_exceeded',
140
+ 'max_tokens',
141
+ 'token limit',
142
+ 'context length',
143
+ 'too many tokens',
144
+ 'non-empty content',
145
+ ];
146
+ /**
147
+ * ============================================================================
148
+ * EDIT ERROR RECOVERY
149
+ * ============================================================================
150
+ */
151
+ /**
152
+ * Known Edit tool error patterns that indicate the AI made a mistake
153
+ */
154
+ export const EDIT_ERROR_PATTERNS = [
155
+ 'oldString and newString must be different',
156
+ 'oldString not found',
157
+ 'oldString found multiple times',
158
+ 'old_string not found',
159
+ 'old_string and new_string must be different',
160
+ ];
161
+ /**
162
+ * System reminder injected when Edit tool fails due to AI mistake
163
+ * Short, direct, and commanding - forces immediate corrective action
164
+ */
165
+ export const EDIT_ERROR_REMINDER = `
166
+ [EDIT ERROR - IMMEDIATE ACTION REQUIRED]
167
+
168
+ You made an Edit mistake. STOP and do this NOW:
169
+
170
+ 1. READ the file immediately to see its ACTUAL current state
171
+ 2. VERIFY what the content really looks like (your assumption was wrong)
172
+ 3. APOLOGIZE briefly to the user for the error
173
+ 4. CONTINUE with corrected action based on the real file content
174
+
175
+ DO NOT attempt another edit until you've read and verified the file state.
176
+ `;
177
+ /**
178
+ * ============================================================================
179
+ * SESSION RECOVERY
180
+ * ============================================================================
181
+ */
182
+ /**
183
+ * Recovery messages for different error types
184
+ */
185
+ export const RECOVERY_MESSAGES = {
186
+ tool_result_missing: {
187
+ title: 'Tool Crash Recovery',
188
+ message: 'Injecting cancelled tool results...',
189
+ },
190
+ thinking_block_order: {
191
+ title: 'Thinking Block Recovery',
192
+ message: 'Fixing message structure...',
193
+ },
194
+ thinking_disabled_violation: {
195
+ title: 'Thinking Strip Recovery',
196
+ message: 'Stripping thinking blocks...',
197
+ },
198
+ empty_content: {
199
+ title: 'Empty Content Recovery',
200
+ message: 'Adding placeholder content...',
201
+ },
202
+ context_window_limit: {
203
+ title: 'Context Window Limit',
204
+ message: 'Context limit reached - recovery required',
205
+ },
206
+ edit_error: {
207
+ title: 'Edit Error',
208
+ message: 'Edit operation failed - corrective action needed',
209
+ },
210
+ };
211
+ /**
212
+ * Recovery error patterns
213
+ */
214
+ export const ERROR_PATTERNS = {
215
+ tool_result_missing: ['tool_use', 'tool_result'],
216
+ thinking_block_order: [
217
+ 'thinking',
218
+ 'first block',
219
+ 'must start with',
220
+ 'preceeding',
221
+ 'final block',
222
+ 'cannot be thinking',
223
+ ],
224
+ thinking_disabled_violation: ['thinking is disabled', 'cannot contain'],
225
+ empty_content: ['empty', 'content', 'message'],
226
+ };
227
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/hooks/recovery/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE1C;;;GAGG;AACH,SAAS,UAAU;IACjB,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACzE,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB;IAC9B,OAAO,IAAI,CAAC,UAAU,EAAE,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,uBAAuB,EAAE,CAAC;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC;AACpE,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;AAE9D;;GA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,SAAS,CAAC;CACtC,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Context Window Limit Recovery
3
+ *
4
+ * Detects context window limit errors and injects recovery messages
5
+ * to help Claude recover gracefully.
6
+ */
7
+ import type { ParsedTokenLimitError, RecoveryResult, RecoveryConfig } from './types.js';
8
+ /**
9
+ * Parse an error to detect if it's a token limit error
10
+ */
11
+ export declare function parseTokenLimitError(err: unknown): ParsedTokenLimitError | null;
12
+ /**
13
+ * Check if text contains a context limit error
14
+ */
15
+ export declare function containsTokenLimitError(text: string): boolean;
16
+ /**
17
+ * Handle context window limit recovery
18
+ */
19
+ export declare function handleContextWindowRecovery(sessionId: string, error: unknown, config?: RecoveryConfig): RecoveryResult;
20
+ /**
21
+ * Check if text contains a context limit error
22
+ */
23
+ export declare function detectContextLimitError(text: string): boolean;
24
+ //# sourceMappingURL=context-window.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-window.d.ts","sourceRoot":"","sources":["../../../src/hooks/recovery/context-window.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,OAAO,KAAK,EACV,qBAAqB,EAGrB,cAAc,EACd,cAAc,EACf,MAAM,YAAY,CAAC;AAsFpB;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,OAAO,GACX,qBAAqB,GAAG,IAAI,CA8J9B;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D;AAuFD;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,cAAc,GACtB,cAAc,CAwBhB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D"}