@stackmemoryai/stackmemory 0.5.59 → 0.5.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -1
- package/dist/scripts/initialize.js +68 -1
- package/dist/scripts/initialize.js.map +2 -2
- package/dist/src/cli/claude-sm.js +130 -50
- package/dist/src/cli/claude-sm.js.map +2 -2
- package/dist/src/cli/index.js +18 -3
- package/dist/src/cli/index.js.map +3 -3
- package/dist/src/core/extensions/custom-tools.js +567 -0
- package/dist/src/core/extensions/custom-tools.js.map +7 -0
- package/dist/src/core/extensions/index.js +55 -0
- package/dist/src/core/extensions/index.js.map +7 -0
- package/dist/src/core/extensions/loader.js +709 -0
- package/dist/src/core/extensions/loader.js.map +7 -0
- package/dist/src/core/extensions/plugin-system.js +506 -0
- package/dist/src/core/extensions/plugin-system.js.map +7 -0
- package/dist/src/core/extensions/provider-adapter.js +617 -0
- package/dist/src/core/extensions/provider-adapter.js.map +7 -0
- package/dist/src/core/extensions/sandbox-runtime.js +664 -0
- package/dist/src/core/extensions/sandbox-runtime.js.map +7 -0
- package/dist/src/core/retrieval/index.js +2 -0
- package/dist/src/core/retrieval/index.js.map +2 -2
- package/dist/src/core/retrieval/privacy-filter.js +129 -0
- package/dist/src/core/retrieval/privacy-filter.js.map +7 -0
- package/dist/src/core/retrieval/unified-context-assembler.js +273 -0
- package/dist/src/core/retrieval/unified-context-assembler.js.map +7 -0
- package/dist/src/core/storage/chromadb-adapter.js +32 -6
- package/dist/src/core/storage/chromadb-adapter.js.map +2 -2
- package/dist/src/hooks/diffmem-hooks.js +377 -0
- package/dist/src/hooks/diffmem-hooks.js.map +7 -0
- package/dist/src/integrations/diffmem/client.js +209 -0
- package/dist/src/integrations/diffmem/client.js.map +7 -0
- package/dist/src/integrations/diffmem/config.js +15 -0
- package/dist/src/integrations/diffmem/config.js.map +7 -0
- package/dist/{core/session → src/integrations/diffmem}/index.js +5 -8
- package/dist/src/integrations/diffmem/index.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/diffmem-handlers.js +456 -0
- package/dist/src/integrations/mcp/handlers/diffmem-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/server.js +121 -0
- package/dist/src/integrations/mcp/server.js.map +2 -2
- package/dist/src/skills/repo-ingestion-skill.js +35 -12
- package/dist/src/skills/repo-ingestion-skill.js.map +2 -2
- package/package.json +13 -7
- package/scripts/background-sync-manager.js +145 -83
- package/scripts/claude-sm-autostart.js +17 -12
- package/scripts/gepa/README.md +275 -0
- package/scripts/gepa/config.json +53 -0
- package/scripts/gepa/evals/coding-tasks.jsonl +5 -0
- package/scripts/gepa/evals/fixtures/buggy-loop.js +18 -0
- package/scripts/gepa/evals/fixtures/callback-hell.js +53 -0
- package/scripts/gepa/generations/gen-000/baseline.md +124 -0
- package/scripts/gepa/hooks/auto-optimize.js +494 -0
- package/scripts/gepa/hooks/eval-tracker.js +203 -0
- package/scripts/gepa/hooks/reflect.js +311 -0
- package/scripts/gepa/optimize.js +611 -0
- package/scripts/gepa/state.json +14 -0
- package/scripts/initialize.ts +83 -1
- package/scripts/test-pre-publish-quick.sh +1 -1
- package/dist/agents/core/agent-task-manager.js +0 -527
- package/dist/agents/core/agent-task-manager.js.map +0 -7
- package/dist/agents/testing-agent.js +0 -614
- package/dist/agents/testing-agent.js.map +0 -7
- package/dist/agents/verifiers/base-verifier.js +0 -133
- package/dist/agents/verifiers/base-verifier.js.map +0 -7
- package/dist/agents/verifiers/formatter-verifier.js +0 -130
- package/dist/agents/verifiers/formatter-verifier.js.map +0 -7
- package/dist/agents/verifiers/llm-judge.js +0 -252
- package/dist/agents/verifiers/llm-judge.js.map +0 -7
- package/dist/cli/auto-detect.js +0 -321
- package/dist/cli/auto-detect.js.map +0 -7
- package/dist/cli/browser-test.js +0 -33
- package/dist/cli/browser-test.js.map +0 -7
- package/dist/cli/claude-sm-danger.js +0 -21
- package/dist/cli/claude-sm-danger.js.map +0 -7
- package/dist/cli/claude-sm.js +0 -1156
- package/dist/cli/claude-sm.js.map +0 -7
- package/dist/cli/codex-sm-danger.js +0 -21
- package/dist/cli/codex-sm-danger.js.map +0 -7
- package/dist/cli/codex-sm.js +0 -349
- package/dist/cli/codex-sm.js.map +0 -7
- package/dist/cli/commands/api.js +0 -232
- package/dist/cli/commands/api.js.map +0 -7
- package/dist/cli/commands/auto-background.js +0 -180
- package/dist/cli/commands/auto-background.js.map +0 -7
- package/dist/cli/commands/cleanup-processes.js +0 -68
- package/dist/cli/commands/cleanup-processes.js.map +0 -7
- package/dist/cli/commands/clear.js +0 -202
- package/dist/cli/commands/clear.js.map +0 -7
- package/dist/cli/commands/config.js +0 -445
- package/dist/cli/commands/config.js.map +0 -7
- package/dist/cli/commands/context-rehydrate.js +0 -751
- package/dist/cli/commands/context-rehydrate.js.map +0 -7
- package/dist/cli/commands/context.js +0 -343
- package/dist/cli/commands/context.js.map +0 -7
- package/dist/cli/commands/daemon.js +0 -392
- package/dist/cli/commands/daemon.js.map +0 -7
- package/dist/cli/commands/dashboard.js +0 -210
- package/dist/cli/commands/dashboard.js.map +0 -7
- package/dist/cli/commands/db.js +0 -147
- package/dist/cli/commands/db.js.map +0 -7
- package/dist/cli/commands/decision.js +0 -266
- package/dist/cli/commands/decision.js.map +0 -7
- package/dist/cli/commands/discovery.js +0 -279
- package/dist/cli/commands/discovery.js.map +0 -7
- package/dist/cli/commands/handoff.js +0 -624
- package/dist/cli/commands/handoff.js.map +0 -7
- package/dist/cli/commands/hooks.js +0 -298
- package/dist/cli/commands/hooks.js.map +0 -7
- package/dist/cli/commands/linear-unified.js +0 -353
- package/dist/cli/commands/linear-unified.js.map +0 -7
- package/dist/cli/commands/linear.js +0 -529
- package/dist/cli/commands/linear.js.map +0 -7
- package/dist/cli/commands/log.js +0 -169
- package/dist/cli/commands/log.js.map +0 -7
- package/dist/cli/commands/login.js +0 -172
- package/dist/cli/commands/login.js.map +0 -7
- package/dist/cli/commands/migrate.js +0 -240
- package/dist/cli/commands/migrate.js.map +0 -7
- package/dist/cli/commands/model.js +0 -533
- package/dist/cli/commands/model.js.map +0 -7
- package/dist/cli/commands/monitor.js +0 -313
- package/dist/cli/commands/monitor.js.map +0 -7
- package/dist/cli/commands/onboard.js +0 -536
- package/dist/cli/commands/onboard.js.map +0 -7
- package/dist/cli/commands/projects.js +0 -199
- package/dist/cli/commands/projects.js.map +0 -7
- package/dist/cli/commands/quality.js +0 -413
- package/dist/cli/commands/quality.js.map +0 -7
- package/dist/cli/commands/ralph.js +0 -909
- package/dist/cli/commands/ralph.js.map +0 -7
- package/dist/cli/commands/retrieval.js +0 -248
- package/dist/cli/commands/retrieval.js.map +0 -7
- package/dist/cli/commands/search.js +0 -173
- package/dist/cli/commands/search.js.map +0 -7
- package/dist/cli/commands/service.js +0 -749
- package/dist/cli/commands/service.js.map +0 -7
- package/dist/cli/commands/session.js +0 -200
- package/dist/cli/commands/session.js.map +0 -7
- package/dist/cli/commands/settings.js +0 -306
- package/dist/cli/commands/settings.js.map +0 -7
- package/dist/cli/commands/setup.js +0 -701
- package/dist/cli/commands/setup.js.map +0 -7
- package/dist/cli/commands/shell.js +0 -249
- package/dist/cli/commands/shell.js.map +0 -7
- package/dist/cli/commands/signup.js +0 -50
- package/dist/cli/commands/signup.js.map +0 -7
- package/dist/cli/commands/skills.js +0 -470
- package/dist/cli/commands/skills.js.map +0 -7
- package/dist/cli/commands/sms-notify.js +0 -795
- package/dist/cli/commands/sms-notify.js.map +0 -7
- package/dist/cli/commands/storage-tier.js +0 -183
- package/dist/cli/commands/storage-tier.js.map +0 -7
- package/dist/cli/commands/storage.js +0 -360
- package/dist/cli/commands/storage.js.map +0 -7
- package/dist/cli/commands/sweep.js +0 -249
- package/dist/cli/commands/sweep.js.map +0 -7
- package/dist/cli/commands/tasks.js +0 -213
- package/dist/cli/commands/tasks.js.map +0 -7
- package/dist/cli/commands/test.js +0 -286
- package/dist/cli/commands/test.js.map +0 -7
- package/dist/cli/commands/workflow.js +0 -142
- package/dist/cli/commands/workflow.js.map +0 -7
- package/dist/cli/commands/worktree.js +0 -319
- package/dist/cli/commands/worktree.js.map +0 -7
- package/dist/cli/index.js +0 -594
- package/dist/cli/index.js.map +0 -7
- package/dist/cli/opencode-sm.js +0 -448
- package/dist/cli/opencode-sm.js.map +0 -7
- package/dist/cli/utils/viewer.js +0 -96
- package/dist/cli/utils/viewer.js.map +0 -7
- package/dist/core/analytics/team-analytics.js +0 -378
- package/dist/core/analytics/team-analytics.js.map +0 -7
- package/dist/core/config/config-manager.js +0 -398
- package/dist/core/config/config-manager.js.map +0 -7
- package/dist/core/config/feature-flags.js +0 -76
- package/dist/core/config/feature-flags.js.map +0 -7
- package/dist/core/config/storage-config.js +0 -115
- package/dist/core/config/storage-config.js.map +0 -7
- package/dist/core/config/types.js +0 -144
- package/dist/core/config/types.js.map +0 -7
- package/dist/core/context/auto-context.js +0 -80
- package/dist/core/context/auto-context.js.map +0 -7
- package/dist/core/context/dual-stack-manager.js +0 -870
- package/dist/core/context/dual-stack-manager.js.map +0 -7
- package/dist/core/context/enhanced-rehydration.js +0 -994
- package/dist/core/context/enhanced-rehydration.js.map +0 -7
- package/dist/core/context/frame-database.js +0 -479
- package/dist/core/context/frame-database.js.map +0 -7
- package/dist/core/context/frame-digest.js +0 -250
- package/dist/core/context/frame-digest.js.map +0 -7
- package/dist/core/context/frame-handoff-manager.js +0 -778
- package/dist/core/context/frame-handoff-manager.js.map +0 -7
- package/dist/core/context/frame-lifecycle-hooks.js +0 -119
- package/dist/core/context/frame-lifecycle-hooks.js.map +0 -7
- package/dist/core/context/frame-manager.js +0 -1069
- package/dist/core/context/frame-manager.js.map +0 -7
- package/dist/core/context/frame-recovery.js +0 -302
- package/dist/core/context/frame-recovery.js.map +0 -7
- package/dist/core/context/frame-stack.js +0 -314
- package/dist/core/context/frame-stack.js.map +0 -7
- package/dist/core/context/frame-types.js +0 -5
- package/dist/core/context/frame-types.js.map +0 -7
- package/dist/core/context/incremental-gc.js +0 -290
- package/dist/core/context/incremental-gc.js.map +0 -7
- package/dist/core/context/index.js +0 -25
- package/dist/core/context/index.js.map +0 -7
- package/dist/core/context/model-aware-compaction.js +0 -623
- package/dist/core/context/model-aware-compaction.js.map +0 -7
- package/dist/core/context/permission-manager.js +0 -185
- package/dist/core/context/permission-manager.js.map +0 -7
- package/dist/core/context/recursive-context-manager.js +0 -592
- package/dist/core/context/recursive-context-manager.js.map +0 -7
- package/dist/core/context/refactored-frame-manager.js +0 -754
- package/dist/core/context/refactored-frame-manager.js.map +0 -7
- package/dist/core/context/shared-context-layer.js +0 -621
- package/dist/core/context/shared-context-layer.js.map +0 -7
- package/dist/core/context/stack-merge-resolver.js +0 -749
- package/dist/core/context/stack-merge-resolver.js.map +0 -7
- package/dist/core/context/validation.js +0 -130
- package/dist/core/context/validation.js.map +0 -7
- package/dist/core/database/batch-operations.js +0 -384
- package/dist/core/database/batch-operations.js.map +0 -7
- package/dist/core/database/connection-pool.js +0 -330
- package/dist/core/database/connection-pool.js.map +0 -7
- package/dist/core/database/database-adapter.js +0 -60
- package/dist/core/database/database-adapter.js.map +0 -7
- package/dist/core/database/migration-manager.js +0 -614
- package/dist/core/database/migration-manager.js.map +0 -7
- package/dist/core/database/paradedb-adapter.js +0 -990
- package/dist/core/database/paradedb-adapter.js.map +0 -7
- package/dist/core/database/query-cache.js +0 -298
- package/dist/core/database/query-cache.js.map +0 -7
- package/dist/core/database/query-router.js +0 -430
- package/dist/core/database/query-router.js.map +0 -7
- package/dist/core/database/sqlite-adapter.js +0 -738
- package/dist/core/database/sqlite-adapter.js.map +0 -7
- package/dist/core/digest/enhanced-hybrid-digest.js +0 -277
- package/dist/core/digest/enhanced-hybrid-digest.js.map +0 -7
- package/dist/core/digest/frame-digest-integration.js +0 -176
- package/dist/core/digest/frame-digest-integration.js.map +0 -7
- package/dist/core/digest/hybrid-digest-generator.js +0 -553
- package/dist/core/digest/hybrid-digest-generator.js.map +0 -7
- package/dist/core/digest/index.js +0 -9
- package/dist/core/digest/index.js.map +0 -7
- package/dist/core/digest/types.js +0 -25
- package/dist/core/digest/types.js.map +0 -7
- package/dist/core/errors/error-utils.js +0 -208
- package/dist/core/errors/error-utils.js.map +0 -7
- package/dist/core/errors/index.js +0 -521
- package/dist/core/errors/index.js.map +0 -7
- package/dist/core/errors/recovery.js +0 -269
- package/dist/core/errors/recovery.js.map +0 -7
- package/dist/core/execution/parallel-executor.js +0 -258
- package/dist/core/execution/parallel-executor.js.map +0 -7
- package/dist/core/frame/workflow-templates.js +0 -319
- package/dist/core/frame/workflow-templates.js.map +0 -7
- package/dist/core/merge/conflict-detector.js +0 -431
- package/dist/core/merge/conflict-detector.js.map +0 -7
- package/dist/core/merge/index.js +0 -9
- package/dist/core/merge/index.js.map +0 -7
- package/dist/core/merge/resolution-engine.js +0 -558
- package/dist/core/merge/resolution-engine.js.map +0 -7
- package/dist/core/merge/stack-diff.js +0 -532
- package/dist/core/merge/stack-diff.js.map +0 -7
- package/dist/core/merge/unified-merge-resolver.js +0 -303
- package/dist/core/merge/unified-merge-resolver.js.map +0 -7
- package/dist/core/models/fallback-monitor.js +0 -232
- package/dist/core/models/fallback-monitor.js.map +0 -7
- package/dist/core/models/model-router.js +0 -340
- package/dist/core/models/model-router.js.map +0 -7
- package/dist/core/monitoring/error-handler.js +0 -49
- package/dist/core/monitoring/error-handler.js.map +0 -7
- package/dist/core/monitoring/logger.js +0 -202
- package/dist/core/monitoring/logger.js.map +0 -7
- package/dist/core/monitoring/metrics.js +0 -172
- package/dist/core/monitoring/metrics.js.map +0 -7
- package/dist/core/monitoring/progress-tracker.js +0 -189
- package/dist/core/monitoring/progress-tracker.js.map +0 -7
- package/dist/core/monitoring/session-monitor.js +0 -300
- package/dist/core/monitoring/session-monitor.js.map +0 -7
- package/dist/core/performance/context-cache.js +0 -273
- package/dist/core/performance/context-cache.js.map +0 -7
- package/dist/core/performance/index.js +0 -11
- package/dist/core/performance/index.js.map +0 -7
- package/dist/core/performance/lazy-context-loader.js +0 -327
- package/dist/core/performance/lazy-context-loader.js.map +0 -7
- package/dist/core/performance/monitor.js +0 -221
- package/dist/core/performance/monitor.js.map +0 -7
- package/dist/core/performance/optimized-frame-context.js +0 -345
- package/dist/core/performance/optimized-frame-context.js.map +0 -7
- package/dist/core/performance/performance-benchmark.js +0 -277
- package/dist/core/performance/performance-benchmark.js.map +0 -7
- package/dist/core/performance/performance-profiler.js +0 -370
- package/dist/core/performance/performance-profiler.js.map +0 -7
- package/dist/core/performance/streaming-jsonl-parser.js +0 -195
- package/dist/core/performance/streaming-jsonl-parser.js.map +0 -7
- package/dist/core/persistence/postgres-adapter.js +0 -349
- package/dist/core/persistence/postgres-adapter.js.map +0 -7
- package/dist/core/projects/project-isolation.js +0 -201
- package/dist/core/projects/project-isolation.js.map +0 -7
- package/dist/core/projects/project-manager.js +0 -697
- package/dist/core/projects/project-manager.js.map +0 -7
- package/dist/core/query/query-parser.js +0 -370
- package/dist/core/query/query-parser.js.map +0 -7
- package/dist/core/query/query-templates.js +0 -321
- package/dist/core/query/query-templates.js.map +0 -7
- package/dist/core/retrieval/context-retriever.js +0 -479
- package/dist/core/retrieval/context-retriever.js.map +0 -7
- package/dist/core/retrieval/graph-retrieval.js +0 -662
- package/dist/core/retrieval/graph-retrieval.js.map +0 -7
- package/dist/core/retrieval/hierarchical-retrieval.js +0 -656
- package/dist/core/retrieval/hierarchical-retrieval.js.map +0 -7
- package/dist/core/retrieval/index.js +0 -8
- package/dist/core/retrieval/index.js.map +0 -7
- package/dist/core/retrieval/llm-context-retrieval.js +0 -613
- package/dist/core/retrieval/llm-context-retrieval.js.map +0 -7
- package/dist/core/retrieval/llm-provider.js +0 -151
- package/dist/core/retrieval/llm-provider.js.map +0 -7
- package/dist/core/retrieval/retrieval-audit.js +0 -236
- package/dist/core/retrieval/retrieval-audit.js.map +0 -7
- package/dist/core/retrieval/retrieval-benchmarks.js +0 -521
- package/dist/core/retrieval/retrieval-benchmarks.js.map +0 -7
- package/dist/core/retrieval/summary-generator.js +0 -589
- package/dist/core/retrieval/summary-generator.js.map +0 -7
- package/dist/core/retrieval/types.js +0 -21
- package/dist/core/retrieval/types.js.map +0 -7
- package/dist/core/security/index.js +0 -35
- package/dist/core/security/index.js.map +0 -7
- package/dist/core/security/input-sanitizer.js +0 -321
- package/dist/core/security/input-sanitizer.js.map +0 -7
- package/dist/core/session/clear-survival.js +0 -465
- package/dist/core/session/clear-survival.js.map +0 -7
- package/dist/core/session/enhanced-handoff.js +0 -792
- package/dist/core/session/enhanced-handoff.js.map +0 -7
- package/dist/core/session/handoff-generator.js +0 -343
- package/dist/core/session/handoff-generator.js.map +0 -7
- package/dist/core/session/index.js.map +0 -7
- package/dist/core/session/session-manager.js +0 -347
- package/dist/core/session/session-manager.js.map +0 -7
- package/dist/core/skills/index.js +0 -7
- package/dist/core/skills/index.js.map +0 -7
- package/dist/core/skills/skill-storage.js +0 -764
- package/dist/core/skills/skill-storage.js.map +0 -7
- package/dist/core/skills/types.js +0 -193
- package/dist/core/skills/types.js.map +0 -7
- package/dist/core/storage/chromadb-adapter.js +0 -354
- package/dist/core/storage/chromadb-adapter.js.map +0 -7
- package/dist/core/storage/infinite-storage.js +0 -510
- package/dist/core/storage/infinite-storage.js.map +0 -7
- package/dist/core/storage/railway-optimized-storage.js +0 -591
- package/dist/core/storage/railway-optimized-storage.js.map +0 -7
- package/dist/core/storage/remote-storage.js +0 -489
- package/dist/core/storage/remote-storage.js.map +0 -7
- package/dist/core/storage/two-tier-storage.js +0 -766
- package/dist/core/storage/two-tier-storage.js.map +0 -7
- package/dist/core/trace/cli-trace-wrapper.js +0 -132
- package/dist/core/trace/cli-trace-wrapper.js.map +0 -7
- package/dist/core/trace/db-trace-wrapper.js +0 -247
- package/dist/core/trace/db-trace-wrapper.js.map +0 -7
- package/dist/core/trace/debug-trace.js +0 -417
- package/dist/core/trace/debug-trace.js.map +0 -7
- package/dist/core/trace/index.js +0 -109
- package/dist/core/trace/index.js.map +0 -7
- package/dist/core/trace/linear-api-wrapper.js +0 -178
- package/dist/core/trace/linear-api-wrapper.js.map +0 -7
- package/dist/core/trace/trace-demo.js +0 -154
- package/dist/core/trace/trace-demo.js.map +0 -7
- package/dist/core/trace/trace-detector.demo.js +0 -142
- package/dist/core/trace/trace-detector.demo.js.map +0 -7
- package/dist/core/trace/trace-detector.js +0 -528
- package/dist/core/trace/trace-detector.js.map +0 -7
- package/dist/core/trace/trace-store.js +0 -345
- package/dist/core/trace/trace-store.js.map +0 -7
- package/dist/core/trace/types.js +0 -77
- package/dist/core/trace/types.js.map +0 -7
- package/dist/core/utils/async-mutex.js +0 -114
- package/dist/core/utils/async-mutex.js.map +0 -7
- package/dist/core/utils/compression.js +0 -83
- package/dist/core/utils/compression.js.map +0 -7
- package/dist/core/utils/update-checker.js +0 -218
- package/dist/core/utils/update-checker.js.map +0 -7
- package/dist/core/worktree/worktree-manager.js +0 -465
- package/dist/core/worktree/worktree-manager.js.map +0 -7
- package/dist/daemon/daemon-config.js +0 -149
- package/dist/daemon/daemon-config.js.map +0 -7
- package/dist/daemon/services/context-service.js +0 -122
- package/dist/daemon/services/context-service.js.map +0 -7
- package/dist/daemon/services/linear-service.js +0 -136
- package/dist/daemon/services/linear-service.js.map +0 -7
- package/dist/daemon/session-daemon.js +0 -312
- package/dist/daemon/session-daemon.js.map +0 -7
- package/dist/daemon/unified-daemon.js +0 -276
- package/dist/daemon/unified-daemon.js.map +0 -7
- package/dist/features/analytics/api/analytics-api.js +0 -287
- package/dist/features/analytics/api/analytics-api.js.map +0 -7
- package/dist/features/analytics/core/analytics-service.js +0 -282
- package/dist/features/analytics/core/analytics-service.js.map +0 -7
- package/dist/features/analytics/index.js +0 -18
- package/dist/features/analytics/index.js.map +0 -7
- package/dist/features/analytics/queries/metrics-queries.js +0 -277
- package/dist/features/analytics/queries/metrics-queries.js.map +0 -7
- package/dist/features/analytics/types/metrics.js +0 -5
- package/dist/features/analytics/types/metrics.js.map +0 -7
- package/dist/features/browser/browser-mcp.js +0 -492
- package/dist/features/browser/browser-mcp.js.map +0 -7
- package/dist/features/sweep/index.js +0 -20
- package/dist/features/sweep/index.js.map +0 -7
- package/dist/features/sweep/prediction-client.js +0 -155
- package/dist/features/sweep/prediction-client.js.map +0 -7
- package/dist/features/sweep/prompt-builder.js +0 -85
- package/dist/features/sweep/prompt-builder.js.map +0 -7
- package/dist/features/sweep/pty-wrapper.js +0 -171
- package/dist/features/sweep/pty-wrapper.js.map +0 -7
- package/dist/features/sweep/state-watcher.js +0 -87
- package/dist/features/sweep/state-watcher.js.map +0 -7
- package/dist/features/sweep/status-bar.js +0 -88
- package/dist/features/sweep/status-bar.js.map +0 -7
- package/dist/features/sweep/sweep-server-manager.js +0 -226
- package/dist/features/sweep/sweep-server-manager.js.map +0 -7
- package/dist/features/sweep/tab-interceptor.js +0 -38
- package/dist/features/sweep/tab-interceptor.js.map +0 -7
- package/dist/features/sweep/types.js +0 -18
- package/dist/features/sweep/types.js.map +0 -7
- package/dist/features/tasks/linear-task-manager.js +0 -487
- package/dist/features/tasks/linear-task-manager.js.map +0 -7
- package/dist/features/tasks/task-aware-context.js +0 -410
- package/dist/features/tasks/task-aware-context.js.map +0 -7
- package/dist/features/tui/simple-monitor.js +0 -116
- package/dist/features/tui/simple-monitor.js.map +0 -7
- package/dist/features/tui/swarm-monitor.js +0 -648
- package/dist/features/tui/swarm-monitor.js.map +0 -7
- package/dist/features/web/client/stores/task-store.js +0 -26
- package/dist/features/web/client/stores/task-store.js.map +0 -7
- package/dist/features/web/server/index.js +0 -194
- package/dist/features/web/server/index.js.map +0 -7
- package/dist/hooks/auto-background.js +0 -151
- package/dist/hooks/auto-background.js.map +0 -7
- package/dist/hooks/claude-code-whatsapp-hook.js +0 -197
- package/dist/hooks/claude-code-whatsapp-hook.js.map +0 -7
- package/dist/hooks/config.js +0 -150
- package/dist/hooks/config.js.map +0 -7
- package/dist/hooks/daemon.js +0 -364
- package/dist/hooks/daemon.js.map +0 -7
- package/dist/hooks/events.js +0 -58
- package/dist/hooks/events.js.map +0 -7
- package/dist/hooks/index.js +0 -12
- package/dist/hooks/index.js.map +0 -7
- package/dist/hooks/linear-task-picker.js +0 -186
- package/dist/hooks/linear-task-picker.js.map +0 -7
- package/dist/hooks/schemas.js +0 -197
- package/dist/hooks/schemas.js.map +0 -7
- package/dist/hooks/secure-fs.js +0 -49
- package/dist/hooks/secure-fs.js.map +0 -7
- package/dist/hooks/security-logger.js +0 -155
- package/dist/hooks/security-logger.js.map +0 -7
- package/dist/hooks/session-summary.js +0 -222
- package/dist/hooks/session-summary.js.map +0 -7
- package/dist/hooks/sms-action-runner.js +0 -371
- package/dist/hooks/sms-action-runner.js.map +0 -7
- package/dist/hooks/sms-notify.js +0 -506
- package/dist/hooks/sms-notify.js.map +0 -7
- package/dist/hooks/sms-watcher.js +0 -93
- package/dist/hooks/sms-watcher.js.map +0 -7
- package/dist/hooks/sms-webhook.js +0 -555
- package/dist/hooks/sms-webhook.js.map +0 -7
- package/dist/hooks/whatsapp-commands.js +0 -479
- package/dist/hooks/whatsapp-commands.js.map +0 -7
- package/dist/hooks/whatsapp-scheduler.js +0 -317
- package/dist/hooks/whatsapp-scheduler.js.map +0 -7
- package/dist/hooks/whatsapp-sync.js +0 -409
- package/dist/hooks/whatsapp-sync.js.map +0 -7
- package/dist/index.js +0 -25
- package/dist/index.js.map +0 -7
- package/dist/integrations/anthropic/client.js +0 -263
- package/dist/integrations/anthropic/client.js.map +0 -7
- package/dist/integrations/claude-code/agent-bridge.js +0 -768
- package/dist/integrations/claude-code/agent-bridge.js.map +0 -7
- package/dist/integrations/claude-code/enhanced-pre-clear-hooks.js +0 -459
- package/dist/integrations/claude-code/enhanced-pre-clear-hooks.js.map +0 -7
- package/dist/integrations/claude-code/lifecycle-hooks.js +0 -254
- package/dist/integrations/claude-code/lifecycle-hooks.js.map +0 -7
- package/dist/integrations/claude-code/post-task-hooks.js +0 -545
- package/dist/integrations/claude-code/post-task-hooks.js.map +0 -7
- package/dist/integrations/claude-code/subagent-client-stub.js +0 -20
- package/dist/integrations/claude-code/subagent-client-stub.js.map +0 -7
- package/dist/integrations/claude-code/subagent-client.js +0 -511
- package/dist/integrations/claude-code/subagent-client.js.map +0 -7
- package/dist/integrations/claude-code/task-coordinator.js +0 -360
- package/dist/integrations/claude-code/task-coordinator.js.map +0 -7
- package/dist/integrations/linear/auth.js +0 -337
- package/dist/integrations/linear/auth.js.map +0 -7
- package/dist/integrations/linear/auto-sync.js +0 -258
- package/dist/integrations/linear/auto-sync.js.map +0 -7
- package/dist/integrations/linear/client.js +0 -634
- package/dist/integrations/linear/client.js.map +0 -7
- package/dist/integrations/linear/config.js +0 -130
- package/dist/integrations/linear/config.js.map +0 -7
- package/dist/integrations/linear/migration.js +0 -361
- package/dist/integrations/linear/migration.js.map +0 -7
- package/dist/integrations/linear/oauth-server.js +0 -454
- package/dist/integrations/linear/oauth-server.js.map +0 -7
- package/dist/integrations/linear/rest-client.js +0 -213
- package/dist/integrations/linear/rest-client.js.map +0 -7
- package/dist/integrations/linear/sync-manager.js +0 -236
- package/dist/integrations/linear/sync-manager.js.map +0 -7
- package/dist/integrations/linear/sync-service.js +0 -231
- package/dist/integrations/linear/sync-service.js.map +0 -7
- package/dist/integrations/linear/sync.js +0 -782
- package/dist/integrations/linear/sync.js.map +0 -7
- package/dist/integrations/linear/types.js +0 -5
- package/dist/integrations/linear/types.js.map +0 -7
- package/dist/integrations/linear/unified-sync.js +0 -589
- package/dist/integrations/linear/unified-sync.js.map +0 -7
- package/dist/integrations/linear/webhook-handler.js +0 -219
- package/dist/integrations/linear/webhook-handler.js.map +0 -7
- package/dist/integrations/linear/webhook-server.js +0 -218
- package/dist/integrations/linear/webhook-server.js.map +0 -7
- package/dist/integrations/linear/webhook.js +0 -291
- package/dist/integrations/linear/webhook.js.map +0 -7
- package/dist/integrations/mcp/handlers/code-execution-handlers.js +0 -266
- package/dist/integrations/mcp/handlers/code-execution-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/context-handlers.js +0 -257
- package/dist/integrations/mcp/handlers/context-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/discovery-handlers.js +0 -497
- package/dist/integrations/mcp/handlers/discovery-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/index.js +0 -166
- package/dist/integrations/mcp/handlers/index.js.map +0 -7
- package/dist/integrations/mcp/handlers/linear-handlers.js +0 -247
- package/dist/integrations/mcp/handlers/linear-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/skill-handlers.js +0 -529
- package/dist/integrations/mcp/handlers/skill-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/task-handlers.js +0 -239
- package/dist/integrations/mcp/handlers/task-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/trace-handlers.js +0 -308
- package/dist/integrations/mcp/handlers/trace-handlers.js.map +0 -7
- package/dist/integrations/mcp/index.js +0 -23
- package/dist/integrations/mcp/index.js.map +0 -7
- package/dist/integrations/mcp/middleware/tool-scoring.js +0 -356
- package/dist/integrations/mcp/middleware/tool-scoring.js.map +0 -7
- package/dist/integrations/mcp/refactored-server.js +0 -374
- package/dist/integrations/mcp/refactored-server.js.map +0 -7
- package/dist/integrations/mcp/remote-server.js +0 -682
- package/dist/integrations/mcp/remote-server.js.map +0 -7
- package/dist/integrations/mcp/schemas.js +0 -147
- package/dist/integrations/mcp/schemas.js.map +0 -7
- package/dist/integrations/mcp/server.js +0 -1975
- package/dist/integrations/mcp/server.js.map +0 -7
- package/dist/integrations/mcp/tool-definitions-code.js +0 -125
- package/dist/integrations/mcp/tool-definitions-code.js.map +0 -7
- package/dist/integrations/mcp/tool-definitions.js +0 -702
- package/dist/integrations/mcp/tool-definitions.js.map +0 -7
- package/dist/integrations/mcp/trace-test.js +0 -48
- package/dist/integrations/mcp/trace-test.js.map +0 -7
- package/dist/integrations/pg-aiguide/embedding-provider.js +0 -189
- package/dist/integrations/pg-aiguide/embedding-provider.js.map +0 -7
- package/dist/integrations/pg-aiguide/semantic-search.js +0 -187
- package/dist/integrations/pg-aiguide/semantic-search.js.map +0 -7
- package/dist/integrations/pg-aiguide/timescale-analytics.js +0 -224
- package/dist/integrations/pg-aiguide/timescale-analytics.js.map +0 -7
- package/dist/integrations/ralph/bridge/ralph-stackmemory-bridge.js +0 -860
- package/dist/integrations/ralph/bridge/ralph-stackmemory-bridge.js.map +0 -7
- package/dist/integrations/ralph/context/context-budget-manager.js +0 -301
- package/dist/integrations/ralph/context/context-budget-manager.js.map +0 -7
- package/dist/integrations/ralph/context/stackmemory-context-loader.js +0 -360
- package/dist/integrations/ralph/context/stackmemory-context-loader.js.map +0 -7
- package/dist/integrations/ralph/coordination/enhanced-coordination.js +0 -410
- package/dist/integrations/ralph/coordination/enhanced-coordination.js.map +0 -7
- package/dist/integrations/ralph/index.js +0 -18
- package/dist/integrations/ralph/index.js.map +0 -7
- package/dist/integrations/ralph/learning/pattern-learner.js +0 -401
- package/dist/integrations/ralph/learning/pattern-learner.js.map +0 -7
- package/dist/integrations/ralph/lifecycle/iteration-lifecycle.js +0 -448
- package/dist/integrations/ralph/lifecycle/iteration-lifecycle.js.map +0 -7
- package/dist/integrations/ralph/monitoring/swarm-dashboard.js +0 -294
- package/dist/integrations/ralph/monitoring/swarm-dashboard.js.map +0 -7
- package/dist/integrations/ralph/monitoring/swarm-registry.js +0 -108
- package/dist/integrations/ralph/monitoring/swarm-registry.js.map +0 -7
- package/dist/integrations/ralph/orchestration/multi-loop-orchestrator.js +0 -463
- package/dist/integrations/ralph/orchestration/multi-loop-orchestrator.js.map +0 -7
- package/dist/integrations/ralph/patterns/compounding-engineering-pattern.js +0 -400
- package/dist/integrations/ralph/patterns/compounding-engineering-pattern.js.map +0 -7
- package/dist/integrations/ralph/patterns/extended-coherence-sessions.js +0 -473
- package/dist/integrations/ralph/patterns/extended-coherence-sessions.js.map +0 -7
- package/dist/integrations/ralph/patterns/oracle-worker-pattern.js +0 -388
- package/dist/integrations/ralph/patterns/oracle-worker-pattern.js.map +0 -7
- package/dist/integrations/ralph/performance/performance-optimizer.js +0 -358
- package/dist/integrations/ralph/performance/performance-optimizer.js.map +0 -7
- package/dist/integrations/ralph/ralph-integration-demo.js +0 -182
- package/dist/integrations/ralph/ralph-integration-demo.js.map +0 -7
- package/dist/integrations/ralph/recovery/crash-recovery.js +0 -462
- package/dist/integrations/ralph/recovery/crash-recovery.js.map +0 -7
- package/dist/integrations/ralph/state/state-reconciler.js +0 -404
- package/dist/integrations/ralph/state/state-reconciler.js.map +0 -7
- package/dist/integrations/ralph/swarm/git-workflow-manager.js +0 -428
- package/dist/integrations/ralph/swarm/git-workflow-manager.js.map +0 -7
- package/dist/integrations/ralph/swarm/swarm-coordinator.js +0 -996
- package/dist/integrations/ralph/swarm/swarm-coordinator.js.map +0 -7
- package/dist/integrations/ralph/types.js +0 -5
- package/dist/integrations/ralph/types.js.map +0 -7
- package/dist/integrations/ralph/visualization/ralph-debugger.js +0 -585
- package/dist/integrations/ralph/visualization/ralph-debugger.js.map +0 -7
- package/dist/mcp/stackmemory-mcp-server.js +0 -554
- package/dist/mcp/stackmemory-mcp-server.js.map +0 -7
- package/dist/middleware/exponential-rate-limiter.js +0 -289
- package/dist/middleware/exponential-rate-limiter.js.map +0 -7
- package/dist/models/user.model.js +0 -358
- package/dist/models/user.model.js.map +0 -7
- package/dist/servers/production/auth-middleware.js +0 -528
- package/dist/servers/production/auth-middleware.js.map +0 -7
- package/dist/servers/railway/config.js +0 -55
- package/dist/servers/railway/config.js.map +0 -7
- package/dist/servers/railway/index-enhanced.js +0 -160
- package/dist/servers/railway/index-enhanced.js.map +0 -7
- package/dist/servers/railway/index.js +0 -1349
- package/dist/servers/railway/index.js.map +0 -7
- package/dist/servers/railway/simple.js +0 -64
- package/dist/servers/railway/simple.js.map +0 -7
- package/dist/servers/railway/storage-test.js +0 -459
- package/dist/servers/railway/storage-test.js.map +0 -7
- package/dist/services/config-service.js +0 -65
- package/dist/services/config-service.js.map +0 -7
- package/dist/services/context-service.js +0 -194
- package/dist/services/context-service.js.map +0 -7
- package/dist/skills/api-discovery.js +0 -354
- package/dist/skills/api-discovery.js.map +0 -7
- package/dist/skills/api-skill.js +0 -475
- package/dist/skills/api-skill.js.map +0 -7
- package/dist/skills/claude-skills.js +0 -1061
- package/dist/skills/claude-skills.js.map +0 -7
- package/dist/skills/dashboard-launcher.js +0 -216
- package/dist/skills/dashboard-launcher.js.map +0 -7
- package/dist/skills/recursive-agent-orchestrator.js +0 -575
- package/dist/skills/recursive-agent-orchestrator.js.map +0 -7
- package/dist/skills/repo-ingestion-skill.js +0 -609
- package/dist/skills/repo-ingestion-skill.js.map +0 -7
- package/dist/skills/security-secrets-scanner.js +0 -284
- package/dist/skills/security-secrets-scanner.js.map +0 -7
- package/dist/skills/unified-rlm-orchestrator.js +0 -404
- package/dist/skills/unified-rlm-orchestrator.js.map +0 -7
- package/dist/types/task.js +0 -5
- package/dist/types/task.js.map +0 -7
- package/dist/utils/env.js +0 -50
- package/dist/utils/env.js.map +0 -7
- package/dist/utils/formatting.js +0 -62
- package/dist/utils/formatting.js.map +0 -7
- package/dist/utils/process-cleanup.js +0 -136
- package/dist/utils/process-cleanup.js.map +0 -7
- package/dist/validation/schemas.js +0 -222
- package/dist/validation/schemas.js.map +0 -7
- /package/dist/{core/merge → src/core/extensions}/types.js +0 -0
- /package/dist/{core/merge → src/core/extensions}/types.js.map +0 -0
- /package/dist/{core → src/integrations/diffmem}/types.js +0 -0
- /package/dist/{core → src/integrations/diffmem}/types.js.map +0 -0
|
@@ -1,994 +0,0 @@
|
|
|
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
|