1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Persistent auto-memory (Phase 9b, L2) — Claude Code compatible.
//!
//! Memories live as Markdown files with YAML frontmatter under a
//! per-project directory (default: `~/.claude/projects/<slug>/memory/`),
//! indexed by `MEMORY.md`. The format, slug algorithm, and index layout are
//! byte-compatible with Claude Code's auto-memory, so both tools read and
//! write the same directory with zero migration.
//!
//! Layering (docs/phase9-plan.md "Framework Layering Design"):
//! - This module owns the *mechanism*: frontmatter (de)serialization, atomic
//! file writes, row-level index sync, and a `std::sync::Mutex` serializing
//! index read-modify-write within the process (file IO inside the critical
//! section is synchronous and millisecond-scale, so no async lock needed).
//! - The consumer owns the *policy* via [`MemoryConfig`]: root path, index
//! filename, and the prompt template injected into the system prompt.
//!
//! Concurrency model: in-process writes are serialized per [`MemoryStore`];
//! cross-process concurrency (phimint + Claude Code) relies on atomic
//! rename-based writes (last-write-wins, no torn files) plus [`rebuild_index`]
//! as the repair path.
//!
//! Shared-writer contract (the directory has a second writer — Claude Code —
//! and neither side can stop the other from writing):
//! - **Tolerant read**: any frontmatter this module doesn't know — missing
//! stamps (`node_type`, `originSessionId`, …), unknown keys — still parses.
//! Claude Code's documented format is a supported fixture, not an error.
//! - **Faithful write**: updates merge into the existing frontmatter instead of
//! re-rendering it, so keys owned by the other writer survive (see
//! [`MemoryStore::write_memory`]).
//! - **Conservative repair**: a row is identified structurally — by its own
//! link target `- [title](name.md)`, never by a substring of another line.
//! An update refreshes only the row's `— description` tail; a rebuild
//! re-emits existing rows byte-identical and in their curated order
//! ([`index_add`], [`rebuild_index`]) — human titles live only in the index.
//! A rebuild never erases a row it cannot re-derive.
/// Default index file name (Claude Code compatible).
pub const DEFAULT_INDEX_FILENAME: &str = "MEMORY.md";
/// Fixed `metadata.node_type` value for every memory file.
pub const MEMORY_NODE_TYPE: &str = "memory";
/// Allowed `metadata.type` values.
pub const MEMORY_TYPES: = ;
pub use ;
pub use rebuild_index;
pub use ;
pub use atomic_write;
pub use now_iso8601;
pub use ;
pub use ;
// ─────────────────────────────────────────────────────────────────────────────
// Tests (modules 1 & 2)
// ─────────────────────────────────────────────────────────────────────────────