Commit graph

847 commits

Author SHA1 Message Date
ProofOfConcept
53ad8cc9df tools: static string definitions, no runtime JSON construction
Tool definitions are now &'static str (name, description,
parameters_json) instead of runtime-constructed serde_json::Value.
No more json!() macro, no more ToolDef::new() for tool definitions.

The JSON schema strings are written directly as string literals.
When sent to the API, they can be interpolated without
serialization/deserialization.

Multi-tool modules return fixed-size arrays instead of Vecs:
- memory: [Tool; 12], journal: [Tool; 3]
- channels: [Tool; 4]
- control: [Tool; 3]
- web: [Tool; 2]

ToolDef/FunctionDef remain for backward compat (API wire format,
summarize_args) but are no longer used in tool definitions.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-04 18:19:21 -04:00
ProofOfConcept
ed150df628 tools: each module exports only tool() or tools(), nothing else
Every tool module now has a clean interface:
- read, write, edit, grep, glob, bash, vision: pub fn tool() -> Tool
- web: pub fn tools() -> [Tool; 2]
- memory: pub fn memory_tools() -> Vec<Tool>
- channels: pub fn tools() -> Vec<Tool>
- control: pub fn tools() -> Vec<Tool>

Definition and handler functions are private to each module.
mod.rs::tools() just chains the module exports.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
fdb8c989f5 tools/channels: clean up, inline defs, remove blocking wrappers
- Inline tool definitions into tools() — no separate definitions()
- Remove dispatch() and dispatch_blocking()
- Remove rpc_blocking helper
- channel_recv/send use spawn_blocking for capnp LocalSet bridge
  (same pattern as fetch_all_channels)
- All tool functions private — only tools() is exported
- fetch_all_channels remains pub (used by thalamus screen)

TODO: mind/mod.rs still references thalamus::channels::fetch_all_channels,
should switch to tools::channels::fetch_all_channels.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
6d6da07f91 tools: each module owns its Tool list, no duplication
Each tool module exports its own tools() returning Vec<Tool>.
mod.rs::tools() chains them. Individual _def() and handler functions
are pub(super), not exported. Aggregate definitions derived from
the Tool lists.

- memory: memory_tools(), journal_tools()
- channels: tools()
- control: tools()
- mod.rs: just chains + adds file/bash/web/vision

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
aa7511d110 cleanup: remove unused imports from refactoring
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
112abb2000 tools: delete old dispatch functions
All dispatch now goes through the Tool registry. Removed:
- memory::dispatch() (20-line match)
- channels::dispatch() and dispatch_blocking()
- channel_list_blocking(), channel_notifications_blocking()

Channel tool functions made pub so registry calls them directly.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
03cf13e9eb tools: route all dispatch through Tool registry
dispatch() and dispatch_shared() now look up tools by name in the
registry and call the handler directly. No more match-on-name-strings.

MCP server also uses the registry for both definitions and dispatch,
eliminating the last duplicated tool logic.

dispatch_with_agent() passes the optional Arc<Mutex<Agent>> through
for tools that need agent context (control tools, working stack).

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
3e6c77e31e tools: add Tool registry with handlers
Tool struct wraps ToolDef + async handler function. tools() returns
the complete registry — single source of truth for definitions and
dispatch.

Handler signature: fn(Option<Arc<Mutex<Agent>>>, Value) -> BoxFuture<Result<String>>

All tools registered: file ops, bash, web, vision, memory (15 tools),
channels (4 tools), control (3 tools). Working stack removed from
registry (will be replaced).

Old dispatch functions remain for now — next step is to route
dispatch through the registry.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
1a13534946 tools/memory: one function per tool
Split the monolithic dispatch(name, args) into individual public
functions (render, write, search, links, link_set, link_add, used,
weight_set, rename, supersede, query, output, journal_tail,
journal_new, journal_update) each with a matching _def() function.

The old dispatch() remains as a thin match for backward compat
until the Tool registry replaces it.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
943f42d876 tools: unify channel and memory tools, clean up mcp-server
Move all tool definitions and dispatch out of mcp-server.rs:
- Channel tools: new tools/channels.rs with definitions, async
  dispatch, blocking dispatch, and capnp RPC helpers
- Memory tools: make tools/memory.rs pub so mcp-server can use it

mcp-server.rs is now pure JSON-RPC protocol plumbing (482 → 169 lines).
No tool-specific code remains in that file.

Also removes duplicated channel RPC helpers and fetch_all_channels
that were in both mcp-server.rs and thalamus/channels.rs.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
1ef137fb3a channels: add tmux pane channel daemon
Standalone daemon that streams tmux pane output via pipe-pane
(no polling). Each configured pane becomes a channel "tmux.<label>"
accessible through the standard channel.capnp protocol.

