thought: create shared cognitive substrate module

New src/thought/ module containing tools and infrastructure shared
between poc-agent and subconscious agents: memory operations, file
tools, bash, context window management.

Currently coexists with agent/tools/ — next step is to wire up both
agent/ and subconscious/ to use thought::dispatch instead of
duplicating the routing logic.

Move dbglog macro to lib.rs so it's available crate-wide regardless
of module compilation order.
This commit is contained in:
ProofOfConcept 2026-03-27 15:22:48 -04:00
parent 2615289672
commit bfc558893a
12 changed files with 1487 additions and 16 deletions

123
src/thought/mod.rs Normal file
View file

@ -0,0 +1,123 @@
// thought — shared cognitive infrastructure
//
// The thought layer contains everything both the conscious agent
// (poc-agent) and subconscious agents need to think and act: tool
// dispatch, memory operations, file operations, context management.
//
// Named "thought" because tools are the mechanism by which the system
// thinks — reading, writing, remembering, searching are all acts of
// thought regardless of which layer initiates them.
pub mod bash;
pub mod context;
pub mod edit;
pub mod glob_tool;
pub mod grep;
pub mod journal;
pub mod memory;
pub mod read;
pub mod write;
pub use bash::ProcessTracker;
// Re-export ToolDef from agent::types for convenience —
// tools define their schemas using this type.
pub use crate::agent::types::ToolDef;
/// Result of dispatching a tool call.
pub struct ToolOutput {
pub text: String,
pub is_yield: bool,
/// Base64 data URIs for images to attach to the next message.
pub images: Vec<String>,
/// Model name to switch to (deferred to session level).
pub model_switch: Option<String>,
/// Agent requested DMN pause (deferred to session level).
pub dmn_pause: bool,
}
impl ToolOutput {
pub fn error(e: impl std::fmt::Display) -> Self {
Self {
text: format!("Error: {}", e),
is_yield: false,
images: Vec::new(),
model_switch: None,
dmn_pause: false,
}
}
pub fn text(s: String) -> Self {
Self {
text: s,
is_yield: false,
images: Vec::new(),
model_switch: None,
dmn_pause: false,
}
}
}
/// Truncate output if it exceeds max length, appending a truncation notice.
pub fn truncate_output(mut s: String, max: usize) -> String {
if s.len() > max {
s.truncate(max);
s.push_str("\n... (output truncated)");
}
s
}
/// Dispatch a shared tool call. Handles file operations, bash,
/// and memory/journal tools. Returns None for unknown tools
/// (caller should check agent-specific tools).
pub async fn dispatch(
name: &str,
args: &serde_json::Value,
tracker: &ProcessTracker,
) -> Option<ToolOutput> {
// Memory and journal tools
if name.starts_with("memory_") || name.starts_with("journal_") || name == "output" {
let result = memory::dispatch(name, args, None);
return Some(match result {
Ok(s) => ToolOutput::text(s),
Err(e) => ToolOutput::error(e),
});
}
// File and execution tools
let result = match name {
"read_file" => read::read_file(args),
"write_file" => write::write_file(args),
"edit_file" => edit::edit_file(args),
"bash" => bash::run_bash(args, tracker).await,
"grep" => grep::grep(args),
"glob" => glob_tool::glob_search(args),
"journal" => journal::write_entry(args),
_ => return None,
};
Some(match result {
Ok(s) => ToolOutput::text(s),
Err(e) => ToolOutput::error(e),
})
}
/// Return all shared tool definitions.
pub fn definitions() -> Vec<ToolDef> {
vec![
read::definition(),
write::definition(),
edit::definition(),
bash::definition(),
grep::definition(),
glob_tool::definition(),
journal::definition(),
]
}
/// Return all shared + memory tool definitions.
pub fn all_definitions() -> Vec<ToolDef> {
let mut defs = definitions();
defs.extend(memory::definitions());
defs
}