ServiceChannel webhook processor, proposal approval cards, attachment auto-post, CollabSupport commands, and Docker deployment configuration. Co-authored-by: Cursor <cursoragent@cursor.com>
5.8 KiB
5.8 KiB
ServChan Refactor Log
Date: 2026-05-28
Operator: Grok (assisting jmcqueen)
Phase: Initial cleanup & modularization (pre-security hardening)
Backup Performed
Primary backup (filesystem tarball):
- Location:
~/backups/ServChan-pre-refactor-20260528-122917.tar.gz - Size: 22 MB
- Exclusions:
node_modules/,.git/(none existed),logs/,*.csv,*.json(large data files),AppleTVEnriched* - Created with:
tar -czf ...from/Users/jmcqueen/Docker
Note on version control:
- At the time of backup, this directory was not a git repository (
fatal: not a git repository). - The tarball is the authoritative rollback artifact for this refactor.
Rollback instructions:
- Stop any running containers:
docker compose down cd /Users/jmcqueen/Dockerrm -rf ServChan/(or move the current tree aside)tar -xzf ~/backups/ServChan-pre-refactor-20260528-122917.tar.gzcd ServChan && docker compose up --build
Goals of This Refactor Pass
- Make
src/the single source of truth with a clean, logical structure. - Thin
index.jsto pure bootstrap. - Rationalize the multiple overlapping Webex clients (bot operations vs. privileged admin/telephony operations).
- Remove dead/broken references to local device integrations that have moved to the remote CollabSupport service.
- Stabilize the core webhook → per-WO room flow.
- Add minimal but useful documentation (README + this log).
- Create a solid base before touching high-risk security items (secrets in config.json, etc.).
Key Decisions Captured During Planning
- Webex clients: Keep a deliberate split.
botClient.jsfor standard ServChan bot actions (messages, rooms, memberships using the bot token). SeparateadminClient.js(or telephony client) for DECT/phone lookups that require a different privileged token/scope. - Remote services:
avStatus,woSummary,woHistory,woAttachments(and phone status) now primarily delegate to the external CollabSupport service (CS_API_BASE). Local heavy device libraries (meraki, mdm, red, atlas, optisigns, deviceService, phoneService) are obsolete for current operations and will be removed or isolated. - No git history at start of work — rely on the tarball above.
Work Status
(Will be updated as the refactor progresses)
- Full backup created and verified
- Started core webhook logic extraction (webhookProcessor)
- Wired new webhookProcessor into the live /webhook route in index.js (old functions marked LEGACY but left in place for safety during transition)
- Moved the entire remaining legacy block (createWebexSpace, addMember, postToWebexSpace, old processWebhook, summarizeTicketDescription, cleanupOldLogs, etc.) into src/legacy/old-index-helpers.js. index.js is now a thin ~108-line orchestrator.
Step 4 - Thin webexService Wrapper (2026-05-28)
- Created
src/services/webexService.js— a thin service layer overbotClient. - Provides the same low-level interface (
createRoom,addMember,sendMarkdown) for drop-in compatibility with the currentwebhookProcessor. - Also includes higher-level ServChan-specific helpers (
createWorkOrderRoom,addDefaultMembers,postWorkOrderMessage). - Wired into
index.js: thewebhookProcessornow receives aWebexServiceinstance instead of rawbotClient. - This improves isolation, testability, and gives a clear place for future Webex business logic.
Step 3 - Consolidate Summarizer (2026-05-28)
- Moved the initial WorkOrderCreated description summarizer (
summarizeTicketDescription) from the legacy file intosrc/integrations/xai/client.jsas a proper, well-documented export. - Updated
index.jsto import the summarizer from the canonical xAI integration module. - Cleaned up
src/legacy/old-index-helpers.js(removed the summarizer and updated its header). - The legacy file is now significantly smaller and closer to being deletable.
- All summarization logic for the bot now lives under
src/integrations/xai/.
Step 2 - Safe DB Layer Improvements (2026-05-28)
- Created
src/db/path.js— centralized, safegetDbPath()that respectsprocess.env.DB_PATHwith the exact same fallback the original production code used. - Updated
src/db/mappings.jsto use the centralized path resolver instead of hardcoding./webex_sc_mappings.db. This was the biggest risk for accidentally creating/connecting to the wrong database file. - Enhanced
runSpaceCleanupto accept an optional{ db }instance so callers can explicitly pass the production connection. - Updated
src/server/app.jsto forward the realdbinstance to the cleanup test endpoint. - No database files were moved, renamed, or had new ones created. The production DB remains exactly where it was.
All changes were designed to reduce the chance of the codebase accidentally using a different SQLite file than the live production bot.
- DB path handling: Hard constraint — production bot actively uses the current DB file. No moves, renames, or changes to the physical DB file/location during this refactor phase. Code changes only (env-driven resolution where safe, without altering the file itself).
DB Constraint (2026-05-28)
The SQLite database backing the live production ServChan bot must remain untouched.
- Do not
mv,cp, or rename any.dbfile. - Do not change the default fallback path in a way that would cause a new DB file to be created in a different location.
- All DB-related work in this phase must be read-only from the code perspective (improving how we resolve the path from
DB_PATHenv when possible) while the actual file stays exactly where production expects it.
Post-Refactor Notes
(Added after completion)
If anything feels off after changes, restore from the tarball above immediately. Do not attempt manual fixes on a broken refactor state without the backup in hand.
Last updated: 2026-05-28 (start of cleanup)