Commit graph

1144 commits

Author SHA1 Message Date
Kent Overstreet
9bb07bc26a memory.rs: clean up store access and tool dispatch
- Single access() function returns StoreAccess enum (Daemon/Client/None)
- OnceLock for daemon store, thread-local RefCell for client socket
- Remove dispatch() - Tool handlers call jsonargs_* directly
- get_provenance() takes agent ref, no JSON round-trip
- Expose missing graph tools (communities, normalize, link_impact, trace)
- Local tool! macro for cleaner Tool definitions

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 14:27:38 -04:00
Kent Overstreet
fb46ab095d Consolidate memory RPC in tools/memory.rs
- Move memory_rpc(), socket_path(), SocketConn from mcp_server.rs
- Convert remaining callers to typed async API:
  - defs.rs: organize placeholder, run_agent query
  - cli/agent.rs: query resolution (now async)
  - mind/identity.rs: Store context loading
- Re-export socket_path/memory_rpc from mcp_server for compatibility

All external memory access now goes through tools/memory.rs typed API.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 13:39:59 -04:00
Kent Overstreet
5b07a81aa7 CLI/hippocampus: rename core memory functions to memory_*
Aligns function names with tool names for consistency:
- hippocampus: render → memory_render, write → memory_write, etc.
- tools/memory.rs: macro no longer prepends memory_ prefix
- CLI files: use typed async API throughout (graph.rs, journal.rs, admin.rs)

This eliminates the "memory_graph_topology" tool name bug where
graph_* and journal_* tools were incorrectly prefixed.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 13:26:22 -04:00
Kent Overstreet
fa50f1c826 CLI: convert node commands to typed async API
- node.rs: use memory::* typed helpers instead of memory_rpc()
- main.rs: make Run trait async, await all command dispatch
- defs.rs: bridge get_group_content async via block_in_place

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 13:20:04 -04:00
Kent Overstreet
933221f482 memory tools: generate public typed API via macro
The memory_tool! macro now generates two functions:
- jsonargs_*() - internal, takes JSON args for dispatch table
- pub fn name() - typed args, handles RPC-vs-local automatically

Callers can now use typed Rust API:
  memory::write(Some(&agent), "key", "content").await?;
  memory::query(None, "all | type:semantic", Some("full")).await?;

No more manual JSON construction for memory tool calls.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 13:12:11 -04:00
Kent Overstreet
4560ba9230 memory tools: typed hippocampus fns + macro dispatch
Move tool implementations from tools/memory.rs to hippocampus/mod.rs
with proper typed signatures:
  fn name(store, provenance, ...typed args...) -> Result<String>

Optional params take Option<T>, defaults applied in implementation.

tools/memory.rs is now a thin dispatch layer using memory_tool! macro:
  memory_tool!(write, mut, key: [str], content: [str]);
  memory_tool!(search, ref, keys: [Vec<String>], max_hops: [Option<u32>], ...);

~634 lines of boilerplate replaced with ~30 one-liner invocations.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 13:03:24 -04:00
Kent Overstreet
d7a5ac6347 memory tools: simplify provenance handling
Move provenance injection to dispatch() entry point - agent provenance is
always written to args._provenance before routing. Individual tool
functions now just call get_provenance(args) which is sync and simple.

Removes agent parameter from: write, link_add, supersede, journal_new,
journal_update.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 12:08:46 -04:00
Kent Overstreet
dc1049f62d CLI: async runtime + proper RPC fallback plumbing
- main.rs: use #[tokio::main] so CLI has a runtime available
- memory.rs: make run_with_local_store async (no more runtime creation)
- mcp_server.rs: cache socket connection in OnceLock, use block_in_place
  for async fallback when socket unavailable