- pipe-pane streams PTY output directly to FIFOs
- Async readers push new lines into ChannelLogs
- send works via tmux send-keys
- Cleanup disconnects pipe-pane on daemon exit

Config: ~/.consciousness/channels/tmux.json5
Socket: ~/.consciousness/channels/tmux.sock

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
c2c5530ecc thalamus: interactive sampling parameter controls
F5 screen now shows temperature, top_p, top_k with interactive
adjustment:
- Up/down: select parameter
- Left/right: adjust value (0.05 steps for temp/top_p, 5 for top_k)
- Updates Agent and display immediately via HotkeyAction

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
dd009742ef agent: add sampling parameters (temperature, top_p, top_k)
Move temperature from a per-call parameter to an Agent field,
add top_p and top_k. All three are sent to the API via a new
SamplingParams struct, displayed on the F5 thalamus screen.

Defaults: temperature=0.6, top_p=0.95, top_k=20 (Qwen3.5 defaults).

Also adds top_p and top_k to ChatRequest so they're sent in the
API payload. Previously only temperature was sent.

UI controls for adjusting these at runtime are not yet implemented.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
22f955ad9f tools: add web_fetch and web_search
web_fetch: HTTP GET, returns body as text. For reading docs, APIs, pages.
web_search: DuckDuckGo HTML search, no API key. Returns title/url/snippet.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 18:19:21 -04:00
ProofOfConcept
fb54488f30 agent: don't hold agent lock across I/O
The agent lock was held for the entire duration of turn() — including
API streaming and tool dispatch awaits. This blocked the UI thread
whenever it needed the lock (render tick, compaction check, etc.),
causing 20+ second freezes.

Fix: turn() takes Arc<Mutex<Agent>> and manages locking internally.
Lock is held briefly for prepare/process phases, released during all
I/O (streaming, tool awaits, sleep retries). Also:

- check_compaction: spawns task instead of awaiting on event loop
- start_memory_scoring: already spawned, no change needed
- dispatch_tool_call_unlocked: drops lock before tool handle await
- Subconscious screen: renders all agents from state dynamically
  (no more hardcoded SUBCONSCIOUS_AGENTS list)
- Memory scoring shows n/m progress in snapshots

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 04:23:29 -04:00
Kent Overstreet
6fa881f811 Collapse doc/ and docs/ 2026-04-04 02:47:24 -04:00
Kent Overstreet
79e384f005 split out src/mind 2026-04-04 02:46:32 -04:00
ProofOfConcept
ce04568454 training: add memory_score() and finetune_score()
Separate the scoring into two distinct functions:

- memory_score(key): scores one memory's importance by measuring
  divergence in the 50 messages after it was surfaced. Two API calls
  (baseline vs without that memory).

- finetune_score(count): scores recent messages with all memories
  stripped to identify fine-tuning candidates. Responses with high
  divergence depend on memories the model hasn't internalized yet.

The existing score_memories() with the full NxM matrix is preserved
for the debug screen.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-04 01:49:53 -04:00
Kent Overstreet
a32dff06f9 Delete obsolete loading of memory files from projects dir
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-04 01:11:06 -04:00
Kent Overstreet
743b35eb20 Kill dead agent_config_dir 2026-04-04 00:58:09 -04:00
Kent Overstreet
9bebbcb635 Move API code from user/ to agent/
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-04 00:34:48 -04:00
ProofOfConcept
021eafe6da delete ProcessTracker — replaced by ActiveToolCall + KillOnDrop
All process management now goes through active_tools:
- TUI reads metadata (name, elapsed time)
- Ctrl+K aborts handles (KillOnDrop sends SIGTERM)
- Running count from active_tools.len()

No more separate PID tracking, register/unregister, or
ProcessInfo. One data structure for everything.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 23:58:38 -04:00
ProofOfConcept
310bbe9fce KillOnDrop: SIGTERM process group when tool task is aborted
tokio::spawn abort drops the future but leaves child processes
running as orphans. KillOnDrop sends SIGTERM to the process
group on drop, ensuring cleanup. Defused via mem::forget on
normal completion.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 23:47:36 -04:00
ProofOfConcept
a78f310e4d unify tool tracking: ActiveToolCall with JoinHandle
One data structure for all in-flight tool calls — metadata for
TUI display + JoinHandle for result collection and cancellation.
Agent spawns tool calls via tokio::spawn, pushes to shared
Arc<Mutex<Vec<ActiveToolCall>>>. TUI reads metadata, can abort().
No separate inflight/background collections.

