dsh-codex-style-computer-use 2.3.0 → 2.3.2

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.
@@ -4,7 +4,7 @@ import { captureCoordinates } from './media-contract.js'
4
4
 
5
5
  export function screenshotMetadata (shot) {
6
6
  const value = {}
7
- for (const key of ['capturedAt', 'ts', 'imageSize', 'settled', 'settleMs', 'settleDiffPct', 'settleNote',
7
+ for (const key of ['hwnd', 'captureBackend', 'capturedAt', 'ts', 'imageSize', 'settled', 'settleMs', 'settleDiffPct', 'settleNote',
8
8
  'cursor', 'cursorRequested', 'cursorDrawn', 'cursorScreenPos', 'cursorInImage', 'cursorNote']) {
9
9
  if (shot[key] !== undefined) value[key] = shot[key]
10
10
  }
@@ -21,39 +21,32 @@ function setCoordinates (value, size) {
21
21
  const validImageSize = size => Array.isArray(size) && size.length === 2 && size.every(n => Number.isFinite(n) && n > 0)
22
22
  const validPoint = point => Number.isFinite(point?.x) && Number.isFinite(point?.y)
23
23
 
24
- function restoreFileGeometry (value) {
25
- if (!value.sourceImageSize) return
26
- value.imageSize = value.sourceImageSize
27
- if (value.sourceCursorInImage) value.cursorInImage = value.sourceCursorInImage
28
- else delete value.cursorInImage
29
- delete value.sourceImageSize
30
- delete value.sourceCursorInImage
24
+ export function screenshotPathOnly (value, reason) {
25
+ value.imageStatus = 'path-only'
26
+ value.imageReason = reason
31
27
  setCoordinates(value, value.imageSize)
28
+ const notes = {
29
+ 'model-text-only': 'Image not attached: this model does not declare image input. Use UIA/text or switch to an image-capable model.',
30
+ 'delivery-path': 'Path delivery requested: no image block was attached. The file is on path; call read_image only if visual inspection is actually needed.',
31
+ 'earlier-batch-image': 'This earlier capture is available at its path.',
32
+ }
33
+ value.view = notes[reason] || 'Image not attached. Use read_image on path if visual inspection is needed.'
34
+ if (value.settled === false) value.view = 'NOT settled — re-shoot. ' + value.view
35
+ return value
32
36
  }
33
37
 
34
38
  // DSH image blocks reference the host's durable attachment store. Paths and raw
35
39
  // base64 are not image blocks. Keep a usable file when a route cannot accept one.
36
40
  export async function attachScreenshot (ctx, exec, value, data, options = {}) {
37
- // The local file has geometry even when the model route cannot accept images.
38
- setCoordinates(value, value.imageSize)
39
- const fallback = (reason) => {
40
- delete value.image
41
- restoreFileGeometry(value)
42
- value.imageStatus = 'path-only'
43
- value.imageReason = reason
44
- value.view = reason === 'model-text-only'
45
- ? 'Image not attached: this model does not declare image input. Use UIA/text or switch to an image-capable model.'
46
- : reason === 'delivery-path'
47
- ? 'Path delivery requested: no image block was attached. The file is on path; call read_image only if visual inspection is actually needed.'
48
- : 'Image not attached. Use read_image on path if visual inspection is needed.'
49
- if (value.settled === false) value.view = 'NOT settled — re-shoot. ' + value.view
50
- return value
51
- }
41
+ const fallback = reason => screenshotPathOnly(value, reason)
52
42
  // delivery:"path" — the caller has another way to verify (UIA/OCR/window text), so the pixels
53
43
  // are not evidence it will read. The file is still written and the path still returned; only
54
44
  // the image block is withheld, which is what keeps it out of the re-sent conversation history.
55
45
  if (options.delivery === 'path') return fallback('delivery-path')
46
+ const blocked = () => exec?.signal?.aborted || options.blocked?.()
56
47
  try {
48
+ const interrupted = () => fallback(exec?.signal?.aborted ? 'cancelled' : 'cancelled-or-paused')
49
+ if (blocked()) return interrupted()
57
50
  if (!validImageSize(value.imageSize)) return fallback('invalid-source-image-size')
58
51
  const sourceSize = [...value.imageSize]
59
52
  const attachments = ctx.get?.('attachments')
@@ -65,10 +58,10 @@ export async function attachScreenshot (ctx, exec, value, data, options = {}) {
65
58
  if (!llm?.resolveModelInfo || !provider || !model) return fallback('route-unavailable')
66
59
  const active = await llm.resolveModelInfo(provider, model, exec?.signal)
67
60
  if (!active.inputModalities?.includes('image')) return fallback('model-text-only')
68
- if (exec?.signal?.aborted) return fallback('cancelled')
61
+ if (blocked()) return interrupted()
69
62
  if (!attachments.imageLimits?.mediaTypes?.includes(value.mime)) return fallback('media-type-unavailable')
70
63
  const image = await attachments.saveImage({ data, mediaType: value.mime, name: basename(value.path) })
71
- if (exec?.signal?.aborted) return fallback('cancelled')
64
+ if (blocked()) return interrupted()
72
65
  const attachedSize = [image?.width, image?.height]
73
66
  if (!validImageSize(attachedSize)) return fallback('invalid-attachment-image-size')
74
67
  const evidence = visionEvidence(exec, { ...options, adapterVersion: active.adapterVersion || 'unversioned' })
@@ -84,6 +77,7 @@ export async function attachScreenshot (ctx, exec, value, data, options = {}) {
84
77
  }
85
78
  value.image = image
86
79
  value.imageStatus = 'attached'
80
+ delete value.imageReason
87
81
  setCoordinates(value, attachedSize)
88
82
  if (resized && value.coordinateRule) value.coordinateRule += ' imageSize, cursorInImage and coordinates describe the attached image. path retains the original capture: use sourceImageSize and sourceCursorInImage for that file; map its pixels using region.width/sourceImageSize[0] and region.height/sourceImageSize[1].'
89
83
  value.view = value.settled === false
@@ -111,48 +105,12 @@ export function renderScreenshot (value) {
111
105
  ]
112
106
  }
113
107
 
114
- // A batch exposes one latest image as its checkpoint. Earlier explicit captures
115
- // keep their paths for deliberate later reads, without multiplying vision input.
116
- //
117
- // `delivery` is the batch-level request, and it has to reach further than the checkpoint: when
118
- // no checkpoint happens (shot:"never", a readback tail, or a later failure) the observation
119
- // falls back to the last explicit step image. A batch that asked for paths must not hand one
120
- // back as a picture just because the checkpoint was skipped — same pixels, quieter route.
121
- export function selectBatchScreenshot (result, automatic, kind = 'image', delivery = 'auto') {
122
- let latest = automatic
123
- let index
124
- if (!latest) {
125
- for (const [i, action] of result.actions.entries()) {
126
- if (action.tool === 'computer_shot' && action.result?.path) {
127
- latest = action.result
128
- index = i
129
- }
130
- }
131
- }
132
- const pathDelivery = delivery === 'path'
133
- const pathNote = 'Path delivery requested: no image block was attached. Use read_image on this path only if these pixels are the evidence.'
134
- for (const action of result.actions) {
135
- const shot = action.result
136
- if (shot?.image && shot !== latest) {
137
- delete shot.image
138
- restoreFileGeometry(shot)
139
- shot.imageStatus = 'path-only'
140
- shot.imageReason = pathDelivery ? 'delivery-path' : 'earlier-batch-image'
141
- shot.view = pathDelivery
142
- ? pathNote
143
- : kind === 'state'
144
- ? 'A newer UIA state is returned. This earlier image remains at its path.'
145
- : 'Only the latest batch screenshot is attached. Use read_image on this path if this earlier frame is needed.'
146
- }
147
- }
108
+ // If no automatic checkpoint exists (including after a failed step), identify the
109
+ // last successful explicit capture by its actual step, not the end of the batch.
110
+ export function selectBatchScreenshot (result, automatic, kind = 'image') {
111
+ const index = automatic ? -1 : result.actions.findLastIndex(a => a.tool === 'computer_shot' && a.result?.path)
112
+ const latest = automatic ?? result.actions[index]?.result
148
113
  if (latest) {
149
- if (pathDelivery && latest.image) {
150
- delete latest.image
151
- restoreFileGeometry(latest)
152
- latest.imageStatus = 'path-only'
153
- latest.imageReason = 'delivery-path'
154
- latest.view = pathNote
155
- }
156
114
  result.observation = latest
157
115
  if (kind === 'state') result.observationSource = 'automatic final UIA state'
158
116
  else result.imageSource = automatic ? 'automatic final screenshot' : `action ${index + 1}; captured before any later actions`
package/lib/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { installApprovalAttribution } from './approval-attribution.js'
2
+ import { installArgumentRecovery } from './argument-recovery.js'
3
+ import * as hostLlm from '@deepseek-ai/dsh-llm'
2
4
  import { HOST_DEBUG_FILE, noteHostBlocked, readHostDebug, sessionPermission, writeHostDebug } from './host-debug.js'
3
5
  import { installHumanAttention } from './attention.js'
4
6
  // dsh-computer-use — DSH Cordis plugin
@@ -1354,6 +1356,7 @@ export function apply (ctx, config) {
1354
1356
 
1355
1357
  const definitions = []
1356
1358
  registerTools({ ctx, cu, config, dataDir, log, snapshotPath, defineTool, hooks, ensureCycle, register: d => definitions.push(d) })
1359
+ installArgumentRecovery(ctx, new Set([ACTIVATION_TOOL, ...definitions.map(tool => tool.name)]), buildMessage, hostLlm.isAgentLoopRequest)
1357
1360
  installToolExposure({ ctx, definitions, defineTool, scopeOf, log, enabled: config.progressiveTools !== false,
1358
1361
  skillPath: fileURLToPath(new URL('SKILL.md', SKILL_DIR_URL)),
1359
1362
  readSkill: () => fs.readFileSync(fileURLToPath(new URL('SKILL.md', SKILL_DIR_URL)), 'utf8') })
@@ -1,7 +1,7 @@
1
1
  // One command grammar for approval and dispatch. Native parsing implements the
2
2
  // same contract for direct worker clients; cross-language fixtures guard parity.
3
3
  export const KEY_ALIASES = Object.freeze({
4
- control: 'ctrl', lwin: 'win', windows: 'win', meta: 'win',
4
+ control_l: 'ctrl', shift_l: 'shift', alt_l: 'alt', control: 'ctrl', lwin: 'win', windows: 'win', meta: 'win',
5
5
  return: 'enter', escape: 'esc', bksp: 'backspace', del: 'delete',
6
6
  ins: 'insert', pageup: 'pgup', pagedown: 'pgdn', capslock: 'caps', printscreen: 'prtsc',
7
7
  })
@@ -15,8 +15,8 @@ export function parseKeyCommand (combo) {
15
15
  const unique = []
16
16
  for (const part of combo.split('+')) {
17
17
  const raw = part.trim().toLowerCase()
18
- const key = KEY_ALIASES[raw] || raw
19
- if (!key || !(named.has(key) || /^[a-z0-9]$/.test(key) || /^f(?:[1-9]|1\d|2[0-4])$/.test(key))) {
18
+ const key = KEY_ALIASES[raw] || raw.replace(/^(?:numpad_|kp_)([0-9])$/, 'numpad$1')
19
+ if (!key || !(named.has(key) || /^numpad[0-9]$/.test(key) || /^[a-z0-9]$/.test(key) || /^f(?:[1-9]|1\d|2[0-4])$/.test(key))) {
20
20
  throw new Error(`KEY_COMMAND_INVALID: unknown or empty key ${JSON.stringify(raw)}`)
21
21
  }
22
22
  if (!unique.includes(key)) unique.push(key)