aicodeman 0.2.8

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 (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +403 -0
  3. package/dist/ai-checker-base.d.ts +175 -0
  4. package/dist/ai-checker-base.d.ts.map +1 -0
  5. package/dist/ai-checker-base.js +424 -0
  6. package/dist/ai-checker-base.js.map +1 -0
  7. package/dist/ai-idle-checker.d.ts +53 -0
  8. package/dist/ai-idle-checker.d.ts.map +1 -0
  9. package/dist/ai-idle-checker.js +141 -0
  10. package/dist/ai-idle-checker.js.map +1 -0
  11. package/dist/ai-plan-checker.d.ts +52 -0
  12. package/dist/ai-plan-checker.d.ts.map +1 -0
  13. package/dist/ai-plan-checker.js +103 -0
  14. package/dist/ai-plan-checker.js.map +1 -0
  15. package/dist/bash-tool-parser.d.ts +191 -0
  16. package/dist/bash-tool-parser.d.ts.map +1 -0
  17. package/dist/bash-tool-parser.js +598 -0
  18. package/dist/bash-tool-parser.js.map +1 -0
  19. package/dist/cli.d.ts +12 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +460 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/config/buffer-limits.d.ts +59 -0
  24. package/dist/config/buffer-limits.d.ts.map +1 -0
  25. package/dist/config/buffer-limits.js +74 -0
  26. package/dist/config/buffer-limits.js.map +1 -0
  27. package/dist/config/map-limits.d.ts +40 -0
  28. package/dist/config/map-limits.d.ts.map +1 -0
  29. package/dist/config/map-limits.js +52 -0
  30. package/dist/config/map-limits.js.map +1 -0
  31. package/dist/file-stream-manager.d.ts +148 -0
  32. package/dist/file-stream-manager.d.ts.map +1 -0
  33. package/dist/file-stream-manager.js +351 -0
  34. package/dist/file-stream-manager.js.map +1 -0
  35. package/dist/hooks-config.d.ts +31 -0
  36. package/dist/hooks-config.d.ts.map +1 -0
  37. package/dist/hooks-config.js +115 -0
  38. package/dist/hooks-config.js.map +1 -0
  39. package/dist/image-watcher.d.ts +86 -0
  40. package/dist/image-watcher.d.ts.map +1 -0
  41. package/dist/image-watcher.js +275 -0
  42. package/dist/image-watcher.js.map +1 -0
  43. package/dist/index.d.ts +11 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +54 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/mux-factory.d.ts +13 -0
  48. package/dist/mux-factory.d.ts.map +1 -0
  49. package/dist/mux-factory.js +19 -0
  50. package/dist/mux-factory.js.map +1 -0
  51. package/dist/mux-interface.d.ts +145 -0
  52. package/dist/mux-interface.d.ts.map +1 -0
  53. package/dist/mux-interface.js +9 -0
  54. package/dist/mux-interface.js.map +1 -0
  55. package/dist/plan-orchestrator.d.ts +123 -0
  56. package/dist/plan-orchestrator.d.ts.map +1 -0
  57. package/dist/plan-orchestrator.js +500 -0
  58. package/dist/plan-orchestrator.js.map +1 -0
  59. package/dist/prompts/index.d.ts +9 -0
  60. package/dist/prompts/index.d.ts.map +1 -0
  61. package/dist/prompts/index.js +9 -0
  62. package/dist/prompts/index.js.map +1 -0
  63. package/dist/prompts/planner.d.ts +14 -0
  64. package/dist/prompts/planner.d.ts.map +1 -0
  65. package/dist/prompts/planner.js +83 -0
  66. package/dist/prompts/planner.js.map +1 -0
  67. package/dist/prompts/research-agent.d.ts +10 -0
  68. package/dist/prompts/research-agent.d.ts.map +1 -0
  69. package/dist/prompts/research-agent.js +143 -0
  70. package/dist/prompts/research-agent.js.map +1 -0
  71. package/dist/push-store.d.ts +41 -0
  72. package/dist/push-store.d.ts.map +1 -0
  73. package/dist/push-store.js +168 -0
  74. package/dist/push-store.js.map +1 -0
  75. package/dist/ralph-config.d.ts +67 -0
  76. package/dist/ralph-config.d.ts.map +1 -0
  77. package/dist/ralph-config.js +134 -0
  78. package/dist/ralph-config.js.map +1 -0
  79. package/dist/ralph-loop.d.ts +124 -0
  80. package/dist/ralph-loop.d.ts.map +1 -0
  81. package/dist/ralph-loop.js +418 -0
  82. package/dist/ralph-loop.js.map +1 -0
  83. package/dist/ralph-tracker.d.ts +1081 -0
  84. package/dist/ralph-tracker.d.ts.map +1 -0
  85. package/dist/ralph-tracker.js +3343 -0
  86. package/dist/ralph-tracker.js.map +1 -0
  87. package/dist/respawn-controller.d.ts +1182 -0
  88. package/dist/respawn-controller.d.ts.map +1 -0
  89. package/dist/respawn-controller.js +2754 -0
  90. package/dist/respawn-controller.js.map +1 -0
  91. package/dist/run-summary.d.ts +123 -0
  92. package/dist/run-summary.d.ts.map +1 -0
  93. package/dist/run-summary.js +325 -0
  94. package/dist/run-summary.js.map +1 -0
  95. package/dist/session-lifecycle-log.d.ts +36 -0
  96. package/dist/session-lifecycle-log.d.ts.map +1 -0
  97. package/dist/session-lifecycle-log.js +101 -0
  98. package/dist/session-lifecycle-log.js.map +1 -0
  99. package/dist/session-manager.d.ts +97 -0
  100. package/dist/session-manager.d.ts.map +1 -0
  101. package/dist/session-manager.js +224 -0
  102. package/dist/session-manager.js.map +1 -0
  103. package/dist/session.d.ts +686 -0
  104. package/dist/session.d.ts.map +1 -0
  105. package/dist/session.js +2025 -0
  106. package/dist/session.js.map +1 -0
  107. package/dist/state-store.d.ts +189 -0
  108. package/dist/state-store.d.ts.map +1 -0
  109. package/dist/state-store.js +730 -0
  110. package/dist/state-store.js.map +1 -0
  111. package/dist/subagent-watcher.d.ts +345 -0
  112. package/dist/subagent-watcher.d.ts.map +1 -0
  113. package/dist/subagent-watcher.js +1469 -0
  114. package/dist/subagent-watcher.js.map +1 -0
  115. package/dist/task-queue.d.ts +108 -0
  116. package/dist/task-queue.d.ts.map +1 -0
  117. package/dist/task-queue.js +235 -0
  118. package/dist/task-queue.js.map +1 -0
  119. package/dist/task-tracker.d.ts +306 -0
  120. package/dist/task-tracker.d.ts.map +1 -0
  121. package/dist/task-tracker.js +488 -0
  122. package/dist/task-tracker.js.map +1 -0
  123. package/dist/task.d.ts +73 -0
  124. package/dist/task.d.ts.map +1 -0
  125. package/dist/task.js +177 -0
  126. package/dist/task.js.map +1 -0
  127. package/dist/team-watcher.d.ts +53 -0
  128. package/dist/team-watcher.d.ts.map +1 -0
  129. package/dist/team-watcher.js +313 -0
  130. package/dist/team-watcher.js.map +1 -0
  131. package/dist/templates/case-template.md +461 -0
  132. package/dist/templates/claude-md.d.ts +26 -0
  133. package/dist/templates/claude-md.d.ts.map +1 -0
  134. package/dist/templates/claude-md.js +74 -0
  135. package/dist/templates/claude-md.js.map +1 -0
  136. package/dist/tmux-manager.d.ts +181 -0
  137. package/dist/tmux-manager.d.ts.map +1 -0
  138. package/dist/tmux-manager.js +1405 -0
  139. package/dist/tmux-manager.js.map +1 -0
  140. package/dist/transcript-watcher.d.ts +110 -0
  141. package/dist/transcript-watcher.d.ts.map +1 -0
  142. package/dist/transcript-watcher.js +338 -0
  143. package/dist/transcript-watcher.js.map +1 -0
  144. package/dist/tunnel-manager.d.ts +54 -0
  145. package/dist/tunnel-manager.d.ts.map +1 -0
  146. package/dist/tunnel-manager.js +251 -0
  147. package/dist/tunnel-manager.js.map +1 -0
  148. package/dist/types.d.ts +1139 -0
  149. package/dist/types.d.ts.map +1 -0
  150. package/dist/types.js +215 -0
  151. package/dist/types.js.map +1 -0
  152. package/dist/utils/buffer-accumulator.d.ts +111 -0
  153. package/dist/utils/buffer-accumulator.d.ts.map +1 -0
  154. package/dist/utils/buffer-accumulator.js +172 -0
  155. package/dist/utils/buffer-accumulator.js.map +1 -0
  156. package/dist/utils/claude-cli-resolver.d.ts +26 -0
  157. package/dist/utils/claude-cli-resolver.d.ts.map +1 -0
  158. package/dist/utils/claude-cli-resolver.js +78 -0
  159. package/dist/utils/claude-cli-resolver.js.map +1 -0
  160. package/dist/utils/cleanup-manager.d.ts +165 -0
  161. package/dist/utils/cleanup-manager.d.ts.map +1 -0
  162. package/dist/utils/cleanup-manager.js +274 -0
  163. package/dist/utils/cleanup-manager.js.map +1 -0
  164. package/dist/utils/index.d.ts +19 -0
  165. package/dist/utils/index.d.ts.map +1 -0
  166. package/dist/utils/index.js +19 -0
  167. package/dist/utils/index.js.map +1 -0
  168. package/dist/utils/lru-map.d.ts +140 -0
  169. package/dist/utils/lru-map.d.ts.map +1 -0
  170. package/dist/utils/lru-map.js +234 -0
  171. package/dist/utils/lru-map.js.map +1 -0
  172. package/dist/utils/nice-wrapper.d.ts +13 -0
  173. package/dist/utils/nice-wrapper.d.ts.map +1 -0
  174. package/dist/utils/nice-wrapper.js +17 -0
  175. package/dist/utils/nice-wrapper.js.map +1 -0
  176. package/dist/utils/opencode-cli-resolver.d.ts +21 -0
  177. package/dist/utils/opencode-cli-resolver.d.ts.map +1 -0
  178. package/dist/utils/opencode-cli-resolver.js +67 -0
  179. package/dist/utils/opencode-cli-resolver.js.map +1 -0
  180. package/dist/utils/regex-patterns.d.ts +64 -0
  181. package/dist/utils/regex-patterns.d.ts.map +1 -0
  182. package/dist/utils/regex-patterns.js +74 -0
  183. package/dist/utils/regex-patterns.js.map +1 -0
  184. package/dist/utils/stale-expiration-map.d.ts +159 -0
  185. package/dist/utils/stale-expiration-map.d.ts.map +1 -0
  186. package/dist/utils/stale-expiration-map.js +277 -0
  187. package/dist/utils/stale-expiration-map.js.map +1 -0
  188. package/dist/utils/string-similarity.d.ts +108 -0
  189. package/dist/utils/string-similarity.d.ts.map +1 -0
  190. package/dist/utils/string-similarity.js +189 -0
  191. package/dist/utils/string-similarity.js.map +1 -0
  192. package/dist/utils/token-validation.d.ts +39 -0
  193. package/dist/utils/token-validation.d.ts.map +1 -0
  194. package/dist/utils/token-validation.js +59 -0
  195. package/dist/utils/token-validation.js.map +1 -0
  196. package/dist/utils/type-safety.d.ts +33 -0
  197. package/dist/utils/type-safety.d.ts.map +1 -0
  198. package/dist/utils/type-safety.js +35 -0
  199. package/dist/utils/type-safety.js.map +1 -0
  200. package/dist/web/public/app.js +491 -0
  201. package/dist/web/public/app.js.br +0 -0
  202. package/dist/web/public/app.js.gz +0 -0
  203. package/dist/web/public/index.html +1675 -0
  204. package/dist/web/public/index.html.br +0 -0
  205. package/dist/web/public/index.html.gz +0 -0
  206. package/dist/web/public/manifest.json +8 -0
  207. package/dist/web/public/mobile.css +1 -0
  208. package/dist/web/public/mobile.css.br +0 -0
  209. package/dist/web/public/mobile.css.gz +0 -0
  210. package/dist/web/public/ralph-wizard.js +1037 -0
  211. package/dist/web/public/ralph-wizard.js.br +0 -0
  212. package/dist/web/public/ralph-wizard.js.gz +0 -0
  213. package/dist/web/public/styles.css +1 -0
  214. package/dist/web/public/styles.css.br +0 -0
  215. package/dist/web/public/styles.css.gz +0 -0
  216. package/dist/web/public/sw.js +67 -0
  217. package/dist/web/public/sw.js.br +0 -0
  218. package/dist/web/public/sw.js.gz +0 -0
  219. package/dist/web/public/upload.html +155 -0
  220. package/dist/web/public/upload.html.br +0 -0
  221. package/dist/web/public/upload.html.gz +0 -0
  222. package/dist/web/public/vendor/xterm-addon-fit.min.js +1 -0
  223. package/dist/web/public/vendor/xterm-addon-fit.min.js.br +0 -0
  224. package/dist/web/public/vendor/xterm-addon-fit.min.js.gz +0 -0
  225. package/dist/web/public/vendor/xterm-addon-unicode11.min.js +1 -0
  226. package/dist/web/public/vendor/xterm-addon-unicode11.min.js.br +0 -0
  227. package/dist/web/public/vendor/xterm-addon-unicode11.min.js.gz +0 -0
  228. package/dist/web/public/vendor/xterm-addon-webgl.min.js +2 -0
  229. package/dist/web/public/vendor/xterm-addon-webgl.min.js.br +0 -0
  230. package/dist/web/public/vendor/xterm-addon-webgl.min.js.gz +0 -0
  231. package/dist/web/public/vendor/xterm.css +209 -0
  232. package/dist/web/public/vendor/xterm.css.br +0 -0
  233. package/dist/web/public/vendor/xterm.css.gz +0 -0
  234. package/dist/web/public/vendor/xterm.min.js +9 -0
  235. package/dist/web/public/vendor/xterm.min.js.br +0 -0
  236. package/dist/web/public/vendor/xterm.min.js.gz +0 -0
  237. package/dist/web/schemas.d.ts +479 -0
  238. package/dist/web/schemas.d.ts.map +1 -0
  239. package/dist/web/schemas.js +448 -0
  240. package/dist/web/schemas.js.map +1 -0
  241. package/dist/web/server.d.ts +207 -0
  242. package/dist/web/server.d.ts.map +1 -0
  243. package/dist/web/server.js +5784 -0
  244. package/dist/web/server.js.map +1 -0
  245. package/package.json +110 -0
  246. package/scripts/postinstall.js +390 -0
@@ -0,0 +1,1139 @@
1
+ /**
2
+ * @fileoverview Type definitions for Codeman
3
+ *
4
+ * This module contains all TypeScript interfaces, types, and enums used
5
+ * throughout the Codeman application. It provides type safety for:
6
+ * - Session management
7
+ * - Task queue operations
8
+ * - Ralph Loop configuration
9
+ * - API requests/responses
10
+ * - Mux session handling
11
+ * - Inner loop tracking (Ralph Wiggum detection)
12
+ */
13
+ /**
14
+ * Interface for objects that hold resources requiring explicit cleanup.
15
+ * Implementing classes should release timers, watchers, and other resources in dispose().
16
+ */
17
+ export interface Disposable {
18
+ /** Release all held resources. Safe to call multiple times. */
19
+ dispose(): void;
20
+ /** Whether this object has been disposed */
21
+ readonly isDisposed: boolean;
22
+ }
23
+ /**
24
+ * Configuration for buffer accumulator instances.
25
+ * Used for terminal buffers, text output, and other size-limited string storage.
26
+ */
27
+ export interface BufferConfig {
28
+ /** Maximum buffer size in bytes before trimming */
29
+ maxSize: number;
30
+ /** Size to trim to when maxSize is exceeded */
31
+ trimSize: number;
32
+ /** Optional callback invoked when buffer is trimmed */
33
+ onTrim?: (trimmedBytes: number) => void;
34
+ }
35
+ /**
36
+ * Resource types that can be registered for cleanup.
37
+ */
38
+ export type CleanupResourceType = 'timer' | 'interval' | 'watcher' | 'listener' | 'stream';
39
+ /**
40
+ * Registration entry for a cleanup resource.
41
+ * Used by CleanupManager to track and dispose resources.
42
+ */
43
+ export interface CleanupRegistration {
44
+ /** Unique identifier for this registration */
45
+ id: string;
46
+ /** Type of resource */
47
+ type: CleanupResourceType;
48
+ /** Human-readable description for debugging */
49
+ description: string;
50
+ /** Cleanup function to call on dispose */
51
+ cleanup: () => void;
52
+ /** Timestamp when registered */
53
+ registeredAt: number;
54
+ }
55
+ /** Status of a Claude session */
56
+ export type SessionStatus = 'idle' | 'busy' | 'stopped' | 'error';
57
+ /** Status of a task in the queue */
58
+ export type TaskStatus = 'pending' | 'running' | 'completed' | 'failed';
59
+ /** Status of the Ralph Loop controller */
60
+ export type RalphLoopStatus = 'stopped' | 'running' | 'paused';
61
+ /** Task execution status for plan tracking */
62
+ export type PlanTaskStatus = 'pending' | 'in_progress' | 'completed' | 'failed' | 'blocked';
63
+ /** TDD phase categories */
64
+ export type TddPhase = 'setup' | 'test' | 'impl' | 'verify' | 'review';
65
+ /** Types of session lifecycle events recorded to the audit log */
66
+ export type LifecycleEventType = 'created' | 'started' | 'exit' | 'deleted' | 'detached' | 'recovered' | 'stale_cleaned' | 'mux_died' | 'server_started' | 'server_stopped';
67
+ /** A single entry in the session lifecycle audit log */
68
+ export interface LifecycleEntry {
69
+ ts: number;
70
+ event: LifecycleEventType;
71
+ sessionId: string;
72
+ name?: string;
73
+ mode?: string;
74
+ reason?: string;
75
+ exitCode?: number | null;
76
+ extra?: Record<string, unknown>;
77
+ }
78
+ /**
79
+ * Claude CLI startup permission mode.
80
+ * - `'dangerously-skip-permissions'`: Bypass all permission prompts (default)
81
+ * - `'normal'`: Standard mode with permission prompts
82
+ * - `'allowedTools'`: Only allow specific tools (requires allowedTools list)
83
+ */
84
+ export type ClaudeMode = 'dangerously-skip-permissions' | 'normal' | 'allowedTools';
85
+ /** Session mode: which CLI backend a session runs */
86
+ export type SessionMode = 'claude' | 'shell' | 'opencode';
87
+ /** OpenCode session configuration */
88
+ export interface OpenCodeConfig {
89
+ /** Model identifier (e.g., "anthropic/claude-sonnet-4-5", "openai/gpt-5.2", "ollama/codellama") */
90
+ model?: string;
91
+ /** Whether to auto-allow all tool executions (sets permission.* = allow) */
92
+ autoAllowTools?: boolean;
93
+ /** Session ID to continue from */
94
+ continueSession?: string;
95
+ /** Whether to fork when continuing (branch the conversation) */
96
+ forkSession?: boolean;
97
+ /** Custom inline config JSON (passed via OPENCODE_CONFIG_CONTENT) */
98
+ configContent?: string;
99
+ }
100
+ /**
101
+ * Configuration for creating a new session
102
+ */
103
+ export interface SessionConfig {
104
+ /** Unique session identifier */
105
+ id: string;
106
+ /** Working directory for the session */
107
+ workingDir: string;
108
+ /** Timestamp when session was created */
109
+ createdAt: number;
110
+ }
111
+ /**
112
+ * Available session colors for visual differentiation
113
+ */
114
+ export type SessionColor = 'default' | 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'purple' | 'pink';
115
+ /**
116
+ * Current state of a session
117
+ */
118
+ export interface SessionState {
119
+ /** Unique session identifier */
120
+ id: string;
121
+ /** Process ID of the PTY process, null if not running */
122
+ pid: number | null;
123
+ /** Current session status */
124
+ status: SessionStatus;
125
+ /** Working directory path */
126
+ workingDir: string;
127
+ /** ID of currently assigned task, null if none */
128
+ currentTaskId: string | null;
129
+ /** Timestamp when session was created */
130
+ createdAt: number;
131
+ /** Timestamp of last activity */
132
+ lastActivityAt: number;
133
+ /** Session display name */
134
+ name?: string;
135
+ /** Session mode */
136
+ mode?: SessionMode;
137
+ /** Auto-clear enabled */
138
+ autoClearEnabled?: boolean;
139
+ /** Auto-clear token threshold */
140
+ autoClearThreshold?: number;
141
+ /** Auto-compact enabled */
142
+ autoCompactEnabled?: boolean;
143
+ /** Auto-compact token threshold */
144
+ autoCompactThreshold?: number;
145
+ /** Auto-compact prompt */
146
+ autoCompactPrompt?: string;
147
+ /** Image watcher enabled for this session */
148
+ imageWatcherEnabled?: boolean;
149
+ /** Total cost in USD */
150
+ totalCost?: number;
151
+ /** Input tokens used */
152
+ inputTokens?: number;
153
+ /** Output tokens used */
154
+ outputTokens?: number;
155
+ /** Whether respawn controller is currently enabled/running */
156
+ respawnEnabled?: boolean;
157
+ /** Respawn controller config (if enabled) */
158
+ respawnConfig?: RespawnConfig & {
159
+ durationMinutes?: number;
160
+ };
161
+ /** Ralph / Todo tracker enabled */
162
+ ralphEnabled?: boolean;
163
+ /** Ralph auto-enable disabled (user explicitly turned off Ralph) */
164
+ ralphAutoEnableDisabled?: boolean;
165
+ /** Ralph completion phrase (if set) */
166
+ ralphCompletionPhrase?: string;
167
+ /** Parent agent ID if this session is a spawned agent */
168
+ parentAgentId?: string;
169
+ /** Child agent IDs spawned by this session */
170
+ childAgentIds?: string[];
171
+ /** Nice priority enabled */
172
+ niceEnabled?: boolean;
173
+ /** Nice value (-20 to 19) */
174
+ niceValue?: number;
175
+ /** User-assigned color for visual differentiation */
176
+ color?: SessionColor;
177
+ /** Flicker filter enabled (buffers output after screen clears) */
178
+ flickerFilterEnabled?: boolean;
179
+ /** Claude Code CLI version (parsed from terminal, e.g., "2.1.27") */
180
+ cliVersion?: string;
181
+ /** Claude model in use (parsed from terminal, e.g., "Opus 4.5") */
182
+ cliModel?: string;
183
+ /** Account type (parsed from terminal, e.g., "Claude Max", "API") */
184
+ cliAccountType?: string;
185
+ /** Latest CLI version available (parsed from version check) */
186
+ cliLatestVersion?: string;
187
+ /** OpenCode-specific configuration (only for mode === 'opencode') */
188
+ openCodeConfig?: OpenCodeConfig;
189
+ }
190
+ /**
191
+ * Global statistics across all sessions (including deleted ones).
192
+ * Persisted to track cumulative usage over time.
193
+ */
194
+ export interface GlobalStats {
195
+ /** Total input tokens used across all sessions */
196
+ totalInputTokens: number;
197
+ /** Total output tokens used across all sessions */
198
+ totalOutputTokens: number;
199
+ /** Total cost in USD across all sessions */
200
+ totalCost: number;
201
+ /** Total number of sessions created (lifetime) */
202
+ totalSessionsCreated: number;
203
+ /** Timestamp when stats were first recorded */
204
+ firstRecordedAt: number;
205
+ /** Timestamp of last update */
206
+ lastUpdatedAt: number;
207
+ }
208
+ /**
209
+ * Daily token usage entry for historical tracking.
210
+ */
211
+ export interface TokenUsageEntry {
212
+ /** Date in YYYY-MM-DD format */
213
+ date: string;
214
+ /** Input tokens used on this day */
215
+ inputTokens: number;
216
+ /** Output tokens used on this day */
217
+ outputTokens: number;
218
+ /** Estimated cost in USD */
219
+ estimatedCost: number;
220
+ /** Number of sessions that contributed to this day's usage */
221
+ sessions: number;
222
+ }
223
+ /**
224
+ * Token usage statistics with daily tracking.
225
+ */
226
+ export interface TokenStats {
227
+ /** Daily usage entries (most recent first) */
228
+ daily: TokenUsageEntry[];
229
+ /** Timestamp of last update */
230
+ lastUpdated: number;
231
+ }
232
+ /**
233
+ * Definition of a task to be executed
234
+ */
235
+ export interface TaskDefinition {
236
+ /** Unique task identifier */
237
+ id: string;
238
+ /** Prompt to send to Claude */
239
+ prompt: string;
240
+ /** Working directory for task execution */
241
+ workingDir: string;
242
+ /** Priority level (higher = processed first) */
243
+ priority: number;
244
+ /** IDs of tasks that must complete first */
245
+ dependencies: string[];
246
+ /** Custom phrase to detect task completion */
247
+ completionPhrase?: string;
248
+ /** Timeout in milliseconds */
249
+ timeoutMs?: number;
250
+ }
251
+ /**
252
+ * Full state of a task including execution details
253
+ */
254
+ export interface TaskState {
255
+ /** Unique task identifier */
256
+ id: string;
257
+ /** Prompt sent to Claude */
258
+ prompt: string;
259
+ /** Working directory for task execution */
260
+ workingDir: string;
261
+ /** Priority level (higher = processed first) */
262
+ priority: number;
263
+ /** IDs of tasks that must complete first */
264
+ dependencies: string[];
265
+ /** Custom phrase to detect task completion */
266
+ completionPhrase?: string;
267
+ /** Timeout in milliseconds */
268
+ timeoutMs?: number;
269
+ /** Current task status */
270
+ status: TaskStatus;
271
+ /** ID of session running this task, null if not assigned */
272
+ assignedSessionId: string | null;
273
+ /** Timestamp when task was created */
274
+ createdAt: number;
275
+ /** Timestamp when task started executing */
276
+ startedAt: number | null;
277
+ /** Timestamp when task completed */
278
+ completedAt: number | null;
279
+ /** Captured output from Claude */
280
+ output: string;
281
+ /** Error message if task failed */
282
+ error: string | null;
283
+ }
284
+ /**
285
+ * State of the Ralph Loop controller
286
+ */
287
+ export interface RalphLoopState {
288
+ /** Current loop status */
289
+ status: RalphLoopStatus;
290
+ /** Timestamp when loop started */
291
+ startedAt: number | null;
292
+ /** Minimum duration to run in milliseconds */
293
+ minDurationMs: number | null;
294
+ /** Number of tasks completed in this run */
295
+ tasksCompleted: number;
296
+ /** Number of tasks auto-generated */
297
+ tasksGenerated: number;
298
+ /** Timestamp of last status check */
299
+ lastCheckAt: number | null;
300
+ }
301
+ /**
302
+ * Complete application state
303
+ */
304
+ export interface AppState {
305
+ /** Map of session ID to session state */
306
+ sessions: Record<string, SessionState>;
307
+ /** Map of task ID to task state */
308
+ tasks: Record<string, TaskState>;
309
+ /** Ralph Loop controller state */
310
+ ralphLoop: RalphLoopState;
311
+ /** Application configuration */
312
+ config: AppConfig;
313
+ /** Global statistics (cumulative across all sessions) */
314
+ globalStats?: GlobalStats;
315
+ /** Daily token usage statistics */
316
+ tokenStats?: TokenStats;
317
+ }
318
+ /**
319
+ * Configuration for process priority using `nice`.
320
+ * Lower priority reduces CPU contention with other processes.
321
+ */
322
+ export interface NiceConfig {
323
+ /** Whether nice priority is enabled */
324
+ enabled: boolean;
325
+ /** Nice value (-20 to 19, default: 10 = lower priority) */
326
+ niceValue: number;
327
+ }
328
+ export declare const DEFAULT_NICE_CONFIG: NiceConfig;
329
+ /**
330
+ * Configuration for the Respawn Controller
331
+ *
332
+ * The respawn controller keeps interactive sessions productive by
333
+ * automatically cycling through update prompts when Claude goes idle.
334
+ */
335
+ export interface RespawnConfig {
336
+ /** How long to wait after seeing prompt before considering truly idle (ms) */
337
+ idleTimeoutMs: number;
338
+ /** The prompt to send for updating docs */
339
+ updatePrompt: string;
340
+ /** Delay between sending steps (ms) */
341
+ interStepDelayMs: number;
342
+ /** Whether to enable respawn loop */
343
+ enabled: boolean;
344
+ /** Whether to send /clear after update prompt */
345
+ sendClear: boolean;
346
+ /** Whether to send /init after /clear */
347
+ sendInit: boolean;
348
+ /** Optional prompt to send if /init doesn't trigger work */
349
+ kickstartPrompt?: string;
350
+ /** Time to wait after completion message before confirming idle (ms) */
351
+ completionConfirmMs?: number;
352
+ /** Fallback timeout when no output received at all (ms) */
353
+ noOutputTimeoutMs?: number;
354
+ /** Whether to auto-accept plan mode prompts by pressing Enter (not questions) */
355
+ autoAcceptPrompts?: boolean;
356
+ /** Delay before auto-accepting plan mode prompts when no output and no completion message (ms) */
357
+ autoAcceptDelayMs?: number;
358
+ /** Whether AI idle check is enabled */
359
+ aiIdleCheckEnabled?: boolean;
360
+ /** Model to use for AI idle check */
361
+ aiIdleCheckModel?: string;
362
+ /** Maximum characters of terminal buffer for AI check */
363
+ aiIdleCheckMaxContext?: number;
364
+ /** Timeout for AI check in ms */
365
+ aiIdleCheckTimeoutMs?: number;
366
+ /** Cooldown after WORKING verdict in ms */
367
+ aiIdleCheckCooldownMs?: number;
368
+ /** Whether AI plan mode check is enabled for auto-accept */
369
+ aiPlanCheckEnabled?: boolean;
370
+ /** Model to use for AI plan mode check */
371
+ aiPlanCheckModel?: string;
372
+ /** Maximum characters of terminal buffer for plan check */
373
+ aiPlanCheckMaxContext?: number;
374
+ /** Timeout for AI plan check in ms */
375
+ aiPlanCheckTimeoutMs?: number;
376
+ /** Cooldown after NOT_PLAN_MODE verdict in ms */
377
+ aiPlanCheckCooldownMs?: number;
378
+ /** Whether to use adaptive timing based on historical patterns */
379
+ adaptiveTimingEnabled?: boolean;
380
+ /** Minimum value for adaptive completion confirm (ms) */
381
+ adaptiveMinConfirmMs?: number;
382
+ /** Maximum value for adaptive completion confirm (ms) */
383
+ adaptiveMaxConfirmMs?: number;
384
+ /** Whether to skip /clear when context is below threshold */
385
+ skipClearWhenLowContext?: boolean;
386
+ /** Token percentage threshold below which /clear is skipped (0-100) */
387
+ skipClearThresholdPercent?: number;
388
+ /** Whether to track and persist cycle metrics */
389
+ trackCycleMetrics?: boolean;
390
+ }
391
+ /**
392
+ * Outcome of a respawn cycle
393
+ */
394
+ export type CycleOutcome = 'success' | 'stuck_recovery' | 'blocked' | 'error' | 'cancelled';
395
+ /**
396
+ * Metrics for a single respawn cycle.
397
+ * Persisted for post-mortem analysis of long-running loops.
398
+ */
399
+ export interface RespawnCycleMetrics {
400
+ /** Unique cycle ID (session-id:cycle-number) */
401
+ cycleId: string;
402
+ /** Session ID this cycle belongs to */
403
+ sessionId: string;
404
+ /** Cycle number within the session */
405
+ cycleNumber: number;
406
+ /** Timestamp when cycle started */
407
+ startedAt: number;
408
+ /** Timestamp when cycle completed */
409
+ completedAt: number;
410
+ /** Total duration of cycle (ms) */
411
+ durationMs: number;
412
+ /** What triggered idle detection */
413
+ idleReason: string;
414
+ /** Time spent detecting idle (from start of watching to idle confirmed) */
415
+ idleDetectionMs: number;
416
+ /** Steps completed in this cycle */
417
+ stepsCompleted: string[];
418
+ /** Whether /clear was skipped (P2-002) */
419
+ clearSkipped: boolean;
420
+ /** Outcome of the cycle */
421
+ outcome: CycleOutcome;
422
+ /** Error message if outcome is 'error' */
423
+ errorMessage?: string;
424
+ /** Token count at start of cycle */
425
+ tokenCountAtStart?: number;
426
+ /** Token count at end of cycle */
427
+ tokenCountAtEnd?: number;
428
+ /** Completion confirm time used (may be adaptive) */
429
+ completionConfirmMsUsed: number;
430
+ }
431
+ /**
432
+ * Aggregate metrics across multiple cycles for health scoring.
433
+ */
434
+ export interface RespawnAggregateMetrics {
435
+ /** Total cycles tracked */
436
+ totalCycles: number;
437
+ /** Successful cycles */
438
+ successfulCycles: number;
439
+ /** Cycles that required stuck-state recovery */
440
+ stuckRecoveryCycles: number;
441
+ /** Blocked cycles */
442
+ blockedCycles: number;
443
+ /** Error cycles */
444
+ errorCycles: number;
445
+ /** Average cycle duration (ms) */
446
+ avgCycleDurationMs: number;
447
+ /** Average idle detection time (ms) */
448
+ avgIdleDetectionMs: number;
449
+ /** 90th percentile cycle duration (ms) */
450
+ p90CycleDurationMs: number;
451
+ /** Success rate (0-100) */
452
+ successRate: number;
453
+ /** Last updated timestamp */
454
+ lastUpdatedAt: number;
455
+ }
456
+ /**
457
+ * Health status levels for the Ralph Loop system.
458
+ */
459
+ export type HealthStatus = 'excellent' | 'good' | 'degraded' | 'critical';
460
+ /**
461
+ * Comprehensive health score for a Ralph Loop session.
462
+ * Aggregates multiple health signals into a single score.
463
+ */
464
+ export interface RalphLoopHealthScore {
465
+ /** Overall health score (0-100) */
466
+ score: number;
467
+ /** Health status based on score thresholds */
468
+ status: HealthStatus;
469
+ /** Individual component scores (0-100 each) */
470
+ components: {
471
+ /** Based on recent cycle success rate */
472
+ cycleSuccess: number;
473
+ /** Based on circuit breaker state */
474
+ circuitBreaker: number;
475
+ /** Based on iteration stall metrics */
476
+ iterationProgress: number;
477
+ /** Based on AI checker error rate */
478
+ aiChecker: number;
479
+ /** Based on stuck-state recovery count */
480
+ stuckRecovery: number;
481
+ };
482
+ /** Human-readable summary of health */
483
+ summary: string;
484
+ /** Recommendations for improvement */
485
+ recommendations: string[];
486
+ /** Timestamp when score was calculated */
487
+ calculatedAt: number;
488
+ }
489
+ /**
490
+ * Historical timing data for adaptive adjustments.
491
+ */
492
+ export interface TimingHistory {
493
+ /** Rolling window of recent idle detection durations (ms) */
494
+ recentIdleDetectionMs: number[];
495
+ /** Rolling window of recent cycle durations (ms) */
496
+ recentCycleDurationMs: number[];
497
+ /** Calculated adaptive completion confirm value (ms) */
498
+ adaptiveCompletionConfirmMs: number;
499
+ /** Number of samples in rolling windows */
500
+ sampleCount: number;
501
+ /** Maximum samples to keep */
502
+ maxSamples: number;
503
+ /** Last updated timestamp */
504
+ lastUpdatedAt: number;
505
+ }
506
+ /**
507
+ * Named respawn configuration preset for quick setup
508
+ */
509
+ export interface RespawnPreset {
510
+ /** Unique preset identifier */
511
+ id: string;
512
+ /** User-friendly preset name */
513
+ name: string;
514
+ /** Description of when to use this preset */
515
+ description?: string;
516
+ /** The respawn configuration (without enabled flag) */
517
+ config: Omit<RespawnConfig, 'enabled'>;
518
+ /** Duration in minutes (optional default) */
519
+ durationMinutes?: number;
520
+ /** Whether this is a built-in preset */
521
+ builtIn?: boolean;
522
+ /** Timestamp when created */
523
+ createdAt: number;
524
+ }
525
+ /**
526
+ * Application configuration
527
+ */
528
+ export interface AppConfig {
529
+ /** Interval for polling session status (ms) */
530
+ pollIntervalMs: number;
531
+ /** Default timeout for tasks (ms) */
532
+ defaultTimeoutMs: number;
533
+ /** Maximum concurrent sessions allowed */
534
+ maxConcurrentSessions: number;
535
+ /** Path to state file */
536
+ stateFilePath: string;
537
+ /** Respawn controller configuration */
538
+ respawn: RespawnConfig;
539
+ /** Last used case name (for default selection) */
540
+ lastUsedCase: string | null;
541
+ /** Whether Ralph/Todo tracker is globally enabled for all new sessions */
542
+ ralphEnabled: boolean;
543
+ }
544
+ /**
545
+ * Output captured from a session
546
+ */
547
+ export interface SessionOutput {
548
+ /** Standard output content */
549
+ stdout: string;
550
+ /** Standard error content */
551
+ stderr: string;
552
+ /** Exit code of the process, null if still running */
553
+ exitCode: number | null;
554
+ }
555
+ /**
556
+ * Standard error codes for API responses
557
+ */
558
+ export declare enum ApiErrorCode {
559
+ /** Resource not found */
560
+ NOT_FOUND = "NOT_FOUND",
561
+ /** Invalid input provided */
562
+ INVALID_INPUT = "INVALID_INPUT",
563
+ /** Session is currently busy */
564
+ SESSION_BUSY = "SESSION_BUSY",
565
+ /** Operation failed */
566
+ OPERATION_FAILED = "OPERATION_FAILED",
567
+ /** Resource already exists */
568
+ ALREADY_EXISTS = "ALREADY_EXISTS",
569
+ /** Internal server error */
570
+ INTERNAL_ERROR = "INTERNAL_ERROR"
571
+ }
572
+ /**
573
+ * Hook event types triggered by Claude Code's hooks system
574
+ */
575
+ export type HookEventType = 'idle_prompt' | 'permission_prompt' | 'elicitation_dialog' | 'stop' | 'teammate_idle' | 'task_completed';
576
+ /**
577
+ * Standard API response wrapper (discriminated union for type safety)
578
+ * @template T Type of the data payload
579
+ */
580
+ export type ApiResponse<T = unknown> = {
581
+ success: true;
582
+ data?: T;
583
+ } | {
584
+ success: false;
585
+ error: string;
586
+ errorCode: ApiErrorCode;
587
+ };
588
+ /**
589
+ * Creates a standardized error response
590
+ * @param code Error code
591
+ * @param details Optional detailed error message
592
+ * @returns Formatted error response
593
+ */
594
+ export declare function createErrorResponse(code: ApiErrorCode, details?: string): ApiResponse<never>;
595
+ /**
596
+ * Response for quick start operation
597
+ */
598
+ export interface QuickStartResponse {
599
+ /** Whether the request succeeded */
600
+ success: boolean;
601
+ /** Created session ID */
602
+ sessionId?: string;
603
+ /** Path to case folder */
604
+ casePath?: string;
605
+ /** Case name */
606
+ caseName?: string;
607
+ /** Error message if failed */
608
+ error?: string;
609
+ }
610
+ /**
611
+ * Information about a case folder
612
+ */
613
+ export interface CaseInfo {
614
+ /** Case name */
615
+ name: string;
616
+ /** Full path to case folder */
617
+ path: string;
618
+ /** Whether CLAUDE.md exists */
619
+ hasClaudeMd?: boolean;
620
+ }
621
+ /**
622
+ * Persisted respawn configuration for mux sessions.
623
+ * Subset of RespawnConfig that gets saved to disk.
624
+ */
625
+ export interface PersistedRespawnConfig {
626
+ /** Whether respawn was enabled */
627
+ enabled: boolean;
628
+ /** How long to wait after seeing prompt before considering truly idle (ms) */
629
+ idleTimeoutMs: number;
630
+ /** The prompt to send for updating docs */
631
+ updatePrompt: string;
632
+ /** Delay between sending steps (ms) */
633
+ interStepDelayMs: number;
634
+ /** Whether to send /clear after update prompt */
635
+ sendClear: boolean;
636
+ /** Whether to send /init after /clear */
637
+ sendInit: boolean;
638
+ /** Optional prompt to send if /init doesn't trigger work */
639
+ kickstartPrompt?: string;
640
+ /** Whether to auto-accept plan mode prompts by pressing Enter (not questions) */
641
+ autoAcceptPrompts?: boolean;
642
+ /** Delay before auto-accepting prompts (ms) */
643
+ autoAcceptDelayMs?: number;
644
+ /** Time to wait after completion message before confirming idle (ms) */
645
+ completionConfirmMs?: number;
646
+ /** Fallback timeout when no output received at all (ms) */
647
+ noOutputTimeoutMs?: number;
648
+ /** Whether AI idle check is enabled */
649
+ aiIdleCheckEnabled?: boolean;
650
+ /** Model to use for AI idle check */
651
+ aiIdleCheckModel?: string;
652
+ /** Maximum characters of terminal buffer for AI check */
653
+ aiIdleCheckMaxContext?: number;
654
+ /** Timeout for AI check in ms */
655
+ aiIdleCheckTimeoutMs?: number;
656
+ /** Cooldown after WORKING verdict in ms */
657
+ aiIdleCheckCooldownMs?: number;
658
+ /** Whether AI plan mode check is enabled for auto-accept */
659
+ aiPlanCheckEnabled?: boolean;
660
+ /** Model to use for AI plan mode check */
661
+ aiPlanCheckModel?: string;
662
+ /** Maximum characters of terminal buffer for plan check */
663
+ aiPlanCheckMaxContext?: number;
664
+ /** Timeout for AI plan check in ms */
665
+ aiPlanCheckTimeoutMs?: number;
666
+ /** Cooldown after NOT_PLAN_MODE verdict in ms */
667
+ aiPlanCheckCooldownMs?: number;
668
+ /** Duration in minutes if timed respawn was set */
669
+ durationMinutes?: number;
670
+ }
671
+ /**
672
+ * Process resource statistics
673
+ */
674
+ export interface ProcessStats {
675
+ /** Memory usage in megabytes */
676
+ memoryMB: number;
677
+ /** CPU usage percentage */
678
+ cpuPercent: number;
679
+ /** Number of child processes */
680
+ childCount: number;
681
+ /** Timestamp of stats collection */
682
+ updatedAt: number;
683
+ }
684
+ /**
685
+ * Default application configuration values
686
+ */
687
+ export declare const DEFAULT_CONFIG: AppConfig;
688
+ /**
689
+ * Types for tracking Ralph Wiggum loops and todo lists
690
+ * running inside Claude Code sessions.
691
+ *
692
+ * This allows Codeman to detect and display when Claude Code
693
+ * is running its own autonomous loops internally.
694
+ */
695
+ /** Status of a detected todo item */
696
+ export type RalphTodoStatus = 'pending' | 'in_progress' | 'completed';
697
+ /**
698
+ * State of per-session Ralph / Todo tracking (detected from Claude output)
699
+ */
700
+ /**
701
+ * Confidence scoring for completion detection.
702
+ * Helps distinguish genuine completion signals from false positives.
703
+ */
704
+ export interface CompletionConfidence {
705
+ /** Overall confidence level (0-100) */
706
+ score: number;
707
+ /** Whether score is above threshold for triggering completion */
708
+ isConfident: boolean;
709
+ /** Individual signal contributions */
710
+ signals: {
711
+ /** Promise tag detected with proper formatting */
712
+ hasPromiseTag: boolean;
713
+ /** Phrase matches expected completion phrase */
714
+ matchesExpected: boolean;
715
+ /** All todos are marked complete */
716
+ allTodosComplete: boolean;
717
+ /** EXIT_SIGNAL: true in RALPH_STATUS block */
718
+ hasExitSignal: boolean;
719
+ /** Multiple completion indicators present */
720
+ multipleIndicators: boolean;
721
+ /** Output context suggests completion (not in prompt/explanation) */
722
+ contextAppropriate: boolean;
723
+ };
724
+ /** Timestamp of last confidence calculation */
725
+ calculatedAt: number;
726
+ }
727
+ export interface RalphTrackerState {
728
+ /** Whether the tracker is actively monitoring (disabled by default) */
729
+ enabled: boolean;
730
+ /** Whether a loop is currently active */
731
+ active: boolean;
732
+ /** Detected completion phrase (primary) */
733
+ completionPhrase: string | null;
734
+ /** Additional valid completion phrases (P1-003: multi-phrase support) */
735
+ alternateCompletionPhrases?: string[];
736
+ /** Timestamp when loop started */
737
+ startedAt: number | null;
738
+ /** Number of cycles/iterations detected */
739
+ cycleCount: number;
740
+ /** Maximum iterations if detected */
741
+ maxIterations: number | null;
742
+ /** Timestamp of last activity */
743
+ lastActivity: number;
744
+ /** Elapsed hours if detected */
745
+ elapsedHours: number | null;
746
+ /** Current plan version (for versioning UI) */
747
+ planVersion?: number;
748
+ /** Number of versions in history (for versioning UI) */
749
+ planHistoryLength?: number;
750
+ /** Last completion confidence assessment */
751
+ completionConfidence?: CompletionConfidence;
752
+ }
753
+ /**
754
+ * Priority levels for todo items.
755
+ * Matches @fix_plan.md format (P0=critical, P1=high, P2=normal).
756
+ */
757
+ export type RalphTodoPriority = 'P0' | 'P1' | 'P2' | null;
758
+ /**
759
+ * A detected todo item from Claude Code output
760
+ */
761
+ export interface RalphTodoItem {
762
+ /** Unique identifier based on content hash */
763
+ id: string;
764
+ /** Todo item text content */
765
+ content: string;
766
+ /** Current status */
767
+ status: RalphTodoStatus;
768
+ /** Timestamp when detected */
769
+ detectedAt: number;
770
+ /** Priority level (P0=critical, P1=high, P2=normal) */
771
+ priority: RalphTodoPriority;
772
+ /** P1-009: Estimated time to complete (ms), based on historical patterns */
773
+ estimatedDurationMs?: number;
774
+ /** P1-009: Complexity category for progress estimation */
775
+ estimatedComplexity?: 'trivial' | 'simple' | 'moderate' | 'complex';
776
+ }
777
+ /**
778
+ * Progress estimation for the todo list
779
+ */
780
+ export interface RalphTodoProgress {
781
+ /** Total number of todos */
782
+ total: number;
783
+ /** Number completed */
784
+ completed: number;
785
+ /** Number in progress */
786
+ inProgress: number;
787
+ /** Number pending */
788
+ pending: number;
789
+ /** Completion percentage (0-100) */
790
+ percentComplete: number;
791
+ /** Estimated remaining time (ms), based on historical completion rate */
792
+ estimatedRemainingMs: number | null;
793
+ /** Average time per todo completion (ms) */
794
+ avgCompletionTimeMs: number | null;
795
+ /** Projected completion timestamp (epoch ms) */
796
+ projectedCompletionAt: number | null;
797
+ }
798
+ /**
799
+ * Complete Ralph/todo state for a session
800
+ */
801
+ export interface RalphSessionState {
802
+ /** Session this state belongs to */
803
+ sessionId: string;
804
+ /** Loop tracking state */
805
+ loop: RalphTrackerState;
806
+ /** Detected todo items */
807
+ todos: RalphTodoItem[];
808
+ /** Timestamp of last update */
809
+ lastUpdated: number;
810
+ }
811
+ /**
812
+ * Status values from RALPH_STATUS block.
813
+ * - IN_PROGRESS: Work is ongoing
814
+ * - COMPLETE: All tasks finished
815
+ * - BLOCKED: Needs human intervention
816
+ */
817
+ export type RalphStatusValue = 'IN_PROGRESS' | 'COMPLETE' | 'BLOCKED';
818
+ /**
819
+ * Test status from RALPH_STATUS block.
820
+ */
821
+ export type RalphTestsStatus = 'PASSING' | 'FAILING' | 'NOT_RUN';
822
+ /**
823
+ * Work type classification for current iteration.
824
+ */
825
+ export type RalphWorkType = 'IMPLEMENTATION' | 'TESTING' | 'DOCUMENTATION' | 'REFACTORING';
826
+ /**
827
+ * Parsed RALPH_STATUS block from Claude output.
828
+ *
829
+ * Claude outputs this at the end of every response:
830
+ * ```
831
+ * ---RALPH_STATUS---
832
+ * STATUS: IN_PROGRESS
833
+ * TASKS_COMPLETED_THIS_LOOP: 3
834
+ * FILES_MODIFIED: 5
835
+ * TESTS_STATUS: PASSING
836
+ * WORK_TYPE: IMPLEMENTATION
837
+ * EXIT_SIGNAL: false
838
+ * RECOMMENDATION: Continue with database migration
839
+ * ---END_RALPH_STATUS---
840
+ * ```
841
+ */
842
+ export interface RalphStatusBlock {
843
+ /** Overall loop status */
844
+ status: RalphStatusValue;
845
+ /** Number of tasks completed in current iteration */
846
+ tasksCompletedThisLoop: number;
847
+ /** Number of files modified in current iteration */
848
+ filesModified: number;
849
+ /** Current state of tests */
850
+ testsStatus: RalphTestsStatus;
851
+ /** Type of work being performed */
852
+ workType: RalphWorkType;
853
+ /** Whether Claude is signaling completion */
854
+ exitSignal: boolean;
855
+ /** Claude's recommendation for next steps */
856
+ recommendation: string;
857
+ /** Timestamp when this block was parsed */
858
+ parsedAt: number;
859
+ }
860
+ /**
861
+ * Circuit breaker states for detecting stuck loops.
862
+ * - CLOSED: Normal operation, all checks passing
863
+ * - HALF_OPEN: Warning state, some checks failing
864
+ * - OPEN: Loop is stuck, requires intervention
865
+ */
866
+ export type CircuitBreakerState = 'CLOSED' | 'HALF_OPEN' | 'OPEN';
867
+ /**
868
+ * Reason codes for circuit breaker state transitions.
869
+ */
870
+ export type CircuitBreakerReason = 'normal_operation' | 'no_progress_warning' | 'no_progress_open' | 'same_error_repeated' | 'tests_failing_too_long' | 'progress_detected' | 'manual_reset';
871
+ /**
872
+ * Circuit breaker status for tracking loop health.
873
+ *
874
+ * Transitions:
875
+ * - CLOSED -> HALF_OPEN: consecutive_no_progress >= 2
876
+ * - CLOSED -> OPEN: consecutive_no_progress >= 3 OR consecutive_same_error >= 5
877
+ * - HALF_OPEN -> CLOSED: progress detected
878
+ * - HALF_OPEN -> OPEN: consecutive_no_progress >= 3
879
+ * - OPEN -> CLOSED: manual reset only
880
+ */
881
+ export interface CircuitBreakerStatus {
882
+ /** Current state of the circuit breaker */
883
+ state: CircuitBreakerState;
884
+ /** Number of consecutive iterations with no progress */
885
+ consecutiveNoProgress: number;
886
+ /** Number of consecutive iterations with the same error */
887
+ consecutiveSameError: number;
888
+ /** Number of consecutive iterations with failing tests */
889
+ consecutiveTestsFailure: number;
890
+ /** Last iteration number that showed progress */
891
+ lastProgressIteration: number;
892
+ /** Human-readable reason for current state */
893
+ reason: string;
894
+ /** Reason code for programmatic handling */
895
+ reasonCode: CircuitBreakerReason;
896
+ /** Timestamp of last state transition */
897
+ lastTransitionAt: number;
898
+ /** Last error message seen (for same-error tracking) */
899
+ lastErrorMessage: string | null;
900
+ }
901
+ /**
902
+ * Creates initial circuit breaker status.
903
+ */
904
+ export declare function createInitialCircuitBreakerStatus(): CircuitBreakerStatus;
905
+ /**
906
+ * Creates initial Ralph tracker state
907
+ * @returns Fresh Ralph tracker state with defaults
908
+ */
909
+ export declare function createInitialRalphTrackerState(): RalphTrackerState;
910
+ /**
911
+ * Creates initial Ralph session state
912
+ * @param sessionId Session ID this state belongs to
913
+ * @returns Fresh Ralph session state
914
+ */
915
+ export declare function createInitialRalphSessionState(sessionId: string): RalphSessionState;
916
+ /**
917
+ * Creates initial application state
918
+ * @returns Fresh application state with defaults
919
+ */
920
+ export declare function createInitialState(): AppState;
921
+ /**
922
+ * Creates initial global stats object
923
+ * @returns Fresh global stats with zero values
924
+ */
925
+ export declare function createInitialGlobalStats(): GlobalStats;
926
+ /**
927
+ * Type guard to check if a value is an Error instance
928
+ * @param value The value to check
929
+ * @returns True if the value is an Error instance
930
+ */
931
+ export declare function isError(value: unknown): value is Error;
932
+ /**
933
+ * Safely extracts an error message from an unknown caught value.
934
+ * Handles the TypeScript 4.4+ unknown error type in catch blocks.
935
+ *
936
+ * @param error The caught error (type unknown in strict mode)
937
+ * @returns A string error message
938
+ *
939
+ * @example
940
+ * ```typescript
941
+ * try {
942
+ * await riskyOperation();
943
+ * } catch (err) {
944
+ * console.error('Failed:', getErrorMessage(err));
945
+ * }
946
+ * ```
947
+ */
948
+ export declare function getErrorMessage(error: unknown): string;
949
+ /**
950
+ * Types of events tracked in the run summary.
951
+ * These provide a historical view of what happened during a session.
952
+ */
953
+ export type RunSummaryEventType = 'session_started' | 'session_stopped' | 'respawn_cycle_started' | 'respawn_cycle_completed' | 'respawn_state_change' | 'error' | 'warning' | 'token_milestone' | 'auto_compact' | 'auto_clear' | 'idle_detected' | 'working_detected' | 'ralph_completion' | 'ai_check_result' | 'hook_event' | 'state_stuck';
954
+ /**
955
+ * Severity levels for run summary events.
956
+ */
957
+ export type RunSummaryEventSeverity = 'info' | 'warning' | 'error' | 'success';
958
+ /**
959
+ * A single event in the run summary timeline.
960
+ */
961
+ export interface RunSummaryEvent {
962
+ /** Unique event identifier */
963
+ id: string;
964
+ /** Timestamp when event occurred */
965
+ timestamp: number;
966
+ /** Type of event */
967
+ type: RunSummaryEventType;
968
+ /** Severity level for display */
969
+ severity: RunSummaryEventSeverity;
970
+ /** Short title for the event */
971
+ title: string;
972
+ /** Optional detailed description */
973
+ details?: string;
974
+ /** Optional additional metadata */
975
+ metadata?: Record<string, unknown>;
976
+ }
977
+ /**
978
+ * Statistics aggregated from run summary events.
979
+ */
980
+ export interface RunSummaryStats {
981
+ /** Number of respawn cycles completed */
982
+ totalRespawnCycles: number;
983
+ /** Total tokens used during this run */
984
+ totalTokensUsed: number;
985
+ /** Peak token count observed */
986
+ peakTokens: number;
987
+ /** Total time Claude was actively working (ms) */
988
+ totalTimeActiveMs: number;
989
+ /** Total time Claude was idle (ms) */
990
+ totalTimeIdleMs: number;
991
+ /** Number of errors encountered */
992
+ errorCount: number;
993
+ /** Number of warnings encountered */
994
+ warningCount: number;
995
+ /** Number of AI idle checks performed */
996
+ aiCheckCount: number;
997
+ /** Timestamp when last became idle */
998
+ lastIdleAt: number | null;
999
+ /** Timestamp when last started working */
1000
+ lastWorkingAt: number | null;
1001
+ /** Total number of state transitions */
1002
+ stateTransitions: number;
1003
+ }
1004
+ /**
1005
+ * Complete run summary for a session.
1006
+ * Provides a historical view of session activity for users returning after absence.
1007
+ */
1008
+ export interface RunSummary {
1009
+ /** Session ID this summary belongs to */
1010
+ sessionId: string;
1011
+ /** Session display name */
1012
+ sessionName: string;
1013
+ /** Timestamp when tracking started */
1014
+ startedAt: number;
1015
+ /** Timestamp of last update */
1016
+ lastUpdatedAt: number;
1017
+ /** Timeline of events (most recent last) */
1018
+ events: RunSummaryEvent[];
1019
+ /** Aggregated statistics */
1020
+ stats: RunSummaryStats;
1021
+ }
1022
+ /**
1023
+ * Creates initial run summary stats.
1024
+ */
1025
+ export declare function createInitialRunSummaryStats(): RunSummaryStats;
1026
+ /**
1027
+ * Status of an active Bash tool command.
1028
+ */
1029
+ export type ActiveBashToolStatus = 'running' | 'completed';
1030
+ /**
1031
+ * Represents an active Bash tool command detected in Claude's output.
1032
+ * Used to display clickable file paths for file-viewing commands.
1033
+ */
1034
+ export interface ActiveBashTool {
1035
+ /** Unique identifier for this tool invocation */
1036
+ id: string;
1037
+ /** The full command being executed */
1038
+ command: string;
1039
+ /** Extracted file paths from the command (clickable) */
1040
+ filePaths: string[];
1041
+ /** Timeout string if specified (e.g., "16m 0s") */
1042
+ timeout?: string;
1043
+ /** Timestamp when the tool started */
1044
+ startedAt: number;
1045
+ /** Current status */
1046
+ status: ActiveBashToolStatus;
1047
+ /** Session ID this tool belongs to */
1048
+ sessionId: string;
1049
+ }
1050
+ /**
1051
+ * Event emitted when a new image file is detected in a session's working directory.
1052
+ * Used to trigger automatic image popup display in the web UI.
1053
+ */
1054
+ export interface ImageDetectedEvent {
1055
+ /** Codeman session ID where the image was detected */
1056
+ sessionId: string;
1057
+ /** Full path to the detected image file */
1058
+ filePath: string;
1059
+ /** Path relative to the session's working directory (for file-raw endpoint) */
1060
+ relativePath: string;
1061
+ /** Image file name (basename) */
1062
+ fileName: string;
1063
+ /** Timestamp when the image was detected */
1064
+ timestamp: number;
1065
+ /** File size in bytes */
1066
+ size: number;
1067
+ }
1068
+ /**
1069
+ * Information about a tmux pane within a session.
1070
+ * Used for agent team teammate pane management.
1071
+ */
1072
+ export interface PaneInfo {
1073
+ /** Pane ID (e.g., "%0", "%1") — immutable within a tmux session */
1074
+ paneId: string;
1075
+ /** Pane index within the window (0, 1, 2...) */
1076
+ paneIndex: number;
1077
+ /** PID of the process running in the pane */
1078
+ panePid: number;
1079
+ /** Pane width in columns */
1080
+ width: number;
1081
+ /** Pane height in rows */
1082
+ height: number;
1083
+ }
1084
+ export type { PlanItem } from './plan-orchestrator.js';
1085
+ /** A registered push subscription */
1086
+ export interface PushSubscriptionRecord {
1087
+ id: string;
1088
+ endpoint: string;
1089
+ keys: {
1090
+ p256dh: string;
1091
+ auth: string;
1092
+ };
1093
+ userAgent: string;
1094
+ createdAt: number;
1095
+ lastUsedAt: number;
1096
+ pushPreferences: Record<string, boolean>;
1097
+ }
1098
+ /** VAPID key pair for Web Push */
1099
+ export interface VapidKeys {
1100
+ publicKey: string;
1101
+ privateKey: string;
1102
+ generatedAt: number;
1103
+ }
1104
+ /** Team configuration from ~/.claude/teams/{name}/config.json */
1105
+ export interface TeamConfig {
1106
+ name: string;
1107
+ leadSessionId: string;
1108
+ members: TeamMember[];
1109
+ }
1110
+ /** A single team member (lead or teammate) */
1111
+ export interface TeamMember {
1112
+ agentId: string;
1113
+ name: string;
1114
+ agentType: 'team-lead' | 'general-purpose' | string;
1115
+ color?: string;
1116
+ backendType?: string;
1117
+ prompt?: string;
1118
+ tmuxPaneId?: string;
1119
+ }
1120
+ /** A task from ~/.claude/tasks/{team-name}/{N}.json */
1121
+ export interface TeamTask {
1122
+ id: string;
1123
+ subject: string;
1124
+ description?: string;
1125
+ activeForm?: string;
1126
+ status: 'pending' | 'in_progress' | 'completed' | string;
1127
+ blocks: string[];
1128
+ blockedBy: string[];
1129
+ owner?: string;
1130
+ metadata?: Record<string, unknown>;
1131
+ }
1132
+ /** An inbox message from ~/.claude/teams/{name}/inboxes/{member}.json */
1133
+ export interface InboxMessage {
1134
+ from: string;
1135
+ text: string;
1136
+ timestamp: string;
1137
+ read?: boolean;
1138
+ }
1139
+ //# sourceMappingURL=types.d.ts.map