@stackmemoryai/stackmemory 0.5.58 → 0.5.59
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/dist/cli/commands/search.js +20 -3
- package/dist/cli/commands/search.js.map +2 -2
- package/dist/core/database/sqlite-adapter.js +13 -3
- package/dist/core/database/sqlite-adapter.js.map +2 -2
- package/dist/core/errors/error-utils.js +208 -0
- package/dist/core/errors/error-utils.js.map +7 -0
- package/dist/core/errors/index.js +13 -4
- package/dist/core/errors/index.js.map +2 -2
- package/dist/core/merge/unified-merge-resolver.js +303 -0
- package/dist/core/merge/unified-merge-resolver.js.map +7 -0
- package/dist/core/monitoring/logger.js +61 -9
- package/dist/core/monitoring/logger.js.map +2 -2
- package/dist/core/security/index.js +35 -0
- package/dist/core/security/index.js.map +7 -0
- package/dist/core/security/input-sanitizer.js +321 -0
- package/dist/core/security/input-sanitizer.js.map +7 -0
- package/dist/integrations/linear/client.js +5 -1
- package/dist/integrations/linear/client.js.map +2 -2
- package/dist/integrations/mcp/remote-server.js +27 -36
- package/dist/integrations/mcp/remote-server.js.map +2 -2
- package/dist/integrations/mcp/server.js +44 -29
- package/dist/integrations/mcp/server.js.map +3 -3
- package/dist/scripts/benchmark-performance.js +48 -0
- package/dist/scripts/benchmark-performance.js.map +7 -0
- package/dist/scripts/check-redis.js +42 -0
- package/dist/scripts/check-redis.js.map +7 -0
- package/dist/scripts/initialize.js +116 -0
- package/dist/scripts/initialize.js.map +7 -0
- package/dist/scripts/list-linear-tasks.js +124 -0
- package/dist/scripts/list-linear-tasks.js.map +7 -0
- package/dist/scripts/measure-handoff-impact.js +340 -0
- package/dist/scripts/measure-handoff-impact.js.map +7 -0
- package/dist/scripts/query-chromadb.js +160 -0
- package/dist/scripts/query-chromadb.js.map +7 -0
- package/dist/scripts/show-linear-summary.js +119 -0
- package/dist/scripts/show-linear-summary.js.map +7 -0
- package/dist/scripts/simple-swarm-demo.js +90 -0
- package/dist/scripts/simple-swarm-demo.js.map +7 -0
- package/dist/scripts/status.js +155 -0
- package/dist/scripts/status.js.map +7 -0
- package/dist/scripts/test-chromadb-sync.js +192 -0
- package/dist/scripts/test-chromadb-sync.js.map +7 -0
- package/dist/scripts/test-ralph-iteration-fix.js +86 -0
- package/dist/scripts/test-ralph-iteration-fix.js.map +7 -0
- package/dist/scripts/test-ralph-iterations.js +121 -0
- package/dist/scripts/test-ralph-iterations.js.map +7 -0
- package/dist/scripts/test-redis-storage.js +389 -0
- package/dist/scripts/test-redis-storage.js.map +7 -0
- package/dist/scripts/test-simple-ralph-state-sync.js +115 -0
- package/dist/scripts/test-simple-ralph-state-sync.js.map +7 -0
- package/dist/scripts/test-swarm-fixes.js +125 -0
- package/dist/scripts/test-swarm-fixes.js.map +7 -0
- package/dist/scripts/test-swarm-tui.js +23 -0
- package/dist/scripts/test-swarm-tui.js.map +7 -0
- package/dist/scripts/test-tui-shortcuts.js +52 -0
- package/dist/scripts/test-tui-shortcuts.js.map +7 -0
- package/dist/scripts/validate-tui-shortcuts.js +60 -0
- package/dist/scripts/validate-tui-shortcuts.js.map +7 -0
- package/dist/src/agents/core/agent-task-manager.js +527 -0
- package/dist/src/agents/core/agent-task-manager.js.map +7 -0
- package/dist/src/agents/verifiers/base-verifier.js +133 -0
- package/dist/src/agents/verifiers/base-verifier.js.map +7 -0
- package/dist/src/agents/verifiers/formatter-verifier.js +130 -0
- package/dist/src/agents/verifiers/formatter-verifier.js.map +7 -0
- package/dist/src/agents/verifiers/llm-judge.js +252 -0
- package/dist/src/agents/verifiers/llm-judge.js.map +7 -0
- package/dist/src/cli/auto-detect.js +321 -0
- package/dist/src/cli/auto-detect.js.map +7 -0
- package/dist/src/cli/claude-sm-danger.js +21 -0
- package/dist/src/cli/claude-sm-danger.js.map +7 -0
- package/dist/src/cli/claude-sm.js +1156 -0
- package/dist/src/cli/claude-sm.js.map +7 -0
- package/dist/src/cli/codex-sm-danger.js +21 -0
- package/dist/src/cli/codex-sm-danger.js.map +7 -0
- package/dist/src/cli/codex-sm.js +349 -0
- package/dist/src/cli/codex-sm.js.map +7 -0
- package/dist/src/cli/commands/api.js +232 -0
- package/dist/src/cli/commands/api.js.map +7 -0
- package/dist/src/cli/commands/auto-background.js +180 -0
- package/dist/src/cli/commands/auto-background.js.map +7 -0
- package/dist/src/cli/commands/cleanup-processes.js +68 -0
- package/dist/src/cli/commands/cleanup-processes.js.map +7 -0
- package/dist/src/cli/commands/clear.js +202 -0
- package/dist/src/cli/commands/clear.js.map +7 -0
- package/dist/src/cli/commands/config.js +445 -0
- package/dist/src/cli/commands/config.js.map +7 -0
- package/dist/src/cli/commands/context-rehydrate.js +751 -0
- package/dist/src/cli/commands/context-rehydrate.js.map +7 -0
- package/dist/src/cli/commands/context.js +343 -0
- package/dist/src/cli/commands/context.js.map +7 -0
- package/dist/src/cli/commands/daemon.js +392 -0
- package/dist/src/cli/commands/daemon.js.map +7 -0
- package/dist/src/cli/commands/dashboard.js +210 -0
- package/dist/src/cli/commands/dashboard.js.map +7 -0
- package/dist/src/cli/commands/db.js +147 -0
- package/dist/src/cli/commands/db.js.map +7 -0
- package/dist/src/cli/commands/decision.js +266 -0
- package/dist/src/cli/commands/decision.js.map +7 -0
- package/dist/src/cli/commands/discovery.js +279 -0
- package/dist/src/cli/commands/discovery.js.map +7 -0
- package/dist/src/cli/commands/handoff.js +624 -0
- package/dist/src/cli/commands/handoff.js.map +7 -0
- package/dist/src/cli/commands/hooks.js +298 -0
- package/dist/src/cli/commands/hooks.js.map +7 -0
- package/dist/src/cli/commands/linear.js +529 -0
- package/dist/src/cli/commands/linear.js.map +7 -0
- package/dist/src/cli/commands/log.js +169 -0
- package/dist/src/cli/commands/log.js.map +7 -0
- package/dist/src/cli/commands/login.js +172 -0
- package/dist/src/cli/commands/login.js.map +7 -0
- package/dist/src/cli/commands/migrate.js +240 -0
- package/dist/src/cli/commands/migrate.js.map +7 -0
- package/dist/src/cli/commands/model.js +533 -0
- package/dist/src/cli/commands/model.js.map +7 -0
- package/dist/src/cli/commands/onboard.js +536 -0
- package/dist/src/cli/commands/onboard.js.map +7 -0
- package/dist/src/cli/commands/projects.js +199 -0
- package/dist/src/cli/commands/projects.js.map +7 -0
- package/dist/src/cli/commands/ralph.js +909 -0
- package/dist/src/cli/commands/ralph.js.map +7 -0
- package/dist/src/cli/commands/retrieval.js +248 -0
- package/dist/src/cli/commands/retrieval.js.map +7 -0
- package/dist/src/cli/commands/search.js +173 -0
- package/dist/src/cli/commands/search.js.map +7 -0
- package/dist/src/cli/commands/service.js +749 -0
- package/dist/src/cli/commands/service.js.map +7 -0
- package/dist/src/cli/commands/session.js +200 -0
- package/dist/src/cli/commands/session.js.map +7 -0
- package/dist/src/cli/commands/settings.js +306 -0
- package/dist/src/cli/commands/settings.js.map +7 -0
- package/dist/src/cli/commands/setup.js +701 -0
- package/dist/src/cli/commands/setup.js.map +7 -0
- package/dist/src/cli/commands/shell.js +249 -0
- package/dist/src/cli/commands/shell.js.map +7 -0
- package/dist/src/cli/commands/signup.js +50 -0
- package/dist/src/cli/commands/signup.js.map +7 -0
- package/dist/src/cli/commands/skills.js +470 -0
- package/dist/src/cli/commands/skills.js.map +7 -0
- package/dist/src/cli/commands/sms-notify.js +795 -0
- package/dist/src/cli/commands/sms-notify.js.map +7 -0
- package/dist/src/cli/commands/storage-tier.js +183 -0
- package/dist/src/cli/commands/storage-tier.js.map +7 -0
- package/dist/src/cli/commands/sweep.js +249 -0
- package/dist/src/cli/commands/sweep.js.map +7 -0
- package/dist/src/cli/commands/tasks.js +213 -0
- package/dist/src/cli/commands/tasks.js.map +7 -0
- package/dist/src/cli/commands/worktree.js +319 -0
- package/dist/src/cli/commands/worktree.js.map +7 -0
- package/dist/src/cli/index.js +594 -0
- package/dist/src/cli/index.js.map +7 -0
- package/dist/src/cli/opencode-sm.js +448 -0
- package/dist/src/cli/opencode-sm.js.map +7 -0
- package/dist/src/cli/utils/viewer.js +96 -0
- package/dist/src/cli/utils/viewer.js.map +7 -0
- package/dist/src/core/config/config-manager.js +398 -0
- package/dist/src/core/config/config-manager.js.map +7 -0
- package/dist/src/core/config/feature-flags.js +76 -0
- package/dist/src/core/config/feature-flags.js.map +7 -0
- package/dist/src/core/config/storage-config.js +115 -0
- package/dist/src/core/config/storage-config.js.map +7 -0
- package/dist/src/core/config/types.js +144 -0
- package/dist/src/core/config/types.js.map +7 -0
- package/dist/src/core/context/auto-context.js +80 -0
- package/dist/src/core/context/auto-context.js.map +7 -0
- package/dist/src/core/context/dual-stack-manager.js +870 -0
- package/dist/src/core/context/dual-stack-manager.js.map +7 -0
- package/dist/src/core/context/enhanced-rehydration.js +994 -0
- package/dist/src/core/context/enhanced-rehydration.js.map +7 -0
- package/dist/src/core/context/frame-database.js +479 -0
- package/dist/src/core/context/frame-database.js.map +7 -0
- package/dist/src/core/context/frame-digest.js +250 -0
- package/dist/src/core/context/frame-digest.js.map +7 -0
- package/dist/src/core/context/frame-handoff-manager.js +778 -0
- package/dist/src/core/context/frame-handoff-manager.js.map +7 -0
- package/dist/src/core/context/frame-lifecycle-hooks.js +119 -0
- package/dist/src/core/context/frame-lifecycle-hooks.js.map +7 -0
- package/dist/src/core/context/frame-recovery.js +302 -0
- package/dist/src/core/context/frame-recovery.js.map +7 -0
- package/dist/src/core/context/frame-stack.js +314 -0
- package/dist/src/core/context/frame-stack.js.map +7 -0
- package/dist/src/core/context/frame-types.js +5 -0
- package/dist/src/core/context/frame-types.js.map +7 -0
- package/dist/src/core/context/index.js +25 -0
- package/dist/src/core/context/index.js.map +7 -0
- package/dist/src/core/context/permission-manager.js +185 -0
- package/dist/src/core/context/permission-manager.js.map +7 -0
- package/dist/src/core/context/recursive-context-manager.js +592 -0
- package/dist/src/core/context/recursive-context-manager.js.map +7 -0
- package/dist/src/core/context/refactored-frame-manager.js +754 -0
- package/dist/src/core/context/refactored-frame-manager.js.map +7 -0
- package/dist/src/core/context/shared-context-layer.js +621 -0
- package/dist/src/core/context/shared-context-layer.js.map +7 -0
- package/dist/src/core/context/stack-merge-resolver.js +749 -0
- package/dist/src/core/context/stack-merge-resolver.js.map +7 -0
- package/dist/src/core/context/validation.js +130 -0
- package/dist/src/core/context/validation.js.map +7 -0
- package/dist/src/core/database/batch-operations.js +384 -0
- package/dist/src/core/database/batch-operations.js.map +7 -0
- package/dist/src/core/database/connection-pool.js +330 -0
- package/dist/src/core/database/connection-pool.js.map +7 -0
- package/dist/src/core/database/database-adapter.js +60 -0
- package/dist/src/core/database/database-adapter.js.map +7 -0
- package/dist/src/core/database/migration-manager.js +614 -0
- package/dist/src/core/database/migration-manager.js.map +7 -0
- package/dist/src/core/database/query-cache.js +298 -0
- package/dist/src/core/database/query-cache.js.map +7 -0
- package/dist/src/core/database/query-router.js +430 -0
- package/dist/src/core/database/query-router.js.map +7 -0
- package/dist/src/core/database/sqlite-adapter.js +738 -0
- package/dist/src/core/database/sqlite-adapter.js.map +7 -0
- package/dist/src/core/digest/enhanced-hybrid-digest.js +277 -0
- package/dist/src/core/digest/enhanced-hybrid-digest.js.map +7 -0
- package/dist/src/core/digest/frame-digest-integration.js +176 -0
- package/dist/src/core/digest/frame-digest-integration.js.map +7 -0
- package/dist/src/core/digest/hybrid-digest-generator.js +553 -0
- package/dist/src/core/digest/hybrid-digest-generator.js.map +7 -0
- package/dist/src/core/digest/index.js +9 -0
- package/dist/src/core/digest/index.js.map +7 -0
- package/dist/src/core/digest/types.js +25 -0
- package/dist/src/core/digest/types.js.map +7 -0
- package/dist/src/core/errors/error-utils.js +208 -0
- package/dist/src/core/errors/error-utils.js.map +7 -0
- package/dist/src/core/errors/index.js +521 -0
- package/dist/src/core/errors/index.js.map +7 -0
- package/dist/src/core/errors/recovery.js +269 -0
- package/dist/src/core/errors/recovery.js.map +7 -0
- package/dist/src/core/execution/parallel-executor.js +258 -0
- package/dist/src/core/execution/parallel-executor.js.map +7 -0
- package/dist/src/core/frame/workflow-templates.js +319 -0
- package/dist/src/core/frame/workflow-templates.js.map +7 -0
- package/dist/src/core/merge/conflict-detector.js +431 -0
- package/dist/src/core/merge/conflict-detector.js.map +7 -0
- package/dist/src/core/merge/index.js +9 -0
- package/dist/src/core/merge/index.js.map +7 -0
- package/dist/src/core/merge/resolution-engine.js +558 -0
- package/dist/src/core/merge/resolution-engine.js.map +7 -0
- package/dist/src/core/merge/stack-diff.js +532 -0
- package/dist/src/core/merge/stack-diff.js.map +7 -0
- package/dist/src/core/merge/types.js +5 -0
- package/dist/src/core/merge/types.js.map +7 -0
- package/dist/src/core/merge/unified-merge-resolver.js +303 -0
- package/dist/src/core/merge/unified-merge-resolver.js.map +7 -0
- package/dist/src/core/models/fallback-monitor.js +232 -0
- package/dist/src/core/models/fallback-monitor.js.map +7 -0
- package/dist/src/core/models/model-router.js +340 -0
- package/dist/src/core/models/model-router.js.map +7 -0
- package/dist/src/core/monitoring/error-handler.js +49 -0
- package/dist/src/core/monitoring/error-handler.js.map +7 -0
- package/dist/src/core/monitoring/logger.js +202 -0
- package/dist/src/core/monitoring/logger.js.map +7 -0
- package/dist/src/core/monitoring/metrics.js +172 -0
- package/dist/src/core/monitoring/metrics.js.map +7 -0
- package/dist/src/core/monitoring/progress-tracker.js +189 -0
- package/dist/src/core/monitoring/progress-tracker.js.map +7 -0
- package/dist/src/core/monitoring/session-monitor.js +300 -0
- package/dist/src/core/monitoring/session-monitor.js.map +7 -0
- package/dist/src/core/performance/context-cache.js +273 -0
- package/dist/src/core/performance/context-cache.js.map +7 -0
- package/dist/src/core/performance/index.js +11 -0
- package/dist/src/core/performance/index.js.map +7 -0
- package/dist/src/core/performance/lazy-context-loader.js +327 -0
- package/dist/src/core/performance/lazy-context-loader.js.map +7 -0
- package/dist/src/core/performance/monitor.js +221 -0
- package/dist/src/core/performance/monitor.js.map +7 -0
- package/dist/src/core/performance/optimized-frame-context.js +345 -0
- package/dist/src/core/performance/optimized-frame-context.js.map +7 -0
- package/dist/src/core/performance/performance-benchmark.js +277 -0
- package/dist/src/core/performance/performance-benchmark.js.map +7 -0
- package/dist/src/core/performance/performance-profiler.js +370 -0
- package/dist/src/core/performance/performance-profiler.js.map +7 -0
- package/dist/src/core/performance/streaming-jsonl-parser.js +195 -0
- package/dist/src/core/performance/streaming-jsonl-parser.js.map +7 -0
- package/dist/src/core/persistence/postgres-adapter.js +349 -0
- package/dist/src/core/persistence/postgres-adapter.js.map +7 -0
- package/dist/src/core/projects/project-isolation.js +201 -0
- package/dist/src/core/projects/project-isolation.js.map +7 -0
- package/dist/src/core/projects/project-manager.js +697 -0
- package/dist/src/core/projects/project-manager.js.map +7 -0
- package/dist/src/core/query/query-parser.js +370 -0
- package/dist/src/core/query/query-parser.js.map +7 -0
- package/dist/src/core/query/query-templates.js +321 -0
- package/dist/src/core/query/query-templates.js.map +7 -0
- package/dist/src/core/retrieval/context-retriever.js +479 -0
- package/dist/src/core/retrieval/context-retriever.js.map +7 -0
- package/dist/src/core/retrieval/index.js +8 -0
- package/dist/src/core/retrieval/index.js.map +7 -0
- package/dist/src/core/retrieval/llm-context-retrieval.js +613 -0
- package/dist/src/core/retrieval/llm-context-retrieval.js.map +7 -0
- package/dist/src/core/retrieval/llm-provider.js +151 -0
- package/dist/src/core/retrieval/llm-provider.js.map +7 -0
- package/dist/src/core/retrieval/retrieval-audit.js +236 -0
- package/dist/src/core/retrieval/retrieval-audit.js.map +7 -0
- package/dist/src/core/retrieval/summary-generator.js +589 -0
- package/dist/src/core/retrieval/summary-generator.js.map +7 -0
- package/dist/src/core/retrieval/types.js +21 -0
- package/dist/src/core/retrieval/types.js.map +7 -0
- package/dist/src/core/security/index.js +35 -0
- package/dist/src/core/security/index.js.map +7 -0
- package/dist/src/core/security/input-sanitizer.js +321 -0
- package/dist/src/core/security/input-sanitizer.js.map +7 -0
- package/dist/src/core/session/clear-survival.js +465 -0
- package/dist/src/core/session/clear-survival.js.map +7 -0
- package/dist/src/core/session/enhanced-handoff.js +792 -0
- package/dist/src/core/session/enhanced-handoff.js.map +7 -0
- package/dist/src/core/session/handoff-generator.js +343 -0
- package/dist/src/core/session/handoff-generator.js.map +7 -0
- package/dist/src/core/session/index.js +15 -0
- package/dist/src/core/session/index.js.map +7 -0
- package/dist/src/core/session/session-manager.js +347 -0
- package/dist/src/core/session/session-manager.js.map +7 -0
- package/dist/src/core/skills/index.js +7 -0
- package/dist/src/core/skills/index.js.map +7 -0
- package/dist/src/core/skills/skill-storage.js +764 -0
- package/dist/src/core/skills/skill-storage.js.map +7 -0
- package/dist/src/core/skills/types.js +193 -0
- package/dist/src/core/skills/types.js.map +7 -0
- package/dist/src/core/storage/chromadb-adapter.js +354 -0
- package/dist/src/core/storage/chromadb-adapter.js.map +7 -0
- package/dist/src/core/storage/infinite-storage.js +510 -0
- package/dist/src/core/storage/infinite-storage.js.map +7 -0
- package/dist/src/core/storage/remote-storage.js +489 -0
- package/dist/src/core/storage/remote-storage.js.map +7 -0
- package/dist/src/core/storage/two-tier-storage.js +766 -0
- package/dist/src/core/storage/two-tier-storage.js.map +7 -0
- package/dist/src/core/trace/cli-trace-wrapper.js +132 -0
- package/dist/src/core/trace/cli-trace-wrapper.js.map +7 -0
- package/dist/src/core/trace/db-trace-wrapper.js +247 -0
- package/dist/src/core/trace/db-trace-wrapper.js.map +7 -0
- package/dist/src/core/trace/debug-trace.js +417 -0
- package/dist/src/core/trace/debug-trace.js.map +7 -0
- package/dist/src/core/trace/index.js +109 -0
- package/dist/src/core/trace/index.js.map +7 -0
- package/dist/src/core/trace/linear-api-wrapper.js +178 -0
- package/dist/src/core/trace/linear-api-wrapper.js.map +7 -0
- package/dist/src/core/trace/trace-detector.js +528 -0
- package/dist/src/core/trace/trace-detector.js.map +7 -0
- package/dist/src/core/trace/trace-store.js +345 -0
- package/dist/src/core/trace/trace-store.js.map +7 -0
- package/dist/src/core/trace/types.js +77 -0
- package/dist/src/core/trace/types.js.map +7 -0
- package/dist/src/core/types.js +5 -0
- package/dist/src/core/types.js.map +7 -0
- package/dist/src/core/utils/async-mutex.js +114 -0
- package/dist/src/core/utils/async-mutex.js.map +7 -0
- package/dist/src/core/utils/compression.js +83 -0
- package/dist/src/core/utils/compression.js.map +7 -0
- package/dist/src/core/utils/update-checker.js +218 -0
- package/dist/src/core/utils/update-checker.js.map +7 -0
- package/dist/src/core/worktree/worktree-manager.js +465 -0
- package/dist/src/core/worktree/worktree-manager.js.map +7 -0
- package/dist/src/daemon/daemon-config.js +149 -0
- package/dist/src/daemon/daemon-config.js.map +7 -0
- package/dist/src/daemon/services/context-service.js +122 -0
- package/dist/src/daemon/services/context-service.js.map +7 -0
- package/dist/src/daemon/services/linear-service.js +136 -0
- package/dist/src/daemon/services/linear-service.js.map +7 -0
- package/dist/src/daemon/session-daemon.js +312 -0
- package/dist/src/daemon/session-daemon.js.map +7 -0
- package/dist/src/daemon/unified-daemon.js +276 -0
- package/dist/src/daemon/unified-daemon.js.map +7 -0
- package/dist/src/features/analytics/api/analytics-api.js +287 -0
- package/dist/src/features/analytics/api/analytics-api.js.map +7 -0
- package/dist/src/features/analytics/core/analytics-service.js +282 -0
- package/dist/src/features/analytics/core/analytics-service.js.map +7 -0
- package/dist/src/features/analytics/index.js +18 -0
- package/dist/src/features/analytics/index.js.map +7 -0
- package/dist/src/features/analytics/queries/metrics-queries.js +277 -0
- package/dist/src/features/analytics/queries/metrics-queries.js.map +7 -0
- package/dist/src/features/analytics/types/metrics.js +5 -0
- package/dist/src/features/analytics/types/metrics.js.map +7 -0
- package/dist/src/features/browser/browser-mcp.js +492 -0
- package/dist/src/features/browser/browser-mcp.js.map +7 -0
- package/dist/src/features/sweep/index.js +20 -0
- package/dist/src/features/sweep/index.js.map +7 -0
- package/dist/src/features/sweep/prediction-client.js +155 -0
- package/dist/src/features/sweep/prediction-client.js.map +7 -0
- package/dist/src/features/sweep/prompt-builder.js +85 -0
- package/dist/src/features/sweep/prompt-builder.js.map +7 -0
- package/dist/src/features/sweep/pty-wrapper.js +171 -0
- package/dist/src/features/sweep/pty-wrapper.js.map +7 -0
- package/dist/src/features/sweep/state-watcher.js +87 -0
- package/dist/src/features/sweep/state-watcher.js.map +7 -0
- package/dist/src/features/sweep/status-bar.js +88 -0
- package/dist/src/features/sweep/status-bar.js.map +7 -0
- package/dist/src/features/sweep/sweep-server-manager.js +226 -0
- package/dist/src/features/sweep/sweep-server-manager.js.map +7 -0
- package/dist/src/features/sweep/tab-interceptor.js +38 -0
- package/dist/src/features/sweep/tab-interceptor.js.map +7 -0
- package/dist/src/features/sweep/types.js +18 -0
- package/dist/src/features/sweep/types.js.map +7 -0
- package/dist/src/features/tasks/linear-task-manager.js +487 -0
- package/dist/src/features/tasks/linear-task-manager.js.map +7 -0
- package/dist/src/features/tasks/task-aware-context.js +410 -0
- package/dist/src/features/tasks/task-aware-context.js.map +7 -0
- package/dist/src/features/tui/simple-monitor.js +116 -0
- package/dist/src/features/tui/simple-monitor.js.map +7 -0
- package/dist/src/features/tui/swarm-monitor.js +648 -0
- package/dist/src/features/tui/swarm-monitor.js.map +7 -0
- package/dist/src/features/web/client/stores/task-store.js +26 -0
- package/dist/src/features/web/client/stores/task-store.js.map +7 -0
- package/dist/src/features/web/server/index.js +194 -0
- package/dist/src/features/web/server/index.js.map +7 -0
- package/dist/src/hooks/auto-background.js +151 -0
- package/dist/src/hooks/auto-background.js.map +7 -0
- package/dist/src/hooks/claude-code-whatsapp-hook.js +197 -0
- package/dist/src/hooks/claude-code-whatsapp-hook.js.map +7 -0
- package/dist/src/hooks/config.js +150 -0
- package/dist/src/hooks/config.js.map +7 -0
- package/dist/src/hooks/daemon.js +364 -0
- package/dist/src/hooks/daemon.js.map +7 -0
- package/dist/src/hooks/events.js +58 -0
- package/dist/src/hooks/events.js.map +7 -0
- package/dist/src/hooks/index.js +12 -0
- package/dist/src/hooks/index.js.map +7 -0
- package/dist/src/hooks/linear-task-picker.js +186 -0
- package/dist/src/hooks/linear-task-picker.js.map +7 -0
- package/dist/src/hooks/schemas.js +197 -0
- package/dist/src/hooks/schemas.js.map +7 -0
- package/dist/src/hooks/secure-fs.js +49 -0
- package/dist/src/hooks/secure-fs.js.map +7 -0
- package/dist/src/hooks/security-logger.js +155 -0
- package/dist/src/hooks/security-logger.js.map +7 -0
- package/dist/src/hooks/session-summary.js +222 -0
- package/dist/src/hooks/session-summary.js.map +7 -0
- package/dist/src/hooks/sms-action-runner.js +371 -0
- package/dist/src/hooks/sms-action-runner.js.map +7 -0
- package/dist/src/hooks/sms-notify.js +506 -0
- package/dist/src/hooks/sms-notify.js.map +7 -0
- package/dist/src/hooks/sms-watcher.js +93 -0
- package/dist/src/hooks/sms-watcher.js.map +7 -0
- package/dist/src/hooks/sms-webhook.js +555 -0
- package/dist/src/hooks/sms-webhook.js.map +7 -0
- package/dist/src/hooks/whatsapp-commands.js +479 -0
- package/dist/src/hooks/whatsapp-commands.js.map +7 -0
- package/dist/src/hooks/whatsapp-scheduler.js +317 -0
- package/dist/src/hooks/whatsapp-scheduler.js.map +7 -0
- package/dist/src/hooks/whatsapp-sync.js +409 -0
- package/dist/src/hooks/whatsapp-sync.js.map +7 -0
- package/dist/src/index.js +25 -0
- package/dist/src/index.js.map +7 -0
- package/dist/src/integrations/anthropic/client.js +263 -0
- package/dist/src/integrations/anthropic/client.js.map +7 -0
- package/dist/src/integrations/claude-code/agent-bridge.js +768 -0
- package/dist/src/integrations/claude-code/agent-bridge.js.map +7 -0
- package/dist/src/integrations/claude-code/enhanced-pre-clear-hooks.js +459 -0
- package/dist/src/integrations/claude-code/enhanced-pre-clear-hooks.js.map +7 -0
- package/dist/src/integrations/claude-code/lifecycle-hooks.js +254 -0
- package/dist/src/integrations/claude-code/lifecycle-hooks.js.map +7 -0
- package/dist/src/integrations/claude-code/post-task-hooks.js +545 -0
- package/dist/src/integrations/claude-code/post-task-hooks.js.map +7 -0
- package/dist/src/integrations/claude-code/subagent-client-stub.js +20 -0
- package/dist/src/integrations/claude-code/subagent-client-stub.js.map +7 -0
- package/dist/src/integrations/claude-code/subagent-client.js +511 -0
- package/dist/src/integrations/claude-code/subagent-client.js.map +7 -0
- package/dist/src/integrations/claude-code/task-coordinator.js +360 -0
- package/dist/src/integrations/claude-code/task-coordinator.js.map +7 -0
- package/dist/src/integrations/linear/auth.js +337 -0
- package/dist/src/integrations/linear/auth.js.map +7 -0
- package/dist/src/integrations/linear/auto-sync.js +258 -0
- package/dist/src/integrations/linear/auto-sync.js.map +7 -0
- package/dist/src/integrations/linear/client.js +634 -0
- package/dist/src/integrations/linear/client.js.map +7 -0
- package/dist/src/integrations/linear/config.js +130 -0
- package/dist/src/integrations/linear/config.js.map +7 -0
- package/dist/src/integrations/linear/migration.js +361 -0
- package/dist/src/integrations/linear/migration.js.map +7 -0
- package/dist/src/integrations/linear/oauth-server.js +454 -0
- package/dist/src/integrations/linear/oauth-server.js.map +7 -0
- package/dist/src/integrations/linear/rest-client.js +213 -0
- package/dist/src/integrations/linear/rest-client.js.map +7 -0
- package/dist/src/integrations/linear/sync-manager.js +236 -0
- package/dist/src/integrations/linear/sync-manager.js.map +7 -0
- package/dist/src/integrations/linear/sync-service.js +231 -0
- package/dist/src/integrations/linear/sync-service.js.map +7 -0
- package/dist/src/integrations/linear/sync.js +782 -0
- package/dist/src/integrations/linear/sync.js.map +7 -0
- package/dist/src/integrations/linear/types.js +5 -0
- package/dist/src/integrations/linear/types.js.map +7 -0
- package/dist/src/integrations/linear/unified-sync.js +589 -0
- package/dist/src/integrations/linear/unified-sync.js.map +7 -0
- package/dist/src/integrations/linear/webhook-handler.js +219 -0
- package/dist/src/integrations/linear/webhook-handler.js.map +7 -0
- package/dist/src/integrations/linear/webhook-server.js +218 -0
- package/dist/src/integrations/linear/webhook-server.js.map +7 -0
- package/dist/src/integrations/linear/webhook.js +291 -0
- package/dist/src/integrations/linear/webhook.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/code-execution-handlers.js +266 -0
- package/dist/src/integrations/mcp/handlers/code-execution-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/context-handlers.js +257 -0
- package/dist/src/integrations/mcp/handlers/context-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/discovery-handlers.js +497 -0
- package/dist/src/integrations/mcp/handlers/discovery-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/index.js +166 -0
- package/dist/src/integrations/mcp/handlers/index.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/linear-handlers.js +247 -0
- package/dist/src/integrations/mcp/handlers/linear-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/skill-handlers.js +529 -0
- package/dist/src/integrations/mcp/handlers/skill-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/task-handlers.js +239 -0
- package/dist/src/integrations/mcp/handlers/task-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/trace-handlers.js +308 -0
- package/dist/src/integrations/mcp/handlers/trace-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/index.js +23 -0
- package/dist/src/integrations/mcp/index.js.map +7 -0
- package/dist/src/integrations/mcp/middleware/tool-scoring.js +356 -0
- package/dist/src/integrations/mcp/middleware/tool-scoring.js.map +7 -0
- package/dist/src/integrations/mcp/refactored-server.js +374 -0
- package/dist/src/integrations/mcp/refactored-server.js.map +7 -0
- package/dist/src/integrations/mcp/remote-server.js +682 -0
- package/dist/src/integrations/mcp/remote-server.js.map +7 -0
- package/dist/src/integrations/mcp/schemas.js +147 -0
- package/dist/src/integrations/mcp/schemas.js.map +7 -0
- package/dist/src/integrations/mcp/server.js +1975 -0
- package/dist/src/integrations/mcp/server.js.map +7 -0
- package/dist/src/integrations/mcp/tool-definitions-code.js +125 -0
- package/dist/src/integrations/mcp/tool-definitions-code.js.map +7 -0
- package/dist/src/integrations/mcp/tool-definitions.js +702 -0
- package/dist/src/integrations/mcp/tool-definitions.js.map +7 -0
- package/dist/src/integrations/ralph/bridge/ralph-stackmemory-bridge.js +860 -0
- package/dist/src/integrations/ralph/bridge/ralph-stackmemory-bridge.js.map +7 -0
- package/dist/src/integrations/ralph/context/context-budget-manager.js +301 -0
- package/dist/src/integrations/ralph/context/context-budget-manager.js.map +7 -0
- package/dist/src/integrations/ralph/context/stackmemory-context-loader.js +360 -0
- package/dist/src/integrations/ralph/context/stackmemory-context-loader.js.map +7 -0
- package/dist/src/integrations/ralph/coordination/enhanced-coordination.js +410 -0
- package/dist/src/integrations/ralph/coordination/enhanced-coordination.js.map +7 -0
- package/dist/src/integrations/ralph/index.js +18 -0
- package/dist/src/integrations/ralph/index.js.map +7 -0
- package/dist/src/integrations/ralph/learning/pattern-learner.js +401 -0
- package/dist/src/integrations/ralph/learning/pattern-learner.js.map +7 -0
- package/dist/src/integrations/ralph/lifecycle/iteration-lifecycle.js +448 -0
- package/dist/src/integrations/ralph/lifecycle/iteration-lifecycle.js.map +7 -0
- package/dist/src/integrations/ralph/monitoring/swarm-dashboard.js +294 -0
- package/dist/src/integrations/ralph/monitoring/swarm-dashboard.js.map +7 -0
- package/dist/src/integrations/ralph/monitoring/swarm-registry.js +108 -0
- package/dist/src/integrations/ralph/monitoring/swarm-registry.js.map +7 -0
- package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js +463 -0
- package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js.map +7 -0
- package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js +400 -0
- package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js.map +7 -0
- package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js +473 -0
- package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js.map +7 -0
- package/dist/src/integrations/ralph/patterns/oracle-worker-pattern.js +388 -0
- package/dist/src/integrations/ralph/patterns/oracle-worker-pattern.js.map +7 -0
- package/dist/src/integrations/ralph/performance/performance-optimizer.js +358 -0
- package/dist/src/integrations/ralph/performance/performance-optimizer.js.map +7 -0
- package/dist/src/integrations/ralph/recovery/crash-recovery.js +462 -0
- package/dist/src/integrations/ralph/recovery/crash-recovery.js.map +7 -0
- package/dist/src/integrations/ralph/state/state-reconciler.js +404 -0
- package/dist/src/integrations/ralph/state/state-reconciler.js.map +7 -0
- package/dist/src/integrations/ralph/swarm/git-workflow-manager.js +428 -0
- package/dist/src/integrations/ralph/swarm/git-workflow-manager.js.map +7 -0
- package/dist/src/integrations/ralph/swarm/swarm-coordinator.js +996 -0
- package/dist/src/integrations/ralph/swarm/swarm-coordinator.js.map +7 -0
- package/dist/src/integrations/ralph/types.js +5 -0
- package/dist/src/integrations/ralph/types.js.map +7 -0
- package/dist/src/integrations/ralph/visualization/ralph-debugger.js +585 -0
- package/dist/src/integrations/ralph/visualization/ralph-debugger.js.map +7 -0
- package/dist/src/mcp/stackmemory-mcp-server.js +554 -0
- package/dist/src/mcp/stackmemory-mcp-server.js.map +7 -0
- package/dist/src/middleware/exponential-rate-limiter.js +289 -0
- package/dist/src/middleware/exponential-rate-limiter.js.map +7 -0
- package/dist/src/models/user.model.js +358 -0
- package/dist/src/models/user.model.js.map +7 -0
- package/dist/src/servers/production/auth-middleware.js +528 -0
- package/dist/src/servers/production/auth-middleware.js.map +7 -0
- package/dist/src/services/config-service.js +65 -0
- package/dist/src/services/config-service.js.map +7 -0
- package/dist/src/services/context-service.js +194 -0
- package/dist/src/services/context-service.js.map +7 -0
- package/dist/src/skills/api-discovery.js +354 -0
- package/dist/src/skills/api-discovery.js.map +7 -0
- package/dist/src/skills/api-skill.js +475 -0
- package/dist/src/skills/api-skill.js.map +7 -0
- package/dist/src/skills/claude-skills.js +1061 -0
- package/dist/src/skills/claude-skills.js.map +7 -0
- package/dist/src/skills/dashboard-launcher.js +216 -0
- package/dist/src/skills/dashboard-launcher.js.map +7 -0
- package/dist/src/skills/recursive-agent-orchestrator.js +575 -0
- package/dist/src/skills/recursive-agent-orchestrator.js.map +7 -0
- package/dist/src/skills/repo-ingestion-skill.js +609 -0
- package/dist/src/skills/repo-ingestion-skill.js.map +7 -0
- package/dist/src/skills/unified-rlm-orchestrator.js +404 -0
- package/dist/src/skills/unified-rlm-orchestrator.js.map +7 -0
- package/dist/src/types/task.js +5 -0
- package/dist/src/types/task.js.map +7 -0
- package/dist/src/utils/env.js +50 -0
- package/dist/src/utils/env.js.map +7 -0
- package/dist/src/utils/formatting.js +62 -0
- package/dist/src/utils/formatting.js.map +7 -0
- package/dist/src/utils/process-cleanup.js +136 -0
- package/dist/src/utils/process-cleanup.js.map +7 -0
- package/package.json +3 -3
- package/scripts/initialize.ts +16 -7
- package/scripts/install.sh +14 -62
- package/scripts/status.ts +111 -46
|
@@ -0,0 +1,860 @@
|
|
|
1
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
2
|
+
import { dirname as __pathDirname } from 'path';
|
|
3
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
4
|
+
const __dirname = __pathDirname(__filename);
|
|
5
|
+
import { v4 as uuidv4 } from "uuid";
|
|
6
|
+
import * as fs from "fs/promises";
|
|
7
|
+
import * as path from "path";
|
|
8
|
+
import { execSync } from "child_process";
|
|
9
|
+
import { logger } from "../../../core/monitoring/logger.js";
|
|
10
|
+
import { FrameManager } from "../../../core/context/index.js";
|
|
11
|
+
import { SessionManager } from "../../../core/session/session-manager.js";
|
|
12
|
+
import { SQLiteAdapter } from "../../../core/database/sqlite-adapter.js";
|
|
13
|
+
import { ContextBudgetManager } from "../context/context-budget-manager.js";
|
|
14
|
+
import { StateReconciler } from "../state/state-reconciler.js";
|
|
15
|
+
import {
|
|
16
|
+
IterationLifecycle
|
|
17
|
+
} from "../lifecycle/iteration-lifecycle.js";
|
|
18
|
+
import { PerformanceOptimizer } from "../performance/performance-optimizer.js";
|
|
19
|
+
class RalphStackMemoryBridge {
|
|
20
|
+
state;
|
|
21
|
+
config;
|
|
22
|
+
frameManager;
|
|
23
|
+
sessionManager;
|
|
24
|
+
recoveryState;
|
|
25
|
+
ralphDir = ".ralph";
|
|
26
|
+
requiresDatabase;
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.config = this.mergeConfig(options?.config);
|
|
29
|
+
this.requiresDatabase = options?.useStackMemory !== false;
|
|
30
|
+
this.state = {
|
|
31
|
+
initialized: false,
|
|
32
|
+
contextManager: new ContextBudgetManager(this.config.contextBudget),
|
|
33
|
+
stateReconciler: new StateReconciler(this.config.stateReconciliation),
|
|
34
|
+
performanceOptimizer: new PerformanceOptimizer(this.config.performance)
|
|
35
|
+
};
|
|
36
|
+
this.sessionManager = SessionManager.getInstance();
|
|
37
|
+
this.setupLifecycleHooks(options);
|
|
38
|
+
logger.info("Ralph-StackMemory Bridge initialized", {
|
|
39
|
+
config: {
|
|
40
|
+
maxTokens: this.config.contextBudget.maxTokens,
|
|
41
|
+
asyncSaves: this.config.performance.asyncSaves,
|
|
42
|
+
checkpoints: this.config.lifecycle.checkpoints.enabled
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Initialize bridge with session
|
|
48
|
+
*/
|
|
49
|
+
async initialize(options) {
|
|
50
|
+
logger.info("Initializing bridge", options);
|
|
51
|
+
try {
|
|
52
|
+
await this.sessionManager.initialize();
|
|
53
|
+
const session = await this.sessionManager.getOrCreateSession({
|
|
54
|
+
sessionId: options?.sessionId
|
|
55
|
+
});
|
|
56
|
+
this.state.currentSession = session;
|
|
57
|
+
const dbAdapter = await this.getDatabaseAdapter();
|
|
58
|
+
await dbAdapter.connect();
|
|
59
|
+
const db = dbAdapter.db;
|
|
60
|
+
const projectId = path.basename(this.ralphDir);
|
|
61
|
+
this.frameManager = new FrameManager(db, projectId, { skipContextBridge: true });
|
|
62
|
+
if (this.requiresDatabase) {
|
|
63
|
+
if (session.database && session.projectId) {
|
|
64
|
+
this.frameManager = new FrameManager(
|
|
65
|
+
session.database,
|
|
66
|
+
session.projectId,
|
|
67
|
+
{
|
|
68
|
+
skipContextBridge: true
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
} else {
|
|
72
|
+
throw new Error(
|
|
73
|
+
"Session database not available for FrameManager initialization. If StackMemory features are not needed, set useStackMemory: false in options"
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
logger.info(
|
|
78
|
+
"Running without StackMemory database (useStackMemory: false)"
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
if (options?.loopId) {
|
|
82
|
+
await this.resumeLoop(options.loopId);
|
|
83
|
+
} else if (options?.task && options?.criteria) {
|
|
84
|
+
await this.createNewLoop(options.task, options.criteria);
|
|
85
|
+
} else {
|
|
86
|
+
await this.attemptRecovery();
|
|
87
|
+
}
|
|
88
|
+
this.state.initialized = true;
|
|
89
|
+
logger.info("Bridge initialized successfully");
|
|
90
|
+
} catch (error) {
|
|
91
|
+
logger.error("Bridge initialization failed", { error: error.message });
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Create new Ralph loop with StackMemory integration
|
|
97
|
+
*/
|
|
98
|
+
async createNewLoop(task, criteria) {
|
|
99
|
+
logger.info("Creating new Ralph loop", { task: task.substring(0, 100) });
|
|
100
|
+
const loopId = uuidv4();
|
|
101
|
+
const startTime = Date.now();
|
|
102
|
+
const loopState = {
|
|
103
|
+
loopId,
|
|
104
|
+
task,
|
|
105
|
+
criteria,
|
|
106
|
+
iteration: 0,
|
|
107
|
+
status: "initialized",
|
|
108
|
+
startTime,
|
|
109
|
+
lastUpdateTime: startTime,
|
|
110
|
+
startCommit: await this.getCurrentGitCommit()
|
|
111
|
+
};
|
|
112
|
+
await this.initializeRalphDirectory(loopState);
|
|
113
|
+
const rootFrame = await this.createRootFrame(loopState);
|
|
114
|
+
await this.saveLoopState(loopState);
|
|
115
|
+
this.state.activeLoop = loopState;
|
|
116
|
+
logger.info("Ralph loop created", {
|
|
117
|
+
loopId,
|
|
118
|
+
frameId: rootFrame.frame_id
|
|
119
|
+
});
|
|
120
|
+
return loopState;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Resume existing loop
|
|
124
|
+
*/
|
|
125
|
+
async resumeLoop(loopId) {
|
|
126
|
+
logger.info("Resuming loop", { loopId });
|
|
127
|
+
const sources = await this.gatherStateSources(loopId);
|
|
128
|
+
const reconciledState = await this.state.stateReconciler.reconcile(sources);
|
|
129
|
+
if (this.config.stateReconciliation.validateConsistency) {
|
|
130
|
+
const validation = await this.state.stateReconciler.validateConsistency(reconciledState);
|
|
131
|
+
if (validation.errors.length > 0) {
|
|
132
|
+
logger.error("State validation failed", { errors: validation.errors });
|
|
133
|
+
throw new Error(`Invalid state: ${validation.errors.join(", ")}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
this.state.activeLoop = reconciledState;
|
|
137
|
+
const context = await this.loadIterationContext(reconciledState);
|
|
138
|
+
logger.info("Loop resumed", {
|
|
139
|
+
loopId,
|
|
140
|
+
iteration: reconciledState.iteration,
|
|
141
|
+
status: reconciledState.status
|
|
142
|
+
});
|
|
143
|
+
return reconciledState;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Run worker iteration
|
|
147
|
+
*/
|
|
148
|
+
async runWorkerIteration() {
|
|
149
|
+
if (!this.state.activeLoop) {
|
|
150
|
+
throw new Error("No active loop");
|
|
151
|
+
}
|
|
152
|
+
const iterationNumber = this.state.activeLoop.iteration + 1;
|
|
153
|
+
logger.info("Starting worker iteration", { iteration: iterationNumber });
|
|
154
|
+
let context = await this.loadIterationContext(this.state.activeLoop);
|
|
155
|
+
context = this.state.contextManager.allocateBudget(context);
|
|
156
|
+
if (this.config.contextBudget.compressionEnabled) {
|
|
157
|
+
context = this.state.contextManager.compressContext(context);
|
|
158
|
+
}
|
|
159
|
+
const lifecycle = this.getLifecycle();
|
|
160
|
+
context = await lifecycle.startIteration(iterationNumber, context);
|
|
161
|
+
const iteration = await this.executeWorkerIteration(context);
|
|
162
|
+
await this.saveIterationResults(iteration);
|
|
163
|
+
await lifecycle.completeIteration(iteration);
|
|
164
|
+
this.state.activeLoop.iteration = iterationNumber;
|
|
165
|
+
this.state.activeLoop.lastUpdateTime = Date.now();
|
|
166
|
+
await this.saveLoopState(this.state.activeLoop);
|
|
167
|
+
logger.info("Worker iteration completed", {
|
|
168
|
+
iteration: iterationNumber,
|
|
169
|
+
changes: iteration.changes.length,
|
|
170
|
+
success: iteration.validation.testsPass
|
|
171
|
+
});
|
|
172
|
+
return iteration;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Run reviewer iteration
|
|
176
|
+
*/
|
|
177
|
+
async runReviewerIteration() {
|
|
178
|
+
if (!this.state.activeLoop) {
|
|
179
|
+
throw new Error("No active loop");
|
|
180
|
+
}
|
|
181
|
+
logger.info("Starting reviewer iteration", {
|
|
182
|
+
iteration: this.state.activeLoop.iteration
|
|
183
|
+
});
|
|
184
|
+
const evaluation = await this.evaluateCompletion();
|
|
185
|
+
if (evaluation.complete) {
|
|
186
|
+
this.state.activeLoop.status = "completed";
|
|
187
|
+
this.state.activeLoop.completionData = evaluation;
|
|
188
|
+
await this.saveLoopState(this.state.activeLoop);
|
|
189
|
+
const lifecycle = this.getLifecycle();
|
|
190
|
+
await lifecycle.handleCompletion(this.state.activeLoop);
|
|
191
|
+
logger.info("Task completed successfully");
|
|
192
|
+
return { complete: true };
|
|
193
|
+
}
|
|
194
|
+
const feedback = this.generateFeedback(evaluation);
|
|
195
|
+
this.state.activeLoop.feedback = feedback;
|
|
196
|
+
await this.saveLoopState(this.state.activeLoop);
|
|
197
|
+
logger.info("Reviewer iteration completed", {
|
|
198
|
+
complete: false,
|
|
199
|
+
feedbackLength: feedback.length
|
|
200
|
+
});
|
|
201
|
+
return { complete: false, feedback };
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Rehydrate session from StackMemory
|
|
205
|
+
*/
|
|
206
|
+
async rehydrateSession(sessionId) {
|
|
207
|
+
logger.info("Rehydrating session", { sessionId });
|
|
208
|
+
const session = await this.sessionManager.getSession(sessionId);
|
|
209
|
+
if (!session) {
|
|
210
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
211
|
+
}
|
|
212
|
+
const frames = await this.loadSessionFrames(sessionId);
|
|
213
|
+
const ralphFrames = frames.filter(
|
|
214
|
+
(f) => f.type === "task" && f.name.startsWith("ralph-")
|
|
215
|
+
);
|
|
216
|
+
if (ralphFrames.length === 0) {
|
|
217
|
+
throw new Error("No Ralph loops found in session");
|
|
218
|
+
}
|
|
219
|
+
const latestLoop = ralphFrames[ralphFrames.length - 1];
|
|
220
|
+
const loopState = await this.reconstructLoopState(latestLoop);
|
|
221
|
+
const context = await this.buildContextFromFrames(frames, loopState);
|
|
222
|
+
this.state.activeLoop = loopState;
|
|
223
|
+
logger.info("Session rehydrated", {
|
|
224
|
+
loopId: loopState.loopId,
|
|
225
|
+
iteration: loopState.iteration,
|
|
226
|
+
frameCount: frames.length
|
|
227
|
+
});
|
|
228
|
+
return context;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Create checkpoint
|
|
232
|
+
*/
|
|
233
|
+
async createCheckpoint() {
|
|
234
|
+
if (!this.state.activeLoop) {
|
|
235
|
+
throw new Error("No active loop");
|
|
236
|
+
}
|
|
237
|
+
const lifecycle = this.getLifecycle();
|
|
238
|
+
const iteration = {
|
|
239
|
+
number: this.state.activeLoop.iteration,
|
|
240
|
+
timestamp: Date.now(),
|
|
241
|
+
analysis: {
|
|
242
|
+
filesCount: 0,
|
|
243
|
+
testsPass: true,
|
|
244
|
+
testsFail: 0,
|
|
245
|
+
lastChange: await this.getCurrentGitCommit()
|
|
246
|
+
},
|
|
247
|
+
plan: {
|
|
248
|
+
summary: "Checkpoint",
|
|
249
|
+
steps: [],
|
|
250
|
+
priority: "low"
|
|
251
|
+
},
|
|
252
|
+
changes: [],
|
|
253
|
+
validation: {
|
|
254
|
+
testsPass: true,
|
|
255
|
+
lintClean: true,
|
|
256
|
+
buildSuccess: true,
|
|
257
|
+
errors: [],
|
|
258
|
+
warnings: []
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const checkpoint = await lifecycle.createCheckpoint(iteration);
|
|
262
|
+
logger.info("Checkpoint created", {
|
|
263
|
+
id: checkpoint.id,
|
|
264
|
+
iteration: checkpoint.iteration
|
|
265
|
+
});
|
|
266
|
+
return checkpoint;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Restore from checkpoint
|
|
270
|
+
*/
|
|
271
|
+
async restoreFromCheckpoint(checkpointId) {
|
|
272
|
+
const lifecycle = this.getLifecycle();
|
|
273
|
+
await lifecycle.restoreFromCheckpoint(checkpointId);
|
|
274
|
+
const sources = await this.gatherStateSources(
|
|
275
|
+
this.state.activeLoop?.loopId || ""
|
|
276
|
+
);
|
|
277
|
+
const reconciledState = await this.state.stateReconciler.reconcile(sources);
|
|
278
|
+
this.state.activeLoop = reconciledState;
|
|
279
|
+
logger.info("Restored from checkpoint", {
|
|
280
|
+
checkpointId,
|
|
281
|
+
iteration: reconciledState.iteration
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Get performance metrics
|
|
286
|
+
*/
|
|
287
|
+
getPerformanceMetrics() {
|
|
288
|
+
return this.state.performanceOptimizer.getMetrics();
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Start a new Ralph loop
|
|
292
|
+
*/
|
|
293
|
+
async startLoop(options) {
|
|
294
|
+
const state = await this.createNewLoop(options.task, options.criteria);
|
|
295
|
+
return state.loopId;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Stop the active loop
|
|
299
|
+
*/
|
|
300
|
+
async stopLoop() {
|
|
301
|
+
if (!this.state.activeLoop) {
|
|
302
|
+
logger.warn("No active loop to stop");
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
this.state.activeLoop.status = "completed";
|
|
306
|
+
this.state.activeLoop.lastUpdateTime = Date.now();
|
|
307
|
+
await this.saveLoopState(this.state.activeLoop);
|
|
308
|
+
const lifecycle = this.getLifecycle();
|
|
309
|
+
await lifecycle.handleCompletion(this.state.activeLoop);
|
|
310
|
+
logger.info("Ralph loop stopped", { loopId: this.state.activeLoop.loopId });
|
|
311
|
+
this.state.activeLoop = void 0;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Cleanup resources
|
|
315
|
+
*/
|
|
316
|
+
async cleanup() {
|
|
317
|
+
logger.info("Cleaning up bridge resources");
|
|
318
|
+
await this.state.performanceOptimizer.flushBatch();
|
|
319
|
+
this.getLifecycle().cleanup();
|
|
320
|
+
this.state.performanceOptimizer.cleanup();
|
|
321
|
+
logger.info("Bridge cleanup completed");
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Merge configuration with defaults
|
|
325
|
+
*/
|
|
326
|
+
mergeConfig(config) {
|
|
327
|
+
return {
|
|
328
|
+
contextBudget: {
|
|
329
|
+
maxTokens: 4e3,
|
|
330
|
+
priorityWeights: {
|
|
331
|
+
task: 0.3,
|
|
332
|
+
recentWork: 0.25,
|
|
333
|
+
feedback: 0.2,
|
|
334
|
+
gitHistory: 0.15,
|
|
335
|
+
dependencies: 0.1
|
|
336
|
+
},
|
|
337
|
+
compressionEnabled: true,
|
|
338
|
+
adaptiveBudgeting: true,
|
|
339
|
+
...config?.contextBudget
|
|
340
|
+
},
|
|
341
|
+
stateReconciliation: {
|
|
342
|
+
precedence: ["git", "files", "memory"],
|
|
343
|
+
conflictResolution: "automatic",
|
|
344
|
+
syncInterval: 5e3,
|
|
345
|
+
validateConsistency: true,
|
|
346
|
+
...config?.stateReconciliation
|
|
347
|
+
},
|
|
348
|
+
lifecycle: {
|
|
349
|
+
hooks: {
|
|
350
|
+
preIteration: true,
|
|
351
|
+
postIteration: true,
|
|
352
|
+
onStateChange: true,
|
|
353
|
+
onError: true,
|
|
354
|
+
onComplete: true
|
|
355
|
+
},
|
|
356
|
+
checkpoints: {
|
|
357
|
+
enabled: true,
|
|
358
|
+
frequency: 5,
|
|
359
|
+
retentionDays: 7
|
|
360
|
+
},
|
|
361
|
+
...config?.lifecycle
|
|
362
|
+
},
|
|
363
|
+
performance: {
|
|
364
|
+
asyncSaves: true,
|
|
365
|
+
batchSize: 10,
|
|
366
|
+
compressionLevel: 2,
|
|
367
|
+
cacheEnabled: true,
|
|
368
|
+
parallelOperations: true,
|
|
369
|
+
...config?.performance
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Setup lifecycle hooks
|
|
375
|
+
*/
|
|
376
|
+
setupLifecycleHooks(options) {
|
|
377
|
+
const hooks = {
|
|
378
|
+
preIteration: async (context) => {
|
|
379
|
+
logger.debug("Pre-iteration hook", {
|
|
380
|
+
iteration: context.task.currentIteration
|
|
381
|
+
});
|
|
382
|
+
return context;
|
|
383
|
+
},
|
|
384
|
+
postIteration: async (iteration) => {
|
|
385
|
+
await this.saveIterationFrame(iteration);
|
|
386
|
+
},
|
|
387
|
+
onStateChange: async (oldState, newState) => {
|
|
388
|
+
await this.updateStateFrame(oldState, newState);
|
|
389
|
+
},
|
|
390
|
+
onError: async (error, context) => {
|
|
391
|
+
logger.error("Iteration error", { error: error.message, context });
|
|
392
|
+
await this.saveErrorFrame(error, context);
|
|
393
|
+
},
|
|
394
|
+
onComplete: async (state) => {
|
|
395
|
+
await this.closeRootFrame(state);
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
const lifecycle = new IterationLifecycle(this.config.lifecycle, hooks);
|
|
399
|
+
this.state.lifecycle = lifecycle;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Get lifecycle instance
|
|
403
|
+
*/
|
|
404
|
+
getLifecycle() {
|
|
405
|
+
return this.state.lifecycle;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Initialize Ralph directory structure
|
|
409
|
+
*/
|
|
410
|
+
async initializeRalphDirectory(state) {
|
|
411
|
+
await fs.mkdir(this.ralphDir, { recursive: true });
|
|
412
|
+
await fs.mkdir(path.join(this.ralphDir, "history"), { recursive: true });
|
|
413
|
+
await fs.writeFile(path.join(this.ralphDir, "task.md"), state.task);
|
|
414
|
+
await fs.writeFile(
|
|
415
|
+
path.join(this.ralphDir, "completion-criteria.md"),
|
|
416
|
+
state.criteria
|
|
417
|
+
);
|
|
418
|
+
await fs.writeFile(path.join(this.ralphDir, "iteration.txt"), "0");
|
|
419
|
+
await fs.writeFile(path.join(this.ralphDir, "feedback.txt"), "");
|
|
420
|
+
await fs.writeFile(
|
|
421
|
+
path.join(this.ralphDir, "state.json"),
|
|
422
|
+
JSON.stringify(state, null, 2)
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Create root frame for Ralph loop
|
|
427
|
+
*/
|
|
428
|
+
async createRootFrame(state) {
|
|
429
|
+
if (!this.requiresDatabase) {
|
|
430
|
+
return {
|
|
431
|
+
frame_id: `mock-${state.loopId}`,
|
|
432
|
+
type: "task",
|
|
433
|
+
name: `ralph-${state.loopId}`,
|
|
434
|
+
inputs: {
|
|
435
|
+
task: state.task,
|
|
436
|
+
criteria: state.criteria,
|
|
437
|
+
loopId: state.loopId
|
|
438
|
+
},
|
|
439
|
+
created_at: Date.now()
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
if (!this.frameManager) {
|
|
443
|
+
throw new Error("Frame manager not initialized");
|
|
444
|
+
}
|
|
445
|
+
const frame = {
|
|
446
|
+
type: "task",
|
|
447
|
+
name: `ralph-${state.loopId}`,
|
|
448
|
+
inputs: {
|
|
449
|
+
task: state.task,
|
|
450
|
+
criteria: state.criteria,
|
|
451
|
+
loopId: state.loopId
|
|
452
|
+
},
|
|
453
|
+
digest_json: {
|
|
454
|
+
type: "ralph_loop",
|
|
455
|
+
status: "started"
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
return await this.frameManager.createFrame({
|
|
459
|
+
name: frame.name,
|
|
460
|
+
type: frame.type,
|
|
461
|
+
content: frame.content || "",
|
|
462
|
+
metadata: frame.metadata
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Load iteration context from StackMemory
|
|
467
|
+
*/
|
|
468
|
+
async loadIterationContext(state) {
|
|
469
|
+
const frames = await this.loadRelevantFrames(state.loopId);
|
|
470
|
+
return {
|
|
471
|
+
task: {
|
|
472
|
+
description: state.task,
|
|
473
|
+
criteria: state.criteria.split("\n").filter(Boolean),
|
|
474
|
+
currentIteration: state.iteration,
|
|
475
|
+
feedback: state.feedback,
|
|
476
|
+
priority: "medium"
|
|
477
|
+
},
|
|
478
|
+
history: {
|
|
479
|
+
recentIterations: await this.loadRecentIterations(state.loopId),
|
|
480
|
+
gitCommits: await this.loadGitCommits(),
|
|
481
|
+
changedFiles: await this.loadChangedFiles(),
|
|
482
|
+
testResults: []
|
|
483
|
+
},
|
|
484
|
+
environment: {
|
|
485
|
+
projectPath: process.cwd(),
|
|
486
|
+
branch: await this.getCurrentBranch(),
|
|
487
|
+
dependencies: {},
|
|
488
|
+
configuration: {}
|
|
489
|
+
},
|
|
490
|
+
memory: {
|
|
491
|
+
relevantFrames: frames,
|
|
492
|
+
decisions: [],
|
|
493
|
+
patterns: [],
|
|
494
|
+
blockers: []
|
|
495
|
+
},
|
|
496
|
+
tokenCount: 0
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Execute worker iteration
|
|
501
|
+
*/
|
|
502
|
+
async executeWorkerIteration(context) {
|
|
503
|
+
const iterationNumber = context.task.currentIteration + 1;
|
|
504
|
+
try {
|
|
505
|
+
const analysis = await this.analyzeCodebaseState();
|
|
506
|
+
const plan = await this.generateIterationPlan(context, analysis);
|
|
507
|
+
const changes = await this.executeIterationChanges(plan, context);
|
|
508
|
+
const validation = await this.validateIterationResults(changes);
|
|
509
|
+
logger.info("Iteration execution completed", {
|
|
510
|
+
iteration: iterationNumber,
|
|
511
|
+
changesCount: changes.length,
|
|
512
|
+
testsPass: validation.testsPass
|
|
513
|
+
});
|
|
514
|
+
return {
|
|
515
|
+
number: iterationNumber,
|
|
516
|
+
timestamp: Date.now(),
|
|
517
|
+
analysis,
|
|
518
|
+
plan,
|
|
519
|
+
changes,
|
|
520
|
+
validation
|
|
521
|
+
};
|
|
522
|
+
} catch (error) {
|
|
523
|
+
logger.error("Iteration execution failed", error);
|
|
524
|
+
return {
|
|
525
|
+
number: iterationNumber,
|
|
526
|
+
timestamp: Date.now(),
|
|
527
|
+
analysis: {
|
|
528
|
+
filesCount: 0,
|
|
529
|
+
testsPass: false,
|
|
530
|
+
testsFail: 1,
|
|
531
|
+
lastChange: `Error: ${error.message}`
|
|
532
|
+
},
|
|
533
|
+
plan: {
|
|
534
|
+
summary: "Iteration failed due to error",
|
|
535
|
+
steps: ["Investigate error", "Fix underlying issue"],
|
|
536
|
+
priority: "high"
|
|
537
|
+
},
|
|
538
|
+
changes: [],
|
|
539
|
+
validation: {
|
|
540
|
+
testsPass: false,
|
|
541
|
+
lintClean: false,
|
|
542
|
+
buildSuccess: false,
|
|
543
|
+
errors: [error.message],
|
|
544
|
+
warnings: []
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Analyze current codebase state
|
|
551
|
+
*/
|
|
552
|
+
async analyzeCodebaseState() {
|
|
553
|
+
try {
|
|
554
|
+
const stats = {
|
|
555
|
+
filesCount: 0,
|
|
556
|
+
testsPass: true,
|
|
557
|
+
testsFail: 0,
|
|
558
|
+
lastChange: "No recent changes"
|
|
559
|
+
};
|
|
560
|
+
try {
|
|
561
|
+
const { execSync: execSync2 } = await import("child_process");
|
|
562
|
+
const output = execSync2(
|
|
563
|
+
'find . -type f -name "*.ts" -o -name "*.js" -o -name "*.json" | grep -v node_modules | grep -v .git | wc -l',
|
|
564
|
+
{ encoding: "utf8", cwd: process.cwd() }
|
|
565
|
+
);
|
|
566
|
+
stats.filesCount = parseInt(output.trim()) || 0;
|
|
567
|
+
} catch {
|
|
568
|
+
stats.filesCount = 0;
|
|
569
|
+
}
|
|
570
|
+
try {
|
|
571
|
+
const { execSync: execSync2 } = await import("child_process");
|
|
572
|
+
const gitLog = execSync2("git log -1 --oneline", {
|
|
573
|
+
encoding: "utf8",
|
|
574
|
+
cwd: process.cwd()
|
|
575
|
+
});
|
|
576
|
+
stats.lastChange = gitLog.trim() || "No git history";
|
|
577
|
+
} catch {
|
|
578
|
+
stats.lastChange = "No git repository";
|
|
579
|
+
}
|
|
580
|
+
try {
|
|
581
|
+
const { existsSync } = await import("fs");
|
|
582
|
+
if (existsSync("package.json")) {
|
|
583
|
+
const packageJson = JSON.parse(
|
|
584
|
+
await fs.readFile("package.json", "utf8")
|
|
585
|
+
);
|
|
586
|
+
if (packageJson.scripts?.test) {
|
|
587
|
+
const { execSync: execSync2 } = await import("child_process");
|
|
588
|
+
execSync2("npm test", { stdio: "pipe", timeout: 3e4 });
|
|
589
|
+
stats.testsPass = true;
|
|
590
|
+
stats.testsFail = 0;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
} catch {
|
|
594
|
+
stats.testsPass = false;
|
|
595
|
+
stats.testsFail = 1;
|
|
596
|
+
}
|
|
597
|
+
return stats;
|
|
598
|
+
} catch (error) {
|
|
599
|
+
return {
|
|
600
|
+
filesCount: 0,
|
|
601
|
+
testsPass: false,
|
|
602
|
+
testsFail: 1,
|
|
603
|
+
lastChange: `Analysis failed: ${error.message}`
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Generate iteration plan based on context and analysis
|
|
609
|
+
*/
|
|
610
|
+
async generateIterationPlan(context, analysis) {
|
|
611
|
+
const task = context.task.task || "Complete assigned work";
|
|
612
|
+
const criteria = context.task.criteria || "Meet completion criteria";
|
|
613
|
+
const steps = [];
|
|
614
|
+
if (!analysis.testsPass) {
|
|
615
|
+
steps.push("Fix failing tests");
|
|
616
|
+
}
|
|
617
|
+
if (analysis.filesCount === 0) {
|
|
618
|
+
steps.push("Initialize project structure");
|
|
619
|
+
}
|
|
620
|
+
if (task.toLowerCase().includes("implement")) {
|
|
621
|
+
steps.push("Implement required functionality");
|
|
622
|
+
steps.push("Add appropriate tests");
|
|
623
|
+
} else if (task.toLowerCase().includes("fix")) {
|
|
624
|
+
steps.push("Identify root cause");
|
|
625
|
+
steps.push("Implement fix");
|
|
626
|
+
steps.push("Verify fix works");
|
|
627
|
+
} else {
|
|
628
|
+
steps.push("Analyze requirements");
|
|
629
|
+
steps.push("Plan implementation approach");
|
|
630
|
+
steps.push("Execute planned work");
|
|
631
|
+
}
|
|
632
|
+
steps.push("Validate changes");
|
|
633
|
+
return {
|
|
634
|
+
summary: `Iteration plan for: ${task}`,
|
|
635
|
+
steps,
|
|
636
|
+
priority: analysis.testsPass ? "medium" : "high"
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Execute planned changes
|
|
641
|
+
*/
|
|
642
|
+
async executeIterationChanges(plan, context) {
|
|
643
|
+
const changes = [];
|
|
644
|
+
for (let i = 0; i < plan.steps.length; i++) {
|
|
645
|
+
const step = plan.steps[i];
|
|
646
|
+
changes.push({
|
|
647
|
+
type: "step_execution",
|
|
648
|
+
description: step,
|
|
649
|
+
timestamp: Date.now(),
|
|
650
|
+
files_affected: [],
|
|
651
|
+
success: true
|
|
652
|
+
});
|
|
653
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
654
|
+
}
|
|
655
|
+
logger.debug("Executed iteration changes", {
|
|
656
|
+
stepsCount: plan.steps.length,
|
|
657
|
+
changesCount: changes.length
|
|
658
|
+
});
|
|
659
|
+
return changes;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Validate iteration results
|
|
663
|
+
*/
|
|
664
|
+
async validateIterationResults(changes) {
|
|
665
|
+
const validation = {
|
|
666
|
+
testsPass: true,
|
|
667
|
+
lintClean: true,
|
|
668
|
+
buildSuccess: true,
|
|
669
|
+
errors: [],
|
|
670
|
+
warnings: []
|
|
671
|
+
};
|
|
672
|
+
try {
|
|
673
|
+
const { existsSync } = await import("fs");
|
|
674
|
+
if (existsSync("package.json")) {
|
|
675
|
+
const packageJson = JSON.parse(
|
|
676
|
+
await fs.readFile("package.json", "utf8")
|
|
677
|
+
);
|
|
678
|
+
if (packageJson.scripts?.lint) {
|
|
679
|
+
try {
|
|
680
|
+
const { execSync: execSync2 } = await import("child_process");
|
|
681
|
+
execSync2("npm run lint", { stdio: "pipe", timeout: 3e4 });
|
|
682
|
+
validation.lintClean = true;
|
|
683
|
+
} catch (error) {
|
|
684
|
+
validation.lintClean = false;
|
|
685
|
+
validation.warnings.push("Lint warnings detected");
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (packageJson.scripts?.build) {
|
|
689
|
+
try {
|
|
690
|
+
const { execSync: execSync2 } = await import("child_process");
|
|
691
|
+
execSync2("npm run build", { stdio: "pipe", timeout: 6e4 });
|
|
692
|
+
validation.buildSuccess = true;
|
|
693
|
+
} catch (error) {
|
|
694
|
+
validation.buildSuccess = false;
|
|
695
|
+
validation.errors.push("Build failed");
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
} catch (error) {
|
|
700
|
+
validation.errors.push(`Validation error: ${error.message}`);
|
|
701
|
+
}
|
|
702
|
+
return validation;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Save iteration results
|
|
706
|
+
*/
|
|
707
|
+
async saveIterationResults(iteration) {
|
|
708
|
+
await this.state.performanceOptimizer.saveIteration(iteration);
|
|
709
|
+
const iterDir = path.join(
|
|
710
|
+
this.ralphDir,
|
|
711
|
+
"history",
|
|
712
|
+
`iteration-${String(iteration.number).padStart(3, "0")}`
|
|
713
|
+
);
|
|
714
|
+
await fs.mkdir(iterDir, { recursive: true });
|
|
715
|
+
await fs.writeFile(
|
|
716
|
+
path.join(iterDir, "artifacts.json"),
|
|
717
|
+
JSON.stringify(iteration, null, 2)
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Save iteration frame to StackMemory
|
|
722
|
+
*/
|
|
723
|
+
async saveIterationFrame(iteration) {
|
|
724
|
+
if (!this.requiresDatabase || !this.frameManager || !this.state.activeLoop)
|
|
725
|
+
return;
|
|
726
|
+
const frame = {
|
|
727
|
+
type: "subtask",
|
|
728
|
+
name: `iteration-${iteration.number}`,
|
|
729
|
+
inputs: {
|
|
730
|
+
iterationNumber: iteration.number,
|
|
731
|
+
loopId: this.state.activeLoop.loopId
|
|
732
|
+
},
|
|
733
|
+
outputs: {
|
|
734
|
+
changes: iteration.changes.length,
|
|
735
|
+
success: iteration.validation.testsPass
|
|
736
|
+
},
|
|
737
|
+
digest_json: iteration
|
|
738
|
+
};
|
|
739
|
+
await this.state.performanceOptimizer.saveFrame(frame);
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Get database adapter for FrameManager
|
|
743
|
+
*/
|
|
744
|
+
async getDatabaseAdapter() {
|
|
745
|
+
const dbPath = path.join(this.ralphDir, "stackmemory.db");
|
|
746
|
+
const projectId = path.basename(this.ralphDir);
|
|
747
|
+
return new SQLiteAdapter(projectId, { dbPath });
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Additional helper methods
|
|
751
|
+
*/
|
|
752
|
+
async getCurrentGitCommit() {
|
|
753
|
+
try {
|
|
754
|
+
return execSync("git rev-parse HEAD", { encoding: "utf8" }).trim();
|
|
755
|
+
} catch {
|
|
756
|
+
return "";
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
async getCurrentBranch() {
|
|
760
|
+
try {
|
|
761
|
+
return execSync("git branch --show-current", { encoding: "utf8" }).trim();
|
|
762
|
+
} catch {
|
|
763
|
+
return "main";
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
async saveLoopState(state) {
|
|
767
|
+
await fs.writeFile(
|
|
768
|
+
path.join(this.ralphDir, "state.json"),
|
|
769
|
+
JSON.stringify(state, null, 2)
|
|
770
|
+
);
|
|
771
|
+
await fs.writeFile(
|
|
772
|
+
path.join(this.ralphDir, "iteration.txt"),
|
|
773
|
+
state.iteration.toString()
|
|
774
|
+
);
|
|
775
|
+
logger.debug("Saved loop state", {
|
|
776
|
+
iteration: state.iteration,
|
|
777
|
+
status: state.status
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
async gatherStateSources(loopId) {
|
|
781
|
+
const sources = [];
|
|
782
|
+
sources.push(await this.state.stateReconciler.getGitState());
|
|
783
|
+
sources.push(await this.state.stateReconciler.getFileState());
|
|
784
|
+
sources.push(await this.state.stateReconciler.getMemoryState(loopId));
|
|
785
|
+
return sources;
|
|
786
|
+
}
|
|
787
|
+
async attemptRecovery() {
|
|
788
|
+
logger.info("Attempting crash recovery");
|
|
789
|
+
try {
|
|
790
|
+
const stateFile = path.join(this.ralphDir, "state.json");
|
|
791
|
+
const exists = await fs.stat(stateFile).then(() => true).catch(() => false);
|
|
792
|
+
if (exists) {
|
|
793
|
+
const stateData = await fs.readFile(stateFile, "utf8");
|
|
794
|
+
const state = JSON.parse(stateData);
|
|
795
|
+
if (state.status !== "completed") {
|
|
796
|
+
logger.info("Found incomplete loop", { loopId: state.loopId });
|
|
797
|
+
await this.resumeLoop(state.loopId);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
} catch (error) {
|
|
801
|
+
logger.error("Recovery failed", { error: error.message });
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
async evaluateCompletion() {
|
|
805
|
+
return {
|
|
806
|
+
complete: false,
|
|
807
|
+
criteria: {},
|
|
808
|
+
unmet: ["criteria1", "criteria2"]
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
generateFeedback(evaluation) {
|
|
812
|
+
if (evaluation.unmet.length === 0) {
|
|
813
|
+
return "All criteria met";
|
|
814
|
+
}
|
|
815
|
+
return `Still need to address:
|
|
816
|
+
${evaluation.unmet.map((c) => `- ${c}`).join("\n")}`;
|
|
817
|
+
}
|
|
818
|
+
async loadRelevantFrames(loopId) {
|
|
819
|
+
return [];
|
|
820
|
+
}
|
|
821
|
+
async loadRecentIterations(loopId) {
|
|
822
|
+
return [];
|
|
823
|
+
}
|
|
824
|
+
async loadGitCommits() {
|
|
825
|
+
return [];
|
|
826
|
+
}
|
|
827
|
+
async loadChangedFiles() {
|
|
828
|
+
return [];
|
|
829
|
+
}
|
|
830
|
+
async loadSessionFrames(sessionId) {
|
|
831
|
+
return [];
|
|
832
|
+
}
|
|
833
|
+
async reconstructLoopState(frame) {
|
|
834
|
+
return {
|
|
835
|
+
loopId: frame.inputs.loopId || "",
|
|
836
|
+
task: frame.inputs.task || "",
|
|
837
|
+
criteria: frame.inputs.criteria || "",
|
|
838
|
+
iteration: 0,
|
|
839
|
+
status: "running",
|
|
840
|
+
startTime: frame.created_at,
|
|
841
|
+
lastUpdateTime: Date.now()
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
async buildContextFromFrames(frames, state) {
|
|
845
|
+
return await this.loadIterationContext(state);
|
|
846
|
+
}
|
|
847
|
+
async updateStateFrame(oldState, newState) {
|
|
848
|
+
logger.debug("State frame updated");
|
|
849
|
+
}
|
|
850
|
+
async saveErrorFrame(error, context) {
|
|
851
|
+
logger.debug("Error frame saved");
|
|
852
|
+
}
|
|
853
|
+
async closeRootFrame(state) {
|
|
854
|
+
logger.debug("Root frame closed");
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
export {
|
|
858
|
+
RalphStackMemoryBridge
|
|
859
|
+
};
|
|
860
|
+
//# sourceMappingURL=ralph-stackmemory-bridge.js.map
|