@fishwithcat/dsh 0.0.0-stage → 0.2.2-alpha.3.fork.1

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.
@@ -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: 5745e2e516fbfa8b
10
+ zh: e40f2324536bad90
11
+ /deepseek-ai-dsh/app-arguments:
12
+ en: cc03e6b75206661b
13
+ zh: 99e41f4143198352
14
+ /deepseek-ai-dsh/profiles:
15
+ en: 523477a093beb0c2
16
+ zh: f88ea21e5fbea969
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,68 @@
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>` | Replace a custom profile with a fresh copy of 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 watch <session-id>` | Watch a local subagent read-only in another terminal; see [TUI watching](../../packages/bundle/tui-app/README.md). |
19
+ | `dsh plugin --profile <name> <pnpm args>` | Manage a profile's plugins by forwarding to pnpm in the profile directory. |
20
+
21
+ `watch` and `plugin` are reserved subcommands; use `--profile watch` or `--profile plugin` to boot profiles with those names.
22
+
23
+ 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 or reset another profile at a 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.
24
+
25
+ ## App arguments
26
+
27
+ 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:
28
+
29
+ ```sh
30
+ dsh --profile web --port 8080 # --port belongs to the web app
31
+ dsh --profile tui --resume <id> # example, assuming the tui profile is installed; --resume belongs to the terminal app
32
+ dsh --profile tui --watch <id> # view a local subagent read-only; --watch belongs to the terminal app
33
+ dsh --profile headless "run the tests"
34
+ dsh --profile web --help # the web app's flags, not the launcher's
35
+ dsh --help # the launcher's own help
36
+ ```
37
+
38
+ <a id="profiles"></a>
39
+ ## Profiles
40
+
41
+ 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.
42
+
43
+ Installation and profile startup enforce the declared `engines.dsh` range, or DSH peer ranges when it is absent, 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.
44
+
45
+ The tree composes over an empty root:
46
+ - each bundle's patch in `dsh.profile.bundles` order
47
+ - then the profile's `cordis.patch.yml`, then the home-level `$DSH_HOME/cordis.patch.yml`
48
+ - then `--patch` overlays
49
+
50
+ 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.
51
+
52
+ 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.
53
+
54
+ 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.
55
+
56
+ ## Optional overlays
57
+
58
+ `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.
59
+
60
+ ## Development
61
+
62
+ 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.
63
+
64
+ 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.
65
+
66
+ 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.
67
+
68
+ 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,68 @@
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 watch <session-id>` | 在另一个终端只读查看本地子 agent;参见 [TUI 查看说明](../../packages/bundle/tui-app/README.zh.md)。 |
19
+ | `dsh plugin --profile <name> <pnpm args>` | 通过在 profile 目录中转发给 pnpm 来管理该 profile 的插件。 |
20
+
21
+ `watch` 和 `plugin` 是保留子命令;启动同名 profile 时使用 `--profile watch` 或 `--profile plugin`。
22
+
23
+ 运行命令时所在的目录将作为默认 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。
24
+
25
+ ## 应用参数
26
+
27
+ 启动器只解析自身的 flag,并将其后的所有内容交给已启动的 profile;注入该 profile 的任意应用插件都可以解析这份共享的不可变快照([`dsh-cmdline`](../../packages/boot/cmdline/README.zh.md))。启动器无法识别的第一个 token 标志着应用参数的开始:
28
+
29
+ ```sh
30
+ dsh --profile web --port 8080 # --port belongs to the web app
31
+ dsh --profile tui --resume <id> # example, assuming the tui profile is installed; --resume belongs to the terminal app
32
+ dsh --profile tui --watch <id> # view a local subagent read-only; --watch belongs to the terminal app
33
+ dsh --profile headless "run the tests"
34
+ dsh --profile web --help # the web app's flags, not the launcher's
35
+ dsh --help # the launcher's own help
36
+ ```
37
+
38
+ <a id="profiles"></a>
39
+ ## Profile
40
+
41
+ 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 调用保留清理后的环境并捕获诊断。
42
+
43
+ 安装和 profile 启动会按声明的 `engines.dsh` 范围(未声明时按 DSH peer 范围),检查与 `dsh --version` 显示值相同的运行时版本。不兼容插件需要用户明确确认精确版本豁免。[插件管理器的兼容性参考](../../packages/boot/plugin-manager/README.zh.md#version-compatibility-and-exemptions)说明 `version-exemptions`、`allow-version`、`revoke-version`、持久化规则与风险。
44
+
45
+ 配置树以空根为起点,依次叠加以下配置层:
46
+ - `dsh.profile.bundles` 中各组合包的 patch
47
+ - profile 自身的 `cordis.patch.yml`,然后是 home 级的 `$DSH_HOME/cordis.patch.yml`
48
+ - `--patch` 指定的覆盖层
49
+
50
+ `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 会将树外插件安装到该目录。
51
+
52
+ 使用 `--dump-default-config` 和 `--dump-config` 可在不启动的情况下检查组合后的配置树。`--dump-config-schema` 会导入组合树中插件声明的 schema,并打印描述 entry 与 patch 的 JSON Schema,而不是配置值;检查不受信任的插件前,请阅读 [schema dump 的安全性与范围](reference/README.zh.md#config-schema-dump)。
53
+
54
+ 层的确切优先级、flag、关闭行为、部署默认值和源码执行方式,以 [CLI 行为参考](reference/README.zh.md)为准。[启动与重载失败表](../../packages/boot/app-boot/README.zh.md#startup-and-reload-failures)对比 optional、required 插件启动失败与配置 HMR 的行为。
55
+
56
+ ## 可选覆盖层
57
+
58
+ `config/examples/` 交付 GitHub 评审 webhook、记忆 MCP 服务器与运行时 Cordis 工具的可选覆盖层。它们绝不属于默认 profile;设置与安全说明由[用户指南](../../docs/user/guide/index.zh.md)和[开发实战指南](../../docs/user/develop/practice/index.zh.md)负责。
59
+
60
+ ## 开发
61
+
62
+ 生产运行需要已构建的包与前端产物。请在仓库根目录单独运行 `pnpm run build`,然后使用 `pnpm dsh <args...>` 运行 TypeScript 入口并转发所有参数;模块解析约定以[源码执行参考](reference/README.zh.md#source-execution)为准。
63
+
64
+ `@deepseek-ai/dsh/profile-boot` 导出向 Desktop Host 提供共享 profile 生命周期。已解析的应用 profile 为运行时包解析指定自己的安装锚点,同时沿用 Harness home patch、代理环境、遥测开关、patch 热重载和有界关闭。
65
+
66
+ 打包安装通过同一个 `runCli()` 入口传入包管理器可执行文件。Desktop 载体还会启用其已初始化 profile 的插件操作;npm 启动不传入这些选项。安装包提供的包管理环境仅用于插件包操作;调用目录、普通 profile 选择与 agent shell 的 PATH 保留 CLI 语义。
67
+
68
+ [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 的必需依赖与端口冲突。
@@ -0,0 +1,270 @@
1
+ import { join } from "node:path";
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 { inspect } from "node:util";
8
+ //#region lib/types/args.js
9
+ /**
10
+ * Commander adapter for the `dsh` command line.
11
+ *
12
+ * The launcher parses only what it owns — which profile to boot, which extra
13
+ * patch overlays to apply, and the config dumps — and hands **everything after
14
+ * its own flags** to the booted tree verbatim, where injected app plugins parse
15
+ * their own flag families and print their own `--help` (see
16
+ * `@deepseek-ai/dsh-cmdline`). Launcher flags therefore come first: the first
17
+ * token this parser does not recognize starts the inner arguments, so
18
+ * `dsh --profile tui --resume abc` boots the tui profile with `--resume abc`,
19
+ * and `dsh --profile web -h` prints the web app's help, not this one's.
20
+ *
21
+ * `dsh <name>` abbreviates `dsh --profile <name>`; `plugin` manages a profile's
22
+ * plugin dependencies by forwarding to pnpm; `watch` opens the TUI's read-only viewer.
23
+ * @module @deepseek-ai/dsh/args
24
+ */
25
+ /** Environment variable that overrides which profile a bare `dsh` boots. */
26
+ const DEFAULT_PROFILE_ENV = "DSH_DEFAULT_PROFILE";
27
+ /**
28
+ * Profile a bare `dsh` boots when the invocation names none. This fork defaults
29
+ * to its terminal UI; name another shipped profile through
30
+ * {@link DEFAULT_PROFILE_ENV} to change the default, or set that variable empty
31
+ * to require `--profile` as upstream does.
32
+ */
33
+ const DEFAULT_PROFILE = "tui";
34
+ /**
35
+ * Repeatable single-value collector: `--patch a.yml --patch b.yml`. Never
36
+ * variadic — a variadic `--patch` would swallow the inner arguments.
37
+ */
38
+ const collect = (value, previous = []) => [...previous, value];
39
+ function selectProfile(value, previous) {
40
+ if (previous !== void 0) throw new InvalidArgumentError("select a profile only once");
41
+ return value;
42
+ }
43
+ function rejectElectronProfile(program, profile) {
44
+ if (profile.toLowerCase() === "desktop") program.error("error: profile \"desktop\" is managed exclusively by the Electron application");
45
+ }
46
+ /** The launcher's own help text; each app prints its own. */
47
+ const HELP_EXAMPLES = `
48
+ Examples:
49
+ dsh boot the default terminal UI profile (same as: dsh --profile tui)
50
+ dsh web boot the web profile (same as: dsh --profile web)
51
+ dsh rescue --from-default-profile web
52
+ recreate rescue from the shipped web template, then boot it
53
+ dsh headless "run the tests" answer one task, print the result, and exit
54
+ dsh tui --patch ./extra.yml boot a custom profile with one extra overlay
55
+ dsh tui --resume <session> arguments after the launcher flags reach the app
56
+ dsh watch <session> watch a local subagent read-only from another terminal
57
+ dsh web --help the web app's own flags and help
58
+ dsh plugin --profile tui add <package> install a plugin into the tui profile
59
+ `;
60
+ /**
61
+ * Resolve a boot or dump invocation from the launcher flags and the leftover
62
+ * inner arguments.
63
+ * @param program - the command whose options were parsed.
64
+ * @param profile - the profile these flags boot.
65
+ * @param options - the launcher flags commander collected.
66
+ * @param args - the leftover arguments, in argv order.
67
+ * @returns the resolved invocation.
68
+ */
69
+ function resolveBoot(program, profile, options, args) {
70
+ const patches = options.patch ?? [];
71
+ if (patches.includes("")) program.error("error: --patch needs a path");
72
+ if (options.fromDefaultProfile === "") program.error("error: --from-default-profile needs a name");
73
+ const dumps = [
74
+ options.dumpConfig,
75
+ options.dumpDefaultConfig,
76
+ options.dumpConfigSchema
77
+ ].filter(Boolean);
78
+ if (dumps.length === 0) return {
79
+ mode: "profile",
80
+ profile,
81
+ fromDefaultProfile: options.fromDefaultProfile,
82
+ patches,
83
+ args
84
+ };
85
+ if (dumps.length > 1) program.error("error: --dump-config, --dump-default-config, and --dump-config-schema are mutually exclusive");
86
+ if (args.length > 0) program.error(`error: config dumps take no app arguments, got ${args.map((argument) => JSON.stringify(argument)).join(" ")}`);
87
+ if (options.dumpConfigSchema === true) return {
88
+ mode: "dump-config-schema",
89
+ profile,
90
+ fromDefaultProfile: options.fromDefaultProfile,
91
+ patches
92
+ };
93
+ const defaultOnly = options.dumpDefaultConfig === true;
94
+ if (defaultOnly && patches.length > 0) program.error("error: --dump-default-config prints the bundle layers and takes no --patch");
95
+ return {
96
+ mode: "dump-config",
97
+ profile,
98
+ fromDefaultProfile: options.fromDefaultProfile,
99
+ defaultOnly,
100
+ patches
101
+ };
102
+ }
103
+ /**
104
+ * Resolve argv into one invocation, or print and exit for help, version, or an
105
+ * error.
106
+ * @param argv - arguments after the Node binary and script.
107
+ * @param version - version string printed by `--version`.
108
+ * @param manageDesktopProfile - permit Desktop's installed carrier to manage its reserved profile's plugins.
109
+ * @returns the resolved invocation.
110
+ */
111
+ function parseDshArgs(argv, version, manageDesktopProfile = false) {
112
+ const first = argv[0];
113
+ let resolved;
114
+ const program = new Command();
115
+ 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>", "replace a custom profile with a fresh copy of 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) => {
116
+ if (options.profile === void 0 && args.some((argument) => argument === "-h" || argument === "--help")) program.help();
117
+ if (options.profile === "") program.error("error: --profile needs a name");
118
+ const profile = options.profile ?? process.env[DEFAULT_PROFILE_ENV] ?? DEFAULT_PROFILE;
119
+ if (profile === "") program.error("error: --profile <name> is required");
120
+ rejectElectronProfile(program, profile);
121
+ resolved = resolveBoot(program, profile, options, args);
122
+ });
123
+ if (first === "plugin") {
124
+ const plugin = program.command("plugin").description("manage a profile's plugins by forwarding the remaining arguments to pnpm in the profile directory");
125
+ plugin.helpOption("-h, --help", "show this help").passThroughOptions().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) => {
126
+ if (options.profile === "") program.error("error: --profile needs a name");
127
+ if (!manageDesktopProfile) rejectElectronProfile(plugin, options.profile);
128
+ if (args.length === 0) program.error("error: plugin needs pnpm arguments to forward (e.g. add <package>)");
129
+ resolved = {
130
+ mode: "plugin",
131
+ profile: options.profile.toLowerCase() === "desktop" ? "desktop" : options.profile,
132
+ args
133
+ };
134
+ });
135
+ }
136
+ if (first === "watch") {
137
+ const watch = program.command("watch").description("watch a local subagent session read-only in the terminal");
138
+ watch.helpOption("-h, --help", "show this help").argument("<session-id>", "the local subagent session to watch").option("--patch <path>", "extra patch-list overlay for the tui profile (repeatable)", collect).action((sessionId, options) => {
139
+ if (sessionId === "") watch.error("error: watch needs a session id");
140
+ if (program.opts().profile !== void 0) watch.error("error: watch uses the tui profile; do not pass --profile");
141
+ resolved = resolveBoot(watch, "tui", options, ["--watch", sessionId]);
142
+ });
143
+ }
144
+ try {
145
+ const expanded = first !== void 0 && !first.startsWith("-") && first !== "plugin" && first !== "watch" ? ["--profile", ...argv] : argv;
146
+ program.parse(expanded, { from: "user" });
147
+ } catch (error) {
148
+ return process.exit(error instanceof CommanderError ? error.exitCode : 1);
149
+ }
150
+ /* v8 ignore next -- an action resolves or Commander throws */
151
+ if (resolved === void 0) throw new Error("dsh: no invocation resolved");
152
+ return resolved;
153
+ }
154
+ //#endregion
155
+ //#region lib/types/startup-diagnostics.js
156
+ /** Save original startup diagnostics while keeping the terminal report concise. */
157
+ /** Wait for stderr to finish the write before the failed process exits. */
158
+ function writeStderr(text) {
159
+ return new Promise((resolve, reject) => {
160
+ process.stderr.write(text, (error) => {
161
+ if (error) reject(error);
162
+ else resolve();
163
+ });
164
+ });
165
+ }
166
+ /**
167
+ * Print the startup summary and save a private, uniquely named report under DSH_HOME/logs.
168
+ * Failed writes print the complete report to stderr instead of claiming a saved path.
169
+ * @param error - startup audit failure retaining plugin metadata and original errors.
170
+ * @param context - resolved Harness home, application version, and selected profile.
171
+ * @param write - terminal output sink; awaited before returning, defaults to stderr.
172
+ * @returns after saving or printing the report and completing terminal writes.
173
+ */
174
+ async function reportStartupFailure(error, context, write = writeStderr) {
175
+ const now = (/* @__PURE__ */ new Date()).toISOString();
176
+ const report = "WARNING: Raw diagnostics may contain configuration or credential values from plugin errors. Review before sharing.\n\n" + inspect({
177
+ timestamp: now,
178
+ dshVersion: context.version,
179
+ nodeVersion: process.version,
180
+ platform: process.platform,
181
+ arch: process.arch,
182
+ profile: context.profile,
183
+ error
184
+ }, {
185
+ depth: null,
186
+ maxArrayLength: null,
187
+ maxStringLength: null,
188
+ showHidden: true,
189
+ customInspect: false,
190
+ getters: false,
191
+ colors: false
192
+ }) + "\n";
193
+ await write(`${error.message}\n`);
194
+ const logDir = join(context.home, "logs");
195
+ const logPath = join(logDir, `startup-${now.replaceAll(":", "-")}-${randomUUID()}.log`);
196
+ try {
197
+ await mkdir(logDir, {
198
+ recursive: true,
199
+ mode: 448
200
+ });
201
+ await writeFile(logPath, report, {
202
+ flag: "wx",
203
+ mode: 384
204
+ });
205
+ } catch (writeError) {
206
+ await write(`\ndsh: warning: could not write startup diagnostics: ${String(writeError)}\nFull diagnostics:\n${report}`);
207
+ return;
208
+ }
209
+ await write(`\nFull diagnostics: ${logPath}\n`);
210
+ }
211
+ //#endregion
212
+ //#region lib/types/bin.js
213
+ /**
214
+ * Command-line entry for dsh.
215
+ * @module @deepseek-ai/dsh/bin
216
+ */
217
+ /* v8 ignore file -- built-bin acceptance exercises this self-executing dispatch. */
218
+ /**
219
+ * Run the public dsh command-line interface.
220
+ * @param options - Package runtime and Desktop profile access supplied by the installation.
221
+ * @returns a promise that settles when the selected command mode finishes.
222
+ */
223
+ async function runCli(options = {}) {
224
+ const version = getDshRuntimeVersion();
225
+ const { manageDesktopProfile, ...profileOptions } = options;
226
+ const invocation = parseDshArgs(process.argv.slice(2), version, manageDesktopProfile);
227
+ switch (invocation.mode) {
228
+ case "profile": {
229
+ const { runProfile } = await import("./profile-boot.js");
230
+ try {
231
+ await runProfile({
232
+ environment: loadLayeredEnv("dsh"),
233
+ profile: invocation.profile,
234
+ fromDefaultProfile: invocation.fromDefaultProfile,
235
+ patchFiles: invocation.patches,
236
+ args: invocation.args,
237
+ ...profileOptions
238
+ });
239
+ } catch (error) {
240
+ if (!(error instanceof StartupError)) throw error;
241
+ await reportStartupFailure(error, {
242
+ home: resolveDshHome(),
243
+ version,
244
+ profile: invocation.profile
245
+ });
246
+ process.exit(1);
247
+ }
248
+ break;
249
+ }
250
+ case "plugin": {
251
+ const { runPlugin } = await import("./plugin-cQMw2oZz.js");
252
+ process.exit(await runPlugin(invocation.profile, invocation.args, options.packageManager));
253
+ break;
254
+ }
255
+ case "dump-config": {
256
+ const { runDumpConfig } = await import("./dump-config-ekMiCsuS.js");
257
+ runDumpConfig(invocation.profile, invocation.defaultOnly, invocation.patches, invocation.fromDefaultProfile);
258
+ break;
259
+ }
260
+ case "dump-config-schema": {
261
+ const { runDumpConfigSchema } = await import("./dump-config-schema-C_NhxM7L.js");
262
+ await runDumpConfigSchema(invocation.profile, invocation.patches, invocation.fromDefaultProfile);
263
+ break;
264
+ }
265
+ default: throw new Error(`dsh: unhandled invocation mode ${JSON.stringify(invocation)}`);
266
+ }
267
+ }
268
+ if (import.meta.main) await runCli();
269
+ //#endregion
270
+ export { runCli };
package/lib/bin.js ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ import { realpathSync } from "node:fs";
3
+ import { pathToFileURL } from "node:url";
4
+ //#region lib/types/installed-bin.js
5
+ /**
6
+ * Installed CLI entry for disk launchers and embedded runtimes.
7
+ * @module @deepseek-ai/dsh/installed-bin
8
+ */
9
+ var __rewriteRelativeImportExtension = function(path, preserveJsx) {
10
+ if (typeof path === "string" && /^\.\.?\//.test(path)) return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function(m, tsx, d, ext, cm) {
11
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : d + ext + "." + cm.toLowerCase() + "js";
12
+ });
13
+ return path;
14
+ };
15
+ /**
16
+ * Run the CLI in the importing carrier's module tree.
17
+ * @param options - Installation-owned runtime options.
18
+ * @returns Settlement of the selected command.
19
+ */
20
+ async function runCli(options) {
21
+ await (await import("./bin-CKGHv5ga.js")).runCli(options);
22
+ }
23
+ if (import.meta.main) {
24
+ const entry = process.platform === "win32" ? pathToFileURL(realpathSync.native(import.meta.filename)).href : import.meta.url;
25
+ if (entry === import.meta.url) await runCli();
26
+ else await (await import(__rewriteRelativeImportExtension(entry))).runCli();
27
+ }
28
+ //#endregion
29
+ export { runCli };
@@ -0,0 +1,64 @@
1
+ import { a as prepareProfile, n as PROFILE_ROOT_FILENAME, r as homePatchPath } from "./profile-boot-xiaehH2x.js";
2
+ import { existsSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
4
+ import { loadOptionalPatches, loadOverlayPatches, renderConfigDump } from "@deepseek-ai/dsh-app-boot";
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 that replaces the profile before loading it.
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-DCQrFN8g.js";
2
+ export { runDumpConfig };
@@ -0,0 +1,41 @@
1
+ import { a as prepareProfile, t as INSTALL_ANCHOR } from "./profile-boot-xiaehH2x.js";
2
+ import { t as collectConfigDumpLayers } from "./dump-config-DCQrFN8g.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 that replaces the profile before loading it.
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 };