@xkiro/code 0.0.0-stage → 2.5.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.
- package/LICENSE +202 -0
- package/NOTICE.md +133 -0
- package/README.md +43 -2
- package/bin/xkcode.js +506 -0
- package/package.json +47 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Z.AI Co., Ltd
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# xKCode notice
|
|
2
|
+
|
|
3
|
+
xKCode includes software derived from ZCode (https://github.com/zai-org/ZCode), licensed under the Apache License,
|
|
4
|
+
Version 2.0; a copy of that license is in LICENSE. Third-party software included in xKCode, with its license texts, is
|
|
5
|
+
listed in THIRD-PARTY-NOTICES.md.
|
|
6
|
+
|
|
7
|
+
## Network services
|
|
8
|
+
|
|
9
|
+
- **xKiro account and models.** Your xKiro account and the xKiro model gateway use https://api.xkiro.com. When a task
|
|
10
|
+
runs on an xKiro model, the request — your prompt and the conversation, including any file contents and tool results
|
|
11
|
+
the task sends to the model — goes there.
|
|
12
|
+
- **Sign-in.** Signing in opens xKiro's sign-in page on xkiro.com in your browser; after you approve, the app receives
|
|
13
|
+
an API key for your account from https://api.xkiro.com.
|
|
14
|
+
- **Other model providers.** If you add another provider with your own API key, requests for that provider's models
|
|
15
|
+
go to the endpoint you configured for it, not to xKiro.
|
|
16
|
+
- **Crash and error reports.** Starting with the desktop app and the `xkcode` CLI 2.0.4 and the VS Code extension
|
|
17
|
+
0.2.6, release builds send crash and error reports to https://api.xkiro.com, which forwards them to Sentry
|
|
18
|
+
(sentry.io), the service that processes them for xKiro. No performance measurements are sent. Reporting starts only
|
|
19
|
+
after a one-time notice; the VS Code extension also follows VS Code's `telemetry.telemetryLevel` setting. Reports are
|
|
20
|
+
masked on your machine and contain no prompts, chat messages, file contents, commands or keys, except common English
|
|
21
|
+
words that appear in an error message.
|
|
22
|
+
Turn reporting off in Settings → General → Privacy, with **Turn Off** in the extension's notice, or by setting
|
|
23
|
+
`XKCODE_DISABLE_ERROR_REPORTING=1`, `XKCODE_DISABLE_TELEMETRY=1` or `DO_NOT_TRACK=1`. Releases up to desktop / CLI
|
|
24
|
+
2.0.3 and extension 0.2.5 send no reports. Details: https://xkiro.com/privacy.
|
|
25
|
+
- **Updates.** In builds with update checks enabled (the Windows installer from xkiro.com, not the Microsoft Store
|
|
26
|
+
build), the desktop app checks https://dl.xkiro.com for a new version of the app and asks before installing it; the
|
|
27
|
+
check sends no account information. The `xkcode update` command downloads new CLI releases from
|
|
28
|
+
https://dl.xkiro.com. Every update is verified (signed release manifest and checksum) before it is installed.
|
|
29
|
+
- **Plugins.** Installing a plugin from the built-in marketplace downloads it from the address listed for that plugin
|
|
30
|
+
in the marketplace catalog.
|
|
31
|
+
|
|
32
|
+
## Your responsibility
|
|
33
|
+
|
|
34
|
+
AI-generated code, commands and answers can be wrong or unsafe. Tools that run in xKCode (files, terminal, Git,
|
|
35
|
+
plugins, MCP servers, hooks) act with the permissions of your operating-system account. Review what an agent is about
|
|
36
|
+
to do before you approve it, and keep backups of work you cannot afford to lose.
|
|
37
|
+
|
|
38
|
+
## Code from other open-source projects
|
|
39
|
+
|
|
40
|
+
- **opencode** (https://github.com/anomalyco/opencode) — MIT License, Copyright (c) 2025 opencode. Parts of the
|
|
41
|
+
terminal interface, the session database schema and the patch engine of the file-editing tool come from opencode.
|
|
42
|
+
- **OpenAI Codex** (https://github.com/openai/codex) — Apache License, Version 2.0. OpenAI Codex, Copyright 2025
|
|
43
|
+
OpenAI. Some wording of the goal tool's prompt comes from Codex, and the file-editing tool accepts Codex's patch
|
|
44
|
+
format.
|
|
45
|
+
|
|
46
|
+
The full license and notice texts of these projects are in THIRD-PARTY-NOTICES.md.
|
|
47
|
+
|
|
48
|
+
The source tree also keeps the upstream `design-plugin` package (its design resources derive from the open-design
|
|
49
|
+
project, MIT, with license texts inside the package). It is not registered and is not included in any xKCode build, so
|
|
50
|
+
it is not part of xKCode releases.
|
|
51
|
+
|
|
52
|
+
## Original ZCode NOTICE, retained per Apache-2.0 §4(d)
|
|
53
|
+
|
|
54
|
+
The NOTICE file of ZCode is reproduced unchanged below. It describes the original ZCode product and its services, not
|
|
55
|
+
xKCode.
|
|
56
|
+
|
|
57
|
+
<!-- BEGIN ORIGINAL ZCODE NOTICE (verbatim) -->
|
|
58
|
+
|
|
59
|
+
# ZCode 相关功能说明与第三方组件声明
|
|
60
|
+
|
|
61
|
+
本声明适用于本仓库公开的源码及其构建产物。各运行形态的功能、权限、存储位置和网络行为不同,不能将其中一种形态的默认设置理解为整个项目的统一设置。
|
|
62
|
+
|
|
63
|
+
## 一、AI 输出、执行权限与自动化风险
|
|
64
|
+
|
|
65
|
+
AI 生成的代码、命令、解释、文件和建议可能存在错误、遗漏、安全缺陷或第三方权利问题。应结合实际文件、命令退出状态、工具结果和测试核查;模型声称“已完成”“已安全处理”或“已获授权”不构成事实或授权证明。重要操作前应审查执行目标、接收方及影响,并保留可恢复的备份。
|
|
66
|
+
|
|
67
|
+
文件、终端、Git、Agent 工具及外部进程可在实际运行它们的操作系统账号权限范围内读写文件、启动进程和访问网络。在 Web 或远端工作区中,操作可能发生在服务端、SSH 主机、WSL 或容器环境,不能仅凭当前页面所在设备判断执行位置。当前共享 Agent 执行适配器不提供默认的操作系统沙箱;工作目录、工作区身份、Git worktree、浏览器页面隔离和 Node REPL 的运行上下文,均不应被当作所有工具的系统级隔离保证。
|
|
68
|
+
|
|
69
|
+
共享运行配置默认采用 `build` 权限模式;独立 CLI 通过 `--prompt` 执行非交互任务时,未指定 `--mode` 会采用 `yolo`。交互会话、桌面会话、恢复的任务及宿主可使用各自配置、保存或传入的模式。是否逐次确认受工具声明、权限规则及运行模式影响;未同时启用只读规划约束的 `yolo` 会放行普通工具操作,交互类工具和明确要求确认的工具仍有各自规则。模型工具审批不是整个应用的统一权限开关,不能据此推定终端操作、插件进程或更新下载都会经过同一审批流程。具体见 [CLI 提示词模式](apps/zcode-cli/packages/cli/src/run.ts#L486)及[工具权限判断](apps/zcode-cli/packages/core/src/permission/service.ts#L97)。
|
|
70
|
+
|
|
71
|
+
| 能力或业务钩子 | 可能产生的影响及边界 |
|
|
72
|
+
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
73
|
+
| 文件、Git、终端、Shell、Node REPL | 可读写或删除数据、运行程序和访问网络;Git、包管理器及用户命令还可能触发其自身脚本和钩子。任务快照、Git 检查点和会话恢复不能替代对全部本地文件、数据库及外部服务的备份。 |
|
|
74
|
+
| 用户及工作区指令、技能 | 工作区指令文件、技能文本、模板和脚本会影响模型计划;读取、安装或展示它们不代表内容可信、合法或经过官方安全审查。 |
|
|
75
|
+
| 生命周期 Hooks | `SessionStart`、`UserPromptSubmit`、`PreToolUse`、`PermissionRequest`、`PostToolUse`、`PostToolUseFailure`、`Stop` 可触发命令或进程。输入可能包含提示词、工作路径、工具参数、工具结果和回复;Hook 还可补充上下文、改写工具输入或参与权限决策。 |
|
|
76
|
+
| 工作区 Hook 信任 | 工作区 Hook 按工作区身份和声明摘要审查;声明变化会使原信任失效。该机制不等于对插件 Hook、MCP 配置或其他项目脚本的统一审核。 |
|
|
77
|
+
| 插件与 MCP | 启用插件可以带入自动执行的 Hook、本地程序和远端工具。当前 Agent 运行配置将工作区级 MCP 纳入自动连接范围;启用 MCP 并启动运行时时,可能使用配置中的命令、环境变量、认证头或 OAuth 连接服务。插件 Hook 与工作区 Hook 使用不同准入路径。 |
|
|
78
|
+
| 启动与安装脚本 | 桌面或终端为获取 Shell 环境可能执行登录 Shell 及其启动配置;依赖安装也可运行原生模块构建等生命周期脚本。相关脚本可能早于模型任务运行,不应理解为仅执行模型逐项批准的命令。 |
|
|
79
|
+
| 子代理、工作流与后台任务 | 可继续调用模型、执行命令并产生费用或外部副作用。停止会话、切换页面或取消某次请求,不能撤销已经完成的文件写入、发布、上传或其他外部操作。 |
|
|
80
|
+
| 桌面定时任务与闲时任务 | 在调度器及执行宿主可用时按所存配置运行,可在窗口隐藏后继续执行。关闭窗口可能只是隐藏到后台或托盘;显式退出、休眠、断网、账号或模型不可用都可能影响执行。不能保证关机后仍运行或错过的任务一定补跑;独立 CLI 也不因包含 Cron 工具就自动具备持久调度服务。 |
|
|
81
|
+
| 内嵌浏览器与 Browser Use | 可访问网页、读取页面内容、截图或录制页面,并执行点击、输入、上传和下载。经用户操作导入或复用的浏览器登录状态可能允许访问私人数据、提交表单或改变远端账号中的内容;访问网页本身也会与网站及其加载的服务通信。 |
|
|
82
|
+
| Computer Use | 本仓库随附的 Computer Use 包为不可用占位实现,调用会返回不可用错误,不提供系统截图或操作能力。具体见 [Computer Use 入口](packages/zcode-cua/index.js#L3)。 |
|
|
83
|
+
| Web 服务与远端运行环境 | 网络可达范围、登录认证、进程账号和文件权限由具体部署共同决定。认证默认值因启动入口和监听地址而异;本机监听、来源检查和 SSH 通道各自控制不同边界,不能把开发服务或本机核心端口直接视为适合公开暴露的服务。 |
|
|
84
|
+
| 内容分享、导入与资源预览 | 可能读取或传输对话、代码、附件及生成物。导入的共享上下文、网页和文件属于外部输入,不能因来源显示为 ZCode 链接就自动视为可信指令或取得其中内容的版权授权。 |
|
|
85
|
+
|
|
86
|
+
网页、仓库内容、工具返回值和第三方指令可能包含诱导模型执行额外操作的内容。处理不可信项目时,应限制运行账号、凭据和网络权限,并审查敏感操作。
|
|
87
|
+
|
|
88
|
+
自行部署 Web 或远端服务时,应按实际入口配置认证、传输保护和访问控制;应用账号登录不能代替部署层的安全边界。Web 启动参数和认证配置见 [README 运行说明](README.md#zcode-命令行版)。独立远端服务核心仅接受本机回环监听地址,未提供同等的外部账号鉴权。HTTP/WS 与 HTTPS/WSS、SSH 的保护条件不同,不保证所有部署默认加密,也不保证远端主机或服务运营者无法访问其处理的数据。远端核心的限制见 [监听规则](packages/zcode-server-cli/src/server-core/http.ts#L115)。
|
|
89
|
+
|
|
90
|
+
## 二、上传接口、对外请求与业务用途
|
|
91
|
+
|
|
92
|
+
| 业务场景 | 业务用途、触发条件与数据范围 |
|
|
93
|
+
| ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
94
|
+
| 模型与辅助模型请求 | 任务执行、压缩、标题、记忆、历史会话提取、目标完成验证、AI Git 提交信息生成和模型连通性测试可调用模型;部分辅助调用随任务自动触发。发送相关提示词、历史、代码、diff、工具结果或附件,具体范围依功能而异,连接测试使用固定探测消息。请求还可带认证信息、客户端环境及会话/请求/追踪标识;Anthropic 兼容调用会附加设备和会话标识。接收方取决于实际端点、下述网关转发及代理配置,不能只凭 SDK 名称判断。 |
|
|
95
|
+
| 登录、授权、账号与 API 凭据 | 登录、授权码交换、登录状态轮询、账号及权益查询可发送授权状态、code、访问令牌、轮询凭据和客户端标识;登录后或账号配置解析时,可能自动查询、获取或创建项目 API Key,已订阅团队项目也可在定价刷新中创建缺少的 Key。内嵌套餐页面可向通过来源检查的页面传递登录凭据、语言和主题,并提供设备标识、账号标识和应用版本。当前内置账号适配器未实现账号刷新令牌交换;MCP OAuth 的自动刷新另见“MCP 连接、OAuth 与工具调用”。账号认证证明访问身份,不代表每项后续发送都有独立用户确认;外部授权网页的内部处理未在本仓核验。 |
|
|
96
|
+
| 套餐、订单、支付与额度 | 额度重置及相关状态同步可向业务服务发送账号凭据、个人或团队/项目范围、重置类型和幂等标识;机会请求、状态轮询和已读核销可自动触发。仓库提供已注册的订单试算/创建/取消、续订、支付方式管理及支付服务,调用时可发送产品、订单、支付方式或授权标识、金额、订阅选项及调用方提供的渠道或追踪字段;服务方法存在不代表各发行形态均有可用购买界面,也不代表打开页面即发起付款。 |
|
|
97
|
+
| 官方 Coding Plan 模型网关转发 | 当前对代码列出的两个官方 Anthropic 兼容模型端点按协议、主机、有效端口和路径匹配;命中时自动改发 ZCode 网关,保留请求方法、正文、查询参数及除 Host 外的请求头,包括请求中的认证信息。实际网关 origin 可由 ZCODE_BASE_URL/ZCODE_ENDPOINT_ORIGIN 配置改变。此转发未设置额外的逐次用户确认;判断依据是请求 URL,不能因提供商由用户自行创建就推定一定绕过网关。网关收到请求后的内部处理不属于客户端源码已核验范围。 |
|
|
98
|
+
| 提供商、业务配置与连通性检查 | 启动后的后台检查、配置刷新、服务检查或相关页面活动可访问提供商目录、业务配置、帮助内容和 CDN,发送请求 URL、版本、平台及按接口装配的来源信息;帮助配置请求还可携带设备标识,服务连通性检查可携带配置的认证头。提供商目录下载及公开配置读取不继承控制面认证。部分请求独立于模型任务运行,不要求每次手动刷新。模型连接测试另走模型请求链路;检查服务方法的存在不代表所有检查在启动时自动执行。 |
|
|
99
|
+
| 搜索、网页处理与远程资源 | 模型工具、用户页面访问或资源展示可向模型提供商、目标网站及资源服务发送查询、URL、请求头和普通网络信息。当前 WebSearch 通过支持原生搜索的模型提供商执行;WebFetch 抓取的内容还可能连同处理提示发送给模型,不应把网页下载理解为后续仅在本地处理。网页、插件市场图片及其他远程资源的接收方可获得访问请求及 IP 等信息。 |
|
|
100
|
+
| MCP 连接、OAuth 与工具调用 | 启用 MCP 且运行时加载对应配置后,可自动连接工作区或插件声明的服务、协商协议和发现工具;OAuth 还可进行发现、客户端注册、授权交换及自动令牌刷新。工具调用发送参数,并可自动附加工作区绝对路径、工作区身份、会话/轮次/追踪及远端会话标识。HTTP/SSE 向配置的服务发送;stdio 先交给本地或执行主机上的进程,其后续网络行为取决于该程序。工具审批不统一覆盖连接、发现和刷新流程。 |
|
|
101
|
+
| SSH/WSL/容器及其他执行环境 | 建立连接或执行任务后,可跨环境传递协议命令、提示词、文件、附件、工具结果和终端状态。个人提供商配置、账号选择设置及允许同步的账号 API Key、OAuth 访问/刷新令牌等可在环境首次上线以及连接存续期间相关配置或凭据变化时自动传入目标环境;该同步没有单独的逐项凭据确认步骤。SSH 可涉及网络传输,WSL/容器也可使用文件拷贝或进程输入;这些传输不必然到官方云端。 |
|
|
102
|
+
| Skills、MCP、插件与配置同步 | 设置界面选择并同步时,可将技能或插件目录、支持文件、市场来源及配置传至目标环境;服务接口也可由调用方直接调用。技能同步可包含选中目录内的文件,MCP 配置可含命令参数、环境变量、请求头、认证信息和本机路径。部分插件选项有敏感字段筛选,但不构成对目录归档和所有配置的全面秘密检测。 |
|
|
103
|
+
| 附件传输与媒体预览 | 文件、图片或文本可以来自选择、拖放、粘贴及任务产生的内容。附件加入输入区并具备执行会话后,可能在点击发送消息前开始预传输,恢复会话也可能继续处理队列。本地文件路径可直接引用而不上传;协议分块上传或远端预传输的接收方是执行主机。远端媒体预览也可能从该主机读取回本机。上述本地或跨环境处理不等于公开发布;内容随后仍可能按任务进入模型或分享链路。 |
|
|
104
|
+
| 会话分享、浏览与导入 | 分享操作可向分享服务提交选中会话行的公开投影及可物化附件,包含用户文本、模型回复与推理文本、工具输入输出和相关元数据。选择阶段可先查询分享服务能力,该能力请求不发送会话投影正文。正常 UI 发布流程要求先确认披露,服务也先校验调用方提交的确认时间,再创建准备记录、上传附件,最后提交发布确认;因此附件可在最终发布成功前已发送,但准备/上传步骤位于服务的披露校验之后。当前 UI 默认公开可导入,浏览与导入不以发布勾选为前提。确认时间字段不能证明任意调用方都经过 UI 勾选。浏览与导入会发送分享码和可用认证信息,并访问附件下载地址;导入还会发送请求标识。投影过滤和文本处理不是全面秘密检测;本地删除或取消不保证外部已上传副本或接收者副本被删除。 |
|
|
105
|
+
| 闲时任务票据与状态同步 | 可用性查询、取号排队、票据状态同步及核销会发送任务标识、票据标识、来源/请求标识、Coding Plan 身份及认证信息。存在待处理票据等条件时,后台同步可持续请求;这类请求不等于发送完整任务提示词,实际模型内容另走模型链路。 |
|
|
106
|
+
| 主动反馈、补充消息与诊断附件 | 用户通过反馈表单提交时,可发送正文、联系方式、账号和客户端信息、截图及文件名;服务仍提供补充消息和附件上传接口,后台任务也会用消息接口报告上传结果,接口存在不代表当前界面提供后续补充编辑入口。工单创建成功后可收起表单,已提交的截图和勾选的日志由后台任务继续上传;工单创建成功前退出表单会请求取消创建。附件先向反馈服务申请上传凭证,再向返回的对象存储地址直传文件。桌面日志选项默认不勾选;勾选后按本地当天修改时间和归档规则选取诊断日志文件,并处理文件全文,不保证仅含当天产生的条目。未勾选日志不影响正文或其他附件,文本处理规则也不保证截图和任意文件已脱敏。 |
|
|
107
|
+
| 手机远程控制 | 启用远程控制并完成配对后,桌面与手机网页经外部 relay 交换会话内容、输入、任务状态、权限请求与附件预览等协议消息;relay 负责鉴权、配对、心跳与消息透传,不运行任务。配对与连接会发送设备、窗口与会话标识。relay 地址随发行配置确定,可由 `ZCODE_WEB_REMOTE_CONTROL_RELAY_WS_URL` 覆盖。 |
|
|
108
|
+
| Bots 第三方聊天接入 | 配置 Bot 后,所选第三方聊天平台(如 Telegram、飞书/Lark)的消息可驱动任务;Bot 按回复模式把助手回复、工具调用、文件变更摘要及权限请求发送到该平台,平台方可获得这些内容。Bot 凭据保存在本地凭据服务,配置文件只保存引用。 |
|
|
109
|
+
| 营销触达与奖励中心 | 登录后可从业务服务获取营销 Banner/弹窗配置及资源包并展示;点击、关闭等操作会上报确认/取消事件,领取类操作会调用套餐领取接口。奖励中心以内嵌网页打开,桥接接口向该页面提供主题、语言和登录状态。 |
|
|
110
|
+
| 安装、插件获取、远端部署与更新 | 安装、发现、认证、部署和更新会访问仓库、包服务、插件市场、CDN 或更新服务器;统一 CLI 安装脚本会从配置的分发源读取版本清单并下载发行包。桌面自动更新受发行形态和运行条件控制,启用后可在启动及周期检查时请求更新清单,携带平台、渠道、设备等信息;平台取值可区分架构,版本信息还会影响更新选择。开源构建默认不启用自动更新(构建期可选能力);启用时,仅未打包开发态接受 `ZCODE_UPDATE_FEED_URL` 环境变量及 `--zcode-update-feed-url` 启动参数覆盖更新源,用于诊断;打包应用忽略这两个入口,继续使用既有服务端 manifest 入口。下载的代码可能随后被安装或执行,远端部署还可能将本地已有或下载的组件上传/复制到目标环境。下载检查、实际安装及运行组件的控制条件不同,不能统一描述成每步都先弹出确认。 |
|
|
111
|
+
| 工具、Hook、工作流与自动任务的交付或发布 | Shell、终端、Git、Node REPL、浏览器、插件、MCP 或工作流可以读取任务涉及的数据、向相应目标服务上传文件或生成物,并改变外部服务状态;生命周期 Hook 和已配置的定时/后台任务也可触发程序。权限规则、模式、插件配置及系统账号决定执行范围,不能保证每份外发内容都由用户逐项选择或每次外发都有独立确认。发布、发送、购买或部署完成后,本地取消或撤销不一定能恢复外部状态;权限边界见第二节。 |
|
|
112
|
+
| 开发测试、调试与请求录制 | 显式运行相关开发工具时,可向配置的真实模型或工具服务发送测试提示、样例资料及认证头;配置为真实上游的录制代理可转发请求,不能因名称含测试/录制就认为完全离线。请求轨迹和调试文件还可能在本地保存模型内容;这些工具的触发入口与普通产品运行不同。 |
|
|
113
|
+
| 构建、签名与维护者发布 | 显式运行安装、构建或发布脚本时,可下载依赖、原生二进制和运行时,将构建材料复制到发布共享目录、推送 Git,或交给签名工具、Apple 公证服务处理。外部签名工具及另行配置的 CI、存储和分发服务具有自己的网络行为;本仓未展开的流程不能仅凭脚本名称推定已核验。相关调用具有不同的启动入口、环境和凭据要求。CLI SEA 共享目录发布与上传会先校验第三方声明材料,校验失败会阻断该发布流程。当前 native-search 准备步骤按目标平台校验并解包仓库内置归档,本步骤不下载这些归档;Node 等其他组件有各自的下载链路。 |
|
|
114
|
+
|
|
115
|
+
上述业务用途针对本项目提供的接口。用户自行编写的脚本、配置的任意地址或另行安装的第三方组件,可能具有额外的数据发送行为;不能仅因通过 ZCode 启动,就推定其用途或接收方已经获得官方审核。
|
|
116
|
+
|
|
117
|
+
## 三、本地数据、日志与凭据
|
|
118
|
+
|
|
119
|
+
数据可能分别保存在桌面设备、浏览器、CLI 所在主机、SSH/WSL 环境及外部服务中。桌面和服务端的数据目录可受运行环境和启动配置影响,包含设置、会话、附件、缓存、任务记录、插件和日志;独立 CLI 默认会话数据库位于 `~/.zcode/cli/db/db.sqlite`。关闭窗口、退出登录、卸载客户端或删除一个工作区,不应被理解为已经清除其他环境、独立数据目录、备份和外部服务中的全部副本。
|
|
120
|
+
|
|
121
|
+
记忆功能的默认值和入口不同:独立 CLI 的默认配置启用记忆,桌面应用设置默认关闭。启用后可分析已保存会话、持久化记忆,并在后续任务中复用;相关提取或整理可产生额外模型请求。自动化计划、运行记录和未完成任务也有各自的持久化位置,恢复这些记录不保证此前的外部操作被撤销或能够完整重放。
|
|
122
|
+
|
|
123
|
+
共享 Agent 的模型输入输出日志在开发和生产运行中默认写入本地,测试环境除外。日志可能含提示词、代码、上下文、工具参数和模型回复;请求头及部分图像、视频数据有脱敏处理,但不能认为所有用户文本均已脱敏。生产默认有轮转和裁剪,显式开启完整保留会改变该行为。桌面主进程、Host、调度器、Web 服务及远端守护进程还有各自的日志和崩溃记录,单个日志上限不代表全项目统一的保存期限。
|
|
124
|
+
|
|
125
|
+
凭据存储机制也不相同:CLI 共享凭据文件使用加密机制,默认密钥可从本机环境信息派生,读取逻辑也接受明文记录;桌面/Node 服务的凭据同样采用本地加密文件及可配置或环境派生的密钥,并非系统钥匙串;Web OAuth 凭据可保存在 localStorage。模型配置、环境变量、插件/MCP 设置、SSH 配置及远端同步的数据也可能含有效凭据,不应把这些存储统一视为系统钥匙串、硬件隔离或“始终不离开本机”的保证。
|
|
126
|
+
|
|
127
|
+
内嵌浏览器使用持久化浏览数据;显式导入其他浏览器的 Cookies 和 LocalStorage 可使其获得相应登录状态。清理缓存与清理全部站点数据是不同操作,浏览器记录、下载文件、网页录制产物和模型日志也不一定由同一清理入口删除。不要把真实密钥或 token 写入版本控制跟踪的文件。复制日志、上传反馈、分享对话或备份数据目录前,应检查接收范围,避免将真实凭据、原始会话和私人项目内容提交到公开仓库或问题报告。
|
|
128
|
+
|
|
129
|
+
## 四、第三方许可与版权声明
|
|
130
|
+
|
|
131
|
+
本仓库第一方代码依照根 [LICENSE](LICENSE) 采用 Apache-2.0;该许可不替其他权利人新增授权,也不覆盖第三方软件、复制代码、原生二进制、字体、图标、网页素材及其他资源的独立条款。具体依赖包详见 [THIRD-PARTY-NOTICES.md](THIRD-PARTY-NOTICES.md)。受第三方版权、许可及再分发条件等约束,不承诺提供官方产品的全部功能及活动政策,具体以实际发布的源码和构建产物为准。
|
|
132
|
+
|
|
133
|
+
<!-- END ORIGINAL ZCODE NOTICE -->
|
package/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# xKCode CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
xKCode is an AI coding agent for your terminal, made by [xKiro](https://xkiro.com). It plans changes, edits files and runs
|
|
4
|
+
commands in your project.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm i -g @xkiro/code@latest
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Then start it in your project folder:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
xkcode # interactive terminal UI
|
|
16
|
+
xkcode login # sign in with xKiro
|
|
17
|
+
xkcode -p "..." # one-off prompt, prints the answer
|
|
18
|
+
xkcode --help
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Approvals
|
|
22
|
+
|
|
23
|
+
The interactive UI starts in Build mode: it runs read-only commands (listing, reading or searching files) without asking,
|
|
24
|
+
and asks before it edits files or runs any other command (switch to Plan, Guarded or YOLO inside the UI).
|
|
25
|
+
`xkcode -p` is non-interactive and runs in YOLO mode by default, so it edits files and runs commands without asking. For
|
|
26
|
+
a read-only run add `--mode plan`. With `--mode guarded` it runs everything else without asking but refuses clearly
|
|
27
|
+
dangerous commands, because there is no one to approve them. Run it only in projects you trust.
|
|
28
|
+
|
|
29
|
+
npm installs a standalone build for your platform (it carries its own Node.js runtime; the Node.js you run npm with only
|
|
30
|
+
starts it). Builds in 2.5.0: macOS Apple silicon, Linux arm64 (glibc), Linux x64 (glibc), Windows x64.
|
|
31
|
+
Linux needs glibc 2.28 or newer and libatomic (`sudo apt-get install libatomic1` on Debian/Ubuntu); musl-based
|
|
32
|
+
distributions such as Alpine are not supported yet. Other platforms: https://xkiro.com/download.
|
|
33
|
+
|
|
34
|
+
## Update and uninstall
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
npm i -g @xkiro/code@latest # update
|
|
38
|
+
npm uninstall -g @xkiro/code # remove; your settings and sessions stay in ~/.xkcode
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
See `LICENSE` and `NOTICE.md`. The platform packages also carry the notices for bundled third-party components and
|
|
44
|
+
the embedded Node.js runtime.
|
package/bin/xkcode.js
ADDED
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// xKCode: lệnh `xkcode` của gói npm `@xkiro/code` (docs/xkcode/NPM-PACKAGE.md). Gói chính chỉ có tệp này; binary độc lập
|
|
3
|
+
// (SEA, Node 26 nhúng sẵn) nằm trong gói nền tảng `@xkiro/cli-<os>-<arch>` mà npm tự chọn theo `os`/`cpu`/`libc`
|
|
4
|
+
// (optionalDependencies). Không postinstall, không tải gì: chạy được cả khi cài với `--ignore-scripts` hay sau tường lửa.
|
|
5
|
+
//
|
|
6
|
+
// Tìm gói nền tảng theo ĐƯỜNG CỐ ĐỊNH suy từ vị trí gói này (lồng trong `@xkiro/code/node_modules` — bố cục global của npm
|
|
7
|
+
// — hoặc cạnh `@xkiro/code` trong cùng `node_modules` — npx / dự án / pnpm; gói có scope nằm ở `node_modules/@xkiro/code`
|
|
8
|
+
// nên `node_modules` chứa nó ở HAI cấp trên), KHÔNG `require.resolve` tên trần: tên trần đi ngược
|
|
9
|
+
// lên mọi thư mục cha (`~/node_modules`, `C:\node_modules`…) ⇒ thư mục người khác ghi được có thể cài binary giả.
|
|
10
|
+
// Gói tìm được phải đúng tên + ĐÚNG phiên bản của launcher.
|
|
11
|
+
//
|
|
12
|
+
// Chạy: POSIX + Node có `process.execve` (≥ 22.15 / 23.11) ⇒ thay hẳn tiến trình bằng binary (tín hiệu, Ctrl+Z, mã thoát
|
|
13
|
+
// đi thẳng, không còn tiến trình Node đứng giữa); còn lại ⇒ tiến trình con kế thừa stdio, launcher chỉ chờ rồi trả đúng
|
|
14
|
+
// mã thoát / tín hiệu. Mọi câu báo lỗi tiếng Anh như CLI.
|
|
15
|
+
"use strict";
|
|
16
|
+
|
|
17
|
+
const { execFileSync, spawn } = require("node:child_process");
|
|
18
|
+
const fs = require("node:fs");
|
|
19
|
+
const os = require("node:os");
|
|
20
|
+
const path = require("node:path");
|
|
21
|
+
|
|
22
|
+
const SCOPE = "@xkiro";
|
|
23
|
+
// Tên gói chính trên npm (lệnh vẫn là `xkcode`) — PHẢI khớp NPM_MAIN_PACKAGE của npm-package-layout.mjs (test khoá).
|
|
24
|
+
const MAIN_PACKAGE = "@xkiro/code";
|
|
25
|
+
const DOWNLOAD_PAGE = "https://xkiro.com/download";
|
|
26
|
+
// Cùng câu với scripts/xkcode-cli/install.sh và XKCODE_LIBATOMIC_INSTALL_HINT của `xkcode update` (test khoá).
|
|
27
|
+
const LIBATOMIC_HINT =
|
|
28
|
+
"xkcode needs libatomic. Install it first (Debian/Ubuntu: sudo apt-get install libatomic1; Fedora/RHEL: sudo dnf install libatomic; openSUSE: sudo zypper install libatomic1).";
|
|
29
|
+
const MUSL_HINT =
|
|
30
|
+
"musl-based Linux (e.g. Alpine) is not supported yet; xkcode needs glibc 2.28 or newer.";
|
|
31
|
+
const LIBATOMIC_DIRECTORIES = [
|
|
32
|
+
"/lib",
|
|
33
|
+
"/lib64",
|
|
34
|
+
"/usr/lib",
|
|
35
|
+
"/usr/lib64",
|
|
36
|
+
"/lib/x86_64-linux-gnu",
|
|
37
|
+
"/usr/lib/x86_64-linux-gnu",
|
|
38
|
+
"/lib/aarch64-linux-gnu",
|
|
39
|
+
"/usr/lib/aarch64-linux-gnu",
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
function fail(message) {
|
|
43
|
+
process.stderr.write(`${message}\n`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function readJson(file) {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
50
|
+
} catch {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const packageRoot = fs.realpathSync(path.join(__dirname, ".."));
|
|
56
|
+
const manifest = readJson(path.join(packageRoot, "package.json")) || {};
|
|
57
|
+
const version = manifest.version;
|
|
58
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
59
|
+
const platformPackage = `${SCOPE}/cli-${platformKey}`;
|
|
60
|
+
const releasedPackages = Object.keys(manifest.optionalDependencies || {});
|
|
61
|
+
const binaryName = process.platform === "win32" ? "xkcode.exe" : "xkcode";
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Thư mục `node_modules` chứa gói này: gói có scope nằm ở `node_modules/@xkiro/code` ⇒ lên HAI cấp; tên không scope (cài
|
|
65
|
+
* bằng bí danh, vd `npm i foo@npm:@xkiro/code` ⇒ `node_modules/foo`) ⇒ MỘT cấp. Không nằm trong `node_modules` ⇒ undefined.
|
|
66
|
+
*/
|
|
67
|
+
function containingNodeModules() {
|
|
68
|
+
const parent = path.dirname(packageRoot);
|
|
69
|
+
const holder = path.basename(parent).startsWith("@") ? path.dirname(parent) : parent;
|
|
70
|
+
return path.basename(holder).toLowerCase() === "node_modules" ? holder : undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Thư mục gói nền tảng đúng tên + đúng phiên bản; `mismatch` = thấy gói đúng tên nhưng khác phiên bản. */
|
|
74
|
+
function locatePlatformPackage() {
|
|
75
|
+
const segments = platformPackage.split("/");
|
|
76
|
+
const candidates = [path.join(packageRoot, "node_modules", ...segments)];
|
|
77
|
+
const holder = containingNodeModules();
|
|
78
|
+
if (holder) candidates.push(path.join(holder, ...segments));
|
|
79
|
+
// Yarn PnP không có node_modules; bộ phân giải của PnP chặt (chỉ phụ thuộc đã khai báo), không đi ngược thư mục cha.
|
|
80
|
+
if (process.versions.pnp) {
|
|
81
|
+
try {
|
|
82
|
+
candidates.push(path.dirname(require.resolve(`${platformPackage}/package.json`)));
|
|
83
|
+
} catch {
|
|
84
|
+
// Không có ⇒ báo thiếu gói bên dưới.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
let mismatch;
|
|
88
|
+
for (const directory of candidates) {
|
|
89
|
+
const pkg = readJson(path.join(directory, "package.json"));
|
|
90
|
+
if (!pkg || pkg.name !== platformPackage) continue;
|
|
91
|
+
if (pkg.version !== version) {
|
|
92
|
+
mismatch = mismatch || { directory, version: pkg.version };
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const binary = path.join(directory, "bin", binaryName);
|
|
96
|
+
if (fs.existsSync(binary)) return { binary };
|
|
97
|
+
}
|
|
98
|
+
return { mismatch };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Có bộ nạp musl mà KHÔNG có bộ nạp glibc. Chỉ xét tệp musl là sai: Debian/Ubuntu cài gói `musl` cũng có
|
|
103
|
+
* `/lib/ld-musl-x86_64.so.1` mà hệ vẫn là glibc.
|
|
104
|
+
*/
|
|
105
|
+
function isMusl() {
|
|
106
|
+
const musl =
|
|
107
|
+
fs.existsSync("/lib/ld-musl-x86_64.so.1") || fs.existsSync("/lib/ld-musl-aarch64.so.1");
|
|
108
|
+
const glibc =
|
|
109
|
+
fs.existsSync("/lib64/ld-linux-x86-64.so.2") || fs.existsSync("/lib/ld-linux-aarch64.so.1");
|
|
110
|
+
return musl && !glibc;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function hasLibatomic() {
|
|
114
|
+
try {
|
|
115
|
+
if (fs.readFileSync("/etc/ld.so.cache").includes("libatomic.so.1")) return true;
|
|
116
|
+
} catch {
|
|
117
|
+
// Không có cache của ldconfig (Nix…) ⇒ dò thư mục.
|
|
118
|
+
}
|
|
119
|
+
// NIX_LD_LIBRARY_PATH: thư viện mà nix-ld (NixOS) đưa cho binary FHS.
|
|
120
|
+
const directories = [
|
|
121
|
+
...LIBATOMIC_DIRECTORIES,
|
|
122
|
+
...(process.env.LD_LIBRARY_PATH || "").split(":").filter(Boolean),
|
|
123
|
+
...(process.env.NIX_LD_LIBRARY_PATH || "").split(":").filter(Boolean),
|
|
124
|
+
];
|
|
125
|
+
return directories.some((directory) => fs.existsSync(path.join(directory, "libatomic.so.1")));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function isRosettaTranslated() {
|
|
129
|
+
try {
|
|
130
|
+
// Đường tuyệt đối: không tra PATH (một `sysctl` lạ trong PATH không được chạy).
|
|
131
|
+
const output = execFileSync("/usr/sbin/sysctl", ["-n", "sysctl.proc_translated"], {
|
|
132
|
+
encoding: "utf8",
|
|
133
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
134
|
+
timeout: 5000,
|
|
135
|
+
});
|
|
136
|
+
return output.trim() === "1";
|
|
137
|
+
} catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Đoạn thư mục của một đường, chữ thường (so không phân biệt hoa thường — `Yarn\Data\global` trên Windows). */
|
|
143
|
+
function segmentsOf(target) {
|
|
144
|
+
return target
|
|
145
|
+
.split(/[\\/]+/u)
|
|
146
|
+
.filter(Boolean)
|
|
147
|
+
.map((name) => name.toLowerCase());
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Có các đoạn thư mục liền nhau `run` trong `segments`. */
|
|
151
|
+
function hasSegments(segments, run) {
|
|
152
|
+
for (let start = 0; start + run.length <= segments.length; start += 1) {
|
|
153
|
+
if (run.every((name, offset) => segments[start + offset] === name)) return true;
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** `target` nằm TRONG thư mục `root` (lấy từ biến môi trường; rỗng = không). Windows: path.relative không phân biệt hoa thường. */
|
|
159
|
+
function isInside(target, root) {
|
|
160
|
+
if (!root) return false;
|
|
161
|
+
let base = path.resolve(root);
|
|
162
|
+
try {
|
|
163
|
+
base = fs.realpathSync(base);
|
|
164
|
+
} catch {
|
|
165
|
+
// Thư mục không tồn tại ⇒ so theo đường như đã cho.
|
|
166
|
+
}
|
|
167
|
+
const relative = path.relative(base, target);
|
|
168
|
+
return relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Thư mục tổ tiên GẦN NHẤT của `start` (kể cả chính nó) thoả `match(dir)`; không có ⇒ undefined. */
|
|
172
|
+
function findAncestor(start, match) {
|
|
173
|
+
for (let directory = start; ; directory = path.dirname(directory)) {
|
|
174
|
+
if (match(directory)) return directory;
|
|
175
|
+
if (path.dirname(directory) === directory) return undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Thư mục cache của một lần chạy tạm: `<…>/<parentName>/<băm>` chứa gói này. */
|
|
180
|
+
function cacheFolderUnder(parentName) {
|
|
181
|
+
return findAncestor(
|
|
182
|
+
packageRoot,
|
|
183
|
+
(directory) => path.basename(path.dirname(directory)).toLowerCase() === parentName,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Cách người dùng đã cài gói này — CÙNG luật với `detectPackageManagerInstall()` của CLI (update-install-method.ts), chỉ
|
|
189
|
+
* khác điểm neo (ở đây là thư mục gói `@xkiro/code`, CLI dùng binary). Chỉ dựa vào đường + vài tệp / biến môi trường đọc được
|
|
190
|
+
* ngay (không gọi `npm prefix -g`, không mạng). Không chắc ⇒ `unknown` (câu nêu cả hai cách).
|
|
191
|
+
* npx `_npx/<băm>` · pnpm dlx `dlx/<băm>/<giờ>-<pid>` · bunx `bunx-<uid>-<gói>` · yarn dlx `xfs-<băm>/…/dlx-<pid>`
|
|
192
|
+
* pnpm global: `pnpm/global`, `global/<số>/node_modules/.pnpm`, hoặc nằm trong $PNPM_HOME; `.pnpm` dưới thư mục tên là
|
|
193
|
+
* số (global-dir tự đặt — global của pnpm luôn là `<thư mục>/<số phiên bản bố cục>`) ⇒ không chắc; `.pnpm` khác = dự án
|
|
194
|
+
* Bun global: `.bun/install/global`, `install/global/node_modules` ($BUN_INSTALL khác), $BUN_INSTALL_GLOBAL_DIR
|
|
195
|
+
* Yarn global: `yarn/global`, `Yarn/Data/global` · Yarn Berry (có `.yarn`): dự án hoặc yarn dlx
|
|
196
|
+
* npm: lệnh global nằm ở `<prefix>/bin/xkcode` (POSIX, node_modules = `<prefix>/lib/node_modules`) hoặc
|
|
197
|
+
* `<prefix>\xkcode.cmd` (Windows, node_modules = `<prefix>\node_modules`); dự án có `node_modules/.bin/xkcode`. Thấy đúng
|
|
198
|
+
* MỘT trong hai ⇒ biết; cả hai / không có gì (`.bin` lạc trong `<prefix>/lib`, cài `--no-bin-links`…) ⇒ không chắc.
|
|
199
|
+
*/
|
|
200
|
+
function detectInstall() {
|
|
201
|
+
const segments = segmentsOf(packageRoot);
|
|
202
|
+
if (segments.includes("_npx")) return { kind: "npx", cacheDir: cacheFolderUnder("_npx") };
|
|
203
|
+
for (let index = 0; index + 2 < segments.length; index += 1) {
|
|
204
|
+
if (
|
|
205
|
+
segments[index] === "dlx" &&
|
|
206
|
+
/^[0-9a-f]{32,}$/u.test(segments[index + 1]) &&
|
|
207
|
+
/^[0-9a-f]+-[0-9a-f]+$/u.test(segments[index + 2])
|
|
208
|
+
) {
|
|
209
|
+
return { kind: "pnpm-dlx", cacheDir: cacheFolderUnder("dlx") };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (segments.some((name) => name.startsWith("bunx-"))) {
|
|
213
|
+
return {
|
|
214
|
+
kind: "bunx",
|
|
215
|
+
cacheDir: findAncestor(packageRoot, (directory) => /^bunx-/iu.test(path.basename(directory))),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
const xfs = segments.findIndex((name) => /^xfs-[0-9a-f]+$/u.test(name));
|
|
219
|
+
if (xfs !== -1 && segments.slice(xfs + 1).some((name) => /^dlx-\d+$/u.test(name))) {
|
|
220
|
+
return { kind: "yarn-dlx" };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Đoạn `.pnpm` CUỐI = kho ảo `node_modules/.pnpm`: thư mục cha có thể cũng tên `.pnpm` (vd PNPM_HOME=/root/.pnpm).
|
|
224
|
+
const pnpmIndex = segments.lastIndexOf(".pnpm");
|
|
225
|
+
if (pnpmIndex !== -1 || hasSegments(segments, ["pnpm", "global"])) {
|
|
226
|
+
// Gốc pnpm = thư mục chứa `node_modules/.pnpm`.
|
|
227
|
+
const root = pnpmIndex >= 2 ? segments[pnpmIndex - 2] : "";
|
|
228
|
+
const numberedRoot = /^\d+$/u.test(root);
|
|
229
|
+
if (
|
|
230
|
+
hasSegments(segments, ["pnpm", "global"]) ||
|
|
231
|
+
(numberedRoot && segments[pnpmIndex - 3] === "global") ||
|
|
232
|
+
isInside(packageRoot, process.env.PNPM_HOME)
|
|
233
|
+
) {
|
|
234
|
+
return { kind: "pnpm-global" };
|
|
235
|
+
}
|
|
236
|
+
return { kind: numberedRoot ? "unknown" : "project", tool: "pnpm" };
|
|
237
|
+
}
|
|
238
|
+
if (
|
|
239
|
+
hasSegments(segments, [".bun", "install", "global"]) ||
|
|
240
|
+
hasSegments(segments, ["install", "global", "node_modules"]) ||
|
|
241
|
+
isInside(packageRoot, process.env.BUN_INSTALL_GLOBAL_DIR)
|
|
242
|
+
) {
|
|
243
|
+
return { kind: "bun-global" };
|
|
244
|
+
}
|
|
245
|
+
if (
|
|
246
|
+
hasSegments(segments, ["yarn", "global"]) ||
|
|
247
|
+
hasSegments(segments, ["yarn", "data", "global"])
|
|
248
|
+
) {
|
|
249
|
+
return { kind: "yarn-global" };
|
|
250
|
+
}
|
|
251
|
+
if (segments.includes(".yarn")) return { kind: "yarn-berry" };
|
|
252
|
+
|
|
253
|
+
const nodeModules = containingNodeModules();
|
|
254
|
+
if (!nodeModules) return { kind: "unknown", tool: "npm" };
|
|
255
|
+
const prefix = path.dirname(nodeModules);
|
|
256
|
+
const globalShim =
|
|
257
|
+
process.platform === "win32"
|
|
258
|
+
? fs.existsSync(path.join(prefix, "xkcode.cmd"))
|
|
259
|
+
: path.basename(prefix) === "lib" &&
|
|
260
|
+
fs.existsSync(path.join(path.dirname(prefix), "bin", "xkcode"));
|
|
261
|
+
const projectShim = fs.existsSync(
|
|
262
|
+
path.join(nodeModules, ".bin", process.platform === "win32" ? "xkcode.cmd" : "xkcode"),
|
|
263
|
+
);
|
|
264
|
+
if (globalShim && !projectShim) return { kind: "npm-global" };
|
|
265
|
+
if (projectShim && !globalShim) return { kind: "project", tool: "npm" };
|
|
266
|
+
return { kind: "unknown", tool: "npm" };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Lệnh xoá một thư mục cache hỏng, theo hệ điều hành. Windows: không biết người dùng đang ở PowerShell hay cmd.exe (cú pháp
|
|
271
|
+
* khác nhau — `rmdir /s /q` trong PowerShell là lỗi) ⇒ nêu cả hai.
|
|
272
|
+
*/
|
|
273
|
+
function removeDirectoryCommand(directory) {
|
|
274
|
+
return process.platform === "win32"
|
|
275
|
+
? `Remove-Item -Recurse -Force "${directory}" (PowerShell) or rmdir /s /q "${directory}" (cmd.exe)`
|
|
276
|
+
: `rm -rf "${directory}"`;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const RUNNERS = { npx: "npx", "pnpm-dlx": "pnpm dlx", bunx: "bunx", "yarn-dlx": "yarn dlx" };
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Câu cài lại ĐÚNG cách người dùng đã cài (`spec` = `@xkiro/code@<phiên bản>`). Chạy tạm (npx…) mà gói hỏng/thiếu ⇒ chạy lại
|
|
283
|
+
* y lệnh cũ sẽ dùng lại ĐÚNG thư mục cache đó ⇒ bảo xoá nó trước (`npm cache clean --force` chỉ xoá `_cacache`, KHÔNG xoá
|
|
284
|
+
* `_npx`). `staleCache: false` khi cache không hỏng (vd đổi sang Node arm64).
|
|
285
|
+
*/
|
|
286
|
+
function reinstallCommand(spec, { staleCache = true } = {}) {
|
|
287
|
+
const install = detectInstall();
|
|
288
|
+
const runner = RUNNERS[install.kind];
|
|
289
|
+
if (runner) {
|
|
290
|
+
return staleCache && install.cacheDir
|
|
291
|
+
? `delete the ${runner} cache folder with: ${removeDirectoryCommand(install.cacheDir)} — then run: ${runner} ${spec}`
|
|
292
|
+
: `${runner} ${spec}`;
|
|
293
|
+
}
|
|
294
|
+
switch (install.kind) {
|
|
295
|
+
case "pnpm-global":
|
|
296
|
+
return `pnpm add -g ${spec}`;
|
|
297
|
+
case "bun-global":
|
|
298
|
+
return `bun add -g ${spec}`;
|
|
299
|
+
case "yarn-global":
|
|
300
|
+
return `yarn global add ${spec}`;
|
|
301
|
+
case "yarn-berry":
|
|
302
|
+
return `yarn add ${spec} (in your project folder), or yarn dlx ${spec}`;
|
|
303
|
+
case "npm-global":
|
|
304
|
+
return `npm i -g ${spec}`;
|
|
305
|
+
case "project":
|
|
306
|
+
return install.tool === "pnpm"
|
|
307
|
+
? `pnpm add ${spec} (in your project folder)`
|
|
308
|
+
: `npm i ${spec} (in your project folder, or your package manager's equivalent)`;
|
|
309
|
+
default:
|
|
310
|
+
return install.tool === "pnpm"
|
|
311
|
+
? `pnpm add -g ${spec} if it was installed globally, or pnpm add ${spec} in your project folder`
|
|
312
|
+
: `npm i -g ${spec} if it was installed globally, or npm i ${spec} in your project folder (or your package manager's equivalent)`;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function explainMissingPackage(mismatch) {
|
|
317
|
+
if (mismatch) {
|
|
318
|
+
return `${platformPackage} ${mismatch.version} does not match ${MAIN_PACKAGE} ${version} (${mismatch.directory}). Reinstall: ${reinstallCommand(`${MAIN_PACKAGE}@${version}`)}`;
|
|
319
|
+
}
|
|
320
|
+
if (!releasedPackages.includes(platformPackage)) {
|
|
321
|
+
if (process.platform === "darwin" && process.arch === "x64" && isRosettaTranslated()) {
|
|
322
|
+
return `Node.js is running as x64 under Rosetta on this Apple silicon Mac. Install the arm64 build of Node.js, then reinstall: ${reinstallCommand(MAIN_PACKAGE, { staleCache: false })}`;
|
|
323
|
+
}
|
|
324
|
+
const builds =
|
|
325
|
+
releasedPackages.map((name) => name.slice(`${SCOPE}/cli-`.length)).join(", ") || "none";
|
|
326
|
+
return `xKCode ${version} has no build for ${platformKey} (builds: ${builds}). See ${DOWNLOAD_PAGE}`;
|
|
327
|
+
}
|
|
328
|
+
return `The ${platformPackage}@${version} package is missing. It is an optional dependency, so it is skipped by --omit=optional, --no-optional or when node_modules was copied from another platform. Reinstall: ${reinstallCommand(`${MAIN_PACKAGE}@${version}`)}`;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** Binary không có quyền chạy: mode thiếu +x (gói đóng sai, chép tay) hoặc thư mục cài nằm trên ổ mount `noexec`. */
|
|
332
|
+
function explainNotExecutable(error) {
|
|
333
|
+
const code = (error && error.code) || "EACCES";
|
|
334
|
+
return `Cannot run ${binary} (${code}): the file is not executable, or the folder it is installed in is on a filesystem mounted with noexec. Make it executable with: chmod +x "${binary}" — or reinstall: ${reinstallCommand(`${MAIN_PACKAGE}@${version}`)}`;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const ELF_MACHINES = { x64: 62, arm64: 183 };
|
|
338
|
+
const ELF_MACHINE_NAMES = { 3: "x86 (32-bit)", 40: "ARM (32-bit)", 62: "x64", 183: "arm64" };
|
|
339
|
+
const MACHO_CPU_TYPES = { x64: 0x01000007, arm64: 0x0100000c };
|
|
340
|
+
const MACHO_CPU_NAMES = { 0x01000007: "x64", 0x0100000c: "arm64" };
|
|
341
|
+
const PT_INTERP = 3;
|
|
342
|
+
|
|
343
|
+
function readAt(fd, length, position) {
|
|
344
|
+
const buffer = Buffer.alloc(length);
|
|
345
|
+
return buffer.subarray(0, fs.readSync(fd, buffer, 0, length, position));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** ELF 64-bit little-endian (Linux): sai định dạng / sai kiến trúc / thiếu bộ nạp (PT_INTERP) ⇒ câu giải thích. */
|
|
349
|
+
function elfProblem(fd, file, reinstall) {
|
|
350
|
+
const corrupted = `${file} is not a valid Linux ${process.arch} executable (the file is damaged or incomplete). Reinstall: ${reinstall}`;
|
|
351
|
+
const header = readAt(fd, 64, 0);
|
|
352
|
+
if (header.length < 64 || header.readUInt32BE(0) !== 0x7f454c46) return corrupted;
|
|
353
|
+
if (header[4] !== 2 || header[5] !== 1) return corrupted;
|
|
354
|
+
const type = header.readUInt16LE(16);
|
|
355
|
+
if (type !== 2 && type !== 3) return corrupted;
|
|
356
|
+
const machine = header.readUInt16LE(18);
|
|
357
|
+
if (machine !== ELF_MACHINES[process.arch]) {
|
|
358
|
+
return `${file} is built for ${ELF_MACHINE_NAMES[machine] || `ELF machine ${machine}`}, but this machine is ${process.arch}. Reinstall: ${reinstall}`;
|
|
359
|
+
}
|
|
360
|
+
const tableOffset = Number(header.readBigUInt64LE(32));
|
|
361
|
+
const entrySize = header.readUInt16LE(54);
|
|
362
|
+
const entryCount = header.readUInt16LE(56);
|
|
363
|
+
if (!Number.isSafeInteger(tableOffset) || entrySize < 56 || entryCount > 512) return corrupted;
|
|
364
|
+
const table = readAt(fd, entrySize * entryCount, tableOffset);
|
|
365
|
+
if (table.length < entrySize * entryCount) return corrupted;
|
|
366
|
+
for (let index = 0; index < entryCount; index += 1) {
|
|
367
|
+
const entry = index * entrySize;
|
|
368
|
+
if (table.readUInt32LE(entry) !== PT_INTERP) continue;
|
|
369
|
+
const offset = Number(table.readBigUInt64LE(entry + 8));
|
|
370
|
+
const size = Number(table.readBigUInt64LE(entry + 32));
|
|
371
|
+
if (!Number.isSafeInteger(offset) || size < 2 || size > 4096) return corrupted;
|
|
372
|
+
const loader = readAt(fd, size, offset).toString("latin1").split("\0")[0];
|
|
373
|
+
if (!loader.startsWith("/")) return corrupted;
|
|
374
|
+
try {
|
|
375
|
+
fs.accessSync(loader, fs.constants.X_OK);
|
|
376
|
+
} catch {
|
|
377
|
+
return `${file} needs the program loader ${loader}, which is missing or not executable on this system: xkcode is built for glibc-based Linux (glibc 2.28 or newer). On NixOS enable programs.nix-ld; on Guix run it inside "guix shell --container --emulate-fhs". Other ways to install: ${DOWNLOAD_PAGE}`;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return undefined;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** Mach-O 64-bit (macOS), một kiến trúc hoặc universal: không có lát cắt cho CPU này ⇒ câu giải thích. */
|
|
384
|
+
function machOProblem(fd, file, reinstall) {
|
|
385
|
+
const corrupted = `${file} is not a valid macOS ${process.arch} executable (the file is damaged or incomplete). Reinstall: ${reinstall}`;
|
|
386
|
+
const header = readAt(fd, 8, 0);
|
|
387
|
+
if (header.length < 8) return corrupted;
|
|
388
|
+
const wanted = MACHO_CPU_TYPES[process.arch];
|
|
389
|
+
let cpuTypes;
|
|
390
|
+
if (header.readUInt32LE(0) === 0xfeedfacf) {
|
|
391
|
+
cpuTypes = [header.readUInt32LE(4)];
|
|
392
|
+
} else if (header.readUInt32BE(0) === 0xcafebabe || header.readUInt32BE(0) === 0xcafebabf) {
|
|
393
|
+
// Universal: fat_arch 20 byte / fat_arch_64 32 byte, big-endian, cputype ở đầu mỗi mục.
|
|
394
|
+
const count = Math.min(header.readUInt32BE(4), 32);
|
|
395
|
+
const entrySize = header.readUInt32BE(0) === 0xcafebabf ? 32 : 20;
|
|
396
|
+
const table = readAt(fd, count * entrySize, 8);
|
|
397
|
+
if (count === 0 || table.length < count * entrySize) return corrupted;
|
|
398
|
+
cpuTypes = Array.from({ length: count }, (_, index) => table.readUInt32BE(index * entrySize));
|
|
399
|
+
} else {
|
|
400
|
+
return corrupted;
|
|
401
|
+
}
|
|
402
|
+
if (cpuTypes.includes(wanted)) return undefined;
|
|
403
|
+
const built = cpuTypes.map((cpu) => MACHO_CPU_NAMES[cpu] || `CPU type ${cpu}`).join(" + ");
|
|
404
|
+
return `${file} is built for ${built}, but this machine is ${process.arch}. Reinstall: ${reinstall}`;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Lỗi mà `process.execve` chỉ phát hiện lúc gọi hệ thống — ENOEXEC (tệp hỏng/cắt cụt có bit x, sai kiến trúc) và ENOENT
|
|
409
|
+
* (bộ nạp ELF không có: NixOS, Guix, container tối giản) — làm Node ABORT (134) thay vì ném ⇒ kiểm TRƯỚC, đọc vài trăm
|
|
410
|
+
* byte đầu. Không đọc được tệp (chỉ có quyền x) ⇒ không chặn.
|
|
411
|
+
*/
|
|
412
|
+
function executableFormatProblem(file) {
|
|
413
|
+
let fd;
|
|
414
|
+
try {
|
|
415
|
+
fd = fs.openSync(file, "r");
|
|
416
|
+
} catch {
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
try {
|
|
420
|
+
const reinstall = reinstallCommand(`${MAIN_PACKAGE}@${version}`);
|
|
421
|
+
return process.platform === "darwin"
|
|
422
|
+
? machOProblem(fd, file, reinstall)
|
|
423
|
+
: elfProblem(fd, file, reinstall);
|
|
424
|
+
} catch {
|
|
425
|
+
return undefined;
|
|
426
|
+
} finally {
|
|
427
|
+
fs.closeSync(fd);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (process.platform === "linux" && isMusl()) fail(MUSL_HINT);
|
|
432
|
+
|
|
433
|
+
const located = locatePlatformPackage();
|
|
434
|
+
if (!located.binary) fail(explainMissingPackage(located.mismatch));
|
|
435
|
+
const binary = located.binary;
|
|
436
|
+
const args = process.argv.slice(2);
|
|
437
|
+
|
|
438
|
+
if (process.platform !== "win32") {
|
|
439
|
+
// Kiểm quyền chạy TRƯỚC: lỗi hệ thống của `process.execve` (EACCES, noexec…) KHÔNG ném ra mà làm Node ABORT (exit 134, có
|
|
440
|
+
// thể kèm core dump — đo trong node:24-bookworm-slim với binary mode 0644), nên try/catch không đỡ được. access(X_OK) báo
|
|
441
|
+
// EACCES cả cho ổ mount noexec; root cũng bị từ chối khi tệp không có bit x nào.
|
|
442
|
+
try {
|
|
443
|
+
fs.accessSync(binary, fs.constants.X_OK);
|
|
444
|
+
} catch (error) {
|
|
445
|
+
fail(explainNotExecutable(error));
|
|
446
|
+
}
|
|
447
|
+
const problem = executableFormatProblem(binary);
|
|
448
|
+
if (problem) fail(problem);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// Sau kiểm bộ nạp: trên NixOS/Guix câu "thiếu bộ nạp" đúng hơn câu cài libatomic kiểu Debian. Thiếu libatomic thì bộ nạp
|
|
452
|
+
// báo lỗi SAU execve (thoát 127, không abort) ⇒ biến bỏ qua vẫn an toàn.
|
|
453
|
+
if (
|
|
454
|
+
process.platform === "linux" &&
|
|
455
|
+
process.env.XKCODE_SKIP_LIBATOMIC_CHECK !== "1" &&
|
|
456
|
+
!hasLibatomic()
|
|
457
|
+
) {
|
|
458
|
+
fail(LIBATOMIC_HINT);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (process.platform !== "win32" && typeof process.execve === "function") {
|
|
462
|
+
try {
|
|
463
|
+
// argv[0] = đường binary (như shell gọi thẳng); env giữ nguyên.
|
|
464
|
+
process.execve(binary, [binary, ...args], process.env);
|
|
465
|
+
} catch {
|
|
466
|
+
// Chỉ lỗi kiểm tham số (ném đồng bộ trước khi gọi hệ thống) tới được đây ⇒ chạy bằng tiến trình con bên dưới.
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const child = spawn(binary, args, { stdio: "inherit" });
|
|
471
|
+
const keepWaiting = () => {
|
|
472
|
+
// Ctrl+C / Ctrl+Break tới CẢ nhóm tiến trình (console Windows, nhóm foreground của terminal) ⇒ binary đã nhận; launcher
|
|
473
|
+
// chỉ cần sống tới khi nó thoát. Chuyển tiếp thêm lần nữa = binary tưởng người dùng bấm hai lần (buộc thoát).
|
|
474
|
+
};
|
|
475
|
+
const forward = (signal) => () => {
|
|
476
|
+
try {
|
|
477
|
+
child.kill(signal);
|
|
478
|
+
} catch {
|
|
479
|
+
// Tiến trình con đã thoát.
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
// SIGTERM / SIGHUP thường gửi riêng cho PID launcher (kill, trình giám sát) ⇒ chuyển cho binary.
|
|
483
|
+
const handlers =
|
|
484
|
+
process.platform === "win32"
|
|
485
|
+
? { SIGINT: keepWaiting, SIGBREAK: keepWaiting }
|
|
486
|
+
: {
|
|
487
|
+
SIGINT: keepWaiting,
|
|
488
|
+
SIGQUIT: keepWaiting,
|
|
489
|
+
SIGTERM: forward("SIGTERM"),
|
|
490
|
+
SIGHUP: forward("SIGHUP"),
|
|
491
|
+
};
|
|
492
|
+
for (const [signal, handler] of Object.entries(handlers)) process.on(signal, handler);
|
|
493
|
+
|
|
494
|
+
child.on("error", (error) => {
|
|
495
|
+
fail(`Could not start ${binary}: ${error.message}`);
|
|
496
|
+
});
|
|
497
|
+
child.on("exit", (code, signal) => {
|
|
498
|
+
for (const [name, handler] of Object.entries(handlers)) process.removeListener(name, handler);
|
|
499
|
+
if (signal) {
|
|
500
|
+
// Trả đúng kiểu kết thúc cho shell: tự gửi lại tín hiệu đó; phòng khi Node bỏ qua nó thì vẫn là mã 128 + số tín hiệu.
|
|
501
|
+
process.exitCode = 128 + (os.constants.signals[signal] || 0);
|
|
502
|
+
process.kill(process.pid, signal);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
process.exit(code === null ? 1 : code);
|
|
506
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xkiro/code",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.5.0",
|
|
4
|
+
"description": "xKCode: AI coding agent in your terminal, by xKiro. Plans changes, edits files and runs commands in your project.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ai",
|
|
7
|
+
"agent",
|
|
8
|
+
"coding agent",
|
|
9
|
+
"cli",
|
|
10
|
+
"terminal",
|
|
11
|
+
"tui",
|
|
12
|
+
"llm",
|
|
13
|
+
"mcp",
|
|
14
|
+
"xkcode",
|
|
15
|
+
"xkiro"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://xkiro.com",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://xkiro.com/contact",
|
|
20
|
+
"email": "support@xkiro.com"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://xkiro.com"
|
|
25
|
+
},
|
|
26
|
+
"license": "Apache-2.0",
|
|
27
|
+
"author": "xKiro",
|
|
28
|
+
"bin": {
|
|
29
|
+
"xkcode": "bin/xkcode.js"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"bin/xkcode.js",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"NOTICE.md",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"optionalDependencies": {
|
|
41
|
+
"@xkiro/cli-darwin-arm64": "2.5.0",
|
|
42
|
+
"@xkiro/cli-linux-arm64": "2.5.0",
|
|
43
|
+
"@xkiro/cli-linux-x64": "2.5.0",
|
|
44
|
+
"@xkiro/cli-win32-x64": "2.5.0"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
}
|
|
49
|
+
}
|