@copylee/dsh-computer-use 0.14.2 → 0.16.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.
@@ -1,13 +1,11 @@
1
1
  /**
2
- * The accent colour shared by the copylee DSH plugins (docs/ui-spec.md).
2
+ * This plugin's own accent colour (settings page, composer pill).
3
3
  *
4
- * One choice — terracotta orange by default, blue or black — is kept in the
5
- * browser under a key every plugin reads, and painted as two CSS variables on
6
- * `<body>`, where the Host keeps its own theme variables. A plugin's styles
7
- * only ever write `var(--cl-accent)` / `var(--cl-accent-ink)`, so changing the
8
- * colour in any plugin's settings recolours all of them at once.
9
- *
10
- * This file is identical in every plugin; change it in all of them together.
4
+ * One choice — black by default, terracotta orange or blue — is kept in the
5
+ * browser under a key only this plugin reads, and painted as two CSS
6
+ * variables on `<body>` that only this plugin's styles use
7
+ * (`var(--dshcu-accent)` / `var(--dshcu-accent-ink)`). Changing it here does
8
+ * not recolour the other copylee plugins, and theirs does not recolour this one.
11
9
  */
12
10
  import * as React from 'react';
13
11
  export type Accent = 'orange' | 'blue' | 'black';
@@ -21,11 +19,12 @@ export declare const DEFAULT_ACCENT: Accent;
21
19
  /** Use these in styles; the fallbacks cover the moment before the first paint. */
22
20
  export declare const ACCENT: string;
23
21
  export declare const ACCENT_INK: string;
22
+ export declare const ACCENT_KEY = "copylee.dsh.computer-use.accent";
24
23
  export declare function isAccent(value: unknown): value is Accent;
25
24
  /** The choice made in this browser, or null while none has been made. */
26
25
  export declare function storedAccent(): Accent | null;
27
26
  export declare function readAccent(): Accent;
28
- /** Choose the accent for every plugin. */
27
+ /** Choose this plugin's accent. */
29
28
  export declare function writeAccent(accent: Accent): void;
30
29
  /** Paint the current accent and keep it current. Returns the undo for plugin disposal. */
31
30
  export declare function installAccent(): () => void;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  /** Menu appearance and fixed-position behavior follow dsh-free-search / dsh-proxy. */
