dsh-ptc-plus 0.3.2 → 0.4.2

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 (206) hide show
  1. package/README.en.md +63 -80
  2. package/README.md +63 -80
  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 +30827 -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 +556 -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 +7 -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 +77 -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 +28 -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 +76 -25
  56. package/docs/semantic-validation.md +29 -0
  57. package/docs/stateful-binding-updates-proposal.md +759 -0
  58. package/docs/user-bindings.en.md +66 -0
  59. package/docs/user-bindings.md +66 -0
  60. package/docs/value-wire.md +3 -3
  61. package/docs/verification-optimization-work.md +41 -0
  62. package/docs/verification.md +71 -0
  63. package/index.js +369 -92
  64. package/internal/ast-traversal.js +5 -2
  65. package/internal/async-local-storage-intrinsics.js +38 -0
  66. package/internal/binding-declaration-contract.js +8 -0
  67. package/internal/binding-descriptors.js +1 -0
  68. package/internal/binding-pattern-traversal.js +25 -0
  69. package/internal/binding-pattern.js +26 -29
  70. package/internal/binding-source-analysis.js +708 -0
  71. package/internal/binding-update-policy.js +72 -0
  72. package/internal/bounded-worker-round.js +56 -0
  73. package/internal/callable-definition-environment.js +42 -0
  74. package/internal/callable-source-catalog.js +129 -0
  75. package/internal/callable-source-encoding.js +47 -0
  76. package/internal/callable-source-facts.js +459 -0
  77. package/internal/callable-source-format.js +2 -0
  78. package/internal/callable-source-lowering.js +123 -0
  79. package/internal/cell-analysis-contract.js +25 -0
  80. package/internal/cell-analysis.js +253 -290
  81. package/internal/cell-completion.js +15 -0
  82. package/internal/cell-error.js +7 -0
  83. package/internal/cell-parser.js +66 -0
  84. package/internal/cell-rewriter.js +3 -677
  85. package/internal/commonjs-export-evidence.js +63 -0
  86. package/internal/commonjs-source-evidence.js +72 -0
  87. package/internal/compiler-amaro.cjs +2 -0
  88. package/internal/compiler-compression.js +12 -0
  89. package/internal/compiler-data.js +58 -0
  90. package/internal/compiler-descriptors.js +54 -0
  91. package/internal/compiler-dynamic-cache.js +48 -0
  92. package/internal/compiler-entry.js +35 -0
  93. package/internal/compiler-generated-names.js +17 -0
  94. package/internal/compiler-intrinsics.js +50 -0
  95. package/internal/compiler-module-links.js +37 -0
  96. package/internal/compiler-operations.js +61 -0
  97. package/internal/compiler-platform-factory.js +84 -0
  98. package/internal/compiler-platform.js +136 -0
  99. package/internal/compiler-record-roles.js +53 -0
  100. package/internal/compiler-region-output.js +259 -0
  101. package/internal/compiler-resource-lowering.js +103 -0
  102. package/internal/compiler-scope-facts.js +115 -0
  103. package/internal/compiler-service.js +109 -0
  104. package/internal/compiler-source-cache.js +32 -0
  105. package/internal/compiler-source-pieces.js +93 -0
  106. package/internal/compiler-source-regions.js +132 -0
  107. package/internal/compiler-storage-source.js +54 -0
  108. package/internal/compiler-text.js +15 -0
  109. package/internal/compiler-typescript.cjs +2 -0
  110. package/internal/config-spec.js +83 -27
  111. package/internal/cordis-tools-owner.js +130 -21
  112. package/internal/diagnostic.js +27 -1
  113. package/internal/direct-surface-owner.js +76 -23
  114. package/internal/dynamic-binding-evidence.js +16 -0
  115. package/internal/dynamic-environment-compiler.js +779 -0
  116. package/internal/dynamic-environment-integration.js +91 -0
  117. package/internal/dynamic-environment-runtime.js +383 -0
  118. package/internal/dynamic-native-calls.js +153 -0
  119. package/internal/dynamic-native-runtime.js +262 -0
  120. package/internal/dynamic-scope-analysis.js +90 -0
  121. package/internal/edit-transport-owner.js +27 -2
  122. package/internal/execution-seam-compat.js +193 -0
  123. package/internal/failure-reporting.js +136 -28
  124. package/internal/host-rpc.js +66 -0
  125. package/internal/isolated-worker.js +555 -0
  126. package/internal/kernel-child.js +139 -0
  127. package/internal/kernel-worker.js +1179 -233
  128. package/internal/language-semantics.js +14 -0
  129. package/internal/legacy-binding-catalog.js +48 -0
  130. package/internal/legacy-cell-analysis.js +600 -0
  131. package/internal/legacy-cell-parser.js +50 -0
  132. package/internal/legacy-cell-rewriter.js +631 -0
  133. package/internal/legacy-repl-convenience.js +291 -0
  134. package/internal/managed-module-operations.js +170 -0
  135. package/internal/module-compilation.js +322 -0
  136. package/internal/module-runtime-platform.js +19 -0
  137. package/internal/module-transform-contract.js +42 -0
  138. package/internal/native-await-declarations.js +68 -0
  139. package/internal/native-root-compilation.js +54 -0
  140. package/internal/native-root-dynamic.js +67 -0
  141. package/internal/record-utils.js +24 -15
  142. package/internal/recovery-tips.js +27 -15
  143. package/internal/rejected-cell-editor.js +13 -8
  144. package/internal/repl-convenience.js +2 -289
  145. package/internal/repl-memory-projection.js +81 -12
  146. package/internal/repl-observation-interest.js +70 -0
  147. package/internal/repl-rewrite-contract.js +6 -0
  148. package/internal/repl-scope-normalizer.js +2091 -0
  149. package/internal/repl-value-observer.js +117 -0
  150. package/internal/rpc-contract.js +52 -0
  151. package/internal/runtime-bridge-owner.js +172 -28
  152. package/internal/runtime-config.js +48 -52
  153. package/internal/runtime-contexts.js +82 -10
  154. package/internal/runtime-intrinsics.js +101 -0
  155. package/internal/runtime-messages.js +111 -0
  156. package/internal/session-cell-executor.js +402 -87
  157. package/internal/session-journal-recovery.js +684 -0
  158. package/internal/session-journal-schema.js +123 -0
  159. package/internal/session-journal.js +199 -654
  160. package/internal/session-log-view.js +42 -9
  161. package/internal/session-runtime.js +257 -95
  162. package/internal/session-state.js +247 -71
  163. package/internal/source-position-map.js +230 -71
  164. package/internal/stateful-module-compiler.js +154 -0
  165. package/internal/stateful-module-runtime.js +303 -0
  166. package/internal/stateful-root-compiler.js +600 -0
  167. package/internal/stateful-root-runtime.js +340 -0
  168. package/internal/typert-codec-compat.js +28 -0
  169. package/internal/typescript-transform.js +31 -0
  170. package/internal/user-binding-authoring.js +70 -0
  171. package/internal/user-binding-console-worker.js +244 -0
  172. package/internal/user-binding-console.js +148 -0
  173. package/internal/user-binding-draft-projection.js +335 -0
  174. package/internal/user-binding-model-context.js +31 -0
  175. package/internal/user-binding-runner.js +56 -0
  176. package/internal/user-bindings-owner.js +1065 -0
  177. package/internal/user-bindings-store.js +293 -0
  178. package/internal/user-bindings.js +361 -0
  179. package/internal/value-wire-schema.js +28 -0
  180. package/internal/value-wire.js +130 -91
  181. package/internal/worker-client.js +57 -67
  182. package/internal/worker-cwd-virtualization.js +80 -53
  183. package/internal/worker-environment.js +65 -0
  184. package/internal/worker-output-relay.js +29 -0
  185. package/internal/worker-repl-realm.js +134 -0
  186. package/internal/worker-shutdown.js +14 -0
  187. package/package.json +76 -7
  188. package/src/client-activity.js +95 -53
  189. package/src/client-authoring-view.js +580 -0
  190. package/src/client-binding-review.js +230 -0
  191. package/src/client-bindings-data.js +29 -0
  192. package/src/client-catalog.js +127 -0
  193. package/src/client-code-editor.js +84 -0
  194. package/src/client-console.js +112 -0
  195. package/src/client-copy.js +370 -0
  196. package/src/client-feature-gates.js +62 -0
  197. package/src/client-host-compat.js +150 -0
  198. package/src/client-indicator-view.js +267 -0
  199. package/src/client-repl-view.js +292 -0
  200. package/src/client-rpc.js +20 -0
  201. package/src/client-settings-view.js +221 -0
  202. package/src/client-styles.js +106 -0
  203. package/src/client-tool-view.js +108 -0
  204. package/src/client-transport.js +159 -0
  205. package/src/client-workbench.js +521 -0
  206. package/src/client.js +233 -615