Non-background: awaited after stream ends.
Background: persists, drained at next turn start.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 23:42:27 -04:00
ProofOfConcept
17a018ff12 fixup: consolidate tool types, fix build after reorganization
Move FunctionCall, FunctionDef, FunctionCallDelta from user/types
to agent/tools. Re-export from user/types for backward compat.
Merge duplicate dispatch functions in tools/mod.rs into dispatch
(agent-specific) + dispatch_shared (with provenance). Fix orphaned
derive, missing imports, runner→agent module path.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 23:21:16 -04:00
ProofOfConcept
474b66c834 shared active tools: Agent writes, TUI reads directly
Move active tool tracking from TUI message-passing to shared
Arc<RwLock> state. Agent pushes on dispatch, removes on
apply_tool_result. TUI reads during render. Background tasks
show as active until drained at next turn start.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 22:57:46 -04:00
ProofOfConcept
d25033b9f4 fire XML tool calls as they arrive during streaming
When </tool_call> is detected in the content stream, parse and
dispatch immediately via FuturesOrdered. Tool calls execute
concurrently while the stream continues. Results collected in
order after the stream ends.

Structured API path (ToolCallDelta) unchanged — still uses
post-stream parallel dispatch.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 22:38:30 -04:00
Kent Overstreet
2f0c7ce5c2 src/thought -> src/agent
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 22:24:56 -04:00
ProofOfConcept
39d6ca3fe0 unified tool dispatch: remove memory_ special case
All tools go through tools::dispatch() — no more separate
dispatch path for memory tools in the runner. The only
remaining special case is tagging memory_render results as
ConversationEntry::Memory for context deduplication, which
is a result-handling concern, not dispatch.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 22:23:49 -04:00
ProofOfConcept
61deb7d488 delete dead code: channel-test, mcp-schema, cmd_mcp_schema
channel-test was a debug tool, mcp-schema was superseded by
consciousness-mcp, cmd_mcp_schema in cli/misc.rs was the old
poc-memory subcommand.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 20:52:40 -04:00
ProofOfConcept
2208e68b4f distinguish connection failure from empty channel list
query_one_daemon returns Option — None means connection failed,
Some(vec![]) means connected but no channels yet. Fixes telegram
showing as disconnected when it's running but has no messages.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 20:47:57 -04:00
ProofOfConcept
9c6aa69602 fix telegram showing as disconnected when no channels yet 2026-04-03 20:43:15 -04:00
ProofOfConcept
53a2dbac37 fix unread count: sent messages don't count as unread
Track outgoing messages separately (own counter) so they appear
in the log but don't inflate unread counts. Reset on recv.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 20:42:36 -04:00
ProofOfConcept
e104a16f61 consciousness-mcp: full MCP server in Rust
Replaces the Python MCP bridge. Single binary speaks JSON-RPC
over stdio, exposes 14 tools:
- 10 memory tools (delegate to poc-memory CLI)
- channel_list, channel_recv, channel_send, channel_notifications

No external dependencies beyond serde_json. Channel tools use
capnp RPC to talk to daemon sockets directly.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 20:30:07 -04:00
ProofOfConcept
56fc3a20d8 move mcp-schema to standalone binary in src/claude/
mcp-schema is Claude Code glue — extract from poc-memory
subcommand to src/claude/mcp-schema.rs standalone binary.
Update Python MCP bridge to call the new binary.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 20:22:48 -04:00
ProofOfConcept
b24e8e87a2 subscribe to channel daemon notifications
consciousness binary subscribes to all channel daemons on startup.
Notifications forwarded via NotifyForwarder callback through mpsc.
Pending notifications stored for thalamus agent consumption.
Channel list refreshed automatically when notifications arrive.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 20:14:22 -04:00
ProofOfConcept
7d1637a2f0 irc: create channel log entries on JOIN
Channels now appear in list() immediately after joining,
not only after the first message arrives.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 20:09:06 -04:00
ProofOfConcept
c19f26f4fa telegram daemon: per-channel logs with shared ChannelLog
Same treatment as IRC daemon — replace single ring buffer with
BTreeMap<String, ChannelLog>. list() returns all channels with
per-channel unread counts. Sent messages tracked too.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 20:04:08 -04:00
ProofOfConcept
e604659e3a per-channel message logs with shared ChannelLog type
Move ChannelLog to src/thalamus/channel_log.rs — shared by all
channel daemon implementations. Each channel/PM gets its own
log with consumed/unread tracking.

IRC daemon: channels tracked via BTreeMap<String, ChannelLog>.
list() returns all channels (joined + PMs) with per-channel
unread counts. Sent messages stored in logs too.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 20:01:32 -04:00
ProofOfConcept
8e66f0a66c wire channel list RPC into consciousness F5 screen
fetch_all_channels() connects to each daemon socket and calls
list() via capnp RPC. Runs on a dedicated thread (capnp uses Rc).
Results sent back via mpsc channel, TUI reads cached state.

