patchwork-os 1.2.0-beta.3.canary.919 → 1.2.0-beta.3.canary.920
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,12 +1,4 @@
|
|
|
1
1
|
import { type ExtensionClient } from "../extensionClient.js";
|
|
2
|
-
/**
|
|
3
|
-
* Upper bound on one native clipboard command. Without it a child that never
|
|
4
|
-
* exits (a cold or wedged PowerShell on a loaded Windows host, a clipboard
|
|
5
|
-
* held open by another process) left the tool call pending forever, so the
|
|
6
|
-
* MCP client got no reply at all. Linux may try two tools, so the worst case
|
|
7
|
-
* is twice this.
|
|
8
|
-
*/
|
|
9
|
-
export declare const NATIVE_CLIPBOARD_TIMEOUT_MS = 3000;
|
|
10
2
|
export declare function createReadClipboardTool(extensionClient: ExtensionClient): {
|
|
11
3
|
schema: {
|
|
12
4
|
name: string;
|
package/dist/tools/clipboard.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
2
3
|
import { ExtensionTimeoutError, } from "../extensionClient.js";
|
|
3
4
|
import { error, successStructured } from "./utils.js";
|
|
5
|
+
const execFileAsync = promisify(execFile);
|
|
4
6
|
const MAX_CLIPBOARD_BYTES = 100 * 1024; // 100 KB
|
|
5
7
|
const MAX_WRITE_BYTES = 1024 * 1024; // 1 MB (documented limit for writeClipboard)
|
|
6
|
-
/**
|
|
7
|
-
* Upper bound on one native clipboard command. Without it a child that never
|
|
8
|
-
* exits (a cold or wedged PowerShell on a loaded Windows host, a clipboard
|
|
9
|
-
* held open by another process) left the tool call pending forever, so the
|
|
10
|
-
* MCP client got no reply at all. Linux may try two tools, so the worst case
|
|
11
|
-
* is twice this.
|
|
12
|
-
*/
|
|
13
|
-
export const NATIVE_CLIPBOARD_TIMEOUT_MS = 3_000;
|
|
14
8
|
/**
|
|
15
9
|
* Truncate a string so that its UTF-8 byte length does not exceed `maxBytes`.
|
|
16
10
|
* String.slice() counts UTF-16 code units, not bytes, so for content with
|
|
@@ -29,41 +23,17 @@ function truncateToBytes(str, maxBytes) {
|
|
|
29
23
|
}
|
|
30
24
|
return str.slice(0, len);
|
|
31
25
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Run a native clipboard command, optionally piping `input` to stdin.
|
|
34
|
-
* Rejects (and kills the child) after NATIVE_CLIPBOARD_TIMEOUT_MS. The bound
|
|
35
|
-
* is our own timer rather than execFile's `timeout` option, because that
|
|
36
|
-
* option only settles once the killed child actually exits.
|
|
37
|
-
*/
|
|
38
|
-
function runNative(cmd, args, input) {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
let timer;
|
|
41
|
-
const proc = execFile(cmd, args, { windowsHide: true }, (err, stdout) => {
|
|
42
|
-
clearTimeout(timer);
|
|
43
|
-
if (err)
|
|
44
|
-
reject(err);
|
|
45
|
-
else
|
|
46
|
-
resolve(String(stdout));
|
|
47
|
-
});
|
|
48
|
-
timer = setTimeout(() => {
|
|
49
|
-
proc.kill();
|
|
50
|
-
reject(new Error(`${cmd} timed out`));
|
|
51
|
-
}, NATIVE_CLIPBOARD_TIMEOUT_MS);
|
|
52
|
-
if (input !== undefined)
|
|
53
|
-
proc.stdin?.end(input);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
26
|
/** Read clipboard text using platform-native CLI tools. */
|
|
57
27
|
async function nativeReadClipboard() {
|
|
58
28
|
try {
|
|
59
29
|
if (process.platform === "darwin") {
|
|
60
|
-
const stdout = await
|
|
30
|
+
const { stdout } = await execFileAsync("pbpaste");
|
|
61
31
|
return truncateToBytes(stdout, MAX_CLIPBOARD_BYTES);
|
|
62
32
|
}
|
|
63
33
|
if (process.platform === "linux") {
|
|
64
34
|
// xclip preferred; fall back to xsel
|
|
65
35
|
try {
|
|
66
|
-
const stdout = await
|
|
36
|
+
const { stdout } = await execFileAsync("xclip", [
|
|
67
37
|
"-selection",
|
|
68
38
|
"clipboard",
|
|
69
39
|
"-o",
|
|
@@ -71,12 +41,15 @@ async function nativeReadClipboard() {
|
|
|
71
41
|
return truncateToBytes(stdout, MAX_CLIPBOARD_BYTES);
|
|
72
42
|
}
|
|
73
43
|
catch {
|
|
74
|
-
const stdout = await
|
|
44
|
+
const { stdout } = await execFileAsync("xsel", [
|
|
45
|
+
"--clipboard",
|
|
46
|
+
"--output",
|
|
47
|
+
]);
|
|
75
48
|
return truncateToBytes(stdout, MAX_CLIPBOARD_BYTES);
|
|
76
49
|
}
|
|
77
50
|
}
|
|
78
51
|
if (process.platform === "win32") {
|
|
79
|
-
const stdout = await
|
|
52
|
+
const { stdout } = await execFileAsync("powershell", [
|
|
80
53
|
"-NoProfile",
|
|
81
54
|
"-Command",
|
|
82
55
|
"Get-Clipboard",
|
|
@@ -85,7 +58,7 @@ async function nativeReadClipboard() {
|
|
|
85
58
|
}
|
|
86
59
|
}
|
|
87
60
|
catch {
|
|
88
|
-
// tool not available
|
|
61
|
+
// tool not available or clipboard empty
|
|
89
62
|
}
|
|
90
63
|
return null;
|
|
91
64
|
}
|
|
@@ -93,26 +66,38 @@ async function nativeReadClipboard() {
|
|
|
93
66
|
async function nativeWriteClipboard(text) {
|
|
94
67
|
try {
|
|
95
68
|
if (process.platform === "darwin") {
|
|
96
|
-
await
|
|
69
|
+
await new Promise((resolve, reject) => {
|
|
70
|
+
const proc = execFile("pbcopy", (err) => err ? reject(err) : resolve());
|
|
71
|
+
proc.stdin?.end(text);
|
|
72
|
+
});
|
|
97
73
|
return true;
|
|
98
74
|
}
|
|
99
75
|
if (process.platform === "linux") {
|
|
76
|
+
const writeVia = async (cmd, args) => {
|
|
77
|
+
await new Promise((resolve, reject) => {
|
|
78
|
+
const proc = execFile(cmd, args, (err) => err ? reject(err) : resolve());
|
|
79
|
+
proc.stdin?.end(text);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
100
82
|
try {
|
|
101
|
-
await
|
|
83
|
+
await writeVia("xclip", ["-selection", "clipboard"]);
|
|
102
84
|
}
|
|
103
85
|
catch {
|
|
104
|
-
await
|
|
86
|
+
await writeVia("xsel", ["--clipboard", "--input"]);
|
|
105
87
|
}
|
|
106
88
|
return true;
|
|
107
89
|
}
|
|
108
90
|
if (process.platform === "win32") {
|
|
109
|
-
|
|
110
|
-
|
|
91
|
+
await new Promise((resolve, reject) => {
|
|
92
|
+
// Use clip.exe — ships with all Windows versions
|
|
93
|
+
const proc = execFile("clip", (err) => (err ? reject(err) : resolve()));
|
|
94
|
+
proc.stdin?.end(text);
|
|
95
|
+
});
|
|
111
96
|
return true;
|
|
112
97
|
}
|
|
113
98
|
}
|
|
114
99
|
catch {
|
|
115
|
-
// tool not available
|
|
100
|
+
// tool not available
|
|
116
101
|
}
|
|
117
102
|
return false;
|
|
118
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../../src/tools/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAEL,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,mBAAmB,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,SAAS;AACjD,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,6CAA6C;AAElF;;;;;;GAMG;AACH,
|
|
1
|
+
{"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../../src/tools/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAEL,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,aAAa,GAAG,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,wBAAwB,CAC7B,CAAC;wBACJ,CAAC;oBACH,CAAC;gBACH,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,IAAI,CAAC,CAAC,GAAG,YAAY,qBAAqB,CAAC;wBAAE,MAAM,GAAG,CAAC;gBACzD,CAAC;YACH,CAAC;YACD,oDAAoD;YACpD,MAAM,EAAE,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,CAAC,EAAE;gBACL,OAAO,KAAK,CACV,4FAA4F,CAC7F,CAAC;YACJ,OAAO,iBAAiB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "patchwork-os",
|
|
3
|
-
"version": "1.2.0-beta.3.canary.
|
|
3
|
+
"version": "1.2.0-beta.3.canary.920",
|
|
4
4
|
"description": "Your personal AI runtime, local-first. Patchwork OS gives any AI model a consistent set of tools, YAML recipes, a delegation policy with approval queue, and a durable trace memory — all on your machine, all under your policy.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|