Files
deepseek-harness/packages/shell/shell-env/README.zh.md
T
Turtle 38c7a9fbf4 feat(release): publish package source, declaration maps, and documentation (#5884)
* feat(release): publish package source, declaration maps, and documentation

Every release member publishes its TypeScript source and the declaration
maps that resolve into it, and @deepseek-ai/dsh publishes the repository
Markdown documentation staged from docs/ at prepack time.

The ./src/* export most members already declared now resolves for an
installed consumer, and a consumer editor follows a declaration to the
implementation. Bundled JavaScript maps stay unpublished; the vendored
family and the Desktop runtime file policy are unchanged.

Rationale: .agents/notes/implemented/process/2026-10-08-published-source-and-docs.md

* feat(release): publish JavaScript maps and compress bundles

Every emitted JavaScript map ships beside the bundle it describes, and the
workspace build and the client preset compress bundles without mangling
identifiers.

The documentation payload now mirrors the website publication manifest and
is removed again by `postpack`; Desktop and the Python executable exclude
the published source, documentation, and maps; `clean` removes a staged
copy. Typert's publication contract gains the Remote declaration map.

* fix(release): keep node bundles readable for the worker image

The browser worker image lowers `yield*` only as a whole statement and
rewrites `for await` loops by their source layout, so compressed node-side
entries either fail that lowering or lower to unparseable code. Only the
browser bundles keep compression, which removes about a third of their text.

The bundle-purity assertion now matches the module-loader call regardless of
the quote style compression picks, and the release-pack fixture exercises
the installed package's new documentation requirement.

* feat(release): publish the whole documentation tree

`@deepseek-ai/dsh` copies `docs/` in full instead of the website's page
set: the maintainer documents, the generated migration records, the
translation guidelines, and the `*.i18n.yaml` consistency records ship
with the installed package, so the documentation's own links resolve
without a checkout.

* feat(release): publish the upgrade guides with the documentation

The staged documentation keeps the website's page set and adds every
`docs/upgrade-guide/` document, which is what an installed reader consults
when a released change breaks something. The rest of the maintainer tree
stays out.

* test(release): expect source and maps in master's new payload cases

* feat(release): keep installed docs and source readable in Desktop

Desktop keeps the published src/ and docs/ trees inside app.asar, and
every model shell call receives DSH_INSTALL_DIR and DSH_NODE_EXECUTABLE
so an agent can read them through Electron's Node mode. Staging also
generates docs/upgrade-guide/README.md, an index of the upgrade guides
grouped by the release they upgrade from.

Minified client bundles print string literals with backticks: the
worker image packer now recognizes those chunk requests, client license
banners are prepended after minification so their text survives, and
the affected artifact tests accept either quote.

* test(desktop): read archived docs through the Windows PowerShell form

Regenerate the config catalog for the shifted shell-env source line.

* test(desktop): wait for the GUI-subsystem Electron process from PowerShell

* build(release): publish source and maps from the message-quotes package

* build(release): publish source and maps from packages new on master

* build(release): publish source and maps from the tool-office package
2026-11-05 00:22:36 +08:00

7.4 KiB
Raw Blame History

description, kind
description kind
受管 DSH_* shell 环境,供选择、配置或扩展每次模型 shell 调用所运行环境的使用者与维护者阅读。 package-reference

@deepseek-ai/dsh-shell-env

English | 中文

概述

dsh-shell-env 提供每次模型 shell 调用——bash 或 pwsh——所运行的受信 DSH_* 环境:内置事实如 DSH_HOME、DSH_SHELL=1、agent(智能体)的 DSH_SESSION_ID,以及所启动 profile 的 DSH_PROFILE 与 DSH_PROFILE_DIR。插件作者可以注册自己的事实,带声明键、按每次执行收集,并随插件释放;重复所有权或未声明的运行时键会明确报错,而不是静默覆盖。注册表不会改变模型看到的其他任何内容——shell 工具拥有各自的 schema 与提示词。任何挂载了模型 shell 工具的组合都适合选择它;配置只决定 Harness 主目录。

目录


使用本包

在任何挂载模型 shell 工具(dsh-tool-bash 或 dsh-tool-pwsh)的组合中加载本插件:此后每次前台或后台 shell 调用都会运行在新收集的受管环境中,而不是进程继承来的任意 DSH_* 值。

每次 shell 调用都会收到什么

每次调用都会收到 DSH_HOME(Harness 主目录的绝对路径)、DSH_SHELL=1,agent 调用还会收到 DSH_SESSION_ID(调用方会话的 id)。不在单可执行文件应用中运行时,每次调用还会收到 DSH_NODE_EXECUTABLE,即运行 Harness 的可执行文件的绝对路径。Desktop 下它是 Electron 可执行文件:只有设置 ELECTRON_RUN_AS_NODE=1 时它才以 Node 方式运行脚本,其 Node 文件 API 能读取普通工具打不开的 app.asar 归档内条目。启动器提供了 profile 上下文时,每次调用还会收到 DSH_PROFILE(profile 名)、DSH_PROFILE_DIR(其绝对目录;其 node_modules 只存放 profile 自行安装的包,harness 自带的组合包从 dsh 安装目录解析)与 DSH_INSTALL_DIR(作为安装锚点的 @deepseek-ai/dsh 包的绝对目录,随包发布的 docs/ 与 src/ 位于其中);不带 profile 启动的组合则三者都没有。

添加你自己的环境事实

其他插件通过注册一个 contributor 来贡献事实,需要提供稳定名称、它可能返回的完整 DSH_* 键集合、每个键的描述,以及为一次执行计算取值的 resolver:

import type { Context } from '@deepseek-ai/cordis'
import type {} from '@deepseek-ai/dsh-shell-env'

export const inject = ['shellEnv']

export function apply(ctx: Context): void {
  ctx.shellEnv.register({
    name: 'deployment-region',
    variables: { DSH_DEPLOYMENT_REGION: { description: 'Current deployment region.' } },
    resolve: execution => execution.agent === undefined ? {} : { DSH_DEPLOYMENT_REGION: 'cn-north' },
  })
}

contributor 必须声明它返回的每个键;返回未声明或非字符串的值会让该次调用失败。注册随注册插件的释放而释放,因此热重载插件会移除它的事实。

选择 Harness 主目录

唯一配置字段决定暴露为 DSH_HOME 的主目录;默认解析顺序为 dshHome 配置、环境变量 $DSH_HOME,然后是 ~/.dsh。

字段 默认值 含义
dshHome $DSH_HOME,然后 ~/.dsh 暴露为 DSH_HOME 的 Harness 主目录绝对路径

生成的配置目录是每个受支持字段及其 JSDoc 的穷尽式真源。

可能出什么问题

两个 contributor 声明同一个键,或 contributor 声称拥有保留内置键(DSH_HOME、DSH_SHELL、DSH_SESSION_ID、DSH_PROFILE、DSH_PROFILE_DIR、DSH_INSTALL_DIR、DSH_NODE_EXECUTABLE),都会导致插件加载时明确报错。DSH_* 键必须全大写并带下划线(例如 DSH_REGION),缺少描述也会让注册失败。


理解实现

实现细节——点击展开

本节解释注册表背后的设计决策,并指出实现它们的代码位置;可观察行为已在使用本包中完整说明。

设计理念

  • 受信命名空间,每次调用重建。 环境是归 Harness 所有的 DSH_* 命名空间:shell 执行器丢弃继承的 DSH_* 值,并为每次执行合并注册表的当前快照,因此嵌套 harness 与并发的父子 agent 无法泄漏陈旧身份,process.env 也永不被修改。
  • 声明所有权,冲突明确报错。 contributor 预先声明键,使重复所有权在第一条命令之前就被发现;resolver 只能返回已声明的键。
  • 内置键留在这里。 DSH_HOME、DSH_SHELL、DSH_SESSION_ID、DSH_PROFILE、DSH_PROFILE_DIR、DSH_INSTALL_DIR 与 DSH_NODE_EXECUTABLE 为注册表保留;contributor 不能声称拥有它们。

源码地图

文件 职责
src/index.ts 插件入口、ShellEnvRegistry 服务与内置事实

收集

collect(execution) 从内置键出发,当执行携带 agent 时加入会话 id,再按 contributor 名称排序合并每个已注册 contributor 解析出的值。结果是一个冻结、按键排序的快照,通过 ShellExecRequest.dshEnv 传递。list() 枚举声明而不运行 resolver,因此无法反映依赖执行的值。


进一步探索

当包级约定不够用时阅读以下页面。它们从 shell 家族逐步进入执行器 seam 与生成目录。


模型体验

通过 shell 工具(dsh-tool-bash、dsh-tool-pwsh)间接产生影响;这些工具把本注册表的受管 DSH_* 事实暴露在每次 shell 工具调用中。

KV Cache 影响

受管环境永远不会进入请求前缀,因此不会使提供方缓存复用失效;任何前缀变更都取决于 shell 工具定义与当前请求信封。

已知限制与延期工作

这些限制说明注册表何时不合适或需要小心使用。它们是当前包约束,不是任务积压。

  • list() 只枚举插件贡献的变量——注册表自有的内置键(DSH_HOME、DSH_SHELL、DSH_SESSION_ID、DSH_PROFILE、DSH_PROFILE_DIR、DSH_INSTALL_DIR、DSH_NODE_EXECUTABLE)不包含在内,因此诊断、提示词或 UI 代码不得把 list() 当作完整的环境目录。

开发备注

维护者的工作上下文——点击展开

无。