@xmoon76/dsh-pi-tui 0.5.6 → 0.5.8
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/LICENSE +33 -0
- package/README.en.md +103 -814
- package/README.md +102 -711
- package/cordis.patch.yml +186 -0
- package/dist/acp-preferences.d.mts +29 -0
- package/dist/acp-preferences.mjs +15 -0
- package/dist/{bootstrap-DQ4YPL-7.mjs → bootstrap-CMIjGyuk.mjs} +33515 -7587
- package/dist/builtins.mjs +3 -3
- package/dist/{client-bootstrap-Cr1JCaF5.mjs → client-bootstrap-BjGPc-DM.mjs} +4637 -492
- package/dist/client-extension-loader-probe-BUw7q8bJ.mjs +119 -0
- package/dist/command-trust-DChWUamk.mjs +406 -0
- package/dist/daemon-launcher-Dult7Jxv.mjs +1932 -0
- package/dist/daemon-launcher.d.mts +159 -0
- package/dist/daemon-launcher.mjs +2 -0
- package/dist/diagnostics-D5jwc-q1.d.mts +11 -0
- package/dist/{dist-CIsR7cz4.mjs → dist-BFgC-5tL.mjs} +938 -487
- package/dist/entry-control-DjNsE3I0.mjs +190 -0
- package/dist/extension/advanced.d.mts +1 -1
- package/dist/extension/unstable.d.mts +1 -1
- package/dist/extension-config-probe-BDdvutkG.mjs +95 -0
- package/dist/extension-config.d.mts +29 -0
- package/dist/extension-config.mjs +22 -0
- package/dist/{extensions-Bp0L37lP.mjs → extensions-B4uLpSTv.mjs} +1109 -100
- package/dist/{extensions-Bte3XOt5.d.mts → extensions-C8eAM0gX.d.mts} +1 -1
- package/dist/extensions.d.mts +2 -2
- package/dist/extensions.mjs +1 -1
- package/dist/{host-bootstrap-DilsvA6f.mjs → host-bootstrap-MVxks641.mjs} +129 -24
- package/dist/{host-foundation-probe--5jtvHVe.mjs → host-foundation-probe-DMNTmNrH.mjs} +2 -2
- package/dist/host-runtime.d.mts +11 -5
- package/dist/host-runtime.mjs +4171 -920
- package/dist/index.d.mts +86 -174
- package/dist/index.mjs +38087 -9967
- package/dist/local-acp-listener-B65J0Bx4.mjs +3115 -0
- package/dist/local-client.mjs +1158 -59
- package/dist/local-daemon-control-C14q9KnD.mjs +1588 -0
- package/dist/local-daemon-control-TCnERL7n.mjs +1424 -0
- package/dist/local-discovery-DOSsCh9q.mjs +2883 -0
- package/dist/local-discovery-egN4_gsQ.mjs +2 -0
- package/dist/local-discovery-uOBfFq5j.mjs +2764 -0
- package/dist/local-host.mjs +812 -89
- package/dist/local-profile-daemon-admin-BmQSdzT0.mjs +210 -0
- package/dist/local-scope-DamiMqPd.mjs +1340 -0
- package/dist/{local-transport-BVwFYq_Y.mjs → local-transport-Iwo0mtu3.mjs} +313 -38
- package/dist/local-web-control-DMrjwCkl.mjs +454 -0
- package/dist/local-workspace-object-D06GL0UO.mjs +248 -0
- package/dist/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/dist/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/dist/open-CmOBxSjN.mjs +63 -0
- package/dist/persisted-setting-probe-DWZLtWoB.mjs +145 -0
- package/dist/pi-tui-acp-access-contract-BdLwduU6.mjs +75 -0
- package/dist/pi-tui-remote-contribution-Do8ECrUy.mjs +1492 -0
- package/dist/pi-tui-terminal-progress-contract-B3RoEzjK.mjs +146 -0
- package/dist/preferences.d.mts +17 -0
- package/dist/preferences.mjs +20 -0
- package/dist/preset-BcWqOtY7.mjs +46 -0
- package/dist/profile-preferences-migration-BfUGdPZx.mjs +500 -0
- package/dist/profile-preferences-migration-CThz4rHH.mjs +2 -0
- package/dist/prompt-sections-DUKmWb8g.mjs +2232 -0
- package/dist/prompt-sections-DXmjB58H.mjs +634 -0
- package/dist/{public-types-Dgf1bDke.d.mts → public-types-C1YgFtwC.d.mts} +56 -3
- package/dist/row-id-DPbyt9Nn.mjs +24 -0
- package/dist/{runtime-status-Cj1nFOdS.mjs → runtime-status-v-FTnWcD.mjs} +49 -3
- package/dist/schema-BTGYn8_X.d.mts +54 -0
- package/dist/schema-qE_P09zJ.mjs +124 -0
- package/dist/{session-BKGXyh80.mjs → session-C6tSs86s.mjs} +9672 -7270
- package/dist/{session-CPt_U8_f.mjs → session-CstInGIA.mjs} +9674 -7273
- package/dist/startup-CarQxWwi.d.mts +213 -0
- package/dist/{startup-7BYWuvBU.mjs → startup-EG5UqIcd.mjs} +341 -26
- package/dist/startup.d.mts +2 -99
- package/dist/startup.mjs +2 -2
- package/dist/{terminal-progress-source-DrqQhtT8.mjs → terminal-progress-source-CpfpQO_h.mjs} +2038 -67
- package/dist/{pasted-path-range-CMnxuGPx.mjs → transcript-view-C1YtJ49Y.mjs} +11590 -6718
- package/dist/{pasted-path-range-r6qzV_tC.mjs → transcript-view-CuJYWkhp.mjs} +12296 -6923
- package/dist/version-B9yC7bBk.mjs +83 -0
- package/dist/visual-tools.d.mts +1 -1
- package/dist/visual-tools.mjs +1 -1
- package/dist/web-preferences.d.mts +1 -1
- package/dist/{web-roster-CjqnUXNk.mjs → web-roster-Dis7BhrA.mjs} +63 -3
- package/generated/dsh-presets/cordis.patch.yml +4 -2
- package/generated/dsh-presets/ptc.patch.yml +4 -0
- package/generated/dsh-presets/standard.patch.yml +7 -0
- package/generated/web-access/cordis.patch.yml +239 -0
- package/package.json +217 -170
- package/dist/entry-control-DnduyDiw.mjs +0 -92
- package/dist/local-discovery-C9VMjc0K.mjs +0 -759
- package/dist/local-discovery-CDaQHA_R.mjs +0 -2
- package/dist/pi-tui-remote-contribution-B0EQsP0N.mjs +0 -85
- package/dist/pi-tui-terminal-progress-contract-CdBH9j78.mjs +0 -70
- package/dist/pi-tui-terminal-progress-contract-MLXZ-i3t.mjs +0 -905
- package/dist/version-a-eF-QER.mjs +0 -80
package/dist/local-client.mjs
CHANGED
|
@@ -1,15 +1,609 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { n as createEntryDiag, r as writeEntryRecord, t as attachEntryControl } from "./entry-control-DnduyDiw.mjs";
|
|
4
|
-
import { i as runDetached } from "./tasks-D_z5Yjjr.mjs";
|
|
5
|
-
import { t as mergeCause } from "./dispose-cause-CNFuUnjR.mjs";
|
|
2
|
+
import { d as readInstalledDshVersion, h as scopeFromInstalledProfile, n as LocalScopeError, o as bindProfileKernelSeat, p as readProcessStartDiagnostic, r as NO_PROCESS_SEAT, s as computeBuildId, u as installedPackageRootFromEntry, v as parseProcessStatStarttime, y as readKernelProcess } from "./local-scope-DamiMqPd.mjs";
|
|
6
3
|
import { t as runSyncDisposalSteps } from "./disposal-BYBbEpVY.mjs";
|
|
4
|
+
import { n as createEntryDiag, r as writeEntryRecord, t as attachEntryControl } from "./entry-control-DjNsE3I0.mjs";
|
|
5
|
+
import { i as runDetached, o as safeErrorMessage } from "./tasks-D_z5Yjjr.mjs";
|
|
6
|
+
import { r as observeHostWorkspaceObject } from "./local-workspace-object-D06GL0UO.mjs";
|
|
7
|
+
import { c as ensureLocalHost, m as sameLocalInstanceRecord, p as readLocalRecord, r as assertRecordedHostKernelIdentityCurrent } from "./local-discovery-DOSsCh9q.mjs";
|
|
8
|
+
import { t as mergeCause } from "./dispose-cause-CNFuUnjR.mjs";
|
|
9
|
+
import { a as dshHome, n as profileDaemonAdminRun, t as createProfileDaemonAdmin } from "./local-profile-daemon-admin-BmQSdzT0.mjs";
|
|
7
10
|
import { createRequire } from "node:module";
|
|
8
|
-
import {
|
|
11
|
+
import { randomUUID } from "node:crypto";
|
|
12
|
+
import { chmodSync, closeSync, constants, existsSync, fchmodSync, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, rmSync, statSync, writeSync } from "node:fs";
|
|
9
13
|
import { dirname, isAbsolute, join } from "node:path";
|
|
10
14
|
import { pathToFileURL } from "node:url";
|
|
11
|
-
import { spawn } from "node:child_process";
|
|
12
15
|
import { constants as constants$1 } from "node:os";
|
|
16
|
+
import { spawn } from "node:child_process";
|
|
17
|
+
//#region src/app/remote-process/client-fatal-diagnostics.ts
|
|
18
|
+
/**
|
|
19
|
+
* Private Client fatal diagnostics.
|
|
20
|
+
*
|
|
21
|
+
* The Split Client runs in its own process; its launcher inherits this
|
|
22
|
+
* process's terminal but cannot report the child's cause, and the official
|
|
23
|
+
* `daemon logs` command must remain a Host-only source. This module is the ONE
|
|
24
|
+
* Client-owned fatal artifact writer: on a real surface fatal it stores a
|
|
25
|
+
* bounded, redacted, human-readable report under the private
|
|
26
|
+
* `$DSH_HOME/logs/pi-tui-client/` directory and returns a terminal-safe
|
|
27
|
+
* locator. It writes nothing on a successful start, depends on no Cordis /
|
|
28
|
+
* Host / Remote state, and an IO failure is a secondary result that never
|
|
29
|
+
* replaces the primary failure.
|
|
30
|
+
*
|
|
31
|
+
* The file is private incident data, not a shareable report: mode 0600 is
|
|
32
|
+
* mandatory, and redaction covers only the well-known credential carriers.
|
|
33
|
+
* Arbitrary secrets embedded in a user-thrown error cannot be fully
|
|
34
|
+
* recognized; never treat this file as safe to share anonymously.
|
|
35
|
+
* @module app/remote-process/client-fatal-diagnostics
|
|
36
|
+
*/
|
|
37
|
+
const HEADER = "dsh-pi-tui client fatal v1";
|
|
38
|
+
const MAX_FILE_BYTES = 32768;
|
|
39
|
+
const MAX_MESSAGE_BYTES = 2048;
|
|
40
|
+
const MAX_STACK_BYTES = 12288;
|
|
41
|
+
const MAX_CAUSE_DEPTH = 4;
|
|
42
|
+
const MAX_NAME_BYTES = 128;
|
|
43
|
+
const ERROR_CODE_PATTERN = /^[A-Z][A-Z0-9_]{0,63}$/u;
|
|
44
|
+
/** Only the Node module-loader codes are Client dependency misses. */
|
|
45
|
+
const MODULE_MISSING_CODE_PATTERN = /^(?:ERR_MODULE_NOT_FOUND|MODULE_NOT_FOUND)$/u;
|
|
46
|
+
const SAFE_MODULE_SPECIFIER_PATTERN = /^[A-Za-z0-9@._/-]{1,96}$/u;
|
|
47
|
+
const SAFE_ERRNO_PATTERN = /^[A-Z][A-Z0-9_]{0,31}$/u;
|
|
48
|
+
const MODULE_NOT_FOUND_SENTENCE = /Cannot find (?:package|module) '([^']+)'/u;
|
|
49
|
+
/** A deliberate policy refusal with a controlled errno-shaped code. */
|
|
50
|
+
var DiagnosticWriteRefusal = class extends Error {
|
|
51
|
+
code;
|
|
52
|
+
constructor(code) {
|
|
53
|
+
super(code);
|
|
54
|
+
this.name = "DiagnosticWriteRefusal";
|
|
55
|
+
this.code = code;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/** Read one error-like field without letting a hostile getter or proxy escape. */
|
|
59
|
+
function readField(value, field) {
|
|
60
|
+
try {
|
|
61
|
+
return value[field];
|
|
62
|
+
} catch {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The controlled errno name of a thrown IO/policy failure, or `UNKNOWN`. */
|
|
67
|
+
function controlledErrno(error) {
|
|
68
|
+
const code = readField(error, "code");
|
|
69
|
+
return typeof code === "string" && SAFE_ERRNO_PATTERN.test(code) ? code : "UNKNOWN";
|
|
70
|
+
}
|
|
71
|
+
/** The legal error code of a thrown value, if it has one. */
|
|
72
|
+
function legalErrorCode(error) {
|
|
73
|
+
const code = readField(error, "code");
|
|
74
|
+
return typeof code === "string" && ERROR_CODE_PATTERN.test(code) ? code : void 0;
|
|
75
|
+
}
|
|
76
|
+
/** Whether this is the exact Node loader shape of a missing Client dependency. */
|
|
77
|
+
function isModuleMissing(error) {
|
|
78
|
+
const code = legalErrorCode(error);
|
|
79
|
+
return code !== void 0 && MODULE_MISSING_CODE_PATTERN.test(code);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The only module specifier that may reach the terminal: the standard Node
|
|
83
|
+
* `Cannot find ...` sentence, a bounded package-shaped name with no path or
|
|
84
|
+
* URL shape. An unknown shape stays unknown rather than guessing.
|
|
85
|
+
*/
|
|
86
|
+
function clientModuleSpecifier(error) {
|
|
87
|
+
const specifier = MODULE_NOT_FOUND_SENTENCE.exec(safeErrorMessage(error))?.[1];
|
|
88
|
+
if (specifier === void 0) return void 0;
|
|
89
|
+
if (!SAFE_MODULE_SPECIFIER_PATTERN.test(specifier)) return void 0;
|
|
90
|
+
if (specifier.startsWith("/") || specifier.startsWith("./") || specifier.startsWith("../")) return void 0;
|
|
91
|
+
if (specifier.includes("/../") || specifier.includes("//") || specifier.includes("\\")) return void 0;
|
|
92
|
+
return specifier;
|
|
93
|
+
}
|
|
94
|
+
/** The controlled classification of one fatal observation. */
|
|
95
|
+
function clientFatalKind(error, phase) {
|
|
96
|
+
if (isModuleMissing(error)) return "CLIENT_MODULE_MISSING";
|
|
97
|
+
return phase === "client-runtime" ? "CLIENT_RUNTIME_FAILED" : "CLIENT_STARTUP_FAILED";
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Redact the known credential carriers from private diagnostic text. Bounded
|
|
101
|
+
* on purpose: the file contract states that arbitrary secret formats cannot
|
|
102
|
+
* be fully recognized.
|
|
103
|
+
*/
|
|
104
|
+
function redactPrivateText(text) {
|
|
105
|
+
return text.replace(/\b(Authorization|Cookie|Set-Cookie)\s*:\s*[^\r\n]*/giu, "$1: <redacted>").replace(/\b[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s'"]+/gu, "<url>").replace(/([?&](?:token|access_token|cookie)=)[^&#\s]+/giu, "$1<redacted>").replace(/\b(token|access_token|password)\s*=\s*(?:\\?"(?:\\.|[^"\\])*\\?"|\\?'(?:\\.|[^'\\])*\\?'|[^\s&;,]+)/giu, "$1=<redacted>");
|
|
106
|
+
}
|
|
107
|
+
/** Truncate a string to at most `maxBytes` UTF-8 bytes without splitting a code point. */
|
|
108
|
+
function truncateUtf8(text, maxBytes) {
|
|
109
|
+
const buffer = Buffer.from(text, "utf8");
|
|
110
|
+
if (buffer.length <= maxBytes) return text;
|
|
111
|
+
let end = maxBytes;
|
|
112
|
+
while (end > 0 && (buffer[end] & 192) === 128) end -= 1;
|
|
113
|
+
return buffer.subarray(0, end).toString("utf8");
|
|
114
|
+
}
|
|
115
|
+
/** Collapse a single-line field without letting control characters cross fields. */
|
|
116
|
+
function singleLine(text, maxBytes) {
|
|
117
|
+
return truncateUtf8(redactPrivateText(text).replace(/[\r\n]+/gu, " "), maxBytes);
|
|
118
|
+
}
|
|
119
|
+
/** Observe Error/AggregateError identity without a hostile trap escaping. */
|
|
120
|
+
function isErrorLike(value) {
|
|
121
|
+
try {
|
|
122
|
+
return value instanceof Error;
|
|
123
|
+
} catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function isAggregateErrorLike(value) {
|
|
128
|
+
try {
|
|
129
|
+
return value instanceof AggregateError;
|
|
130
|
+
} catch {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** The error branches of one AggregateError, without the wrapper itself. */
|
|
135
|
+
function aggregateBranches(value) {
|
|
136
|
+
const errors = readField(value, "errors");
|
|
137
|
+
try {
|
|
138
|
+
return Array.isArray(errors) ? [...errors] : [];
|
|
139
|
+
} catch {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** The direct cause branches of one error layer, including an AggregateError's
|
|
144
|
+
* own standard `.cause` alongside its `.errors` branches. */
|
|
145
|
+
function causeBranches(value) {
|
|
146
|
+
if (isAggregateErrorLike(value)) {
|
|
147
|
+
const branches = aggregateBranches(value);
|
|
148
|
+
const cause = readField(value, "cause");
|
|
149
|
+
if (cause !== void 0) branches.push(cause);
|
|
150
|
+
if (branches.length > 0) return branches;
|
|
151
|
+
}
|
|
152
|
+
const cause = readField(value, "cause");
|
|
153
|
+
return cause === void 0 ? [] : [cause];
|
|
154
|
+
}
|
|
155
|
+
/** Append one primary/cause layer to the fixed field list. */
|
|
156
|
+
function appendErrorFields(lines, error, depth) {
|
|
157
|
+
const prefix = depth === 0 ? "error" : `cause[${depth}]`;
|
|
158
|
+
const name = readField(error, "name");
|
|
159
|
+
const fallbackName = isErrorLike(error) ? "Error" : "NonError";
|
|
160
|
+
lines.push(`${prefix}.name: ${typeof name === "string" && name !== "" ? singleLine(name, MAX_NAME_BYTES) : fallbackName}`);
|
|
161
|
+
const code = legalErrorCode(error);
|
|
162
|
+
if (code !== void 0) lines.push(`${prefix}.code: ${code}`);
|
|
163
|
+
lines.push(`${prefix}.message: ${truncateUtf8(redactPrivateText(safeErrorMessage(error)), MAX_MESSAGE_BYTES)}`);
|
|
164
|
+
const stack = readField(error, "stack");
|
|
165
|
+
if (typeof stack === "string" && stack !== "") lines.push(`${prefix}.stack: ${truncateUtf8(redactPrivateText(stack), MAX_STACK_BYTES)}`);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Append at most MAX_CAUSE_DEPTH REAL causes. `AggregateError` wrappers are
|
|
169
|
+
* flattening devices: their branches occupy the same cause slots, so the
|
|
170
|
+
* cleanup merge can expose both sides without spending a slot on the wrapper.
|
|
171
|
+
*/
|
|
172
|
+
function appendCauseChain(lines, root) {
|
|
173
|
+
const seen = /* @__PURE__ */ new Set();
|
|
174
|
+
let count = 0;
|
|
175
|
+
let circular = false;
|
|
176
|
+
const visit = (value) => {
|
|
177
|
+
if (value === void 0 || count >= MAX_CAUSE_DEPTH) return;
|
|
178
|
+
if (seen.has(value)) {
|
|
179
|
+
circular = true;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
seen.add(value);
|
|
183
|
+
const branches = causeBranches(value);
|
|
184
|
+
if (isAggregateErrorLike(value) && branches.length > 0) {
|
|
185
|
+
for (const branch of branches) visit(branch);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
count += 1;
|
|
189
|
+
appendErrorFields(lines, value, count);
|
|
190
|
+
if (count >= MAX_CAUSE_DEPTH) return;
|
|
191
|
+
for (const child of branches) visit(child);
|
|
192
|
+
};
|
|
193
|
+
for (const child of causeBranches(root)) visit(child);
|
|
194
|
+
if (circular) lines.push("cause: <circular cause>");
|
|
195
|
+
}
|
|
196
|
+
/** Bound the whole document to the frozen 32 KiB contract. */
|
|
197
|
+
function boundFileText(text) {
|
|
198
|
+
if (Buffer.from(text, "utf8").length <= MAX_FILE_BYTES) return text;
|
|
199
|
+
const marker = "\n[truncated]\n";
|
|
200
|
+
return `${truncateUtf8(text, MAX_FILE_BYTES - Buffer.byteLength(marker, "utf8"))}${marker}`;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Build the bounded, redacted private text for one fatal. Shared with the
|
|
204
|
+
* writer so the security/size rules live in exactly one implementation.
|
|
205
|
+
*/
|
|
206
|
+
function clientFatalErrorDetails(error, phase) {
|
|
207
|
+
const kind = clientFatalKind(error, phase);
|
|
208
|
+
const lines = [
|
|
209
|
+
HEADER,
|
|
210
|
+
`time: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
211
|
+
`phase: ${phase}`,
|
|
212
|
+
`kind: ${kind}`
|
|
213
|
+
];
|
|
214
|
+
appendErrorFields(lines, error, 0);
|
|
215
|
+
appendCauseChain(lines, error);
|
|
216
|
+
return {
|
|
217
|
+
kind,
|
|
218
|
+
text: boundFileText(`${lines.join("\n")}\n`)
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/** The terminal-safe locator for one write result: never a private absolute path. */
|
|
222
|
+
function clientDiagnosticLocation(result) {
|
|
223
|
+
if (result.kind === "written") return `Client diagnostics: $DSH_HOME/logs/pi-tui-client/${result.fileName} (default DSH_HOME: ~/.dsh)`;
|
|
224
|
+
if (result.kind === "disabled") return "Client diagnostic file disabled (DSH_PI_TUI_LOG=off)";
|
|
225
|
+
return `Client diagnostics unavailable (DIAGNOSTIC_WRITE_FAILURE: ${result.errno})`;
|
|
226
|
+
}
|
|
227
|
+
/** Create (or tighten) the Client-only directory and prove it is a private 0700 real directory. */
|
|
228
|
+
function ensurePrivateClientDirectory(path, uid) {
|
|
229
|
+
let info;
|
|
230
|
+
try {
|
|
231
|
+
info = lstatSync(path);
|
|
232
|
+
} catch (error) {
|
|
233
|
+
if (controlledErrno(error) !== "ENOENT") throw error;
|
|
234
|
+
try {
|
|
235
|
+
mkdirSync(path, { mode: 448 });
|
|
236
|
+
} catch (mkdirError) {
|
|
237
|
+
if (controlledErrno(mkdirError) !== "EEXIST") throw mkdirError;
|
|
238
|
+
}
|
|
239
|
+
info = lstatSync(path);
|
|
240
|
+
}
|
|
241
|
+
if (info.isSymbolicLink() || !info.isDirectory()) throw new DiagnosticWriteRefusal("ELOOP");
|
|
242
|
+
if (uid !== void 0 && info.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
243
|
+
if ((info.mode & 511) !== 448) {
|
|
244
|
+
chmodSync(path, 448);
|
|
245
|
+
info = lstatSync(path);
|
|
246
|
+
if (info.isSymbolicLink() || !info.isDirectory() || (info.mode & 511) !== 448) throw new DiagnosticWriteRefusal("EPERM");
|
|
247
|
+
if (uid !== void 0 && info.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
248
|
+
}
|
|
249
|
+
return path;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Resolve the real DSH home, prove the actual `logs` parent and the Client-only
|
|
253
|
+
* child are uid-owned real directories, and create only the Client-specific
|
|
254
|
+
* directory when missing. The shared `logs` directory is never chmodded.
|
|
255
|
+
*/
|
|
256
|
+
function prepareDiagnosticDirectory(env) {
|
|
257
|
+
const home = realpathSync(dshHome(env));
|
|
258
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
259
|
+
const homeInfo = statSync(home);
|
|
260
|
+
if (!homeInfo.isDirectory()) throw new DiagnosticWriteRefusal("ENOTDIR");
|
|
261
|
+
if (uid !== void 0 && homeInfo.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
262
|
+
const logs = join(home, "logs");
|
|
263
|
+
let logsInfo;
|
|
264
|
+
try {
|
|
265
|
+
logsInfo = lstatSync(logs);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if (controlledErrno(error) !== "ENOENT") throw error;
|
|
268
|
+
mkdirSync(logs, { mode: 448 });
|
|
269
|
+
logsInfo = lstatSync(logs);
|
|
270
|
+
}
|
|
271
|
+
if (logsInfo.isSymbolicLink() || !logsInfo.isDirectory()) throw new DiagnosticWriteRefusal("ELOOP");
|
|
272
|
+
if (uid !== void 0 && logsInfo.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
273
|
+
if ((logsInfo.mode & 18) !== 0) throw new DiagnosticWriteRefusal("EPERM");
|
|
274
|
+
const directory = ensurePrivateClientDirectory(join(logs, "pi-tui-client"), uid);
|
|
275
|
+
if (realpathSync(directory) !== directory) throw new DiagnosticWriteRefusal("ELOOP");
|
|
276
|
+
return directory;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Write the whole UTF-8 buffer. `writeSync` may legally return a short count
|
|
280
|
+
* for a regular file (for example a full disk); a short/zero write is an IO
|
|
281
|
+
* failure, never a successful `written` result.
|
|
282
|
+
*/
|
|
283
|
+
function writeAllBytes(fd, text, write = writeSync) {
|
|
284
|
+
const buffer = Buffer.from(text, "utf8");
|
|
285
|
+
let offset = 0;
|
|
286
|
+
while (offset < buffer.length) {
|
|
287
|
+
const written = write(fd, buffer, offset, buffer.length - offset);
|
|
288
|
+
if (written <= 0) throw new DiagnosticWriteRefusal("EIO");
|
|
289
|
+
offset += written;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Write ONE Client fatal artifact. Returns the terminal-safe locator facts; a
|
|
294
|
+
* disabled or failed write is reported explicitly and never throws into the
|
|
295
|
+
* application startup root.
|
|
296
|
+
*/
|
|
297
|
+
function writeClientFatalDiagnostic(error, phase, env) {
|
|
298
|
+
const configured = env.DSH_PI_TUI_LOG;
|
|
299
|
+
if (configured === "off" || configured === "") return { kind: "disabled" };
|
|
300
|
+
let directory;
|
|
301
|
+
try {
|
|
302
|
+
directory = prepareDiagnosticDirectory(env);
|
|
303
|
+
} catch (ioError) {
|
|
304
|
+
return {
|
|
305
|
+
kind: "unavailable",
|
|
306
|
+
errno: controlledErrno(ioError)
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
const fileName = `startup-${randomUUID()}.log`;
|
|
310
|
+
const target = join(directory, fileName);
|
|
311
|
+
let fd;
|
|
312
|
+
let created = false;
|
|
313
|
+
try {
|
|
314
|
+
fd = openSync(target, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 384);
|
|
315
|
+
created = true;
|
|
316
|
+
let info = fstatSync(fd);
|
|
317
|
+
if (!info.isFile()) throw new DiagnosticWriteRefusal("EPERM");
|
|
318
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
319
|
+
if (uid !== void 0 && info.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
320
|
+
if ((info.mode & 511) !== 384) {
|
|
321
|
+
fchmodSync(fd, 384);
|
|
322
|
+
info = fstatSync(fd);
|
|
323
|
+
}
|
|
324
|
+
if (!info.isFile() || (info.mode & 511) !== 384 || uid !== void 0 && info.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
325
|
+
writeAllBytes(fd, clientFatalErrorDetails(error, phase).text);
|
|
326
|
+
closeSync(fd);
|
|
327
|
+
fd = void 0;
|
|
328
|
+
return {
|
|
329
|
+
kind: "written",
|
|
330
|
+
fileName
|
|
331
|
+
};
|
|
332
|
+
} catch (ioError) {
|
|
333
|
+
if (fd !== void 0) try {
|
|
334
|
+
closeSync(fd);
|
|
335
|
+
} catch {}
|
|
336
|
+
if (created) try {
|
|
337
|
+
rmSync(target, { force: true });
|
|
338
|
+
} catch {}
|
|
339
|
+
return {
|
|
340
|
+
kind: "unavailable",
|
|
341
|
+
errno: controlledErrno(ioError)
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/app/remote-process/local-workspace-equivalence.ts
|
|
347
|
+
/**
|
|
348
|
+
* The Client-local launch-cwd / Host-directory equivalence classifier
|
|
349
|
+
* (M6-1/F5-B §4.5): the ONLY evidence that may turn a Client process's own
|
|
350
|
+
* launch directory into an AUTOMATIC Host Workspace proposal.
|
|
351
|
+
*
|
|
352
|
+
* The verdict permits an AUTOMATIC host-path PROPOSAL only. It grants no Host
|
|
353
|
+
* file permission and is never a WorkspaceId: a manual Host path or
|
|
354
|
+
* WorkspaceId still goes through the official Host
|
|
355
|
+
* `workspaceController`/`workspaceRegistry`. {@link
|
|
356
|
+
* LaunchWorkspaceProof.revalidate} re-runs the SAME evidence asynchronously
|
|
357
|
+
* before a Host `workspace.create` and again before the resulting
|
|
358
|
+
* `workspaceId` is adopted.
|
|
359
|
+
*
|
|
360
|
+
* Linux uses its long-lived kernel view: the authenticated Host
|
|
361
|
+
* `/proc/<pid>/stat` starttime and `/proc/<pid>/root` directory object. macOS
|
|
362
|
+
* cannot read another process's `/proc` view, so the Host process itself
|
|
363
|
+
* answers through the Owner-only read-only workspace-object route. Both
|
|
364
|
+
* platforms require the SAME directory object the Client started in — a path
|
|
365
|
+
* spelling alone is never evidence — and a failed/unverifiable observation
|
|
366
|
+
* only means the user must choose a Host Workspace through the existing
|
|
367
|
+
* Browser.
|
|
368
|
+
*
|
|
369
|
+
* @module @xmoon76/dsh-pi-tui/app/remote-process/local-workspace-equivalence
|
|
370
|
+
*/
|
|
371
|
+
/** The Linux `starttime` of one PID, read through the shared official parser
|
|
372
|
+
* (the `procRoot` seam exists only for the fail-closed contract tests). */
|
|
373
|
+
function readProcessStarttimeAt(pid, procRoot = "/proc") {
|
|
374
|
+
try {
|
|
375
|
+
return parseProcessStatStarttime(readFileSync(join(procRoot, String(pid), "stat"), "utf8"));
|
|
376
|
+
} catch {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/** One real directory object as exact decimal strings. */
|
|
381
|
+
function statDirectoryObject(path) {
|
|
382
|
+
try {
|
|
383
|
+
const stat = statSync(path, { bigint: true });
|
|
384
|
+
if (!stat.isDirectory()) return void 0;
|
|
385
|
+
return {
|
|
386
|
+
device: stat.dev.toString(),
|
|
387
|
+
inode: stat.ino.toString()
|
|
388
|
+
};
|
|
389
|
+
} catch {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Classify whether this Client's launch directory is the SAME directory object
|
|
395
|
+
* the authenticated Host process sees at that pathname. Never throws: every
|
|
396
|
+
* unreadable fact is an `unverified` verdict with its reason.
|
|
397
|
+
*/
|
|
398
|
+
async function classifyLaunchWorkspace(identity, launchCwd, options = {}) {
|
|
399
|
+
const platform = options.platform ?? process.platform;
|
|
400
|
+
if (identity === void 0) return {
|
|
401
|
+
kind: "unverified",
|
|
402
|
+
reason: "the local Host identity is unavailable"
|
|
403
|
+
};
|
|
404
|
+
if (platform === "darwin") return await classifyDarwinLaunchWorkspace(identity, launchCwd, options);
|
|
405
|
+
if (platform !== "linux") return {
|
|
406
|
+
kind: "unverified",
|
|
407
|
+
reason: "the Host/Client directory equivalence check is only available on Linux and macOS"
|
|
408
|
+
};
|
|
409
|
+
if (identity.schema !== 1) return {
|
|
410
|
+
kind: "unverified",
|
|
411
|
+
reason: "the Host publication is not a Linux schema 1 record"
|
|
412
|
+
};
|
|
413
|
+
return classifyLinuxLaunchWorkspace(identity, launchCwd, options);
|
|
414
|
+
}
|
|
415
|
+
/** The frozen Linux proof: `/proc` starttime plus `/proc/<pid>/root`. */
|
|
416
|
+
function classifyLinuxLaunchWorkspace(identity, launchCwd, options) {
|
|
417
|
+
const procRoot = options.procRoot ?? "/proc";
|
|
418
|
+
const readStarttime = options.readStarttime ?? readProcessStarttimeAt;
|
|
419
|
+
if (identity.hostPid < 1 || identity.hostStarttime === "") return {
|
|
420
|
+
kind: "unverified",
|
|
421
|
+
reason: "the authenticated Host identity is incomplete"
|
|
422
|
+
};
|
|
423
|
+
const observedStarttime = readStarttime(identity.hostPid, procRoot);
|
|
424
|
+
if (observedStarttime === void 0) return {
|
|
425
|
+
kind: "unverified",
|
|
426
|
+
reason: `the Host process /proc/${String(identity.hostPid)}/stat is not readable`
|
|
427
|
+
};
|
|
428
|
+
if (observedStarttime !== identity.hostStarttime) return {
|
|
429
|
+
kind: "unverified",
|
|
430
|
+
reason: "the Host process starttime no longer matches the authenticated identity"
|
|
431
|
+
};
|
|
432
|
+
const launchObject = options.launchObject ?? statDirectoryObject(".");
|
|
433
|
+
if (launchObject === void 0) return {
|
|
434
|
+
kind: "unverified",
|
|
435
|
+
reason: "the Client launch object cannot be inspected"
|
|
436
|
+
};
|
|
437
|
+
const client = statDirectoryObject(launchCwd);
|
|
438
|
+
if (client === void 0) return {
|
|
439
|
+
kind: "unverified",
|
|
440
|
+
reason: "the Client launch directory cannot be inspected"
|
|
441
|
+
};
|
|
442
|
+
if (client.device !== launchObject.device || client.inode !== launchObject.inode) return {
|
|
443
|
+
kind: "unverified",
|
|
444
|
+
reason: "the launch path no longer names the directory the Client started in (renamed or recreated)"
|
|
445
|
+
};
|
|
446
|
+
try {
|
|
447
|
+
const hostView = statSync(join(procRoot, String(identity.hostPid), "root", launchCwd), { bigint: true });
|
|
448
|
+
if (!hostView.isDirectory()) return {
|
|
449
|
+
kind: "unverified",
|
|
450
|
+
reason: "the Host view of the launch path is not a directory"
|
|
451
|
+
};
|
|
452
|
+
if (hostView.dev.toString() !== client.device || hostView.ino.toString() !== client.inode) return {
|
|
453
|
+
kind: "unverified",
|
|
454
|
+
reason: "the Client and Host see different directory objects at the launch path"
|
|
455
|
+
};
|
|
456
|
+
} catch {
|
|
457
|
+
return {
|
|
458
|
+
kind: "unverified",
|
|
459
|
+
reason: "the Host view of the launch path cannot be inspected"
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
if (readStarttime(identity.hostPid, procRoot) !== identity.hostStarttime) return {
|
|
463
|
+
kind: "unverified",
|
|
464
|
+
reason: "the Host process changed while the launch directory was compared"
|
|
465
|
+
};
|
|
466
|
+
const revalidate = async () => {
|
|
467
|
+
if (readStarttime(identity.hostPid, procRoot) !== identity.hostStarttime) return false;
|
|
468
|
+
const now = statDirectoryObject(launchCwd);
|
|
469
|
+
if (now === void 0 || now.device !== launchObject.device || now.inode !== launchObject.inode) return false;
|
|
470
|
+
try {
|
|
471
|
+
const hostView = statSync(join(procRoot, String(identity.hostPid), "root", launchCwd), { bigint: true });
|
|
472
|
+
if (!hostView.isDirectory() || hostView.dev.toString() !== launchObject.device || hostView.ino.toString() !== launchObject.inode) return false;
|
|
473
|
+
} catch {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
return readStarttime(identity.hostPid, procRoot) === identity.hostStarttime;
|
|
477
|
+
};
|
|
478
|
+
return {
|
|
479
|
+
kind: "verified",
|
|
480
|
+
launchCwd,
|
|
481
|
+
instanceId: identity.instanceId,
|
|
482
|
+
hostPid: identity.hostPid,
|
|
483
|
+
device: launchObject.device,
|
|
484
|
+
inode: launchObject.inode,
|
|
485
|
+
revalidate
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* The macOS proof: the Host itself stats the same absolute path through the
|
|
490
|
+
* Owner-only route, and BOTH the kernel identity and the official Connection
|
|
491
|
+
* generation must be unchanged before and after the observation.
|
|
492
|
+
*/
|
|
493
|
+
async function classifyDarwinLaunchWorkspace(identity, launchCwd, options) {
|
|
494
|
+
if (identity.schema !== 2) return {
|
|
495
|
+
kind: "unverified",
|
|
496
|
+
reason: "the Host publication is not a macOS schema 2 record"
|
|
497
|
+
};
|
|
498
|
+
if (identity.hostPid < 1) return {
|
|
499
|
+
kind: "unverified",
|
|
500
|
+
reason: "the authenticated Host identity is incomplete"
|
|
501
|
+
};
|
|
502
|
+
const transport = options.transport;
|
|
503
|
+
if (transport === void 0) return {
|
|
504
|
+
kind: "unverified",
|
|
505
|
+
reason: "the authenticated Host transport is unavailable"
|
|
506
|
+
};
|
|
507
|
+
const scope = options.scope;
|
|
508
|
+
const readRecord = options.readRecord ?? readLocalRecord;
|
|
509
|
+
if (scope === void 0) return {
|
|
510
|
+
kind: "unverified",
|
|
511
|
+
reason: "the official local scope is unavailable"
|
|
512
|
+
};
|
|
513
|
+
const readKernel = options.readKernel ?? readKernelProcess;
|
|
514
|
+
const generation = transport.status();
|
|
515
|
+
if (generation.transport !== "connected" || generation.generationId === void 0) return {
|
|
516
|
+
kind: "unverified",
|
|
517
|
+
reason: "the official Host Connection generation is not ready"
|
|
518
|
+
};
|
|
519
|
+
const capturedGeneration = generation.generationId;
|
|
520
|
+
if (!recordIsCurrent(identity, readKernel, readRecord, scope)) return {
|
|
521
|
+
kind: "unverified",
|
|
522
|
+
reason: "the current Host publication does not match the authenticated identity"
|
|
523
|
+
};
|
|
524
|
+
const launchObject = options.launchObject ?? statDirectoryObject(".");
|
|
525
|
+
if (launchObject === void 0) return {
|
|
526
|
+
kind: "unverified",
|
|
527
|
+
reason: "the Client launch object cannot be inspected"
|
|
528
|
+
};
|
|
529
|
+
const client = statDirectoryObject(launchCwd);
|
|
530
|
+
if (client === void 0) return {
|
|
531
|
+
kind: "unverified",
|
|
532
|
+
reason: "the Client launch directory cannot be inspected"
|
|
533
|
+
};
|
|
534
|
+
if (client.device !== launchObject.device || client.inode !== launchObject.inode) return {
|
|
535
|
+
kind: "unverified",
|
|
536
|
+
reason: "the launch path no longer names the directory the Client started in (renamed or recreated)"
|
|
537
|
+
};
|
|
538
|
+
if (Boolean(options.signal?.aborted)) return {
|
|
539
|
+
kind: "unverified",
|
|
540
|
+
reason: "the Host workspace object observation was aborted"
|
|
541
|
+
};
|
|
542
|
+
const hostObject = await observeHostWorkspaceObject((input, init) => transport.authenticatedFetch(input, init), identity.origin, identity.instanceId, launchCwd, options.signal);
|
|
543
|
+
if (Boolean(options.signal?.aborted)) return {
|
|
544
|
+
kind: "unverified",
|
|
545
|
+
reason: "the Host workspace object observation was aborted"
|
|
546
|
+
};
|
|
547
|
+
if (hostObject.kind !== "observed") return {
|
|
548
|
+
kind: "unverified",
|
|
549
|
+
reason: hostObject.reason
|
|
550
|
+
};
|
|
551
|
+
if (hostObject.device !== client.device || hostObject.inode !== client.inode) return {
|
|
552
|
+
kind: "unverified",
|
|
553
|
+
reason: "the Client and Host see different directory objects at the launch path"
|
|
554
|
+
};
|
|
555
|
+
const clientAfter = statDirectoryObject(launchCwd);
|
|
556
|
+
if (clientAfter === void 0 || clientAfter.device !== launchObject.device || clientAfter.inode !== launchObject.inode) return {
|
|
557
|
+
kind: "unverified",
|
|
558
|
+
reason: "the launch path changed while the Host object was observed"
|
|
559
|
+
};
|
|
560
|
+
if (!recordIsCurrent(identity, readKernel, readRecord, scope) || transport.status().generationId !== capturedGeneration) return {
|
|
561
|
+
kind: "unverified",
|
|
562
|
+
reason: "the Host identity or Connection generation changed during the observation"
|
|
563
|
+
};
|
|
564
|
+
const revalidate = async (signal) => {
|
|
565
|
+
try {
|
|
566
|
+
if (Boolean(signal?.aborted)) return false;
|
|
567
|
+
const now = transport.status();
|
|
568
|
+
if (now.transport !== "connected" || now.generationId !== capturedGeneration) return false;
|
|
569
|
+
if (!recordIsCurrent(identity, readKernel, readRecord, scope)) return false;
|
|
570
|
+
const clientNow = statDirectoryObject(launchCwd);
|
|
571
|
+
if (clientNow === void 0 || clientNow.device !== launchObject.device || clientNow.inode !== launchObject.inode) return false;
|
|
572
|
+
if (Boolean(signal?.aborted)) return false;
|
|
573
|
+
const observed = await observeHostWorkspaceObject((input, init) => transport.authenticatedFetch(input, init), identity.origin, identity.instanceId, launchCwd, signal);
|
|
574
|
+
if (Boolean(signal?.aborted)) return false;
|
|
575
|
+
if (observed.kind !== "observed" || observed.device !== launchObject.device || observed.inode !== launchObject.inode) return false;
|
|
576
|
+
const clientAfter = statDirectoryObject(launchCwd);
|
|
577
|
+
if (clientAfter === void 0 || clientAfter.device !== launchObject.device || clientAfter.inode !== launchObject.inode) return false;
|
|
578
|
+
if (transport.status().generationId !== capturedGeneration) return false;
|
|
579
|
+
return recordIsCurrent(identity, readKernel, readRecord, scope);
|
|
580
|
+
} catch {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
return {
|
|
585
|
+
kind: "verified",
|
|
586
|
+
launchCwd,
|
|
587
|
+
instanceId: identity.instanceId,
|
|
588
|
+
hostPid: identity.hostPid,
|
|
589
|
+
device: launchObject.device,
|
|
590
|
+
inode: launchObject.inode,
|
|
591
|
+
revalidate
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
/** The live Host publication and kernel identity are still the authenticated
|
|
595
|
+
* ones. Any exception (unreadable registry, unknown kernel read) is `false`,
|
|
596
|
+
* never an assumed success. */
|
|
597
|
+
function recordIsCurrent(identity, readKernel, readRecord, scope) {
|
|
598
|
+
try {
|
|
599
|
+
assertRecordedHostKernelIdentityCurrent(identity, readKernel);
|
|
600
|
+
const recorded = readRecord(scope);
|
|
601
|
+
return recorded !== void 0 && sameLocalInstanceRecord(recorded, identity);
|
|
602
|
+
} catch {
|
|
603
|
+
return false;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
//#endregion
|
|
13
607
|
//#region src/app/remote-process/client-interaction-delivery.ts
|
|
14
608
|
/** Wrap a waterfall `next` so one official invocation delegates AT MOST once. */
|
|
15
609
|
function onceNext(next) {
|
|
@@ -178,8 +772,37 @@ function createSplitClientInteractionDelivery(options) {
|
|
|
178
772
|
*/
|
|
179
773
|
const presentWhenAdmissible = async (sessionId, requestSignal, invoke) => {
|
|
180
774
|
const lifetime = lifetimeOf(requestSignal);
|
|
775
|
+
/**
|
|
776
|
+
* The ROOT is gone while the official invocation is still pending: the
|
|
777
|
+
* request lifetime (or another delegate of the same invocation) still owns
|
|
778
|
+
* it. A local teardown is never a Host decision, so the disposed root stops
|
|
779
|
+
* presenting and does NOT answer with the disposal error. The request's OWN
|
|
780
|
+
* lifetime remains the authority: when it ends (the Gateway releases its
|
|
781
|
+
* delivery task through its own generation signal, which is what lets the
|
|
782
|
+
* Client's transport disposal drain), settle exactly like every other
|
|
783
|
+
* abort — the Gateway classifies by its own abort, not by a local answer.
|
|
784
|
+
* The disposed root merely stops presenting; it never wins a race.
|
|
785
|
+
*/
|
|
786
|
+
const withholdForDisposedRoot = async () => {
|
|
787
|
+
if (requestSignal !== void 0) await new Promise((_resolve, reject) => {
|
|
788
|
+
if (requestSignal.aborted) {
|
|
789
|
+
reject(abortReason(requestSignal));
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
requestSignal.addEventListener("abort", () => {
|
|
793
|
+
reject(abortReason(requestSignal));
|
|
794
|
+
}, { once: true });
|
|
795
|
+
});
|
|
796
|
+
return await new Promise(() => {});
|
|
797
|
+
};
|
|
181
798
|
for (;;) {
|
|
182
|
-
await
|
|
799
|
+
if (disposed) return await withholdForDisposedRoot();
|
|
800
|
+
try {
|
|
801
|
+
await waitForAdmission(sessionId, lifetime);
|
|
802
|
+
} catch (error) {
|
|
803
|
+
if (disposed) return await withholdForDisposedRoot();
|
|
804
|
+
throw error;
|
|
805
|
+
}
|
|
183
806
|
const attachment = current;
|
|
184
807
|
if (attachment === void 0) continue;
|
|
185
808
|
const hold = navigationHold;
|
|
@@ -195,6 +818,7 @@ function createSplitClientInteractionDelivery(options) {
|
|
|
195
818
|
if (lifetime.aborted) throw abortReason(lifetime);
|
|
196
819
|
if (current === attachment && navigationHold === hold && presentationEpoch === epoch && isCommittedSubject(sessionId)) return result;
|
|
197
820
|
} catch (error) {
|
|
821
|
+
if (disposed) return await withholdForDisposedRoot();
|
|
198
822
|
if (lifetime.aborted) throw abortReason(lifetime);
|
|
199
823
|
if (current === attachment && navigationHold === hold && presentationEpoch === epoch && isCommittedSubject(sessionId)) throw error;
|
|
200
824
|
}
|
|
@@ -398,6 +1022,28 @@ function createLocalClientSurfaceBridge(stop) {
|
|
|
398
1022
|
*
|
|
399
1023
|
* @module app/remote-process/local-client-entry
|
|
400
1024
|
*/
|
|
1025
|
+
/**
|
|
1026
|
+
* The Client process's OWN launch directory, captured ONCE at module start.
|
|
1027
|
+
* A later `process.cwd()` change (a shell builtin, a plugin) is not the launch
|
|
1028
|
+
* fact, so the automatic Workspace classifier never follows drift.
|
|
1029
|
+
*/
|
|
1030
|
+
const CLIENT_LAUNCH_CWD = process.cwd();
|
|
1031
|
+
/** The DIRECTORY OBJECT the Client started in, captured at the same instant as
|
|
1032
|
+
* `CLIENT_LAUNCH_CWD`. A later rename+recreation of the path must not be
|
|
1033
|
+
* mistaken for the launch directory (external review EXT-P1). An unreadable
|
|
1034
|
+
* capture stays `undefined`; the classifier then falls back to its own real
|
|
1035
|
+
* `stat('.')` object and still fails closed. */
|
|
1036
|
+
const CLIENT_LAUNCH_OBJECT = (() => {
|
|
1037
|
+
try {
|
|
1038
|
+
const stat = statSync(".", { bigint: true });
|
|
1039
|
+
return stat.isDirectory() ? {
|
|
1040
|
+
device: stat.dev.toString(),
|
|
1041
|
+
inode: stat.ino.toString()
|
|
1042
|
+
} : void 0;
|
|
1043
|
+
} catch {
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
})();
|
|
401
1047
|
/** Load the published DSH modules this entry needs, from the installation anchor. */
|
|
402
1048
|
async function loadOfficialClientHost(anchor) {
|
|
403
1049
|
const requireFromDsh = createRequire(realpathSync(anchor));
|
|
@@ -416,20 +1062,29 @@ async function loadOfficialClientHost(anchor) {
|
|
|
416
1062
|
resolveProfileDir: appBoot.resolveProfileDir
|
|
417
1063
|
};
|
|
418
1064
|
}
|
|
419
|
-
/** Project the authenticated record without the profile path or cookie.
|
|
1065
|
+
/** Project the authenticated record without the profile path or cookie. The
|
|
1066
|
+
* schema-specific identity is projected explicitly; no field is read from the
|
|
1067
|
+
* other schema's shape. */
|
|
420
1068
|
function hostRecordForTrace(host) {
|
|
421
1069
|
const record = host.identity;
|
|
422
|
-
|
|
1070
|
+
const shared = {
|
|
1071
|
+
schema: record.schema,
|
|
423
1072
|
scopeId: record.scopeId,
|
|
424
1073
|
instanceId: record.instanceId,
|
|
425
1074
|
hostPid: record.hostPid,
|
|
426
|
-
hostStarttime: record.hostStarttime,
|
|
427
1075
|
origin: record.origin,
|
|
428
1076
|
protocol: record.protocol,
|
|
429
1077
|
bundleVersion: record.bundleVersion,
|
|
430
1078
|
dshVersion: record.dshVersion,
|
|
431
1079
|
buildId: record.buildId
|
|
432
1080
|
};
|
|
1081
|
+
return record.schema === 1 ? {
|
|
1082
|
+
...shared,
|
|
1083
|
+
hostStarttime: record.hostStarttime
|
|
1084
|
+
} : {
|
|
1085
|
+
...shared,
|
|
1086
|
+
hostKernelIdentity: record.hostKernelIdentity
|
|
1087
|
+
};
|
|
433
1088
|
}
|
|
434
1089
|
/**
|
|
435
1090
|
* The surface-mode telemetry sink: an owner-managed `0600` absolute JSONL file
|
|
@@ -440,7 +1095,7 @@ function hostRecordForTrace(host) {
|
|
|
440
1095
|
*/
|
|
441
1096
|
function createSurfaceRecordSink() {
|
|
442
1097
|
const target = process.env.SPLIT_PROCESS_CLIENT_RECORD_FILE;
|
|
443
|
-
if (target === void 0 || target === "")
|
|
1098
|
+
if (target === void 0 || target === "") return void 0;
|
|
444
1099
|
if (!isAbsolute(target)) throw new Error("local client entry: the surface record file path must be absolute");
|
|
445
1100
|
const directory = realpathSync(dirname(target));
|
|
446
1101
|
const directoryStats = statSync(directory);
|
|
@@ -463,17 +1118,88 @@ function createSurfaceRecordSink() {
|
|
|
463
1118
|
}
|
|
464
1119
|
};
|
|
465
1120
|
}
|
|
1121
|
+
/** The private v1 public-launch data channel (M6-2A). Carries ONLY the public
|
|
1122
|
+
* `sessionLaunch`/`presetId` intent from the daemon Coordinator; it never
|
|
1123
|
+
* carries a token, Host URL, Profile secret or exact Session id. */
|
|
1124
|
+
const CLIENT_LAUNCH_ENVELOPE_ENV = "SPLIT_PROCESS_CLIENT_LAUNCH_V1";
|
|
1125
|
+
/** A hard ceiling on the decoded envelope size (plan §A4.1: 16 KiB). */
|
|
1126
|
+
const MAX_CLIENT_LAUNCH_ENVELOPE_BYTES = 16384;
|
|
1127
|
+
/** Decode ONE public launch intent, strictly: exactly the known keys, a browse
|
|
1128
|
+
* with an empty query, or a lookup with a non-empty query, or a continue with
|
|
1129
|
+
* no query. Every other shape fails closed before the Host is ensured. */
|
|
1130
|
+
function decodeLaunchIntent(value) {
|
|
1131
|
+
if (!isRecord(value)) throw new Error("local client entry: the launch envelope sessionLaunch must be an object");
|
|
1132
|
+
const keys = Object.keys(value).sort();
|
|
1133
|
+
if (value.kind === "browse") {
|
|
1134
|
+
if (keys.length !== 2 || value.query !== "") throw new Error("local client entry: a browse launch is exactly { kind: \"browse\", query: \"\" }");
|
|
1135
|
+
return {
|
|
1136
|
+
kind: "browse",
|
|
1137
|
+
query: ""
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
if (value.kind === "lookup") {
|
|
1141
|
+
if (keys.length !== 2 || typeof value.query !== "string" || value.query.trim() === "") throw new Error("local client entry: a lookup launch needs exactly a non-empty \"query\"");
|
|
1142
|
+
return {
|
|
1143
|
+
kind: "lookup",
|
|
1144
|
+
query: value.query.trim()
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
if (value.kind === "continue") {
|
|
1148
|
+
if (keys.length !== 1) throw new Error("local client entry: a continue launch carries no query");
|
|
1149
|
+
return { kind: "continue" };
|
|
1150
|
+
}
|
|
1151
|
+
throw new Error("local client entry: unknown launch envelope sessionLaunch kind");
|
|
1152
|
+
}
|
|
1153
|
+
/** Decode the raw envelope: bounded, valid JSON, exactly the known keys, and a
|
|
1154
|
+
* validated public intent. `version` is frozen at 1. */
|
|
1155
|
+
function decodeClientLaunchEnvelope(raw) {
|
|
1156
|
+
if (Buffer.byteLength(raw, "utf8") > MAX_CLIENT_LAUNCH_ENVELOPE_BYTES) throw new Error("local client entry: the launch envelope exceeds 16 KiB");
|
|
1157
|
+
let parsed;
|
|
1158
|
+
try {
|
|
1159
|
+
parsed = JSON.parse(raw);
|
|
1160
|
+
} catch (error) {
|
|
1161
|
+
throw new Error("local client entry: the launch envelope is not valid JSON", { cause: error });
|
|
1162
|
+
}
|
|
1163
|
+
if (!isRecord(parsed)) throw new Error("local client entry: the launch envelope must be a JSON object");
|
|
1164
|
+
for (const key of Object.keys(parsed)) if (key !== "version" && key !== "sessionLaunch" && key !== "presetId" && key !== "backendSource") throw new Error(`local client entry: unexpected launch envelope key ${JSON.stringify(key)}`);
|
|
1165
|
+
if (parsed.version !== 1) throw new Error("local client entry: the launch envelope version must be 1");
|
|
1166
|
+
const envelope = {};
|
|
1167
|
+
if ("sessionLaunch" in parsed) envelope.sessionLaunch = decodeLaunchIntent(parsed.sessionLaunch);
|
|
1168
|
+
if ("backendSource" in parsed) {
|
|
1169
|
+
const bs = parsed.backendSource;
|
|
1170
|
+
if (!isRecord(bs) || bs.value !== "direct" && bs.value !== "daemon" || bs.source !== "env" && bs.source !== "profile") throw new Error("local client entry: the launch envelope backendSource must be { value: \"direct\"|\"daemon\", source: \"env\"|\"profile\" }");
|
|
1171
|
+
envelope.backendSource = {
|
|
1172
|
+
value: bs.value,
|
|
1173
|
+
source: bs.source
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
if ("presetId" in parsed) {
|
|
1177
|
+
if (typeof parsed.presetId !== "string" || parsed.presetId.trim() === "") throw new Error("local client entry: the launch envelope presetId must be a non-empty string");
|
|
1178
|
+
envelope.presetId = parsed.presetId;
|
|
1179
|
+
}
|
|
1180
|
+
return envelope;
|
|
1181
|
+
}
|
|
1182
|
+
/** Read and decode the envelope when it is present; absent otherwise. */
|
|
1183
|
+
function readClientLaunchEnvelope() {
|
|
1184
|
+
const raw = process.env[CLIENT_LAUNCH_ENVELOPE_ENV];
|
|
1185
|
+
return raw === void 0 ? void 0 : decodeClientLaunchEnvelope(raw);
|
|
1186
|
+
}
|
|
466
1187
|
/** The surface-mode startup intent: an explicit internal input, never a
|
|
467
|
-
* control-channel override of published behavior.
|
|
468
|
-
|
|
1188
|
+
* control-channel override of published behavior. The public envelope and the
|
|
1189
|
+
* internal exact `SPLIT_PROCESS_CLIENT_SESSION` channel are mutually exclusive;
|
|
1190
|
+
* the exact channel is what reexec and qualification use. */
|
|
1191
|
+
function surfaceStartupFacts(options, envelope) {
|
|
469
1192
|
const sessionId = process.env.SPLIT_PROCESS_CLIENT_SESSION;
|
|
470
1193
|
const presetId = process.env.SPLIT_PROCESS_CLIENT_PRESET;
|
|
471
1194
|
if (options.mode !== "surface") return {};
|
|
472
1195
|
if (sessionId !== void 0 && sessionId.trim() === "") throw new Error("local client entry: SPLIT_PROCESS_CLIENT_SESSION must be non-empty when set");
|
|
473
1196
|
if (presetId !== void 0 && presetId.trim() === "") throw new Error("local client entry: SPLIT_PROCESS_CLIENT_PRESET must be non-empty when set");
|
|
1197
|
+
if (envelope !== void 0 && sessionId !== void 0) throw new Error("local client entry: the public launch envelope is mutually exclusive with the internal exact Session channel");
|
|
1198
|
+
const effectivePreset = envelope?.presetId !== void 0 ? envelope.presetId : presetId === void 0 || presetId === "" ? void 0 : presetId;
|
|
474
1199
|
return {
|
|
475
1200
|
...sessionId === void 0 || sessionId === "" ? {} : { sessionId },
|
|
476
|
-
...
|
|
1201
|
+
...effectivePreset === void 0 ? {} : { presetId: effectivePreset },
|
|
1202
|
+
...envelope?.sessionLaunch === void 0 ? {} : { sessionLaunch: envelope.sessionLaunch }
|
|
477
1203
|
};
|
|
478
1204
|
}
|
|
479
1205
|
/** The single internal Loader builtin name of the interaction startup gate. */
|
|
@@ -500,16 +1226,63 @@ const OLD_CLIENT_ENVIRONMENT = [
|
|
|
500
1226
|
"SPLIT_PROCESS_CLIENT_HOLD_ASSEMBLY",
|
|
501
1227
|
"SPLIT_PROCESS_CLIENT_HOLD_BEFORE_START",
|
|
502
1228
|
"SPLIT_PROCESS_CLIENT_HOLD_STARTUP_GATE",
|
|
1229
|
+
"SPLIT_PROCESS_CLIENT_EXTENSION_CONFIG_PROBE",
|
|
1230
|
+
"SPLIT_PROCESS_CLIENT_EXTENSION_CONFIG_PACKAGES",
|
|
1231
|
+
"SPLIT_PROCESS_CLIENT_EXTENSION_LOADER_PROBE",
|
|
1232
|
+
"SPLIT_PROCESS_CLIENT_EXTENSION_LOADER_PACKAGES",
|
|
1233
|
+
"SPLIT_PROCESS_CLIENT_EXTENSION_LOADER_KEEP_BYTES",
|
|
1234
|
+
"SPLIT_PROCESS_CLIENT_EXTENSION_LOADER_NOTICE_PROBE",
|
|
503
1235
|
"SPLIT_PROCESS_CLIENT_FORCE_FAILURE",
|
|
504
1236
|
"SPLIT_PROCESS_CLIENT_FORCE_STARTUP_FATAL",
|
|
505
1237
|
"SPLIT_PROCESS_CLIENT_FORCE_REFRESH_UNRESPONSIVE_ONCE",
|
|
506
1238
|
"SPLIT_PROCESS_CLIENT_DROP_PROMPT_ACK",
|
|
1239
|
+
"SPLIT_PROCESS_CLIENT_DROP_MODEL_ACK",
|
|
507
1240
|
"SPLIT_PROCESS_CLIENT_OMIT_COOKIE",
|
|
508
1241
|
"SPLIT_PROCESS_CLIENT_WORKSPACE_INTENT_PATH"
|
|
509
1242
|
];
|
|
510
1243
|
function failureMessage(error) {
|
|
511
1244
|
return error instanceof Error ? error.message : String(error);
|
|
512
1245
|
}
|
|
1246
|
+
/** Observe Error identity without a hostile Proxy `getPrototypeOf` trap escaping. */
|
|
1247
|
+
function isErrorValue(value) {
|
|
1248
|
+
try {
|
|
1249
|
+
return value instanceof Error;
|
|
1250
|
+
} catch {
|
|
1251
|
+
return false;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
/** Observe LocalScopeError identity through the same safe boundary. */
|
|
1255
|
+
function isLocalScopeErrorValue(value) {
|
|
1256
|
+
try {
|
|
1257
|
+
return value instanceof LocalScopeError;
|
|
1258
|
+
} catch {
|
|
1259
|
+
return false;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Merge the stop coordinator's cleanup errors into the ONE primary error that
|
|
1264
|
+
* the incident file records. The terminal classification keeps the original
|
|
1265
|
+
* failure; only the artifact needs the cleanup cause chain.
|
|
1266
|
+
*/
|
|
1267
|
+
function clientFatalPrimaryWithCleanup(failure, cleanupErrors) {
|
|
1268
|
+
const primary = isErrorValue(failure) ? failure : new Error(safeErrorMessage(failure));
|
|
1269
|
+
if (cleanupErrors.length === 0) return primary;
|
|
1270
|
+
try {
|
|
1271
|
+
let merged = primary;
|
|
1272
|
+
for (const cleanupError of cleanupErrors) merged = mergeCause(merged, cleanupError);
|
|
1273
|
+
return merged;
|
|
1274
|
+
} catch {
|
|
1275
|
+
const root = new Error(safeErrorMessage(failure));
|
|
1276
|
+
if (isErrorValue(failure)) try {
|
|
1277
|
+
root.name = failure.name;
|
|
1278
|
+
root.stack = failure.stack;
|
|
1279
|
+
const code = failure.code;
|
|
1280
|
+
if (typeof code === "string") root.code = code;
|
|
1281
|
+
} catch {}
|
|
1282
|
+
root.cause = new AggregateError([failure, ...cleanupErrors], "local client entry: fatal failure with cleanup causes");
|
|
1283
|
+
return root;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
513
1286
|
function isRecord(value) {
|
|
514
1287
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
515
1288
|
}
|
|
@@ -526,10 +1299,7 @@ function inspectClientReexecTarget(packageRoot, dshVersion) {
|
|
|
526
1299
|
} catch (error) {
|
|
527
1300
|
throw new Error("local client reexec: the target package root is not readable", { cause: error });
|
|
528
1301
|
}
|
|
529
|
-
|
|
530
|
-
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
531
|
-
if (!rootInfo.isDirectory()) throw new Error("local client reexec: the target package root is not a directory");
|
|
532
|
-
if (uid !== void 0 && rootInfo.uid !== uid) throw new Error("local client reexec: the target package root is not owned by this process user");
|
|
1302
|
+
if (!lstatSync(root).isDirectory()) throw new Error("local client reexec: the target package root is not a directory");
|
|
533
1303
|
let manifest;
|
|
534
1304
|
try {
|
|
535
1305
|
manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
@@ -541,13 +1311,20 @@ function inspectClientReexecTarget(packageRoot, dshVersion) {
|
|
|
541
1311
|
const devDependencies = manifest.devDependencies;
|
|
542
1312
|
if (!isRecord(devDependencies) || devDependencies[DSH_PIN_PACKAGE] !== dshVersion) throw new Error("local client reexec: the target package is pinned to a different DSH runtime");
|
|
543
1313
|
const entry = join(root, "dist", "local-client.mjs");
|
|
544
|
-
let
|
|
1314
|
+
let realEntry;
|
|
545
1315
|
try {
|
|
546
|
-
|
|
1316
|
+
realEntry = realpathSync(entry);
|
|
547
1317
|
} catch (error) {
|
|
548
1318
|
throw new Error("local client reexec: the target package has no Client entry", { cause: error });
|
|
549
1319
|
}
|
|
550
|
-
if (
|
|
1320
|
+
if (!lstatSync(realEntry).isFile()) throw new Error("local client reexec: the target Client entry must resolve to a regular file");
|
|
1321
|
+
let entryRoot;
|
|
1322
|
+
try {
|
|
1323
|
+
entryRoot = installedPackageRootFromEntry(pathToFileURL(entry).href);
|
|
1324
|
+
} catch (error) {
|
|
1325
|
+
throw new Error("local client reexec: the target Client entry cannot locate its installed package root", { cause: error });
|
|
1326
|
+
}
|
|
1327
|
+
if (entryRoot !== root) throw new Error("local client reexec: the target Client entry resolves a different installed package root");
|
|
551
1328
|
return {
|
|
552
1329
|
packageRoot: root,
|
|
553
1330
|
entry,
|
|
@@ -694,6 +1471,7 @@ function createClientReexecChildEnvironment(intent, source = process.env) {
|
|
|
694
1471
|
const injectedFailure = source.SPLIT_PROCESS_CLIENT_REEXEC_CHILD_FAILURE;
|
|
695
1472
|
for (const name of OLD_CLIENT_ENVIRONMENT) delete env[name];
|
|
696
1473
|
delete env.SPLIT_PROCESS_CLIENT_PRESET;
|
|
1474
|
+
delete env.SPLIT_PROCESS_CLIENT_LAUNCH_V1;
|
|
697
1475
|
env.SPLIT_PROCESS_CLIENT_MODE = "surface";
|
|
698
1476
|
env.SPLIT_PROCESS_CLIENT_EXPECTED_INSTANCE_ID = intent.expectedInstanceId;
|
|
699
1477
|
env.SPLIT_PROCESS_DSH_ANCHOR = intent.dshAnchor;
|
|
@@ -1038,28 +1816,46 @@ function observeQualificationSocket(socket, emit) {
|
|
|
1038
1816
|
async function runLocalClientEntry(options) {
|
|
1039
1817
|
const expectedHostInstanceId = expectedHostInstanceFromEnvironment(options.mode);
|
|
1040
1818
|
assertHandoffSignalExclusivity(options.mode, expectedHostInstanceId);
|
|
1819
|
+
const launchEnvelope = options.mode === "surface" ? readClientLaunchEnvelope() : void 0;
|
|
1820
|
+
if (launchEnvelope !== void 0 && process.env.SPLIT_PROCESS_CLIENT_SESSION !== void 0) throw new Error("local client entry: the public launch envelope is mutually exclusive with the internal exact Session channel");
|
|
1821
|
+
if (launchEnvelope?.backendSource !== void 0) process.env.SPLIT_PROCESS_CLIENT_LAUNCH_BACKEND = JSON.stringify(launchEnvelope.backendSource);
|
|
1041
1822
|
const hostModules = await loadOfficialClientHost(options.dshAnchor);
|
|
1042
1823
|
const dshHome = hostModules.resolveDshHome();
|
|
1043
|
-
const
|
|
1824
|
+
const invokedEntry = process.argv[1];
|
|
1825
|
+
const packageRoot = installedPackageRootFromEntry(invokedEntry === void 0 ? import.meta.url : pathToFileURL(invokedEntry).href);
|
|
1044
1826
|
const profileDir = hostModules.resolveProfileDir(options.profile, dshHome);
|
|
1827
|
+
const installedDshVersion = readInstalledDshVersion(options.dshAnchor);
|
|
1045
1828
|
const scope = scopeFromInstalledProfile({
|
|
1046
1829
|
dshHome,
|
|
1047
1830
|
profileDir,
|
|
1048
1831
|
packageRoot,
|
|
1049
|
-
dshVersion:
|
|
1832
|
+
dshVersion: installedDshVersion
|
|
1050
1833
|
});
|
|
1051
|
-
const
|
|
1834
|
+
const daemonAdminProfile = {
|
|
1835
|
+
name: options.profile,
|
|
1836
|
+
dir: profileDir,
|
|
1837
|
+
home: dshHome,
|
|
1838
|
+
installAnchor: options.dshAnchor,
|
|
1839
|
+
packageRoot,
|
|
1840
|
+
dshVersion: installedDshVersion
|
|
1841
|
+
};
|
|
1842
|
+
const profileDaemonAdmin = createProfileDaemonAdmin(daemonAdminProfile, { run: profileDaemonAdminRun(daemonAdminProfile) });
|
|
1843
|
+
const processStartIdentity = readProcessStartDiagnostic();
|
|
1052
1844
|
const recordSink = options.mode === "surface" ? createSurfaceRecordSink() : void 0;
|
|
1053
|
-
const emit = recordSink?.emit ?? writeEntryRecord;
|
|
1845
|
+
const emit = recordSink?.emit ?? (options.mode === "surface" ? () => {} : writeEntryRecord);
|
|
1054
1846
|
emit({
|
|
1055
1847
|
m4a0: "client-started",
|
|
1056
1848
|
processRole: "client",
|
|
1057
1849
|
pid: process.pid,
|
|
1058
1850
|
phase: "startup"
|
|
1059
1851
|
});
|
|
1060
|
-
const seat = options.mode === "qualification" ? await
|
|
1852
|
+
const seat = options.mode === "qualification" ? await bindProfileKernelSeat(scope, "qualification-client", "CLIENT_ALREADY_ACTIVE") : NO_PROCESS_SEAT;
|
|
1061
1853
|
let context;
|
|
1062
1854
|
let loaderFiber;
|
|
1855
|
+
/** The SAME official Loader installed below (surface/peer modes only). */
|
|
1856
|
+
let clientLoader;
|
|
1857
|
+
/** The SAME official `PluginPackages` service this Client process resolved. */
|
|
1858
|
+
let clientPluginPackages;
|
|
1063
1859
|
let startupGate;
|
|
1064
1860
|
let installedTransport;
|
|
1065
1861
|
let transport;
|
|
@@ -1087,7 +1883,12 @@ async function runLocalClientEntry(options) {
|
|
|
1087
1883
|
revisionTask = run.then(() => {}, () => {});
|
|
1088
1884
|
return run;
|
|
1089
1885
|
};
|
|
1090
|
-
const diag = createEntryDiag("client", recordSink?.emit);
|
|
1886
|
+
const diag = createEntryDiag("client", recordSink?.emit ?? (options.mode === "surface" ? () => {} : void 0));
|
|
1887
|
+
/** Monotonic process-relative stamp for the shutdown qualification records.
|
|
1888
|
+
* Surface mode writes these ONLY to its private 0600 JSONL sink; the real
|
|
1889
|
+
* terminal never carries timing JSON. */
|
|
1890
|
+
const processStartedAt = performance.now();
|
|
1891
|
+
const elapsedMs = () => Math.round((performance.now() - processStartedAt) * 10) / 10;
|
|
1091
1892
|
const CLIENT_DISPOSE_DEADLINE_MS = 1e4;
|
|
1092
1893
|
const disposeWithinDeadline = async (dispose, errors) => {
|
|
1093
1894
|
let timer;
|
|
@@ -1133,6 +1934,13 @@ async function runLocalClientEntry(options) {
|
|
|
1133
1934
|
const stop = (code, failure) => {
|
|
1134
1935
|
if (stopping !== void 0) return stopping;
|
|
1135
1936
|
startupAbort.abort(failure ?? /* @__PURE__ */ new Error("local client entry: stop requested during startup"));
|
|
1937
|
+
emit({
|
|
1938
|
+
m4a0: "shutdown-stage",
|
|
1939
|
+
processRole: "client",
|
|
1940
|
+
phase: "requested",
|
|
1941
|
+
pid: process.pid,
|
|
1942
|
+
atMs: elapsedMs()
|
|
1943
|
+
});
|
|
1136
1944
|
stopping = (async () => {
|
|
1137
1945
|
if (failure !== void 0) {
|
|
1138
1946
|
const primary = failure instanceof Error ? failure : new Error(String(failure));
|
|
@@ -1154,12 +1962,30 @@ async function runLocalClientEntry(options) {
|
|
|
1154
1962
|
handle = await startupPromise;
|
|
1155
1963
|
} catch {}
|
|
1156
1964
|
if (handle !== void 0) {
|
|
1965
|
+
const revisionAt = performance.now();
|
|
1157
1966
|
await revisionTask;
|
|
1967
|
+
emit({
|
|
1968
|
+
m4a0: "shutdown-stage",
|
|
1969
|
+
processRole: "client",
|
|
1970
|
+
phase: "revision-drained",
|
|
1971
|
+
pid: process.pid,
|
|
1972
|
+
durationMs: Math.round((performance.now() - revisionAt) * 10) / 10,
|
|
1973
|
+
atMs: elapsedMs()
|
|
1974
|
+
});
|
|
1975
|
+
const disposeAt = performance.now();
|
|
1158
1976
|
try {
|
|
1159
1977
|
await handle.dispose();
|
|
1160
1978
|
} catch (error) {
|
|
1161
1979
|
errors.push(error);
|
|
1162
1980
|
}
|
|
1981
|
+
emit({
|
|
1982
|
+
m4a0: "shutdown-stage",
|
|
1983
|
+
processRole: "client",
|
|
1984
|
+
phase: "handle-disposed",
|
|
1985
|
+
pid: process.pid,
|
|
1986
|
+
durationMs: Math.round((performance.now() - disposeAt) * 10) / 10,
|
|
1987
|
+
atMs: elapsedMs()
|
|
1988
|
+
});
|
|
1163
1989
|
rootReleased = true;
|
|
1164
1990
|
return;
|
|
1165
1991
|
}
|
|
@@ -1201,9 +2027,18 @@ async function runLocalClientEntry(options) {
|
|
|
1201
2027
|
}
|
|
1202
2028
|
rootReleased = true;
|
|
1203
2029
|
}, errors);
|
|
2030
|
+
emit({
|
|
2031
|
+
m4a0: "shutdown-stage",
|
|
2032
|
+
processRole: "client",
|
|
2033
|
+
phase: "dispose-settled",
|
|
2034
|
+
pid: process.pid,
|
|
2035
|
+
timedOut,
|
|
2036
|
+
atMs: elapsedMs()
|
|
2037
|
+
});
|
|
1204
2038
|
if (options.mode === "surface" && handle !== void 0) emit({
|
|
1205
2039
|
m4b2s: "client-closed",
|
|
1206
|
-
...traceStatus(handle.status)
|
|
2040
|
+
...traceStatus(handle.status),
|
|
2041
|
+
atMs: elapsedMs()
|
|
1207
2042
|
});
|
|
1208
2043
|
const transportCleanupFailed = errors.some((error) => error instanceof Error && error.cleanupFailed === true);
|
|
1209
2044
|
if (errors.length > 0 || timedOut) {
|
|
@@ -1229,8 +2064,21 @@ async function runLocalClientEntry(options) {
|
|
|
1229
2064
|
process.exitCode = code;
|
|
1230
2065
|
if (code === 0 && reexecIntent !== void 0) reexecTeardownSucceeded = true;
|
|
1231
2066
|
}
|
|
2067
|
+
if (options.mode === "surface" && failure !== void 0) {
|
|
2068
|
+
const phase = handle !== void 0 ? "client-runtime" : context === void 0 ? "pre-context" : "client-assembly";
|
|
2069
|
+
process.stderr.write(`${reportStopClientFatal(failure, options.profile, phase, expectedHostInstanceId !== void 0, process.env, errors)}\n`);
|
|
2070
|
+
}
|
|
1232
2071
|
process.stdin.pause();
|
|
1233
2072
|
resolveStopped?.();
|
|
2073
|
+
emit({
|
|
2074
|
+
m4a0: "shutdown-stage",
|
|
2075
|
+
processRole: "client",
|
|
2076
|
+
phase: "cleanup-complete",
|
|
2077
|
+
pid: process.pid,
|
|
2078
|
+
atMs: elapsedMs(),
|
|
2079
|
+
failure: failure !== void 0,
|
|
2080
|
+
errors: errors.length
|
|
2081
|
+
});
|
|
1234
2082
|
if (timedOut || transportCleanupFailed) forceExitAfterCleanupFailure();
|
|
1235
2083
|
})();
|
|
1236
2084
|
return stopping;
|
|
@@ -1283,10 +2131,12 @@ async function runLocalClientEntry(options) {
|
|
|
1283
2131
|
try {
|
|
1284
2132
|
const host = await ensureLocalHost({
|
|
1285
2133
|
scope,
|
|
2134
|
+
signal: startupAbort.signal,
|
|
1286
2135
|
hostEntryPath: join(packageRoot, "dist", "local-host.mjs"),
|
|
1287
2136
|
dshAnchor: options.dshAnchor,
|
|
1288
2137
|
profile: options.profile,
|
|
1289
|
-
...expectedHostInstanceId === void 0 ? {} : { expectedInstanceId: expectedHostInstanceId }
|
|
2138
|
+
...expectedHostInstanceId === void 0 ? {} : { expectedInstanceId: expectedHostInstanceId },
|
|
2139
|
+
...options.mode === "surface" && launchEnvelope !== void 0 && expectedHostInstanceId === void 0 ? { hostStartPolicy: "public" } : {}
|
|
1290
2140
|
});
|
|
1291
2141
|
startupAbort.signal.throwIfAborted();
|
|
1292
2142
|
emit({
|
|
@@ -1303,14 +2153,15 @@ async function runLocalClientEntry(options) {
|
|
|
1303
2153
|
});
|
|
1304
2154
|
context = new hostModules.Context();
|
|
1305
2155
|
await context.plugin(hostModules.PluginPackages, { resolution });
|
|
2156
|
+
clientPluginPackages = context.get("pluginPackages");
|
|
1306
2157
|
emit({
|
|
1307
2158
|
m4a0: "context-ready",
|
|
1308
2159
|
processRole: "client",
|
|
1309
2160
|
pid: process.pid,
|
|
1310
2161
|
phase: "context-ready"
|
|
1311
2162
|
});
|
|
1312
|
-
const transportModule = await import("./local-transport-
|
|
1313
|
-
const { mountSurfaceClientDomainPrerequisites, startLocalClient } = await import("./client-bootstrap-
|
|
2163
|
+
const transportModule = await import("./local-transport-Iwo0mtu3.mjs");
|
|
2164
|
+
const { mountSurfaceClientDomainPrerequisites, startLocalClient } = await import("./client-bootstrap-BjGPc-DM.mjs");
|
|
1314
2165
|
const onTransportFatal = (error) => {
|
|
1315
2166
|
terminalError ??= error;
|
|
1316
2167
|
if (compositionDone) runDetached("local client: terminal transport identity failure", () => stop(1, terminalError), { diag });
|
|
@@ -1318,10 +2169,11 @@ async function runLocalClientEntry(options) {
|
|
|
1318
2169
|
if (options.mode === "surface" || options.mode === "peer") {
|
|
1319
2170
|
const clientContext = context;
|
|
1320
2171
|
if (clientContext === void 0) throw new Error("local client entry: the Client root Context is missing");
|
|
1321
|
-
loaderFiber = clientContext.plugin(hostModules.Loader, {});
|
|
2172
|
+
loaderFiber = clientContext.plugin(hostModules.Loader, { baseUrl: pathToFileURL(join(profileDir, "package.json")).href });
|
|
1322
2173
|
await loaderFiber;
|
|
1323
2174
|
const loader = clientContext.get("loader");
|
|
1324
2175
|
if (loader === void 0) throw new Error("local client entry: the official Cordis Loader did not install");
|
|
2176
|
+
clientLoader = loader;
|
|
1325
2177
|
startupGate = createInteractionStartupGate();
|
|
1326
2178
|
loader.builtins[INTERACTION_STARTUP_GATE] = startupGate.plugin;
|
|
1327
2179
|
await loader.create({ name: `cordis:${INTERACTION_STARTUP_GATE}` });
|
|
@@ -1344,6 +2196,12 @@ async function runLocalClientEntry(options) {
|
|
|
1344
2196
|
diag,
|
|
1345
2197
|
signal: startupAbort.signal,
|
|
1346
2198
|
onFatal: onTransportFatal,
|
|
2199
|
+
...options.mode === "surface" && process.env.SPLIT_PROCESS_CLIENT_DROP_PROMPT_ACK === "1" ? { qualificationPromptAckDropped: () => {
|
|
2200
|
+
emit({
|
|
2201
|
+
m4b2s: "qualification",
|
|
2202
|
+
op: "prompt-ack-dropped"
|
|
2203
|
+
});
|
|
2204
|
+
} } : {},
|
|
1347
2205
|
...options.mode === "peer" ? { qualificationWebSocketObserver: (_url, socket) => observeQualificationSocket(socket, emit) } : {}
|
|
1348
2206
|
});
|
|
1349
2207
|
transport = installedTransport;
|
|
@@ -1595,6 +2453,170 @@ async function runLocalClientEntry(options) {
|
|
|
1595
2453
|
});
|
|
1596
2454
|
return false;
|
|
1597
2455
|
}
|
|
2456
|
+
if (request.op === "qualification-tui-preferences") {
|
|
2457
|
+
const settings = remoteService?.settings;
|
|
2458
|
+
if (settings === void 0) throw new Error("local client entry: the qualification Peer has no settings namespace");
|
|
2459
|
+
const preferenceOf = (value) => {
|
|
2460
|
+
const entry = (value?.namespaces)?.find((candidate) => candidate.ns === "pi-tui-preferences");
|
|
2461
|
+
if (entry === void 0 || typeof entry.revision !== "number") return void 0;
|
|
2462
|
+
const plain = (input) => input !== null && typeof input === "object" && !Array.isArray(input) ? input : {};
|
|
2463
|
+
return {
|
|
2464
|
+
revision: entry.revision,
|
|
2465
|
+
value: plain(entry.value),
|
|
2466
|
+
user: plain(entry.user)
|
|
2467
|
+
};
|
|
2468
|
+
};
|
|
2469
|
+
const before = await settings.describe();
|
|
2470
|
+
const current = before.ok ? preferenceOf(before.value) : void 0;
|
|
2471
|
+
if (current === void 0) {
|
|
2472
|
+
emit({
|
|
2473
|
+
m4a0: "qualification",
|
|
2474
|
+
op: "tui-preferences",
|
|
2475
|
+
processRole: "client",
|
|
2476
|
+
pid: process.pid,
|
|
2477
|
+
ok: false,
|
|
2478
|
+
errorCode: "preferences/unavailable",
|
|
2479
|
+
...request.requestId === void 0 ? {} : { requestId: request.requestId }
|
|
2480
|
+
});
|
|
2481
|
+
return false;
|
|
2482
|
+
}
|
|
2483
|
+
if (request.tuiPreferencesField === void 0) {
|
|
2484
|
+
emit({
|
|
2485
|
+
m4a0: "qualification",
|
|
2486
|
+
op: "tui-preferences",
|
|
2487
|
+
processRole: "client",
|
|
2488
|
+
pid: process.pid,
|
|
2489
|
+
action: "read",
|
|
2490
|
+
ok: true,
|
|
2491
|
+
ns: "pi-tui-preferences",
|
|
2492
|
+
revision: current.revision,
|
|
2493
|
+
valueText: JSON.stringify(current.value),
|
|
2494
|
+
userText: JSON.stringify(current.user),
|
|
2495
|
+
...request.requestId === void 0 ? {} : { requestId: request.requestId }
|
|
2496
|
+
});
|
|
2497
|
+
return false;
|
|
2498
|
+
}
|
|
2499
|
+
if (typeof request.tuiPreferencesField !== "string" || typeof request.tuiPreferencesValue !== "string") throw new Error("local client entry: qualification-tui-preferences requires a string field/value");
|
|
2500
|
+
const write = await settings.mutate("pi-tui-preferences", [{
|
|
2501
|
+
op: "set",
|
|
2502
|
+
path: [request.tuiPreferencesField],
|
|
2503
|
+
value: request.tuiPreferencesValue
|
|
2504
|
+
}], request.tuiPreferencesRevision);
|
|
2505
|
+
const after = await settings.describe();
|
|
2506
|
+
const settled = after.ok ? preferenceOf(after.value) : void 0;
|
|
2507
|
+
emit({
|
|
2508
|
+
m4a0: "qualification",
|
|
2509
|
+
op: "tui-preferences",
|
|
2510
|
+
processRole: "client",
|
|
2511
|
+
pid: process.pid,
|
|
2512
|
+
action: "write",
|
|
2513
|
+
field: request.tuiPreferencesField,
|
|
2514
|
+
requested: request.tuiPreferencesValue,
|
|
2515
|
+
ok: write.ok === true && settled !== void 0,
|
|
2516
|
+
...settled === void 0 ? {} : {
|
|
2517
|
+
revision: settled.revision,
|
|
2518
|
+
valueText: JSON.stringify(settled.value),
|
|
2519
|
+
userText: JSON.stringify(settled.user),
|
|
2520
|
+
readBack: settled.value[request.tuiPreferencesField] === request.tuiPreferencesValue
|
|
2521
|
+
},
|
|
2522
|
+
...write.ok ? {} : {
|
|
2523
|
+
errorCode: write.error?.code,
|
|
2524
|
+
...write.error?.message === void 0 ? {} : { error: write.error.message.slice(0, 300) }
|
|
2525
|
+
},
|
|
2526
|
+
...request.requestId === void 0 ? {} : { requestId: request.requestId }
|
|
2527
|
+
});
|
|
2528
|
+
return false;
|
|
2529
|
+
}
|
|
2530
|
+
if (request.op === "qualification-acp-access") {
|
|
2531
|
+
const enabled = request.acpEnabled;
|
|
2532
|
+
const acpAccess = remoteService?.piTuiAcpAccess;
|
|
2533
|
+
if (acpAccess === void 0) throw new Error("local client entry: the qualification Peer has no piTuiAcpAccess namespace");
|
|
2534
|
+
const result = enabled === void 0 ? await acpAccess.getStatus() : await acpAccess.setEnabled(enabled);
|
|
2535
|
+
emit({
|
|
2536
|
+
m4a0: "qualification",
|
|
2537
|
+
op: "acp-access",
|
|
2538
|
+
processRole: "client",
|
|
2539
|
+
pid: process.pid,
|
|
2540
|
+
action: enabled === void 0 ? "getStatus" : "setEnabled",
|
|
2541
|
+
...enabled === void 0 ? {} : { enabled },
|
|
2542
|
+
ok: result.ok === true,
|
|
2543
|
+
...result.ok ? { status: result.value } : {
|
|
2544
|
+
errorCode: result.error?.code,
|
|
2545
|
+
...result.error?.message === void 0 ? {} : { error: result.error.message.slice(0, 300) }
|
|
2546
|
+
},
|
|
2547
|
+
...request.requestId === void 0 ? {} : { requestId: request.requestId }
|
|
2548
|
+
});
|
|
2549
|
+
return false;
|
|
2550
|
+
}
|
|
2551
|
+
if (request.op === "qualification-acp-autostart") {
|
|
2552
|
+
const settings = remoteService?.settings;
|
|
2553
|
+
if (settings === void 0) throw new Error("local client entry: the qualification Peer has no settings namespace");
|
|
2554
|
+
const preferenceOf = (value) => {
|
|
2555
|
+
const entry = (value?.namespaces)?.find((candidate) => candidate.ns === "pi-tui-acp-preferences");
|
|
2556
|
+
if (entry === void 0) return void 0;
|
|
2557
|
+
const projected = entry.value;
|
|
2558
|
+
if (typeof projected?.autoStart !== "boolean" || typeof entry.revision !== "number") return void 0;
|
|
2559
|
+
const user = entry.user;
|
|
2560
|
+
return {
|
|
2561
|
+
autoStart: projected.autoStart,
|
|
2562
|
+
revision: entry.revision,
|
|
2563
|
+
userOverridden: user?.autoStart !== void 0
|
|
2564
|
+
};
|
|
2565
|
+
};
|
|
2566
|
+
const before = await settings.describe();
|
|
2567
|
+
const current = before.ok ? preferenceOf(before.value) : void 0;
|
|
2568
|
+
if (current === void 0) {
|
|
2569
|
+
emit({
|
|
2570
|
+
m4a0: "qualification",
|
|
2571
|
+
op: "acp-autostart",
|
|
2572
|
+
processRole: "client",
|
|
2573
|
+
pid: process.pid,
|
|
2574
|
+
ok: false,
|
|
2575
|
+
errorCode: "preference/unavailable",
|
|
2576
|
+
...request.requestId === void 0 ? {} : { requestId: request.requestId }
|
|
2577
|
+
});
|
|
2578
|
+
return false;
|
|
2579
|
+
}
|
|
2580
|
+
const requested = request.acpAutoStart;
|
|
2581
|
+
if (requested === void 0) {
|
|
2582
|
+
emit({
|
|
2583
|
+
m4a0: "qualification",
|
|
2584
|
+
op: "acp-autostart",
|
|
2585
|
+
processRole: "client",
|
|
2586
|
+
pid: process.pid,
|
|
2587
|
+
action: "read",
|
|
2588
|
+
...current,
|
|
2589
|
+
ok: true,
|
|
2590
|
+
...request.requestId === void 0 ? {} : { requestId: request.requestId }
|
|
2591
|
+
});
|
|
2592
|
+
return false;
|
|
2593
|
+
}
|
|
2594
|
+
if (typeof requested !== "boolean") throw new Error("local client entry: qualification-acp-autostart requires a boolean acpAutoStart");
|
|
2595
|
+
const write = await settings.mutate("pi-tui-acp-preferences", [{
|
|
2596
|
+
op: "set",
|
|
2597
|
+
path: ["autoStart"],
|
|
2598
|
+
value: requested
|
|
2599
|
+
}], current.revision);
|
|
2600
|
+
const after = await settings.describe();
|
|
2601
|
+
const settled = after.ok ? preferenceOf(after.value) : void 0;
|
|
2602
|
+
emit({
|
|
2603
|
+
m4a0: "qualification",
|
|
2604
|
+
op: "acp-autostart",
|
|
2605
|
+
processRole: "client",
|
|
2606
|
+
pid: process.pid,
|
|
2607
|
+
action: "write",
|
|
2608
|
+
requested,
|
|
2609
|
+
ok: write.ok && settled !== void 0,
|
|
2610
|
+
...settled === void 0 ? {} : settled,
|
|
2611
|
+
readBack: settled?.autoStart === requested,
|
|
2612
|
+
...write.ok ? {} : {
|
|
2613
|
+
errorCode: write.error?.code,
|
|
2614
|
+
...write.error?.message === void 0 ? {} : { error: write.error.message.slice(0, 300) }
|
|
2615
|
+
},
|
|
2616
|
+
...request.requestId === void 0 ? {} : { requestId: request.requestId }
|
|
2617
|
+
});
|
|
2618
|
+
return false;
|
|
2619
|
+
}
|
|
1598
2620
|
if (request.op === "qualification-web-access-url") {
|
|
1599
2621
|
const webAccess = remoteService?.piTuiWebAccess;
|
|
1600
2622
|
if (webAccess === void 0) throw new Error("local client entry: the qualification Peer has no piTuiWebAccess namespace");
|
|
@@ -1685,7 +2707,7 @@ async function runLocalClientEntry(options) {
|
|
|
1685
2707
|
if (process.env.SPLIT_PROCESS_CLIENT_FORCE_FAILURE === "client-bootstrap") throw new Error("local client entry: qualification forced client bootstrap failure");
|
|
1686
2708
|
const clientContext = context;
|
|
1687
2709
|
if (clientContext === void 0) throw new Error("local client entry: the Client root Context is missing");
|
|
1688
|
-
const surfaceFacts = surfaceStartupFacts(options);
|
|
2710
|
+
const surfaceFacts = surfaceStartupFacts(options, launchEnvelope);
|
|
1689
2711
|
/**
|
|
1690
2712
|
* The ONE allowed process-composition edge into `app/bootstrap.ts`
|
|
1691
2713
|
* (architecture gate: exact lazy dynamic import, this entry only). It runs
|
|
@@ -1698,15 +2720,28 @@ async function runLocalClientEntry(options) {
|
|
|
1698
2720
|
runDetached("local client: surface exit", () => stop(code), { diag });
|
|
1699
2721
|
});
|
|
1700
2722
|
activeBridge = bridge;
|
|
1701
|
-
const { applyRunnerWithRuntime } = await import("./bootstrap-
|
|
2723
|
+
const { applyRunnerWithRuntime } = await import("./bootstrap-CMIjGyuk.mjs");
|
|
2724
|
+
const launchWorkspace = await classifyLaunchWorkspace(host.identity, CLIENT_LAUNCH_CWD, {
|
|
2725
|
+
...CLIENT_LAUNCH_OBJECT === void 0 ? {} : { launchObject: CLIENT_LAUNCH_OBJECT },
|
|
2726
|
+
scope,
|
|
2727
|
+
signal: startupAbort.signal,
|
|
2728
|
+
...transport === void 0 ? {} : { transport }
|
|
2729
|
+
});
|
|
2730
|
+
startupAbort.signal.throwIfAborted();
|
|
1702
2731
|
let runnerFiber;
|
|
1703
2732
|
try {
|
|
1704
2733
|
runnerFiber = clientContext.plugin((pluginContext) => {
|
|
1705
2734
|
applyRunnerWithRuntime(pluginContext, input.config, input.override, {
|
|
1706
2735
|
surfaceReady: () => bridge.markMounted(),
|
|
1707
2736
|
surfaceFailed: (error) => bridge.fail(error),
|
|
2737
|
+
authenticatedBuilds: {
|
|
2738
|
+
clientBuildId: scope.buildId,
|
|
2739
|
+
hostBuildId: host.identity.buildId,
|
|
2740
|
+
initialSurface: input.mountKind === "initial"
|
|
2741
|
+
},
|
|
2742
|
+
presencePeerScope: clientContext,
|
|
1708
2743
|
...reexecHandler === void 0 ? {} : { requestClientReload: () => reexecHandler.request("manual") }
|
|
1709
|
-
});
|
|
2744
|
+
}, launchWorkspace);
|
|
1710
2745
|
});
|
|
1711
2746
|
await runnerFiber;
|
|
1712
2747
|
} catch (error) {
|
|
@@ -1790,7 +2825,13 @@ async function runLocalClientEntry(options) {
|
|
|
1790
2825
|
domains: mountedDomains,
|
|
1791
2826
|
interactionDelivery,
|
|
1792
2827
|
mountRunner,
|
|
2828
|
+
profileDaemonAdmin,
|
|
1793
2829
|
diag,
|
|
2830
|
+
...clientLoader === void 0 || clientPluginPackages === void 0 ? {} : { clientExtensions: {
|
|
2831
|
+
loader: clientLoader,
|
|
2832
|
+
pluginPackages: clientPluginPackages,
|
|
2833
|
+
parentURL: import.meta.url
|
|
2834
|
+
} },
|
|
1794
2835
|
onStatus: (status) => {
|
|
1795
2836
|
emit({
|
|
1796
2837
|
m4b2s: "surface-status",
|
|
@@ -1902,7 +2943,7 @@ async function runLocalClientEntry(options) {
|
|
|
1902
2943
|
if (workspaceResume === true && workspacePath === void 0) throw new Error("local client entry: the generation-resume control requires a workspacePath");
|
|
1903
2944
|
const schedule = qualificationRequest.schedule;
|
|
1904
2945
|
if (schedule !== void 0 && schedule !== true) throw new Error("local client entry: schedule must be the boolean true when supplied");
|
|
1905
|
-
const { runHostFoundationProbe } = await import("./host-foundation-probe
|
|
2946
|
+
const { runHostFoundationProbe } = await import("./host-foundation-probe-DMNTmNrH.mjs");
|
|
1906
2947
|
const proof = await runHostFoundationProbe(context, {
|
|
1907
2948
|
dshAnchor: options.dshAnchor,
|
|
1908
2949
|
host,
|
|
@@ -1944,7 +2985,7 @@ async function runLocalClientEntry(options) {
|
|
|
1944
2985
|
return;
|
|
1945
2986
|
}
|
|
1946
2987
|
const failure = terminalError ?? error;
|
|
1947
|
-
|
|
2988
|
+
const primary = isErrorValue(failure) ? failure : new Error(safeErrorMessage(failure));
|
|
1948
2989
|
const cleanupErrors = [];
|
|
1949
2990
|
const timedOut = await disposeWithinDeadline(async () => {
|
|
1950
2991
|
if (rootReleased) return;
|
|
@@ -1995,21 +3036,23 @@ async function runLocalClientEntry(options) {
|
|
|
1995
3036
|
}
|
|
1996
3037
|
rootReleased = true;
|
|
1997
3038
|
}, cleanupErrors);
|
|
1998
|
-
|
|
1999
|
-
const transportCleanupFailed = error
|
|
3039
|
+
const filePrimary = clientFatalPrimaryWithCleanup(primary, cleanupErrors);
|
|
3040
|
+
const transportCleanupFailed = isErrorValue(error) && error.cleanupFailed === true || cleanupErrors.some((cleanupError) => isErrorValue(cleanupError) && cleanupError.cleanupFailed === true);
|
|
2000
3041
|
emit({
|
|
2001
3042
|
m4a0: "failure",
|
|
2002
3043
|
processRole: "client",
|
|
2003
3044
|
phase: context === void 0 ? "startup" : "after-context",
|
|
2004
3045
|
pid: process.pid,
|
|
2005
3046
|
...traceTransportStatus(),
|
|
2006
|
-
...failure
|
|
2007
|
-
error:
|
|
2008
|
-
...
|
|
2009
|
-
...
|
|
3047
|
+
...isLocalScopeErrorValue(failure) ? { code: failure.code } : {},
|
|
3048
|
+
error: filePrimary.message,
|
|
3049
|
+
...filePrimary.stack === void 0 ? {} : { stack: filePrimary.stack },
|
|
3050
|
+
...filePrimary.cause === void 0 ? {} : { cause: isErrorValue(filePrimary.cause) ? filePrimary.cause.message : safeErrorMessage(filePrimary.cause) }
|
|
2010
3051
|
});
|
|
2011
|
-
if (options.mode === "surface"
|
|
2012
|
-
|
|
3052
|
+
if (options.mode === "surface") {
|
|
3053
|
+
const phase = handle === void 0 ? context === void 0 ? "pre-context" : "client-assembly" : "client-runtime";
|
|
3054
|
+
process.stderr.write(`${reportSurfaceClientFatal(failure, options.profile, phase, expectedHostInstanceId !== void 0, process.env, filePrimary)}\n`);
|
|
3055
|
+
}
|
|
2013
3056
|
process.stdin.pause();
|
|
2014
3057
|
if (cleanupErrors.length === 0 && !timedOut && !transportCleanupFailed) emit({
|
|
2015
3058
|
m4a0: "cleanup",
|
|
@@ -2088,17 +3131,71 @@ async function waitForStartupHold(path, signal) {
|
|
|
2088
3131
|
}
|
|
2089
3132
|
signal.throwIfAborted();
|
|
2090
3133
|
}
|
|
3134
|
+
/** Quote an official Profile name for a copy-pasteable shell command. */
|
|
3135
|
+
function shellProfileArg(profile) {
|
|
3136
|
+
if (/^[A-Za-z0-9_.-]+$/u.test(profile)) return profile;
|
|
3137
|
+
return `'${profile.replace(/'/gu, "'\\''")}'`;
|
|
3138
|
+
}
|
|
3139
|
+
/**
|
|
3140
|
+
* The human-facing surface line for one startup failure. Host Typed
|
|
3141
|
+
* protocol/auth/scope refusals keep their dedicated actionable line: the code,
|
|
3142
|
+
* the untouched Host and the public daemon management commands for THIS
|
|
3143
|
+
* official Profile. A Client-local failure is classified on the Client side
|
|
3144
|
+
* and never pretends `daemon logs` contains its detail. It never includes the
|
|
3145
|
+
* registry PID, the launch URL/token or a private profile path.
|
|
3146
|
+
*/
|
|
3147
|
+
function surfaceStartupFailureLine(error, profile, phase = "client-assembly") {
|
|
3148
|
+
const daemon = (verb) => `dsh --profile ${shellProfileArg(profile)} daemon ${verb}`;
|
|
3149
|
+
if (isLocalScopeErrorValue(error)) {
|
|
3150
|
+
if (error.code === "HOST_PROTOCOL_INCOMPATIBLE") return `HOST_PROTOCOL_INCOMPATIBLE: Another live local Host for this profile uses a different local protocol or DSH runtime. The Host has not been stopped or replaced. Inspect it with: ${daemon("status")}; read its logs with: ${daemon("logs")}. If you decide this Profile service is yours to recover, run: ${daemon("restart")}. Recovery is not guaranteed; Automatic upgrade and migration of in-memory work are not supported.`;
|
|
3151
|
+
return `split client surface: cannot establish the local Host (${error.code}); the Host was not stopped. Inspect it with: ${daemon("status")}; read its logs with: ${daemon("logs")}. If you choose to recover, run: ${daemon("restart")}; recovery is not guaranteed.`;
|
|
3152
|
+
}
|
|
3153
|
+
return `split client surface: ${controlledSurfaceReason(error, phase)}`;
|
|
3154
|
+
}
|
|
2091
3155
|
/**
|
|
2092
|
-
* The
|
|
2093
|
-
*
|
|
2094
|
-
*
|
|
2095
|
-
*
|
|
2096
|
-
* includes the registry PID, the launch URL/token or a private profile path.
|
|
2097
|
-
* Every other startup failure keeps the existing diagnostic.
|
|
3156
|
+
* The ONE pure Client-local terminal summary. A missing Client module names
|
|
3157
|
+
* only the safely extracted specifier and points at reinstalling the TUI
|
|
3158
|
+
* plugin; every other failure stays a fixed controlled reason and never
|
|
3159
|
+
* suggests a Host restart, because the Host is not the failing component.
|
|
2098
3160
|
*/
|
|
2099
|
-
function
|
|
2100
|
-
if (error
|
|
2101
|
-
|
|
3161
|
+
function controlledSurfaceReason(error, phase) {
|
|
3162
|
+
if (clientFatalKind(error, phase) === "CLIENT_MODULE_MISSING") return `CLIENT_MODULE_MISSING: required Client module ${clientModuleSpecifier(error) ?? "unknown"} was not found; reinstall the TUI plugin with the supported DSH version. The Host was not stopped.`;
|
|
3163
|
+
if (phase === "client-runtime") return "CLIENT_RUNTIME_FAILED: the Client terminated unexpectedly. The Host was not stopped.";
|
|
3164
|
+
const entryPrefix = "local client entry: ";
|
|
3165
|
+
let raw;
|
|
3166
|
+
try {
|
|
3167
|
+
raw = isErrorValue(error) ? error.message : String(error);
|
|
3168
|
+
} catch {
|
|
3169
|
+
raw = "";
|
|
3170
|
+
}
|
|
3171
|
+
if (raw.startsWith(entryPrefix)) return `CLIENT_STARTUP_FAILED: ${sanitizeSurfaceText(raw.slice(20))}. The Host was not stopped.`;
|
|
3172
|
+
return "CLIENT_STARTUP_FAILED: startup failed before the TUI mounted. The Host was not stopped.";
|
|
3173
|
+
}
|
|
3174
|
+
/**
|
|
3175
|
+
* The ONE surface fatal reporter: build the pure terminal summary, append the
|
|
3176
|
+
* terminal-safe private-file locator, and write exactly one Client artifact.
|
|
3177
|
+
* Used only at the three real fatal entry points (outer catch, body catch and
|
|
3178
|
+
* the stop coordinator), never from an ordinary pure-function test path.
|
|
3179
|
+
*/
|
|
3180
|
+
function reportSurfaceClientFatal(failure, profile, phase, isHandoff, env, primary = failure) {
|
|
3181
|
+
return `${isHandoff ? handoffStartupFailureLine(failure) : surfaceStartupFailureLine(failure, profile, phase)} ${clientDiagnosticLocation(writeClientFatalDiagnostic(primary, phase, env))}`;
|
|
3182
|
+
}
|
|
3183
|
+
/**
|
|
3184
|
+
* The stop-coordinator report entry: merge its collected cleanup causes into
|
|
3185
|
+
* the ONE artifact primary while the terminal classification stays on the
|
|
3186
|
+
* original failure.
|
|
3187
|
+
*/
|
|
3188
|
+
function reportStopClientFatal(failure, profile, phase, isHandoff, env, cleanupErrors) {
|
|
3189
|
+
return reportSurfaceClientFatal(failure, profile, phase, isHandoff, env, clientFatalPrimaryWithCleanup(failure, cleanupErrors));
|
|
3190
|
+
}
|
|
3191
|
+
/** Strip control characters, known credential carriers, URLs and absolute paths; bound the length. */
|
|
3192
|
+
function sanitizeSurfaceText(text) {
|
|
3193
|
+
let out = text.replace(/\b(Authorization|Cookie|Set-Cookie)\s*:\s*[^\r\n]*/giu, "$1: <redacted>").replace(/([?&](?:token|access_token|cookie)=)[^&#\s]+/giu, "$1<redacted>").replace(/\b(token|access_token|password)\s*=\s*(?:\\?"(?:\\.|[^"\\])*\\?"|\\?'(?:\\.|[^'\\])*\\?'|[^\s&;,]+)/giu, "$1=<redacted>");
|
|
3194
|
+
out = out.replace(/[\u0000-\u001f\u007f]/gu, " ");
|
|
3195
|
+
out = out.replace(/[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s'"]+/gu, "<url>");
|
|
3196
|
+
out = out.replace(/(?:\/[\w.@+-]+){2,}\/?/gu, "<path>");
|
|
3197
|
+
out = out.replace(/\s+/gu, " ").trim().slice(0, 200);
|
|
3198
|
+
return out === "" ? "startup failed" : out;
|
|
2102
3199
|
}
|
|
2103
3200
|
/**
|
|
2104
3201
|
* The human-facing line for ONE replacement-Client handoff failure. It names
|
|
@@ -2106,16 +3203,18 @@ function surfaceStartupFailureLine(error) {
|
|
|
2106
3203
|
* replacement package, or Session history open) and says how to recover
|
|
2107
3204
|
* manually. Only fixed entry-owned messages are surfaced: an arbitrary
|
|
2108
3205
|
* startup/spawn error may carry a private path or PID and is replaced with a
|
|
2109
|
-
* generic reason. No Cookie/token/launch URL ever enters this line.
|
|
3206
|
+
* generic reason. No Cookie/token/launch URL ever enters this line. This is
|
|
3207
|
+
* intentionally NOT the daemon-restart guidance: a handoff failure is about a
|
|
3208
|
+
* replaced expected Client instance, not a Host that should be restarted.
|
|
2110
3209
|
*/
|
|
2111
3210
|
function handoffStartupFailureLine(error) {
|
|
2112
3211
|
let reason;
|
|
2113
|
-
if (error
|
|
3212
|
+
if (isLocalScopeErrorValue(error)) {
|
|
2114
3213
|
if (error.code === "HOST_HANDOFF_UNAVAILABLE") reason = "the expected Host is no longer available";
|
|
2115
3214
|
else if (error.code === "HOST_IDENTITY_MISMATCH") reason = "the live local Host is not the expected instance";
|
|
2116
3215
|
else if (error.code === "HOST_PROTOCOL_INCOMPATIBLE") reason = "the expected Host uses a different local protocol or DSH runtime";
|
|
2117
3216
|
else reason = "the expected Host could not be authenticated";
|
|
2118
|
-
} else if (error
|
|
3217
|
+
} else if (isErrorValue(error) && (error.message.startsWith("local client entry: ") || error.message.startsWith("local client reexec: "))) reason = sanitizeSurfaceText(error.message.slice(error.message.indexOf(": ") + 2));
|
|
2119
3218
|
else reason = "the replacement Client could not restore the expected Host and Session";
|
|
2120
3219
|
return `Client handoff failed: ${reason}. The Host was not stopped or replaced. Start a compatible Client manually to continue.`;
|
|
2121
3220
|
}
|
|
@@ -2154,10 +3253,10 @@ if (import.meta.main) try {
|
|
|
2154
3253
|
};
|
|
2155
3254
|
if (process.env.SPLIT_PROCESS_CLIENT_MODE === "surface") {
|
|
2156
3255
|
const handoff = process.env.SPLIT_PROCESS_CLIENT_EXPECTED_INSTANCE_ID;
|
|
2157
|
-
const line = handoff
|
|
3256
|
+
const line = reportSurfaceClientFatal(error, process.env.SPLIT_PROCESS_PROFILE ?? "pi-tui", "pre-entry", handoff !== void 0 && handoff !== "", process.env);
|
|
2158
3257
|
process.stderr.write(`${line}\n`);
|
|
2159
3258
|
} else writeEntryRecord(record);
|
|
2160
3259
|
process.exit(1);
|
|
2161
3260
|
}
|
|
2162
3261
|
//#endregion
|
|
2163
|
-
export { ClientReexecRefusal, INTERACTION_STARTUP_GATE, assertHandoffRestored, assertHandoffSignalExclusivity, assertInteractionStartupReady, createClientReexecChildEnvironment, createClientReexecRequestHandler, createInteractionStartupGate, expectedHostInstanceFromEnvironment, finishClientEntryShutdown, handoffStartupFailureLine, inspectClientReexecTarget, prepareClientReexec, resolveProfileInstalledClientTarget, routeReexecTermination, runLocalClientEntry, stopLocalClient, surfaceStartupFailureLine };
|
|
3262
|
+
export { ClientReexecRefusal, INTERACTION_STARTUP_GATE, assertHandoffRestored, assertHandoffSignalExclusivity, assertInteractionStartupReady, clientFatalPrimaryWithCleanup, createClientReexecChildEnvironment, createClientReexecRequestHandler, createInteractionStartupGate, decodeClientLaunchEnvelope, expectedHostInstanceFromEnvironment, finishClientEntryShutdown, handoffStartupFailureLine, inspectClientReexecTarget, prepareClientReexec, reportStopClientFatal, reportSurfaceClientFatal, resolveProfileInstalledClientTarget, routeReexecTermination, runLocalClientEntry, sanitizeSurfaceText, stopLocalClient, surfaceStartupFacts, surfaceStartupFailureLine };
|