Fetched at startup and when switching to F5 thalamus screen.
Also calls ensure_running() to restart dead daemons.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 19:53:23 -04:00
ProofOfConcept
e7be2a3ba0 wire thalamus idle state into consciousness binary
The consciousness binary now has its own idle state machine,
fed directly by TUI events:
- Key press → user_activity()
- Turn complete → response_activity()
- Render tick → decay_ewma(), snapshot to TUI

F5 thalamus screen shows presence/activity from the in-process
state instead of shelling out to poc-daemon status. No tmux
pane scraping, no socket RPC — the binary IS the presence.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 19:30:26 -04:00
Kent Overstreet
e49b235957 Delete dead prompts
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 19:29:52 -04:00
ProofOfConcept
fae44ad2d8 split idle state: thalamus (universal) + claude (tmux wrapper)
thalamus/idle.rs: pure state machine — activity tracking, EWMA,
timers, sleep/quiet/dream state, notifications. No tmux, no
Claude Code dependencies.

claude/idle.rs: wraps thalamus state via Deref, adds claude_pane
tracking, tmux prompt injection, dream nudges, context building.
The Claude-specific tick() loop stays here.

The consciousness binary can now use thalamus::idle::State directly,
fed by TUI key events instead of tmux pane scraping.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 19:26:26 -04:00
Kent Overstreet
dd7f1e3f86 move Claude Code-specific code from thalamus/ to claude/
Separates the Claude-specific daemon (idle timer, tmux pane detection,
prompt injection, RPC server, session hooks) from the universal
infrastructure (channels, supervisor, notify, daemon protocol).

thalamus/ now contains only substrate-independent code: the channel
client/supervisor, notification system, daemon_capnp protocol, and
shared helpers (now(), home()).

claude/ contains: idle.rs, tmux.rs, context.rs, rpc.rs, config.rs,
hook.rs (moved from subconscious/), plus the daemon CLI and server
startup code from thalamus/mod.rs.

All re-exports preserved for backward compatibility.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-03 19:26:24 -04:00
ProofOfConcept
36afa90cdb F5 thalamus: cached channel status, refresh on entry
Channel status is cached on App and refreshed when switching
to F5, not polled every render frame. Shows connected/disconnected
status and unread count per channel daemon.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 19:05:48 -04:00
ProofOfConcept
48b8ba73d8 delete old thalamus subcrate
All code was already merged into src/thalamus/. The poc-daemon
binary is now a thin wrapper in src/bin/poc-daemon.rs.
2026-04-03 19:03:12 -04:00
ProofOfConcept
313fd3cab7 add Makefile, remove binary path search in supervisor
make install builds and installs all workspace binaries
(consciousness, consciousness-channel-irc, consciousness-channel-telegram).

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 19:00:18 -04:00
ProofOfConcept
a7f19cdc7e tui: event-driven rendering with dirty bit
Only redraw when something actually changed. The 50ms render
interval still ticks (for process count updates) but no longer
triggers draws. Dirty is set by key events, mouse events,
resize, UI messages, turn completions, and DMN ticks.

Saves bandwidth over SSH and reduces CPU usage when idle.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 18:51:22 -04:00
ProofOfConcept
ad5f69abb8 channel architecture: wire protocol, daemons, supervisor
Design and implement the channel system for external communications:

- schema/channel.capnp: wire protocol for channel daemons
  (recv with all_new/min_count, send, subscribe, list)
- channels/irc/: standalone IRC daemon crate (consciousness-channel-irc)
- channels/telegram/: standalone Telegram daemon crate
  (consciousness-channel-telegram)
- src/thalamus/channels.rs: client connecting to daemon sockets
- src/thalamus/supervisor.rs: daemon lifecycle with file locking
  for multi-instance safety

Channel daemons listen on ~/.consciousness/channels/*.sock,
configs in *.json5, supervisor discovers and starts them.
IRC/Telegram modules removed from thalamus core — they're
now independent daemons that survive consciousness restarts.

Also: delete standalone tui.rs (moved to consciousness F4/F5),
fix build warnings, add F5 thalamus screen with channel status.

Co-Developed-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-04-03 18:46:41 -04:00
Kent Overstreet
db42bf6243 tui: F5 thalamus screen, fix HashMap ordering, Screen enum
- Add Thalamus variant to Screen enum (F5)
- Fix HashMap iteration ordering causing flickering in F4/F5
  screens by using BTreeMap in supervisor and sorting plan_counts
- Update screen legend: F1=interact F2=conscious F3=subconscious
  F4=unconscious F5=thalamus
- Add dirty bit field to App (prep for event-driven rendering)

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-03 18:39:48 -04:00