dsh-agent-enhancer 0.3.14 → 0.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.en.md +3 -3
  2. package/README.md +3 -3
  3. package/lib/client/browser-agent/tab.d.ts.map +1 -1
  4. package/lib/client/dsh/settings-features.d.ts +3 -2
  5. package/lib/client/dsh/settings-features.d.ts.map +1 -1
  6. package/lib/client/dsh/settings.d.ts.map +1 -1
  7. package/lib/client/locales.d.ts +51 -7
  8. package/lib/client/locales.d.ts.map +1 -1
  9. package/lib/client/remote.d.ts +4 -1
  10. package/lib/client/remote.d.ts.map +1 -1
  11. package/lib/client.js +238 -17
  12. package/lib/client.js.map +1 -1
  13. package/lib/config.d.ts +15 -3
  14. package/lib/config.d.ts.map +1 -1
  15. package/lib/host/browser-agent/capture.d.ts +4 -0
  16. package/lib/host/browser-agent/capture.d.ts.map +1 -1
  17. package/lib/host/browser-agent/demo.d.ts +60 -0
  18. package/lib/host/browser-agent/demo.d.ts.map +1 -0
  19. package/lib/host/browser-agent/driver.d.ts +12 -0
  20. package/lib/host/browser-agent/driver.d.ts.map +1 -1
  21. package/lib/host/browser-agent/install.d.ts +15 -2
  22. package/lib/host/browser-agent/install.d.ts.map +1 -1
  23. package/lib/host/browser-agent/playwright-driver.d.ts +25 -0
  24. package/lib/host/browser-agent/playwright-driver.d.ts.map +1 -1
  25. package/lib/host/browser-agent/playwright-snapshot.d.ts +4 -0
  26. package/lib/host/browser-agent/playwright-snapshot.d.ts.map +1 -1
  27. package/lib/host/browser-agent/prompt.d.ts.map +1 -1
  28. package/lib/host/browser-agent/tools.d.ts +2 -0
  29. package/lib/host/browser-agent/tools.d.ts.map +1 -1
  30. package/lib/host/index.d.ts +11 -5
  31. package/lib/host/index.d.ts.map +1 -1
  32. package/lib/host/rpc.d.ts +141 -0
  33. package/lib/host/rpc.d.ts.map +1 -1
  34. package/lib/index.js +563 -34
  35. package/lib/index.js.map +3 -3
  36. package/package.json +59 -59
package/lib/index.js CHANGED
@@ -20,6 +20,28 @@ function resolveRunAlertsLevel(value) {
20
20
  return "unfocused";
21
21
  }
22
22
  }
