dsh-ptc-plus 0.3.2 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/README.en.md +65 -78
  2. package/README.md +65 -78
  3. package/assets/ptc-plus-bindings-en.png +0 -0
  4. package/assets/ptc-plus-bindings-zh.png +0 -0
  5. package/assets/ptc-plus-repair-en.png +0 -0
  6. package/assets/ptc-plus-repair-zh.png +0 -0
  7. package/assets/ptc-plus-repl-workspace-en.png +0 -0
  8. package/assets/ptc-plus-repl-workspace-zh.png +0 -0
  9. package/assets/ptc-plus-settings-en.png +0 -0
  10. package/assets/ptc-plus-settings-zh.png +0 -0
  11. package/client.js +30596 -742
  12. package/compiler-amaro.cjs +5 -0
  13. package/compiler-amaro.cjs.map +6 -0
  14. package/compiler-asset-124f80c1bba92ff5fe79cfec6e8ad518f476de4a42514cae3919538887f510e8.txt +1 -0
  15. package/compiler-assets.json +3 -0
  16. package/compiler-core.cjs +554 -0
  17. package/compiler-core.cjs.map +6 -0
  18. package/compiler-platform.cjs +2 -0
  19. package/compiler-platform.cjs.map +6 -0
  20. package/compiler-typescript.cjs +388 -0
  21. package/compiler-typescript.cjs.map +6 -0
  22. package/docs/README.md +6 -0
  23. package/docs/adr/0004-declare-program-bindings-at-the-host.md +1 -1
  24. package/docs/adr/0006-rewrite-module-syntax-with-an-ast.md +5 -3
  25. package/docs/adr/0007-separate-worker-transport-from-session-semantics.md +1 -1
  26. package/docs/adr/0009-bound-expensive-acceptance-default.md +2 -0
  27. package/docs/adr/0010-session-log-derived-recovery-tips.md +59 -5
  28. package/docs/adr/0011-isolate-the-local-recovery-tip-provider.md +1 -1
  29. package/docs/adr/0012-preserve-mixed-destructuring-initialization.md +3 -1
  30. package/docs/adr/0013-isolate-repl-redeclaration-convenience.md +3 -1
  31. package/docs/adr/0014-persist-cell-rewrite-policy.md +6 -2
  32. package/docs/adr/0015-preserve-source-positions-through-rewrites.md +1 -1
  33. package/docs/adr/0016-archive-resolved-review-findings.md +1 -1
  34. package/docs/adr/0017-track-the-latest-dsh-public-surface.md +49 -0
  35. package/docs/adr/0018-use-versioned-fixture-for-ab-benchmark.md +3 -3
  36. package/docs/adr/0019-plugin-settings-and-kill-switch.md +5 -3
  37. package/docs/adr/0020-optional-cordis-tools-in-ptc-mode.md +2 -2
  38. package/docs/adr/0021-separate-host-bootstrap-from-session-runtime.md +12 -0
  39. package/docs/adr/0023-global-user-bindings.md +104 -0
  40. package/docs/adr/0024-repl-console-observation.md +33 -0
  41. package/docs/adr/0025-use-versioned-logical-binding-identities.md +119 -0
  42. package/docs/adr/0026-persist-the-delivery-verdict-against-the-verified-candidate.md +21 -0
  43. package/docs/adr/0027-run-the-session-kernel-in-a-killable-helper-process.md +37 -0
  44. package/docs/adr/0028-attach-to-the-host-ptc-execution-seam.md +103 -0
  45. package/docs/adr/0029-keep-plugin-unavailability-out-of-the-host-agent-lifecycle.md +27 -0
  46. package/docs/adr/0030-serve-both-typert-codec-generations-from-one-codec.md +27 -0
  47. package/docs/architecture.md +73 -21
  48. package/docs/binding-review-placement-design.md +200 -0
  49. package/docs/capability-projection.md +1 -1
  50. package/docs/client-ui.md +95 -19
  51. package/docs/durability-design.md +25 -10
  52. package/docs/evaluation.md +78 -6
  53. package/docs/installation.md +41 -6
  54. package/docs/publishing.md +5 -3
  55. package/docs/runtime-reference.md +72 -25
  56. package/docs/semantic-validation.md +29 -0
  57. package/docs/stateful-binding-updates-proposal.md +755 -0
  58. package/docs/user-bindings.en.md +64 -0
  59. package/docs/user-bindings.md +64 -0
  60. package/docs/value-wire.md +3 -3
  61. package/docs/verification.md +57 -0
  62. package/index.js +369 -92
  63. package/internal/ast-traversal.js +5 -2
  64. package/internal/binding-descriptors.js +1 -0
  65. package/internal/binding-pattern-traversal.js +25 -0
  66. package/internal/binding-pattern.js +26 -29
  67. package/internal/binding-source-analysis.js +391 -0
  68. package/internal/binding-update-policy.js +66 -0
  69. package/internal/bounded-worker-round.js +56 -0
  70. package/internal/callable-definition-environment.js +42 -0
  71. package/internal/callable-source-catalog.js +129 -0
  72. package/internal/callable-source-encoding.js +47 -0
  73. package/internal/callable-source-facts.js +459 -0
  74. package/internal/callable-source-format.js +2 -0
  75. package/internal/callable-source-lowering.js +123 -0
  76. package/internal/cell-analysis-contract.js +25 -0
  77. package/internal/cell-analysis.js +240 -290
  78. package/internal/cell-completion.js +15 -0
  79. package/internal/cell-error.js +7 -0
  80. package/internal/cell-parser.js +66 -0
  81. package/internal/cell-rewriter.js +3 -677
  82. package/internal/commonjs-export-evidence.js +63 -0
  83. package/internal/commonjs-source-evidence.js +72 -0
  84. package/internal/compiler-amaro.cjs +2 -0
  85. package/internal/compiler-compression.js +12 -0
  86. package/internal/compiler-data.js +58 -0
  87. package/internal/compiler-descriptors.js +54 -0
  88. package/internal/compiler-dynamic-cache.js +48 -0
  89. package/internal/compiler-entry.js +35 -0
  90. package/internal/compiler-generated-names.js +17 -0
  91. package/internal/compiler-intrinsics.js +84 -0
  92. package/internal/compiler-module-links.js +34 -0
  93. package/internal/compiler-operations.js +61 -0
  94. package/internal/compiler-platform-factory.js +84 -0
  95. package/internal/compiler-platform.js +136 -0
  96. package/internal/compiler-record-roles.js +53 -0
  97. package/internal/compiler-region-output.js +259 -0
  98. package/internal/compiler-resource-lowering.js +103 -0
  99. package/internal/compiler-scope-facts.js +115 -0
  100. package/internal/compiler-service.js +109 -0
  101. package/internal/compiler-source-cache.js +32 -0
  102. package/internal/compiler-source-pieces.js +93 -0
  103. package/internal/compiler-source-regions.js +132 -0
  104. package/internal/compiler-storage-source.js +54 -0
  105. package/internal/compiler-text.js +15 -0
  106. package/internal/compiler-typescript.cjs +2 -0
  107. package/internal/config-spec.js +83 -27
  108. package/internal/cordis-tools-owner.js +130 -21
  109. package/internal/diagnostic.js +27 -1
  110. package/internal/direct-surface-owner.js +76 -23
  111. package/internal/dynamic-binding-evidence.js +16 -0
  112. package/internal/dynamic-environment-compiler.js +779 -0
  113. package/internal/dynamic-environment-integration.js +87 -0
  114. package/internal/dynamic-environment-runtime.js +362 -0
  115. package/internal/dynamic-native-calls.js +150 -0
  116. package/internal/dynamic-native-runtime.js +248 -0
  117. package/internal/dynamic-scope-analysis.js +90 -0
  118. package/internal/edit-transport-owner.js +27 -2
  119. package/internal/execution-seam-compat.js +193 -0
  120. package/internal/failure-reporting.js +118 -18
  121. package/internal/host-rpc.js +66 -0
  122. package/internal/isolated-worker.js +548 -0
  123. package/internal/kernel-child.js +139 -0
  124. package/internal/kernel-worker.js +904 -120
  125. package/internal/language-semantics.js +14 -0
  126. package/internal/legacy-binding-catalog.js +48 -0
  127. package/internal/legacy-cell-analysis.js +600 -0
  128. package/internal/legacy-cell-parser.js +50 -0
  129. package/internal/legacy-cell-rewriter.js +631 -0
  130. package/internal/legacy-repl-convenience.js +291 -0
  131. package/internal/managed-module-operations.js +170 -0
  132. package/internal/module-compilation.js +321 -0
  133. package/internal/module-runtime-platform.js +19 -0
  134. package/internal/module-transform-contract.js +12 -0
  135. package/internal/native-await-declarations.js +68 -0
  136. package/internal/native-root-compilation.js +54 -0
  137. package/internal/native-root-dynamic.js +67 -0
  138. package/internal/recovery-tips.js +27 -15
  139. package/internal/rejected-cell-editor.js +13 -8
  140. package/internal/repl-convenience.js +2 -289
  141. package/internal/repl-memory-projection.js +81 -12
  142. package/internal/repl-observation-interest.js +70 -0
  143. package/internal/repl-rewrite-contract.js +6 -0
  144. package/internal/repl-scope-normalizer.js +2091 -0
  145. package/internal/repl-value-observer.js +114 -0
  146. package/internal/rpc-contract.js +52 -0
  147. package/internal/runtime-bridge-owner.js +172 -28
  148. package/internal/runtime-config.js +48 -52
  149. package/internal/runtime-contexts.js +82 -10
  150. package/internal/runtime-messages.js +111 -0
  151. package/internal/session-cell-executor.js +401 -87
  152. package/internal/session-journal-recovery.js +684 -0
  153. package/internal/session-journal-schema.js +106 -0
  154. package/internal/session-journal.js +184 -654
  155. package/internal/session-log-view.js +42 -9
  156. package/internal/session-runtime.js +256 -95
  157. package/internal/session-state.js +247 -71
  158. package/internal/source-position-map.js +211 -71
  159. package/internal/stateful-module-compiler.js +154 -0
  160. package/internal/stateful-module-runtime.js +303 -0
  161. package/internal/stateful-root-compiler.js +598 -0
  162. package/internal/stateful-root-runtime.js +340 -0
  163. package/internal/typert-codec-compat.js +28 -0
  164. package/internal/typescript-transform.js +29 -0
  165. package/internal/user-binding-authoring.js +70 -0
  166. package/internal/user-binding-console-worker.js +184 -0
  167. package/internal/user-binding-console.js +148 -0
  168. package/internal/user-binding-draft-projection.js +335 -0
  169. package/internal/user-binding-model-context.js +31 -0
  170. package/internal/user-binding-runner.js +56 -0
  171. package/internal/user-bindings-owner.js +1065 -0
  172. package/internal/user-bindings-store.js +293 -0
  173. package/internal/user-bindings.js +353 -0
  174. package/internal/value-wire-schema.js +28 -0
  175. package/internal/value-wire.js +29 -20
  176. package/internal/worker-client.js +57 -67
  177. package/internal/worker-environment.js +45 -0
  178. package/internal/worker-output-relay.js +29 -0
  179. package/internal/worker-shutdown.js +14 -0
  180. package/package.json +75 -7
  181. package/src/client-activity.js +88 -53
  182. package/src/client-authoring-view.js +580 -0
  183. package/src/client-binding-review.js +230 -0
  184. package/src/client-bindings-data.js +29 -0
  185. package/src/client-catalog.js +127 -0
  186. package/src/client-code-editor.js +84 -0
  187. package/src/client-console.js +112 -0
  188. package/src/client-copy.js +370 -0
  189. package/src/client-feature-gates.js +62 -0
  190. package/src/client-host-compat.js +150 -0
  191. package/src/client-indicator-view.js +267 -0
  192. package/src/client-repl-view.js +292 -0
  193. package/src/client-rpc.js +20 -0
  194. package/src/client-settings-view.js +221 -0
  195. package/src/client-styles.js +106 -0
  196. package/src/client-tool-view.js +108 -0
  197. package/src/client-transport.js +159 -0
  198. package/src/client-workbench.js +521 -0
  199. package/src/client.js +233 -615
