@edlsh/cua-core 0.0.0-stage → 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 +18 -2
- package/dist/config.d.ts +14 -0
- package/dist/config.js +78 -0
- package/dist/desktop.d.ts +49 -0
- package/dist/desktop.js +607 -0
- package/dist/driver.d.ts +59 -0
- package/dist/driver.js +339 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/jev.d.ts +65 -0
- package/dist/jev.js +288 -0
- package/dist/render.d.ts +43 -0
- package/dist/render.js +244 -0
- package/dist/schema.d.ts +413 -0
- package/dist/schema.js +86 -0
- package/package.json +63 -4
- package/skills/desktop/SKILL.md +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Enzo Lucchesi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @edlsh/cua-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Host-neutral macOS desktop automation core backed by the [cua-driver](https://github.com/trycua/cua) `CuaDriver.app` daemon (`@trycua/cua-driver` 0.64.2), shared by `@edlsh/pi-cua` and `@edlsh/omp-cua`.
|
|
4
|
+
|
|
5
|
+
## What lives here
|
|
6
|
+
|
|
7
|
+
- `driver`: shared daemon connection management, automatic reconnect and stale-cache clearing, dynamic `listToolsJson()` schema/session discovery, `since` diff snapshot reconciliation, and macOS `/usr/bin/sips` JPEG screenshot compression.
|
|
8
|
+
- `render`: compact accessibility tree normalization, AppKit custom-action collapsing, `AXSecureTextField` + `is_password` redaction, range-value injection, menu-bar folding, diff rendering, `health_report` formatting, and context screenshot pruning.
|
|
9
|
+
- `schema`: strict Zod input schemas for `desktop_observe`, `desktop_act`, and `desktop_driver`.
|
|
10
|
+
- `jev`: privacy-filtered desktop candidate extraction, multi-chunk tournament targeting, hedged Vercel AI Gateway chooser, and Cloudflare Workers AI chooser.
|
|
11
|
+
- `config`: declarative `<agentDir>/cua.json` loader with `"!command"` credential resolvers.
|
|
12
|
+
- `desktop`: host-neutral `createDesktopCore(adapter, options)` tool/command/event registration factory.
|
|
13
|
+
|
|
14
|
+
## Development
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
bun install --frozen-lockfile --ignore-scripts
|
|
18
|
+
bun run check # typecheck, unit tests, dist build, and package verification
|
|
19
|
+
```
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { CloudflareCredentials } from "./jev.ts";
|
|
3
|
+
declare const configuration: z.ZodObject<{
|
|
4
|
+
jevClassifier: z.ZodOptional<z.ZodString>;
|
|
5
|
+
jevApiKey: z.ZodOptional<z.ZodString>;
|
|
6
|
+
cloudflareAccountId: z.ZodOptional<z.ZodString>;
|
|
7
|
+
cloudflareApiKey: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, z.core.$strict>;
|
|
9
|
+
export type CuaFileConfig = z.infer<typeof configuration>;
|
|
10
|
+
export declare function defaultAgentDir(host: "omp" | "pi"): string;
|
|
11
|
+
export declare function readCuaConfig(agentDir: string, signal?: AbortSignal): Promise<CuaFileConfig>;
|
|
12
|
+
export declare function resolveFileJevKey(agentDir: string, signal?: AbortSignal): Promise<string | undefined>;
|
|
13
|
+
export declare function resolveFileCloudflare(agentDir: string, signal?: AbortSignal): Promise<CloudflareCredentials | undefined>;
|
|
14
|
+
export {};
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
|
+
// Credentials are "!command" values whose stdout is the secret, so literal keys never sit in cua.json.
|
|
9
|
+
const command = z.string().regex(/^!\S/, 'must be a "!command" that prints the credential; keep literal keys out of cua.json');
|
|
10
|
+
const configuration = z.object({
|
|
11
|
+
jevClassifier: z.string().min(1).optional(),
|
|
12
|
+
jevApiKey: command.optional(),
|
|
13
|
+
cloudflareAccountId: z.string().min(1).optional(),
|
|
14
|
+
cloudflareApiKey: command.optional(),
|
|
15
|
+
}).strict();
|
|
16
|
+
// One execution per command for the process lifetime; a failed command is forgotten so the next call retries.
|
|
17
|
+
const credentials = new Map();
|
|
18
|
+
/** Runs a "!command" credential resolver. Neither stdout nor stderr is echoed on error. */
|
|
19
|
+
async function runCredential(field, value) {
|
|
20
|
+
if (!value)
|
|
21
|
+
return undefined;
|
|
22
|
+
let pending = credentials.get(value);
|
|
23
|
+
if (!pending) {
|
|
24
|
+
pending = execFileAsync("/bin/sh", ["-c", value.slice(1)], { timeout: 10_000, encoding: "utf8", maxBuffer: 16_384 })
|
|
25
|
+
.then(({ stdout }) => {
|
|
26
|
+
const key = stdout.trim();
|
|
27
|
+
if (!key)
|
|
28
|
+
throw new Error("empty");
|
|
29
|
+
return key;
|
|
30
|
+
})
|
|
31
|
+
.catch(() => { throw new Error(`The ${field} command in cua.json failed or printed nothing.`); });
|
|
32
|
+
credentials.set(value, pending);
|
|
33
|
+
pending.catch(() => credentials.delete(value));
|
|
34
|
+
}
|
|
35
|
+
return pending;
|
|
36
|
+
}
|
|
37
|
+
export function defaultAgentDir(host) {
|
|
38
|
+
if (host === "omp")
|
|
39
|
+
return process.env.OMP_CODING_AGENT_DIR?.trim() || join(homedir(), ".omp", "agent");
|
|
40
|
+
return process.env.PI_CODING_AGENT_DIR?.trim() || join(homedir(), ".pi", "agent");
|
|
41
|
+
}
|
|
42
|
+
export async function readCuaConfig(agentDir, signal) {
|
|
43
|
+
const path = join(agentDir, "cua.json");
|
|
44
|
+
let raw;
|
|
45
|
+
try {
|
|
46
|
+
raw = await readFile(path, { encoding: "utf8", signal });
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error.code === "ENOENT")
|
|
50
|
+
return {};
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
let parsedJson;
|
|
54
|
+
try {
|
|
55
|
+
parsedJson = JSON.parse(raw);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
throw new Error(`Invalid JSON in ${path}`);
|
|
59
|
+
}
|
|
60
|
+
const parsed = configuration.safeParse(parsedJson);
|
|
61
|
+
if (!parsed.success)
|
|
62
|
+
throw new Error(`Invalid settings in ${path}: ${z.prettifyError(parsed.error)}`);
|
|
63
|
+
return parsed.data;
|
|
64
|
+
}
|
|
65
|
+
export async function resolveFileJevKey(agentDir, signal) {
|
|
66
|
+
const file = await readCuaConfig(agentDir, signal);
|
|
67
|
+
return runCredential("jevApiKey", file.jevApiKey);
|
|
68
|
+
}
|
|
69
|
+
export async function resolveFileCloudflare(agentDir, signal) {
|
|
70
|
+
const file = await readCuaConfig(agentDir, signal);
|
|
71
|
+
if (!file.cloudflareApiKey)
|
|
72
|
+
return undefined;
|
|
73
|
+
const accountId = (file.cloudflareAccountId ?? process.env.CLOUDFLARE_ACCOUNT_ID)?.trim();
|
|
74
|
+
if (!accountId)
|
|
75
|
+
return undefined;
|
|
76
|
+
const apiKey = await runCredential("cloudflareApiKey", file.cloudflareApiKey);
|
|
77
|
+
return apiKey ? { accountId, apiKey } : undefined;
|
|
78
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type CloudflareCredentials } from "./jev.ts";
|
|
2
|
+
export declare const JEV_PROMPT = "Desktop JEV mode is on: desktop_act click/double_click/right_click/type/set_value/scroll steps accept `target`, a plain-language control description such as \"Save button in the toolbar\", instead of index, so you can act without observing first. If a step fails with jev_uncertain, retry with one of the listed indices; with jev_none or jev_no_candidates, read the returned state; with jev_needs_index, pass the index only if the destructive action is intended.";
|
|
3
|
+
export interface DesktopOptions {
|
|
4
|
+
/** Supplies the Vercel AI Gateway key for JEV when AI_GATEWAY_API_KEY is unset. Called on first JEV use. */
|
|
5
|
+
jevApiKey?: () => Promise<string | undefined>;
|
|
6
|
+
/** Supplies Cloudflare Workers AI credentials for JEV when env vars are unset. */
|
|
7
|
+
cloudflare?: () => Promise<CloudflareCredentials | undefined>;
|
|
8
|
+
/** JEV classifier backend: "vercel" (default), "workers-ai", or "workers-ai/<model>". */
|
|
9
|
+
jevClassifier?: string;
|
|
10
|
+
/** Profile directory containing cua.json. */
|
|
11
|
+
agentDir?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface DesktopContext {
|
|
14
|
+
sessionManager: {
|
|
15
|
+
getSessionId(): string;
|
|
16
|
+
};
|
|
17
|
+
hasUI: boolean;
|
|
18
|
+
ui: {
|
|
19
|
+
notify(message: string, level?: "info" | "warning" | "error"): void;
|
|
20
|
+
setStatus(key: string, text: string | undefined): void;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface DesktopResult {
|
|
24
|
+
content: ({
|
|
25
|
+
type: "text";
|
|
26
|
+
text: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: "image";
|
|
29
|
+
data: string;
|
|
30
|
+
mimeType: string;
|
|
31
|
+
})[];
|
|
32
|
+
details: Record<string, unknown>;
|
|
33
|
+
isError?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface DesktopHostAdapter {
|
|
36
|
+
packageName: string;
|
|
37
|
+
sessionPrefix: string;
|
|
38
|
+
profileEnvVar: string;
|
|
39
|
+
defaultAgentDirHost: "omp" | "pi";
|
|
40
|
+
connectionSymbol: string;
|
|
41
|
+
desktopPrompt: string;
|
|
42
|
+
normalizeToolArguments?: (input: unknown) => unknown;
|
|
43
|
+
toolMeta?: (name: "desktop_observe" | "desktop_act" | "desktop_driver") => Record<string, unknown>;
|
|
44
|
+
appendSystemPrompt: (event: any, lines: string[]) => any;
|
|
45
|
+
hasSessionSwitch?: boolean;
|
|
46
|
+
resolveAgentDir?: (api: any) => string | undefined;
|
|
47
|
+
}
|
|
48
|
+
export declare function formatSessionLabel(prefix: string, sessionId: string, profile: string): string;
|
|
49
|
+
export declare function createDesktopCore(adapter: DesktopHostAdapter, options?: DesktopOptions): (pi: any) => void;
|