Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ All interactive coding providers — Claude Code, Codex, Cursor, Ollama, DeepSee

## Rules

- `.gaviero/settings.json` is the only read/network policy source, plus one exception: read-only folders the user grants to one TUI chat conversation with `/add-dir` (`AgentOptions::session_read_folders` → `SensitivePolicy::with_session_read_folders`; persisted with the conversation, cleared by `/reset`, `/clear`, `/handoff`; desktop only). Provider read rules are compiled from both at spawn (`agent_guard`); never author provider permission files by hand — they are replaced.
- `.gaviero/settings.json` is the only read/network policy source, plus one exception: read-only folders the user grants to one TUI chat conversation with `/add-dir` (`AgentOptions::session_read_folders` → `SensitivePolicy::with_session_read_folders`; persisted with the conversation and kept across `/reset`, `/clear`, `/handoff`; bare `/add-dir` lists them numbered, `/remove-dir [N]` removes the Nth or all; desktop only). Provider read rules are compiled from both at spawn (`agent_guard`); never author provider permission files by hand — they are replaced.
- `.gaviero/settings.json` is also the only MCP server source. `config_synth` replaces (never merges) the server lists in `.mcp.json` / `.cursor/mcp.json`, and the spawn sites block vendor-side servers: Claude always gets `--strict-mcp-config`, Codex gets `codex_unmanaged_mcp_overrides`, and Cursor user-level servers are denied in `.cursor/cli.json`. Never read a provider MCP file back as input.
- Every file change made during a TUI chat turn is captured in that turn's change set (`turn_capture`) and must be reviewed before the conversation continues. Swarm and CLI writes go through `WriteGatePipeline`. Host-side writes made during a turn (editor saves, review reverts, MCP config synthesis) must be recorded in `TurnCapture::ledger()` or they are attributed to the agent.
- Never let an MCP tool touch a store directly. Any tool with an effect goes through the writer task or the Write Gate — that is the invariant. A read-only surface is the default posture, not a hard rule: each tool costs ~150–250 prompt tokens on every subprocess turn (provenance: `git show f11eca9:tier-a-part-2-surface.md` §A5), so make it earn that.
Expand Down
5 changes: 5 additions & 0 deletions crates/gaviero-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,11 @@ impl App {
commands::handle_add_dir_command(self);
}

/// Handle `/remove-dir [N]` command.
fn handle_remove_dir_command(&mut self) {
commands::handle_remove_dir_command(self);
}

/// Paste from clipboard into chat — checks for image first, then text.
fn chat_paste_from_clipboard(&mut self) {
side_panel::chat_paste_from_clipboard(self);
Expand Down
169 changes: 148 additions & 21 deletions crates/gaviero-tui/src/app/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,9 +1353,31 @@ pub(super) fn handle_detach_command(app: &mut App) {
}
}

/// The active conversation's `/add-dir` grants, numbered from 1 — the
/// numbers `/remove-dir <N>` takes.
fn add_dir_listing(grants: &[std::path::PathBuf]) -> String {
if grants.is_empty() {
return "No folders granted to this conversation.\n\
Usage: /add-dir <path> — let the agent read a folder outside the workspace \
(read-only); /remove-dir [N] removes grants."
.to_string();
}
let list: Vec<String> = grants
.iter()
.enumerate()
.map(|(i, p)| format!(" {}. {}", i + 1, p.display()))
.collect();
format!(
"Folders this conversation's agent may read (read-only):\n{}\n\
/remove-dir <N> removes one, /remove-dir removes all.",
list.join("\n")
)
}

