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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,8 @@ MCP servers, skills, commands — is used until you run `incode plugin approve
`.git` left out). Any change to it afterwards leaves it out again until you
approve it again. A session says which were left out; `incode plugin list`
shows each one's state. Yours in `~/.incode/plugins/` need no approval.
Approvals are kept in `~/.incode/plugin-approvals.json`.
Approvals are kept in `~/.incode/plugin-approvals.json`, beside the approvals of
a project's lifecycle commands (`incode lifecycle approve`).

### Output styles

Expand Down Expand Up @@ -1343,7 +1344,7 @@ and `--admin` prints which layer decided each value.
| `sandbox_network` | `allow` (default) · `deny` — see [the OS sandbox](#the-os-sandbox) |
| `sandbox_engine` · `sandbox_allow_hosts` · `sandbox_backend` | `builtin` (default) · `sbx`; under sbx, the hosts a command may reach and, on Windows, `native` · `wsl` · `auto` — see [the OS sandbox](#the-os-sandbox) |
| `codex_tools` | `own` (default) · `incode` — whose tools a `codex` model runs; see [the codex route](#the-codex-route-whose-tools) |
| `hooks` (also `desktop_hooks`) | Your `pre_tool_use` / `post_tool_use` commands, run for every tool, and `user_prompt_submit`, run for each line you send. The event is JSON on stdin (`hook_event_name`, `session_id`, `cwd`, and `tool_name`/`tool_input` or `prompt`); exit 2 on a pre-tool command denies the call, on a prompt command refuses the line (the reason is shown and nothing is sent — not to the agent, not to the memory engine); a prompt command's stdout is added to that turn's context, and your line is never changed; bounded at 10 s. The prompt hook runs for lines typed in the REPL or sent over `--acp`, and for `-t`; for `/review` it sees the review prompt (the change included), and for `/run` each task's instruction before a worker or lane gets it — a refused task fails that attempt, and the hook's output rides that task's turn. It is taken from here and from your own plugins (`~/.incode/plugins/`), never from a project's `.incode/plugins/`, which arrives with whatever was cloned. `pre_compact` runs before `/compact` (event field `trigger`: `manual`, plus `custom_instructions`; when the agent compacts its own conversation, as a CLI agent does, it still runs and nothing is compacted by incode) and before the API route compacts on its own near the context window (`trigger`: `auto`, its output shown as incode's note during the turn); a CLI agent's own automatic compaction happens inside that agent and fires nothing, and `stop` when one of your turns has ended (`last_assistant_message`); neither can refuse anything, and their stdout is shown — with the compaction result, and with the turn's notices. `session_start` runs when a session opens (`source`: `startup`) and `session_end` when it closes (`reason`, e.g. `prompt_input_exit`, `other`), in the REPL, `--acp` and `-t`; neither can stop or keep anything, and their stdout is shown (on stderr for `-t`; a `--acp` session's end output goes to the trace, as the client has gone). They supersede `.incode/lifecycle.json`'s `on_session_start`/`on_session_end`, which still run. `notification` runs whenever incode would notify you (`notification_type`: `turn_done` or `input_needed`, plus `message`), in the background beside `notify_command`, in the REPL; its output is not shown |
| `hooks` (also `desktop_hooks`) | Your `pre_tool_use` / `post_tool_use` commands, run for every tool, and `user_prompt_submit`, run for each line you send. The event is JSON on stdin (`hook_event_name`, `session_id`, `cwd`, and `tool_name`/`tool_input` or `prompt`); exit 2 on a pre-tool command denies the call, on a prompt command refuses the line (the reason is shown and nothing is sent — not to the agent, not to the memory engine); a prompt command's stdout is added to that turn's context, and your line is never changed; bounded at 10 s. The prompt hook runs for lines typed in the REPL or sent over `--acp`, and for `-t`; for `/review` it sees the review prompt (the change included), and for `/run` each task's instruction before a worker or lane gets it — a refused task fails that attempt, and the hook's output rides that task's turn. It is taken from here and from your own plugins (`~/.incode/plugins/`), never from a project's `.incode/plugins/`, which arrives with whatever was cloned. `pre_compact` runs before `/compact` (event field `trigger`: `manual`, plus `custom_instructions`; when the agent compacts its own conversation, as a CLI agent does, it still runs and nothing is compacted by incode) and before the API route compacts on its own near the context window (`trigger`: `auto`, its output shown as incode's note during the turn); a CLI agent's own automatic compaction happens inside that agent and fires nothing, and `stop` when one of your turns has ended (`last_assistant_message`); neither can refuse anything, and their stdout is shown — with the compaction result, and with the turn's notices. `session_start` runs when a session opens (`source`: `startup`) and `session_end` when it closes (`reason`, e.g. `prompt_input_exit`, `other`), in the REPL, `--acp` and `-t`; neither can stop or keep anything, and their stdout is shown (on stderr for `-t`; a `--acp` session's end output goes to the trace, as the client has gone). They supersede a project's `.incode/lifecycle.json` (or the `lifecycle` section of `.incode.json`), whose `on_session_start`/`on_session_end` still run in the REPL — but only once you approve them as they are, since they arrive with whatever was cloned: `incode lifecycle show` lists them, `incode lifecycle approve` approves them, and any change needs approving again. `notification` runs whenever incode would notify you (`notification_type`: `turn_done` or `input_needed`, plus `message`), in the background beside `notify_command`, in the REPL; its output is not shown |
| `desktop_limits` | The desktop's limits, each optional: `max_actions_per_minute` (120), `heartbeat_deadline_secs` (30), `tree_depth` (12), `tree_max_elements` (400), `journal_max_bytes` (262144), `xvfb_start_timeout_secs` (10), `clipboard_timeout_secs` (5), `accessibility_call_timeout_ms` (1000), `paste_restore_delay_ms` (500, how long the pasted text stays on the clipboard before the old one is put back), `settle_ms` (300, the pause before a `screenshot_after`), `max_scroll_steps` (50, wheel steps in one `scroll`), `tree_max_visited` (4000, elements one tree walk may visit), and `blocked_apps` (application names, matched case-insensitively as a part of the name, added to the built-in password managers: 1Password, Bitwarden, LastPass, Dashlane, KeePass, NordPass, Proton Pass, Enpass, RoboForm, Keeper). The first two are safety limits and may only be lowered; zero and unknown keys are refused, and the desktop does not start on a malformed admin.json |
| `desktop_display` | Linux computer use: `":N"` drives a running X display; `"xvfb"` or `"xvfb:1280x800"` starts a private Xvfb for the desktop server's lifetime (default 1920x1080). Unset refuses rather than using `$DISPLAY`. `paste_text` needs `xclip` or `xsel`; `ui_tree` needs a D-Bus session with at-spi2-core |
| `plugins` | Which memory-service parts are used; all on by default |
Expand Down
13 changes: 11 additions & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,20 @@ pub(crate) fn prepare_session(
});
tool_cache.detect_all();

// Lifecycle hooks (Feature 7: session start/end scripts)
// Lifecycle hooks (Feature 7: session start/end scripts). A project's
// run only once the operator approved them as they are
// (`runtime::lifecycle::usable`): they arrive with whatever was cloned.
let lifecycle_hooks = if config.lifecycle_hooks.has_any() {
config.lifecycle_hooks.clone()
} else {
LifecycleHooks::discover(&workspace).unwrap_or_default()
let (hooks, note) = crate::runtime::lifecycle::usable(
&workspace,
&crate::admin::AdminConfig::default_dir(),
);
if let Some(note) = note {
render::print_info(&note);
}
hooks
};

// Load skills (72 bundled + user skills from workspace)
Expand Down
28 changes: 28 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ USAGE:
incode review [--base <REF>] [-p] Review the current change (see `incode review -h`)
incode plugin list | add <git-url | path> | update [name] | remove <name> [--project]
incode mcp <list|get|add|remove|approve> ... (see `incode mcp help`)
incode lifecycle <show|approve> This project's lifecycle commands, which run
only once approved (see `incode lifecycle help`)
incode completions <bash|zsh|fish|powershell> Print a completion script
for that shell (the script says how to load it)

Expand Down Expand Up @@ -252,6 +254,12 @@ const COMPLETION: completions::Command = {
verbs: &["list", "add", "update", "remove", "approve", "help"],
subcommands: &[],
},
Command {
name: "lifecycle",
flags: &[HELP],
verbs: &["show", "approve", "help"],
subcommands: &[],
},
Command {
name: "mcp",
flags: &[HELP],
Expand Down Expand Up @@ -328,6 +336,19 @@ fn main() -> anyhow::Result<()> {
println!("{}", said.trim_end());
return Ok(());
}
// `incode lifecycle ...`: show or approve this project's lifecycle
// commands, which run nowhere until approved.
if raw.first().map(String::as_str) == Some("lifecycle") {
let workspace = std::env::current_dir()?;
let said = incord_code::runtime::lifecycle::cli(
&raw[1..],
&workspace,
&incord_code::admin::AdminConfig::default_dir(),
)
.map_err(|e| anyhow::anyhow!(e))?;
println!("{}", said.trim_end());
return Ok(());
}
}
// NOTE: the crate emits `tracing` events (MCP connection failures, tool
// errors) but no subscriber is installed, so they currently go nowhere.
Expand Down Expand Up @@ -2083,6 +2104,13 @@ mod tests {
}
let ws = tempfile::tempdir().expect("ws");
let data = tempfile::tempdir().expect("data");
for verb in sub("lifecycle").verbs {
if let Err(e) =
incord_code::runtime::lifecycle::cli(&[(*verb).to_string()], ws.path(), data.path())
{
assert!(!e.starts_with("unknown"), "lifecycle {verb}: {e}");
}
}
for verb in sub("mcp").verbs {
if let Err(e) =
incord_code::mcp_config::command(&[(*verb).to_string()], ws.path(), data.path())
Expand Down
23 changes: 22 additions & 1 deletion src/plugin_approvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,35 @@ fn read(data_dir: &Path) -> Result<Store, String> {
///
/// The folder or the store could not be read, or the store not written.
pub fn approve(data_dir: &Path, plugin: &Plugin) -> Result<(), String> {
approve_key(data_dir, &key(plugin)?)
}

/// Record `key` as approved. The store holds every kind of project content
/// the operator approved to run: a plugin ([`key`]), and a project's
/// lifecycle commands (`runtime::lifecycle::approval_key`).
///
/// # Errors
///
/// The store could not be read, or not written.
pub fn approve_key(data_dir: &Path, key: &str) -> Result<(), String> {
let mut store = read(data_dir)?;
store.approved.insert(key(plugin)?);
store.approved.insert(key.to_string());
std::fs::create_dir_all(data_dir).map_err(|e| format!("{}: {e}", data_dir.display()))?;
let path = data_dir.join(FILE);
let text = serde_json::to_string_pretty(&store).map_err(|e| e.to_string())?;
std::fs::write(&path, text).map_err(|e| format!("{}: {e}", path.display()))
}

/// Whether `key` is approved. A store that cannot be read is an error, never
/// quietly "not approved" or "approved".
///
/// # Errors
///
/// The store could not be read or parsed.
pub fn is_approved(data_dir: &Path, key: &str) -> Result<bool, String> {
Ok(read(data_dir)?.approved.contains(key))
}

/// Where `plugin` stands.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum State {
Expand Down
Loading
Loading