@copylee/dsh-computer-use 0.1.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.
- package/LICENSE +21 -0
- package/README.md +116 -0
- package/cordis.patch.yml +4 -0
- package/helper/CuHelper.cs +1236 -0
- package/lib/index.js +7325 -0
- package/lib/types/access.d.ts +31 -0
- package/lib/types/computer.d.ts +105 -0
- package/lib/types/coords.d.ts +39 -0
- package/lib/types/helper-client.d.ts +30 -0
- package/lib/types/index.d.ts +28 -0
- package/lib/types/keys.d.ts +14 -0
- package/lib/types/overlay.d.ts +32 -0
- package/lib/types/prompt.d.ts +3 -0
- package/lib/types/tools.d.ts +13 -0
- package/package.json +99 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-session application grants, modelled on Claude's computer use: the
|
|
3
|
+
* model asks for named apps with request_access, the user approves through
|
|
4
|
+
* DSH's own approval prompt, and input is only delivered to granted apps.
|
|
5
|
+
* The DSH window itself and configured blocked apps are never controllable.
|
|
6
|
+
*/
|
|
7
|
+
export type AccessMode = 'per-app' | 'allow-all';
|
|
8
|
+
export interface WindowLike {
|
|
9
|
+
exe: string;
|
|
10
|
+
title: string;
|
|
11
|
+
}
|
|
12
|
+
/** The DSH desktop host: the agent must never type into its own chat. */
|
|
13
|
+
export declare const HOST_EXES: string[];
|
|
14
|
+
export declare function normalizeApp(name: string): string;
|
|
15
|
+
export declare function isHostWindow(win: WindowLike): boolean;
|
|
16
|
+
/** Does a granted (or requested) app name refer to this window? */
|
|
17
|
+
export declare function appMatches(name: string, win: WindowLike): boolean;
|
|
18
|
+
export declare class AccessControl {
|
|
19
|
+
private readonly grants;
|
|
20
|
+
grant(session: string, names: readonly string[]): string[];
|
|
21
|
+
granted(session: string): string[];
|
|
22
|
+
isGranted(session: string, win: WindowLike): boolean;
|
|
23
|
+
/** Names from `names` the session has not been granted yet. */
|
|
24
|
+
missing(session: string, names: readonly string[]): string[];
|
|
25
|
+
forget(session: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Why input may not go to `win`, or undefined when it may. `action` is a
|
|
28
|
+
* short verb for the message ("click", "type into").
|
|
29
|
+
*/
|
|
30
|
+
denial(session: string, win: WindowLike | undefined, mode: AccessMode, blocked: readonly string[], action: string): string | undefined;
|
|
31
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { AccessControl, AccessMode, WindowLike } from './access.js';
|
|
2
|
+
import { type Display, type Point, type Size } from './coords.js';
|
|
3
|
+
import type { HelperLike } from './helper-client.js';
|
|
4
|
+
import type { CancellableAgent, OverlayController } from './overlay.js';
|
|
5
|
+
export interface Settings {
|
|
6
|
+
accessMode: AccessMode;
|
|
7
|
+
blockedApps: string[];
|
|
8
|
+
overlay: boolean;
|
|
9
|
+
overlayLabel: string;
|
|
10
|
+
minimizeHostWindow: boolean;
|
|
11
|
+
maxLongEdge: number;
|
|
12
|
+
maxPixels: number;
|
|
13
|
+
jpegQuality: number;
|
|
14
|
+
autoScreenshot: boolean;
|
|
15
|
+
settleMs: number;
|
|
16
|
+
}
|
|
17
|
+
export interface WindowInfo extends WindowLike {
|
|
18
|
+
hwnd: number;
|
|
19
|
+
pid: number;
|
|
20
|
+
className: string;
|
|
21
|
+
path: string;
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
minimized: boolean;
|
|
27
|
+
maximized: boolean;
|
|
28
|
+
foreground?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface Shot {
|
|
31
|
+
data: Uint8Array;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
}
|
|
35
|
+
/** What a tool call knows about its caller. */
|
|
36
|
+
export interface CallContext {
|
|
37
|
+
session: string;
|
|
38
|
+
agent: CancellableAgent | undefined;
|
|
39
|
+
signal: AbortSignal;
|
|
40
|
+
/** Whether the conversation model can look at images. */
|
|
41
|
+
vision: boolean;
|
|
42
|
+
}
|
|
43
|
+
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"];
|
|
44
|
+
export type Action = typeof ACTIONS[number];
|
|
45
|
+
export interface ActionInput {
|
|
46
|
+
action: Action;
|
|
47
|
+
coordinate?: number[];
|
|
48
|
+
start_coordinate?: number[];
|
|
49
|
+
text?: string;
|
|
50
|
+
modifiers?: string;
|
|
51
|
+
scroll_direction?: 'up' | 'down' | 'left' | 'right';
|
|
52
|
+
scroll_amount?: number;
|
|
53
|
+
duration?: number;
|
|
54
|
+
region?: number[];
|
|
55
|
+
}
|
|
56
|
+
export interface ActionOutcome {
|
|
57
|
+
text: string;
|
|
58
|
+
/** A screenshot or zoom image to return to the model. */
|
|
59
|
+
image?: Shot;
|
|
60
|
+
}
|
|
61
|
+
export declare class Computer {
|
|
62
|
+
readonly helper: HelperLike;
|
|
63
|
+
readonly access: AccessControl;
|
|
64
|
+
readonly overlay: OverlayController;
|
|
65
|
+
readonly settings: () => Settings;
|
|
66
|
+
private displays;
|
|
67
|
+
private displayIndex;
|
|
68
|
+
private heldButton;
|
|
69
|
+
constructor(helper: HelperLike, access: AccessControl, overlay: OverlayController, settings: () => Settings);
|
|
70
|
+
refreshDisplays(): Promise<Display[]>;
|
|
71
|
+
display(): Promise<Display>;
|
|
72
|
+
selectDisplay(index: number): Promise<Display>;
|
|
73
|
+
get currentIndex(): number;
|
|
74
|
+
shotSize(display: Display): Size;
|
|
75
|
+
private point;
|
|
76
|
+
toModel(point: Point): Promise<Point & {
|
|
77
|
+
offscreen: boolean;
|
|
78
|
+
}>;
|
|
79
|
+
screenshot(): Promise<Shot>;
|
|
80
|
+
private capture;
|
|
81
|
+
zoom(region: number[] | undefined): Promise<Shot>;
|
|
82
|
+
foreground(): Promise<WindowInfo | undefined>;
|
|
83
|
+
windowAt(point: Point): Promise<WindowInfo | undefined>;
|
|
84
|
+
windows(): Promise<WindowInfo[]>;
|
|
85
|
+
cursor(): Promise<Point>;
|
|
86
|
+
/** Short description of the frontmost window, for result text. */
|
|
87
|
+
describeForeground(): Promise<string>;
|
|
88
|
+
private assertAllowed;
|
|
89
|
+
private checkPointer;
|
|
90
|
+
private checkKeyboard;
|
|
91
|
+
/** Overlay status line for an action (Chinese, shown to the user). */
|
|
92
|
+
static statusOf(input: ActionInput): string;
|
|
93
|
+
/** Run one action. Returns text plus an image for screenshot/zoom. */
|
|
94
|
+
run(input: ActionInput, call: CallContext): Promise<ActionOutcome>;
|
|
95
|
+
/** Release a mouse button left down by an aborted run. */
|
|
96
|
+
releaseHeld(): Promise<void>;
|
|
97
|
+
/** After a mutating action: settle, then capture (vision models only). */
|
|
98
|
+
after(inputs: readonly ActionInput[], call: CallContext): Promise<Shot | undefined>;
|
|
99
|
+
/** Bring a window forward and verify it is the foreground window. */
|
|
100
|
+
focus(win: WindowInfo): Promise<WindowInfo & {
|
|
101
|
+
focused: boolean;
|
|
102
|
+
}>;
|
|
103
|
+
/** Window rectangle in screenshot coordinates, for listings. */
|
|
104
|
+
windowBox(win: WindowInfo): Promise<string>;
|
|
105
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model only ever sees one coordinate space: pixels of the most recent
|
|
3
|
+
* screenshot of the current display. The plugin owns the conversion to
|
|
4
|
+
* physical virtual-screen pixels, so the model never does scale arithmetic.
|
|
5
|
+
*/
|
|
6
|
+
export interface Display {
|
|
7
|
+
/** Physical virtual-screen origin and size. */
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
primary: boolean;
|
|
13
|
+
dpi: number;
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ScreenshotLimits {
|
|
17
|
+
maxLongEdge: number;
|
|
18
|
+
maxPixels: number;
|
|
19
|
+
}
|
|
20
|
+
export interface Size {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}
|
|
24
|
+
export interface Point {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
}
|
|
28
|
+
export interface Rect extends Point, Size {
|
|
29
|
+
}
|
|
30
|
+
/** Screenshot size for a display: fit both limits, keep aspect, never upscale. */
|
|
31
|
+
export declare function screenshotSize(display: Size, limits: ScreenshotLimits): Size;
|
|
32
|
+
/** Screenshot pixels → physical virtual-screen pixels. Throws when outside the image. */
|
|
33
|
+
export declare function toPhysical(point: Point, display: Display, shot: Size): Point;
|
|
34
|
+
/** Physical virtual-screen pixels → screenshot pixels (may fall outside for other displays). */
|
|
35
|
+
export declare function toScreenshot(point: Point, display: Display, shot: Size): Point;
|
|
36
|
+
/** Screenshot-space region [x1, y1, x2, y2] → physical rect clamped to the display. */
|
|
37
|
+
export declare function regionToPhysical(region: readonly number[], display: Display, shot: Size): Rect;
|
|
38
|
+
/** Is a physical point on this display? */
|
|
39
|
+
export declare function contains(display: Display, point: Point): boolean;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface HelperEvent {
|
|
2
|
+
event: string;
|
|
3
|
+
reason?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface HelperLike {
|
|
6
|
+
call<T = unknown>(cmd: string, args?: Record<string, unknown>, timeoutMs?: number): Promise<T>;
|
|
7
|
+
onEvent(listener: (event: HelperEvent) => void): () => void;
|
|
8
|
+
dispose(): void;
|
|
9
|
+
}
|
|
10
|
+
/** The helper source at the package root: one level up from lib/ or src/, two from lib/types/. */
|
|
11
|
+
export declare function helperSourcePath(): string;
|
|
12
|
+
/** Compile the helper if this source version has no cached exe yet; returns the exe path. */
|
|
13
|
+
export declare function ensureHelperExe(source?: string): Promise<string>;
|
|
14
|
+
export declare class HelperClient implements HelperLike {
|
|
15
|
+
private readonly log;
|
|
16
|
+
private child;
|
|
17
|
+
private starting;
|
|
18
|
+
private readonly pending;
|
|
19
|
+
private readonly listeners;
|
|
20
|
+
private nextId;
|
|
21
|
+
private disposed;
|
|
22
|
+
constructor(log?: (message: string) => void);
|
|
23
|
+
onEvent(listener: (event: HelperEvent) => void): () => void;
|
|
24
|
+
call<T = unknown>(cmd: string, args?: Record<string, unknown>, timeoutMs?: number): Promise<T>;
|
|
25
|
+
dispose(): void;
|
|
26
|
+
private kill;
|
|
27
|
+
private ensure;
|
|
28
|
+
private start;
|
|
29
|
+
private handle;
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copylee/dsh-computer-use host bundle: Claude-style computer use for the
|
|
3
|
+
* Windows desktop — screenshots in, mouse and keyboard out, per-app grants
|
|
4
|
+
* through DSH approvals, and an orange "DeepSeek is using your computer"
|
|
5
|
+
* overlay that a physical Esc dismisses.
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
8
|
+
import z from '@deepseek-ai/schemastery';
|
|
9
|
+
import { type AccessMode } from './access.js';
|
|
10
|
+
import { type Settings } from './computer.js';
|
|
11
|
+
export declare const name = "@copylee/dsh-computer-use";
|
|
12
|
+
export declare const inject: string[];
|
|
13
|
+
export interface Config {
|
|
14
|
+
accessMode?: AccessMode;
|
|
15
|
+
overlay?: boolean;
|
|
16
|
+
overlayLabel?: string;
|
|
17
|
+
minimizeHostWindow?: boolean;
|
|
18
|
+
autoScreenshot?: boolean;
|
|
19
|
+
settleMs?: number;
|
|
20
|
+
maxLongEdge?: number;
|
|
21
|
+
maxPixels?: number;
|
|
22
|
+
jpegQuality?: number;
|
|
23
|
+
blockedApps?: string[];
|
|
24
|
+
}
|
|
25
|
+
export declare const Config: z<Config>;
|
|
26
|
+
/** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
|
|
27
|
+
export declare function resolveConfig(raw: unknown): Settings;
|
|
28
|
+
export declare function apply(ctx: Context, config?: Config): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* xdotool-style key names (what the Anthropic computer tool and most models
|
|
3
|
+
* emit: "ctrl+shift+t", "Return", "super", "F5") mapped to Windows virtual-key
|
|
4
|
+
* codes. One combo is a list of VKs pressed in order and released in reverse.
|
|
5
|
+
*/
|
|
6
|
+
/** One key name to a VK code, or undefined when unknown. */
|
|
7
|
+
export declare function keyCode(name: string): number | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Parse "ctrl+shift+t" or a space-separated sequence "ctrl+a Delete" into
|
|
10
|
+
* combos. A lone "+" is the plus key. Throws with the unknown name.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseKeys(text: string): number[][];
|
|
13
|
+
/** Modifier names accepted by the `modifiers` parameter of click/scroll actions. */
|
|
14
|
+
export declare function parseModifiers(text: string | undefined): number[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { HelperLike } from './helper-client.js';
|
|
2
|
+
export interface CancellableAgent {
|
|
3
|
+
cancel(cause: {
|
|
4
|
+
kind: 'user';
|
|
5
|
+
}): void;
|
|
6
|
+
}
|
|
7
|
+
export interface OverlaySettings {
|
|
8
|
+
overlay: boolean;
|
|
9
|
+
overlayLabel: string;
|
|
10
|
+
minimizeHostWindow: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class OverlayController {
|
|
13
|
+
private readonly helper;
|
|
14
|
+
private readonly settings;
|
|
15
|
+
private readonly log;
|
|
16
|
+
private agent;
|
|
17
|
+
private visible;
|
|
18
|
+
private idleTimer;
|
|
19
|
+
private minimizedHost;
|
|
20
|
+
private stopping;
|
|
21
|
+
constructor(helper: HelperLike, settings: () => OverlaySettings, log: (message: string) => void);
|
|
22
|
+
/** The agent currently driving the computer, if any. */
|
|
23
|
+
get controller(): CancellableAgent | undefined;
|
|
24
|
+
/** Called before every action: shows the overlay once and updates its status line. */
|
|
25
|
+
begin(agent: CancellableAgent | undefined, status: string): Promise<void>;
|
|
26
|
+
/** Agent finished (idle), was cancelled, or the plugin is stopping. */
|
|
27
|
+
end(agent?: CancellableAgent): Promise<void>;
|
|
28
|
+
private stop;
|
|
29
|
+
private armIdle;
|
|
30
|
+
private minimizeHost;
|
|
31
|
+
private restoreHost;
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
|
|
2
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
3
|
+
import { Computer, type CallContext, type Shot } from './computer.js';
|
|
4
|
+
type ToolDefinition = ReturnType<typeof defineTool>;
|
|
5
|
+
export interface ToolHost {
|
|
6
|
+
computer: Computer;
|
|
7
|
+
/** Persist an image so the model can see it. */
|
|
8
|
+
saveImage(shot: Shot, name: string): Promise<ImageAttachmentRef>;
|
|
9
|
+
/** Build the per-call context (session, agent, vision support). */
|
|
10
|
+
context(exec: unknown): Promise<CallContext>;
|
|
11
|
+
}
|
|
12
|
+
export declare function createTools(host: ToolHost): ToolDefinition[];
|
|
13
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@copylee/dsh-computer-use",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "DeepSeek Harness Computer Use 插件(Windows):像 Claude 一样看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek 正在使用你的电脑”,按 Esc 立即停止。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"author": "copylee",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/copylee711/dsh-computer-use.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/copylee711/dsh-computer-use/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/copylee711/dsh-computer-use#readme",
|
|
15
|
+
"main": "lib/index.js",
|
|
16
|
+
"types": "lib/types/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./lib/types/index.d.ts",
|
|
20
|
+
"default": "./lib/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"lib/index.js",
|
|
26
|
+
"lib/types/**/*.d.ts",
|
|
27
|
+
"helper/CuHelper.cs",
|
|
28
|
+
"cordis.patch.yml",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"os": [
|
|
33
|
+
"win32"
|
|
34
|
+
],
|
|
35
|
+
"dsh": {
|
|
36
|
+
"bundle": {
|
|
37
|
+
"patch": "./cordis.patch.yml"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"dsh": ">=0.2.0-rc.2"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"build": "tsc && tsdown",
|
|
46
|
+
"prepare": "pnpm run build",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"pack:check": "pnpm pack --dry-run",
|
|
49
|
+
"smoke": "node scripts/helper-smoke.mjs"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
53
|
+
},
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"keywords": [
|
|
56
|
+
"deepseek",
|
|
57
|
+
"deepseek-harness",
|
|
58
|
+
"dsh",
|
|
59
|
+
"dsh-plugin",
|
|
60
|
+
"ai-agent",
|
|
61
|
+
"computer-use",
|
|
62
|
+
"computer-control",
|
|
63
|
+
"desktop-automation",
|
|
64
|
+
"windows",
|
|
65
|
+
"screenshot",
|
|
66
|
+
"ui-automation",
|
|
67
|
+
"rpa",
|
|
68
|
+
"cordis"
|
|
69
|
+
],
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@deepseek-ai/cordis": ">=4.0.0 <5",
|
|
72
|
+
"@deepseek-ai/schemastery": ">=3.18.0 <4"
|
|
73
|
+
},
|
|
74
|
+
"peerDependenciesMeta": {
|
|
75
|
+
"@deepseek-ai/cordis": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"@deepseek-ai/schemastery": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@deepseek-ai/cordis": "4.0.4",
|
|
84
|
+
"@deepseek-ai/dsh-agent": "0.2.0-rc.2",
|
|
85
|
+
"@deepseek-ai/dsh-attachment": "0.2.0-rc.2",
|
|
86
|
+
"@deepseek-ai/dsh-llm": "0.2.0-rc.2",
|
|
87
|
+
"@deepseek-ai/dsh-session": "0.2.0-rc.2",
|
|
88
|
+
"@deepseek-ai/dsh-tools": "0.2.0-rc.2",
|
|
89
|
+
"@deepseek-ai/schemastery": "3.18.4",
|
|
90
|
+
"@types/node": "^22.20.0",
|
|
91
|
+
"tsdown": "^0.22.2",
|
|
92
|
+
"typescript": "^6.0.3",
|
|
93
|
+
"vitest": "^4.1.8"
|
|
94
|
+
},
|
|
95
|
+
"packageManager": "pnpm@10.28.0",
|
|
96
|
+
"publishConfig": {
|
|
97
|
+
"access": "public"
|
|
98
|
+
}
|
|
99
|
+
}
|