@qilin-agent/cli 0.0.0-stage → 3.1.3
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 +21 -0
- package/README.i18n.yaml +22 -0
- package/README.md +69 -2
- package/README.zh.md +70 -0
- package/lib/bin.js +255 -0
- package/lib/dump-config-_HRfhhWz.js +53 -0
- package/lib/plugin-BQ1sn-63.js +239 -0
- package/lib/profile-boot-DSy6PUHQ.js +315 -0
- package/lib/profile-boot.js +2 -0
- package/lib/types/args.d.ts +56 -0
- package/lib/types/bin.d.ts +11 -0
- package/lib/types/dump-config.d.ts +18 -0
- package/lib/types/plugin.d.ts +29 -0
- package/lib/types/process-shutdown.d.ts +20 -0
- package/lib/types/profile-boot.d.ts +92 -0
- package/lib/types/startup-diagnostics.d.ts +19 -0
- package/package.json +171 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kkutysllb
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Bilingual-pair consistency record for README.md (docs/i18n/README.md): per heading
|
|
2
|
+
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
|
3
|
+
# After editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm run verify-translation-pairing --write apps/cli/README.md
|
|
5
|
+
/qilin-cli:
|
|
6
|
+
en: 30f6f6d09ef3f96b
|
|
7
|
+
zh: 9215ee1c45f8a0f6
|
|
8
|
+
/qilin-cli/entry-modes:
|
|
9
|
+
en: 8f3f0fe760a8a5aa
|
|
10
|
+
zh: 1a5566f392aa3161
|
|
11
|
+
/qilin-cli/app-arguments:
|
|
12
|
+
en: 979c1c9bedaf1b3e
|
|
13
|
+
zh: a77b6d9db2cfc191
|
|
14
|
+
/qilin-cli/profiles:
|
|
15
|
+
en: 2403793fc28a4574
|
|
16
|
+
zh: b7655fd1d77a8501
|
|
17
|
+
/qilin-cli/optional-overlays:
|
|
18
|
+
en: 55972a91e0d1d24d
|
|
19
|
+
zh: 920ae26285d8e1b6
|
|
20
|
+
/qilin-cli/development:
|
|
21
|
+
en: e83101b27f5dd5a3
|
|
22
|
+
zh: 17d66dcf09613c3c
|
package/README.md
CHANGED
|
@@ -1,3 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@qilin-agent/cli`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
The `qilin` command is the sole supported Node application launcher: profiles are ordered stacks of plugin-bundle patch layers under the user's own overrides. SDK and ACP are profiles, not separate public bins. The Python runtime wheel packages this same command; the SDK defaults to `sdk`, and the minimal example selects `sdk-minimal`. [`src/args.ts`](src/args.ts) owns the command grammar, and [`src/bin.ts`](src/bin.ts) loads only the selected runner. Invalid commands, options from another mode, and fatal configuration or boot failures exit nonzero.
|
|
6
|
+
|
|
7
|
+
## Entry modes
|
|
8
|
+
|
|
9
|
+
| Command | Purpose |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `qilin <name>` / `qilin --profile <name>` | Boot the named profile under `$QILIN_HOME/profiles/<name>`. |
|
|
12
|
+
| `qilin --profile <name> --from-default-profile <template>` | Create a new custom profile from a shipped template, then boot it. |
|
|
13
|
+
| `qilin --profile acp` | Serve automation clients over ACP stdio until disconnect. |
|
|
14
|
+
| `qilin --profile headless "job"` | Run one fresh persisted session, print the final answer, and exit. |
|
|
15
|
+
| `qilin --profile sdk` | Serve SDK clients over JSON-RPC stdio until shutdown or disconnect. |
|
|
16
|
+
| `qilin --profile sdk-minimal` | Serve SDK clients with the standalone minimal agent tree. |
|
|
17
|
+
| `qilin web` | Boot the Web profile. |
|
|
18
|
+
| `qilin plugin --profile <name> <pnpm args>` | Manage a profile's plugins by forwarding to pnpm in the profile directory. |
|
|
19
|
+
| `qilin plugin list` | List a profile's bundle layers in activation order; omit `--profile` for the product profile. |
|
|
20
|
+
| `qilin plugin doctor <package\|directory>` | Report one plugin package's DSH-era compatibility without installing or running anything. |
|
|
21
|
+
|
|
22
|
+
The invoking directory is the default workspace root. The `web`, `headless`, `sdk`, `sdk-minimal`, and `acp` profiles auto-initialize on first use from shipped templates. Create another profile at an unused, non-shipped name with `--from-default-profile`, or initialize a base-backed profile through `qilin plugin`. The `desktop` name is reserved for the Electron-owned profile, so the CLI rejects boot, config-dump, and plugin-management requests for it. After a successful package operation the command reconciles the profile's bundle list, and it refuses a profile whose installed dependencies include an upstream DSH-era engine package: the diagnostic names each colliding package, the QiLin package it maps onto, and the `remove` command that clears it, and the command exits 1 without changing the bundle list.
|
|
23
|
+
|
|
24
|
+
`list` and `doctor` read the profile and never initialize it or run pnpm. `doctor` accepts an installed package name or a package directory and checks the four rules a plugin must satisfy to load here: whether the package builds the DSH-era home itself instead of reading `DSH_HOME`/`QILIN_HOME`, installs an engine package the harness supplies, imports an engine name it never declared as a peer, and injects client module names the compatibility layer cannot map. It prints one finding per line and exits 1 only when a finding blocks activation.
|
|
25
|
+
|
|
26
|
+
`list` marks a shipped template layer with `(shipped)`: it moves with the running installation and cannot be dropped from the profile. Every other listed layer belongs to the profile — for example the retired `dsh-animations` animations skill pack installed back through `qilin plugin add` — and upgrades or removes in place without a QiLin release.
|
|
27
|
+
|
|
28
|
+
Install the command itself from the published package (`npm install -g @qilin-agent/cli`) to get `qilin` on `PATH`; the manifest declares `lib/bin.js` as the `qilin` bin and ships only that bundle.
|
|
29
|
+
|
|
30
|
+
## App arguments
|
|
31
|
+
|
|
32
|
+
The launcher parses only its own flags and hands everything after them to the booted profile, where any injected app plugin may parse the shared immutable snapshot ([`qilin-cmdline`](../../packages/boot/cmdline/README.md)). The first token the launcher does not recognize starts the app's arguments:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
qilin --profile web --port 8080 # --port belongs to the web app
|
|
36
|
+
qilin --profile tui --resume <id> # example, assuming the tui profile is installed; --resume belongs to the terminal app
|
|
37
|
+
qilin --profile headless "run the tests"
|
|
38
|
+
qilin --profile web --help # the web app's flags, not the launcher's
|
|
39
|
+
qilin --help # the launcher's own help
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
<a id="profiles"></a>
|
|
43
|
+
## Profiles
|
|
44
|
+
|
|
45
|
+
A profile directory holds a `package.json` (out-of-tree plugin dependencies plus the profile manifest `qilin.profile` with its ordered `bundles` list) and a `cordis.patch.yml` (the user's own patch layer). `qilin-hmr`, when enabled in YAML, watches the profile manifest and both profile and home patch files, then recomposes all layers through one serialized reload. Without HMR, changes apply on restart. Edits arriving during watcher registration use the same nonfatal reload reporting as later edits. [Plugin Manager](../../packages/boot/plugin-manager/README.md) shares package operations and the profile write lock with `qilin plugin`; package updates retain disabled bundle selections. CLI package commands inherit authentication variables and terminal descriptors, including interactive build approval; service calls retain their scrubbed environment and captured diagnostics.
|
|
46
|
+
|
|
47
|
+
Installation and profile startup enforce declared qilin peer ranges against the same runtime version `qilin --version` prints. Incompatible plugins require an explicitly acknowledged exact-version exemption, which `qilin plugin allow-version`, `revoke-version`, and `version-exemptions` manage for one profile. The [plugin manager's compatibility reference](../../packages/boot/plugin-manager/README.md#version-compatibility-and-exemptions) documents the commands, persistence, and risks.
|
|
48
|
+
|
|
49
|
+
The tree composes over an empty root:
|
|
50
|
+
- each bundle's patch in `qilin.profile.bundles` order
|
|
51
|
+
- then the profile's `cordis.patch.yml`, then the home-level `$QILIN_HOME/cordis.patch.yml`
|
|
52
|
+
- then `--patch` overlays
|
|
53
|
+
|
|
54
|
+
Bundles named in `qilin.profile.bundles` resolve from the qilin installation first (`@qilin-agent/base`, `@qilin-agent/web-app`, `@qilin-agent/headless`, `@qilin-agent/sdk-app`, `@qilin-agent/sdk-minimal`, `@qilin-agent/acp-app`), then from the profile's own `node_modules`, where pnpm installs out-of-tree plugins.
|
|
55
|
+
|
|
56
|
+
Use `--dump-default-config` and `--dump-config` to inspect the composed tree without booting it.
|
|
57
|
+
|
|
58
|
+
The [CLI behavior reference](reference/README.md) owns exact layer precedence, flags, shutdown behavior, deployment defaults, and source execution. The [startup and reload failure table](../../packages/boot/app-boot/README.md#startup-and-reload-failures) compares optional and required plugin failures with configuration HMR.
|
|
59
|
+
|
|
60
|
+
## Optional overlays
|
|
61
|
+
|
|
62
|
+
`config/examples/` ships opt-in overlays for GitHub review webhooks, session-local Schedule, memory MCP servers, and runtime Kylin tools. They are never part of a default profile; the [user guides](../../docs/user/guide/index.md) and [developer practice guides](../../docs/user/develop/practice/index.md) own setup and safety instructions.
|
|
63
|
+
|
|
64
|
+
## Development
|
|
65
|
+
|
|
66
|
+
Production runs require built package and frontend artifacts. From the repository root, run `pnpm run build` separately, then use `pnpm qilin <args...>` to run the TypeScript entry and forward every argument; the [source-execution reference](reference/README.md#source-execution) owns the module-resolution contract.
|
|
67
|
+
|
|
68
|
+
The `@qilin-agent/cli/profile-boot` export provides the shared profile lifecycle to the Desktop host. A resolved application profile supplies its own installation anchor for runtime package resolution while retaining the Harness home patch, proxy environment, telemetry switch, patch reload, and bounded shutdown.
|
|
69
|
+
|
|
70
|
+
The [Web failure matrix](tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts) runs the built CLI through startup failures and native configuration HMR with `awaitWriteFinish` enabled in `test:expected`. It verifies authenticated HTTP responses, diagnostics, recovery, process exits, and disposal without model API calls; the [startup acceptance](tests/profiles/web/tests/web-best-effort-startup.expected.e2e.ts) also covers the shipped required Web dependencies and port conflicts.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# `@qilin-agent/cli`
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 中文
|
|
4
|
+
|
|
5
|
+
`qilin` 是唯一受支持的 Node 应用启动器;profile 由多个插件组合包 patch 层按顺序叠加而成,其上再应用用户自己的覆盖配置。SDK 与 ACP(Agent Client Protocol)都是 profile,而不是独立的公开可执行命令。Python 运行时 wheel 包中也包含同一个命令;SDK 默认使用 `sdk`,极简示例选择 `sdk-minimal`。[`src/args.ts`](src/args.ts) 负责命令语法,[`src/bin.ts`](src/bin.ts) 只加载选中的运行器。无效命令、来自其他模式的选项,以及致命的配置或启动错误都会以非零状态退出。
|
|
6
|
+
|
|
7
|
+
## 入口模式
|
|
8
|
+
|
|
9
|
+
| 命令 | 用途 |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `qilin <name>` / `qilin --profile <name>` | 启动位于 `$QILIN_HOME/profiles/<name>` 的指定 profile。 |
|
|
12
|
+
| `qilin --profile <name> --from-default-profile <template>` | 从随附模板创建新的自定义 profile,然后启动它。 |
|
|
13
|
+
| `qilin --profile acp` | 通过 ACP stdio 为自动化客户端提供服务,直至断开连接。 |
|
|
14
|
+
| `qilin --profile headless "job"` | 运行一个全新的持久化会话,打印最终答案并退出。 |
|
|
15
|
+
| `qilin --profile sdk` | 通过 JSON-RPC stdio 为 SDK 客户端提供服务,直至关闭或断开连接。 |
|
|
16
|
+
| `qilin --profile sdk-minimal` | 以独立极简 agent(智能体)配置树为 SDK 客户端提供服务。 |
|
|
17
|
+
| `qilin web` | 启动 Web profile。 |
|
|
18
|
+
| `qilin plugin --profile <name> <pnpm args>` | 通过在 profile 目录中转发给 pnpm 来管理该 profile 的插件。 |
|
|
19
|
+
| `qilin plugin list` | 按激活顺序列出某个 profile 的 bundle 层;省略 `--profile` 时使用产品 profile。 |
|
|
20
|
+
| `qilin plugin doctor <包名\|目录>` | 报告某个插件包的 DSH 时代兼容性,不安装也不运行任何东西。 |
|
|
21
|
+
|
|
22
|
+
运行命令时所在的目录将作为默认 workspace 根目录。`web`、`headless`、`sdk`、`sdk-minimal` 和 `acp` profile 在首次使用时会从随附模板自动初始化。使用 `--from-default-profile` 可以基于这些模板之一,在尚未使用的非内置名称处创建其他 profile;通过 `qilin plugin` 则可以初始化一个以 base 为基础的 profile。`desktop` 名称保留给 Electron 持有的 profile,因此 CLI(命令行界面)会拒绝针对它的启动、配置 dump 和插件管理请求。包操作成功后命令会协调 profile 的 bundle 列表;若 profile 的已安装依赖中出现上游 DSH 时代的引擎包,命令会拒绝:诊断会指明每个冲突包、它映射到的 QiLin 包,以及清除它的 `remove` 命令,命令以退出码 1 结束且不改变 bundle 列表。
|
|
23
|
+
|
|
24
|
+
`list` 与 `doctor` 只读取 profile,既不初始化它也不运行 pnpm。`doctor` 接受已安装的包名或包目录,检查插件要在此加载必须满足的四条规则:包是否自己拼出 DSH 时代的主目录而不是读取 `DSH_HOME`/`QILIN_HOME`、是否安装了 harness 已提供的引擎包、是否导入了未声明为 peer 的引擎名、以及是否注入了兼容层无法映射的客户端模块名。它每行输出一条发现,仅当某条发现会阻断激活时才以退出码 1 结束。
|
|
25
|
+
|
|
26
|
+
`list` 把随附模板层标为 `(shipped)`:它随运行中的安装实例走,无法从 profile 移除。列表里其余每层都归 profile 所有——例如通过 `qilin plugin add` 装回的已退役 `dsh-animations` 动效技能包——可原地升级或移除,无需等待 QiLin 发版。
|
|
27
|
+
|
|
28
|
+
命令本身从已发布的包安装(`npm install -g @qilin-agent/cli`)即可把 `qilin` 放到 `PATH`;manifest 把 `lib/bin.js` 声明为 `qilin` bin,并且只随包发布该 bundle。
|
|
29
|
+
|
|
30
|
+
## 应用参数
|
|
31
|
+
|
|
32
|
+
启动器只解析自身的 flag,并将其后的所有内容交给已启动的 profile;注入该 profile 的任意应用插件都可以解析这份共享的不可变快照([`qilin-cmdline`](../../packages/boot/cmdline/README.zh.md))。启动器无法识别的第一个 token 标志着应用参数的开始:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
qilin --profile web --port 8080 # --port belongs to the web app
|
|
36
|
+
qilin --profile tui --resume <id> # example, assuming the tui profile is installed; --resume belongs to the terminal app
|
|
37
|
+
qilin --profile headless "run the tests"
|
|
38
|
+
qilin --profile web --help # the web app's flags, not the launcher's
|
|
39
|
+
qilin --help # the launcher's own help
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
<a id="profiles"></a>
|
|
43
|
+
## Profile
|
|
44
|
+
|
|
45
|
+
profile 目录包含一个 `package.json`,其中记录树外插件依赖,以及 profile manifest(元数据清单)`qilin.profile`、其中按顺序排列的 `bundles` 列表;还包含一个 `cordis.patch.yml`,其中保存用户自己的 patch 层。在 YAML 中启用的 `qilin-hmr` 监视 profile manifest、profile 与 home 级 patch 文件,再通过统一串行重载重新组合所有层。未启用 HMR 时,更改在重启后生效。监听器注册期间发生的编辑与后续编辑使用相同的非致命重载错误报告。[插件管理器](../../packages/boot/plugin-manager/README.zh.md) 与 `qilin plugin` 共享包操作和 profile 写锁;更新依赖会保留已停用的组合包选择。CLI 包操作继承认证环境和终端描述符,支持交互式构建批准;service 调用保留清理后的环境并捕获诊断。
|
|
46
|
+
|
|
47
|
+
安装与 profile 启动会用 `qilin --version` 打印的同一个运行时版本校验已声明的 qilin peer 范围。不兼容的插件必须显式确认精确版本豁免,`qilin plugin allow-version`、`revoke-version` 与 `version-exemptions` 按 profile 管理这些豁免。[插件管理器兼容性参考](../../packages/boot/plugin-manager/README.zh.md#version-compatibility-and-exemptions)记录了命令、持久化方式与风险。
|
|
48
|
+
|
|
49
|
+
配置树以空根为起点,依次叠加以下配置层:
|
|
50
|
+
- `qilin.profile.bundles` 中各组合包的 patch
|
|
51
|
+
- profile 自身的 `cordis.patch.yml`,然后是 home 级的 `$QILIN_HOME/cordis.patch.yml`
|
|
52
|
+
- `--patch` 指定的覆盖层
|
|
53
|
+
|
|
54
|
+
`qilin.profile.bundles` 中列出的组合包先从 qilin 安装目录解析(`@qilin-agent/base`、`@qilin-agent/web-app`、`@qilin-agent/headless`、`@qilin-agent/sdk-app`、`@qilin-agent/sdk-minimal`、`@qilin-agent/acp-app`),再从 profile 自身的 `node_modules` 解析;pnpm 会将树外插件安装到该目录。
|
|
55
|
+
|
|
56
|
+
使用 `--dump-default-config` 和 `--dump-config` 可在不启动的情况下检查组合后的配置树。
|
|
57
|
+
|
|
58
|
+
层的确切优先级、flag、关闭行为、部署默认值和源码执行方式,以 [CLI 行为参考](reference/README.zh.md)为准。[启动与重载失败表](../../packages/boot/app-boot/README.zh.md#startup-and-reload-failures)对比 optional、required 插件启动失败与配置 HMR 的行为。
|
|
59
|
+
|
|
60
|
+
## 可选覆盖层
|
|
61
|
+
|
|
62
|
+
`config/examples/` 交付 GitHub 评审 webhook、会话内 Schedule、记忆 MCP 服务器与运行时 Kylin 工具的可选覆盖层。它们绝不属于默认 profile;设置与安全说明由[用户指南](../../docs/user/guide/index.zh.md)和[开发实战指南](../../docs/user/develop/practice/index.zh.md)负责。
|
|
63
|
+
|
|
64
|
+
## 开发
|
|
65
|
+
|
|
66
|
+
生产运行需要已构建的包与前端产物。请在仓库根目录单独运行 `pnpm run build`,然后使用 `pnpm qilin <args...>` 运行 TypeScript 入口并转发所有参数;模块解析约定以[源码执行参考](reference/README.zh.md#source-execution)为准。
|
|
67
|
+
|
|
68
|
+
`@qilin-agent/cli/profile-boot` 导出向 Desktop Host 提供共享 profile 生命周期。已解析的应用 profile 为运行时包解析指定自己的安装锚点,同时沿用 Harness home patch、代理环境、遥测开关、patch 热重载和有界关闭。
|
|
69
|
+
|
|
70
|
+
[Web 失败矩阵](tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts)在 `test:expected` 中通过构建后的 CLI 验证启动失败与启用 `awaitWriteFinish` 的原生配置 HMR。它不调用模型 API,而是检查经过认证的 HTTP 响应、诊断、恢复、进程退出与 dispose;[启动验收测试](tests/profiles/web/tests/web-best-effort-startup.expected.e2e.ts)还覆盖随附 Web 的必需依赖与端口冲突。
|
package/lib/bin.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StartupError, getQilinRuntimeVersion, loadLayeredEnv } from "@qilin-agent/app-boot";
|
|
3
|
+
import { resolveQilinHome } from "@qilin-agent/home-paths";
|
|
4
|
+
import { Command, CommanderError, InvalidArgumentError } from "commander";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { inspect } from "node:util";
|
|
9
|
+
//#region lib/types/args.js
|
|
10
|
+
/**
|
|
11
|
+
* Commander adapter for the `qilin` command line.
|
|
12
|
+
*
|
|
13
|
+
* The launcher parses only what it owns — which profile to boot, which extra
|
|
14
|
+
* patch overlays to apply, and the config dumps — and hands **everything after
|
|
15
|
+
* its own flags** to the booted tree verbatim, where injected app plugins parse
|
|
16
|
+
* their own flag families and print their own `--help` (see
|
|
17
|
+
* `@qilin-agent/cmdline`). Launcher flags therefore come first: the first
|
|
18
|
+
* token this parser does not recognize starts the inner arguments, so
|
|
19
|
+
* `qilin --profile tui --resume abc` boots the tui profile with `--resume abc`,
|
|
20
|
+
* and `qilin --profile web -h` prints the web app's help, not this one's.
|
|
21
|
+
*
|
|
22
|
+
* `qilin <name>` abbreviates `qilin --profile <name>`; `plugin` manages a profile's
|
|
23
|
+
* plugin dependencies by forwarding to pnpm.
|
|
24
|
+
* @module @qilin-agent/cli/args
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Repeatable single-value collector: `--patch a.yml --patch b.yml`. Never
|
|
28
|
+
* variadic — a variadic `--patch` would swallow the inner arguments.
|
|
29
|
+
*/
|
|
30
|
+
const collect = (value, previous = []) => [...previous, value];
|
|
31
|
+
function selectProfile(value, previous) {
|
|
32
|
+
if (previous !== void 0) throw new InvalidArgumentError("select a profile only once");
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
function rejectReservedDesktopProfile(program, profile) {
|
|
36
|
+
if (profile.toLowerCase() === "desktop") program.error("error: profile \"desktop\" belongs to the separate QiLin desktop application, not this repository");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Profile a bare `qilin` boots: the QiLin product surface. It is the only
|
|
40
|
+
* profile a user has to know, so naming it again on the command line would
|
|
41
|
+
* only repeat the product's own name.
|
|
42
|
+
*/
|
|
43
|
+
const PRODUCT_PROFILE = "qilin";
|
|
44
|
+
/** The launcher's own help text; each app prints its own. */
|
|
45
|
+
const HELP_EXAMPLES = `
|
|
46
|
+
Examples:
|
|
47
|
+
qilin boot the QiLin product surface, then serve it
|
|
48
|
+
qilin --no-open the same, without opening a browser
|
|
49
|
+
qilin web boot the unbranded web surface (same as: qilin --profile web)
|
|
50
|
+
qilin rescue --from-default-profile web
|
|
51
|
+
create rescue from the shipped web template, then boot it
|
|
52
|
+
qilin headless "run the tests" answer one task, print the result, and exit
|
|
53
|
+
qilin tui --patch ./extra.yml boot a custom profile with one extra overlay
|
|
54
|
+
qilin tui --resume <session> arguments after the launcher flags reach the app
|
|
55
|
+
qilin web --help the web app's own flags and help
|
|
56
|
+
qilin plugin list list the product profile's plugin layers
|
|
57
|
+
qilin plugin doctor <package|directory> report one plugin's DSH-era compatibility
|
|
58
|
+
qilin plugin add <package> install a plugin into the product profile
|
|
59
|
+
qilin plugin --profile tui add <package> install a plugin into the tui profile
|
|
60
|
+
qilin plugin version-exemptions list the profile's exact-version exemptions
|
|
61
|
+
qilin plugin allow-version <pkg@ver> --qilin-version <exact> --accept-risk
|
|
62
|
+
allow one rejected plugin/runtime pair
|
|
63
|
+
qilin plugin revoke-version <pkg@ver> --qilin-version <exact>
|
|
64
|
+
withdraw one exemption
|
|
65
|
+
`;
|
|
66
|
+
/**
|
|
67
|
+
* Resolve a boot or dump invocation from the launcher flags and the leftover
|
|
68
|
+
* inner arguments.
|
|
69
|
+
* @param program - the command whose options were parsed.
|
|
70
|
+
* @param profile - the profile these flags boot.
|
|
71
|
+
* @param options - the launcher flags commander collected.
|
|
72
|
+
* @param args - the leftover arguments, in argv order.
|
|
73
|
+
* @returns the resolved invocation.
|
|
74
|
+
*/
|
|
75
|
+
function resolveBoot(program, profile, options, args) {
|
|
76
|
+
const patches = options.patch ?? [];
|
|
77
|
+
if (patches.includes("")) program.error("error: --patch needs a path");
|
|
78
|
+
if (options.fromDefaultProfile === "") program.error("error: --from-default-profile needs a name");
|
|
79
|
+
if (options.dumpConfig !== true && options.dumpDefaultConfig !== true) return {
|
|
80
|
+
mode: "profile",
|
|
81
|
+
profile,
|
|
82
|
+
fromDefaultProfile: options.fromDefaultProfile,
|
|
83
|
+
patches,
|
|
84
|
+
args
|
|
85
|
+
};
|
|
86
|
+
if (options.dumpConfig === true && options.dumpDefaultConfig === true) program.error("error: --dump-config and --dump-default-config are mutually exclusive");
|
|
87
|
+
if (args.length > 0) program.error(`error: config dumps take no app arguments, got ${args.map((argument) => JSON.stringify(argument)).join(" ")}`);
|
|
88
|
+
const defaultOnly = options.dumpDefaultConfig === true;
|
|
89
|
+
if (defaultOnly && patches.length > 0) program.error("error: --dump-default-config prints the bundle layers and takes no --patch");
|
|
90
|
+
return {
|
|
91
|
+
mode: "dump-config",
|
|
92
|
+
profile,
|
|
93
|
+
fromDefaultProfile: options.fromDefaultProfile,
|
|
94
|
+
defaultOnly,
|
|
95
|
+
patches
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Resolve argv into one invocation, or print and exit for help, version, or an
|
|
100
|
+
* error.
|
|
101
|
+
* @param argv - arguments after the Node binary and script.
|
|
102
|
+
* @param version - version string printed by `--version`.
|
|
103
|
+
* @returns the resolved invocation.
|
|
104
|
+
*/
|
|
105
|
+
function parseQilinArgs(argv, version) {
|
|
106
|
+
const first = argv[0];
|
|
107
|
+
let resolved;
|
|
108
|
+
const program = new Command();
|
|
109
|
+
program.name("qilin").version(version, "-V, --version", "output the version number").usage("[--profile] <name> [options] [app-args...]\n qilin plugin --profile <name> <pnpm-args...>").description("qilin: boot the QiLin product surface, or any profile — an ordered stack of plugin-bundle patch layers under your own overrides.").addHelpText("after", HELP_EXAMPLES).exitOverride().helpOption(false).helpCommand(false).allowUnknownOption().passThroughOptions().enablePositionalOptions().argument("[args...]", "arguments for the booted profile's app (see: qilin --profile <name> --help)").option("--profile <name>", "the profile under $QILIN_HOME/profiles to boot", selectProfile).option("--from-default-profile <name>", "initialize a new custom profile from a shipped profile template").option("--patch <path>", "extra patch-list overlay applied after the profile layer (repeatable)", collect).option("--dump-config", "print the composed profile tree and exit").option("--dump-default-config", "print the profile tree without its user layer or --patch overlays and exit").action((args, options) => {
|
|
110
|
+
if (options.profile === void 0 && args.some((argument) => argument === "-h" || argument === "--help")) program.help();
|
|
111
|
+
const profile = options.profile ?? PRODUCT_PROFILE;
|
|
112
|
+
if (profile === "") program.error("error: --profile needs a name");
|
|
113
|
+
rejectReservedDesktopProfile(program, profile);
|
|
114
|
+
resolved = resolveBoot(program, profile, options, args);
|
|
115
|
+
});
|
|
116
|
+
if (first === "plugin") {
|
|
117
|
+
const plugin = program.command("plugin").description("manage a profile's plugins: list them, forward pnpm arguments, or grant an exact-version compatibility exemption");
|
|
118
|
+
plugin.option("--profile <name>", "the profile whose plugins to manage (defaults to the product profile; initialized on first use)", selectProfile).allowUnknownOption().argument("[args...]", "one of: list, doctor <name|path>, version-exemptions, allow-version <package@version> --qilin-version <exact> --accept-risk, revoke-version <package@version> --qilin-version <exact>; otherwise pnpm arguments forwarded verbatim (add <pkg>, remove <pkg>, why <pkg>, ...)").action((args, options) => {
|
|
119
|
+
const profile = options.profile ?? PRODUCT_PROFILE;
|
|
120
|
+
if (profile === "") program.error("error: --profile needs a name");
|
|
121
|
+
rejectReservedDesktopProfile(plugin, profile);
|
|
122
|
+
if (args.length === 0) program.error("error: plugin needs a subcommand (list, doctor <name|path>, version-exemptions, allow-version <package@version>, revoke-version <package@version>) or pnpm arguments to forward (e.g. add <package>)");
|
|
123
|
+
if (args[0] === "list" && args.length > 1) program.error("error: plugin list takes no further arguments");
|
|
124
|
+
if (args[0] === "doctor" && args.length !== 2) program.error("error: plugin doctor takes exactly one installed package name or package directory");
|
|
125
|
+
resolved = {
|
|
126
|
+
mode: "plugin",
|
|
127
|
+
profile,
|
|
128
|
+
args
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const expanded = first !== void 0 && !first.startsWith("-") && first !== "plugin" ? ["--profile", ...argv] : argv;
|
|
134
|
+
program.parse(expanded, { from: "user" });
|
|
135
|
+
} catch (error) {
|
|
136
|
+
return process.exit(error instanceof CommanderError ? error.exitCode : 1);
|
|
137
|
+
}
|
|
138
|
+
/* v8 ignore next -- an action resolves or Commander throws */
|
|
139
|
+
if (resolved === void 0) throw new Error("qilin: no invocation resolved");
|
|
140
|
+
return resolved;
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region lib/types/startup-diagnostics.js
|
|
144
|
+
/** Save original startup diagnostics while keeping the terminal report concise. */
|
|
145
|
+
/** Wait for stderr to finish the write before the failed process exits. */
|
|
146
|
+
function writeStderr(text) {
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
process.stderr.write(text, (error) => {
|
|
149
|
+
if (error) reject(error);
|
|
150
|
+
else resolve();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Print the startup summary and save a private, uniquely named report under QILIN_HOME/logs.
|
|
156
|
+
* Failed writes print the complete report to stderr instead of claiming a saved path.
|
|
157
|
+
* @param error - startup audit failure retaining plugin metadata and original errors.
|
|
158
|
+
* @param context - resolved Harness home, application version, and selected profile.
|
|
159
|
+
* @param write - terminal output sink; awaited before returning, defaults to stderr.
|
|
160
|
+
* @returns after saving or printing the report and completing terminal writes.
|
|
161
|
+
*/
|
|
162
|
+
async function reportStartupFailure(error, context, write = writeStderr) {
|
|
163
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
164
|
+
const report = "WARNING: Raw diagnostics may contain configuration or credential values from plugin errors. Review before sharing.\n\n" + inspect({
|
|
165
|
+
timestamp: now,
|
|
166
|
+
qilinVersion: context.version,
|
|
167
|
+
nodeVersion: process.version,
|
|
168
|
+
platform: process.platform,
|
|
169
|
+
arch: process.arch,
|
|
170
|
+
profile: context.profile,
|
|
171
|
+
error
|
|
172
|
+
}, {
|
|
173
|
+
depth: null,
|
|
174
|
+
maxArrayLength: null,
|
|
175
|
+
maxStringLength: null,
|
|
176
|
+
showHidden: true,
|
|
177
|
+
customInspect: false,
|
|
178
|
+
getters: false,
|
|
179
|
+
colors: false
|
|
180
|
+
}) + "\n";
|
|
181
|
+
await write(`${error.message}\n`);
|
|
182
|
+
const logDir = join(context.home, "logs");
|
|
183
|
+
const logPath = join(logDir, `startup-${now.replaceAll(":", "-")}-${randomUUID()}.log`);
|
|
184
|
+
try {
|
|
185
|
+
await mkdir(logDir, {
|
|
186
|
+
recursive: true,
|
|
187
|
+
mode: 448
|
|
188
|
+
});
|
|
189
|
+
await writeFile(logPath, report, {
|
|
190
|
+
flag: "wx",
|
|
191
|
+
mode: 384
|
|
192
|
+
});
|
|
193
|
+
} catch (writeError) {
|
|
194
|
+
await write(`\nqilin: warning: could not write startup diagnostics: ${String(writeError)}\nFull diagnostics:\n${report}`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
await write(`\nFull diagnostics: ${logPath}\n`);
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region lib/types/bin.js
|
|
201
|
+
/**
|
|
202
|
+
* Command-line entry for qilin.
|
|
203
|
+
* @module @qilin-agent/cli/bin
|
|
204
|
+
*/
|
|
205
|
+
/* v8 ignore file -- built-bin acceptance exercises this self-executing dispatch. */
|
|
206
|
+
if (globalThis.scheduler === void 0) Object.defineProperty(globalThis, "scheduler", {
|
|
207
|
+
value: { yield: () => new Promise((resolve) => setImmediate(resolve)) },
|
|
208
|
+
writable: true,
|
|
209
|
+
configurable: true
|
|
210
|
+
});
|
|
211
|
+
/**
|
|
212
|
+
* Run the public qilin command-line interface.
|
|
213
|
+
* @returns a promise that settles when the selected command mode finishes.
|
|
214
|
+
*/
|
|
215
|
+
async function runCli() {
|
|
216
|
+
const version = getQilinRuntimeVersion();
|
|
217
|
+
const invocation = parseQilinArgs(process.argv.slice(2), version);
|
|
218
|
+
switch (invocation.mode) {
|
|
219
|
+
case "profile": {
|
|
220
|
+
const { runProfile } = await import("./profile-boot.js");
|
|
221
|
+
try {
|
|
222
|
+
await runProfile({
|
|
223
|
+
environment: loadLayeredEnv("qilin"),
|
|
224
|
+
profile: invocation.profile,
|
|
225
|
+
fromDefaultProfile: invocation.fromDefaultProfile,
|
|
226
|
+
patchFiles: invocation.patches,
|
|
227
|
+
args: invocation.args
|
|
228
|
+
});
|
|
229
|
+
} catch (error) {
|
|
230
|
+
if (!(error instanceof StartupError)) throw error;
|
|
231
|
+
await reportStartupFailure(error, {
|
|
232
|
+
home: resolveQilinHome(),
|
|
233
|
+
version,
|
|
234
|
+
profile: invocation.profile
|
|
235
|
+
});
|
|
236
|
+
process.exit(1);
|
|
237
|
+
}
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case "plugin": {
|
|
241
|
+
const { runPlugin } = await import("./plugin-BQ1sn-63.js");
|
|
242
|
+
process.exit(await runPlugin(invocation.profile, invocation.args));
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case "dump-config": {
|
|
246
|
+
const { runDumpConfig } = await import("./dump-config-_HRfhhWz.js");
|
|
247
|
+
runDumpConfig(invocation.profile, invocation.defaultOnly, invocation.patches, invocation.fromDefaultProfile);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
default: throw new Error(`qilin: unhandled invocation mode ${JSON.stringify(invocation)}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (import.meta.main) await runCli();
|
|
254
|
+
//#endregion
|
|
255
|
+
export { runCli };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { a as prepareProfile, n as PROFILE_ROOT_FILENAME, r as homePatchPath } from "./profile-boot-DSy6PUHQ.js";
|
|
2
|
+
import { loadOptionalPatches, loadOverlayPatches, renderConfigDump } from "@qilin-agent/app-boot";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
//#region lib/types/dump-config.js
|
|
6
|
+
/**
|
|
7
|
+
* Config-dump entry for `qilin --profile <name> --dump-config`: compose the
|
|
8
|
+
* profile's patch layers through the include plugin's patch algorithm without
|
|
9
|
+
* booting or evaluating `!!js`, with one source layer per bundle, the
|
|
10
|
+
* profile's own patch file, and each `--patch` overlay.
|
|
11
|
+
* @module @qilin-agent/cli/dump-config
|
|
12
|
+
*/
|
|
13
|
+
const NAME = "qilin";
|
|
14
|
+
/* v8 ignore start -- built-bin acceptance drives this boot-free dispatch */
|
|
15
|
+
/**
|
|
16
|
+
* Print a profile composition with comments naming each source file and patch layer.
|
|
17
|
+
* @param profile - the profile name.
|
|
18
|
+
* @param defaultOnly - omit the profile's user layer and `--patch` overlays
|
|
19
|
+
* (the recovery diagnostic for a broken `cordis.patch.yml`, which is then
|
|
20
|
+
* never parsed).
|
|
21
|
+
* @param patches - `--patch` overlay paths, in argv order.
|
|
22
|
+
* @param fromDefaultProfile - shipped template used once to initialize a missing profile.
|
|
23
|
+
*/
|
|
24
|
+
function runDumpConfig(profile, defaultOnly, patches, fromDefaultProfile) {
|
|
25
|
+
const loaded = prepareProfile(profile, !defaultOnly, fromDefaultProfile);
|
|
26
|
+
const layers = loaded.layers.map((layer) => ({
|
|
27
|
+
label: layer.packageName,
|
|
28
|
+
patches: layer.patches
|
|
29
|
+
}));
|
|
30
|
+
if (!defaultOnly) {
|
|
31
|
+
if (existsSync(loaded.patchPath)) layers.push({
|
|
32
|
+
label: loaded.patchPath,
|
|
33
|
+
patches: loaded.patches
|
|
34
|
+
});
|
|
35
|
+
const homePatchFile = homePatchPath();
|
|
36
|
+
const homePatches = loadOptionalPatches(NAME, homePatchFile);
|
|
37
|
+
if (homePatches !== void 0) layers.push({
|
|
38
|
+
label: homePatchFile,
|
|
39
|
+
patches: homePatches
|
|
40
|
+
});
|
|
41
|
+
for (const file of patches) {
|
|
42
|
+
const absolute = resolve(file);
|
|
43
|
+
layers.push({
|
|
44
|
+
label: absolute,
|
|
45
|
+
patches: loadOverlayPatches(NAME, absolute)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
process.stdout.write(renderConfigDump(NAME, join(loaded.dir, PROFILE_ROOT_FILENAME), layers));
|
|
50
|
+
}
|
|
51
|
+
/* v8 ignore stop */
|
|
52
|
+
//#endregion
|
|
53
|
+
export { runDumpConfig };
|