A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
feat(plugins): ask before a new plugin runs
RoversX54a365297e44
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftlindex 0e0e7da3..0910440e 100644--- a/thinkterm-i18n/i18n/de-DE.ftl+++ b/thinkterm-i18n/i18n/de-DE.ftl@@ -797,6 +797,8 @@ settings-plugins-builtin = Integriertsettings-plugins-builtin-panel = Integriert · Stellt das Panel „{ $panel }“ in der rechten Seitenleiste bereitsettings-plugins-starting = Wird gestartet …settings-plugins-running = Läuft+settings-plugins-new = Neu: läuft erst, wenn du es erlaubst+settings-plugins-allow = Erlaubensettings-plugins-crashed = Angehalten: { $reason }settings-plugins-failed = Fehlgeschlagen: { $reason }settings-plugins-invalid = Nicht verwendbar: { $reason }diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftlindex 9f6608d4..30f9345d 100644--- a/thinkterm-i18n/i18n/en-US.ftl+++ b/thinkterm-i18n/i18n/en-US.ftl@@ -797,6 +797,8 @@ settings-plugins-builtin = Built insettings-plugins-builtin-panel = Built in · Provides the { $panel } panel in the right sidebarsettings-plugins-starting = Starting…settings-plugins-running = Running+settings-plugins-new = New: it does not run until you allow it+settings-plugins-allow = Allowsettings-plugins-crashed = Stopped: { $reason }settings-plugins-failed = Failed: { $reason }settings-plugins-invalid = Can't be used: { $reason }diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftlindex 6b05c24b..ac05e4e8 100644--- a/thinkterm-i18n/i18n/fr-FR.ftl+++ b/thinkterm-i18n/i18n/fr-FR.ftl@@ -794,6 +794,8 @@ settings-plugins-builtin = Intégréesettings-plugins-builtin-panel = Intégré · Fournit le panneau « { $panel } » de la barre latérale droitesettings-plugins-starting = Démarrage…settings-plugins-running = En cours d'exécution+settings-plugins-new = Nouveau : ne s'exécute pas avant que vous l'autorisiez+settings-plugins-allow = Autorisersettings-plugins-crashed = Arrêtée : { $reason }settings-plugins-failed = En échec : { $reason }settings-plugins-invalid = Inutilisable : { $reason }diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftlindex e36eddba..b7212586 100644--- a/thinkterm-i18n/i18n/ja-JP.ftl+++ b/thinkterm-i18n/i18n/ja-JP.ftl@@ -782,6 +782,8 @@ settings-plugins-builtin = 内蔵settings-plugins-builtin-panel = 内蔵 · 右サイドバーの「{ $panel }」パネルを提供しますsettings-plugins-starting = 起動中…settings-plugins-running = 実行中+settings-plugins-new = 新しいプラグイン:許可するまで実行されません+settings-plugins-allow = 許可settings-plugins-crashed = 停止しました:{ $reason }settings-plugins-failed = 失敗しました:{ $reason }settings-plugins-invalid = 使用できません:{ $reason }diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftlindex 6db64d30..b7b5a925 100644--- a/thinkterm-i18n/i18n/zh-CN.ftl+++ b/thinkterm-i18n/i18n/zh-CN.ftl@@ -782,6 +782,8 @@ settings-plugins-builtin = 内置settings-plugins-builtin-panel = 内置 · 提供右侧栏的「{ $panel }」面板settings-plugins-starting = 正在启动…settings-plugins-running = 运行中+settings-plugins-new = 新插件:允许之前不会运行+settings-plugins-allow = 允许settings-plugins-crashed = 已停止:{ $reason }settings-plugins-failed = 出错:{ $reason }settings-plugins-invalid = 无法使用:{ $reason }diff --git a/thinkterm-plugin-channel/src/registry.rs b/thinkterm-plugin-channel/src/registry.rsindex 22c889e2..f5d1b4e1 100644--- a/thinkterm-plugin-channel/src/registry.rs+++ b/thinkterm-plugin-channel/src/registry.rs@@ -54,8 +54,8 @@ pub enum Request {#[serde(default)]locale: String,},- /// Turn a plugin on or off. Answered with `null`; the change is- /// announced.+ /// Turn a plugin on or off. On lets a new one run, from where it is+ /// installed. Answered with `null`; the change is announced.SetEnabled { id: String, enabled: bool },/// Choose how long a plugin runs unused; `None` goes back to what its/// manifest says. Answered with `null`; the change is announced.@@ -91,9 +91,14 @@ pub struct Info {pub version: String,#[serde(default)]pub builtin: bool,- /// Where an installed plugin lives.+ /// Where an installed plugin lives: its own directory in the plugins+ /// directory.#[serde(default)]pub dir: Option<String>,+ /// Where `dir` leads, links followed, when that is elsewhere: what the+ /// user lets run.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub target: Option<String>,pub enabled: bool,pub state: State,/// The panel it adds to the right sidebar, if it adds one.@@ -130,6 +135,9 @@ impl Info {#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]#[serde(tag = "kind", rename_all = "snake_case")]pub enum State {+ /// Installed, and never let run from where it is: nothing starts it+ /// until the user turns it on, which lets it.+ New,/// Turned off.Off,/// On, and not running: started when something uses it.@@ -162,7 +170,11 @@ impl State {pub fn usable(&self) -> bool {!matches!(self,- Self::Off | Self::Failed { .. } | Self::Invalid { .. } | Self::Unsupported { .. }+ Self::New+ | Self::Off+ | Self::Failed { .. }+ | Self::Invalid { .. }+ | Self::Unsupported { .. })}@@ -173,7 +185,7 @@ impl State {| Self::Failed { reason }| Self::Invalid { reason }| Self::Unsupported { reason } => Some(reason),- Self::Off | Self::Idle | Self::Starting | Self::Running => None,+ Self::New | Self::Off | Self::Idle | Self::Starting | Self::Running => None,}}}@@ -249,6 +261,7 @@ mod tests {version: String::new(),builtin: false,dir: None,+ target: None,enabled: true,state: State::Idle,panel: None,@@ -261,5 +274,8 @@ mod tests {};assert!(!info.usable());assert_eq!(info.state.reason(), Some("no"));+ info.state = State::New;+ assert!(!info.usable(), "not until it is let run");+ assert_eq!(to_value(State::New).unwrap(), json!({"kind": "new"}));}}diff --git a/thinkterm-plugin-channel/src/wire.rs b/thinkterm-plugin-channel/src/wire.rsindex 2c9446bd..a6281b97 100644--- a/thinkterm-plugin-channel/src/wire.rs+++ b/thinkterm-plugin-channel/src/wire.rs@@ -12,8 +12,9 @@ use std::io::{self, Read, Write};/// one that finds a newer host leaves it alone. 2 added the host's own API/// (`registry`) and installed plugins; 3 took commands and notifications/// out of it; 4 added plugins' panels; 5 what a panel's plugin asks of-/// another machine, and how long plugins run unused.-pub const PROTOCOL: u32 = 5;+/// another machine, and how long plugins run unused; 6 plugins that wait+/// for the user to let them run.+pub const PROTOCOL: u32 = 6;/// The largest frame either side sends or accepts, so a confused peer/// cannot have the other allocate without bound. A thousand scripts ofdiff --git a/thinkterm-plugin-server/src/registry.rs b/thinkterm-plugin-server/src/registry.rsindex 07bd0c87..cedb8860 100644--- a/thinkterm-plugin-server/src/registry.rs+++ b/thinkterm-plugin-server/src/registry.rs@@ -4,7 +4,9 @@//!//! The directory is looked at again whenever the list is asked for, and a//! plugin's manifest and program whenever it is used, so installing,-//! removing, editing and rebuilding a plugin need no restart. A plugin's+//! removing, editing and rebuilding a plugin need no restart. Nothing of+//! an installed plugin runs until the user lets it, from where it is+//! (`switches`): before that it is new, and nothing starts it. A plugin's//! program starts when a client uses the plugin -- or, for one that runs//! always, while ThinkTerm keeps the host -- and stops once it has gone//! unused for as long as the plugin may run so ([`Background`]). No program@@ -82,6 +84,9 @@ struct Queued {/// What starting an installed plugin's program takes, once it may start.struct Launch {id: String,+ /// Where it was let run from, links followed, as just looked at: what+ /// runs, and where, so that a link turned since starts nothing new.+ dir: PathBuf,program: Result<(PathBuf, Vec<String>), String>,program_stamp: Option<Stamp>,}@@ -90,6 +95,9 @@ struct Installed {dir: PathBuf,/// What a plugin whose manifest does not read is known by.dir_name: String,+ /// Where `dir` really is, links followed: what the user lets it run+ /// from.+ real_dir: String,manifest: Result<Manifest, String>,manifest_stamp: Option<Stamp>,/// Why it is not used although its manifest reads: another plugin has@@ -124,6 +132,7 @@ enum Run {impl Installed {fn new(dir_name: String, dir: PathBuf) -> Self {let mut installed = Self {+ real_dir: real_dir(&dir),dir,dir_name,manifest: Err(String::new()),@@ -160,6 +169,17 @@ impl Installed {self.shadowed.is_none() && self.id() == Some(id)}+ /// Whether the user let it run from where it is.+ fn allowed(&self, switches: &Switches) -> bool {+ self.id()+ .is_some_and(|id| switches.allowed(id, &self.real_dir))+ }++ /// Whether it may run: let, and turned on.+ fn runs(&self, switches: &Switches) -> bool {+ self.allowed(switches) && self.id().is_some_and(|id| switches.enabled(id))+ }+/// Stops its program, if it runs, handing its unanswered calls to/// `fallout` with `why`. The program is exiting until it is gone.fn stop(&mut self, why: &str, fallout: &mut Fallout) {@@ -275,7 +295,10 @@ impl Registry {.iter().position(|installed| installed.dir_name == name){- Some(index) => self.refresh_manifest(index, fallout),+ Some(index) => {+ self.follow_real_dir(index, fallout);+ self.refresh_manifest(index, fallout);+ }None => {log::info!("found plugin {}", dir.display());self.installed.push(Installed::new(name, dir));@@ -287,6 +310,53 @@ impl Registry {}self.installed.sort_by(|a, b| a.dir_name.cmp(&b.dir_name));self.resolve_ids(fallout);+ self.hold_new(fallout);+ }++ /// Notices that a plugin's directory is somewhere else now -- a link+ /// pointed elsewhere: it was let run from where it was, not from here,+ /// and is stopped.+ fn follow_real_dir(&mut self, index: usize, fallout: &mut Fallout) {+ let installed = &mut self.installed[index];+ let now = real_dir(&installed.dir);+ if now == installed.real_dir {+ return;+ }+ installed.real_dir = now;+ installed.reset("it is somewhere else now", fallout);+ fallout.changed = true;+ }++ /// Writes the plugins not let run from where they are -- new ones, and+ /// ones somewhere else now -- in as off, so that a build that does not+ /// know to wait leaves them off too; and those held so that are back+ /// where they were let run from in as on again. What another host+ /// changed in the switches is taken in first.+ fn hold_new(&mut self, fallout: &mut Fallout) {+ self.follow_switches(fallout);+ let mut waiting = Vec::new();+ let mut back = Vec::new();+ for installed in self+ .installed+ .iter()+ .filter(|installed| installed.shadowed.is_none())+ {+ let Some(id) = installed.id() else {+ continue;+ };+ if !installed.allowed(&self.switches) {+ if self.switches.enabled(id) {+ waiting.push(id.to_string());+ }+ } else if self.switches.held(id) {+ back.push(id.to_string());+ }+ }+ match self.switches.hold(&waiting, &back) {+ Ok(true) => fallout.changed = true,+ Ok(false) => {}+ Err(err) => log::warn!("cannot keep new plugins off for other builds: {err:#}"),+ }}/// The plugin directories, by name: not hidden, at most [`DIR_LIMIT`].@@ -298,8 +368,7 @@ impl Registry {}fallout.changed = true;for installed in &mut self.installed {- let off = installed.id().is_some_and(|id| !self.switches.enabled(id));- if off {+ if installed.id().is_some() && !installed.runs(&self.switches) {installed.reset("it was turned off", fallout);}}@@ -402,6 +471,7 @@ impl Registry {version: String::new(),builtin: true,dir: None,+ target: None,enabled,state: if enabled { State::Idle } else { State::Off },panel: None,@@ -419,7 +489,11 @@ impl Registry {}fn installed_info(&self, installed: &Installed, locale: &str) -> Info {- let dir = Some(installed.dir.display().to_string());+ let dir = installed.dir.display().to_string();+ // Where it really is, when a link leads elsewhere: what the user+ // lets run.+ let target = linked(&installed.dir).then(|| shown(&installed.real_dir));+ let dir = Some(dir);let manifest = match &installed.manifest {Ok(manifest) => manifest,Err(reason) => {@@ -430,6 +504,7 @@ impl Registry {version: String::new(),builtin: false,dir,+ target,enabled: self.switches.enabled(&installed.dir_name),state: State::Invalid {reason: reason.clone(),@@ -440,7 +515,8 @@ impl Registry {}}};- let enabled = self.switches.enabled(&manifest.id);+ let allowed = installed.allowed(&self.switches);+ let enabled = installed.runs(&self.switches);let state = if let Some(reason) = &installed.shadowed {State::Invalid {reason: reason.clone(),@@ -453,6 +529,8 @@ impl Registry {std::env::consts::OS),}+ } else if !allowed {+ State::New} else if !enabled {State::Off} else {@@ -477,6 +555,7 @@ impl Registry {version: manifest.version.clone(),builtin: false,dir,+ target,enabled,state,panel: manifest.panel.clone(),@@ -544,10 +623,18 @@ impl Registry {// The file is written over what it says now, so what another host// changed in it is acted on first, not just carried along.self.follow_switches(fallout);- let moved = self- .switches- .set(id, enabled)- .map_err(|err| format!("cannot save the switch: {err:#}"))?;+ // Turned on, an installed plugin is let run from where it is now.+ let lets = self+ .installed+ .iter()+ .find(|installed| installed.answers_to(id))+ .map(|installed| installed.real_dir.clone())+ .filter(|_| enabled);+ let moved = match &lets {+ Some(dir) => self.switches.allow(id, dir),+ None => self.switches.set(id, enabled),+ }+ .map_err(|err| format!("cannot save the switch: {err:#}"))?;if !moved {return Ok(());}@@ -593,6 +680,15 @@ impl Registry {return Err(why);}self.follow_switches(fallout);+ // How long it runs is asked of one that runs: a new one is let run+ // first, by turning it on.+ let allowed = self+ .installed+ .iter()+ .any(|installed| installed.answers_to(id) && installed.allowed(&self.switches));+ if !allowed {+ return Err(format!("{id:?} is new: turn it on first, to let it run"));+ }let moved = self.switches.set_background(id, background)@@ -648,12 +744,12 @@ impl Registry {};let id = manifest.id.clone();let background = self.background(manifest);- // One that cannot run -- turned off, or not for this system --- // is not tried each time.+ // One that cannot run -- new, turned off, or not for this+ // system -- is not tried each time.let always = kept&& background == Background::Always&& manifest.supported()- && self.switches.enabled(&id);+ && installed.runs(&self.switches);let in_use = |installed: &Installed| match &installed.run {Run::Running(process) => {always || process.busy() || !installed.queued.is_empty() || used(&id)@@ -694,12 +790,9 @@ impl Registry {// Started once it is gone: word of that runs this again.continue;}- let Ok(launch) = self.launchable(index, fallout) else {+ let Ok(launch) = self.launchable(index, Some(&id), fallout) else {continue;};- if launch.id != id {- continue;- }log::info!("starting plugin {id}: it runs always");if let Err(why) = self.start(index, launch, listener, fallout) {log::warn!("plugin {id} runs always, and cannot start: {why}");@@ -721,11 +814,10 @@ impl Registry {.iter().filter(|installed| installed.shadowed.is_none()).filter(|installed| !matches!(installed.run, Run::Failed { .. }))+ .filter(|installed| installed.runs(&self.switches)).filter_map(|installed| installed.manifest.as_ref().ok()).filter(|manifest| {- manifest.supported()- && self.switches.enabled(&manifest.id)- && self.background(manifest) == Background::Always+ manifest.supported() && self.background(manifest) == Background::Always}).map(|manifest| manifest.id.clone()).collect();@@ -794,12 +886,7 @@ impl Registry {listener: &Arc<dyn Listener>,fallout: &mut Fallout,) -> Result<(), String> {- let launch = self.launchable(index, fallout)?;- // Its manifest, read again, may name another id now: the call is- // not for that plugin.- if launch.id != id {- return Err(format!("there is no plugin named {id:?}"));- }+ let launch = self.launchable(index, Some(id), fallout)?;let installed = &mut self.installed[index];if let Run::Running(process) = &installed.run {if stamp(&process.program) != process.program_stamp {@@ -842,10 +929,9 @@ impl Registry {reason,again: false,};- let launch = self.launchable(index, fallout).map_err(for_good)?;- if launch.id != id {- return Err(for_good(format!("there is no plugin named {id:?}")));- }+ let launch = self+ .launchable(index, Some(id), fallout)+ .map_err(for_good)?;let installed = &mut self.installed[index];let Ok(manifest) = &installed.manifest else {return Err(for_good(format!("there is no plugin named {id:?}")));@@ -958,7 +1044,7 @@ impl Registry {}// A manifest read again here answers the calls it no longer// takes: the plugin is reset.- let launch = match self.launchable(index, fallout) {+ let launch = match self.launchable(index, None, fallout) {Ok(launch) => launch,Err(why) => {let calls = std::mem::take(&mut self.installed[index].queued);@@ -976,23 +1062,51 @@ impl Registry {}}- /// Whether the installed plugin at `index` may run now, reading its- /// manifest again if it changed, and what starting it takes.- fn launchable(&mut self, index: usize, fallout: &mut Fallout) -> Result<Launch, String> {+ /// Whether the installed plugin at `index` may run now -- as `id`, when+ /// it is for that -- reading its manifest again if it changed, and what+ /// starting it takes.+ fn launchable(+ &mut self,+ index: usize,+ id: Option<&str>,+ fallout: &mut Fallout,+ ) -> Result<Launch, String> {+ // The switches as they are now: another host may have turned it+ // off, or on, since they were last read.+ self.follow_switches(fallout);self.refresh_manifest(index, fallout);let installed = &self.installed[index];let manifest = installed.manifest.as_ref().map_err(Clone::clone)?;+ // Its manifest, read again, may name another id now: what was meant+ // for the old one is not for that plugin.+ if let Some(id) = id.filter(|id| *id != manifest.id) {+ return Err(format!("there is no plugin named {id:?}"));+ }if let Some(reason) = &installed.shadowed {return Err(reason.clone());}if !manifest.supported() {return Err(format!("{} does not run on this system", manifest.name));}+ // Looked at again here, where it is about to run: a link pointed+ // elsewhere since the last look is not where it was let run from.+ self.follow_real_dir(index, fallout);+ let installed = &self.installed[index];+ let Ok(manifest) = installed.manifest.as_ref() else {+ unreachable!("read above");+ };+ if !installed.allowed(&self.switches) {+ return Err(format!(+ "{} is new: it runs once you turn it on",+ manifest.name+ ));+ }if !self.switches.enabled(&manifest.id) {return Err(format!("{} is turned off", manifest.name));}let id = manifest.id.clone();- let program = manifest.program(&installed.dir);+ let dir = PathBuf::from(&installed.real_dir);+ let program = manifest.program(&dir);let program_stamp = program.as_ref().ok().and_then(|(path, _)| stamp(path));let installed = &mut self.installed[index];@@ -1012,6 +1126,7 @@ impl Registry {}Ok(Launch {id,+ dir,program,program_stamp,})@@ -1076,6 +1191,7 @@ impl Registry {) -> Result<(), String> {let Launch {id,+ dir,program,program_stamp,} = launch;@@ -1099,7 +1215,7 @@ impl Registry {generation: self.generation,program: &path,args: &args,- dir: &installed.dir,+ dir: &dir,data_dir: &data_dir,ready_within: self.ready_within,};@@ -1278,6 +1394,30 @@ impl Registry {}}+/// Where `dir` really is, links followed, as the switches keep it: itself,+/// when that cannot be found.+fn real_dir(dir: &Path) -> String {+ std::fs::canonicalize(dir)+ .unwrap_or_else(|_| dir.to_path_buf())+ .display()+ .to_string()+}++/// Whether plugin directory `dir` is a link to one elsewhere.+fn linked(dir: &Path) -> bool {+ std::fs::symlink_metadata(dir).is_ok_and(|meta| meta.file_type().is_symlink())+}++/// `path` as a person writes it: without the `\\?\` Windows puts before+/// a path it resolved.+fn shown(path: &str) -> String {+ match path.strip_prefix(r"\\?\") {+ Some(unc) if unc.starts_with("UNC\\") => format!(r"\\{}", &unc[4..]),+ Some(local) => local.to_string(),+ None => path.to_string(),+ }+}+/// Writes `text` to `path` whole, or not at all.fn write_whole(path: &Path, text: String) -> anyhow::Result<()> {use std::io::Write;@@ -1290,3 +1430,21 @@ fn write_whole(path: &Path, text: String) -> anyhow::Result<()> {file.persist(path)?;Ok(())}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn a_resolved_windows_path_is_shown_as_it_is_written() {+ assert_eq!(+ shown(r"\\?\C:\Users\user\plugins\foo"),+ r"C:\Users\user\plugins\foo"+ );+ assert_eq!(+ shown(r"\\?\UNC\server-a\share\foo"),+ r"\\server-a\share\foo"+ );+ assert_eq!(shown("/home/user/plugins/foo"), "/home/user/plugins/foo");+ }+}diff --git a/thinkterm-plugin-server/src/switches.rs b/thinkterm-plugin-server/src/switches.rsindex ac8d5017..eaeaab2a 100644--- a/thinkterm-plugin-server/src/switches.rs+++ b/thinkterm-plugin-server/src/switches.rs@@ -1,8 +1,15 @@-//! Which plugins are turned off, and how long the user lets each run-//! unused: `plugins.json` in the data directory. A plugin that is not in it-//! is on, and runs as its manifest says. A switch stays when its plugin is-//! removed, so a plugin installed again comes back as it was left. Builds-//! share the file: what one does not know is kept as another wrote it.+//! Which plugins the user let run, which are turned off, and how long the+//! user lets each run unused: `plugins.json` in the data directory. An+//! installed plugin runs only once the user let it, from the directory it+//! is in then: one that is not in the file, or is somewhere else now --+//! moved, or another under its id -- waits to be let, and is written in+//! as off, so that an older build sharing the file does not run it either;+//! never over a file that does not read, which only a switch the user+//! changes writes anew.+//! A built-in plugin is ThinkTerm's own: it is on unless turned off. A+//! switch stays when its plugin is removed, so a plugin installed again+//! where it was comes back as it was left. Builds share the file: what one+//! does not know is kept as another wrote it.use crate::stamp::{stamp, Stamp};use serde::{Deserialize, Serialize};@@ -27,6 +34,13 @@ struct Stored {struct Switch {#[serde(default = "on")]enabled: bool,+ /// The directory the user let the plugin run from, links followed.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ allowed: Option<String>,+ /// Turned off by ThinkTerm, not the user, while the plugin was not+ /// where it was let run from: on again once it is back there.+ #[serde(default, skip_serializing_if = "is_false")]+ held: bool,/// The user's choice, as written; none, the manifest's. One this build/// does not know counts as none, and is kept.#[serde(default, skip_serializing_if = "Option::is_none")]@@ -40,6 +54,8 @@ impl Default for Switch {fn default() -> Self {Self {enabled: true,+ allowed: None,+ held: false,background: None,rest: BTreeMap::new(),}@@ -50,11 +66,18 @@ fn on() -> bool {true}+fn is_false(value: &bool) -> bool {+ !*value+}+pub struct Switches {path: PathBuf,stored: Stored,/// The file as last read or written, to notice another host's change.seen: Option<Stamp>,+ /// The file is there and does not read: nothing writes over it but a+ /// switch the user changes.+ unreadable: bool,}impl Switches {@@ -63,22 +86,33 @@ impl Switches {path,stored: Stored::default(),seen: None,+ unreadable: false,};switches.read();switches}- /// Reads the file again. One that does not read leaves every plugin on- /// until a switch is changed, which writes it anew.+ /// Reads the file again. One that does not read lets no installed+ /// plugin run, and leaves the built-in ones on, until a switch is+ /// changed, which writes it anew.fn read(&mut self) {self.seen = stamp(&self.path);- self.stored = match std::fs::read(&self.path) {- Ok(bytes) => serde_json::from_slice(&bytes).unwrap_or_else(|err| {- log::warn!("{} does not read: {err}", self.path.display());- Stored::default()- }),- Err(_) => Stored::default(),+ let (stored, unreadable) = match std::fs::read(&self.path) {+ Ok(bytes) => match serde_json::from_slice(&bytes) {+ Ok(stored) => (stored, false),+ Err(err) => {+ log::warn!("{} does not read: {err}", self.path.display());+ (Stored::default(), true)+ }+ },+ Err(err) if err.kind() == std::io::ErrorKind::NotFound => (Stored::default(), false),+ Err(err) => {+ log::warn!("cannot read {}: {err}", self.path.display());+ (Stored::default(), true)+ }};+ self.stored = stored;+ self.unreadable = unreadable;}/// Picks up a change made by another host -- a debug build's, say.@@ -92,6 +126,9 @@ impl Switches {self.stored != before}+ /// Whether plugin `id`'s switch is on: a plugin not in the file is.+ /// An installed one runs only if it was let run too+ /// ([`allowed`](Self::allowed)).pub fn enabled(&self, id: &str) -> bool {self.stored.plugins@@ -99,6 +136,23 @@ impl Switches {.map_or(true, |switch| switch.enabled)}+ /// Whether the user let plugin `id` run from `dir`, where it is now.+ pub fn allowed(&self, id: &str, dir: &str) -> bool {+ self.stored+ .plugins+ .get(id)+ .and_then(|switch| switch.allowed.as_deref())+ == Some(dir)+ }++ /// Whether plugin `id` is off because ThinkTerm held it, not the user.+ pub fn held(&self, id: &str) -> bool {+ self.stored+ .plugins+ .get(id)+ .is_some_and(|switch| switch.held)+ }+/// How long the user lets plugin `id` run unused, if they chose.pub fn background(&self, id: &str) -> Option<Background> {let chosen = self.stored.plugins.get(id)?.background.as_ref()?;@@ -109,7 +163,55 @@ impl Switches {/// written over as last read: [`refresh`](Self::refresh) first, and act/// on what another host moved. False when it already was.pub fn set(&mut self, id: &str, enabled: bool) -> anyhow::Result<bool> {- self.change(id, |switch| switch.enabled = enabled)+ self.change(id, |switch| {+ switch.enabled = enabled;+ switch.held = false;+ })+ }++ /// Lets installed plugin `id` run from `dir`, and turns it on, as+ /// [`set`](Self::set) does.+ pub fn allow(&mut self, id: &str, dir: &str) -> anyhow::Result<bool> {+ self.change(id, |switch| {+ switch.enabled = true;+ switch.allowed = Some(dir.to_string());+ switch.held = false;+ })+ }++ /// Writes plugins `waiting` -- installed, and not let run from where+ /// they are -- in as off, keeping what else their entries say: they+ /// wait to be let run, in builds that know to wait and in older ones+ /// alike. Those held so that are `back` where they were let run from+ /// are on again. One write, and not over a file that does not read, nor+ /// over one another host wrote since it was last read here: the next+ /// look does it, once that is taken in. False when nothing was written.+ pub fn hold(&mut self, waiting: &[String], back: &[String]) -> anyhow::Result<bool> {+ if self.unreadable || stamp(&self.path) != self.seen {+ return Ok(false);+ }+ let mut next = self.stored.clone();+ let mut changed = false;+ for id in waiting {+ let switch = next.plugins.entry(id.clone()).or_default();+ if switch.enabled {+ switch.enabled = false;+ switch.held = true;+ changed = true;+ }+ }+ for id in back {+ if let Some(switch) = next.plugins.get_mut(id).filter(|switch| switch.held) {+ switch.enabled = true;+ switch.held = false;+ changed = true;+ }+ }+ if !changed {+ return Ok(false);+ }+ self.write(next)?;+ Ok(true)}/// Keeps the user's choice of how long plugin `id` runs unused, `None`@@ -137,6 +239,13 @@ impl Switches {if *switch == Switch::default() && !self.stored.plugins.contains_key(id) {return Ok(false);}+ self.write(next)?;+ self.unreadable = false;+ Ok(true)+ }++ /// Writes `next` over the file, whole, before it counts.+ fn write(&mut self, next: Stored) -> anyhow::Result<()> {let dir = self.path.parent()@@ -148,7 +257,7 @@ impl Switches {file.persist(&self.path)?;self.stored = next;self.seen = stamp(&self.path);- Ok(true)+ Ok(())}}@@ -240,6 +349,86 @@ mod tests {);}+ #[test]+ fn a_plugin_is_let_run_from_where_it_was_and_a_new_one_is_written_in_as_off() {+ let dir = tempfile::tempdir().unwrap();+ let path = dir.path().join(FILE);+ let mut switches = Switches::load(path.clone());+ assert!(!switches.allowed("a", "/home/user/plugins/a"));+ assert!(switches.hold(&["a".into(), "b".into()], &[]).unwrap());+ assert!(!switches.hold(&["a".into()], &[]).unwrap(), "said already");+ let held: Value = serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();+ assert_eq!(+ held,+ serde_json::json!({"plugins": {+ "a": {"enabled": false, "held": true},+ "b": {"enabled": false, "held": true},+ }}),+ "off, for a build that does not know to wait"+ );+ assert!(switches.allow("a", "/home/user/plugins/a").unwrap());+ assert!(switches.enabled("a"));+ assert!(switches.allowed("a", "/home/user/plugins/a"));+ assert!(+ !switches.allowed("a", "/home/user/elsewhere/a"),+ "moved, it waits again"+ );+ let read = Switches::load(path);+ assert!(read.allowed("a", "/home/user/plugins/a"));+ assert!(!read.allowed("b", "/home/user/plugins/b"));+ // Turned off, it stays let: on again needs no new say.+ let mut switches = read;+ assert!(switches.set("a", false).unwrap());+ assert!(switches.allowed("a", "/home/user/plugins/a"));+ // Let run from elsewhere, and on: held off, what else it says kept.+ assert!(switches.set("a", true).unwrap());+ assert!(switches.hold(&["a".into()], &[]).unwrap());+ assert!(!switches.enabled("a"));+ assert!(switches.allowed("a", "/home/user/plugins/a"));+ // Back where it was let run from: on again.+ assert!(switches.hold(&[], &["a".into()]).unwrap());+ assert!(switches.enabled("a") && !switches.held("a"));+ // One the user turned off stays off, back or not.+ assert!(switches.set("a", false).unwrap());+ assert!(!switches.hold(&[], &["a".into()]).unwrap());+ assert!(!switches.enabled("a"));+ assert!(switches.set("a", true).unwrap());+ assert!(switches.hold(&["a".into()], &[]).unwrap());+ assert!(switches.set("a", false).unwrap(), "the user's say");+ assert!(!switches.held("a"));+ assert!(!switches.hold(&[], &["a".into()]).unwrap());+ }++ #[test]+ fn nothing_is_held_over_a_file_that_does_not_read_or_another_host_just_wrote() {+ let dir = tempfile::tempdir().unwrap();+ let path = dir.path().join(FILE);+ std::fs::write(+ &path,+ r#"{"plugins": {"a": {"enabled": true, "allowed": "/x"},}"#,+ )+ .unwrap();+ let mut switches = Switches::load(path.clone());+ assert!(!switches.hold(&["a".into(), "b".into()], &[]).unwrap());+ assert_eq!(+ std::fs::read_to_string(&path).unwrap(),+ r#"{"plugins": {"a": {"enabled": true, "allowed": "/x"},}"#,+ "left as it is, for the user to mend"+ );++ std::fs::write(&path, r#"{"plugins": {}}"#).unwrap();+ let mut switches = Switches::load(path.clone());+ // Another host writes meanwhile: not written over.+ std::fs::write(+ &path,+ r#"{"plugins": {"b": {"enabled": true, "allowed": "/b"}}}"#,+ )+ .unwrap();+ assert!(!switches.hold(&["b".into()], &[]).unwrap());+ assert!(switches.refresh());+ assert!(switches.allowed("b", "/b"), "the other host's say stands");+ }+#[test]fn a_file_that_does_not_read_leaves_everything_on() {let dir = tempfile::tempdir().unwrap();diff --git a/thinkterm-plugin-server/tests/common/mod.rs b/thinkterm-plugin-server/tests/common/mod.rsindex 6ee0ef79..d2bbca53 100644--- a/thinkterm-plugin-server/tests/common/mod.rs+++ b/thinkterm-plugin-server/tests/common/mod.rs@@ -57,6 +57,24 @@ pub fn wait_until(what: &str, mut done: impl FnMut() -> bool) {}}+/// Lets installed plugin `id`, in `dir`, run, as turning it on does: in+/// the host's switches, which it reads again whenever they change.+pub fn allow(host: &Host, id: &str, dir: &Path) {+ let path = host.data_dir.join("plugins.json");+ let mut switches: serde_json::Value = std::fs::read(&path)+ .ok()+ .and_then(|bytes| serde_json::from_slice(&bytes).ok())+ .unwrap_or_else(|| serde_json::json!({"plugins": {}}));+ let real = std::fs::canonicalize(dir).unwrap().display().to_string();+ switches["plugins"][id] = serde_json::json!({"enabled": true, "allowed": real});+ std::fs::create_dir_all(&host.data_dir).unwrap();+ // Whole or not at all, as the host writes it: a host reading meanwhile+ // never finds half a file.+ let partial = host.data_dir.join("plugins.json.partial");+ std::fs::write(&partial, serde_json::to_vec_pretty(&switches).unwrap()).unwrap();+ std::fs::rename(&partial, &path).unwrap();+}+/// A session, and the notices it gives.pub fn session(host: &Host) -> (Session, mpsc::Receiver<Notice>) {let (tx, rx) = mpsc::channel();diff --git a/thinkterm-plugin-server/tests/panels.rs b/thinkterm-plugin-server/tests/panels.rsindex 17ef4a4e..63b61271 100644--- a/thinkterm-plugin-server/tests/panels.rs+++ b/thinkterm-plugin-server/tests/panels.rs@@ -7,7 +7,7 @@mod common;-use common::{host_in, next_notice, session, stop, wait_until};+use common::{allow, host_in, next_notice, session, stop, wait_until};use serde_json::{json, Value};use std::os::unix::fs::PermissionsExt;use std::path::PathBuf;@@ -70,6 +70,7 @@ fn install_panel(host: &Host) -> PathBuf {let program = dir.join("plugin.sh");std::fs::write(&program, PANEL).unwrap();std::fs::set_permissions(&program, std::fs::Permissions::from_mode(0o755)).unwrap();+ allow(host, "panel", &dir);dir}@@ -207,6 +208,31 @@ fn a_panel_is_listed_opened_drawn_and_closed() {stop(&host);}+#[test]+fn the_panel_of_a_plugin_never_let_run_does_not_start_it() {+ let dir = tempfile::tempdir().unwrap();+ let host = host_in(dir.path());+ let plugin = install_panel(&host);+ std::fs::remove_file(host.data_dir.join("plugins.json")).unwrap();+ let (session, notices) = session(&host);+ open(&session, 7);+ let PanelEvent::Closed { reason, again } = heard(¬ices, 7) else {+ panic!("not refused")+ };+ assert!(reason.contains("is new"), "{reason}");+ assert!(!again, "nothing comes of opening it again");+ assert!(+ !host.data_dir.join("plugin-data/panel").exists(),+ "its program never ran"+ );+ // Let run, it opens.+ allow(&host, "panel", &plugin);+ open(&session, 8);+ assert_eq!(drawn(heard(¬ices, 8)), "open");+ drop(session);+ stop(&host);+}+#[test]fn an_extended_view_knows_its_panel_and_closes_before_it() {let dir = tempfile::tempdir().unwrap();diff --git a/thinkterm-plugin-server/tests/plugins.rs b/thinkterm-plugin-server/tests/plugins.rsindex fee9306e..9c41213d 100644--- a/thinkterm-plugin-server/tests/plugins.rs+++ b/thinkterm-plugin-server/tests/plugins.rs@@ -4,7 +4,7 @@mod common;-use common::{host_in, next_notice, session, spawn, spawn_with_env, stop, wait_until, WAIT};+use common::{allow, host_in, next_notice, session, spawn, spawn_with_env, stop, wait_until, WAIT};use serde_json::{json, Value};use std::path::PathBuf;use std::sync::mpsc;@@ -56,15 +56,30 @@ fn set_enabled(session: &Session, id: &str, enabled: bool) -> Answer {)}-/// Installs a plugin: a directory `name` in the host's plugins directory,-/// holding `manifest`.+/// Installs a plugin, and lets it run, as the user turning it on does: a+/// directory `name` in the host's plugins directory, holding `manifest`.fn install(host: &Host, name: &str, manifest: &str) -> PathBuf {+ let dir = place(host, name, manifest);+ if let Some(id) = id_of(manifest) {+ allow(host, &id, &dir);+ }+ dir+}++/// Installs a plugin the user has not let run yet.+fn place(host: &Host, name: &str, manifest: &str) -> PathBuf {let dir = host.data_dir.join("plugins").join(name);std::fs::create_dir_all(&dir).unwrap();std::fs::write(dir.join("plugin.toml"), manifest).unwrap();dir}+/// The id a manifest gives, when it reads.+fn id_of(manifest: &str) -> Option<String> {+ let value: toml::Value = toml::from_str(manifest).ok()?;+ Some(value.get("id")?.as_str()?.to_string())+}+/// Snippets installed again under another id, as a program of its own:/// the host's own program serving it over standard input and output.fn snippets_copy(host: &Host) -> String {@@ -215,13 +230,15 @@ fn a_manifest_that_cannot_be_used_is_listed_with_why() {let copy = snippets_copy(&host);install(&host, "copy", ©);let broken = install(&host, "broken", "id = \n");- install(&host, "twin", ©);- install(+ // Not used whether let run or not: placed, as installed and never+ // turned on.+ place(&host, "twin", ©);+ place(&host,"clash",©.replace("\"snippets-copy\"", "\"snippets\""),);- install(&host, "future", ©.replace("api = 1", "api = 99"));+ place(&host, "future", ©.replace("api = 1", "api = 99"));std::fs::create_dir_all(host.data_dir.join("plugins/empty")).unwrap();let (session, _notices) = session(&host);@@ -270,6 +287,12 @@ fn a_manifest_that_cannot_be_used_is_listed_with_why() {copy.replace("snippets-copy", "mended"),).unwrap();+ assert_eq!(+ info(&session, "mended").state,+ State::New,+ "another plugin now, which waits to be let run"+ );+ set_enabled(&session, "mended", true).unwrap();assert_eq!(info(&session, "mended").state, State::Idle);drop(session);stop(&host);@@ -373,15 +396,122 @@ program = "plugin.sh"install_script_in(host, "shell", script)}- /// The same plugin, id "shell", installed in directory `name`.+ /// The same plugin, id "shell", installed in directory `name`, and let+ /// run.fn install_script_in(host: &Host, name: &str, script: &str) -> PathBuf {- let dir = install(host, name, MANIFEST);+ let program = place_script(host, name, script);+ allow(host, "shell", program.parent().unwrap());+ program+ }++ /// [`install_script_in`], never let run.+ fn place_script(host: &Host, name: &str, script: &str) -> PathBuf {+ let dir = place(host, name, MANIFEST);let program = dir.join("plugin.sh");std::fs::write(&program, script).unwrap();std::fs::set_permissions(&program, std::fs::Permissions::from_mode(0o755)).unwrap();program}+ #[test]+ fn a_new_plugin_runs_only_once_turned_on_and_only_from_where_it_was() {+ let dir = tempfile::tempdir().unwrap();+ let host = host_in(dir.path());+ let program = place_script(&host, "shell", WELL_BEHAVED);+ let (session, _notices) = session(&host);+ let shell = info(&session, "shell");+ assert_eq!((shell.state, shell.enabled), (State::New, false));+ let switches: Value =+ serde_json::from_slice(&std::fs::read(host.data_dir.join("plugins.json")).unwrap())+ .unwrap();+ assert_eq!(+ switches["plugins"]["shell"],+ json!({"enabled": false, "held": true}),+ "written in as off, for a build that does not know to wait"+ );+ let why = call(&session, "shell", json!({"op": "pid"})).unwrap_err();+ assert!(why.contains("is new"), "{why}");+ let why = set_background(&session, "shell", Some(api::Background::Always)).unwrap_err();+ assert!(why.contains("turn it on first"), "{why}");++ set_enabled(&session, "shell", true).unwrap();+ assert_eq!(info(&session, "shell").state, State::Idle);+ let first = pid(call(&session, "shell", json!({"op": "pid"})));++ // Its link pointed at another copy: it is stopped, and that one+ // waits to be let run, as a plugin of its own.+ let plugin = program.parent().unwrap();+ let elsewhere = dir.path().join("elsewhere");+ std::fs::rename(plugin, &elsewhere).unwrap();+ std::os::unix::fs::symlink(&elsewhere, plugin).unwrap();+ assert_eq!(info(&session, "shell").state, State::New);+ wait_until("the run let from where it was to stop", || !alive(first));+ let why = call(&session, "shell", json!({"op": "pid"})).unwrap_err();+ assert!(why.contains("is new"), "{why}");++ // Put back where it was let run from: on again, with no new say.+ std::fs::remove_file(plugin).unwrap();+ std::fs::rename(&elsewhere, plugin).unwrap();+ let back = info(&session, "shell");+ assert_eq!((back.state, back.enabled), (State::Idle, true), "on again");+ let second = pid(call(&session, "shell", json!({"op": "pid"})));+ assert_ne!(second, first);++ // Elsewhere again, and let run from there.+ std::fs::rename(plugin, &elsewhere).unwrap();+ std::os::unix::fs::symlink(&elsewhere, plugin).unwrap();+ assert_eq!(info(&session, "shell").state, State::New);+ wait_until("the second run to stop", || !alive(second));+ set_enabled(&session, "shell", true).unwrap();+ assert_ne!(pid(call(&session, "shell", json!({"op": "pid"}))), second);+ drop(session);+ stop(&host);+ }++ #[test]+ fn a_new_plugin_that_runs_always_waits_to_be_let_run_too() {+ let dir = tempfile::tempdir().unwrap();+ let host = host_in(dir.path());+ let program = place_script(&host, "shell", WELL_BEHAVED);+ let manifest = program.with_file_name("plugin.toml");+ let text = std::fs::read_to_string(&manifest).unwrap();+ std::fs::write(+ &manifest,+ text.replace(+ "program = \"plugin.sh\"",+ "program = \"plugin.sh\"\nbackground = \"always\"",+ ),+ )+ .unwrap();+ let mut child = spawn(&host, &[]);+ wait_until("the host to listen", || host.socket.exists());+ let mut keeper = host.connect().unwrap();+ keeper+ .send(&ToHost::Call {+ id: 1,+ plugin: api::PLUGIN.into(),+ body: json!({"op": "keep"}),+ })+ .unwrap();+ let (session, _notices) = session(&host);+ // Kept, and looked at: not started.+ std::thread::sleep(Duration::from_millis(500));+ assert_eq!(info(&session, "shell").state, State::New);+ let always = thinkterm_plugin_channel::paths::always_in(&host.data_dir);+ assert!(!always.exists(), "nothing to keep the host up for");++ set_enabled(&session, "shell", true).unwrap();+ wait_until("it to start by itself", || {+ info(&session, "shell").state == State::Running+ });+ assert_eq!(std::fs::read_to_string(&always).unwrap(), "shell\n");+ drop(session);+ keeper.shutdown();+ drop(keeper);+ stop(&host);+ wait_until("the host to quit", || child.try_wait().unwrap().is_some());+ }+fn pid(answer: Answer) -> u64 {answer.unwrap().as_u64().expect("a pid")}@@ -764,6 +894,10 @@ printf '%s' "$$" > "$THINKTERM_PLUGIN_DATA/state"// plugin's to answer.let why = call(&session, "shell", json!({"op": "pid"})).unwrap_err();assert!(why.contains("no plugin named"), "{why}");+ // Under another id it is another plugin, which waits to be let run.+ let why = call(&session, "renamed", json!({"op": "pid"})).unwrap_err();+ assert!(why.contains("is new"), "{why}");+ set_enabled(&session, "renamed", true).unwrap();// The old run is on its way out under the old id; the new id has// nothing to wait for.let second = pid(call(&session, "renamed", json!({"op": "pid"})));@@ -781,12 +915,12 @@ printf '%s' "$$" > "$THINKTERM_PLUGIN_DATA/state"let running = pid(call(&session, "shell", json!({"op": "pid"})));// Another host -- a debug build's -- turns it off in the file they- // share; then a switch is set here.- std::fs::write(- host.data_dir.join("plugins.json"),- r#"{"plugins":{"shell":{"enabled":false}}}"#,- )- .unwrap();+ // share, keeping where it was let run from; then a switch is set+ // here.+ let path = host.data_dir.join("plugins.json");+ let mut switches: Value = serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();+ switches["plugins"]["shell"]["enabled"] = json!(false);+ std::fs::write(&path, switches.to_string()).unwrap();set_enabled(&session, "snippets", false).unwrap();wait_until("the plugin turned off elsewhere to stop", || {!alive(running)diff --git a/thinkterm-web/src/plugin_list.rs b/thinkterm-web/src/plugin_list.rsindex 74e7e487..86158aef 100644--- a/thinkterm-web/src/plugin_list.rs+++ b/thinkterm-web/src/plugin_list.rs@@ -75,6 +75,9 @@ pub struct PluginRow {pub enabled: bool,/// Whether a switch could do anything for it.pub switchable: bool,+ /// Never let run: offered a button that lets it, which takes a press+ /// made for it, rather than a switch.+ pub new: bool,/// Built into ThinkTerm: its switch is its panel's, among the panels,/// not in the list.pub builtin: bool,@@ -140,6 +143,7 @@ fn detail(plugin: &Info) -> String {};let state = match &plugin.state {State::Off | State::Idle => None,+ State::New => Some(tr("settings-plugins-new")),State::Starting => Some(tr("settings-plugins-starting")),State::Running => Some(tr("settings-plugins-running")),State::Crashed { reason } => Some(with_reason("settings-plugins-crashed", reason)),@@ -147,7 +151,14 @@ fn detail(plugin: &Info) -> String {State::Invalid { reason } => Some(with_reason("settings-plugins-invalid", reason)),State::Unsupported { .. } => Some(tr("settings-plugins-unsupported")),};- [Some(origin), state, Some(plugin.description.clone())]+ // A new one says where it is, on the server's machine: that is what+ // allowing it lets run.+ let place = plugin+ .target+ .clone()+ .or_else(|| plugin.dir.clone())+ .filter(|_| plugin.state == State::New);+ [Some(origin), state, place, Some(plugin.description.clone())].into_iter().flatten().filter(|part| !part.is_empty())@@ -384,6 +395,8 @@ impl PluginsModel {detail: detail(plugin),enabled,switchable,+ new: plugin.state == State::New+ && !self.switching.iter().any(|(id, _)| *id == plugin.id),builtin: plugin.builtin,background: offered.then(|| background_name(background)),background_detail: if offered {diff --git a/thinkterm-web/src/views.rs b/thinkterm-web/src/views.rsindex e74218e5..47b0db3a 100644--- a/thinkterm-web/src/views.rs+++ b/thinkterm-web/src/views.rs@@ -181,6 +181,7 @@ pub const STRING_KEYS: &[&str] = &["settings-plugins-reload-description","settings-plugins-reload-button","settings-plugins-unusable",+ "settings-plugins-allow","settings-plugins-background-always","settings-plugins-background-briefly","settings-plugins-background-never",diff --git a/thinkterm-web/ui/src/SettingsPanel.svelte b/thinkterm-web/ui/src/SettingsPanel.svelteindex d758314a..aabb4d64 100644--- a/thinkterm-web/ui/src/SettingsPanel.svelte+++ b/thinkterm-web/ui/src/SettingsPanel.svelte@@ -419,6 +419,9 @@<div class="tx"><div class="lab">{row.name}</div><div class="desc">{row.detail}</div></div>{#if row.builtin}<!-- Its switch is its panel's, above. -->+ {:else if row.new}+ <!-- Never let run: a press made for it lets it, from where it is. -->+ <button class="pillbtn" type="button" data-plugin-allow={row.id} onclick={() => void handle.client?.plugin_set_enabled(row.id, true)}>{s('settings-plugins-allow')}</button>{:else if row.switchable}<div class="ctl">{#if row.background}diff --git a/thinkterm-web/ui/src/model.ts b/thinkterm-web/ui/src/model.tsindex 29fe9027..872af246 100644--- a/thinkterm-web/ui/src/model.ts+++ b/thinkterm-web/ui/src/model.ts@@ -242,6 +242,8 @@ export type PluginRow = {enabled: boolean;/** Whether a switch could do anything for it. */switchable: boolean;+ /** Never let run: a button lets it, rather than a switch. */+ new: boolean;/** Built into ThinkTerm: its switch is its panel's, not in the list. */builtin: boolean;/** How long an installed plugin that is on runs unused; none for others. */diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rsindex 2dcf796b..64010ccd 100644--- a/wezterm-gui/src/settings_window.rs+++ b/wezterm-gui/src/settings_window.rs@@ -1323,6 +1323,7 @@ fn plugin_row_description(plugin: &thinkterm_plugin_channel::registry::Info) ->};let state = match &plugin.state {State::Off | State::Idle => None,+ State::New => Some(crate::i18n::tr("settings-plugins-new")),State::Starting => Some(crate::i18n::tr("settings-plugins-starting")),State::Running => Some(crate::i18n::tr("settings-plugins-running")),State::Crashed { reason } => Some(settings_tr(@@ -1339,7 +1340,14 @@ fn plugin_row_description(plugin: &thinkterm_plugin_channel::registry::Info) ->)),State::Unsupported { .. } => Some(crate::i18n::tr("settings-plugins-unsupported")),};- vec![Some(origin), state, Some(plugin.description.clone())]+ // A new one says where it is: that is what allowing it lets run.+ let place = plugin+ .target+ .as_deref()+ .or(plugin.dir.as_deref())+ .filter(|_| plugin.state == State::New)+ .map(|dir| crate::ui::home_relative(std::path::Path::new(dir)));+ vec![Some(origin), state, place, Some(plugin.description.clone())].into_iter().flatten().filter(|part| !part.is_empty())@@ -1381,6 +1389,8 @@ enum SettingsAction {/// Turn a plugin on or off. Carries `plugin_key(id)`, as RevokeWebToken/// carries its token's: the list can change between press and release.TogglePlugin(u64),+ /// Let a new plugin run, from where it is, keyed as TogglePlugin.+ AllowPlugin(u64),/// How long a plugin runs unused, keyed as TogglePlugin: the menu of the/// choices, and one chosen.TogglePluginBackgroundMenu(u64),@@ -5741,6 +5751,19 @@ impl SettingsWindow {}window.invalidate();}+ SettingsAction::AllowPlugin(key) => {+ self.ui.open_dropdown = None;+ let new = self+ .ui+ .plugin_switches+ .iter()+ .find(|(shown, _, _)| *shown == key)+ .cloned();+ if let Some((_, id, _)) = new {+ crate::plugins::set_enabled(&id, true);+ }+ window.invalidate();+ }SettingsAction::TogglePluginBackgroundMenu(key) => {let menu = SettingsDropdown::PluginBackground(key);self.ui.open_dropdown = if self.ui.open_dropdown == Some(menu) {@@ -14022,6 +14045,25 @@ impl SettingsWindow {continue;}let key = plugin_key(&plugin.id);+ if plugin.state == State::New && crate::plugins::switching(&plugin.id).is_none() {+ // Never let run: a button, not a switch, so that it+ // takes a press made for it.+ this.ui+ .plugin_switches+ .push((key, plugin.id.clone(), false));+ rows.add(this.paint_action_setting_row(+ layers,+ tx,+ rows.y,+ tw,+ &plugin.name,+ &description,+ &crate::i18n::tr("settings-plugins-allow"),+ SettingsAction::AllowPlugin(key),+ rows.rule(),+ )?);+ continue;+ }let enabled = crate::plugins::switching(&plugin.id).unwrap_or(plugin.enabled);this.ui.plugin_switchesdiff --git a/wezterm/src/plugin.rs b/wezterm/src/plugin.rsindex a8288367..9d8016fa 100644--- a/wezterm/src/plugin.rs+++ b/wezterm/src/plugin.rs@@ -19,7 +19,8 @@ pub struct PluginCommand {enum Sub {/// List the plugins and their statesList,- /// Turn a plugin on+ /// Turn a plugin on. A new one is let run from where it is installed,+ /// which nothing else doesEnable { id: String },/// Turn a plugin offDisable { id: String },@@ -120,6 +121,7 @@ fn locale() -> String {fn state_label(info: &Info) -> &'static str {match info.state {+ State::New => "new",State::Off => "off",State::Idle => "idle",State::Starting => "starting",@@ -164,6 +166,13 @@ fn print_list(listed: &[Info]) -> std::io::Result<()> {if let Some(reason) = info.state.reason() {writeln!(out, "{:id_width$} {reason}", "")?;}+ if info.state == State::New {+ writeln!(+ out,+ "{:id_width$} never let run: `thinkterm plugin enable {}` lets it",+ "", info.id+ )?;+ }}Ok(())}