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.

fix(agent): report skill changes on bare /reload and share limit resolution

thinhlpg44f0d6205258
diff --git a/docs/src/pages/docs/agent/plugins.mdx b/docs/src/pages/docs/agent/plugins.mdx
index 0b49b1dd2..b9d613d8f 100644
--- a/docs/src/pages/docs/agent/plugins.mdx
+++ b/docs/src/pages/docs/agent/plugins.mdx
@@ -75,6 +75,10 @@ The plugin is cloned (`--depth 1`), validated to contain a plugin manifest, `ski
Reinstalling an existing plugin is refused (remove it first). Specs with shell metacharacters are
rejected outright - a plugin name is a name, not a command.
+A plugin installed or edited outside the running session (another terminal, `git pull`, a hand
+edit) is picked up with `/reload plugin`, which re-scans and reports what was added, removed, or
+changed without restarting.
+
## Invoking plugin skills
Plugin skills are qualified with their plugin name: `release-tools:prepare`.
diff --git a/docs/src/pages/docs/agent/project-config.mdx b/docs/src/pages/docs/agent/project-config.mdx
index 211a62d37..cbf74d55d 100644
--- a/docs/src/pages/docs/agent/project-config.mdx
+++ b/docs/src/pages/docs/agent/project-config.mdx
@@ -115,6 +115,11 @@ inject = "always"
### `[agent]`
+The running agent reads this file at startup. After editing `context_window`, `compaction_ratio`,
+`compaction_reserve_tokens`, `max_tokens`, `send_reasoning`, or `[budget].max_tokens`, run
+`/reload config` to apply them from the next run without restarting. The model, `[tools]`,
+`[provider]`, and `[budget].max_usd` still need a restart.
+
| Key | Default | Description |
| --- | --- | --- |
| `model` | inherited | Model id. Overridden by `--model` |
diff --git a/docs/src/pages/docs/agent/skills.mdx b/docs/src/pages/docs/agent/skills.mdx
index 442c957bb..a1805c5f6 100644
--- a/docs/src/pages/docs/agent/skills.mdx
+++ b/docs/src/pages/docs/agent/skills.mdx
@@ -27,6 +27,9 @@ The folder form is what new and imported skills are written as, and it lets a sk
scripts or templates next to its instructions. The format matches the wider SKILL.md ecosystem, so
skills written elsewhere generally work here.
+The model sees skills rebuilt from disk on every run. To refresh the `/` popup after adding, editing,
+or deleting one mid-session, run `/reload skills`; it reports what was added, removed, or changed.
+
## Writing one
A skill is markdown with a name and a description:
diff --git a/src-tauri/src/core/cli/mod.rs b/src-tauri/src/core/cli/mod.rs
index 2e3037cfd..ddd626ca2 100644
--- a/src-tauri/src/core/cli/mod.rs
+++ b/src-tauri/src/core/cli/mod.rs
@@ -767,7 +767,7 @@ use tokio::sync::{mpsc, Mutex};
/// Advisory, not a bound: crossing it compacts the history and records a note,
/// then the run carries on (see `body_session_budget`). `--max-turns` and
/// cancellation are what actually stop a runaway loop.
-pub(crate) const DEFAULT_MAX_SESSION_TOKENS: u64 = 128_000;
+const DEFAULT_MAX_SESSION_TOKENS: u64 = 128_000;
/// Where the session token ceiling in effect came from, so `agent status` can
/// say which source won.
@@ -790,10 +790,26 @@ fn session_budget_source(flag: Option<u64>, configured: Option<u64>) -> &'static
/// `DEFAULT_MAX_SESSION_TOKENS` - the same flag/config/default shape the
/// sandbox setting resolves with. `0` from either source means unbounded and is
/// carried through as-is (see `body_session_budget`).
-fn resolve_session_budget(flag: Option<u64>, configured: Option<u64>) -> u64 {
+pub(crate) fn resolve_session_budget(flag: Option<u64>, configured: Option<u64>) -> u64 {
flag.or(configured).unwrap_or(DEFAULT_MAX_SESSION_TOKENS)
}
+/// The compaction ratio for `model`. A provider that names its own ratio wins
+/// over the project's: context windows differ by an order of magnitude across
+/// providers, so one ratio cannot be right for all of them. Resolved through
+/// the same selection the upstream resolution makes, so the ratio always
+/// describes the route that will actually serve this request.
+pub(crate) fn resolve_compaction_ratio(
+ model: &str,
+ provider_configs: &HashMap<String, crate::core::state::ProviderConfig>,
+ configured: Option<f64>,
+) -> f64 {
+ crate::core::agent::upstream::pick_provider_for_model(model, provider_configs)
+ .and_then(|name| provider_configs.get(&name)?.compaction_ratio)
+ .or(configured)
+ .unwrap_or(crate::core::agent::compaction::DEFAULT_COMPACTION_RATIO)
+}
+
/// The money ceiling for a run, priced against the model actually being billed.
///
/// Precedence matches the token budget: `--max-budget-usd`, then
@@ -1663,16 +1679,8 @@ fn prepare_agent_session(
.as_ref()
.map(|w| w.path.clone())
.unwrap_or_else(|| project_root.clone());
- // A provider that names its own ratio wins over the project's: context
- // windows differ by an order of magnitude across providers, so one ratio
- // cannot be right for all of them. Resolved through the same selection the
- // upstream resolution makes, so the ratio always describes the route that
- // will actually serve this request.
let compaction_ratio =
- crate::core::agent::upstream::pick_provider_for_model(&model, &provider_configs)
- .and_then(|name| provider_configs.get(&name)?.compaction_ratio)
- .or(cfg.agent.compaction_ratio)
- .unwrap_or(crate::core::agent::compaction::DEFAULT_COMPACTION_RATIO);
+ resolve_compaction_ratio(&model, &provider_configs, cfg.agent.compaction_ratio);
let mut args = build_cli_orchestration_args(
tool_root,
diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rs
index 9b677f1a1..56759bedb 100644
--- a/src-tauri/src/core/cli/tui.rs
+++ b/src-tauri/src/core/cli/tui.rs
@@ -14523,23 +14523,26 @@ fn reload_skill_entries(skills: &[crate::core::agent::skills::SkillMeta]) -> Vec
.collect()
}
+/// Display lines for what a reload changed, one list per kind of change.
+#[derive(Default)]
+struct ReloadDiff {
+ added: Vec<String>,
+ removed: Vec<String>,
+ updated: Vec<String>,
+}
+
/// 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 diff_reload_entries(before: &[ReloadEntry], after: &[ReloadEntry]) -> ReloadDiff {
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();
+ let mut diff = ReloadDiff::default();
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!(
+ None => diff.added.push(entry.label.clone()),
+ Some(prev) if prev.state != entry.state => diff.updated.push(format!(
"{} ({} → {})",
entry.label, prev.state, entry.state
)),
@@ -14548,10 +14551,10 @@ fn diff_reload_entries(
}
for (key, entry) in &old {
if !new.contains_key(key) {
- removed.push(entry.label.clone());
+ diff.removed.push(entry.label.clone());
}
}
- (added, removed, updated)
+ diff
}
/// `/reload [config|plugin|skills|system-prompt]`: re-read on-disk state into
@@ -14564,15 +14567,14 @@ fn diff_reload_entries(
/// reports what the next run picks up. Bare `/reload` does all of them.
fn reload_command(app: &mut App, arg: &str) {
match arg.trim() {
- "" | "all" => {
+ "" => {
reload_config(app);
- reload_plugins(app);
- reload_skills(app);
+ reload_catalog(app, true, true);
reload_system_prompt(app);
}
- "config" | "settings" => reload_config(app),
- "plugin" | "plugins" => reload_plugins(app),
- "skill" | "skills" => reload_skills(app),
+ "config" => reload_config(app),
+ "plugin" => reload_catalog(app, true, false),
+ "skills" => reload_catalog(app, false, true),
"system-prompt" => reload_system_prompt(app),
other => app.note(&format!(
"unknown /reload target '{other}' (try config | plugin | skills | system-prompt)"
@@ -14580,20 +14582,23 @@ fn reload_command(app: &mut App, arg: &str) {
}
}
-fn reload_plugins(app: &mut App) {
- 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));
-}
-
-fn reload_skills(app: &mut App) {
- let before = reload_skill_entries(&app.slash_catalog.all_skills);
+/// Re-run discovery once and report the plugin and/or skill diff. Both
+/// snapshots are taken before the single refresh: one refresh rescans both
+/// catalogs, so diffing skills after a plugin refresh would always come up empty.
+fn reload_catalog(app: &mut App, plugins: bool, skills: bool) {
+ let plugins_before = reload_plugin_entries(&app.slash_catalog.plugins);
+ let skills_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));
+ if plugins {
+ let after = reload_plugin_entries(&app.slash_catalog.plugins);
+ app.note("◈ reload · plugin · re-scanned installed plugins");
+ report_reload_diff(app, diff_reload_entries(&plugins_before, &after));
+ }
+ if skills {
+ 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(&skills_before, &after));
+ }
}
fn reload_system_prompt(app: &mut App) {
@@ -14631,23 +14636,34 @@ fn reload_config(app: &mut App) {
}
};
let before = reload_config_entries(app);
+ let budget_before = app.max_session_tokens;
app.configured_context_window = cfg.agent.context_window;
- let provider_ratio = app.args.as_ref().and_then(|args| {
- let pc = args.provider_configs.try_lock().ok()?;
- crate::core::agent::upstream::pick_provider_for_model(&app.model, &pc)
- .and_then(|name| pc.get(&name)?.compaction_ratio)
- });
- app.compaction_ratio = provider_ratio
- .or(cfg.agent.compaction_ratio)
- .unwrap_or(crate::core::agent::compaction::DEFAULT_COMPACTION_RATIO);
+ // Provider configs sit behind the engine's lock. If a run holds it right
+ // now, keep the current ratio rather than resolve without the provider's
+ // own override and silently pick the wrong one.
+ let configured_ratio = cfg.agent.compaction_ratio;
+ let ratio = match app.args.as_ref().map(|a| a.provider_configs.try_lock()) {
+ Some(Ok(pc)) => Some(super::resolve_compaction_ratio(
+ &app.model,
+ &pc,
+ configured_ratio,
+ )),
+ Some(Err(_)) => None,
+ None => Some(super::resolve_compaction_ratio(
+ &app.model,
+ &HashMap::new(),
+ configured_ratio,
+ )),
+ };
+ let ratio_busy = ratio.is_none();
+ if let Some(ratio) = ratio {
+ app.compaction_ratio = ratio;
+ }
app.compaction_reserve_tokens = cfg.agent.compaction_reserve_tokens;
app.max_tokens = cfg.agent.max_tokens;
if !app.max_session_tokens_pinned {
- app.max_session_tokens = cfg
- .budget
- .max_tokens
- .unwrap_or(super::DEFAULT_MAX_SESSION_TOKENS);
+ app.max_session_tokens = super::resolve_session_budget(None, cfg.budget.max_tokens);
}
app.send_reasoning = cfg.agent.send_reasoning.unwrap_or(true);
// Re-resolves the window and pushes the compaction budget to the engine.
@@ -14659,9 +14675,23 @@ fn reload_config(app: &mut App) {
crate::core::agent::project::agent_toml_path(&app.project_root).display()
));
report_reload_diff(app, diff_reload_entries(&before, &after));
- if app.max_session_tokens_pinned {
+ if app.max_session_tokens_pinned
+ && super::resolve_session_budget(None, cfg.budget.max_tokens) != budget_before
+ {
app.system_detail_text(" budget.max_tokens ignored: --max-session-tokens was passed");
}
+ if !ratio_busy
+ && cfg.agent.compaction_ratio.is_some_and(|r| r != app.compaction_ratio)
+ {
+ app.system_detail_text(
+ " compaction_ratio from agent.toml ignored: the serving provider sets its own",
+ );
+ }
+ if ratio_busy {
+ app.system_detail_text(
+ " compaction_ratio kept: provider settings are busy; /reload config again when idle",
+ );
+ }
if app.should_auto_compact() {
app.compact_request = Some(CompactKind::Auto);
app.system_detail_text(" context now over the compaction trigger; compacting");
@@ -14693,10 +14723,12 @@ fn reload_config_entries(app: &App) -> Vec<ReloadEntry> {
}
/// 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>),
-) {
+fn report_reload_diff(app: &mut App, diff: ReloadDiff) {
+ let ReloadDiff {
+ added,
+ removed,
+ updated,
+ } = diff;
if added.is_empty() && removed.is_empty() && updated.is_empty() {
app.system_detail_text(" no changes since the last scan");
return;
@@ -37113,9 +37145,9 @@ mod tests {
}
#[tokio::test]
- async fn reload_bare_defaults_to_plugin_and_reports_changes() {
+ async fn reload_plugin_reports_installed_plugins() {
let (mut app, root) = skill_test_app("deploy", "How to deploy.");
- // Bare /reload covers plugins; nothing installed, nothing changed.
+ // Nothing installed, nothing changed.
run_command(&mut app, "reload plugin", &no_mcp()).await;
let out = transcript_text(&app);
assert!(
@@ -37131,7 +37163,7 @@ mod tests {
// 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;
+ run_command(&mut app, "reload plugin", &no_mcp()).await;
let out = transcript_text(&app);
assert!(out.contains("+ plugin acme (v1.0.0)"), "diff: {out}");
assert!(
@@ -37231,6 +37263,22 @@ mod tests {
] {
assert!(out.contains(want), "missing {want}: {out}");
}
+
+ // One bare reload reports both a new plugin and a new skill: the
+ // plugin refresh must not swallow the skill diff.
+ plugin_command_in_app(&root, "acme", "ship", "---\ndescription: Ship it\n---\nGo");
+ plugin_manifest_in_app(&root, "acme", "1.0.0");
+ let skills = crate::core::agent::project::store_root(&root).join("skills");
+ 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", &no_mcp()).await;
+ let out = transcript_text(&app);
+ assert!(out.contains("+ plugin acme (v1.0.0)"), "plugin diff: {out}");
+ assert!(out.contains("+ audit"), "skill diff: {out}");
let _ = std::fs::remove_dir_all(&root);
}
@@ -37319,6 +37367,21 @@ mod tests {
let _ = std::fs::remove_dir_all(&root);
}
+ #[tokio::test]
+ async fn model_switch_hands_the_new_window_to_the_engine() {
+ let (mut app, root) = skill_test_app("deploy", "How to deploy.");
+ app.args = Some(test_args(&app, std::collections::HashMap::new()));
+ app.configured_context_window = Some(64_000);
+ app.set_model("anthropic/claude-opus-5".to_string());
+ let budget = app.args.as_ref().and_then(|a| a.compaction);
+ assert_eq!(
+ budget.map(|b| b.context_window),
+ Some(app.context_window),
+ "the engine compacts against the window the header shows"
+ );
+ let _ = std::fs::remove_dir_all(&root);
+ }
+
#[test]
fn slash_commands_include_reload() {
assert!(SLASH_COMMANDS.iter().any(|c| c.name == "/reload"));