@stackmemoryai/stackmemory 0.5.57 → 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/bin/codex-smd +6 -0
- package/dist/cli/codex-sm-danger.js +21 -0
- package/dist/cli/codex-sm-danger.js.map +7 -0
- package/dist/cli/commands/handoff.js +33 -3
- package/dist/cli/commands/handoff.js.map +2 -2
- 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/core/session/enhanced-handoff.js +136 -2
- package/dist/core/session/enhanced-handoff.js.map +3 -3
- 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 +4 -3
- package/scripts/create-cleanup-issues.js +302 -0
- package/scripts/demos/browser-test.ts +39 -0
- package/scripts/demos/ralph-integration-demo.ts +244 -0
- package/scripts/demos/trace-demo.ts +214 -0
- package/scripts/demos/trace-detector.demo.ts +171 -0
- package/scripts/demos/trace-test.ts +67 -0
- package/scripts/initialize.ts +16 -7
- package/scripts/install.sh +14 -62
- package/scripts/status.ts +111 -46
- package/scripts/test-claude-config.sh +123 -0
- package/scripts/validate-claude-config.sh +155 -0
|
@@ -0,0 +1,994 @@
|
|
|
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 * as fs from "fs/promises";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
import { logger } from "../monitoring/logger.js";
|
|
8
|
+
class CompactionHandler {
|
|
9
|
+
frameManager;
|
|
10
|
+
metrics;
|
|
11
|
+
tokenAccumulator = 0;
|
|
12
|
+
preservedAnchors = /* @__PURE__ */ new Map();
|
|
13
|
+
constructor(frameManager) {
|
|
14
|
+
this.frameManager = frameManager;
|
|
15
|
+
this.metrics = {
|
|
16
|
+
estimatedTokens: 0,
|
|
17
|
+
warningThreshold: 15e4,
|
|
18
|
+
// 150K tokens
|
|
19
|
+
criticalThreshold: 17e4,
|
|
20
|
+
// 170K tokens
|
|
21
|
+
anchorsPreserved: 0
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Track token usage from a message
|
|
26
|
+
*/
|
|
27
|
+
trackTokens(content) {
|
|
28
|
+
const estimatedTokens = Math.ceil(content.length / 4);
|
|
29
|
+
this.tokenAccumulator += estimatedTokens;
|
|
30
|
+
this.metrics.estimatedTokens += estimatedTokens;
|
|
31
|
+
if (this.isApproachingCompaction()) {
|
|
32
|
+
this.preserveCriticalContext();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if approaching compaction threshold
|
|
37
|
+
*/
|
|
38
|
+
isApproachingCompaction() {
|
|
39
|
+
return this.metrics.estimatedTokens >= this.metrics.warningThreshold;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if past critical threshold
|
|
43
|
+
*/
|
|
44
|
+
isPastCriticalThreshold() {
|
|
45
|
+
return this.metrics.estimatedTokens >= this.metrics.criticalThreshold;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Detect if compaction likely occurred
|
|
49
|
+
*/
|
|
50
|
+
detectCompactionEvent(content) {
|
|
51
|
+
const compactionIndicators = [
|
|
52
|
+
"earlier in this conversation",
|
|
53
|
+
"previously discussed",
|
|
54
|
+
"as mentioned before",
|
|
55
|
+
"summarized for brevity",
|
|
56
|
+
"[conversation compressed]",
|
|
57
|
+
"[context truncated]"
|
|
58
|
+
];
|
|
59
|
+
const lowerContent = content.toLowerCase();
|
|
60
|
+
return compactionIndicators.some(
|
|
61
|
+
(indicator) => lowerContent.includes(indicator)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Preserve critical context before compaction
|
|
66
|
+
*/
|
|
67
|
+
async preserveCriticalContext() {
|
|
68
|
+
try {
|
|
69
|
+
const currentFrameId = this.frameManager.getCurrentFrameId();
|
|
70
|
+
if (!currentFrameId) {
|
|
71
|
+
logger.warn("No active frame to preserve context from");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const events = this.frameManager.getFrameEvents(currentFrameId);
|
|
75
|
+
const toolCalls = this.extractToolCalls(events);
|
|
76
|
+
const fileOps = this.extractFileOperations(events);
|
|
77
|
+
const decisions = this.extractDecisions(events);
|
|
78
|
+
const errorPatterns = this.extractErrorPatterns(events);
|
|
79
|
+
const anchor = {
|
|
80
|
+
anchor_id: `compact_${Date.now()}`,
|
|
81
|
+
type: "COMPACTION_PRESERVE",
|
|
82
|
+
priority: 10,
|
|
83
|
+
content: {
|
|
84
|
+
tool_calls: toolCalls,
|
|
85
|
+
file_operations: fileOps,
|
|
86
|
+
decisions,
|
|
87
|
+
error_resolutions: errorPatterns
|
|
88
|
+
},
|
|
89
|
+
created_at: Date.now(),
|
|
90
|
+
token_estimate: this.metrics.estimatedTokens
|
|
91
|
+
};
|
|
92
|
+
this.frameManager.addAnchor(
|
|
93
|
+
"CONSTRAINT",
|
|
94
|
+
// Using CONSTRAINT type for now
|
|
95
|
+
JSON.stringify(anchor),
|
|
96
|
+
10,
|
|
97
|
+
{
|
|
98
|
+
compaction_preserve: true,
|
|
99
|
+
token_count: this.metrics.estimatedTokens
|
|
100
|
+
},
|
|
101
|
+
currentFrameId
|
|
102
|
+
);
|
|
103
|
+
this.preservedAnchors.set(anchor.anchor_id, anchor);
|
|
104
|
+
this.metrics.anchorsPreserved++;
|
|
105
|
+
logger.info(
|
|
106
|
+
`Preserved critical context at ${this.metrics.estimatedTokens} tokens`
|
|
107
|
+
);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
logger.error(
|
|
110
|
+
"Failed to preserve critical context:",
|
|
111
|
+
error instanceof Error ? error : void 0
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Extract tool calls from events
|
|
117
|
+
*/
|
|
118
|
+
extractToolCalls(events) {
|
|
119
|
+
const toolCalls = [];
|
|
120
|
+
const toolEvents = events.filter((e) => e.event_type === "tool_call");
|
|
121
|
+
for (const event of toolEvents) {
|
|
122
|
+
const resultEvent = events.find(
|
|
123
|
+
(e) => e.event_type === "tool_result" && e.seq > event.seq && e.payload.tool_name === event.payload.tool_name
|
|
124
|
+
);
|
|
125
|
+
toolCalls.push({
|
|
126
|
+
tool: event.payload.tool_name || "unknown",
|
|
127
|
+
timestamp: event.ts,
|
|
128
|
+
key_inputs: this.extractKeyInputs(event.payload),
|
|
129
|
+
key_outputs: resultEvent ? this.extractKeyOutputs(resultEvent.payload) : {},
|
|
130
|
+
files_affected: this.extractAffectedFiles(
|
|
131
|
+
event.payload,
|
|
132
|
+
resultEvent?.payload
|
|
133
|
+
),
|
|
134
|
+
success: resultEvent ? !resultEvent.payload.error : false,
|
|
135
|
+
error: resultEvent?.payload.error
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return toolCalls;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Extract key inputs from tool call
|
|
142
|
+
*/
|
|
143
|
+
extractKeyInputs(payload) {
|
|
144
|
+
const keys = [
|
|
145
|
+
"file_path",
|
|
146
|
+
"command",
|
|
147
|
+
"query",
|
|
148
|
+
"path",
|
|
149
|
+
"pattern",
|
|
150
|
+
"content"
|
|
151
|
+
];
|
|
152
|
+
const result = {};
|
|
153
|
+
for (const key of keys) {
|
|
154
|
+
if (payload.arguments?.[key]) {
|
|
155
|
+
result[key] = payload.arguments[key];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Extract key outputs from tool result
|
|
162
|
+
*/
|
|
163
|
+
extractKeyOutputs(payload) {
|
|
164
|
+
return {
|
|
165
|
+
success: !payload.error,
|
|
166
|
+
error: payload.error,
|
|
167
|
+
result_type: payload.result_type,
|
|
168
|
+
files_created: payload.files_created,
|
|
169
|
+
files_modified: payload.files_modified
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Extract affected files from tool events
|
|
174
|
+
*/
|
|
175
|
+
extractAffectedFiles(callPayload, resultPayload) {
|
|
176
|
+
const files = /* @__PURE__ */ new Set();
|
|
177
|
+
if (callPayload?.arguments?.file_path) {
|
|
178
|
+
files.add(callPayload.arguments.file_path);
|
|
179
|
+
}
|
|
180
|
+
if (callPayload?.arguments?.path) {
|
|
181
|
+
files.add(callPayload.arguments.path);
|
|
182
|
+
}
|
|
183
|
+
if (resultPayload?.files_created) {
|
|
184
|
+
resultPayload.files_created.forEach((f) => files.add(f));
|
|
185
|
+
}
|
|
186
|
+
if (resultPayload?.files_modified) {
|
|
187
|
+
resultPayload.files_modified.forEach((f) => files.add(f));
|
|
188
|
+
}
|
|
189
|
+
return Array.from(files);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Extract file operations from events
|
|
193
|
+
*/
|
|
194
|
+
extractFileOperations(events) {
|
|
195
|
+
const fileOps = [];
|
|
196
|
+
const fileTools = ["Read", "Write", "Edit", "MultiEdit", "Delete"];
|
|
197
|
+
const toolEvents = events.filter(
|
|
198
|
+
(e) => e.event_type === "tool_call" && fileTools.includes(e.payload.tool_name)
|
|
199
|
+
);
|
|
200
|
+
for (const event of toolEvents) {
|
|
201
|
+
const operation = this.mapToolToOperation(event.payload.tool_name);
|
|
202
|
+
const path2 = event.payload.arguments?.file_path || event.payload.arguments?.path || "unknown";
|
|
203
|
+
fileOps.push({
|
|
204
|
+
type: operation,
|
|
205
|
+
path: path2,
|
|
206
|
+
timestamp: event.ts,
|
|
207
|
+
success: true,
|
|
208
|
+
// Will be updated from result
|
|
209
|
+
error: void 0
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return fileOps;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Map tool name to file operation type
|
|
216
|
+
*/
|
|
217
|
+
mapToolToOperation(toolName) {
|
|
218
|
+
const mapping = {
|
|
219
|
+
Read: "read",
|
|
220
|
+
Write: "write",
|
|
221
|
+
Edit: "edit",
|
|
222
|
+
MultiEdit: "edit",
|
|
223
|
+
Delete: "delete"
|
|
224
|
+
};
|
|
225
|
+
return mapping[toolName] || "read";
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Extract decisions from events
|
|
229
|
+
*/
|
|
230
|
+
extractDecisions(events) {
|
|
231
|
+
const decisions = [];
|
|
232
|
+
const decisionEvents = events.filter((e) => e.event_type === "decision");
|
|
233
|
+
for (const event of decisionEvents) {
|
|
234
|
+
if (event.payload.text) {
|
|
235
|
+
decisions.push(event.payload.text);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return decisions;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Extract error patterns and resolutions
|
|
242
|
+
*/
|
|
243
|
+
extractErrorPatterns(events) {
|
|
244
|
+
const patterns = [];
|
|
245
|
+
const errorEvents = events.filter(
|
|
246
|
+
(e) => e.event_type === "tool_result" && e.payload.error
|
|
247
|
+
);
|
|
248
|
+
for (const errorEvent of errorEvents) {
|
|
249
|
+
const subsequentTools = events.filter((e) => e.event_type === "tool_call" && e.seq > errorEvent.seq).slice(0, 3);
|
|
250
|
+
if (subsequentTools.length > 0) {
|
|
251
|
+
patterns.push({
|
|
252
|
+
error: errorEvent.payload.error,
|
|
253
|
+
resolution: `Attempted resolution with ${subsequentTools.map((t) => t.payload.tool_name).join(", ")}`,
|
|
254
|
+
tool_sequence: subsequentTools.map((t) => t.payload.tool_name),
|
|
255
|
+
timestamp: errorEvent.ts
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return patterns;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Restore context after compaction detected
|
|
263
|
+
*/
|
|
264
|
+
async restoreContext() {
|
|
265
|
+
if (this.preservedAnchors.size === 0) {
|
|
266
|
+
logger.warn("No preserved anchors to restore from");
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const anchors = Array.from(this.preservedAnchors.values());
|
|
270
|
+
anchors.sort((a, b) => b.created_at - a.created_at);
|
|
271
|
+
const latestAnchor = anchors[0];
|
|
272
|
+
const restorationFrame = this.frameManager.createFrame({
|
|
273
|
+
type: "review",
|
|
274
|
+
name: "Context Restoration After Compaction",
|
|
275
|
+
inputs: { reason: "autocompaction_detected" }
|
|
276
|
+
});
|
|
277
|
+
this.frameManager.addAnchor(
|
|
278
|
+
"FACT",
|
|
279
|
+
`Context restored from token position ${latestAnchor.token_estimate}`,
|
|
280
|
+
10,
|
|
281
|
+
{ restoration: true },
|
|
282
|
+
restorationFrame
|
|
283
|
+
);
|
|
284
|
+
const toolSequence = latestAnchor.content.tool_calls.map((t) => t.tool).join(" \u2192 ");
|
|
285
|
+
this.frameManager.addAnchor(
|
|
286
|
+
"FACT",
|
|
287
|
+
`Tool sequence: ${toolSequence}`,
|
|
288
|
+
9,
|
|
289
|
+
{},
|
|
290
|
+
restorationFrame
|
|
291
|
+
);
|
|
292
|
+
const files = /* @__PURE__ */ new Set();
|
|
293
|
+
latestAnchor.content.file_operations.forEach((op) => files.add(op.path));
|
|
294
|
+
if (files.size > 0) {
|
|
295
|
+
this.frameManager.addAnchor(
|
|
296
|
+
"FACT",
|
|
297
|
+
`Files touched: ${Array.from(files).join(", ")}`,
|
|
298
|
+
8,
|
|
299
|
+
{},
|
|
300
|
+
restorationFrame
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
for (const decision of latestAnchor.content.decisions) {
|
|
304
|
+
this.frameManager.addAnchor(
|
|
305
|
+
"DECISION",
|
|
306
|
+
decision,
|
|
307
|
+
7,
|
|
308
|
+
{},
|
|
309
|
+
restorationFrame
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
logger.info("Context restored after compaction detection");
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Get current metrics
|
|
316
|
+
*/
|
|
317
|
+
getMetrics() {
|
|
318
|
+
return { ...this.metrics };
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Reset token counter (e.g., at session start)
|
|
322
|
+
*/
|
|
323
|
+
resetTokenCount() {
|
|
324
|
+
this.metrics.estimatedTokens = 0;
|
|
325
|
+
this.tokenAccumulator = 0;
|
|
326
|
+
this.metrics.lastCompactionAt = void 0;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
class EnhancedRehydrationManager {
|
|
330
|
+
frameManager;
|
|
331
|
+
compactionHandler;
|
|
332
|
+
snapshotThreshold = 10;
|
|
333
|
+
// Take snapshot every N significant events
|
|
334
|
+
eventCount = 0;
|
|
335
|
+
rehydrationStorage = /* @__PURE__ */ new Map();
|
|
336
|
+
constructor(frameManager, compactionHandler) {
|
|
337
|
+
this.frameManager = frameManager;
|
|
338
|
+
this.compactionHandler = compactionHandler;
|
|
339
|
+
this.setupCompactDetection();
|
|
340
|
+
this.initializeStackTraceStorage();
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Initialize dedicated stack trace storage in database
|
|
344
|
+
*/
|
|
345
|
+
initializeStackTraceStorage() {
|
|
346
|
+
try {
|
|
347
|
+
const db = this.frameManager.db;
|
|
348
|
+
db.exec(`
|
|
349
|
+
CREATE TABLE IF NOT EXISTS stack_traces (
|
|
350
|
+
trace_id TEXT PRIMARY KEY,
|
|
351
|
+
frame_id TEXT,
|
|
352
|
+
project_id TEXT NOT NULL,
|
|
353
|
+
error_message TEXT NOT NULL,
|
|
354
|
+
stack_frames TEXT NOT NULL,
|
|
355
|
+
file_path TEXT,
|
|
356
|
+
line_number INTEGER,
|
|
357
|
+
function_name TEXT,
|
|
358
|
+
context TEXT,
|
|
359
|
+
resolution_attempted TEXT,
|
|
360
|
+
resolution_status TEXT NOT NULL DEFAULT 'pending',
|
|
361
|
+
error_type TEXT,
|
|
362
|
+
error_severity TEXT DEFAULT 'medium',
|
|
363
|
+
created_at INTEGER DEFAULT (unixepoch()),
|
|
364
|
+
updated_at INTEGER DEFAULT (unixepoch()),
|
|
365
|
+
FOREIGN KEY(frame_id) REFERENCES frames(frame_id)
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
CREATE INDEX IF NOT EXISTS idx_stack_traces_frame ON stack_traces(frame_id);
|
|
369
|
+
CREATE INDEX IF NOT EXISTS idx_stack_traces_status ON stack_traces(resolution_status);
|
|
370
|
+
CREATE INDEX IF NOT EXISTS idx_stack_traces_type ON stack_traces(error_type);
|
|
371
|
+
CREATE INDEX IF NOT EXISTS idx_stack_traces_severity ON stack_traces(error_severity);
|
|
372
|
+
CREATE INDEX IF NOT EXISTS idx_stack_traces_created ON stack_traces(created_at);
|
|
373
|
+
`);
|
|
374
|
+
logger.info("Stack trace storage initialized");
|
|
375
|
+
} catch (error) {
|
|
376
|
+
logger.error("Failed to initialize stack trace storage:", error);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Set up automatic compact detection and recovery
|
|
381
|
+
*/
|
|
382
|
+
setupCompactDetection() {
|
|
383
|
+
setInterval(() => this.checkForCompactionEvent(), 3e4);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Enhanced file content snapshot with context
|
|
387
|
+
*/
|
|
388
|
+
async captureFileSnapshot(filePath, contextTags = []) {
|
|
389
|
+
try {
|
|
390
|
+
const stats = await fs.stat(filePath);
|
|
391
|
+
const content = await fs.readFile(filePath, "utf8");
|
|
392
|
+
const hash = this.simpleHash(content);
|
|
393
|
+
return {
|
|
394
|
+
path: filePath,
|
|
395
|
+
content,
|
|
396
|
+
size: stats.size,
|
|
397
|
+
lastModified: stats.mtimeMs,
|
|
398
|
+
hash,
|
|
399
|
+
contextTags
|
|
400
|
+
};
|
|
401
|
+
} catch (error) {
|
|
402
|
+
logger.warn(`Failed to capture snapshot for ${filePath}:`, error);
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Capture conversation reasoning and decisions including stack traces
|
|
408
|
+
*/
|
|
409
|
+
captureConversationContext(reasoning, decisions, nextSteps = [], userPrefs = {}, painPoints = [], stackTraces = [], errorPatterns = []) {
|
|
410
|
+
return {
|
|
411
|
+
timestamp: Date.now(),
|
|
412
|
+
reasoning,
|
|
413
|
+
decisions_made: decisions,
|
|
414
|
+
next_steps: nextSteps,
|
|
415
|
+
user_preferences: userPrefs,
|
|
416
|
+
pain_points: painPoints,
|
|
417
|
+
stack_traces: stackTraces,
|
|
418
|
+
error_patterns: errorPatterns
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Capture stack trace from error with context and store in database
|
|
423
|
+
*/
|
|
424
|
+
captureStackTrace(error, context, filePath, resolutionAttempts = [], frameId) {
|
|
425
|
+
const errorMessage = typeof error === "string" ? error : error.message;
|
|
426
|
+
const stackFrames = typeof error === "string" ? [] : error.stack?.split("\n") || [];
|
|
427
|
+
let extractedFilePath = filePath;
|
|
428
|
+
let lineNumber;
|
|
429
|
+
let functionName;
|
|
430
|
+
if (stackFrames.length > 0) {
|
|
431
|
+
const firstFrame = stackFrames.find((frame) => frame.includes("at "));
|
|
432
|
+
if (firstFrame) {
|
|
433
|
+
const match = firstFrame.match(/at (.+?) \((.+):(\d+):(\d+)\)/);
|
|
434
|
+
if (match) {
|
|
435
|
+
functionName = match[1];
|
|
436
|
+
extractedFilePath = extractedFilePath || match[2];
|
|
437
|
+
lineNumber = parseInt(match[3]);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const stackTrace = {
|
|
442
|
+
error_message: errorMessage,
|
|
443
|
+
stack_frames: stackFrames,
|
|
444
|
+
file_path: extractedFilePath,
|
|
445
|
+
line_number: lineNumber,
|
|
446
|
+
function_name: functionName,
|
|
447
|
+
timestamp: Date.now(),
|
|
448
|
+
context,
|
|
449
|
+
resolution_attempted: resolutionAttempts,
|
|
450
|
+
resolution_status: "pending"
|
|
451
|
+
};
|
|
452
|
+
this.storeStackTrace(stackTrace, frameId);
|
|
453
|
+
return stackTrace;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Store stack trace in database
|
|
457
|
+
*/
|
|
458
|
+
storeStackTrace(stackTrace, frameId) {
|
|
459
|
+
try {
|
|
460
|
+
const db = this.frameManager.db;
|
|
461
|
+
const traceId = this.generateTraceId();
|
|
462
|
+
const currentFrameId = frameId || this.frameManager.getCurrentFrameId();
|
|
463
|
+
const errorType = this.extractErrorType(stackTrace.error_message);
|
|
464
|
+
const severity = this.determineErrorSeverity(stackTrace);
|
|
465
|
+
const stmt = db.prepare(`
|
|
466
|
+
INSERT INTO stack_traces (
|
|
467
|
+
trace_id, frame_id, project_id, error_message, stack_frames,
|
|
468
|
+
file_path, line_number, function_name, context, resolution_attempted,
|
|
469
|
+
resolution_status, error_type, error_severity
|
|
470
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
471
|
+
`);
|
|
472
|
+
stmt.run(
|
|
473
|
+
traceId,
|
|
474
|
+
currentFrameId,
|
|
475
|
+
this.frameManager.projectId,
|
|
476
|
+
stackTrace.error_message,
|
|
477
|
+
JSON.stringify(stackTrace.stack_frames),
|
|
478
|
+
stackTrace.file_path,
|
|
479
|
+
stackTrace.line_number,
|
|
480
|
+
stackTrace.function_name,
|
|
481
|
+
stackTrace.context,
|
|
482
|
+
JSON.stringify(stackTrace.resolution_attempted),
|
|
483
|
+
stackTrace.resolution_status,
|
|
484
|
+
errorType,
|
|
485
|
+
severity
|
|
486
|
+
);
|
|
487
|
+
logger.info(`Stored stack trace ${traceId} for frame ${currentFrameId}`);
|
|
488
|
+
return traceId;
|
|
489
|
+
} catch (error) {
|
|
490
|
+
logger.error("Failed to store stack trace:", error);
|
|
491
|
+
return "";
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Retrieve stack traces from database
|
|
496
|
+
*/
|
|
497
|
+
getStackTraces(frameId, limit = 50) {
|
|
498
|
+
try {
|
|
499
|
+
const db = this.frameManager.db;
|
|
500
|
+
const traces = [];
|
|
501
|
+
let query;
|
|
502
|
+
let params;
|
|
503
|
+
if (frameId) {
|
|
504
|
+
query = `
|
|
505
|
+
SELECT * FROM stack_traces
|
|
506
|
+
WHERE frame_id = ?
|
|
507
|
+
ORDER BY created_at DESC
|
|
508
|
+
LIMIT ?
|
|
509
|
+
`;
|
|
510
|
+
params = [frameId, limit];
|
|
511
|
+
} else {
|
|
512
|
+
query = `
|
|
513
|
+
SELECT * FROM stack_traces
|
|
514
|
+
WHERE project_id = ?
|
|
515
|
+
ORDER BY created_at DESC
|
|
516
|
+
LIMIT ?
|
|
517
|
+
`;
|
|
518
|
+
params = [this.frameManager.projectId, limit];
|
|
519
|
+
}
|
|
520
|
+
const rows = db.prepare(query).all(...params);
|
|
521
|
+
for (const row of rows) {
|
|
522
|
+
traces.push({
|
|
523
|
+
error_message: row.error_message,
|
|
524
|
+
stack_frames: JSON.parse(row.stack_frames || "[]"),
|
|
525
|
+
file_path: row.file_path,
|
|
526
|
+
line_number: row.line_number,
|
|
527
|
+
function_name: row.function_name,
|
|
528
|
+
timestamp: row.created_at * 1e3,
|
|
529
|
+
// Convert from unix to JS timestamp
|
|
530
|
+
context: row.context,
|
|
531
|
+
resolution_attempted: JSON.parse(row.resolution_attempted || "[]"),
|
|
532
|
+
resolution_status: row.resolution_status
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
return traces;
|
|
536
|
+
} catch (error) {
|
|
537
|
+
logger.error("Failed to retrieve stack traces:", error);
|
|
538
|
+
return [];
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Update stack trace resolution status
|
|
543
|
+
*/
|
|
544
|
+
updateStackTraceStatus(traceId, status, resolutionAttempts) {
|
|
545
|
+
try {
|
|
546
|
+
const db = this.frameManager.db;
|
|
547
|
+
const stmt = db.prepare(`
|
|
548
|
+
UPDATE stack_traces
|
|
549
|
+
SET resolution_status = ?, resolution_attempted = ?, updated_at = unixepoch()
|
|
550
|
+
WHERE trace_id = ?
|
|
551
|
+
`);
|
|
552
|
+
const result = stmt.run(
|
|
553
|
+
status,
|
|
554
|
+
resolutionAttempts ? JSON.stringify(resolutionAttempts) : void 0,
|
|
555
|
+
traceId
|
|
556
|
+
);
|
|
557
|
+
return result.changes > 0;
|
|
558
|
+
} catch (error) {
|
|
559
|
+
logger.error("Failed to update stack trace status:", error);
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Helper methods for stack trace processing
|
|
565
|
+
*/
|
|
566
|
+
generateTraceId() {
|
|
567
|
+
return `trace_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
568
|
+
}
|
|
569
|
+
extractErrorType(errorMessage) {
|
|
570
|
+
const typeMatch = errorMessage.match(/^(\w+Error?):/);
|
|
571
|
+
return typeMatch ? typeMatch[1] : "Unknown";
|
|
572
|
+
}
|
|
573
|
+
determineErrorSeverity(stackTrace) {
|
|
574
|
+
const message = stackTrace.error_message.toLowerCase();
|
|
575
|
+
if (message.includes("critical") || message.includes("fatal") || message.includes("cannot read properties")) {
|
|
576
|
+
return "high";
|
|
577
|
+
} else if (message.includes("warning") || message.includes("deprecated")) {
|
|
578
|
+
return "low";
|
|
579
|
+
} else {
|
|
580
|
+
return "medium";
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Auto-detect project structure and relationships
|
|
585
|
+
*/
|
|
586
|
+
async analyzeProjectMapping(workingDir) {
|
|
587
|
+
const mapping = {
|
|
588
|
+
file_relationships: {},
|
|
589
|
+
workflow_sequences: [],
|
|
590
|
+
key_directories: [],
|
|
591
|
+
entry_points: [],
|
|
592
|
+
configuration_files: []
|
|
593
|
+
};
|
|
594
|
+
try {
|
|
595
|
+
const configPatterns = [
|
|
596
|
+
"package.json",
|
|
597
|
+
"tsconfig.json",
|
|
598
|
+
".env",
|
|
599
|
+
"docker-compose.yml",
|
|
600
|
+
"*.config.js",
|
|
601
|
+
"*.config.ts",
|
|
602
|
+
"Dockerfile",
|
|
603
|
+
"README.md"
|
|
604
|
+
];
|
|
605
|
+
const files = await this.getDirectoryFiles(workingDir);
|
|
606
|
+
for (const file of files) {
|
|
607
|
+
const ext = path.extname(file);
|
|
608
|
+
const basename = path.basename(file);
|
|
609
|
+
if (configPatterns.some(
|
|
610
|
+
(pattern) => pattern.includes("*") ? basename.includes(pattern.replace("*", "")) : basename === pattern
|
|
611
|
+
)) {
|
|
612
|
+
mapping.configuration_files.push(file);
|
|
613
|
+
}
|
|
614
|
+
if (basename === "index.js" || basename === "index.ts" || basename === "main.js") {
|
|
615
|
+
mapping.entry_points.push(file);
|
|
616
|
+
}
|
|
617
|
+
const filePrefix = basename.split(".")[0];
|
|
618
|
+
const relatedFiles = files.filter(
|
|
619
|
+
(f) => f !== file && path.basename(f).startsWith(filePrefix)
|
|
620
|
+
);
|
|
621
|
+
if (relatedFiles.length > 0) {
|
|
622
|
+
mapping.file_relationships[file] = relatedFiles;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
const dirs = files.map((f) => path.dirname(f)).filter((v, i, a) => a.indexOf(v) === i);
|
|
626
|
+
mapping.key_directories = dirs.filter(
|
|
627
|
+
(dir) => ["src", "lib", "components", "pages", "api", "utils", "types"].some(
|
|
628
|
+
(key) => dir.includes(key)
|
|
629
|
+
)
|
|
630
|
+
);
|
|
631
|
+
} catch (error) {
|
|
632
|
+
logger.warn("Failed to analyze project mapping:", error);
|
|
633
|
+
}
|
|
634
|
+
return mapping;
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Create comprehensive rehydration context before compaction
|
|
638
|
+
*/
|
|
639
|
+
async createRehydrationCheckpoint() {
|
|
640
|
+
const sessionId = this.frameManager.getSessionId() || "unknown";
|
|
641
|
+
const checkpointId = `${sessionId}_${Date.now()}`;
|
|
642
|
+
try {
|
|
643
|
+
const workingDir = process.cwd();
|
|
644
|
+
const fileSnapshots = [];
|
|
645
|
+
const recentFiles = await this.getRecentlyModifiedFiles(workingDir);
|
|
646
|
+
for (const file of recentFiles.slice(0, 20)) {
|
|
647
|
+
const snapshot = await this.captureFileSnapshot(
|
|
648
|
+
file,
|
|
649
|
+
this.inferContextTags(file)
|
|
650
|
+
);
|
|
651
|
+
if (snapshot) {
|
|
652
|
+
fileSnapshots.push(snapshot);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const projectMapping = await this.analyzeProjectMapping(workingDir);
|
|
656
|
+
const conversationContext = this.extractConversationContext();
|
|
657
|
+
const rehydrationContext = {
|
|
658
|
+
session_id: sessionId,
|
|
659
|
+
compact_detected_at: Date.now(),
|
|
660
|
+
pre_compact_state: {
|
|
661
|
+
file_snapshots: fileSnapshots,
|
|
662
|
+
conversation_context: conversationContext,
|
|
663
|
+
project_mapping: projectMapping,
|
|
664
|
+
active_workflows: this.detectActiveWorkflows(fileSnapshots),
|
|
665
|
+
current_focus: this.inferCurrentFocus(
|
|
666
|
+
fileSnapshots,
|
|
667
|
+
conversationContext
|
|
668
|
+
)
|
|
669
|
+
},
|
|
670
|
+
recovery_anchors: this.createRecoveryAnchors(
|
|
671
|
+
fileSnapshots,
|
|
672
|
+
conversationContext
|
|
673
|
+
)
|
|
674
|
+
};
|
|
675
|
+
this.rehydrationStorage.set(checkpointId, rehydrationContext);
|
|
676
|
+
await this.persistRehydrationContext(checkpointId, rehydrationContext);
|
|
677
|
+
logger.info(
|
|
678
|
+
`Created rehydration checkpoint ${checkpointId} with ${fileSnapshots.length} file snapshots`
|
|
679
|
+
);
|
|
680
|
+
return checkpointId;
|
|
681
|
+
} catch (error) {
|
|
682
|
+
logger.error("Failed to create rehydration checkpoint:", error);
|
|
683
|
+
throw error;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Inject rich context after compaction detection
|
|
688
|
+
*/
|
|
689
|
+
async rehydrateContext(checkpointId) {
|
|
690
|
+
try {
|
|
691
|
+
let context;
|
|
692
|
+
if (checkpointId) {
|
|
693
|
+
context = this.rehydrationStorage.get(checkpointId);
|
|
694
|
+
if (!context) {
|
|
695
|
+
context = await this.loadPersistedContext(checkpointId);
|
|
696
|
+
}
|
|
697
|
+
} else {
|
|
698
|
+
context = await this.findMostRecentContext();
|
|
699
|
+
}
|
|
700
|
+
if (!context) {
|
|
701
|
+
logger.warn("No rehydration context available");
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
await this.injectRichContext(context);
|
|
705
|
+
return true;
|
|
706
|
+
} catch (error) {
|
|
707
|
+
logger.error("Failed to rehydrate context:", error);
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Inject rich context into current session
|
|
713
|
+
*/
|
|
714
|
+
async injectRichContext(context) {
|
|
715
|
+
const frameId = this.frameManager.getCurrentFrameId();
|
|
716
|
+
if (!frameId) {
|
|
717
|
+
logger.warn("No active frame for context injection");
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
for (const snapshot of context.pre_compact_state.file_snapshots.slice(
|
|
721
|
+
0,
|
|
722
|
+
5
|
|
723
|
+
)) {
|
|
724
|
+
this.frameManager.addAnchor(
|
|
725
|
+
"FACT",
|
|
726
|
+
`File: ${snapshot.path} (${snapshot.contextTags.join(", ")})
|
|
727
|
+
Last modified: ${new Date(snapshot.lastModified).toISOString()}
|
|
728
|
+
Size: ${snapshot.size} bytes
|
|
729
|
+
Content preview: ${this.getContentPreview(snapshot.content)}`,
|
|
730
|
+
9,
|
|
731
|
+
{
|
|
732
|
+
rehydration: true,
|
|
733
|
+
file_path: snapshot.path,
|
|
734
|
+
context_tags: snapshot.contextTags
|
|
735
|
+
},
|
|
736
|
+
frameId
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
const conv = context.pre_compact_state.conversation_context;
|
|
740
|
+
if (conv.decisions_made.length > 0) {
|
|
741
|
+
this.frameManager.addAnchor(
|
|
742
|
+
"DECISION",
|
|
743
|
+
`Previous decisions: ${conv.decisions_made.join("; ")}`,
|
|
744
|
+
8,
|
|
745
|
+
{ rehydration: true },
|
|
746
|
+
frameId
|
|
747
|
+
);
|
|
748
|
+
}
|
|
749
|
+
if (conv.next_steps.length > 0) {
|
|
750
|
+
this.frameManager.addAnchor(
|
|
751
|
+
"FACT",
|
|
752
|
+
`Next steps identified: ${conv.next_steps.join("; ")}`,
|
|
753
|
+
7,
|
|
754
|
+
{ rehydration: true },
|
|
755
|
+
frameId
|
|
756
|
+
);
|
|
757
|
+
}
|
|
758
|
+
if (conv.stack_traces.length > 0) {
|
|
759
|
+
for (const trace of conv.stack_traces.slice(0, 3)) {
|
|
760
|
+
this.frameManager.addAnchor(
|
|
761
|
+
"ERROR",
|
|
762
|
+
`Error context: ${trace.error_message}
|
|
763
|
+
Context: ${trace.context}
|
|
764
|
+
File: ${trace.file_path || "unknown"}${trace.line_number ? `:${trace.line_number}` : ""}
|
|
765
|
+
Function: ${trace.function_name || "unknown"}
|
|
766
|
+
Status: ${trace.resolution_status}
|
|
767
|
+
Stack preview: ${trace.stack_frames.slice(0, 3).join("\n")}`,
|
|
768
|
+
9,
|
|
769
|
+
{
|
|
770
|
+
rehydration: true,
|
|
771
|
+
error_type: trace.error_message.split(":")[0],
|
|
772
|
+
resolution_status: trace.resolution_status,
|
|
773
|
+
file_path: trace.file_path
|
|
774
|
+
},
|
|
775
|
+
frameId
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (conv.error_patterns.length > 0) {
|
|
780
|
+
this.frameManager.addAnchor(
|
|
781
|
+
"PATTERN",
|
|
782
|
+
`Recurring error patterns detected: ${conv.error_patterns.join(", ")}`,
|
|
783
|
+
7,
|
|
784
|
+
{ rehydration: true },
|
|
785
|
+
frameId
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
const mapping = context.pre_compact_state.project_mapping;
|
|
789
|
+
if (mapping.entry_points.length > 0) {
|
|
790
|
+
this.frameManager.addAnchor(
|
|
791
|
+
"FACT",
|
|
792
|
+
`Project entry points: ${mapping.entry_points.join(", ")}`,
|
|
793
|
+
6,
|
|
794
|
+
{ rehydration: true },
|
|
795
|
+
frameId
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
if (context.pre_compact_state.current_focus) {
|
|
799
|
+
this.frameManager.addAnchor(
|
|
800
|
+
"CONSTRAINT",
|
|
801
|
+
`Previous focus: ${context.pre_compact_state.current_focus}`,
|
|
802
|
+
8,
|
|
803
|
+
{ rehydration: true },
|
|
804
|
+
frameId
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
logger.info("Rich context injected successfully");
|
|
808
|
+
}
|
|
809
|
+
// Helper methods
|
|
810
|
+
async getDirectoryFiles(dir) {
|
|
811
|
+
return [];
|
|
812
|
+
}
|
|
813
|
+
async getRecentlyModifiedFiles(dir) {
|
|
814
|
+
return [];
|
|
815
|
+
}
|
|
816
|
+
inferContextTags(filePath) {
|
|
817
|
+
const tags = [];
|
|
818
|
+
const content = filePath.toLowerCase();
|
|
819
|
+
if (content.includes("pipeline") || content.includes("migrate"))
|
|
820
|
+
tags.push("migration");
|
|
821
|
+
if (content.includes("hubspot")) tags.push("hubspot");
|
|
822
|
+
if (content.includes("pipedream")) tags.push("pipedream");
|
|
823
|
+
if (content.includes("test")) tags.push("test");
|
|
824
|
+
if (content.includes("config")) tags.push("configuration");
|
|
825
|
+
return tags;
|
|
826
|
+
}
|
|
827
|
+
extractConversationContext() {
|
|
828
|
+
const recentErrors = this.extractRecentStackTraces();
|
|
829
|
+
const errorPatterns = this.detectErrorPatterns(recentErrors);
|
|
830
|
+
return {
|
|
831
|
+
timestamp: Date.now(),
|
|
832
|
+
reasoning: [],
|
|
833
|
+
decisions_made: [],
|
|
834
|
+
next_steps: [],
|
|
835
|
+
user_preferences: {},
|
|
836
|
+
pain_points: [],
|
|
837
|
+
stack_traces: recentErrors,
|
|
838
|
+
error_patterns: errorPatterns
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Extract recent stack traces from database and frame events
|
|
843
|
+
*/
|
|
844
|
+
extractRecentStackTraces() {
|
|
845
|
+
try {
|
|
846
|
+
const dbTraces = this.getStackTraces(void 0, 10);
|
|
847
|
+
const eventTraces = this.extractStackTracesFromFrameEvents();
|
|
848
|
+
const allTraces = [...dbTraces, ...eventTraces];
|
|
849
|
+
const uniqueTraces = allTraces.filter(
|
|
850
|
+
(trace, index, array) => array.findIndex(
|
|
851
|
+
(t) => t.error_message === trace.error_message && t.file_path === trace.file_path
|
|
852
|
+
) === index
|
|
853
|
+
);
|
|
854
|
+
return uniqueTraces.sort((a, b) => b.timestamp - a.timestamp).slice(0, 5);
|
|
855
|
+
} catch (error) {
|
|
856
|
+
logger.warn("Failed to extract stack traces:", error);
|
|
857
|
+
return [];
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Extract stack traces from frame events (fallback method)
|
|
862
|
+
*/
|
|
863
|
+
extractStackTracesFromFrameEvents() {
|
|
864
|
+
const traces = [];
|
|
865
|
+
try {
|
|
866
|
+
const frames = this.frameManager.getActiveFramePath();
|
|
867
|
+
for (const frame of frames.slice(-3)) {
|
|
868
|
+
const frameData = this.frameManager.getFrame(frame.frame_id);
|
|
869
|
+
if (frameData?.events) {
|
|
870
|
+
for (const event of frameData.events) {
|
|
871
|
+
if (event.type === "error" || event.type === "exception") {
|
|
872
|
+
const trace = this.parseStackTraceFromEvent(event);
|
|
873
|
+
if (trace) {
|
|
874
|
+
traces.push(trace);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
} catch (error) {
|
|
881
|
+
logger.warn("Failed to extract frame event traces:", error);
|
|
882
|
+
}
|
|
883
|
+
return traces;
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* Parse stack trace from frame event
|
|
887
|
+
*/
|
|
888
|
+
parseStackTraceFromEvent(event) {
|
|
889
|
+
try {
|
|
890
|
+
const data = typeof event.data === "string" ? JSON.parse(event.data) : event.data;
|
|
891
|
+
return {
|
|
892
|
+
error_message: data.error || data.message || "Unknown error",
|
|
893
|
+
stack_frames: data.stack ? data.stack.split("\n") : [],
|
|
894
|
+
file_path: data.file || data.fileName,
|
|
895
|
+
line_number: data.line || data.lineNumber,
|
|
896
|
+
function_name: data.function || data.functionName,
|
|
897
|
+
timestamp: event.timestamp || Date.now(),
|
|
898
|
+
context: data.context || "Error occurred during frame processing",
|
|
899
|
+
resolution_attempted: data.resolutionAttempts || [],
|
|
900
|
+
resolution_status: data.resolved ? "resolved" : "pending"
|
|
901
|
+
};
|
|
902
|
+
} catch (error) {
|
|
903
|
+
return null;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Detect recurring error patterns
|
|
908
|
+
*/
|
|
909
|
+
detectErrorPatterns(traces) {
|
|
910
|
+
const patterns = /* @__PURE__ */ new Map();
|
|
911
|
+
for (const trace of traces) {
|
|
912
|
+
const errorType = trace.error_message.split(":")[0].trim();
|
|
913
|
+
patterns.set(errorType, (patterns.get(errorType) || 0) + 1);
|
|
914
|
+
}
|
|
915
|
+
return Array.from(patterns.entries()).filter(([, count]) => count > 1).map(([pattern]) => pattern);
|
|
916
|
+
}
|
|
917
|
+
detectActiveWorkflows(snapshots) {
|
|
918
|
+
const workflows = [];
|
|
919
|
+
for (const snapshot of snapshots) {
|
|
920
|
+
if (snapshot.contextTags.includes("migration")) {
|
|
921
|
+
workflows.push("data_migration");
|
|
922
|
+
}
|
|
923
|
+
if (snapshot.path.includes("test")) {
|
|
924
|
+
workflows.push("testing");
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
return [...new Set(workflows)];
|
|
928
|
+
}
|
|
929
|
+
inferCurrentFocus(snapshots, context) {
|
|
930
|
+
if (snapshots.some((s) => s.contextTags.includes("migration"))) {
|
|
931
|
+
return "Data migration and transformation";
|
|
932
|
+
}
|
|
933
|
+
if (snapshots.some((s) => s.path.includes("test"))) {
|
|
934
|
+
return "Testing and validation";
|
|
935
|
+
}
|
|
936
|
+
return "Development";
|
|
937
|
+
}
|
|
938
|
+
createRecoveryAnchors(snapshots, context) {
|
|
939
|
+
const anchors = [];
|
|
940
|
+
for (const snapshot of snapshots.slice(0, 3)) {
|
|
941
|
+
anchors.push(
|
|
942
|
+
`File context: ${snapshot.path} with ${snapshot.contextTags.join(", ")}`
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
return anchors;
|
|
946
|
+
}
|
|
947
|
+
async persistRehydrationContext(id, context) {
|
|
948
|
+
const contextDir = path.join(process.cwd(), ".stackmemory", "rehydration");
|
|
949
|
+
await fs.mkdir(contextDir, { recursive: true });
|
|
950
|
+
await fs.writeFile(
|
|
951
|
+
path.join(contextDir, `${id}.json`),
|
|
952
|
+
JSON.stringify(context, null, 2)
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
async loadPersistedContext(id) {
|
|
956
|
+
try {
|
|
957
|
+
const contextPath = path.join(
|
|
958
|
+
process.cwd(),
|
|
959
|
+
".stackmemory",
|
|
960
|
+
"rehydration",
|
|
961
|
+
`${id}.json`
|
|
962
|
+
);
|
|
963
|
+
const content = await fs.readFile(contextPath, "utf8");
|
|
964
|
+
return JSON.parse(content);
|
|
965
|
+
} catch {
|
|
966
|
+
return void 0;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
async findMostRecentContext() {
|
|
970
|
+
return void 0;
|
|
971
|
+
}
|
|
972
|
+
checkForCompactionEvent() {
|
|
973
|
+
if (this.compactionHandler.detectCompactionEvent("")) {
|
|
974
|
+
this.rehydrateContext();
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
simpleHash(content) {
|
|
978
|
+
let hash = 0;
|
|
979
|
+
for (let i = 0; i < content.length; i++) {
|
|
980
|
+
const char = content.charCodeAt(i);
|
|
981
|
+
hash = (hash << 5) - hash + char;
|
|
982
|
+
hash = hash & hash;
|
|
983
|
+
}
|
|
984
|
+
return hash.toString(16);
|
|
985
|
+
}
|
|
986
|
+
getContentPreview(content, maxLength = 200) {
|
|
987
|
+
return content.length > maxLength ? content.substring(0, maxLength) + "..." : content;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
export {
|
|
991
|
+
CompactionHandler,
|
|
992
|
+
EnhancedRehydrationManager
|
|
993
|
+
};
|
|
994
|
+
//# sourceMappingURL=enhanced-rehydration.js.map
|