aicodeman 0.2.9 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -4
- package/dist/ai-idle-checker.d.ts.map +1 -1
- package/dist/ai-idle-checker.js +3 -2
- package/dist/ai-idle-checker.js.map +1 -1
- package/dist/ai-plan-checker.d.ts.map +1 -1
- package/dist/ai-plan-checker.js +3 -2
- package/dist/ai-plan-checker.js.map +1 -1
- package/dist/bash-tool-parser.d.ts +2 -3
- package/dist/bash-tool-parser.d.ts.map +1 -1
- package/dist/bash-tool-parser.js +14 -31
- package/dist/bash-tool-parser.js.map +1 -1
- package/dist/config/ai-defaults.d.ts +16 -0
- package/dist/config/ai-defaults.d.ts.map +1 -0
- package/dist/config/ai-defaults.js +16 -0
- package/dist/config/ai-defaults.js.map +1 -0
- package/dist/config/auth-config.d.ts +19 -0
- package/dist/config/auth-config.d.ts.map +1 -0
- package/dist/config/auth-config.js +28 -0
- package/dist/config/auth-config.js.map +1 -0
- package/dist/config/exec-timeout.d.ts +10 -0
- package/dist/config/exec-timeout.d.ts.map +1 -0
- package/dist/config/exec-timeout.js +10 -0
- package/dist/config/exec-timeout.js.map +1 -0
- package/dist/config/map-limits.d.ts +4 -0
- package/dist/config/map-limits.d.ts.map +1 -1
- package/dist/config/map-limits.js +7 -0
- package/dist/config/map-limits.js.map +1 -1
- package/dist/config/server-timing.d.ts +42 -0
- package/dist/config/server-timing.d.ts.map +1 -0
- package/dist/config/server-timing.js +57 -0
- package/dist/config/server-timing.js.map +1 -0
- package/dist/config/team-config.d.ts +16 -0
- package/dist/config/team-config.d.ts.map +1 -0
- package/dist/config/team-config.js +16 -0
- package/dist/config/team-config.js.map +1 -0
- package/dist/config/terminal-limits.d.ts +18 -0
- package/dist/config/terminal-limits.d.ts.map +1 -0
- package/dist/config/terminal-limits.js +18 -0
- package/dist/config/terminal-limits.js.map +1 -0
- package/dist/config/tunnel-config.d.ts +27 -0
- package/dist/config/tunnel-config.d.ts.map +1 -0
- package/dist/config/tunnel-config.js +36 -0
- package/dist/config/tunnel-config.js.map +1 -0
- package/dist/hooks-config.d.ts +21 -6
- package/dist/hooks-config.d.ts.map +1 -1
- package/dist/hooks-config.js +28 -12
- package/dist/hooks-config.js.map +1 -1
- package/dist/image-watcher.d.ts +4 -4
- package/dist/image-watcher.d.ts.map +1 -1
- package/dist/image-watcher.js +17 -30
- package/dist/image-watcher.js.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/plan-orchestrator.d.ts +2 -24
- package/dist/plan-orchestrator.d.ts.map +1 -1
- package/dist/plan-orchestrator.js.map +1 -1
- package/dist/prompts/planner.d.ts +7 -8
- package/dist/prompts/planner.d.ts.map +1 -1
- package/dist/prompts/planner.js +7 -8
- package/dist/prompts/planner.js.map +1 -1
- package/dist/prompts/research-agent.d.ts +6 -4
- package/dist/prompts/research-agent.d.ts.map +1 -1
- package/dist/prompts/research-agent.js +6 -4
- package/dist/prompts/research-agent.js.map +1 -1
- package/dist/push-store.d.ts +1 -1
- package/dist/push-store.d.ts.map +1 -1
- package/dist/push-store.js +4 -12
- package/dist/push-store.js.map +1 -1
- package/dist/ralph-fix-plan-watcher.d.ts +91 -0
- package/dist/ralph-fix-plan-watcher.d.ts.map +1 -0
- package/dist/ralph-fix-plan-watcher.js +326 -0
- package/dist/ralph-fix-plan-watcher.js.map +1 -0
- package/dist/ralph-loop.d.ts +14 -4
- package/dist/ralph-loop.d.ts.map +1 -1
- package/dist/ralph-loop.js +14 -4
- package/dist/ralph-loop.js.map +1 -1
- package/dist/ralph-plan-tracker.d.ts +201 -0
- package/dist/ralph-plan-tracker.d.ts.map +1 -0
- package/dist/ralph-plan-tracker.js +325 -0
- package/dist/ralph-plan-tracker.js.map +1 -0
- package/dist/ralph-stall-detector.d.ts +84 -0
- package/dist/ralph-stall-detector.d.ts.map +1 -0
- package/dist/ralph-stall-detector.js +139 -0
- package/dist/ralph-stall-detector.js.map +1 -0
- package/dist/ralph-status-parser.d.ts +141 -0
- package/dist/ralph-status-parser.d.ts.map +1 -0
- package/dist/ralph-status-parser.js +478 -0
- package/dist/ralph-status-parser.js.map +1 -0
- package/dist/ralph-tracker.d.ts +218 -692
- package/dist/ralph-tracker.d.ts.map +1 -1
- package/dist/ralph-tracker.js +389 -1723
- package/dist/ralph-tracker.js.map +1 -1
- package/dist/respawn-adaptive-timing.d.ts +61 -0
- package/dist/respawn-adaptive-timing.d.ts.map +1 -0
- package/dist/respawn-adaptive-timing.js +105 -0
- package/dist/respawn-adaptive-timing.js.map +1 -0
- package/dist/respawn-controller.d.ts +35 -115
- package/dist/respawn-controller.d.ts.map +1 -1
- package/dist/respawn-controller.js +167 -607
- package/dist/respawn-controller.js.map +1 -1
- package/dist/respawn-health.d.ts +54 -0
- package/dist/respawn-health.d.ts.map +1 -0
- package/dist/respawn-health.js +183 -0
- package/dist/respawn-health.js.map +1 -0
- package/dist/respawn-metrics.d.ts +81 -0
- package/dist/respawn-metrics.d.ts.map +1 -0
- package/dist/respawn-metrics.js +198 -0
- package/dist/respawn-metrics.js.map +1 -0
- package/dist/respawn-patterns.d.ts +45 -0
- package/dist/respawn-patterns.d.ts.map +1 -0
- package/dist/respawn-patterns.js +125 -0
- package/dist/respawn-patterns.js.map +1 -0
- package/dist/session-auto-ops.d.ts +89 -0
- package/dist/session-auto-ops.d.ts.map +1 -0
- package/dist/session-auto-ops.js +224 -0
- package/dist/session-auto-ops.js.map +1 -0
- package/dist/session-cli-builder.d.ts +62 -0
- package/dist/session-cli-builder.d.ts.map +1 -0
- package/dist/session-cli-builder.js +121 -0
- package/dist/session-cli-builder.js.map +1 -0
- package/dist/session-manager.d.ts +17 -5
- package/dist/session-manager.d.ts.map +1 -1
- package/dist/session-manager.js +17 -5
- package/dist/session-manager.js.map +1 -1
- package/dist/session-task-cache.d.ts +52 -0
- package/dist/session-task-cache.d.ts.map +1 -0
- package/dist/session-task-cache.js +90 -0
- package/dist/session-task-cache.js.map +1 -0
- package/dist/session.d.ts +23 -41
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +79 -317
- package/dist/session.js.map +1 -1
- package/dist/state-store.d.ts +19 -9
- package/dist/state-store.d.ts.map +1 -1
- package/dist/state-store.js +29 -30
- package/dist/state-store.js.map +1 -1
- package/dist/subagent-watcher.d.ts +26 -7
- package/dist/subagent-watcher.d.ts.map +1 -1
- package/dist/subagent-watcher.js +47 -64
- package/dist/subagent-watcher.js.map +1 -1
- package/dist/team-watcher.d.ts.map +1 -1
- package/dist/team-watcher.js +2 -5
- package/dist/team-watcher.js.map +1 -1
- package/dist/tmux-manager.d.ts.map +1 -1
- package/dist/tmux-manager.js +1 -2
- package/dist/tmux-manager.js.map +1 -1
- package/dist/tunnel-manager.d.ts +26 -0
- package/dist/tunnel-manager.d.ts.map +1 -1
- package/dist/tunnel-manager.js +126 -7
- package/dist/tunnel-manager.js.map +1 -1
- package/dist/types/api.d.ts +108 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +98 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/app-state.d.ts +117 -0
- package/dist/types/app-state.d.ts.map +1 -0
- package/dist/types/app-state.js +76 -0
- package/dist/types/app-state.js.map +1 -0
- package/dist/types/common.d.ts +79 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +17 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +66 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +66 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/lifecycle.d.ts +28 -0
- package/dist/types/lifecycle.d.ts.map +1 -0
- package/dist/types/lifecycle.js +16 -0
- package/dist/types/lifecycle.js.map +1 -0
- package/dist/types/plan.d.ts +45 -0
- package/dist/types/plan.d.ts.map +1 -0
- package/dist/types/plan.js +18 -0
- package/dist/types/plan.js.map +1 -0
- package/dist/types/push.d.ts +36 -0
- package/dist/types/push.d.ts.map +1 -0
- package/dist/types/push.js +18 -0
- package/dist/types/push.js.map +1 -0
- package/dist/types/ralph.d.ts +262 -0
- package/dist/types/ralph.d.ts.map +1 -0
- package/dist/types/ralph.js +70 -0
- package/dist/types/ralph.js.map +1 -0
- package/dist/types/respawn.d.ts +271 -0
- package/dist/types/respawn.d.ts.map +1 -0
- package/dist/types/respawn.js +26 -0
- package/dist/types/respawn.js.map +1 -0
- package/dist/types/run-summary.d.ts +96 -0
- package/dist/types/run-summary.d.ts.map +1 -0
- package/dist/types/run-summary.js +37 -0
- package/dist/types/run-summary.js.map +1 -0
- package/dist/types/session.d.ts +152 -0
- package/dist/types/session.d.ts.map +1 -0
- package/dist/types/session.js +27 -0
- package/dist/types/session.js.map +1 -0
- package/dist/types/task.d.ts +72 -0
- package/dist/types/task.d.ts.map +1 -0
- package/dist/types/task.js +19 -0
- package/dist/types/task.js.map +1 -0
- package/dist/types/teams.d.ts +73 -0
- package/dist/types/teams.d.ts.map +1 -0
- package/dist/types/teams.js +23 -0
- package/dist/types/teams.js.map +1 -0
- package/dist/types/tools.d.ts +61 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +20 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/types.d.ts +8 -1134
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -210
- package/dist/types.js.map +1 -1
- package/dist/utils/claude-cli-resolver.d.ts.map +1 -1
- package/dist/utils/claude-cli-resolver.js +1 -2
- package/dist/utils/claude-cli-resolver.js.map +1 -1
- package/dist/utils/debouncer.d.ts +111 -0
- package/dist/utils/debouncer.d.ts.map +1 -0
- package/dist/utils/debouncer.js +162 -0
- package/dist/utils/debouncer.js.map +1 -0
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/opencode-cli-resolver.d.ts.map +1 -1
- package/dist/utils/opencode-cli-resolver.js +1 -2
- package/dist/utils/opencode-cli-resolver.js.map +1 -1
- package/dist/utils/string-similarity.d.ts +0 -57
- package/dist/utils/string-similarity.d.ts.map +1 -1
- package/dist/utils/string-similarity.js +3 -18
- package/dist/utils/string-similarity.js.map +1 -1
- package/dist/web/middleware/auth.d.ts +31 -0
- package/dist/web/middleware/auth.d.ts.map +1 -0
- package/dist/web/middleware/auth.js +154 -0
- package/dist/web/middleware/auth.js.map +1 -0
- package/dist/web/ports/auth-port.d.ts +18 -0
- package/dist/web/ports/auth-port.d.ts.map +1 -0
- package/dist/web/ports/auth-port.js +6 -0
- package/dist/web/ports/auth-port.js.map +1 -0
- package/dist/web/ports/config-port.d.ts +28 -0
- package/dist/web/ports/config-port.d.ts.map +1 -0
- package/dist/web/ports/config-port.js +6 -0
- package/dist/web/ports/config-port.js.map +1 -0
- package/dist/web/ports/event-port.d.ts +13 -0
- package/dist/web/ports/event-port.d.ts.map +1 -0
- package/dist/web/ports/event-port.js +6 -0
- package/dist/web/ports/event-port.js.map +1 -0
- package/dist/web/ports/index.d.ts +14 -0
- package/dist/web/ports/index.d.ts.map +1 -0
- package/dist/web/ports/index.js +9 -0
- package/dist/web/ports/index.js.map +1 -0
- package/dist/web/ports/infra-port.d.ts +36 -0
- package/dist/web/ports/infra-port.d.ts.map +1 -0
- package/dist/web/ports/infra-port.js +6 -0
- package/dist/web/ports/infra-port.js.map +1 -0
- package/dist/web/ports/respawn-port.d.ts +20 -0
- package/dist/web/ports/respawn-port.d.ts.map +1 -0
- package/dist/web/ports/respawn-port.js +6 -0
- package/dist/web/ports/respawn-port.js.map +1 -0
- package/dist/web/ports/session-port.d.ts +15 -0
- package/dist/web/ports/session-port.d.ts.map +1 -0
- package/dist/web/ports/session-port.js +6 -0
- package/dist/web/ports/session-port.js.map +1 -0
- package/dist/web/public/api-client.js +82 -0
- package/dist/web/public/api-client.js.br +0 -0
- package/dist/web/public/api-client.js.gz +0 -0
- package/dist/web/public/app.js +117 -201
- package/dist/web/public/app.js.br +0 -0
- package/dist/web/public/app.js.gz +0 -0
- package/dist/web/public/constants.js +365 -0
- package/dist/web/public/constants.js.br +0 -0
- package/dist/web/public/constants.js.gz +0 -0
- package/dist/web/public/index.html +15 -3
- package/dist/web/public/index.html.br +0 -0
- package/dist/web/public/index.html.gz +0 -0
- package/dist/web/public/keyboard-accessory.js +302 -0
- package/dist/web/public/keyboard-accessory.js.br +0 -0
- package/dist/web/public/keyboard-accessory.js.gz +0 -0
- package/dist/web/public/mobile-handlers.js +491 -0
- package/dist/web/public/mobile-handlers.js.br +0 -0
- package/dist/web/public/mobile-handlers.js.gz +0 -0
- package/dist/web/public/mobile.css.gz +0 -0
- package/dist/web/public/notification-manager.js +472 -0
- package/dist/web/public/notification-manager.js.br +0 -0
- package/dist/web/public/notification-manager.js.gz +0 -0
- package/dist/web/public/ralph-wizard.js +33 -9
- package/dist/web/public/ralph-wizard.js.br +0 -0
- package/dist/web/public/ralph-wizard.js.gz +0 -0
- package/dist/web/public/styles.css.gz +0 -0
- package/dist/web/public/subagent-windows.js +1149 -0
- package/dist/web/public/subagent-windows.js.br +0 -0
- package/dist/web/public/subagent-windows.js.gz +0 -0
- package/dist/web/public/sw.js +15 -0
- package/dist/web/public/sw.js.br +0 -0
- package/dist/web/public/sw.js.gz +0 -0
- package/dist/web/public/upload.html.gz +0 -0
- package/dist/web/public/vendor/xterm-addon-fit.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-addon-unicode11.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-addon-webgl.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-zerolag-input.js +4 -0
- package/dist/web/public/vendor/xterm-zerolag-input.js.br +0 -0
- package/dist/web/public/vendor/xterm-zerolag-input.js.gz +0 -0
- package/dist/web/public/vendor/xterm.css.gz +0 -0
- package/dist/web/public/vendor/xterm.min.js.gz +0 -0
- package/dist/web/public/voice-input.js +882 -0
- package/dist/web/public/voice-input.js.br +0 -0
- package/dist/web/public/voice-input.js.gz +0 -0
- package/dist/web/route-helpers.d.ts +38 -0
- package/dist/web/route-helpers.d.ts.map +1 -0
- package/dist/web/route-helpers.js +144 -0
- package/dist/web/route-helpers.js.map +1 -0
- package/dist/web/routes/case-routes.d.ts +9 -0
- package/dist/web/routes/case-routes.d.ts.map +1 -0
- package/dist/web/routes/case-routes.js +426 -0
- package/dist/web/routes/case-routes.js.map +1 -0
- package/dist/web/routes/file-routes.d.ts +8 -0
- package/dist/web/routes/file-routes.d.ts.map +1 -0
- package/dist/web/routes/file-routes.js +337 -0
- package/dist/web/routes/file-routes.js.map +1 -0
- package/dist/web/routes/hook-event-routes.d.ts +9 -0
- package/dist/web/routes/hook-event-routes.d.ts.map +1 -0
- package/dist/web/routes/hook-event-routes.js +57 -0
- package/dist/web/routes/hook-event-routes.js.map +1 -0
- package/dist/web/routes/index.d.ts +16 -0
- package/dist/web/routes/index.d.ts.map +1 -0
- package/dist/web/routes/index.js +16 -0
- package/dist/web/routes/index.js.map +1 -0
- package/dist/web/routes/mux-routes.d.ts +8 -0
- package/dist/web/routes/mux-routes.d.ts.map +1 -0
- package/dist/web/routes/mux-routes.js +32 -0
- package/dist/web/routes/mux-routes.js.map +1 -0
- package/dist/web/routes/plan-routes.d.ts +9 -0
- package/dist/web/routes/plan-routes.d.ts.map +1 -0
- package/dist/web/routes/plan-routes.js +385 -0
- package/dist/web/routes/plan-routes.js.map +1 -0
- package/dist/web/routes/push-routes.d.ts +8 -0
- package/dist/web/routes/push-routes.d.ts.map +1 -0
- package/dist/web/routes/push-routes.js +49 -0
- package/dist/web/routes/push-routes.js.map +1 -0
- package/dist/web/routes/ralph-routes.d.ts +9 -0
- package/dist/web/routes/ralph-routes.d.ts.map +1 -0
- package/dist/web/routes/ralph-routes.js +485 -0
- package/dist/web/routes/ralph-routes.js.map +1 -0
- package/dist/web/routes/respawn-routes.d.ts +8 -0
- package/dist/web/routes/respawn-routes.d.ts.map +1 -0
- package/dist/web/routes/respawn-routes.js +270 -0
- package/dist/web/routes/respawn-routes.js.map +1 -0
- package/dist/web/routes/scheduled-routes.d.ts +8 -0
- package/dist/web/routes/scheduled-routes.d.ts.map +1 -0
- package/dist/web/routes/scheduled-routes.js +51 -0
- package/dist/web/routes/scheduled-routes.js.map +1 -0
- package/dist/web/routes/session-routes.d.ts +9 -0
- package/dist/web/routes/session-routes.d.ts.map +1 -0
- package/dist/web/routes/session-routes.js +751 -0
- package/dist/web/routes/session-routes.js.map +1 -0
- package/dist/web/routes/system-routes.d.ts +9 -0
- package/dist/web/routes/system-routes.d.ts.map +1 -0
- package/dist/web/routes/system-routes.js +699 -0
- package/dist/web/routes/system-routes.js.map +1 -0
- package/dist/web/routes/team-routes.d.ts +8 -0
- package/dist/web/routes/team-routes.d.ts.map +1 -0
- package/dist/web/routes/team-routes.js +14 -0
- package/dist/web/routes/team-routes.js.map +1 -0
- package/dist/web/schemas.d.ts +43 -3
- package/dist/web/schemas.d.ts.map +1 -1
- package/dist/web/schemas.js +6 -2
- package/dist/web/schemas.js.map +1 -1
- package/dist/web/server.d.ts +35 -15
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +563 -3971
- package/dist/web/server.js.map +1 -1
- package/dist/web/sse-events.d.ts +361 -0
- package/dist/web/sse-events.d.ts.map +1 -0
- package/dist/web/sse-events.js +396 -0
- package/dist/web/sse-events.js.map +1 -0
- package/package.json +2 -1
- package/scripts/postinstall.js +58 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Cycle metrics tracker for respawn controller.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from respawn-controller.ts for modularity. Tracks per-cycle metrics
|
|
5
|
+
* and maintains aggregate statistics across all tracked cycles.
|
|
6
|
+
*
|
|
7
|
+
* @module respawn-metrics
|
|
8
|
+
*/
|
|
9
|
+
import type { RespawnCycleMetrics, RespawnAggregateMetrics, CycleOutcome } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Tracks respawn cycle metrics and maintains aggregate statistics.
|
|
12
|
+
*
|
|
13
|
+
* Each respawn cycle is tracked from start to completion, recording timing,
|
|
14
|
+
* steps completed, and outcome. Aggregate metrics provide a rolling view
|
|
15
|
+
* of system health across recent cycles.
|
|
16
|
+
*/
|
|
17
|
+
export declare class RespawnCycleMetricsTracker {
|
|
18
|
+
/** Current cycle being tracked */
|
|
19
|
+
private currentCycleMetrics;
|
|
20
|
+
/** Recent cycle metrics (rolling window for aggregate calculation) */
|
|
21
|
+
private recentCycleMetrics;
|
|
22
|
+
/** Aggregate metrics across all tracked cycles */
|
|
23
|
+
private aggregateMetrics;
|
|
24
|
+
/**
|
|
25
|
+
* Start tracking metrics for a new cycle.
|
|
26
|
+
* Called when a respawn cycle begins.
|
|
27
|
+
*
|
|
28
|
+
* @param sessionId - The session this cycle belongs to
|
|
29
|
+
* @param cycleNumber - The cycle number within the session
|
|
30
|
+
* @param idleReason - What triggered idle detection
|
|
31
|
+
* @param idleDetectionStartTime - Timestamp when idle detection started
|
|
32
|
+
* @param lastTokenCount - Token count at start of cycle
|
|
33
|
+
* @param adaptiveCompletionConfirmMs - Completion confirm timeout used
|
|
34
|
+
*/
|
|
35
|
+
startCycle(sessionId: string, cycleNumber: number, idleReason: string, idleDetectionStartTime: number, lastTokenCount: number, adaptiveCompletionConfirmMs: number): void;
|
|
36
|
+
/**
|
|
37
|
+
* Record a completed step in the current cycle.
|
|
38
|
+
* @param step - Name of the step (e.g., 'update', 'clear', 'init')
|
|
39
|
+
*/
|
|
40
|
+
recordStep(step: string): void;
|
|
41
|
+
/**
|
|
42
|
+
* Mark that /clear was skipped in the current cycle.
|
|
43
|
+
*/
|
|
44
|
+
markClearSkipped(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Get the current in-progress cycle metrics (for external inspection).
|
|
47
|
+
* @returns The current cycle metrics, or null if no cycle is in progress
|
|
48
|
+
*/
|
|
49
|
+
getCurrentCycle(): Partial<RespawnCycleMetrics> | null;
|
|
50
|
+
/**
|
|
51
|
+
* Complete the current cycle metrics with outcome.
|
|
52
|
+
* Adds to recent metrics and updates aggregates.
|
|
53
|
+
*
|
|
54
|
+
* @param outcome - Outcome of the cycle
|
|
55
|
+
* @param lastTokenCount - Token count at end of cycle
|
|
56
|
+
* @param errorMessage - Optional error message if outcome is 'error'
|
|
57
|
+
* @returns The completed cycle metrics, or null if no cycle was in progress
|
|
58
|
+
*/
|
|
59
|
+
completeCycle(outcome: CycleOutcome, lastTokenCount: number, errorMessage?: string): RespawnCycleMetrics | null;
|
|
60
|
+
/**
|
|
61
|
+
* Get aggregate metrics for monitoring.
|
|
62
|
+
* @returns Copy of aggregate metrics
|
|
63
|
+
*/
|
|
64
|
+
getAggregate(): RespawnAggregateMetrics;
|
|
65
|
+
/**
|
|
66
|
+
* Get recent cycle metrics for analysis.
|
|
67
|
+
* @param limit - Maximum number of metrics to return (default: 20)
|
|
68
|
+
* @returns Recent cycle metrics, newest first
|
|
69
|
+
*/
|
|
70
|
+
getRecent(limit?: number): RespawnCycleMetrics[];
|
|
71
|
+
/**
|
|
72
|
+
* Reset all metrics state.
|
|
73
|
+
*/
|
|
74
|
+
reset(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Update aggregate metrics with a new cycle's data.
|
|
77
|
+
* @param metrics - The completed cycle metrics
|
|
78
|
+
*/
|
|
79
|
+
private updateAggregateMetrics;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=respawn-metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"respawn-metrics.d.ts","sourceRoot":"","sources":["../src/respawn-metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAO7F;;;;;;GAMG;AACH,qBAAa,0BAA0B;IACrC,kCAAkC;IAClC,OAAO,CAAC,mBAAmB,CAA6C;IAExE,sEAAsE;IACtE,OAAO,CAAC,kBAAkB,CAA6B;IAEvD,kDAAkD;IAClD,OAAO,CAAC,gBAAgB,CAWtB;IAEF;;;;;;;;;;OAUG;IACH,UAAU,CACR,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,sBAAsB,EAAE,MAAM,EAC9B,cAAc,EAAE,MAAM,EACtB,2BAA2B,EAAE,MAAM,GAClC,IAAI;IAgBP;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK9B;;OAEG;IACH,gBAAgB,IAAI,IAAI;IAMxB;;;OAGG;IACH,eAAe,IAAI,OAAO,CAAC,mBAAmB,CAAC,GAAG,IAAI;IAItD;;;;;;;;OAQG;IACH,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,mBAAmB,GAAG,IAAI;IA4B/G;;;OAGG;IACH,YAAY,IAAI,uBAAuB;IAIvC;;;;OAIG;IACH,SAAS,CAAC,KAAK,GAAE,MAAW,GAAG,mBAAmB,EAAE;IAIpD;;OAEG;IACH,KAAK,IAAI,IAAI;IAiBb;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CA6C/B"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Cycle metrics tracker for respawn controller.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from respawn-controller.ts for modularity. Tracks per-cycle metrics
|
|
5
|
+
* and maintains aggregate statistics across all tracked cycles.
|
|
6
|
+
*
|
|
7
|
+
* @module respawn-metrics
|
|
8
|
+
*/
|
|
9
|
+
import { assertNever } from './utils/index.js';
|
|
10
|
+
/**
|
|
11
|
+
* Maximum number of cycle metrics to keep in memory.
|
|
12
|
+
*/
|
|
13
|
+
const MAX_CYCLE_METRICS_IN_MEMORY = 100;
|
|
14
|
+
/**
|
|
15
|
+
* Tracks respawn cycle metrics and maintains aggregate statistics.
|
|
16
|
+
*
|
|
17
|
+
* Each respawn cycle is tracked from start to completion, recording timing,
|
|
18
|
+
* steps completed, and outcome. Aggregate metrics provide a rolling view
|
|
19
|
+
* of system health across recent cycles.
|
|
20
|
+
*/
|
|
21
|
+
export class RespawnCycleMetricsTracker {
|
|
22
|
+
/** Current cycle being tracked */
|
|
23
|
+
currentCycleMetrics = null;
|
|
24
|
+
/** Recent cycle metrics (rolling window for aggregate calculation) */
|
|
25
|
+
recentCycleMetrics = [];
|
|
26
|
+
/** Aggregate metrics across all tracked cycles */
|
|
27
|
+
aggregateMetrics = {
|
|
28
|
+
totalCycles: 0,
|
|
29
|
+
successfulCycles: 0,
|
|
30
|
+
stuckRecoveryCycles: 0,
|
|
31
|
+
blockedCycles: 0,
|
|
32
|
+
errorCycles: 0,
|
|
33
|
+
avgCycleDurationMs: 0,
|
|
34
|
+
avgIdleDetectionMs: 0,
|
|
35
|
+
p90CycleDurationMs: 0,
|
|
36
|
+
successRate: 100,
|
|
37
|
+
lastUpdatedAt: Date.now(),
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Start tracking metrics for a new cycle.
|
|
41
|
+
* Called when a respawn cycle begins.
|
|
42
|
+
*
|
|
43
|
+
* @param sessionId - The session this cycle belongs to
|
|
44
|
+
* @param cycleNumber - The cycle number within the session
|
|
45
|
+
* @param idleReason - What triggered idle detection
|
|
46
|
+
* @param idleDetectionStartTime - Timestamp when idle detection started
|
|
47
|
+
* @param lastTokenCount - Token count at start of cycle
|
|
48
|
+
* @param adaptiveCompletionConfirmMs - Completion confirm timeout used
|
|
49
|
+
*/
|
|
50
|
+
startCycle(sessionId, cycleNumber, idleReason, idleDetectionStartTime, lastTokenCount, adaptiveCompletionConfirmMs) {
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
this.currentCycleMetrics = {
|
|
53
|
+
cycleId: `${sessionId}:${cycleNumber}`,
|
|
54
|
+
sessionId,
|
|
55
|
+
cycleNumber,
|
|
56
|
+
startedAt: now,
|
|
57
|
+
idleReason,
|
|
58
|
+
idleDetectionMs: now - idleDetectionStartTime,
|
|
59
|
+
stepsCompleted: [],
|
|
60
|
+
clearSkipped: false,
|
|
61
|
+
tokenCountAtStart: lastTokenCount,
|
|
62
|
+
completionConfirmMsUsed: adaptiveCompletionConfirmMs,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Record a completed step in the current cycle.
|
|
67
|
+
* @param step - Name of the step (e.g., 'update', 'clear', 'init')
|
|
68
|
+
*/
|
|
69
|
+
recordStep(step) {
|
|
70
|
+
if (!this.currentCycleMetrics)
|
|
71
|
+
return;
|
|
72
|
+
this.currentCycleMetrics.stepsCompleted?.push(step);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Mark that /clear was skipped in the current cycle.
|
|
76
|
+
*/
|
|
77
|
+
markClearSkipped() {
|
|
78
|
+
if (this.currentCycleMetrics) {
|
|
79
|
+
this.currentCycleMetrics.clearSkipped = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get the current in-progress cycle metrics (for external inspection).
|
|
84
|
+
* @returns The current cycle metrics, or null if no cycle is in progress
|
|
85
|
+
*/
|
|
86
|
+
getCurrentCycle() {
|
|
87
|
+
return this.currentCycleMetrics;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Complete the current cycle metrics with outcome.
|
|
91
|
+
* Adds to recent metrics and updates aggregates.
|
|
92
|
+
*
|
|
93
|
+
* @param outcome - Outcome of the cycle
|
|
94
|
+
* @param lastTokenCount - Token count at end of cycle
|
|
95
|
+
* @param errorMessage - Optional error message if outcome is 'error'
|
|
96
|
+
* @returns The completed cycle metrics, or null if no cycle was in progress
|
|
97
|
+
*/
|
|
98
|
+
completeCycle(outcome, lastTokenCount, errorMessage) {
|
|
99
|
+
if (!this.currentCycleMetrics)
|
|
100
|
+
return null;
|
|
101
|
+
const now = Date.now();
|
|
102
|
+
const metrics = {
|
|
103
|
+
...this.currentCycleMetrics,
|
|
104
|
+
completedAt: now,
|
|
105
|
+
durationMs: now - (this.currentCycleMetrics.startedAt ?? now),
|
|
106
|
+
outcome,
|
|
107
|
+
errorMessage,
|
|
108
|
+
tokenCountAtEnd: lastTokenCount,
|
|
109
|
+
};
|
|
110
|
+
// Add to recent metrics
|
|
111
|
+
this.recentCycleMetrics.push(metrics);
|
|
112
|
+
if (this.recentCycleMetrics.length > MAX_CYCLE_METRICS_IN_MEMORY) {
|
|
113
|
+
this.recentCycleMetrics.shift();
|
|
114
|
+
}
|
|
115
|
+
// Update aggregate metrics
|
|
116
|
+
this.updateAggregateMetrics(metrics);
|
|
117
|
+
// Clear current cycle
|
|
118
|
+
this.currentCycleMetrics = null;
|
|
119
|
+
return metrics;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get aggregate metrics for monitoring.
|
|
123
|
+
* @returns Copy of aggregate metrics
|
|
124
|
+
*/
|
|
125
|
+
getAggregate() {
|
|
126
|
+
return { ...this.aggregateMetrics };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get recent cycle metrics for analysis.
|
|
130
|
+
* @param limit - Maximum number of metrics to return (default: 20)
|
|
131
|
+
* @returns Recent cycle metrics, newest first
|
|
132
|
+
*/
|
|
133
|
+
getRecent(limit = 20) {
|
|
134
|
+
return this.recentCycleMetrics.slice(-limit).reverse();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Reset all metrics state.
|
|
138
|
+
*/
|
|
139
|
+
reset() {
|
|
140
|
+
this.currentCycleMetrics = null;
|
|
141
|
+
this.recentCycleMetrics = [];
|
|
142
|
+
this.aggregateMetrics = {
|
|
143
|
+
totalCycles: 0,
|
|
144
|
+
successfulCycles: 0,
|
|
145
|
+
stuckRecoveryCycles: 0,
|
|
146
|
+
blockedCycles: 0,
|
|
147
|
+
errorCycles: 0,
|
|
148
|
+
avgCycleDurationMs: 0,
|
|
149
|
+
avgIdleDetectionMs: 0,
|
|
150
|
+
p90CycleDurationMs: 0,
|
|
151
|
+
successRate: 100,
|
|
152
|
+
lastUpdatedAt: Date.now(),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Update aggregate metrics with a new cycle's data.
|
|
157
|
+
* @param metrics - The completed cycle metrics
|
|
158
|
+
*/
|
|
159
|
+
updateAggregateMetrics(metrics) {
|
|
160
|
+
const agg = this.aggregateMetrics;
|
|
161
|
+
agg.totalCycles++;
|
|
162
|
+
switch (metrics.outcome) {
|
|
163
|
+
case 'success':
|
|
164
|
+
agg.successfulCycles++;
|
|
165
|
+
break;
|
|
166
|
+
case 'stuck_recovery':
|
|
167
|
+
agg.stuckRecoveryCycles++;
|
|
168
|
+
break;
|
|
169
|
+
case 'blocked':
|
|
170
|
+
agg.blockedCycles++;
|
|
171
|
+
break;
|
|
172
|
+
case 'error':
|
|
173
|
+
agg.errorCycles++;
|
|
174
|
+
break;
|
|
175
|
+
case 'cancelled':
|
|
176
|
+
// Cancelled cycles don't count towards any specific category
|
|
177
|
+
// but are still counted in totalCycles
|
|
178
|
+
break;
|
|
179
|
+
default:
|
|
180
|
+
assertNever(metrics.outcome, `Unhandled CycleOutcome: ${metrics.outcome}`);
|
|
181
|
+
}
|
|
182
|
+
// Recalculate averages using all recent metrics
|
|
183
|
+
const durations = this.recentCycleMetrics.map((m) => m.durationMs);
|
|
184
|
+
const idleTimes = this.recentCycleMetrics.map((m) => m.idleDetectionMs);
|
|
185
|
+
if (durations.length > 0) {
|
|
186
|
+
agg.avgCycleDurationMs = Math.round(durations.reduce((a, b) => a + b, 0) / durations.length);
|
|
187
|
+
agg.avgIdleDetectionMs = Math.round(idleTimes.reduce((a, b) => a + b, 0) / idleTimes.length);
|
|
188
|
+
// Calculate P90
|
|
189
|
+
const sortedDurations = [...durations].sort((a, b) => a - b);
|
|
190
|
+
const p90Index = Math.floor(sortedDurations.length * 0.9);
|
|
191
|
+
agg.p90CycleDurationMs = sortedDurations[p90Index];
|
|
192
|
+
}
|
|
193
|
+
// Calculate success rate
|
|
194
|
+
agg.successRate = agg.totalCycles > 0 ? Math.round((agg.successfulCycles / agg.totalCycles) * 100) : 100;
|
|
195
|
+
agg.lastUpdatedAt = Date.now();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=respawn-metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"respawn-metrics.js","sourceRoot":"","sources":["../src/respawn-metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C;;GAEG;AACH,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,OAAO,0BAA0B;IACrC,kCAAkC;IAC1B,mBAAmB,GAAwC,IAAI,CAAC;IAExE,sEAAsE;IAC9D,kBAAkB,GAA0B,EAAE,CAAC;IAEvD,kDAAkD;IAC1C,gBAAgB,GAA4B;QAClD,WAAW,EAAE,CAAC;QACd,gBAAgB,EAAE,CAAC;QACnB,mBAAmB,EAAE,CAAC;QACtB,aAAa,EAAE,CAAC;QAChB,WAAW,EAAE,CAAC;QACd,kBAAkB,EAAE,CAAC;QACrB,kBAAkB,EAAE,CAAC;QACrB,kBAAkB,EAAE,CAAC;QACrB,WAAW,EAAE,GAAG;QAChB,aAAa,EAAE,IAAI,CAAC,GAAG,EAAE;KAC1B,CAAC;IAEF;;;;;;;;;;OAUG;IACH,UAAU,CACR,SAAiB,EACjB,WAAmB,EACnB,UAAkB,EAClB,sBAA8B,EAC9B,cAAsB,EACtB,2BAAmC;QAEnC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,mBAAmB,GAAG;YACzB,OAAO,EAAE,GAAG,SAAS,IAAI,WAAW,EAAE;YACtC,SAAS;YACT,WAAW;YACX,SAAS,EAAE,GAAG;YACd,UAAU;YACV,eAAe,EAAE,GAAG,GAAG,sBAAsB;YAC7C,cAAc,EAAE,EAAE;YA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C,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,gBAAgB,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QAEzG,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Pure utility functions for terminal pattern detection in respawn controller.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from respawn-controller.ts for modularity. These are stateless functions
|
|
5
|
+
* and constants used to detect completion messages, working patterns, and token counts
|
|
6
|
+
* in terminal output.
|
|
7
|
+
*
|
|
8
|
+
* @module respawn-patterns
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Patterns indicating Claude is ready for input (legacy fallback).
|
|
12
|
+
* Used as secondary signals, not primary detection.
|
|
13
|
+
*/
|
|
14
|
+
export declare const PROMPT_PATTERNS: string[];
|
|
15
|
+
/**
|
|
16
|
+
* Patterns indicating Claude is actively working.
|
|
17
|
+
* When detected, resets all idle detection timers.
|
|
18
|
+
* Note: ✻ and ✽ removed - they appear in completion messages too.
|
|
19
|
+
*/
|
|
20
|
+
export declare const WORKING_PATTERNS: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Check if data contains a completion message pattern.
|
|
23
|
+
* Matches "Worked for Xh Xm Xs" time duration patterns.
|
|
24
|
+
*
|
|
25
|
+
* @param data - Raw terminal output data
|
|
26
|
+
* @returns True if completion message pattern is found
|
|
27
|
+
*/
|
|
28
|
+
export declare function isCompletionMessage(data: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a rolling window of terminal output contains working patterns.
|
|
31
|
+
* The rolling window catches patterns split across chunks (e.g., "Thin" + "king").
|
|
32
|
+
*
|
|
33
|
+
* @param window - Rolling window of recent terminal output (already includes current data)
|
|
34
|
+
* @returns True if any working pattern is found in the window
|
|
35
|
+
*/
|
|
36
|
+
export declare function hasWorkingPattern(window: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Extract token count from data if present.
|
|
39
|
+
* Parses patterns like "123.4k tokens" or "1.5M tokens".
|
|
40
|
+
*
|
|
41
|
+
* @param data - Raw terminal output data
|
|
42
|
+
* @returns Parsed token count, or null if no token pattern found
|
|
43
|
+
*/
|
|
44
|
+
export declare function extractTokenCount(data: string): number | null;
|
|
45
|
+
//# sourceMappingURL=respawn-patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"respawn-patterns.d.ts","sourceRoot":"","sources":["../src/respawn-patterns.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgBH;;;GAGG;AACH,eAAO,MAAM,eAAe,UAI3B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,UAkD5B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAU7D"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Pure utility functions for terminal pattern detection in respawn controller.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from respawn-controller.ts for modularity. These are stateless functions
|
|
5
|
+
* and constants used to detect completion messages, working patterns, and token counts
|
|
6
|
+
* in terminal output.
|
|
7
|
+
*
|
|
8
|
+
* @module respawn-patterns
|
|
9
|
+
*/
|
|
10
|
+
import { TOKEN_PATTERN } from './utils/index.js';
|
|
11
|
+
// ========== Constants ==========
|
|
12
|
+
/**
|
|
13
|
+
* Pattern to detect completion messages from Claude Code.
|
|
14
|
+
* Requires "Worked for" prefix to avoid false positives from bare time durations
|
|
15
|
+
* in regular text (e.g., "wait for 5s", "run for 2m").
|
|
16
|
+
*
|
|
17
|
+
* Matches: "Worked for 2m 46s", "Worked for 46s", "Worked for 1h 2m 3s"
|
|
18
|
+
* Does NOT match: "wait for 5s", "run for 2m", "for 3s the system..."
|
|
19
|
+
*/
|
|
20
|
+
const COMPLETION_TIME_PATTERN = /\bWorked\s+for\s+\d+[hms](\s*\d+[hms])*/i;
|
|
21
|
+
/**
|
|
22
|
+
* Patterns indicating Claude is ready for input (legacy fallback).
|
|
23
|
+
* Used as secondary signals, not primary detection.
|
|
24
|
+
*/
|
|
25
|
+
export const PROMPT_PATTERNS = [
|
|
26
|
+
'❯', // Standard prompt
|
|
27
|
+
'\u276f', // Unicode variant
|
|
28
|
+
'⏵', // Claude Code prompt variant
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* Patterns indicating Claude is actively working.
|
|
32
|
+
* When detected, resets all idle detection timers.
|
|
33
|
+
* Note: ✻ and ✽ removed - they appear in completion messages too.
|
|
34
|
+
*/
|
|
35
|
+
export const WORKING_PATTERNS = [
|
|
36
|
+
'Thinking',
|
|
37
|
+
'Writing',
|
|
38
|
+
'Reading',
|
|
39
|
+
'Running',
|
|
40
|
+
'Searching',
|
|
41
|
+
'Editing',
|
|
42
|
+
'Creating',
|
|
43
|
+
'Deleting',
|
|
44
|
+
'Analyzing',
|
|
45
|
+
'Executing',
|
|
46
|
+
'Synthesizing',
|
|
47
|
+
'Brewing', // Claude's processing indicators
|
|
48
|
+
'Compiling',
|
|
49
|
+
'Building',
|
|
50
|
+
'Installing',
|
|
51
|
+
'Fetching',
|
|
52
|
+
'Downloading',
|
|
53
|
+
'Processing',
|
|
54
|
+
'Generating',
|
|
55
|
+
'Loading',
|
|
56
|
+
'Starting',
|
|
57
|
+
'Updating',
|
|
58
|
+
'Checking',
|
|
59
|
+
'Validating',
|
|
60
|
+
'Testing',
|
|
61
|
+
'Formatting',
|
|
62
|
+
'Linting',
|
|
63
|
+
'⠋',
|
|
64
|
+
'⠙',
|
|
65
|
+
'⠹',
|
|
66
|
+
'⠸',
|
|
67
|
+
'⠼',
|
|
68
|
+
'⠴',
|
|
69
|
+
'⠦',
|
|
70
|
+
'⠧',
|
|
71
|
+
'⠇',
|
|
72
|
+
'⠏', // Spinner chars
|
|
73
|
+
'◐',
|
|
74
|
+
'◓',
|
|
75
|
+
'◑',
|
|
76
|
+
'◒', // Alternative spinners
|
|
77
|
+
'⣾',
|
|
78
|
+
'⣽',
|
|
79
|
+
'⣻',
|
|
80
|
+
'⢿',
|
|
81
|
+
'⡿',
|
|
82
|
+
'⣟',
|
|
83
|
+
'⣯',
|
|
84
|
+
'⣷', // Braille spinners
|
|
85
|
+
];
|
|
86
|
+
/**
|
|
87
|
+
* Check if data contains a completion message pattern.
|
|
88
|
+
* Matches "Worked for Xh Xm Xs" time duration patterns.
|
|
89
|
+
*
|
|
90
|
+
* @param data - Raw terminal output data
|
|
91
|
+
* @returns True if completion message pattern is found
|
|
92
|
+
*/
|
|
93
|
+
export function isCompletionMessage(data) {
|
|
94
|
+
return COMPLETION_TIME_PATTERN.test(data);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check if a rolling window of terminal output contains working patterns.
|
|
98
|
+
* The rolling window catches patterns split across chunks (e.g., "Thin" + "king").
|
|
99
|
+
*
|
|
100
|
+
* @param window - Rolling window of recent terminal output (already includes current data)
|
|
101
|
+
* @returns True if any working pattern is found in the window
|
|
102
|
+
*/
|
|
103
|
+
export function hasWorkingPattern(window) {
|
|
104
|
+
return WORKING_PATTERNS.some((pattern) => window.includes(pattern));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Extract token count from data if present.
|
|
108
|
+
* Parses patterns like "123.4k tokens" or "1.5M tokens".
|
|
109
|
+
*
|
|
110
|
+
* @param data - Raw terminal output data
|
|
111
|
+
* @returns Parsed token count, or null if no token pattern found
|
|
112
|
+
*/
|
|
113
|
+
export function extractTokenCount(data) {
|
|
114
|
+
const match = data.match(TOKEN_PATTERN);
|
|
115
|
+
if (!match)
|
|
116
|
+
return null;
|
|
117
|
+
let count = parseFloat(match[1]);
|
|
118
|
+
const suffix = match[2]?.toLowerCase();
|
|
119
|
+
if (suffix === 'k')
|
|
120
|
+
count *= 1000;
|
|
121
|
+
else if (suffix === 'm')
|
|
122
|
+
count *= 1000000;
|
|
123
|
+
return Math.round(count);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=respawn-patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"respawn-patterns.js","sourceRoot":"","sources":["../src/respawn-patterns.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,kCAAkC;AAElC;;;;;;;GAOG;AACH,MAAM,uBAAuB,GAAG,0CAA0C,CAAC;AAE3E;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,GAAG,EAAE,kBAAkB;IACvB,QAAQ,EAAE,kBAAkB;IAC5B,GAAG,EAAE,6BAA6B;CACnC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,UAAU;IACV,SAAS;IACT,SAAS;IACT,SAAS;IACT,WAAW;IACX,SAAS;IACT,UAAU;IACV,UAAU;IACV,WAAW;IACX,WAAW;IACX,cAAc;IACd,SAAS,EAAE,iCAAiC;IAC5C,WAAW;IACX,UAAU;IACV,YAAY;IACZ,UAAU;IACV,aAAa;IACb,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,UAAU;IACV,UAAU;IACV,UAAU;IACV,YAAY;IACZ,SAAS;IACT,YAAY;IACZ,SAAS;IACT,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG,EAAE,gBAAgB;IACrB,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG,EAAE,uBAAuB;IAC5B,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG,EAAE,mBAAmB;CACzB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACxC,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAExB,IAAI,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;IACvC,IAAI,MAAM,KAAK,GAAG;QAAE,KAAK,IAAI,IAAI,CAAC;SAC7B,IAAI,MAAM,KAAK,GAAG;QAAE,KAAK,IAAI,OAAO,CAAC;IAE1C,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Auto-compact and auto-clear automation for Session.
|
|
3
|
+
*
|
|
4
|
+
* Monitors token counts and triggers /compact or /clear commands when
|
|
5
|
+
* configurable thresholds are reached. Waits for Claude to be idle
|
|
6
|
+
* before sending commands, with retry logic and mutual exclusion
|
|
7
|
+
* (compact and clear never run simultaneously).
|
|
8
|
+
*
|
|
9
|
+
* @module session-auto-ops
|
|
10
|
+
*/
|
|
11
|
+
import { EventEmitter } from 'node:events';
|
|
12
|
+
/**
|
|
13
|
+
* Callbacks required by SessionAutoOps to interact with the parent Session.
|
|
14
|
+
*/
|
|
15
|
+
export interface AutoOpsCallbacks {
|
|
16
|
+
/** Send a command via the terminal multiplexer */
|
|
17
|
+
writeCommand: (command: string) => Promise<boolean>;
|
|
18
|
+
/** Check if Claude is currently working */
|
|
19
|
+
isWorking: () => boolean;
|
|
20
|
+
/** Check if the session has been stopped */
|
|
21
|
+
isStopped: () => boolean;
|
|
22
|
+
/** Get current total token count (input + output) */
|
|
23
|
+
getTotalTokens: () => number;
|
|
24
|
+
/** Get session ID for logging */
|
|
25
|
+
getSessionId: () => string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Events emitted by SessionAutoOps.
|
|
29
|
+
*/
|
|
30
|
+
export interface SessionAutoOpsEvents {
|
|
31
|
+
/** Auto-compact was triggered and the /compact command was sent */
|
|
32
|
+
autoCompact: (data: {
|
|
33
|
+
tokens: number;
|
|
34
|
+
threshold: number;
|
|
35
|
+
prompt?: string;
|
|
36
|
+
}) => void;
|
|
37
|
+
/** Auto-clear was triggered and the /clear command was sent */
|
|
38
|
+
autoClear: (data: {
|
|
39
|
+
tokens: number;
|
|
40
|
+
threshold: number;
|
|
41
|
+
}) => void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Manages auto-compact and auto-clear automation for a Session.
|
|
45
|
+
*
|
|
46
|
+
* When enabled, monitors token counts after each update and triggers
|
|
47
|
+
* /compact or /clear commands when thresholds are exceeded. Ensures
|
|
48
|
+
* mutual exclusion between compact and clear operations.
|
|
49
|
+
*/
|
|
50
|
+
export declare class SessionAutoOps extends EventEmitter {
|
|
51
|
+
private _autoCompactThreshold;
|
|
52
|
+
private _autoCompactEnabled;
|
|
53
|
+
private _autoCompactPrompt;
|
|
54
|
+
private _isCompacting;
|
|
55
|
+
private _autoCompactTimer;
|
|
56
|
+
private _autoClearThreshold;
|
|
57
|
+
private _autoClearEnabled;
|
|
58
|
+
private _isClearing;
|
|
59
|
+
private _autoClearTimer;
|
|
60
|
+
private readonly callbacks;
|
|
61
|
+
constructor(callbacks: AutoOpsCallbacks, config?: {
|
|
62
|
+
compactThreshold?: number;
|
|
63
|
+
clearThreshold?: number;
|
|
64
|
+
});
|
|
65
|
+
get autoCompactThreshold(): number;
|
|
66
|
+
get autoCompactEnabled(): boolean;
|
|
67
|
+
get autoCompactPrompt(): string;
|
|
68
|
+
get isCompacting(): boolean;
|
|
69
|
+
setAutoCompact(enabled: boolean, threshold?: number, prompt?: string): void;
|
|
70
|
+
get autoClearThreshold(): number;
|
|
71
|
+
get autoClearEnabled(): boolean;
|
|
72
|
+
get isClearing(): boolean;
|
|
73
|
+
setAutoClear(enabled: boolean, threshold?: number): void;
|
|
74
|
+
/**
|
|
75
|
+
* Check if auto-compact should be triggered based on current token count.
|
|
76
|
+
* Called after token count updates.
|
|
77
|
+
*/
|
|
78
|
+
checkAutoCompact(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Check if auto-clear should be triggered based on current token count.
|
|
81
|
+
* Called after token count updates.
|
|
82
|
+
*/
|
|
83
|
+
checkAutoClear(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Clear all timers and reset state. Called when the session stops.
|
|
86
|
+
*/
|
|
87
|
+
destroy(): void;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=session-auto-ops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-auto-ops.d.ts","sourceRoot":"","sources":["../src/session-auto-ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA8B3C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACpD,2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