Every public Rust struct and enum that crosses the HTTP/MCP/CLI boundary. Field-level types, defaults, serde tags, since-when annotations. The contract a client implements when it wires up to ai-memory.
Grouped by responsibility: core domain (Tier, Memory, MemoryLink), request/response shapes (Create/Update/Search/List/Recall), governance (GovernanceLevel, ApproverType, GovernancePolicy, GovernedAction, GovernanceDecision), federation (VectorClock, SyncStateEntry, AgentRegistration, NamespaceMetaEntry), pending-action queue (PendingAction, PendingDecision, Approval).
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] · #[serde(rename_all = "snake_case")]#[derive(Debug, Clone, Serialize, Deserialize)]GET /memories/:id and MCP memory_get. Persisted into the memories table; mirrored to FTS5 + HNSW vector index.| field | type | notes |
|---|---|---|
| id | String | REQUUIDv4 primary key. |
| tier | Tier | REQOne of short · mid · long. |
| namespace | String | REQHierarchical path; up to 8 segments; default "global". |
| title | String | REQ1–500 chars; required. |
| content | String | REQ1–65 536 bytes (MAX_CONTENT_SIZE). |
| tags | Vec<String> | DEFDefault []; max 32 tags, 64 chars each. |
| priority | i32 | DEFDefault 5; range 1-10. |
| confidence | f64 | DEFDefault 1.0; range 0.0-1.0. |
| source | String | DEFDefault "api"; closed set: user · claude · hook · api · import. |
| access_count | i64 | Server-tracked; bumps on each memory_get/memory_recall hit. |
| created_at | String | RFC3339; server-stamped. |
| updated_at | String | RFC3339; updated on each memory_update. |
| last_accessed_at | Option<String> | OPTRFC3339; skip_serializing_if = None. |
| expires_at | Option<String> | OPTRFC3339; computed from ttl_secs or tier default. |
| metadata | serde_json::Value | DEFDefault {}; carries governance, scope, agent_id, taxonomy fields. |
#[derive(Debug, Clone, Serialize, Deserialize)]memory_links.| field | type | notes |
|---|---|---|
| source_id | String | REQFK to memories.id. |
| target_id | String | REQFK to memories.id. |
| relation | String | REQOne of: related_to · supersedes · contradicts · derived_from. |
| created_at | String | RFC3339; server-stamped. |
#[derive(Debug, Deserialize)]POST /memories and memory_store. Every field has a server-side default except title + content.| field | type | notes |
|---|---|---|
| tier | Tier | DEFDefault Mid. |
| namespace | String | DEFDefault "global". |
| title | String | REQ1–500 chars. |
| content | String | REQ1–65 536 bytes. |
| tags | Vec<String> | DEFDefault []. |
| priority | i32 | DEFDefault 5. |
| confidence | f64 | DEFDefault 1.0. |
| source | String | DEFDefault "api". |
| expires_at | Option<String> | OPTRFC3339; explicit override. |
| ttl_secs | Option<i64> | OPTConvenience: expires_at = now + ttl_secs. |
| metadata | Value | DEFDefault {}. |
| agent_id | Option<String> | OPTAuto-resolved by identity when omitted. |
| scope | Option<String> | OPTOne of VALID_SCOPES; default "private". |
#[derive(Debug, Deserialize)]PUT /memories/:id and memory_update. Every field is optional — only the present fields are mutated; the rest are preserved.| field | type | notes |
|---|---|---|
| title | Option<String> | OPT1–500 chars when set. |
| content | Option<String> | OPT1–65 536 bytes when set. |
| tier | Option<Tier> | OPTPromoting Mid→Long passes through governance. |
| namespace | Option<String> | OPTRe-namespacing; depth ≤ 8. |
| tags | Option<Vec<String>> | OPTReplaces tag set entirely (not merged). |
| priority | Option<i32> | OPT1-10 range. |
| confidence | Option<f64> | OPT0.0-1.0 range. |
| expires_at | Option<String> | OPTRFC3339. |
| metadata | Option<Value> | OPTReplaces metadata wholesale (not merged). |
#[derive(Debug, Deserialize)]POST /links and memory_link. Creates a directed edge in the KG.| field | type | notes |
|---|---|---|
| source_id | String | REQUUID; must exist in memories. |
| target_id | String | REQUUID; must exist in memories. |
| relation | String | DEFDefault "related_to". |
#[derive(Debug, Deserialize)]POST /memories/forget and memory_forget. Pattern-based delete; archives matched memories rather than hard-deleting.| field | type | notes |
|---|---|---|
| namespace | Option<String> | OPTRestricts the sweep to a namespace. |
| pattern | Option<String> | OPTFTS5 pattern; matches title+content. |
| tier | Option<Tier> | OPTRestricts to one tier. |
#[derive(Debug, Deserialize)]GET /search and body for memory_search. FTS5-backed.| field | type | notes |
|---|---|---|
| q | String | REQFTS5 expression; supports AND/OR/NEAR/"phrase". |
| namespace | Option<String> | OPTRestricts to one namespace prefix. |
| tier | Option<Tier> | OPT |
| limit | Option<usize> | DEFDefault 20. |
| min_priority | Option<i32> | OPT |
| since / until | Option<String> | OPTRFC3339 created_at window. |
| tags | Option<String> | OPTComma-separated; AND semantics. |
| agent_id | Option<String> | OPTFilters by metadata.agent_id exact. |
| as_agent | Option<String> | OPTQuerying agent's namespace position; drives scope filtering. |
#[derive(Debug, Deserialize)]GET /memories and memory_list. Pagination + filter by namespace/tier/tags.| field | type | notes |
|---|---|---|
| namespace | Option<String> | OPT |
| tier | Option<Tier> | OPT |
| limit | Option<usize> | DEFDefault 20. |
| offset | Option<usize> | OPT |
| min_priority | Option<i32> | OPT |
| since / until | Option<String> | OPTRFC3339 window. |
| tags | Option<String> | OPTComma-separated. |
| agent_id | Option<String> | OPT |
#[derive(Debug, Deserialize)]GET /recall. Hybrid 70/30 fusion (FTS5 + HNSW); optional context-budget pruning.| field | type | notes |
|---|---|---|
| context | Option<String> | OPTFree-form context to retrieve against. |
| namespace | Option<String> | OPT |
| limit | Option<usize> | DEFDefault 10. |
| tags | Option<String> | OPT |
| since / until | Option<String> | OPT |
| as_agent | Option<String> | OPTVisibility filter (Task 1.5). |
| budget_tokens | Option<usize> | OPTCap on cumulative tokens; top-N items that fit (Task 1.11). |
#[derive(Debug, Deserialize)]POST /recall and memory_recall. Same shape as RecallQuery but context is required.| field | type | notes |
|---|---|---|
| context | String | REQ |
| namespace | Option<String> | OPT |
| limit | Option<usize> | DEFDefault 10. |
| tags / since / until / as_agent / budget_tokens | … | Same as RecallQuery. |
#[derive(Debug, Serialize)]GET /stats and memory_stats.| field | type | notes |
|---|---|---|
| total | usize | Count of non-archived memories. |
| by_tier | Vec<TierCount> | 3 rows: short / mid / long. |
| by_namespace | Vec<NamespaceCount> | One row per distinct namespace. |
| expiring_soon | usize | Count expiring within 24h. |
| links_count | usize | Total memory_links rows. |
| db_size_bytes | u64 | SQLite file size. |
#[derive(Debug, Serialize)]Stats.by_tier.| field | type | notes |
|---|---|---|
| tier | String | "short" · "mid" · "long" |
| count | usize |
#[derive(Debug, Serialize)]Stats.by_namespace.| field | type | notes |
|---|---|---|
| namespace | String | |
| count | usize |
#[derive(Debug, Clone, PartialEq, Eq)]Allow, MUST reject on Deny, and SHOULD queue + return the pending_id on Pending.pending_id.#[derive(Debug, Clone, Copy, PartialEq, Eq)]action_type column in pending_actions; discriminator for enforcement calls.#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] · #[serde(rename_all = "snake_case")]metadata.governance._agents namespace).metadata.agent_id owner may perform the action.ApproverType.#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] · #[serde(rename_all = "snake_case")]GovernanceLevel::Approve. Externally-tagged."human"; interactive or out-of-band approval.{"agent": "alice"}; specific registered agent must approve.{"consensus": 3}; consensus of N approvers required.#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]metadata.governance. Default policy: { write: Any, promote: Any, delete: Owner, approver: Human }. v0.6.2 (S34) made promote/delete/approver tolerant of missing fields for partial-policy payloads.| field | type | notes |
|---|---|---|
| write | GovernanceLevel | REQRequired — core knob a policy is setting. |
| promote | GovernanceLevel | DEFDefault Any. |
| delete | GovernanceLevel | DEFDefault Owner. |
| approver | ApproverType | DEFDefault Human. |
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]| field | type | notes |
|---|---|---|
| agent_id | String | Approving agent's id. |
| approved_at | String | RFC3339. |
#[derive(Debug, Clone, Serialize, Deserialize)]db::list_pending_actions. Mirrors the pending_actions table.| field | type | notes |
|---|---|---|
| id | String | UUID. |
| action_type | String | store · delete · promote. |
| memory_id | Option<String> | Set for delete/promote; null for pending stores. |
| namespace | String | |
| payload | Value | Action-shaped JSON for replay. |
| requested_by | String | agent_id of requester. |
| requested_at | String | RFC3339. |
| status | String | pending · approved · rejected. |
| decided_by | Option<String> | OPT |
| decided_at | Option<String> | OPT |
| approvals | Vec<Approval> | Consensus vote log (Task 1.10); empty for Human/Agent paths. |
#[derive(Debug, Clone, Serialize, Deserialize)]sync_push.pending_decisions field; peers apply via db::decide_pending_action.| field | type | notes |
|---|---|---|
| id | String | pending_action UUID. |
| approved | bool | true → approve; false → reject. |
| decider | String | agent_id of decider. |
#[derive(Debug, Clone, Serialize, Deserialize)]broadcast_store_quorum) but not the (namespace, standard_id, parent_namespace) tuple, so inheritance-chain walks fall back to auto_detect_parent.| field | type | notes |
|---|---|---|
| namespace | String | |
| standard_id | String | UUID of the standard memory. |
| parent_namespace | Option<String> | OPT |
| updated_at | String | RFC3339. |
#[derive(Debug, Deserialize)]POST /agents/register. Persists into the _agents namespace.| field | type | notes |
|---|---|---|
| agent_id | String | REQStable identifier; max 64 chars. |
| agent_type | String | REQOne of VALID_AGENT_TYPES. |
| capabilities | Option<Vec<String>> | OPTFree-form capability tags. |
#[derive(Debug, Serialize)]POST /agents/register and rows in GET /agents.| field | type | notes |
|---|---|---|
| agent_id | String | |
| agent_type | String | |
| capabilities | Vec<String> | Empty when none registered. |
| registered_at | String | RFC3339. |
| last_seen_at | String | RFC3339; bumps on agent activity. |
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]updated_at this peer has seen from each known remote. Populated lazily on /sync/push and /sync/since. CRDT-lite merge semantics arrive in Task 3a.1; the foundation ships the wire format so adding semantics later does not force a schema migration.| field | type | notes |
|---|---|---|
| entries | BTreeMap<String, String> | DEFpeer agent_id → latest RFC3339 updated_at. |
#[derive(Debug, Clone, Serialize, Deserialize)]sync_state table serialized for diagnostic / API responses. Consumed by Task 3b.2 sync diagnostics.| field | type | notes |
|---|---|---|
| agent_id | String | Local agent's id. |
| peer_id | String | Remote peer's id. |
| last_seen_at | String | RFC3339; latest updated_at seen on receive. |
| last_pulled_at | String | RFC3339; cursor advanced on send. |
usize = 65_536 — hard cap on memory content bytes. Validated at write time.usize = 8 — maximum number of /-delimited segments in a namespace path. Sample: alphaone/engineering/platform/team/squad/pod/role/agent.&[&str] = &["private", "team", "unit", "org", "collective"] — closed set stamped into metadata.scope (Task 1.5). Drives hierarchical visibility matching.POST /agents/register. Persisted; extend carefully.&str = "_agents" — namespace reserved for agent registrations (Task 1.3). Listed via memory_agent_list./-delimited segments. Flat namespaces return 1; empty returns 0.