@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,93 @@
|
|
|
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 { existsSync, readFileSync, watchFile, writeFileSync } from "fs";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
import { homedir } from "os";
|
|
9
|
+
import { execSync } from "child_process";
|
|
10
|
+
const RESPONSE_PATH = join(
|
|
11
|
+
homedir(),
|
|
12
|
+
".stackmemory",
|
|
13
|
+
"sms-latest-response.json"
|
|
14
|
+
);
|
|
15
|
+
const SIGNAL_PATH = join(homedir(), ".stackmemory", "sms-signal.txt");
|
|
16
|
+
let lastProcessedTimestamp = "";
|
|
17
|
+
function checkForResponse() {
|
|
18
|
+
try {
|
|
19
|
+
if (existsSync(RESPONSE_PATH)) {
|
|
20
|
+
const data = JSON.parse(
|
|
21
|
+
readFileSync(RESPONSE_PATH, "utf8")
|
|
22
|
+
);
|
|
23
|
+
if (data.timestamp !== lastProcessedTimestamp) {
|
|
24
|
+
lastProcessedTimestamp = data.timestamp;
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
function triggerNotification(response) {
|
|
33
|
+
const message = `SMS Response: "${response.response}"`;
|
|
34
|
+
try {
|
|
35
|
+
execSync(
|
|
36
|
+
`osascript -e 'display notification "${message}" with title "StackMemory"'`,
|
|
37
|
+
{
|
|
38
|
+
stdio: "ignore"
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
process.stdout.write("\x07");
|
|
44
|
+
try {
|
|
45
|
+
writeFileSync(
|
|
46
|
+
SIGNAL_PATH,
|
|
47
|
+
JSON.stringify({
|
|
48
|
+
type: "sms_response",
|
|
49
|
+
response: response.response,
|
|
50
|
+
promptId: response.promptId,
|
|
51
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
console.log(`
|
|
57
|
+
[SMS] User responded: "${response.response}"`);
|
|
58
|
+
console.log(`[SMS] Run: stackmemory notify run-actions
|
|
59
|
+
`);
|
|
60
|
+
}
|
|
61
|
+
function startResponseWatcher(intervalMs = 2e3) {
|
|
62
|
+
console.log("[SMS Watcher] Watching for responses...");
|
|
63
|
+
console.log("[SMS Watcher] Press Ctrl+C to stop\n");
|
|
64
|
+
const initial = checkForResponse();
|
|
65
|
+
if (initial) {
|
|
66
|
+
triggerNotification(initial);
|
|
67
|
+
}
|
|
68
|
+
setInterval(() => {
|
|
69
|
+
const response = checkForResponse();
|
|
70
|
+
if (response) {
|
|
71
|
+
triggerNotification(response);
|
|
72
|
+
}
|
|
73
|
+
}, intervalMs);
|
|
74
|
+
}
|
|
75
|
+
function startFileWatcher() {
|
|
76
|
+
console.log("[SMS Watcher] Watching for responses (file mode)...");
|
|
77
|
+
watchFile(RESPONSE_PATH, { interval: 1e3 }, () => {
|
|
78
|
+
const response = checkForResponse();
|
|
79
|
+
if (response) {
|
|
80
|
+
triggerNotification(response);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (process.argv[1]?.includes("sms-watcher")) {
|
|
85
|
+
startResponseWatcher();
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
checkForResponse,
|
|
89
|
+
startFileWatcher,
|
|
90
|
+
startResponseWatcher,
|
|
91
|
+
triggerNotification
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=sms-watcher.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/sms-watcher.ts"],
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env node\n/**\n * SMS Response Watcher\n * Watches for incoming SMS/WhatsApp responses and triggers notifications\n *\n * Run in background: stackmemory notify watch-responses &\n */\n\nimport { existsSync, readFileSync, watchFile, writeFileSync } from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport { execSync } from 'child_process';\n\nconst RESPONSE_PATH = join(\n homedir(),\n '.stackmemory',\n 'sms-latest-response.json'\n);\nconst SIGNAL_PATH = join(homedir(), '.stackmemory', 'sms-signal.txt');\n\ninterface SMSResponse {\n promptId: string;\n response: string;\n timestamp: string;\n}\n\nlet lastProcessedTimestamp = '';\n\nfunction checkForResponse(): SMSResponse | null {\n try {\n if (existsSync(RESPONSE_PATH)) {\n const data = JSON.parse(\n readFileSync(RESPONSE_PATH, 'utf8')\n ) as SMSResponse;\n\n // Only process new responses\n if (data.timestamp !== lastProcessedTimestamp) {\n lastProcessedTimestamp = data.timestamp;\n return data;\n }\n }\n } catch {\n // Ignore errors\n }\n return null;\n}\n\nfunction triggerNotification(response: SMSResponse): void {\n const message = `SMS Response: \"${response.response}\"`;\n\n // macOS notification\n try {\n execSync(\n `osascript -e 'display notification \"${message}\" with title \"StackMemory\"'`,\n {\n stdio: 'ignore',\n }\n );\n } catch {\n // Ignore if not on macOS\n }\n\n // Terminal bell\n process.stdout.write('\\x07');\n\n // Write to signal file (for other processes to detect)\n try {\n writeFileSync(\n SIGNAL_PATH,\n JSON.stringify({\n type: 'sms_response',\n response: response.response,\n promptId: response.promptId,\n timestamp: new Date().toISOString(),\n })\n );\n } catch {\n // Ignore\n }\n\n // Output to terminal\n console.log(`\\n[SMS] User responded: \"${response.response}\"`);\n console.log(`[SMS] Run: stackmemory notify run-actions\\n`);\n}\n\nexport function startResponseWatcher(intervalMs: number = 2000): void {\n console.log('[SMS Watcher] Watching for responses...');\n console.log('[SMS Watcher] Press Ctrl+C to stop\\n');\n\n // Initial check\n const initial = checkForResponse();\n if (initial) {\n triggerNotification(initial);\n }\n\n // Poll for changes\n setInterval(() => {\n const response = checkForResponse();\n if (response) {\n triggerNotification(response);\n }\n }, intervalMs);\n}\n\n// Also watch file for immediate notification\nexport function startFileWatcher(): void {\n console.log('[SMS Watcher] Watching for responses (file mode)...');\n\n watchFile(RESPONSE_PATH, { interval: 1000 }, () => {\n const response = checkForResponse();\n if (response) {\n triggerNotification(response);\n }\n });\n}\n\n// CLI entry\nif (process.argv[1]?.includes('sms-watcher')) {\n startResponseWatcher();\n}\n\nexport { checkForResponse, triggerNotification };\n"],
|
|
5
|
+
"mappings": ";;;;;AAQA,SAAS,YAAY,cAAc,WAAW,qBAAqB;AACnE,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,gBAAgB;AAEzB,MAAM,gBAAgB;AAAA,EACpB,QAAQ;AAAA,EACR;AAAA,EACA;AACF;AACA,MAAM,cAAc,KAAK,QAAQ,GAAG,gBAAgB,gBAAgB;AAQpE,IAAI,yBAAyB;AAE7B,SAAS,mBAAuC;AAC9C,MAAI;AACF,QAAI,WAAW,aAAa,GAAG;AAC7B,YAAM,OAAO,KAAK;AAAA,QAChB,aAAa,eAAe,MAAM;AAAA,MACpC;AAGA,UAAI,KAAK,cAAc,wBAAwB;AAC7C,iCAAyB,KAAK;AAC9B,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO;AACT;AAEA,SAAS,oBAAoB,UAA6B;AACxD,QAAM,UAAU,kBAAkB,SAAS,QAAQ;AAGnD,MAAI;AACF;AAAA,MACE,uCAAuC,OAAO;AAAA,MAC9C;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,QAAQ;AAAA,EAER;AAGA,UAAQ,OAAO,MAAM,MAAM;AAG3B,MAAI;AACF;AAAA,MACE;AAAA,MACA,KAAK,UAAU;AAAA,QACb,MAAM;AAAA,QACN,UAAU,SAAS;AAAA,QACnB,UAAU,SAAS;AAAA,QACnB,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,MACpC,CAAC;AAAA,IACH;AAAA,EACF,QAAQ;AAAA,EAER;AAGA,UAAQ,IAAI;AAAA,yBAA4B,SAAS,QAAQ,GAAG;AAC5D,UAAQ,IAAI;AAAA,CAA6C;AAC3D;AAEO,SAAS,qBAAqB,aAAqB,KAAY;AACpE,UAAQ,IAAI,yCAAyC;AACrD,UAAQ,IAAI,sCAAsC;AAGlD,QAAM,UAAU,iBAAiB;AACjC,MAAI,SAAS;AACX,wBAAoB,OAAO;AAAA,EAC7B;AAGA,cAAY,MAAM;AAChB,UAAM,WAAW,iBAAiB;AAClC,QAAI,UAAU;AACZ,0BAAoB,QAAQ;AAAA,IAC9B;AAAA,EACF,GAAG,UAAU;AACf;AAGO,SAAS,mBAAyB;AACvC,UAAQ,IAAI,qDAAqD;AAEjE,YAAU,eAAe,EAAE,UAAU,IAAK,GAAG,MAAM;AACjD,UAAM,WAAW,iBAAiB;AAClC,QAAI,UAAU;AACZ,0BAAoB,QAAQ;AAAA,IAC9B;AAAA,EACF,CAAC;AACH;AAGA,IAAI,QAAQ,KAAK,CAAC,GAAG,SAAS,aAAa,GAAG;AAC5C,uBAAqB;AACvB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,555 @@
|
|
|
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 { createServer } from "http";
|
|
6
|
+
import { parse as parseUrl } from "url";
|
|
7
|
+
import { existsSync, readFileSync } from "fs";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
import { homedir } from "os";
|
|
10
|
+
import { createHmac } from "crypto";
|
|
11
|
+
import { execFileSync } from "child_process";
|
|
12
|
+
import {
|
|
13
|
+
processIncomingResponse,
|
|
14
|
+
loadSMSConfig,
|
|
15
|
+
cleanupExpiredPrompts,
|
|
16
|
+
sendNotification
|
|
17
|
+
} from "./sms-notify.js";
|
|
18
|
+
import {
|
|
19
|
+
queueAction,
|
|
20
|
+
executeActionSafe,
|
|
21
|
+
cleanupOldActions
|
|
22
|
+
} from "./sms-action-runner.js";
|
|
23
|
+
import {
|
|
24
|
+
isCommand,
|
|
25
|
+
processCommand,
|
|
26
|
+
sendCommandResponse
|
|
27
|
+
} from "./whatsapp-commands.js";
|
|
28
|
+
import { writeFileSecure, ensureSecureDir } from "./secure-fs.js";
|
|
29
|
+
import {
|
|
30
|
+
logWebhookRequest,
|
|
31
|
+
logRateLimit,
|
|
32
|
+
logSignatureInvalid,
|
|
33
|
+
logBodyTooLarge,
|
|
34
|
+
logContentTypeInvalid,
|
|
35
|
+
logActionAllowed,
|
|
36
|
+
logActionBlocked,
|
|
37
|
+
logCleanup
|
|
38
|
+
} from "./security-logger.js";
|
|
39
|
+
const CLEANUP_INTERVAL_MS = 5 * 60 * 1e3;
|
|
40
|
+
const MAX_SMS_BODY_LENGTH = 1e3;
|
|
41
|
+
const MAX_PHONE_LENGTH = 50;
|
|
42
|
+
const MAX_BODY_SIZE = 50 * 1024;
|
|
43
|
+
const RATE_LIMIT_WINDOW_MS = 60 * 1e3;
|
|
44
|
+
const RATE_LIMIT_MAX_REQUESTS = 30;
|
|
45
|
+
const ACTION_TIMEOUT_MS = 6e4;
|
|
46
|
+
async function executeActionWithTimeout(action, response) {
|
|
47
|
+
return Promise.race([
|
|
48
|
+
executeActionSafe(action, response),
|
|
49
|
+
new Promise(
|
|
50
|
+
(_, reject) => setTimeout(
|
|
51
|
+
() => reject(new Error(`Action timed out after ${ACTION_TIMEOUT_MS}ms`)),
|
|
52
|
+
ACTION_TIMEOUT_MS
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
]).catch((error) => ({
|
|
56
|
+
success: false,
|
|
57
|
+
error: error instanceof Error ? error.message : String(error)
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
const RATE_LIMIT_PATH = join(homedir(), ".stackmemory", "rate-limits.json");
|
|
61
|
+
let rateLimitCache = {};
|
|
62
|
+
let rateLimitCacheDirty = false;
|
|
63
|
+
function loadRateLimits() {
|
|
64
|
+
try {
|
|
65
|
+
if (existsSync(RATE_LIMIT_PATH)) {
|
|
66
|
+
const data = JSON.parse(readFileSync(RATE_LIMIT_PATH, "utf8"));
|
|
67
|
+
const now = Date.now();
|
|
68
|
+
const cleaned = {};
|
|
69
|
+
for (const [ip, record] of Object.entries(data)) {
|
|
70
|
+
const r = record;
|
|
71
|
+
if (r.resetTime > now) {
|
|
72
|
+
cleaned[ip] = r;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return cleaned;
|
|
76
|
+
}
|
|
77
|
+
} catch {
|
|
78
|
+
}
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
function saveRateLimits() {
|
|
82
|
+
if (!rateLimitCacheDirty) return;
|
|
83
|
+
try {
|
|
84
|
+
ensureSecureDir(join(homedir(), ".stackmemory"));
|
|
85
|
+
writeFileSecure(RATE_LIMIT_PATH, JSON.stringify(rateLimitCache));
|
|
86
|
+
rateLimitCacheDirty = false;
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
setInterval(saveRateLimits, 3e4);
|
|
91
|
+
rateLimitCache = loadRateLimits();
|
|
92
|
+
function checkRateLimit(ip) {
|
|
93
|
+
const now = Date.now();
|
|
94
|
+
const record = rateLimitCache[ip];
|
|
95
|
+
if (!record || now > record.resetTime) {
|
|
96
|
+
rateLimitCache[ip] = { count: 1, resetTime: now + RATE_LIMIT_WINDOW_MS };
|
|
97
|
+
rateLimitCacheDirty = true;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
if (record.count >= RATE_LIMIT_MAX_REQUESTS) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
record.count++;
|
|
104
|
+
rateLimitCacheDirty = true;
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
function verifyTwilioSignature(url, params, signature) {
|
|
108
|
+
const authToken = process.env["TWILIO_AUTH_TOKEN"];
|
|
109
|
+
if (!authToken) {
|
|
110
|
+
const isDev = process.env["NODE_ENV"] === "development" || process.env["SKIP_TWILIO_VERIFICATION"] === "true";
|
|
111
|
+
if (isDev) {
|
|
112
|
+
console.warn(
|
|
113
|
+
"[sms-webhook] TWILIO_AUTH_TOKEN not set, skipping verification (dev mode)"
|
|
114
|
+
);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
console.error(
|
|
118
|
+
"[sms-webhook] TWILIO_AUTH_TOKEN not set - rejecting request in production"
|
|
119
|
+
);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const sortedKeys = Object.keys(params).sort();
|
|
123
|
+
let data = url;
|
|
124
|
+
for (const key of sortedKeys) {
|
|
125
|
+
data += key + params[key];
|
|
126
|
+
}
|
|
127
|
+
const hmac = createHmac("sha1", authToken);
|
|
128
|
+
hmac.update(data);
|
|
129
|
+
const expectedSignature = hmac.digest("base64");
|
|
130
|
+
return signature === expectedSignature;
|
|
131
|
+
}
|
|
132
|
+
function parseFormData(body) {
|
|
133
|
+
const params = new URLSearchParams(body);
|
|
134
|
+
const result = {};
|
|
135
|
+
params.forEach((value, key) => {
|
|
136
|
+
result[key] = value;
|
|
137
|
+
});
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
function storeLatestResponse(promptId, response, action) {
|
|
141
|
+
ensureSecureDir(join(homedir(), ".stackmemory"));
|
|
142
|
+
const responsePath = join(
|
|
143
|
+
homedir(),
|
|
144
|
+
".stackmemory",
|
|
145
|
+
"sms-latest-response.json"
|
|
146
|
+
);
|
|
147
|
+
writeFileSecure(
|
|
148
|
+
responsePath,
|
|
149
|
+
JSON.stringify({
|
|
150
|
+
promptId,
|
|
151
|
+
response,
|
|
152
|
+
action,
|
|
153
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
function storeIncomingRequest(from, message) {
|
|
158
|
+
ensureSecureDir(join(homedir(), ".stackmemory"));
|
|
159
|
+
const requestPath = join(
|
|
160
|
+
homedir(),
|
|
161
|
+
".stackmemory",
|
|
162
|
+
"sms-incoming-request.json"
|
|
163
|
+
);
|
|
164
|
+
writeFileSecure(
|
|
165
|
+
requestPath,
|
|
166
|
+
JSON.stringify({
|
|
167
|
+
from,
|
|
168
|
+
message,
|
|
169
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
170
|
+
processed: false
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
function getIncomingRequest() {
|
|
175
|
+
const requestPath = join(
|
|
176
|
+
homedir(),
|
|
177
|
+
".stackmemory",
|
|
178
|
+
"sms-incoming-request.json"
|
|
179
|
+
);
|
|
180
|
+
if (!existsSync(requestPath)) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const data = JSON.parse(readFileSync(requestPath, "utf-8"));
|
|
185
|
+
if (data.processed) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
return data;
|
|
189
|
+
} catch {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function markRequestProcessed() {
|
|
194
|
+
const requestPath = join(
|
|
195
|
+
homedir(),
|
|
196
|
+
".stackmemory",
|
|
197
|
+
"sms-incoming-request.json"
|
|
198
|
+
);
|
|
199
|
+
if (!existsSync(requestPath)) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
const data = JSON.parse(readFileSync(requestPath, "utf-8"));
|
|
204
|
+
data.processed = true;
|
|
205
|
+
writeFileSecure(requestPath, JSON.stringify(data));
|
|
206
|
+
} catch {
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async function handleSMSWebhook(payload) {
|
|
210
|
+
const { From, Body } = payload;
|
|
211
|
+
if (Body && Body.length > MAX_SMS_BODY_LENGTH) {
|
|
212
|
+
console.log(`[sms-webhook] Body too long: ${Body.length} chars`);
|
|
213
|
+
return { response: "Message too long. Max 1000 characters." };
|
|
214
|
+
}
|
|
215
|
+
if (From && From.length > MAX_PHONE_LENGTH) {
|
|
216
|
+
console.log(
|
|
217
|
+
`[sms-webhook] Phone number too long: ${From.length} chars (max ${MAX_PHONE_LENGTH}): ${From.substring(0, 30)}...`
|
|
218
|
+
);
|
|
219
|
+
return { response: "Invalid phone number." };
|
|
220
|
+
}
|
|
221
|
+
console.log(`[sms-webhook] Received from ${From}: ${Body}`);
|
|
222
|
+
if (isCommand(Body)) {
|
|
223
|
+
console.log(`[sms-webhook] Processing command: ${Body}`);
|
|
224
|
+
const cmdResult = await processCommand(From, Body);
|
|
225
|
+
if (cmdResult.handled) {
|
|
226
|
+
if (cmdResult.response) {
|
|
227
|
+
sendCommandResponse(cmdResult.response).catch(console.error);
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
response: cmdResult.response || "Command processed",
|
|
231
|
+
action: cmdResult.action,
|
|
232
|
+
queued: false
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const result = processIncomingResponse(From, Body);
|
|
237
|
+
if (!result.matched) {
|
|
238
|
+
if (result.prompt) {
|
|
239
|
+
return {
|
|
240
|
+
response: `Invalid response. Expected: ${result.prompt.options.map((o) => o.key).join(", ")}`
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
storeIncomingRequest(From, Body);
|
|
244
|
+
console.log(
|
|
245
|
+
`[sms-webhook] Stored new request from ${From}: ${Body.substring(0, 50)}...`
|
|
246
|
+
);
|
|
247
|
+
return { response: "Got it! Your request has been queued." };
|
|
248
|
+
}
|
|
249
|
+
storeLatestResponse(
|
|
250
|
+
result.prompt?.id || "unknown",
|
|
251
|
+
result.response || Body,
|
|
252
|
+
result.action
|
|
253
|
+
);
|
|
254
|
+
triggerResponseNotification(result.response || Body);
|
|
255
|
+
if (result.action) {
|
|
256
|
+
console.log(`[sms-webhook] Executing action: ${result.action}`);
|
|
257
|
+
const actionResult = await executeActionWithTimeout(
|
|
258
|
+
result.action,
|
|
259
|
+
result.response || Body
|
|
260
|
+
);
|
|
261
|
+
if (actionResult.success) {
|
|
262
|
+
logActionAllowed("sms-webhook", result.action);
|
|
263
|
+
console.log(
|
|
264
|
+
`[sms-webhook] Action completed: ${(actionResult.output || "").substring(0, 200)}`
|
|
265
|
+
);
|
|
266
|
+
return {
|
|
267
|
+
response: `Done! Action executed successfully.`,
|
|
268
|
+
action: result.action,
|
|
269
|
+
queued: false
|
|
270
|
+
};
|
|
271
|
+
} else {
|
|
272
|
+
logActionBlocked(
|
|
273
|
+
"sms-webhook",
|
|
274
|
+
result.action,
|
|
275
|
+
actionResult.error || "unknown"
|
|
276
|
+
);
|
|
277
|
+
console.log(`[sms-webhook] Action failed: ${actionResult.error}`);
|
|
278
|
+
queueAction(
|
|
279
|
+
result.prompt?.id || "unknown",
|
|
280
|
+
result.response || Body,
|
|
281
|
+
result.action
|
|
282
|
+
);
|
|
283
|
+
return {
|
|
284
|
+
response: `Action failed, queued for retry: ${(actionResult.error || "").substring(0, 50)}`,
|
|
285
|
+
action: result.action,
|
|
286
|
+
queued: true
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
response: `Received: ${result.response}. Next action will be triggered.`
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function escapeAppleScript(str) {
|
|
295
|
+
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").substring(0, 200);
|
|
296
|
+
}
|
|
297
|
+
function triggerResponseNotification(response) {
|
|
298
|
+
const safeMessage = escapeAppleScript(`SMS Response: ${response}`);
|
|
299
|
+
try {
|
|
300
|
+
execFileSync(
|
|
301
|
+
"osascript",
|
|
302
|
+
[
|
|
303
|
+
"-e",
|
|
304
|
+
`display notification "${safeMessage}" with title "StackMemory" sound name "Glass"`
|
|
305
|
+
],
|
|
306
|
+
{ stdio: "ignore", timeout: 5e3 }
|
|
307
|
+
);
|
|
308
|
+
} catch {
|
|
309
|
+
}
|
|
310
|
+
try {
|
|
311
|
+
const signalPath = join(homedir(), ".stackmemory", "sms-signal.txt");
|
|
312
|
+
writeFileSecure(
|
|
313
|
+
signalPath,
|
|
314
|
+
JSON.stringify({
|
|
315
|
+
type: "sms_response",
|
|
316
|
+
response,
|
|
317
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
318
|
+
})
|
|
319
|
+
);
|
|
320
|
+
} catch {
|
|
321
|
+
}
|
|
322
|
+
console.log(`
|
|
323
|
+
*** SMS RESPONSE RECEIVED: "${response}" ***`);
|
|
324
|
+
console.log(`*** Run: stackmemory notify run-actions ***
|
|
325
|
+
`);
|
|
326
|
+
}
|
|
327
|
+
function twimlResponse(message) {
|
|
328
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
329
|
+
<Response>
|
|
330
|
+
<Message>${escapeXml(message)}</Message>
|
|
331
|
+
</Response>`;
|
|
332
|
+
}
|
|
333
|
+
function escapeXml(str) {
|
|
334
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
335
|
+
}
|
|
336
|
+
function startWebhookServer(port = 3456) {
|
|
337
|
+
const server = createServer(
|
|
338
|
+
async (req, res) => {
|
|
339
|
+
const url = parseUrl(req.url || "/", true);
|
|
340
|
+
if (url.pathname === "/health") {
|
|
341
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
342
|
+
res.end(JSON.stringify({ status: "ok" }));
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if ((url.pathname === "/sms" || url.pathname === "/sms/incoming" || url.pathname === "/webhook") && req.method === "POST") {
|
|
346
|
+
const clientIp = req.socket.remoteAddress || "unknown";
|
|
347
|
+
logWebhookRequest(
|
|
348
|
+
"sms-webhook",
|
|
349
|
+
req.method || "POST",
|
|
350
|
+
url.pathname || "/sms",
|
|
351
|
+
clientIp
|
|
352
|
+
);
|
|
353
|
+
if (!checkRateLimit(clientIp)) {
|
|
354
|
+
logRateLimit("sms-webhook", clientIp);
|
|
355
|
+
res.writeHead(429, {
|
|
356
|
+
"Content-Type": "text/xml",
|
|
357
|
+
"Retry-After": "60"
|
|
358
|
+
});
|
|
359
|
+
res.end(twimlResponse("Too many requests. Please try again later."));
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const contentType = req.headers["content-type"] || "";
|
|
363
|
+
if (!contentType.includes("application/x-www-form-urlencoded")) {
|
|
364
|
+
logContentTypeInvalid("sms-webhook", contentType, clientIp);
|
|
365
|
+
res.writeHead(400, { "Content-Type": "text/xml" });
|
|
366
|
+
res.end(twimlResponse("Invalid content type"));
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
let body = "";
|
|
370
|
+
let bodyTooLarge = false;
|
|
371
|
+
req.on("data", (chunk) => {
|
|
372
|
+
body += chunk;
|
|
373
|
+
if (body.length > MAX_BODY_SIZE) {
|
|
374
|
+
bodyTooLarge = true;
|
|
375
|
+
logBodyTooLarge("sms-webhook", body.length, clientIp);
|
|
376
|
+
req.destroy();
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
req.on("end", async () => {
|
|
380
|
+
if (bodyTooLarge) {
|
|
381
|
+
res.writeHead(413, { "Content-Type": "text/xml" });
|
|
382
|
+
res.end(twimlResponse("Request too large"));
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
try {
|
|
386
|
+
const payload = parseFormData(
|
|
387
|
+
body
|
|
388
|
+
);
|
|
389
|
+
const twilioSignature = req.headers["x-twilio-signature"];
|
|
390
|
+
const webhookUrl = `${req.headers["x-forwarded-proto"] || "http"}://${req.headers.host}${req.url}`;
|
|
391
|
+
if (twilioSignature && !verifyTwilioSignature(
|
|
392
|
+
webhookUrl,
|
|
393
|
+
payload,
|
|
394
|
+
twilioSignature
|
|
395
|
+
)) {
|
|
396
|
+
logSignatureInvalid("sms-webhook", clientIp);
|
|
397
|
+
console.error("[sms-webhook] Invalid Twilio signature");
|
|
398
|
+
res.writeHead(401, { "Content-Type": "text/xml" });
|
|
399
|
+
res.end(twimlResponse("Unauthorized"));
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const result = await handleSMSWebhook(payload);
|
|
403
|
+
res.writeHead(200, { "Content-Type": "text/xml" });
|
|
404
|
+
res.end(twimlResponse(result.response));
|
|
405
|
+
} catch (err) {
|
|
406
|
+
console.error("[sms-webhook] Error:", err);
|
|
407
|
+
res.writeHead(500, { "Content-Type": "text/xml" });
|
|
408
|
+
res.end(twimlResponse("Error processing message"));
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (url.pathname === "/sms/status" && req.method === "POST") {
|
|
414
|
+
let body = "";
|
|
415
|
+
req.on("data", (chunk) => {
|
|
416
|
+
body += chunk;
|
|
417
|
+
});
|
|
418
|
+
req.on("end", () => {
|
|
419
|
+
try {
|
|
420
|
+
const payload = parseFormData(body);
|
|
421
|
+
console.log(
|
|
422
|
+
`[sms-webhook] Status update: ${payload["MessageSid"]} -> ${payload["MessageStatus"]}`
|
|
423
|
+
);
|
|
424
|
+
const statusPath = join(
|
|
425
|
+
homedir(),
|
|
426
|
+
".stackmemory",
|
|
427
|
+
"sms-status.json"
|
|
428
|
+
);
|
|
429
|
+
const statuses = existsSync(statusPath) ? JSON.parse(readFileSync(statusPath, "utf8")) : {};
|
|
430
|
+
statuses[payload["MessageSid"]] = payload["MessageStatus"];
|
|
431
|
+
writeFileSecure(statusPath, JSON.stringify(statuses, null, 2));
|
|
432
|
+
res.writeHead(200, { "Content-Type": "text/plain" });
|
|
433
|
+
res.end("OK");
|
|
434
|
+
} catch (err) {
|
|
435
|
+
console.error("[sms-webhook] Status error:", err);
|
|
436
|
+
res.writeHead(500);
|
|
437
|
+
res.end("Error");
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (url.pathname === "/status") {
|
|
443
|
+
const config = loadSMSConfig();
|
|
444
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
445
|
+
res.end(
|
|
446
|
+
JSON.stringify({
|
|
447
|
+
enabled: config.enabled,
|
|
448
|
+
pendingPrompts: config.pendingPrompts.length
|
|
449
|
+
})
|
|
450
|
+
);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (url.pathname === "/request" && req.method === "GET") {
|
|
454
|
+
const request = getIncomingRequest();
|
|
455
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
456
|
+
res.end(JSON.stringify({ request }));
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (url.pathname === "/request/ack" && req.method === "POST") {
|
|
460
|
+
markRequestProcessed();
|
|
461
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
462
|
+
res.end(JSON.stringify({ success: true }));
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if (url.pathname === "/send" && req.method === "POST") {
|
|
466
|
+
let body = "";
|
|
467
|
+
req.on("data", (chunk) => {
|
|
468
|
+
body += chunk;
|
|
469
|
+
if (body.length > MAX_BODY_SIZE) {
|
|
470
|
+
req.destroy();
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
req.on("end", async () => {
|
|
474
|
+
try {
|
|
475
|
+
const payload = JSON.parse(body);
|
|
476
|
+
const message = payload.message || payload.body || "";
|
|
477
|
+
const title = payload.title || "Notification";
|
|
478
|
+
const type = payload.type || "custom";
|
|
479
|
+
if (!message) {
|
|
480
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
481
|
+
res.end(
|
|
482
|
+
JSON.stringify({ success: false, error: "Message required" })
|
|
483
|
+
);
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
const result = await sendNotification({
|
|
487
|
+
type,
|
|
488
|
+
title,
|
|
489
|
+
message
|
|
490
|
+
});
|
|
491
|
+
res.writeHead(result.success ? 200 : 500, {
|
|
492
|
+
"Content-Type": "application/json"
|
|
493
|
+
});
|
|
494
|
+
res.end(JSON.stringify(result));
|
|
495
|
+
} catch (err) {
|
|
496
|
+
console.error("[sms-webhook] Send error:", err);
|
|
497
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
498
|
+
res.end(
|
|
499
|
+
JSON.stringify({
|
|
500
|
+
success: false,
|
|
501
|
+
error: err instanceof Error ? err.message : "Send failed"
|
|
502
|
+
})
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
res.writeHead(404);
|
|
509
|
+
res.end("Not found");
|
|
510
|
+
}
|
|
511
|
+
);
|
|
512
|
+
server.listen(port, () => {
|
|
513
|
+
console.log(`[sms-webhook] Server listening on port ${port}`);
|
|
514
|
+
console.log(
|
|
515
|
+
`[sms-webhook] Incoming messages: http://localhost:${port}/sms/incoming`
|
|
516
|
+
);
|
|
517
|
+
console.log(
|
|
518
|
+
`[sms-webhook] Status callback: http://localhost:${port}/sms/status`
|
|
519
|
+
);
|
|
520
|
+
console.log(`[sms-webhook] Configure these URLs in Twilio console`);
|
|
521
|
+
setInterval(() => {
|
|
522
|
+
try {
|
|
523
|
+
const expiredPrompts = cleanupExpiredPrompts();
|
|
524
|
+
const oldActions = cleanupOldActions();
|
|
525
|
+
if (expiredPrompts > 0 || oldActions > 0) {
|
|
526
|
+
logCleanup("sms-webhook", expiredPrompts, oldActions);
|
|
527
|
+
console.log(
|
|
528
|
+
`[sms-webhook] Cleanup: ${expiredPrompts} expired prompts, ${oldActions} old actions`
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
} catch {
|
|
532
|
+
}
|
|
533
|
+
}, CLEANUP_INTERVAL_MS);
|
|
534
|
+
console.log(
|
|
535
|
+
`[sms-webhook] Cleanup interval: every ${CLEANUP_INTERVAL_MS / 1e3}s`
|
|
536
|
+
);
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
async function smsWebhookMiddleware(req, res) {
|
|
540
|
+
const result = await handleSMSWebhook(req.body);
|
|
541
|
+
res.type("text/xml");
|
|
542
|
+
res.send(twimlResponse(result.response));
|
|
543
|
+
}
|
|
544
|
+
if (process.argv[1]?.endsWith("sms-webhook.js")) {
|
|
545
|
+
const port = parseInt(process.env["SMS_WEBHOOK_PORT"] || "3456", 10);
|
|
546
|
+
startWebhookServer(port);
|
|
547
|
+
}
|
|
548
|
+
export {
|
|
549
|
+
getIncomingRequest,
|
|
550
|
+
handleSMSWebhook,
|
|
551
|
+
markRequestProcessed,
|
|
552
|
+
smsWebhookMiddleware,
|
|
553
|
+
startWebhookServer
|
|
554
|
+
};
|
|
555
|
+
//# sourceMappingURL=sms-webhook.js.map
|