@xmoon76/dsh-pi-tui 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +28 -7
- package/README.md +25 -6
- package/dist/application-runtime-CbBO4bY-.mjs +6860 -0
- package/dist/bootstrap-DLOydLLj.mjs +108410 -0
- package/dist/builtins.mjs +2 -3
- package/dist/client-bootstrap-DwSFzcTW.mjs +872 -0
- package/dist/context-summary-Bz0AGXa1.mjs +12027 -0
- package/dist/{context-summary-DAisTA_7.mjs → context-summary-D9mhxPXL.mjs} +1468 -10
- package/dist/custom-items-CKrOBCox.mjs +655 -0
- package/dist/disposal-BYBbEpVY.mjs +54 -0
- package/dist/dispose-cause-BzcXo4hu.mjs +123 -0
- package/dist/dist-C7QMk0ws.mjs +15431 -0
- package/dist/{entry-control-DvSrndWd.mjs → entry-control-DnduyDiw.mjs} +12 -31
- package/dist/{extensions-CcuMY4n2.mjs → extensions-pcFiH7Qe.mjs} +758 -68
- package/dist/extensions.mjs +1 -1
- package/dist/host-bootstrap-CKdfLkNS.mjs +188 -0
- package/dist/host-foundation-probe-CYHsbAw6.mjs +143 -0
- package/dist/host-prerequisites-9JBTtVNu.mjs +36 -0
- package/dist/host-runtime.d.mts +26 -0
- package/dist/host-runtime.mjs +450 -0
- package/dist/index.d.mts +8 -1
- package/dist/index.mjs +5192 -2118
- package/dist/local-client.mjs +1681 -188
- package/dist/local-discovery-CXnLT4GF.mjs +755 -0
- package/dist/local-discovery-DVFFpfBG.mjs +2 -0
- package/dist/local-host.mjs +927 -78
- package/dist/local-transport-C9aonplC.mjs +513 -0
- package/dist/performance-host.d.mts +2 -2
- package/dist/performance-host.mjs +258 -1
- package/dist/pi-tui-remote-contribution-DRk6Tl3J.mjs +78 -0
- package/dist/pi-tui-terminal-progress-contract-CdBH9j78.mjs +70 -0
- package/dist/pi-tui-terminal-progress-contract-XTQKj-WW.mjs +905 -0
- package/dist/{runtime-vc4mdr-R.mjs → runtime-Bh5OsftD.mjs} +655 -675
- package/dist/runtime-C5ROZqFj.mjs +2 -0
- package/dist/{session-tdJHLnJR.mjs → session-4keoXjk0.mjs} +2341 -217
- package/dist/session-B2zqv4wr.mjs +10869 -0
- package/dist/{startup-JaVZoTIl.mjs → startup-Ct2UUjUL.mjs} +7 -6
- package/dist/startup.d.mts +1 -1
- package/dist/startup.mjs +1 -1
- package/dist/{client-bootstrap-F5DHFI9t.mjs → terminal-progress-source-BhufrZ74.mjs} +3431 -3007
- package/dist/terminal-progress-source-CsBinCJ_.mjs +965 -0
- package/package.json +125 -116
- package/dist/host-bootstrap-DAgKknbY.mjs +0 -119
- package/dist/performance-host-CcDJjjVA.mjs +0 -266
- package/dist/rolldown-runtime-8H4AJuhK.mjs +0 -14
- package/dist/terminal-progress-source-xor3vakJ.mjs +0 -2256
|
@@ -0,0 +1,965 @@
|
|
|
1
|
+
import { r as parsePiTuiTerminalProgressFrame } from "./pi-tui-terminal-progress-contract-XTQKj-WW.mjs";
|
|
2
|
+
//#region src/runtime/session-reader-port.ts
|
|
3
|
+
/** The official context-pressure occupancy numerator shared by both
|
|
4
|
+
* backends: `projectedTokens ?? pressureTokens` over the raw projection
|
|
5
|
+
* value (an absent/foreign-shaped field is not coerced; a projection with
|
|
6
|
+
* neither field reads unmeasured). */
|
|
7
|
+
function contextPressureOccupancy(value) {
|
|
8
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
9
|
+
const pressure = value;
|
|
10
|
+
if (typeof pressure.projectedTokens === "number") return pressure.projectedTokens;
|
|
11
|
+
if (typeof pressure.pressureTokens === "number") return pressure.pressureTokens;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/runtime/read-error.ts
|
|
15
|
+
/**
|
|
16
|
+
* A typed semantic READ failure: the read was superseded by a connection or
|
|
17
|
+
* surface change, so its result must not be presented as the current Host
|
|
18
|
+
* state. Remote adapters throw this instead of a generic Error so a consumer
|
|
19
|
+
* can stay UI-silent (v2 §0.2.3/§0.3.1) rather than surfacing a stale failure.
|
|
20
|
+
* Host-free; no I/O.
|
|
21
|
+
* @module @xmoon76/dsh-pi-tui/read-error
|
|
22
|
+
*/
|
|
23
|
+
/** The read no longer owns the surface (generation change or superseded epoch). */
|
|
24
|
+
var SupersededReadError = class extends Error {
|
|
25
|
+
reason;
|
|
26
|
+
constructor(reason) {
|
|
27
|
+
super(reason);
|
|
28
|
+
this.name = "SupersededReadError";
|
|
29
|
+
this.reason = reason;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/domain/catalog/provider.ts
|
|
34
|
+
/**
|
|
35
|
+
* Read a value at a dotted path inside a plain object (the web schema-form
|
|
36
|
+
* `getPath` semantics, structural here so /login needs no schema package).
|
|
37
|
+
* @param value - the object to walk.
|
|
38
|
+
* @param path - path segments; the empty path returns `value` itself.
|
|
39
|
+
* @returns the value at the path, or undefined when any segment is missing.
|
|
40
|
+
*/
|
|
41
|
+
function getPath(value, path) {
|
|
42
|
+
let current = value;
|
|
43
|
+
for (const key of path) {
|
|
44
|
+
if (Array.isArray(current)) {
|
|
45
|
+
current = current[Number(key)];
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (typeof current !== "object" || current === null) return void 0;
|
|
49
|
+
current = current[key];
|
|
50
|
+
}
|
|
51
|
+
return current;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Derive the conventional credential reference for a provider route: the web
|
|
55
|
+
* Models page never asks for an environment-variable name, so a typed key
|
|
56
|
+
* stores under this derived reference and the profile records it as
|
|
57
|
+
* `apiKeyEnv`. Kept byte-identical to the web's `deriveKeyRef`.
|
|
58
|
+
* @param provider - provider route id (e.g. `anthropic`, `minimax-cn`).
|
|
59
|
+
* @returns the derived reference name (e.g. `MINIMAX_CN_API_KEY`).
|
|
60
|
+
*/
|
|
61
|
+
function deriveKeyRef(provider) {
|
|
62
|
+
return `${provider.toUpperCase().replace(/[^A-Z0-9]+/g, "_")}_API_KEY`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A route id usable as a settings key AND as the stem of a credential name.
|
|
66
|
+
* The web create card's pattern: the leading letter is the second half of
|
|
67
|
+
* that — `deriveKeyRef` uppercases the id and replaces every non-alphanumeric
|
|
68
|
+
* run with `_`, and a credential reference is a POSIX shell identifier, which
|
|
69
|
+
* cannot start with a digit. A digit-leading id passes every check this card
|
|
70
|
+
* makes and then fails at the credential seam with a raw regular expression
|
|
71
|
+
* the user cannot act on.
|
|
72
|
+
*/
|
|
73
|
+
const ROUTE_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
74
|
+
/** The wire protocols a hand-declared route may name. Mirrors the pi-ai
|
|
75
|
+
* adapter's `supportedProtocols()`; keep in step with
|
|
76
|
+
* `@deepseek-ai/dsh-llm-pi-ai`'s `PROTOCOLS` table (the drift gate is the
|
|
77
|
+
* adapter's own — a protocol it stops serving must be removed here too). */
|
|
78
|
+
const PROTOCOL_CHOICES = [
|
|
79
|
+
"openai-completions",
|
|
80
|
+
"openai-responses",
|
|
81
|
+
"anthropic-messages"
|
|
82
|
+
];
|
|
83
|
+
/**
|
|
84
|
+
* Project one profile value onto the merge's per-route facts: whether a
|
|
85
|
+
* profile EXISTS for the route, and the explicit `apiKeyEnv` it names.
|
|
86
|
+
* A primitive or an absent value is still a configuration fact: an absent
|
|
87
|
+
* profile is the only "not present" case.
|
|
88
|
+
*/
|
|
89
|
+
function providerProfileProjectionOf(profile) {
|
|
90
|
+
if (profile === void 0) return { present: false };
|
|
91
|
+
if (typeof profile !== "object" || profile === null) return { present: true };
|
|
92
|
+
const namedRef = profile.apiKeyEnv;
|
|
93
|
+
return {
|
|
94
|
+
present: true,
|
|
95
|
+
...typeof namedRef === "string" ? { namedRef } : {}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Merge the configurable-provider directory with the existing settings
|
|
100
|
+
* section into the /login option list.
|
|
101
|
+
*
|
|
102
|
+
* The PROVIDER identity is the ROUTE: two routes that name the same
|
|
103
|
+
* credential reference are two providers, and both stay visible (the
|
|
104
|
+
* credential READ is deduplicated by reference later, in the read planner —
|
|
105
|
+
* not here, where the route is the identity). The deepseek official builtin
|
|
106
|
+
* leads and keeps its own route.
|
|
107
|
+
*
|
|
108
|
+
* @param entries - the llm directory entries (or undefined when the llm
|
|
109
|
+
* service is absent — degrades to the official target only).
|
|
110
|
+
* @param readProfile - project ONE route's profile facts from the adapter's
|
|
111
|
+
* single settings snapshot; undefined when the route's profile could not
|
|
112
|
+
* be read at all.
|
|
113
|
+
* @returns the merged options, deepseek official first, one entry per route.
|
|
114
|
+
*/
|
|
115
|
+
function providerOptionsFor(entries, readProfile) {
|
|
116
|
+
const options = [];
|
|
117
|
+
const seenRoutes = /* @__PURE__ */ new Set();
|
|
118
|
+
const push = (option) => {
|
|
119
|
+
if (seenRoutes.has(option.route)) return;
|
|
120
|
+
seenRoutes.add(option.route);
|
|
121
|
+
options.push(option);
|
|
122
|
+
};
|
|
123
|
+
push({
|
|
124
|
+
label: "deepseek official",
|
|
125
|
+
ref: "DEEPSEEK_API_KEY",
|
|
126
|
+
route: "deepseek-official",
|
|
127
|
+
configured: true,
|
|
128
|
+
declared: false,
|
|
129
|
+
namesCredential: true,
|
|
130
|
+
group: "configured",
|
|
131
|
+
settingsNs: "",
|
|
132
|
+
settingsPath: []
|
|
133
|
+
});
|
|
134
|
+
if (entries === void 0) return options;
|
|
135
|
+
for (const entry of entries) {
|
|
136
|
+
if (entry.provider.length === 0 || entry.settingsNs.length === 0) continue;
|
|
137
|
+
const profile = readProfile(entry);
|
|
138
|
+
const configured = profile?.present === true;
|
|
139
|
+
const namedRef = profile?.namedRef;
|
|
140
|
+
const namesCredential = namedRef !== void 0 && namedRef !== "";
|
|
141
|
+
const ref = namesCredential ? namedRef : deriveKeyRef(entry.provider);
|
|
142
|
+
push({
|
|
143
|
+
label: entry.displayName,
|
|
144
|
+
ref,
|
|
145
|
+
route: entry.provider,
|
|
146
|
+
configured,
|
|
147
|
+
declared: entry.declared === true,
|
|
148
|
+
namesCredential,
|
|
149
|
+
group: configured ? "configured" : entry.declared === true ? "custom" : "available",
|
|
150
|
+
settingsNs: entry.settingsNs,
|
|
151
|
+
settingsPath: [...entry.settingsPath]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return options;
|
|
155
|
+
}
|
|
156
|
+
/** Resolve a /login or /logout argument with the SAME rules the command has
|
|
157
|
+
* always used: a route name (or a label's first word) wins, then a literal
|
|
158
|
+
* env-var-looking name (uppercased like the old behavior); anything else is
|
|
159
|
+
* unknown. */
|
|
160
|
+
function classifyCredentialArg(arg, options) {
|
|
161
|
+
const trimmed = arg.trim();
|
|
162
|
+
if (trimmed === "") return void 0;
|
|
163
|
+
const needle = trimmed.toLowerCase();
|
|
164
|
+
const route = options.find((option) => option.route !== void 0 && option.route.toLowerCase() === needle) ?? options.find((option) => option.label.toLowerCase() === needle || option.label.split(" ")[0].toLowerCase() === needle);
|
|
165
|
+
if (route !== void 0) return {
|
|
166
|
+
kind: "route",
|
|
167
|
+
option: route
|
|
168
|
+
};
|
|
169
|
+
const exactRef = options.find((option) => option.ref.toLowerCase() === needle);
|
|
170
|
+
if (exactRef !== void 0) return {
|
|
171
|
+
kind: "ref",
|
|
172
|
+
ref: exactRef.ref
|
|
173
|
+
};
|
|
174
|
+
if (/^[a-zA-Z][a-zA-Z0-9_]*$/.test(trimmed)) return {
|
|
175
|
+
kind: "ref",
|
|
176
|
+
ref: trimmed.toUpperCase()
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/runtime/session-lifecycle-port.ts
|
|
181
|
+
/** A lifecycle outcome that must ABORT the caller's transition, carrying the
|
|
182
|
+
* two independent axes so a Remote caller never has to parse a string. */
|
|
183
|
+
var LifecycleError = class extends Error {
|
|
184
|
+
settlement;
|
|
185
|
+
ownership;
|
|
186
|
+
publishedSessionId;
|
|
187
|
+
/** CORRELATION ONLY for an indeterminate create — never publication proof. */
|
|
188
|
+
requestedSessionId;
|
|
189
|
+
constructor(settlement, ownership, message, publishedSessionId, requestedSessionId) {
|
|
190
|
+
super(message);
|
|
191
|
+
this.name = "LifecycleError";
|
|
192
|
+
this.settlement = settlement;
|
|
193
|
+
this.ownership = ownership;
|
|
194
|
+
this.publishedSessionId = publishedSessionId;
|
|
195
|
+
this.requestedSessionId = requestedSessionId;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
/** Unwrap a CREATE result for the runner's transition: a `created` result that
|
|
199
|
+
* still owns the surface yields the handle; everything else aborts with a
|
|
200
|
+
* machine-readable `LifecycleError` (a superseded create is NOT committed to
|
|
201
|
+
* the local surface, though its identity stays available). */
|
|
202
|
+
function requireCreated(result) {
|
|
203
|
+
const { ownership, outcome } = result;
|
|
204
|
+
switch (outcome.kind) {
|
|
205
|
+
case "created":
|
|
206
|
+
if (ownership === "superseded") throw new LifecycleError("superseded", ownership, `Session "${outcome.handle.session.id}" was created, but the local surface was superseded — do not retry creation`, outcome.handle.session.id);
|
|
207
|
+
return outcome.handle;
|
|
208
|
+
case "published-with-error": throw new LifecycleError(outcome.kind, ownership, `Session "${outcome.sessionId}" was published, but workspace attach/reconcile failed: ${outcome.error.message} (${outcome.error.code}) — do not retry creation`, outcome.sessionId);
|
|
209
|
+
case "indeterminate": throw new LifecycleError(outcome.kind, ownership, `the create is indeterminate — do not retry: ${outcome.error.message} (${outcome.error.code})`, void 0, outcome.requestedSessionId);
|
|
210
|
+
case "rejected": throw new LifecycleError(outcome.kind, ownership, `${outcome.error.message} (${outcome.error.code})`, void 0);
|
|
211
|
+
case "cancelled": throw new LifecycleError("cancelled", ownership, "the Session creation was cancelled before dispatch", void 0);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** Unwrap an OPEN result for the runner's transition. */
|
|
215
|
+
function requireOpened(result) {
|
|
216
|
+
const { ownership, outcome } = result;
|
|
217
|
+
switch (outcome.kind) {
|
|
218
|
+
case "opened":
|
|
219
|
+
if (ownership === "superseded") throw new LifecycleError("superseded", ownership, "the Session was opened but the local surface was superseded", outcome.handle.session.id);
|
|
220
|
+
return outcome.handle;
|
|
221
|
+
case "unavailable": throw new LifecycleError("unavailable", ownership, outcome.message, void 0);
|
|
222
|
+
case "cancelled": throw new LifecycleError("cancelled", ownership, "the Session open was cancelled before selection", void 0);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/** Extract the Direct ownership handle (the real AgentHandle with
|
|
226
|
+
* `dispose()`) from a lifecycle result. Accepts both the converged
|
|
227
|
+
* SessionHandle and a legacy AgentHandle so transition code cannot lose the
|
|
228
|
+
* ownership capability. Remote handles lack `direct` and yield undefined. */
|
|
229
|
+
function ownerHandleOf(next) {
|
|
230
|
+
const handle = next;
|
|
231
|
+
if (handle.direct?.ownerHandle !== void 0) return handle.direct.ownerHandle;
|
|
232
|
+
if (typeof handle.dispose === "function") return handle;
|
|
233
|
+
}
|
|
234
|
+
/** Extract the live in-process agent from a lifecycle result (the Direct
|
|
235
|
+
* SessionHandle via `direct.agent`, or a legacy AgentHandle's `agent`).
|
|
236
|
+
* Remote handles yield undefined. */
|
|
237
|
+
function directAgentOf(next) {
|
|
238
|
+
const handle = next;
|
|
239
|
+
return handle.direct?.agent ?? handle.agent;
|
|
240
|
+
}
|
|
241
|
+
/** Extract the Remote Client generation owner from a lifecycle result. A
|
|
242
|
+
* Direct handle yields undefined. A composing Remote caller must release it
|
|
243
|
+
* exactly once on retirement — including when a superseded transition discards
|
|
244
|
+
* the handle. The Remote session-owner provider (`app/remote/session-owners.ts`)
|
|
245
|
+
* consumes it as the sole ownership mapping source; the Direct runner never
|
|
246
|
+
* interprets it. */
|
|
247
|
+
function clientOwnerOf(next) {
|
|
248
|
+
return next.client;
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/runtime/deliverables-port.ts
|
|
252
|
+
/** One DEFINITE read refusal the preview renders as a state (never a guess). */
|
|
253
|
+
var DeliveredFileReadError = class extends Error {
|
|
254
|
+
code;
|
|
255
|
+
constructor(code, message, options) {
|
|
256
|
+
super(message, options);
|
|
257
|
+
this.name = "DeliveredFileReadError";
|
|
258
|
+
this.code = code;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* The official refusal code → the preview's semantic code.
|
|
263
|
+
*
|
|
264
|
+
* `gateway/lookup-not-found` is the generated Remote's ASSEMBLY refusal when its
|
|
265
|
+
* Session-derived `workspaceFileScope` lookup cannot resolve the identity (a
|
|
266
|
+
* closed/unknown Session): the preview's `session-unavailable`, never a
|
|
267
|
+
* fabricated "Host says the file is missing".
|
|
268
|
+
*/
|
|
269
|
+
const OFFICIAL_CODE_MAP = {
|
|
270
|
+
"workspace-file/not-found": "not-found",
|
|
271
|
+
"workspace-file/not-text": "not-text",
|
|
272
|
+
"workspace-file/not-regular-file": "not-regular-file",
|
|
273
|
+
"workspace-file/too-large": "too-large",
|
|
274
|
+
"gateway/lookup-not-found": "session-unavailable"
|
|
275
|
+
};
|
|
276
|
+
/** Whether one value is a module/instance code carrier. */
|
|
277
|
+
function codeOf(error) {
|
|
278
|
+
if (typeof error !== "object" || error === null) return void 0;
|
|
279
|
+
const code = error.code;
|
|
280
|
+
return typeof code === "string" ? code : void 0;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Map ONE official failure onto the port's vocabulary.
|
|
284
|
+
*
|
|
285
|
+
* A recognized `workspace-file/*` refusal becomes a definite
|
|
286
|
+
* {@link DeliveredFileReadError}; ANYTHING else is returned as-is so the caller
|
|
287
|
+
* keeps its own honesty (the UI reports an unknown failure and its diagnostics
|
|
288
|
+
* channel records the cause) instead of receiving a fabricated state.
|
|
289
|
+
* @param error - the thrown/rejected Host value.
|
|
290
|
+
* @returns the mapped refusal, or the original error when unrecognized.
|
|
291
|
+
*/
|
|
292
|
+
function deliveredFileReadErrorFrom(error) {
|
|
293
|
+
const code = codeOf(error);
|
|
294
|
+
if (code === void 0) return error;
|
|
295
|
+
const mapped = OFFICIAL_CODE_MAP[code];
|
|
296
|
+
if (mapped === void 0) return error;
|
|
297
|
+
return new DeliveredFileReadError(mapped, error instanceof Error ? error.message : `${code}`, { cause: error });
|
|
298
|
+
}
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/runtime/capability.ts
|
|
301
|
+
/** The capabilities the experimental Remote backend serves: exactly the
|
|
302
|
+
* ports its M3-3B assembly provides. A capability is added HERE only when its
|
|
303
|
+
* Remote port genuinely serves the semantic contract (no misleading empty
|
|
304
|
+
* defaults), so the set is deliberately explicit rather than derived. */
|
|
305
|
+
const REMOTE_IMPLEMENTED_CAPABILITIES = [
|
|
306
|
+
"session-read",
|
|
307
|
+
"session-write",
|
|
308
|
+
"session-lifecycle",
|
|
309
|
+
"subagent",
|
|
310
|
+
"interaction",
|
|
311
|
+
"catalog",
|
|
312
|
+
"config",
|
|
313
|
+
"host-file",
|
|
314
|
+
"session-archive",
|
|
315
|
+
"host-command",
|
|
316
|
+
"plugin-manager",
|
|
317
|
+
"job-observation"
|
|
318
|
+
];
|
|
319
|
+
/** The capabilities the Direct backend ACTUALLY serves today: one port per
|
|
320
|
+
* entry, nothing more — never advertise what is not served. */
|
|
321
|
+
const DIRECT_IMPLEMENTED_CAPABILITIES = [
|
|
322
|
+
"session-read",
|
|
323
|
+
"session-write",
|
|
324
|
+
"session-lifecycle",
|
|
325
|
+
"subagent",
|
|
326
|
+
"interaction",
|
|
327
|
+
"catalog",
|
|
328
|
+
"config",
|
|
329
|
+
"host-file",
|
|
330
|
+
"session-archive",
|
|
331
|
+
"host-command",
|
|
332
|
+
"plugin-manager",
|
|
333
|
+
"job-observation"
|
|
334
|
+
];
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/runtime/write-outcome.ts
|
|
337
|
+
/**
|
|
338
|
+
* Pinned Gateway infrastructure codes raised strictly BEFORE the addressed
|
|
339
|
+
* business method is invoked (descriptor/argument/receiver/endpoint resolution
|
|
340
|
+
* and context/lookup provider resolution — all inside `prepareInvocation` and
|
|
341
|
+
* boundary decoding): such a failure proves the operation did not commit. The
|
|
342
|
+
* only Gateway code raised AFTER invocation is `gateway/result-invalid`, so it
|
|
343
|
+
* is deliberately absent.
|
|
344
|
+
*/
|
|
345
|
+
const GATEWAY_PRE_INVOCATION_CODES = /* @__PURE__ */ new Set([
|
|
346
|
+
"gateway/ambiguous-endpoint",
|
|
347
|
+
"gateway/arguments-invalid",
|
|
348
|
+
"gateway/binding-invalid",
|
|
349
|
+
"gateway/context-failed",
|
|
350
|
+
"gateway/context-not-found",
|
|
351
|
+
"gateway/context-unavailable",
|
|
352
|
+
"gateway/definition-unavailable",
|
|
353
|
+
"gateway/input-invalid",
|
|
354
|
+
"gateway/invocation-unavailable",
|
|
355
|
+
"gateway/lookup-failed",
|
|
356
|
+
"gateway/lookup-not-found",
|
|
357
|
+
"gateway/lookup-unavailable",
|
|
358
|
+
"gateway/method-unavailable",
|
|
359
|
+
"gateway/provider-mismatch",
|
|
360
|
+
"gateway/service-unavailable",
|
|
361
|
+
"gateway/signature-invalid"
|
|
362
|
+
]);
|
|
363
|
+
/**
|
|
364
|
+
* Whether a failure code PROVES the addressed operation was refused: domain
|
|
365
|
+
* codes, `gateway/bad-request`, and the pinned pre-invocation Gateway
|
|
366
|
+
* infrastructure codes qualify. `gateway/cancelled`, `gateway/internal`,
|
|
367
|
+
* `gateway/result-invalid`, an unknown `gateway/*` code, or a code-less failure
|
|
368
|
+
* do NOT (the commit state stays unproven).
|
|
369
|
+
*
|
|
370
|
+
* SCOPE: this predicate expresses ONLY the D2.2-verified write vocabulary plus
|
|
371
|
+
* the pinned Gateway pre-invocation codes. It is NOT a general
|
|
372
|
+
* idempotency/commit judgement: a domain code does not universally prove that
|
|
373
|
+
* no mutation happened (e.g. `session/workspace-attach-failed` can follow a
|
|
374
|
+
* successful Session create/fork). Later operation families (D2.3/D2.4) must
|
|
375
|
+
* use their own operation-specific settlement table rather than extending this
|
|
376
|
+
* helper.
|
|
377
|
+
*/
|
|
378
|
+
function isRemoteBusinessRefusalCode(code) {
|
|
379
|
+
if (code === void 0) return false;
|
|
380
|
+
if (code === "gateway/bad-request") return true;
|
|
381
|
+
if (code.startsWith("gateway/")) return GATEWAY_PRE_INVOCATION_CODES.has(code);
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/runtime/subagent-outcome.ts
|
|
386
|
+
/**
|
|
387
|
+
* Backend-neutral outcome/error classification for one subagent viewer prompt
|
|
388
|
+
* (TS8-F4): the stable refusal taxonomy shared by the Direct and Remote
|
|
389
|
+
* adapters. Pure and never throwing — it reads structural `code` values only,
|
|
390
|
+
* so the subagent package stays resolvable from the dsh installation and is
|
|
391
|
+
* never imported here.
|
|
392
|
+
* @module @xmoon76/dsh-pi-tui/runtime/subagent-outcome
|
|
393
|
+
*/
|
|
394
|
+
/**
|
|
395
|
+
* Settle a failed viewer prompt. A caller cancellation and every PROVEN refusal
|
|
396
|
+
* code are rejected (a domain `subagent/*` admission refusal, `gateway/bad-request`,
|
|
397
|
+
* or a pre-invocation Gateway infrastructure code); only a carrier/internal/
|
|
398
|
+
* post-invocation failure (`gateway/internal`, `gateway/result-invalid`, an
|
|
399
|
+
* unknown `gateway/*` code) or a code-less throw settles `indeterminate`.
|
|
400
|
+
*/
|
|
401
|
+
function classifySubagentPromptSettlement(error) {
|
|
402
|
+
const reason = classifySubagentPromptError(error);
|
|
403
|
+
if (reason.kind !== "error") return {
|
|
404
|
+
kind: "rejected",
|
|
405
|
+
reason
|
|
406
|
+
};
|
|
407
|
+
if (isRemoteBusinessRefusalCode(remoteErrorCode(error))) return {
|
|
408
|
+
kind: "rejected",
|
|
409
|
+
reason
|
|
410
|
+
};
|
|
411
|
+
return {
|
|
412
|
+
kind: "indeterminate",
|
|
413
|
+
message: reason.message
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Classify an official prompt failure into the stable reason set. The Direct
|
|
418
|
+
* adapter reads the official RemoteError vocabulary structurally (the `code`
|
|
419
|
+
* string; the subagent package stays resolvable from the dsh installation,
|
|
420
|
+
* never an import here).
|
|
421
|
+
*/
|
|
422
|
+
function classifySubagentPromptError(error) {
|
|
423
|
+
if (isAbortError(error)) return { kind: "cancelled" };
|
|
424
|
+
const code = remoteErrorCode(error);
|
|
425
|
+
if (code === "gateway/cancelled") return { kind: "cancelled" };
|
|
426
|
+
if (code === "subagent/parent-unavailable") return { kind: "parent-unavailable" };
|
|
427
|
+
if (code === "subagent/not-resumable" || code === "subagent/not-found" || code === "subagent/catalog-diagnostic") return { kind: "stale-child" };
|
|
428
|
+
if (code === "subagent/unauthorized") return { kind: "unauthorized" };
|
|
429
|
+
if (code === "subagent/delivery-unavailable" || code === "subagent/projections-unavailable") return { kind: "unavailable" };
|
|
430
|
+
return {
|
|
431
|
+
kind: "error",
|
|
432
|
+
message: safeSubagentErrorMessage(error)
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
/** The stable failure code of a structural official failure, if any. */
|
|
436
|
+
function remoteErrorCode(error) {
|
|
437
|
+
if (typeof error !== "object" || error === null) return void 0;
|
|
438
|
+
const code = error.code;
|
|
439
|
+
return typeof code === "string" && code !== "" ? code : void 0;
|
|
440
|
+
}
|
|
441
|
+
function isAbortError(error) {
|
|
442
|
+
return typeof error === "object" && error !== null && error.name === "AbortError";
|
|
443
|
+
}
|
|
444
|
+
/** One-line safe error text (never throws on hostile values). Shared with the
|
|
445
|
+
* Direct adapter's pre-dispatch catch so both settle the same wording. */
|
|
446
|
+
function safeSubagentErrorMessage(error) {
|
|
447
|
+
if (error === void 0 || error === null) return "unknown error";
|
|
448
|
+
if (typeof error === "string") return error;
|
|
449
|
+
if (error instanceof Error) {
|
|
450
|
+
const message = error.message;
|
|
451
|
+
return message === "" ? error.name : message;
|
|
452
|
+
}
|
|
453
|
+
if (typeof error === "object") {
|
|
454
|
+
const message = error.message;
|
|
455
|
+
if (typeof message === "string" && message !== "") return message;
|
|
456
|
+
}
|
|
457
|
+
try {
|
|
458
|
+
return String(error);
|
|
459
|
+
} catch {
|
|
460
|
+
return "unknown error";
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
//#endregion
|
|
464
|
+
//#region src/runtime/presentation-read-port.ts
|
|
465
|
+
/** Detach the official `turnOutline` wire view into the picker DTO — only
|
|
466
|
+
* well-formed entries cross (shared by the Direct projection read and the
|
|
467
|
+
* Remote binding projection read); a foreign-shaped value reads unknown. */
|
|
468
|
+
function detachedTurnOutline(value) {
|
|
469
|
+
if (!Array.isArray(value)) return void 0;
|
|
470
|
+
const entries = [];
|
|
471
|
+
for (const entry of value) {
|
|
472
|
+
if (typeof entry !== "object" || entry === null) return void 0;
|
|
473
|
+
const record = entry;
|
|
474
|
+
if (typeof record.turn !== "number" || typeof record.seq !== "number") return void 0;
|
|
475
|
+
if (typeof record.prompt !== "string" || typeof record.response !== "string") return void 0;
|
|
476
|
+
entries.push({
|
|
477
|
+
turn: record.turn,
|
|
478
|
+
seq: record.seq,
|
|
479
|
+
prompt: record.prompt,
|
|
480
|
+
response: record.response
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
return Object.freeze(entries);
|
|
484
|
+
}
|
|
485
|
+
//#endregion
|
|
486
|
+
//#region src/runtime/session-status-projection.ts
|
|
487
|
+
/**
|
|
488
|
+
* Detach the official projection values into the status DTO. Fields are
|
|
489
|
+
* only present when their official projection value is well-formed; nothing
|
|
490
|
+
* is coerced, defaulted or copied from another subject.
|
|
491
|
+
*/
|
|
492
|
+
function detachedSessionStatus(sessionId, values, cwd) {
|
|
493
|
+
const record = { sessionId };
|
|
494
|
+
if (typeof cwd === "string" && cwd !== "") record.cwd = cwd;
|
|
495
|
+
const model = modelSelectionFact(values.modelSelection);
|
|
496
|
+
if (model !== void 0) record.model = model;
|
|
497
|
+
if (typeof values.agentPreset === "string" && values.agentPreset !== "") record.preset = values.agentPreset;
|
|
498
|
+
if (typeof values.title === "string" && values.title !== "") record.title = values.title;
|
|
499
|
+
const permissionValue = values.permissions;
|
|
500
|
+
if (typeof permissionValue === "object" && permissionValue !== null) {
|
|
501
|
+
const current = permissionValue.currentValue;
|
|
502
|
+
if (typeof current === "string" && current !== "") record.permission = current;
|
|
503
|
+
}
|
|
504
|
+
if ("goal" in values) {
|
|
505
|
+
const goal = goalFact(values.goal);
|
|
506
|
+
if (goal !== void 0) record.goal = goal;
|
|
507
|
+
}
|
|
508
|
+
const pressure = numericRecord(values.contextPressure);
|
|
509
|
+
const breakdownValue = values.contextBreakdown;
|
|
510
|
+
const breakdown = typeof breakdownValue === "object" && breakdownValue !== null ? numericRecord(breakdownValue) : void 0;
|
|
511
|
+
const hasBreakdown = breakdown !== void 0 && typeof breakdown.systemTokens === "number" && typeof breakdown.toolsTokens === "number" && typeof breakdown.messageTokens === "number";
|
|
512
|
+
if (pressure !== void 0 && Object.keys(pressure).length > 0 || hasBreakdown) record.context = {
|
|
513
|
+
...pressure ?? {},
|
|
514
|
+
...hasBreakdown ? { breakdown: {
|
|
515
|
+
systemTokens: breakdown.systemTokens,
|
|
516
|
+
toolsTokens: breakdown.toolsTokens,
|
|
517
|
+
messageTokens: breakdown.messageTokens
|
|
518
|
+
} } : {}
|
|
519
|
+
};
|
|
520
|
+
const todos = detachedTodos(values.todos);
|
|
521
|
+
if (todos !== void 0) record.todos = todos;
|
|
522
|
+
const usageValue = numericRecord(values.tokenUsage);
|
|
523
|
+
if (usageValue !== void 0 && typeof usageValue.uncachedInputTokens === "number" && typeof usageValue.outputTokens === "number" && typeof usageValue.cacheReadTokens === "number" && typeof usageValue.cacheWriteTokens === "number") record.usage = {
|
|
524
|
+
uncachedInputTokens: usageValue.uncachedInputTokens,
|
|
525
|
+
outputTokens: usageValue.outputTokens,
|
|
526
|
+
cacheReadTokens: usageValue.cacheReadTokens,
|
|
527
|
+
cacheWriteTokens: usageValue.cacheWriteTokens
|
|
528
|
+
};
|
|
529
|
+
const performance = performanceProjection(values.piTuiPerformance);
|
|
530
|
+
if (performance !== void 0) record.performance = performance;
|
|
531
|
+
return record;
|
|
532
|
+
}
|
|
533
|
+
/** A finite non-negative projection number, or `undefined` (never coerced,
|
|
534
|
+
* never defaulted). */
|
|
535
|
+
function finiteNumber(value) {
|
|
536
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
537
|
+
}
|
|
538
|
+
/** Whether every entry of a candidate tuple is present (the shape gate). */
|
|
539
|
+
function allDefined(values) {
|
|
540
|
+
return values.every((entry) => entry !== void 0);
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Detach the bundle's own `piTuiPerformance` wire value: BOTH scopes with all
|
|
544
|
+
* of their finite non-negative counters, or `undefined` — a malformed,
|
|
545
|
+
* foreign or partial value reads absent (the capability cannot answer), never
|
|
546
|
+
* a partially copied or coerced projection.
|
|
547
|
+
*/
|
|
548
|
+
function performanceProjection(value) {
|
|
549
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
550
|
+
const source = value;
|
|
551
|
+
const recent = typeof source.recent === "object" && source.recent !== null ? source.recent : void 0;
|
|
552
|
+
const all = typeof source.all === "object" && source.all !== null ? source.all : void 0;
|
|
553
|
+
if (recent === void 0 || all === void 0) return void 0;
|
|
554
|
+
const fields = [
|
|
555
|
+
finiteNumber(recent.outputTokens),
|
|
556
|
+
finiteNumber(recent.modelMs),
|
|
557
|
+
finiteNumber(recent.samples),
|
|
558
|
+
finiteNumber(recent.firstTokenMs),
|
|
559
|
+
finiteNumber(recent.firstTokenSamples),
|
|
560
|
+
finiteNumber(all.outputTokens),
|
|
561
|
+
finiteNumber(all.modelMs),
|
|
562
|
+
finiteNumber(all.samples)
|
|
563
|
+
];
|
|
564
|
+
if (!allDefined(fields)) return void 0;
|
|
565
|
+
const [recentOutputTokens, recentModelMs, recentSamples, firstTokenMs, firstTokenSamples, allOutputTokens, allModelMs, allSamples] = fields;
|
|
566
|
+
return {
|
|
567
|
+
recent: {
|
|
568
|
+
outputTokens: recentOutputTokens,
|
|
569
|
+
modelMs: recentModelMs,
|
|
570
|
+
samples: recentSamples,
|
|
571
|
+
firstTokenMs,
|
|
572
|
+
firstTokenSamples
|
|
573
|
+
},
|
|
574
|
+
all: {
|
|
575
|
+
outputTokens: allOutputTokens,
|
|
576
|
+
modelMs: allModelMs,
|
|
577
|
+
samples: allSamples
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
/** Narrow the official `goal` projection view: `null` (no goal) is a LEGAL
|
|
582
|
+
* value and stays distinct from `undefined` (unavailable); the current goal
|
|
583
|
+
* is read from `goal.{objective,phase}` with the phase vocabulary validated. */
|
|
584
|
+
function goalFact(value) {
|
|
585
|
+
if (value === null) return null;
|
|
586
|
+
if (typeof value !== "object") return void 0;
|
|
587
|
+
const current = value.goal;
|
|
588
|
+
if (typeof current !== "object" || current === null) return void 0;
|
|
589
|
+
const goal = current;
|
|
590
|
+
if (typeof goal.objective !== "string" || goal.objective === "") return void 0;
|
|
591
|
+
if (goal.phase !== "active" && goal.phase !== "paused" && goal.phase !== "blocked" && goal.phase !== "complete") return;
|
|
592
|
+
return {
|
|
593
|
+
objective: goal.objective,
|
|
594
|
+
phase: goal.phase
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
/** Narrow an unknown projection value to its numeric fields (no coercion). */
|
|
598
|
+
function numericRecord(value) {
|
|
599
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
600
|
+
const source = value;
|
|
601
|
+
const out = {};
|
|
602
|
+
for (const [key, entry] of Object.entries(source)) if (typeof entry === "number") out[key] = entry;
|
|
603
|
+
return out;
|
|
604
|
+
}
|
|
605
|
+
/** The effective selection off the official `modelSelection` fold:
|
|
606
|
+
* `next ?? lastUsed`, validated to the normalized shape. */
|
|
607
|
+
function modelSelectionFact(value) {
|
|
608
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
609
|
+
const fold = value;
|
|
610
|
+
for (const candidate of [fold.next, fold.lastUsed]) {
|
|
611
|
+
if (typeof candidate !== "object" || candidate === null) continue;
|
|
612
|
+
const selection = candidate;
|
|
613
|
+
if (typeof selection.provider !== "string" || selection.provider === "") continue;
|
|
614
|
+
if (typeof selection.model !== "string" || selection.model === "") continue;
|
|
615
|
+
return {
|
|
616
|
+
provider: selection.provider,
|
|
617
|
+
model: selection.model,
|
|
618
|
+
...typeof selection.reasoningEffort === "string" && selection.reasoningEffort !== "" ? { reasoningEffort: selection.reasoningEffort } : {}
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
/** Detach the official `todos` whole-list snapshot. The projection's
|
|
623
|
+
* LEGAL `null` (no `todo/write` yet) stays `null`; only `undefined` (the
|
|
624
|
+
* projection value was absent — capability unavailable) reads absent. */
|
|
625
|
+
function detachedTodos(value) {
|
|
626
|
+
if (value === null) return null;
|
|
627
|
+
if (value === void 0) return void 0;
|
|
628
|
+
if (!Array.isArray(value)) return void 0;
|
|
629
|
+
const todos = [];
|
|
630
|
+
for (const item of value) {
|
|
631
|
+
if (typeof item !== "object" || item === null) return void 0;
|
|
632
|
+
const todo = item;
|
|
633
|
+
if (typeof todo.content !== "string") return void 0;
|
|
634
|
+
if (todo.status !== "pending" && todo.status !== "in_progress" && todo.status !== "completed") return void 0;
|
|
635
|
+
todos.push({
|
|
636
|
+
content: todo.content,
|
|
637
|
+
status: todo.status
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
return Object.freeze(todos);
|
|
641
|
+
}
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/runtime/interaction-port.ts
|
|
644
|
+
/** The official Host code for a late answer whose reply is already queued. */
|
|
645
|
+
const QUESTION_REPLY_QUEUED = "REPLY_QUEUED";
|
|
646
|
+
/** The official Host code for a late answer that does not name each question. */
|
|
647
|
+
const QUESTION_BAD_ANSWER = "BAD_ANSWER";
|
|
648
|
+
/**
|
|
649
|
+
* One rejected late answer with the Host's stable code (`REPLY_QUEUED`,
|
|
650
|
+
* `BAD_ANSWER`, `CALLER_NOT_LIVE`, or a transport/gateway code). Both
|
|
651
|
+
* adapters throw THIS shape so a consumer can offer truthful recovery
|
|
652
|
+
* without switching on a backend.
|
|
653
|
+
*/
|
|
654
|
+
var QuestionAnswerError = class extends Error {
|
|
655
|
+
code;
|
|
656
|
+
constructor(code, message, options) {
|
|
657
|
+
super(message, options);
|
|
658
|
+
this.name = "QuestionAnswerError";
|
|
659
|
+
this.code = code;
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
/** Wrap an unknown failure from the late-answer path in the port vocabulary. */
|
|
663
|
+
function questionAnswerError(error) {
|
|
664
|
+
if (error instanceof QuestionAnswerError) return error;
|
|
665
|
+
return new QuestionAnswerError(typeof error === "object" && error !== null && typeof error.code === "string" ? error.code : "question/answer-failed", typeof error === "object" && error !== null && typeof error.message === "string" ? error.message : String(error), { cause: error });
|
|
666
|
+
}
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region src/runtime/plugin-manager-mapping.ts
|
|
669
|
+
/** Generate one install request id (the branded shape is a plain string). */
|
|
670
|
+
function pluginInstallRequestId(value) {
|
|
671
|
+
return value;
|
|
672
|
+
}
|
|
673
|
+
/** Resolve one official localized text to the English fallback. */
|
|
674
|
+
function localizedText(value) {
|
|
675
|
+
if (value === void 0) return void 0;
|
|
676
|
+
return typeof value === "string" ? value : value.en;
|
|
677
|
+
}
|
|
678
|
+
function detachIncompatible(entry) {
|
|
679
|
+
return Object.freeze({
|
|
680
|
+
name: entry.name,
|
|
681
|
+
version: entry.version,
|
|
682
|
+
runtimeVersion: entry.runtimeVersion,
|
|
683
|
+
requirements: Object.freeze({ ...entry.requirements })
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
function detachError(error) {
|
|
687
|
+
if (error === void 0) return void 0;
|
|
688
|
+
return Object.freeze({
|
|
689
|
+
code: error.code,
|
|
690
|
+
...error.diagnostic === void 0 ? {} : { diagnostic: error.diagnostic },
|
|
691
|
+
...error.incompatible === void 0 ? {} : { incompatible: Object.freeze(error.incompatible.map(detachIncompatible)) }
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
function pickMeta(meta) {
|
|
695
|
+
const title = localizedText(meta.title);
|
|
696
|
+
const description = localizedText(meta.description);
|
|
697
|
+
return {
|
|
698
|
+
...title === void 0 ? {} : { title },
|
|
699
|
+
...description === void 0 ? {} : { description }
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
function detachBundle(bundle) {
|
|
703
|
+
const rows = bundle.rows.map((row) => Object.freeze({
|
|
704
|
+
rowId: row.rowId,
|
|
705
|
+
moduleName: row.moduleName,
|
|
706
|
+
...row.meta === void 0 ? {} : pickMeta(row.meta),
|
|
707
|
+
...row.entryId === void 0 ? {} : { entryId: String(row.entryId) }
|
|
708
|
+
}));
|
|
709
|
+
return Object.freeze({
|
|
710
|
+
name: bundle.name,
|
|
711
|
+
official: bundle.official,
|
|
712
|
+
availability: bundle.availability,
|
|
713
|
+
...bundle.installTarget === void 0 ? {} : { installTarget: Object.freeze({
|
|
714
|
+
spec: bundle.installTarget.spec,
|
|
715
|
+
version: bundle.installTarget.version
|
|
716
|
+
}) },
|
|
717
|
+
...bundle.version === void 0 ? {} : { version: bundle.version },
|
|
718
|
+
...bundle.meta === void 0 ? {} : pickMeta(bundle.meta),
|
|
719
|
+
...bundle.description === void 0 ? {} : { description: bundle.description },
|
|
720
|
+
enabled: bundle.enabled,
|
|
721
|
+
installed: bundle.installed,
|
|
722
|
+
optional: bundle.optional,
|
|
723
|
+
...bundle.source === void 0 ? {} : { source: bundle.source },
|
|
724
|
+
removable: bundle.removable,
|
|
725
|
+
...bundle.readOnlyReason === void 0 ? {} : { readOnlyReason: bundle.readOnlyReason },
|
|
726
|
+
...bundle.error === void 0 ? {} : { error: detachError(bundle.error) },
|
|
727
|
+
rows: Object.freeze(rows),
|
|
728
|
+
overrides: Object.freeze([...bundle.overrides])
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
function detachPlugin(entry) {
|
|
732
|
+
const addressable = "patchId" in entry;
|
|
733
|
+
return Object.freeze({
|
|
734
|
+
entryId: String(entry.entryId),
|
|
735
|
+
moduleName: entry.moduleName,
|
|
736
|
+
...entry.meta === void 0 ? {} : pickMeta(entry.meta),
|
|
737
|
+
enabled: entry.enabled,
|
|
738
|
+
fiberPhase: entry.fiberPhase,
|
|
739
|
+
...addressable ? { patchId: entry.patchId } : { readOnlyReason: entry.readOnlyReason }
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
function detachRegistries(registries) {
|
|
743
|
+
return Object.freeze({
|
|
744
|
+
registry: registries.registry,
|
|
745
|
+
fallbackRegistries: Object.freeze([...registries.fallbackRegistries]),
|
|
746
|
+
resolved: registries.resolved
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
function detachExemptions(value) {
|
|
750
|
+
return Object.freeze(Object.entries(value.exemptions).map(([packageVersion, runtimeVersions]) => Object.freeze({
|
|
751
|
+
packageVersion,
|
|
752
|
+
runtimeVersions: Object.freeze([...runtimeVersions])
|
|
753
|
+
})));
|
|
754
|
+
}
|
|
755
|
+
/** Map one complete snapshot read onto the detached surface facts. */
|
|
756
|
+
function detachPluginManagerSnapshot(input) {
|
|
757
|
+
return Object.freeze({
|
|
758
|
+
bundles: Object.freeze(input.bundles.map(detachBundle)),
|
|
759
|
+
plugins: Object.freeze(input.plugins.map(detachPlugin)),
|
|
760
|
+
registries: detachRegistries(input.registries),
|
|
761
|
+
exemptions: detachExemptions(input.exemptions),
|
|
762
|
+
exemptionWarnings: Object.freeze([...input.exemptions.warnings])
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
function detachPackageResult(result) {
|
|
766
|
+
return Object.freeze({
|
|
767
|
+
exitCode: result.exitCode,
|
|
768
|
+
output: result.output,
|
|
769
|
+
truncated: result.truncated,
|
|
770
|
+
...result.kind === void 0 ? {} : { kind: result.kind },
|
|
771
|
+
...result.timedOut === void 0 ? {} : { timedOut: result.timedOut },
|
|
772
|
+
...result.incompatible === void 0 ? {} : { incompatible: Object.freeze(result.incompatible.map(detachIncompatible)) }
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
/** Map one persisted change and its observed application outcome. */
|
|
776
|
+
function detachChange(result) {
|
|
777
|
+
return Object.freeze({
|
|
778
|
+
changed: result.changed,
|
|
779
|
+
application: result.application,
|
|
780
|
+
...result.restartReason === void 0 ? {} : { restartReason: result.restartReason },
|
|
781
|
+
stage: result.stage,
|
|
782
|
+
target: result.target,
|
|
783
|
+
...result.enabled === void 0 ? {} : { enabled: result.enabled },
|
|
784
|
+
...result.error === void 0 ? {} : { error: detachError(result.error) },
|
|
785
|
+
...result.warnings === void 0 ? {} : { warnings: Object.freeze([...result.warnings]) },
|
|
786
|
+
...result.bundle === void 0 ? {} : { bundle: result.bundle },
|
|
787
|
+
...result.version === void 0 ? {} : { version: result.version },
|
|
788
|
+
...result.pendingBuilds === void 0 ? {} : { pendingBuilds: Object.freeze([...result.pendingBuilds]) },
|
|
789
|
+
...result.approvedBuilds === void 0 ? {} : { approvedBuilds: Object.freeze([...result.approvedBuilds]) },
|
|
790
|
+
...result.packageResult === void 0 ? {} : { packageResult: detachPackageResult(result.packageResult) },
|
|
791
|
+
...result.registries === void 0 ? {} : { registries: Object.freeze([...result.registries]) },
|
|
792
|
+
...result.failedAt === void 0 ? {} : { failedAt: result.failedAt }
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
/** Map what a spec names before installation. */
|
|
796
|
+
function detachInspection(inspection) {
|
|
797
|
+
if (inspection.status === "accepted") return Object.freeze({
|
|
798
|
+
status: "accepted",
|
|
799
|
+
kind: inspection.kind,
|
|
800
|
+
...inspection.name === void 0 ? {} : { name: inspection.name },
|
|
801
|
+
...inspection.version === void 0 ? {} : { version: inspection.version },
|
|
802
|
+
...inspection.description === void 0 ? {} : { description: inspection.description },
|
|
803
|
+
bundle: inspection.bundle,
|
|
804
|
+
registry: inspection.registry,
|
|
805
|
+
...inspection.host === void 0 ? {} : { host: inspection.host }
|
|
806
|
+
});
|
|
807
|
+
return Object.freeze({
|
|
808
|
+
status: "refused",
|
|
809
|
+
problem: inspection.problem,
|
|
810
|
+
reason: inspection.reason,
|
|
811
|
+
...inspection.registries === void 0 ? {} : { registries: Object.freeze([...inspection.registries]) }
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
/** Map one official install-phase announcement. */
|
|
815
|
+
function detachPhase(progress) {
|
|
816
|
+
return Object.freeze({
|
|
817
|
+
requestId: String(progress.requestId),
|
|
818
|
+
phase: progress.phase,
|
|
819
|
+
...progress.attempt === void 0 ? {} : { attempt: Object.freeze({
|
|
820
|
+
registry: progress.attempt.registry,
|
|
821
|
+
index: progress.attempt.index,
|
|
822
|
+
total: progress.attempt.total
|
|
823
|
+
}) }
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
/** Map one pnpm output chunk. */
|
|
827
|
+
function detachLog(chunk) {
|
|
828
|
+
return Object.freeze({
|
|
829
|
+
...chunk.requestId === void 0 ? {} : { requestId: String(chunk.requestId) },
|
|
830
|
+
jobId: chunk.jobId,
|
|
831
|
+
stream: chunk.stream,
|
|
832
|
+
text: chunk.text
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
//#endregion
|
|
836
|
+
//#region src/runtime/plugin-manager-port.ts
|
|
837
|
+
/**
|
|
838
|
+
* One plugin mutation's result arrived after the operation's authoritative
|
|
839
|
+
* currentness context was superseded. The write may have been applied, so this
|
|
840
|
+
* is NOT a refusal: the caller must present the outcome as indeterminate and
|
|
841
|
+
* let the authoritative inventory reread decide what is true. A backend
|
|
842
|
+
* adapter raises it only when its own currentness authority proves the reply
|
|
843
|
+
* belongs to a superseded context; this module names no transport.
|
|
844
|
+
*/
|
|
845
|
+
var PluginManagerStaleResultError = class extends Error {
|
|
846
|
+
constructor(operation) {
|
|
847
|
+
super(`pluginManager.${operation} returned after its currentness context was superseded; the authoritative inventory reread decides the outcome`);
|
|
848
|
+
this.name = "PluginManagerStaleResultError";
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
//#endregion
|
|
852
|
+
//#region src/app/remote/terminal-progress-source.ts
|
|
853
|
+
/** Consecutive frame-less watch endings tolerated before failing closed. */
|
|
854
|
+
const EMPTY_WATCH_REOPEN_LIMIT = 3;
|
|
855
|
+
/**
|
|
856
|
+
* Consume the ONE Remote progress watch of one session for as long as the caller
|
|
857
|
+
* stays current, re-establishing it whenever the Host retires it.
|
|
858
|
+
*
|
|
859
|
+
* @param source - the Remote progress source.
|
|
860
|
+
* @param sessionId - the main session this authority belongs to.
|
|
861
|
+
* @param signal - the caller's lifetime; aborting it stops the consumption at
|
|
862
|
+
* the next fact and before any re-open.
|
|
863
|
+
* @param consumer - the currentness fence and the fact sink.
|
|
864
|
+
* @throws when the Host keeps ending the watch without ever delivering a frame.
|
|
865
|
+
*/
|
|
866
|
+
async function consumeRemoteTerminalProgress(source, sessionId, signal, consumer) {
|
|
867
|
+
let emptyReopens = 0;
|
|
868
|
+
for (;;) {
|
|
869
|
+
let frames = 0;
|
|
870
|
+
try {
|
|
871
|
+
for await (const fact of source.open(sessionId, signal)) {
|
|
872
|
+
if (signal.aborted || !consumer.isCurrent()) return;
|
|
873
|
+
frames += 1;
|
|
874
|
+
consumer.onFact(fact);
|
|
875
|
+
}
|
|
876
|
+
} catch (error) {
|
|
877
|
+
if (signal.aborted) return;
|
|
878
|
+
throw error;
|
|
879
|
+
}
|
|
880
|
+
if (signal.aborted || !consumer.isCurrent()) return;
|
|
881
|
+
if (frames === 0) {
|
|
882
|
+
emptyReopens += 1;
|
|
883
|
+
if (emptyReopens > EMPTY_WATCH_REOPEN_LIMIT) throw new Error(`the Remote terminal-progress watch of ${sessionId} ended without a frame ${String(emptyReopens)} times`);
|
|
884
|
+
} else emptyReopens = 0;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* Assemble the source over the ONE Remote Client graph. It constructs no
|
|
889
|
+
* Client and owns no subscription of its own; the provenance of an accepted
|
|
890
|
+
* frame lives only for the watch that observed it (see {@link createRemoteTerminalProgressSource}).
|
|
891
|
+
*/
|
|
892
|
+
function createRemoteTerminalProgressSource(deps) {
|
|
893
|
+
/**
|
|
894
|
+
* Judge one frame against the provenance of THIS watch.
|
|
895
|
+
*
|
|
896
|
+
* @param previous - the last frame accepted by this watch, or `undefined`
|
|
897
|
+
* before its opening baseline. It deliberately never crosses watches: a
|
|
898
|
+
* settled `done`/`error` belongs to the interval ONE watch observed, so a new
|
|
899
|
+
* watch (a reconnect, a re-adopted session, a re-retained binding, another TUI
|
|
900
|
+
* owner) opens on the Host's current `running` truth and `idle` — the plan's
|
|
901
|
+
* "a new binding default to idle" — instead of inheriting a result it cannot
|
|
902
|
+
* prove.
|
|
903
|
+
* @param opened - whether this watch already delivered its opening baseline.
|
|
904
|
+
* @returns the fact to publish, or `undefined` for a frame that must be dropped.
|
|
905
|
+
* @throws when the stream cannot be interpreted at all.
|
|
906
|
+
*/
|
|
907
|
+
const acceptFrame = (frame, sessionId, opened, previous) => {
|
|
908
|
+
if (!opened) {
|
|
909
|
+
if (frame.kind !== "snapshot") throw new Error(`the Remote terminal-progress stream of ${sessionId} did not open with a snapshot`);
|
|
910
|
+
return {
|
|
911
|
+
kind: "snapshot",
|
|
912
|
+
restart: true,
|
|
913
|
+
running: frame.running,
|
|
914
|
+
outcome: "idle"
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
if (previous !== void 0 && frame.revision < previous.revision) throw new Error(`the Remote terminal-progress stream of ${sessionId} moved its revision backwards`);
|
|
918
|
+
if (frame.kind === "snapshot") return {
|
|
919
|
+
kind: "snapshot",
|
|
920
|
+
restart: true,
|
|
921
|
+
running: frame.running,
|
|
922
|
+
outcome: "idle"
|
|
923
|
+
};
|
|
924
|
+
if (previous === void 0) return void 0;
|
|
925
|
+
if (frame.hostEpoch !== previous.hostEpoch) return;
|
|
926
|
+
if (frame.agentEpoch < previous.agentEpoch) return void 0;
|
|
927
|
+
if (frame.revision <= previous.revision) return void 0;
|
|
928
|
+
return {
|
|
929
|
+
kind: "update",
|
|
930
|
+
restart: frame.agentEpoch > previous.agentEpoch,
|
|
931
|
+
running: frame.running,
|
|
932
|
+
outcome: frame.outcome
|
|
933
|
+
};
|
|
934
|
+
};
|
|
935
|
+
return { async *open(sessionId, signal) {
|
|
936
|
+
const capturedGeneration = deps.generation.getSnapshot();
|
|
937
|
+
const capturedBinding = deps.binding(sessionId);
|
|
938
|
+
if (capturedGeneration === void 0 || capturedBinding === void 0) throw new Error(`the Remote terminal-progress watch of ${sessionId} has no retained Session binding`);
|
|
939
|
+
const handle = deps.remote.piTuiTerminalProgress.watch(sessionId, signal);
|
|
940
|
+
try {
|
|
941
|
+
let opened = false;
|
|
942
|
+
/** This watch's own provenance: it dies with the watch. */
|
|
943
|
+
let accepted;
|
|
944
|
+
for await (const item of handle) {
|
|
945
|
+
if (signal.aborted) return;
|
|
946
|
+
if (!Object.is(capturedGeneration, deps.generation.getSnapshot()) || deps.binding(sessionId) !== capturedBinding) throw new Error(`the Remote terminal-progress watch of ${sessionId} lost its transport identity`);
|
|
947
|
+
const frame = parsePiTuiTerminalProgressFrame(item);
|
|
948
|
+
if (frame.sessionId !== sessionId) throw new Error(`the Remote terminal-progress stream of ${sessionId} delivered a frame of ${frame.sessionId}`);
|
|
949
|
+
const fact = acceptFrame(frame, sessionId, opened, accepted);
|
|
950
|
+
if (fact === void 0) continue;
|
|
951
|
+
opened = true;
|
|
952
|
+
accepted = {
|
|
953
|
+
hostEpoch: frame.hostEpoch,
|
|
954
|
+
agentEpoch: frame.agentEpoch,
|
|
955
|
+
revision: frame.revision
|
|
956
|
+
};
|
|
957
|
+
yield fact;
|
|
958
|
+
}
|
|
959
|
+
} finally {
|
|
960
|
+
handle.dispose();
|
|
961
|
+
}
|
|
962
|
+
} };
|
|
963
|
+
}
|
|
964
|
+
//#endregion
|
|
965
|
+
export { PROTOCOL_CHOICES as A, deliveredFileReadErrorFrom as C, ownerHandleOf as D, directAgentOf as E, providerOptionsFor as F, providerProfileProjectionOf as I, SupersededReadError as L, classifyCredentialArg as M, deriveKeyRef as N, requireCreated as O, getPath as P, contextPressureOccupancy as R, DeliveredFileReadError as S, clientOwnerOf as T, safeSubagentErrorMessage as _, detachInspection as a, DIRECT_IMPLEMENTED_CAPABILITIES as b, detachPluginManagerSnapshot as c, QUESTION_REPLY_QUEUED as d, QuestionAnswerError as f, classifySubagentPromptSettlement as g, detachedTurnOutline as h, detachChange as i, ROUTE_PATTERN as j, requireOpened as k, pluginInstallRequestId as l, detachedSessionStatus as m, createRemoteTerminalProgressSource as n, detachLog as o, questionAnswerError as p, PluginManagerStaleResultError as r, detachPhase as s, consumeRemoteTerminalProgress as t, QUESTION_BAD_ANSWER as u, GATEWAY_PRE_INVOCATION_CODES as v, LifecycleError as w, REMOTE_IMPLEMENTED_CAPABILITIES as x, isRemoteBusinessRefusalCode as y };
|