dsh-codex-style-computer-use 2.3.1 → 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.
- package/lib/argument-recovery.js +50 -0
- package/lib/core/bin/dsh-computer-use-worker.exe +0 -0
- package/lib/core/bin/dsh-computer-use-worker.exe.json +2 -2
- package/lib/core/index.js +18 -2
- package/lib/core/worker.cs +972 -121
- package/lib/image-output.js +1 -1
- package/lib/index.js +3 -0
- package/lib/key-command.js +3 -3
- package/lib/tools.js +233 -78
- package/mcp/src/tools.js +5 -2
- package/package.json +1 -1
- package/scripts/check-behavior.mjs +2 -1
- package/skills/computer-use/SKILL.md +28 -0
- package/skills/computer-use/scripts/inspect-borrow.py +113 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// The agent loop settles a failed model response before dispatching any of its tools.
|
|
2
|
+
// Returning retry at this boundary regenerates only this step, on the existing turn.
|
|
3
|
+
export function installArgumentRecovery (ctx, names, buildNotice, isAgentLoopRequest) {
|
|
4
|
+
if (typeof isAgentLoopRequest !== 'function') return
|
|
5
|
+
const attempts = new WeakMap()
|
|
6
|
+
|
|
7
|
+
ctx.on('agent/request-error', async ({ agent, turn, step, signal, failure }, next) => {
|
|
8
|
+
if (signal.aborted || failure.code !== 'MALFORMED_RESPONSE') return next()
|
|
9
|
+
const message = failure.message ?? ''
|
|
10
|
+
const name = /^Tool call "(computer_[a-z0-9_]+)": /.exec(message)?.[1]
|
|
11
|
+
if (!names.has(name) || !message.includes('\n\nReceived arguments:\n')) return next()
|
|
12
|
+
const session = agent.session
|
|
13
|
+
if (!session.requestHeader()?.tools?.some(tool => tool.name === name)) return next()
|
|
14
|
+
|
|
15
|
+
const previous = attempts.get(signal)
|
|
16
|
+
const count = previous?.sessionId === session.id && previous.turn === turn && previous.step === step ? previous.count + 1 : 1
|
|
17
|
+
const state = { sessionId: session.id, turn, step, count, name }
|
|
18
|
+
const text = [
|
|
19
|
+
`Windows Computer Use: ${name} had invalid JSON. No tool from the failed response ran. Earlier tool results are already recorded.`,
|
|
20
|
+
'Continue the current task from those results. Generate the pending action using the advertised parameter types.',
|
|
21
|
+
...(name === 'computer_click' ? ['The JSON shape for a coordinate click is {"at":"<screenX>,<screenY>"}. Replace both placeholders with the observed screen coordinates.'] : []),
|
|
22
|
+
...(count === 2 ? ['If this format keeps failing, use another available approach or explain what remains in plain text.'] : []),
|
|
23
|
+
].join(' ')
|
|
24
|
+
if (count <= 2) {
|
|
25
|
+
const notice = await buildNotice(text, `correct ${name} arguments (attempt ${count})`)
|
|
26
|
+
signal.throwIfAborted()
|
|
27
|
+
session.append('user/message', notice, { surfaceOp: 'append' })
|
|
28
|
+
}
|
|
29
|
+
attempts.set(signal, state)
|
|
30
|
+
return { kind: 'retry' }
|
|
31
|
+
}, { prepend: true })
|
|
32
|
+
|
|
33
|
+
// After two unsuccessful corrections the host still needs a normal finish. Publish an
|
|
34
|
+
// explicitly plugin-authored status through the chat stream, with no tool blocks.
|
|
35
|
+
ctx.on('llm/stream', (request, next) => {
|
|
36
|
+
const state = attempts.get(request.signal)
|
|
37
|
+
if (!state || state.count <= 2 || state.sessionId !== request.sessionId || !isAgentLoopRequest(request)) return next()
|
|
38
|
+
request.signal.throwIfAborted()
|
|
39
|
+
attempts.delete(request.signal)
|
|
40
|
+
return checkpoint(state.name)
|
|
41
|
+
}, { prepend: true })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function * checkpoint (name) {
|
|
45
|
+
const text = `Windows Computer Use 插件:模型连续三次生成了无效的工具参数,最后一次是 ${name}。这一步尚未执行,之前的操作结果已保留。可以在本对话继续。`
|
|
46
|
+
yield { type: 'block-start', index: 0, blockType: 'text' }
|
|
47
|
+
yield { type: 'text-delta', index: 0, text }
|
|
48
|
+
yield { type: 'block-end', index: 0, block: { type: 'text', text } }
|
|
49
|
+
yield { type: 'finish', reason: { kind: 'stop' } }
|
|
50
|
+
}
|
|
Binary file
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"format": 1,
|
|
3
3
|
"platform": "win32",
|
|
4
4
|
"architecture": "x64",
|
|
5
|
-
"sourceSha256": "
|
|
6
|
-
"binarySha256": "
|
|
5
|
+
"sourceSha256": "ebbf272345b97a9f1131222da00bab2a2b657a2907da7dea406fe895b98d6057",
|
|
6
|
+
"binarySha256": "4d849ce169734ab03aee4ee3ee7b5991cb49c34545274bb4a00105b6bed3a153"
|
|
7
7
|
}
|
package/lib/core/index.js
CHANGED
|
@@ -28,6 +28,10 @@ const INPUT_CLEANUP_GRACE_MS = 1500
|
|
|
28
28
|
// A UIA tree walk can block the resident's synchronous COM thread. Bound the
|
|
29
29
|
// caller's wait separately from recovery of a worker that never returns.
|
|
30
30
|
const UIA_READS = new Set(['uia', 'uiaFromPoint', 'uiaFocused'])
|
|
31
|
+
function holdDuration (value) {
|
|
32
|
+
if (!Number.isInteger(value) || value < 20 || value > 2000) throw new Error('durationMs must be an integer from 20 to 2000')
|
|
33
|
+
return value
|
|
34
|
+
}
|
|
31
35
|
const URGENT_CONTROL = new Set(['cancelInput', 'abort', 'panic', 'exit', 'endAsk'])
|
|
32
36
|
const INPUT_OPS = new Set(['click', 'shiftClick', 'move', 'drag', 'scroll', 'selectRange',
|
|
33
37
|
'type', 'key', 'uiaAct', 'windowOp', 'activate', 'clipWrite', 'calibrate', 'selftest'])
|
|
@@ -738,6 +742,7 @@ export class ComputerUse extends EventEmitter {
|
|
|
738
742
|
const data = await this.call('capture', {
|
|
739
743
|
x: opts.x, y: opts.y, width: opts.width, height: opts.height,
|
|
740
744
|
preset: opts.preset,
|
|
745
|
+
shotWindow: opts.hwnd, clickWitness: opts.clickWitness === true,
|
|
741
746
|
format: opts.format || 'jpeg',
|
|
742
747
|
quality: opts.quality ?? 75,
|
|
743
748
|
// ~1280 wide ≈ Anthropic WXGA guidance: ⌈w/28⌉×⌈h/28⌉ tokens ≈ 1600; bigger
|
|
@@ -825,8 +830,13 @@ export class ComputerUse extends EventEmitter {
|
|
|
825
830
|
const pt = await this.resolveTarget(target) // {x,y} | {mark:'M3'} | [x,y]
|
|
826
831
|
return this.actuate('click', {
|
|
827
832
|
x: pt.x, y: pt.y, button: opts.button || 'left', clicks: opts.clicks || 1,
|
|
833
|
+
...(opts.ctrl ? { ctrl: true } : {}), ...(opts.shift ? { shift: true } : {}),
|
|
834
|
+
...(opts.durationMs !== undefined ? { holdMs: holdDuration(opts.durationMs) } : {}),
|
|
828
835
|
settleMs: opts.settleMs ?? 40,
|
|
829
836
|
...(witness ? { verificationRegion: witness } : {}),
|
|
837
|
+
...(opts.shotGeometry ? { shotGeometry: opts.shotGeometry } : {}),
|
|
838
|
+
...(opts.shotWitness ? { shotWitness: opts.shotWitness } : {}),
|
|
839
|
+
...(opts.strictHwnd ? { strictHwnd: true } : {}),
|
|
830
840
|
// Embedded renderers (a WeChat article panel, an Electron child) belong to a DIFFERENT
|
|
831
841
|
// process than the window that hosts them, so the occlusion check reads them as "covered"
|
|
832
842
|
// even though the pixel is inside the app the caller activated. The worker already
|
|
@@ -851,7 +861,9 @@ export class ComputerUse extends EventEmitter {
|
|
|
851
861
|
const o = opts || {}
|
|
852
862
|
const at = o.at || (o.x !== undefined && o.y !== undefined ? o : null)
|
|
853
863
|
const pt = at ? await this.resolveTarget(at) : null
|
|
854
|
-
return this.actuate('scroll', { direction, lines, ...(pt ? { x: pt.x, y: pt.y } : {})
|
|
864
|
+
return this.actuate('scroll', { direction, lines, ...(pt ? { x: pt.x, y: pt.y } : {}),
|
|
865
|
+
...(o.expectHwnd ? { expectHwnd: o.expectHwnd } : {}),
|
|
866
|
+
...(o.strictHwnd ? { strictHwnd: true } : {}), ...(o.shotGeometry ? { shotGeometry: o.shotGeometry } : {}) })
|
|
855
867
|
}
|
|
856
868
|
|
|
857
869
|
// Anchor-based selection: click the START, scroll freely, then shift+click the END.
|
|
@@ -1108,7 +1120,9 @@ export class ComputerUse extends EventEmitter {
|
|
|
1108
1120
|
async calibrate (opts = {}) { return this.actuate('calibrate', opts) }
|
|
1109
1121
|
|
|
1110
1122
|
async key (combo, opts = {}) {
|
|
1111
|
-
|
|
1123
|
+
const holdMs = opts.durationMs === undefined ? opts.holdMs ?? 60 : holdDuration(opts.durationMs)
|
|
1124
|
+
return this.actuate('key', { combo: parseKeyCommand(combo).combo, holdMs, ...(opts.expectHwnd ? { expectHwnd: opts.expectHwnd } : {}),
|
|
1125
|
+
...(opts.strictHwnd ? { strictHwnd: true } : {}) })
|
|
1112
1126
|
}
|
|
1113
1127
|
|
|
1114
1128
|
async type (text, opts = {}) {
|
|
@@ -1125,7 +1139,9 @@ export class ComputerUse extends EventEmitter {
|
|
|
1125
1139
|
const automatic = !opts.mode || opts.mode === 'auto'
|
|
1126
1140
|
const mode = automatic ? (/[\u0100-\uffff]/.test(text) || text.length > 80 ? 'paste' : 'unicode') : opts.mode
|
|
1127
1141
|
const args = {
|
|
1142
|
+
...(opts.expectTarget ? { expectTarget: opts.expectTarget } : {}),
|
|
1128
1143
|
text, mode, restoreClipboard: opts.restoreClipboard ?? true,
|
|
1144
|
+
...(opts.strictHwnd ? { strictHwnd: true } : {}),
|
|
1129
1145
|
...(opts.expectHwnd ? { expectHwnd: opts.expectHwnd } : {}),
|
|
1130
1146
|
}
|
|
1131
1147
|
try {
|