dsh-builtin-browser 1.0.1 → 1.0.4

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 (222) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +1 -1
  3. package/assets/browser-panel-locales.mjs +37 -5
  4. package/assets/browser-policy.d.mts +29 -0
  5. package/assets/browser-policy.mjs +40 -0
  6. package/desktop-bridge/desktop-discovery.d.mts +1 -1
  7. package/desktop-bridge/desktop-discovery.mjs +59 -9
  8. package/desktop-bridge/desktop-identity.json +12 -0
  9. package/desktop-bridge/install.mjs +14 -7
  10. package/desktop-bridge/plugin-browser-bridge.js +19 -7
  11. package/docs/acceptance-2026-11-27.md +67 -0
  12. package/docs/architecture.md +1 -1
  13. package/docs/development.md +33 -4
  14. package/docs/dsh-0.2.3-host-patch-task.md +34 -0
  15. package/docs/hardcoding-audit.md +28 -8
  16. package/docs/known-issues.md +26 -0
  17. package/docs/limitations.md +6 -2
  18. package/docs/tool-reference.md +1 -1
  19. package/docs/v1.1.0-bu-data-batching-task.md +66 -0
  20. package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
  21. package/dsh-host-patch/README.md +4 -0
  22. package/dsh-host-patch/apply.mjs +61 -13
  23. package/dsh-host-patch/rc3-revision9.json.gz +0 -0
  24. package/dsh-host-patch/rc5-revision9.json.gz +0 -0
  25. package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
  26. package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
  27. package/dsh-host-patch/tauri-revision1.json +39 -0
  28. package/dsh-host-patch/tauri.json +43 -0
  29. package/dsh-host-patch/v023-alpha2.json +153 -0
  30. package/lib/browser/anti-bot.js +215 -0
  31. package/lib/browser/deep-dom.js +39 -0
  32. package/lib/browser/runtime.js +15 -0
  33. package/lib/browser/takeover-target.js +13 -6
  34. package/lib/browser/types.js +30 -1
  35. package/lib/browser-electron/authenticated-route.js +16 -2
  36. package/lib/browser-electron/automatic-maintenance.js +16 -10
  37. package/lib/browser-electron/bridge-connection.js +3 -8
  38. package/lib/browser-electron/bridge-install.js +2 -1
  39. package/lib/browser-electron/bridge-status.js +55 -26
  40. package/lib/browser-electron/desktop-bridge-host.js +7 -6
  41. package/lib/browser-electron/desktop-identity.js +28 -5
  42. package/lib/browser-electron/desktop-shell.js +64 -0
  43. package/lib/browser-electron/electron-provision.js +105 -18
  44. package/lib/browser-electron/entry.js +129 -44
  45. package/lib/browser-electron/extension-browser.js +4 -4
  46. package/lib/browser-electron/foreground-watch.js +134 -0
  47. package/lib/browser-electron/guest-cookie-jar.js +13 -13
  48. package/lib/browser-electron/guest-route.js +181 -32
  49. package/lib/browser-electron/guest-runtime.js +61 -10
  50. package/lib/browser-electron/guest-storage.js +2 -2
  51. package/lib/browser-electron/history-store.js +1 -5
  52. package/lib/browser-electron/host-main.js +8 -4
  53. package/lib/browser-electron/host-patch-maintenance.js +14 -8
  54. package/lib/browser-electron/maintenance-route.js +2 -1
  55. package/lib/browser-electron/missing-system-browser.js +5 -9
  56. package/lib/browser-electron/preferred-browser.js +7 -3
  57. package/lib/browser-electron/preview-route.js +9 -13
  58. package/lib/browser-electron/process-ownership.js +1 -1
  59. package/lib/browser-electron/profile-command.js +2 -1
  60. package/lib/browser-electron/profile-extension.js +5 -0
  61. package/lib/browser-electron/profile-lease.js +152 -47
  62. package/lib/browser-electron/provider-core.js +527 -0
  63. package/lib/browser-electron/provider-interaction.js +963 -0
  64. package/lib/browser-electron/provider-media.js +518 -0
  65. package/lib/browser-electron/provider-navigation.js +301 -0
  66. package/lib/browser-electron/provider-observation.js +623 -0
  67. package/lib/browser-electron/provider-tabs.js +372 -0
  68. package/lib/browser-electron/provider.js +150 -3301
  69. package/lib/browser-electron/reference-route.js +9 -18
  70. package/lib/browser-electron/remote-host.js +79 -34
  71. package/lib/browser-electron/runtime-status.js +56 -6
  72. package/lib/browser-electron/settings-store.js +3 -6
  73. package/lib/browser-electron/sidebar-only-host.js +1 -1
  74. package/lib/browser-electron/system-browser.js +539 -172
  75. package/lib/browser-electron/tauri-host.js +208 -0
  76. package/lib/browser-electron/virtual-cursor.js +23 -13
  77. package/lib/browser-reference/service.js +22 -4
  78. package/lib/browser-reference/web-sources.js +1 -1
  79. package/lib/client.js +43409 -0
  80. package/lib/compat/host-features.js +75 -0
  81. package/lib/reference-source.js +1 -1
  82. package/lib/reference-text.js +23 -1
  83. package/lib/takeover-protocol.js +1 -1
  84. package/lib/tool-browser/block-recovery.js +69 -0
  85. package/lib/tool-browser/code-tool.js +170 -19
  86. package/lib/tool-browser/code-worker.js +115 -20
  87. package/lib/tool-browser/errors.js +34 -0
  88. package/lib/tool-browser/index.js +66 -3593
  89. package/lib/tool-browser/page-probe.js +227 -28
  90. package/lib/tool-browser/panel-page.js +2 -1
  91. package/lib/tool-browser/probe-client.js +157 -0
  92. package/lib/tool-browser/screenshot-annotations.js +108 -0
  93. package/lib/tool-browser/state.js +337 -0
  94. package/lib/tool-browser/takeover.js +1 -1
  95. package/lib/tool-browser/tools-debug.js +862 -0
  96. package/lib/tool-browser/tools-interaction.js +993 -0
  97. package/lib/tool-browser/tools-navigation.js +807 -0
  98. package/lib/tool-browser/tools-observation.js +461 -0
  99. package/lib/tool-browser/tools-reference.js +293 -0
  100. package/lib/web-guest.js +1 -0
  101. package/package.json +16 -36
  102. package/scripts/build-client.mjs +305 -0
  103. package/scripts/build.mjs +15 -12
  104. package/scripts/fix-exports.mjs +6 -16
  105. package/scripts/install-electron.mjs +55 -5
  106. package/scripts/pack.mjs +99 -0
  107. package/scripts/publish-manifest.mjs +56 -0
  108. package/scripts/verify-exports.mjs +26 -15
  109. package/skills/dsh-builtin-browser/SKILL.md +27 -2
  110. package/skills/dsh-builtin-browser/references/batch.md +15 -0
  111. package/src/browser/anti-bot.ts +251 -0
  112. package/src/browser/deep-dom.ts +40 -0
  113. package/src/browser/runtime.ts +18 -0
  114. package/src/browser/takeover-target.ts +16 -7
  115. package/src/browser/types.ts +56 -3
  116. package/src/browser-electron/authenticated-route.ts +29 -4
  117. package/src/browser-electron/automatic-maintenance.ts +23 -13
  118. package/src/browser-electron/bridge-connection.ts +11 -10
  119. package/src/browser-electron/bridge-install.ts +2 -1
  120. package/src/browser-electron/bridge-status.ts +61 -22
  121. package/src/browser-electron/desktop-bridge-host.ts +9 -7
  122. package/src/browser-electron/desktop-identity.ts +38 -5
  123. package/src/browser-electron/desktop-shell.ts +100 -0
  124. package/src/browser-electron/electron-provision.ts +104 -18
  125. package/src/browser-electron/entry.ts +1378 -1299
  126. package/src/browser-electron/extension-browser.ts +11 -4
  127. package/src/browser-electron/foreground-watch.ts +142 -0
  128. package/src/browser-electron/guest-cookie-jar.ts +3 -2
  129. package/src/browser-electron/guest-route.ts +180 -32
  130. package/src/browser-electron/guest-runtime.ts +61 -10
  131. package/src/browser-electron/guest-storage.ts +5 -2
  132. package/src/browser-electron/history-store.ts +3 -6
  133. package/src/browser-electron/host-main.ts +8 -4
  134. package/src/browser-electron/host-patch-maintenance.ts +18 -9
  135. package/src/browser-electron/maintenance-route.ts +2 -1
  136. package/src/browser-electron/missing-system-browser.ts +11 -10
  137. package/src/browser-electron/preferred-browser.ts +13 -3
  138. package/src/browser-electron/preview-route.ts +9 -12
  139. package/src/browser-electron/process-ownership.ts +9 -3
  140. package/src/browser-electron/profile-command.ts +2 -1
  141. package/src/browser-electron/profile-extension.ts +5 -0
  142. package/src/browser-electron/profile-lease.ts +131 -35
  143. package/src/browser-electron/provider-core.ts +1107 -0
  144. package/src/browser-electron/provider-interaction.ts +1034 -0
  145. package/src/browser-electron/provider-media.ts +589 -0
  146. package/src/browser-electron/provider-navigation.ts +323 -0
  147. package/src/browser-electron/provider-observation.ts +664 -0
  148. package/src/browser-electron/provider-tabs.ts +372 -0
  149. package/src/browser-electron/provider.ts +158 -4063
  150. package/src/browser-electron/reference-route.ts +598 -608
  151. package/src/browser-electron/remote-host.ts +118 -42
  152. package/src/browser-electron/runtime-status.ts +80 -13
  153. package/src/browser-electron/settings-store.ts +10 -6
  154. package/src/browser-electron/sidebar-only-host.ts +4 -2
  155. package/src/browser-electron/system-browser.ts +537 -184
  156. package/src/browser-electron/tauri-host.ts +194 -0
  157. package/src/browser-electron/virtual-cursor.ts +24 -14
  158. package/src/browser-reference/service.ts +38 -7
  159. package/src/browser-reference/web-sources.ts +4 -1
  160. package/src/client/apply-guard.ts +22 -0
  161. package/src/client/browser/BrowserController.ts +3 -3
  162. package/src/client/browser/IframeImpl.ts +182 -176
  163. package/src/client/browser/frame-history.ts +125 -0
  164. package/src/client/browser/frame-state.ts +27 -0
  165. package/src/client/browser/web-reference-source.ts +5 -1
  166. package/src/client/definition.tsx +36 -30
  167. package/src/client/electron/ElectronWebViewImpl.ts +20 -13
  168. package/src/client/electron/ElectronWebviewPresentation.ts +4 -2
  169. package/src/client/electron/NativeChildPresentation.ts +11 -3
  170. package/src/client/electron/NativeViewPage.ts +19 -5
  171. package/src/client/index.ts +333 -293
  172. package/src/client/locales.ts +9 -6
  173. package/src/client/reference/client/plugin.ts +21 -2
  174. package/src/client/reference/client/production/ReferenceCapsules.tsx +3 -3
  175. package/src/client/reference/client/production/assembly.ts +4 -28
  176. package/src/client/reference/client/production/availability.ts +0 -2
  177. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  178. package/src/client/reference/client/production/draft-adapter.ts +4 -0
  179. package/src/client/reference/client/production/http-transport.ts +0 -5
  180. package/src/client/reference/client/production/production-submission.ts +50 -290
  181. package/src/client/reference/client/production/protocol.ts +7 -4
  182. package/src/client/reference/client/production/runtime.ts +41 -86
  183. package/src/client/reference/client/production/source-marker.ts +49 -13
  184. package/src/client/reference/client/production/user-text-rule.ts +10 -1
  185. package/src/client/reference/client/reveal.ts +3 -1
  186. package/src/client/reference/client/session-schedule.ts +36 -0
  187. package/src/client/settings/index.ts +8 -0
  188. package/src/client/settings/mount-guard.ts +31 -0
  189. package/src/client/settings/panel.ts +163 -52
  190. package/src/client/startpage/controller.ts +3 -6
  191. package/src/client/view/BrowserBody.tsx +2 -1
  192. package/src/client/view/IframePresentation.ts +37 -16
  193. package/src/client/view/StartPage.tsx +2 -1
  194. package/src/compat/host-features.ts +92 -0
  195. package/src/reference-source.ts +1 -1
  196. package/src/reference-text.ts +23 -1
  197. package/src/takeover-protocol.ts +11 -2
  198. package/src/tool-browser/block-recovery.ts +85 -0
  199. package/src/tool-browser/code-tool.ts +173 -19
  200. package/src/tool-browser/code-worker.ts +101 -15
  201. package/src/tool-browser/errors.ts +40 -0
  202. package/src/tool-browser/index.ts +66 -3534
  203. package/src/tool-browser/page-probe.ts +229 -28
  204. package/src/tool-browser/panel-page.ts +3 -1
  205. package/src/tool-browser/probe-client.ts +183 -0
  206. package/src/tool-browser/screenshot-annotations.ts +131 -0
  207. package/src/tool-browser/state.ts +375 -0
  208. package/src/tool-browser/takeover.ts +3 -2
  209. package/src/tool-browser/tools-debug.ts +806 -0
  210. package/src/tool-browser/tools-interaction.ts +956 -0
  211. package/src/tool-browser/tools-navigation.ts +786 -0
  212. package/src/tool-browser/tools-observation.ts +474 -0
  213. package/src/tool-browser/tools-reference.ts +294 -0
  214. package/src/web-guest.ts +35 -34
  215. package/dist/client.cjs +0 -43167
  216. package/dist/client.d.cts +0 -516
  217. package/dist/client.d.mts +0 -516
  218. package/dist/index.cjs +0 -92
  219. package/dist/index.d.mts +0 -2960
  220. package/dist/index.mjs +0 -24
  221. package/lib/browser-reference/submission-receipts.js +0 -139
  222. package/src/browser-reference/submission-receipts.ts +0 -122
