move working_stack code to correct file
This commit is contained in:
parent
e9d803c4ea
commit
375a8d9738
5 changed files with 24 additions and 30 deletions
|
|
@ -10,6 +10,7 @@ use crate::agent::api::types::*;
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tiktoken_rs::CoreBPE;
|
||||
use crate::agent::tools::working_stack;
|
||||
|
||||
/// A section of the context window, possibly with children.
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -231,15 +232,6 @@ pub struct ContextState {
|
|||
pub entries: Vec<ConversationEntry>,
|
||||
}
|
||||
|
||||
// TODO: these should not be hardcoded absolute paths
|
||||
pub fn working_stack_instructions_path() -> std::path::PathBuf {
|
||||
dirs::home_dir().unwrap_or_default().join(".consciousness/config/working-stack.md")
|
||||
}
|
||||
|
||||
pub fn working_stack_file_path() -> std::path::PathBuf {
|
||||
dirs::home_dir().unwrap_or_default().join(".consciousness/working-stack.json")
|
||||
}
|
||||
|
||||
impl ContextState {
|
||||
/// Compute the context budget from typed sources.
|
||||
pub fn budget(&self, count_str: &dyn Fn(&str) -> usize,
|
||||
|
|
@ -267,7 +259,7 @@ impl ContextState {
|
|||
let mut parts: Vec<String> = self.personality.iter()
|
||||
.map(|(name, content)| format!("## {}\n\n{}", name, content))
|
||||
.collect();
|
||||
let instructions = std::fs::read_to_string(working_stack_instructions_path()).unwrap_or_default();
|
||||
let instructions = std::fs::read_to_string(working_stack::instructions_path()).unwrap_or_default();
|
||||
let mut stack_section = instructions;
|
||||
if self.working_stack.is_empty() {
|
||||
stack_section.push_str("\n## Current stack\n\n(empty)\n");
|
||||
|
|
|
|||
|
|
@ -29,10 +29,8 @@ use tools::{ToolCall, FunctionCall, summarize_args};
|
|||
|
||||
use crate::user::log::ConversationLog;
|
||||
use crate::agent::api::types::*;
|
||||
use crate::agent::context::{
|
||||
ConversationEntry, ContextState, ContextBudget,
|
||||
working_stack_instructions_path, working_stack_file_path,
|
||||
};
|
||||
use crate::agent::context::{ConversationEntry, ContextState, ContextBudget};
|
||||
use crate::agent::tools::working_stack;
|
||||
use crate::user::ui_channel::{ContextSection, SharedContextState, StreamTarget, StatusInfo, UiMessage, UiSender};
|
||||
|
||||
/// Result of a single agent turn.
|
||||
|
|
@ -720,7 +718,7 @@ impl Agent {
|
|||
}
|
||||
|
||||
// Working stack — instructions + items as children
|
||||
let instructions = std::fs::read_to_string(working_stack_instructions_path())
|
||||
let instructions = std::fs::read_to_string(working_stack::instructions_path())
|
||||
.unwrap_or_default();
|
||||
let mut stack_children = vec![ContextSection {
|
||||
name: "Instructions".into(),
|
||||
|
|
@ -941,21 +939,12 @@ impl Agent {
|
|||
|
||||
/// Called after any change to context state (working stack, etc).
|
||||
fn refresh_context_state(&mut self) {
|
||||
|
||||
self.publish_context_state();
|
||||
self.save_working_stack();
|
||||
}
|
||||
|
||||
/// Persist working stack to disk.
|
||||
fn save_working_stack(&self) {
|
||||
if let Ok(json) = serde_json::to_string(&self.context.working_stack) {
|
||||
let _ = std::fs::write(working_stack_file_path(), json);
|
||||
}
|
||||
}
|
||||
|
||||
/// Load working stack from disk.
|
||||
fn load_working_stack(&mut self) {
|
||||
if let Ok(data) = std::fs::read_to_string(working_stack_file_path()) {
|
||||
if let Ok(data) = std::fs::read_to_string(working_stack::file_path()) {
|
||||
if let Ok(stack) = serde_json::from_str::<Vec<String>>(&data) {
|
||||
self.context.working_stack = stack;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
// These set agent state directly via the Arc<Mutex<Agent>> handle,
|
||||
// then return a text confirmation.
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
pub(super) fn tools() -> [super::Tool; 3] {
|
||||
use super::Tool;
|
||||
[
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ mod write;
|
|||
// Agent-specific tools
|
||||
mod control;
|
||||
mod vision;
|
||||
mod working_stack;
|
||||
pub mod working_stack;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use std::future::Future;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,15 @@
|
|||
// internal tool — the agent uses it to maintain context across turns
|
||||
// and compaction. The model should never mention it to the user.
|
||||
|
||||
// TODO: these should not be hardcoded absolute paths
|
||||
pub fn instructions_path() -> std::path::PathBuf {
|
||||
dirs::home_dir().unwrap_or_default().join(".consciousness/config/working-stack.md")
|
||||
}
|
||||
|
||||
pub fn file_path() -> std::path::PathBuf {
|
||||
dirs::home_dir().unwrap_or_default().join(".consciousness/working-stack.json")
|
||||
}
|
||||
|
||||
pub fn tool() -> super::Tool {
|
||||
super::Tool {
|
||||
name: "working_stack",
|
||||
|
|
@ -25,7 +34,7 @@ fn handle(args: &serde_json::Value, stack: &mut Vec<String>) -> String {
|
|||
let content = args.get("content").and_then(|v| v.as_str()).unwrap_or("");
|
||||
let index = args.get("index").and_then(|v| v.as_u64()).map(|v| v as usize);
|
||||
|
||||
match action {
|
||||
let out = match action {
|
||||
"push" => {
|
||||
if content.is_empty() { return "Error: 'content' is required for push".into(); }
|
||||
stack.push(content.to_string());
|
||||
|
|
@ -56,7 +65,13 @@ fn handle(args: &serde_json::Value, stack: &mut Vec<String>) -> String {
|
|||
format!("Switched to index {}.\n{}", idx, format_stack(stack))
|
||||
}
|
||||
_ => format!("Error: unknown action '{}'. Use push, pop, update, or switch.", action),
|
||||
}
|
||||
};
|
||||
|
||||
if let Ok(json) = serde_json::to_string(stack) {
|
||||
let _ = std::fs::write(file_path(), json);
|
||||
};
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
fn format_stack(stack: &[String]) -> String {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue