@stackmemoryai/stackmemory 0.5.59 → 0.5.61
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/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/storage/chromadb-adapter.js +32 -6
- package/dist/src/core/storage/chromadb-adapter.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 +11 -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/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 +0 -15
- 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/types.js +0 -5
- package/dist/core/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
|
@@ -1,1069 +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 { v4 as uuidv4 } from "uuid";
|
|
6
|
-
import { logger } from "../monitoring/logger.js";
|
|
7
|
-
import {
|
|
8
|
-
DatabaseError,
|
|
9
|
-
FrameError,
|
|
10
|
-
SystemError,
|
|
11
|
-
ErrorCode,
|
|
12
|
-
createErrorHandler
|
|
13
|
-
} from "../errors/index.js";
|
|
14
|
-
import { sessionManager, FrameQueryMode } from "../session/index.js";
|
|
15
|
-
import { contextBridge } from "./context-bridge.js";
|
|
16
|
-
let whatsappSync = null;
|
|
17
|
-
async function loadWhatsAppSync() {
|
|
18
|
-
if (whatsappSync !== null) return whatsappSync;
|
|
19
|
-
try {
|
|
20
|
-
const mod = await import("../../hooks/whatsapp-sync.js");
|
|
21
|
-
whatsappSync = {
|
|
22
|
-
onFrameClosed: mod.onFrameClosed,
|
|
23
|
-
createFrameDigestData: mod.createFrameDigestData
|
|
24
|
-
};
|
|
25
|
-
return whatsappSync;
|
|
26
|
-
} catch {
|
|
27
|
-
whatsappSync = null;
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const MAX_FRAME_DEPTH = 100;
|
|
32
|
-
const DEFAULT_MAX_DEPTH = 100;
|
|
33
|
-
function getEnv(key, defaultValue) {
|
|
34
|
-
const value = process.env[key];
|
|
35
|
-
if (value === void 0) {
|
|
36
|
-
if (defaultValue !== void 0) return defaultValue;
|
|
37
|
-
throw new SystemError(
|
|
38
|
-
`Environment variable ${key} is required`,
|
|
39
|
-
ErrorCode.CONFIGURATION_ERROR,
|
|
40
|
-
{ variable: key }
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
45
|
-
function getOptionalEnv(key) {
|
|
46
|
-
return process.env[key];
|
|
47
|
-
}
|
|
48
|
-
class FrameManager {
|
|
49
|
-
db;
|
|
50
|
-
currentRunId;
|
|
51
|
-
sessionId;
|
|
52
|
-
projectId;
|
|
53
|
-
activeStack = [];
|
|
54
|
-
// Stack of active frame IDs
|
|
55
|
-
queryMode = FrameQueryMode.PROJECT_ACTIVE;
|
|
56
|
-
maxFrameDepth = DEFAULT_MAX_DEPTH;
|
|
57
|
-
constructor(db, projectId, runIdOrOptions) {
|
|
58
|
-
this.db = db;
|
|
59
|
-
this.projectId = projectId;
|
|
60
|
-
let runId;
|
|
61
|
-
let skipContextBridge = false;
|
|
62
|
-
if (typeof runIdOrOptions === "string") {
|
|
63
|
-
runId = runIdOrOptions;
|
|
64
|
-
} else if (runIdOrOptions) {
|
|
65
|
-
runId = runIdOrOptions.runId;
|
|
66
|
-
skipContextBridge = runIdOrOptions.skipContextBridge || false;
|
|
67
|
-
this.maxFrameDepth = runIdOrOptions.maxFrameDepth || DEFAULT_MAX_DEPTH;
|
|
68
|
-
}
|
|
69
|
-
const session = sessionManager.getCurrentSession();
|
|
70
|
-
if (session) {
|
|
71
|
-
this.currentRunId = session.runId;
|
|
72
|
-
this.sessionId = session.sessionId;
|
|
73
|
-
} else {
|
|
74
|
-
this.currentRunId = runId || uuidv4();
|
|
75
|
-
this.sessionId = this.currentRunId;
|
|
76
|
-
}
|
|
77
|
-
this.initializeSchema();
|
|
78
|
-
this.loadActiveStack();
|
|
79
|
-
const shouldInitializeBridge = !skipContextBridge && process.env["NODE_ENV"] !== "test" && !process.env["VITEST"] && !process.env["STACKMEMORY_CLI"];
|
|
80
|
-
if (shouldInitializeBridge) {
|
|
81
|
-
contextBridge.initialize(this, {
|
|
82
|
-
autoSync: true,
|
|
83
|
-
syncInterval: 6e4,
|
|
84
|
-
// 1 minute
|
|
85
|
-
minFrameScore: 0.5,
|
|
86
|
-
// Sync frames above 0.5 score
|
|
87
|
-
importantTags: ["decision", "error", "milestone", "learning"]
|
|
88
|
-
}).catch((error) => {
|
|
89
|
-
logger.warn("Failed to initialize context bridge", { error });
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
setQueryMode(mode) {
|
|
94
|
-
this.queryMode = mode;
|
|
95
|
-
this.loadActiveStack();
|
|
96
|
-
}
|
|
97
|
-
initializeSchema() {
|
|
98
|
-
const errorHandler = createErrorHandler({
|
|
99
|
-
operation: "initializeSchema",
|
|
100
|
-
projectId: this.projectId,
|
|
101
|
-
runId: this.currentRunId
|
|
102
|
-
});
|
|
103
|
-
try {
|
|
104
|
-
if (!this.db || typeof this.db.exec !== "function") {
|
|
105
|
-
throw new DatabaseError(
|
|
106
|
-
"Database not properly initialized. Expected SQLite Database instance with exec() method.",
|
|
107
|
-
ErrorCode.DB_CONNECTION_FAILED,
|
|
108
|
-
{ operation: "initializeSchema" }
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
this.db.pragma("foreign_keys = ON");
|
|
112
|
-
this.db.exec(`
|
|
113
|
-
CREATE TABLE IF NOT EXISTS frames (
|
|
114
|
-
frame_id TEXT PRIMARY KEY,
|
|
115
|
-
run_id TEXT NOT NULL,
|
|
116
|
-
project_id TEXT NOT NULL,
|
|
117
|
-
parent_frame_id TEXT REFERENCES frames(frame_id),
|
|
118
|
-
depth INTEGER NOT NULL DEFAULT 0,
|
|
119
|
-
type TEXT NOT NULL,
|
|
120
|
-
name TEXT NOT NULL,
|
|
121
|
-
state TEXT DEFAULT 'active',
|
|
122
|
-
inputs TEXT DEFAULT '{}',
|
|
123
|
-
outputs TEXT DEFAULT '{}',
|
|
124
|
-
digest_text TEXT,
|
|
125
|
-
digest_json TEXT DEFAULT '{}',
|
|
126
|
-
created_at INTEGER DEFAULT (unixepoch()),
|
|
127
|
-
closed_at INTEGER
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
CREATE TABLE IF NOT EXISTS events (
|
|
131
|
-
event_id TEXT PRIMARY KEY,
|
|
132
|
-
run_id TEXT NOT NULL,
|
|
133
|
-
frame_id TEXT NOT NULL,
|
|
134
|
-
seq INTEGER NOT NULL,
|
|
135
|
-
event_type TEXT NOT NULL,
|
|
136
|
-
payload TEXT NOT NULL,
|
|
137
|
-
ts INTEGER DEFAULT (unixepoch()),
|
|
138
|
-
FOREIGN KEY(frame_id) REFERENCES frames(frame_id) ON DELETE CASCADE
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
CREATE TABLE IF NOT EXISTS anchors (
|
|
142
|
-
anchor_id TEXT PRIMARY KEY,
|
|
143
|
-
frame_id TEXT NOT NULL,
|
|
144
|
-
project_id TEXT NOT NULL,
|
|
145
|
-
type TEXT NOT NULL,
|
|
146
|
-
text TEXT NOT NULL,
|
|
147
|
-
priority INTEGER DEFAULT 0,
|
|
148
|
-
created_at INTEGER DEFAULT (unixepoch()),
|
|
149
|
-
metadata TEXT DEFAULT '{}',
|
|
150
|
-
FOREIGN KEY(frame_id) REFERENCES frames(frame_id) ON DELETE CASCADE
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
CREATE TABLE IF NOT EXISTS handoff_requests (
|
|
154
|
-
request_id TEXT PRIMARY KEY,
|
|
155
|
-
source_stack_id TEXT NOT NULL,
|
|
156
|
-
target_stack_id TEXT NOT NULL,
|
|
157
|
-
frame_ids TEXT NOT NULL,
|
|
158
|
-
status TEXT NOT NULL DEFAULT 'pending',
|
|
159
|
-
created_at INTEGER DEFAULT (unixepoch()),
|
|
160
|
-
expires_at INTEGER,
|
|
161
|
-
target_user_id TEXT,
|
|
162
|
-
message TEXT
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
CREATE INDEX IF NOT EXISTS idx_frames_run ON frames(run_id);
|
|
166
|
-
CREATE INDEX IF NOT EXISTS idx_frames_parent ON frames(parent_frame_id);
|
|
167
|
-
CREATE INDEX IF NOT EXISTS idx_frames_state ON frames(state);
|
|
168
|
-
CREATE INDEX IF NOT EXISTS idx_events_frame ON events(frame_id);
|
|
169
|
-
CREATE INDEX IF NOT EXISTS idx_events_seq ON events(frame_id, seq);
|
|
170
|
-
CREATE INDEX IF NOT EXISTS idx_anchors_frame ON anchors(frame_id);
|
|
171
|
-
CREATE INDEX IF NOT EXISTS idx_handoff_requests_status ON handoff_requests(status);
|
|
172
|
-
CREATE INDEX IF NOT EXISTS idx_handoff_requests_target ON handoff_requests(target_stack_id);
|
|
173
|
-
`);
|
|
174
|
-
try {
|
|
175
|
-
this.ensureCascadeConstraints();
|
|
176
|
-
} catch (e) {
|
|
177
|
-
logger.warn(
|
|
178
|
-
"Failed to ensure cascade constraints (frame-manager)",
|
|
179
|
-
e
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
} catch (error) {
|
|
183
|
-
const dbError = errorHandler(error, {
|
|
184
|
-
operation: "initializeSchema",
|
|
185
|
-
schema: "frames"
|
|
186
|
-
});
|
|
187
|
-
if (dbError instanceof DatabaseError) {
|
|
188
|
-
throw new DatabaseError(
|
|
189
|
-
"Failed to initialize frame database schema",
|
|
190
|
-
ErrorCode.DB_MIGRATION_FAILED,
|
|
191
|
-
{
|
|
192
|
-
projectId: this.projectId,
|
|
193
|
-
operation: "initializeSchema",
|
|
194
|
-
originalError: error
|
|
195
|
-
},
|
|
196
|
-
error instanceof Error ? error : void 0
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
throw dbError;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
// Ensure ON DELETE CASCADE for events/anchors referencing frames
|
|
203
|
-
ensureCascadeConstraints() {
|
|
204
|
-
const needsCascade = (table) => {
|
|
205
|
-
const rows = this.db.prepare(`PRAGMA foreign_key_list(${table})`).all();
|
|
206
|
-
return rows.some(
|
|
207
|
-
(r) => r.table === "frames" && String(r.on_delete).toUpperCase() !== "CASCADE"
|
|
208
|
-
);
|
|
209
|
-
};
|
|
210
|
-
const migrateTable = (table) => {
|
|
211
|
-
const createSql = table === "events" ? `CREATE TABLE events_new (
|
|
212
|
-
event_id TEXT PRIMARY KEY,
|
|
213
|
-
run_id TEXT NOT NULL,
|
|
214
|
-
frame_id TEXT NOT NULL,
|
|
215
|
-
seq INTEGER NOT NULL,
|
|
216
|
-
event_type TEXT NOT NULL,
|
|
217
|
-
payload TEXT NOT NULL,
|
|
218
|
-
ts INTEGER DEFAULT (unixepoch()),
|
|
219
|
-
FOREIGN KEY(frame_id) REFERENCES frames(frame_id) ON DELETE CASCADE
|
|
220
|
-
);` : `CREATE TABLE anchors_new (
|
|
221
|
-
anchor_id TEXT PRIMARY KEY,
|
|
222
|
-
frame_id TEXT NOT NULL,
|
|
223
|
-
project_id TEXT NOT NULL,
|
|
224
|
-
type TEXT NOT NULL,
|
|
225
|
-
text TEXT NOT NULL,
|
|
226
|
-
priority INTEGER DEFAULT 0,
|
|
227
|
-
created_at INTEGER DEFAULT (unixepoch()),
|
|
228
|
-
metadata TEXT DEFAULT '{}',
|
|
229
|
-
FOREIGN KEY(frame_id) REFERENCES frames(frame_id) ON DELETE CASCADE
|
|
230
|
-
);`;
|
|
231
|
-
const cols = table === "events" ? "event_id, run_id, frame_id, seq, event_type, payload, ts" : "anchor_id, frame_id, project_id, type, text, priority, created_at, metadata";
|
|
232
|
-
const idxSql = table === "events" ? [
|
|
233
|
-
"CREATE INDEX IF NOT EXISTS idx_events_frame ON events(frame_id);",
|
|
234
|
-
"CREATE INDEX IF NOT EXISTS idx_events_seq ON events(frame_id, seq);"
|
|
235
|
-
] : [
|
|
236
|
-
"CREATE INDEX IF NOT EXISTS idx_anchors_frame ON anchors(frame_id);"
|
|
237
|
-
];
|
|
238
|
-
this.db.exec("PRAGMA foreign_keys = OFF;");
|
|
239
|
-
this.db.exec("BEGIN;");
|
|
240
|
-
this.db.exec(createSql);
|
|
241
|
-
this.db.prepare(
|
|
242
|
-
`INSERT INTO ${table === "events" ? "events_new" : "anchors_new"} (${cols}) SELECT ${cols} FROM ${table}`
|
|
243
|
-
).run();
|
|
244
|
-
this.db.exec(`DROP TABLE ${table};`);
|
|
245
|
-
this.db.exec(`ALTER TABLE ${table}_new RENAME TO ${table};`);
|
|
246
|
-
for (const stmt of idxSql) this.db.exec(stmt);
|
|
247
|
-
this.db.exec("COMMIT;");
|
|
248
|
-
this.db.exec("PRAGMA foreign_keys = ON;");
|
|
249
|
-
logger.info(
|
|
250
|
-
`Migrated ${table} to include ON DELETE CASCADE (frame-manager)`
|
|
251
|
-
);
|
|
252
|
-
};
|
|
253
|
-
if (needsCascade("events")) migrateTable("events");
|
|
254
|
-
if (needsCascade("anchors")) migrateTable("anchors");
|
|
255
|
-
}
|
|
256
|
-
loadActiveStack() {
|
|
257
|
-
const errorHandler = createErrorHandler({
|
|
258
|
-
operation: "loadActiveStack",
|
|
259
|
-
runId: this.currentRunId,
|
|
260
|
-
projectId: this.projectId
|
|
261
|
-
});
|
|
262
|
-
try {
|
|
263
|
-
let query;
|
|
264
|
-
let params;
|
|
265
|
-
switch (this.queryMode) {
|
|
266
|
-
case FrameQueryMode.ALL_ACTIVE:
|
|
267
|
-
query = `
|
|
268
|
-
SELECT frame_id, parent_frame_id, depth
|
|
269
|
-
FROM frames
|
|
270
|
-
WHERE state = 'active'
|
|
271
|
-
ORDER BY created_at DESC, depth ASC
|
|
272
|
-
`;
|
|
273
|
-
params = [];
|
|
274
|
-
break;
|
|
275
|
-
case FrameQueryMode.PROJECT_ACTIVE:
|
|
276
|
-
query = `
|
|
277
|
-
SELECT frame_id, parent_frame_id, depth, run_id
|
|
278
|
-
FROM frames
|
|
279
|
-
WHERE state = 'active' AND project_id = ?
|
|
280
|
-
ORDER BY created_at DESC, depth ASC
|
|
281
|
-
`;
|
|
282
|
-
params = [this.projectId];
|
|
283
|
-
break;
|
|
284
|
-
case FrameQueryMode.HISTORICAL:
|
|
285
|
-
query = `
|
|
286
|
-
SELECT frame_id, parent_frame_id, depth
|
|
287
|
-
FROM frames
|
|
288
|
-
WHERE project_id = ?
|
|
289
|
-
ORDER BY created_at DESC, depth ASC
|
|
290
|
-
`;
|
|
291
|
-
params = [this.projectId];
|
|
292
|
-
break;
|
|
293
|
-
case FrameQueryMode.CURRENT_SESSION:
|
|
294
|
-
default:
|
|
295
|
-
query = `
|
|
296
|
-
SELECT frame_id, parent_frame_id, depth
|
|
297
|
-
FROM frames
|
|
298
|
-
WHERE run_id = ? AND state = 'active'
|
|
299
|
-
ORDER BY depth ASC
|
|
300
|
-
`;
|
|
301
|
-
params = [this.currentRunId];
|
|
302
|
-
break;
|
|
303
|
-
}
|
|
304
|
-
const activeFrames = this.db.prepare(query).all(...params);
|
|
305
|
-
this.activeStack = this.buildStackOrder(activeFrames);
|
|
306
|
-
logger.info("Loaded active stack", {
|
|
307
|
-
runId: this.currentRunId,
|
|
308
|
-
stackDepth: this.activeStack.length,
|
|
309
|
-
activeFrames: this.activeStack,
|
|
310
|
-
queryMode: this.queryMode
|
|
311
|
-
});
|
|
312
|
-
} catch (error) {
|
|
313
|
-
const dbError = errorHandler(error, {
|
|
314
|
-
query: "Frame loading query",
|
|
315
|
-
runId: this.currentRunId,
|
|
316
|
-
queryMode: this.queryMode
|
|
317
|
-
});
|
|
318
|
-
if (dbError instanceof DatabaseError) {
|
|
319
|
-
throw new DatabaseError(
|
|
320
|
-
"Failed to load active frame stack",
|
|
321
|
-
ErrorCode.DB_QUERY_FAILED,
|
|
322
|
-
{
|
|
323
|
-
runId: this.currentRunId,
|
|
324
|
-
projectId: this.projectId,
|
|
325
|
-
operation: "loadActiveStack"
|
|
326
|
-
},
|
|
327
|
-
error instanceof Error ? error : void 0
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
throw dbError;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
buildStackOrder(frames) {
|
|
334
|
-
const stack = [];
|
|
335
|
-
const rootFrame = frames.find((f) => !f.parent_frame_id);
|
|
336
|
-
if (!rootFrame) return [];
|
|
337
|
-
let currentFrame = rootFrame;
|
|
338
|
-
stack.push(currentFrame.frame_id);
|
|
339
|
-
while (currentFrame) {
|
|
340
|
-
const childFrame = frames.find(
|
|
341
|
-
(f) => f.parent_frame_id === currentFrame.frame_id
|
|
342
|
-
);
|
|
343
|
-
if (!childFrame) break;
|
|
344
|
-
stack.push(childFrame.frame_id);
|
|
345
|
-
currentFrame = childFrame;
|
|
346
|
-
}
|
|
347
|
-
return stack;
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Create a new frame and push to stack
|
|
351
|
-
*/
|
|
352
|
-
createFrame(options) {
|
|
353
|
-
return this._createFrame(options);
|
|
354
|
-
}
|
|
355
|
-
_createFrame(options) {
|
|
356
|
-
const frameId = uuidv4();
|
|
357
|
-
const parentFrameId = options.parentFrameId || this.getCurrentFrameId();
|
|
358
|
-
const depth = parentFrameId ? this.getFrameDepth(parentFrameId) + 1 : 0;
|
|
359
|
-
if (depth > this.maxFrameDepth) {
|
|
360
|
-
throw new FrameError(
|
|
361
|
-
`Maximum frame depth exceeded: ${depth} > ${this.maxFrameDepth}`,
|
|
362
|
-
ErrorCode.FRAME_STACK_OVERFLOW,
|
|
363
|
-
{
|
|
364
|
-
currentDepth: depth,
|
|
365
|
-
maxDepth: this.maxFrameDepth,
|
|
366
|
-
frameId,
|
|
367
|
-
parentFrameId,
|
|
368
|
-
frameName: options.name
|
|
369
|
-
}
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
if (parentFrameId) {
|
|
373
|
-
const cycle = this.detectCycle(frameId, parentFrameId);
|
|
374
|
-
if (cycle) {
|
|
375
|
-
throw new FrameError(
|
|
376
|
-
`Circular reference detected in frame hierarchy`,
|
|
377
|
-
ErrorCode.FRAME_CYCLE_DETECTED,
|
|
378
|
-
{
|
|
379
|
-
frameId,
|
|
380
|
-
parentFrameId,
|
|
381
|
-
cycle,
|
|
382
|
-
frameName: options.name
|
|
383
|
-
}
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
const frame = {
|
|
388
|
-
frame_id: frameId,
|
|
389
|
-
run_id: this.currentRunId,
|
|
390
|
-
project_id: this.projectId,
|
|
391
|
-
parent_frame_id: parentFrameId,
|
|
392
|
-
depth,
|
|
393
|
-
type: options.type,
|
|
394
|
-
name: options.name,
|
|
395
|
-
state: "active",
|
|
396
|
-
inputs: options.inputs || {},
|
|
397
|
-
created_at: Math.floor(Date.now() / 1e3)
|
|
398
|
-
};
|
|
399
|
-
try {
|
|
400
|
-
this.db.prepare(
|
|
401
|
-
`
|
|
402
|
-
INSERT INTO frames (
|
|
403
|
-
frame_id, run_id, project_id, parent_frame_id, depth, type, name, state, inputs, created_at
|
|
404
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
405
|
-
`
|
|
406
|
-
).run(
|
|
407
|
-
frame.frame_id,
|
|
408
|
-
frame.run_id,
|
|
409
|
-
frame.project_id,
|
|
410
|
-
frame.parent_frame_id,
|
|
411
|
-
frame.depth,
|
|
412
|
-
frame.type,
|
|
413
|
-
frame.name,
|
|
414
|
-
frame.state,
|
|
415
|
-
JSON.stringify(frame.inputs),
|
|
416
|
-
frame.created_at
|
|
417
|
-
);
|
|
418
|
-
} catch (error) {
|
|
419
|
-
throw new DatabaseError(
|
|
420
|
-
`Failed to create frame: ${options.name}`,
|
|
421
|
-
ErrorCode.DB_QUERY_FAILED,
|
|
422
|
-
{
|
|
423
|
-
frameId,
|
|
424
|
-
frameType: options.type,
|
|
425
|
-
frameName: options.name,
|
|
426
|
-
parentFrameId,
|
|
427
|
-
depth,
|
|
428
|
-
operation: "createFrame"
|
|
429
|
-
},
|
|
430
|
-
error instanceof Error ? error : void 0
|
|
431
|
-
);
|
|
432
|
-
}
|
|
433
|
-
this.activeStack.push(frameId);
|
|
434
|
-
logger.info("Created frame", {
|
|
435
|
-
frameId,
|
|
436
|
-
type: options.type,
|
|
437
|
-
name: options.name,
|
|
438
|
-
depth,
|
|
439
|
-
parentFrameId,
|
|
440
|
-
stackDepth: this.activeStack.length
|
|
441
|
-
});
|
|
442
|
-
return frameId;
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Close the current frame and generate digest
|
|
446
|
-
*/
|
|
447
|
-
closeFrame(frameId, outputs) {
|
|
448
|
-
this._closeFrame(frameId, outputs);
|
|
449
|
-
}
|
|
450
|
-
_closeFrame(frameId, outputs) {
|
|
451
|
-
const targetFrameId = frameId || this.getCurrentFrameId();
|
|
452
|
-
if (!targetFrameId) {
|
|
453
|
-
throw new FrameError(
|
|
454
|
-
"No active frame to close",
|
|
455
|
-
ErrorCode.FRAME_INVALID_STATE,
|
|
456
|
-
{
|
|
457
|
-
operation: "closeFrame",
|
|
458
|
-
activeStack: this.activeStack,
|
|
459
|
-
stackDepth: this.activeStack.length
|
|
460
|
-
}
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
-
const frame = this.getFrame(targetFrameId);
|
|
464
|
-
if (!frame) {
|
|
465
|
-
throw new FrameError(
|
|
466
|
-
`Frame not found: ${targetFrameId}`,
|
|
467
|
-
ErrorCode.FRAME_NOT_FOUND,
|
|
468
|
-
{
|
|
469
|
-
frameId: targetFrameId,
|
|
470
|
-
operation: "closeFrame",
|
|
471
|
-
runId: this.currentRunId
|
|
472
|
-
}
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
if (frame.state === "closed") {
|
|
476
|
-
logger.warn("Attempted to close already closed frame", {
|
|
477
|
-
frameId: targetFrameId
|
|
478
|
-
});
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
const digest = this.generateDigest(targetFrameId);
|
|
482
|
-
const finalOutputs = { ...outputs, ...digest.structured };
|
|
483
|
-
try {
|
|
484
|
-
this.db.prepare(
|
|
485
|
-
`
|
|
486
|
-
UPDATE frames
|
|
487
|
-
SET state = 'closed',
|
|
488
|
-
outputs = ?,
|
|
489
|
-
digest_text = ?,
|
|
490
|
-
digest_json = ?,
|
|
491
|
-
closed_at = unixepoch()
|
|
492
|
-
WHERE frame_id = ?
|
|
493
|
-
`
|
|
494
|
-
).run(
|
|
495
|
-
JSON.stringify(finalOutputs),
|
|
496
|
-
digest.text,
|
|
497
|
-
JSON.stringify(digest.structured),
|
|
498
|
-
targetFrameId
|
|
499
|
-
);
|
|
500
|
-
} catch (error) {
|
|
501
|
-
throw new DatabaseError(
|
|
502
|
-
`Failed to close frame: ${targetFrameId}`,
|
|
503
|
-
ErrorCode.DB_QUERY_FAILED,
|
|
504
|
-
{
|
|
505
|
-
frameId: targetFrameId,
|
|
506
|
-
frameName: frame.name,
|
|
507
|
-
operation: "closeFrame"
|
|
508
|
-
},
|
|
509
|
-
error instanceof Error ? error : void 0
|
|
510
|
-
);
|
|
511
|
-
}
|
|
512
|
-
this.activeStack = this.activeStack.filter((id) => id !== targetFrameId);
|
|
513
|
-
this.closeChildFrames(targetFrameId);
|
|
514
|
-
this.triggerWhatsAppSync(frame, targetFrameId).catch(() => {
|
|
515
|
-
});
|
|
516
|
-
logger.info("Closed frame", {
|
|
517
|
-
frameId: targetFrameId,
|
|
518
|
-
name: frame.name,
|
|
519
|
-
duration: Math.floor(Date.now() / 1e3) - frame.created_at,
|
|
520
|
-
digestLength: digest.text.length,
|
|
521
|
-
stackDepth: this.activeStack.length
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
/**
|
|
525
|
-
* Trigger WhatsApp sync for closed frame (non-blocking)
|
|
526
|
-
*/
|
|
527
|
-
async triggerWhatsAppSync(frame, frameId) {
|
|
528
|
-
const sync = await loadWhatsAppSync();
|
|
529
|
-
if (!sync) return;
|
|
530
|
-
try {
|
|
531
|
-
const events = this.getFrameEvents(frameId);
|
|
532
|
-
const anchors = this.getFrameAnchors(frameId);
|
|
533
|
-
const digestData = sync.createFrameDigestData(frame, events, anchors);
|
|
534
|
-
await sync.onFrameClosed(digestData);
|
|
535
|
-
} catch {
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* Delete a frame completely from the database (used in handoffs)
|
|
540
|
-
*/
|
|
541
|
-
deleteFrame(frameId) {
|
|
542
|
-
try {
|
|
543
|
-
this.db.prepare("DELETE FROM events WHERE frame_id = ?").run(frameId);
|
|
544
|
-
this.db.prepare("DELETE FROM anchors WHERE frame_id = ?").run(frameId);
|
|
545
|
-
this.activeStack = this.activeStack.filter((id) => id !== frameId);
|
|
546
|
-
this.db.prepare("DELETE FROM frames WHERE frame_id = ?").run(frameId);
|
|
547
|
-
logger.debug("Deleted frame completely", { frameId });
|
|
548
|
-
} catch (error) {
|
|
549
|
-
logger.error("Failed to delete frame", { frameId, error });
|
|
550
|
-
throw error;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
closeChildFrames(parentFrameId) {
|
|
554
|
-
try {
|
|
555
|
-
const children = this.db.prepare(
|
|
556
|
-
`
|
|
557
|
-
SELECT frame_id FROM frames
|
|
558
|
-
WHERE parent_frame_id = ? AND state = 'active'
|
|
559
|
-
`
|
|
560
|
-
).all(parentFrameId);
|
|
561
|
-
children.forEach((child) => {
|
|
562
|
-
try {
|
|
563
|
-
this.closeFrame(child.frame_id);
|
|
564
|
-
} catch (error) {
|
|
565
|
-
logger.error(
|
|
566
|
-
"Failed to close child frame",
|
|
567
|
-
error instanceof Error ? error : new Error(String(error)),
|
|
568
|
-
{
|
|
569
|
-
parentFrameId,
|
|
570
|
-
childFrameId: child.frame_id
|
|
571
|
-
}
|
|
572
|
-
);
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
} catch (error) {
|
|
576
|
-
throw new DatabaseError(
|
|
577
|
-
`Failed to close child frames for parent: ${parentFrameId}`,
|
|
578
|
-
ErrorCode.DB_QUERY_FAILED,
|
|
579
|
-
{
|
|
580
|
-
parentFrameId,
|
|
581
|
-
operation: "closeChildFrames"
|
|
582
|
-
},
|
|
583
|
-
error instanceof Error ? error : void 0
|
|
584
|
-
);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
|
-
* Generate digest for a frame
|
|
589
|
-
*/
|
|
590
|
-
generateDigest(frameId) {
|
|
591
|
-
const frame = this.getFrame(frameId);
|
|
592
|
-
const events = this.getFrameEvents(frameId);
|
|
593
|
-
const anchors = this.getFrameAnchors(frameId);
|
|
594
|
-
if (!frame) {
|
|
595
|
-
throw new FrameError(
|
|
596
|
-
`Cannot generate digest: frame not found ${frameId}`,
|
|
597
|
-
ErrorCode.FRAME_NOT_FOUND,
|
|
598
|
-
{
|
|
599
|
-
frameId,
|
|
600
|
-
operation: "generateDigest",
|
|
601
|
-
runId: this.currentRunId
|
|
602
|
-
}
|
|
603
|
-
);
|
|
604
|
-
}
|
|
605
|
-
const decisions = anchors.filter((a) => a.type === "DECISION");
|
|
606
|
-
const constraints = anchors.filter((a) => a.type === "CONSTRAINT");
|
|
607
|
-
const risks = anchors.filter((a) => a.type === "RISK");
|
|
608
|
-
const toolCalls = events.filter((e) => e.event_type === "tool_call");
|
|
609
|
-
const artifacts = events.filter((e) => e.event_type === "artifact");
|
|
610
|
-
const structured = {
|
|
611
|
-
result: frame.name,
|
|
612
|
-
decisions: decisions.map((d) => ({ id: d.anchor_id, text: d.text })),
|
|
613
|
-
constraints: constraints.map((c) => ({ id: c.anchor_id, text: c.text })),
|
|
614
|
-
risks: risks.map((r) => ({ id: r.anchor_id, text: r.text })),
|
|
615
|
-
artifacts: artifacts.map((a) => ({
|
|
616
|
-
kind: a.payload.kind || "unknown",
|
|
617
|
-
ref: a.payload.ref
|
|
618
|
-
})),
|
|
619
|
-
tool_calls_count: toolCalls.length,
|
|
620
|
-
duration_seconds: frame.closed_at ? frame.closed_at - frame.created_at : 0
|
|
621
|
-
};
|
|
622
|
-
const text = this.generateDigestText(frame, structured, events.length);
|
|
623
|
-
return { text, structured };
|
|
624
|
-
}
|
|
625
|
-
generateDigestText(frame, structured, eventCount) {
|
|
626
|
-
let summary = `Completed: ${frame.name}
|
|
627
|
-
`;
|
|
628
|
-
if (structured.decisions.length > 0) {
|
|
629
|
-
summary += `
|
|
630
|
-
Decisions made:
|
|
631
|
-
${structured.decisions.map((d) => `- ${d.text}`).join("\n")}`;
|
|
632
|
-
}
|
|
633
|
-
if (structured.constraints.length > 0) {
|
|
634
|
-
summary += `
|
|
635
|
-
Constraints established:
|
|
636
|
-
${structured.constraints.map((c) => `- ${c.text}`).join("\n")}`;
|
|
637
|
-
}
|
|
638
|
-
if (structured.risks.length > 0) {
|
|
639
|
-
summary += `
|
|
640
|
-
Risks identified:
|
|
641
|
-
${structured.risks.map((r) => `- ${r.text}`).join("\n")}`;
|
|
642
|
-
}
|
|
643
|
-
summary += `
|
|
644
|
-
Activity: ${eventCount} events, ${structured.tool_calls_count} tool calls`;
|
|
645
|
-
if (structured.duration_seconds > 0) {
|
|
646
|
-
summary += `, ${Math.floor(structured.duration_seconds / 60)}m ${structured.duration_seconds % 60}s duration`;
|
|
647
|
-
}
|
|
648
|
-
return summary;
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* Add event to current frame
|
|
652
|
-
*/
|
|
653
|
-
addEvent(eventType, payload, frameId) {
|
|
654
|
-
const targetFrameId = frameId || this.getCurrentFrameId();
|
|
655
|
-
if (!targetFrameId) {
|
|
656
|
-
throw new FrameError(
|
|
657
|
-
"No active frame for event",
|
|
658
|
-
ErrorCode.FRAME_INVALID_STATE,
|
|
659
|
-
{
|
|
660
|
-
operation: "addEvent",
|
|
661
|
-
eventType,
|
|
662
|
-
activeStack: this.activeStack
|
|
663
|
-
}
|
|
664
|
-
);
|
|
665
|
-
}
|
|
666
|
-
const eventId = uuidv4();
|
|
667
|
-
const seq = this.getNextEventSequence(targetFrameId);
|
|
668
|
-
try {
|
|
669
|
-
this.db.prepare(
|
|
670
|
-
`
|
|
671
|
-
INSERT INTO events (event_id, run_id, frame_id, seq, event_type, payload)
|
|
672
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
673
|
-
`
|
|
674
|
-
).run(
|
|
675
|
-
eventId,
|
|
676
|
-
this.currentRunId,
|
|
677
|
-
targetFrameId,
|
|
678
|
-
seq,
|
|
679
|
-
eventType,
|
|
680
|
-
JSON.stringify(payload)
|
|
681
|
-
);
|
|
682
|
-
} catch (error) {
|
|
683
|
-
throw new DatabaseError(
|
|
684
|
-
`Failed to add event to frame: ${targetFrameId}`,
|
|
685
|
-
ErrorCode.DB_QUERY_FAILED,
|
|
686
|
-
{
|
|
687
|
-
eventId,
|
|
688
|
-
frameId: targetFrameId,
|
|
689
|
-
eventType,
|
|
690
|
-
seq,
|
|
691
|
-
operation: "addEvent"
|
|
692
|
-
},
|
|
693
|
-
error instanceof Error ? error : void 0
|
|
694
|
-
);
|
|
695
|
-
}
|
|
696
|
-
return eventId;
|
|
697
|
-
}
|
|
698
|
-
/**
|
|
699
|
-
* Add anchor to frame
|
|
700
|
-
*/
|
|
701
|
-
addAnchor(type, text, priority = 0, metadata = {}, frameId) {
|
|
702
|
-
const targetFrameId = frameId || this.getCurrentFrameId();
|
|
703
|
-
if (!targetFrameId) {
|
|
704
|
-
throw new FrameError(
|
|
705
|
-
"No active frame for anchor",
|
|
706
|
-
ErrorCode.FRAME_INVALID_STATE,
|
|
707
|
-
{
|
|
708
|
-
operation: "addAnchor",
|
|
709
|
-
anchorType: type,
|
|
710
|
-
text: text.substring(0, 100),
|
|
711
|
-
activeStack: this.activeStack
|
|
712
|
-
}
|
|
713
|
-
);
|
|
714
|
-
}
|
|
715
|
-
const anchorId = uuidv4();
|
|
716
|
-
try {
|
|
717
|
-
this.db.prepare(
|
|
718
|
-
`
|
|
719
|
-
INSERT INTO anchors (anchor_id, frame_id, project_id, type, text, priority, metadata)
|
|
720
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
721
|
-
`
|
|
722
|
-
).run(
|
|
723
|
-
anchorId,
|
|
724
|
-
targetFrameId,
|
|
725
|
-
this.projectId,
|
|
726
|
-
type,
|
|
727
|
-
text,
|
|
728
|
-
priority,
|
|
729
|
-
JSON.stringify(metadata)
|
|
730
|
-
);
|
|
731
|
-
} catch (error) {
|
|
732
|
-
throw new DatabaseError(
|
|
733
|
-
`Failed to add anchor to frame: ${targetFrameId}`,
|
|
734
|
-
ErrorCode.DB_QUERY_FAILED,
|
|
735
|
-
{
|
|
736
|
-
anchorId,
|
|
737
|
-
frameId: targetFrameId,
|
|
738
|
-
anchorType: type,
|
|
739
|
-
operation: "addAnchor"
|
|
740
|
-
},
|
|
741
|
-
error instanceof Error ? error : void 0
|
|
742
|
-
);
|
|
743
|
-
}
|
|
744
|
-
return anchorId;
|
|
745
|
-
}
|
|
746
|
-
/**
|
|
747
|
-
* Get hot stack context for current active frames
|
|
748
|
-
*/
|
|
749
|
-
getHotStackContext(maxEvents = 20) {
|
|
750
|
-
return this.activeStack.map((frameId) => {
|
|
751
|
-
const frame = this.getFrame(frameId);
|
|
752
|
-
if (!frame) return null;
|
|
753
|
-
return {
|
|
754
|
-
frameId,
|
|
755
|
-
header: {
|
|
756
|
-
goal: frame.name,
|
|
757
|
-
constraints: this.extractConstraints(frame.inputs),
|
|
758
|
-
definitions: frame.inputs.definitions
|
|
759
|
-
},
|
|
760
|
-
anchors: this.getFrameAnchors(frameId),
|
|
761
|
-
recentEvents: this.getFrameEvents(frameId, maxEvents),
|
|
762
|
-
activeArtifacts: this.getActiveArtifacts(frameId)
|
|
763
|
-
};
|
|
764
|
-
}).filter(Boolean);
|
|
765
|
-
}
|
|
766
|
-
/**
|
|
767
|
-
* Get active frame path (root to current)
|
|
768
|
-
*/
|
|
769
|
-
getActiveFramePath() {
|
|
770
|
-
return this.activeStack.map((frameId) => this.getFrame(frameId)).filter(Boolean);
|
|
771
|
-
}
|
|
772
|
-
// Utility methods
|
|
773
|
-
getCurrentFrameId() {
|
|
774
|
-
return this.activeStack[this.activeStack.length - 1];
|
|
775
|
-
}
|
|
776
|
-
getStackDepth() {
|
|
777
|
-
return this.activeStack.length;
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Get recent frames for context sharing
|
|
781
|
-
*/
|
|
782
|
-
async getRecentFrames(limit = 100) {
|
|
783
|
-
try {
|
|
784
|
-
const rows = this.db.prepare(
|
|
785
|
-
`
|
|
786
|
-
SELECT * FROM frames
|
|
787
|
-
WHERE project_id = ?
|
|
788
|
-
ORDER BY created_at DESC
|
|
789
|
-
LIMIT ?
|
|
790
|
-
`
|
|
791
|
-
).all(this.projectId, limit);
|
|
792
|
-
return rows.map((row) => ({
|
|
793
|
-
...row,
|
|
794
|
-
frameId: row.frame_id,
|
|
795
|
-
runId: row.run_id,
|
|
796
|
-
projectId: row.project_id,
|
|
797
|
-
parentFrameId: row.parent_frame_id,
|
|
798
|
-
title: row.name,
|
|
799
|
-
timestamp: row.created_at,
|
|
800
|
-
metadata: {
|
|
801
|
-
tags: this.extractTagsFromFrame(row),
|
|
802
|
-
importance: this.calculateFrameImportance(row)
|
|
803
|
-
},
|
|
804
|
-
data: {
|
|
805
|
-
inputs: JSON.parse(row.inputs || "{}"),
|
|
806
|
-
outputs: JSON.parse(row.outputs || "{}"),
|
|
807
|
-
digest: JSON.parse(row.digest_json || "{}")
|
|
808
|
-
},
|
|
809
|
-
inputs: JSON.parse(row.inputs || "{}"),
|
|
810
|
-
outputs: JSON.parse(row.outputs || "{}"),
|
|
811
|
-
digest_json: JSON.parse(row.digest_json || "{}")
|
|
812
|
-
}));
|
|
813
|
-
} catch (error) {
|
|
814
|
-
logger.error("Failed to get recent frames", error);
|
|
815
|
-
return [];
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
/**
|
|
819
|
-
* Add context metadata to the current frame
|
|
820
|
-
*/
|
|
821
|
-
async addContext(key, value) {
|
|
822
|
-
const currentFrameId = this.getCurrentFrameId();
|
|
823
|
-
if (!currentFrameId) return;
|
|
824
|
-
try {
|
|
825
|
-
const frame = this.getFrame(currentFrameId);
|
|
826
|
-
if (!frame) return;
|
|
827
|
-
const metadata = frame.outputs || {};
|
|
828
|
-
metadata[key] = value;
|
|
829
|
-
this.db.prepare(`UPDATE frames SET outputs = ? WHERE frame_id = ?`).run(JSON.stringify(metadata), currentFrameId);
|
|
830
|
-
} catch (error) {
|
|
831
|
-
logger.warn("Failed to add context to frame", { error, key });
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
extractTagsFromFrame(frame) {
|
|
835
|
-
const tags = [];
|
|
836
|
-
if (frame.type) tags.push(frame.type);
|
|
837
|
-
if (frame.name) {
|
|
838
|
-
if (frame.name.toLowerCase().includes("error")) tags.push("error");
|
|
839
|
-
if (frame.name.toLowerCase().includes("fix")) tags.push("resolution");
|
|
840
|
-
if (frame.name.toLowerCase().includes("decision")) tags.push("decision");
|
|
841
|
-
if (frame.name.toLowerCase().includes("milestone"))
|
|
842
|
-
tags.push("milestone");
|
|
843
|
-
}
|
|
844
|
-
try {
|
|
845
|
-
const digest = JSON.parse(frame.digest_json || "{}");
|
|
846
|
-
if (digest.tags) tags.push(...digest.tags);
|
|
847
|
-
} catch {
|
|
848
|
-
}
|
|
849
|
-
return [...new Set(tags)];
|
|
850
|
-
}
|
|
851
|
-
calculateFrameImportance(frame) {
|
|
852
|
-
if (frame.type === "milestone" || frame.name?.includes("decision"))
|
|
853
|
-
return "high";
|
|
854
|
-
if (frame.type === "error" || frame.type === "resolution") return "medium";
|
|
855
|
-
if (frame.closed_at && frame.created_at) {
|
|
856
|
-
const duration = frame.closed_at - frame.created_at;
|
|
857
|
-
if (duration > 300) return "medium";
|
|
858
|
-
}
|
|
859
|
-
return "low";
|
|
860
|
-
}
|
|
861
|
-
getFrameDepth(frameId) {
|
|
862
|
-
const frame = this.getFrame(frameId);
|
|
863
|
-
return frame?.depth || 0;
|
|
864
|
-
}
|
|
865
|
-
getFrame(frameId) {
|
|
866
|
-
try {
|
|
867
|
-
const row = this.db.prepare(
|
|
868
|
-
`
|
|
869
|
-
SELECT * FROM frames WHERE frame_id = ?
|
|
870
|
-
`
|
|
871
|
-
).get(frameId);
|
|
872
|
-
if (!row) return void 0;
|
|
873
|
-
return {
|
|
874
|
-
...row,
|
|
875
|
-
inputs: JSON.parse(row.inputs || "{}"),
|
|
876
|
-
outputs: JSON.parse(row.outputs || "{}"),
|
|
877
|
-
digest_json: JSON.parse(row.digest_json || "{}")
|
|
878
|
-
};
|
|
879
|
-
} catch (error) {
|
|
880
|
-
logger.warn(`Failed to get frame: ${frameId}`, {
|
|
881
|
-
error: error instanceof Error ? error.message : String(error),
|
|
882
|
-
frameId,
|
|
883
|
-
operation: "getFrame"
|
|
884
|
-
});
|
|
885
|
-
return void 0;
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
getFrameEvents(frameId, limit) {
|
|
889
|
-
try {
|
|
890
|
-
const query = limit ? `SELECT * FROM events WHERE frame_id = ? ORDER BY seq DESC LIMIT ?` : `SELECT * FROM events WHERE frame_id = ? ORDER BY seq ASC`;
|
|
891
|
-
const params = limit ? [frameId, limit] : [frameId];
|
|
892
|
-
const rows = this.db.prepare(query).all(...params);
|
|
893
|
-
return rows.map((row) => ({
|
|
894
|
-
...row,
|
|
895
|
-
payload: JSON.parse(row.payload)
|
|
896
|
-
}));
|
|
897
|
-
} catch (error) {
|
|
898
|
-
throw new DatabaseError(
|
|
899
|
-
`Failed to get frame events: ${frameId}`,
|
|
900
|
-
ErrorCode.DB_QUERY_FAILED,
|
|
901
|
-
{
|
|
902
|
-
frameId,
|
|
903
|
-
limit,
|
|
904
|
-
operation: "getFrameEvents"
|
|
905
|
-
},
|
|
906
|
-
error instanceof Error ? error : void 0
|
|
907
|
-
);
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
getFrameAnchors(frameId) {
|
|
911
|
-
try {
|
|
912
|
-
const rows = this.db.prepare(
|
|
913
|
-
`
|
|
914
|
-
SELECT * FROM anchors WHERE frame_id = ? ORDER BY priority DESC, created_at ASC
|
|
915
|
-
`
|
|
916
|
-
).all(frameId);
|
|
917
|
-
return rows.map((row) => ({
|
|
918
|
-
...row,
|
|
919
|
-
metadata: JSON.parse(row.metadata || "{}")
|
|
920
|
-
}));
|
|
921
|
-
} catch (error) {
|
|
922
|
-
throw new DatabaseError(
|
|
923
|
-
`Failed to get frame anchors: ${frameId}`,
|
|
924
|
-
ErrorCode.DB_QUERY_FAILED,
|
|
925
|
-
{
|
|
926
|
-
frameId,
|
|
927
|
-
operation: "getFrameAnchors"
|
|
928
|
-
},
|
|
929
|
-
error instanceof Error ? error : void 0
|
|
930
|
-
);
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
getNextEventSequence(frameId) {
|
|
934
|
-
try {
|
|
935
|
-
const result = this.db.prepare(
|
|
936
|
-
`
|
|
937
|
-
SELECT MAX(seq) as max_seq FROM events WHERE frame_id = ?
|
|
938
|
-
`
|
|
939
|
-
).get(frameId);
|
|
940
|
-
return (result.max_seq || 0) + 1;
|
|
941
|
-
} catch (error) {
|
|
942
|
-
throw new DatabaseError(
|
|
943
|
-
`Failed to get next event sequence for frame: ${frameId}`,
|
|
944
|
-
ErrorCode.DB_QUERY_FAILED,
|
|
945
|
-
{
|
|
946
|
-
frameId,
|
|
947
|
-
operation: "getNextEventSequence"
|
|
948
|
-
},
|
|
949
|
-
error instanceof Error ? error : void 0
|
|
950
|
-
);
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
extractConstraints(inputs) {
|
|
954
|
-
return inputs.constraints;
|
|
955
|
-
}
|
|
956
|
-
getActiveArtifacts(frameId) {
|
|
957
|
-
const artifacts = this.getFrameEvents(frameId).filter((e) => e.event_type === "artifact").map((e) => e.payload.ref).filter(Boolean);
|
|
958
|
-
return artifacts;
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* Detect if setting a parent frame would create a cycle in the frame hierarchy.
|
|
962
|
-
* Returns the cycle path if detected, or null if no cycle.
|
|
963
|
-
* @param childFrameId - The frame that would be the child
|
|
964
|
-
* @param parentFrameId - The proposed parent frame
|
|
965
|
-
* @returns Array of frame IDs forming the cycle, or null if no cycle
|
|
966
|
-
*/
|
|
967
|
-
detectCycle(childFrameId, parentFrameId) {
|
|
968
|
-
const visited = /* @__PURE__ */ new Set();
|
|
969
|
-
const path = [];
|
|
970
|
-
let currentId = parentFrameId;
|
|
971
|
-
while (currentId) {
|
|
972
|
-
if (visited.has(currentId)) {
|
|
973
|
-
const cycleStart = path.indexOf(currentId);
|
|
974
|
-
return path.slice(cycleStart).concat(currentId);
|
|
975
|
-
}
|
|
976
|
-
if (currentId === childFrameId) {
|
|
977
|
-
return path.concat([currentId, childFrameId]);
|
|
978
|
-
}
|
|
979
|
-
visited.add(currentId);
|
|
980
|
-
path.push(currentId);
|
|
981
|
-
const frame = this.getFrame(currentId);
|
|
982
|
-
if (!frame) {
|
|
983
|
-
break;
|
|
984
|
-
}
|
|
985
|
-
currentId = frame.parent_frame_id;
|
|
986
|
-
if (path.length > this.maxFrameDepth) {
|
|
987
|
-
throw new FrameError(
|
|
988
|
-
`Frame hierarchy traversal exceeded maximum depth during cycle detection`,
|
|
989
|
-
ErrorCode.FRAME_STACK_OVERFLOW,
|
|
990
|
-
{
|
|
991
|
-
depth: path.length,
|
|
992
|
-
maxDepth: this.maxFrameDepth,
|
|
993
|
-
path
|
|
994
|
-
}
|
|
995
|
-
);
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
return null;
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* Update parent frame of an existing frame (with cycle detection)
|
|
1002
|
-
* @param frameId - The frame to update
|
|
1003
|
-
* @param newParentFrameId - The new parent frame ID
|
|
1004
|
-
*/
|
|
1005
|
-
updateParentFrame(frameId, newParentFrameId) {
|
|
1006
|
-
const frame = this.getFrame(frameId);
|
|
1007
|
-
if (!frame) {
|
|
1008
|
-
throw new FrameError(
|
|
1009
|
-
`Frame not found: ${frameId}`,
|
|
1010
|
-
ErrorCode.FRAME_NOT_FOUND,
|
|
1011
|
-
{ frameId }
|
|
1012
|
-
);
|
|
1013
|
-
}
|
|
1014
|
-
if (newParentFrameId) {
|
|
1015
|
-
const cycle = this.detectCycle(frameId, newParentFrameId);
|
|
1016
|
-
if (cycle) {
|
|
1017
|
-
throw new FrameError(
|
|
1018
|
-
`Cannot set parent: would create circular reference`,
|
|
1019
|
-
ErrorCode.FRAME_CYCLE_DETECTED,
|
|
1020
|
-
{
|
|
1021
|
-
frameId,
|
|
1022
|
-
newParentFrameId,
|
|
1023
|
-
cycle,
|
|
1024
|
-
currentParentId: frame.parent_frame_id
|
|
1025
|
-
}
|
|
1026
|
-
);
|
|
1027
|
-
}
|
|
1028
|
-
const newParentFrame = this.getFrame(newParentFrameId);
|
|
1029
|
-
if (newParentFrame) {
|
|
1030
|
-
const newDepth = newParentFrame.depth + 1;
|
|
1031
|
-
if (newDepth > this.maxFrameDepth) {
|
|
1032
|
-
throw new FrameError(
|
|
1033
|
-
`Cannot set parent: would exceed maximum frame depth`,
|
|
1034
|
-
ErrorCode.FRAME_STACK_OVERFLOW,
|
|
1035
|
-
{
|
|
1036
|
-
frameId,
|
|
1037
|
-
newParentFrameId,
|
|
1038
|
-
newDepth,
|
|
1039
|
-
maxDepth: this.maxFrameDepth
|
|
1040
|
-
}
|
|
1041
|
-
);
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
try {
|
|
1046
|
-
this.db.prepare(`UPDATE frames SET parent_frame_id = ? WHERE frame_id = ?`).run(newParentFrameId, frameId);
|
|
1047
|
-
logger.info("Updated parent frame", {
|
|
1048
|
-
frameId,
|
|
1049
|
-
oldParentId: frame.parent_frame_id,
|
|
1050
|
-
newParentId: newParentFrameId
|
|
1051
|
-
});
|
|
1052
|
-
} catch (error) {
|
|
1053
|
-
throw new DatabaseError(
|
|
1054
|
-
`Failed to update parent frame`,
|
|
1055
|
-
ErrorCode.DB_UPDATE_FAILED,
|
|
1056
|
-
{
|
|
1057
|
-
frameId,
|
|
1058
|
-
newParentFrameId,
|
|
1059
|
-
operation: "updateParentFrame"
|
|
1060
|
-
},
|
|
1061
|
-
error instanceof Error ? error : void 0
|
|
1062
|
-
);
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
export {
|
|
1067
|
-
FrameManager
|
|
1068
|
-
};
|
|
1069
|
-
//# sourceMappingURL=frame-manager.js.map
|