feat: Phase 2 — session monitor, lifecycle, watcher manager

Phase 2 (Session Monitor + Lifecycle):
- src/session-monitor.js: polls sessions.json every 2s for new/ended sessions
  - Detects agents via transcriptDir subdirectory scan
  - Resolves channelId/rootPostId from session key format
  - Emits session-added/session-removed events
  - Handles multi-agent environments
  - Falls back to defaultChannel for non-MM sessions
- src/watcher-manager.js: top-level orchestrator
  - Starts session-monitor, status-watcher, health-server
  - Creates/updates Mattermost status posts on session events
  - Sub-agent linking: children embedded in parent status
  - Offset persistence (save/restore lastOffset on restart)
  - Post recovery on restart (search channel history for marker)
  - SIGTERM/SIGINT graceful shutdown: mark all boxes interrupted
  - CLI: node watcher-manager.js start|stop|status
  - MAX_ACTIVE_SESSIONS enforcement

Integration tests:
- test/integration/session-monitor.test.js: 14 tests
  - Session detection, removal, multi-agent, malformed JSON handling
- test/integration/status-watcher.test.js: 13 tests
  - JSONL parsing, tool_call/result pairs, idle detection, offset recovery

All 86 tests pass (59 unit + 27 integration). make check clean.
This commit is contained in:
sol
2026-03-07 17:32:28 +00:00
parent 43cfebee96
commit e3bd6c52dd
7 changed files with 1339 additions and 3 deletions

View File

@@ -9,7 +9,7 @@
"stop": "node src/watcher-manager.js stop",
"status": "node src/watcher-manager.js status",
"test": "node --test test/unit/*.test.js",
"test:integration": "node --test test/integration/*.test.js"
"test-integration": "node --test test/integration/*.test.js"
},
"dependencies": {
"pino": "^9.14.0"