proofed-cli 0.1.3 → 0.2.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.
Files changed (65) hide show
  1. package/README.md +176 -122
  2. package/dist/action/requests.js +130 -0
  3. package/dist/{server.js → action/server.js} +17 -3
  4. package/dist/changes.js +7 -1
  5. package/dist/{args.js → check/args.js} +31 -3
  6. package/dist/check/cache.js +89 -0
  7. package/dist/{check.js → check/check.js} +86 -40
  8. package/dist/{doctor.js → check/doctor.js} +55 -19
  9. package/dist/check/help.js +139 -0
  10. package/dist/{list.js → check/list.js} +27 -15
  11. package/dist/{pipeline.js → check/pipeline.js} +106 -68
  12. package/dist/{render.js → check/render.js} +22 -15
  13. package/dist/check/run.js +277 -0
  14. package/dist/check/targetfilter.js +10 -0
  15. package/dist/check/textcheck.js +162 -0
  16. package/dist/env.js +6 -0
  17. package/dist/fix/agent.js +21 -0
  18. package/dist/fix/claude.js +30 -0
  19. package/dist/fix/codex.js +71 -0
  20. package/dist/fix/fixsetup.js +76 -0
  21. package/dist/fix/fixtarget.js +48 -0
  22. package/dist/fix/models.js +67 -0
  23. package/dist/github.js +62 -14
  24. package/dist/integrations/claude-stop.js +104 -0
  25. package/dist/integrations/cli.js +63 -0
  26. package/dist/integrations/mcp.js +130 -0
  27. package/dist/kane/creditmeter.js +104 -0
  28. package/dist/kane/kane.js +131 -0
  29. package/dist/kane/kaneauth.js +84 -0
  30. package/dist/kane/kaneversion.js +13 -0
  31. package/dist/paths.js +32 -0
  32. package/dist/process.js +65 -0
  33. package/dist/proofed.js +34 -16
  34. package/dist/{live.js → report/live.js} +1 -1
  35. package/dist/{livefile.js → report/livefile.js} +1 -1
  36. package/dist/{report.js → report/report.js} +105 -125
  37. package/dist/report/reportdata.js +120 -0
  38. package/dist/{result.js → report/result.js} +12 -7
  39. package/dist/{runfile.js → report/runfile.js} +2 -2
  40. package/dist/report/runresult.js +5 -0
  41. package/dist/scenarios.js +41 -19
  42. package/dist/secrets.js +74 -0
  43. package/dist/{cdp.js → targets/cdp.js} +20 -6
  44. package/dist/targets/chrome.js +98 -0
  45. package/dist/{clip.js → targets/clip.js} +21 -11
  46. package/dist/{precheck.js → targets/precheck.js} +53 -20
  47. package/dist/targets/preparetarget.js +350 -0
  48. package/dist/{recorder.js → targets/recorder.js} +154 -19
  49. package/dist/{serve.js → targets/serve.js} +9 -13
  50. package/dist/{target.js → targets/target.js} +42 -7
  51. package/dist/targets/targetchecks.js +139 -0
  52. package/dist/timing.js +25 -0
  53. package/dist/types.js +1 -0
  54. package/dist/which.js +26 -13
  55. package/docs/cli.md +370 -0
  56. package/package.json +10 -5
  57. package/dist/cache.js +0 -48
  58. package/dist/chrome.js +0 -77
  59. package/dist/help.js +0 -133
  60. package/dist/kane.js +0 -75
  61. package/dist/kaneauth.js +0 -48
  62. package/dist/models.js +0 -44
  63. package/dist/requests.js +0 -58
  64. package/dist/run.js +0 -173
  65. /package/dist/{deps.js → targets/deps.js} +0 -0
@@ -4,8 +4,9 @@
4
4
  // So in a repo that already runs Proofed on its pull requests, `proofed check` needs no flags.
5
5
  import { existsSync, readdirSync, readFileSync } from "node:fs";
6
6
  import { join, resolve } from "node:path";
7
- import { SetupError } from "./setuperror.js";
8
- const KEYS = ["url", "serve", "build", "install"];
7
+ import { SetupError } from "../setuperror.js";
8
+ export const TARGET_KEYS = ["target", "execution", "app", "device", "os_version", "launch", "cdp_endpoint"];
9
+ const KEYS = ["url", "serve", "build", "install", ...TARGET_KEYS];
9
10
  export const CONFIG_FILE = ".proofed/config.json";
10
11
  // "localhost:5173" parses as a URL with the scheme "localhost:", so parsing alone isn't the test.