Fixes "cannot start a runtime from within a runtime" panic when CLI
falls back to local store.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-13 11:23:52 -04:00
Kent Overstreet
7476e9d0db delete rename agent and related code
The organize agents handle renaming as part of their normal work now.
Also simplified resolve_placeholders to build graph internally.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 02:05:58 -04:00
Kent Overstreet
bd9ce3ed09 keys_to_replay_items() -> memory.rs 2026-04-13 01:57:23 -04:00
Kent Overstreet
a08f521b02 defs.rs: convert run_agent query to use RPC
Uses memory_rpc("memory_query", ...) instead of direct search::run_query.
Removes now-unused crate::search import.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 01:54:22 -04:00
Kent Overstreet
b863f77998 defs.rs: convert seed placeholder to use resolve_tool
Uses the existing tool infrastructure instead of direct store access.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 01:49:22 -04:00
Kent Overstreet
c688b812ef defs.rs: convert organize placeholder to use RPC
Uses memory_render RPC instead of direct store access.
Simplifies from ~60 to ~20 lines.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 01:45:12 -04:00
Kent Overstreet
4cfeb9ee2f defs.rs: delete dead placeholders, simplify siblings
- Remove {{targets}}, {{hubs}}, {{node:KEY}}, {{latest_journal}} placeholders
- Add graph_hubs as proper RPC tool (was placeholder, now callable)
- Replace {{latest_journal}} with {{tool: journal_tail ...}} in journal.agent
- Simplify siblings/neighborhood: drop unused cross-links, use simple top-20
- Remove unused store/graph params from resolve_tool()

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 01:37:33 -04:00
Kent Overstreet
de5a6672c3 cleanup: remove dead placeholder code, use RPC for identity loading
- links() in memory.rs: use cached_store() instead of MemoryNode::load()
- identity.rs: use memory_rpc for Store context loading
- defs.rs: delete dead placeholders (topology, nodes/episodes, health, split)
  - agents now use {{tool: graph_topology}} etc instead
- prompts.rs: delete unused format_split_plan_node()

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-13 01:22:08 -04:00
Kent Overstreet
2ab4aef19f CLI: more RPC conversions, delete obsolete commands
- cmd_health: use graph_health RPC
- cmd_topology: new command using graph_topology RPC
- cmd_status: use graph_topology RPC (type counts folded into topology)
- cmd_run_agent: query resolution via memory_query RPC
- Delete cmd_bulk_rename (one-time migration, obsolete)
- Delete cmd_replay_queue, cmd_digest_links (unconscious agents handle)
- format_topology_header: add type counts, takes &Store now

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-12 23:37:05 -04:00
Kent Overstreet
1f6bfb5915 kill cmd_graph, cmd_organize 2026-04-12 23:20:19 -04:00
ProofOfConcept
11f2d5b169 graph_trace, graph_link_impact: convert to RPC tools
Agents can use these to understand graph structure:
- trace: shows node and neighbors grouped by type
- link_impact: analyzes what happens if a link is removed

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 23:16:12 -04:00
ProofOfConcept
f02a23468e graph_normalize_strengths: convert to RPC tool
Agents can use this to check if edge weights are skewed.
Dry run by default, pass apply:true to write changes.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 23:12:42 -04:00
ProofOfConcept
a8d91896a2 graph_communities: new RPC tool, convert cmd_communities
Agents can use graph_communities to discover isolated knowledge
clusters that need better integration.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 23:09:12 -04:00
ProofOfConcept
be9db3fb1a graph: delete cmd_spread, convert cmd_link to RPC
cmd_spread was duplicate of cmd_search/memory_search.
cmd_link now uses memory_links RPC.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 23:07:06 -04:00
Kent Overstreet
70097fa84b kill cli/misc.rs 2026-04-12 23:03:00 -04:00
ProofOfConcept
5a832b1d6c get_group_content: use RPC, delete store-based version
One function that uses memory_rpc (which handles daemon vs local).
Removes 65 lines of duplicate logic.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 23:00:10 -04:00
ProofOfConcept
051198b3d1 memory_search: accept optional params
max_hops (default 3), edge_decay (default 0.3), min_activation
(default 0.01), limit (default 20). No longer reads from store.params.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 22:49:40 -04:00
ProofOfConcept
d1d57267d3 Remove cmd_log and cmd_params
Retrieval log was never used (history covers node log).
Params should come from config, not hardcoded store defaults.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 22:47:58 -04:00
ProofOfConcept
aff872e101 cmd_search: thin wrapper around memory_search RPC
Remove term matching, pipeline stages, mmap/store paths. Just
pass keys to memory_search and print result. For anything fancy,
use memory_query.

