dsh-codex-style-computer-use 1.2.0-rc.3

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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -0
  3. package/README.zh.md +132 -0
  4. package/cordis.patch.yml +17 -0
  5. package/lib/artifacts.js +35 -0
  6. package/lib/attention-native.js +93 -0
  7. package/lib/attention-worker.cs +194 -0
  8. package/lib/attention.js +140 -0
  9. package/lib/audit.js +30 -0
  10. package/lib/batch.js +52 -0
  11. package/lib/bin/attention-worker.exe +0 -0
  12. package/lib/bin/attention-worker.exe.json +7 -0
  13. package/lib/core/bin/dsh-computer-use-worker.exe +0 -0
  14. package/lib/core/bin/dsh-computer-use-worker.exe.json +7 -0
  15. package/lib/core/compile-worker.ps1 +58 -0
  16. package/lib/core/index.js +844 -0
  17. package/lib/core/native-runtime.js +97 -0
  18. package/lib/core/worker.cs +6375 -0
  19. package/lib/cycle.js +314 -0
  20. package/lib/exposure.js +91 -0
  21. package/lib/feedback.js +35 -0
  22. package/lib/image-output.js +92 -0
  23. package/lib/index.js +1715 -0
  24. package/lib/observations.js +78 -0
  25. package/lib/policy.js +109 -0
  26. package/lib/recovery.js +8 -0
  27. package/lib/skill-gate.js +68 -0
  28. package/lib/tools.js +717 -0
  29. package/mcp/package.json +12 -0
  30. package/mcp/src/index.js +335 -0
  31. package/package.json +88 -0
  32. package/scripts/build-native.mjs +7 -0
  33. package/scripts/smoke-native.mjs +38 -0
  34. package/scripts/verify-package.mjs +28 -0
  35. package/skills/computer-use/SKILL.md +74 -0
  36. package/skills/computer-use/references/lifecycle.md +180 -0
  37. package/skills/computer-use/references/maintenance.md +56 -0
  38. package/skills/computer-use/references/precision.md +297 -0
  39. package/skills/computer-use/references/progressive-control.md +30 -0
  40. package/skills/computer-use/references/shared-input.md +27 -0
