Skip to content

Commit d8e8f2a

Browse files
samrusaniSami Rusani
andauthored
B1: formalize Hermes provider bridge contract (#143)
Co-authored-by: Sami Rusani <sr@samirusani>
1 parent f7c093b commit d8e8f2a

17 files changed

Lines changed: 1092 additions & 545 deletions

ARCHITECTURE.md

Lines changed: 100 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,108 @@
11
# Architecture
22

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+
36
## 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.
410

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.
612

713
## 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.
8162

8263
## 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).

BUILD_REPORT.md

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,73 @@
11
# BUILD_REPORT
22

33
## sprint objective
4-
Implement `P11-R1` provider-runtime security hardening to close the release-blocking findings: SSRF via provider `base_url`, upstream error-detail reflection/persistence, and URL userinfo credential exposure.
4+
Implement Bridge Sprint 1 (`B1`) Hermes provider contract foundation by extending the shipped provider with bridge-phase config normalization, deterministic lifecycle hooks (`prefetch`, `queue_prefetch`, `sync_turn`, `on_session_end`), provider status/readiness validation, and the new automation-oriented MCP prefetch surface `alice_prefetch_context`.
55

66
## completed work
7-
- Added centralized provider URL security policy:
8-
- allowed schemes restricted to `http`/`https`
9-
- rejects userinfo in `base_url`
10-
- blocks loopback, link-local/metadata, RFC1918/private, and other non-global IP literal targets
11-
- Enforced URL policy before persistence and before outbound execution:
12-
- registration paths validate `base_url` before provider row creation
13-
- runtime adapter outbound paths validate `base_url` before helper/network calls
14-
- runtime/test flows hard-reject disallowed stored provider targets
15-
- Sanitized upstream provider error handling:
16-
- provider test/discovery/invoke errors now map to bounded safe messages for API and persistence
17-
- persisted `provider_capabilities.discovery_error` now stores sanitized values
18-
- runtime failure traces store sanitized provider failure messages
19-
- Added serialization hygiene:
20-
- provider serialization now redacts userinfo from `base_url` (defense in depth for legacy rows)
21-
- Added/updated sprint verification coverage:
22-
- blocked target registration cases (`169.254.169.254`, loopback, RFC1918 ranges)
23-
- blocked target runtime/test rejection with no outbound attempt
24-
- userinfo rejection and legacy serialization redaction
25-
- raw upstream detail not reflected or persisted
26-
- Updated control-doc truth rules and roadmap marker to align with active `P11-R1`.
27-
- Updated `REVIEW_REPORT.md` to grade `P11-R1` and explicitly close each in-scope finding.
7+
- Extended (not replaced) the shipped Hermes Alice provider with bridge contract behavior:
8+
- normalized canonical bridge config keys for lifecycle operation
9+
- preserved legacy config-key compatibility
10+
- added provider status/readiness reporting without live network dependency
11+
- added deterministic session-end flush behavior
12+
- added duplicate-write suppression for repeated `sync_turn` and `on_memory_write` callback execution
13+
- fixed capture-queue worker start race and bounded dedupe behavior to avoid suppressing valid later repeats
14+
- Added MCP tool `alice_prefetch_context` with deterministic prefetch text assembled from existing continuity resumption semantics.
15+
- Updated smoke script to emit provider bridge status/lifecycle readiness evidence.
16+
- Updated install and integration docs for bridge contract keys, lifecycle mapping, compatibility keys, and MCP tool surface.
17+
- Added/updated unit and integration coverage for:
18+
- provider config compatibility and invalid-config status
19+
- deterministic lifecycle dedupe/flush behavior
20+
- MCP tool surface stability including `alice_prefetch_context`
21+
- Aligned control-doc truth checks and active control docs to the current bridge-phase baseline.
22+
- Clarified architecture docs so B2+ capture/review surfaces are marked as planned (not shipped in B1).
23+
24+
Legacy compatibility keys preserved:
25+
- `prefetch_limit`
26+
- `max_recent_changes`
27+
- `max_open_loops`
28+
- `include_non_promotable_facts`
29+
- `auto_capture`
30+
- `mirror_memory_writes`
2831

2932
## incomplete work
30-
- None within the `P11-R1` sprint packet scope.
33+
- No code deliverable remains incomplete in B1 scope.
3134

3235
## files changed
33-
- `apps/api/src/alicebot_api/provider_security.py` (new)
34-
- `apps/api/src/alicebot_api/main.py`
35-
- `apps/api/src/alicebot_api/provider_runtime.py`
36-
- `apps/api/src/alicebot_api/local_provider_helpers.py`
37-
- `apps/api/src/alicebot_api/azure_provider_helpers.py`
38-
- `tests/unit/test_provider_security.py` (new)
39-
- `tests/unit/test_provider_runtime.py`
40-
- `tests/integration/test_phase11_provider_runtime_api.py`
36+
- `ARCHITECTURE.md`
37+
- `BUILD_REPORT.md`
38+
- `PRODUCT_BRIEF.md`
39+
- `README.md`
4140
- `ROADMAP.md`
41+
- `RULES.md`
42+
- `docs/integrations/hermes-memory-provider/plugins/memory/alice/__init__.py`
43+
- `apps/api/src/alicebot_api/mcp_tools.py`
44+
- `docs/integrations/hermes-memory-provider.md`
45+
- `docs/integrations/mcp.md`
4246
- `scripts/check_control_doc_truth.py`
43-
- `REVIEW_REPORT.md`
44-
- `BUILD_REPORT.md`
47+
- `scripts/install_hermes_alice_memory_provider.py`
48+
- `scripts/run_hermes_memory_provider_smoke.py`
49+
- `tests/unit/test_hermes_memory_provider.py`
50+
- `tests/unit/test_mcp.py`
51+
- `tests/integration/test_mcp_server.py`
4552

4653
## tests run
4754
1. `python3 scripts/check_control_doc_truth.py`
4855
- Result: PASS
4956
- Output: `Control-doc truth check: PASS`
50-
5157
2. `./.venv/bin/python -m pytest tests/unit tests/integration -q`
5258
- Result: PASS
53-
- Output: `1169 passed in 185.41s (0:03:05)`
54-
55-
3. `./.venv/bin/bandit -r apps/api/src/alicebot_api/provider_runtime.py apps/api/src/alicebot_api/local_provider_helpers.py apps/api/src/alicebot_api/azure_provider_helpers.py apps/api/src/alicebot_api/main.py`
59+
- Output: `1174 passed in 186.28s (0:03:06)`
60+
3. `./.venv/bin/python scripts/run_hermes_memory_provider_smoke.py`
5661
- Result: PASS
57-
- Output: `No issues identified`
62+
- Output summary:
63+
- single external provider enforcement validated
64+
- provider registered with expected tool set
65+
- `structural.bridge_status.ready=true`
66+
- `structural.bridge_status.errors=[]`
67+
- lifecycle hooks status present for `prefetch`, `queue_prefetch`, `sync_turn`, `on_session_end`
5868

5969
## blockers/issues
60-
- No implementation blockers in sprint scope.
61-
- Workspace contains a pre-existing unrelated dirty file not modified by this sprint:
62-
- `README.md`
70+
- None.
6371

6472
## recommended next step
65-
Proceed to security review sign-off for `P11-R1`, then merge once the release hold is formally cleared against the three closed findings.
73+
Proceed with reviewer re-check against B1 acceptance criteria using this updated evidence set.

0 commit comments

Comments
 (0)