mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 03:08:00 +00:00
Messages: a success token, and the docs state the plug-in and rollback rules
- The success level takes a new `success` theme token (the same green) instead of the 3D axis color. - docs/mcp.md names the plug-in conditions for `vc_call`, says no step is recorded while a drag or typing is in progress, says a failed script run keeps the messages it raised, and names the headless MCP server and `vectorcraft-cli run` as the sessions without a window. Lines wrap like the rest of the file. - The params text and the error say "whitespace", which is what the check rejects. - A new test runs a script that draws, raises a message and throws: the drawing is put back and the message is kept. - The long-message test also checks that the stack stays inside the window. - The evidence line in docs/target-app-parity.md moves after the Scripts entries.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
//! `app.toast`: a short message shown over the window that does not stop work and goes away by
|
||||
//! itself (a toast). Scripts (`vc.run`), actions (a recorded step), MCP clients and the app's own
|
||||
//! code ([`Session::toast`]) raise one. The engine queues the messages and the desktop app takes
|
||||
//! them each frame ([`Session::take_toasts`]) and shows them.
|
||||
//! itself (a toast). Scripts (`vc.run`), actions (a recorded step), MCP clients and plug-ins raise
|
||||
//! one with the command, and the app's code can raise one with [`Session::toast`]. The engine
|
||||
//! queues the messages and the desktop app takes them each frame ([`Session::take_toasts`]) and
|
||||
//! shows them. A failed script run puts the documents back but keeps the messages it raised.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
|
||||
@@ -22,7 +23,7 @@ pub const MIN_SECONDS: f64 = 0.5;
|
||||
pub const MAX_SECONDS: f64 = 60.0;
|
||||
|
||||
/// The most messages waiting for the app to take them: past it the oldest one goes. A session
|
||||
/// without a window (MCP, the command line) never takes them.
|
||||
/// without a window (the headless MCP server, `vectorcraft-cli run`) never takes them.
|
||||
pub const MAX_QUEUED: usize = 32;
|
||||
|
||||
/// What kind of news a message is, which sets its color.
|
||||
@@ -95,7 +96,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Show Message",
|
||||
[],
|
||||
None,
|
||||
"{message: string (1 to 500 characters, not only spaces), level?: \"info\" | \"success\" | \"warning\" | \"error\" (default \"info\"), seconds?: number 0.5 to 60 (default 4)} show `message` over the window without stopping work: it goes away after `seconds` or when clicked; messages stack at the window's bottom right, the newest lowest, at most 5 at once; edits no document; an action records it as a step → {message, level, seconds}",
|
||||
"{message: string (1 to 500 characters, not only whitespace), level?: \"info\" | \"success\" | \"warning\" | \"error\" (default \"info\"), seconds?: number 0.5 to 60 (default 4)} show `message` over the window without stopping work: it goes away after `seconds` or when clicked; messages stack at the window's bottom right, the newest lowest, at most 5 at once; edits no document; an action records it as a step → {message, level, seconds}",
|
||||
always,
|
||||
run
|
||||
)]
|
||||
@@ -116,7 +117,7 @@ fn parse(p: &Value) -> Result<Toast> {
|
||||
None => return Err(bad(ID, "`message` is required")),
|
||||
};
|
||||
if message.trim().is_empty() {
|
||||
return Err(bad(ID, "`message` must have a character other than a space"));
|
||||
return Err(bad(ID, "`message` must have a character other than whitespace"));
|
||||
}
|
||||
let chars = message.chars().count();
|
||||
if chars > MAX_CHARS {
|
||||
@@ -231,6 +232,27 @@ mod tests {
|
||||
assert_eq!(s.take_toasts(), vec![Toast::new("Done: 2", Level::Success)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_script_run_puts_the_documents_back_and_keeps_its_messages() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({})).unwrap();
|
||||
let art = format!("{:?}", s.active().unwrap().doc.layers);
|
||||
let e = s
|
||||
.execute(
|
||||
"script.run",
|
||||
&json!({
|
||||
"source": "vc.run('shape.rectangle', {x: 0, y: 0, width: 10, height: 10}); vc.run('app.toast', {message: 'Failed: no artboard'}); throw new Error('stop');",
|
||||
"name": "t.js",
|
||||
"answers": [],
|
||||
}),
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string();
|
||||
assert!(e.contains("stop"), "{e}");
|
||||
assert_eq!(format!("{:?}", s.active().unwrap().doc.layers), art, "the rectangle is put back");
|
||||
assert_eq!(s.take_toasts(), vec![Toast::new("Failed: no artboard", Level::Info)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_command_batch_raises_its_messages_in_order() {
|
||||
let mut s = Session::new();
|
||||
|
||||
@@ -163,6 +163,8 @@ pub struct Tokens {
|
||||
pub error: Color32,
|
||||
/// Warning marks (a modified linked file).
|
||||
pub warning: Color32,
|
||||
/// Success marks (a message of level `success`).
|
||||
pub success: Color32,
|
||||
/// Rotation gizmo axes, also labelled X, Y and Z.
|
||||
pub axis_x: Color32,
|
||||
pub axis_y: Color32,
|
||||
@@ -215,6 +217,7 @@ impl Tokens {
|
||||
artboard_mark: hex(0x808080),
|
||||
error: hex(0xe34850),
|
||||
warning: hex(0xf0a330),
|
||||
success: hex(0x45af63),
|
||||
axis_x: hex(0xef6058),
|
||||
axis_y: hex(0x45af63),
|
||||
axis_z: hex(0x378ef0),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Messages that `app.toast` and the app's own code ([`vectorcraft_engine::Session::toast`]) queue,
|
||||
//! shown over the window without taking the keyboard or stopping work: a stack at the window's
|
||||
//! bottom right, the newest lowest. Each one goes after its time or when clicked; past
|
||||
//! Messages that `app.toast` or a call of [`vectorcraft_engine::Session::toast`] queues, shown
|
||||
//! over the window without taking the keyboard or stopping work: a stack at the window's bottom
|
||||
//! right, the newest lowest. Each one goes after its time or when clicked; past
|
||||
//! [`MAX_SHOWN`] the oldest goes first. A message shows at most [`MAX_ROWS`] lines, and the whole
|
||||
//! text on hover; a stack taller than the window scrolls.
|
||||
|
||||
@@ -64,7 +64,7 @@ impl Shown {
|
||||
fn color(t: &Tokens, level: Level) -> egui::Color32 {
|
||||
match level {
|
||||
Level::Info => t.text_dim,
|
||||
Level::Success => t.axis_y,
|
||||
Level::Success => t.success,
|
||||
Level::Warning => t.warning,
|
||||
Level::Error => t.error,
|
||||
}
|
||||
@@ -319,6 +319,9 @@ mod tests {
|
||||
pass_in(&mut app, &ctx, 0.0, vec![], height);
|
||||
let newest = app.toasts.list.last().unwrap().rect.unwrap();
|
||||
assert!(newest.top() >= MARGIN - 0.5 && newest.bottom() <= height - MARGIN + 0.5, "{newest:?}");
|
||||
// The stack scrolls inside the window instead of growing past its top.
|
||||
let stack = ctx.memory(|m| m.area_rect(egui::Id::unique("toasts"))).unwrap();
|
||||
assert!(stack.top() >= MARGIN - 0.5 && stack.bottom() <= height - MARGIN + 0.5, "{stack:?}");
|
||||
assert_eq!(app.toasts.list.len(), MAX_SHOWN);
|
||||
}
|
||||
|
||||
|
||||
+8
-6
@@ -3160,15 +3160,17 @@ dropped.
|
||||
## Messages over the window
|
||||
|
||||
`app.toast {message, level?, seconds?}` shows a short message over the desktop app's window without stopping work
|
||||
→ `{message, level, seconds}`. `message` is 1 to 500 characters and not only spaces. `level` is `info` (the
|
||||
→ `{message, level, seconds}`. `message` is 1 to 500 characters and not only whitespace. `level` is `info` (the
|
||||
default), `success`, `warning` or `error`, and sets the color of the message's edge. `seconds` is how long it shows,
|
||||
0.5 to 60 (4 by default); a click on it closes it sooner. Messages stack at the window's bottom right, the newest
|
||||
lowest, at most 5 at once: a sixth closes the oldest. A message shows at most 6 lines, with the whole text on hover,
|
||||
and a stack taller than the window scrolls. A missing `message` or a value outside these ranges is an error,
|
||||
and nothing shows. The command edits no document and adds no undo step. Scripts raise one with `vc.run('app.toast',
|
||||
{...})`, a plug-in whose manifest lists `app.toast` calls it like its other commands, and an action recording records it as a step that shows the message again when the action plays. A session
|
||||
without a window (MCP, `vectorcraft-cli`) keeps the last 32 messages it was given and shows none. These limits are
|
||||
VectorCraft's own values.
|
||||
and a stack taller than the window scrolls. A missing `message` or a value outside these ranges is an error, and
|
||||
nothing shows. The command edits no document and adds no undo step. Scripts raise one with `vc.run('app.toast',
|
||||
{...})`. A plug-in calls it through `vc_call` under the conditions in [Plug-ins](#plug-ins): API level 2, the
|
||||
`commands` and `doc.read` permissions, and `app.toast` in its `commandAllowlist`. An action recording records it as a
|
||||
step that shows the message again when the action plays, except while a drag or typing is in progress, when no
|
||||
command is recorded. A script run that fails puts the documents back, and the messages it raised still show. The headless MCP server and `vectorcraft-cli run` have no window: they keep the last 32 messages they were
|
||||
given and show none. These limits are VectorCraft's own values.
|
||||
|
||||
```json
|
||||
{"name":"run_command","arguments":{"command":"app.toast","params":{"message":"Exported 4 artboards","level":"success"}}}
|
||||
|
||||
@@ -905,7 +905,6 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- Synthetic input validates complete gestures before queue mutation: at most 256 drag steps, 16 clicks and 1,024 pending events; up to 64 control requests per frame, with later requests retained for the next frame (#1709).
|
||||
- The control server writes each reply through a 64 KiB buffer. On Windows 11 it sends the 17 MB `document.inspect` reply of a document with 50,000 objects on one layer to a client over loopback in 0.09 s instead of 34 s.
|
||||
- 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`.
|
||||
- Messages over the window: `app.toast {message, level?, seconds?}` shows a message at the window's bottom right that does not stop work and closes after its time (4 seconds by default) or when clicked; at most 5 show at once, the newest lowest. Scripts raise one through `vc.run`, MCP clients through the command, and an action records it as a step. The limits are VectorCraft's own values. Tests: `cmd::toast::tests` in `vectorcraft-engine`, `toasts::tests` in `vectorcraft-ui-egui`.
|
||||
- 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 `$` 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`.
|
||||
@@ -922,6 +921,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- Scripts: `File` and `Folder` ([File object](https://extendscript.docsforadobe.dev/file-system-access/file-object/), [Folder object](https://extendscript.docsforadobe.dev/file-system-access/folder-object/)) name files and folders by platform or URI path, with `name`, `fsName`, `absoluteURI`, `relativeURI`, `parent`, `Folder.current` and `encode`/`decode`, and read them: `exists`, `length`, the dates, `getFiles` with a mask or a function, and `open('r')` with `read`, `readln`, `readch`, `seek`, `tell` and `close`, decoding by byte order mark, `encoding`, UTF-8 or CP1252. VectorCraft's own rules: a script reads only in its own folder and below (and inside the automation read roots when they are set); any other path and a network or device path are refused before anything is looked up, and a link that leads out is refused as well (`false` or `null`, with `error` set); a file is read whole up to 8 MiB and a run reads up to 32 MiB; writing, the file dialogs and `execute` are not available yet. `crates/engine/src/tests/script_io.rs`.
|
||||
- Scripts: `#strict on` (and `//@strict on`) runs the script with the checks the [`$` object](https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/) help page gives for `$.strict`: an assignment to a read-only property throws a `TypeError`, and so does a new property on an object that takes none. VectorCraft's own rules: a getter-only property counts as read-only, the objects that take no new properties are the non-extensible ones (`Object.preventExtensions`, `seal`, `freeze`, and the frozen `vc` and `$` objects), the last `#strict` line of the script and its includes sets the whole run, a file `$.evalFile` runs keeps its own line's checks for its code, and the rest of ES5 strict mode stays with `'use strict'`. Without the line, runs are unchanged. `crates/engine/src/tests/script_include.rs` (`strict_on_*`, `strict_mode_in_eval_file_is_scoped`), `crates/js/src/interp_tests.rs` (`strict_writes_are_separate_from_es5_strict`).
|
||||
- Scripts folder: File › Scripts lists the `.js` and `.jsx` files of the `Scripts` folder next to the preferences, each named after its file without the extension, with each subfolder as a submenu, above Check Script… and Other Script… (https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/automate-actions/install-and-run-scripts.html). VectorCraft's own rules: the folder is read again when the window becomes active and when the File menu opens (in the macOS menu bar, when any of its menus opens, and the new listing shows the next time the menu opens), links are not followed, and one read stops at 2,048 entries, 512 scripts, 128 subfolders, 4 levels or 250 ms. `script.listInstalled` returns the listing. `crates/engine/src/tests/script_folder.rs`, `crates/ui-egui/src/tests/scripts_menu.rs`.
|
||||
- Messages over the window: `app.toast {message, level?, seconds?}` shows a message at the window's bottom right that does not stop work and closes after its time (4 seconds by default) or when clicked; at most 5 show at once, the newest lowest. Scripts raise one through `vc.run`, MCP clients through the command, and an action records it as a step. The limits are VectorCraft's own values. Tests: `cmd::toast::tests` in `vectorcraft-engine`, `toasts::tests` in `vectorcraft-ui-egui`.
|
||||
- Open Recent Files under `--automation-read-root`: the control channel's `ui.menu.list` and `file.recentFiles` leave out the recent files outside the read roots, the other rows keep their ids, and `file.openRecentN` for one outside them answers `no such recent file`, as an empty slot does. `crates/ui-egui/src/tests/automation.rs`.
|
||||
- Saves, Export for Screens and Package under `--automation-read-root`: a save without a path leaves the document's own file out of its reply, and a save without a path known leaves out the suggested folder, when they are outside the read roots; Export for Screens into an export preset's folder outside them lists its files relative to that folder and names that folder by its name in an error, and the export settings and saved presets leave out a folder outside them when read or exported; Package's report and warnings, and Document Info's linked images, name a file outside them by its file name. A path the client gives stays in the reply. `crates/engine/src/tests/save.rs`, `crates/engine/src/cmd/fileio/tests_screens.rs`, `crates/engine/src/tests/package.rs`, `crates/ui-egui/src/tests/automation.rs`.
|
||||
- Errors under `--automation-read-root`: a refused save without a path and `file.revert` (also as an `action.batch` step), `script.listInstalled` and `links.relink {copy}` name the document's own file, the Scripts folder or the document's folder by its file name when it is outside the read roots, and keep the roots and the reason; `links.relink`'s copies name such a file by its file name too. A path the client gives stays whole. `crates/engine/src/tests/save.rs` (`pathless_save_rejection_hides_document_folder`), `crates/engine/src/cmd/fileio/action_batch.rs`, `crates/engine/src/tests/links.rs`, `crates/engine/src/tests/script_folder.rs`.
|
||||
|
||||
Reference in New Issue
Block a user