@civilization/dsh 0.0.0-stage → 0.2.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
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.
@@ -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
+ /deepseek-ai-dsh:
6
+ en: ebdc75fa0da18801
7
+ zh: 5c6cd2554b8f8a98
8
+ /deepseek-ai-dsh/entry-modes:
9
+ en: c4811e2012a5e919
10
+ zh: e6d20ec8238c2638
11
+ /deepseek-ai-dsh/app-arguments:
12
+ en: cc03e6b75206661b
13
+ zh: 99e41f4143198352
14
+ /deepseek-ai-dsh/profiles:
15
+ en: 79cad979b0f7895c
16
+ zh: b0f922a4b43accf8
17
+ /deepseek-ai-dsh/optional-overlays:
18
+ en: 3a40ddc44e55f79c
19
+ zh: 8d3949132e1ef93c
20
+ /deepseek-ai-dsh/development:
21
+ en: 0a289c1235869927
22
+ zh: a1f473f70036ad37
package/README.md CHANGED
@@ -1,3 +1,64 @@
1
- # Temporary Holding Version
1
+ # `@deepseek-ai/dsh`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ English | [中文](README.zh.md)
4
+
5
+ The `dsh` 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
+ | `dsh <name>` / `dsh --profile <name>` | Boot the named profile under `$DSH_HOME/profiles/<name>`. |
12
+ | `dsh --profile <name> --from-default-profile <template>` | Create a new custom profile from a shipped template, then boot it. |
13
+ | `dsh --profile acp` | Serve automation clients over ACP stdio until disconnect. |
14
+ | `dsh --profile headless "job"` | Run one fresh persisted session, print the final answer, and exit. |
15
+ | `dsh --profile sdk` | Serve SDK clients over JSON-RPC stdio until shutdown or disconnect. |
16
+ | `dsh --profile sdk-minimal` | Serve SDK clients with the standalone minimal agent tree. |
17
+ | `dsh web` | Boot the Web profile. |
18
+ | `dsh plugin --profile <name> <pnpm args>` | Manage a profile's plugins by forwarding to pnpm in the profile directory. |
19
+
20
+ 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 `dsh plugin`. The `desktop` name is reserved for the Electron-owned profile, so the CLI rejects boot and config-dump requests for it. The npm CLI also rejects its plugin-management requests; the [Desktop-installed command](../desktop/README.md#bundled-command-runtime) can manage the initialized Desktop profile using that installation’s runtime.
21
+
22
+ ## App arguments
23
+
24
+ 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 ([`dsh-cmdline`](../../packages/boot/cmdline/README.md)). The first token the launcher does not recognize starts the app's arguments:
25
+
26
+ ```sh
27
+ dsh --profile web --port 8080 # --port belongs to the web app
28
+ dsh --profile tui --resume <id> # example, assuming the tui profile is installed; --resume belongs to the terminal app
29
+ dsh --profile headless "run the tests"
30
+ dsh --profile web --help # the web app's flags, not the launcher's
31
+ dsh --help # the launcher's own help
32
+ ```
33
+
34
+ <a id="profiles"></a>
35
+ ## Profiles
36
+
37
+ A profile directory holds a `package.json` (out-of-tree plugin dependencies plus the profile manifest `dsh.profile` with its ordered `bundles` list) and a `cordis.patch.yml` (the user's own patch layer). `dsh-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 `dsh 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.
38
+
39
+ Installation and profile startup enforce declared DSH peer ranges against the same runtime version shown by `dsh --version`. Incompatible plugins require an explicitly acknowledged exact-version exemption. The [plugin manager's compatibility reference](../../packages/boot/plugin-manager/README.md#version-compatibility-and-exemptions) documents `version-exemptions`, `allow-version`, `revoke-version`, persistence, and risks.
40
+
41
+ The tree composes over an empty root:
42
+ - each bundle's patch in `dsh.profile.bundles` order
43
+ - then the profile's `cordis.patch.yml`, then the home-level `$DSH_HOME/cordis.patch.yml`
44
+ - then `--patch` overlays
45
+
46
+ Bundles named in `dsh.profile.bundles` resolve from the dsh installation first (`@deepseek-ai/dsh-base`, `@deepseek-ai/dsh-web-app`, `@deepseek-ai/dsh-headless`, `@deepseek-ai/dsh-sdk-app`, `@deepseek-ai/dsh-sdk-minimal`, `@deepseek-ai/dsh-acp-app`), then from the profile's own `node_modules`, where pnpm installs out-of-tree plugins.
47
+
48
+ Use `--dump-default-config` and `--dump-config` to inspect the composed tree without booting it. `--dump-config-schema` imports the composed tree's declared plugin schemas and prints JSON Schema for entries and patches instead of configuration values; read the [schema-dump safety and scope](reference/README.md#config-schema-dump) before inspecting untrusted plugins.
49
+
50
+ 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.
51
+
52
+ ## Optional overlays
53
+
54
+ `config/examples/` ships opt-in overlays for GitHub review webhooks, memory MCP servers, and runtime Cordis 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.
55
+
56
+ ## Development
57
+
58
+ Production runs require built package and frontend artifacts. From the repository root, run `pnpm run build` separately, then use `pnpm dsh <args...>` to run the TypeScript entry and forward every argument; the [source-execution reference](reference/README.md#source-execution) owns the module-resolution contract.
59
+
60
+ The `@deepseek-ai/dsh/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.
61
+
62
+ Packaged installations call the same `runCli()` entry with their package-manager executable. The Desktop carrier also enables plugin operations for its initialized profile; npm launches omit these options. Installation-owned package environments apply only to plugin package operations; the invoking directory, ordinary profile selection, and agent-shell PATH retain their CLI meanings.
63
+
64
+ 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,64 @@
1
+ # `@deepseek-ai/dsh`
2
+
3
+ [English](README.md) | 中文
4
+
5
+ `dsh` 是唯一受支持的 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
+ | `dsh <name>` / `dsh --profile <name>` | 启动位于 `$DSH_HOME/profiles/<name>` 的指定 profile。 |
12
+ | `dsh --profile <name> --from-default-profile <template>` | 从随附模板创建新的自定义 profile,然后启动它。 |
13
+ | `dsh --profile acp` | 通过 ACP stdio 为自动化客户端提供服务,直至断开连接。 |
14
+ | `dsh --profile headless "job"` | 运行一个全新的持久化会话,打印最终答案并退出。 |
15
+ | `dsh --profile sdk` | 通过 JSON-RPC stdio 为 SDK 客户端提供服务,直至关闭或断开连接。 |
16
+ | `dsh --profile sdk-minimal` | 以独立极简 agent(智能体)配置树为 SDK 客户端提供服务。 |
17
+ | `dsh web` | 启动 Web profile。 |
18
+ | `dsh plugin --profile <name> <pnpm args>` | 通过在 profile 目录中转发给 pnpm 来管理该 profile 的插件。 |
19
+
20
+ 运行命令时所在的目录将作为默认 workspace 根目录。`web`、`headless`、`sdk`、`sdk-minimal` 和 `acp` profile 在首次使用时会从随附模板自动初始化。使用 `--from-default-profile` 可以基于这些模板之一,在尚未使用的非内置名称处创建其他 profile;通过 `dsh plugin` 则可以初始化一个以 base 为基础的 profile。`desktop` 名称保留给 Electron 持有的 profile,因此 CLI(命令行界面)会拒绝针对它的启动和配置 dump 请求。npm CLI 也会拒绝其插件管理请求;[Desktop 内置命令](../desktop/README.zh.md#bundled-command-runtime)可以使用该安装的运行时管理已初始化的 Desktop profile。
21
+
22
+ ## 应用参数
23
+
24
+ 启动器只解析自身的 flag,并将其后的所有内容交给已启动的 profile;注入该 profile 的任意应用插件都可以解析这份共享的不可变快照([`dsh-cmdline`](../../packages/boot/cmdline/README.zh.md))。启动器无法识别的第一个 token 标志着应用参数的开始:
25
+
26
+ ```sh
27
+ dsh --profile web --port 8080 # --port belongs to the web app
28
+ dsh --profile tui --resume <id> # example, assuming the tui profile is installed; --resume belongs to the terminal app
29
+ dsh --profile headless "run the tests"
30
+ dsh --profile web --help # the web app's flags, not the launcher's
31
+ dsh --help # the launcher's own help
32
+ ```
33
+
34
+ <a id="profiles"></a>
35
+ ## Profile
36
+
37
+ profile 目录包含一个 `package.json`,其中记录树外插件依赖,以及 profile manifest(元数据清单)`dsh.profile`、其中按顺序排列的 `bundles` 列表;还包含一个 `cordis.patch.yml`,其中保存用户自己的 patch 层。在 YAML 中启用的 `dsh-hmr` 监视 profile manifest、profile 与 home 级 patch 文件,再通过统一串行重载重新组合所有层。未启用 HMR 时,更改在重启后生效。监听器注册期间发生的编辑与后续编辑使用相同的非致命重载错误报告。[插件管理器](../../packages/boot/plugin-manager/README.zh.md) 与 `dsh plugin` 共享包操作和 profile 写锁;更新依赖会保留已停用的组合包选择。CLI 包操作继承认证环境和终端描述符,支持交互式构建批准;service 调用保留清理后的环境并捕获诊断。
38
+
39
+ 安装和 profile 启动会按声明的 DSH peer 范围,检查与 `dsh --version` 显示值相同的运行时版本。不兼容插件需要用户明确确认精确版本豁免。[插件管理器的兼容性参考](../../packages/boot/plugin-manager/README.zh.md#version-compatibility-and-exemptions)说明 `version-exemptions`、`allow-version`、`revoke-version`、持久化规则与风险。
40
+
41
+ 配置树以空根为起点,依次叠加以下配置层:
42
+ - `dsh.profile.bundles` 中各组合包的 patch
43
+ - profile 自身的 `cordis.patch.yml`,然后是 home 级的 `$DSH_HOME/cordis.patch.yml`
44
+ - `--patch` 指定的覆盖层
45
+
46
+ `dsh.profile.bundles` 中列出的组合包先从 dsh 安装目录解析(`@deepseek-ai/dsh-base`、`@deepseek-ai/dsh-web-app`、`@deepseek-ai/dsh-headless`、`@deepseek-ai/dsh-sdk-app`、`@deepseek-ai/dsh-sdk-minimal`、`@deepseek-ai/dsh-acp-app`),再从 profile 自身的 `node_modules` 解析;pnpm 会将树外插件安装到该目录。
47
+
48
+ 使用 `--dump-default-config` 和 `--dump-config` 可在不启动的情况下检查组合后的配置树。`--dump-config-schema` 会导入组合树中插件声明的 schema,并打印描述 entry 与 patch 的 JSON Schema,而不是配置值;检查不受信任的插件前,请阅读 [schema dump 的安全性与范围](reference/README.zh.md#config-schema-dump)。
49
+
50
+ 层的确切优先级、flag、关闭行为、部署默认值和源码执行方式,以 [CLI 行为参考](reference/README.zh.md)为准。[启动与重载失败表](../../packages/boot/app-boot/README.zh.md#startup-and-reload-failures)对比 optional、required 插件启动失败与配置 HMR 的行为。
51
+
52
+ ## 可选覆盖层
53
+
54
+ `config/examples/` 交付 GitHub 评审 webhook、记忆 MCP 服务器与运行时 Cordis 工具的可选覆盖层。它们绝不属于默认 profile;设置与安全说明由[用户指南](../../docs/user/guide/index.zh.md)和[开发实战指南](../../docs/user/develop/practice/index.zh.md)负责。
55
+
56
+ ## 开发
57
+
58
+ 生产运行需要已构建的包与前端产物。请在仓库根目录单独运行 `pnpm run build`,然后使用 `pnpm dsh <args...>` 运行 TypeScript 入口并转发所有参数;模块解析约定以[源码执行参考](reference/README.zh.md#source-execution)为准。
59
+
60
+ `@deepseek-ai/dsh/profile-boot` 导出向 Desktop Host 提供共享 profile 生命周期。已解析的应用 profile 为运行时包解析指定自己的安装锚点,同时沿用 Harness home patch、代理环境、遥测开关、patch 热重载和有界关闭。
61
+
62
+ 打包安装通过同一个 `runCli()` 入口传入包管理器可执行文件。Desktop 载体还会启用其已初始化 profile 的插件操作;npm 启动不传入这些选项。安装包提供的包管理环境仅用于插件包操作;调用目录、普通 profile 选择与 agent shell 的 PATH 保留 CLI 语义。
63
+
64
+ [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,254 @@
1
+ #!/usr/bin/env node
2
+ import { StartupError, getDshRuntimeVersion, loadLayeredEnv } from "@deepseek-ai/dsh-app-boot";
3
+ import { resolveDshHome } from "@deepseek-ai/dsh-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 `dsh` 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
+ * `@deepseek-ai/dsh-cmdline`). Launcher flags therefore come first: the first
18
+ * token this parser does not recognize starts the inner arguments, so
19
+ * `dsh --profile tui --resume abc` boots the tui profile with `--resume abc`,
20
+ * and `dsh --profile web -h` prints the web app's help, not this one's.
21
+ *
22
+ * `dsh <name>` abbreviates `dsh --profile <name>`; `plugin` manages a profile's
23
+ * plugin dependencies by forwarding to pnpm.
24
+ * @module @deepseek-ai/dsh/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 rejectElectronProfile(program, profile) {
36
+ if (profile.toLowerCase() === "desktop") program.error("error: profile \"desktop\" is managed exclusively by the Electron application");
37
+ }
38
+ /** The launcher's own help text; each app prints its own. */
39
+ const HELP_EXAMPLES = `
40
+ Examples:
41
+ dsh web boot the web profile (same as: dsh --profile web)
42
+ dsh rescue --from-default-profile web
43
+ create rescue from the shipped web template, then boot it
44
+ dsh headless "run the tests" answer one task, print the result, and exit
45
+ dsh tui --patch ./extra.yml boot a custom profile with one extra overlay
46
+ dsh tui --resume <session> arguments after the launcher flags reach the app
47
+ dsh web --help the web app's own flags and help
48
+ dsh plugin --profile tui add <package> install a plugin into the tui profile
49
+ `;
50
+ /**
51
+ * Resolve a boot or dump invocation from the launcher flags and the leftover
52
+ * inner arguments.
53
+ * @param program - the command whose options were parsed.
54
+ * @param profile - the profile these flags boot.
55
+ * @param options - the launcher flags commander collected.
56
+ * @param args - the leftover arguments, in argv order.
57
+ * @returns the resolved invocation.
58
+ */
59
+ function resolveBoot(program, profile, options, args) {
60
+ const patches = options.patch ?? [];
61
+ if (patches.includes("")) program.error("error: --patch needs a path");
62
+ if (options.fromDefaultProfile === "") program.error("error: --from-default-profile needs a name");
63
+ const dumps = [
64
+ options.dumpConfig,
65
+ options.dumpDefaultConfig,
66
+ options.dumpConfigSchema
67
+ ].filter(Boolean);
68
+ if (dumps.length === 0) return {
69
+ mode: "profile",
70
+ profile,
71
+ fromDefaultProfile: options.fromDefaultProfile,
72
+ patches,
73
+ args
74
+ };
75
+ if (dumps.length > 1) program.error("error: --dump-config, --dump-default-config, and --dump-config-schema are mutually exclusive");
76
+ if (args.length > 0) program.error(`error: config dumps take no app arguments, got ${args.map((argument) => JSON.stringify(argument)).join(" ")}`);
77
+ if (options.dumpConfigSchema === true) return {
78
+ mode: "dump-config-schema",
79
+ profile,
80
+ fromDefaultProfile: options.fromDefaultProfile,
81
+ patches
82
+ };
83
+ const defaultOnly = options.dumpDefaultConfig === true;
84
+ if (defaultOnly && patches.length > 0) program.error("error: --dump-default-config prints the bundle layers and takes no --patch");
85
+ return {
86
+ mode: "dump-config",
87
+ profile,
88
+ fromDefaultProfile: options.fromDefaultProfile,
89
+ defaultOnly,
90
+ patches
91
+ };
92
+ }
93
+ /**
94
+ * Resolve argv into one invocation, or print and exit for help, version, or an
95
+ * error.
96
+ * @param argv - arguments after the Node binary and script.
97
+ * @param version - version string printed by `--version`.
98
+ * @param manageDesktopProfile - permit Desktop's installed carrier to manage its reserved profile's plugins.
99
+ * @returns the resolved invocation.
100
+ */
101
+ function parseDshArgs(argv, version, manageDesktopProfile = false) {
102
+ const first = argv[0];
103
+ let resolved;
104
+ const program = new Command();
105
+ program.name("dsh").version(version, "-V, --version", "output the version number").usage("[--profile] <name> [options] [app-args...]\n dsh plugin --profile <name> <pnpm-args...>").description("dsh: boot a DeepSeek Harness 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: dsh --profile <name> --help)").option("--profile <name>", "the profile under $DSH_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-config-schema", "print JSON Schema for profile entries and patches without mounting").option("--dump-default-config", "print the profile tree without its user layer or --patch overlays and exit").action((args, options) => {
106
+ if (options.profile === void 0) {
107
+ if (args.some((argument) => argument === "-h" || argument === "--help")) program.help();
108
+ program.error("error: --profile <name> is required");
109
+ }
110
+ const profile = options.profile;
111
+ if (profile === "") program.error("error: --profile needs a name");
112
+ rejectElectronProfile(program, profile);
113
+ resolved = resolveBoot(program, profile, options, args);
114
+ });
115
+ if (first === "plugin") {
116
+ const plugin = program.command("plugin").description("manage a profile's plugins by forwarding the remaining arguments to pnpm in the profile directory");
117
+ plugin.requiredOption("--profile <name>", "the profile whose plugins to manage (initialized on first use)", selectProfile).allowUnknownOption().argument("[args...]", "pnpm arguments, forwarded verbatim (add <pkg>, remove <pkg>, why <pkg>, ...)").action((args, options) => {
118
+ if (options.profile === "") program.error("error: --profile needs a name");
119
+ if (!manageDesktopProfile) rejectElectronProfile(plugin, options.profile);
120
+ if (args.length === 0) program.error("error: plugin needs pnpm arguments to forward (e.g. add <package>)");
121
+ resolved = {
122
+ mode: "plugin",
123
+ profile: options.profile.toLowerCase() === "desktop" ? "desktop" : options.profile,
124
+ args
125
+ };
126
+ });
127
+ }
128
+ try {
129
+ const expanded = first !== void 0 && !first.startsWith("-") && first !== "plugin" ? ["--profile", ...argv] : argv;
130
+ program.parse(expanded, { from: "user" });
131
+ } catch (error) {
132
+ return process.exit(error instanceof CommanderError ? error.exitCode : 1);
133
+ }
134
+ /* v8 ignore next -- an action resolves or Commander throws */
135
+ if (resolved === void 0) throw new Error("dsh: no invocation resolved");
136
+ return resolved;
137
+ }
138
+ //#endregion
139
+ //#region lib/types/startup-diagnostics.js
140
+ /** Save original startup diagnostics while keeping the terminal report concise. */
141
+ /** Wait for stderr to finish the write before the failed process exits. */
142
+ function writeStderr(text) {
143
+ return new Promise((resolve, reject) => {
144
+ process.stderr.write(text, (error) => {
145
+ if (error) reject(error);
146
+ else resolve();
147
+ });
148
+ });
149
+ }
150
+ /**
151
+ * Print the startup summary and save a private, uniquely named report under DSH_HOME/logs.
152
+ * Failed writes print the complete report to stderr instead of claiming a saved path.
153
+ * @param error - startup audit failure retaining plugin metadata and original errors.
154
+ * @param context - resolved Harness home, application version, and selected profile.
155
+ * @param write - terminal output sink; awaited before returning, defaults to stderr.
156
+ * @returns after saving or printing the report and completing terminal writes.
157
+ */
158
+ async function reportStartupFailure(error, context, write = writeStderr) {
159
+ const now = (/* @__PURE__ */ new Date()).toISOString();
160
+ const report = "WARNING: Raw diagnostics may contain configuration or credential values from plugin errors. Review before sharing.\n\n" + inspect({
161
+ timestamp: now,
162
+ dshVersion: context.version,
163
+ nodeVersion: process.version,
164
+ platform: process.platform,
165
+ arch: process.arch,
166
+ profile: context.profile,
167
+ error
168
+ }, {
169
+ depth: null,
170
+ maxArrayLength: null,
171
+ maxStringLength: null,
172
+ showHidden: true,
173
+ customInspect: false,
174
+ getters: false,
175
+ colors: false
176
+ }) + "\n";
177
+ await write(`${error.message}\n`);
178
+ const logDir = join(context.home, "logs");
179
+ const logPath = join(logDir, `startup-${now.replaceAll(":", "-")}-${randomUUID()}.log`);
180
+ try {
181
+ await mkdir(logDir, {
182
+ recursive: true,
183
+ mode: 448
184
+ });
185
+ await writeFile(logPath, report, {
186
+ flag: "wx",
187
+ mode: 384
188
+ });
189
+ } catch (writeError) {
190
+ await write(`\ndsh: warning: could not write startup diagnostics: ${String(writeError)}\nFull diagnostics:\n${report}`);
191
+ return;
192
+ }
193
+ await write(`\nFull diagnostics: ${logPath}\n`);
194
+ }
195
+ //#endregion
196
+ //#region lib/types/bin.js
197
+ /**
198
+ * Command-line entry for dsh.
199
+ * @module @deepseek-ai/dsh/bin
200
+ */
201
+ /* v8 ignore file -- built-bin acceptance exercises this self-executing dispatch. */
202
+ /**
203
+ * Run the public dsh command-line interface.
204
+ * @param options - Package runtime and Desktop profile access supplied by the installation.
205
+ * @returns a promise that settles when the selected command mode finishes.
206
+ */
207
+ async function runCli(options = {}) {
208
+ const version = getDshRuntimeVersion();
209
+ const { manageDesktopProfile, ...profileOptions } = options;
210
+ const invocation = parseDshArgs(process.argv.slice(2), version, manageDesktopProfile);
211
+ switch (invocation.mode) {
212
+ case "profile": {
213
+ const { runProfile } = await import("./profile-boot.js");
214
+ try {
215
+ await runProfile({
216
+ environment: loadLayeredEnv("dsh"),
217
+ profile: invocation.profile,
218
+ fromDefaultProfile: invocation.fromDefaultProfile,
219
+ patchFiles: invocation.patches,
220
+ args: invocation.args,
221
+ ...profileOptions
222
+ });
223
+ } catch (error) {
224
+ if (!(error instanceof StartupError)) throw error;
225
+ await reportStartupFailure(error, {
226
+ home: resolveDshHome(),
227
+ version,
228
+ profile: invocation.profile
229
+ });
230
+ process.exit(1);
231
+ }
232
+ break;
233
+ }
234
+ case "plugin": {
235
+ const { runPlugin } = await import("./plugin-BGnVfe_D.js");
236
+ process.exit(await runPlugin(invocation.profile, invocation.args, options.packageManager));
237
+ break;
238
+ }
239
+ case "dump-config": {
240
+ const { runDumpConfig } = await import("./dump-config-crgOY3tW.js");
241
+ runDumpConfig(invocation.profile, invocation.defaultOnly, invocation.patches, invocation.fromDefaultProfile);
242
+ break;
243
+ }
244
+ case "dump-config-schema": {
245
+ const { runDumpConfigSchema } = await import("./dump-config-schema-DhhNOaro.js");
246
+ await runDumpConfigSchema(invocation.profile, invocation.patches, invocation.fromDefaultProfile);
247
+ break;
248
+ }
249
+ default: throw new Error(`dsh: unhandled invocation mode ${JSON.stringify(invocation)}`);
250
+ }
251
+ }
252
+ if (import.meta.main) await runCli();
253
+ //#endregion
254
+ export { runCli };
@@ -0,0 +1,64 @@
1
+ import { a as prepareProfile, n as PROFILE_ROOT_FILENAME, r as homePatchPath } from "./profile-boot-BZ2ZjNWi.js";
2
+ import { loadOptionalPatches, loadOverlayPatches, renderConfigDump } from "@deepseek-ai/dsh-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 `dsh --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 @deepseek-ai/dsh/dump-config
12
+ */
13
+ const NAME = "dsh";
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 = collectConfigDumpLayers(loaded, defaultOnly, patches);
27
+ process.stdout.write(renderConfigDump(NAME, join(loaded.dir, PROFILE_ROOT_FILENAME), layers));
28
+ }
29
+ /**
30
+ * Read dump layers in bundle, profile, home, then argv order without composing them.
31
+ * @param loaded - prepared profile and parsed bundle and profile patches.
32
+ * @param defaultOnly - omit profile, home, and argv layers without reading their files.
33
+ * @param patches - overlay paths relative to the invoking directory, in argv order.
34
+ * @returns the labeled layers shared by YAML and schema dumps.
35
+ */
36
+ function collectConfigDumpLayers(loaded, defaultOnly, patches) {
37
+ const layers = loaded.layers.map((layer) => ({
38
+ label: layer.packageName,
39
+ patches: layer.patches
40
+ }));
41
+ if (!defaultOnly) {
42
+ if (existsSync(loaded.patchPath)) layers.push({
43
+ label: loaded.patchPath,
44
+ patches: loaded.patches
45
+ });
46
+ const homePatchFile = homePatchPath();
47
+ const homePatches = loadOptionalPatches(NAME, homePatchFile);
48
+ if (homePatches !== void 0) layers.push({
49
+ label: homePatchFile,
50
+ patches: homePatches
51
+ });
52
+ for (const file of patches) {
53
+ const absolute = resolve(file);
54
+ layers.push({
55
+ label: absolute,
56
+ patches: loadOverlayPatches(NAME, absolute)
57
+ });
58
+ }
59
+ }
60
+ return layers;
61
+ }
62
+ /* v8 ignore stop */
63
+ //#endregion
64
+ export { runDumpConfig as n, collectConfigDumpLayers as t };
@@ -0,0 +1,2 @@
1
+ import { n as runDumpConfig } from "./dump-config-BEDI-dNY.js";
2
+ export { runDumpConfig };
@@ -0,0 +1,41 @@
1
+ import { a as prepareProfile, t as INSTALL_ANCHOR } from "./profile-boot-BZ2ZjNWi.js";
2
+ import { t as collectConfigDumpLayers } from "./dump-config-BEDI-dNY.js";
3
+ import { generateConfigSchema } from "@deepseek-ai/dsh-app-boot";
4
+ //#region lib/types/dump-config-schema.js
5
+ /**
6
+ * Schema-dump entry: inspect the composed profile without applying its plugins.
7
+ * Imports and lazy schema builders execute trusted module code.
8
+ * @module @deepseek-ai/dsh/dump-config-schema
9
+ */
10
+ /* v8 ignore file -- built-bin acceptance drives schema collection and output. */
11
+ const NAME = "dsh";
12
+ /**
13
+ * Print one JSON Schema document; incomplete collection or projection sets exitCode to 1.
14
+ * Profile initialization writes match the YAML dump. Plugin imports may execute
15
+ * top-level code, but collection never applies plugins or evaluates `!!js`.
16
+ * During schema generation, ordinary stdout writes are redirected to stderr.
17
+ * @param profile - the profile name.
18
+ * @param patches - overlay paths, in argv order.
19
+ * @param fromDefaultProfile - shipped template used once to initialize a missing profile.
20
+ * @returns after collection and output, with diagnostics also written to stderr.
21
+ */
22
+ async function runDumpConfigSchema(profile, patches, fromDefaultProfile) {
23
+ const loaded = prepareProfile(profile, true, fromDefaultProfile);
24
+ const layers = collectConfigDumpLayers(loaded, false, patches);
25
+ const stdoutWrite = process.stdout.write;
26
+ let dump;
27
+ process.stdout.write = process.stderr.write.bind(process.stderr);
28
+ try {
29
+ dump = await generateConfigSchema(loaded, layers.map((layer) => layer.patches), INSTALL_ANCHOR);
30
+ } finally {
31
+ process.stdout.write = stdoutWrite;
32
+ }
33
+ process.stdout.write(`${JSON.stringify(dump, null, 2)}\n`);
34
+ for (const diagnostic of dump["x-cordis"].diagnostics) {
35
+ const location = diagnostic.path === void 0 ? "" : ` [${diagnostic.path}]`;
36
+ process.stderr.write(`${NAME}: ${diagnostic.level}:${location} ${diagnostic.message}\n`);
37
+ }
38
+ if (!dump["x-cordis"].complete) process.exitCode = 1;
39
+ }
40
+ //#endregion
41
+ export { runDumpConfigSchema };
@@ -0,0 +1,101 @@
1
+ import { t as INSTALL_ANCHOR } from "./profile-boot-BZ2ZjNWi.js";
2
+ import { DEFAULT_PROFILE_BUNDLES, PROFILE_TEMPLATES, initProfile, readProfileCompatibility, resolveProfileDir } from "@deepseek-ai/dsh-app-boot";
3
+ import { mkdir } from "node:fs/promises";
4
+ import { join } from "node:path";
5
+ import { existsSync } from "node:fs";
6
+ import { runPluginCommand, runProfilePnpm, setProfileVersionExemption } from "@deepseek-ai/dsh-plugin-manager/operations";
7
+ import { withFileLock } from "@deepseek-ai/dsh-atomic-write";
8
+ //#region lib/types/plugin.js
9
+ /** Profile package management and explicit, exact-version compatibility approvals. */
10
+ function requireDesktopProfile(dir) {
11
+ if (!existsSync(join(dir, "package.json"))) throw new Error("Open DeepSeek Harness Desktop once to initialize its profile, then fully quit it before running dsh plugin --profile desktop.");
12
+ }
13
+ /** Parse only DSH-owned commands; all other arguments remain pnpm's responsibility. */
14
+ async function versionCommand(profile, args) {
15
+ const [command, ...rest] = args;
16
+ if (command !== "allow-version" && command !== "revoke-version" && command !== "version-exemptions") return void 0;
17
+ try {
18
+ let packageVersion;
19
+ let runtimeVersion;
20
+ let acceptRisk = false;
21
+ const argumentsIterator = rest.values();
22
+ for (const argument of argumentsIterator) if (argument === "--accept-risk" && command === "allow-version" && !acceptRisk) acceptRisk = true;
23
+ else if (argument === "--dsh-version" && runtimeVersion === void 0) runtimeVersion = argumentsIterator.next().value;
24
+ else if (argument.startsWith("--dsh-version=") && runtimeVersion === void 0) runtimeVersion = argument.slice(14);
25
+ else if (!argument.startsWith("-") && packageVersion === void 0) packageVersion = argument;
26
+ else throw new Error(`unexpected argument ${JSON.stringify(argument)}`);
27
+ if (command === "version-exemptions" && rest.length > 0) throw new Error("usage: dsh plugin version-exemptions");
28
+ let request;
29
+ if (command !== "version-exemptions") {
30
+ if (packageVersion === void 0 || runtimeVersion === void 0) throw new Error(`usage: dsh plugin ${command} <package@version> --dsh-version <exact>${command === "allow-version" ? " --accept-risk" : ""}`);
31
+ request = {
32
+ packageVersion,
33
+ runtimeVersion
34
+ };
35
+ }
36
+ if (command === "allow-version") process.stderr.write("dsh: warning: allowing incompatible plugin versions can break the application or corrupt data. Approval applies only to the exact package and DSH versions.\n");
37
+ const dir = resolveProfileDir(profile);
38
+ if (profile !== "desktop") await mkdir(dir, { recursive: true });
39
+ await withFileLock(join(dir, "package.json"), async () => {
40
+ if (profile === "desktop") requireDesktopProfile(dir);
41
+ else if (!existsSync(join(dir, "package.json"))) initProfile(dir, PROFILE_TEMPLATES[profile]?.bundles ?? DEFAULT_PROFILE_BUNDLES);
42
+ if (request === void 0) {
43
+ const { exemptions, warnings } = readProfileCompatibility(dir);
44
+ for (const warning of warnings) process.stderr.write(`dsh: warning: ${warning}\n`);
45
+ process.stdout.write(JSON.stringify(exemptions, void 0, 2) + "\n");
46
+ } else {
47
+ await setProfileVersionExemption(dir, request.packageVersion, request.runtimeVersion, command === "allow-version", acceptRisk);
48
+ process.stdout.write(`dsh: ${command === "allow-version" ? "allowed" : "revoked"} ${request.packageVersion} for DSH ${request.runtimeVersion}\n`);
49
+ }
50
+ }, { waitMs: 12e4 });
51
+ return 0;
52
+ } catch (error) {
53
+ process.stderr.write(`dsh: ${String(error)}\n`);
54
+ return 1;
55
+ }
56
+ }
57
+ /** Run package management for a profile.
58
+ * @param profile Profile name; Desktop's reserved profile must already be initialized by the application.
59
+ * @param args DSH exemption command or pnpm arguments relative to the invoking directory.
60
+ * @param packageManager Installation-owned executable and environment for pnpm operations.
61
+ * @returns Zero on success; nonzero on invalid approval or package-manager failure.
62
+ */
63
+ async function runPlugin(profile, args, packageManager) {
64
+ if (profile === "desktop") try {
65
+ requireDesktopProfile(resolveProfileDir(profile));
66
+ } catch (error) {
67
+ process.stderr.write(`dsh: ${String(error)}\n`);
68
+ return 1;
69
+ }
70
+ const versionResult = await versionCommand(profile, args);
71
+ if (versionResult !== void 0) return versionResult;
72
+ const dir = resolveProfileDir(profile);
73
+ if (existsSync(join(dir, "package.json"))) for (const warning of readProfileCompatibility(dir).warnings) process.stderr.write(`dsh: warning: ${warning}\n`);
74
+ const context = {
75
+ profile,
76
+ dir,
77
+ installAnchor: INSTALL_ANCHOR,
78
+ cwd: process.cwd()
79
+ };
80
+ const options = {
81
+ ...packageManager,
82
+ execution: "cli",
83
+ outputBytes: 16384,
84
+ lockWaitMs: 12e4,
85
+ lookupTimeoutMs: 12e4,
86
+ onOutput: (text, stream) => {
87
+ process[stream].write(text);
88
+ }
89
+ };
90
+ const result = profile === "desktop" ? await withFileLock(join(dir, "package.json"), async () => {
91
+ requireDesktopProfile(dir);
92
+ return runProfilePnpm(context, args, options);
93
+ }, { waitMs: 12e4 }) : await runPluginCommand(context, args, options);
94
+ if (result.exitCode === 127) process.stderr.write("dsh: pnpm was not found; install pnpm and make it available on PATH.\n");
95
+ for (const { name, version, runtimeVersion } of result.incompatible ?? []) process.stderr.write(`dsh: to accept the risk, run: dsh plugin --profile ${profile} allow-version ${name}@${version} --dsh-version ${runtimeVersion} --accept-risk\n`);
96
+ if (result.exitCode !== 0) process.stderr.write(`dsh: plugin command failed; diagnostics: ${result.logPath}\n`);
97
+ if (result.exitCode !== 0 && args.some((argument) => /^git\+|^github:|\.git(?:#|$)/.test(argument))) process.stderr.write(`dsh: git-hosted plugins build on install via their prepare script, which pnpm blocks until allowed — add the exact key pnpm printed above under allowBuilds in ${join(resolveProfileDir(profile), "pnpm-workspace.yaml")}, then re-run\n`);
98
+ return result.exitCode;
99
+ }
100
+ //#endregion
101
+ export { runPlugin };