@stackmemoryai/stackmemory 0.5.57 → 0.5.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/codex-smd +6 -0
- package/dist/cli/codex-sm-danger.js +21 -0
- package/dist/cli/codex-sm-danger.js.map +7 -0
- package/dist/cli/commands/handoff.js +33 -3
- package/dist/cli/commands/handoff.js.map +2 -2
- package/dist/cli/commands/search.js +20 -3
- package/dist/cli/commands/search.js.map +2 -2
- package/dist/core/database/sqlite-adapter.js +13 -3
- package/dist/core/database/sqlite-adapter.js.map +2 -2
- package/dist/core/errors/error-utils.js +208 -0
- package/dist/core/errors/error-utils.js.map +7 -0
- package/dist/core/errors/index.js +13 -4
- package/dist/core/errors/index.js.map +2 -2
- package/dist/core/merge/unified-merge-resolver.js +303 -0
- package/dist/core/merge/unified-merge-resolver.js.map +7 -0
- package/dist/core/monitoring/logger.js +61 -9
- package/dist/core/monitoring/logger.js.map +2 -2
- package/dist/core/security/index.js +35 -0
- package/dist/core/security/index.js.map +7 -0
- package/dist/core/security/input-sanitizer.js +321 -0
- package/dist/core/security/input-sanitizer.js.map +7 -0
- package/dist/core/session/enhanced-handoff.js +136 -2
- package/dist/core/session/enhanced-handoff.js.map +3 -3
- package/dist/integrations/linear/client.js +5 -1
- package/dist/integrations/linear/client.js.map +2 -2
- package/dist/integrations/mcp/remote-server.js +27 -36
- package/dist/integrations/mcp/remote-server.js.map +2 -2
- package/dist/integrations/mcp/server.js +44 -29
- package/dist/integrations/mcp/server.js.map +3 -3
- package/dist/scripts/benchmark-performance.js +48 -0
- package/dist/scripts/benchmark-performance.js.map +7 -0
- package/dist/scripts/check-redis.js +42 -0
- package/dist/scripts/check-redis.js.map +7 -0
- package/dist/scripts/initialize.js +116 -0
- package/dist/scripts/initialize.js.map +7 -0
- package/dist/scripts/list-linear-tasks.js +124 -0
- package/dist/scripts/list-linear-tasks.js.map +7 -0
- package/dist/scripts/measure-handoff-impact.js +340 -0
- package/dist/scripts/measure-handoff-impact.js.map +7 -0
- package/dist/scripts/query-chromadb.js +160 -0
- package/dist/scripts/query-chromadb.js.map +7 -0
- package/dist/scripts/show-linear-summary.js +119 -0
- package/dist/scripts/show-linear-summary.js.map +7 -0
- package/dist/scripts/simple-swarm-demo.js +90 -0
- package/dist/scripts/simple-swarm-demo.js.map +7 -0
- package/dist/scripts/status.js +155 -0
- package/dist/scripts/status.js.map +7 -0
- package/dist/scripts/test-chromadb-sync.js +192 -0
- package/dist/scripts/test-chromadb-sync.js.map +7 -0
- package/dist/scripts/test-ralph-iteration-fix.js +86 -0
- package/dist/scripts/test-ralph-iteration-fix.js.map +7 -0
- package/dist/scripts/test-ralph-iterations.js +121 -0
- package/dist/scripts/test-ralph-iterations.js.map +7 -0
- package/dist/scripts/test-redis-storage.js +389 -0
- package/dist/scripts/test-redis-storage.js.map +7 -0
- package/dist/scripts/test-simple-ralph-state-sync.js +115 -0
- package/dist/scripts/test-simple-ralph-state-sync.js.map +7 -0
- package/dist/scripts/test-swarm-fixes.js +125 -0
- package/dist/scripts/test-swarm-fixes.js.map +7 -0
- package/dist/scripts/test-swarm-tui.js +23 -0
- package/dist/scripts/test-swarm-tui.js.map +7 -0
- package/dist/scripts/test-tui-shortcuts.js +52 -0
- package/dist/scripts/test-tui-shortcuts.js.map +7 -0
- package/dist/scripts/validate-tui-shortcuts.js +60 -0
- package/dist/scripts/validate-tui-shortcuts.js.map +7 -0
- package/dist/src/agents/core/agent-task-manager.js +527 -0
- package/dist/src/agents/core/agent-task-manager.js.map +7 -0
- package/dist/src/agents/verifiers/base-verifier.js +133 -0
- package/dist/src/agents/verifiers/base-verifier.js.map +7 -0
- package/dist/src/agents/verifiers/formatter-verifier.js +130 -0
- package/dist/src/agents/verifiers/formatter-verifier.js.map +7 -0
- package/dist/src/agents/verifiers/llm-judge.js +252 -0
- package/dist/src/agents/verifiers/llm-judge.js.map +7 -0
- package/dist/src/cli/auto-detect.js +321 -0
- package/dist/src/cli/auto-detect.js.map +7 -0
- package/dist/src/cli/claude-sm-danger.js +21 -0
- package/dist/src/cli/claude-sm-danger.js.map +7 -0
- package/dist/src/cli/claude-sm.js +1156 -0
- package/dist/src/cli/claude-sm.js.map +7 -0
- package/dist/src/cli/codex-sm-danger.js +21 -0
- package/dist/src/cli/codex-sm-danger.js.map +7 -0
- package/dist/src/cli/codex-sm.js +349 -0
- package/dist/src/cli/codex-sm.js.map +7 -0
- package/dist/src/cli/commands/api.js +232 -0
- package/dist/src/cli/commands/api.js.map +7 -0
- package/dist/src/cli/commands/auto-background.js +180 -0
- package/dist/src/cli/commands/auto-background.js.map +7 -0
- package/dist/src/cli/commands/cleanup-processes.js +68 -0
- package/dist/src/cli/commands/cleanup-processes.js.map +7 -0
- package/dist/src/cli/commands/clear.js +202 -0
- package/dist/src/cli/commands/clear.js.map +7 -0
- package/dist/src/cli/commands/config.js +445 -0
- package/dist/src/cli/commands/config.js.map +7 -0
- package/dist/src/cli/commands/context-rehydrate.js +751 -0
- package/dist/src/cli/commands/context-rehydrate.js.map +7 -0
- package/dist/src/cli/commands/context.js +343 -0
- package/dist/src/cli/commands/context.js.map +7 -0
- package/dist/src/cli/commands/daemon.js +392 -0
- package/dist/src/cli/commands/daemon.js.map +7 -0
- package/dist/src/cli/commands/dashboard.js +210 -0
- package/dist/src/cli/commands/dashboard.js.map +7 -0
- package/dist/src/cli/commands/db.js +147 -0
- package/dist/src/cli/commands/db.js.map +7 -0
- package/dist/src/cli/commands/decision.js +266 -0
- package/dist/src/cli/commands/decision.js.map +7 -0
- package/dist/src/cli/commands/discovery.js +279 -0
- package/dist/src/cli/commands/discovery.js.map +7 -0
- package/dist/src/cli/commands/handoff.js +624 -0
- package/dist/src/cli/commands/handoff.js.map +7 -0
- package/dist/src/cli/commands/hooks.js +298 -0
- package/dist/src/cli/commands/hooks.js.map +7 -0
- package/dist/src/cli/commands/linear.js +529 -0
- package/dist/src/cli/commands/linear.js.map +7 -0
- package/dist/src/cli/commands/log.js +169 -0
- package/dist/src/cli/commands/log.js.map +7 -0
- package/dist/src/cli/commands/login.js +172 -0
- package/dist/src/cli/commands/login.js.map +7 -0
- package/dist/src/cli/commands/migrate.js +240 -0
- package/dist/src/cli/commands/migrate.js.map +7 -0
- package/dist/src/cli/commands/model.js +533 -0
- package/dist/src/cli/commands/model.js.map +7 -0
- package/dist/src/cli/commands/onboard.js +536 -0
- package/dist/src/cli/commands/onboard.js.map +7 -0
- package/dist/src/cli/commands/projects.js +199 -0
- package/dist/src/cli/commands/projects.js.map +7 -0
- package/dist/src/cli/commands/ralph.js +909 -0
- package/dist/src/cli/commands/ralph.js.map +7 -0
- package/dist/src/cli/commands/retrieval.js +248 -0
- package/dist/src/cli/commands/retrieval.js.map +7 -0
- package/dist/src/cli/commands/search.js +173 -0
- package/dist/src/cli/commands/search.js.map +7 -0
- package/dist/src/cli/commands/service.js +749 -0
- package/dist/src/cli/commands/service.js.map +7 -0
- package/dist/src/cli/commands/session.js +200 -0
- package/dist/src/cli/commands/session.js.map +7 -0
- package/dist/src/cli/commands/settings.js +306 -0
- package/dist/src/cli/commands/settings.js.map +7 -0
- package/dist/src/cli/commands/setup.js +701 -0
- package/dist/src/cli/commands/setup.js.map +7 -0
- package/dist/src/cli/commands/shell.js +249 -0
- package/dist/src/cli/commands/shell.js.map +7 -0
- package/dist/src/cli/commands/signup.js +50 -0
- package/dist/src/cli/commands/signup.js.map +7 -0
- package/dist/src/cli/commands/skills.js +470 -0
- package/dist/src/cli/commands/skills.js.map +7 -0
- package/dist/src/cli/commands/sms-notify.js +795 -0
- package/dist/src/cli/commands/sms-notify.js.map +7 -0
- package/dist/src/cli/commands/storage-tier.js +183 -0
- package/dist/src/cli/commands/storage-tier.js.map +7 -0
- package/dist/src/cli/commands/sweep.js +249 -0
- package/dist/src/cli/commands/sweep.js.map +7 -0
- package/dist/src/cli/commands/tasks.js +213 -0
- package/dist/src/cli/commands/tasks.js.map +7 -0
- package/dist/src/cli/commands/worktree.js +319 -0
- package/dist/src/cli/commands/worktree.js.map +7 -0
- package/dist/src/cli/index.js +594 -0
- package/dist/src/cli/index.js.map +7 -0
- package/dist/src/cli/opencode-sm.js +448 -0
- package/dist/src/cli/opencode-sm.js.map +7 -0
- package/dist/src/cli/utils/viewer.js +96 -0
- package/dist/src/cli/utils/viewer.js.map +7 -0
- package/dist/src/core/config/config-manager.js +398 -0
- package/dist/src/core/config/config-manager.js.map +7 -0
- package/dist/src/core/config/feature-flags.js +76 -0
- package/dist/src/core/config/feature-flags.js.map +7 -0
- package/dist/src/core/config/storage-config.js +115 -0
- package/dist/src/core/config/storage-config.js.map +7 -0
- package/dist/src/core/config/types.js +144 -0
- package/dist/src/core/config/types.js.map +7 -0
- package/dist/src/core/context/auto-context.js +80 -0
- package/dist/src/core/context/auto-context.js.map +7 -0
- package/dist/src/core/context/dual-stack-manager.js +870 -0
- package/dist/src/core/context/dual-stack-manager.js.map +7 -0
- package/dist/src/core/context/enhanced-rehydration.js +994 -0
- package/dist/src/core/context/enhanced-rehydration.js.map +7 -0
- package/dist/src/core/context/frame-database.js +479 -0
- package/dist/src/core/context/frame-database.js.map +7 -0
- package/dist/src/core/context/frame-digest.js +250 -0
- package/dist/src/core/context/frame-digest.js.map +7 -0
- package/dist/src/core/context/frame-handoff-manager.js +778 -0
- package/dist/src/core/context/frame-handoff-manager.js.map +7 -0
- package/dist/src/core/context/frame-lifecycle-hooks.js +119 -0
- package/dist/src/core/context/frame-lifecycle-hooks.js.map +7 -0
- package/dist/src/core/context/frame-recovery.js +302 -0
- package/dist/src/core/context/frame-recovery.js.map +7 -0
- package/dist/src/core/context/frame-stack.js +314 -0
- package/dist/src/core/context/frame-stack.js.map +7 -0
- package/dist/src/core/context/frame-types.js +5 -0
- package/dist/src/core/context/frame-types.js.map +7 -0
- package/dist/src/core/context/index.js +25 -0
- package/dist/src/core/context/index.js.map +7 -0
- package/dist/src/core/context/permission-manager.js +185 -0
- package/dist/src/core/context/permission-manager.js.map +7 -0
- package/dist/src/core/context/recursive-context-manager.js +592 -0
- package/dist/src/core/context/recursive-context-manager.js.map +7 -0
- package/dist/src/core/context/refactored-frame-manager.js +754 -0
- package/dist/src/core/context/refactored-frame-manager.js.map +7 -0
- package/dist/src/core/context/shared-context-layer.js +621 -0
- package/dist/src/core/context/shared-context-layer.js.map +7 -0
- package/dist/src/core/context/stack-merge-resolver.js +749 -0
- package/dist/src/core/context/stack-merge-resolver.js.map +7 -0
- package/dist/src/core/context/validation.js +130 -0
- package/dist/src/core/context/validation.js.map +7 -0
- package/dist/src/core/database/batch-operations.js +384 -0
- package/dist/src/core/database/batch-operations.js.map +7 -0
- package/dist/src/core/database/connection-pool.js +330 -0
- package/dist/src/core/database/connection-pool.js.map +7 -0
- package/dist/src/core/database/database-adapter.js +60 -0
- package/dist/src/core/database/database-adapter.js.map +7 -0
- package/dist/src/core/database/migration-manager.js +614 -0
- package/dist/src/core/database/migration-manager.js.map +7 -0
- package/dist/src/core/database/query-cache.js +298 -0
- package/dist/src/core/database/query-cache.js.map +7 -0
- package/dist/src/core/database/query-router.js +430 -0
- package/dist/src/core/database/query-router.js.map +7 -0
- package/dist/src/core/database/sqlite-adapter.js +738 -0
- package/dist/src/core/database/sqlite-adapter.js.map +7 -0
- package/dist/src/core/digest/enhanced-hybrid-digest.js +277 -0
- package/dist/src/core/digest/enhanced-hybrid-digest.js.map +7 -0
- package/dist/src/core/digest/frame-digest-integration.js +176 -0
- package/dist/src/core/digest/frame-digest-integration.js.map +7 -0
- package/dist/src/core/digest/hybrid-digest-generator.js +553 -0
- package/dist/src/core/digest/hybrid-digest-generator.js.map +7 -0
- package/dist/src/core/digest/index.js +9 -0
- package/dist/src/core/digest/index.js.map +7 -0
- package/dist/src/core/digest/types.js +25 -0
- package/dist/src/core/digest/types.js.map +7 -0
- package/dist/src/core/errors/error-utils.js +208 -0
- package/dist/src/core/errors/error-utils.js.map +7 -0
- package/dist/src/core/errors/index.js +521 -0
- package/dist/src/core/errors/index.js.map +7 -0
- package/dist/src/core/errors/recovery.js +269 -0
- package/dist/src/core/errors/recovery.js.map +7 -0
- package/dist/src/core/execution/parallel-executor.js +258 -0
- package/dist/src/core/execution/parallel-executor.js.map +7 -0
- package/dist/src/core/frame/workflow-templates.js +319 -0
- package/dist/src/core/frame/workflow-templates.js.map +7 -0
- package/dist/src/core/merge/conflict-detector.js +431 -0
- package/dist/src/core/merge/conflict-detector.js.map +7 -0
- package/dist/src/core/merge/index.js +9 -0
- package/dist/src/core/merge/index.js.map +7 -0
- package/dist/src/core/merge/resolution-engine.js +558 -0
- package/dist/src/core/merge/resolution-engine.js.map +7 -0
- package/dist/src/core/merge/stack-diff.js +532 -0
- package/dist/src/core/merge/stack-diff.js.map +7 -0
- package/dist/src/core/merge/types.js +5 -0
- package/dist/src/core/merge/types.js.map +7 -0
- package/dist/src/core/merge/unified-merge-resolver.js +303 -0
- package/dist/src/core/merge/unified-merge-resolver.js.map +7 -0
- package/dist/src/core/models/fallback-monitor.js +232 -0
- package/dist/src/core/models/fallback-monitor.js.map +7 -0
- package/dist/src/core/models/model-router.js +340 -0
- package/dist/src/core/models/model-router.js.map +7 -0
- package/dist/src/core/monitoring/error-handler.js +49 -0
- package/dist/src/core/monitoring/error-handler.js.map +7 -0
- package/dist/src/core/monitoring/logger.js +202 -0
- package/dist/src/core/monitoring/logger.js.map +7 -0
- package/dist/src/core/monitoring/metrics.js +172 -0
- package/dist/src/core/monitoring/metrics.js.map +7 -0
- package/dist/src/core/monitoring/progress-tracker.js +189 -0
- package/dist/src/core/monitoring/progress-tracker.js.map +7 -0
- package/dist/src/core/monitoring/session-monitor.js +300 -0
- package/dist/src/core/monitoring/session-monitor.js.map +7 -0
- package/dist/src/core/performance/context-cache.js +273 -0
- package/dist/src/core/performance/context-cache.js.map +7 -0
- package/dist/src/core/performance/index.js +11 -0
- package/dist/src/core/performance/index.js.map +7 -0
- package/dist/src/core/performance/lazy-context-loader.js +327 -0
- package/dist/src/core/performance/lazy-context-loader.js.map +7 -0
- package/dist/src/core/performance/monitor.js +221 -0
- package/dist/src/core/performance/monitor.js.map +7 -0
- package/dist/src/core/performance/optimized-frame-context.js +345 -0
- package/dist/src/core/performance/optimized-frame-context.js.map +7 -0
- package/dist/src/core/performance/performance-benchmark.js +277 -0
- package/dist/src/core/performance/performance-benchmark.js.map +7 -0
- package/dist/src/core/performance/performance-profiler.js +370 -0
- package/dist/src/core/performance/performance-profiler.js.map +7 -0
- package/dist/src/core/performance/streaming-jsonl-parser.js +195 -0
- package/dist/src/core/performance/streaming-jsonl-parser.js.map +7 -0
- package/dist/src/core/persistence/postgres-adapter.js +349 -0
- package/dist/src/core/persistence/postgres-adapter.js.map +7 -0
- package/dist/src/core/projects/project-isolation.js +201 -0
- package/dist/src/core/projects/project-isolation.js.map +7 -0
- package/dist/src/core/projects/project-manager.js +697 -0
- package/dist/src/core/projects/project-manager.js.map +7 -0
- package/dist/src/core/query/query-parser.js +370 -0
- package/dist/src/core/query/query-parser.js.map +7 -0
- package/dist/src/core/query/query-templates.js +321 -0
- package/dist/src/core/query/query-templates.js.map +7 -0
- package/dist/src/core/retrieval/context-retriever.js +479 -0
- package/dist/src/core/retrieval/context-retriever.js.map +7 -0
- package/dist/src/core/retrieval/index.js +8 -0
- package/dist/src/core/retrieval/index.js.map +7 -0
- package/dist/src/core/retrieval/llm-context-retrieval.js +613 -0
- package/dist/src/core/retrieval/llm-context-retrieval.js.map +7 -0
- package/dist/src/core/retrieval/llm-provider.js +151 -0
- package/dist/src/core/retrieval/llm-provider.js.map +7 -0
- package/dist/src/core/retrieval/retrieval-audit.js +236 -0
- package/dist/src/core/retrieval/retrieval-audit.js.map +7 -0
- package/dist/src/core/retrieval/summary-generator.js +589 -0
- package/dist/src/core/retrieval/summary-generator.js.map +7 -0
- package/dist/src/core/retrieval/types.js +21 -0
- package/dist/src/core/retrieval/types.js.map +7 -0
- package/dist/src/core/security/index.js +35 -0
- package/dist/src/core/security/index.js.map +7 -0
- package/dist/src/core/security/input-sanitizer.js +321 -0
- package/dist/src/core/security/input-sanitizer.js.map +7 -0
- package/dist/src/core/session/clear-survival.js +465 -0
- package/dist/src/core/session/clear-survival.js.map +7 -0
- package/dist/src/core/session/enhanced-handoff.js +792 -0
- package/dist/src/core/session/enhanced-handoff.js.map +7 -0
- package/dist/src/core/session/handoff-generator.js +343 -0
- package/dist/src/core/session/handoff-generator.js.map +7 -0
- package/dist/src/core/session/index.js +15 -0
- package/dist/src/core/session/index.js.map +7 -0
- package/dist/src/core/session/session-manager.js +347 -0
- package/dist/src/core/session/session-manager.js.map +7 -0
- package/dist/src/core/skills/index.js +7 -0
- package/dist/src/core/skills/index.js.map +7 -0
- package/dist/src/core/skills/skill-storage.js +764 -0
- package/dist/src/core/skills/skill-storage.js.map +7 -0
- package/dist/src/core/skills/types.js +193 -0
- package/dist/src/core/skills/types.js.map +7 -0
- package/dist/src/core/storage/chromadb-adapter.js +354 -0
- package/dist/src/core/storage/chromadb-adapter.js.map +7 -0
- package/dist/src/core/storage/infinite-storage.js +510 -0
- package/dist/src/core/storage/infinite-storage.js.map +7 -0
- package/dist/src/core/storage/remote-storage.js +489 -0
- package/dist/src/core/storage/remote-storage.js.map +7 -0
- package/dist/src/core/storage/two-tier-storage.js +766 -0
- package/dist/src/core/storage/two-tier-storage.js.map +7 -0
- package/dist/src/core/trace/cli-trace-wrapper.js +132 -0
- package/dist/src/core/trace/cli-trace-wrapper.js.map +7 -0
- package/dist/src/core/trace/db-trace-wrapper.js +247 -0
- package/dist/src/core/trace/db-trace-wrapper.js.map +7 -0
- package/dist/src/core/trace/debug-trace.js +417 -0
- package/dist/src/core/trace/debug-trace.js.map +7 -0
- package/dist/src/core/trace/index.js +109 -0
- package/dist/src/core/trace/index.js.map +7 -0
- package/dist/src/core/trace/linear-api-wrapper.js +178 -0
- package/dist/src/core/trace/linear-api-wrapper.js.map +7 -0
- package/dist/src/core/trace/trace-detector.js +528 -0
- package/dist/src/core/trace/trace-detector.js.map +7 -0
- package/dist/src/core/trace/trace-store.js +345 -0
- package/dist/src/core/trace/trace-store.js.map +7 -0
- package/dist/src/core/trace/types.js +77 -0
- package/dist/src/core/trace/types.js.map +7 -0
- package/dist/src/core/types.js +5 -0
- package/dist/src/core/types.js.map +7 -0
- package/dist/src/core/utils/async-mutex.js +114 -0
- package/dist/src/core/utils/async-mutex.js.map +7 -0
- package/dist/src/core/utils/compression.js +83 -0
- package/dist/src/core/utils/compression.js.map +7 -0
- package/dist/src/core/utils/update-checker.js +218 -0
- package/dist/src/core/utils/update-checker.js.map +7 -0
- package/dist/src/core/worktree/worktree-manager.js +465 -0
- package/dist/src/core/worktree/worktree-manager.js.map +7 -0
- package/dist/src/daemon/daemon-config.js +149 -0
- package/dist/src/daemon/daemon-config.js.map +7 -0
- package/dist/src/daemon/services/context-service.js +122 -0
- package/dist/src/daemon/services/context-service.js.map +7 -0
- package/dist/src/daemon/services/linear-service.js +136 -0
- package/dist/src/daemon/services/linear-service.js.map +7 -0
- package/dist/src/daemon/session-daemon.js +312 -0
- package/dist/src/daemon/session-daemon.js.map +7 -0
- package/dist/src/daemon/unified-daemon.js +276 -0
- package/dist/src/daemon/unified-daemon.js.map +7 -0
- package/dist/src/features/analytics/api/analytics-api.js +287 -0
- package/dist/src/features/analytics/api/analytics-api.js.map +7 -0
- package/dist/src/features/analytics/core/analytics-service.js +282 -0
- package/dist/src/features/analytics/core/analytics-service.js.map +7 -0
- package/dist/src/features/analytics/index.js +18 -0
- package/dist/src/features/analytics/index.js.map +7 -0
- package/dist/src/features/analytics/queries/metrics-queries.js +277 -0
- package/dist/src/features/analytics/queries/metrics-queries.js.map +7 -0
- package/dist/src/features/analytics/types/metrics.js +5 -0
- package/dist/src/features/analytics/types/metrics.js.map +7 -0
- package/dist/src/features/browser/browser-mcp.js +492 -0
- package/dist/src/features/browser/browser-mcp.js.map +7 -0
- package/dist/src/features/sweep/index.js +20 -0
- package/dist/src/features/sweep/index.js.map +7 -0
- package/dist/src/features/sweep/prediction-client.js +155 -0
- package/dist/src/features/sweep/prediction-client.js.map +7 -0
- package/dist/src/features/sweep/prompt-builder.js +85 -0
- package/dist/src/features/sweep/prompt-builder.js.map +7 -0
- package/dist/src/features/sweep/pty-wrapper.js +171 -0
- package/dist/src/features/sweep/pty-wrapper.js.map +7 -0
- package/dist/src/features/sweep/state-watcher.js +87 -0
- package/dist/src/features/sweep/state-watcher.js.map +7 -0
- package/dist/src/features/sweep/status-bar.js +88 -0
- package/dist/src/features/sweep/status-bar.js.map +7 -0
- package/dist/src/features/sweep/sweep-server-manager.js +226 -0
- package/dist/src/features/sweep/sweep-server-manager.js.map +7 -0
- package/dist/src/features/sweep/tab-interceptor.js +38 -0
- package/dist/src/features/sweep/tab-interceptor.js.map +7 -0
- package/dist/src/features/sweep/types.js +18 -0
- package/dist/src/features/sweep/types.js.map +7 -0
- package/dist/src/features/tasks/linear-task-manager.js +487 -0
- package/dist/src/features/tasks/linear-task-manager.js.map +7 -0
- package/dist/src/features/tasks/task-aware-context.js +410 -0
- package/dist/src/features/tasks/task-aware-context.js.map +7 -0
- package/dist/src/features/tui/simple-monitor.js +116 -0
- package/dist/src/features/tui/simple-monitor.js.map +7 -0
- package/dist/src/features/tui/swarm-monitor.js +648 -0
- package/dist/src/features/tui/swarm-monitor.js.map +7 -0
- package/dist/src/features/web/client/stores/task-store.js +26 -0
- package/dist/src/features/web/client/stores/task-store.js.map +7 -0
- package/dist/src/features/web/server/index.js +194 -0
- package/dist/src/features/web/server/index.js.map +7 -0
- package/dist/src/hooks/auto-background.js +151 -0
- package/dist/src/hooks/auto-background.js.map +7 -0
- package/dist/src/hooks/claude-code-whatsapp-hook.js +197 -0
- package/dist/src/hooks/claude-code-whatsapp-hook.js.map +7 -0
- package/dist/src/hooks/config.js +150 -0
- package/dist/src/hooks/config.js.map +7 -0
- package/dist/src/hooks/daemon.js +364 -0
- package/dist/src/hooks/daemon.js.map +7 -0
- package/dist/src/hooks/events.js +58 -0
- package/dist/src/hooks/events.js.map +7 -0
- package/dist/src/hooks/index.js +12 -0
- package/dist/src/hooks/index.js.map +7 -0
- package/dist/src/hooks/linear-task-picker.js +186 -0
- package/dist/src/hooks/linear-task-picker.js.map +7 -0
- package/dist/src/hooks/schemas.js +197 -0
- package/dist/src/hooks/schemas.js.map +7 -0
- package/dist/src/hooks/secure-fs.js +49 -0
- package/dist/src/hooks/secure-fs.js.map +7 -0
- package/dist/src/hooks/security-logger.js +155 -0
- package/dist/src/hooks/security-logger.js.map +7 -0
- package/dist/src/hooks/session-summary.js +222 -0
- package/dist/src/hooks/session-summary.js.map +7 -0
- package/dist/src/hooks/sms-action-runner.js +371 -0
- package/dist/src/hooks/sms-action-runner.js.map +7 -0
- package/dist/src/hooks/sms-notify.js +506 -0
- package/dist/src/hooks/sms-notify.js.map +7 -0
- package/dist/src/hooks/sms-watcher.js +93 -0
- package/dist/src/hooks/sms-watcher.js.map +7 -0
- package/dist/src/hooks/sms-webhook.js +555 -0
- package/dist/src/hooks/sms-webhook.js.map +7 -0
- package/dist/src/hooks/whatsapp-commands.js +479 -0
- package/dist/src/hooks/whatsapp-commands.js.map +7 -0
- package/dist/src/hooks/whatsapp-scheduler.js +317 -0
- package/dist/src/hooks/whatsapp-scheduler.js.map +7 -0
- package/dist/src/hooks/whatsapp-sync.js +409 -0
- package/dist/src/hooks/whatsapp-sync.js.map +7 -0
- package/dist/src/index.js +25 -0
- package/dist/src/index.js.map +7 -0
- package/dist/src/integrations/anthropic/client.js +263 -0
- package/dist/src/integrations/anthropic/client.js.map +7 -0
- package/dist/src/integrations/claude-code/agent-bridge.js +768 -0
- package/dist/src/integrations/claude-code/agent-bridge.js.map +7 -0
- package/dist/src/integrations/claude-code/enhanced-pre-clear-hooks.js +459 -0
- package/dist/src/integrations/claude-code/enhanced-pre-clear-hooks.js.map +7 -0
- package/dist/src/integrations/claude-code/lifecycle-hooks.js +254 -0
- package/dist/src/integrations/claude-code/lifecycle-hooks.js.map +7 -0
- package/dist/src/integrations/claude-code/post-task-hooks.js +545 -0
- package/dist/src/integrations/claude-code/post-task-hooks.js.map +7 -0
- package/dist/src/integrations/claude-code/subagent-client-stub.js +20 -0
- package/dist/src/integrations/claude-code/subagent-client-stub.js.map +7 -0
- package/dist/src/integrations/claude-code/subagent-client.js +511 -0
- package/dist/src/integrations/claude-code/subagent-client.js.map +7 -0
- package/dist/src/integrations/claude-code/task-coordinator.js +360 -0
- package/dist/src/integrations/claude-code/task-coordinator.js.map +7 -0
- package/dist/src/integrations/linear/auth.js +337 -0
- package/dist/src/integrations/linear/auth.js.map +7 -0
- package/dist/src/integrations/linear/auto-sync.js +258 -0
- package/dist/src/integrations/linear/auto-sync.js.map +7 -0
- package/dist/src/integrations/linear/client.js +634 -0
- package/dist/src/integrations/linear/client.js.map +7 -0
- package/dist/src/integrations/linear/config.js +130 -0
- package/dist/src/integrations/linear/config.js.map +7 -0
- package/dist/src/integrations/linear/migration.js +361 -0
- package/dist/src/integrations/linear/migration.js.map +7 -0
- package/dist/src/integrations/linear/oauth-server.js +454 -0
- package/dist/src/integrations/linear/oauth-server.js.map +7 -0
- package/dist/src/integrations/linear/rest-client.js +213 -0
- package/dist/src/integrations/linear/rest-client.js.map +7 -0
- package/dist/src/integrations/linear/sync-manager.js +236 -0
- package/dist/src/integrations/linear/sync-manager.js.map +7 -0
- package/dist/src/integrations/linear/sync-service.js +231 -0
- package/dist/src/integrations/linear/sync-service.js.map +7 -0
- package/dist/src/integrations/linear/sync.js +782 -0
- package/dist/src/integrations/linear/sync.js.map +7 -0
- package/dist/src/integrations/linear/types.js +5 -0
- package/dist/src/integrations/linear/types.js.map +7 -0
- package/dist/src/integrations/linear/unified-sync.js +589 -0
- package/dist/src/integrations/linear/unified-sync.js.map +7 -0
- package/dist/src/integrations/linear/webhook-handler.js +219 -0
- package/dist/src/integrations/linear/webhook-handler.js.map +7 -0
- package/dist/src/integrations/linear/webhook-server.js +218 -0
- package/dist/src/integrations/linear/webhook-server.js.map +7 -0
- package/dist/src/integrations/linear/webhook.js +291 -0
- package/dist/src/integrations/linear/webhook.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/code-execution-handlers.js +266 -0
- package/dist/src/integrations/mcp/handlers/code-execution-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/context-handlers.js +257 -0
- package/dist/src/integrations/mcp/handlers/context-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/discovery-handlers.js +497 -0
- package/dist/src/integrations/mcp/handlers/discovery-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/index.js +166 -0
- package/dist/src/integrations/mcp/handlers/index.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/linear-handlers.js +247 -0
- package/dist/src/integrations/mcp/handlers/linear-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/skill-handlers.js +529 -0
- package/dist/src/integrations/mcp/handlers/skill-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/task-handlers.js +239 -0
- package/dist/src/integrations/mcp/handlers/task-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/handlers/trace-handlers.js +308 -0
- package/dist/src/integrations/mcp/handlers/trace-handlers.js.map +7 -0
- package/dist/src/integrations/mcp/index.js +23 -0
- package/dist/src/integrations/mcp/index.js.map +7 -0
- package/dist/src/integrations/mcp/middleware/tool-scoring.js +356 -0
- package/dist/src/integrations/mcp/middleware/tool-scoring.js.map +7 -0
- package/dist/src/integrations/mcp/refactored-server.js +374 -0
- package/dist/src/integrations/mcp/refactored-server.js.map +7 -0
- package/dist/src/integrations/mcp/remote-server.js +682 -0
- package/dist/src/integrations/mcp/remote-server.js.map +7 -0
- package/dist/src/integrations/mcp/schemas.js +147 -0
- package/dist/src/integrations/mcp/schemas.js.map +7 -0
- package/dist/src/integrations/mcp/server.js +1975 -0
- package/dist/src/integrations/mcp/server.js.map +7 -0
- package/dist/src/integrations/mcp/tool-definitions-code.js +125 -0
- package/dist/src/integrations/mcp/tool-definitions-code.js.map +7 -0
- package/dist/src/integrations/mcp/tool-definitions.js +702 -0
- package/dist/src/integrations/mcp/tool-definitions.js.map +7 -0
- package/dist/src/integrations/ralph/bridge/ralph-stackmemory-bridge.js +860 -0
- package/dist/src/integrations/ralph/bridge/ralph-stackmemory-bridge.js.map +7 -0
- package/dist/src/integrations/ralph/context/context-budget-manager.js +301 -0
- package/dist/src/integrations/ralph/context/context-budget-manager.js.map +7 -0
- package/dist/src/integrations/ralph/context/stackmemory-context-loader.js +360 -0
- package/dist/src/integrations/ralph/context/stackmemory-context-loader.js.map +7 -0
- package/dist/src/integrations/ralph/coordination/enhanced-coordination.js +410 -0
- package/dist/src/integrations/ralph/coordination/enhanced-coordination.js.map +7 -0
- package/dist/src/integrations/ralph/index.js +18 -0
- package/dist/src/integrations/ralph/index.js.map +7 -0
- package/dist/src/integrations/ralph/learning/pattern-learner.js +401 -0
- package/dist/src/integrations/ralph/learning/pattern-learner.js.map +7 -0
- package/dist/src/integrations/ralph/lifecycle/iteration-lifecycle.js +448 -0
- package/dist/src/integrations/ralph/lifecycle/iteration-lifecycle.js.map +7 -0
- package/dist/src/integrations/ralph/monitoring/swarm-dashboard.js +294 -0
- package/dist/src/integrations/ralph/monitoring/swarm-dashboard.js.map +7 -0
- package/dist/src/integrations/ralph/monitoring/swarm-registry.js +108 -0
- package/dist/src/integrations/ralph/monitoring/swarm-registry.js.map +7 -0
- package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js +463 -0
- package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js.map +7 -0
- package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js +400 -0
- package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js.map +7 -0
- package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js +473 -0
- package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js.map +7 -0
- package/dist/src/integrations/ralph/patterns/oracle-worker-pattern.js +388 -0
- package/dist/src/integrations/ralph/patterns/oracle-worker-pattern.js.map +7 -0
- package/dist/src/integrations/ralph/performance/performance-optimizer.js +358 -0
- package/dist/src/integrations/ralph/performance/performance-optimizer.js.map +7 -0
- package/dist/src/integrations/ralph/recovery/crash-recovery.js +462 -0
- package/dist/src/integrations/ralph/recovery/crash-recovery.js.map +7 -0
- package/dist/src/integrations/ralph/state/state-reconciler.js +404 -0
- package/dist/src/integrations/ralph/state/state-reconciler.js.map +7 -0
- package/dist/src/integrations/ralph/swarm/git-workflow-manager.js +428 -0
- package/dist/src/integrations/ralph/swarm/git-workflow-manager.js.map +7 -0
- package/dist/src/integrations/ralph/swarm/swarm-coordinator.js +996 -0
- package/dist/src/integrations/ralph/swarm/swarm-coordinator.js.map +7 -0
- package/dist/src/integrations/ralph/types.js +5 -0
- package/dist/src/integrations/ralph/types.js.map +7 -0
- package/dist/src/integrations/ralph/visualization/ralph-debugger.js +585 -0
- package/dist/src/integrations/ralph/visualization/ralph-debugger.js.map +7 -0
- package/dist/src/mcp/stackmemory-mcp-server.js +554 -0
- package/dist/src/mcp/stackmemory-mcp-server.js.map +7 -0
- package/dist/src/middleware/exponential-rate-limiter.js +289 -0
- package/dist/src/middleware/exponential-rate-limiter.js.map +7 -0
- package/dist/src/models/user.model.js +358 -0
- package/dist/src/models/user.model.js.map +7 -0
- package/dist/src/servers/production/auth-middleware.js +528 -0
- package/dist/src/servers/production/auth-middleware.js.map +7 -0
- package/dist/src/services/config-service.js +65 -0
- package/dist/src/services/config-service.js.map +7 -0
- package/dist/src/services/context-service.js +194 -0
- package/dist/src/services/context-service.js.map +7 -0
- package/dist/src/skills/api-discovery.js +354 -0
- package/dist/src/skills/api-discovery.js.map +7 -0
- package/dist/src/skills/api-skill.js +475 -0
- package/dist/src/skills/api-skill.js.map +7 -0
- package/dist/src/skills/claude-skills.js +1061 -0
- package/dist/src/skills/claude-skills.js.map +7 -0
- package/dist/src/skills/dashboard-launcher.js +216 -0
- package/dist/src/skills/dashboard-launcher.js.map +7 -0
- package/dist/src/skills/recursive-agent-orchestrator.js +575 -0
- package/dist/src/skills/recursive-agent-orchestrator.js.map +7 -0
- package/dist/src/skills/repo-ingestion-skill.js +609 -0
- package/dist/src/skills/repo-ingestion-skill.js.map +7 -0
- package/dist/src/skills/unified-rlm-orchestrator.js +404 -0
- package/dist/src/skills/unified-rlm-orchestrator.js.map +7 -0
- package/dist/src/types/task.js +5 -0
- package/dist/src/types/task.js.map +7 -0
- package/dist/src/utils/env.js +50 -0
- package/dist/src/utils/env.js.map +7 -0
- package/dist/src/utils/formatting.js +62 -0
- package/dist/src/utils/formatting.js.map +7 -0
- package/dist/src/utils/process-cleanup.js +136 -0
- package/dist/src/utils/process-cleanup.js.map +7 -0
- package/package.json +4 -3
- package/scripts/create-cleanup-issues.js +302 -0
- package/scripts/demos/browser-test.ts +39 -0
- package/scripts/demos/ralph-integration-demo.ts +244 -0
- package/scripts/demos/trace-demo.ts +214 -0
- package/scripts/demos/trace-detector.demo.ts +171 -0
- package/scripts/demos/trace-test.ts +67 -0
- package/scripts/initialize.ts +16 -7
- package/scripts/install.sh +14 -62
- package/scripts/status.ts +111 -46
- package/scripts/test-claude-config.sh +123 -0
- package/scripts/validate-claude-config.sh +155 -0
|
@@ -0,0 +1,782 @@
|
|
|
1
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
2
|
+
import { dirname as __pathDirname } from 'path';
|
|
3
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
4
|
+
const __dirname = __pathDirname(__filename);
|
|
5
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
6
|
+
import { join } from "path";
|
|
7
|
+
import { logger } from "../../core/monitoring/logger.js";
|
|
8
|
+
import { IntegrationError, ErrorCode } from "../../core/errors/index.js";
|
|
9
|
+
import { LinearClient } from "./client.js";
|
|
10
|
+
class LinearSyncEngine {
|
|
11
|
+
taskStore;
|
|
12
|
+
linearClient;
|
|
13
|
+
authManager;
|
|
14
|
+
config;
|
|
15
|
+
mappings = /* @__PURE__ */ new Map();
|
|
16
|
+
projectRoot;
|
|
17
|
+
mappingsPath;
|
|
18
|
+
constructor(taskStore, authManager, config, projectRoot) {
|
|
19
|
+
this.taskStore = taskStore;
|
|
20
|
+
this.authManager = authManager;
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.projectRoot = projectRoot || process.cwd();
|
|
23
|
+
this.mappingsPath = join(
|
|
24
|
+
this.projectRoot,
|
|
25
|
+
".stackmemory",
|
|
26
|
+
"linear-mappings.json"
|
|
27
|
+
);
|
|
28
|
+
const apiKey = process.env["LINEAR_API_KEY"];
|
|
29
|
+
if (apiKey) {
|
|
30
|
+
this.linearClient = new LinearClient({
|
|
31
|
+
apiKey
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
const tokens = this.authManager.loadTokens();
|
|
35
|
+
if (!tokens) {
|
|
36
|
+
throw new IntegrationError(
|
|
37
|
+
'Linear API key or authentication tokens not found. Set LINEAR_API_KEY environment variable or run "stackmemory linear setup" first.',
|
|
38
|
+
ErrorCode.LINEAR_SYNC_FAILED
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
this.linearClient = new LinearClient({
|
|
42
|
+
apiKey: tokens.accessToken,
|
|
43
|
+
useBearer: true,
|
|
44
|
+
onUnauthorized: async () => {
|
|
45
|
+
const refreshed = await this.authManager.refreshAccessToken();
|
|
46
|
+
return refreshed.accessToken;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
this.loadMappings();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Update sync configuration
|
|
54
|
+
*/
|
|
55
|
+
updateConfig(newConfig) {
|
|
56
|
+
this.config = { ...this.config, ...newConfig };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Perform bi-directional sync
|
|
60
|
+
*/
|
|
61
|
+
async sync() {
|
|
62
|
+
if (!this.config.enabled) {
|
|
63
|
+
return {
|
|
64
|
+
success: false,
|
|
65
|
+
synced: { toLinear: 0, fromLinear: 0, updated: 0 },
|
|
66
|
+
conflicts: [],
|
|
67
|
+
errors: ["Sync is disabled"]
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const result = {
|
|
71
|
+
success: true,
|
|
72
|
+
synced: { toLinear: 0, fromLinear: 0, updated: 0 },
|
|
73
|
+
conflicts: [],
|
|
74
|
+
errors: []
|
|
75
|
+
};
|
|
76
|
+
try {
|
|
77
|
+
const apiKey = process.env["LINEAR_API_KEY"];
|
|
78
|
+
if (!apiKey) {
|
|
79
|
+
const token = await this.authManager.getValidToken();
|
|
80
|
+
this.linearClient = new LinearClient({
|
|
81
|
+
apiKey: token,
|
|
82
|
+
useBearer: true,
|
|
83
|
+
onUnauthorized: async () => {
|
|
84
|
+
const refreshed = await this.authManager.refreshAccessToken();
|
|
85
|
+
return refreshed.accessToken;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (!this.config.defaultTeamId) {
|
|
90
|
+
const team = await this.linearClient.getTeam();
|
|
91
|
+
this.config.defaultTeamId = team.id;
|
|
92
|
+
logger.info(`Using Linear team: ${team.name} (${team.key})`);
|
|
93
|
+
}
|
|
94
|
+
if (this.config.direction === "bidirectional" || this.config.direction === "to_linear") {
|
|
95
|
+
const toLinearResult = await this.syncToLinear();
|
|
96
|
+
result.synced.toLinear = toLinearResult.created;
|
|
97
|
+
result.synced.updated += toLinearResult.updated;
|
|
98
|
+
result.errors.push(...toLinearResult.errors);
|
|
99
|
+
}
|
|
100
|
+
if (this.config.direction === "bidirectional" || this.config.direction === "from_linear") {
|
|
101
|
+
const fromLinearResult = await this.syncFromLinear();
|
|
102
|
+
result.synced.fromLinear = fromLinearResult.created;
|
|
103
|
+
result.synced.updated += fromLinearResult.updated;
|
|
104
|
+
result.conflicts.push(...fromLinearResult.conflicts);
|
|
105
|
+
result.errors.push(...fromLinearResult.errors);
|
|
106
|
+
}
|
|
107
|
+
this.saveMappings();
|
|
108
|
+
} catch (error) {
|
|
109
|
+
result.success = false;
|
|
110
|
+
result.errors.push(`Sync failed: ${String(error)}`);
|
|
111
|
+
logger.error("Linear sync failed:", error);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Delay helper for rate limiting
|
|
117
|
+
*/
|
|
118
|
+
async delay(ms) {
|
|
119
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Sync tasks from StackMemory to Linear
|
|
123
|
+
*/
|
|
124
|
+
async syncToLinear() {
|
|
125
|
+
const result = { created: 0, updated: 0, errors: [] };
|
|
126
|
+
const maxBatchSize = this.config.maxBatchSize || 10;
|
|
127
|
+
const rateLimitDelay = this.config.rateLimitDelay || 500;
|
|
128
|
+
const duplicateDetector = new LinearDuplicateDetector(this.linearClient);
|
|
129
|
+
const unsyncedTasks = this.getUnsyncedTasks();
|
|
130
|
+
const tasksToSync = unsyncedTasks.slice(0, maxBatchSize);
|
|
131
|
+
if (unsyncedTasks.length > maxBatchSize) {
|
|
132
|
+
logger.info(
|
|
133
|
+
`Syncing ${tasksToSync.length} of ${unsyncedTasks.length} unsynced tasks (batch limit)`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
for (const task of tasksToSync) {
|
|
137
|
+
try {
|
|
138
|
+
const duplicateCheck = await duplicateDetector.checkForDuplicate(
|
|
139
|
+
task.title,
|
|
140
|
+
this.config.defaultTeamId
|
|
141
|
+
);
|
|
142
|
+
let linearIssue;
|
|
143
|
+
if (duplicateCheck.isDuplicate && duplicateCheck.existingIssue) {
|
|
144
|
+
logger.info(
|
|
145
|
+
`Found existing Linear issue for "${task.title}": ${duplicateCheck.existingIssue.identifier} (${Math.round((duplicateCheck.similarity || 0) * 100)}% match)`
|
|
146
|
+
);
|
|
147
|
+
linearIssue = await duplicateDetector.mergeIntoExisting(
|
|
148
|
+
duplicateCheck.existingIssue,
|
|
149
|
+
task.title,
|
|
150
|
+
this.formatDescriptionForLinear(task),
|
|
151
|
+
`StackMemory Task ID: ${task.id}
|
|
152
|
+
Frame: ${task.frame_id}`
|
|
153
|
+
);
|
|
154
|
+
} else {
|
|
155
|
+
linearIssue = await this.createLinearIssueFromTask(task);
|
|
156
|
+
}
|
|
157
|
+
const mapping = {
|
|
158
|
+
stackmemoryId: task.id,
|
|
159
|
+
linearId: linearIssue.id,
|
|
160
|
+
linearIdentifier: linearIssue.identifier,
|
|
161
|
+
lastSyncTimestamp: Date.now(),
|
|
162
|
+
lastLinearUpdate: linearIssue.updatedAt,
|
|
163
|
+
lastStackMemoryUpdate: task.timestamp * 1e3
|
|
164
|
+
};
|
|
165
|
+
this.mappings.set(task.id, mapping);
|
|
166
|
+
this.updateTaskWithLinearRef(task.id, linearIssue);
|
|
167
|
+
result.created++;
|
|
168
|
+
logger.info(
|
|
169
|
+
`Synced task to Linear: ${task.title} \u2192 ${linearIssue.identifier}`
|
|
170
|
+
);
|
|
171
|
+
await this.delay(rateLimitDelay);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
const errorMsg = String(error);
|
|
174
|
+
if (errorMsg.includes("rate limit") || errorMsg.includes("usage limit")) {
|
|
175
|
+
logger.warn("Rate limit hit, stopping sync batch");
|
|
176
|
+
result.errors.push("Rate limit reached - sync paused");
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
result.errors.push(`Failed to sync task ${task.id}: ${errorMsg}`);
|
|
180
|
+
logger.error(
|
|
181
|
+
`Failed to sync task ${task.id} to Linear:`,
|
|
182
|
+
error
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const modifiedTasks = this.getModifiedTasks();
|
|
187
|
+
for (const task of modifiedTasks) {
|
|
188
|
+
try {
|
|
189
|
+
const mapping = this.mappings.get(task.id);
|
|
190
|
+
if (!mapping) continue;
|
|
191
|
+
await this.updateLinearIssueFromTask(task, mapping);
|
|
192
|
+
mapping.lastSyncTimestamp = Date.now();
|
|
193
|
+
mapping.lastStackMemoryUpdate = task.timestamp * 1e3;
|
|
194
|
+
result.updated++;
|
|
195
|
+
logger.info(`Updated Linear issue: ${mapping.linearIdentifier}`);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
result.errors.push(
|
|
198
|
+
`Failed to update Linear issue for task ${task.id}: ${String(error)}`
|
|
199
|
+
);
|
|
200
|
+
logger.error(
|
|
201
|
+
`Failed to update Linear issue for task ${task.id}:`,
|
|
202
|
+
error
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Sync tasks from Linear to StackMemory
|
|
210
|
+
*/
|
|
211
|
+
async syncFromLinear() {
|
|
212
|
+
const result = {
|
|
213
|
+
created: 0,
|
|
214
|
+
updated: 0,
|
|
215
|
+
conflicts: [],
|
|
216
|
+
errors: []
|
|
217
|
+
};
|
|
218
|
+
const importResult = await this.importFromLinear();
|
|
219
|
+
result.created = importResult.imported;
|
|
220
|
+
result.errors.push(...importResult.errors);
|
|
221
|
+
for (const [taskId, mapping] of this.mappings) {
|
|
222
|
+
try {
|
|
223
|
+
const linearIssue = await this.linearClient.getIssue(mapping.linearId);
|
|
224
|
+
if (!linearIssue) {
|
|
225
|
+
result.errors.push(`Linear issue ${mapping.linearId} not found`);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const linearUpdateTime = new Date(linearIssue.updatedAt).getTime();
|
|
229
|
+
if (linearUpdateTime <= mapping.lastSyncTimestamp) {
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const task = this.taskStore.getTask(taskId);
|
|
233
|
+
if (!task) {
|
|
234
|
+
result.errors.push(`StackMemory task ${taskId} not found`);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
const stackMemoryUpdateTime = task.timestamp * 1e3;
|
|
238
|
+
if (stackMemoryUpdateTime > mapping.lastSyncTimestamp && linearUpdateTime > mapping.lastSyncTimestamp) {
|
|
239
|
+
result.conflicts.push({
|
|
240
|
+
taskId,
|
|
241
|
+
linearId: mapping.linearId,
|
|
242
|
+
reason: "Both StackMemory and Linear were updated since last sync"
|
|
243
|
+
});
|
|
244
|
+
if (this.config.conflictResolution === "manual") {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const shouldUpdateFromLinear = this.shouldUpdateFromLinear(
|
|
249
|
+
task,
|
|
250
|
+
linearIssue,
|
|
251
|
+
mapping,
|
|
252
|
+
stackMemoryUpdateTime,
|
|
253
|
+
linearUpdateTime
|
|
254
|
+
);
|
|
255
|
+
if (shouldUpdateFromLinear) {
|
|
256
|
+
this.updateTaskFromLinearIssue(task, linearIssue);
|
|
257
|
+
mapping.lastSyncTimestamp = Date.now();
|
|
258
|
+
mapping.lastLinearUpdate = linearIssue.updatedAt;
|
|
259
|
+
result.updated++;
|
|
260
|
+
logger.info(`Updated StackMemory task from Linear: ${task.title}`);
|
|
261
|
+
}
|
|
262
|
+
} catch (error) {
|
|
263
|
+
result.errors.push(
|
|
264
|
+
`Failed to sync from Linear for task ${taskId}: ${String(error)}`
|
|
265
|
+
);
|
|
266
|
+
logger.error(
|
|
267
|
+
`Failed to sync from Linear for task ${taskId}:`,
|
|
268
|
+
error
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return result;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Create Linear issue from StackMemory task
|
|
276
|
+
*/
|
|
277
|
+
async createLinearIssueFromTask(task) {
|
|
278
|
+
const input = {
|
|
279
|
+
title: task.title,
|
|
280
|
+
description: this.formatDescriptionForLinear(task),
|
|
281
|
+
teamId: this.config.defaultTeamId,
|
|
282
|
+
priority: this.mapPriorityToLinear(task.priority),
|
|
283
|
+
estimate: task.estimated_effort ? Math.ceil(task.estimated_effort / 60) : void 0,
|
|
284
|
+
// Convert minutes to hours
|
|
285
|
+
labelIds: this.mapTagsToLinear(task.tags)
|
|
286
|
+
};
|
|
287
|
+
return await this.linearClient.createIssue(input);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Update Linear issue from StackMemory task
|
|
291
|
+
*/
|
|
292
|
+
async updateLinearIssueFromTask(task, mapping) {
|
|
293
|
+
const updates = {
|
|
294
|
+
title: task.title,
|
|
295
|
+
description: this.formatDescriptionForLinear(task),
|
|
296
|
+
priority: this.mapPriorityToLinear(task.priority),
|
|
297
|
+
estimate: task.estimated_effort ? Math.ceil(task.estimated_effort / 60) : void 0,
|
|
298
|
+
stateId: await this.mapStatusToLinearState(task.status)
|
|
299
|
+
};
|
|
300
|
+
await this.linearClient.updateIssue(mapping.linearId, updates);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Update StackMemory task from Linear issue
|
|
304
|
+
*/
|
|
305
|
+
updateTaskFromLinearIssue(task, linearIssue) {
|
|
306
|
+
const newStatus = this.mapLinearStateToStatus(linearIssue.state.type);
|
|
307
|
+
if (newStatus !== task.status) {
|
|
308
|
+
this.taskStore.updateTaskStatus(
|
|
309
|
+
task.id,
|
|
310
|
+
newStatus,
|
|
311
|
+
"Updated from Linear"
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Check if task should be updated from Linear based on conflict resolution strategy
|
|
317
|
+
*/
|
|
318
|
+
shouldUpdateFromLinear(task, linearIssue, mapping, stackMemoryUpdateTime, linearUpdateTime) {
|
|
319
|
+
switch (this.config.conflictResolution) {
|
|
320
|
+
case "linear_wins":
|
|
321
|
+
return true;
|
|
322
|
+
case "stackmemory_wins":
|
|
323
|
+
return false;
|
|
324
|
+
case "newest_wins":
|
|
325
|
+
return linearUpdateTime > stackMemoryUpdateTime;
|
|
326
|
+
case "manual":
|
|
327
|
+
return false;
|
|
328
|
+
default:
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get tasks that haven't been synced to Linear yet
|
|
334
|
+
*/
|
|
335
|
+
getUnsyncedTasks() {
|
|
336
|
+
const activeTasks = this.taskStore.getActiveTasks();
|
|
337
|
+
return activeTasks.filter(
|
|
338
|
+
(task) => !this.mappings.has(task.id) && !task.external_refs?.linear
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Get tasks that have been modified since last sync
|
|
343
|
+
*/
|
|
344
|
+
getModifiedTasks() {
|
|
345
|
+
const tasks = [];
|
|
346
|
+
for (const [taskId, mapping] of this.mappings) {
|
|
347
|
+
const task = this.taskStore.getTask(taskId);
|
|
348
|
+
if (task && task.timestamp * 1e3 > mapping.lastSyncTimestamp) {
|
|
349
|
+
tasks.push(task);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return tasks;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Update task with Linear reference
|
|
356
|
+
*/
|
|
357
|
+
updateTaskWithLinearRef(taskId, linearIssue) {
|
|
358
|
+
const task = this.taskStore.getTask(taskId);
|
|
359
|
+
if (!task) return;
|
|
360
|
+
logger.info(`Task ${taskId} mapped to Linear ${linearIssue.identifier}`);
|
|
361
|
+
}
|
|
362
|
+
// Mapping utilities
|
|
363
|
+
formatDescriptionForLinear(task) {
|
|
364
|
+
let description = task.description || "";
|
|
365
|
+
description += `
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
**StackMemory Context:**
|
|
369
|
+
`;
|
|
370
|
+
description += `- Task ID: ${task.id}
|
|
371
|
+
`;
|
|
372
|
+
description += `- Frame: ${task.frame_id}
|
|
373
|
+
`;
|
|
374
|
+
description += `- Created: ${new Date(task.created_at * 1e3).toISOString()}
|
|
375
|
+
`;
|
|
376
|
+
if (task.tags.length > 0) {
|
|
377
|
+
description += `- Tags: ${task.tags.join(", ")}
|
|
378
|
+
`;
|
|
379
|
+
}
|
|
380
|
+
if (task.depends_on.length > 0) {
|
|
381
|
+
description += `- Dependencies: ${task.depends_on.join(", ")}
|
|
382
|
+
`;
|
|
383
|
+
}
|
|
384
|
+
return description;
|
|
385
|
+
}
|
|
386
|
+
mapPriorityToLinear(priority) {
|
|
387
|
+
const map = {
|
|
388
|
+
low: 1,
|
|
389
|
+
// Low priority in Linear
|
|
390
|
+
medium: 2,
|
|
391
|
+
// Medium priority in Linear
|
|
392
|
+
high: 3,
|
|
393
|
+
// High priority in Linear
|
|
394
|
+
urgent: 4
|
|
395
|
+
// Urgent priority in Linear
|
|
396
|
+
};
|
|
397
|
+
return map[priority] || 2;
|
|
398
|
+
}
|
|
399
|
+
mapTagsToLinear(_tags) {
|
|
400
|
+
return void 0;
|
|
401
|
+
}
|
|
402
|
+
mapLinearStateToStatus(linearStateType) {
|
|
403
|
+
switch (linearStateType) {
|
|
404
|
+
case "backlog":
|
|
405
|
+
case "unstarted":
|
|
406
|
+
return "pending";
|
|
407
|
+
case "started":
|
|
408
|
+
return "in_progress";
|
|
409
|
+
case "completed":
|
|
410
|
+
return "completed";
|
|
411
|
+
case "cancelled":
|
|
412
|
+
return "cancelled";
|
|
413
|
+
default:
|
|
414
|
+
return "pending";
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
async mapStatusToLinearState(status) {
|
|
418
|
+
try {
|
|
419
|
+
const team = await this.linearClient.getTeam();
|
|
420
|
+
const states = await this.linearClient.getWorkflowStates(team.id);
|
|
421
|
+
const targetStateType = this.getLinearStateTypeFromStatus(status);
|
|
422
|
+
const matchingState = states.find(
|
|
423
|
+
(state) => state.type === targetStateType
|
|
424
|
+
);
|
|
425
|
+
return matchingState?.id;
|
|
426
|
+
} catch (error) {
|
|
427
|
+
logger.warn(
|
|
428
|
+
"Failed to map status to Linear state:",
|
|
429
|
+
error instanceof Error ? { error } : void 0
|
|
430
|
+
);
|
|
431
|
+
return void 0;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
getLinearStateTypeFromStatus(status) {
|
|
435
|
+
switch (status) {
|
|
436
|
+
case "pending":
|
|
437
|
+
return "unstarted";
|
|
438
|
+
case "in_progress":
|
|
439
|
+
return "started";
|
|
440
|
+
case "completed":
|
|
441
|
+
return "completed";
|
|
442
|
+
case "cancelled":
|
|
443
|
+
return "cancelled";
|
|
444
|
+
case "blocked":
|
|
445
|
+
return "unstarted";
|
|
446
|
+
// Map blocked to unstarted in Linear
|
|
447
|
+
default:
|
|
448
|
+
return "unstarted";
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
// Persistence for mappings
|
|
452
|
+
loadMappings() {
|
|
453
|
+
this.mappings.clear();
|
|
454
|
+
if (existsSync(this.mappingsPath)) {
|
|
455
|
+
try {
|
|
456
|
+
const data = readFileSync(this.mappingsPath, "utf8");
|
|
457
|
+
const mappingsArray = JSON.parse(data);
|
|
458
|
+
for (const mapping of mappingsArray) {
|
|
459
|
+
this.mappings.set(mapping.stackmemoryId, mapping);
|
|
460
|
+
}
|
|
461
|
+
logger.info(`Loaded ${this.mappings.size} task mappings from disk`);
|
|
462
|
+
} catch (error) {
|
|
463
|
+
logger.warn("Failed to load mappings, starting fresh");
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
saveMappings() {
|
|
468
|
+
try {
|
|
469
|
+
const mappingsArray = Array.from(this.mappings.values());
|
|
470
|
+
writeFileSync(this.mappingsPath, JSON.stringify(mappingsArray, null, 2));
|
|
471
|
+
logger.info(`Saved ${this.mappings.size} task mappings to disk`);
|
|
472
|
+
} catch (error) {
|
|
473
|
+
logger.error("Failed to save mappings:", error);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Import all issues from Linear to local task store
|
|
478
|
+
*/
|
|
479
|
+
async importFromLinear() {
|
|
480
|
+
const result = { imported: 0, skipped: 0, errors: [] };
|
|
481
|
+
try {
|
|
482
|
+
if (!this.config.defaultTeamId) {
|
|
483
|
+
const team = await this.linearClient.getTeam();
|
|
484
|
+
this.config.defaultTeamId = team.id;
|
|
485
|
+
logger.info(`Using Linear team: ${team.name} (${team.key})`);
|
|
486
|
+
}
|
|
487
|
+
const issues = await this.linearClient.getIssues({
|
|
488
|
+
teamId: this.config.defaultTeamId,
|
|
489
|
+
limit: 100
|
|
490
|
+
});
|
|
491
|
+
logger.info(`Found ${issues.length} issues in Linear`);
|
|
492
|
+
const linearIdToTaskId = /* @__PURE__ */ new Map();
|
|
493
|
+
for (const [taskId, mapping] of this.mappings) {
|
|
494
|
+
linearIdToTaskId.set(mapping.linearId, taskId);
|
|
495
|
+
}
|
|
496
|
+
for (const issue of issues) {
|
|
497
|
+
try {
|
|
498
|
+
if (linearIdToTaskId.has(issue.id)) {
|
|
499
|
+
result.skipped++;
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
const taskId = await this.createTaskFromLinearIssue(issue);
|
|
503
|
+
if (taskId) {
|
|
504
|
+
const mapping = {
|
|
505
|
+
stackmemoryId: taskId,
|
|
506
|
+
linearId: issue.id,
|
|
507
|
+
linearIdentifier: issue.identifier,
|
|
508
|
+
lastSyncTimestamp: Date.now(),
|
|
509
|
+
lastLinearUpdate: issue.updatedAt,
|
|
510
|
+
lastStackMemoryUpdate: Date.now()
|
|
511
|
+
};
|
|
512
|
+
this.mappings.set(taskId, mapping);
|
|
513
|
+
result.imported++;
|
|
514
|
+
logger.info(`Imported ${issue.identifier}: ${issue.title}`);
|
|
515
|
+
}
|
|
516
|
+
} catch (error) {
|
|
517
|
+
result.errors.push(
|
|
518
|
+
`Failed to import ${issue.identifier}: ${String(error)}`
|
|
519
|
+
);
|
|
520
|
+
logger.error(`Failed to import ${issue.identifier}:`, error);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
this.saveMappings();
|
|
524
|
+
} catch (error) {
|
|
525
|
+
result.errors.push(`Import failed: ${String(error)}`);
|
|
526
|
+
logger.error("Linear import failed:", error);
|
|
527
|
+
}
|
|
528
|
+
return result;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Create a local task from a Linear issue
|
|
532
|
+
*/
|
|
533
|
+
async createTaskFromLinearIssue(issue) {
|
|
534
|
+
try {
|
|
535
|
+
const priority = this.mapLinearPriorityToLocal(issue.priority);
|
|
536
|
+
let description = issue.description || "";
|
|
537
|
+
description += `
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
**Linear:** ${issue.identifier} | ${issue.url}`;
|
|
541
|
+
const labels = Array.isArray(issue.labels) ? issue.labels : issue.labels?.nodes || [];
|
|
542
|
+
const tags = labels.map((l) => l.name);
|
|
543
|
+
if (tags.length === 0) tags.push("linear");
|
|
544
|
+
const taskId = this.taskStore.createTask({
|
|
545
|
+
title: `[${issue.identifier}] ${issue.title}`,
|
|
546
|
+
description,
|
|
547
|
+
priority,
|
|
548
|
+
frameId: "linear-import",
|
|
549
|
+
tags,
|
|
550
|
+
estimatedEffort: issue.estimate ? issue.estimate * 60 : void 0
|
|
551
|
+
});
|
|
552
|
+
const status = this.mapLinearStateToStatus(issue.state.type);
|
|
553
|
+
if (status !== "pending") {
|
|
554
|
+
this.taskStore.updateTaskStatus(
|
|
555
|
+
taskId,
|
|
556
|
+
status,
|
|
557
|
+
`Imported from Linear as ${status}`
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
return taskId;
|
|
561
|
+
} catch (error) {
|
|
562
|
+
logger.error(
|
|
563
|
+
`Failed to create task from Linear issue ${issue.identifier}: ${String(error)}`
|
|
564
|
+
);
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Map Linear priority (0-4) to local TaskPriority
|
|
570
|
+
*/
|
|
571
|
+
mapLinearPriorityToLocal(priority) {
|
|
572
|
+
switch (priority) {
|
|
573
|
+
case 1:
|
|
574
|
+
return "urgent";
|
|
575
|
+
case 2:
|
|
576
|
+
return "high";
|
|
577
|
+
case 3:
|
|
578
|
+
return "medium";
|
|
579
|
+
case 4:
|
|
580
|
+
return "low";
|
|
581
|
+
default:
|
|
582
|
+
return "medium";
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
const DEFAULT_SYNC_CONFIG = {
|
|
587
|
+
enabled: false,
|
|
588
|
+
direction: "bidirectional",
|
|
589
|
+
autoSync: true,
|
|
590
|
+
conflictResolution: "newest_wins",
|
|
591
|
+
syncInterval: 15,
|
|
592
|
+
// minutes
|
|
593
|
+
maxBatchSize: 10,
|
|
594
|
+
// max tasks per sync batch
|
|
595
|
+
rateLimitDelay: 500
|
|
596
|
+
// 500ms between API calls
|
|
597
|
+
};
|
|
598
|
+
class LinearDuplicateDetector {
|
|
599
|
+
linearClient;
|
|
600
|
+
titleCache = /* @__PURE__ */ new Map();
|
|
601
|
+
cacheExpiry = 5 * 60 * 1e3;
|
|
602
|
+
// 5 minutes
|
|
603
|
+
lastCacheRefresh = 0;
|
|
604
|
+
constructor(linearClient) {
|
|
605
|
+
this.linearClient = linearClient;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Search for existing Linear issues with similar titles
|
|
609
|
+
*/
|
|
610
|
+
async searchByTitle(title, teamId) {
|
|
611
|
+
const normalizedTitle = this.normalizeTitle(title);
|
|
612
|
+
if (this.isCacheValid()) {
|
|
613
|
+
const cached = this.titleCache.get(normalizedTitle);
|
|
614
|
+
if (cached) return cached;
|
|
615
|
+
}
|
|
616
|
+
try {
|
|
617
|
+
const allIssues = await this.linearClient.getIssues({
|
|
618
|
+
teamId,
|
|
619
|
+
limit: 100
|
|
620
|
+
// Use smaller limit to avoid API errors
|
|
621
|
+
});
|
|
622
|
+
const matchingIssues = allIssues.filter((issue) => {
|
|
623
|
+
const issueNormalized = this.normalizeTitle(issue.title);
|
|
624
|
+
if (issueNormalized === normalizedTitle) return true;
|
|
625
|
+
const similarity = this.calculateSimilarity(
|
|
626
|
+
normalizedTitle,
|
|
627
|
+
issueNormalized
|
|
628
|
+
);
|
|
629
|
+
return similarity > 0.85;
|
|
630
|
+
});
|
|
631
|
+
this.titleCache.set(normalizedTitle, matchingIssues);
|
|
632
|
+
this.lastCacheRefresh = Date.now();
|
|
633
|
+
return matchingIssues;
|
|
634
|
+
} catch (error) {
|
|
635
|
+
logger.error("Failed to search Linear issues by title:", error);
|
|
636
|
+
return [];
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Check if a task title would create a duplicate in Linear
|
|
641
|
+
*/
|
|
642
|
+
async checkForDuplicate(title, teamId) {
|
|
643
|
+
const existingIssues = await this.searchByTitle(title, teamId);
|
|
644
|
+
if (existingIssues.length === 0) {
|
|
645
|
+
return { isDuplicate: false };
|
|
646
|
+
}
|
|
647
|
+
let bestMatch;
|
|
648
|
+
let bestSimilarity = 0;
|
|
649
|
+
for (const issue of existingIssues) {
|
|
650
|
+
const similarity = this.calculateSimilarity(
|
|
651
|
+
this.normalizeTitle(title),
|
|
652
|
+
this.normalizeTitle(issue.title)
|
|
653
|
+
);
|
|
654
|
+
if (similarity > bestSimilarity) {
|
|
655
|
+
bestSimilarity = similarity;
|
|
656
|
+
bestMatch = issue;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return {
|
|
660
|
+
isDuplicate: true,
|
|
661
|
+
existingIssue: bestMatch,
|
|
662
|
+
similarity: bestSimilarity
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Merge task content into existing Linear issue
|
|
667
|
+
*/
|
|
668
|
+
async mergeIntoExisting(existingIssue, newTitle, newDescription, additionalContext) {
|
|
669
|
+
try {
|
|
670
|
+
let mergedDescription = existingIssue.description || "";
|
|
671
|
+
if (newDescription && !mergedDescription.includes(newDescription)) {
|
|
672
|
+
mergedDescription += `
|
|
673
|
+
|
|
674
|
+
## Additional Context (${(/* @__PURE__ */ new Date()).toISOString()})
|
|
675
|
+
`;
|
|
676
|
+
mergedDescription += newDescription;
|
|
677
|
+
}
|
|
678
|
+
if (additionalContext) {
|
|
679
|
+
mergedDescription += `
|
|
680
|
+
|
|
681
|
+
---
|
|
682
|
+
${additionalContext}`;
|
|
683
|
+
}
|
|
684
|
+
const updateQuery = `
|
|
685
|
+
mutation UpdateIssue($id: String!, $input: IssueUpdateInput!) {
|
|
686
|
+
issueUpdate(id: $id, input: $input) {
|
|
687
|
+
issue {
|
|
688
|
+
id
|
|
689
|
+
identifier
|
|
690
|
+
title
|
|
691
|
+
description
|
|
692
|
+
updatedAt
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
`;
|
|
697
|
+
const variables = {
|
|
698
|
+
id: existingIssue.id,
|
|
699
|
+
input: {
|
|
700
|
+
description: mergedDescription
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
const response = await this.linearClient.graphql(updateQuery, variables);
|
|
704
|
+
const updatedIssue = response.issueUpdate?.issue;
|
|
705
|
+
if (updatedIssue) {
|
|
706
|
+
logger.info(
|
|
707
|
+
`Merged content into existing Linear issue ${existingIssue.identifier}: ${existingIssue.title}`
|
|
708
|
+
);
|
|
709
|
+
return updatedIssue;
|
|
710
|
+
}
|
|
711
|
+
return existingIssue;
|
|
712
|
+
} catch (error) {
|
|
713
|
+
logger.error(
|
|
714
|
+
"Failed to merge into existing Linear issue:",
|
|
715
|
+
error
|
|
716
|
+
);
|
|
717
|
+
return existingIssue;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Normalize title for comparison
|
|
722
|
+
*/
|
|
723
|
+
normalizeTitle(title) {
|
|
724
|
+
return title.toLowerCase().trim().replace(/\s+/g, " ").replace(/[^\w\s-]/g, "").replace(/^(sta|eng|bug|feat|task|tsk)[-\s]\d+[-\s:]*/, "").trim();
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Calculate similarity between two strings (Levenshtein distance based)
|
|
728
|
+
*/
|
|
729
|
+
calculateSimilarity(str1, str2) {
|
|
730
|
+
if (str1 === str2) return 1;
|
|
731
|
+
if (str1.length === 0 || str2.length === 0) return 0;
|
|
732
|
+
const distance = this.levenshteinDistance(str1, str2);
|
|
733
|
+
const maxLength = Math.max(str1.length, str2.length);
|
|
734
|
+
return 1 - distance / maxLength;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Calculate Levenshtein distance between two strings
|
|
738
|
+
*/
|
|
739
|
+
levenshteinDistance(str1, str2) {
|
|
740
|
+
const m = str1.length;
|
|
741
|
+
const n = str2.length;
|
|
742
|
+
const dp = Array(m + 1).fill(null).map(() => Array(n + 1).fill(0));
|
|
743
|
+
for (let i = 0; i <= m; i++) dp[i][0] = i;
|
|
744
|
+
for (let j = 0; j <= n; j++) dp[0][j] = j;
|
|
745
|
+
for (let i = 1; i <= m; i++) {
|
|
746
|
+
for (let j = 1; j <= n; j++) {
|
|
747
|
+
if (str1[i - 1] === str2[j - 1]) {
|
|
748
|
+
dp[i][j] = dp[i - 1][j - 1];
|
|
749
|
+
} else {
|
|
750
|
+
dp[i][j] = 1 + Math.min(
|
|
751
|
+
dp[i - 1][j],
|
|
752
|
+
// deletion
|
|
753
|
+
dp[i][j - 1],
|
|
754
|
+
// insertion
|
|
755
|
+
dp[i - 1][j - 1]
|
|
756
|
+
// substitution
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return dp[m][n];
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Check if cache is still valid
|
|
765
|
+
*/
|
|
766
|
+
isCacheValid() {
|
|
767
|
+
return Date.now() - this.lastCacheRefresh < this.cacheExpiry;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Clear the title cache
|
|
771
|
+
*/
|
|
772
|
+
clearCache() {
|
|
773
|
+
this.titleCache.clear();
|
|
774
|
+
this.lastCacheRefresh = 0;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
export {
|
|
778
|
+
DEFAULT_SYNC_CONFIG,
|
|
779
|
+
LinearDuplicateDetector,
|
|
780
|
+
LinearSyncEngine
|
|
781
|
+
};
|
|
782
|
+
//# sourceMappingURL=sync.js.map
|