@volcengine/ark-cli 0.1.17-beta.0e2572f

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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @volcengine/ark-cli
2
+
3
+ 火山方舟 ARK 平台命令行工具。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install -g @volcengine/ark-cli
9
+ ```
10
+
11
+ 安装时会根据你的操作系统与 CPU 架构,从 CDN 自动下载对应的二进制并校验 sha256。
12
+
13
+ ## 使用
14
+
15
+ ```bash
16
+ arkcli --help
17
+ ```
18
+
19
+ ## 支持平台
20
+
21
+ | 操作系统 | 架构 |
22
+ |----------|------|
23
+ | macOS | arm64 / x64 |
24
+ | Linux | arm64 / x64 |
25
+ | Windows | arm64 / x64 |
26
+
27
+ ## 许可
28
+
29
+ [Apache-2.0](./LICENSE)
package/manifest.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "version": "0.1.17-beta.0e2572f",
3
+ "platforms": {
4
+ "darwin-amd64": {
5
+ "url": "https://lf3-static.bytednsdoc.com/obj/eden-cn/psjryh/ljhwZthlaukjlkulzlp/dev/0.1.17-beta.0e2572f/arkcli-0.1.17-beta.0e2572f-darwin-amd64",
6
+ "sha256": "be1d6241d150f9568f14b40edcb877ef4f0d7a3c6be1be168ac9dd774204eecd"
7
+ },
8
+ "darwin-arm64": {
9
+ "url": "https://lf3-static.bytednsdoc.com/obj/eden-cn/psjryh/ljhwZthlaukjlkulzlp/dev/0.1.17-beta.0e2572f/arkcli-0.1.17-beta.0e2572f-darwin-arm64",
10
+ "sha256": "bb0085f79d9c019e81fd1c44082eb9642ef85360d2f3ad2d2a534719c2c808cc"
11
+ },
12
+ "linux-amd64": {
13
+ "url": "https://lf3-static.bytednsdoc.com/obj/eden-cn/psjryh/ljhwZthlaukjlkulzlp/dev/0.1.17-beta.0e2572f/arkcli-0.1.17-beta.0e2572f-linux-amd64",
14
+ "sha256": "cf4aa8cf635e2ea9771019c6934d493f6f613c1da6593fb9999bb4958e7f123a"
15
+ },
16
+ "linux-arm64": {
17
+ "url": "https://lf3-static.bytednsdoc.com/obj/eden-cn/psjryh/ljhwZthlaukjlkulzlp/dev/0.1.17-beta.0e2572f/arkcli-0.1.17-beta.0e2572f-linux-arm64",
18
+ "sha256": "506ac654e9293f0890539230a1063295aad471844a88bd4b90b517ddc2bf4012"
19
+ },
20
+ "windows-amd64": {
21
+ "url": "https://lf3-static.bytednsdoc.com/obj/eden-cn/psjryh/ljhwZthlaukjlkulzlp/dev/0.1.17-beta.0e2572f/arkcli-0.1.17-beta.0e2572f-windows-amd64.exe",
22
+ "sha256": "dee2284ee9ef43e9a86738ae70bde4a9e5a54789054cce5fce93a5cb6e2cffd8"
23
+ },
24
+ "windows-arm64": {
25
+ "url": "https://lf3-static.bytednsdoc.com/obj/eden-cn/psjryh/ljhwZthlaukjlkulzlp/dev/0.1.17-beta.0e2572f/arkcli-0.1.17-beta.0e2572f-windows-arm64.exe",
26
+ "sha256": "4009e1e7ba866f060b768e6bde86c683dcd3fa13dc5e98ac6369bef4684977a4"
27
+ }
28
+ },
29
+ "skills": {
30
+ "primary": {
31
+ "url": "https://lf3-static.bytednsdoc.com/obj/eden-cn/psjryh/ljhwZthlaukjlkulzlp/dev/0.1.17-beta.0e2572f/skills.tar.gz",
32
+ "sha256": "e4f800bfe3cb4e956b0f5896cc82706d33a7cb975df22bc6a4708ae0ec9801c6",
33
+ "kind": "cdn"
34
+ },
35
+ "tag": "v0.1.17-beta.0e2572f"
36
+ }
37
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@volcengine/ark-cli",
3
+ "version": "0.1.17-beta.0e2572f",
4
+ "description": "火山方舟 ARK 平台命令行工具",
5
+ "bin": {
6
+ "arkcli": "scripts/run.js"
7
+ },
8
+ "files": [
9
+ "scripts/run.js",
10
+ "scripts/postinstall.js",
11
+ "manifest.json"
12
+ ],
13
+ "scripts": {
14
+ "postinstall": "node scripts/postinstall.js"
15
+ },
16
+ "engines": {
17
+ "node": ">=16"
18
+ },
19
+ "os": [
20
+ "darwin",
21
+ "linux",
22
+ "win32"
23
+ ],
24
+ "cpu": [
25
+ "x64",
26
+ "arm64"
27
+ ],
28
+ "license": "Apache-2.0",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/volcengine/ark-cli.git"
32
+ }
33
+ }
@@ -0,0 +1,297 @@
1
+ #!/usr/bin/env node
2
+ // @volcengine/ark-cli postinstall。
3
+ // 由 npm 的 postinstall lifecycle 触发:读 manifest.json,按当前平台从 CDN 下载
4
+ // 对应二进制,校验 sha256,落到 <pkg>/bin/,然后(可选)+connect 装内置 skill。
5
+ //
6
+ // 与内场 postinstall 的区别(对外洁净契约):
7
+ // - 无 TEA 埋点
8
+ // - 无 bytecloud 卸载逻辑
9
+ // - 二进制不内嵌,运行时从 CDN 按平台下载
10
+ //
11
+ // 失败策略:
12
+ // - 下载/校验二进制 = 核心,失败则 exit 1(没有二进制这个包不可用,fail loud)
13
+ // - +connect 装 skill = 增强,失败仅告警,不影响安装结果(exit 0)
14
+
15
+ const fs = require("fs");
16
+ const path = require("path");
17
+ const http = require("http");
18
+ const https = require("https");
19
+ const crypto = require("crypto");
20
+ const { execFileSync } = require("child_process");
21
+ const os = require("os");
22
+
23
+ // —— 逃生阀 ——
24
+ if (process.env.ARKCLI_SKIP_POSTINSTALL === "1") {
25
+ process.exit(0);
26
+ }
27
+
28
+ const platformMap = { darwin: "darwin", linux: "linux", win32: "windows" };
29
+ const archMap = { x64: "amd64", arm64: "arm64" };
30
+ const platform = platformMap[process.platform];
31
+ const arch = archMap[process.arch];
32
+ if (!platform || !arch) {
33
+ console.error(
34
+ `@volcengine/ark-cli: unsupported platform ${process.platform}-${process.arch}`,
35
+ );
36
+ process.exit(1);
37
+ }
38
+ const key = `${platform}-${arch}`;
39
+ const ext = platform === "windows" ? ".exe" : "";
40
+
41
+ // —— 读 manifest(发布时烘焙的"平台 -> 真实 cdnUrl + sha256"对照表) ——
42
+ let manifest;
43
+ try {
44
+ manifest = JSON.parse(
45
+ fs.readFileSync(path.join(__dirname, "..", "manifest.json"), "utf-8"),
46
+ );
47
+ } catch (err) {
48
+ console.error(
49
+ `@volcengine/ark-cli: cannot read manifest.json: ${err.message || err}`,
50
+ );
51
+ process.exit(1);
52
+ }
53
+
54
+ const entry = manifest.platforms && manifest.platforms[key];
55
+ if (!entry || !entry.url) {
56
+ console.error(`@volcengine/ark-cli: no CDN entry for platform ${key} in manifest`);
57
+ process.exit(1);
58
+ }
59
+
60
+ const binDir = path.join(__dirname, "..", "bin");
61
+ const binPath = path.join(binDir, `arkcli-${platform}-${arch}${ext}`);
62
+
63
+ function httpMod(url) {
64
+ return url.startsWith("http://") ? http : https;
65
+ }
66
+
67
+ // 下载到临时文件,跟随 3xx 重定向(CDN 边缘常有跳转)。
68
+ function download(url, dest, redirects = 0) {
69
+ return new Promise((resolve, reject) => {
70
+ if (redirects > 5) return reject(new Error("too many redirects"));
71
+ const file = fs.createWriteStream(dest);
72
+ const req = httpMod(url).get(url, (res) => {
73
+ if (
74
+ res.statusCode >= 300 &&
75
+ res.statusCode < 400 &&
76
+ res.headers.location
77
+ ) {
78
+ file.close();
79
+ fs.rmSync(dest, { force: true });
80
+ return resolve(download(res.headers.location, dest, redirects + 1));
81
+ }
82
+ if (res.statusCode !== 200) {
83
+ file.close();
84
+ fs.rmSync(dest, { force: true });
85
+ return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
86
+ }
87
+ res.pipe(file);
88
+ file.on("finish", () => file.close(() => resolve()));
89
+ });
90
+ req.on("error", (err) => {
91
+ file.close();
92
+ fs.rmSync(dest, { force: true });
93
+ reject(err);
94
+ });
95
+ });
96
+ }
97
+
98
+ function sha256(file) {
99
+ return crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
100
+ }
101
+
102
+ // —— skill 安装(Phase 2:对外 skill 不内嵌,运行时下载到 <pkg>/skills/)——
103
+ // 候选源顺序:ARKCLI_SKILLS_URL(逃生阀) > manifest.skills.primary(CDN,强 sha)
104
+ // > manifest.skills.fallback(GitHub archive,结构校验)。任一成功即停。
105
+ // 全失败仅告警不阻断(skill 是 agent 增强,二进制才是核心;且 GitHub 国内不稳是已知风险)。
106
+
107
+ // skills 目录有效性:含至少一个 <name>/SKILL.md。
108
+ function isSkillsDir(p) {
109
+ try {
110
+ for (const e of fs.readdirSync(p, { withFileTypes: true })) {
111
+ if (e.isDirectory() && fs.existsSync(path.join(p, e.name, "SKILL.md"))) return true;
112
+ }
113
+ } catch (_) {}
114
+ return false;
115
+ }
116
+
117
+ // 在解压根下定位 skills/ 目录:CDN tar 顶层就是 skills/;
118
+ // GitHub archive tarball 是 <repo>-<tag>/skills/(多一层前缀)。
119
+ function findSkillsDir(root) {
120
+ const direct = path.join(root, "skills");
121
+ if (isSkillsDir(direct)) return direct;
122
+ let entries = [];
123
+ try { entries = fs.readdirSync(root, { withFileTypes: true }); } catch (_) {}
124
+ for (const e of entries) {
125
+ if (e.isDirectory()) {
126
+ const nested = path.join(root, e.name, "skills");
127
+ if (isSkillsDir(nested)) return nested;
128
+ }
129
+ }
130
+ return null;
131
+ }
132
+
133
+ // 解压前安全校验:不受信任归档(尤其 GitHub fallback 无 sha 强校验)可能塞越界/软链条目,
134
+ // 直接 tar -x 会写出到目标目录之外(路径穿越 / 软链攻击)。这里先 tar -t 列条目,
135
+ // 拒绝【绝对路径 / 含 .. 的路径 / 非「普通文件·目录」的条目(软链/硬链/设备等)】,通过才解压。
136
+ function assertSafeTar(tarPath) {
137
+ const names = execFileSync("tar", ["-tzf", tarPath], { encoding: "utf-8" });
138
+ for (const raw of names.split("\n")) {
139
+ const name = raw.trim();
140
+ if (!name) continue;
141
+ if (name.startsWith("/") || name.split("/").includes("..")) {
142
+ throw new Error(`unsafe path in skills archive: ${name}`);
143
+ }
144
+ }
145
+ // tar -tvzf 行首是文件类型:- 普通文件 / d 目录 / l 软链 / h 硬链 / b,c,p,s 设备等。
146
+ const verbose = execFileSync("tar", ["-tvzf", tarPath], { encoding: "utf-8" });
147
+ for (const raw of verbose.split("\n")) {
148
+ const line = raw.trim();
149
+ if (!line) continue;
150
+ const type = line[0];
151
+ if (type !== "-" && type !== "d") {
152
+ throw new Error(`unsafe entry type '${type}' in skills archive: ${line}`);
153
+ }
154
+ }
155
+ }
156
+
157
+ function extractSkillsTo(tarPath, destSkillsDir) {
158
+ assertSafeTar(tarPath); // 不受信任归档:解压前校验路径与类型,防越界写 / 软链攻击
159
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "arkcli-skills-"));
160
+ try {
161
+ execFileSync("tar", ["-xzf", tarPath, "-C", tmp], { stdio: "ignore" });
162
+ const src = findSkillsDir(tmp);
163
+ if (!src) throw new Error("archive 内找不到有效 skills/(无 */SKILL.md)");
164
+ fs.rmSync(destSkillsDir, { recursive: true, force: true });
165
+ try {
166
+ fs.renameSync(src, destSkillsDir);
167
+ } catch (_) {
168
+ fs.cpSync(src, destSkillsDir, { recursive: true }); // 跨设备 rename 失败兜底
169
+ }
170
+ } finally {
171
+ fs.rmSync(tmp, { recursive: true, force: true });
172
+ }
173
+ }
174
+
175
+ async function installSkillsFromSource(src, destSkillsDir) {
176
+ const tmpTar = path.join(os.tmpdir(), `arkcli-skills-${process.pid}.tar.gz`);
177
+ try {
178
+ await download(src.url, tmpTar);
179
+ if (src.sha256) {
180
+ const actual = sha256(tmpTar);
181
+ if (actual !== src.sha256) {
182
+ throw new Error(`sha256 mismatch (expected ${src.sha256}, got ${actual})`);
183
+ }
184
+ }
185
+ extractSkillsTo(tmpTar, destSkillsDir);
186
+ if (!isSkillsDir(destSkillsDir)) {
187
+ throw new Error("解压后 skills/ 无 */SKILL.md(结构校验失败)");
188
+ }
189
+ } finally {
190
+ fs.rmSync(tmpTar, { force: true });
191
+ }
192
+ }
193
+
194
+ async function installSkills() {
195
+ const pkgDir = path.join(__dirname, "..");
196
+ const destSkillsDir = path.join(pkgDir, "skills");
197
+ const skills = manifest.skills;
198
+ const override = (process.env.ARKCLI_SKILLS_URL || "").trim();
199
+
200
+ // 候选源:override(逃生阀,无 sha) > primary(强 sha) > fallback(结构校验)。
201
+ const sources = [];
202
+ if (override) sources.push({ url: override, sha256: null, kind: "override" });
203
+ if (skills && skills.primary && skills.primary.url) {
204
+ sources.push({ url: skills.primary.url, sha256: skills.primary.sha256 || null, kind: skills.primary.kind || "primary" });
205
+ }
206
+ if (skills && skills.fallback && skills.fallback.url) {
207
+ sources.push({ url: skills.fallback.url, sha256: null, kind: skills.fallback.kind || "fallback" });
208
+ }
209
+ if (sources.length === 0) {
210
+ console.warn("@volcengine/ark-cli: manifest 无 skills 源,跳过 skill 下载(可稍后 arkcli +connect 手动补)");
211
+ return false;
212
+ }
213
+
214
+ for (const src of sources) {
215
+ try {
216
+ console.log(`@volcengine/ark-cli: downloading skills from ${src.kind}...`);
217
+ await installSkillsFromSource(src, destSkillsDir);
218
+ console.log(`@volcengine/ark-cli: skills ready (${src.kind})`);
219
+ return true;
220
+ } catch (e) {
221
+ console.warn(`@volcengine/ark-cli: skill source ${src.kind} failed: ${e.message || e}`);
222
+ }
223
+ }
224
+ console.warn(
225
+ "@volcengine/ark-cli: 所有 skill 源下载失败;稍后可跑 `arkcli +connect`,或设 ARKCLI_SKILLS_URL 指定镜像后重装",
226
+ );
227
+ return false;
228
+ }
229
+
230
+ (async () => {
231
+ fs.mkdirSync(binDir, { recursive: true });
232
+ const tmp = `${binPath}.download`;
233
+
234
+ try {
235
+ console.log(`@volcengine/ark-cli: downloading ${key} binary from CDN...`);
236
+ await download(entry.url, tmp);
237
+ } catch (err) {
238
+ fs.rmSync(tmp, { force: true });
239
+ console.error(`@volcengine/ark-cli: download failed: ${err.message || err}`);
240
+ process.exit(1);
241
+ }
242
+
243
+ // sha256 完整性校验(烘焙时一定写入 entry.sha256)
244
+ if (entry.sha256) {
245
+ const actual = sha256(tmp);
246
+ if (actual !== entry.sha256) {
247
+ fs.rmSync(tmp, { force: true });
248
+ console.error(
249
+ `@volcengine/ark-cli: sha256 mismatch for ${key}\n` +
250
+ ` expected ${entry.sha256}\n` +
251
+ ` actual ${actual}`,
252
+ );
253
+ process.exit(1);
254
+ }
255
+ }
256
+
257
+ fs.renameSync(tmp, binPath);
258
+ if (platform !== "windows") {
259
+ fs.chmodSync(binPath, 0o755);
260
+ }
261
+ console.log(`@volcengine/ark-cli: installed ${path.basename(binPath)}`);
262
+
263
+ // CI 环境:不下 skill、不 +connect(无 agent 交互场景,且 CI 常无外网),直接收工。
264
+ if (process.env.CI === "true" || process.env.CI === "1") {
265
+ process.exit(0);
266
+ }
267
+
268
+ // —— Phase 2:下载 skill 到 <pkg>/skills/(对外不内嵌);失败仅告警不阻断 ——
269
+ try {
270
+ await installSkills();
271
+ } catch (err) {
272
+ console.warn(`@volcengine/ark-cli: skill install skipped (${err.message || err})`);
273
+ }
274
+
275
+ // —— +connect 把 skill 装到各 agent:增强项,失败不影响安装结果 ——
276
+ // 无 controlling tty 时静默跳过(管道 / Windows 无 /dev/tty 等)。
277
+ let ttyFd = null;
278
+ try {
279
+ ttyFd = fs.openSync("/dev/tty", "r+");
280
+ } catch (_) {
281
+ // no controlling tty (CI、管道、Windows 无 /dev/tty 等)
282
+ }
283
+ if (ttyFd === null) {
284
+ process.exit(0);
285
+ }
286
+ try {
287
+ execFileSync(binPath, ["+connect"], { stdio: ["ignore", ttyFd, ttyFd] });
288
+ } catch (err) {
289
+ try {
290
+ fs.writeSync(ttyFd, `arkcli: skill sync skipped (${err.message || err})\n`);
291
+ } catch (_) {}
292
+ }
293
+ try {
294
+ fs.closeSync(ttyFd);
295
+ } catch (_) {}
296
+ process.exit(0);
297
+ })();
package/scripts/run.js ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ // @volcengine/ark-cli npm bin wrapper。
3
+ // 二进制不内嵌在包里 —— 由 postinstall 按当前平台从 CDN 下载到 <pkg>/bin/,
4
+ // 这里只负责 exec 它。对外只有 arkcli 一个产品,故产品名硬编码。
5
+ const path = require("path");
6
+ const fs = require("fs");
7
+ const { execFileSync } = require("child_process");
8
+
9
+ const platformMap = { darwin: "darwin", linux: "linux", win32: "windows" };
10
+ const archMap = { x64: "amd64", arm64: "arm64" };
11
+ const platform = platformMap[process.platform];
12
+ const arch = archMap[process.arch];
13
+
14
+ if (!platform || !arch) {
15
+ console.error(`Unsupported platform: ${process.platform}-${process.arch}`);
16
+ process.exit(1);
17
+ }
18
+
19
+ const ext = platform === "windows" ? ".exe" : "";
20
+ const binary = path.join(__dirname, "..", "bin", `arkcli-${platform}-${arch}${ext}`);
21
+
22
+ if (!fs.existsSync(binary)) {
23
+ console.error(
24
+ `arkcli: binary not found at ${binary}\n` +
25
+ `安装时平台二进制可能下载失败。请尝试重新安装:\n` +
26
+ ` npm install -g @volcengine/ark-cli\n` +
27
+ `或手动重跑安装步骤:\n` +
28
+ ` node ${path.join(__dirname, "postinstall.js")}`,
29
+ );
30
+ process.exit(1);
31
+ }
32
+
33
+ try {
34
+ execFileSync(binary, process.argv.slice(2), { stdio: "inherit" });
35
+ } catch (err) {
36
+ process.exit(err.status || 1);
37
+ }