@stackmemoryai/stackmemory 0.5.58 → 0.5.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/search.js +20 -3
- package/dist/cli/commands/search.js.map +2 -2
- package/dist/core/database/sqlite-adapter.js +13 -3
- package/dist/core/database/sqlite-adapter.js.map +2 -2
- package/dist/core/errors/error-utils.js +208 -0
- package/dist/core/errors/error-utils.js.map +7 -0
- package/dist/core/errors/index.js +13 -4
- package/dist/core/errors/index.js.map +2 -2
- package/dist/core/merge/unified-merge-resolver.js +303 -0
- package/dist/core/merge/unified-merge-resolver.js.map +7 -0
- package/dist/core/monitoring/logger.js +61 -9
- package/dist/core/monitoring/logger.js.map +2 -2
- package/dist/core/security/index.js +35 -0
- package/dist/core/security/index.js.map +7 -0
- package/dist/core/security/input-sanitizer.js +321 -0
- package/dist/core/security/input-sanitizer.js.map +7 -0
- package/dist/integrations/linear/client.js +5 -1
- package/dist/integrations/linear/client.js.map +2 -2
- package/dist/integrations/mcp/remote-server.js +27 -36
- package/dist/integrations/mcp/remote-server.js.map +2 -2
- package/dist/integrations/mcp/server.js +44 -29
- package/dist/integrations/mcp/server.js.map +3 -3
- package/dist/scripts/benchmark-performance.js +48 -0
- package/dist/scripts/benchmark-performance.js.map +7 -0
- package/dist/scripts/check-redis.js +42 -0
- package/dist/scripts/check-redis.js.map +7 -0
- package/dist/scripts/initialize.js +116 -0
- package/dist/scripts/initialize.js.map +7 -0
- package/dist/scripts/list-linear-tasks.js +124 -0
- package/dist/scripts/list-linear-tasks.js.map +7 -0
- package/dist/scripts/measure-handoff-impact.js +340 -0
- package/dist/scripts/measure-handoff-impact.js.map +7 -0
- package/dist/scripts/query-chromadb.js +160 -0
- package/dist/scripts/query-chromadb.js.map +7 -0
- package/dist/scripts/show-linear-summary.js +119 -0
- package/dist/scripts/show-linear-summary.js.map +7 -0
- package/dist/scripts/simple-swarm-demo.js +90 -0
- package/dist/scripts/simple-swarm-demo.js.map +7 -0
- package/dist/scripts/status.js +155 -0
- package/dist/scripts/status.js.map +7 -0
- package/dist/scripts/test-chromadb-sync.js +192 -0
- package/dist/scripts/test-chromadb-sync.js.map +7 -0
- package/dist/scripts/test-ralph-iteration-fix.js +86 -0
- package/dist/scripts/test-ralph-iteration-fix.js.map +7 -0
- package/dist/scripts/test-ralph-iterations.js +121 -0
- package/dist/scripts/test-ralph-iterations.js.map +7 -0
- package/dist/scripts/test-redis-storage.js +389 -0
- package/dist/scripts/test-redis-storage.js.map +7 -0
- package/dist/scripts/test-simple-ralph-state-sync.js +115 -0
- package/dist/scripts/test-simple-ralph-state-sync.js.map +7 -0
- package/dist/scripts/test-swarm-fixes.js +125 -0
- package/dist/scripts/test-swarm-fixes.js.map +7 -0
- package/dist/scripts/test-swarm-tui.js +23 -0
- package/dist/scripts/test-swarm-tui.js.map +7 -0
- package/dist/scripts/test-tui-shortcuts.js +52 -0
- package/dist/scripts/test-tui-shortcuts.js.map +7 -0
- package/dist/scripts/validate-tui-shortcuts.js +60 -0
- package/dist/scripts/validate-tui-shortcuts.js.map +7 -0
- package/dist/src/agents/core/agent-task-manager.js +527 -0
- package/dist/src/agents/core/agent-task-manager.js.map +7 -0
- package/dist/src/agents/verifiers/base-verifier.js +133 -0
- package/dist/src/agents/verifiers/base-verifier.js.map +7 -0
- package/dist/src/agents/verifiers/formatter-verifier.js +130 -0
- package/dist/src/agents/verifiers/formatter-verifier.js.map +7 -0
- package/dist/src/agents/verifiers/llm-judge.js +252 -0
- package/dist/src/agents/verifiers/llm-judge.js.map +7 -0
- package/dist/src/cli/auto-detect.js +321 -0
- package/dist/src/cli/auto-detect.js.map +7 -0
- package/dist/src/cli/claude-sm-danger.js +21 -0
- package/dist/src/cli/claude-sm-danger.js.map +7 -0
- package/dist/src/cli/claude-sm.js +1156 -0
- package/dist/src/cli/claude-sm.js.map +7 -0
- package/dist/src/cli/codex-sm-danger.js +21 -0
- package/dist/src/cli/codex-sm-danger.js.map +7 -0
- package/dist/src/cli/codex-sm.js +349 -0
- package/dist/src/cli/codex-sm.js.map +7 -0
- package/dist/src/cli/commands/api.js +232 -0
- package/dist/src/cli/commands/api.js.map +7 -0
- package/dist/src/cli/commands/auto-background.js +180 -0
- package/dist/src/cli/commands/auto-background.js.map +7 -0
- package/dist/src/cli/commands/cleanup-processes.js +68 -0
- package/dist/src/cli/commands/cleanup-processes.js.map +7 -0
- package/dist/src/cli/commands/clear.js +202 -0
- package/dist/src/cli/commands/clear.js.map +7 -0
- package/dist/src/cli/commands/config.js +445 -0
- package/dist/src/cli/commands/config.js.map +7 -0
- package/dist/src/cli/commands/context-rehydrate.js +751 -0
- package/dist/src/cli/commands/context-rehydrate.js.map +7 -0
- package/dist/src/cli/commands/context.js +343 -0
- package/dist/src/cli/commands/context.js.map +7 -0
- package/dist/src/cli/commands/daemon.js +392 -0
- package/dist/src/cli/commands/daemon.js.map +7 -0
- package/dist/src/cli/commands/dashboard.js +210 -0
- package/dist/src/cli/commands/dashboard.js.map +7 -0
- package/dist/src/cli/commands/db.js +147 -0
- package/dist/src/cli/commands/db.js.map +7 -0
- package/dist/src/cli/commands/decision.js +266 -0
- package/dist/src/cli/commands/decision.js.map +7 -0
- package/dist/src/cli/commands/discovery.js +279 -0
- package/dist/src/cli/commands/discovery.js.map +7 -0
- package/dist/src/cli/commands/handoff.js +624 -0
- package/dist/src/cli/commands/handoff.js.map +7 -0
- package/dist/src/cli/commands/hooks.js +298 -0
- package/dist/src/cli/commands/hooks.js.map +7 -0
- package/dist/src/cli/commands/linear.js +529 -0
- package/dist/src/cli/commands/linear.js.map +7 -0
- package/dist/src/cli/commands/log.js +169 -0
- package/dist/src/cli/commands/log.js.map +7 -0
- package/dist/src/cli/commands/login.js +172 -0
- package/dist/src/cli/commands/login.js.map +7 -0
- package/dist/src/cli/commands/migrate.js +240 -0
- package/dist/src/cli/commands/migrate.js.map +7 -0
- package/dist/src/cli/commands/model.js +533 -0
- package/dist/src/cli/commands/model.js.map +7 -0
- package/dist/src/cli/commands/onboard.js +536 -0
- package/dist/src/cli/commands/onboard.js.map +7 -0
- package/dist/src/cli/commands/projects.js +199 -0
- package/dist/src/cli/commands/projects.js.map +7 -0
- package/dist/src/cli/commands/ralph.js +909 -0
- package/dist/src/cli/commands/ralph.js.map +7 -0
- package/dist/src/cli/commands/retrieval.js +248 -0
- package/dist/src/cli/commands/retrieval.js.map +7 -0
- package/dist/src/cli/commands/search.js +173 -0
- package/dist/src/cli/commands/search.js.map +7 -0
- package/dist/src/cli/commands/service.js +749 -0
- package/dist/src/cli/commands/service.js.map +7 -0
- package/dist/src/cli/commands/session.js +200 -0
- package/dist/src/cli/commands/session.js.map +7 -0
- package/dist/src/cli/commands/settings.js +306 -0
- package/dist/src/cli/commands/settings.js.map +7 -0
- package/dist/src/cli/commands/setup.js +701 -0
- package/dist/src/cli/commands/setup.js.map +7 -0
- package/dist/src/cli/commands/shell.js +249 -0
- package/dist/src/cli/commands/shell.js.map +7 -0
- package/dist/src/cli/commands/signup.js +50 -0
- package/dist/src/cli/commands/signup.js.map +7 -0
- package/dist/src/cli/commands/skills.js +470 -0
- package/dist/src/cli/commands/skills.js.map +7 -0
- package/dist/src/cli/commands/sms-notify.js +795 -0
- package/dist/src/cli/commands/sms-notify.js.map +7 -0
- package/dist/src/cli/commands/storage-tier.js +183 -0
- package/dist/src/cli/commands/storage-tier.js.map +7 -0
- package/dist/src/cli/commands/sweep.js +249 -0
- package/dist/src/cli/commands/sweep.js.map +7 -0
- package/dist/src/cli/commands/tasks.js +213 -0
- package/dist/src/cli/commands/tasks.js.map +7 -0
- package/dist/src/cli/commands/worktree.js +319 -0
- package/dist/src/cli/commands/worktree.js.map +7 -0
- package/dist/src/cli/index.js +594 -0
- package/dist/src/cli/index.js.map +7 -0
- package/dist/src/cli/opencode-sm.js +448 -0
- package/dist/src/cli/opencode-sm.js.map +7 -0
- package/dist/src/cli/utils/viewer.js +96 -0
- package/dist/src/cli/utils/viewer.js.map +7 -0
- package/dist/src/core/config/config-manager.js +398 -0
- package/dist/src/core/config/config-manager.js.map +7 -0
- package/dist/src/core/config/feature-flags.js +76 -0
- package/dist/src/core/config/feature-flags.js.map +7 -0
- package/dist/src/core/config/storage-config.js +115 -0
- package/dist/src/core/config/storage-config.js.map +7 -0
- package/dist/src/core/config/types.js +144 -0
- package/dist/src/core/config/types.js.map +7 -0
- package/dist/src/core/context/auto-context.js +80 -0
- package/dist/src/core/context/auto-context.js.map +7 -0
- package/dist/src/core/context/dual-stack-manager.js +870 -0
- package/dist/src/core/context/dual-stack-manager.js.map +7 -0
- package/dist/src/core/context/enhanced-rehydration.js +994 -0
- package/dist/src/core/context/enhanced-rehydration.js.map +7 -0
- package/dist/src/core/context/frame-database.js +479 -0
- package/dist/src/core/context/frame-database.js.map +7 -0
- package/dist/src/core/context/frame-digest.js +250 -0
- package/dist/src/core/context/frame-digest.js.map +7 -0
- package/dist/src/core/context/frame-handoff-manager.js +778 -0
- package/dist/src/core/context/frame-handoff-manager.js.map +7 -0
- package/dist/src/core/context/frame-lifecycle-hooks.js +119 -0
- package/dist/src/core/context/frame-lifecycle-hooks.js.map +7 -0
- package/dist/src/core/context/frame-recovery.js +302 -0
- package/dist/src/core/context/frame-recovery.js.map +7 -0
- package/dist/src/core/context/frame-stack.js +314 -0
- package/dist/src/core/context/frame-stack.js.map +7 -0
- package/dist/src/core/context/frame-types.js +5 -0
- package/dist/src/core/context/frame-types.js.map +7 -0
- package/dist/src/core/context/index.js +25 -0
- package/dist/src/core/context/index.js.map +7 -0
- package/dist/src/core/context/permission-manager.js +185 -0
- package/dist/src/core/context/permission-manager.js.map +7 -0
- package/dist/src/core/context/recursive-context-manager.js +592 -0
- package/dist/src/core/context/recursive-context-manager.js.map +7 -0
- package/dist/src/core/context/refactored-frame-manager.js +754 -0
- package/dist/src/core/context/refactored-frame-manager.js.map +7 -0
- package/dist/src/core/context/shared-context-layer.js +621 -0
- package/dist/src/core/context/shared-context-layer.js.map +7 -0
- package/dist/src/core/context/stack-merge-resolver.js +749 -0
- package/dist/src/core/context/stack-merge-resolver.js.map +7 -0
- package/dist/src/core/context/validation.js +130 -0
- package/dist/src/core/context/validation.js.map +7 -0
- package/dist/src/core/database/batch-operations.js +384 -0
- package/dist/src/core/database/batch-operations.js.map +7 -0
- package/dist/src/core/database/connection-pool.js +330 -0
- package/dist/src/core/database/connection-pool.js.map +7 -0
- package/dist/src/core/database/database-adapter.js +60 -0
- package/dist/src/core/database/database-adapter.js.map +7 -0
- package/dist/src/core/database/migration-manager.js +614 -0
- package/dist/src/core/database/migration-manager.js.map +7 -0
- package/dist/src/core/database/query-cache.js +298 -0
- package/dist/src/core/database/query-cache.js.map +7 -0
- package/dist/src/core/database/query-router.js +430 -0
- package/dist/src/core/database/query-router.js.map +7 -0
- package/dist/src/core/database/sqlite-adapter.js +738 -0
- package/dist/src/core/database/sqlite-adapter.js.map +7 -0
- package/dist/src/core/digest/enhanced-hybrid-digest.js +277 -0
- package/dist/src/core/digest/enhanced-hybrid-digest.js.map +7 -0
- package/dist/src/core/digest/frame-digest-integration.js +176 -0
- package/dist/src/core/digest/frame-digest-integration.js.map +7 -0
- package/dist/src/core/digest/hybrid-digest-generator.js +553 -0
- package/dist/src/core/digest/hybrid-digest-generator.js.map +7 -0
- package/dist/src/core/digest/index.js +9 -0
- package/dist/src/core/digest/index.js.map +7 -0
- package/dist/src/core/digest/types.js +25 -0
- package/dist/src/core/digest/types.js.map +7 -0
- package/dist/src/core/errors/error-utils.js +208 -0
- package/dist/src/core/errors/error-utils.js.map +7 -0
- package/dist/src/core/errors/index.js +521 -0
- package/dist/src/core/errors/index.js.map +7 -0
- package/dist/src/core/errors/recovery.js +269 -0
- package/dist/src/core/errors/recovery.js.map +7 -0
- package/dist/src/core/execution/parallel-executor.js +258 -0
- package/dist/src/core/execution/parallel-executor.js.map +7 -0
- package/dist/src/core/frame/workflow-templates.js +319 -0
- package/dist/src/core/frame/workflow-templates.js.map +7 -0
- package/dist/src/core/merge/conflict-detector.js +431 -0
- package/dist/src/core/merge/conflict-detector.js.map +7 -0
- package/dist/src/core/merge/index.js +9 -0
- package/dist/src/core/merge/index.js.map +7 -0
- package/dist/src/core/merge/resolution-engine.js +558 -0
- package/dist/src/core/merge/resolution-engine.js.map +7 -0
- package/dist/src/core/merge/stack-diff.js +532 -0
- package/dist/src/core/merge/stack-diff.js.map +7 -0
- package/dist/src/core/merge/types.js +5 -0
- package/dist/src/core/merge/types.js.map +7 -0
- package/dist/src/core/merge/unified-merge-resolver.js +303 -0
- package/dist/src/core/merge/unified-merge-resolver.js.map +7 -0
- package/dist/src/core/models/fallback-monitor.js +232 -0
- package/dist/src/core/models/fallback-monitor.js.map +7 -0
- package/dist/src/core/models/model-router.js +340 -0
- package/dist/src/core/models/model-router.js.map +7 -0
- package/dist/src/core/monitoring/error-handler.js +49 -0
- package/dist/src/core/monitoring/error-handler.js.map +7 -0
- package/dist/src/core/monitoring/logger.js +202 -0
- package/dist/src/core/monitoring/logger.js.map +7 -0
- package/dist/src/core/monitoring/metrics.js +172 -0
- package/dist/src/core/monitoring/metrics.js.map +7 -0
- package/dist/src/core/monitoring/progress-tracker.js +189 -0
- package/dist/src/core/monitoring/progress-tracker.js.map +7 -0
- package/dist/src/core/monitoring/session-monitor.js +300 -0
- package/dist/src/core/monitoring/session-monitor.js.map +7 -0
- package/dist/src/core/performance/context-cache.js +273 -0
- package/dist/src/core/performance/context-cache.js.map +7 -0
- package/dist/src/core/performance/index.js +11 -0
- package/dist/src/core/performance/index.js.map +7 -0
- package/dist/src/core/performance/lazy-context-loader.js +327 -0
- package/dist/src/core/performance/lazy-context-loader.js.map +7 -0
- package/dist/src/core/performance/monitor.js +221 -0
- package/dist/src/core/performance/monitor.js.map +7 -0
- package/dist/src/core/performance/optimized-frame-context.js +345 -0
- package/dist/src/core/performance/optimized-frame-context.js.map +7 -0
- package/dist/src/core/performance/performance-benchmark.js +277 -0
- package/dist/src/core/performance/performance-benchmark.js.map +7 -0
- package/dist/src/core/performance/performance-profiler.js +370 -0
- package/dist/src/core/performance/performance-profiler.js.map +7 -0
- package/dist/src/core/performance/streaming-jsonl-parser.js +195 -0
- package/dist/src/core/performance/streaming-jsonl-parser.js.map +7 -0
- package/dist/src/core/persistence/postgres-adapter.js +349 -0
- package/dist/src/core/persistence/postgres-adapter.js.map +7 -0
- package/dist/src/core/projects/project-isolation.js +201 -0
- package/dist/src/core/projects/project-isolation.js.map +7 -0
- package/dist/src/core/projects/project-manager.js +697 -0
- package/dist/src/core/projects/project-manager.js.map +7 -0
- package/dist/src/core/query/query-parser.js +370 -0
- package/dist/src/core/query/query-parser.js.map +7 -0
- package/dist/src/core/query/query-templates.js +321 -0
- package/dist/src/core/query/query-templates.js.map +7 -0
- package/dist/src/core/retrieval/context-retriever.js +479 -0
- package/dist/src/core/retrieval/context-retriever.js.map +7 -0
- package/dist/src/core/retrieval/index.js +8 -0
- package/dist/src/core/retrieval/index.js.map +7 -0
- package/dist/src/core/retrieval/llm-context-retrieval.js +613 -0
- package/dist/src/core/retrieval/llm-context-retrieval.js.map +7 -0
- package/dist/src/core/retrieval/llm-provider.js +151 -0
- package/dist/src/core/retrieval/llm-provider.js.map +7 -0
- package/dist/src/core/retrieval/retrieval-audit.js +236 -0
- package/dist/src/core/retrieval/retrieval-audit.js.map +7 -0
- package/dist/src/core/retrieval/summary-generator.js +589 -0
- package/dist/src/core/retrieval/summary-generator.js.map +7 -0
- package/dist/src/core/retrieval/types.js +21 -0
- package/dist/src/core/retrieval/types.js.map +7 -0
- package/dist/src/core/security/index.js +35 -0
- package/dist/src/core/security/index.js.map +7 -0
- package/dist/src/core/security/input-sanitizer.js +321 -0
- package/dist/src/core/security/input-sanitizer.js.map +7 -0
- package/dist/src/core/session/clear-survival.js +465 -0
- package/dist/src/core/session/clear-survival.js.map +7 -0
- package/dist/src/core/session/enhanced-handoff.js +792 -0
- package/dist/src/core/session/enhanced-handoff.js.map +7 -0
- package/dist/src/core/session/handoff-generator.js +343 -0
- package/dist/src/core/session/handoff-generator.js.map +7 -0
- package/dist/src/core/session/index.js +15 -0
- package/dist/src/core/session/index.js.map +7 -0
- package/dist/src/core/session/session-manager.js +347 -0
- package/dist/src/core/session/session-manager.js.map +7 -0
- package/dist/src/core/skills/index.js +7 -0
- package/dist/src/core/skills/index.js.map +7 -0
- package/dist/src/core/skills/skill-storage.js +764 -0
- package/dist/src/core/skills/skill-storage.js.map +7 -0
- package/dist/src/core/skills/types.js +193 -0
- package/dist/src/core/skills/types.js.map +7 -0
- package/dist/src/core/storage/chromadb-adapter.js +354 -0
- package/dist/src/core/storage/chromadb-adapter.js.map +7 -0
- package/dist/src/core/storage/infinite-storage.js +510 -0
- package/dist/src/core/storage/infinite-storage.js.map +7 -0
- package/dist/src/core/storage/remote-storage.js +489 -0
- package/dist/src/core/storage/remote-storage.js.map +7 -0
- package/dist/src/core/storage/two-tier-storage.js +766 -0
- package/dist/src/core/storage/two-tier-storage.js.map +7 -0
- package/dist/src/core/trace/cli-trace-wrapper.js +132 -0
- package/dist/src/core/trace/cli-trace-wrapper.js.map +7 -0
- package/dist/src/core/trace/db-trace-wrapper.js +247 -0
- package/dist/src/core/trace/db-trace-wrapper.js.map +7 -0
- package/dist/src/core/trace/debug-trace.js +417 -0
- package/dist/src/core/trace/debug-trace.js.map +7 -0
- package/dist/src/core/trace/index.js +109 -0
- package/dist/src/core/trace/index.js.map +7 -0
- package/dist/src/core/trace/linear-api-wrapper.js +178 -0
- package/dist/src/core/trace/linear-api-wrapper.js.map +7 -0
- package/dist/src/core/trace/trace-detector.js +528 -0
- package/dist/src/core/trace/trace-detector.js.map +7 -0
- package/dist/src/core/trace/trace-store.js +345 -0
- package/dist/src/core/trace/trace-store.js.map +7 -0
- package/dist/src/core/trace/types.js +77 -0
- package/dist/src/core/trace/types.js.map +7 -0
- package/dist/src/core/types.js +5 -0
- package/dist/src/core/types.js.map +7 -0
- package/dist/src/core/utils/async-mutex.js +114 -0
- package/dist/src/core/utils/async-mutex.js.map +7 -0
- package/dist/src/core/utils/compression.js +83 -0
- package/dist/src/core/utils/compression.js.map +7 -0
- package/dist/src/core/utils/update-checker.js +218 -0
- package/dist/src/core/utils/update-checker.js.map +7 -0
- package/dist/src/core/worktree/worktree-manager.js +465 -0
- package/dist/src/core/worktree/worktree-manager.js.map +7 -0
- package/dist/src/daemon/daemon-config.js +149 -0
- package/dist/src/daemon/daemon-config.js.map +7 -0
- package/dist/src/daemon/services/context-service.js +122 -0
- package/dist/src/daemon/services/context-service.js.map +7 -0
- package/dist/src/daemon/services/linear-service.js +136 -0
- package/dist/src/daemon/services/linear-service.js.map +7 -0
- package/dist/src/daemon/session-daemon.js +312 -0
- package/dist/src/daemon/session-daemon.js.map +7 -0
- package/dist/src/daemon/unified-daemon.js +276 -0
- package/dist/src/daemon/unified-daemon.js.map +7 -0
- package/dist/src/features/analytics/api/analytics-api.js +287 -0
- package/dist/src/features/analytics/api/analytics-api.js.map +7 -0
- package/dist/src/features/analytics/core/analytics-service.js +282 -0
- package/dist/src/features/analytics/core/analytics-service.js.map +7 -0
- package/dist/src/features/analytics/index.js +18 -0
- package/dist/src/features/analytics/index.js.map +7 -0
- package/dist/src/features/analytics/queries/metrics-queries.js +277 -0
- package/dist/src/features/analytics/queries/metrics-queries.js.map +7 -0
- package/dist/src/features/analytics/types/metrics.js +5 -0
- package/dist/src/features/analytics/types/metrics.js.map +7 -0
- package/dist/src/features/browser/browser-mcp.js +492 -0
- package/dist/src/features/browser/browser-mcp.js.map +7 -0
- package/dist/src/features/sweep/index.js +20 -0
- package/dist/src/features/sweep/index.js.map +7 -0
- package/dist/src/features/sweep/prediction-client.js +155 -0
- package/dist/src/features/sweep/prediction-client.js.map +7 -0
- package/dist/src/features/sweep/prompt-builder.js +85 -0
- package/dist/src/features/sweep/prompt-builder.js.map +7 -0
- package/dist/src/features/sweep/pty-wrapper.js +171 -0
- package/dist/src/features/sweep/pty-wrapper.js.map +7 -0
- package/dist/src/features/sweep/state-watcher.js +87 -0
- package/dist/src/features/sweep/state-watcher.js.map +7 -0
- package/dist/src/features/sweep/status-bar.js +88 -0
- package/dist/src/features/sweep/status-bar.js.map +7 -0
- package/dist/src/features/sweep/sweep-server-manager.js +226 -0
- package/dist/src/features/sweep/sweep-server-manager.js.map +7 -0
- package/dist/src/features/sweep/tab-interceptor.js +38 -0
- package/dist/src/features/sweep/tab-interceptor.js.map +7 -0
- package/dist/src/features/sweep/types.js +18 -0
- package/dist/src/features/sweep/types.js.map +7 -0
- package/dist/src/features/tasks/linear-task-manager.js +487 -0
- package/dist/src/features/tasks/linear-task-manager.js.map +7 -0
- package/dist/src/features/tasks/task-aware-context.js +410 -0
- package/dist/src/features/tasks/task-aware-context.js.map +7 -0
- package/dist/src/features/tui/simple-monitor.js +116 -0
- package/dist/src/features/tui/simple-monitor.js.map +7 -0
- package/dist/src/features/tui/swarm-monitor.js +648 -0
- package/dist/src/features/tui/swarm-monitor.js.map +7 -0
- package/dist/src/features/web/client/stores/task-store.js +26 -0
- package/dist/src/features/web/client/stores/task-store.js.map +7 -0
- package/dist/src/features/web/server/index.js +194 -0
- package/dist/src/features/web/server/index.js.map +7 -0
- package/dist/src/hooks/auto-background.js +151 -0
- package/dist/src/hooks/auto-background.js.map +7 -0
- package/dist/src/hooks/claude-code-whatsapp-hook.js +197 -0
- package/dist/src/hooks/claude-code-whatsapp-hook.js.map +7 -0
- package/dist/src/hooks/config.js +150 -0
- package/dist/src/hooks/config.js.map +7 -0
- package/dist/src/hooks/daemon.js +364 -0
- package/dist/src/hooks/daemon.js.map +7 -0
- package/dist/src/hooks/events.js +58 -0
- package/dist/src/hooks/events.js.map +7 -0
- package/dist/src/hooks/index.js +12 -0
- package/dist/src/hooks/index.js.map +7 -0
- package/dist/src/hooks/linear-task-picker.js +186 -0
- package/dist/src/hooks/linear-task-picker.js.map +7 -0
- package/dist/src/hooks/schemas.js +197 -0
- package/dist/src/hooks/schemas.js.map +7 -0
- package/dist/src/hooks/secure-fs.js +49 -0
- package/dist/src/hooks/secure-fs.js.map +7 -0
- package/dist/src/hooks/security-logger.js +155 -0
- package/dist/src/hooks/security-logger.js.map +7 -0
- package/dist/src/hooks/session-summary.js +222 -0
- package/dist/src/hooks/session-summary.js.map +7 -0
- package/dist/src/hooks/sms-action-runner.js +371 -0
- package/dist/src/hooks/sms-action-runner.js.map +7 -0
- package/dist/src/hooks/sms-notify.js +506 -0
- package/dist/src/hooks/sms-notify.js.map +7 -0
- package/dist/src/hooks/sms-watcher.js +93 -0
- package/dist/src/hooks/sms-watcher.js.map +7 -0
- package/dist/src/hooks/sms-webhook.js +555 -0
- package/dist/src/hooks/sms-webhook.js.map +7 -0
- package/dist/src/hooks/whatsapp-commands.js +479 -0
- package/dist/src/hooks/whatsapp-commands.js.map +7 -0
- package/dist/src/hooks/whatsapp-scheduler.js +317 -0
- package/dist/src/hooks/whatsapp-scheduler.js.map +7 -0
- package/dist/src/hooks/whatsapp-sync.js +409 -0
- package/dist/src/hooks/whatsapp-sync.js.map +7 -0
- package/dist/src/index.js +25 -0
- package/dist/src/index.js.map +7 -0
- package/dist/src/integrations/anthropic/client.js +263 -0
- package/dist/src/integrations/anthropic/client.js.map +7 -0
- package/dist/src/integrations/claude-code/agent-bridge.js +768 -0
- package/dist/src/integrations/claude-code/agent-bridge.js.map +7 -0
- package/dist/src/integrations/claude-code/enhanced-pre-clear-hooks.js +459 -0
- package/dist/src/integrations/claude-code/enhanced-pre-clear-hooks.js.map +7 -0
- package/dist/src/integrations/claude-code/lifecycle-hooks.js +254 -0
- package/dist/src/integrations/claude-code/lifecycle-hooks.js.map +7 -0
- package/dist/src/integrations/claude-code/post-task-hooks.js +545 -0
- package/dist/src/integrations/claude-code/post-task-hooks.js.map +7 -0
- package/dist/src/integrations/claude-code/subagent-client-stub.js +20 -0
- package/dist/src/integrations/claude-code/subagent-client-stub.js.map +7 -0
- package/dist/src/integrations/claude-code/subagent-client.js +511 -0
- package/dist/src/integrations/claude-code/subagent-client.js.map +7 -0
- package/dist/src/integrations/claude-code/task-coordinator.js +360 -0
- package/dist/src/integrations/claude-code/task-coordinator.js.map +7 -0
- package/dist/src/integrations/linear/auth.js +337 -0
- package/dist/src/integrations/linear/auth.js.map +7 -0
- package/dist/src/integrations/linear/auto-sync.js +258 -0
- package/dist/src/integrations/linear/auto-sync.js.map +7 -0
- package/dist/src/integrations/linear/client.js +634 -0
- package/dist/src/integrations/linear/client.js.map +7 -0
- package/dist/src/integrations/linear/config.js +130 -0
- package/dist/src/integrations/linear/config.js.map +7 -0
- package/dist/src/integrations/linear/migration.js +361 -0
- package/dist/src/integrations/linear/migration.js.map +7 -0
- package/dist/src/integrations/linear/oauth-server.js +454 -0
- package/dist/src/integrations/linear/oauth-server.js.map +7 -0
- package/dist/src/integrations/linear/rest-client.js +213 -0
- package/dist/src/integrations/linear/rest-client.js.map +7 -0
- package/dist/src/integrations/linear/sync-manager.js +236 -0
- package/dist/src/integrations/linear/sync-manager.js.map +7 -0
- package/dist/src/integrations/linear/sync-service.js +231 -0
- package/dist/src/integrations/linear/sync-service.js.map +7 -0
- package/dist/src/integrations/linear/sync.js +782 -0
- package/dist/src/integrations/linear/sync.js.map +7 -0
- package/dist/src/integrations/linear/types.js +5 -0
- package/dist/src/integrations/linear/types.js.map +7 -0
- package/dist/src/integrations/linear/unified-sync.js +589 -0
- package/dist/src/integrations/linear/unified-sync.js.map +7 -0
- package/dist/src/integrations/linear/webhook-handler.js +219 -0
- package/dist/src/integrations/linear/webhook-handler.js.map +7 -0
- package/dist/src/integrations/linear/webhook-server.js +218 -0
- package/dist/src/integrations/linear/webhook-server.js.map +7 -0
- package/dist/src/integrations/linear/webhook.js +291 -0
- package/dist/src/integrations/linear/webhook.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/code-execution-handlers.js +266 -0
- package/dist/src/integrations/mcp/handlers/code-execution-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/context-handlers.js +257 -0
- package/dist/src/integrations/mcp/handlers/context-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/discovery-handlers.js +497 -0
- package/dist/src/integrations/mcp/handlers/discovery-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/index.js +166 -0
- package/dist/src/integrations/mcp/handlers/index.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/linear-handlers.js +247 -0
- package/dist/src/integrations/mcp/handlers/linear-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/skill-handlers.js +529 -0
- package/dist/src/integrations/mcp/handlers/skill-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/task-handlers.js +239 -0
- package/dist/src/integrations/mcp/handlers/task-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/trace-handlers.js +308 -0
- package/dist/src/integrations/mcp/handlers/trace-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/index.js +23 -0
- package/dist/src/integrations/mcp/index.js.map +7 -0
- package/dist/src/integrations/mcp/middleware/tool-scoring.js +356 -0
- package/dist/src/integrations/mcp/middleware/tool-scoring.js.map +7 -0
- package/dist/src/integrations/mcp/refactored-server.js +374 -0
- package/dist/src/integrations/mcp/refactored-server.js.map +7 -0
- package/dist/src/integrations/mcp/remote-server.js +682 -0
- package/dist/src/integrations/mcp/remote-server.js.map +7 -0
- package/dist/src/integrations/mcp/schemas.js +147 -0
- package/dist/src/integrations/mcp/schemas.js.map +7 -0
- package/dist/src/integrations/mcp/server.js +1975 -0
- package/dist/src/integrations/mcp/server.js.map +7 -0
- package/dist/src/integrations/mcp/tool-definitions-code.js +125 -0
- package/dist/src/integrations/mcp/tool-definitions-code.js.map +7 -0
- package/dist/src/integrations/mcp/tool-definitions.js +702 -0
- package/dist/src/integrations/mcp/tool-definitions.js.map +7 -0
- package/dist/src/integrations/ralph/bridge/ralph-stackmemory-bridge.js +860 -0
- package/dist/src/integrations/ralph/bridge/ralph-stackmemory-bridge.js.map +7 -0
- package/dist/src/integrations/ralph/context/context-budget-manager.js +301 -0
- package/dist/src/integrations/ralph/context/context-budget-manager.js.map +7 -0
- package/dist/src/integrations/ralph/context/stackmemory-context-loader.js +360 -0
- package/dist/src/integrations/ralph/context/stackmemory-context-loader.js.map +7 -0
- package/dist/src/integrations/ralph/coordination/enhanced-coordination.js +410 -0
- package/dist/src/integrations/ralph/coordination/enhanced-coordination.js.map +7 -0
- package/dist/src/integrations/ralph/index.js +18 -0
- package/dist/src/integrations/ralph/index.js.map +7 -0
- package/dist/src/integrations/ralph/learning/pattern-learner.js +401 -0
- package/dist/src/integrations/ralph/learning/pattern-learner.js.map +7 -0
- package/dist/src/integrations/ralph/lifecycle/iteration-lifecycle.js +448 -0
- package/dist/src/integrations/ralph/lifecycle/iteration-lifecycle.js.map +7 -0
- package/dist/src/integrations/ralph/monitoring/swarm-dashboard.js +294 -0
- package/dist/src/integrations/ralph/monitoring/swarm-dashboard.js.map +7 -0
- package/dist/src/integrations/ralph/monitoring/swarm-registry.js +108 -0
- package/dist/src/integrations/ralph/monitoring/swarm-registry.js.map +7 -0
- package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js +463 -0
- package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js.map +7 -0
- package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js +400 -0
- package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js.map +7 -0
- package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js +473 -0
- package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js.map +7 -0
- package/dist/src/integrations/ralph/patterns/oracle-worker-pattern.js +388 -0
- package/dist/src/integrations/ralph/patterns/oracle-worker-pattern.js.map +7 -0
- package/dist/src/integrations/ralph/performance/performance-optimizer.js +358 -0
- package/dist/src/integrations/ralph/performance/performance-optimizer.js.map +7 -0
- package/dist/src/integrations/ralph/recovery/crash-recovery.js +462 -0
- package/dist/src/integrations/ralph/recovery/crash-recovery.js.map +7 -0
- package/dist/src/integrations/ralph/state/state-reconciler.js +404 -0
- package/dist/src/integrations/ralph/state/state-reconciler.js.map +7 -0
- package/dist/src/integrations/ralph/swarm/git-workflow-manager.js +428 -0
- package/dist/src/integrations/ralph/swarm/git-workflow-manager.js.map +7 -0
- package/dist/src/integrations/ralph/swarm/swarm-coordinator.js +996 -0
- package/dist/src/integrations/ralph/swarm/swarm-coordinator.js.map +7 -0
- package/dist/src/integrations/ralph/types.js +5 -0
- package/dist/src/integrations/ralph/types.js.map +7 -0
- package/dist/src/integrations/ralph/visualization/ralph-debugger.js +585 -0
- package/dist/src/integrations/ralph/visualization/ralph-debugger.js.map +7 -0
- package/dist/src/mcp/stackmemory-mcp-server.js +554 -0
- package/dist/src/mcp/stackmemory-mcp-server.js.map +7 -0
- package/dist/src/middleware/exponential-rate-limiter.js +289 -0
- package/dist/src/middleware/exponential-rate-limiter.js.map +7 -0
- package/dist/src/models/user.model.js +358 -0
- package/dist/src/models/user.model.js.map +7 -0
- package/dist/src/servers/production/auth-middleware.js +528 -0
- package/dist/src/servers/production/auth-middleware.js.map +7 -0
- package/dist/src/services/config-service.js +65 -0
- package/dist/src/services/config-service.js.map +7 -0
- package/dist/src/services/context-service.js +194 -0
- package/dist/src/services/context-service.js.map +7 -0
- package/dist/src/skills/api-discovery.js +354 -0
- package/dist/src/skills/api-discovery.js.map +7 -0
- package/dist/src/skills/api-skill.js +475 -0
- package/dist/src/skills/api-skill.js.map +7 -0
- package/dist/src/skills/claude-skills.js +1061 -0
- package/dist/src/skills/claude-skills.js.map +7 -0
- package/dist/src/skills/dashboard-launcher.js +216 -0
- package/dist/src/skills/dashboard-launcher.js.map +7 -0
- package/dist/src/skills/recursive-agent-orchestrator.js +575 -0
- package/dist/src/skills/recursive-agent-orchestrator.js.map +7 -0
- package/dist/src/skills/repo-ingestion-skill.js +609 -0
- package/dist/src/skills/repo-ingestion-skill.js.map +7 -0
- package/dist/src/skills/unified-rlm-orchestrator.js +404 -0
- package/dist/src/skills/unified-rlm-orchestrator.js.map +7 -0
- package/dist/src/types/task.js +5 -0
- package/dist/src/types/task.js.map +7 -0
- package/dist/src/utils/env.js +50 -0
- package/dist/src/utils/env.js.map +7 -0
- package/dist/src/utils/formatting.js +62 -0
- package/dist/src/utils/formatting.js.map +7 -0
- package/dist/src/utils/process-cleanup.js +136 -0
- package/dist/src/utils/process-cleanup.js.map +7 -0
- package/package.json +3 -3
- package/scripts/initialize.ts +16 -7
- package/scripts/install.sh +14 -62
- package/scripts/status.ts +111 -46
|
@@ -0,0 +1,1975 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
3
|
+
import { dirname as __pathDirname } from 'path';
|
|
4
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = __pathDirname(__filename);
|
|
6
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
7
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import Database from "better-sqlite3";
|
|
10
|
+
import {
|
|
11
|
+
validateInput,
|
|
12
|
+
StartFrameSchema,
|
|
13
|
+
AddAnchorSchema,
|
|
14
|
+
CreateTaskSchema
|
|
15
|
+
} from "./schemas.js";
|
|
16
|
+
import { readFileSync, existsSync, mkdirSync } from "fs";
|
|
17
|
+
import { join, dirname } from "path";
|
|
18
|
+
import { execSync } from "child_process";
|
|
19
|
+
import { FrameManager } from "../../core/context/index.js";
|
|
20
|
+
import { logger } from "../../core/monitoring/logger.js";
|
|
21
|
+
import { isFeatureEnabled } from "../../core/config/feature-flags.js";
|
|
22
|
+
import {
|
|
23
|
+
TaskPriority,
|
|
24
|
+
TaskStatus
|
|
25
|
+
} from "../../features/tasks/linear-task-manager.js";
|
|
26
|
+
import { BrowserMCPIntegration } from "../../features/browser/browser-mcp.js";
|
|
27
|
+
import { TraceDetector } from "../../core/trace/trace-detector.js";
|
|
28
|
+
import { LLMContextRetrieval } from "../../core/retrieval/index.js";
|
|
29
|
+
import { DiscoveryHandlers } from "./handlers/discovery-handlers.js";
|
|
30
|
+
import { v4 as uuidv4 } from "uuid";
|
|
31
|
+
function getEnv(key, defaultValue) {
|
|
32
|
+
const value = process.env[key];
|
|
33
|
+
if (value === void 0) {
|
|
34
|
+
if (defaultValue !== void 0) return defaultValue;
|
|
35
|
+
throw new Error(`Environment variable ${key} is required`);
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
function getOptionalEnv(key) {
|
|
40
|
+
return process.env[key];
|
|
41
|
+
}
|
|
42
|
+
class LocalStackMemoryMCP {
|
|
43
|
+
server;
|
|
44
|
+
db;
|
|
45
|
+
projectRoot;
|
|
46
|
+
frameManager;
|
|
47
|
+
taskStore = null;
|
|
48
|
+
linearAuthManager = null;
|
|
49
|
+
linearSync = null;
|
|
50
|
+
projectId;
|
|
51
|
+
contexts = /* @__PURE__ */ new Map();
|
|
52
|
+
browserMCP;
|
|
53
|
+
traceDetector;
|
|
54
|
+
contextRetrieval;
|
|
55
|
+
discoveryHandlers;
|
|
56
|
+
constructor() {
|
|
57
|
+
this.projectRoot = this.findProjectRoot();
|
|
58
|
+
this.projectId = this.getProjectId();
|
|
59
|
+
const dbDir = join(this.projectRoot, ".stackmemory");
|
|
60
|
+
if (!existsSync(dbDir)) {
|
|
61
|
+
mkdirSync(dbDir, { recursive: true });
|
|
62
|
+
}
|
|
63
|
+
const dbPath = join(dbDir, "context.db");
|
|
64
|
+
this.db = new Database(dbPath);
|
|
65
|
+
this.initDB();
|
|
66
|
+
this.frameManager = new FrameManager(this.db, this.projectId);
|
|
67
|
+
this.initLinearIfEnabled();
|
|
68
|
+
this.server = new Server(
|
|
69
|
+
{
|
|
70
|
+
name: "stackmemory-local",
|
|
71
|
+
version: "0.1.0"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
capabilities: {
|
|
75
|
+
tools: {}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
this.browserMCP = new BrowserMCPIntegration({
|
|
80
|
+
headless: process.env["BROWSER_HEADLESS"] !== "false",
|
|
81
|
+
defaultViewport: { width: 1280, height: 720 }
|
|
82
|
+
});
|
|
83
|
+
this.traceDetector = new TraceDetector({}, void 0, this.db);
|
|
84
|
+
this.contextRetrieval = new LLMContextRetrieval(
|
|
85
|
+
this.db,
|
|
86
|
+
this.frameManager,
|
|
87
|
+
this.projectId
|
|
88
|
+
);
|
|
89
|
+
this.discoveryHandlers = new DiscoveryHandlers({
|
|
90
|
+
frameManager: this.frameManager,
|
|
91
|
+
contextRetrieval: this.contextRetrieval,
|
|
92
|
+
db: this.db,
|
|
93
|
+
projectRoot: this.projectRoot
|
|
94
|
+
});
|
|
95
|
+
this.setupHandlers();
|
|
96
|
+
this.loadInitialContext();
|
|
97
|
+
this.browserMCP.initialize(this.server).catch((error) => {
|
|
98
|
+
logger.error("Failed to initialize Browser MCP", error);
|
|
99
|
+
});
|
|
100
|
+
logger.info("StackMemory MCP Server initialized", {
|
|
101
|
+
projectRoot: this.projectRoot,
|
|
102
|
+
projectId: this.projectId
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
findProjectRoot() {
|
|
106
|
+
let dir = process.cwd();
|
|
107
|
+
while (dir !== "/") {
|
|
108
|
+
if (existsSync(join(dir, ".git"))) {
|
|
109
|
+
return dir;
|
|
110
|
+
}
|
|
111
|
+
dir = dirname(dir);
|
|
112
|
+
}
|
|
113
|
+
return process.cwd();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Initialize Linear integration if enabled and credentials available
|
|
117
|
+
*/
|
|
118
|
+
async initLinearIfEnabled() {
|
|
119
|
+
if (!isFeatureEnabled("linear")) {
|
|
120
|
+
logger.info("Linear integration disabled (no API key or LOCAL mode)");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const { LinearTaskManager } = await import("../../features/tasks/linear-task-manager.js");
|
|
125
|
+
const { LinearAuthManager } = await import("../linear/auth.js");
|
|
126
|
+
const { LinearSyncEngine, DEFAULT_SYNC_CONFIG: DEFAULT_SYNC_CONFIG2 } = await import("../linear/sync.js");
|
|
127
|
+
this.taskStore = new LinearTaskManager(this.projectRoot, this.db);
|
|
128
|
+
this.linearAuthManager = new LinearAuthManager(this.projectRoot);
|
|
129
|
+
this.linearSync = new LinearSyncEngine(
|
|
130
|
+
this.taskStore,
|
|
131
|
+
this.linearAuthManager,
|
|
132
|
+
DEFAULT_SYNC_CONFIG2
|
|
133
|
+
);
|
|
134
|
+
logger.info("Linear integration initialized");
|
|
135
|
+
} catch (error) {
|
|
136
|
+
logger.warn("Failed to initialize Linear integration", { error });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
initDB() {
|
|
140
|
+
this.db.exec(`
|
|
141
|
+
CREATE TABLE IF NOT EXISTS contexts (
|
|
142
|
+
id TEXT PRIMARY KEY,
|
|
143
|
+
type TEXT NOT NULL,
|
|
144
|
+
content TEXT NOT NULL,
|
|
145
|
+
importance REAL DEFAULT 0.5,
|
|
146
|
+
created_at INTEGER DEFAULT (unixepoch()),
|
|
147
|
+
last_accessed INTEGER DEFAULT (unixepoch()),
|
|
148
|
+
access_count INTEGER DEFAULT 1
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
CREATE TABLE IF NOT EXISTS attention_log (
|
|
152
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
153
|
+
context_id TEXT,
|
|
154
|
+
query TEXT,
|
|
155
|
+
response TEXT,
|
|
156
|
+
influence_score REAL,
|
|
157
|
+
timestamp INTEGER DEFAULT (unixepoch())
|
|
158
|
+
);
|
|
159
|
+
`);
|
|
160
|
+
}
|
|
161
|
+
loadInitialContext() {
|
|
162
|
+
const projectInfo = this.getProjectInfo();
|
|
163
|
+
this.addContext(
|
|
164
|
+
"project",
|
|
165
|
+
`Project: ${projectInfo.name}
|
|
166
|
+
Path: ${projectInfo.path}`,
|
|
167
|
+
0.9
|
|
168
|
+
);
|
|
169
|
+
try {
|
|
170
|
+
const recentCommits = execSync("git log --oneline -10", {
|
|
171
|
+
cwd: this.projectRoot
|
|
172
|
+
}).toString();
|
|
173
|
+
this.addContext("git_history", `Recent commits:
|
|
174
|
+
${recentCommits}`, 0.6);
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
const readmePath = join(this.projectRoot, "README.md");
|
|
178
|
+
if (existsSync(readmePath)) {
|
|
179
|
+
const readme = readFileSync(readmePath, "utf-8");
|
|
180
|
+
const summary = readme.substring(0, 500);
|
|
181
|
+
this.addContext("readme", `Project README:
|
|
182
|
+
${summary}...`, 0.8);
|
|
183
|
+
}
|
|
184
|
+
this.loadStoredContexts();
|
|
185
|
+
}
|
|
186
|
+
getProjectId() {
|
|
187
|
+
let identifier;
|
|
188
|
+
try {
|
|
189
|
+
identifier = execSync("git config --get remote.origin.url", {
|
|
190
|
+
cwd: this.projectRoot,
|
|
191
|
+
stdio: "pipe",
|
|
192
|
+
timeout: 5e3
|
|
193
|
+
}).toString().trim();
|
|
194
|
+
} catch {
|
|
195
|
+
identifier = this.projectRoot;
|
|
196
|
+
}
|
|
197
|
+
const cleaned = identifier.replace(/\.git$/, "").replace(/[^a-zA-Z0-9-]/g, "-").toLowerCase();
|
|
198
|
+
return cleaned.substring(cleaned.length - 50) || "unknown";
|
|
199
|
+
}
|
|
200
|
+
getProjectInfo() {
|
|
201
|
+
const packageJsonPath = join(this.projectRoot, "package.json");
|
|
202
|
+
if (existsSync(packageJsonPath)) {
|
|
203
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
204
|
+
return {
|
|
205
|
+
name: pkg.name || "unknown",
|
|
206
|
+
path: this.projectRoot
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
name: this.projectRoot.split("/").pop() || "unknown",
|
|
211
|
+
path: this.projectRoot
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
addContext(type, content, importance = 0.5) {
|
|
215
|
+
const id = `${type}_${Date.now()}`;
|
|
216
|
+
this.db.prepare(
|
|
217
|
+
`
|
|
218
|
+
INSERT OR REPLACE INTO contexts (id, type, content, importance)
|
|
219
|
+
VALUES (?, ?, ?, ?)
|
|
220
|
+
`
|
|
221
|
+
).run(id, type, content, importance);
|
|
222
|
+
this.contexts.set(id, { type, content, importance });
|
|
223
|
+
return id;
|
|
224
|
+
}
|
|
225
|
+
loadStoredContexts() {
|
|
226
|
+
const stored = this.db.prepare(
|
|
227
|
+
`
|
|
228
|
+
SELECT * FROM contexts
|
|
229
|
+
ORDER BY importance DESC, last_accessed DESC
|
|
230
|
+
LIMIT 50
|
|
231
|
+
`
|
|
232
|
+
).all();
|
|
233
|
+
stored.forEach((ctx) => {
|
|
234
|
+
this.contexts.set(ctx.id, ctx);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
setupHandlers() {
|
|
238
|
+
this.server.setRequestHandler(
|
|
239
|
+
z.object({
|
|
240
|
+
method: z.literal("tools/list")
|
|
241
|
+
}),
|
|
242
|
+
async () => {
|
|
243
|
+
return {
|
|
244
|
+
tools: [
|
|
245
|
+
{
|
|
246
|
+
name: "get_context",
|
|
247
|
+
description: "Get current project context",
|
|
248
|
+
inputSchema: {
|
|
249
|
+
type: "object",
|
|
250
|
+
properties: {
|
|
251
|
+
query: {
|
|
252
|
+
type: "string",
|
|
253
|
+
description: "What you want to know"
|
|
254
|
+
},
|
|
255
|
+
limit: {
|
|
256
|
+
type: "number",
|
|
257
|
+
description: "Max contexts to return"
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
name: "add_decision",
|
|
264
|
+
description: "Record a decision or important information",
|
|
265
|
+
inputSchema: {
|
|
266
|
+
type: "object",
|
|
267
|
+
properties: {
|
|
268
|
+
content: {
|
|
269
|
+
type: "string",
|
|
270
|
+
description: "The decision or information"
|
|
271
|
+
},
|
|
272
|
+
type: {
|
|
273
|
+
type: "string",
|
|
274
|
+
enum: ["decision", "constraint", "learning"]
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
required: ["content", "type"]
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
name: "start_frame",
|
|
282
|
+
description: "Start a new frame (task/subtask) on the call stack",
|
|
283
|
+
inputSchema: {
|
|
284
|
+
type: "object",
|
|
285
|
+
properties: {
|
|
286
|
+
name: { type: "string", description: "Frame name/goal" },
|
|
287
|
+
type: {
|
|
288
|
+
type: "string",
|
|
289
|
+
enum: [
|
|
290
|
+
"task",
|
|
291
|
+
"subtask",
|
|
292
|
+
"tool_scope",
|
|
293
|
+
"review",
|
|
294
|
+
"write",
|
|
295
|
+
"debug"
|
|
296
|
+
],
|
|
297
|
+
description: "Frame type"
|
|
298
|
+
},
|
|
299
|
+
constraints: {
|
|
300
|
+
type: "array",
|
|
301
|
+
items: { type: "string" },
|
|
302
|
+
description: "Constraints for this frame"
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
required: ["name", "type"]
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
name: "close_frame",
|
|
310
|
+
description: "Close current frame and generate digest",
|
|
311
|
+
inputSchema: {
|
|
312
|
+
type: "object",
|
|
313
|
+
properties: {
|
|
314
|
+
result: {
|
|
315
|
+
type: "string",
|
|
316
|
+
description: "Frame completion result"
|
|
317
|
+
},
|
|
318
|
+
outputs: {
|
|
319
|
+
type: "object",
|
|
320
|
+
description: "Final outputs from frame"
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
name: "add_anchor",
|
|
327
|
+
description: "Add anchored fact/decision/constraint to current frame",
|
|
328
|
+
inputSchema: {
|
|
329
|
+
type: "object",
|
|
330
|
+
properties: {
|
|
331
|
+
type: {
|
|
332
|
+
type: "string",
|
|
333
|
+
enum: [
|
|
334
|
+
"FACT",
|
|
335
|
+
"DECISION",
|
|
336
|
+
"CONSTRAINT",
|
|
337
|
+
"INTERFACE_CONTRACT",
|
|
338
|
+
"TODO",
|
|
339
|
+
"RISK"
|
|
340
|
+
],
|
|
341
|
+
description: "Anchor type"
|
|
342
|
+
},
|
|
343
|
+
text: { type: "string", description: "Anchor content" },
|
|
344
|
+
priority: {
|
|
345
|
+
type: "number",
|
|
346
|
+
description: "Priority (0-10)",
|
|
347
|
+
minimum: 0,
|
|
348
|
+
maximum: 10
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
required: ["type", "text"]
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
name: "get_hot_stack",
|
|
356
|
+
description: "Get current active frames and context",
|
|
357
|
+
inputSchema: {
|
|
358
|
+
type: "object",
|
|
359
|
+
properties: {
|
|
360
|
+
maxEvents: {
|
|
361
|
+
type: "number",
|
|
362
|
+
description: "Max recent events per frame",
|
|
363
|
+
default: 20
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
name: "create_task",
|
|
370
|
+
description: "Create a new task in git-tracked JSONL storage",
|
|
371
|
+
inputSchema: {
|
|
372
|
+
type: "object",
|
|
373
|
+
properties: {
|
|
374
|
+
title: { type: "string", description: "Task title" },
|
|
375
|
+
description: {
|
|
376
|
+
type: "string",
|
|
377
|
+
description: "Task description"
|
|
378
|
+
},
|
|
379
|
+
priority: {
|
|
380
|
+
type: "string",
|
|
381
|
+
enum: ["low", "medium", "high", "urgent"],
|
|
382
|
+
description: "Task priority"
|
|
383
|
+
},
|
|
384
|
+
estimatedEffort: {
|
|
385
|
+
type: "number",
|
|
386
|
+
description: "Estimated effort in minutes"
|
|
387
|
+
},
|
|
388
|
+
dependsOn: {
|
|
389
|
+
type: "array",
|
|
390
|
+
items: { type: "string" },
|
|
391
|
+
description: "Task IDs this depends on"
|
|
392
|
+
},
|
|
393
|
+
tags: {
|
|
394
|
+
type: "array",
|
|
395
|
+
items: { type: "string" },
|
|
396
|
+
description: "Tags for categorization"
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
required: ["title"]
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
name: "update_task_status",
|
|
404
|
+
description: "Update task status with automatic time tracking",
|
|
405
|
+
inputSchema: {
|
|
406
|
+
type: "object",
|
|
407
|
+
properties: {
|
|
408
|
+
taskId: { type: "string", description: "Task ID to update" },
|
|
409
|
+
status: {
|
|
410
|
+
type: "string",
|
|
411
|
+
enum: [
|
|
412
|
+
"pending",
|
|
413
|
+
"in_progress",
|
|
414
|
+
"completed",
|
|
415
|
+
"blocked",
|
|
416
|
+
"cancelled"
|
|
417
|
+
],
|
|
418
|
+
description: "New status"
|
|
419
|
+
},
|
|
420
|
+
reason: {
|
|
421
|
+
type: "string",
|
|
422
|
+
description: "Reason for status change (especially for blocked)"
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
required: ["taskId", "status"]
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
name: "get_active_tasks",
|
|
430
|
+
description: "Get currently active tasks synced from Linear",
|
|
431
|
+
inputSchema: {
|
|
432
|
+
type: "object",
|
|
433
|
+
properties: {
|
|
434
|
+
frameId: {
|
|
435
|
+
type: "string",
|
|
436
|
+
description: "Filter by specific frame ID"
|
|
437
|
+
},
|
|
438
|
+
status: {
|
|
439
|
+
type: "string",
|
|
440
|
+
enum: [
|
|
441
|
+
"pending",
|
|
442
|
+
"in_progress",
|
|
443
|
+
"completed",
|
|
444
|
+
"blocked",
|
|
445
|
+
"cancelled"
|
|
446
|
+
],
|
|
447
|
+
description: "Filter by status"
|
|
448
|
+
},
|
|
449
|
+
priority: {
|
|
450
|
+
type: "string",
|
|
451
|
+
enum: ["low", "medium", "high", "urgent"],
|
|
452
|
+
description: "Filter by priority"
|
|
453
|
+
},
|
|
454
|
+
search: {
|
|
455
|
+
type: "string",
|
|
456
|
+
description: "Search in task title or description"
|
|
457
|
+
},
|
|
458
|
+
limit: {
|
|
459
|
+
type: "number",
|
|
460
|
+
description: "Max number of tasks to return (default: 20)"
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
name: "get_task_metrics",
|
|
467
|
+
description: "Get project task metrics and analytics",
|
|
468
|
+
inputSchema: {
|
|
469
|
+
type: "object",
|
|
470
|
+
properties: {}
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
name: "add_task_dependency",
|
|
475
|
+
description: "Add dependency relationship between tasks",
|
|
476
|
+
inputSchema: {
|
|
477
|
+
type: "object",
|
|
478
|
+
properties: {
|
|
479
|
+
taskId: {
|
|
480
|
+
type: "string",
|
|
481
|
+
description: "Task that depends on another"
|
|
482
|
+
},
|
|
483
|
+
dependsOnId: {
|
|
484
|
+
type: "string",
|
|
485
|
+
description: "Task ID that this depends on"
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
required: ["taskId", "dependsOnId"]
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
name: "linear_sync",
|
|
493
|
+
description: "Sync tasks with Linear",
|
|
494
|
+
inputSchema: {
|
|
495
|
+
type: "object",
|
|
496
|
+
properties: {
|
|
497
|
+
direction: {
|
|
498
|
+
type: "string",
|
|
499
|
+
enum: ["bidirectional", "to_linear", "from_linear"],
|
|
500
|
+
description: "Sync direction"
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
name: "linear_update_task",
|
|
507
|
+
description: "Update a Linear task status",
|
|
508
|
+
inputSchema: {
|
|
509
|
+
type: "object",
|
|
510
|
+
properties: {
|
|
511
|
+
issueId: {
|
|
512
|
+
type: "string",
|
|
513
|
+
description: "Linear issue ID or identifier (e.g., STA-34)"
|
|
514
|
+
},
|
|
515
|
+
status: {
|
|
516
|
+
type: "string",
|
|
517
|
+
enum: ["todo", "in-progress", "done", "canceled"],
|
|
518
|
+
description: "New status for the task"
|
|
519
|
+
},
|
|
520
|
+
title: {
|
|
521
|
+
type: "string",
|
|
522
|
+
description: "Update task title (optional)"
|
|
523
|
+
},
|
|
524
|
+
description: {
|
|
525
|
+
type: "string",
|
|
526
|
+
description: "Update task description (optional)"
|
|
527
|
+
},
|
|
528
|
+
priority: {
|
|
529
|
+
type: "number",
|
|
530
|
+
enum: [1, 2, 3, 4],
|
|
531
|
+
description: "Priority (1=urgent, 2=high, 3=medium, 4=low)"
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
required: ["issueId"]
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
name: "linear_get_tasks",
|
|
539
|
+
description: "Get Linear tasks",
|
|
540
|
+
inputSchema: {
|
|
541
|
+
type: "object",
|
|
542
|
+
properties: {
|
|
543
|
+
status: {
|
|
544
|
+
type: "string",
|
|
545
|
+
enum: ["todo", "in-progress", "done", "all"],
|
|
546
|
+
description: "Filter by status"
|
|
547
|
+
},
|
|
548
|
+
limit: {
|
|
549
|
+
type: "number",
|
|
550
|
+
description: "Maximum number of tasks to return"
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
name: "linear_status",
|
|
557
|
+
description: "Get Linear integration status",
|
|
558
|
+
inputSchema: {
|
|
559
|
+
type: "object",
|
|
560
|
+
properties: {}
|
|
561
|
+
}
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
name: "get_traces",
|
|
565
|
+
description: "Get detected traces (bundled tool call sequences)",
|
|
566
|
+
inputSchema: {
|
|
567
|
+
type: "object",
|
|
568
|
+
properties: {
|
|
569
|
+
type: {
|
|
570
|
+
type: "string",
|
|
571
|
+
enum: [
|
|
572
|
+
"search_driven",
|
|
573
|
+
"error_recovery",
|
|
574
|
+
"feature_implementation",
|
|
575
|
+
"refactoring",
|
|
576
|
+
"testing",
|
|
577
|
+
"exploration",
|
|
578
|
+
"debugging",
|
|
579
|
+
"documentation",
|
|
580
|
+
"build_deploy",
|
|
581
|
+
"unknown"
|
|
582
|
+
],
|
|
583
|
+
description: "Filter by trace type"
|
|
584
|
+
},
|
|
585
|
+
minScore: {
|
|
586
|
+
type: "number",
|
|
587
|
+
description: "Minimum importance score (0-1)"
|
|
588
|
+
},
|
|
589
|
+
limit: {
|
|
590
|
+
type: "number",
|
|
591
|
+
description: "Maximum number of traces to return"
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
name: "get_trace_statistics",
|
|
598
|
+
description: "Get statistics about detected traces",
|
|
599
|
+
inputSchema: {
|
|
600
|
+
type: "object",
|
|
601
|
+
properties: {}
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
name: "flush_traces",
|
|
606
|
+
description: "Flush any pending trace and finalize detection",
|
|
607
|
+
inputSchema: {
|
|
608
|
+
type: "object",
|
|
609
|
+
properties: {}
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
name: "compress_old_traces",
|
|
614
|
+
description: "Compress traces older than specified hours",
|
|
615
|
+
inputSchema: {
|
|
616
|
+
type: "object",
|
|
617
|
+
properties: {
|
|
618
|
+
ageHours: {
|
|
619
|
+
type: "number",
|
|
620
|
+
description: "Age threshold in hours (default: 24)"
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
name: "smart_context",
|
|
627
|
+
description: "LLM-driven context retrieval - intelligently selects relevant frames based on query",
|
|
628
|
+
inputSchema: {
|
|
629
|
+
type: "object",
|
|
630
|
+
properties: {
|
|
631
|
+
query: {
|
|
632
|
+
type: "string",
|
|
633
|
+
description: "Natural language query describing what context you need"
|
|
634
|
+
},
|
|
635
|
+
tokenBudget: {
|
|
636
|
+
type: "number",
|
|
637
|
+
description: "Maximum tokens to use for context (default: 4000)"
|
|
638
|
+
},
|
|
639
|
+
forceRefresh: {
|
|
640
|
+
type: "boolean",
|
|
641
|
+
description: "Force refresh of cached summaries"
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
required: ["query"]
|
|
645
|
+
}
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
name: "get_summary",
|
|
649
|
+
description: "Get compressed summary of project memory for analysis",
|
|
650
|
+
inputSchema: {
|
|
651
|
+
type: "object",
|
|
652
|
+
properties: {
|
|
653
|
+
forceRefresh: {
|
|
654
|
+
type: "boolean",
|
|
655
|
+
description: "Force refresh of cached summary"
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
},
|
|
660
|
+
// Discovery tools
|
|
661
|
+
{
|
|
662
|
+
name: "sm_discover",
|
|
663
|
+
description: "Discover relevant files based on current context. Extracts keywords from active frames and searches codebase.",
|
|
664
|
+
inputSchema: {
|
|
665
|
+
type: "object",
|
|
666
|
+
properties: {
|
|
667
|
+
query: {
|
|
668
|
+
type: "string",
|
|
669
|
+
description: "Optional query to focus the discovery"
|
|
670
|
+
},
|
|
671
|
+
depth: {
|
|
672
|
+
type: "string",
|
|
673
|
+
enum: ["shallow", "medium", "deep"],
|
|
674
|
+
description: "Search depth"
|
|
675
|
+
},
|
|
676
|
+
maxFiles: {
|
|
677
|
+
type: "number",
|
|
678
|
+
description: "Maximum files to return"
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
name: "sm_related_files",
|
|
685
|
+
description: "Find files related to a specific file or concept",
|
|
686
|
+
inputSchema: {
|
|
687
|
+
type: "object",
|
|
688
|
+
properties: {
|
|
689
|
+
file: {
|
|
690
|
+
type: "string",
|
|
691
|
+
description: "File path to find related files for"
|
|
692
|
+
},
|
|
693
|
+
concept: {
|
|
694
|
+
type: "string",
|
|
695
|
+
description: "Concept to search for"
|
|
696
|
+
},
|
|
697
|
+
maxFiles: {
|
|
698
|
+
type: "number",
|
|
699
|
+
description: "Maximum files to return"
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
name: "sm_session_summary",
|
|
706
|
+
description: "Get summary of current session with active tasks, files, and decisions",
|
|
707
|
+
inputSchema: {
|
|
708
|
+
type: "object",
|
|
709
|
+
properties: {
|
|
710
|
+
includeFiles: {
|
|
711
|
+
type: "boolean",
|
|
712
|
+
description: "Include recently accessed files"
|
|
713
|
+
},
|
|
714
|
+
includeDecisions: {
|
|
715
|
+
type: "boolean",
|
|
716
|
+
description: "Include recent decisions"
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
name: "sm_search",
|
|
723
|
+
description: "Search across StackMemory - frames, events, decisions, tasks",
|
|
724
|
+
inputSchema: {
|
|
725
|
+
type: "object",
|
|
726
|
+
properties: {
|
|
727
|
+
query: {
|
|
728
|
+
type: "string",
|
|
729
|
+
description: "Search query"
|
|
730
|
+
},
|
|
731
|
+
scope: {
|
|
732
|
+
type: "string",
|
|
733
|
+
enum: ["all", "frames", "events", "decisions", "tasks"],
|
|
734
|
+
description: "Scope of search"
|
|
735
|
+
},
|
|
736
|
+
limit: {
|
|
737
|
+
type: "number",
|
|
738
|
+
description: "Maximum results"
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
required: ["query"]
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
]
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
);
|
|
748
|
+
this.server.setRequestHandler(
|
|
749
|
+
z.object({
|
|
750
|
+
method: z.literal("tools/call"),
|
|
751
|
+
params: z.object({
|
|
752
|
+
name: z.string(),
|
|
753
|
+
arguments: z.record(z.unknown())
|
|
754
|
+
})
|
|
755
|
+
}),
|
|
756
|
+
async (request) => {
|
|
757
|
+
const { name, arguments: args } = request.params;
|
|
758
|
+
const callId = uuidv4();
|
|
759
|
+
const startTime = Date.now();
|
|
760
|
+
const currentFrameId = this.frameManager.getCurrentFrameId();
|
|
761
|
+
if (currentFrameId) {
|
|
762
|
+
this.frameManager.addEvent("tool_call", {
|
|
763
|
+
tool_name: name,
|
|
764
|
+
arguments: args,
|
|
765
|
+
timestamp: startTime
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
const toolCall = {
|
|
769
|
+
id: callId,
|
|
770
|
+
tool: name,
|
|
771
|
+
arguments: args,
|
|
772
|
+
timestamp: startTime
|
|
773
|
+
};
|
|
774
|
+
let result;
|
|
775
|
+
let error;
|
|
776
|
+
try {
|
|
777
|
+
switch (name) {
|
|
778
|
+
case "get_context":
|
|
779
|
+
result = await this.handleGetContext(args);
|
|
780
|
+
break;
|
|
781
|
+
case "add_decision":
|
|
782
|
+
result = await this.handleAddDecision(args);
|
|
783
|
+
break;
|
|
784
|
+
case "start_frame":
|
|
785
|
+
result = await this.handleStartFrame(args);
|
|
786
|
+
break;
|
|
787
|
+
case "close_frame":
|
|
788
|
+
result = await this.handleCloseFrame(args);
|
|
789
|
+
break;
|
|
790
|
+
case "add_anchor":
|
|
791
|
+
result = await this.handleAddAnchor(args);
|
|
792
|
+
break;
|
|
793
|
+
case "get_hot_stack":
|
|
794
|
+
result = await this.handleGetHotStack(args);
|
|
795
|
+
break;
|
|
796
|
+
case "create_task":
|
|
797
|
+
result = await this.handleCreateTask(args);
|
|
798
|
+
break;
|
|
799
|
+
case "update_task_status":
|
|
800
|
+
result = await this.handleUpdateTaskStatus(args);
|
|
801
|
+
break;
|
|
802
|
+
case "get_active_tasks":
|
|
803
|
+
result = await this.handleGetActiveTasks(args);
|
|
804
|
+
break;
|
|
805
|
+
case "get_task_metrics":
|
|
806
|
+
result = await this.handleGetTaskMetrics(args);
|
|
807
|
+
break;
|
|
808
|
+
case "add_task_dependency":
|
|
809
|
+
result = await this.handleAddTaskDependency(args);
|
|
810
|
+
break;
|
|
811
|
+
case "linear_sync":
|
|
812
|
+
result = await this.handleLinearSync(args);
|
|
813
|
+
break;
|
|
814
|
+
case "linear_update_task":
|
|
815
|
+
result = await this.handleLinearUpdateTask(args);
|
|
816
|
+
break;
|
|
817
|
+
case "linear_get_tasks":
|
|
818
|
+
result = await this.handleLinearGetTasks(args);
|
|
819
|
+
break;
|
|
820
|
+
case "linear_status":
|
|
821
|
+
result = await this.handleLinearStatus(args);
|
|
822
|
+
break;
|
|
823
|
+
case "get_traces":
|
|
824
|
+
result = await this.handleGetTraces(args);
|
|
825
|
+
break;
|
|
826
|
+
case "get_trace_statistics":
|
|
827
|
+
result = await this.handleGetTraceStatistics(args);
|
|
828
|
+
break;
|
|
829
|
+
case "flush_traces":
|
|
830
|
+
result = await this.handleFlushTraces(args);
|
|
831
|
+
break;
|
|
832
|
+
case "compress_old_traces":
|
|
833
|
+
result = await this.handleCompressOldTraces(args);
|
|
834
|
+
break;
|
|
835
|
+
case "smart_context":
|
|
836
|
+
result = await this.handleSmartContext(args);
|
|
837
|
+
break;
|
|
838
|
+
case "get_summary":
|
|
839
|
+
result = await this.handleGetSummary(args);
|
|
840
|
+
break;
|
|
841
|
+
// Discovery tools
|
|
842
|
+
case "sm_discover":
|
|
843
|
+
result = await this.handleSmDiscover(args);
|
|
844
|
+
break;
|
|
845
|
+
case "sm_related_files":
|
|
846
|
+
result = await this.handleSmRelatedFiles(args);
|
|
847
|
+
break;
|
|
848
|
+
case "sm_session_summary":
|
|
849
|
+
result = await this.handleSmSessionSummary(args);
|
|
850
|
+
break;
|
|
851
|
+
case "sm_search":
|
|
852
|
+
result = await this.handleSmSearch(args);
|
|
853
|
+
break;
|
|
854
|
+
default:
|
|
855
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
856
|
+
}
|
|
857
|
+
} catch (err) {
|
|
858
|
+
error = err instanceof Error ? err : new Error(String(err));
|
|
859
|
+
toolCall.error = error.message;
|
|
860
|
+
throw err;
|
|
861
|
+
} finally {
|
|
862
|
+
const endTime = Date.now();
|
|
863
|
+
if (currentFrameId && name !== "close_frame") {
|
|
864
|
+
try {
|
|
865
|
+
this.frameManager.addEvent("tool_result", {
|
|
866
|
+
tool_name: name,
|
|
867
|
+
success: !error,
|
|
868
|
+
result: error ? { error: error.message } : result,
|
|
869
|
+
timestamp: endTime
|
|
870
|
+
});
|
|
871
|
+
} catch {
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
toolCall.result = error ? void 0 : result;
|
|
875
|
+
toolCall.duration = endTime - startTime;
|
|
876
|
+
if (args.file_path || args.path) {
|
|
877
|
+
toolCall.filesAffected = [args.file_path || args.path].filter(
|
|
878
|
+
Boolean
|
|
879
|
+
);
|
|
880
|
+
} else if (result?.files) {
|
|
881
|
+
const files = result.files;
|
|
882
|
+
toolCall.filesAffected = Array.isArray(files) ? files : [files];
|
|
883
|
+
}
|
|
884
|
+
this.traceDetector.addToolCall(toolCall);
|
|
885
|
+
}
|
|
886
|
+
return result;
|
|
887
|
+
}
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
async handleGetContext(args) {
|
|
891
|
+
const { query: query2 = "", limit = 10 } = args;
|
|
892
|
+
const contexts = Array.from(this.contexts.values()).sort((a, b) => b.importance - a.importance).slice(0, limit);
|
|
893
|
+
contexts.forEach((ctx) => {
|
|
894
|
+
this.db.prepare(
|
|
895
|
+
`
|
|
896
|
+
UPDATE contexts
|
|
897
|
+
SET last_accessed = unixepoch(),
|
|
898
|
+
access_count = access_count + 1
|
|
899
|
+
WHERE id = ?
|
|
900
|
+
`
|
|
901
|
+
).run(ctx.id);
|
|
902
|
+
});
|
|
903
|
+
const response = contexts.map(
|
|
904
|
+
(ctx) => `[${ctx.type.toUpperCase()}] (importance: ${ctx.importance.toFixed(2)})
|
|
905
|
+
${ctx.content}`
|
|
906
|
+
).join("\n\n---\n\n");
|
|
907
|
+
this.logAttention(query2, response);
|
|
908
|
+
return {
|
|
909
|
+
content: [
|
|
910
|
+
{
|
|
911
|
+
type: "text",
|
|
912
|
+
text: response || "No context available yet. Start adding decisions and information!"
|
|
913
|
+
}
|
|
914
|
+
]
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
async handleAddDecision(args) {
|
|
918
|
+
const { content, type = "decision" } = args;
|
|
919
|
+
const id = this.addContext(type, content, 0.8);
|
|
920
|
+
return {
|
|
921
|
+
content: [
|
|
922
|
+
{
|
|
923
|
+
type: "text",
|
|
924
|
+
text: `\u2713 Added ${type}: ${content}
|
|
925
|
+
ID: ${id}`
|
|
926
|
+
}
|
|
927
|
+
]
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
async handleStartFrame(args) {
|
|
931
|
+
const { name, type, constraints } = validateInput(
|
|
932
|
+
StartFrameSchema,
|
|
933
|
+
args,
|
|
934
|
+
"start_frame"
|
|
935
|
+
);
|
|
936
|
+
const inputs = {};
|
|
937
|
+
if (constraints) {
|
|
938
|
+
inputs.constraints = constraints;
|
|
939
|
+
}
|
|
940
|
+
const frameId = this.frameManager.createFrame({
|
|
941
|
+
type,
|
|
942
|
+
name,
|
|
943
|
+
inputs
|
|
944
|
+
});
|
|
945
|
+
this.frameManager.addEvent("user_message", {
|
|
946
|
+
action: "start_frame",
|
|
947
|
+
name,
|
|
948
|
+
type,
|
|
949
|
+
constraints
|
|
950
|
+
});
|
|
951
|
+
this.addContext("active_frame", `Active frame: ${name} (${type})`, 0.9);
|
|
952
|
+
const stackDepth = this.frameManager.getStackDepth();
|
|
953
|
+
return {
|
|
954
|
+
content: [
|
|
955
|
+
{
|
|
956
|
+
type: "text",
|
|
957
|
+
text: `\u{1F680} Started ${type}: ${name}
|
|
958
|
+
Frame ID: ${frameId}
|
|
959
|
+
Stack depth: ${stackDepth}`
|
|
960
|
+
}
|
|
961
|
+
]
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
async handleCloseFrame(args) {
|
|
965
|
+
const { result, outputs } = args;
|
|
966
|
+
const currentFrameId = this.frameManager.getCurrentFrameId();
|
|
967
|
+
if (!currentFrameId) {
|
|
968
|
+
return {
|
|
969
|
+
content: [
|
|
970
|
+
{
|
|
971
|
+
type: "text",
|
|
972
|
+
text: "\u26A0\uFE0F No active frame to close"
|
|
973
|
+
}
|
|
974
|
+
]
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
this.frameManager.addEvent("assistant_message", {
|
|
978
|
+
action: "close_frame",
|
|
979
|
+
result,
|
|
980
|
+
outputs
|
|
981
|
+
});
|
|
982
|
+
this.frameManager.closeFrame(currentFrameId, outputs);
|
|
983
|
+
const newStackDepth = this.frameManager.getStackDepth();
|
|
984
|
+
return {
|
|
985
|
+
content: [
|
|
986
|
+
{
|
|
987
|
+
type: "text",
|
|
988
|
+
text: `\u2705 Closed frame: ${result || "completed"}
|
|
989
|
+
Stack depth: ${newStackDepth}`
|
|
990
|
+
}
|
|
991
|
+
]
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
async handleAddAnchor(args) {
|
|
995
|
+
const { type, text, priority } = validateInput(
|
|
996
|
+
AddAnchorSchema,
|
|
997
|
+
args,
|
|
998
|
+
"add_anchor"
|
|
999
|
+
);
|
|
1000
|
+
const anchorId = this.frameManager.addAnchor(type, text, priority);
|
|
1001
|
+
this.frameManager.addEvent("decision", {
|
|
1002
|
+
anchor_type: type,
|
|
1003
|
+
text,
|
|
1004
|
+
priority,
|
|
1005
|
+
anchor_id: anchorId
|
|
1006
|
+
});
|
|
1007
|
+
return {
|
|
1008
|
+
content: [
|
|
1009
|
+
{
|
|
1010
|
+
type: "text",
|
|
1011
|
+
text: `\u{1F4CC} Added ${type}: ${text}
|
|
1012
|
+
Anchor ID: ${anchorId}`
|
|
1013
|
+
}
|
|
1014
|
+
]
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
async handleGetHotStack(args) {
|
|
1018
|
+
const { maxEvents = 20 } = args;
|
|
1019
|
+
const hotStack = this.frameManager.getHotStackContext(maxEvents);
|
|
1020
|
+
const activePath = this.frameManager.getActiveFramePath();
|
|
1021
|
+
if (hotStack.length === 0) {
|
|
1022
|
+
return {
|
|
1023
|
+
content: [
|
|
1024
|
+
{
|
|
1025
|
+
type: "text",
|
|
1026
|
+
text: "\u{1F4DA} No active frames. Start a frame with start_frame tool."
|
|
1027
|
+
}
|
|
1028
|
+
]
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
let response = "\u{1F4DA} **Active Call Stack:**\n\n";
|
|
1032
|
+
activePath.forEach((frame, index) => {
|
|
1033
|
+
const indent = " ".repeat(index);
|
|
1034
|
+
const context = hotStack[index];
|
|
1035
|
+
response += `${indent}${index + 1}. **${frame.name}** (${frame.type})
|
|
1036
|
+
`;
|
|
1037
|
+
if (context && context.anchors && context.anchors.length > 0) {
|
|
1038
|
+
response += `${indent} \u{1F4CC} ${context.anchors.length} anchors
|
|
1039
|
+
`;
|
|
1040
|
+
}
|
|
1041
|
+
if (context && context.recentEvents && context.recentEvents.length > 0) {
|
|
1042
|
+
response += `${indent} \u{1F4DD} ${context.recentEvents.length} recent events
|
|
1043
|
+
`;
|
|
1044
|
+
}
|
|
1045
|
+
response += "\n";
|
|
1046
|
+
});
|
|
1047
|
+
response += `**Total stack depth:** ${hotStack.length}`;
|
|
1048
|
+
this.frameManager.addEvent("observation", {
|
|
1049
|
+
action: "get_hot_stack",
|
|
1050
|
+
stack_depth: hotStack.length,
|
|
1051
|
+
total_anchors: hotStack.reduce(
|
|
1052
|
+
(sum, frame) => sum + frame.anchors.length,
|
|
1053
|
+
0
|
|
1054
|
+
),
|
|
1055
|
+
total_events: hotStack.reduce(
|
|
1056
|
+
(sum, frame) => sum + frame.recentEvents.length,
|
|
1057
|
+
0
|
|
1058
|
+
)
|
|
1059
|
+
});
|
|
1060
|
+
return {
|
|
1061
|
+
content: [
|
|
1062
|
+
{
|
|
1063
|
+
type: "text",
|
|
1064
|
+
text: response
|
|
1065
|
+
}
|
|
1066
|
+
]
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
logAttention(query2, response) {
|
|
1070
|
+
this.db.prepare(
|
|
1071
|
+
`
|
|
1072
|
+
INSERT INTO attention_log (query, response)
|
|
1073
|
+
VALUES (?, ?)
|
|
1074
|
+
`
|
|
1075
|
+
).run(query2, response);
|
|
1076
|
+
}
|
|
1077
|
+
async handleCreateTask(args) {
|
|
1078
|
+
const validated = validateInput(CreateTaskSchema, args, "create_task");
|
|
1079
|
+
const { title, description, priority, tags } = validated;
|
|
1080
|
+
const { estimatedEffort, dependsOn } = args;
|
|
1081
|
+
const currentFrameId = this.frameManager.getCurrentFrameId();
|
|
1082
|
+
if (!currentFrameId) {
|
|
1083
|
+
return {
|
|
1084
|
+
content: [
|
|
1085
|
+
{
|
|
1086
|
+
type: "text",
|
|
1087
|
+
text: "\u26A0\uFE0F No active frame. Start a frame first with start_frame tool."
|
|
1088
|
+
}
|
|
1089
|
+
]
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
const taskId = this.taskStore.createTask({
|
|
1093
|
+
title,
|
|
1094
|
+
description,
|
|
1095
|
+
priority,
|
|
1096
|
+
frameId: currentFrameId,
|
|
1097
|
+
dependsOn,
|
|
1098
|
+
tags,
|
|
1099
|
+
estimatedEffort
|
|
1100
|
+
});
|
|
1101
|
+
this.frameManager.addEvent("decision", {
|
|
1102
|
+
action: "create_task",
|
|
1103
|
+
task_id: taskId,
|
|
1104
|
+
title,
|
|
1105
|
+
priority: priority || "medium"
|
|
1106
|
+
});
|
|
1107
|
+
return {
|
|
1108
|
+
content: [
|
|
1109
|
+
{
|
|
1110
|
+
type: "text",
|
|
1111
|
+
text: `\u2705 Created task: ${title}
|
|
1112
|
+
ID: ${taskId}
|
|
1113
|
+
Frame: ${currentFrameId}
|
|
1114
|
+
Stored in: .stackmemory/tasks.jsonl`
|
|
1115
|
+
}
|
|
1116
|
+
]
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
async handleUpdateTaskStatus(args) {
|
|
1120
|
+
const { taskId, status, reason } = args;
|
|
1121
|
+
try {
|
|
1122
|
+
this.taskStore.updateTaskStatus(taskId, status, reason);
|
|
1123
|
+
this.frameManager.addEvent("observation", {
|
|
1124
|
+
action: "update_task_status",
|
|
1125
|
+
task_id: taskId,
|
|
1126
|
+
new_status: status,
|
|
1127
|
+
reason
|
|
1128
|
+
});
|
|
1129
|
+
return {
|
|
1130
|
+
content: [
|
|
1131
|
+
{
|
|
1132
|
+
type: "text",
|
|
1133
|
+
text: `\u2705 Updated task ${taskId} to ${status}${reason ? `
|
|
1134
|
+
Reason: ${reason}` : ""}`
|
|
1135
|
+
}
|
|
1136
|
+
]
|
|
1137
|
+
};
|
|
1138
|
+
} catch (error) {
|
|
1139
|
+
return {
|
|
1140
|
+
content: [
|
|
1141
|
+
{
|
|
1142
|
+
type: "text",
|
|
1143
|
+
text: `\u274C Failed to update task: ${error}`
|
|
1144
|
+
}
|
|
1145
|
+
]
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
async handleGetActiveTasks(args) {
|
|
1150
|
+
const { frameId, status, priority, search, limit = 20 } = args;
|
|
1151
|
+
let tasks = this.taskStore.getActiveTasks(frameId);
|
|
1152
|
+
if (status) {
|
|
1153
|
+
tasks = tasks.filter((t) => t.status === status);
|
|
1154
|
+
}
|
|
1155
|
+
if (priority) {
|
|
1156
|
+
tasks = tasks.filter((t) => t.priority === priority);
|
|
1157
|
+
}
|
|
1158
|
+
if (search) {
|
|
1159
|
+
const searchLower = search.toLowerCase();
|
|
1160
|
+
tasks = tasks.filter(
|
|
1161
|
+
(t) => t.title.toLowerCase().includes(searchLower) || t.description && t.description.toLowerCase().includes(searchLower)
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
const priorityOrder = { urgent: 0, high: 1, medium: 2, low: 3 };
|
|
1165
|
+
tasks.sort((a, b) => {
|
|
1166
|
+
const pa = priorityOrder[a.priority] ?? 2;
|
|
1167
|
+
const pb = priorityOrder[b.priority] ?? 2;
|
|
1168
|
+
if (pa !== pb) return pa - pb;
|
|
1169
|
+
return b.created_at - a.created_at;
|
|
1170
|
+
});
|
|
1171
|
+
tasks = tasks.slice(0, limit);
|
|
1172
|
+
if (tasks.length === 0) {
|
|
1173
|
+
return {
|
|
1174
|
+
content: [
|
|
1175
|
+
{
|
|
1176
|
+
type: "text",
|
|
1177
|
+
text: search ? `\u{1F4DD} No tasks matching "${search}"` : "\u{1F4DD} No active tasks found"
|
|
1178
|
+
}
|
|
1179
|
+
]
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
let response = `\u{1F4DD} **Tasks** (${tasks.length} found)
|
|
1183
|
+
|
|
1184
|
+
`;
|
|
1185
|
+
tasks.forEach((task) => {
|
|
1186
|
+
const priorityIcon = { urgent: "\u{1F534}", high: "\u{1F7E0}", medium: "\u{1F7E1}", low: "\u{1F7E2}" }[task.priority] || "\u26AA";
|
|
1187
|
+
const statusIcon = {
|
|
1188
|
+
pending: "\u23F3",
|
|
1189
|
+
in_progress: "\u{1F504}",
|
|
1190
|
+
completed: "\u2705",
|
|
1191
|
+
blocked: "\u{1F6AB}",
|
|
1192
|
+
cancelled: "\u274C"
|
|
1193
|
+
}[task.status] || "\u26AA";
|
|
1194
|
+
const effort = task.estimated_effort ? ` (~${task.estimated_effort}m)` : "";
|
|
1195
|
+
const linearMatch = task.title.match(/\[ENG-\d+\]/);
|
|
1196
|
+
const linearId = linearMatch ? linearMatch[0] : "";
|
|
1197
|
+
const title = linearId ? task.title.replace(linearId, "").trim() : task.title;
|
|
1198
|
+
response += `${statusIcon} ${priorityIcon} **${linearId || task.id}** ${title}${effort}
|
|
1199
|
+
`;
|
|
1200
|
+
if (task.description) {
|
|
1201
|
+
const desc = task.description.split("\n")[0].slice(0, 100);
|
|
1202
|
+
response += ` ${desc}${task.description.length > 100 ? "..." : ""}
|
|
1203
|
+
`;
|
|
1204
|
+
}
|
|
1205
|
+
if (task.tags && task.tags.length > 0) {
|
|
1206
|
+
response += ` \u{1F3F7}\uFE0F ${task.tags.join(", ")}
|
|
1207
|
+
`;
|
|
1208
|
+
}
|
|
1209
|
+
response += "\n";
|
|
1210
|
+
});
|
|
1211
|
+
return {
|
|
1212
|
+
content: [
|
|
1213
|
+
{
|
|
1214
|
+
type: "text",
|
|
1215
|
+
text: response
|
|
1216
|
+
}
|
|
1217
|
+
]
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
async handleGetTaskMetrics(_args) {
|
|
1221
|
+
const metrics = this.taskStore.getMetrics();
|
|
1222
|
+
let response = "\u{1F4CA} **Task Metrics**\n\n";
|
|
1223
|
+
response += `**Total Tasks:** ${metrics.total_tasks}
|
|
1224
|
+
`;
|
|
1225
|
+
response += `**Completion Rate:** ${(metrics.completion_rate * 100).toFixed(1)}%
|
|
1226
|
+
|
|
1227
|
+
`;
|
|
1228
|
+
response += "**By Status:**\n";
|
|
1229
|
+
Object.entries(metrics.by_status).forEach(([status, count]) => {
|
|
1230
|
+
response += `- ${status}: ${count}
|
|
1231
|
+
`;
|
|
1232
|
+
});
|
|
1233
|
+
response += "\n**By Priority:**\n";
|
|
1234
|
+
Object.entries(metrics.by_priority).forEach(([priority, count]) => {
|
|
1235
|
+
response += `- ${priority}: ${count}
|
|
1236
|
+
`;
|
|
1237
|
+
});
|
|
1238
|
+
if (metrics.blocked_tasks > 0) {
|
|
1239
|
+
response += `
|
|
1240
|
+
\u26A0\uFE0F **${metrics.blocked_tasks} blocked tasks**`;
|
|
1241
|
+
}
|
|
1242
|
+
if (metrics.avg_effort_accuracy > 0) {
|
|
1243
|
+
response += `
|
|
1244
|
+
\u{1F3AF} **Effort Accuracy:** ${(metrics.avg_effort_accuracy * 100).toFixed(1)}%`;
|
|
1245
|
+
}
|
|
1246
|
+
return {
|
|
1247
|
+
content: [
|
|
1248
|
+
{
|
|
1249
|
+
type: "text",
|
|
1250
|
+
text: response
|
|
1251
|
+
}
|
|
1252
|
+
]
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
async handleAddTaskDependency(args) {
|
|
1256
|
+
const { taskId, dependsOnId } = args;
|
|
1257
|
+
try {
|
|
1258
|
+
this.taskStore.addDependency(taskId, dependsOnId);
|
|
1259
|
+
this.frameManager.addEvent("decision", {
|
|
1260
|
+
action: "add_task_dependency",
|
|
1261
|
+
task_id: taskId,
|
|
1262
|
+
depends_on_id: dependsOnId
|
|
1263
|
+
});
|
|
1264
|
+
return {
|
|
1265
|
+
content: [
|
|
1266
|
+
{
|
|
1267
|
+
type: "text",
|
|
1268
|
+
text: `\u{1F517} Added dependency: ${taskId} depends on ${dependsOnId}`
|
|
1269
|
+
}
|
|
1270
|
+
]
|
|
1271
|
+
};
|
|
1272
|
+
} catch (error) {
|
|
1273
|
+
return {
|
|
1274
|
+
content: [
|
|
1275
|
+
{
|
|
1276
|
+
type: "text",
|
|
1277
|
+
text: `\u274C Failed to add dependency: ${error}`
|
|
1278
|
+
}
|
|
1279
|
+
]
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
// Linear Integration Handlers
|
|
1284
|
+
async handleLinearSync(args) {
|
|
1285
|
+
try {
|
|
1286
|
+
const tokens = this.linearAuthManager.loadTokens();
|
|
1287
|
+
if (!tokens) {
|
|
1288
|
+
return {
|
|
1289
|
+
content: [
|
|
1290
|
+
{
|
|
1291
|
+
type: "text",
|
|
1292
|
+
text: "\u274C Linear not authenticated. Run: stackmemory linear setup"
|
|
1293
|
+
}
|
|
1294
|
+
]
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
const syncConfig = { ...DEFAULT_SYNC_CONFIG, enabled: true };
|
|
1298
|
+
if (args.direction) {
|
|
1299
|
+
syncConfig.direction = args.direction;
|
|
1300
|
+
}
|
|
1301
|
+
this.linearSync.updateConfig(syncConfig);
|
|
1302
|
+
const result = await this.linearSync.sync();
|
|
1303
|
+
return {
|
|
1304
|
+
content: [
|
|
1305
|
+
{
|
|
1306
|
+
type: "text",
|
|
1307
|
+
text: `\u2705 Linear sync completed
|
|
1308
|
+
- To Linear: ${result.synced.toLinear} tasks
|
|
1309
|
+
- From Linear: ${result.synced.fromLinear} tasks
|
|
1310
|
+
- Updated: ${result.synced.updated} tasks`
|
|
1311
|
+
}
|
|
1312
|
+
]
|
|
1313
|
+
};
|
|
1314
|
+
} catch (error) {
|
|
1315
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1316
|
+
logger.error("Linear sync failed", { error: message });
|
|
1317
|
+
return {
|
|
1318
|
+
content: [
|
|
1319
|
+
{
|
|
1320
|
+
type: "text",
|
|
1321
|
+
text: `\u274C Linear sync failed: ${message}`
|
|
1322
|
+
}
|
|
1323
|
+
]
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
async handleLinearUpdateTask(args) {
|
|
1328
|
+
try {
|
|
1329
|
+
const { LinearClient } = await import("../linear/client.js");
|
|
1330
|
+
const tokens = this.linearAuthManager.loadTokens();
|
|
1331
|
+
if (!tokens) {
|
|
1332
|
+
return {
|
|
1333
|
+
content: [
|
|
1334
|
+
{
|
|
1335
|
+
type: "text",
|
|
1336
|
+
text: "\u274C Linear not authenticated. Run: stackmemory linear setup"
|
|
1337
|
+
}
|
|
1338
|
+
]
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1341
|
+
const client = new LinearClient({
|
|
1342
|
+
apiKey: tokens.accessToken,
|
|
1343
|
+
useBearer: true,
|
|
1344
|
+
onUnauthorized: async () => {
|
|
1345
|
+
const refreshed = await this.linearAuthManager.refreshAccessToken();
|
|
1346
|
+
return refreshed.accessToken;
|
|
1347
|
+
}
|
|
1348
|
+
});
|
|
1349
|
+
let issue = await client.getIssue(args.issueId);
|
|
1350
|
+
if (!issue) {
|
|
1351
|
+
issue = await client.findIssueByIdentifier(args.issueId);
|
|
1352
|
+
}
|
|
1353
|
+
if (!issue) {
|
|
1354
|
+
return {
|
|
1355
|
+
content: [
|
|
1356
|
+
{
|
|
1357
|
+
type: "text",
|
|
1358
|
+
text: `\u274C Linear issue ${args.issueId} not found`
|
|
1359
|
+
}
|
|
1360
|
+
]
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
const updates = {};
|
|
1364
|
+
if (args.status) {
|
|
1365
|
+
const team = await client.getTeam();
|
|
1366
|
+
const states = await client.getWorkflowStates(team.id);
|
|
1367
|
+
const statusMap = {
|
|
1368
|
+
todo: "unstarted",
|
|
1369
|
+
"in-progress": "started",
|
|
1370
|
+
done: "completed",
|
|
1371
|
+
canceled: "cancelled"
|
|
1372
|
+
};
|
|
1373
|
+
const targetType = statusMap[args.status] || args.status;
|
|
1374
|
+
const targetState = states.find((s) => s.type === targetType);
|
|
1375
|
+
if (!targetState) {
|
|
1376
|
+
return {
|
|
1377
|
+
content: [
|
|
1378
|
+
{
|
|
1379
|
+
type: "text",
|
|
1380
|
+
text: `\u274C Invalid status: ${args.status}`
|
|
1381
|
+
}
|
|
1382
|
+
]
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
updates.stateId = targetState.id;
|
|
1386
|
+
}
|
|
1387
|
+
if (args.title) updates.title = args.title;
|
|
1388
|
+
if (args.description) updates.description = args.description;
|
|
1389
|
+
if (args.priority) updates.priority = args.priority;
|
|
1390
|
+
const updatedIssue = await client.updateIssue(issue.id, updates);
|
|
1391
|
+
this.linearSync.updateConfig({
|
|
1392
|
+
...DEFAULT_SYNC_CONFIG,
|
|
1393
|
+
enabled: true,
|
|
1394
|
+
direction: "from_linear"
|
|
1395
|
+
});
|
|
1396
|
+
const syncResult = await this.linearSync.sync();
|
|
1397
|
+
let response = `\u2705 Updated ${updatedIssue.identifier}: ${updatedIssue.title}
|
|
1398
|
+
`;
|
|
1399
|
+
if (args.status) {
|
|
1400
|
+
response += `Status: ${updatedIssue.state.name}
|
|
1401
|
+
`;
|
|
1402
|
+
}
|
|
1403
|
+
response += `URL: ${updatedIssue.url}
|
|
1404
|
+
`;
|
|
1405
|
+
response += `
|
|
1406
|
+
\u{1F504} Local sync: ${syncResult.synced.fromLinear} new, ${syncResult.synced.updated} updated`;
|
|
1407
|
+
return {
|
|
1408
|
+
content: [
|
|
1409
|
+
{
|
|
1410
|
+
type: "text",
|
|
1411
|
+
text: response
|
|
1412
|
+
}
|
|
1413
|
+
]
|
|
1414
|
+
};
|
|
1415
|
+
} catch (error) {
|
|
1416
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1417
|
+
logger.error("Failed to update Linear task", { error: message });
|
|
1418
|
+
return {
|
|
1419
|
+
content: [
|
|
1420
|
+
{
|
|
1421
|
+
type: "text",
|
|
1422
|
+
text: `\u274C Failed to update Linear task: ${message}`
|
|
1423
|
+
}
|
|
1424
|
+
]
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
async handleLinearGetTasks(args) {
|
|
1429
|
+
try {
|
|
1430
|
+
const { LinearClient } = await import("../linear/client.js");
|
|
1431
|
+
const tokens = this.linearAuthManager.loadTokens();
|
|
1432
|
+
if (!tokens) {
|
|
1433
|
+
return {
|
|
1434
|
+
content: [
|
|
1435
|
+
{
|
|
1436
|
+
type: "text",
|
|
1437
|
+
text: "\u274C Linear not authenticated. Run: stackmemory linear setup"
|
|
1438
|
+
}
|
|
1439
|
+
]
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
const client = new LinearClient({
|
|
1443
|
+
apiKey: tokens.accessToken,
|
|
1444
|
+
useBearer: true,
|
|
1445
|
+
onUnauthorized: async () => {
|
|
1446
|
+
const refreshed = await this.linearAuthManager.refreshAccessToken();
|
|
1447
|
+
return refreshed.accessToken;
|
|
1448
|
+
}
|
|
1449
|
+
});
|
|
1450
|
+
let stateType = void 0;
|
|
1451
|
+
if (args.status && args.status !== "all") {
|
|
1452
|
+
const statusMap = {
|
|
1453
|
+
todo: "unstarted",
|
|
1454
|
+
"in-progress": "started",
|
|
1455
|
+
done: "completed"
|
|
1456
|
+
};
|
|
1457
|
+
stateType = statusMap[args.status] || args.status;
|
|
1458
|
+
}
|
|
1459
|
+
const issues = await client.getIssues({
|
|
1460
|
+
stateType,
|
|
1461
|
+
limit: args.limit || 20
|
|
1462
|
+
});
|
|
1463
|
+
if (!issues || issues.length === 0) {
|
|
1464
|
+
return {
|
|
1465
|
+
content: [
|
|
1466
|
+
{
|
|
1467
|
+
type: "text",
|
|
1468
|
+
text: "No Linear tasks found"
|
|
1469
|
+
}
|
|
1470
|
+
]
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
let response = `\u{1F4CB} **Linear Tasks** (${issues.length} items)
|
|
1474
|
+
|
|
1475
|
+
`;
|
|
1476
|
+
issues.forEach((issue) => {
|
|
1477
|
+
const priority = issue.priority ? `P${issue.priority}` : "-";
|
|
1478
|
+
response += `- **${issue.identifier}**: ${issue.title}
|
|
1479
|
+
`;
|
|
1480
|
+
response += ` Status: ${issue.state.name} | Priority: ${priority}
|
|
1481
|
+
`;
|
|
1482
|
+
if (issue.assignee) {
|
|
1483
|
+
response += ` Assignee: ${issue.assignee.name}
|
|
1484
|
+
`;
|
|
1485
|
+
}
|
|
1486
|
+
response += ` ${issue.url}
|
|
1487
|
+
|
|
1488
|
+
`;
|
|
1489
|
+
});
|
|
1490
|
+
return {
|
|
1491
|
+
content: [
|
|
1492
|
+
{
|
|
1493
|
+
type: "text",
|
|
1494
|
+
text: response
|
|
1495
|
+
}
|
|
1496
|
+
]
|
|
1497
|
+
};
|
|
1498
|
+
} catch (error) {
|
|
1499
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1500
|
+
logger.error("Failed to get Linear tasks", { error: message });
|
|
1501
|
+
return {
|
|
1502
|
+
content: [
|
|
1503
|
+
{
|
|
1504
|
+
type: "text",
|
|
1505
|
+
text: `\u274C Failed to get Linear tasks: ${message}`
|
|
1506
|
+
}
|
|
1507
|
+
]
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
async handleLinearStatus(_args) {
|
|
1512
|
+
try {
|
|
1513
|
+
const { LinearClient } = await import("../linear/client.js");
|
|
1514
|
+
const tokens = this.linearAuthManager.loadTokens();
|
|
1515
|
+
if (!tokens) {
|
|
1516
|
+
return {
|
|
1517
|
+
content: [
|
|
1518
|
+
{
|
|
1519
|
+
type: "text",
|
|
1520
|
+
text: "\u274C Linear integration not configured\nRun: stackmemory linear setup"
|
|
1521
|
+
}
|
|
1522
|
+
]
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
try {
|
|
1526
|
+
const client = new LinearClient({
|
|
1527
|
+
apiKey: tokens.accessToken,
|
|
1528
|
+
useBearer: true,
|
|
1529
|
+
onUnauthorized: async () => {
|
|
1530
|
+
const refreshed = await this.linearAuthManager.refreshAccessToken();
|
|
1531
|
+
return refreshed.accessToken;
|
|
1532
|
+
}
|
|
1533
|
+
});
|
|
1534
|
+
const viewer = await client.getViewer();
|
|
1535
|
+
const team = await client.getTeam();
|
|
1536
|
+
return {
|
|
1537
|
+
content: [
|
|
1538
|
+
{
|
|
1539
|
+
type: "text",
|
|
1540
|
+
text: `\u2705 **Linear Integration Status**
|
|
1541
|
+
|
|
1542
|
+
Connected as: ${viewer.name} (${viewer.email})
|
|
1543
|
+
Team: ${team.name} (${team.key})
|
|
1544
|
+
Tokens: Valid`
|
|
1545
|
+
}
|
|
1546
|
+
]
|
|
1547
|
+
};
|
|
1548
|
+
} catch (error) {
|
|
1549
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1550
|
+
return {
|
|
1551
|
+
content: [
|
|
1552
|
+
{
|
|
1553
|
+
type: "text",
|
|
1554
|
+
text: `\u26A0\uFE0F Linear configured but connection failed: ${message}`
|
|
1555
|
+
}
|
|
1556
|
+
]
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
} catch (error) {
|
|
1560
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1561
|
+
logger.error("Linear status check failed", { error: message });
|
|
1562
|
+
return {
|
|
1563
|
+
content: [
|
|
1564
|
+
{
|
|
1565
|
+
type: "text",
|
|
1566
|
+
text: `\u274C Linear status check failed: ${message}`
|
|
1567
|
+
}
|
|
1568
|
+
]
|
|
1569
|
+
};
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
async handleGetTraces(args) {
|
|
1573
|
+
const { type, minScore, limit = 20 } = args;
|
|
1574
|
+
this.traceDetector.flush();
|
|
1575
|
+
let traces = this.traceDetector.getTraces();
|
|
1576
|
+
if (type) {
|
|
1577
|
+
traces = traces.filter((t) => t.type === type);
|
|
1578
|
+
}
|
|
1579
|
+
if (minScore !== void 0) {
|
|
1580
|
+
traces = traces.filter((t) => t.score >= minScore);
|
|
1581
|
+
}
|
|
1582
|
+
traces = traces.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
1583
|
+
const formattedTraces = traces.map((trace) => ({
|
|
1584
|
+
id: trace.id,
|
|
1585
|
+
type: trace.type,
|
|
1586
|
+
score: trace.score.toFixed(2),
|
|
1587
|
+
summary: trace.summary,
|
|
1588
|
+
toolCount: trace.tools.length,
|
|
1589
|
+
duration: `${((trace.metadata.endTime - trace.metadata.startTime) / 1e3).toFixed(1)}s`,
|
|
1590
|
+
filesModified: trace.metadata.filesModified.length,
|
|
1591
|
+
hasErrors: trace.metadata.errorsEncountered.length > 0,
|
|
1592
|
+
compressed: !!trace.compressed
|
|
1593
|
+
}));
|
|
1594
|
+
return {
|
|
1595
|
+
content: [
|
|
1596
|
+
{
|
|
1597
|
+
type: "text",
|
|
1598
|
+
text: `Found ${formattedTraces.length} traces:
|
|
1599
|
+
|
|
1600
|
+
${formattedTraces.map(
|
|
1601
|
+
(t) => `[${t.type}] Score: ${t.score} | Tools: ${t.toolCount} | Duration: ${t.duration}
|
|
1602
|
+
${t.summary}`
|
|
1603
|
+
).join("\n\n")}`
|
|
1604
|
+
}
|
|
1605
|
+
]
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
async handleGetTraceStatistics(args) {
|
|
1609
|
+
this.traceDetector.flush();
|
|
1610
|
+
const stats = this.traceDetector.getStatistics();
|
|
1611
|
+
const typeBreakdown = Object.entries(stats.tracesByType).map(([type, count]) => ` ${type}: ${count}`).join("\n");
|
|
1612
|
+
return {
|
|
1613
|
+
content: [
|
|
1614
|
+
{
|
|
1615
|
+
type: "text",
|
|
1616
|
+
text: `**Trace Statistics**
|
|
1617
|
+
|
|
1618
|
+
Total Traces: ${stats.totalTraces}
|
|
1619
|
+
Average Score: ${stats.averageScore.toFixed(2)}
|
|
1620
|
+
Average Length: ${stats.averageLength.toFixed(1)} tools
|
|
1621
|
+
High Importance (>0.7): ${stats.highImportanceCount}
|
|
1622
|
+
Compressed: ${stats.compressedCount}
|
|
1623
|
+
|
|
1624
|
+
**Trace Types:**
|
|
1625
|
+
${typeBreakdown}`
|
|
1626
|
+
}
|
|
1627
|
+
]
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
async handleFlushTraces(args) {
|
|
1631
|
+
this.traceDetector.flush();
|
|
1632
|
+
return {
|
|
1633
|
+
content: [
|
|
1634
|
+
{
|
|
1635
|
+
type: "text",
|
|
1636
|
+
text: "Pending traces have been flushed and finalized."
|
|
1637
|
+
}
|
|
1638
|
+
]
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
async handleCompressOldTraces(args) {
|
|
1642
|
+
const { ageHours = 24 } = args;
|
|
1643
|
+
const compressedCount = this.traceDetector.compressOldTraces(ageHours);
|
|
1644
|
+
return {
|
|
1645
|
+
content: [
|
|
1646
|
+
{
|
|
1647
|
+
type: "text",
|
|
1648
|
+
text: `Compressed ${compressedCount} traces older than ${ageHours} hours.`
|
|
1649
|
+
}
|
|
1650
|
+
]
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
async handleSmartContext(args) {
|
|
1654
|
+
const { query: query2, tokenBudget = 4e3, forceRefresh = false } = args;
|
|
1655
|
+
try {
|
|
1656
|
+
const result = await this.contextRetrieval.retrieveContext(query2, {
|
|
1657
|
+
tokenBudget,
|
|
1658
|
+
forceRefresh
|
|
1659
|
+
});
|
|
1660
|
+
const currentFrameId = this.frameManager.getCurrentFrameId();
|
|
1661
|
+
if (currentFrameId) {
|
|
1662
|
+
this.frameManager.addEvent("observation", {
|
|
1663
|
+
action: "smart_context",
|
|
1664
|
+
query: query2,
|
|
1665
|
+
framesRetrieved: result.frames.length,
|
|
1666
|
+
tokenUsage: result.tokenUsage,
|
|
1667
|
+
confidence: result.analysis.confidenceScore
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
let response = result.context;
|
|
1671
|
+
response += `
|
|
1672
|
+
|
|
1673
|
+
---
|
|
1674
|
+
\u{1F4CA} **Retrieval Stats**
|
|
1675
|
+
`;
|
|
1676
|
+
response += `- Frames included: ${result.frames.length}
|
|
1677
|
+
`;
|
|
1678
|
+
response += `- Tokens used: ${result.tokenUsage.used}/${result.tokenUsage.budget}
|
|
1679
|
+
`;
|
|
1680
|
+
response += `- Confidence: ${(result.analysis.confidenceScore * 100).toFixed(0)}%
|
|
1681
|
+
`;
|
|
1682
|
+
response += `- Time: ${result.metadata.retrievalTimeMs}ms`;
|
|
1683
|
+
return {
|
|
1684
|
+
content: [
|
|
1685
|
+
{
|
|
1686
|
+
type: "text",
|
|
1687
|
+
text: response
|
|
1688
|
+
}
|
|
1689
|
+
]
|
|
1690
|
+
};
|
|
1691
|
+
} catch (error) {
|
|
1692
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1693
|
+
logger.error("Context retrieval failed", { error: message });
|
|
1694
|
+
return {
|
|
1695
|
+
content: [
|
|
1696
|
+
{
|
|
1697
|
+
type: "text",
|
|
1698
|
+
text: `\u274C Context retrieval failed: ${message}`
|
|
1699
|
+
}
|
|
1700
|
+
]
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
async handleGetSummary(args) {
|
|
1705
|
+
const { forceRefresh = false } = args;
|
|
1706
|
+
try {
|
|
1707
|
+
const summary = this.contextRetrieval.getSummary(forceRefresh);
|
|
1708
|
+
let response = "\u{1F4CB} **Compressed Memory Summary**\n\n";
|
|
1709
|
+
response += "## Recent Session\n";
|
|
1710
|
+
response += `- Frames: ${summary.recentSession.frames.length}
|
|
1711
|
+
`;
|
|
1712
|
+
response += `- Time range: ${new Date(summary.recentSession.timeRange.start).toLocaleString()} - ${new Date(summary.recentSession.timeRange.end).toLocaleString()}
|
|
1713
|
+
`;
|
|
1714
|
+
if (summary.recentSession.dominantOperations.length > 0) {
|
|
1715
|
+
response += `- Dominant ops: ${summary.recentSession.dominantOperations.slice(0, 5).map((o) => `${o.operation}(${o.count})`).join(", ")}
|
|
1716
|
+
`;
|
|
1717
|
+
}
|
|
1718
|
+
if (summary.recentSession.filesTouched.length > 0) {
|
|
1719
|
+
response += `- Files touched: ${summary.recentSession.filesTouched.slice(0, 5).map((f) => f.path).join(", ")}
|
|
1720
|
+
`;
|
|
1721
|
+
}
|
|
1722
|
+
if (summary.recentSession.errorsEncountered.length > 0) {
|
|
1723
|
+
response += `- Errors: ${summary.recentSession.errorsEncountered.length}
|
|
1724
|
+
`;
|
|
1725
|
+
}
|
|
1726
|
+
response += "\n## Historical Patterns\n";
|
|
1727
|
+
response += `- Topic counts: ${Object.keys(summary.historicalPatterns.topicFrameCounts).length} topics
|
|
1728
|
+
`;
|
|
1729
|
+
if (summary.historicalPatterns.keyDecisions.length > 0) {
|
|
1730
|
+
response += `
|
|
1731
|
+
### Key Decisions (${summary.historicalPatterns.keyDecisions.length})
|
|
1732
|
+
`;
|
|
1733
|
+
summary.historicalPatterns.keyDecisions.slice(0, 5).forEach((d) => {
|
|
1734
|
+
response += `- ${d.text.substring(0, 80)}${d.text.length > 80 ? "..." : ""}
|
|
1735
|
+
`;
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
if (summary.historicalPatterns.recurringIssues.length > 0) {
|
|
1739
|
+
response += `
|
|
1740
|
+
### Recurring Issues (${summary.historicalPatterns.recurringIssues.length})
|
|
1741
|
+
`;
|
|
1742
|
+
summary.historicalPatterns.recurringIssues.slice(0, 3).forEach((i) => {
|
|
1743
|
+
response += `- ${i.issueType} (${i.occurrenceCount} times)
|
|
1744
|
+
`;
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
response += "\n## Available Indices\n";
|
|
1748
|
+
response += `- By time: ${Object.keys(summary.queryableIndices.byTimeframe).length} periods
|
|
1749
|
+
`;
|
|
1750
|
+
response += `- By file: ${Object.keys(summary.queryableIndices.byFile).length} files
|
|
1751
|
+
`;
|
|
1752
|
+
response += `- By topic: ${Object.keys(summary.queryableIndices.byTopic).length} topics
|
|
1753
|
+
`;
|
|
1754
|
+
response += `- By error: ${Object.keys(summary.queryableIndices.byErrorType).length} error types
|
|
1755
|
+
`;
|
|
1756
|
+
response += `
|
|
1757
|
+
## Stats
|
|
1758
|
+
`;
|
|
1759
|
+
response += `- Total frames: ${summary.stats.totalFrames}
|
|
1760
|
+
`;
|
|
1761
|
+
response += `- Total anchors: ${summary.stats.totalAnchors}
|
|
1762
|
+
`;
|
|
1763
|
+
response += `- Total events: ${summary.stats.totalEvents}
|
|
1764
|
+
`;
|
|
1765
|
+
response += `- Generated: ${new Date(summary.generatedAt).toLocaleString()}`;
|
|
1766
|
+
return {
|
|
1767
|
+
content: [
|
|
1768
|
+
{
|
|
1769
|
+
type: "text",
|
|
1770
|
+
text: response
|
|
1771
|
+
}
|
|
1772
|
+
]
|
|
1773
|
+
};
|
|
1774
|
+
} catch (error) {
|
|
1775
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1776
|
+
logger.error("Failed to get summary", { error: message });
|
|
1777
|
+
return {
|
|
1778
|
+
content: [
|
|
1779
|
+
{
|
|
1780
|
+
type: "text",
|
|
1781
|
+
text: `\u274C Failed to get summary: ${message}`
|
|
1782
|
+
}
|
|
1783
|
+
]
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
// ============================================
|
|
1788
|
+
// Discovery Tools Handlers
|
|
1789
|
+
// ============================================
|
|
1790
|
+
async handleSmDiscover(args) {
|
|
1791
|
+
return this.discoveryHandlers.handleDiscover(args);
|
|
1792
|
+
}
|
|
1793
|
+
async handleSmRelatedFiles(args) {
|
|
1794
|
+
return this.discoveryHandlers.handleRelatedFiles(args);
|
|
1795
|
+
}
|
|
1796
|
+
async handleSmSessionSummary(args) {
|
|
1797
|
+
return this.discoveryHandlers.handleSessionSummary(args);
|
|
1798
|
+
}
|
|
1799
|
+
async handleSmSearch(args) {
|
|
1800
|
+
try {
|
|
1801
|
+
const { query: query2, scope: scope2 = "all", limit = 20 } = args;
|
|
1802
|
+
if (!query2) {
|
|
1803
|
+
throw new Error("Query is required");
|
|
1804
|
+
}
|
|
1805
|
+
const results = [];
|
|
1806
|
+
if (scope2 === "all" || scope2 === "frames") {
|
|
1807
|
+
const frames = this.db.prepare(
|
|
1808
|
+
`
|
|
1809
|
+
SELECT frame_id, name, type, created_at, inputs, outputs
|
|
1810
|
+
FROM frames
|
|
1811
|
+
WHERE project_id = ? AND (name LIKE ? OR inputs LIKE ? OR outputs LIKE ?)
|
|
1812
|
+
ORDER BY created_at DESC
|
|
1813
|
+
LIMIT ?
|
|
1814
|
+
`
|
|
1815
|
+
).all(
|
|
1816
|
+
this.projectId,
|
|
1817
|
+
`%${query2}%`,
|
|
1818
|
+
`%${query2}%`,
|
|
1819
|
+
`%${query2}%`,
|
|
1820
|
+
limit
|
|
1821
|
+
);
|
|
1822
|
+
frames.forEach((f) => {
|
|
1823
|
+
results.push({
|
|
1824
|
+
type: "frame",
|
|
1825
|
+
id: f.frame_id,
|
|
1826
|
+
name: f.name,
|
|
1827
|
+
frameType: f.type,
|
|
1828
|
+
created: new Date(f.created_at * 1e3).toISOString()
|
|
1829
|
+
});
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
if (scope2 === "all" || scope2 === "events") {
|
|
1833
|
+
const events = this.db.prepare(
|
|
1834
|
+
`
|
|
1835
|
+
SELECT e.event_id, e.type, e.data, e.timestamp, f.name as frame_name
|
|
1836
|
+
FROM events e
|
|
1837
|
+
JOIN frames f ON e.frame_id = f.frame_id
|
|
1838
|
+
WHERE f.project_id = ? AND e.data LIKE ?
|
|
1839
|
+
ORDER BY e.timestamp DESC
|
|
1840
|
+
LIMIT ?
|
|
1841
|
+
`
|
|
1842
|
+
).all(this.projectId, `%${query2}%`, limit);
|
|
1843
|
+
events.forEach((e) => {
|
|
1844
|
+
results.push({
|
|
1845
|
+
type: "event",
|
|
1846
|
+
id: e.event_id,
|
|
1847
|
+
eventType: e.type,
|
|
1848
|
+
frame: e.frame_name,
|
|
1849
|
+
timestamp: new Date(e.timestamp * 1e3).toISOString()
|
|
1850
|
+
});
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
if (scope2 === "all" || scope2 === "decisions") {
|
|
1854
|
+
const anchors = this.db.prepare(
|
|
1855
|
+
`
|
|
1856
|
+
SELECT a.anchor_id, a.type, a.text, a.priority, a.created_at, f.name as frame_name
|
|
1857
|
+
FROM anchors a
|
|
1858
|
+
JOIN frames f ON a.frame_id = f.frame_id
|
|
1859
|
+
WHERE f.project_id = ? AND a.text LIKE ?
|
|
1860
|
+
ORDER BY a.created_at DESC
|
|
1861
|
+
LIMIT ?
|
|
1862
|
+
`
|
|
1863
|
+
).all(this.projectId, `%${query2}%`, limit);
|
|
1864
|
+
anchors.forEach((a) => {
|
|
1865
|
+
results.push({
|
|
1866
|
+
type: "decision",
|
|
1867
|
+
id: a.anchor_id,
|
|
1868
|
+
decisionType: a.type,
|
|
1869
|
+
text: a.text,
|
|
1870
|
+
priority: a.priority,
|
|
1871
|
+
frame: a.frame_name
|
|
1872
|
+
});
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1875
|
+
if (scope2 === "all" || scope2 === "tasks") {
|
|
1876
|
+
try {
|
|
1877
|
+
const tasks = this.db.prepare(
|
|
1878
|
+
`
|
|
1879
|
+
SELECT id, title, description, status, priority
|
|
1880
|
+
FROM task_cache
|
|
1881
|
+
WHERE title LIKE ? OR description LIKE ?
|
|
1882
|
+
ORDER BY created_at DESC
|
|
1883
|
+
LIMIT ?
|
|
1884
|
+
`
|
|
1885
|
+
).all(`%${query2}%`, `%${query2}%`, limit);
|
|
1886
|
+
tasks.forEach((t) => {
|
|
1887
|
+
results.push({
|
|
1888
|
+
type: "task",
|
|
1889
|
+
id: t.id,
|
|
1890
|
+
title: t.title,
|
|
1891
|
+
status: t.status,
|
|
1892
|
+
priority: t.priority
|
|
1893
|
+
});
|
|
1894
|
+
});
|
|
1895
|
+
} catch {
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
let response = `# Search Results for "${query2}"
|
|
1899
|
+
|
|
1900
|
+
`;
|
|
1901
|
+
response += `Found ${results.length} results
|
|
1902
|
+
|
|
1903
|
+
`;
|
|
1904
|
+
const grouped = results.reduce(
|
|
1905
|
+
(acc, r) => {
|
|
1906
|
+
if (!acc[r.type]) acc[r.type] = [];
|
|
1907
|
+
acc[r.type].push(r);
|
|
1908
|
+
return acc;
|
|
1909
|
+
},
|
|
1910
|
+
{}
|
|
1911
|
+
);
|
|
1912
|
+
for (const [type, items] of Object.entries(grouped)) {
|
|
1913
|
+
response += `## ${type.charAt(0).toUpperCase() + type.slice(1)}s (${items.length})
|
|
1914
|
+
`;
|
|
1915
|
+
for (const item of items.slice(0, 10)) {
|
|
1916
|
+
if (type === "frame") {
|
|
1917
|
+
response += `- [${item.frameType}] ${item.name}
|
|
1918
|
+
`;
|
|
1919
|
+
} else if (type === "decision") {
|
|
1920
|
+
response += `- [${item.decisionType}] ${item.text.slice(0, 60)}...
|
|
1921
|
+
`;
|
|
1922
|
+
} else if (type === "task") {
|
|
1923
|
+
response += `- [${item.status}] ${item.title}
|
|
1924
|
+
`;
|
|
1925
|
+
} else {
|
|
1926
|
+
response += `- ${JSON.stringify(item).slice(0, 80)}...
|
|
1927
|
+
`;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
response += "\n";
|
|
1931
|
+
}
|
|
1932
|
+
return {
|
|
1933
|
+
content: [
|
|
1934
|
+
{
|
|
1935
|
+
type: "text",
|
|
1936
|
+
text: response
|
|
1937
|
+
}
|
|
1938
|
+
],
|
|
1939
|
+
metadata: { results, query: query2, scope: scope2 }
|
|
1940
|
+
};
|
|
1941
|
+
} catch (error) {
|
|
1942
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1943
|
+
logger.error("Search failed", { error: message, query, scope });
|
|
1944
|
+
return {
|
|
1945
|
+
content: [
|
|
1946
|
+
{
|
|
1947
|
+
type: "text",
|
|
1948
|
+
text: `\u274C Search failed: ${message}`
|
|
1949
|
+
}
|
|
1950
|
+
]
|
|
1951
|
+
};
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
async start() {
|
|
1955
|
+
const transport = new StdioServerTransport();
|
|
1956
|
+
await this.server.connect(transport);
|
|
1957
|
+
console.error("StackMemory MCP Server started");
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
var server_default = LocalStackMemoryMCP;
|
|
1961
|
+
async function runMCPServer() {
|
|
1962
|
+
const server = new LocalStackMemoryMCP();
|
|
1963
|
+
await server.start();
|
|
1964
|
+
}
|
|
1965
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
1966
|
+
const server = new LocalStackMemoryMCP();
|
|
1967
|
+
server.start().catch(console.error);
|
|
1968
|
+
}
|
|
1969
|
+
export {
|
|
1970
|
+
TaskPriority,
|
|
1971
|
+
TaskStatus,
|
|
1972
|
+
server_default as default,
|
|
1973
|
+
runMCPServer
|
|
1974
|
+
};
|
|
1975
|
+
//# sourceMappingURL=server.js.map
|