Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

Merge remote-tracking branch 'origin/main' into HEAD

thinhlpg52405fe38fbc
diff --cc docs/src/pages/docs/agent/slash-commands.mdx
index f050860ea,0f241d05d..bfdc2f256
--- a/docs/src/pages/docs/agent/slash-commands.mdx
+++ b/docs/src/pages/docs/agent/slash-commands.mdx
@@@ -65,7 -65,8 +65,8 @@@ See [Run modes](/docs/agent/run-modes)
| `/model [id]` | Switch model. Bare: pick interactively. Opening the picker re-lists each provider's models once per session; <kbd>Ctrl</kbd>+<kbd>R</kbd> inside it re-lists them again on demand |
| `/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 |
+| `/plugin [list\|install <spec>\|remove <name>\|search [query]\|setup [name]]` | Install and manage plugins. Installation opens setup automatically: masked API-key entry, then confirmation to enable declared MCP servers and sign in when required. Bare `setup` opens a single-plugin picker; `setup <name>` resumes that plugin directly without manual MCP configuration or restarting Jan |
+ | `/skills` | List every skill Jan can see from this project, with its scope (`project`, `plugin`, `user`, `built-in`), invocation flags, and whether it is disabled. A skill hidden by a same-named higher-precedence one is marked `shadowed by <scope>` |
| `/reload [config\|plugin\|skills\|system-prompt]` | Re-read on-disk state into the running session without a restart (bare: all). `config` re-applies the project's `agent.toml` limits - `context_window`, `compaction_ratio`, `compaction_reserve_tokens`, `max_tokens`, `send_reasoning`, `[budget].max_tokens` - to the next run and lists what changed; the model, `[tools]`, `[provider]` and `[budget].max_usd` still need a restart. `plugin`/`skills` re-scan and rebuild the catalog, reporting added/removed/changed entries. `system-prompt` re-reads `JAN.md`, which applies on the next run |
| `/login` | Sign in to Tokamak and save the API key |
| `/config` | View provider config (`~/.jan/config.toml`) |
diff --cc src-tauri/src/core/agent/skills.rs
index 893ee3b93,792ab858d..5f8ab7a36
--- a/src-tauri/src/core/agent/skills.rs
+++ b/src-tauri/src/core/agent/skills.rs
@@@ -203,15 -266,38 +266,42 @@@ pub(crate) fn scan_skill_dir(dir: &Path
out
}
-/// All project skills (`<store_root>/skills`), sorted by name.
+/// All project skills (`<store_root>/skills`), sorted by name. A linked git
+/// worktree shares its main checkout's skills because
+/// [`crate::core::agent::project::store_root`] maps both to one store.
pub(crate) fn discover(root: &Path) -> Vec<SkillEntry> {
- scan_skill_dir(&skills_dir(root))
+ let mut out = scan_skill_dir(&skills_dir(root));
+ out.sort_by(|a, b| a.name.cmp(&b.name));
+ out
}
+ /// All user-scope skills (`~/.jan/skills`), sorted by name.
+ pub(crate) fn discover_user() -> Vec<SkillEntry> {
+ let Some(dir) = user_skills_dir() else {
+ return Vec::new();
+ };
+ scan_skill_dir(&dir)
+ .into_iter()
+ .map(|e| SkillEntry { user: true, ..e })
+ .collect()
+ }
+
+ /// A skill file's identity on disk for deduplication: its canonical path, so
+ /// the same folder reached through two symlinks (or a project `skills/` that
+ /// is itself a link to `~/.jan/skills`) counts once.
+ fn canonical(file: &Path) -> PathBuf {
+ std::fs::canonicalize(file).unwrap_or_else(|_| file.to_path_buf())
+ }
+
+ /// A skill that lost to a higher-precedence one of the same name.
+ #[derive(Debug, Clone)]
+ #[cfg_attr(not(any(feature = "cli", test)), allow(dead_code))]
+ pub(crate) struct Shadowed {
+ pub entry: SkillEntry,
+ /// The scope of the skill that wins.
+ pub by: SkillScope,
+ }
+
/// The plugins directory `<store_root>/plugins`.
pub(crate) fn plugins_dir(root: &Path) -> PathBuf {
crate::core::agent::project::store_root(root).join("plugins")
@@@ -296,26 -353,44 +386,27 @@@ pub(crate) fn invocation_wrapper(name:
/// (folder and flat forms, same rules as project skills) plus an optional
/// single `SKILL.md` at the plugin root (a repo that is itself one skill).
pub(crate) fn discover_plugins(root: &Path) -> Vec<SkillEntry> {
- let dir = plugins_dir(root);
- let Ok(rd) = std::fs::read_dir(&dir) else {
- return Vec::new();
- };
let mut out: Vec<SkillEntry> = Vec::new();
- for entry in rd.flatten() {
- let path = entry.path();
- if !entry.file_type().map(|t| t.is_dir()).unwrap_or(false) {
- continue;
- }
- let Some(plugin) = path.file_name().and_then(|s| s.to_str()) else {
- continue;
- };
- // Ignore interrupted `.installing-*` staging directories, matching the
- // command/agent loaders: a partially-copied plugin must not leak its
- // skills into the catalog during an install.
- if plugin.starts_with(".installing-") {
- continue;
- }
+ for_each_plugin_dir(root, |plugin, path| {
let mut tagged = Vec::new();
- for e in scan_skill_dir(&path.join("skills")) {
- tagged.push(SkillEntry {
- plugin: Some(plugin.to_string()),
- ..e
- });
- }
- let root_md = path.join("SKILL.md");
- if root_md.is_file() {
- tagged.push(SkillEntry {
- name: plugin.to_string(),
- file: root_md,
- is_folder: false,
- plugin: Some(plugin.to_string()),
- user: false,
- });
- }
- out.extend(tagged);
- }
+ for e in scan_skill_dir(&path.join("skills")) {
+ tagged.push(SkillEntry {
+ plugin: Some(plugin.to_string()),
+ ..e
+ });
+ }
+ let root_md = path.join("SKILL.md");
+ if root_md.is_file() {
+ tagged.push(SkillEntry {
+ name: plugin.to_string(),
+ file: root_md,
+ is_folder: false,
+ plugin: Some(plugin.to_string()),
++ user: false,
+ });
+ }
+ out.extend(tagged);
+ });
out.sort_by(|a, b| a.name.cmp(&b.name));
out
}
@@@ -1238,68 -1463,205 +1479,270 @@@ mod tests
let _ = std::fs::remove_dir_all(&root);
}
+ /// A repo with one commit plus a linked worktree, or skip when git is
+ /// unavailable. Returns `(main_root, linked_root)`.
+ fn repo_with_linked_worktree(tag: &str) -> Option<(std::path::PathBuf, std::path::PathBuf)> {
+ if std::process::Command::new("git").arg("--version").output().is_err() {
+ return None;
+ }
+ let n = std::time::SystemTime::UNIX_EPOCH
+ .elapsed()
+ .unwrap()
+ .as_nanos();
+ let main = std::env::temp_dir().join(format!("jan_wt_main_{tag}_{n}"));
+ std::fs::create_dir_all(&main).unwrap();
+ let run = |args: &[&str]| -> bool {
+ std::process::Command::new("git")
+ .args(args)
+ .current_dir(&main)
+ .status()
+ .map(|s| s.success())
+ .unwrap_or(false)
+ };
+ if !run(&["init", "-q", "."])
+ || !run(&["commit", "--allow-empty", "-q", "-m", "init"])
+ {
+ return None;
+ }
+ let linked = std::env::temp_dir().join(format!("jan_wt_link_{tag}_{n}"));
+ let l = linked.to_string_lossy().to_string();
+ if !run(&["worktree", "add", &l]) {
+ return None;
+ }
+ Some((main, linked))
+ }
+
+ /// Skills and plugins installed in the main worktree are visible from a
+ /// linked worktree: the store follows the repo, not the checkout.
+ #[test]
+ fn linked_worktree_sees_main_worktree_skills_and_plugins() {
+ let Some((main, linked)) = repo_with_linked_worktree("discover") else {
+ return;
+ };
+ // git resolves paths through realpath, and on macOS /var is a symlink
+ // to /private/var: canonicalize so prefix comparisons hold.
+ let main = std::fs::canonicalize(&main).unwrap();
+ let linked = std::fs::canonicalize(&linked).unwrap();
+ project_skill(&main, "shared", "shared\n");
+ plugin_skill(&main, "shared-plugin", "prep", "plugin\n");
+
+ // Both the shared skill and the shared plugin's skills are visible
+ // from the linked worktree, under the linked root.
+ let names: Vec<String> = discover(&linked).iter().map(|e| e.name.clone()).collect();
+ assert!(names.contains(&"shared".to_string()), "{names:?}");
+ let plugins = discover_plugins(&linked);
+ assert_eq!(
+ plugins.iter().map(qualified_name).collect::<Vec<_>>(),
+ vec!["shared-plugin:prep".to_string()]
+ );
+ // Both checkouts resolve to one store, so the file lives in it.
+ let entry = resolve_readable(&linked, "shared-plugin:prep").unwrap();
+ assert!(entry.file.starts_with(plugins_dir(&main)), "{:?}", entry.file);
+ assert_eq!(plugins_dir(&linked), plugins_dir(&main));
+
+ let _ = std::fs::remove_dir_all(&main);
+ let _ = std::fs::remove_dir_all(&linked);
+ }
++
+ /// Skills written into the (per-process, test-only) user scope
+ /// `~/.jan/skills`, removed on drop so no other test sees them.
+ struct UserSkills(Vec<std::path::PathBuf>);
+
+ impl UserSkills {
+ fn new() -> Self {
+ Self(Vec::new())
+ }
+
+ fn folder(&mut self, name: &str, body: &str) -> std::path::PathBuf {
+ let dir = user_skills_dir().unwrap().join(name);
+ std::fs::create_dir_all(&dir).unwrap();
+ std::fs::write(dir.join("SKILL.md"), body).unwrap();
+ self.0.push(dir.clone());
+ dir
+ }
+
+ fn flat(&mut self, name: &str, body: &str) {
+ let dir = user_skills_dir().unwrap();
+ std::fs::create_dir_all(&dir).unwrap();
+ let file = dir.join(format!("{name}.md"));
+ std::fs::write(&file, body).unwrap();
+ self.0.push(file);
+ }
+
+ /// Track a path created by the test itself (a symlink, say).
+ fn track(&mut self, path: std::path::PathBuf) {
+ self.0.push(path);
+ }
+ }
+
+ impl Drop for UserSkills {
+ fn drop(&mut self) {
+ for path in &self.0 {
+ if std::fs::symlink_metadata(path).is_ok_and(|m| m.is_dir()) {
+ let _ = std::fs::remove_dir_all(path);
+ } else {
+ let _ = std::fs::remove_file(path);
+ }
+ }
+ }
+ }
+
+ #[test]
+ fn user_scope_skills_reach_catalogs_and_reads_from_any_project() {
+ let mut user = UserSkills::new();
+ user.folder("u394-review", "---\ndescription: Review a diff\n---\nreview body\n");
+ user.flat("u394-notes", "---\ndescription: Take notes\n---\nnotes body\n");
+ for tag in ["ua", "ub"] {
+ let root = temp_root(tag);
+ let model = catalog(&root, &[]);
+ let m = model.iter().find(|m| m.name == "u394-review").expect("user skill listed");
+ assert_eq!(m.scope, SkillScope::User);
+ assert_eq!(m.description, "Review a diff");
+ assert!(model.iter().any(|m| m.name == "u394-notes"), "flat user skill");
+ assert!(user_catalog(&root, &[]).iter().any(|m| m.name == "u394-review"));
+ assert_eq!(read_for_model(&root, &[], "u394-review").unwrap(), "review body");
+ assert_eq!(read_for_model(&root, &[], "u394-notes").unwrap(), "notes body");
+ let (msg, _) = build_invocation_message(&root, "u394-review", "").unwrap();
+ assert!(msg.contains("review body"), "{msg}");
+ let _ = std::fs::remove_dir_all(&root);
+ }
+ }
+
+ #[test]
+ fn project_skill_shadows_a_same_named_user_skill_and_report_marks_it() {
+ let mut user = UserSkills::new();
+ user.folder("u394-deploy", "---\ndescription: user deploy\n---\nuser body\n");
+ let root = temp_root("shadow");
+ project_skill(&root, "u394-deploy", "---\ndescription: project deploy\n---\nproject body\n");
+
+ let model = catalog(&root, &[]);
+ let hits: Vec<_> = model.iter().filter(|m| m.name == "u394-deploy").collect();
+ assert_eq!(hits.len(), 1, "one entry per name");
+ assert_eq!(hits[0].scope, SkillScope::Project);
+ assert_eq!(hits[0].description, "project deploy");
+ assert_eq!(read_for_model(&root, &[], "u394-deploy").unwrap(), "project body");
+
+ let rows = report(&root, &[]);
+ let rows: Vec<_> = rows.iter().filter(|r| r.name == "u394-deploy").collect();
+ assert_eq!(rows.len(), 2, "winner and shadowed entry both reported");
+ assert_eq!((rows[0].scope, rows[0].shadowed_by), (SkillScope::Project, None));
+ assert_eq!(
+ (rows[1].scope, rows[1].shadowed_by),
+ (SkillScope::User, Some(SkillScope::Project))
+ );
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ #[test]
+ fn plugin_skills_stay_qualified_beside_a_same_named_user_skill() {
+ let mut user = UserSkills::new();
+ user.folder("u394-prepare", "---\ndescription: user prep\n---\nuser prep body\n");
+ let root = temp_root("plugq");
+ plugin_skill(&root, "rel", "u394-prepare", "---\ndescription: plugin prep\n---\nplugin prep body\n");
+
+ let model = catalog(&root, &[]);
+ let plain = model.iter().find(|m| m.name == "u394-prepare").unwrap();
+ assert_eq!(plain.scope, SkillScope::User);
+ let qualified = model.iter().find(|m| m.name == "rel:u394-prepare").unwrap();
+ assert_eq!(qualified.scope, SkillScope::Plugin);
+ // The plain name is the user skill; the qualified name is the plugin's.
+ assert_eq!(read_for_model(&root, &[], "u394-prepare").unwrap(), "user prep body");
+ assert_eq!(read_for_model(&root, &[], "rel:u394-prepare").unwrap(), "plugin prep body");
+ // Nothing is shadowed: the names differ.
+ assert!(report(&root, &[]).iter().all(|r| r.shadowed_by.is_none() || r.name == "jan"));
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ #[test]
+ fn built_in_jan_is_shadowed_by_a_user_skill_named_jan() {
+ let mut user = UserSkills::new();
+ user.folder("jan", "---\ndescription: my jan\n---\nmine\n");
+ let root = temp_root("janu");
+ let model = catalog(&root, &[]);
+ let jan: Vec<_> = model.iter().filter(|m| m.name == "jan").collect();
+ assert_eq!(jan.len(), 1);
+ assert_eq!(jan[0].scope, SkillScope::User);
+ assert_eq!(read_for_model(&root, &[], "jan").unwrap(), "mine");
+ let builtin = report(&root, &[])
+ .into_iter()
+ .find(|r| r.scope == SkillScope::Builtin)
+ .unwrap();
+ assert_eq!(builtin.shadowed_by, Some(SkillScope::User));
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ #[test]
+ fn model_reads_plugin_skills_and_honours_filters() {
+ let root = temp_root("plugread");
+ plugin_skill(&root, "rel", "prepare", "---\ndescription: prep\n---\nprep body\n");
+ plugin_skill(
+ &root,
+ "rel",
+ "secret",
+ "---\ndescription: s\ndisable-model-invocation: true\n---\nno\n",
+ );
+ // Qualified and unique-plain names both read.
+ assert_eq!(read_for_model(&root, &[], "rel:prepare").unwrap(), "prep body");
+ assert_eq!(read_for_model(&root, &[], "prepare").unwrap(), "prep body");
+ // A user-only skill never reaches the model.
+ assert!(read_for_model(&root, &[], "rel:secret").is_err());
+ // The whitelist applies: a plugin not enabled is unreadable.
+ assert!(read_for_model(&root, &["other".into()], "rel:prepare").is_err());
+ assert!(read_for_model(&root, &["rel".into()], "rel:prepare").is_ok());
+ // The built-in jan skill still reads.
+ assert!(!read_for_model(&root, &[], "jan").unwrap().is_empty());
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
+ #[cfg(unix)]
+ #[test]
+ fn symlinked_skill_folders_are_listed_in_both_scopes_and_deduped() {
+ use std::os::unix::fs::symlink;
+ let library = temp_root("library");
+ for name in ["u394-linked-proj", "u394-linked-user"] {
+ let dir = library.join(name);
+ std::fs::create_dir_all(&dir).unwrap();
+ std::fs::write(dir.join("SKILL.md"), format!("---\ndescription: {name}\n---\nbody\n"))
+ .unwrap();
+ }
+ let root = temp_root("symlink");
+ let proj_dir = skills_dir(&root);
+ std::fs::create_dir_all(&proj_dir).unwrap();
+ symlink(library.join("u394-linked-proj"), proj_dir.join("u394-linked-proj")).unwrap();
+ // A symlink loop and a dangling link must be skipped, not hang or panic.
+ symlink(proj_dir.join("loop-b"), proj_dir.join("loop-a")).unwrap();
+ symlink(proj_dir.join("loop-a"), proj_dir.join("loop-b")).unwrap();
+ symlink(library.join("missing"), proj_dir.join("dangling")).unwrap();
+ // A self-referencing folder link (`dir/self -> dir`) is one level only.
+ symlink(&proj_dir, proj_dir.join("self")).unwrap();
+
+ let mut user = UserSkills::new();
+ let user_dir = user_skills_dir().unwrap();
+ std::fs::create_dir_all(&user_dir).unwrap();
+ let link = user_dir.join("u394-linked-user");
+ symlink(library.join("u394-linked-user"), &link).unwrap();
+ user.track(link);
+ // The same library folder linked into both scopes counts once.
+ let dup = user_dir.join("u394-linked-proj");
+ symlink(library.join("u394-linked-proj"), &dup).unwrap();
+ user.track(dup);
+
+ let model = catalog(&root, &[]);
+ let names: Vec<_> = model.iter().map(|m| (m.name.as_str(), m.scope)).collect();
+ assert!(names.contains(&("u394-linked-proj", SkillScope::Project)), "{names:?}");
+ assert!(names.contains(&("u394-linked-user", SkillScope::User)), "{names:?}");
+ assert_eq!(
+ names.iter().filter(|(n, _)| *n == "u394-linked-proj").count(),
+ 1,
+ "{names:?}"
+ );
+ assert!(!names.iter().any(|(n, _)| n.starts_with("loop") || *n == "dangling"));
+ // The duplicate is not reported as shadowing: it is the same file.
+ assert!(report(&root, &[])
+ .iter()
+ .all(|r| r.name != "u394-linked-proj" || r.shadowed_by.is_none()));
+ assert_eq!(read_for_model(&root, &[], "u394-linked-user").unwrap(), "body");
+ let _ = std::fs::remove_dir_all(&root);
+ let _ = std::fs::remove_dir_all(&library);
+ }
}
diff --cc src-tauri/src/core/cli/tui.rs
index b3a2ae61b,0b9e9faaf..62c3bdb0a
--- a/src-tauri/src/core/cli/tui.rs
+++ b/src-tauri/src/core/cli/tui.rs
@@@ -12626,10 -12303,16 +12716,16 @@@ const SLASH_COMMANDS: &[SlashCommand]
},
SlashCommand {
name: "/plugin",
- hint: "[list|install <spec>|remove <name>|search [query]]",
- description: "Manage plugins: install from a git URL or the marketplace, list/remove installed, search the marketplace",
+ hint: "[list|install <spec>|remove <name>|search [query]|setup [name]]",
+ description: "Manage plugins: install, list/remove, search, or choose a plugin to set up its API keys and MCP connections",
alias_of: None,
},
+ SlashCommand {
+ name: "/skills",
+ hint: "",
+ description: "List skills with their scope (project, plugin, user, built-in) and shadowing",
+ alias_of: None,
+ },
SlashCommand {
name: "/reload",
hint: "[config|plugin|skills|system-prompt]",