Commit graph

587 commits

Author SHA1 Message Date
ProofOfConcept
85fa54cba9 journal tools: use NodeType instead of string key matching
- journal_new: create EpisodicSession node with auto-generated key
- journal_tail: query by node_type, not by parsing a monolithic node
- journal_update: find latest EpisodicSession by timestamp
- No string key matching anywhere — all typed
- Fixes journal entries not appearing in 'poc-memory journal tail'
- Also: added --provenance/-p filter to 'poc-memory tail'
- Also: fix early return in surface_observe_cycle store load failure
- Also: scale max_turns by number of steps (50 per step)

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 18:41:10 -04:00
ProofOfConcept
41fcec58f0 main: replace giant match block with Run trait dispatch
Each subcommand enum (Command, NodeCmd, JournalCmd, GraphCmd,
CursorCmd, DaemonCmd, AgentCmd, AdminCmd) now implements a Run
trait. main() becomes `cli.command.run()`.

Standalone dispatch functions (cmd_cursor, cmd_daemon,
cmd_experience_mine) inlined into their enum's Run impl.
No functional changes.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 18:00:23 -04:00
ProofOfConcept
3e410347a2 api: retry transient connection errors, misc fixes
- Retry up to 5 times with exponential backoff (2s, 4s, 8s, 16s)
  on transient errors: IncompleteMessage, connection closed/reset/
  refused, timeouts. Non-transient errors fail immediately.
- tail command: print to stdout instead of stderr
- state_dir rename: output_dir → state_dir throughout knowledge.rs

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 17:48:44 -04:00
ProofOfConcept
5d803441c9 cleanup: kill dead code, fix signal handler safety
- Remove unused now_secs(), parse_json_response, any_alive, Regex import
- Signal handler: replace Mutex with AtomicPtr<c_char> for signal safety
  (Mutex::lock in a signal handler can deadlock if main thread holds it)
- PidGuard Drop reclaims the leaked CString; signal handler just unlinks
- scan_pid_files moved to knowledge.rs as pub helper
- setup_agent_state calls scan_pid_files to clean stale pids on startup

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 15:58:59 -04:00
ProofOfConcept
52703b4637 agents: bail script support, pid file simplification, cleanup
- Bail command moved from hardcoded closure to external script
  specified in agent JSON header ("bail": "bail-no-competing.sh")
- Runner executes script between steps with pid file path as $1,
  cwd = state dir. Non-zero exit stops the pipeline.
- PID files simplified to just the phase name (no JSON) for easy
  bash inspection (cat pid-*)