@@ -0,0 +1,123 @@
1
+ import {
2
+ LEGACY_DEFAULT_EXPORT_BINDING,
3
+ LIVE_DEFAULT_EXPORT_BINDING,
4
+ LEGACY_IMPORT_EXPRESSION_BOUNDARY,
5
+ LIVE_IMPORT_EXPRESSION_BOUNDARY,
6
+ } from './repl-rewrite-contract.js'
7
+
8
+ export const JOURNAL_KEY = 'dshPtcPlus'
9
+ export const EDIT_TARGET_KEY = 'dshPtcPlusEdit'
10
+ export const DERIVED_RUN_KEY = 'dshPtcPlusDerivedRun'
11
+ export const REWRITES_KEY = 'dshPtcPlusRewrites'
12
+ export const RECOVERY_BOUNDARY_KEY = 'dshPtcPlusRecoveryBoundaries'
13
+ export const IMPORT_BOUNDARY_JOURNAL_VERSION = 7
14
+ export const PER_NAME_USER_BINDINGS_JOURNAL_VERSION = 8
15
+ export const LANGUAGE_SEMANTICS_JOURNAL_VERSION = 9
16
+ export const MODULE_TRANSFORM_JOURNAL_VERSION = 10
17
+ export const JOURNAL_VERSION = MODULE_TRANSFORM_JOURNAL_VERSION
18
+ export const LIVE_USER_BINDINGS_SHADOW_POLICY = 'per-name'
19
+ export const LEGACY_USER_BINDINGS_SHADOW_POLICY = 'whole-entry'
20
+ export const LIVE_USER_BINDINGS_REUSE_POLICY = 'implementation-v1'
21
+ export const LEGACY_USER_BINDINGS_REUSE_POLICY = 'fingerprint-v1'
22
+ export const LEGACY_JOURNAL_VERSION = 1
23
+ export const INTERMEDIATE_JOURNAL_VERSION = 2
24
+ export const PREVIOUS_JOURNAL_VERSION = 3
25
+ export const USER_BINDING_RELATIONLESS_JOURNAL_VERSION = 4
26
+ export const FINGERPRINT_REUSE_JOURNAL_VERSION = 5
27
+ export const VERSIONED_BINDING_REUSE_JOURNAL_VERSION = 6
28
+ export const RECOVERY_BOUNDARY_EVENT = 'ptc-plus/recovery-boundary'
29
+
30
+ export const STATUSES = new Set(['durable', 'volatile', 'discarded', 'noop'])
31
+ export const BINDING_MODES = new Set(['loose', 'strict'])
32
+ export const WHOLE_ENTRY_JOURNAL_FIELDS = new Set(['version', 'bindingPolicy', 'rewritePolicy', 'moduleSemantics', 'userBindingsFingerprint', 'userBindingsReusePolicy', 'status', 'calls', 'operations', 'confirms', 'diagnostics', 'completion', 'volatileReason'])
33
+ export const PER_NAME_JOURNAL_FIELDS = new Set([...WHOLE_ENTRY_JOURNAL_FIELDS, 'userBindingsShadowPolicy', 'userBindingNames'])
34
+ export const LANGUAGE_SEMANTICS_JOURNAL_FIELDS = new Set([...PER_NAME_JOURNAL_FIELDS, 'languageSemantics'])
35
+ export const JOURNAL_FIELDS = new Set([...LANGUAGE_SEMANTICS_JOURNAL_FIELDS, 'moduleTransform'])
36
+ export const FINGERPRINT_REUSE_JOURNAL_FIELDS = new Set([...WHOLE_ENTRY_JOURNAL_FIELDS].filter(field => field !== 'userBindingsReusePolicy'))
37
+ export const RELATIONLESS_JOURNAL_FIELDS = new Set([...FINGERPRINT_REUSE_JOURNAL_FIELDS].filter(field => field !== 'userBindingsFingerprint'))
38
+ export const PREDECESSOR_JOURNAL_FIELDS = new Set(['version', 'bindingMode', 'rewritePolicy', 'status', 'calls', 'operations', 'confirms', 'diagnostics', 'completion', 'volatileReason'])
39
+ export const LEGACY_JOURNAL_FIELDS = new Set([...PREDECESSOR_JOURNAL_FIELDS].filter(field => field !== 'rewritePolicy'))
40
+ export const BINDING_POLICY_FIELDS = new Set(['variableRedeclarations', 'functionClassRedeclarations'])
41
+ export const REWRITE_POLICY_FIELDS = new Set(['autoRewriteImports', 'autoStripExports', 'autoSplitRedeclarations'])
42
+ export const LEGACY_MODULE_SEMANTICS_FIELDS = new Set(['defaultExportBinding'])
43
+ export const MODULE_SEMANTICS_FIELDS = new Set([...LEGACY_MODULE_SEMANTICS_FIELDS, 'importExpressionBoundary'])
44
+ export const IMPORT_EXPRESSION_BOUNDARIES = new Set([
45
+ LEGACY_IMPORT_EXPRESSION_BOUNDARY,
46
+ LIVE_IMPORT_EXPRESSION_BOUNDARY,
47
+ ])
48
+ export const DEFAULT_EXPORT_BINDINGS = new Set([
49
+ LEGACY_DEFAULT_EXPORT_BINDING,
50
+ LIVE_DEFAULT_EXPORT_BINDING,
51
+ ])
52
+ export const CALL_SUCCESS_FIELDS = new Set(['global', 'member', 'args', 'ok', 'value', 'settle'])
53
+ export const CALL_ERROR_FIELDS = new Set(['global', 'member', 'args', 'ok', 'error', 'settle'])
54
+ export const OPERATION_FIELDS = new Set(['action', 'name'])
55
+ export const RETURN_FIELDS = new Set(['kind', 'hasValue', 'value'])
56
+ export const THROW_FIELDS = new Set(['kind', 'error'])
57
+ export const ERROR_FIELDS = new Set(['kind', 'message'])
58
+ export const EDIT_TARGET_FIELDS = new Set(['targetCallSeq'])
59
+ export const DERIVED_RUN_FIELDS = new Set(['code', 'description'])
60
+
61
+ export const JOURNAL_VERSIONS = new Set([LEGACY_JOURNAL_VERSION, INTERMEDIATE_JOURNAL_VERSION, PREVIOUS_JOURNAL_VERSION, USER_BINDING_RELATIONLESS_JOURNAL_VERSION, FINGERPRINT_REUSE_JOURNAL_VERSION, VERSIONED_BINDING_REUSE_JOURNAL_VERSION, IMPORT_BOUNDARY_JOURNAL_VERSION, PER_NAME_USER_BINDINGS_JOURNAL_VERSION, LANGUAGE_SEMANTICS_JOURNAL_VERSION, JOURNAL_VERSION])
62
+ export const USER_BINDINGS_REUSE_POLICIES = new Set([LEGACY_USER_BINDINGS_REUSE_POLICY, LIVE_USER_BINDINGS_REUSE_POLICY])
63
+ export const USER_BINDINGS_SHADOW_POLICIES = new Set([LEGACY_USER_BINDINGS_SHADOW_POLICY, LIVE_USER_BINDINGS_SHADOW_POLICY])
64
+ const USER_BINDING_NAME_STATES = new Set(['provider', 'local', 'absent', 'unknown'])
65
+ const isArray = Array.isArray
66
+ const freeze = Object.freeze
67
+ const ownKeys = Reflect.ownKeys
68
+ const defineProperty = Object.defineProperty
69
+ const uncurry = Function.prototype.bind.bind(Function.prototype.call)
70
+ const setHas = uncurry(Set.prototype.has)
71
+ const setAdd = uncurry(Set.prototype.add)
72
+ const sort = uncurry(Array.prototype.sort)
73
+ const enumerable = uncurry(Object.prototype.propertyIsEnumerable)
74
+
75
+ /** Closed, value-free evidence shared by worker settlement, persistence and Client. */
76
+ export function normalizeUserBindingNames(value) {
77
+ if (!isArray(value)) throw new TypeError('invalid user binding name evidence')
78
+ const names = new Set()
79
+ const normalized = []
80
+ for (let index = 0; index < value.length; index++) {
81
+ const fact = value[index]
82
+ if (fact === null || typeof fact !== 'object'
83
+ || !setHas(USER_BINDING_NAME_STATES, fact.state)
84
+ || typeof fact.name !== 'string' || fact.name.length > 128
85
+ || !/^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u.test(fact.name)
86
+ || setHas(names, fact.name)) throw new TypeError('invalid user binding name evidence')
87
+ const fields = fact.state === 'provider' ? ['name', 'state', 'entryId'] : ['name', 'state']
88
+ let validFields = ownKeys(fact).length === fields.length
89
+ for (let field = 0; validFields && field < fields.length; field++) validFields = enumerable(fact, fields[field])
90
+ if (!validFields
91
+ || (fact.state === 'provider' && (typeof fact.entryId !== 'string'
92
+ || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(fact.entryId)))) {
93
+ throw new TypeError('invalid user binding name evidence')
94
+ }
95
+ setAdd(names, fact.name)
96
+ defineProperty(normalized, normalized.length, { configurable: true, enumerable: true, writable: true,
97
+ value: freeze({ name: fact.name, state: fact.state,
98
+ ...(fact.state === 'provider' ? { entryId: fact.entryId } : {}) }) })
99
+ }
100
+ sort(normalized, (left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0)
101
+ return freeze(normalized)
102
+ }
103
+
104
+ export function normalizeJournalUserBindingNames(journal) {
105
+ if (!USER_BINDINGS_SHADOW_POLICIES.has(journal.userBindingsShadowPolicy)) {
106
+ throw new TypeError('invalid user binding shadow policy')
107
+ }
108
+ if (journal.userBindingsShadowPolicy === LEGACY_USER_BINDINGS_SHADOW_POLICY
109
+ || journal.status === 'noop' || journal.status === 'discarded') {
110
+ if (journal.userBindingNames !== null) throw new TypeError('unexpected user binding name evidence')
111
+ return null
112
+ }
113
+ return normalizeUserBindingNames(journal.userBindingNames)
114
+ }
115
+ export const RECOVERY_BOUNDARY_FIELDS = new Set(['failedCallSeq', 'frontierCallSeq'])
116
+ export const REPL_TOOL_NAMES = new Set(['run_code', 'edit_run_code'])
117
+ export const REWRITE_FIELDS = new Set(['kind', 'description', 'source'])
118
+ export const REWRITE_KINDS = new Set(['import', 'redeclaration', 'export'])
119
+
120
+ /** Journal v1 uses call IDs; later recognized generations use persisted event sequences. */
121
+ export function usesCallSequenceConfirms(journal) {
122
+ return JOURNAL_VERSIONS.has(journal?.version) && journal.version !== LEGACY_JOURNAL_VERSION
123
+ }