diff --git a/docs/HLSD/mcp-server.md b/docs/HLSD/mcp-server.md
index bc792345ca..1231339af8 100644
--- a/docs/HLSD/mcp-server.md
+++ b/docs/HLSD/mcp-server.md
@@ -63,7 +63,8 @@ application/json` (415) and the size cap (413). No CORS headers are sent, so bro
`McpProtocol` picks one of two protocol eras for each message.
- **Handshake era.** `initialize` echoes the client's version if it is 2025-11-25 or 2025-06-18,
- and answers 2025-11-25 otherwise. Then come `notifications/initialized`, `ping`, `tools/list`
+ and answers 2025-11-25 otherwise; the name it gives (`clientInfo.name`) names its calls in the Agent Activity
+ pane. Then come `notifications/initialized`, `ping`, `tools/list`
and `tools/call`. A present `MCP-Protocol-Version` header must be supported (400).
- **2026-07-28.** A request whose `params._meta` carries
`io.modelcontextprotocol/protocolVersion` is served without a handshake. `server/discover`
@@ -2404,7 +2405,7 @@ key, whatever its command is named), its title, its Speed Dial section (the item
come from several sections: `export_gcode` is in Slice & Export, `export_stl_multi` in Export), its icon and
the value its second phase collects (`input`). A person's pins and run counts are stored under the id, so the
ids of the menu items a released build stored stay the ids of actions. `tests/data/speed_dial_actions.json`
-holds the 129 actions (key, title, section, icon, input), and the unit test "every Speed Dial action of today
+holds the 130 actions (key, title, section, icon, input), and the unit test "every Speed Dial action of today
is still a command's action" finds each in the Speed Dial with that presentation and no other; "a menu item's id
is an action's key, not a command" holds that no menu item's id is a command's name.
@@ -3861,7 +3862,8 @@ is in neither. Recordings and screenshots show it as the person sees it, since c
shows, so its pulsing dot is in the frames and a recording never sees an idle window: each frame in which the
dot changed is queued.
-**Captions.** `McpCore` reports each call it runs to a `CallObserver`: when its handler starts, when
+**Captions.** `McpCore` reports each call it runs to its `CallObserver`s, the recorder and the activity log
+(see Agent Activity pane): when its handler starts, when
`set_journal_args()` replaces its arguments (refs become locators), and its final result (a job's,
worker job included). Calls refused before they run are not reported. The recorder captions calls
that are not `Inspect` (mutate and recover tools, replay steps included) as the tool's translated
@@ -4686,6 +4688,119 @@ doing. `tool_call {tool, args}` runs any command of the catalog, listed or not,
arguments are normalized and validated, and the call runs as the target's own, with its guard, mode, budget and
journal flag, so the journal records the target.
+## Agent Activity pane
+
+View › Agent Activity, a check item that is on while the pane is on screen, its Speed Dial action
+`toggle_agent_activity_panel` and the command `view_toggle_activity_panel`, which the tool list does not show, show or
+hide the Agent Activity pane (`AgentActivityPanel`, page `resources/web/dialog/AgentActivity/`). While it is open, it
+lists, live, every call automation makes in the app, reads included: an agent's, a run's from Action Replay, the Run Script panel or the
+command line (`--run`), and a plugin's, with the dialogs auto-answer rules answered and the agent's calls the protocol
+refused before they ran. A person's own picks from the Speed Dial and the menus are left out, with what they run. The
+pane only watches: it stops, pauses and exports nothing, and it opens only when a person opens it.
+
+**Origins.** Each call into the core says who made it, and `CallObserver::call_started()` gets that with the call's
+own job: `McpCore::call()` and `call_person()` take an origin, a JSON object whose `source` is `agent`,
+`action_replay`, `run_script`, `command_line`, `plugin` or `person`. The protocol gives an agent's: `client`, the name
+of the handshakes it answered while only one name has come since it was made, else empty (shown as "Agent"), since
+two clients' calls can't be told apart over stateless HTTP, and a 2026-07-28 call has no handshake; and `request`, the
+JSON-RPC message as it came, so a `tool_call` shows the wrapper and the command it names. The runtime's followed calls
+carry their front end's (`FollowedCall::origin`): Action Replay's runs, the Run Script panel's session, `--run`, and a
+person's recording's encode as the person's. `call_plugin()` gives `plugin` with the plugin's key, and `submit()`, a
+person's pick, `person`. A child call has none: its parent's job says where it comes from. A recording's encode that
+`recording_stop` starts names the stop's job as `under`, and is listed with the stop. The core tells each of its
+observers in turn. A call that runs as a job is also told as it is queued (`call_queued()`), on the thread that made
+it, right after its job is registered and before its thread starts: its parent, or the call it is `under`, still runs
+then. Every queued call is later ended, also one whose thread can't start or whose plugin unloaded before its handler.
+
+**The log.** `ActivityLog` (no wx) is an observer the runtime makes as it starts. It lists only while it records
+(`set_recording()`), which the pane turns on while the person has it open: docked while another tab is up and across a
+main-window rebuild too, off as they hide or close it and as the panel goes at exit. Nothing that comes while it is off
+is listed, but what it already lists still ends, the list stays until Clear list, and the log keeps what placing and
+masking later entries needs: the marks and the masking records below. An entry is a call, a dialog a rule answered, or a
+work of the Run Script panel, with its source and label, tool, arguments, request (an agent's message, else
+`{tool, args}` as the app runs the call), response (the final result's data, or `{isError, message, details}`; a job's
+once it ends), status, error, times, job and the entry it nests under. A replay whose step failed and a script that
+did not finish report success to their caller; the log reads their result and fails them, with the script's exception
+as the error, or else a `failure` the pane words in the UI's language: the failed step's number and error, or how the
+script ended (stopped, out of time, Python unavailable, not run), whose runner message is agent-facing English. A Run
+Script work's end reads the same way. It is numbered as Action Replay numbers its steps: the top-level calls and works count up, the entries
+under a run from 1, and a dialog takes no number. Every job call, listed or not, leaves marks by its job, set as it is
+queued and dropped as it ends: its run's source, client and plugin, or that it is a person's pick or a Run Script
+session. A child job copies its nearest marked ancestor's, which still runs then, so a run that outlives its parent keeps
+them. A child call nests under the nearest of its parent jobs that has an entry (`JobRegistry::ancestry()`), past any
+that has none; with no such job, its marks place it: a run that started before the pane opened lists its later calls at
+the top level under its own source, and a person's pick's calls stay out however late they come. A Run Script session
+has no entry of its own: each work the panel runs in it is one, which the panel reports as it submits the work
+(`work_started()`, the code its request) and as it ends (`work_ended()`: the Finished event's result or error, or a
+stop when its session ends without one or the panel lets the session go). A call the session makes goes under the work
+running at the time, or at the top level between works.
+
+The protocol reports a `tools/call` it refuses before the core sees it, for an unknown tool, arguments the schema
+refuses or a `tool_call` it can't resolve (`McpProtocol::set_on_refused()`), and the endpoint hands it to the log as a
+failed entry. Calls the core refuses (admission, blocking slots) are not reported, as they aren't to the recorder.
+`ModalTracker` reports each answer a rule gives (`set_on_answered()`, wherever a rule's `uses` grows) with the rule's
+layer; the runtime finds the run, plugin or client whose layer it is, and the log places the dialog's entry there. Each
+`dialog_auto_answer` call puts its rules in a layer of their own, which no later call changes (a client's next call
+replaces the layer). The runtime tells the log the layer and the call's job while it still holds the rules lock that an
+answer's report takes first (`rules_set()`), so no answer comes before it: an answer links the call that set its
+rules, and none when that call isn't listed, made while the log didn't record or dropped since. A client's answer
+carries the client of the call that set the rule. The log keeps a layer while its call is listed, and the latest others,
+up to 4000 layers in all.
+
+Arguments, requests, responses and errors are masked as captions are: `hidden_values()` gives what `caption_detail()`
+leaves out of a call (sensitive values, typed text, a value set into a field not found by its key, a page's
+JavaScript), and `mask_hidden()` replaces it, and every member of a sensitive key, by `•••`, inside longer text only
+from three characters on. A string that is JSON text (a replay given as its text) is read as JSON and, when that masks
+something, written out again masked, so what the text escapes is masked too. What nests arrays and objects deeper than
+64 levels, a payload or JSON text in one, is neither read nor shown (`•••`), since masking recurses through what it
+reads and nlohmann's copy recurses too, so the depth is checked before anything is copied; a job call whose arguments or
+result nest deeper has no masking record, and a call whose own arguments do shows no result, nor a dialog answered
+while it runs. A run whose result nests deeper is still failed when the fields that tell its outcome say so, which are
+read without going down the deep branches, but the pane words the failure without its reason. A replay hides what each
+of its steps hides, as written and with its placeholders put in by the replay engine's own substitution
+(`substitute_args_lenient()`, which leaves Python source as written, as a run does), and each value a placeholder in a
+hidden value puts in, directly or through another placeholder (a variable, an environment variable), with every string
+and number inside one that is an object or an array; the log has no saved jobs or folders, whose placeholders put in
+nothing secret. Variables that put each other in grow as the power of the nesting, so the log puts in at most 1 MiB for
+the replays written in one call and keeps the rest as written: what that cuts short only shows whole in a payload over
+32 KiB, which is shown by its size. A call
+that names a job (`app_wait`,
+`job_cancel`) also hides what that job's call hid, as the call ends. Every job call, listed or not, has a masking record
+from when it starts: what its arguments, their rewrite and its result hide, kept for the last 2000 job calls within
+4 MiB. A value longer than 32 KiB drops its record, since a shortened error could show part of it. A call naming a job
+with no record as it ends is `withheld`: it shows neither its response nor its error text, which may repeat that job's
+secrets. A dialog's title and message hide what the calls running as it is answered hide, also the start of a value a
+message ends in where `ModalTracker` cut it (from three bytes on, as written and escaped); past 10 000 such values or
+1 MiB of them, which would hold up the UI thread that reports the answer, the title and message are not shown. A
+payload over 32 KiB as JSON is `{truncated: true, bytes}`, unmasked since it shows nothing, and one, or an error, whose
+check would scan more than 256 MiB (values × length) is `•••`. The log keeps 2000 entries, dropping the oldest whose calls have all ended, with what is
+nested under them. Each change moves a version on: `changes_since()` gives the entries changed since a version and the
+ids dropped, or every entry with `reset` when the reader is too far behind or Clear list has run (`clear()`, which
+keeps what still runs and the masking records, and numbers from 1 again once nothing is left). The log
+calls its `changed` hook once until the next read, which the runtime posts to the UI thread for the pane, so nothing
+runs for it while no pane reads it. What an observer throws, the core drops, so the log never fails a call.
+
+**The pane.** A Plater dock pane, docked on the right of the 3D view at first (420 × 640 DIPs) and kept where the
+person moves it by the saved layout; its close button hides it. Docked it shows on Prepare and Preview, and showing it
+from another tab selects Prepare; floated it stays up on every tab, the Design tab included
+(`add_dock_pane(..., floats_on_every_tab)`). `GUI_App` owns `AgentActivityPanel`, which builds the pane again after a
+main-window rebuild, as the Run Script panel does. While the pane is on screen it reads the log's changes at most ten
+times a second and words them on the UI thread for its page: a call's translated title and target as the recording
+captions word them (`shown_title()`, `caption_detail()`), the source's label (the agent's name or "Agent", Action
+Replay, Run Script, Command line, the plugin's name), the effect tags Action Replay shows (`describe_step()`), and a
+screenshot's thumbnail. The page draws the rail Action Replay draws its steps with (`css/step_rail.css`): a read is a
+quiet line with a hollow dot, a change a filled one, a failure red with its reason, a running call a ringing dot with
+its job; a run and a Run Script work hold their own steps, shown while they run or once opened. An opened step shows
+its request and its response as JSON, laid out as the Run Script console lays out a result, with Copy, which the host
+puts on the clipboard. Everything, Changes or Failures, a source and Find a call filter the list. It follows the
+newest call until the person scrolls up, and then counts the calls that came below.
+
+**Out of the tools' reach.** As the Run Script panel's, the pane is named `kHiddenFromAutomation`, as is the frame it
+floats in (`AuiMgr::CreateFloatingFrame()`): `skipped_by_walks()` keeps the walks of `widget_list`, locators and
+`webview_run_javascript`'s search for a web view out of it, and `window_list` lists the floating frame as hidden, with
+no ref. Its page navigates nowhere but its own loads. Docked, the pane is part of the main window and shows in its
+screenshots and recordings; floating, it stays out of them, as the person's own dialogs do.
+
## stdio bridge
`orca-slicer --mcp-stdio [--datadir DIR] [--mcp-port N]` serves clients that speak only stdio,
@@ -4829,7 +4944,7 @@ In `tests/slic3rutils/`, the files of the same name hold the cases that need the
`test_mcp_core` a context with no runtime and an action's journal update; `test_mcp_protocol` the order of the
process catalog's `tools/list` and the tool families the stdio bridge lists; `test_command_catalog` the
process catalog itself: unique keys, the commands in their places' groups in the tool list's order,
-which are listed, the Speed Dial's 129 actions held as data in `tests/data/speed_dial_actions.json` (tagged
+which are listed, the Speed Dial's 130 actions held as data in `tests/data/speed_dial_actions.json` (tagged
`[SpeedDial]`: each found with its id, title, section, icon and input, every menu item's id an action's key and
no command, every action's arguments fitting its command's schema), the person's forms of the commands with
actions and what a pick of an action runs in place, the names of `retired_names.hpp`, which no command has, the
diff --git a/localization/i18n/list.txt b/localization/i18n/list.txt
index 76af19f504..542099a79a 100644
--- a/localization/i18n/list.txt
+++ b/localization/i18n/list.txt
@@ -128,6 +128,7 @@ src/slic3r/GUI/Jobs/UpgradeNetworkJob.cpp
src/slic3r/GUI/AboutDialog.cpp
src/slic3r/GUI/ActionRegistry.cpp
src/slic3r/GUI/ActionReplayDialog.cpp
+src/slic3r/GUI/AgentActivityPanel.cpp
src/slic3r/GUI/AMSMaterialsSetting.cpp
src/slic3r/GUI/ExtrusionCalibration.cpp
src/slic3r/GUI/AmsMappingPopup.cpp
diff --git a/resources/web/dialog/ActionReplay/index.html b/resources/web/dialog/ActionReplay/index.html
index 0c2962d6e8..42bbabd35a 100644
--- a/resources/web/dialog/ActionReplay/index.html
+++ b/resources/web/dialog/ActionReplay/index.html
@@ -6,6 +6,7 @@
Action Replay
+
diff --git a/resources/web/dialog/ActionReplay/style.css b/resources/web/dialog/ActionReplay/style.css
index dec9f1d5cb..dacc39a98f 100644
--- a/resources/web/dialog/ActionReplay/style.css
+++ b/resources/web/dialog/ActionReplay/style.css
@@ -1,29 +1,14 @@
/* Action Replay. Colours come from the host theme contract (--orca-*) and theme.css's status roles,
- * so the page follows the app in light and dark. The one distinctive element is the step rail: an
- * accent thread that fills down the list as steps pass. Everything else stays quiet and host-native. */
+ * so the page follows the app in light and dark. The one distinctive element is the step rail
+ * (../css/step_rail.css): an accent thread that fills down the list as steps pass. Everything else
+ * stays quiet and host-native. */
:root {
- --sr-bg: var(--orca-bg, #ffffff);
- --sr-fg: var(--orca-fg, #262e30);
- --sr-muted: var(--orca-muted, #6b7478);
- --sr-rule: var(--border, #dcdfe1);
- --sr-accent: var(--orca-accent, #009688);
- --sr-accent-fg: var(--orca-accent-fg, #ffffff);
- --sr-pass: var(--plugin-status-ok, #137333);
- --sr-fail: var(--plugin-status-danger, #b42318);
- --sr-fail-bg: var(--plugin-status-danger-bg, rgba(180, 35, 24, 0.12));
- --sr-warn: var(--plugin-status-warn, #a15c00);
- --sr-warn-bg: var(--plugin-status-warn-bg, rgba(199, 122, 22, 0.12));
- --sr-hover: var(--row-hover, #f7f9fb);
--sr-footer: var(--footer-bg, #fafafa);
--sr-btn-bg: var(--btn-bg, #ffffff);
--sr-btn-border: var(--btn-border, #cccccc);
--sr-btn-hover: var(--btn-hover, #f0f0f0);
--sr-accent-tint: var(--plugin-source-mine-bg, rgba(0, 150, 136, 0.12));
- --sr-ring: rgba(0, 150, 136, 0.25);
- --sr-ring-soft: rgba(0, 150, 136, 0.1);
- --sr-mono: var(--code-font);
- --sr-dot: 20px;
}
* { box-sizing: border-box; }
@@ -151,85 +136,11 @@ button:focus-visible, textarea:focus-visible { outline: 2px solid var(--sr-accen
/* ---- no steps yet ---- */
.steps-hint { margin: 0; padding: 12px 14px; color: var(--sr-muted); }
-/* ---- the step rail ---- */
-.rail { list-style: none; margin: 0; padding: 6px 0 10px; }
+/* ---- the step rail: what only Action Replay's steps have ---- */
/* The last steps that parsed, kept while the text doesn't, so typing doesn't empty the list. */
.rail.is-stale { opacity: 0.45; }
-.step {
- position: relative;
- display: grid;
- grid-template-columns: var(--sr-dot) minmax(0, 1fr) auto;
- column-gap: 10px;
- padding: 0 12px 0 14px;
-}
-/* The thread from this step's dot down to the next one; it takes the accent once the step passed. */
-.step::before {
- content: "";
- position: absolute;
- left: calc(14px + var(--sr-dot) / 2 - 1px);
- top: calc(6px + var(--sr-dot));
- bottom: -6px;
- width: 2px;
- background: var(--sr-rule);
- transition: background-color 240ms ease;
-}
-.step:last-child::before { display: none; }
-.step.is-done::before, .step.is-warn::before { background: var(--sr-accent); }
-.dot {
- margin-top: 6px;
- width: var(--sr-dot);
- height: var(--sr-dot);
- border-radius: 50%;
- border: 1.5px solid var(--sr-rule);
- background: var(--sr-bg);
- color: var(--sr-muted);
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 11px;
- font-variant-numeric: tabular-nums;
- position: relative;
- z-index: 1;
-}
-.step.is-done .dot { background: var(--sr-accent); border-color: var(--sr-accent); color: var(--sr-accent-fg); }
-.step.is-warn .dot { background: var(--sr-warn); border-color: var(--sr-warn); color: #ffffff; }
-.step.is-fail .dot, .step.is-stopped .dot { background: var(--sr-fail); border-color: var(--sr-fail); color: #ffffff; }
.step.is-skip .dot { border-style: dashed; }
-.step.is-running .dot { border-color: var(--sr-accent); color: var(--sr-accent); animation: sr-ring 1.4s ease-in-out infinite; }
-@keyframes sr-ring {
- 0%, 100% { box-shadow: 0 0 0 2px var(--sr-ring); }
- 50% { box-shadow: 0 0 0 5px var(--sr-ring-soft); }
-}
-
-.step-main { min-width: 0; }
-.step-head {
- display: block;
- width: 100%;
- padding: 6px 4px 6px 0;
- font: inherit;
- color: inherit;
- background: none;
- border: 0;
- text-align: left;
- cursor: pointer;
-}
-.step-title { font-weight: 600; }
.step.is-wait .step-title, .step.is-skip .step-title { font-weight: 400; color: var(--sr-muted); }
-.step-what, .step-args { display: block; color: var(--sr-muted); font-size: 12px; overflow-wrap: anywhere; }
-.step-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
-.tag {
- font-size: 11px;
- line-height: 16px;
- padding: 0 6px;
- border-radius: 3px;
- color: var(--sr-warn);
- background: var(--sr-warn-bg);
-}
-.tag.is-check { color: var(--sr-muted); background: none; border: 1px solid var(--sr-rule); }
-
-.step-side { display: flex; align-items: flex-start; gap: 6px; padding-top: 7px; }
-.time { font-size: 12px; color: var(--sr-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
-.step.is-running .time { color: var(--sr-accent); }
.play {
width: 20px;
height: 20px;
@@ -244,48 +155,12 @@ button:focus-visible, textarea:focus-visible { outline: 2px solid var(--sr-accen
opacity: 0;
}
.step:hover .play:not(:disabled), .play:focus-visible { opacity: 1; border-color: var(--sr-rule); }
-
-/* ---- an opened step ---- */
-.step-detail { padding: 2px 0 10px; font-size: 12px; }
-.step.is-open { background: var(--sr-hover); }
-.args { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; margin: 0 0 6px; }
-.args dt { color: var(--sr-muted); }
-.args dd { margin: 0; font-family: var(--sr-mono); font-size: 11.5px; overflow-wrap: anywhere; white-space: pre-wrap; }
.result-line { margin: 2px 0; }
.checks { list-style: none; margin: 0 0 6px; padding: 0; color: var(--sr-muted); }
.checks li { margin: 2px 0; overflow-wrap: anywhere; }
.checks li.is-met::before { content: "\2713\00a0"; color: var(--sr-pass); }
-.failure {
- margin: 4px 0 6px;
- padding: 6px 8px;
- border-left: 2px solid var(--sr-fail);
- border-radius: 0 3px 3px 0;
- background: var(--sr-fail-bg);
-}
-.step.is-warn .failure { border-left-color: var(--sr-warn); background: var(--sr-warn-bg); }
-.failure-detail { display: block; margin-top: 3px; color: var(--sr-muted); overflow-wrap: anywhere; }
.files { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0; }
-.thumb {
- display: block;
- width: 160px;
- max-width: 100%;
- border: 1px solid var(--sr-rule);
- border-radius: 3px;
- cursor: zoom-in;
-}
.actions { display: flex; gap: 12px; align-items: center; margin-top: 6px; }
-.raw {
- margin: 6px 0 0;
- max-height: 220px;
- overflow: auto;
- padding: 6px 8px;
- border: 1px solid var(--sr-rule);
- border-radius: 3px;
- font-family: var(--sr-mono);
- font-size: 11px;
- white-space: pre;
- user-select: text;
-}
/* ---- source editor ----
* Ace (../js/code_editor.js), filling the section; code_editor.css colours what is inside it. */
@@ -320,6 +195,5 @@ button:focus-visible, textarea:focus-visible { outline: 2px solid var(--sr-accen
.outcome-detail { font-size: 12px; color: var(--sr-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (prefers-reduced-motion: reduce) {
- .step.is-running .dot { animation: none; box-shadow: 0 0 0 2px var(--sr-ring); }
- .step::before, .chevron { transition: none; }
+ .chevron { transition: none; }
}
diff --git a/resources/web/dialog/AgentActivity/agent_activity.js b/resources/web/dialog/AgentActivity/agent_activity.js
new file mode 100644
index 0000000000..c2eabf8114
--- /dev/null
+++ b/resources/web/dialog/AgentActivity/agent_activity.js
@@ -0,0 +1,437 @@
+// The Agent Activity pane's page. The host (AgentActivityPanel) sends the activity log's entries as they change, with
+// their titles, targets and source labels in the UI's language; this page draws them as a step rail, filters them, and
+// asks the host to clear the list or copy a request or response.
+
+const M = AgentActivityModel;
+const MASK = "\u2022\u2022\u2022";
+
+const S = {
+ store: M.createStore(),
+ open: new Set(), // the entries the person opened
+ show: "all", // all | changes | failures
+ source: "all", // a sourceKey(), or all
+ find: "",
+ following: true, // the list follows the newest call until the person scrolls up
+ newBelow: 0, // calls that came while the person read further up
+ tree: { top: [], children: new Map() },
+};
+const rows = new Map(); // entry id -> its
+
+const ICON = {
+ agent: '',
+ action_replay: '',
+ run_script: '',
+ command_line: '',
+ plugin: '',
+ dialog: '',
+};
+
+function $(id) { return document.getElementById(id); }
+
+function send(command, extra) { SendWXMessage(JSON.stringify(Object.assign({ command }, extra || {}))); }
+
+function el(tag, className, text) {
+ const node = document.createElement(tag);
+ if (className) node.className = className;
+ if (text !== undefined) node.textContent = text;
+ return node;
+}
+
+// An icon from the fixed set above, never from an entry.
+function icon(name) {
+ const span = el("span", "icon");
+ span.innerHTML = ICON[name] || ICON.agent;
+ return span;
+}
+
+// ---- JSON, laid out as the Run Script console lays out a result ---------------------------------------------------
+
+function jsonBlock(value) {
+ const pre = el("pre", "raw");
+ if (M.truncated(value)) {
+ pre.className = "raw is-note";
+ pre.textContent = M.tr("too_large", "Too large to show here (%s bytes).", value.bytes);
+ return pre;
+ }
+ const shown = RunScriptModel.formatJson(JSON.stringify(value));
+ const tokens = RunScriptModel.jsonTokens(shown);
+ if (!tokens) {
+ pre.textContent = shown;
+ return pre;
+ }
+ for (const token of tokens) {
+ if (token.type === "space") pre.append(document.createTextNode(token.text));
+ else pre.append(el("span", "j-" + token.type + (token.text === '"' + MASK + '"' ? " mask" : ""), token.text));
+ }
+ return pre;
+}
+
+// ---- a step -------------------------------------------------------------------------------------------------------
+
+function makeRow(entry) {
+ const row = el("li", "step");
+ row.dataset.id = entry.id;
+ row.append(el("span", "dot"));
+ const main = el("div", "step-main");
+ const head = el("button", "step-head");
+ head.type = "button";
+ head.setAttribute("aria-expanded", "false");
+ head.append(el("span", "step-title"), el("span", "step-what"));
+ head.addEventListener("click", () => toggle(entry.id));
+ const nested = el("ol", "rail nested");
+ nested.hidden = true;
+ const detail = el("div", "step-detail");
+ detail.hidden = true;
+ main.append(head, el("div", "step-tags"), el("div", "failure"), nested, detail);
+ row.append(main, el("div", "step-side"));
+ return row;
+}
+
+function nestedOf(row) { return row.querySelector(":scope > .step-main > .rail.nested"); }
+
+function anyRunning(entry) {
+ return entry.status === "running" || (S.tree.children.get(entry.id) || []).some(anyRunning);
+}
+
+function renderRow(entry) {
+ const row = rows.get(entry.id);
+ const open = S.open.has(entry.id);
+ const children = S.tree.children.get(entry.id) || [];
+ const status = { running: "is-running", done: "is-done", failed: "is-fail" }[entry.status] || "is-done";
+ row.className = "step " + status + (entry.status !== "running" ? " is-ended" : "") + (entry.read ? " is-read" : "") +
+ (entry.kind === "dialog" ? " is-dialog" : "") + (open ? " is-open" : "") + (row.classList.contains("is-hidden") ? " is-hidden" : "") +
+ (row.classList.contains("is-last") ? " is-last" : "");
+
+ const dot = row.querySelector(":scope > .dot");
+ dot.textContent = "";
+ if (entry.kind === "dialog") dot.append(icon("dialog"));
+ else dot.textContent = entry.number ? String(entry.number) : "";
+ dot.title = entry.kind === "dialog" ? M.tr("dialog_answered", "A dialog a rule answered")
+ : entry.read ? M.tr("read_call", "A call that only reads") : M.tr("change_call", "A call that changes something");
+
+ const head = row.querySelector(":scope > .step-main > .step-head");
+ head.setAttribute("aria-expanded", String(open));
+ head.querySelector(".step-title").textContent = entry.title || entry.tool || "";
+ const what = head.querySelector(".step-what");
+ what.textContent = entry.what || "";
+ if (entry.kind === "dialog" && entry.request && entry.request.button) what.append(el("span", "pressed", entry.request.button));
+ if (entry.status === "running" && entry.job && !entry.read)
+ what.append(el("span", "res is-run", (entry.what ? " " : "") + M.tr("running_as_job", "running as job %s", entry.job)));
+
+ const tags = row.querySelector(":scope > .step-main > .step-tags");
+ tags.textContent = "";
+ // What a call does beyond the open project, labelled by the host as Action Replay's steps are ("flag_" + id).
+ for (const id of entry.flags || []) tags.append(el("span", "tag", M.tr("flag_" + id, id)));
+ tags.hidden = !tags.childNodes.length;
+
+ const failure = row.querySelector(":scope > .step-main > .failure");
+ failure.hidden = entry.status !== "failed" || !entry.error;
+ failure.textContent = entry.status === "failed" ? (entry.error || "").split("\n")[0] : "";
+
+ // A run's own steps, while it runs or once opened.
+ const nested = nestedOf(row);
+ nested.hidden = !children.length || !(open || anyRunning(entry));
+
+ const detail = row.querySelector(":scope > .step-main > .step-detail");
+ detail.hidden = !open;
+ if (open) fillDetail(detail, entry);
+
+ const side = row.querySelector(":scope > .step-side");
+ side.textContent = "";
+ if (!entry.parent || !S.store.has(entry.parent)) {
+ const src = el("span", "src");
+ src.title = entry.source_label || "";
+ src.append(el("span", "src-name", entry.source_label || ""), icon(entry.source));
+ side.append(src, el("span", "clock", M.clock(entry.started)));
+ }
+ side.append(el("span", "time", entry.kind === "dialog" ? "" : M.duration(M.elapsed(entry, Date.now()))));
+}
+
+function fillDetail(detail, entry) {
+ detail.textContent = "";
+ if (entry.kind === "dialog") {
+ const d = entry.request || {};
+ detail.append(el("div", "kv-head", M.tr("dialog", "Dialog")));
+ const dl = el("dl", "args plain");
+ for (const [key, fallback, value] of [["dialog_title", "Title", d.title], ["dialog_message", "Message", d.message], ["pressed", "Pressed", d.button]])
+ if (value) dl.append(el("dt", "", M.tr(key, fallback)), el("dd", "", value));
+ detail.append(dl);
+ const rule = M.ruleSetter(entry, S.store);
+ const ruleHead = el("div", "kv-head", M.tr("rule", "Rule"));
+ if (rule) {
+ ruleHead.append(el("span", "meta", M.tr("set_by", "set by call %s, %s", rule.number, rule.title || rule.tool)));
+ const show = el("button", "link", M.tr("show_call", "Show that call"));
+ show.type = "button";
+ show.addEventListener("click", () => reveal(rule.id));
+ ruleHead.append(show);
+ } else ruleHead.append(el("span", "meta", M.tr("rule_gone", "the call that set it isn't listed")));
+ detail.append(ruleHead);
+ const rl = el("dl", "args");
+ // The rule's own arguments, by their names.
+ rl.append(el("dt", "", "match"), el("dd", "", d.match || ""), el("dt", "", "button"), el("dd", "", d.button || ""));
+ detail.append(rl);
+ return;
+ }
+ const parent = S.store.get(entry.parent);
+ detail.append(section(M.tr("request", "Request"), M.requestNote(entry, parent && (parent.title || parent.tool)), entry.request,
+ M.tr("copy_request", "Copy request")));
+ const state = M.responseState(entry);
+ detail.append(section(M.tr("response", "Response"), M.responseNote(entry, Date.now()), state === "value" ? entry.response : undefined,
+ M.tr("copy_response", "Copy response"), state === "withheld"));
+ // The files its result names, as Action Replay lists a step's: a screenshot opens in the system's viewer, and each
+ // file shows in its folder. The host finds a file by the entry and its place in the list.
+ const files = entry.files || [];
+ if (files.length) {
+ const box = el("div", "files");
+ if (entry.thumb) {
+ const img = el("img", "thumb");
+ img.src = entry.thumb;
+ img.alt = files[0];
+ img.addEventListener("click", () => send("open_file", { id: entry.id, index: 0 }));
+ box.append(img);
+ }
+ files.forEach((name, index) => {
+ const link = el("button", "link", name);
+ link.type = "button";
+ link.title = M.tr("show_in_folder", "Show in folder");
+ link.addEventListener("click", () => send("show_file", { id: entry.id, index }));
+ box.append(link);
+ });
+ detail.append(box);
+ }
+}
+
+// A titled JSON block with its note and a Copy link; "Nothing yet." while a call has no response, and a note in place of
+// a response the host withheld.
+function section(title, note, value, copyLabel, withheld) {
+ const wrap = el("div", "kv");
+ const head = el("div", "kv-head", title);
+ head.append(el("span", "meta", note));
+ if (value !== undefined && !M.truncated(value)) {
+ const copy = el("button", "link", copyLabel);
+ copy.type = "button";
+ copy.addEventListener("click", (e) => {
+ e.stopPropagation();
+ send("copy", { text: JSON.stringify(value, null, 2) });
+ copy.textContent = M.tr("copied", "Copied");
+ setTimeout(() => { copy.textContent = copyLabel; }, 1200);
+ });
+ head.append(copy);
+ }
+ wrap.append(head, withheld ? el("p", "none", M.tr("withheld", "Can't be shown: it repeats a call whose record the pane no longer has."))
+ : value === undefined ? el("p", "none", M.tr("nothing_yet_response", "Nothing yet."))
+ : jsonBlock(value));
+ return wrap;
+}
+
+function toggle(id) {
+ if (S.open.has(id)) S.open.delete(id);
+ else S.open.add(id);
+ const entry = S.store.get(id);
+ if (entry) renderRow(entry);
+ refresh();
+}
+
+// Opens an entry and scrolls to it: the call a dialog's rule came from.
+function reveal(id) {
+ const entry = S.store.get(id);
+ if (!entry) return;
+ S.open.add(id);
+ const above = ancestors(entry);
+ for (const up of above) S.open.add(up.id);
+ for (const shown of [entry].concat(above)) renderRow(shown);
+ refresh();
+ S.following = false;
+ const row = rows.get(id);
+ const list = $("list");
+ if (row) list.scrollTop = row.getBoundingClientRect().top - list.getBoundingClientRect().top + list.scrollTop - 8;
+}
+
+function ancestors(entry) {
+ const out = [];
+ for (let up = S.store.get(entry.parent); up; up = S.store.get(up.parent)) out.push(up);
+ return out;
+}
+
+function atBottom(list) { return list.scrollHeight - list.scrollTop - list.clientHeight < 30; }
+
+// ---- the list -----------------------------------------------------------------------------------------------------
+
+function onEntries(msg) {
+ const list = $("list");
+ const wasAtBottom = atBottom(list);
+ const before = S.tree.top.length;
+ if (msg.reset) {
+ rows.clear();
+ $("rail").textContent = "";
+ S.open.clear();
+ }
+ for (const id of msg.removed || []) {
+ const row = rows.get(id);
+ if (row) row.remove();
+ rows.delete(id);
+ S.open.delete(id);
+ }
+ M.apply(S.store, msg);
+ S.tree = M.tree(S.store);
+ // A new row goes last under its parent, or at the end of the list: ids only grow.
+ const place = (entry) => {
+ if (!rows.has(entry.id)) rows.set(entry.id, makeRow(entry));
+ const row = rows.get(entry.id);
+ const host = entry.parent && rows.has(entry.parent) ? nestedOf(rows.get(entry.parent)) : $("rail");
+ if (row.parentNode !== host) host.append(row);
+ };
+ const changed = new Set((msg.entries || []).map((e) => e.id));
+ const walk = (entries) => {
+ for (const entry of entries) {
+ if (msg.reset || changed.has(entry.id) || !rows.has(entry.id)) place(entry);
+ walk(S.tree.children.get(entry.id) || []);
+ }
+ };
+ walk(S.tree.top);
+ // Each changed entry and, once each, the runs above them, whose running state and counts follow their steps.
+ const render = new Set();
+ for (const id of changed) {
+ const entry = S.store.get(id);
+ if (!entry) continue;
+ render.add(entry);
+ for (const up of ancestors(entry)) render.add(up);
+ }
+ for (const entry of render) renderRow(entry);
+ const following = S.following || wasAtBottom || msg.reset;
+ S.newBelow = following ? 0 : S.newBelow + Math.max(0, S.tree.top.length - before);
+ refresh();
+ if (following) list.scrollTop = list.scrollHeight;
+}
+
+// Which rows show, the thread's end, the source names that repeat, the toolbar.
+function refresh() {
+ const { shown, last } = M.visibility(S.tree, { show: S.show, source: S.source, find: S.find });
+ for (const [id, row] of rows) {
+ row.classList.toggle("is-hidden", !shown.has(id));
+ row.classList.toggle("is-last", last.has(id));
+ }
+ let previous = null;
+ for (const entry of S.tree.top) {
+ if (!shown.has(entry.id)) continue;
+ const src = rows.has(entry.id) ? rows.get(entry.id).querySelector(":scope > .step-side .src") : null;
+ if (src) src.classList.toggle("same", entry.source_label === previous);
+ previous = entry.source_label;
+ }
+ const empty = $("empty");
+ empty.hidden = S.tree.top.some((e) => shown.has(e.id));
+ empty.textContent = S.tree.top.length ? M.tr("no_match", "No call matches.")
+ : M.tr("empty", "Calls from agents, Action Replay, Run Script and plugins appear here as they run.");
+ $("latest").hidden = !S.newBelow;
+ $("latest-n").textContent = M.tr("new_calls", "New calls: %s", S.newBelow);
+ renderToolbar();
+}
+
+function renderToolbar() {
+ document.querySelectorAll(".seg button").forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.show === S.show)));
+ const sources = M.sources(S.tree.top);
+ const picked = sources.find((s) => s.key === S.source);
+ if (S.source !== "all" && !picked) S.source = "all";
+ $("src-label").textContent = picked ? picked.label : M.tr("everyone", "Everyone");
+
+ const status = M.status(S.tree.top);
+ const counts = M.counts(S.tree.top);
+ const box = $("status");
+ box.textContent = "";
+ const who = el("span", status.busy ? "is-busy" : "");
+ who.append(el("span", "sdot"), el("span", "who", status.text));
+ box.append(who, el("span", "counts", M.tr("calls", "Calls: %s", counts.calls)));
+ if (counts.failed) {
+ const failed = el("button", "nfail", M.tr("failed", "Failed: %s", counts.failed));
+ failed.type = "button";
+ failed.addEventListener("click", () => setShow("failures"));
+ box.append(failed);
+ }
+}
+
+function setShow(show) {
+ S.show = show;
+ refresh();
+}
+
+function renderSourceMenu() {
+ const menu = $("src-menu");
+ menu.textContent = "";
+ const items = [{ key: "all", label: M.tr("everyone", "Everyone"), count: S.tree.top.length }].concat(M.sources(S.tree.top));
+ for (const item of items) {
+ const b = el("button");
+ b.type = "button";
+ b.setAttribute("role", "menuitemradio");
+ b.setAttribute("aria-checked", String(S.source === item.key));
+ b.append(el("span", "tick", S.source === item.key ? "✓" : ""));
+ if (item.source) b.append(icon(item.source));
+ b.append(el("span", "label", item.label), el("span", "mc", String(item.count)));
+ b.addEventListener("click", () => {
+ S.source = item.key;
+ closeSourceMenu();
+ refresh();
+ });
+ menu.append(b);
+ }
+}
+
+function closeSourceMenu() {
+ $("src-menu").hidden = true;
+ $("src-btn").setAttribute("aria-expanded", "false");
+}
+
+// The running calls' durations, four times a second.
+function tick() {
+ const now = Date.now();
+ for (const [id, row] of rows) {
+ const entry = S.store.get(id);
+ if (!entry || entry.status !== "running") continue;
+ const time = row.querySelector(":scope > .step-side .time");
+ if (time) time.textContent = M.duration(now - entry.started);
+ }
+}
+
+// ---- host messages ------------------------------------------------------------------------------------------------
+
+function HandleStudio(msg) {
+ switch (msg.command) {
+ case "entries": onEntries(msg); break;
+ }
+}
+
+function OnInit() {
+ TranslatePage();
+ $("clear").addEventListener("click", () => send("clear"));
+ document.querySelectorAll(".seg button").forEach((b) => b.addEventListener("click", () => setShow(b.dataset.show)));
+ $("src-btn").addEventListener("click", (e) => {
+ e.stopPropagation();
+ const menu = $("src-menu");
+ if (!menu.hidden) return closeSourceMenu();
+ renderSourceMenu();
+ menu.hidden = false;
+ $("src-btn").setAttribute("aria-expanded", "true");
+ });
+ document.addEventListener("click", (e) => { if (!$("src-menu").contains(e.target)) closeSourceMenu(); });
+ document.addEventListener("keydown", (e) => { if (e.key === "Escape") closeSourceMenu(); });
+ $("find").addEventListener("input", () => {
+ S.find = $("find").value;
+ refresh();
+ });
+ const list = $("list");
+ list.addEventListener("scroll", () => {
+ S.following = atBottom(list);
+ if (S.following && S.newBelow) {
+ S.newBelow = 0;
+ $("latest").hidden = true;
+ }
+ });
+ $("latest").addEventListener("click", () => {
+ S.following = true;
+ S.newBelow = 0;
+ list.scrollTop = list.scrollHeight;
+ $("latest").hidden = true;
+ });
+ setInterval(tick, 250);
+ refresh();
+ send("ready");
+}
diff --git a/resources/web/dialog/AgentActivity/agent_activity_model.js b/resources/web/dialog/AgentActivity/agent_activity_model.js
new file mode 100644
index 0000000000..07c26e0e18
--- /dev/null
+++ b/resources/web/dialog/AgentActivity/agent_activity_model.js
@@ -0,0 +1,188 @@
+// The Agent Activity page's pure logic: the host's entries merged into one list and nested by run, what the filters
+// show, what the toolbar counts and names, and the times and notes a step shows. Loaded by the page as a script and by
+// agent_activity_model.test.js as a module.
+(function (root, factory) {
+ "use strict";
+ const api = factory();
+ if (typeof module === "object" && module.exports) module.exports = api;
+ else root.AgentActivityModel = api;
+})(typeof globalThis === "object" ? globalThis : this, function () {
+ "use strict";
+
+ // The page's T() (i18n.js) where it is loaded; the English with its %s filled in a test.
+ function tr(key, fallback, ...args) {
+ if (typeof T === "function") return T(key, fallback, ...args);
+ let text = fallback;
+ args.forEach((arg) => { text = text.replace("%s", () => String(arg)); });
+ return text;
+ }
+
+ // ---- the list ----------------------------------------------------------------------------------------------------
+
+ // The entries by id. apply() merges a host message {reset, entries, removed}: with reset, what the host sends is all
+ // there is.
+ function createStore() { return new Map(); }
+ function apply(store, msg) {
+ if (msg.reset) store.clear();
+ for (const entry of msg.entries || []) store.set(entry.id, entry);
+ for (const id of msg.removed || []) store.delete(id);
+ }
+
+ // The top-level entries oldest first, and the entries nested under each id, oldest first. An entry whose parent is
+ // gone stands at the top level.
+ function tree(store) {
+ const top = [];
+ const children = new Map();
+ const ids = Array.from(store.keys()).sort((a, b) => a - b);
+ for (const id of ids) {
+ const entry = store.get(id);
+ if (entry.parent && store.has(entry.parent)) {
+ if (!children.has(entry.parent)) children.set(entry.parent, []);
+ children.get(entry.parent).push(entry);
+ } else top.push(entry);
+ }
+ return { top, children };
+ }
+
+ // ---- filters -----------------------------------------------------------------------------------------------------
+
+ // What the source menu sorts by: a plugin's entries by the plugin.
+ function sourceKey(entry) { return entry.source === "plugin" ? "plugin:" + (entry.plugin || "") : entry.source || ""; }
+
+ // Whether `entry`, or an entry nested under it, passes Everything / Changes / Failures and Find a call. A dialog a rule
+ // answered changed something: a button was pressed.
+ function matches(entry, filter, children) {
+ const find = (filter.find || "").trim().toLowerCase();
+ const self = (filter.show === "all" || !filter.show || (filter.show === "changes" && !entry.read) ||
+ (filter.show === "failures" && entry.status === "failed")) &&
+ (!find || [entry.title, entry.what, entry.tool, entry.source_label].join(" ").toLowerCase().includes(find));
+ return self || (children.get(entry.id) || []).some((c) => matches(c, filter, children));
+ }
+
+ // Whether a top-level entry shows: its source is the one the menu picked, and it matches.
+ function showsAtTop(entry, filter, children) {
+ return (!filter.source || filter.source === "all" || sourceKey(entry) === filter.source) && matches(entry, filter, children);
+ }
+
+ // Whether an entry nested under a shown one shows: all of them under Everything with nothing to find, else those
+ // that match.
+ function showsNested(entry, filter, children) {
+ return ((filter.show === "all" || !filter.show) && !(filter.find || "").trim()) || matches(entry, filter, children);
+ }
+
+ // Which entries show under `filter`, and which shown entry ends its list, where its thread stops: {shown, last}, sets of
+ // ids. A top-level entry shows by showsAtTop(), an entry nested under a shown one by showsNested(), at any depth.
+ function visibility(tree, filter) {
+ const shown = new Set();
+ const last = new Set();
+ const walk = (entries, top) => {
+ let end = null;
+ for (const entry of entries) {
+ if (!(top ? showsAtTop(entry, filter, tree.children) : showsNested(entry, filter, tree.children))) continue;
+ shown.add(entry.id);
+ end = entry;
+ walk(tree.children.get(entry.id) || [], false);
+ }
+ if (end) last.add(end.id);
+ };
+ walk(tree.top, true);
+ return { shown, last };
+ }
+
+ // ---- the toolbar -------------------------------------------------------------------------------------------------
+
+ // The calls listed at the top level, which the last number counts, and how many of them failed. A dialog is no call.
+ function counts(top) {
+ const calls = top.filter((e) => e.kind !== "dialog");
+ return { calls: calls.length, failed: calls.filter((e) => e.status === "failed").length };
+ }
+
+ // The sources of the top-level entries, in the order they first came, with their labels and how many entries each.
+ function sources(top) {
+ const out = new Map();
+ for (const entry of top) {
+ const key = sourceKey(entry);
+ if (!out.has(key)) out.set(key, { key, source: entry.source, label: entry.source_label || "", count: 0 });
+ const item = out.get(key);
+ ++item.count;
+ // The newest label: an agent's name may have become "Agent" since.
+ if (entry.source_label) item.label = entry.source_label;
+ }
+ return Array.from(out.values());
+ }
+
+ // What the status says: who works now (the newest running top-level entry's source), else whether anything ran.
+ function status(top) {
+ const running = top.filter((e) => e.status === "running");
+ if (running.length) return { busy: true, text: tr("working", "%s is working", running[running.length - 1].source_label) };
+ return { busy: false, text: top.length ? tr("idle", "Idle") : tr("nothing_yet", "Nothing yet") };
+ }
+
+ // ---- a step ------------------------------------------------------------------------------------------------------
+
+ // A duration: tenths of a second under ten seconds, then whole seconds, then minutes and seconds.
+ function duration(ms) {
+ const s = Math.max(0, ms) / 1000;
+ if (s < 60) return tr("seconds", "%s s", s < 10 ? s.toFixed(1) : Math.floor(s));
+ return tr("minutes_seconds", "%s min %s s", Math.floor(s / 60), Math.floor(s % 60));
+ }
+
+ // The time of day `ms` (since the epoch) was, as hours, minutes and seconds.
+ function clock(ms) {
+ const d = new Date(ms);
+ const two = (n) => String(n).padStart(2, "0");
+ return `${two(d.getHours())}:${two(d.getMinutes())}:${two(d.getSeconds())}`;
+ }
+
+ function elapsed(entry, now) { return (entry.ended || now) - entry.started; }
+
+ // Calls a person sees run for longer than this ran as a job the agent was told to wait for.
+ const LONG_MS = 1500;
+
+ // The note beside Response: how the call answered, or that it still runs.
+ function responseNote(entry, now) {
+ const took = duration(elapsed(entry, now));
+ if (entry.status === "running")
+ return entry.job ? tr("running_no_result", "running as job %s; no result yet", entry.job) : tr("waiting_reply", "waiting for the reply");
+ if (entry.status === "failed") return tr("failed_after", "failed after %s", took);
+ if (entry.job && elapsed(entry, now) > LONG_MS) return tr("ran_as_job", "ran as job %s; finished after %s", entry.job, took);
+ return tr("answered_in", "answered in %s", took);
+ }
+
+ // Whether an agent's request went through tool_call, the tool for commands the tool list leaves out.
+ function viaToolCall(entry) {
+ const params = entry.request && entry.request.params;
+ return !!params && params.name === "tool_call";
+ }
+
+ // The note beside Request: where it came from.
+ function requestNote(entry, parentTitle) {
+ const at = clock(entry.started);
+ if (entry.parent && parentTitle) return tr("made_by", "made by %s", parentTitle);
+ if (entry.kind === "work") return tr("work_at", "run in the Run Script panel at %s", at);
+ if (entry.source === "agent" && entry.request && entry.request.method === "tools/call")
+ return viaToolCall(entry) ? tr("tools_call_via", "tools/call from %s through tool_call, at %s", entry.source_label, at)
+ : tr("tools_call_from", "tools/call from %s at %s", entry.source_label, at);
+ return tr("sent_at", "sent at %s", at);
+ }
+
+ // What an entry's Response section shows: "withheld" when the host can't show it (it repeats a job's result whose masking
+ // record the host no longer has), "pending" while there is none yet, else "value".
+ function responseState(entry) {
+ if (entry.withheld === true) return "withheld";
+ return entry.response === null || entry.response === undefined ? "pending" : "value";
+ }
+
+ // The entry of the call that set the rule a dialog's answer came from, or null when the list doesn't hold it.
+ function ruleSetter(entry, store) {
+ return (entry.rule && store.get(entry.rule)) || null;
+ }
+
+ // A request or response the host left out for its size: {truncated: true, bytes}.
+ function truncated(value) {
+ return !!value && typeof value === "object" && value.truncated === true && typeof value.bytes === "number" && Object.keys(value).length === 2;
+ }
+
+ return { tr, createStore, apply, tree, sourceKey, matches, showsAtTop, showsNested, visibility, counts, sources, status, duration, clock,
+ elapsed, responseNote, requestNote, viaToolCall, responseState, ruleSetter, truncated };
+});
diff --git a/resources/web/dialog/AgentActivity/agent_activity_model.test.js b/resources/web/dialog/AgentActivity/agent_activity_model.test.js
new file mode 100644
index 0000000000..3f0bdec502
--- /dev/null
+++ b/resources/web/dialog/AgentActivity/agent_activity_model.test.js
@@ -0,0 +1,144 @@
+"use strict";
+const { test } = require("node:test");
+const assert = require("node:assert/strict");
+const model = require("./agent_activity_model.js");
+
+// An entry as the host sends it, with what a test leaves out filled in.
+function entry(fields) {
+ return Object.assign({ id: 1, parent: 0, number: 1, kind: "call", source: "agent", source_label: "Claude Code", plugin: "",
+ tool: "app_state", title: "Get app state", what: "", read: false, status: "done", error: "", job: "",
+ started: 1000, ended: 1200, request: {}, response: {}, rule: 0 }, fields);
+}
+
+test("the host's changes merge into the list, and a reset starts it over", () => {
+ const store = model.createStore();
+ model.apply(store, { reset: true, entries: [entry({ id: 1 }), entry({ id: 2, status: "running" })] });
+ model.apply(store, { entries: [entry({ id: 2, status: "done" }), entry({ id: 3 })], removed: [1] });
+ assert.deepEqual(Array.from(store.keys()).sort(), [2, 3]);
+ assert.equal(store.get(2).status, "done");
+ model.apply(store, { reset: true, entries: [entry({ id: 9 })] });
+ assert.deepEqual(Array.from(store.keys()), [9]);
+});
+
+test("a run's steps nest under it in order, and a step whose run is gone stands at the top", () => {
+ const store = model.createStore();
+ model.apply(store, { entries: [entry({ id: 5, parent: 1 }), entry({ id: 1 }), entry({ id: 3, parent: 1 }), entry({ id: 7, parent: 4 })] });
+ const { top, children } = model.tree(store);
+ assert.deepEqual(top.map((e) => e.id), [1, 7]);
+ assert.deepEqual(children.get(1).map((e) => e.id), [3, 5]);
+});
+
+test("Changes leaves out reads, Failures shows failed calls, and a run shows when one of its steps matches", () => {
+ const store = model.createStore();
+ model.apply(store, { entries: [
+ entry({ id: 1, read: true }),
+ entry({ id: 2, title: "Slice", what: "Plate 1" }),
+ entry({ id: 3, tool: "replay_run", title: "Run a replay" }),
+ entry({ id: 4, parent: 3, title: "Export", status: "failed", error: "Disk full" }),
+ entry({ id: 5, kind: "dialog", title: "Answered a dialog", read: false }),
+ ] });
+ const { top, children } = model.tree(store);
+ const shown = (filter) => top.filter((e) => model.showsAtTop(e, filter, children)).map((e) => e.id);
+ assert.deepEqual(shown({ show: "all" }), [1, 2, 3, 5]);
+ assert.deepEqual(shown({ show: "changes" }), [2, 3, 5]);
+ assert.deepEqual(shown({ show: "failures" }), [3]);
+ assert.deepEqual(shown({ show: "all", find: "plate 1" }), [2]);
+ assert.deepEqual(shown({ show: "all", find: "EXPORT" }), [3]);
+ // Under a shown run, Everything with nothing to find shows every step; otherwise the ones that match.
+ const step = store.get(4);
+ assert.equal(model.showsNested(step, { show: "all" }, children), true);
+ assert.equal(model.showsNested(step, { show: "changes", find: "slice" }, children), false);
+});
+
+test("the source menu lists each source once with its newest label, and a plugin's entries by plugin", () => {
+ const store = model.createStore();
+ model.apply(store, { entries: [
+ entry({ id: 1, source: "agent", source_label: "Claude Code" }),
+ entry({ id: 2, source: "plugin", plugin: "brim", source_label: "Brim Ears" }),
+ entry({ id: 3, source: "agent", source_label: "Agent" }),
+ entry({ id: 4, source: "plugin", plugin: "fill", source_label: "Fill" }),
+ entry({ id: 5, parent: 2, source: "plugin", plugin: "brim", source_label: "Brim Ears" }),
+ ] });
+ const { top, children } = model.tree(store);
+ assert.deepEqual(model.sources(top).map((s) => [s.key, s.label, s.count]),
+ [["agent", "Agent", 2], ["plugin:brim", "Brim Ears", 1], ["plugin:fill", "Fill", 1]]);
+ assert.deepEqual(top.filter((e) => model.showsAtTop(e, { show: "all", source: "plugin:brim" }, children)).map((e) => e.id), [2]);
+});
+
+test("the counts are of top-level calls, without dialogs, and the status names who works", () => {
+ const top = [entry({ id: 1 }), entry({ id: 2, status: "failed" }), entry({ id: 3, kind: "dialog" }),
+ entry({ id: 4, status: "running", source_label: "Action Replay" })];
+ assert.deepEqual(model.counts(top), { calls: 3, failed: 1 });
+ assert.deepEqual(model.status(top), { busy: true, text: "Action Replay is working" });
+ assert.deepEqual(model.status([entry({ id: 1 })]), { busy: false, text: "Idle" });
+ assert.deepEqual(model.status([]), { busy: false, text: "Nothing yet" });
+});
+
+test("durations read in tenths, seconds, then minutes", () => {
+ assert.equal(model.duration(420), "0.4 s");
+ assert.equal(model.duration(12400), "12 s");
+ assert.equal(model.duration(125000), "2 min 5 s");
+});
+
+test("the response note says how the call answered, or that it still runs", () => {
+ const now = 10000;
+ assert.equal(model.responseNote(entry({ started: 1000, ended: 1300 }), now), "answered in 0.3 s");
+ assert.equal(model.responseNote(entry({ job: "j4", started: 1000, ended: 9000 }), now), "ran as job j4; finished after 8.0 s");
+ assert.equal(model.responseNote(entry({ job: "j4", status: "running", ended: 0 }), now), "running as job j4; no result yet");
+ assert.equal(model.responseNote(entry({ status: "running", ended: 0 }), now), "waiting for the reply");
+ assert.equal(model.responseNote(entry({ status: "failed", started: 1000, ended: 1500 }), now), "failed after 0.5 s");
+});
+
+test("the request note names an agent's tools/call, through tool_call where it went, and a step's run", () => {
+ const started = new Date(2026, 10, 23, 14, 2, 5).getTime();
+ const call = entry({ started, request: { jsonrpc: "2.0", id: 3, method: "tools/call", params: { name: "plate_slice" } } });
+ assert.equal(model.requestNote(call), "tools/call from Claude Code at 14:02:05");
+ const wrapped = entry({ started, request: { jsonrpc: "2.0", id: 4, method: "tools/call", params: { name: "tool_call", arguments: { tool: "sketch_create" } } } });
+ assert.equal(model.requestNote(wrapped), "tools/call from Claude Code through tool_call, at 14:02:05");
+ assert.equal(model.requestNote(entry({ parent: 2 }), "Run a replay"), "made by Run a replay");
+ assert.equal(model.requestNote(entry({ started, kind: "work", source: "run_script" })), "run in the Run Script panel at 14:02:05");
+});
+
+test("a payload the host left out for its size is told apart from one that only looks like it", () => {
+ assert.equal(model.truncated({ truncated: true, bytes: 40000 }), true);
+ assert.equal(model.truncated({ truncated: true, bytes: 40000, extra: 1 }), false);
+ assert.equal(model.truncated({ truncated: "yes", bytes: 1 }), false);
+ assert.equal(model.truncated(null), false);
+});
+
+test("the filters reach every depth: a replay's script's steps show or hide by their own match", () => {
+ const store = model.createStore();
+ model.apply(store, { entries: [
+ entry({ id: 1, tool: "replay_run", title: "Run a replay" }),
+ entry({ id: 2, parent: 1, tool: "script_run", title: "Run a Python script" }),
+ entry({ id: 3, parent: 2, read: true, title: "List objects" }),
+ entry({ id: 4, parent: 2, title: "Export", status: "failed", error: "Disk full" }),
+ entry({ id: 5, read: true, title: "Get app state" }),
+ ] });
+ const tree = model.tree(store);
+ const failures = model.visibility(tree, { show: "failures" });
+ assert.deepEqual(Array.from(failures.shown).sort(), [1, 2, 4]);
+ assert.deepEqual(Array.from(failures.last).sort(), [1, 2, 4]); // each list's last shown entry
+ const all = model.visibility(tree, { show: "all" });
+ assert.deepEqual(Array.from(all.shown).sort(), [1, 2, 3, 4, 5]);
+ assert.deepEqual(Array.from(all.last).sort(), [2, 4, 5]);
+ const changes = model.visibility(tree, { show: "changes" });
+ assert.equal(changes.shown.has(3), false);
+ assert.equal(changes.shown.has(5), false);
+});
+
+test("a withheld response is told by the entry, not by what the response holds", () => {
+ assert.equal(model.responseState(entry({ withheld: true, response: null })), "withheld");
+ assert.equal(model.responseState(entry({ withheld: false, response: { withheld: true } })), "value");
+ assert.equal(model.responseState(entry({ status: "running", response: null })), "pending");
+ assert.equal(model.responseState(entry({ response: { ok: true } })), "value");
+});
+
+test("a dialog's rule links the call that set it only while the list holds that call", () => {
+ const store = model.createStore();
+ model.apply(store, { entries: [entry({ id: 4, tool: "dialog_auto_answer" }), entry({ id: 6, kind: "dialog", rule: 4 })] });
+ assert.equal(model.ruleSetter(store.get(6), store).id, 4);
+ assert.equal(model.ruleSetter(entry({ kind: "dialog", rule: 0 }), store), null);
+ model.apply(store, { entries: [], removed: [4] });
+ assert.equal(model.ruleSetter(store.get(6), store), null);
+});
diff --git a/resources/web/dialog/AgentActivity/index.html b/resources/web/dialog/AgentActivity/index.html
new file mode 100644
index 0000000000..016c703e56
--- /dev/null
+++ b/resources/web/dialog/AgentActivity/index.html
@@ -0,0 +1,41 @@
+
+
+
+
+
+ Agent Activity
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/web/dialog/AgentActivity/style.css b/resources/web/dialog/AgentActivity/style.css
new file mode 100644
index 0000000000..418dc3a889
--- /dev/null
+++ b/resources/web/dialog/AgentActivity/style.css
@@ -0,0 +1,239 @@
+/* Agent Activity. The step rail comes from ../css/step_rail.css, as Action Replay's; this adds the toolbar, a read's
+ * quiet line, a dialog's step, the nested steps of a run, and the request and response under an opened step. Colours
+ * come from the host theme contract (--orca-*), theme.css's status roles and code_editor.css's JSON colours. */
+
+:root {
+ --aa-tint: var(--plugin-source-mine-bg, rgba(0, 150, 136, 0.12));
+ --aa-accent-text: var(--plugin-source-mine-text, #00897b);
+ --aa-btn-bg: var(--btn-bg, #ffffff);
+ --aa-btn-border: var(--btn-border, #cccccc);
+ --aa-btn-hover: var(--btn-hover, #f0f0f0);
+ --aa-menu-bg: var(--ctx-bg, #ffffff);
+}
+:root[data-orca-theme="dark"] { --aa-accent-text: #4db6ac; }
+
+* { box-sizing: border-box; }
+
+html, body {
+ height: 100%;
+ margin: 0;
+ overflow: hidden;
+ background: var(--sr-bg);
+ color: var(--sr-fg);
+ font-family: var(--orca-font, "Segoe UI", system-ui, sans-serif);
+ font-size: 13px;
+ line-height: 1.4;
+}
+
+[hidden] { display: none !important; }
+button:focus-visible, input:focus-visible { outline: 2px solid var(--sr-accent); outline-offset: 1px; }
+
+.pane { height: 100%; display: flex; flex-direction: column; container-type: inline-size; container-name: pane; }
+
+/* ---- toolbar, as the Run Script panel's ---- */
+.toolbar { flex: none; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--sr-rule); }
+.btn {
+ font: inherit;
+ font-size: 12.5px;
+ color: var(--sr-fg);
+ background: var(--aa-btn-bg);
+ border: 1px solid var(--aa-btn-border);
+ border-radius: 4px;
+ padding: 2px 10px;
+ height: 24px;
+ cursor: pointer;
+ white-space: nowrap;
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+}
+.btn svg { width: 10px; height: 10px; flex: none; }
+.btn:hover:not(:disabled) { background: var(--aa-btn-hover); }
+.tsep { width: 1px; height: 16px; background: var(--sr-rule); margin: 0 2px; }
+.seg { display: inline-flex; border: 1px solid var(--aa-btn-border); border-radius: 4px; overflow: hidden; height: 24px; }
+.seg button { font: inherit; font-size: 12px; border: 0; background: var(--aa-btn-bg); color: var(--sr-fg); padding: 0 9px; cursor: pointer; }
+.seg button + button { border-left: 1px solid var(--aa-btn-border); }
+.seg button[aria-pressed="true"] { background: var(--aa-tint); color: var(--aa-accent-text); font-weight: 600; }
+.menu-wrap { position: relative; }
+.menu {
+ position: absolute;
+ z-index: 20;
+ top: calc(100% + 4px);
+ left: 0;
+ min-width: 200px;
+ max-width: 280px;
+ background: var(--aa-menu-bg);
+ border: 1px solid var(--aa-btn-border);
+ border-radius: 4px;
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
+ padding: 4px;
+}
+.menu button {
+ width: 100%;
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ border: 0;
+ background: none;
+ color: var(--sr-fg);
+ padding: 5px 8px;
+ border-radius: 3px;
+ cursor: pointer;
+ font: inherit;
+ font-size: 12.5px;
+ text-align: left;
+}
+.menu button:hover { background: var(--sr-hover); }
+.menu .label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.menu .mc { margin-left: auto; color: var(--sr-muted); font-variant-numeric: tabular-nums; }
+.menu .tick { width: 12px; flex: none; color: var(--aa-accent-text); }
+.menu .icon { color: var(--sr-muted); }
+.find {
+ height: 24px;
+ width: 150px;
+ font: inherit;
+ font-size: 12.5px;
+ color: var(--sr-fg);
+ background: var(--sr-bg);
+ border: 1px solid var(--aa-btn-border);
+ border-radius: 4px;
+ padding: 0 8px;
+}
+.find::placeholder { color: var(--sr-muted); }
+.status { margin-left: auto; min-width: 0; display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--sr-muted); white-space: nowrap; }
+.status .sdot { width: 7px; height: 7px; border-radius: 50%; background: var(--sr-muted); opacity: 0.5; display: inline-block; margin-right: 5px; }
+.status .is-busy .sdot { background: var(--aa-accent-text); opacity: 1; animation: aa-pulse 1.2s ease-in-out infinite; }
+.status .who { color: var(--sr-fg); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
+.status > span:first-child { min-width: 0; display: inline-flex; align-items: center; }
+.status .nfail {
+ font: inherit;
+ font-size: 12px;
+ color: var(--sr-fail);
+ border: 0;
+ background: none;
+ padding: 0;
+ cursor: pointer;
+ text-decoration: underline;
+ text-underline-offset: 2px;
+}
+@keyframes aa-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
+
+.icon { display: inline-flex; }
+.icon svg { width: 12px; height: 12px; flex: none; }
+.link {
+ font: inherit;
+ font-size: 12px;
+ color: var(--aa-accent-text);
+ background: none;
+ border: 0;
+ padding: 0;
+ cursor: pointer;
+ text-decoration: underline;
+ text-underline-offset: 2px;
+ white-space: nowrap;
+}
+
+/* ---- the list ---- */
+.list-wrap { position: relative; flex: 1; min-height: 0; }
+.list { position: absolute; inset: 0; overflow: auto; }
+.empty { margin: 0; padding: 14px 16px; color: var(--sr-muted); }
+.latest {
+ position: absolute;
+ right: 16px;
+ bottom: 10px;
+ z-index: 2;
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ font: inherit;
+ font-size: 12px;
+ border: 1px solid var(--sr-accent);
+ background: var(--sr-bg);
+ color: var(--aa-accent-text);
+ border-radius: 12px;
+ padding: 2px 10px 2px 8px;
+ cursor: pointer;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
+}
+.latest svg { width: 10px; height: 10px; }
+
+/* ---- the step rail, as a list of calls ---- */
+.step { padding: 0 10px 0 12px; }
+.step.is-hidden { display: none; }
+.step::before { left: calc(12px + var(--sr-dot) / 2 - 1px); }
+.step.is-last::before { display: none; }
+/* The thread takes the accent once the call has ended, failed or not. */
+.step.is-ended::before { background: var(--sr-accent); }
+.dot { font-size: 10.5px; letter-spacing: -0.02em; }
+.dot .icon svg { width: 11px; height: 11px; }
+/* A read passed too, but changed nothing: the hollow dot. */
+.step.is-read.is-done .dot { background: var(--sr-bg); border-color: var(--sr-accent); color: var(--aa-accent-text); }
+.step.is-running .dot { color: var(--aa-accent-text); }
+.step.is-dialog .dot { background: var(--aa-tint); border-color: var(--sr-accent); color: var(--aa-accent-text); }
+.step-head:hover .step-title { text-decoration: underline; text-decoration-color: var(--sr-rule); text-underline-offset: 3px; }
+.step-what .res.is-run { color: var(--aa-accent-text); }
+.step-what .pressed {
+ display: inline-block;
+ margin-left: 6px;
+ padding: 0 6px;
+ border: 1px solid var(--sr-rule);
+ border-radius: 3px;
+ color: var(--sr-fg);
+ font-size: 11px;
+ line-height: 16px;
+}
+.failure { margin: 0 0 6px; padding: 5px 8px; font-size: 12px; overflow-wrap: anywhere; }
+
+/* A read is one quiet line: title and target side by side, no weight. */
+.step.is-read .dot { margin-top: 2px; }
+.step.is-read::before { top: calc(2px + var(--sr-dot)); }
+.step.is-read .step-head { display: flex; align-items: baseline; gap: 8px; padding: 2px 4px 2px 0; min-width: 0; }
+.step.is-read .step-title { font-weight: 400; color: var(--sr-muted); white-space: nowrap; }
+.step.is-read .step-what { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.step.is-read.is-open .step-what { white-space: normal; }
+
+.step-side { align-self: start; align-items: center; justify-content: flex-end; gap: 10px; font-size: 12px; color: var(--sr-muted); white-space: nowrap; }
+.step.is-read .step-side { padding-top: 3px; }
+.src { display: inline-flex; align-items: center; gap: 5px; min-width: 0; max-width: 140px; }
+.src-name { overflow: hidden; text-overflow: ellipsis; }
+.src.same .src-name { display: none; }
+.clock { width: 54px; text-align: right; font-variant-numeric: tabular-nums; }
+.time { width: 50px; text-align: right; }
+.step.is-running > .step-side .time { color: var(--aa-accent-text); }
+/* ---- an opened step: its request and its response, as JSON ---- */
+.kv-head { display: flex; align-items: baseline; gap: 10px; margin: 6px 0 3px; font-weight: 600; }
+.kv-head .meta { font-weight: 400; color: var(--sr-muted); min-width: 0; overflow-wrap: anywhere; }
+.kv-head .link { margin-left: auto; }
+.args { margin: 0; }
+.args.plain dd { font-family: inherit; font-size: 12px; }
+.none { margin: 0; color: var(--sr-muted); }
+/* Long lines wrap: a pane this narrow shows a value whole rather than behind a sideways scroll, whose bar WebKit would
+ paint over the heading below. */
+.raw { margin: 0; max-height: 240px; line-height: 1.45; color: var(--sr-fg); background: var(--sr-bg); white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: hidden; }
+.raw.is-note { color: var(--sr-muted); font-family: inherit; white-space: normal; }
+.raw .j-key { color: var(--code-key); }
+.raw .j-string { color: var(--code-string); }
+.raw .j-number { color: var(--code-number); }
+.raw .j-literal { color: var(--code-keyword); }
+.raw .j-punct { color: var(--code-punct); }
+.raw .mask { color: var(--sr-muted); letter-spacing: 0.1em; }
+.files { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
+.thumb { width: 168px; cursor: pointer; }
+
+/* ---- a run's own steps, nested under its row as Action Replay lists them ---- */
+.rail.nested { padding: 0 0 6px; }
+.rail.nested .step { --sr-dot: 16px; padding-left: 0; padding-right: 0; font-size: 12.5px; }
+.rail.nested .step::before { left: calc(var(--sr-dot) / 2 - 1px); }
+.rail.nested .dot { font-size: 9.5px; }
+.rail.nested .step.is-open { background: transparent; }
+
+/* A narrow pane (docked right, a small floating window) keeps the rail and drops the extras. */
+@container pane (max-width: 560px) {
+ .clock, .src-name, .t-opt, .status .counts { display: none !important; }
+ .find { flex: 1 1 90px; width: auto; min-width: 90px; }
+ .status { margin-left: 0; }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .status .is-busy .sdot { animation: none; }
+}
diff --git a/resources/web/dialog/RunScript/run_script.js b/resources/web/dialog/RunScript/run_script.js
index 59950be173..17664aa39f 100644
--- a/resources/web/dialog/RunScript/run_script.js
+++ b/resources/web/dialog/RunScript/run_script.js
@@ -334,7 +334,7 @@ function runCell() {
const code = cellText(cell, text.split("\n"));
S.pending = { kind: "cell", cells, text, cell, code };
S.message = null;
- send("run", { kind: "cell", text, first_line: cell.start, last_line: cell.end, code });
+ send("run", { kind: "cell", text, first_line: cell.start, last_line: cell.end, cell: cell.index, title: cell.title, code });
render();
}
diff --git a/resources/web/dialog/css/step_rail.css b/resources/web/dialog/css/step_rail.css
new file mode 100644
index 0000000000..28da1b3756
--- /dev/null
+++ b/resources/web/dialog/css/step_rail.css
@@ -0,0 +1,139 @@
+/* The step rail that Action Replay and Agent Activity draw a list of calls with: a numbered dot per step on a
+ * thread that takes the accent as steps pass, the step's title and target, its time at the side, and its detail
+ * when opened. Colours come from the host theme contract (--orca-*) and theme.css's status roles, so it follows the
+ * app in light and dark. A page links it after theme.css and before its own style.css. */
+
+:root {
+ --sr-bg: var(--orca-bg, #ffffff);
+ --sr-fg: var(--orca-fg, #262e30);
+ --sr-muted: var(--orca-muted, #6b7478);
+ --sr-rule: var(--border, #dcdfe1);
+ --sr-accent: var(--orca-accent, #009688);
+ --sr-accent-fg: var(--orca-accent-fg, #ffffff);
+ --sr-pass: var(--plugin-status-ok, #137333);
+ --sr-fail: var(--plugin-status-danger, #b42318);
+ --sr-fail-bg: var(--plugin-status-danger-bg, rgba(180, 35, 24, 0.12));
+ --sr-warn: var(--plugin-status-warn, #a15c00);
+ --sr-warn-bg: var(--plugin-status-warn-bg, rgba(199, 122, 22, 0.12));
+ --sr-hover: var(--row-hover, #f7f9fb);
+ --sr-ring: rgba(0, 150, 136, 0.25);
+ --sr-ring-soft: rgba(0, 150, 136, 0.1);
+ --sr-mono: var(--code-font);
+ --sr-dot: 20px;
+}
+
+.rail { list-style: none; margin: 0; padding: 6px 0 10px; }
+.step {
+ position: relative;
+ display: grid;
+ grid-template-columns: var(--sr-dot) minmax(0, 1fr) auto;
+ column-gap: 10px;
+ padding: 0 12px 0 14px;
+}
+/* The thread from this step's dot down to the next one; it takes the accent once the step passed. */
+.step::before {
+ content: "";
+ position: absolute;
+ left: calc(14px + var(--sr-dot) / 2 - 1px);
+ top: calc(6px + var(--sr-dot));
+ bottom: -6px;
+ width: 2px;
+ background: var(--sr-rule);
+ transition: background-color 240ms ease;
+}
+.step:last-child::before { display: none; }
+.step.is-done::before, .step.is-warn::before { background: var(--sr-accent); }
+.dot {
+ margin-top: 6px;
+ width: var(--sr-dot);
+ height: var(--sr-dot);
+ border-radius: 50%;
+ border: 1.5px solid var(--sr-rule);
+ background: var(--sr-bg);
+ color: var(--sr-muted);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 11px;
+ font-variant-numeric: tabular-nums;
+ position: relative;
+ z-index: 1;
+}
+.step.is-done .dot { background: var(--sr-accent); border-color: var(--sr-accent); color: var(--sr-accent-fg); }
+.step.is-warn .dot { background: var(--sr-warn); border-color: var(--sr-warn); color: #ffffff; }
+.step.is-fail .dot, .step.is-stopped .dot { background: var(--sr-fail); border-color: var(--sr-fail); color: #ffffff; }
+.step.is-running .dot { border-color: var(--sr-accent); color: var(--sr-accent); animation: sr-ring 1.4s ease-in-out infinite; }
+@keyframes sr-ring {
+ 0%, 100% { box-shadow: 0 0 0 2px var(--sr-ring); }
+ 50% { box-shadow: 0 0 0 5px var(--sr-ring-soft); }
+}
+
+.step-main { min-width: 0; }
+.step-head {
+ display: block;
+ width: 100%;
+ padding: 6px 4px 6px 0;
+ font: inherit;
+ color: inherit;
+ background: none;
+ border: 0;
+ text-align: left;
+ cursor: pointer;
+}
+.step-title { font-weight: 600; }
+.step-what, .step-args { display: block; color: var(--sr-muted); font-size: 12px; overflow-wrap: anywhere; }
+.step-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
+.tag {
+ font-size: 11px;
+ line-height: 16px;
+ padding: 0 6px;
+ border-radius: 3px;
+ color: var(--sr-warn);
+ background: var(--sr-warn-bg);
+}
+.tag.is-check { color: var(--sr-muted); background: none; border: 1px solid var(--sr-rule); }
+
+.step-side { display: flex; align-items: flex-start; gap: 6px; padding-top: 7px; }
+.time { font-size: 12px; color: var(--sr-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
+.step.is-running .time { color: var(--sr-accent); }
+
+/* ---- an opened step ---- */
+.step-detail { padding: 2px 0 10px; font-size: 12px; }
+.step.is-open { background: var(--sr-hover); }
+.args { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; margin: 0 0 6px; }
+.args dt { color: var(--sr-muted); }
+.args dd { margin: 0; font-family: var(--sr-mono); font-size: 11.5px; overflow-wrap: anywhere; white-space: pre-wrap; }
+.failure {
+ margin: 4px 0 6px;
+ padding: 6px 8px;
+ border-left: 2px solid var(--sr-fail);
+ border-radius: 0 3px 3px 0;
+ background: var(--sr-fail-bg);
+}
+.step.is-warn .failure { border-left-color: var(--sr-warn); background: var(--sr-warn-bg); }
+.failure-detail { display: block; margin-top: 3px; color: var(--sr-muted); overflow-wrap: anywhere; }
+.thumb {
+ display: block;
+ width: 160px;
+ max-width: 100%;
+ border: 1px solid var(--sr-rule);
+ border-radius: 3px;
+ cursor: zoom-in;
+}
+.raw {
+ margin: 6px 0 0;
+ max-height: 220px;
+ overflow: auto;
+ padding: 6px 8px;
+ border: 1px solid var(--sr-rule);
+ border-radius: 3px;
+ font-family: var(--sr-mono);
+ font-size: 11px;
+ white-space: pre;
+ user-select: text;
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .step.is-running .dot { animation: none; box-shadow: 0 0 0 2px var(--sr-ring); }
+ .step::before { transition: none; }
+}
diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt
index 3259b08f44..0e4eef8f03 100644
--- a/src/slic3r/CMakeLists.txt
+++ b/src/slic3r/CMakeLists.txt
@@ -145,6 +145,8 @@ set(SLIC3R_GUI_SOURCES
GUI/ActionRegistry.hpp
GUI/ActionReplayDialog.cpp
GUI/ActionReplayDialog.hpp
+ GUI/AgentActivityPanel.cpp
+ GUI/AgentActivityPanel.hpp
GUI/NativeCommandMenuItems.hpp
GUI/NativeCommands.cpp
GUI/NativeCommands.hpp
@@ -174,6 +176,8 @@ set(SLIC3R_GUI_SOURCES
GUI/Operations/RunStatus.hpp
GUI/SyntheticInput.cpp
GUI/SyntheticInput.hpp
+ GUI/Mcp/ActivityLog.cpp
+ GUI/Mcp/ActivityLog.hpp
GUI/Mcp/AutomationRuntime.cpp
GUI/Mcp/AutomationRuntime.hpp
GUI/Mcp/AutomationRuntimePtr.hpp
diff --git a/src/slic3r/GUI/ActionReplayDialog.cpp b/src/slic3r/GUI/ActionReplayDialog.cpp
index c52e321cd1..94fe71f06d 100644
--- a/src/slic3r/GUI/ActionReplayDialog.cpp
+++ b/src/slic3r/GUI/ActionReplayDialog.cpp
@@ -235,8 +235,29 @@ std::string expect_text(const json& r)
return {};
}
-// A screenshot as a 160 px wide PNG data URL for the step's row, or "" when it can't be read.
-std::string thumbnail(const std::string& path)
+} // namespace
+
+json flag_strings()
+{
+ return {
+ {"flag_writes_file", _u8L("Writes a file")},
+ {"flag_changes_presets", _u8L("Changes presets")},
+ {"flag_replaces_project", _u8L("Replaces the project")},
+ {"flag_sends_to_printer", _u8L("Sends to a printer")},
+ {"flag_runs_program", _u8L("Can run a program")},
+ };
+}
+
+std::string script_status_text(const std::string& status)
+{
+ return status == "cancelled" ? _u8L("The script was stopped.") :
+ status == "timed_out" ? _u8L("The script ran out of time.") :
+ status == "unavailable" ? _u8L("Python is not available in this OrcaSlicer.") :
+ status == "refused" ? _u8L("The script could not run.") :
+ _u8L("The script raised an exception.");
+}
+
+std::string screenshot_thumbnail(const std::string& path)
{
wxImage image;
if (!image.LoadFile(from_u8(path), wxBITMAP_TYPE_PNG) || !image.IsOk() || image.GetWidth() <= 0)
@@ -252,8 +273,6 @@ std::string thumbnail(const std::string& path)
return "data:image/png;base64," + into_u8(wxBase64Encode(bytes.data(), bytes.size()));
}
-} // namespace
-
ActionReplayDialog::ActionReplayDialog(wxWindow* parent) : WebViewHostDialog(parent)
{
// The window is one the GUI tools reach, as any of the app's windows, so an agent or a test can read and close it;
@@ -322,7 +341,7 @@ nlohmann::json ActionReplayDialog::localized_strings() const
#else
const std::string control = ctrl, enter = "Enter";
#endif
- return {
+ json strings = {
{"key_suggest", control + "Space"},
{"key_run", ctrl + enter},
{"key_save", ctrl + "S"},
@@ -360,11 +379,6 @@ nlohmann::json ActionReplayDialog::localized_strings() const
{"show_in_folder", _u8L("Show in folder")},
{"skipped", _u8L("Skipped")},
{"checks_result", _u8L("Checks the result")},
- {"flag_writes_file", _u8L("Writes a file")},
- {"flag_changes_presets", _u8L("Changes presets")},
- {"flag_replaces_project", _u8L("Replaces the project")},
- {"flag_sends_to_printer", _u8L("Sends to a printer")},
- {"flag_runs_program", _u8L("Can run a program")},
// TRN A duration; %s is a number of seconds such as 0.8.
{"seconds", _u8L("%s s")},
// TRN %s is the number of the step that is running.
@@ -375,6 +389,8 @@ nlohmann::json ActionReplayDialog::localized_strings() const
{"starting", _u8L("OrcaSlicer is still starting…")},
{"code_editor", code_editor_strings()},
};
+ strings.update(flag_strings());
+ return strings;
}
void ActionReplayDialog::on_script_message(const nlohmann::json& payload)
@@ -830,10 +846,7 @@ json ActionReplayDialog::step_view(const json& entry) const
else
view["failure_text"] = _u8L("This step needs a job that no step of this replay saves.");
} else if (kind == "python") {
- const std::string status = reason.value("status", "");
- view["failure_text"] = status == "cancelled" ? _u8L("The script was stopped.") :
- status == "timed_out" ? _u8L("The script ran out of time.") :
- _u8L("The script raised an exception.");
+ view["failure_text"] = script_status_text(reason.value("status", ""));
const json result = entry.value("result", json::object());
view["failure_detail"] = result.value("traceback", std::string()).empty() ? entry.value("error", std::string()) :
result.value("traceback", std::string());
@@ -883,7 +896,7 @@ json ActionReplayDialog::step_view(const json& entry) const
for (const std::string& path : Mcp::result_files(result))
files.push_back({{"path", path}, {"name", Mcp::path_to_utf8(Mcp::path_from_utf8(path).filename())}});
if (tool == "window_screenshot" && !files.empty())
- if (const std::string url = thumbnail(files[0]["path"].get()); !url.empty())
+ if (const std::string url = screenshot_thumbnail(files[0]["path"].get()); !url.empty())
view["thumbnail"] = url;
view["files"] = std::move(files);
return view;
diff --git a/src/slic3r/GUI/ActionReplayDialog.hpp b/src/slic3r/GUI/ActionReplayDialog.hpp
index f28faaaca5..491401e9eb 100644
--- a/src/slic3r/GUI/ActionReplayDialog.hpp
+++ b/src/slic3r/GUI/ActionReplayDialog.hpp
@@ -38,6 +38,18 @@ struct ReplayContext;
// titled as its own action is, and a call that is one of its actions (`what`'s `action`) as that action.
std::pair replay_what_text(const nlohmann::json& what, const CommandCatalog& catalog);
+// A screenshot as a 160 px wide PNG data URL for a step's row, as Action Replay and Agent Activity show one, or "" when
+// the file at `path` can't be read as a PNG.
+std::string screenshot_thumbnail(const std::string& path);
+
+// The labels of what a step does beyond the open project (describe_step()'s flags), keyed "flag_" + flag_id(), for the
+// strings of a page that tags steps with them: Action Replay's and Agent Activity's.
+nlohmann::json flag_strings();
+
+// A Python script's ending other than by finishing, by its status (cancelled, timed_out, unavailable, refused; any other
+// is a raised exception), as Action Replay and Agent Activity word it.
+std::string script_status_text(const std::string& status);
+
// The Action Replay window: a person opens or writes a replay file (the JSON list of tool calls an
// agent session exports), saves it, reads its steps and replays it, whole or one step at a time, watching each step's
// outcome. The page (resources/web/dialog/ActionReplay) shows; this host parses, describes, words and runs, through the
diff --git a/src/slic3r/GUI/AgentActivityPanel.cpp b/src/slic3r/GUI/AgentActivityPanel.cpp
new file mode 100644
index 0000000000..7393f770fe
--- /dev/null
+++ b/src/slic3r/GUI/AgentActivityPanel.cpp
@@ -0,0 +1,533 @@
+#include "AgentActivityPanel.hpp"
+
+#include "ActionReplayDialog.hpp"
+#include "CommandCatalog.hpp"
+#include "GUI.hpp"
+#include "GUI_App.hpp"
+#include "I18N.hpp"
+#include "MainFrame.hpp"
+#include "NativeCommands.hpp"
+#include "Plater.hpp"
+#include "format.hpp"
+#include "Mcp/ActivityLog.hpp"
+#include "Mcp/AutomationRuntime.hpp"
+#include "Mcp/McpPaths.hpp"
+#include "Mcp/McpReplay.hpp"
+#include "Mcp/McpReplaySummary.hpp"
+#include "Mcp/McpTools.hpp"
+#include "Mcp/VideoOverlay.hpp"
+#include "Mcp/WindowNames.hpp"
+#include "Widgets/WebView.hpp"
+#include "Widgets/WebViewHostDialog.hpp"
+#include "libslic3r/Utils.hpp"
+#include "slic3r/plugin/PluginDescriptor.hpp"
+#include "slic3r/plugin/PluginManager.hpp"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace Slic3r { namespace GUI {
+
+using nlohmann::json;
+namespace fs = boost::filesystem;
+
+namespace {
+
+// The least time between two refreshes of the page, and how often a pane off screen with changes waiting looks again.
+constexpr std::chrono::milliseconds kRefreshEvery{100};
+constexpr std::chrono::milliseconds kOffScreenRetry{500};
+
+// The page's text.
+json page_strings()
+{
+ json strings = {
+ {"pane", _u8L("Agent Activity")},
+ // TRN A button of the Agent Activity pane: it empties the list of calls.
+ {"clear", _u8L("Clear list")},
+ {"show", _u8L("Show")},
+ // TRN Agent Activity pane: show every call, reads included.
+ {"show_all", _u8L("Everything")},
+ // TRN Agent Activity pane: show only the calls that change something.
+ {"show_changes", _u8L("Changes")},
+ // TRN Agent Activity pane: show only the calls that failed.
+ {"show_failures", _u8L("Failures")},
+ // TRN Agent Activity pane, before who made the calls listed, such as "Everyone" or "Claude Code".
+ {"from", _u8L("From:")},
+ {"everyone", _u8L("Everyone")},
+ {"find", _u8L("Find a call")},
+ {"empty", _u8L("Calls from agents, Action Replay, Run Script and plugins appear here as they run.")},
+ {"no_match", _u8L("No call matches.")},
+ // TRN Agent Activity pane, while a call runs. %s is who made it, such as "Claude Code" or "Action Replay".
+ {"working", _u8L("%s is working")},
+ {"idle", _u8L("Idle")},
+ {"nothing_yet", _u8L("Nothing yet")},
+ // TRN Agent Activity pane: how many calls are listed. %s is the number.
+ {"calls", _u8L("Calls: %s")},
+ // TRN Agent Activity pane: how many listed calls failed. %s is the number.
+ {"failed", _u8L("Failed: %s")},
+ // TRN Agent Activity pane: a button that scrolls to calls that came while the person read further up. %s is their number.
+ {"new_calls", _u8L("New calls: %s")},
+ // TRN A duration under a minute. %s is the seconds, with one decimal under ten.
+ {"seconds", _u8L("%s s")},
+ // TRN A duration of a minute or more: the minutes, then the seconds.
+ {"minutes_seconds", _u8L("%s min %s s")},
+ // TRN Agent Activity pane, after a running call. %s is its job, such as "j4".
+ {"running_as_job", _u8L("running as job %s")},
+ {"read_call", _u8L("A call that only reads")},
+ {"change_call", _u8L("A call that changes something")},
+ {"dialog_answered", _u8L("A dialog a rule answered")},
+ {"request", _u8L("Request")},
+ {"response", _u8L("Response")},
+ {"copy_request", _u8L("Copy request")},
+ {"copy_response", _u8L("Copy response")},
+ {"copied", _u8L("Copied")},
+ // TRN Agent Activity pane: a call that has no response yet.
+ {"nothing_yet_response", _u8L("Nothing yet.")},
+ // TRN Agent Activity pane: a request or response left out for its size. %s is its size in bytes.
+ {"too_large", _u8L("Too large to show here (%s bytes).")},
+ // TRN Agent Activity pane, beside an agent's request. The first %s is the agent, such as "Claude Code"; the second the time.
+ {"tools_call_from", _u8L("tools/call from %s at %s")},
+ // TRN Agent Activity pane, beside an agent's request sent through tool_call (keep both names). The first %s is the agent; the second the time.
+ {"tools_call_via", _u8L("tools/call from %s through tool_call, at %s")},
+ // TRN Agent Activity pane, beside a step's request. %s is the title of the run that made it, such as "Run a replay".
+ {"made_by", _u8L("made by %s")},
+ // TRN Agent Activity pane, beside the code of a cell or console line. %s is the time.
+ {"work_at", _u8L("run in the Run Script panel at %s")},
+ // TRN Agent Activity pane, beside a request. %s is the time.
+ {"sent_at", _u8L("sent at %s")},
+ // TRN Agent Activity pane, beside a response. %s is a duration.
+ {"answered_in", _u8L("answered in %s")},
+ // TRN Agent Activity pane, beside a response. The first %s is the job, such as "j4"; the second a duration.
+ {"ran_as_job", _u8L("ran as job %s; finished after %s")},
+ // TRN Agent Activity pane, while a call runs. %s is its job, such as "j4".
+ {"running_no_result", _u8L("running as job %s; no result yet")},
+ {"waiting_reply", _u8L("waiting for the reply")},
+ // TRN Agent Activity pane, beside a failed call's response. %s is a duration.
+ {"failed_after", _u8L("failed after %s")},
+ // TRN Agent Activity pane: a dialog an auto-answer rule answered.
+ {"dialog", _u8L("Dialog")},
+ {"dialog_title", _u8L("Title")},
+ {"dialog_message", _u8L("Message")},
+ // TRN Agent Activity pane: the button an auto-answer rule pressed in a dialog.
+ {"pressed", _u8L("Pressed")},
+ // TRN Agent Activity pane: the auto-answer rule that answered a dialog.
+ {"rule", _u8L("Rule")},
+ // TRN Agent Activity pane, beside a rule. The first %s is the number of the call that set it; the second its title.
+ {"set_by", _u8L("set by call %s, %s")},
+ {"show_call", _u8L("Show that call")},
+ // TRN Agent Activity pane, beside the rule that answered a dialog, when the call that set it isn't in the list.
+ {"rule_gone", _u8L("the call that set it isn't listed")},
+ // TRN Agent Activity pane: in place of a response that repeats an earlier call's result the pane can't mask.
+ {"withheld", _u8L("Can't be shown: it repeats a call whose record the pane no longer has.")},
+ {"show_in_folder", _u8L("Show in folder")},
+ };
+ strings.update(flag_strings());
+ return strings;
+}
+
+// Who made an entry's calls, as the pane names them.
+std::string source_label(const json& entry)
+{
+ const std::string source = Mcp::arg_string(entry, "source");
+ if (source == "agent") {
+ const std::string client = Mcp::arg_string(entry, "client");
+ // TRN Agent Activity pane: an AI agent whose name the app doesn't know.
+ return client.empty() ? _u8L("Agent") : client;
+ }
+ if (source == "action_replay")
+ return _u8L("Action Replay");
+ if (source == "run_script")
+ return _u8L("Run Script");
+ if (source == "command_line")
+ // TRN Agent Activity pane: a replay or script OrcaSlicer was started with (--run).
+ return _u8L("Command line");
+ if (source == "plugin") {
+ const std::string key = Mcp::arg_string(entry, "plugin");
+ PluginDescriptor descriptor;
+ if (PluginManager::instance().try_get_plugin_descriptor(key, descriptor) && !descriptor.name.empty())
+ return descriptor.name;
+ return key;
+ }
+ // TRN Agent Activity pane: automation whose source the app doesn't know.
+ return _u8L("Automation");
+}
+
+// The first line of `text`, shortened.
+std::string first_line(const std::string& text) { return Mcp::shorten(text, 160); }
+
+} // namespace
+
+// The panel's dock pane: a web view on the page, hidden from the automation tools with everything inside it.
+class AgentActivityPane : public wxPanel
+{
+public:
+ AgentActivityPane(wxWindow* parent, AgentActivityPanel& owner);
+ ~AgentActivityPane() override;
+ AgentActivityPane(const AgentActivityPane&) = delete;
+ AgentActivityPane& operator=(const AgentActivityPane&) = delete;
+
+ // HandleStudio(payload) on the page, after the current event and only while the pane lives.
+ void send(const json& payload);
+
+private:
+ AgentActivityPanel& m_owner;
+ wxWebView* m_web = nullptr;
+ wxFileName m_page;
+ std::shared_ptr> m_alive = std::make_shared>(true);
+};
+
+AgentActivityPane::AgentActivityPane(wxWindow* parent, AgentActivityPanel& owner)
+ : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, Mcp::kHiddenFromAutomation), m_owner(owner)
+{
+ const fs::path page = fs::path(resources_dir()) / "web" / "dialog" / "AgentActivity" / "index.html";
+ m_page = wxFileName(from_path(page));
+ m_web = WebViewHostDialog::create_pane_web_view(
+ this, page, page_strings(), m_alive, [owner = &m_owner](const json& payload) { owner->handle(payload); },
+ // The page goes nowhere but its own loads.
+ [this](wxWebViewEvent& event) {
+ if (WebViewHostDialog::own_page_navigation(event.GetURL(), m_page))
+ event.Skip();
+ else
+ event.Veto();
+ });
+}
+
+AgentActivityPane::~AgentActivityPane()
+{
+ m_alive->store(false);
+ m_owner.pane_destroyed(this);
+}
+
+void AgentActivityPane::send(const json& payload)
+{
+ wxString script = "HandleStudio(" + wxString::FromUTF8(payload.dump(-1, ' ', false, json::error_handler_t::replace)) + ")";
+ wxGetApp().CallAfter([this, script = std::move(script), alive = m_alive] {
+ if (alive->load() && m_web != nullptr)
+ WebView::RunScript(m_web, script);
+ });
+}
+
+AgentActivityPanel::AgentActivityPanel() : m_alive(std::make_shared>(true))
+{
+ m_timer.Bind(wxEVT_TIMER, [this](wxTimerEvent&) { refresh(); });
+ // The pane comes back after a rebuild once the old main window is gone, as the Run Script panel's does.
+ wxGetApp().Bind(wxEVT_IDLE, [this, alive = m_alive](wxIdleEvent& event) {
+ event.Skip();
+ if (!alive->load() || !std::exchange(m_rebuild_pending, false))
+ return;
+ wxGetApp().CallAfter([this, alive] {
+ if (alive->load() && m_wanted && m_pane == nullptr)
+ show();
+ });
+ });
+}
+
+AgentActivityPanel::~AgentActivityPanel()
+{
+ m_alive->store(false);
+ m_timer.Stop();
+ // The panel goes at exit, before the runtime: nothing is recorded any more.
+ if (Mcp::AutomationRuntime* runtime = wxGetApp().automation_if_started()) {
+ runtime->activity().set_recording(false);
+ runtime->set_activity_listener({});
+ }
+}
+
+void AgentActivityPanel::set_wanted(bool wanted)
+{
+ m_wanted = wanted;
+ // The log records while the person has the pane open, docked on another tab and across a main-window rebuild too.
+ if (Mcp::AutomationRuntime* runtime = wxGetApp().automation_if_started())
+ runtime->activity().set_recording(wanted);
+}
+
+void AgentActivityPanel::toggle()
+{
+ if (on_screen()) {
+ set_wanted(false);
+ if (Plater* plater = wxGetApp().plater(); plater != nullptr)
+ plater->show_dock_pane(m_pane, false);
+ } else
+ show();
+}
+
+void AgentActivityPanel::show()
+{
+ MainFrame* frame = wxGetApp().mainframe;
+ Plater* plater = wxGetApp().plater();
+ if (frame == nullptr || plater == nullptr)
+ return;
+ // The log lives in the automation runtime, started here without the network endpoint when nothing has started it.
+ Mcp::AutomationRuntime* runtime = wxGetApp().automation();
+ if (runtime == nullptr)
+ return;
+ runtime->set_activity_listener([this, alive = m_alive] {
+ if (alive->load())
+ changed();
+ });
+ set_wanted(true);
+ // Docked, the pane shows on Prepare and Preview only; floated, on every tab.
+ const bool floating = m_pane != nullptr && plater->is_dock_pane_floating(m_pane);
+ if (!floating && !frame->is_prepare_or_preview_tab())
+ frame->select_tab(wxString(TAB_ID_PREPARE));
+ if (m_pane == nullptr) {
+ m_pane = new AgentActivityPane(plater, *this);
+ plater->add_dock_pane(
+ m_pane, "agent_activity", _L("Agent Activity"), "right", wxSize(420, 640),
+ [this, alive = m_alive] {
+ if (alive->load())
+ set_wanted(false);
+ },
+ true, true);
+ } else
+ plater->show_dock_pane(m_pane, true);
+ refresh();
+}
+
+bool AgentActivityPanel::on_screen() const { return m_pane != nullptr && m_pane->IsShownOnScreen(); }
+
+void AgentActivityPanel::forget_pane()
+{
+ m_pane = nullptr;
+ m_page_ready = false;
+ m_version = 0;
+}
+
+void AgentActivityPanel::pane_destroyed(AgentActivityPane* pane)
+{
+ if (m_pane == pane)
+ forget_pane();
+}
+
+void AgentActivityPanel::main_window_closing()
+{
+ m_timer.Stop();
+ forget_pane();
+}
+
+void AgentActivityPanel::main_window_rebuilt()
+{
+ m_rebuild_pending = m_wanted;
+ if (m_rebuild_pending)
+ wxWakeUpIdle();
+}
+
+void AgentActivityPanel::handle(const json& payload)
+{
+ const std::string command = Mcp::arg_string(payload, "command");
+ if (command == "ready") {
+ m_page_ready = true;
+ m_version = 0;
+ refresh();
+ } else if (command == "clear") {
+ if (Mcp::AutomationRuntime* runtime = wxGetApp().automation_if_started())
+ runtime->activity().clear();
+ } else if (command == "copy") {
+ if (wxTheClipboard->Open()) {
+ wxTheClipboard->SetData(new wxTextDataObject(wxString::FromUTF8(Mcp::arg_string(payload, "text"))));
+ wxTheClipboard->Close();
+ }
+ } else if (command == "open_file" || command == "show_file") {
+ // A file of an entry's result, named by the entry and its place in the list the page was given, never by a path:
+ // the image opens in the system's viewer, as Action Replay opens one, and any file shows in its folder.
+ const auto id = payload.find("id");
+ const auto index = payload.find("index");
+ if (id == payload.end() || !id->is_number_unsigned() || index == payload.end() || !index->is_number_unsigned())
+ return;
+ const auto files = m_files.find(id->get());
+ if (files == m_files.end() || index->get() >= files->second.size())
+ return;
+ const std::string& path = files->second[index->get()];
+ if (command == "open_file")
+ wxLaunchDefaultApplication(from_u8(path));
+ else
+ desktop_open_any_folder(Mcp::path_to_utf8(Mcp::path_from_utf8(path).parent_path()));
+ }
+}
+
+void AgentActivityPanel::changed()
+{
+ if (m_timer.IsRunning())
+ return;
+ const auto since = std::chrono::steady_clock::now() - m_last_refresh;
+ if (since >= kRefreshEvery)
+ refresh();
+ else
+ m_timer.StartOnce(int(std::chrono::duration_cast(kRefreshEvery - since).count()) + 1);
+}
+
+void AgentActivityPanel::refresh()
+{
+ if (m_pane == nullptr || !m_page_ready)
+ return;
+ // A pane off screen reads nothing, and the log reports no more changes until it is read: while the pane is wanted
+ // (docked off Prepare and Preview, the app's window minimized), it looks again until it shows.
+ if (!on_screen()) {
+ if (m_wanted && !m_timer.IsRunning())
+ m_timer.StartOnce(int(kOffScreenRetry.count()));
+ return;
+ }
+ Mcp::AutomationRuntime* runtime = wxGetApp().automation_if_started();
+ if (runtime == nullptr)
+ return;
+ m_last_refresh = std::chrono::steady_clock::now();
+ const json changes = runtime->activity().changes_since(m_version);
+ // The page holds nothing yet at version 0.
+ const bool reset = m_version == 0 || changes.value("reset", false);
+ m_version = changes.value("version", uint64_t(0));
+ json entries = json::array();
+ for (const json& entry : changes["entries"]) {
+ // Wording runs on the UI thread, where an exception would end the app: an entry it fails on shows by its tool.
+ try {
+ entries.push_back(page_entry(entry));
+ } catch (const std::exception&) {
+ json plain = entry;
+ plain.erase("args");
+ plain["title"] = Mcp::arg_string(entry, "tool");
+ plain["what"] = "";
+ plain["source_label"] = source_label(entry);
+ plain["flags"] = json::array();
+ entries.push_back(std::move(plain));
+ }
+ }
+ for (const json& id : changes["removed"]) {
+ m_files.erase(id.get());
+ m_thumbs.erase(id.get());
+ }
+ if (!reset && entries.empty() && changes["removed"].empty())
+ return;
+ m_pane->send({{"command", "entries"}, {"reset", reset}, {"entries", std::move(entries)}, {"removed", changes["removed"]}});
+}
+
+json AgentActivityPanel::page_entry(const json& entry)
+{
+ json out = entry;
+ json args = out.contains("args") ? std::move(out["args"]) : json::object();
+ const json& request = entry["request"];
+ const std::string kind = Mcp::arg_string(entry, "kind");
+ const std::string tool = Mcp::arg_string(entry, "tool");
+ out.erase("args");
+ out["source_label"] = source_label(entry);
+ out["flags"] = json::array();
+ if (kind == "dialog") {
+ // TRN Agent Activity pane: the title of a step where an auto-answer rule answered a dialog.
+ out["title"] = _u8L("Answered a dialog");
+ out["what"] = Mcp::arg_string(request, "title");
+ } else if (kind == "work") {
+ const std::string work = Mcp::arg_string(request, "work");
+ const std::string file = Mcp::path_to_utf8(Mcp::path_from_utf8(Mcp::arg_string(request, "file")).filename());
+ const std::string title = Mcp::arg_string(request, "title");
+ const int cell = request.is_object() ? request.value("cell", 0) : 0;
+ if (work == "file") {
+ out["title"] = _u8L("Run all");
+ out["what"] = file;
+ } else if (work == "console") {
+ // TRN Agent Activity pane: the title of a step where a person ran a line in the Run Script panel's console.
+ out["title"] = _u8L("Run a console line");
+ out["what"] = first_line(Mcp::arg_string(request, "code"));
+ } else {
+ // TRN Agent Activity pane: the title of a step where a person ran a cell in the Run Script panel.
+ out["title"] = _u8L("Run a cell");
+ // TRN Agent Activity pane: the cell a person ran. %1% is the script's file name, %2% the cell's number, %3% its title.
+ out["what"] = title.empty() ? format(_u8L("%1%, cell %2%"), file, cell) : format(_u8L("%1%, cell %2%: %3%"), file, cell, title);
+ }
+ } else {
+ const std::shared_ptr def = NativeCommands::instance().lookup(tool);
+ if (def == nullptr) {
+ out["title"] = tool;
+ out["what"] = "";
+ } else {
+ // The arguments of a call the protocol refused were never checked, and the wording reads them by type: what
+ // it can't read leaves the call titled by its tool, as one the catalog doesn't know.
+ try {
+ // Worded as the recording captions word the call.
+ const auto [title, titled] = shown_title(NativeCommands::instance(), *def, args);
+ const char* context = title_context(*titled);
+ out["title"] = into_u8(context != nullptr ? I18N::translate(title, context) : wxGetTranslation(from_u8(title)));
+ out["what"] = Mcp::caption_detail(tool, args);
+ // A run's own steps show what they do: read before it runs, a run given no file reads as doing everything.
+ if (!entry.value("read", false) && tool != "replay_run" && tool != "script_run") {
+ Mcp::ReplayStep step;
+ step.tool = tool;
+ step.args = args.is_object() ? std::move(args) : json::object();
+ for (const Mcp::StepFlag flag :
+ Mcp::describe_step(NativeCommands::instance(), step, Mcp::Replay{}, Mcp::ReplayContext{}).flags)
+ out["flags"].push_back(Mcp::flag_id(flag));
+ }
+ } catch (const std::exception&) {
+ out["title"] = tool;
+ out["what"] = "";
+ out["flags"] = json::array();
+ }
+ }
+ }
+ // A failure the log read from a run's result, which the call itself reported as a success.
+ if (const json failure = entry.value("failure", json()); failure.contains("script")) {
+ out["error"] = script_status_text(Mcp::arg_string(failure, "script"));
+ } else if (failure.contains("why")) {
+ const std::string why = Mcp::arg_string(failure, "why");
+ if (const int step = failure.value("step", 0); step > 0)
+ // TRN Agent Activity pane: why a replay failed. %1% is the number of the step that failed, %2% that step's
+ // error, in English.
+ out["error"] = why.empty() ? format(_u8L("Step %1% failed"), step) : format(_u8L("Step %1% failed: %2%"), step, why);
+ else
+ // TRN Agent Activity pane: a replay failed without saying which step.
+ out["error"] = why.empty() ? _u8L("The replay failed.") : why;
+ }
+ // The files a finished call's result names, by name, and a screenshot's thumbnail, read once the call has written
+ // them. A path the log masked names no file, and gets no link.
+ const uint64_t id = entry.value("id", uint64_t(0));
+ if (Mcp::arg_string(entry, "status") == "done") {
+ auto files = m_files.find(id);
+ if (files == m_files.end()) {
+ std::vector existing;
+ for (const std::string& path : Mcp::result_files(entry["response"])) {
+ boost::system::error_code ec;
+ if (fs::is_regular_file(Mcp::path_from_utf8(path), ec))
+ existing.push_back(path);
+ }
+ files = m_files.emplace(id, std::move(existing)).first;
+ }
+ if (!files->second.empty()) {
+ out["files"] = json::array();
+ for (const std::string& path : files->second)
+ out["files"].push_back(Mcp::path_to_utf8(Mcp::path_from_utf8(path).filename()));
+ }
+ if (tool == "window_screenshot" && !files->second.empty()) {
+ auto thumb = m_thumbs.find(id);
+ if (thumb == m_thumbs.end())
+ thumb = m_thumbs.emplace(id, screenshot_thumbnail(files->second.front())).first;
+ if (!thumb->second.empty())
+ out["thumb"] = thumb->second;
+ }
+ }
+ return out;
+}
+
+}} // namespace Slic3r::GUI
diff --git a/src/slic3r/GUI/AgentActivityPanel.hpp b/src/slic3r/GUI/AgentActivityPanel.hpp
new file mode 100644
index 0000000000..0cf5fcc4ab
--- /dev/null
+++ b/src/slic3r/GUI/AgentActivityPanel.hpp
@@ -0,0 +1,78 @@
+#pragma once
+
+#include
+#include
+
+#include
+#include
+#include
+#include