23
+ var BROWSER_AGENT_IDLE_CLOSE = ["10m", "30m", "60m", "never"];
24
+ function resolveBrowserAgentIdleClose(value) {
25
+ if (value === false) return "never";
26
+ if (value === true) return "10m";
27
+ return BROWSER_AGENT_IDLE_CLOSE.includes(value) ? value : "10m";
28
+ }
29
+ function browserAgentIdleCloseMs(value) {
30
+ switch (value) {
31
+ case "10m":
32
+ return 10 * 6e4;
33
+ case "30m":
34
+ return 30 * 6e4;
35
+ case "60m":
36
+ return 60 * 6e4;
37
+ case "never":
38
+ return null;
39
+ default: {
40
+ const _exhaustive = value;
41
+ return _exhaustive;
42
+ }
43
+ }
44
+ }
23
45
  function resolveBrowserAgentBrowser(value) {
24
46
  switch (value) {
25
47
  case "auto":
@@ -69,7 +91,8 @@ var DEFAULT_SETTINGS = {
69
91
  browserAgentEnabled: false,
70
92
  browserAgentBrowser: "auto",
71
93
  browserAgentDebugTools: false,
72
- browserAgentIdleClose: true,
94
+ browserAgentDemonstrate: false,
95
+ browserAgentIdleClose: "10m",
73
96
  webChatBridgeEnabled: true,
74
97
  instructionsSkillsEnabled: true,
75
98
  mcpConnectorsEnabled: true,
@@ -116,7 +139,8 @@ function resolveSettings(value) {
116
139
  browserAgentEnabled: value?.browserAgentEnabled ?? false,
117
140
  browserAgentBrowser: resolveBrowserAgentBrowser(value?.browserAgentBrowser),
118
141
  browserAgentDebugTools: value?.browserAgentDebugTools === true,
119
- browserAgentIdleClose: value?.browserAgentIdleClose !== false,
142
+ browserAgentDemonstrate: value?.browserAgentDemonstrate === true,
143
+ browserAgentIdleClose: resolveBrowserAgentIdleClose(value?.browserAgentIdleClose),
120
144
  webChatBridgeEnabled: value?.webChatBridgeEnabled ?? true,
121
145
  instructionsSkillsEnabled: value?.instructionsSkillsEnabled ?? true,
122
146
  mcpConnectorsEnabled: value?.mcpConnectorsEnabled ?? true,
@@ -878,7 +902,8 @@ function selectSnapshotRows(rows, max) {
878
902
  remaining -= 1;
879
903
  }
880
904
  }
881
- return rows.filter((row) => picked.has(row));
905
+ const groupOf = (row) => row.priority === 1 ? 0 : row.priority <= 0 ? 1 : 2;
906
+ return rows.filter((row) => picked.has(row)).sort((a, b) => groupOf(a) - groupOf(b));
882
907
  }
883
908
  async function capturePlaywrightSnapshot(page, options = {}) {
884
909
  const harvest = await page.evaluate(`(() => { ${HARVEST_PAGE_SNAPSHOT_SOURCE} })()`);
@@ -988,6 +1013,206 @@ async function capturePlaywrightSnapshot(page, options = {}) {
988
1013
  return { body, refs };
989
1014
  }
990
1015
 
1016
+ // src/host/browser-agent/demo.ts
1017
+ var SECRET_FIELD = /pass(word)?|\bpw\b|\bpwd\b|otp|one[-_]?time|code|pin|cvv|cvc|secret|token|card[-_]?number|iban/i;
1018
+ function isSensitiveFieldName(...parts) {
1019
+ return parts.some((part) => typeof part === "string" && SECRET_FIELD.test(part));
1020
+ }
1021
+ function pushDemoStep(steps, step, windowMs = 1500) {
1022
+ const last = steps[steps.length - 1];
1023
+ if (last !== void 0 && step.at - last.at <= windowMs) {
1024
+ if (last.kind === "fill" && step.kind === "fill" && last.selector === step.selector) {
1025
+ steps[steps.length - 1] = step;
1026
+ return;
1027
+ }
1028
+ if (last.kind === "click" && step.kind === "fill" && last.selector === step.selector) {
1029
+ steps[steps.length - 1] = step;
1030
+ return;
1031
+ }
1032
+ }
1033
+ if (steps.length >= 200) return;
1034
+ steps.push(step);
1035
+ }
1036
+ function mergeDemoSteps(pageSteps, navSteps) {
1037
+ const all = [...pageSteps, ...navSteps].sort((a, b) => a.at - b.at);
1038
+ const out = [];
1039
+ for (const step of all) {
1040
+ const prev = out[out.length - 1];
1041
+ if (prev !== void 0 && sameStep(prev, step)) continue;
1042
+ out.push(step);
1043
+ }
1044
+ return out;
1045
+ }
1046
+ function sameStep(a, b) {
1047
+ if (a.kind !== b.kind) return false;
1048
+ if (a.kind === "navigate" && b.kind === "navigate") return a.url === b.url;
1049
+ if (a.kind === "click" && b.kind === "click") return a.selector === b.selector;
1050
+ if (a.kind === "fill" && b.kind === "fill") return a.selector === b.selector && a.value === b.value;
1051
+ if (a.kind === "press" && b.kind === "press") return a.selector === b.selector && a.key === b.key;
1052
+ return false;
1053
+ }
1054
+ function sanitizeDemoSteps(steps) {
1055
+ return steps.map((step) => {
1056
+ if (step.kind !== "fill") return step;
1057
+ if (step.masked || !isSensitiveFieldName(step.field, step.name, step.selector)) return step;
1058
+ return { ...step, value: "***", masked: true };
1059
+ });
1060
+ }
1061
+ function summarizeDemoSteps(steps, max = 40) {
1062
+ const shown = steps.slice(0, Math.max(1, max));
1063
+ const lines = shown.map((step, index) => {
1064
+ const n = index + 1;
1065
+ switch (step.kind) {
1066
+ case "navigate":
1067
+ return `${n}. navigate -> ${step.url}`;
1068
+ case "click":
1069
+ return `${n}. click ${step.role} ${JSON.stringify(step.name)}${step.href === void 0 ? "" : ` (href ${step.href})`} [selector ${step.selector}]`;
1070
+ case "fill": {
1071
+ const value = step.masked ? "***" : JSON.stringify(step.value);
1072
+ const checked = step.checked === void 0 ? "" : ` checked=${String(step.checked)}`;
1073
+ return `${n}. fill ${step.role} ${JSON.stringify(step.name)} = ${value}${checked} [selector ${step.selector}]`;
1074
+ }
1075
+ case "press":
1076
+ return `${n}. press ${step.key} [selector ${step.selector}]`;
1077
+ default: {
1078
+ const exhaustive = step;
1079
+ return `${n}. ${JSON.stringify(exhaustive)}`;
1080
+ }
1081
+ }
1082
+ });
1083
+ return {
1084
+ lines,
1085
+ shown: shown.length,
1086
+ masked: shown.filter((step) => step.kind === "fill" && step.masked).length
1087
+ };
1088
+ }
1089
+ var DEMO_SYMBOL = "Symbol.for('dsh-demo')";
1090
+ var DEMO_RECORDER_SOURCE = `"use strict";
1091
+ var KEY = ${DEMO_SYMBOL};
1092
+ var existing = window[KEY];
1093
+ if (existing) { try { existing.stop(); } catch (e) { } }
1094
+ var SECRET = /pass(word)?|\\bpw\\b|\\bpwd\\b|otp|one[-_]?time|code|pin|cvv|cvc|secret|token|card[-_]?number|iban/i;
1095
+ var steps = [];
1096
+ var OFF = [];
1097
+ function textOf(el, max) {
1098
+ var raw = el.getAttribute("aria-label") || el.getAttribute("title") || (el.innerText || el.textContent || "");
1099
+ return String(raw || "").replace(/\\s+/g, " ").trim().slice(0, max || 60);
1100
+ }
1101
+ function roleOf(el) {
1102
+ var explicit = el.getAttribute("role");
1103
+ if (explicit) return explicit;
1104
+ var tag = el.tagName.toLowerCase();
1105
+ if (tag === "a") return "link";
1106
+ if (tag === "button") return "button";
1107
+ if (tag === "select") return "combobox";
1108
+ if (tag === "textarea") return "textbox";
1109
+ if (tag === "input") {
1110
+ var type = (el.getAttribute("type") || "text").toLowerCase();
1111
+ if (type === "checkbox") return "checkbox";
1112
+ if (type === "radio") return "radio";
1113
+ if (type === "submit" || type === "button") return "button";
1114
+ return "textbox";
1115
+ }
1116
+ return tag;
1117
+ }
1118
+ function selectorOf(el) {
1119
+ try {
1120
+ if (el.id && document.querySelectorAll("#" + CSS.escape(el.id)).length === 1) return "#" + CSS.escape(el.id);
1121
+ } catch (e) { }
1122
+ var testid = el.getAttribute("data-testid") || el.getAttribute("data-test-id");
1123
+ if (testid) return '[data-testid="' + testid + '"]';
1124
+ var name = el.getAttribute("name");
1125
+ if (name) return el.tagName.toLowerCase() + '[name="' + name + '"]';
1126
+ var parts = [];
1127
+ var node = el;
1128
+ while (node && node.nodeType === 1 && parts.length < 6) {
1129
+ var tag = node.tagName.toLowerCase();
1130
+ if (node.id) { parts.unshift("#" + CSS.escape(node.id)); break; }
1131
+ var parent = node.parentElement;
1132
+ var same = parent ? Array.prototype.filter.call(parent.children, function (child) { return child.tagName === node.tagName; }) : [];
1133
+ parts.unshift(same.length > 1 ? tag + ":nth-of-type(" + (same.indexOf(node) + 1) + ")" : tag);
1134
+ node = parent;
1135
+ }
1136
+ return parts.join(" > ");
1137
+ }
1138
+ function push(step) {
1139
+ step.at = Date.now();
1140
+ try { if (typeof window.__dshDemoPush === "function") window.__dshDemoPush(step); } catch (e) { }
1141
+ }
1142
+ function isSecret(el) {
1143
+ var type = (el.getAttribute("type") || "").toLowerCase();
1144
+ if (type === "password") return true;
1145
+ return SECRET.test(el.getAttribute("name") || "") || SECRET.test(el.id || "")
1146
+ || SECRET.test(el.getAttribute("autocomplete") || "") || SECRET.test(el.getAttribute("placeholder") || "");
1147
+ }
1148
+ function on(target, type, handler, capture) {
1149
+ target.addEventListener(type, handler, capture === true);
1150
+ OFF.push(function () { target.removeEventListener(type, handler, capture === true); });
1151
+ }
1152
+ on(document, "click", function (event) {
1153
+ var el = event.target && event.target.closest ? event.target.closest("a,button,input,select,textarea,[role],[contenteditable='true']") : null;
1154
+ if (!el) return;
1155
+ var href = el.tagName === "A" && el.href ? String(el.href) : "";
1156
+ push({ kind: "click", role: roleOf(el), name: textOf(el), selector: selectorOf(el), href: /^https?:\\/\\//i.test(href) ? href : "" });
1157
+ }, true);
1158
+ function fieldStep(el) {
1159
+ var tag = el.tagName.toLowerCase();
1160
+ var type = (el.getAttribute("type") || "").toLowerCase();
1161
+ if (tag === "select") {
1162
+ push({ kind: "fill", role: "combobox", name: textOf(el), selector: selectorOf(el), field: el.name || el.id || "select", value: String(el.value || ""), masked: false });
1163
+ return;
1164
+ }
1165
+ if (type === "checkbox" || type === "radio") {
1166
+ push({ kind: "fill", role: type, name: textOf(el), selector: selectorOf(el), field: el.name || el.id || type, value: el.checked ? "on" : "off", masked: false, checked: el.checked });
1167
+ return;
1168
+ }
1169
+ if (tag !== "input" && tag !== "textarea") return;
1170
+ var secret = isSecret(el);
1171
+ push({
1172
+ kind: "fill",
1173
+ role: roleOf(el),
1174
+ name: textOf(el) || el.getAttribute("placeholder") || "",
1175
+ selector: selectorOf(el),
1176
+ field: el.name || el.id || type || "field",
1177
+ value: secret ? "***" : String(el.value || ""),
1178
+ masked: secret,
1179
+ });
1180
+ }
1181
+ // "input" catches typing as it happens; "change" catches selects, checkboxes and blur.
1182
+ on(document, "input", function (event) {
1183
+ var el = event.target;
1184
+ if (!el || !el.tagName) return;
1185
+ fieldStep(el);
1186
+ }, true);
1187
+ on(document, "change", function (event) {
1188
+ var el = event.target;
1189
+ if (!el || !el.tagName) return;
1190
+ var tag = el.tagName.toLowerCase();
1191
+ var type = (el.getAttribute("type") || "").toLowerCase();
1192
+ if (tag === "select" || type === "checkbox" || type === "radio") fieldStep(el);
1193
+ }, true);
1194
+ on(document, "keydown", function (event) {
1195
+ if (event.key !== "Enter") return;
1196
+ var el = event.target;
1197
+ if (!el || !el.tagName) return;
1198
+ push({ kind: "press", key: "Enter", selector: selectorOf(el) });
1199
+ }, true);
1200
+ var recorder = {
1201
+ stop: function () {
1202
+ for (var i = 0; i < OFF.length; i++) { try { OFF[i](); } catch (e) { } }
1203
+ OFF.length = 0;
1204
+ delete window[KEY];
1205
+ },
1206
+ };
1207
+ window[KEY] = recorder;
1208
+ return true;
1209
+ `;
1210
+ var DEMO_STOP_SOURCE = `(() => {
1211
+ const r = window[${DEMO_SYMBOL}];
1212
+ if (r) { try { r.stop(); } catch (e) { } }
1213
+ return true;
1214
+ })()`;
1215
+
991
1216
  // src/host/browser-agent/capture.ts
992
1217
  var SECRET_PARAM = /^(access_?token|id_?token|auth|authorization|code|key|password|secret|session|sessionid|sig|signature|token)$/i;
993
1218
  var URL_IN_TEXT = /https?:\/\/[^\s"'<>]+/g;
@@ -1027,14 +1252,16 @@ var CaptureBuffer = class {
1027
1252
  /** Newest `limit` entries of the requested kind, optionally clearing them. */
1028
1253
  read(kind, options = {}) {
1029
1254
  const limit = Math.min(Math.max(Math.trunc(options.limit ?? 40), 1), 200);
1030
- const matched = this.entries.filter((entry) => kind === "all" || entry.kind === (kind === "network" ? "request" : "console"));
1255
+ const ofKind = this.entries.filter((entry) => kind === "all" || entry.kind === (kind === "network" ? "request" : "console"));
1256
+ const matched = options.tabId === void 0 ? ofKind : ofKind.filter((entry) => entry.tabId === options.tabId);
1257
+ const skipped = ofKind.length - matched.length;
1031
1258
  const selected = matched.slice(-limit);
1032
1259
  if (options.clear === true) {
1033
1260
  const keep = this.entries.filter((entry) => !selected.includes(entry));
1034
1261
  this.entries.length = 0;
1035
1262
  this.entries.push(...keep);
1036
1263
  }
1037
- return { entries: selected, dropped: this.dropped };
1264
+ return { entries: selected, dropped: this.dropped, skipped };
1038
1265
  }
1039
1266
  clear() {
1040
1267
  this.entries.length = 0;
@@ -1183,6 +1410,13 @@ var PlaywrightDriver = class {
1183
1410
  requestStart = /* @__PURE__ */ new WeakMap();
1184
1411
  /** Last applied emulation per tab, echoed in snapshot so the agent can see it. */
1185
1412
  emulationByTab = /* @__PURE__ */ new Map();
1413
+ /** Active "show me" recording: bound page plus navigations seen meanwhile. */
1414
+ demoPage = null;
1415
+ demoNavSteps = [];
1416
+ demoPageSteps = [];
1417
+ demoTrackedPages = /* @__PURE__ */ new WeakSet();
1418
+ demoPageHandler = null;
1419
+ demoBindingReady = false;
1186
1420
  /** Last agent/UI use per page; a page's clock starts when it is first seen. */
1187
1421
  lastUse = /* @__PURE__ */ new WeakMap();
1188
1422
  constructor(options) {
@@ -1661,15 +1895,25 @@ var PlaywrightDriver = class {
1661
1895
  for (const page of context.pages()) this.attachCapture(page);
1662
1896
  context.on("page", (page) => this.attachCapture(page));
1663
1897
  }
1898
+ /**
1899
+ * Stop recording and drop the buffer. Listeners stay attached (they close over
1900
+ * the old buffer), so each one checks that it is still the live buffer.
1901
+ */
1902
+ stopCapture() {
1903
+ this.capture = null;
1904
+ }
1664
1905
  attachCapture(page) {
1665
- const buffer = this.capture;
1666
- if (buffer === null || this.captureStartedPages.has(page)) return;
1906
+ if (this.capture === null || this.captureStartedPages.has(page)) return;
1667
1907
  this.captureStartedPages.add(page);
1668
1908
  const tabId = this.tabIdFor(page);
1669
1909
  const stamp = () => Date.now();
1910
+ const record2 = (entry) => {
1911
+ this.capture?.push(entry);
1912
+ };
1670
1913
  page.on("console", (message) => {
1914
+ if (this.capture === null) return;
1671
1915
  try {
1672
- buffer.push({
1916
+ record2({
1673
1917
  kind: "console",
1674
1918
  at: stamp(),
1675
1919
  tabId,
@@ -1683,7 +1927,8 @@ var PlaywrightDriver = class {
1683
1927
  }
1684
1928
  });
1685
1929
  page.on("pageerror", (error) => {
1686
- buffer.push({
1930
+ if (this.capture === null) return;
1931
+ record2({
1687
1932
  kind: "console",
1688
1933
  at: stamp(),
1689
1934
  tabId,
@@ -1692,12 +1937,14 @@ var PlaywrightDriver = class {
1692
1937
  });
1693
1938
  });
1694
1939
  page.on("request", (request) => {
1940
+ if (this.capture === null) return;
1695
1941
  this.requestStart.set(request, performance.now());
1696
1942
  });
1697
1943
  page.on("response", (response) => {
1944
+ if (this.capture === null) return;
1698
1945
  const request = response.request();
1699
1946
  const started = this.requestStart.get(request);
1700
- buffer.push({
1947
+ record2({
1701
1948
  kind: "request",
1702
1949
  at: stamp(),
1703
1950
  tabId,
@@ -1709,8 +1956,9 @@ var PlaywrightDriver = class {
1709
1956
  });
1710
1957
  });
1711
1958
  page.on("requestfailed", (request) => {
1959
+ if (this.capture === null) return;
1712
1960
  const started = this.requestStart.get(request);
1713
- buffer.push({
1961
+ record2({
1714
1962
  kind: "request",
1715
1963
  at: stamp(),
1716
1964
  tabId,
@@ -1723,10 +1971,11 @@ var PlaywrightDriver = class {
1723
1971
  });
1724
1972
  }
1725
1973
  readCapture(input) {
1726
- if (this.capture === null) return { entries: [], dropped: 0 };
1974
+ if (this.capture === null) return { entries: [], dropped: 0, skipped: 0 };
1727
1975
  return this.capture.read(input.kind, {
1728
1976
  ...input.limit === void 0 ? {} : { limit: input.limit },
1729
- ...input.clear === void 0 ? {} : { clear: input.clear }
1977
+ ...input.clear === void 0 ? {} : { clear: input.clear },
1978
+ ...input.tabId === void 0 ? {} : { tabId: input.tabId }
1730
1979
  });
1731
1980
  }
1732
1981
  async emulate(input) {
@@ -1757,6 +2006,74 @@ var PlaywrightDriver = class {
1757
2006
  tabId: this.tabIdFor(page)
1758
2007
  };
1759
2008
  }
2009
+ /** Record a user demonstration in the bound tab until stopDemonstration(). */
2010
+ async startDemonstration() {
2011
+ const page = await this.requirePage();
2012
+ if (this.demoPage !== null) await this.stopDemonstration().catch(() => void 0);
2013
+ this.demoPage = page;
2014
+ this.demoNavSteps = [];
2015
+ this.demoPageSteps = [];
2016
+ const context = page.context();
2017
+ if (!this.demoBindingReady) {
2018
+ try {
2019
+ await context.exposeBinding("__dshDemoPush", (_source, step) => {
2020
+ if (this.demoPage === null) return;
2021
+ pushDemoStep(this.demoPageSteps, step);
2022
+ });
2023
+ this.demoBindingReady = true;
2024
+ } catch {
2025
+ this.demoBindingReady = true;
2026
+ }
2027
+ }
2028
+ this.watchDemoNavigation(page);
2029
+ await page.evaluate(`(() => { ${DEMO_RECORDER_SOURCE} })()`).catch(() => void 0);
2030
+ if (this.demoPageHandler === null) {
2031
+ this.demoPageHandler = (opened) => {
2032
+ if (this.demoPage === null) return;
2033
+ this.watchDemoNavigation(opened);
2034
+ void opened.evaluate(`(() => { ${DEMO_RECORDER_SOURCE} })()`).catch(() => void 0);
2035
+ };
2036
+ context.on("page", this.demoPageHandler);
2037
+ }
2038
+ }
2039
+ /**
2040
+ * Record top-level http(s) navigations of the pages the demo touches and
2041
+ * re-arm the recorder on the new document (the old one dies with the page).
2042
+ */
2043
+ watchDemoNavigation(page) {
2044
+ if (this.demoTrackedPages.has(page)) return;
2045
+ this.demoTrackedPages.add(page);
2046
+ page.on("framenavigated", (frame) => {
2047
+ if (this.demoPage === null || frame !== page.mainFrame()) return;
2048
+ const url = frame.url();
2049
+ if (!/^https?:\/\//i.test(url)) return;
2050
+ this.demoNavSteps.push({ kind: "navigate", at: Date.now(), url: redactUrl(url) });
2051
+ void frame.page().evaluate(`(() => { ${DEMO_RECORDER_SOURCE} })()`).catch(() => void 0);
2052
+ });
2053
+ }
2054
+ /** Stop recording and return the flow, secrets masked, repeats dropped. */
2055
+ demonstrationActive() {
2056
+ return this.demoPage !== null;
2057
+ }
2058
+ async stopDemonstration() {
2059
+ const page = this.demoPage;
2060
+ this.demoPage = null;
2061
+ if (this.demoPageHandler !== null) {
2062
+ this.context?.off("page", this.demoPageHandler);
2063
+ this.demoPageHandler = null;
2064
+ }
2065
+ if (page !== null && !page.isClosed()) {
2066
+ await page.evaluate(DEMO_STOP_SOURCE).catch(() => void 0);
2067
+ }
2068
+ for (const other of this.context?.pages() ?? []) {
2069
+ if (other === page || other.isClosed()) continue;
2070
+ await other.evaluate(DEMO_STOP_SOURCE).catch(() => void 0);
2071
+ }
2072
+ const steps = sanitizeDemoSteps(mergeDemoSteps(this.demoPageSteps, this.demoNavSteps));
2073
+ this.demoNavSteps = [];
2074
+ this.demoPageSteps = [];
2075
+ return steps;
2076
+ }
1760
2077
  /** Record what is now emulated on this tab, so snapshot can echo it. */
1761
2078
  rememberEmulation(tabId, input) {
1762
2079
  const next = { ...this.emulationByTab.get(tabId) ?? {} };
@@ -1876,6 +2193,8 @@ var GUIDANCE = [
1876
2193
  "Below-the-fold or long content: browser_scroll \u2192 browser_wait \u2192 browser_extract. Report what extract returns; do not hop to unrelated pages.",
1877
2194
  "The dedicated browser auto-launches when needed; never tell the user to click \u201CLaunch browser agent\u201D unless the tool error says so.",
1878
2195
  "Mutation tools may pause for an in-app Allow card \u2014 wait for allow/deny.",
2196
+ "When the user says they will show you how something works (\u6F14\u793A / \u793A\u8303 / \u6211\u64CD\u4F5C\u4F60\u770B), or you cannot work out a flow after a couple of attempts, call browser_demonstrate with one short instruction instead of guessing. It blocks until the user presses Continue and returns numbered steps.",
2197
+ "browser_demonstrate returns click/fill/Enter/navigation steps with role + name. Replay them with browser_snapshot, then act by role and name; the selectors in the steps are for humans, and refs change between runs. If the tool reports that demonstration recording is off, ask the user to enable \u8BBE\u7F6E \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u529F\u80FD \u2192 \u6D4F\u89C8\u5668 Agent \u2192 \u6F14\u793A\u5F55\u5236.",
1879
2198
  "Login / captcha / 2FA: NEVER type passwords. When needs_human appears, call browser_ask_user and STOP until the user finishes in the dedicated window. A bare \u201CLog in\u201D chip on a normal page is not a wall.",
1880
2199
  "Do not invent page content or refs. Prefer finishing the user task over exploring more pages."
1881
2200
  ].join("\n");
@@ -2224,7 +2543,7 @@ function formatSnapshot(body, extra) {
2224
2543
  const controls = body.nodes.length - links;
2225
2544
  const shown = body.nodes.length;
2226
2545
  const tally = controls > 0 ? `${links} link / ${controls} control` : `${links} link`;
2227
- return controls > 0 ? `interactive (${shown} shown: ${tally} \u2014 controls are at the end; prefer refs that include href=\u2026 ; never invent URLs; re-snapshot after navigation):` : `interactive (${shown} shown: ${tally}; prefer refs that include href=\u2026 ; never invent URLs; re-snapshot after navigation):`;
2546
+ return controls > 0 ? `interactive (${shown} shown: ${tally} \u2014 controls listed first; prefer refs that include href=\u2026 ; never invent URLs; re-snapshot after navigation):` : `interactive (${shown} shown: ${tally}; prefer refs that include href=\u2026 ; never invent URLs; re-snapshot after navigation):`;
2228
2547
  })(),
2229
2548
  ...body.nodes.slice(0, 80).map((node) => `- [${node.ref}] ${node.role}${node.tag !== void 0 ? `/${node.tag}` : ""}${node.sensitive === true ? " [sensitive]" : ""}${typeof node.href === "string" && node.href !== "" ? ` href=${JSON.stringify(node.href)}` : ""} ${JSON.stringify(node.name)}`),
2230
2549
  "text_preview (short \u2014 use browser_extract for long/below-fold content):",
@@ -2327,10 +2646,20 @@ function registerBrowserTools(ctx, options) {
2327
2646
  }
2328
2647
  await driverOf(options).ensureReady(startUrl);
2329
2648
  };
2649
+ const requireDemonstrate = () => {
2650
+ if (options.demonstrate?.() === true) return;
2651
+ throw new Error(
2652
+ "browser_demonstrate: demonstration recording is off. Nothing is recording. Ask the user to enable \u8BBE\u7F6E \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u529F\u80FD \u2192 \u6D4F\u89C8\u5668 Agent \u2192 \u6F14\u793A\u5F55\u5236, then retry."
2653
+ );
2654
+ };
2330
2655
  const requireDebugTools = (tool) => {
2331
2656
  if (options.debugTools?.() === true) return;
2657
+ try {
2658
+ driverOf(options).stopCapture?.();
2659
+ } catch {
2660
+ }
2332
2661
  throw new Error(
2333
- `${tool}: debug tools are off. Nothing ran. Ask the user to enable \u8BBE\u7F6E \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u529F\u80FD \u2192 \u6D4F\u89C8\u5668 Agent \u2192 \u8C03\u8BD5\u5DE5\u5177, then retry.`
2662
+ `${tool}: debug tools are off. Nothing ran. Ask the user to enable \u8BBE\u7F6E \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u529F\u80FD \u2192 \u6D4F\u89C8\u5668 Agent \u2192 \u8C03\u8BD5\u4E0E\u9875\u9762\u6A21\u62DF, then retry.`
2334
2663
  );
2335
2664
  };
2336
2665
  const requireWritableTab = (sessionId, tool) => {
@@ -3099,12 +3428,16 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
3099
3428
  )));
3100
3429
  disposers.push(ctx.tools.register(textTool(
3101
3430
  "browser_network",
3102
- "Read buffered network activity for the bound tab (method, url, status, duration, failures). Read-only; no approval. Headers, cookies and bodies are never recorded; secret-looking query values are masked. Requires the Debug tools switch in Settings \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u6D4F\u89C8\u5668 Agent. Capture starts automatically when that switch is on, so navigate first, then read.",
3431
+ "Read buffered network activity for the bound tab (method, url, status, duration, failures). Read-only; no approval. Defaults to the bound tab; pass allTabs: true to include other tabs. Headers, cookies and bodies are never recorded; secret-looking query values are masked. Requires the Debug tools switch in Settings \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u6D4F\u89C8\u5668 Agent. Capture starts automatically when that switch is on, so navigate first, then read.",
3103
3432
  {
3104
3433
  limit: {
3105
3434
  type: "number",
3106
3435
  description: "Newest N entries (default 40, max 200)."
3107
3436
  },
3437
+ allTabs: {
3438
+ type: "boolean",
3439
+ description: "Read every tab instead of only the bound tab."
3440
+ },
3108
3441
  clear: {
3109
3442
  type: "boolean",
3110
3443
  description: "Drop the returned entries from the buffer."
@@ -3117,19 +3450,27 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
3117
3450
  await ensureConnected();
3118
3451
  await ensureSessionTab(sessionId);
3119
3452
  const limit = Number(args.limit);
3453
+ const tabId = options.sessions.tabOf(sessionId);
3454
+ const allTabs = args.allTabs === true || tabId === void 0;
3120
3455
  const driver = driverOf(options);
3121
3456
  driver.startCapture();
3122
- const { entries, dropped } = driver.readCapture({
3457
+ const { entries, dropped, skipped } = driver.readCapture({
3123
3458
  kind: "network",
3124
3459
  ...Number.isFinite(limit) ? { limit } : {},
3125
- ...args.clear === true ? { clear: true } : {}
3460
+ ...args.clear === true ? { clear: true } : {},
3461
+ ...allTabs ? {} : { tabId }
3126
3462
  });
3127
3463
  const rows = entries.filter((entry) => entry.kind === "request");
3128
3464
  if (rows.length === 0) {
3129
- return "no network activity buffered yet. Navigate or wait for the page to load, then call browser_network again.";
3465
+ return [
3466
+ allTabs ? "no network activity buffered yet." : `no network activity buffered for tab ${tabId ?? "?"}.`,
3467
+ ...skipped > 0 ? [`${skipped} entries came from other tabs \u2014 pass allTabs: true to read them.`] : [],
3468
+ "Navigate or wait for the page to load, then call browser_network again."
3469
+ ].join("\n");
3130
3470
  }
3131
3471
  return [
3132
- `network entries: ${rows.length}${dropped > 0 ? ` (${dropped} older dropped)` : ""}`,
3472
+ `network entries: ${rows.length} (${allTabs ? "all tabs" : `tab ${tabId}`})${dropped > 0 ? ` (${dropped} older dropped)` : ""}`,
3473
+ ...skipped > 0 ? [`${skipped} entries from other tabs not shown \u2014 pass allTabs: true to include them.`] : [],
3133
3474
  ...rows.map((entry) => {
3134
3475
  const status = entry.kind !== "request" ? "" : entry.status === void 0 ? entry.failure ?? "failed" : String(entry.status);
3135
3476
  const ms = entry.kind === "request" && entry.durationMs !== void 0 ? ` ${entry.durationMs}ms` : "";
@@ -3141,12 +3482,16 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
3141
3482
  )));
3142
3483
  disposers.push(ctx.tools.register(textTool(
3143
3484
  "browser_console",
3144
- "Read buffered console messages and uncaught page errors for the bound tab. Read-only; no approval. Requires the Debug tools switch in Settings \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u6D4F\u89C8\u5668 Agent.",
3485
+ "Read buffered console messages and uncaught page errors for the bound tab. Read-only; no approval. Defaults to the bound tab; pass allTabs: true to include other tabs. Requires the Debug tools switch in Settings \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u6D4F\u89C8\u5668 Agent.",
3145
3486
  {
3146
3487
  limit: {
3147
3488
  type: "number",
3148
3489
  description: "Newest N entries (default 40, max 200)."
3149
3490
  },
3491
+ allTabs: {
3492
+ type: "boolean",
3493
+ description: "Read every tab instead of only the bound tab."
3494
+ },
3150
3495
  clear: {
3151
3496
  type: "boolean",
3152
3497
  description: "Drop the returned entries from the buffer."
@@ -3159,18 +3504,26 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
3159
3504
  await ensureConnected();
3160
3505
  await ensureSessionTab(sessionId);
3161
3506
  const limit = Number(args.limit);
3507
+ const tabId = options.sessions.tabOf(sessionId);
3508
+ const allTabs = args.allTabs === true || tabId === void 0;
3162
3509
  const driver = driverOf(options);
3163
3510
  driver.startCapture();
3164
- const { entries } = driver.readCapture({
3511
+ const { entries, skipped } = driver.readCapture({
3165
3512
  kind: "console",
3166
3513
  ...Number.isFinite(limit) ? { limit } : {},
3167
- ...args.clear === true ? { clear: true } : {}
3514
+ ...args.clear === true ? { clear: true } : {},
3515
+ ...allTabs ? {} : { tabId }
3168
3516
  });
3169
3517
  if (entries.length === 0) {
3170
- return "no console output buffered yet. Reload or interact with the page, then call browser_console again.";
3518
+ return [
3519
+ allTabs ? "no console output buffered yet." : `no console output buffered for tab ${tabId ?? "?"}.`,
3520
+ ...skipped > 0 ? [`${skipped} entries came from other tabs \u2014 pass allTabs: true to read them.`] : [],
3521
+ "Reload or interact with the page, then call browser_console again."
3522
+ ].join("\n");
3171
3523
  }
3172
3524
  return [
3173
- `console entries: ${entries.length}`,
3525
+ `console entries: ${entries.length} (${allTabs ? "all tabs" : `tab ${tabId}`})`,
3526
+ ...skipped > 0 ? [`${skipped} entries from other tabs not shown \u2014 pass allTabs: true to include them.`] : [],
3174
3527
  ...entries.map((entry) => {
3175
3528
  if (entry.kind !== "console") return "";
3176
3529
  const where = entry.location === void 0 ? "" : ` (${entry.location})`;
@@ -3229,6 +3582,74 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
3229
3582
  ].filter((line) => line !== null).join("\n");
3230
3583
  }
3231
3584
  )));
3585
+ disposers.push(ctx.tools.register(textTool(
3586
+ "browser_demonstrate",
3587
+ "Ask the user to show you a flow in the dedicated browser window (they click and type, you watch), blocking until they press Continue. Records clicks, filled fields, Enter presses and top-level navigations; password / OTP / token fields are masked as ***. Use it when you cannot work out how a flow works. Returns numbered steps to replay with browser_snapshot then browser_click / browser_type by name (refs change between runs). Requires the Demonstrate switch in Settings \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u6D4F\u89C8\u5668 Agent.",
3588
+ {
3589
+ message: {
3590
+ type: "string",
3591
+ required: true,
3592
+ description: `What to show, in the user's language, e.g. "Show me how you export the report, then click Continue."`
3593
+ },
3594
+ timeoutMs: {
3595
+ type: "number",
3596
+ description: "How long to wait for the user, in ms (default 300000)."
3597
+ }
3598
+ },
3599
+ async (args, exec) => {
3600
+ guardEnabled();
3601
+ requireDemonstrate();
3602
+ const sessionId = sessionIdOf(exec);
3603
+ const message = String(args.message ?? "").trim();
3604
+ if (message === "") throw new Error("message is required");
3605
+ const timeoutRaw = Number(args.timeoutMs);
3606
+ const timeoutMs = Number.isFinite(timeoutRaw) ? Math.min(Math.max(Math.trunc(timeoutRaw), 3e4), 9e5) : HUMAN_WAIT_TIMEOUT_MS;
3607
+ await ensureConnected();
3608
+ await ensureSessionTab(sessionId);
3609
+ const driver = driverOf(options);
3610
+ const tabId = options.sessions.tabOf(sessionId);
3611
+ await driver.startDemonstration();
3612
+ options.sessions.record({
3613
+ sessionId,
3614
+ tool: "browser_demonstrate",
3615
+ summary: message.slice(0, 160),
3616
+ outcome: "needs_human"
3617
+ });
3618
+ const status = await pauseForHuman({
3619
+ sessionId,
3620
+ prompt: message,
3621
+ detail: message.slice(0, 240),
3622
+ kind: "ask",
3623
+ ...tabId === void 0 ? {} : { tabId },
3624
+ signal: exec.signal
3625
+ });
3626
+ const steps = await driver.stopDemonstration().catch(() => []);
3627
+ if (status === "cancelled") {
3628
+ return "user_ack: cancelled\nAction: the demonstration was cancelled. Ask what they want next.";
3629
+ }
3630
+ const summary = summarizeDemoSteps(steps);
3631
+ options.sessions.record({
3632
+ sessionId,
3633
+ tool: "browser_demonstrate",
3634
+ summary: `Demonstrated ${summary.shown} step(s)`,
3635
+ outcome: "ok"
3636
+ });
3637
+ if (summary.shown === 0) {
3638
+ return [
3639
+ "demonstrated steps: 0",
3640
+ "Nothing was recorded \u2014 the user may have pressed Continue without acting, or the flow happened in another tab.",
3641
+ "Action: call browser_ask_user to check, or browser_snapshot and continue on your own."
3642
+ ].join("\n");
3643
+ }
3644
+ return [
3645
+ `demonstrated steps: ${summary.shown}${steps.length > summary.shown ? ` (of ${steps.length})` : ""}`,
3646
+ ...summary.masked > 0 ? [`masked fields: ${summary.masked} (secret values are never shown)`] : [],
3647
+ ...summary.lines,
3648
+ "Action: replay with browser_snapshot, then browser_click / browser_type by the role+name shown here. Refs change between runs; never invent selectors."
3649
+ ].join("\n");
3650
+ },
3651
+ HUMAN_WAIT_TIMEOUT_MS
3652
+ )));
3232
3653
  disposers.push(ctx.tools.register(textTool(
3233
3654
  "browser_list_tabs",
3234
3655
  "List open browser tabs (id, title, url, active, bound). Read-only; no approval. Use with browser_follow_tab to bind this session to another tab.",
@@ -3310,7 +3731,6 @@ title: ${result.title}`;
3310
3731
 
3311
3732
  // src/host/browser-agent/install.ts
3312
3733
  var IDLE_TICK_MS = 6e4;
3313
- var IDLE_CLOSE_MS = 10 * 6e4;
3314
3734
  function installBrowserAgent(ctx, options) {
3315
3735
  const approval = new BrowserApprovalGate();
3316
3736
  const human = new BrowserHumanGate();
@@ -3434,6 +3854,7 @@ function installBrowserAgent(ctx, options) {
3434
3854
  sessions,
3435
3855
  tabScope,
3436
3856
  debugTools: () => options.debugTools?.() === true,
3857
+ demonstrate: () => options.demonstrate?.() === true,
3437
3858
  diagnosis: diagnoseNow,
3438
3859
  // Gate on settings only — `active` flips false during driver align and
3439
3860
  // must not make browser_* look "disabled" mid-turn.
@@ -3495,6 +3916,7 @@ function installBrowserAgent(ctx, options) {
3495
3916
  };
3496
3917
  const refresh = () => {
3497
3918
  availabilityCache = null;
3919
+ if (options.debugTools?.() !== true) activeDriver?.stopCapture?.();
3498
3920
  const want = options.enabled();
3499
3921
  if (!want) {
3500
3922
  if (!active && playwrightDriver === null && unregisterTools === null && !switchPending) {
@@ -3519,12 +3941,14 @@ function installBrowserAgent(ctx, options) {
3519
3941
  };
3520
3942
  refresh();
3521
3943
  const sweepIdleTabs = async () => {
3522
- if (!options.enabled() || options.idleClose?.() !== true) return;
3944
+ if (!options.enabled()) return;
3945
+ const idleMs = browserAgentIdleCloseMs(options.idleClose?.() ?? "10m");
3946
+ if (idleMs === null) return;
3523
3947
  const driver = activeDriver;
3524
3948
  if (driver === null || driver.status().ready !== true) return;
3525
3949
  try {
3526
3950
  const closed = await driver.sweepIdleTabs({
3527
- idleMs: IDLE_CLOSE_MS,
3951
+ idleMs,
3528
3952
  keep: sessions.boundTabIds()
3529
3953
  });
3530
3954
  for (const tabId of closed) {
@@ -3601,6 +4025,46 @@ function installBrowserAgent(ctx, options) {
3601
4025
  });
3602
4026
  return { ok: true };
3603
4027
  },
4028
+ async demoStart() {
4029
+ if (!options.enabled()) return { ok: false, error: "Browser agent disabled" };
4030
+ if (options.demonstrate?.() !== true) {
4031
+ return { ok: false, error: "\u6F14\u793A\u5F55\u5236\u672A\u5F00\u542F\uFF1A\u8BBE\u7F6E \u2192 \u529F\u80FD \u2192 \u6D4F\u89C8\u5668 Agent" };
4032
+ }
4033
+ try {
4034
+ const aligned = await alignToPreference();
4035
+ if (!aligned.ok) return { ok: false, error: aligned.error ?? "Browser agent failed to start" };
4036
+ await requireDriver().startDemonstration();
4037
+ sessions.record({
4038
+ sessionId: "sidebar",
4039
+ tool: "browser_demonstrate",
4040
+ summary: "Demonstration recording started from the sidebar",
4041
+ outcome: "needs_human"
4042
+ });
4043
+ return { ok: true };
4044
+ } catch (error) {
4045
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
4046
+ }
4047
+ },
4048
+ async demoStop() {
4049
+ const driver = activeDriver;
4050
+ if (driver === null) return { ok: false, error: "Browser agent is not running" };
4051
+ try {
4052
+ const steps = await driver.stopDemonstration();
4053
+ const summary = summarizeDemoSteps(steps);
4054
+ sessions.record({
4055
+ sessionId: "sidebar",
4056
+ tool: "browser_demonstrate",
4057
+ summary: `Demonstration stopped from the sidebar (${summary.shown} step(s))`,
4058
+ outcome: "ok"
4059
+ });
4060
+ return { ok: true, steps: summary.lines };
4061
+ } catch (error) {
4062
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
4063
+ }
4064
+ },
4065
+ demoActive() {
4066
+ return activeDriver?.demonstrationActive() === true;
4067
+ },
3604
4068
  async selectTab(input) {
3605
4069
  if (!options.enabled()) return { ok: false, error: "Browser agent disabled" };
3606
4070
  await switchGate.catch(() => void 0);
@@ -15762,6 +16226,11 @@ var browserAgentSnapshotSchema = z4.strictObject({
15762
16226
  pending: browserAgentPendingSchema.nullable(),
15763
16227
  /** Why the browser is (not) usable and the concrete next step. */
15764
16228
  diagnosis: browserAgentDiagnosisSchema,
16229
+ /** Demonstration recorder: switch state and whether it is recording now. */
16230
+ demo: z4.strictObject({
16231
+ enabled: z4.boolean(),
16232
+ recording: z4.boolean()
16233
+ }),
15765
16234
  tabConflict: browserAgentTabConflictSchema.nullable(),
15766
16235
  needsHuman: browserAgentNeedsHumanSchema.nullable(),
15767
16236
  boundTabId: z4.number().int().nullable(),
@@ -15775,6 +16244,24 @@ var browserAgentSnapshotCodec = codec(
15775
16244
  "dsh-agent-enhancer#BrowserAgentSnapshot",
15776
16245
  browserAgentSnapshotSchema
15777
16246
  );
16247
+ var browserAgentDemoRequestSchema = z4.strictObject({
16248
+ action: z4.enum(["start", "stop"])
16249
+ });
16250
+ var browserAgentDemoRequestCodec = codec(
16251
+ "dsh-agent-enhancer#BrowserAgentDemoRequest",
16252
+ browserAgentDemoRequestSchema
16253
+ );
16254
+ var browserAgentDemoResultSchema = z4.strictObject({
16255
+ ok: z4.boolean(),
16256
+ /** One line per recorded step, when stopping. */
16257
+ steps: z4.array(z4.string()).optional(),
16258
+ error: z4.string().optional(),
16259
+ snapshot: browserAgentSnapshotSchema
16260
+ });
16261
+ var browserAgentDemoResultCodec = codec(
16262
+ "dsh-agent-enhancer#BrowserAgentDemoResult",
16263
+ browserAgentDemoResultSchema
16264
+ );
15778
16265
  var browserAgentResolveRequestSchema = z4.strictObject({
15779
16266
  id: z4.string().min(1),
15780
16267
  decision: browserAgentApprovalDecisionSchema
@@ -16669,6 +17156,18 @@ var remoteInfo = createTypertRemoteInfo({
16669
17156
  }],
16670
17157
  result: browserAgentSelectTabResultCodec
16671
17158
  },
17159
+ "agentEnhancer/browserAgentDemo": {
17160
+ service: "agentEnhancer",
17161
+ implementation: "browserAgentDemo",
17162
+ invocation: { kind: "direct" },
17163
+ parameters: [{
17164
+ name: "request",
17165
+ source: "json",
17166
+ codec: browserAgentDemoRequestCodec,
17167
+ strictCodec: browserAgentDemoRequestCodec
17168
+ }],
17169
+ result: browserAgentDemoResultCodec
17170
+ },
16672
17171
  "agentEnhancer/browserAgentSetTabReadOnly": {
16673
17172
  service: "agentEnhancer",
16674
17173
  implementation: "browserAgentSetTabReadOnly",
@@ -17358,8 +17857,10 @@ var Config = z5.object({
17358
17857
  browserAgentBrowser: z5.string().default("auto").volatile(),
17359
17858
  /** Debug tools (network / console / emulate); default off, gated per tool. */
17360
17859
  browserAgentDebugTools: z5.boolean().default(false).volatile(),
17361
- /** Close idle agent tabs after ~10 min; default on, never the bound/active tab. */
17362
- browserAgentIdleClose: z5.boolean().default(true).volatile(),
17860
+ /** "Show me" recorder; observes user actions in the bound tab, default off. */
17861
+ browserAgentDemonstrate: z5.boolean().default(false).volatile(),
17862
+ /** Close idle agent tabs after ~10 min; coerced via resolveBrowserAgentIdleClose. */
17863
+ browserAgentIdleClose: z5.union([z5.boolean(), z5.string()]).default("10m").volatile(),
17363
17864
  /** Default off; embeds official web chat + import to work. */
17364
17865
  webChatBridgeEnabled: z5.boolean().default(true).volatile(),
17365
17866
  instructionsSkillsEnabled: z5.boolean().default(true).volatile(),
@@ -17411,7 +17912,8 @@ var AgentEnhancerService = class extends TypertRemoteService {
17411
17912
  join30(homedir5(), ".dsh", "profiles", "desktop", "plugin-data", PACKAGE_NAME, "extra-folders")
17412
17913
  ), softPause = new SoftPauseGate(), softPauseEnabled = () => true, installLedgerRoot = void 0, mcpHost = null, browserAgent = null, browserAgentSettings = () => ({
17413
17914
  enabled: false,
17414
- browser: "auto"
17915
+ browser: "auto",
17916
+ demonstrate: false
17415
17917
  }), setBrowserAgentBrowser = () => void 0, browserAgentProfileDir = defaultBrowserAgentProfileDir(
17416
17918
  join30(homedir5(), ".dsh", "profiles", "desktop", "plugin-data", PACKAGE_NAME)
17417
17919
  )) {
@@ -17483,6 +17985,10 @@ var AgentEnhancerService = class extends TypertRemoteService {
17483
17985
  ...pending.url === void 0 ? {} : { url: pending.url },
17484
17986
  ...pending.origin === void 0 ? {} : { origin: pending.origin }
17485
17987
  },
17988
+ demo: {
17989
+ enabled: settings.demonstrate,
17990
+ recording: this.browserAgent?.demoActive() === true
17991
+ },
17486
17992
  diagnosis: diag ?? {
17487
17993
  code: settings.enabled ? "idle" : "disabled",
17488
17994
  nextStep: settings.enabled ? "Nothing launched yet. Call browser_navigate (or Alt+click a chat link) to launch the dedicated browser." : "Browser agent is off. Enable it in \u8BBE\u7F6E \u2192 \u667A\u80FD\u4F53\u589E\u5F3A \u2192 \u529F\u80FD.",
@@ -18190,6 +18696,24 @@ var AgentEnhancerService = class extends TypertRemoteService {
18190
18696
  snapshot: await this.browserSnapshotNow()
18191
18697
  };
18192
18698
  }
18699
+ async browserAgentDemo(request) {
18700
+ this.assertOwner();
18701
+ if (request.action === "start") {
18702
+ const result = await (this.browserAgent?.demoStart() ?? Promise.resolve({ ok: false, error: "runtime unavailable" }));
18703
+ return {
18704
+ ok: result.ok === true,
18705
+ ...result.error === void 0 ? {} : { error: result.error },
18706
+ snapshot: await this.browserSnapshotNow()
18707
+ };
18708
+ }
18709
+ const stopped = await (this.browserAgent?.demoStop() ?? Promise.resolve({ ok: false, error: "runtime unavailable" }));
18710
+ return {
18711
+ ok: stopped.ok === true,
18712
+ ...stopped.steps === void 0 ? {} : { steps: [...stopped.steps] },
18713
+ ...stopped.error === void 0 ? {} : { error: stopped.error },
18714
+ snapshot: await this.browserSnapshotNow()
18715
+ };
18716
+ }
18193
18717
  async browserAgentSetTabReadOnly(request) {
18194
18718
  this.assertOwner();
18195
18719
  const result = this.browserAgent?.setTabReadOnly({
@@ -18286,7 +18810,8 @@ function readSettings(config) {
18286
18810
  browserAgentEnabled: config.browserAgentEnabled.get(),
18287
18811
  browserAgentBrowser: hostBrowserPreference(config.browserAgentBrowser.get()),
18288
18812
  browserAgentDebugTools: config.browserAgentDebugTools.get(),
18289
- browserAgentIdleClose: config.browserAgentIdleClose.get(),
18813
+ browserAgentDemonstrate: config.browserAgentDemonstrate.get(),
18814
+ browserAgentIdleClose: resolveBrowserAgentIdleClose(config.browserAgentIdleClose.get()),
18290
18815
  webChatBridgeEnabled: config.webChatBridgeEnabled.get(),
18291
18816
  instructionsSkillsEnabled: config.instructionsSkillsEnabled.get(),
18292
18817
  mcpConnectorsEnabled: config.mcpConnectorsEnabled.get(),
@@ -18368,12 +18893,14 @@ function apply(ctx, config) {
18368
18893
  const browserAgentProfileDir = defaultBrowserAgentProfileDir(pluginDataPackageRoot);
18369
18894
  const browserAgentLive = {
18370
18895
  enabled: settings().browserAgentEnabled,
18371
- browser: settings().browserAgentBrowser
18896
+ browser: settings().browserAgentBrowser,
18897
+ demonstrate: settings().browserAgentDemonstrate
18372
18898
  };
18373
18899
  const browserAgent = installBrowserAgent(ctx, {
18374
18900
  enabled: () => browserAgentLive.enabled,
18375
18901
  browserPreference: () => browserAgentLive.browser,
18376
18902
  debugTools: () => settings().browserAgentDebugTools,
18903
+ demonstrate: () => settings().browserAgentDemonstrate,
18377
18904
  idleClose: () => settings().browserAgentIdleClose,
18378
18905
  profileRoot: pluginDataPackageRoot,
18379
18906
  softPause: softPauseGate,
@@ -18421,7 +18948,8 @@ function apply(ctx, config) {
18421
18948
  browserAgent,
18422
18949
  () => ({
18423
18950
  enabled: browserAgentLive.enabled,
18424
- browser: browserAgentLive.browser
18951
+ browser: browserAgentLive.browser,
18952
+ demonstrate: browserAgentLive.demonstrate
18425
18953
  }),
18426
18954
  (browser) => {
18427
18955
  browserAgentLive.browser = hostBrowserPreference(browser);
@@ -18440,6 +18968,7 @@ function apply(ctx, config) {
18440
18968
  const prevBrowser = browserAgentLive.browser;
18441
18969
  browserAgentLive.enabled = cfg.browserAgentEnabled.get();
18442
18970
  browserAgentLive.browser = hostBrowserPreference(cfg.browserAgentBrowser.get());
18971
+ browserAgentLive.demonstrate = cfg.browserAgentDemonstrate.get();
18443
18972
  browserAgent.refresh();
18444
18973
  if (browserAgentLive.enabled && prevBrowser !== browserAgentLive.browser && browserAgent.driverStatus()?.ready === true) {
18445
18974
  void browserAgent.alignToPreference().catch((error) => {