Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions crates/tui/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,47 @@ pub fn theme(app: &mut App, arg: Option<&str>) -> CommandResult {
}
}

/// `/slop [query|export]` — inspect or export the slop ledger (#2127).
/// With no arguments, prints a summary. `query` shows filtered results;
/// `export` outputs the full ledger as Markdown.
pub fn slop(_app: &mut App, arg: Option<&str>) -> CommandResult {
let arg = arg.map(str::trim).unwrap_or("");
let ledger = match crate::slop_ledger::SlopLedger::load() {
Ok(l) => l,
Err(e) => return CommandResult::error(format!("Failed to load slop ledger: {e}")),
};

match arg {
"" => CommandResult::message(ledger.summary()),
"query" | "q" => {
if ledger.is_empty() {
return CommandResult::message("Slop ledger is empty.");
}
let mut out = String::new();
for entry in &ledger.query(&Default::default()) {
use std::fmt::Write;
let _ = writeln!(
out,
"[{}] {} ({:?} | {:?}) — {}",
&entry.id[..8],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Slicing &entry.id[..8] directly can panic if the ID is shorter than 8 bytes or sliced on an invalid UTF-8 boundary. Use .get(..8) to safely slice the ID.

                    entry.id.get(..8).unwrap_or(&entry.id),

Comment on lines +723 to +724
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Byte-slice panic on short IDs in /slop query output

&entry.id[..8] indexes by byte offset and panics if entry.id is fewer than 8 bytes. The ledger is a user-editable JSON file, so a manually-edited entry with a short id causes /slop query to crash. Use get(..8).unwrap_or(&entry.id) as already suggested for the identical pattern in slop_ledger.rs.

Suggested change
"[{}] {} ({:?} | {:?}) — {}",
&entry.id[..8],
"[{}] {} ({:?} | {:?}) — {}",
entry.id.get(..8).unwrap_or(&entry.id),

Fix in Codex Fix in Claude Code Fix in Cursor

entry.bucket.as_str(),
entry.severity,
entry.status,
entry.title
);
}
CommandResult::message(out)
}
"export" | "e" => {
let md = ledger.export_markdown(None, None);
CommandResult::message(md)
}
_ => CommandResult::error(format!(
"Unknown /slop action '{arg}'. Use /slop, /slop query, or /slop export."
)),
}
}

/// Manage workspace-level trust and the per-path allowlist.
///
/// Subcommands:
Expand Down
10 changes: 10 additions & 0 deletions crates/tui/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@ pub const COMMANDS: &[CommandInfo] = &[
usage: "/cache [count|inspect|warmup]",
description_id: MessageId::CmdCacheDescription,
},
// Slop Ledger (#2127)
CommandInfo {
name: "slop",
aliases: &["canzha"],
usage: "/slop [query|export]",
description_id: MessageId::CmdHelpDescription,
},
];

/// Execute a slash command
Expand Down Expand Up @@ -614,6 +621,9 @@ pub fn execute(cmd: &str, app: &mut App) -> CommandResult {
"balance" => balance::balance(app),
"cache" => debug::cache(app, arg),

// Slop ledger (#2127)
"slop" | "canzha" => config::slop(app, arg),

// ChangeLog command
"change" => change::change(app, arg),
"system" | "xitong" => debug::system_prompt(app),
Expand Down
37 changes: 36 additions & 1 deletion crates/tui/src/core/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ pub struct Engine {
/// Diagnostics collected during the current step's tool calls. Drained
/// and forwarded as a synthetic user message before the next API call.
pending_lsp_blocks: Vec<crate::lsp::DiagnosticBlock>,
/// Cached SlopLedger gate block so `refresh_system_prompt` doesn't hit
/// the filesystem on every turn (#2127). `None` = not yet loaded;
/// `Some(None)` = loaded, no open entries; `Some(Some(...))` = loaded,
/// gate block ready.
slop_ledger_gate_cache: Option<Option<String>>,
}

// === Internal tool helpers ===
Expand Down Expand Up @@ -564,6 +569,7 @@ impl Engine {
turn_counter: 0,
lsp_manager,
pending_lsp_blocks: Vec::new(),
slop_ledger_gate_cache: None,
workshop_vars,
sandbox_backend,
};
Expand Down Expand Up @@ -1840,8 +1846,37 @@ impl Engine {
},
self.session.approval_mode,
);
let stable_prompt =
let mut stable_prompt =
merge_system_prompts(Some(&base), self.session.compaction_summary_prompt.clone());

// SlopLedger completion-gate: inject unresolved slop entries into the
// system prompt so the agent can autonomously review them before
// claiming the task is done (#2127). Cached to avoid filesystem I/O on
// every turn — only re-loaded when the cache is empty (first call or
// after invalidation).
let gate_block = match &self.slop_ledger_gate_cache {
Some(cached) => cached.clone(),
None => {
let loaded = crate::slop_ledger::SlopLedger::load()
.ok()
.and_then(|ledger| {
if ledger.has_open_entries() {
ledger.completion_gate_summary()
} else {
None
}
});
self.slop_ledger_gate_cache = Some(loaded.clone());
loaded
}
};
if let Some(ref block) = gate_block {
if let Some(SystemPrompt::Text(prompt_text)) = &mut stable_prompt {
prompt_text.push_str("\n\n");
prompt_text.push_str(block);
}
}
Comment on lines +1857 to +1878
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Completion gate cache never invalidated after ledger mutation

slop_ledger_gate_cache is populated once on the first turn and never cleared — not when slop_ledger_append adds new open entries, and not when slop_ledger_update closes them. In the common case where an agent is asked to do work and append slop during the same session, the gate starts as Some(None) (no open entries at session start) and stays that way for the entire run, silently skipping every entry the agent just wrote. The feature's stated purpose — prompting the agent to review residue before claiming done — is therefore never triggered for same-session entries. The cache needs to be cleared (self.slop_ledger_gate_cache = None) after any successful slop_ledger_append or slop_ledger_update tool call, or the cache approach needs to be removed in favour of reading from disk every N turns.

Fix in Codex Fix in Claude Code Fix in Cursor


let stable_hash = system_prompt_hash(stable_prompt.as_ref());
if self.session.system_prompt_override {
self.session.last_system_prompt_hash = Some(stable_hash);
Expand Down
8 changes: 8 additions & 0 deletions crates/tui/src/core/engine/tool_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ impl Engine {
.with_parallel_tool()
.with_recall_archive_tool();

// SlopLedger: plan mode only gets read-only query + export,
// agent/yolo get the full set including append + update.
builder = if mode == AppMode::Plan {
builder.with_slop_ledger_read_only_tools()
} else {
builder.with_slop_ledger_tools()
};

if mode != AppMode::Plan {
builder = builder
.with_rlm_tool(self.deepseek_client.clone(), self.session.model.clone())
Expand Down
1 change: 1 addition & 0 deletions crates/tui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ mod session_manager;
mod settings;
mod skill_state;
mod skills;
mod slop_ledger;
mod snapshot;
mod task_manager;
#[cfg(test)]
Expand Down
Loading
Loading