@copylee/dsh-computer-use 0.8.8 → 0.9.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.
@@ -228,12 +228,33 @@ function buttonFlags(button) {
228
228
  function vkList(value) {
229
229
  return Array.isArray(value) ? value.filter((v) => typeof v === "number") : [];
230
230
  }
231
+ const clickHistory = [];
232
+ function noteClick(x, y) {
233
+ const now = Date.now();
234
+ while (clickHistory.length > 0 && now - clickHistory[0].at > 12e4) clickHistory.shift();
235
+ clickHistory.push({
236
+ x,
237
+ y,
238
+ at: now
239
+ });
240
+ let count = 0;
241
+ for (const item of clickHistory) if (Math.abs(item.x - x) <= 24 && Math.abs(item.y - y) <= 24) count++;
242
+ return count;
243
+ }
231
244
  function click(args) {
245
+ let x, y;
232
246
  if (typeof args.x === "number") {
233
- move(int(args, "x", 0), int(args, "y", 0));
247
+ x = int(args, "x", 0);
248
+ y = int(args, "y", 0);
249
+ move(x, y);
234
250
  sleep(30);
251
+ } else {
252
+ const pos = cursor();
253
+ x = pos.x;
254
+ y = pos.y;
235
255
  }
236
- const [down, up] = buttonFlags(args.button);
256
+ const button = args.button === "right" || args.button === "middle" ? args.button : "left";
257
+ const [down, up] = buttonFlags(button);
237
258
  const count = Math.max(1, Math.min(3, int(args, "count", 1)));
238
259
  const mods = vkList(args.modifiers);
239
260
  send(mods.map((vk) => key(vk, false)));
@@ -247,7 +268,13 @@ function click(args) {
247
268
  } finally {
248
269
  send([...mods].reverse().map((vk) => key(vk, true)));
249
270
  }
250
- return null;
271
+ return {
272
+ x,
273
+ y,
274
+ button,
275
+ count,
276
+ repeat: noteClick(x, y)
277
+ };
251
278
  }
252
279
  function keys(args) {
253
280
  const combos = Array.isArray(args.combos) ? args.combos.map(vkList) : [];
@@ -549,8 +576,7 @@ function changed(a, b) {
549
576
  for (let i = 0; i < a.length; i += 3) if (Math.abs(a[i] - b[i]) + Math.abs(a[i + 1] - b[i + 1]) + Math.abs(a[i + 2] - b[i + 2]) > 30) diff++;
550
577
  return a.length === 0 ? 0 : diff / (a.length / 3);
551
578
  }
552
- let marked;
553
- let markedRect = "";
579
+ const markedBySlot = /* @__PURE__ */ new Map();
554
580
  /** Encode a GDI+ image to JPEG in memory and return the bytes. */
555
581
  function encodeJpeg(image, quality) {
556
582
  const value = koffi.alloc("uint32_t", 1);
@@ -612,12 +638,19 @@ function screenshot(args) {
612
638
  GdiFlush();
613
639
  const compare = args.compare === true;
614
640
  if (args.mark === true || compare) {
641
+ const slot = typeof args.slot === "string" && args.slot.trim() !== "" ? args.slot : "full";
615
642
  const key = `${x},${y},${w},${h}`;
616
643
  const now = sample(bits[0], w, h);
617
644
  const threshold = typeof args.threshold === "number" ? args.threshold : 5e-4;
618
- if (compare && marked && markedRect === key && changed(marked, now) < threshold) return { unchanged: true };
619
- marked = now;
620
- markedRect = key;
645
+ const outPixels = ow * oh;
646
+ const prev = markedBySlot.get(slot);
647
+ if (compare && prev && prev.rect === key && outPixels <= prev.outPixels && quality <= prev.quality && changed(prev.sample, now) < threshold) return { unchanged: true };
648
+ markedBySlot.set(slot, {
649
+ rect: key,
650
+ sample: now,
651
+ outPixels,
652
+ quality
653
+ });
621
654
  }
622
655
  const source = [0n];
623
656
  check(GdipCreateBitmapFromScan0(w, h, w * 4, 139273, bits[0], source), "GdipCreateBitmapFromScan0");
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Per-session computer-use toggle pill rendered in the conversation composer's
3
+ * left tool row (`conversation.input.left`). Clicking turns computer-use tools
4
+ * and system-prompt guidance on or off for the current session without restart.
5
+ */
6
+ import * as React from 'react';
7
+ export interface ComposerPillProps {
8
+ sessionId?: string;
9
+ }
10
+ export declare function createComposerPill(subscribeSettings?: (listener: () => void) => (() => void) | undefined): (props: ComposerPillProps) => React.DetailedReactHTMLElement<{
11
+ type: string;
12
+ className: string;
13
+ 'data-active': string;
14
+ 'aria-pressed': boolean;
15
+ 'aria-label': string;
16
+ title: string;
17
+ disabled: boolean;
18
+ onClick: () => void;
19
+ }, HTMLElement> | null;
@@ -1,13 +1,16 @@
1
1
  import { type AccessControl, type AccessMode, type WindowLike } from './access.js';
2
2
  import { type BrowserTab } from './browser-host.js';
3
- import { type Display, type Point, type Size } from './coords.js';
3
+ import { type Display, type Point, type ScreenshotDetail, type Size } from './coords.js';
4
4
  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
+ export type AutoScreenshotDetail = 'standard' | 'compact';
7
8
  export interface Settings {
8
9
  /** Web GUI origin, inferred from the local web server unless configured. */
9
10
  harnessUrl?: string | undefined;
10
11
  accessMode: AccessMode;
12
+ /** Whether new sessions start with computer-use tools enabled (default false; toggle per session in composer). */
13
+ defaultSessionEnabled: boolean;
11
14
  blockedApps: string[];
12
15
  overlay: boolean;
13
16
  overlayLabel: string;
@@ -18,6 +21,8 @@ export interface Settings {
18
21
  maxPixels: number;
19
22
  jpegQuality: number;
20
23
  autoScreenshot: boolean;
24
+ /** Detail tier for automatic post-action screenshots: standard or compact (smaller/cheaper). */
25
+ autoScreenshotDetail: AutoScreenshotDetail;
21
26
  settleMs: number;
22
27
  /** Pause while the user types on the physical keyboard. */
23
28
  pauseOnUserInput: boolean;
@@ -77,14 +82,25 @@ export interface ActionInput {
77
82
  until?: string;
78
83
  /** wait: wait for it to disappear instead. */
79
84
  gone?: boolean;
85
+ /** screenshot / zoom: capture even when pixels match the previous image. */
86
+ force?: boolean;
87
+ /** Screenshot detail: 'high' uses full configured limits; 'low' uses a compact budget for quick checks. */
88
+ detail?: ScreenshotDetail;
80
89
  }
81
90
  export interface ActionOutcome {
82
91
  text: string;
83
- /** A screenshot or zoom image to return to the model. */
84
- image?: Shot;
92
+ /** A screenshot or zoom image to return to the model, or 'unchanged' when deduplicated. */
93
+ image?: Shot | 'unchanged';
85
94
  /** The action was not performed because the user took over the keyboard. */
86
95
  skipped?: boolean;
87
96
  }
97
+ export interface ClickResult {
98
+ x?: number;
99
+ y?: number;
100
+ button?: string;
101
+ count?: number;
102
+ repeat?: number;
103
+ }
88
104
  /** Text returned instead of an identical screenshot. */
89
105
  export declare const UNCHANGED_TEXT = "The screen looks exactly as in your previous screenshot: the action had no visible effect.";
90
106
  /** Longest adaptive wait for the screen to settle after an action. */
@@ -97,6 +113,10 @@ export declare class Computer {
97
113
  private displays;
98
114
  private displayIndex;
99
115
  private heldButton;
116
+ /** Dimensions of the latest full-display screenshot shown to the model (keeps coordinate conversion exact across detail modes). */
117
+ private lastShot;
118
+ /** Recent click locations (fallback repeat counter when helper does not report repeat). */
119
+ private readonly clickHistory;
100
120
  /** The agent that last wrote the clipboard; when it goes idle the user's clipboard comes back. */
101
121
  clipboardAgent: CancellableAgent | undefined;
102
122
  constructor(helper: HelperLike, access: AccessControl, overlay: OverlayController, settings: () => Settings);
@@ -104,18 +124,31 @@ export declare class Computer {
104
124
  display(): Promise<Display>;
105
125
  selectDisplay(index: number): Promise<Display>;
106
126
  get currentIndex(): number;
107
- shotSize(display: Display): Size;
127
+ private shotBudget;
128
+ shotSize(display: Display, detail?: ScreenshotDetail): Size;
129
+ /** Coordinate space of the latest full screenshot of `display` (or its default full size before any capture). */
130
+ coordSize(display: Display): Size;
108
131
  private point;
109
132
  toModel(point: Point): Promise<Point & {
110
133
  offscreen: boolean;
111
134
  }>;
112
- screenshot(): Promise<Shot>;
135
+ /** Unconditional full screenshot (used when the model must see a fresh frame, e.g. after pause/switch). */
136
+ screenshot(detail?: ScreenshotDetail): Promise<Shot>;
137
+ /**
138
+ * Explicit model-requested screenshot: deduplicates against the last full
139
+ * screenshot shown to the model unless `force: true` or higher detail is asked.
140
+ */
141
+ takeScreenshot(options?: {
142
+ force?: boolean;
143
+ detail?: ScreenshotDetail;
144
+ }): Promise<Shot | 'unchanged'>;
113
145
  /**
114
- * A fresh screenshot, or 'unchanged' when the screen looks the same as in
115
- * the last one the model saw (saves an image and tells it the action had no
116
- * visible effect).
146
+ * A fresh post-action screenshot, or 'unchanged' when the screen looks the
147
+ * same as in the last one the model saw (saves an image and tells it the
148
+ * action had no visible effect). Respects `autoScreenshotDetail` unless
149
+ * overridden by an explicit `detail`.
117
150
  */
118
- freshShot(): Promise<Shot | 'unchanged'>;
151
+ freshShot(detail?: ScreenshotDetail): Promise<Shot | 'unchanged'>;
119
152
  /** The foreground window as of the model's latest look at the screen. */
120
153
  private seen;
121
154
  /** The latest foreground window that was not DeepSeek Harness itself. */
@@ -129,7 +162,12 @@ export declare class Computer {
129
162
  */
130
163
  private foregroundChanged;
131
164
  private capture;
132
- zoom(region: number[] | undefined): Promise<Shot>;
165
+ zoom(region: number[] | undefined, options?: {
166
+ force?: boolean;
167
+ detail?: ScreenshotDetail;
168
+ }): Promise<Shot | 'unchanged'>;
169
+ /** Record a physical click position and return how many times this spot (±24 px) was clicked in the last 2 minutes. */
170
+ private noteClick;
133
171
  foreground(): Promise<WindowInfo | undefined>;
134
172
  /**
135
173
  * The user clicked into the DeepSeek Harness card (to read or scroll the
@@ -210,7 +248,7 @@ export declare class Computer {
210
248
  * (vision models only). A wait already waited, so it is captured at once:
211
249
  * "wait, then look" should be one step, not two.
212
250
  */
213
- after(inputs: readonly ActionInput[], call: CallContext): Promise<Shot | 'unchanged' | undefined>;
251
+ after(inputs: readonly ActionInput[], call: CallContext, detail?: ScreenshotDetail): Promise<Shot | 'unchanged' | undefined>;
214
252
  /** Bring a window forward and verify it is the foreground window. */
215
253
  focus(win: WindowInfo): Promise<WindowInfo & {
216
254
  focused: boolean;
@@ -17,6 +17,14 @@ export interface ScreenshotLimits {
17
17
  maxLongEdge: number;
18
18
  maxPixels: number;
19
19
  }
20
+ export interface ScreenshotBudget extends ScreenshotLimits {
21
+ jpegQuality: number;
22
+ }
23
+ export type ScreenshotDetail = 'high' | 'low';
24
+ export interface ScreenshotSizeInfo extends Size {
25
+ megapixels: number;
26
+ limitedBy: 'none' | 'longEdge' | 'pixels';
27
+ }
20
28
  export interface Size {
21
29
  width: number;
22
30
  height: number;
@@ -29,6 +37,10 @@ export interface Rect extends Point, Size {
29
37
  }
30
38
  /** Screenshot size for a display: fit both limits, keep aspect, never upscale. */
31
39
  export declare function screenshotSize(display: Size, limits: ScreenshotLimits): Size;
40
+ /** Output size together with which limit (`longEdge`, `pixels`, or neither) actually constrained it. */
41
+ export declare function describeScreenshotSize(display: Size, limits: ScreenshotLimits): ScreenshotSizeInfo;
42
+ /** Lower-cost screenshot budget for quick confirmation shots (~30–40% fewer bytes). */
43
+ export declare function compactLimits(budget: ScreenshotBudget): ScreenshotBudget;
32
44
  /** Screenshot pixels → physical virtual-screen pixels. Throws when outside the image. */
33
45
  export declare function toPhysical(point: Point, display: Display, shot: Size): Point;
34
46
  /** Physical virtual-screen pixels → screenshot pixels (may fall outside for other displays). */
@@ -1,7 +1,7 @@
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 TypingMode } from './computer.js';
4
+ import { type AutoScreenshotDetail, type TypingMode } from './computer.js';
5
5
  import { type HostWindowMode } from './overlay.js';
6
6
  export { DEFAULTS, ENTRY_ID, resolveConfig } from './settings.js';
7
7
  export declare const name = "@copylee/dsh-computer-use";
@@ -9,6 +9,7 @@ export declare const inject: string[];
9
9
  export interface Config {
10
10
  harnessUrl?: string;
11
11
  accessMode?: AccessMode;
12
+ defaultSessionEnabled?: boolean;
12
13
  overlay?: boolean;
13
14
  overlayLabel?: string;
14
15
  hostWindow?: HostWindowMode;
@@ -16,6 +17,7 @@ export interface Config {
16
17
  /** @deprecated replaced by hostWindow: 'minimize' */
17
18
  minimizeHostWindow?: boolean;
18
19
  autoScreenshot?: boolean;
20
+ autoScreenshotDetail?: AutoScreenshotDetail;
19
21
  settleMs?: number;
20
22
  maxLongEdge?: number;
21
23
  maxPixels?: number;
@@ -3,17 +3,19 @@
3
3
  * resulting screenshot size) and a short overlay preview.
4
4
  */
5
5
  import type { IncomingMessage, ServerResponse } from 'node:http';
6
- import { type Display } from './coords.js';
6
+ import { type Display, type ScreenshotSizeInfo } from './coords.js';
7
7
  import type { Settings } from './computer.js';
8
8
  import type { HelperLike } from './helper-client.js';
9
9
  import type { OverlayController } from './overlay.js';
10
10
  import type { ScreenshotCache } from './screenshots.js';
11
+ import type { SessionGate } from './sessions.js';
11
12
  import type { SkillStore } from './skills.js';
12
13
  export declare const STATUS_ROUTE = "/api/dsh-computer-use/status";
13
14
  export declare const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
14
15
  export declare const SCREENSHOTS_ROUTE = "/api/dsh-computer-use/screenshots";
15
16
  export declare const SCREENSHOTS_CLEAN_ROUTE = "/api/dsh-computer-use/screenshots/clean";
16
17
  export declare const SKILLS_ROUTE = "/api/dsh-computer-use/skills";
18
+ export declare const SESSION_ROUTE = "/api/dsh-computer-use/session";
17
19
  type Handler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
18
20
  export interface StatusBody {
19
21
  ok: true;
@@ -21,10 +23,8 @@ export interface StatusBody {
21
23
  helper: 'ready' | 'error';
22
24
  error?: string;
23
25
  displays: Array<Display & {
24
- shot: {
25
- width: number;
26
- height: number;
27
- };
26
+ shot: ScreenshotSizeInfo;
27
+ compactShot: ScreenshotSizeInfo;
28
28
  }>;
29
29
  controlling: boolean;
30
30
  }
@@ -37,4 +37,6 @@ export declare function screenshotsRoute(cache: ScreenshotCache): Handler;
37
37
  export declare function screenshotsCleanRoute(cache: ScreenshotCache): Handler;
38
38
  /** App skills for the settings page: GET lists them; POST { op: 'save' | 'delete' | 'reset', ... } changes one. */
39
39
  export declare function skillsRoute(skills: SkillStore): Handler;
40
+ /** Per-session computer-use toggle: GET ?sessionId=... reads resolved state; POST { sessionId, enabled } updates and syncs live agents. */
41
+ export declare function sessionRoute(gate: SessionGate, settings: () => Settings, parentIdsFor: (sessionId: string) => readonly string[], sync: () => void): Handler;
40
42
  export {};
@@ -0,0 +1,56 @@
1
+ export interface SessionResolveOptions {
2
+ defaultEnabled?: boolean;
3
+ parentIds?: readonly string[];
4
+ }
5
+ export interface SessionToggleStatus {
6
+ sessionId: string;
7
+ enabled: boolean;
8
+ explicit: boolean;
9
+ inherited: boolean;
10
+ defaultEnabled: boolean;
11
+ }
12
+ export interface AgentLineageLike {
13
+ readonly id?: string;
14
+ readonly session: {
15
+ readonly id: string;
16
+ readonly header?: {
17
+ readonly parentSession?: string;
18
+ };
19
+ };
20
+ }
21
+ export interface AgentRegistryLike {
22
+ get?(id: string): AgentLineageLike | undefined;
23
+ list?(): readonly AgentLineageLike[];
24
+ isOwnedBy?(id: string, owner: AgentLineageLike): boolean;
25
+ }
26
+ export declare function defaultSessionsFile(): string;
27
+ /**
28
+ * Walk an agent's parent chain (nearest ancestor first), combining durable
29
+ * `session.header.parentSession` with runtime parent ownership for subagents.
30
+ */
31
+ export declare function parentSessionChain(agent: AgentLineageLike | undefined, registry?: AgentRegistryLike): string[];
32
+ export declare class SessionGate {
33
+ /** Disk path for persistence; pass `null` for an in-memory store (tests). */
34
+ private readonly storeFile;
35
+ private readonly log;
36
+ private readonly entries;
37
+ private saving;
38
+ constructor(
39
+ /** Disk path for persistence; pass `null` for an in-memory store (tests). */
40
+ storeFile?: string | null, log?: (message: string) => void);
41
+ /** Explicit decision stored for `sessionId`, or undefined when unset. */
42
+ explicit(sessionId: string): boolean | undefined;
43
+ /** Effective enabled state for `sessionId`, inheriting ancestors before falling back to `defaultEnabled`. */
44
+ isEnabled(sessionId: string | undefined, options?: SessionResolveOptions): boolean;
45
+ /** Inspect the resolved state plus whether it came from an explicit choice or ancestor inheritance. */
46
+ status(sessionId: string, options?: SessionResolveOptions): SessionToggleStatus;
47
+ /** Persist an explicit on/off choice for `sessionId`. */
48
+ set(sessionId: string, enabled: boolean): void;
49
+ /** Remove an explicit choice so the session falls back to inheritance / default. */
50
+ clear(sessionId: string): void;
51
+ /** Wait for any pending write to settle (used by tests). */
52
+ flush(): Promise<void>;
53
+ private trim;
54
+ private loadSync;
55
+ private persist;
56
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.8.8",
3
+ "version": "0.9.0",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "icon": "assets/icon.svg",
6
6
  "type": "module",