@copylee/dsh-computer-use 0.9.0 → 0.11.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.
@@ -11,6 +11,11 @@ export interface WindowLike {
11
11
  }
12
12
  /** The DSH desktop host: the agent must never type into its own chat. */
13
13
  export declare const HOST_EXES: string[];
14
+ /**
15
+ * True when an open_application target refers to a command interpreter or
16
+ * script host (with or without path/extension/arguments).
17
+ */
18
+ export declare function isCommandInterpreter(target: string): boolean;
14
19
  export declare function normalizeApp(name: string): string;
15
20
  /** Do two app names refer to the same program ("explorer" and "文件资源管理器")? */
16
21
  export declare function sameApp(a: string, b: string): boolean;
@@ -31,6 +36,8 @@ export declare class AccessControl {
31
36
  isGranted(session: string, win: WindowLike): boolean;
32
37
  /** Names from `names` the session has not been granted yet (aliases count). */
33
38
  missing(session: string, names: readonly string[]): string[];
39
+ /** Remove matching app grants (or all grants when `name` is "all" / "*"). Returns revoked entries. */
40
+ revoke(session: string, name: string): string[];
34
41
  forget(session: string): void;
35
42
  /**
36
43
  * Why input may not go to `win`, or undefined when it may. `action` is a
@@ -0,0 +1,55 @@
1
+ export interface CdpTarget {
2
+ id: string;
3
+ type: string;
4
+ title: string;
5
+ url: string;
6
+ webSocketDebuggerUrl?: string;
7
+ }
8
+ export interface CdpDomElement {
9
+ role: string;
10
+ name: string;
11
+ selector: string;
12
+ x: number;
13
+ y: number;
14
+ width: number;
15
+ height: number;
16
+ value?: string;
17
+ editable?: boolean;
18
+ password?: boolean;
19
+ }
20
+ export interface CdpSnapshot {
21
+ port: number;
22
+ title: string;
23
+ url: string;
24
+ elements: CdpDomElement[];
25
+ }
26
+ /** Probe candidate localhost debugging ports and return the first matching visible page target. */
27
+ export declare function findCdpTarget(options?: {
28
+ ports?: readonly number[];
29
+ titleHint?: string;
30
+ harnessUrl?: string;
31
+ timeoutMs?: number;
32
+ }): Promise<{
33
+ port: number;
34
+ target: CdpTarget;
35
+ } | 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>;
38
+ /** Read visible interactive DOM controls from a local CDP-enabled browser tab. */
39
+ export declare function readCdpElements(options?: {
40
+ ports?: readonly number[];
41
+ titleHint?: string;
42
+ harnessUrl?: string;
43
+ }): Promise<CdpSnapshot | undefined>;
44
+ /** Read visible innerText from a local CDP-enabled browser tab (excluding password inputs). */
45
+ export declare function readCdpText(options?: {
46
+ ports?: readonly number[];
47
+ titleHint?: string;
48
+ harnessUrl?: string;
49
+ tail?: number;
50
+ }): Promise<{
51
+ port: number;
52
+ title: string;
53
+ url: string;
54
+ text: string;
55
+ } | undefined>;
@@ -15,6 +15,10 @@ interface NamespaceView {
15
15
  }
16
16
  interface ClientContext {
17
17
  effect(execute: () => (() => void) | void, label?: string): void;
18
+ inject?(deps: string[], callback: (scope: {
19
+ effect(fn: () => (() => void) | void, label?: string): void;
20
+ inputTriggers?: unknown;
21
+ }) => void): void;
18
22
  slots: {
19
23
  inject(name: string, register: () => unknown): void;
20
24
  register(meta: Record<string, unknown>, render: (props: unknown) => unknown): unknown;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Composer `@` reference source for running Windows application windows.
3
+ * Uses DSH's optional `inputTriggers` service (`ctx.inject(['inputTriggers'])`)
4
+ * and queries the passive read-only `/api/dsh-computer-use/windows` endpoint
5
+ * without ever lighting up the overlay or focusing any window.
6
+ */
7
+ interface InputTriggersLike {
8
+ registerSource?(source: {
9
+ trigger: string;
10
+ name: string;
11
+ showGroupTitle?: boolean;
12
+ lexicon?: () => unknown[];
13
+ subscribeLexicon?: (session: unknown, listener: () => void) => () => void;
14
+ candidates: (session: unknown, request?: {
15
+ query?: string;
16
+ quoted?: boolean;
17
+ drilled?: boolean;
18
+ signal?: AbortSignal;
19
+ }) => Promise<unknown[]>;
20
+ onPick: (pick: {
21
+ candidate?: {
22
+ value?: unknown;
23
+ label?: string;
24
+ description?: string;
25
+ };
26
+ }) => unknown;
27
+ codec?: {
28
+ clipboardText?: (ref: string) => string;
29
+ serialize?: (ref: string, signal?: AbortSignal) => Promise<string>;
30
+ };
31
+ }): () => void;
32
+ }
33
+ export declare function registerWindowReferenceSource(scope: {
34
+ effect(fn: () => (() => void) | void, label?: string): void;
35
+ inputTriggers?: InputTriggersLike;
36
+ }): void;
37
+ export {};
@@ -5,11 +5,14 @@ import type { HelperLike } from './helper-client.js';
5
5
  import { type UiElement } from './target.js';
6
6
  import type { CancellableAgent, HostWindowMode, OverlayController } from './overlay.js';
7
7
  export type AutoScreenshotDetail = 'standard' | 'compact';
8
+ export type SessionMode = 'off' | 'on' | 'always';
8
9
  export interface Settings {
9
10
  /** Web GUI origin, inferred from the local web server unless configured. */
10
11
  harnessUrl?: string | undefined;
11
12
  accessMode: AccessMode;
12
- /** Whether new sessions start with computer-use tools enabled (default false; toggle per session in composer). */
13
+ /** Per-session activation mode: off (per-session pill, default off), on (default on with pill), always (always on, hide composer pill). */
14
+ sessionMode: SessionMode;
15
+ /** Derived convenience flag (`sessionMode !== 'off'`); kept for backwards compatibility. */
13
16
  defaultSessionEnabled: boolean;
14
17
  blockedApps: string[];
15
18
  overlay: boolean;
@@ -34,6 +37,16 @@ export interface Settings {
34
37
  quickSteps: boolean;
35
38
  /** Run screenshots, display / window queries and idle input in-process through DSH's koffi instead of the C# helper. */
36
39
  nativeHelper: boolean;
40
+ /** Try background UIA semantic click at coordinate before falling back to a physical pointer click. */
41
+ elementFirstClick: boolean;
42
+ /** Restore the user's physical mouse position right after a physical click. */
43
+ restorePointer: boolean;
44
+ /** Refuse automated typing into password fields (UIA IsPassword / Win32 ES_PASSWORD) and mask values. */
45
+ protectPasswords: boolean;
46
+ /** Guard coordinate clicks/drags when the foreground window moved/resized or is occluded since the last screenshot. */
47
+ windowChangeGuard: boolean;
48
+ /** Optional local Chromium remote debugging port for CDP fast-lane (0 = auto-probe 9222/9229 on demand). */
49
+ cdpPort: number;
37
50
  }
38
51
  export type TypingMode = 'stream' | 'type' | 'paste';
39
52
  export interface WindowInfo extends WindowLike {
@@ -86,6 +99,8 @@ export interface ActionInput {
86
99
  force?: boolean;
87
100
  /** Screenshot detail: 'high' uses full configured limits; 'low' uses a compact budget for quick checks. */
88
101
  detail?: ScreenshotDetail;
102
+ /** type: select all (Ctrl+A) before entering replacement text. */
103
+ replace?: boolean;
89
104
  }
90
105
  export interface ActionOutcome {
91
106
  text: string;
@@ -101,6 +116,25 @@ export interface ClickResult {
101
116
  count?: number;
102
117
  repeat?: number;
103
118
  }
119
+ export interface OcrBox {
120
+ text: string;
121
+ x: number;
122
+ y: number;
123
+ width: number;
124
+ height: number;
125
+ }
126
+ export interface OcrLine extends OcrBox {
127
+ words: OcrBox[];
128
+ }
129
+ export interface OcrResult extends Partial<WindowInfo> {
130
+ language: string;
131
+ text: string;
132
+ x: number;
133
+ y: number;
134
+ width: number;
135
+ height: number;
136
+ lines: OcrLine[];
137
+ }
104
138
  /** Text returned instead of an identical screenshot. */
105
139
  export declare const UNCHANGED_TEXT = "The screen looks exactly as in your previous screenshot: the action had no visible effect.";
106
140
  /** Longest adaptive wait for the screen to settle after an action. */
@@ -151,6 +185,10 @@ export declare class Computer {
151
185
  freshShot(detail?: ScreenshotDetail): Promise<Shot | 'unchanged'>;
152
186
  /** The foreground window as of the model's latest look at the screen. */
153
187
  private seen;
188
+ /** Snapshot of the foreground window geometry captured during the latest screenshot/marks look. */
189
+ private lastShotWindow;
190
+ /** Most recent Set-of-Marks element list so `target: "#12"` resolves directly. */
191
+ private lastMarks;
154
192
  /** The latest foreground window that was not DeepSeek Harness itself. */
155
193
  private lastTarget;
156
194
  /** A new turn starts: the user may have rearranged things while chatting. */
@@ -210,7 +248,19 @@ export declare class Computer {
210
248
  * more on a file dialog, and the control is nearly always in the window.
211
249
  */
212
250
  elements(where?: 'window' | 'popups', hwnd?: number): Promise<UiElement[]>;
213
- /** Look for a named control in the window, and only if it is not there in its popups. */
251
+ /** Read visible text and physical bounding boxes via built-in Windows OCR. */
252
+ ocr(hwnd?: number): Promise<OcrResult>;
253
+ /** Capture a Set-of-Marks annotated screenshot and cache indexed elements so `target: "#N"` works directly. */
254
+ marks(hwnd?: number, max?: number): Promise<{
255
+ window: Partial<WindowInfo>;
256
+ elements: UiElement[];
257
+ shot: Shot;
258
+ }>;
259
+ /**
260
+ * Look for a named control in the window, then its popups, and when the UIA
261
+ * tree is empty or sparse (<= 20 controls, e.g. canvas/WebView/game/custom
262
+ * UIs), fall back to built-in Windows OCR so `target` still finds visible text.
263
+ */
214
264
  private find;
215
265
  /**
216
266
  * Where a named control is. It may still be appearing (the menu just
@@ -0,0 +1,76 @@
1
+ import { describeScreenshotSize, type Display } from './coords.js';
2
+ import type { Settings } from './computer.js';
3
+ export interface DiagnosticCall {
4
+ at: string;
5
+ tool: string;
6
+ action?: string;
7
+ durationMs: number;
8
+ ok: boolean;
9
+ error?: string;
10
+ }
11
+ export interface DiagnosticSnapshot {
12
+ generatedAt: string;
13
+ pluginVersion: string;
14
+ nodeVersion: string;
15
+ os: string;
16
+ helper: {
17
+ status: 'ready' | 'error';
18
+ nativeAvailable: boolean;
19
+ error?: string;
20
+ };
21
+ displays: Array<{
22
+ index: number;
23
+ primary: boolean;
24
+ width: number;
25
+ height: number;
26
+ dpi: number;
27
+ shot: ReturnType<typeof describeScreenshotSize>;
28
+ compactShot: ReturnType<typeof describeScreenshotSize>;
29
+ }>;
30
+ settings: {
31
+ accessMode: Settings['accessMode'];
32
+ sessionMode: Settings['sessionMode'];
33
+ defaultSessionEnabled: boolean;
34
+ overlay: boolean;
35
+ hostWindow: Settings['hostWindow'];
36
+ cardOpacity: number;
37
+ typingMode: Settings['typingMode'];
38
+ quickSteps: boolean;
39
+ autoScreenshot: boolean;
40
+ autoScreenshotDetail: Settings['autoScreenshotDetail'];
41
+ settleMs: number;
42
+ maxLongEdge: number;
43
+ maxPixels: number;
44
+ jpegQuality: number;
45
+ pauseOnUserInput: boolean;
46
+ userIdleMs: number;
47
+ nativeHelper: boolean;
48
+ elementFirstClick: boolean;
49
+ restorePointer: boolean;
50
+ protectPasswords: boolean;
51
+ windowChangeGuard: boolean;
52
+ cdpPort: number;
53
+ blockedAppsCount: number;
54
+ hasCustomHarnessUrl: boolean;
55
+ };
56
+ recentCalls: readonly DiagnosticCall[];
57
+ }
58
+ export declare class DiagnosticsLog {
59
+ private readonly calls;
60
+ record(entry: Omit<DiagnosticCall, 'at'> & {
61
+ at?: string;
62
+ }): void;
63
+ recent(): readonly DiagnosticCall[];
64
+ }
65
+ /** Extract a safe short action summary from tool arguments without leaking typed/clipboard text. */
66
+ export declare function summarizeToolAction(tool: string, rawArgs: unknown): string | undefined;
67
+ export declare function buildDiagnosticSnapshot(options: {
68
+ pluginVersion: string;
69
+ settings: Settings;
70
+ displays: readonly Display[];
71
+ helperStatus: 'ready' | 'error';
72
+ helperError?: string;
73
+ nativeAvailable: boolean;
74
+ recentCalls: readonly DiagnosticCall[];
75
+ }): DiagnosticSnapshot;
76
+ export declare function formatDiagnosticText(snap: DiagnosticSnapshot): string;
@@ -1,14 +1,20 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
2
  import z from '@deepseek-ai/schemastery';
3
3
  import { type AccessMode } from './access.js';
4
- import { type AutoScreenshotDetail, type TypingMode } from './computer.js';
4
+ import { type AutoScreenshotDetail, type SessionMode, type TypingMode } from './computer.js';
5
5
  import { type HostWindowMode } from './overlay.js';
6
+ /** Parse `/cu [on|off|toggle|status|reset|stop|revoke <app>]` arguments into an action. */
7
+ export declare function parseCuCommand(rawInput: string): 'on' | 'off' | 'toggle' | 'status' | 'reset' | 'stop' | 'revoke' | 'invalid';
8
+ /** Extract the app name argument after `/cu revoke ...` (empty means all granted apps). */
9
+ export declare function parseCuRevokeTarget(rawInput: string): string;
6
10
  export { DEFAULTS, ENTRY_ID, resolveConfig } from './settings.js';
7
11
  export declare const name = "@copylee/dsh-computer-use";
8
12
  export declare const inject: string[];
9
13
  export interface Config {
10
14
  harnessUrl?: string;
11
15
  accessMode?: AccessMode;
16
+ sessionMode?: SessionMode;
17
+ /** @deprecated replaced by sessionMode: 'on' */
12
18
  defaultSessionEnabled?: boolean;
13
19
  overlay?: boolean;
14
20
  overlayLabel?: string;
@@ -28,6 +34,11 @@ export interface Config {
28
34
  typingMode?: TypingMode;
29
35
  quickSteps?: boolean;
30
36
  nativeHelper?: boolean;
37
+ elementFirstClick?: boolean;
38
+ restorePointer?: boolean;
39
+ protectPasswords?: boolean;
40
+ windowChangeGuard?: boolean;
41
+ cdpPort?: number;
31
42
  }
32
43
  export declare const Config: z<Config>;
33
44
  export declare function apply(ctx: Context, config?: Config): void;
@@ -0,0 +1,30 @@
1
+ import type { ActionInput } from './computer.js';
2
+ export declare const MAX_MACRO_ACTIONS = 30;
3
+ export interface ActionMacro {
4
+ id: string;
5
+ name: string;
6
+ app?: string;
7
+ description: string;
8
+ params: string[];
9
+ actions: ActionInput[];
10
+ updatedAt: number;
11
+ }
12
+ export interface MacroInput {
13
+ name: string;
14
+ app?: string;
15
+ description?: string;
16
+ actions: ActionInput[];
17
+ }
18
+ export declare function macroId(name: string): string;
19
+ /** Collect `{{param}}` placeholder names referenced across macro actions. */
20
+ export declare function extractMacroParams(actions: readonly ActionInput[]): string[];
21
+ /** Substitute `{{param}}` placeholders into a fresh copy of `actions`. */
22
+ export declare function renderMacroActions(actions: readonly ActionInput[], params?: Record<string, string | number | boolean>): ActionInput[];
23
+ export declare class MacroStore {
24
+ readonly dir: string;
25
+ constructor(dir?: string);
26
+ list(): ActionMacro[];
27
+ get(nameOrId: string): ActionMacro | undefined;
28
+ save(input: MacroInput): ActionMacro;
29
+ remove(nameOrId: string): boolean;
30
+ }
@@ -5,6 +5,7 @@
5
5
  import type { IncomingMessage, ServerResponse } from 'node:http';
6
6
  import { type Display, type ScreenshotSizeInfo } from './coords.js';
7
7
  import type { Settings } from './computer.js';
8
+ import { type DiagnosticsLog } from './diagnostics.js';
8
9
  import type { HelperLike } from './helper-client.js';
9
10
  import type { OverlayController } from './overlay.js';
10
11
  import type { ScreenshotCache } from './screenshots.js';
@@ -16,9 +17,13 @@ export declare const SCREENSHOTS_ROUTE = "/api/dsh-computer-use/screenshots";
16
17
  export declare const SCREENSHOTS_CLEAN_ROUTE = "/api/dsh-computer-use/screenshots/clean";
17
18
  export declare const SKILLS_ROUTE = "/api/dsh-computer-use/skills";
18
19
  export declare const SESSION_ROUTE = "/api/dsh-computer-use/session";
20
+ export declare const DIAGNOSTICS_ROUTE = "/api/dsh-computer-use/diagnostics";
21
+ export declare const UPDATE_ROUTE = "/api/dsh-computer-use/update";
22
+ export declare const WINDOWS_ROUTE = "/api/dsh-computer-use/windows";
19
23
  type Handler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
20
24
  export interface StatusBody {
21
25
  ok: true;
26
+ version: string;
22
27
  platform: string;
23
28
  helper: 'ready' | 'error';
24
29
  error?: string;
@@ -28,7 +33,7 @@ export interface StatusBody {
28
33
  }>;
29
34
  controlling: boolean;
30
35
  }
31
- export declare function statusRoute(helper: HelperLike, settings: () => Settings, overlay: OverlayController): Handler;
36
+ export declare function statusRoute(helper: HelperLike, settings: () => Settings, overlay: OverlayController, pluginVersion?: string): Handler;
32
37
  /** Show the overlay for a few seconds so the user can see how it looks (skipped while an agent is controlling). */
33
38
  export declare function previewRoute(helper: HelperLike, settings: () => Settings, overlay: OverlayController, iconPath: string): Handler;
34
39
  /** Screenshot cache size and how much of it is orphaned. */
@@ -39,4 +44,12 @@ export declare function screenshotsCleanRoute(cache: ScreenshotCache): Handler;
39
44
  export declare function skillsRoute(skills: SkillStore): Handler;
40
45
  /** Per-session computer-use toggle: GET ?sessionId=... reads resolved state; POST { sessionId, enabled } updates and syncs live agents. */
41
46
  export declare function sessionRoute(gate: SessionGate, settings: () => Settings, parentIdsFor: (sessionId: string) => readonly string[], sync: () => void): Handler;
47
+ /** Export a sanitized diagnostic report (plain text by default, or JSON with ?format=json). */
48
+ export declare function diagnosticsRoute(helper: HelperLike & {
49
+ available?: boolean;
50
+ }, settings: () => Settings, diagnostics: DiagnosticsLog, pluginVersion: string): Handler;
51
+ /** Check npmjs & npmmirror concurrently for a newer plugin version. */
52
+ export declare function updateRoute(pluginVersion: string): Handler;
53
+ /** Passive read-only window list for `@窗口` composer references (never triggers overlay or focus). */
54
+ export declare function windowsRoute(helper: HelperLike): Handler;
42
55
  export {};
@@ -1,5 +1,6 @@
1
1
  export interface SessionResolveOptions {
2
2
  defaultEnabled?: boolean;
3
+ alwaysOn?: boolean;
3
4
  parentIds?: readonly string[];
4
5
  }
5
6
  export interface SessionToggleStatus {
@@ -8,6 +9,7 @@ export interface SessionToggleStatus {
8
9
  explicit: boolean;
9
10
  inherited: boolean;
10
11
  defaultEnabled: boolean;
12
+ alwaysOn: boolean;
11
13
  }
12
14
  export interface AgentLineageLike {
13
15
  readonly id?: string;
@@ -17,6 +17,10 @@ export interface UiElement {
17
17
  focusable?: boolean;
18
18
  /** True for web contenteditable composers (ProseMirror/tiptap/CodeMirror...). */
19
19
  editable?: boolean;
20
+ /** True when the control is a password field (UIA IsPassword or Win32 ES_PASSWORD). */
21
+ password?: boolean;
22
+ /** 1-based Set-of-Marks badge number when returned by `ui_elements({ marks: true })`. */
23
+ mark?: number;
20
24
  /** Internal UIA identity used to verify a live named target before dispatch. */
21
25
  runtimeId?: string;
22
26
  windowHwnd?: number;
@@ -1,5 +1,6 @@
1
1
  import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
2
2
  import { defineTool } from '@deepseek-ai/dsh-tools';
3
+ import { type MacroStore } from './macros.js';
3
4
  import { type SkillStore } from './skills.js';
4
5
  import { Computer, type CallContext, type Shot } from './computer.js';
5
6
  type ToolDefinition = ReturnType<typeof defineTool>;
@@ -11,6 +12,8 @@ export interface ToolHost {
11
12
  context(exec: unknown): Promise<CallContext>;
12
13
  /** Per-app notes the agent keeps (optional: tests run without). */
13
14
  skills?: SkillStore;
15
+ /** Saved replayable action macros (optional: tests run without). */
16
+ macros?: MacroStore;
14
17
  }
15
18
  export declare function createTools(host: ToolHost): ToolDefinition[];
16
19
  export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Concurrent plugin update check probing both npmjs and npmmirror so users in
3
+ * mainland China and overseas both get fast, reliable latest-version feedback.
4
+ */
5
+ export interface UpdateCheckResult {
6
+ current: string;
7
+ latest?: string;
8
+ hasUpdate: boolean;
9
+ source?: 'npmjs' | 'npmmirror';
10
+ error?: string;
11
+ }
12
+ /** Compare two semver strings (major.minor.patch); returns >0 when `a > b`. */
13
+ export declare function compareSemver(a: string, b: string): number;
14
+ /** Race npmjs & npmmirror concurrently and return the highest valid version found. */
15
+ export declare function checkForUpdate(current: string, fetchImpl?: typeof fetch, timeoutMs?: number): Promise<UpdateCheckResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "icon": "assets/icon.svg",
6
6
  "type": "module",