typeclaw 0.50.0 → 0.52.0

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 (258) hide show
  1. package/dist/types/agent/bash-sandbox-env.d.ts +17 -0
  2. package/dist/types/agent/bash-sandbox-proc.d.ts +8 -0
  3. package/dist/types/agent/bash-sandbox.d.ts +98 -0
  4. package/dist/types/agent/compaction.d.ts +4 -4
  5. package/dist/types/agent/idle-compaction.d.ts +1 -0
  6. package/dist/types/agent/index.d.ts +10 -17
  7. package/dist/types/agent/multimodal/look-at.d.ts +1 -1
  8. package/dist/types/agent/output-allowance.d.ts +4 -0
  9. package/dist/types/agent/plugin-tools.d.ts +8 -75
  10. package/dist/types/agent/prompt-cache-key.d.ts +1 -0
  11. package/dist/types/agent/session-tail.d.ts +12 -0
  12. package/dist/types/agent/subagents.d.ts +5 -0
  13. package/dist/types/agent/system-prompt-composition.d.ts +18 -0
  14. package/dist/types/agent/system-prompt.d.ts +2 -0
  15. package/dist/types/agent/tools/channel-disengage.d.ts +1 -1
  16. package/dist/types/agent/tools/channel-edit.d.ts +1 -1
  17. package/dist/types/agent/tools/channel-fetch-attachment.d.ts +1 -1
  18. package/dist/types/agent/tools/channel-handoff.d.ts +1 -1
  19. package/dist/types/agent/tools/channel-history.d.ts +1 -1
  20. package/dist/types/agent/tools/channel-react.d.ts +1 -1
  21. package/dist/types/agent/tools/channel-read.d.ts +10 -2
  22. package/dist/types/agent/tools/channel-reply.d.ts +1 -1
  23. package/dist/types/agent/tools/channel-send.d.ts +1 -1
  24. package/dist/types/agent/tools/channel-session-search.d.ts +1 -1
  25. package/dist/types/agent/tools/ddg.d.ts +9 -0
  26. package/dist/types/agent/tools/grant-role.d.ts +1 -1
  27. package/dist/types/agent/tools/post-github-review.d.ts +1 -1
  28. package/dist/types/agent/tools/restart.d.ts +1 -1
  29. package/dist/types/agent/tools/skip-response.d.ts +1 -1
  30. package/dist/types/agent/tools/spawn-subagent.d.ts +2 -1
  31. package/dist/types/agent/tools/stream-snapshot.d.ts +2 -2
  32. package/dist/types/agent/tools/subagent-cancel.d.ts +1 -1
  33. package/dist/types/agent/tools/subagent-output.d.ts +1 -1
  34. package/dist/types/agent/tools/todo/index.d.ts +1 -1
  35. package/dist/types/agent/tools/webfetch/adaptive-html.d.ts +3 -3
  36. package/dist/types/agent/tools/webfetch/strategies/readability-process.d.ts +48 -0
  37. package/dist/types/agent/tools/webfetch/tool.d.ts +2 -2
  38. package/dist/types/agent/tools/websearch.d.ts +1 -1
  39. package/dist/types/channels/adapters/github/auth-app.d.ts +25 -0
  40. package/dist/types/channels/adapters/github/auth-pat.d.ts +17 -0
  41. package/dist/types/channels/adapters/github/auth.d.ts +24 -0
  42. package/dist/types/channels/github-review-check.d.ts +1 -1
  43. package/dist/types/channels/github-token-bridge.d.ts +4 -0
  44. package/dist/types/channels/lost-background-context.d.ts +2 -0
  45. package/dist/types/channels/persistence.d.ts +1 -0
  46. package/dist/types/channels/router.d.ts +16 -50
  47. package/dist/types/channels/types.d.ts +1 -0
  48. package/dist/types/coding-agent/tool.d.ts +1 -1
  49. package/dist/types/config/config.d.ts +22 -0
  50. package/dist/types/config/providers.d.ts +50 -1
  51. package/dist/types/container/start.d.ts +1 -0
  52. package/dist/types/eval/cell.d.ts +26 -0
  53. package/dist/types/eval/config.d.ts +19 -0
  54. package/dist/types/eval/dispatch.d.ts +7 -0
  55. package/dist/types/eval/kernel.d.ts +28 -0
  56. package/dist/types/eval/process.d.ts +23 -0
  57. package/dist/types/eval/protocol.d.ts +34 -0
  58. package/dist/types/eval/sandbox.d.ts +12 -0
  59. package/dist/types/eval/tool.d.ts +17 -0
  60. package/dist/types/eval/wire.d.ts +33 -0
  61. package/dist/types/git/resolve-identity.d.ts +2 -0
  62. package/dist/types/init/dockerfile.d.ts +1 -0
  63. package/dist/types/init/gitignore.d.ts +1 -1
  64. package/dist/types/permissions/builtins.d.ts +1 -0
  65. package/dist/types/plugin/types.d.ts +3 -0
  66. package/dist/types/sandbox/canonical-secrets.d.ts +2 -2
  67. package/dist/types/sandbox/coding-agent.d.ts +1 -1
  68. package/dist/types/sandbox/dependency-bins.d.ts +1 -0
  69. package/dist/types/sandbox/dev-source.d.ts +2 -2
  70. package/dist/types/sandbox/env-exposure.d.ts +2 -0
  71. package/dist/types/sandbox/hidden-paths.d.ts +1 -0
  72. package/dist/types/sandbox/index.d.ts +1 -1
  73. package/dist/types/sandbox/policy.d.ts +3 -0
  74. package/dist/types/typevault/cli-path.d.ts +2 -0
  75. package/dist/types/typevault/envelope-store.d.ts +11 -0
  76. package/dist/types/typevault/lifecycle.d.ts +13 -0
  77. package/dist/types/typevault/vault.d.ts +27 -0
  78. package/package.json +8 -7
  79. package/scripts/test.ts +252 -0
  80. package/src/agent/bash-sandbox-env.ts +136 -0
  81. package/src/agent/bash-sandbox-proc.ts +70 -0
  82. package/src/agent/bash-sandbox.ts +239 -0
  83. package/src/agent/compaction.ts +22 -10
  84. package/src/agent/idle-compaction.ts +7 -3
  85. package/src/agent/index.ts +185 -187
  86. package/src/agent/multimodal/look-at.ts +1 -1
  87. package/src/agent/output-allowance.ts +7 -0
  88. package/src/agent/plugin-tools.ts +64 -380
  89. package/src/agent/prompt-cache-key.ts +26 -3
  90. package/src/agent/session-origin.ts +41 -19
  91. package/src/agent/session-tail.ts +28 -0
  92. package/src/agent/subagent-completion-reminder.ts +2 -2
  93. package/src/agent/subagents.ts +21 -2
  94. package/src/agent/system-prompt-composition.ts +159 -0
  95. package/src/agent/system-prompt.ts +43 -5
  96. package/src/agent/todo/scope.ts +1 -1
  97. package/src/agent/tool-error-remediation.ts +18 -3
  98. package/src/agent/tools/channel-disengage.ts +1 -1
  99. package/src/agent/tools/channel-edit.ts +1 -1
  100. package/src/agent/tools/channel-fetch-attachment.ts +1 -1
  101. package/src/agent/tools/channel-handoff.ts +3 -2
  102. package/src/agent/tools/channel-history.ts +2 -1
  103. package/src/agent/tools/channel-react.ts +1 -1
  104. package/src/agent/tools/channel-read.ts +36 -3
  105. package/src/agent/tools/channel-reply.ts +1 -1
  106. package/src/agent/tools/channel-send.ts +4 -3
  107. package/src/agent/tools/channel-session-search.ts +13 -4
  108. package/src/agent/tools/ddg.ts +71 -11
  109. package/src/agent/tools/grant-role.ts +1 -1
  110. package/src/agent/tools/post-github-review.ts +1 -1
  111. package/src/agent/tools/restart.ts +1 -1
  112. package/src/agent/tools/skip-response.ts +1 -1
  113. package/src/agent/tools/spawn-subagent.ts +15 -1
  114. package/src/agent/tools/stream-snapshot.ts +1 -1
  115. package/src/agent/tools/subagent-cancel.ts +1 -1
  116. package/src/agent/tools/subagent-output.ts +1 -1
  117. package/src/agent/tools/todo/index.ts +1 -1
  118. package/src/agent/tools/webfetch/adaptive-html.ts +6 -4
  119. package/src/agent/tools/webfetch/strategies/readability-child.ts +25 -0
  120. package/src/agent/tools/webfetch/strategies/readability-process.ts +185 -0
  121. package/src/agent/tools/webfetch/tool.ts +6 -5
  122. package/src/agent/tools/websearch.ts +1 -1
  123. package/src/agent/tools-without-local-file-operands.ts +4 -0
  124. package/src/browser/dockerfile.ts +1 -1
  125. package/src/browser/fill-secret.ts +364 -0
  126. package/src/browser/registry.ts +6 -6
  127. package/src/bundled-plugins/agent-messenger-cli-auth/command.ts +211 -0
  128. package/src/bundled-plugins/agent-messenger-cli-auth/index.ts +186 -0
  129. package/src/bundled-plugins/backup/index.ts +17 -2
  130. package/src/bundled-plugins/backup/runner.ts +37 -2
  131. package/src/bundled-plugins/browser-agent/browser-agent.ts +51 -14
  132. package/src/bundled-plugins/browser-agent/index.ts +12 -5
  133. package/src/bundled-plugins/explorer/explorer.ts +1 -1
  134. package/src/bundled-plugins/github-cli-auth/gh-review-detect.ts +40 -16
  135. package/src/bundled-plugins/github-cli-auth/graphql-auth-nudge.ts +12 -7
  136. package/src/bundled-plugins/github-cli-auth/index.ts +10 -1
  137. package/src/bundled-plugins/managed-browser/index.ts +130 -2
  138. package/src/bundled-plugins/managed-browser/skills/browserskill/browserskill/SKILL.md +13 -5
  139. package/src/bundled-plugins/managed-browser/skills/omowright/omowright/SKILL.md +56 -5
  140. package/src/bundled-plugins/memory/README.md +23 -2
  141. package/src/bundled-plugins/memory/append-fragment.ts +133 -0
  142. package/src/bundled-plugins/memory/append-tool.ts +80 -149
  143. package/src/bundled-plugins/memory/dreaming.ts +6 -1
  144. package/src/bundled-plugins/memory/index.ts +33 -6
  145. package/src/bundled-plugins/memory/load-memory.ts +2 -4
  146. package/src/bundled-plugins/memory/memory-logger.ts +200 -6
  147. package/src/bundled-plugins/memory/references/store-reference-tool.ts +56 -32
  148. package/src/bundled-plugins/memory/remember-tool.ts +81 -0
  149. package/src/bundled-plugins/memory/search-tool-hybrid.ts +91 -0
  150. package/src/bundled-plugins/memory/search-tool.ts +58 -12
  151. package/src/bundled-plugins/memory/stream-events.ts +2 -0
  152. package/src/bundled-plugins/memory/transcript-cursor.ts +30 -0
  153. package/src/bundled-plugins/memory/transcript-preload.ts +208 -0
  154. package/src/bundled-plugins/memory/transcript-view.ts +36 -0
  155. package/src/bundled-plugins/memory/vector/hybrid.ts +25 -14
  156. package/src/bundled-plugins/memory/watermark.ts +19 -10
  157. package/src/bundled-plugins/reviewer/reviewer.ts +20 -0
  158. package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +3 -6
  159. package/src/bundled-plugins/security/policies/outbound-text.ts +20 -0
  160. package/src/bundled-plugins/security/policies/private-surface-read.ts +166 -201
  161. package/src/bundled-plugins/security/policies/system-prompt-leak.ts +2 -7
  162. package/src/bundled-plugins/typevault/grants.ts +119 -0
  163. package/src/bundled-plugins/typevault/index.ts +152 -0
  164. package/src/bundled-plugins/typevault/request.ts +87 -0
  165. package/src/bundled-plugins/typevault/runtime.ts +45 -0
  166. package/src/bundled-plugins/typevault/skills/typevault/SKILL.md +65 -0
  167. package/src/channels/adapter-halt.ts +17 -0
  168. package/src/channels/adapters/discord-bot-reference.ts +5 -4
  169. package/src/channels/adapters/discord-bot.ts +1 -0
  170. package/src/channels/adapters/discord-classify.ts +8 -3
  171. package/src/channels/adapters/discord.ts +29 -0
  172. package/src/channels/adapters/github/history.ts +23 -2
  173. package/src/channels/adapters/github/inbound.ts +60 -1
  174. package/src/channels/adapters/github/index.ts +27 -5
  175. package/src/channels/adapters/github/reconcile-open-prs.ts +7 -1
  176. package/src/channels/adapters/kakaotalk-author-resolver.ts +7 -5
  177. package/src/channels/adapters/kakaotalk-channel-resolver.ts +45 -15
  178. package/src/channels/adapters/kakaotalk-classify.ts +7 -9
  179. package/src/channels/adapters/kakaotalk-list.ts +62 -0
  180. package/src/channels/adapters/kakaotalk-member-cache.ts +67 -0
  181. package/src/channels/adapters/kakaotalk-membership.ts +27 -10
  182. package/src/channels/adapters/kakaotalk-mention.ts +61 -0
  183. package/src/channels/adapters/kakaotalk.ts +159 -125
  184. package/src/channels/adapters/teams-classify.ts +18 -8
  185. package/src/channels/github-review-check.ts +5 -1
  186. package/src/channels/github-review-verdict-coordinator.ts +68 -2
  187. package/src/channels/github-token-bridge.ts +13 -0
  188. package/src/channels/lost-background-context.ts +46 -0
  189. package/src/channels/manager.ts +52 -3
  190. package/src/channels/persistence.ts +5 -0
  191. package/src/channels/router.ts +208 -128
  192. package/src/channels/schema.ts +1 -1
  193. package/src/channels/subagent-completion-bridge.ts +3 -2
  194. package/src/channels/types.ts +3 -0
  195. package/src/cli/hostd.ts +3 -0
  196. package/src/coding-agent/tool.ts +1 -1
  197. package/src/config/config.ts +35 -1
  198. package/src/config/providers.ts +75 -4
  199. package/src/container/start.ts +52 -3
  200. package/src/doctor/channel-checks.ts +33 -0
  201. package/src/doctor/checks.ts +37 -18
  202. package/src/doctor/index.ts +48 -12
  203. package/src/doctor/operational-incidents.ts +16 -1
  204. package/src/doctor/plugin-bridge.ts +14 -1
  205. package/src/doctor/stage.ts +14 -0
  206. package/src/doctor/types.ts +6 -0
  207. package/src/eval/cell.ts +93 -0
  208. package/src/eval/config.ts +32 -0
  209. package/src/eval/dispatch.ts +67 -0
  210. package/src/eval/entry.ts +261 -0
  211. package/src/eval/kernel.ts +154 -0
  212. package/src/eval/process.ts +113 -0
  213. package/src/eval/protocol.ts +26 -0
  214. package/src/eval/redeclare.ts +174 -0
  215. package/src/eval/sandbox.ts +117 -0
  216. package/src/eval/tool.ts +99 -0
  217. package/src/eval/wire.ts +93 -0
  218. package/src/git/resolve-identity.ts +67 -2
  219. package/src/git/system-commit.ts +7 -0
  220. package/src/init/dockerfile.ts +5 -1
  221. package/src/init/gitignore.ts +3 -3
  222. package/src/init/index.ts +1 -0
  223. package/src/init/models-dev.ts +2 -0
  224. package/src/init/validate-api-key.ts +5 -0
  225. package/src/migrations/secrets-v1-to-v2.ts +2 -0
  226. package/src/operations/classify-tool-outcome.ts +1 -1
  227. package/src/permissions/builtins.ts +8 -0
  228. package/src/plugin/core-tool-names.ts +6 -1
  229. package/src/plugin/types.ts +6 -0
  230. package/src/run/bundled-plugins.ts +12 -0
  231. package/src/run/channel-session-factory.ts +3 -0
  232. package/src/run/index.ts +13 -2
  233. package/src/sandbox/build.ts +1 -0
  234. package/src/sandbox/canonical-secrets.ts +6 -0
  235. package/src/sandbox/dependency-bins.ts +13 -1
  236. package/src/sandbox/dev-source.ts +21 -12
  237. package/src/sandbox/env-exposure.ts +20 -0
  238. package/src/sandbox/hidden-paths.ts +1 -1
  239. package/src/sandbox/index.ts +1 -0
  240. package/src/sandbox/policy.ts +5 -0
  241. package/src/secrets/hydrate.ts +4 -1
  242. package/src/secrets/storage.ts +10 -1
  243. package/src/server/command-runner.ts +4 -0
  244. package/src/server/index.ts +54 -12
  245. package/src/skills/typeclaw-config/SKILL.md +36 -2
  246. package/src/skills/typeclaw-memory/SKILL.md +3 -1
  247. package/src/skills/typeclaw-permissions/SKILL.md +8 -8
  248. package/src/skills/typeclaw-troubleshooting/SKILL.md +18 -1
  249. package/src/tunnels/active.ts +14 -0
  250. package/src/typevault/bash-cli.ts +18 -0
  251. package/src/typevault/cli-path.ts +11 -0
  252. package/src/typevault/envelope-helper.ts +17 -0
  253. package/src/typevault/envelope-store.ts +98 -0
  254. package/src/typevault/lifecycle.ts +132 -0
  255. package/src/typevault/prompt-tunnel.ts +33 -0
  256. package/src/typevault/redaction.ts +37 -0
  257. package/src/typevault/vault.ts +283 -0
  258. package/typeclaw.schema.json +92 -10
