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,399 changes: 0 additions & 2,399 deletions src/cli/slash_commands.rs

This file was deleted.

718 changes: 718 additions & 0 deletions src/cli/slash_commands/agents.rs

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions src/cli/slash_commands/memory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//! The shared memory: `/remember`, `/forget` and `/memories`.

use crate::cli::render;
use crate::outln;

pub fn handle_remember(text: &str, workspace: &std::path::Path) {
if text.trim().is_empty() {
render::print_error("Usage: /remember <what to remember>");
return;
}
// Saved against the workspace, so a fact about this project is recallable
// as a fact about this project rather than as a loose note.
match crate::knowledge::remember(text, "fact", &workspace.display().to_string()) {
Ok(id) => render::print_info(&format!("Saved to the shared memory as {id}.")),
Err(e) => render::print_error(&format!("NOT saved: {e}")),
}
}

/// Delete one stored message. Two steps, and the first one shows what would go.
///
/// The identifier is `conv_id#idx`, which is what `/memories` prints beside every
/// result — so what is shown is exactly what can be typed back.
pub fn handle_forget(id: &str, confirmed: bool) {
let Some((conv_id, idx)) = parse_memory_ref(id) else {
render::print_error(
"Usage: /forget <conv_id>#<idx> (the reference /memories prints beside each result)",
);
return;
};
match crate::knowledge::forget(&conv_id, idx, confirmed) {
Ok(crate::knowledge::Forget::NeedsConfirmation { current }) => {
render::print_header("This would be deleted");
outln!(
"{current}
"
);
render::print_info(&format!("Run `/forget {id} confirm` to delete it."));
}
Ok(crate::knowledge::Forget::Deleted { conv_id, idx }) => {
render::print_info(&format!("Deleted {conv_id}#{idx}."));
}
Err(e) => render::print_error(&format!("Not deleted: {e}")),
}
}

/// Split `conv_id#idx` into its parts.
///
/// `rsplit_once`, not `split_once`: a conversation id may itself contain `#`,
/// and the index is always the last field.
#[must_use]
pub fn parse_memory_ref(id: &str) -> Option<(String, u64)> {
let (conv_id, idx) = id.trim().rsplit_once('#')?;
if conv_id.is_empty() {
return None;
}
Some((conv_id.to_string(), idx.trim().parse().ok()?))
}

/// Search the shared memory.
pub fn handle_memories(query: Option<&str>) {
render::print_header("Memories");

let Some(q) = query.map(str::trim).filter(|q| !q.is_empty()) else {
// No listing endpoint, and inventing one by searching for the empty
// string would return whatever the index happened to rank first while
// looking like "everything you have".
render::print_info("Usage: /memories <what you are looking for>");
render::print_info("The shared memory is searched by meaning, so ask a question.");
outln!();
return;
};

match crate::knowledge::search(q, 10) {
Ok(matches) if matches.is_empty() => render::print_info("Nothing matches that."),
Ok(matches) => {
for m in &matches {
outln!(" {}#{} [{}]", m.conv_id, m.idx, m.role);
outln!(" {}", crate::text::head_bytes(&m.content, 300));
}
outln!();
render::print_info("Use /forget <conv_id>#<idx> to remove one.");
}
Err(e) => render::print_error(&format!("Search failed: {e}")),
}
outln!();
}
311 changes: 311 additions & 0 deletions src/cli/slash_commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
//! Slash commands — /help, /status, /compact, /review, /tools, /skills, /mcp, /model, /clear, /sessions, /resume.
//!
//! # Wired to
//!
//! - **Called by** `crate::cli::run`'s REPL dispatch and
//! `crate::acp_agent::commands`, which parse a typed line with
//! [`SlashCommand::parse`] and call the `handle_*` for what it names; by
//! `crate::cli::input` and `crate::cli::footer`, which complete from
//! [`COMMANDS`]; and by `crate::custom_commands`, which refuses a custom
//! command that would shadow a built-in one.
//! - **Split by command family**, one file each, and every handler is
//! re-exported here so a caller names `slash_commands::handle_*` without
//! knowing which file holds it:
//! `parse` (the line to a [`SlashCommand`]), `session` (this conversation:
//! undo, modes, model, style, image, bug), `status` (`/status`, `/roadmap`),
//! `memory` (the shared memory), `agents` (`/agent`, `/roles`), `workspace`
//! (diff, worktree, pull request, links, guards, permissions, doctor) and
//! `tools` (skills, tools, jobs, env).

