Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
feat(agent): add /reload slash command to refresh skills/plugins mid-session
thinhlpg4e67d5d07a1e
diff --git a/docs/src/pages/docs/agent/slash-commands.mdx b/docs/src/pages/docs/agent/slash-commands.mdxindex b91d6d11d..9c4f83619 100644--- a/docs/src/pages/docs/agent/slash-commands.mdx+++ b/docs/src/pages/docs/agent/slash-commands.mdx@@ -66,6 +66,7 @@ See [Run modes](/docs/agent/run-modes), [Goals and todos](/docs/agent/goals-and-| `/effort [low\|medium\|high]` | Set reasoning effort. Bare: show current; `low` is faster, `high` thinks deeper || `/mcp` | List, toggle, add, edit, and remove MCP servers; Enter opens a server's detail screen, where you can list its tools and sign in to it || `/plugin [list\|install <spec>\|remove <name>\|search [query]]` | Manage plugins: install from a git URL or the marketplace, list/remove installed, search the marketplace |+| `/reload [plugin\|skills\|system-prompt]` | Re-scan skills/plugins from disk and rebuild the catalog mid-session (bare: `plugin`), reporting added/removed/changed entries. `system-prompt` re-reads `JAN.md` and applies on the next run || `/login` | Sign in to Tokamak and save the API key || `/config` | View provider config (`~/.jan/config.toml`) || `/terminal-setup` | Configure this terminal so <kbd>Shift</kbd>+<kbd>Enter</kbd> inserts a newline and, on macOS, <kbd>Option</kbd>+<kbd>Delete</kbd> deletes a word. Writes the terminal's own config where it can (VS Code, kitty, Ghostty, tmux) and prints the manual step where it cannot. Idempotent |diff --git a/src-tauri/src/core/agent/context.rs b/src-tauri/src/core/agent/context.rsindex f9c6888b4..b250c0807 100644--- a/src-tauri/src/core/agent/context.rs+++ b/src-tauri/src/core/agent/context.rs@@ -39,10 +39,11 @@ get on with unrelated work or finish the turn.";/// by hand or through `/init` -- becomes authoritative project context.const CONTEXT_FILE_NAME: &str = "JAN.md";-/// Ingest `JAN.md` from the project root and its ancestors, wrapped in a-/// `<project_context>` block so the model treats them as authoritative project-/// instructions. Returns None when none exist.-pub(crate) fn load_context_files(project_root: &Path) -> Option<String> {+/// Read every non-empty `JAN.md` from the project root up to the filesystem+/// root, nearest-first. Shared by the system-prompt builder and the CLI's+/// `/reload system-prompt` report (which needs paths and sizes, not the+/// wrapped block).+pub(crate) fn context_files(project_root: &Path) -> Vec<(std::path::PathBuf, String)> {let mut files: Vec<(std::path::PathBuf, String)> = Vec::new();let mut dir = Some(project_root);while let Some(current) = dir {@@ -54,12 +55,20 @@ pub(crate) fn load_context_files(project_root: &Path) -> Option<String> {}dir = current.parent();}- if files.is_empty() {- return None;- }// Ancestors are collected nearest-first; reverse so the nearest (most// specific) instructions appear last and take precedence.files.reverse();+ files+}++/// Ingest `JAN.md` from the project root and its ancestors, wrapped in a+/// `<project_context>` block so the model treats them as authoritative project+/// instructions. Returns None when none exist.+pub(crate) fn load_context_files(project_root: &Path) -> Option<String> {+ let files = context_files(project_root);+ if files.is_empty() {+ return None;+ }let mut block = String::from("<project_context>\n\nProject-specific instructions and guidelines:\n\n",);diff --git a/src-tauri/src/core/agent/skills.rs b/src-tauri/src/core/agent/skills.rsindex 5e82cea38..ed0520321 100644--- a/src-tauri/src/core/agent/skills.rs+++ b/src-tauri/src/core/agent/skills.rs@@ -538,12 +538,20 @@ pub(crate) fn user_catalog(root: &Path, enabled: &[String]) -> Vec<SkillMeta> {side_catalog(root, enabled, |p| p.user_invocable)}+/// Every discovered skill (project + plugin), both invocation sides, ignoring+/// the enabled whitelist — the full disk truth. This is what `/reload skills`+/// diffs against the previous scan, so an edit or install shows up as an+/// added/removed/changed entry regardless of who may invoke it.+pub(crate) fn full_catalog(root: &Path) -> Vec<SkillMeta> {+ side_catalog(root, &[], |_| true)+}+/// Metadata for every skill one plugin ships (both invocation sides), for the/// `/plugin list` view. The enabled whitelist is intentionally ignored here:/// the management view shows what the plugin contributes, not what is active.#[cfg(feature = "cli")]pub(crate) fn plugin_skill_metas(root: &Path, plugin: &str) -> Vec<SkillMeta> {- let mut metas = side_catalog(root, &[], |_| true);+ let mut metas = full_catalog(root);metas.retain(|m| m.plugin.as_deref() == Some(plugin));metas}diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rsindex 8742f2f0c..d326c5925 100644--- a/src-tauri/src/core/cli/tui.rs+++ b/src-tauri/src/core/cli/tui.rs@@ -11788,10 +11788,18 @@ struct SlashCommand {}/// Slash popup metadata is intentionally loaded outside the render path.-/// Plugin installation and removal explicitly refresh this snapshot.+/// Plugin installation and removal explicitly refresh this snapshot — as does+/// `/reload`, which diffs a fresh scan against it to report what changed.struct SlashCatalog {commands: Vec<crate::core::agent::plugin_commands::CommandEntry>,skills: Vec<crate::core::agent::skills::SkillMeta>,+ /// Installed plugin summaries from the same scan, for `/reload plugin`'s+ /// added/removed/updated report.+ plugins: Vec<crate::core::agent::plugins::InstalledPlugin>,+ /// Every discovered skill, both invocation sides — the full disk truth+ /// `/reload skills` diffs against (the popup list above is only the+ /// user-invocable subset).+ all_skills: Vec<crate::core::agent::skills::SkillMeta>,}impl SlashCatalog {@@ -11801,6 +11809,8 @@ impl SlashCatalog {// Keep every user-invocable skill here. The enabled whitelist is// re-read below so edits to agent.toml take effect immediately.skills: crate::core::agent::skills::user_catalog(root, &[]),+ plugins: crate::core::agent::plugins::installed(root),+ all_skills: crate::core::agent::skills::full_catalog(root),}}@@ -12147,6 +12157,12 @@ const SLASH_COMMANDS: &[SlashCommand] = &[description: "Manage plugins: install from a git URL or the marketplace, list/remove installed, search the marketplace",alias_of: None,},+ SlashCommand {+ name: "/reload",+ hint: "[plugin|skills|system-prompt]",+ description: "Re-scan skills/plugins from disk and rebuild the catalog mid-session (bare: plugin)",+ alias_of: None,+ },SlashCommand {name: "/cancel",hint: "[N]",@@ -12383,6 +12399,7 @@ async fn run_command("agents" => open_agents_picker(app),"shells" | "jobs" => open_background_shells_picker(app),"plugin" => plugin_command(app, arg).await,+ "reload" => reload_command(app, arg),"login" => login_command(app, arg),"logout" => logout_command(app, arg),"update" => update_command(app),@@ -14423,6 +14440,152 @@ async fn plugin_command(app: &mut App, arg: &str) {}}+/// One diffable catalog entry for `/reload`: `key` is the stable identity,+/// `label` the display line, `state` everything whose change marks the entry+/// as updated (version/description/counts for plugins, description and+/// invocation flags for skills).+struct ReloadEntry {+ key: String,+ label: String,+ state: String,+}++/// Snapshot the installed-plugin summaries for `/reload plugin`'s diff.+fn reload_plugin_entries(plugins: &[crate::core::agent::plugins::InstalledPlugin]) -> Vec<ReloadEntry> {+ plugins+ .iter()+ .map(|p| ReloadEntry {+ key: p.name.clone(),+ label: format!("plugin {} (v{})", p.name, p.version),+ state: format!(+ "v{} · {} skill(s) · {} command(s) · {} agent(s) · {}",+ p.version, p.skills, p.commands, p.agents, p.description+ ),+ })+ .collect()+}++/// Snapshot the full skill catalog for `/reload skills`'s diff, keyed by+/// qualified name (`<plugin>:<skill>` for plugin skills).+fn reload_skill_entries(skills: &[crate::core::agent::skills::SkillMeta]) -> Vec<ReloadEntry> {+ skills+ .iter()+ .map(|m| {+ let name = m+ .plugin+ .as_ref()+ .map_or_else(|| m.name.clone(), |p| format!("{p}:{}", m.name));+ ReloadEntry {+ key: name.clone(),+ label: name,+ state: format!(+ "{} [user:{} model:{}]",+ m.description, m.user_invocable, m.model_invocable+ ),+ }+ })+ .collect()+}++/// Diff two catalog snapshots by identity, returning display lines for+/// added, removed, and updated entries in scan order.+fn diff_reload_entries(+ before: &[ReloadEntry],+ after: &[ReloadEntry],+) -> (Vec<String>, Vec<String>, Vec<String>) {+ fn keyed(items: &[ReloadEntry]) -> std::collections::BTreeMap<String, &ReloadEntry> {+ items.iter().map(|e| (e.key.clone(), e)).collect()+ }+ let (old, new) = (keyed(before), keyed(after));+ let mut added = Vec::new();+ let mut removed = Vec::new();+ let mut updated = Vec::new();+ for (key, entry) in &new {+ match old.get(key) {+ None => added.push(entry.label.clone()),+ Some(prev) if prev.state != entry.state => updated.push(format!(+ "{} ({} → {})",+ entry.label, prev.state, entry.state+ )),+ Some(_) => {}+ }+ }+ for (key, entry) in &old {+ if !new.contains_key(key) {+ removed.push(entry.label.clone());+ }+ }+ (added, removed, updated)+}++/// `/reload [plugin|skills|system-prompt]`: re-run skill/plugin discovery and+/// rebuild the slash catalog mid-session, reporting added/removed/changed+/// entries. Bare `/reload` targets plugins — the payload an install most+/// often changes. The model-facing system prompt (JAN.md instructions, the+/// skills catalog) is rebuilt from disk on every run, so the `system-prompt`+/// target re-reads and reports what the next run picks up.+fn reload_command(app: &mut App, arg: &str) {+ let root = app.project_root.clone();+ match arg.trim() {+ "" | "plugin" | "plugins" => {+ let before = reload_plugin_entries(&app.slash_catalog.plugins);+ app.refresh_slash_catalog();+ let after = reload_plugin_entries(&app.slash_catalog.plugins);+ app.note("◈ reload · plugin · re-scanned installed plugins");+ report_reload_diff(app, diff_reload_entries(&before, &after));+ }+ "skill" | "skills" => {+ let before = reload_skill_entries(&app.slash_catalog.all_skills);+ app.refresh_slash_catalog();+ let after = reload_skill_entries(&app.slash_catalog.all_skills);+ app.note("◈ reload · skills · re-scanned project and plugin skills");+ report_reload_diff(app, diff_reload_entries(&before, &after));+ }+ "system-prompt" => {+ // Nothing caches the instructions across runs: the system prompt+ // (including this block and the skills catalog) is rebuilt from+ // disk at the start of every run. Re-read now to confirm what the+ // next run will pick up.+ let files = crate::core::agent::context::context_files(&root);+ if files.is_empty() {+ app.note("◈ reload · system-prompt · no JAN.md in this project or its ancestors");+ return;+ }+ app.note("◈ reload · system-prompt · re-read project instructions (applies next run)");+ for (path, content) in &files {+ app.system_detail_text(&format!(+ " {} ({} bytes)",+ path.display(),+ content.len()+ ));+ }+ }+ other => app.note(&format!(+ "unknown /reload target '{other}' (try plugin | skills | system-prompt)"+ )),+ }+}++/// Print a reload diff, or the unchanged note when the scan found nothing new.+fn report_reload_diff(+ app: &mut App,+ (added, removed, updated): (Vec<String>, Vec<String>, Vec<String>),+) {+ if added.is_empty() && removed.is_empty() && updated.is_empty() {+ app.system_detail_text(" no changes since the last scan");+ return;+ }+ for line in added {+ app.system_detail_text(&format!(" + {line}"));+ }+ for line in removed {+ app.system_detail_text(&format!(" - {line}"));+ }+ for line in updated {+ app.system_detail_text(&format!(" ~ {line}"));+ }+}+/// Print the active goal's condition, turn count, duration, and the evaluator's/// latest reason. Notes when there is no goal.fn show_goal_status(app: &mut App) {@@ -36300,11 +36463,15 @@ mod tests {fn slash_prefix_narrows_and_unmatched_hides() {let mut app = test_app();app.input = "/re".into();- // Both `/resume` and `/reasoning` start with `re`; catalog order- // (stable sort on equal prefix score) keeps resume first.+ // `/resume`, `/reasoning`, and `/reload` start with `re`; catalog+ // order (stable sort on equal prefix score) keeps resume first.assert_eq!(names(&app),- vec!["/resume".to_string(), "/reasoning".to_string()]+ vec![+ "/resume".to_string(),+ "/reasoning".to_string(),+ "/reload".to_string()+ ]);app.input = "/xyz".into();assert!(app.slash_matches().is_empty());@@ -36804,6 +36971,140 @@ mod tests {let _ = std::fs::remove_dir_all(&root);}+ /// A plugin summary manifest on disk, so `/reload plugin` has a version+ /// to report.+ fn plugin_manifest_in_app(root: &std::path::Path, plugin: &str, version: &str) {+ std::fs::write(+ root.join(".jan/agent/plugins")+ .join(plugin)+ .join("plugin.toml"),+ format!("name = \"{plugin}\"\nversion = \"{version}\"\n"),+ )+ .unwrap();+ }++ #[tokio::test]+ async fn reload_bare_defaults_to_plugin_and_reports_changes() {+ let (mut app, root) = skill_test_app("deploy", "How to deploy.");+ // Bare /reload targets plugins; nothing installed, nothing changed.+ run_command(&mut app, "reload", &no_mcp()).await;+ let out = transcript_text(&app);+ assert!(+ out.contains("re-scanned installed plugins"),+ "note: {out}"+ );+ assert!(+ out.contains("no changes since the last scan"),+ "diff: {out}"+ );++ // Install a plugin payload on disk; the next reload reports it and+ // the rebuilt catalog serves its command immediately.+ plugin_command_in_app(&root, "acme", "ship", "---\ndescription: Ship it\n---\nGo");+ plugin_manifest_in_app(&root, "acme", "1.0.0");+ run_command(&mut app, "reload", &no_mcp()).await;+ let out = transcript_text(&app);+ assert!(out.contains("+ plugin acme (v1.0.0)"), "diff: {out}");+ assert!(+ app.slash_catalog+ .commands+ .iter()+ .any(|c| c.plugin == "acme" && c.name == "ship"),+ "command must be live after reload"+ );++ // A second reload has an up-to-date snapshot: nothing changed.+ run_command(&mut app, "reload plugin", &no_mcp()).await;+ assert!(transcript_text(&app).contains("no changes since the last scan"));+ let _ = std::fs::remove_dir_all(&root);+ }++ #[tokio::test]+ async fn reload_skills_reports_added_changed_and_removed() {+ let (mut app, root) = skill_test_app("deploy", "How to deploy.");+ run_command(&mut app, "reload skills", &no_mcp()).await;+ assert!(transcript_text(&app).contains("no changes since the last scan"));++ let skills = root.join(".jan/agent/skills");++ // Added: a new skill shows up and joins the popup catalog.+ std::fs::create_dir_all(skills.join("audit")).unwrap();+ std::fs::write(+ skills.join("audit").join("SKILL.md"),+ "---\ndescription: Audit deps\n---\n\nBody.\n",+ )+ .unwrap();+ run_command(&mut app, "reload skills", &no_mcp()).await;+ let out = transcript_text(&app);+ assert!(out.contains("+ audit"), "diff: {out}");+ assert!(+ app.slash_catalog+ .skills+ .iter()+ .any(|m| m.name == "audit"),+ "skill must be live after reload"+ );++ // Changed: an edited description is reported as an update.+ std::fs::write(+ skills.join("deploy").join("SKILL.md"),+ "---\ndescription: How to ship\n---\n\nBody.\n",+ )+ .unwrap();+ run_command(&mut app, "reload skills", &no_mcp()).await;+ let out = transcript_text(&app);+ assert!(+ out.contains("~ deploy (How to deploy."),+ "diff: {out}"+ );+ assert!(out.contains("→ How to ship"), "diff: {out}");++ // Removed: a deleted skill leaves the catalog.+ std::fs::remove_dir_all(skills.join("audit")).unwrap();+ run_command(&mut app, "reload skills", &no_mcp()).await;+ let out = transcript_text(&app);+ assert!(out.contains("- audit"), "diff: {out}");+ assert!(+ !app.slash_catalog.skills.iter().any(|m| m.name == "audit"),+ "removed skill must drop from the catalog"+ );+ let _ = std::fs::remove_dir_all(&root);+ }++ #[tokio::test]+ async fn reload_system_prompt_reads_jan_md() {+ let (mut app, root) = skill_test_app("deploy", "How to deploy.");+ run_command(&mut app, "reload system-prompt", &no_mcp()).await;+ assert!(+ transcript_text(&app).contains("no JAN.md in this project"),+ "empty project: {}",+ transcript_text(&app)+ );++ std::fs::write(root.join("JAN.md"), "# Rules\n\nRun the tests.\n").unwrap();+ run_command(&mut app, "reload system-prompt", &no_mcp()).await;+ let out = transcript_text(&app);+ assert!(out.contains("re-read project instructions"), "{out}");+ assert!(out.contains("JAN.md"), "{out}");+ let _ = std::fs::remove_dir_all(&root);+ }++ #[test]+ fn slash_commands_include_reload() {+ assert!(SLASH_COMMANDS.iter().any(|c| c.name == "/reload"));+ }++ #[tokio::test]+ async fn reload_unknown_target_notes_usage() {+ let mut app = test_app();+ run_command(&mut app, "reload bogus", &no_mcp()).await;+ assert!(+ transcript_text(&app).contains("unknown /reload target 'bogus'"),+ "{}",+ transcript_text(&app)+ );+ }+#[tokio::test]async fn plugin_command_installs_lists_dispatch_removes() {// Local git repo fixture with a plugin payload.