@namzu/sdk 75.0.0 → 76.0.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 (100) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/bridge/acp/server.d.ts.map +1 -1
  3. package/dist/bridge/acp/server.js +4 -1
  4. package/dist/bridge/acp/server.js.map +1 -1
  5. package/dist/bridge/acp/update.d.ts.map +1 -1
  6. package/dist/bridge/acp/update.js +22 -2
  7. package/dist/bridge/acp/update.js.map +1 -1
  8. package/dist/peers/record.d.ts +3 -3
  9. package/dist/public-runtime.d.ts +2 -2
  10. package/dist/public-runtime.d.ts.map +1 -1
  11. package/dist/public-runtime.js +1 -1
  12. package/dist/public-runtime.js.map +1 -1
  13. package/dist/runtime/query/executor.d.ts.map +1 -1
  14. package/dist/runtime/query/executor.js +10 -1
  15. package/dist/runtime/query/executor.js.map +1 -1
  16. package/dist/session/workspace/git-worktree.d.ts +18 -0
  17. package/dist/session/workspace/git-worktree.d.ts.map +1 -1
  18. package/dist/session/workspace/git-worktree.js +100 -1
  19. package/dist/session/workspace/git-worktree.js.map +1 -1
  20. package/dist/session/workspace/index.d.ts +1 -1
  21. package/dist/session/workspace/index.d.ts.map +1 -1
  22. package/dist/session/workspace/index.js +1 -1
  23. package/dist/session/workspace/index.js.map +1 -1
  24. package/dist/store/checkpoint/contract.d.ts.map +1 -1
  25. package/dist/store/checkpoint/contract.js +5 -2
  26. package/dist/store/checkpoint/contract.js.map +1 -1
  27. package/dist/store/session-log/core.d.ts.map +1 -1
  28. package/dist/store/session-log/core.js +30 -1
  29. package/dist/store/session-log/core.js.map +1 -1
  30. package/dist/tools/admit-facts.d.ts.map +1 -1
  31. package/dist/tools/admit-facts.js +19 -0
  32. package/dist/tools/admit-facts.js.map +1 -1
  33. package/dist/tools/builtins/bash.d.ts +1 -1
  34. package/dist/tools/builtins/bash.d.ts.map +1 -1
  35. package/dist/tools/builtins/bash.js +9 -7
  36. package/dist/tools/builtins/bash.js.map +1 -1
  37. package/dist/tools/builtins/browser.d.ts +2 -2
  38. package/dist/tools/builtins/browser.d.ts.map +1 -1
  39. package/dist/tools/builtins/browser.js +15 -3
  40. package/dist/tools/builtins/browser.js.map +1 -1
  41. package/dist/tools/builtins/computer-use.d.ts +19 -3
  42. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  43. package/dist/tools/builtins/computer-use.js +150 -50
  44. package/dist/tools/builtins/computer-use.js.map +1 -1
  45. package/dist/tools/coordinator/agent.d.ts.map +1 -1
  46. package/dist/tools/coordinator/agent.js +6 -0
  47. package/dist/tools/coordinator/agent.js.map +1 -1
  48. package/dist/tools/coordinator/index.d.ts.map +1 -1
  49. package/dist/tools/coordinator/index.js +6 -0
  50. package/dist/tools/coordinator/index.js.map +1 -1
  51. package/dist/tools/coordinator/progress.d.ts +9 -0
  52. package/dist/tools/coordinator/progress.d.ts.map +1 -0
  53. package/dist/tools/coordinator/progress.js +30 -0
  54. package/dist/tools/coordinator/progress.js.map +1 -0
  55. package/dist/tools/shell-output-window.d.ts +12 -0
  56. package/dist/tools/shell-output-window.d.ts.map +1 -0
  57. package/dist/tools/shell-output-window.js +92 -0
  58. package/dist/tools/shell-output-window.js.map +1 -0
  59. package/dist/types/acp/index.d.ts +3 -0
  60. package/dist/types/acp/index.d.ts.map +1 -1
  61. package/dist/types/browser/index.d.ts +4 -0
  62. package/dist/types/browser/index.d.ts.map +1 -1
  63. package/dist/types/computer-use/index.d.ts +4 -0
  64. package/dist/types/computer-use/index.d.ts.map +1 -1
  65. package/dist/types/session/checkpoint.d.ts +13 -0
  66. package/dist/types/session/checkpoint.d.ts.map +1 -1
  67. package/dist/types/session/checkpoint.js +33 -0
  68. package/dist/types/session/checkpoint.js.map +1 -1
  69. package/dist/types/session/events.d.ts +3 -0
  70. package/dist/types/session/events.d.ts.map +1 -1
  71. package/dist/types/session/events.js.map +1 -1
  72. package/dist/types/tool/index.d.ts +15 -0
  73. package/dist/types/tool/index.d.ts.map +1 -1
  74. package/dist/types/tool/index.js.map +1 -1
  75. package/dist/types/tool/presentation.d.ts +8 -0
  76. package/dist/types/tool/presentation.d.ts.map +1 -1
  77. package/package.json +1 -1
  78. package/src/bridge/acp/server.ts +6 -1
  79. package/src/bridge/acp/update.ts +23 -2
  80. package/src/public-runtime.ts +2 -0
  81. package/src/runtime/query/executor.ts +12 -3
  82. package/src/session/workspace/git-worktree.ts +115 -1
  83. package/src/session/workspace/index.ts +6 -1
  84. package/src/store/checkpoint/contract.ts +9 -2
  85. package/src/store/session-log/core.ts +34 -1
  86. package/src/tools/admit-facts.ts +20 -0
  87. package/src/tools/builtins/bash.ts +11 -12
  88. package/src/tools/builtins/browser.ts +16 -3
  89. package/src/tools/builtins/computer-use.ts +188 -44
  90. package/src/tools/coordinator/agent.ts +6 -0
  91. package/src/tools/coordinator/index.ts +6 -0
  92. package/src/tools/coordinator/progress.ts +40 -0
  93. package/src/tools/shell-output-window.ts +97 -0
  94. package/src/types/acp/index.ts +3 -0
  95. package/src/types/browser/index.ts +2 -0
  96. package/src/types/computer-use/index.ts +17 -0
  97. package/src/types/session/checkpoint.ts +37 -0
  98. package/src/types/session/events.ts +3 -0
  99. package/src/types/tool/index.ts +10 -0
  100. package/src/types/tool/presentation.ts +12 -1