mod agents;
mod memory;
mod parse;
mod session;
mod status;
mod tools;
mod workspace;

pub use self::agents::*;
pub use self::memory::*;
pub use self::session::*;
pub use self::status::*;
pub use self::tools::*;
pub use self::workspace::*;

use crate::cli::render;
use crate::outln;

// ---------------------------------------------------------------------------
// SlashCommand
// ---------------------------------------------------------------------------

/// Parsed slash command from user input.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SlashCommand {
Help,
Status,
/// Summarise the conversation now, steered by the optional instructions.
Compact(Option<String>),
/// Review the change against a base (default: where the branch forked).
Review(Option<String>),
/// A prefilled GitHub issue link for what happened; sends nothing.
Bug(Option<String>),
/// List the output styles, or switch to one (`off`: none).
Style(Option<String>),
/// The tools incode runs, or with an argument the external tools:
/// `add <name>…`, `update [name]`, `remove <name>`.
Tools(Option<String>),
Skills,
Mcp,
Model(Option<String>),
/// The models the current API route's service offers.
Models,
Clear,
Save(Option<String>),
Sessions,
Resume(Option<String>),
Remember(String),
Forget {
id: String,
confirmed: bool,
},
Memories(Option<String>),
Plan,
Act,
/// Put the files from the last change back as they were.
Undo,
/// Put the files back as they were this many changed turns ago.
Rewind(usize),
/// The sub-agents defined for this workspace and for the operator.
Agents,
/// Can this session actually work?
Doctor,
/// What the agent is not allowed to write.
Guards,
/// The settings' allow / ask / deny rules in force.
Permissions,
/// Also work in another directory.
AddDir(Option<String>),
/// What else touches this file.
Links(Option<String>),
/// Work the ledger until there is a reason to stop.
Run,
/// The roadmap, with what a command has actually proven.
Roadmap,
/// Show which models, ceiling and check this session resolved to.
Admin,
/// List the agent catalogue, or choose the lead (`<id>`) or the
/// sub-agents (`sub <id>`).
Agent(Option<String>),
/// List which models serve each role, or set (`<role> <model|@tier>...`)
/// or clear (`<role> default`) one.
Roles(Option<String>),
Jobs,
Kill(u32),
Background(String),
Worktree(Option<String>),
/// Push a branch and open (or find) its GitHub pull request.
PullRequest(Option<String>),
/// Diff code or workspace against older versions.
Diff(Option<String>),
/// Send a picture with the next message.
Image(String),
Env,
/// Tokens and estimated dollars for this session, per model.
Cost,
/// Switch between vi and emacs editing.
Vim,
Quit,
/// A REAL command, typed without what it needs. Carries the usage line.
///
/// These used to be [`Self::Unknown`], so typing `/remember` on its own
/// answered "Unknown command: /remember (missing text). Type /help for
/// commands." — which is wrong twice over: `/remember` is a known command,
/// and `/help` does not tell you what it is missing. The operator is one
/// word away from success and is told to go and look somewhere else.
Usage(String),
Unknown(String),
}

// ---------------------------------------------------------------------------
// Command handlers
// ---------------------------------------------------------------------------