- scan_pid_files helper deduplicates pid scanning logic
- Timeout check uses file mtime instead of embedded timestamp
- PID file cleaned up on bail/error (not just success)
- output() tool validates key names (rejects pid-*, /, ..)
- Agent log files append instead of truncate
- Fixed orphaned derive and doc comment on AgentStep/AgentDef
- Phase written after bail check passes, not before

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 15:20:29 -04:00
ProofOfConcept
e20aeeeabe agents: phase tracking, pid files, pipelining, unified cycle
- AgentStep with phase labels (=== PROMPT phase:name ===)
- PID files in state dir (pid-{PID} with JSON phase/timestamp)
- Built-in bail check: between steps, bail if other pid files exist
- surface_observe_cycle replaces surface_agent_cycle + journal_agent_cycle
- Reads surface output from state dir instead of parsing stdout
- Pipelining: starts new agent if running one is past surface phase
- link_set upserts (creates link if missing)
- Better error message for context window overflow

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 14:48:42 -04:00
ProofOfConcept
11289667f5 agents: add surface-observe pipeline and agent definition
surface-observe.agent: three-step pipeline (surface → observe → journal)

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 14:27:14 -04:00
ProofOfConcept
84c78f7ae1 session: --session flag, journal agent cycle, conversation bytes config
- memory-search: add --session flag for multi-session support
- config: add surface_conversation_bytes option
- journal_agent_cycle: trigger journal agent every 10KB of conversation
- Session::from_id() constructor

Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
2026-03-26 14:22:29 -04:00
ProofOfConcept
7c0c376e0f render: use backtick-quoted keys and tool call format in link footer
Links now display as \`key\` instead of bare text, and overflow
shows memory_links() tool call format instead of CLI command.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 14:22:21 -04:00
ProofOfConcept
1e1f17f775 store: link_set upserts instead of erroring on missing link
Creates the link if it doesn't exist, avoiding wasted agent turns
from the link_set/link_add confusion.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 14:22:12 -04:00
ProofOfConcept
e176639437 cli: add --state-dir flag to agent run
Override the agent output/input directory for manual testing.
Sets POC_AGENT_OUTPUT_DIR so output() writes there and
{{input:key}} reads from there.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 14:22:05 -04:00
ProofOfConcept
4b32716d3e tools: add output(), journal_tail/new/update tools
- output(key, value): write named results to agent state dir,
  readable via {{input:key}} placeholder
- journal_tail(count): read last N journal entries
- journal_new(title, body): start new ## timestamped entry
- journal_update(body): append to last entry

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 14:21:54 -04:00
ProofOfConcept
77d1d39f3f agents: multi-step agent support
Split agent prompts on === PROMPT === delimiter. Each step runs as
a new user message in the same LLM conversation, so context carries
forward naturally between steps. Single-step agents are unchanged.

- AgentDef.prompt -> AgentDef.prompts: Vec<String>
- AgentBatch.prompt -> AgentBatch.prompts: Vec<String>
- API layer injects next prompt after each text response
- {{conversation:N}} parameterized byte budget for conversation context

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-26 14:21:43 -04:00
ProofOfConcept
baf208281d tui: overlay screens via F-keys (F1=context, F2=agents)
Replaced debug_visible bool with an Overlay enum. F1 shows the
context/debug screen (Ctrl+D still works as alias), F2 shows the
agents screen (placeholder for now — will show surface, observe,
reflect, journal status). Esc closes any overlay.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 03:12:28 -04:00
ProofOfConcept
c5efc6e650 budget: identity = system prompt + personality, memory = loaded nodes
Personality is identity, not memory. Memory is nodes loaded during
the session via tool calls — things I've actively looked at.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 02:28:44 -04:00
ProofOfConcept
79672cbe53 budget: count personality + loaded nodes as memory tokens
mem% was always 0 because memory_tokens was hardcoded to 0. Now
counts personality context + loaded nodes from memory tool calls.
Also calls measure_budget + publish_context_state after memory tool
dispatch so the debug screen updates immediately.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 02:27:25 -04:00
ProofOfConcept
a865285313 tools: add memory_query for structured graph queries
Exposes the full query language as a tool: filtering, sorting, field
selection, neighbor walks. Examples:
  degree > 10 | sort weight | limit 5
  neighbors('identity') | select strength
  key ~ 'journal.*' | count

Also added query_to_string() in the parser so queries return strings
instead of printing to stdout. Updated memory-instructions-core to
list all current tools (added memory_query and journal, removed
CLI commands section and nonexistent memory_search_content).

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 02:22:07 -04:00
ProofOfConcept
9a09a665fb render: show plain node keys in link footer, not CLI commands
Links now show just the key name instead of `poc-memory render KEY`.
The agent uses memory_render tool calls, not bash commands.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 02:15:46 -04:00
ProofOfConcept
9127e61c69 identity: handle .md suffix in file-backed context group keys
Keys like "identity.md" were producing "identity.md.md" lookups.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 02:06:39 -04:00
ProofOfConcept
b88b05fe07 identity: load ContextSource::Store from graph, not flat files
ContextSource::Store was handled identically to File — reading .md
files from disk. Now uses MemoryNode::load() to read from the capnp
store. This is why personality wasn't showing correctly in poc-agent:
store-sourced context groups (cognitive-modes, stuck-toolkit,
instructions, memory-instructions-core) were being looked up as
flat files and silently missing.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 02:04:07 -04:00
ProofOfConcept
164a603c8e cleanup: simplify MemoryNode, deduplicate tool dispatch
- Removed write/search/mark_used static methods from MemoryNode —
  those are store ops, not MemoryNode concerns
- Removed SearchResult duplicate — use query::engine::SearchResult
- Simplified Link to (String, f32) tuple — inline detection moved
  to render()
- Collapsed tool definitions to one-liners
- Consolidated store-mutation tools into with_store() helper
- Supersede uses store directly instead of MemoryNode round-trip

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 01:59:13 -04:00
ProofOfConcept
10932cb67e hippocampus: move MemoryNode + store ops to where they belong
MemoryNode moved from agent/memory.rs to hippocampus/memory.rs — it's
a view over hippocampus data, not agent-specific.

Store operations (set_weight, set_link_strength, add_link) moved into
store/ops.rs. CLI code (cli/graph.rs, cli/node.rs) and agent tools
both call the same store methods now. render_node() delegates to
MemoryNode::from_store().render() — 3 lines instead of 40.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 01:55:21 -04:00
ProofOfConcept
4b97bb2f2e runner: context-aware memory tracking
Memory tools now dispatch through a special path in the runner (like
working_stack) instead of the generic tools::dispatch. This gives them
&mut self access to track loaded nodes:

- memory_render/memory_links: loads MemoryNode, registers in
  context.loaded_nodes (replace if already tracked)
- memory_write: refreshes existing tracked node if present
- All other memory tools: dispatch directly, no tracking needed

The debug screen (context_state_summary) now shows a "Memory nodes"
section listing all loaded nodes with version, weight, and link count.

This is the agent knowing what it's holding — the foundation for
intelligent refresh and eviction.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 01:48:15 -04:00
ProofOfConcept
2c61a3575d tools/memory: direct store calls instead of spawning poc-memory
Every memory tool call was spawning a poc-memory subprocess. Now uses
MemoryNode and direct Store API calls:
- memory_render: MemoryNode::load() + render()
- memory_write: MemoryNode::write() via store.upsert_provenance()
- memory_search: MemoryNode::search() via search engine
- memory_links: MemoryNode::load() + iterate links
- memory_link_add: store.add_relation() with Jaccard strength
- memory_link_set: direct relation mutation
- memory_used: store.mark_used()
- memory_weight_set: direct node.weight mutation
- memory_supersede: MemoryNode::load() + write() + weight_set()

No more Command::new("poc-memory") in this module.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 01:42:33 -04:00
ProofOfConcept
4cc4952234 agent: add MemoryNode for direct store access
MemoryNode is the agent's live view of a loaded memory node — key,
content, links, version, weight. Operations (load, write, search,
mark_used) go directly through the store API instead of spawning
poc-memory subprocesses.

This is the foundation for context-aware memory: the agent can track
which nodes are loaded in its context window, detect changes, and
refresh regions when nodes are updated.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 01:39:48 -04:00
ProofOfConcept
1399bb3a5e runner: call memory_search directly instead of spawning poc-hook
The agent was shelling out to poc-hook which shells out to memory-search.
Now that everything is one crate, just call the library function. Removes
subprocess overhead on every user message.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 01:32:54 -04:00
ProofOfConcept
a00d52214a session: extract Session from memory_search to src/session.rs
Generic session state (session_id, seen set, state directory) doesn't
belong in the memory search module. Now at crate root, re-exported
from memory_search for backwards compatibility.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 01:26:03 -04:00
ProofOfConcept
228815d807 config: unify memory and agent config into single module
Both hippocampus/config.rs and agent/config.rs read from the same
config file (~/.config/poc-agent/config.json5). Having two separate
implementations was a footgun — load_context_groups() was duplicated
three times across the codebase.

Merged into src/config.rs:
- Config (memory settings, global get()/reload())
- AppConfig (agent backend/model settings, figment-based loading)
- SessionConfig (resolved agent session, renamed from agent's Config)
- Single ContextGroup/ContextSource definition used everywhere

Eliminated: duplicate load_context_groups(), duplicate ContextGroup
definition in identity.rs, duplicate config file path constants.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 01:23:12 -04:00
ProofOfConcept
2f3fbb3353 subconscious: flatten agents/ nesting, move prompts in
agents/*.agent definitions and prompts/ now live under
src/subconscious/ alongside the code that uses them.
No more intermediate agents/ subdirectory.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 01:10:25 -04:00
ProofOfConcept
29ce56845d remove old poc-agent directory
Source merged into src/agent/ — these are dead copies.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 01:06:57 -04:00
ProofOfConcept
d5c0e86700 restructure: hippocampus/ for memory, subconscious/ for agents
hippocampus/ — memory storage, retrieval, and consolidation:
  store, graph, query, similarity, spectral, neuro, counters,
  config, transcript, memory_search, lookups, cursor, migrate

subconscious/ — autonomous agents that process without being asked:
  reflect, surface, consolidate, digest, audit, etc.

All existing crate::X paths preserved via re-exports in lib.rs.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-25 01:05:30 -04:00
ProofOfConcept
cfed85bd20 rename: poc-agent → agent, poc-daemon → thalamus
The thalamus: sensory relay, always-on routing. Perfect name for the
daemon that bridges IRC, Telegram, and the agent.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 01:03:51 -04:00
ProofOfConcept
998b71e52c flatten: move poc-memory contents to workspace root
No more subcrate nesting — src/, agents/, schema/, defaults/, build.rs
all live at the workspace root. poc-daemon remains as the only workspace
member. Crate name (poc-memory) and all imports unchanged.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 00:54:12 -04:00
ProofOfConcept
891cca57f8 merge poc-agent into poc-memory as agent/ module
Eliminates the circular dependency between poc-agent and poc-memory by
moving all poc-agent source into poc-memory/src/agent/. The poc-agent
binary now builds from poc-memory/src/bin/poc-agent.rs using library
imports. All poc_agent:: references updated to crate::agent::.

poc-agent/ directory kept for now (removed from workspace members).

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-03-25 00:52:41 -04:00
Kent Overstreet
01abd795ce Surface agent tweaks
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-25 00:21:41 -04:00
ProofOfConcept
9d84dde597 search: exclude seen set when running in agent session
Make Session::from_env() and Session::seen() the public API for
accessing session state. Internal callers converted to use session
methods. Search automatically filters already-surfaced nodes when
POC_SESSION_ID is set.
2026-03-24 23:50:23 -04:00
ProofOfConcept
5c3baeea80 memory-search: fix reflect/surface output parsing
Extract response after '=== RESPONSE ===' marker before parsing
for REFLECTION/NEW RELEVANT MEMORIES. The agent runner dumps the
full log (turns, think blocks) to stdout.
2026-03-24 20:33:50 -04:00
ProofOfConcept
e93e682359 memory-search: add surface/reflect subcommands
`memory-search surface` and `memory-search reflect` run the agent
directly, parse the output, and dump rendered results to stdout.
Useful for testing with `watch memory-search reflect`.
2026-03-24 20:31:21 -04:00
ProofOfConcept
f086815eaa memory: add temperature support to agent defs, update reflect prompt
Thread temperature parameter from agent def header through the API
call chain. Agents can now specify {"temperature": 1.2} in their
JSON header to override the default 0.6.

Also includes Kent's reflect agent prompt iterations.
2026-03-24 20:29:17 -04:00
ProofOfConcept
e88df06cd4 memory: don't auto-run reflect agent yet
Still testing the prompt. The lifecycle and handler are wired up —
just needs the hook call uncommented when ready.
2026-03-24 20:05:41 -04:00
ProofOfConcept
684d1850a7 memory: add reflect agent, refactor agent lifecycle
Add reflect.agent — a lateral-thinking subconscious agent that
observes the conversation and offers occasional reflections when the
conscious mind seems to be missing something.

Refactor memory_search.rs: extract generic agent_cycle_raw() from
the surface-specific code. PID tracking, timeout, spawn/reap logic
is now shared. Surface and reflect agents each have their own result
handler (handle_surface_result, handle_reflect_result) wired through
the common lifecycle.
2026-03-24 20:00:48 -04:00
ProofOfConcept
b6bfb26369 memory: add agent-context placeholder, split context groups
Add `agent: bool` field to ContextGroup (default true) so agents get
personality/identity context without session-specific groups (journal,
where-am-i). Agents now get the full identity.md, reflections.md,
toolkit, etc. instead of the compact core-personality loader.

New {{agent-context}} placeholder resolves all agent-tagged groups
using the same get_group_content() as load-context.
2026-03-24 20:00:36 -04:00
ProofOfConcept
c5ce6e515f fix seen set pollution from agent tool calls
The CLI render command was marking keys as seen in the user's session
whenever POC_SESSION_ID was set. Agent processes inherit POC_SESSION_ID
(they need to read the conversation and seen set), so their tool calls
to poc-memory render were writing to the seen file as a side effect —
bypassing the dedup logic in surface_agent_cycle.

Fix: set POC_AGENT=1 at the start of cmd_run_agent (covers all agents,
not just surface), and guard the CLI render seen-marking on POC_AGENT
being absent. Agents can read the seen set but only surface_agent_cycle
should write to it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 12:35:59 -04:00
ProofOfConcept
9782365b10 add test-conversation tool for debugging transcript parsing
Standalone binary that exercises TailMessages on a transcript file,
reporting progress and timing. Useful for isolating conversation
resolution issues from the full hook pipeline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 12:28:01 -04:00
ProofOfConcept
a48cbe51a8 memory-search: move hook logic to library module, eliminate subprocesses
Move the hook logic from the memory-search binary into a library module
(poc_memory::memory_search) so poc-hook can call it as a direct function
instead of spawning a subprocess with piped stdin.

Also convert the node render call in surface_agent_cycle from
Command::new("poc-memory render") to a direct crate::cli::node::render_node()
call, eliminating another subprocess.

The memory-search binary remains as a thin CLI wrapper for debugging
(--hook reads from stdin) and inspection (show_seen).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 12:27:54 -04:00
ProofOfConcept
78c93dde4d surface agent: add surface_hooks config and reduce search hops
Add surface_hooks config field — list of hook event names that trigger
the surface agent (e.g. ["UserPromptSubmit"]). Empty list disables it.

Reduce surface agent search from 3-5 hops to 2-3 to keep prompt size
under the API endpoint's connection limit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 12:27:40 -04:00
ProofOfConcept
9a0121250b agents: fix resolve_placeholders infinite loop
The placeholder resolver re-scanned from the beginning of the string
after each expansion. If expanded node content contained {{...}}
patterns (which core-personality does), those got expanded recursively.
Cyclic node references caused infinite string growth.

Fix: track a position offset that advances past each substitution,
so expanded content is never re-scanned for placeholders.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 12:27:31 -04:00
ProofOfConcept
38816dc56e transcript: fix close-brace finder to track string boundaries
The backward JSON scanner (JsonlBackwardIter and TailMessages) was
matching } characters inside JSON strings — code blocks full of Rust
braces being the primary offender. This caused:

- Quadratic retry behavior on code-heavy transcripts (wrong object
  boundaries → serde parse failure → retry from different position)
- Inconsistent find_last_compaction_in_file offsets across calls,
  making detect_new_compaction fire repeatedly → context reload on
  every hook call → seen set growing without bound

Fix: add string-boundary tracking with escaped-quote handling to
the close-brace finder loop, matching the existing logic in the
depth-tracking loop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 12:27:22 -04:00
Kent Overstreet
aa46b1d5a6 poc-agent: read context_groups from config instead of hardcoded list
- Remove MEMORY_FILES constant from identity.rs
- Add ContextGroup struct for deserializing from config
- Load context_groups from ~/.config/poc-agent/config.json5
- Check ~/.config/poc-agent/ first for identity files, then project/global
- Debug screen now shows what's actually configured

This eliminates the hardcoded duplication and makes the debug output
match what's in the config file.
2026-03-24 01:53:28 -04:00
Kent Overstreet
966219720a fix: mark surfaced keys as returned so --seen classifies them correctly
The surface agent result consumer in poc-hook was writing to the seen
file but not the returned file, so surfaced keys showed up as
"context-loaded" in memory-search --seen.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 23:06:46 -04:00