Files
deepseek-harness/examples/desktop/scripts/qa-cdp-drive-9234.mjs
ZiyaZhang e8f5c0b51b feat(desktop): DSH Electron desktop shell — harness internals visualized
Minimal Electron shell over the DSH JSON-RPC runtime — a first-look at
what a ChatGPT.app-style host on top of the DeepSeek Harness looks
like, with the harness's normally-invisible internals (trace timeline,
context surface, subagent tree, compaction, plugin registry, rubrics)
brought forward as first-class UI surfaces so plugin authors and
researchers can see what the agent is actually doing.

Runs against three keyless-to-live profiles (stdio-echo works on
master out of the box; daemon-echo / daemon-vibe-echo activate once
the daemon-demo lands; stdio-deepseek and daemon-vibe hit the real
DeepSeek API when you supply a key). HARNESS_DEV auto-resolves to the
in-repo runtime when this shell ships under examples/desktop/, so a
fresh clone launches without config; env DSH_DEV_ROOT overrides for
custom layouts, and a sibling deepseek-harness-dev/ checkout is the
original dev workflow.

Cold-clone gate (P0 fixes for first-time-clone usability):
- HARNESS_DEV: 3-candidate resolver (env → walk-up in-repo marker →
  sibling), unit-tested via mock fs so ordering is locked without
  needing either real layout on disk.
- config yml leaves rewritten at assemble time so the sibling-clone
  paths (../../deepseek-harness-dev/examples/echo-agent/…) become
  the in-repo paths (../../echo-agent/…) in the released tree —
  source yml stays usable for local dev, released tree ships a
  working shape.
- pnpm-workspace.yaml allowBuilds.electron = true (was placeholder).
- missing-key card in stdio-deepseek offers a one-click switch to
  stdio-echo (the keyless profile that works on master) rather than
  daemon-echo (blocked on the not-yet-shipped daemon-demo).
- assemble-oss-release.sh rewrites the source-side breadcrumb name
  'dsh-desktop-demo' → 'dsh-desktop' for the released package.json.

FOUC guard on the onboarding gate (41fc5df carried) keeps the
first-launch splash from flashing before the runtime probe finishes.

Test suite (1634 tests in source, 3990 in the runtime repo) covers
resolver ordering, renderer classifiers, trace timeline shape,
compaction diff rendering, rubric parity, and the missing-key
onboarding paths.
2026-07-18 12:59:34 -07:00

94 lines
3.3 KiB
JavaScript

#!/usr/bin/env node
// CDP driver for the bench lane — port 9234. Same shape as
// scripts/qa-cdp-drive-9223.mjs but pinned to a different port so multiple
// lanes' Electron instances can coexist.
//
// Usage:
// node scripts/qa-cdp-drive-9234.mjs js '<expression>'
// node scripts/qa-cdp-drive-9234.mjs switchTab bench
// node scripts/qa-cdp-drive-9234.mjs shot <path>
import http from 'node:http'
import fs from 'node:fs'
const PORT = 9234
function listTargets() {
return new Promise((resolve, reject) => {
http.get(`http://localhost:${PORT}/json/list`, (res) => {
let b = ''; res.on('data', c => b += c); res.on('end', () => { try { resolve(JSON.parse(b)) } catch (e) { reject(e) } })
}).on('error', reject)
})
}
async function pickPage() {
const t = await listTargets()
const p = t.find(x => x.title === 'DSH Desktop') || t.find(x => x.type === 'page')
if (!p) throw new Error('no DSH page')
return p.webSocketDebuggerUrl
}
async function connect() {
const url = await pickPage()
const ws = new WebSocket(url)
await new Promise((r, j) => { ws.onopen = () => r(); ws.onerror = (e) => j(e.message) })
let seq = 0
const pending = new Map()
ws.onmessage = (ev) => {
let msg; try { msg = JSON.parse(ev.data) } catch { return }
if (msg.id != null && pending.has(msg.id)) {
const { resolve, reject } = pending.get(msg.id); pending.delete(msg.id)
if (msg.error) reject(new Error(JSON.stringify(msg.error)))
else resolve(msg.result)
}
}
function send(method, params) {
const id = ++seq
return new Promise((resolve, reject) => {
pending.set(id, { resolve, reject })
ws.send(JSON.stringify({ id, method, params: params || {} }))
})
}
return { send, ws }
}
async function evalExpr(client, expr) {
const r = await client.send('Runtime.evaluate', {
expression: expr, awaitPromise: true, returnByValue: true,
})
if (r.exceptionDetails) throw new Error('eval failed: ' + JSON.stringify(r.exceptionDetails))
return r.result && r.result.value
}
async function main() {
const [, , cmd, ...rest] = process.argv
const client = await connect()
try {
if (cmd === 'js') {
const val = await evalExpr(client, rest.join(' '))
console.log(JSON.stringify(val, null, 2))
} else if (cmd === 'switchTab') {
await evalExpr(client, `window.__dshTabs.switchTo(${JSON.stringify(rest[0])}); true`)
console.log('OK')
} else if (cmd === 'shot') {
const outPath = rest[0]
await client.send('Page.enable')
// Bring window forward before capture (macOS Electron sometimes hides on
// background). window.reveal seam.
try { await evalExpr(client, 'window.dsh && window.dsh.qa && window.dsh.qa.reveal && window.dsh.qa.reveal()') } catch {}
const r = await client.send('Page.captureScreenshot', { format: 'png', captureBeyondViewport: false })
fs.writeFileSync(outPath, Buffer.from(r.data, 'base64'))
console.log('wrote', outPath, fs.statSync(outPath).size, 'bytes')
} else if (cmd === 'wait') {
await new Promise(r => setTimeout(r, Number(rest[0] || 500)))
console.log('ok')
} else {
console.log('usage: js <expr> | switchTab <name> | shot <path> | wait <ms>')
}
} finally {
client.ws.close()
}
}
main().catch(e => { console.error(e); process.exit(1) })