/// `/add-dir [path]`: grant the active conversation's agent read-only access
/// to a folder outside the workspace until `/reset`, `/clear` or `/handoff`
/// (`Conversation::session_read_folders`). The bare form lists the grants.
/// to a folder outside the workspace (`Conversation::session_read_folders`).
/// Grants survive `/reset`, `/clear` and `/handoff`; only `/remove-dir`
/// drops them. The bare form lists the grants, numbered from 1.
/// Desktop only: `/add-dir` is not in the remote allow-list.
pub(super) fn handle_add_dir_command(app: &mut App) {
use gaviero_core::agent_guard::{SessionReadFolderCheck, check_session_read_folder};
Expand All @@ -1371,23 +1393,7 @@ pub(super) fn handle_add_dir_command(app: &mut App) {
let idx = app.chat_state.active_conv;

if arg.is_empty() {
let grants = &app.chat_state.conversations[idx].session_read_folders;
let msg = if grants.is_empty() {
"No folders granted to this conversation.\n\
Usage: /add-dir <path> — let the agent read a folder outside the workspace \
(read-only) until /reset, /clear or /handoff."
.to_string()
} else {
let list: Vec<String> = grants
.iter()
.map(|p| format!(" {}", p.display()))
.collect();
format!(
"Folders this conversation's agent may read (read-only):\n{}\n\
/reset, /clear or /handoff removes them.",
list.join("\n")
)
};
let msg = add_dir_listing(&app.chat_state.conversations[idx].session_read_folders);
app.chat_state.add_system_message_at(idx, &msg);
return;
}
Expand Down Expand Up @@ -1427,8 +1433,7 @@ pub(super) fn handle_add_dir_command(app: &mut App) {
let msg = format!(
"Read access granted for this conversation: {}\n\
The agent can read and search it from the next prompt but cannot write \
there. /reset, /clear or /handoff removes it; /add-dir lists the granted \
folders.",
there. /add-dir lists the granted folders; /remove-dir removes them.",
path.display()
);
let conv = &mut app.chat_state.conversations[idx];
Expand All @@ -1443,6 +1448,60 @@ pub(super) fn handle_add_dir_command(app: &mut App) {
}
}

/// `/remove-dir [N]`: the counterpart of `/add-dir`. Bare, it drops every
/// grant of the active conversation; with `N` it drops the Nth grant in the
/// order `/add-dir` lists them (1-based). Desktop only, like `/add-dir`.
pub(super) fn handle_remove_dir_command(app: &mut App) {
let input = app.chat_state.take_input();
let arg = input
.trim()
.strip_prefix("/remove-dir")
.unwrap_or("")
.trim()
.to_string();
app.chat_state.add_user_message(&input);
let idx = app.chat_state.active_conv;
let count = app.chat_state.conversations[idx].session_read_folders.len();

if arg.is_empty() {
let msg = if count == 0 {
"No folders granted to this conversation.".to_string()
} else {
let conv = &mut app.chat_state.conversations[idx];
conv.session_read_folders.clear();
conv.bump_revision();
format!(
"Removed {count} granted folder(s). The agent loses read access from the next \
prompt."
)
};
app.chat_state.add_system_message_at(idx, &msg);
return;
}

let msg = match arg.parse::<usize>() {
Ok(n) if n >= 1 && n <= count => {
let conv = &mut app.chat_state.conversations[idx];
let removed = conv.session_read_folders.remove(n - 1);
conv.bump_revision();
format!(
"Removed read access for this conversation: {}\n\
The agent loses it from the next prompt.",
removed.display()
)
}
_ if count == 0 => format!(
"No folder number {arg}: no folders are granted to this conversation."
),
_ => format!(
"No folder number {arg}. Usage: /remove-dir <N> with N from 1 to {count}, \
or /remove-dir to remove all.\n{}",
add_dir_listing(&app.chat_state.conversations[idx].session_read_folders)
),
};
app.chat_state.add_system_message_at(idx, &msg);
}

#[cfg(test)]
mod add_dir_tests {
use super::*;
Expand Down Expand Up @@ -1532,8 +1591,76 @@ mod add_dir_tests {
);
}

#[test]
fn bare_add_dir_numbers_grants_from_one() {
let (_ws, mut app) = test_app();
let a = tempfile::tempdir().unwrap();
let b = tempfile::tempdir().unwrap();
run(&mut app, &format!("/add-dir {}", a.path().display()));
run(&mut app, &format!("/add-dir {}", b.path().display()));
run(&mut app, "/add-dir");
let listing = last_system(&app);
assert!(
listing.contains(&format!(" 1. {}", a.path().display())),
"{listing}"
);
assert!(
listing.contains(&format!(" 2. {}", b.path().display())),
"{listing}"
);
}

fn remove(app: &mut App, line: &str) {
app.chat_state.text_input.text = line.to_string();
handle_remove_dir_command(app);
}

fn three_grants(app: &mut App) -> Vec<tempfile::TempDir> {
let dirs: Vec<tempfile::TempDir> = (0..3).map(|_| tempfile::tempdir().unwrap()).collect();
for d in &dirs {
run(app, &format!("/add-dir {}", d.path().display()));
}
assert_eq!(grants(app).len(), 3);
dirs
}

#[test]
fn remove_dir_n_removes_the_nth_grant() {
let (_ws, mut app) = test_app();
let dirs = three_grants(&mut app);
remove(&mut app, "/remove-dir 2");
assert_eq!(
grants(&app),
vec![dirs[0].path().to_path_buf(), dirs[2].path().to_path_buf()]
);
assert!(last_system(&app).starts_with("Removed read access"), "{}", last_system(&app));
}

#[test]
fn bare_remove_dir_removes_every_grant() {
let (_ws, mut app) = test_app();
three_grants(&mut app);
remove(&mut app, "/remove-dir");
assert!(grants(&app).is_empty());
assert!(last_system(&app).starts_with("Removed 3"), "{}", last_system(&app));
remove(&mut app, "/remove-dir");
assert!(last_system(&app).starts_with("No folders granted"), "{}", last_system(&app));
}

#[test]
fn remove_dir_rejects_out_of_range_or_non_numeric() {
let (_ws, mut app) = test_app();
three_grants(&mut app);
for bad in ["/remove-dir 0", "/remove-dir 4", "/remove-dir two"] {
remove(&mut app, bad);
assert_eq!(grants(&app).len(), 3, "{bad}");
assert!(last_system(&app).starts_with("No folder number"), "{}", last_system(&app));
}
}

#[test]
fn add_dir_is_not_allowed_remotely() {
assert!(!crate::app::remote::REMOTE_ALLOWED_SLASH.contains(&"/add-dir"));
assert!(!crate::app::remote::REMOTE_ALLOWED_SLASH.contains(&"/remove-dir"));
}
}
4 changes: 4 additions & 0 deletions crates/gaviero-tui/src/app/side_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ pub(super) fn handle_chat_action(app: &mut App, action: Action) {
{
// First-token match: `/add-dirx` stays an unknown command.
app.handle_add_dir_command();
} else if app.chat_state.text_input.text.split_whitespace().next()
== Some("/remove-dir")
{
app.handle_remove_dir_command();
} else if app.chat_state.text_input.text.trim().starts_with("/attach") {
app.handle_attach_command();
} else if app.chat_state.text_input.text.trim().starts_with("/detach") {
Expand Down
32 changes: 17 additions & 15 deletions crates/gaviero-tui/src/panels/agent_chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,8 @@ pub struct Conversation {
/// `/add-dir` grants: absolute folders outside the workspace this
/// conversation's agent may read (read-only). Passed to every provider
/// session as `AgentOptions::session_read_folders`; persisted with the
/// conversation; cleared by `/reset`, `/clear` and `/handoff`.
/// conversation; kept across `/reset`, `/clear` and `/handoff`, removed
/// only by `/remove-dir`.
pub session_read_folders: Vec<std::path::PathBuf>,
}

Expand Down Expand Up @@ -2721,7 +2722,8 @@ impl AgentChatState {
/context mode <mode> — Set bootstrap mode for this conversation (auto|minimal|manual|none)\n\
/rename [new title] — Rename the active conversation tab (bare form starts interactive rename, same as F2)\n\
/reset — Clear agent context (keeps visible chat history). Alias: /clear\n\
/add-dir [path] — Let the agent read a folder outside the workspace (read-only) until /reset, /clear or /handoff; bare form lists the granted folders (desktop only)\n\
/add-dir [path] — Let the agent read a folder outside the workspace (read-only; survives /reset, /clear and /handoff); bare form lists the granted folders, numbered (desktop only)\n\
/remove-dir [N] — Remove the Nth /add-dir folder; bare form removes them all (desktop only)\n\
/keep [clear] — List (or unmark) the exchanges marked to keep. Mark them in browse mode: Ctrl+C with nothing selected, ↑/↓, Space\n\
/handoff [to <tab|new>] — Start a fresh session carrying only the kept exchanges, verbatim (detours left out). Default: this tab. `to <n|title>` seeds another tab (this one is left untouched), `to new` opens one\n\
/compact [text|N] — Claude: compact the session natively (optional extra guidance). Other providers: keep the last N messages of the replayed transcript (default 6)\n\n\
Expand Down Expand Up @@ -3099,9 +3101,9 @@ impl AgentChatState {
// A plain reset drops whatever an earlier `/handoff` carried;
// `/handoff` sets its block again right after resetting.
conv.carried_context = None;
// `/add-dir` grants last until `/reset`, `/clear` or `/handoff` —
// all three come through here.
conv.session_read_folders.clear();
// `/add-dir` grants deliberately survive `/reset`, `/clear` and
// `/handoff` (all three come through here): only `/remove-dir`
// drops them.
// Host-side replay watermark: visible pre-reset turns stay in the
// panel but must not re-enter `Turn.replay_history` once
// `transcript_inline_mode` returns to `Auto`. `deepseek:` keeps
Expand Down Expand Up @@ -7598,28 +7600,28 @@ mod tests {
}

#[test]
fn reset_drops_add_dir_grants() {
fn reset_keeps_add_dir_grants() {
let mut state = AgentChatState::new();
let idx = state.active_conv;
state.conversations[idx]
.session_read_folders
.push(std::path::PathBuf::from("/srv/docs"));
let grant = std::path::PathBuf::from("/srv/docs");
state.conversations[idx].session_read_folders.push(grant.clone());
state.reset_conversation_at(idx);
assert!(state.conversations[idx].session_read_folders.is_empty());
assert_eq!(state.conversations[idx].session_read_folders, vec![grant.clone()]);
assert!(state.apply_slash_line(idx, "/clear", SlashOrigin::Desktop));
assert_eq!(state.conversations[idx].session_read_folders, vec![grant]);
}

#[test]
fn handoff_in_place_drops_add_dir_grants() {
fn handoff_in_place_keeps_add_dir_grants() {
let mut state = AgentChatState::new();
let idx = session_with_detour(&mut state);
state.active_conv = idx;
state.conversations[idx].toggle_keep_exchange(1);
state.conversations[idx]
.session_read_folders
.push(std::path::PathBuf::from("/srv/docs"));
let grant = std::path::PathBuf::from("/srv/docs");
state.conversations[idx].session_read_folders.push(grant.clone());
assert!(state.apply_slash_line(idx, "/handoff", SlashOrigin::Desktop));
assert!(state.conversations[idx].carried_context.is_some(), "handoff ran");
assert!(state.conversations[idx].session_read_folders.is_empty());
assert_eq!(state.conversations[idx].session_read_folders, vec![grant]);
}

#[test]
Expand Down
Loading