11
12
  export function isHttpUrl(value) {
@@ -25,7 +26,7 @@ export function readConfig(cwd) {
25
26
  data = JSON.parse(readFileSync(file, "utf8"));
26
27
  }
27
28
  catch (e) {
28
- throw new SetupError("config_invalid", `${CONFIG_FILE} is not valid JSON: ${e instanceof Error ? e.message : e}`, `Correct the JSON in ${CONFIG_FILE}; it holds { "url", "serve", "build", "install" }.`);
29
+ throw new SetupError("config_invalid", `${CONFIG_FILE} is not valid JSON: ${e instanceof Error ? e.message : e}`, `Correct the JSON in ${CONFIG_FILE}; it accepts url, serve, build, install and target settings.`);
29
30
  }
30
31
  if (typeof data !== "object" || data === null)
31
32
  return {};
@@ -93,7 +94,7 @@ export function readWorkflow(cwd) {
93
94
  if (!existsSync(dir))
94
95
  return undefined;
95
96
  for (const name of readdirSync(dir).filter((f) => /\.ya?ml$/.test(f)).sort()) {
96
- const file = join(".github/workflows", name);
97
+ const file = `.github/workflows/${name}`;
97
98
  const inputs = workflowInputs(readFileSync(join(cwd, file), "utf8"));
98
99
  if (inputs)
99
100
  return { file, inputs };
@@ -126,13 +127,47 @@ export function resolveTarget({ flags, env, cwd }) {
126
127
  // A build and an install belong with their serve command: the workflow's build is for the
127
128
  // workflow's serve. One given as a flag or in the environment applies to whichever serve is used.
128
129
  const withServe = (key) => pick(key, layers.slice(0, 2)) ?? (serve && pick(key, [serve.layer]));
129
- const build = withServe("build");
130
- const install = withServe("install");
130
+ const build = withServe("build") ?? (!serve ? pick("build") : undefined);
131
+ const install = withServe("install") ?? (!serve ? pick("install") : undefined);
131
132
  return {
132
133
  url: url?.setting,
133
134
  serve: serve?.setting,
134
135
  build: build?.setting,
135
136
  install: install?.setting,
136
- dir: resolve(cwd, serve?.layer.dir ?? "."),
137
+ dir: resolve(cwd, env.PROOFED_DIR || (serve ? serve.layer.dir : workflow?.inputs["working-directory"]) || "."),
137
138
  };
138
139
  }
140
+ export function resolveScenarioTarget(scenario, flags, env, cwd) {
141
+ const config = readConfig(cwd);
142
+ const workflow = readWorkflow(cwd);
143
+ const values = {};
144
+ const sources = {};
145
+ for (const key of TARGET_KEYS) {
146
+ const layers = [
147
+ [flags[key], `--${key.replaceAll("_", "-")}`],
148
+ [env[`PROOFED_${key.toUpperCase()}`]?.trim(), `PROOFED_${key.toUpperCase()}`],
149
+ [scenario[key], "scenario"], [config[key], CONFIG_FILE],
150
+ [workflow?.inputs[key.replaceAll("_", "-")], workflow?.file],
151
+ ];
152
+ const found = layers.find(([value]) => value);
153
+ if (found) {
154
+ values[key] = found[0];
155
+ sources[key] = found[1];
156
+ }
157
+ }
158
+ sources.target ??= "default";
159
+ sources.execution ??= "default";
160
+ const kind = values.target ?? "web";
161
+ const execution = values.execution ?? "local";
162
+ if (!["web", "ios", "android", "desktop"].includes(kind) || !["local", "cloud"].includes(execution))
163
+ throw new SetupError("target_invalid", `Invalid target/execution: ${kind}/${execution}`, "Use web, ios, android or desktop; cloud execution is only for ios and android.");
164
+ if (execution === "cloud" && (kind === "web" || kind === "desktop"))
165
+ throw new SetupError("target_invalid", `${kind} requires execution: local`, "Use local execution.");
166
+ const service = resolveTarget({ flags: {}, env, cwd });
167
+ const app = values.app && (/^APP[\w-]+$/.test(values.app) ? values.app : resolve(service.dir, values.app));
168
+ if (kind === "web")
169
+ return { kind, execution: "local", sources, dir: service.dir };
170
+ if (kind === "desktop")
171
+ return { kind, execution: "local", app, launch: values.launch, cdp_endpoint: values.cdp_endpoint, reuse: flags.reuse ?? false, sources, dir: service.dir };
172
+ return { kind: kind, execution: execution, app, device: values.device, os_version: values.os_version, sources, dir: service.dir };
173
+ }
@@ -0,0 +1,139 @@
1
+ import { executableCommand } from "../process.js";
2
+ import { execFile } from "node:child_process";
3
+ import { existsSync, statSync } from "node:fs";
4
+ import { promisify } from "node:util";
5
+ import { cdpUrl } from "./cdp.js";
6
+ const exec = promisify(execFile);
7
+ export const kaneTarget = (target) => target.kind === "ios" ? (target.execution === "local" ? "simulator" : "ios") : target.kind === "android" ? (target.execution === "local" ? "emulator" : "android") : "desktop";
8
+ export async function command(bin, args, env = process.env, timeout = 20_000) {
9
+ try {
10
+ const cmd = executableCommand(bin, args, env);
11
+ const { stdout, stderr } = await exec(cmd.file, cmd.args, { env, windowsHide: true, timeout, maxBuffer: 4 * 1024 * 1024 });
12
+ return { ok: true, stdout, text: `${stdout}\n${stderr}`.trim() };
13
+ }
14
+ catch (error) {
15
+ const e = error;
16
+ const detail = e.stderr?.trim() ? e.stderr : e.message || "Command failed";
17
+ return { ok: false, text: `${e.stdout?.trimEnd() ?? ""}\n${detail}`.trim() };
18
+ }
19
+ }
20
+ export const isAppBundle = (app) => /\.app$/i.test(app);
21
+ export async function cdpOccupied(endpoint) {
22
+ return fetch(cdpUrl(endpoint, "version"), { signal: AbortSignal.timeout(1000) }).then(() => true, () => false);
23
+ }
24
+ export async function renderer(endpoint) {
25
+ const version = await fetch(cdpUrl(endpoint, "version"), { signal: AbortSignal.timeout(1500) });
26
+ if (!version.ok || !(await version.json()).webSocketDebuggerUrl)
27
+ throw new Error("CDP /json/version has no browser websocket");
28
+ const response = await fetch(cdpUrl(endpoint, "list"), { signal: AbortSignal.timeout(1500) });
29
+ const pages = (await response.json()).filter((p) => p.type === "page");
30
+ if (pages.length !== 1)
31
+ throw new Error(`Expected one page renderer, found ${pages.length}`);
32
+ return pages[0];
33
+ }
34
+ export async function localDevice(target, env = process.env) {
35
+ if (!target.device || !target.os_version)
36
+ throw new Error("Local mobile requires device and os_version");
37
+ if (target.kind === "ios") {
38
+ const result = await command("xcrun", ["simctl", "list", "devices", "available", "--json"], env);
39
+ if (!result.ok)
40
+ throw new Error(result.text);
41
+ const data = JSON.parse(result.stdout);
42
+ const matches = Object.entries(data.devices).filter(([runtime]) => runtime.endsWith(`iOS-${target.os_version.replaceAll(".", "-")}`)).flatMap(([, devices]) => devices).filter((d) => d.name === target.device && d.state === "Booted");
43
+ if (matches.length !== 1)
44
+ throw new Error(`Expected one booted ${target.device} iOS ${target.os_version}, found ${matches.length}`);
45
+ return matches[0].udid;
46
+ }
47
+ const devices = await command("adb", ["devices"], env);
48
+ if (!devices.ok)
49
+ throw new Error(devices.text);
50
+ const matches = [];
51
+ for (const line of devices.stdout.split(/\r?\n/)) {
52
+ const serial = /^(emulator-\S+)\s+device\s*$/.exec(line)?.[1];
53
+ if (!serial)
54
+ continue;
55
+ const name = await command("adb", ["-s", serial, "emu", "avd", "name"], env);
56
+ const model = await command("adb", ["-s", serial, "shell", "getprop", "ro.product.model"], env);
57
+ const os = await command("adb", ["-s", serial, "shell", "getprop", "ro.build.version.release"], env);
58
+ // `adb emu avd name` answers "Pixel_8_API_34\r\nOK\r\n".
59
+ if (!os.ok || os.stdout.trim() !== target.os_version)
60
+ continue;
61
+ if ((name.ok && name.stdout.split(/\r?\n/)[0]?.trim() === target.device) ||
62
+ (model.ok && model.stdout.trim() === target.device))
63
+ matches.push(serial);
64
+ }
65
+ if (matches.length !== 1)
66
+ throw new Error(`Expected one online ${target.device} Android ${target.os_version}, found ${matches.length}`);
67
+ return matches[0];
68
+ }
69
+ export async function targetChecks(target, options = {}) {
70
+ const env = options.env ?? process.env;
71
+ const checks = [];
72
+ const add = (name, ok, detail, fix) => checks.push({ name, status: ok ? "ok" : "fail", detail, fix });
73
+ if (target.kind === "web")
74
+ return checks;
75
+ if (target.kind === "desktop") {
76
+ if (!target.cdp_endpoint)
77
+ add("Desktop CDP", false, "No cdp_endpoint", "Set --cdp-endpoint http://127.0.0.1:<port> and --launch, or --reuse for an existing app.");
78
+ else {
79
+ try {
80
+ if (target.launch || target.app) {
81
+ if (await cdpOccupied(target.cdp_endpoint)) {
82
+ add("Desktop CDP", false, "CDP endpoint already answers", "Stop the running app, or omit launch and app and pass --reuse.");
83
+ }
84
+ else {
85
+ add("Desktop CDP", !!options.launchPending, options.launchPending ? "not running, as expected: proofed check launches it" : "CDP endpoint is not running", "proofed check will launch the app; doctor never launches it.");
86
+ }
87
+ }
88
+ else {
89
+ const page = await renderer(target.cdp_endpoint);
90
+ add("Desktop CDP", true, `Experimental Electron renderer: ${page.url}`, "Keep exactly one page renderer.");
91
+ }
92
+ }
93
+ catch (e) {
94
+ add("Desktop CDP", false, String(e), target.launch || target.app ? "Set a valid CDP endpoint for the app to launch." : "Start the app with remote debugging and exactly one page renderer.");
95
+ }
96
+ }
97
+ if (!target.launch && !target.app && !target.reuse)
98
+ add("Desktop ownership", false, "Existing endpoints require --reuse", "Pass --reuse; Proofed will not close the existing app.");
99
+ if (target.app && !target.launch) {
100
+ add("Desktop app", existsSync(target.app) || !!options.pendingBuild, target.app, "Build the desktop app, or set launch to its launch command.");
101
+ }
102
+ return checks;
103
+ }
104
+ const app = target.app;
105
+ const validType = !!app && (/^APP[\w-]+$/.test(app) ||
106
+ (target.kind === "ios"
107
+ ? target.execution === "local" ? isAppBundle(app) || /\.zip$/i.test(app) : /\.ipa$/i.test(app)
108
+ : (target.execution === "local" ? /\.apk$/i : /\.(apk|aab)$/i).test(app)));
109
+ add("App artifact type", validType, app ?? "No app artifact", `Set --app to ${target.kind === "ios" ? target.execution === "local" ? "a simulator .app or .zip" : "a device .ipa" : target.execution === "local" ? "an .apk" : "an .apk or .aab"}, or an APP ID.`);
110
+ if (app && !/^APP[\w-]+$/.test(app)) {
111
+ const present = existsSync(app) && (isAppBundle(app) ? statSync(app).isDirectory() : statSync(app).isFile());
112
+ checks.push({ name: "App artifact", status: present || options.pendingBuild ? "ok" : "fail", detail: present ? app : options.pendingBuild ? `artifact_pending_build: proofed check builds ${app} first` : `Missing ${app}`, fix: "Build the app before running the check." });
113
+ }
114
+ if (target.execution === "cloud") {
115
+ checks.push({ name: "Cloud recording", status: "ok", detail: "screenshots only, no video clip; local execution records MP4", fix: "Use local execution for MP4 recording." });
116
+ return checks;
117
+ }
118
+ if ((options.platform ?? process.platform) !== "darwin" || (options.arch ?? process.arch) !== "arm64") {
119
+ add(`${target.kind === "ios" ? "iOS" : "Android"} host`, false, "Kane local Android emulators and iOS simulators require macOS on Apple Silicon (arm64)", "Use an Apple Silicon Mac for local mobile, or select cloud execution with an .apk/.aab (Android) or .ipa (iOS).");
120
+ return checks;
121
+ }
122
+ if (target.kind === "ios") {
123
+ for (const [name, bin, args] of [["Xcode", "xcodebuild", ["-version"]], ["simctl", "xcrun", ["simctl", "list", "devices", "available", "--json"]]]) {
124
+ const result = await command(bin, [...args], env);
125
+ add(name, result.ok, result.text, "Install full Xcode and a matching iOS runtime; select Xcode with xcode-select. Doctor never installs or boots devices.");
126
+ }
127
+ }
128
+ const deps = await command(env.KANE_CLI ?? "kane-cli", ["doctor", "--target", kaneTarget(target)], env);
129
+ // Only doctor's own check lines count: kane-cli also prints notices such as "Skill update available: not installed".
130
+ add("Kane managed mobile dependencies", deps.ok && !/^\s*[✗✘]/m.test(deps.text), deps.text, `Run kane-cli doctor --target ${kaneTarget(target)} and explicitly set up the listed managed dependencies before check.`);
131
+ try {
132
+ const id = await localDevice(target, env);
133
+ add("Recording device", true, id, "Keep this device online and booted.");
134
+ }
135
+ catch (e) {
136
+ add("Recording device", false, String(e), "Set --device and --os-version to exactly one booted simulator or online emulator; boot it yourself.");
137
+ }
138
+ return checks;
139
+ }
package/dist/timing.js ADDED
@@ -0,0 +1,25 @@
1
+ export function phase(label) {
2
+ if (process.env.GITHUB_ACTIONS !== "true")
3
+ return () => { };
4
+ const start = performance.now();
5
+ // stderr: the CLI also runs inside Actions, and its --json stdout must stay one JSON document.
6
+ return () => console.error(`Proofed timing ${label}: ${((performance.now() - start) / 1000).toFixed(2)}s`);
7
+ }
8
+ export function timed(label, run) {
9
+ const end = phase(label);
10
+ try {
11
+ return run();
12
+ }
13
+ finally {
14
+ end();
15
+ }
16
+ }
17
+ export async function timedAsync(label, run) {
18
+ const end = phase(label);
19
+ try {
20
+ return await run();
21
+ }
22
+ finally {
23
+ end();
24
+ }
25
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/which.js CHANGED
@@ -1,28 +1,41 @@
1
1
  import { accessSync, constants, statSync } from "node:fs";
2
- import { delimiter, join, resolve } from "node:path";
3
- const executable = (file) => {
2
+ import { join, resolve, win32 } from "node:path";
3
+ const executable = (file, platform = process.platform) => {
4
4
  try {
5
- accessSync(file, constants.X_OK);
5
+ accessSync(file, platform === "win32" ? constants.F_OK : constants.X_OK);
6
6
  return statSync(file).isFile();
7
7
  }
8
8
  catch {
9
9
  return false;
10
10
  }
11
11
  };
12
- export function findOnPath(name, env = process.env) {
13
- for (const dir of (env.PATH ?? "").split(delimiter).filter(Boolean)) {
14
- const file = join(dir, name);
15
- if (executable(file))
16
- return file;
12
+ export const pathValue = (env, name) => env[name] ?? env[Object.keys(env).find((key) => key.toLowerCase() === name.toLowerCase()) ?? name];
13
+ export function findOnPath(name, env = process.env, platform = process.platform) {
14
+ const windows = platform === "win32";
15
+ const extensions = windows ? (pathValue(env, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [];
16
+ const explicit = /[/\\]/.test(name);
17
+ const suffixes = windows && !extensions.some((ext) => name.toLowerCase().endsWith(ext.toLowerCase()))
18
+ ? explicit || win32.extname(name) ? [...extensions, ""] : extensions
19
+ : [""];
20
+ const dirs = explicit ? [""] : (pathValue(env, "PATH") ?? "").split(windows ? ";" : ":").filter(Boolean);
21
+ for (const dir of dirs) {
22
+ for (const suffix of suffixes) {
23
+ const file = dir ? join(dir.replace(/^"|"$/g, ""), `${name}${suffix}`) : name + suffix;
24
+ if (executable(file, platform))
25
+ return resolve(file);
26
+ // Windows filesystems ignore case; this also lets injected-platform tests run on Unix.
27
+ const lower = file.slice(0, file.length - suffix.length) + suffix.toLowerCase();
28
+ if (suffix && executable(lower, platform))
29
+ return resolve(lower);
30
+ }
17
31
  }
18
32
  return undefined;
19
33
  }
20
- // The Kane binary src/kane.ts will spawn: KANE_CLI when set, else kane-cli on PATH.
21
- export function findKane(env = process.env) {
34
+ export function findKane(env = process.env, platform = process.platform) {
22
35
  const own = env.KANE_CLI?.trim();
23
36
  if (own) {
24
- const file = own.includes("/") ? resolve(own) : findOnPath(own, env);
25
- return { path: file && executable(file) ? file : undefined, from: `KANE_CLI=${own}` };
37
+ const file = findOnPath(/[/\\]/.test(own) ? resolve(own) : own, env, platform);
38
+ return { path: file, from: `KANE_CLI=${own}` };
26
39
  }
27
- return { path: findOnPath("kane-cli", env), from: "PATH" };
40
+ return { path: findOnPath("kane-cli", env, platform), from: "PATH" };
28
41
  }