DSH / Atlas
2026-11-05implementedarchitecture

Keep the HarnessError base in a dependency-free package

把 HarnessError 基类放在无依赖的包中

The tool registry records a failed result's `error.name` and `error.code` only when the thrown value is `instanceof HarnessError`, so every expected failure must extend the one shared class; copying its `code` field is not enough. The [archived structured-error-taxonomy note](../../archived/architecture/2026-06-11-structured-error-taxonomy.md) placed the base in `dsh-llm` because `dsh-llm` was then a leaf that every

English

Problem

The tool registry records a failed result's error.name and error.code only when the thrown value is instanceof HarnessError, so every expected failure must extend the one shared class; copying its code field is not enough. The archived structured-error-taxonomy note placed the base in dsh-llm because dsh-llm was then a leaf that every package already imported, so the base added no dependency edge.

dsh-llm stopped being a leaf. ImageBlock references ImageAttachmentRef from dsh-attachment, and dsh-llm depends on dsh-typert-protocol. A class in either lower package cannot extend a base defined in dsh-llm without a TypeScript project-reference cycle, so AttachmentError and RemoteError re-implement the code field on plain Error, and tool failures that carry them persist without structured identity.

Decision

HarnessError lives in @deepseek-ai/dsh-error (packages/util/error), a package with no dependencies that contains only the base class. dsh-llm depends on it and re-exports the same class from its entry, so existing import { HarnessError } from '@deepseek-ai/dsh-llm' statements keep working and both import paths name one constructor, which keeps instanceof checks consistent. LLM-specific failure codes and helpers such as isHarnessError stay in dsh-llm.

New code imports HarnessError from dsh-error when the importing package does not otherwise need dsh-llm, so a package that needs only the base takes no dependency on the LLM runtime. Packages below dsh-llm, such as dsh-attachment, can extend the base without a cycle.

Alternatives considered

Keep the base in dsh-llm. Lower packages would keep re-implementing the field shape, and the registry would keep dropping their codes; recognizing those shapes structurally in the registry would make it trust any object with a string code, including Node errno values.

Recognize specific classes in the registry. Matching RemoteError or AttachmentError by marker would add a dependency from dsh-tools to each package and repeat for every new low-level error class.

Move the base to an existing utility package. dsh-util-values and dsh-brand have unrelated roles; a dedicated package names the role and keeps the base free of their dependencies and change history.

Drop the dsh-llm re-export. Every existing import would have to change in one step without a behavior benefit.

Consequences

Any package can extend HarnessError, including packages that dsh-llm depends on, and the base no longer changes with the LLM runtime. The cost is one more published package and one more dependency edge for dsh-llm. Two import paths exist for one class; both are supported, and the error-handling rules name dsh-error as the home.

中文

问题

工具注册表只有在抛出值 instanceof HarnessError 时,才会在失败结果上记录 error.name 与 error.code,因此每种预期失败都必须继承这一个共享类;只复制它的 code 字段不够。已归档的结构化错误分类决策把基类放在 dsh-llm 中,因为当时 dsh-llm 是所有包都已导入的叶子包,放在那里不会增加依赖边。

dsh-llm 后来不再是叶子包。ImageBlock 引用了 dsh-attachment 的 ImageAttachmentRef,dsh-llm 还依赖 dsh-typert-protocol。这两个更底层的包中的类无法继承定义在 dsh-llm 里的基类,否则 TypeScript 项目引用会成环,因此 AttachmentError 与 RemoteError 只能在普通 Error 上重复实现 code 字段,携带它们的工具失败在持久化时没有结构化身份。

决策

HarnessError 位于 @deepseek-ai/dsh-error(packages/util/error)。这个包没有任何依赖,只包含该基类。dsh-llm 依赖它,并从自身入口重新导出同一个类,因此现有的 import { HarnessError } from '@deepseek-ai/dsh-llm' 继续可用,两种导入路径指向同一个构造函数,instanceof 判断保持一致。LLM 专属的失败码以及 isHarnessError 等辅助函数仍留在 dsh-llm。

当导入方本身不需要 dsh-llm 时,新代码从 dsh-error 导入 HarnessError,这样只需要基类的包不必依赖 LLM 运行时。dsh-attachment 等位于 dsh-llm 之下的包可以继承该基类而不形成依赖环。

考虑过的替代方案

把基类留在 dsh-llm。 底层包会继续重复实现字段结构,注册表也会继续丢弃它们的 code;如果让注册表按结构识别这类对象,它就会信任任何带字符串 code 的对象,包括 Node errno 值。

在注册表中识别特定类。 按标记匹配 RemoteError 或 AttachmentError 会让 dsh-tools 依赖每个这样的包,而且每出现一个新的底层错误类都要重复一次。

把基类移到现有的工具包。 dsh-util-values 与 dsh-brand 的职责与此无关;独立的包能准确命名职责,也让基类不受它们的依赖与变更历史影响。

去掉 dsh-llm 的重新导出。 所有现有导入都得一次性修改,却不带来任何行为收益。

后果

任何包都可以继承 HarnessError,包括 dsh-llm 所依赖的包,基类也不再随 LLM 运行时一起变更。代价是多发布一个包,dsh-llm 多一条依赖边。同一个类有两种导入路径,两者都受支持,错误处理规则把 dsh-error 作为它的归属位置。