|
1 | 1 | # Architecture |
2 | 2 |
|
| 3 | +## Scope Boundary |
| 4 | +This document treats Phase 11 as shipped baseline. New planned work here is the **Hermes Auto-Capture bridge phase** only. |
| 5 | + |
3 | 6 | ## System Overview |
| 7 | +Use a dual-path integration: |
| 8 | +- **Hermes memory provider (shipped baseline, extended in bridge scope):** lifecycle automation hooks. |
| 9 | +- **Alice MCP server (existing + extended):** explicit recall/review/explain operations. |
4 | 10 |
|
5 | | -Phase 10 keeps the shipped Phase 9 modular monolith and adds a hosted product layer on top of the same continuity core. Alice Core remains authoritative for continuity objects, recall, resume, corrections, approvals, and provenance-backed retrieval. Hosted identity, Telegram, and scheduling orchestrate access to that core; they do not create a second semantics stack. |
| 11 | +This keeps Alice continuity semantics centralized while adding Hermes-native automation points. |
6 | 12 |
|
7 | 13 | ## Technical Stack |
8 | | - |
9 | | -- API and core runtime: Python 3.12 + FastAPI under `apps/api/src/alicebot_api` |
10 | | -- Web app: Next.js 15 + React 19 under `apps/web` |
11 | | -- Background/task surface: `workers` |
12 | | -- Primary data store: Postgres with `pgvector` |
13 | | -- Local support services: Redis and MinIO via `docker-compose.yml` |
14 | | -- Packaging: `alice-core` in `pyproject.toml` |
15 | | -- Test surface: pytest, Vitest, and the Phase 9 evaluation harness |
16 | | - |
17 | | -## Runtime Boundaries |
18 | | - |
19 | | -### Core Data Plane |
20 | | - |
21 | | -Owns: |
22 | | - |
23 | | -- continuity capture and revision persistence |
24 | | -- typed continuity objects and memory revisions |
25 | | -- recall and resumption compilation |
26 | | -- entities, edges, and open loops |
27 | | -- approvals and audit traces |
28 | | -- CLI and MCP semantics |
29 | | -- importer provenance and deterministic dedupe |
30 | | - |
31 | | -### Hosted Control Plane |
32 | | - |
33 | | -Owns: |
34 | | - |
35 | | -- user accounts and auth sessions |
36 | | -- devices and trust levels |
37 | | -- workspaces and bootstrap state |
38 | | -- channel bindings |
39 | | -- user preferences and notification policy |
40 | | -- beta cohorts and feature flags |
41 | | -- telemetry and support tooling |
42 | | - |
43 | | -### Surface Layer |
44 | | - |
45 | | -- local API and CLI |
46 | | -- MCP server |
47 | | -- Telegram adapter and chat routing layer |
48 | | -- web onboarding/settings/admin surfaces |
49 | | -- brief and notification scheduler |
50 | | - |
51 | | -## Phase 10 Core Flows |
52 | | - |
53 | | -### Onboarding |
54 | | - |
55 | | -1. User authenticates with a hosted session. |
56 | | -2. User creates or boots a workspace. |
57 | | -3. Device and channel bindings are established. |
58 | | -4. Preferences and import choices are stored. |
59 | | -5. Alice generates a first brief against the existing continuity core. |
60 | | - |
61 | | -### Inbound Chat |
62 | | - |
63 | | -1. Telegram webhook receives an inbound message. |
64 | | -2. The message is normalized into a common channel message contract. |
65 | | -3. Routing resolves workspace, actor, and best-fit continuity context. |
66 | | -4. Core capture/recall/resume/correction logic executes. |
67 | | -5. A reply is dispatched back through the same channel thread. |
68 | | - |
69 | | -### Approval |
70 | | - |
71 | | -1. Core logic emits an approval request. |
72 | | -2. Chat surface presents approve/reject/context actions. |
73 | | -3. Approval resolution writes back to the same approval and audit objects used by other surfaces. |
74 | | - |
75 | | -### Daily Brief |
76 | | - |
77 | | -1. Scheduler selects workspaces due for delivery. |
78 | | -2. Brief compiler builds a deterministic summary from continuity state. |
79 | | -3. Notification policy and quiet hours are applied. |
80 | | -4. Delivery receipts and failures are recorded for support tooling. |
| 14 | +- Core API/runtime: Python + FastAPI (`apps/api/src/alicebot_api`) |
| 15 | +- Persistence: Postgres (+ existing continuity and provenance schema) |
| 16 | +- Existing surfaces: CLI, MCP, web/admin, workers |
| 17 | +- Hermes integration artifacts: provider plugin + Hermes config (`~/.hermes/config.yaml`) |
| 18 | + |
| 19 | +## Module Boundaries |
| 20 | +### Alice Core (already shipped) |
| 21 | +- Continuity objects, revisions, provenance, corrections, open loops |
| 22 | +- Recall/resume/context compilation |
| 23 | +- Existing MCP/CLI APIs and policy controls |
| 24 | + |
| 25 | +### Hermes Provider Adapter (bridge scope) |
| 26 | +- Extends the shipped Hermes Alice provider rather than replacing it |
| 27 | +- Reads provider config (`mode`, thresholds, feature toggles) |
| 28 | +- Executes lifecycle hooks around Hermes turns/sessions |
| 29 | +- Injects compact prefetch payload into Hermes prompt context |
| 30 | + |
| 31 | +### MCP Tool Surface (explicit workflows) |
| 32 | +Implemented in B1: |
| 33 | +- `alice_prefetch_context` |
| 34 | + |
| 35 | +Planned for B2+ (not shipped in B1): |
| 36 | +- `alice_capture_candidates` |
| 37 | +- `alice_commit_captures` |
| 38 | +- `alice_session_flush` |
| 39 | +- `alice_review_queue` |
| 40 | +- `alice_review_apply` |
| 41 | + |
| 42 | +## Runtime Flows |
| 43 | +### Flow 1: Pre-turn Prefetch |
| 44 | +1. Hermes receives user input. |
| 45 | +2. Provider calls `alice_prefetch_context`. |
| 46 | +3. Alice returns compact continuity payload (summary, relevant memories, open loops, recent decisions/changes, optional resume brief, trust posture). |
| 47 | +4. Provider injects payload into Hermes context before model response. |
| 48 | + |
| 49 | +### Flow 2: Post-response Candidate Extraction (planned B2+) |
| 50 | +1. Hermes emits assistant response. |
| 51 | +2. Provider sends user/assistant turn pair to `alice_capture_candidates`. |
| 52 | +3. Alice returns typed candidates with confidence, trust class, proposed action, evidence snippet, and target object type. |
| 53 | + |
| 54 | +### Flow 3: Post-response Commit (planned B2+) |
| 55 | +1. In `assist`/`auto`, provider submits candidates to `alice_commit_captures`. |
| 56 | +2. Policy gates auto-save vs review queue using type allowlist + confidence threshold. |
| 57 | +3. Writes are idempotent across repeated sync attempts. |
| 58 | + |
| 59 | +### Flow 4: Session-End Flush (planned B2+) |
| 60 | +1. On session end, provider calls `alice_session_flush`. |
| 61 | +2. Alice performs dedupe merge, contradiction checks, open-loop normalization, summary refresh, and review queue updates. |
81 | 62 |
|
82 | 63 | ## Data Model Summary |
83 | | - |
84 | | -### Existing Baseline Objects |
85 | | - |
86 | | -- continuity capture events |
87 | | -- typed continuity objects |
88 | | -- correction events and revisions |
89 | | -- open loops and brief-ready summaries |
90 | | -- import provenance with explicit `source_kind` |
91 | | - |
92 | | -### Phase 10 Additions |
93 | | - |
94 | | -Control-plane tables: |
95 | | - |
96 | | -- `user_accounts` |
97 | | -- `auth_sessions` |
98 | | -- `devices` |
99 | | -- `workspaces` |
100 | | -- `workspace_members` |
101 | | -- `user_preferences` |
102 | | -- `beta_cohorts` |
103 | | -- `feature_flags` |
104 | | - |
105 | | -Channel and scheduler tables: |
106 | | - |
107 | | -- `channel_identities` |
108 | | -- `channel_messages` |
109 | | -- `channel_threads` |
110 | | -- `channel_delivery_receipts` |
111 | | -- `chat_intents` |
112 | | -- `continuity_briefs` |
113 | | -- `approval_challenges` |
114 | | -- `daily_brief_jobs` |
115 | | -- `notification_subscriptions` |
116 | | -- `open_loop_reviews` |
117 | | -- `chat_telemetry` |
118 | | - |
119 | | -## Security and Governance |
120 | | - |
121 | | -- Postgres remains the system of record. |
122 | | -- Hosted identity and channel access add to, but do not bypass, existing approval and provenance discipline. |
123 | | -- Append-only continuity and correction history stay intact. |
124 | | -- Device linking, channel binding, and session expiry are explicit control-plane concerns. |
125 | | -- Consequential actions remain approval-bounded even when initiated from chat. |
126 | | -- Opt-in backup/sync must preserve user isolation and encryption boundaries. |
127 | | - |
128 | | -## Deployment |
129 | | - |
130 | | -### Shipped Baseline |
131 | | - |
132 | | -Canonical local startup path remains: |
133 | | - |
134 | | -```bash |
135 | | -docker compose up -d |
136 | | -./scripts/migrate.sh |
137 | | -./scripts/load_sample_data.sh |
138 | | -APP_RELOAD=false ./scripts/api_dev.sh |
139 | | -``` |
140 | | - |
141 | | -### Phase 10 Production Additions |
142 | | - |
143 | | -- hosted auth/session endpoints |
144 | | -- public webhook ingress for Telegram |
145 | | -- scheduler/worker execution for briefs and notifications |
146 | | -- support/admin visibility for beta operations |
147 | | - |
148 | | -## Testing |
149 | | - |
150 | | -Existing quality gates remain: |
151 | | - |
152 | | -```bash |
153 | | -./.venv/bin/python -m pytest tests/unit tests/integration |
154 | | -pnpm --dir apps/web test |
155 | | -./scripts/run_phase9_eval.sh --report-path eval/reports/phase9_eval_latest.json |
156 | | -``` |
157 | | - |
158 | | -Phase 10 adds targeted verification for: |
159 | | - |
160 | | -- auth and workspace bootstrap |
161 | | -- device and channel linking |
162 | | -- idempotent webhook ingest and outbound delivery |
163 | | -- cross-surface parity between local, CLI, MCP, and Telegram |
164 | | -- daily brief scheduling, quiet hours, and failure handling |
165 | | -- support telemetry and rollout controls |
166 | | - |
167 | | -## Architecture Constraints |
168 | | - |
169 | | -- Phase 10 must not fork semantics between local, CLI, MCP, and Telegram. |
170 | | -- Telegram is another surface on the same core objects, not a separate assistant stack. |
171 | | -- Control-plane additions must not rewrite shipped Alice Core contracts. |
172 | | -- Do not expand connector breadth beyond Telegram in Phase 10 without an explicit roadmap change. |
173 | | -- Keep docs clear about what is shipped OSS baseline versus planned beta surface. |
174 | | - |
175 | | -## Historical Traceability |
176 | | - |
177 | | -Historical planning/control snapshots are retained in local-only internal docs and are intentionally excluded from the public repository. |
| 64 | +### Reuse Existing Baseline Objects |
| 65 | +- continuity object graph |
| 66 | +- correction/supersession history |
| 67 | +- open-loop structures |
| 68 | +- provenance evidence links |
| 69 | + |
| 70 | +### Bridge-Phase Additions/Extensions (required) |
| 71 | +- capture candidate records (including confidence + evidence) |
| 72 | +- review queue records with lifecycle state |
| 73 | +- commit decision audit trail (auto-saved vs queued vs rejected) |
| 74 | + |
| 75 | +## Security And Trust Controls |
| 76 | +- Preserve existing approval/provenance/correction contracts. |
| 77 | +- Never auto-promote speculative single-turn inferences into higher-order trusted patterns. |
| 78 | +- Keep confidence and type gating explicit and configurable by mode. |
| 79 | +- Ensure workspace/session isolation in provider hook calls. |
| 80 | +- Keep credential handling out of logs and redact sensitive provider connection details. |
| 81 | + |
| 82 | +## Deployment Topology |
| 83 | +### Recommended |
| 84 | +- Hermes configured with external `alice` memory provider + enabled Alice MCP server. |
| 85 | +- Provider and MCP may run against local Alice API base URL for local/self-hosted paths. |
| 86 | + |
| 87 | +### Fallback |
| 88 | +- MCP-only mode remains supported when provider plugin is not installed. |
| 89 | + |
| 90 | +## Testing Strategy |
| 91 | +### Bridge-Phase Required Tests |
| 92 | +- prefetch context injection behavior |
| 93 | +- explicit decision/correction auto-capture in `assist` |
| 94 | +- low-confidence inference routes to review queue |
| 95 | +- session-end flush behavior |
| 96 | +- idempotency on duplicate sync attempts |
| 97 | + |
| 98 | +### Existing Gates To Keep |
| 99 | +- unit/integration suites |
| 100 | +- MCP parity checks |
| 101 | +- phase eval/regression harnesses already in repo |
| 102 | + |
| 103 | +## Underspecified Areas (Control Tower Decisions Needed) |
| 104 | +- Canonical candidate/review schema and migration details. |
| 105 | +- Confidence model calibration and versioning policy. |
| 106 | +- Provider package distribution/versioning strategy for Hermes installs. |
| 107 | +- Auth boundary between Hermes provider process and Alice API in hosted deployments. |
| 108 | +- UX surface ownership for review queue beyond MCP parity (web/CLI split not fully specified). |
0 commit comments