7.4 KiB
Modular refactor and seven robustness fixes Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development to implement this plan task-by-task. Steps use checkbox syntax for tracking.
Goal: Deliver the approved business-module architecture and close all seven reproduced failure paths.
Architecture: CommonJS modular monolith. Application owns lifecycle and dependency injection; business modules own API/service/store boundaries; platform and shared code own OS and cross-cutting facilities.
Tech Stack: Node >=22.13, existing SQLite/Playwright/SMTP dependencies, Windows PowerShell.
Spec: docs/superpowers/specs/2026-10-19-modular-refactor-design.md
Global Constraints
- Preserve public URLs, response fields, cookies and CLI entrypoints.
- Preserve state paths, SQLite data, DPAPI identity, AAD and key names.
- Keep dependencies unchanged; tests use NODE_PATH with original checkout and temporary review dependencies.
- No real provider access, production process control or production data writes.
- Worktree: C:/Users/ABS/.codex/worktrees/modular-refactor/Order Notification Automation.
- No push, merge or deployment. Keep working result reviewable in this attached worktree.
Task 1: Mechanical module migration and path foundations
Files: all existing src business files, web feature files, tests; scripts and package.json imports; new src/shared/paths.cjs. Interfaces: preserve exports, except notifications.cjs remains temporarily under modules/notifications until Task 3 splits it. PROJECT_ROOT/WEB_ROOT/SCRIPTS_ROOT/EXTENSION_ROOT exported by shared/paths.
- Inventory current tests and relative/resource path uses with rg.
- Move files to approved directories; rewrite imports from resolved original absolute targets, including fixture paths. Keep src/server.cjs as current entry until Task 5. Move dashboard.cjs to app/dashboard.cjs. Temporarily place notifications.cjs at modules/notifications/notifications.cjs.
- Centralize static roots. Preserve sibling worker lookup and server entry location; map old public web URLs to new physical files.
- Change test discovery to recursive node --test pattern; verify all original 49 test files remain discovered.
- Run module import checks and baseline suite. Record the intermediate baseline honestly; the migration baseline runner ended before a complete result. The final integrated full suite verifies migration with the Unicode fix. Commit isolated migration.
Task 2: Saved SMB bounded execution
Files: src/modules/storage/, tests/storage/ and owned fixtures. Interfaces: StorageService public methods remain compatible. Worker runner accepts AbortSignal and deadline; SmbClient exposes cancellable bounded operations without passing secrets in command arguments.
- Add failure-first tests: hung saved list/check terminates; stop cancels active and queued operations; queue works after timeout; archive result preserves bytes; oversized/invalid IPC fails.
- Execute targeted tests and capture failure before implementation.
- Route saved operations through isolated worker, reuse FileArea guards, observe process exit on cancel/timeout, enforce binary response limits. Stop rejects queued tasks promptly.
- Run storage suites including local fake-worker and archive integrity regressions; commit and report commands/results.
Task 3: Notifications transaction boundary and manual recovery
Files: src/modules/notifications/{store,service,mapping,api}.cjs, web/modules/notifications/view.js, tests/notifications/*. Interfaces: NotificationStore.recover() explicit, NotificationStore.beginSending(batchId) transactional CAS; NotificationService retains existing API and adds retryItem(id,input,actor). API retains routes and adds admin retry with evidence/audit.
- Test constructing second store leaves active prepared batch/items unchanged; cancelled reservation fails beginSending and cannot reach SMTP.
- Test final allowed SMTP failure becomes exhausted; next tick does not send; manual retry requires admin and evidence, audits, resets one item, rejects repeated submission.
- Split mapping, transactions and SMTP orchestration into separate files. Recovery runs only explicitly after application ownership. Preserve unknown-result manual resolution rules.
- Implement accurate exhausted display/action; test API and UI with local fixtures. Commit/report targeted results.
Task 4: BPM/browser, shared redaction and Windows supervisor
Files: modules/bpm/session-manager.cjs and login-form.cjs; shared/redact.cjs; assistant/policy/service and health imports; platform/service/supervisor.cjs and windows-startup.cjs; scripts/service.cjs; relevant tests and fixtures. Interfaces: preserve manager.browser(), extract form helpers with unchanged login security; redact exported centrally; supervisor accepts validated fresh ports provider each launch; Unicode shortcut create/read retain ownership metadata.
- Test browser close then concurrent reconstruction launches exactly once, invalidates dead leases and ignores stale disconnect events; use real headless Chrome fixture.
- Test nested quoted JSON password/cookie and complete Cookie/Authorization values are absent from actual runtime input and persisted history.
- Test real managed child port A to B restart remains healthy, unknown occupants rejected.
- Retain failing Chinese startup-path regression on codepage1252; replace shortcut COM ANSI path handling using Unicode IShellLinkW/IPersistFile, test readback and foreign ownership.
- Implement minimal fixes and form responsibility extraction. Run owned suites, commit/report.
Task 5: Application/HTTP responsibility split and ownership
Files: src/app/{application,bridge,dashboard,assets,request}.cjs; modules/dashboard/{api,auth}.cjs; platform/service/instance-lock.cjs; src/server.cjs; tests/app and tests/service. Interfaces: server exports main/createServer/startService; application acquires acquireInstanceLock(stateDir) before any business store construction and releases on all failure/shutdown paths. notificationStore.recover() called only with ownership acquired.
- Test second main on same temporary state fails before business recovery while first owns batch; first can send once and item becomes sent. Test startup failure releases ownership.
- Split existing bridge/createServer from lifecycle, retain thin formal entry. Extract dashboard auth/business routes, request/security helpers and asset mapping with routing/auth order preserved.
- Implement named-pipe ownership lock keyed by canonical state directory; avoid unsafe stale PID lockfiles. Make cleanup robust after partial initialization.
- Run auth, HTTP, resources, browser navigation, startup and integration regressions; verify unchanged cookie/URL behavior. Commit/report.
Task 6: Review and acceptance
Files: README/development docs/HANDOFF as relevant, all changed modules and tests.
- Independent task reviews and final whole-change review; route meaningful findings back to implementers and verify fixes.
- Check no dangling old imports/resource paths; verify test discovery and encrypted persistence compatibility using temporary state.
- Run full npm test with review NODE_PATH; require zero failures, document official CLI skip honestly.
- Update design/plan progress and architecture documentation. Report exact results and untested real-provider limits; retain reviewable attached checkout.