zcode-app-cli 3.3.5-1
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 +24 -0
- package/README.md +642 -0
- package/bin/zcode.js +848 -0
- package/config.example.json +110 -0
- package/package.json +81 -0
- package/vendor/.node-bundle-meta.json +6 -0
- package/vendor/extraction.json +11 -0
- package/vendor/node_modules/@zcode/tui/dist/index.js +161875 -0
- package/vendor/node_modules/@zcode/tui/package.json +14 -0
- package/vendor/packages/android-emulator-plugin/.mcp.json +19 -0
- package/vendor/packages/android-emulator-plugin/.zcode-plugin/plugin.json +63 -0
- package/vendor/packages/android-emulator-plugin/README.md +134 -0
- package/vendor/packages/android-emulator-plugin/commands/android-dev.md +11 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/path.d.ts +4 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/path.js +17 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/result.d.ts +5 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/result.js +22 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/run.d.ts +18 -0
- package/vendor/packages/android-emulator-plugin/dist/lib/run.js +99 -0
- package/vendor/packages/android-emulator-plugin/dist/mcp/server.d.ts +3 -0
- package/vendor/packages/android-emulator-plugin/dist/mcp/server.js +47607 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/app.d.ts +39 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/app.js +50 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/avd.d.ts +37 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/avd.js +185 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/build.d.ts +68 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/build.js +131 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/config.d.ts +7 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/config.js +29 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/device.d.ts +20 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/device.js +91 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/logs.d.ts +15 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/logs.js +31 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/preflight.d.ts +15 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/preflight.js +123 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project-template.d.ts +13 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project-template.js +211 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project.d.ts +33 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/project.js +195 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.d.ts +14 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.js +73 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/sdk.d.ts +14 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/sdk.js +185 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/ui.d.ts +92 -0
- package/vendor/packages/android-emulator-plugin/dist/providers/ui.js +146 -0
- package/vendor/packages/android-emulator-plugin/hooks/hooks.json +3 -0
- package/vendor/packages/android-emulator-plugin/package.json +35 -0
- package/vendor/packages/android-emulator-plugin/skills/android-dev/INSTALL_ENVIRONMENT.md +357 -0
- package/vendor/packages/android-emulator-plugin/skills/android-dev/SKILL.md +73 -0
- package/vendor/packages/android-emulator-plugin/templates/compose-app/README.md +5 -0
- package/vendor/packages/document-skills-plugin/.zcode-plugin/plugin.json +8 -0
- package/vendor/packages/document-skills-plugin/package.json +8 -0
- package/vendor/packages/document-skills-plugin/skills/docx/LICENSE.txt +13 -0
- package/vendor/packages/document-skills-plugin/skills/docx/SKILL.md +201 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/chart-templates.md +386 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/common-rules.md +419 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/decorations.md +537 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/design-system.md +1797 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-advanced.md +257 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-core.md +332 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/faq.md +323 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/math-formulas.md +276 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/ooxml.md +222 -0
- package/vendor/packages/document-skills-plugin/skills/docx/references/toc.md +264 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/comment.md +88 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/create.md +207 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/edit.md +115 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/format.md +120 -0
- package/vendor/packages/document-skills-plugin/skills/docx/routes/read.md +114 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/academic.md +783 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/contract.md +463 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/copywriting.md +139 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/exam.md +698 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/official-doc.md +411 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/report.md +340 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scenes/resume.md +534 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/__init__.py +1 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/add_toc_placeholders.py +749 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/document.py +1333 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/postcheck.py +807 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/comments.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtended.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsIds.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/people.xml +3 -0
- package/vendor/packages/document-skills-plugin/skills/docx/scripts/utilities.py +374 -0
- package/vendor/packages/document-skills-plugin/skills/docx/setup.sh +177 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/LICENSE.txt +13 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/SKILL.md +919 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/academic.md +1058 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/creative.md +770 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/poster.md +702 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process-advanced.md +284 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process.md +319 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/briefs/report.md +1659 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/configs/components.md +153 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/configs/fonts.md +93 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/configs/visual_framework.md +263 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-academic.tex +130 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-altacv.tex +190 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/cover_validate.js +367 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/design_engine.py +2816 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2pdf-next.js +754 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2poster.js +256 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf.py +2959 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf_qa.py +901 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/poster_validate.py +1337 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/setup.sh +269 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/scripts/toc_validate.py +2075 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/charts.md +320 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover-backgrounds.md +384 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover.md +1442 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/fill-engine.md +527 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/geometry.md +142 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/overflow.md +630 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/pagination.md +367 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/palette.md +217 -0
- package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/typography.md +20 -0
- package/vendor/packages/ios-simulator-plugin/.mcp.json +15 -0
- package/vendor/packages/ios-simulator-plugin/.zcode-plugin/plugin.json +34 -0
- package/vendor/packages/ios-simulator-plugin/README.md +111 -0
- package/vendor/packages/ios-simulator-plugin/commands/ios-dev.md +11 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/path.d.ts +4 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/path.js +18 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/result.d.ts +5 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/result.js +20 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/run.d.ts +17 -0
- package/vendor/packages/ios-simulator-plugin/dist/lib/run.js +83 -0
- package/vendor/packages/ios-simulator-plugin/dist/mcp/server.d.ts +3 -0
- package/vendor/packages/ios-simulator-plugin/dist/mcp/server.js +46833 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/build.d.ts +112 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/build.js +99 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/logs.d.ts +21 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/logs.js +26 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.d.ts +12 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.js +62 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/project.d.ts +35 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/project.js +288 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.d.ts +22 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.js +30 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/sim.d.ts +60 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/sim.js +116 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/ui.d.ts +57 -0
- package/vendor/packages/ios-simulator-plugin/dist/providers/ui.js +67 -0
- package/vendor/packages/ios-simulator-plugin/hooks/hooks.json +3 -0
- package/vendor/packages/ios-simulator-plugin/package.json +35 -0
- package/vendor/packages/ios-simulator-plugin/skills/ios-dev/SKILL.md +45 -0
- package/vendor/packages/ios-simulator-plugin/templates/swiftui-app/README.md +5 -0
- package/vendor/packages/restore-legacy-sessions-plugin/.zcode-plugin/plugin.json +9 -0
- package/vendor/packages/restore-legacy-sessions-plugin/README.md +35 -0
- package/vendor/packages/restore-legacy-sessions-plugin/commands/restore-legacy-sessions.md +11 -0
- package/vendor/packages/restore-legacy-sessions-plugin/package.json +8 -0
- package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/SKILL.md +92 -0
- package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/restore-conversation.mjs +648 -0
- package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/scan-legacy-sessions.mjs +422 -0
- package/vendor/packages/skill-creator-plugin/.zcode-plugin/plugin.json +8 -0
- package/vendor/packages/skill-creator-plugin/package.json +8 -0
- package/vendor/packages/skill-creator-plugin/skills/skill-creator/SKILL.md +159 -0
- package/vendor/packages/zcode-guide-plugin/.zcode-plugin/plugin.json +8 -0
- package/vendor/packages/zcode-guide-plugin/README.md +22 -0
- package/vendor/packages/zcode-guide-plugin/package.json +8 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-commands/SKILL.md +66 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-hooks/SKILL.md +66 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-mcp/SKILL.md +97 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-plugins/SKILL.md +59 -0
- package/vendor/packages/zcode-guide-plugin/skills/diagnosing-skills/SKILL.md +61 -0
- package/vendor/packages/zcode-guide-plugin/skills/zcode-configuration-guide/SKILL.md +99 -0
- package/vendor/zcode.cjs +2926 -0
- package/zcode-runtime.lock.json +8 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { spawn as spawnChild } from "node:child_process";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { data, inside, rel } from "../lib/path.js";
|
|
5
|
+
import { ensureDevice } from "./avd.js";
|
|
6
|
+
import { androidEnv, requireTool } from "./sdk.js";
|
|
7
|
+
export async function shot(input = {}) {
|
|
8
|
+
const device = await ensureDevice(input);
|
|
9
|
+
const file = input.path
|
|
10
|
+
? inside(process.cwd(), input.path)
|
|
11
|
+
: path.join(await data("screenshots"), `${stamp()}-${device.serial}.png`);
|
|
12
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
13
|
+
const bytes = await screencap(device.serial, input.timeoutMs ?? 30_000);
|
|
14
|
+
await writeFile(file, bytes);
|
|
15
|
+
return {
|
|
16
|
+
device,
|
|
17
|
+
path: rel(file),
|
|
18
|
+
bytes: bytes.byteLength,
|
|
19
|
+
data: Buffer.from(bytes).toString("base64"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async function screencap(serial, timeoutMs) {
|
|
23
|
+
const adb = await requireTool("adb");
|
|
24
|
+
const env = await androidEnv();
|
|
25
|
+
const child = spawnChild(adb, ["-s", serial, "exec-out", "screencap", "-p"], {
|
|
26
|
+
env: Object.fromEntries(Object.entries({ ...process.env, ...env }).filter((item) => typeof item[1] === "string")),
|
|
27
|
+
shell: false,
|
|
28
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
29
|
+
});
|
|
30
|
+
let timed = false;
|
|
31
|
+
let spawnError;
|
|
32
|
+
const timer = setTimeout(() => {
|
|
33
|
+
timed = true;
|
|
34
|
+
child.kill("SIGTERM");
|
|
35
|
+
}, timeoutMs);
|
|
36
|
+
const out = collectBuffer(child.stdout);
|
|
37
|
+
const err = collectText(child.stderr);
|
|
38
|
+
const code = await new Promise((resolve) => {
|
|
39
|
+
let settled = false;
|
|
40
|
+
const settle = (exitCode) => {
|
|
41
|
+
if (settled)
|
|
42
|
+
return;
|
|
43
|
+
settled = true;
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
resolve(exitCode);
|
|
46
|
+
};
|
|
47
|
+
child.once("error", (error) => {
|
|
48
|
+
spawnError = error instanceof Error ? error : new Error(String(error));
|
|
49
|
+
settle(127);
|
|
50
|
+
});
|
|
51
|
+
child.once("close", (exitCode) => settle(exitCode ?? 1));
|
|
52
|
+
});
|
|
53
|
+
if (code !== 0 || timed) {
|
|
54
|
+
const stderr = [await err, spawnError?.message].filter(Boolean).join("\n").trim();
|
|
55
|
+
throw new Error(stderr || `screencap failed with exit ${code}${timed ? " after timeout" : ""}`);
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
async function collectBuffer(stream) {
|
|
60
|
+
if (!stream)
|
|
61
|
+
return Buffer.alloc(0);
|
|
62
|
+
const chunks = [];
|
|
63
|
+
for await (const chunk of stream) {
|
|
64
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
65
|
+
}
|
|
66
|
+
return Buffer.concat(chunks);
|
|
67
|
+
}
|
|
68
|
+
async function collectText(stream) {
|
|
69
|
+
return (await collectBuffer(stream)).toString("utf8");
|
|
70
|
+
}
|
|
71
|
+
function stamp() {
|
|
72
|
+
return new Date().toISOString().replaceAll(/[:.]/g, "-");
|
|
73
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type ToolCheck = {
|
|
2
|
+
name: string;
|
|
3
|
+
path?: string;
|
|
4
|
+
ok: boolean;
|
|
5
|
+
detail: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function sdkRoot(): Promise<string | undefined>;
|
|
8
|
+
export declare function findTool(name: string): Promise<string | undefined>;
|
|
9
|
+
export declare function requireTool(name: string): Promise<string>;
|
|
10
|
+
export declare function checkTool(name: string, versionArgs?: string[]): Promise<ToolCheck>;
|
|
11
|
+
export declare function androidEnv(): Promise<Record<string, string | undefined>>;
|
|
12
|
+
export declare function javaHome(): Promise<string | undefined>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { access, readdir } from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { brief, ok, run } from "../lib/run.js";
|
|
5
|
+
import { javaMajorVersion } from "./config.js";
|
|
6
|
+
const TOOL_PATHS = {
|
|
7
|
+
adb: ["platform-tools/adb"],
|
|
8
|
+
emulator: ["emulator/emulator"],
|
|
9
|
+
sdkmanager: [
|
|
10
|
+
"cmdline-tools/latest/bin/sdkmanager",
|
|
11
|
+
"cmdline-tools/bin/sdkmanager",
|
|
12
|
+
"tools/bin/sdkmanager",
|
|
13
|
+
],
|
|
14
|
+
avdmanager: [
|
|
15
|
+
"cmdline-tools/latest/bin/avdmanager",
|
|
16
|
+
"cmdline-tools/bin/avdmanager",
|
|
17
|
+
"tools/bin/avdmanager",
|
|
18
|
+
],
|
|
19
|
+
apkanalyzer: ["cmdline-tools/latest/bin/apkanalyzer", "cmdline-tools/bin/apkanalyzer"],
|
|
20
|
+
};
|
|
21
|
+
function sdkRoots(env = process.env) {
|
|
22
|
+
const configured = [env.ANDROID_PLUGIN_SDK_PATH, env.ANDROID_HOME, env.ANDROID_SDK_ROOT].filter((item) => Boolean(item && item.trim()));
|
|
23
|
+
return unique([
|
|
24
|
+
...configured,
|
|
25
|
+
path.join(os.homedir(), "Library", "Android", "sdk"),
|
|
26
|
+
path.join(os.homedir(), "Android", "Sdk"),
|
|
27
|
+
...windowsSdkRoots(env),
|
|
28
|
+
"/opt/android-sdk",
|
|
29
|
+
"/usr/local/share/android-sdk",
|
|
30
|
+
"/opt/homebrew/share/android-commandlinetools",
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
export async function sdkRoot() {
|
|
34
|
+
for (const item of sdkRoots()) {
|
|
35
|
+
if (await exists(item))
|
|
36
|
+
return item;
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
export async function findTool(name) {
|
|
41
|
+
const viaPath = await which(name);
|
|
42
|
+
if (viaPath)
|
|
43
|
+
return viaPath;
|
|
44
|
+
const rels = TOOL_PATHS[name] ?? [];
|
|
45
|
+
for (const root of sdkRoots()) {
|
|
46
|
+
for (const rel of rels) {
|
|
47
|
+
for (const candidate of executableCandidates(path.join(root, rel))) {
|
|
48
|
+
if (await exists(candidate))
|
|
49
|
+
return candidate;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
export async function requireTool(name) {
|
|
56
|
+
const found = await findTool(name);
|
|
57
|
+
if (found)
|
|
58
|
+
return found;
|
|
59
|
+
throw new Error(`Missing Android tool: ${name}. Run android_preflight for setup details.`);
|
|
60
|
+
}
|
|
61
|
+
export async function checkTool(name, versionArgs = ["--version"]) {
|
|
62
|
+
const found = await findTool(name);
|
|
63
|
+
if (!found) {
|
|
64
|
+
return {
|
|
65
|
+
name,
|
|
66
|
+
ok: false,
|
|
67
|
+
detail: "not found",
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const out = await run([found, ...versionArgs], { timeout: 10_000, env: await androidEnv() });
|
|
71
|
+
return {
|
|
72
|
+
name,
|
|
73
|
+
path: found,
|
|
74
|
+
ok: ok(out),
|
|
75
|
+
detail: ok(out) ? brief(out, 1000) || found : brief(out, 1000),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export async function androidEnv() {
|
|
79
|
+
const root = await sdkRoot();
|
|
80
|
+
const java = await javaHome();
|
|
81
|
+
const paths = [
|
|
82
|
+
java ? path.join(java, "bin") : undefined,
|
|
83
|
+
root ? path.join(root, "platform-tools") : undefined,
|
|
84
|
+
root ? path.join(root, "emulator") : undefined,
|
|
85
|
+
root ? path.join(root, "cmdline-tools", "latest", "bin") : undefined,
|
|
86
|
+
root ? path.join(root, "cmdline-tools", "bin") : undefined,
|
|
87
|
+
root ? path.join(root, "tools", "bin") : undefined,
|
|
88
|
+
process.env.PATH,
|
|
89
|
+
].filter((item) => Boolean(item));
|
|
90
|
+
return {
|
|
91
|
+
JAVA_HOME: java,
|
|
92
|
+
ANDROID_HOME: root,
|
|
93
|
+
ANDROID_SDK_ROOT: root,
|
|
94
|
+
PATH: paths.join(path.delimiter),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export async function javaHome() {
|
|
98
|
+
const version = javaMajorVersion();
|
|
99
|
+
const configured = process.env.JAVA_HOME?.trim();
|
|
100
|
+
if (configured && (await exists(path.join(configured, "bin", javaBin()))))
|
|
101
|
+
return configured;
|
|
102
|
+
if (process.platform === "darwin") {
|
|
103
|
+
const home = await run(["/usr/libexec/java_home", "-v", version], { timeout: 5000 });
|
|
104
|
+
if (ok(home)) {
|
|
105
|
+
const value = home.stdout.trim();
|
|
106
|
+
if (value)
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
for (const candidate of await javaHomes(version)) {
|
|
111
|
+
if (await exists(path.join(candidate, "bin", javaBin())))
|
|
112
|
+
return candidate;
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
async function which(name) {
|
|
117
|
+
const out = await run(process.platform === "win32" ? ["where", name] : ["which", name], {
|
|
118
|
+
timeout: 5000,
|
|
119
|
+
});
|
|
120
|
+
if (!ok(out))
|
|
121
|
+
return undefined;
|
|
122
|
+
const found = out.stdout.trim().split("\n")[0];
|
|
123
|
+
return found || undefined;
|
|
124
|
+
}
|
|
125
|
+
async function exists(file) {
|
|
126
|
+
return access(file)
|
|
127
|
+
.then(() => true)
|
|
128
|
+
.catch(() => false);
|
|
129
|
+
}
|
|
130
|
+
function unique(items) {
|
|
131
|
+
const seen = new Set();
|
|
132
|
+
const out = [];
|
|
133
|
+
for (const item of items) {
|
|
134
|
+
const resolved = path.resolve(item);
|
|
135
|
+
if (seen.has(resolved))
|
|
136
|
+
continue;
|
|
137
|
+
seen.add(resolved);
|
|
138
|
+
out.push(resolved);
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
function executableCandidates(base) {
|
|
143
|
+
if (process.platform !== "win32")
|
|
144
|
+
return [base];
|
|
145
|
+
const ext = path.extname(base);
|
|
146
|
+
if (ext)
|
|
147
|
+
return [base];
|
|
148
|
+
return [".exe", ".bat", ".cmd", ""].map((suffix) => `${base}${suffix}`);
|
|
149
|
+
}
|
|
150
|
+
function javaBin() {
|
|
151
|
+
return process.platform === "win32" ? "java.exe" : "java";
|
|
152
|
+
}
|
|
153
|
+
function windowsSdkRoots(env) {
|
|
154
|
+
return [
|
|
155
|
+
env.LOCALAPPDATA ? path.join(env.LOCALAPPDATA, "Android", "Sdk") : undefined,
|
|
156
|
+
path.join(os.homedir(), "AppData", "Local", "Android", "Sdk"),
|
|
157
|
+
].filter((item) => Boolean(item));
|
|
158
|
+
}
|
|
159
|
+
async function javaHomes(version) {
|
|
160
|
+
const fixed = [
|
|
161
|
+
`/opt/homebrew/opt/openjdk@${version}/libexec/openjdk.jdk/Contents/Home`,
|
|
162
|
+
`/Library/Java/JavaVirtualMachines/openjdk-${version}.jdk/Contents/Home`,
|
|
163
|
+
path.join(process.env.ProgramFiles || "", "Eclipse Adoptium", `jdk-${version}`),
|
|
164
|
+
path.join(process.env.ProgramFiles || "", "Java", `jdk-${version}`),
|
|
165
|
+
].filter(Boolean);
|
|
166
|
+
if (process.platform !== "win32")
|
|
167
|
+
return fixed;
|
|
168
|
+
const pattern = new RegExp(`^jdk-${escapeRegex(version)}`, "i");
|
|
169
|
+
return unique([
|
|
170
|
+
...fixed,
|
|
171
|
+
...(await childDirs(path.join(process.env.ProgramFiles || "", "Eclipse Adoptium"), pattern)),
|
|
172
|
+
...(await childDirs(path.join(process.env.ProgramFiles || "", "Java"), pattern)),
|
|
173
|
+
]);
|
|
174
|
+
}
|
|
175
|
+
async function childDirs(root, pattern) {
|
|
176
|
+
if (!root)
|
|
177
|
+
return [];
|
|
178
|
+
const items = await readdir(root, { withFileTypes: true }).catch(() => []);
|
|
179
|
+
return items
|
|
180
|
+
.filter((item) => item.isDirectory() && pattern.test(item.name))
|
|
181
|
+
.map((item) => path.join(root, item.name));
|
|
182
|
+
}
|
|
183
|
+
function escapeRegex(value) {
|
|
184
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
185
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
type UiTarget = {
|
|
2
|
+
serial?: string;
|
|
3
|
+
avd?: string;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
};
|
|
6
|
+
type UiElement = {
|
|
7
|
+
index: number;
|
|
8
|
+
text?: string;
|
|
9
|
+
contentDescription?: string;
|
|
10
|
+
resourceId?: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
bounds?: Bounds;
|
|
13
|
+
clickable?: boolean;
|
|
14
|
+
enabled?: boolean;
|
|
15
|
+
};
|
|
16
|
+
type Bounds = {
|
|
17
|
+
left: number;
|
|
18
|
+
top: number;
|
|
19
|
+
right: number;
|
|
20
|
+
bottom: number;
|
|
21
|
+
centerX: number;
|
|
22
|
+
centerY: number;
|
|
23
|
+
};
|
|
24
|
+
declare const KEY_EVENTS: {
|
|
25
|
+
readonly BACK: "KEYCODE_BACK";
|
|
26
|
+
readonly HOME: "KEYCODE_HOME";
|
|
27
|
+
readonly ENTER: "KEYCODE_ENTER";
|
|
28
|
+
readonly APP_SWITCH: "KEYCODE_APP_SWITCH";
|
|
29
|
+
readonly MENU: "KEYCODE_MENU";
|
|
30
|
+
readonly SEARCH: "KEYCODE_SEARCH";
|
|
31
|
+
};
|
|
32
|
+
export declare function status(): Promise<{
|
|
33
|
+
backend: string;
|
|
34
|
+
adb: string | undefined;
|
|
35
|
+
adbInput: boolean;
|
|
36
|
+
uiAutomator: boolean;
|
|
37
|
+
available: boolean;
|
|
38
|
+
implementedBackends: string[];
|
|
39
|
+
}>;
|
|
40
|
+
export declare function describe(input?: UiTarget): Promise<{
|
|
41
|
+
device: import("./device.js").Device;
|
|
42
|
+
elements: UiElement[];
|
|
43
|
+
}>;
|
|
44
|
+
export declare function resolve(input: UiTarget & {
|
|
45
|
+
query: string;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
device: import("./device.js").Device;
|
|
48
|
+
element: UiElement;
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
}>;
|
|
52
|
+
export declare function tap(input: UiTarget & {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
}): Promise<{
|
|
56
|
+
tapped: boolean;
|
|
57
|
+
serial: string;
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
}>;
|
|
61
|
+
export declare function swipe(input: UiTarget & {
|
|
62
|
+
x1: number;
|
|
63
|
+
y1: number;
|
|
64
|
+
x2: number;
|
|
65
|
+
y2: number;
|
|
66
|
+
durationMs?: number;
|
|
67
|
+
}): Promise<{
|
|
68
|
+
swiped: boolean;
|
|
69
|
+
serial: string;
|
|
70
|
+
x1: number;
|
|
71
|
+
y1: number;
|
|
72
|
+
x2: number;
|
|
73
|
+
y2: number;
|
|
74
|
+
}>;
|
|
75
|
+
export declare function typeText(input: UiTarget & {
|
|
76
|
+
text: string;
|
|
77
|
+
}): Promise<{
|
|
78
|
+
typed: boolean;
|
|
79
|
+
serial: string;
|
|
80
|
+
length: number;
|
|
81
|
+
}>;
|
|
82
|
+
export declare function keyevent(input: UiTarget & {
|
|
83
|
+
key: keyof typeof KEY_EVENTS;
|
|
84
|
+
}): Promise<{
|
|
85
|
+
pressed: boolean;
|
|
86
|
+
serial: string;
|
|
87
|
+
key: "BACK" | "HOME" | "ENTER" | "APP_SWITCH" | "MENU" | "SEARCH";
|
|
88
|
+
}>;
|
|
89
|
+
export declare function parseUiAutomator(value: string): UiElement[];
|
|
90
|
+
export declare function inputText(value: string): string;
|
|
91
|
+
export {};
|
|
92
|
+
//# sourceMappingURL=ui.d.ts.map
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ensureDevice } from "./avd.js";
|
|
2
|
+
import { adbShell } from "./device.js";
|
|
3
|
+
import { findTool } from "./sdk.js";
|
|
4
|
+
const KEY_EVENTS = {
|
|
5
|
+
BACK: "KEYCODE_BACK",
|
|
6
|
+
HOME: "KEYCODE_HOME",
|
|
7
|
+
ENTER: "KEYCODE_ENTER",
|
|
8
|
+
APP_SWITCH: "KEYCODE_APP_SWITCH",
|
|
9
|
+
MENU: "KEYCODE_MENU",
|
|
10
|
+
SEARCH: "KEYCODE_SEARCH",
|
|
11
|
+
};
|
|
12
|
+
const MAX_INPUT_TEXT_LENGTH = 1000;
|
|
13
|
+
export async function status() {
|
|
14
|
+
const adb = await findTool("adb");
|
|
15
|
+
const adbAvailable = Boolean(adb);
|
|
16
|
+
return {
|
|
17
|
+
backend: "adb-uiautomator",
|
|
18
|
+
adb,
|
|
19
|
+
adbInput: adbAvailable,
|
|
20
|
+
uiAutomator: adbAvailable,
|
|
21
|
+
available: adbAvailable,
|
|
22
|
+
implementedBackends: adbAvailable ? ["uiautomator", "adb-input"] : [],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export async function describe(input = {}) {
|
|
26
|
+
const device = await ensureDevice(input);
|
|
27
|
+
await adbShell(device.serial, ["uiautomator", "dump", "/sdcard/window.xml"], input.timeoutMs ?? 30_000);
|
|
28
|
+
const out = await adbShell(device.serial, ["cat", "/sdcard/window.xml"], input.timeoutMs ?? 30_000);
|
|
29
|
+
const elements = parseUiAutomator(out.stdout);
|
|
30
|
+
return { device, elements };
|
|
31
|
+
}
|
|
32
|
+
export async function resolve(input) {
|
|
33
|
+
const tree = await describe(input);
|
|
34
|
+
const query = input.query.trim().toLowerCase();
|
|
35
|
+
if (!query)
|
|
36
|
+
throw new Error("UI query must not be empty.");
|
|
37
|
+
const hit = tree.elements.find((item) => elementText(item).toLowerCase().includes(query) && item.bounds);
|
|
38
|
+
if (!hit?.bounds)
|
|
39
|
+
throw new Error(`No visible Android UI element matched: ${input.query}`);
|
|
40
|
+
return {
|
|
41
|
+
device: tree.device,
|
|
42
|
+
element: hit,
|
|
43
|
+
x: hit.bounds.centerX,
|
|
44
|
+
y: hit.bounds.centerY,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export async function tap(input) {
|
|
48
|
+
const device = await ensureDevice(input);
|
|
49
|
+
await adbShell(device.serial, ["input", "tap", String(Math.round(input.x)), String(Math.round(input.y))], input.timeoutMs ?? 30_000);
|
|
50
|
+
return { tapped: true, serial: device.serial, x: input.x, y: input.y };
|
|
51
|
+
}
|
|
52
|
+
export async function swipe(input) {
|
|
53
|
+
const device = await ensureDevice(input);
|
|
54
|
+
await adbShell(device.serial, [
|
|
55
|
+
"input",
|
|
56
|
+
"swipe",
|
|
57
|
+
String(Math.round(input.x1)),
|
|
58
|
+
String(Math.round(input.y1)),
|
|
59
|
+
String(Math.round(input.x2)),
|
|
60
|
+
String(Math.round(input.y2)),
|
|
61
|
+
String(Math.round(input.durationMs ?? 300)),
|
|
62
|
+
], input.timeoutMs ?? 30_000);
|
|
63
|
+
return {
|
|
64
|
+
swiped: true,
|
|
65
|
+
serial: device.serial,
|
|
66
|
+
x1: input.x1,
|
|
67
|
+
y1: input.y1,
|
|
68
|
+
x2: input.x2,
|
|
69
|
+
y2: input.y2,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export async function typeText(input) {
|
|
73
|
+
const device = await ensureDevice(input);
|
|
74
|
+
const text = inputText(input.text);
|
|
75
|
+
await adbShell(device.serial, ["input", "text", text], input.timeoutMs ?? 30_000);
|
|
76
|
+
return { typed: true, serial: device.serial, length: input.text.length };
|
|
77
|
+
}
|
|
78
|
+
export async function keyevent(input) {
|
|
79
|
+
const device = await ensureDevice(input);
|
|
80
|
+
await adbShell(device.serial, ["input", "keyevent", KEY_EVENTS[input.key]], input.timeoutMs ?? 30_000);
|
|
81
|
+
return { pressed: true, serial: device.serial, key: input.key };
|
|
82
|
+
}
|
|
83
|
+
export function parseUiAutomator(value) {
|
|
84
|
+
const elements = [];
|
|
85
|
+
for (const match of value.matchAll(/<node\b([^>]*)\/?>/g)) {
|
|
86
|
+
const attrs = attributes(match[1] ?? "");
|
|
87
|
+
const bounds = parseBounds(attrs.get("bounds") || "");
|
|
88
|
+
elements.push({
|
|
89
|
+
index: elements.length,
|
|
90
|
+
text: empty(attrs.get("text")),
|
|
91
|
+
contentDescription: empty(attrs.get("content-desc")),
|
|
92
|
+
resourceId: empty(attrs.get("resource-id")),
|
|
93
|
+
className: empty(attrs.get("class")),
|
|
94
|
+
bounds,
|
|
95
|
+
clickable: attrs.get("clickable") === "true",
|
|
96
|
+
enabled: attrs.get("enabled") !== "false",
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return elements;
|
|
100
|
+
}
|
|
101
|
+
function attributes(value) {
|
|
102
|
+
const out = new Map();
|
|
103
|
+
for (const match of value.matchAll(/([A-Za-z0-9_-]+)="([^"]*)"/g)) {
|
|
104
|
+
if (match[1])
|
|
105
|
+
out.set(match[1], decode(match[2] ?? ""));
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
function parseBounds(value) {
|
|
110
|
+
const match = value.match(/\[(\d+),(\d+)]\[(\d+),(\d+)]/);
|
|
111
|
+
if (!match)
|
|
112
|
+
return undefined;
|
|
113
|
+
const left = Number(match[1]);
|
|
114
|
+
const top = Number(match[2]);
|
|
115
|
+
const right = Number(match[3]);
|
|
116
|
+
const bottom = Number(match[4]);
|
|
117
|
+
return {
|
|
118
|
+
left,
|
|
119
|
+
top,
|
|
120
|
+
right,
|
|
121
|
+
bottom,
|
|
122
|
+
centerX: Math.round((left + right) / 2),
|
|
123
|
+
centerY: Math.round((top + bottom) / 2),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export function inputText(value) {
|
|
127
|
+
if (value.length > MAX_INPUT_TEXT_LENGTH)
|
|
128
|
+
throw new Error("Text input is too long.");
|
|
129
|
+
return value.replace(/%/g, "%25").replace(/\s/g, "%s");
|
|
130
|
+
}
|
|
131
|
+
function elementText(item) {
|
|
132
|
+
return [item.text, item.contentDescription, item.resourceId, item.className]
|
|
133
|
+
.filter(Boolean)
|
|
134
|
+
.join(" ");
|
|
135
|
+
}
|
|
136
|
+
function empty(value) {
|
|
137
|
+
return value && value.length > 0 ? value : undefined;
|
|
138
|
+
}
|
|
139
|
+
function decode(value) {
|
|
140
|
+
return value
|
|
141
|
+
.replace(/"/g, '"')
|
|
142
|
+
.replace(/'/g, "'")
|
|
143
|
+
.replace(/</g, "<")
|
|
144
|
+
.replace(/>/g, ">")
|
|
145
|
+
.replace(/&/g, "&");
|
|
146
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "@zcode/android-emulator-plugin",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"private": true,
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"bin": {
|
|
8
|
+
"android-emulator-mcp": "./dist/mcp/server.js"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/mcp/server.js",
|
|
12
|
+
"types": "./dist/mcp/server.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
"./mcp": {
|
|
15
|
+
"types": "./dist/mcp/server.d.ts",
|
|
16
|
+
"import": "./dist/mcp/server.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc && node scripts/build-mcp.mjs",
|
|
21
|
+
"clean": "node ../../scripts/clean-dist.mjs",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"test": "vitest run test"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
27
|
+
"zod": "^4.4.3"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^24.0.0",
|
|
31
|
+
"esbuild": "^0.25.0",
|
|
32
|
+
"typescript": "^5.9.0",
|
|
33
|
+
"vitest": "^4.1.5"
|
|
34
|
+
}
|
|
35
|
+
}
|