@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,413 @@
|
|
|
1
|
+
import { r as writeEntryRecord } from "./entry-control-DnduyDiw.mjs";
|
|
2
|
+
import { t as mergeCause } from "./dispose-cause-CNFuUnjR.mjs";
|
|
3
|
+
import { t as PI_TUI_CLIENT_CONTRIBUTION } from "./pi-tui-remote-contribution-B0EQsP0N.mjs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
6
|
+
import { isAbsolute } from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
//#region src/app/remote-process/host-foundation-probe.ts
|
|
9
|
+
/**
|
|
10
|
+
* M4-B2-HF real Host RPC qualification probe.
|
|
11
|
+
*
|
|
12
|
+
* Runs ONLY on the existing B1 Client Context after the authenticated
|
|
13
|
+
* transport is live. It temporarily mounts the package's own private
|
|
14
|
+
* contribution and the official Session controller `/remote` contribution —
|
|
15
|
+
* plus the official Workspace controller `/remote` contribution when the caller
|
|
16
|
+
* requests the Workspace proof — calls the official `session/list` RPC, the
|
|
17
|
+
* private PiFile RPC, one private terminal-progress watch and (on request) the
|
|
18
|
+
* official `workspace` namespace (`follow` baseline then `create` identity),
|
|
19
|
+
* then unmounts them in reverse order. It creates no Context, no Connection and
|
|
20
|
+
* no Gateway.
|
|
21
|
+
*
|
|
22
|
+
* The probe is an internal qualification control (not an npm export, CLI
|
|
23
|
+
* command or user-facing API). The caller owns the control channel; this module
|
|
24
|
+
* owns only the contribution/stream lifetime and the structured proof.
|
|
25
|
+
*
|
|
26
|
+
* @module app/remote-process/host-foundation-probe
|
|
27
|
+
*/
|
|
28
|
+
/** The no-live-Agent Session id every negative business probe names. */
|
|
29
|
+
const PROBE_SESSION_ID = "m4-hf-no-live-agent";
|
|
30
|
+
/** Bounded wait for one Workspace stream frame; a timeout is a FAIL, never a PASS. */
|
|
31
|
+
const WORKSPACE_FRAME_TIMEOUT_MS = 2e4;
|
|
32
|
+
/** Bound on frames skipped while looking for one Workspace `upsert`. */
|
|
33
|
+
const WORKSPACE_FRAME_LIMIT = 64;
|
|
34
|
+
/**
|
|
35
|
+
* Load one official generated `/remote` contribution from the installed DSH
|
|
36
|
+
* anchor. This is the same installed-package resolution strategy the B1
|
|
37
|
+
* transport already uses; a source-tree module must never participate.
|
|
38
|
+
*/
|
|
39
|
+
async function loadInstalledRemote(dshAnchor, specifier) {
|
|
40
|
+
const resolved = createRequire(realpathSync(dshAnchor)).resolve(specifier);
|
|
41
|
+
const contribution = (await import(pathToFileURL(resolved).href)).default;
|
|
42
|
+
if (typeof contribution !== "object" || contribution === null || !Array.isArray(contribution.descriptors)) throw new Error(`host foundation probe: the installed ${specifier} export is not a Remote contribution`);
|
|
43
|
+
return contribution;
|
|
44
|
+
}
|
|
45
|
+
function remoteOf(context) {
|
|
46
|
+
const remote = context.remote;
|
|
47
|
+
if (remote === void 0) throw new Error("host foundation probe: the Client Context has no official Remote service");
|
|
48
|
+
return remote;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Wait at the qualification hold point so the split-process harness can read
|
|
52
|
+
* the live Host subscriber count while the watch is still open. Production
|
|
53
|
+
* never sets this environment variable.
|
|
54
|
+
*/
|
|
55
|
+
async function waitForQualificationBarrier(path) {
|
|
56
|
+
const deadline = Date.now() + 3e4;
|
|
57
|
+
while (!existsSync(path)) {
|
|
58
|
+
if (Date.now() > deadline) throw new Error(`host foundation probe: the qualification barrier was not released: ${path}`);
|
|
59
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Validate the opening terminal-progress snapshot required by T24. */
|
|
63
|
+
function assertOpeningSnapshot(frame) {
|
|
64
|
+
if (frame === void 0 || frame.kind !== "snapshot") throw new Error("host foundation probe: the terminal-progress watch did not open with a snapshot");
|
|
65
|
+
if (frame.sessionId !== PROBE_SESSION_ID) throw new Error("host foundation probe: the terminal-progress snapshot names another Session");
|
|
66
|
+
if (frame.running !== false || frame.outcome !== "idle") throw new Error("host foundation probe: the terminal-progress baseline is not idle");
|
|
67
|
+
if (typeof frame.hostEpoch !== "string" || frame.hostEpoch === "") throw new Error("host foundation probe: the terminal-progress snapshot has no Host epoch");
|
|
68
|
+
if (!Number.isSafeInteger(frame.agentEpoch) || !Number.isSafeInteger(frame.revision)) throw new Error("host foundation probe: the terminal-progress snapshot has invalid epoch/revision");
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Await the next frame of one Workspace stream under the qualification bound.
|
|
72
|
+
* A stream that ends or stalls is a FAIL, never an empty success.
|
|
73
|
+
*/
|
|
74
|
+
async function nextWorkspaceFrame(iterator, label) {
|
|
75
|
+
let timer;
|
|
76
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
77
|
+
timer = setTimeout(() => {
|
|
78
|
+
reject(/* @__PURE__ */ new Error(`host foundation probe: timed out waiting for ${label}`));
|
|
79
|
+
}, WORKSPACE_FRAME_TIMEOUT_MS);
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
const next = await Promise.race([iterator.next(), timeout]);
|
|
83
|
+
if (next.done === true) throw new Error(`host foundation probe: the Workspace stream ended before ${label}`);
|
|
84
|
+
return next.value;
|
|
85
|
+
} finally {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Bounded wait for one pull of a HELD stream, so a hang is classified separately. */
|
|
90
|
+
var HeldStreamWaitTimeout = class extends Error {};
|
|
91
|
+
/**
|
|
92
|
+
* Pull one HELD Workspace iterator once and classify the outcome. A frame means
|
|
93
|
+
* the obsolete generation still wrote into the Client (stale delivery); an ended
|
|
94
|
+
* iterator or a carrier failure means the generation is gone and wrote nothing.
|
|
95
|
+
*/
|
|
96
|
+
async function pullHeldStream(iterator) {
|
|
97
|
+
let timer;
|
|
98
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
99
|
+
timer = setTimeout(() => {
|
|
100
|
+
reject(new HeldStreamWaitTimeout("held-stream-wait-timeout"));
|
|
101
|
+
}, WORKSPACE_FRAME_TIMEOUT_MS);
|
|
102
|
+
});
|
|
103
|
+
try {
|
|
104
|
+
const next = await Promise.race([iterator.next(), timeout]);
|
|
105
|
+
return next.done === true ? { kind: "ended" } : {
|
|
106
|
+
kind: "frame",
|
|
107
|
+
frame: next.value
|
|
108
|
+
};
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (error instanceof HeldStreamWaitTimeout) throw new Error("host foundation probe: the held Workspace stream neither ended nor reported a carrier failure within its bound");
|
|
111
|
+
return {
|
|
112
|
+
kind: "failed",
|
|
113
|
+
error
|
|
114
|
+
};
|
|
115
|
+
} finally {
|
|
116
|
+
clearTimeout(timer);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** Read one Workspace projection out of an unknown Remote value, or fail loudly. */
|
|
120
|
+
function readWorkspaceFacts(value, label) {
|
|
121
|
+
const candidate = value;
|
|
122
|
+
if (candidate === void 0 || typeof candidate.workspaceId !== "string" || candidate.workspaceId === "" || typeof candidate.path !== "string" || !isAbsolute(candidate.path) || !Array.isArray(candidate.sessionIds) || !candidate.sessionIds.every((sessionId) => typeof sessionId === "string")) throw new Error(`host foundation probe: ${label} did not return a Workspace projection: ${JSON.stringify(value)}`);
|
|
123
|
+
return {
|
|
124
|
+
workspaceId: candidate.workspaceId,
|
|
125
|
+
path: candidate.path,
|
|
126
|
+
sessionIds: candidate.sessionIds
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async function proveWorkspace(remote, workspacePath, resume) {
|
|
130
|
+
const expectedPath = realpathSync(workspacePath);
|
|
131
|
+
const stream = remote.workspace.follow();
|
|
132
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
133
|
+
let streamClosed = false;
|
|
134
|
+
try {
|
|
135
|
+
const opening = await nextWorkspaceFrame(iterator, "the Workspace baseline");
|
|
136
|
+
if (opening.type !== "baseline" || !Array.isArray(opening.value?.items)) throw new Error(`host foundation probe: workspace/follow did not open with a baseline: ${JSON.stringify(opening)}`);
|
|
137
|
+
const baselineIds = /* @__PURE__ */ new Set();
|
|
138
|
+
for (const item of opening.value.items) baselineIds.add(readWorkspaceFacts(item, "the Workspace baseline").workspaceId);
|
|
139
|
+
const first = await remote.workspace.create({ path: workspacePath });
|
|
140
|
+
if (first.ok !== true || first.value === void 0) throw new Error(`host foundation probe: workspace/create did not return ok: ${JSON.stringify(first)}`);
|
|
141
|
+
if (typeof first.value.created !== "boolean") throw new Error(`host foundation probe: workspace/create did not report "created": ${JSON.stringify(first.value)}`);
|
|
142
|
+
const createdWorkspace = readWorkspaceFacts(first.value.workspace, "workspace/create");
|
|
143
|
+
if (createdWorkspace.path !== expectedPath) throw new Error(`host foundation probe: workspace/create returned "${createdWorkspace.path}" instead of the Host canonical "${expectedPath}"`);
|
|
144
|
+
const inBaseline = baselineIds.has(createdWorkspace.workspaceId);
|
|
145
|
+
let upserted;
|
|
146
|
+
if (first.value.created) {
|
|
147
|
+
if (inBaseline) throw new Error(`host foundation probe: workspace/create reported a new Workspace while the baseline already carried "${createdWorkspace.workspaceId}"`);
|
|
148
|
+
for (let frames = 0; frames < WORKSPACE_FRAME_LIMIT; frames += 1) {
|
|
149
|
+
const frame = await nextWorkspaceFrame(iterator, `the "${createdWorkspace.workspaceId}" Workspace upsert`);
|
|
150
|
+
if (frame.type !== "upsert") continue;
|
|
151
|
+
const candidate = readWorkspaceFacts(frame.workspace, "a Workspace upsert frame");
|
|
152
|
+
if (candidate.workspaceId === createdWorkspace.workspaceId) {
|
|
153
|
+
upserted = candidate;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (upserted === void 0) throw new Error(`host foundation probe: workspace/follow never reported an upsert for "${createdWorkspace.workspaceId}"`);
|
|
158
|
+
if (upserted.path !== createdWorkspace.path || JSON.stringify(upserted.sessionIds) !== JSON.stringify(createdWorkspace.sessionIds)) throw new Error(`host foundation probe: the Workspace upsert disagrees with workspace/create: ${JSON.stringify(upserted)} vs ${JSON.stringify(createdWorkspace)}`);
|
|
159
|
+
} else if (!inBaseline) throw new Error(`host foundation probe: workspace/create resolved "${createdWorkspace.workspaceId}" but the baseline did not carry it`);
|
|
160
|
+
const second = await remote.workspace.create({ path: workspacePath });
|
|
161
|
+
if (second.ok !== true || second.value === void 0 || second.value.created !== false) throw new Error(`host foundation probe: a repeated workspace/create was not an idempotent resolve: ${JSON.stringify(second)}`);
|
|
162
|
+
const resolvedWorkspace = readWorkspaceFacts(second.value.workspace, "the repeated workspace/create");
|
|
163
|
+
if (resolvedWorkspace.workspaceId !== createdWorkspace.workspaceId) throw new Error(`host foundation probe: a repeated workspace/create returned "${resolvedWorkspace.workspaceId}" instead of "${createdWorkspace.workspaceId}"`);
|
|
164
|
+
let generationAdvanced = false;
|
|
165
|
+
let heldStreamClosed = false;
|
|
166
|
+
let restoredBaseline = false;
|
|
167
|
+
if (resume !== void 0) {
|
|
168
|
+
if (resume.requestId !== void 0) writeEntryRecord({
|
|
169
|
+
m4b2hf: "workspace-hold-open",
|
|
170
|
+
processRole: "client",
|
|
171
|
+
pid: process.pid,
|
|
172
|
+
requestId: resume.requestId
|
|
173
|
+
});
|
|
174
|
+
resume.dropCarrier();
|
|
175
|
+
const deadline = Date.now() + WORKSPACE_FRAME_TIMEOUT_MS;
|
|
176
|
+
let generationAfter = resume.readGeneration();
|
|
177
|
+
while (generationAfter === void 0 || resume.generationBefore === void 0 || generationAfter <= resume.generationBefore) {
|
|
178
|
+
if (Date.now() > deadline) throw new Error(`host foundation probe: the held Workspace stream did not observe a replacement Connection generation (${String(resume.generationBefore)} -> ${String(generationAfter)})`);
|
|
179
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
180
|
+
generationAfter = resume.readGeneration();
|
|
181
|
+
}
|
|
182
|
+
generationAdvanced = true;
|
|
183
|
+
const held = await pullHeldStream(iterator);
|
|
184
|
+
if (held.kind === "frame") throw new Error(`host foundation probe: the held Workspace stream delivered a "${held.frame.type}" frame after its Connection generation was replaced`);
|
|
185
|
+
heldStreamClosed = true;
|
|
186
|
+
const restarted = remote.workspace.follow();
|
|
187
|
+
const restartedIterator = restarted[Symbol.asyncIterator]();
|
|
188
|
+
try {
|
|
189
|
+
const baseline = await nextWorkspaceFrame(restartedIterator, "the post-replacement Workspace baseline");
|
|
190
|
+
if (baseline.type !== "baseline" || !Array.isArray(baseline.value?.items)) throw new Error(`host foundation probe: the post-replacement stream did not open with a Host baseline: ${JSON.stringify(baseline)}`);
|
|
191
|
+
const restoredIds = baseline.value.items.map((item) => readWorkspaceFacts(item, "the post-replacement Workspace baseline").workspaceId);
|
|
192
|
+
if (!restoredIds.includes(createdWorkspace.workspaceId)) throw new Error(`host foundation probe: the post-replacement baseline dropped the Workspace the Host had already published (${JSON.stringify(restoredIds)})`);
|
|
193
|
+
restoredBaseline = true;
|
|
194
|
+
} finally {
|
|
195
|
+
restarted.dispose();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
stream.dispose();
|
|
199
|
+
streamClosed = true;
|
|
200
|
+
if ((await iterator.next()).done !== true) throw new Error("host foundation probe: the Workspace stream did not end after dispose");
|
|
201
|
+
return {
|
|
202
|
+
baseline: true,
|
|
203
|
+
inBaseline,
|
|
204
|
+
created: first.value.created,
|
|
205
|
+
idempotent: true,
|
|
206
|
+
upsert: upserted !== void 0,
|
|
207
|
+
workspaceId: createdWorkspace.workspaceId,
|
|
208
|
+
path: createdWorkspace.path,
|
|
209
|
+
generationAdvanced,
|
|
210
|
+
heldStreamClosed,
|
|
211
|
+
restoredBaseline
|
|
212
|
+
};
|
|
213
|
+
} finally {
|
|
214
|
+
if (!streamClosed) try {
|
|
215
|
+
stream.dispose();
|
|
216
|
+
} catch {}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** Wait until the Client's own Connection generation advances past `before`. */
|
|
220
|
+
async function waitForCarrierReplacement(readGeneration, before) {
|
|
221
|
+
const deadline = Date.now() + WORKSPACE_FRAME_TIMEOUT_MS;
|
|
222
|
+
let after = readGeneration();
|
|
223
|
+
while (after === void 0 || before === void 0 || after <= before) {
|
|
224
|
+
if (Date.now() > deadline) throw new Error(`host foundation probe: the Schedule catalog did not observe a replacement Connection generation (${String(before)} -> ${String(after)})`);
|
|
225
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
226
|
+
after = readGeneration();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Prove the official `schedule` namespace over the authenticated link on the
|
|
231
|
+
* SAME live Client Context: a real `catalog`, a Host-created task returned with
|
|
232
|
+
* its identity, one CAS `edit`, and — when the resume control is supplied — a
|
|
233
|
+
* fresh `catalog` on a replacement Connection generation that STILL lists the
|
|
234
|
+
* created task. A failure in any stage throws; the probe never swallows a
|
|
235
|
+
* business/transport error into a false PASS.
|
|
236
|
+
*/
|
|
237
|
+
async function proveSchedule(remote, resume) {
|
|
238
|
+
const opening = await remote.schedule.catalog();
|
|
239
|
+
if (opening.ok !== true || !Array.isArray(opening.value)) throw new Error(`host foundation probe: schedule/catalog did not return ok with an entry array: ${JSON.stringify(opening)}`);
|
|
240
|
+
const baselineIds = new Set(opening.value.map((entry) => entry.id));
|
|
241
|
+
const title = `probe-schedule-${Date.now()}-${process.pid}`;
|
|
242
|
+
const created = await remote.schedule.create({
|
|
243
|
+
title,
|
|
244
|
+
prompt: "host foundation probe schedule task",
|
|
245
|
+
timing: {
|
|
246
|
+
kind: "after",
|
|
247
|
+
after_seconds: 3600
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
if (created.ok !== true || created.value === void 0) throw new Error(`host foundation probe: schedule/create did not return ok: ${JSON.stringify(created)}`);
|
|
251
|
+
const entry = created.value;
|
|
252
|
+
if (typeof entry.id !== "string" || entry.id === "" || entry.title !== title) throw new Error(`host foundation probe: schedule/create did not return the created task identity: ${JSON.stringify(entry)}`);
|
|
253
|
+
if (baselineIds.has(entry.id)) throw new Error(`host foundation probe: schedule/create returned an identity the opening catalog already held: ${entry.id}`);
|
|
254
|
+
const editedTitle = `${title}-edited`;
|
|
255
|
+
const edited = await remote.schedule.edit({
|
|
256
|
+
id: entry.id,
|
|
257
|
+
action: "update",
|
|
258
|
+
patch: { title: editedTitle }
|
|
259
|
+
});
|
|
260
|
+
if (edited.ok !== true || edited.value === void 0) throw new Error(`host foundation probe: schedule/edit did not return ok: ${JSON.stringify(edited)}`);
|
|
261
|
+
const editedEntry = edited.value;
|
|
262
|
+
if (editedEntry.id !== entry.id || editedEntry.title !== editedTitle) throw new Error(`host foundation probe: schedule/edit did not return the updated task: ${JSON.stringify(editedEntry)}`);
|
|
263
|
+
let reconnectCatalog;
|
|
264
|
+
if (resume !== void 0) {
|
|
265
|
+
const generationBefore = resume.readGeneration();
|
|
266
|
+
resume.dropCarrier();
|
|
267
|
+
await waitForCarrierReplacement(resume.readGeneration, generationBefore);
|
|
268
|
+
const after = await remote.schedule.catalog();
|
|
269
|
+
if (after.ok !== true || !Array.isArray(after.value)) throw new Error(`host foundation probe: the post-replacement schedule/catalog did not return ok: ${JSON.stringify(after)}`);
|
|
270
|
+
reconnectCatalog = after.value.some((candidate) => candidate.id === entry.id);
|
|
271
|
+
if (!reconnectCatalog) throw new Error(`host foundation probe: the post-replacement schedule/catalog dropped the task the Host had already created (${entry.id})`);
|
|
272
|
+
}
|
|
273
|
+
const deleted = await remote.schedule.edit({
|
|
274
|
+
id: entry.id,
|
|
275
|
+
action: "delete"
|
|
276
|
+
});
|
|
277
|
+
if (deleted.ok !== true) throw new Error(`host foundation probe: schedule/edit(delete) did not return ok: ${JSON.stringify(deleted)}`);
|
|
278
|
+
const afterDelete = await remote.schedule.catalog();
|
|
279
|
+
if (afterDelete.ok !== true || !Array.isArray(afterDelete.value)) throw new Error(`host foundation probe: the post-delete schedule/catalog did not return ok: ${JSON.stringify(afterDelete)}`);
|
|
280
|
+
if (afterDelete.value.some((candidate) => candidate.id === entry.id)) throw new Error(`host foundation probe: the deleted schedule task is still listed: ${entry.id}`);
|
|
281
|
+
return {
|
|
282
|
+
catalog: true,
|
|
283
|
+
create: true,
|
|
284
|
+
edit: true,
|
|
285
|
+
deleted: true,
|
|
286
|
+
...resume === void 0 ? {} : { reconnectCatalog }
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Execute the real Host RPC proof on the caller's live Client Context.
|
|
291
|
+
*
|
|
292
|
+
* Contribution mounts are recorded immediately after each `$mount` resolves;
|
|
293
|
+
* cleanup runs in reverse order in `finally`, so a failed second mount still
|
|
294
|
+
* unmounts the first. Cleanup failures attach to the original RPC error as its
|
|
295
|
+
* cause chain instead of masking it. The result is returned only after the
|
|
296
|
+
* contribution unmounts and the stream cancellations both succeeded.
|
|
297
|
+
*/
|
|
298
|
+
async function runHostFoundationProbe(context, options) {
|
|
299
|
+
if (options.dropCarrier === void 0 !== (options.readGeneration === void 0)) throw new Error("host foundation probe: the generation-resume control requires BOTH dropCarrier and readGeneration");
|
|
300
|
+
if (options.dropCarrier !== void 0 && options.workspacePath === void 0) throw new Error("host foundation probe: the generation-resume control requires the Workspace proof");
|
|
301
|
+
const remote = remoteOf(context);
|
|
302
|
+
const sessionRemote = await loadInstalledRemote(options.dshAnchor, "@deepseek-ai/dsh-api-session-controller/remote");
|
|
303
|
+
const workspaceRequest = options.workspacePath;
|
|
304
|
+
const workspaceRemote = workspaceRequest === void 0 ? void 0 : await loadInstalledRemote(options.dshAnchor, "@deepseek-ai/dsh-api-workspace-controller/remote");
|
|
305
|
+
const scheduleRemote = options.schedule === true ? await loadInstalledRemote(options.dshAnchor, "@deepseek-ai/dsh-schedule/remote") : void 0;
|
|
306
|
+
const disposers = [];
|
|
307
|
+
const cleanupErrors = [];
|
|
308
|
+
let watch;
|
|
309
|
+
let watchIterator;
|
|
310
|
+
let result;
|
|
311
|
+
let primaryError;
|
|
312
|
+
try {
|
|
313
|
+
disposers.push(await remote.$mount(PI_TUI_CLIENT_CONTRIBUTION));
|
|
314
|
+
disposers.push(await remote.$mount(sessionRemote));
|
|
315
|
+
if (workspaceRemote !== void 0) disposers.push(await remote.$mount(workspaceRemote));
|
|
316
|
+
if (scheduleRemote !== void 0) disposers.push(await remote.$mount(scheduleRemote));
|
|
317
|
+
const list = await remote.session.list({});
|
|
318
|
+
if (list.ok !== true || !Array.isArray(list.value?.items)) throw new Error(`host foundation probe: official session/list did not return ok with an items array: ${JSON.stringify(list)}`);
|
|
319
|
+
const fileResult = await remote.piTuiFileReferences.list(PROBE_SESSION_ID, "notes");
|
|
320
|
+
if (fileResult.ok !== true || fileResult.value?.kind !== "unavailable") throw new Error(`host foundation probe: private PiFile RPC did not return ok/unavailable: ${JSON.stringify(fileResult)}`);
|
|
321
|
+
watch = remote.piTuiTerminalProgress.watch(PROBE_SESSION_ID);
|
|
322
|
+
watchIterator = watch[Symbol.asyncIterator]();
|
|
323
|
+
const opening = await watchIterator.next();
|
|
324
|
+
if (opening.done) throw new Error("host foundation probe: the terminal-progress watch ended before its snapshot");
|
|
325
|
+
assertOpeningSnapshot(opening.value);
|
|
326
|
+
if (options.requestId !== void 0) writeEntryRecord({
|
|
327
|
+
m4b2hf: "host-rpc-watch-open",
|
|
328
|
+
processRole: "client",
|
|
329
|
+
pid: process.pid,
|
|
330
|
+
requestId: options.requestId
|
|
331
|
+
});
|
|
332
|
+
const barrier = process.env.SPLIT_PROCESS_HOST_FOUNDATION_BARRIER;
|
|
333
|
+
if (barrier !== void 0 && barrier !== "") await waitForQualificationBarrier(barrier);
|
|
334
|
+
watch.dispose();
|
|
335
|
+
if ((await watchIterator.next()).done !== true) throw new Error("host foundation probe: the terminal-progress watch did not end after dispose");
|
|
336
|
+
watch = void 0;
|
|
337
|
+
watchIterator = void 0;
|
|
338
|
+
const dropCarrier = options.dropCarrier;
|
|
339
|
+
const readGeneration = options.readGeneration;
|
|
340
|
+
if (dropCarrier === void 0 !== (readGeneration === void 0)) throw new Error("host foundation probe: the generation-resume control requires BOTH dropCarrier and readGeneration");
|
|
341
|
+
const workspace = workspaceRequest === void 0 ? void 0 : await proveWorkspace(remote, workspaceRequest, dropCarrier === void 0 || readGeneration === void 0 ? void 0 : {
|
|
342
|
+
readGeneration,
|
|
343
|
+
generationBefore: readGeneration(),
|
|
344
|
+
dropCarrier,
|
|
345
|
+
...options.requestId === void 0 ? {} : { requestId: options.requestId }
|
|
346
|
+
});
|
|
347
|
+
const schedule = options.schedule === true ? await proveSchedule(remote, dropCarrier === void 0 || readGeneration === void 0 ? void 0 : {
|
|
348
|
+
readGeneration,
|
|
349
|
+
dropCarrier
|
|
350
|
+
}) : void 0;
|
|
351
|
+
result = {
|
|
352
|
+
officialSessionList: true,
|
|
353
|
+
privateFileRpc: true,
|
|
354
|
+
terminalSnapshot: true,
|
|
355
|
+
...schedule === void 0 ? {} : {
|
|
356
|
+
scheduleRemote: true,
|
|
357
|
+
scheduleCatalog: schedule.catalog,
|
|
358
|
+
scheduleCreate: schedule.create,
|
|
359
|
+
scheduleEdit: schedule.edit,
|
|
360
|
+
scheduleDeleted: schedule.deleted,
|
|
361
|
+
...schedule.reconnectCatalog === void 0 ? {} : { scheduleReconnectCatalog: schedule.reconnectCatalog }
|
|
362
|
+
},
|
|
363
|
+
...workspace === void 0 ? {} : {
|
|
364
|
+
workspaceRemote: true,
|
|
365
|
+
workspaceBaseline: workspace.baseline,
|
|
366
|
+
workspaceInBaseline: workspace.inBaseline,
|
|
367
|
+
workspaceCreated: workspace.created,
|
|
368
|
+
workspaceIdempotent: workspace.idempotent,
|
|
369
|
+
workspaceUpsert: workspace.upsert,
|
|
370
|
+
workspaceId: workspace.workspaceId,
|
|
371
|
+
workspacePath: workspace.path,
|
|
372
|
+
...options.dropCarrier === void 0 ? {} : {
|
|
373
|
+
workspaceGenerationAdvanced: workspace.generationAdvanced,
|
|
374
|
+
workspaceHeldStreamClosed: workspace.heldStreamClosed,
|
|
375
|
+
workspaceRestoredBaseline: workspace.restoredBaseline
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
} catch (error) {
|
|
380
|
+
primaryError = error;
|
|
381
|
+
} finally {
|
|
382
|
+
if (watch !== void 0) try {
|
|
383
|
+
watch.dispose();
|
|
384
|
+
} catch (error) {
|
|
385
|
+
cleanupErrors.push(error);
|
|
386
|
+
}
|
|
387
|
+
for (let index = disposers.length - 1; index >= 0; index -= 1) try {
|
|
388
|
+
await disposers[index]();
|
|
389
|
+
} catch (error) {
|
|
390
|
+
cleanupErrors.push(error);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (primaryError !== void 0) {
|
|
394
|
+
const primary = primaryError instanceof Error ? primaryError : new Error(String(primaryError));
|
|
395
|
+
if (cleanupErrors.length > 0) {
|
|
396
|
+
const secondary = cleanupErrors.length === 1 ? cleanupErrors[0] : new AggregateError(cleanupErrors, "host foundation probe: contribution cleanup failures");
|
|
397
|
+
throw mergeCause(primary, secondary);
|
|
398
|
+
}
|
|
399
|
+
throw primary;
|
|
400
|
+
}
|
|
401
|
+
if (result === void 0) throw new Error("host foundation probe: no proof was produced");
|
|
402
|
+
if (cleanupErrors.length > 0) throw mergeCause(/* @__PURE__ */ new Error("host foundation probe: contribution cleanup failed"), cleanupErrors.length === 1 ? cleanupErrors[0] : new AggregateError(cleanupErrors, "host foundation probe: contribution cleanup failures"));
|
|
403
|
+
return {
|
|
404
|
+
m4b2hf: "host-rpc-proof",
|
|
405
|
+
hostPid: options.host.identity.hostPid,
|
|
406
|
+
hostInstanceId: options.host.identity.instanceId,
|
|
407
|
+
clientPid: process.pid,
|
|
408
|
+
...result,
|
|
409
|
+
cleaned: true
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
//#endregion
|
|
413
|
+
export { runHostFoundationProbe };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
|
|
3
|
+
//#region src/app/host/pi-tui-host-runtime.d.ts
|
|
4
|
+
/** Stable Cordis plugin name (the Loader row id in the Host-only overlay). */
|
|
5
|
+
declare const name = "pi-tui-host-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* Explicit Host dependencies: the private Typert registry plus the two live
|
|
8
|
+
* Host facts the business rows resolve per call. `tuiStartup` remains a Loader
|
|
9
|
+
* row gate (see the Host-only overlay), not a plugin inject. The Web access row
|
|
10
|
+
* resolves the Host's OWN Loader through the service on every call, so this
|
|
11
|
+
* published row contract does not change: this row IS a Loader row, and a Host
|
|
12
|
+
* without a Loader fails closed (`unavailable`) instead of pending forever.
|
|
13
|
+
*/
|
|
14
|
+
declare const inject: string[];
|
|
15
|
+
/** Data-free readiness gate published after the whole built-in runtime is live. */
|
|
16
|
+
declare const PI_TUI_HOST_READY_SERVICE = "piTuiHostReady";
|
|
17
|
+
/**
|
|
18
|
+
* Mount the built-in PiTui Host Runtime on the launching Host Context.
|
|
19
|
+
*
|
|
20
|
+
* Startup order is fixed: register the package's ONE contribution, mount the
|
|
21
|
+
* file-reference service, mount the terminal-progress service, mount the Web
|
|
22
|
+
* access service, verify ALL live bindings, then publish the readiness gate.
|
|
23
|
+
* Every child fiber is recorded BEFORE it is awaited; a partial rejection
|
|
24
|
+
* disposes the recorded children in reverse order (contribution last) while
|
|
25
|
+
* keeping the original error primary and attaching cleanup failures to its
|
|
26
|
+
* cause chain.
|
|
27
|
+
*/
|
|
28
|
+
declare function apply(ctx: Context): Promise<void>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { PI_TUI_HOST_READY_SERVICE, apply, inject, name };
|