From 214493b44c8abfba10b59d12f20397e3280771b6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 18:27:24 -0800 Subject: [PATCH 1/7] =?UTF-8?q?Scripts:=20the=20Other=20Script=E2=80=A6=20?= =?UTF-8?q?warning=20lists=20what=20the=20script=20reaches=20outside=20the?= =?UTF-8?q?=20document?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The warning before File › Scripts › Other Script… runs a script now runs script.check on it, which does not run any of it, and lists what the check finds: each outside-the-document category of the report (files the script writes, moves or deletes, files it opens in other apps, messages to other apps, the network, native code, environment variables, preferences, code the checker can't read), the files and dialogs it needs, features only the reference app has, and the files its `#include` lines name. It says when the script is too large to check, compiled, not a script or not read, and when a list was cut short at its limit. A script that reaches nothing gets the warning as before. The labels are Check Script…'s. Run still runs the script. The report is in the dialog's protected `__reaches` field, which ui.dialog.set cannot change. Scripts from the Scripts folder still run without the warning. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/dialogs/script_check.rs | 10 +-- crates/ui-egui/src/dialogs/script_run.rs | 88 ++++++++++++++++++- crates/ui-egui/src/tests/script_run.rs | 99 ++++++++++++++++++++++ docs/mcp.md | 9 +- docs/target-app-parity.md | 1 + 6 files changed, 200 insertions(+), 9 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index c3dbf78293..da4575a87b 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -2029,7 +2029,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.runScript", "Other Script…", "Cmd+F12", - "{path? | source?, name?} run a .js or .jsx file (script.run), after the warning unless Preferences › General › Show External Script Warning is off (dialog `scriptRun`: `name`, `script`, `dontShow`); without a file pick one (the web opens the browser's file picker)", + "{path? | source?, name?} run a .js or .jsx file (script.run), after the warning unless Preferences › General › Show External Script Warning is off (dialog `scriptRun`: `name`, `script`, `dontShow`, and `__reaches`: the `kind`, `needs`, `outside`, `includes` and `truncated` of script.check's report on the script, which the warning lists, or null when the check failed); without a file pick one (the web opens the browser's file picker)", ), ( "ui.runInstalledScript", diff --git a/crates/ui-egui/src/dialogs/script_check.rs b/crates/ui-egui/src/dialogs/script_check.rs index e134cf1b39..fd22e6bd11 100644 --- a/crates/ui-egui/src/dialogs/script_check.rs +++ b/crates/ui-egui/src/dialogs/script_check.rs @@ -123,7 +123,7 @@ pub(crate) fn problem_label(code: &str) -> Option<&'static str> { } /// Where something is: `line 12`, or `lib/a.jsxinc, line 3` in an included file. -fn place(item: &Value) -> String { +pub(super) fn place(item: &Value) -> String { let line = item["line"].as_u64().map(|l| l.to_string()); match (item["file"].as_str(), line) { (Some(file), Some(line)) => crate::i18n::fmt(tl!("{file}, line {line}"), &[("file", file), ("line", &line)]), @@ -164,7 +164,7 @@ fn body(_: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { } /// A row of a section: `text` (user data in `mono`), then a count and lines, dimmed. -fn row(ui: &mut egui::Ui, t: &Tokens, text: &str, mono: bool, note: &str) { +pub(super) fn row(ui: &mut egui::Ui, t: &Tokens, text: &str, mono: bool, note: &str) { ui.horizontal_wrapped(|ui| { let text = egui::RichText::new(text).color(t.text_strong); ui.label(if mono { text.monospace() } else { text.size(12.5) }); @@ -175,7 +175,7 @@ fn row(ui: &mut egui::Ui, t: &Tokens, text: &str, mono: bool, note: &str) { } /// `count` and `lines` of an entry as a note: `3 · lines 4, 9, 12`. -fn tally(item: &Value) -> String { +pub(super) fn tally(item: &Value) -> String { let count = item["count"].as_u64().unwrap_or_default(); match lines(item) { l if l.is_empty() => count.to_string(), @@ -183,13 +183,13 @@ fn tally(item: &Value) -> String { } } -fn section(ui: &mut egui::Ui, heading: &str, rows: impl FnOnce(&mut egui::Ui)) { +pub(super) fn section(ui: &mut egui::Ui, heading: &str, rows: impl FnOnce(&mut egui::Ui)) { ui.add_space(8.0); widgets::section_header(ui, heading); rows(ui); } -fn list<'r>(r: &'r Value, key: &str) -> &'r [Value] { +pub(super) fn list<'r>(r: &'r Value, key: &str) -> &'r [Value] { r[key].as_array().map_or(&[][..], Vec::as_slice) } diff --git a/crates/ui-egui/src/dialogs/script_run.rs b/crates/ui-egui/src/dialogs/script_run.rs index f8baa7b7de..94f53b7ca0 100644 --- a/crates/ui-egui/src/dialogs/script_run.rs +++ b/crates/ui-egui/src/dialogs/script_run.rs @@ -5,7 +5,16 @@ //! `ui.runScript {path? | source?, name?}` shows the warning for that script; without either it //! asks for a `.js` or `.jsx` file (the web opens the browser's file picker). With Preferences › //! General › Show External Script Warning off, the chosen script runs at once. Warning fields: -//! `name`, `script` (`script.run`'s params) and `dontShow` (true: turn the warning off). +//! `name`, `script` (`script.run`'s params), `dontShow` (true: turn the warning off) and +//! `__reaches`, which `ui.dialog.set` cannot set: the `kind`, `needs`, `outside`, `includes` and +//! `truncated` of `script.check`'s report on the script, read without running it (a path also +//! checks the files its `#include` lines name), or null when the check fails. The warning lists +//! what the report finds the script reaches outside the document (each of `script.check`'s +//! `outside` categories, such as files it writes, moves or deletes, files it opens in other apps, +//! the network, native code, environment variables and code the checker can't read), the files +//! and dialogs it needs, features only the reference app has, and its includes. It says when the +//! script is too large to check, compiled or not a script, when the check failed, and when a list +//! was cut short at its limit. The listing is information: Run runs the script as before. //! //! A script's dialog (kind `scriptDialog`) has the fields `kind` (alert, confirm or prompt), //! `message`, `title` (null: Script Alert), `errorIcon`, `noAsDefault` and `value` (the prompt's @@ -151,15 +160,90 @@ pub(crate) fn chosen(app: &mut VectorcraftApp, params: Value) -> Result Value { + let check = match (params.get("path"), params.get("source")) { + (Some(path), _) => json!({"path": path, "includes": true}), + (None, Some(source)) => json!({"data": source}), + (None, None) => return Value::Null, + }; + let Ok(r) = app.session.execute("script.check", &check) else { return Value::Null }; + json!({"kind": r["kind"], "needs": r["needs"], "outside": r["outside"], "includes": r["includes"], "truncated": r["truncated"]}) +} + +/// What the report `r` finds the script reaches outside the document; nothing for a script that +/// was checked and reaches nothing. A failed check (null) says the script was not read. +fn reach_rows(ui: &mut egui::Ui, r: &Value, t: &Tokens) { + use super::script_check::{list, need_label, outside_label, place, row, section, status_label, tally}; + let unchecked = match r["kind"].as_str() { + Some("script") => None, + Some("compiled") => Some(tl!("Compiled script: ask its author for the .jsx file")), + Some("tooLarge") => Some(tl!("Too large to check")), + _ if r.is_null() => Some(tl!("Not read")), + _ => Some(tl!("Not a script for the reference app")), + }; + if let Some(text) = unchecked { + ui.add_space(8.0); + widgets::dim_label(ui, text); + return; + } + let outside: Vec<(&str, &Value)> = list(r, "outside").iter().filter_map(|o| Some((o["id"].as_str().and_then(outside_label)?, o))).collect(); + let needs: Vec<&str> = + list(r, "needs").iter().filter_map(Value::as_str).filter(|n| matches!(*n, "files" | "dialogs" | "hostOnly")).filter_map(need_label).collect(); + let includes = list(r, "includes"); + let truncated = r["truncated"].as_bool() == Some(true); + if outside.is_empty() && needs.is_empty() && includes.is_empty() && !truncated { + return; + } + ui.add_space(8.0); + widgets::dim_label(ui, tl!("VectorCraft read this script without running it.")); + egui::ScrollArea::vertical().id_salt("script-reaches").max_height(220.0).show(ui, |ui| { + if !outside.is_empty() || !needs.is_empty() { + section(ui, tl!("Outside the document"), |ui| { + for (label, o) in outside { + let modes: Vec<&str> = list(o, "modes").iter().filter_map(Value::as_str).collect(); + let label = if modes.is_empty() { label.to_string() } else { format!("{label} ({})", modes.join(", ")) }; + row(ui, t, &label, false, &tally(o)); + } + for need in needs { + row(ui, t, need, false, ""); + } + }); + } + if !includes.is_empty() { + section(ui, tl!("Includes"), |ui| { + for i in includes { + let status = i["status"].as_str().and_then(status_label).unwrap_or_default(); + let note = [status.to_string(), place(i)].into_iter().filter(|s| !s.is_empty()).collect::>().join(" · "); + row(ui, t, i["value"].as_str().unwrap_or_default(), true, ¬e); + } + }); + } + }); + if truncated { + ui.add_space(6.0); + widgets::dim_label(ui, tl!("Some lists were cut short at their limit.")); + } +} + fn body(_: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { let t = Tokens::get(ui.ctx()); ui.label(egui::RichText::new(d.fields.get("name").and_then(Value::as_str).unwrap_or_default()).font(theme::semibold(12.5)).color(t.text_strong)); ui.add_space(4.0); ui.label(tl!("A script can change the open documents and can write files through the commands it runs. Run only scripts you trust.")); + if let Some(r) = d.fields.get(REACHES) { + reach_rows(ui, r, &t); + } ui.add_space(8.0); let dont_show = d.fields.get("dontShow").and_then(Value::as_bool).unwrap_or(false); if widgets::check(ui, tl!("Do not show this warning again"), dont_show, true) { diff --git a/crates/ui-egui/src/tests/script_run.rs b/crates/ui-egui/src/tests/script_run.rs index fee27caa13..579f55b4e4 100644 --- a/crates/ui-egui/src/tests/script_run.rs +++ b/crates/ui-egui/src/tests/script_run.rs @@ -640,6 +640,105 @@ fn a_scripts_file_dialog_keeps_at_most_2048_picked_files() { finish(&mut app); } +/// The warning before a run lists the files the script writes, read without running it. +#[test] +fn the_warning_lists_the_files_a_script_writes() { + let mut app = app(); + let source = "var f = new File(Folder.temp + '/out.txt');\nf.open('w');\nf.write('x');\nf.close();\n"; + menus::run_ui_command(&mut app, "ui.runScript", &json!({"source": source, "name": "write.js"})).unwrap().unwrap(); + assert!(!app.session.script_running()); + let texts = dialog_texts(&mut app); + let writes = dialogs::script_check::outside_label("filesWritten").unwrap(); + assert!(texts.iter().any(|t| t.starts_with(writes) && t.contains("(w)")), "{texts:?}"); + assert!(texts.iter().any(|t| t == dialogs::script_check::need_label("files").unwrap()), "{texts:?}"); + assert!(texts.iter().any(|t| t == "Outside the document"), "{texts:?}"); + // The warning holds the report as `__reaches`, which `ui.dialog.set` cannot change. + let d = app.ui.dialog.as_ref().unwrap(); + assert_eq!(d.fields["__reaches"]["outside"][0]["id"], "filesWritten"); + assert!(dialogs::protected_field(d, "__reaches")); + dialogs::cancel(&mut app); + finish(&mut app); +} + +/// A script that reaches nothing outside the document gets the warning with nothing more. +#[test] +fn the_warning_for_a_script_that_reaches_nothing_lists_nothing_more() { + let mut app = app(); + menus::run_ui_command(&mut app, "ui.runScript", &json!({"source": DRAW, "name": "draw.js"})).unwrap().unwrap(); + let texts = dialog_texts(&mut app); + assert!(texts.iter().any(|t| t.starts_with("A script can change the open documents")), "{texts:?}"); + for heading in ["Outside the document", "Includes", "VectorCraft read this script without running it."] { + assert!(!texts.iter().any(|t| t == heading), "{heading}: {texts:?}"); + } + confirm(&mut app).unwrap(); + finish(&mut app); + assert_eq!(objects(&app), 2); +} + +/// A script file's warning also lists what the files its `#include` lines name reach. +#[test] +fn the_warning_lists_what_a_scripts_included_files_reach() { + let mut app = app(); + let dir = folder("includes"); + std::fs::create_dir_all(dir.join("lib")).unwrap(); + std::fs::write(dir.join("main.jsx"), "#include 'lib/net.jsxinc'\n").unwrap(); + std::fs::write(dir.join("lib/net.jsxinc"), "var s = new Socket();\n").unwrap(); + menus::run_ui_command(&mut app, "ui.runScript", &json!({"path": dir.join("main.jsx").to_string_lossy()})).unwrap().unwrap(); + let texts = dialog_texts(&mut app); + assert!(texts.iter().any(|t| t == "lib/net.jsxinc"), "{texts:?}"); + assert!(texts.iter().any(|t| t == dialogs::script_check::need_label("hostOnly").unwrap()), "{texts:?}"); + dialogs::cancel(&mut app); + finish(&mut app); + let _ = std::fs::remove_dir_all(&dir); +} + +/// A script the checker could not read as a script gets a warning that says so, not the warning of +/// a script that was checked and reaches nothing. +#[test] +fn the_warning_says_when_a_script_was_not_checked() { + let missing = std::env::temp_dir().join(format!("vc-script-run-ui-missing-{}.js", std::process::id())); + for (params, text) in [ + (json!({"source": "export const b = 2;", "name": "module.js"}), "Not a script for the reference app"), + (json!({"source": "var a = 1;\u{0}", "name": "binary.js"}), "Not a script for the reference app"), + (json!({"source": "@JSXBIN@ES@2.0@MyBbyBn0ABJAnA", "name": "compiled.js"}), "Compiled script: ask its author for the .jsx file"), + (json!({"path": missing.to_string_lossy()}), "Not read"), + ] { + let mut app = app(); + menus::run_ui_command(&mut app, "ui.runScript", ¶ms).unwrap().unwrap(); + let texts = dialog_texts(&mut app); + assert!(texts.iter().any(|t| t == text), "{params}: {texts:?}"); + dialogs::cancel(&mut app); + finish(&mut app); + } +} + +/// A script whose report was cut short at a list's limit says so, also when nothing else is listed. +#[test] +fn the_warning_says_when_a_list_was_cut_short() { + let mut app = app(); + let source: String = (0..=1000).map(|n| format!("x = app.m{n};\n")).collect(); + menus::run_ui_command(&mut app, "ui.runScript", &json!({"source": source, "name": "many.js"})).unwrap().unwrap(); + let texts = dialog_texts(&mut app); + assert!(texts.iter().any(|t| t == "Some lists were cut short at their limit."), "{texts:?}"); + dialogs::cancel(&mut app); + finish(&mut app); +} + +/// A script over the checker's size limit gets a warning that says it was too large to check. +#[test] +fn the_warning_says_when_a_script_is_too_large_to_check() { + let mut app = app(); + let dir = folder("large"); + let path = dir.join("large.js"); + std::fs::write(&path, vec![b' '; vectorcraft_engine::script::MAX_SOURCE_BYTES + 1]).unwrap(); + menus::run_ui_command(&mut app, "ui.runScript", &json!({"path": path.to_string_lossy()})).unwrap().unwrap(); + let texts = dialog_texts(&mut app); + assert!(texts.iter().any(|t| t == "Too large to check"), "{texts:?}"); + dialogs::cancel(&mut app); + finish(&mut app); + let _ = std::fs::remove_dir_all(&dir); +} + #[test] fn a_new_app_shows_the_warning_by_default() { assert!(Session::new().prefs.show_external_script_warning); diff --git a/docs/mcp.md b/docs/mcp.md index e7abf476a9..b0b7d1cfe3 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2605,7 +2605,14 @@ vectorcraft-cli run --cmd script.check --params '{"path": "Tidy Layers.jsx"}' `script.run {path? | source?, name?, args?, answers?, maxFuel?}` runs a JavaScript file against the open documents. File › Scripts › Other Script… (Cmd+F12) picks a `.js` or `.jsx` file and runs it the same way; the help page https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/install-and-run-scripts.html -describes that menu item. Pass exactly one of `path` and `source`. A `path` must end in `.js` or `.jsx`, in any +describes that menu item. Its warning before the run lists what `script.check` finds the script reaches outside +the document, read without running it: each `outside` category of the report (files it writes, moves or deletes, +files it opens in other apps, messages to other apps, the network, native code, environment variables, the reference +app's preferences and code the checker can't read), the files and dialogs it needs, features only the reference app +has, and the files its `#include` lines name. It says when the script is too large to check, compiled or not a +script, when the check failed, and when a list was cut short at its limit. The listing does not stop the run. A +script from the Scripts folder runs without the warning. +Pass exactly one of `path` and `source`. A `path` must end in `.js` or `.jsx`, in any case. A `.jsxbin` file or text that starts with `@JSXBIN@` is compiled and ends with an error, as does text that is not UTF-8. The language is ES5.1, except that identifiers take the characters Unicode's `ID_Start` and `ID_Continue` properties allow, as later editions define them, and may use `\u{...}` escapes. The script reaches the diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 57ac87a396..3e6fa55d4b 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1026,6 +1026,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Scripts: File › Scripts › Other Script… and `script.run` run a JavaScript file against the open documents as one transaction with one undo step for each changed document. A failed or stopped run puts every document back. `crates/engine/src/tests/script_run.rs`. - Scripts: Window › Script Console shows each run's `$.write` and `$.writeln` output, `vc.log` entries, uncaught error with the script's name, line and column, and a report of its time, host calls and slowest commands, keeping at most 2,048 lines and counting the lines it dropped. `script.run`'s report carries the same data, and `script.console`, `script.console.clear` and `ui.copyScriptConsole` read, clear and copy it. `crates/engine/src/tests/script_console.rs`. - Scripts: the status bar translates its own words around a failed run's error and the app's own error messages, and shows text the script threw itself (a value, an error it made, or an error whose name or message it changed) as it is, even when that text reads like one of the app's messages. `script.run`'s report gives `messageOrigin` (`script` or `built-in`), and the advice about objects other applications give their scripts follows only the app's own reference errors. VectorCraft's own rule. `crates/js/src/interp_tests.rs`, `crates/engine/src/tests/script_run.rs`, `crates/ui-egui/src/chrome/tests.rs`. + - Scripts: the warning before File › Scripts › Other Script… runs a script lists what `script.check` finds the script reaches outside the document (files it writes, moves or deletes, other apps, the network, native code, environment variables, preferences, code the checker can't read), the files and dialogs it needs, features only the reference app has and its included files, read without running it. It says when the script is too large to check, compiled, not a script or not read, and when a list was cut short. VectorCraft's own rule. `crates/ui-egui/src/tests/script_run.rs`. - Scripts: the `$` object has the other members the Dollar object page lists (https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/), from `$.about()` to `$.version`, and scripts have the global `localize(object, ...values)` (https://extendscript.docsforadobe.dev/extendscript-tools-features/localizing-extendscript-strings/), `toSource(value)` and `Object.prototype.toSource()`. Each run starts with the interface's locale, and what a script changes in `$` lasts only for that run. `crates/engine/src/tests/script_dollar.rs`, `crates/js/src/extension_tests.rs`. - Scripts: `toSource` throws a `TypeError` for a property that is not writable or not configurable, a sealed, frozen or non-extensible object or array, and an array with a read-only `length` (VectorCraft's own rule). `crates/js/src/extension_tests.rs`. - Scripts: a canceled request stops a run that sleeps in `$.sleep`, waits at a dialog or waits for approval to grow at the run's next slice, before its wake time or an answer, and every document goes back to its state before the run. VectorCraft's own rule. `crates/engine/src/tests/script_dollar.rs`, `crates/engine/src/tests/script_dialogs.rs`, `crates/engine/src/tests/script_run.rs`. From d62c72305667415a97dd0615f44565c7feb407a6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 06:22:17 -0800 Subject: [PATCH 2/7] Scripts: ui.runScript's source description lists the warning's __reaches The generated catalog in crates/mcp/src/ui_catalog.rs described the `__reaches` field of the `scriptRun` dialog, but the source entry in crates/ui-egui/src/menus/ui_commands.rs did not, so `cargo xtask ui-commands --check` failed. The source entry now carries the same text. --- crates/ui-egui/src/menus/ui_commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index d2c72aae40..4f8d017b1c 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -2030,7 +2030,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.runScript", "Other Script…", "Cmd+F12", - "{path? | source?, name?} run a .js or .jsx file (script.run), after the warning unless Preferences › General › Show External Script Warning is off (dialog `scriptRun`: `name`, `script`, `dontShow`); without a file pick one (the web opens the browser's file picker)", + "{path? | source?, name?} run a .js or .jsx file (script.run), after the warning unless Preferences › General › Show External Script Warning is off (dialog `scriptRun`: `name`, `script`, `dontShow`, and `__reaches`: the `kind`, `needs`, `outside`, `includes` and `truncated` of script.check's report on the script, which the warning lists, or null when the check failed); without a file pick one (the web opens the browser's file picker)", ), ( crate::scripts_menu::COMMAND, From 263223d604293a29cfe400285244d778a575af90 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 23:57:54 -0800 Subject: [PATCH 3/7] Scripts: Run checks the script again before running it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the script's report has changed since the Other Script… warning opened, Run runs nothing, says so in the status bar and opens the warning again with the new report. --- crates/ui-egui/src/dialogs/script_run.rs | 31 ++++++++++++++++++++---- crates/ui-egui/src/tests/script_run.rs | 22 +++++++++++++++++ docs/mcp.md | 5 ++-- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/dialogs/script_run.rs b/crates/ui-egui/src/dialogs/script_run.rs index 690feebd62..b7f3897931 100644 --- a/crates/ui-egui/src/dialogs/script_run.rs +++ b/crates/ui-egui/src/dialogs/script_run.rs @@ -15,7 +15,9 @@ //! and dialogs it needs, features only the reference app has, and its includes (at most //! [`SHOWN_INCLUDES`], then the count of the rest). It says when the script is too large to check, //! compiled or not a script, when the check failed, and when a list was cut short at its limit. -//! The listing is information: Run runs the script as before. The growth question +//! The listing is information: Run runs the script as before, after checking it again. When the +//! report has changed since the warning opened, nothing runs and the warning opens again with the +//! new report. The growth question //! (`scriptGrowth`) and the question quitting asks (`scriptClose`) have the `choice` field alone. //! //! A script's dialog (kind `scriptDialog`) has the fields `kind` (alert, confirm or prompt), @@ -522,8 +524,14 @@ pub(crate) fn chosen(app: &mut VectorcraftApp, params: Value) -> Result Result { + let path = params.get("path").and_then(Value::as_str); + let name = params.get("name").and_then(Value::as_str).or(path).map_or_else(|| "script".to_string(), vectorcraft_engine::cmd::fileio::file_name); // The script's name is the message: it is what the person reads first. let prompt = StandardPrompt::custom(name) .title(tl!("Run Script")) @@ -537,6 +545,10 @@ pub(crate) fn chosen(app: &mut VectorcraftApp, params: Value) -> Result() + && let Some(RunWarning { params, reaches: listed }) = answer.take_tag::() { - let stored = if answer.skip { app.run("prefs.set", json!({"key": "showExternalScriptWarning", "value": false})).map(drop) } else { Ok(()) }; - if let Err(e) = stored.and_then(|()| app.run("script.run", params).map(drop)) { + // A script whose report changed while the warning was open is listed again before it runs. + let now = reaches(app, ¶ms); + let ran = if now == listed { + let stored = + if answer.skip { app.run("prefs.set", json!({"key": "showExternalScriptWarning", "value": false})).map(drop) } else { Ok(()) }; + stored.and_then(|()| app.run("script.run", params).map(drop)) + } else { + app.status(CHANGED_SINCE_WARNING); + warn(app, params, now).map(drop) + }; + if let Err(e) = ran { app.status(e); } } diff --git a/crates/ui-egui/src/tests/script_run.rs b/crates/ui-egui/src/tests/script_run.rs index 0f26951362..11d9a3ed0c 100644 --- a/crates/ui-egui/src/tests/script_run.rs +++ b/crates/ui-egui/src/tests/script_run.rs @@ -541,6 +541,28 @@ fn the_warning_lists_what_a_scripts_included_files_reach() { let _ = std::fs::remove_dir_all(&dir); } +/// A script file that changes what it reaches while its warning is open does not run on Run: the +/// warning opens again with the new report, and the next Run runs it. +#[test] +fn run_lists_a_script_again_when_it_changed_after_its_warning_opened() { + let mut app = app(); + let dir = folder("changed"); + let path = dir.join("changed.jsx"); + std::fs::write(&path, DRAW).unwrap(); + menus::run_ui_command(&mut app, "ui.runScript", &json!({"path": path.to_string_lossy()})).unwrap().unwrap(); + assert_eq!(fields(&app, KIND)["reaches"]["outside"], json!([])); + std::fs::write(&path, format!("{DRAW}\nvar s = new Socket();\n")).unwrap(); + assert!(confirm(&mut app, KIND)); + assert!(!app.session.script_running()); + assert!(is_open::(&app)); + assert_eq!(app.ui.status, script_run::CHANGED_SINCE_WARNING); + assert_eq!(fields(&app, KIND)["reaches"]["outside"][0]["id"], "network"); + assert!(confirm(&mut app, KIND)); + assert!(app.session.script_running()); + finish(&mut app); + let _ = std::fs::remove_dir_all(&dir); +} + /// A script with more includes than the warning lists gives the count of the rest. #[test] fn the_warning_counts_the_includes_it_does_not_list() { diff --git a/docs/mcp.md b/docs/mcp.md index 8ef2380bca..5cd7f9210f 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2643,8 +2643,9 @@ files it opens in other apps, messages to other apps, the network, native code, app's preferences and code the checker can't read), the files and dialogs it needs, features only the reference app has, and the files its `#include` lines name (the first 20, then the count of the rest; VectorCraft's own limit). It says when the script is too large to check, compiled or not a script, when the check failed, and when a list was cut -short at its limit. The listing does not stop the run. A -script from the Scripts folder runs without the warning. +short at its limit. The listing does not stop the run. Run checks the script again, and when the report has changed +since the warning opened, nothing runs and the warning opens again with the new report. A script from the Scripts +folder runs without the warning. Pass exactly one of `path` and `source`. A `path` must end in `.js` or `.jsx`, in any case. A `.jsxbin` file or text that starts with `@JSXBIN@` is compiled and ends with an error, as does text that is not UTF-8. The language is ES5.1, except that identifiers take the characters Unicode's `ID_Start` and From 2b155a5de177931f7860860bb017f24cb4f5bfb0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 04:00:21 -0800 Subject: [PATCH 4/7] Scripts: the warning lists a script's needs apart from what it reaches A need such as dialogs or host features now shows on its own line, and the "Outside the document" heading appears only above what the script does outside the document. --- crates/ui-egui/src/dialogs/script_run.rs | 11 ++++++----- crates/ui-egui/src/tests/script_run.rs | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/dialogs/script_run.rs b/crates/ui-egui/src/dialogs/script_run.rs index b7f3897931..1d54f82fd6 100644 --- a/crates/ui-egui/src/dialogs/script_run.rs +++ b/crates/ui-egui/src/dialogs/script_run.rs @@ -592,11 +592,12 @@ fn listed(prompt: StandardPrompt, r: &Value) -> StandardPrompt { }) .collect(); let needs = list(r, "needs").iter().filter_map(Value::as_str).filter(|n| matches!(*n, "files" | "dialogs" | "hostOnly")).filter_map(need_label); - let mut lines: Vec = Vec::new(); - lines.extend(outside); - lines.extend(needs.map(str::to_string)); - if !lines.is_empty() { - lines.insert(0, crate::i18n::colon(tl!("Outside the document"))); + // The needs come first, each a sentence of its own; the heading names only what the script does + // outside the document. + let mut lines: Vec = needs.map(str::to_string).collect(); + if !outside.is_empty() { + lines.push(crate::i18n::colon(tl!("Outside the document"))); + lines.extend(outside); } let includes = list(r, "includes"); if !includes.is_empty() { diff --git a/crates/ui-egui/src/tests/script_run.rs b/crates/ui-egui/src/tests/script_run.rs index 11d9a3ed0c..fcb0d8bbd2 100644 --- a/crates/ui-egui/src/tests/script_run.rs +++ b/crates/ui-egui/src/tests/script_run.rs @@ -541,6 +541,20 @@ fn the_warning_lists_what_a_scripts_included_files_reach() { let _ = std::fs::remove_dir_all(&dir); } +/// A script that opens a dialog and reaches nothing outside the document lists the need without the +/// outside-the-document heading. +#[test] +fn the_warning_lists_a_need_without_the_outside_heading() { + let mut app = app(); + menus::run_ui_command(&mut app, "ui.runScript", &json!({"source": "var w = new Window('dialog', 'Title');", "name": "dialog.js"})).unwrap().unwrap(); + assert_eq!(fields(&app, KIND)["reaches"]["outside"], json!([])); + let texts = dialog_texts(&mut app); + assert!(texts.iter().any(|t| t == script_check::need_label("dialogs").unwrap()), "{texts:?}"); + assert!(!texts.iter().any(|t| t == "Outside the document:"), "{texts:?}"); + cancel(&mut app, KIND); + finish(&mut app); +} + /// A script file that changes what it reaches while its warning is open does not run on Run: the /// warning opens again with the new report, and the next Run runs it. #[test] From 8ab94ba4e88cbb4804092b3a2b941f8d65d3c0cd Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 04:24:48 -0800 Subject: [PATCH 5/7] Scripts: format the dialog-need warning test --- crates/ui-egui/src/tests/script_run.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tests/script_run.rs b/crates/ui-egui/src/tests/script_run.rs index fcb0d8bbd2..8ffe57f766 100644 --- a/crates/ui-egui/src/tests/script_run.rs +++ b/crates/ui-egui/src/tests/script_run.rs @@ -546,7 +546,8 @@ fn the_warning_lists_what_a_scripts_included_files_reach() { #[test] fn the_warning_lists_a_need_without_the_outside_heading() { let mut app = app(); - menus::run_ui_command(&mut app, "ui.runScript", &json!({"source": "var w = new Window('dialog', 'Title');", "name": "dialog.js"})).unwrap().unwrap(); + let source = "var w = new Window('dialog', 'Title');"; + menus::run_ui_command(&mut app, "ui.runScript", &json!({"source": source, "name": "dialog.js"})).unwrap().unwrap(); assert_eq!(fields(&app, KIND)["reaches"]["outside"], json!([])); let texts = dialog_texts(&mut app); assert!(texts.iter().any(|t| t == script_check::need_label("dialogs").unwrap()), "{texts:?}"); From 2b9abfc8fb41d7f7bda99040075242ec2c4a283e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 06:20:33 -0800 Subject: [PATCH 6/7] Scripts: Run checks the script again under the access the run has The check Run makes before running read the script under the answering request's access alone. A warning asked under a folder limit listed a script it could not read, and answered without that limit, the check then read it and reported the script as changed. A warning answered by automation confined to a folder failed the check and also reported a change. The check now runs under the same combined access as the run, and a script the warning listed that this access cannot read is refused with the check's error. --- crates/ui-egui/src/dialogs/script_run.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/dialogs/script_run.rs b/crates/ui-egui/src/dialogs/script_run.rs index b05572feeb..87352085f7 100644 --- a/crates/ui-egui/src/dialogs/script_run.rs +++ b/crates/ui-egui/src/dialogs/script_run.rs @@ -581,13 +581,19 @@ pub(crate) const SHOWN_INCLUDES: usize = 20; /// warning lists, read without running the script; a path also checks the files its `#include` /// lines name. Null when the check fails: the run reports why the script can't be read. fn reaches(app: &mut VectorcraftApp, params: &Value) -> Value { + checked(app, params).unwrap_or(Value::Null) +} + +/// [`reaches`], with the check's error when it fails, for example when the request asking can't +/// read the script. +fn checked(app: &mut VectorcraftApp, params: &Value) -> Result { let check = match (params.get("path"), params.get("source")) { (Some(path), _) => json!({"path": path, "includes": true}), (None, Some(source)) => json!({"data": source}), - (None, None) => return Value::Null, + (None, None) => return Ok(Value::Null), }; - let Ok(r) = app.session.execute("script.check", &check) else { return Value::Null }; - json!({"kind": r["kind"], "needs": r["needs"], "outside": r["outside"], "includes": r["includes"], "truncated": r["truncated"]}) + let r = app.session.execute("script.check", &check).map_err(|e| e.to_string())?; + Ok(json!({"kind": r["kind"], "needs": r["needs"], "outside": r["outside"], "includes": r["includes"], "truncated": r["truncated"]})) } /// `prompt` with what the report `r` finds the script reaches outside the document, one line each; @@ -731,8 +737,14 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) { && let Some(RunWarning { params, reaches: listed, scope, automated }) = answer.take_tag::() { // A script whose report changed while the warning was open is listed again before it runs. - let now = reaches(app, ¶ms); - let ran = if now == listed { + // A script read when the warning opened that the answering request can't read is + // refused with the check's error, not listed again as changed. + // The check reads the script under the access the run would have. + let ran = match scope.clone().within_current().run(|| checked(app, ¶ms)) { + Err(e) if !listed.is_null() => Err(e), + now => Ok(now.unwrap_or(Value::Null)), + } + .and_then(|now| if now == listed { let stored = if answer.skip { app.run("prefs.set", json!({"key": "showExternalScriptWarning", "value": false})).map(drop) } else { Ok(()) }; let run = |app: &mut VectorcraftApp| crate::script_runs::run_chosen(app, params).map(drop); @@ -741,7 +753,7 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) { } else { app.status(CHANGED_SINCE_WARNING); warn(app, params, now, scope, automated).map(drop) - }; + }); if let Err(e) = ran { app.status(e); } From 4fc6469b34f361a2da00156119474571c6224238 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 07:38:14 -0800 Subject: [PATCH 7/7] fmt: format the changed-script check in script_run.rs The gate stopped at `cargo fmt --all -- --check` on the `and_then` closure that compares the script with the one the warning listed. rustfmt wraps a multi-line `if` body of a closure in a block. --- crates/ui-egui/src/dialogs/script_run.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/dialogs/script_run.rs b/crates/ui-egui/src/dialogs/script_run.rs index 87352085f7..9b1a1b6764 100644 --- a/crates/ui-egui/src/dialogs/script_run.rs +++ b/crates/ui-egui/src/dialogs/script_run.rs @@ -744,15 +744,17 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) { Err(e) if !listed.is_null() => Err(e), now => Ok(now.unwrap_or(Value::Null)), } - .and_then(|now| if now == listed { - let stored = - if answer.skip { app.run("prefs.set", json!({"key": "showExternalScriptWarning", "value": false})).map(drop) } else { Ok(()) }; - let run = |app: &mut VectorcraftApp| crate::script_runs::run_chosen(app, params).map(drop); - let automated = automated || app.automation_asked(); - stored.and_then(|()| scope.within_current().run(|| file_asks::as_automated(app, automated, run))) - } else { - app.status(CHANGED_SINCE_WARNING); - warn(app, params, now, scope, automated).map(drop) + .and_then(|now| { + if now == listed { + let stored = + if answer.skip { app.run("prefs.set", json!({"key": "showExternalScriptWarning", "value": false})).map(drop) } else { Ok(()) }; + let run = |app: &mut VectorcraftApp| crate::script_runs::run_chosen(app, params).map(drop); + let automated = automated || app.automation_asked(); + stored.and_then(|()| scope.within_current().run(|| file_asks::as_automated(app, automated, run))) + } else { + app.status(CHANGED_SINCE_WARNING); + warn(app, params, now, scope, automated).map(drop) + } }); if let Err(e) = ran { app.status(e);