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.
- package/README.en.md +63 -80
- package/README.md +63 -80
- package/assets/ptc-plus-bindings-en.png +0 -0
- package/assets/ptc-plus-bindings-zh.png +0 -0
- package/assets/ptc-plus-repair-en.png +0 -0
- package/assets/ptc-plus-repair-zh.png +0 -0
- package/assets/ptc-plus-repl-workspace-en.png +0 -0
- package/assets/ptc-plus-repl-workspace-zh.png +0 -0
- package/assets/ptc-plus-settings-en.png +0 -0
- package/assets/ptc-plus-settings-zh.png +0 -0
- package/client.js +30827 -742
- package/compiler-amaro.cjs +5 -0
- package/compiler-amaro.cjs.map +6 -0
- package/compiler-asset-124f80c1bba92ff5fe79cfec6e8ad518f476de4a42514cae3919538887f510e8.txt +1 -0
- package/compiler-assets.json +3 -0
- package/compiler-core.cjs +556 -0
- package/compiler-core.cjs.map +6 -0
- package/compiler-platform.cjs +2 -0
- package/compiler-platform.cjs.map +6 -0
- package/compiler-typescript.cjs +388 -0
- package/compiler-typescript.cjs.map +6 -0
- package/docs/README.md +7 -0
- package/docs/adr/0004-declare-program-bindings-at-the-host.md +1 -1
- package/docs/adr/0006-rewrite-module-syntax-with-an-ast.md +5 -3
- package/docs/adr/0007-separate-worker-transport-from-session-semantics.md +1 -1
- package/docs/adr/0009-bound-expensive-acceptance-default.md +2 -0
- package/docs/adr/0010-session-log-derived-recovery-tips.md +59 -5
- package/docs/adr/0011-isolate-the-local-recovery-tip-provider.md +1 -1
- package/docs/adr/0012-preserve-mixed-destructuring-initialization.md +3 -1
- package/docs/adr/0013-isolate-repl-redeclaration-convenience.md +3 -1
- package/docs/adr/0014-persist-cell-rewrite-policy.md +6 -2
- package/docs/adr/0015-preserve-source-positions-through-rewrites.md +1 -1
- package/docs/adr/0016-archive-resolved-review-findings.md +1 -1
- package/docs/adr/0017-track-the-latest-dsh-public-surface.md +49 -0
- package/docs/adr/0018-use-versioned-fixture-for-ab-benchmark.md +3 -3
- package/docs/adr/0019-plugin-settings-and-kill-switch.md +5 -3
- package/docs/adr/0020-optional-cordis-tools-in-ptc-mode.md +2 -2
- package/docs/adr/0021-separate-host-bootstrap-from-session-runtime.md +12 -0
- package/docs/adr/0023-global-user-bindings.md +104 -0
- package/docs/adr/0024-repl-console-observation.md +33 -0
- package/docs/adr/0025-use-versioned-logical-binding-identities.md +119 -0
- package/docs/adr/0026-persist-the-delivery-verdict-against-the-verified-candidate.md +21 -0
- package/docs/adr/0027-run-the-session-kernel-in-a-killable-helper-process.md +37 -0
- package/docs/adr/0028-attach-to-the-host-ptc-execution-seam.md +103 -0
- package/docs/adr/0029-keep-plugin-unavailability-out-of-the-host-agent-lifecycle.md +27 -0
- package/docs/adr/0030-serve-both-typert-codec-generations-from-one-codec.md +27 -0
- package/docs/architecture.md +77 -21
- package/docs/binding-review-placement-design.md +200 -0
- package/docs/capability-projection.md +1 -1
- package/docs/client-ui.md +95 -19
- package/docs/durability-design.md +28 -10
- package/docs/evaluation.md +78 -6
- package/docs/installation.md +41 -6
- package/docs/publishing.md +5 -3
- package/docs/runtime-reference.md +76 -25
- package/docs/semantic-validation.md +29 -0
- package/docs/stateful-binding-updates-proposal.md +759 -0
- package/docs/user-bindings.en.md +66 -0
- package/docs/user-bindings.md +66 -0
- package/docs/value-wire.md +3 -3
- package/docs/verification-optimization-work.md +41 -0
- package/docs/verification.md +71 -0
- package/index.js +369 -92
- package/internal/ast-traversal.js +5 -2
- package/internal/async-local-storage-intrinsics.js +38 -0
- package/internal/binding-declaration-contract.js +8 -0
- package/internal/binding-descriptors.js +1 -0
- package/internal/binding-pattern-traversal.js +25 -0
- package/internal/binding-pattern.js +26 -29
- package/internal/binding-source-analysis.js +708 -0
- package/internal/binding-update-policy.js +72 -0
- package/internal/bounded-worker-round.js +56 -0
- package/internal/callable-definition-environment.js +42 -0
- package/internal/callable-source-catalog.js +129 -0
- package/internal/callable-source-encoding.js +47 -0
- package/internal/callable-source-facts.js +459 -0
- package/internal/callable-source-format.js +2 -0
- package/internal/callable-source-lowering.js +123 -0
- package/internal/cell-analysis-contract.js +25 -0
- package/internal/cell-analysis.js +253 -290
- package/internal/cell-completion.js +15 -0
- package/internal/cell-error.js +7 -0
- package/internal/cell-parser.js +66 -0
- package/internal/cell-rewriter.js +3 -677
- package/internal/commonjs-export-evidence.js +63 -0
- package/internal/commonjs-source-evidence.js +72 -0
- package/internal/compiler-amaro.cjs +2 -0
- package/internal/compiler-compression.js +12 -0
- package/internal/compiler-data.js +58 -0
- package/internal/compiler-descriptors.js +54 -0
- package/internal/compiler-dynamic-cache.js +48 -0
- package/internal/compiler-entry.js +35 -0
- package/internal/compiler-generated-names.js +17 -0
- package/internal/compiler-intrinsics.js +50 -0
- package/internal/compiler-module-links.js +37 -0
- package/internal/compiler-operations.js +61 -0
- package/internal/compiler-platform-factory.js +84 -0
- package/internal/compiler-platform.js +136 -0
- package/internal/compiler-record-roles.js +53 -0
- package/internal/compiler-region-output.js +259 -0
- package/internal/compiler-resource-lowering.js +103 -0
- package/internal/compiler-scope-facts.js +115 -0
- package/internal/compiler-service.js +109 -0
- package/internal/compiler-source-cache.js +32 -0
- package/internal/compiler-source-pieces.js +93 -0
- package/internal/compiler-source-regions.js +132 -0
- package/internal/compiler-storage-source.js +54 -0
- package/internal/compiler-text.js +15 -0
- package/internal/compiler-typescript.cjs +2 -0
- package/internal/config-spec.js +83 -27
- package/internal/cordis-tools-owner.js +130 -21
- package/internal/diagnostic.js +27 -1
- package/internal/direct-surface-owner.js +76 -23
- package/internal/dynamic-binding-evidence.js +16 -0
- package/internal/dynamic-environment-compiler.js +779 -0
- package/internal/dynamic-environment-integration.js +91 -0
- package/internal/dynamic-environment-runtime.js +383 -0
- package/internal/dynamic-native-calls.js +153 -0
- package/internal/dynamic-native-runtime.js +262 -0
- package/internal/dynamic-scope-analysis.js +90 -0
- package/internal/edit-transport-owner.js +27 -2
- package/internal/execution-seam-compat.js +193 -0
- package/internal/failure-reporting.js +136 -28
- package/internal/host-rpc.js +66 -0
- package/internal/isolated-worker.js +555 -0
- package/internal/kernel-child.js +139 -0
- package/internal/kernel-worker.js +1179 -233
- package/internal/language-semantics.js +14 -0
- package/internal/legacy-binding-catalog.js +48 -0
- package/internal/legacy-cell-analysis.js +600 -0
- package/internal/legacy-cell-parser.js +50 -0
- package/internal/legacy-cell-rewriter.js +631 -0
- package/internal/legacy-repl-convenience.js +291 -0
- package/internal/managed-module-operations.js +170 -0
- package/internal/module-compilation.js +322 -0
- package/internal/module-runtime-platform.js +19 -0
- package/internal/module-transform-contract.js +42 -0
- package/internal/native-await-declarations.js +68 -0
- package/internal/native-root-compilation.js +54 -0
- package/internal/native-root-dynamic.js +67 -0
- package/internal/record-utils.js +24 -15
- package/internal/recovery-tips.js +27 -15
- package/internal/rejected-cell-editor.js +13 -8
- package/internal/repl-convenience.js +2 -289
- package/internal/repl-memory-projection.js +81 -12
- package/internal/repl-observation-interest.js +70 -0
- package/internal/repl-rewrite-contract.js +6 -0
- package/internal/repl-scope-normalizer.js +2091 -0
- package/internal/repl-value-observer.js +117 -0
- package/internal/rpc-contract.js +52 -0
- package/internal/runtime-bridge-owner.js +172 -28
- package/internal/runtime-config.js +48 -52
- package/internal/runtime-contexts.js +82 -10
- package/internal/runtime-intrinsics.js +101 -0
- package/internal/runtime-messages.js +111 -0
- package/internal/session-cell-executor.js +402 -87
- package/internal/session-journal-recovery.js +684 -0
- package/internal/session-journal-schema.js +123 -0
- package/internal/session-journal.js +199 -654
- package/internal/session-log-view.js +42 -9
- package/internal/session-runtime.js +257 -95
- package/internal/session-state.js +247 -71
- package/internal/source-position-map.js +230 -71
- package/internal/stateful-module-compiler.js +154 -0
- package/internal/stateful-module-runtime.js +303 -0
- package/internal/stateful-root-compiler.js +600 -0
- package/internal/stateful-root-runtime.js +340 -0
- package/internal/typert-codec-compat.js +28 -0
- package/internal/typescript-transform.js +31 -0
- package/internal/user-binding-authoring.js +70 -0
- package/internal/user-binding-console-worker.js +244 -0
- package/internal/user-binding-console.js +148 -0
- package/internal/user-binding-draft-projection.js +335 -0
- package/internal/user-binding-model-context.js +31 -0
- package/internal/user-binding-runner.js +56 -0
- package/internal/user-bindings-owner.js +1065 -0
- package/internal/user-bindings-store.js +293 -0
- package/internal/user-bindings.js +361 -0
- package/internal/value-wire-schema.js +28 -0
- package/internal/value-wire.js +130 -91
- package/internal/worker-client.js +57 -67
- package/internal/worker-cwd-virtualization.js +80 -53
- package/internal/worker-environment.js +65 -0
- package/internal/worker-output-relay.js +29 -0
- package/internal/worker-repl-realm.js +134 -0
- package/internal/worker-shutdown.js +14 -0
- package/package.json +76 -7
- package/src/client-activity.js +95 -53
- package/src/client-authoring-view.js +580 -0
- package/src/client-binding-review.js +230 -0
- package/src/client-bindings-data.js +29 -0
- package/src/client-catalog.js +127 -0
- package/src/client-code-editor.js +84 -0
- package/src/client-console.js +112 -0
- package/src/client-copy.js +370 -0
- package/src/client-feature-gates.js +62 -0
- package/src/client-host-compat.js +150 -0
- package/src/client-indicator-view.js +267 -0
- package/src/client-repl-view.js +292 -0
- package/src/client-rpc.js +20 -0
- package/src/client-settings-view.js +221 -0
- package/src/client-styles.js +106 -0
- package/src/client-tool-view.js +108 -0
- package/src/client-transport.js +159 -0
- package/src/client-workbench.js +521 -0
- package/src/client.js +233 -615
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Worker } from 'node:worker_threads'
|
|
2
|
+
import { relayWorkerOutput } from './worker-output-relay.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Host one session kernel worker inside a killable helper process.
|
|
6
|
+
*
|
|
7
|
+
* Boundary: the host reaches this process over the process IPC channel, this
|
|
8
|
+
* process owns the kernel worker and its private MessagePort, and that port
|
|
9
|
+
* never crosses the process boundary. Kernel output reaches the host through the
|
|
10
|
+
* helper's own platform stdio pipes, so no byte is duplicated into IPC messages
|
|
11
|
+
* and counting stays with the host's output budget owner.
|
|
12
|
+
*/
|
|
13
|
+
const send = message => { if (typeof process.send === 'function') process.send(message) }
|
|
14
|
+
|
|
15
|
+
function sendBeforeDisconnect(message) {
|
|
16
|
+
return new Promise(resolve => {
|
|
17
|
+
if (typeof process.send !== 'function' || !process.connected) { resolve(); return }
|
|
18
|
+
process.send(message, () => resolve())
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function errorWire(error) {
|
|
23
|
+
return {
|
|
24
|
+
type: 'child-error',
|
|
25
|
+
message: error?.message ?? String(error),
|
|
26
|
+
name: error?.name,
|
|
27
|
+
code: error?.code,
|
|
28
|
+
stack: error?.stack,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let kernelPort
|
|
33
|
+
let worker
|
|
34
|
+
let stopping = false
|
|
35
|
+
let utilizationTimer
|
|
36
|
+
|
|
37
|
+
function releaseHelper() {
|
|
38
|
+
if (stopping) return
|
|
39
|
+
stopping = true
|
|
40
|
+
clearInterval(utilizationTimer)
|
|
41
|
+
utilizationTimer = undefined
|
|
42
|
+
kernelPort?.close()
|
|
43
|
+
kernelPort = undefined
|
|
44
|
+
process.removeAllListeners('message')
|
|
45
|
+
if (typeof process.disconnect === 'function' && process.connected) process.disconnect()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
process.on('message', message => {
|
|
49
|
+
if (worker !== undefined) {
|
|
50
|
+
// Host budget baselines must be sampled after any work that finished before
|
|
51
|
+
// this request. The helper answers directly without waiting for the worker,
|
|
52
|
+
// so a busy inner loop cannot hide the current utilization.
|
|
53
|
+
if (message?.type === 'sample-utilization') {
|
|
54
|
+
send({ type: 'utilization-sample', id: message.id, utilization: worker.performance.eventLoopUtilization() })
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
// Routed by ownership, not by handshake shape: parent-port requests reach the
|
|
58
|
+
// worker whenever it exists, and private messages need the port to be ready.
|
|
59
|
+
if (message?.type === 'kernel-message') kernelPort?.postMessage(message.value)
|
|
60
|
+
if (message?.type === 'worker-message') worker.postMessage(message.value)
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
if (message?.type !== 'init' || typeof message.workerData !== 'object' || message.workerData === null) {
|
|
64
|
+
send({ type: 'child-error', message: 'helper requires one init message before the kernel worker starts' })
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
// The host boundary already normalized the entry to an absolute file URL and
|
|
68
|
+
// supplied an explicit, pre-fork snapshot of the user worker's environment.
|
|
69
|
+
// That projection is the user Worker contract; the helper's own coverage
|
|
70
|
+
// variable is deliberately not reused here.
|
|
71
|
+
worker = new Worker(message.entry === undefined ? new URL('./kernel-worker.js', import.meta.url) : new URL(message.entry), {
|
|
72
|
+
workerData: message.workerData,
|
|
73
|
+
resourceLimits: message.resourceLimits,
|
|
74
|
+
execArgv: [],
|
|
75
|
+
stdout: true,
|
|
76
|
+
stderr: true,
|
|
77
|
+
env: message.env,
|
|
78
|
+
})
|
|
79
|
+
// The inner worker reports its own effective limits; the host never echoes back
|
|
80
|
+
// what it requested.
|
|
81
|
+
send({ type: 'child-limits', limits: worker.resourceLimits })
|
|
82
|
+
const relayedOutput = Promise.allSettled([
|
|
83
|
+
relayWorkerOutput(worker.stdout, process.stdout),
|
|
84
|
+
relayWorkerOutput(worker.stderr, process.stderr),
|
|
85
|
+
])
|
|
86
|
+
let workerFailure
|
|
87
|
+
const failStartup = error => {
|
|
88
|
+
workerFailure ??= error
|
|
89
|
+
// A protocol-level startup failure can leave the Worker alive under
|
|
90
|
+
// coverage or another runtime hook. End it here so direct transport users
|
|
91
|
+
// also reach process close and receive the drained public error.
|
|
92
|
+
void worker.terminate().catch(terminationError => { workerFailure ??= terminationError })
|
|
93
|
+
}
|
|
94
|
+
worker.on('error', error => { workerFailure = error })
|
|
95
|
+
worker.on('exit', async code => {
|
|
96
|
+
const outputResults = await relayedOutput
|
|
97
|
+
const outputFailure = outputResults.find(result => result.status === 'rejected')?.reason
|
|
98
|
+
if (workerFailure !== undefined) await sendBeforeDisconnect(errorWire(workerFailure))
|
|
99
|
+
else if (outputFailure !== undefined) await sendBeforeDisconnect(errorWire(outputFailure))
|
|
100
|
+
await sendBeforeDisconnect({ type: 'inner-worker-exit', code })
|
|
101
|
+
releaseHelper()
|
|
102
|
+
process.exitCode = code ?? 0
|
|
103
|
+
})
|
|
104
|
+
// Battery of samples taken here, on this process's main thread: the inner
|
|
105
|
+
// worker's utilization stays readable while its own loop is blocked, which is
|
|
106
|
+
// what the host's compute budget needs.
|
|
107
|
+
utilizationTimer = setInterval(() => {
|
|
108
|
+
send({ type: 'child-utilization', utilization: worker.performance.eventLoopUtilization() })
|
|
109
|
+
}, 50)
|
|
110
|
+
if (message.protocol === 'parent-port') {
|
|
111
|
+
// Workbench and candidate workers speak on their own parent port instead of
|
|
112
|
+
// opening a private channel; both directions are relayed unchanged.
|
|
113
|
+
worker.on('message', value => send({ type: 'worker-message', value }))
|
|
114
|
+
send({ type: 'ready', utilization: worker.performance.eventLoopUtilization() })
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
worker.once('message', message => {
|
|
118
|
+
if (message?.type === 'startup-error' && typeof message.error === 'string') {
|
|
119
|
+
failStartup(new Error(message.error))
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
if (message?.type !== 'ready' || typeof message.port?.postMessage !== 'function') {
|
|
123
|
+
failStartup(new Error('kernel worker returned an invalid private channel'))
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
kernelPort = message.port
|
|
127
|
+
kernelPort.on('message', value => send({
|
|
128
|
+
type: 'kernel-message',
|
|
129
|
+
value,
|
|
130
|
+
// Fresh baseline for the inner worker at every relayed message, on top of
|
|
131
|
+
// the main thread's periodic sampling below.
|
|
132
|
+
utilization: worker.performance.eventLoopUtilization(),
|
|
133
|
+
}))
|
|
134
|
+
worker.on('message', value => {
|
|
135
|
+
if (value?.type !== 'ready') send({ type: 'worker-message', value })
|
|
136
|
+
})
|
|
137
|
+
send({ type: 'ready', utilization: worker.performance.eventLoopUtilization() })
|
|
138
|
+
})
|
|
139
|
+
})
|