@@ -25,34 +25,37 @@ function format(value) {
25
25
  }
26
26
  }
27
27
  const log = (...values) => { send({ type: 'log', text: values.map(format).join(' ') }); };
28
- async function ask(name, args = {}) {
29
- const id = ++seq;
30
- const reply = await new Promise(resolve => { pending.set(id, { resolve }); send({ type: 'call', id, name, args }); });
31
- if (reply.error !== undefined)
32
- throw new Error(reply.error);
33
- return reply;
34
- }
35
- const value = async (name, args) => (await ask(name, args)).value;
36
- /** A failed `tools.*` call, named after the tool, like DSH run_code's ToolCallError. */
28
+ const SLEEP_HINT_AFTER = 3;
29
+ const SLEEP_HINT = `[hint] sleep() called ${SLEEP_HINT_AFTER} times in this cell; wait on the condition instead: wait_for_element, wait_for_text, wait_for_gone, wait_until(expr) or wait_for_response(url, trigger).`;
30
+ let sleepsThisCell = 0;
31
+ /** A failed browser tool call (a helper or `tools.*`), named after the tool, like DSH run_code's ToolCallError. */
37
32
  class ToolCallError extends Error {
38
33
  toolName;
39
- constructor(toolName, message) {
34
+ code;
35
+ constructor(toolName, message, code) {
40
36
  super(message);
41
37
  this.name = 'ToolCallError';
42
38
  this.toolName = toolName;
39
+ this.code = code;
40
+ }
41
+ }
42
+ async function ask(name, args = {}) {
43
+ const id = ++seq;
44
+ const reply = await new Promise(resolve => { pending.set(id, { resolve }); send({ type: 'call', id, name, args }); });
45
+ if (reply.error !== undefined) {
46
+ if (name.startsWith('__'))
47
+ throw new Error(reply.error);
48
+ throw new ToolCallError(name.startsWith('dsh_browser_') ? name : `dsh_browser_${name}`, reply.error, reply.code);
43
49
  }
50
+ return reply;
44
51
  }
52
+ const value = async (name, args) => (await ask(name, args)).value;
45
53
  /** DSH run_code-style bindings: `await tools.dsh_browser_snapshot({})` resolves to the tool's JSON value. */
46
54
  const tools = new Proxy(Object.create(null), {
47
- get: (_target, name) => typeof name !== 'string' || name === 'then' ? undefined : async (args = {}) => {
48
- try {
49
- return (await ask(name, args)).value;
50
- }
51
- catch (error) {
52
- throw new ToolCallError(name, error instanceof Error ? error.message : String(error));
53
- }
54
- },
55
+ get: (_target, name) => typeof name !== 'string' || name === 'then' ? undefined : (args = {}) => value(name, args),
55
56
  });
57
+ /** The task's tabs, read without a trace entry (wait_for_new_tab polls this). */
58
+ const tabs = async () => (await value('__tabs')).tabs ?? [];
56
59
  const text = async (name, args) => (await ask(name, args)).text ?? '';
57
60
  const HTML_TAGS = new Set(['a', 'button', 'input', 'select', 'textarea', 'form', 'div', 'span', 'li', 'ul', 'ol', 'table', 'tr', 'td', 'th', 'tbody', 'thead', 'img', 'label', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'nav', 'main', 'header', 'footer', 'section', 'article', 'aside', 'option', 'summary', 'details', 'iframe', 'body', 'svg', 'dialog']);
58
61
  function looksLikeSelector(raw) {
@@ -752,6 +755,36 @@ const helpers = {
752
755
  list_tabs: () => value('list_tabs'),
753
756
  switch_tab: (tabId) => text('switch_tab', { tabId }),
754
757
  close_tab: (tabId) => text('close_tab', { tabId }),
758
+ wait_for_new_tab: async (trigger, timeoutMs) => {
759
+ const budget = typeof trigger === 'number' ? trigger : timeoutMs ?? 10_000;
760
+ const known = new Set((await tabs()).map(tab => tab.id));
761
+ if (typeof trigger === 'function')
762
+ await trigger();
763
+ const deadline = Date.now() + Math.min(Math.max(Number(budget) || 0, 0), 600_000);
764
+ for (;;) {
765
+ const fresh = (await tabs()).filter(tab => !known.has(tab.id));
766
+ if (fresh.length > 0)
767
+ return fresh[fresh.length - 1];
768
+ if (Date.now() >= deadline)
769
+ throw new Error(`no new tab opened within ${budget}ms`);
770
+ await new Promise(done => setTimeout(done, 150));
771
+ }
772
+ },
773
+ with_tab: async (tabId, fn) => {
774
+ if (typeof fn !== 'function')
775
+ throw new TypeError('with_tab(tabId, fn) needs a function');
776
+ const previous = (await tabs()).find(tab => tab.active)?.id;
777
+ if (previous !== tabId)
778
+ await text('switch_tab', { tabId });
779
+ try {
780
+ return await fn();
781
+ }
782
+ finally {
783
+ const now = await tabs();
784
+ if (previous !== undefined && now.find(tab => tab.active)?.id !== previous && now.some(tab => tab.id === previous))
785
+ await text('switch_tab', { tabId: previous });
786
+ }
787
+ },
755
788
  js: (script) => js(script),
756
789
  click_at_xy: (x, y) => text('click', { x, y }),
757
790
  type_text: (input) => text('type', { text: input }),
@@ -795,6 +828,49 @@ const helpers = {
795
828
  throw new Error(`wait_for_network_idle: ${out.reason ?? 'not idle'}`);
796
829
  return true;
797
830
  },
831
+ // Deterministic waits: each returns as soon as its condition holds and throws when it never does.
832
+ wait_for_text: async (needle, timeoutMs) => { await doStep('wait_for_text', { wait_text: { text: needle } }, timeoutMs); return true; },
833
+ wait_for_gone: async (needle, timeoutMs) => { await doStep('wait_for_gone', { wait_gone: { text: needle } }, timeoutMs); return true; },
834
+ wait_until: async (expression, opts = {}) => {
835
+ if (typeof expression !== 'string')
836
+ throw new Error('wait_until(expression): pass page JavaScript as a string, e.g. wait_until("document.querySelectorAll(\'.row\').length >= 20")');
837
+ const out = await doStep('wait_until', { wait_js: { script: pageScript(expression), ...opts.intervalMs !== undefined ? { intervalMs: opts.intervalMs } : {} } }, opts.timeoutMs ?? 10_000);
838
+ const raw = out.log.at(-1)?.value;
839
+ return raw === undefined ? true : JSON.parse(raw);
840
+ },
841
+ wait_for_response: async (urlContains, trigger, opts = {}) => {
842
+ if (typeof trigger === 'object' && trigger !== null) {
843
+ opts = trigger;
844
+ trigger = undefined;
845
+ }
846
+ // Sent before the trigger runs: the scheduler holds the trigger until the watcher has its cursor.
847
+ const pending = value('wait_for_response', { urlContains, ...opts });
848
+ pending.catch(() => undefined);
849
+ if (typeof trigger === 'function')
850
+ await trigger();
851
+ const out = await pending;
852
+ if (!out.matched)
853
+ throw new Error(`wait_for_response: ${out.reason}`);
854
+ return out.entry;
855
+ },
856
+ // Data first: what the page already holds, and its JSON APIs read with the page's own cookies.
857
+ inspect_data_sources: () => value('data_sources'),
858
+ fetch_json: async (url, init = {}) => {
859
+ const headers = { ...init.headers };
860
+ let body = init.body;
861
+ if (body !== undefined && typeof body !== 'string') {
862
+ body = JSON.stringify(body);
863
+ if (!Object.keys(headers).some(key => key.toLowerCase() === 'content-type'))
864
+ headers['content-type'] = 'application/json';
865
+ }
866
+ const out = await value('fetch_json', {
867
+ url,
868
+ ...init.method !== undefined ? { method: init.method } : {},
869
+ ...Object.keys(headers).length > 0 ? { headers } : {},
870
+ ...body !== undefined ? { body } : {},
871
+ });
872
+ return JSON.parse(out.body);
873
+ },
798
874
  upload_file: (selector, path) => text('upload', { target: { by: 'css', value: selector }, path }),
799
875
  // Semantic helpers over the dsh tools.
800
876
  click: (target) => text('click', targetArgs(target)),
@@ -835,17 +911,35 @@ const helpers = {
835
911
  },
836
912
  call: (name, args = {}) => value(name, args),
837
913
  help: (name) => value('__help', name === undefined ? {} : { name }),
838
- sleep: (ms) => new Promise(done => setTimeout(done, Math.min(Math.max(Number(ms) || 0, 0), 60_000))),
914
+ sleep: (ms) => {
915
+ if (++sleepsThisCell === SLEEP_HINT_AFTER)
916
+ log(SLEEP_HINT);
917
+ return new Promise(done => setTimeout(done, Math.min(Math.max(Number(ms) || 0, 0), 60_000)));
918
+ },
839
919
  print: log,
840
920
  log,
841
921
  console: { log, info: log, warn: log, error: log, debug: log },
842
922
  };
923
+ async function doStep(label, step, timeoutMs) {
924
+ const out = await value('do', { steps: [step], ...timeoutMs !== undefined ? { timeoutMs } : {} });
925
+ if (!out.ok)
926
+ throw new Error(`${label}: ${out.reason ?? 'condition never held'}`);
927
+ return out;
928
+ }
843
929
  async function js(script) {
844
930
  const out = await value('execute', { script: pageScript(script) });
845
931
  if (!out.ok)
846
932
  throw new Error(`js: ${out.exception ?? 'page script failed'}`);
847
933
  return out.value === undefined ? undefined : JSON.parse(out.value);
848
934
  }
935
+ /** How a cell's uncaught error reads in the output: a tool failure names its tool. */
936
+ function describe(error) {
937
+ if (!(error instanceof Error))
938
+ return String(error);
939
+ if (error instanceof ToolCallError)
940
+ return `ToolCallError (${error.toolName}): ${error.message}`;
941
+ return `${error.name === 'Error' ? '' : `${error.name}: `}${error.message}`;
942
+ }
849
943
  const context = createContext({ ...helpers, open: helpers.goto_url, press: helpers.press_key, tools, ToolCallError });
850
944
  process.on('message', (message) => {
851
945
  if (message.type === 'reply') {
@@ -855,6 +949,7 @@ process.on('message', (message) => {
855
949
  return;
856
950
  }
857
951
  if (message.type === 'run') {
952
+ sleepsThisCell = 0;
858
953
  void (async () => {
859
954
  try {
860
955
  const result = await runInContext(`(async () => {\n${prepare(message.code)}\n})()`, context, { filename: 'cell.js' });
@@ -863,7 +958,7 @@ process.on('message', (message) => {
863
958
  send({ type: 'done', ok: true });
864
959
  }
865
960
  catch (error) {
866
- send({ type: 'done', ok: false, error: error instanceof Error ? `${error.name === 'Error' ? '' : `${error.name}: `}${error.message}` : String(error) });
961
+ send({ type: 'done', ok: false, error: describe(error) });
867
962
  }
868
963
  })();
869
964
  }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Structured failures of the dsh_browser_* tools.
3
+ *
4
+ * DSH records `error: { name, code }` on `tool/result` only for a thrown `HarnessError`, and PTC
5
+ * programs see the same class, so every browser tool failure leaves as one.
6
+ * @module dsh-browser/tool-browser/errors
7
+ */
8
+ import { HarnessError } from '@deepseek-ai/dsh-error';
9
+ /** A browser tool failure with a stable code; the message is what the model sees. */
10
+ export class BrowserToolError extends HarnessError {
11
+ constructor(message, code, options) {
12
+ super(message, code, options);
13
+ this.name = 'BrowserToolError';
14
+ }
15
+ }
16
+ /**
17
+ * The error a browser tool rethrows: HarnessErrors and cancellations unchanged, anything else with
18
+ * the same message, the original as `cause`, and its own string `code` (e.g.
19
+ * `BROWSER_BRIDGE_VERSION_MISMATCH`) or `BROWSER_TOOL_FAILED`.
20
+ * @param error - what the tool threw.
21
+ * @param signal - the call's abort signal, if any.
22
+ */
23
+ export function toBrowserToolError(error, signal) {
24
+ if (error instanceof HarnessError)
25
+ return error;
26
+ if (signal?.aborted === true)
27
+ return error;
28
+ if (error instanceof Error && error.name === 'AbortError')
29
+ return error;
30
+ const message = error instanceof Error ? error.message : String(error);
31
+ const own = error?.code;
32
+ const code = typeof own === 'string' && own !== '' ? own : 'BROWSER_TOOL_FAILED';
33
+ return new BrowserToolError(message, code, { cause: error });
34
+ }