@cadence-aria/cli 0.0.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/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @cadence-aria/cli
2
+
3
+ 通过 npx 一键在本地启动 Aria 工作台:
4
+
5
+ ```bash
6
+ npx @cadence-aria/cli
7
+ ```
8
+
9
+ 无参运行会启动本地 Web 工作台(绑定 `127.0.0.1`,自动选空闲端口)并打开浏览器。
10
+
11
+ ## 用法
12
+
13
+ - `npx @cadence-aria/cli`:启动 web 工作台并开浏览器。
14
+ - `npx @cadence-aria/cli --no-open`:启动 web 但不开浏览器(远程/无头环境)。
15
+ - `npx @cadence-aria/cli web --port 3000`:指定端口(不自动开浏览器)。
16
+ - `npx @cadence-aria/cli task run ...` / `daemon` / `repl`:透传给底层 aria 二进制。
17
+
18
+ ## 平台支持
19
+
20
+ 预编译二进制覆盖:linux-x64、darwin-x64、darwin-arm64。其它平台请使用源码构建或查阅 GitHub Release。
21
+
22
+ ## 可选外部依赖
23
+
24
+ 真实 provider 执行需要 `codex` / `claude` CLI 在 PATH 中;缺失不影响工作台界面与演示。
package/bin/aria.js ADDED
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { spawn } = require("node:child_process");
5
+ const http = require("node:http");
6
+ const { resolveBinary } = require("../lib/platform.js");
7
+ const { planInvocation } = require("../lib/args.js");
8
+ const { pickFreePort } = require("../lib/port.js");
9
+
10
+ // 打开浏览器(尽力而为,失败仅降级为打印地址)。
11
+ function openBrowser(url) {
12
+ const platform = process.platform;
13
+ const cmd = platform === "darwin" ? "open" : platform === "win32" ? "cmd" : "xdg-open";
14
+ const args = platform === "win32" ? ["/c", "start", "", url] : [url];
15
+ try {
16
+ const child = spawn(cmd, args, { stdio: "ignore", detached: true });
17
+ child.on("error", () => console.error(`无法自动打开浏览器,请手动访问:${url}`));
18
+ child.unref();
19
+ } catch {
20
+ console.error(`无法自动打开浏览器,请手动访问:${url}`);
21
+ }
22
+ }
23
+
24
+ // 轮询 /api/health 直到就绪或超时(用于决定何时开浏览器)。
25
+ function waitForReady(port, timeoutMs = 30000) {
26
+ const deadline = Date.now() + timeoutMs;
27
+ return new Promise((resolve) => {
28
+ const tick = () => {
29
+ const req = http.get(
30
+ { host: "127.0.0.1", port, path: "/api/health", timeout: 1000 },
31
+ (res) => {
32
+ res.resume();
33
+ if (res.statusCode === 200) return resolve(true);
34
+ retry();
35
+ },
36
+ );
37
+ req.on("error", retry);
38
+ req.on("timeout", () => {
39
+ req.destroy();
40
+ retry();
41
+ });
42
+ };
43
+ const retry = () => {
44
+ if (Date.now() > deadline) return resolve(false);
45
+ setTimeout(tick, 200);
46
+ };
47
+ tick();
48
+ });
49
+ }
50
+
51
+ async function main() {
52
+ const argv = process.argv.slice(2);
53
+ const plan = planInvocation(argv);
54
+
55
+ let binary;
56
+ try {
57
+ binary = resolveBinary(process.platform, process.arch, require);
58
+ } catch (err) {
59
+ console.error(err.message);
60
+ process.exit(1);
61
+ }
62
+
63
+ let forwardArgs = plan.forwardArgs;
64
+ let port = null;
65
+
66
+ // 默认 web 模式:launcher 自选端口并以 web --port <p> --host 127.0.0.1 传入。
67
+ if (plan.defaultWebMode) {
68
+ port = await pickFreePort();
69
+ forwardArgs = ["web", "--port", String(port), "--host", "127.0.0.1"];
70
+ }
71
+
72
+ const child = spawn(binary, forwardArgs, { stdio: "inherit" });
73
+
74
+ // 信号转发,保证 Ctrl-C 干净退出。
75
+ for (const sig of ["SIGINT", "SIGTERM"]) {
76
+ process.on(sig, () => child.kill(sig));
77
+ }
78
+
79
+ // 自动开浏览器(仅默认 web 模式且未 --no-open)。
80
+ if (plan.open && port !== null) {
81
+ waitForReady(port).then((ready) => {
82
+ const url = `http://127.0.0.1:${port}`;
83
+ if (ready) openBrowser(url);
84
+ else console.error(`服务未在预期时间内就绪,请手动访问:${url}`);
85
+ });
86
+ }
87
+
88
+ child.on("exit", (code, signal) => {
89
+ if (signal) {
90
+ process.kill(process.pid, signal);
91
+ } else {
92
+ process.exit(code ?? 0);
93
+ }
94
+ });
95
+ }
96
+
97
+ main();
package/lib/args.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ // 解析用户传给 npx 的参数,决定:转发给二进制的参数、是否默认 web 模式、是否自动开浏览器。
4
+ //
5
+ // 规则(见设计 v1.3 第 5 节):
6
+ // - 无参 -> 注入默认 `web`,默认 web 模式,自动开浏览器。
7
+ // - 恰好只传 `web`(无任何其它参数)-> 默认 web 模式(launcher 自选端口、开浏览器)。
8
+ // - `web` 后跟任何参数(--port/--check/--host/--workspace 等)或其它任意子命令
9
+ // -> 非默认模式:尊重用户参数原样透传、不自选端口、不开浏览器。
10
+ // - `--no-open` 由 launcher 消费、从转发参数剥离,并关闭开浏览器。
11
+ function planInvocation(argv) {
12
+ const open0 = !argv.includes("--no-open");
13
+ const rest = argv.filter((a) => a !== "--no-open");
14
+
15
+ if (rest.length === 0) {
16
+ return { forwardArgs: ["web"], defaultWebMode: true, open: open0 };
17
+ }
18
+
19
+ // 默认 web 模式只在「恰好只有 web 一个 token」时成立。
20
+ // web 后跟任何 flag 都意味着用户接管,必须原样透传、不劫持端口、不开浏览器。
21
+ const defaultWebMode = rest.length === 1 && rest[0] === "web";
22
+
23
+ return {
24
+ forwardArgs: rest,
25
+ defaultWebMode,
26
+ // 仅默认 web 模式才可能开浏览器。
27
+ open: defaultWebMode && open0,
28
+ };
29
+ }
30
+
31
+ module.exports = { planInvocation };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ // 支持的 <os>-<arch> 矩阵。新增平台时同步此处与 scripts/pack-npm.mjs 与 release workflow。
4
+ const SUPPORTED = new Set(["linux-x64", "darwin-x64", "darwin-arm64"]);
5
+
6
+ // 由 process.platform + process.arch 映射到平台子包名。
7
+ function subpackageName(platform, arch) {
8
+ const key = `${platform}-${arch}`;
9
+ if (!SUPPORTED.has(key)) {
10
+ throw new Error(
11
+ `当前平台 ${key} 暂无预编译包 (unsupported)。已支持:${[...SUPPORTED].join(", ")}。\n` +
12
+ `可改用源码构建(需 Rust 1.95 + pnpm),或在 GitHub Release 查找对应二进制。`,
13
+ );
14
+ }
15
+ return `@cadence-aria/cli-${key}`;
16
+ }
17
+
18
+ // 定位子包内的二进制路径。require.resolve 在子包未安装时抛错。
19
+ function resolveBinary(platform, arch, requireFn) {
20
+ const pkg = subpackageName(platform, arch);
21
+ const target = `${pkg}/bin/aria`;
22
+ try {
23
+ return requireFn.resolve(target);
24
+ } catch (primaryErr) {
25
+ // 回退:从 cwd 解析(覆盖测试桩与非常规安装布局)
26
+ try {
27
+ const { createRequire } = require("node:module");
28
+ const path = require("node:path");
29
+ const cwdRequire = createRequire(path.join(process.cwd(), "noop.js"));
30
+ return cwdRequire.resolve(target);
31
+ } catch {
32
+ throw primaryErr;
33
+ }
34
+ }
35
+ }
36
+
37
+ module.exports = { SUPPORTED, subpackageName, resolveBinary };
package/lib/port.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ const net = require("node:net");
4
+
5
+ // 让内核分配一个空闲端口(listen 0),取到后立即释放并返回端口号。
6
+ // 存在「释放后到二进制再 bind」的微小窗口,但本机本地场景概率极低,且二进制 bind 失败会显式报错。
7
+ function pickFreePort() {
8
+ return new Promise((resolve, reject) => {
9
+ const srv = net.createServer();
10
+ srv.once("error", reject);
11
+ srv.listen(0, "127.0.0.1", () => {
12
+ const { port } = srv.address();
13
+ srv.close((err) => (err ? reject(err) : resolve(port)));
14
+ });
15
+ });
16
+ }
17
+
18
+ module.exports = { pickFreePort };
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@cadence-aria/cli",
3
+ "version": "0.0.1",
4
+ "description": "Aria 本地化工作台 — 通过 npx 一键启动",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/michaelChe956/cadence-aria.git"
9
+ },
10
+ "type": "commonjs",
11
+ "bin": {
12
+ "aria": "bin/aria.js"
13
+ },
14
+ "files": [
15
+ "bin/",
16
+ "lib/",
17
+ "README.md"
18
+ ],
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "optionalDependencies": {
23
+ "@cadence-aria/cli-linux-x64": "0.0.1",
24
+ "@cadence-aria/cli-darwin-x64": "0.0.1",
25
+ "@cadence-aria/cli-darwin-arm64": "0.0.1"
26
+ }
27
+ }