Record policy rejection before native input release confirmation

This commit is contained in:
creatixchu committed 2026-11-20 18:35:29 +08:00
1 parent 5b0b1f915d
commit 7715be3c89
4 files changed
+35 -23

No files matched your search

@@ -0,0 +1,16 @@
/** This policy scenario holds native confirmation until the model has received the final tool error. */
import { installFixture } from '../cua-run-code/provider.mjs'
import { createNativeFixture } from '../cua-run-code/native-channel.mjs'
export { Config, inject, name } from '../cua-run-code/provider.mjs'
/** @param {import('@deepseek-ai/cordis').Context} ctx @param {import('@deepseek-ai/dsh-cua').CuaConfig} config */
export function apply(ctx, config) {
const fixture = createNativeFixture()
const release = fixture.controlNext('releaseHeldInputs')
const remove = ctx.on('session/event', (_session, event) => {
if (event.type !== 'turn/end') return
remove()
release.reply()
})
installFixture(ctx, config, fixture)
}
@@ -3,9 +3,8 @@
- id: computer-use
name: '@deepseek-ai/dsh-computer-use'
- id: cua-run-code-fixture
name: '../cua-run-code/provider.mjs'
name: './provider.mjs'
config:
confirmReleaseAtTurnEnd: true
allowedApps:
- id: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
name: Fixture
@@ -12,7 +12,7 @@
{"type":"request/header","data":{"header":{"config":{"provider":"deepseek-official","model":"deepseek-v4-flash"},"tools":"{{tools}}"},"reason":"initial"}}
{"type":"request/context","data":{"provider":"deepseek-official","model":"deepseek-v4-flash"}}
{"type":"session/title","data":{"title":"Hold W in test.fixture using","messageSeqs":[8],"source":{"kind":"fallback"}}}
{"type":"assistant/message","data":{"turn":1,"step":1,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua_first","name":"run_code","arguments":"{\"code\":\"await tools.cua_run_code({\\\"code\\\": \\\"var app = await cua.getApp(\\\\\\\"test.fixture\\\\\\\"); await app.sendKeyEvent(\\\\\\\"w\\\\\\\", \\\\\\\"down\\\\\\\")\\\", \\\"description\\\": \\\"Hold W in the fixture\\\"})\",\"description\":\"Hold W\"}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:4}}"},"stream":[{"type":"chunk","time":1795095784699,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1795095784700,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua_first","name":"run_code","arguments":"{\"code\":\"await tools.cua_run_code({\\\"code\\\": \\\"var app = await cua.getApp(\\\\\\\"test.fixture\\\\\\\"); await app.sendKeyEvent(\\\\\\\"w\\\\\\\", \\\\\\\"down\\\\\\\")\\\", \\\"description\\\": \\\"Hold W in the fixture\\\"})\",\"description\":\"Hold W\"}"}}},{"type":"chunk","time":1795095784700,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"assistant/message","data":{"turn":1,"step":1,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua_first","name":"run_code","arguments":"{\"code\":\"await tools.cua_run_code({\\\"code\\\": \\\"var app = await cua.getApp(\\\\\\\"test.fixture\\\\\\\"); await app.sendKeyEvent(\\\\\\\"w\\\\\\\", \\\\\\\"down\\\\\\\")\\\", \\\"description\\\": \\\"Hold W in the fixture\\\"})\",\"description\":\"Hold W\"}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:4}}"},"stream":[{"type":"chunk","time":1795148927697,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1795148927697,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua_first","name":"run_code","arguments":"{\"code\":\"await tools.cua_run_code({\\\"code\\\": \\\"var app = await cua.getApp(\\\\\\\"test.fixture\\\\\\\"); await app.sendKeyEvent(\\\\\\\"w\\\\\\\", \\\\\\\"down\\\\\\\")\\\", \\\"description\\\": \\\"Hold W in the fixture\\\"})\",\"description\":\"Hold W\"}"}}},{"type":"chunk","time":1795148927697,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":1,"callId":"cua_first","name":"run_code","arguments":"{\"code\":\"await tools.cua_run_code({\\\"code\\\": \\\"var app = await cua.getApp(\\\\\\\"test.fixture\\\\\\\"); await app.sendKeyEvent(\\\\\\\"w\\\\\\\", \\\\\\\"down\\\\\\\")\\\", \\\"description\\\": \\\"Hold W in the fixture\\\"})\",\"description\":\"Hold W\"}"}}
{"type":"tool/ptc-dispatch-start","data":{"rootCallId":"cua_first","parentCallId":"cua_first","subCallId":"cua_first:ptc:1","name":"cua_run_code","arguments":{"code":"var app = await cua.getApp(\"test.fixture\"); await app.sendKeyEvent(\"w\", \"down\")","description":"Hold W in the fixture"}}}
{"type":"tool/ptc-dispatch-start","data":{"rootCallId":"cua_first","parentCallId":"cua_first:ptc:1","subCallId":"cua_first:ptc:1:ptc:1","name":"cua","arguments":{"method":"getCapabilities","params":{}}}}
@@ -24,12 +24,11 @@
{"type":"tool/ptc-dispatch","data":{"rootCallId":"cua_first","parentCallId":"cua_first","subCallId":"cua_first:ptc:1","name":"cua_run_code","arguments":{"code":"var app = await cua.getApp(\"test.fixture\"); await app.sendKeyEvent(\"w\", \"down\")","description":"Hold W in the fixture"},"isError":false,"content":[{"type":"text","text":"(cua_run_code completed with no output)"}]}}
{"type":"hook/invoked","data":{"turn":1,"point":"PostToolUse","dialect":"codex","handlerId":"codex:PostToolUse:1","matcher":"^run_code$"}}
{"type":"hook/result","data":{"turn":1,"point":"PostToolUse","handlerId":"codex:PostToolUse:1","decision":"block","exitCode":2,"stderrSummary":"tool output rejected by codex policy: summarize instead","durationMs":5.269749999999931}}
{"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"inserted":[{"content":[{"type":"text","text":"<system-reminder>\nCUA inputs were released during cleanup:\n- Key \"w\", appHandle \"fixture-app\" (application input).\nThese inputs are no longer held.\n</system-reminder>"}],"source":{"kind":"cua-inputs-released","form":"notice","summary":"CUA inputs released"},"role":"user","id":"{{message:5}}"}]}}
{"type":"tool/result","data":{"turn":1,"step":1,"message":{"role":"tool","source":{"kind":"tool","callId":"cua_first"},"toolCallId":"cua_first","content":[{"type":"text","text":"tool output rejected by codex policy: summarize instead"}],"isError":true,"id":"{{message:6}}"},"error":{"name":"HookError","code":"HOOK_BLOCKED"}},"sourceEventSeqs":[14],"surfaceOp":"append"}
{"type":"tool/result","data":{"turn":1,"step":1,"message":{"role":"tool","source":{"kind":"tool","callId":"cua_first"},"toolCallId":"cua_first","content":[{"type":"text","text":"tool output rejected by codex policy: summarize instead"}],"isError":true,"id":"{{message:5}}"},"error":{"name":"HookError","code":"HOOK_BLOCKED"}},"sourceEventSeqs":[14],"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":1}}
{"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"removedCount":1,"inserted":[]}}
{"type":"step/start","data":{"turn":1,"step":2}}
{"type":"user/message","data":{"content":[{"type":"text","text":"<system-reminder>\nCUA inputs were released during cleanup:\n- Key \"w\", appHandle \"fixture-app\" (application input).\nThese inputs are no longer held.\n</system-reminder>"}],"source":{"kind":"cua-inputs-released","form":"notice","summary":"CUA inputs released"},"role":"user","id":"{{message:5}}"},"surfaceOp":"append"}
{"type":"assistant/message","data":{"turn":1,"step":2,"message":{"role":"assistant","content":[{"type":"text","text":"The policy rejected the program output. I have not received confirmation that W was released."}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:7}}"},"stream":[{"type":"chunk","time":1795095785319,"chunk":{"type":"block-start","index":0,"blockType":"text"}},{"type":"chunk","time":1795095785319,"chunk":{"type":"block-end","index":0,"block":{"type":"text","text":"The policy rejected the program output. I have not received confirmation that W was released."}}},{"type":"chunk","time":1795095785319,"chunk":{"type":"finish","reason":{"kind":"stop"}}}]},"surfaceOp":"append"}
{"type":"assistant/message","data":{"turn":1,"step":2,"message":{"role":"assistant","content":[{"type":"text","text":"The policy rejected the program output. I have not received confirmation that W was released."}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash"},"id":"{{message:6}}"},"stream":[{"type":"chunk","time":1795148928147,"chunk":{"type":"block-start","index":0,"blockType":"text"}},{"type":"chunk","time":1795148928147,"chunk":{"type":"block-end","index":0,"block":{"type":"text","text":"The policy rejected the program output. I have not received confirmation that W was released."}}},{"type":"chunk","time":1795148928147,"chunk":{"type":"finish","reason":{"kind":"stop"}}}]},"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":2}}
{"type":"turn/end","data":{"turn":1,"reason":{"kind":"completed"}}}
{"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"inserted":[{"content":[{"type":"text","text":"<system-reminder>\nCUA inputs were released during cleanup:\n- Key \"w\", appHandle \"fixture-app\" (application input).\nThese inputs are no longer held.\n</system-reminder>"}],"source":{"kind":"cua-inputs-released","form":"notice","summary":"CUA inputs released"},"role":"user","id":"{{message:7}}"}]}}
{"type":"agent/inbox/spliced","data":{"target":"next-step","start":0,"removedCount":1,"inserted":[],"outcome":"canceled"}}
+13 -15
View File
@@ -1,25 +1,23 @@
/** Real CUA registration with an isolated fixture at the native byte-stream boundary. */
import Schema from '@deepseek-ai/schemastery'
import { installCua } from '@deepseek-ai/dsh-cua'
import { CuaConfigFields } from '@deepseek-ai/dsh-cua/config'
import { CuaConfig, installCua } from '@deepseek-ai/dsh-cua'
import { COMMON_GUIDANCE } from '@deepseek-ai/dsh-cua/guidance'
import { createNativeFixture } from './native-channel.mjs'
export const name = 'cua-run-code-fixture'
export const inject = ['computerUse', 'tools', 'systemPrompt', 'subprocess', 'agents']
export const Config = Schema.object({ ...CuaConfigFields, confirmReleaseAtTurnEnd: Schema.boolean().default(false) })
export const Config = CuaConfig
/** @param {import('@deepseek-ai/cordis').Context} ctx @param {import('@deepseek-ai/dsh-cua').CuaConfig & { confirmReleaseAtTurnEnd: boolean }} config */
export function apply(ctx, { confirmReleaseAtTurnEnd, ...config }) {
const fixture = createNativeFixture()
if (confirmReleaseAtTurnEnd) {
const release = fixture.controlNext('releaseHeldInputs')
const remove = ctx.on('session/event', (_session, event) => {
if (event.type !== 'turn/end') return
remove()
release.reply()
})
}
/** @param {import('@deepseek-ai/cordis').Context} ctx @param {import('@deepseek-ai/dsh-cua').CuaConfig} config */
export function apply(ctx, config) {
installFixture(ctx, config, createNativeFixture())
}
/**
* @param {import('@deepseek-ai/cordis').Context} ctx - Provider scope.
* @param {import('@deepseek-ai/dsh-cua').CuaConfig} config - CUA provider options.
* @param {ReturnType<typeof createNativeFixture>} fixture - Native request receiver for this scenario.
*/
export function installFixture(ctx, config, fixture) {
installCua(ctx, config, {
helperPath: process.execPath,
heldInputState: true,