refactor(error): move HarnessError to the dependency-free dsh-error package

dsh-llm depends on dsh-attachment and dsh-typert-protocol, so classes in
those packages could not extend a base defined in dsh-llm without a
project-reference cycle. HarnessError now lives in @deepseek-ai/dsh-error,
which has no dependencies; dsh-llm declares it as a peer and re-exports
the same class, so existing imports and instanceof checks keep working.
The Agent Note records why the original leaf-package placement no longer
holds.

Refs #7869
This commit is contained in:
sjw1231 committed 2026-11-05 21:26:38 +08:00
1 parent 09604ac04d
commit 71cb6c739a
29 files changed
+394 -21

No files matched your search

@@ -0,0 +1,19 @@
# Bilingual-pair consistency record for 2026-11-05-harness-error-dependency-free-base.md (docs/i18n/README.md): per heading
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
# After editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write .agents/notes/implemented/architecture/2026-11-05-harness-error-dependency-free-base.md
/agent-note-keep-the-harnesserror-base-in-a-dependency-free-package:
en: 6ff178be521c3318
zh: 18a9a8cc261fe975
/agent-note-keep-the-harnesserror-base-in-a-dependency-free-package/problem:
en: 29880462facde90c
zh: d07805b2000c85b1
/agent-note-keep-the-harnesserror-base-in-a-dependency-free-package/decision:
en: caec42054c040d37
zh: d726f0da57dc1e68
/agent-note-keep-the-harnesserror-base-in-a-dependency-free-package/alternatives-considered:
en: 8245e473d4e90250
zh: fe7883dfe13070a9
/agent-note-keep-the-harnesserror-base-in-a-dependency-free-package/consequences:
en: 9a577f5c3bb9fa15
zh: 4c18ec885768b9d3
@@ -0,0 +1,31 @@
# Agent Note: Keep the HarnessError base in a dependency-free package
Status: implemented
English | [中文](2026-11-05-harness-error-dependency-free-base.zh.md)
## 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](../../archived/architecture/2026-06-11-structured-error-taxonomy.md) 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.
@@ -0,0 +1,31 @@
# Agent Note: 把 HarnessError 基类放在无依赖的包中
Status: implemented
[English](2026-11-05-harness-error-dependency-free-base.md) | 中文
## 问题
工具注册表只有在抛出值 `instanceof HarnessError` 时,才会在失败结果上记录 `error.name` 与 `error.code`,因此每种预期失败都必须继承这一个共享类;只复制它的 `code` 字段不够。[已归档的结构化错误分类决策](../../archived/architecture/2026-06-11-structured-error-taxonomy.md)把基类放在 `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` 作为它的归属位置。
+1 -1
View File
@@ -11,7 +11,7 @@ Define failures, their owners, and what remains safe after failure.
Expected failures need declared types, stable discriminants, and handling-relevant details. Reuse package error conventions, preserve causes, and separate machine identity from display text. Never route handling by parsing messages. Unexpected defects such as `assertNever` may remain plain `Error`; containment must never turn them into success.
An error class that carries a machine code extends `HarnessError` from `dsh-llm`, directly or through its package's error class, never bare `Error`. Prefer one error class per owning package or domain over a class per failure; a separate class is justified when callers catch it by type or it carries its own structured fields, such as `ToolArgsError.violations`. `name` is the class name, except for cancellation (below), and `code` values are stable `UPPER_SNAKE_CASE` strings, usually prefixed by the domain and declared as a union or constants beside the class. A code names the failure class its consumers act on, not the call site; add a code rather than reuse one whose meaning differs. The [error class and code guide](references/error-codes.md) defines class choice, naming, the standard conditions, declaration, foreign-error conversion, and compatibility.
An error class that carries a machine code extends `HarnessError` from `dsh-error` (also re-exported by `dsh-llm`), directly or through its package's error class, never bare `Error`. Prefer one error class per owning package or domain over a class per failure; a separate class is justified when callers catch it by type or it carries its own structured fields, such as `ToolArgsError.violations`. `name` is the class name, except for cancellation (below), and `code` values are stable `UPPER_SNAKE_CASE` strings, usually prefixed by the domain and declared as a union or constants beside the class. A code names the failure class its consumers act on, not the call site; add a code rather than reuse one whose meaning differs. The [error class and code guide](references/error-codes.md) defines class choice, naming, the standard conditions, declaration, foreign-error conversion, and compatibility.
Convert foreign failures where the dependency is owned. Node errno, SDK, protocol, native, worker, and cross-realm errors become the owning package's error with the original as `cause`; a foreign numeric or vendor code belongs in the message, not in `code`. Preserve structure across layers: never re-wrap a `HarnessError` in a plain `Error`, store only its message for a later rethrow, or drop its `name` and `code` while redacting text. A process or worker boundary transports `name` and `code` and reconstructs the error.
+1
View File
@@ -5157,6 +5157,7 @@ Imported as libraries by other packages; a `cordis.yml` cannot load them.
| `@deepseek-ai/dsh-cmdline` | — | [`packages/boot/cmdline/src/index.ts`](../packages/boot/cmdline/src/index.ts) |
| `@deepseek-ai/dsh-cua-bundle` | — | [`packages/experimental/cua-bundle/src/index.ts`](../packages/experimental/cua-bundle/src/index.ts) |
| `@deepseek-ai/dsh-deque` | — | [`packages/util/deque/src/index.ts`](../packages/util/deque/src/index.ts) |
| `@deepseek-ai/dsh-error` | — | [`packages/util/error/src/index.ts`](../packages/util/error/src/index.ts) |
| `@deepseek-ai/dsh-experimental-badge-skill-bundle` | — | [`packages/experimental/badge-skill-bundle/src/index.ts`](../packages/experimental/badge-skill-bundle/src/index.ts) |
| `@deepseek-ai/dsh-experimental-browser-use-runtime` | — | [`packages/experimental/browser-use-runtime/src/index.ts`](../packages/experimental/browser-use-runtime/src/index.ts) |
| `@deepseek-ai/dsh-experimental-cot-translation-bundle` | — | [`packages/experimental/cot-translation-bundle/src/index.ts`](../packages/experimental/cot-translation-bundle/src/index.ts) |
+1
View File
@@ -5159,6 +5159,7 @@ export interface Config {
| `@deepseek-ai/dsh-cmdline` | — | [`packages/boot/cmdline/src/index.ts`](../packages/boot/cmdline/src/index.ts) |
| `@deepseek-ai/dsh-cua-bundle` | — | [`packages/experimental/cua-bundle/src/index.ts`](../packages/experimental/cua-bundle/src/index.ts) |
| `@deepseek-ai/dsh-deque` | — | [`packages/util/deque/src/index.ts`](../packages/util/deque/src/index.ts) |
| `@deepseek-ai/dsh-error` | — | [`packages/util/error/src/index.ts`](../packages/util/error/src/index.ts) |
| `@deepseek-ai/dsh-experimental-badge-skill-bundle` | — | [`packages/experimental/badge-skill-bundle/src/index.ts`](../packages/experimental/badge-skill-bundle/src/index.ts) |
| `@deepseek-ai/dsh-experimental-browser-use-runtime` | — | [`packages/experimental/browser-use-runtime/src/index.ts`](../packages/experimental/browser-use-runtime/src/index.ts) |
| `@deepseek-ai/dsh-experimental-cot-translation-bundle` | — | [`packages/experimental/cot-translation-bundle/src/index.ts`](../packages/experimental/cot-translation-bundle/src/index.ts) |
+2
View File
@@ -12,6 +12,7 @@ flowchart TD
pkg_brand["brand"]
pkg_chunked_list["chunked-list"]
pkg_deque["deque"]
pkg_error["error"]
pkg_home_paths["home-paths"]
pkg_http_proxy["http-proxy"]
pkg_launch_environment["launch-environment"]
@@ -1542,6 +1543,7 @@ flowchart TD
| [`brand`](../packages/util/brand) | `util` | — |
| [`chunked-list`](../packages/util/chunked-list) | `util` | — |
| [`deque`](../packages/util/deque) | `util` | — |
| [`error`](../packages/util/error) | `util` | — |
| [`home-paths`](../packages/util/home-paths) | `util` | — |
| [`http-proxy`](../packages/util/http-proxy) | `util` | — |
| [`launch-environment`](../packages/util/launch-environment) | `util` | — |
+2
View File
@@ -14,6 +14,7 @@ flowchart TD
pkg_brand["brand"]
pkg_chunked_list["chunked-list"]
pkg_deque["deque"]
pkg_error["error"]
pkg_home_paths["home-paths"]
pkg_http_proxy["http-proxy"]
pkg_launch_environment["launch-environment"]
@@ -1544,6 +1545,7 @@ flowchart TD
| [`brand`](../packages/util/brand) | `util` | — |
| [`chunked-list`](../packages/util/chunked-list) | `util` | — |
| [`deque`](../packages/util/deque) | `util` | — |
| [`error`](../packages/util/error) | `util` | — |
| [`home-paths`](../packages/util/home-paths) | `util` | — |
| [`http-proxy`](../packages/util/http-proxy) | `util` | — |
| [`launch-environment`](../packages/util/launch-environment) | `util` | — |
+2
View File
@@ -62,6 +62,7 @@
],
"license": "MIT",
"peerDependencies": {
"@deepseek-ai/dsh-error": "workspace:*",
"@deepseek-ai/cordis": "workspace:~"
},
"dependencies": {
@@ -75,6 +76,7 @@
},
"devDependencies": {
"@deepseek-ai/dsh-attachment": "workspace:*",
"@deepseek-ai/dsh-error": "workspace:*",
"@deepseek-ai/dsh-package-manifest": "workspace:*",
"@deepseek-ai/cordis": "workspace:~"
}
+5 -17
View File
@@ -1,25 +1,13 @@
/**
* Harness error base with a stable machine-routable code and chained cause.
* Package errors extend it so tool results and replay can retain failure class.
* LLM failure codes and helpers over the shared Harness error base. The base
* class lives in `@deepseek-ai/dsh-error` and is re-exported here, so both
* import paths name the same class.
* @module @deepseek-ai/dsh-llm/error
*/
/**
* Base class for all harness errors. Carries a `code` (stable, programmatic —
* e.g. `NO_ADAPTER`, `INVALID_ARGS`) distinct from the
* human-readable `message`, and supports `cause` chaining via the standard
* `ErrorOptions`. `name` defaults to the subclass constructor name.
*/
export class HarnessError extends Error {
/** Stable machine-routable failure class (e.g. `RATE_LIMIT`); route on this, never by parsing `message`. */
readonly code: string
import { HarnessError } from '@deepseek-ai/dsh-error'
constructor(message: string, code: string, options?: ErrorOptions) {
super(message, options)
this.code = code
this.name = new.target.name
}
}
export { HarnessError }
/**
* Every failure code the built-in providers and the LLM runtime raise. An entry
+3
View File
@@ -37,6 +37,9 @@
},
{
"path": "../../typert/protocol"
},
{
"path": "../../util/error"
}
]
}
+2 -2
View File
@@ -15,8 +15,8 @@
en: 1eb35b015a6c423f
zh: a8a3dceee2c9e943
/util-shared-utilities/packages:
en: 5d7eb32e5a9e81dc
zh: 5e419d4b44ffbd10
en: e345b399695a4e93
zh: 179fee3e2c4d90cc
/util-shared-utilities/related-documentation:
en: 432ae81110914571
zh: c5bf4efc007311f3
+1
View File
@@ -27,6 +27,7 @@ Each package provides one primitive or one data set; open a package page for how
| Package | Role |
|---|---|
| [`brand/`](brand/README.md) | Nominal string types and their stateless constructor |
| [`error/`](error/README.md) | The dependency-free `HarnessError` base class with a stable machine-routable code |
| [`package-manifest/`](package-manifest/README.md) | Shared TypeScript declarations for package manifests |
| [`plugin-detail/`](plugin-detail/README.md) | Selects plugin detail documents and reads them from local packages and npm file CDNs |
| [`plugin-market-index/`](plugin-market-index/README.md) | Validates plugin market index format 1 and builds pinned install arguments |
+1
View File
@@ -27,6 +27,7 @@ kind: "package-group"
| 包 | 职责 |
|---|---|
| [`brand/`](brand/README.zh.md) | 提供名义字符串类型及其无状态构造函数 |
| [`error/`](error/README.zh.md) | 无依赖、带稳定可路由 code 的 `HarnessError` 基类 |
| [`package-manifest/`](package-manifest/README.zh.md) | 包 manifest(元数据清单)的共享 TypeScript 声明 |
| [`plugin-detail/`](plugin-detail/README.zh.md) | 选择插件详细介绍文档,并从本地包和 npm 文件 CDN 读取它们 |
| [`plugin-market-index/`](plugin-market-index/README.zh.md) | 校验插件市场索引格式 1,并生成锁定版本的安装参数 |
+34
View File
@@ -0,0 +1,34 @@
# Bilingual-pair consistency record for README.md (docs/i18n/README.md): per heading
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
# After editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write packages/util/error/README.md
/:
en: 765d60b0cc7f8cf1
zh: 66b731f7143ccc5c
/deepseek-ai-dsh-error:
en: 78fc89983568c13f
zh: 12bb37d45b49562b
/deepseek-ai-dsh-error/summary:
en: eefb4278f326243a
zh: 681e25fc7d65865e
/deepseek-ai-dsh-error/table-of-contents:
en: c992e0cd2e7042d6
zh: 2e8cd826664632d1
/deepseek-ai-dsh-error/use-this-package:
en: 1b8c9b68ec9b48fc
zh: 4b0b54d3330b288b
/deepseek-ai-dsh-error/understand-the-implementation:
en: 42b15ac6321706aa
zh: 4ed0861911abaf5d
/deepseek-ai-dsh-error/understand-the-implementation/source-map:
en: a2e80abfe169f97f
zh: eb37e22c32f66add
/deepseek-ai-dsh-error/understand-the-implementation/why-it-stays-dependency-free:
en: 79564181c4c59db6
zh: 845856fa121b3ff7
/deepseek-ai-dsh-error/further-exploration:
en: 530bc3a0690a4012
zh: 192682c5a8571dfe
/deepseek-ai-dsh-error/dev-note:
en: 5de1d6304e00c58f
zh: 0087361e6f535488
+76
View File
@@ -0,0 +1,76 @@
---
description: "Dependency-free HarnessError base class whose stable code lets tool results, retries, and replay route failures."
kind: "package-library"
---
# @deepseek-ai/dsh-error
English | [中文](README.zh.md)
## Summary
`dsh-error` holds `HarnessError`, the base class for every expected Harness failure. A `HarnessError` carries a stable machine-routable `code` beside its human-readable `message` and optional `cause`, and its `name` is the constructing class name. The tool registry records `name` and `code` of a thrown `HarnessError` on `tool/result`, so retry policy, UI, replay, and analytics route on the code instead of parsing text. The package has no dependencies, so packages below `dsh-llm` in the dependency graph can extend the base too; `dsh-llm` re-exports the same class.
## Table of Contents
- [Use this package](#use-this-package)
- [Understand the implementation](#understand-the-implementation)
- [Further Exploration](#further-exploration)
- [Dev Note](#dev-note)
-----
<a id="use-this-package"></a>
## Use this package
Extend `HarnessError` with one class per owning package or domain and give each failure a stable `UPPER_SNAKE_CASE` code:
```ts
import { HarnessError } from '@deepseek-ai/dsh-error'
export class ArchiveError extends HarnessError {}
throw new ArchiveError('archive entry is missing', 'ARCHIVE_ENTRY_NOT_FOUND')
```
Assign `this.name` a string literal in a subclass constructor when a bundler could rename the class, because `name` is persisted. Import the class from `@deepseek-ai/dsh-error` or from its `@deepseek-ai/dsh-llm` re-export; both name the same class, so `instanceof` checks agree. The [error class and code guide](../../../.agents/skills/dsh-error-handling/references/error-codes.md) defines class choice, naming, and code conventions.
-----
<a id="understand-the-implementation"></a>
## Understand the implementation
<details>
<summary>Implementation internals — click to expand</summary>
### Source map
| File | Role |
|---|---|
| [`src/index.ts`](src/index.ts) | The `HarnessError` base class |
### Why it stays dependency-free
`dsh-llm` depends on lower packages such as `dsh-attachment` and `dsh-typert-protocol`, so a base class defined there could not be extended below it without a dependency cycle. Keeping the class in a package without dependencies lets every package extend it; the [decision note](../../../.agents/notes/implemented/architecture/2026-11-05-harness-error-dependency-free-base.md) records the relocation.
</details>
-----
<a id="further-exploration"></a>
## Further Exploration
- [Tools subsystem](../../../docs/subsystems/tools.md) — how the registry records `ToolErrorInfo` from a thrown `HarnessError`.
- [Error-handling rules](../../../.agents/skills/dsh-error-handling/SKILL.md) — when code must throw a `HarnessError`.
-----
<a id="dev-note"></a>
## Dev Note
<details>
<summary>Working context for maintainers — click to expand</summary>
None.
</details>
+76
View File
@@ -0,0 +1,76 @@
---
description: "无依赖的 HarnessError 基类,其稳定 code 让工具结果、重试与回放能够按失败类别路由。"
kind: "package-library"
---
# @deepseek-ai/dsh-error
[English](README.md) | 中文
## 概述
`dsh-error` 存放 `HarnessError`,即所有预期 Harness 失败的基类。`HarnessError` 在人类可读的 `message` 与可选的 `cause` 之外,携带稳定、可供机器路由的 `code`,其 `name` 为构造它的类名。工具注册表会把抛出的 `HarnessError` 的 `name` 与 `code` 记录到 `tool/result` 上,使重试策略、UI、回放与数据分析按 code 路由,而不必解析文本。本包没有任何依赖,因此依赖图中位于 `dsh-llm` 之下的包也能继承该基类;`dsh-llm` 会重新导出同一个类。
## 目录
- [使用本包](#use-this-package)
- [理解实现](#understand-the-implementation)
- [进一步探索](#further-exploration)
- [开发备注](#dev-note)
-----
<a id="use-this-package"></a>
## 使用本包
每个所属包或领域继承出一个 `HarnessError` 子类,并为每种失败指定稳定的 `UPPER_SNAKE_CASE` code:
```ts
import { HarnessError } from '@deepseek-ai/dsh-error'
export class ArchiveError extends HarnessError {}
throw new ArchiveError('archive entry is missing', 'ARCHIVE_ENTRY_NOT_FOUND')
```
打包工具可能重命名类时,在子类构造函数中把 `this.name` 赋为字符串字面量,因为 `name` 会被持久化。可以从 `@deepseek-ai/dsh-error` 导入该类,也可以使用 `@deepseek-ai/dsh-llm` 的重新导出;两者是同一个类,因此 `instanceof` 判断结果一致。[错误类与 code 指南](../../../.agents/skills/dsh-error-handling/references/error-codes.md)规定了类的选择、命名与 code 约定。
-----
<a id="understand-the-implementation"></a>
## 理解实现
<details>
<summary>实现细节——点击展开</summary>
### 源码地图
| 文件 | 职责 |
|---|---|
| [`src/index.ts`](src/index.ts) | `HarnessError` 基类 |
### 为什么保持无依赖
`dsh-llm` 依赖 `dsh-attachment`、`dsh-typert-protocol` 等更底层的包,定义在其中的基类无法被这些包继承,否则会形成依赖环。把该类放在没有依赖的包中,所有包都可以继承它;[决策记录](../../../.agents/notes/implemented/architecture/2026-11-05-harness-error-dependency-free-base.zh.md)记录了这次迁移。
</details>
-----
<a id="further-exploration"></a>
## 进一步探索
- [工具子系统](../../../docs/subsystems/tools.zh.md) — 注册表如何根据抛出的 `HarnessError` 记录 `ToolErrorInfo`。
- [错误处理规则](../../../.agents/skills/dsh-error-handling/SKILL.md) — 何时必须抛出 `HarnessError`。
-----
<a id="dev-note"></a>
## 开发备注
<details>
<summary>维护者的工作背景——点击展开</summary>
无。
</details>
+38
View File
@@ -0,0 +1,38 @@
{
"name": "@deepseek-ai/dsh-error",
"description": "Dependency-free HarnessError base class with a stable machine-routable code for the DeepSeek Harness",
"version": "0.2.2-rc.1",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
"directory": "packages/util/error"
},
"type": "module",
"main": "lib/index.js",
"types": "lib/types/index.d.ts",
"exports": {
".": {
"types": "./lib/types/index.d.ts",
"default": "./lib/index.js"
},
"./src/*": "./src/*",
"./package.json": "./package.json"
},
"files": [
"lib/index.js",
"lib/types/**/*.d.ts",
"lib/types/**/*.d.ts.map",
"lib/**/*.js.map",
"src"
],
"license": "MIT",
"peerDependencies": {
"@deepseek-ai/cordis": "workspace:~"
},
"devDependencies": {
"@deepseek-ai/cordis": "workspace:~"
}
}
+22
View File
@@ -0,0 +1,22 @@
/**
* Harness error base with a stable machine-routable code and chained cause.
* Package errors extend it so tool results and replay can retain failure class.
* @module @deepseek-ai/dsh-error
*/
/**
* Base class for all harness errors. Carries a `code` (stable, programmatic —
* e.g. `NO_ADAPTER`, `INVALID_ARGS`) distinct from the
* human-readable `message`, and supports `cause` chaining via the standard
* `ErrorOptions`. `name` defaults to the subclass constructor name.
*/
export class HarnessError extends Error {
/** Stable machine-routable failure class (e.g. `RATE_LIMIT`); route on this, never by parsing `message`. */
readonly code: string
constructor(message: string, code: string, options?: ErrorOptions) {
super(message, options)
this.code = code
this.name = new.target.name
}
}
+19
View File
@@ -0,0 +1,19 @@
import { describe, expect, it } from 'vitest'
import { HarnessError } from '../src/index.ts'
class SampleError extends HarnessError {}
describe('HarnessError', () => {
it('carries a code, a cause, and the constructing class name', () => {
const cause = new Error('underlying failure')
const error = new SampleError('operation failed', 'SAMPLE_FAILED', { cause })
expect(error).toBeInstanceOf(Error)
expect(error).toBeInstanceOf(HarnessError)
expect(error).toMatchObject({ name: 'SampleError', code: 'SAMPLE_FAILED', message: 'operation failed', cause })
})
it('names a direct instance HarnessError', () => {
expect(new HarnessError('failed', 'FAILED').name).toBe('HarnessError')
})
})
+10
View File
@@ -0,0 +1,10 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib/types"
},
"include": [
"src"
]
}
@@ -1,4 +1,4 @@
/** Generated by scripts/gen-workflow-guest.ts. Do not edit directly. */
/** Self-contained ESM guest transported into the mounted PTC runtime. */
export const WORKFLOW_GUEST_SOURCE = "import * as vm from \"node:vm\";\n//#region packages/workflow/workflow-ptc/src/realm.ts\n/**\n* Materializes script VM values as plain JSON and renders thrown values.\n* Getters and proxy traps may execute inside the confined Node process;\n* process isolation and cancellation belong to PTC, not the VM.\n* @module @deepseek-ai/dsh-workflow-ptc/realm\n*/\n/** Thrown by {@link materializeFromRealm}; the caller wraps it into the right `WorkflowError` code. */\nvar MaterializeError = class extends Error {\n\tpath;\n\treason;\n\tconstructor(path, reason) {\n\t\tsuper(`${path}: ${reason}`);\n\t\tthis.path = path;\n\t\tthis.reason = reason;\n\t\tthis.name = \"MaterializeError\";\n\t}\n};\n/**\n* Render a thrown value to failure text without ever throwing: prefer the\n* `stack` (host or realm — a realm error's `stack` is a plain string read),\n* fall back to `message`, then `String()`. Reading those properties MAY run\n* script code; if that code itself throws, a fixed label is returned instead.\n* @param error - any value thrown in the host or guest realm.\n* @returns human-readable text for the failure report; prefers the stack.\n*/\nfunction renderThrown(error) {\n\ttry {\n\t\tconst stack = error?.stack;\n\t\tif (typeof stack === \"string\" && stack.length > 0) return stack;\n\t\tconst message = error?.message;\n\t\tif (typeof message === \"string\" && message.length > 0) return message;\n\t\treturn String(error);\n\t} catch {\n\t\treturn \"[unrenderable thrown value]\";\n\t}\n}\n/**\n* Whether an object's prototype chain represents a plain data object: `null`, or a prototype\n* whose own prototype is `null` (the realm's `Object.prototype` — which we\n* cannot compare by identity across realms). A `Date`/`Map`/class instance\n* has a longer chain and is rejected.\n*/\nfunction hasPlainPrototype(value) {\n\tconst proto = Object.getPrototypeOf(value);\n\tif (proto === null) return true;\n\treturn Object.getPrototypeOf(proto) === null;\n}\n/**\n* Copy `value` (typically from the vm realm) into plain host JSON data. Root `undefined` is\n* returned unchanged; nested `undefined` and values JSON cannot represent losslessly fail\n* with the offending path. Property accessors run normally, and a throwing read is wrapped\n* with its rendered failure.\n*\n* @param value - the realm value to materialize.\n* @param root - the path label for the root value (error messages).\n* @returns the host-realm copy (plain objects/arrays/scalars only).\n* @throws {@link MaterializeError} for unsupported values, cycles, sparse arrays, exotic\n* prototypes, or property reads that throw.\n*/\nfunction materializeFromRealm(value, root = \"value\") {\n\tif (value === void 0) return void 0;\n\ttry {\n\t\treturn materialize(value, root, /* @__PURE__ */ new Set());\n\t} catch (error) {\n\t\tif (error instanceof MaterializeError) throw error;\n\t\tthrow new MaterializeError(root, `reading the value threw: ${renderThrown(error)}`);\n\t}\n}\nfunction materialize(value, path, seen) {\n\tswitch (typeof value) {\n\t\tcase \"boolean\":\n\t\tcase \"string\": return value;\n\t\tcase \"number\":\n\t\t\tif (!Number.isFinite(value)) throw new MaterializeError(path, \"non-finite numbers are not JSON data\");\n\t\t\treturn value;\n\t\tcase \"bigint\": throw new MaterializeError(path, \"bigints are not JSON data\");\n\t\tcase \"function\": throw new MaterializeError(path, \"functions are not plain JSON data\");\n\t\tcase \"symbol\": throw new MaterializeError(path, \"symbols are not plain JSON data\");\n\t\tcase \"undefined\": throw new MaterializeError(path, \"undefined is not JSON data\");\n\t\tcase \"object\": break;\n\t}\n\tif (value === null) return null;\n\tconst objectValue = value;\n\tif (seen.has(objectValue)) throw new MaterializeError(path, \"circular references are not JSON data\");\n\tseen.add(objectValue);\n\ttry {\n\t\tif (Array.isArray(objectValue)) return materializeArray(objectValue, path, seen);\n\t\treturn materializeObject(objectValue, path, seen);\n\t} finally {\n\t\tseen.delete(objectValue);\n\t}\n}\nfunction materializeArray(value, path, seen) {\n\tconst out = [];\n\tfor (let index = 0; index < value.length; index++) {\n\t\tif (!(index in value)) throw new MaterializeError(`${path}[${index}]`, \"sparse arrays are not JSON data\");\n\t\tout.push(materialize(value[index], `${path}[${index}]`, seen));\n\t}\n\tfor (const key of Object.keys(value)) {\n\t\tconst index = Number(key);\n\t\tif (!Number.isInteger(index) || index < 0 || index >= value.length) throw new MaterializeError(`${path}.${key}`, \"arrays with non-index properties are not JSON data\");\n\t}\n\tif (Object.getOwnPropertySymbols(value).length > 0) throw new MaterializeError(path, \"symbol-keyed properties are not plain JSON data\");\n\treturn out;\n}\nfunction materializeObject(value, path, seen) {\n\tif (!hasPlainPrototype(value)) throw new MaterializeError(path, \"only plain objects and arrays are JSON data (exotic prototype)\");Line truncated
export const WORKFLOW_GUEST_SOURCE = "import * as vm from \"node:vm\";\n//#region packages/workflow/workflow-ptc/src/realm.ts\n/**\n* Materializes script VM values as plain JSON and renders thrown values.\n* Getters and proxy traps may execute inside the confined Node process;\n* process isolation and cancellation belong to PTC, not the VM.\n* @module @deepseek-ai/dsh-workflow-ptc/realm\n*/\n/** Thrown by {@link materializeFromRealm}; the caller wraps it into the right `WorkflowError` code. */\nvar MaterializeError = class extends Error {\n\tpath;\n\treason;\n\tconstructor(path, reason) {\n\t\tsuper(`${path}: ${reason}`);\n\t\tthis.path = path;\n\t\tthis.reason = reason;\n\t\tthis.name = \"MaterializeError\";\n\t}\n};\n/**\n* Render a thrown value to failure text without ever throwing: prefer the\n* `stack` (host or realm — a realm error's `stack` is a plain string read),\n* fall back to `message`, then `String()`. Reading those properties MAY run\n* script code; if that code itself throws, a fixed label is returned instead.\n* @param error - any value thrown in the host or guest realm.\n* @returns human-readable text for the failure report; prefers the stack.\n*/\nfunction renderThrown(error) {\n\ttry {\n\t\tconst stack = error?.stack;\n\t\tif (typeof stack === \"string\" && stack.length > 0) return stack;\n\t\tconst message = error?.message;\n\t\tif (typeof message === \"string\" && message.length > 0) return message;\n\t\treturn String(error);\n\t} catch {\n\t\treturn \"[unrenderable thrown value]\";\n\t}\n}\n/**\n* Whether an object's prototype chain represents a plain data object: `null`, or a prototype\n* whose own prototype is `null` (the realm's `Object.prototype` — which we\n* cannot compare by identity across realms). A `Date`/`Map`/class instance\n* has a longer chain and is rejected.\n*/\nfunction hasPlainPrototype(value) {\n\tconst proto = Object.getPrototypeOf(value);\n\tif (proto === null) return true;\n\treturn Object.getPrototypeOf(proto) === null;\n}\n/**\n* Copy `value` (typically from the vm realm) into plain host JSON data. Root `undefined` is\n* returned unchanged; nested `undefined` and values JSON cannot represent losslessly fail\n* with the offending path. Property accessors run normally, and a throwing read is wrapped\n* with its rendered failure.\n*\n* @param value - the realm value to materialize.\n* @param root - the path label for the root value (error messages).\n* @returns the host-realm copy (plain objects/arrays/scalars only).\n* @throws {@link MaterializeError} for unsupported values, cycles, sparse arrays, exotic\n* prototypes, or property reads that throw.\n*/\nfunction materializeFromRealm(value, root = \"value\") {\n\tif (value === void 0) return void 0;\n\ttry {\n\t\treturn materialize(value, root, /* @__PURE__ */ new Set());\n\t} catch (error) {\n\t\tif (error instanceof MaterializeError) throw error;\n\t\tthrow new MaterializeError(root, `reading the value threw: ${renderThrown(error)}`);\n\t}\n}\nfunction materialize(value, path, seen) {\n\tswitch (typeof value) {\n\t\tcase \"boolean\":\n\t\tcase \"string\": return value;\n\t\tcase \"number\":\n\t\t\tif (!Number.isFinite(value)) throw new MaterializeError(path, \"non-finite numbers are not JSON data\");\n\t\t\treturn value;\n\t\tcase \"bigint\": throw new MaterializeError(path, \"bigints are not JSON data\");\n\t\tcase \"function\": throw new MaterializeError(path, \"functions are not plain JSON data\");\n\t\tcase \"symbol\": throw new MaterializeError(path, \"symbols are not plain JSON data\");\n\t\tcase \"undefined\": throw new MaterializeError(path, \"undefined is not JSON data\");\n\t\tcase \"object\": break;\n\t}\n\tif (value === null) return null;\n\tconst objectValue = value;\n\tif (seen.has(objectValue)) throw new MaterializeError(path, \"circular references are not JSON data\");\n\tseen.add(objectValue);\n\ttry {\n\t\tif (Array.isArray(objectValue)) return materializeArray(objectValue, path, seen);\n\t\treturn materializeObject(objectValue, path, seen);\n\t} finally {\n\t\tseen.delete(objectValue);\n\t}\n}\nfunction materializeArray(value, path, seen) {\n\tconst out = [];\n\tfor (let index = 0; index < value.length; index++) {\n\t\tif (!(index in value)) throw new MaterializeError(`${path}[${index}]`, \"sparse arrays are not JSON data\");\n\t\tout.push(materialize(value[index], `${path}[${index}]`, seen));\n\t}\n\tfor (const key of Object.keys(value)) {\n\t\tconst index = Number(key);\n\t\tif (!Number.isInteger(index) || index < 0 || index >= value.length) throw new MaterializeError(`${path}.${key}`, \"arrays with non-index properties are not JSON data\");\n\t}\n\tif (Object.getOwnPropertySymbols(value).length > 0) throw new MaterializeError(path, \"symbol-keyed properties are not plain JSON data\");\n\treturn out;\n}\nfunction materializeObject(value, path, seen) {\n\tif (!hasPlainPrototype(value)) throw new MaterializeError(path, \"only plain objects and arrays are JSON data (exotic prototype)\");Line truncated
+9
View File
@@ -13214,6 +13214,9 @@ importers:
'@deepseek-ai/dsh-attachment':
specifier: workspace:*
version: link:../../attachment/attachment
'@deepseek-ai/dsh-error':
specifier: workspace:*
version: link:../../util/error
'@deepseek-ai/dsh-package-manifest':
specifier: workspace:*
version: link:../../util/package-manifest
@@ -17750,6 +17753,12 @@ importers:
specifier: workspace:~
version: link:../../../vendor/cordis
packages/util/error:
devDependencies:
'@deepseek-ai/cordis':
specifier: workspace:~
version: link:../../../vendor/cordis
packages/util/file-drag:
dependencies:
mime:
+1
View File
@@ -94,6 +94,7 @@ const PACKAGE_LIBRARIES: Readonly<Record<string, string>> = {
'packages/util/atomic-write': 'Zero-dependency filesystem write utility.',
'packages/util/brand': 'Stateless nominal-string and canonical-key constructors.',
'packages/util/crypto': 'Zero-dependency identifier minting utility.',
'packages/util/error': 'Zero-dependency HarnessError base class.',
'packages/util/deque': 'Zero-dependency circular deque utility.',
'packages/util/chunked-list': 'Persistent collection operations and checkpoint validation without a plugin surface.',
'packages/util/code-language': 'Zero-dependency file-extension to syntax-highlighting language table.',
+2
View File
@@ -80,6 +80,8 @@ const PEER_REQUIRED_HOST_EXPORTS = {
// CUA checks UserQuestionError and preserves AttachmentError from image admission.
'@deepseek-ai/dsh-attachment': ['admitEncodedImages'],
'@deepseek-ai/dsh-user-questions': ['UserQuestionError'],
// The tool registry and every subclass rely on `instanceof` against one HarnessError class.
'@deepseek-ai/dsh-error': ['HarnessError'],
// `instanceof` checks need the translator's own class instance.
'@deepseek-ai/dsh-experimental-translator': ['TranslationError'],
// Stateless; a safe classification would turn the forge panel's forge and worktree peers into dependencies.
@@ -18,6 +18,7 @@ const CANONICAL = '## Known Limitations and Deferred Work'
/** Packages audited as having no limitations section, keyed by repo-relative directory. */
const NO_LIMITATIONS: Readonly<Record<string, string>> = {
'packages/util/brand': 'Stateless nominal-string and canonical-key helpers have no deferred work.',
'packages/util/error': 'A single base class with no behavior beyond its constructor has no deferred work.',
}
/** A heading that reads as a limitations section — canonical or drifted. */
@@ -35,6 +35,7 @@ const NO_MODEL_EXPERIENCE_SECTION: Readonly<Record<string, string>> = {
'packages/core/scope': 'The package is a model-agnostic registration and lifecycle primitive; model-facing consumers own any context selection.',
'packages/experimental/liveshare-protocol': 'The package only defines wire frames and identity values that its consumers exchange; it registers nothing model-facing.',
'packages/util/brand': 'The package only constructs plain string values and registers nothing model-facing.',
'packages/util/error': 'The package only defines the HarnessError base class; packages that throw it own any model-facing text.',
'packages/util/home-paths': 'The package only resolves harness-owned host paths; model-facing consumers own any rendered use.',
'packages/util/launch-environment': 'The package only resolves host environment values; model-facing consumers own any rendered use.',
'packages/util/workspace-path': 'The package only formats Workspace paths for browser UI; it never constructs model input.',
+1
View File
@@ -453,6 +453,7 @@
"@deepseek-ai/dsh-deepseek-llm-api-extensions": ["./packages/llm/deepseek-llm-api-extensions/src"],
"@deepseek-ai/dsh-deliverable-file-references": ["./packages/deliverables/deliverable-file-references/src"],
"@deepseek-ai/dsh-deque": ["./packages/util/deque/src"],
"@deepseek-ai/dsh-error": ["./packages/util/error/src"],
"@deepseek-ai/dsh-file-reference": ["./packages/context/file-reference/src"],
"@deepseek-ai/dsh-file-reference-local": ["./packages/context/file-reference-local/src"],
"@deepseek-ai/dsh-fs": ["./packages/fs/fs/src"],
+1
View File
@@ -343,6 +343,7 @@
{ "path": "./packages/boot/hmr" },
{ "path": "./vendor/logger-console" },
{ "path": "./packages/util/brand" },
{ "path": "./packages/util/error" },
{ "path": "./packages/util/package-manifest" },
{ "path": "./packages/util/plugin-detail" },
{ "path": "./packages/util/plugin-market-index" },