@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
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
1
|
+
import { a as PI_TUI_EXTENSIONS_SERVICE, n as extensions_exports } from "./extensions-pcFiH7Qe.mjs";
|
|
2
|
+
import { n as TUI_STARTUP_SERVICE } from "./startup-Ct2UUjUL.mjs";
|
|
3
|
+
import { C as safeErrorMessage, d as parseFooterCustomItems, g as resolveUserLayerFooterMode, h as resolveUserCommandItemFallbackActivationIds, m as resolveUserCommandItemActivationIds, p as resolveTrustedFooterCommand, v as cancellationError, y as isCancellation } from "./custom-items-CKrOBCox.mjs";
|
|
4
|
+
import { C as deliveredFileReadErrorFrom, F as providerOptionsFor, I as providerProfileProjectionOf, L as SupersededReadError, P as getPath, R as contextPressureOccupancy, S as DeliveredFileReadError, T as clientOwnerOf, a as detachInspection, c as detachPluginManagerSnapshot, f as QuestionAnswerError, g as classifySubagentPromptSettlement, h as detachedTurnOutline, i as detachChange, l as pluginInstallRequestId, m as detachedSessionStatus, n as createRemoteTerminalProgressSource, o as detachLog, r as PluginManagerStaleResultError, s as detachPhase, v as GATEWAY_PRE_INVOCATION_CODES, x as REMOTE_IMPLEMENTED_CAPABILITIES, y as isRemoteBusinessRefusalCode } from "./terminal-progress-source-CsBinCJ_.mjs";
|
|
5
5
|
import { t as builtins_exports } from "./builtins.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { n as PI_TUI_CLIENT_CONTRIBUTION, t as mergeCause } from "./dispose-cause-BzcXo4hu.mjs";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
|
+
import { realpathSync } from "node:fs";
|
|
8
9
|
import { randomUUID } from "node:crypto";
|
|
10
|
+
import { pathToFileURL } from "node:url";
|
|
9
11
|
import { Context } from "@deepseek-ai/cordis";
|
|
10
12
|
import * as sessionLogExport from "@deepseek-ai/dsh-session-log-export";
|
|
13
|
+
import * as clientStore from "@deepseek-ai/dsh-client-store";
|
|
11
14
|
import commandsRemote from "@deepseek-ai/dsh-commands/remote";
|
|
12
15
|
import subagentsRemote from "@deepseek-ai/dsh-subagent/remote";
|
|
13
16
|
import agentPresetsRemote from "@deepseek-ai/dsh-agent-preset-registry/remote";
|
|
@@ -27,7 +30,6 @@ import { HostConnectionService } from "@deepseek-ai/dsh-client-connection";
|
|
|
27
30
|
import FileUploads from "@deepseek-ai/dsh-client-file-upload";
|
|
28
31
|
import * as sessionStats from "@deepseek-ai/dsh-session-stats";
|
|
29
32
|
import * as sessionTurnOutline from "@deepseek-ai/dsh-session-turn-outline";
|
|
30
|
-
import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
31
33
|
//#region src/runtime/remote/write-failure.ts
|
|
32
34
|
/**
|
|
33
35
|
* Remote write settlement classification (D2.2): map one official Client
|
|
@@ -288,7 +290,33 @@ function copyProviderEntry(entry) {
|
|
|
288
290
|
* Invalidations only bump the counter (the snapshot stays readable as the
|
|
289
291
|
* last-known display value); no unowned background promise is started.
|
|
290
292
|
*/
|
|
293
|
+
/**
|
|
294
|
+
* The ONE accepted-write lifetime counter of the Remote configuration port.
|
|
295
|
+
* Every write sink (the settings mirror's `mutate` and the credential
|
|
296
|
+
* reference writes) brackets its accepted work; the Client reload safety gate
|
|
297
|
+
* reads the count so it can never retire the Client while a persisted
|
|
298
|
+
* configuration write is still in flight. Read-only calls never register.
|
|
299
|
+
*/
|
|
300
|
+
var RemoteConfigWriteLifetime = class {
|
|
301
|
+
pending = 0;
|
|
302
|
+
/** Register one accepted write; the returned release is idempotent. */
|
|
303
|
+
begin() {
|
|
304
|
+
this.pending += 1;
|
|
305
|
+
let released = false;
|
|
306
|
+
return () => {
|
|
307
|
+
if (released) return;
|
|
308
|
+
released = true;
|
|
309
|
+
this.pending -= 1;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
hasUnsettledWrites() {
|
|
313
|
+
return this.pending > 0;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
291
316
|
var RemoteConfigMirror = class {
|
|
317
|
+
/** The accepted-write lifetime owner (the serialized chain below is
|
|
318
|
+
* `writes`, its internal queue). */
|
|
319
|
+
writeLifetime;
|
|
292
320
|
settings;
|
|
293
321
|
llm;
|
|
294
322
|
permissionPresets;
|
|
@@ -311,7 +339,8 @@ var RemoteConfigMirror = class {
|
|
|
311
339
|
* synchronously-notified generation subscription cannot start a read
|
|
312
340
|
* before construction finishes. */
|
|
313
341
|
constructed = false;
|
|
314
|
-
constructor(source, on) {
|
|
342
|
+
constructor(source, on, writeLifetime) {
|
|
343
|
+
this.writeLifetime = writeLifetime;
|
|
315
344
|
this.settings = source.remote.settings;
|
|
316
345
|
this.llm = source.remote.llm;
|
|
317
346
|
this.permissionPresets = source.remote.permissionPresets;
|
|
@@ -519,36 +548,41 @@ var RemoteConfigMirror = class {
|
|
|
519
548
|
* authority itself and reports accepted-but-unverified instead of a refusal.
|
|
520
549
|
*/
|
|
521
550
|
async mutate(ns, ops, baseRevision, refreshFailure = "reject") {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
this.
|
|
551
|
+
const endWrite = this.writeLifetime.begin();
|
|
552
|
+
try {
|
|
553
|
+
await this.enqueueWrite(async () => {
|
|
554
|
+
await this.ensureCurrent();
|
|
555
|
+
const snapshot = this.lastKnown();
|
|
556
|
+
if (snapshot === void 0 || !this.isCurrent()) {
|
|
557
|
+
if (snapshot?.settingsFailure instanceof Error) throw new Error(`settings.describe failed: ${snapshot.settingsFailure.message}`);
|
|
558
|
+
throw new Error(this.generation.getSnapshot() === void 0 ? "the Remote configuration is unavailable on this connection; the change was not saved" : snapshot === void 0 ? "the Remote configuration has not been read yet; the change was not saved" : "the Remote configuration is not current; the change was not saved");
|
|
559
|
+
}
|
|
560
|
+
if (ops.length === 0) return;
|
|
561
|
+
const descriptor = snapshot.namespaces?.get(ns);
|
|
562
|
+
if (descriptor === void 0) throw new Error(`settings namespace "${ns}" is not available in this deployment`);
|
|
563
|
+
const result = await settledResult(this.settings.mutate(ns, [...ops], baseRevision ?? descriptor.revision));
|
|
564
|
+
if (!result.ok) {
|
|
565
|
+
this.invalidate();
|
|
566
|
+
try {
|
|
567
|
+
await this.describe();
|
|
568
|
+
} catch (error) {
|
|
569
|
+
this.recordFailure(error);
|
|
570
|
+
}
|
|
571
|
+
throw new Error(`settings.mutate(${ns}) failed: ${remoteFailureMessage(result.error)}`);
|
|
572
|
+
}
|
|
573
|
+
if (refreshFailure === "reject") {
|
|
574
|
+
await this.describe();
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
535
577
|
try {
|
|
536
578
|
await this.describe();
|
|
537
579
|
} catch (error) {
|
|
538
580
|
this.recordFailure(error);
|
|
539
581
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
try {
|
|
547
|
-
await this.describe();
|
|
548
|
-
} catch (error) {
|
|
549
|
-
this.recordFailure(error);
|
|
550
|
-
}
|
|
551
|
-
});
|
|
582
|
+
});
|
|
583
|
+
} finally {
|
|
584
|
+
endWrite();
|
|
585
|
+
}
|
|
552
586
|
}
|
|
553
587
|
/** Drop the cached snapshot (and any in-flight read's publication right). */
|
|
554
588
|
disposeCache() {
|
|
@@ -964,12 +998,14 @@ var RemoteCredentialConfig = class {
|
|
|
964
998
|
credentials;
|
|
965
999
|
generation;
|
|
966
1000
|
on;
|
|
1001
|
+
writeLifetime;
|
|
967
1002
|
/** Every active listener subscription, so dispose() releases them once. */
|
|
968
1003
|
active = /* @__PURE__ */ new Set();
|
|
969
|
-
constructor(credentials, on, generation) {
|
|
1004
|
+
constructor(credentials, on, generation, writeLifetime) {
|
|
970
1005
|
this.credentials = credentials;
|
|
971
1006
|
this.on = on;
|
|
972
1007
|
this.generation = generation;
|
|
1008
|
+
this.writeLifetime = writeLifetime;
|
|
973
1009
|
}
|
|
974
1010
|
available() {
|
|
975
1011
|
return this.generation.getSnapshot() !== void 0;
|
|
@@ -999,13 +1035,23 @@ var RemoteCredentialConfig = class {
|
|
|
999
1035
|
}
|
|
1000
1036
|
async setReference(ref, secret) {
|
|
1001
1037
|
this.requireDispatchableGeneration();
|
|
1002
|
-
const
|
|
1003
|
-
|
|
1038
|
+
const endWrite = this.writeLifetime.begin();
|
|
1039
|
+
try {
|
|
1040
|
+
const result = await settledResult(this.credentials.set(ref, secret));
|
|
1041
|
+
if (!result.ok) throw new Error(`credentials.set(${ref}) failed: ${remoteFailureMessage(result.error)}`);
|
|
1042
|
+
} finally {
|
|
1043
|
+
endWrite();
|
|
1044
|
+
}
|
|
1004
1045
|
}
|
|
1005
1046
|
async unsetReference(ref) {
|
|
1006
1047
|
this.requireDispatchableGeneration();
|
|
1007
|
-
const
|
|
1008
|
-
|
|
1048
|
+
const endWrite = this.writeLifetime.begin();
|
|
1049
|
+
try {
|
|
1050
|
+
const result = await settledResult(this.credentials.unset(ref));
|
|
1051
|
+
if (!result.ok) throw new Error(`credentials.unset(${ref}) failed: ${remoteFailureMessage(result.error)}`);
|
|
1052
|
+
} finally {
|
|
1053
|
+
endWrite();
|
|
1054
|
+
}
|
|
1009
1055
|
}
|
|
1010
1056
|
async describeReference(ref) {
|
|
1011
1057
|
const captured = this.generation.getSnapshot();
|
|
@@ -1254,6 +1300,8 @@ var RemoteConfigPort = class {
|
|
|
1254
1300
|
mirror;
|
|
1255
1301
|
tuiSettingsWrapper;
|
|
1256
1302
|
credentialConfig;
|
|
1303
|
+
/** The ONE accepted-write lifetime of this port (settings + credentials). */
|
|
1304
|
+
writes = new RemoteConfigWriteLifetime();
|
|
1257
1305
|
footerCommandTrust;
|
|
1258
1306
|
footerCustomItems;
|
|
1259
1307
|
providers;
|
|
@@ -1276,12 +1324,12 @@ var RemoteConfigPort = class {
|
|
|
1276
1324
|
remote: source.remote,
|
|
1277
1325
|
connection: source.connection
|
|
1278
1326
|
};
|
|
1279
|
-
this.mirror = new RemoteConfigMirror(bound, on);
|
|
1327
|
+
this.mirror = new RemoteConfigMirror(bound, on, this.writes);
|
|
1280
1328
|
this.tuiSettingsWrapper = new RemoteTuiSettingsConfig(this.mirror);
|
|
1281
1329
|
this.footerCommandTrust = new RemoteFooterCommandTrust(this.mirror);
|
|
1282
1330
|
this.footerCustomItems = new RemoteFooterCustomItems(this.mirror);
|
|
1283
1331
|
this.providers = new RemoteProviderProfileConfig(this.mirror);
|
|
1284
|
-
this.credentialConfig = new RemoteCredentialConfig(bound.remote.credentials, on, source.connection.generation);
|
|
1332
|
+
this.credentialConfig = new RemoteCredentialConfig(bound.remote.credentials, on, source.connection.generation, this.writes);
|
|
1285
1333
|
this.credentials = this.credentialConfig;
|
|
1286
1334
|
this.authorization = new RemoteAuthorizationConfig();
|
|
1287
1335
|
this.account = new RemoteUnsupportedAccountConfig();
|
|
@@ -1308,6 +1356,10 @@ var RemoteConfigPort = class {
|
|
|
1308
1356
|
readiness() {
|
|
1309
1357
|
return this.mirror.readiness();
|
|
1310
1358
|
}
|
|
1359
|
+
/** Whether an accepted persisted configuration write is still unsettled. */
|
|
1360
|
+
hasUnsettledWrites() {
|
|
1361
|
+
return this.writes.hasUnsettledWrites();
|
|
1362
|
+
}
|
|
1311
1363
|
/** The semantic currentness signal (§9.1): the UI marks last-known values
|
|
1312
1364
|
* non-current and refuses writes while this is not `ready`. */
|
|
1313
1365
|
configReadiness() {
|
|
@@ -1492,127 +1544,6 @@ function createRemoteBackend(parts) {
|
|
|
1492
1544
|
};
|
|
1493
1545
|
}
|
|
1494
1546
|
//#endregion
|
|
1495
|
-
//#region src/runtime/remote/pi-tui-file-reference-contract.ts
|
|
1496
|
-
/** The wire namespace (and Host Cordis service key) of the augmentation. */
|
|
1497
|
-
const PI_TUI_FILE_REFERENCES_NAMESPACE = "piTuiFileReferences";
|
|
1498
|
-
/** The private method's stable endpoint identity. */
|
|
1499
|
-
const PI_TUI_FILE_REFERENCES_LIST_ENDPOINT = "@xmoon76/dsh-pi-tui#piTuiFileReferences/list";
|
|
1500
|
-
/** One strict JSON codec that validates a wire string. */
|
|
1501
|
-
function stringCodec(typeSymbol) {
|
|
1502
|
-
return {
|
|
1503
|
-
mode: "strict",
|
|
1504
|
-
typeSymbol,
|
|
1505
|
-
create: () => ({ parse: (value) => {
|
|
1506
|
-
if (typeof value !== "string") throw new TypeError(`${typeSymbol}: the wire value must be a string`);
|
|
1507
|
-
return value;
|
|
1508
|
-
} })
|
|
1509
|
-
};
|
|
1510
|
-
}
|
|
1511
|
-
/**
|
|
1512
|
-
* Validate and detach one wire `HostFileListResult`. The result is produced by
|
|
1513
|
-
* this package's own Host router, but it is still a wire boundary on the Client
|
|
1514
|
-
* and the ONLY place the shape crosses.
|
|
1515
|
-
*/
|
|
1516
|
-
function decodeHostFileListResult(value) {
|
|
1517
|
-
if (typeof value !== "object" || value === null) throw new TypeError("piTuiFileReferences/list: the result must be an object");
|
|
1518
|
-
const record = value;
|
|
1519
|
-
if (record.kind === "unavailable") {
|
|
1520
|
-
if (typeof record.reason !== "string") throw new TypeError("piTuiFileReferences/list: an unavailable result needs a reason");
|
|
1521
|
-
return {
|
|
1522
|
-
kind: "unavailable",
|
|
1523
|
-
reason: record.reason
|
|
1524
|
-
};
|
|
1525
|
-
}
|
|
1526
|
-
if (record.kind !== "ok" || !Array.isArray(record.items)) throw new TypeError("piTuiFileReferences/list: the result must be ok(items) or unavailable(reason)");
|
|
1527
|
-
return {
|
|
1528
|
-
kind: "ok",
|
|
1529
|
-
items: record.items.map((entry) => {
|
|
1530
|
-
if (typeof entry !== "object" || entry === null) throw new TypeError("piTuiFileReferences/list: every candidate must be an object");
|
|
1531
|
-
const candidate = entry;
|
|
1532
|
-
if (typeof candidate.path !== "string" || candidate.kind !== "file" && candidate.kind !== "directory") throw new TypeError("piTuiFileReferences/list: every candidate needs a string path and a file/directory kind");
|
|
1533
|
-
return {
|
|
1534
|
-
path: candidate.path,
|
|
1535
|
-
kind: candidate.kind
|
|
1536
|
-
};
|
|
1537
|
-
})
|
|
1538
|
-
};
|
|
1539
|
-
}
|
|
1540
|
-
const HOST_FILE_LIST_RESULT_CODEC = {
|
|
1541
|
-
mode: "strict",
|
|
1542
|
-
typeSymbol: "@xmoon76/dsh-pi-tui#piTuiFileReferences/list:result",
|
|
1543
|
-
create: () => ({ parse: decodeHostFileListResult }),
|
|
1544
|
-
decode: decodeHostFileListResult
|
|
1545
|
-
};
|
|
1546
|
-
/**
|
|
1547
|
-
* The ONE shared invocation descriptor both contributions derive from. The
|
|
1548
|
-
* Host registers this exact object; the Client mounts this exact object.
|
|
1549
|
-
*/
|
|
1550
|
-
const PI_TUI_FILE_REFERENCES_LIST = {
|
|
1551
|
-
id: PI_TUI_FILE_REFERENCES_LIST_ENDPOINT,
|
|
1552
|
-
service: PI_TUI_FILE_REFERENCES_NAMESPACE,
|
|
1553
|
-
namespace: PI_TUI_FILE_REFERENCES_NAMESPACE,
|
|
1554
|
-
method: "list",
|
|
1555
|
-
invocation: { kind: "direct" },
|
|
1556
|
-
parameters: [{
|
|
1557
|
-
name: "sessionId",
|
|
1558
|
-
wire: "sessionId",
|
|
1559
|
-
source: "json",
|
|
1560
|
-
codec: stringCodec("@xmoon76/dsh-pi-tui#piTuiFileReferences/list:sessionId")
|
|
1561
|
-
}, {
|
|
1562
|
-
name: "query",
|
|
1563
|
-
wire: "query",
|
|
1564
|
-
source: "json",
|
|
1565
|
-
codec: stringCodec("@xmoon76/dsh-pi-tui#piTuiFileReferences/list:query")
|
|
1566
|
-
}],
|
|
1567
|
-
cancellation: { parameter: "signal" },
|
|
1568
|
-
result: HOST_FILE_LIST_RESULT_CODEC
|
|
1569
|
-
};
|
|
1570
|
-
//#endregion
|
|
1571
|
-
//#region src/runtime/remote/pi-tui-remote-contribution.ts
|
|
1572
|
-
/** The npm package that owns every private Remote invocation here. A test
|
|
1573
|
-
* guards that it equals each contract module's own package constant. */
|
|
1574
|
-
const PI_TUI_REMOTE_PACKAGE = "@xmoon76/dsh-pi-tui";
|
|
1575
|
-
/** The explicit Host contribution registered once with `ctx.typert.register`. */
|
|
1576
|
-
const PI_TUI_HOST_CONTRIBUTION = {
|
|
1577
|
-
package: PI_TUI_REMOTE_PACKAGE,
|
|
1578
|
-
face: "host",
|
|
1579
|
-
schemas: [],
|
|
1580
|
-
model: {
|
|
1581
|
-
services: [],
|
|
1582
|
-
events: [],
|
|
1583
|
-
objects: []
|
|
1584
|
-
},
|
|
1585
|
-
invocations: [PI_TUI_FILE_REFERENCES_LIST, PI_TUI_TERMINAL_PROGRESS_WATCH]
|
|
1586
|
-
};
|
|
1587
|
-
/** The explicit Client contribution mounted once with `ctx.remote.$mount`. */
|
|
1588
|
-
const PI_TUI_CLIENT_CONTRIBUTION = {
|
|
1589
|
-
package: PI_TUI_REMOTE_PACKAGE,
|
|
1590
|
-
descriptors: [PI_TUI_FILE_REFERENCES_LIST, PI_TUI_TERMINAL_PROGRESS_WATCH]
|
|
1591
|
-
};
|
|
1592
|
-
//#endregion
|
|
1593
|
-
//#region src/app/remote/dispose-cause.ts
|
|
1594
|
-
/**
|
|
1595
|
-
* Transport-neutral disposal failure chaining for the Remote composition.
|
|
1596
|
-
*
|
|
1597
|
-
* The helper is shared by the Host composition, the official Client runtime,
|
|
1598
|
-
* the Client UI subtree and the application aggregate. It deliberately lives
|
|
1599
|
-
* beside them (not inside `host-runtime.ts`) so a Client-only process entry can
|
|
1600
|
-
* reuse it without importing a Host-only value graph.
|
|
1601
|
-
*
|
|
1602
|
-
* @module app/remote/dispose-cause
|
|
1603
|
-
*/
|
|
1604
|
-
/**
|
|
1605
|
-
* Attach one secondary failure to `failure`'s cause chain without losing an
|
|
1606
|
-
* existing cause: when the failure already carries a cause, both aggregate
|
|
1607
|
-
* into a single `AggregateError`. A `undefined` secondary is a no-op.
|
|
1608
|
-
*/
|
|
1609
|
-
function mergeCause(failure, secondary) {
|
|
1610
|
-
if (secondary === void 0) return failure;
|
|
1611
|
-
const existingCause = failure.cause;
|
|
1612
|
-
failure.cause = existingCause === void 0 ? secondary : new AggregateError([existingCause, secondary], "remote composition: aggregated failure causes");
|
|
1613
|
-
return failure;
|
|
1614
|
-
}
|
|
1615
|
-
//#endregion
|
|
1616
1547
|
//#region src/app/remote/client-runtime.ts
|
|
1617
1548
|
/**
|
|
1618
1549
|
* Experimental official Client runtime composition (M3-1).
|
|
@@ -1670,6 +1601,24 @@ const OFFICIAL_CLIENT_BUNDLES = [
|
|
|
1670
1601
|
];
|
|
1671
1602
|
/** Expected registration ids, in dependency order. */
|
|
1672
1603
|
const EXPECTED_REGISTRATION_IDS = OFFICIAL_CLIENT_BUNDLES.map((bundle) => bundle.id);
|
|
1604
|
+
/**
|
|
1605
|
+
* The official web shell's platform static modules, which the browser-form
|
|
1606
|
+
* `/client` bundles resolve through the Loader's `require` (the published web
|
|
1607
|
+
* seed shares exactly these singletons). The Node Client shell is that shell:
|
|
1608
|
+
* it supplies the installed Harness-family `@deepseek-ai/dsh-client-store`
|
|
1609
|
+
* instance instead of relying on a transitive resolution from a bundle's own
|
|
1610
|
+
* package graph. `@deepseek-ai/cordis` is imported directly by this module and
|
|
1611
|
+
* therefore already resolves normally.
|
|
1612
|
+
*/
|
|
1613
|
+
const CLIENT_PLATFORM_MODULES = { "@deepseek-ai/dsh-client-store": clientStore };
|
|
1614
|
+
/** The loader's bare-dependency resolver: platform statics first, then the
|
|
1615
|
+
* CALLER's installation resolver. The real Client passes the DSH anchor
|
|
1616
|
+
* resolver so every non-platform dependency of a browser-form bundle also
|
|
1617
|
+
* resolves from the anchored installation, never from an unrelated source
|
|
1618
|
+
* tree. */
|
|
1619
|
+
function createPlatformRequire(fallback) {
|
|
1620
|
+
return (specifier) => Object.hasOwn(CLIENT_PLATFORM_MODULES, specifier) ? CLIENT_PLATFORM_MODULES[specifier] : fallback(specifier);
|
|
1621
|
+
}
|
|
1673
1622
|
/** Process-wide single-flight capture; module code evaluates once per process. */
|
|
1674
1623
|
let officialClientModulesPromise;
|
|
1675
1624
|
/**
|
|
@@ -1707,8 +1656,8 @@ function loadOfficialClientModulesOnce() {
|
|
|
1707
1656
|
* before its dependency-order capture; admit a directly imported Node bundle
|
|
1708
1657
|
* for an id the loader did not register; report missing expected ids.
|
|
1709
1658
|
*/
|
|
1710
|
-
function createScopedClientModuleLoader(expectedIds) {
|
|
1711
|
-
const nodeRequire =
|
|
1659
|
+
function createScopedClientModuleLoader(expectedIds, requireFrom = createRequire(import.meta.url)) {
|
|
1660
|
+
const nodeRequire = requireFrom;
|
|
1712
1661
|
const registrations = /* @__PURE__ */ new Map();
|
|
1713
1662
|
const captured = /* @__PURE__ */ new Map();
|
|
1714
1663
|
const requireModule = (specifier) => {
|
|
@@ -1799,7 +1748,7 @@ function installScopedModuleLoaderShim(load) {
|
|
|
1799
1748
|
return restore;
|
|
1800
1749
|
}
|
|
1801
1750
|
async function captureOfficialClientModules() {
|
|
1802
|
-
const loader = createScopedClientModuleLoader(EXPECTED_REGISTRATION_IDS);
|
|
1751
|
+
const loader = createScopedClientModuleLoader(EXPECTED_REGISTRATION_IDS, createPlatformRequire(createRequire(import.meta.url)));
|
|
1803
1752
|
const restoreShim = installScopedModuleLoaderShim(loader.load);
|
|
1804
1753
|
try {
|
|
1805
1754
|
for (const bundle of OFFICIAL_CLIENT_BUNDLES) loader.acceptImported(bundle.id, await import(bundle.specifier));
|
|
@@ -1839,6 +1788,76 @@ const REMOTE_CONTRIBUTIONS = [
|
|
|
1839
1788
|
workspaceFilesRemote
|
|
1840
1789
|
];
|
|
1841
1790
|
/**
|
|
1791
|
+
* The exact generated `/remote` contribution specifiers in the SAME frozen
|
|
1792
|
+
* order as {@link REMOTE_CONTRIBUTIONS}. A real installed Client process
|
|
1793
|
+
* resolves THESE from its DSH installation anchor instead of consuming the
|
|
1794
|
+
* statically imported source-tree copy; both channels produce the one table
|
|
1795
|
+
* `mountRemoteClientDomains` mounts.
|
|
1796
|
+
*/
|
|
1797
|
+
const REMOTE_CONTRIBUTION_SPECIFIERS = [
|
|
1798
|
+
"@deepseek-ai/dsh-api-session-controller/remote",
|
|
1799
|
+
"@deepseek-ai/dsh-api-job-controller/remote",
|
|
1800
|
+
"@deepseek-ai/dsh-commands/remote",
|
|
1801
|
+
"@deepseek-ai/dsh-subagent/remote",
|
|
1802
|
+
"@deepseek-ai/dsh-agent-preset-registry/remote",
|
|
1803
|
+
"@deepseek-ai/dsh-plugin-manager/remote",
|
|
1804
|
+
"@deepseek-ai/dsh-api-settings-controller/remote",
|
|
1805
|
+
"@deepseek-ai/dsh-permission-presets/remote",
|
|
1806
|
+
"@deepseek-ai/dsh-llm/remote",
|
|
1807
|
+
"@deepseek-ai/dsh-client-file-upload/remote",
|
|
1808
|
+
"@deepseek-ai/dsh-user-questions/remote",
|
|
1809
|
+
"@deepseek-ai/dsh-api-workspace-files/remote"
|
|
1810
|
+
];
|
|
1811
|
+
/** Per-installation single-flight captures, keyed by the real anchor path. */
|
|
1812
|
+
const installedClientDomainModules = /* @__PURE__ */ new Map();
|
|
1813
|
+
/** Capture the six official `/client` bundles through the installation anchor. */
|
|
1814
|
+
async function captureInstalledOfficialClientModules(requireFromAnchor) {
|
|
1815
|
+
const loader = createScopedClientModuleLoader(EXPECTED_REGISTRATION_IDS, createPlatformRequire(requireFromAnchor));
|
|
1816
|
+
const restoreShim = installScopedModuleLoaderShim(loader.load);
|
|
1817
|
+
try {
|
|
1818
|
+
for (const bundle of OFFICIAL_CLIENT_BUNDLES) {
|
|
1819
|
+
const resolved = requireFromAnchor.resolve(bundle.specifier);
|
|
1820
|
+
loader.acceptImported(bundle.id, await import(pathToFileURL(resolved).href));
|
|
1821
|
+
}
|
|
1822
|
+
loader.assertComplete();
|
|
1823
|
+
} finally {
|
|
1824
|
+
restoreShim();
|
|
1825
|
+
}
|
|
1826
|
+
const captured = /* @__PURE__ */ new Map();
|
|
1827
|
+
for (const id of EXPECTED_REGISTRATION_IDS) captured.set(id, loader.requireModule(`${id}/client`));
|
|
1828
|
+
return freezeOfficialClientModules(captured);
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Capture ONE installed DSH generation's whole Client domain composition: the
|
|
1832
|
+
* six official `/client` bundles and the generated `/remote` contributions,
|
|
1833
|
+
* every specifier resolved from `dshAnchor`. A rejection stays cached (fail
|
|
1834
|
+
* fast; a retry cannot succeed because ESM evaluates the bundles once).
|
|
1835
|
+
*/
|
|
1836
|
+
async function captureInstalledClientDomainModules(anchor) {
|
|
1837
|
+
const requireFromAnchor = createRequire(anchor);
|
|
1838
|
+
const modules = await captureInstalledOfficialClientModules(requireFromAnchor);
|
|
1839
|
+
const contributions = [];
|
|
1840
|
+
for (const specifier of REMOTE_CONTRIBUTION_SPECIFIERS) {
|
|
1841
|
+
const contribution = (await import(pathToFileURL(requireFromAnchor.resolve(specifier)).href)).default;
|
|
1842
|
+
if (typeof contribution !== "object" || contribution === null || !Array.isArray(contribution.descriptors)) throw new Error(`remote client domains: installed ${specifier} is not a generated Remote contribution`);
|
|
1843
|
+
contributions.push(contribution);
|
|
1844
|
+
}
|
|
1845
|
+
return {
|
|
1846
|
+
modules,
|
|
1847
|
+
contributions
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
/** Load the Client domain composition from one installed DSH anchor (single-flight). */
|
|
1851
|
+
function loadInstalledClientDomainModules(dshAnchor) {
|
|
1852
|
+
const anchor = realpathSync(dshAnchor);
|
|
1853
|
+
let pending = installedClientDomainModules.get(anchor);
|
|
1854
|
+
if (pending === void 0) {
|
|
1855
|
+
pending = captureInstalledClientDomainModules(anchor);
|
|
1856
|
+
installedClientDomainModules.set(anchor, pending);
|
|
1857
|
+
}
|
|
1858
|
+
return pending;
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1842
1861
|
* Reverse-dispose the recorded `/remote` contribution disposers. Per-step
|
|
1843
1862
|
* error isolation: one rejecting disposer cannot truncate the remaining
|
|
1844
1863
|
* cleanup. Returns the collected cleanup errors in encounter order.
|
|
@@ -1856,13 +1875,133 @@ async function disposeRemoteContributions(disposers) {
|
|
|
1856
1875
|
}
|
|
1857
1876
|
return errors;
|
|
1858
1877
|
}
|
|
1878
|
+
/** Reverse-order Domain teardown. Contribution failures are isolated. */
|
|
1879
|
+
async function shutdownDomainState(state) {
|
|
1880
|
+
if (state.disposed) return [];
|
|
1881
|
+
state.disposed = true;
|
|
1882
|
+
for (const fiber of [
|
|
1883
|
+
state.jobsFiber,
|
|
1884
|
+
state.sessionFiber,
|
|
1885
|
+
state.fileUploadFiber
|
|
1886
|
+
]) await fiber?.dispose();
|
|
1887
|
+
state.jobsFiber = void 0;
|
|
1888
|
+
state.sessionFiber = void 0;
|
|
1889
|
+
state.fileUploadFiber = void 0;
|
|
1890
|
+
const contributionErrors = await disposeRemoteContributions(state.contributionDisposers);
|
|
1891
|
+
state.contributionDisposers.length = 0;
|
|
1892
|
+
return contributionErrors;
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Mount the official Client Domain prerequisites on the caller's
|
|
1896
|
+
* ALREADY-AUTHENTICATED Client `Context`: the twelve generated `/remote`
|
|
1897
|
+
* contributions, the private pi-tui contribution, the official fileUpload
|
|
1898
|
+
* Client, then the official Session Client (which registers the `agent`
|
|
1899
|
+
* `typert.contexts` resolver). It deliberately does NOT wait for a Connection
|
|
1900
|
+
* generation: the split Client must mount the Session resolver and its root
|
|
1901
|
+
* interaction listeners before the official Gateway starts its event pump.
|
|
1902
|
+
*
|
|
1903
|
+
* Failure semantics: a construction failure unwinds exactly what this stage
|
|
1904
|
+
* created, in reverse order; the original error stays primary and any cleanup
|
|
1905
|
+
* failures ride its cause chain.
|
|
1906
|
+
*/
|
|
1907
|
+
async function mountRemoteClientDomainPrerequisites(options) {
|
|
1908
|
+
const { context } = options;
|
|
1909
|
+
const connection = context.get("connection");
|
|
1910
|
+
const remote = context.get("remote");
|
|
1911
|
+
if (context.get("typert") === void 0 || connection === void 0 || remote === void 0) throw new Error("remote client domains: the caller must install typert, the authenticated connection and the API gateway first");
|
|
1912
|
+
const source = options.dshAnchor === void 0 ? {
|
|
1913
|
+
modules: await loadOfficialClientModulesOnce(),
|
|
1914
|
+
contributions: REMOTE_CONTRIBUTIONS
|
|
1915
|
+
} : await loadInstalledClientDomainModules(options.dshAnchor);
|
|
1916
|
+
const state = {
|
|
1917
|
+
context,
|
|
1918
|
+
connection,
|
|
1919
|
+
remote,
|
|
1920
|
+
sessions: void 0,
|
|
1921
|
+
contributionDisposers: [],
|
|
1922
|
+
disposed: false
|
|
1923
|
+
};
|
|
1924
|
+
const unwind = async (error) => {
|
|
1925
|
+
const cleanupErrors = await shutdownDomainState(state);
|
|
1926
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
1927
|
+
if (cleanupErrors.length > 0) {
|
|
1928
|
+
const secondary = cleanupErrors.length === 1 ? cleanupErrors[0] : new AggregateError(cleanupErrors, "remote client domains: unwind disposal failures");
|
|
1929
|
+
mergeCause(failure, secondary);
|
|
1930
|
+
}
|
|
1931
|
+
throw failure;
|
|
1932
|
+
};
|
|
1933
|
+
try {
|
|
1934
|
+
for (const contribution of source.contributions) state.contributionDisposers.push(await remote.$mount(contribution));
|
|
1935
|
+
state.contributionDisposers.push(await remote.$mount(PI_TUI_CLIENT_CONTRIBUTION));
|
|
1936
|
+
state.fileUploadFiber = context.plugin(source.modules.fileUpload);
|
|
1937
|
+
await state.fileUploadFiber;
|
|
1938
|
+
state.sessionFiber = context.plugin(source.modules.session);
|
|
1939
|
+
await state.sessionFiber;
|
|
1940
|
+
state.sessions = context.get("sessions");
|
|
1941
|
+
if (state.sessions === void 0) throw new Error("remote client domains: the official Session Client did not install");
|
|
1942
|
+
} catch (error) {
|
|
1943
|
+
return await unwind(error);
|
|
1944
|
+
}
|
|
1945
|
+
return {
|
|
1946
|
+
context,
|
|
1947
|
+
connection,
|
|
1948
|
+
remote,
|
|
1949
|
+
sessions: state.sessions,
|
|
1950
|
+
async complete(completeOptions = {}) {
|
|
1951
|
+
if (state.disposed) throw new Error("remote client domains: the prerequisites were already disposed");
|
|
1952
|
+
state.completion ??= (async () => {
|
|
1953
|
+
try {
|
|
1954
|
+
state.jobsFiber = context.plugin(source.modules.jobs);
|
|
1955
|
+
await state.jobsFiber;
|
|
1956
|
+
await waitForInitialReadiness(connection, state.sessions, completeOptions.signal);
|
|
1957
|
+
const jobs = context.get("jobs");
|
|
1958
|
+
if (jobs === void 0) throw new Error("remote client domains: the official Jobs Client did not install");
|
|
1959
|
+
return {
|
|
1960
|
+
context,
|
|
1961
|
+
connection,
|
|
1962
|
+
sessions: state.sessions,
|
|
1963
|
+
jobs,
|
|
1964
|
+
remote,
|
|
1965
|
+
async dispose() {
|
|
1966
|
+
const cleanupErrors = await shutdownDomainState(state);
|
|
1967
|
+
if (cleanupErrors.length === 0) return;
|
|
1968
|
+
const failure = cleanupErrors[0] instanceof Error ? cleanupErrors[0] : new Error(String(cleanupErrors[0]));
|
|
1969
|
+
if (cleanupErrors.length > 1) mergeCause(failure, new AggregateError(cleanupErrors.slice(1), "remote client domains: remaining disposal failures"));
|
|
1970
|
+
throw failure;
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
} catch (error) {
|
|
1974
|
+
return await unwind(error);
|
|
1975
|
+
}
|
|
1976
|
+
})();
|
|
1977
|
+
return await state.completion;
|
|
1978
|
+
},
|
|
1979
|
+
async dispose() {
|
|
1980
|
+
const cleanupErrors = await shutdownDomainState(state);
|
|
1981
|
+
if (cleanupErrors.length === 0) return;
|
|
1982
|
+
const failure = cleanupErrors[0] instanceof Error ? cleanupErrors[0] : new Error(String(cleanupErrors[0]));
|
|
1983
|
+
if (cleanupErrors.length > 1) mergeCause(failure, new AggregateError(cleanupErrors.slice(1), "remote client domains: remaining disposal failures"));
|
|
1984
|
+
throw failure;
|
|
1985
|
+
}
|
|
1986
|
+
};
|
|
1987
|
+
}
|
|
1859
1988
|
/**
|
|
1860
|
-
*
|
|
1861
|
-
*
|
|
1862
|
-
*
|
|
1863
|
-
*
|
|
1864
|
-
*
|
|
1865
|
-
|
|
1989
|
+
* Mount the official Client data plane on the caller's ALREADY-AUTHENTICATED
|
|
1990
|
+
* Client `Context`: the full staged domain graph (prerequisites + Jobs) and
|
|
1991
|
+
* the initial-readiness wait. This wrapper preserves the M3 in-process
|
|
1992
|
+
* composition contract; the split Client uses the staged functions directly
|
|
1993
|
+
* so its interaction owner exists before the Gateway starts.
|
|
1994
|
+
*/
|
|
1995
|
+
async function mountRemoteClientDomains(options) {
|
|
1996
|
+
return await (await mountRemoteClientDomainPrerequisites(options)).complete(options.signal === void 0 ? {} : { signal: options.signal });
|
|
1997
|
+
}
|
|
1998
|
+
/**
|
|
1999
|
+
* Compose one fresh official Client `Context` over the M3 in-process carrier:
|
|
2000
|
+
* typert -> Connection (explicit transport) -> Gateway -> the shared Domain
|
|
2001
|
+
* mount ({@link mountRemoteClientDomains}, which owns the `/remote`
|
|
2002
|
+
* contributions and the fileUpload -> Sessions -> Jobs plugins) -> initial
|
|
2003
|
+
* readiness. On construction failure the partial composition unwinds
|
|
2004
|
+
* immediately; the loader shim is never active during plugin execution.
|
|
1866
2005
|
*/
|
|
1867
2006
|
async function createRemoteClientRuntime(options) {
|
|
1868
2007
|
const modules = await loadOfficialClientModulesOnce();
|
|
@@ -1871,42 +2010,35 @@ async function createRemoteClientRuntime(options) {
|
|
|
1871
2010
|
let typertFiber;
|
|
1872
2011
|
let connectionFiber;
|
|
1873
2012
|
let gatewayFiber;
|
|
1874
|
-
let
|
|
1875
|
-
let sessionFiber;
|
|
1876
|
-
let jobsFiber;
|
|
1877
|
-
let services;
|
|
1878
|
-
const contributionDisposers = [];
|
|
2013
|
+
let domains;
|
|
1879
2014
|
let disposed = false;
|
|
1880
2015
|
/**
|
|
1881
|
-
* The frozen §16 shutdown sequence:
|
|
1882
|
-
* `/remote` contributions
|
|
1883
|
-
* then the Client root. Unwinding a partial composition
|
|
1884
|
-
* order over whatever subset exists
|
|
1885
|
-
* already assigned, so it unwinds at its own position; only stages that
|
|
1886
|
-
* were never reached are skipped.
|
|
2016
|
+
* The frozen §16 shutdown sequence: the shared Domain mount (Jobs -> Sessions
|
|
2017
|
+
* -> fileUpload -> `/remote` contributions reverse), Gateway/Connection/
|
|
2018
|
+
* Typert (reverse), then the Client root. Unwinding a partial composition
|
|
2019
|
+
* runs the SAME order over whatever subset exists.
|
|
1887
2020
|
*
|
|
1888
|
-
*
|
|
1889
|
-
*
|
|
1890
|
-
*
|
|
1891
|
-
*
|
|
2021
|
+
* A Domain teardown failure is collected (never allowed to truncate the
|
|
2022
|
+
* remaining cleanup). Cordis contains unload-disposer failures inside
|
|
2023
|
+
* `fiber.dispose()` (they are logged there, never propagated), so the
|
|
2024
|
+
* remaining fiber steps cannot reject.
|
|
1892
2025
|
*
|
|
1893
|
-
* @returns the collected
|
|
2026
|
+
* @returns the collected cleanup errors.
|
|
1894
2027
|
*/
|
|
1895
2028
|
const shutdown = async () => {
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
contributionDisposers.length = 0;
|
|
2029
|
+
const errors = [];
|
|
2030
|
+
try {
|
|
2031
|
+
await domains?.dispose();
|
|
2032
|
+
} catch (error) {
|
|
2033
|
+
errors.push(error);
|
|
2034
|
+
}
|
|
1903
2035
|
for (const fiber of [
|
|
1904
2036
|
gatewayFiber,
|
|
1905
2037
|
connectionFiber,
|
|
1906
2038
|
typertFiber
|
|
1907
2039
|
]) await fiber?.dispose();
|
|
1908
2040
|
await context.fiber.dispose();
|
|
1909
|
-
return
|
|
2041
|
+
return errors;
|
|
1910
2042
|
};
|
|
1911
2043
|
const unwind = async () => {
|
|
1912
2044
|
disposed = true;
|
|
@@ -1928,33 +2060,26 @@ async function createRemoteClientRuntime(options) {
|
|
|
1928
2060
|
await connectionFiber;
|
|
1929
2061
|
gatewayFiber = context.plugin(modules.gateway);
|
|
1930
2062
|
await gatewayFiber;
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
sessionFiber = context.plugin(modules.session);
|
|
1936
|
-
await sessionFiber;
|
|
1937
|
-
jobsFiber = context.plugin(modules.jobs);
|
|
1938
|
-
await jobsFiber;
|
|
1939
|
-
services = {
|
|
1940
|
-
connection: context.get("connection"),
|
|
1941
|
-
sessions: context.get("sessions"),
|
|
1942
|
-
jobs: context.get("jobs")
|
|
1943
|
-
};
|
|
1944
|
-
await waitForInitialReadiness(services.connection, services.sessions, options.signal);
|
|
2063
|
+
domains = await mountRemoteClientDomains({
|
|
2064
|
+
context,
|
|
2065
|
+
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
2066
|
+
});
|
|
1945
2067
|
} catch (error) {
|
|
1946
2068
|
const cleanupErrors = await unwind();
|
|
1947
2069
|
const failure = error instanceof Error ? error : new Error(String(error));
|
|
1948
|
-
if (cleanupErrors.length > 0)
|
|
2070
|
+
if (cleanupErrors.length > 0) {
|
|
2071
|
+
const secondary = cleanupErrors.length === 1 ? cleanupErrors[0] : new AggregateError(cleanupErrors, "remote client runtime: unwind disposal failures");
|
|
2072
|
+
mergeCause(failure, secondary);
|
|
2073
|
+
}
|
|
1949
2074
|
throw failure;
|
|
1950
2075
|
}
|
|
1951
|
-
const
|
|
2076
|
+
const mounted = domains;
|
|
1952
2077
|
return {
|
|
1953
2078
|
context,
|
|
1954
|
-
connection,
|
|
1955
|
-
sessions,
|
|
1956
|
-
jobs,
|
|
1957
|
-
remote:
|
|
2079
|
+
connection: mounted.connection,
|
|
2080
|
+
sessions: mounted.sessions,
|
|
2081
|
+
jobs: mounted.jobs,
|
|
2082
|
+
remote: mounted.remote,
|
|
1958
2083
|
async dispose() {
|
|
1959
2084
|
if (disposed) return;
|
|
1960
2085
|
disposed = true;
|
|
@@ -2189,360 +2314,6 @@ var RemoteHostUserShellPort = class {
|
|
|
2189
2314
|
}
|
|
2190
2315
|
};
|
|
2191
2316
|
//#endregion
|
|
2192
|
-
//#region src/runtime/remote/pi-tui-file-reference-host-bridge.ts
|
|
2193
|
-
/**
|
|
2194
|
-
* The Remote Host-side bridge for the private `piTuiFileReferences` endpoint
|
|
2195
|
-
* (TS8-HF1): a CONSTRUCTION/ADAPTATION seam ONLY. It binds the private Remote
|
|
2196
|
-
* method to the SAME Host-scoped completion authority the Direct adapter uses
|
|
2197
|
-
* (`runtime/direct/host-file-augmentation-direct.ts` + the Direct Host
|
|
2198
|
-
* discovery driver) and returns a transport-neutral `list` runtime.
|
|
2199
|
-
*
|
|
2200
|
-
* It owns NO Cordis service, NO Typert registration and NO lifecycle policy —
|
|
2201
|
-
* the Cordis service, its Typert contribution registration and its disposal
|
|
2202
|
-
* remain with the Remote Host composition
|
|
2203
|
-
* (`app/remote/pi-tui-file-reference-host.ts`). The dependency direction is
|
|
2204
|
-
* therefore `app/remote/** -> runtime/remote/** -> runtime/direct/**`, never
|
|
2205
|
-
* `app/remote/** -> runtime/direct/**`.
|
|
2206
|
-
*
|
|
2207
|
-
* The bridge lives in `runtime/remote/**` because that layer may consume the
|
|
2208
|
-
* Direct Host implementation; the composition layer may not.
|
|
2209
|
-
*
|
|
2210
|
-
* @module @xmoon76/dsh-pi-tui/runtime/remote/pi-tui-file-reference-host-bridge
|
|
2211
|
-
*/
|
|
2212
|
-
/**
|
|
2213
|
-
* Bind the private Remote method to the Host-scoped completion authority.
|
|
2214
|
-
* The Host finder is resolved ONCE for the runtime's lifetime (it is a pure
|
|
2215
|
-
* PATH pin; a later PATH change is not a Host completion fact).
|
|
2216
|
-
*/
|
|
2217
|
-
function createPiTuiHostFileReferenceRuntime(deps) {
|
|
2218
|
-
const driver = new DirectHostDiscoveryDriver(deps.fdPath);
|
|
2219
|
-
const environment = hostPathQueryEnvironment();
|
|
2220
|
-
return { async list(sessionId, query, signal) {
|
|
2221
|
-
signal.throwIfAborted();
|
|
2222
|
-
const agent = deps.agentFor(sessionId);
|
|
2223
|
-
if (agent === void 0) return {
|
|
2224
|
-
kind: "unavailable",
|
|
2225
|
-
reason: "the requested Session has no live Host Agent"
|
|
2226
|
-
};
|
|
2227
|
-
return await listPiTuiHostFileReferences(agent, query, signal, {
|
|
2228
|
-
official: deps.official(),
|
|
2229
|
-
driver,
|
|
2230
|
-
environment,
|
|
2231
|
-
workingDirectory: deps.workingDirectory?.()
|
|
2232
|
-
});
|
|
2233
|
-
} };
|
|
2234
|
-
}
|
|
2235
|
-
//#endregion
|
|
2236
|
-
//#region src/app/remote/pi-tui-file-reference-host.ts
|
|
2237
|
-
/**
|
|
2238
|
-
* The Host endpoint of the private augmentation. One instance per Remote Host
|
|
2239
|
-
* composition; the descriptor leaves with the owning fiber.
|
|
2240
|
-
*/
|
|
2241
|
-
var PiTuiFileReferenceHostService = class extends TypertRemoteService {
|
|
2242
|
-
/** The Typert registry owns the explicit invocation definitions. */
|
|
2243
|
-
static inject = ["typert"];
|
|
2244
|
-
runtime;
|
|
2245
|
-
/**
|
|
2246
|
-
* @param ctx - the Host context this row is mounted in.
|
|
2247
|
-
* @param deps - the narrow Host facts the composition resolved.
|
|
2248
|
-
*/
|
|
2249
|
-
constructor(ctx, deps) {
|
|
2250
|
-
super(ctx, PI_TUI_FILE_REFERENCES_NAMESPACE);
|
|
2251
|
-
this.runtime = createPiTuiHostFileReferenceRuntime({
|
|
2252
|
-
...deps,
|
|
2253
|
-
workingDirectory: () => ctx.get("workingDirectory")
|
|
2254
|
-
});
|
|
2255
|
-
}
|
|
2256
|
-
/**
|
|
2257
|
-
* The private Remote method (`piTuiFileReferences/list`, see
|
|
2258
|
-
* `pi-tui-file-reference-contract.ts`). Cancellation outranks every outcome.
|
|
2259
|
-
*/
|
|
2260
|
-
list(sessionId, query, signal) {
|
|
2261
|
-
return this.runtime.list(sessionId, query, signal);
|
|
2262
|
-
}
|
|
2263
|
-
};
|
|
2264
|
-
//#endregion
|
|
2265
|
-
//#region src/app/remote/terminal-progress-host.ts
|
|
2266
|
-
/** The structural `turn/start` / `turn/end` payload read (never a guessed shape). */
|
|
2267
|
-
function turnOf(data) {
|
|
2268
|
-
const turn = data?.turn;
|
|
2269
|
-
return typeof turn === "number" ? turn : void 0;
|
|
2270
|
-
}
|
|
2271
|
-
/** The merge-extensible `turn/end.reason.kind` discriminant. */
|
|
2272
|
-
function reasonKindOf(data) {
|
|
2273
|
-
const reason = data?.reason;
|
|
2274
|
-
return typeof reason?.kind === "string" ? reason.kind : void 0;
|
|
2275
|
-
}
|
|
2276
|
-
/**
|
|
2277
|
-
* Frames one subscriber may fall behind by before the stream is failed instead
|
|
2278
|
-
* of silently losing an edge. A real run produces a handful of transitions, so
|
|
2279
|
-
* only a consumer that stopped draining can reach it.
|
|
2280
|
-
*/
|
|
2281
|
-
const SUBSCRIBER_QUEUE_LIMIT = 64;
|
|
2282
|
-
/**
|
|
2283
|
-
* One subscriber's ordered frame queue. The Host ALWAYS mutates the record
|
|
2284
|
-
* before pushing, so a queue can never observe a frame the record has not
|
|
2285
|
-
* committed, and `close()` is idempotent.
|
|
2286
|
-
*
|
|
2287
|
-
* An overflowing queue FAILS the reader: dropping frames and continuing would
|
|
2288
|
-
* let a stream report a settlement whose running edge it lost (plan §6.5).
|
|
2289
|
-
*/
|
|
2290
|
-
var FrameQueue = class {
|
|
2291
|
-
frames = [];
|
|
2292
|
-
wake;
|
|
2293
|
-
closed = false;
|
|
2294
|
-
failure;
|
|
2295
|
-
limit = SUBSCRIBER_QUEUE_LIMIT;
|
|
2296
|
-
push(frame) {
|
|
2297
|
-
if (this.closed || this.failure !== void 0) return;
|
|
2298
|
-
if (this.frames.length >= this.limit) {
|
|
2299
|
-
this.failure = /* @__PURE__ */ new Error("piTuiTerminalProgress: the subscriber queue overflowed");
|
|
2300
|
-
this.frames.length = 0;
|
|
2301
|
-
const wake = this.wake;
|
|
2302
|
-
this.wake = void 0;
|
|
2303
|
-
wake?.();
|
|
2304
|
-
return;
|
|
2305
|
-
}
|
|
2306
|
-
this.frames.push(frame);
|
|
2307
|
-
const wake = this.wake;
|
|
2308
|
-
this.wake = void 0;
|
|
2309
|
-
wake?.();
|
|
2310
|
-
}
|
|
2311
|
-
/**
|
|
2312
|
-
* End the consumer's read AFTER every frame already committed to it: a
|
|
2313
|
-
* disposal publishes the retired interval BEFORE it ends the watchers, and a
|
|
2314
|
-
* committed terminal fact must never be dropped in flight.
|
|
2315
|
-
*/
|
|
2316
|
-
close() {
|
|
2317
|
-
if (this.closed) return;
|
|
2318
|
-
this.closed = true;
|
|
2319
|
-
const wake = this.wake;
|
|
2320
|
-
this.wake = void 0;
|
|
2321
|
-
wake?.();
|
|
2322
|
-
}
|
|
2323
|
-
async next() {
|
|
2324
|
-
for (;;) {
|
|
2325
|
-
const frame = this.frames.shift();
|
|
2326
|
-
if (frame !== void 0) return {
|
|
2327
|
-
value: frame,
|
|
2328
|
-
done: false
|
|
2329
|
-
};
|
|
2330
|
-
if (this.failure !== void 0) throw this.failure;
|
|
2331
|
-
if (this.closed) return {
|
|
2332
|
-
value: void 0,
|
|
2333
|
-
done: true
|
|
2334
|
-
};
|
|
2335
|
-
await new Promise((resolve) => {
|
|
2336
|
-
this.wake = resolve;
|
|
2337
|
-
});
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
|
-
};
|
|
2341
|
-
/**
|
|
2342
|
-
* The Host endpoint of the private stream. One instance per Remote Host
|
|
2343
|
-
* composition; the descriptors and the subscriptions leave with the fiber.
|
|
2344
|
-
*/
|
|
2345
|
-
var PiTuiTerminalProgressHostService = class extends TypertRemoteService {
|
|
2346
|
-
/** The Typert registry owns the explicit invocation definition. */
|
|
2347
|
-
static inject = ["typert"];
|
|
2348
|
-
/** The narrow Host facts the composition resolved (explicit field: the
|
|
2349
|
-
* strip-only TS loader rejects parameter properties). */
|
|
2350
|
-
deps;
|
|
2351
|
-
/** One opaque identity per Host plugin instance: a Host restart, a new
|
|
2352
|
-
* composition or a re-mounted fiber all invalidate older frames. */
|
|
2353
|
-
hostEpoch = `host-${randomEpoch()}`;
|
|
2354
|
-
records = /* @__PURE__ */ new Map();
|
|
2355
|
-
/** Monotonic Agent-lifetime counter: a replacement ALWAYS outranks every
|
|
2356
|
-
* earlier lifetime of the same session, even after its record was dropped. */
|
|
2357
|
-
epochCounter = 0;
|
|
2358
|
-
disposed = false;
|
|
2359
|
-
/**
|
|
2360
|
-
* @param ctx - the Host context this row is mounted in.
|
|
2361
|
-
* @param deps - the narrow Host facts the composition resolved.
|
|
2362
|
-
*/
|
|
2363
|
-
constructor(ctx, deps) {
|
|
2364
|
-
super(ctx, PI_TUI_TERMINAL_PROGRESS_NAMESPACE);
|
|
2365
|
-
this.deps = deps;
|
|
2366
|
-
ctx.on("agent/status", ({ agent, status }) => {
|
|
2367
|
-
this.onAgentStatus(agent, status);
|
|
2368
|
-
}, { global: true });
|
|
2369
|
-
ctx.on("session/event", (session, event) => {
|
|
2370
|
-
this.onSessionEvent(session, event.type, event.data);
|
|
2371
|
-
}, { global: true });
|
|
2372
|
-
ctx.on("agent/disposed", ({ agent }) => {
|
|
2373
|
-
this.onAgentDisposed(agent);
|
|
2374
|
-
}, { global: true });
|
|
2375
|
-
ctx.effect(() => () => {
|
|
2376
|
-
this.closeAll();
|
|
2377
|
-
}, "pi-tui-terminal-progress-watchers");
|
|
2378
|
-
}
|
|
2379
|
-
/**
|
|
2380
|
-
* The private Remote method (`piTuiTerminalProgress/watch`): the ONE
|
|
2381
|
-
* per-session ordered stream, opening with the authoritative snapshot of the
|
|
2382
|
-
* instant it subscribes and then every real Host-side change (plan §6.5).
|
|
2383
|
-
*
|
|
2384
|
-
* The subscriber is registered and the cut (revision + current state) is
|
|
2385
|
-
* captured in the SAME synchronous block before the first `yield`, so an
|
|
2386
|
-
* update can neither be lost between the snapshot and the subscription nor be
|
|
2387
|
-
* replayed twice.
|
|
2388
|
-
*/
|
|
2389
|
-
async *watch(sessionId, signal) {
|
|
2390
|
-
const record = this.recordFor(sessionId);
|
|
2391
|
-
const queue = new FrameQueue();
|
|
2392
|
-
const cut = record.revision;
|
|
2393
|
-
const snapshot = {
|
|
2394
|
-
kind: "snapshot",
|
|
2395
|
-
sessionId,
|
|
2396
|
-
hostEpoch: this.hostEpoch,
|
|
2397
|
-
agentEpoch: record.agentEpoch,
|
|
2398
|
-
revision: cut,
|
|
2399
|
-
running: record.running,
|
|
2400
|
-
outcome: record.outcome
|
|
2401
|
-
};
|
|
2402
|
-
record.subscribers.add(queue);
|
|
2403
|
-
const onAbort = () => {
|
|
2404
|
-
queue.close();
|
|
2405
|
-
};
|
|
2406
|
-
if (signal.aborted) queue.close();
|
|
2407
|
-
else signal.addEventListener("abort", onAbort, { once: true });
|
|
2408
|
-
try {
|
|
2409
|
-
yield snapshot;
|
|
2410
|
-
for (;;) {
|
|
2411
|
-
const next = await queue.next();
|
|
2412
|
-
if (next.done === true) return;
|
|
2413
|
-
yield next.value;
|
|
2414
|
-
}
|
|
2415
|
-
} finally {
|
|
2416
|
-
signal.removeEventListener("abort", onAbort);
|
|
2417
|
-
record.subscribers.delete(queue);
|
|
2418
|
-
this.reclaim(record);
|
|
2419
|
-
}
|
|
2420
|
-
}
|
|
2421
|
-
/**
|
|
2422
|
-
* Drop a record nobody watches and no Agent owns. A watch of a session that
|
|
2423
|
-
* has no live Agent must not leave an empty record behind for the rest of the
|
|
2424
|
-
* Host's life: it is observable by nothing, and the next Agent lifetime starts
|
|
2425
|
-
* a FRESH record carrying a HIGHER `agentEpoch` (the epoch counter never
|
|
2426
|
-
* rewinds), so no Client provenance can be resurrected across the gap.
|
|
2427
|
-
*/
|
|
2428
|
-
reclaim(record) {
|
|
2429
|
-
if (record.subscribers.size > 0 || record.agent !== void 0) return;
|
|
2430
|
-
if (this.records.get(record.sessionId) === record) this.records.delete(record.sessionId);
|
|
2431
|
-
}
|
|
2432
|
-
/** The live `agent/status` transition of one Agent (plan §6.4). */
|
|
2433
|
-
onAgentStatus(agent, status) {
|
|
2434
|
-
if (this.deps.agentFor(agent.session.id) !== agent) return;
|
|
2435
|
-
const record = this.recordFor(agent.session.id);
|
|
2436
|
-
if (record.agent !== agent) return;
|
|
2437
|
-
this.publish(record, record.fold.status(status === "running"));
|
|
2438
|
-
}
|
|
2439
|
-
/** One durable Session event (plan §6.4): evidence only, never an interim commit. */
|
|
2440
|
-
onSessionEvent(session, type, data) {
|
|
2441
|
-
const record = this.records.get(session.id);
|
|
2442
|
-
if (record === void 0 || record.agent === void 0) return;
|
|
2443
|
-
if (record.session !== session) return;
|
|
2444
|
-
if (type === "turn/start") {
|
|
2445
|
-
const turn = turnOf(data);
|
|
2446
|
-
if (turn !== void 0) record.fold.turnStart(turn);
|
|
2447
|
-
return;
|
|
2448
|
-
}
|
|
2449
|
-
if (type === "turn/end") {
|
|
2450
|
-
const turn = turnOf(data);
|
|
2451
|
-
const kind = reasonKindOf(data);
|
|
2452
|
-
if (turn !== void 0 && kind !== void 0) record.fold.turnEnd(turn, kind);
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
/** The Agent lifetime ended (plan §6.4): retire honestly, end the watchers. */
|
|
2456
|
-
onAgentDisposed(agent) {
|
|
2457
|
-
const record = this.records.get(agent.session.id);
|
|
2458
|
-
if (record === void 0 || record.agent !== agent) return;
|
|
2459
|
-
const retired = record.fold.retire();
|
|
2460
|
-
if (retired !== void 0) this.publish(record, retired);
|
|
2461
|
-
this.records.delete(agent.session.id);
|
|
2462
|
-
for (const subscriber of record.subscribers) subscriber.close();
|
|
2463
|
-
}
|
|
2464
|
-
/**
|
|
2465
|
-
* The record of one session, bound to the live Agent the authoritative Host
|
|
2466
|
-
* registry currently holds. Creation AND a replaced Agent lifetime consume a
|
|
2467
|
-
* new `agentEpoch` and reset the interval: a new Agent can never inherit the
|
|
2468
|
-
* previous lifetime's evidence (plan §6.3/§6.4).
|
|
2469
|
-
*/
|
|
2470
|
-
recordFor(sessionId) {
|
|
2471
|
-
let record = this.records.get(sessionId);
|
|
2472
|
-
if (record === void 0) {
|
|
2473
|
-
record = {
|
|
2474
|
-
sessionId,
|
|
2475
|
-
agent: void 0,
|
|
2476
|
-
session: void 0,
|
|
2477
|
-
agentEpoch: 0,
|
|
2478
|
-
fold: createTerminalProgressInterval((kind) => {
|
|
2479
|
-
this.deps.onUnknownReason(kind);
|
|
2480
|
-
}),
|
|
2481
|
-
revision: 0,
|
|
2482
|
-
running: false,
|
|
2483
|
-
outcome: "idle",
|
|
2484
|
-
subscribers: /* @__PURE__ */ new Set()
|
|
2485
|
-
};
|
|
2486
|
-
this.records.set(sessionId, record);
|
|
2487
|
-
}
|
|
2488
|
-
const live = this.deps.agentFor(sessionId);
|
|
2489
|
-
if (live !== void 0 && live !== record.agent) this.rebind(record, live);
|
|
2490
|
-
return record;
|
|
2491
|
-
}
|
|
2492
|
-
/**
|
|
2493
|
-
* Bind one Agent lifetime: the running truth is read from the Agent's OWN
|
|
2494
|
-
* current status (a plugin mounted mid-run may therefore report `working`),
|
|
2495
|
-
* but the outcome starts at `idle` — an unobserved start can never prove a
|
|
2496
|
-
* settlement. The rebind is ALWAYS published, because the epoch change is
|
|
2497
|
-
* itself a fact the Client must fence on.
|
|
2498
|
-
*/
|
|
2499
|
-
rebind(record, agent) {
|
|
2500
|
-
record.agent = agent;
|
|
2501
|
-
record.session = agent.session;
|
|
2502
|
-
record.agentEpoch = ++this.epochCounter;
|
|
2503
|
-
const running = agent.status === "running";
|
|
2504
|
-
record.fold.apply({
|
|
2505
|
-
active: running,
|
|
2506
|
-
outcome: "idle"
|
|
2507
|
-
});
|
|
2508
|
-
record.running = running;
|
|
2509
|
-
record.outcome = "idle";
|
|
2510
|
-
record.revision += 1;
|
|
2511
|
-
this.broadcast(record, "update");
|
|
2512
|
-
}
|
|
2513
|
-
/** Commit one fold transition: mutate the record FIRST, then broadcast. */
|
|
2514
|
-
publish(record, next) {
|
|
2515
|
-
if (next === void 0) return;
|
|
2516
|
-
if (next.active === record.running && next.outcome === record.outcome) return;
|
|
2517
|
-
record.running = next.active;
|
|
2518
|
-
record.outcome = next.outcome;
|
|
2519
|
-
record.revision += 1;
|
|
2520
|
-
this.broadcast(record, "update");
|
|
2521
|
-
}
|
|
2522
|
-
broadcast(record, kind) {
|
|
2523
|
-
const frame = {
|
|
2524
|
-
kind,
|
|
2525
|
-
sessionId: record.sessionId,
|
|
2526
|
-
hostEpoch: this.hostEpoch,
|
|
2527
|
-
agentEpoch: record.agentEpoch,
|
|
2528
|
-
revision: record.revision,
|
|
2529
|
-
running: record.running,
|
|
2530
|
-
outcome: record.outcome
|
|
2531
|
-
};
|
|
2532
|
-
for (const subscriber of record.subscribers) subscriber.push(frame);
|
|
2533
|
-
}
|
|
2534
|
-
/** End every watcher (the row's fiber is going away). */
|
|
2535
|
-
closeAll() {
|
|
2536
|
-
if (this.disposed) return;
|
|
2537
|
-
this.disposed = true;
|
|
2538
|
-
for (const record of this.records.values()) for (const subscriber of record.subscribers) subscriber.close();
|
|
2539
|
-
}
|
|
2540
|
-
};
|
|
2541
|
-
/** An opaque, process-unique Host-plugin identity (the wire sees only a string). */
|
|
2542
|
-
function randomEpoch() {
|
|
2543
|
-
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
2544
|
-
}
|
|
2545
|
-
//#endregion
|
|
2546
2317
|
//#region src/app/remote/host-prerequisites.ts
|
|
2547
2318
|
/**
|
|
2548
2319
|
* Host services the ordinary Host Context must already expose before any
|
|
@@ -2614,21 +2385,26 @@ function createInProcessCarrier(hostContext) {
|
|
|
2614
2385
|
};
|
|
2615
2386
|
}
|
|
2616
2387
|
/**
|
|
2617
|
-
* Mount the exact additive official Host closure
|
|
2618
|
-
*
|
|
2619
|
-
*
|
|
2388
|
+
* Mount the exact M3-only additive official Host closure onto the existing Host
|
|
2389
|
+
* Context and await every fiber. The caller must already have mounted the
|
|
2390
|
+
* built-in PiTui Host Runtime (private services + readiness) and the
|
|
2391
|
+
* Performance projection row exactly once; this function verifies both
|
|
2392
|
+
* readiness gates and then mounts only the M3-only official additive fibers.
|
|
2393
|
+
*
|
|
2394
|
+
* The existing `jobController`/`userQuestions` services are asserted before and
|
|
2395
|
+
* after construction and never re-mounted.
|
|
2620
2396
|
*
|
|
2621
2397
|
* On a partial construction failure the already-mounted fibers unwind in
|
|
2622
2398
|
* reverse order before the original error rethrows.
|
|
2623
2399
|
*/
|
|
2624
|
-
async function createRemoteHostRuntime(hostContext
|
|
2400
|
+
async function createRemoteHostRuntime(hostContext) {
|
|
2625
2401
|
assertRemoteHostPrerequisites(hostContext);
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2402
|
+
for (const service of [
|
|
2403
|
+
"piTuiHostReady",
|
|
2404
|
+
"piTuiFileReferences",
|
|
2405
|
+
"piTuiTerminalProgress",
|
|
2406
|
+
"piTuiPerformanceReady"
|
|
2407
|
+
]) if (hostContext.reflect.get(service) === void 0) throw new Error(`remote host runtime: the M3 composition requires the mounted PiTui Host Runtime and Performance row; missing "${service}"`);
|
|
2632
2408
|
const jobControllerBefore = hostContext.reflect.get("jobController");
|
|
2633
2409
|
const userQuestionsBefore = hostContext.reflect.get("userQuestions");
|
|
2634
2410
|
const fibers = [];
|
|
@@ -2652,29 +2428,6 @@ async function createRemoteHostRuntime(hostContext, options = {}) {
|
|
|
2652
2428
|
return errors;
|
|
2653
2429
|
};
|
|
2654
2430
|
try {
|
|
2655
|
-
const contributionFiber = hostContext.inject(["typert"], (contributionCtx) => {
|
|
2656
|
-
contributionCtx.effect(() => contributionCtx.typert.register(PI_TUI_HOST_CONTRIBUTION), "pi-tui-private-remote-host");
|
|
2657
|
-
});
|
|
2658
|
-
fibers.push(contributionFiber);
|
|
2659
|
-
await contributionFiber;
|
|
2660
|
-
const fileReferenceFiber = hostContext.inject(PiTuiFileReferenceHostService.inject, (pluginCtx) => {
|
|
2661
|
-
new PiTuiFileReferenceHostService(pluginCtx, {
|
|
2662
|
-
agentFor: (sessionId) => liveAgentFor(sessionId),
|
|
2663
|
-
official: () => hostContext.reflect.get("fileReferences")
|
|
2664
|
-
});
|
|
2665
|
-
});
|
|
2666
|
-
fibers.push(fileReferenceFiber);
|
|
2667
|
-
await fileReferenceFiber;
|
|
2668
|
-
const terminalProgressFiber = hostContext.inject(PiTuiTerminalProgressHostService.inject, (pluginCtx) => {
|
|
2669
|
-
new PiTuiTerminalProgressHostService(pluginCtx, {
|
|
2670
|
-
agentFor: (sessionId) => liveAgentFor(sessionId),
|
|
2671
|
-
onUnknownReason: (kind) => {
|
|
2672
|
-
diag.warn("terminal progress: unknown turn/end reason", { kind });
|
|
2673
|
-
}
|
|
2674
|
-
});
|
|
2675
|
-
});
|
|
2676
|
-
fibers.push(terminalProgressFiber);
|
|
2677
|
-
await terminalProgressFiber;
|
|
2678
2431
|
const connFiber = hostContext.plugin((connectionContext) => {
|
|
2679
2432
|
new HostConnectionService(connectionContext, [], {});
|
|
2680
2433
|
});
|
|
@@ -2686,9 +2439,6 @@ async function createRemoteHostRuntime(hostContext, options = {}) {
|
|
|
2686
2439
|
const statsFiber = hostContext.plugin(sessionStats);
|
|
2687
2440
|
fibers.push(statsFiber);
|
|
2688
2441
|
await statsFiber;
|
|
2689
|
-
const performanceFiber = hostContext.plugin(performance_host_exports);
|
|
2690
|
-
fibers.push(performanceFiber);
|
|
2691
|
-
await performanceFiber;
|
|
2692
2442
|
const outlineFiber = hostContext.plugin(sessionTurnOutline);
|
|
2693
2443
|
fibers.push(outlineFiber);
|
|
2694
2444
|
await outlineFiber;
|
|
@@ -2802,14 +2552,19 @@ var RemoteQuestionInteractionPort = class {
|
|
|
2802
2552
|
sessions;
|
|
2803
2553
|
remote;
|
|
2804
2554
|
generation;
|
|
2555
|
+
onQualification;
|
|
2805
2556
|
/** Every subscription this adapter owns, released exactly once. */
|
|
2806
2557
|
owned = [];
|
|
2807
|
-
|
|
2558
|
+
registerDelivery;
|
|
2559
|
+
constructor(source, registerDelivery) {
|
|
2808
2560
|
this.sessions = source.sessions;
|
|
2809
2561
|
this.remote = source.remote;
|
|
2810
2562
|
this.generation = source.connection.generation;
|
|
2563
|
+
this.onQualification = source.onQualification;
|
|
2564
|
+
this.registerDelivery = registerDelivery;
|
|
2811
2565
|
}
|
|
2812
2566
|
onRequest(provider) {
|
|
2567
|
+
if (this.registerDelivery !== void 0) return this.registerDelivery(provider);
|
|
2813
2568
|
const sessions = this.sessions;
|
|
2814
2569
|
this.owned.push(this.remote.$on("user-questions/request", function(request, next) {
|
|
2815
2570
|
const sessionId = sessions.scopeOf(this);
|
|
@@ -2936,6 +2691,12 @@ var RemoteQuestionInteractionPort = class {
|
|
|
2936
2691
|
async answerContinued(sessionId, callId, answer) {
|
|
2937
2692
|
if (this.generation.getSnapshot() === void 0) throw new SupersededReadError("the question answer was not dispatched: no current Connection generation");
|
|
2938
2693
|
const result = await this.remote.userQuestions.answer(sessionId, callId, answer);
|
|
2694
|
+
const classification = result.ok ? result.value ? "queued" : "not-continued" : "error";
|
|
2695
|
+
this.onQualification?.({
|
|
2696
|
+
op: "question-answer-continued",
|
|
2697
|
+
callId,
|
|
2698
|
+
result: classification
|
|
2699
|
+
});
|
|
2939
2700
|
if (!result.ok) throw new QuestionAnswerError(remoteFailureCode(result.error) ?? "question/answer-failed", remoteFailureMessage(result.error));
|
|
2940
2701
|
return result.value ? "queued" : "not-continued";
|
|
2941
2702
|
}
|
|
@@ -2947,15 +2708,51 @@ var RemoteInteractionPort = class {
|
|
|
2947
2708
|
/** Every subscription this port owns, released exactly once. */
|
|
2948
2709
|
owned = [];
|
|
2949
2710
|
questionsPort;
|
|
2711
|
+
delivery;
|
|
2712
|
+
surfaceRevision;
|
|
2713
|
+
/** The split-delivery providers supplied by the CURRENT surface revision. */
|
|
2714
|
+
pendingQuestion;
|
|
2715
|
+
pendingApproval;
|
|
2716
|
+
deliveryDisposer;
|
|
2950
2717
|
constructor(source) {
|
|
2951
2718
|
this.remote = source.remote;
|
|
2952
|
-
this.
|
|
2719
|
+
this.delivery = source.delivery;
|
|
2720
|
+
this.surfaceRevision = source.surfaceRevision ?? 0;
|
|
2721
|
+
this.questionsPort = new RemoteQuestionInteractionPort(source, this.delivery === void 0 ? void 0 : (provider) => this.registerQuestion(provider));
|
|
2953
2722
|
this.questions = this.questionsPort;
|
|
2954
2723
|
}
|
|
2724
|
+
registerQuestion(provider) {
|
|
2725
|
+
this.pendingQuestion = provider;
|
|
2726
|
+
this.attachDeliveryWhenComplete();
|
|
2727
|
+
return true;
|
|
2728
|
+
}
|
|
2729
|
+
attachDeliveryWhenComplete() {
|
|
2730
|
+
if (this.delivery === void 0 || this.deliveryDisposer !== void 0) return;
|
|
2731
|
+
if (this.pendingQuestion === void 0 || this.pendingApproval === void 0) return;
|
|
2732
|
+
this.deliveryDisposer = this.delivery.attachSurface(this.surfaceRevision, {
|
|
2733
|
+
onQuestion: this.pendingQuestion,
|
|
2734
|
+
onApproval: this.pendingApproval
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2955
2737
|
onApprovalRequest(listener) {
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2738
|
+
if (this.delivery === void 0) {
|
|
2739
|
+
this.owned.push(this.remote.$on("approval/request", function(request, next) {
|
|
2740
|
+
return listener(request, next);
|
|
2741
|
+
}));
|
|
2742
|
+
return;
|
|
2743
|
+
}
|
|
2744
|
+
this.pendingApproval = listener;
|
|
2745
|
+
this.attachDeliveryWhenComplete();
|
|
2746
|
+
}
|
|
2747
|
+
/**
|
|
2748
|
+
* Revoke the current surface's presentation token BEFORE the surface owner
|
|
2749
|
+
* withdraws its modal promises. A local teardown result must never be
|
|
2750
|
+
* forwarded as a Host decision; the root delivery then holds the official
|
|
2751
|
+
* invocation for a replacement surface (or the request lifetime).
|
|
2752
|
+
*/
|
|
2753
|
+
detachSurface() {
|
|
2754
|
+
this.deliveryDisposer?.();
|
|
2755
|
+
this.deliveryDisposer = void 0;
|
|
2959
2756
|
}
|
|
2960
2757
|
/**
|
|
2961
2758
|
* Release every subscription this adapter owns. The assembly runs it BEFORE
|
|
@@ -2963,6 +2760,7 @@ var RemoteInteractionPort = class {
|
|
|
2963
2760
|
* forwarded-event listener never outlives its owner.
|
|
2964
2761
|
*/
|
|
2965
2762
|
dispose() {
|
|
2763
|
+
this.detachSurface();
|
|
2966
2764
|
this.questionsPort.dispose();
|
|
2967
2765
|
for (const off of this.owned.splice(0)) off();
|
|
2968
2766
|
}
|
|
@@ -4182,8 +3980,16 @@ var RemoteSessionLifecycle = class {
|
|
|
4182
3980
|
}
|
|
4183
3981
|
};
|
|
4184
3982
|
}
|
|
4185
|
-
if (!Object.is(captured, this.generation.getSnapshot())
|
|
3983
|
+
if (isAborted(request.signal) || !Object.is(captured, this.generation.getSnapshot())) {
|
|
3984
|
+
const stateAtLoss = owner.openState();
|
|
4186
3985
|
owner.release();
|
|
3986
|
+
if (stateAtLoss.openState === "open") return {
|
|
3987
|
+
ownership: "superseded",
|
|
3988
|
+
outcome: {
|
|
3989
|
+
kind: "opened",
|
|
3990
|
+
handle: { session: { id: request.sessionId } }
|
|
3991
|
+
}
|
|
3992
|
+
};
|
|
4187
3993
|
return {
|
|
4188
3994
|
ownership: "superseded",
|
|
4189
3995
|
outcome: { kind: "cancelled" }
|
|
@@ -5263,7 +5069,10 @@ function createRemoteM3ASemantics(runtime, options) {
|
|
|
5263
5069
|
userQuestions: remote.userQuestions,
|
|
5264
5070
|
$on: forwardedEvents
|
|
5265
5071
|
},
|
|
5266
|
-
connection: { generation }
|
|
5072
|
+
connection: { generation },
|
|
5073
|
+
...options.delivery === void 0 ? {} : { delivery: options.delivery },
|
|
5074
|
+
...options.surfaceRevision === void 0 ? {} : { surfaceRevision: options.surfaceRevision },
|
|
5075
|
+
...options.onQualification === void 0 ? {} : { onQualification: options.onQualification }
|
|
5267
5076
|
});
|
|
5268
5077
|
const presetCatalog = new RemotePresetCatalog(remote.agentPresets, generation);
|
|
5269
5078
|
let disposed = false;
|
|
@@ -5323,19 +5132,32 @@ function createRemoteM3ASemantics(runtime, options) {
|
|
|
5323
5132
|
* owner, so `flush`/`preCancel` are deliberate no-ops, `retire` releases the
|
|
5324
5133
|
* exact Client reference exactly once, and `whenIdleOrAbort` observes the
|
|
5325
5134
|
* official `SessionSnapshot.running` without ever cancelling the Host session.
|
|
5135
|
+
* The ONE Host mutation here is `cancel`: the explicit user Stop addresses the
|
|
5136
|
+
* EXACT captured binding generation through the official `SessionFace.cancel`
|
|
5137
|
+
* verb; it never substitutes a same-id replacement and never releases the
|
|
5138
|
+
* Client reference. The Connection generation is captured before dispatch and
|
|
5139
|
+
* re-checked with the exact binding after the reply, so a superseded reply is
|
|
5140
|
+
* `indeterminate`, never the current generation's definite result. The same
|
|
5141
|
+
* one-shot verb serves the navigation audience through `cancelForNavigation`,
|
|
5142
|
+
* which resolves the dispatch PHASE (a dispatched reply whose classification is
|
|
5143
|
+
* a caller/carrier `cancelled` is dispatched-unproven there) without changing
|
|
5144
|
+
* the control `cancel` taxonomy; only `committed` lets navigation proceed.
|
|
5326
5145
|
*
|
|
5327
|
-
* Composition note:
|
|
5328
|
-
*
|
|
5329
|
-
*
|
|
5146
|
+
* Composition note: the Remote application runtime constructs this provider
|
|
5147
|
+
* ONCE over the official Client's sessions and Connection generation source.
|
|
5148
|
+
* Tests may construct it directly over a fake binding/generation source.
|
|
5330
5149
|
*
|
|
5331
5150
|
* @module @xmoon76/dsh-pi-tui/app/remote/session-owners
|
|
5332
5151
|
*/
|
|
5333
5152
|
/**
|
|
5334
|
-
* Build the Remote Session owner services over one binding borrow source
|
|
5335
|
-
* `owners` and `retirement` share the SAME
|
|
5336
|
-
* independent mappings would create a second
|
|
5153
|
+
* Build the Remote Session owner services over one binding borrow source and
|
|
5154
|
+
* the Connection generation source. `owners` and `retirement` share the SAME
|
|
5155
|
+
* registry state; constructing two independent mappings would create a second
|
|
5156
|
+
* owner truth. The generation source is the SAME official pre-dispatch fence
|
|
5157
|
+
* the Remote session writer uses: an owner mutation's reply is only a definite
|
|
5158
|
+
* outcome for the generation it was dispatched on.
|
|
5337
5159
|
*/
|
|
5338
|
-
function createRemoteSessionOwnerServices(source) {
|
|
5160
|
+
function createRemoteSessionOwnerServices(source, generation) {
|
|
5339
5161
|
const byBinding = /* @__PURE__ */ new WeakMap();
|
|
5340
5162
|
const byOwner = /* @__PURE__ */ new WeakMap();
|
|
5341
5163
|
const releasedWrappers = /* @__PURE__ */ new WeakSet();
|
|
@@ -5372,26 +5194,123 @@ function createRemoteSessionOwnerServices(source) {
|
|
|
5372
5194
|
return existing;
|
|
5373
5195
|
};
|
|
5374
5196
|
const sessionId = (owner) => recordOf(owner).sessionId;
|
|
5375
|
-
|
|
5197
|
+
/**
|
|
5198
|
+
* The ONE exact-owner cancel body. `dispatched` records whether the official
|
|
5199
|
+
* `SessionFace.cancel()` was actually invoked: a local fence can prove it was
|
|
5200
|
+
* not; every reply (including a cancelled/superseded one) is about a call
|
|
5201
|
+
* that WAS made. The control audience projects only `outcome` (PR-A's
|
|
5202
|
+
* taxonomy is unchanged); the navigation audience resolves the phase.
|
|
5203
|
+
*/
|
|
5204
|
+
const cancelExactOwner = async (owner) => {
|
|
5205
|
+
const notDispatched = (outcome) => ({
|
|
5206
|
+
outcome,
|
|
5207
|
+
dispatched: false
|
|
5208
|
+
});
|
|
5209
|
+
const record = recordOf(owner);
|
|
5210
|
+
if (record.currentWrapper === void 0) return notDispatched({ kind: "cancelled" });
|
|
5211
|
+
const capturedGeneration = generation.getSnapshot();
|
|
5212
|
+
if (capturedGeneration === void 0) return notDispatched({ kind: "cancelled" });
|
|
5213
|
+
const borrowed = source.binding(record.sessionId);
|
|
5214
|
+
if (borrowed === void 0 || !Object.is(borrowed, record.bindingIdentity)) return notDispatched({ kind: "cancelled" });
|
|
5215
|
+
if (!Object.is(capturedGeneration, generation.getSnapshot())) return notDispatched({ kind: "cancelled" });
|
|
5216
|
+
const result = await borrowed.session.cancel();
|
|
5217
|
+
const currentGeneration = generation.getSnapshot();
|
|
5218
|
+
if (currentGeneration === void 0 || !Object.is(capturedGeneration, currentGeneration) || record.currentWrapper === void 0 || !Object.is(source.binding(record.sessionId), record.bindingIdentity)) return {
|
|
5219
|
+
outcome: {
|
|
5220
|
+
kind: "indeterminate",
|
|
5221
|
+
error: {
|
|
5222
|
+
code: "session/cancel-superseded",
|
|
5223
|
+
message: "the session owner or connection generation changed while the cancel was in flight"
|
|
5224
|
+
}
|
|
5225
|
+
},
|
|
5226
|
+
dispatched: true
|
|
5227
|
+
};
|
|
5228
|
+
if (result.ok) return {
|
|
5229
|
+
outcome: {
|
|
5230
|
+
kind: "committed",
|
|
5231
|
+
value: void 0
|
|
5232
|
+
},
|
|
5233
|
+
dispatched: true,
|
|
5234
|
+
receipt: { token: capturedGeneration }
|
|
5235
|
+
};
|
|
5236
|
+
return {
|
|
5237
|
+
outcome: classifyRemoteWriteFailure(result.error),
|
|
5238
|
+
dispatched: true
|
|
5239
|
+
};
|
|
5240
|
+
};
|
|
5241
|
+
/** The control (Busy Esc / Stop) audience: PR-A's shared write taxonomy. */
|
|
5242
|
+
const cancel = async (owner) => (await cancelExactOwner(owner)).outcome;
|
|
5243
|
+
/**
|
|
5244
|
+
* The navigation audience. The phase is resolved HERE, without changing
|
|
5245
|
+
* `cancel`:
|
|
5246
|
+
* - a pre-dispatch local fence is `cancelled` (the request was not addressed;
|
|
5247
|
+
* never permission to switch);
|
|
5248
|
+
* - a DISPATCHED reply classified as a caller/carrier cancellation is
|
|
5249
|
+
* `indeterminate` (the Host may have executed it) — the control audience
|
|
5250
|
+
* still sees PR-A's `cancelled`;
|
|
5251
|
+
* - a dispatched superseded reply is already `indeterminate`;
|
|
5252
|
+
* - a proven business refusal is `rejected`, success `committed`.
|
|
5253
|
+
*/
|
|
5254
|
+
const cancelForNavigation = async (owner) => {
|
|
5255
|
+
const { outcome, dispatched, receipt } = await cancelExactOwner(owner);
|
|
5256
|
+
switch (outcome.kind) {
|
|
5257
|
+
case "committed": return {
|
|
5258
|
+
kind: "committed",
|
|
5259
|
+
...receipt === void 0 ? {} : { receipt }
|
|
5260
|
+
};
|
|
5261
|
+
case "rejected": return {
|
|
5262
|
+
kind: "rejected",
|
|
5263
|
+
detail: outcome.error.message
|
|
5264
|
+
};
|
|
5265
|
+
case "unsupported": return {
|
|
5266
|
+
kind: "rejected",
|
|
5267
|
+
detail: outcome.reason
|
|
5268
|
+
};
|
|
5269
|
+
case "cancelled": return dispatched ? {
|
|
5270
|
+
kind: "indeterminate",
|
|
5271
|
+
detail: "the Host session cancel was dispatched but its reply was a caller/carrier cancellation"
|
|
5272
|
+
} : { kind: "cancelled" };
|
|
5273
|
+
case "indeterminate": return {
|
|
5274
|
+
kind: "indeterminate",
|
|
5275
|
+
detail: outcome.error.message
|
|
5276
|
+
};
|
|
5277
|
+
}
|
|
5278
|
+
};
|
|
5279
|
+
const whenIdleOrAbort = (owner, signal, receipt) => {
|
|
5376
5280
|
const record = recordOf(owner);
|
|
5281
|
+
const capturedGeneration = receipt === void 0 ? generation.getSnapshot() : receipt.token;
|
|
5282
|
+
if (capturedGeneration === void 0) return Promise.resolve("unobservable");
|
|
5283
|
+
if (!Object.is(generation.getSnapshot(), capturedGeneration)) return Promise.resolve("unobservable");
|
|
5377
5284
|
const borrowed = source.binding(record.sessionId);
|
|
5378
|
-
if (borrowed === void 0 || !Object.is(borrowed, record.bindingIdentity)) return Promise.resolve(
|
|
5285
|
+
if (borrowed === void 0 || !Object.is(borrowed, record.bindingIdentity)) return Promise.resolve("unobservable");
|
|
5286
|
+
const exactBindingCurrent = () => Object.is(source.binding(record.sessionId), record.bindingIdentity) && Object.is(generation.getSnapshot(), capturedGeneration);
|
|
5379
5287
|
const face = borrowed.session;
|
|
5380
|
-
if (!face.getSnapshot().running) return Promise.resolve(false);
|
|
5288
|
+
if (!face.getSnapshot().running) return Promise.resolve(exactBindingCurrent() ? false : "unobservable");
|
|
5381
5289
|
if (signal.aborted) return Promise.resolve(true);
|
|
5382
5290
|
return new Promise((resolve) => {
|
|
5383
5291
|
let settled = false;
|
|
5384
5292
|
let unsubscribe;
|
|
5385
5293
|
let offAbort;
|
|
5386
|
-
|
|
5294
|
+
let offGeneration;
|
|
5295
|
+
let offRetain;
|
|
5296
|
+
const retainInfo = source.retainInfo?.(record.sessionId);
|
|
5297
|
+
const settle = (result) => {
|
|
5387
5298
|
if (settled) return;
|
|
5388
5299
|
settled = true;
|
|
5389
5300
|
unsubscribe?.();
|
|
5390
5301
|
offAbort?.();
|
|
5391
|
-
|
|
5302
|
+
offGeneration?.();
|
|
5303
|
+
offRetain?.();
|
|
5304
|
+
resolve(result);
|
|
5305
|
+
};
|
|
5306
|
+
const onGeneration = () => {
|
|
5307
|
+
if (!Object.is(generation.getSnapshot(), capturedGeneration)) settle("unobservable");
|
|
5308
|
+
};
|
|
5309
|
+
const onRetain = () => {
|
|
5310
|
+
if (!exactBindingCurrent()) settle("unobservable");
|
|
5392
5311
|
};
|
|
5393
5312
|
const onSnapshot = () => {
|
|
5394
|
-
if (!face.getSnapshot().running) settle(false);
|
|
5313
|
+
if (!face.getSnapshot().running) settle(exactBindingCurrent() ? false : "unobservable");
|
|
5395
5314
|
};
|
|
5396
5315
|
const onAbort = () => {
|
|
5397
5316
|
settle(true);
|
|
@@ -5400,9 +5319,13 @@ function createRemoteSessionOwnerServices(source) {
|
|
|
5400
5319
|
offAbort = () => {
|
|
5401
5320
|
signal.removeEventListener("abort", onAbort);
|
|
5402
5321
|
};
|
|
5322
|
+
offGeneration = generation.subscribe(onGeneration);
|
|
5323
|
+
if (settled) offGeneration();
|
|
5324
|
+
offRetain = retainInfo?.subscribe(onRetain);
|
|
5325
|
+
if (settled) offRetain?.();
|
|
5403
5326
|
unsubscribe = face.subscribe(onSnapshot);
|
|
5404
5327
|
if (settled) unsubscribe();
|
|
5405
|
-
if (!face.getSnapshot().running) settle(false);
|
|
5328
|
+
if (!face.getSnapshot().running) settle(exactBindingCurrent() ? false : "unobservable");
|
|
5406
5329
|
if (signal.aborted) settle(true);
|
|
5407
5330
|
});
|
|
5408
5331
|
};
|
|
@@ -5457,6 +5380,8 @@ function createRemoteSessionOwnerServices(source) {
|
|
|
5457
5380
|
},
|
|
5458
5381
|
retirement: {
|
|
5459
5382
|
whenIdleOrAbort,
|
|
5383
|
+
cancel,
|
|
5384
|
+
cancelForNavigation,
|
|
5460
5385
|
flush: async () => {},
|
|
5461
5386
|
preCancel: () => {},
|
|
5462
5387
|
retire,
|
|
@@ -6384,9 +6309,10 @@ function detachedPlan(value) {
|
|
|
6384
6309
|
};
|
|
6385
6310
|
}
|
|
6386
6311
|
/**
|
|
6387
|
-
* Assemble the Remote application presentation source from the ONE
|
|
6388
|
-
*
|
|
6389
|
-
*
|
|
6312
|
+
* Assemble the Remote application presentation source from the ONE shared
|
|
6313
|
+
* Client runtime source (the M3-1 Client runtime or the real split Client's
|
|
6314
|
+
* mounted official Domains). Every member reuses a face that source already
|
|
6315
|
+
* owns: `semantics.presentationReader` by identity, its
|
|
6390
6316
|
* `sessions`/`connection.generation` for the official projection/echo reads,
|
|
6391
6317
|
* and the eventSource borrow for the live ingress. Constructing this bundle
|
|
6392
6318
|
* installs exactly ONE watch — the ingress factory's process-lifetime
|
|
@@ -6396,23 +6322,23 @@ function detachedPlan(value) {
|
|
|
6396
6322
|
* ingress subscription is created lazily by the bootstrap and disposed through
|
|
6397
6323
|
* its own handle.
|
|
6398
6324
|
*/
|
|
6399
|
-
function createRemotePresentationSource(
|
|
6400
|
-
const sessions =
|
|
6401
|
-
const generation =
|
|
6325
|
+
function createRemotePresentationSource(client, backendRuntime) {
|
|
6326
|
+
const sessions = client.sessions;
|
|
6327
|
+
const generation = client.connection.generation;
|
|
6402
6328
|
const sessionReader = backendRuntime.semantics.sessionReader;
|
|
6403
6329
|
const planSource = sessions;
|
|
6404
6330
|
const liveIngress = createRemoteLiveIngress(sessions, generation, CURRENT_STATUS_PROJECTION_KEYS);
|
|
6405
|
-
const taskReader = new RemoteTaskReader(sessions,
|
|
6331
|
+
const taskReader = new RemoteTaskReader(sessions, client.jobs, generation);
|
|
6406
6332
|
return {
|
|
6407
6333
|
presentationReader: backendRuntime.semantics.presentationReader,
|
|
6408
6334
|
commandSource: createRemoteCommandSource({
|
|
6409
|
-
authority:
|
|
6335
|
+
authority: client.remote,
|
|
6410
6336
|
generation,
|
|
6411
6337
|
bindings: sessions
|
|
6412
6338
|
}),
|
|
6413
6339
|
submissionPresentation: new RemoteSubmissionPresentation(sessions, generation),
|
|
6414
6340
|
terminalProgress: createRemoteTerminalProgressSource({
|
|
6415
|
-
remote:
|
|
6341
|
+
remote: client.remote,
|
|
6416
6342
|
generation,
|
|
6417
6343
|
binding: (sessionId) => sessions.binding(sessionId)
|
|
6418
6344
|
}),
|
|
@@ -6465,12 +6391,12 @@ function createRemotePresentationSource(wire, backendRuntime) {
|
|
|
6465
6391
|
},
|
|
6466
6392
|
task: {
|
|
6467
6393
|
readDescendants: (parentSessionId, signal) => taskReader.readDescendants(parentSessionId, signal),
|
|
6468
|
-
jobs: (sessionId) =>
|
|
6394
|
+
jobs: (sessionId) => client.jobs.state.getSnapshot().rows[sessionId] ?? [],
|
|
6469
6395
|
activityOf: (childSessionId) => {
|
|
6470
6396
|
const entry = sessions.list.getSnapshot().byId[childSessionId];
|
|
6471
6397
|
return entry === void 0 ? void 0 : entry.running ? "running" : "inactive";
|
|
6472
6398
|
},
|
|
6473
|
-
subscribeJobs: (listener) =>
|
|
6399
|
+
subscribeJobs: (listener) => client.jobs.state.subscribe(listener),
|
|
6474
6400
|
subscribeSessions: (listener) => sessions.list.subscribe(listener),
|
|
6475
6401
|
dispose: () => taskReader.dispose()
|
|
6476
6402
|
},
|
|
@@ -6571,7 +6497,10 @@ async function createRemoteClientUiRuntime(options) {
|
|
|
6571
6497
|
} catch (error) {
|
|
6572
6498
|
const cleanupErrors = await unwind();
|
|
6573
6499
|
const failure = error instanceof Error ? error : new Error(String(error));
|
|
6574
|
-
if (cleanupErrors.length > 0)
|
|
6500
|
+
if (cleanupErrors.length > 0) {
|
|
6501
|
+
const secondary = cleanupErrors.length === 1 ? cleanupErrors[0] : new AggregateError(cleanupErrors, "remote client UI runtime: unwind disposal failures");
|
|
6502
|
+
mergeCause(failure, secondary);
|
|
6503
|
+
}
|
|
6575
6504
|
throw failure;
|
|
6576
6505
|
}
|
|
6577
6506
|
}
|
|
@@ -6594,21 +6523,21 @@ function throwAggregated(errors, label) {
|
|
|
6594
6523
|
throw failure;
|
|
6595
6524
|
}
|
|
6596
6525
|
/**
|
|
6597
|
-
*
|
|
6598
|
-
*
|
|
6599
|
-
*
|
|
6600
|
-
*
|
|
6601
|
-
*
|
|
6602
|
-
*
|
|
6526
|
+
* The ONE Remote semantic composition stage shared by both public
|
|
6527
|
+
* application-runtime constructors. It composes the Backend, the ONE owner
|
|
6528
|
+
* registry and the presentation bundle over the supplied Client runtime
|
|
6529
|
+
* source. It owns no Context/Connection/Gateway/UI: the caller owns those and
|
|
6530
|
+
* disposes them around this stage.
|
|
6531
|
+
*
|
|
6532
|
+
* Failure semantics: a backend construction failure unwinds inside
|
|
6533
|
+
* `createRemoteBackendRuntime`; a LATER owner/presentation failure disposes the
|
|
6534
|
+
* constructed presentation task/backend before rethrowing, with the original
|
|
6535
|
+
* error primary.
|
|
6603
6536
|
*/
|
|
6604
|
-
async function
|
|
6605
|
-
const wire = await createExperimentalRemoteRuntime({
|
|
6606
|
-
hostContext: options.hostContext,
|
|
6607
|
-
waitForHostPrerequisites: options.waitForHostPrerequisites,
|
|
6608
|
-
signal: options.signal
|
|
6609
|
-
});
|
|
6537
|
+
async function composeRemoteApplicationStage(input) {
|
|
6610
6538
|
let backendRuntime;
|
|
6611
6539
|
let ownerServices;
|
|
6540
|
+
let presentation;
|
|
6612
6541
|
/**
|
|
6613
6542
|
* The composition-owned pre-dispatch write admission: OPEN for the whole live
|
|
6614
6543
|
* surface, closed ONCE and synchronously by the application's surface-stop
|
|
@@ -6619,23 +6548,75 @@ async function createRemoteApplicationRuntime(options) {
|
|
|
6619
6548
|
let dispatchAdmissionOpen = true;
|
|
6620
6549
|
try {
|
|
6621
6550
|
backendRuntime = await createRemoteBackendRuntime({
|
|
6622
|
-
runtime:
|
|
6623
|
-
fetch:
|
|
6551
|
+
runtime: input.client,
|
|
6552
|
+
fetch: input.fetch,
|
|
6624
6553
|
isDispatchAllowed: () => dispatchAdmissionOpen,
|
|
6554
|
+
...input.promptSerializer === void 0 ? {} : { promptSerializer: input.promptSerializer },
|
|
6555
|
+
...input.delivery === void 0 ? {} : { delivery: input.delivery },
|
|
6556
|
+
...input.surfaceRevision === void 0 ? {} : { surfaceRevision: input.surfaceRevision },
|
|
6557
|
+
...input.onQualification === void 0 ? {} : { onQualification: input.onQualification }
|
|
6558
|
+
});
|
|
6559
|
+
ownerServices = createRemoteSessionOwnerServices(input.client.sessions, input.client.connection.generation);
|
|
6560
|
+
presentation = createRemotePresentationSource(input.client, backendRuntime);
|
|
6561
|
+
} catch (error) {
|
|
6562
|
+
const disposeErrors = [...presentation === void 0 ? [] : await collectDisposeErrors$1(() => presentation.task.dispose()), ...backendRuntime === void 0 ? [] : await collectDisposeErrors$1(() => backendRuntime.dispose())];
|
|
6563
|
+
if (disposeErrors.length > 0) {
|
|
6564
|
+
const secondary = disposeErrors.length === 1 ? disposeErrors[0] : new AggregateError(disposeErrors, "remote application runtime: disposal failures during stage construction");
|
|
6565
|
+
throw mergeCause(error instanceof Error ? error : new Error(String(error)), secondary);
|
|
6566
|
+
}
|
|
6567
|
+
throw error;
|
|
6568
|
+
}
|
|
6569
|
+
const composed = {
|
|
6570
|
+
backendRuntime,
|
|
6571
|
+
ownerServices,
|
|
6572
|
+
presentation
|
|
6573
|
+
};
|
|
6574
|
+
let adaptersDisposed = false;
|
|
6575
|
+
return {
|
|
6576
|
+
backendRuntime: composed.backendRuntime,
|
|
6577
|
+
owners: composed.ownerServices.owners,
|
|
6578
|
+
retirement: composed.ownerServices.retirement,
|
|
6579
|
+
presentation: composed.presentation,
|
|
6580
|
+
stopSurfaceAdmission: () => {
|
|
6581
|
+
dispatchAdmissionOpen = false;
|
|
6582
|
+
},
|
|
6583
|
+
async disposeAdapters() {
|
|
6584
|
+
if (adaptersDisposed) return;
|
|
6585
|
+
adaptersDisposed = true;
|
|
6586
|
+
const errors = [...await collectDisposeErrors$1(() => composed.presentation.task.dispose()), ...await collectDisposeErrors$1(() => composed.backendRuntime.dispose())];
|
|
6587
|
+
if (errors.length > 0) throwAggregated(errors, "remote application runtime adapter disposal");
|
|
6588
|
+
}
|
|
6589
|
+
};
|
|
6590
|
+
}
|
|
6591
|
+
/**
|
|
6592
|
+
* Compose the M3 Remote application runtime as ONE graph. Failure semantics: a
|
|
6593
|
+
* Host/Client construction failure unwinds inside
|
|
6594
|
+
* `createExperimentalRemoteRuntime` (no leaked fibers); a backend/owner
|
|
6595
|
+
* failure after the wire exists disposes the wire (both steps run; the
|
|
6596
|
+
* original error surfaces with disposal failures on its cause chain, never
|
|
6597
|
+
* masked by them) and rethrows.
|
|
6598
|
+
*/
|
|
6599
|
+
async function createRemoteApplicationRuntime(options) {
|
|
6600
|
+
const wire = await createExperimentalRemoteRuntime({
|
|
6601
|
+
hostContext: options.hostContext,
|
|
6602
|
+
waitForHostPrerequisites: options.waitForHostPrerequisites,
|
|
6603
|
+
signal: options.signal
|
|
6604
|
+
});
|
|
6605
|
+
let stage;
|
|
6606
|
+
try {
|
|
6607
|
+
stage = await composeRemoteApplicationStage({
|
|
6608
|
+
client: wire.client,
|
|
6609
|
+
fetch: wire.host.carrier.fetch,
|
|
6625
6610
|
...options.promptSerializer === void 0 ? {} : { promptSerializer: options.promptSerializer }
|
|
6626
6611
|
});
|
|
6627
|
-
ownerServices = createRemoteSessionOwnerServices(wire.client.sessions);
|
|
6628
6612
|
} catch (error) {
|
|
6629
|
-
const
|
|
6630
|
-
const disposeErrors = [...constructed !== void 0 ? await collectDisposeErrors$1(() => constructed.dispose()) : [], ...await collectDisposeErrors$1(() => wire.dispose())];
|
|
6613
|
+
const disposeErrors = await collectDisposeErrors$1(() => wire.dispose());
|
|
6631
6614
|
if (disposeErrors.length > 0) {
|
|
6632
|
-
const secondary = disposeErrors.length === 1 ? disposeErrors[0] : new AggregateError(disposeErrors, "remote application runtime: disposal failures during
|
|
6615
|
+
const secondary = disposeErrors.length === 1 ? disposeErrors[0] : new AggregateError(disposeErrors, "remote application runtime: disposal failures during stage-failure unwind");
|
|
6633
6616
|
throw mergeCause(error instanceof Error ? error : new Error(String(error)), secondary);
|
|
6634
6617
|
}
|
|
6635
6618
|
throw error;
|
|
6636
6619
|
}
|
|
6637
|
-
let transportDisposed = false;
|
|
6638
|
-
const presentation = createRemotePresentationSource(wire, backendRuntime);
|
|
6639
6620
|
let clientUi;
|
|
6640
6621
|
try {
|
|
6641
6622
|
clientUi = await createRemoteClientUiRuntime({
|
|
@@ -6643,41 +6624,35 @@ async function createRemoteApplicationRuntime(options) {
|
|
|
6643
6624
|
startup: options.clientUiStartup
|
|
6644
6625
|
});
|
|
6645
6626
|
} catch (error) {
|
|
6646
|
-
const disposeErrors = [
|
|
6647
|
-
...await collectDisposeErrors$1(() => presentation.task.dispose()),
|
|
6648
|
-
...await collectDisposeErrors$1(() => backendRuntime.dispose()),
|
|
6649
|
-
...await collectDisposeErrors$1(() => wire.dispose())
|
|
6650
|
-
];
|
|
6627
|
+
const disposeErrors = [...await collectDisposeErrors$1(() => stage.disposeAdapters()), ...await collectDisposeErrors$1(() => wire.dispose())];
|
|
6651
6628
|
if (disposeErrors.length > 0) {
|
|
6652
6629
|
const secondary = disposeErrors.length === 1 ? disposeErrors[0] : new AggregateError(disposeErrors, "remote application runtime: disposal failures during client-UI construction failure");
|
|
6653
6630
|
throw mergeCause(error instanceof Error ? error : new Error(String(error)), secondary);
|
|
6654
6631
|
}
|
|
6655
6632
|
throw error;
|
|
6656
6633
|
}
|
|
6634
|
+
let transportDisposed = false;
|
|
6657
6635
|
return {
|
|
6658
6636
|
selected: {
|
|
6659
6637
|
kind: "remote",
|
|
6660
|
-
backend: backendRuntime.backend,
|
|
6661
|
-
owners:
|
|
6662
|
-
retirement:
|
|
6663
|
-
stopSurfaceAdmission:
|
|
6664
|
-
dispatchAdmissionOpen = false;
|
|
6665
|
-
},
|
|
6638
|
+
backend: stage.backendRuntime.backend,
|
|
6639
|
+
owners: stage.owners,
|
|
6640
|
+
retirement: stage.retirement,
|
|
6641
|
+
stopSurfaceAdmission: stage.stopSurfaceAdmission,
|
|
6666
6642
|
disposeTransport: async () => {
|
|
6667
6643
|
if (transportDisposed) return;
|
|
6668
6644
|
transportDisposed = true;
|
|
6669
6645
|
const errors = [
|
|
6670
6646
|
...await collectDisposeErrors$1(() => clientUi.dispose()),
|
|
6671
|
-
...await collectDisposeErrors$1(() =>
|
|
6672
|
-
...await collectDisposeErrors$1(() => backendRuntime.dispose()),
|
|
6647
|
+
...await collectDisposeErrors$1(() => stage.disposeAdapters()),
|
|
6673
6648
|
...await collectDisposeErrors$1(() => wire.dispose())
|
|
6674
6649
|
];
|
|
6675
6650
|
if (errors.length > 0) throwAggregated(errors, "remote application runtime transport disposal");
|
|
6676
6651
|
}
|
|
6677
6652
|
},
|
|
6678
6653
|
wire,
|
|
6679
|
-
backendRuntime,
|
|
6680
|
-
presentation,
|
|
6654
|
+
backendRuntime: stage.backendRuntime,
|
|
6655
|
+
presentation: stage.presentation,
|
|
6681
6656
|
clientUi
|
|
6682
6657
|
};
|
|
6683
6658
|
}
|
|
@@ -6741,9 +6716,11 @@ async function createExperimentalRemoteRuntime(options) {
|
|
|
6741
6716
|
}
|
|
6742
6717
|
};
|
|
6743
6718
|
}
|
|
6744
|
-
/** Compile-time proof that the
|
|
6745
|
-
* ConfigPort's narrow source face (never called; referenced by the
|
|
6746
|
-
* official-contract gate).
|
|
6719
|
+
/** Compile-time proof that the shared Client runtime source satisfies the
|
|
6720
|
+
* Remote ConfigPort's narrow source face (never called; referenced by the
|
|
6721
|
+
* official-contract gate). The M3-1 Client runtime AND the real split
|
|
6722
|
+
* Client's Domain mount are the same structural source; the config-plane
|
|
6723
|
+
* namespaces stay part of the ONE `remote` service, never a second object. */
|
|
6747
6724
|
function remoteConfigRuntimeSourceOf(runtime) {
|
|
6748
6725
|
return runtime;
|
|
6749
6726
|
}
|
|
@@ -6778,7 +6755,10 @@ async function createRemoteBackendRuntime(options) {
|
|
|
6778
6755
|
try {
|
|
6779
6756
|
const semantics = createRemoteM3ASemantics(remoteM3ARuntimeSourceOf(options.runtime), {
|
|
6780
6757
|
promptSerializer: options.promptSerializer ?? RemotePromptSerializerProduction.overSessions(options.runtime.sessions),
|
|
6781
|
-
...options.isDispatchAllowed === void 0 ? {} : { isDispatchAllowed: options.isDispatchAllowed }
|
|
6758
|
+
...options.isDispatchAllowed === void 0 ? {} : { isDispatchAllowed: options.isDispatchAllowed },
|
|
6759
|
+
...options.delivery === void 0 ? {} : { delivery: options.delivery },
|
|
6760
|
+
...options.surfaceRevision === void 0 ? {} : { surfaceRevision: options.surfaceRevision },
|
|
6761
|
+
...options.onQualification === void 0 ? {} : { onQualification: options.onQualification }
|
|
6782
6762
|
});
|
|
6783
6763
|
unwind.push(() => semantics.dispose());
|
|
6784
6764
|
const config = new RemoteConfigPort(remoteConfigRuntimeSourceOf(options.runtime));
|