@@ -13,7 +13,7 @@
13
13
 
14
14
  import { execFile } from 'node:child_process'
15
15
  import { readFileSync, realpathSync } from 'node:fs'
16
- import { realpath } from 'node:fs/promises'
16
+ import { lstat, readdir, readlink, realpath } from 'node:fs/promises'
17
17
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
18
18
  import { promisify } from 'node:util'
19
19
  import { NAMZU } from '../../constants/telemetry/index.js'
@@ -91,6 +91,31 @@ export interface GitWorktreeDriverConfig {
91
91
 
92
92
  const DEFAULT_BRANCH_PREFIX = 'namzu'
93
93
 
94
+ /**
95
+ * The refusal creating a worktree reports when the checkout it was asked to
96
+ * branch from does not own the Git directory it uses.
97
+ *
98
+ * `git worktree add` writes into the repository it runs in. When the Git
99
+ * directory is reached through a link, or is a `cp -al` copy whose files are
100
+ * hard links, those writes land in the checkout on the other end: the command
101
+ * succeeds, the new checkout looks right, and the refs and object store being
102
+ * changed belong to somebody else's repository. The message names what was
103
+ * found and what to do about it, because this is read by a person whose
104
+ * checkout is not what it appears to be.
105
+ */
106
+ export class LinkedCheckoutError extends Error {
107
+ override readonly name = 'LinkedCheckoutError'
108
+
109
+ constructor(
110
+ readonly repoRoot: string,
111
+ readonly found: string,
112
+ ) {
113
+ super(
114
+ `The checkout ${repoRoot} is not a plain clone: ${found}. Creating a worktree in it would write into the repository it shares its Git directory with. Clone the repository again and work in that clone.`,
115
+ )
116
+ }
117
+ }
118
+
94
119
  /** One safe branch component: no slash, no leading dot or hyphen, no Git syntax. */
95
120
  function isBranchPrefix(value: string): boolean {
96
121
  return (
@@ -154,6 +179,10 @@ export class GitWorktreeDriver implements WorkspaceBackendDriver {
154
179
  throw new WorkspaceBackendError({ op: 'create:ownership', kind: this.kind, cause })
155
180
  }
156
181
 
182
+ // Before Git runs: a checkout that does not own the Git directory it
183
+ // uses would have its new worktree registered in another repository.
184
+ await assertSoleGitDirectory(repoRoot)
185
+
157
186
  const relativePath = relative(worktreesDir, worktreePath).split(sep).join('/')
158
187
  const branch = `${this.branchPrefix}/${relativePath}`
159
188
 
@@ -471,6 +500,91 @@ export class GitWorktreeDriver implements WorkspaceBackendDriver {
471
500
  }
472
501
  }
473
502
 
503
+ /**
504
+ * The entries of a Git directory that decide where a repository's state lives.
505
+ *
506
+ * A link on one of these hands that state to another directory, and Git run in
507
+ * this checkout then writes through it. A link elsewhere — `hooks`, for
508
+ * instance, which some setups point at a shared folder — changes nothing about
509
+ * where the repository is, so it is left alone.
510
+ */
511
+ const SHARED_STATE_ENTRIES = new Set([
512
+ 'HEAD',
513
+ 'ORIG_HEAD',
514
+ 'FETCH_HEAD',
515
+ 'MERGE_HEAD',
516
+ 'commondir',
517
+ 'config',
518
+ 'logs',
519
+ 'objects',
520
+ 'packed-refs',
521
+ 'refs',
522
+ 'worktrees',
523
+ ])
524
+
525
+ /**
526
+ * Refuse a checkout whose Git directory does not belong to it alone.
527
+ *
528
+ * `git worktree add` writes into the repository it runs in: the entry under
529
+ * `<git dir>/worktrees`, the branch under `refs/heads`, and the checkout's own
530
+ * files. That is correct only when the Git directory belongs to this checkout.
531
+ * A `git-new-workdir` layout — a `.git` that is a link, or a directory whose
532
+ * state entries are links into another repository — and a `cp -al` copy, whose
533
+ * files are hard links to the originals, both hand Git a directory it does not
534
+ * own: the command succeeds, the new checkout looks right, and the writes land
535
+ * in the other repository, whose refs and object store are the ones changed.
536
+ *
537
+ * Runs before Git does, and judges the Git directory and its own entries only,
538
+ * never the object store below them: `git clone --local` hard-links object
539
+ * files by design and is an ordinary, independent clone. A checkout with no
540
+ * `.git` at all is left to Git, which reports it better than this can, and a
541
+ * `.git` file is Git's own indirection — a linked worktree and a submodule both
542
+ * use one — so it is left alone as well.
543
+ */
544
+ async function assertSoleGitDirectory(repoRoot: string): Promise<void> {
545
+ const gitDir = join(repoRoot, '.git')
546
+ const node = await lstat(gitDir).catch((cause) => {
547
+ if ((cause as NodeJS.ErrnoException).code === 'ENOENT') return undefined
548
+ throw cause
549
+ })
550
+ if (node === undefined) return
551
+
552
+ if (node.isSymbolicLink()) {
553
+ const target = await readlink(gitDir).catch(() => undefined)
554
+ throw new LinkedCheckoutError(
555
+ repoRoot,
556
+ `its .git is a symbolic link${target === undefined ? '' : ` to ${target}`}, so it uses another checkout's Git directory`,
557
+ )
558
+ }
559
+ if (!node.isDirectory()) {
560
+ // A `.git` file is Git's own indirection: a linked worktree
561
+ // (`gitdir: <common>/worktrees/<name>`) and a submodule
562
+ // (`gitdir: <super>/.git/modules/<name>`) both use one, and Git
563
+ // resolves the directory it names without writing outside it. Only a
564
+ // `.git` that is a link, or a directory whose state entries are links,
565
+ // hands Git a directory it does not own.
566
+ return
567
+ }
568
+
569
+ for (const name of await readdir(gitDir)) {
570
+ const entryPath = join(gitDir, name)
571
+ const entry = await lstat(entryPath)
572
+ if (entry.isSymbolicLink() && SHARED_STATE_ENTRIES.has(name)) {
573
+ const target = await readlink(entryPath).catch(() => undefined)
574
+ throw new LinkedCheckoutError(
575
+ repoRoot,
576
+ `its .git/${name} is a symbolic link${target === undefined ? '' : ` to ${target}`}, so Git would write through it into another checkout`,
577
+ )
578
+ }
579
+ if (entry.isFile() && entry.nlink > 1) {
580
+ throw new LinkedCheckoutError(
581
+ repoRoot,
582
+ `its .git/${name} is one of ${entry.nlink} hard links, so another checkout holds the same file`,
583
+ )
584
+ }
585
+ }
586
+ }
587
+
474
588
  /** Resolve every existing path component, preserving only a missing suffix. */
475
589
  async function canonicalizeThroughExisting(input: string): Promise<string> {
476
590
  let existing = resolve(input)
@@ -19,7 +19,12 @@ export type {
19
19
 
20
20
  export { WorkspaceBackendRegistry } from './registry.js'
21
21
 
22
- export { GitWorktreeDriver, defaultWorktreesDir, parseWorktreeList } from './git-worktree.js'
22
+ export {
23
+ GitWorktreeDriver,
24
+ LinkedCheckoutError,
25
+ defaultWorktreesDir,
26
+ parseWorktreeList,
27
+ } from './git-worktree.js'
23
28
  export type { ExecFile, ExecFileResult, GitWorktreeDriverConfig } from './git-worktree.js'
24
29
 
25
30
  export {
@@ -1,6 +1,10 @@
1
1
  import { createHash } from 'node:crypto'
2
2
  import type { CheckpointId, SessionId, TenantId, TurnId } from '../../types/ids/index.js'
3
- import { type Checkpoint, parseCheckpoint } from '../../types/session/checkpoint.js'
3
+ import {
4
+ type Checkpoint,
5
+ parseCheckpoint,
6
+ persistedTokenUsage,
7
+ } from '../../types/session/checkpoint.js'
4
8
  import type { ProjectId } from '../../types/session/ids.js'
5
9
  import { asCheckpointId, asProjectId, asSessionId, asTenantId, asTurnId } from '../../utils/id.js'
6
10
 
@@ -197,7 +201,10 @@ export class CheckpointOwnerError extends Error {
197
201
 
198
202
  /** Refuse a write whose document names another session or turn than its scope. */
199
203
  export function checkWriteOwner(scope: CheckpointScope, checkpoint: Checkpoint): Checkpoint {
200
- const parsed = parseCheckpoint(checkpoint)
204
+ const parsed = parseCheckpoint({
205
+ ...checkpoint,
206
+ tokenUsage: persistedTokenUsage(checkpoint.tokenUsage),
207
+ })
201
208
  if (parsed.sessionId !== scope.sessionId || parsed.turnId !== scope.turnId) {
202
209
  throw new CheckpointOwnerError(
203
210
  `Checkpoint ${parsed.checkpointId} belongs to session ${parsed.sessionId} turn ${parsed.turnId}; it cannot be written under session ${scope.sessionId} turn ${scope.turnId}.`,
@@ -5,6 +5,7 @@ import {
5
5
  } from '../../session/log-hash.js'
6
6
  import type { SessionId, TurnId } from '../../types/ids/index.js'
7
7
  import type { Message } from '../../types/message/index.js'
8
+ import { persistedTokenUsage } from '../../types/session/checkpoint.js'
8
9
  import {
9
10
  type RecordPointer,
10
11
  SESSION_RECORD_MAX_BYTES,
@@ -808,7 +809,11 @@ export class SessionLogCore implements SessionLog {
808
809
  gen: lease.fence,
809
810
  }
810
811
  const { type, ...payload } = draft as { type: string } & Record<string, unknown>
811
- let candidate: Record<string, unknown> = { ...envelope, type, ...payload }
812
+ let candidate: Record<string, unknown> = {
813
+ ...envelope,
814
+ type,
815
+ ...persistedUsageOf(type, payload),
816
+ }
812
817
  candidate = await this.#spillIfLarge(candidate)
813
818
  const parsed = SessionRecordSchema.safeParse(candidate)
814
819
  if (!parsed.success) {
@@ -1414,3 +1419,31 @@ export async function* walkSessionLog(
1414
1419
  ...(brokeAt === undefined ? {} : { break: brokeAt }),
1415
1420
  }
1416
1421
  }
1422
+
1423
+ /**
1424
+ * Keep only the persisted usage keys in the usage of a settled turn and of an ended child
1425
+ * session (see {@link persistedTokenUsage}): a usage total carries summed fields those
1426
+ * shapes do not name, and every release reads them strictly. Other records' usage (a
1427
+ * completed message's own) has its own shape and is left as it is.
1428
+ */
1429
+ function persistedUsageOf(type: string, payload: Record<string, unknown>): Record<string, unknown> {
1430
+ const project = (value: unknown) =>
1431
+ value && typeof value === 'object' && !Array.isArray(value)
1432
+ ? persistedTokenUsage(value as Parameters<typeof persistedTokenUsage>[0])
1433
+ : value
1434
+ if (type === 'child_session_ended' && payload.usage !== undefined) {
1435
+ return { ...payload, usage: project(payload.usage) }
1436
+ }
1437
+ const settlement = payload.settlement
1438
+ if (
1439
+ (type === 'turn_completed' || type === 'turn_failed') &&
1440
+ settlement &&
1441
+ typeof settlement === 'object' &&
1442
+ !Array.isArray(settlement) &&
1443
+ (settlement as Record<string, unknown>).usage !== undefined
1444
+ ) {
1445
+ const settled = settlement as Record<string, unknown>
1446
+ return { ...payload, settlement: { ...settled, usage: project(settled.usage) } }
1447
+ }
1448
+ return payload
1449
+ }
@@ -1,4 +1,5 @@
1
1
  import type { ToolDiffHunk, ToolFacts, ToolFailureReason } from '../types/tool/presentation.js'
2
+ import { isEntityId } from '../utils/id.js'
2
3
 
3
4
  const FAILURE_REASONS: readonly ToolFailureReason[] = [
4
5
  'not_found',
@@ -130,6 +131,25 @@ function hunks(value: unknown): readonly ToolDiffHunk[] | undefined {
130
131
  export function admitToolFacts(value: unknown): ToolFacts | undefined {
131
132
  if (!isRecord(value)) return undefined
132
133
  switch (value.kind) {
134
+ case 'delegate': {
135
+ const id = value.childSessionId
136
+ const status = value.childStatus
137
+ return pick<ToolFacts>({
138
+ kind: 'delegate',
139
+ description: text(value.description)?.slice(0, 240),
140
+ childSessionId: isEntityId(id, 'session') ? id : undefined,
141
+ childStatus:
142
+ status === 'pending' ||
143
+ status === 'running' ||
144
+ status === 'completed' ||
145
+ status === 'failed' ||
146
+ status === 'canceled' ||
147
+ status === 'rejected' ||
148
+ status === 'input-required'
149
+ ? status
150
+ : undefined,
151
+ })
152
+ }
133
153
  case 'command':
134
154
  return pick<ToolFacts>({
135
155
  kind: 'command',
@@ -8,6 +8,7 @@ import { appendDirsToPath } from '../../plugin/bin-path.js'
8
8
  import { killTree } from '../../process/kill-tree.js'
9
9
  import { genericLabel } from '../../registry/tool/presentation.js'
10
10
  import { cancelCauseOf } from '../../types/session/cancel-cause.js'
11
+ import type { ToolProgressDetails } from '../../types/tool/index.js'
11
12
  import type { ToolFacts } from '../../types/tool/presentation.js'
12
13
  import { subscribeToAbort } from '../../utils/abort.js'
13
14
  import { readPositiveIntEnv } from '../../utils/env.js'
@@ -28,6 +29,7 @@ import { defineTool } from '../defineTool.js'
28
29
  import { scrubInheritedEnv, withheldEnvNoticeText } from '../env-scrub.js'
29
30
  import { withSafeGitConfig } from '../git-config-env.js'
30
31
  import { createHostOutputDecoder } from '../host-output.js'
32
+ import { ShellOutputWindow } from '../shell-output-window.js'
31
33
  import { looksBinary, windowText } from '../text-window.js'
32
34
  import {
33
35
  bashWorkingDirectoryForExecution,
@@ -260,25 +262,22 @@ function progressLine(value: string): string {
260
262
  }
261
263
 
262
264
  /**
263
- * One latest line per stream, independent of transport chunk boundaries.
265
+ * Recent output and the latest progress line, independent of transport chunk boundaries.
264
266
  * Reports stay synchronous: the executor owns coalescing and backpressure.
265
- * This projection adds neither an output log nor a queue of pending reports.
267
+ * Only the rolling window and the current partial lines are held.
266
268
  */
267
269
  function shellProgress(
268
- report?: (
269
- message: string,
270
- fraction?: number,
271
- details?: { readonly outputLines?: number },
272
- ) => void,
270
+ report?: (message: string, fraction?: number, details?: ToolProgressDetails) => void,
273
271
  ) {
274
272
  if (!report) return undefined
275
273
  const partial = { stdout: '', stderr: '' }
274
+ const window = new ShellOutputWindow()
276
275
  let lastMessage = ''
277
276
  // Lines of output so far, both streams: every line feed seen. Counted here, on
278
277
  // every chunk, because the reports below are coalesced and a viewer counting
279
278
  // the messages it received would undercount a fast command.
280
279
  let outputLines = 0
281
- let lastLines = 0
280
+
282
281
  return ({ stream, data }: { stream: 'stdout' | 'stderr'; data: string }): void => {
283
282
  let line = partial[stream]
284
283
  let latest = ''
@@ -294,11 +293,11 @@ function shellProgress(
294
293
  line = appendProgressTail(line, data, start, data.length)
295
294
  partial[stream] = line
296
295
  const message = progressLine(line) || latest
297
- if (!message || (message === lastMessage && outputLines === lastLines)) return
298
- lastMessage = message
299
- lastLines = outputLines
296
+ if (message) lastMessage = message
297
+ const output = window.append(stream, data)
298
+ if (!lastMessage) return
300
299
  try {
301
- report(message, undefined, { outputLines })
300
+ report(lastMessage, undefined, { outputLines, output })
302
301
  } catch {
303
302
  // A diagnostic observer cannot break the process output reader.
304
303
  }
@@ -725,7 +725,10 @@ function renderResult(host: BrowserHost, result: BrowserResult): ToolResult {
725
725
  else if (result.page && !result.screenshot) parts.push(formatBrowserPageHeader(result.page))
726
726
 
727
727
  const page = result.snapshot?.page ?? result.screenshot?.page ?? result.value?.page ?? result.page
728
- const data = page ? { page: { origin: headerOrigin(page), url: page.url, tab: page.tab } } : {}
728
+ const data = {
729
+ ...(page ? { page: { origin: headerOrigin(page), url: page.url, tab: page.tab } } : {}),
730
+ ...(result.paneFallback ? { paneFallback: result.paneFallback } : {}),
731
+ }
729
732
 
730
733
  if (result.screenshot) {
731
734
  const shot = result.screenshot
@@ -751,6 +754,14 @@ function renderResult(host: BrowserHost, result: BrowserResult): ToolResult {
751
754
  return { success: true, output: parts.join('\n') || 'Done.', data }
752
755
  }
753
756
 
757
+ function presentPaneFallback(_input: unknown, result: ToolResult) {
758
+ const fallback = (result.data as Pick<BrowserResult, 'paneFallback'> | undefined)?.paneFallback
759
+ if (fallback) {
760
+ return { kind: 'terminal' as const, output: result.output, paneFallback: fallback }
761
+ }
762
+ return undefined
763
+ }
764
+
754
765
  // ---------------------------------------------------------------------------
755
766
  // Host errors
756
767
  // ---------------------------------------------------------------------------
@@ -820,7 +831,7 @@ function hostErrorToResult(tool: string, error: BrowserHostError): ToolResult {
820
831
  )
821
832
  case 'browser_stale_ref':
822
833
  return refusal(
823
- `${tool}: element ${error.ref} is not on the page any more (it came from an older snapshot). Nothing was done. Take a new snapshot and use a ref from it.`,
834
+ `${tool}: element ${error.ref} no longer matches the older snapshot of this tab. Nothing was done. Take a new snapshot and use a ref from it.`,
824
835
  { code: error.code, ref: error.ref },
825
836
  )
826
837
  case 'browser_human_required': {
@@ -1053,7 +1064,7 @@ function actDescription(caps: BrowserCapabilities): string {
1053
1064
  return [
1054
1065
  "Changes the page in the web browser: click, type, fill_form, select, press, hover, upload, dialog (accept or dismiss a page alert, confirm or prompt; a prompt takes promptText, never a password or code). Act by ref from the latest snapshot of the browser tool. When an element has no ref (a menu that opens on hover, a control the snapshot leaves out), click and hover also take its visible text, or its role with its accessible name; they refuse and list the candidates when none or several match. A click or hover on a large container lands on the container's own text or its first control, not its middle.",
1055
1066
  'press takes a key; without ref it sends Escape, Enter, Tab, Shift+Tab, PageDown, PageUp, Home, End or Space to the focused element, and refuses when that is a password or code field. type can send real key presses (keys), keep the existing text (append) or clear first (clear).',
1056
- 'Every call must carry origin, copied from the snapshot header ("Page: <origin> — …"); if the page is no longer on that origin nothing is done. A stale ref is refused the same way: take a new snapshot.',
1067
+ 'Every call must carry origin, copied from the snapshot header ("Page: <origin> — …"); if the page is no longer on that origin nothing is done. A ref is refused if the tab or page changed, or if the ref no longer names the same role and accessible name. Take a new snapshot before trying again.',
1057
1068
  'Every result starts with "Effect:", what the action did to the page (lines that appeared or went, an address change, or "no visible change"). Read it before the next call: "no visible change" means nothing happened, so do not repeat the same call; look at the page or choose a different element. Set snapshot: true to get the whole page back after the action. Leave passwords and one-time codes to the person, because a model that holds a credential can be steered into leaking it; if the page needs a person, stop and tell the user.',
1058
1069
  'Example, filling two fields: {"action":"fill_form","origin":"https://example.com","fields":[{"ref":"e12","value":"<text>"},{"ref":"e14","value":"<text>"}]}.',
1059
1070
  ...unavailableLine(caps),
@@ -1197,6 +1208,7 @@ export function createBrowserTools(
1197
1208
  // A page is looked at to be acted on, and an action is read back by
1198
1209
  // looking: the two load in one search.
1199
1210
  loadsWith: [BROWSER_ACT_TOOL_NAME],
1211
+ presentResult: presentPaneFallback,
1200
1212
  presentCall: (input) => ({
1201
1213
  kind: 'generic',
1202
1214
  label: observeLabel(host, input),
@@ -1256,6 +1268,7 @@ export function createBrowserTools(
1256
1268
  concurrencySafe: false,
1257
1269
  pathArgument: 'path',
1258
1270
  loadsWith: [BROWSER_TOOL_NAME],
1271
+ presentResult: presentPaneFallback,
1259
1272
  presentCall: (input) => ({
1260
1273
  kind: 'generic',
1261
1274
  label: actLabel(host, input),