@byteplus/ark-cli 1.0.11-beta.c5c1095
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 +201 -0
- package/README.md +47 -0
- package/manifest.json +36 -0
- package/package.json +48 -0
- package/scripts/postinstall.js +376 -0
- package/scripts/run.js +46 -0
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,47 @@
|
|
|
1
|
+
# BytePlus Ark CLI
|
|
2
|
+
|
|
3
|
+
BytePlus Ark CLI provides command-line access and Agent Skills for BytePlus Ark. This repository contains the public English Skills distributed with the CLI and the documentation required to use them from supported AI coding agents.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm install -g @byteplus/ark-cli@latest
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
After installing the CLI, authenticate and install the bundled Skills into the supported local agents:
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
arkcli auth login
|
|
15
|
+
arkcli auth status
|
|
16
|
+
arkcli +connect
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
BytePlus CLI state is stored separately under `~/.arkcli-bp`.
|
|
20
|
+
|
|
21
|
+
## Skills
|
|
22
|
+
|
|
23
|
+
The [`skills/`](./skills) directory contains one capability-oriented Skill per Ark CLI domain. Each Skill uses the standard `SKILL.md` and `references/` layout and is written in English for BytePlus users.
|
|
24
|
+
|
|
25
|
+
The public Skill tree is derived from the Ark CLI source repository at a fixed commit. Product support is audited independently for BytePlus; the presence of a Skill documents the command surface and does not override the support status recorded by the product capability audit.
|
|
26
|
+
|
|
27
|
+
## Community
|
|
28
|
+
|
|
29
|
+
Scan the QR code to join the Ark CLI Lark user group for installation help, troubleshooting, bug reports, and usage discussions.
|
|
30
|
+
|
|
31
|
+
Do not share API keys, access keys, tokens, or other credentials in the group. For reproducible bugs, please also open a GitHub issue so the fix can be tracked.
|
|
32
|
+
|
|
33
|
+
<img src="./assets/lark-user-group.png" width="360" alt="Ark CLI Lark user group QR code" />
|
|
34
|
+
|
|
35
|
+
## Security
|
|
36
|
+
|
|
37
|
+
Do not disclose security issues through a public GitHub issue or the user group. Report them through the official BytePlus support channel.
|
|
38
|
+
|
|
39
|
+
## Links
|
|
40
|
+
|
|
41
|
+
- npm: <https://www.npmjs.com/package/@byteplus/ark-cli>
|
|
42
|
+
- GitHub Releases: <https://github.com/byteplus-sdk/ark-cli/releases>
|
|
43
|
+
- Bundled Skills: <https://github.com/byteplus-sdk/ark-cli/tree/main/skills>
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
The public Skills and documentation are licensed under the [Apache License 2.0](./LICENSE).
|
package/manifest.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"package": "@byteplus/ark-cli",
|
|
3
|
+
"version": "1.0.11-beta.c5c1095",
|
|
4
|
+
"platforms": {
|
|
5
|
+
"darwin-amd64": {
|
|
6
|
+
"kind": "cdn",
|
|
7
|
+
"url": "https://sf16-sg.tiktokcdn.com/obj/eden-sg/psjryh/ljhwZthlaukjlkulzlp/dev/1.0.11-beta.c5c1095/arkcli-1.0.11-beta.c5c1095-darwin-amd64",
|
|
8
|
+
"sha256": "1fb8f49003ebd81dd99ed797717a60efea5f32b7f79a7b9bda0d5ec5a9ca8de0"
|
|
9
|
+
},
|
|
10
|
+
"darwin-arm64": {
|
|
11
|
+
"kind": "cdn",
|
|
12
|
+
"url": "https://sf16-sg.tiktokcdn.com/obj/eden-sg/psjryh/ljhwZthlaukjlkulzlp/dev/1.0.11-beta.c5c1095/arkcli-1.0.11-beta.c5c1095-darwin-arm64",
|
|
13
|
+
"sha256": "0fc949769cb292140962b89dd53e587b08ded395aa33ceb7273e080f222d2287"
|
|
14
|
+
},
|
|
15
|
+
"linux-amd64": {
|
|
16
|
+
"kind": "cdn",
|
|
17
|
+
"url": "https://sf16-sg.tiktokcdn.com/obj/eden-sg/psjryh/ljhwZthlaukjlkulzlp/dev/1.0.11-beta.c5c1095/arkcli-1.0.11-beta.c5c1095-linux-amd64",
|
|
18
|
+
"sha256": "ea54a3ac95a787dd0ca6d3a3819fa1ee693983e4d35e402a4009228b59f73f7e"
|
|
19
|
+
},
|
|
20
|
+
"linux-arm64": {
|
|
21
|
+
"kind": "cdn",
|
|
22
|
+
"url": "https://sf16-sg.tiktokcdn.com/obj/eden-sg/psjryh/ljhwZthlaukjlkulzlp/dev/1.0.11-beta.c5c1095/arkcli-1.0.11-beta.c5c1095-linux-arm64",
|
|
23
|
+
"sha256": "46774c5e9b644a74b866ea800f5cf172b33f47d785a4d3fa225b1951b817c8ea"
|
|
24
|
+
},
|
|
25
|
+
"windows-amd64": {
|
|
26
|
+
"kind": "cdn",
|
|
27
|
+
"url": "https://sf16-sg.tiktokcdn.com/obj/eden-sg/psjryh/ljhwZthlaukjlkulzlp/dev/1.0.11-beta.c5c1095/arkcli-1.0.11-beta.c5c1095-windows-amd64.exe",
|
|
28
|
+
"sha256": "31d9b8e003996908d782bf68081c9c93a235df95706c4ab31acd6820ae4e9226"
|
|
29
|
+
},
|
|
30
|
+
"windows-arm64": {
|
|
31
|
+
"kind": "cdn",
|
|
32
|
+
"url": "https://sf16-sg.tiktokcdn.com/obj/eden-sg/psjryh/ljhwZthlaukjlkulzlp/dev/1.0.11-beta.c5c1095/arkcli-1.0.11-beta.c5c1095-windows-arm64.exe",
|
|
33
|
+
"sha256": "e377e8bb6f219dc370d0bcea4e1290191e2503e5a6aa282146c75f11cd9d602e"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@byteplus/ark-cli",
|
|
3
|
+
"version": "1.0.11-beta.c5c1095",
|
|
4
|
+
"description": "BytePlus Ark command-line interface",
|
|
5
|
+
"bin": {
|
|
6
|
+
"arkcli": "scripts/run.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"scripts/run.js",
|
|
10
|
+
"scripts/postinstall.js",
|
|
11
|
+
"manifest.json",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"postinstall": "node scripts/postinstall.js"
|
|
17
|
+
},
|
|
18
|
+
"arkcli": {
|
|
19
|
+
"product": "arkcli-bp",
|
|
20
|
+
"teaAppId": 1044680,
|
|
21
|
+
"teaUrl": "https://sgali-mcs.byteoversea.com/list"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=16"
|
|
29
|
+
},
|
|
30
|
+
"os": [
|
|
31
|
+
"darwin",
|
|
32
|
+
"linux",
|
|
33
|
+
"win32"
|
|
34
|
+
],
|
|
35
|
+
"cpu": [
|
|
36
|
+
"x64",
|
|
37
|
+
"arm64"
|
|
38
|
+
],
|
|
39
|
+
"license": "Apache-2.0",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/byteplus-sdk/ark-cli.git"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/byteplus-sdk/ark-cli#readme",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/byteplus-sdk/ark-cli/issues"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// Install the BytePlus binary from the manifest's SG CDN source first, then
|
|
5
|
+
// fall back to the matching byteplus-sdk/ark-cli GitHub Release asset. Both
|
|
6
|
+
// sources must match the same immutable SHA-256 digest.
|
|
7
|
+
|
|
8
|
+
const crypto = require("crypto");
|
|
9
|
+
const fs = require("fs");
|
|
10
|
+
const http = require("http");
|
|
11
|
+
const https = require("https");
|
|
12
|
+
const path = require("path");
|
|
13
|
+
const { execFileSync } = require("child_process");
|
|
14
|
+
const { Transform, pipeline } = require("stream");
|
|
15
|
+
|
|
16
|
+
const PACKAGE_NAME = "@byteplus/ark-cli";
|
|
17
|
+
const GITHUB_RELEASE_PREFIX = "/byteplus-sdk/ark-cli/releases/download/";
|
|
18
|
+
const MAX_REDIRECTS = 5;
|
|
19
|
+
const MAX_BINARY_BYTES = 256 * 1024 * 1024;
|
|
20
|
+
const DEFAULT_DOWNLOAD_TIMEOUT_MS = 30_000;
|
|
21
|
+
|
|
22
|
+
if (process.env.ARKCLI_SKIP_POSTINSTALL === "1") {
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const platformMap = { darwin: "darwin", linux: "linux", win32: "windows" };
|
|
27
|
+
const archMap = { x64: "amd64", arm64: "arm64" };
|
|
28
|
+
const platform = platformMap[process.platform];
|
|
29
|
+
const arch = archMap[process.arch];
|
|
30
|
+
if (!platform || !arch) {
|
|
31
|
+
console.error(`${PACKAGE_NAME}: unsupported platform ${process.platform}-${process.arch}`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function readJSON(file, label) {
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
38
|
+
} catch (err) {
|
|
39
|
+
throw new Error(`cannot read ${label}: ${err.message || err}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const packageRoot = path.join(__dirname, "..");
|
|
44
|
+
let packageJSON;
|
|
45
|
+
let manifest;
|
|
46
|
+
try {
|
|
47
|
+
packageJSON = readJSON(path.join(packageRoot, "package.json"), "package.json");
|
|
48
|
+
manifest = readJSON(path.join(packageRoot, "manifest.json"), "manifest.json");
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.error(`${PACKAGE_NAME}: ${err.message || err}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const stableVersionPattern = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/;
|
|
55
|
+
const betaProbeVersionPattern =
|
|
56
|
+
/^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-beta\.[0-9a-f]{7}$/;
|
|
57
|
+
const isStableVersion = stableVersionPattern.test(packageJSON.version || "");
|
|
58
|
+
const isBetaProbeVersion = betaProbeVersionPattern.test(packageJSON.version || "");
|
|
59
|
+
if (packageJSON.name !== PACKAGE_NAME || (!isStableVersion && !isBetaProbeVersion)) {
|
|
60
|
+
console.error(`${PACKAGE_NAME}: package identity is missing or malformed`);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
if (manifest.package !== PACKAGE_NAME || manifest.version !== packageJSON.version) {
|
|
64
|
+
console.error(
|
|
65
|
+
`${PACKAGE_NAME}: manifest identity mismatch (package=${manifest.package || "<missing>"}, version=${manifest.version || "<missing>"})`,
|
|
66
|
+
);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const key = `${platform}-${arch}`;
|
|
71
|
+
const entry = manifest.platforms && manifest.platforms[key];
|
|
72
|
+
if (!entry || entry.kind !== "cdn" || typeof entry.url !== "string") {
|
|
73
|
+
console.error(`${PACKAGE_NAME}: manifest has no CDN binary entry for ${key}`);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
if (!/^[0-9a-f]{64}$/i.test(entry.sha256 || "")) {
|
|
77
|
+
console.error(`${PACKAGE_NAME}: manifest has a missing or malformed sha256 for ${key}`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
if (isStableVersion) {
|
|
81
|
+
if (
|
|
82
|
+
!entry.fallback ||
|
|
83
|
+
entry.fallback.kind !== "github-release" ||
|
|
84
|
+
typeof entry.fallback.url !== "string"
|
|
85
|
+
) {
|
|
86
|
+
console.error(`${PACKAGE_NAME}: manifest has no GitHub Release fallback for ${key}`);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
} else if (Object.prototype.hasOwnProperty.call(entry, "fallback")) {
|
|
90
|
+
console.error(`${PACKAGE_NAME}: temporary beta manifest must be CDN-only for ${key}`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const allowTestHTTP = process.env.ARKCLI_POSTINSTALL_ALLOW_HTTP_FOR_TESTS === "1";
|
|
95
|
+
const testTimeout = Number(process.env.ARKCLI_POSTINSTALL_TIMEOUT_MS_FOR_TESTS || 0);
|
|
96
|
+
const downloadTimeoutMS =
|
|
97
|
+
allowTestHTTP && Number.isInteger(testTimeout) && testTimeout >= 50 && testTimeout <= 30_000
|
|
98
|
+
? testTimeout
|
|
99
|
+
: DEFAULT_DOWNLOAD_TIMEOUT_MS;
|
|
100
|
+
|
|
101
|
+
function isLoopback(hostname) {
|
|
102
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function checkedURL(raw, kind, initial) {
|
|
106
|
+
let parsed;
|
|
107
|
+
try {
|
|
108
|
+
parsed = new URL(raw);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
throw new Error(`${kind} URL is malformed: ${err.message || err}`);
|
|
111
|
+
}
|
|
112
|
+
if (parsed.username || parsed.password) {
|
|
113
|
+
throw new Error(`${kind} URL must not contain credentials`);
|
|
114
|
+
}
|
|
115
|
+
const testLoopback =
|
|
116
|
+
allowTestHTTP && parsed.protocol === "http:" && isLoopback(parsed.hostname);
|
|
117
|
+
if (parsed.protocol !== "https:") {
|
|
118
|
+
if (!testLoopback) {
|
|
119
|
+
throw new Error(`${kind} URL is rejected: HTTPS is required`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (
|
|
123
|
+
initial &&
|
|
124
|
+
kind === "github-release" &&
|
|
125
|
+
!testLoopback &&
|
|
126
|
+
(parsed.hostname !== "github.com" || !parsed.pathname.startsWith(GITHUB_RELEASE_PREFIX))
|
|
127
|
+
) {
|
|
128
|
+
throw new Error(`${kind} URL must target byteplus-sdk/ark-cli releases`);
|
|
129
|
+
}
|
|
130
|
+
return parsed;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function download(
|
|
134
|
+
rawURL,
|
|
135
|
+
destination,
|
|
136
|
+
kind,
|
|
137
|
+
redirects = 0,
|
|
138
|
+
deadline = Date.now() + downloadTimeoutMS,
|
|
139
|
+
) {
|
|
140
|
+
if (redirects > MAX_REDIRECTS) {
|
|
141
|
+
return Promise.reject(new Error(`${kind} exceeded ${MAX_REDIRECTS} redirects`));
|
|
142
|
+
}
|
|
143
|
+
const remaining = deadline - Date.now();
|
|
144
|
+
if (remaining <= 0) {
|
|
145
|
+
return Promise.reject(new Error(`${kind} exceeded the total download deadline`));
|
|
146
|
+
}
|
|
147
|
+
let parsed;
|
|
148
|
+
try {
|
|
149
|
+
parsed = checkedURL(rawURL, kind, redirects === 0);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
return Promise.reject(err);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return new Promise((resolve, reject) => {
|
|
155
|
+
let settled = false;
|
|
156
|
+
let activeResponse = null;
|
|
157
|
+
let wallTimer = null;
|
|
158
|
+
const resolveOnce = (value) => {
|
|
159
|
+
if (settled) return;
|
|
160
|
+
settled = true;
|
|
161
|
+
if (wallTimer !== null) clearTimeout(wallTimer);
|
|
162
|
+
resolve(value);
|
|
163
|
+
};
|
|
164
|
+
const rejectOnce = (err) => {
|
|
165
|
+
if (settled) return;
|
|
166
|
+
settled = true;
|
|
167
|
+
if (wallTimer !== null) clearTimeout(wallTimer);
|
|
168
|
+
reject(err);
|
|
169
|
+
};
|
|
170
|
+
const transport = parsed.protocol === "http:" ? http : https;
|
|
171
|
+
const request = transport.get(parsed, (response) => {
|
|
172
|
+
activeResponse = response;
|
|
173
|
+
if (
|
|
174
|
+
response.statusCode >= 300 &&
|
|
175
|
+
response.statusCode < 400 &&
|
|
176
|
+
response.headers.location
|
|
177
|
+
) {
|
|
178
|
+
let next;
|
|
179
|
+
try {
|
|
180
|
+
next = new URL(response.headers.location, parsed).toString();
|
|
181
|
+
} catch (err) {
|
|
182
|
+
response.destroy();
|
|
183
|
+
rejectOnce(new Error(`${kind} redirect URL is malformed: ${err.message || err}`));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
response.destroy();
|
|
187
|
+
resolveOnce(download(next, destination, kind, redirects + 1, deadline));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (response.statusCode !== 200) {
|
|
191
|
+
response.destroy();
|
|
192
|
+
rejectOnce(new Error(`HTTP ${response.statusCode} for ${kind}`));
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const declaredLength = Number(response.headers["content-length"] || 0);
|
|
197
|
+
if (declaredLength > MAX_BINARY_BYTES) {
|
|
198
|
+
response.destroy();
|
|
199
|
+
rejectOnce(new Error(`${kind} binary exceeds ${MAX_BINARY_BYTES} bytes`));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
let received = 0;
|
|
204
|
+
const limiter = new Transform({
|
|
205
|
+
transform(chunk, encoding, callback) {
|
|
206
|
+
received += chunk.length;
|
|
207
|
+
if (received > MAX_BINARY_BYTES) {
|
|
208
|
+
callback(new Error(`${kind} binary exceeds ${MAX_BINARY_BYTES} bytes`));
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
callback(null, chunk);
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
const output = fs.createWriteStream(destination, { flags: "wx", mode: 0o600 });
|
|
215
|
+
pipeline(response, limiter, output, (err) => {
|
|
216
|
+
if (err) {
|
|
217
|
+
rejectOnce(err);
|
|
218
|
+
} else if (received === 0) {
|
|
219
|
+
rejectOnce(new Error(`${kind} returned an empty binary`));
|
|
220
|
+
} else {
|
|
221
|
+
resolveOnce();
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
wallTimer = setTimeout(() => {
|
|
226
|
+
const err = new Error(`${kind} exceeded the total download deadline`);
|
|
227
|
+
if (activeResponse !== null) activeResponse.destroy(err);
|
|
228
|
+
request.destroy(err);
|
|
229
|
+
rejectOnce(err);
|
|
230
|
+
}, remaining);
|
|
231
|
+
request.setTimeout(Math.min(DEFAULT_DOWNLOAD_TIMEOUT_MS, remaining), () => {
|
|
232
|
+
request.destroy(new Error(`${kind} download timed out`));
|
|
233
|
+
});
|
|
234
|
+
request.on("error", rejectOnce);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function sha256(file) {
|
|
239
|
+
return new Promise((resolve, reject) => {
|
|
240
|
+
const hash = crypto.createHash("sha256");
|
|
241
|
+
const input = fs.createReadStream(file);
|
|
242
|
+
input.on("error", reject);
|
|
243
|
+
hash.on("error", reject);
|
|
244
|
+
hash.on("finish", () => resolve(hash.digest("hex")));
|
|
245
|
+
input.pipe(hash);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async function downloadVerifiedBinary(sources, destination, expectedSHA) {
|
|
250
|
+
const errors = [];
|
|
251
|
+
for (const source of sources) {
|
|
252
|
+
fs.rmSync(destination, { force: true });
|
|
253
|
+
try {
|
|
254
|
+
console.log(`${PACKAGE_NAME}: downloading ${key} binary from ${source.kind}...`);
|
|
255
|
+
await download(source.url, destination, source.kind);
|
|
256
|
+
const actual = await sha256(destination);
|
|
257
|
+
if (actual !== expectedSHA.toLowerCase()) {
|
|
258
|
+
throw new Error(`sha256 mismatch (expected ${expectedSHA}, actual ${actual})`);
|
|
259
|
+
}
|
|
260
|
+
return source;
|
|
261
|
+
} catch (err) {
|
|
262
|
+
fs.rmSync(destination, { force: true });
|
|
263
|
+
const detail = err.message || String(err);
|
|
264
|
+
errors.push(`${source.kind}: ${detail}`);
|
|
265
|
+
console.warn(`${PACKAGE_NAME}: ${source.kind} binary source failed: ${detail}`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
throw new Error(errors.join("; "));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function recoverInterruptedInstall(binary, backup) {
|
|
272
|
+
if (!fs.existsSync(backup)) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (fs.existsSync(binary)) {
|
|
276
|
+
fs.rmSync(backup, { force: true });
|
|
277
|
+
} else {
|
|
278
|
+
fs.renameSync(backup, binary);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async function install() {
|
|
283
|
+
const ext = platform === "windows" ? ".exe" : "";
|
|
284
|
+
const binDir = path.join(packageRoot, "bin");
|
|
285
|
+
const binPath = path.join(binDir, `arkcli-${platform}-${arch}${ext}`);
|
|
286
|
+
const tempPath = `${binPath}.download-${process.pid}`;
|
|
287
|
+
const backupPath = `${binPath}.backup`;
|
|
288
|
+
const injectedFailure = allowTestHTTP
|
|
289
|
+
? process.env.ARKCLI_POSTINSTALL_FAIL_STEP_FOR_TESTS || ""
|
|
290
|
+
: "";
|
|
291
|
+
const failStepForTests = (step) => {
|
|
292
|
+
if (injectedFailure === step) {
|
|
293
|
+
throw new Error(`injected ${step} failure`);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
297
|
+
recoverInterruptedInstall(binPath, backupPath);
|
|
298
|
+
|
|
299
|
+
let installedFrom;
|
|
300
|
+
try {
|
|
301
|
+
const sources = [{ kind: "cdn", url: entry.url }];
|
|
302
|
+
if (isStableVersion) {
|
|
303
|
+
sources.push({ kind: "github-release", url: entry.fallback.url });
|
|
304
|
+
}
|
|
305
|
+
installedFrom = await downloadVerifiedBinary(sources, tempPath, entry.sha256);
|
|
306
|
+
} catch (err) {
|
|
307
|
+
fs.rmSync(tempPath, { force: true });
|
|
308
|
+
throw new Error(`binary download failed: ${err.message || err}`);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
let oldMoved = false;
|
|
312
|
+
let newInstalled = false;
|
|
313
|
+
try {
|
|
314
|
+
if (platform !== "windows") {
|
|
315
|
+
failStepForTests("chmod-temp");
|
|
316
|
+
fs.chmodSync(tempPath, 0o755);
|
|
317
|
+
}
|
|
318
|
+
if (fs.existsSync(binPath)) {
|
|
319
|
+
failStepForTests("move-old");
|
|
320
|
+
fs.renameSync(binPath, backupPath);
|
|
321
|
+
oldMoved = true;
|
|
322
|
+
}
|
|
323
|
+
failStepForTests("install-new");
|
|
324
|
+
fs.renameSync(tempPath, binPath);
|
|
325
|
+
newInstalled = true;
|
|
326
|
+
fs.rmSync(backupPath, { force: true });
|
|
327
|
+
} catch (err) {
|
|
328
|
+
fs.rmSync(tempPath, { force: true });
|
|
329
|
+
if (newInstalled) {
|
|
330
|
+
fs.rmSync(binPath, { force: true });
|
|
331
|
+
}
|
|
332
|
+
if (oldMoved && fs.existsSync(backupPath)) {
|
|
333
|
+
fs.renameSync(backupPath, binPath);
|
|
334
|
+
}
|
|
335
|
+
throw new Error(`cannot install verified binary: ${err.message || err}`);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
console.log(`${PACKAGE_NAME}: installed ${path.basename(binPath)} from ${installedFrom.kind}`);
|
|
339
|
+
|
|
340
|
+
if (process.env.CI === "true" || process.env.CI === "1") {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
let tty = null;
|
|
345
|
+
try {
|
|
346
|
+
tty = fs.openSync("/dev/tty", "r+");
|
|
347
|
+
} catch (_) {
|
|
348
|
+
// A controlling terminal is optional; +connect is still non-interactive.
|
|
349
|
+
}
|
|
350
|
+
const stdio = tty === null ? "inherit" : ["ignore", tty, tty];
|
|
351
|
+
try {
|
|
352
|
+
execFileSync(binPath, ["+connect", "--refresh"], { stdio });
|
|
353
|
+
} catch (err) {
|
|
354
|
+
const message =
|
|
355
|
+
`${PACKAGE_NAME}: Skill sync skipped (${err.message || err}). ` +
|
|
356
|
+
"Run `arkcli +connect --refresh` to retry.";
|
|
357
|
+
if (tty === null) {
|
|
358
|
+
console.warn(message);
|
|
359
|
+
} else {
|
|
360
|
+
try {
|
|
361
|
+
fs.writeSync(tty, `${message}\n`);
|
|
362
|
+
} catch (_) {}
|
|
363
|
+
}
|
|
364
|
+
} finally {
|
|
365
|
+
if (tty !== null) {
|
|
366
|
+
try {
|
|
367
|
+
fs.closeSync(tty);
|
|
368
|
+
} catch (_) {}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
install().catch((err) => {
|
|
374
|
+
console.error(`${PACKAGE_NAME}: ${err.message || err}`);
|
|
375
|
+
process.exit(1);
|
|
376
|
+
});
|
package/scripts/run.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const { execFileSync } = require("child_process");
|
|
7
|
+
|
|
8
|
+
const PACKAGE_NAME = "@byteplus/ark-cli";
|
|
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(`${PACKAGE_NAME}: 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
|
+
let binaryReady = false;
|
|
23
|
+
try {
|
|
24
|
+
const info = fs.lstatSync(binary);
|
|
25
|
+
binaryReady = info.isFile() && !info.isSymbolicLink();
|
|
26
|
+
} catch (_) {
|
|
27
|
+
// The repair guidance below covers missing and unreadable binaries.
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!binaryReady) {
|
|
31
|
+
console.error(
|
|
32
|
+
`${PACKAGE_NAME}: binary not found at ${binary}\n` +
|
|
33
|
+
`Reinstall the package with:\n npm install -g ${PACKAGE_NAME}\n` +
|
|
34
|
+
`or retry the install step with:\n node ${path.join(__dirname, "postinstall.js")}`,
|
|
35
|
+
);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
execFileSync(binary, process.argv.slice(2), { stdio: "inherit" });
|
|
41
|
+
} catch (err) {
|
|
42
|
+
if (err.signal) {
|
|
43
|
+
process.kill(process.pid, err.signal);
|
|
44
|
+
}
|
|
45
|
+
process.exit(Number.isInteger(err.status) ? err.status : 1);
|
|
46
|
+
}
|