From d4066efe5e97a51266b0d2e424c910c27f3cbb07 Mon Sep 17 00:00:00 2001 From: Turtle Date: Fri, 6 Nov 2026 19:13:07 +0800 Subject: [PATCH] docs(notes): clarify stable API markers, checks, and pilot scope Refs #8074 --- ...2026-06-11-api-extractor-reports.i18n.yaml | 4 +- .../2026-06-11-api-extractor-reports.md | 2 +- .../2026-06-11-api-extractor-reports.zh.md | 2 +- .../2026-11-05-stable-api-policy.i18n.yaml | 52 +++++++------- .../process/2026-11-05-stable-api-policy.md | 71 ++++++++++--------- .../2026-11-05-stable-api-policy.zh.md | 71 ++++++++++--------- 6 files changed, 108 insertions(+), 94 deletions(-) diff --git a/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.i18n.yaml b/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.i18n.yaml index 092eb06323..51ff96836f 100644 --- a/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.i18n.yaml +++ b/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.i18n.yaml @@ -21,5 +21,5 @@ en: 21838e31d29b87fb zh: c72c81ef53b090e0 /agent-note-api-extractor-reports/why-deferred: - en: 63f9de99ab88ae98 - zh: fc088ed2f4bfbb0e + en: 7e8a1bd17832ec5c + zh: 3ea8dea04965f676 diff --git a/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.md b/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.md index b325587684..df04821628 100644 --- a/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.md +++ b/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.md @@ -31,4 +31,4 @@ The dependency is heavy and finicky — the reason this was deferred — and the Deferred when doc-sync landed: low value for an internal monorepo where reviewers already see the source diff, and a heavy, finicky dependency. Revisit if the packages are ever published externally — at that point a stable, diffable public API earns its keep. -The packages are now published to npm, so the revisit condition holds. The [stable API policy](2026-11-05-stable-api-policy.md) proposal adopts this report as its baseline phase and adds stability levels and per-seam versions to it. +The packages are now published to npm, so the revisit condition holds. The [stable API policy](2026-11-05-stable-api-policy.md) proposal replaces the per-package reports with one report covering exports, services, and events, and adds stability levels and per-seam versions; its acceptance criteria apply if it is accepted. diff --git a/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.zh.md b/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.zh.md index 4063f5f8e0..f21f46eb86 100644 --- a/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.zh.md +++ b/.agents/notes/proposed/process/2026-06-11-api-extractor-reports.zh.md @@ -31,4 +31,4 @@ Status: proposed 在 doc-sync 落地时被推迟:对于一个内部 monorepo,评审者已经能看到源码 diff,价值不高;且依赖笨重、难以调教。如果各包将来对外发布,再重新评估——届时一份稳定、可 diff 的公开接口报告才值得其维护成本。 -各包现已发布到 npm,重新评估的条件已经满足。[稳定 API 规范](2026-11-05-stable-api-policy.zh.md)提案把本报告作为其基线阶段,并在报告中加入稳定级别和按 seam 划分的版本。 +各包现已发布到 npm,重新评估的条件已经满足。[稳定 API 规范](2026-11-05-stable-api-policy.zh.md)提案用一份覆盖导出、服务和事件的报告取代每个包一份的报告,并加入稳定级别和按 seam 划分的版本;该提案被接受后,以其验收标准为准。 diff --git a/.agents/notes/proposed/process/2026-11-05-stable-api-policy.i18n.yaml b/.agents/notes/proposed/process/2026-11-05-stable-api-policy.i18n.yaml index 5eb25bb1de..aaddf1c727 100644 --- a/.agents/notes/proposed/process/2026-11-05-stable-api-policy.i18n.yaml +++ b/.agents/notes/proposed/process/2026-11-05-stable-api-policy.i18n.yaml @@ -6,44 +6,44 @@ en: efcff6bc65d1ae54 zh: 2b32885373cb788d /agent-note-stable-api-policy/problem: - en: 2fdcc60662854a90 - zh: f3a608aef7c0a19f + en: b6492a320d28ff1c + zh: 0105277d71fe43ab /agent-note-stable-api-policy/proposal: - en: e3b788c84737dd2b - zh: 5a77241451adb735 + en: 88384462c8232e93 + zh: 355ad48f96efc95e /agent-note-stable-api-policy/proposal/stability-levels: - en: f9ee42fc3b9a3d25 - zh: 3408072f29801caf + en: ad9ea5e151e05ac2 + zh: baa08299dac43ee4 /agent-note-stable-api-policy/proposal/unit-one-capability-seam: - en: 2c7967117aacab78 - zh: ec76ef3db7216b73 + en: f6707df2621559f2 + zh: 82dc3b81c29b5f0a /agent-note-stable-api-policy/proposal/what-stable-covers: - en: b3359a75deac0cb2 - zh: b6202f91ff2031ab + en: 0a637e21cfbabeb3 + zh: 76078282bf686e17 /agent-note-stable-api-policy/proposal/api-report-and-ci: - en: daf2b29671f39467 - zh: b3728dafff7c1c8d + en: 772026ec3f2512b0 + zh: d6cf271248e85a0e /agent-note-stable-api-policy/proposal/plugin-author-warnings: - en: f5acb81f7dd4f54e - zh: 9670fdbd63dbbb8b + en: e9bdb925a73e14e4 + zh: e04aa39a43407070 /agent-note-stable-api-policy/proposal/plugin-requirements: - en: fa7610e3b6d7338b - zh: 40fe03120eb29e46 + en: cce626a0c5dff76f + zh: d85d04d33ddcff48 /agent-note-stable-api-policy/proposal/compatibility-layer: en: 40445e93d1bb8561 zh: 05a845c5093f4abd /agent-note-stable-api-policy/proposal/rollout: - en: ee100e798d22c433 - zh: 993a4a1f96bf84bc + en: 16e88b03b3f1bc38 + zh: 5628adf979269b92 /agent-note-stable-api-policy/proposal/open-questions: - en: 1983889788985670 - zh: 8c1baeb91a74e08a + en: 7adf48d2e14e57bd + zh: 01e6160925bc6c68 /agent-note-stable-api-policy/alternatives-considered: - en: 7c48764472252b93 - zh: c18289c0d09745dc + en: 4154f0aadc2f0017 + zh: cc1e120f80e7fbb8 /agent-note-stable-api-policy/acceptance-criteria: - en: 62bddb29ddf4e974 - zh: 9dadef50f9f7d920 + en: a858ac77edabe3d3 + zh: 63f0872b73eef7f3 /agent-note-stable-api-policy/risks: - en: 64ba57f19f3996b1 - zh: 58e58e2e9c1d960d + en: 16693acc4f57df3a + zh: 96b056ba83bf3c38 diff --git a/.agents/notes/proposed/process/2026-11-05-stable-api-policy.md b/.agents/notes/proposed/process/2026-11-05-stable-api-policy.md index 3f4684d797..4f2dc652aa 100644 --- a/.agents/notes/proposed/process/2026-11-05-stable-api-policy.md +++ b/.agents/notes/proposed/process/2026-11-05-stable-api-policy.md @@ -6,61 +6,64 @@ English | [中文](2026-11-05-stable-api-policy.zh.md) ## Problem -Every public DSH API is pre-stable: root `AGENTS.md` tells contributors to update every consumer when an API changes. That rule works inside the repository, but external plugins now install from npm and the plugin market, and their authors cannot tell which APIs they can rely on. All released packages share one lockstep version, so a package version says nothing about which API changed. The only compatibility check, `evaluatePluginCompatibility` in [plugin-compatibility.ts](../../../../packages/boot/app-boot/src/plugin-compatibility.ts), compares a plugin's `engines.dsh` or `@deepseek-ai/dsh-*` peer ranges with the whole runtime version. +Every public DSH API is pre-stable: root `AGENTS.md` tells contributors to update every consumer when an API changes. That rule works inside the repository, but external plugins now install from npm and the plugin market, and their authors cannot tell which APIs they can rely on. All released packages share one lockstep version, so a package version says nothing about which API changed. The only compatibility check, `evaluatePluginCompatibility` in [plugin-compatibility.ts](../../../../packages/boot/app-boot/src/plugin-compatibility.ts), compares a plugin's `engines.dsh` range, or else its `@deepseek-ai/dsh` and `@deepseek-ai/dsh-*` peer ranges, with the whole runtime version; `workspace:` peer ranges count as the running version. -Nothing in the source marks stability today. Package exports carry no `@public`, `@beta`, `@stable`, or `@since` tags, and `@deprecated` appears only about a dozen times. The only rigorous compatibility rules cover data formats ([Session format status](../../../../docs/session-format-status.md), SQLite schema versions, persistence type acknowledgements) and [upgrade guides](../../../skills/dsh-create-upgrade-guide/SKILL.md). +No source marker distinguishes stable from unstable APIs. Exports carry no `@public`, `@beta`, `@stable`, or `@since` tags; `@internal` appears about ten times with differing meanings, and undated `@deprecated` about a dozen times. The only rigorous compatibility rules cover data formats ([Session format status](../../../../docs/session-format-status.md), SQLite schema versions, persistence type acknowledgements) and [upgrade guides](../../../skills/dsh-create-upgrade-guide/SKILL.md). The policy must start from this state. Contributors must not have to classify every API before the policy takes effect, and code that nobody marks must keep today's workflow. ## Proposal -Stability markers in source are the only input. A generated API report turns them into a versioned list of stable APIs for each release. The unit of versioning is the [capability seam](../../../../docs/glossary.md#capability-seam). Anything not marked stays unstable, so adoption proceeds one seam at a time. +Stability markers in source are the only input. A generated API report turns them into a versioned list of stable APIs for each release. The unit of versioning is the [capability seam](../../../../docs/glossary.md#capability-seam). Anything not marked stays unstable, so adoption proceeds one member at a time. ### Stability levels -| Level | Meaning | Change rule | +| Level | Marker | Change rule | |---|---|---| -| internal | Marked `@internal`; used only inside this repository, and excluded from the published API report | Change freely and update every consumer | -| unstable (default) | Every public export, service, event, and config field without a stable marker | Change freely, update every consumer, and record externally perceptible breaks in an upgrade guide | -| stable | Promoted explicitly as part of a versioned seam API | Backward-compatible additions only; a removal or incompatible change requires prior deprecation and a major seam version | -| deprecated | Stable API scheduled for removal | Removable only after the deprecation period has elapsed since its dated `@deprecated` marker; names its replacement or states that none exists | +| unstable (default) | None | Change freely, update every consumer, and record externally perceptible breaks in an upgrade guide | +| stable | `@stable @`, the seam version that added the member | Backward-compatible additions only; a removal or incompatible change requires a completed deprecation period and a major seam version | +| internal | `@internal` | Used only inside this repository; omitted from the API report; change freely | -Packages under [`packages/experimental/`](../../../../packages/experimental/README.md#status) cannot contain stable APIs; a package is promoted out of the experimental group before any of its APIs are promoted. +Deprecation is a state of a stable member, not a fourth level: a member tagged `@deprecated ` stays stable until its deprecation period ends. `@internal` and `@deprecated` tags on unstable members keep their current meaning; the policy assigns no new meaning to existing tags. + +Packages under [`packages/experimental/`](../../../../packages/experimental/README.md#status) cannot contain stable members; a package is promoted out of the experimental group before any of its members are promoted. ### Unit: one capability seam -Each capability seam has its own API version, independent of the lockstep package version. A seam's API covers its Service Definition, the types and events the Service Definition package declares, waterfall calling conventions, and the config fields of the Service Definition package. Config fields of Service Providers follow the level of their provider package. Exports that belong to no seam, such as utilities, CLI options, and the SDK wire protocol, stay unstable until a later proposal assigns them. +Each capability seam has its own API version, independent of the lockstep package version. A stable member belongs to the seam of the Service Definition package that declares it; a member of a declaration-merged interface such as `Context` or `SessionEventMap` belongs to the seam of the package that adds it. Exports that belong to no seam, such as utilities, CLI options, and the SDK wire protocol, stay unstable until a later proposal assigns them. Members reachable only through `./src/*` export subpaths are unstable. -The package that declares a Service Definition records the seam in its manifest. One package can declare several seams, so the field is a list: +The package that declares a Service Definition records its seam version in the existing `package.json` `dsh` declaration, owned by the [public package manifest](../../implemented/architecture/2026-09-10-public-package-manifest.md) decision. One package can declare several seams, so the member is a list: ```json -{ "dsh": { "apis": [{ "name": "agent", "version": "1.0.0", "stability": "stable" }] } } +{ "dsh": { "manifestVersion": 1, "apis": [{ "name": "agent", "version": "1.0.0" }] } } ``` -The field name and position are not settled yet. JSDoc tags override the seam level for individual members: `@unstable` keeps a member of a stable seam unstable, and `@deprecated YYYY-MM-DD ` starts the deprecation period. Members of declaration-merged interfaces such as `Context` and `SessionEventMap` are marked one by one. +The member names, and whether they require a new `manifestVersion`, are not settled. As that decision requires, the report generator and the compatibility check each validate the members they read. ### What stable covers -Stable covers type signatures, event order, and waterfall calling conventions, including whether a listener must call `next()`. Default config values are not covered. CI detects signature changes from the generated report. Behavior changes cannot be detected reliably, so the author declares them in the PR, following the pattern of [persistence type acknowledgements](../../../../docs/cookbook/reviewing-persistence-type-changes.md). This keeps changes that do not break callers from being reported as breaks. +Stable covers type signatures, event order, and waterfall calling conventions, including whether a listener must call `next()`. Default config values and config fields are not covered in this proposal. CI detects signature changes from the generated report. Behavior changes cannot be detected reliably; the author declares them in the PR description, and ordinary review checks the declaration. Tests that pin stable event order and waterfall conventions belong to the Service Definition package and run against the shipped Service Provider. + +A stable signature can reference types from other seams, such as `SessionId` or `Scoped`. Those referenced types become part of the referencing seam's promise: the report lists them under that seam, and an incompatible change to them fails the same checks as a change to the seam's own members. ### API report and CI -A script generates one checked-in API report covering exports, Cordis services, and events, with each entry's seam, level, and version. The deferred [API extractor reports](2026-06-11-api-extractor-reports.md) proposal is the first phase of this report. CI checks stable entries against the previous report and fails when: +A script generates one checked-in API report covering exports, Cordis services, and events, with each entry's seam, level, and version; it replaces the per-package reports of the deferred [API extractor reports](2026-06-11-api-extractor-reports.md) proposal. Each release archives its report. CI compares stable entries, including referenced types, with the latest released report and fails when: - a stable entry is removed or changed incompatibly without a major seam version bump and an upgrade guide; -- a removed entry was not deprecated, or its deprecation period has not elapsed; +- a removed entry was not deprecated in a released report, or its deprecation period has not elapsed since the first release whose report recorded the deprecation; - a stable entry is added without a minor seam version bump; -- a stable signature references an unstable type. +- a stable signature references a member marked `@internal` or an unstable member of its own seam. -Changes to unstable entries appear in the report diff without failing CI. CI also posts a summary of stable API changes to the PR. Promotion and breaking changes are approved in ordinary PR review; no dedicated API owner or committee is named. +Measuring the period from the first release that recorded the deprecation keeps it independent of dates authors write. Changes to unstable entries appear in the report diff without failing CI. CI also posts a summary of stable API changes to the PR. Promotion and breaking changes are approved in ordinary PR review; no dedicated API owner or committee is named. ### Plugin author warnings -A type-aware lint rule reports uses of unstable APIs, working the same way as `typescript/no-deprecated`, which [.oxlintrc.json](../../../../.oxlintrc.json) already enables: it resolves the called symbol and reads its level. Plugin authors run it in their own builds; the repository runs it on stable Service Definition packages. Subpath export isolation (`…/unstable` entry points) was rejected; see [Alternatives considered](#alternatives-considered). +A type-aware lint rule reports uses of unstable members by resolving each used symbol and reading its level from the published declarations. Event and waterfall names are string literals passed to `ctx.on()` and similar calls, so the rule resolves them against the event map; `typescript/no-deprecated` in [.oxlintrc.json](../../../../.oxlintrc.json) does not cover this case. Oxlint offers no custom type-aware rules, so the rule ships as a published tool that plugin authors run in their own builds; the repository runs it on stable Service Definition packages. Subpath export isolation (`…/unstable` entry points) was rejected; see [Alternatives considered](#alternatives-considered). ### Plugin requirements -A plugin may declare the seam versions it needs, for example `"dsh": { "requires": { "agent": "^1.0.0" } }`; the field name follows the `apis` decision. When the field is present, `evaluatePluginCompatibility` checks each listed seam range against the installed seam versions. By convention the plugin also lists the unstable seams it uses; the Host cannot verify that list, and the plugin manager shows it as a risk. When it is absent, the current `engines.dsh` and peer range check applies unchanged and the plugin is treated as depending on unstable APIs. The declaration does not restrict what a plugin can import or access: Cordis plugins run in the Host process and can import any package or reach any service on `ctx`. +A plugin may declare the seam versions it needs, for example `"dsh": { "requires": { "agent": "^1.0.0" } }`. The seam check is additive: `evaluatePluginCompatibility` still evaluates `engines.dsh` or the DSH peer ranges, and also compares each listed seam range with the seam versions recorded in the running Host's API report. A plugin that declares seam ranges can widen its `engines.dsh` range to every runtime it supports. Plugin market index entries and registry update checks read the same declaration, so discovery, installation, and update reach the same result. By convention the plugin also lists the unstable seams it uses; the Host cannot verify that list, and the plugin manager shows it as a risk. The declaration does not restrict what a plugin can import or access: Cordis plugins run in the Host process and can import any package or reach any service on `ctx`. ### Compatibility layer @@ -68,47 +71,51 @@ Serving an old major seam version to old plugins is deferred. It becomes worthwh ### Rollout -1. Policy only: land this note, change the root `AGENTS.md` pre-stable rule to "unmarked APIs are unstable", and define the deprecation period. No code changes. +1. Policy only: land this note and define the deprecation period. Replace the pre-stable statement with "unmarked APIs are unstable" in root `AGENTS.md`, [packages/README.md](../../../../packages/README.md), [packages/experimental/README.md](../../../../packages/experimental/README.md), [apps/cli/reference/README.md](../../../../apps/cli/reference/README.md), and the generated package reference from [gen-plugin-packages.ts](../../../../scripts/gen-plugin-packages.ts). No code changes. 2. Baseline report: generate and check in the first API report; CI only checks that it is current. -3. Pilot: promote the agent seam. Its stable API is the Service Definition in `dsh-agent`: `ctx.agents`, the `Agent` handle, the `agent/*` events, and the `agent/pre-step` waterfall. The `dsh-agent-loop` Service Provider stays unstable. The already deprecated `agent/request` waterfall receives a dated marker stating that no replacement exists for other per-request controls, and exercises the deprecation and removal checks. The lint rule and the `requires` check ship in this phase. -4. Promote further seams when the maintainers of a seam choose to; publish the stable API list on the documentation website. +3. Pilot: promote members of the agent seam declared by `dsh-agent`: `ctx.agents`, `AgentHandle`, `Agent`, the `agent/*` events other than the deprecated `agent/request`, and the `agent/pre-step` waterfall. Types they reference from session, scope, and llm packages join the promise as described above. The `dsh-agent-loop` Service Provider and its config stay unstable, so the pilot stabilizes no configuration. The lint tool and the `requires` check ship in this phase; [package-manifest README](../../../../packages/util/package-manifest/README.md) and the public package manifest note are updated to describe the enforced check. +4. Promote further members and seams when the maintainers of a seam choose to; publish the stable API list on the documentation website. 5. Add compatibility adapters for specific seams when the condition above holds. ### Open questions -- Name and position of the `dsh.apis` and `dsh.requires` manifest fields. +- Names of the `dsh.apis` and `dsh.requires` members, and whether they require a new `manifestVersion`. - Length of the time-based deprecation period before DSH 1.0. - Whether the Python SDK methods, the SDK JSON-RPC protocol, and `cordis.yml` config fields join the same levels, and whether the protocol needs its own version. - Report generator: API Extractor or a dump built on the export walker in [scripts/verify-export-jsdoc.ts](../../../../scripts/verify-export-jsdoc.ts) and the tag parser in [scripts/jsdoc.ts](../../../../scripts/jsdoc.ts). +- Lint tool form: a standalone published checker built on the same export walker, a non-type-aware approximation, or an upstream oxlint rule. ## Alternatives considered -**`@stable` markers without versions.** Cheapest and incremental, but a plugin cannot state which stable API it was built against, the Host cannot check it, and a deprecation period has no unit. Kept as the input format; the generated report supplies the versions. +**`@stable` markers without versions.** Cheapest and incremental, but a plugin cannot state which stable API it was built against, the Host cannot check it, and the report cannot tell additions from existing members. Kept as the input format with the adding seam version attached; the generated report supplies the list. **A hand-maintained versioned list per release.** Gives plugin authors a clear reference, but maintaining it by hand for over a thousand export subpaths and more than a hundred services is not practical, and one version for the whole list forces every plugin to react to any seam's break. Kept as the generated report rather than a maintained artifact. **One API version for the whole platform** (Android API level, VS Code `engines`). Simplest for plugin authors, but DSH releases often and its seams evolve independently; a single number would either grow with every break or discourage necessary breaks. +**Independent semver per npm package, dropping the lockstep version.** The [npm release sequences](../../implemented/process/2026-08-10-npm-release-sequences.md) decision keeps all DSH packages on one version so releases and peer ranges stay consistent. Package versions would also change for internal refactors that do not touch any API a plugin uses. Seam versions describe API compatibility without changing how packages are released. + **Grouping by package directory instead of seam.** Groups such as `fs/` mix Service Definitions, providers, and tools that evolve separately. The seam is already the unit the architecture uses, so it costs the least to maintain. -**Subpath export isolation for unstable APIs.** Making the import path the opt-in is a more explicit opt-in than a lint warning, but it restructures the exports of every package and breaks every current consumer at once, which contradicts incremental adoption. +**Subpath export isolation for unstable APIs.** Making the import path the opt-in is more explicit than a lint warning, but it restructures the exports of every package and breaks every current consumer at once, which contradicts incremental adoption. **Shipping a compatibility layer from the start.** Each retained old version needs its own conversion code and tests. Before any seam is stable and before external plugins depend on an old major, that cost buys nothing. -**Counting the deprecation period in releases.** DSH release frequency varies, so a release count gives plugin authors an unpredictable amount of time. A dated marker lets CI compute the period mechanically. +**Counting the deprecation period in releases.** DSH release frequency varies, so a release count gives plugin authors an unpredictable amount of time. Measuring time from the first release that recorded the deprecation is predictable and can be computed from archived reports. ## Acceptance criteria -- Root `AGENTS.md` states that unmarked APIs are unstable, and the deprecation period is defined. +- Root `AGENTS.md` and the package documentation listed in rollout step 1 state that unmarked APIs are unstable, and the deprecation period is defined. - A checked-in API report covers exports, services, and events; CI fails when it is stale. -- The agent seam is declared stable at version 1.0.0; CI rejects an incompatible signature change or an early removal of a deprecated member in it, and posts a stable API change summary on PRs that touch it. -- The lint rule reports a plugin's use of an unstable member. -- A plugin that declares `requires` is accepted or rejected per seam range; a plugin without it behaves as it does today. +- The pilot members of the agent seam carry `@stable agent@1.0.0`; CI rejects an incompatible change to them or to a type they reference, and posts a stable API change summary on PRs that touch them. +- The lint tool reports a plugin's use of an unstable member, including an unstable event name passed to `ctx.on()`. +- A plugin that declares `requires` is accepted or rejected per seam range in installation, update, and market discovery; a plugin without it behaves as it does today. ## Risks -- Seam membership of shared types is not always clear; a type used by two seams needs one owner before either seam is promoted. +- Referenced types from other seams join the promise of the referencing seam; promoting the agent seam therefore freezes parts of the session, scope, and llm types before those seams are promoted. - Behavior changes rely on author declarations, which review can miss. - Seam versions and the lockstep package version are two numbering systems, which plugin authors may confuse. - Promoting the agent seam constrains a core part of the loop that still changes often; promotion trades that flexibility for plugin stability. +- The lint tool is new published tooling that the project must maintain alongside the oxlint configuration. - The manifest declaration cannot stop a plugin from using undeclared APIs; it informs checks and users, not enforcement. diff --git a/.agents/notes/proposed/process/2026-11-05-stable-api-policy.zh.md b/.agents/notes/proposed/process/2026-11-05-stable-api-policy.zh.md index ab3c2ce022..64fc0c10d0 100644 --- a/.agents/notes/proposed/process/2026-11-05-stable-api-policy.zh.md +++ b/.agents/notes/proposed/process/2026-11-05-stable-api-policy.zh.md @@ -6,61 +6,64 @@ Status: proposed ## Problem -DSH 的所有公开 API 都是 pre-stable:根目录 `AGENTS.md` 要求 API 变化时同步更新每个消费方。这条规则在仓库内部可行,但外部插件现在从 npm 和插件市场安装,作者无法判断哪些 API 可以依赖。所有发布的包共用一个锁步版本,包版本无法说明哪个 API 变了。唯一的兼容检查是 [plugin-compatibility.ts](../../../../packages/boot/app-boot/src/plugin-compatibility.ts) 中的 `evaluatePluginCompatibility`,它把插件的 `engines.dsh` 或 `@deepseek-ai/dsh-*` peer 范围与整个运行时版本比较。 +DSH 的所有公开 API 都处于预稳定(pre-stable)阶段:根目录 `AGENTS.md` 要求 API 变化时同步更新每个消费方。这条规则在仓库内部可行,但外部插件现在从 npm 和插件市场安装,作者无法判断哪些 API 可以依赖。所有发布的包共用一个锁步版本,包版本无法说明哪个 API 变了。唯一的兼容检查是 [plugin-compatibility.ts](../../../../packages/boot/app-boot/src/plugin-compatibility.ts) 中的 `evaluatePluginCompatibility`,它把插件的 `engines.dsh` 范围(没有时改用 `@deepseek-ai/dsh` 和 `@deepseek-ai/dsh-*` peer 范围)与整个运行时版本比较;`workspace:` peer 范围视为当前运行版本。 -目前源码中没有任何稳定性标记。包导出不带 `@public`、`@beta`、`@stable` 或 `@since` 标签,`@deprecated` 也只出现约十几次。唯一严格的兼容规则针对数据格式([Session 格式状态](../../../../docs/session-format-status.zh.md)、SQLite schema 版本、持久化类型变更确认)和 [upgrade guide](../../../skills/dsh-create-upgrade-guide/SKILL.md)。 +源码中没有区分 stable 与 unstable API 的标记。导出不带 `@public`、`@beta`、`@stable` 或 `@since` 标签;`@internal` 出现约十次且含义不一,不带日期的 `@deprecated` 出现约十几次。唯一严格的兼容规则针对数据格式([Session 格式状态](../../../../docs/session-format-status.zh.md)、SQLite schema 版本、持久化类型变更确认)和 [upgrade guide](../../../skills/dsh-create-upgrade-guide/SKILL.md)。 规范必须从这一现状起步。贡献者不需要先给所有 API 定级,规范才能生效;没有人标记的代码保持现有工作方式。 ## Proposal -源码中的稳定性标记是唯一输入。生成的 API 报告把标记转换为每次发布的带版本稳定 API 列表。版本单位是[能力 seam](../../../../docs/glossary.zh.md#capability-seam)。未标记的内容一律保持 unstable,因此可以逐个 seam 推进。 +源码中的稳定性标记是唯一输入。生成的 API 报告把标记转换为每次发布的带版本稳定 API 列表。版本单位是[能力 seam](../../../../docs/glossary.zh.md#capability-seam)。未标记的内容一律保持 unstable,因此可以逐个成员推进。 ### 稳定级别 -| 级别 | 含义 | 变更规则 | +| 级别 | 标记 | 变更规则 | |---|---|---| -| internal | 标记为 `@internal`;仅在本仓库内部使用,不进入发布的 API 报告 | 随时修改并更新每个消费方 | -| unstable(默认) | 所有未带 stable 标记的公开导出、服务、事件和配置字段 | 随时修改,更新每个消费方,外部可感知的破坏性变更写入 upgrade guide | -| stable | 显式晋升,属于某个带版本的 seam API | 只允许向后兼容的新增;删除或不兼容修改需要先弃用,并升级 seam 主版本 | -| deprecated | 计划删除的 stable API | 自带日期的 `@deprecated` 标记起满弃用期后才能删除;须指明替代 API,或说明没有替代 | +| unstable(默认) | 无 | 随时修改,更新每个消费方,外部可感知的破坏性变更写入 upgrade guide | +| stable | `@stable @`,即加入该成员的 seam 版本 | 只允许向后兼容的新增;删除或不兼容修改需要弃用期已满,并升级 seam 主版本 | +| internal | `@internal` | 仅在本仓库内部使用;不进入 API 报告;随时修改 | -[`packages/experimental/`](../../../../packages/experimental/README.zh.md#status) 下的包不能包含 stable API;包须先移出 experimental 分组,其中的 API 才能晋升。 +弃用是 stable 成员的一种状态,不是第四个级别:带 `@deprecated <替代项或“无替代”>` 的成员在弃用期结束前仍是 stable。unstable 成员上的 `@internal` 和 `@deprecated` 标签保持现有含义;本规范不给现有标签赋予新含义。 + +[`packages/experimental/`](../../../../packages/experimental/README.zh.md#status) 下的包不能包含 stable 成员;包须先移出 experimental 分组,其中的成员才能晋升。 ### 单位:一个能力 seam -每个能力 seam 有自己的 API 版本,与锁步的包版本无关。一个 seam 的 API 包括它的 Service Definition、Service Definition 所在包声明的类型和事件、waterfall 调用约定,以及 Service Definition 所在包的配置字段。Service Provider 的配置字段跟随其所在 provider 包的级别。不属于任何 seam 的导出(如工具函数、CLI 选项、SDK wire 协议)保持 unstable,留待后续提案归属。 +每个能力 seam 有自己的 API 版本,与锁步的包版本无关。stable 成员属于声明它的 Service Definition 包所在的 seam;`Context`、`SessionEventMap` 等声明合并接口的成员属于添加该成员的包所在的 seam。不属于任何 seam 的导出(如工具函数、CLI 选项、SDK wire 协议)保持 unstable,留待后续提案归属。只能通过 `./src/*` 导出子路径访问的成员是 unstable。 -声明 Service Definition 的包在 manifest 中登记 seam。一个包可以声明多个 seam,因此该字段是列表: +声明 Service Definition 的包在现有的 `package.json` `dsh` 声明中登记 seam 版本,该声明由[公开包 manifest](../../implemented/architecture/2026-09-10-public-package-manifest.zh.md) 决策负责。一个包可以声明多个 seam,因此该成员是列表: ```json -{ "dsh": { "apis": [{ "name": "agent", "version": "1.0.0", "stability": "stable" }] } } +{ "dsh": { "manifestVersion": 1, "apis": [{ "name": "agent", "version": "1.0.0" }] } } ``` -字段名称和位置尚未确定。JSDoc 标签可以覆盖单个成员的 seam 级别:`@unstable` 让 stable seam 中的某个成员保持 unstable,`@deprecated YYYY-MM-DD <替代项或“无替代”>` 开始弃用期。`Context`、`SessionEventMap` 等声明合并接口的成员逐个标记。 +成员名称,以及是否需要新的 `manifestVersion`,尚未确定。按该决策的要求,报告生成器和兼容检查各自校验自己读取的成员。 ### stable 覆盖的范围 -stable 覆盖类型签名、事件顺序和 waterfall 调用约定(包括 listener 是否必须调用 `next()`),不覆盖默认配置值。CI 根据生成的报告检测签名变化。行为变化无法可靠地自动检测,由作者在 PR 中声明,做法与[持久化类型变更确认](../../../../docs/cookbook/reviewing-persistence-type-changes.zh.md)相同。这样可以避免把没有破坏调用方的变化报告为破坏性变更。 +stable 覆盖类型签名、事件顺序和 waterfall 调用约定(包括 listener 是否必须调用 `next()`)。本提案不覆盖默认配置值和配置字段。CI 根据生成的报告检测签名变化。行为变化无法可靠地自动检测;作者在 PR 描述中声明,由正常评审核对。锁定 stable 事件顺序和 waterfall 约定的测试属于 Service Definition 包,针对随产品发布的 Service Provider 运行。 + +stable 签名可以引用其他 seam 的类型,例如 `SessionId` 或 `Scoped`。这些被引用的类型成为引用方 seam 承诺的一部分:报告把它们列在该 seam 下,对它们的不兼容修改与修改该 seam 自身成员一样触发检查失败。 ### API 报告与 CI -一个脚本生成并提交一份 API 报告,覆盖导出、Cordis 服务和事件,每个条目带有所属 seam、级别和版本。已推迟的 [API extractor 报告](2026-06-11-api-extractor-reports.zh.md)提案即这份报告的第一阶段。CI 把 stable 条目与上一份报告比较,以下情况失败: +一个脚本生成并提交一份 API 报告,覆盖导出、Cordis 服务和事件,每个条目带有所属 seam、级别和版本;它取代已推迟的 [API extractor 报告](2026-06-11-api-extractor-reports.zh.md)提案中每个包一份的报告。每次发布归档当次报告。CI 把 stable 条目(包括被引用的类型)与最近一次发布的报告比较,以下情况失败: - stable 条目被删除或不兼容修改,但没有升级 seam 主版本并写 upgrade guide; -- 被删除的条目没有事先弃用,或弃用期未满; +- 被删除的条目没有在已发布的报告中标为弃用,或自首次记录该弃用的发布起弃用期未满; - 新增 stable 条目,但没有升级 seam 次版本; -- stable 签名引用了 unstable 类型。 +- stable 签名引用了标为 `@internal` 的成员,或本 seam 的 unstable 成员。 -unstable 条目的变化只出现在报告 diff 中,不会让 CI 失败。CI 还会在 PR 中发布 stable API 变更摘要。晋升和破坏性变更在正常 PR 评审中批准,不指定专门的 API owner 或委员会。 +从首次记录弃用的发布开始计算弃用期,使其不依赖作者填写的日期。unstable 条目的变化只出现在报告 diff 中,不会让 CI 失败。CI 还会在 PR 中发布 stable API 变更摘要。晋升和破坏性变更在正常 PR 评审中批准,不指定专门的 API owner 或委员会。 ### 插件作者告警 -一条类型感知的 lint 规则报告对 unstable API 的使用,工作方式与 [.oxlintrc.json](../../../../.oxlintrc.json) 已启用的 `typescript/no-deprecated` 相同:解析被调用的符号并读取其级别。插件作者在自己的构建中运行该规则;仓库对 stable 的 Service Definition 包运行该规则。子路径导出隔离(`…/unstable` 入口)已否决,见 [Alternatives considered](#alternatives-considered)。 +一条类型感知的 lint 规则报告对 unstable 成员的使用:解析每个被使用的符号,并从发布的类型声明中读取其级别。事件和 waterfall 名称是传给 `ctx.on()` 等调用的字符串字面量,因此规则要把它们与事件映射对应起来;[.oxlintrc.json](../../../../.oxlintrc.json) 中的 `typescript/no-deprecated` 不覆盖这种情况。oxlint 不支持自定义的类型感知规则,因此该规则以发布的工具形式提供,插件作者在自己的构建中运行;仓库对 stable 的 Service Definition 包运行该规则。子路径导出隔离(`…/unstable` 入口)已否决,见 [Alternatives considered](#alternatives-considered)。 ### 插件依赖声明 -插件可以声明所需的 seam 版本,例如 `"dsh": { "requires": { "agent": "^1.0.0" } }`;字段名称随 `apis` 的决定确定。声明该字段时,`evaluatePluginCompatibility` 把列出的每个 seam 范围与已安装的 seam 版本比较。按约定,插件还列出它使用的 unstable seam;Host 无法验证这份列表,插件管理页把它显示为风险。未声明时,现有的 `engines.dsh` 和 peer 范围检查保持不变,插件被视为依赖 unstable API。该声明不限制插件能导入或访问什么:Cordis 插件在 Host 进程内运行,可以导入任意包或访问 `ctx` 上的任意服务。 +插件可以声明所需的 seam 版本,例如 `"dsh": { "requires": { "agent": "^1.0.0" } }`。seam 检查是附加的:`evaluatePluginCompatibility` 仍然检查 `engines.dsh` 或 DSH peer 范围,同时把列出的每个 seam 范围与当前 Host 的 API 报告中记录的 seam 版本比较。声明了 seam 范围的插件可以把 `engines.dsh` 放宽到它支持的所有运行时。插件市场索引条目和 registry 更新检查读取同一声明,使发现、安装和更新得出相同结论。按约定,插件还列出它使用的 unstable seam;Host 无法验证这份列表,插件管理页把它显示为风险。该声明不限制插件能导入或访问什么:Cordis 插件在 Host 进程内运行,可以导入任意包或访问 `ctx` 上的任意服务。 ### 兼容层 @@ -68,47 +71,51 @@ unstable 条目的变化只出现在报告 diff 中,不会让 CI 失败。CI ### 落地步骤 -1. 仅规范:合入本 Agent Note,把根目录 `AGENTS.md` 的 pre-stable 规则改为“未标记的 API 为 unstable”,并确定弃用期。不改代码。 +1. 仅规范:合入本 Agent Note 并确定弃用期。把根目录 `AGENTS.md`、[packages/README.md](../../../../packages/README.zh.md)、[packages/experimental/README.md](../../../../packages/experimental/README.zh.md)、[apps/cli/reference/README.md](../../../../apps/cli/reference/README.zh.md) 以及由 [gen-plugin-packages.ts](../../../../scripts/gen-plugin-packages.ts) 生成的包参考中的预稳定表述改为“未标记的 API 为 unstable”。不改代码。 2. 基线报告:生成并提交第一份 API 报告;CI 只检查报告是否最新。 -3. 试点:晋升 agent seam。其 stable API 是 `dsh-agent` 中的 Service Definition:`ctx.agents`、`Agent` 句柄、`agent/*` 事件和 `agent/pre-step` waterfall。Service Provider `dsh-agent-loop` 保持 unstable。已弃用的 `agent/request` waterfall 补上带日期的标记,并注明其他单次请求控制项没有替代,用来演练弃用和删除检查。lint 规则和 `requires` 检查在这一阶段交付。 -4. 由各 seam 的维护者按需晋升更多 seam;在文档站发布稳定 API 列表。 +3. 试点:晋升 `dsh-agent` 声明的 agent seam 成员:`ctx.agents`、`AgentHandle`、`Agent`、除已弃用的 `agent/request` 之外的 `agent/*` 事件,以及 `agent/pre-step` waterfall。它们引用的 session、scope 和 llm 包类型按上文加入承诺。Service Provider `dsh-agent-loop` 及其配置保持 unstable,因此试点不稳定任何配置。lint 工具和 `requires` 检查在这一阶段交付;同时更新 [package-manifest README](../../../../packages/util/package-manifest/README.zh.md) 和公开包 manifest 决策记录,说明已强制执行的检查。 +4. 由各 seam 的维护者按需晋升更多成员和 seam;在文档站发布稳定 API 列表。 5. 满足上述条件时,为特定 seam 增加兼容适配插件。 ### 待决问题 -- manifest 字段 `dsh.apis` 和 `dsh.requires` 的名称与位置。 +- `dsh.apis` 和 `dsh.requires` 成员的名称,以及是否需要新的 `manifestVersion`。 - DSH 1.0 之前按时间计算的弃用期长度。 - Python SDK 方法、SDK JSON-RPC 协议和 `cordis.yml` 配置字段是否纳入同一套级别,以及协议是否需要独立版本。 - 报告生成方式:API Extractor,还是基于 [scripts/verify-export-jsdoc.ts](../../../../scripts/verify-export-jsdoc.ts) 的导出遍历和 [scripts/jsdoc.ts](../../../../scripts/jsdoc.ts) 的标签解析生成的转储。 +- lint 工具形式:基于同一导出遍历的独立发布检查器、非类型感知的近似实现,或上游 oxlint 规则。 ## Alternatives considered -**不带版本的 `@stable` 标记。** 成本最低且可渐进,但插件无法说明自己基于哪个稳定 API 构建,Host 也无法检查,弃用期没有计量单位。保留为输入格式,版本由生成的报告提供。 +**不带版本的 `@stable` 标记。** 成本最低且可渐进,但插件无法说明自己基于哪个稳定 API 构建,Host 也无法检查,报告也无法区分新增成员和已有成员。保留为输入格式,并附上加入该成员的 seam 版本;列表由生成的报告提供。 **每次发布手工维护带版本的列表。** 插件作者有明确的参考,但为一千多个导出子路径和一百多个服务手工维护不现实,而且整个列表只有一个版本,任何 seam 的破坏性变更都会波及所有插件。保留为生成的报告,而不是手工维护的产物。 **整个平台一个 API 版本**(Android API level、VS Code `engines`)。对插件作者最简单,但 DSH 发布频繁,各 seam 独立演进;单一版本号要么随每次破坏性变更增长,要么抑制必要的破坏性变更。 +**每个 npm 包独立 semver,取消锁步版本。** [npm 发布序列](../../implemented/process/2026-08-10-npm-release-sequences.zh.md)决策让所有 DSH 包使用同一版本,以保持发布和 peer 范围一致。包版本还会因不涉及任何插件所用 API 的内部重构而变化。seam 版本描述 API 兼容性,不改变包的发布方式。 + **按包目录而不是 seam 分组。** `fs/` 等分组混合了独立演进的 Service Definition、provider 和工具。seam 本来就是架构使用的单位,维护成本最低。 -**用子路径导出隔离 unstable API。** 让导入路径本身成为 opt-in,比 lint 告警更明确地要求 opt-in,但需要重组每个包的导出,并一次性破坏所有现有消费方,与渐进推进相矛盾。 +**用子路径导出隔离 unstable API。** 让导入路径本身成为 opt-in,比 lint 告警更明确,但需要重组每个包的导出,并一次性破坏所有现有消费方,与渐进推进相矛盾。 **一开始就提供兼容层。** 每保留一个旧版本,都需要单独的转换代码和测试。在任何 seam 稳定、且外部插件依赖旧主版本之前,这项成本没有收益。 -**按发布次数计算弃用期。** DSH 发布频率不固定,按次数计算给插件作者的时间不可预测。带日期的标记让 CI 可以机械地计算弃用期。 +**按发布次数计算弃用期。** DSH 发布频率不固定,按次数计算给插件作者的时间不可预测。从首次记录弃用的发布开始按时间计算,结果可预测,并且可以从归档的报告中算出。 ## Acceptance criteria -- 根目录 `AGENTS.md` 写明未标记的 API 为 unstable,且弃用期已确定。 +- 根目录 `AGENTS.md` 和落地步骤 1 列出的包文档写明未标记的 API 为 unstable,且弃用期已确定。 - 已提交的 API 报告覆盖导出、服务和事件;报告过期时 CI 失败。 -- agent seam 以 1.0.0 版本声明为 stable;CI 拒绝其中不兼容的签名变化或提前删除已弃用成员,并在涉及它的 PR 中发布 stable API 变更摘要。 -- lint 规则报告插件对 unstable 成员的使用。 -- 声明了 `requires` 的插件按 seam 范围被接受或拒绝;未声明的插件行为与现在相同。 +- agent seam 的试点成员带有 `@stable agent@1.0.0`;CI 拒绝对它们或它们引用的类型的不兼容修改,并在涉及它们的 PR 中发布 stable API 变更摘要。 +- lint 工具报告插件对 unstable 成员的使用,包括传给 `ctx.on()` 的 unstable 事件名。 +- 声明了 `requires` 的插件在安装、更新和市场发现中按 seam 范围被接受或拒绝;未声明的插件行为与现在相同。 ## Risks -- 共享类型属于哪个 seam 并不总是明确;被两个 seam 使用的类型须在任一 seam 晋升前确定唯一归属。 +- 其他 seam 中被引用的类型会加入引用方 seam 的承诺;晋升 agent seam 因而会在 session、scope 和 llm 等 seam 晋升之前冻结其部分类型。 - 行为变化依赖作者声明,评审可能遗漏。 - seam 版本与锁步包版本是两套编号,插件作者可能混淆。 - 晋升 agent seam 会约束仍在频繁变化的 loop 核心部分;晋升以这部分灵活性换取插件稳定性。 +- lint 工具是新的发布工具,项目需要与 oxlint 配置一起维护。 - manifest 声明无法阻止插件使用未声明的 API;它只为检查和用户提供信息,不是强制手段。