@copylee/dsh-computer-use 0.12.0 → 0.13.1

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.
@@ -39,6 +39,13 @@ export declare class AccessControl {
39
39
  /** Remove matching app grants (or all grants when `name` is "all" / "*"). Returns revoked entries. */
40
40
  revoke(session: string, name: string): string[];
41
41
  forget(session: string): void;
42
+ /**
43
+ * Why reading/observing `win` is refused, or undefined when allowed.
44
+ * Always blocks DeepSeek Harness and blocked apps (password managers, user-blocked apps).
45
+ * When `requireGrant` is true (e.g. CDP DOM inspection or clipboard read), also enforces
46
+ * per-app session grants.
47
+ */
48
+ readDenial(session: string, win: WindowLike | undefined, mode: AccessMode, blocked: readonly string[], action: string, requireGrant?: boolean): string | undefined;
42
49
  /**
43
50
  * Why input may not go to `win`, or undefined when it may. `action` is a
44
51
  * short verb for the message ("click", "type into").
@@ -23,28 +23,39 @@ export interface CdpSnapshot {
23
23
  url: string;
24
24
  elements: CdpDomElement[];
25
25
  }
26
- /** Probe candidate localhost debugging ports and return the first matching visible page target. */
26
+ /** Strip common browser window title suffixes so Chrome/Edge window titles match CDP page titles cleanly. */
27
+ export declare function normalizeBrowserTitle(title: string): string;
28
+ /** Verify a CDP WebSocket URL points strictly to the loopback interface on the expected port. */
29
+ export declare function isLocalCdpWsUrl(wsUrl: string, expectedPort?: number): boolean;
30
+ /**
31
+ * Probe candidate localhost debugging ports and return the matching visible page target.
32
+ * Never falls back to an unrelated tab (`pages[0]`) when `titleHint` fails to match or multiple
33
+ * tabs are ambiguous — callers fall back to UIA / OCR instead of leaking another tab's DOM.
34
+ */
27
35
  export declare function findCdpTarget(options?: {
28
36
  ports?: readonly number[];
29
37
  titleHint?: string;
38
+ urlHint?: string;
30
39
  harnessUrl?: string;
31
40
  timeoutMs?: number;
32
41
  }): Promise<{
33
42
  port: number;
34
43
  target: CdpTarget;
35
44
  } | undefined>;
36
- /** Execute one CDP `Runtime.evaluate` returning JSON on a debugger WebSocket URL. */
37
- export declare function evalCdpJson<T>(wsUrl: string, expression: string, timeoutMs?: number): Promise<T | undefined>;
45
+ /** Execute one CDP `Runtime.evaluate` returning JSON on a validated local debugger WebSocket URL. */
46
+ export declare function evalCdpJson<T>(wsUrl: string, expression: string, timeoutMs?: number, expectedPort?: number): Promise<T | undefined>;
38
47
  /** Read visible interactive DOM controls from a local CDP-enabled browser tab. */
39
48
  export declare function readCdpElements(options?: {
40
49
  ports?: readonly number[];
41
50
  titleHint?: string;
51
+ urlHint?: string;
42
52
  harnessUrl?: string;
43
53
  }): Promise<CdpSnapshot | undefined>;
44
54
  /** Read visible innerText from a local CDP-enabled browser tab (excluding password inputs). */
45
55
  export declare function readCdpText(options?: {
46
56
  ports?: readonly number[];
47
57
  titleHint?: string;
58
+ urlHint?: string;
48
59
  harnessUrl?: string;
49
60
  tail?: number;
50
61
  }): Promise<{
@@ -1,7 +1,7 @@
1
1
  /**
2
- * "应用技能" card: the per-app notes the agent keeps (see ../skills.ts). The
3
- * user can read, edit, add and delete them here; built-in skills can be
4
- * overridden and restored.
2
+ * "应用技能" card: per-app notes the agent keeps (see ../skills.ts).
3
+ * Compact collapsible list with live search & source filter, plus a centered
4
+ * modal dialog for viewing, editing, and creating skills.
5
5
  */
6
6
  import * as React from 'react';
7
7
  export declare function SkillsCard({ S }: {
@@ -2,7 +2,9 @@ import { type AccessControl, type AccessMode, type WindowLike } from './access.j
2
2
  import { type BrowserTab } from './browser-host.js';
3
3
  import { type Display, type Point, type ScreenshotDetail, type Size } from './coords.js';
4
4
  import type { HelperLike } from './helper-client.js';
5
+ import { DesktopLease } from './lease.js';
5
6
  import { type UiElement } from './target.js';
7
+ import { UiDiffTracker } from './ui-diff.js';
6
8
  import type { CancellableAgent, HostWindowMode, OverlayController, PetCardSize } from './overlay.js';
7
9
  export type AutoScreenshotDetail = 'standard' | 'compact';
8
10
  export type SessionMode = 'off' | 'on' | 'always';
@@ -49,7 +51,9 @@ export interface Settings {
49
51
  protectPasswords: boolean;
50
52
  /** Guard coordinate clicks/drags when the foreground window moved/resized or is occluded since the last screenshot. */
51
53
  windowChangeGuard: boolean;
52
- /** Optional local Chromium remote debugging port for CDP fast-lane (0 = auto-probe 9222/9229 on demand). */
54
+ /** Explicitly enable the optional local Chromium CDP browser fast-lane (off by default unless enabled or cdpPort > 0). */
55
+ cdpEnabled: boolean;
56
+ /** Optional local Chromium remote debugging port for CDP fast-lane (0 = default port 9222 when cdpEnabled is true). */
53
57
  cdpPort: number;
54
58
  }
55
59
  export type TypingMode = 'stream' | 'type' | 'paste';
@@ -157,7 +161,11 @@ export declare class Computer {
157
161
  private readonly clickHistory;
158
162
  /** The agent that last wrote the clipboard; when it goes idle the user's clipboard comes back. */
159
163
  clipboardAgent: CancellableAgent | undefined;
160
- constructor(helper: HelperLike, access: AccessControl, overlay: OverlayController, settings: () => Settings);
164
+ /** Single-machine desktop control lease preventing concurrent sessions from colliding. */
165
+ readonly lease: DesktopLease;
166
+ /** Per-window UI Automation tree snapshot tracker for incremental `diff: true` queries. */
167
+ readonly uiDiff: UiDiffTracker;
168
+ constructor(helper: HelperLike, access: AccessControl, overlay: OverlayController, settings: () => Settings, lease?: DesktopLease);
161
169
  refreshDisplays(): Promise<Display[]>;
162
170
  display(): Promise<Display>;
163
171
  selectDisplay(index: number): Promise<Display>;
@@ -191,12 +199,14 @@ export declare class Computer {
191
199
  private seen;
192
200
  /** Snapshot of the foreground window geometry captured during the latest screenshot/marks look. */
193
201
  private lastShotWindow;
194
- /** Most recent Set-of-Marks element list so `target: "#12"` resolves directly. */
202
+ /** Most recent Set-of-Marks element list so `target: "#12"` resolves directly until the screen mutates. */
195
203
  private lastMarks;
196
204
  /** The latest foreground window that was not DeepSeek Harness itself. */
197
205
  private lastTarget;
198
206
  /** A new turn starts: the user may have rearranged things while chatting. */
199
207
  resetLook(): void;
208
+ /** Drop cached Set-of-Marks indices whenever the screen or foreground state mutates. */
209
+ invalidateMarks(): void;
200
210
  private remember;
201
211
  /**
202
212
  * Did another window come to the front since the model last looked, without
@@ -238,6 +248,8 @@ export declare class Computer {
238
248
  cursor(): Promise<Point>;
239
249
  /** Short description of the frontmost window, for result text. */
240
250
  describeForeground(): Promise<string>;
251
+ /** Enforce access control for read/observe surfaces (UIA, OCR, Set-of-Marks, CDP, clipboard). */
252
+ assertReadable(call: CallContext, win: WindowInfo | undefined, verb?: string, requireGrant?: boolean): void;
241
253
  assertAllowed(call: CallContext, win: WindowInfo | undefined, verb: string): Promise<BrowserTab | undefined>;
242
254
  private checkWebContent;
243
255
  private checkPointer;
@@ -51,6 +51,7 @@ export interface DiagnosticSnapshot {
51
51
  restorePointer: boolean;
52
52
  protectPasswords: boolean;
53
53
  windowChangeGuard: boolean;
54
+ cdpEnabled: boolean;
54
55
  cdpPort: number;
55
56
  blockedAppsCount: number;
56
57
  hasCustomHarnessUrl: boolean;
@@ -11,8 +11,10 @@ export interface HelperLike {
11
11
  /** A file in helper/ at the package root: one level up from lib/ or src/, two from lib/types/. */
12
12
  export declare function helperAssetPath(name: string): string;
13
13
  export declare function helperSourcePath(): string;
14
- /** Compile the helper if this source version has no cached exe yet; returns the exe path. */
15
- export declare function ensureHelperExe(source?: string): Promise<string>;
14
+ /** All modular C# 5 source files under `helper/` compiled together into `cu-helper.exe`. */
15
+ export declare function helperSourceFiles(): string[];
16
+ /** Compile the helper if this source set has no cached exe yet; returns the exe path. */
17
+ export declare function ensureHelperExe(sources?: string | readonly string[]): Promise<string>;
16
18
  /** For the smoke script: run the helper inside powershell.exe from the start. */
17
19
  export declare function useHostedHelper(on?: boolean): void;
18
20
  export declare class HelperClient implements HelperLike {
@@ -40,6 +40,7 @@ export interface Config {
40
40
  restorePointer?: boolean;
41
41
  protectPasswords?: boolean;
42
42
  windowChangeGuard?: boolean;
43
+ cdpEnabled?: boolean;
43
44
  cdpPort?: number;
44
45
  }
45
46
  export declare const Config: z<Config>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Single-machine desktop control lease: prevents concurrent sessions / subagents
3
+ * from fighting over the mouse, keyboard, or shared Computer state (`lastMarks`,
4
+ * `seen`, `lastShot`). A session acquires the lease while acting and releases it
5
+ * immediately when its turn ends (or after `idleExpiryMs` of inactivity).
6
+ */
7
+ export interface LeaseHolder {
8
+ session: string;
9
+ activeCalls: number;
10
+ acquiredAt: number;
11
+ lastActiveAt: number;
12
+ }
13
+ export declare class DesktopLease {
14
+ private readonly idleExpiryMs;
15
+ private readonly waitTimeoutMs;
16
+ private holder;
17
+ private readonly waiters;
18
+ private tail;
19
+ constructor(idleExpiryMs?: number, waitTimeoutMs?: number);
20
+ private expireIfIdle;
21
+ /** Current active lease holder (if not expired). */
22
+ current(): Readonly<LeaseHolder> | undefined;
23
+ /** Explicitly release the lease held by `session` (e.g. when a turn finishes). */
24
+ release(session: string): void;
25
+ /** Acquire the desktop lease for `session`, waiting briefly if another session is finishing up. */
26
+ acquire(session: string, signal?: AbortSignal): Promise<void>;
27
+ /** Run `fn` exclusively under `session`'s desktop lease, serializing overlapping calls. */
28
+ withLease<T>(session: string, signal: AbortSignal | undefined, fn: () => Promise<T>): Promise<T>;
29
+ private wakeNext;
30
+ }
@@ -90,9 +90,10 @@ export declare class OverlayController {
90
90
  private workTab;
91
91
  private starting;
92
92
  private stopping;
93
- /** Progress card lines: host-provided reasoning and recent operations. */
93
+ /** Progress card lines: host-provided reasoning, brief mid-turn reply, and recent operations. */
94
94
  private streamAgent;
95
95
  private thinking;
96
+ private reply;
96
97
  /** Recent steps (tool actions), oldest first. */
97
98
  private steps;
98
99
  private resume;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Incremental UI Automation tree diffing: caches the previous element snapshot
3
+ * per window HWND so repeated `ui_elements({ diff: true })` inspections send
4
+ * only added, changed, and removed controls — saving 70-90% tokens on long tasks.
5
+ */
6
+ import type { UiElement } from './target.js';
7
+ export interface UiElementChange {
8
+ element: UiElement;
9
+ changes: string[];
10
+ }
11
+ export interface UiDiffResult {
12
+ isBaseline: boolean;
13
+ titleChanged: boolean;
14
+ previousTitle?: string;
15
+ added: UiElement[];
16
+ changed: UiElementChange[];
17
+ removed: UiElement[];
18
+ unchangedCount: number;
19
+ }
20
+ export declare class UiDiffTracker {
21
+ private readonly snapshots;
22
+ /** Record a full snapshot as the latest baseline for `hwnd` without computing a diff. */
23
+ record(hwnd: number, title: string, elements: readonly UiElement[]): void;
24
+ /** Compute the incremental delta against the last snapshot of `hwnd`, updating the stored baseline. */
25
+ diff(hwnd: number, title: string, elements: readonly UiElement[]): UiDiffResult;
26
+ clear(hwnd?: number): void;
27
+ private store;
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.12.0",
3
+ "version": "0.13.1",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "icon": "assets/icon.svg",
6
6
  "type": "module",
@@ -34,7 +34,7 @@
34
34
  "lib/native-worker.js",
35
35
  "lib/client.js",
36
36
  "lib/types/**/*.d.ts",
37
- "helper/CuHelper.cs",
37
+ "helper/*.cs",
38
38
  "helper/host.ps1",
39
39
  "helper/deepseek-white.png",
40
40
  "helper/deepseek-black.png",
@@ -68,6 +68,7 @@
68
68
  "build": "tsc && tsdown",
69
69
  "prepare": "pnpm run build",
70
70
  "test": "vitest run",
71
+ "bench": "node scripts/benchmark.mjs",
71
72
  "pack:check": "pnpm pack --dry-run",
72
73
  "smoke": "node scripts/helper-smoke.mjs"
73
74
  },