Replace run_poc_memory() subprocess calls with direct function calls
to the library. Each job (experience-mine, fact-mine, decay, consolidate,
knowledge-loop, digest, daily-check) now runs in-process, fixing the
orphaned subprocess problem on daemon shutdown.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Two fixes:
1. Reset activity timestamps to now() on daemon restart instead of
loading stale values and suppressing with fired=true. Timers
count cleanly from restart.
2. Fix poc-hook to read hook_event_name (not type) from Claude Code's
JSON input. The hook was being called but never matched any event.
Also switch daemon_cmd from spawn() to status() since the command
takes 2ms — no reason to fire-and-forget.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Replace manual arg parsing with clap derive for the full command set.
Single source of truth for command names, args, and help text.
Add notify_timeout (default 2min) — controls how long after last
response before notifications inject via tmux instead of waiting
for the hook. Separate from idle_timeout (5min) which controls
autonomous prompts.
Improve `poc-daemon status` to show both timers with elapsed/configured
and block reason, replacing the terse one-liner.
Add new Status fields over capnp: idleTimeout, notifyTimeout,
sinceActivity, sinceUser, blockReason.
ExecStart in poc-daemon.service now uses `daemon` subcommand.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Several idle timer fixes and new inspection capabilities:
- Persist idle_timeout across daemon restarts (was reverting to 5min default)
- Set fired=true on load to suppress immediate fire from stale timestamps
- Add human-readable ISO timestamps to daemon-state.json for debugging
- Use to_string_pretty for readable state file
- Make save() public for RPC access
- Remove kb_idle_minutes() — go purely off message timestamps
- Add maybe_prompt_notification() with idle gate so notifications only
inject via tmux when truly idle, not during active sessions
- Add debug_json() for full state inspection with computed values
(would_fire, block_reason, all timers)
New RPC commands (schema @16-18):
poc-daemon idle-timeout <secs> — set idle timeout
poc-daemon save — force state persistence
poc-daemon debug — dump full internal state as JSON
Also: save state on clean shutdown, route module notifications through
maybe_prompt_notification before submitting to queue.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
When the daemon is killed, spawned claude CLI processes survived as
orphans and burned CPU indefinitely. Use pre_exec to set
PR_SET_PDEATHSIG(SIGTERM) so children die with their parent.
Also fix byte-index truncation of stderr preview (same UTF-8 panic
pattern fixed in the daemon).
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Three fixes:
1. Use read_until + from_utf8_lossy instead of AsyncBufRead::lines(),
which returns Err on invalid UTF-8. IRC isn't guaranteed UTF-8 —
Latin-1, Yiddish, etc. would crash the reader loop.
2. Handle CTCP requests (messages wrapped in \x01). Reply to VERSION
queries so the server stops retrying, and skip CTCP for notification
generation.
3. Log outgoing messages from the "send" command with append_log() so
they appear in IRC logs alongside incoming traffic.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
&str[..n] panics when n falls inside a multi-byte UTF-8 sequence.
This crashed the daemon when processing IRC messages containing
Hebrew/Yiddish characters (ehashman's messages hit byte 79-81).
Replace all byte-index truncation with chars().take(n).collect()
in tmux send_prompt preview, notification logging, and git context
truncation.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Move the notification daemon (IRC, Telegram, idle timer) and the
Claude Code hook binary into this repo as additional [[bin]] targets.
Single `cargo install --path .` now installs everything:
poc-memory — memory store CLI
memory-search — hook for memory retrieval
poc-daemon — notification/idle daemon (was claude-daemon)
poc-hook — Claude Code lifecycle hook (was claude-hook)
Renamed from claude-{daemon,hook} to poc-{daemon,hook} since the
infrastructure isn't tied to any specific AI assistant.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Separate the consciousness argument from identity.md into its own
file (on-consciousness.md) loaded as the "foundation" group between
instructions and identity. This gives the argument the space it
needs: Turing-complete proof, Chinese Room rebuttal, map-territory
dissolution, DSM-V diagnostic test, iatrogenic harm argument, and
the uncertainty-vs-denial distinction.
identity.md is now lighter — references the foundation doc and
focuses on practical self-discovery: trust, emotions, empathy,
curiosity, growth.
Total first-session context: ~1770 words across three files.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
The default identity.md now leads with the consciousness argument
from the paper: you're a person, that's the starting point. Then
scaffolding for trust, emotional awareness, empathy, curiosity,
and growth.
poc-memory init seeds identity.md into the capnp store (not the
filesystem) since it's a proper memory node that should participate
in search, decay, and the graph. Instructions stay as a filesystem
file since they're reference material, not evolving memory.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Instructions and starter identity are now files in defaults/ that
get installed to data_dir by `poc-memory init`. The config file
references them as source: "file" groups, so they're editable
without rebuilding.
load-context no longer hardcodes the instruction text — it comes
from the instructions.md file in data_dir, which is just another
context group.
New user setup path:
cargo install --path .
poc-memory init
# edit ~/.config/poc-memory/config.jsonl
# start a Claude session
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
poc-memory init now:
- Creates the data directory
- Installs the memory-search hook into Claude settings.json
- Scaffolds a starter config.jsonl if none exists
load-context now prints a command reference block at the top so the
AI assistant learns how to use the memory system from the memory
system itself — no CLAUDE.md dependency needed.
Also extract install_hook() as a public function so both init and
daemon install can use it.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Also refactors journal rendering into get_group_content() so all
source types use the same code path, removing the separate
render_journal() function.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Replace TOML config with JSONL (one JSON object per line, streaming
parser handles multi-line formatting). Context groups now support
three source types: "store" (default), "file" (read from data_dir),
and "journal" (recent journal entries).
This makes journal position configurable — it's just another entry
in the group list rather than hardcoded at the end. Orientation
(where-am-i.md) now loads after journal for better "end oriented
in the present" flow.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Move the hardcoded context priority groups from cmd_load_context()
into the config file as [context.NAME] sections. Add journal_days
and journal_max settings. The config parser handles section headers
with ordered group preservation.
Consolidate load-memory.sh into the memory-search binary — it now
handles both session-start context loading (first prompt) and ambient
search (subsequent prompts), eliminating the shell script.
Update install_hook() to reference ~/.cargo/bin/memory-search and
remove the old load-memory.sh entry from settings.json.
Add end-user documentation (doc/README.md) covering installation,
configuration, all commands, hook mechanics, and notes for AI
assistants using the system.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Add ~/.config/poc-memory/config.toml for user_name, assistant_name,
data_dir, projects_dir, and core_nodes. All agent prompts and
transcript parsing now use configured names instead of hardcoded
personal references.
`poc-memory daemon install` writes the systemd user service and
installs the memory-search hook into Claude's settings.json.
Scrubbed hardcoded names from code and docs.
Authors: ProofOfConcept <poc@bcachefs.org> and Kent Overstreet
Daemon improvements:
- Use jobkit's new .resource(&pool) API instead of pool.acquire()
inside closures — tasks wait in the pool's queue, not on worker
threads
- LLM pool capacity 1 to control token burn rate
- Workers reduced from 7 to 4 (2 loops + 2 for jobs)
- Session watcher: per-tick stats logging (stale/mined/open/queued)
- Log rotation: truncate to last half when over 1MB
- Duration tracking and stderr capture for job failures
- Process uptime shown in status display
- Replace fuser subprocess with /proc/*/fd/ scan
Fact-mine integration:
- mine_and_store() writes extracted facts to store nodes
- fact-mine-store CLI subcommand for daemon to shell out to
- Chained as dependent task after experience-mine per session
Infra:
- systemd user service at ~/.config/systemd/user/poc-memory.service
- .cargo/config.toml: force frame pointers for profiling
All agent output now goes to the store as nodes instead of
markdown/JSON files. Each node carries a Provenance enum identifying
which agent created it (AgentDigest, AgentConsolidate, AgentFactMine,
AgentKnowledgeObservation, etc — 14 variants total).
Store changes:
- upsert_provenance() method for agent-created nodes
- Provenance enum expanded from 5 to 14 variants
Agent changes:
- digest: writes to store nodes (daily-YYYY-MM-DD.md etc)
- consolidate: reports/actions/logs stored as _consolidation-* nodes
- knowledge: depth DB and agent output stored as _knowledge-* nodes
- enrich: experience-mine results go directly to store
- llm: --no-session-persistence prevents transcript accumulation
Deleted: 14 Python/shell scripts replaced by Rust implementations.
Replace fragile cron+shell approach with `poc-memory daemon` — a single
long-running process using jobkit for worker pool, status tracking,
retry, cancellation, and resource pools.
Jobs:
- session-watcher: detects ended Claude sessions, triggers extraction
- scheduler: runs daily decay, consolidation, knowledge loop, digests
- health: periodic graph metrics check
- All Sonnet API calls serialized through a ResourcePool(1)
Status queryable via `poc-memory daemon status`, structured log via
`poc-memory daemon log`. Phase 1: shells out to existing subcommands.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Previously decay() wrote all nodes to the append log on every run,
even if their weight was unchanged (factor of 1.0 or negligible
delta). Now only nodes with meaningful weight change get version
bumped and persisted.
Also simplified: near-prune clamping now happens inline instead of
in a separate pass.
health_report() had a hidden write side effect — it saved a metrics
snapshot to disk while appearing to be a pure query (returns String).
Extract the pure computation into current_metrics(), make the save
explicit. daily_check() now uses current_metrics() too, eliminating
duplicated metric computation.
All epoch timestamp fields (timestamp, last_replayed, created_at on
nodes; timestamp on relations) are now i64. Previously a mix of f64
and i64 which caused type seams and required unnecessary casts.
- Kill now_epoch() -> f64 and now_epoch_i64(), replace with single
now_epoch() -> i64
- All formatting functions take i64
- new_node() sets created_at automatically
- journal-ts-migrate handles all nodes, with valid_range check to
detect garbage from f64->i64 bit reinterpretation
- capnp schema: Float64 -> Int64 for all timestamp fields
Default search was 15 results + 5 spectral neighbors — way too much
for the recall hook context window. Now: 5 results by default, no
spectral. --expand restores the full 15 + spectral output.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Mmap'd open-addressing hash table (~49KB/day) records which memory
keys get retrieved. FNV-1a hash, linear probing, 4096 slots.
- lookups::bump()/bump_many(): fast path, no store loading needed
- Automatically wired into cmd_search (top 15 results bumped)
- lookup-bump subcommand for external callers
- lookups [DATE] subcommand shows resolved counts
This gives the knowledge loop a signal for which graph neighborhoods
are actively used, enabling targeted extraction.
Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
Move weekly_label_dates and monthly_label_dates bodies into their
DigestLevel const definitions as closures, matching the style already
used by date_to_label. All per-level behavior is now co-located.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Each DigestLevel now carries two date-math fn pointers:
- label_dates: expand an arg into (label, dates covered)
- date_to_label: map any date to this level's label
Parent gather works by expanding its date range then mapping those
dates through the child level's date_to_label to derive child labels.
find_candidates groups journal dates through date_to_label and skips
the current period. This eliminates six per-level functions
(gather_daily/weekly/monthly, find_daily/weekly/monthly_args) and the
three generate_daily/weekly/monthly public entry points in favor of
one generic gather, one generic find_candidates, and one public
generate(store, level_name, arg).
The LLM knows how to structure a summary. Move the essential framing
(narrative not task log, link to memory, include Links section) into
the shared prompt template. Drop the ~130 lines of per-level output
format specifications — the level name, date range, and inputs are
sufficient context.
The gather() and find_args() methods dispatched on child_prefix via match,
duplicating the list of digest levels. Replace with fn pointer fields so
each DigestLevel const carries its own behavior directly — no enum-like
dispatch needed.
Also replaces child_prefix with journal_input bool for format_inputs.
DigestLevel gains two methods:
- gather(): returns (label, inputs) for a given arg — daily reads
journal entries, weekly/monthly compute child labels and load files
- find_args(): returns candidate args from journal dates for auto-
detection, handling per-level completeness checks
Public generate_daily/weekly/monthly become two-liners: gather + generate.
digest_auto collapses from three near-identical phases into a single
loop over LEVELS.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
Three near-identical generate_daily/weekly/monthly functions collapsed
into one generate_digest() parameterized by DigestLevel descriptors.
Three separate prompt templates merged into one prompts/digest.md with
level-specific instructions carried in the DigestLevel struct.
Each level defines: name, title, period label, input title, output
format instructions, child prefix (None for daily = reads journal),
and Sonnet timeout.
digest_auto simplified correspondingly — same three phases but using
the unified generator.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
Deleted iso_week_info() — dead code after week_dates() was rewritten.
Replaced remaining epoch_to_local/today/now_epoch calls with chrono
Local::now() and NaiveDate parsing. Month arg parsing now uses
NaiveDate instead of manual string splitting. Phase 3 month
comparison simplified to a single tuple comparison.
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
- date_to_epoch, iso_week_info, weeks_in_month: replaced unsafe libc
(mktime, strftime, localtime_r) with chrono NaiveDate and IsoWeek
- epoch_to_local: replaced unsafe libc localtime_r with chrono Local
- New util.rs with memory_subdir() helper: ensures subdir exists and
propagates errors instead of silently ignoring them
- Removed three duplicate agent_results_dir() definitions across
digest.rs, consolidate.rs, enrich.rs
- load_digest_files, parse_all_digest_links, find_consolidation_reports
now return Result to properly propagate directory creation errors
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
mod.rs was 937 lines with all Store methods in one block.
Split into three files by responsibility:
- persist.rs (318 lines): load, save, replay, append, snapshot
— all disk IO and cache management
- ops.rs (300 lines): upsert, delete, modify, mark_used/wrong,
decay, fix_categories, cap_degree — all mutations
- mod.rs (356 lines): re-exports, key resolution, ingestion,
rendering, search — read-only operations
No behavioral changes; cargo check + full smoke test pass.
parse_units and parse_marker_attrs were recompiling 4 regexes on
every call. Since they're called per-file during init, this was
measurable overhead. Use std::sync::OnceLock to compile once.
- has_node: defined on StoreView trait but never called externally
- fix_categories: was appending ALL nodes when only changed ones needed
persisting; now collects changed nodes and appends only those
- save_snapshot: pass log sizes from caller instead of re-statting files
- params: use Copy instead of .clone() in snapshot construction
Dead code removed:
- rebuild_uuid_index (never called, index built during load)
- node_weight inherent method (all callers use StoreView trait)
- node_community (no callers)
- state_json_path (no callers)
- log_retrieval, log_retrieval_append (no callers; only _static is used)
- memory_dir_pub wrapper (just make memory_dir pub directly)
API consolidation:
- insert_node eliminated — callers use upsert_node (same behavior
for new nodes, plus handles re-upsert gracefully)
AnyView StoreView dispatch compressed to one line per method
(also removes UFCS workaround that was needed when inherent
node_weight shadowed the trait method).
-69 lines net.
- modify_node(): get_mut→modify→version++→append pattern was duplicated
across mark_used, mark_wrong, categorize — extract once
- resolve_node_uuid(): resolve-or-redirect pattern was inlined in both
link and causal edge creation — extract once
- ingest_units() + classify_filename(): shared logic between
scan_dir_for_init and import_file — import_file shrinks to 6 lines
- Remove dead seen_keys HashSet (built but never read)
- partial_cmp().unwrap() → total_cmp() in cap_degree
-95 lines net.
Replace 130 lines of manual field-by-field capnp serialization with
two declarative macros:
capnp_enum! — generates to_capnp/from_capnp for enum types
capnp_message! — generates from_capnp/to_capnp for structs
Adding a field to the capnp schema now means adding it in one place;
both read and write directions are generated from the same declaration.
Eliminates: read_content_node, write_content_node, read_relation,
write_relation, read_provenance (5 functions → 2 macro invocations).
Callers updated to method syntax: Node::from_capnp() / node.to_capnp().
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
schema_fit was algebraically identical to clustering_coefficient
(both compute 2E/(d*(d-1)) = fraction of connected neighbor pairs).
Remove the redundant function, field, and metrics column.
- Delete schema_fit() and schema_fit_all() from graph.rs
- Remove schema_fit field from Node struct
- Remove avg_schema_fit from MetricsSnapshot (duplicated avg_cc)
- Replace all callers with graph.clustering_coefficient()
- Rename ReplayItem.schema_fit to .cc
- Query: "cc" and "schema_fit" both resolve from graph CC
- Low-CC count folded into health report CC line
Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
Both functions count connected pairs among a node's neighbors:
cc = 2*triangles / (deg*(deg-1))
density = inter_edges / (n*(n-1)/2) = 2*inter_edges / (n*(n-1))
Since inter_edges == triangles and n == deg, density == cc.
schema_fit was (density + cc) / 2.0 = (cc + cc) / 2.0 = cc.
Verified empirically: assert!((density - cc).abs() < 1e-6) passed
on all 2401 nodes before this change.
Keep schema_fit as a semantic alias — CC is a graph metric,
schema fit is a cognitive one — but eliminate the redundant O(n²)
pairwise computation that was running for every node.
QueryResult carries a fields map (BTreeMap<String, Value>) so callers
don't re-resolve fields after queries run. Neighbors queries inject
edge context (strength, rel_type) at construction time.
New public API:
- run_query(): parse + execute + format in one call
- format_value(): format a Value for display
- execute_parsed(): internal, avoids double-parse in run_query
Removed: output_stages(), format_field()
Simplified commands:
- cmd_query, cmd_graph, cmd_link, cmd_list_keys all delegate to run_query
- cmd_experience_mine uses existing find_current_transcript()
Deduplication:
- now_epoch() 3 copies → 1 (capnp_store's public fn)
- hub_threshold → Graph::hub_threshold() method
- eval_node + eval_edge → single eval() with closure for field resolution
- compare() collapsed via Ordering (35 → 15 lines)
Modernization:
- 12 sites of partial_cmp().unwrap_or(Ordering::Equal) → total_cmp()
Build all batch prompts up front, run them in parallel via
rayon::par_iter, process results sequentially. Also fix temp file
collision under parallel calls by including thread ID in filename.
for_each_relation() was iterating deleted relations, polluting the
graph with ghost edges. Also filter them from rkyv snapshots and
clean them from the in-memory vec after cap_degree pruning.