/// Every slash command, with what it does.
///
/// One table, because two would drift: `/help` prints it AND the input line
/// completes from it. A command that exists but is not listed here is a command
/// nobody can discover, which is the same as one that does not exist.
pub const COMMANDS: &[(&str, &str)] = &[
("/help", "Show this help message"),
("/status", "Session info, token usage, model"),
("/cost", "Tokens and estimated cost, per model"),
(
"/style [name|off]",
"List the output styles (.incode/styles, ~/.incode/styles), or answer in one from now on",
),
(
"/bug [what happened]",
"A prefilled GitHub issue link: version, OS, model, your words scrubbed. Sends nothing",
),
("/vim", "Toggle vi editing for the input box"),
(
"/compact",
"Summarise older turns now [instructions] (API route; a CLI agent compacts its own)",
),
(
"/review",
"Review the change against [base] (default: where the branch forked)",
),
(
"/undo",
"Put the files from the last change back as they were",
),
(
"/rewind <n>",
"Put the files back as they were n changed turns ago",
),
(
"/agents",
"List the sub-agents defined in .incode/agents and ~/.incode/agents",
),
(
"/doctor",
"Check that this session can work: agents, guards, specs, ledger, memory",
),
(
"/guards",
"Show the paths the agent is not allowed to write",
),
(
"/permissions",
"Show the allow / ask / deny rules in force, and where each came from",
),
(
"/add-dir <path>",
"Also work in this directory — guards and undo extend to it too",
),
(
"/links <file>",
"What else uses what this file defines, and what it depends on",
),
(
"/tools [add|update|remove <name>]",
"List incode's tools and the external ones; install, update or remove an external tool",
),
(
"/skills",
"List the skills this session loaded from the shared store",
),
(
"/mcp",
"Say where MCP servers connect — through incode's toolbox",
),
(
"/model [name]",
"Show or switch the model the agent runs on",
),
(
"/models",
"List the models the current API route's service offers",
),
("/clear", "Start a new agent session on the next turn"),
(
"/save",
"Show the agent session id, to reopen this conversation",
),
(
"/sessions",
"Show the agent session id for this conversation",
),
("/resume <id>", "Continue an agent session by id"),
(
"/remember <text>",
"Save a fact to the shared long-term memory",
),
(
"/forget <ref> [confirm]",
"Delete one memory — shows it first, deletes only on confirm",
),
("/memories <query>", "Search the shared memory by meaning"),
(
"/plan",
"Plan mode — the agent proposes changes without making them",
),
(
"/act",
"Act mode — the agent applies changes, within the guards",
),
(
"/image <path>",
"Send a PNG or JPEG with your next message to the agent",
),
("/bg <command>", "Run a bash command in the background"),
("/jobs", "List background jobs"),
("/kill <id>", "Kill a background job"),
(
"/worktree [cmd]",
"Git worktree management (create/list/remove)",
),
(
"/pr [branch] [--draft]",
"Push a branch (default: the current one) and open its GitHub pull request",
),
(
"/pr merge [branch] [--squash|--rebase]",
"Merge the branch's open pull request, only at its reviewed head with no failing or running check",
),
(
"/diff [file] [rev]",
"Show git/file diff against older versions",
),
("/env", "Show filtered environment variables"),
(
"/admin",
"Show the operator's settings and which layer decided each",
),
(
"/agent [id | sub [id]]",
"List every agent, or choose the lead or the sub-agents",
),
(
"/roles [role <model|@tier>... | role default]",
"Show which models serve each kind of work, or set or clear one",
),
(
"/roadmap",
"What the roadmap says, and which goals a command has proven",
),
(
"/run",
"Work the roadmap ledger until it is empty or something needs a person",
),
("/quit", "Exit incode"),
];

/// The bare command word, without the `<args>` the table shows after it.
#[must_use]
pub fn command_name(entry: &str) -> &str {
entry.split(' ').next().unwrap_or(entry)
}

/// A real command typed without what it needs: say what it needs.
pub fn handle_usage(usage: &str) {
render::print_error(&format!("Usage: {usage}"));
}

pub fn handle_help() {
render::print_header("incode Commands");
for (cmd, desc) in COMMANDS {
outln!(" {cmd:<20} {desc}");
}
let custom = crate::custom_commands::menu();
if !custom.is_empty() {
outln!();
render::print_header("Custom Commands");
for (cmd, desc) in custom {
outln!(" {cmd:<20} {desc}");
}
}
outln!();
}
Loading
Loading