@@ -0,0 +1,64 @@
1
+ # Global binding guide
2
+
3
+ [简体中文](user-bindings.md) · English
4
+
5
+ Global bindings save reusable TypeScript helpers for use across sessions. For example, a binding named `textTools` lets the model call `textTools.clean(text)` inside `run_code`.
6
+
7
+ ## Create and use a binding
8
+
9
+ 1. Open PTC Plus settings (when the sparkle shortcut is already present, choose **PTC Plus settings** from its menu; the host's native entry is the plugin's **Configure** on the current DSH side-bar **Plugins** page, or **Settings → Plugin configuration → PTC Plus** on the preceding DSH) and enable **Global User Bindings**.
10
+ 2. In a PTC session, open the sparkle menu by the composer and choose **Write a new binding**, or enter `/binding new <requirement>`.
11
+ 3. Inspect the draft's source, interface, and model prompt in the panel above the composer.
12
+ 4. Choose **Save and enable**. Subsequent `run_code` calls load the binding; initialization failures appear in execution results.
13
+
14
+ During authoring, the Agent starts with a small in-memory check of the core behavior, then adds normal, edge, and failure assertions with `node:assert/strict`. Bulk tests report totals and a few representative failures instead of printing every successful case into the context. Tests must not modify external files or services. File and network helpers use in-memory substitutes to verify argument forwarding and error propagation; the answer identifies integration behavior that remains untested. Submission delivers a draft for your review. You decide whether to save and enable it.
15
+
16
+ To revise a saved binding, use `/binding edit <id> <requirement>`. Its storage `id`, shown in the workbench, may differ from its call name. You can also select the Agent editing action from the binding list.
17
+
18
+ ## Draft panel
19
+
20
+ A new draft opens above the composer. Click the title bar or use Enter/Space to collapse and expand it. Long content scrolls inside the panel.
21
+
22
+ - **Save as disabled**: keep the entry in the global list without loading it.
23
+ - **Save and enable**: save it and allow subsequent calls to load it.
24
+ - **Discard draft**: abandon this unsaved candidate.
25
+ - **Close panel**: hide it without saving or discarding.
26
+
27
+ The sparkle button shows a PTC Plus tooltip on hover or focus that names it as the Global User Binding entry; a pending draft changes the tooltip to the draft state. The button shows a badge for pending drafts. Open its menu by hovering, clicking, or using the keyboard, then select the draft to show it again. Each session retains one current candidate. A confirmed save or discard closes the panel; failures leave the draft available for retry.
28
+
29
+ The sparkle menu is available before the first message, and opens once the pointer dwells on the entry: crossing the composer no longer drops a menu over it. A hovered menu closes as soon as the pointer leaves it; clicking keeps it open until you click again, click elsewhere, or press Escape. Global bindings show their names, purposes, and enabled states using text and a checkmark. Click an entry to toggle it for all sessions. The catalog refreshes in the background, and the entries stay usable while it does; toggles are disabled only while saving, and reload after a conflict or failure before trying again. **Manage global bindings** opens the full workbench. **Write a new binding** and **Revise a binding** appear when the authoring command is available; the revision step lists existing entries and prefills `/binding edit <id> `. The reusable REPL binding list shows how many later cells reused each binding, with the total in the section title; the count comes from static references in each later cell's compiled source, and a redeclaration counts as neither a reuse nor a reset of the accumulated count.
30
+
31
+ The original binding request retains its requirement, status, and accepted source in history. Historical inspection does not restore permission to save that draft. When another edit changes the catalog, reload its current state before deciding whether to save.
32
+
33
+ ## Interface and model prompt
34
+
35
+ Each entry has two independent settings:
36
+
37
+ | Setting | Purpose |
38
+ | --- | --- |
39
+ | Include interface declaration for the model | On by default. Names, parameters, return types, and API comments come from source; no separate declaration is needed |
40
+ | Prompt for the model | Optional. Add usage conditions, input constraints, or examples missing from the types |
41
+
42
+ For example, a size formatter might add: “Input is in bytes; display using IEC units.” Usage already clear from the interface need not be repeated.
43
+
44
+ The model receives one line identifying `run_code` and the updated API reference, followed by entry names, configured prompts and selected interfaces. Ordinary calls do not resend unchanged documentation.
45
+
46
+ Omitting the interface leaves a separate prompt available. Omitting both does not disable execution. Enabled entries are described from the first request in a new session. Saving, enabling, disabling, deleting, or editing an entry updates the next permitted request. DSH runtime-context suppression defers delivery.
47
+
48
+ Changing only the prompt, interface switch, purpose, or top-level display name preserves loaded module state. Changing implementation source, scope, namespace call name, or selected exports reloads the module on subsequent execution.
49
+
50
+ ## Manual management and testing
51
+
52
+ Open **Manage global bindings** in settings or use the session's **REPL** tab. Manual creation, `.ts` import, interface inspection, editing, enablement, and removal are available without an active PTC session.
53
+
54
+ Source must be a TypeScript module with named value exports. Default exports and re-exports are unsupported. `namespace` exposes selected exports under one object; `top-level` exposes them directly. Leaving the export list empty selects all named value exports. Conflicting names are rejected before enablement.
55
+
56
+ The code console runs the entry's unsaved source draft. It supports top-level `await` and retains temporary variables between commands. Its state is separate from the Agent session, but it has the same process permissions: file and network operations you run have real effects. Stopping, resetting, switching entries, or leaving the workbench releases the environment. After source changes, the next execution starts fresh. Ten minutes without execution also releases it while preserving the displayed input and output history.
57
+
58
+ Bindings are stored in `$DSH_HOME/ptc-plus/bindings.json`. Relative imports in binding modules resolve from that file's directory; ordinary session REPL imports resolve from the session's project directory.
59
+
60
+ ## Limits
61
+
62
+ Enabled configuration allows loading but does not guarantee successful initialization. Assigning or redeclaring a same-name variable can override the global default in the current session without modifying its saved entry.
63
+
64
+ Restart recovery retains only verifiable session state. External files and services may have changed. Recovery does not repeat historical tool operations; diagnostics identify state that could not be recovered. See the [runtime reference](runtime-reference.md#global-user-bindings) for source formats, resource limits, and recovery, and [Client UI](client-ui.md) for workbench details.
@@ -0,0 +1,64 @@
1
+ # 全局绑定使用指南
2
+
3
+ 简体中文 · [English](user-bindings.en.md)
4
+
5
+ 全局绑定把常用 TypeScript helper 保存下来,供多个会话复用。例如,保存名为 `textTools` 的绑定后,模型可以在 `run_code` 中调用 `textTools.clean(text)`。
6
+
7
+ ## 创建和使用
8
+
9
+ 1. 打开 PTC Plus 设置(已有星光入口时可直接选择菜单中的 **PTC Plus 设置**;宿主原生入口在当前 DSH 为侧栏 **Plugins** 页面里本插件的 **Configure**,旧版 DSH 为 **设置 → 插件配置 → PTC Plus**),开启“全局用户绑定”。
10
+ 2. 在 PTC 会话中打开输入框星光按钮的菜单,选择“编写新绑定”,或输入 `/binding new <需求>`。
11
+ 3. 等待 Agent 提交草稿,在输入框上方检查源码、接口和给模型的提示词。
12
+ 4. 选择“保存并启用”。后续 `run_code` 会加载该绑定;如果初始化失败,执行结果会说明原因。
13
+
14
+ 编写过程中,Agent 会先用小型内存样例验证核心行为,再用 `node:assert/strict` 补充正常、边界和失败断言。批量测试只报告总数和少量代表性失败,避免把每个成功样例写入上下文。测试不得修改外部文件或服务;文件和网络 helper 可以用内存替代对象验证参数转发与错误传播,未实际验证的集成部分应在回答中说明。提交草稿只交给你审阅,保存与启用由你决定。
15
+
16
+ 编辑已有绑定可用 `/binding edit <id> <需求>`。`id` 是管理工作台中的存储标识,不一定与调用名称相同;也可以在绑定清单中选择 Agent 编辑入口。
17
+
18
+ ## 草稿面板
19
+
20
+ 新草稿自动在输入框上方展开。点击标题栏或使用 Enter/Space 折叠、展开;长内容可在面板内滚动。
21
+
22
+ - **保存为停用**:保存到全局列表,暂不加载。
23
+ - **保存并启用**:保存并允许后续调用加载。
24
+ - **丢弃草稿**:放弃这份未保存候选。
25
+ - **关闭面板**:只隐藏面板,不保存或丢弃。
26
+
27
+ 输入框星光按钮显示待处理草稿的角标。悬停、点击或键盘打开菜单后,选择草稿即可重新显示。每个会话保留一份当前候选。保存或丢弃确认成功后面板关闭;失败时保留草稿供重试。
28
+
29
+ 星光按钮悬浮或聚焦时显示 PTC Plus 提示,说明它是全局用户绑定入口;有待处理草稿时改为提示草稿状态。星光菜单在首条消息发出前即可使用,鼠标停留一下才展开,扫过输入区不会弹出。悬停打开后鼠标移开菜单即自动关闭;点击可让菜单保持常开,再点一次、点击别处或按 Escape 关闭。全局绑定按名称和用途列出,选中标记与文字表示启用状态;点击条目切换启停,配置对所有会话生效。目录在后台刷新,刷新期间沿用上一次的列表并可以继续操作;保存期间暂时禁用切换,发生冲突或失败时可重新加载后再操作。“管理全局绑定”打开完整工作台;编写命令可用时显示“编写新绑定”和“修改绑定”,“修改绑定”第二步从已有条目中选择后预填 `/binding edit <id> `。REPL 可复用绑定列表会显示每项被后续 cell 复用的次数,并在区块标题显示总复用次数;次数按后续 cell 编译后源码中的静态引用统计,重定义或重声明本身不算一次复用,也不会把已累计的次数清零。
30
+
31
+ 历史中的“绑定编写”请求保留需求、状态和接受时的源码。它供查看当时内容,不重新获得保存资格。目录发生并发修改时,重新加载最新状态后再决定是否保存。
32
+
33
+ ## 接口和给模型的提示词
34
+
35
+ 每个条目有两个独立设置:
36
+
37
+ | 设置 | 用途 |
38
+ | --- | --- |
39
+ | 将接口声明提供给模型 | 默认开启。从源码生成名称、参数、返回类型和 API 注释,无需另写声明 |
40
+ | 给模型的提示词 | 可留空。补充类型未表达的使用时机、输入约束或示例 |
41
+
42
+ 例如,一个接受字节数的格式化函数可补充:“输入单位为字节,显示时使用 IEC 单位。”函数签名已经清楚的用法无需再写一遍。
43
+
44
+ 模型收到一行 `run_code` 调用位置和接口参考文档更新说明,以及各条目的名称、已配置提示词和所选接口。内容未变时不会因普通调用重复发送。
45
+
46
+ 关闭接口展示不会关闭独立提示词;两者都省略也不会禁用绑定执行。已启用条目的说明在新会话首轮提供,中途保存、启停、删除或修改后在下一次允许的请求中更新。若 DSH 暂停运行时上下文投递,更新会暂缓。
47
+
48
+ 仅修改提示词、声明开关、用途说明或 top-level 显示名会保留已加载模块状态。修改实现源码、scope、namespace 调用名或导出列表会在后续执行时重新加载。
49
+
50
+ ## 手动管理和试运行
51
+
52
+ 从设置中的“管理全局绑定”或会话 **REPL** 页签打开工作台。没有当前 PTC 会话也可以手动创建、导入 `.ts`、检查声明、编辑、启停或删除绑定。
53
+
54
+ 源码必须是带具名值导出的 TypeScript 模块,不支持默认导出或转出其他模块的导出。`namespace` 将选中导出放在一个对象下;`top-level` 直接暴露选中导出。导出列表留空时使用全部具名值导出。名称冲突会在启用前被拒绝。
55
+
56
+ 代码控制台运行当前条目的未保存草稿,支持顶层 `await`,并在连续输入之间保留临时变量。它与 Agent 会话的变量分开,但拥有相同的进程权限;你手动执行的文件、网络等操作会产生真实效果。停止、重置、切换条目或离开工作台会释放环境;源码修改后的下一次运行重新开始。连续十分钟不运行代码也会释放环境,界面中的输入输出记录仍保留。
57
+
58
+ 绑定保存在 `$DSH_HOME/ptc-plus/bindings.json`。条目源码中的相对 import 从该文件所在目录解析,普通会话 REPL 的 import 则从会话项目目录解析。
59
+
60
+ ## 使用限制
61
+
62
+ 已启用表示绑定配置允许加载,不保证每次初始化都成功。当前会话中同名变量的赋值或重声明可以覆盖全局默认值,不会修改保存的条目。
63
+
64
+ 重启后只能恢复可验证的会话状态,不能保证外部文件或服务仍与历史执行时相同。恢复不会重发历史工具操作;无法恢复的部分通过诊断说明。源码格式、资源上限和恢复机制见[运行时参考](runtime-reference.md#global-user-bindings);工作台详细交互见[客户端 UI](client-ui.md)。
@@ -7,7 +7,7 @@ PTC runtime value、持久 wire 与模型文本是三个不同契约:
7
7
  ```text
8
8
  JavaScript value
9
9
  -> ptc-value-graph/v1 envelope worker IPC / journal / replay identity
10
- -> structured JSON or TS-like text outer CodeRuntime projection
10
+ -> structured JSON or TS-like text outer execution-seam projection
11
11
  ```
12
12
 
13
13
  wire 从不使用 `eval` 或 `Function` 解码,模型文本也从不作为可执行序列化读取。
@@ -44,10 +44,10 @@ graph 发现顺序与 ECMAScript own-key 顺序共同确定唯一编码。plain
44
44
 
45
45
  worker completion 显式携带 `hasValue`,协议字段缺失不能与已编码的 JavaScript `undefined` 混淆。显式 `return undefined` 有值;自然无输出的声明 cell 仍保持无值。
46
46
 
47
- DSH 的公共 `CodeRuntime`/tool output 只接受 JSON-safe structured value。为保持社区插件边界:
47
+ DSH 的公共执行缝/tool output 只接受 JSON-safe structured value。为保持社区插件边界:
48
48
 
49
49
  - dense、无 shared identity 的 plain JSON tree 继续作为 structured result 返回;
50
- - 包含 `undefined`、special number、BigInt、hole、shared identity 或 cycle 的合法 PTC value 使用确定性、有 byte ceiling 的 TS-like renderer,作为 string result 进入外层 CodeRuntime;
50
+ - 包含 `undefined`、special number、BigInt、hole、shared identity 或 cycle 的合法 PTC value 使用确定性、有 byte ceiling 的 TS-like renderer,作为 string result 进入外层执行缝;
51
51
  - 外层投影是 untagged overlapping union:plain JSON 根值本身也可以是 string,调用方不能用 `typeof value === "string"` 判断是否经过 renderer;
52
52
  - renderer 只是模型展示,不参与 hydrate;需要继续计算时应保留 live REPL binding;
53
53
  - journal 保存 canonical graph envelope,不保存 renderer 反解析结果,也不把 decoded rich value 交给外层 `JSON.stringify`。
@@ -0,0 +1,57 @@
1
+ # Deterministic verification
2
+
3
+ `npm run check` runs `npm run verify`, checks that the source tree and review ledger did not change, and records the verified tree for the commit hook. Run `check` alone when the ledger is absent or resolved; running `verify` immediately before it repeats the full suite. While the ledger has unresolved findings, use `npm run verify` to collect verification evidence.
4
+
5
+ Both commands validate the ledger, compare generated bundles, check syntax, run Client tests, and run all backend tests with coverage. Backend test files run in separate Node processes. The default process count is half the available CPUs, rounded down and bounded between one and four; each process can also own runtime Workers. Tests within each file retain their existing ordering. Coverage still requires 100% lines and functions and at least 95% branches, including compiler source remapping.
6
+
7
+ Source fingerprints use Git with temporary administrative files, an index and an object directory. Configuration includes and repository attributes preserve canonical content, and newly computed objects stay in the temporary directory. One tagged file inventory identifies tracked, missing, untracked and sparse entries without repeatedly starting Git for each category. The temporary files are written directly, avoiding repeated Git initialization and configuration processes; explicit Git command arguments preserve isolation across Windows/WSL command forwarders.
8
+
9
+ Set `DSH_PTC_TEST_CONCURRENCY` to a positive integer to override the backend process count. Use `1` for serial diagnosis or when CPU/memory contention affects timing-sensitive tests. This changes scheduling, not runtime compute budgets, test selection, or coverage thresholds. For example:
10
+
11
+ ```bash
12
+ DSH_PTC_TEST_CONCURRENCY=1 npm run verify
13
+ ```
14
+
15
+ ```powershell
16
+ $env:DSH_PTC_TEST_CONCURRENCY = '1'
17
+ npm run verify
18
+ Remove-Item Env:DSH_PTC_TEST_CONCURRENCY
19
+ ```
20
+
21
+ Coverage runs additionally set `DSH_PTC_TEST_WORKER_COVERAGE=1` and load `scripts/instrument-worker-coverage.mjs` through Node's `--import`; that test-only seam adds the coverage variable to the helper's inner-Worker launch environment so real kernel, console, and candidate worker branches are measured. Production never sets the marker and continues to project `NODE_V8_COVERAGE` out of the user Worker environment. Because some transport tests install module mocks before importing the real transport, the runner executes two backend groups into the same coverage directory: the mock-dependent files run without the preload, and the remaining files run with it. Each group writes its own `run-*-mock.tap` or `run-*-instrumented.tap` diagnostic, both managed by the same retention and cleanup lifecycle. Test arguments such as `--test-name-pattern` are placed before the selected file list so Node applies them to test selection rather than treating them as file inputs.
22
+
23
+ `npm run coverage` uses the same scheduling and prints test and total elapsed time. Each invocation collects worker coverage in its own temporary directory under `coverage/`, removed after c8 finishes reporting, so simultaneous runs cannot erase or combine each other's evidence. The default report is printed to the terminal. A separate `coverage/run-*.tap` log retains Node's test diagnostics, including process exit codes and signals that the concise terminal reporter can omit. An explicit Node test reporter option replaces these default reporters. Source changes during verification still invalidate a `check` proof; separate coverage directories do not make concurrent source edits safe.
24
+
25
+ Windows Node 24 and 26 reproductions and stacks identify a cppgc finalizer (`node::contextify::ContextifyScript`, or `ContextifyContext` when coverage was enabled) running after the environment that owned its private realm was gone, which wrote through a dangling `node::Realm` during isolate teardown. The reproduction ended the whole DSH process when an in-host session worker was terminated; macOS runners also observed whole-file aborts under coverage, but the available evidence does not establish that those aborts came from the same Windows stack or that the same cause applies across platforms. The session kernel now runs in a plugin-owned helper process (`internal/kernel-child.js`); `IsolatedWorker` sends a cooperative shutdown and, if the helper does not leave within its bound, kills only that helper. DSH is no longer the worker-teardown target on any supported host, so a wedged kernel is contained as a helper failure rather than a host-native crash. `.github/workflows/ci.yml` sets `DSH_PTC_TEST_CONCURRENCY: 1` and runs `npm run check` once; the former file-level retry wrapper is gone, and any failing test or file-level abort fails that run. This boundary removes the plugin's in-host kill exposure; it neither repairs the upstream Node path nor proves the macOS abort shared the Windows cause.
26
+
27
+ Native oracle workers and external Windows command fixtures explicitly disable inherited `NODE_V8_COVERAGE`; they execute no code included by the plugin coverage gate. Subprocesses testing plugin implementations still collect coverage. PowerShell semantic-version observations share one invocation, and Windows registry fixtures read the three effective registry values with one real npm configuration query. Each retains its original inputs and assertions.
28
+
29
+ The reporting adapter filters script records before c8 merges them. It reads source-map metadata once per input file, retains maps that lead to selected original sources, and leaves unknown or malformed maps to c8. Dependency-only compiler artifacts can be excluded before remapping; mixed compiler bundles retain their original coverage records. c8 still owns merging, remapping, counters, reporting and threshold checks. This uses an isolated adapter for c8's normalization method; dependency upgrades must pass the comparison with ordinary c8, including uncovered counters and mapped sources. The raw V8 reports are not rewritten.
30
+
31
+ Runtime Workers defer parsing the compiler bundle until their first compiler operation. Ordinary cells already prepared by the host avoid that startup work. Once an uninstrumented host has initialized its compiler, it snapshots V8 compiler bytecode for subsequent session kernel Workers. Coverage runs prepare that snapshot once in a separate uninstrumented process and pass its temporary file through `DSH_PTC_COMPILER_BYTECODE`; instrumented compiler instances neither produce nor consume bytecode. The runner owns this variable and removes the file after the tests. Workers receive private bytes through their initialization data and do not inherit the temporary file setting.
32
+
33
+ A Worker uses a snapshot only when its complete compiler source matches; V8 checks bytecode compatibility and recompiles when it rejects the snapshot. Workers still initialize independent compiler realms and session state. The host retains one snapshot in memory, and each Worker discards its private copy after consumption; bytecode contains no saved program values. The bundle source, VM constructor and options are captured or isolated from source-owned mutations before execution.
34
+
35
+ Repeated Global User Binding validation reuses export descriptions and durability analysis inside the private compiler realm. Each cache keys the complete source and transform generation, retains at most 64 entries and 512 Ki characters of serialized keys, and returns fresh data to its caller. Snapshot fields, fingerprints and publication evidence still undergo validation on each request. This cache contains source-derived metadata, never executed values or module state, and is rebuilt for every compiler realm.
36
+
37
+ Cell preparation carries its successful native JavaScript parse proof into scope normalization, as module preparation already does. Decorator and resource transforms consume their feature scan's existing syntax tree through Babel's AST API. Recovered invalid decorator input retains the original parser diagnostic path. Intrinsic binding skips its source scan when the compiler recorded no bindings to replace. These changes remove repeated preparation work without changing execution budgets or coverage collection.
38
+
39
+ Nested callable reflection reuses completed ordinary function recipes inside enclosing recipes. A source-position index selects the outermost reusable descendants, and syntax inspection skips their complete AST subtrees. Each reused function already contains its generated helper dependencies; class and method definition recipes keep their separate lowering paths. If all non-native syntax is inside those substituted functions, the surrounding recipe needs no additional type-erasure pass. Enclosing type syntax and resource declarations still undergo their own lowering. Callable marker emission uses cumulative edit offsets and binary searches to retain exact source boundaries without rescanning all edits for each mapping point. Declaration analysis groups at most 64 declarations into each shared ancestry witness, so Babel assigns ownership without repeatedly walking the same ancestors or retaining a full expression graph.
40
+
41
+ Dynamic eval and Function preparation reuse source-derived compilation results within their private compiler realm. The key includes the complete source and syntax options. Every hit rechecks the original-source facts consulted by that compilation; a changed fact requires compilation again. The cache holds at most 64 entries and 2 Mi characters of serialized keys, results and source facts. Callers receive fresh metadata, and each execution still declares its variables and creates a new activation against the current environment. Cell operation plans remain with their existing compiler owner.
42
+
43
+ Optional-chain transforms allocate temporary names through the complete compilation unit's allocator. A scoped Babel adapter retains Babel's UID reservations and restores its original method when the transform completes or throws. This avoids a subsequent whole-scope rename for every generated temporary while preserving uniqueness across module regions.
44
+
45
+ Callable catalogs compress windows containing referenced source ranges. Ranges separated by at most one source block share a window, preserving compression across nearby functions; large unreferenced gaps and unused buffers are omitted. Empty catalogs retain no source buffers. Entries keep their registration order and exact UTF-16 text in the existing catalog format.
46
+
47
+ Cell preparation traverses parsed trees and edit mappings without allocating a
48
+ temporary object per unit of work. The namespace walk reads a node's own keys
49
+ once and indexes node arrays directly instead of materializing an entry pair
50
+ per property; the source-map builder validates and writes its four offsets
51
+ positionally, and replacement runs reach that builder through a direct emitter
52
+ instead of a generator and a per-run segment object. Rehomed compiler messages
53
+ write their owned data descriptor directly rather than copying a generic
54
+ descriptor first. Every one of these paths produced identical output before and
55
+ after the change; only the immediately discarded allocations are gone.
56
+
57
+ For focused diagnostics, use `npm run test:client`, `npm run test:semantics`, or Node's test runner with selected test files. These do not replace the final complete command. Model-backed evaluation remains separate and opt-in; see [Evaluation](evaluation.md).