@@ -1,12 +1,12 @@
1
- import { Type } from '@earendil-works/pi-ai'
2
1
  import { defineTool } from '@earendil-works/pi-coding-agent'
2
+ import { Type } from 'typebox'
3
3
 
4
4
  import { extractAdaptiveHtml, validateAdaptiveHtmlComplexity } from './adaptive-html'
5
5
  import { fetchWithLimits, normalizeUrl, parseMimeType, WebFetchError } from './fetch'
6
6
  import { applyGrep, GrepError } from './strategies/grep'
7
7
  import { applyJq, JqError } from './strategies/jq'
8
8
  import { applyRaw } from './strategies/raw'
9
- import { applyReadability } from './strategies/readability'
9
+ import { applyReadabilityIsolated } from './strategies/readability-process'
10
10
  import { applySelector, SelectorError } from './strategies/selector'
11
11
  import { applySnapshot } from './strategies/snapshot'
12
12
  import {
@@ -135,7 +135,7 @@ export const webFetchTool = defineTool({
135
135
  let extractionAttempts: HtmlExtractionAttempt[] | undefined
136
136
  try {
137
137
  if (strategy === 'readability' && autoDetected) {
138
- const extracted = await extractAdaptiveHtml(response.body, response.finalUrl)
138
+ const extracted = await extractAdaptiveHtml(response.body, response.finalUrl, undefined, signal)
139
139
  extractionAttempts = extracted.attempts
140
140
  if (extracted.kind === 'error') {
141
141
  return errorResult(normalizedUrl, extracted.message, {
@@ -165,7 +165,7 @@ export const webFetchTool = defineTool({
165
165
  })
166
166
  }
167
167
  }
168
- output = await runStrategy(strategy, response.body, response.finalUrl, params)
168
+ output = await runStrategy(strategy, response.body, response.finalUrl, params, signal)
169
169
  }
170
170
  } catch (error) {
171
171
  const message = error instanceof Error ? error.message : String(error)
@@ -262,12 +262,13 @@ async function runStrategy(
262
262
  body: string,
263
263
  url: string,
264
264
  params: WebFetchParams,
265
+ signal: AbortSignal | undefined,
265
266
  ): Promise<string> {
266
267
  switch (strategy) {
267
268
  case 'raw':
268
269
  return applyRaw(body)
269
270
  case 'readability':
270
- return await applyReadability(body, url)
271
+ return (await applyReadabilityIsolated(body, url, signal)).output
271
272
  case 'jq':
272
273
  try {
273
274
  return await applyJq(body, params.query ?? '')
@@ -1,5 +1,5 @@
1
- import { Type } from '@earendil-works/pi-ai'
2
1
  import { defineTool } from '@earendil-works/pi-coding-agent'
2
+ import { Type } from 'typebox'
3
3
 
4
4
  import { CurlImpersonateError, isCurlExitTimeout } from './curl-impersonate'
5
5
  import { ddgSearch, DdgCaptchaError, type DdgResult } from './ddg'
@@ -14,8 +14,12 @@
14
14
  // can both read it without a circular-init TDZ. Add a tool here ONLY after
15
15
  // confirming it dereferences no argument as a local path.
16
16
  export const TOOLS_WITHOUT_LOCAL_FILE_OPERANDS: ReadonlySet<string> = new Set([
17
+ // Source code is not a host-side path operand. Raw I/O is confined by the
18
+ // shared bash sandbox; tool.* operands enter their own wrapped definitions.
19
+ 'eval',
17
20
  'channel_read',
18
21
  'channel_history',
22
+ 'channel_handoff',
19
23
  'channel_edit',
20
24
  'channel_react',
21
25
  'channel_fetch_attachment',
@@ -35,7 +35,7 @@ RUN mkdir -p ${root} \\
35
35
  && cd ${root} \\
36
36
  && printf '{}' > package.json \\
37
37
  && BUN_INSTALL_CACHE_DIR=/tmp/typeclaw-browser-bun-cache bun add ${spec} \\
38
- && printf '%s\\n' 'export * from "${root}/node_modules/${id}/src/index.js"' > ${module} \\
38
+ && printf '%s\\n' 'export * from "${id}"' > ${module} \\
39
39
  && rm -rf /tmp/typeclaw-browser-bun-cache \\
40
40
  && chmod -R a+rX ${root} \\
41
41
  && bun -e 'await import("${module}")'`
@@ -0,0 +1,364 @@
1
+ // Types a runtime-held value into the focused field of a managed-browser tab
2
+ // over CDP, so the model can enter a secret it never sees. The value only ever
3
+ // travels runtime -> Chrome; every outcome reports where it went, never what.
4
+
5
+ const COMMAND_TIMEOUT_MS = 10_000
6
+ const DEFAULT_NAVIGATION_TIMEOUT_MS = 15_000
7
+ // How long a real Enter gets to start a navigation before the form is
8
+ // submitted directly instead.
9
+ const ENTER_GRACE_MS = 2_000
10
+
11
+ export type FillSecretOptions = {
12
+ cdpUrl: string
13
+ value: string
14
+ url?: string
15
+ submit: boolean
16
+ navigationTimeoutMs?: number
17
+ }
18
+
19
+ export type FillSecretOutcome =
20
+ | { status: 'filled'; url: string; field: string }
21
+ | { status: 'submitted'; url: string; field: string }
22
+ | { status: 'not-navigated'; url: string; field: string; cleared: boolean }
23
+ | { status: 'refused'; reason: string }
24
+
25
+ export async function fillSecretIntoFocusedField(options: FillSecretOptions): Promise<FillSecretOutcome> {
26
+ const cdp = await CdpConnection.open(options.cdpUrl)
27
+ try {
28
+ const target = await pickTarget(cdp, options.url)
29
+ if ('reason' in target) return { status: 'refused', reason: target.reason }
30
+ const sessionId = target.sessionId ?? (await attachWithFocus(cdp, target.targetId))
31
+ const focused = target.focus ?? (await inspectFocus(cdp, sessionId))
32
+ if (focused.kind === 'none') {
33
+ return {
34
+ status: 'refused',
35
+ reason: `no editable field is focused on ${target.url}${focused.field === undefined ? '' : ` (focused: ${focused.field})`}; click or focus the field first`,
36
+ }
37
+ }
38
+
39
+ await pressCommand(cdp, sessionId, 'selectAll')
40
+ try {
41
+ await cdp.send('Input.insertText', { text: options.value }, sessionId)
42
+ if (!options.submit) return { status: 'filled', url: target.url, field: focused.field }
43
+
44
+ await cdp.send('Page.enable', {}, sessionId)
45
+ const timeoutMs = options.navigationTimeoutMs ?? DEFAULT_NAVIGATION_TIMEOUT_MS
46
+ const { frameTree } = (await cdp.send('Page.getFrameTree', {}, sessionId)) as {
47
+ frameTree: { frame: { id: string } }
48
+ }
49
+ const navigated = cdp.waitForEvent(
50
+ 'Page.frameNavigated',
51
+ sessionId,
52
+ (params) => (params as { frame?: { parentId?: string } }).frame?.parentId === undefined,
53
+ timeoutMs,
54
+ )
55
+ const startedLoading = cdp.waitForEvent(
56
+ 'Page.frameStartedLoading',
57
+ sessionId,
58
+ (params) => (params as { frameId?: string }).frameId === frameTree.frame.id,
59
+ Math.min(ENTER_GRACE_MS, timeoutMs / 2),
60
+ )
61
+ // Enter first: script-driven logins (encrypt-then-submit from a keyup or
62
+ // button handler) cancel a direct form submit, while a real keystroke
63
+ // runs their handlers and still triggers implicit submission elsewhere.
64
+ // Once a load starts the old document (and the field handle) may be gone,
65
+ // so it is only probed after the grace period passes with no load. The
66
+ // submit-seen check and the fallback submit run in one browser-side call
67
+ // so a handler that submits late in the grace period is not doubled.
68
+ await callOnField(cdp, sessionId, focused.objectId, WATCH_SUBMIT_FUNCTION)
69
+ await pressEnter(cdp, sessionId)
70
+ if (!(await startedLoading)) {
71
+ try {
72
+ await callOnField(cdp, sessionId, focused.objectId, SUBMIT_UNLESS_SEEN_FUNCTION)
73
+ } catch (error) {
74
+ // A navigation that began right after the grace period destroys the
75
+ // handle; that is a successful submit, not a failure.
76
+ if (!(await navigated)) throw error
77
+ }
78
+ }
79
+ if (await navigated) return { status: 'submitted', url: target.url, field: focused.field }
80
+ } catch (error) {
81
+ // The value may already be in the field; a failed step must not leave it there.
82
+ if (focused.objectId !== undefined) await clearField(cdp, sessionId, focused.objectId)
83
+ throw error
84
+ }
85
+
86
+ // The page stayed put (wrong value, inline error, SPA): don't leave the
87
+ // secret sitting in the DOM for a later snapshot or script to read back.
88
+ const cleared = focused.objectId !== undefined && (await clearField(cdp, sessionId, focused.objectId))
89
+ return { status: 'not-navigated', url: target.url, field: focused.field, cleared }
90
+ } finally {
91
+ cdp.close()
92
+ }
93
+ }
94
+
95
+ type TargetInfo = { targetId: string; type: string; url: string }
96
+
97
+ type PickedTarget = { targetId: string; url: string; sessionId?: string; focus?: FocusInfo & { kind: 'editable' } }
98
+
99
+ async function pickTarget(cdp: CdpConnection, url: string | undefined): Promise<PickedTarget | { reason: string }> {
100
+ const { targetInfos } = (await cdp.send('Target.getTargets')) as { targetInfos: TargetInfo[] }
101
+ const pages = targetInfos.filter((t) => t.type === 'page' && !/^(devtools|chrome|chrome-extension):/.test(t.url))
102
+ const prefixed = url === undefined ? pages : pages.filter((t) => t.url === url || t.url.startsWith(url))
103
+ // An exact URL names one tab even when it is also a prefix of its siblings'
104
+ // URLs (`/` vs `/login`).
105
+ const exact = url === undefined ? [] : prefixed.filter((t) => t.url === url)
106
+ const matches = exact.length > 0 ? exact : prefixed
107
+ if (matches.length === 1) return matches[0]!
108
+ if (matches.length === 0) {
109
+ return { reason: url === undefined ? 'the shared browser has no open tab' : `no open tab matches ${url}` }
110
+ }
111
+ // Duplicate tabs of one site are common after a retry opens a fresh tab, and
112
+ // no URL can tell them apart. The secret goes into the focused field, so the
113
+ // one tab whose focus sits in an editable field is the one just clicked.
114
+ const focused: PickedTarget[] = []
115
+ for (const t of matches) {
116
+ const sessionId = await attachWithFocus(cdp, t.targetId)
117
+ const focus = await inspectFocus(cdp, sessionId)
118
+ if (focus.kind === 'editable') focused.push({ targetId: t.targetId, url: t.url, sessionId, focus })
119
+ }
120
+ if (focused.length === 1) return focused[0]!
121
+ return {
122
+ reason: `several tabs match and ${focused.length === 0 ? 'none has' : 'more than one has'} a focused editable field; click the field first, or close the duplicate tabs, or pass the exact \`url\` of one of: ${matches.map((t) => t.url).join(', ')}`,
123
+ }
124
+ }
125
+
126
+ async function attachWithFocus(cdp: CdpConnection, targetId: string): Promise<string> {
127
+ const { sessionId } = (await cdp.send('Target.attachToTarget', { targetId, flatten: true })) as {
128
+ sessionId: string
129
+ }
130
+ // Background tabs (omowright opens them) report no focus; emulate it so
131
+ // keyboard input reaches the focused element without stealing the window.
132
+ await cdp.send('Emulation.setFocusEmulationEnabled', { enabled: true }, sessionId)
133
+ return sessionId
134
+ }
135
+
136
+ type FocusInfo = { kind: 'editable'; field: string; objectId?: string } | { kind: 'none'; field?: string }
137
+
138
+ // Walks shadow roots and same-origin iframes down to the real focused element.
139
+ // A cross-origin iframe (hosted card/key widgets) can't be inspected from the
140
+ // top frame, but keyboard input still lands in its focused field.
141
+ const FOCUS_EXPRESSION = `(() => {
142
+ const deepest = (el) => { while (el && el.shadowRoot && el.shadowRoot.activeElement) el = el.shadowRoot.activeElement; return el }
143
+ let el = deepest(document.activeElement)
144
+ while (el && el.tagName === 'IFRAME') {
145
+ let doc = null
146
+ try { doc = el.contentDocument } catch {}
147
+ if (!doc) return { kind: 'frame' }
148
+ el = deepest(doc.activeElement)
149
+ }
150
+ if (!el || el === el.ownerDocument.body || el === el.ownerDocument.documentElement) return { kind: 'none' }
151
+ const tag = el.tagName.toLowerCase()
152
+ if (el.isContentEditable) return { kind: 'editable', field: tag + '[contenteditable]', el }
153
+ const usable = !el.disabled && !el.readOnly
154
+ if (tag === 'textarea') return usable ? { kind: 'editable', field: 'textarea', el } : { kind: 'none', field: tag }
155
+ if (tag === 'input') {
156
+ const type = (el.getAttribute('type') || 'text').toLowerCase()
157
+ const textual = ['text', 'password', 'email', 'tel', 'url', 'search', 'number'].includes(type)
158
+ return textual && usable ? { kind: 'editable', field: 'input[type=' + type + ']', el } : { kind: 'none', field: 'input[type=' + type + ']' }
159
+ }
160
+ return { kind: 'none', field: tag }
161
+ })()`
162
+
163
+ async function inspectFocus(cdp: CdpConnection, sessionId: string): Promise<FocusInfo> {
164
+ const described = (await cdp.send(
165
+ 'Runtime.evaluate',
166
+ {
167
+ expression: `(() => { const r = ${FOCUS_EXPRESSION}; return { kind: r.kind, field: r.field } })()`,
168
+ returnByValue: true,
169
+ },
170
+ sessionId,
171
+ )) as { result: { value?: { kind: string; field?: string } } }
172
+ const info = described.result.value
173
+ if (info?.kind === 'frame') return { kind: 'editable', field: 'cross-origin iframe' }
174
+ if (info?.kind !== 'editable' || info.field === undefined)
175
+ return { kind: 'none', ...(info?.field ? { field: info.field } : {}) }
176
+ // Hold a handle to the exact element so a later clear can't hit whatever
177
+ // happens to be focused after the page changes.
178
+ const handle = (await cdp.send('Runtime.evaluate', { expression: `(${FOCUS_EXPRESSION}).el` }, sessionId)) as {
179
+ result: { objectId?: string }
180
+ }
181
+ return {
182
+ kind: 'editable',
183
+ field: info.field,
184
+ ...(handle.result.objectId ? { objectId: handle.result.objectId } : {}),
185
+ }
186
+ }
187
+
188
+ // Frameworks such as React shadow `value` on the element itself to track the
189
+ // last value they saw; assigning through that shadow updates the tracker, so the
190
+ // input event looks like no change and the app's state keeps the secret. Writing
191
+ // through the prototype's native setter leaves the tracker stale, so the app sees
192
+ // the edit and its own state is emptied too.
193
+ export const CLEAR_FIELD_FUNCTION = `function () {
194
+ if (!this.isConnected) return true
195
+ if (this.isContentEditable) {
196
+ this.textContent = ''
197
+ this.dispatchEvent(new Event('input', { bubbles: true }))
198
+ return this.textContent === ''
199
+ }
200
+ let setter
201
+ for (let proto = Object.getPrototypeOf(this); proto && !setter; proto = Object.getPrototypeOf(proto)) {
202
+ setter = Object.getOwnPropertyDescriptor(proto, 'value')?.set
203
+ }
204
+ if (!setter) return false
205
+ setter.call(this, '')
206
+ this.dispatchEvent(new Event('input', { bubbles: true }))
207
+ return this.value === ''
208
+ }`
209
+
210
+ async function clearField(cdp: CdpConnection, sessionId: string, objectId: string): Promise<boolean> {
211
+ const result = (await cdp
212
+ .send(
213
+ 'Runtime.callFunctionOn',
214
+ {
215
+ objectId,
216
+ functionDeclaration: CLEAR_FIELD_FUNCTION,
217
+ returnByValue: true,
218
+ },
219
+ sessionId,
220
+ )
221
+ .catch(() => ({ result: { value: false } }))) as { result: { value?: boolean } }
222
+ return result.result.value === true
223
+ }
224
+
225
+ async function pressCommand(cdp: CdpConnection, sessionId: string, command: string): Promise<void> {
226
+ await cdp.send('Input.dispatchKeyEvent', { type: 'rawKeyDown', commands: [command] }, sessionId)
227
+ await cdp.send('Input.dispatchKeyEvent', { type: 'keyUp' }, sessionId)
228
+ }
229
+
230
+ const WATCH_SUBMIT_FUNCTION = `function () {
231
+ const form = this.form
232
+ if (!form) return
233
+ form.__typeclawSubmitSeen = false
234
+ form.addEventListener('submit', () => { form.__typeclawSubmitSeen = true }, { capture: true, once: true })
235
+ }`
236
+
237
+ // A form without a submit button and with several fields ignores Enter (HTML
238
+ // implicit submission), so it is submitted directly when Enter did nothing.
239
+ const SUBMIT_UNLESS_SEEN_FUNCTION = `function () {
240
+ const form = this.form
241
+ if (!this.isConnected || !form || form.__typeclawSubmitSeen === true) return
242
+ form.requestSubmit()
243
+ }`
244
+
245
+ async function callOnField(
246
+ cdp: CdpConnection,
247
+ sessionId: string,
248
+ objectId: string | undefined,
249
+ functionDeclaration: string,
250
+ ): Promise<unknown> {
251
+ if (objectId === undefined) return undefined
252
+ const result = (await cdp.send(
253
+ 'Runtime.callFunctionOn',
254
+ { objectId, functionDeclaration, returnByValue: true },
255
+ sessionId,
256
+ )) as { result?: { value?: unknown } }
257
+ return result.result?.value
258
+ }
259
+
260
+ async function pressEnter(cdp: CdpConnection, sessionId: string): Promise<void> {
261
+ const key = { key: 'Enter', code: 'Enter', windowsVirtualKeyCode: 13, nativeVirtualKeyCode: 13 }
262
+ await cdp.send('Input.dispatchKeyEvent', { type: 'keyDown', text: '\r', ...key }, sessionId)
263
+ await cdp.send('Input.dispatchKeyEvent', { type: 'keyUp', ...key }, sessionId)
264
+ }
265
+
266
+ type Pending = {
267
+ resolve: (value: unknown) => void
268
+ reject: (error: Error) => void
269
+ timer: ReturnType<typeof setTimeout>
270
+ }
271
+ type EventListener = { method: string; sessionId: string; onEvent: (params: unknown) => void }
272
+
273
+ class CdpConnection {
274
+ private nextId = 1
275
+ private readonly pending = new Map<number, Pending>()
276
+ private readonly listeners = new Set<EventListener>()
277
+
278
+ private constructor(private readonly socket: WebSocket) {
279
+ socket.addEventListener('message', (event) => this.onMessage(String(event.data)))
280
+ socket.addEventListener('close', () => {
281
+ for (const p of this.pending.values()) {
282
+ clearTimeout(p.timer)
283
+ p.reject(new Error('browser connection closed'))
284
+ }
285
+ this.pending.clear()
286
+ })
287
+ }
288
+
289
+ static open(url: string): Promise<CdpConnection> {
290
+ return new Promise((resolve, reject) => {
291
+ const socket = new WebSocket(url)
292
+ socket.addEventListener('open', () => resolve(new CdpConnection(socket)), { once: true })
293
+ socket.addEventListener('error', () => reject(new Error('could not connect to the shared browser')), {
294
+ once: true,
295
+ })
296
+ })
297
+ }
298
+
299
+ send(method: string, params: Record<string, unknown> = {}, sessionId?: string): Promise<unknown> {
300
+ const id = this.nextId++
301
+ return new Promise((resolve, reject) => {
302
+ const timer = setTimeout(() => {
303
+ this.pending.delete(id)
304
+ reject(new Error(`${method} timed out`))
305
+ }, COMMAND_TIMEOUT_MS)
306
+ this.pending.set(id, { resolve, reject, timer })
307
+ this.socket.send(JSON.stringify({ id, method, params, ...(sessionId === undefined ? {} : { sessionId }) }))
308
+ })
309
+ }
310
+
311
+ // Registered before the triggering command so a fast event can't slip past.
312
+ waitForEvent(
313
+ method: string,
314
+ sessionId: string,
315
+ predicate: (params: unknown) => boolean,
316
+ timeoutMs: number,
317
+ ): Promise<boolean> {
318
+ return new Promise((resolve) => {
319
+ const listener: EventListener = {
320
+ method,
321
+ sessionId,
322
+ onEvent: (params) => {
323
+ if (!predicate(params)) return
324
+ finish(true)
325
+ },
326
+ }
327
+ const timer = setTimeout(() => finish(false), timeoutMs)
328
+ const finish = (value: boolean): void => {
329
+ clearTimeout(timer)
330
+ this.listeners.delete(listener)
331
+ resolve(value)
332
+ }
333
+ this.listeners.add(listener)
334
+ })
335
+ }
336
+
337
+ close(): void {
338
+ this.socket.close()
339
+ }
340
+
341
+ private onMessage(raw: string): void {
342
+ const message = JSON.parse(raw) as {
343
+ id?: number
344
+ result?: unknown
345
+ error?: { message: string }
346
+ method?: string
347
+ params?: unknown
348
+ sessionId?: string
349
+ }
350
+ if (message.id !== undefined) {
351
+ const pending = this.pending.get(message.id)
352
+ if (pending === undefined) return
353
+ this.pending.delete(message.id)
354
+ clearTimeout(pending.timer)
355
+ if (message.error !== undefined) pending.reject(new Error(message.error.message))
356
+ else pending.resolve(message.result)
357
+ return
358
+ }
359
+ for (const listener of this.listeners) {
360
+ if (listener.method === message.method && listener.sessionId === message.sessionId)
361
+ listener.onEvent(message.params)
362
+ }
363
+ }
364
+ }
@@ -46,9 +46,9 @@ export const BSK_DAEMON_PORT = 52800
46
46
 
47
47
  export const OMOWRIGHT_MODULE = `${BROWSER_ROOT}/omowright/index.js`
48
48
 
49
- const OMOWRIGHT_COMMIT = 'a3f0c2b54fc41804beca7eb6ab26ee54804742a9'
49
+ const OMOWRIGHT_VERSION = '0.3.0'
50
50
  const BROWSER_USE_VERSION = '0.13.11'
51
- const BSK_VERSION = '0.3.3'
51
+ const BSK_VERSION = '0.4.2'
52
52
  const BSK_RELEASES = 'https://github.com/Tencent/BrowserSkill/releases/download'
53
53
 
54
54
  export const BROWSER_ENGINES: Record<BrowserEngineId, BrowserEngineSpec> = {
@@ -59,7 +59,7 @@ export const BROWSER_ENGINES: Record<BrowserEngineId, BrowserEngineSpec> = {
59
59
  },
60
60
  omowright: {
61
61
  id: 'omowright',
62
- install: { kind: 'bun-global', spec: `github:code-yeongyu/omowright#${OMOWRIGHT_COMMIT}` },
62
+ install: { kind: 'bun-global', spec: `omowright@${OMOWRIGHT_VERSION}` },
63
63
  env: (cdpUrl) => ({ OMOWRIGHT_CDP_URL: cdpUrl }),
64
64
  },
65
65
  'browser-use': {
@@ -75,18 +75,18 @@ export const BROWSER_EXTENSIONS: Record<BrowserExtensionId, BrowserExtensionSpec
75
75
  version: BSK_VERSION,
76
76
  zip: {
77
77
  url: `${BSK_RELEASES}/ext-v${BSK_VERSION}/browser-skill-extension-v${BSK_VERSION}-chrome.zip`,
78
- sha256: '10ef76e68f352893fa22dd4cce2f1b96cb90ed957b815d656e13180d07d3c6ea',
78
+ sha256: '5360ef01ec8fcd3550215e12c417d8b98814bff0e54d478e6b867d693c1d4d76',
79
79
  },
80
80
  cli: {
81
81
  name: 'bsk',
82
82
  urlByArch: {
83
83
  amd64: {
84
84
  url: `${BSK_RELEASES}/cli-v${BSK_VERSION}/bsk-v${BSK_VERSION}-x86_64-unknown-linux-musl.tar.gz`,
85
- sha256: '141b73489bec99d768cf18042919f0e054c9f614e6ecdfd754028d2b606e9106',
85
+ sha256: '5286ccdc104e52200c47b4a492c6e043069e5bf1e638db8fdbde62a9d4939979',
86
86
  },
87
87
  arm64: {
88
88
  url: `${BSK_RELEASES}/cli-v${BSK_VERSION}/bsk-v${BSK_VERSION}-aarch64-unknown-linux-musl.tar.gz`,
89
- sha256: '747e4c416da46650c7d8127a47dd8f08e813e0f69366c4db1af226d0b63a575d',
89
+ sha256: 'f965474d8ad61cfb819b5123f4355135ee2afa9c4f742bbbe9e4f463dc7d5fa3',
90
90
  },
91
91
  },
92
92
  },