@@ -0,0 +1,97 @@
1
+ // Native helpers ship prebuilt. Source checkouts can compile with Windows' own
2
+ // .NET Framework compiler; neither path needs PowerShell, an SDK, or a network.
3
+ import fs from 'node:fs'
4
+ import os from 'node:os'
5
+ import path from 'node:path'
6
+ import { createHash } from 'node:crypto'
7
+ import { execFileSync } from 'node:child_process'
8
+
9
+ const hash = bytes => createHash('sha256').update(bytes).digest('hex')
10
+ const fileHash = file => hash(fs.readFileSync(file))
11
+ const framework = env => path.join(env.SystemRoot || env.windir || 'C:\\Windows', 'Microsoft.NET', 'Framework64', 'v4.0.30319')
12
+
13
+ export function workerReferences (env = process.env) {
14
+ const gac = path.join(env.SystemRoot || env.windir || 'C:\\Windows', 'Microsoft.NET', 'assembly', 'GAC_MSIL')
15
+ return ['System.dll', 'System.Core.dll', 'System.Drawing.dll', 'System.Web.Extensions.dll', 'System.Windows.Forms.dll',
16
+ ...['UIAutomationClient', 'UIAutomationTypes', 'WindowsBase'].map(name => path.join(gac, name, 'v4.0_4.0.0.0__31bf3856ad364e35', `${name}.dll`))]
17
+ }
18
+
19
+ export function compileNativeBinary (source, output, references, { env = process.env } = {}) {
20
+ const compiler = path.join(framework(env), 'csc.exe')
21
+ if (!fs.existsSync(compiler)) {
22
+ throw new Error('Computer Use 缺少可用的预编译组件,且 Windows .NET Framework 4.x 编译器不存在。请在插件市场重新安装最新版;如果仍失败,请启用 Windows 的 .NET Framework 4.x。无需安装 PowerShell 7。 / No usable prebuilt helper or Windows .NET Framework 4.x compiler. Reinstall the plugin from the market, or enable .NET Framework 4.x. PowerShell 7 is not required.')
23
+ }
24
+ try {
25
+ execFileSync(compiler, ['/nologo', '/target:exe', '/platform:x64', '/optimize+', '/warn:1', `/out:${output}`,
26
+ ...references.map(ref => `/r:${ref}`), source], { encoding: 'utf8', windowsHide: true, timeout: 120_000, env })
27
+ } catch (error) {
28
+ throw new Error(`Computer Use 原生组件编译失败,请从市场重新安装完整发布包。 / Native helper compilation failed; reinstall the complete market package. ${error.message}\n${error.stdout || ''}\n${error.stderr || ''}`, { cause: error })
29
+ }
30
+ }
31
+
32
+ // Publish-time only. Deliberately not an install/prepare lifecycle hook.
33
+ export function buildNativeBundle ({ source, name, references }, options = {}) {
34
+ const bin = path.join(path.dirname(source), 'bin')
35
+ fs.mkdirSync(bin, { recursive: true })
36
+ const binary = path.join(bin, name)
37
+ compileNativeBinary(source, binary, references, options)
38
+ const manifest = { format: 1, platform: 'win32', architecture: 'x64', sourceSha256: fileHash(source), binarySha256: fileHash(binary) }
39
+ fs.writeFileSync(`${binary}.json`, JSON.stringify(manifest, null, 2) + '\n')
40
+ return { binary, ...manifest }
41
+ }
42
+
43
+ function verifiedBinary (binary, sourceSha256, expectedBinarySha256) {
44
+ try {
45
+ const manifest = JSON.parse(fs.readFileSync(`${binary}.json`, 'utf8'))
46
+ return manifest.format === 1 && manifest.platform === 'win32' && manifest.architecture === 'x64' &&
47
+ manifest.sourceSha256 === sourceSha256 && /^[a-f0-9]{64}$/.test(manifest.binarySha256) &&
48
+ (!expectedBinarySha256 || manifest.binarySha256 === expectedBinarySha256) &&
49
+ fileHash(binary) === manifest.binarySha256 ? manifest : null
50
+ } catch { return null }
51
+ }
52
+
53
+ export function prepareNativeBinary ({ source, name, cache, references }, { env = process.env, log = () => {} } = {}) {
54
+ if (process.platform !== 'win32') throw new Error('Computer Use requires Windows. / Computer Use 仅支持 Windows。')
55
+ const sourceSha256 = fileHash(source)
56
+ const bundled = path.join(path.dirname(source), 'bin', name)
57
+ const manifest = verifiedBinary(bundled, sourceSha256)
58
+ // Include the binary/build identity so an update never replaces a running exe.
59
+ const identity = manifest?.binarySha256 || hash(JSON.stringify({ compiler: framework(env), references, recipe: 1 }))
60
+ const cacheRoot = path.join(env.LOCALAPPDATA || os.tmpdir(), 'dsh-computer-use', cache)
61
+ const dir = path.join(cacheRoot, `${sourceSha256.slice(0, 16).toUpperCase()}-${manifest ? 'prebuilt' : 'csc'}-${identity.slice(0, 16)}`)
62
+ const binary = path.join(dir, name)
63
+ if (verifiedBinary(binary, sourceSha256, manifest?.binarySha256)) return binary
64
+ fs.mkdirSync(cacheRoot, { recursive: true })
65
+ const temporary = fs.mkdtempSync(path.join(cacheRoot, '.building-'))
66
+ try {
67
+ const output = path.join(temporary, name)
68
+ if (manifest) {
69
+ fs.copyFileSync(bundled, output)
70
+ } else {
71
+ log('[computer-use] no matching prebuilt helper; compiling with Windows .NET Framework (no PowerShell required)')
72
+ compileNativeBinary(source, output, references, { env })
73
+ }
74
+ const built = { format: 1, platform: 'win32', architecture: 'x64', sourceSha256, binarySha256: fileHash(output) }
75
+ if (manifest && built.binarySha256 !== manifest.binarySha256) throw new Error('Computer Use native helper changed during installation; reinstall the package.')
76
+ fs.writeFileSync(`${output}.json`, JSON.stringify(built) + '\n')
77
+ // Publish the binary and its identity together. Concurrent first use accepts
78
+ // only another complete build of the same source; it never executes a partial copy.
79
+ try { fs.renameSync(temporary, dir) }
80
+ catch (error) {
81
+ if (!verifiedBinary(binary, sourceSha256, manifest?.binarySha256)) {
82
+ // Preserve a damaged/locked cache for diagnosis and use a fresh verified
83
+ // directory. No running helper or installed package is overwritten.
84
+ if (!fs.existsSync(dir)) throw error
85
+ const repaired = `${dir}-repaired-${path.basename(temporary)}`
86
+ fs.renameSync(temporary, repaired)
87
+ return path.join(repaired, name)
88
+ }
89
+ }
90
+ log(`[computer-use] ${manifest ? 'prebuilt' : 'compiled'} helper ready: ${binary}`)
91
+ return binary
92
+ } finally {
93
+ // Only this call's freshly allocated scratch directory can be removed.
94
+ if (path.dirname(temporary) !== cacheRoot) throw new Error('invalid native build scratch path')
95
+ fs.rmSync(temporary, { recursive: true, force: true })
96
+ }
97
+ }