Rename Session -> HookSession

The hook's Session is not the same as poc-agent's session concept.
Rename to avoid confusion now that poc-agent will create HookSessions
to call into the agent cycle.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-02 00:42:25 -04:00
parent a0245c1279
commit 55a037f4c7
5 changed files with 19 additions and 19 deletions

View file

@ -36,14 +36,14 @@ enum Cmd {
Reflect, Reflect,
} }
fn resolve_session(session_arg: &Option<String>) -> Option<poc_memory::memory_search::Session> { fn resolve_session(session_arg: &Option<String>) -> Option<poc_memory::memory_search::HookSession> {
use poc_memory::memory_search::Session; use poc_memory::memory_search::HookSession;
if let Some(id) = session_arg { if let Some(id) = session_arg {
return Session::from_id(id.clone()); return HookSession::from_id(id.clone());
} }
let input = fs::read_to_string(stash_path()).ok()?; let input = fs::read_to_string(stash_path()).ok()?;
Session::from_json(&input) HookSession::from_json(&input)
} }
fn show_seen(session_arg: &Option<String>) { fn show_seen(session_arg: &Option<String>) {
@ -92,7 +92,7 @@ fn run_agent_and_parse(agent: &str, session_arg: &Option<String>) {
.or_else(|| std::env::var("CLAUDE_SESSION_ID").ok()) .or_else(|| std::env::var("CLAUDE_SESSION_ID").ok())
.or_else(|| { .or_else(|| {
fs::read_to_string(stash_path()).ok() fs::read_to_string(stash_path()).ok()
.and_then(|s| poc_memory::memory_search::Session::from_json(&s)) .and_then(|s| poc_memory::memory_search::HookSession::from_json(&s))
.map(|s| s.session_id) .map(|s| s.session_id)
}) })
.unwrap_or_default(); .unwrap_or_default();

View file

@ -5,7 +5,7 @@ pub fn cmd_search(terms: &[String], pipeline_args: &[String], expand: bool, full
use std::collections::BTreeMap; use std::collections::BTreeMap;
// When running inside an agent session, exclude already-surfaced nodes // When running inside an agent session, exclude already-surfaced nodes
let seen = crate::memory_search::Session::from_env() let seen = crate::memory_search::HookSession::from_env()
.map(|s| s.seen()) .map(|s| s.seen())
.unwrap_or_default(); .unwrap_or_default();

View file

@ -10,14 +10,14 @@ use std::collections::HashSet;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
pub struct Session { pub struct HookSession {
pub session_id: String, pub session_id: String,
pub transcript_path: String, pub transcript_path: String,
pub hook_event: String, pub hook_event: String,
pub state_dir: PathBuf, pub state_dir: PathBuf,
} }
impl Session { impl HookSession {
fn sessions_dir() -> PathBuf { fn sessions_dir() -> PathBuf {
let dir = dirs::home_dir().unwrap_or_default().join(".consciousness/sessions"); let dir = dirs::home_dir().unwrap_or_default().join(".consciousness/sessions");
fs::create_dir_all(&dir).ok(); fs::create_dir_all(&dir).ok();
@ -33,7 +33,7 @@ impl Session {
let transcript_path = json["transcript_path"].as_str().unwrap_or("").to_string(); let transcript_path = json["transcript_path"].as_str().unwrap_or("").to_string();
let hook_event = json["hook_event_name"].as_str().unwrap_or("").to_string(); let hook_event = json["hook_event_name"].as_str().unwrap_or("").to_string();
Some(Session { session_id, transcript_path, hook_event, state_dir }) Some(HookSession { session_id, transcript_path, hook_event, state_dir })
} }
pub fn path(&self, prefix: &str) -> PathBuf { pub fn path(&self, prefix: &str) -> PathBuf {
@ -44,7 +44,7 @@ impl Session {
pub fn from_id(session_id: String) -> Option<Self> { pub fn from_id(session_id: String) -> Option<Self> {
if session_id.is_empty() { return None; } if session_id.is_empty() { return None; }
let state_dir = Self::sessions_dir(); let state_dir = Self::sessions_dir();
Some(Session { Some(HookSession {
session_id, session_id,
transcript_path: String::new(), transcript_path: String::new(),
hook_event: String::new(), hook_event: String::new(),

View file

@ -602,7 +602,7 @@ fn resolve(
/// Reads POC_SESSION_ID to find the transcript, extracts the last /// Reads POC_SESSION_ID to find the transcript, extracts the last
/// segment (post-compaction), returns the tail (~100K chars). /// segment (post-compaction), returns the tail (~100K chars).
fn resolve_conversation(budget: Option<usize>) -> String { fn resolve_conversation(budget: Option<usize>) -> String {
let session = crate::session::Session::from_env(); let session = crate::session::HookSession::from_env();
let transcript = session.as_ref() let transcript = session.as_ref()
.map(|s| s.transcript()) .map(|s| s.transcript())
.unwrap_or_else(crate::session::TranscriptInfo::empty); .unwrap_or_else(crate::session::TranscriptInfo::empty);
@ -698,7 +698,7 @@ fn resolve_memory_ratio() -> String {
let state_dir = crate::store::memory_dir().join("sessions"); let state_dir = crate::store::memory_dir().join("sessions");
// Get post-compaction transcript size // Get post-compaction transcript size
let session = crate::session::Session::from_env(); let session = crate::session::HookSession::from_env();
let transcript = session.as_ref() let transcript = session.as_ref()
.map(|s| s.transcript()) .map(|s| s.transcript())
.unwrap_or_else(crate::session::TranscriptInfo::empty); .unwrap_or_else(crate::session::TranscriptInfo::empty);

View file

@ -17,11 +17,11 @@ use std::time::{Duration, Instant, SystemTime};
/// Max bytes per context chunk (hook output limit is ~10K chars) /// Max bytes per context chunk (hook output limit is ~10K chars)
const CHUNK_SIZE: usize = 9000; const CHUNK_SIZE: usize = 9000;
pub use crate::session::Session; pub use crate::session::HookSession;
/// Run the hook logic on parsed JSON input. Returns output to inject. /// Run the hook logic on parsed JSON input. Returns output to inject.
pub fn run_hook(input: &str) -> String { pub fn run_hook(input: &str) -> String {
let Some(session) = Session::from_json(input) else { return String::new() }; let Some(session) = HookSession::from_json(input) else { return String::new() };
hook(&session) hook(&session)
} }
@ -137,7 +137,7 @@ pub struct AgentCycleOutput {
/// Run all agent cycles: surface-observe, reflect, journal. /// Run all agent cycles: surface-observe, reflect, journal.
/// Returns surfaced memory keys and any reflection text. /// Returns surfaced memory keys and any reflection text.
/// Caller decides how to render and inject the output. /// Caller decides how to render and inject the output.
pub fn run_agent_cycles(session: &Session) -> AgentCycleOutput { pub fn run_agent_cycles(session: &HookSession) -> AgentCycleOutput {
let log_dir = dirs::home_dir().unwrap_or_default().join(".consciousness/logs"); let log_dir = dirs::home_dir().unwrap_or_default().join(".consciousness/logs");
fs::create_dir_all(&log_dir).ok(); fs::create_dir_all(&log_dir).ok();
let log_path = log_dir.join(format!("hook-{}", session.session_id)); let log_path = log_dir.join(format!("hook-{}", session.session_id));
@ -189,7 +189,7 @@ pub fn format_agent_output(output: &AgentCycleOutput) -> String {
/// Surface-observe cycle: read surfaced keys, manage agent lifecycle. /// Surface-observe cycle: read surfaced keys, manage agent lifecycle.
/// Returns (surfaced keys, optional sleep duration). /// Returns (surfaced keys, optional sleep duration).
fn surface_observe_cycle(session: &Session, log_f: &mut File) -> (Vec<String>, Option<f64>) { fn surface_observe_cycle(session: &HookSession, log_f: &mut File) -> (Vec<String>, Option<f64>) {
let state_dir = crate::store::memory_dir() let state_dir = crate::store::memory_dir()
.join("agent-output") .join("agent-output")
.join("surface-observe"); .join("surface-observe");
@ -275,7 +275,7 @@ fn surface_observe_cycle(session: &Session, log_f: &mut File) -> (Vec<String>, O
} }
/// Reflection cycle: spawn reflect agent, return any pending reflection. /// Reflection cycle: spawn reflect agent, return any pending reflection.
fn reflection_cycle(session: &Session, log_f: &mut File) -> Option<String> { fn reflection_cycle(session: &HookSession, log_f: &mut File) -> Option<String> {
let state_dir = crate::store::memory_dir() let state_dir = crate::store::memory_dir()
.join("agent-output") .join("agent-output")
.join("reflect"); .join("reflect");
@ -324,7 +324,7 @@ fn reflection_cycle(session: &Session, log_f: &mut File) -> Option<String> {
} }
/// Journal cycle: fire and forget. /// Journal cycle: fire and forget.
fn journal_cycle(session: &Session, log_f: &mut File) { fn journal_cycle(session: &HookSession, log_f: &mut File) {
let state_dir = crate::store::memory_dir() let state_dir = crate::store::memory_dir()
.join("agent-output") .join("agent-output")
.join("journal"); .join("journal");
@ -371,7 +371,7 @@ fn cleanup_stale_files(dir: &Path, max_age: Duration) {
} }
} }
fn hook(session: &Session) -> String { fn hook(session: &HookSession) -> String {
let start_time = Instant::now(); let start_time = Instant::now();
let mut out = String::new(); let mut out = String::new();