3
- export declare const selectCss = "\n@keyframes dshcu-menu-in{from{opacity:0;transform:translateY(-4px) scale(.985)}to{opacity:1;transform:translateY(0) scale(1)}}\n.dshcu-select{box-sizing:border-box;width:100%;height:36px;padding:0 12px;display:flex;align-items:center;gap:8px;text-align:left;border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.28));border-radius:var(--dsw-radius-md,9px);background:var(--dsw-alias-bg-layer-3,transparent);color:inherit;font:inherit;font-size:13px;cursor:pointer;transition:border-color .16s ease,background-color .16s ease,box-shadow .16s ease}\n.dshcu-select:hover:not(:disabled){border-color:color-mix(in srgb,var(--cl-accent,#D97757) 55%,var(--dsw-alias-border-l3,#888));background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.05))}\n.dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:none;border-color:var(--cl-accent,#D97757);box-shadow:0 0 0 3px color-mix(in srgb,var(--cl-accent,#D97757) 20%,transparent)}\n.dshcu-select:disabled{opacity:.48;cursor:default}\n.dshcu-select svg{flex:none;transition:transform .2s cubic-bezier(.22,1,.36,1)}\n.dshcu-menu{position:fixed;z-index:1100;box-sizing:border-box;padding:5px;overflow-y:auto;overscroll-behavior:contain;border-radius:var(--dsw-radius-lg,12px);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.18));background:var(--dsw-menu-surface-fill,var(--dsw-alias-bg-layer-1,#fff));color:var(--dsw-alias-label-primary,#222);backdrop-filter:var(--dsw-menu-backdrop-filter,none);box-shadow:var(--dsw-elevation-prominent,0 12px 32px rgba(0,0,0,.16),0 2px 6px rgba(0,0,0,.06));animation:dshcu-menu-in .14s cubic-bezier(.22,1,.36,1)}\n.dshcu-option{display:flex;align-items:center;gap:8px;min-height:34px;padding:6px 10px;box-sizing:border-box;border-radius:var(--dsw-radius-md,8px);font-size:13px;line-height:20px;cursor:pointer;user-select:none;transition:background-color .12s ease,color .12s ease}\n.dshcu-option[data-active=true]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.11))}\n.dshcu-option[aria-selected=true]{font-weight:500;color:var(--cl-accent,#D97757)}\n";
3
+ export declare const selectCss = "\n@keyframes dshcu-menu-in{from{opacity:0;transform:translateY(-4px) scale(.985)}to{opacity:1;transform:translateY(0) scale(1)}}\n.dshcu-select{box-sizing:border-box;width:100%;height:36px;padding:0 12px;display:flex;align-items:center;gap:8px;text-align:left;border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.28));border-radius:var(--dsw-radius-md,9px);background:var(--dsw-alias-bg-layer-3,transparent);color:inherit;font:inherit;font-size:13px;cursor:pointer;transition:border-color .16s ease,background-color .16s ease,box-shadow .16s ease}\n.dshcu-select:hover:not(:disabled){border-color:color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 55%,var(--dsw-alias-border-l3,#888));background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.05))}\n.dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:none;border-color:var(--dshcu-accent,#1F1E1D);box-shadow:0 0 0 3px color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 20%,transparent)}\n.dshcu-select:disabled{opacity:.48;cursor:default}\n.dshcu-select svg{flex:none;transition:transform .2s cubic-bezier(.22,1,.36,1)}\n.dshcu-menu{position:fixed;z-index:1100;box-sizing:border-box;padding:5px;overflow-y:auto;overscroll-behavior:contain;border-radius:var(--dsw-radius-lg,12px);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.18));background:var(--dsw-menu-surface-fill,var(--dsw-alias-bg-layer-1,#fff));color:var(--dsw-alias-label-primary,#222);backdrop-filter:var(--dsw-menu-backdrop-filter,none);box-shadow:var(--dsw-elevation-prominent,0 12px 32px rgba(0,0,0,.16),0 2px 6px rgba(0,0,0,.06));animation:dshcu-menu-in .14s cubic-bezier(.22,1,.36,1)}\n.dshcu-option{display:flex;align-items:center;gap:8px;min-height:34px;padding:6px 10px;box-sizing:border-box;border-radius:var(--dsw-radius-md,8px);font-size:13px;line-height:20px;cursor:pointer;user-select:none;transition:background-color .12s ease,color .12s ease}\n.dshcu-option[data-active=true]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.11))}\n.dshcu-option[aria-selected=true]{font-weight:500;color:var(--dshcu-accent,#1F1E1D)}\n";
4
4
  export declare function Select<V extends string>({ options, value, disabled, label, onChange }: {
5
5
  options: {
6
6
  value: V;
@@ -27,6 +27,8 @@ export interface Settings {
27
27
  maxLongEdge: number;
28
28
  maxPixels: number;
29
29
  jpegQuality: number;
30
+ /** Screenshots kept as images in a conversation; older ones become text placeholders and their files are cleaned up. 0 keeps all. */
31
+ keepScreenshots: number;
30
32
  autoScreenshot: boolean;
31
33
  /** Detail tier for automatic post-action screenshots: standard or compact (smaller/cheaper). */
32
34
  autoScreenshotDetail: AutoScreenshotDetail;
@@ -88,6 +90,7 @@ export interface CallContext {
88
90
  export declare const ACTIONS: readonly ["screenshot", "left_click", "right_click", "middle_click", "double_click", "triple_click", "mouse_move", "left_click_drag", "left_mouse_down", "left_mouse_up", "scroll", "type", "key", "hold_key", "wait", "zoom", "cursor_position", "ui_action"];
89
91
  export type Action = typeof ACTIONS[number];
90
92
  export type UiSemanticOperation = 'invoke' | 'focus' | 'set_checked' | 'expand' | 'collapse' | 'select' | 'set_value';
93
+ export type ActionFeedback = 'auto' | 'state' | 'diff' | 'screenshot' | 'none';
91
94
  export interface ActionInput {
92
95
  action: Action;
93
96
  coordinate?: number[];
@@ -116,6 +119,8 @@ export interface ActionInput {
116
119
  detail?: ScreenshotDetail;
117
120
  /** type: select all (Ctrl+A) before entering replacement text. */
118
121
  replace?: boolean;
122
+ /** Post-action feedback mode: 'auto' skips screenshots for verified deterministic ui_action, 'state'/'none' skips screenshot, 'diff' returns UIA delta, 'screenshot' forces visual capture. */
123
+ feedback?: ActionFeedback;
119
124
  }
120
125
  export interface ActionOutcome {
121
126
  text: string;
@@ -123,6 +128,8 @@ export interface ActionOutcome {
123
128
  image?: Shot | 'unchanged';
124
129
  /** The action was not performed because the user took over the keyboard. */
125
130
  skipped?: boolean;
131
+ /** True when a deterministic UIA Control Pattern read back and verified the desired post-state. */
132
+ verified?: boolean;
126
133
  }
127
134
  export interface ClickResult {
128
135
  x?: number;
@@ -164,8 +171,10 @@ export declare class Computer {
164
171
  private heldButton;
165
172
  /** Dimensions of the latest full-display screenshot shown to the model (keeps coordinate conversion exact across detail modes). */
166
173
  private lastShot;
167
- /** Recent click locations (repeat counter + auto physical-click fallback if a UIA invoke had no effect). */
174
+ /** Recent click locations (repeat counter + scoped auto physical-click fallback if a UIA invoke had no effect). */
168
175
  private readonly clickHistory;
176
+ /** Rolling per-phase timing samples (settle + screenshot) for diagnostics & performance profiling. */
177
+ private readonly phaseSamples;
169
178
  /** The agent that last wrote the clipboard; when it goes idle the user's clipboard comes back. */
170
179
  clipboardAgent: CancellableAgent | undefined;
171
180
  /** Single-machine desktop control lease preventing concurrent sessions from colliding. */
@@ -227,8 +236,17 @@ export declare class Computer {
227
236
  }): Promise<Shot | 'unchanged'>;
228
237
  /** Record a click position and return how many times this spot (±24 px) was clicked in the last 2 minutes. */
229
238
  private noteClick;
230
- /** Whether this spot (±24 px) was already clicked via background UIA invoke recently (so a retry should use a real physical click). */
239
+ /**
240
+ * Whether this spot (±24 px) in the same session & window was recently invoked via UIA
241
+ * (and is NOT a non-idempotent submit/delete/pay button), so a retry upgrades to physical click.
242
+ */
231
243
  private hadRecentUiaClickAt;
244
+ /** Rolling average settle/screenshot phase timings for diagnostics. */
245
+ timingSummary(): {
246
+ samples: number;
247
+ avgSettleMs: number;
248
+ avgShotMs: number;
249
+ };
232
250
  foreground(): Promise<WindowInfo | undefined>;
233
251
  /**
234
252
  * The user clicked into the DeepSeek Harness card (to read or scroll the
@@ -236,6 +254,8 @@ export declare class Computer {
236
254
  * in front instead of refusing.
237
255
  */
238
256
  private refocusFromHost;
257
+ /** Prefer sampling the visible foreground target window (clamped to current display) so taskbar/side-app animations never disrupt settle detection. */
258
+ private settleRect;
239
259
  /** Wait at most `maxMs`, returning once the screen settles (for waits ≥ 4s, waits for a real visual update first and emits progress checkpoints if still changing so AI can act early or wait again). */
240
260
  waitForQuiet(maxMs: number, signal: AbortSignal, wait?: WaitHandle): Promise<{
241
261
  ms: number;
@@ -296,11 +316,14 @@ export declare class Computer {
296
316
  maxMatches?: number;
297
317
  }): Promise<(Partial<WindowInfo> & {
298
318
  elements: UiElement[];
319
+ truncated?: boolean;
299
320
  }) | undefined>;
300
321
  /**
301
- * Look for a named control via fast C#-side targeted UIA query when possible,
302
- * then full window UIA, then popups, and finally built-in Windows OCR when
303
- * the UIA tree is empty or sparse (<= 20 controls).
322
+ * Look for a named control via tiered C#-side targeted UIA lookup:
323
+ * 1. Exact AutomationId native PropertyCondition
324
+ * 2. Exact Name (+ optional Role) native PropertyCondition
325
+ * 3. Role + fuzzy query (accepting unique results only when not truncated)
326
+ * 4. Full window UIA -> popup UIA -> Windows OCR fallback.
304
327
  */
305
328
  private find;
306
329
  /**
@@ -343,7 +366,7 @@ export declare class Computer {
343
366
  * (vision models only). A wait already waited, so it is captured at once:
344
367
  * "wait, then look" should be one step, not two.
345
368
  */
346
- after(inputs: readonly ActionInput[], call: CallContext, detail?: ScreenshotDetail): Promise<Shot | 'unchanged' | undefined>;
369
+ after(inputs: readonly ActionInput[], call: CallContext, detail?: ScreenshotDetail, forceScreenshot?: boolean): Promise<Shot | 'unchanged' | undefined>;
347
370
  /** Bring a window forward and verify it is the foreground window. */
348
371
  focus(win: WindowInfo): Promise<WindowInfo & {
349
372
  focused: boolean;
@@ -57,6 +57,11 @@ export interface DiagnosticSnapshot {
57
57
  hasCustomHarnessUrl: boolean;
58
58
  };
59
59
  recentCalls: readonly DiagnosticCall[];
60
+ phaseTiming?: {
61
+ samples: number;
62
+ avgSettleMs: number;
63
+ avgShotMs: number;
64
+ };
60
65
  }
61
66
  export declare class DiagnosticsLog {
62
67
  private readonly calls;
@@ -75,5 +80,10 @@ export declare function buildDiagnosticSnapshot(options: {
75
80
  helperError?: string;
76
81
  nativeAvailable: boolean;
77
82
  recentCalls: readonly DiagnosticCall[];
83
+ phaseTiming?: {
84
+ samples: number;
85
+ avgSettleMs: number;
86
+ avgShotMs: number;
87
+ };
78
88
  }): DiagnosticSnapshot;
79
89
  export declare function formatDiagnosticText(snap: DiagnosticSnapshot): string;
@@ -29,6 +29,7 @@ export interface Config {
29
29
  maxLongEdge?: number;
30
30
  maxPixels?: number;
31
31
  jpegQuality?: number;
32
+ keepScreenshots?: number;
32
33
  blockedApps?: string[];
33
34
  pauseOnUserInput?: boolean;
34
35
  reportUserActions?: boolean;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Screenshot retention inside a conversation.
3
+ *
4
+ * DeepSeek Harness resends every image still in the history with each model
5
+ * request (up to its per-request budget), so a long computer-use task pays for
6
+ * dozens of stale screenshots on every step, and none of their files can ever
7
+ * be deleted. The Host's own image offload (`@deepseek-ai/dsh-compaction-image-offload`)
8
+ * only kicks in once a request is rejected as over budget.
9
+ *
10
+ * Before each step this plugin records the same durable `image/offload`
11
+ * decision for its own screenshots older than the newest `keep`: the model
12
+ * then sees a one-line placeholder in their place, provider caching restarts
13
+ * only at that (recent) point, and the screenshot files are no longer read
14
+ * for requests, so `ScreenshotCache` may delete them. User images and images
15
+ * from other tools are never touched.
16
+ */
17
+ /** The attachment name every screenshot of this plugin carries. */
18
+ export declare const SCREENSHOT_NAME = "screenshot.jpg";
19
+ interface BlockLike {
20
+ type?: unknown;
21
+ offloaded?: unknown;
22
+ attachment?: {
23
+ attachmentId?: unknown;
24
+ name?: unknown;
25
+ };
26
+ }
27
+ interface EventLike {
28
+ type?: unknown;
29
+ data?: unknown;
30
+ }
31
+ /** The parts of a Host Session this module uses (all optional: older hosts lack some). */
32
+ export interface RetentionSession {
33
+ surface?: {
34
+ nodes?: Iterable<number>;
35
+ };
36
+ eventAt?(seq: number): EventLike;
37
+ deriveEventMessage?(event: EventLike): {
38
+ content?: readonly BlockLike[];
39
+ };
40
+ append?(type: string, data: unknown): unknown;
41
+ }
42
+ export interface OffloadTarget {
43
+ seq: number;
44
+ imageIndexes: number[];
45
+ }
46
+ /**
47
+ * The image/offload targets that leave only the newest `keep` of this plugin's
48
+ * retained screenshots. Image indexes count every top-level image block of the
49
+ * message, offloaded ones included, exactly as the Host's projection does.
50
+ */
51
+ export declare function planOffload(session: RetentionSession, keep: number): {
52
+ targets: OffloadTarget[];
53
+ attachmentIds: string[];
54
+ };
55
+ /**
56
+ * Offload this plugin's screenshots older than the newest `keep` in `session`.
57
+ * Returns the attachment ids offloaded (empty when nothing changed). Never throws.
58
+ */
59
+ export declare function offloadOldScreenshots(session: RetentionSession | undefined, keep: number, log?: (message: string) => void): string[];
60
+ export {};
@@ -47,7 +47,11 @@ export declare function sessionRoute(gate: SessionGate, settings: () => Settings
47
47
  /** Export a sanitized diagnostic report (plain text by default, or JSON with ?format=json). */
48
48
  export declare function diagnosticsRoute(helper: HelperLike & {
49
49
  available?: boolean;
50
- }, settings: () => Settings, diagnostics: DiagnosticsLog, pluginVersion: string): Handler;
50
+ }, settings: () => Settings, diagnostics: DiagnosticsLog, pluginVersion: string, phaseTiming?: () => {
51
+ samples: number;
52
+ avgSettleMs: number;
53
+ avgShotMs: number;
54
+ }): Handler;
51
55
  /** Check npmjs & npmmirror concurrently for a newer plugin version. */
52
56
  export declare function updateRoute(pluginVersion: string): Handler;
53
57
  /** Passive read-only window list for `@窗口` composer references (never triggers overlay or focus). */
@@ -18,13 +18,19 @@ export declare class ScreenshotCache {
18
18
  private index;
19
19
  private saving;
20
20
  private busy;
21
+ /** Parsed session logs keyed by path, reused while their size and mtime stay the same. */
22
+ private files;
23
+ private soon;
21
24
  constructor(dshHome?: string, indexFile?: string, log?: (message: string) => void);
22
25
  private get objects();
23
26
  private path;
24
27
  /** Remember a screenshot attachment ("sha256:<hex>") this plugin saved. */
25
28
  record(attachmentId: string): void;
26
29
  stats(): Promise<ScreenshotStats>;
27
- /** Delete orphaned screenshots. */
30
+ /** Run `clean()` once, `delayMs` after the last call (screenshots were just offloaded). */
31
+ cleanSoon(delayMs?: number): void;
32
+ dispose(): void;
33
+ /** Delete screenshots no request can need any more. */
28
34
  clean(): Promise<CleanResult>;
29
35
  private classify;
30
36
  /** Every attachment id referenced anywhere DSH keeps conversation state. */
@@ -36,6 +42,13 @@ export declare class ScreenshotCache {
36
42
  }
37
43
  /** Ids in `text`; ids of our own screenshots (tool results named screenshot.jpg) also go to `ours`. */
38
44
  export declare function collect(text: string, referenced: Set<string>, ours: Set<string>): void;
45
+ /**
46
+ * Read one session log. An image occurrence (message seq, top-level image
47
+ * index) named by an `image/offload` event is offloaded; every other mention
48
+ * of an attachment, in any event, keeps it referenced. Lines that do not parse
49
+ * keep everything they mention.
50
+ */
51
+ export declare function collectLog(text: string, referenced: Set<string>, ours: Set<string>, offloaded: Set<string>): void;
39
52
  /** Split at frame magics; when a split falls inside a frame, merge with the next piece and retry. */
40
53
  export declare function decodeFrames(data: Buffer, zstd: ZstdDecompress): string | undefined;
41
54
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.14.2",
3
+ "version": "0.16.0",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "icon": "assets/icon.svg",
6
6
  "type": "module",