-165 lines.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 22:44:59 -04:00
ProofOfConcept
8b59becbab cmd_load_context: use RPC instead of Store::load()
Add get_group_content_rpc() which uses memory_query and memory_render
instead of direct store access. The original get_group_content() stays
for the subconscious path which already has a store open.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 22:32:47 -04:00
Kent Overstreet
a6b93c2255 cli: kill cmd_list_keys
Redundant with query

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 22:27:31 -04:00
Kent Overstreet
ad59596335 cli: add memory_history, remove dump-json/edges/lookups
- Add memory_history MCP tool for version history
- Convert cmd_history to use memory_rpc
- Add raw parameter to memory_render for editing
- Remove unused: dump-json, list-edges, lookup-bump, lookups
- Fix render_node path in defs.rs/subconscious.rs

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 22:24:34 -04:00
Kent Overstreet
3e0c6b039f move render_node() to memory.rs 2026-04-12 22:20:31 -04:00
Kent Overstreet
4b4271f618 cli: convert cmd_edit to use memory_rpc
Add raw parameter to memory_render for getting content without
links footer. cmd_edit now uses memory_render(raw=true) to read
and memory_write to save.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 22:18:28 -04:00
Kent Overstreet
366b17163d cli: convert write/delete/journal-write to use memory_rpc
- cmd_write → memory_write RPC
- cmd_node_delete → new memory_delete MCP tool + RPC
- cmd_journal_write → journal_new RPC

Removes validate_inline_refs and find_current_transcript
(now handled server-side or not needed).

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 22:15:53 -04:00
Kent Overstreet
7842b6fc8b remove legacy feedback commands (used, wrong, gap, etc.)
These were early experiments with manual feedback signals that
never worked well. The scoring system will handle this properly.

Removed:
- CLI: used, wrong, not-relevant, not-useful, gap
- MCP: memory_used
- Store: mark_used, mark_wrong, record_gap, modify_node

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 22:12:02 -04:00
Kent Overstreet
11b58e6b0b cli: convert simple commands to use memory_rpc
Commands now forward to daemon (or fallback to local store):
- query → memory_query
- journal tail → journal_tail
- graph link-set → memory_link_set
- graph link-add → memory_link_add
- weight-set → memory_weight_set
- node rename → memory_rename

Removes ~50 lines of duplicated store access code.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 21:54:34 -04:00
Kent Overstreet
d2a82d4327 memory tools: forward to daemon when not in daemon process
Add STORE_HANDLE global that daemon sets at startup. When set, tools
access store directly. When unset (external process), tools forward
to daemon via MCP socket.

This allows consciousness-claude and poc-memory to import and call
memory tools directly - they'll automatically route through the
daemon socket.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 21:45:59 -04:00
Kent Overstreet
2c0f2065e0 mcp_server: Unix socket server for external tool access
Exposes memory/journal tools over ~/.consciousness/mcp.sock via
JSON-RPC 2.0 (MCP protocol). External processes (consciousness-mcp,
poc-memory) will connect here instead of accessing the store directly.

Handles: initialize, tools/list, tools/call
Dispatches to the same tool handlers the agent uses internally.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 21:45:10 -04:00
Kent Overstreet
72f4f1b617 context: cache role header token lengths
Branch::tokens() was calling tokenizer::encode() on every call for
the role header ("system\n", "user\n", "assistant\n") and trailing
newline. In trim_conversation(), this meant hundreds of encode calls
per trim cycle.

These are fixed strings - cache them with OnceLock on first use.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 20:47:36 -04:00
Kent Overstreet
ac6f1e9294 unconscious: move health refresh outside lock too
refresh_health() was doing Store::load() + compute_graph_health()
while holding the Unconscious lock, causing 12 second stalls.

Split into needs_health_refresh() (quick check) and set_health()
(quick store), with the slow I/O happening outside the lock.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 20:37:54 -04:00
Kent Overstreet
f40d8cfa9d unconscious: release lock during slow spawn work
Split trigger() into phases so the Unconscious mutex is only held briefly:
- reap_finished(): check handles, restore completed autos
- select_to_spawn(): pick agents, take their autos out
- prepare_spawn(): slow work (Store::load, query, Agent::new) - NO LOCK
- complete_spawn()/abort_spawn(): store results back

