dsh-codex-style-computer-use 2.3.4 → 3.1.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.
- package/README.md +60 -5
- package/README.zh.md +50 -5
- package/client.js +1556 -32
- package/lib/browser/APACHE-2.0.txt +202 -0
- package/lib/browser/MIT-dsh-doyourweb.txt +21 -0
- package/lib/browser/NOTICE.md +53 -0
- package/lib/browser/README.md +139 -0
- package/lib/browser/access.js +540 -0
- package/lib/browser/approval.js +82 -0
- package/lib/browser/bridge.js +1048 -0
- package/lib/browser/engine.js +669 -0
- package/lib/browser/extension/background.js +474 -0
- package/lib/browser/extension/config.js +6 -0
- package/lib/browser/extension/manifest.json +25 -0
- package/lib/browser/extension/popup.css +89 -0
- package/lib/browser/extension/popup.html +35 -0
- package/lib/browser/extension/popup.js +99 -0
- package/lib/browser/host-protocol.js +132 -0
- package/lib/browser/host.js +1089 -0
- package/lib/browser/model.js +111 -0
- package/lib/browser/pairing.js +126 -0
- package/lib/browser/policy.js +131 -0
- package/lib/browser/protocol.js +171 -0
- package/lib/browser/schema.js +82 -0
- package/lib/browser/setup-page.js +145 -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 +58 -1
- package/lib/core/worker.cs +32 -1
- package/lib/host-debug.js +3 -2
- package/lib/index.js +286 -4
- package/lib/references-apps.js +586 -0
- package/lib/references-files.js +77 -0
- package/lib/references.js +233 -0
- package/package.json +7 -2
- package/scripts/check-behavior.mjs +60 -0
- package/scripts/verify-browser-integration.mjs +807 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// lib/browser/setup-page.js — the one page a human opens to pair a browser.
|
|
2
|
+
//
|
|
3
|
+
// Scope, stated because upstream's equivalent did more: this page pairs a
|
|
4
|
+
// browser and shows the extension folder. No annotation toolbar, no app or
|
|
5
|
+
// connector management, no network capture — those were separate upstream
|
|
6
|
+
// features and are not part of this plugin.
|
|
7
|
+
//
|
|
8
|
+
// Served per response with a fresh CSP nonce. `default-src 'none'` means the page
|
|
9
|
+
// cannot fetch, frame or embed anything but its own `/auth/session` and
|
|
10
|
+
// `/setup/pair` posts; the only script is the invitation exchange plus the copy
|
|
11
|
+
// buttons, both inline under the nonce.
|
|
12
|
+
|
|
13
|
+
import { approvalScript } from './approval.js'
|
|
14
|
+
|
|
15
|
+
function escapeHtml (value) {
|
|
16
|
+
return String(value).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function setupCsp (nonce) {
|
|
20
|
+
return `default-src 'none'; connect-src 'self'; style-src 'unsafe-inline'; script-src 'nonce-${nonce}'; ` +
|
|
21
|
+
"base-uri 'none'; frame-ancestors 'none'; form-action 'self'"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function setupPage ({ state, nonce }) {
|
|
25
|
+
const copy = (label, value) => `<button type="button" class="copy" data-copy="${escapeHtml(value)}">${escapeHtml(label)}</button>`
|
|
26
|
+
const connected = state.connected
|
|
27
|
+
const pending = state.pending
|
|
28
|
+
|
|
29
|
+
// A code the human can compare is exactly six digits. Anything else is shown
|
|
30
|
+
// as inert text rather than as a row whose "allow" would mean "approve
|
|
31
|
+
// whatever is pending".
|
|
32
|
+
const requests = pending.map(entry => `<li><strong>验证码 ${escapeHtml(/^\d{6}$/.test(entry.code) ? entry.code : '——————')}</strong>
|
|
33
|
+
<form method="post" action="/setup/pair"><input type="hidden" name="key" value="">
|
|
34
|
+
<input type="hidden" name="id" value="${escapeHtml(entry.id)}">
|
|
35
|
+
<button name="action" value="allow" disabled>允许</button>
|
|
36
|
+
<button name="action" value="deny" disabled>拒绝</button></form></li>`).join('')
|
|
37
|
+
|
|
38
|
+
const install = `<div class="step"><span class="number">1</span><div>
|
|
39
|
+
<h2>加载浏览器扩展</h2>
|
|
40
|
+
<p>扩展管理页不能被网页直接打开。请按下面的顺序操作,两个复制按钮共用剪贴板,先复制地址、后复制目录,中间别在别处复制别的路径。</p>
|
|
41
|
+
<ol class="steps">
|
|
42
|
+
<li><strong>先复制管理页地址。</strong>Chrome 用 <code>chrome://extensions</code>,Edge 用 <code>edge://extensions</code>。
|
|
43
|
+
<div class="actions">${copy('复制 Chrome 管理页地址', 'chrome://extensions')}${copy('复制 Edge 管理页地址', 'edge://extensions')}</div></li>
|
|
44
|
+
<li>粘到地址栏,在<strong>新标签页</strong>打开扩展管理页。原标签页先留着,后面要用。</li>
|
|
45
|
+
<li><strong>再回到本页复制扩展目录</strong>——它会覆盖剪贴板里刚才的地址,所以务必先完成上一步。
|
|
46
|
+
<div class="path"><code>${escapeHtml(state.extensionPath)}</code>${copy('复制扩展目录路径', state.extensionPath)}</div>
|
|
47
|
+
<p class="hint">选择器里只会列出子目录,不显示目录中的文件。这个目录里即使有 manifest.json,打开时也可能看起来是空的——这是正常的,直接选中整个文件夹即可,不必进入其中。</p></li>
|
|
48
|
+
<li>回到扩展管理页,开启开发者模式(Edge 称为开发人员模式)。</li>
|
|
49
|
+
<li>点「加载未打包的扩展程序」;Edge 里同一项写作「加载解压缩的扩展」。</li>
|
|
50
|
+
<li>在选择窗口底部的文件夹栏里粘贴刚复制的目录路径,点「选择文件夹」。</li>
|
|
51
|
+
<li>如果只是进入了这个目录、并没有装上,再点一次「选择文件夹」。</li>
|
|
52
|
+
</ol>
|
|
53
|
+
<p class="hint">装好后扩展列表里会出现「DSH Computer Use Browser」,确认它处于启用状态,再继续下一步。已安装可直接进行下一步。</p>
|
|
54
|
+
</div></div>`
|
|
55
|
+
|
|
56
|
+
const pairing = `<section class="card step"><span class="number">2</span><div>
|
|
57
|
+
<h2>核对验证码,确认连接</h2>
|
|
58
|
+
<p>扩展弹窗会显示一个 6 位验证码;点开扩展图标即可看到。与下面某一行一致时点击「允许」。每个验证码只属于一个请求。</p>
|
|
59
|
+
${requests ? `<ul class="requests">${requests}</ul>`
|
|
60
|
+
: '<div class="waiting"><span class="dot"></span>正在等待扩展发来请求…</div><p class="hint">加载扩展后会自动出现,无需手动输入验证码。</p>'}
|
|
61
|
+
</div></section>`
|
|
62
|
+
|
|
63
|
+
const success = `<section class="success"><h2>连接已就绪</h2>
|
|
64
|
+
<p>桥接端口 ${state.port}</p>
|
|
65
|
+
<p>回到 DSH 用 <kbd>@</kbd> 选择要操作的标签页。只有在对话里被引用的页面才会被操作,登录状态一直留在你的浏览器里。</p>
|
|
66
|
+
<p class="hint">要再连一个浏览器,重复上面两步即可;多个浏览器配置可以同时在线。</p></section>`
|
|
67
|
+
|
|
68
|
+
const help = `<details class="help"><summary>连接帮助与本地 HTML</summary>
|
|
69
|
+
<p>如果扩展显示 OFF,打开扩展弹窗确认「连接 DSH」是打开的,并在「连接设置」里把端口设为 <code>${state.port}</code>。</p>
|
|
70
|
+
<p>本地 HTML:在扩展详情里开启「允许访问文件网址」,之后已打开的 .html 标签页就会出现在列表里。${state.allowFile ? '' : '当前插件设置未允许本地文件页面,开启后才会列出。'}</p>
|
|
71
|
+
<p>扩展只连接本机 ${state.port},不读取也不导出 Cookie;没有给模型的自由 CDP / 脚本执行接口,也没有常驻调试端口。</p>
|
|
72
|
+
<p>浏览器内部页面(chrome://、edge://、扩展页)和扩展商店既不会列出,也不会被操作。</p>
|
|
73
|
+
</details>`
|
|
74
|
+
|
|
75
|
+
const body = `<main><header>
|
|
76
|
+
<div class="mark" aria-hidden="true"><svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3a16 16 0 0 1 0 18 16 16 0 0 1 0-18"/></svg></div>
|
|
77
|
+
<div><h1>连接你的浏览器</h1><p class="product">DSH 电脑操控 · 浏览器连接(本机)</p></div>
|
|
78
|
+
<span role="status" class="badge ${connected ? 'online' : ''}">${connected ? '已连接' : pending.length ? '待确认' : '等待连接'}</span>
|
|
79
|
+
</header>
|
|
80
|
+
<p class="intro">让对话接着你已有的标签页工作:保留登录态,用 <kbd>@</kbd> 选择页面。扩展只连接本机 ${state.port},与你已装的其他浏览器插件互不干扰。</p>
|
|
81
|
+
${connected ? success : ''}
|
|
82
|
+
${connected ? `<details><summary>再连接一个浏览器</summary>${install}</details>`
|
|
83
|
+
: `<section class="card">${pending.length ? `<details><summary>扩展已发来请求 · 查看安装步骤</summary>${install}</details>` : install}</section>`}
|
|
84
|
+
${!connected || requests ? pairing : ''}
|
|
85
|
+
${help}
|
|
86
|
+
<p id="approval-status" role="status">批准连接前,请从 DSH 的浏览器设置打开本页。</p>
|
|
87
|
+
<footer><span>DSH 电脑操控 · 本机连接</span><a href="/setup">刷新状态</a></footer></main>`
|
|
88
|
+
|
|
89
|
+
const script = `
|
|
90
|
+
${approvalScript('setup', 'Open this page from the DSH browser settings to confirm the connection.')}
|
|
91
|
+
approvalReady.then(key => {
|
|
92
|
+
for (const form of document.querySelectorAll('form')) {
|
|
93
|
+
form.elements.key.value = key;
|
|
94
|
+
for (const button of form.querySelectorAll('button')) button.disabled = false;
|
|
95
|
+
}
|
|
96
|
+
document.querySelector('#approval-status').textContent = 'DSH 已打开本次确认窗口,请核对扩展弹窗里的验证码';
|
|
97
|
+
}).catch(error => { document.querySelector('#approval-status').textContent = error.message; });
|
|
98
|
+
for (const button of document.querySelectorAll('.copy')) button.addEventListener('click', async () => {
|
|
99
|
+
const value = button.dataset.copy;
|
|
100
|
+
try { await navigator.clipboard.writeText(value); } catch {
|
|
101
|
+
const field = document.createElement('textarea');
|
|
102
|
+
field.value = value;
|
|
103
|
+
document.body.append(field);
|
|
104
|
+
field.select();
|
|
105
|
+
document.execCommand('copy');
|
|
106
|
+
field.remove();
|
|
107
|
+
}
|
|
108
|
+
const label = button.textContent;
|
|
109
|
+
button.textContent = '已复制';
|
|
110
|
+
setTimeout(() => { button.textContent = label; }, 1500);
|
|
111
|
+
});`
|
|
112
|
+
|
|
113
|
+
// Poll only while nothing is pending: a meta refresh would fight the approve
|
|
114
|
+
// buttons the moment the invitation script enables them.
|
|
115
|
+
const refresh = pending.length || connected ? '' : '<meta http-equiv="refresh" content="3">'
|
|
116
|
+
|
|
117
|
+
return `<!doctype html><html lang="zh-CN"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">${refresh}
|
|
118
|
+
<title>DSH 电脑操控 · 浏览器连接</title><style>
|
|
119
|
+
:root{color-scheme:light dark;--ink:#242424;--muted:#666;--ground:#fafafa;--surface:#fff;--soft:#f3f3f3;--line:#e2e2e2;--control:#ccc;--focus:#0066cc;--positive:#287447}
|
|
120
|
+
*{box-sizing:border-box}body{margin:0;padding:44px 22px;font:14px/1.7 "Segoe UI","Microsoft YaHei UI","Microsoft YaHei","Noto Sans CJK SC",sans-serif;color:var(--ink);background:var(--ground)}
|
|
121
|
+
main{max-width:760px;margin:auto}header{display:flex;align-items:center;gap:14px}.mark{display:grid;place-items:center;flex:none;color:var(--ink)}
|
|
122
|
+
.product{color:var(--muted);font-size:12px;margin:4px 0 0}h1{font-size:25px;line-height:1.3;letter-spacing:-.5px;margin:0;font-weight:600}
|
|
123
|
+
h2{font-size:16px;margin:0 0 6px;font-weight:600}p{margin:6px 0 12px}.intro{margin:22px 0;color:var(--muted);max-width:65ch}
|
|
124
|
+
.badge{margin-left:auto;white-space:nowrap;border:1px solid var(--line);padding:3px 10px;border-radius:20px;font-size:12px;color:var(--muted)}.online{color:var(--positive)}
|
|
125
|
+
.card,.success{padding:22px;margin:16px 0;background:var(--surface);border:1px solid var(--line);border-radius:12px}.success h2{color:var(--positive)}
|
|
126
|
+
.step{display:flex;gap:16px}.step>div{min-width:0;flex:1}.number{flex-shrink:0;width:26px;height:26px;background:var(--soft);color:var(--muted);border-radius:6px;text-align:center;font-weight:500;font-variant-numeric:tabular-nums}
|
|
127
|
+
.actions{display:flex;flex-wrap:wrap;gap:8px;margin:14px 0}.path{display:flex;align-items:center;gap:12px;padding:12px;background:var(--soft);border-radius:6px}
|
|
128
|
+
.path code{flex:1;min-width:0;overflow-wrap:anywhere;font:12px/1.6 ui-monospace,monospace}
|
|
129
|
+
button{border:1px solid var(--control);background:var(--surface);color:var(--ink);padding:8px 12px;min-height:36px;border-radius:6px;font:inherit;font-size:12px;cursor:pointer;white-space:nowrap}
|
|
130
|
+
button:hover:not(:disabled){background:var(--soft)}button:disabled{opacity:.5;cursor:default}
|
|
131
|
+
button:focus-visible,a:focus-visible,summary:focus-visible{outline:2px solid var(--focus);outline-offset:3px}
|
|
132
|
+
.hint{color:var(--muted);font-size:12px;margin-top:10px}ul{padding:0;list-style:none;margin:12px 0}
|
|
133
|
+
.steps{padding-left:20px;margin:12px 0}.steps li{margin:6px 0}
|
|
134
|
+
.steps .actions{margin:8px 0 2px}.steps .path{margin:8px 0 2px}.steps .hint{margin-top:6px}
|
|
135
|
+
.requests li{display:flex;flex-wrap:wrap;align-items:center;gap:10px;padding:12px;border:1px solid var(--line);border-radius:8px;margin-bottom:8px}
|
|
136
|
+
.requests form{display:flex;gap:8px;margin-left:auto}.waiting{display:flex;align-items:center;gap:8px;color:var(--muted);padding:14px 0}
|
|
137
|
+
.dot{width:8px;height:8px;border-radius:50%;background:var(--muted);animation:pulse 1.4s ease-in-out infinite}
|
|
138
|
+
@keyframes pulse{50%{opacity:.25}}@media(prefers-reduced-motion:reduce){.dot{animation:none}}
|
|
139
|
+
.help{margin:18px 0;color:var(--muted)}.help code{font-size:12px;overflow-wrap:anywhere}.help p{font-size:12px}
|
|
140
|
+
kbd{font:12px/1 ui-monospace,monospace;border:1px solid var(--line);border-radius:4px;padding:2px 5px;background:var(--soft)}
|
|
141
|
+
footer{display:flex;justify-content:space-between;gap:12px;margin-top:26px;padding-top:14px;border-top:1px solid var(--line);font-size:12px;color:var(--muted)}
|
|
142
|
+
a{color:var(--ink);text-underline-offset:3px}#approval-status{font-size:12px;color:var(--muted)}
|
|
143
|
+
@media(prefers-color-scheme:dark){:root{--ink:#eee;--muted:#b5b5b5;--ground:#1b1b1b;--surface:#232323;--soft:#2c2c2c;--line:#3a3a3a;--control:#6d6d6d;--focus:#82b5ff;--positive:#5fbf8a}}
|
|
144
|
+
</style><body>${body}<script nonce="${nonce}">${script}</script></body></html>`
|
|
145
|
+
}
|
|
Binary file
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"format": 1,
|
|
3
3
|
"platform": "win32",
|
|
4
4
|
"architecture": "x64",
|
|
5
|
-
"sourceSha256": "
|
|
6
|
-
"binarySha256": "
|
|
5
|
+
"sourceSha256": "837b42e54f24491ee824f91ec6a08062194519a499268f3789e825cb8499d70a",
|
|
6
|
+
"binarySha256": "30e5ad952ef75d8e68f36dab2af3aab3705c25cf6bb8020180e3bfaff4dd3433"
|
|
7
7
|
}
|
package/lib/core/index.js
CHANGED
|
@@ -36,6 +36,14 @@ const URGENT_CONTROL = new Set(['cancelInput', 'abort', 'panic', 'exit', 'endAsk
|
|
|
36
36
|
const INPUT_OPS = new Set(['click', 'shiftClick', 'move', 'drag', 'scroll', 'selectRange',
|
|
37
37
|
'type', 'key', 'uiaAct', 'windowOp', 'activate', 'clipWrite', 'calibrate', 'selftest'])
|
|
38
38
|
const isInputOp = (op, args = {}) => INPUT_OPS.has(op) || (op === 'focus' && args.refocus === true)
|
|
39
|
+
// Ops that READ the machine and never touch it. A caller outside the tool surface (the `@` menu's
|
|
40
|
+
// running-application inventory) may ask one of these at any time, including while no cycle exists,
|
|
41
|
+
// and must not light the cycle, arm the human monitors or take a desktop lease by doing so.
|
|
42
|
+
//
|
|
43
|
+
// This is an ALLOWLIST ON PURPOSE: anything that could dispatch input, focus, activate, launch or
|
|
44
|
+
// change a window is absent, so a future op cannot silently inherit "passive" by being forgotten
|
|
45
|
+
// here — it simply stays unavailable to `callPassive`.
|
|
46
|
+
const PASSIVE_OPS = new Set(['windows', 'screens', 'cursor', 'ping', 'probe'])
|
|
39
47
|
// THE CORE'S ASK DEADLINE, AND IT IS A BARE LITERAL ON PURPOSE (merge-design.md §3, §3.2).
|
|
40
48
|
//
|
|
41
49
|
// It bounds ONE thing: a wedged worker inside `beginAsk`'s raise sequence (a hung UIA provider), or
|
|
@@ -361,6 +369,32 @@ export class ComputerUse extends EventEmitter {
|
|
|
361
369
|
return this.inputContext.run({ internalCleanup: true }, () => this.call(op, args, timeoutMs, killOnTimeout, beforeDispatch))
|
|
362
370
|
}
|
|
363
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Read the machine WITHOUT starting, lighting or arming anything.
|
|
374
|
+
*
|
|
375
|
+
* THE DEFECT THIS EXISTS FOR (measured on the real 3.0.0 build): typing `@` in the composer
|
|
376
|
+
* listed running applications, the inventory called `cu.call('windows')`, and `call()` signs
|
|
377
|
+
* EVERY request with `__cycle: true`. The worker treats a signed cycle op as "an agent cycle is
|
|
378
|
+
* live" and lights the cyan breathing border plus the human monitors — off a pure read, before
|
|
379
|
+
* the human had chosen anything, with no driving call behind it and no ordinary way to stop it.
|
|
380
|
+
*
|
|
381
|
+
* A passive read is stamped `__cycle: false`, so the worker's own cycle gate stays shut: nothing
|
|
382
|
+
* is lit, nothing is armed, and the desktop lease is untouched. It is deliberately restricted to
|
|
383
|
+
* `PASSIVE_OPS`, and it never sends `__inputSeries` — it cannot drive the machine even if a
|
|
384
|
+
* caller passes driving-looking arguments.
|
|
385
|
+
*
|
|
386
|
+
* It does NOT clear a brake, resume a cycle or bypass `Panic.CheckOp`: a stopped session still
|
|
387
|
+
* refuses, and an exited one still reports its record. Only the lighting is suppressed.
|
|
388
|
+
*/
|
|
389
|
+
callPassive (op, args = {}, timeoutMs = DEFAULT_TIMEOUT_MS, killOnTimeout = false) {
|
|
390
|
+
if (!PASSIVE_OPS.has(op)) throw new Error(`unsupported passive read operation: ${String(op)}`)
|
|
391
|
+
if (isInputOp(op, args)) throw new Error(`unsupported passive read operation: ${String(op)}`)
|
|
392
|
+
// `passive` is its own flag, NOT `internalCleanup`: cleanup is an authority for releasing input,
|
|
393
|
+
// and a future change to it must not silently widen what a read may do. It has exactly two
|
|
394
|
+
// readers in `call()`: the `__cycle` signature and the host-written `__passiveRead` mark.
|
|
395
|
+
return this.inputContext.run({ passive: true }, () => this.call(op, args, timeoutMs, killOnTimeout))
|
|
396
|
+
}
|
|
397
|
+
|
|
364
398
|
async cancelRequest (requestId, child, reason, killOnFailure = true) {
|
|
365
399
|
const cleanup = { requestId, workerGeneration: this.workerGeneration, requested: true,
|
|
366
400
|
cleanupConfirmed: false, cleanupState: 'unconfirmed', workerKilled: false }
|
|
@@ -420,7 +454,30 @@ export class ComputerUse extends EventEmitter {
|
|
|
420
454
|
requestId: id, workerGeneration: generation, runtime: this.runtime,
|
|
421
455
|
})
|
|
422
456
|
// __cycle is signed last. A caller cannot forge another input series or turn.
|
|
423
|
-
|
|
457
|
+
//
|
|
458
|
+
// `__cycle:false` means "this call does not light or arm the cycle", and there are exactly two
|
|
459
|
+
// authorities for it: internal cleanup (which runs under its own explicit authority) and a
|
|
460
|
+
// passive read (`callPassive`). Neither can dispatch input, so neither can open a cycle.
|
|
461
|
+
//
|
|
462
|
+
// `__passiveRead` is a SEPARATE, narrower mark and it is NOT a licence to skip checks. It exists
|
|
463
|
+
// because `__cycle:false` alone still took the desktop lease: measured in 3.1.0, the `@` candidate
|
|
464
|
+
// list called `windows` through `callPassive`, the worker's `Handle()` ran
|
|
465
|
+
// `EnsureDesktopOwnership(op)` unconditionally and wrote `owner=native cycle: windows`, holding the
|
|
466
|
+
// handle — so another conversation could be refused the machine by a read that never touched it.
|
|
467
|
+
// The worker honours this mark ONLY for a strict allowlist of side-effect-free ops with no
|
|
468
|
+
// arguments of consequence (see `EnsureDesktopOwnership`); every real control, screenshot,
|
|
469
|
+
// inspection and input op keeps its ownership check exactly as before.
|
|
470
|
+
const passive = context?.internalCleanup === true || context?.passive === true
|
|
471
|
+
const signed = { ...args, __cycle: !passive, __kickoff: this.kickoffRequired }
|
|
472
|
+
// THE MARK IS WRITTEN BY THE HOST, NOT MERELY DEFAULTED.
|
|
473
|
+
//
|
|
474
|
+
// `{ ...args }` above copies whatever the caller sent, so a plain `call('windows', {
|
|
475
|
+
// __passiveRead: true })` would otherwise arrive at the worker carrying a forged exemption. Both
|
|
476
|
+
// branches are therefore explicit: a passive read sets `true`, EVERY other call DELETES the key.
|
|
477
|
+
// Stamping only the true case (the previous shape) left a caller-supplied value in place for
|
|
478
|
+
// ordinary calls, which is exactly the contract this marker must not have.
|
|
479
|
+
if (context?.passive === true) signed.__passiveRead = true
|
|
480
|
+
else delete signed.__passiveRead
|
|
424
481
|
if (input) signed.__inputSeries = context?.inputSeries || randomUUID()
|
|
425
482
|
// The two host-driving gates travel with EVERY call so the worker can decide per request:
|
|
426
483
|
// gate 1 = the calling conversation is full permission, gate 2 = debug mode was switched on by
|
package/lib/core/worker.cs
CHANGED
|
@@ -3592,6 +3592,35 @@ namespace DshComputerUse.Worker
|
|
|
3592
3592
|
error.Data["outcome"] = "not-dispatched"; throw error;
|
|
3593
3593
|
}
|
|
3594
3594
|
}
|
|
3595
|
+
/// <summary>
|
|
3596
|
+
/// Is this request a PURE READ that must not take, replace or release the desktop lease?
|
|
3597
|
+
///
|
|
3598
|
+
/// MEASURED IN 3.1.0: the `@` candidate list builds its inventory with
|
|
3599
|
+
/// `createAppInventory({cu}).list('', {refresh:true})`, which reaches `windows`. That read ran
|
|
3600
|
+
/// `EnsureDesktopOwnership("windows")`, so a query that only ENUMERATES windows acquired the
|
|
3601
|
+
/// lease, wrote `owner=native cycle: windows` to the owner file and held the handle — another
|
|
3602
|
+
/// conversation could then be refused the desktop by a call that never touched it.
|
|
3603
|
+
///
|
|
3604
|
+
/// THREE CONDITIONS, ALL REQUIRED, and none of them can be produced by a caller:
|
|
3605
|
+
/// * `__passiveRead` — written by the HOST (lib/core/index.js), which also DELETES it on
|
|
3606
|
+
/// every ordinary call, so a tool argument of the same name cannot survive;
|
|
3607
|
+
/// * `__cycle` STRICTLY false — a passive read never lights or arms the cycle, and a request
|
|
3608
|
+
/// that asks for a cycle op is by definition not this one;
|
|
3609
|
+
/// * the exact pure-enumeration shape of `windows` — its other modes (`feedbackHwnd`,
|
|
3610
|
+
/// `inspectHwnd`, `appQuery`) take a target and keep the ordinary check.
|
|
3611
|
+
///
|
|
3612
|
+
/// Anything else keeps the full ownership gate. This is an allowlist: a new op is never exempt
|
|
3613
|
+
/// by being forgotten here.
|
|
3614
|
+
/// </summary>
|
|
3615
|
+
static bool IsPassiveDesktopRead(string op, Dictionary<string, object> a)
|
|
3616
|
+
{
|
|
3617
|
+
if (a == null || !GetB(a, "__passiveRead", false)) return false;
|
|
3618
|
+
if (GetB(a, "__cycle", true)) return false;
|
|
3619
|
+
// `windows` is the ONLY op with a pure enumerating mode.
|
|
3620
|
+
if (op != "windows") return false;
|
|
3621
|
+
// Arguments are inspected, not trusted: the target-carrying forms are different modes.
|
|
3622
|
+
return !a.ContainsKey("feedbackHwnd") && !a.ContainsKey("inspectHwnd") && !a.ContainsKey("appQuery");
|
|
3623
|
+
}
|
|
3595
3624
|
public static void ReleaseDesktopOwnership()
|
|
3596
3625
|
{
|
|
3597
3626
|
lock (InputLock)
|
|
@@ -4205,7 +4234,9 @@ namespace DshComputerUse.Worker
|
|
|
4205
4234
|
// No other input may use the flag to skip the controls and then dispatch.
|
|
4206
4235
|
if (dryInput && (op != "click" || !args.ContainsKey("x") || !args.ContainsKey("y")))
|
|
4207
4236
|
return Err("UNSUPPORTED_DRY_RUN: native input simulation requires a click with x and y; no input was dispatched.");
|
|
4208
|
-
|
|
4237
|
+
// A pure window enumeration neither takes, replaces nor releases the desktop lease: it is
|
|
4238
|
+
// the `@` candidate list, which must stay silent on a machine someone else is driving.
|
|
4239
|
+
if (!IsPassiveDesktopRead(op, args)) EnsureDesktopOwnership(op);
|
|
4209
4240
|
int requestId = GetI(request, "id", 0);
|
|
4210
4241
|
bool ignored;
|
|
4211
4242
|
_activeRequestId = requestId;
|
package/lib/host-debug.js
CHANGED
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
// writes. Tools can read both; they cannot write either.
|
|
15
15
|
//
|
|
16
16
|
// SETTINGS PAGE CONTRACT (host side):
|
|
17
|
-
// GET /api/computer-use/host-debug
|
|
18
|
-
// POST /api/computer-use/host-debug
|
|
17
|
+
// GET /api/computer-use/host-debug?session=<id> returns { enabled, since, session, lastBlockedAt, ready }.
|
|
18
|
+
// POST /api/computer-use/host-debug?session=<id> accepts { enabled: boolean } and returns the same status.
|
|
19
|
+
// The query identifies the displayed conversation. A missing or unknown id reports fullAccess: false.
|
|
19
20
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
20
21
|
import path from 'node:path'
|
|
21
22
|
|