@xmoon76/dsh-pi-tui 0.5.4 → 0.5.6
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 +46 -42
- package/README.md +46 -27
- package/cordis.patch.yml +77 -7
- package/dist/bootstrap-DQ4YPL-7.mjs +113583 -0
- package/dist/builtins.mjs +3 -9
- package/dist/{runtime-vc4mdr-R.mjs → client-bootstrap-Cr1JCaF5.mjs} +3670 -2277
- package/dist/disposal-BYBbEpVY.mjs +54 -0
- package/dist/dist-CIsR7cz4.mjs +15717 -0
- package/dist/{entry-control-DvSrndWd.mjs → entry-control-DnduyDiw.mjs} +12 -31
- package/dist/{extensions-CcuMY4n2.mjs → extensions-Bp0L37lP.mjs} +1239 -271
- package/dist/extensions.mjs +1 -1
- package/dist/host-bootstrap-DilsvA6f.mjs +281 -0
- package/dist/host-foundation-probe--5jtvHVe.mjs +413 -0
- package/dist/host-runtime.d.mts +30 -0
- package/dist/host-runtime.mjs +1317 -0
- package/dist/index.d.mts +19 -18
- package/dist/index.mjs +18410 -8836
- package/dist/local-client.mjs +2027 -187
- package/dist/local-discovery-C9VMjc0K.mjs +759 -0
- package/dist/local-discovery-CDaQHA_R.mjs +2 -0
- package/dist/local-host.mjs +1088 -87
- package/dist/local-transport-BVwFYq_Y.mjs +513 -0
- package/dist/{context-summary-DAisTA_7.mjs → pasted-path-range-CMnxuGPx.mjs} +7613 -216
- package/dist/pasted-path-range-r6qzV_tC.mjs +17510 -0
- package/dist/performance-host.d.mts +2 -2
- package/dist/performance-host.mjs +258 -1
- package/dist/pi-tui-remote-contribution-B0EQsP0N.mjs +85 -0
- package/dist/pi-tui-terminal-progress-contract-CdBH9j78.mjs +70 -0
- package/dist/pi-tui-terminal-progress-contract-MLXZ-i3t.mjs +905 -0
- package/dist/pi-tui-web-access-contract-BN8Cc_Ho.mjs +118 -0
- package/dist/{runtime-status-0lp9CM0V.mjs → runtime-status-Cj1nFOdS.mjs} +72 -214
- package/dist/session-BKGXyh80.mjs +15794 -0
- package/dist/{session-tdJHLnJR.mjs → session-CPt_U8_f.mjs} +10707 -3657
- package/dist/{startup-JaVZoTIl.mjs → startup-7BYWuvBU.mjs} +124 -8
- package/dist/startup.d.mts +1 -1
- package/dist/startup.mjs +1 -1
- package/dist/{client-bootstrap-F5DHFI9t.mjs → terminal-progress-source-DrqQhtT8.mjs} +3653 -2969
- package/dist/visual-tools.d.mts +2 -2
- package/dist/visual-tools.mjs +26 -31
- package/dist/web-preferences.d.mts +29 -0
- package/dist/web-preferences.mjs +15 -0
- package/dist/web-roster-CjqnUXNk.mjs +285 -0
- package/generated/dsh-presets/cordis.patch.yml +5 -3
- package/generated/dsh-presets/ptc.patch.yml +7 -7
- package/generated/dsh-presets/standard.patch.yml +6 -4
- package/package.json +195 -172
- package/dist/host-bootstrap-DAgKknbY.mjs +0 -119
- package/dist/performance-host-CcDJjjVA.mjs +0 -266
- package/dist/rolldown-runtime-8H4AJuhK.mjs +0 -14
- package/dist/terminal-progress-source-xor3vakJ.mjs +0 -2256
|
@@ -0,0 +1,1317 @@
|
|
|
1
|
+
import { a as DirectHostDiscoveryDriver, i as listPiTuiHostFileReferences, n as PI_TUI_TERMINAL_PROGRESS_WATCH, o as hostPathQueryEnvironment, r as createTerminalProgressInterval, t as PI_TUI_TERMINAL_PROGRESS_NAMESPACE } from "./pi-tui-terminal-progress-contract-MLXZ-i3t.mjs";
|
|
2
|
+
import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
3
|
+
//#region src/runtime/remote/pi-tui-file-reference-contract.ts
|
|
4
|
+
/** The wire namespace (and Host Cordis service key) of the augmentation. */
|
|
5
|
+
const PI_TUI_FILE_REFERENCES_NAMESPACE = "piTuiFileReferences";
|
|
6
|
+
/** The private method's stable endpoint identity. */
|
|
7
|
+
const PI_TUI_FILE_REFERENCES_LIST_ENDPOINT = "@xmoon76/dsh-pi-tui#piTuiFileReferences/list";
|
|
8
|
+
/** One strict JSON codec that validates a wire string. */
|
|
9
|
+
function stringCodec(typeSymbol) {
|
|
10
|
+
return {
|
|
11
|
+
mode: "strict",
|
|
12
|
+
typeSymbol,
|
|
13
|
+
create: () => ({ parse: (value) => {
|
|
14
|
+
if (typeof value !== "string") throw new TypeError(`${typeSymbol}: the wire value must be a string`);
|
|
15
|
+
return value;
|
|
16
|
+
} })
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validate and detach one wire `HostFileListResult`. The result is produced by
|
|
21
|
+
* this package's own Host router, but it is still a wire boundary on the Client
|
|
22
|
+
* and the ONLY place the shape crosses.
|
|
23
|
+
*/
|
|
24
|
+
function decodeHostFileListResult(value) {
|
|
25
|
+
if (typeof value !== "object" || value === null) throw new TypeError("piTuiFileReferences/list: the result must be an object");
|
|
26
|
+
const record = value;
|
|
27
|
+
if (record.kind === "unavailable") {
|
|
28
|
+
if (typeof record.reason !== "string") throw new TypeError("piTuiFileReferences/list: an unavailable result needs a reason");
|
|
29
|
+
return {
|
|
30
|
+
kind: "unavailable",
|
|
31
|
+
reason: record.reason
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (record.kind !== "ok" || !Array.isArray(record.items)) throw new TypeError("piTuiFileReferences/list: the result must be ok(items) or unavailable(reason)");
|
|
35
|
+
return {
|
|
36
|
+
kind: "ok",
|
|
37
|
+
items: record.items.map((entry) => {
|
|
38
|
+
if (typeof entry !== "object" || entry === null) throw new TypeError("piTuiFileReferences/list: every candidate must be an object");
|
|
39
|
+
const candidate = entry;
|
|
40
|
+
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");
|
|
41
|
+
return {
|
|
42
|
+
path: candidate.path,
|
|
43
|
+
kind: candidate.kind
|
|
44
|
+
};
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const HOST_FILE_LIST_RESULT_CODEC = {
|
|
49
|
+
mode: "strict",
|
|
50
|
+
typeSymbol: "@xmoon76/dsh-pi-tui#piTuiFileReferences/list:result",
|
|
51
|
+
create: () => ({ parse: decodeHostFileListResult }),
|
|
52
|
+
decode: decodeHostFileListResult
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The ONE shared invocation descriptor both contributions derive from. The
|
|
56
|
+
* Host registers this exact object; the Client mounts this exact object.
|
|
57
|
+
*/
|
|
58
|
+
const PI_TUI_FILE_REFERENCES_LIST = {
|
|
59
|
+
id: PI_TUI_FILE_REFERENCES_LIST_ENDPOINT,
|
|
60
|
+
service: PI_TUI_FILE_REFERENCES_NAMESPACE,
|
|
61
|
+
namespace: PI_TUI_FILE_REFERENCES_NAMESPACE,
|
|
62
|
+
method: "list",
|
|
63
|
+
invocation: { kind: "direct" },
|
|
64
|
+
parameters: [{
|
|
65
|
+
name: "sessionId",
|
|
66
|
+
wire: "sessionId",
|
|
67
|
+
source: "json",
|
|
68
|
+
codec: stringCodec("@xmoon76/dsh-pi-tui#piTuiFileReferences/list:sessionId")
|
|
69
|
+
}, {
|
|
70
|
+
name: "query",
|
|
71
|
+
wire: "query",
|
|
72
|
+
source: "json",
|
|
73
|
+
codec: stringCodec("@xmoon76/dsh-pi-tui#piTuiFileReferences/list:query")
|
|
74
|
+
}],
|
|
75
|
+
cancellation: { parameter: "signal" },
|
|
76
|
+
result: HOST_FILE_LIST_RESULT_CODEC
|
|
77
|
+
};
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/runtime/remote/pi-tui-web-access-contract.ts
|
|
80
|
+
/** The wire namespace (and Host Cordis service key) of the toggle. */
|
|
81
|
+
const PI_TUI_WEB_ACCESS_NAMESPACE = "piTuiWebAccess";
|
|
82
|
+
/** The status method's stable endpoint identity. */
|
|
83
|
+
const PI_TUI_WEB_ACCESS_GET_STATUS_ENDPOINT = "@xmoon76/dsh-pi-tui#piTuiWebAccess/getStatus";
|
|
84
|
+
/** The mutation method's stable endpoint identity. */
|
|
85
|
+
const PI_TUI_WEB_ACCESS_SET_ENABLED_ENDPOINT = "@xmoon76/dsh-pi-tui#piTuiWebAccess/setEnabled";
|
|
86
|
+
/** The authenticated-URL method's stable endpoint identity. */
|
|
87
|
+
const PI_TUI_WEB_ACCESS_GET_AUTHENTICATED_URL_ENDPOINT = "@xmoon76/dsh-pi-tui#piTuiWebAccess/getAuthenticatedUrl";
|
|
88
|
+
/** One strict JSON codec that validates a wire boolean. */
|
|
89
|
+
const BOOLEAN_CODEC = {
|
|
90
|
+
mode: "strict",
|
|
91
|
+
typeSymbol: "@xmoon76/dsh-pi-tui#piTuiWebAccess/setEnabled:enabled",
|
|
92
|
+
create: () => ({ parse: (value) => {
|
|
93
|
+
if (typeof value !== "boolean") throw new TypeError("piTuiWebAccess/setEnabled: the wire value must be a boolean");
|
|
94
|
+
return value;
|
|
95
|
+
} })
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Validate and detach one wire `PiTuiWebAccessStatus`. The status is produced by
|
|
99
|
+
* this package's own Host service, but it is still a wire boundary on the
|
|
100
|
+
* Client and the ONLY place the shape crosses.
|
|
101
|
+
*/
|
|
102
|
+
function parsePiTuiWebAccessStatus(value) {
|
|
103
|
+
if (typeof value !== "object" || value === null) throw new TypeError("piTuiWebAccess: the result must be an object");
|
|
104
|
+
const record = value;
|
|
105
|
+
const field = record.state === "unavailable" ? "reason" : void 0;
|
|
106
|
+
for (const key of Object.keys(record)) if (key !== "state" && key !== field) throw new TypeError(`piTuiWebAccess: unexpected result field ${JSON.stringify(key)}`);
|
|
107
|
+
if (record.state === "disabled" || record.state === "enabled" || record.state === "changing") return { state: record.state };
|
|
108
|
+
if (record.state !== "unavailable") throw new TypeError("piTuiWebAccess: the result state must be disabled, enabled, changing or unavailable");
|
|
109
|
+
if (typeof record.reason !== "string" || record.reason === "") throw new TypeError("piTuiWebAccess: an unavailable result needs a non-empty reason");
|
|
110
|
+
return {
|
|
111
|
+
state: "unavailable",
|
|
112
|
+
reason: record.reason
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const PI_TUI_WEB_ACCESS_STATUS_CODEC = {
|
|
116
|
+
mode: "strict",
|
|
117
|
+
typeSymbol: "@xmoon76/dsh-pi-tui#piTuiWebAccess:status",
|
|
118
|
+
create: () => ({ parse: parsePiTuiWebAccessStatus }),
|
|
119
|
+
decode: parsePiTuiWebAccessStatus
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* The `getStatus` invocation both contributions derive from. The Host
|
|
123
|
+
* registers this exact object; the Client mounts this exact object.
|
|
124
|
+
*/
|
|
125
|
+
const PI_TUI_WEB_ACCESS_GET_STATUS = {
|
|
126
|
+
id: PI_TUI_WEB_ACCESS_GET_STATUS_ENDPOINT,
|
|
127
|
+
service: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
128
|
+
namespace: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
129
|
+
method: "getStatus",
|
|
130
|
+
invocation: { kind: "direct" },
|
|
131
|
+
parameters: [],
|
|
132
|
+
result: PI_TUI_WEB_ACCESS_STATUS_CODEC
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* The `setEnabled` invocation both contributions derive from. `enabled` is one
|
|
136
|
+
* required boolean: the Host Gateway decodes it through {@link BOOLEAN_CODEC},
|
|
137
|
+
* so a malformed value is refused at the wire boundary and never reaches the
|
|
138
|
+
* toggle.
|
|
139
|
+
*/
|
|
140
|
+
const PI_TUI_WEB_ACCESS_SET_ENABLED = {
|
|
141
|
+
id: PI_TUI_WEB_ACCESS_SET_ENABLED_ENDPOINT,
|
|
142
|
+
service: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
143
|
+
namespace: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
144
|
+
method: "setEnabled",
|
|
145
|
+
invocation: { kind: "direct" },
|
|
146
|
+
parameters: [{
|
|
147
|
+
name: "enabled",
|
|
148
|
+
wire: "enabled",
|
|
149
|
+
source: "json",
|
|
150
|
+
codec: BOOLEAN_CODEC
|
|
151
|
+
}],
|
|
152
|
+
result: PI_TUI_WEB_ACCESS_STATUS_CODEC
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Validate and detach one wire `PiTuiWebAccessAuthenticatedUrl`.
|
|
156
|
+
*
|
|
157
|
+
* It is the ONE place the token-carrying value crosses the wire, so the shape is
|
|
158
|
+
* parsed strictly: exactly one `url` field, a non-empty string, and an absolute
|
|
159
|
+
* `http(s)` URL. Nothing is normalized or rewritten — the Client opens/copies
|
|
160
|
+
* the official URL verbatim.
|
|
161
|
+
*/
|
|
162
|
+
function parsePiTuiWebAccessAuthenticatedUrl(value) {
|
|
163
|
+
if (typeof value !== "object" || value === null) throw new TypeError("piTuiWebAccess: the authenticated URL result must be an object");
|
|
164
|
+
const record = value;
|
|
165
|
+
for (const key of Object.keys(record)) if (key !== "url") throw new TypeError(`piTuiWebAccess: unexpected authenticated URL field ${JSON.stringify(key)}`);
|
|
166
|
+
if (typeof record.url !== "string" || record.url === "") throw new TypeError("piTuiWebAccess: the authenticated URL must be a non-empty string");
|
|
167
|
+
let parsed;
|
|
168
|
+
try {
|
|
169
|
+
parsed = new URL(record.url);
|
|
170
|
+
} catch {
|
|
171
|
+
throw new TypeError("piTuiWebAccess: the authenticated URL must be an absolute URL");
|
|
172
|
+
}
|
|
173
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new TypeError("piTuiWebAccess: the authenticated URL must be an http(s) URL");
|
|
174
|
+
return { url: record.url };
|
|
175
|
+
}
|
|
176
|
+
/** The explicit Host contribution registered once with `ctx.typert.register`. */
|
|
177
|
+
const PI_TUI_HOST_CONTRIBUTION = {
|
|
178
|
+
package: "@xmoon76/dsh-pi-tui",
|
|
179
|
+
face: "host",
|
|
180
|
+
schemas: [],
|
|
181
|
+
model: {
|
|
182
|
+
services: [],
|
|
183
|
+
events: [],
|
|
184
|
+
objects: []
|
|
185
|
+
},
|
|
186
|
+
invocations: [
|
|
187
|
+
PI_TUI_FILE_REFERENCES_LIST,
|
|
188
|
+
PI_TUI_TERMINAL_PROGRESS_WATCH,
|
|
189
|
+
PI_TUI_WEB_ACCESS_GET_STATUS,
|
|
190
|
+
PI_TUI_WEB_ACCESS_SET_ENABLED,
|
|
191
|
+
{
|
|
192
|
+
id: PI_TUI_WEB_ACCESS_GET_AUTHENTICATED_URL_ENDPOINT,
|
|
193
|
+
service: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
194
|
+
namespace: PI_TUI_WEB_ACCESS_NAMESPACE,
|
|
195
|
+
method: "getAuthenticatedUrl",
|
|
196
|
+
invocation: { kind: "direct" },
|
|
197
|
+
parameters: [],
|
|
198
|
+
result: {
|
|
199
|
+
mode: "strict",
|
|
200
|
+
typeSymbol: "@xmoon76/dsh-pi-tui#piTuiWebAccess:authenticatedUrl",
|
|
201
|
+
create: () => ({ parse: parsePiTuiWebAccessAuthenticatedUrl }),
|
|
202
|
+
decode: parsePiTuiWebAccessAuthenticatedUrl
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
};
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/app/remote/dispose-cause.ts
|
|
209
|
+
/**
|
|
210
|
+
* Transport-neutral disposal failure chaining for the Remote composition.
|
|
211
|
+
*
|
|
212
|
+
* The helper is shared by the Host composition, the official Client runtime,
|
|
213
|
+
* the Client UI subtree and the application aggregate. It deliberately lives
|
|
214
|
+
* beside them (not inside `host-runtime.ts`) so a Client-only process entry can
|
|
215
|
+
* reuse it without importing a Host-only value graph.
|
|
216
|
+
*
|
|
217
|
+
* @module app/remote/dispose-cause
|
|
218
|
+
*/
|
|
219
|
+
/**
|
|
220
|
+
* Attach one secondary failure to `failure`'s cause chain without losing an
|
|
221
|
+
* existing cause: when the failure already carries a cause, both aggregate
|
|
222
|
+
* into a single `AggregateError`. A `undefined` secondary is a no-op.
|
|
223
|
+
*/
|
|
224
|
+
function mergeCause(failure, secondary) {
|
|
225
|
+
if (secondary === void 0) return failure;
|
|
226
|
+
const existingCause = failure.cause;
|
|
227
|
+
failure.cause = existingCause === void 0 ? secondary : new AggregateError([existingCause, secondary], "remote composition: aggregated failure causes");
|
|
228
|
+
return failure;
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/runtime/remote/pi-tui-file-reference-host-bridge.ts
|
|
232
|
+
/**
|
|
233
|
+
* The Remote Host-side bridge for the private `piTuiFileReferences` endpoint
|
|
234
|
+
* (TS8-HF1): a CONSTRUCTION/ADAPTATION seam ONLY. It binds the private Remote
|
|
235
|
+
* method to the SAME Host-scoped completion authority the Direct adapter uses
|
|
236
|
+
* (`runtime/direct/host-file-augmentation-direct.ts` + the Direct Host
|
|
237
|
+
* discovery driver) and returns a transport-neutral `list` runtime.
|
|
238
|
+
*
|
|
239
|
+
* It owns NO Cordis service, NO Typert registration and NO lifecycle policy —
|
|
240
|
+
* the Cordis service, its Typert contribution registration and its disposal
|
|
241
|
+
* remain with the built-in PiTui Host Runtime
|
|
242
|
+
* (`app/host/features/file-reference.ts`). The dependency direction is
|
|
243
|
+
* therefore `app/host/features/** -> runtime/remote/** -> runtime/direct/**`,
|
|
244
|
+
* never `app/host/** -> runtime/direct/**`.
|
|
245
|
+
*
|
|
246
|
+
* The bridge lives in `runtime/remote/**` because that layer may consume the
|
|
247
|
+
* Direct Host implementation; the composition layer may not.
|
|
248
|
+
*
|
|
249
|
+
* @module @xmoon76/dsh-pi-tui/runtime/remote/pi-tui-file-reference-host-bridge
|
|
250
|
+
*/
|
|
251
|
+
/**
|
|
252
|
+
* Bind the private Remote method to the Host-scoped completion authority.
|
|
253
|
+
* The Host finder is resolved ONCE for the runtime's lifetime (it is a pure
|
|
254
|
+
* PATH pin; a later PATH change is not a Host completion fact).
|
|
255
|
+
*/
|
|
256
|
+
function createPiTuiHostFileReferenceRuntime(deps) {
|
|
257
|
+
const driver = new DirectHostDiscoveryDriver(deps.fdPath);
|
|
258
|
+
const environment = hostPathQueryEnvironment();
|
|
259
|
+
return { async list(sessionId, query, signal) {
|
|
260
|
+
signal.throwIfAborted();
|
|
261
|
+
const agent = deps.agentFor(sessionId);
|
|
262
|
+
if (agent === void 0) return {
|
|
263
|
+
kind: "unavailable",
|
|
264
|
+
reason: "the requested Session has no live Host Agent"
|
|
265
|
+
};
|
|
266
|
+
return await listPiTuiHostFileReferences(agent, query, signal, {
|
|
267
|
+
official: deps.official(),
|
|
268
|
+
driver,
|
|
269
|
+
environment,
|
|
270
|
+
workingDirectory: deps.workingDirectory?.()
|
|
271
|
+
});
|
|
272
|
+
} };
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/app/host/features/file-reference.ts
|
|
276
|
+
/**
|
|
277
|
+
* The Host endpoint of the private augmentation. One instance per built-in
|
|
278
|
+
* Host Runtime; the descriptor leaves with the owning fiber.
|
|
279
|
+
*/
|
|
280
|
+
var PiTuiFileReferenceHostService = class extends TypertRemoteService {
|
|
281
|
+
/** The Typert registry owns the explicit invocation definitions. */
|
|
282
|
+
static inject = ["typert"];
|
|
283
|
+
runtime;
|
|
284
|
+
/**
|
|
285
|
+
* @param ctx - the Host context this row is mounted in.
|
|
286
|
+
* @param deps - the narrow Host facts the built-in Host Runtime resolved.
|
|
287
|
+
*/
|
|
288
|
+
constructor(ctx, deps) {
|
|
289
|
+
super(ctx, PI_TUI_FILE_REFERENCES_NAMESPACE);
|
|
290
|
+
this.runtime = createPiTuiHostFileReferenceRuntime({
|
|
291
|
+
...deps,
|
|
292
|
+
workingDirectory: () => ctx.get("workingDirectory")
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The private Remote method (`piTuiFileReferences/list`, see
|
|
297
|
+
* `pi-tui-file-reference-contract.ts`). Cancellation outranks every outcome.
|
|
298
|
+
*/
|
|
299
|
+
list(sessionId, query, signal) {
|
|
300
|
+
return this.runtime.list(sessionId, query, signal);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/app/host/features/terminal-progress.ts
|
|
305
|
+
/** The structural `turn/start` / `turn/end` payload read (never a guessed shape). */
|
|
306
|
+
function turnOf(data) {
|
|
307
|
+
const turn = data?.turn;
|
|
308
|
+
return typeof turn === "number" ? turn : void 0;
|
|
309
|
+
}
|
|
310
|
+
/** The merge-extensible `turn/end.reason.kind` discriminant. */
|
|
311
|
+
function reasonKindOf(data) {
|
|
312
|
+
const reason = data?.reason;
|
|
313
|
+
return typeof reason?.kind === "string" ? reason.kind : void 0;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Frames one subscriber may fall behind by before the stream is failed instead
|
|
317
|
+
* of silently losing an edge. A real run produces a handful of transitions, so
|
|
318
|
+
* only a consumer that stopped draining can reach it.
|
|
319
|
+
*/
|
|
320
|
+
const SUBSCRIBER_QUEUE_LIMIT = 64;
|
|
321
|
+
/**
|
|
322
|
+
* One subscriber's ordered frame queue. The Host ALWAYS mutates the record
|
|
323
|
+
* before pushing, so a queue can never observe a frame the record has not
|
|
324
|
+
* committed, and `close()` is idempotent.
|
|
325
|
+
*
|
|
326
|
+
* An overflowing queue FAILS the reader: dropping frames and continuing would
|
|
327
|
+
* let a stream report a settlement whose running edge it lost (plan §6.5).
|
|
328
|
+
*/
|
|
329
|
+
var FrameQueue = class {
|
|
330
|
+
frames = [];
|
|
331
|
+
wake;
|
|
332
|
+
closed = false;
|
|
333
|
+
failure;
|
|
334
|
+
limit = SUBSCRIBER_QUEUE_LIMIT;
|
|
335
|
+
push(frame) {
|
|
336
|
+
if (this.closed || this.failure !== void 0) return;
|
|
337
|
+
if (this.frames.length >= this.limit) {
|
|
338
|
+
this.failure = /* @__PURE__ */ new Error("piTuiTerminalProgress: the subscriber queue overflowed");
|
|
339
|
+
this.frames.length = 0;
|
|
340
|
+
const wake = this.wake;
|
|
341
|
+
this.wake = void 0;
|
|
342
|
+
wake?.();
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
this.frames.push(frame);
|
|
346
|
+
const wake = this.wake;
|
|
347
|
+
this.wake = void 0;
|
|
348
|
+
wake?.();
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* End the consumer's read AFTER every frame already committed to it: a
|
|
352
|
+
* disposal publishes the retired interval BEFORE it ends the watchers, and a
|
|
353
|
+
* committed terminal fact must never be dropped in flight.
|
|
354
|
+
*/
|
|
355
|
+
close() {
|
|
356
|
+
if (this.closed) return;
|
|
357
|
+
this.closed = true;
|
|
358
|
+
const wake = this.wake;
|
|
359
|
+
this.wake = void 0;
|
|
360
|
+
wake?.();
|
|
361
|
+
}
|
|
362
|
+
async next() {
|
|
363
|
+
for (;;) {
|
|
364
|
+
const frame = this.frames.shift();
|
|
365
|
+
if (frame !== void 0) return {
|
|
366
|
+
value: frame,
|
|
367
|
+
done: false
|
|
368
|
+
};
|
|
369
|
+
if (this.failure !== void 0) throw this.failure;
|
|
370
|
+
if (this.closed) return {
|
|
371
|
+
value: void 0,
|
|
372
|
+
done: true
|
|
373
|
+
};
|
|
374
|
+
await new Promise((resolve) => {
|
|
375
|
+
this.wake = resolve;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
/**
|
|
381
|
+
* The Host endpoint of the private stream. One instance per built-in Host
|
|
382
|
+
* Runtime; the descriptors and the subscriptions leave with the fiber.
|
|
383
|
+
*/
|
|
384
|
+
var PiTuiTerminalProgressHostService = class extends TypertRemoteService {
|
|
385
|
+
/** The Typert registry owns the explicit invocation definition. */
|
|
386
|
+
static inject = ["typert"];
|
|
387
|
+
/** The narrow Host facts the built-in Host Runtime resolved (explicit field:
|
|
388
|
+
* the strip-only TS loader rejects parameter properties). */
|
|
389
|
+
deps;
|
|
390
|
+
/** One opaque identity per Host plugin instance: a Host restart, a new
|
|
391
|
+
* composition or a re-mounted fiber all invalidate older frames. */
|
|
392
|
+
hostEpoch = `host-${randomEpoch()}`;
|
|
393
|
+
records = /* @__PURE__ */ new Map();
|
|
394
|
+
/** Monotonic Agent-lifetime counter: a replacement ALWAYS outranks every
|
|
395
|
+
* earlier lifetime of the same session, even after its record was dropped. */
|
|
396
|
+
epochCounter = 0;
|
|
397
|
+
disposed = false;
|
|
398
|
+
/**
|
|
399
|
+
* @param ctx - the Host context this row is mounted in.
|
|
400
|
+
* @param deps - the narrow Host facts the built-in Host Runtime resolved.
|
|
401
|
+
*/
|
|
402
|
+
constructor(ctx, deps) {
|
|
403
|
+
super(ctx, PI_TUI_TERMINAL_PROGRESS_NAMESPACE);
|
|
404
|
+
this.deps = deps;
|
|
405
|
+
ctx.on("agent/status", ({ agent, status }) => {
|
|
406
|
+
this.onAgentStatus(agent, status);
|
|
407
|
+
}, { global: true });
|
|
408
|
+
ctx.on("session/event", (session, event) => {
|
|
409
|
+
this.onSessionEvent(session, event.type, event.data);
|
|
410
|
+
}, { global: true });
|
|
411
|
+
ctx.on("agent/disposed", ({ agent }) => {
|
|
412
|
+
this.onAgentDisposed(agent);
|
|
413
|
+
}, { global: true });
|
|
414
|
+
ctx.effect(() => () => {
|
|
415
|
+
this.closeAll();
|
|
416
|
+
}, "pi-tui-terminal-progress-watchers");
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* The private Remote method (`piTuiTerminalProgress/watch`): the ONE
|
|
420
|
+
* per-session ordered stream, opening with the authoritative snapshot of the
|
|
421
|
+
* instant it subscribes and then every real Host-side change (plan §6.5).
|
|
422
|
+
*
|
|
423
|
+
* The subscriber is registered and the cut (revision + current state) is
|
|
424
|
+
* captured in the SAME synchronous block before the first `yield`, so an
|
|
425
|
+
* update can neither be lost between the snapshot and the subscription nor be
|
|
426
|
+
* replayed twice.
|
|
427
|
+
*/
|
|
428
|
+
async *watch(sessionId, signal) {
|
|
429
|
+
const record = this.recordFor(sessionId);
|
|
430
|
+
const queue = new FrameQueue();
|
|
431
|
+
const cut = record.revision;
|
|
432
|
+
const snapshot = {
|
|
433
|
+
kind: "snapshot",
|
|
434
|
+
sessionId,
|
|
435
|
+
hostEpoch: this.hostEpoch,
|
|
436
|
+
agentEpoch: record.agentEpoch,
|
|
437
|
+
revision: cut,
|
|
438
|
+
running: record.running,
|
|
439
|
+
outcome: record.outcome
|
|
440
|
+
};
|
|
441
|
+
record.subscribers.add(queue);
|
|
442
|
+
const onAbort = () => {
|
|
443
|
+
queue.close();
|
|
444
|
+
};
|
|
445
|
+
if (signal.aborted) queue.close();
|
|
446
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
447
|
+
try {
|
|
448
|
+
yield snapshot;
|
|
449
|
+
for (;;) {
|
|
450
|
+
const next = await queue.next();
|
|
451
|
+
if (next.done === true) return;
|
|
452
|
+
yield next.value;
|
|
453
|
+
}
|
|
454
|
+
} finally {
|
|
455
|
+
signal.removeEventListener("abort", onAbort);
|
|
456
|
+
record.subscribers.delete(queue);
|
|
457
|
+
this.reclaim(record);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Drop a record nobody watches and no Agent owns. A watch of a session that
|
|
462
|
+
* has no live Agent must not leave an empty record behind for the rest of the
|
|
463
|
+
* Host's life: it is observable by nothing, and the next Agent lifetime starts
|
|
464
|
+
* a FRESH record carrying a HIGHER `agentEpoch` (the epoch counter never
|
|
465
|
+
* rewinds), so no Client provenance can be resurrected across the gap.
|
|
466
|
+
*/
|
|
467
|
+
reclaim(record) {
|
|
468
|
+
if (record.subscribers.size > 0 || record.agent !== void 0) return;
|
|
469
|
+
if (this.records.get(record.sessionId) === record) this.records.delete(record.sessionId);
|
|
470
|
+
}
|
|
471
|
+
/** The live `agent/status` transition of one Agent (plan §6.4). */
|
|
472
|
+
onAgentStatus(agent, status) {
|
|
473
|
+
if (this.deps.agentFor(agent.session.id) !== agent) return;
|
|
474
|
+
const record = this.recordFor(agent.session.id);
|
|
475
|
+
if (record.agent !== agent) return;
|
|
476
|
+
this.publish(record, record.fold.status(status === "running"));
|
|
477
|
+
}
|
|
478
|
+
/** One durable Session event (plan §6.4): evidence only, never an interim commit. */
|
|
479
|
+
onSessionEvent(session, type, data) {
|
|
480
|
+
const record = this.records.get(session.id);
|
|
481
|
+
if (record === void 0 || record.agent === void 0) return;
|
|
482
|
+
if (record.session !== session) return;
|
|
483
|
+
if (type === "turn/start") {
|
|
484
|
+
const turn = turnOf(data);
|
|
485
|
+
if (turn !== void 0) record.fold.turnStart(turn);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
if (type === "turn/end") {
|
|
489
|
+
const turn = turnOf(data);
|
|
490
|
+
const kind = reasonKindOf(data);
|
|
491
|
+
if (turn !== void 0 && kind !== void 0) record.fold.turnEnd(turn, kind);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
/** The Agent lifetime ended (plan §6.4): retire honestly, end the watchers. */
|
|
495
|
+
onAgentDisposed(agent) {
|
|
496
|
+
const record = this.records.get(agent.session.id);
|
|
497
|
+
if (record === void 0 || record.agent !== agent) return;
|
|
498
|
+
const retired = record.fold.retire();
|
|
499
|
+
if (retired !== void 0) this.publish(record, retired);
|
|
500
|
+
this.records.delete(agent.session.id);
|
|
501
|
+
for (const subscriber of record.subscribers) subscriber.close();
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* The record of one session, bound to the live Agent the authoritative Host
|
|
505
|
+
* registry currently holds. Creation AND a replaced Agent lifetime consume a
|
|
506
|
+
* new `agentEpoch` and reset the interval: a new Agent can never inherit the
|
|
507
|
+
* previous lifetime's evidence (plan §6.3/§6.4).
|
|
508
|
+
*/
|
|
509
|
+
recordFor(sessionId) {
|
|
510
|
+
let record = this.records.get(sessionId);
|
|
511
|
+
if (record === void 0) {
|
|
512
|
+
record = {
|
|
513
|
+
sessionId,
|
|
514
|
+
agent: void 0,
|
|
515
|
+
session: void 0,
|
|
516
|
+
agentEpoch: 0,
|
|
517
|
+
fold: createTerminalProgressInterval((kind) => {
|
|
518
|
+
this.deps.onUnknownReason(kind);
|
|
519
|
+
}),
|
|
520
|
+
revision: 0,
|
|
521
|
+
running: false,
|
|
522
|
+
outcome: "idle",
|
|
523
|
+
subscribers: /* @__PURE__ */ new Set()
|
|
524
|
+
};
|
|
525
|
+
this.records.set(sessionId, record);
|
|
526
|
+
}
|
|
527
|
+
const live = this.deps.agentFor(sessionId);
|
|
528
|
+
if (live !== void 0 && live !== record.agent) this.rebind(record, live);
|
|
529
|
+
return record;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Bind one Agent lifetime: the running truth is read from the Agent's OWN
|
|
533
|
+
* current status (a plugin mounted mid-run may therefore report `working`),
|
|
534
|
+
* but the outcome starts at `idle` — an unobserved start can never prove a
|
|
535
|
+
* settlement. The rebind is ALWAYS published, because the epoch change is
|
|
536
|
+
* itself a fact the Client must fence on.
|
|
537
|
+
*/
|
|
538
|
+
rebind(record, agent) {
|
|
539
|
+
record.agent = agent;
|
|
540
|
+
record.session = agent.session;
|
|
541
|
+
record.agentEpoch = ++this.epochCounter;
|
|
542
|
+
const running = agent.status === "running";
|
|
543
|
+
record.fold.apply({
|
|
544
|
+
active: running,
|
|
545
|
+
outcome: "idle"
|
|
546
|
+
});
|
|
547
|
+
record.running = running;
|
|
548
|
+
record.outcome = "idle";
|
|
549
|
+
record.revision += 1;
|
|
550
|
+
this.broadcast(record, "update");
|
|
551
|
+
}
|
|
552
|
+
/** Commit one fold transition: mutate the record FIRST, then broadcast. */
|
|
553
|
+
publish(record, next) {
|
|
554
|
+
if (next === void 0) return;
|
|
555
|
+
if (next.active === record.running && next.outcome === record.outcome) return;
|
|
556
|
+
record.running = next.active;
|
|
557
|
+
record.outcome = next.outcome;
|
|
558
|
+
record.revision += 1;
|
|
559
|
+
this.broadcast(record, "update");
|
|
560
|
+
}
|
|
561
|
+
broadcast(record, kind) {
|
|
562
|
+
const frame = {
|
|
563
|
+
kind,
|
|
564
|
+
sessionId: record.sessionId,
|
|
565
|
+
hostEpoch: this.hostEpoch,
|
|
566
|
+
agentEpoch: record.agentEpoch,
|
|
567
|
+
revision: record.revision,
|
|
568
|
+
running: record.running,
|
|
569
|
+
outcome: record.outcome
|
|
570
|
+
};
|
|
571
|
+
for (const subscriber of record.subscribers) subscriber.push(frame);
|
|
572
|
+
}
|
|
573
|
+
/** End every watcher (the row's fiber is going away). */
|
|
574
|
+
closeAll() {
|
|
575
|
+
if (this.disposed) return;
|
|
576
|
+
this.disposed = true;
|
|
577
|
+
for (const record of this.records.values()) for (const subscriber of record.subscribers) subscriber.close();
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
/** An opaque, process-unique Host-plugin identity (the wire sees only a string). */
|
|
581
|
+
function randomEpoch() {
|
|
582
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
583
|
+
}
|
|
584
|
+
//#endregion
|
|
585
|
+
//#region src/app/host/features/web-roster.ts
|
|
586
|
+
/**
|
|
587
|
+
* The ONE production Web-only Loader roster (C8: a single static member table).
|
|
588
|
+
*
|
|
589
|
+
* These are the official Browser Web rows the Host-only overlay declares and
|
|
590
|
+
* the private `piTuiWebAccess` Host service toggles at runtime. The row set is
|
|
591
|
+
* the official Web composition of the installed DSH family: it must satisfy
|
|
592
|
+
* every `dsh.client.inject` dependency the shipped official Client UIs declare,
|
|
593
|
+
* so it is fixed by those manifests rather than by a local count.
|
|
594
|
+
*
|
|
595
|
+
* PURE DATA, NO HOST DEPENDENCY: `local-host-entry.ts` renders this table into
|
|
596
|
+
* the Host-only overlay YAML, and `web-access.ts` verifies the LIVE Loader
|
|
597
|
+
* against it. The hand-written expectations stay their own oracles and must
|
|
598
|
+
* not be derived from this module: `WEB_ROWS` in
|
|
599
|
+
* `test/app/remote-process-host-foundation.test.ts` (that test imports this
|
|
600
|
+
* production table only to compare the toggle roster with the real overlay)
|
|
601
|
+
* and `PR_A_WEB_ROWS` in `scripts/smoke/split-process/web-helpers.mjs`.
|
|
602
|
+
*
|
|
603
|
+
* @module @xmoon76/dsh-pi-tui/app/host/features/web-roster
|
|
604
|
+
*/
|
|
605
|
+
/**
|
|
606
|
+
* The official Web-only Loader rows, in the overlay's canonical order, with the
|
|
607
|
+
* exact official package each row loads. The set, never a count, is the
|
|
608
|
+
* composition contract: every entry is the ONE owner of its published package.
|
|
609
|
+
*/
|
|
610
|
+
const PI_TUI_WEB_ACCESS_ROWS = [
|
|
611
|
+
{
|
|
612
|
+
id: "web-runtime",
|
|
613
|
+
name: "@deepseek-ai/dsh-web-app"
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
id: "modules",
|
|
617
|
+
name: "@deepseek-ai/dsh-client-modules"
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
id: "client-hmr",
|
|
621
|
+
name: "@deepseek-ai/dsh-client-hmr"
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
id: "cordis-client-runner",
|
|
625
|
+
name: "@deepseek-ai/dsh-cordis-client-runner"
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
id: "ui-file-actions",
|
|
629
|
+
name: "@deepseek-ai/dsh-client-ui-file-actions"
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
id: "ui-context-menu",
|
|
633
|
+
name: "@deepseek-ai/dsh-client-ui-context-menu"
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
id: "ui-open-in-app",
|
|
637
|
+
name: "@deepseek-ai/dsh-client-ui-open-in-app"
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
id: "ui-settings-account",
|
|
641
|
+
name: "@deepseek-ai/dsh-client-ui-settings-account"
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
id: "ui-theme",
|
|
645
|
+
name: "@deepseek-ai/dsh-client-ui-theme"
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
id: "locale",
|
|
649
|
+
name: "@deepseek-ai/dsh-client-locale"
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
id: "shortcuts",
|
|
653
|
+
name: "@deepseek-ai/dsh-client-shortcuts"
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
id: "ui-shortcuts",
|
|
657
|
+
name: "@deepseek-ai/dsh-client-ui-shortcuts"
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
id: "ui-layout",
|
|
661
|
+
name: "@deepseek-ai/dsh-client-ui-layout"
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
id: "ui-renderer",
|
|
665
|
+
name: "@deepseek-ai/dsh-client-ui-renderer"
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
id: "ui-session",
|
|
669
|
+
name: "@deepseek-ai/dsh-client-ui-session"
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
id: "resources",
|
|
673
|
+
name: "@deepseek-ai/dsh-client-resources"
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
id: "ui-sidebar",
|
|
677
|
+
name: "@deepseek-ai/dsh-client-ui-sidebar"
|
|
678
|
+
},
|
|
679
|
+
{
|
|
680
|
+
id: "ui-sidebar-right",
|
|
681
|
+
name: "@deepseek-ai/dsh-client-ui-sidebar-right"
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
id: "office-to-pdf",
|
|
685
|
+
name: "@deepseek-ai/dsh-office-to-pdf"
|
|
686
|
+
},
|
|
687
|
+
{
|
|
688
|
+
id: "ui-sidebar-documentpreview",
|
|
689
|
+
name: "@deepseek-ai/dsh-client-ui-sidebar-documentpreview"
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
id: "ui-sidebar-terminal",
|
|
693
|
+
name: "@deepseek-ai/dsh-client-ui-sidebar-terminal"
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
id: "ui-sidebar-files",
|
|
697
|
+
name: "@deepseek-ai/dsh-client-ui-sidebar-files"
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
id: "ui-settings",
|
|
701
|
+
name: "@deepseek-ai/dsh-client-ui-settings"
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
id: "ui-settings-general",
|
|
705
|
+
name: "@deepseek-ai/dsh-client-ui-settings-general"
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
id: "ui-settings-models",
|
|
709
|
+
name: "@deepseek-ai/dsh-client-ui-settings-models"
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
id: "ui-plugin-manager",
|
|
713
|
+
name: "@deepseek-ai/dsh-client-ui-plugin-manager"
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
id: "ui-settings-plugin-inventory",
|
|
717
|
+
name: "@deepseek-ai/dsh-client-ui-settings-plugin-inventory"
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
id: "ui-conversation",
|
|
721
|
+
name: "@deepseek-ai/dsh-client-ui-conversation"
|
|
722
|
+
},
|
|
723
|
+
{
|
|
724
|
+
id: "ui-approval",
|
|
725
|
+
name: "@deepseek-ai/dsh-client-ui-approval"
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
id: "message-quotes",
|
|
729
|
+
name: "@deepseek-ai/dsh-message-quotes"
|
|
730
|
+
},
|
|
731
|
+
{
|
|
732
|
+
id: "ui-chat",
|
|
733
|
+
name: "@deepseek-ai/dsh-client-ui-chat"
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
id: "ui-brand-official",
|
|
737
|
+
name: "@deepseek-ai/dsh-client-ui-brand-official"
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
id: "ui-attachment",
|
|
741
|
+
name: "@deepseek-ai/dsh-client-ui-attachment"
|
|
742
|
+
},
|
|
743
|
+
{
|
|
744
|
+
id: "ui-file-drag",
|
|
745
|
+
name: "@deepseek-ai/dsh-client-ui-file-drag"
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
id: "ui-tool",
|
|
749
|
+
name: "@deepseek-ai/dsh-client-ui-tool"
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
id: "ui-cordis",
|
|
753
|
+
name: "@deepseek-ai/dsh-client-ui-cordis"
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
id: "workspace-changes",
|
|
757
|
+
name: "@deepseek-ai/dsh-workspace-changes"
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
id: "ui-deliverables",
|
|
761
|
+
name: "@deepseek-ai/dsh-client-ui-deliverables"
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
id: "ui-workspace",
|
|
765
|
+
name: "@deepseek-ai/dsh-client-ui-workspace"
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
id: "ui-workflow-run",
|
|
769
|
+
name: "@deepseek-ai/dsh-client-ui-workflow-run"
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
id: "ui-input-trigger",
|
|
773
|
+
name: "@deepseek-ai/dsh-client-ui-input-trigger"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
id: "ui-commands",
|
|
777
|
+
name: "@deepseek-ai/dsh-client-ui-commands"
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
id: "ui-skill",
|
|
781
|
+
name: "@deepseek-ai/dsh-client-ui-skill"
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
id: "ui-subagent",
|
|
785
|
+
name: "@deepseek-ai/dsh-client-ui-subagent"
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
id: "ui-reference",
|
|
789
|
+
name: "@deepseek-ai/dsh-client-ui-reference"
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
id: "ui-secret-mask",
|
|
793
|
+
name: "@deepseek-ai/dsh-client-ui-secret-mask"
|
|
794
|
+
},
|
|
795
|
+
{
|
|
796
|
+
id: "ui-jobs",
|
|
797
|
+
name: "@deepseek-ai/dsh-client-ui-jobs"
|
|
798
|
+
},
|
|
799
|
+
{
|
|
800
|
+
id: "ui-schedule",
|
|
801
|
+
name: "@deepseek-ai/dsh-client-ui-schedule"
|
|
802
|
+
},
|
|
803
|
+
{
|
|
804
|
+
id: "ui-goal",
|
|
805
|
+
name: "@deepseek-ai/dsh-client-ui-goal"
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
id: "ui-message-feedback",
|
|
809
|
+
name: "@deepseek-ai/dsh-client-ui-message-feedback"
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
id: "ui-model-selection",
|
|
813
|
+
name: "@deepseek-ai/dsh-client-ui-model-selection"
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
id: "ui-permission",
|
|
817
|
+
name: "@deepseek-ai/dsh-client-ui-permission-presets"
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
id: "ui-agent-preset",
|
|
821
|
+
name: "@deepseek-ai/dsh-client-ui-agent-preset"
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
id: "entry-customization",
|
|
825
|
+
name: "@deepseek-ai/dsh-client-ui-entry-customization"
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
id: "ui-settings-session-log",
|
|
829
|
+
name: "@deepseek-ai/dsh-client-ui-settings-session-log"
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
id: "ui-settings-plugins",
|
|
833
|
+
name: "@deepseek-ai/dsh-client-ui-settings-plugins"
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
id: "ui-settings-shell",
|
|
837
|
+
name: "@deepseek-ai/dsh-client-ui-settings-shell"
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
id: "ui-settings-agent-loop",
|
|
841
|
+
name: "@deepseek-ai/dsh-client-ui-settings-agent-loop"
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
id: "ui-settings-subagent",
|
|
845
|
+
name: "@deepseek-ai/dsh-client-ui-settings-subagent"
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
id: "ui-settings-web-search",
|
|
849
|
+
name: "@deepseek-ai/dsh-client-ui-settings-web-search"
|
|
850
|
+
},
|
|
851
|
+
{
|
|
852
|
+
id: "ui-plan",
|
|
853
|
+
name: "@deepseek-ai/dsh-client-ui-plan"
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
id: "ui-user-questions",
|
|
857
|
+
name: "@deepseek-ai/dsh-client-ui-user-questions"
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
id: "ui-trajectory",
|
|
861
|
+
name: "@deepseek-ai/dsh-client-ui-trajectory"
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
id: "terminal-controller",
|
|
865
|
+
name: "@deepseek-ai/dsh-api-terminal-controller"
|
|
866
|
+
}
|
|
867
|
+
];
|
|
868
|
+
//#endregion
|
|
869
|
+
//#region src/app/host/features/web-access.ts
|
|
870
|
+
/** Cordis `FiberState.ACTIVE` (the enum is a const enum with no runtime value). */
|
|
871
|
+
const FIBER_ACTIVE = 2;
|
|
872
|
+
/**
|
|
873
|
+
* The production Web-only Loader roster is pure data owned by
|
|
874
|
+
* `./web-roster.ts`; this service verifies the LIVE Loader against it and owns
|
|
875
|
+
* every enable/disable transition. The table is the composition expectation,
|
|
876
|
+
* never a statement that those rows are currently mounted.
|
|
877
|
+
*/
|
|
878
|
+
/**
|
|
879
|
+
* The official Web services whose live binding is what `enabled` claims:
|
|
880
|
+
* `webApp` owns the SPA fallback, `clientModules` owns the `/plugins` graph,
|
|
881
|
+
* `terminalController` is the Web Browser's Host-side terminal owner, and
|
|
882
|
+
* `officeToPdf` is the Browser document-preview conversion provider.
|
|
883
|
+
*/
|
|
884
|
+
const REQUIRED_WEB_SERVICES = [
|
|
885
|
+
"webApp",
|
|
886
|
+
"clientModules",
|
|
887
|
+
"terminalController",
|
|
888
|
+
"officeToPdf"
|
|
889
|
+
];
|
|
890
|
+
/** The Browser graph rows that must be assembled first and released last. */
|
|
891
|
+
const BROWSER_GRAPH_ROWS = [
|
|
892
|
+
"modules",
|
|
893
|
+
"client-hmr",
|
|
894
|
+
"cordis-client-runner",
|
|
895
|
+
"terminal-controller"
|
|
896
|
+
];
|
|
897
|
+
const SPA_ROW = "web-runtime";
|
|
898
|
+
/** The Browser presentation rows, in the overlay's canonical order. */
|
|
899
|
+
const PRESENTATION_ROWS = PI_TUI_WEB_ACCESS_ROWS.map((row) => row.id).filter((id) => id !== SPA_ROW && !BROWSER_GRAPH_ROWS.includes(id));
|
|
900
|
+
/**
|
|
901
|
+
* FROZEN enable order: assemble the browser graph first, then its presentation
|
|
902
|
+
* rows, and withdraw nothing — the SPA fallback is mounted LAST so the official
|
|
903
|
+
* index is never served before the graph it advertises exists.
|
|
904
|
+
*
|
|
905
|
+
* Exported because the order is a product decision, not an implementation
|
|
906
|
+
* detail: the source test asserts THIS sequence.
|
|
907
|
+
*/
|
|
908
|
+
const PI_TUI_WEB_ACCESS_ENABLE_ORDER = [
|
|
909
|
+
...BROWSER_GRAPH_ROWS,
|
|
910
|
+
...PRESENTATION_ROWS,
|
|
911
|
+
SPA_ROW
|
|
912
|
+
];
|
|
913
|
+
/**
|
|
914
|
+
* FROZEN disable order: withdraw the SPA fallback FIRST, then the presentation
|
|
915
|
+
* rows in reverse canonical order, then the browser graph rows last so
|
|
916
|
+
* `clientModules` keeps owning `/plugins` until nothing can request it.
|
|
917
|
+
*
|
|
918
|
+
* Exported for the same reason as the enable order.
|
|
919
|
+
*/
|
|
920
|
+
const PI_TUI_WEB_ACCESS_DISABLE_ORDER = [
|
|
921
|
+
SPA_ROW,
|
|
922
|
+
...[...PRESENTATION_ROWS].reverse(),
|
|
923
|
+
...[...BROWSER_GRAPH_ROWS].reverse()
|
|
924
|
+
];
|
|
925
|
+
/** The package each roster id must load, keyed by id. */
|
|
926
|
+
const ROSTER_PACKAGES = new Map(PI_TUI_WEB_ACCESS_ROWS.map((row) => [row.id, row.name]));
|
|
927
|
+
/** Every official package exactly one roster row owns. */
|
|
928
|
+
const ROSTER_PACKAGE_NAMES = new Set(PI_TUI_WEB_ACCESS_ROWS.map((row) => row.name));
|
|
929
|
+
/** Append the best-effort cleanup failures to one redacted diagnostic. */
|
|
930
|
+
function withCleanup(reason, cleanup) {
|
|
931
|
+
if (cleanup.length === 0) return reason;
|
|
932
|
+
return `${reason} (cleanup: ${cleanup.map(reasonOf).join("; ")})`;
|
|
933
|
+
}
|
|
934
|
+
/** One fixed diagnostic for the status vocabulary (never a token/URL/path). */
|
|
935
|
+
function reasonOf(error) {
|
|
936
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
937
|
+
return message.length > 300 ? `${message.slice(0, 297)}...` : message;
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* The private Web access authority. One instance per built-in Host Runtime; the
|
|
941
|
+
* service leaves with the owning fiber.
|
|
942
|
+
*/
|
|
943
|
+
var PiTuiWebAccessHostService = class extends TypertRemoteService {
|
|
944
|
+
/**
|
|
945
|
+
* The Typert registry owns the descriptors. The Host's Loader is read PER CALL
|
|
946
|
+
* (`loader()` below) instead of declared here: this service is mounted by a
|
|
947
|
+
* Loader row, so the Loader is guaranteed in every real composition, and a
|
|
948
|
+
* Host that somehow lacks one must report `unavailable` rather than hold the
|
|
949
|
+
* mounting row pending forever.
|
|
950
|
+
*/
|
|
951
|
+
static inject = ["typert"];
|
|
952
|
+
/** The serialized mutation chain: one toggle runs at a time, failures do not poison it. */
|
|
953
|
+
tail = Promise.resolve();
|
|
954
|
+
/** The number of serialized mutations currently running (the `changing` state). */
|
|
955
|
+
inFlight = 0;
|
|
956
|
+
/**
|
|
957
|
+
* The current Host lifetime's last SUCCESSFULLY requested enablement, or
|
|
958
|
+
* `undefined` before any toggle. It is a TARGET INTENT for the recomposition
|
|
959
|
+
* repair only — NEVER a state authority: `getStatus()`/`describe()` keep
|
|
960
|
+
* reading the live Loader rows and official Web services on every call.
|
|
961
|
+
*/
|
|
962
|
+
target;
|
|
963
|
+
/**
|
|
964
|
+
* @param ctx - the Host context this row is mounted in.
|
|
965
|
+
*/
|
|
966
|
+
constructor(ctx) {
|
|
967
|
+
super(ctx, PI_TUI_WEB_ACCESS_NAMESPACE);
|
|
968
|
+
ctx.on("app-boot/config-reload", () => {
|
|
969
|
+
this.reconcileAfterRecompose();
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* The private status method (`piTuiWebAccess/getStatus`, see
|
|
974
|
+
* `pi-tui-web-access-contract.ts`). Reads the live Loader rows and the
|
|
975
|
+
* official Web services on every call; never a cached flag.
|
|
976
|
+
*/
|
|
977
|
+
async getStatus() {
|
|
978
|
+
return this.inFlight > 0 ? { state: "changing" } : this.describe();
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* The private authenticated-URL method (`piTuiWebAccess/getAuthenticatedUrl`):
|
|
982
|
+
* the official launch URL of THIS Host's Web frontend, built by the official
|
|
983
|
+
* `connection.authenticatedUrl(webServer.getOrigin() + '/')`.
|
|
984
|
+
*
|
|
985
|
+
* It answers ONLY while the live roster/status is `enabled`. The value carries
|
|
986
|
+
* the official launch token, so this method never stores it, never adds it to
|
|
987
|
+
* a status object and never writes it to a diagnostic: the caller (one
|
|
988
|
+
* explicit user action) is the only owner.
|
|
989
|
+
*
|
|
990
|
+
* @returns the official authenticated URL of the running Web frontend.
|
|
991
|
+
*/
|
|
992
|
+
async getAuthenticatedUrl() {
|
|
993
|
+
const status = await this.getStatus();
|
|
994
|
+
if (status.state !== "enabled") throw new Error(status.state === "unavailable" ? `web access: the official Web frontend is unavailable (${status.reason})` : "web access: the official Web frontend is not enabled");
|
|
995
|
+
const connection = this.ctx.get("connection");
|
|
996
|
+
if (connection === void 0 || typeof connection.authenticatedUrl !== "function") throw new Error("web access: the Host has no official Connection service");
|
|
997
|
+
const webServer = this.ctx.get("webServer");
|
|
998
|
+
if (webServer === void 0 || typeof webServer.getOrigin !== "function") throw new Error("web access: the Host has no official WebServer service");
|
|
999
|
+
return { url: connection.authenticatedUrl(`${webServer.getOrigin()}/`) };
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* The private mutation method (`piTuiWebAccess/setEnabled`). Idempotent: a
|
|
1003
|
+
* request for the already-settled state touches no row. Concurrent requests
|
|
1004
|
+
* are serialized in ONE Host-owned promise queue, and a failed mutation never
|
|
1005
|
+
* poisons the following entries.
|
|
1006
|
+
*
|
|
1007
|
+
* @param enabled - whether the official Web frontend must be serving.
|
|
1008
|
+
* @returns the status the Host actually reached, never the requested boolean.
|
|
1009
|
+
*/
|
|
1010
|
+
setEnabled(enabled) {
|
|
1011
|
+
const run = this.tail.then(() => this.applyAndTrack(enabled));
|
|
1012
|
+
this.tail = run.then(() => void 0, () => void 0);
|
|
1013
|
+
return run;
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* One serialized mutation that updates the target intent ONLY when the Host
|
|
1017
|
+
* really reached the requested state. A failed/partial mutation leaves the
|
|
1018
|
+
* previous successful intent in place and reports its reached state.
|
|
1019
|
+
*/
|
|
1020
|
+
async applyAndTrack(enabled) {
|
|
1021
|
+
const status = await this.apply(enabled);
|
|
1022
|
+
if (status.state === (enabled ? "enabled" : "disabled")) this.target = enabled ? "enabled" : "disabled";
|
|
1023
|
+
return status;
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Repair the live roster after the official profile recomposition.
|
|
1027
|
+
*
|
|
1028
|
+
* The listener runs synchronously and only ENQUEUES the repair on the same
|
|
1029
|
+
* serialized chain (the official emit does not await promises, and a settings
|
|
1030
|
+
* write also reconciles before and after its own write). The LATEST target is
|
|
1031
|
+
* re-read when the repair actually runs, so a user toggle admitted later wins
|
|
1032
|
+
* in FIFO order. No repair runs before the first successful toggle, and a
|
|
1033
|
+
* failed repair is reported by the live status (never a fabricated success).
|
|
1034
|
+
*/
|
|
1035
|
+
reconcileAfterRecompose() {
|
|
1036
|
+
const run = this.tail.then(() => {
|
|
1037
|
+
const target = this.target;
|
|
1038
|
+
if (target === void 0) return this.describe();
|
|
1039
|
+
const status = this.describe();
|
|
1040
|
+
if (status.state === target) return status;
|
|
1041
|
+
return this.applyAndTrack(target === "enabled");
|
|
1042
|
+
});
|
|
1043
|
+
this.tail = run.then(() => void 0, () => void 0);
|
|
1044
|
+
run.then((status) => {
|
|
1045
|
+
if (status.state === "unavailable") this.logger().warn("profile recomposition repair did not reach the live target", { state: status.state });
|
|
1046
|
+
}, (error) => {
|
|
1047
|
+
this.logger().warn("profile recomposition repair failed", { reason: reasonOf(error) });
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
/** The row's own Cordis logger (diagnostics only; never a state channel). */
|
|
1051
|
+
logger() {
|
|
1052
|
+
return this.ctx.logger("pi-tui-web-access");
|
|
1053
|
+
}
|
|
1054
|
+
/** Run one serialized mutation and always report the reached state. */
|
|
1055
|
+
async apply(enabled) {
|
|
1056
|
+
this.inFlight += 1;
|
|
1057
|
+
try {
|
|
1058
|
+
let roster;
|
|
1059
|
+
try {
|
|
1060
|
+
roster = this.resolveRoster();
|
|
1061
|
+
} catch (error) {
|
|
1062
|
+
return {
|
|
1063
|
+
state: "unavailable",
|
|
1064
|
+
reason: reasonOf(error)
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
const targetDisabled = !enabled;
|
|
1068
|
+
if (PI_TUI_WEB_ACCESS_ROWS.filter((row) => roster.get(row.id).disabled !== targetDisabled).length === 0) return this.describe();
|
|
1069
|
+
try {
|
|
1070
|
+
if (enabled) await this.enableRows(roster);
|
|
1071
|
+
else await this.disableRows(roster);
|
|
1072
|
+
} catch (error) {
|
|
1073
|
+
const cleanup = await this.disableRemaining(roster);
|
|
1074
|
+
return {
|
|
1075
|
+
state: "unavailable",
|
|
1076
|
+
reason: withCleanup(reasonOf(error), cleanup)
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
const settled = this.describe();
|
|
1080
|
+
if (enabled && settled.state !== "enabled") {
|
|
1081
|
+
const cleanup = await this.disableRemaining(roster);
|
|
1082
|
+
return {
|
|
1083
|
+
state: "unavailable",
|
|
1084
|
+
reason: withCleanup(settled.state === "unavailable" ? settled.reason : "web access: the Web graph did not settle", cleanup)
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
return settled;
|
|
1088
|
+
} finally {
|
|
1089
|
+
this.inFlight -= 1;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Bring the whole Web roster up in the frozen enable order. Every row is
|
|
1094
|
+
* awaited through its own fiber (so a rejected plugin apply is a real
|
|
1095
|
+
* failure) and through Loader settlement.
|
|
1096
|
+
*/
|
|
1097
|
+
async enableRows(roster) {
|
|
1098
|
+
for (const id of PI_TUI_WEB_ACCESS_ENABLE_ORDER) {
|
|
1099
|
+
const entry = roster.get(id);
|
|
1100
|
+
if (entry.disabled) await entry.update({ disabled: false });
|
|
1101
|
+
await this.settleEnabled(entry);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
/** Tear the whole Web roster down in the frozen disable order. */
|
|
1105
|
+
async disableRows(roster) {
|
|
1106
|
+
for (const id of PI_TUI_WEB_ACCESS_DISABLE_ORDER) await this.disableEntry(roster.get(id));
|
|
1107
|
+
}
|
|
1108
|
+
/** Dispose ONE Web row and await its fiber release plus Loader settlement. */
|
|
1109
|
+
async disableEntry(entry) {
|
|
1110
|
+
if (entry.disabled) return;
|
|
1111
|
+
const released = entry.fiber;
|
|
1112
|
+
await entry.update({ disabled: true });
|
|
1113
|
+
await released?.inertia;
|
|
1114
|
+
await this.loader().await();
|
|
1115
|
+
}
|
|
1116
|
+
/** Await one enabled row's fiber AND its Loader settlement. */
|
|
1117
|
+
async settleEnabled(entry) {
|
|
1118
|
+
const fiber = entry.fiber;
|
|
1119
|
+
if (fiber === void 0) throw new Error(`web access: the "${entry.options.id}" row did not mount a fiber`);
|
|
1120
|
+
await fiber.await();
|
|
1121
|
+
await this.loader().await();
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Best-effort recovery after a failed mutation: return the WHOLE Web roster
|
|
1125
|
+
* to disabled, reporting every cleanup failure instead of swallowing it. A
|
|
1126
|
+
* failed disable keeps closing; a failed enable withdraws what it mounted so
|
|
1127
|
+
* no partial Web surface stays served. Shared Host owners are never touched.
|
|
1128
|
+
*/
|
|
1129
|
+
async disableRemaining(roster) {
|
|
1130
|
+
const failures = [];
|
|
1131
|
+
for (const id of PI_TUI_WEB_ACCESS_DISABLE_ORDER) try {
|
|
1132
|
+
await this.disableEntry(roster.get(id));
|
|
1133
|
+
} catch (error) {
|
|
1134
|
+
failures.push(error);
|
|
1135
|
+
}
|
|
1136
|
+
return failures;
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Read the availability the live Loader and the official Web services prove.
|
|
1140
|
+
* A settled roster is `disabled` (everything off) or `enabled` (everything on
|
|
1141
|
+
* and the Web services live); anything in between is `unavailable`, because
|
|
1142
|
+
* neither claim would be true.
|
|
1143
|
+
*/
|
|
1144
|
+
describe() {
|
|
1145
|
+
let roster;
|
|
1146
|
+
try {
|
|
1147
|
+
roster = this.resolveRoster();
|
|
1148
|
+
} catch (error) {
|
|
1149
|
+
return {
|
|
1150
|
+
state: "unavailable",
|
|
1151
|
+
reason: reasonOf(error)
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
const disabled = PI_TUI_WEB_ACCESS_ROWS.filter((row) => roster.get(row.id).disabled);
|
|
1155
|
+
if (disabled.length === PI_TUI_WEB_ACCESS_ROWS.length) {
|
|
1156
|
+
const published = REQUIRED_WEB_SERVICES.filter((service) => this.ctx.reflect.get(service) !== void 0);
|
|
1157
|
+
if (published.length > 0) return {
|
|
1158
|
+
state: "unavailable",
|
|
1159
|
+
reason: `web access: the Web rows are disabled but the official Web services are still published: ${published.join(", ")}`
|
|
1160
|
+
};
|
|
1161
|
+
return { state: "disabled" };
|
|
1162
|
+
}
|
|
1163
|
+
if (disabled.length > 0) {
|
|
1164
|
+
const named = disabled.slice(0, 8).map((row) => row.id).join(", ");
|
|
1165
|
+
const more = disabled.length > 8 ? ", ..." : "";
|
|
1166
|
+
return {
|
|
1167
|
+
state: "unavailable",
|
|
1168
|
+
reason: `web access: ${String(disabled.length)} of the ${String(PI_TUI_WEB_ACCESS_ROWS.length)} Web rows are disabled (${named}${more}) and the rest are enabled`
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
for (const row of PI_TUI_WEB_ACCESS_ROWS) {
|
|
1172
|
+
const state = roster.get(row.id).fiber?.state;
|
|
1173
|
+
if (state === FIBER_ACTIVE) continue;
|
|
1174
|
+
return {
|
|
1175
|
+
state: "unavailable",
|
|
1176
|
+
reason: `web access: the "${row.id}" row is ${state === void 0 ? "not started" : `state-${String(state)}`}, not active`
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
const missing = REQUIRED_WEB_SERVICES.filter((service) => this.ctx.reflect.get(service) === void 0);
|
|
1180
|
+
if (missing.length > 0) return {
|
|
1181
|
+
state: "unavailable",
|
|
1182
|
+
reason: `web access: the official Web services are missing: ${missing.join(", ")}`
|
|
1183
|
+
};
|
|
1184
|
+
return { state: "enabled" };
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* Resolve EXACTLY one live row per roster id from this Host's own Loader.
|
|
1188
|
+
* A missing, duplicated or re-pointed row is refused instead of toggling a
|
|
1189
|
+
* partial graph.
|
|
1190
|
+
*/
|
|
1191
|
+
resolveRoster() {
|
|
1192
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
1193
|
+
for (const entry of this.loader().entries()) {
|
|
1194
|
+
const id = entry.options.id;
|
|
1195
|
+
const expected = ROSTER_PACKAGES.get(id);
|
|
1196
|
+
if (expected === void 0) {
|
|
1197
|
+
if (ROSTER_PACKAGE_NAMES.has(entry.options.name)) throw new Error(`web access: the Loader owns a second ${JSON.stringify(entry.options.name)} row outside the roster ("${id}")`);
|
|
1198
|
+
continue;
|
|
1199
|
+
}
|
|
1200
|
+
if (entry.options.name !== expected) throw new Error(`web access: the "${id}" row loads ${JSON.stringify(entry.options.name)}, not ${JSON.stringify(expected)}`);
|
|
1201
|
+
if (resolved.has(id)) throw new Error(`web access: the Loader owns more than one "${id}" row`);
|
|
1202
|
+
resolved.set(id, entry);
|
|
1203
|
+
}
|
|
1204
|
+
const missing = PI_TUI_WEB_ACCESS_ROWS.map((row) => row.id).filter((id) => !resolved.has(id));
|
|
1205
|
+
if (missing.length > 0) throw new Error(`web access: the Host Loader does not own the Web rows: ${missing.join(", ")}`);
|
|
1206
|
+
return resolved;
|
|
1207
|
+
}
|
|
1208
|
+
/** Read the Host's own Loader service per call, never a composition snapshot. */
|
|
1209
|
+
loader() {
|
|
1210
|
+
const loader = this.ctx.get("loader");
|
|
1211
|
+
if (loader === void 0) throw new Error("web access: the Host has no Loader service");
|
|
1212
|
+
return loader;
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
//#endregion
|
|
1216
|
+
//#region src/app/host/pi-tui-host-runtime.ts
|
|
1217
|
+
/** Stable Cordis plugin name (the Loader row id in the Host-only overlay). */
|
|
1218
|
+
const name = "pi-tui-host-runtime";
|
|
1219
|
+
/**
|
|
1220
|
+
* Explicit Host dependencies: the private Typert registry plus the two live
|
|
1221
|
+
* Host facts the business rows resolve per call. `tuiStartup` remains a Loader
|
|
1222
|
+
* row gate (see the Host-only overlay), not a plugin inject. The Web access row
|
|
1223
|
+
* resolves the Host's OWN Loader through the service on every call, so this
|
|
1224
|
+
* published row contract does not change: this row IS a Loader row, and a Host
|
|
1225
|
+
* without a Loader fails closed (`unavailable`) instead of pending forever.
|
|
1226
|
+
*/
|
|
1227
|
+
const inject = [
|
|
1228
|
+
"typert",
|
|
1229
|
+
"agents",
|
|
1230
|
+
"fileReferences",
|
|
1231
|
+
"workingDirectory"
|
|
1232
|
+
];
|
|
1233
|
+
/** Data-free readiness gate published after the whole built-in runtime is live. */
|
|
1234
|
+
const PI_TUI_HOST_READY_SERVICE = "piTuiHostReady";
|
|
1235
|
+
/**
|
|
1236
|
+
* Read the LIVE Agent of one Session through the authoritative Host registry
|
|
1237
|
+
* PER CALL: a replaced registry or Agent must be observed, never a
|
|
1238
|
+
* composition-time snapshot.
|
|
1239
|
+
*/
|
|
1240
|
+
function agentFor(ctx, sessionId) {
|
|
1241
|
+
return ctx.reflect.get("agents")?.get(sessionId);
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Assert one private Typert service is readable through its exact Cordis
|
|
1245
|
+
* service key and carries the expected wire namespace. A truthy service alone
|
|
1246
|
+
* is not proof: the Gateway dispatches on the binding, not the service object.
|
|
1247
|
+
*/
|
|
1248
|
+
function assertPrivateBinding(ctx, serviceKey, namespace) {
|
|
1249
|
+
const service = ctx.reflect.get(serviceKey);
|
|
1250
|
+
if (service === void 0) throw new Error(`pi-tui-host-runtime: the "${serviceKey}" service is not readable`);
|
|
1251
|
+
const binding = service.typertRemote;
|
|
1252
|
+
if (binding === void 0) throw new Error(`pi-tui-host-runtime: the "${serviceKey}" service has no Typert binding`);
|
|
1253
|
+
if (binding.serviceKey !== serviceKey) throw new Error(`pi-tui-host-runtime: the "${serviceKey}" Typert service key is ${JSON.stringify(binding.serviceKey)}`);
|
|
1254
|
+
if (binding.namespace !== namespace) throw new Error(`pi-tui-host-runtime: the "${serviceKey}" Typert namespace is ${JSON.stringify(binding.namespace)}`);
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Mount the built-in PiTui Host Runtime on the launching Host Context.
|
|
1258
|
+
*
|
|
1259
|
+
* Startup order is fixed: register the package's ONE contribution, mount the
|
|
1260
|
+
* file-reference service, mount the terminal-progress service, mount the Web
|
|
1261
|
+
* access service, verify ALL live bindings, then publish the readiness gate.
|
|
1262
|
+
* Every child fiber is recorded BEFORE it is awaited; a partial rejection
|
|
1263
|
+
* disposes the recorded children in reverse order (contribution last) while
|
|
1264
|
+
* keeping the original error primary and attaching cleanup failures to its
|
|
1265
|
+
* cause chain.
|
|
1266
|
+
*/
|
|
1267
|
+
async function apply(ctx) {
|
|
1268
|
+
const fibers = [];
|
|
1269
|
+
let disposeContribution;
|
|
1270
|
+
try {
|
|
1271
|
+
disposeContribution = ctx.effect(() => ctx.typert.register(PI_TUI_HOST_CONTRIBUTION), "pi-tui-private-remote-host");
|
|
1272
|
+
const fileReferenceFiber = ctx.inject(PiTuiFileReferenceHostService.inject, (pluginCtx) => {
|
|
1273
|
+
new PiTuiFileReferenceHostService(pluginCtx, {
|
|
1274
|
+
agentFor: (sessionId) => agentFor(ctx, sessionId),
|
|
1275
|
+
official: () => ctx.reflect.get("fileReferences")
|
|
1276
|
+
});
|
|
1277
|
+
});
|
|
1278
|
+
fibers.push(fileReferenceFiber);
|
|
1279
|
+
await fileReferenceFiber;
|
|
1280
|
+
const terminalProgressFiber = ctx.inject(PiTuiTerminalProgressHostService.inject, (pluginCtx) => {
|
|
1281
|
+
new PiTuiTerminalProgressHostService(pluginCtx, {
|
|
1282
|
+
agentFor: (sessionId) => agentFor(ctx, sessionId),
|
|
1283
|
+
onUnknownReason: (kind) => {
|
|
1284
|
+
ctx.logger("pi-tui-host-runtime").warn("terminal progress: unknown turn/end reason", { kind });
|
|
1285
|
+
}
|
|
1286
|
+
});
|
|
1287
|
+
});
|
|
1288
|
+
fibers.push(terminalProgressFiber);
|
|
1289
|
+
await terminalProgressFiber;
|
|
1290
|
+
const webAccessFiber = ctx.inject(PiTuiWebAccessHostService.inject, (pluginCtx) => {
|
|
1291
|
+
new PiTuiWebAccessHostService(pluginCtx);
|
|
1292
|
+
});
|
|
1293
|
+
fibers.push(webAccessFiber);
|
|
1294
|
+
await webAccessFiber;
|
|
1295
|
+
assertPrivateBinding(ctx, "piTuiFileReferences", PI_TUI_FILE_REFERENCES_NAMESPACE);
|
|
1296
|
+
assertPrivateBinding(ctx, "piTuiTerminalProgress", PI_TUI_TERMINAL_PROGRESS_NAMESPACE);
|
|
1297
|
+
assertPrivateBinding(ctx, "piTuiWebAccess", PI_TUI_WEB_ACCESS_NAMESPACE);
|
|
1298
|
+
ctx.provide(PI_TUI_HOST_READY_SERVICE, {});
|
|
1299
|
+
} catch (error) {
|
|
1300
|
+
const cleanupErrors = [];
|
|
1301
|
+
for (let index = fibers.length - 1; index >= 0; index -= 1) try {
|
|
1302
|
+
await fibers[index].dispose();
|
|
1303
|
+
} catch (cleanupError) {
|
|
1304
|
+
cleanupErrors.push(cleanupError);
|
|
1305
|
+
}
|
|
1306
|
+
if (disposeContribution !== void 0) try {
|
|
1307
|
+
await disposeContribution();
|
|
1308
|
+
} catch (cleanupError) {
|
|
1309
|
+
cleanupErrors.push(cleanupError);
|
|
1310
|
+
}
|
|
1311
|
+
const primary = error instanceof Error ? error : new Error(String(error));
|
|
1312
|
+
if (cleanupErrors.length === 0) throw primary;
|
|
1313
|
+
throw mergeCause(primary, cleanupErrors.length === 1 ? cleanupErrors[0] : new AggregateError(cleanupErrors, "pi-tui-host-runtime: child disposal failures"));
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
//#endregion
|
|
1317
|
+
export { PI_TUI_HOST_READY_SERVICE, apply, inject, name };
|