Previously held the lock for 28+ seconds during Store::load and query
execution. Now lock hold time should be milliseconds.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 20:33:23 -04:00
Kent Overstreet
f56fc3a7c7 locks: add process-wide lock hold time tracking
TrackedMutex and TrackedRwLock wrappers that record hold durations
by source location using #[track_caller]. Stats written to
~/.consciousness/lock-stats.json every second, sorted by max hold time.

Re-exported as crate::Mutex so all locks are instrumented. To disable,
swap the re-export back to tokio::sync::Mutex.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 20:27:42 -04:00
Kent Overstreet
b94e056372 unconscious/subconscious: use Option<AutoAgent> instead of placeholder
Previously, spawning an agent used std::mem::replace with an empty-name
AutoAgent as placeholder. This caused ghost stats entries under "" when
those placeholders accidentally got their stats logged.

Now uses Option<AutoAgent> with .take() - the type honestly represents
that the agent is unavailable while running. Panic recovery in
subconscious now properly recreates the agent from its definition.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 20:11:40 -04:00
Kent Overstreet
33156d9ab3 channels: improve tmux state tracking and config persistence
tmux channel:
- Track connected state per-pane (shows true channel availability)
- Persist pane config on add/remove (survives restarts)
- Remove cleanup_pipes on exit (unnecessary with persisted config)
- Reorder PaneConfig fields for consistency

telegram channel:
- Use json5 crate for config parsing (matches tmux)

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 20:11:34 -04:00
Kent Overstreet
4556e16fd7 enable short backtraces by default
Uses panic_backtrace_config feature to set BacktraceStyle::Short,
so panics show useful backtraces without needing RUST_BACKTRACE=1.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 20:11:27 -04:00
Kent Overstreet
dfab7d0a33 prompts: remove unused replay_queue import
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 16:21:54 -04:00
Kent Overstreet
783046a3f5 selectable: silence unused method warning
The is_selected method is reserved for future per-character
highlight rendering when the module is fully integrated.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 16:10:58 -04:00
Kent Overstreet
195abfaab1 chat: guard pop_line against empty list
Small defensive improvement - only pop markers and invalidate scroll
if lines.pop() actually removed something.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 16:04:43 -04:00
Kent Overstreet
f06c8077e1 research: latent reasoning integration plans for Qwen 3.5 27B
Two research documents:

latent-reasoning-integration-plan.md: Synthesizes 10+ papers on
latent reasoning, identifies which approaches work with finetuning
(vs requiring pretraining from scratch), and maps them to our
APOLLO-Mini training pipeline.

pause-tokens-gdn-recurrence.md: Explores the connection between
token-based latent reasoning and GDN's internal recurrence. Key
insight: pause tokens on Qwen 3.5 trigger both forward passes AND
recurrent state updates, giving double benefit.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 15:50:09 -04:00
Kent Overstreet
dcd647764c user: fix text selection on wrapped lines
scroll_pane: screen_to_item() now properly accounts for wrapped
lines using textwrap to compute actual character positions instead
of just using mouse_x directly.

selectable: new module with PUA markers for wrap-aware selection.
Not yet integrated into chat.rs but ready for future use. Uses
continuation markers to track logical vs visual lines.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 15:49:57 -04:00
Kent Overstreet
ab0f16a3b5 tools: add cd tool for changing working directory
Uses std::env::set_current_dir() syscall so the change affects
all subsequent tool invocations. Supports absolute paths, relative
paths, and ~ expansion.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 15:49:46 -04:00
Kent Overstreet
0612e1bc41 query: MCP tool uses execute_query, add double-quote strings
- MCP memory_query tool now uses execute_query path instead of
  parse_stages, enabling full expression support (content ~, AND/OR,
  neighbors, etc.) instead of just Expr::All
- Parser now accepts double-quoted strings ("foo") in addition to
  single quotes ('foo')
- Added tests for double-quote syntax
- Removed dead resolve_field_str function from memory.rs

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-12 13:30:00 -04:00