@xmoon76/dsh-pi-tui 0.5.4 → 0.5.5
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 +28 -7
- package/README.md +25 -6
- package/dist/application-runtime-CbBO4bY-.mjs +6860 -0
- package/dist/bootstrap-DLOydLLj.mjs +108410 -0
- package/dist/builtins.mjs +2 -3
- package/dist/client-bootstrap-DwSFzcTW.mjs +872 -0
- package/dist/context-summary-Bz0AGXa1.mjs +12027 -0
- package/dist/{context-summary-DAisTA_7.mjs → context-summary-D9mhxPXL.mjs} +1468 -10
- package/dist/custom-items-CKrOBCox.mjs +655 -0
- package/dist/disposal-BYBbEpVY.mjs +54 -0
- package/dist/dispose-cause-BzcXo4hu.mjs +123 -0
- package/dist/dist-C7QMk0ws.mjs +15431 -0
- package/dist/{entry-control-DvSrndWd.mjs → entry-control-DnduyDiw.mjs} +12 -31
- package/dist/{extensions-CcuMY4n2.mjs → extensions-pcFiH7Qe.mjs} +758 -68
- package/dist/extensions.mjs +1 -1
- package/dist/host-bootstrap-CKdfLkNS.mjs +188 -0
- package/dist/host-foundation-probe-CYHsbAw6.mjs +143 -0
- package/dist/host-prerequisites-9JBTtVNu.mjs +36 -0
- package/dist/host-runtime.d.mts +26 -0
- package/dist/host-runtime.mjs +450 -0
- package/dist/index.d.mts +8 -1
- package/dist/index.mjs +5192 -2118
- package/dist/local-client.mjs +1681 -188
- package/dist/local-discovery-CXnLT4GF.mjs +755 -0
- package/dist/local-discovery-DVFFpfBG.mjs +2 -0
- package/dist/local-host.mjs +927 -78
- package/dist/local-transport-C9aonplC.mjs +513 -0
- package/dist/performance-host.d.mts +2 -2
- package/dist/performance-host.mjs +258 -1
- package/dist/pi-tui-remote-contribution-DRk6Tl3J.mjs +78 -0
- package/dist/pi-tui-terminal-progress-contract-CdBH9j78.mjs +70 -0
- package/dist/pi-tui-terminal-progress-contract-XTQKj-WW.mjs +905 -0
- package/dist/{runtime-vc4mdr-R.mjs → runtime-Bh5OsftD.mjs} +655 -675
- package/dist/runtime-C5ROZqFj.mjs +2 -0
- package/dist/{session-tdJHLnJR.mjs → session-4keoXjk0.mjs} +2341 -217
- package/dist/session-B2zqv4wr.mjs +10869 -0
- package/dist/{startup-JaVZoTIl.mjs → startup-Ct2UUjUL.mjs} +7 -6
- package/dist/startup.d.mts +1 -1
- package/dist/startup.mjs +1 -1
- package/dist/{client-bootstrap-F5DHFI9t.mjs → terminal-progress-source-BhufrZ74.mjs} +3431 -3007
- package/dist/terminal-progress-source-CsBinCJ_.mjs +965 -0
- package/package.json +125 -116
- package/dist/host-bootstrap-DAgKknbY.mjs +0 -119
- package/dist/performance-host-CcDJjjVA.mjs +0 -266
- package/dist/rolldown-runtime-8H4AJuhK.mjs +0 -14
- package/dist/terminal-progress-source-xor3vakJ.mjs +0 -2256
|
@@ -0,0 +1,872 @@
|
|
|
1
|
+
import "./terminal-progress-source-BhufrZ74.mjs";
|
|
2
|
+
import { i as runDetached } from "./tasks-D_z5Yjjr.mjs";
|
|
3
|
+
import { t as mergeCause } from "./dispose-cause-CNFuUnjR.mjs";
|
|
4
|
+
import { c as mountRemoteClientDomainPrerequisites, n as createRemoteApplicationRuntimeFromClient, r as createRemoteClientUiRuntime, s as RemotePromptSerializerProduction } from "./application-runtime-CbBO4bY-.mjs";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import z from "@deepseek-ai/schemastery";
|
|
7
|
+
//#region src/app/config/schema.ts
|
|
8
|
+
/**
|
|
9
|
+
* The TUI plugin's Cordis config contract (plan §28): the resumed session id
|
|
10
|
+
* plus the DSH 0.1.7 profile-owned live TUI preferences. Every preference
|
|
11
|
+
* field is a schemastery `.volatile()` reference (PR A): the `tui-app`
|
|
12
|
+
* plugin's Config is the ONE runtime authority, Loader commits live updates
|
|
13
|
+
* into the references without remounting, and the Settings service projects
|
|
14
|
+
* these fields into editable forms keyed by the `tui-app` profile entry.
|
|
15
|
+
*
|
|
16
|
+
* The package entry re-exports `Config` unchanged, so the published root
|
|
17
|
+
* surface is preserved while the composition root consumes the same contract.
|
|
18
|
+
* @module @xmoon76/dsh-pi-tui/app/config/schema
|
|
19
|
+
*/
|
|
20
|
+
const Config = z.object({
|
|
21
|
+
sessionId: z.string(),
|
|
22
|
+
theme: z.string().default("auto").volatile(),
|
|
23
|
+
iconStyle: z.string().default("emoji").volatile(),
|
|
24
|
+
footer: z.string().default("full").volatile(),
|
|
25
|
+
footerFallbackMode: z.string().default("default").volatile(),
|
|
26
|
+
footerLayout: z.object({
|
|
27
|
+
schemaVersion: z.const(1),
|
|
28
|
+
rows: z.array(z.object({
|
|
29
|
+
left: z.array(z.object({
|
|
30
|
+
id: z.string(),
|
|
31
|
+
format: z.string(),
|
|
32
|
+
tone: z.string(),
|
|
33
|
+
prefix: z.string(),
|
|
34
|
+
suffix: z.string(),
|
|
35
|
+
importance: z.number(),
|
|
36
|
+
hideInTsp: z.boolean()
|
|
37
|
+
})),
|
|
38
|
+
right: z.array(z.object({
|
|
39
|
+
id: z.string(),
|
|
40
|
+
format: z.string(),
|
|
41
|
+
tone: z.string(),
|
|
42
|
+
prefix: z.string(),
|
|
43
|
+
suffix: z.string(),
|
|
44
|
+
importance: z.number(),
|
|
45
|
+
hideInTsp: z.boolean()
|
|
46
|
+
})),
|
|
47
|
+
separator: z.object({
|
|
48
|
+
text: z.string(),
|
|
49
|
+
tone: z.string()
|
|
50
|
+
})
|
|
51
|
+
}))
|
|
52
|
+
}).volatile(),
|
|
53
|
+
footerCustomItems: z.any().volatile(),
|
|
54
|
+
footerCommand: z.object({
|
|
55
|
+
schemaVersion: z.const(1),
|
|
56
|
+
command: z.string(),
|
|
57
|
+
timeoutMs: z.number(),
|
|
58
|
+
refreshIntervalMs: z.number(),
|
|
59
|
+
maxRows: z.number()
|
|
60
|
+
}).volatile(),
|
|
61
|
+
fullscreen: z.string().default("on").volatile(),
|
|
62
|
+
busyEnter: z.string().default("queue").volatile(),
|
|
63
|
+
localShellSandbox: z.string().default("bypass").volatile(),
|
|
64
|
+
homeEndKeys: z.string().default("input").volatile(),
|
|
65
|
+
displayPreset: z.string().default("full").volatile(),
|
|
66
|
+
progressUpdates: z.string().default("milestones").volatile(),
|
|
67
|
+
gitAttribution: z.string().default("off").volatile(),
|
|
68
|
+
responseStyle: z.string().default("default").volatile(),
|
|
69
|
+
notificationMode: z.string().default("unfocused").volatile(),
|
|
70
|
+
notificationMethod: z.string().default("auto").volatile(),
|
|
71
|
+
terminalProgress: z.string().default("9;4+7501").volatile(),
|
|
72
|
+
wheelScrollLines: z.string().default("1").volatile(),
|
|
73
|
+
keybindings: z.any().volatile(),
|
|
74
|
+
legacySettingsMigrationVersion: z.number().default(0).volatile()
|
|
75
|
+
});
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/app/remote-process/client-bootstrap.ts
|
|
78
|
+
/**
|
|
79
|
+
* Client-only pre-connection bootstrap for the M4-B1/B2-S process entries.
|
|
80
|
+
*
|
|
81
|
+
* The official Client runtime requires an explicit Host carrier; M4-B1 owns
|
|
82
|
+
* the authenticated cross-process transport in `local-transport.ts`. This
|
|
83
|
+
* module owns two precise modes on the caller's ONE Client Context:
|
|
84
|
+
*
|
|
85
|
+
* - `qualification` (the default, frozen B1 contract): mount only the A0
|
|
86
|
+
* Client-local subtree (TUI startup facts, extension host, first-party
|
|
87
|
+
* builtins) and project the official Connection state into a status
|
|
88
|
+
* snapshot. No official Client domains and no physical surface.
|
|
89
|
+
* - `surface` (the internal M4-B2-S real Client): mount exactly one official
|
|
90
|
+
* Client Domain graph (the shared `mountRemoteClientDomains`), the one
|
|
91
|
+
* Client UI subtree, the one split-Client application runtime (Backend +
|
|
92
|
+
* owners + presentation), then the one real PiTui runner through the
|
|
93
|
+
* process composition root's lazy `mountRunner` callback. It never creates
|
|
94
|
+
* a Host handle, never fabricates a Host service, never copies connection
|
|
95
|
+
* state into a long-lived flag, and never calls a Host shutdown.
|
|
96
|
+
*
|
|
97
|
+
* The surface mode's disposal order is one reverse chain: runner surface
|
|
98
|
+
* (TUI + owned `tuiMainView` + session retirement + the selected Remote
|
|
99
|
+
* adapters), Client UI subtree, the memoized application transport disposer
|
|
100
|
+
* (presentation/backend/domains), the borrowed official transport, then the
|
|
101
|
+
* Client root. `LocalClientHandle.dispose()` is the ONE Client coordinator;
|
|
102
|
+
* the runner's own earlier `selected.disposeTransport()` is the same memoized
|
|
103
|
+
* release, never a second unmount.
|
|
104
|
+
*
|
|
105
|
+
* @module app/remote-process/client-bootstrap
|
|
106
|
+
*/
|
|
107
|
+
/** Project the authenticated record without the profile path. */
|
|
108
|
+
function hostFacts(record) {
|
|
109
|
+
return {
|
|
110
|
+
scopeId: record.scopeId,
|
|
111
|
+
instanceId: record.instanceId,
|
|
112
|
+
hostPid: record.hostPid,
|
|
113
|
+
hostStarttime: record.hostStarttime,
|
|
114
|
+
origin: record.origin,
|
|
115
|
+
protocol: record.protocol,
|
|
116
|
+
bundleVersion: record.bundleVersion,
|
|
117
|
+
dshVersion: record.dshVersion,
|
|
118
|
+
buildId: record.buildId
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** The exact Host startup facts object (never the Host-only readiness seam). */
|
|
122
|
+
function startupFactsOf(startup) {
|
|
123
|
+
return {
|
|
124
|
+
...startup.sessionId === void 0 ? {} : { sessionId: startup.sessionId },
|
|
125
|
+
...startup.presetId === void 0 ? {} : { presetId: startup.presetId }
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Qualification-only assembly hold: pause ONE startup stage until a barrier
|
|
130
|
+
* file is released OR the caller aborts the startup. It is the deterministic
|
|
131
|
+
* seam for the "stop during Domain readiness / Surface mount" tests; production
|
|
132
|
+
* never sets `SPLIT_PROCESS_CLIENT_HOLD_ASSEMBLY`.
|
|
133
|
+
*/
|
|
134
|
+
async function waitForAssemblyHold(stage, signal, onHold, envName = "SPLIT_PROCESS_CLIENT_HOLD_ASSEMBLY") {
|
|
135
|
+
const spec = process.env[envName];
|
|
136
|
+
if (spec === void 0 || spec === "") return;
|
|
137
|
+
const [name, path] = spec.split("@");
|
|
138
|
+
if (name !== stage || path === void 0 || path === "") return;
|
|
139
|
+
onHold?.({
|
|
140
|
+
op: "assembly-hold",
|
|
141
|
+
stage,
|
|
142
|
+
barrier: path
|
|
143
|
+
});
|
|
144
|
+
const deadline = Date.now() + 6e4;
|
|
145
|
+
while (!existsSync(path)) {
|
|
146
|
+
signal?.throwIfAborted();
|
|
147
|
+
if (Date.now() > deadline) throw new Error(`local client entry: the ${stage} assembly barrier was not released`);
|
|
148
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
149
|
+
}
|
|
150
|
+
signal?.throwIfAborted();
|
|
151
|
+
}
|
|
152
|
+
/** A never-resolving promise that rejects on abort, plus its listener cleanup. */
|
|
153
|
+
function abortable(signal) {
|
|
154
|
+
let listener;
|
|
155
|
+
return {
|
|
156
|
+
promise: new Promise((_resolve, reject) => {
|
|
157
|
+
if (signal === void 0) return;
|
|
158
|
+
const abort = () => {
|
|
159
|
+
reject(signal.reason ?? /* @__PURE__ */ new Error("local client entry: startup aborted"));
|
|
160
|
+
};
|
|
161
|
+
if (signal.aborted) {
|
|
162
|
+
abort();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
listener = abort;
|
|
166
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
167
|
+
}),
|
|
168
|
+
cancel: () => {
|
|
169
|
+
if (listener !== void 0) signal?.removeEventListener("abort", listener);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** Wait for the qualification barrier file; a bounded wait, never a timer. */
|
|
174
|
+
async function waitForQualificationBarrier(path) {
|
|
175
|
+
const deadline = Date.now() + 6e4;
|
|
176
|
+
while (!existsSync(path)) {
|
|
177
|
+
if (Date.now() > deadline) throw new Error(`local client entry: the qualification barrier was not released: ${path}`);
|
|
178
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** Throw the collected disposal errors with the first one primary. */
|
|
182
|
+
function throwDisposalErrors(errors, label) {
|
|
183
|
+
if (errors.length === 0) return;
|
|
184
|
+
const primary = errors[0] instanceof Error ? errors[0] : new Error(String(errors[0]));
|
|
185
|
+
for (const secondary of errors.slice(1)) mergeCause(primary, secondary);
|
|
186
|
+
throw Object.assign(primary, { cleanupFailed: true });
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The ONE serial surface-revision task slot. Revision mounts and the final
|
|
190
|
+
* Client disposal chain through it, so an HMR replacement can never overlap
|
|
191
|
+
* another replacement, a stop, or the root release. A failed task settles the
|
|
192
|
+
* slot and the next task still runs (the caller owns the failure decision).
|
|
193
|
+
*/
|
|
194
|
+
var SurfaceRevisionTasks = class {
|
|
195
|
+
tail = Promise.resolve();
|
|
196
|
+
run(task) {
|
|
197
|
+
const run = this.tail.then(task, task);
|
|
198
|
+
this.tail = run.then(() => {}, () => {});
|
|
199
|
+
return run;
|
|
200
|
+
}
|
|
201
|
+
/** Resolve after every task queued SO FAR has settled. */
|
|
202
|
+
drain() {
|
|
203
|
+
return this.tail;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
/** The current official `tuiMainView` Session id, derived from live sources. */
|
|
207
|
+
function mainViewSessionId(sessions) {
|
|
208
|
+
for (const id of sessions.list.getSnapshot().ids) if ((sessions.retainInfo(id).getSnapshot().retainedBy.tuiMainView ?? 0) > 0) return String(id);
|
|
209
|
+
}
|
|
210
|
+
/** The official `tuiMainView` reference one mounted Domain graph holds. */
|
|
211
|
+
function openSessionIdFor(domains) {
|
|
212
|
+
return mainViewSessionId(domains.sessions);
|
|
213
|
+
}
|
|
214
|
+
/** Borrow the CURRENT official binding of one listed Session id (no retain). */
|
|
215
|
+
function bindingOfListedSession(sessions, sessionId) {
|
|
216
|
+
for (const id of sessions.list.getSnapshot().ids) if (String(id) === sessionId) return sessions.binding(id);
|
|
217
|
+
}
|
|
218
|
+
/** Bound on one handoff restore observation (not a business timeout). */
|
|
219
|
+
const HANDOFF_OPEN_TIMEOUT_MS = 3e4;
|
|
220
|
+
/** Re-validate ONE settled handoff proof synchronously, before claiming success. */
|
|
221
|
+
function verifyHandoffRestoreProof(sources, generationId, sessionId, bindingIdentity) {
|
|
222
|
+
const current = sources.transport.status();
|
|
223
|
+
if (current.transport !== "connected" || current.generationId !== generationId) throw new Error("local client entry: the official transport generation changed after the handoff restore proof");
|
|
224
|
+
if (sources.surfaceMounted() !== true) throw new Error("local client entry: the handoff Client surface is no longer mounted");
|
|
225
|
+
const open = mainViewSessionId(sources.sessions);
|
|
226
|
+
if (sessionId === void 0) {
|
|
227
|
+
if (open !== void 0) throw new Error("local client entry: a Session opened after the sessionless handoff restore proof");
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (bindingIdentity === void 0) throw new Error("local client entry: the handoff restore proof has no settled Session binding");
|
|
231
|
+
if (open !== sessionId) throw new Error("local client entry: the handoff Client no longer owns the restored Session");
|
|
232
|
+
const binding = bindingOfListedSession(sources.sessions, sessionId);
|
|
233
|
+
if (binding === void 0 || !Object.is(binding, bindingIdentity)) throw new Error("local client entry: the restored Session binding changed after the handoff restore proof");
|
|
234
|
+
if (binding.session.getSnapshot().openState !== "open") throw new Error("local client entry: the official Session history is no longer open");
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* One-shot Client-handoff restore proof over the LIVE official sources.
|
|
238
|
+
*
|
|
239
|
+
* A Session-bearing handoff succeeds only when the current official
|
|
240
|
+
* `tuiMainView` owner still holds that exact Session and its official history
|
|
241
|
+
* state is terminal `'open'`; `cold`/`loading` keep waiting and `error` fails
|
|
242
|
+
* closed. A sessionless handoff succeeds only with a mounted sessionless
|
|
243
|
+
* surface on the connected transport and NEVER creates a Session. The initial
|
|
244
|
+
* transport generation is captured first: a rollover invalidates the proof.
|
|
245
|
+
* The observation is bounded and holds no reference and no long-lived state;
|
|
246
|
+
* the returned proof must be verified synchronously immediately before the
|
|
247
|
+
* final `handoff-restored` claim.
|
|
248
|
+
*/
|
|
249
|
+
async function observeHandoffOpen(sources, sessionId, signal) {
|
|
250
|
+
const initial = sources.transport.status();
|
|
251
|
+
if (initial.transport !== "connected" || initial.generationId === void 0) throw new Error("local client entry: the handoff Client has no connected official transport generation");
|
|
252
|
+
const capturedGeneration = initial.generationId;
|
|
253
|
+
return await new Promise((resolve, reject) => {
|
|
254
|
+
const unsubscribers = [];
|
|
255
|
+
let settled = false;
|
|
256
|
+
let retainSubscribed = false;
|
|
257
|
+
/** The binding generation this proof first observed; it may never change. */
|
|
258
|
+
let observedBinding;
|
|
259
|
+
let sessionUnsubscribe;
|
|
260
|
+
let deadline;
|
|
261
|
+
const cleanup = () => {
|
|
262
|
+
if (deadline !== void 0) clearTimeout(deadline);
|
|
263
|
+
sessionUnsubscribe?.();
|
|
264
|
+
sessionUnsubscribe = void 0;
|
|
265
|
+
for (const unsubscribe of unsubscribers.splice(0)) unsubscribe();
|
|
266
|
+
signal?.removeEventListener("abort", onAbort);
|
|
267
|
+
};
|
|
268
|
+
const succeed = () => {
|
|
269
|
+
if (settled) return;
|
|
270
|
+
const settledBinding = observedBinding;
|
|
271
|
+
if (sessionId !== void 0 && settledBinding === void 0) {
|
|
272
|
+
settled = true;
|
|
273
|
+
cleanup();
|
|
274
|
+
reject(/* @__PURE__ */ new Error("local client entry: the handoff restore proof lost its settled Session binding"));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
settled = true;
|
|
278
|
+
cleanup();
|
|
279
|
+
resolve({
|
|
280
|
+
generationId: capturedGeneration,
|
|
281
|
+
...sessionId === void 0 ? {} : {
|
|
282
|
+
sessionId,
|
|
283
|
+
bindingIdentity: settledBinding
|
|
284
|
+
},
|
|
285
|
+
verify: () => {
|
|
286
|
+
verifyHandoffRestoreProof(sources, capturedGeneration, sessionId, settledBinding);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
const fail = (error) => {
|
|
291
|
+
if (settled) return;
|
|
292
|
+
settled = true;
|
|
293
|
+
cleanup();
|
|
294
|
+
reject(error);
|
|
295
|
+
};
|
|
296
|
+
function onAbort() {
|
|
297
|
+
fail(/* @__PURE__ */ new Error("local client entry: the handoff restore observation was aborted"));
|
|
298
|
+
}
|
|
299
|
+
const evaluate = () => {
|
|
300
|
+
if (settled) return;
|
|
301
|
+
const current = sources.transport.status();
|
|
302
|
+
if (current.transport !== "connected" || current.generationId !== capturedGeneration) {
|
|
303
|
+
fail(/* @__PURE__ */ new Error("local client entry: the official transport generation changed during the handoff restore"));
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (sources.surfaceMounted() !== true) {
|
|
307
|
+
fail(/* @__PURE__ */ new Error("local client entry: the handoff Client surface is not mounted"));
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const open = mainViewSessionId(sources.sessions);
|
|
311
|
+
if (sessionId === void 0) {
|
|
312
|
+
if (open !== void 0) {
|
|
313
|
+
fail(/* @__PURE__ */ new Error("local client entry: a sessionless Client handoff opened a new Session"));
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
succeed();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (!retainSubscribed) for (const id of sources.sessions.list.getSnapshot().ids) {
|
|
320
|
+
if (String(id) !== sessionId) continue;
|
|
321
|
+
unsubscribers.push(sources.sessions.retainInfo(id).subscribe(evaluate));
|
|
322
|
+
retainSubscribed = true;
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
if (open === void 0) return;
|
|
326
|
+
if (open !== sessionId) {
|
|
327
|
+
fail(/* @__PURE__ */ new Error("local client entry: the handoff Client opened a different Session"));
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const binding = bindingOfListedSession(sources.sessions, sessionId);
|
|
331
|
+
if (binding === void 0) return;
|
|
332
|
+
if (observedBinding === void 0) {
|
|
333
|
+
observedBinding = binding;
|
|
334
|
+
sessionUnsubscribe = binding.session.subscribe(evaluate);
|
|
335
|
+
} else if (!Object.is(observedBinding, binding)) {
|
|
336
|
+
fail(/* @__PURE__ */ new Error("local client entry: the handoff Session ownership changed during the restore"));
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const snapshot = binding.session.getSnapshot();
|
|
340
|
+
if (snapshot.openState === "open") {
|
|
341
|
+
if (mainViewSessionId(sources.sessions) !== sessionId || !Object.is(bindingOfListedSession(sources.sessions, sessionId), observedBinding)) {
|
|
342
|
+
fail(/* @__PURE__ */ new Error("local client entry: the handoff Session ownership changed during the restore"));
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
succeed();
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (snapshot.openState === "error") fail(/* @__PURE__ */ new Error("local client entry: the official Session history open failed"));
|
|
349
|
+
};
|
|
350
|
+
unsubscribers.push(sources.sessions.list.subscribe(evaluate));
|
|
351
|
+
unsubscribers.push(sources.transport.connection.generation.subscribe(evaluate));
|
|
352
|
+
if (signal?.aborted === true) {
|
|
353
|
+
onAbort();
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
357
|
+
deadline = setTimeout(() => {
|
|
358
|
+
fail(/* @__PURE__ */ new Error(`local client entry: the handoff Session open did not settle within ${String(HANDOFF_OPEN_TIMEOUT_MS / 1e3)}s`));
|
|
359
|
+
}, HANDOFF_OPEN_TIMEOUT_MS);
|
|
360
|
+
evaluate();
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* The ONE split-Client surface composition: Domain graph -> Client UI
|
|
365
|
+
* subtree -> Remote application runtime -> real runner. Every stage is
|
|
366
|
+
* recorded the instant it exists, so a failure at any later stage unwinds the
|
|
367
|
+
* whole partial composition in reverse and the original error stays primary.
|
|
368
|
+
*
|
|
369
|
+
* The composition is a sequence of SURFACE REVISIONS over the SAME Client
|
|
370
|
+
* Context and B1 transport. A normal Client process mounts exactly one
|
|
371
|
+
* revision; the qualification-only replacement path retires the current
|
|
372
|
+
* revision (runner -> Client UI -> the memoized application/Domain release)
|
|
373
|
+
* and mounts a fresh one on the same Context. The host is never involved:
|
|
374
|
+
* its `runProfile`, Agent, Job and service fibers stay owned by the Host
|
|
375
|
+
* process.
|
|
376
|
+
*/
|
|
377
|
+
async function startSurfaceLocalClient(context, startup, processStartIdentity, composition) {
|
|
378
|
+
const { transport, host, dshAnchor, authenticatedFetch, mountRunner } = composition;
|
|
379
|
+
const signal = composition.signal;
|
|
380
|
+
if (transport === void 0 || host === void 0) throw new Error("local client entry: surface mode requires the official transport and the authenticated Host");
|
|
381
|
+
if (dshAnchor === void 0 || dshAnchor === "") throw new Error("local client entry: surface mode requires the installed DSH anchor");
|
|
382
|
+
if (authenticatedFetch === void 0) throw new Error("local client entry: surface mode requires the authenticated Host fetch");
|
|
383
|
+
if (mountRunner === void 0) throw new Error("local client entry: surface mode requires the process composition runner mount");
|
|
384
|
+
if (composition.domains === void 0) throw new Error("local client entry: surface mode requires the mounted official Client Domain graph");
|
|
385
|
+
if (composition.interactionDelivery === void 0) throw new Error("local client entry: surface mode requires the root interaction delivery owner");
|
|
386
|
+
const domains = composition.domains;
|
|
387
|
+
const delivery = composition.interactionDelivery;
|
|
388
|
+
let currentRevision;
|
|
389
|
+
let revisionSequence = 0;
|
|
390
|
+
let disposed = false;
|
|
391
|
+
const revisionTasks = new SurfaceRevisionTasks();
|
|
392
|
+
const enqueueRevision = (task) => revisionTasks.run(task);
|
|
393
|
+
const base = {
|
|
394
|
+
processRole: "client",
|
|
395
|
+
pid: process.pid,
|
|
396
|
+
...processStartIdentity === void 0 ? {} : { processStartIdentity },
|
|
397
|
+
phase: "client-local-ready",
|
|
398
|
+
fiberOwner: "client-root",
|
|
399
|
+
...context.fiber.uid == null ? {} : { rootFiberUid: context.fiber.uid },
|
|
400
|
+
extensionService: { present: true },
|
|
401
|
+
startupFacts: startupFactsOf(startup),
|
|
402
|
+
host: hostFacts(host)
|
|
403
|
+
};
|
|
404
|
+
const status = () => {
|
|
405
|
+
const observed = transport.status();
|
|
406
|
+
const revision = currentRevision;
|
|
407
|
+
const domainsOpen = revision !== void 0;
|
|
408
|
+
const current = domainsOpen ? openSessionIdFor(domains) : void 0;
|
|
409
|
+
const privateRemote = domains.remote;
|
|
410
|
+
return {
|
|
411
|
+
...base,
|
|
412
|
+
transport: observed.transport,
|
|
413
|
+
sessionOpen: current !== void 0,
|
|
414
|
+
...current === void 0 ? {} : { openSessionId: current },
|
|
415
|
+
surfaceMounted: revision?.surfaceMounted === true,
|
|
416
|
+
...revision === void 0 ? {} : { surfaceRevision: revision.id },
|
|
417
|
+
...revision?.runner?.fiberUid === void 0 ? {} : { surfaceFiberUid: revision.runner.fiberUid },
|
|
418
|
+
...observed.generationId === void 0 ? {} : { generationId: observed.generationId },
|
|
419
|
+
...observed.hostHome === void 0 ? {} : { hostHome: observed.hostHome },
|
|
420
|
+
activeWrappers: observed.activeWrappers,
|
|
421
|
+
liveSockets: observed.liveSockets,
|
|
422
|
+
owners: {
|
|
423
|
+
typert: context.reflect.get("typert") === void 0 ? 0 : 1,
|
|
424
|
+
connection: context.reflect.get("connection") === void 0 ? 0 : 1,
|
|
425
|
+
remote: context.reflect.get("remote") === void 0 ? 0 : 1,
|
|
426
|
+
fileUpload: context.reflect.get("fileUpload") === void 0 ? 0 : 1,
|
|
427
|
+
sessions: context.reflect.get("sessions") === void 0 ? 0 : 1,
|
|
428
|
+
jobs: context.reflect.get("jobs") === void 0 ? 0 : 1
|
|
429
|
+
},
|
|
430
|
+
...domainsOpen ? { sessionsListPhase: domains.sessions.list.getSnapshot().phase } : {},
|
|
431
|
+
privateNamespaces: domainsOpen && privateRemote?.piTuiFileReferences !== void 0 && privateRemote.piTuiTerminalProgress !== void 0 ? 2 : 0
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
let lastStatusKey = "";
|
|
435
|
+
const emitStatus = () => {
|
|
436
|
+
if (composition.onStatus === void 0) return;
|
|
437
|
+
const current = status();
|
|
438
|
+
const key = JSON.stringify([
|
|
439
|
+
current.transport,
|
|
440
|
+
current.generationId,
|
|
441
|
+
current.sessionOpen,
|
|
442
|
+
current.openSessionId,
|
|
443
|
+
current.surfaceMounted,
|
|
444
|
+
current.surfaceRevision,
|
|
445
|
+
current.surfaceFiberUid
|
|
446
|
+
]);
|
|
447
|
+
if (key === lastStatusKey) return;
|
|
448
|
+
lastStatusKey = key;
|
|
449
|
+
composition.onStatus(current);
|
|
450
|
+
};
|
|
451
|
+
/** Attach the revision-local official status subscriptions. */
|
|
452
|
+
const subscribeRevisionStatus = (revision) => {
|
|
453
|
+
const watched = /* @__PURE__ */ new Map();
|
|
454
|
+
const watchListedSessions = () => {
|
|
455
|
+
for (const id of domains.sessions.list.getSnapshot().ids) {
|
|
456
|
+
const key = String(id);
|
|
457
|
+
if (watched.has(key)) continue;
|
|
458
|
+
watched.set(key, domains.sessions.retainInfo(id).subscribe(emitStatus));
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
const unsubscribeList = domains.sessions.list.subscribe(() => {
|
|
462
|
+
watchListedSessions();
|
|
463
|
+
emitStatus();
|
|
464
|
+
});
|
|
465
|
+
const unsubscribeGeneration = transport.connection.generation.subscribe(emitStatus);
|
|
466
|
+
revision.statusCleanup = () => {
|
|
467
|
+
unsubscribeList();
|
|
468
|
+
unsubscribeGeneration();
|
|
469
|
+
for (const unsubscribe of watched.values()) unsubscribe();
|
|
470
|
+
watched.clear();
|
|
471
|
+
};
|
|
472
|
+
watchListedSessions();
|
|
473
|
+
};
|
|
474
|
+
/** Mount one fresh revision on the SAME Client Context/transport. */
|
|
475
|
+
const mountRevision = async (kind, sessionIdOverride) => {
|
|
476
|
+
signal?.throwIfAborted();
|
|
477
|
+
const revision = {
|
|
478
|
+
id: ++revisionSequence,
|
|
479
|
+
surfaceMounted: false
|
|
480
|
+
};
|
|
481
|
+
currentRevision = revision;
|
|
482
|
+
await waitForAssemblyHold("domain", signal, composition.onQualification);
|
|
483
|
+
signal?.throwIfAborted();
|
|
484
|
+
const revisionStartup = {
|
|
485
|
+
...startupFactsOf(startup),
|
|
486
|
+
...sessionIdOverride === void 0 ? {} : { sessionId: sessionIdOverride }
|
|
487
|
+
};
|
|
488
|
+
revision.ui = await createRemoteClientUiRuntime({
|
|
489
|
+
context,
|
|
490
|
+
startup: revisionStartup
|
|
491
|
+
});
|
|
492
|
+
composition.onQualification?.({
|
|
493
|
+
op: "startup-stage",
|
|
494
|
+
stage: "ui-mounted",
|
|
495
|
+
revision: revision.id
|
|
496
|
+
});
|
|
497
|
+
signal?.throwIfAborted();
|
|
498
|
+
const holdPath = process.env.SPLIT_PROCESS_CLIENT_HOLD_SERIALIZE;
|
|
499
|
+
let promptSerializer;
|
|
500
|
+
if (holdPath !== void 0 && holdPath !== "") {
|
|
501
|
+
const production = RemotePromptSerializerProduction.overSessions(domains.sessions);
|
|
502
|
+
promptSerializer = {
|
|
503
|
+
preflight: (message) => production.preflight(message),
|
|
504
|
+
async serialize(message) {
|
|
505
|
+
const serialized = await production.serialize(message);
|
|
506
|
+
await waitForQualificationBarrier(holdPath);
|
|
507
|
+
return serialized;
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
revision.application = await createRemoteApplicationRuntimeFromClient({
|
|
512
|
+
domains,
|
|
513
|
+
fetch: authenticatedFetch,
|
|
514
|
+
clientUi: revision.ui,
|
|
515
|
+
delivery,
|
|
516
|
+
surfaceRevision: revision.id,
|
|
517
|
+
...composition.onQualification === void 0 ? {} : { onQualification: composition.onQualification },
|
|
518
|
+
...signal === void 0 ? {} : { signal },
|
|
519
|
+
...promptSerializer === void 0 ? {} : { promptSerializer }
|
|
520
|
+
});
|
|
521
|
+
composition.onQualification?.({
|
|
522
|
+
op: "startup-stage",
|
|
523
|
+
stage: "application-ready",
|
|
524
|
+
revision: revision.id
|
|
525
|
+
});
|
|
526
|
+
signal?.throwIfAborted();
|
|
527
|
+
if (kind === "hmr" && process.env.SPLIT_PROCESS_CLIENT_HMR_FAIL === "1") throw new Error("local client entry: qualification forced HMR surface mount failure");
|
|
528
|
+
const override = {
|
|
529
|
+
selected: revision.application.selected,
|
|
530
|
+
presentation: revision.application.presentation,
|
|
531
|
+
extensionService: revision.application.extensionService
|
|
532
|
+
};
|
|
533
|
+
const activeSessionId = sessionIdOverride ?? startup.sessionId;
|
|
534
|
+
const config = Config({ ...activeSessionId === void 0 ? {} : { sessionId: activeSessionId } });
|
|
535
|
+
signal?.throwIfAborted();
|
|
536
|
+
revision.runner = await mountRunner({
|
|
537
|
+
context,
|
|
538
|
+
config,
|
|
539
|
+
override
|
|
540
|
+
});
|
|
541
|
+
composition.onQualification?.({
|
|
542
|
+
op: "startup-stage",
|
|
543
|
+
stage: "runner-fiber-mounted",
|
|
544
|
+
revision: revision.id
|
|
545
|
+
});
|
|
546
|
+
await waitForAssemblyHold("surface", signal, composition.onQualification, kind === "hmr" ? "SPLIT_PROCESS_CLIENT_HMR_HOLD" : "SPLIT_PROCESS_CLIENT_HOLD_ASSEMBLY");
|
|
547
|
+
signal?.throwIfAborted();
|
|
548
|
+
const abortReady = abortable(signal);
|
|
549
|
+
try {
|
|
550
|
+
await Promise.race([
|
|
551
|
+
revision.runner.ready,
|
|
552
|
+
revision.runner.stopped.then((code) => {
|
|
553
|
+
throw new Error(`local client entry: the surface startup was cancelled by exit request ${String(code)}`);
|
|
554
|
+
}),
|
|
555
|
+
abortReady.promise
|
|
556
|
+
]);
|
|
557
|
+
} finally {
|
|
558
|
+
abortReady.cancel();
|
|
559
|
+
}
|
|
560
|
+
composition.onQualification?.({
|
|
561
|
+
op: "startup-stage",
|
|
562
|
+
stage: "surface-ready",
|
|
563
|
+
revision: revision.id
|
|
564
|
+
});
|
|
565
|
+
revision.surfaceMounted = true;
|
|
566
|
+
subscribeRevisionStatus(revision);
|
|
567
|
+
emitStatus();
|
|
568
|
+
return revision;
|
|
569
|
+
};
|
|
570
|
+
/** Reverse-dispose exactly one revision: runner -> UI -> application adapters. */
|
|
571
|
+
const disposeRevision = async (revision) => {
|
|
572
|
+
revision.surfaceMounted = false;
|
|
573
|
+
emitStatus();
|
|
574
|
+
revision.statusCleanup?.();
|
|
575
|
+
revision.statusCleanup = void 0;
|
|
576
|
+
const errors = [];
|
|
577
|
+
if (revision.runner !== void 0) try {
|
|
578
|
+
await revision.runner.dispose();
|
|
579
|
+
} catch (error) {
|
|
580
|
+
errors.push(error);
|
|
581
|
+
}
|
|
582
|
+
if (revision.ui !== void 0) try {
|
|
583
|
+
await revision.ui.dispose();
|
|
584
|
+
} catch (error) {
|
|
585
|
+
errors.push(error);
|
|
586
|
+
}
|
|
587
|
+
if (revision.application !== void 0) try {
|
|
588
|
+
await revision.application.selected.disposeTransport();
|
|
589
|
+
} catch (error) {
|
|
590
|
+
errors.push(error);
|
|
591
|
+
}
|
|
592
|
+
revision.runner = void 0;
|
|
593
|
+
revision.ui = void 0;
|
|
594
|
+
revision.application = void 0;
|
|
595
|
+
throwDisposalErrors(errors, "local client surface revision");
|
|
596
|
+
};
|
|
597
|
+
if (process.env.SPLIT_PROCESS_CLIENT_PRIVATE_RPC_PROOF === "1") {
|
|
598
|
+
if (composition.diag === void 0) throw new Error("local client entry: the private RPC qualification requires the Client diagnostics sink");
|
|
599
|
+
const diag = composition.diag;
|
|
600
|
+
process.on("SIGUSR2", () => {
|
|
601
|
+
if (currentRevision === void 0) {
|
|
602
|
+
composition.onQualification?.({
|
|
603
|
+
op: "private-rpc-proof",
|
|
604
|
+
error: "no retained Session"
|
|
605
|
+
});
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const target = openSessionIdFor(domains) ?? domains.sessions.list.getSnapshot().ids[0];
|
|
609
|
+
if (target === void 0) {
|
|
610
|
+
composition.onQualification?.({
|
|
611
|
+
op: "private-rpc-proof",
|
|
612
|
+
error: "no retained Session"
|
|
613
|
+
});
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const currentDomains = domains;
|
|
617
|
+
runDetached("surface private RPC proof", async () => {
|
|
618
|
+
const remote = currentDomains.remote;
|
|
619
|
+
const sessionId = String(target);
|
|
620
|
+
const file = await remote.piTuiFileReferences.list(sessionId, "notes");
|
|
621
|
+
const watch = remote.piTuiTerminalProgress.watch(sessionId);
|
|
622
|
+
const iterator = watch[Symbol.asyncIterator]();
|
|
623
|
+
let terminalKind;
|
|
624
|
+
try {
|
|
625
|
+
const first = await iterator.next();
|
|
626
|
+
terminalKind = first.done === true ? "ended" : first.value?.kind;
|
|
627
|
+
} finally {
|
|
628
|
+
watch.dispose();
|
|
629
|
+
}
|
|
630
|
+
composition.onQualification?.({
|
|
631
|
+
op: "private-rpc-proof",
|
|
632
|
+
sessionId,
|
|
633
|
+
fileOk: file.ok === true,
|
|
634
|
+
fileKind: file.ok ? file.value?.kind : void 0,
|
|
635
|
+
terminalKind,
|
|
636
|
+
owners: status().owners,
|
|
637
|
+
privateNamespaces: status().privateNamespaces
|
|
638
|
+
});
|
|
639
|
+
}, { diag });
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
if (process.env.SPLIT_PROCESS_CLIENT_HOLD_SERIALIZE !== void 0 && process.env.SPLIT_PROCESS_CLIENT_HOLD_SERIALIZE !== "") process.on("SIGUSR2", () => {
|
|
643
|
+
currentRevision?.application?.selected.stopSurfaceAdmission?.();
|
|
644
|
+
composition.onQualification?.({ op: "stop-surface-admission" });
|
|
645
|
+
});
|
|
646
|
+
try {
|
|
647
|
+
await enqueueRevision(async () => {
|
|
648
|
+
await mountRevision("initial");
|
|
649
|
+
});
|
|
650
|
+
} catch (error) {
|
|
651
|
+
const partial = currentRevision;
|
|
652
|
+
currentRevision = void 0;
|
|
653
|
+
const cleanupErrors = [];
|
|
654
|
+
if (partial !== void 0) try {
|
|
655
|
+
await disposeRevision(partial);
|
|
656
|
+
} catch (cleanupError) {
|
|
657
|
+
cleanupErrors.push(cleanupError);
|
|
658
|
+
}
|
|
659
|
+
try {
|
|
660
|
+
delivery.dispose();
|
|
661
|
+
} catch (cleanupError) {
|
|
662
|
+
cleanupErrors.push(cleanupError);
|
|
663
|
+
}
|
|
664
|
+
let primary = error instanceof Error ? error : new Error(String(error));
|
|
665
|
+
for (const cleanupError of cleanupErrors) primary = mergeCause(primary, cleanupError);
|
|
666
|
+
throw primary;
|
|
667
|
+
}
|
|
668
|
+
return {
|
|
669
|
+
get status() {
|
|
670
|
+
return status();
|
|
671
|
+
},
|
|
672
|
+
async awaitHandoffOpen(sessionId, abort) {
|
|
673
|
+
if (disposed) throw new Error("local client entry: the surface revision owner is already disposed");
|
|
674
|
+
return await observeHandoffOpen({
|
|
675
|
+
sessions: domains.sessions,
|
|
676
|
+
transport,
|
|
677
|
+
surfaceMounted: () => status().surfaceMounted === true
|
|
678
|
+
}, sessionId, abort);
|
|
679
|
+
},
|
|
680
|
+
async replaceSurfaceForQualification() {
|
|
681
|
+
await enqueueRevision(async () => {
|
|
682
|
+
if (disposed) throw new Error("local client entry: the surface revision owner is already disposed");
|
|
683
|
+
const previous = currentRevision;
|
|
684
|
+
if (previous === void 0) throw new Error("local client entry: no mounted surface revision to replace");
|
|
685
|
+
const previousSessionId = openSessionIdFor(domains);
|
|
686
|
+
composition.onQualification?.({
|
|
687
|
+
op: "hmr-revision-start",
|
|
688
|
+
revision: revisionSequence + 1
|
|
689
|
+
});
|
|
690
|
+
previous.surfaceMounted = false;
|
|
691
|
+
emitStatus();
|
|
692
|
+
try {
|
|
693
|
+
await disposeRevision(previous);
|
|
694
|
+
} catch (error) {
|
|
695
|
+
composition.onQualification?.({
|
|
696
|
+
op: "hmr-revision-failure",
|
|
697
|
+
phase: "retire",
|
|
698
|
+
revision: previous.id,
|
|
699
|
+
error: error instanceof Error ? error.message : String(error)
|
|
700
|
+
});
|
|
701
|
+
throw error;
|
|
702
|
+
}
|
|
703
|
+
composition.onQualification?.({
|
|
704
|
+
op: "hmr-revision-retired",
|
|
705
|
+
revision: previous.id
|
|
706
|
+
});
|
|
707
|
+
try {
|
|
708
|
+
const next = await mountRevision("hmr", previousSessionId);
|
|
709
|
+
composition.onQualification?.({
|
|
710
|
+
op: "hmr-revision-ready",
|
|
711
|
+
revision: next.id,
|
|
712
|
+
pid: process.pid,
|
|
713
|
+
...next.runner?.fiberUid === void 0 ? {} : { fiberUid: next.runner.fiberUid },
|
|
714
|
+
...status().generationId === void 0 ? {} : { generationId: status().generationId }
|
|
715
|
+
});
|
|
716
|
+
} catch (error) {
|
|
717
|
+
const partial = currentRevision;
|
|
718
|
+
currentRevision = void 0;
|
|
719
|
+
const cleanupErrors = [];
|
|
720
|
+
if (partial !== void 0) try {
|
|
721
|
+
await disposeRevision(partial);
|
|
722
|
+
} catch (cleanupError) {
|
|
723
|
+
cleanupErrors.push(cleanupError);
|
|
724
|
+
}
|
|
725
|
+
composition.onQualification?.({
|
|
726
|
+
op: "hmr-revision-failure",
|
|
727
|
+
phase: "mount",
|
|
728
|
+
revision: revisionSequence,
|
|
729
|
+
error: error instanceof Error ? error.message : String(error)
|
|
730
|
+
});
|
|
731
|
+
let primary = error instanceof Error ? error : new Error(String(error));
|
|
732
|
+
for (const cleanupError of cleanupErrors) primary = mergeCause(primary, cleanupError);
|
|
733
|
+
throw primary;
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
},
|
|
737
|
+
async dispose() {
|
|
738
|
+
if (disposed) return;
|
|
739
|
+
disposed = true;
|
|
740
|
+
await revisionTasks.drain();
|
|
741
|
+
const errors = [];
|
|
742
|
+
const revision = currentRevision;
|
|
743
|
+
currentRevision = void 0;
|
|
744
|
+
if (revision !== void 0) try {
|
|
745
|
+
await disposeRevision(revision);
|
|
746
|
+
} catch (error) {
|
|
747
|
+
errors.push(error);
|
|
748
|
+
}
|
|
749
|
+
try {
|
|
750
|
+
delivery.dispose();
|
|
751
|
+
} catch (error) {
|
|
752
|
+
errors.push(error);
|
|
753
|
+
}
|
|
754
|
+
try {
|
|
755
|
+
await transport.dispose();
|
|
756
|
+
} catch (error) {
|
|
757
|
+
errors.push(error);
|
|
758
|
+
}
|
|
759
|
+
try {
|
|
760
|
+
await domains.dispose();
|
|
761
|
+
} catch (error) {
|
|
762
|
+
errors.push(error);
|
|
763
|
+
}
|
|
764
|
+
try {
|
|
765
|
+
await context.fiber.dispose();
|
|
766
|
+
} catch (error) {
|
|
767
|
+
errors.push(error);
|
|
768
|
+
}
|
|
769
|
+
throwDisposalErrors(errors, "local client surface");
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Mount the split surface's official Client Domain prerequisites on the root
|
|
775
|
+
* `Context` BEFORE the Gateway's first generation: the generated `/remote`
|
|
776
|
+
* contributions, the private pi-tui contribution, fileUpload and the official
|
|
777
|
+
* Session Client (the Agent scope resolver). The caller then registers the
|
|
778
|
+
* root interaction listeners, releases the official Loader gate, awaits the
|
|
779
|
+
* first generation and calls `complete()`.
|
|
780
|
+
*/
|
|
781
|
+
async function mountSurfaceClientDomainPrerequisites(context, options) {
|
|
782
|
+
return await mountRemoteClientDomainPrerequisites({
|
|
783
|
+
context,
|
|
784
|
+
dshAnchor: options.dshAnchor
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Mount the Client-local subtree on the supplied Client `Context` and report
|
|
789
|
+
* the live status. The caller owns the Context and must dispose this handle
|
|
790
|
+
* before the root; a construction failure unwinds exactly what this call
|
|
791
|
+
* mounted and never disposes the root twice.
|
|
792
|
+
*/
|
|
793
|
+
async function startLocalClient(context, startup, processStartIdentity, composition = {}) {
|
|
794
|
+
if (composition.transport === void 0 !== (composition.host === void 0)) throw new Error("local client entry: the official transport and the authenticated Host must be supplied together");
|
|
795
|
+
if (composition.mode === "surface") return await startSurfaceLocalClient(context, startup, processStartIdentity, composition);
|
|
796
|
+
if (composition.mode !== void 0 && composition.mode !== "qualification") throw new Error(`local client entry: unknown Client mode ${JSON.stringify(composition.mode)}`);
|
|
797
|
+
let ui;
|
|
798
|
+
try {
|
|
799
|
+
ui = await createRemoteClientUiRuntime({
|
|
800
|
+
context,
|
|
801
|
+
startup
|
|
802
|
+
});
|
|
803
|
+
} catch (error) {
|
|
804
|
+
throw error;
|
|
805
|
+
}
|
|
806
|
+
if (context.get("piTuiExtensions") === void 0) {
|
|
807
|
+
await ui.dispose();
|
|
808
|
+
throw new Error("local client entry: the Client-local extension host did not publish piTuiExtensions");
|
|
809
|
+
}
|
|
810
|
+
const { transport, host } = composition;
|
|
811
|
+
let disposed = false;
|
|
812
|
+
const startupFacts = startupFactsOf(startup);
|
|
813
|
+
return {
|
|
814
|
+
get status() {
|
|
815
|
+
const base = {
|
|
816
|
+
processRole: "client",
|
|
817
|
+
pid: process.pid,
|
|
818
|
+
...processStartIdentity === void 0 ? {} : { processStartIdentity },
|
|
819
|
+
phase: "client-local-ready",
|
|
820
|
+
sessionOpen: false,
|
|
821
|
+
surfaceMounted: false,
|
|
822
|
+
fiberOwner: "client-root",
|
|
823
|
+
...context.fiber.uid == null ? {} : { rootFiberUid: context.fiber.uid },
|
|
824
|
+
extensionService: { present: true },
|
|
825
|
+
startupFacts,
|
|
826
|
+
...host === void 0 ? {} : { host: hostFacts(host) }
|
|
827
|
+
};
|
|
828
|
+
if (transport === void 0) return {
|
|
829
|
+
...base,
|
|
830
|
+
transport: "not-connected"
|
|
831
|
+
};
|
|
832
|
+
const observed = transport.status();
|
|
833
|
+
return {
|
|
834
|
+
...base,
|
|
835
|
+
transport: observed.transport,
|
|
836
|
+
...observed.generationId === void 0 ? {} : { generationId: observed.generationId },
|
|
837
|
+
...observed.hostHome === void 0 ? {} : { hostHome: observed.hostHome },
|
|
838
|
+
activeWrappers: observed.activeWrappers,
|
|
839
|
+
liveSockets: observed.liveSockets
|
|
840
|
+
};
|
|
841
|
+
},
|
|
842
|
+
async replaceSurfaceForQualification() {
|
|
843
|
+
throw new Error("local client entry: surface replacement requires the internal surface mode");
|
|
844
|
+
},
|
|
845
|
+
async awaitHandoffOpen() {
|
|
846
|
+
throw new Error("local client entry: the handoff restore proof requires the internal surface mode");
|
|
847
|
+
},
|
|
848
|
+
async dispose() {
|
|
849
|
+
if (disposed) return;
|
|
850
|
+
disposed = true;
|
|
851
|
+
const errors = [];
|
|
852
|
+
try {
|
|
853
|
+
await ui.dispose();
|
|
854
|
+
} catch (error) {
|
|
855
|
+
errors.push(error);
|
|
856
|
+
}
|
|
857
|
+
try {
|
|
858
|
+
await transport?.dispose();
|
|
859
|
+
} catch (error) {
|
|
860
|
+
errors.push(error);
|
|
861
|
+
}
|
|
862
|
+
try {
|
|
863
|
+
await context.fiber.dispose();
|
|
864
|
+
} catch (error) {
|
|
865
|
+
errors.push(error);
|
|
866
|
+
}
|
|
867
|
+
throwDisposalErrors(errors, "local client");
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
//#endregion
|
|
872
|
+
export { mountSurfaceClientDomainPrerequisites, startLocalClient };
|