Record capability-specific reminders and cover cleanup error combinations

This commit is contained in:
creatixchu committed 2026-11-19 15:42:52 +08:00
1 parent 34f4901dc7
commit e5ee75a1eb
10 files changed
+41 -16

No files matched your search

@@ -1 +1 @@
DeepSeek Harness Computer Use: observe and operate desktop applications on this machine. Start every conversation by calling cua_get_api_reference: it returns the complete cua API reference, and programs written without it guess the API wrong. Then call cua_run_code with a TypeScript program that uses the global cua object; program state persists across calls on this connection. A call may ask the user for application or pointer consent before it proceeds. Call cua_reset to discard program state. Explicit key and mouse downs remain held across successful programs; a system reminder lists remaining holds. Explicit up, program failure, request cancellation, reset, and connection closure release owned input. Client pause between completed calls is not observable by this server and does not release input.
DeepSeek Harness Computer Use: observe and operate desktop applications on this machine. Start every conversation by calling cua_get_api_reference: it returns the complete cua API reference, and programs written without it guess the API wrong. Then call cua_run_code with a TypeScript program that uses the global cua object; program state persists across calls on this connection. A call may ask the user for application or pointer consent before it proceeds. Call cua_reset to discard program state.
@@ -53,7 +53,7 @@ Available at app or window level depending on the platform.
- pressKey(key: string, modifiers?: Modifier[]) -> ActionResult — press and release one complete keystroke. For example pressKey('Tab', ['shift']) or pressKey('+'). Key names are platform-defined strings. Pass key and modifiers separately; do not pack them into a chord string.
- sendKeyEvent(key: string, direction: 'down' | 'up') -> ActionResult — send one key-down or key-up event; key accepts a single key name, including a modifier.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them at their original recipient. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them through the same target. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
click, drag, and pressKey are convenience operations; sendKeyEvent, mouseMove, and toggleMouse are primitive operations. For complex action combinations, decompose convenience operations into sequences of primitive operations supported by the current platform.
@@ -240,7 +240,7 @@ describe('Computer Use MCP composition', () => {
expect(native.held).toEqual([])
})
it.each(['reset', 'image failure'] as const)('cleans up held input when %s interrupts response delivery', async (ending) => {
it.each(['reset', 'image failure', 'cleanup failure'] as const)('cleans up held input when %s interrupts response delivery', async (ending) => {
const { ctx, native, client, run } = await setup()
const entered: PromiseWithResolvers<void> = Promise.withResolvers()
const finish: PromiseWithResolvers<void> = Promise.withResolvers()
@@ -249,7 +249,7 @@ describe('Computer Use MCP composition', () => {
if (native.calls.some(call => call.method === 'getHeldInputs')) {
entered.resolve()
await finish.promise
if (ending === 'image failure') throw new Error('Fixture screenshot could not be delivered')
if (ending !== 'reset') throw new Error('Fixture screenshot could not be delivered')
}
return original(...args)
})
@@ -268,12 +268,22 @@ describe('Computer Use MCP composition', () => {
release.reply()
expect(resetDone).toBe(false)
}
if (ending === 'cleanup failure') {
const release = native.controlNext('releaseHeldInputs')
finish.resolve()
await release.entered
release.reply({ code: 'INPUT_CLEANUP_FAILED', message: 'Fixture cleanup refused during response delivery' })
}
} finally { finish.resolve() }
const result = await running
expect(result).not.toContain('CUA inputs are still held')
if (ending === 'image failure') expect(result).toContain('Fixture screenshot could not be delivered')
if (ending !== 'reset') expect(result).toContain('Fixture screenshot could not be delivered')
if (ending === 'cleanup failure') {
expect(result).toContain('Fixture cleanup refused during response delivery')
const next = await run('await win.sendKeyEvent("w", "down")')
expect(texts(next).join(' ')).toContain('INPUT_CLEANUP_UNCONFIRMED')
} else expect(native.held).toEqual([])
expect((await reset)?.isError).not.toBe(true)
expect(native.held).toEqual([])
})
it('reports refused cleanup after a cancelled MCP request and prevents further native input', async () => {
@@ -407,6 +407,19 @@ it('releases keyboard and mouse in mixed reverse order on program failure', asyn
expect(results.map(result => result.isError)).toEqual([false, true, false])
})
it('releases a previous hold when downstream execution throws before producing a result', async () => {
const f = await setup([holdProgram], 'macos', undefined, true, true)
await f.run()
f.model.restart(['inspect("unreachable")'])
f.ctx.on('tools/execute', (execution, next) => {
if (execution.name === 'cua_run_code') throw new Error('Executor middleware failed')
return next()
})
await f.run()
expect(f.native.events).toEqual(['w:down', 'w:up'])
expect(JSON.stringify(f.agent.session.deriveMessages())).toContain('Executor middleware failed')
})
it('reminders name the actual mouse target and omit explicitly released inputs', async () => {
const f = await setup([holdProgram, 'await app.sendKeyEvent("w", "up"); var win = await app.getWindow("7"); await win.toggleMouse("left", "down")'],
'macos', undefined, true, true)
@@ -683,13 +696,17 @@ it('drops a delayed held-state reminder after cancellation has already released
expect(reminders(f.agent, 'cua-inputs-released')).toHaveLength(1)
})
it('does not report held input when stopped as its native state query replies', async () => {
it.each(['reply before stop', 'stop before reply'] as const)('does not report held input on %s', async (order) => {
const f = await setup([holdProgram], 'macos', undefined, true, true)
const query = f.native.controlNext('getHeldInputs', { afterDispatch: true })
const query = f.native.controlNext('getHeldInputs', { afterDispatch: true, waitForCancellation: order === 'stop before reply' })
const running = f.run()
await query.entered
query.reply()
if (order === 'reply before stop') query.reply()
f.agent.cancel({ kind: 'user' })
if (order === 'stop before reply') {
await query.cancelled
query.reply({ code: 'NATIVE_CANCELLED', message: 'Held-state query cancelled' })
}
await running
expect(f.native.held).toEqual([])
expect(f.agent.inbox.nextStep.some(message => message.source.kind === 'cua-held-inputs')).toBe(false)
@@ -87,7 +87,7 @@ Available at app or window level depending on the platform.
- pressKey(key: string, modifiers?: Modifier[]) -> ActionResult — press and release one complete keystroke. For example pressKey('Tab', ['shift']) or pressKey('+'). Key names are platform-defined strings. Pass key and modifiers separately; do not pack them into a chord string.
- sendKeyEvent(key: string, direction: 'down' | 'up') -> ActionResult — send one key-down or key-up event; key accepts a single key name, including a modifier.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them at their original recipient. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them through the same target. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
click, drag, and pressKey are convenience operations; sendKeyEvent, mouseMove, and toggleMouse are primitive operations. For complex action combinations, decompose convenience operations into sequences of primitive operations supported by the current platform.
@@ -90,7 +90,7 @@ Available at app or window level depending on the platform.
- pressKey(key: string, modifiers?: Modifier[]) -> ActionResult — press and release one complete keystroke. For example pressKey('Tab', ['shift']) or pressKey('+'). Key names are platform-defined strings. Pass key and modifiers separately; do not pack them into a chord string.
- sendKeyEvent(key: string, direction: 'down' | 'up') -> ActionResult — send one key-down or key-up event; key accepts a single key name, including a modifier. For example W down, D down, D up, W up. A repeated 'down' for an ordinary held key sends one repeat without adding another hold.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them at their original recipient. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them through the same target. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
click, drag, and pressKey are convenience operations; sendKeyEvent, mouseMove, and toggleMouse are primitive operations. For complex action combinations, decompose convenience operations into sequences of primitive operations supported by the current platform.
@@ -92,7 +92,7 @@ Available at app or window level depending on the platform.
- pressKey(key: string, modifiers?: Modifier[]) -> ActionResult — press and release one complete keystroke. For example pressKey('Tab', ['shift']) or pressKey('+'). Key names are platform-defined strings. Pass key and modifiers separately; do not pack them into a chord string.
- sendKeyEvent(key: string, direction: 'down' | 'up') -> ActionResult — send one key-down or key-up event; key accepts a single key name, including a modifier. For example W down, D down, D up, W up. A repeated 'down' for an ordinary held key sends one repeat without adding another hold.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them at their original recipient. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them through the same target. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
click, drag, and pressKey are convenience operations; sendKeyEvent, mouseMove, and toggleMouse are primitive operations. For complex action combinations, decompose convenience operations into sequences of primitive operations supported by the current platform.
@@ -88,7 +88,7 @@ Available at app or window level depending on the platform.
- pressKey(key: string, modifiers?: Modifier[]) -> ActionResult — press and release one complete keystroke. For example pressKey('Tab', ['shift']) or pressKey('+'). Key names are platform-defined strings. Pass key and modifiers separately; do not pack them into a chord string.
- sendKeyEvent(key: string, direction: 'down' | 'up') -> ActionResult — send one key-down or key-up event; key accepts a single key name, including a modifier.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them at their original recipient. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them through the same target. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
click, drag, and pressKey are convenience operations; sendKeyEvent, mouseMove, and toggleMouse are primitive operations. For complex action combinations, decompose convenience operations into sequences of primitive operations supported by the current platform.
@@ -86,7 +86,7 @@ Available at app or window level depending on the platform.
- pressKey(key: string, modifiers?: Modifier[]) -> ActionResult — press and release one complete keystroke. For example pressKey('Tab', ['shift']) or pressKey('+'). Key names are platform-defined strings. Pass key and modifiers separately; do not pack them into a chord string.
- sendKeyEvent(key: string, direction: 'down' | 'up') -> ActionResult — send one key-down or key-up event; key accepts a single key name, including a modifier.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them at their original recipient. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them through the same target. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
click, drag, and pressKey are convenience operations; sendKeyEvent, mouseMove, and toggleMouse are primitive operations. For complex action combinations, decompose convenience operations into sequences of primitive operations supported by the current platform.
@@ -92,8 +92,6 @@ Available at app or window level depending on the platform.
- pressKey(key: string, modifiers?: Modifier[]) -> ActionResult — press and release one complete keystroke. For example pressKey('Tab', ['shift']) or pressKey('+'). Key names are platform-defined strings. Pass key and modifiers separately; do not pack them into a chord string.
- sendKeyEvent(key: string, direction: 'down' | 'up') -> ActionResult — send one key-down or key-up event; key accepts a single key name, including a modifier. For example W down, D down, D up, W up. A repeated 'down' for an ordinary held key sends one repeat without adding another hold.
Explicit downs from sendKeyEvent and toggleMouse remain held across programs and turns until an explicit up releases them at their original recipient. After a successful run_code or cua_run_code, a system reminder lists any remaining keys and mouse buttons, their targets and input modes. No reminder is added when none remain. Program failure, a received cancellation, connection closure, and disposal release owned inputs together in reverse dispatch order. A client pause between completed MCP calls is not observable by the server, so held input can remain pressed. pressKey, typeText, click, and complete drag release their own inputs within the operation.
click, drag, and pressKey are convenience operations; sendKeyEvent, mouseMove, and toggleMouse are primitive operations. For complex action combinations, decompose convenience operations into sequences of primitive operations supported by the current platform.
Raw tools use { method, params }: include appHandle for app calls and windowId for window calls, and use snapshotId with elementId for element routes. getAccessibilityTree maps to getState; getWindow has no raw method; getWindows maps to listWindows; getScreenshot maps to screenshot; cua.getState maps to listApps; every other named operation uses the same method name.