The problem
Engineering knowledge is fragmented across GitHub, documentation sites, PDFs, Markdown, local folders and internal wikis. Chat assistants can talk about all of it, but they can’t tell you where an answer came from, and they rarely admit when your material simply doesn’t contain one.
Companion OS is built around one rule:
Every answer carries citations, or an explicit “I don’t know”. There is no third category.
Phase 1 succeeds when a user can import a project, search it, ask project-specific questions, get a citation or an honest refusal for every answer, and come back later without re-explaining context. The first product on the core is a Knowledge Companion; later companions (code, SQL, API, infrastructure) are meant to reuse the same core by configuration rather than by forking it.
Architecture
A modular monolith: one Rust workspace with a crate per bounded context (identity, workspace, knowledge, indexing, search,
conversation), and two binaries, api and worker, built from the same crates with different composition roots.
PostgreSQL holds relational data, the job queue, the outbox, vectors and full-text indexes.
A document goes through one pipeline from source to answer:
fetch → parse → normalize → revision ─(DocumentRevisionCreated)→ chunk → embed
→ write as pending → activate atomically → hybrid search → confidence gate
→ generate → grounding check → durable citations
Dependency direction is part of the architecture, not a convention: contexts may depend only on the kernel, adapters on contexts and platform, apps on everything. Cargo enforces it, and a fitness-function script fails CI on a violation. A self-test deliberately introduces one to prove the check turns red.
Workspace isolation in five layers
The isolation design starts from an uncomfortable assumption: application code will eventually be wrong. So no single layer is trusted to keep one workspace’s data out of another’s.
| Layer | Mechanism |
|---|---|
| L1 Request | Workspace resolved and authorised once, at the edge. |
| L2 Type | A WorkspaceScope token that repositories require; the compiler rejects unscoped access (checked with trybuild tests). |
| L3 Database | Postgres row-level security; ScopedPool sets app.workspace_id per transaction. |
| L4 Storage | Object keys prefixed ws/{workspace_id}/. |
| L5 Index | Every vector and full-text query carries a workspace filter. |
Key decisions
Each one is an accepted ADR with the alternatives written down. A few of them:
Modular monolith with extraction seams
One crate per context, no cross-context joins or foreign keys. A context is extracted into a service only when a measured trigger says so.
Rejected: microservices per context (independent scaling nobody needs yet), a single-crate monolith (boundaries erode silently), serverless.
Hybrid retrieval by default
Dense (pgvector) and lexical (Postgres FTS) retrieval run concurrently and are fused with reciprocal rank fusion, k = 60. Embeddings are systematically weak on rare literal tokens like E_CONN_REFUSED. Longer note →
Rejected: semantic-only with lexical “later”, weighted score fusion, a separate search engine, query-time routing.
Index generations and embedding-model pinning
The tuple (model, dimensions, chunker version) defines an index generation. A new generation builds in the background and is activated atomically. Embedding never fails over to a different model.
Rejected: filtering by model at query time, rebuilding in place, continuous dual-write.
Postgres is the queue; events go through an outbox
Jobs are rows claimed with FOR UPDATE SKIP LOCKED under a lease. Domain events are written to an outbox in the same transaction as the change, relayed to an in-process bus, and handled idempotently. Longer note →
Rejected: Redis/BullMQ, Kafka/NATS, SQS, DB triggers with NOTIFY, CDC.
Server-sent events for chat
Citations are streamed before content, with a time-to-first-token target of p95 < 2 s.
Rejected: WebSocket, long polling, gRPC streaming, non-streaming responses.
Status
Phase 1 is pre-release with no public users. Milestones as of September 2026:
- M0 Governance · 14 ADRs accepted
- M1 Walking skeleton · fitness functions verified in both directions
- M2 Platform foundations · jobs, outbox, envelope encryption
- M3 Identity, workspace, isolation · type-layer isolation proven by the compiler
- M4 Knowledge & ingestion · PDF/DOCX, crawler and S3 adapter not yet
- M5 Indexing + AI gateway · worker wiring and reindex job remain
- M6 Hybrid search · not yet wired into the API
- M7 Conversation, RAG, SSE · provider chat adapters remain
- M8 Memory · M9 Companion composition + web · M10 Evals & release
Engineering evidence
Bugs the tests caught before any user could:
- Chunk overlap corrupted character offsets, so a citation would have quoted the wrong passage.
- Sibling Markdown headings were nested under each other.
- A paragraph without sentence punctuation was never split.
Properties pinned by tests: re-importing unchanged content performs zero writes; one fabricated citation ungrounds the
whole answer; citations arrive before the first token. Security tests cover SSRF (cloud metadata IP, @-userinfo
tricks, IPv4-mapped loopback, DNS rebinding), path traversal, login timing, and refresh-token misuse.
Roadmap
- Rest of Phase 1: memory v1 (bitemporal, with provenance), a second companion defined only by configuration, the full web UI, a ≥ 100-question eval set as a CI gate, load tests and a restore drill, then
v0.1.0. - Phase 2: agents, MCP client and server, a companion SDK, reranking.
- Phase 3: a Tauri desktop app with local-first sync.
- Phase 4: WASM component-model plugins.
Later phases are ordered, not scheduled. Each one starts on a trigger, not a date.