Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/rustgis-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,16 @@ fn mcp(s: &mut Session, args: &[String]) -> Result<(), String> {
Ok(())
}

/// Runs the command line, then stops the session plugins' programs its commands started.
fn main() -> ExitCode {
let code = cli();
// Session plugins' programs a command started end with the command line.
rustgis_engine::plugins::session::stop_all();
code
}

/// The command line: loads the plugins, then runs the subcommand the arguments name.
fn cli() -> ExitCode {
let args: Vec<String> = std::env::args().skip(1).collect();
let Some(cmd) = args.first().map(|s| s.as_str()) else { return usage() };
if !args.iter().any(|a| a == "--no-plugins") {
Expand Down
2 changes: 2 additions & 0 deletions apps/rustgis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ impl eframe::App for App {
fn on_exit(&mut self) {
self.0.end_exports();
self.0.end_autosave();
// Session plugins' programs end with the app, with what they started.
rustgis_engine::plugins::session::stop_all();
// The installer starts before the marker goes, so a RustGIS started meanwhile finds this
// one still running.
#[cfg(windows)]
Expand Down
377 changes: 356 additions & 21 deletions crates/engine/src/cmd/plugins.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/engine/src/cmd/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn commands() -> Vec<C> {
// The session log (#797): read, written out, emptied, turned on or off. It sits outside
// the project, so none of these changes the project or takes an undo step.
C::new("project.log", "Session Log", "Project", log).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files)).view().params(
r#"{"since"?: milliseconds since 1970 (UTC), "until"?: milliseconds, "command"?: "a command id, or the start of one (layer.)", "failed"?: bool (true: only those that failed; false: only those that succeeded), "limit"?: entries, a whole number (default 100, the newest; 1 to 1000)} → {"entries": [{"at", "command", "params", "ok", "error"?, "millis", "project": the project open when it ran, "partial"?: true when params were cut or had secrets taken out}], "count": matching, "total": in the log, "on": bool}"#,
r#"{"since"?: milliseconds since 1970 (UTC), "until"?: milliseconds, "command"?: "a command id, or the start of one (layer.)", "failed"?: bool (true: only those that failed; false: only those that succeeded), "limit"?: entries, a whole number (default 100, the newest; 1 to 1000)} → {"entries": [{"at", "command", "params", "ok", "error"?, "millis", "project": the project open when it ran, "partial"?: true when params were cut or had secrets taken out, "plugin"?: the session plugin that asked for it between its commands}], "count": matching, "total": in the log, "on": bool}"#,
),
C::new("project.exportLog", "Export Session Log", "Project", export_log).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Files))
.view()
Expand Down
4 changes: 4 additions & 0 deletions crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,9 @@ pub struct Session {
/// them (it keeps nothing between calls). Not saved with the project: a plugin's state
/// command reads what it needs from the map when the panel opens.
pub plugin_panels: std::collections::BTreeMap<String, rustgis_plugins::PanelState>,
/// What running session plugins were last told of the map, to send them events.
#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
pub(crate) plugin_watch: cmd::plugins::Watch,
/// Data downloads of this project under way (Home › Add › Add Data › From URL), by id.
downloading: Vec<u64>,
/// Downloads that landed, waiting for `layer.addDownload`.
Expand Down Expand Up @@ -1150,6 +1153,7 @@ impl Session {
started: Vec::new(),
plugin_runs: Vec::new(),
plugin_panels: std::collections::BTreeMap::new(),
plugin_watch: Default::default(),
downloading: Vec::new(),
downloaded: Vec::new(),
landed_reads: Vec::new(),
Expand Down
14 changes: 14 additions & 0 deletions crates/engine/src/policy/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,20 @@ impl Session {
Err(p) => std::panic::resume_unwind(p),
}
}
/// Runs what a session plugin's program asks between its commands with the plugin's own
/// authority, as its commands run: the exact load, still current, narrowing the scope the app
/// is in (none at the frame's root, the trusted native convention).
#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn as_session_plugin<T>(
&mut self,
plugin: Arc<rustgis_plugins::Plugin>,
f: impl FnOnce(&mut Session) -> T,
) -> Result<T, String> {
if !rustgis_plugins::is_current(&plugin) {
return Err("the plugin was disabled, updated or removed".into());
}
self.narrowed(Narrow::Plugin(super::plan::PluginPin(plugin)), f)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-raised with new evidence (confidence: medium): between-command requests lose the initiating agent's or assistant's scope.

as_session_plugin narrows whatever scope is on top of the stack. The frame's poll_plugin_sessions runs with an empty stack, so scope() falls back to Scope::user(). A request a session program sends between commands is therefore judged as the user's own, narrowed only by the plugin pin.

The same request is judged differently when the next command's prelude drains it (run_plugin in cmd/plugins.rs). That drain runs inside the command's narrowed(Narrow::Plugin(..)), so the initiating Kind::Agent/Kind::Assistant scope is still on the stack and applies.

Failure scenario: an agent with AgentAccess::Review starts a session plugin's command. The user approves that one Plugin call. Afterwards the program's layer.addUrl (network) or layer.addData (files) requests, sent between commands, run at user scope on the frame, with no per-call agent review.

The earlier replies answered the plugin-permissions question, but this thread's scope point has no answer. Suggested direction: record the initiating scope's kind (or the scope itself) when the program starts, and narrow the frame's polls to it, so the frame and the command prelude judge a request the same way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right that the two paths can differ, but only ever by narrowing: the drain at the start of a command runs inside that command's scope, so a request it answers is judged by the caller's scope intersected with the plugin's, never more than the plugin's own; the frame's poll judges it by the plugin's own authority, as designed for requests between commands. Making them identical would mean either widening a scope from inside a narrower one, which the policy refuses on purpose, or carrying the last caller's scope into the session, which the earlier thread answers. Leaving this to the maintainers as the design call it is.

}
/// Intersects nested plugin/item authority with its initiating scope.
pub(crate) fn narrowed<T>(&mut self, to: Narrow, f: impl FnOnce(&mut Session) -> T) -> Result<T, String> {
let mut scope = self.scope();
Expand Down
15 changes: 11 additions & 4 deletions crates/engine/src/project_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ pub(crate) fn entry(
project: project.0,
opened: project.1,
partial,
plugin: None,
}
}

Expand Down Expand Up @@ -573,6 +574,10 @@ pub struct LogEntry {
/// wouldn't run as they ran.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub partial: bool,
/// The plugin whose session program asked for it between its commands: it counts with the
/// plugins' commands toward [`LOG_PLUGIN_LIMIT`].
#[serde(default, skip_serializing_if = "Option::is_none")]
pub plugin: Option<String>,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AGENTS.md: "Never silent" (confidence: medium). Re-raised with new reasoning.

This field is what the CSV export drops. The CSV header and write_entry (project_log.rs ~616) have no plugin column, so a row for a between-command host.addLayer or select.rows from a plugin looks the same as the user's own. The JSON export keeps it. AGENTS.md says a writer that drops data must say what it dropped. The earlier answer, "a format and an interface addition of their own", doesn't cover that: the attribution is already in the entry, and the CSV drops it without a notice.

Options: add a plugin column to the CSV, or have the export notice say how many entries carry an attribution the CSV leaves out. Add a test for both the clean case and the lossy one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, fixed in aa621a8: the CSV export has a plugin column (empty for the user's own entries), so nothing in the entry is dropped; docs updated. The export test checks both an attributed row and a clean one.

}

impl LogEntry {
Expand Down Expand Up @@ -623,7 +628,7 @@ impl SessionLog {
if self.off && !matches!(e.command.as_str(), "project.logCommands" | "project.clearLog") {
return;
}
let plugin = |e: &LogEntry| e.command.starts_with(rustgis_plugins::PREFIX);
let plugin = |e: &LogEntry| e.command.starts_with(rustgis_plugins::PREFIX) || e.plugin.is_some();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if plugin(&e)
&& self.plugin_entries >= LOG_PLUGIN_LIMIT
&& let Some(oldest) = self.entries.iter().position(plugin)
Expand All @@ -649,7 +654,8 @@ impl SessionLog {
/// into the last undo step ([`crate::Session::merge_undo`]). The entry keeps when the first
/// started, takes the last one's parameters, and adds up how long they took.
pub fn join_last(&mut self, mut e: LogEntry) {
if let Some(last) = self.entries.back_mut().filter(|l| l.ok && l.command == e.command) {
// A session plugin's entry between the steps isn't the user's step to join.
if let Some(last) = self.entries.back_mut().filter(|l| l.ok && l.command == e.command && l.plugin == e.plugin) {
e.at = last.at;
e.millis = last.millis.saturating_add(e.millis);
*last = e;
Expand Down Expand Up @@ -713,7 +719,7 @@ impl SessionLog {
/// line). Entry by entry, so a long log isn't held as text first.
pub fn write(&self, w: &mut dyn std::io::Write, csv: bool) -> std::io::Result<()> {
if csv {
w.write_all(b"time_utc,at,command,ok,millis,error,params,project\n")?;
w.write_all(b"time_utc,at,command,ok,millis,error,params,plugin,project\n")?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compatibility (confidence: medium-low). The new plugin column is inserted before project, so every existing CSV export row moves its project value from column 8 to column 9. Anyone who reads this export by position (a spreadsheet macro, a script that uses cut -f8) gets the wrong field after upgrading, and nothing says so.

Appending the column after project keeps every existing column where it was. The header here and the write_entry row (csv_cell(e.plugin…) before csv_cell(&e.project)) would both move the new cell to the end. The sessionlog.rs test that checks the header prefix would need the same change.

@Mavrick-F Mavrick-F Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No released export has project in column 8: the project column came in #1583, after v0.6.0, whose CSV ends at params. So both new columns arrive together in the next release, and every column a released export has stays where it was in either order. Leaving the order as it is.

}
self.entries.iter().try_for_each(|e| write_entry(w, e, csv))
}
Expand All @@ -740,14 +746,15 @@ fn write_entry(w: &mut dyn std::io::Write, e: &LogEntry, csv: bool) -> std::io::
if csv {
writeln!(
w,
"{},{},{},{},{},{},{},{}",
"{},{},{},{},{},{},{},{},{}",
e.time_utc(),
e.at,
csv_cell(&e.command),
e.ok,
e.millis,
csv_cell(e.error.as_deref().unwrap_or("")),
csv_cell(&e.params.to_string()),
csv_cell(e.plugin.as_deref().unwrap_or("")),
csv_cell(&e.project)
)
} else {
Expand Down
Loading
Loading