provenance: pass directly through thought::dispatch, remove globals

Provenance now flows as a function parameter through the entire tool
dispatch chain: thought::dispatch → memory::dispatch → store methods.

Removed task_local (TASK_AGENT), thread_local (TASK_PHASE), and env
var (POC_PROVENANCE) from the tool dispatch path. The env var remains
only as a fallback for non-tool paths (CLI commands, digest).

Phase names are passed from knowledge.rs → llm.rs → api.rs, and
api.rs updates the provenance string between steps. No globals needed.
This commit is contained in:
ProofOfConcept 2026-03-27 15:44:39 -04:00
parent 36bde60ba0
commit 92ca2bf2c8
7 changed files with 34 additions and 47 deletions

View file

@ -333,17 +333,13 @@ fn run_one_agent_inner(
.map(|s| s.prompt.clone()).collect();
let step_phases: Vec<String> = agent_batch.steps.iter()
.map(|s| s.phase.clone()).collect();
let step_phases_for_bail = step_phases.clone();
for (i, s) in agent_batch.steps.iter().enumerate() {
log(&format!("=== PROMPT {}/{} ({}) ===\n\n{}", i + 1, n_steps, s.phase, s.prompt));
}
log("\n=== CALLING LLM ===");
// Set initial phase for provenance tracking
if let Some(first_phase) = step_phases.first() {
crate::store::set_phase(first_phase);
}
// Bail check: if the agent defines a bail script, run it between steps.
// The script receives the pid file path as $1, cwd = state dir.
let bail_script = def.bail.as_ref().map(|name| {
@ -355,9 +351,8 @@ fn run_one_agent_inner(
let pid_path_for_bail = pid_path.clone();
let bail_fn = move |step_idx: usize| -> Result<(), String> {
// Update phase in pid file and provenance tracking
if step_idx < step_phases.len() {
write_pid(&step_phases[step_idx]);
crate::store::set_phase(&step_phases[step_idx]);
if step_idx < step_phases_for_bail.len() {
write_pid(&step_phases_for_bail[step_idx]);
}
// Run bail script if defined
if let Some(ref script) = bail_script {
@ -375,7 +370,7 @@ fn run_one_agent_inner(
Ok(())
};
let output = llm::call_for_def_multi(def, &prompts, Some(&bail_fn), log)?;
let output = llm::call_for_def_multi(def, &prompts, &step_phases, Some(&bail_fn), log)?;
Ok(AgentResult {
output,