Merge commit 'refs/codex/pr885/master-20260730' into worktree/retarget-pr885-20260729
# Conflicts: # eslint.config.mjs
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write
|
||||
2026-07-27-compiler-independent-typert-model.md: 338476924dfb5d9832d0b64bf01b8d3c297cd6d6
|
||||
2026-07-27-compiler-independent-typert-model.zh.md: a88f4dbba50696071552ea12a63b69ecac202418
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
# Agent Note: Compiler-independent Typert type model
|
||||
|
||||
Status: implemented
|
||||
|
||||
English | [中文](2026-07-27-compiler-independent-typert-model.zh.md)
|
||||
|
||||
## Problem
|
||||
|
||||
Constructing Zod and reflection text directly from the TypeScript AST couples type analysis and business-semantic recognition to a single generation target. Such a generator can answer only “can this syntax be generated?” It cannot provide a canonical representation of packages, faces, public exports, services, events, objects, and their type relationships, nor can static checks and later generation targets reuse it.
|
||||
|
||||
The host and client are independent TypeScript projects; placing both in one `ts.Program` merges conflicting Cordis `Context` and `Events` declarations. At the same time, client types still need to reference host types explicitly, so neither complete isolation nor duplicating types on both sides can express the actual dependencies.
|
||||
|
||||
## Decision
|
||||
|
||||
[`dsh-typert-generator`](../../../../packages/typert/generator/README.md) builds separate `ts.Program` instances from the host and client projects and uses compiler nodes, symbols, and checkers only as extraction tools. After analysis, every generator and scanner consumes only Typert's own `WorkspaceModel`, `FaceModel`, and `TypeGraph`; the model retains no AST or checker objects. The generator has no dependency on `@deepseek-ai/dsh-typert-registry`.
|
||||
|
||||
TypeGraph preserves the developer-authored, pre-evaluation type structure, including generic parameters and applications, explicit inheritance, conditional and mapped types, recursive references, and JSDoc. A reachable type that cannot be represented losslessly causes analysis to fail. If an emitter cannot handle an already modeled node, that emitter fails instead of flattening the type or degrading it to `unknown`.
|
||||
|
||||
Each face independently owns a PackageModel and TypeGraph. Direct project references from `tsconfig.host.json` and `tsconfig.client.json` determine a package's face membership, while `package.json#exports` defines its public boundary. Cross-face relationships come only from explicit imports or re-exports in source and remain separate links; external npm types are recorded as External without reading or copying their declarations.
|
||||
|
||||
PackageModel recognizes Cordis services, events, `@typert object` reference objects, and `@typert schema` data roots. Services and objects expose only public instance members, excluding constructors and static, private, and protected members; inheritance edges remain in TypeGraph instead of being copied into flattened members. When a public property, parameter, or return type lacks an annotation, `check` mode reports an error, while `write` mode writes the checker-inferred result, rebuilds the project, and analyzes it again in strict mode.
|
||||
|
||||
[`dsh-typert-registry`](../../../../packages/typert/registry/README.md) provides `ctx.typert` and handles runtime registration only: one contribution atomically carries package-face reflection and an optional Zod schema, and Cordis effect disposal revokes it. The registry neither analyzes TypeScript nor merges the two faces. JSON Schema is an on-demand projection of registered Zod schemas.
|
||||
|
||||
Package artifact publication is explicit opt-in. When invoked, `WorkspaceTypertGenerator` validates that each requested host face exposes the user-facing subpath `package/typert` from the root artifact `package/lib/typert.host.{js,d.ts}`, or that each requested client face exposes `package/client/typert` from `package/lib/typert.client.{js,d.ts}`. It neither edits exports nor runs as part of the ordinary root build or typecheck, so those commands do not generate whole-workspace Typert artifacts. Generated declarations keep `TYPERT` typed as `unknown`, so business packages do not depend on the registry.
|
||||
|
||||
At build time, `CordisCatalogProjector` consumes the analyzed `FaceModel` and `TypeGraph` once to generate `docs/cordis-catalog/events.md`, `docs/cordis-catalog/services.md`, and the static `SERVICE_API`, `EVENT_API`, and `TYPE_API` catalog committed for `tool-cordis`. `tool-cordis` reads that static catalog and has no runtime dependency on `ctx.typert`. [`dsh-typert-loader`](../../../../packages/typert/loader/README.md) and the registry remain an independent runtime path: the loader follows Cordis Loader entry lifecycle events, imports an explicitly published `./typert` host artifact, and registers it through `ctx.typert`; neither component supplies the current `cordis_inspect` catalog.
|
||||
|
||||
## Verification contract
|
||||
|
||||
A small two-face project in the repository snapshots the complete type model, including its source declaration index. Batched workspace analysis and direct focused analysis must produce model-equivalent `FaceModel` and `TypeGraph` results for the same faces. Compile-time exhaustive maps and runtime set comparisons ensure that every node, target, declaration, and member discriminant is exercised by source-authored TypeScript syntax; a field-semantics matrix covers every keyword, type operator, and literal value category, plus every state of generics, parameters, tuples, mapped modifiers, import attributes, abstract forms, predicates, and enum initializers.
|
||||
|
||||
For every property in `SyntaxZoo`, the TypeScript printer normalizes the source type, which must exactly match the TypeGraph rendering; TypeScript then recompiles every rendered declaration. This layer checks that each node's internal information is preserved losslessly, including no-substitution template literals, type queries with type arguments, and constrained `infer`, without substituting discriminant coverage or code coverage for structural equivalence.
|
||||
|
||||
Boundary cases pin explicit package imports within and across faces, cross-face named re-exports, exact export aliases, qualified `import()` links, and the External classification of global `@types` declarations; they reject TypeScript diagnostics originating in package-owned files, relative-path boundary crossings, references outside `package.json#exports`, and cross-face namespace re-exports without a model target. Interface declaration merging explicitly preserves every authored part; other merges that cannot be represented losslessly fail.
|
||||
|
||||
For each supported node kind and literal category, Zod emitter tests run both successful and failing parses; for each unsupported kind, they assert an explicit `TypertEmitError`. Emitter fixtures snapshot generated Zod JavaScript and `.d.ts` text, execute the JavaScript, and typecheck the declarations. `dsh-typert-registry` tests pin atomic registration, queries, JSON Schema, and effect disposal; `dsh-typert-loader` tests also prove delayed mounting, unloading, and disposal while a dynamic import remains pending. A real `dsh-tools` vertical slice generates a contribution from the model, loads it through the runtime registry, and compares its service, event, and related-type records with the committed static `SERVICE_API`, `EVENT_API`, and `TYPE_API`. A full-workspace projector test regenerates the two Cordis catalog documents and the `tool-cordis` API catalog and requires all three texts to be byte-for-byte identical to the committed artifacts.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
**Retain the TypeScript AST directly.** The AST preserves source syntax, but it would make every consumer depend on the compiler lifecycle, node identity, and checker context, preventing a stable architectural boundary. It is therefore used only during extraction.
|
||||
|
||||
**Generate final types from the checker.** A flattened `ts.Type` is easy to traverse directly, but it loses the developer's expression of generics, conditional and mapped types, and alias applications, so it cannot support reflection and later generation needs.
|
||||
|
||||
**Merge the host/client projects or duplicate host types.** Merging would contaminate Cordis declaration merging; duplication would create a second source of truth for types. Independent faces with explicit cross-face links preserve project isolation and actual reference relationships.
|
||||
|
||||
**Make `dsh-typert-registry` responsible for type resolution and cross-package composition.** That would recouple the TypeScript compiler, Cordis lifecycle, and a specific schema policy. The registry remains a lifecycle container for generated artifacts, while the build-time model retains complex analysis.
|
||||
|
||||
## Consequences
|
||||
|
||||
New generation targets and static checks can reuse the same TypeGraph, and business categories can extend PackageModel without parsing the AST again. Preserving pre-evaluation types and independent faces makes the model more complex than a flattened schema; emitters must explicitly declare their supported scope and fail on missing capabilities.
|
||||
|
||||
Explicit opt-in keeps artifact publication and package exports under package ownership, while ordinary root builds and typechecks incur no whole-workspace Typert generation phase. The static Cordis catalogs remain reproducible from the canonical model without coupling `tool-cordis` to runtime registry state. `ctx.typert` reflects only artifacts mounted in the current runtime, and unloading does not control Zod instances that consumers retain after importing them directly.
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
# Agent Note: 编译器无关的 Typert 类型模型
|
||||
|
||||
Status: implemented
|
||||
|
||||
[English](2026-07-27-compiler-independent-typert-model.md) | 中文
|
||||
|
||||
## Problem
|
||||
|
||||
直接从 TypeScript AST 拼接 Zod 和反射文本,会把类型分析、业务语义识别与单个生成目标绑在一起。这样的生成器只能回答“这段语法能否生成”,无法提供包、face、公开导出、service、event、对象及其类型关系的标准表示,也无法供静态检查和后续生成目标复用。
|
||||
|
||||
host 与 client 属于独立 TypeScript project;把两者放进同一个 `ts.Program` 会合并冲突的 Cordis `Context` 与 `Events` 声明。与此同时,client 类型仍需显式引用 host 类型,因此完全隔离或在两边复制类型都不能表达真实依赖。
|
||||
|
||||
## Decision
|
||||
|
||||
[`dsh-typert-generator`](../../../../packages/typert/generator/README.md) 分别从 host 和 client project 建立 `ts.Program`,只把 compiler node、symbol 和 checker 当作提取工具。分析结束后,所有生成器和扫描器只消费 Typert 自有的 `WorkspaceModel`、`FaceModel` 与 `TypeGraph`,模型中不保留 AST 或 checker 对象。生成器不依赖 `@deepseek-ai/dsh-typert-registry`。
|
||||
|
||||
TypeGraph 保存开发者写下的计算前类型结构,包括泛型参数与应用、显式继承、conditional、mapped、递归引用和 JSDoc。无法无损表示的可达类型使分析失败;某个 emitter 无法处理已经建模的节点时由该 emitter 失败,而不是把类型展平或降级为 `unknown`。
|
||||
|
||||
每个 face 独立拥有 PackageModel 和 TypeGraph。`tsconfig.host.json` 与 `tsconfig.client.json` 的直接 project references 决定 package 的 face 归属,`package.json#exports` 决定公开边界。跨 face 关系只来自源码中的显式 import 或 re-export,并作为独立 link 保留;外部 npm 类型记录为 External,不读取或复制其声明。
|
||||
|
||||
PackageModel 识别 Cordis service、event、`@typert object` 引用对象和 `@typert schema` 数据根。service 与 object 只暴露 public instance member,排除 constructor、static、private 和 protected;继承边保留在 TypeGraph 中,不复制为扁平成员。缺少 public property、parameter 或 return 类型标注时,`check` 模式报错,`write` 模式写入 checker 推断结果后重建 project 并再次以严格模式分析。
|
||||
|
||||
[`dsh-typert-registry`](../../../../packages/typert/registry/README.md) 提供 `ctx.typert`,且只负责运行时注册:一个 contribution 原子携带 package-face reflection 与可选 Zod schema,并随 Cordis effect 撤销。注册表不分析 TypeScript,也不合并两个 face。JSON Schema 是对已注册 Zod schema 的按需投影。
|
||||
|
||||
包产物发布采用显式 opt-in。`WorkspaceTypertGenerator` 仅在被调用时校验所请求 face 的根目录产物协议:host face 必须通过面向用户的 subpath `package/typert` 暴露 `package/lib/typert.host.{js,d.ts}`,client face 必须通过 `package/client/typert` 暴露 `package/lib/typert.client.{js,d.ts}`。它既不修改 exports,也不作为根目录普通 build 或 typecheck 的一部分运行,因此这些命令不会生成全仓 Typert 产物。生成的声明将 `TYPERT` 类型保持为 `unknown`,因此业务包不依赖注册表。
|
||||
|
||||
构建期的 `CordisCatalogProjector` 一次消费分析后的 `FaceModel` 与 `TypeGraph`,生成 `docs/cordis-catalog/events.md`、`docs/cordis-catalog/services.md`,以及为 `tool-cordis` 提交的静态 `SERVICE_API`、`EVENT_API` 和 `TYPE_API` catalog。`tool-cordis` 读取该静态 catalog,运行时不依赖 `ctx.typert`。[`dsh-typert-loader`](../../../../packages/typert/loader/README.md) 与注册表仍是独立的运行时路径:loader 监听 Cordis Loader 配置项生命周期事件,导入显式发布的 `./typert` host 产物,并通过 `ctx.typert` 注册;两者都不是当前 `cordis_inspect` catalog 的数据源。
|
||||
|
||||
## Verification contract
|
||||
|
||||
提交内的小型双 face project 对完整类型模型及其源码声明索引做 snapshot。全仓分批分析与直接聚焦分析必须为相同 face 生成模型等价的 `FaceModel` 与 `TypeGraph`。类型级全集和运行时集合比较保证每种 node、target、declaration 与 member discriminant 都来自真实 TypeScript syntax;字段语义矩阵覆盖所有 keyword、type operator、literal value 类目,以及泛型、参数、tuple、mapped modifier、import attributes、abstract、predicate 和 enum initializer 的各个状态。
|
||||
|
||||
`SyntaxZoo` 中每个 property 的源码类型经 TypeScript printer 标准化后,必须与 TypeGraph 渲染结果逐项相等,随后所有渲染 declaration 再交给 TypeScript 编译。这一层检查节点内部信息是否无损,包括无插值 template literal、带 type argument 的 type query 和受约束 `infer`,不以 discriminant 覆盖或代码覆盖率代替结构等价。
|
||||
|
||||
边界用例固定同 face 与跨 face 的显式包导入、跨 face 命名 re-export、精确 export alias、qualified `import()` link 和全局 `@types` External 归属,并拒绝 package 自有 TypeScript 诊断、相对路径越界、`package.json#exports` 之外的引用,以及尚无模型 target 的跨 face namespace re-export。interface declaration merging 显式保留每个 authored part,无法无损表示的其他 merge 失败。
|
||||
|
||||
Zod emitter 对支持的节点和各类 literal 逐类执行成功与失败 parse,对不支持的节点逐类断言明确的 `TypertEmitError`。Emitter fixture 对生成的 Zod JavaScript 与 `.d.ts` 文本做快照,执行 JavaScript,并对声明做类型检查。`dsh-typert-registry` 测试固定原子注册、查询、JSON Schema 和 effect 撤销,`dsh-typert-loader` 测试还证明延迟挂载、卸载及未完成 dynamic import 的释放行为。真实 `dsh-tools` 纵切从模型生成 contribution,经运行时注册表加载后,将其服务、事件与关联类型记录同已提交的静态 `SERVICE_API`、`EVENT_API` 和 `TYPE_API` 对照。全仓 projector 测试重新生成两份 Cordis catalog 文档与 `tool-cordis` API catalog,并要求三份文本同已提交产物逐字节一致。
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
**直接保存 TypeScript AST。** AST 能保留源码写法,但会让每个消费者依赖 compiler 生命周期、node identity 和 checker 上下文,无法形成稳定的架构边界,因此只在提取阶段使用。
|
||||
|
||||
**基于 checker 的最终类型生成。** 展平后的 `ts.Type` 便于直接遍历,却丢失泛型、conditional、mapped 和 alias application 的开发者表达,无法满足反射与后续生成需要。
|
||||
|
||||
**合并 host/client project 或复制 host 类型。** 合并会污染 Cordis declaration merging;复制会产生第二份类型事实源。独立 face 加显式 cross-face link 保留了 project 隔离与真实引用关系。
|
||||
|
||||
**让 `dsh-typert-registry` 承担类型解析和跨包合成。** 这会把 TypeScript compiler、Cordis 生命周期和具体 schema 策略重新耦合。注册表保持为生成 artifact 的生命周期容器,复杂分析留在构建期模型。
|
||||
|
||||
## Consequences
|
||||
|
||||
新增生成目标或静态检查可复用同一 TypeGraph,业务类目也可在 PackageModel 上扩展,而无需再次解析 AST。保留计算前类型和独立 face 的代价是模型比打平后的 schema 更复杂,emitter 必须显式声明支持范围并对缺失能力失败。
|
||||
|
||||
显式 opt-in 使产物发布与 package exports 由各包自行管理,根目录普通 build 和 typecheck 不会引入全仓 Typert 生成阶段。静态 Cordis catalog 可从标准模型复现,同时不把 `tool-cordis` 与运行时注册表状态耦合。`ctx.typert` 只反映当前运行时中已挂载的产物;对于消费方直接导入后仍持有的 Zod 实例,卸载流程无法控制。
|
||||
@@ -36,3 +36,4 @@ apps/web/dist/
|
||||
.worktrees/
|
||||
worktrees/
|
||||
.agents/worktrees/
|
||||
.typert-*/
|
||||
@@ -20,6 +20,7 @@
|
||||
"**/.node-next-types-*/**",
|
||||
"**/.oxlint-contract-*/**", // Scratch files created by the executable lint-contract tests.
|
||||
"**/oxlint-contract-*", // Flat probes use real TypeScript project include paths.
|
||||
"packages/typert/generator/tests/fixtures/type-model/**", // tsgolint rejects this fixture's preserved project shapes before rules run.
|
||||
"website/.generated/**",
|
||||
"vendor/**", // Vendored source keeps upstream style and idioms.
|
||||
"native/**", // The imported landlock-run subtree has its own gates; see native/README.md.
|
||||
|
||||
@@ -12,6 +12,7 @@ DeepSeek Harness SDK is a plugin-based agent harness on vendored Cordis: **every
|
||||
vendor/ Vendored Cordis source — manifest + sync procedure in vendor/README.md
|
||||
packages/ @deepseek-ai/dsh-<pkg> workspaces at packages/<group>/<pkg>/
|
||||
core/ product API spine: session, system-prompt, tools, agent, agent-loop
|
||||
typert/ type graph generator, loader, and runtime registry
|
||||
llm/ LLM seam + DeepSeek adapters (direct-fetch + pi-ai design twin)
|
||||
bash/ bash executor seam + local impl + model-facing bash tools
|
||||
subprocess/ subprocess seam + local process-tree impl
|
||||
|
||||
+43
-56
@@ -1,6 +1,15 @@
|
||||
// @vitest-environment jsdom
|
||||
// Session row actions in the assembled fixture app: Rename opens the
|
||||
// browser-owned dialog and settles the title from the unary response.
|
||||
// The built-bundle boot smoke: the ONE assembled-jsdom test that loads the
|
||||
// real `packages/client/*/lib/client.js` artifacts through AppWebEntry's
|
||||
// ModuleLoader path (fetchBundle/executeBundle) and proves the boot graph
|
||||
// assembles — staged activation across the immediately tier and the inject
|
||||
// layers, per-plugin CSS injection, and a rendered journey reaching chat
|
||||
// content from the keyless FixtureApiClient transport.
|
||||
//
|
||||
// Behavior assertions do NOT belong here: component and wiring behavior is
|
||||
// pinned by the per-package suites (SlotTestRuntime benches over src), which
|
||||
// this smoke's plugin set cannot influence — bundling, module-table
|
||||
// resolution, and boot layering are the only failure modes left to it.
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { act, cleanup, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||
@@ -16,9 +25,18 @@ const PLUGINS: readonly (WebBootEntry & { dir: string })[] = [
|
||||
{ id: '@deepseek-ai/dsh-client-ui-layout', dir: 'ui-layout', url: '/plugins/ui-layout.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-sidebar', dir: 'ui-sidebar', url: '/plugins/ui-sidebar.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-conversation', dir: 'ui-conversation', url: '/plugins/ui-conversation.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-slash', dir: 'ui-slash', url: '/plugins/ui-slash.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime', '@deepseek-ai/dsh-client-ui-conversation'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-command', dir: 'ui-command', url: '/plugins/ui-command.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-slash', '@deepseek-ai/dsh-client-ui-conversation'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-workspace', dir: 'ui-workspace', url: '/plugins/ui-workspace.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime', '@deepseek-ai/dsh-client-ui-conversation', '@deepseek-ai/dsh-client-ui-sidebar'] },
|
||||
{
|
||||
id: '@deepseek-ai/dsh-client-ui-workspace',
|
||||
dir: 'ui-workspace',
|
||||
url: '/plugins/ui-workspace.js',
|
||||
rev: 'fx',
|
||||
inject: [
|
||||
'@deepseek-ai/dsh-client-runtime',
|
||||
'@deepseek-ai/dsh-client-ui-conversation',
|
||||
'@deepseek-ai/dsh-client-ui-sidebar',
|
||||
],
|
||||
},
|
||||
{ id: '@deepseek-ai/dsh-client-ui-trajectory', dir: 'ui-trajectory', url: '/plugins/ui-trajectory.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-conversation'] },
|
||||
]
|
||||
|
||||
const bundles = new Map(PLUGINS.map(plugin => [
|
||||
@@ -42,16 +60,11 @@ let unmount: (() => void) | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
history.replaceState(null, '', '/?fixture')
|
||||
document.title = 'DeepSeek Harness'
|
||||
const root = document.createElement('div')
|
||||
root.id = 'root'
|
||||
document.body.appendChild(root)
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) =>
|
||||
setTimeout(() => { callback(0) }, 0) as unknown as number)
|
||||
vi.stubGlobal('cancelAnimationFrame', (id: number) => { clearTimeout(id) })
|
||||
win.__DSH_BOOT__ = { rev: 'fx', entries: PLUGINS.map(({ dir: _dir, ...plugin }) => plugin) }
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@@ -60,7 +73,6 @@ afterEach(() => {
|
||||
cleanup()
|
||||
delete win.__DSH_BOOT__
|
||||
delete win.__ModuleLoader__
|
||||
delete (globalThis as Record<string, unknown>).__fxTiming
|
||||
document.body.innerHTML = ''
|
||||
document.head.querySelectorAll('style[data-plugin]').forEach((style) => { style.remove() })
|
||||
document.title = ''
|
||||
@@ -68,9 +80,12 @@ afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
async function bootApp(): Promise<void> {
|
||||
const root = document.querySelector<HTMLElement>('#root')
|
||||
if (root === null) throw new Error('snapshot root missing')
|
||||
it('boots the built plugin graph and renders a fixture session end to end', async () => {
|
||||
history.replaceState(null, '', '/?fixture')
|
||||
const root = document.createElement('div')
|
||||
root.id = 'root'
|
||||
document.body.appendChild(root)
|
||||
win.__DSH_BOOT__ = { rev: 'fx', entries: PLUGINS.map(({ dir: _dir, ...plugin }) => plugin) }
|
||||
act(() => {
|
||||
const entry = new AppWebEntry(root, {
|
||||
fetchBundle: (url) => {
|
||||
@@ -82,49 +97,21 @@ async function bootApp(): Promise<void> {
|
||||
void entry.run()
|
||||
unmount = () => { entry.dispose() }
|
||||
})
|
||||
await screen.findByRole('tree', { name: 'Sessions' }, { timeout: 10_000 })
|
||||
}
|
||||
|
||||
/** The session row element carrying the given visible label. */
|
||||
function rowOf(label: string): HTMLElement {
|
||||
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
||||
const row = within(tree).getByText(label).closest<HTMLElement>('[role="treeitem"]')
|
||||
if (row === null) throw new Error(`session row "${label}" missing`)
|
||||
return row
|
||||
}
|
||||
// The sidebar renders from the boot graph: every inject layer activated.
|
||||
const tree = await screen.findByRole('tree', { name: 'Sessions' }, { timeout: 10_000 })
|
||||
await within(tree).findByText('4 sessions')
|
||||
|
||||
/** Open the row's ... menu and click one action. The anchor button is
|
||||
* CSS-hover-revealed (real stylesheets are injected in this assembled run,
|
||||
* so role queries filter it as hidden); target it directly. */
|
||||
function pickRowAction(label: string, action: string): void {
|
||||
const anchor = rowOf(label).querySelector<HTMLElement>(`button[aria-label="Session actions for ${label}"]`)
|
||||
if (anchor === null) throw new Error(`row menu anchor for "${label}" missing`)
|
||||
fireEvent.click(anchor)
|
||||
fireEvent.click(screen.getByRole('menuitem', { name: action, hidden: true }))
|
||||
}
|
||||
// Opening a session reaches chat content through the fixture transport.
|
||||
fireEvent.click(await within(tree).findByText('Fixture 历史会话'))
|
||||
await waitFor(() => {
|
||||
expect(document.querySelector('[data-sample="bash-global"]')).not.toBeNull()
|
||||
}, { timeout: 10_000 })
|
||||
|
||||
it('renames a session through the row-menu dialog; the row settles from the unary response', async () => {
|
||||
await bootApp()
|
||||
const sourceLabel = 'Fixture 历史会话'
|
||||
await screen.findByText(sourceLabel)
|
||||
|
||||
pickRowAction(sourceLabel, 'Rename')
|
||||
const input = await screen.findByLabelText('Session name')
|
||||
expect((input as HTMLInputElement).value).toBe(sourceLabel)
|
||||
fireEvent.change(input, { target: { value: ' 分叉 实验记录 ' } })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
|
||||
// Host-side normalization collapses whitespace; the dialog closes on
|
||||
// acceptance and the row re-labels without any push-frame wait.
|
||||
const renamed = '分叉 实验记录'
|
||||
await waitFor(() => { expect(screen.queryByLabelText('Session name')).toBeNull() })
|
||||
await screen.findByText(renamed)
|
||||
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
||||
expect(within(tree).queryByText(sourceLabel)).toBeNull()
|
||||
|
||||
const rows = [...tree.querySelectorAll('[role="treeitem"]')].map(row => ({
|
||||
label: row.textContent?.replace(/\s+/g, ' ').trim() ?? '',
|
||||
}))
|
||||
await expect(`${JSON.stringify(rows, null, 2)}\n`)
|
||||
.toMatchFileSnapshot('./snapshots/session-actions/rename-rows.json')
|
||||
// Every bundle injected its plugin-owned style tag (the loader's CSS path).
|
||||
const styleOwners = [...document.head.querySelectorAll('style[data-plugin]')]
|
||||
.map(style => style.getAttribute('data-plugin'))
|
||||
for (const plugin of ['@deepseek-ai/dsh-client-ui-layout', '@deepseek-ai/dsh-client-ui-sidebar', '@deepseek-ai/dsh-client-ui-conversation']) {
|
||||
expect(styleOwners).toContain(plugin)
|
||||
}
|
||||
})
|
||||
@@ -1,239 +0,0 @@
|
||||
// @vitest-environment jsdom
|
||||
// Code Mode fixture snapshot over the BUILT client graph (the workspace-flow
|
||||
// idiom: real bundles via AppWebEntry, keyless FixtureApiClient transport).
|
||||
// Opens the fixture history session and pins the run_code turn's rendering:
|
||||
// the code-variant parent row titled by the model-authored description, its
|
||||
// three always-visible nested sub-rows (bash through the sample registration,
|
||||
// read through GenericToolCard, the failing read wearing the error state),
|
||||
// the expanded program body, inert bash / file-link sub-row gestures,
|
||||
// details-panel resolution of a sub-callId, and the Trajectory tab's sub-call
|
||||
// cells and timing overview.
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { act, cleanup, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import type { WebBootEntry } from '@deepseek-ai/dsh-client-modules/client'
|
||||
import { AppWebEntry } from '@deepseek-ai/dsh-client-web'
|
||||
|
||||
const PLUGINS: readonly (WebBootEntry & { dir: string })[] = [
|
||||
{ id: '@deepseek-ai/dsh-client-connection', dir: 'connection', url: '/plugins/connection.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-runtime', dir: 'runtime', url: '/plugins/runtime.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-connection'], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-theme', dir: 'ui-theme', url: '/plugins/ui-theme.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-locale', dir: 'locale', url: '/plugins/locale.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-layout', dir: 'ui-layout', url: '/plugins/ui-layout.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-sidebar', dir: 'ui-sidebar', url: '/plugins/ui-sidebar.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-conversation', dir: 'ui-conversation', url: '/plugins/ui-conversation.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{
|
||||
id: '@deepseek-ai/dsh-client-ui-workspace',
|
||||
dir: 'ui-workspace',
|
||||
url: '/plugins/ui-workspace.js',
|
||||
rev: 'fx',
|
||||
inject: [
|
||||
'@deepseek-ai/dsh-client-runtime',
|
||||
'@deepseek-ai/dsh-client-ui-conversation',
|
||||
'@deepseek-ai/dsh-client-ui-sidebar',
|
||||
],
|
||||
},
|
||||
{ id: '@deepseek-ai/dsh-client-ui-trajectory', dir: 'ui-trajectory', url: '/plugins/ui-trajectory.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-conversation'] },
|
||||
]
|
||||
|
||||
const bundles = new Map(PLUGINS.map(plugin => [
|
||||
plugin.url,
|
||||
readFileSync(join(process.cwd(), 'packages/client', plugin.dir, 'lib/client.js'), 'utf8'),
|
||||
]))
|
||||
|
||||
interface FixtureWindow extends Window {
|
||||
__DSH_BOOT__?: { rev: string; entries: WebBootEntry[] }
|
||||
__ModuleLoader__?: unknown
|
||||
}
|
||||
|
||||
class ResizeObserverStub {
|
||||
observe(): void {}
|
||||
disconnect(): void {}
|
||||
unobserve(): void {}
|
||||
}
|
||||
|
||||
const win = window as FixtureWindow
|
||||
let unmount: (() => void) | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
document.title = 'DeepSeek Harness'
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) =>
|
||||
setTimeout(() => { callback(0) }, 0) as unknown as number)
|
||||
vi.stubGlobal('cancelAnimationFrame', (id: number) => { clearTimeout(id) })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
act(() => { unmount?.() })
|
||||
unmount = undefined
|
||||
cleanup()
|
||||
delete win.__DSH_BOOT__
|
||||
delete win.__ModuleLoader__
|
||||
delete (globalThis as Record<string, unknown>).__fxTiming
|
||||
document.body.innerHTML = ''
|
||||
document.head.querySelectorAll('style[data-plugin]').forEach((style) => { style.remove() })
|
||||
document.title = ''
|
||||
history.replaceState(null, '', '/')
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
/** Boot the complete built client graph against the populated fixture branch. */
|
||||
function boot(): void {
|
||||
history.replaceState(null, '', '/?fixture')
|
||||
const root = document.createElement('div')
|
||||
root.id = 'root'
|
||||
document.body.appendChild(root)
|
||||
win.__DSH_BOOT__ = { rev: 'fx', entries: PLUGINS.map(({ dir: _dir, ...plugin }) => plugin) }
|
||||
act(() => {
|
||||
const entry = new AppWebEntry(root, {
|
||||
fetchBundle: (url) => {
|
||||
const code = bundles.get(url)
|
||||
return code === undefined ? Promise.reject(new Error(`missing built bundle ${url}`)) : Promise.resolve(code)
|
||||
},
|
||||
executeBundle: (code) => { (0, eval)(code) },
|
||||
})
|
||||
void entry.run()
|
||||
unmount = () => { entry.dispose() }
|
||||
})
|
||||
}
|
||||
|
||||
/** Collapse decorative whitespace while preserving the text a user sees. */
|
||||
function visibleText(element: Element): string {
|
||||
return (element.textContent ?? '').replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
|
||||
/** Open the fixture history session (the alpha log carrying the run_code turn) and scroll to its tail. */
|
||||
async function openFixtureSession(): Promise<void> {
|
||||
const tree = await screen.findByRole('tree', { name: 'Sessions' }, { timeout: 10_000 })
|
||||
const group = within(tree).getByText('4 sessions').closest<HTMLElement>('[role="treeitem"]')
|
||||
if (group === null) throw new Error('fixture Workspace group missing')
|
||||
if (group.getAttribute('aria-expanded') === 'false') {
|
||||
fireEvent.click(within(group).getByText('fixture'))
|
||||
await waitFor(() => {
|
||||
expect(within(tree).getByText('4 sessions').closest('[role="treeitem"]')?.getAttribute('aria-expanded')).toBe('true')
|
||||
})
|
||||
}
|
||||
const session = await within(tree).findByText('Fixture 历史会话')
|
||||
fireEvent.click(session)
|
||||
await waitFor(() => {
|
||||
expect(document.querySelector('[data-variant="code"]')).not.toBeNull()
|
||||
}, { timeout: 10_000 })
|
||||
}
|
||||
|
||||
it('renders the fixture run_code turn: code parent row, nested sub-rows, error state', async () => {
|
||||
boot()
|
||||
await openFixtureSession()
|
||||
|
||||
const codeRoot = document.querySelector('[data-variant="code"]')
|
||||
if (codeRoot === null) throw new Error('code-variant row missing')
|
||||
const nest = codeRoot.closest('[class*="callRow"]')?.querySelector('[data-subcalls]')
|
||||
if (nest === undefined || nest === null) throw new Error('sub-call nest missing under the code row')
|
||||
|
||||
expect({
|
||||
parentRow: visibleText(codeRoot),
|
||||
// The three sub-rows in dispatch order: bash rides the sample plugin's
|
||||
// keyed registration (the same one a native top-level bash row uses),
|
||||
// both reads ride GenericToolCard.
|
||||
bashSample: nest.querySelector('[data-sample="bash-global"]') !== null,
|
||||
subRows: [...nest.querySelectorAll(':scope > *')].map(visibleText),
|
||||
errorSubRow: nest.querySelector('[data-state="error"]') !== null,
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"bashSample": true,
|
||||
"errorSubRow": true,
|
||||
"parentRow": "CodeRead the notes files and summarize",
|
||||
"subRows": [
|
||||
"BashList notes",
|
||||
"Readnotes/demo.txt",
|
||||
"Readnotes/missing.txt",
|
||||
],
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('expands the code row into the program body; sub-row clicks do not open details', async () => {
|
||||
boot()
|
||||
await openFixtureSession()
|
||||
|
||||
// Expand: the leading control reveals the program (shiki-tokenized: the
|
||||
// text splits into styled spans inside one <pre class="shiki"> tree).
|
||||
const codeRoot = document.querySelector('[data-variant="code"]')
|
||||
if (codeRoot === null) throw new Error('code-variant row missing')
|
||||
const toggle = codeRoot.querySelector('button[aria-expanded]')
|
||||
if (toggle === null) throw new Error('code row expand control missing')
|
||||
fireEvent.click(toggle)
|
||||
await waitFor(() => {
|
||||
// Scope to THIS row: the markdown fixture turn also renders shiki pres.
|
||||
const pre = codeRoot.querySelector('pre.shiki')
|
||||
if (pre === null || !(pre.textContent ?? '').includes('const listing = await tools.bash')) {
|
||||
throw new Error('highlighted program body missing under the code row')
|
||||
}
|
||||
})
|
||||
|
||||
// Tool rows no longer drive the details panel: bash is inert, file paths
|
||||
// are host-open links (fixture openPath is a no-op success).
|
||||
const nest = document.querySelector('[data-subcalls]')
|
||||
if (nest === null) throw new Error('sub-call nest missing')
|
||||
const bashRow = nest.querySelector('[data-sample="bash-global"]')
|
||||
if (bashRow === null) throw new Error('bash sample sub-row missing')
|
||||
const fileLink = nest.querySelector('button')
|
||||
if (fileLink === null) throw new Error('file-path summary link missing on a read sub-row')
|
||||
const frame = document.querySelector('[data-details-collapsed]')
|
||||
if (frame === null) throw new Error('app frame missing')
|
||||
expect(frame.getAttribute('data-details-collapsed')).toBe('true')
|
||||
fireEvent.click(bashRow)
|
||||
expect(frame.getAttribute('data-details-collapsed')).toBe('true')
|
||||
fireEvent.click(fileLink)
|
||||
expect(frame.getAttribute('data-details-collapsed')).toBe('true')
|
||||
expect({
|
||||
fileLink: visibleText(fileLink),
|
||||
detailsCollapsed: frame.getAttribute('data-details-collapsed'),
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"detailsCollapsed": "true",
|
||||
"fileLink": "notes/demo.txt",
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('trajectory surfaces run_code sub-calls in the ledger and timing overview', async () => {
|
||||
boot()
|
||||
await openFixtureSession()
|
||||
|
||||
// Switch to the trajectory tab (same slot ring the chat view registers in).
|
||||
fireEvent.click(await screen.findByRole('tab', { name: 'Trajectory' }))
|
||||
await waitFor(() => {
|
||||
expect(document.querySelector('[data-kind="subtool"]')).not.toBeNull()
|
||||
}, { timeout: 10_000 })
|
||||
const subCells = [...document.querySelectorAll('[data-kind="subtool"]')]
|
||||
expect({
|
||||
// Three Subtool cells nested under the run_code Tool cell in dispatch
|
||||
// order, each paired with its result preview.
|
||||
subCells: subCells.map(cell => visibleText(cell)),
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"subCells": [
|
||||
"SUBTOOLbash{"command":"ls notes","description":"List notes"}→demo.txt new-demo.txt",
|
||||
"SUBTOOLread{"path":"notes/demo.txt"}→hello fixture",
|
||||
"SUBTOOLread{"path":"notes/missing.txt"}→error",
|
||||
],
|
||||
}
|
||||
`)
|
||||
|
||||
const timelineSubCalls = [...document.querySelectorAll('[data-timeline-span="subtool"]')]
|
||||
expect({
|
||||
count: timelineSubCalls.length,
|
||||
measured: timelineSubCalls.map(span => span.getAttribute('title')?.endsWith(' · 800 ms')),
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"count": 3,
|
||||
"measured": [
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
}
|
||||
`)
|
||||
})
|
||||
@@ -1,153 +0,0 @@
|
||||
// @vitest-environment jsdom
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { act, cleanup, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import type { WebBootEntry } from '@deepseek-ai/dsh-client-modules/client'
|
||||
import { AppWebEntry } from '@deepseek-ai/dsh-client-web'
|
||||
|
||||
const PLUGINS: readonly (WebBootEntry & { dir: string })[] = [
|
||||
{ id: '@deepseek-ai/dsh-client-connection', dir: 'connection', url: '/plugins/connection.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-runtime', dir: 'runtime', url: '/plugins/runtime.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-connection'], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-theme', dir: 'ui-theme', url: '/plugins/ui-theme.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-locale', dir: 'locale', url: '/plugins/locale.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-layout', dir: 'ui-layout', url: '/plugins/ui-layout.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-sidebar', dir: 'ui-sidebar', url: '/plugins/ui-sidebar.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-settings', dir: 'ui-settings', url: '/plugins/ui-settings.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-sidebar'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-settings-general', dir: 'ui-settings-general', url: '/plugins/ui-settings-general.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-settings', '@deepseek-ai/dsh-client-locale'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-models', dir: 'ui-models', url: '/plugins/ui-models.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-settings'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-conversation', dir: 'ui-conversation', url: '/plugins/ui-conversation.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-slash', dir: 'ui-slash', url: '/plugins/ui-slash.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime', '@deepseek-ai/dsh-client-ui-conversation'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-command', dir: 'ui-command', url: '/plugins/ui-command.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-slash', '@deepseek-ai/dsh-client-ui-conversation'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-model', dir: 'ui-model', url: '/plugins/ui-model.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime', '@deepseek-ai/dsh-client-ui-command'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-workspace', dir: 'ui-workspace', url: '/plugins/ui-workspace.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime', '@deepseek-ai/dsh-client-ui-conversation', '@deepseek-ai/dsh-client-ui-sidebar'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-trajectory', dir: 'ui-trajectory', url: '/plugins/ui-trajectory.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-conversation'] },
|
||||
]
|
||||
|
||||
const bundles = new Map(PLUGINS.map(plugin => [
|
||||
plugin.url,
|
||||
readFileSync(join(process.cwd(), 'packages/client', plugin.dir, 'lib/client.js'), 'utf8'),
|
||||
]))
|
||||
|
||||
interface FixtureTiming {
|
||||
appendTitle(id: string, title: string): void
|
||||
}
|
||||
|
||||
interface FixtureWindow extends Window {
|
||||
__DSH_BOOT__?: { rev: string; entries: WebBootEntry[] }
|
||||
__ModuleLoader__?: unknown
|
||||
}
|
||||
|
||||
class ResizeObserverStub {
|
||||
observe(): void {}
|
||||
disconnect(): void {}
|
||||
unobserve(): void {}
|
||||
}
|
||||
|
||||
const win = window as FixtureWindow
|
||||
let unmount: (() => void) | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
history.replaceState(null, '', '/?fixture')
|
||||
document.title = 'DeepSeek Harness'
|
||||
const root = document.createElement('div')
|
||||
root.id = 'root'
|
||||
document.body.appendChild(root)
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) =>
|
||||
setTimeout(() => { callback(0) }, 0) as unknown as number)
|
||||
vi.stubGlobal('cancelAnimationFrame', (id: number) => { clearTimeout(id) })
|
||||
win.__DSH_BOOT__ = { rev: 'fx', entries: PLUGINS.map(({ dir: _dir, ...plugin }) => plugin) }
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
act(() => { unmount?.() })
|
||||
unmount = undefined
|
||||
cleanup()
|
||||
delete win.__DSH_BOOT__
|
||||
delete win.__ModuleLoader__
|
||||
delete (globalThis as Record<string, unknown>).__fxTiming
|
||||
document.body.innerHTML = ''
|
||||
document.head.querySelectorAll('style[data-plugin]').forEach((style) => { style.remove() })
|
||||
document.title = ''
|
||||
history.replaceState(null, '', '/')
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
/** Read only the stable, user-facing title surfaces from the assembled app. */
|
||||
function titleSurfaces(label: string): { sidebar: string; breadcrumb: string; documentTitle: string } {
|
||||
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
||||
const sidebar = within(tree).getByText(label).textContent ?? ''
|
||||
const breadcrumb = within(screen.getByRole('navigation', { name: 'Session hierarchy' }))
|
||||
.getByRole('button', { name: label }).textContent ?? ''
|
||||
return { sidebar, breadcrumb, documentTitle: document.title }
|
||||
}
|
||||
|
||||
it('projects titles and routes the next turn through the selected model in the built fixture app', async () => {
|
||||
const root = document.querySelector<HTMLElement>('#root')
|
||||
if (root === null) throw new Error('snapshot root missing')
|
||||
act(() => {
|
||||
const entry = new AppWebEntry(root, {
|
||||
fetchBundle: (url) => {
|
||||
const code = bundles.get(url)
|
||||
return code === undefined ? Promise.reject(new Error(`missing built bundle ${url}`)) : Promise.resolve(code)
|
||||
},
|
||||
executeBundle: (code) => { (0, eval)(code) },
|
||||
})
|
||||
void entry.run()
|
||||
unmount = () => { entry.dispose() }
|
||||
})
|
||||
|
||||
const tree = await screen.findByRole('tree', { name: 'Sessions' }, { timeout: 10_000 })
|
||||
// The fixture Intent selects the workspace, so the current-group effect
|
||||
// already expanded it; clicking the header would now collapse (the twist
|
||||
// stays live since intent stopped forcing expansion).
|
||||
await within(tree).findByText('4 sessions')
|
||||
|
||||
const initialLabel = 'Fixture 历史会话'
|
||||
const initialRowLabel = await screen.findByText(initialLabel)
|
||||
const initialRow = initialRowLabel.closest<HTMLElement>('[role="treeitem"]')
|
||||
if (initialRow === null) throw new Error('fixture session row missing')
|
||||
fireEvent.click(initialRow)
|
||||
await waitFor(() => { expect(document.title).toBe(`${initialLabel} — DeepSeek Harness`) })
|
||||
const initial = titleSurfaces(initialLabel)
|
||||
|
||||
const revisedLabel = 'Fixture 修订标题'
|
||||
const timing = (globalThis as Record<string, unknown>).__fxTiming as FixtureTiming
|
||||
act(() => { timing.appendTitle('fx-alpha', revisedLabel) })
|
||||
await waitFor(() => { expect(document.title).toBe(`${revisedLabel} — DeepSeek Harness`) })
|
||||
const revised = titleSurfaces(revisedLabel)
|
||||
|
||||
// fx-alpha carries the fixture's resident answerable approval, so the
|
||||
// approval panel has taken over the composer (the real takeover behavior);
|
||||
// answer it to restore the composer chrome before asserting the model seat.
|
||||
fireEvent.click(await screen.findByRole('button', { name: '允许一次' }))
|
||||
const modelTrigger = await screen.findByRole('button', {
|
||||
name: '选择模型,当前 DeepSeek-V4-Flash,推理等级 High',
|
||||
})
|
||||
fireEvent.click(modelTrigger)
|
||||
fireEvent.click(screen.getByRole('menuitem', { name: /Model/ }))
|
||||
fireEvent.click(screen.getByRole('menuitemradio', { name: /GPT-5/ }))
|
||||
await waitFor(() => {
|
||||
expect(modelTrigger.getAttribute('aria-label')).toBe('选择模型,当前 GPT-5,推理等级 Medium')
|
||||
})
|
||||
fireEvent.click(modelTrigger)
|
||||
fireEvent.click(screen.getByRole('menuitem', { name: /Effort/ }))
|
||||
fireEvent.click(screen.getByRole('menuitemradio', { name: 'Max' }))
|
||||
await waitFor(() => {
|
||||
expect(modelTrigger.getAttribute('aria-label')).toBe('选择模型,当前 GPT-5,推理等级 Max')
|
||||
})
|
||||
|
||||
// fx-alpha starts in the running state. Selecting above is intentionally
|
||||
// allowed for the next turn; stop the fixture's resident run before sending
|
||||
// the route-report prompt.
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Stop generating' }))
|
||||
const composer = await screen.findByPlaceholderText('给智能体发消息')
|
||||
fireEvent.change(composer, { target: { value: 'report model' } })
|
||||
fireEvent.keyDown(composer, { key: 'Enter' })
|
||||
await screen.findByText('当前模型:openai/gpt-5 · 推理等级:max', {}, { timeout: 10_000 })
|
||||
|
||||
await expect(`${JSON.stringify({ initial, revised }, null, 2)}\n`)
|
||||
.toMatchFileSnapshot('./snapshots/session-title.json')
|
||||
})
|
||||
@@ -1,213 +0,0 @@
|
||||
// @vitest-environment jsdom
|
||||
// Assembled keyless snapshot of the slash/input/session convergence under the
|
||||
// agent-parity model: the New Session view state locks the composer until a
|
||||
// Workspace is picked (connectWorkspace materializes the full Session+Agent),
|
||||
// the '/' menu renders the session's skill and wire command catalogs
|
||||
// (sessions are always agent-backed — no draft/materialized split), a skill
|
||||
// pick inserts its reference, a leadingInput command claims,
|
||||
// submits over the wire, and notices its result, and the SAME composer
|
||||
// textarea then carries the first plain send, whose ACCEPTANCE (not attempt)
|
||||
// flips blank and surfaces the session in lists. This is the user-visible
|
||||
// acceptance anchor — package mocks do not substitute for the assembled
|
||||
// application transcript.
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { act, cleanup, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import type { WebBootEntry } from '@deepseek-ai/dsh-client-modules/client'
|
||||
import { AppWebEntry } from '@deepseek-ai/dsh-client-web'
|
||||
|
||||
const PLUGINS: readonly (WebBootEntry & { dir: string })[] = [
|
||||
{ id: '@deepseek-ai/dsh-client-connection', dir: 'connection', url: '/plugins/connection.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-runtime', dir: 'runtime', url: '/plugins/runtime.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-connection'], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-theme', dir: 'ui-theme', url: '/plugins/ui-theme.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-locale', dir: 'locale', url: '/plugins/locale.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-layout', dir: 'ui-layout', url: '/plugins/ui-layout.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-sidebar', dir: 'ui-sidebar', url: '/plugins/ui-sidebar.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-slash', dir: 'ui-slash', url: '/plugins/ui-slash.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-conversation', dir: 'ui-conversation', url: '/plugins/ui-conversation.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout', '@deepseek-ai/dsh-client-ui-slash'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-command', dir: 'ui-command', url: '/plugins/ui-command.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-slash', '@deepseek-ai/dsh-client-ui-conversation'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-skill', dir: 'ui-skill', url: '/plugins/ui-skill.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-slash'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-subagent', dir: 'ui-subagent', url: '/plugins/ui-subagent.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-slash'] },
|
||||
{
|
||||
id: '@deepseek-ai/dsh-client-ui-workspace',
|
||||
dir: 'ui-workspace',
|
||||
url: '/plugins/ui-workspace.js',
|
||||
rev: 'fx',
|
||||
inject: [
|
||||
'@deepseek-ai/dsh-client-runtime',
|
||||
'@deepseek-ai/dsh-client-ui-conversation',
|
||||
'@deepseek-ai/dsh-client-ui-sidebar',
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const bundles = new Map(PLUGINS.map(plugin => [
|
||||
plugin.url,
|
||||
readFileSync(join(process.cwd(), 'packages/client', plugin.dir, 'lib/client.js'), 'utf8'),
|
||||
]))
|
||||
|
||||
interface FixtureWindow extends Window {
|
||||
__DSH_BOOT__?: { rev: string; entries: WebBootEntry[] }
|
||||
__ModuleLoader__?: unknown
|
||||
}
|
||||
|
||||
class ResizeObserverStub {
|
||||
observe(): void {}
|
||||
disconnect(): void {}
|
||||
unobserve(): void {}
|
||||
}
|
||||
|
||||
// jsdom has no scrollIntoView; the slash menu follows its highlighted option.
|
||||
const scrollIntoView = vi.fn()
|
||||
const win = window as FixtureWindow
|
||||
let unmount: (() => void) | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
document.title = 'DeepSeek Harness'
|
||||
Element.prototype.scrollIntoView = scrollIntoView
|
||||
scrollIntoView.mockClear()
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) =>
|
||||
setTimeout(() => { callback(0) }, 0) as unknown as number)
|
||||
vi.stubGlobal('cancelAnimationFrame', (id: number) => { clearTimeout(id) })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
act(() => { unmount?.() })
|
||||
unmount = undefined
|
||||
cleanup()
|
||||
delete win.__DSH_BOOT__
|
||||
delete win.__ModuleLoader__
|
||||
delete (globalThis as Record<string, unknown>).__fxTiming
|
||||
document.body.innerHTML = ''
|
||||
document.head.querySelectorAll('style[data-plugin]').forEach((style) => { style.remove() })
|
||||
document.title = ''
|
||||
history.replaceState(null, '', '/')
|
||||
Reflect.deleteProperty(Element.prototype, 'scrollIntoView')
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
/** Boot the complete built client graph against one keyless fixture branch. */
|
||||
function boot(search: string): void {
|
||||
history.replaceState(null, '', `/${search}`)
|
||||
const root = document.createElement('div')
|
||||
root.id = 'root'
|
||||
document.body.appendChild(root)
|
||||
win.__DSH_BOOT__ = { rev: 'fx', entries: PLUGINS.map(({ dir: _dir, ...plugin }) => plugin) }
|
||||
act(() => {
|
||||
const entry = new AppWebEntry(root, {
|
||||
fetchBundle: (url) => {
|
||||
const code = bundles.get(url)
|
||||
return code === undefined ? Promise.reject(new Error(`missing built bundle ${url}`)) : Promise.resolve(code)
|
||||
},
|
||||
executeBundle: (code) => { (0, eval)(code) },
|
||||
})
|
||||
void entry.run()
|
||||
unmount = () => { entry.dispose() }
|
||||
})
|
||||
}
|
||||
|
||||
/** Collapse decorative whitespace while preserving the text a user sees. */
|
||||
function visibleText(element: Element): string {
|
||||
return (element.textContent ?? '').replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
|
||||
/** Type into the machine-driven composer and let the change echo back. */
|
||||
async function typeComposer(composer: HTMLTextAreaElement, value: string): Promise<void> {
|
||||
fireEvent.change(composer, { target: { value } })
|
||||
await waitFor(() => { expect(composer.value).toBe(value) })
|
||||
}
|
||||
|
||||
it('locked view state, skill discovery, /echo claim chain, and blank-on-acceptance ride one resident composer', async () => {
|
||||
boot('?fixture=empty')
|
||||
|
||||
// View state: no session entity — the composer renders locked; only the
|
||||
// workspace picker is live.
|
||||
const locked = await screen.findByPlaceholderText<HTMLTextAreaElement>(
|
||||
'Choose a workspace to start', {}, { timeout: 10_000 },
|
||||
)
|
||||
expect(locked.disabled).toBe(true)
|
||||
|
||||
// Pick (create) a Workspace: connectWorkspace materializes the full
|
||||
// Session+Agent and the provider swaps in the live blank-session hero.
|
||||
fireEvent.click(screen.getAllByRole('button', { name: 'Choose workspace' })
|
||||
.find(el => el.getAttribute('aria-haspopup') === 'menu')!)
|
||||
fireEvent.click(await screen.findByRole('menuitem', { name: 'Create a new workspace' }))
|
||||
const dialog = await screen.findByRole('dialog', { name: 'Create a new workspace' })
|
||||
fireEvent.change(within(dialog).getByRole('textbox', { name: 'New workspace name' }), {
|
||||
target: { value: 'nova' },
|
||||
})
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: 'Create workspace' }))
|
||||
|
||||
const composer = await screen.findByPlaceholderText<HTMLTextAreaElement>(
|
||||
'Describe what you want to build', {}, { timeout: 10_000 },
|
||||
)
|
||||
expect(composer.disabled).toBe(false)
|
||||
|
||||
// The built skill plugin prewarms the fixture's session-addressed catalog;
|
||||
// this pins client rendering and picking, while the real-host browser lane
|
||||
// owns policy filtering. Picking inserts the literal reference into the
|
||||
// resident composer.
|
||||
await typeComposer(composer, '/fixture')
|
||||
const skillMenu = await screen.findByRole('listbox', { name: 'Trigger suggestions' })
|
||||
const skillOption = await within(skillMenu).findByRole('option', { name: /fixture-demo/ })
|
||||
const skillMenuText = visibleText(skillMenu)
|
||||
fireEvent.mouseDown(skillOption)
|
||||
await waitFor(() => { expect(composer.value).toBe('/fixture-demo ') })
|
||||
const pickedSkill = composer.value
|
||||
await typeComposer(composer, '')
|
||||
|
||||
// '/' opens the menu with the session's wire command catalog (the session
|
||||
// is agent-backed from birth — the catalog is the single-address list).
|
||||
await typeComposer(composer, '/')
|
||||
const menu = await screen.findByRole('listbox', { name: 'Trigger suggestions' })
|
||||
await waitFor(() => { expect(visibleText(menu)).toContain('echo') })
|
||||
const menuText = visibleText(menu)
|
||||
|
||||
// Pick /echo (leadingInput): the claim token lands in the same textarea.
|
||||
fireEvent.mouseDown(screen.getByRole('option', { name: /echo/ }))
|
||||
await waitFor(() => { expect(composer.value).toBe('/echo ') })
|
||||
|
||||
// Type args and submit: the claim executes over the wire and notices its
|
||||
// result; the token is consumed and the draft returns to plain text.
|
||||
await typeComposer(composer, '/echo hello parser')
|
||||
fireEvent.keyDown(composer, { key: 'Enter' })
|
||||
await screen.findByText('hello parser', {}, { timeout: 10_000 })
|
||||
await waitFor(() => { expect(composer.value).toBe('') })
|
||||
|
||||
// Slash execution does not flip blank: the selected row remains New Session.
|
||||
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
||||
expect(within(tree).getByText('1 session')).toBeDefined()
|
||||
expect(within(tree).getByText('New Session')).toBeDefined()
|
||||
|
||||
// First plain send through the SAME textarea: acceptance logs the user
|
||||
// message and converts the existing sidebar row out of blank.
|
||||
const before = composer
|
||||
await typeComposer(composer, 'build me a parser')
|
||||
fireEvent.keyDown(composer, { key: 'Enter' })
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText("Let's start building")).toBeNull()
|
||||
}, { timeout: 10_000 })
|
||||
await waitFor(() => { expect(within(tree).getByText('1 session')).toBeDefined() }, { timeout: 10_000 })
|
||||
const after = document.querySelector('textarea')
|
||||
|
||||
expect({
|
||||
menuHadEcho: menuText.includes('echo'),
|
||||
menuHadCompact: menuText.includes('compact'),
|
||||
composerSurvivedConversion: after === before,
|
||||
skillMenuHadFixtureDemo: skillMenuText.includes('fixture-demo'),
|
||||
skillPickInserted: pickedSkill,
|
||||
sessionListed: visibleText(within(tree).getByText('1 session').closest('[role="treeitem"]')!),
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"composerSurvivedConversion": true,
|
||||
"menuHadCompact": true,
|
||||
"menuHadEcho": true,
|
||||
"sessionListed": "nova1 session",
|
||||
"skillMenuHadFixtureDemo": true,
|
||||
"skillPickInserted": "/fixture-demo ",
|
||||
}
|
||||
`)
|
||||
})
|
||||
@@ -1,14 +0,0 @@
|
||||
[
|
||||
{
|
||||
"label": "fixture4 sessions"
|
||||
},
|
||||
{
|
||||
"label": "New Sessionnow"
|
||||
},
|
||||
{
|
||||
"label": "分叉 实验记录now"
|
||||
},
|
||||
{
|
||||
"label": "fixture2min"
|
||||
}
|
||||
]
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"initial": {
|
||||
"sidebar": "Fixture 历史会话",
|
||||
"breadcrumb": "Fixture 历史会话",
|
||||
"documentTitle": "Fixture 历史会话 — DeepSeek Harness"
|
||||
},
|
||||
"revised": {
|
||||
"sidebar": "Fixture 修订标题",
|
||||
"breadcrumb": "Fixture 修订标题",
|
||||
"documentTitle": "Fixture 修订标题 — DeepSeek Harness"
|
||||
}
|
||||
}
|
||||
@@ -1,306 +0,0 @@
|
||||
// @vitest-environment jsdom
|
||||
// Terminal card snapshot over the BUILT client graph (the code-mode-fixture
|
||||
// idiom: real bundles via AppWebEntry, keyless FixtureApiClient transport).
|
||||
// Opens the fixture history session and pins the `card: 'terminal'` render
|
||||
// intent at both of its conversation render sites, for both chat-row shapes:
|
||||
// turn 60's `fx-bash` on the render-site fallback row (expand-gated body) and
|
||||
// turn 65's `bash` on the keyed BashRow registration (resident body). Turn 65
|
||||
// carries what turn 60's two clean prompt rows cannot — SGR runs resolved to
|
||||
// --dsw-* tokens, output past the chat cap, a nested cwd, and a non-zero exit
|
||||
// pill; turn 60 carries the multi-line command's per-line prompt rows.
|
||||
//
|
||||
// The details panel's Output section is NOT covered here: tool rows stopped
|
||||
// being details-panel click targets, and nothing else in the assembled
|
||||
// application opens that panel, so the surface cannot be driven end to end.
|
||||
// Its terminal rendering stays pinned in ui-conversation's
|
||||
// tests/terminal-card.spec.tsx, which mounts DetailsPanel with a selection
|
||||
// directly.
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { act, cleanup, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import type { WebBootEntry } from '@deepseek-ai/dsh-client-modules/client'
|
||||
import { AppWebEntry } from '@deepseek-ai/dsh-client-web'
|
||||
|
||||
const PLUGINS: readonly (WebBootEntry & { dir: string })[] = [
|
||||
{ id: '@deepseek-ai/dsh-client-connection', dir: 'connection', url: '/plugins/connection.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-runtime', dir: 'runtime', url: '/plugins/runtime.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-connection'], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-theme', dir: 'ui-theme', url: '/plugins/ui-theme.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-locale', dir: 'locale', url: '/plugins/locale.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-layout', dir: 'ui-layout', url: '/plugins/ui-layout.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-sidebar', dir: 'ui-sidebar', url: '/plugins/ui-sidebar.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-conversation', dir: 'ui-conversation', url: '/plugins/ui-conversation.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{
|
||||
id: '@deepseek-ai/dsh-client-ui-workspace',
|
||||
dir: 'ui-workspace',
|
||||
url: '/plugins/ui-workspace.js',
|
||||
rev: 'fx',
|
||||
inject: [
|
||||
'@deepseek-ai/dsh-client-runtime',
|
||||
'@deepseek-ai/dsh-client-ui-conversation',
|
||||
'@deepseek-ai/dsh-client-ui-sidebar',
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const bundles = new Map(PLUGINS.map(plugin => [
|
||||
plugin.url,
|
||||
readFileSync(join(process.cwd(), 'packages/client', plugin.dir, 'lib/client.js'), 'utf8'),
|
||||
]))
|
||||
|
||||
interface FixtureWindow extends Window {
|
||||
__DSH_BOOT__?: { rev: string; entries: WebBootEntry[] }
|
||||
__ModuleLoader__?: unknown
|
||||
}
|
||||
|
||||
class ResizeObserverStub {
|
||||
observe(): void {}
|
||||
disconnect(): void {}
|
||||
unobserve(): void {}
|
||||
}
|
||||
|
||||
const win = window as FixtureWindow
|
||||
let unmount: (() => void) | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
document.title = 'DeepSeek Harness'
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) =>
|
||||
setTimeout(() => { callback(0) }, 0) as unknown as number)
|
||||
vi.stubGlobal('cancelAnimationFrame', (id: number) => { clearTimeout(id) })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
act(() => { unmount?.() })
|
||||
unmount = undefined
|
||||
cleanup()
|
||||
delete win.__DSH_BOOT__
|
||||
delete win.__ModuleLoader__
|
||||
document.body.innerHTML = ''
|
||||
document.head.querySelectorAll('style[data-plugin]').forEach((style) => { style.remove() })
|
||||
document.title = ''
|
||||
history.replaceState(null, '', '/')
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
/** Boot the complete built client graph against the populated fixture branch. */
|
||||
function boot(): void {
|
||||
history.replaceState(null, '', '/?fixture')
|
||||
const root = document.createElement('div')
|
||||
root.id = 'root'
|
||||
document.body.appendChild(root)
|
||||
win.__DSH_BOOT__ = { rev: 'fx', entries: PLUGINS.map(({ dir: _dir, ...plugin }) => plugin) }
|
||||
act(() => {
|
||||
const entry = new AppWebEntry(root, {
|
||||
fetchBundle: (url) => {
|
||||
const code = bundles.get(url)
|
||||
return code === undefined ? Promise.reject(new Error(`missing built bundle ${url}`)) : Promise.resolve(code)
|
||||
},
|
||||
executeBundle: (code) => { (0, eval)(code) },
|
||||
})
|
||||
void entry.run()
|
||||
unmount = () => { entry.dispose() }
|
||||
})
|
||||
}
|
||||
|
||||
/** Collapse decorative whitespace while preserving the text a user sees. */
|
||||
function visibleText(element: Element): string {
|
||||
return (element.textContent ?? '').replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
|
||||
/**
|
||||
* Read one terminal card's user-visible state. Output lines keep their interior
|
||||
* whitespace: holding column alignment is what this card exists for, so
|
||||
* collapsing runs of spaces would hide the behavior under test.
|
||||
*/
|
||||
function readCard(card: Element) {
|
||||
const status = card.querySelector('[class*="_status_"]')
|
||||
const expander = card.querySelector('button[aria-expanded]')
|
||||
return {
|
||||
// One entry per command line: a multi-line command is one row per line.
|
||||
prompt: [...card.querySelectorAll('[class*="_promptLine_"]')].map(row =>
|
||||
`${row.querySelector('[class*="_cwd_"]')?.textContent ?? ''} ${row.querySelector('[class*="_command_"]')?.textContent ?? ''}`),
|
||||
// Dots per prompt row: exactly one, on the first row — the exit status the
|
||||
// view carries is the whole call's, so a dot per line would assert a
|
||||
// per-line outcome bash does not report.
|
||||
dotsPerPromptRow: [...card.querySelectorAll('[class*="_promptLine_"]')].map(row =>
|
||||
row.querySelectorAll('[data-state]').length),
|
||||
status: status === null ? null : status.textContent,
|
||||
copy: card.querySelector('[class*="_copyButton_"]')?.textContent ?? null,
|
||||
lines: [...card.querySelectorAll('[class*="_line_"]')].map(line => line.textContent),
|
||||
expander: expander === null ? null : {
|
||||
label: expander.getAttribute('aria-label'),
|
||||
text: expander.textContent,
|
||||
expanded: expander.getAttribute('aria-expanded'),
|
||||
},
|
||||
// The run-state dot at the head of the prompt line, by its StateDot state.
|
||||
runState: card.querySelector('[class*="_runState_"][data-state]')?.getAttribute('data-state') ?? null,
|
||||
runStateLabel: card.querySelector('[class*="_runStateLabel_"]')?.textContent ?? null,
|
||||
// Every color the ANSI parser emits resolves through a --dsw-* token, so
|
||||
// the card follows the theme instead of painting literal terminal rgb.
|
||||
// Scoped to the output lines: the run-state dot is an inline-styled span
|
||||
// too, and its geometry is not an ANSI-resolved color.
|
||||
colors: [...new Set([...card.querySelectorAll('[class*="_line_"] span[style]')]
|
||||
.map(span => span.getAttribute('style')))],
|
||||
}
|
||||
}
|
||||
|
||||
/** Open the fixture history session (the alpha log carrying both bash turns) and wait for its tail. */
|
||||
async function openFixtureSession(): Promise<void> {
|
||||
const tree = await screen.findByRole('tree', { name: 'Sessions' }, { timeout: 10_000 })
|
||||
// Anchor on the expandable Workspace group row: the title and the blank
|
||||
// session row can both read "fixture".
|
||||
const group = (await within(tree).findAllByText('fixture'))
|
||||
.map(el => el.closest<HTMLElement>('[role="treeitem"]'))
|
||||
.find(el => el?.getAttribute('aria-expanded') !== null)
|
||||
if (group === null || group === undefined) throw new Error('fixture Workspace group missing')
|
||||
if (group.getAttribute('aria-expanded') === 'false') {
|
||||
fireEvent.click(within(group).getByText('fixture'))
|
||||
await waitFor(() => {
|
||||
expect(group.getAttribute('aria-expanded')).toBe('true')
|
||||
})
|
||||
}
|
||||
fireEvent.click(await within(tree).findByText('Fixture 历史会话'))
|
||||
await waitFor(() => {
|
||||
expect(document.querySelector('[data-sample="bash-global"]')).not.toBeNull()
|
||||
}, { timeout: 10_000 })
|
||||
}
|
||||
|
||||
/** The keyed BashRow of fixture turn 65 (the one carrying the ANSI sample). */
|
||||
function keyedBashRow(): Element {
|
||||
// Anchored on the BashRow wrapper (summary row + resident card), not on the
|
||||
// summary row itself: the summary now shows the presenter's description (the
|
||||
// contract's above-card text), so the command lives only in the card below it.
|
||||
const row = [...document.querySelectorAll('[data-sample="bash-global"]')]
|
||||
.map(node => node.parentElement)
|
||||
.find((node): node is HTMLElement => node !== null && visibleText(node).includes('pnpm run check'))
|
||||
if (row === undefined) throw new Error('keyed bash row for turn 65 missing')
|
||||
return row
|
||||
}
|
||||
|
||||
/** The turn-60 fallback row, which reaches the terminal card through GenericToolCard/ToolRow. */
|
||||
function fallbackBashRow(): Element {
|
||||
const row = document.querySelector('[data-tool="fx-bash"]')
|
||||
if (row === null) throw new Error('fx-bash fallback row missing')
|
||||
return row
|
||||
}
|
||||
|
||||
it('renders the keyed bash row with a resident terminal card', async () => {
|
||||
boot()
|
||||
await openFixtureSession()
|
||||
|
||||
const row = keyedBashRow()
|
||||
const card = row.parentElement?.querySelector('[data-terminal]')
|
||||
if (card === null || card === undefined) throw new Error('keyed bash row has no resident terminal card')
|
||||
// The prompt shortens the nested cwd to its last segment, the exit pill comes
|
||||
// from the sample's authored exit status (its body deliberately carries no
|
||||
// `[exit code: N]` marker, since the real presenter consumes that one), ANSI
|
||||
// runs land on theme tokens, and the chat cap (8) collapses the middle into a
|
||||
// head/tail split with an expander between them.
|
||||
expect(readCard(card)).toMatchInlineSnapshot(`
|
||||
{
|
||||
"colors": [
|
||||
"font-weight: 700;",
|
||||
"color: var(--dsw-alias-state-success-primary);",
|
||||
"color: var(--dsw-alias-state-error-primary);",
|
||||
],
|
||||
"copy": "复制",
|
||||
"dotsPerPromptRow": [
|
||||
1,
|
||||
],
|
||||
"expander": {
|
||||
"expanded": "false",
|
||||
"label": "展开其余 13 行输出",
|
||||
"text": "… 其余 13 行",
|
||||
},
|
||||
"lines": [
|
||||
"Running 4 checks",
|
||||
"✓ typecheck 1.82s",
|
||||
"✓ lint 0.94s",
|
||||
"✓ duplication 2.10s",
|
||||
"StateDot.tsx 100% 100% 100% -",
|
||||
"markdown/Markdown.tsx 100% 100% 100% -",
|
||||
"",
|
||||
"1 of 4 checks failed",
|
||||
],
|
||||
"prompt": [
|
||||
"nested pnpm run check",
|
||||
],
|
||||
"runState": "error",
|
||||
"runStateLabel": "失败",
|
||||
"status": "退出码 1",
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('the fallback row reaches the same card through its expand control', async () => {
|
||||
boot()
|
||||
await openFixtureSession()
|
||||
|
||||
const row = fallbackBashRow()
|
||||
expect(row.querySelector('[data-terminal]')).toBeNull()
|
||||
const toggle = row.querySelector('button[aria-expanded]')
|
||||
if (toggle === null) throw new Error('fallback row expand control missing')
|
||||
fireEvent.click(toggle)
|
||||
const card = await waitFor(() => {
|
||||
const found = row.querySelector('[data-terminal]')
|
||||
if (found === null) throw new Error('terminal card missing after expanding the fallback row')
|
||||
return found
|
||||
})
|
||||
// Three plain lines under the cap: no ANSI spans, no exit pill, no expander.
|
||||
expect(readCard(card)).toMatchInlineSnapshot(`
|
||||
{
|
||||
"colors": [],
|
||||
"copy": "复制",
|
||||
"dotsPerPromptRow": [
|
||||
1,
|
||||
0,
|
||||
],
|
||||
"expander": null,
|
||||
"lines": [
|
||||
"total 2",
|
||||
"drwxr-xr-x fixture",
|
||||
"-rw-r--r-- demo.txt",
|
||||
],
|
||||
"prompt": [
|
||||
"fixture ls -la",
|
||||
"$ echo done",
|
||||
],
|
||||
"runState": "done",
|
||||
"runStateLabel": "已完成",
|
||||
"status": null,
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('the chat card expands the collapsed middle in place, without opening the details panel', async () => {
|
||||
boot()
|
||||
await openFixtureSession()
|
||||
|
||||
const card = keyedBashRow().parentElement?.querySelector('[data-terminal]')
|
||||
if (card === null || card === undefined) throw new Error('resident terminal card missing')
|
||||
const expander = card.querySelector('button[aria-expanded]')
|
||||
if (expander === null) throw new Error('height-cap expander missing')
|
||||
const capped = card.querySelectorAll('[class*="_line_"]').length
|
||||
|
||||
fireEvent.click(expander)
|
||||
await waitFor(() => {
|
||||
expect(card.querySelector('button[aria-expanded]')?.getAttribute('aria-expanded')).toBe('true')
|
||||
})
|
||||
expect({
|
||||
cappedLines: capped,
|
||||
expandedLines: card.querySelectorAll('[class*="_line_"]').length,
|
||||
expanderLabel: card.querySelector('button[aria-expanded]')?.getAttribute('aria-label'),
|
||||
// The card sits outside the summary row's click target, so toggling it
|
||||
// left the details panel shut.
|
||||
detailsOpen: screen.queryByText('Input') !== null,
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"cappedLines": 8,
|
||||
"detailsOpen": false,
|
||||
"expandedLines": 21,
|
||||
"expanderLabel": "收起输出",
|
||||
}
|
||||
`)
|
||||
})
|
||||
@@ -1,213 +0,0 @@
|
||||
// @vitest-environment jsdom
|
||||
// Todo display snapshot over the BUILT client graph (the code-mode-fixture
|
||||
// idiom: real bundles via AppWebEntry, keyless FixtureApiClient transport).
|
||||
// Opens the fixture history session and pins the todo_write turn's two
|
||||
// surfaces: the dedicated TodoRow in the chat flow (keyed toolview, summary
|
||||
// derived from the call args) and the TodoPanel plan strip riding the
|
||||
// 'conversation.input.dock' slot (fed by the host `todos` projection via
|
||||
// useProjection, seeded by the tail history page), including the collapse
|
||||
// interaction and the next-turn clearance of the standing plan.
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { act, cleanup, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import type { WebBootEntry } from '@deepseek-ai/dsh-client-modules/client'
|
||||
import { AppWebEntry } from '@deepseek-ai/dsh-client-web'
|
||||
|
||||
const PLUGINS: readonly (WebBootEntry & { dir: string })[] = [
|
||||
{ id: '@deepseek-ai/dsh-client-connection', dir: 'connection', url: '/plugins/connection.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-runtime', dir: 'runtime', url: '/plugins/runtime.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-connection'], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-theme', dir: 'ui-theme', url: '/plugins/ui-theme.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-locale', dir: 'locale', url: '/plugins/locale.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-layout', dir: 'ui-layout', url: '/plugins/ui-layout.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-sidebar', dir: 'ui-sidebar', url: '/plugins/ui-sidebar.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-conversation', dir: 'ui-conversation', url: '/plugins/ui-conversation.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{
|
||||
id: '@deepseek-ai/dsh-client-ui-workspace',
|
||||
dir: 'ui-workspace',
|
||||
url: '/plugins/ui-workspace.js',
|
||||
rev: 'fx',
|
||||
inject: [
|
||||
'@deepseek-ai/dsh-client-runtime',
|
||||
'@deepseek-ai/dsh-client-ui-conversation',
|
||||
'@deepseek-ai/dsh-client-ui-sidebar',
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const bundles = new Map(PLUGINS.map(plugin => [
|
||||
plugin.url,
|
||||
readFileSync(join(process.cwd(), 'packages/client', plugin.dir, 'lib/client.js'), 'utf8'),
|
||||
]))
|
||||
|
||||
interface FixtureWindow extends Window {
|
||||
__DSH_BOOT__?: { rev: string; entries: WebBootEntry[] }
|
||||
__ModuleLoader__?: unknown
|
||||
}
|
||||
|
||||
class ResizeObserverStub {
|
||||
observe(): void {}
|
||||
disconnect(): void {}
|
||||
unobserve(): void {}
|
||||
}
|
||||
|
||||
const win = window as FixtureWindow
|
||||
let unmount: (() => void) | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
document.title = 'DeepSeek Harness'
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) =>
|
||||
setTimeout(() => { callback(0) }, 0) as unknown as number)
|
||||
vi.stubGlobal('cancelAnimationFrame', (id: number) => { clearTimeout(id) })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
act(() => { unmount?.() })
|
||||
unmount = undefined
|
||||
cleanup()
|
||||
delete win.__DSH_BOOT__
|
||||
delete win.__ModuleLoader__
|
||||
delete (globalThis as Record<string, unknown>).__fxTiming
|
||||
document.body.innerHTML = ''
|
||||
document.head.querySelectorAll('style[data-plugin]').forEach((style) => { style.remove() })
|
||||
document.title = ''
|
||||
history.replaceState(null, '', '/')
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
/** Boot the complete built client graph against the populated fixture branch. */
|
||||
function boot(): void {
|
||||
history.replaceState(null, '', '/?fixture')
|
||||
const root = document.createElement('div')
|
||||
root.id = 'root'
|
||||
document.body.appendChild(root)
|
||||
win.__DSH_BOOT__ = { rev: 'fx', entries: PLUGINS.map(({ dir: _dir, ...plugin }) => plugin) }
|
||||
act(() => {
|
||||
const entry = new AppWebEntry(root, {
|
||||
fetchBundle: (url) => {
|
||||
const code = bundles.get(url)
|
||||
return code === undefined ? Promise.reject(new Error(`missing built bundle ${url}`)) : Promise.resolve(code)
|
||||
},
|
||||
executeBundle: (code) => { (0, eval)(code) },
|
||||
})
|
||||
void entry.run()
|
||||
unmount = () => { entry.dispose() }
|
||||
})
|
||||
}
|
||||
|
||||
/** Collapse decorative whitespace while preserving the text a user sees. */
|
||||
function visibleText(element: Element): string {
|
||||
return (element.textContent ?? '').replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
|
||||
/** Open the fixture history session (the alpha log carrying the todo_write turn) and wait for its tail. */
|
||||
async function openFixtureSession(): Promise<void> {
|
||||
const tree = await screen.findByRole('tree', { name: 'Sessions' }, { timeout: 10_000 })
|
||||
// Anchor on the expandable Workspace group row: the title and the blank
|
||||
// session row can both read "fixture", and the session-count meta shifts
|
||||
// when a blank session joins the group.
|
||||
const group = (await within(tree).findAllByText('fixture'))
|
||||
.map(el => el.closest<HTMLElement>('[role="treeitem"]'))
|
||||
.find(el => el?.getAttribute('aria-expanded') !== null)
|
||||
if (group === null || group === undefined) throw new Error('fixture Workspace group missing')
|
||||
if (group.getAttribute('aria-expanded') === 'false') {
|
||||
fireEvent.click(within(group).getByText('fixture'))
|
||||
await waitFor(() => {
|
||||
expect(group.getAttribute('aria-expanded')).toBe('true')
|
||||
})
|
||||
}
|
||||
const session = await within(tree).findByText('Fixture 历史会话')
|
||||
fireEvent.click(session)
|
||||
await waitFor(() => {
|
||||
expect(document.querySelector('[data-sample="todo-row"]')).not.toBeNull()
|
||||
}, { timeout: 10_000 })
|
||||
}
|
||||
|
||||
it('renders the todo_write turn: dedicated tool row + the dock plan strip', async () => {
|
||||
boot()
|
||||
await openFixtureSession()
|
||||
|
||||
const row = document.querySelector('[data-sample="todo-row"]')
|
||||
if (row === null) throw new Error('todo row missing')
|
||||
const panel = document.querySelector('[data-testid="todo-panel"]')
|
||||
if (panel === null) throw new Error('todo panel missing from the input dock')
|
||||
|
||||
// Header spans are adjacent inline nodes; textContent joins "To-dos" +
|
||||
// "1/3…" with no space (visual gap is CSS gap: 10px, not a text node).
|
||||
expect({
|
||||
row: visibleText(row),
|
||||
rowState: row.getAttribute('data-state'),
|
||||
panelHeader: visibleText(panel.querySelector('button') ?? panel),
|
||||
panelItems: [...panel.querySelectorAll('li')].map(item => ({
|
||||
status: item.getAttribute('data-status'),
|
||||
text: visibleText(item),
|
||||
})),
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"panelHeader": "To-dos1/3 tasks · 1 in progress",
|
||||
"panelItems": [],
|
||||
"row": "更新任务清单1/3 已完成 · 实现 fixture 样本",
|
||||
"rowState": "ok",
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('expands the default-collapsed plan strip and restores its folded state', async () => {
|
||||
boot()
|
||||
await openFixtureSession()
|
||||
|
||||
const panel = document.querySelector('[data-testid="todo-panel"]')
|
||||
if (panel === null) throw new Error('todo panel missing from the input dock')
|
||||
const header = panel.querySelector('button')
|
||||
if (header === null) throw new Error('todo panel header missing')
|
||||
|
||||
expect({
|
||||
collapsedHeader: visibleText(header),
|
||||
expanded: header.getAttribute('aria-expanded'),
|
||||
listGone: panel.querySelector('ul') === null,
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"collapsedHeader": "To-dos1/3 tasks · 1 in progress",
|
||||
"expanded": "false",
|
||||
"listGone": true,
|
||||
}
|
||||
`)
|
||||
|
||||
fireEvent.click(header)
|
||||
expect(panel.querySelectorAll('li')).toHaveLength(3)
|
||||
expect(header.getAttribute('aria-expanded')).toBe('true')
|
||||
|
||||
fireEvent.click(header)
|
||||
expect(panel.querySelector('ul')).toBeNull()
|
||||
expect(header.getAttribute('aria-expanded')).toBe('false')
|
||||
})
|
||||
|
||||
it('hides the plan strip when the next turn starts', async () => {
|
||||
boot()
|
||||
await openFixtureSession()
|
||||
expect(document.querySelector('[data-testid="todo-panel"]')).not.toBeNull()
|
||||
|
||||
const composer = await screen.findByPlaceholderText('给智能体发消息', {}, { timeout: 10_000 })
|
||||
fireEvent.change(composer, { target: { value: '下一轮清空计划' } })
|
||||
fireEvent.keyDown(composer, { key: 'Enter' })
|
||||
|
||||
await screen.findByText('下一轮清空计划', { exact: true }, { timeout: 10_000 })
|
||||
await waitFor(() => {
|
||||
expect(document.querySelector('[data-testid="todo-panel"]')).toBeNull()
|
||||
}, { timeout: 10_000 })
|
||||
|
||||
expect({
|
||||
promptVisible: screen.getByText('下一轮清空计划', { exact: true }).textContent,
|
||||
panelGone: document.querySelector('[data-testid="todo-panel"]') === null,
|
||||
// Historical todo_write row stays in the flow; only the dock strip clears.
|
||||
rowStillPresent: document.querySelector('[data-sample="todo-row"]') !== null,
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"panelGone": true,
|
||||
"promptVisible": "下一轮清空计划",
|
||||
"rowStillPresent": true,
|
||||
}
|
||||
`)
|
||||
})
|
||||
@@ -1,397 +0,0 @@
|
||||
// @vitest-environment jsdom
|
||||
// Assembled keyless snapshots of the New Session flow under the agent-parity
|
||||
// model: startup auto-connects the recent Workspace's blank session when one
|
||||
// exists; without any Workspace the composer is locked in the pure view
|
||||
// state until one is chosen. Picking one materializes the full Session+Agent
|
||||
// (reuse-or-create of the workspace's blank session), the first ACCEPTED
|
||||
// prompt flips blank and surfaces the session in lists, and failures leave
|
||||
// no client-side transaction state: a failed attach keeps the view state
|
||||
// locked, a rejected prompt keeps the session blank with the draft restored.
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { act, cleanup, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import type { WebBootEntry } from '@deepseek-ai/dsh-client-modules/client'
|
||||
import { AppWebEntry } from '@deepseek-ai/dsh-client-web'
|
||||
|
||||
const PLUGINS: readonly (WebBootEntry & { dir: string })[] = [
|
||||
{ id: '@deepseek-ai/dsh-client-connection', dir: 'connection', url: '/plugins/connection.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-runtime', dir: 'runtime', url: '/plugins/runtime.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-connection'], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-theme', dir: 'ui-theme', url: '/plugins/ui-theme.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-locale', dir: 'locale', url: '/plugins/locale.js', rev: 'fx', inject: [], immediately: true },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-layout', dir: 'ui-layout', url: '/plugins/ui-layout.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-runtime'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-sidebar', dir: 'ui-sidebar', url: '/plugins/ui-sidebar.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-settings', dir: 'ui-settings', url: '/plugins/ui-settings.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-sidebar'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-settings-general', dir: 'ui-settings-general', url: '/plugins/ui-settings-general.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-settings', '@deepseek-ai/dsh-client-locale'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-models', dir: 'ui-models', url: '/plugins/ui-models.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-settings'] },
|
||||
{ id: '@deepseek-ai/dsh-client-ui-conversation', dir: 'ui-conversation', url: '/plugins/ui-conversation.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-layout'] },
|
||||
{
|
||||
id: '@deepseek-ai/dsh-client-ui-workspace',
|
||||
dir: 'ui-workspace',
|
||||
url: '/plugins/ui-workspace.js',
|
||||
rev: 'fx',
|
||||
inject: [
|
||||
'@deepseek-ai/dsh-client-runtime',
|
||||
'@deepseek-ai/dsh-client-ui-conversation',
|
||||
'@deepseek-ai/dsh-client-ui-sidebar',
|
||||
],
|
||||
},
|
||||
{ id: '@deepseek-ai/dsh-client-ui-trajectory', dir: 'ui-trajectory', url: '/plugins/ui-trajectory.js', rev: 'fx', inject: ['@deepseek-ai/dsh-client-ui-conversation'] },
|
||||
// Dual-face host package: its browser half fills the directory-flow holes
|
||||
// (the same composition row apps/cli mounts for the node-side backend).
|
||||
{
|
||||
id: '@deepseek-ai/dsh-host-directory-picker-browse',
|
||||
dir: '../host/directory-picker-browse',
|
||||
url: '/plugins/directory-picker-browse.js',
|
||||
rev: 'fx',
|
||||
inject: ['@deepseek-ai/dsh-client-runtime', '@deepseek-ai/dsh-client-ui-workspace', '@deepseek-ai/dsh-client-locale'],
|
||||
},
|
||||
]
|
||||
|
||||
const bundles = new Map(PLUGINS.map(plugin => [
|
||||
plugin.url,
|
||||
readFileSync(join(process.cwd(), 'packages/client', plugin.dir, 'lib/client.js'), 'utf8'),
|
||||
]))
|
||||
|
||||
interface FixtureWindow extends Window {
|
||||
__DSH_BOOT__?: { rev: string; entries: WebBootEntry[] }
|
||||
__ModuleLoader__?: unknown
|
||||
}
|
||||
|
||||
class ResizeObserverStub {
|
||||
observe(): void {}
|
||||
disconnect(): void {}
|
||||
unobserve(): void {}
|
||||
}
|
||||
|
||||
const win = window as FixtureWindow
|
||||
let unmount: (() => void) | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
document.title = 'DeepSeek Harness'
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) =>
|
||||
setTimeout(() => { callback(0) }, 0) as unknown as number)
|
||||
vi.stubGlobal('cancelAnimationFrame', (id: number) => { clearTimeout(id) })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
act(() => { unmount?.() })
|
||||
unmount = undefined
|
||||
cleanup()
|
||||
delete win.__DSH_BOOT__
|
||||
delete win.__ModuleLoader__
|
||||
delete (globalThis as Record<string, unknown>).__fxTiming
|
||||
document.body.innerHTML = ''
|
||||
document.head.querySelectorAll('style[data-plugin]').forEach((style) => { style.remove() })
|
||||
document.title = ''
|
||||
history.replaceState(null, '', '/')
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
/** Boot the complete built client graph against one keyless fixture branch. */
|
||||
function boot(search: string): void {
|
||||
history.replaceState(null, '', `/${search}`)
|
||||
const root = document.createElement('div')
|
||||
root.id = 'root'
|
||||
document.body.appendChild(root)
|
||||
win.__DSH_BOOT__ = { rev: 'fx', entries: PLUGINS.map(({ dir: _dir, ...plugin }) => plugin) }
|
||||
act(() => {
|
||||
const entry = new AppWebEntry(root, {
|
||||
fetchBundle: (url) => {
|
||||
const code = bundles.get(url)
|
||||
return code === undefined ? Promise.reject(new Error(`missing built bundle ${url}`)) : Promise.resolve(code)
|
||||
},
|
||||
executeBundle: (code) => { (0, eval)(code) },
|
||||
})
|
||||
void entry.run()
|
||||
unmount = () => { entry.dispose() }
|
||||
})
|
||||
}
|
||||
|
||||
/** Collapse decorative whitespace while preserving the text a user sees. */
|
||||
function visibleText(element: Element): string {
|
||||
return (element.textContent ?? '').replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
|
||||
/** Identify the interactive Workspace chip (view state or blank-session hero) by its menu contract. */
|
||||
function workspaceChip(): HTMLElement {
|
||||
const chip = screen.getAllByRole('button', { name: 'Choose workspace' })
|
||||
.find(element => element.getAttribute('aria-haspopup') === 'menu')
|
||||
if (chip === undefined) throw new Error('Workspace chip missing')
|
||||
return chip
|
||||
}
|
||||
|
||||
/** The locked view-state composer (no session yet). */
|
||||
async function findLockedComposer(): Promise<HTMLTextAreaElement> {
|
||||
return await screen.findByPlaceholderText(
|
||||
'Choose a workspace to start', {}, { timeout: 10_000 },
|
||||
)
|
||||
}
|
||||
|
||||
/** The live blank-session hero composer (session materialized). */
|
||||
async function findHeroComposer(): Promise<HTMLTextAreaElement> {
|
||||
return await screen.findByPlaceholderText(
|
||||
'Describe what you want to build', {}, { timeout: 10_000 },
|
||||
)
|
||||
}
|
||||
|
||||
/** Edit the machine-owned controlled input and assert the same-tick echo. */
|
||||
function setComposerText(composer: HTMLElement, value: string): void {
|
||||
fireEvent.change(composer, { target: { value } })
|
||||
expect((composer as HTMLTextAreaElement).value).toBe(value)
|
||||
}
|
||||
|
||||
/** Drive the picker's create flow: chip → Create a new workspace → name dialog. */
|
||||
async function createWorkspaceViaPicker(name: string): Promise<void> {
|
||||
fireEvent.click(workspaceChip())
|
||||
fireEvent.click(await screen.findByRole('menuitem', { name: 'Create a new workspace' }))
|
||||
const dialog = await screen.findByRole('dialog', { name: 'Create a new workspace' })
|
||||
fireEvent.change(within(dialog).getByRole('textbox', { name: 'New workspace name' }), {
|
||||
target: { value: name },
|
||||
})
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: 'Create workspace' }))
|
||||
}
|
||||
|
||||
/** Pick an existing Workspace row from the chip menu. */
|
||||
async function pickWorkspace(title: string): Promise<void> {
|
||||
fireEvent.click(workspaceChip())
|
||||
fireEvent.click(await screen.findByRole('menuitem', { name: title }))
|
||||
}
|
||||
|
||||
it('locks the composer in the New Session view state until a Workspace is chosen', async () => {
|
||||
boot('?fixture=empty')
|
||||
|
||||
const composer = await findLockedComposer()
|
||||
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
||||
|
||||
expect({
|
||||
headline: visibleText(screen.getByText("Let's start building")),
|
||||
chip: visibleText(workspaceChip()),
|
||||
composerDisabled: composer.disabled,
|
||||
sendDisabled: screen.getByRole<HTMLButtonElement>('button', { name: 'Send message' }).disabled,
|
||||
sidebar: visibleText(tree),
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"chip": "Choose workspace",
|
||||
"composerDisabled": true,
|
||||
"headline": "Let's start building",
|
||||
"sendDisabled": true,
|
||||
"sidebar": "No sessions yet",
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('adopts a directory through the composed in-app browse flow and lands in its blank session', async () => {
|
||||
boot('?fixture=empty')
|
||||
|
||||
await findLockedComposer()
|
||||
fireEvent.click(workspaceChip())
|
||||
const menu = await screen.findByRole('menu')
|
||||
// The composed flow package occupies the directory-flow hole, so the
|
||||
// picking affordance is present (no advertised-kind read exists anymore).
|
||||
expect(within(menu).getAllByRole('menuitem').map(item => visibleText(item)))
|
||||
.toEqual(['Open local folder…', 'Create a new workspace'])
|
||||
fireEvent.click(within(menu).getByRole('menuitem', { name: 'Open local folder…' }))
|
||||
// The browse occupant renders the Select Workspace Directory dialog at the
|
||||
// fixture home; select Documents, advance into project, and adopt it.
|
||||
const dialog = await screen.findByRole('dialog', { name: '选择工作区目录' }, { timeout: 10_000 })
|
||||
// Row targeting goes through the visible label text: listitem accessible-name
|
||||
// computation differs across dom-accessibility-api environments, while the
|
||||
// row's name span is stable (clicks bubble to the row button).
|
||||
fireEvent.click(await within(dialog).findByText('Documents', {}, { timeout: 10_000 }))
|
||||
fireEvent.click(await within(dialog).findByText('project', {}, { timeout: 10_000 }))
|
||||
// Open disables while the selection's child listing is in flight; wait for
|
||||
// the enabled state or the click lands on a dead button on slow runners.
|
||||
await waitFor(() => {
|
||||
expect(within(dialog).getByRole<HTMLButtonElement>('button', { name: '打开' }).disabled).toBe(false)
|
||||
}, { timeout: 10_000 })
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: '打开' }))
|
||||
await findHeroComposer()
|
||||
await waitFor(() => {
|
||||
expect(visibleText(screen.getByRole('tree', { name: 'Sessions' }))).toContain('project')
|
||||
})
|
||||
})
|
||||
|
||||
it('selects the recent Workspace and opens its blank Session on first load', async () => {
|
||||
boot('?fixture')
|
||||
|
||||
const composer = await findHeroComposer()
|
||||
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
||||
await waitFor(() => { expect(within(tree).getByText('4 sessions')).toBeDefined() }, { timeout: 10_000 })
|
||||
|
||||
expect({
|
||||
chip: visibleText(workspaceChip()),
|
||||
composerDisabled: composer.disabled,
|
||||
blankRow: within(tree).getByText('New Session').textContent,
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"blankRow": "New Session",
|
||||
"chip": "fixture",
|
||||
"composerDisabled": false,
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('creating a Workspace materializes and lists its selected blank Session', async () => {
|
||||
boot('?fixture=empty')
|
||||
|
||||
await findLockedComposer()
|
||||
await createWorkspaceViaPicker('nova')
|
||||
|
||||
// The pick connected the workspace: full Session+Agent exists, composer live.
|
||||
const composer = await findHeroComposer()
|
||||
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
||||
await waitFor(() => { expect(within(tree).getByText('1 session')).toBeDefined() })
|
||||
expect(within(tree).getByText('New Session')).toBeDefined()
|
||||
const group = within(tree).getByText('1 session').closest('[role="treeitem"]')
|
||||
if (group === null) throw new Error('created Workspace projection missing')
|
||||
|
||||
expect({
|
||||
composerDisabled: composer.disabled,
|
||||
chip: visibleText(workspaceChip()),
|
||||
workspace: visibleText(group),
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"chip": "nova",
|
||||
"composerDisabled": false,
|
||||
"workspace": "nova1 session",
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('New Session reuses the Workspace blank session and converts the single visible row', async () => {
|
||||
boot('?fixture=empty')
|
||||
|
||||
await findLockedComposer()
|
||||
await createWorkspaceViaPicker('nova')
|
||||
await findHeroComposer()
|
||||
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
||||
await waitFor(() => { expect(within(tree).getByText('1 session')).toBeDefined() }, { timeout: 10_000 })
|
||||
|
||||
// New Session resolves through the recent Workspace and reuses its blank
|
||||
// session in place: no locked interlude, no second entity.
|
||||
const newSessionButton = screen.getAllByRole('button', { name: 'New session' })
|
||||
.find(button => visibleText(button) === 'New Session')
|
||||
if (newSessionButton === undefined) throw new Error('New Session button missing')
|
||||
fireEvent.click(newSessionButton)
|
||||
const composer = await findHeroComposer()
|
||||
await waitFor(() => { expect(within(tree).getByText('1 session')).toBeDefined() }, { timeout: 10_000 })
|
||||
|
||||
setComposerText(composer, 'first light')
|
||||
fireEvent.keyDown(composer, { key: 'Enter' })
|
||||
|
||||
// Conversion: the accepted prompt flips blank without adding a second row.
|
||||
await screen.findByText('first light', { exact: true }, { timeout: 10_000 })
|
||||
await waitFor(() => { expect(within(tree).getByText('1 session')).toBeDefined() }, { timeout: 10_000 })
|
||||
const group = within(tree).getByText('1 session').closest('[role="treeitem"]')
|
||||
if (group === null) throw new Error('converted Session projection missing')
|
||||
|
||||
expect({
|
||||
workspace: visibleText(group),
|
||||
promptVisible: screen.getByText('first light', { exact: true }).textContent,
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"promptVisible": "first light",
|
||||
"workspace": "nova1 session",
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('a failed Workspace attach recovers by reusing the published blank session', async () => {
|
||||
boot('?fixture&fixtureAttach=fail')
|
||||
|
||||
// The rejected startup connect surfaces the locked view state first: the
|
||||
// failure leaves no client-side transaction state to unwind.
|
||||
await findLockedComposer()
|
||||
|
||||
// The host published the session before rejecting attachment (blank, with
|
||||
// the workspace cwd), so the next connect — retry or manual pick — reuses
|
||||
// it instead of minting a duplicate, and the hero opens on it.
|
||||
await pickWorkspace('fixture')
|
||||
const composer = await findHeroComposer()
|
||||
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
||||
const group = within(tree).getByText('3 sessions').closest('[role="treeitem"]')
|
||||
if (group === null) throw new Error('fixture Workspace projection missing')
|
||||
|
||||
expect({
|
||||
headline: visibleText(screen.getByText("Let's start building")),
|
||||
composerDisabled: composer.disabled,
|
||||
chip: visibleText(workspaceChip()),
|
||||
workspace: visibleText(group),
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"chip": "fixture",
|
||||
"composerDisabled": false,
|
||||
"headline": "Let's start building",
|
||||
"workspace": "fixture3 sessions",
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('a rejected first prompt keeps the session blank and the draft in the machine', async () => {
|
||||
boot('?fixture=empty&fixturePrompt=reject')
|
||||
|
||||
await findLockedComposer()
|
||||
await createWorkspaceViaPicker('nova')
|
||||
const composer = await findHeroComposer()
|
||||
|
||||
setComposerText(composer, 'do not lose this')
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Send message' }))
|
||||
|
||||
const alert = await screen.findByRole('alert', {}, { timeout: 10_000 })
|
||||
// Failure restore rides the machine (no pendingPrompt transaction): the
|
||||
// draft returns to the same resident textarea one render later. The
|
||||
// attempt flips the composer out of the hero (engaging = retry chrome),
|
||||
// but acceptance never happened: the session row stays New Session.
|
||||
const retained = await screen.findByDisplayValue('do not lose this')
|
||||
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
||||
const group = within(tree).getByText('1 session').closest('[role="treeitem"]')
|
||||
if (group === null) throw new Error('rejected-send Workspace projection missing')
|
||||
|
||||
expect({
|
||||
error: visibleText(alert),
|
||||
prompt: (retained as HTMLTextAreaElement).value,
|
||||
blankRow: within(tree).getByText('New Session').textContent,
|
||||
workspace: visibleText(group),
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"blankRow": "New Session",
|
||||
"error": "fixture: prompt rejected before acceptance (agent-busy)",
|
||||
"prompt": "do not lose this",
|
||||
"workspace": "nova1 session",
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('switching Workspace before the first message carries the draft to the new blank session', async () => {
|
||||
boot('?fixture')
|
||||
|
||||
const composer = await findHeroComposer()
|
||||
setComposerText(composer, 'carry me')
|
||||
|
||||
// Switch = session switch: the new workspace's blank session takes over,
|
||||
// the typed draft moves machine-to-machine, the old blank stays hidden.
|
||||
await createWorkspaceViaPicker('nova')
|
||||
await waitFor(() => { expect(visibleText(workspaceChip())).toBe('nova') }, { timeout: 10_000 })
|
||||
const carried = await screen.findByDisplayValue('carry me')
|
||||
const tree = screen.getByRole('tree', { name: 'Sessions' })
|
||||
const fixtureGroup = within(tree).getByText('3 sessions').closest('[role="treeitem"]')
|
||||
const novaGroup = within(tree).getByText('1 session').closest('[role="treeitem"]')
|
||||
if (fixtureGroup === null || novaGroup === null) throw new Error('Workspace projections missing after switch')
|
||||
|
||||
expect({
|
||||
chip: visibleText(workspaceChip()),
|
||||
prompt: (carried as HTMLTextAreaElement).value,
|
||||
fixtureWorkspace: visibleText(fixtureGroup),
|
||||
novaWorkspace: visibleText(novaGroup),
|
||||
}).toMatchInlineSnapshot(`
|
||||
{
|
||||
"chip": "nova",
|
||||
"fixtureWorkspace": "fixture3 sessions",
|
||||
"novaWorkspace": "nova1 session",
|
||||
"prompt": "carry me",
|
||||
}
|
||||
`)
|
||||
})
|
||||
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write docs/architecture.md
|
||||
architecture.md: bb5414d6bb108056bf2ff25366e5afe261e1803a
|
||||
architecture.zh.md: 6d39a320019a1bf87141be0874a5a20a51fc3fbb
|
||||
architecture.md: 1fe5c1dfa4aee8c3bfe5ac634f47bb68f36afe9f
|
||||
architecture.zh.md: d754c6a2ea5bcd38524d31d02bc4f38ca2074942
|
||||
@@ -47,6 +47,7 @@ Harnesses are [Cordis](cordis-primer.md) contexts; packages contribute services,
|
||||
| `ctx.sessionQuery` | [`session-query/`](../packages/session-query/README.md) | live-preferred exact/filter/trace queries over SQLite FTS, workspace-authorized model tools |
|
||||
| `ctx.sessionTitle` | [`session-title/`](../packages/session-title/README.md) | log-backed fallbacks, one optional asynchronous provider |
|
||||
| `ctx.directoryPicker` | [`host/directory-picker`](../packages/host/directory-picker/README.md) | GUI-host directory picking (`native`/`browse` interactions) |
|
||||
| `ctx.typert` | [`typert/registry`](../packages/typert/registry/README.md) | runtime registry for generated package reflection and live Zod schemas |
|
||||
| `ctx.invariants` | [`support/invariants`](../packages/support/invariants/README.md) | package-name-selected registry of package-owned runtime checks |
|
||||
|
||||
## Event
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
| `ctx.sessionQuery` | [`session-query/`](../packages/session-query/README.md) | 基于 SQLite 全文搜索的实时优先精确检索/过滤/追踪、经工作区授权的模型工具 |
|
||||
| `ctx.sessionTitle` | [`session-title/`](../packages/session-title/README.md) | 基于日志的回退标题和单个可选异步提供方 |
|
||||
| `ctx.directoryPicker` | [`host/directory-picker`](../packages/host/directory-picker/README.md) | GUI 宿主目录选取(`native`/`browse` 交互) |
|
||||
| `ctx.typert` | [`typert/registry`](../packages/typert/registry/README.md) | 生成的包反射和实时 Zod schema 的运行时注册表 |
|
||||
| `ctx.invariants` | [`support/invariants`](../packages/support/invariants/README.md) | 按包名筛选包自有运行时检查的注册表 |
|
||||
|
||||
## 事件
|
||||
|
||||
@@ -29,6 +29,9 @@ flowchart LR
|
||||
pkg_invariants["invariants"]
|
||||
svc_invariants["ctx.invariants<br/>Package-owned invariant registry"]
|
||||
pkg_scope["scope"]
|
||||
pkg_typert_registry["typert-registry"]
|
||||
svc_typert["ctx.typert<br/>Runtime type registry"]
|
||||
pkg_typert_loader["typert-loader"]
|
||||
svc_sessionPersistence["ctx.sessionPersistence<br/>Durable session persistence seam"]
|
||||
pkg_session_persistence_jsonl["session-persistence-jsonl"]
|
||||
pkg_session_persistence_sqlite["session-persistence-sqlite"]
|
||||
@@ -224,6 +227,7 @@ flowchart LR
|
||||
pkg_tools --> svc_tools
|
||||
pkg_tui --> svc_tui
|
||||
pkg_tui --> svc_userInteraction
|
||||
pkg_typert_registry --> svc_typert
|
||||
pkg_user_interaction --> svc_userInteraction
|
||||
pkg_web --> svc_web
|
||||
pkg_web_fetch_local --> svc_web
|
||||
@@ -318,6 +322,7 @@ flowchart LR
|
||||
svc_tools --> pkg_tool_subagent
|
||||
svc_tools --> pkg_tool_todo
|
||||
svc_tools --> pkg_tool_web
|
||||
svc_typert --> pkg_typert_loader
|
||||
svc_userInteraction --> pkg_tool_ask_user
|
||||
svc_userInteraction --> pkg_tui
|
||||
svc_web --> pkg_tool_web
|
||||
@@ -334,6 +339,7 @@ flowchart LR
|
||||
| `ctx.toolResultPrune` | `core` | [`compact-tool-result-prune`](../packages/compact/compact-tool-result-prune) | - | [`compact-basic`](../packages/compact/compact-basic) | - | Rewrites oversized current tool results through replayable single-node surface replacements before summary compaction. |
|
||||
| `ctx.sessions` | `core` | [`session`](../packages/core/session) | - | [`agent-loop`](../packages/core/agent-loop), [`agent`](../packages/core/agent), [`cli-demo`](../packages/examples/cli-demo), [`session-persistence`](../packages/session-persistence/session-persistence), [`session-query`](../packages/session-query/session-query), [`session-query-sqlite`](../packages/session-query/session-query-sqlite), [`subagent-inprocess`](../packages/subagent/subagent-inprocess), [`invariants`](../packages/support/invariants) | - | Owns append-only Session instances and emits the durable session event feed. |
|
||||
| `ctx.invariants` | `core` | [`invariants`](../packages/support/invariants) | - | [`session`](../packages/core/session), [`agent`](../packages/core/agent), [`scope`](../packages/core/scope), [`agent-loop`](../packages/core/agent-loop) | - | Companion subpaths register owner-local checks; the service owns selection, uniqueness, child fibers, and package-attributed failures. |
|
||||
| `ctx.typert` | `core` | [`typert-registry`](../packages/typert/registry) | - | [`typert-loader`](../packages/typert/loader) | - | Plugins register live zod contributions directly or through dsh-typert-loader; runtime consumers query schemas and reflection metadata at their own edges. |
|
||||
| `ctx.sessionPersistence` | `seam` | [`session-persistence`](../packages/session-persistence/session-persistence) | [`session-persistence-jsonl`](../packages/session-persistence/session-persistence-jsonl), [`session-persistence-sqlite`](../packages/session-persistence/session-persistence-sqlite) | [`agent-loop`](../packages/core/agent-loop), [`tool-bash`](../packages/bash/tool-bash), [`hooks-claude`](../packages/hooks/hooks-claude), [`hooks-codex`](../packages/hooks/hooks-codex), [`session-query`](../packages/session-query/session-query), [`session-query-sqlite`](../packages/session-query/session-query-sqlite) | - | Backends persist the same SessionEvent vocabulary; apps choose a backend at composition time. |
|
||||
| `ctx.telemetry` | `seam` | [`session-telemetry`](../packages/telemetry/session-telemetry) | [`session-telemetry-otel`](../packages/telemetry/session-telemetry-otel) | - | - | The seam captures, redacts, and hands session records to one backend; nothing else consumes the service — its output leaves the process. |
|
||||
| `ctx.storage` | `seam` | [`storage`](../packages/storage/storage) | [`storage-json`](../packages/storage/storage-json), [`storage-sqlite`](../packages/storage/storage-sqlite) | [`storage-domain`](../packages/storage/storage-domain) | - | Backends register side by side under names; data forms (domain first) mount on the hub and translate typed operations into opaque KV-unit primitives. |
|
||||
|
||||
@@ -2022,6 +2022,20 @@ Depends on: [`agentCore`](../packages/examples/agent-spine-demo/src/index.ts) ·
|
||||
|
||||
Source: [`packages/examples/tui-demo/src/index.ts:39`](../packages/examples/tui-demo/src/index.ts)
|
||||
|
||||
## `@deepseek-ai/dsh-typert-loader`
|
||||
|
||||
Requires: `typert` · `loader`
|
||||
|
||||
```ts config-catalog
|
||||
/** Additional package artifacts whose owning plugins are nested behind another Loader entry. */
|
||||
export interface Config {
|
||||
/** Exact npm package names that must resolve and export `./typert`. */
|
||||
packages?: string[]
|
||||
}
|
||||
```
|
||||
|
||||
Source: [`packages/typert/loader/src/index.ts:47`](../packages/typert/loader/src/index.ts)
|
||||
|
||||
## `@deepseek-ai/dsh-user-approval`
|
||||
|
||||
```ts config-catalog
|
||||
@@ -2264,6 +2278,7 @@ These load from a `cordis.yml` entry with no `config:` block; they declare no co
|
||||
- `@deepseek-ai/dsh-timeout-policy` — requires `tools` ([`packages/timeout/timeout-policy/src/index.ts`](../packages/timeout/timeout-policy/src/index.ts))
|
||||
- `@deepseek-ai/dsh-tool-ask-user` — requires `tools` · `userInteraction` ([`packages/ui/tool-ask-user/src/index.ts`](../packages/ui/tool-ask-user/src/index.ts))
|
||||
- `@deepseek-ai/dsh-tool-todo` — requires `tools` ([`packages/todo/tool-todo/src/index.ts`](../packages/todo/tool-todo/src/index.ts))
|
||||
- `@deepseek-ai/dsh-typert-registry` ([`packages/typert/registry/src/index.ts`](../packages/typert/registry/src/index.ts))
|
||||
- `@deepseek-ai/dsh-user-interaction` ([`packages/ui/user-interaction/src/index.ts`](../packages/ui/user-interaction/src/index.ts))
|
||||
- `@deepseek-ai/dsh-workspace` — requires `storageDomain` · `sessionPersistence` ([`packages/workspace/workspace/src/index.ts`](../packages/workspace/workspace/src/index.ts))
|
||||
|
||||
@@ -2315,3 +2330,4 @@ Imported as libraries by other packages; a `cordis.yml` cannot load them.
|
||||
- `@deepseek-ai/dsh-subagent-inprocess` ([`packages/subagent/subagent-inprocess/src/index.ts`](../packages/subagent/subagent-inprocess/src/index.ts))
|
||||
- `@deepseek-ai/dsh-telemetry` ([`packages/sdk/telemetry/src/index.ts`](../packages/sdk/telemetry/src/index.ts))
|
||||
- `@deepseek-ai/dsh-timeout` ([`packages/util/timeout/src/index.ts`](../packages/util/timeout/src/index.ts))
|
||||
- `@deepseek-ai/dsh-typert-generator` ([`packages/typert/generator/src/index.ts`](../packages/typert/generator/src/index.ts))
|
||||
@@ -9,7 +9,7 @@ This file is GENERATED from source (`scripts/gen-cordis-catalog.ts`) and verifie
|
||||
|
||||
The **harness tier** below (the `@deepseek-ai/dsh-*` packages) is the vocabulary this repo owns, grouped by scope. The **inherited tier** at the end is the cordis-core + loader/hmr/timer event surface a plugin also sees — pinned vendor source, summarized tersely. The event-dispatch methods themselves are generated in the [Cordis core Events API](core/events.md).
|
||||
|
||||
Dispatch modes: **emit** (fire-and-forget), **waterfall** (each listener gets `next()` and may transform or veto — see [waterfall semantics](../cordis-primer.md#cordis-waterfall-semantics)), **parallel** (awaited fan-out; all listeners run), **serial** (awaited in registration order until one returns a bail value — anything other than `null`, `false`, or `undefined`), **bail** (synchronous in-order dispatch until one listener returns a bail value; the scoped input-mutation events use it for an applied/not-applied answer).
|
||||
Dispatch modes: **emit** (fire-and-forget), **waterfall** (each listener gets `next()` and may transform or veto — see [waterfall semantics](../cordis-primer.md#cordis-waterfall-semantics)), **parallel** (awaited fan-out; all listeners run), **serial** (awaited in registration order until one returns a bail value — anything other than `null`, `false`, or `undefined`).
|
||||
|
||||
## `agent/*`
|
||||
|
||||
@@ -32,7 +32,7 @@ Effective broad cancellation was requested, before queued/outbox work is cleared
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [AgentCancelCause](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:286`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:289`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/created` — emit
|
||||
|
||||
@@ -54,7 +54,7 @@ A fully configured agent and live session were published. Setup is composition-o
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:218`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:221`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/disposed` — emit
|
||||
|
||||
@@ -74,7 +74,7 @@ An agent left the registry; AgentLoop emits this after driver quiescence and sco
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:227`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:230`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/error` — emit
|
||||
|
||||
@@ -96,7 +96,7 @@ A step or turn errored. The machine reports a failure here (plus the logger) eve
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:400`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:403`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/inbox/dequeue` — emit
|
||||
|
||||
@@ -119,7 +119,7 @@ The driver claimed one item out of the inbox: a queued item at a turn boundary,
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [InboxPlacement](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md) · [UserMessage](../core-data-structures/session.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:259`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:262`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/inbox/discard` — emit
|
||||
|
||||
@@ -142,7 +142,7 @@ Pending inbox items were dropped without delivering them, so every enqueue occur
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md) · [UserMessage](../core-data-structures/session.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:276`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:279`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/inbox/enqueue` — emit
|
||||
|
||||
@@ -164,7 +164,7 @@ An item entered the queued or steering inbox. `placement` is the acceptance-time
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [InboxPlacement](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md) · [UserMessage](../core-data-structures/session.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:247`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:250`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/prompt-submit` — waterfall
|
||||
|
||||
@@ -187,7 +187,7 @@ Allow, rewrite, or block one claimed prompt before it becomes a user message or
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [PromptDecision](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md) · [UserMessage](../core-data-structures/session.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:313`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:316`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/request` — waterfall
|
||||
|
||||
@@ -211,7 +211,7 @@ Replace the frozen call configuration. `await next()` yields the config the mach
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [LlmCallConfig](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:339`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:342`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/request-error` — waterfall
|
||||
|
||||
@@ -241,7 +241,7 @@ Handle a model-request failure after its failed step has closed but before the f
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [LlmFailure](../core-data-structures/llm-streaming.md) · [RequestError](../core-data-structures/core.md) · [RequestErrorAction](../core-data-structures/core.md) · [ResolvedRetryPolicy](../core-data-structures/llm-streaming.md) · [Scoped](../core-data-structures/scope.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:358`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:361`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/session-start` — emit
|
||||
|
||||
@@ -263,7 +263,7 @@ The session lifecycle began, once before the first turn. Use `agent.inject()` to
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md) · [SessionStartSource](../core-data-structures/core.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:299`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:302`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/settled` — emit
|
||||
|
||||
@@ -288,7 +288,7 @@ One drain chain reached its terminal turn: that turn's `turn/end` is already com
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md) · [SettleReason](../core-data-structures/core.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:387`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:390`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/status` — emit
|
||||
|
||||
@@ -308,7 +308,7 @@ Agent status changed (`idle` ⇄ `running`). `send()` does not enter `running` s
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [AgentStatus](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:236`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:239`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/step` — serial
|
||||
|
||||
@@ -332,7 +332,7 @@ Awaited serial checkpoint before EVERY request of a turn is built (the first as
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:326`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:329`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
### `agent/turn-stopping` — serial
|
||||
|
||||
@@ -358,7 +358,7 @@ The turn is about to close: the model owes no response (no live tool calls, no f
|
||||
|
||||
Types: [Agent](../core-data-structures/core.md) · [Scoped](../core-data-structures/scope.md)
|
||||
|
||||
Source: [`packages/core/agent/src/types.ts:373`](../../packages/core/agent/src/types.ts)
|
||||
Source: [`packages/core/agent/src/types.ts:376`](../../packages/core/agent/src/types.ts)
|
||||
|
||||
## `agent-loop/*`
|
||||
|
||||
@@ -661,75 +661,6 @@ A skill provider, runtime contribution, or provider-backed catalog may have chan
|
||||
|
||||
Source: [`packages/skill/skill/src/index.ts:188`](../../packages/skill/skill/src/index.ts)
|
||||
|
||||
## `slash/*`
|
||||
|
||||
### `slash/input-begin-command` — bail
|
||||
|
||||
Applies one command claim to the scoped Input. Dispatched with the session's scope carrier; the owning session's input listener returns `true` only after the phase and span CAS checks pass and the machine actually mutated — producers treat anything else as "not applied".
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Applies one command claim to the scoped Input. Dispatched with the
|
||||
* session's scope carrier; the owning session's input listener returns
|
||||
* `true` only after the phase and span CAS checks pass and the machine
|
||||
* actually mutated — producers treat anything else as "not applied".
|
||||
* @param request - Claim and menu-time span CAS.
|
||||
* @mode bail
|
||||
*/
|
||||
'slash/input-begin-command'(request: BeginCommandRequest): true | undefined
|
||||
```
|
||||
|
||||
Source: [`packages/client/ui-slash/src/types.ts:232`](../../packages/client/ui-slash/src/types.ts)
|
||||
|
||||
### `slash/input-consume-token` — bail
|
||||
|
||||
Consumes one command token after business success (popup settle / menu-pick execute). Same carrier routing and applied-truth contract.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Consumes one command token after business success (popup settle /
|
||||
* menu-pick execute). Same carrier routing and applied-truth contract.
|
||||
* @param request - Exact span or bare-token guard.
|
||||
* @mode bail
|
||||
*/
|
||||
'slash/input-consume-token'(request: ConsumeTokenRequest): true | undefined
|
||||
```
|
||||
|
||||
Source: [`packages/client/ui-slash/src/types.ts:246`](../../packages/client/ui-slash/src/types.ts)
|
||||
|
||||
### `slash/input-insert-reference` — bail
|
||||
|
||||
Inserts one reference into the scoped Input (same carrier routing and applied-truth contract as begin-command).
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Inserts one reference into the scoped Input (same carrier routing and
|
||||
* applied-truth contract as begin-command).
|
||||
* @param request - Reference and menu-time span CAS.
|
||||
* @mode bail
|
||||
*/
|
||||
'slash/input-insert-reference'(request: InsertReferenceRequest): true | undefined
|
||||
```
|
||||
|
||||
Source: [`packages/client/ui-slash/src/types.ts:239`](../../packages/client/ui-slash/src/types.ts)
|
||||
|
||||
### `slash/input-insert-text` — bail
|
||||
|
||||
Replaces the trigger token span with literal text — the plain-text reference path (decision 21). Same carrier routing and applied-truth contract; the draft gains ordinary characters, no occurrence entry.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Replaces the trigger token span with literal text — the plain-text
|
||||
* reference path (decision 21). Same carrier routing and applied-truth
|
||||
* contract; the draft gains ordinary characters, no occurrence entry.
|
||||
* @param request - Replacement text and menu-time span CAS.
|
||||
* @mode bail
|
||||
*/
|
||||
'slash/input-insert-text'(request: InsertTextRequest): true | undefined
|
||||
```
|
||||
|
||||
Source: [`packages/client/ui-slash/src/types.ts:254`](../../packages/client/ui-slash/src/types.ts)
|
||||
|
||||
## `subagent/*`
|
||||
|
||||
### `subagent/end` — emit
|
||||
|
||||
@@ -978,7 +978,7 @@ signal(owner: Agent, id: PtySessionId, signal: PtySignal): Promise<PtySignalResu
|
||||
* @param reason - diagnostic cleanup reason.
|
||||
* @returns true for a newly closed session, false when the same close is already in flight.
|
||||
*/
|
||||
async kill(owner: Agent, id: PtySessionId, reason = 'model request'): Promise<boolean>
|
||||
async kill(owner: Agent, id: PtySessionId, reason: string = 'model request'): Promise<boolean>
|
||||
|
||||
/**
|
||||
* List fresh snapshots for exactly one owner.
|
||||
@@ -1447,7 +1447,7 @@ Exact-read consumer that prepares immutable cross-session message context.
|
||||
* @param signal - optional cancellation boundary for host autocomplete teardown.
|
||||
* @returns candidates labeled by latest title or, when absent, session id.
|
||||
*/
|
||||
async listCandidates( agent: Agent, query = '', limit = this.config.candidateLimit, signal?: AbortSignal, ): Promise<SessionReferenceCandidate[]>
|
||||
async listCandidates( agent: Agent, query: string = '', limit: number = this.config.candidateLimit, signal?: AbortSignal, ): Promise<SessionReferenceCandidate[]>
|
||||
|
||||
/**
|
||||
* Snapshot all references before enqueue and return one aggregated durable context.
|
||||
@@ -1590,7 +1590,7 @@ fork(source: SessionForkSource, boundary?: number, childSessionId?: SessionId):
|
||||
|
||||
Types: [CreateSessionOptions](../core-data-structures/persistence.md) · [Session](../core-data-structures/session.md) · [SessionId](../core-data-structures/core.md)
|
||||
|
||||
Source: [`packages/core/session/src/index.ts:694`](../../packages/core/session/src/index.ts)
|
||||
Source: [`packages/core/session/src/index.ts:695`](../../packages/core/session/src/index.ts)
|
||||
|
||||
## `ctx.sessionTitle` — `SessionTitleService`
|
||||
|
||||
@@ -2199,6 +2199,67 @@ abstract openOverlay(request: TuiOverlayRequest): TuiOverlaySession
|
||||
|
||||
Source: [`packages/ui/tui/src/index.ts:247`](../../packages/ui/tui/src/index.ts)
|
||||
|
||||
## `ctx.typert` — `TypertRegistry`
|
||||
|
||||
Registry of generated schemas and package reflection.
|
||||
|
||||
```ts cordis-catalog
|
||||
/**
|
||||
* Register one generated contribution atomically for the calling fiber.
|
||||
* Duplicate package-face identities or schema keys reject the whole batch.
|
||||
* @param contribution - generated schemas and package metadata.
|
||||
* @returns the exact effect disposer that removes this contribution.
|
||||
*/
|
||||
register(contribution: TypertContribution): () => void
|
||||
|
||||
/**
|
||||
* Look up one schema by `<package>#<name>`.
|
||||
* @param key - global schema key.
|
||||
* @returns the live schema record, or `undefined` when absent.
|
||||
*/
|
||||
get(key: string): TypertSchemaRecord | undefined
|
||||
|
||||
/**
|
||||
* Resolve one required schema.
|
||||
* @param key - global schema key.
|
||||
* @returns the live schema record.
|
||||
* @throws when the key is malformed, the package face is absent, or the schema is not contributed.
|
||||
*/
|
||||
resolve(key: string): TypertSchemaRecord
|
||||
|
||||
/**
|
||||
* Enumerate live schemas in registration order.
|
||||
* @param filter - optional package and face restriction.
|
||||
* @returns matching schema records.
|
||||
*/
|
||||
list(filter: TypertSchemaFilter = {}): TypertSchemaRecord[]
|
||||
|
||||
/**
|
||||
* Look up generated reflection for one package face.
|
||||
* @param packageName - exact npm package name.
|
||||
* @param face - face to query; defaults to the host runtime.
|
||||
* @returns the live package record, or `undefined` when absent.
|
||||
*/
|
||||
getPackage(packageName: string, face: TypertFace = 'host'): TypertPackageRecord | undefined
|
||||
|
||||
/**
|
||||
* Enumerate generated package reflection in registration order.
|
||||
* @param filter - optional package and face restriction.
|
||||
* @returns matching package records.
|
||||
*/
|
||||
listPackages(filter: TypertPackageFilter = {}): TypertPackageRecord[]
|
||||
|
||||
/**
|
||||
* Project a live Zod schema to JSON Schema without caching the result.
|
||||
* @param key - global schema key.
|
||||
* @param params - Zod projection parameters.
|
||||
* @returns a fresh JSON Schema document.
|
||||
*/
|
||||
toJSONSchema(key: string, params?: z.core.ToJSONSchemaParams): z.core.JSONSchema.BaseSchema
|
||||
```
|
||||
|
||||
Source: [`packages/typert/registry/src/index.ts:67`](../../packages/typert/registry/src/index.ts)
|
||||
|
||||
## `ctx.userInteraction` — `UserInteractionService`
|
||||
|
||||
`ctx.userInteraction`: one active UI provider plus an `ask()` surface.
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write docs/core-data-structures/core.md
|
||||
core.md: b9df539136c2661537775ba9a425bdf7ef1fd958
|
||||
core.zh.md: 1c75e8484dd1184077fe0194b2b6088230d1bbf5
|
||||
core.md: 0ab58864bf70a52554d0c4b9da10fa3fc49e9dc2
|
||||
core.zh.md: 5719c603d0d7576e9fc030e73fb9a6857fef458c
|
||||
@@ -477,7 +477,10 @@ type AgentCancelCause =
|
||||
`Agent` is an interface over the public live-agent contract. Concrete drivers own the `followup`/`steer`/`inject` aliases and route them through `send`'s (`target` × `wakeup`) matrix.
|
||||
|
||||
```ts type-equiv
|
||||
/** Public live-agent handle with aliases over the unified delivery primitive. */
|
||||
/**
|
||||
* Public live-agent handle with aliases over the unified delivery primitive.
|
||||
* @typert object
|
||||
*/
|
||||
interface Agent {
|
||||
/** The single identity shared with {@link session}. */
|
||||
readonly id: SessionId
|
||||
|
||||
@@ -485,7 +485,10 @@ type AgentCancelCause =
|
||||
`Agent` 是覆盖公开活跃 agent 契约的接口。具体驱动器拥有 `followup`/`steer`/`inject` 别名方法,并将它们经由 `send` 的(`target` × `wakeup`)矩阵路由。
|
||||
|
||||
```ts type-equiv
|
||||
/** Public live-agent handle with aliases over the unified delivery primitive. */
|
||||
/**
|
||||
* Public live-agent handle with aliases over the unified delivery primitive.
|
||||
* @typert object
|
||||
*/
|
||||
interface Agent {
|
||||
/** The single identity shared with {@link session}. */
|
||||
readonly id: SessionId
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write docs/core-data-structures/session.md
|
||||
session.md: 6ae0ab79b5c7bc3bc1859bf819ce25679672a7f0
|
||||
session.zh.md: 79ed40f7eee7a8cae05a366d646f85580c73d5d2
|
||||
session.md: fd8285eebd76e8bd7723ee86ae15427f4923f4d6
|
||||
session.zh.md: 1033bfda117b5693421f0bdf4ec3fc136039f223
|
||||
@@ -302,6 +302,7 @@ The body-stripped declaration keeps the plain class's public constructor, state
|
||||
*
|
||||
* Plain class (not a Service) — create instances via `ctx.sessions.create()`.
|
||||
* Seeding with an existing event log replays/forks a session.
|
||||
* @typert object
|
||||
*/
|
||||
declare class Session {
|
||||
/** The ordered surface over this session's event log. */
|
||||
|
||||
@@ -304,6 +304,7 @@ interface SurfaceFoldResult {
|
||||
*
|
||||
* Plain class (not a Service) — create instances via `ctx.sessions.create()`.
|
||||
* Seeding with an existing event log replays/forks a session.
|
||||
* @typert object
|
||||
*/
|
||||
declare class Session {
|
||||
/** The ordered surface over this session's event log. */
|
||||
|
||||
@@ -8,21 +8,21 @@ This matrix shows which packages dispatch each harness-owned event and which pac
|
||||
| Event | Mode | Declared in | Dispatchers | Listeners |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `agent-loop/config-start-failed` | `emit` | [`packages/core/agent-loop/src/index.ts:148`](../packages/core/agent-loop/src/index.ts) | [`agent-loop`](../packages/core/agent-loop) (`events.dispatch`) | [`tui`](../packages/ui/tui) |
|
||||
| `agent/cancel-requested` | `emit` | [`packages/core/agent/src/types.ts:286`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`goal-session`](../packages/goal/goal-session) |
|
||||
| `agent/created` | `emit` | [`packages/core/agent/src/types.ts:218`](../packages/core/agent/src/types.ts) | [`agent`](../packages/core/agent) (`events.dispatch`) | [`goal-session`](../packages/goal/goal-session), [`tui`](../packages/ui/tui) |
|
||||
| `agent/disposed` | `emit` | [`packages/core/agent/src/types.ts:227`](../packages/core/agent/src/types.ts) | [`agent`](../packages/core/agent) (`events.dispatch`) | [`agent-loop`](../packages/core/agent-loop), [`goal-session`](../packages/goal/goal-session), [`tui`](../packages/ui/tui) |
|
||||
| `agent/error` | `emit` | [`packages/core/agent/src/types.ts:400`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | `apiproxy`, [`goal-session`](../packages/goal/goal-session), [`session-telemetry`](../packages/telemetry/session-telemetry), [`tui`](../packages/ui/tui) |
|
||||
| `agent/inbox/dequeue` | `emit` | [`packages/core/agent/src/types.ts:259`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`agent`](../packages/core/agent), `apiproxy`, [`tui`](../packages/ui/tui) |
|
||||
| `agent/inbox/discard` | `emit` | [`packages/core/agent/src/types.ts:276`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`agent`](../packages/core/agent), `apiproxy`, [`tui`](../packages/ui/tui) |
|
||||
| `agent/inbox/enqueue` | `emit` | [`packages/core/agent/src/types.ts:247`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`agent`](../packages/core/agent), `apiproxy`, [`goal-session`](../packages/goal/goal-session) |
|
||||
| `agent/prompt-submit` | `waterfall` | [`packages/core/agent/src/types.ts:313`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`waterfall`) | [`goal-session`](../packages/goal/goal-session), [`hooks-claude`](../packages/hooks/hooks-claude), [`hooks-codex`](../packages/hooks/hooks-codex), [`repeat-tool-guard`](../packages/guard/repeat-tool-guard), [`tui`](../packages/ui/tui) |
|
||||
| `agent/request` | `waterfall` | [`packages/core/agent/src/types.ts:339`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`waterfall`) | [`agent`](../packages/core/agent) |
|
||||
| `agent/request-error` | `waterfall` | [`packages/core/agent/src/types.ts:358`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`waterfall`) | [`compact-basic`](../packages/compact/compact-basic), [`llm-retry`](../packages/llm/llm-retry) |
|
||||
| `agent/session-start` | `emit` | [`packages/core/agent/src/types.ts:299`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`goal`](../packages/goal/goal), [`goal-session`](../packages/goal/goal-session), [`hooks-claude`](../packages/hooks/hooks-claude), [`hooks-codex`](../packages/hooks/hooks-codex), [`workspace-context`](../packages/context/workspace-context) |
|
||||
| `agent/settled` | `emit` | [`packages/core/agent/src/types.ts:387`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`compact-basic`](../packages/compact/compact-basic) |
|
||||
| `agent/status` | `emit` | [`packages/core/agent/src/types.ts:236`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`agent`](../packages/core/agent), `apiproxy`, [`goal-session`](../packages/goal/goal-session), [`tui`](../packages/ui/tui) |
|
||||
| `agent/step` | `serial` | [`packages/core/agent/src/types.ts:326`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`serial`) | [`compact-basic`](../packages/compact/compact-basic), [`plan-mode`](../packages/plan/plan-mode), [`session-checkpoint-policy`](../packages/session-persistence/session-checkpoint-policy), [`time-context`](../packages/context/time-context), [`tmux-context`](../packages/context/tmux-context), [`tool-skill`](../packages/skill/tool-skill), [`user-approval`](../packages/ui/user-approval), [`workspace-context`](../packages/context/workspace-context) |
|
||||
| `agent/turn-stopping` | `serial` | [`packages/core/agent/src/types.ts:373`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`serial`) | [`hooks-claude`](../packages/hooks/hooks-claude), [`hooks-codex`](../packages/hooks/hooks-codex) |
|
||||
| `agent/cancel-requested` | `emit` | [`packages/core/agent/src/types.ts:289`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`goal-session`](../packages/goal/goal-session) |
|
||||
| `agent/created` | `emit` | [`packages/core/agent/src/types.ts:221`](../packages/core/agent/src/types.ts) | [`agent`](../packages/core/agent) (`events.dispatch`) | [`goal-session`](../packages/goal/goal-session), [`tui`](../packages/ui/tui) |
|
||||
| `agent/disposed` | `emit` | [`packages/core/agent/src/types.ts:230`](../packages/core/agent/src/types.ts) | [`agent`](../packages/core/agent) (`events.dispatch`) | [`agent-loop`](../packages/core/agent-loop), [`goal-session`](../packages/goal/goal-session), [`tui`](../packages/ui/tui) |
|
||||
| `agent/error` | `emit` | [`packages/core/agent/src/types.ts:403`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | `apiproxy`, [`goal-session`](../packages/goal/goal-session), [`session-telemetry`](../packages/telemetry/session-telemetry), [`tui`](../packages/ui/tui) |
|
||||
| `agent/inbox/dequeue` | `emit` | [`packages/core/agent/src/types.ts:262`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`agent`](../packages/core/agent), `apiproxy`, [`tui`](../packages/ui/tui) |
|
||||
| `agent/inbox/discard` | `emit` | [`packages/core/agent/src/types.ts:279`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`agent`](../packages/core/agent), `apiproxy`, [`tui`](../packages/ui/tui) |
|
||||
| `agent/inbox/enqueue` | `emit` | [`packages/core/agent/src/types.ts:250`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`agent`](../packages/core/agent), `apiproxy`, [`goal-session`](../packages/goal/goal-session) |
|
||||
| `agent/prompt-submit` | `waterfall` | [`packages/core/agent/src/types.ts:316`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`waterfall`) | [`goal-session`](../packages/goal/goal-session), [`hooks-claude`](../packages/hooks/hooks-claude), [`hooks-codex`](../packages/hooks/hooks-codex), [`repeat-tool-guard`](../packages/guard/repeat-tool-guard), [`tui`](../packages/ui/tui) |
|
||||
| `agent/request` | `waterfall` | [`packages/core/agent/src/types.ts:342`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`waterfall`) | [`agent`](../packages/core/agent) |
|
||||
| `agent/request-error` | `waterfall` | [`packages/core/agent/src/types.ts:361`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`waterfall`) | [`compact-basic`](../packages/compact/compact-basic), [`llm-retry`](../packages/llm/llm-retry) |
|
||||
| `agent/session-start` | `emit` | [`packages/core/agent/src/types.ts:302`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`goal`](../packages/goal/goal), [`goal-session`](../packages/goal/goal-session), [`hooks-claude`](../packages/hooks/hooks-claude), [`hooks-codex`](../packages/hooks/hooks-codex), [`workspace-context`](../packages/context/workspace-context) |
|
||||
| `agent/settled` | `emit` | [`packages/core/agent/src/types.ts:390`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`compact-basic`](../packages/compact/compact-basic) |
|
||||
| `agent/status` | `emit` | [`packages/core/agent/src/types.ts:239`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`emitAgentEvent`) | [`agent`](../packages/core/agent), `apiproxy`, [`goal-session`](../packages/goal/goal-session), [`tui`](../packages/ui/tui) |
|
||||
| `agent/step` | `serial` | [`packages/core/agent/src/types.ts:329`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`serial`) | [`compact-basic`](../packages/compact/compact-basic), [`plan-mode`](../packages/plan/plan-mode), [`session-checkpoint-policy`](../packages/session-persistence/session-checkpoint-policy), [`time-context`](../packages/context/time-context), [`tmux-context`](../packages/context/tmux-context), [`tool-skill`](../packages/skill/tool-skill), [`user-approval`](../packages/ui/user-approval), [`workspace-context`](../packages/context/workspace-context) |
|
||||
| `agent/turn-stopping` | `serial` | [`packages/core/agent/src/types.ts:376`](../packages/core/agent/src/types.ts) | [`agent-loop`](../packages/core/agent-loop) (`serial`) | [`hooks-claude`](../packages/hooks/hooks-claude), [`hooks-codex`](../packages/hooks/hooks-codex) |
|
||||
| `approval/request` | `waterfall` | [`packages/ui/user-approval/src/index.ts:30`](../packages/ui/user-approval/src/index.ts) | [`user-approval`](../packages/ui/user-approval) (`waterfall`) | [`acp`](../packages/acp/acp), `apiproxy` |
|
||||
| `commands/change` | `emit` | [`packages/ui/commands/src/index.ts:154`](../packages/ui/commands/src/index.ts) | [`commands`](../packages/ui/commands) (`events.dispatch`) | `apiproxy`, [`tui`](../packages/ui/tui) |
|
||||
| `domain/changed` | `emit` | [`packages/storage/storage-domain/src/events.ts:46`](../packages/storage/storage-domain/src/events.ts) | [`storage-domain`](../packages/storage/storage-domain) (`emit`) | `apiproxy`, [`storage-domain`](../packages/storage/storage-domain), [`workspace`](../packages/workspace/workspace) |
|
||||
@@ -36,10 +36,6 @@ This matrix shows which packages dispatch each harness-owned event and which pac
|
||||
| `session/event` | `emit` | [`packages/core/session/src/index.ts:93`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`acp`](../packages/acp/acp), `apiproxy`, [`cli-demo`](../packages/examples/cli-demo), [`compact`](../packages/compact/compact), [`compact-basic`](../packages/compact/compact-basic), [`goal`](../packages/goal/goal), [`goal-session`](../packages/goal/goal-session), [`hook-protocol`](../packages/hooks/hook-protocol), [`jsonrpc`](../packages/ui/jsonrpc), [`session`](../packages/core/session), [`session-persistence`](../packages/session-persistence/session-persistence), [`session-projection`](../packages/session-projection/session-projection), [`session-projection-cache`](../packages/session-projection/session-projection-cache), [`session-telemetry`](../packages/telemetry/session-telemetry), [`session-title`](../packages/session-title/session-title), [`token-meter`](../packages/llm/token-meter), [`tools`](../packages/core/tools), [`tui`](../packages/ui/tui), [`user-approval`](../packages/ui/user-approval), [`workspace-context`](../packages/context/workspace-context) |
|
||||
| `session/flush` | `parallel` | [`packages/core/session/src/index.ts:103`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`session-persistence`](../packages/session-persistence/session-persistence), [`session-telemetry`](../packages/telemetry/session-telemetry) |
|
||||
| `skills/change` | `emit` | [`packages/skill/skill/src/index.ts:188`](../packages/skill/skill/src/index.ts) | [`skill`](../packages/skill/skill) (`events.dispatch`) | [`tui`](../packages/ui/tui) |
|
||||
| `slash/input-begin-command` | `bail` | [`packages/client/ui-slash/src/types.ts:232`](../packages/client/ui-slash/src/types.ts) | - | `ui-conversation` |
|
||||
| `slash/input-consume-token` | `bail` | [`packages/client/ui-slash/src/types.ts:246`](../packages/client/ui-slash/src/types.ts) | - | `ui-conversation` |
|
||||
| `slash/input-insert-reference` | `bail` | [`packages/client/ui-slash/src/types.ts:239`](../packages/client/ui-slash/src/types.ts) | - | `ui-conversation` |
|
||||
| `slash/input-insert-text` | `bail` | [`packages/client/ui-slash/src/types.ts:254`](../packages/client/ui-slash/src/types.ts) | - | `ui-conversation` |
|
||||
| `subagent/end` | `emit` | [`packages/subagent/subagent/src/index.ts:140`](../packages/subagent/subagent/src/index.ts) | [`subagent`](../packages/subagent/subagent) (`events.dispatch`) | [`hooks-claude`](../packages/hooks/hooks-claude), [`jsonrpc`](../packages/ui/jsonrpc), [`subagent`](../packages/subagent/subagent) |
|
||||
| `subagent/provider-added` | `emit` | [`packages/subagent/subagent/src/index.ts:114`](../packages/subagent/subagent/src/index.ts) | [`subagent`](../packages/subagent/subagent) (`emit`) | [`subagent`](../packages/subagent/subagent), [`tool-subagent`](../packages/subagent/tool-subagent) |
|
||||
| `subagent/provider-removed` | `emit` | [`packages/subagent/subagent/src/index.ts:120`](../packages/subagent/subagent/src/index.ts) | [`subagent`](../packages/subagent/subagent) (`events.dispatch`) | [`subagent`](../packages/subagent/subagent), [`tool-subagent`](../packages/subagent/tool-subagent) |
|
||||
@@ -67,9 +63,13 @@ This matrix shows which packages dispatch each harness-owned event and which pac
|
||||
| `commands/changed` | `runtime` (`emit`) | `ui-command` |
|
||||
| `connection/reset` | `runtime` (`emit`) | `ui-command` |
|
||||
| `internal/dispatch` | - | [`commands`](../packages/ui/commands), [`compact`](../packages/compact/compact), [`fs`](../packages/fs/fs), [`goal`](../packages/goal/goal), [`goal-session`](../packages/goal/goal-session), [`hook-protocol`](../packages/hooks/hook-protocol), [`llm-retry`](../packages/llm/llm-retry), [`permission`](../packages/ui/permission), [`plan-mode`](../packages/plan/plan-mode), [`pty-local`](../packages/pty/pty-local), `runtime`, [`sandbox-policy`](../packages/sandbox/sandbox-policy), [`scope`](../packages/core/scope), [`session`](../packages/core/session), [`session-title`](../packages/session-title/session-title), [`subagent`](../packages/subagent/subagent), [`time-context`](../packages/context/time-context), [`tool-todo`](../packages/todo/tool-todo), [`tools`](../packages/core/tools), [`user-approval`](../packages/ui/user-approval), [`workflow`](../packages/workflow/workflow) |
|
||||
| `internal/plugin` | - | `hmr`, `modules`, `webserver` |
|
||||
| `internal/plugin` | - | `hmr`, `loader`, `modules`, `webserver` |
|
||||
| `internal/status` | - | [`agent`](../packages/core/agent) |
|
||||
| `locale/change` | `locale` (`emit`) | `locale`, `ui-models`, `ui-settings-general` |
|
||||
| `slash/input-begin-command` | - | `ui-conversation` |
|
||||
| `slash/input-consume-token` | - | `ui-conversation` |
|
||||
| `slash/input-insert-reference` | - | `ui-conversation` |
|
||||
| `slash/input-insert-text` | - | `ui-conversation` |
|
||||
| `slots/changed` | `runtime` (`emit`) | - |
|
||||
| `theme/change` | `ui-theme` (`emit`) | `ui-layout`, `ui-theme` |
|
||||
|
||||
|
||||
@@ -241,6 +241,11 @@ flowchart TD
|
||||
pkg_session_telemetry["session-telemetry"]
|
||||
pkg_session_telemetry_otel["session-telemetry-otel"]
|
||||
end
|
||||
subgraph group_typert["packages/typert"]
|
||||
pkg_typert_generator["typert-generator"]
|
||||
pkg_typert_loader["typert-loader"]
|
||||
pkg_typert_registry["typert-registry"]
|
||||
end
|
||||
subgraph group_workflow["packages/workflow"]
|
||||
pkg_tool_ralph["tool-ralph"]
|
||||
pkg_tool_workflow["tool-workflow"]
|
||||
@@ -274,6 +279,8 @@ flowchart TD
|
||||
pkg_host_webserver --> pkg_invariants
|
||||
pkg_storage --> pkg_invariants
|
||||
pkg_subprocess --> pkg_invariants
|
||||
pkg_typert_generator --> pkg_invariants
|
||||
pkg_typert_registry --> pkg_invariants
|
||||
pkg_llm --> pkg_brand
|
||||
pkg_llm --> pkg_invariants
|
||||
pkg_llm --> pkg_timeout
|
||||
@@ -321,6 +328,8 @@ flowchart TD
|
||||
pkg_storage_sqlite --> pkg_storage
|
||||
pkg_subprocess_local --> pkg_invariants
|
||||
pkg_subprocess_local --> pkg_subprocess
|
||||
pkg_typert_loader --> pkg_invariants
|
||||
pkg_typert_loader --> pkg_typert_registry
|
||||
pkg_llm_deepseek --> pkg_invariants
|
||||
pkg_llm_deepseek --> pkg_llm
|
||||
pkg_llm_deepseek --> pkg_timeout
|
||||
@@ -1003,6 +1012,8 @@ flowchart TD
|
||||
| [`host-webserver`](../packages/host/webserver) | `host` | [`invariants`](../packages/support/invariants) |
|
||||
| [`storage`](../packages/storage/storage) | `storage` | [`invariants`](../packages/support/invariants) |
|
||||
| [`subprocess`](../packages/subprocess/subprocess) | `subprocess` | [`invariants`](../packages/support/invariants) |
|
||||
| [`typert-generator`](../packages/typert/generator) | `typert` | [`invariants`](../packages/support/invariants) |
|
||||
| [`typert-registry`](../packages/typert/registry) | `typert` | [`invariants`](../packages/support/invariants) |
|
||||
| [`llm`](../packages/llm/llm) | `llm` | [`brand`](../packages/util/brand), [`invariants`](../packages/support/invariants), [`timeout`](../packages/util/timeout) |
|
||||
| [`client-connection`](../packages/client/connection) | `client` | [`host-webserver`](../packages/host/webserver), [`invariants`](../packages/support/invariants) |
|
||||
| [`client-hmr`](../packages/client/hmr) | `client` | [`client-modules`](../packages/client/modules), [`host-webserver`](../packages/host/webserver), [`invariants`](../packages/support/invariants) |
|
||||
@@ -1019,6 +1030,7 @@ flowchart TD
|
||||
| [`storage-json`](../packages/storage/storage-json) | `storage` | [`invariants`](../packages/support/invariants), [`storage`](../packages/storage/storage) |
|
||||
| [`storage-sqlite`](../packages/storage/storage-sqlite) | `storage` | [`invariants`](../packages/support/invariants), [`storage`](../packages/storage/storage) |
|
||||
| [`subprocess-local`](../packages/subprocess/subprocess-local) | `subprocess` | [`invariants`](../packages/support/invariants), [`subprocess`](../packages/subprocess/subprocess) |
|
||||
| [`typert-loader`](../packages/typert/loader) | `typert` | [`invariants`](../packages/support/invariants), [`typert-registry`](../packages/typert/registry) |
|
||||
| [`llm-deepseek`](../packages/llm/llm-deepseek) | `llm` | [`invariants`](../packages/support/invariants), [`llm`](../packages/llm/llm), [`timeout`](../packages/util/timeout) |
|
||||
| [`llm-pi-ai`](../packages/llm/llm-pi-ai) | `llm` | [`invariants`](../packages/support/invariants), [`llm`](../packages/llm/llm), [`timeout`](../packages/util/timeout) |
|
||||
| [`session`](../packages/core/session) | `core` | [`brand`](../packages/util/brand), [`invariants`](../packages/support/invariants), [`llm`](../packages/llm/llm), [`scope`](../packages/core/scope) |
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write docs/typert-catalog-integration-design.md
|
||||
typert-catalog-integration-design.md: c7d601730655f61f3b875ad5ad6997d3c888bfea
|
||||
typert-catalog-integration-design.zh.md: abaddfe1f740d4bd7cff5b2db8fd91e34626aab8
|
||||
@@ -0,0 +1,133 @@
|
||||
# Typert Catalog Integration Design
|
||||
|
||||
English | [中文](typert-catalog-integration-design.zh.md)
|
||||
|
||||
## Current State and Problem
|
||||
|
||||
Typert already provides separate host/client `FaceModel` instances, a `TypeGraph` with explicit cross-face references, and analysis support for services, events, `@typert object`, generics, inheritance, and External types. The TypeScript compiler API should only translate source code into this standard model; downstream consumers should not traverse the TypeScript AST again.
|
||||
|
||||
The repository currently has two catalog pipelines that analyze TypeScript source directly: the static API catalog consumed by `tool-cordis`, and the generation and freshness gate for `docs/cordis-catalog/events.md` and `docs/cordis-catalog/services.md`. They analyze the same services, events, and related types, but maintain separate collection and rendering logic, so they cannot prove that the Typert model is sufficient to represent the existing domain semantics.
|
||||
|
||||
The first phase makes both pipelines consume the Typert model while keeping the three committed artifacts character-for-character identical to their pre-migration versions:
|
||||
|
||||
- `docs/cordis-catalog/events.md`
|
||||
- `docs/cordis-catalog/services.md`
|
||||
- `packages/cordis/tool-cordis/src/api-catalog.ts`
|
||||
|
||||
This phase does not require product plugins to publish Typert subpaths, example applications to load Typert, or changes to the runtime dependencies of `tool-cordis`.
|
||||
|
||||
## Options
|
||||
|
||||
### Drive `tool-cordis` from the Runtime Registry
|
||||
|
||||
Each plugin publishes and loads Typert artifacts, then `tool-cordis` reads the current runtime model from `ctx.typert`. This path reflects the set of plugins actually loaded, but it requires every product package represented in the catalog to add package exports, generated artifacts, registry contributions, and application assembly. That integration surface is much larger than the analysis capability being validated now.
|
||||
|
||||
### Publish Typert Artifacts Repository-Wide, Then Aggregate Them Statically
|
||||
|
||||
All product packages generate host/client JS and DTS during the normal build/typecheck process, then the catalog generator aggregates those artifacts. This path establishes the complete publication protocol up front, but it also changes many package manifests and the build topology at once, coupling catalog migration to repository-wide Typert publication.
|
||||
|
||||
### Analyze at Build Time, Then Project the Catalog
|
||||
|
||||
`WorkspaceAnalyzer` builds a `WorkspaceModel` and `TypeGraph` from the host TypeScript project. The repository-specific `CordisCatalogProjector` consumes only that model and generates the three texts. `tool-cordis` continues to import the committed static `api-catalog.ts`, so the runtime does not need the Typert service.
|
||||
|
||||
This phase uses build-time projection. It directly verifies that the standard Typert model can replace the existing AST collector while leaving runtime publication and automatic loading to separate follow-up decisions.
|
||||
|
||||
## Phase-One Architecture
|
||||
|
||||
```text
|
||||
tsconfig.host.json
|
||||
│
|
||||
▼
|
||||
WorkspaceAnalyzer ── TypeScript compiler API 的唯一边界
|
||||
│
|
||||
▼
|
||||
WorkspaceModel + TypeGraph
|
||||
│
|
||||
▼
|
||||
CordisCatalogProjector ── 不依赖 TypeScript AST
|
||||
├── docs/cordis-catalog/events.md
|
||||
├── docs/cordis-catalog/services.md
|
||||
└── packages/cordis/tool-cordis/src/api-catalog.ts
|
||||
```
|
||||
|
||||
The objects have the following responsibilities:
|
||||
|
||||
- `WorkspaceAnalyzer` analyzes packages, exports, services, events, type declarations, and reference relationships, and produces a compiler-independent model.
|
||||
- `WorkspaceModel` and `TypeGraph` are the standard data structures shared by all generation and scanning analyses. They preserve developer-authored generics, inheritance, and type trees without retaining the TypeScript AST.
|
||||
- The root entry point of `@deepseek-ai/dsh-typert-generator` exports `CordisCatalogProjector`, which performs model-driven selection, sorting, summary extraction, source location handling, JSDoc completeness checks, type-link closure, and rendering in three text formats. Its implementation remains in a dedicated Cordis catalog file, but it does not create another package subpath or embed a list of repository type names.
|
||||
- `scripts/gen-cordis-catalog.ts` provides `LINK_MAP`, `FOUNDATION_TYPE_NAMES`, `TYPE_LINK_EXEMPTIONS`, and the inherited Cordis list, injects them explicitly into the projector through `CordisCatalogPolicy`, and owns the write/check CLI behavior. The vendor Cordis core pages continue to be generated by a separate pinned-source projector.
|
||||
- `tool-cordis` imports only the static `api-catalog.ts` and does not depend on `typert-registry` or `typert-loader`.
|
||||
|
||||
`CordisCatalogProjector` is a repository-specific downstream consumer and is not part of Typert's general-purpose model. When adding another category, first extend the standard model, then add the corresponding projector. The Typert analyzer must not absorb Cordis documentation formats or `tool-cordis` presentation logic.
|
||||
|
||||
## Model Additions
|
||||
|
||||
In addition to type structure, the catalog's character-for-character projection needs the declaration forms written by developers and exact source locations. The standard model therefore retains event/service locations, body-free text for events and members, parameter initializers, and the export status and canonical text of type declarations. `SourceDeclarationModel` also indexes top-level exported declarations for ambiguity checks and static type closure, without promoting them to domain graph roots.
|
||||
|
||||
```ts
|
||||
interface SourceLocation {
|
||||
readonly file: string
|
||||
readonly line: number
|
||||
readonly column: number
|
||||
}
|
||||
|
||||
interface EventModel {
|
||||
readonly location: SourceLocation
|
||||
readonly text: string
|
||||
}
|
||||
```
|
||||
|
||||
Repository-wide analysis supports building bounded `ts.Program` instances in package batches, then merging them through source-location-stable graph ids into a face model equivalent to monolithic analysis. This capability changes only the memory boundary of the compiler program; it does not change package, declaration, or type graph semantics.
|
||||
|
||||
All information required by the projector must come from `WorkspaceModel` or `TypeGraph`. If a fact required for character-for-character compatibility cannot be expressed by the model, extend the standard model; do not reintroduce `ts.Node`, `ts.Symbol`, or `ts.TypeChecker` in the projector or script.
|
||||
|
||||
## Character-for-Character Migration Oracle
|
||||
|
||||
Before migration, retain the three texts produced by the old generator against the same source state. After migration, run the new analyzer and projector and require the three outputs to be byte-for-byte identical. Newlines, spaces, ordering, JSDoc, source pointers, and generated headers are all part of the comparison.
|
||||
|
||||
`pnpm run verify-cordis-catalog` retains its `--check` mode, which reads the three committed artifacts and compares them directly with the newly computed results. A missing file or any differing character makes the artifact stale, and the error points to the single `pnpm run gen-cordis-catalog` repair command.
|
||||
|
||||
Tests pin both of the following layers:
|
||||
|
||||
- Typert fixture snapshots pin the `WorkspaceModel`, `TypeGraph`, JS, DTS, and Zod outputs, proving the behavior of the standard model and general-purpose emitters.
|
||||
- Cordis catalog tests or snapshots pin the projector's three complete texts, proving that the repository-specific product projection does not bypass the standard model and providing directly reviewable textual evidence.
|
||||
|
||||
The three committed artifacts are the migration oracle between the old and new implementations and the continuing freshness oracle after migration. The old `gen-cordis-api` AST collector is removed. The scripts and commands with that name remain only as compatibility entry points for the unified projector because the generated file header itself contains the command; retaining the entry point preserves the character-for-character oracle without creating a second source of truth.
|
||||
|
||||
## Exact Change List
|
||||
|
||||
### Typert Generator
|
||||
|
||||
- Add the locations, authored declaration text, parameter initializers, export status, and top-level source declaration index needed for character-for-character projection, with coverage in analyzer and model snapshots.
|
||||
- Support bounded package-batch analysis and prove that direct and batched models are equivalent.
|
||||
- Confirm that the catalog's required service declarations, public instance members, JSDoc, generics, inheritance, and referenced types are all available from the model.
|
||||
- Keep the TypeScript compiler API encapsulated within the analyzer; the public model and projector inputs do not expose compiler objects.
|
||||
|
||||
### Cordis Catalog Projector
|
||||
|
||||
- Select the complete set of Cordis services and events from the host `WorkspaceModel`.
|
||||
- Preserve the old generator's JSDoc rules: events must have `@mode` and payload `@param` tags; service methods must have a matching `@param` for every parameter; non-void returns must have `@returns`.
|
||||
- Compute the type links used by signatures and the transitive public type closure required by `tool-cordis` from the type graph.
|
||||
- Receive caller-maintained type classifications and the inherited surface through an explicit `CordisCatalogPolicy`; do not maintain the repository documentation taxonomy inside the generator package.
|
||||
- Preserve the existing output rules for source pointers, signatures, summaries, ordering, declaration truncation, and the inherited context catalog.
|
||||
- Project once and render the events Markdown, services Markdown, and TypeScript API catalog, preventing drift between documentation and tool data.
|
||||
|
||||
### Commands and Consumers
|
||||
|
||||
- `scripts/gen-cordis-catalog.ts` maintains repository policy data, assembles the analyzer and projector, and writes/checks all three artifacts together. Parsing, validation, and rendering logic lives in the generator's dedicated Cordis source file and is exported uniformly from the package root entry point.
|
||||
- Narrow `scripts/gen-cordis-api.ts` to a logic-free compatibility entry point for the unified CLI; the root `gen-cordis-api` and `verify-cordis-api` aliases point to that entry point.
|
||||
- Restore the static catalog default in `tool-cordis` and remove its dependencies on `ctx.typert`, `typert-registry`, and runtime package-model completeness.
|
||||
- `gen-doc-graphs` obtains the projector's model-level result once and reuses its services and events; it must not continue to import the AST collector or analyze the repository again.
|
||||
|
||||
### Narrow the Scope of Phase-One Changes
|
||||
|
||||
- Remove the newly added `./typert` and `./client/typert` exports and `lib/typert.*` files from product plugin package.json files.
|
||||
- Remove `typert-registry` and `typert-loader` assembly from examples.
|
||||
- Normal build/typecheck does not run repository-wide `gen-typert` or require product-package Typert artifacts to exist before it runs on a clean tree.
|
||||
- Retain `packages/typert/generator`, `packages/typert/registry`, and `packages/typert/loader`, along with their independent fixture, emitter, and runtime registration tests.
|
||||
|
||||
## Future Extensions
|
||||
|
||||
The runtime registry remains the receiving and query layer for generated JS/Zod, and the loader remains the automatic loading mechanism; neither supplies data to the first-phase static catalog. When product packages need runtime reflection, they can opt in by publishing `package/typert` and `package/client/typert`, which the loader then registers with `ctx.typert`.
|
||||
|
||||
Future integration does not change the phase-one layering: only the analyzer handles TypeScript, the standard model serves both static generation and scan analysis, and the emitter produces runtime artifacts from that same model. Whether to extend publication to more packages, enable the loader by default, or extend the runtime registry's query capabilities are separate review decisions and remain decoupled from the Cordis catalog migration.
|
||||
@@ -0,0 +1,133 @@
|
||||
# Typert catalog 接入设计
|
||||
|
||||
[English](typert-catalog-integration-design.md) | 中文
|
||||
|
||||
## 现状与问题
|
||||
|
||||
Typert 已经具备独立的 host/client `FaceModel`、可显式跨 face 引用的 `TypeGraph`,以及 service、event、`@typert object`、泛型、继承和 External 类型的分析能力。TypeScript compiler API 只应负责把源码转换成这套标准模型;后续消费者不应再次遍历 TypeScript AST。
|
||||
|
||||
仓库目前有两条直接分析 TypeScript 源码的 catalog 链路:`tool-cordis` 使用的静态 API catalog,以及 `docs/cordis-catalog/events.md`、`docs/cordis-catalog/services.md` 的生成与 freshness gate。它们分析的是同一批 service、event 和相关类型,却分别维护收集与渲染逻辑,不能证明 Typert 模型足以承载现有业务语义。
|
||||
|
||||
第一阶段的目标是让这两条链路共同消费 Typert 模型,并保持三份已提交产物与迁移前字符级一致:
|
||||
|
||||
- `docs/cordis-catalog/events.md`
|
||||
- `docs/cordis-catalog/services.md`
|
||||
- `packages/cordis/tool-cordis/src/api-catalog.ts`
|
||||
|
||||
本阶段不要求业务插件发布 Typert 子路径,不要求示例应用加载 Typert,也不改变 `tool-cordis` 的运行时依赖关系。
|
||||
|
||||
## 可选路径
|
||||
|
||||
### 运行时 registry 驱动 `tool-cordis`
|
||||
|
||||
每个插件发布并加载 Typert 产物,`tool-cordis` 再从 `ctx.typert` 读取当前运行时模型。这条路径可以反映实际加载的插件集合,但会要求所有参与 catalog 的业务包增加 package exports、生成产物、registry contribution 和应用装配,接入面远大于当前要验证的分析能力。
|
||||
|
||||
### 全仓发布 Typert 产物后静态汇总
|
||||
|
||||
所有业务包在普通 build/typecheck 中生成 host/client JS 与 DTS,再由 catalog 生成器汇总这些产物。这条路径能够提前建立完整的发布协议,但会同时修改大量 package manifest 和构建拓扑,使 catalog 迁移与 Typert 的全仓发布绑定。
|
||||
|
||||
### 构建期分析后投影 catalog
|
||||
|
||||
`WorkspaceAnalyzer` 从 host TypeScript project 构建 `WorkspaceModel` 与 `TypeGraph`,仓库专用的 `CordisCatalogProjector` 只消费该模型并生成三份文本。`tool-cordis` 继续导入已提交的静态 `api-catalog.ts`,运行时不需要 Typert service。
|
||||
|
||||
本阶段采用构建期投影。它直接验证 Typert 标准模型能否替代现有 AST collector,同时把运行时 publication 和自动加载留在独立的后续决策中。
|
||||
|
||||
## 第一阶段架构
|
||||
|
||||
```text
|
||||
tsconfig.host.json
|
||||
│
|
||||
▼
|
||||
WorkspaceAnalyzer ── TypeScript compiler API 的唯一边界
|
||||
│
|
||||
▼
|
||||
WorkspaceModel + TypeGraph
|
||||
│
|
||||
▼
|
||||
CordisCatalogProjector ── 不依赖 TypeScript AST
|
||||
├── docs/cordis-catalog/events.md
|
||||
├── docs/cordis-catalog/services.md
|
||||
└── packages/cordis/tool-cordis/src/api-catalog.ts
|
||||
```
|
||||
|
||||
各对象的职责如下:
|
||||
|
||||
- `WorkspaceAnalyzer` 负责 package、export、service、event、类型声明和引用关系的分析,并产生 compiler-independent model。
|
||||
- `WorkspaceModel` 与 `TypeGraph` 是所有生成和扫描分析共用的标准数据结构,保留开发者写出的泛型、继承和类型树,不保存 TypeScript AST。
|
||||
- `@deepseek-ai/dsh-typert-generator` 根入口导出的 `CordisCatalogProjector` 负责模型驱动的选择、排序、摘要、源位置、JSDoc 完整性、类型链接闭包和三种文本格式;实现仍单独放在 Cordis catalog 专用文件中,但不形成额外的 package subpath,也不内置仓库类型名单。
|
||||
- `scripts/gen-cordis-catalog.ts` 提供 `LINK_MAP`、`FOUNDATION_TYPE_NAMES`、`TYPE_LINK_EXEMPTIONS` 和 inherited Cordis 清单,通过 `CordisCatalogPolicy` 显式注入 projector,并负责 write/check 的命令行行为;vendor Cordis core 页面仍由独立的 pinned-source projector 生成。
|
||||
- `tool-cordis` 只导入静态 `api-catalog.ts`,不依赖 `typert-registry` 或 `typert-loader`。
|
||||
|
||||
`CordisCatalogProjector` 是仓库业务消费者,不进入 Typert 通用模型。新增其他类别时,先扩展标准模型,再增加对应 projector;Typert analyzer 不吸收 Cordis 文档格式或 `tool-cordis` 展示逻辑。
|
||||
|
||||
## 模型补充
|
||||
|
||||
Catalog 的字符级投影除了类型结构,还需要开发者写下的声明形式和精确源码位置。标准模型因此保留 event/service location、event/member 的 body-free text、parameter initializer,以及 type declaration 的 export 状态和 canonical text;`SourceDeclarationModel` 另外索引顶层导出声明,供歧义检查和静态类型闭包使用,但不把它们提升为业务 graph root。
|
||||
|
||||
```ts
|
||||
interface SourceLocation {
|
||||
readonly file: string
|
||||
readonly line: number
|
||||
readonly column: number
|
||||
}
|
||||
|
||||
interface EventModel {
|
||||
readonly location: SourceLocation
|
||||
readonly text: string
|
||||
}
|
||||
```
|
||||
|
||||
全仓分析支持按 package 分批构建有界 `ts.Program`,再依靠源码位置稳定的 graph id 合并为与一次性分析等价的 face model。该能力只改变 compiler program 的内存边界,不改变 package、declaration 或 type graph 语义。
|
||||
|
||||
projector 所需信息必须来自 `WorkspaceModel` 或 `TypeGraph`。如果字符级兼容需要的事实无法从模型表达,应补充标准模型;不得在 projector 或脚本中重新引入 `ts.Node`、`ts.Symbol` 或 `ts.TypeChecker`。
|
||||
|
||||
## 字符级迁移 oracle
|
||||
|
||||
迁移前,在同一份源码状态下保留旧生成器产生的三份文本。迁移后运行新的 analyzer 与 projector,要求三份输出逐字节相等;换行、空格、排序、JSDoc、source pointer 和生成头都属于比较内容。
|
||||
|
||||
`pnpm run verify-cordis-catalog` 的 `--check` 模式继续读取三份 committed artifact,并与本次计算结果直接比较。任一文件缺失或任一字符不同都视为 stale,错误信息指向统一的 `pnpm run gen-cordis-catalog` 修复命令。
|
||||
|
||||
测试同时固定以下两层:
|
||||
|
||||
- Typert fixture snapshots 固定 `WorkspaceModel`、`TypeGraph`、JS、DTS 与 Zod 输出,证明标准模型和通用 emitter 的行为。
|
||||
- Cordis catalog 测试或 snapshot 固定 projector 的三份完整文本,证明仓库业务投影没有绕过标准模型,并给出可直接评审的文本证据。
|
||||
|
||||
三份 committed artifact 是旧实现与新实现的迁移 oracle,也是迁移完成后的持续 freshness oracle。旧 `gen-cordis-api` AST collector 被删除;同名脚本和命令只作为统一 projector 的兼容入口保留,因为生成文件头本身包含该命令,保留入口可以维持字符级 oracle 而不产生第二套真源。
|
||||
|
||||
## 精确改造清单
|
||||
|
||||
### Typert generator
|
||||
|
||||
- 补齐字符级投影所需的 location、authored declaration text、parameter initializer、export 状态和顶层 source declaration index,并在 analyzer 与 model snapshots 中覆盖。
|
||||
- 支持有界 package batch 分析,并证明 direct 与 batched model 等价。
|
||||
- 确认 catalog 所需的 service 声明、public instance member、JSDoc、泛型、继承和引用类型均可从 model 读取。
|
||||
- 保持 TypeScript compiler API 封装在 analyzer 内;公共 model 和 projector 输入不暴露 compiler 对象。
|
||||
|
||||
### Cordis catalog projector
|
||||
|
||||
- 从 host `WorkspaceModel` 选择完整的 Cordis service/event 集合。
|
||||
- 保留旧生成器的 JSDoc 规则:event 必须有 `@mode` 和 payload `@param`,service method 必须有参数对应的 `@param`,非 void 返回必须有 `@returns`。
|
||||
- 从 type graph 计算签名涉及的类型链接和 `tool-cordis` 所需的传递 public type closure。
|
||||
- 通过显式 `CordisCatalogPolicy` 接收调用方维护的类型分类和 inherited surface,不在 generator 包内维护仓库文档 taxonomy。
|
||||
- 保留 source pointer、签名、摘要、排序、声明截断和 inherited context catalog 的既有输出规则。
|
||||
- 一次投影并渲染 events Markdown、services Markdown 与 TypeScript API catalog,避免文档和工具数据漂移。
|
||||
|
||||
### 命令与消费方
|
||||
|
||||
- `scripts/gen-cordis-catalog.ts` 维护仓库 policy 数据、组装 analyzer/projector,并同时 write/check 三份产物;解析、校验和渲染逻辑位于 generator 的 Cordis 专用源文件,并统一从 package 根入口导出。
|
||||
- 将 `scripts/gen-cordis-api.ts` 收窄为统一 CLI 的无逻辑兼容入口;根目录的 `gen-cordis-api`、`verify-cordis-api` aliases 指向该入口。
|
||||
- `tool-cordis` 恢复静态 catalog 默认值,移除对 `ctx.typert`、`typert-registry` 和运行时 package model 完整性的依赖。
|
||||
- `gen-doc-graphs` 一次取得 projector 的 model-level 结果并复用 services/events,不能继续导入 AST collector 或重复分析全仓。
|
||||
|
||||
### 收窄本阶段改动面
|
||||
|
||||
- 撤销业务插件 package.json 中新增的 `./typert`、`./client/typert` exports 和 `lib/typert.*` files。
|
||||
- 撤销 examples 中的 `typert-registry`、`typert-loader` 装配。
|
||||
- 普通 build/typecheck 不运行全仓 `gen-typert`,也不要求 clean tree 预先存在业务包 Typert artifact。
|
||||
- 保留 `packages/typert/generator`、`packages/typert/registry`、`packages/typert/loader` 及其独立 fixture、emitter 和 runtime registration 测试。
|
||||
|
||||
## 后续扩展
|
||||
|
||||
Runtime registry 继续作为生成 JS/Zod 后的接收与查询层,loader 继续作为自动装载机制;两者不承担第一阶段静态 catalog 的数据来源。业务包需要运行时反射时,可以按 package opt-in 发布 `package/typert` 与 `package/client/typert`,再由 loader 注册到 `ctx.typert`。
|
||||
|
||||
后续接入不改变本阶段的分层:TypeScript 只进入 analyzer,标准模型同时服务静态生成与扫描分析,runtime artifact 由 emitter 从同一模型产生。是否把更多 package 接入 publication、是否默认启用 loader,以及 runtime registry 最终提供哪些查询能力,分别评审,不与 Cordis catalog 迁移捆绑。
|
||||
@@ -49,4 +49,11 @@ export default [
|
||||
}],
|
||||
},
|
||||
},
|
||||
{
|
||||
// TypeGraph coverage must retain source-authored syntax that the normal quote rule forbids.
|
||||
files: ['packages/typert/generator/tests/fixtures/type-model/packages/host/src/models.ts'],
|
||||
rules: {
|
||||
'@stylistic/quotes': 'off',
|
||||
},
|
||||
},
|
||||
]
|
||||
@@ -154,6 +154,25 @@
|
||||
"tests/**/*.ts"
|
||||
]
|
||||
},
|
||||
"packages/core/tools": {
|
||||
"entry": [
|
||||
"tests/**/*.spec.ts"
|
||||
],
|
||||
"project": [
|
||||
"src/**/*.ts",
|
||||
"tests/**/*.ts"
|
||||
]
|
||||
},
|
||||
"packages/typert/generator": {
|
||||
"entry": [
|
||||
"tests/**/*.spec.ts",
|
||||
"tests/fixtures/type-model/**/*.ts"
|
||||
],
|
||||
"project": [
|
||||
"src/**/*.ts",
|
||||
"tests/**/*.ts"
|
||||
]
|
||||
},
|
||||
"packages/bash/bash-sandbox": {
|
||||
"entry": [
|
||||
"tests/**/*.spec.ts",
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/README.md
|
||||
README.md: 7a86e0f034264d4059e75775016d8d5d84600d8d
|
||||
README.zh.md: bfcba626bea2a70f5c2aa508bb2a5b8c09bb61dc
|
||||
README.md: fd5e1e8ec1a0ca426ed717cfa9613c51728c60e1
|
||||
README.zh.md: ad4f315171377677a934d8bb02d15c2db96e0e91
|
||||
@@ -11,6 +11,7 @@ Packages live at `packages/<group>/<pkg>/`; groups are containers, while names r
|
||||
| Group | Role | Release expectation |
|
||||
|---|---|---|
|
||||
| [`core/`](core/README.md) | Product API spine: sessions, prompts, tools, agent services, and the concrete loop | Product — stable surface |
|
||||
| [`typert/`](typert/README.md) | Type graph generation, artifact loading, and runtime registry | Product — stable surface |
|
||||
| [`goal/`](goal/README.md) | Persisted same-session goal state and lifecycle | Product — stable surface |
|
||||
| [`llm/`](llm/README.md) | LLM capability family: the abstract service + provider adapters | Product — stable surface |
|
||||
| [`subprocess/`](subprocess/README.md) | Subprocess capability family: spawn seam + local process-tree implementation | Product — stable surface |
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
| 组 | 职责 | 发布预期 |
|
||||
|---|---|---|
|
||||
| [`core/`](core/README.md) | 产品 API 主干:会话、提示词、工具、agent(智能体)服务与具体循环 | 产品:稳定表面 |
|
||||
| [`typert/`](typert/README.md) | 类型图生成、产物加载与运行时注册表 | 产品:稳定表面 |
|
||||
| [`goal/`](goal/README.md) | 持久化的同会话 goal 状态与生命周期 | 产品:稳定表面 |
|
||||
| [`llm/`](llm/README.md) | LLM(大语言模型)能力系列:抽象服务 + 提供方适配器 | 产品:稳定表面 |
|
||||
| [`subprocess/`](subprocess/README.md) | 进程管理能力系列:spawn seam + 本地进程树实现 | 产品:稳定表面 |
|
||||
|
||||
@@ -286,3 +286,78 @@ describe('WorkspacesService', () => {
|
||||
await expect(workspaces.delete(wid('ghost'))).rejects.toThrow(/workspace-not-found: gone/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('startInitialSelection', () => {
|
||||
function bench() {
|
||||
const ctx = new Context()
|
||||
const api = new FakeApiClient()
|
||||
const sessions = new SessionsService(ctx, api)
|
||||
const workspaces = new WorkspacesService(ctx, api, sessions)
|
||||
return { api, sessions, workspaces }
|
||||
}
|
||||
|
||||
it('connects the recent Workspace blank session once baselines are ready and opens it', async () => {
|
||||
const b = bench()
|
||||
const stop = b.workspaces.startInitialSelection()
|
||||
// Nothing happens before both baselines land.
|
||||
expect(b.api.callsOf('session.create')).toHaveLength(0)
|
||||
|
||||
b.api.onWorkspaceList = () => Promise.resolve(ok({
|
||||
items: [workspace('recent', [], '2026-01-02T00:00:00.000Z')] as never[],
|
||||
}))
|
||||
b.api.onCreate = () => Promise.resolve(ok({ sessionId: sid('s-new') }))
|
||||
await b.workspaces.refresh()
|
||||
await b.sessions.refresh()
|
||||
// Store notifications and the connect round trip are microtask-batched.
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
expect(b.api.callsOf('session.create')).toEqual([{ workspaceId: 'recent' }])
|
||||
expect(b.sessions.list.getSnapshot().current).toBe('s-new')
|
||||
stop()
|
||||
})
|
||||
|
||||
it('stays idle when a session is already current or no recent Workspace exists', async () => {
|
||||
const withCurrent = bench()
|
||||
withCurrent.api.onList = () => Promise.resolve(ok({
|
||||
items: [{ sessionId: sid('s1'), updatedAt: 1, running: false, blank: false }] as never[],
|
||||
}))
|
||||
await withCurrent.sessions.refresh()
|
||||
withCurrent.sessions.open(sid('s1'))
|
||||
withCurrent.api.onWorkspaceList = () => Promise.resolve(ok({ items: [workspace('w1', [sid('s1')])] as never[] }))
|
||||
const stopCurrent = withCurrent.workspaces.startInitialSelection()
|
||||
await withCurrent.workspaces.refresh()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
expect(withCurrent.api.callsOf('session.create')).toHaveLength(0)
|
||||
stopCurrent()
|
||||
|
||||
const noRecent = bench()
|
||||
const stopEmpty = noRecent.workspaces.startInitialSelection()
|
||||
await noRecent.workspaces.refresh()
|
||||
await noRecent.sessions.refresh()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
expect(noRecent.api.callsOf('session.create')).toHaveLength(0)
|
||||
expect(() => noRecent.workspaces.startInitialSelection()).toThrow(/already started/)
|
||||
stopEmpty()
|
||||
})
|
||||
|
||||
it('a failed connect returns to waiting and retries on the next list change', async () => {
|
||||
const b = bench()
|
||||
b.api.onWorkspaceList = () => Promise.resolve(ok({
|
||||
items: [workspace('recent', [], '2026-01-02T00:00:00.000Z')] as never[],
|
||||
}))
|
||||
b.api.onCreate = () => Promise.resolve(err({ code: 'internal', message: 'attach exploded', details: {} }))
|
||||
const stop = b.workspaces.startInitialSelection()
|
||||
await b.workspaces.refresh()
|
||||
await b.sessions.refresh()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
expect(b.api.callsOf('session.create')).toHaveLength(1)
|
||||
expect(b.sessions.list.getSnapshot().current).toBeUndefined()
|
||||
|
||||
// Recovery: the next workspace-list change re-runs the reconcile.
|
||||
b.api.onCreate = () => Promise.resolve(ok({ sessionId: sid('s-retry') }))
|
||||
await b.workspaces.refresh()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
expect(b.api.callsOf('session.create')).toHaveLength(2)
|
||||
expect(b.sessions.list.getSnapshot().current).toBe('s-retry')
|
||||
stop()
|
||||
})
|
||||
})
|
||||
@@ -237,6 +237,20 @@ export class TestSessions implements ISessions {
|
||||
await this.stabilize(() => { record.snapshot.update(mutate) })
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a session's list row (the wire-echo stand-in: title settles,
|
||||
* running flips — components subscribed via useSessions re-render).
|
||||
* @param id - session id.
|
||||
* @param patch - summary fields to merge over the row.
|
||||
*/
|
||||
async updateSummary(id: string, patch: Partial<Omit<SessionSummary, 'id'>>): Promise<void> {
|
||||
const record = this.require(id)
|
||||
record.summary = { ...record.summary, ...patch }
|
||||
await this.stabilize(() => {
|
||||
this.list.update((draft) => { draft.byId[id as SessionId] = record.summary })
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch the current selection (undefined = the no-session empty state).
|
||||
* @param id - session id to select, or undefined to clear.
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
// @vitest-environment jsdom
|
||||
/**
|
||||
* Assembly-level acceptance on SlotTestRuntime (real apply, real slot
|
||||
* machinery, real renderer; data fed as fixtures) for surfaces that were
|
||||
* previously pinned only by the assembled-app jsdom snapshots
|
||||
* (apps/web/tests/{todo-display,terminal-card,slash-flow}.snapshot.ts):
|
||||
*
|
||||
* - the todo_write turn reaches BOTH surfaces through the product
|
||||
* registrations (keyed toolview row in the flow, plan strip in the input
|
||||
* dock via the 'todos' projection) and the strip follows projection
|
||||
* retirement;
|
||||
* - the bash keyed row carries its resident terminal card, and the fallback
|
||||
* row reaches the same card through its expand control;
|
||||
* - the resident composer textarea survives the blank→active conversion as
|
||||
* the SAME DOM node (focus/IME continuity rides React reconciliation:
|
||||
* component identity + tree position, which this assembled tree pins).
|
||||
*
|
||||
* Component-level behavior (collapse interaction, card model arms, summary
|
||||
* derivations) lives in todo-panel.spec.tsx / terminal-card.spec.tsx; this
|
||||
* suite only proves the assembled wiring.
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, fireEvent, waitFor, within } from '@testing-library/react'
|
||||
import { LocaleService } from '@deepseek-ai/dsh-client-locale/client'
|
||||
import type { ISession, SessionId, TodoItem, ToolResultNode } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import type { PropsRenderSlots } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import { SlotTestRuntime } from '@deepseek-ai/dsh-client-test-runtime'
|
||||
import { apply, inject } from '@deepseek-ai/dsh-client-ui-conversation/client'
|
||||
|
||||
const SID = 's1' as SessionId
|
||||
|
||||
afterEach(cleanup)
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
const TODOS: TodoItem[] = [
|
||||
{ content: '梳理需求', status: 'completed' },
|
||||
{ content: '实现 fixture 样本', status: 'in_progress' },
|
||||
{ content: '浏览器验收', status: 'pending' },
|
||||
]
|
||||
|
||||
const todoResult = (seq: number): ToolResultNode => ({
|
||||
kind: 'tool-result', seq, time: seq * 1_000, callId: `todo-${seq}`,
|
||||
call: { name: 'todo_write', argsRaw: JSON.stringify({ todos: TODOS }) },
|
||||
callTime: seq * 1_000 - 500,
|
||||
content: [], isError: false, callView: null, resultView: null,
|
||||
})
|
||||
|
||||
const bashResult = (seq: number, callId: string, over?: Partial<ToolResultNode>): ToolResultNode => ({
|
||||
kind: 'tool-result', seq, time: seq * 1_000, callId,
|
||||
call: { name: 'bash', argsRaw: '{"command":"ls -la","description":"List files"}' },
|
||||
callTime: seq * 1_000 - 500,
|
||||
content: [{ type: 'text', text: 'total 2\ndemo.txt\n' }], isError: false,
|
||||
callView: { card: 'terminal', title: 'ls -la', description: 'List files' },
|
||||
resultView: { card: 'terminal', output: 'total 2\ndemo.txt\n', exitCode: 0 },
|
||||
...over,
|
||||
})
|
||||
|
||||
/** Test-owned AppFrame role: declares and renders the resident conversation area. */
|
||||
type AppRootProps = PropsRenderSlots<'conversation' | 'details'>
|
||||
function AppRoot({ renderSlot }: AppRootProps) {
|
||||
return <>{renderSlot('conversation', {})}</>
|
||||
}
|
||||
|
||||
const LAYOUT_CHILDREN = {
|
||||
'conversation': { kind: 'single', scope: 'session-maybe' },
|
||||
'details': { kind: 'single', scope: 'session' },
|
||||
} as const
|
||||
|
||||
async function bench(nodes: ToolResultNode[], opts?: { blank?: boolean }) {
|
||||
const runtime = await SlotTestRuntime.create()
|
||||
runtime.provide('layout', { openDetails: vi.fn(), closeDetails: vi.fn() })
|
||||
runtime.provide('locale', new LocaleService(runtime.ctx))
|
||||
await runtime.sessions.add({
|
||||
id: SID,
|
||||
summary: { title: 'S', displayTitle: 'S', cwd: '/proj' },
|
||||
snapshot: {
|
||||
nodes,
|
||||
...(opts?.blank === true ? { blank: true, composerPhase: 'blank' as const } : {}),
|
||||
},
|
||||
session: {
|
||||
loadOlder: vi.fn<ISession['loadOlder']>(),
|
||||
prompt: vi.fn<ISession['prompt']>(async () => ({ ok: true, value: { accepted: true } })),
|
||||
},
|
||||
})
|
||||
await runtime.root.declare(LAYOUT_CHILDREN, AppRoot)
|
||||
await runtime.mount({ inject: [...inject], apply })
|
||||
return runtime
|
||||
}
|
||||
|
||||
describe('todo_write assembly (product registrations, no outlet twins)', () => {
|
||||
it('reaches the keyed toolview row and the dock plan strip, and the strip follows projection retirement', async () => {
|
||||
const runtime = await bench([todoResult(3)])
|
||||
// The dock strip reads the host-computed 'todos' projection.
|
||||
runtime.sessions.behavior(SID).projections.set('todos', TODOS)
|
||||
const view = runtime.renderRoot()
|
||||
|
||||
// Keyed toolview registration took the row (summary derived from args).
|
||||
const row = view.container.querySelector('[data-sample="todo-row"]')
|
||||
expect(row).not.toBeNull()
|
||||
expect(row!.textContent).toContain('1/3 已完成 · 实现 fixture 样本')
|
||||
|
||||
// The plan strip sits in the input dock, fed by the projection
|
||||
// (default-collapsed: the header summary shows; rows appear on expand).
|
||||
const panel = view.container.querySelector('[data-testid="todo-panel"]')
|
||||
expect(panel).not.toBeNull()
|
||||
expect(panel!.textContent).toContain('1/3 tasks · 1 in progress')
|
||||
fireEvent.click(panel!.querySelector('button')!)
|
||||
expect([...panel!.querySelectorAll('li')].map(li => li.getAttribute('data-status')))
|
||||
.toEqual(['completed', 'in_progress', 'pending'])
|
||||
|
||||
// Next turn retires the standing plan (host pushes null): the strip
|
||||
// clears while the historical row stays in the flow.
|
||||
await runtime.flush()
|
||||
runtime.sessions.behavior(SID).projections.set('todos', null)
|
||||
await waitFor(() => {
|
||||
expect(view.container.querySelector('[data-testid="todo-panel"]')).toBeNull()
|
||||
})
|
||||
expect(view.container.querySelector('[data-sample="todo-row"]')).not.toBeNull()
|
||||
await runtime.dispose()
|
||||
})
|
||||
})
|
||||
|
||||
describe('terminal card assembly', () => {
|
||||
it('the keyed bash row carries a resident terminal card; the fallback row reaches one through expand', async () => {
|
||||
const runtime = await bench([
|
||||
bashResult(3, 'c-keyed'),
|
||||
// An unregistered tool with terminal views: GenericToolCard fallback.
|
||||
bashResult(4, 'c-fallback', { call: { name: 'fx-bash', argsRaw: '{"command":"ls -la"}' } }),
|
||||
])
|
||||
const view = runtime.renderRoot()
|
||||
|
||||
// Keyed BashRow renders the card residently (no expand gesture).
|
||||
const keyed = view.container.querySelector('[data-sample="bash-global"]')?.parentElement
|
||||
expect(keyed?.querySelector('[data-terminal]')).not.toBeNull()
|
||||
|
||||
// Fallback row: card appears only after its expand control.
|
||||
const fallback = view.container.querySelector('[data-tool="fx-bash"]')
|
||||
expect(fallback).not.toBeNull()
|
||||
expect(fallback!.querySelector('[data-terminal]')).toBeNull()
|
||||
fireEvent.click(fallback!.querySelector('button[aria-expanded]')!)
|
||||
await waitFor(() => {
|
||||
expect(fallback!.querySelector('[data-terminal]')).not.toBeNull()
|
||||
})
|
||||
await runtime.dispose()
|
||||
})
|
||||
})
|
||||
|
||||
describe('resident composer', () => {
|
||||
it('renders the locked view state while no session exists at all', async () => {
|
||||
const runtime = await SlotTestRuntime.create()
|
||||
runtime.provide('layout', { openDetails: vi.fn(), closeDetails: vi.fn() })
|
||||
runtime.provide('locale', new LocaleService(runtime.ctx))
|
||||
await runtime.root.declare(LAYOUT_CHILDREN, AppRoot)
|
||||
await runtime.mount({ inject: [...inject], apply })
|
||||
const view = runtime.renderRoot()
|
||||
// No session entity: the inert twin renders (disabled textarea), and the
|
||||
// workspace picker chip is the only live control.
|
||||
const textarea = view.container.querySelector('textarea')
|
||||
expect(textarea).not.toBeNull()
|
||||
expect(textarea!.disabled).toBe(true)
|
||||
expect(view.getByRole('button', { name: 'Choose workspace' })).toBeTruthy()
|
||||
await runtime.dispose()
|
||||
})
|
||||
|
||||
|
||||
it('the textarea survives the blank→active conversion as the same DOM node', async () => {
|
||||
const runtime = await bench([], { blank: true })
|
||||
// The hero renders the LIVE composer only when the blank session's
|
||||
// workspace resolves a chip title; an ownerless blank session shows the
|
||||
// disabled twin instead (deleted-workspace semantics).
|
||||
await runtime.workspaces.update((draft) => {
|
||||
draft.items = [{ workspaceId: 'w1', title: 'Proj', path: '/proj', sessionIds: [SID] }] as never
|
||||
})
|
||||
const view = runtime.renderRoot()
|
||||
const hero = view.container.querySelector('textarea')
|
||||
expect(hero).not.toBeNull()
|
||||
expect(hero!.disabled).toBe(false)
|
||||
|
||||
// First acceptance: the session leaves blank and the composer docks.
|
||||
await runtime.sessions.updateSnapshot(SID, (draft) => {
|
||||
draft.blank = false
|
||||
draft.composerPhase = 'active'
|
||||
})
|
||||
const docked = view.container.querySelector('textarea')
|
||||
expect(docked).toBe(hero)
|
||||
await runtime.dispose()
|
||||
})
|
||||
})
|
||||
|
||||
describe('prompt rejection through the assembled composer', () => {
|
||||
it('renders the promptError alert strip and keeps the draft in the machine', async () => {
|
||||
const runtime = await SlotTestRuntime.create()
|
||||
runtime.provide('layout', { openDetails: vi.fn(), closeDetails: vi.fn() })
|
||||
runtime.provide('locale', new LocaleService(runtime.ctx))
|
||||
const prompt = vi.fn<ISession['prompt']>(async () => ({
|
||||
ok: false, error: { code: 'agent-busy', message: 'prompt rejected before acceptance', details: { reason: 'busy' } },
|
||||
}))
|
||||
await runtime.sessions.add({
|
||||
id: SID,
|
||||
summary: { title: 'S', displayTitle: 'S', cwd: '/proj' },
|
||||
session: { prompt, loadOlder: vi.fn<ISession['loadOlder']>() },
|
||||
})
|
||||
await runtime.root.declare(LAYOUT_CHILDREN, AppRoot)
|
||||
await runtime.mount({ inject: [...inject], apply })
|
||||
const view = runtime.renderRoot()
|
||||
|
||||
const composer = view.container.querySelector('textarea')!
|
||||
fireEvent.change(composer, { target: { value: 'do not lose this' } })
|
||||
fireEvent.keyDown(composer, { key: 'Enter' })
|
||||
await waitFor(() => { expect(prompt).toHaveBeenCalledOnce() })
|
||||
|
||||
// The rejection lands in snapshot.promptError (the Session's own path);
|
||||
// the fixture mirrors that hop — the assembled InputBar renders it.
|
||||
await runtime.sessions.updateSnapshot(SID, (draft) => {
|
||||
draft.promptError = {
|
||||
op: 'send',
|
||||
error: { code: 'agent-busy', message: 'prompt rejected before acceptance', details: { reason: 'busy' } },
|
||||
}
|
||||
})
|
||||
const alert = await view.findByRole('alert')
|
||||
expect(alert.textContent).toContain('prompt rejected before acceptance (agent-busy)')
|
||||
// Failure restore: the machine returned the draft to the same textarea.
|
||||
await waitFor(() => {
|
||||
expect((view.container.querySelector('textarea'))!.value).toBe('do not lose this')
|
||||
})
|
||||
await runtime.dispose()
|
||||
})
|
||||
})
|
||||
|
||||
describe('title projection across assembled surfaces', () => {
|
||||
it('one summary update re-labels the breadcrumb and document.title consumers together', async () => {
|
||||
const runtime = await bench([])
|
||||
const view = runtime.renderRoot()
|
||||
// The strict session header breadcrumb reads useSessions ancestry.
|
||||
const crumb = within(view.container.querySelector('[aria-label="Session hierarchy"]') as HTMLElement)
|
||||
expect(crumb.getByText('S')).toBeTruthy()
|
||||
|
||||
await runtime.sessions.updateSummary(SID, { displayTitle: '修订标题', title: '修订标题' })
|
||||
await waitFor(() => { expect(crumb.getByText('修订标题')).toBeTruthy() })
|
||||
expect(crumb.queryByText('S')).toBeNull()
|
||||
await runtime.dispose()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,118 @@
|
||||
// @vitest-environment jsdom
|
||||
/**
|
||||
* The session-rename assembly chain on SlotTestRuntime (real apply, real
|
||||
* WorkspaceBrowser occupying the sidebar hole): row menu → rename dialog →
|
||||
* the injected renameSession hop (sessions.binding → ISession.rename) → on
|
||||
* the accepted unary response the dialog closes and the row re-labels from
|
||||
* the list state — no push-frame wait. Previously pinned only by the
|
||||
* assembled-app snapshot (apps/web/tests/session-actions.snapshot.ts); the
|
||||
* verb's wire behavior stays with the runtime package
|
||||
* (session.spec.ts#rename), the dialog's own arms with rows.spec /
|
||||
* workspace-browser.spec.
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, fireEvent, waitFor, within } from '@testing-library/react'
|
||||
import type { ISession, SessionId, WorkspaceId } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import type { PropsRenderSlots } from '@deepseek-ai/dsh-client-ui-slots'
|
||||
import { SlotTestRuntime } from '@deepseek-ai/dsh-client-test-runtime'
|
||||
import { apply, inject } from '@deepseek-ai/dsh-client-ui-workspace/client'
|
||||
|
||||
const SID = 's1' as SessionId
|
||||
|
||||
afterEach(cleanup)
|
||||
beforeEach(() => { localStorage.clear() })
|
||||
|
||||
/** Test-owned sidebar shell role: declares and renders the browsing region. */
|
||||
type FrameProps = PropsRenderSlots<'sidebar.workspaces'>
|
||||
function SidebarFrame({ renderSlot }: FrameProps) {
|
||||
return <>{renderSlot('sidebar.workspaces', { wide: true, expandSidebar: () => {} })}</>
|
||||
}
|
||||
|
||||
describe('session rename through the assembled browser', () => {
|
||||
it('renames via the row menu: binding.session.rename fires, the dialog closes, the row re-labels from the list', async () => {
|
||||
const runtime = await SlotTestRuntime.create()
|
||||
const rename = vi.fn<ISession['rename']>(async title => ({
|
||||
ok: true, value: { title: title.trim().replace(/\s+/g, ' '), seq: 7 },
|
||||
}))
|
||||
await runtime.sessions.add({
|
||||
id: SID,
|
||||
summary: { title: '旧标题', displayTitle: '旧标题', cwd: '/w/alpha' },
|
||||
session: { rename },
|
||||
})
|
||||
await runtime.workspaces.update((draft) => {
|
||||
draft.items = [{
|
||||
workspaceId: 'w1' as WorkspaceId, title: 'alpha', path: '/w/alpha',
|
||||
sessionIds: [SID], createdAt: '2026-01-01T00:00:00.000Z', updatedAt: '2026-01-01T00:00:00.000Z',
|
||||
}] as never
|
||||
})
|
||||
await runtime.root.declare(
|
||||
{ 'sidebar.workspaces': { kind: 'single', scope: 'root' } } as never,
|
||||
SidebarFrame as never,
|
||||
)
|
||||
await runtime.mount({ inject: [...inject], apply })
|
||||
const view = runtime.renderRoot()
|
||||
|
||||
// The current session's group auto-expands; open the row's action menu.
|
||||
const row = (await view.findByText('旧标题')).closest('[role="treeitem"]')!
|
||||
fireEvent.click(within(row as HTMLElement).getByLabelText('Session actions for 旧标题'))
|
||||
fireEvent.click(view.getByRole('menuitem', { name: 'Rename', hidden: true }))
|
||||
|
||||
// The dialog seeds from the current title; submit a padded value.
|
||||
const input = await view.findByLabelText('Session name') as HTMLInputElement
|
||||
expect(input.value).toBe('旧标题')
|
||||
fireEvent.change(input, { target: { value: ' 分叉 实验记录 ' } })
|
||||
fireEvent.click(view.getByRole('button', { name: 'Rename' }))
|
||||
|
||||
// The injected hop reached the session face with the edge-trimmed draft
|
||||
// (the dialog trims edges; interior normalization is host-side).
|
||||
await waitFor(() => { expect(rename).toHaveBeenCalledWith('分叉 实验记录') })
|
||||
// Acceptance closes the dialog without any push-frame wait.
|
||||
await waitFor(() => { expect(view.queryByLabelText('Session name')).toBeNull() })
|
||||
// The manager lands the unary echo in the list store (its own package
|
||||
// tests own that hop); the row re-labels from list state alone.
|
||||
await runtime.sessions.updateSummary(SID, { displayTitle: '分叉 实验记录', title: '分叉 实验记录' })
|
||||
await view.findByText('分叉 实验记录')
|
||||
expect(view.queryByText('旧标题')).toBeNull()
|
||||
await runtime.dispose()
|
||||
})
|
||||
|
||||
it('a rejected rename keeps the dialog open with the error surfaced', async () => {
|
||||
const runtime = await SlotTestRuntime.create()
|
||||
const rename = vi.fn<ISession['rename']>(async () => ({
|
||||
ok: false, error: { code: 'internal', message: 'title write failed', details: {} },
|
||||
}))
|
||||
await runtime.sessions.add({
|
||||
id: SID,
|
||||
summary: { title: '旧标题', displayTitle: '旧标题', cwd: '/w/alpha' },
|
||||
session: { rename },
|
||||
})
|
||||
await runtime.workspaces.update((draft) => {
|
||||
draft.items = [{
|
||||
workspaceId: 'w1' as WorkspaceId, title: 'alpha', path: '/w/alpha',
|
||||
sessionIds: [SID], createdAt: '2026-01-01T00:00:00.000Z', updatedAt: '2026-01-01T00:00:00.000Z',
|
||||
}] as never
|
||||
})
|
||||
await runtime.root.declare(
|
||||
{ 'sidebar.workspaces': { kind: 'single', scope: 'root' } } as never,
|
||||
SidebarFrame as never,
|
||||
)
|
||||
await runtime.mount({ inject: [...inject], apply })
|
||||
const view = runtime.renderRoot()
|
||||
await runtime.flush()
|
||||
|
||||
const row = (await view.findByText('旧标题')).closest('[role="treeitem"]')!
|
||||
fireEvent.click(within(row as HTMLElement).getByLabelText('Session actions for 旧标题'))
|
||||
fireEvent.click(view.getByRole('menuitem', { name: 'Rename', hidden: true }))
|
||||
const input = await view.findByLabelText('Session name')
|
||||
fireEvent.change(input, { target: { value: '新名' } })
|
||||
fireEvent.click(view.getByRole('button', { name: 'Rename' }))
|
||||
|
||||
// Failure: the injected hop rethrows the business error; the dialog
|
||||
// stays open with the alert and the row keeps its title.
|
||||
const alert = await view.findByRole('alert')
|
||||
expect(alert.textContent).toContain('title write failed')
|
||||
expect(view.getByLabelText('Session name')).toBeTruthy()
|
||||
expect(view.getByText('旧标题')).toBeTruthy()
|
||||
await runtime.dispose()
|
||||
})
|
||||
})
|
||||
@@ -110,8 +110,8 @@ export class SessionReferenceService extends Service {
|
||||
*/
|
||||
async listCandidates(
|
||||
agent: Agent,
|
||||
query = '',
|
||||
limit = this.config.candidateLimit,
|
||||
query: string = '',
|
||||
limit: number = this.config.candidateLimit,
|
||||
signal?: AbortSignal,
|
||||
): Promise<SessionReferenceCandidate[]> {
|
||||
if (!Number.isSafeInteger(limit) || limit <= 0) {
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/cordis/tool-cordis/README.md
|
||||
README.md: 5b58e665dae95aea0d0ad094238fef5d3dc0fb97
|
||||
README.zh.md: 237b72244be2336a82c8c48cb341d7f9796d08f4
|
||||
README.md: eda135d93e2912bbb4e111af40d176409b383b5b
|
||||
README.zh.md: 6eef10086142d56dd809e5114b4e0e712f726ecc
|
||||
@@ -28,7 +28,7 @@ The sandbox isolates globals but is not a security boundary. Node globals are ab
|
||||
|
||||
## The generated API catalog
|
||||
|
||||
`src/api-catalog.ts` is generated by `scripts/gen-cordis-api.ts` from the same AST walk as [docs/cordis-catalog](../../../docs/cordis-catalog/services.md) and freshness-gated by `pnpm run verify-cordis-api` (in `doc-sync`) — never edit it by hand. `cordis_inspect` intersects it with the live service store at call time. Broad `api` / `events` reports render summaries and signatures only; an exact `name` opts into the retained method/event JSDoc, and unknown or non-running service targets fail loud.
|
||||
`src/api-catalog.ts` is generated from the same Typert `FaceModel` projection as [docs/cordis-catalog](../../../docs/cordis-catalog/services.md) and freshness-gated by `pnpm run verify-cordis-api` (in `doc-sync`) — never edit it by hand. `scripts/gen-cordis-api.ts` is a compatibility entry point for that unified projection, not a second collector. `cordis_inspect` intersects the committed catalog with the live service store at call time; it has no runtime Typert dependency. Broad `api` / `events` reports render summaries and signatures only; an exact `name` opts into the retained method/event JSDoc, and unknown or non-running service targets fail loud.
|
||||
|
||||
## Rendering
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
## 生成的 API 目录
|
||||
|
||||
`src/api-catalog.ts` 由 `scripts/gen-cordis-api.ts` 生成,使用与 [docs/cordis-catalog](../../../docs/cordis-catalog/services.md) 相同的 AST 遍历,并由 `pnpm run verify-cordis-api`(位于 `doc-sync` 中)实施新鲜度门禁,绝不可手工编辑。`cordis_inspect` 在调用时把该目录与存活服务 store 取交集。宽泛的 `api`/`events` 报告只渲染摘要与签名;精确 `name` 会选择保留的方法/事件 JSDoc,未知或未运行的服务目标会明确报错。
|
||||
`src/api-catalog.ts` 与 [docs/cordis-catalog](../../../docs/cordis-catalog/services.md) 由同一个 Typert `FaceModel` 投影生成,并由 `pnpm run verify-cordis-api`(位于 `doc-sync` 中)实施新鲜度门禁,绝不可手工编辑。`scripts/gen-cordis-api.ts` 是该统一投影的兼容入口,而非第二套收集器。`cordis_inspect` 在调用时把已提交的目录与存活服务 store 取交集;它在运行时不依赖 Typert。宽泛的 `api`/`events` 报告只渲染摘要与签名;精确 `name` 会选择保留的方法/事件 JSDoc,未知或未运行的服务目标会高声失败。
|
||||
|
||||
## 渲染
|
||||
|
||||
|
||||
@@ -489,7 +489,7 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
jsDoc: '/**\n * Deliver an allowed signal through an owned backend session.\n * @param owner - exact session owner.\n * @param id - target PTY identity.\n * @param signal - allowed POSIX signal name.\n * @returns delivered foreground process-group identity.\n */',
|
||||
},
|
||||
{
|
||||
signature: 'async kill(owner: Agent, id: PtySessionId, reason = \'model request\'): Promise<boolean>',
|
||||
signature: 'async kill(owner: Agent, id: PtySessionId, reason: string = \'model request\'): Promise<boolean>',
|
||||
jsDoc: '/**\n * Close one owned session and remove it only after quiescent backend cleanup.\n * @param owner - exact session owner.\n * @param id - target PTY identity.\n * @param reason - diagnostic cleanup reason.\n * @returns true for a newly closed session, false when the same close is already in flight.\n */',
|
||||
},
|
||||
{
|
||||
@@ -679,7 +679,7 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
summary: 'Exact-read consumer that prepares immutable cross-session message context.',
|
||||
methods: [
|
||||
{
|
||||
signature: 'async listCandidates( agent: Agent, query = \'\', limit = this.config.candidateLimit, signal?: AbortSignal, ): Promise<SessionReferenceCandidate[]>',
|
||||
signature: 'async listCandidates( agent: Agent, query: string = \'\', limit: number = this.config.candidateLimit, signal?: AbortSignal, ): Promise<SessionReferenceCandidate[]>',
|
||||
jsDoc: '/**\n * List reference candidates, ranked by working-directory affinity.\n * @param agent - target agent; self is excluded and its cwd drives ranking.\n * @param query - optional case-insensitive session-id/cwd/title substring.\n * @param limit - optional positive result cap.\n * @param signal - optional cancellation boundary for host autocomplete teardown.\n * @returns candidates labeled by latest title or, when absent, session id.\n */',
|
||||
},
|
||||
{
|
||||
@@ -1002,6 +1002,40 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'typert',
|
||||
summary: 'Registry of generated schemas and package reflection.',
|
||||
methods: [
|
||||
{
|
||||
signature: 'register(contribution: TypertContribution): () => void',
|
||||
jsDoc: '/**\n * Register one generated contribution atomically for the calling fiber.\n * Duplicate package-face identities or schema keys reject the whole batch.\n * @param contribution - generated schemas and package metadata.\n * @returns the exact effect disposer that removes this contribution.\n */',
|
||||
},
|
||||
{
|
||||
signature: 'get(key: string): TypertSchemaRecord | undefined',
|
||||
jsDoc: '/**\n * Look up one schema by `<package>#<name>`.\n * @param key - global schema key.\n * @returns the live schema record, or `undefined` when absent.\n */',
|
||||
},
|
||||
{
|
||||
signature: 'resolve(key: string): TypertSchemaRecord',
|
||||
jsDoc: '/**\n * Resolve one required schema.\n * @param key - global schema key.\n * @returns the live schema record.\n * @throws when the key is malformed, the package face is absent, or the schema is not contributed.\n */',
|
||||
},
|
||||
{
|
||||
signature: 'list(filter: TypertSchemaFilter = {}): TypertSchemaRecord[]',
|
||||
jsDoc: '/**\n * Enumerate live schemas in registration order.\n * @param filter - optional package and face restriction.\n * @returns matching schema records.\n */',
|
||||
},
|
||||
{
|
||||
signature: 'getPackage(packageName: string, face: TypertFace = \'host\'): TypertPackageRecord | undefined',
|
||||
jsDoc: '/**\n * Look up generated reflection for one package face.\n * @param packageName - exact npm package name.\n * @param face - face to query; defaults to the host runtime.\n * @returns the live package record, or `undefined` when absent.\n */',
|
||||
},
|
||||
{
|
||||
signature: 'listPackages(filter: TypertPackageFilter = {}): TypertPackageRecord[]',
|
||||
jsDoc: '/**\n * Enumerate generated package reflection in registration order.\n * @param filter - optional package and face restriction.\n * @returns matching package records.\n */',
|
||||
},
|
||||
{
|
||||
signature: 'toJSONSchema(key: string, params?: z.core.ToJSONSchemaParams): z.core.JSONSchema.BaseSchema',
|
||||
jsDoc: '/**\n * Project a live Zod schema to JSON Schema without caching the result.\n * @param key - global schema key.\n * @param params - Zod projection parameters.\n * @returns a fresh JSON Schema document.\n */',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'userInteraction',
|
||||
summary: '`ctx.userInteraction`: one active UI provider plus an `ask()` surface.',
|
||||
@@ -1281,34 +1315,6 @@ export const EVENT_API: readonly EventApiEntry[] = [
|
||||
jsDoc: '/**\n * A skill provider, runtime contribution, or provider-backed catalog may\n * have changed. This is an unfiltered invalidation notification; consumers\n * refetch the catalog for their own lookup options. Listener failures are\n * contained and cannot veto the registry mutation.\n * @mode emit\n */',
|
||||
summary: 'A skill provider, runtime contribution, or provider-backed catalog may have changed.',
|
||||
},
|
||||
{
|
||||
name: 'slash/input-begin-command',
|
||||
mode: 'bail',
|
||||
signature: '\'slash/input-begin-command\'(request: BeginCommandRequest): true | undefined',
|
||||
jsDoc: '/**\n * Applies one command claim to the scoped Input. Dispatched with the\n * session\'s scope carrier; the owning session\'s input listener returns\n * `true` only after the phase and span CAS checks pass and the machine\n * actually mutated — producers treat anything else as "not applied".\n * @param request - Claim and menu-time span CAS.\n * @mode bail\n */',
|
||||
summary: 'Applies one command claim to the scoped Input.',
|
||||
},
|
||||
{
|
||||
name: 'slash/input-consume-token',
|
||||
mode: 'bail',
|
||||
signature: '\'slash/input-consume-token\'(request: ConsumeTokenRequest): true | undefined',
|
||||
jsDoc: '/**\n * Consumes one command token after business success (popup settle /\n * menu-pick execute). Same carrier routing and applied-truth contract.\n * @param request - Exact span or bare-token guard.\n * @mode bail\n */',
|
||||
summary: 'Consumes one command token after business success (popup settle / menu-pick execute).',
|
||||
},
|
||||
{
|
||||
name: 'slash/input-insert-reference',
|
||||
mode: 'bail',
|
||||
signature: '\'slash/input-insert-reference\'(request: InsertReferenceRequest): true | undefined',
|
||||
jsDoc: '/**\n * Inserts one reference into the scoped Input (same carrier routing and\n * applied-truth contract as begin-command).\n * @param request - Reference and menu-time span CAS.\n * @mode bail\n */',
|
||||
summary: 'Inserts one reference into the scoped Input (same carrier routing and applied-truth contract as begin-command).',
|
||||
},
|
||||
{
|
||||
name: 'slash/input-insert-text',
|
||||
mode: 'bail',
|
||||
signature: '\'slash/input-insert-text\'(request: InsertTextRequest): true | undefined',
|
||||
jsDoc: '/**\n * Replaces the trigger token span with literal text — the plain-text\n * reference path (decision 21). Same carrier routing and applied-truth\n * contract; the draft gains ordinary characters, no occurrence entry.\n * @param request - Replacement text and menu-time span CAS.\n * @mode bail\n */',
|
||||
summary: 'Replaces the trigger token span with literal text — the plain-text reference path (decision 21).',
|
||||
},
|
||||
{
|
||||
name: 'subagent/end',
|
||||
mode: 'emit',
|
||||
@@ -2698,6 +2704,62 @@ export const TYPE_API: readonly TypeApiEntry[] = [
|
||||
name: 'TurnTriggerMap',
|
||||
declaration: 'export interface TurnTriggerMap {\n message: {\n kind: \'message\';\n source: MessageSource;\n };\n retry: {\n kind: \'retry\';\n };\n injection: {\n kind: \'injection\';\n source: MessageSource;\n };\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertContribution',
|
||||
declaration: 'export interface TypertContribution {\n readonly package: string;\n readonly face: TypertFace;\n readonly schemas: readonly TypertSchema[];\n readonly model: TypertPackageModel;\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertDocTag',
|
||||
declaration: 'export interface TypertDocTag {\n readonly name: string;\n readonly argument?: string;\n readonly comment?: string;\n readonly text: string;\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertDocumentation',
|
||||
declaration: 'export interface TypertDocumentation {\n readonly description?: string;\n readonly summary?: string;\n readonly tags: readonly TypertDocTag[];\n readonly jsDoc?: string;\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertEventModel',
|
||||
declaration: 'export interface TypertEventModel extends TypertDocumentation {\n readonly name: string;\n readonly mode?: string;\n readonly signature: string;\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertMemberModel',
|
||||
declaration: 'export interface TypertMemberModel {\n readonly kind: \'property\' | \'method\' | \'getter\' | \'setter\' | \'call\' | \'construct\' | \'index\';\n readonly name: string;\n readonly signature: string;\n readonly summary?: string;\n readonly jsDoc?: string;\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertObjectModel',
|
||||
declaration: 'export interface TypertObjectModel extends TypertDocumentation {\n readonly name: string;\n readonly exportName: string;\n readonly members: readonly TypertMemberModel[];\n readonly types: readonly TypertTypeModel[];\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertPackageFilter',
|
||||
declaration: 'export interface TypertPackageFilter {\n readonly package?: string;\n readonly face?: TypertFace;\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertPackageModel',
|
||||
declaration: 'export interface TypertPackageModel {\n readonly services: readonly TypertServiceModel[];\n readonly events: readonly TypertEventModel[];\n readonly objects: readonly TypertObjectModel[];\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertPackageRecord',
|
||||
declaration: 'export interface TypertPackageRecord {\n readonly package: string;\n readonly face: TypertFace;\n readonly key: string;\n readonly model: TypertPackageModel;\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertSchema',
|
||||
declaration: 'export interface TypertSchema {\n readonly name: string;\n readonly schema: z.ZodType;\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertSchemaFilter',
|
||||
declaration: 'export interface TypertSchemaFilter {\n readonly package?: string;\n readonly face?: TypertFace;\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertSchemaRecord',
|
||||
declaration: 'export interface TypertSchemaRecord extends TypertSchema {\n readonly package: string;\n readonly face: TypertFace;\n readonly key: string;\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertServiceModel',
|
||||
declaration: 'export interface TypertServiceModel extends TypertDocumentation {\n readonly key: string;\n readonly exportName: string;\n readonly members: readonly TypertMemberModel[];\n readonly types: readonly TypertTypeModel[];\n}',
|
||||
},
|
||||
{
|
||||
name: 'TypertTypeModel',
|
||||
declaration: 'export interface TypertTypeModel {\n readonly name: string;\n readonly declaration: string;\n}',
|
||||
},
|
||||
{
|
||||
name: 'UserInteractionProvider',
|
||||
declaration: 'export interface UserInteractionProvider {\n ask(request: AskUserQuestionRequest): Promise<AskUserQuestionAnswer>;\n}',
|
||||
|
||||
@@ -115,7 +115,10 @@ export type AgentCancelCause =
|
||||
/** Runtime reason carried by the signal that controls one live turn. */
|
||||
export type AgentInterruptReason = AgentCancelCause | { readonly kind: 'disposed' }
|
||||
|
||||
/** Public live-agent handle with aliases over the unified delivery primitive. */
|
||||
/**
|
||||
* Public live-agent handle with aliases over the unified delivery primitive.
|
||||
* @typert object
|
||||
*/
|
||||
export interface Agent {
|
||||
/** The single identity shared with {@link session}. */
|
||||
readonly id: SessionId
|
||||
|
||||
@@ -353,6 +353,7 @@ const attachments = new WeakMap<Session, SessionEntry>()
|
||||
*
|
||||
* Plain class (not a Service) — create instances via `ctx.sessions.create()`.
|
||||
* Seeding with an existing event log replays/forks a session.
|
||||
* @typert object
|
||||
*/
|
||||
export class Session {
|
||||
private log: SessionEvent[] = []
|
||||
|
||||
@@ -282,7 +282,7 @@ export class PtyService extends Service {
|
||||
* @param reason - diagnostic cleanup reason.
|
||||
* @returns true for a newly closed session, false when the same close is already in flight.
|
||||
*/
|
||||
async kill(owner: Agent, id: PtySessionId, reason = 'model request'): Promise<boolean> {
|
||||
async kill(owner: Agent, id: PtySessionId, reason: string = 'model request'): Promise<boolean> {
|
||||
const record = this.expectOwned(owner, id)
|
||||
if (record.closing !== undefined) {
|
||||
await record.closing
|
||||
|
||||
@@ -46,7 +46,7 @@ export interface StorageForms {}
|
||||
*/
|
||||
export class Storage extends Service {
|
||||
/** Named backend table; multiple backends stay mounted side by side. */
|
||||
readonly backend = new BackendRegistry()
|
||||
readonly backend: BackendRegistry = new BackendRegistry()
|
||||
|
||||
private readonly forms = new Map<keyof StorageForms, unknown>()
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/typert/README.md
|
||||
README.md: d11fd8f57245379d67d2a1cdcca334f0032db469
|
||||
README.zh.md: 97e57f9585efa2e86edc1edf576fef4738b63203
|
||||
@@ -0,0 +1,11 @@
|
||||
# Typert
|
||||
|
||||
English | [中文](README.zh.md)
|
||||
|
||||
Typert separates source analysis, runtime storage, and Loader discovery into independent packages.
|
||||
|
||||
| Package | Role | Cordis key |
|
||||
|---|---|---|
|
||||
| [`registry/`](registry/README.md) | Runtime package reflection and live Zod schema registry | `ctx.typert` |
|
||||
| [`loader/`](loader/README.md) | Loader-entry discovery and generated host-artifact registration | consumes `ctx.loader`, `ctx.typert` |
|
||||
| [`generator/`](generator/README.md) | Compiler-independent type analysis and artifact generation | build-time library |
|
||||
@@ -0,0 +1,11 @@
|
||||
# Typert
|
||||
|
||||
[English](README.md) | 中文
|
||||
|
||||
Typert 将源代码分析、运行时存储和 Loader 发现机制拆分为彼此独立的包(package)。
|
||||
|
||||
| 包 | 职责 | Cordis 键 |
|
||||
|---|---|---|
|
||||
| [`registry/`](registry/README.md) | 运行时包反射和实时 Zod schema 注册表 | `ctx.typert` |
|
||||
| [`loader/`](loader/README.md) | 发现 Loader 条目并注册所生成的宿主产物 | 使用 `ctx.loader`、`ctx.typert` |
|
||||
| [`generator/`](generator/README.md) | 与编译器无关的类型分析和产物生成 | 构建时库 |
|
||||
@@ -0,0 +1,6 @@
|
||||
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/typert/generator/README.md
|
||||
README.md: c343fd9475a9407159037f0a10e3a0586a77c3da
|
||||
README.zh.md: e00abe205e5c5c33e7e0028606df169d447e4006
|
||||
@@ -0,0 +1,41 @@
|
||||
# @deepseek-ai/dsh-typert-generator
|
||||
|
||||
English | [中文](README.zh.md)
|
||||
|
||||
TypeScript project analyzer and model-driven Typert generator. It converts the developer-authored source type tree into compiler-independent `FaceModel` and `TypeGraph` data before any artifact is rendered. Static analysis can consume that model without Cordis; emitters never receive TypeScript AST or checker objects.
|
||||
|
||||
Host and client use independent `ts.Program` instances seeded from `tsconfig.host.json` and `tsconfig.client.json`. Direct project references establish face membership, `package.json#exports` establishes every cross-package public boundary, and source imports or re-exports are the only allowed cross-face edges. Types owned by NPM dependencies, including global declarations from `@types` packages, remain `external` references instead of being expanded.
|
||||
|
||||
## Analysis Model
|
||||
|
||||
Each face contains package exports, Cordis services and events, explicitly tagged objects and schemas, and a type graph for their reachable declarations. The graph preserves declaration identity, generic parameters and applications, explicit inheritance, conditional and mapped types, import attributes, abstract modifiers, and source JSDoc. Service and `@typert object` surfaces expose public instance members only; constructors, static members, and non-public members are excluded.
|
||||
|
||||
`WorkspaceAnalyzer` defaults to `check` mode and fails on TypeScript syntax or semantic diagnostics, missing reachable public annotations, private cross-package references, and reachable declaration merges that the model cannot retain losslessly. `write` mode inserts checker-derived annotations, rebuilds the program, and returns a clean check-mode model.
|
||||
|
||||
## Emission and Opt-in Publication
|
||||
|
||||
`FaceModelEmitter` consumes only the model. It emits executable JavaScript containing supported Zod schemas and a `TYPERT` contribution, plus a declaration file whose schemas are typed as `z.ZodType<SourceType>` through the package's public export. Unsupported Zod projections fail instead of flattening or weakening the source type.
|
||||
|
||||
`WorkspaceTypertGenerator` discovers contributors by walking package public exports reachable from Cordis `Context` or `Events` augmentations and explicit `@typert` declarations. When invoked for artifact publication, it requires host artifacts at `lib/typert.host.{js,d.ts}` exposed as `package/typert`, and client artifacts at `lib/typert.client.{js,d.ts}` exposed as `package/client/typert`. Generated declarations expose `TYPERT` as `unknown`, so contributing business packages do not depend on the runtime registry.
|
||||
|
||||
Publication is package opt-in. The root build and typecheck do not generate Typert artifacts or require every business package to add Typert exports. Static consumers can call `WorkspaceAnalyzer` directly, select host/client and package subsets, and use bounded package batches without publishing or loading runtime artifacts.
|
||||
|
||||
## Repository-specific Cordis projection
|
||||
|
||||
The root package export includes the model-driven extraction, completeness checks, and deterministic text renderers used by this repository's Cordis catalogs. They accept a `CordisCatalogPolicy`; repository-owned type links, foundation/exemption classifications, and inherited Cordis entries remain in `scripts/gen-cordis-catalog.ts` and are passed in explicitly. The generator package therefore contains projection mechanics, not a hidden copy of this repository's documentation taxonomy.
|
||||
|
||||
## Model Experience
|
||||
|
||||
None, as this package runs at build or test time and never contributes to a model request.
|
||||
|
||||
#### KV Cache effect
|
||||
|
||||
None.
|
||||
|
||||
## Known Limitations and Deferred Work
|
||||
|
||||
- Package export patterns are skipped; contributing packages need concrete export targets.
|
||||
- Cross-face named and star re-exports produce links; namespace re-exports fail until `TypeTargetModel` can represent a module namespace without flattening it.
|
||||
- The Zod emitter supports a deliberate subset of the modeled TypeScript graph. Generic schema declarations and computed constructs such as conditional or mapped schema roots fail until a concrete schema-factory policy exists.
|
||||
- Cross-face links are represented for analysis, but no generated schema currently requires a runtime cross-face Zod import.
|
||||
- Discovery follows source files reachable from concrete public exports; declarations that are neither exported nor imported by that graph are intentionally outside the package model.
|
||||
@@ -0,0 +1,41 @@
|
||||
# @deepseek-ai/dsh-typert-generator
|
||||
|
||||
[English](README.md) | 中文
|
||||
|
||||
TypeScript 项目分析器和模型驱动的 Typert 生成器。在生成任何产物之前,它会先将开发者编写的源类型树转换为独立于编译器的 `FaceModel` 和 `TypeGraph` 数据。静态分析无需 Cordis 即可消费该模型;各产物生成组件均不会接收 TypeScript 抽象语法树(AST)或类型检查器对象。
|
||||
|
||||
宿主侧与客户端侧分别使用独立的 `ts.Program` 实例,二者以 `tsconfig.host.json` 和 `tsconfig.client.json` 初始化。直接项目引用确定各包(package)所属的 face,`package.json#exports` 确定所有跨包公开边界,跨 face 的边则只能来自源码中的导入或重新导出。NPM 依赖拥有的类型(包括 `@types` 包中的全局声明)继续以 `external` 引用表示,不会被展开。
|
||||
|
||||
## 分析模型
|
||||
|
||||
每个 face 包含包导出、Cordis 服务与事件、显式标记的对象与 schema,以及涵盖其可达声明的类型图。类型图保留声明标识、泛型参数及应用、显式继承、条件类型与映射类型、导入属性、abstract 修饰符和源码 JSDoc。服务和 `@typert object` 对外接口仅暴露公共实例成员;构造函数、静态成员与非公共成员均被排除。
|
||||
|
||||
`WorkspaceAnalyzer` 默认采用 `check` 模式,遇到 TypeScript 语法或语义诊断、可达公开声明缺少类型标注、跨包私有引用,以及模型无法无损保留的可达声明合并时,分析会失败。`write` 模式会插入类型检查器推导出的类型标注,重建该程序,并返回无诊断的检查模式模型。
|
||||
|
||||
## 产物生成与选择性发布
|
||||
|
||||
`FaceModelEmitter` 只消费模型。它会生成可执行 JavaScript,其中包含受支持的 Zod schema 和一个 `TYPERT` contribution;同时生成声明文件,通过包的公开导出将其中的 schema 标注为 `z.ZodType<SourceType>`。遇到不支持的 Zod 投影时,生成会失败,不会展平或弱化源类型。
|
||||
|
||||
`WorkspaceTypertGenerator` 会遍历从 Cordis `Context` 或 `Events` 扩充声明及显式 `@typert` 声明可达的包公开导出,以发现贡献方。发布产物时,它要求宿主侧产物位于 `lib/typert.host.{js,d.ts}` 并以 `package/typert` 暴露,客户端侧产物位于 `lib/typert.client.{js,d.ts}` 并以 `package/client/typert` 暴露。生成的声明将 `TYPERT` 暴露为 `unknown`,因此参与贡献的业务包无需依赖运行时注册表。
|
||||
|
||||
各包可自行选择是否发布。根目录的构建和类型检查不会生成 Typert 产物,也不要求每个业务包添加 Typert 导出。静态消费方可以直接调用 `WorkspaceAnalyzer`,选择宿主侧/客户端侧及包子集,并在不发布或加载运行时产物的情况下分批处理包,同时限制每批数量。
|
||||
|
||||
## 本仓库的 Cordis 投影
|
||||
|
||||
包根导出中包含本仓库 Cordis 目录使用的模型驱动提取逻辑、完整性检查和确定性文本渲染器。它们接受 `CordisCatalogPolicy`;由仓库持有的类型链接、基础类型/豁免类型分类和继承的 Cordis 条目仍位于 `scripts/gen-cordis-catalog.ts`,并由调用方显式传入。因此,生成器包只包含投影机制,不会隐式复制本仓库的文档分类体系。
|
||||
|
||||
## 模型体验
|
||||
|
||||
无。该包仅在构建或测试时运行,不会向模型请求添加任何内容。
|
||||
|
||||
#### KV Cache 影响
|
||||
|
||||
无。
|
||||
|
||||
## 已知限制与暂缓工作
|
||||
|
||||
- 系统会跳过包导出中的模式匹配;参与贡献的包需要具体的导出目标。
|
||||
- 跨 face 的具名重新导出和星号重新导出会生成链接;在 `TypeTargetModel` 能够不经展平便表示模块命名空间之前,命名空间重新导出会失败。
|
||||
- Zod 产物生成组件仅支持 TypeScript 类型图中有意限定的部分。泛型 schema 声明,以及以条件类型或映射类型为 schema 根的计算构造,都会失败,直到存在明确的 schema 工厂策略。
|
||||
- 跨 face 链接会在模型中表示以供分析,但当前生成的 schema 均不需要跨 face 的运行时 Zod 导入。
|
||||
- 发现过程会遍历从具体公开导出可达的源文件;既未导出、也未由该图导入的声明会按设计排除在包模型之外。
|
||||
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "@deepseek-ai/dsh-typert-generator",
|
||||
"description": "TypeScript project analyzer and model-driven Typert artifact generator",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/types/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/types/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./tsdown": {
|
||||
"types": "./lib/types/tsdown-plugin.d.ts",
|
||||
"default": "./lib/types/tsdown-plugin.js"
|
||||
},
|
||||
"./invariant": {
|
||||
"types": "./lib/types/invariant.d.ts",
|
||||
"default": "./lib/invariant.js"
|
||||
},
|
||||
"./src/*": "./src/*",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"lib/index.js",
|
||||
"lib/invariant.js",
|
||||
"lib/types/**/*.js",
|
||||
"lib/types/**/*.d.ts",
|
||||
"lib/types/**/*.d.ts.map",
|
||||
"src"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"typescript": "^6.0.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@deepseek-ai/dsh-invariants": "^0.0.1",
|
||||
"cordis": "^4.0.0-rc.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@deepseek-ai/dsh-invariants": "workspace:^",
|
||||
"@deepseek-ai/dsh-tool-cordis": "workspace:^",
|
||||
"@deepseek-ai/dsh-typert-registry": "workspace:^",
|
||||
"cordis": "^4.0.0-rc.7",
|
||||
"zod": "^4.4.3"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,814 @@
|
||||
/**
|
||||
* Cordis catalog-specific projection over the compiler-independent Typert
|
||||
* model. This module owns Cordis validation and text projection mechanics;
|
||||
* callers supply repository-specific type classifications and inherited data.
|
||||
* @module @deepseek-ai/dsh-typert-generator
|
||||
*/
|
||||
|
||||
import { WorkspaceAnalyzer } from './analyzer.ts'
|
||||
import { childTypeNodeIds } from './model.ts'
|
||||
import { TypeGraphRenderer } from './renderer.ts'
|
||||
import type {
|
||||
FaceModel,
|
||||
MemberModel,
|
||||
ParameterModel,
|
||||
SignatureModel,
|
||||
SourceDeclarationModel,
|
||||
SourceLocation,
|
||||
TypeNodeId,
|
||||
} from './model.ts'
|
||||
|
||||
type Mode = 'emit' | 'waterfall' | 'parallel' | 'serial'
|
||||
|
||||
/** The fenced-block info string for generated signature blocks (skipped by
|
||||
* doc-typecheck, since a bare signature fragment is not standalone-compilable). */
|
||||
const FENCE = 'ts cordis-catalog'
|
||||
|
||||
/** Append fail-closed signature type-link violations from the retained type tree. */
|
||||
function checkTypeLinks(
|
||||
where: string,
|
||||
names: readonly string[],
|
||||
policy: CordisCatalogPolicy,
|
||||
violations: string[],
|
||||
): void {
|
||||
for (const name of names) {
|
||||
if (Object.hasOwn(policy.linkedTypePages, name)
|
||||
|| policy.foundationTypeNames.has(name)
|
||||
|| Object.hasOwn(policy.typeLinkExemptions, name)) continue
|
||||
violations.push(
|
||||
`${where} references unclassified type '${name}'. Add it to linkedTypePages with its documentation page, `
|
||||
+ 'to foundationTypeNames if TypeScript or the framework owns it, or to typeLinkExemptions with '
|
||||
+ 'the non-catalog documentation owner.',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Throw one aggregated diagnostic for every unclassified signature type. */
|
||||
function reportTypeLinkViolations(gate: string, violations: string[]): void {
|
||||
if (violations.length === 0) return
|
||||
throw new Error(
|
||||
`${gate}: ${violations.length} signature type-link coverage violation(s):\n`
|
||||
+ violations.map(violation => ` ${violation}`).join('\n'),
|
||||
)
|
||||
}
|
||||
|
||||
/** One harness event, extracted from an `interface Events` block. */
|
||||
export interface EventEntry {
|
||||
/** Scoped name, e.g. `agent/request`. */
|
||||
name: string
|
||||
/** The scope prefix, e.g. `agent` (everything before the first `/`). */
|
||||
scope: string
|
||||
/** Full signature text (the method-signature member, JSDoc stripped). */
|
||||
signature: string
|
||||
/** Original declaration JSDoc, dedented from its containing interface. */
|
||||
jsDoc: string
|
||||
/** Dispatch mode from the `@mode` tag. */
|
||||
mode: Mode
|
||||
/** Description prose (JSDoc minus the `@mode` tag), one line per paragraph. */
|
||||
doc: string
|
||||
/** Source pointer `packages/…/file.ts:line` of the declaration. */
|
||||
source: string
|
||||
}
|
||||
|
||||
/** One public service method and the source contract attached to it. */
|
||||
export interface ServiceMethodEntry {
|
||||
/** Public method signature (body stripped). */
|
||||
signature: string
|
||||
/** Original method JSDoc, dedented from its containing class. */
|
||||
jsDoc: string
|
||||
}
|
||||
|
||||
/** One harness service, extracted from an `interface Context` block. */
|
||||
export interface ServiceEntry {
|
||||
/** The `ctx.<key>` name, e.g. `llm`. */
|
||||
key: string
|
||||
/** The service class/interface name, e.g. `LlmService`. */
|
||||
type: string
|
||||
/** Whether the service class is abstract (a seam interface). */
|
||||
abstract: boolean
|
||||
/** Class-level JSDoc prose, one line per paragraph. */
|
||||
doc: string
|
||||
/** Public methods (bodies stripped), in source order. */
|
||||
methods: ServiceMethodEntry[]
|
||||
/** Source pointer of the class declaration. */
|
||||
source: string
|
||||
}
|
||||
|
||||
/** A terse inherited-tier entry supplied by the catalog policy. */
|
||||
export interface InheritedEntry {
|
||||
/** Display name of the inherited event or context member group. */
|
||||
name: string
|
||||
/** One-line description rendered into the catalog. */
|
||||
summary: string
|
||||
/** Source pointer such as `vendor/…:line`. */
|
||||
source: string
|
||||
}
|
||||
|
||||
/** Repository policy consumed by the Cordis catalog parsing and rendering logic. */
|
||||
export interface CordisCatalogPolicy {
|
||||
/** Type names linked from signatures to their documentation pages. */
|
||||
readonly linkedTypePages: Readonly<Record<string, string>>
|
||||
/** TypeScript or framework types that need no repository documentation link. */
|
||||
readonly foundationTypeNames: ReadonlySet<string>
|
||||
/** Repository types deliberately documented outside the linked data catalog. */
|
||||
readonly typeLinkExemptions: Readonly<Record<string, string>>
|
||||
/** Manually curated framework events inherited by every plugin. */
|
||||
readonly inheritedEvents: readonly InheritedEntry[]
|
||||
/** Manually curated framework context members inherited by every plugin. */
|
||||
readonly inheritedServices: readonly InheritedEntry[]
|
||||
}
|
||||
|
||||
/** Complete model-level Cordis projection used by every text renderer. */
|
||||
export interface CordisCatalogModel {
|
||||
readonly events: readonly EventEntry[]
|
||||
readonly services: readonly ServiceEntry[]
|
||||
}
|
||||
|
||||
/** Repository-specific Cordis validation and projection over one Typert face. */
|
||||
export class CordisCatalogProjector {
|
||||
private readonly renderer: TypeGraphRenderer
|
||||
|
||||
/**
|
||||
* @param face - analyzed host face containing package business semantics.
|
||||
* @param sourceDeclarations - exported declarations available to the runtime type closure.
|
||||
* @param policy - caller-owned type classifications and inherited Cordis data.
|
||||
*/
|
||||
constructor(
|
||||
private readonly face: FaceModel,
|
||||
private readonly sourceDeclarations: readonly SourceDeclarationModel[],
|
||||
private readonly policy: CordisCatalogPolicy,
|
||||
) {
|
||||
if (face.face !== 'host') throw new Error(`cordis catalog requires the host face, received ${face.face}`)
|
||||
this.renderer = new TypeGraphRenderer(face.graph)
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and project the host model's Cordis surface.
|
||||
* @returns every validated service and event projected from the host model.
|
||||
*/
|
||||
project(): CordisCatalogModel {
|
||||
return {
|
||||
events: this.collectEvents(),
|
||||
services: this.collectServices(),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the model-facing static API consumed by `tool-cordis`.
|
||||
* @param model - validated Cordis catalog projection from this projector.
|
||||
* @returns the model-facing TypeScript catalog source.
|
||||
*/
|
||||
renderRuntimeApi(model: CordisCatalogModel): string {
|
||||
return renderRuntimeApi(
|
||||
model.services,
|
||||
model.events,
|
||||
this.runtimeTypes(model.services),
|
||||
this.policy.inheritedServices,
|
||||
)
|
||||
}
|
||||
|
||||
private collectEvents(): EventEntry[] {
|
||||
const entries: EventEntry[] = []
|
||||
const violations: string[] = []
|
||||
const typeLinkViolations: string[] = []
|
||||
for (const packageModel of this.face.packages) {
|
||||
for (const event of packageModel.events) {
|
||||
const source = pointer(event.location)
|
||||
const where = `event '${event.name}' (${source})`
|
||||
const node = this.renderer.node(event.signature)
|
||||
if (node.kind !== 'function') {
|
||||
violations.push(`${where} is not represented by a callable type.`)
|
||||
continue
|
||||
}
|
||||
checkTypeLinks(where, signatureTypeNames(this.renderer, node.signature), this.policy, typeLinkViolations)
|
||||
const parsed = parseJsDoc(event.jsDoc ?? '')
|
||||
const mode = event.mode
|
||||
if (!isMode(mode)) {
|
||||
violations.push(`${where} is missing an @mode tag. Add '@mode emit|waterfall|parallel|serial' to its JSDoc (see AGENTS.md).`)
|
||||
}
|
||||
const last = node.signature.parameters.at(-1)
|
||||
const hasNext = last?.name === 'next'
|
||||
if (isMode(mode) && hasNext && mode !== 'waterfall') {
|
||||
violations.push(`${where} has a trailing 'next' parameter (structurally a waterfall) but is tagged '@mode ${mode}'. Fix the tag or the signature.`)
|
||||
}
|
||||
if (isMode(mode) && !hasNext && mode === 'waterfall') {
|
||||
violations.push(`${where} is tagged '@mode waterfall' but has no trailing 'next' parameter. A waterfall delegates via next().`)
|
||||
}
|
||||
if (parsed.doc === '') {
|
||||
violations.push(`${where} has no description prose. Say what happened / what a listener may do, above the block tags.`)
|
||||
}
|
||||
checkParams(
|
||||
where,
|
||||
'event',
|
||||
node.signature.parameters,
|
||||
parsed.params,
|
||||
parameter => parameter.receiver || (hasNext && parameter === last),
|
||||
violations,
|
||||
)
|
||||
if (isMode(mode)) {
|
||||
entries.push({
|
||||
name: event.name,
|
||||
scope: event.name.split('/')[0] ?? event.name,
|
||||
signature: event.text,
|
||||
jsDoc: event.jsDoc ?? '',
|
||||
mode,
|
||||
doc: parsed.doc,
|
||||
source,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
reportViolations('gen-cordis-catalog', violations)
|
||||
reportTypeLinkViolations('gen-cordis-catalog', typeLinkViolations)
|
||||
return entries
|
||||
}
|
||||
|
||||
private collectServices(): ServiceEntry[] {
|
||||
const entries: ServiceEntry[] = []
|
||||
const violations: string[] = []
|
||||
const typeLinkViolations: string[] = []
|
||||
for (const packageModel of this.face.packages) {
|
||||
for (const service of packageModel.services) {
|
||||
const declaration = this.renderer.declaration(service.symbol)
|
||||
if (declaration.kind !== 'class'
|
||||
|| !/^packages\/[^/]+\/[^/]+\/src\/index\.ts$/.test(service.location.file)
|
||||
|| declaration.location.file !== service.location.file) continue
|
||||
const doc = parseJsDoc(declaration.jsDoc ?? '').doc
|
||||
const source = pointer(declaration.location)
|
||||
if (doc === '') {
|
||||
violations.push(`service ctx.${service.key} (${source}): class ${declaration.name} has no JSDoc.`)
|
||||
}
|
||||
const methods: ServiceMethodEntry[] = []
|
||||
for (const memberId of service.members) {
|
||||
const member = this.renderer.member(memberId)
|
||||
if (member.kind !== 'method' || member.name.startsWith('[')) continue
|
||||
const where = `service method ctx.${service.key}.${member.name} (${pointer(member.location)})`
|
||||
checkTypeLinks(where, signatureTypeNames(this.renderer, member.signature), this.policy, typeLinkViolations)
|
||||
methods.push({ signature: member.text, jsDoc: member.jsDoc ?? '' })
|
||||
if (member.jsDoc === undefined) {
|
||||
violations.push(`${where} has no JSDoc.`)
|
||||
continue
|
||||
}
|
||||
const parsed = parseJsDoc(member.jsDoc)
|
||||
if (parsed.doc === '') violations.push(`${where} has no description prose above its block tags.`)
|
||||
checkParams(where, 'service', member.signature.parameters, parsed.params,
|
||||
parameter => parameter.receiver, violations)
|
||||
checkReturns(where, member.signature, parsed.returns, this.renderer, violations)
|
||||
}
|
||||
entries.push({
|
||||
key: service.key,
|
||||
type: declaration.name,
|
||||
abstract: declaration.abstract,
|
||||
doc,
|
||||
methods,
|
||||
source,
|
||||
})
|
||||
}
|
||||
}
|
||||
reportViolations('gen-cordis-catalog', violations)
|
||||
reportTypeLinkViolations('gen-cordis-catalog', typeLinkViolations)
|
||||
return entries.sort((left, right) => left.key.localeCompare(right.key))
|
||||
}
|
||||
|
||||
private runtimeTypes(services: readonly ServiceEntry[]): { name: string; declaration: string }[] {
|
||||
const declarations = new Map<string, string>()
|
||||
const ambiguous = new Set<string>()
|
||||
for (const declaration of this.sourceDeclarations) {
|
||||
if (declaration.face !== 'host' || declaration.kind === 'enum'
|
||||
|| !/^packages\/[^/]+\/[^/]+\/src\/[^/]+\.ts$/.test(declaration.location.file)) continue
|
||||
if (declarations.has(declaration.name)) {
|
||||
ambiguous.add(declaration.name)
|
||||
continue
|
||||
}
|
||||
declarations.set(
|
||||
declaration.name,
|
||||
declaration.text.length > MAX_DECL_CHARS
|
||||
? `${declaration.text.slice(0, MAX_DECL_CHARS)} /* …truncated — full shape in source */`
|
||||
: declaration.text,
|
||||
)
|
||||
}
|
||||
for (const name of ambiguous) declarations.delete(name)
|
||||
return referencedTypes(services.flatMap(service => service.methods.map(method => method.signature)), declarations)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze the host project once and return both the model and its projection.
|
||||
* @param scanRoot - workspace root containing `tsconfig.host.json`.
|
||||
* @param policy - caller-owned type classifications and inherited Cordis data.
|
||||
* @returns the configured projector and its validated catalog model.
|
||||
*/
|
||||
export function projectCordisCatalog(scanRoot: string, policy: CordisCatalogPolicy): {
|
||||
readonly projector: CordisCatalogProjector
|
||||
readonly model: CordisCatalogModel
|
||||
} {
|
||||
const discovery = new WorkspaceAnalyzer({
|
||||
root: scanRoot,
|
||||
faces: ['host'],
|
||||
checkDiagnostics: false,
|
||||
}).discoverPackages()
|
||||
const packages = discovery.filter(candidate => candidate.faces.includes('host'))
|
||||
.map(candidate => candidate.package)
|
||||
const workspace = new WorkspaceAnalyzer({
|
||||
root: scanRoot,
|
||||
faces: ['host'],
|
||||
packages,
|
||||
checkDiagnostics: false,
|
||||
}).analyzeInBatches()
|
||||
const face = workspace.faces.find(candidate => candidate.face === 'host')
|
||||
if (face === undefined) throw new Error('gen-cordis-catalog: Typert produced no host face')
|
||||
const sourceDeclarations = new WorkspaceAnalyzer({
|
||||
root: scanRoot,
|
||||
faces: ['host'],
|
||||
checkDiagnostics: false,
|
||||
}).indexSourceDeclarations()
|
||||
const projector = new CordisCatalogProjector(face, sourceDeclarations, policy)
|
||||
return { projector, model: projector.project() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all modeled events for relationship-document consumers.
|
||||
* @param scanRoot - workspace root containing `tsconfig.host.json`.
|
||||
* @param policy - caller-owned Cordis catalog policy.
|
||||
* @returns all validated event entries.
|
||||
*/
|
||||
export function collectEvents(scanRoot: string, policy: CordisCatalogPolicy): EventEntry[] {
|
||||
return [...projectCordisCatalog(scanRoot, policy).model.events]
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all modeled services for relationship-document consumers.
|
||||
* @param scanRoot - workspace root containing `tsconfig.host.json`.
|
||||
* @param policy - caller-owned Cordis catalog policy.
|
||||
* @returns all validated service entries.
|
||||
*/
|
||||
export function collectServices(scanRoot: string, policy: CordisCatalogPolicy): ServiceEntry[] {
|
||||
return [...projectCordisCatalog(scanRoot, policy).model.services]
|
||||
}
|
||||
|
||||
interface ParsedJsDoc {
|
||||
readonly doc: string
|
||||
readonly params: ReadonlyMap<string, string>
|
||||
readonly returns: string | null
|
||||
}
|
||||
|
||||
function parseJsDoc(raw: string): ParsedJsDoc {
|
||||
const lines = raw
|
||||
.replace(/^\/\*\*/, '')
|
||||
.replace(/\*\/$/, '')
|
||||
.split('\n')
|
||||
.map(line => line.replace(/^\s*\*?\s?/, '').replace(/\s+$/, ''))
|
||||
const blocks: string[] = []
|
||||
let paragraph: string[] = []
|
||||
let list: string[] = []
|
||||
let item: string[] = []
|
||||
let inTags = false
|
||||
const join = (parts: readonly string[]): string => parts.join(' ').replace(/\s+/g, ' ').trim()
|
||||
const flushItem = (): void => {
|
||||
if (item.length > 0) list.push(join(item))
|
||||
item = []
|
||||
}
|
||||
const flushList = (): void => {
|
||||
flushItem()
|
||||
if (list.length > 0) blocks.push(list.join('\n'))
|
||||
list = []
|
||||
}
|
||||
const flushParagraph = (): void => {
|
||||
flushList()
|
||||
if (paragraph.length > 0) blocks.push(join(paragraph))
|
||||
paragraph = []
|
||||
}
|
||||
for (const line of lines) {
|
||||
const tagLine = line.trimStart()
|
||||
if (tagLine.startsWith('@')) {
|
||||
flushParagraph()
|
||||
inTags = true
|
||||
continue
|
||||
}
|
||||
if (inTags) continue
|
||||
if (line.trim() === '') {
|
||||
flushParagraph()
|
||||
continue
|
||||
}
|
||||
if (/^-\s+/.test(line)) {
|
||||
flushItem()
|
||||
if (paragraph.length > 0) {
|
||||
blocks.push(join(paragraph))
|
||||
paragraph = []
|
||||
}
|
||||
item.push(line)
|
||||
continue
|
||||
}
|
||||
if (item.length > 0) item.push(line)
|
||||
else paragraph.push(line)
|
||||
}
|
||||
flushParagraph()
|
||||
|
||||
const params = new Map<string, string>()
|
||||
let returns: string | null = null
|
||||
let sink: ((text: string) => void) | undefined
|
||||
for (const line of lines) {
|
||||
const param = /^@param\s+(\[?[\w$]+\]?)\s*(?:[-—–]\s*)?(.*)$/.exec(line)
|
||||
if (param !== null) {
|
||||
const name = (param[1] ?? '').replace(/^\[|\]$/g, '')
|
||||
let value = param[2] ?? ''
|
||||
params.set(name, value)
|
||||
sink = (text) => {
|
||||
value = value === '' ? text : `${value} ${text}`
|
||||
params.set(name, value)
|
||||
}
|
||||
continue
|
||||
}
|
||||
const returnsTag = /^@returns?(?:\s+[-—–]?\s*(.*))?$/.exec(line)
|
||||
if (returnsTag !== null) {
|
||||
let value = returnsTag[1] ?? ''
|
||||
returns = value
|
||||
sink = (text) => {
|
||||
value = value === '' ? text : `${value} ${text}`
|
||||
returns = value
|
||||
}
|
||||
continue
|
||||
}
|
||||
if (line.startsWith('@') || line.trim() === '') sink = undefined
|
||||
else sink?.(line.trim())
|
||||
}
|
||||
return {
|
||||
doc: blocks.join('\n\n').replace(/\{@link\s+([^}]+)\}/g, '$1').trim(),
|
||||
params,
|
||||
returns,
|
||||
}
|
||||
}
|
||||
|
||||
function checkParams(
|
||||
where: string,
|
||||
surface: string,
|
||||
parameters: readonly ParameterModel[],
|
||||
tags: ReadonlyMap<string, string>,
|
||||
isExempt: (parameter: ParameterModel) => boolean,
|
||||
violations: string[],
|
||||
): void {
|
||||
for (const parameter of parameters) {
|
||||
if (parameter.binding !== 'identifier') {
|
||||
violations.push(`${where}: parameter '${parameter.name}' is a binding pattern; the ${surface} surface needs simple identifier parameters so @param can name them.`)
|
||||
continue
|
||||
}
|
||||
if (isExempt(parameter)) continue
|
||||
const description = tags.get(parameter.name)
|
||||
if (description === undefined) violations.push(`${where} is missing @param ${parameter.name}.`)
|
||||
else if (description.trim() === '') violations.push(`${where}: @param ${parameter.name} has an empty description.`)
|
||||
}
|
||||
for (const tag of tags.keys()) {
|
||||
if (!parameters.some(parameter => parameter.binding === 'identifier' && parameter.name === tag)) {
|
||||
violations.push(`${where}: @param ${tag} does not match any parameter (stale tag?).`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkReturns(
|
||||
where: string,
|
||||
signature: SignatureModel,
|
||||
returns: string | null,
|
||||
renderer: TypeGraphRenderer,
|
||||
violations: string[],
|
||||
): void {
|
||||
const type = renderer.renderType(signature.returns)
|
||||
if (type === 'void' || type === 'Promise<void>') return
|
||||
if (returns === null) violations.push(`${where} is missing @returns (return type: ${type}).`)
|
||||
else if (returns.trim() === '') violations.push(`${where}: @returns has an empty description.`)
|
||||
}
|
||||
|
||||
function reportViolations(gate: string, violations: readonly string[]): void {
|
||||
if (violations.length === 0) return
|
||||
throw new Error(
|
||||
`${gate}: ${String(violations.length)} JSDoc completeness violation(s) (see AGENTS.md):\n`
|
||||
+ violations.map(violation => ` ${violation}`).join('\n'),
|
||||
)
|
||||
}
|
||||
|
||||
function pointer(location: SourceLocation): string {
|
||||
return `${location.file}:${String(location.line)}`
|
||||
}
|
||||
|
||||
function isMode(mode: string | undefined): mode is Mode {
|
||||
return mode === 'emit' || mode === 'waterfall' || mode === 'parallel' || mode === 'serial'
|
||||
}
|
||||
|
||||
function signatureTypeNames(renderer: TypeGraphRenderer, signature: SignatureModel): string[] {
|
||||
const names = new Set<string>()
|
||||
const visited = new Set<TypeNodeId>()
|
||||
const visitSignature = (current: SignatureModel): void => {
|
||||
for (const parameter of current.typeParameters) {
|
||||
if (parameter.constraint !== undefined) visit(parameter.constraint)
|
||||
if (parameter.default !== undefined) visit(parameter.default)
|
||||
}
|
||||
for (const parameter of current.parameters) visit(parameter.type)
|
||||
visit(current.returns)
|
||||
}
|
||||
const visitMember = (member: MemberModel): void => {
|
||||
if (member.kind === 'property') visit(member.type)
|
||||
else visitSignature(member.signature)
|
||||
}
|
||||
const visit = (id: TypeNodeId): void => {
|
||||
if (visited.has(id)) return
|
||||
visited.add(id)
|
||||
const node = renderer.node(id)
|
||||
if (node.kind === 'reference' && node.target.kind !== 'type-parameter') names.add(node.name)
|
||||
if (node.kind === 'type-query') names.add(node.expression)
|
||||
for (const child of childTypeNodeIds(node)) visit(child)
|
||||
if (node.kind === 'object') for (const member of node.members) visitMember(member)
|
||||
if (node.kind === 'function' || node.kind === 'constructor') visitSignature(node.signature)
|
||||
}
|
||||
visitSignature(signature)
|
||||
return [...names].sort()
|
||||
}
|
||||
|
||||
/** Declarations longer than this render as a truncated stub. */
|
||||
const MAX_DECL_CHARS = 1500
|
||||
|
||||
/** Render one value as a single-quoted TypeScript literal. */
|
||||
function quote(value: string): string {
|
||||
return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'").replaceAll('\n', '\\n')}'`
|
||||
}
|
||||
|
||||
/** Resolve and sort the word-bounded transitive type closure referenced by seed text. */
|
||||
function referencedTypes(
|
||||
seeds: readonly string[],
|
||||
declarations: ReadonlyMap<string, string>,
|
||||
): { name: string; declaration: string }[] {
|
||||
const included = new Map<string, string>()
|
||||
let frontier = [...seeds]
|
||||
while (frontier.length > 0) {
|
||||
const next: string[] = []
|
||||
for (const [name, declaration] of declarations) {
|
||||
if (included.has(name)) continue
|
||||
const pattern = new RegExp(`\\b${name}\\b`)
|
||||
if (frontier.some(text => pattern.test(text))) {
|
||||
included.set(name, declaration)
|
||||
next.push(declaration)
|
||||
}
|
||||
}
|
||||
frontier = next
|
||||
}
|
||||
return [...included]
|
||||
.map(([name, declaration]) => ({ name, declaration }))
|
||||
.sort((left, right) => left.name.localeCompare(right.name))
|
||||
}
|
||||
|
||||
function firstSentence(doc: string): string {
|
||||
const line = doc.split('\n', 1)[0] ?? ''
|
||||
const match = /^(.*?[.!?])(?:\s|$)/.exec(line)
|
||||
return (match?.[1] ?? line).trim()
|
||||
}
|
||||
|
||||
/** Render the byte-compatible model-facing API catalog. */
|
||||
function renderRuntimeApi(
|
||||
services: readonly ServiceEntry[],
|
||||
events: readonly EventEntry[],
|
||||
types: readonly { name: string; declaration: string }[],
|
||||
inheritedServices: readonly InheritedEntry[],
|
||||
): string {
|
||||
const lines: string[] = [
|
||||
'/**',
|
||||
' * Generated by scripts/gen-cordis-api.ts — do not edit by hand; run',
|
||||
' * `pnpm run gen-cordis-api` to regenerate (freshness-gated by',
|
||||
' * `pnpm run verify-cordis-api` in doc-sync).',
|
||||
' *',
|
||||
' * The machine-readable cordis API catalog `cordis_inspect` serves to the',
|
||||
' * model: harness services (summary + public method signatures/JSDoc),',
|
||||
' * harness events (mode + signature/JSDoc), and the inherited `ctx` surface. Produced by',
|
||||
' * the same AST walk as docs/cordis-catalog, so this data and the rendered',
|
||||
' * docs cannot diverge.',
|
||||
' *',
|
||||
' * @module @deepseek-ai/dsh-tool-cordis/api-catalog',
|
||||
' */',
|
||||
'',
|
||||
'/** One public service method and its source-owned contract. */',
|
||||
'export interface ServiceApiMethod {',
|
||||
' /** Public method signature with its body stripped. */',
|
||||
' signature: string',
|
||||
' /** Original method JSDoc, with only container indentation removed. */',
|
||||
' jsDoc: string',
|
||||
'}',
|
||||
'',
|
||||
'/** One harness `ctx.<key>` service: its one-line summary and public methods. */',
|
||||
'export interface ServiceApiEntry {',
|
||||
' /** The `ctx.<key>` name, e.g. `tools`. */',
|
||||
' key: string',
|
||||
' /** First sentence of the service class JSDoc. */',
|
||||
' summary: string',
|
||||
' /** Public methods, bodies stripped, in source order. */',
|
||||
' methods: readonly ServiceApiMethod[]',
|
||||
'}',
|
||||
'',
|
||||
'/** One harness event: its dispatch mode, exact signature, and one-line summary. */',
|
||||
'export interface EventApiEntry {',
|
||||
' /** The scoped event name, e.g. `agent/status`. */',
|
||||
' name: string',
|
||||
' /** The dispatch mode from the declaration\'s `@mode` tag. */',
|
||||
' mode: string',
|
||||
' /** The exact listener signature, whitespace-normalized. */',
|
||||
' signature: string',
|
||||
' /** Original event JSDoc, with only container indentation removed. */',
|
||||
' jsDoc: string',
|
||||
' /** First sentence of the event JSDoc. */',
|
||||
' summary: string',
|
||||
'}',
|
||||
'',
|
||||
'/** One inherited (cordis core + loader/hmr/timer) `ctx` member group with its summary. */',
|
||||
'export interface InheritedApiEntry {',
|
||||
' /** The `ctx` member name(s), e.g. `ctx.on / ctx.once`. */',
|
||||
' name: string',
|
||||
' /** One-line summary of what the member does. */',
|
||||
' summary: string',
|
||||
'}',
|
||||
'',
|
||||
'/** One named type shape the service signatures reference. */',
|
||||
'export interface TypeApiEntry {',
|
||||
' /** The exported type/interface name, e.g. `BashRunResult`. */',
|
||||
' name: string',
|
||||
' /** The full declaration text, comments stripped. */',
|
||||
' declaration: string',
|
||||
'}',
|
||||
'',
|
||||
'/** Every harness `ctx.<key>` service, sorted by key. */',
|
||||
'export const SERVICE_API: readonly ServiceApiEntry[] = [',
|
||||
]
|
||||
for (const service of services) {
|
||||
lines.push(' {')
|
||||
lines.push(` key: ${quote(service.key)},`)
|
||||
lines.push(` summary: ${quote(firstSentence(service.doc))},`)
|
||||
if (service.methods.length === 0) {
|
||||
lines.push(' methods: [],')
|
||||
} else {
|
||||
lines.push(' methods: [')
|
||||
for (const method of service.methods) {
|
||||
lines.push(' {')
|
||||
lines.push(` signature: ${quote(method.signature)},`)
|
||||
lines.push(` jsDoc: ${quote(method.jsDoc)},`)
|
||||
lines.push(' },')
|
||||
}
|
||||
lines.push(' ],')
|
||||
}
|
||||
lines.push(' },')
|
||||
}
|
||||
lines.push(
|
||||
']',
|
||||
'',
|
||||
'/** Every harness event, sorted by name. */',
|
||||
'export const EVENT_API: readonly EventApiEntry[] = [',
|
||||
)
|
||||
for (const event of [...events].sort((left, right) => left.name.localeCompare(right.name))) {
|
||||
lines.push(' {')
|
||||
lines.push(` name: ${quote(event.name)},`)
|
||||
lines.push(` mode: ${quote(event.mode)},`)
|
||||
lines.push(` signature: ${quote(event.signature)},`)
|
||||
lines.push(` jsDoc: ${quote(event.jsDoc)},`)
|
||||
lines.push(` summary: ${quote(firstSentence(event.doc))},`)
|
||||
lines.push(' },')
|
||||
}
|
||||
lines.push(
|
||||
']',
|
||||
'',
|
||||
'/** Shapes of every exported type the SERVICE_API signatures reference (transitively), sorted by name. */',
|
||||
'export const TYPE_API: readonly TypeApiEntry[] = [',
|
||||
)
|
||||
for (const type of types) {
|
||||
lines.push(' {')
|
||||
lines.push(` name: ${quote(type.name)},`)
|
||||
lines.push(` declaration: ${quote(type.declaration)},`)
|
||||
lines.push(' },')
|
||||
}
|
||||
lines.push(
|
||||
']',
|
||||
'',
|
||||
'/** The inherited `ctx` surface (cordis core + loader/hmr/timer), in curated order. */',
|
||||
'export const INHERITED_CTX_API: readonly InheritedApiEntry[] = [',
|
||||
)
|
||||
for (const inherited of inheritedServices) {
|
||||
lines.push(` { name: ${quote(inherited.name)}, summary: ${quote(inherited.summary)} },`)
|
||||
}
|
||||
lines.push(']', '')
|
||||
return lines.join('\n')
|
||||
}
|
||||
/** Render the cross-link "Types:" line for a signature, or '' if none apply. */
|
||||
function typeLinks(signature: string, linkedTypePages: Readonly<Record<string, string>>): string {
|
||||
const seen = new Set<string>()
|
||||
for (const name of Object.keys(linkedTypePages)) {
|
||||
if (new RegExp(`\\b${name}\\b`).test(signature)) seen.add(name)
|
||||
}
|
||||
if (seen.size === 0) return ''
|
||||
const links = [...seen].sort().map(n => `[${n}](../core-data-structures/${linkedTypePages[n]})`)
|
||||
return `Types: ${links.join(' · ')}`
|
||||
}
|
||||
|
||||
/** Render one harness event entry. */
|
||||
function renderEvent(e: EventEntry, linkedTypePages: Readonly<Record<string, string>>): string[] {
|
||||
const out = [`### \`${e.name}\` — ${e.mode}`, '']
|
||||
if (e.doc) out.push(e.doc, '')
|
||||
out.push('```' + FENCE, e.jsDoc, e.signature, '```', '')
|
||||
const links = typeLinks(e.signature, linkedTypePages)
|
||||
if (links) out.push(links, '')
|
||||
out.push(`Source: [\`${e.source}\`](../../${e.source.split(':')[0]})`, '')
|
||||
return out
|
||||
}
|
||||
|
||||
/** Render one harness service entry. */
|
||||
function renderService(s: ServiceEntry, linkedTypePages: Readonly<Record<string, string>>): string[] {
|
||||
const kind = s.abstract ? ' (abstract seam)' : ''
|
||||
const out = [`## \`ctx.${s.key}\` — \`${s.type}\`${kind}`, '']
|
||||
if (s.doc) out.push(s.doc, '')
|
||||
if (s.methods.length) {
|
||||
const declarations = s.methods.flatMap((method, index) => [
|
||||
...(index > 0 ? [''] : []),
|
||||
method.jsDoc,
|
||||
method.signature,
|
||||
])
|
||||
out.push('```' + FENCE, ...declarations, '```', '')
|
||||
const links = typeLinks(s.methods.map(method => method.signature).join('\n'), linkedTypePages)
|
||||
if (links) out.push(links, '')
|
||||
}
|
||||
out.push(`Source: [\`${s.source}\`](../../${s.source.split(':')[0]})`, '')
|
||||
return out
|
||||
}
|
||||
|
||||
/** The shared generated-file banner comment. */
|
||||
const BANNER = [
|
||||
'<!-- Generated by scripts/gen-cordis-catalog.ts — do not edit by hand.',
|
||||
' Run `pnpm run gen-cordis-catalog` to regenerate. -->',
|
||||
'',
|
||||
]
|
||||
|
||||
/** The shared GENERATED + freshness-gate + fence notice paragraph. */
|
||||
const GATE_NOTICE = 'This file is GENERATED from source (`scripts/gen-cordis-catalog.ts`) and verified fresh by `pnpm run verify-cordis-catalog` (part of `doc-sync`) — do not edit it by hand. Signature blocks use a `ts cordis-catalog` fence and include the original source JSDoc immediately before each event or service method. doc-typecheck skips these bare declaration fragments; type names in a signature link to the page that documents them.'
|
||||
|
||||
/**
|
||||
* Render the events catalog deterministically.
|
||||
* @param events - validated event entries to render.
|
||||
* @param policy - type links and inherited events supplied by the caller.
|
||||
* @returns the complete generated Markdown document.
|
||||
*/
|
||||
export function renderEvents(events: EventEntry[], policy: CordisCatalogPolicy): string {
|
||||
const lines: string[] = [
|
||||
...BANNER,
|
||||
'# Cordis Events Catalog',
|
||||
'',
|
||||
'Every cordis event a plugin can listen to: exact signature, dispatch mode, and original declaration JSDoc. This is one axis of the **wiring** reference a plugin author works against — the callable `ctx.<key>` surface is the sibling [services catalog](services.md), and [core-data-structures/](../core-data-structures/core.md) catalogs the *data structures* these signatures move around.',
|
||||
'',
|
||||
GATE_NOTICE,
|
||||
'',
|
||||
'The **harness tier** below (the `@deepseek-ai/dsh-*` packages) is the vocabulary this repo owns, grouped by scope. The **inherited tier** at the end is the cordis-core + loader/hmr/timer event surface a plugin also sees — pinned vendor source, summarized tersely. The event-dispatch methods themselves are generated in the [Cordis core Events API](core/events.md).',
|
||||
'',
|
||||
'Dispatch modes: **emit** (fire-and-forget), **waterfall** (each listener gets `next()` and may transform or veto — see [waterfall semantics](../cordis-primer.md#cordis-waterfall-semantics)), **parallel** (awaited fan-out; all listeners run), **serial** (awaited in registration order until one returns a bail value — anything other than `null`, `false`, or `undefined`).',
|
||||
'',
|
||||
]
|
||||
const scopes = [...new Set(events.map(e => e.scope))].sort()
|
||||
for (const scope of scopes) {
|
||||
lines.push(`## \`${scope}/*\``, '')
|
||||
for (const e of events.filter(x => x.scope === scope).sort((a, b) => a.name.localeCompare(b.name))) {
|
||||
lines.push(...renderEvent(e, policy.linkedTypePages))
|
||||
}
|
||||
}
|
||||
lines.push(
|
||||
'## Inherited events (cordis core + loader/hmr/timer)',
|
||||
'',
|
||||
'The framework events every plugin also sees, beyond the harness vocabulary above. This is pinned vendor source ([vendoring policy](../../vendor/README.md)); it is summarized here so the page is a complete picture of the event bus, without elevating framework internals to the harness tier\'s prominence.',
|
||||
'',
|
||||
)
|
||||
for (const e of policy.inheritedEvents) {
|
||||
lines.push(`- \`${e.name}\` — ${e.summary} ([\`${e.source}\`](../../${e.source.split(':')[0]}))`)
|
||||
}
|
||||
lines.push('')
|
||||
return lines.join('\n')
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the services catalog deterministically.
|
||||
* @param services - validated service entries to render.
|
||||
* @param policy - type links and inherited services supplied by the caller.
|
||||
* @returns the complete generated Markdown document.
|
||||
*/
|
||||
export function renderServices(services: ServiceEntry[], policy: CordisCatalogPolicy): string {
|
||||
const lines: string[] = [
|
||||
...BANNER,
|
||||
'# Cordis Services Catalog',
|
||||
'',
|
||||
'Every `ctx.<key>` service a plugin can call: the exact public interface with original method JSDoc, plus the class JSDoc. This is one axis of the **wiring** reference a plugin author works against — the events a plugin listens to are the sibling [events catalog](events.md), and [core-data-structures/](../core-data-structures/core.md) catalogs the *data structures* these signatures move around. An abstract seam (e.g. `ctx.bash`) is implemented by a separate package; the interface is what consumers code against.',
|
||||
'',
|
||||
GATE_NOTICE,
|
||||
'',
|
||||
'The **harness tier** below (the `@deepseek-ai/dsh-*` packages) is the vocabulary this repo owns. The **inherited tier** at the end is the cordis-core + loader/hmr/timer `ctx` surface a plugin also sees — pinned vendor source, summarized tersely. Detailed Context, Fiber, Registry, and Service APIs are generated in the [Cordis core API](core/context.md).',
|
||||
'',
|
||||
]
|
||||
for (const s of services) lines.push(...renderService(s, policy.linkedTypePages))
|
||||
lines.push(
|
||||
'## Inherited `ctx` members (cordis core + loader/hmr/timer)',
|
||||
'',
|
||||
'The framework `ctx` surface every plugin also sees, beyond the harness services above. This is pinned vendor source ([vendoring policy](../../vendor/README.md)); it is summarized here so the page is a complete picture of what `ctx` offers, without elevating framework internals to the harness tier\'s prominence.',
|
||||
'',
|
||||
)
|
||||
for (const s of policy.inheritedServices) {
|
||||
lines.push(`- \`${s.name}\` — ${s.summary} ([\`${s.source}\`](../../${s.source.split(':')[0]}))`)
|
||||
}
|
||||
lines.push('')
|
||||
return lines.join('\n')
|
||||
}
|
||||
@@ -0,0 +1,451 @@
|
||||
/**
|
||||
* Model-driven Typert artifact emitter. It consumes only FaceModel and
|
||||
* TypeGraph data; TypeScript compiler nodes are not part of this boundary.
|
||||
* @module @deepseek-ai/dsh-typert-generator/emitter
|
||||
*/
|
||||
|
||||
import type {
|
||||
DocumentationModel,
|
||||
FaceModel,
|
||||
MemberModel,
|
||||
PackageModel,
|
||||
SchemaModel,
|
||||
SymbolId,
|
||||
TypeDeclarationModel,
|
||||
TypeNodeId,
|
||||
TypeNodeModel,
|
||||
} from './model.ts'
|
||||
import { TypeGraphRenderer } from './renderer.ts'
|
||||
|
||||
/** Failure to project a modeled construct into an emitted artifact. */
|
||||
export class TypertEmitError extends Error {
|
||||
override name = 'TypertEmitError'
|
||||
}
|
||||
|
||||
/** JavaScript and declaration artifacts for one package on one face. */
|
||||
export interface ModelEmitResult {
|
||||
readonly package: string
|
||||
readonly face: FaceModel['face']
|
||||
readonly exports: readonly string[]
|
||||
readonly js: string
|
||||
readonly dts: string
|
||||
}
|
||||
|
||||
interface RuntimeMemberModel {
|
||||
readonly kind: MemberModel['kind']
|
||||
readonly name: string
|
||||
readonly signature: string
|
||||
readonly summary?: string
|
||||
readonly jsDoc?: string
|
||||
}
|
||||
|
||||
interface RuntimeTypeModel {
|
||||
readonly name: string
|
||||
readonly declaration: string
|
||||
}
|
||||
|
||||
interface RuntimeServiceModel extends DocumentationModel {
|
||||
readonly key: string
|
||||
readonly exportName: string
|
||||
readonly members: readonly RuntimeMemberModel[]
|
||||
readonly types: readonly RuntimeTypeModel[]
|
||||
}
|
||||
|
||||
interface RuntimeEventModel extends DocumentationModel {
|
||||
readonly name: string
|
||||
readonly mode?: string
|
||||
readonly signature: string
|
||||
}
|
||||
|
||||
interface RuntimeObjectModel extends DocumentationModel {
|
||||
readonly name: string
|
||||
readonly exportName: string
|
||||
readonly members: readonly RuntimeMemberModel[]
|
||||
readonly types: readonly RuntimeTypeModel[]
|
||||
}
|
||||
|
||||
interface RuntimePackageModel {
|
||||
readonly services: readonly RuntimeServiceModel[]
|
||||
readonly events: readonly RuntimeEventModel[]
|
||||
readonly objects: readonly RuntimeObjectModel[]
|
||||
}
|
||||
|
||||
/** Emit generated runtime and type artifacts from one independently analyzed face. */
|
||||
export class FaceModelEmitter {
|
||||
private readonly renderer: TypeGraphRenderer
|
||||
|
||||
/**
|
||||
* Create an emitter for one face graph.
|
||||
* @param face - independently analyzed face.
|
||||
*/
|
||||
constructor(private readonly face: FaceModel) {
|
||||
this.renderer = new TypeGraphRenderer(face.graph)
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit one modeled package.
|
||||
* @param packageName - exact package name in the face model.
|
||||
* @returns executable JavaScript and its precise declaration file.
|
||||
*/
|
||||
emit(packageName: string): ModelEmitResult {
|
||||
const packageModel = this.face.packages.find(candidate => candidate.name === packageName)
|
||||
if (packageModel === undefined) {
|
||||
throw new TypertEmitError(`typert emitter(${this.face.face}): package ${packageName} is not modeled on this face`)
|
||||
}
|
||||
const schemas = new SchemaEmitter(this.renderer, packageModel.schemas)
|
||||
const schemaArtifact = schemas.emit()
|
||||
const runtimeModel = this.runtimeModel(packageModel)
|
||||
const js = this.renderJs(packageModel, schemaArtifact, runtimeModel)
|
||||
const dts = this.renderDts(packageModel, schemaArtifact)
|
||||
return {
|
||||
package: packageName,
|
||||
face: this.face.face,
|
||||
exports: packageModel.schemas.map(schema => schema.export.name),
|
||||
js,
|
||||
dts,
|
||||
}
|
||||
}
|
||||
|
||||
private runtimeModel(packageModel: PackageModel): RuntimePackageModel {
|
||||
const services = packageModel.services.map((service): RuntimeServiceModel => {
|
||||
const members = service.members.map(id => this.runtimeMember(this.renderer.member(id)))
|
||||
return {
|
||||
...documentationLiteral(service),
|
||||
key: service.key,
|
||||
exportName: service.export.name,
|
||||
members,
|
||||
types: this.runtimeTypes(this.renderer.declarationClosureForMembers(service.members), service.symbol),
|
||||
}
|
||||
})
|
||||
const events = packageModel.events.map((event): RuntimeEventModel => {
|
||||
const node = this.renderer.node(event.signature)
|
||||
if (node.kind !== 'function') {
|
||||
throw new TypertEmitError(`typert emitter(${this.face.face}): event ${event.name} is not a function type`)
|
||||
}
|
||||
return {
|
||||
...documentationLiteral(event),
|
||||
name: event.name,
|
||||
...(event.mode === undefined ? {} : { mode: event.mode }),
|
||||
signature: `${quote(event.name)}${this.renderer.renderSignature(node.signature)}`,
|
||||
}
|
||||
})
|
||||
const objects = packageModel.objects.map((object): RuntimeObjectModel => {
|
||||
const declaration = this.renderer.declaration(object.symbol)
|
||||
return {
|
||||
...documentationLiteral(object),
|
||||
name: declaration.name,
|
||||
exportName: object.export.name,
|
||||
members: declaration.members.map(member => this.runtimeMember(member)),
|
||||
types: this.runtimeTypes(this.renderer.declarationClosureForMembers(declaration.members.map(member => member.id)), declaration.id),
|
||||
}
|
||||
})
|
||||
return { services, events, objects }
|
||||
}
|
||||
|
||||
private runtimeMember(member: MemberModel): RuntimeMemberModel {
|
||||
return {
|
||||
kind: member.kind,
|
||||
name: member.name,
|
||||
signature: this.renderer.renderMember(member, true),
|
||||
...(member.summary === undefined ? {} : { summary: member.summary }),
|
||||
...(member.jsDoc === undefined ? {} : { jsDoc: member.jsDoc }),
|
||||
}
|
||||
}
|
||||
|
||||
private runtimeTypes(declarations: readonly TypeDeclarationModel[], root: SymbolId): RuntimeTypeModel[] {
|
||||
return declarations
|
||||
.filter(declaration => declaration.id !== root)
|
||||
.map(declaration => ({
|
||||
name: declaration.name,
|
||||
declaration: this.renderer.renderDeclaration(declaration.id),
|
||||
}))
|
||||
.sort((left, right) => left.name.localeCompare(right.name))
|
||||
}
|
||||
|
||||
private renderJs(
|
||||
packageModel: PackageModel,
|
||||
schemas: SchemaArtifact,
|
||||
runtimeModel: RuntimePackageModel,
|
||||
): string {
|
||||
const lines = [
|
||||
'/* Generated by @deepseek-ai/dsh-typert-generator from FaceModel — do not edit. */',
|
||||
]
|
||||
if (schemas.definitions.length > 0) lines.push('import { z } from \'zod\'', '')
|
||||
lines.push(...schemas.definitions)
|
||||
if (schemas.definitions.length > 0) lines.push('')
|
||||
for (const schema of schemas.exports) lines.push(`export const ${schema.exportName} = ${schema.internalName}`)
|
||||
if (schemas.exports.length > 0) lines.push('')
|
||||
const model = JSON.stringify(runtimeModel, null, 2)
|
||||
lines.push('export const TYPERT = {')
|
||||
lines.push(` package: ${quote(packageModel.name)},`)
|
||||
lines.push(` face: ${quote(this.face.face)},`)
|
||||
lines.push(' schemas: [')
|
||||
for (const schema of schemas.exports) {
|
||||
lines.push(` { name: ${quote(schema.exportName)}, schema: ${schema.exportName} },`)
|
||||
}
|
||||
lines.push(' ],')
|
||||
lines.push(` model: ${indent(model, 2).trimStart()},`)
|
||||
lines.push('}')
|
||||
return `${lines.join('\n')}\n`
|
||||
}
|
||||
|
||||
private renderDts(packageModel: PackageModel, schemas: SchemaArtifact): string {
|
||||
const imports = new Map<string, string[]>()
|
||||
for (const schema of schemas.exports) {
|
||||
const specifier = packageExportSpecifier(packageModel.name, schema.model.export.subpath)
|
||||
const names = imports.get(specifier) ?? []
|
||||
names.push(`${schema.model.export.name} as ${schema.exportName}$source`)
|
||||
imports.set(specifier, names)
|
||||
}
|
||||
const lines = [
|
||||
'/* Generated by @deepseek-ai/dsh-typert-generator from FaceModel — do not edit. */',
|
||||
]
|
||||
if (schemas.exports.length > 0) lines.splice(1, 0, 'import type { z } from \'zod\'')
|
||||
for (const [specifier, names] of [...imports].sort(([left], [right]) => left.localeCompare(right))) {
|
||||
lines.push(`import type { ${names.sort().join(', ')} } from ${quote(specifier)}`)
|
||||
}
|
||||
lines.push('')
|
||||
for (const schema of schemas.exports) {
|
||||
lines.push(`export declare const ${schema.exportName}: z.ZodType<${schema.exportName}$source>`)
|
||||
}
|
||||
if (schemas.exports.length > 0) lines.push('')
|
||||
// The Loader validates and narrows this generated module boundary before
|
||||
// registration. Keeping the public declaration unknown prevents every
|
||||
// contributing business package from depending on the runtime registry.
|
||||
lines.push('export declare const TYPERT: unknown')
|
||||
return `${lines.join('\n')}\n`
|
||||
}
|
||||
}
|
||||
|
||||
interface SchemaExport {
|
||||
readonly model: SchemaModel
|
||||
readonly exportName: string
|
||||
readonly internalName: string
|
||||
}
|
||||
|
||||
interface SchemaArtifact {
|
||||
readonly definitions: readonly string[]
|
||||
readonly exports: readonly SchemaExport[]
|
||||
}
|
||||
|
||||
class SchemaEmitter {
|
||||
private readonly names = new Map<SymbolId, string>()
|
||||
private readonly declarations: TypeDeclarationModel[]
|
||||
|
||||
constructor(
|
||||
private readonly renderer: TypeGraphRenderer,
|
||||
private readonly schemas: readonly SchemaModel[],
|
||||
) {
|
||||
const declarations = new Map<SymbolId, TypeDeclarationModel>()
|
||||
for (const schema of schemas) {
|
||||
for (const declaration of renderer.declarationClosureForTypes([schema.type])) {
|
||||
declarations.set(declaration.id, declaration)
|
||||
}
|
||||
}
|
||||
this.declarations = renderer.graph.declarations.filter(declaration => declarations.has(declaration.id))
|
||||
const identifiers = new Set<string>()
|
||||
for (const declaration of this.declarations) {
|
||||
const base = `${safeIdentifier(declaration.name)}$schema`
|
||||
let name = base
|
||||
let suffix = 2
|
||||
while (identifiers.has(name)) name = `${base}${String(suffix++)}`
|
||||
identifiers.add(name)
|
||||
this.names.set(declaration.id, name)
|
||||
}
|
||||
}
|
||||
|
||||
emit(): SchemaArtifact {
|
||||
const definitions = this.declarations.map((declaration) => {
|
||||
if (declaration.typeParameters.length > 0) {
|
||||
this.fail(declaration.name, 'generic declarations require a schema-factory projection')
|
||||
}
|
||||
return `const ${this.schemaName(declaration.id)} = ${this.declarationSchema(declaration)}`
|
||||
})
|
||||
const exports = this.schemas.map((model): SchemaExport => ({
|
||||
model,
|
||||
exportName: safeIdentifier(model.export.name),
|
||||
internalName: this.schemaName(model.symbol),
|
||||
}))
|
||||
return { definitions, exports }
|
||||
}
|
||||
|
||||
private declarationSchema(declaration: TypeDeclarationModel): string {
|
||||
if (declaration.kind === 'enum') {
|
||||
this.fail(declaration.name, 'enum declarations have no Zod projection')
|
||||
}
|
||||
if (declaration.kind === 'alias') {
|
||||
if (declaration.type === undefined) this.fail(declaration.name, 'alias has no modeled type')
|
||||
return this.describe(this.typeSchema(declaration.type), declaration)
|
||||
}
|
||||
const own = this.objectSchema(declaration.members, declaration.name)
|
||||
let result = own
|
||||
for (const heritage of declaration.extends) {
|
||||
result = `z.intersection(${this.typeSchema(heritage)}, ${result})`
|
||||
}
|
||||
return this.describe(result, declaration)
|
||||
}
|
||||
|
||||
private typeSchema(id: TypeNodeId): string {
|
||||
const node = this.renderer.node(id)
|
||||
switch (node.kind) {
|
||||
case 'keyword': return this.keywordSchema(node.name)
|
||||
case 'literal': return `z.literal(${node.text})`
|
||||
case 'parenthesized': return this.typeSchema(node.type)
|
||||
case 'reference': return this.referenceSchema(node)
|
||||
case 'union': {
|
||||
if (node.types.length === 0) return 'z.never()'
|
||||
if (node.types.length === 1) return this.typeSchema(node.types[0] as TypeNodeId)
|
||||
return `z.union([${node.types.map(type => this.typeSchema(type)).join(', ')}])`
|
||||
}
|
||||
case 'intersection': {
|
||||
const [head, ...tail] = node.types
|
||||
if (head === undefined) return 'z.unknown()'
|
||||
return tail.reduce((left, right) => `z.intersection(${left}, ${this.typeSchema(right)})`, this.typeSchema(head))
|
||||
}
|
||||
case 'array': return `z.array(${this.typeSchema(node.element)})`
|
||||
case 'tuple': {
|
||||
const fixed = node.elements.filter(element => !element.rest)
|
||||
const rest = node.elements.find(element => element.rest)
|
||||
let schema = `z.tuple([${fixed.map(element => this.optional(this.typeSchema(element.type), element.optional)).join(', ')}])`
|
||||
if (rest !== undefined) schema += `.rest(${this.tupleRestSchema(rest.type)})`
|
||||
return schema
|
||||
}
|
||||
case 'object': return this.objectSchema(node.members, id)
|
||||
case 'operator':
|
||||
case 'indexed-access':
|
||||
case 'conditional':
|
||||
case 'infer':
|
||||
case 'mapped':
|
||||
case 'template-literal':
|
||||
case 'type-query':
|
||||
case 'import-type':
|
||||
case 'predicate':
|
||||
case 'function':
|
||||
case 'constructor':
|
||||
case 'this': return this.unsupported(node)
|
||||
}
|
||||
}
|
||||
|
||||
private referenceSchema(node: Extract<TypeNodeModel, { kind: 'reference' }>): string {
|
||||
if (node.target.kind === 'declaration') {
|
||||
return `z.lazy(() => ${this.schemaName(node.target.symbol)})`
|
||||
}
|
||||
if (node.target.kind === 'standard') {
|
||||
switch (node.target.name) {
|
||||
case 'Array':
|
||||
case 'ReadonlyArray': {
|
||||
const element = node.arguments[0]
|
||||
if (element === undefined) this.fail(node.name, 'array reference has no element type')
|
||||
return this.readonly(`z.array(${this.typeSchema(element)})`, node.target.name === 'ReadonlyArray')
|
||||
}
|
||||
case 'Record': {
|
||||
const key = node.arguments[0]
|
||||
const value = node.arguments[1]
|
||||
if (key === undefined || value === undefined) this.fail(node.name, 'Record requires key and value types')
|
||||
return `z.record(${this.typeSchema(key)}, ${this.typeSchema(value)})`
|
||||
}
|
||||
case 'Date': return 'z.date()'
|
||||
default: this.fail(node.name, `standard type ${node.target.name} has no Zod projection`)
|
||||
}
|
||||
}
|
||||
this.fail(node.name, `${node.target.kind} reference has no Zod projection`)
|
||||
}
|
||||
|
||||
private tupleRestSchema(id: TypeNodeId): string {
|
||||
const node = this.renderer.node(id)
|
||||
if (node.kind === 'array') return this.typeSchema(node.element)
|
||||
if (node.kind === 'reference'
|
||||
&& node.target.kind === 'standard'
|
||||
&& (node.target.name === 'Array' || node.target.name === 'ReadonlyArray')) {
|
||||
const element = node.arguments[0]
|
||||
if (element === undefined) this.fail(node.name, 'tuple rest array has no element type')
|
||||
return this.typeSchema(element)
|
||||
}
|
||||
this.fail(id, 'tuple rest element must retain an array type')
|
||||
}
|
||||
|
||||
private objectSchema(members: readonly MemberModel[], subject: string): string {
|
||||
const properties: string[] = []
|
||||
for (const member of members) {
|
||||
if (member.static || member.visibility !== 'public') continue
|
||||
if (member.kind !== 'property') this.fail(subject, `${member.kind} member ${member.name} is not data-schema projectable`)
|
||||
const property = this.describe(
|
||||
this.optional(this.readonly(this.typeSchema(member.type), member.readonly), member.optional),
|
||||
member,
|
||||
)
|
||||
properties.push(`${quote(member.name)}: ${property}`)
|
||||
}
|
||||
return `z.object({${properties.length === 0 ? '' : `\n${properties.map(property => ` ${property},`).join('\n')}\n`}})`
|
||||
}
|
||||
|
||||
private keywordSchema(name: string): string {
|
||||
switch (name) {
|
||||
case 'any': return 'z.any()'
|
||||
case 'unknown': return 'z.unknown()'
|
||||
case 'never': return 'z.never()'
|
||||
case 'string': return 'z.string()'
|
||||
case 'number': return 'z.number()'
|
||||
case 'bigint': return 'z.bigint()'
|
||||
case 'boolean': return 'z.boolean()'
|
||||
case 'symbol': return 'z.symbol()'
|
||||
case 'undefined': return 'z.undefined()'
|
||||
case 'void': return 'z.void()'
|
||||
case 'object': return "z.custom((value) => (typeof value === 'object' && value !== null) || typeof value === 'function')"
|
||||
default: this.fail(name, `keyword ${name} has no Zod projection`)
|
||||
}
|
||||
}
|
||||
|
||||
private schemaName(symbol: SymbolId): string {
|
||||
const name = this.names.get(symbol)
|
||||
if (name === undefined) this.fail(symbol, 'referenced declaration is outside the selected schema closure')
|
||||
return name
|
||||
}
|
||||
|
||||
private describe(schema: string, documentation: DocumentationModel): string {
|
||||
return documentation.description === undefined ? schema : `${schema}.describe(${quote(documentation.description)})`
|
||||
}
|
||||
|
||||
private optional(schema: string, optional: boolean): string {
|
||||
return optional ? `${schema}.optional()` : schema
|
||||
}
|
||||
|
||||
private readonly(schema: string, readonly: boolean): string {
|
||||
return readonly ? `${schema}.readonly()` : schema
|
||||
}
|
||||
|
||||
private unsupported(node: TypeNodeModel): never {
|
||||
this.fail(node.id, `type node ${node.kind} has no Zod projection`)
|
||||
}
|
||||
|
||||
private fail(subject: string, message: string): never {
|
||||
throw new TypertEmitError(`typert Zod emitter: ${subject}: ${message}`)
|
||||
}
|
||||
}
|
||||
|
||||
function documentationLiteral(documentation: DocumentationModel): DocumentationModel {
|
||||
return {
|
||||
...(documentation.description === undefined ? {} : { description: documentation.description }),
|
||||
...(documentation.summary === undefined ? {} : { summary: documentation.summary }),
|
||||
tags: documentation.tags,
|
||||
...(documentation.jsDoc === undefined ? {} : { jsDoc: documentation.jsDoc }),
|
||||
}
|
||||
}
|
||||
|
||||
function packageExportSpecifier(packageName: string, subpath: string): string {
|
||||
return subpath === '.' ? packageName : `${packageName}${subpath.slice(1)}`
|
||||
}
|
||||
|
||||
function safeIdentifier(name: string): string {
|
||||
const normalized = name.replace(/[^$\w]/gu, '_')
|
||||
if (/^[$A-Z_a-z]/u.test(normalized)) return normalized
|
||||
return `_${normalized}`
|
||||
}
|
||||
|
||||
function quote(value: string): string {
|
||||
return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'").replaceAll('\n', '\\n').replaceAll('\r', '\\r')}'`
|
||||
}
|
||||
|
||||
function indent(value: string, spaces: number): string {
|
||||
const prefix = ' '.repeat(spaces)
|
||||
return value.split('\n').map(line => `${prefix}${line}`).join('\n')
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Public surface of the Typert analyzer, compiler-independent model, and
|
||||
* model-driven artifact emitters. Build wiring lives in the `./tsdown`
|
||||
* subpath.
|
||||
* @module @deepseek-ai/dsh-typert-generator
|
||||
*/
|
||||
|
||||
export { WorkspaceAnalyzer, TypertAnalysisError } from './analyzer.ts'
|
||||
export type { AnalysisMode, DiscoveredTypertPackage, WorkspaceAnalyzerOptions } from './analyzer.ts'
|
||||
export { FaceModelEmitter, TypertEmitError } from './emitter.ts'
|
||||
export type { ModelEmitResult } from './emitter.ts'
|
||||
export * from './cordis-catalog.ts'
|
||||
export { TypeGraphRenderer, TypeGraphRenderError } from './renderer.ts'
|
||||
export { WorkspaceTypertGenerator } from './workspace.ts'
|
||||
export type { WorkspaceEmitResult } from './workspace.ts'
|
||||
export type * from './model.ts'
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Package-owned invariant companion for `@deepseek-ai/dsh-typert-generator`.
|
||||
* @module @deepseek-ai/dsh-typert-generator/invariant
|
||||
*/
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-typert-generator'
|
||||
|
||||
/** Cordis companion plugin name. */
|
||||
export const name = 'typert-generator-invariant'
|
||||
/** Service required before the companion can reserve package ownership. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/**
|
||||
* No runtime invariant: this source-project analyzer and build-time emitter
|
||||
* runs outside any cordis runtime; model snapshots, executable artifacts, and
|
||||
* consuming-package typechecks enforce its output contract.
|
||||
*/
|
||||
const install: InvariantInstaller = () => {}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
* @param ctx - Cordis context carrying the invariant service.
|
||||
* @returns the installed registration's disposer after setup succeeds.
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
@@ -0,0 +1,375 @@
|
||||
/**
|
||||
* Compiler-independent Typert analysis model. TypeScript nodes and checker
|
||||
* objects are extraction inputs only; emitters consume this graph.
|
||||
* @module @deepseek-ai/dsh-typert-generator/model
|
||||
*/
|
||||
|
||||
/** One independently compiled side of the workspace. */
|
||||
export type TypertFace = 'host' | 'client'
|
||||
|
||||
/** Stable graph-local identifier of a type expression. */
|
||||
export type TypeNodeId = string
|
||||
|
||||
/** Stable workspace identifier of a declared symbol. */
|
||||
export type SymbolId = string
|
||||
|
||||
/** Keyword types accepted in ordinary TypeScript source declarations. */
|
||||
export type KeywordTypeName =
|
||||
| 'any'
|
||||
| 'bigint'
|
||||
| 'boolean'
|
||||
| 'never'
|
||||
| 'number'
|
||||
| 'object'
|
||||
| 'string'
|
||||
| 'symbol'
|
||||
| 'undefined'
|
||||
| 'unknown'
|
||||
| 'void'
|
||||
|
||||
/** Prefix operators accepted on TypeScript type nodes. */
|
||||
export type TypeOperatorName = 'keyof' | 'readonly' | 'unique'
|
||||
|
||||
/** Source position retained for diagnostics and source-edit mode. */
|
||||
export interface SourceLocation {
|
||||
readonly file: string
|
||||
readonly line: number
|
||||
readonly column: number
|
||||
}
|
||||
|
||||
/** One public package export and the declaration it resolves to. */
|
||||
export interface ExportModel {
|
||||
readonly subpath: string
|
||||
readonly name: string
|
||||
readonly symbol: SymbolId
|
||||
readonly aliases: readonly string[]
|
||||
}
|
||||
|
||||
/** One structured JSDoc tag, retaining its original text for unknown tags. */
|
||||
export interface JsDocTagModel {
|
||||
readonly name: string
|
||||
readonly argument?: string
|
||||
readonly comment?: string
|
||||
readonly text: string
|
||||
}
|
||||
|
||||
/** JSDoc retained as a standard part of every documented model element. */
|
||||
export interface DocumentationModel {
|
||||
readonly description?: string
|
||||
readonly summary?: string
|
||||
readonly tags: readonly JsDocTagModel[]
|
||||
readonly jsDoc?: string
|
||||
}
|
||||
|
||||
/** One Cordis Context contribution. */
|
||||
export interface ServiceModel extends DocumentationModel {
|
||||
readonly key: string
|
||||
readonly symbol: SymbolId
|
||||
readonly export: ExportModel
|
||||
readonly members: readonly string[]
|
||||
readonly location: SourceLocation
|
||||
}
|
||||
|
||||
/** One Cordis Events contribution. */
|
||||
export interface EventModel extends DocumentationModel {
|
||||
readonly name: string
|
||||
readonly signature: TypeNodeId
|
||||
/** Body-free declaration text retained for byte-stable source projections. */
|
||||
readonly text: string
|
||||
readonly mode?: string
|
||||
readonly location: SourceLocation
|
||||
}
|
||||
|
||||
/** One explicitly exported reference-passed object. */
|
||||
export interface ObjectModel extends DocumentationModel {
|
||||
readonly export: ExportModel
|
||||
readonly symbol: SymbolId
|
||||
readonly passing: 'reference'
|
||||
}
|
||||
|
||||
/** One explicitly selected value type for schema generation. */
|
||||
export interface SchemaModel extends DocumentationModel {
|
||||
readonly export: ExportModel
|
||||
readonly symbol: SymbolId
|
||||
readonly type: TypeNodeId
|
||||
}
|
||||
|
||||
/** Business semantics discovered in one package on one face. */
|
||||
export interface PackageModel {
|
||||
readonly name: string
|
||||
readonly root: string
|
||||
readonly exports: readonly ExportModel[]
|
||||
readonly services: readonly ServiceModel[]
|
||||
readonly events: readonly EventModel[]
|
||||
readonly objects: readonly ObjectModel[]
|
||||
readonly schemas: readonly SchemaModel[]
|
||||
}
|
||||
|
||||
/** One explicit import/re-export edge between independently compiled faces. */
|
||||
export interface CrossFaceLink {
|
||||
readonly fromFace: TypertFace
|
||||
readonly fromPackage: string
|
||||
readonly toFace: TypertFace
|
||||
readonly toPackage: string
|
||||
readonly subpath: string
|
||||
readonly name: string
|
||||
}
|
||||
|
||||
/** Complete analysis result for an independently compiled face. */
|
||||
export interface FaceModel {
|
||||
readonly face: TypertFace
|
||||
readonly packages: readonly PackageModel[]
|
||||
readonly graph: TypeGraph
|
||||
}
|
||||
|
||||
/** Complete host/client analysis result. */
|
||||
export interface WorkspaceModel {
|
||||
readonly faces: readonly FaceModel[]
|
||||
readonly crossFaceLinks: readonly CrossFaceLink[]
|
||||
}
|
||||
|
||||
/** One top-level authored type declaration indexed without making it a graph root. */
|
||||
export interface SourceDeclarationModel {
|
||||
readonly face: TypertFace
|
||||
readonly package: string
|
||||
readonly name: string
|
||||
readonly kind: 'interface' | 'class' | 'alias' | 'enum'
|
||||
readonly location: SourceLocation
|
||||
readonly text: string
|
||||
}
|
||||
|
||||
/** Visibility recorded on class members. */
|
||||
export type MemberVisibility = 'public' | 'protected' | 'private'
|
||||
|
||||
/** One generic type parameter, preserving its pre-evaluation constraint/default. */
|
||||
export interface TypeParameterModel {
|
||||
readonly id: string
|
||||
readonly name: string
|
||||
readonly const: boolean
|
||||
readonly constraint?: TypeNodeId
|
||||
readonly default?: TypeNodeId
|
||||
readonly variance?: 'in' | 'out' | 'in-out'
|
||||
}
|
||||
|
||||
/** One function-like parameter. */
|
||||
export interface ParameterModel {
|
||||
readonly name: string
|
||||
readonly binding: 'identifier' | 'object' | 'array'
|
||||
readonly type: TypeNodeId
|
||||
readonly optional: boolean
|
||||
readonly rest: boolean
|
||||
readonly receiver: boolean
|
||||
readonly initializer?: string
|
||||
}
|
||||
|
||||
/** A function/call/construct signature. */
|
||||
export interface SignatureModel {
|
||||
readonly typeParameters: readonly TypeParameterModel[]
|
||||
readonly parameters: readonly ParameterModel[]
|
||||
readonly returns: TypeNodeId
|
||||
}
|
||||
|
||||
/** Shared flags of a class/interface/type-literal member. */
|
||||
export interface MemberBase extends DocumentationModel {
|
||||
readonly id: string
|
||||
readonly name: string
|
||||
readonly optional: boolean
|
||||
readonly readonly: boolean
|
||||
readonly async: boolean
|
||||
readonly abstract: boolean
|
||||
readonly static: boolean
|
||||
readonly visibility: MemberVisibility
|
||||
readonly location: SourceLocation
|
||||
/** Body-free declaration text retained for byte-stable source projections. */
|
||||
readonly text: string
|
||||
}
|
||||
|
||||
/** A property member. */
|
||||
export interface PropertyMemberModel extends MemberBase {
|
||||
readonly kind: 'property'
|
||||
readonly type: TypeNodeId
|
||||
}
|
||||
|
||||
/** A method member. */
|
||||
export interface MethodMemberModel extends MemberBase {
|
||||
readonly kind: 'method'
|
||||
readonly signature: SignatureModel
|
||||
}
|
||||
|
||||
/** A getter or setter member. */
|
||||
export interface AccessorMemberModel extends MemberBase {
|
||||
readonly kind: 'getter' | 'setter'
|
||||
readonly signature: SignatureModel
|
||||
}
|
||||
|
||||
/** A call/construct/index signature in an interface or type literal. */
|
||||
export interface SignatureMemberModel extends MemberBase {
|
||||
readonly kind: 'call' | 'construct' | 'index'
|
||||
readonly signature: SignatureModel
|
||||
}
|
||||
|
||||
/** One declaration or object-literal member. */
|
||||
export type MemberModel =
|
||||
| PropertyMemberModel
|
||||
| MethodMemberModel
|
||||
| AccessorMemberModel
|
||||
| SignatureMemberModel
|
||||
|
||||
/** One enum member, retaining its developer-authored initializer. */
|
||||
export interface EnumMemberModel extends DocumentationModel {
|
||||
readonly name: string
|
||||
readonly initializer?: string
|
||||
readonly location: SourceLocation
|
||||
}
|
||||
|
||||
/** One authored part of a merged interface declaration. */
|
||||
export interface TypeDeclarationPartModel extends DocumentationModel {
|
||||
readonly package: string
|
||||
readonly location: SourceLocation
|
||||
readonly typeParameters: readonly TypeParameterModel[]
|
||||
readonly extends: readonly TypeNodeId[]
|
||||
readonly members: readonly string[]
|
||||
}
|
||||
|
||||
/** A declared interface, class, or alias. */
|
||||
export interface TypeDeclarationModel extends DocumentationModel {
|
||||
readonly id: SymbolId
|
||||
readonly package: string
|
||||
readonly name: string
|
||||
readonly kind: 'interface' | 'class' | 'alias' | 'enum'
|
||||
readonly abstract: boolean
|
||||
readonly exported: boolean
|
||||
readonly location: SourceLocation
|
||||
/** Canonical body-free declaration text retained alongside the type tree. */
|
||||
readonly text: string
|
||||
readonly typeParameters: readonly TypeParameterModel[]
|
||||
readonly extends: readonly TypeNodeId[]
|
||||
readonly implements: readonly TypeNodeId[]
|
||||
readonly members: readonly MemberModel[]
|
||||
readonly parts?: readonly TypeDeclarationPartModel[]
|
||||
readonly type?: TypeNodeId
|
||||
readonly enumMembers?: readonly EnumMemberModel[]
|
||||
}
|
||||
|
||||
/** Target of a named type reference. */
|
||||
export type TypeTargetModel =
|
||||
| { readonly kind: 'declaration'; readonly symbol: SymbolId }
|
||||
| { readonly kind: 'type-parameter'; readonly parameter: string }
|
||||
| {
|
||||
readonly kind: 'cross-face'
|
||||
readonly face: TypertFace
|
||||
readonly package: string
|
||||
readonly subpath: string
|
||||
readonly name: string
|
||||
}
|
||||
| {
|
||||
readonly kind: 'external'
|
||||
readonly module: string
|
||||
readonly subpath: string
|
||||
readonly name: string
|
||||
}
|
||||
| { readonly kind: 'standard'; readonly name: string }
|
||||
|
||||
/** One tuple element, retaining labels and optional/rest modifiers. */
|
||||
export interface TupleElementModel {
|
||||
readonly name?: string
|
||||
readonly type: TypeNodeId
|
||||
readonly optional: boolean
|
||||
readonly rest: boolean
|
||||
}
|
||||
|
||||
/** One template-literal interpolation. */
|
||||
export interface TemplateSpanModel {
|
||||
readonly type: TypeNodeId
|
||||
readonly text: string
|
||||
}
|
||||
|
||||
/** Compiler-independent TypeScript type expression. */
|
||||
export type TypeNodeModel =
|
||||
| { readonly id: TypeNodeId; readonly kind: 'keyword'; readonly name: KeywordTypeName }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'literal'; readonly value: string | number | bigint | boolean | null; readonly text: string }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'parenthesized'; readonly type: TypeNodeId }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'reference'; readonly name: string; readonly target: TypeTargetModel; readonly arguments: readonly TypeNodeId[] }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'union' | 'intersection'; readonly types: readonly TypeNodeId[] }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'array'; readonly element: TypeNodeId }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'tuple'; readonly elements: readonly TupleElementModel[] }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'object'; readonly members: readonly MemberModel[] }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'function'; readonly signature: SignatureModel }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'constructor'; readonly abstract: boolean; readonly signature: SignatureModel }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'indexed-access'; readonly object: TypeNodeId; readonly index: TypeNodeId }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'operator'; readonly operator: TypeOperatorName; readonly type: TypeNodeId }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'conditional'; readonly check: TypeNodeId; readonly extends: TypeNodeId; readonly whenTrue: TypeNodeId; readonly whenFalse: TypeNodeId }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'infer'; readonly parameter: TypeParameterModel }
|
||||
| {
|
||||
readonly id: TypeNodeId
|
||||
readonly kind: 'mapped'
|
||||
readonly parameter: TypeParameterModel
|
||||
readonly nameType?: TypeNodeId
|
||||
readonly value?: TypeNodeId
|
||||
readonly readonly: 'add' | 'remove' | 'preserve'
|
||||
readonly optional: 'add' | 'remove' | 'preserve'
|
||||
}
|
||||
| { readonly id: TypeNodeId; readonly kind: 'template-literal'; readonly head: string; readonly spans: readonly TemplateSpanModel[] }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'type-query'; readonly expression: string; readonly arguments: readonly TypeNodeId[] }
|
||||
| {
|
||||
readonly id: TypeNodeId
|
||||
readonly kind: 'import-type'
|
||||
readonly module: string
|
||||
readonly qualifier?: string
|
||||
readonly arguments: readonly TypeNodeId[]
|
||||
readonly typeof: boolean
|
||||
readonly attributes?: string
|
||||
readonly target?: TypeTargetModel
|
||||
}
|
||||
| { readonly id: TypeNodeId; readonly kind: 'predicate'; readonly asserts: boolean; readonly parameter: string; readonly type?: TypeNodeId }
|
||||
| { readonly id: TypeNodeId; readonly kind: 'this' }
|
||||
|
||||
/**
|
||||
* Return the direct type-expression edges owned by one node.
|
||||
* @param node - compiler-independent type node to inspect.
|
||||
* @returns graph-local ids of its direct child type nodes.
|
||||
*/
|
||||
export function childTypeNodeIds(node: TypeNodeModel): TypeNodeId[] {
|
||||
switch (node.kind) {
|
||||
case 'parenthesized':
|
||||
case 'operator': return [node.type]
|
||||
case 'reference': return [...node.arguments]
|
||||
case 'union':
|
||||
case 'intersection': return [...node.types]
|
||||
case 'array': return [node.element]
|
||||
case 'tuple': return node.elements.map(element => element.type)
|
||||
case 'indexed-access': return [node.object, node.index]
|
||||
case 'conditional': return [node.check, node.extends, node.whenTrue, node.whenFalse]
|
||||
case 'mapped': return [
|
||||
...(node.parameter.constraint === undefined ? [] : [node.parameter.constraint]),
|
||||
...(node.parameter.default === undefined ? [] : [node.parameter.default]),
|
||||
...(node.nameType === undefined ? [] : [node.nameType]),
|
||||
...(node.value === undefined ? [] : [node.value]),
|
||||
]
|
||||
case 'template-literal': return node.spans.map(span => span.type)
|
||||
case 'type-query':
|
||||
case 'import-type': return [...node.arguments]
|
||||
case 'predicate': return node.type === undefined ? [] : [node.type]
|
||||
case 'infer': return [
|
||||
...(node.parameter.constraint === undefined ? [] : [node.parameter.constraint]),
|
||||
...(node.parameter.default === undefined ? [] : [node.parameter.default]),
|
||||
]
|
||||
case 'keyword':
|
||||
case 'literal':
|
||||
case 'object':
|
||||
case 'function':
|
||||
case 'constructor':
|
||||
case 'this': return []
|
||||
default: return assertNever(node)
|
||||
}
|
||||
}
|
||||
|
||||
/** Type declarations and expressions owned by one face. */
|
||||
export interface TypeGraph {
|
||||
readonly declarations: readonly TypeDeclarationModel[]
|
||||
readonly nodes: readonly TypeNodeModel[]
|
||||
}
|
||||
|
||||
function assertNever(value: never): never {
|
||||
throw new Error(`unsupported model variant ${JSON.stringify(value)}`)
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
/**
|
||||
* Rendering and traversal over the compiler-independent TypeGraph. Emitters
|
||||
* use this module instead of reaching back into TypeScript AST nodes.
|
||||
* @module @deepseek-ai/dsh-typert-generator/renderer
|
||||
*/
|
||||
|
||||
import { childTypeNodeIds } from './model.ts'
|
||||
import type {
|
||||
MemberModel,
|
||||
ParameterModel,
|
||||
SignatureModel,
|
||||
SymbolId,
|
||||
TypeDeclarationModel,
|
||||
TypeGraph,
|
||||
TypeNodeId,
|
||||
TypeNodeModel,
|
||||
TypeParameterModel,
|
||||
} from './model.ts'
|
||||
|
||||
/** Failure to render or traverse an internally inconsistent TypeGraph. */
|
||||
export class TypeGraphRenderError extends Error {
|
||||
override name = 'TypeGraphRenderError'
|
||||
}
|
||||
|
||||
/** Read and render one TypeGraph without compiler objects. */
|
||||
export class TypeGraphRenderer {
|
||||
private readonly nodes: ReadonlyMap<TypeNodeId, TypeNodeModel>
|
||||
private readonly declarations: ReadonlyMap<SymbolId, TypeDeclarationModel>
|
||||
private readonly members: ReadonlyMap<string, MemberModel>
|
||||
private readonly parameterNames = new Map<string, string>()
|
||||
|
||||
/**
|
||||
* Index one complete graph.
|
||||
* @param graph - compiler-independent graph to render.
|
||||
*/
|
||||
constructor(readonly graph: TypeGraph) {
|
||||
this.nodes = new Map(graph.nodes.map(node => [node.id, node]))
|
||||
this.declarations = new Map(graph.declarations.map(declaration => [declaration.id, declaration]))
|
||||
this.members = new Map(graph.declarations.flatMap(declaration => declaration.members.map(member => [member.id, member] as const)))
|
||||
for (const declaration of graph.declarations) {
|
||||
this.indexParameters(declaration.typeParameters)
|
||||
for (const member of declaration.members) {
|
||||
if ('signature' in member) this.indexParameters(member.signature.typeParameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a node id or fail with the broken edge.
|
||||
* @param id - graph-local type node id.
|
||||
* @returns the referenced node.
|
||||
*/
|
||||
node(id: TypeNodeId): TypeNodeModel {
|
||||
const node = this.nodes.get(id)
|
||||
if (node === undefined) throw new TypeGraphRenderError(`type graph references missing node ${id}`)
|
||||
return node
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a declaration id or fail with the broken edge.
|
||||
* @param id - workspace symbol id.
|
||||
* @returns the referenced declaration.
|
||||
*/
|
||||
declaration(id: SymbolId): TypeDeclarationModel {
|
||||
const declaration = this.declarations.get(id)
|
||||
if (declaration === undefined) throw new TypeGraphRenderError(`type graph references missing declaration ${id}`)
|
||||
return declaration
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a public member id.
|
||||
* @param id - declaration member id.
|
||||
* @returns the referenced member.
|
||||
*/
|
||||
member(id: string): MemberModel {
|
||||
const member = this.members.get(id)
|
||||
if (member === undefined) throw new TypeGraphRenderError(`type graph references missing member ${id}`)
|
||||
return member
|
||||
}
|
||||
|
||||
/**
|
||||
* Render one type expression from the retained source structure.
|
||||
* @param id - type node id.
|
||||
* @returns TypeScript type text.
|
||||
*/
|
||||
renderType(id: TypeNodeId): string {
|
||||
const node = this.node(id)
|
||||
switch (node.kind) {
|
||||
case 'keyword': return node.name
|
||||
case 'literal': return node.text
|
||||
case 'parenthesized': return `(${this.renderType(node.type)})`
|
||||
case 'reference': {
|
||||
const name = node.target.kind === 'type-parameter'
|
||||
? this.parameterNames.get(node.target.parameter) ?? node.name
|
||||
: node.name
|
||||
return node.arguments.length === 0
|
||||
? name
|
||||
: `${name}<${node.arguments.map(argument => this.renderType(argument)).join(', ')}>`
|
||||
}
|
||||
case 'union': return node.types.map(type => this.renderType(type)).join(' | ')
|
||||
case 'intersection': return node.types.map(type => this.renderType(type)).join(' & ')
|
||||
case 'array': {
|
||||
const element = this.renderType(node.element)
|
||||
const wrapped = needsArrayParentheses(this.node(node.element)) ? `(${element})` : element
|
||||
return `${wrapped}[]`
|
||||
}
|
||||
case 'tuple': {
|
||||
const elements = node.elements.map((element) => {
|
||||
const type = this.renderType(element.type)
|
||||
if (element.name !== undefined) {
|
||||
return `${element.rest ? '...' : ''}${element.name}${element.optional ? '?' : ''}: ${type}`
|
||||
}
|
||||
return `${element.rest ? '...' : ''}${type}${element.optional ? '?' : ''}`
|
||||
})
|
||||
return `[${elements.join(', ')}]`
|
||||
}
|
||||
case 'object': return this.renderObject(node.members)
|
||||
case 'function': return `${this.renderSignatureHead(node.signature)} => ${this.renderType(node.signature.returns)}`
|
||||
case 'constructor': return `${node.abstract ? 'abstract ' : ''}new ${this.renderSignatureHead(node.signature)} => ${this.renderType(node.signature.returns)}`
|
||||
case 'indexed-access': return `${this.renderType(node.object)}[${this.renderType(node.index)}]`
|
||||
case 'operator': return `${node.operator} ${this.renderType(node.type)}`
|
||||
case 'conditional': {
|
||||
return `${this.renderType(node.check)} extends ${this.renderType(node.extends)} ? ${this.renderType(node.whenTrue)} : ${this.renderType(node.whenFalse)}`
|
||||
}
|
||||
case 'infer': return `infer ${this.renderTypeParameter(node.parameter, false)}`
|
||||
case 'mapped': {
|
||||
const readonly = node.readonly === 'preserve' ? '' : node.readonly === 'remove' ? '-readonly ' : 'readonly '
|
||||
const optional = node.optional === 'preserve' ? '' : node.optional === 'remove' ? '-?' : '?'
|
||||
if (node.parameter.constraint === undefined) {
|
||||
throw new TypeGraphRenderError(`mapped type parameter ${node.parameter.name} has no constraint`)
|
||||
}
|
||||
const parameter = `${node.parameter.name} in ${this.renderType(node.parameter.constraint)}`
|
||||
const nameType = node.nameType === undefined ? '' : ` as ${this.renderType(node.nameType)}`
|
||||
const value = node.value === undefined ? 'unknown' : this.renderType(node.value)
|
||||
return `{ ${readonly}[${parameter}${nameType}]${optional}: ${value} }`
|
||||
}
|
||||
case 'template-literal': {
|
||||
const spans = node.spans.map(span => `\${${this.renderType(span.type)}}${escapeTemplate(span.text)}`).join('')
|
||||
return `\`${escapeTemplate(node.head)}${spans}\``
|
||||
}
|
||||
case 'type-query': {
|
||||
const argumentsText = node.arguments.length === 0
|
||||
? ''
|
||||
: `<${node.arguments.map(argument => this.renderType(argument)).join(', ')}>`
|
||||
return `typeof ${node.expression}${argumentsText}`
|
||||
}
|
||||
case 'import-type': {
|
||||
const attributes = node.attributes === undefined ? '' : `, ${node.attributes}`
|
||||
const imported = `import(${quote(node.module)}${attributes})${node.qualifier === undefined ? '' : `.${node.qualifier}`}`
|
||||
const argumentsText = node.arguments.length === 0
|
||||
? ''
|
||||
: `<${node.arguments.map(argument => this.renderType(argument)).join(', ')}>`
|
||||
return `${node.typeof ? 'typeof ' : ''}${imported}${argumentsText}`
|
||||
}
|
||||
case 'predicate': {
|
||||
const assertion = node.asserts ? 'asserts ' : ''
|
||||
return node.type === undefined
|
||||
? `${assertion}${node.parameter}`
|
||||
: `${assertion}${node.parameter} is ${this.renderType(node.type)}`
|
||||
}
|
||||
case 'this': return 'this'
|
||||
default: return assertNever(node)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a callable signature without a member name.
|
||||
* @param signature - modeled signature.
|
||||
* @returns parameter list and return type.
|
||||
*/
|
||||
renderSignature(signature: SignatureModel): string {
|
||||
return `${this.renderSignatureHead(signature)}: ${this.renderType(signature.returns)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Render one class/interface member as a body-free declaration.
|
||||
* @param member - modeled member.
|
||||
* @param sourceModifiers - retain source-only modifiers for reflection text.
|
||||
* @returns one-line TypeScript member text.
|
||||
*/
|
||||
renderMember(member: MemberModel, sourceModifiers = false): string {
|
||||
if (sourceModifiers) return member.text
|
||||
const name = renderPropertyName(member.name)
|
||||
const optional = member.optional ? '?' : ''
|
||||
const readonly = member.readonly ? 'readonly ' : ''
|
||||
const abstract = member.abstract ? 'abstract ' : ''
|
||||
switch (member.kind) {
|
||||
case 'property': return `${abstract}${readonly}${name}${optional}: ${this.renderType(member.type)}`
|
||||
case 'method': return `${abstract}${name}${optional}${this.renderSignature(member.signature)}`
|
||||
case 'getter': return `${abstract}get ${name}()${this.renderReturn(member.signature)}`
|
||||
case 'setter': return `${abstract}set ${name}${this.renderSignatureHead(member.signature)}`
|
||||
case 'call': return this.renderSignature(member.signature)
|
||||
case 'construct': return `new ${this.renderSignature(member.signature)}`
|
||||
case 'index': {
|
||||
const parameters = member.signature.parameters.map(parameter => this.renderParameter(parameter)).join(', ')
|
||||
return `${readonly}[${parameters}]: ${this.renderType(member.signature.returns)}`
|
||||
}
|
||||
default: return assertNever(member)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a named declaration without JSDoc.
|
||||
* @param id - declaration symbol id.
|
||||
* @returns exported TypeScript declaration text.
|
||||
*/
|
||||
renderDeclaration(id: SymbolId): string {
|
||||
const declaration = this.declaration(id)
|
||||
const parameters = this.renderTypeParameters(declaration.typeParameters)
|
||||
if (declaration.kind === 'enum') {
|
||||
const members = declaration.enumMembers?.map(member =>
|
||||
` ${renderPropertyName(member.name)}${member.initializer === undefined ? '' : ` = ${member.initializer}`},`) ?? []
|
||||
return [`export enum ${declaration.name} {`, ...members, '}'].join('\n')
|
||||
}
|
||||
if (declaration.kind === 'alias') {
|
||||
if (declaration.type === undefined) throw new TypeGraphRenderError(`alias ${id} has no type node`)
|
||||
return `export type ${declaration.name}${parameters} = ${this.renderType(declaration.type)};`
|
||||
}
|
||||
const extendsTypes = declaration.extends.map(type => this.renderType(type))
|
||||
const implementsTypes = declaration.implements.map(type => this.renderType(type))
|
||||
const heritage = [
|
||||
extendsTypes.length === 0 ? '' : ` extends ${extendsTypes.join(', ')}`,
|
||||
implementsTypes.length === 0 ? '' : ` implements ${implementsTypes.join(', ')}`,
|
||||
].join('')
|
||||
const prefix = declaration.kind === 'class' && declaration.abstract ? 'abstract ' : ''
|
||||
const members = declaration.members.map(member => ` ${this.renderMember(member)};`)
|
||||
return [`export ${prefix}${declaration.kind} ${declaration.name}${parameters}${heritage} {`, ...members, '}'].join('\n')
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the transitive declaration closure referenced by members.
|
||||
* @param memberIds - business-surface member ids.
|
||||
* @returns declarations in graph order, excluding no roots implicitly.
|
||||
*/
|
||||
declarationClosureForMembers(memberIds: readonly string[]): TypeDeclarationModel[] {
|
||||
return this.declarationClosure(memberIds, [])
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the transitive declaration closure referenced by type roots.
|
||||
* @param typeIds - graph type roots.
|
||||
* @returns declarations in graph order.
|
||||
*/
|
||||
declarationClosureForTypes(typeIds: readonly TypeNodeId[]): TypeDeclarationModel[] {
|
||||
return this.declarationClosure([], typeIds)
|
||||
}
|
||||
|
||||
private declarationClosure(
|
||||
memberIds: readonly string[],
|
||||
typeIds: readonly TypeNodeId[],
|
||||
): TypeDeclarationModel[] {
|
||||
const found = new Set<SymbolId>()
|
||||
const visiting = new Set<SymbolId>()
|
||||
const visitNode = (id: TypeNodeId): void => {
|
||||
const node = this.node(id)
|
||||
if (node.kind === 'reference' && node.target.kind === 'declaration') visitDeclaration(node.target.symbol)
|
||||
if (node.kind === 'import-type' && node.target?.kind === 'declaration') visitDeclaration(node.target.symbol)
|
||||
for (const child of childTypeNodeIds(node)) visitNode(child)
|
||||
for (const signature of nodeSignatures(node)) visitSignature(signature)
|
||||
if (node.kind === 'object') for (const member of node.members) visitMember(member)
|
||||
}
|
||||
const visitSignature = (signature: SignatureModel): void => {
|
||||
for (const parameter of signature.typeParameters) {
|
||||
if (parameter.constraint !== undefined) visitNode(parameter.constraint)
|
||||
if (parameter.default !== undefined) visitNode(parameter.default)
|
||||
}
|
||||
for (const parameter of signature.parameters) visitNode(parameter.type)
|
||||
visitNode(signature.returns)
|
||||
}
|
||||
const visitMember = (member: MemberModel): void => {
|
||||
if (member.kind === 'property') visitNode(member.type)
|
||||
else visitSignature(member.signature)
|
||||
}
|
||||
const visitDeclaration = (id: SymbolId): void => {
|
||||
if (found.has(id) || visiting.has(id)) return
|
||||
visiting.add(id)
|
||||
const declaration = this.declaration(id)
|
||||
for (const parameter of declaration.typeParameters) {
|
||||
if (parameter.constraint !== undefined) visitNode(parameter.constraint)
|
||||
if (parameter.default !== undefined) visitNode(parameter.default)
|
||||
}
|
||||
for (const type of [...declaration.extends, ...declaration.implements]) visitNode(type)
|
||||
if (declaration.type !== undefined) visitNode(declaration.type)
|
||||
for (const member of declaration.members) visitMember(member)
|
||||
visiting.delete(id)
|
||||
found.add(id)
|
||||
}
|
||||
for (const id of memberIds) visitMember(this.member(id))
|
||||
for (const id of typeIds) visitNode(id)
|
||||
return this.graph.declarations.filter(declaration => found.has(declaration.id))
|
||||
}
|
||||
|
||||
private renderSignatureHead(signature: SignatureModel): string {
|
||||
return `${this.renderTypeParameters(signature.typeParameters)}(${signature.parameters.map(parameter => this.renderParameter(parameter)).join(', ')})`
|
||||
}
|
||||
|
||||
private renderReturn(signature: SignatureModel): string {
|
||||
return `: ${this.renderType(signature.returns)}`
|
||||
}
|
||||
|
||||
private renderParameter(parameter: ParameterModel): string {
|
||||
const name = parameter.binding === 'identifier' ? renderPropertyName(parameter.name) : parameter.name
|
||||
const optional = parameter.initializer === undefined && parameter.optional && !parameter.rest ? '?' : ''
|
||||
const initializer = parameter.initializer === undefined ? '' : ` = ${parameter.initializer}`
|
||||
return `${parameter.rest ? '...' : ''}${name}${optional}: ${this.renderType(parameter.type)}${initializer}`
|
||||
}
|
||||
|
||||
private renderTypeParameters(parameters: readonly TypeParameterModel[]): string {
|
||||
return parameters.length === 0
|
||||
? ''
|
||||
: `<${parameters.map(parameter => this.renderTypeParameter(parameter, true)).join(', ')}>`
|
||||
}
|
||||
|
||||
private renderTypeParameter(parameter: TypeParameterModel, includeDefault: boolean): string {
|
||||
const variance = parameter.variance === undefined ? '' : `${parameter.variance === 'in-out' ? 'in out' : parameter.variance} `
|
||||
const constModifier = parameter.const ? 'const ' : ''
|
||||
const constraint = parameter.constraint === undefined ? '' : ` extends ${this.renderType(parameter.constraint)}`
|
||||
const fallback = !includeDefault || parameter.default === undefined ? '' : ` = ${this.renderType(parameter.default)}`
|
||||
return `${constModifier}${variance}${parameter.name}${constraint}${fallback}`
|
||||
}
|
||||
|
||||
private renderObject(members: readonly MemberModel[]): string {
|
||||
if (members.length === 0) return '{}'
|
||||
return `{ ${members.map(member => `${this.renderMember(member)};`).join(' ')} }`
|
||||
}
|
||||
|
||||
private indexParameters(parameters: readonly TypeParameterModel[]): void {
|
||||
for (const parameter of parameters) this.parameterNames.set(parameter.id, parameter.name)
|
||||
}
|
||||
}
|
||||
|
||||
function nodeSignatures(node: TypeNodeModel): SignatureModel[] {
|
||||
return node.kind === 'function' || node.kind === 'constructor' ? [node.signature] : []
|
||||
}
|
||||
|
||||
function needsArrayParentheses(node: TypeNodeModel): boolean {
|
||||
return node.kind === 'union' || node.kind === 'intersection' || node.kind === 'function' || node.kind === 'constructor' || node.kind === 'conditional'
|
||||
}
|
||||
|
||||
function renderPropertyName(name: string): string {
|
||||
if (name.startsWith('[') && name.endsWith(']')) return name
|
||||
if (/^(?:[$A-Z_a-z][$\w]*|\d+)$/u.test(name)) return name
|
||||
return quote(name)
|
||||
}
|
||||
|
||||
function quote(value: string): string {
|
||||
return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'").replaceAll('\n', '\\n')}'`
|
||||
}
|
||||
|
||||
function escapeTemplate(value: string): string {
|
||||
return value.replaceAll('\\', '\\\\').replaceAll('`', '\\`').replaceAll('${', '\\${')
|
||||
}
|
||||
|
||||
function assertNever(value: never): never {
|
||||
throw new TypeGraphRenderError(`unsupported model variant ${JSON.stringify(value)}`)
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Optional tsdown (rolldown) plugin face of the typert generator. When added
|
||||
* to a workspace tsdown config, it runs after each opted-in package bundle is
|
||||
* written and re-emits its model-driven face artifact at the package output
|
||||
* root. Packages without a Typert export are skipped.
|
||||
* @module @deepseek-ai/dsh-typert-generator/tsdown
|
||||
*/
|
||||
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { WorkspaceTypertGenerator } from './workspace.ts'
|
||||
import type { WorkspaceEmitResult } from './workspace.ts'
|
||||
|
||||
/** The subset of the rolldown output-plugin contract this plugin uses (structural; avoids a rolldown type dependency). */
|
||||
interface TypertPlugin {
|
||||
name: string
|
||||
writeBundle: (options: { dir?: string }) => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the typert generation plugin for the root tsdown config.
|
||||
* @returns a rolldown-compatible plugin that emits `lib/typert.<face>.js` and `.d.ts` for contributing packages.
|
||||
*/
|
||||
export function typertPlugin(): TypertPlugin {
|
||||
const artifactsByRoot = new Map<string, readonly WorkspaceEmitResult[]>()
|
||||
return {
|
||||
name: 'dsh-typert-generator',
|
||||
writeBundle(options) {
|
||||
// options.dir is the package's absolute outDir (<package>/lib); its
|
||||
// nearest package.json owns the bundle even when a custom config writes
|
||||
// a nested output such as <package>/lib/dev.
|
||||
if (options.dir === undefined) return
|
||||
const root = workspaceRoot(options.dir)
|
||||
const packageDir = packageRoot(options.dir, root)
|
||||
if (packageDir === undefined) return
|
||||
const manifest = JSON.parse(readFileSync(join(packageDir, 'package.json'), 'utf8')) as {
|
||||
name?: string
|
||||
exports?: unknown
|
||||
}
|
||||
if (manifest.name === undefined || !hasTypertExport(manifest.exports)) return
|
||||
let artifacts = artifactsByRoot.get(root)
|
||||
if (artifacts === undefined) {
|
||||
artifacts = new WorkspaceTypertGenerator(root).generate()
|
||||
artifactsByRoot.set(root, artifacts)
|
||||
}
|
||||
const output = join(packageDir, 'lib')
|
||||
mkdirSync(output, { recursive: true })
|
||||
for (const artifact of artifacts.filter(candidate => candidate.package === manifest.name)) {
|
||||
writeFileSync(join(output, `typert.${artifact.face}.js`), artifact.js)
|
||||
writeFileSync(join(output, `typert.${artifact.face}.d.ts`), artifact.dts)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function hasTypertExport(exportsField: unknown): boolean {
|
||||
if (exportsField === null || typeof exportsField !== 'object' || Array.isArray(exportsField)) return false
|
||||
return Object.hasOwn(exportsField, './typert') || Object.hasOwn(exportsField, './client/typert')
|
||||
}
|
||||
|
||||
function packageRoot(start: string, workspace: string): string | undefined {
|
||||
let current = resolve(start)
|
||||
while (current !== workspace) {
|
||||
if (existsSync(join(current, 'package.json'))) return current
|
||||
current = dirname(current)
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function workspaceRoot(start: string): string {
|
||||
let current = resolve(start)
|
||||
while (!existsSync(join(current, 'tsconfig.host.json'))) {
|
||||
const parent = dirname(current)
|
||||
if (parent === current) throw new Error(`typert-generator: cannot find workspace root above ${start}`)
|
||||
current = parent
|
||||
}
|
||||
return current
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Workspace-level discovery and model-driven Typert generation.
|
||||
* @module @deepseek-ai/dsh-typert-generator/workspace
|
||||
*/
|
||||
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import { TypertAnalysisError, WorkspaceAnalyzer } from './analyzer.ts'
|
||||
import type { DiscoveredTypertPackage } from './analyzer.ts'
|
||||
import { FaceModelEmitter } from './emitter.ts'
|
||||
import type { ModelEmitResult } from './emitter.ts'
|
||||
|
||||
/** One emitted artifact paired with its source package root. */
|
||||
export interface WorkspaceEmitResult extends ModelEmitResult {
|
||||
readonly packageRoot: string
|
||||
}
|
||||
|
||||
/** Discover, analyze, and emit package reflection from independent faces. */
|
||||
export class WorkspaceTypertGenerator {
|
||||
/**
|
||||
* Bind generation to one workspace root.
|
||||
* @param root - directory containing face aggregate tsconfigs.
|
||||
*/
|
||||
constructor(private readonly root: string) {}
|
||||
|
||||
/**
|
||||
* Find public package faces that contribute Cordis services/events or
|
||||
* explicitly tagged Typert roots.
|
||||
* @returns discovered packages in stable package-name order.
|
||||
*/
|
||||
discover(): DiscoveredTypertPackage[] {
|
||||
return new WorkspaceAnalyzer({ root: this.root }).discoverPackages()
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate all discovered contributors, or an explicit package subset.
|
||||
* @param packages - optional exact package names for a focused pass.
|
||||
* @returns one artifact per package face.
|
||||
*/
|
||||
generate(packages?: readonly string[]): WorkspaceEmitResult[] {
|
||||
const selected = packages ?? this.discover().map(candidate => candidate.package)
|
||||
const workspace = new WorkspaceAnalyzer({ root: this.root, packages: selected }).analyze()
|
||||
const artifacts: WorkspaceEmitResult[] = []
|
||||
for (const face of workspace.faces) {
|
||||
const emitter = new FaceModelEmitter(face)
|
||||
for (const packageModel of face.packages) {
|
||||
const artifact = {
|
||||
...emitter.emit(packageModel.name),
|
||||
packageRoot: packageModel.root,
|
||||
}
|
||||
this.validateExport(artifact)
|
||||
artifacts.push(artifact)
|
||||
}
|
||||
}
|
||||
return artifacts
|
||||
}
|
||||
|
||||
private validateExport(artifact: WorkspaceEmitResult): void {
|
||||
const manifestPath = resolve(this.root, artifact.packageRoot, 'package.json')
|
||||
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) as {
|
||||
exports?: unknown
|
||||
files?: unknown
|
||||
}
|
||||
const subpath = artifact.face === 'host' ? './typert' : './client/typert'
|
||||
const expected = {
|
||||
types: `./lib/typert.${artifact.face}.d.ts`,
|
||||
default: `./lib/typert.${artifact.face}.js`,
|
||||
}
|
||||
const actual = manifest.exports !== null && typeof manifest.exports === 'object'
|
||||
? (manifest.exports as Record<string, unknown>)[subpath]
|
||||
: undefined
|
||||
if (!sameExport(actual, expected)) {
|
||||
throw new TypertAnalysisError(
|
||||
`typert(${artifact.face}): ${artifact.package} must export ${subpath} as ${JSON.stringify(expected)}`,
|
||||
)
|
||||
}
|
||||
const files = Array.isArray(manifest.files) ? manifest.files : []
|
||||
for (const file of [`lib/typert.${artifact.face}.js`, `lib/typert.${artifact.face}.d.ts`]) {
|
||||
if (!files.includes(file)) {
|
||||
throw new TypertAnalysisError(`typert(${artifact.face}): ${artifact.package} package files must include ${file}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sameExport(actual: unknown, expected: { types: string; default: string }): boolean {
|
||||
if (actual === null || typeof actual !== 'object' || Array.isArray(actual)) return false
|
||||
const value = actual as Record<string, unknown>
|
||||
return value.types === expected.types && value.default === expected.default
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+87
-14
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Contract and negative-path tests for the cordis catalog generator
|
||||
* Model-extraction and negative-path contracts for the Cordis catalog generator
|
||||
* (`scripts/gen-cordis-catalog.ts`).
|
||||
*/
|
||||
|
||||
@@ -7,16 +7,91 @@ import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { collectEvents, collectServices, renderEvents, renderServices } from '../../../../scripts/gen-cordis-catalog.ts'
|
||||
import {
|
||||
collectEvents as collectEventsWithPolicy,
|
||||
collectServices as collectServicesWithPolicy,
|
||||
renderEvents as renderEventsWithPolicy,
|
||||
renderServices as renderServicesWithPolicy,
|
||||
} from '../src/cordis-catalog.ts'
|
||||
import type {
|
||||
CordisCatalogPolicy,
|
||||
EventEntry,
|
||||
ServiceEntry,
|
||||
} from '../src/cordis-catalog.ts'
|
||||
|
||||
const TEST_POLICY: CordisCatalogPolicy = {
|
||||
linkedTypePages: { SessionEvent: 'core.md' },
|
||||
foundationTypeNames: new Set(['AbortSignal', 'Promise', 'Readonly']),
|
||||
typeLinkExemptions: { PresetSpec: 'fixture deployment metadata' },
|
||||
inheritedEvents: [],
|
||||
inheritedServices: [],
|
||||
}
|
||||
|
||||
function collectEvents(root: string): EventEntry[] {
|
||||
return collectEventsWithPolicy(root, TEST_POLICY)
|
||||
}
|
||||
|
||||
function collectServices(root: string): ServiceEntry[] {
|
||||
return collectServicesWithPolicy(root, TEST_POLICY)
|
||||
}
|
||||
|
||||
function renderEvents(events: EventEntry[]): string {
|
||||
return renderEventsWithPolicy(events, TEST_POLICY)
|
||||
}
|
||||
|
||||
function renderServices(services: ServiceEntry[]): string {
|
||||
return renderServicesWithPolicy(services, TEST_POLICY)
|
||||
}
|
||||
|
||||
const TYPE_FIXTURES = [
|
||||
'export interface FixtureEntry {}',
|
||||
'interface SessionEvent {}',
|
||||
'interface PresetSpec {}',
|
||||
'interface MissingOne {}',
|
||||
'type missingTwo = string',
|
||||
'interface MissingServiceType {}',
|
||||
'',
|
||||
].join('\n')
|
||||
|
||||
/** Materialize one independently compilable package and its host aggregate. */
|
||||
function writeProject(root: string, source: string): void {
|
||||
const packageRoot = join(root, 'packages', 'group', 'fix')
|
||||
const sourceRoot = join(packageRoot, 'src')
|
||||
mkdirSync(sourceRoot, { recursive: true })
|
||||
writeFileSync(join(root, 'tsconfig.host.json'), JSON.stringify({
|
||||
files: [],
|
||||
references: [{ path: './packages/group/fix' }],
|
||||
}))
|
||||
writeFileSync(join(packageRoot, 'package.json'), JSON.stringify({
|
||||
name: '@fixture/fix',
|
||||
private: true,
|
||||
type: 'module',
|
||||
exports: {
|
||||
'.': {
|
||||
types: './lib/types/index.d.ts',
|
||||
default: './lib/index.js',
|
||||
},
|
||||
},
|
||||
}))
|
||||
writeFileSync(join(packageRoot, 'tsconfig.json'), JSON.stringify({
|
||||
compilerOptions: {
|
||||
composite: true,
|
||||
module: 'ESNext',
|
||||
moduleResolution: 'Bundler',
|
||||
rootDir: 'src',
|
||||
target: 'ES2022',
|
||||
},
|
||||
include: ['src'],
|
||||
}))
|
||||
writeFileSync(join(sourceRoot, 'index.ts'), `${TYPE_FIXTURES}${source}`)
|
||||
}
|
||||
|
||||
/** Write a fixture package exposing one `interface Events` block and return the
|
||||
* scan root to hand `collectEvents`. */
|
||||
function fixtureRoot(eventsBlock: string): string {
|
||||
const root = mkdtempSync(join(tmpdir(), 'cordis-catalog-'))
|
||||
const dir = join(root, 'packages', 'group', 'fix', 'src')
|
||||
mkdirSync(dir, { recursive: true })
|
||||
writeFileSync(
|
||||
join(dir, 'index.ts'),
|
||||
writeProject(
|
||||
root,
|
||||
`declare module 'cordis' {\n interface Events {\n${eventsBlock}\n }\n}\n`,
|
||||
)
|
||||
return root
|
||||
@@ -27,10 +102,8 @@ function fixtureRoot(eventsBlock: string): string {
|
||||
* `collectServices`. */
|
||||
function serviceFixtureRoot(classSource: string): string {
|
||||
const root = mkdtempSync(join(tmpdir(), 'cordis-catalog-'))
|
||||
const dir = join(root, 'packages', 'group', 'fix', 'src')
|
||||
mkdirSync(dir, { recursive: true })
|
||||
writeFileSync(
|
||||
join(dir, 'index.ts'),
|
||||
writeProject(
|
||||
root,
|
||||
`declare module 'cordis' {\n interface Context {\n fix: FixService\n }\n}\n\n${classSource}\n`,
|
||||
)
|
||||
return root
|
||||
@@ -95,9 +168,9 @@ describe('gen-cordis-catalog collectEvents', () => {
|
||||
'fix/two',
|
||||
'packages/group/fix/src/index.ts',
|
||||
'missingTwo',
|
||||
'Add it to LINK_MAP',
|
||||
'FOUNDATION_TYPE_NAMES',
|
||||
'TYPE_LINK_EXEMPTIONS',
|
||||
'Add it to linkedTypePages',
|
||||
'foundationTypeNames',
|
||||
'typeLinkExemptions',
|
||||
].join('[\\s\\S]*'))
|
||||
expect(() => collectEvents(make(
|
||||
' /**\n * First.\n * @param value - first value.\n * @mode emit\n */\n \'fix/one\'(value: MissingOne): void\n /**\n * Second.\n * @param value - second value.\n * @mode emit\n */\n \'fix/two\'(value: missingTwo): void',
|
||||
@@ -222,7 +295,7 @@ export class FixService {
|
||||
it('hard-errors on an unannotated (inferred) return type', () => {
|
||||
expect(() => collectServices(makeService(
|
||||
'/** Fixture service. */\nexport class FixService {\n /**\n * Do the thing.\n * @param id - which thing.\n */\n run(id: string) { return id }\n}',
|
||||
))).toThrow(/no return type annotation/)
|
||||
))).toThrow(/missing an explicit type annotation/)
|
||||
})
|
||||
|
||||
it('hard-errors on a service class with no JSDoc', () => {
|
||||
@@ -0,0 +1,24 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
projectCordisCatalog,
|
||||
renderEvents,
|
||||
renderServices,
|
||||
} from '../src/cordis-catalog.ts'
|
||||
import { CORDIS_CATALOG_POLICY } from '../../../../scripts/gen-cordis-catalog.ts'
|
||||
|
||||
const workspaceRoot = resolve(import.meta.dirname, '../../../..')
|
||||
|
||||
describe('Typert-backed Cordis catalog', () => {
|
||||
it('reproduces every committed catalog artifact byte for byte', { timeout: 480_000 }, () => {
|
||||
const { projector, model } = projectCordisCatalog(workspaceRoot, CORDIS_CATALOG_POLICY)
|
||||
const expected = (path: string): string => readFileSync(join(workspaceRoot, path), 'utf8')
|
||||
|
||||
expect(renderEvents([...model.events], CORDIS_CATALOG_POLICY)).toBe(expected('docs/cordis-catalog/events.md'))
|
||||
expect(renderServices([...model.services], CORDIS_CATALOG_POLICY)).toBe(expected('docs/cordis-catalog/services.md'))
|
||||
expect(projector.renderRuntimeApi(model)).toBe(
|
||||
expected('packages/cordis/tool-cordis/src/api-catalog.ts'),
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
declare module 'cordis' {
|
||||
export class Service { protected readonly __service?: never }
|
||||
|
||||
export interface Context {}
|
||||
|
||||
export interface Events {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "@fixture/workspace",
|
||||
"private": true,
|
||||
"type": "module"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "@fixture/client",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/types/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./client/typert": {
|
||||
"types": "./lib/typert.client.d.ts",
|
||||
"default": "./lib/typert.client.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"lib/typert.client.js",
|
||||
"lib/typert.client.d.ts"
|
||||
]
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
import { Service } from 'cordis'
|
||||
import type HostDefault from '@fixture/host'
|
||||
import type * as Host from '@fixture/host'
|
||||
import type { AgentPhase } from '@fixture/host'
|
||||
import type { HostAgent, Payload } from '@fixture/host'
|
||||
|
||||
export type { Box as ReexportedBox } from '@fixture/host'
|
||||
export type { ZodType as ReexportedZodType } from 'zod'
|
||||
|
||||
/** Client-owned inheritance preserves an explicit generic cross-face edge. */
|
||||
export interface ClientAgent extends HostAgent<{ ready: true }> {}
|
||||
|
||||
/** Client-owned view with explicit references to host exports. */
|
||||
export interface ClientView {
|
||||
readonly agent: HostAgent<{ ready: true }>
|
||||
readonly inherited: ClientAgent
|
||||
readonly importedAgent: import('@fixture/host').Agent<{ ready: true }>
|
||||
readonly importedAgentWithNamedArgument: import('@fixture/host').Agent<Payload>
|
||||
readonly namespaceAgent: Host.Agent<{ ready: true }>
|
||||
readonly defaultService: HostDefault
|
||||
readonly payload: Payload
|
||||
readonly phase: AgentPhase
|
||||
}
|
||||
|
||||
/** Client-face service. */
|
||||
export class ClientBridge extends Service {
|
||||
/** Return the host-owned object unchanged. */
|
||||
reflect(view: ClientView): HostAgent<{ ready: true }> {
|
||||
return view.agent
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'cordis' {
|
||||
interface Context {
|
||||
clientBridge: ClientBridge
|
||||
}
|
||||
}
|
||||
|
||||
export default ClientBridge
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "lib/types"
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [
|
||||
{ "path": "../host" }
|
||||
]
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "@fixture/host",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/types/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./models": {
|
||||
"types": "./lib/types/models.d.ts",
|
||||
"default": "./lib/models.js"
|
||||
},
|
||||
"./typert": {
|
||||
"types": "./lib/typert.host.d.ts",
|
||||
"default": "./lib/typert.host.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"lib/typert.host.js",
|
||||
"lib/typert.host.d.ts"
|
||||
]
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
import { Service } from 'cordis'
|
||||
import type { ZodType } from 'zod'
|
||||
import type { AgentPhase, Box, Entity, Flags, Payload, Present, SyntaxZoo } from './models.ts'
|
||||
|
||||
export { AgentPhase } from './models.ts'
|
||||
export type { Box, Entity, Flags, Payload, Present } from './models.ts'
|
||||
|
||||
/**
|
||||
* Reference-passed capability object.
|
||||
* @typert object
|
||||
*/
|
||||
export class Agent<State extends object = { ready: boolean }> implements Entity {
|
||||
static {}
|
||||
static readonly kind: string = 'agent'
|
||||
readonly id: string
|
||||
state: State
|
||||
protected readonly generation: number = 1
|
||||
private readonly secret: string = 'fixture'
|
||||
|
||||
constructor(id: string, state: State) {
|
||||
this.id = id
|
||||
this.state = state
|
||||
}
|
||||
|
||||
/** Read the public display label. */
|
||||
get label(): string {
|
||||
return this.id
|
||||
}
|
||||
|
||||
/** Accept a public display label. */
|
||||
set label(value: string) {
|
||||
void value
|
||||
}
|
||||
|
||||
/** Run one typed input. */
|
||||
run<Value>(input: Box<Value>): Promise<Present<Value>> {
|
||||
return Promise.resolve(input.value as Present<Value>)
|
||||
}
|
||||
}
|
||||
|
||||
export { Agent as HostAgent }
|
||||
|
||||
/** Service exported only through a non-default alias. */
|
||||
class AliasedService extends Service {
|
||||
/** Report readiness. */
|
||||
ready(): boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
export { AliasedService as PublicAliasedService }
|
||||
|
||||
/** Service exported only through the package default. */
|
||||
class DefaultOnlyService extends Service {
|
||||
/** Report readiness. */
|
||||
ready(): boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/** Fixture service with generic, mapped, and truly external boundary types. */
|
||||
export class DemoService extends Service {
|
||||
static readonly kind: string = 'demo'
|
||||
protected readonly generation: number = 1
|
||||
private readonly secret: string = 'fixture'
|
||||
|
||||
/** Inspect one agent without flattening its generic state. */
|
||||
inspect(agent: Agent<{ ready: true }>, flags: Flags<Payload>): Present<Payload> {
|
||||
return { name: agent.id, count: Object.keys(flags).length }
|
||||
}
|
||||
|
||||
/** Keep an npm-owned type as External. */
|
||||
acceptsExternal(schema: ZodType<string>): void {
|
||||
void schema
|
||||
}
|
||||
|
||||
/** Accept a developer-authored enum without flattening it. */
|
||||
setPhase(phase: AgentPhase): void {
|
||||
void phase
|
||||
}
|
||||
|
||||
/** Exercise every retained type-graph shape from a public boundary. */
|
||||
inspectSyntax(zoo: SyntaxZoo): void {
|
||||
void zoo
|
||||
}
|
||||
|
||||
/** Preserve async source metadata without changing its type signature. */
|
||||
async inspectAsync(zoo: SyntaxZoo): Promise<void> {
|
||||
void zoo
|
||||
}
|
||||
|
||||
/** Retain an authored binding-pattern parameter. */
|
||||
destructure({ name }: Payload, [suffix]: [string]): string {
|
||||
return name + suffix
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'cordis' {
|
||||
interface Context {
|
||||
demo: DemoService
|
||||
aliased: AliasedService
|
||||
defaultOnly: DefaultOnlyService
|
||||
ignoredInline: {}
|
||||
ignoredPrimitive: string
|
||||
ignoredExternal: ZodType<string>
|
||||
ignoredMethod(): void
|
||||
}
|
||||
|
||||
interface Events {
|
||||
/**
|
||||
* A generic fixture event.
|
||||
* @param agent - emitting agent.
|
||||
* @param payload - event payload.
|
||||
* @mode emit
|
||||
*/
|
||||
'demo/ready'(agent: Agent<{ ready: true }>, payload: Box<Payload>): void
|
||||
|
||||
'demo/unmodeled'(): void
|
||||
|
||||
'demo/property': (payload: Payload) => void
|
||||
|
||||
/** @mode serial */
|
||||
'demo/serial-property': (payload: Payload) => void
|
||||
|
||||
(payload: Payload): void
|
||||
}
|
||||
|
||||
interface IgnoredInterface {}
|
||||
|
||||
type IgnoredDeclaration = string
|
||||
}
|
||||
|
||||
declare module 'cordis' {
|
||||
interface Context {
|
||||
demo: DemoService
|
||||
}
|
||||
|
||||
interface Events {
|
||||
'demo/ready'(agent: Agent<{ ready: true }>, payload: Box<Payload>): void
|
||||
}
|
||||
}
|
||||
|
||||
export default DefaultOnlyService
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
/** Generic source form retained before conditional evaluation. */
|
||||
export interface Box<T> {
|
||||
/** The boxed value. */
|
||||
readonly value: T
|
||||
}
|
||||
|
||||
/** Conditional source form retained instead of its resolved instantiations. */
|
||||
export type Present<T> = T extends null | undefined ? never : T
|
||||
|
||||
/** Mapped source form retained instead of materialized properties. */
|
||||
export type Flags<T> = {
|
||||
readonly [K in keyof T]?: boolean
|
||||
}
|
||||
|
||||
/** Explicit base edge for reference-passed objects. */
|
||||
export interface Entity {
|
||||
readonly id: string
|
||||
}
|
||||
|
||||
/** Developer-authored enum retained as a declaration. */
|
||||
export enum AgentPhase {
|
||||
Unknown,
|
||||
Idle = 'idle',
|
||||
Running = 'running',
|
||||
}
|
||||
|
||||
/** Runtime-validating data root. @typert schema */
|
||||
export interface Payload {
|
||||
name: string
|
||||
count?: number
|
||||
}
|
||||
|
||||
/** Signature members represented without flattening their callable forms. */
|
||||
export interface Callable {
|
||||
(value: string): number
|
||||
new (value: string): Entity
|
||||
readonly [key: string]: unknown
|
||||
}
|
||||
|
||||
/** Input, output, and invariant parameters retain authored variance. */
|
||||
export interface Variance<in Input, out Output, in out State> {
|
||||
consume: (input: Input) => void
|
||||
readonly produce: () => Output
|
||||
state: State
|
||||
}
|
||||
|
||||
/** Infer form nested inside a conditional type. */
|
||||
export type Result<Value> = Value extends (...arguments_: never[]) => infer Output ? Output : never
|
||||
|
||||
/** Constrained infer form retained before conditional evaluation. */
|
||||
export type StringResult<Value> = Value extends readonly [infer Output extends string] ? Output : never
|
||||
|
||||
/** Template-literal source form. */
|
||||
export type Topic<Name extends string> = `demo/${Name}`
|
||||
|
||||
/** Multiple template spans retain each authored suffix. */
|
||||
export type Route<From extends string, To extends string> = `/${From}/to/${To}/end`
|
||||
|
||||
/** Preserve mapped modifiers when none were authored. */
|
||||
export type PlainMap<Value> = {
|
||||
[Key in keyof Value]: Value[Key]
|
||||
}
|
||||
|
||||
/** Retain key remapping and explicit modifier removal. */
|
||||
export type Remapped<Value> = {
|
||||
-readonly [Key in keyof Value as `get${Capitalize<string & Key>}`]-?: Value[Key]
|
||||
}
|
||||
|
||||
/** Retain explicit mapped modifier addition. */
|
||||
export type Added<Value> = {
|
||||
+readonly [Key in keyof Value]+?: Value[Key]
|
||||
}
|
||||
|
||||
/** Value used by a type query and indexed access. */
|
||||
export const phaseOrder = ['idle', 'running'] as const
|
||||
|
||||
/** Generic value used by an instantiated type query. */
|
||||
export declare function genericFactory<Value>(): Value
|
||||
|
||||
/** Predicates and the polymorphic this type remain signatures. */
|
||||
export interface Guards {
|
||||
isEntity(value: unknown): value is Entity
|
||||
isFluent(): this is Guards
|
||||
assertEntity(value: unknown): asserts value is Entity
|
||||
assertPresent(value: unknown): asserts value
|
||||
fluent(): this
|
||||
}
|
||||
|
||||
/** Abstract declarations remain distinct from concrete classes. */
|
||||
export abstract class AbstractEntity implements Entity {
|
||||
abstract readonly id: string
|
||||
}
|
||||
|
||||
/** Recursive declaration edges retain their declaration target. */
|
||||
export interface Recursive extends Box<string> {
|
||||
readonly next?: Recursive
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export interface TagOnly {
|
||||
readonly value: string
|
||||
}
|
||||
|
||||
/** Description without terminal punctuation */
|
||||
export interface Unpunctuated {
|
||||
readonly value: string
|
||||
}
|
||||
|
||||
/** Every supported TypeNode shape is reachable from this declaration. */
|
||||
export interface SyntaxZoo {
|
||||
anyValue: any
|
||||
bigintValue: bigint
|
||||
parenthesized: (Entity | null)
|
||||
literals: 1 | 1n | -2 | -2n | false | `fixed`
|
||||
readonly uniqueToken: unique symbol
|
||||
intersection: Entity & { active: boolean }
|
||||
array: string[]
|
||||
tuple: [head: string, count?: number, ...tail: boolean[]]
|
||||
unnamedTuple: [string?, ...number[]]
|
||||
readonlyTuple: readonly [string, number]
|
||||
object: {
|
||||
readonly value?: string
|
||||
'quoted-name': number
|
||||
1: boolean
|
||||
['computed']: symbol
|
||||
invoke?(input: number): void
|
||||
}
|
||||
callback: <Value extends Entity = Entity>(
|
||||
this: Entity,
|
||||
value: Value,
|
||||
optional?: string,
|
||||
...rest: number[]
|
||||
) => Promise<Value>
|
||||
constCallback: <const Value extends readonly string[]>(value: Value) => Value
|
||||
factory: new <Value extends Entity>(value: Value) => Value
|
||||
abstractFactory: abstract new (id: string) => AbstractEntity
|
||||
indexed: Payload['name']
|
||||
inferred: Result<() => string>
|
||||
constrainedInfer: StringResult<['value']>
|
||||
topic: Topic<'ready'>
|
||||
route: Route<'source', 'target'>
|
||||
query: typeof phaseOrder
|
||||
instantiatedQuery: typeof genericFactory<string>
|
||||
imported: import('zod').ZodType<string>
|
||||
importedWith: import('zod', { with: { 'resolution-mode': 'import' } }).ZodType<string>
|
||||
importedModule: typeof import('zod')
|
||||
process: NodeJS.Process
|
||||
callable: Callable
|
||||
guards: Guards
|
||||
variance: Variance<Entity, Payload, Box<string>>
|
||||
plainMap: PlainMap<Payload>
|
||||
remapped: Remapped<Payload>
|
||||
added: Added<Payload>
|
||||
abstractEntity: AbstractEntity
|
||||
recursive: Recursive
|
||||
tagOnly: TagOnly
|
||||
unpunctuated: Unpunctuated
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "lib/types"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "@fixture/write",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/types/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { Service } from 'cordis'
|
||||
|
||||
/** Service whose public annotations are intentionally absent. */
|
||||
export class WritableService extends Service {
|
||||
value = 1
|
||||
|
||||
echo(input = 'value') {
|
||||
return input
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'cordis' {
|
||||
interface Context {
|
||||
writable: WritableService
|
||||
}
|
||||
}
|
||||
|
||||
export default WritableService
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "lib/types"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2024",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"strict": true,
|
||||
"composite": true,
|
||||
"noEmit": true,
|
||||
"baseUrl": ".",
|
||||
"allowImportingTsExtensions": true,
|
||||
"ignoreDeprecations": "6.0",
|
||||
"types": ["node"],
|
||||
"paths": {
|
||||
"cordis": ["./cordis.d.ts"],
|
||||
"@fixture/host": ["./packages/host/src/index.ts"],
|
||||
"@fixture/host/*": ["./packages/host/src/*"],
|
||||
"@fixture/client": ["./packages/client/src/index.ts"],
|
||||
"@fixture/write": ["./packages/write/src/index.ts"]
|
||||
},
|
||||
"skipLibCheck": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./packages/client" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./packages/host" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"files": ["cordis.d.ts"]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./packages/write" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type {
|
||||
KeywordTypeName,
|
||||
MemberModel,
|
||||
TypeDeclarationModel,
|
||||
TypeGraph,
|
||||
TypeNodeModel,
|
||||
} from '../src/model.ts'
|
||||
import { childTypeNodeIds } from '../src/model.ts'
|
||||
import { TypeGraphRenderError, TypeGraphRenderer } from '../src/renderer.ts'
|
||||
|
||||
const location = { file: 'fixture.ts', line: 1, column: 1 } as const
|
||||
const documentation = { tags: [] } as const
|
||||
|
||||
describe('TypeGraphRenderer defensive and optional shapes', () => {
|
||||
it('enumerates direct child edges for every type node kind', () => {
|
||||
const signature = { typeParameters: [], parameters: [], returns: 'leaf' } as const
|
||||
const cases: readonly (readonly [TypeNodeModel, readonly string[]])[] = [
|
||||
[keyword('keyword', 'string'), []],
|
||||
[{ id: 'literal', kind: 'literal', value: 1, text: '1' }, []],
|
||||
[{ id: 'parenthesized', kind: 'parenthesized', type: 'leaf' }, ['leaf']],
|
||||
[{ id: 'reference', kind: 'reference', name: 'Ref', target: { kind: 'standard', name: 'Ref' }, arguments: ['left', 'right'] }, ['left', 'right']],
|
||||
[{ id: 'union', kind: 'union', types: ['left', 'right'] }, ['left', 'right']],
|
||||
[{ id: 'intersection', kind: 'intersection', types: ['left', 'right'] }, ['left', 'right']],
|
||||
[{ id: 'array', kind: 'array', element: 'leaf' }, ['leaf']],
|
||||
[{ id: 'tuple', kind: 'tuple', elements: [{ type: 'leaf', optional: false, rest: false }] }, ['leaf']],
|
||||
[{ id: 'object', kind: 'object', members: [] }, []],
|
||||
[{ id: 'function', kind: 'function', signature }, []],
|
||||
[{ id: 'constructor', kind: 'constructor', abstract: false, signature }, []],
|
||||
[{ id: 'indexed', kind: 'indexed-access', object: 'left', index: 'right' }, ['left', 'right']],
|
||||
[{ id: 'operator', kind: 'operator', operator: 'keyof', type: 'leaf' }, ['leaf']],
|
||||
[{ id: 'conditional', kind: 'conditional', check: 'check', extends: 'extends', whenTrue: 'yes', whenFalse: 'no' }, ['check', 'extends', 'yes', 'no']],
|
||||
[{ id: 'infer-full', kind: 'infer', parameter: { id: 'infer', name: 'Value', const: false, constraint: 'constraint', default: 'fallback' } }, ['constraint', 'fallback']],
|
||||
[{ id: 'infer-empty', kind: 'infer', parameter: { id: 'infer', name: 'Value', const: false } }, []],
|
||||
[{ id: 'mapped-full', kind: 'mapped', parameter: { id: 'key', name: 'Key', const: false, constraint: 'constraint', default: 'fallback' }, nameType: 'name', value: 'value', readonly: 'preserve', optional: 'preserve' }, ['constraint', 'fallback', 'name', 'value']],
|
||||
[{ id: 'mapped-empty', kind: 'mapped', parameter: { id: 'key', name: 'Key', const: false }, readonly: 'preserve', optional: 'preserve' }, []],
|
||||
[{ id: 'template', kind: 'template-literal', head: '', spans: [{ type: 'leaf', text: '' }] }, ['leaf']],
|
||||
[{ id: 'query', kind: 'type-query', expression: 'value', arguments: ['leaf'] }, ['leaf']],
|
||||
[{ id: 'import', kind: 'import-type', module: 'fixture', arguments: ['leaf'], typeof: false }, ['leaf']],
|
||||
[{ id: 'predicate-full', kind: 'predicate', asserts: false, parameter: 'value', type: 'leaf' }, ['leaf']],
|
||||
[{ id: 'predicate-empty', kind: 'predicate', asserts: true, parameter: 'value' }, []],
|
||||
[{ id: 'this', kind: 'this' }, []],
|
||||
]
|
||||
|
||||
for (const [node, expected] of cases) expect(childTypeNodeIds(node)).toEqual(expected)
|
||||
})
|
||||
|
||||
it('renders optional source shapes and traverses every optional closure edge', () => {
|
||||
const dependency = declaration('dependency', 'Dependency', 'interface')
|
||||
const graph: TypeGraph = {
|
||||
declarations: [
|
||||
dependency,
|
||||
declaration('empty-enum', 'EmptyEnum', 'enum'),
|
||||
declaration('root', 'Root', 'interface', {
|
||||
members: [property('root-member', 'rootValue', 'imported')],
|
||||
}),
|
||||
],
|
||||
nodes: [
|
||||
keyword('string', 'string'),
|
||||
{ id: 'union', kind: 'union', types: ['string', 'string'] },
|
||||
{ id: 'array', kind: 'array', element: 'union' },
|
||||
{
|
||||
id: 'tuple',
|
||||
kind: 'tuple',
|
||||
elements: [
|
||||
{ type: 'string', optional: false, rest: false },
|
||||
{ type: 'string', optional: true, rest: false },
|
||||
{ type: 'array-of-string', optional: false, rest: true },
|
||||
],
|
||||
},
|
||||
{ id: 'array-of-string', kind: 'array', element: 'string' },
|
||||
{
|
||||
id: 'mapped',
|
||||
kind: 'mapped',
|
||||
parameter: {
|
||||
id: 'key',
|
||||
name: 'Key',
|
||||
const: false,
|
||||
constraint: 'string',
|
||||
default: 'string',
|
||||
},
|
||||
readonly: 'preserve',
|
||||
optional: 'preserve',
|
||||
},
|
||||
{
|
||||
id: 'infer',
|
||||
kind: 'infer',
|
||||
parameter: {
|
||||
id: 'inferred',
|
||||
name: 'Value',
|
||||
const: false,
|
||||
constraint: 'string',
|
||||
default: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'imported',
|
||||
kind: 'import-type',
|
||||
module: '@fixture/dependency',
|
||||
qualifier: 'Dependency',
|
||||
arguments: ['mapped', 'infer'],
|
||||
typeof: false,
|
||||
target: { kind: 'declaration', symbol: 'dependency' },
|
||||
},
|
||||
{ id: 'empty-object', kind: 'object', members: [] },
|
||||
],
|
||||
}
|
||||
const renderer = new TypeGraphRenderer(graph)
|
||||
|
||||
expect(renderer.renderType('array')).toBe('(string | string)[]')
|
||||
expect(renderer.renderType('tuple')).toBe('[string, string?, ...string[]]')
|
||||
expect(renderer.renderType('mapped')).toBe('{ [Key in string]: unknown }')
|
||||
expect(renderer.renderType('empty-object')).toBe('{}')
|
||||
expect(renderer.renderDeclaration('empty-enum')).toBe('export enum EmptyEnum {\n}')
|
||||
expect(renderer.declarationClosureForMembers(['root-member']).map(item => item.name))
|
||||
.toEqual(['Dependency'])
|
||||
})
|
||||
|
||||
it('fails loudly for every broken graph edge and impossible discriminant', () => {
|
||||
const missingConstraint: TypeNodeModel = {
|
||||
id: 'mapped',
|
||||
kind: 'mapped',
|
||||
parameter: { id: 'key', name: 'Key', const: false },
|
||||
readonly: 'preserve',
|
||||
optional: 'preserve',
|
||||
}
|
||||
const alias = declaration('alias', 'Alias', 'alias')
|
||||
const renderer = new TypeGraphRenderer({
|
||||
declarations: [alias],
|
||||
nodes: [missingConstraint],
|
||||
})
|
||||
|
||||
expect(() => renderer.node('missing')).toThrow(TypeGraphRenderError)
|
||||
expect(() => renderer.declaration('missing')).toThrow('missing declaration')
|
||||
expect(() => renderer.member('missing')).toThrow('missing member')
|
||||
expect(renderer.declarationClosureForTypes(['mapped'])).toEqual([])
|
||||
expect(() => renderer.renderType('mapped')).toThrow('has no constraint')
|
||||
expect(() => renderer.renderDeclaration('alias')).toThrow('has no type node')
|
||||
|
||||
const invalidNode = { id: 'invalid', kind: 'future-node' } as unknown as TypeNodeModel
|
||||
const invalidMember = {
|
||||
...property('invalid-member', 'value', 'mapped'),
|
||||
kind: 'future-member',
|
||||
} as unknown as MemberModel
|
||||
const invalidRenderer = new TypeGraphRenderer({
|
||||
declarations: [declaration('invalid-root', 'InvalidRoot', 'interface', { members: [invalidMember] })],
|
||||
nodes: [invalidNode],
|
||||
})
|
||||
expect(() => invalidRenderer.renderType('invalid')).toThrow('unsupported model variant')
|
||||
expect(() => invalidRenderer.renderMember(invalidMember)).toThrow('unsupported model variant')
|
||||
expect(() => invalidRenderer.declarationClosureForTypes(['invalid'])).toThrow('unsupported model variant')
|
||||
})
|
||||
})
|
||||
|
||||
function keyword(id: string, name: KeywordTypeName): TypeNodeModel {
|
||||
return { id, kind: 'keyword', name }
|
||||
}
|
||||
|
||||
function property(id: string, name: string, type: string): MemberModel {
|
||||
return {
|
||||
...documentation,
|
||||
id,
|
||||
kind: 'property',
|
||||
name,
|
||||
type,
|
||||
optional: false,
|
||||
readonly: false,
|
||||
async: false,
|
||||
abstract: false,
|
||||
static: false,
|
||||
visibility: 'public',
|
||||
location,
|
||||
text: `${name}: unknown`,
|
||||
}
|
||||
}
|
||||
|
||||
function declaration(
|
||||
id: string,
|
||||
name: string,
|
||||
kind: TypeDeclarationModel['kind'],
|
||||
options: { readonly members?: readonly MemberModel[] } = {},
|
||||
): TypeDeclarationModel {
|
||||
return {
|
||||
...documentation,
|
||||
id,
|
||||
package: '@fixture/renderer',
|
||||
name,
|
||||
kind,
|
||||
abstract: false,
|
||||
exported: true,
|
||||
location,
|
||||
text: `export ${kind === 'alias' ? 'type' : kind} ${name}`,
|
||||
typeParameters: [],
|
||||
extends: [],
|
||||
implements: [],
|
||||
members: options.members ?? [],
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,730 @@
|
||||
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { FaceModelEmitter, TypertEmitError } from '../src/emitter.ts'
|
||||
import type {
|
||||
FaceModel,
|
||||
KeywordTypeName,
|
||||
MemberModel,
|
||||
SignatureModel,
|
||||
TypeDeclarationModel,
|
||||
TypeNodeModel,
|
||||
} from '../src/model.ts'
|
||||
|
||||
const temporaryRoots: string[] = []
|
||||
const location = { file: 'fixture.ts', line: 1, column: 1 } as const
|
||||
const documentation = { tags: [] } as const
|
||||
|
||||
const ZOD_NODE_SUPPORT = {
|
||||
keyword: 'supported',
|
||||
literal: 'supported',
|
||||
parenthesized: 'supported',
|
||||
reference: 'supported',
|
||||
union: 'supported',
|
||||
intersection: 'supported',
|
||||
array: 'supported',
|
||||
tuple: 'supported',
|
||||
object: 'supported',
|
||||
function: 'unsupported',
|
||||
constructor: 'unsupported',
|
||||
'indexed-access': 'unsupported',
|
||||
operator: 'unsupported',
|
||||
conditional: 'unsupported',
|
||||
infer: 'unsupported',
|
||||
mapped: 'unsupported',
|
||||
'template-literal': 'unsupported',
|
||||
'type-query': 'unsupported',
|
||||
'import-type': 'unsupported',
|
||||
predicate: 'unsupported',
|
||||
this: 'unsupported',
|
||||
} as const satisfies Record<TypeNodeModel['kind'], 'supported' | 'unsupported'>
|
||||
|
||||
interface SchemaCase {
|
||||
readonly name: string
|
||||
readonly nodes: readonly TypeNodeModel[]
|
||||
readonly accepted: readonly unknown[]
|
||||
readonly rejected: readonly unknown[]
|
||||
}
|
||||
|
||||
const supportedCases: readonly SchemaCase[] = [
|
||||
keywordCase('any', [undefined], []),
|
||||
keywordCase('unknown', [{ arbitrary: true }], []),
|
||||
keywordCase('never', [], [undefined]),
|
||||
keywordCase('string', ['value'], [1]),
|
||||
keywordCase('number', [1], ['1']),
|
||||
keywordCase('bigint', [1n], [1]),
|
||||
keywordCase('boolean', [true], ['true']),
|
||||
keywordCase('symbol', [Symbol('value')], ['symbol']),
|
||||
keywordCase('undefined', [undefined], [null]),
|
||||
keywordCase('void', [undefined], [null]),
|
||||
keywordCase('object', [{ value: true }, [], () => undefined], [null, 1]),
|
||||
{
|
||||
name: 'literal',
|
||||
nodes: [{ id: 'root', kind: 'literal', value: 'ready', text: "'ready'" }],
|
||||
accepted: ['ready'],
|
||||
rejected: ['waiting'],
|
||||
},
|
||||
{
|
||||
name: 'numeric literal',
|
||||
nodes: [{ id: 'root', kind: 'literal', value: -2, text: '-2' }],
|
||||
accepted: [-2],
|
||||
rejected: [2],
|
||||
},
|
||||
{
|
||||
name: 'bigint literal',
|
||||
nodes: [{ id: 'root', kind: 'literal', value: -2n, text: '-2n' }],
|
||||
accepted: [-2n],
|
||||
rejected: [-2],
|
||||
},
|
||||
{
|
||||
name: 'boolean literal',
|
||||
nodes: [{ id: 'root', kind: 'literal', value: false, text: 'false' }],
|
||||
accepted: [false],
|
||||
rejected: [true],
|
||||
},
|
||||
{
|
||||
name: 'null literal',
|
||||
nodes: [{ id: 'root', kind: 'literal', value: null, text: 'null' }],
|
||||
accepted: [null],
|
||||
rejected: [undefined],
|
||||
},
|
||||
{
|
||||
name: 'no-substitution template literal',
|
||||
nodes: [{ id: 'root', kind: 'literal', value: 'fixed', text: '`fixed`' }],
|
||||
accepted: ['fixed'],
|
||||
rejected: ['other'],
|
||||
},
|
||||
{
|
||||
name: 'parenthesized',
|
||||
nodes: [
|
||||
{ id: 'root', kind: 'parenthesized', type: 'child' },
|
||||
keyword('child', 'string'),
|
||||
],
|
||||
accepted: ['value'],
|
||||
rejected: [1],
|
||||
},
|
||||
{
|
||||
name: 'standard reference',
|
||||
nodes: [{
|
||||
id: 'root',
|
||||
kind: 'reference',
|
||||
name: 'Date',
|
||||
target: { kind: 'standard', name: 'Date' },
|
||||
arguments: [],
|
||||
}],
|
||||
accepted: [new Date(0)],
|
||||
rejected: ['1970-01-01'],
|
||||
},
|
||||
{
|
||||
name: 'standard Array reference',
|
||||
nodes: [
|
||||
{ id: 'root', kind: 'reference', name: 'Array', target: { kind: 'standard', name: 'Array' }, arguments: ['element'] },
|
||||
keyword('element', 'string'),
|
||||
],
|
||||
accepted: [['value']],
|
||||
rejected: [[1]],
|
||||
},
|
||||
{
|
||||
name: 'standard ReadonlyArray reference',
|
||||
nodes: [
|
||||
{
|
||||
id: 'root',
|
||||
kind: 'reference',
|
||||
name: 'ReadonlyArray',
|
||||
target: { kind: 'standard', name: 'ReadonlyArray' },
|
||||
arguments: ['element'],
|
||||
},
|
||||
keyword('element', 'number'),
|
||||
],
|
||||
accepted: [[1]],
|
||||
rejected: [['1']],
|
||||
},
|
||||
{
|
||||
name: 'standard Record reference',
|
||||
nodes: [
|
||||
{
|
||||
id: 'root',
|
||||
kind: 'reference',
|
||||
name: 'Record',
|
||||
target: { kind: 'standard', name: 'Record' },
|
||||
arguments: ['key', 'value'],
|
||||
},
|
||||
keyword('key', 'string'),
|
||||
keyword('value', 'number'),
|
||||
],
|
||||
accepted: [{ one: 1 }],
|
||||
rejected: [{ one: '1' }],
|
||||
},
|
||||
{
|
||||
name: 'union',
|
||||
nodes: [
|
||||
{ id: 'root', kind: 'union', types: ['left', 'right'] },
|
||||
keyword('left', 'string'),
|
||||
keyword('right', 'number'),
|
||||
],
|
||||
accepted: ['value', 1],
|
||||
rejected: [true],
|
||||
},
|
||||
{
|
||||
name: 'empty union',
|
||||
nodes: [{ id: 'root', kind: 'union', types: [] }],
|
||||
accepted: [],
|
||||
rejected: [undefined],
|
||||
},
|
||||
{
|
||||
name: 'single union',
|
||||
nodes: [
|
||||
{ id: 'root', kind: 'union', types: ['child'] },
|
||||
keyword('child', 'string'),
|
||||
],
|
||||
accepted: ['value'],
|
||||
rejected: [1],
|
||||
},
|
||||
{
|
||||
name: 'intersection',
|
||||
nodes: [
|
||||
{ id: 'root', kind: 'intersection', types: ['left', 'right'] },
|
||||
{ id: 'left', kind: 'object', members: [property('name', 'string')] },
|
||||
{ id: 'right', kind: 'object', members: [property('count', 'number')] },
|
||||
keyword('string', 'string'),
|
||||
keyword('number', 'number'),
|
||||
],
|
||||
accepted: [{ name: 'value', count: 1 }],
|
||||
rejected: [{ name: 'value' }],
|
||||
},
|
||||
{
|
||||
name: 'empty intersection',
|
||||
nodes: [{ id: 'root', kind: 'intersection', types: [] }],
|
||||
accepted: [undefined, { value: true }],
|
||||
rejected: [],
|
||||
},
|
||||
{
|
||||
name: 'array',
|
||||
nodes: [
|
||||
{ id: 'root', kind: 'array', element: 'element' },
|
||||
keyword('element', 'string'),
|
||||
],
|
||||
accepted: [['one', 'two']],
|
||||
rejected: [['one', 2]],
|
||||
},
|
||||
{
|
||||
name: 'tuple with optional and rest elements',
|
||||
nodes: [
|
||||
{
|
||||
id: 'root',
|
||||
kind: 'tuple',
|
||||
elements: [
|
||||
{ name: 'head', type: 'string', optional: false, rest: false },
|
||||
{ name: 'count', type: 'number', optional: true, rest: false },
|
||||
{ name: 'tail', type: 'rest-array', optional: false, rest: true },
|
||||
],
|
||||
},
|
||||
keyword('string', 'string'),
|
||||
keyword('number', 'number'),
|
||||
{ id: 'rest-array', kind: 'array', element: 'boolean' },
|
||||
keyword('boolean', 'boolean'),
|
||||
],
|
||||
accepted: [['value'], ['value', 1, true, false]],
|
||||
rejected: [[1], ['value', 1, 'false']],
|
||||
},
|
||||
{
|
||||
name: 'fixed tuple',
|
||||
nodes: [
|
||||
{
|
||||
id: 'root',
|
||||
kind: 'tuple',
|
||||
elements: [{ type: 'string', optional: false, rest: false }],
|
||||
},
|
||||
keyword('string', 'string'),
|
||||
],
|
||||
accepted: [['value']],
|
||||
rejected: [[], [1]],
|
||||
},
|
||||
{
|
||||
name: 'tuple with standard reference rest',
|
||||
nodes: [
|
||||
{
|
||||
id: 'root',
|
||||
kind: 'tuple',
|
||||
elements: [{ type: 'rest', optional: false, rest: true }],
|
||||
},
|
||||
{
|
||||
id: 'rest',
|
||||
kind: 'reference',
|
||||
name: 'ReadonlyArray',
|
||||
target: { kind: 'standard', name: 'ReadonlyArray' },
|
||||
arguments: ['string'],
|
||||
},
|
||||
keyword('string', 'string'),
|
||||
],
|
||||
accepted: [[], ['value']],
|
||||
rejected: [[1]],
|
||||
},
|
||||
{
|
||||
name: 'object',
|
||||
nodes: [
|
||||
{
|
||||
id: 'root',
|
||||
kind: 'object',
|
||||
members: [
|
||||
property('name', 'string', { readonly: true }),
|
||||
property('count', 'number', { optional: true }),
|
||||
],
|
||||
},
|
||||
keyword('string', 'string'),
|
||||
keyword('number', 'number'),
|
||||
],
|
||||
accepted: [{ name: 'value' }, { name: 'value', count: 1 }],
|
||||
rejected: [{ name: 1 }],
|
||||
},
|
||||
]
|
||||
|
||||
const unsupportedNodeCases: readonly { readonly kind: TypeNodeModel['kind']; readonly nodes: readonly TypeNodeModel[] }[] = [
|
||||
{ kind: 'function', nodes: [{ id: 'root', kind: 'function', signature: signature('child') }, keyword('child', 'string')] },
|
||||
{ kind: 'constructor', nodes: [{ id: 'root', kind: 'constructor', abstract: false, signature: signature('child') }, keyword('child', 'string')] },
|
||||
{ kind: 'indexed-access', nodes: [{ id: 'root', kind: 'indexed-access', object: 'child', index: 'child' }, keyword('child', 'string')] },
|
||||
{ kind: 'operator', nodes: [{ id: 'root', kind: 'operator', operator: 'keyof', type: 'child' }, keyword('child', 'string')] },
|
||||
{
|
||||
kind: 'conditional',
|
||||
nodes: [{ id: 'root', kind: 'conditional', check: 'child', extends: 'child', whenTrue: 'child', whenFalse: 'child' }, keyword('child', 'string')],
|
||||
},
|
||||
{ kind: 'infer', nodes: [{ id: 'root', kind: 'infer', parameter: { id: 'parameter', name: 'Value', const: false } }] },
|
||||
{
|
||||
kind: 'mapped',
|
||||
nodes: [{
|
||||
id: 'root',
|
||||
kind: 'mapped',
|
||||
parameter: { id: 'parameter', name: 'Key', const: false, constraint: 'child' },
|
||||
value: 'child',
|
||||
readonly: 'preserve',
|
||||
optional: 'preserve',
|
||||
}, keyword('child', 'string')],
|
||||
},
|
||||
{
|
||||
kind: 'template-literal',
|
||||
nodes: [{ id: 'root', kind: 'template-literal', head: 'prefix-', spans: [{ type: 'child', text: '' }] }, keyword('child', 'string')],
|
||||
},
|
||||
{ kind: 'type-query', nodes: [{ id: 'root', kind: 'type-query', expression: 'value', arguments: [] }] },
|
||||
{ kind: 'import-type', nodes: [{ id: 'root', kind: 'import-type', module: 'external', arguments: [], typeof: false }] },
|
||||
{ kind: 'predicate', nodes: [{ id: 'root', kind: 'predicate', asserts: false, parameter: 'value', type: 'child' }, keyword('child', 'string')] },
|
||||
{ kind: 'this', nodes: [{ id: 'root', kind: 'this' }] },
|
||||
]
|
||||
|
||||
afterEach(() => {
|
||||
for (const root of temporaryRoots.splice(0)) rmSync(root, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
describe('SchemaEmitter supported projection matrix', () => {
|
||||
it.each(supportedCases)('$name', async ({ nodes, accepted, rejected }) => {
|
||||
const schema = await loadSchema(emit(nodes))
|
||||
for (const value of accepted) expect(schema.safeParse(value).success).toBe(true)
|
||||
for (const value of rejected) expect(schema.safeParse(value).success).toBe(false)
|
||||
})
|
||||
|
||||
it('supports recursive declarations and inherited object shapes', async () => {
|
||||
const recursive = declaration('Root', 'interface', {
|
||||
members: [
|
||||
property('value', 'string'),
|
||||
property('next', 'self', { optional: true }),
|
||||
],
|
||||
})
|
||||
const recursiveSchema = await loadSchema(emit([
|
||||
keyword('string', 'string'),
|
||||
{
|
||||
id: 'self',
|
||||
kind: 'reference',
|
||||
name: 'Root',
|
||||
target: { kind: 'declaration', symbol: 'Root' },
|
||||
arguments: [],
|
||||
},
|
||||
], recursive))
|
||||
expect(recursiveSchema.safeParse({ value: 'one', next: { value: 'two' } }).success).toBe(true)
|
||||
expect(recursiveSchema.safeParse({ value: 'one', next: { value: 2 } }).success).toBe(false)
|
||||
|
||||
const inherited = declaration('Root', 'interface', {
|
||||
extends: ['base-reference'],
|
||||
members: [property('current', 'number')],
|
||||
})
|
||||
const base = declaration('Base', 'interface', { members: [property('base', 'string')] })
|
||||
const inheritedSchema = await loadSchema(emit([
|
||||
{ id: 'base-reference', kind: 'reference', name: 'Base', target: { kind: 'declaration', symbol: 'Base' }, arguments: [] },
|
||||
keyword('string', 'string'),
|
||||
keyword('number', 'number'),
|
||||
], inherited, [base]))
|
||||
expect(inheritedSchema.safeParse({ base: 'value', current: 1 }).success).toBe(true)
|
||||
expect(inheritedSchema.safeParse({ current: 1 }).success).toBe(false)
|
||||
})
|
||||
|
||||
it('classifies every TypeNode kind and executes every supported kind', () => {
|
||||
const expected = Object.entries(ZOD_NODE_SUPPORT)
|
||||
.filter(([, support]) => support === 'supported')
|
||||
.map(([kind]) => kind)
|
||||
.sort()
|
||||
expect(distinct(supportedCases.map(candidate => candidate.nodes[0]?.kind ?? 'missing'))).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('SchemaEmitter unsupported projection matrix', () => {
|
||||
it.each(unsupportedNodeCases)('rejects $kind nodes explicitly', ({ kind, nodes }) => {
|
||||
expect(() => emit(nodes)).toThrow(new TypertEmitError(
|
||||
`typert Zod emitter: root: type node ${kind} has no Zod projection`,
|
||||
))
|
||||
})
|
||||
|
||||
it.each([
|
||||
['type-parameter', { kind: 'type-parameter', parameter: 'parameter' }],
|
||||
['cross-face', { kind: 'cross-face', face: 'client', package: '@fixture/client', subpath: '.', name: 'Value' }],
|
||||
['external', { kind: 'external', module: 'external', subpath: '.', name: 'Value' }],
|
||||
] as const)('rejects %s references explicitly', (kind, target) => {
|
||||
expect(() => emit([{
|
||||
id: 'root',
|
||||
kind: 'reference',
|
||||
name: 'Value',
|
||||
target,
|
||||
arguments: [],
|
||||
}])).toThrow(`typert Zod emitter: Value: ${kind} reference has no Zod projection`)
|
||||
})
|
||||
|
||||
it('rejects unsupported standard references, generic declarations, and enums', () => {
|
||||
const intrinsic = { id: 'root', kind: 'keyword', name: 'intrinsic' } as unknown as TypeNodeModel
|
||||
expect(() => emit([intrinsic]))
|
||||
.toThrow('keyword intrinsic has no Zod projection')
|
||||
|
||||
expect(() => emit([{
|
||||
id: 'root',
|
||||
kind: 'reference',
|
||||
name: 'Promise',
|
||||
target: { kind: 'standard', name: 'Promise' },
|
||||
arguments: [],
|
||||
}])).toThrow('standard type Promise has no Zod projection')
|
||||
|
||||
const generic = declaration('Generic', 'interface', {
|
||||
typeParameters: [{ id: 'parameter', name: 'Value', const: false }],
|
||||
})
|
||||
expect(() => emit([{
|
||||
id: 'root',
|
||||
kind: 'reference',
|
||||
name: 'Generic',
|
||||
target: { kind: 'declaration', symbol: 'Generic' },
|
||||
arguments: [],
|
||||
}], undefined, [generic])).toThrow('generic declarations require a schema-factory projection')
|
||||
|
||||
const enumeration = declaration('Enumeration', 'enum', {
|
||||
enumMembers: [{ ...documentation, name: 'Value', initializer: "'value'", location }],
|
||||
})
|
||||
expect(() => emit([{
|
||||
id: 'root',
|
||||
kind: 'reference',
|
||||
name: 'Enumeration',
|
||||
target: { kind: 'declaration', symbol: 'Enumeration' },
|
||||
arguments: [],
|
||||
}], undefined, [enumeration])).toThrow('enum declarations have no Zod projection')
|
||||
})
|
||||
|
||||
it('rejects incomplete collection references and invalid tuple rest types', () => {
|
||||
expect(() => emit([{
|
||||
id: 'root',
|
||||
kind: 'reference',
|
||||
name: 'Array',
|
||||
target: { kind: 'standard', name: 'Array' },
|
||||
arguments: [],
|
||||
}])).toThrow('array reference has no element type')
|
||||
|
||||
expect(() => emit([{
|
||||
id: 'root',
|
||||
kind: 'reference',
|
||||
name: 'Record',
|
||||
target: { kind: 'standard', name: 'Record' },
|
||||
arguments: [keyword('key', 'string').id],
|
||||
}, keyword('key', 'string')])).toThrow('Record requires key and value types')
|
||||
|
||||
expect(() => emit([
|
||||
{ id: 'root', kind: 'tuple', elements: [{ type: 'rest', optional: false, rest: true }] },
|
||||
{
|
||||
id: 'rest',
|
||||
kind: 'reference',
|
||||
name: 'Array',
|
||||
target: { kind: 'standard', name: 'Array' },
|
||||
arguments: [],
|
||||
},
|
||||
])).toThrow('tuple rest array has no element type')
|
||||
|
||||
expect(() => emit([
|
||||
{ id: 'root', kind: 'tuple', elements: [{ type: 'rest', optional: false, rest: true }] },
|
||||
keyword('rest', 'string'),
|
||||
])).toThrow('tuple rest element must retain an array type')
|
||||
})
|
||||
|
||||
it('rejects incomplete schema roots and non-function event signatures', () => {
|
||||
const incompleteAlias = declaration('Root', 'alias')
|
||||
expect(() => emit([], incompleteAlias)).toThrow('alias has no modeled type')
|
||||
|
||||
const missingSymbolFace = schemaFace([keyword('root', 'string')], 'missing')
|
||||
expect(() => new FaceModelEmitter(missingSymbolFace).emit('@fixture/schema'))
|
||||
.toThrow('referenced declaration is outside the selected schema closure')
|
||||
|
||||
const eventFace: FaceModel = {
|
||||
...schemaFace([], 'Root', []),
|
||||
graph: { declarations: [], nodes: [keyword('event', 'string')] },
|
||||
packages: [{
|
||||
name: '@fixture/schema',
|
||||
root: '.',
|
||||
exports: [],
|
||||
services: [],
|
||||
events: [{
|
||||
...documentation,
|
||||
name: 'fixture/event',
|
||||
signature: 'event',
|
||||
text: "'fixture/event'(): string",
|
||||
location,
|
||||
}],
|
||||
objects: [],
|
||||
schemas: [],
|
||||
}],
|
||||
}
|
||||
expect(() => new FaceModelEmitter(eventFace).emit('@fixture/schema'))
|
||||
.toThrow('event fixture/event is not a function type')
|
||||
expect(() => new FaceModelEmitter(eventFace).emit('@fixture/missing'))
|
||||
.toThrow('package @fixture/missing is not modeled')
|
||||
})
|
||||
|
||||
it('emits undocumented events without an optional mode', () => {
|
||||
const returns = keyword('returns', 'void')
|
||||
const event: TypeNodeModel = {
|
||||
id: 'event',
|
||||
kind: 'function',
|
||||
signature: { typeParameters: [], parameters: [], returns: 'returns' },
|
||||
}
|
||||
const face: FaceModel = {
|
||||
face: 'host',
|
||||
graph: { declarations: [], nodes: [returns, event] },
|
||||
packages: [{
|
||||
name: '@fixture/events',
|
||||
root: '.',
|
||||
exports: [],
|
||||
services: [],
|
||||
events: [{
|
||||
...documentation,
|
||||
name: 'fixture/event',
|
||||
signature: 'event',
|
||||
text: "'fixture/event'(): void",
|
||||
location,
|
||||
}],
|
||||
objects: [],
|
||||
schemas: [],
|
||||
}],
|
||||
}
|
||||
|
||||
const artifact = new FaceModelEmitter(face).emit('@fixture/events')
|
||||
expect(artifact.js).toContain('"name": "fixture/event"')
|
||||
expect(artifact.js).not.toContain('"mode"')
|
||||
})
|
||||
|
||||
it('skips non-instance data members and emits collision-safe schema identifiers', async () => {
|
||||
const hiddenMembers = declaration('Root', 'interface', {
|
||||
members: [
|
||||
{ ...property('static', 'string'), static: true },
|
||||
{ ...property('private', 'string'), visibility: 'private' },
|
||||
],
|
||||
})
|
||||
const hiddenSchema = await loadSchema(emit([keyword('string', 'string')], hiddenMembers))
|
||||
expect(hiddenSchema.safeParse({ arbitrary: true }).success).toBe(true)
|
||||
|
||||
const first = { ...declaration('first', 'interface'), name: 'Same' }
|
||||
const second = { ...declaration('second', 'interface'), name: 'Same' }
|
||||
const face = schemaFace([
|
||||
{ id: 'first-reference', kind: 'reference', name: 'Same', target: { kind: 'declaration', symbol: 'first' }, arguments: [] },
|
||||
{ id: 'second-reference', kind: 'reference', name: 'Same', target: { kind: 'declaration', symbol: 'second' }, arguments: [] },
|
||||
], 'first', [first, second])
|
||||
const packageModel = face.packages[0]
|
||||
if (packageModel === undefined) throw new Error('schema face has no package')
|
||||
const collisionFace: FaceModel = {
|
||||
...face,
|
||||
packages: [{
|
||||
...packageModel,
|
||||
schemas: [
|
||||
{ ...documentation, export: { subpath: '.', name: '1 bad', symbol: 'first', aliases: ['1 bad'] }, symbol: 'first', type: 'first-reference' },
|
||||
{ ...documentation, export: { subpath: './secondary', name: 'Same', symbol: 'second', aliases: ['Same'] }, symbol: 'second', type: 'second-reference' },
|
||||
],
|
||||
}],
|
||||
}
|
||||
const artifact = new FaceModelEmitter(collisionFace).emit('@fixture/schema')
|
||||
expect(artifact.js).toContain('const Same$schema2 =')
|
||||
expect(artifact.js).toContain('export const _1_bad = Same$schema')
|
||||
expect(artifact.dts).toContain("from '@fixture/schema/secondary'")
|
||||
})
|
||||
|
||||
it.each(['method', 'getter', 'setter', 'call', 'construct', 'index'] as const)(
|
||||
'rejects %s members on data-schema objects',
|
||||
(kind) => {
|
||||
expect(() => emit([
|
||||
{ id: 'root', kind: 'object', members: [signatureMember(kind)] },
|
||||
keyword('child', 'string'),
|
||||
])).toThrow(`${kind} member member is not data-schema projectable`)
|
||||
},
|
||||
)
|
||||
|
||||
it('classifies and rejects every unsupported TypeNode kind', () => {
|
||||
const expected = Object.entries(ZOD_NODE_SUPPORT)
|
||||
.filter(([, support]) => support === 'unsupported')
|
||||
.map(([kind]) => kind)
|
||||
.sort()
|
||||
expect(distinct(unsupportedNodeCases.map(candidate => candidate.kind))).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
function keywordCase(name: KeywordTypeName, accepted: readonly unknown[], rejected: readonly unknown[]): SchemaCase {
|
||||
return { name: `keyword ${name}`, nodes: [keyword('root', name)], accepted, rejected }
|
||||
}
|
||||
|
||||
function keyword(id: string, name: KeywordTypeName): TypeNodeModel {
|
||||
return { id, kind: 'keyword', name }
|
||||
}
|
||||
|
||||
function signature(returns: string): SignatureModel {
|
||||
return { typeParameters: [], parameters: [], returns }
|
||||
}
|
||||
|
||||
function property(
|
||||
name: string,
|
||||
type: string,
|
||||
options: { readonly optional?: boolean; readonly readonly?: boolean } = {},
|
||||
): MemberModel {
|
||||
return {
|
||||
...documentation,
|
||||
id: `member:${name}`,
|
||||
kind: 'property',
|
||||
name,
|
||||
type,
|
||||
optional: options.optional ?? false,
|
||||
readonly: options.readonly ?? false,
|
||||
async: false,
|
||||
abstract: false,
|
||||
static: false,
|
||||
visibility: 'public',
|
||||
location,
|
||||
text: `${name}: unknown`,
|
||||
}
|
||||
}
|
||||
|
||||
function signatureMember(kind: Exclude<MemberModel['kind'], 'property'>): MemberModel {
|
||||
return {
|
||||
...documentation,
|
||||
id: `member:${kind}`,
|
||||
kind,
|
||||
name: 'member',
|
||||
signature: signature('child'),
|
||||
optional: false,
|
||||
readonly: false,
|
||||
async: false,
|
||||
abstract: false,
|
||||
static: false,
|
||||
visibility: 'public',
|
||||
location,
|
||||
text: `${kind} member`,
|
||||
}
|
||||
}
|
||||
|
||||
function declaration(
|
||||
name: string,
|
||||
kind: TypeDeclarationModel['kind'],
|
||||
options: Partial<Pick<
|
||||
TypeDeclarationModel,
|
||||
'abstract' | 'typeParameters' | 'extends' | 'implements' | 'members' | 'type' | 'enumMembers'
|
||||
>> = {},
|
||||
): TypeDeclarationModel {
|
||||
return {
|
||||
...documentation,
|
||||
id: name,
|
||||
package: '@fixture/schema',
|
||||
name,
|
||||
kind,
|
||||
abstract: options.abstract ?? false,
|
||||
exported: true,
|
||||
location,
|
||||
text: `export ${kind === 'alias' ? 'type' : kind} ${name}`,
|
||||
typeParameters: options.typeParameters ?? [],
|
||||
extends: options.extends ?? [],
|
||||
implements: options.implements ?? [],
|
||||
members: options.members ?? [],
|
||||
...(options.type === undefined ? {} : { type: options.type }),
|
||||
...(options.enumMembers === undefined ? {} : { enumMembers: options.enumMembers }),
|
||||
}
|
||||
}
|
||||
|
||||
function emit(
|
||||
nodes: readonly TypeNodeModel[],
|
||||
rootDeclaration = declaration('Root', 'alias', { type: 'root' }),
|
||||
dependencies: readonly TypeDeclarationModel[] = [],
|
||||
): string {
|
||||
const schemaReference: TypeNodeModel = {
|
||||
id: 'schema-reference',
|
||||
kind: 'reference',
|
||||
name: 'Root',
|
||||
target: { kind: 'declaration', symbol: 'Root' },
|
||||
arguments: [],
|
||||
}
|
||||
const face: FaceModel = {
|
||||
face: 'host',
|
||||
graph: {
|
||||
declarations: [rootDeclaration, ...dependencies],
|
||||
nodes: [schemaReference, ...nodes],
|
||||
},
|
||||
packages: [{
|
||||
name: '@fixture/schema',
|
||||
root: '.',
|
||||
exports: [{ subpath: '.', name: 'Root', symbol: 'Root', aliases: ['Root'] }],
|
||||
services: [],
|
||||
events: [],
|
||||
objects: [],
|
||||
schemas: [{
|
||||
...documentation,
|
||||
export: { subpath: '.', name: 'Root', symbol: 'Root', aliases: ['Root'] },
|
||||
symbol: 'Root',
|
||||
type: 'schema-reference',
|
||||
}],
|
||||
}],
|
||||
}
|
||||
return new FaceModelEmitter(face).emit('@fixture/schema').js
|
||||
}
|
||||
|
||||
function schemaFace(
|
||||
nodes: readonly TypeNodeModel[],
|
||||
symbol: string,
|
||||
declarations: readonly TypeDeclarationModel[] = [declaration('Root', 'alias', { type: 'root' })],
|
||||
): FaceModel {
|
||||
return {
|
||||
face: 'host',
|
||||
graph: { declarations, nodes },
|
||||
packages: [{
|
||||
name: '@fixture/schema',
|
||||
root: '.',
|
||||
exports: [{ subpath: '.', name: 'Root', symbol, aliases: ['Root'] }],
|
||||
services: [],
|
||||
events: [],
|
||||
objects: [],
|
||||
schemas: [{
|
||||
...documentation,
|
||||
export: { subpath: '.', name: 'Root', symbol, aliases: ['Root'] },
|
||||
symbol,
|
||||
type: 'root',
|
||||
}],
|
||||
}],
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSchema(source: string): Promise<{ safeParse(value: unknown): { success: boolean } }> {
|
||||
const root = mkdtempSync(join(import.meta.dirname, '.generated-schema-'))
|
||||
temporaryRoots.push(root)
|
||||
const path = join(root, 'schema.mjs')
|
||||
writeFileSync(path, source)
|
||||
const generated = await import(`${pathToFileURL(path).href}?test=${Date.now()}-${String(temporaryRoots.length)}`) as {
|
||||
Root: { safeParse(value: unknown): { success: boolean } }
|
||||
}
|
||||
return generated.Root
|
||||
}
|
||||
|
||||
function distinct(values: readonly string[]): string[] {
|
||||
return [...new Set(values)].sort()
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { Context } from 'cordis'
|
||||
import TypertRegistry from '@deepseek-ai/dsh-typert-registry'
|
||||
import type { TypertContribution } from '@deepseek-ai/dsh-typert-registry/types'
|
||||
import { EVENT_API, SERVICE_API, TYPE_API } from '@deepseek-ai/dsh-tool-cordis/src/api-catalog.ts'
|
||||
import { WorkspaceAnalyzer } from '../src/analyzer.ts'
|
||||
import { FaceModelEmitter } from '../src/emitter.ts'
|
||||
|
||||
const workspaceRoot = resolve(import.meta.dirname, '../../../..')
|
||||
const temporaryRoots: string[] = []
|
||||
|
||||
afterEach(() => {
|
||||
for (const root of temporaryRoots.splice(0)) rmSync(root, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
describe('model-driven dsh-tools generation', () => {
|
||||
it('round-trips the complete service and event structure through the runtime registry', { timeout: 30_000 }, async () => {
|
||||
const workspace = new WorkspaceAnalyzer({
|
||||
root: workspaceRoot,
|
||||
faces: ['host'],
|
||||
packages: ['@deepseek-ai/dsh-tools'],
|
||||
}).analyze()
|
||||
const host = workspace.faces.find(candidate => candidate.face === 'host')
|
||||
if (host === undefined) throw new Error('dsh-tools has no analyzed host face')
|
||||
const artifact = new FaceModelEmitter(host).emit('@deepseek-ai/dsh-tools')
|
||||
|
||||
const root = mkdtempSync(join(import.meta.dirname, '.generated-tools-'))
|
||||
temporaryRoots.push(root)
|
||||
const modulePath = join(root, 'host.mjs')
|
||||
writeFileSync(modulePath, artifact.js)
|
||||
const generated = await import(`${pathToFileURL(modulePath).href}?test=${Date.now()}`) as {
|
||||
TYPERT: TypertContribution
|
||||
}
|
||||
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(TypertRegistry)
|
||||
const dispose = ctx.typert.register(generated.TYPERT)
|
||||
const record = ctx.typert.getPackage('@deepseek-ai/dsh-tools', 'host')
|
||||
const service = record?.model.services.find(candidate => candidate.key === 'tools')
|
||||
expect(service).toBeDefined()
|
||||
expect({
|
||||
key: service?.key,
|
||||
summary: service?.summary,
|
||||
methods: service?.members
|
||||
.filter(member => member.kind === 'method' && !member.name.startsWith('['))
|
||||
.map(member => ({
|
||||
signature: member.signature,
|
||||
jsDoc: member.jsDoc ?? '',
|
||||
})),
|
||||
}).toEqual(SERVICE_API.find(candidate => candidate.key === 'tools'))
|
||||
expect(record?.model.events.filter(event => event.name.startsWith('tools/')).map(event => ({
|
||||
name: event.name,
|
||||
mode: event.mode,
|
||||
signature: event.signature,
|
||||
jsDoc: event.jsDoc ?? '',
|
||||
summary: event.summary,
|
||||
}))).toEqual(EVENT_API.filter(event => event.name.startsWith('tools/')))
|
||||
expect(service?.types.find(type => type.name === 'ToolDefinition')).toEqual(
|
||||
TYPE_API.find(type => type.name === 'ToolDefinition'),
|
||||
)
|
||||
|
||||
dispose()
|
||||
expect(ctx.typert.getPackage('@deepseek-ai/dsh-tools', 'host')).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,106 @@
|
||||
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdir } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const generated = vi.hoisted(() => vi.fn(() => [
|
||||
{
|
||||
package: '@deepseek-ai/dsh-tools',
|
||||
packageRoot: 'packages/core/tools',
|
||||
face: 'host' as const,
|
||||
exports: [],
|
||||
js: 'export const host = true\n',
|
||||
dts: 'export declare const host: true\n',
|
||||
},
|
||||
{
|
||||
package: '@deepseek-ai/dsh-tools',
|
||||
packageRoot: 'packages/core/tools',
|
||||
face: 'client' as const,
|
||||
exports: [],
|
||||
js: 'export const client = true\n',
|
||||
dts: 'export declare const client: true\n',
|
||||
},
|
||||
]))
|
||||
|
||||
vi.mock('../src/workspace.ts', () => ({
|
||||
WorkspaceTypertGenerator: class {
|
||||
generate = generated
|
||||
},
|
||||
}))
|
||||
|
||||
const { typertPlugin } = await import('../src/tsdown-plugin.ts')
|
||||
const roots: string[] = []
|
||||
|
||||
afterEach(() => {
|
||||
generated.mockClear()
|
||||
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
describe('typertPlugin', () => {
|
||||
it('skips outputs that do not identify a Typert contributor', async () => {
|
||||
const plugin = typertPlugin()
|
||||
expect(plugin.name).toBe('dsh-typert-generator')
|
||||
plugin.writeBundle({})
|
||||
|
||||
const root = await workspace()
|
||||
const orphan = join(root, 'orphan', 'lib')
|
||||
await mkdir(orphan, { recursive: true })
|
||||
plugin.writeBundle({ dir: orphan })
|
||||
|
||||
const unnamed = await packageOutput(root, 'unnamed', {})
|
||||
plugin.writeBundle({ dir: unnamed })
|
||||
const other = await packageOutput(root, 'other', { name: '@fixture/other' })
|
||||
plugin.writeBundle({ dir: other })
|
||||
|
||||
expect(generated).not.toHaveBeenCalled()
|
||||
expect(() => { plugin.writeBundle({ dir: join(root, '..', 'outside', 'lib') }) })
|
||||
.toThrow('cannot find workspace root')
|
||||
})
|
||||
|
||||
it('writes every generated face beside a nested package bundle', async () => {
|
||||
const root = await workspace()
|
||||
const output = await packageOutput(root, 'tools', {
|
||||
name: '@deepseek-ai/dsh-tools',
|
||||
exports: { './typert': './lib/typert.host.js' },
|
||||
}, 'lib/dev')
|
||||
const clientOutput = await packageOutput(root, 'client-tools', {
|
||||
name: '@deepseek-ai/dsh-tools',
|
||||
exports: { './client/typert': './lib/typert.client.js' },
|
||||
})
|
||||
|
||||
const plugin = typertPlugin()
|
||||
plugin.writeBundle({ dir: output })
|
||||
plugin.writeBundle({ dir: clientOutput })
|
||||
|
||||
expect(generated).toHaveBeenCalledOnce()
|
||||
expect(generated).toHaveBeenCalledWith()
|
||||
const packageLib = join(root, 'packages', 'tools', 'lib')
|
||||
expect(readFileSync(join(packageLib, 'typert.host.js'), 'utf8')).toBe('export const host = true\n')
|
||||
expect(readFileSync(join(packageLib, 'typert.host.d.ts'), 'utf8')).toBe('export declare const host: true\n')
|
||||
expect(readFileSync(join(packageLib, 'typert.client.js'), 'utf8')).toBe('export const client = true\n')
|
||||
expect(existsSync(join(packageLib, 'typert.client.d.ts'))).toBe(true)
|
||||
expect(readFileSync(join(root, 'packages/client-tools/lib/typert.client.js'), 'utf8'))
|
||||
.toBe('export const client = true\n')
|
||||
})
|
||||
})
|
||||
|
||||
async function workspace(): Promise<string> {
|
||||
const root = mkdtempSync(join(tmpdir(), 'dsh-typert-tsdown-'))
|
||||
roots.push(root)
|
||||
writeFileSync(join(root, 'tsconfig.host.json'), '{}\n')
|
||||
return root
|
||||
}
|
||||
|
||||
async function packageOutput(
|
||||
root: string,
|
||||
directory: string,
|
||||
manifest: Record<string, unknown>,
|
||||
output = 'lib',
|
||||
): Promise<string> {
|
||||
const packageRoot = join(root, 'packages', directory)
|
||||
const result = join(packageRoot, output)
|
||||
await mkdir(result, { recursive: true })
|
||||
writeFileSync(join(packageRoot, 'package.json'), `${JSON.stringify(manifest)}\n`)
|
||||
return result
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "lib/types"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../../vendor/cosmokit"
|
||||
},
|
||||
{
|
||||
"path": "../../../vendor/cordis"
|
||||
},
|
||||
{
|
||||
"path": "../../support/invariants"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/typert/loader/README.md
|
||||
README.md: ab9293de1630fdbe8c560bb9e6d00c272cc34161
|
||||
README.zh.md: 7ececd07ac9a12bc04dca8206e348c25adc4ee76
|
||||
@@ -0,0 +1,24 @@
|
||||
# @deepseek-ai/dsh-typert-loader
|
||||
|
||||
English | [中文](README.zh.md)
|
||||
|
||||
Node-only Loader integration for generated Typert artifacts. The plugin requires `ctx.loader` and `ctx.typert`; it does not provide the registry itself.
|
||||
|
||||
During activation it scans existing Loader entries. It then follows Cordis `internal/plugin` lifecycle notifications, resolves each entry package's `package.json`, imports `./typert` when exported, validates its `TYPERT` manifest, and registers the contribution until the entry or this plugin unmounts. An import that settles after either owner is gone is discarded.
|
||||
|
||||
`packages` lists additional package artifacts to register for plugins nested behind another Loader entry. Cordis fibers do not retain those nested plugins' npm specifiers, so this boundary is explicit; every configured package must resolve from the config tree and export `./typert`.
|
||||
|
||||
Packages without the export are skipped. Package resolution and imported manifests are cached for the process lifetime, so adding an export requires a restart. A malformed artifact fails activation when already mounted; a later failure is logged without preventing unrelated packages from registering.
|
||||
|
||||
## Model Experience
|
||||
|
||||
None, as the loader only feeds [`ctx.typert`](../registry/README.md); consumers own any model-visible projection.
|
||||
|
||||
#### KV Cache effect
|
||||
|
||||
No direct effect.
|
||||
|
||||
## Known Limitations and Deferred Work
|
||||
|
||||
- Discovery imports only the host face; client runtimes need a separate composition owner before equivalent discovery is added.
|
||||
- Loader entries are discovered automatically. Nested or non-Loader plugins require an explicit `packages` entry or direct `ctx.typert.register()` ownership.
|
||||
@@ -0,0 +1,24 @@
|
||||
# @deepseek-ai/dsh-typert-loader
|
||||
|
||||
[English](README.md) | 中文
|
||||
|
||||
生成的 Typert 产物所用的 Loader 集成,仅支持 Node。该插件需要 `ctx.loader` 和 `ctx.typert`;它本身不提供注册表。
|
||||
|
||||
激活时,该插件会扫描现有的 Loader 配置项。随后它会监听 Cordis `internal/plugin` 生命周期通知,解析每个配置项所属包(package)的 `package.json`,在其导出 `./typert` 时导入该子路径,校验其 `TYPERT` manifest(元数据清单),并注册该贡献项,直到配置项或本插件卸载。如果导入操作在配置项或本插件卸载后才结束,系统会丢弃其结果。
|
||||
|
||||
`packages` 用于列出需要为嵌套在另一 Loader 配置项下的插件额外注册的包产物。Cordis fiber 不会保留这些嵌套插件的 npm 包说明符,因此这里通过显式配置划定边界;配置中列出的每个包都必须能从配置树解析,并导出 `./typert`。
|
||||
|
||||
未导出该子路径的包会被跳过。包解析结果和已导入的 manifest 会在整个进程生命周期内缓存,因此新增该导出后必须重启进程。如果已经挂载的产物格式错误,插件激活会失败;后续失败只会记录到日志,不会阻止无关包完成注册。
|
||||
|
||||
## 模型体验
|
||||
|
||||
无。loader 只向 [`ctx.typert`](../registry/README.md) 提供注册项;任何模型可见投影均由消费方负责。
|
||||
|
||||
#### KV Cache 影响
|
||||
|
||||
无直接影响。
|
||||
|
||||
## 已知限制与暂缓工作
|
||||
|
||||
- 发现机制只会导入宿主侧产物;若要为客户端运行时添加等价的发现机制,需要先有独立的组合所有者。
|
||||
- Loader 配置项会自动发现。嵌套插件或非 Loader 插件需要显式加入 `packages`,或由组合所有者直接负责调用 `ctx.typert.register()`。
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "@deepseek-ai/dsh-typert-loader",
|
||||
"description": "Loader integration for generated Typert package contributions",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/types/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/types/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./invariant": {
|
||||
"types": "./lib/types/invariant.d.ts",
|
||||
"default": "./lib/invariant.js"
|
||||
},
|
||||
"./src/*": "./src/*",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"lib/index.js",
|
||||
"lib/invariant.js",
|
||||
"lib/types/**/*.d.ts",
|
||||
"lib/types/**/*.d.ts.map",
|
||||
"src"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"peerDependencies": {
|
||||
"@cordisjs/plugin-loader": "^1.0.0-rc.5",
|
||||
"@deepseek-ai/dsh-invariants": "^0.0.1",
|
||||
"@deepseek-ai/dsh-typert-registry": "^0.0.1",
|
||||
"cordis": "^4.0.0-rc.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"schemastery": "^3.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cordisjs/plugin-loader": "workspace:^",
|
||||
"@deepseek-ai/dsh-invariants": "workspace:^",
|
||||
"@deepseek-ai/dsh-typert-registry": "workspace:^",
|
||||
"cordis": "^4.0.0-rc.7",
|
||||
"zod": "^4.4.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
/**
|
||||
* Typert Loader integration: automatic registration for mounted plugin packages.
|
||||
*
|
||||
* When a loader entry mounts, this plugin resolves the entry's package.json; a
|
||||
* package exporting `./typert` has its host face imported and its
|
||||
* `TYPERT` manifest registered into `ctx.typert`, and the registration is
|
||||
* withdrawn when the entry unmounts. Explicit `packages` cover plugins nested
|
||||
* behind another Loader entry, whose Cordis fibers carry no resolvable package
|
||||
* specifier. Packages without the export are skipped silently when discovered
|
||||
* from Loader entries; an explicit package or declared artifact that is broken
|
||||
* fails loud — aggregated into this plugin's activation throw for existing
|
||||
* entries, contained to a logged error per package in steady state.
|
||||
*
|
||||
* Scanning is incremental per entry name, mirroring the client-modules node
|
||||
* half: every cordis `internal/plugin` emission marks the fiber's entry name
|
||||
* dirty and a microtask flush reconciles each dirty name against the live
|
||||
* loader entries; the activation pass seeds the same dirty set with all
|
||||
* current entries. Package verdicts and imported manifests are cached per
|
||||
* package name and never expire — plugin-set changes take effect on restart.
|
||||
*
|
||||
* Manual `ctx.typert.register()` remains the escape hatch for contributions
|
||||
* that do not ride a `./typert` artifact (hand-written contract schemas,
|
||||
* tests, non-loader compositions).
|
||||
*
|
||||
* @module @deepseek-ai/dsh-typert-loader
|
||||
*/
|
||||
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import type { Context } from 'cordis'
|
||||
import z from 'schemastery'
|
||||
import type {} from '@cordisjs/plugin-loader'
|
||||
import type {} from '@deepseek-ai/dsh-typert-registry'
|
||||
import type { TypertContribution } from '@deepseek-ai/dsh-typert-registry/types'
|
||||
|
||||
/** The package.json exports key naming a package's host-face typert artifact. */
|
||||
export const TYPERT_HOST_EXPORT = './typert'
|
||||
|
||||
/** Cordis plugin name. */
|
||||
export const name = 'typert-loader'
|
||||
/** Services required before registration: the registry this plugin feeds and the Loader it observes. */
|
||||
export const inject = ['typert', 'loader']
|
||||
|
||||
/** Additional package artifacts whose owning plugins are nested behind another Loader entry. */
|
||||
export interface Config {
|
||||
/** Exact npm package names that must resolve and export `./typert`. */
|
||||
packages?: string[]
|
||||
}
|
||||
|
||||
/** Validate explicit package names and default to Loader-entry discovery only. */
|
||||
export const Config: z<Config> = z.object({
|
||||
packages: z.array(z.string().min(1)).default([]),
|
||||
})
|
||||
|
||||
type ResolvedConfig = Required<Config>
|
||||
|
||||
const MEMBER_KINDS = new Set(['property', 'method', 'getter', 'setter', 'call', 'construct', 'index'])
|
||||
|
||||
/** Resolve the `./typert` export to a relative path, accepting the string and one-level conditional forms. */
|
||||
function typertExportOf(pkgName: string, exportsField: unknown): string | undefined {
|
||||
if (typeof exportsField !== 'object' || exportsField === null) return undefined
|
||||
const target = (exportsField as Record<string, unknown>)[TYPERT_HOST_EXPORT]
|
||||
if (target === undefined) return undefined
|
||||
if (typeof target === 'string') return target
|
||||
if (typeof target === 'object' && target !== null) {
|
||||
const fallback = (target as Record<string, unknown>).default
|
||||
if (typeof fallback === 'string') return fallback
|
||||
}
|
||||
throw new Error(`typert-loader: ${pkgName} exports["${TYPERT_HOST_EXPORT}"] has an unsupported shape`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Narrow a dynamically imported typert module's `TYPERT` export to a
|
||||
* contribution owned by `pkgName`. This is the module/file boundary: the
|
||||
* manifest crosses from a build artifact into the typed registry, so every
|
||||
* field is checked and every failure names the package and the defect.
|
||||
* @param pkgName - the package whose typert face was imported.
|
||||
* @param exported - the module's `TYPERT` export.
|
||||
* @returns the validated contribution.
|
||||
*/
|
||||
export function validateTypertManifest(pkgName: string, exported: unknown): TypertContribution {
|
||||
if (typeof exported !== 'object' || exported === null) {
|
||||
throw new Error(`typert-loader: ${pkgName} exports "${TYPERT_HOST_EXPORT}" but its module has no TYPERT manifest object`)
|
||||
}
|
||||
const manifest = exported as Record<string, unknown>
|
||||
if (manifest.package !== pkgName) {
|
||||
throw new Error(
|
||||
`typert-loader: ${pkgName} TYPERT manifest names package ${JSON.stringify(manifest.package)} — the manifest must be owned by the package that exports it`,
|
||||
)
|
||||
}
|
||||
if (manifest.face !== 'host') {
|
||||
throw new Error(`typert-loader: ${pkgName} exports "${TYPERT_HOST_EXPORT}" but TYPERT.face is not "host"`)
|
||||
}
|
||||
if (!Array.isArray(manifest.schemas)) {
|
||||
throw new Error(`typert-loader: ${pkgName} TYPERT.schemas must be an array`)
|
||||
}
|
||||
for (const value of manifest.schemas as unknown[]) {
|
||||
if (typeof value !== 'object' || value === null) {
|
||||
throw new Error(`typert-loader: ${pkgName} TYPERT.schemas contains a non-object schema`)
|
||||
}
|
||||
const schema = value as Record<string, unknown>
|
||||
requireString(pkgName, schema, 'name', 'schema')
|
||||
if (typeof schema.schema !== 'object' || schema.schema === null || !('_zod' in schema.schema)) {
|
||||
throw new Error(`typert-loader: ${pkgName} TYPERT schema "${schema.name as string}" is not a zod v4 schema instance`)
|
||||
}
|
||||
}
|
||||
const model = requireObject(pkgName, manifest.model, 'TYPERT.model')
|
||||
const services = requireArray(pkgName, model.services, 'TYPERT.model.services')
|
||||
const events = requireArray(pkgName, model.events, 'TYPERT.model.events')
|
||||
const objects = requireArray(pkgName, model.objects, 'TYPERT.model.objects')
|
||||
for (const value of services) {
|
||||
const service = requireObject(pkgName, value, 'service')
|
||||
requireDocumentation(pkgName, service, 'service')
|
||||
requireString(pkgName, service, 'key', 'service')
|
||||
requireString(pkgName, service, 'exportName', 'service')
|
||||
requireMembers(pkgName, service.members, `service "${service.key as string}"`)
|
||||
requireTypes(pkgName, service.types, `service "${service.key as string}"`)
|
||||
}
|
||||
for (const value of events) {
|
||||
const event = requireObject(pkgName, value, 'event')
|
||||
requireDocumentation(pkgName, event, 'event')
|
||||
requireString(pkgName, event, 'name', 'event')
|
||||
requireString(pkgName, event, 'signature', `event "${event.name as string}"`)
|
||||
if (event.mode !== undefined && typeof event.mode !== 'string') {
|
||||
throw new Error(`typert-loader: ${pkgName} event "${event.name as string}" mode must be a string`)
|
||||
}
|
||||
}
|
||||
for (const value of objects) {
|
||||
const object = requireObject(pkgName, value, 'object')
|
||||
requireDocumentation(pkgName, object, 'object')
|
||||
requireString(pkgName, object, 'name', 'object')
|
||||
requireString(pkgName, object, 'exportName', 'object')
|
||||
requireMembers(pkgName, object.members, `object "${object.name as string}"`)
|
||||
requireTypes(pkgName, object.types, `object "${object.name as string}"`)
|
||||
}
|
||||
return manifest as unknown as TypertContribution
|
||||
}
|
||||
|
||||
function requireObject(pkgName: string, value: unknown, subject: string): Record<string, unknown> {
|
||||
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
||||
throw new Error(`typert-loader: ${pkgName} ${subject} must be an object`)
|
||||
}
|
||||
return value as Record<string, unknown>
|
||||
}
|
||||
|
||||
function requireArray(pkgName: string, value: unknown, subject: string): unknown[] {
|
||||
if (!Array.isArray(value)) throw new Error(`typert-loader: ${pkgName} ${subject} must be an array`)
|
||||
return value
|
||||
}
|
||||
|
||||
function requireString(pkgName: string, value: Record<string, unknown>, key: string, subject: string): void {
|
||||
if (typeof value[key] !== 'string' || value[key].length === 0) {
|
||||
throw new Error(`typert-loader: ${pkgName} ${subject} has a missing or empty ${key}`)
|
||||
}
|
||||
}
|
||||
|
||||
function requireDocumentation(pkgName: string, value: Record<string, unknown>, subject: string): void {
|
||||
requireArray(pkgName, value.tags, `${subject}.tags`)
|
||||
for (const key of ['description', 'summary', 'jsDoc'] as const) {
|
||||
if (value[key] !== undefined && typeof value[key] !== 'string') {
|
||||
throw new Error(`typert-loader: ${pkgName} ${subject}.${key} must be a string`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function requireMembers(pkgName: string, value: unknown, subject: string): void {
|
||||
for (const item of requireArray(pkgName, value, `${subject}.members`)) {
|
||||
const member = requireObject(pkgName, item, `${subject} member`)
|
||||
requireString(pkgName, member, 'name', `${subject} member`)
|
||||
requireString(pkgName, member, 'signature', `${subject} member`)
|
||||
if (typeof member.kind !== 'string' || !MEMBER_KINDS.has(member.kind)) {
|
||||
throw new Error(`typert-loader: ${pkgName} ${subject} member "${member.name as string}" has invalid kind`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function requireTypes(pkgName: string, value: unknown, subject: string): void {
|
||||
for (const item of requireArray(pkgName, value, `${subject}.types`)) {
|
||||
const type = requireObject(pkgName, item, `${subject} type`)
|
||||
requireString(pkgName, type, 'name', `${subject} type`)
|
||||
requireString(pkgName, type, 'declaration', `${subject} type`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan current Loader entries during activation, then follow entry mounts and
|
||||
* unmounts for this plugin's lifetime.
|
||||
* @param ctx - plugin context carrying `typert` and `loader`.
|
||||
* @param config - explicit package artifacts in addition to Loader entries.
|
||||
*/
|
||||
export async function apply(ctx: Context, config: Config): Promise<void> {
|
||||
// Resolution anchor: the config tree's baseUrl (the cordis.yml directory,
|
||||
// whose package declares every composed plugin as a dependency). This
|
||||
// package's own URL would miss sibling packages under pnpm's isolated
|
||||
// node_modules.
|
||||
if (ctx.baseUrl === undefined) {
|
||||
throw new Error('typert-loader: ctx.baseUrl is unset — the loader needs the config-tree anchor to resolve plugin packages')
|
||||
}
|
||||
const require = createRequire(ctx.baseUrl)
|
||||
const configured = new Set((config as ResolvedConfig).packages)
|
||||
|
||||
// Registered contributions by entry name; the disposer withdraws the entry's registration.
|
||||
const registered = new Map<string, () => void>()
|
||||
// In-flight import/register tasks by entry name.
|
||||
const pending = new Map<string, Promise<void>>()
|
||||
// Artifact paths by package name. Negative verdicts (unresolvable specifier —
|
||||
// loader builtins, subpath rows — or no typert export) are cached as null and
|
||||
// never expire: plugin-set changes take effect on restart.
|
||||
const artifactPath = new Map<string, string | null>()
|
||||
// Imported+validated manifests by package name (one import per package per process).
|
||||
const manifests = new Map<string, Promise<TypertContribution>>()
|
||||
const dirty = new Set<string>()
|
||||
let flushQueued = false
|
||||
let active = true
|
||||
ctx.effect(function* () {
|
||||
yield () => {
|
||||
active = false
|
||||
dirty.clear()
|
||||
}
|
||||
}, 'typert loader lifetime')
|
||||
|
||||
const resolveArtifact = (pkgName: string): string | null => {
|
||||
const cached = artifactPath.get(pkgName)
|
||||
if (cached !== undefined) return cached
|
||||
let pkgPath: string
|
||||
try {
|
||||
pkgPath = require.resolve(`${pkgName}/package.json`)
|
||||
} catch (cause) {
|
||||
if (configured.has(pkgName)) {
|
||||
throw new Error(
|
||||
`typert-loader: configured package "${pkgName}" cannot be resolved from the config tree — add it to the composition package dependencies or remove it from packages`,
|
||||
{ cause },
|
||||
)
|
||||
}
|
||||
// Not a resolvable package root: loader builtins (cordis:include) and
|
||||
// subpath entries land here — permanently not a typert contributor.
|
||||
artifactPath.set(pkgName, null)
|
||||
return null
|
||||
}
|
||||
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as Record<string, unknown>
|
||||
const rel = typertExportOf(pkgName, pkg.exports)
|
||||
if (rel === undefined && configured.has(pkgName)) {
|
||||
throw new Error(`typert-loader: configured package "${pkgName}" does not export "${TYPERT_HOST_EXPORT}"`)
|
||||
}
|
||||
const resolved = rel === undefined ? null : join(dirname(pkgPath), rel)
|
||||
artifactPath.set(pkgName, resolved)
|
||||
return resolved
|
||||
}
|
||||
|
||||
const loadManifest = (pkgName: string, path: string): Promise<TypertContribution> => {
|
||||
let loading = manifests.get(pkgName)
|
||||
if (loading === undefined) {
|
||||
loading = import(pathToFileURL(path).href).then(
|
||||
(mod: Record<string, unknown>) => validateTypertManifest(pkgName, mod.TYPERT),
|
||||
(cause: unknown) => {
|
||||
throw new Error(
|
||||
`typert-loader: ${pkgName} exports "${TYPERT_HOST_EXPORT}" but importing ${path} failed: ${String(cause)}`,
|
||||
)
|
||||
},
|
||||
)
|
||||
manifests.set(pkgName, loading)
|
||||
}
|
||||
return loading
|
||||
}
|
||||
|
||||
const qualifies = (entryName: string): boolean => {
|
||||
if (configured.has(entryName)) return true
|
||||
for (const entry of ctx.loader.entries()) {
|
||||
if (entry.options.name === entryName && entry.fiber !== undefined && !entry.disabled) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/** Reconcile one entry name against the live loader entries; a mount returns its async task. */
|
||||
const processOne = (entryName: string): Promise<void> | undefined => {
|
||||
if (!qualifies(entryName)) {
|
||||
const dispose = registered.get(entryName)
|
||||
if (dispose !== undefined) {
|
||||
registered.delete(entryName)
|
||||
dispose()
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
if (registered.has(entryName) || pending.has(entryName)) return undefined
|
||||
const path = resolveArtifact(entryName)
|
||||
if (path === null) return undefined
|
||||
const task = loadManifest(entryName, path).then((manifest) => {
|
||||
// The entry may have unmounted (or already re-registered) while the import was in flight.
|
||||
if (!active || !qualifies(entryName) || registered.has(entryName)) return
|
||||
registered.set(entryName, ctx.typert.register(manifest))
|
||||
})
|
||||
pending.set(entryName, task)
|
||||
// Two-armed settle: a bare .finally() would mint a second, unhandled rejection.
|
||||
const settle = (): void => { pending.delete(entryName) }
|
||||
void task.then(settle, settle)
|
||||
return task
|
||||
}
|
||||
|
||||
const flush = (onError: (error: Error) => void): Promise<void>[] => {
|
||||
const tasks: Promise<void>[] = []
|
||||
for (const entryName of [...dirty]) {
|
||||
dirty.delete(entryName)
|
||||
try {
|
||||
const task = processOne(entryName)
|
||||
if (task !== undefined) tasks.push(task.catch((error: unknown) => { onError(toError(error)) }))
|
||||
} catch (error) {
|
||||
// Steady state: one broken package must not poison the others; the
|
||||
// activation pass aggregates these into a loud throw instead.
|
||||
onError(toError(error))
|
||||
}
|
||||
}
|
||||
return tasks
|
||||
}
|
||||
|
||||
// Subscribe before seeding so an entry arriving mid-activation lands in the
|
||||
// same dirty set (Set idempotence makes the overlap harmless). An entry-less
|
||||
// fiber is a child plugin or a manual mount — never a loader row; O(1) drop.
|
||||
ctx.on('internal/plugin', (fiber) => {
|
||||
const entryName = fiber.entry?.options.name
|
||||
if (entryName === undefined) return
|
||||
dirty.add(entryName)
|
||||
if (flushQueued) return
|
||||
flushQueued = true
|
||||
queueMicrotask(() => {
|
||||
flushQueued = false
|
||||
if (!active) return
|
||||
for (const task of flush((err) => { ctx.logger.error(err) })) void task
|
||||
})
|
||||
})
|
||||
|
||||
// Activation pass: the initial scan IS the incremental path over the current
|
||||
// entries; a malformed typert contributor among the already-loaded entries
|
||||
// aggregates into one loud throw (FAILED loader fiber; the boot sweep reports it).
|
||||
for (const packageName of configured) dirty.add(packageName)
|
||||
for (const entry of ctx.loader.entries()) dirty.add(entry.options.name)
|
||||
const failures: Error[] = []
|
||||
await Promise.all(flush((err) => { failures.push(err) }))
|
||||
if (failures.length > 0) {
|
||||
throw new AggregateError(
|
||||
failures,
|
||||
`typert-loader: ${String(failures.length)} typert contributor(s) failed to register:\n${failures.map(e => ` - ${e.message}`).join('\n')}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Normalize an arbitrary import or manifest failure to an Error. */
|
||||
function toError(error: unknown): Error {
|
||||
return error instanceof Error ? error : new Error(String(error))
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Package-owned invariant companion for `@deepseek-ai/dsh-typert-loader`.
|
||||
* @module @deepseek-ai/dsh-typert-loader/invariant
|
||||
*/
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-typert-loader'
|
||||
|
||||
/** Cordis companion plugin name. */
|
||||
export const name = 'typert-loader-invariant'
|
||||
/** Service required before the companion can reserve package ownership. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/**
|
||||
* No runtime invariant: the Loader entry lifecycle directly owns each exact
|
||||
* registry disposer, and integration tests observe registration and removal.
|
||||
*/
|
||||
const install: InvariantInstaller = () => {}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
* @param ctx - Cordis context carrying the invariant service.
|
||||
* @returns the installed registration's disposer after setup succeeds.
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
@@ -0,0 +1,462 @@
|
||||
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { Context } from 'cordis'
|
||||
import Loader from '@cordisjs/plugin-loader'
|
||||
import TypertRegistry from '@deepseek-ai/dsh-typert-registry'
|
||||
import * as typertLoader from '@deepseek-ai/dsh-typert-loader'
|
||||
import { validateTypertManifest } from '@deepseek-ai/dsh-typert-loader'
|
||||
|
||||
let root: string | undefined
|
||||
let context: Context | undefined
|
||||
|
||||
afterEach(async () => {
|
||||
await context?.fiber.dispose()
|
||||
context = undefined
|
||||
Reflect.deleteProperty(globalThis, '__dshTypertLoaderGate')
|
||||
if (root !== undefined) await rm(root, { recursive: true, force: true })
|
||||
root = undefined
|
||||
})
|
||||
|
||||
/** Write a fake installed package under the fixture root's node_modules. */
|
||||
async function writePackage(
|
||||
base: string,
|
||||
pkgName: string,
|
||||
options: {
|
||||
typertExport?: boolean
|
||||
typertTarget?: unknown
|
||||
typertSource?: string
|
||||
pluginSource?: string
|
||||
omitExports?: boolean
|
||||
} = {},
|
||||
): Promise<void> {
|
||||
const dir = join(base, 'node_modules', ...pkgName.split('/'))
|
||||
await mkdir(dir, { recursive: true })
|
||||
const exportsField: Record<string, unknown> = { '.': './index.js', './package.json': './package.json' }
|
||||
if (options.typertExport !== false && options.typertSource !== undefined) {
|
||||
exportsField['./typert'] = options.typertTarget ?? './typert.host.js'
|
||||
}
|
||||
await writeFile(join(dir, 'package.json'), JSON.stringify({
|
||||
name: pkgName,
|
||||
type: 'module',
|
||||
...(options.omitExports ? { main: './index.js' } : { exports: exportsField }),
|
||||
}))
|
||||
await writeFile(join(dir, 'index.js'), options.pluginSource ?? 'export function apply() {}\n')
|
||||
if (options.typertSource !== undefined) {
|
||||
await writeFile(join(dir, 'typert.host.js'), options.typertSource)
|
||||
}
|
||||
}
|
||||
|
||||
function typertSource(pkgName: string, entryName: string): string {
|
||||
return [
|
||||
'import { z } from \'zod\'',
|
||||
`export const ${entryName} = z.object({ id: z.string() })`,
|
||||
'export const TYPERT = {',
|
||||
` package: '${pkgName}',`,
|
||||
' face: \'host\',',
|
||||
` schemas: [{ name: '${entryName}', schema: ${entryName} }],`,
|
||||
' model: { services: [], events: [], objects: [] },',
|
||||
'}',
|
||||
'',
|
||||
].join('\n')
|
||||
}
|
||||
|
||||
/** Boot a real Loader over a fixture root; plugin modules resolve from its node_modules. */
|
||||
async function boot(): Promise<Context> {
|
||||
context = new Context()
|
||||
context.baseUrl = pathToFileURL(join(root as string, 'cordis.yml')).href
|
||||
await context.plugin(TypertRegistry)
|
||||
await context.plugin(Loader)
|
||||
// zod must be resolvable from the fixture packages; link the workspace copy.
|
||||
await mkdir(join(root as string, 'node_modules'), { recursive: true })
|
||||
return context
|
||||
}
|
||||
|
||||
async function linkZod(base: string): Promise<void> {
|
||||
const { symlink } = await import('node:fs/promises')
|
||||
const target = join(base, 'node_modules', 'zod')
|
||||
const source = new URL(import.meta.resolve('zod/package.json')).pathname.replace(/\/package\.json$/, '')
|
||||
await mkdir(join(base, 'node_modules'), { recursive: true })
|
||||
await symlink(source, target, 'dir')
|
||||
}
|
||||
|
||||
function mountTypertLoader(ctx: Context, config: typertLoader.Config = {}): ReturnType<Context['plugin']> {
|
||||
return ctx.plugin(typertLoader, config)
|
||||
}
|
||||
|
||||
// Fixture setup writes fake installed packages and boots a real Loader; the
|
||||
// default 5s deadline is too tight on slow CI filesystems.
|
||||
const LOADER_TEST_TIMEOUT = { timeout: 60_000 }
|
||||
|
||||
describe('typert loader', () => {
|
||||
it('registers an explicit package without a Loader entry and withdraws it with the loader', LOADER_TEST_TIMEOUT, async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
||||
await linkZod(root)
|
||||
await writePackage(root, '@fixture/nested', { typertSource: typertSource('@fixture/nested', 'Nested') })
|
||||
const ctx = await boot()
|
||||
|
||||
const fiber = mountTypertLoader(ctx, { packages: ['@fixture/nested'] })
|
||||
await fiber
|
||||
expect(ctx.typert.get('@fixture/nested#Nested')).toBeDefined()
|
||||
|
||||
await fiber.dispose()
|
||||
expect(ctx.typert.getPackage('@fixture/nested')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('fails loud when an explicit package is absent or has no Typert export', LOADER_TEST_TIMEOUT, async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
||||
await writePackage(root, '@fixture/plain')
|
||||
const ctx = await boot()
|
||||
|
||||
let failure: unknown
|
||||
try {
|
||||
await mountTypertLoader(ctx, { packages: ['@fixture/missing', '@fixture/plain'] })
|
||||
} catch (error) {
|
||||
failure = error
|
||||
}
|
||||
expect(failure).toBeInstanceOf(AggregateError)
|
||||
expect((failure as Error).message).toContain('configured package "@fixture/missing" cannot be resolved')
|
||||
expect((failure as Error).message).toContain('configured package "@fixture/plain" does not export "./typert"')
|
||||
})
|
||||
|
||||
it('auto-registers a mounted package exporting ./typert and withdraws it on unmount', LOADER_TEST_TIMEOUT, async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
||||
await linkZod(root)
|
||||
await writePackage(root, '@fixture/with-typert', { typertSource: typertSource('@fixture/with-typert', 'Thing') })
|
||||
await writePackage(root, '@fixture/plain')
|
||||
const ctx = await boot()
|
||||
|
||||
const id = await ctx.loader.create({ name: '@fixture/with-typert' })
|
||||
const plainId = await ctx.loader.create({ name: '@fixture/plain' })
|
||||
await ctx.loader.await()
|
||||
await mountTypertLoader(ctx)
|
||||
await ctx.loader.await()
|
||||
|
||||
const record = ctx.typert.get('@fixture/with-typert#Thing')
|
||||
expect(record).toMatchObject({ package: '@fixture/with-typert', face: 'host', name: 'Thing' })
|
||||
expect(record?.schema.safeParse({ id: 'x' }).success).toBe(true)
|
||||
// The plain package is silently skipped.
|
||||
expect(ctx.typert.list().map(r => r.key)).toEqual(['@fixture/with-typert#Thing'])
|
||||
|
||||
const mounted = [...ctx.loader.entries()].find(entry => entry.options.name === '@fixture/with-typert')
|
||||
if (mounted?.fiber === undefined) throw new Error('fixture loader entry has no fiber')
|
||||
ctx.emit('internal/plugin', mounted.fiber)
|
||||
ctx.emit('internal/plugin', mounted.fiber)
|
||||
await new Promise(resolve => setTimeout(resolve, 20))
|
||||
expect(ctx.typert.list()).toHaveLength(1)
|
||||
|
||||
ctx.loader.remove(id)
|
||||
await ctx.loader.await()
|
||||
// The unmount reconciliation rides a queued microtask flush.
|
||||
await new Promise(resolve => setTimeout(resolve, 20))
|
||||
expect(ctx.typert.get('@fixture/with-typert#Thing')).toBeUndefined()
|
||||
ctx.loader.remove(plainId)
|
||||
await ctx.loader.await()
|
||||
await new Promise(resolve => setTimeout(resolve, 20))
|
||||
|
||||
await ctx.loader.create({ name: '@fixture/with-typert' })
|
||||
await ctx.loader.await()
|
||||
await new Promise(resolve => setTimeout(resolve, 20))
|
||||
expect(ctx.typert.get('@fixture/with-typert#Thing')).toBeDefined()
|
||||
})
|
||||
|
||||
it('follows entries mounted after activation', LOADER_TEST_TIMEOUT, async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
||||
await linkZod(root)
|
||||
await writePackage(root, '@fixture/late', { typertSource: typertSource('@fixture/late', 'Late') })
|
||||
const ctx = await boot()
|
||||
await mountTypertLoader(ctx)
|
||||
|
||||
expect(ctx.typert.get('@fixture/late#Late')).toBeUndefined()
|
||||
await ctx.loader.create({ name: '@fixture/late' })
|
||||
await ctx.loader.await()
|
||||
// The microtask flush and the dynamic import need a turn to settle.
|
||||
await new Promise(resolve => setTimeout(resolve, 20))
|
||||
expect(ctx.typert.get('@fixture/late#Late')).toBeDefined()
|
||||
})
|
||||
|
||||
it('drops an in-flight manifest when the loader is disposed before import settles', LOADER_TEST_TIMEOUT, async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
||||
await linkZod(root)
|
||||
let markStarted: (() => void) | undefined
|
||||
const started = new Promise<void>((resolve) => { markStarted = resolve })
|
||||
let releaseImport: (() => void) | undefined
|
||||
const wait = new Promise<void>((resolve) => { releaseImport = resolve })
|
||||
Reflect.set(globalThis, '__dshTypertLoaderGate', {
|
||||
started: (): void => { markStarted?.() },
|
||||
wait,
|
||||
})
|
||||
await writePackage(root, '@fixture/pending', {
|
||||
typertSource: [
|
||||
'import { z } from \'zod\'',
|
||||
'globalThis.__dshTypertLoaderGate.started()',
|
||||
'await globalThis.__dshTypertLoaderGate.wait',
|
||||
'export const Pending = z.object({ id: z.string() })',
|
||||
'export const TYPERT = {',
|
||||
' package: \'@fixture/pending\',',
|
||||
' face: \'host\',',
|
||||
' schemas: [{ name: \'Pending\', schema: Pending }],',
|
||||
' model: { services: [], events: [], objects: [] },',
|
||||
'}',
|
||||
'',
|
||||
].join('\n'),
|
||||
})
|
||||
const ctx = await boot()
|
||||
const loaderFiber = mountTypertLoader(ctx)
|
||||
await loaderFiber
|
||||
await ctx.loader.create({ name: '@fixture/pending' })
|
||||
await ctx.loader.await()
|
||||
await started
|
||||
|
||||
const mounted = [...ctx.loader.entries()].find(entry => entry.options.name === '@fixture/pending')
|
||||
if (mounted?.fiber === undefined) throw new Error('fixture loader entry has no fiber')
|
||||
ctx.emit('internal/plugin', mounted.fiber)
|
||||
await Promise.resolve()
|
||||
|
||||
let queued: (() => void) | undefined
|
||||
const queue = vi.spyOn(globalThis, 'queueMicrotask').mockImplementation((callback) => { queued = callback })
|
||||
ctx.emit('internal/plugin', mounted.fiber)
|
||||
queue.mockRestore()
|
||||
|
||||
await loaderFiber.dispose()
|
||||
queued?.()
|
||||
releaseImport?.()
|
||||
await new Promise(resolve => setTimeout(resolve, 20))
|
||||
|
||||
expect(ctx.typert.getPackage('@fixture/pending')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('fails activation loud when an already-mounted contributor is malformed', LOADER_TEST_TIMEOUT, async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
||||
await linkZod(root)
|
||||
await writePackage(root, '@fixture/broken', {
|
||||
typertSource: 'export const TYPERT = { package: \'@fixture/broken\', face: \'host\', schemas: [{ name: \'\', schema: {} }], model: { services: [], events: [], objects: [] } }\n',
|
||||
})
|
||||
const ctx = await boot()
|
||||
await ctx.loader.create({ name: '@fixture/broken' })
|
||||
await ctx.loader.await()
|
||||
|
||||
await expect(mountTypertLoader(ctx)).rejects.toThrow(/typert contributor\(s\) failed to register/)
|
||||
})
|
||||
|
||||
it('fails loud when the declared typert module cannot be imported', LOADER_TEST_TIMEOUT, async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
||||
await linkZod(root)
|
||||
await writePackage(root, '@fixture/no-module', {
|
||||
typertSource: 'import { missing } from \'./nope.js\'\nexport const TYPERT = missing\n',
|
||||
})
|
||||
const ctx = await boot()
|
||||
await ctx.loader.create({ name: '@fixture/no-module' })
|
||||
await ctx.loader.await()
|
||||
|
||||
await expect(mountTypertLoader(ctx)).rejects.toThrow(/importing .* failed/)
|
||||
})
|
||||
|
||||
it('accepts conditional artifact exports and skips packages with no exports field', LOADER_TEST_TIMEOUT, async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
||||
await linkZod(root)
|
||||
await writePackage(root, '@fixture/conditional', {
|
||||
typertSource: typertSource('@fixture/conditional', 'Conditional'),
|
||||
typertTarget: { default: './typert.host.js' },
|
||||
})
|
||||
await writePackage(root, '@fixture/no-exports', { omitExports: true })
|
||||
const ctx = await boot()
|
||||
await ctx.loader.create({ name: '@fixture/conditional' })
|
||||
await ctx.loader.create({ name: '@fixture/no-exports' })
|
||||
await ctx.loader.await()
|
||||
|
||||
await mountTypertLoader(ctx)
|
||||
|
||||
expect(ctx.typert.get('@fixture/conditional#Conditional')).toBeDefined()
|
||||
expect(ctx.typert.getPackage('@fixture/no-exports')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('aggregates unsupported package export shapes during activation', LOADER_TEST_TIMEOUT, async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
||||
await linkZod(root)
|
||||
await writePackage(root, '@fixture/export-shape', {
|
||||
typertSource: typertSource('@fixture/export-shape', 'Shape'),
|
||||
typertTarget: { default: 1 },
|
||||
})
|
||||
await writePackage(root, '@fixture/export-primitive', {
|
||||
typertSource: typertSource('@fixture/export-primitive', 'Primitive'),
|
||||
typertTarget: 1,
|
||||
})
|
||||
const ctx = await boot()
|
||||
await ctx.loader.create({ name: '@fixture/export-shape' })
|
||||
await ctx.loader.create({ name: '@fixture/export-primitive' })
|
||||
await ctx.loader.await()
|
||||
|
||||
await expect(mountTypertLoader(ctx)).rejects.toThrow('unsupported shape')
|
||||
})
|
||||
|
||||
it('caches a negative verdict for loader entries without a package root', LOADER_TEST_TIMEOUT, async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
||||
const ctx = await boot()
|
||||
ctx.loader.internal = {
|
||||
version: 'v2',
|
||||
async import(specifier: string) {
|
||||
if (specifier !== 'virtual-plugin') throw new Error(`unexpected fixture import ${specifier}`)
|
||||
return { apply() {} }
|
||||
},
|
||||
} as unknown as NonNullable<typeof ctx.loader.internal>
|
||||
await ctx.loader.create({ name: 'virtual-plugin' })
|
||||
await ctx.loader.await()
|
||||
|
||||
await mountTypertLoader(ctx)
|
||||
|
||||
expect(ctx.typert.getPackage('virtual-plugin')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('requires a config-tree resolution anchor', LOADER_TEST_TIMEOUT, async () => {
|
||||
context = new Context()
|
||||
await context.plugin(TypertRegistry)
|
||||
await context.plugin(Loader)
|
||||
|
||||
await expect(mountTypertLoader(context)).rejects.toThrow('ctx.baseUrl is unset')
|
||||
})
|
||||
|
||||
it('contains steady-state registration failures and normalizes non-Error throws', LOADER_TEST_TIMEOUT, async () => {
|
||||
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
||||
await linkZod(root)
|
||||
await writePackage(root, '@fixture/steady-failure', {
|
||||
typertSource: typertSource('@fixture/steady-failure', 'Steady'),
|
||||
})
|
||||
const ctx = await boot()
|
||||
await mountTypertLoader(ctx)
|
||||
const logged = vi.spyOn(ctx.logger, 'error').mockImplementation(() => undefined)
|
||||
vi.spyOn(ctx.typert, 'register').mockImplementation(() => { throw 'register failed' })
|
||||
|
||||
await ctx.loader.create({ name: '@fixture/steady-failure' })
|
||||
await ctx.loader.await()
|
||||
await new Promise(resolve => setTimeout(resolve, 20))
|
||||
|
||||
expect(logged).toHaveBeenCalledWith(expect.objectContaining({ message: 'register failed' }))
|
||||
expect(ctx.typert.getPackage('@fixture/steady-failure')).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('validateTypertManifest', () => {
|
||||
const zodish = { _zod: {} }
|
||||
|
||||
it('accepts a well-formed manifest and rejects each malformed field loudly', () => {
|
||||
expect(validateTypertManifest('pkg', {
|
||||
package: 'pkg',
|
||||
face: 'host',
|
||||
schemas: [{ name: 'A', schema: zodish }],
|
||||
model: { services: [], events: [], objects: [] },
|
||||
}).schemas).toHaveLength(1)
|
||||
|
||||
expect(() => validateTypertManifest('pkg', undefined)).toThrow('no TYPERT manifest object')
|
||||
expect(() => validateTypertManifest('pkg', { package: 'other' })).toThrow('must be owned by the package')
|
||||
expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'client' })).toThrow('TYPERT.face is not "host"')
|
||||
expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'host', schemas: 'x' })).toThrow('schemas must be an array')
|
||||
expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'host', schemas: [null] })).toThrow('non-object schema')
|
||||
expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'host', schemas: [{ name: '', schema: zodish }] }))
|
||||
.toThrow('missing or empty name')
|
||||
expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'host', schemas: [{ name: 'A', schema: {} }] }))
|
||||
.toThrow('not a zod v4 schema instance')
|
||||
expect(() => validateTypertManifest('pkg', {
|
||||
package: 'pkg',
|
||||
face: 'host',
|
||||
schemas: [],
|
||||
model: { services: [{ key: 'tools', exportName: 'ToolRegistry', tags: [], members: 'x', types: [] }], events: [], objects: [] },
|
||||
})).toThrow('service "tools".members must be an array')
|
||||
})
|
||||
|
||||
it('validates service, event, object, member, type, and documentation records', () => {
|
||||
const complete = completeManifest(zodish)
|
||||
expect(validateTypertManifest('pkg', complete)).toBe(complete)
|
||||
|
||||
expect(() => validateTypertManifest('pkg', { ...complete, model: [] }))
|
||||
.toThrow('TYPERT.model must be an object')
|
||||
expect(() => validateTypertManifest('pkg', { ...complete, model: { ...complete.model, services: [null] } }))
|
||||
.toThrow('service must be an object')
|
||||
expect(() => validateTypertManifest('pkg', {
|
||||
...complete,
|
||||
model: { ...complete.model, services: [{ ...complete.model.services[0], tags: 'bad' }] },
|
||||
})).toThrow('service.tags must be an array')
|
||||
expect(() => validateTypertManifest('pkg', {
|
||||
...complete,
|
||||
model: { ...complete.model, services: [{ ...complete.model.services[0], description: 1 }] },
|
||||
})).toThrow('service.description must be a string')
|
||||
expect(() => validateTypertManifest('pkg', {
|
||||
...complete,
|
||||
model: { ...complete.model, services: [{ ...complete.model.services[0], key: '' }] },
|
||||
})).toThrow('service has a missing or empty key')
|
||||
expect(() => validateTypertManifest('pkg', {
|
||||
...complete,
|
||||
model: { ...complete.model, services: [{ ...complete.model.services[0], members: [null] }] },
|
||||
})).toThrow('member must be an object')
|
||||
expect(() => validateTypertManifest('pkg', {
|
||||
...complete,
|
||||
model: {
|
||||
...complete.model,
|
||||
services: [{ ...complete.model.services[0], members: [{ name: 'member', signature: 'member(): void', kind: 1 }] }],
|
||||
},
|
||||
})).toThrow('has invalid kind')
|
||||
expect(() => validateTypertManifest('pkg', {
|
||||
...complete,
|
||||
model: {
|
||||
...complete.model,
|
||||
services: [{ ...complete.model.services[0], members: [{ name: 'member', signature: 'member(): void', kind: 'future' }] }],
|
||||
},
|
||||
})).toThrow('has invalid kind')
|
||||
expect(() => validateTypertManifest('pkg', {
|
||||
...complete,
|
||||
model: { ...complete.model, services: [{ ...complete.model.services[0], types: [null] }] },
|
||||
})).toThrow('type must be an object')
|
||||
expect(() => validateTypertManifest('pkg', {
|
||||
...complete,
|
||||
model: {
|
||||
...complete.model,
|
||||
services: [{ ...complete.model.services[0], types: [{ name: 'Type', declaration: '' }] }],
|
||||
},
|
||||
})).toThrow('type has a missing or empty declaration')
|
||||
expect(() => validateTypertManifest('pkg', {
|
||||
...complete,
|
||||
model: { ...complete.model, events: [{ ...complete.model.events[0], mode: 1 }] },
|
||||
})).toThrow('mode must be a string')
|
||||
expect(() => validateTypertManifest('pkg', { ...complete, model: { ...complete.model, objects: [null] } }))
|
||||
.toThrow('object must be an object')
|
||||
expect(() => validateTypertManifest('pkg', {
|
||||
...complete,
|
||||
model: { ...complete.model, objects: [{ ...complete.model.objects[0], exportName: '' }] },
|
||||
})).toThrow('object has a missing or empty exportName')
|
||||
})
|
||||
})
|
||||
|
||||
function completeManifest(zodish: object) {
|
||||
const member = { name: 'member', signature: 'member(): void', kind: 'method' }
|
||||
const type = { name: 'Value', declaration: 'export interface Value {}' }
|
||||
return {
|
||||
package: 'pkg',
|
||||
face: 'host',
|
||||
schemas: [{ name: 'Schema', schema: zodish }],
|
||||
model: {
|
||||
services: [{
|
||||
key: 'service',
|
||||
exportName: 'Service',
|
||||
description: 'Service description.',
|
||||
summary: 'Service description.',
|
||||
jsDoc: '/** Service description. */',
|
||||
tags: [],
|
||||
members: [member],
|
||||
types: [type],
|
||||
}],
|
||||
events: [
|
||||
{ name: 'event/with-mode', mode: 'emit', signature: "'event/with-mode'(): void", tags: [] },
|
||||
{ name: 'event/without-mode', signature: "'event/without-mode'(): void", tags: [] },
|
||||
],
|
||||
objects: [{
|
||||
name: 'Object',
|
||||
exportName: 'Object',
|
||||
tags: [],
|
||||
members: [member],
|
||||
types: [type],
|
||||
}],
|
||||
},
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user