@xmoon76/dsh-pi-tui 0.5.7 → 0.5.9
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 +64 -26
- package/README.md +64 -26
- package/cordis.patch.yml +13 -0
- package/dist/acp-stdio.mjs +151 -0
- package/dist/{bootstrap-C9nl6e13.mjs → bootstrap-CVyHGQDX.mjs} +22330 -6888
- package/dist/browser-CDUSHIIr.mjs +76 -0
- package/dist/builtins.mjs +2 -2
- package/dist/{client-bootstrap-CGezi85O.mjs → client-bootstrap-4UoeVIHE.mjs} +2407 -1830
- package/dist/client-runtime-BHBlVUf5.mjs +1376 -0
- package/dist/{daemon-launcher-H_1r5Cqs.mjs → daemon-launcher-DxIgjBHW.mjs} +1551 -57
- package/dist/daemon-launcher.d.mts +85 -14
- package/dist/daemon-launcher.mjs +2 -2
- package/dist/diagnostics-Db5iVcuJ.mjs +123 -0
- package/dist/{entry-control-jBfKn1qO.mjs → entry-control-BDLZgg4m.mjs} +1 -1
- package/dist/{extensions-6a5vvJUT.mjs → extensions-Dx7ncPNA.mjs} +1 -4
- package/dist/extensions.mjs +1 -1
- package/dist/handoff-BjoEy3f8.mjs +106 -0
- package/dist/history-search-limits-Cx2UvRC2.mjs +16 -0
- package/dist/history-search-remote-BHuoellG.mjs +113 -0
- package/dist/history-search-remote-BzXdvrxk.mjs +26 -0
- package/dist/history-search-seat-BcHJTpeB.mjs +639 -0
- package/dist/history-search-seat-rZcq0XV6.mjs +639 -0
- package/dist/{host-bootstrap-MVxks641.mjs → host-bootstrap-BfnufpnW.mjs} +37 -72
- package/dist/{host-foundation-probe-DK7n5jDu.mjs → host-foundation-probe-DlD8-N_Q.mjs} +2 -2
- package/dist/host-runtime.mjs +5611 -290
- package/dist/index.d.mts +13 -6
- package/dist/index.mjs +22766 -6893
- package/dist/installed-dsh-BjUiJSwR.mjs +142 -0
- package/dist/interaction-port-D1Yv9zgu.mjs +45 -0
- package/dist/local-acp-control-CC5z4Xbq.mjs +304 -0
- package/dist/local-acp-endpoint-D1jYdJdv.mjs +41 -0
- package/dist/local-acp-listener-Cmgb5M0H.mjs +9493 -0
- package/dist/local-acp-status-B_25Q6kU.mjs +101 -0
- package/dist/local-client.mjs +719 -93
- package/dist/local-daemon-control-BFJAC8Kg.mjs +2199 -0
- package/dist/local-daemon-control-Bm3imctD.mjs +2101 -0
- package/dist/{local-discovery-BPZw1wEd.mjs → local-discovery-BMhaGIiJ.mjs} +254 -544
- package/dist/{local-discovery-BMoNXZjJ.mjs → local-discovery-Ba7_-NNC.mjs} +1 -1
- package/dist/{local-discovery-Bq3jLAn1.mjs → local-discovery-QSbFpjK2.mjs} +301 -544
- package/dist/local-host.mjs +970 -501
- package/dist/local-profile-daemon-admin-otpm69R6.mjs +469 -0
- package/dist/{local-scope-DEuGAy8l.mjs → local-scope-5DEKA_lW.mjs} +1075 -31
- package/dist/{local-transport-X4ZCe2uE.mjs → local-transport-DeWmdZ5E.mjs} +14 -3
- package/dist/{local-web-control-DKWtXIkr.mjs → local-web-control-Dny93N-r.mjs} +10 -7
- package/dist/{local-workspace-object-D06GL0UO.mjs → local-workspace-object-D0RVQt8U.mjs} +33 -9
- package/dist/model-selection-CYlqg2DV.mjs +83 -0
- package/dist/native-client-domains-Dg4srzYt.mjs +2 -0
- package/dist/native-client.d.mts +735 -0
- package/dist/native-client.mjs +3534 -0
- package/dist/{open-CmOBxSjN.mjs → open-QQva8-ar.mjs} +24 -20
- package/dist/{pi-tui-remote-contribution-Do8ECrUy.mjs → pi-tui-remote-contribution-565wiLWp.mjs} +741 -150
- package/dist/preferences.mjs +1 -1
- package/dist/{profile-preferences-migration-CThz4rHH.mjs → profile-preferences-migration-CNOWIdnr.mjs} +1 -1
- package/dist/{profile-preferences-migration-BfUGdPZx.mjs → profile-preferences-migration-IrnXcJWK.mjs} +10 -8
- package/dist/{prompt-sections-DXmjB58H.mjs → prompt-sections-Bi-9_Gr_.mjs} +28 -10
- package/dist/{prompt-sections-DUKmWb8g.mjs → prompt-sections-DFS1dqsY.mjs} +342 -56
- package/dist/{dist-BFgC-5tL.mjs → recall-scope-9Nuoto_i.mjs} +353 -1
- package/dist/rolldown-runtime-8H4AJuhK.mjs +14 -0
- package/dist/schema-CCLvDa7Q.mjs +177 -0
- package/dist/{schema-qE_P09zJ.mjs → schema-t97l3aK8.mjs} +56 -3
- package/dist/{session-DC0XQr5O.mjs → session-Cs8iLCEx.mjs} +784 -342
- package/dist/{session-Cihe8PPS.mjs → session-EBRZF6Ow.mjs} +783 -341
- package/dist/session-create-facts-CkfG5DpQ.mjs +20 -0
- package/dist/{startup-CarQxWwi.d.mts → startup-Dti3Udne.d.mts} +30 -3
- package/dist/{startup-CARqn3kV.mjs → startup-UtFQSDe_.mjs} +90 -15
- package/dist/startup.d.mts +2 -2
- package/dist/startup.mjs +1 -1
- package/dist/task-read-remote-DRtkXDrZ.mjs +1083 -0
- package/dist/{terminal-progress-source-D4DHyXDo.mjs → terminal-progress-source-VsczdXA-.mjs} +610 -335
- package/dist/{transcript-view-a7cROAaI.mjs → transcript-view-B6vCnukn.mjs} +2284 -1166
- package/dist/{transcript-view-hvNVkPtv.mjs → transcript-view-DSSdE2vK.mjs} +2191 -765
- package/dist/write-failure-xNKczXH7.mjs +189 -0
- package/package.json +25 -8
- package/dist/local-acp-listener-CNkguN5-.mjs +0 -2566
- package/dist/local-daemon-control-Bg9s2aYi.mjs +0 -1424
- package/dist/local-daemon-control-Cu_4FIdd.mjs +0 -1585
- package/dist/local-profile-daemon-admin-AXgVH-6y.mjs +0 -91
- package/dist/preset-BcWqOtY7.mjs +0 -46
package/dist/local-client.mjs
CHANGED
|
@@ -1,18 +1,380 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { E as ensureWin32PrivateDirectory, N as win32PrivateDirectorySafe, P as win32PrivateFileStatus, _ as scopeFromInstalledProfile, b as parseProcessStatStarttime, d as installedPackageRootFromEntry, h as readProcessStartDiagnostic, n as LocalScopeError, o as bindProfileKernelSeat, p as readInstalledDshVersion, r as NO_PROCESS_SEAT, s as computeBuildId, x as readKernelProcess } from "./local-scope-5DEKA_lW.mjs";
|
|
3
3
|
import { t as runSyncDisposalSteps } from "./disposal-BYBbEpVY.mjs";
|
|
4
|
-
import { n as createEntryDiag, r as writeEntryRecord, t as attachEntryControl } from "./entry-control-
|
|
5
|
-
import { i as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { n as createEntryDiag, r as writeEntryRecord, t as attachEntryControl } from "./entry-control-BDLZgg4m.mjs";
|
|
5
|
+
import { a as scrubProgramResumeEnvironment, i as encodeProgramResumeHandoff, n as PROGRAM_RESUME_TOKEN_ENV, o as takeProgramResumeHandoff, t as PROGRAM_RESUME_HANDOFF_ENV } from "./handoff-BjoEy3f8.mjs";
|
|
6
|
+
import { i as runDetached, o as safeErrorMessage } from "./tasks-D_z5Yjjr.mjs";
|
|
7
|
+
import { a as observeHostWorkspaceObject, i as isSupportedWin32WorkspacePath, r as isBoundedWorkspaceObjectPath } from "./local-workspace-object-D0RVQt8U.mjs";
|
|
8
|
+
import { c as ensureLocalHost, m as sameLocalInstanceRecord, p as readLocalRecord, r as assertRecordedHostKernelIdentityCurrent } from "./local-discovery-QSbFpjK2.mjs";
|
|
8
9
|
import { t as mergeCause } from "./dispose-cause-CNFuUnjR.mjs";
|
|
9
|
-
import { n as profileDaemonAdminRun, t as createProfileDaemonAdmin } from "./local-profile-daemon-admin-
|
|
10
|
+
import { a as programResumeAdmitted, c as clientProgramResumeWithdrawal, n as profileDaemonAdminRun, s as clientProgramResumeCapability, t as createProfileDaemonAdmin } from "./local-profile-daemon-admin-otpm69R6.mjs";
|
|
11
|
+
import { r as dshHome } from "./diagnostics-Db5iVcuJ.mjs";
|
|
12
|
+
import { a as questionIntentSubtype } from "./interaction-port-D1Yv9zgu.mjs";
|
|
10
13
|
import { createRequire } from "node:module";
|
|
11
|
-
import {
|
|
14
|
+
import { randomUUID } from "node:crypto";
|
|
15
|
+
import { chmodSync, closeSync, constants, existsSync, fchmodSync, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, rmSync, statSync, writeSync } from "node:fs";
|
|
12
16
|
import { dirname, isAbsolute, join } from "node:path";
|
|
13
17
|
import { pathToFileURL } from "node:url";
|
|
14
18
|
import { constants as constants$1 } from "node:os";
|
|
15
19
|
import { spawn } from "node:child_process";
|
|
20
|
+
//#region src/app/remote-process/client-fatal-diagnostics.ts
|
|
21
|
+
/**
|
|
22
|
+
* Private Client fatal diagnostics.
|
|
23
|
+
*
|
|
24
|
+
* The Split Client runs in its own process; its launcher inherits this
|
|
25
|
+
* process's terminal but cannot report the child's cause, and the official
|
|
26
|
+
* `daemon logs` command must remain a Host-only source. This module is the ONE
|
|
27
|
+
* Client-owned fatal artifact writer: on a real surface fatal it stores a
|
|
28
|
+
* bounded, redacted, human-readable report under the private
|
|
29
|
+
* `$DSH_HOME/logs/pi-tui-client/` directory and returns a terminal-safe
|
|
30
|
+
* locator. It writes nothing on a successful start, depends on no Cordis /
|
|
31
|
+
* Host / Remote state, and an IO failure is a secondary result that never
|
|
32
|
+
* replaces the primary failure.
|
|
33
|
+
*
|
|
34
|
+
* The file is private incident data, not a shareable report: mode 0600 is
|
|
35
|
+
* mandatory, and redaction covers only the well-known credential carriers.
|
|
36
|
+
* Arbitrary secrets embedded in a user-thrown error cannot be fully
|
|
37
|
+
* recognized; never treat this file as safe to share anonymously.
|
|
38
|
+
* @module app/remote-process/client-fatal-diagnostics
|
|
39
|
+
*/
|
|
40
|
+
const HEADER = "dsh-pi-tui client fatal v1";
|
|
41
|
+
const MAX_FILE_BYTES = 32768;
|
|
42
|
+
const MAX_MESSAGE_BYTES = 2048;
|
|
43
|
+
const MAX_STACK_BYTES = 12288;
|
|
44
|
+
const MAX_CAUSE_DEPTH = 4;
|
|
45
|
+
const MAX_NAME_BYTES = 128;
|
|
46
|
+
const ERROR_CODE_PATTERN = /^[A-Z][A-Z0-9_]{0,63}$/u;
|
|
47
|
+
/** Only the Node module-loader codes are Client dependency misses. */
|
|
48
|
+
const MODULE_MISSING_CODE_PATTERN = /^(?:ERR_MODULE_NOT_FOUND|MODULE_NOT_FOUND)$/u;
|
|
49
|
+
const SAFE_MODULE_SPECIFIER_PATTERN = /^[A-Za-z0-9@._/-]{1,96}$/u;
|
|
50
|
+
const SAFE_ERRNO_PATTERN = /^[A-Z][A-Z0-9_]{0,31}$/u;
|
|
51
|
+
const MODULE_NOT_FOUND_SENTENCE = /Cannot find (?:package|module) '([^']+)'/u;
|
|
52
|
+
/** A deliberate policy refusal with a controlled errno-shaped code. */
|
|
53
|
+
var DiagnosticWriteRefusal = class extends Error {
|
|
54
|
+
code;
|
|
55
|
+
constructor(code) {
|
|
56
|
+
super(code);
|
|
57
|
+
this.name = "DiagnosticWriteRefusal";
|
|
58
|
+
this.code = code;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/** Read one error-like field without letting a hostile getter or proxy escape. */
|
|
62
|
+
function readField(value, field) {
|
|
63
|
+
try {
|
|
64
|
+
return value[field];
|
|
65
|
+
} catch {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** The controlled errno name of a thrown IO/policy failure, or `UNKNOWN`. */
|
|
70
|
+
function controlledErrno(error) {
|
|
71
|
+
const code = readField(error, "code");
|
|
72
|
+
return typeof code === "string" && SAFE_ERRNO_PATTERN.test(code) ? code : "UNKNOWN";
|
|
73
|
+
}
|
|
74
|
+
/** The legal error code of a thrown value, if it has one. */
|
|
75
|
+
function legalErrorCode(error) {
|
|
76
|
+
const code = readField(error, "code");
|
|
77
|
+
return typeof code === "string" && ERROR_CODE_PATTERN.test(code) ? code : void 0;
|
|
78
|
+
}
|
|
79
|
+
/** Whether this is the exact Node loader shape of a missing Client dependency. */
|
|
80
|
+
function isModuleMissing(error) {
|
|
81
|
+
const code = legalErrorCode(error);
|
|
82
|
+
return code !== void 0 && MODULE_MISSING_CODE_PATTERN.test(code);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The only module specifier that may reach the terminal: the standard Node
|
|
86
|
+
* `Cannot find ...` sentence, a bounded package-shaped name with no path or
|
|
87
|
+
* URL shape. An unknown shape stays unknown rather than guessing.
|
|
88
|
+
*/
|
|
89
|
+
function clientModuleSpecifier(error) {
|
|
90
|
+
const specifier = MODULE_NOT_FOUND_SENTENCE.exec(safeErrorMessage(error))?.[1];
|
|
91
|
+
if (specifier === void 0) return void 0;
|
|
92
|
+
if (!SAFE_MODULE_SPECIFIER_PATTERN.test(specifier)) return void 0;
|
|
93
|
+
if (specifier.startsWith("/") || specifier.startsWith("./") || specifier.startsWith("../")) return void 0;
|
|
94
|
+
if (specifier.includes("/../") || specifier.includes("//") || specifier.includes("\\")) return void 0;
|
|
95
|
+
return specifier;
|
|
96
|
+
}
|
|
97
|
+
/** The controlled classification of one fatal observation. */
|
|
98
|
+
function clientFatalKind(error, phase) {
|
|
99
|
+
if (isModuleMissing(error)) return "CLIENT_MODULE_MISSING";
|
|
100
|
+
return phase === "client-runtime" ? "CLIENT_RUNTIME_FAILED" : "CLIENT_STARTUP_FAILED";
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Redact the known credential carriers from private diagnostic text. Bounded
|
|
104
|
+
* on purpose: the file contract states that arbitrary secret formats cannot
|
|
105
|
+
* be fully recognized.
|
|
106
|
+
*/
|
|
107
|
+
function redactPrivateText(text) {
|
|
108
|
+
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>");
|
|
109
|
+
}
|
|
110
|
+
/** Truncate a string to at most `maxBytes` UTF-8 bytes without splitting a code point. */
|
|
111
|
+
function truncateUtf8(text, maxBytes) {
|
|
112
|
+
const buffer = Buffer.from(text, "utf8");
|
|
113
|
+
if (buffer.length <= maxBytes) return text;
|
|
114
|
+
let end = maxBytes;
|
|
115
|
+
while (end > 0 && (buffer[end] & 192) === 128) end -= 1;
|
|
116
|
+
return buffer.subarray(0, end).toString("utf8");
|
|
117
|
+
}
|
|
118
|
+
/** Collapse a single-line field without letting control characters cross fields. */
|
|
119
|
+
function singleLine(text, maxBytes) {
|
|
120
|
+
return truncateUtf8(redactPrivateText(text).replace(/[\r\n]+/gu, " "), maxBytes);
|
|
121
|
+
}
|
|
122
|
+
/** Observe Error/AggregateError identity without a hostile trap escaping. */
|
|
123
|
+
function isErrorLike(value) {
|
|
124
|
+
try {
|
|
125
|
+
return value instanceof Error;
|
|
126
|
+
} catch {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function isAggregateErrorLike(value) {
|
|
131
|
+
try {
|
|
132
|
+
return value instanceof AggregateError;
|
|
133
|
+
} catch {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** The error branches of one AggregateError, without the wrapper itself. */
|
|
138
|
+
function aggregateBranches(value) {
|
|
139
|
+
const errors = readField(value, "errors");
|
|
140
|
+
try {
|
|
141
|
+
return Array.isArray(errors) ? [...errors] : [];
|
|
142
|
+
} catch {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/** The direct cause branches of one error layer, including an AggregateError's
|
|
147
|
+
* own standard `.cause` alongside its `.errors` branches. */
|
|
148
|
+
function causeBranches(value) {
|
|
149
|
+
if (isAggregateErrorLike(value)) {
|
|
150
|
+
const branches = aggregateBranches(value);
|
|
151
|
+
const cause = readField(value, "cause");
|
|
152
|
+
if (cause !== void 0) branches.push(cause);
|
|
153
|
+
if (branches.length > 0) return branches;
|
|
154
|
+
}
|
|
155
|
+
const cause = readField(value, "cause");
|
|
156
|
+
return cause === void 0 ? [] : [cause];
|
|
157
|
+
}
|
|
158
|
+
/** Append one primary/cause layer to the fixed field list. */
|
|
159
|
+
function appendErrorFields(lines, error, depth) {
|
|
160
|
+
const prefix = depth === 0 ? "error" : `cause[${depth}]`;
|
|
161
|
+
const name = readField(error, "name");
|
|
162
|
+
const fallbackName = isErrorLike(error) ? "Error" : "NonError";
|
|
163
|
+
lines.push(`${prefix}.name: ${typeof name === "string" && name !== "" ? singleLine(name, MAX_NAME_BYTES) : fallbackName}`);
|
|
164
|
+
const code = legalErrorCode(error);
|
|
165
|
+
if (code !== void 0) lines.push(`${prefix}.code: ${code}`);
|
|
166
|
+
lines.push(`${prefix}.message: ${truncateUtf8(redactPrivateText(safeErrorMessage(error)), MAX_MESSAGE_BYTES)}`);
|
|
167
|
+
const stack = readField(error, "stack");
|
|
168
|
+
if (typeof stack === "string" && stack !== "") lines.push(`${prefix}.stack: ${truncateUtf8(redactPrivateText(stack), MAX_STACK_BYTES)}`);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Append at most MAX_CAUSE_DEPTH REAL causes. `AggregateError` wrappers are
|
|
172
|
+
* flattening devices: their branches occupy the same cause slots, so the
|
|
173
|
+
* cleanup merge can expose both sides without spending a slot on the wrapper.
|
|
174
|
+
*/
|
|
175
|
+
function appendCauseChain(lines, root) {
|
|
176
|
+
const seen = /* @__PURE__ */ new Set();
|
|
177
|
+
let count = 0;
|
|
178
|
+
let circular = false;
|
|
179
|
+
const visit = (value) => {
|
|
180
|
+
if (value === void 0 || count >= MAX_CAUSE_DEPTH) return;
|
|
181
|
+
if (seen.has(value)) {
|
|
182
|
+
circular = true;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
seen.add(value);
|
|
186
|
+
const branches = causeBranches(value);
|
|
187
|
+
if (isAggregateErrorLike(value) && branches.length > 0) {
|
|
188
|
+
for (const branch of branches) visit(branch);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
count += 1;
|
|
192
|
+
appendErrorFields(lines, value, count);
|
|
193
|
+
if (count >= MAX_CAUSE_DEPTH) return;
|
|
194
|
+
for (const child of branches) visit(child);
|
|
195
|
+
};
|
|
196
|
+
for (const child of causeBranches(root)) visit(child);
|
|
197
|
+
if (circular) lines.push("cause: <circular cause>");
|
|
198
|
+
}
|
|
199
|
+
/** Bound the whole document to the frozen 32 KiB contract. */
|
|
200
|
+
function boundFileText(text) {
|
|
201
|
+
if (Buffer.from(text, "utf8").length <= MAX_FILE_BYTES) return text;
|
|
202
|
+
const marker = "\n[truncated]\n";
|
|
203
|
+
return `${truncateUtf8(text, MAX_FILE_BYTES - Buffer.byteLength(marker, "utf8"))}${marker}`;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Build the bounded, redacted private text for one fatal. Shared with the
|
|
207
|
+
* writer so the security/size rules live in exactly one implementation.
|
|
208
|
+
*/
|
|
209
|
+
function clientFatalErrorDetails(error, phase) {
|
|
210
|
+
const kind = clientFatalKind(error, phase);
|
|
211
|
+
const lines = [
|
|
212
|
+
HEADER,
|
|
213
|
+
`time: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
214
|
+
`phase: ${phase}`,
|
|
215
|
+
`kind: ${kind}`
|
|
216
|
+
];
|
|
217
|
+
appendErrorFields(lines, error, 0);
|
|
218
|
+
appendCauseChain(lines, error);
|
|
219
|
+
return {
|
|
220
|
+
kind,
|
|
221
|
+
text: boundFileText(`${lines.join("\n")}\n`)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/** The terminal-safe locator for one write result: never a private absolute path. */
|
|
225
|
+
function clientDiagnosticLocation(result) {
|
|
226
|
+
if (result.kind === "written") return `Client diagnostics: $DSH_HOME/logs/pi-tui-client/${result.fileName} (default DSH_HOME: ~/.dsh)`;
|
|
227
|
+
if (result.kind === "disabled") return "Client diagnostic file disabled (DSH_PI_TUI_LOG=off)";
|
|
228
|
+
return `Client diagnostics unavailable (DIAGNOSTIC_WRITE_FAILURE: ${result.errno})`;
|
|
229
|
+
}
|
|
230
|
+
/** Create (or tighten) the Client-only directory and prove it is a private 0700 real directory. */
|
|
231
|
+
function ensurePrivateClientDirectory(path, uid) {
|
|
232
|
+
let info;
|
|
233
|
+
try {
|
|
234
|
+
info = lstatSync(path);
|
|
235
|
+
} catch (error) {
|
|
236
|
+
if (controlledErrno(error) !== "ENOENT") throw error;
|
|
237
|
+
try {
|
|
238
|
+
mkdirSync(path, { mode: 448 });
|
|
239
|
+
} catch (mkdirError) {
|
|
240
|
+
if (controlledErrno(mkdirError) !== "EEXIST") throw mkdirError;
|
|
241
|
+
}
|
|
242
|
+
info = lstatSync(path);
|
|
243
|
+
}
|
|
244
|
+
if (info.isSymbolicLink() || !info.isDirectory()) throw new DiagnosticWriteRefusal("ELOOP");
|
|
245
|
+
if (uid !== void 0 && info.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
246
|
+
if ((info.mode & 511) !== 448) {
|
|
247
|
+
chmodSync(path, 448);
|
|
248
|
+
info = lstatSync(path);
|
|
249
|
+
if (info.isSymbolicLink() || !info.isDirectory() || (info.mode & 511) !== 448) throw new DiagnosticWriteRefusal("EPERM");
|
|
250
|
+
if (uid !== void 0 && info.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
251
|
+
}
|
|
252
|
+
return path;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Resolve the real DSH home, prove the actual `logs` parent and the Client-only
|
|
256
|
+
* child are uid-owned real directories, and create only the Client-specific
|
|
257
|
+
* directory when missing. The shared `logs` directory is never chmodded.
|
|
258
|
+
*/
|
|
259
|
+
function prepareDiagnosticDirectory(env) {
|
|
260
|
+
if (process.platform === "win32") return prepareWin32DiagnosticDirectory(env);
|
|
261
|
+
const home = realpathSync(dshHome(env));
|
|
262
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
263
|
+
const homeInfo = statSync(home);
|
|
264
|
+
if (!homeInfo.isDirectory()) throw new DiagnosticWriteRefusal("ENOTDIR");
|
|
265
|
+
if (uid !== void 0 && homeInfo.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
266
|
+
const logs = join(home, "logs");
|
|
267
|
+
let logsInfo;
|
|
268
|
+
try {
|
|
269
|
+
logsInfo = lstatSync(logs);
|
|
270
|
+
} catch (error) {
|
|
271
|
+
if (controlledErrno(error) !== "ENOENT") throw error;
|
|
272
|
+
mkdirSync(logs, { mode: 448 });
|
|
273
|
+
logsInfo = lstatSync(logs);
|
|
274
|
+
}
|
|
275
|
+
if (logsInfo.isSymbolicLink() || !logsInfo.isDirectory()) throw new DiagnosticWriteRefusal("ELOOP");
|
|
276
|
+
if (uid !== void 0 && logsInfo.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
277
|
+
if ((logsInfo.mode & 18) !== 0) throw new DiagnosticWriteRefusal("EPERM");
|
|
278
|
+
const directory = ensurePrivateClientDirectory(join(logs, "pi-tui-client"), uid);
|
|
279
|
+
if (realpathSync(directory) !== directory) throw new DiagnosticWriteRefusal("ELOOP");
|
|
280
|
+
return directory;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Windows diagnostic directory: the user-chosen DSH home and shared `logs`
|
|
284
|
+
* directory are used as they are, including a legitimate junction/symlink that
|
|
285
|
+
* resolves to an ordinary directory. Their owner-chosen ACL is NEVER modified.
|
|
286
|
+
* Only the product-owned `pi-tui-client` child is managed: when newly created it
|
|
287
|
+
* receives a protected owner-only DACL; an existing child is reused only under
|
|
288
|
+
* the shared existing-object predicate, and an unsafe one fails closed.
|
|
289
|
+
*/
|
|
290
|
+
function prepareWin32DiagnosticDirectory(env) {
|
|
291
|
+
const home = realpathSync(dshHome(env));
|
|
292
|
+
if (!statSync(home).isDirectory()) throw new DiagnosticWriteRefusal("ENOTDIR");
|
|
293
|
+
const logs = join(home, "logs");
|
|
294
|
+
try {
|
|
295
|
+
lstatSync(logs);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
if (controlledErrno(error) !== "ENOENT") throw error;
|
|
298
|
+
mkdirSync(logs);
|
|
299
|
+
}
|
|
300
|
+
const logsReal = realpathSync(logs);
|
|
301
|
+
if (!statSync(logsReal).isDirectory()) throw new DiagnosticWriteRefusal("ENOTDIR");
|
|
302
|
+
const directory = join(logsReal, "pi-tui-client");
|
|
303
|
+
ensureWin32PrivateDirectory(directory);
|
|
304
|
+
return directory;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Write the whole UTF-8 buffer. `writeSync` may legally return a short count
|
|
308
|
+
* for a regular file (for example a full disk); a short/zero write is an IO
|
|
309
|
+
* failure, never a successful `written` result.
|
|
310
|
+
*/
|
|
311
|
+
function writeAllBytes(fd, text, write = writeSync) {
|
|
312
|
+
const buffer = Buffer.from(text, "utf8");
|
|
313
|
+
let offset = 0;
|
|
314
|
+
while (offset < buffer.length) {
|
|
315
|
+
const written = write(fd, buffer, offset, buffer.length - offset);
|
|
316
|
+
if (written <= 0) throw new DiagnosticWriteRefusal("EIO");
|
|
317
|
+
offset += written;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Write ONE Client fatal artifact. Returns the terminal-safe locator facts; a
|
|
322
|
+
* disabled or failed write is reported explicitly and never throws into the
|
|
323
|
+
* application startup root.
|
|
324
|
+
*/
|
|
325
|
+
function writeClientFatalDiagnostic(error, phase, env) {
|
|
326
|
+
const configured = env.DSH_PI_TUI_LOG;
|
|
327
|
+
if (configured === "off" || configured === "") return { kind: "disabled" };
|
|
328
|
+
let directory;
|
|
329
|
+
try {
|
|
330
|
+
directory = prepareDiagnosticDirectory(env);
|
|
331
|
+
} catch (ioError) {
|
|
332
|
+
return {
|
|
333
|
+
kind: "unavailable",
|
|
334
|
+
errno: controlledErrno(ioError)
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
const fileName = `startup-${randomUUID()}.log`;
|
|
338
|
+
const target = join(directory, fileName);
|
|
339
|
+
let fd;
|
|
340
|
+
let created = false;
|
|
341
|
+
try {
|
|
342
|
+
fd = openSync(target, process.platform === "win32" ? constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL : constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 384);
|
|
343
|
+
created = true;
|
|
344
|
+
let info = fstatSync(fd);
|
|
345
|
+
if (!info.isFile()) throw new DiagnosticWriteRefusal("EPERM");
|
|
346
|
+
if (process.platform === "win32") {
|
|
347
|
+
if (win32PrivateFileStatus(target) !== "private") throw new DiagnosticWriteRefusal("EPERM");
|
|
348
|
+
} else {
|
|
349
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
350
|
+
if (uid !== void 0 && info.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
351
|
+
if ((info.mode & 511) !== 384) {
|
|
352
|
+
fchmodSync(fd, 384);
|
|
353
|
+
info = fstatSync(fd);
|
|
354
|
+
}
|
|
355
|
+
if (!info.isFile() || (info.mode & 511) !== 384 || uid !== void 0 && info.uid !== uid) throw new DiagnosticWriteRefusal("EPERM");
|
|
356
|
+
}
|
|
357
|
+
writeAllBytes(fd, clientFatalErrorDetails(error, phase).text);
|
|
358
|
+
closeSync(fd);
|
|
359
|
+
fd = void 0;
|
|
360
|
+
return {
|
|
361
|
+
kind: "written",
|
|
362
|
+
fileName
|
|
363
|
+
};
|
|
364
|
+
} catch (ioError) {
|
|
365
|
+
if (fd !== void 0) try {
|
|
366
|
+
closeSync(fd);
|
|
367
|
+
} catch {}
|
|
368
|
+
if (created) try {
|
|
369
|
+
rmSync(target, { force: true });
|
|
370
|
+
} catch {}
|
|
371
|
+
return {
|
|
372
|
+
kind: "unavailable",
|
|
373
|
+
errno: controlledErrno(ioError)
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
16
378
|
//#region src/app/remote-process/local-workspace-equivalence.ts
|
|
17
379
|
/**
|
|
18
380
|
* The Client-local launch-cwd / Host-directory equivalence classifier
|
|
@@ -29,12 +391,14 @@ import { spawn } from "node:child_process";
|
|
|
29
391
|
*
|
|
30
392
|
* Linux uses its long-lived kernel view: the authenticated Host
|
|
31
393
|
* `/proc/<pid>/stat` starttime and `/proc/<pid>/root` directory object. macOS
|
|
32
|
-
* cannot read another process's `/proc` view, so the Host process
|
|
33
|
-
* answers through the Owner-only read-only workspace-object route
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* Browser.
|
|
394
|
+
* and Windows cannot read another process's `/proc` view, so the Host process
|
|
395
|
+
* itself answers through the Owner-only read-only workspace-object route
|
|
396
|
+
* (schema 2 for macOS, schema 3 for Windows). All platforms require the SAME
|
|
397
|
+
* directory object the Client started in — a path spelling alone is never
|
|
398
|
+
* evidence — and a failed/unverifiable observation only means the user must
|
|
399
|
+
* choose a Host Workspace through the existing Browser. Windows additionally
|
|
400
|
+
* requires the launch object captured at launch and an ordinary local
|
|
401
|
+
* fixed-NTFS path; a missing capture is never filled by a later cwd stat.
|
|
38
402
|
*
|
|
39
403
|
* @module @xmoon76/dsh-pi-tui/app/remote-process/local-workspace-equivalence
|
|
40
404
|
*/
|
|
@@ -71,10 +435,10 @@ async function classifyLaunchWorkspace(identity, launchCwd, options = {}) {
|
|
|
71
435
|
kind: "unverified",
|
|
72
436
|
reason: "the local Host identity is unavailable"
|
|
73
437
|
};
|
|
74
|
-
if (platform === "darwin") return await
|
|
438
|
+
if (platform === "darwin" || platform === "win32") return await classifyHostObservedLaunchWorkspace(identity, launchCwd, options, platform);
|
|
75
439
|
if (platform !== "linux") return {
|
|
76
440
|
kind: "unverified",
|
|
77
|
-
reason: "the Host/Client directory equivalence check is only available on Linux and
|
|
441
|
+
reason: "the Host/Client directory equivalence check is only available on Linux, macOS and Windows"
|
|
78
442
|
};
|
|
79
443
|
if (identity.schema !== 1) return {
|
|
80
444
|
kind: "unverified",
|
|
@@ -156,15 +520,21 @@ function classifyLinuxLaunchWorkspace(identity, launchCwd, options) {
|
|
|
156
520
|
};
|
|
157
521
|
}
|
|
158
522
|
/**
|
|
159
|
-
* The macOS
|
|
160
|
-
* Owner-only route, and BOTH the kernel identity and
|
|
161
|
-
* generation must be unchanged before and after the
|
|
523
|
+
* The Host-observed proof (macOS and Windows): the Host itself stats the same
|
|
524
|
+
* absolute path through the Owner-only route, and BOTH the kernel identity and
|
|
525
|
+
* the official Connection generation must be unchanged before and after the
|
|
526
|
+
* observation. Windows additionally requires the launch object captured at
|
|
527
|
+
* launch and an ordinary local fixed-NTFS path on both sides.
|
|
162
528
|
*/
|
|
163
|
-
async function
|
|
164
|
-
if (identity.schema !== 2) return {
|
|
529
|
+
async function classifyHostObservedLaunchWorkspace(identity, launchCwd, options, platform) {
|
|
530
|
+
if (platform === "darwin" && identity.schema !== 2) return {
|
|
165
531
|
kind: "unverified",
|
|
166
532
|
reason: "the Host publication is not a macOS schema 2 record"
|
|
167
533
|
};
|
|
534
|
+
if (platform === "win32" && identity.schema !== 3) return {
|
|
535
|
+
kind: "unverified",
|
|
536
|
+
reason: "the Host publication is not a Windows schema 3 record"
|
|
537
|
+
};
|
|
168
538
|
if (identity.hostPid < 1) return {
|
|
169
539
|
kind: "unverified",
|
|
170
540
|
reason: "the authenticated Host identity is incomplete"
|
|
@@ -187,15 +557,24 @@ async function classifyDarwinLaunchWorkspace(identity, launchCwd, options) {
|
|
|
187
557
|
reason: "the official Host Connection generation is not ready"
|
|
188
558
|
};
|
|
189
559
|
const capturedGeneration = generation.generationId;
|
|
190
|
-
if (!recordIsCurrent(identity, readKernel, readRecord, scope)) return {
|
|
560
|
+
if (!recordIsCurrent(identity, readKernel, readRecord, scope, platform)) return {
|
|
191
561
|
kind: "unverified",
|
|
192
562
|
reason: "the current Host publication does not match the authenticated identity"
|
|
193
563
|
};
|
|
194
|
-
const launchObject = options.launchObject ?? statDirectoryObject(".");
|
|
564
|
+
const launchObject = platform === "win32" ? options.launchObject : options.launchObject ?? statDirectoryObject(".");
|
|
195
565
|
if (launchObject === void 0) return {
|
|
196
566
|
kind: "unverified",
|
|
197
|
-
reason: "the Client launch object cannot be inspected"
|
|
567
|
+
reason: platform === "win32" ? "the Windows Client launch directory object was not captured at launch" : "the Client launch object cannot be inspected"
|
|
198
568
|
};
|
|
569
|
+
let win32Supported;
|
|
570
|
+
if (platform === "win32") {
|
|
571
|
+
const supported = options.supportedWorkspacePath ?? ((path) => isBoundedWorkspaceObjectPath(path, "win32") && isSupportedWin32WorkspacePath(path));
|
|
572
|
+
if (!supported(launchCwd)) return {
|
|
573
|
+
kind: "unverified",
|
|
574
|
+
reason: "the launch directory is not an ordinary path on a supported local fixed NTFS volume"
|
|
575
|
+
};
|
|
576
|
+
win32Supported = () => supported(launchCwd);
|
|
577
|
+
}
|
|
199
578
|
const client = statDirectoryObject(launchCwd);
|
|
200
579
|
if (client === void 0) return {
|
|
201
580
|
kind: "unverified",
|
|
@@ -227,7 +606,7 @@ async function classifyDarwinLaunchWorkspace(identity, launchCwd, options) {
|
|
|
227
606
|
kind: "unverified",
|
|
228
607
|
reason: "the launch path changed while the Host object was observed"
|
|
229
608
|
};
|
|
230
|
-
if (!recordIsCurrent(identity, readKernel, readRecord, scope) || transport.status().generationId !== capturedGeneration) return {
|
|
609
|
+
if (!recordIsCurrent(identity, readKernel, readRecord, scope, platform) || transport.status().generationId !== capturedGeneration) return {
|
|
231
610
|
kind: "unverified",
|
|
232
611
|
reason: "the Host identity or Connection generation changed during the observation"
|
|
233
612
|
};
|
|
@@ -236,7 +615,8 @@ async function classifyDarwinLaunchWorkspace(identity, launchCwd, options) {
|
|
|
236
615
|
if (Boolean(signal?.aborted)) return false;
|
|
237
616
|
const now = transport.status();
|
|
238
617
|
if (now.transport !== "connected" || now.generationId !== capturedGeneration) return false;
|
|
239
|
-
if (!recordIsCurrent(identity, readKernel, readRecord, scope)) return false;
|
|
618
|
+
if (!recordIsCurrent(identity, readKernel, readRecord, scope, platform)) return false;
|
|
619
|
+
if (win32Supported !== void 0 && !win32Supported()) return false;
|
|
240
620
|
const clientNow = statDirectoryObject(launchCwd);
|
|
241
621
|
if (clientNow === void 0 || clientNow.device !== launchObject.device || clientNow.inode !== launchObject.inode) return false;
|
|
242
622
|
if (Boolean(signal?.aborted)) return false;
|
|
@@ -246,7 +626,7 @@ async function classifyDarwinLaunchWorkspace(identity, launchCwd, options) {
|
|
|
246
626
|
const clientAfter = statDirectoryObject(launchCwd);
|
|
247
627
|
if (clientAfter === void 0 || clientAfter.device !== launchObject.device || clientAfter.inode !== launchObject.inode) return false;
|
|
248
628
|
if (transport.status().generationId !== capturedGeneration) return false;
|
|
249
|
-
return recordIsCurrent(identity, readKernel, readRecord, scope);
|
|
629
|
+
return recordIsCurrent(identity, readKernel, readRecord, scope, platform);
|
|
250
630
|
} catch {
|
|
251
631
|
return false;
|
|
252
632
|
}
|
|
@@ -264,9 +644,9 @@ async function classifyDarwinLaunchWorkspace(identity, launchCwd, options) {
|
|
|
264
644
|
/** The live Host publication and kernel identity are still the authenticated
|
|
265
645
|
* ones. Any exception (unreadable registry, unknown kernel read) is `false`,
|
|
266
646
|
* never an assumed success. */
|
|
267
|
-
function recordIsCurrent(identity, readKernel, readRecord, scope) {
|
|
647
|
+
function recordIsCurrent(identity, readKernel, readRecord, scope, platform) {
|
|
268
648
|
try {
|
|
269
|
-
assertRecordedHostKernelIdentityCurrent(identity, readKernel);
|
|
649
|
+
assertRecordedHostKernelIdentityCurrent(identity, readKernel, platform);
|
|
270
650
|
const recorded = readRecord(scope);
|
|
271
651
|
return recorded !== void 0 && sameLocalInstanceRecord(recorded, identity);
|
|
272
652
|
} catch {
|
|
@@ -356,12 +736,7 @@ function createSplitClientInteractionDelivery(options) {
|
|
|
356
736
|
let committedSessionId;
|
|
357
737
|
let bindingToken;
|
|
358
738
|
let bindingDisposal;
|
|
359
|
-
|
|
360
|
-
* The official invocations this root currently holds. Each entry is created
|
|
361
|
-
* by its own callback stack and removed when that SAME invocation settles,
|
|
362
|
-
* aborts or the root disposes — never a Host pending copy.
|
|
363
|
-
*/
|
|
364
|
-
const eligibleRequests = /* @__PURE__ */ new Set();
|
|
739
|
+
const eligibleRequests = /* @__PURE__ */ new Map();
|
|
365
740
|
const eligibilityListeners = /* @__PURE__ */ new Set();
|
|
366
741
|
const rootLifetime = new AbortController();
|
|
367
742
|
const wakeWaiters = () => {
|
|
@@ -375,18 +750,54 @@ function createSplitClientInteractionDelivery(options) {
|
|
|
375
750
|
listener();
|
|
376
751
|
} catch {}
|
|
377
752
|
};
|
|
378
|
-
const
|
|
753
|
+
const removeEligible = (token) => {
|
|
754
|
+
const entry = eligibleRequests.get(token);
|
|
755
|
+
if (entry === void 0) return;
|
|
756
|
+
eligibleRequests.delete(token);
|
|
757
|
+
entry.offAbort?.();
|
|
758
|
+
notifyEligibility();
|
|
759
|
+
};
|
|
760
|
+
const addEligible = (sessionId, kind, subtype, signal) => {
|
|
379
761
|
const token = {
|
|
380
762
|
sessionId,
|
|
381
763
|
kind,
|
|
764
|
+
...subtype === void 0 ? {} : { subtype },
|
|
382
765
|
live: true
|
|
383
766
|
};
|
|
384
|
-
|
|
767
|
+
const generation = options.generation.getSnapshot();
|
|
768
|
+
if (generation === void 0 || signal?.aborted === true) return token;
|
|
769
|
+
const entry = {
|
|
770
|
+
token,
|
|
771
|
+
generation,
|
|
772
|
+
signal,
|
|
773
|
+
offAbort: void 0
|
|
774
|
+
};
|
|
775
|
+
eligibleRequests.set(token, entry);
|
|
776
|
+
if (signal !== void 0 && !signal.aborted) {
|
|
777
|
+
const onAbort = () => {
|
|
778
|
+
removeEligible(token);
|
|
779
|
+
};
|
|
780
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
781
|
+
entry.offAbort = () => {
|
|
782
|
+
signal.removeEventListener("abort", onAbort);
|
|
783
|
+
};
|
|
784
|
+
}
|
|
385
785
|
notifyEligibility();
|
|
386
786
|
return token;
|
|
387
787
|
};
|
|
388
|
-
|
|
389
|
-
|
|
788
|
+
/** The getter and notification view always use the LIVE official generation
|
|
789
|
+
* and request signal. A lost/replaced generation retires its tokens even if
|
|
790
|
+
* the original invocation's finally has not run yet. */
|
|
791
|
+
const pruneEligible = () => {
|
|
792
|
+
const generation = options.generation.getSnapshot();
|
|
793
|
+
let changed = false;
|
|
794
|
+
for (const [token, entry] of [...eligibleRequests]) {
|
|
795
|
+
if (generation !== void 0 && Object.is(entry.generation, generation) && entry.signal?.aborted !== true) continue;
|
|
796
|
+
eligibleRequests.delete(token);
|
|
797
|
+
entry.offAbort?.();
|
|
798
|
+
changed = true;
|
|
799
|
+
}
|
|
800
|
+
if (changed) notifyEligibility();
|
|
390
801
|
};
|
|
391
802
|
/** The combined official lifetime plus the root lifetime. */
|
|
392
803
|
const lifetimeOf = (signal) => signal === void 0 ? rootLifetime.signal : AbortSignal.any([signal, rootLifetime.signal]);
|
|
@@ -506,7 +917,7 @@ function createSplitClientInteractionDelivery(options) {
|
|
|
506
917
|
...request.signal === void 0 ? {} : { signal: request.signal }
|
|
507
918
|
};
|
|
508
919
|
const nextOnce = onceNext(next);
|
|
509
|
-
const eligible = addEligible(sessionId, "question");
|
|
920
|
+
const eligible = addEligible(sessionId, "question", questionIntentSubtype(request.questions) === "plan-review" ? "plan-review" : void 0, request.signal);
|
|
510
921
|
try {
|
|
511
922
|
return await presentWhenAdmissible(sessionId, request.signal, (attachment) => attachment.onQuestion(view, nextOnce));
|
|
512
923
|
} finally {
|
|
@@ -524,7 +935,7 @@ function createSplitClientInteractionDelivery(options) {
|
|
|
524
935
|
sessionId
|
|
525
936
|
};
|
|
526
937
|
const nextOnce = onceNext(next);
|
|
527
|
-
const eligible = addEligible(sessionId, "approval");
|
|
938
|
+
const eligible = addEligible(sessionId, "approval", void 0, request.signal);
|
|
528
939
|
try {
|
|
529
940
|
return await presentWhenAdmissible(sessionId, request.signal, (attachment) => attachment.onApproval(view, nextOnce));
|
|
530
941
|
} finally {
|
|
@@ -532,6 +943,7 @@ function createSplitClientInteractionDelivery(options) {
|
|
|
532
943
|
}
|
|
533
944
|
};
|
|
534
945
|
const owned = [];
|
|
946
|
+
owned.push(options.generation.subscribe(pruneEligible));
|
|
535
947
|
owned.push(options.remote.$on("user-questions/request", deliverQuestion));
|
|
536
948
|
owned.push(options.remote.$on("approval/request", deliverApproval));
|
|
537
949
|
return {
|
|
@@ -550,7 +962,8 @@ function createSplitClientInteractionDelivery(options) {
|
|
|
550
962
|
};
|
|
551
963
|
},
|
|
552
964
|
currentEligibleRequests() {
|
|
553
|
-
|
|
965
|
+
pruneEligible();
|
|
966
|
+
return [...eligibleRequests.values()].map((entry) => entry.token);
|
|
554
967
|
},
|
|
555
968
|
subscribeEligibility(listener) {
|
|
556
969
|
eligibilityListeners.add(listener);
|
|
@@ -610,6 +1023,7 @@ function createSplitClientInteractionDelivery(options) {
|
|
|
610
1023
|
bindingToken = void 0;
|
|
611
1024
|
const binding = bindingDisposal;
|
|
612
1025
|
bindingDisposal = void 0;
|
|
1026
|
+
for (const entry of eligibleRequests.values()) entry.offAbort?.();
|
|
613
1027
|
eligibleRequests.clear();
|
|
614
1028
|
notifyEligibility();
|
|
615
1029
|
rootLifetime.abort(disposedReason());
|
|
@@ -701,8 +1115,9 @@ const CLIENT_LAUNCH_CWD = process.cwd();
|
|
|
701
1115
|
/** The DIRECTORY OBJECT the Client started in, captured at the same instant as
|
|
702
1116
|
* `CLIENT_LAUNCH_CWD`. A later rename+recreation of the path must not be
|
|
703
1117
|
* mistaken for the launch directory (external review EXT-P1). An unreadable
|
|
704
|
-
* capture stays `undefined`; the classifier then falls back to its own
|
|
705
|
-
* `stat('.')` object
|
|
1118
|
+
* capture stays `undefined`; the POSIX classifier then falls back to its own
|
|
1119
|
+
* real `stat('.')` object, while the Windows classifier requires the captured
|
|
1120
|
+
* object and fails closed. */
|
|
706
1121
|
const CLIENT_LAUNCH_OBJECT = (() => {
|
|
707
1122
|
try {
|
|
708
1123
|
const stat = statSync(".", { bigint: true });
|
|
@@ -770,6 +1185,35 @@ function createSurfaceRecordSink() {
|
|
|
770
1185
|
const directory = realpathSync(dirname(target));
|
|
771
1186
|
const directoryStats = statSync(directory);
|
|
772
1187
|
if (!directoryStats.isDirectory()) throw new Error("local client entry: the surface record directory is not a directory");
|
|
1188
|
+
if (process.platform === "win32") {
|
|
1189
|
+
if (!win32PrivateDirectorySafe(directory)) throw new Error("local client entry: the surface record directory is not a private owner-only directory");
|
|
1190
|
+
const existing = win32PrivateFileStatus(target);
|
|
1191
|
+
if (existing === "unsafe") throw new Error("local client entry: the surface record file is not a private regular file");
|
|
1192
|
+
let fd;
|
|
1193
|
+
let newlyCreated = false;
|
|
1194
|
+
try {
|
|
1195
|
+
fd = openSync(target, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_APPEND, 384);
|
|
1196
|
+
newlyCreated = true;
|
|
1197
|
+
} catch (error) {
|
|
1198
|
+
if (existing !== "private" || error.code !== "EEXIST") throw error;
|
|
1199
|
+
fd = openSync(target, constants.O_WRONLY | constants.O_APPEND, 384);
|
|
1200
|
+
}
|
|
1201
|
+
try {
|
|
1202
|
+
if (!fstatSync(fd).isFile()) throw new Error("local client entry: the surface record file must be a private regular file");
|
|
1203
|
+
if (newlyCreated && win32PrivateFileStatus(target) !== "private") throw new Error("local client entry: the surface record file must be a private regular file");
|
|
1204
|
+
} catch (error) {
|
|
1205
|
+
closeSync(fd);
|
|
1206
|
+
throw error;
|
|
1207
|
+
}
|
|
1208
|
+
return {
|
|
1209
|
+
emit: (record) => {
|
|
1210
|
+
writeSync(fd, `${JSON.stringify(record)}\n`);
|
|
1211
|
+
},
|
|
1212
|
+
close: () => {
|
|
1213
|
+
closeSync(fd);
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
773
1217
|
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
774
1218
|
if (uid !== void 0 && directoryStats.uid !== uid) throw new Error("local client entry: the surface record directory is not owned by this process user");
|
|
775
1219
|
if (existsSync(target) && lstatSync(target).isSymbolicLink()) throw new Error("local client entry: the surface record file must not be a symlink");
|
|
@@ -913,9 +1357,54 @@ const OLD_CLIENT_ENVIRONMENT = [
|
|
|
913
1357
|
function failureMessage(error) {
|
|
914
1358
|
return error instanceof Error ? error.message : String(error);
|
|
915
1359
|
}
|
|
1360
|
+
/** Observe Error identity without a hostile Proxy `getPrototypeOf` trap escaping. */
|
|
1361
|
+
function isErrorValue(value) {
|
|
1362
|
+
try {
|
|
1363
|
+
return value instanceof Error;
|
|
1364
|
+
} catch {
|
|
1365
|
+
return false;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
/** Observe LocalScopeError identity through the same safe boundary. */
|
|
1369
|
+
function isLocalScopeErrorValue(value) {
|
|
1370
|
+
try {
|
|
1371
|
+
return value instanceof LocalScopeError;
|
|
1372
|
+
} catch {
|
|
1373
|
+
return false;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
/**
|
|
1377
|
+
* Merge the stop coordinator's cleanup errors into the ONE primary error that
|
|
1378
|
+
* the incident file records. The terminal classification keeps the original
|
|
1379
|
+
* failure; only the artifact needs the cleanup cause chain.
|
|
1380
|
+
*/
|
|
1381
|
+
function clientFatalPrimaryWithCleanup(failure, cleanupErrors) {
|
|
1382
|
+
const primary = isErrorValue(failure) ? failure : new Error(safeErrorMessage(failure));
|
|
1383
|
+
if (cleanupErrors.length === 0) return primary;
|
|
1384
|
+
try {
|
|
1385
|
+
let merged = primary;
|
|
1386
|
+
for (const cleanupError of cleanupErrors) merged = mergeCause(merged, cleanupError);
|
|
1387
|
+
return merged;
|
|
1388
|
+
} catch {
|
|
1389
|
+
const root = new Error(safeErrorMessage(failure));
|
|
1390
|
+
if (isErrorValue(failure)) try {
|
|
1391
|
+
root.name = failure.name;
|
|
1392
|
+
root.stack = failure.stack;
|
|
1393
|
+
const code = failure.code;
|
|
1394
|
+
if (typeof code === "string") root.code = code;
|
|
1395
|
+
} catch {}
|
|
1396
|
+
root.cause = new AggregateError([failure, ...cleanupErrors], "local client entry: fatal failure with cleanup causes");
|
|
1397
|
+
return root;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
916
1400
|
function isRecord(value) {
|
|
917
1401
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
918
1402
|
}
|
|
1403
|
+
/** Whether the installed target manifest implements the v1 Client handoff. */
|
|
1404
|
+
function clientHandoffCapability(manifest) {
|
|
1405
|
+
const capabilities = manifest.dshPiTuiInternalCapabilities;
|
|
1406
|
+
return isRecord(capabilities) && capabilities.osc7577ClientHandoff === 1;
|
|
1407
|
+
}
|
|
919
1408
|
/**
|
|
920
1409
|
* Validate one replacement Client package root and derive its production build
|
|
921
1410
|
* fingerprint. The same checks apply to the package currently installed in the
|
|
@@ -959,7 +1448,8 @@ function inspectClientReexecTarget(packageRoot, dshVersion) {
|
|
|
959
1448
|
packageRoot: root,
|
|
960
1449
|
entry,
|
|
961
1450
|
buildId: computeBuildId(root, dshVersion),
|
|
962
|
-
bundleVersion: manifest.version
|
|
1451
|
+
bundleVersion: manifest.version,
|
|
1452
|
+
programResumeHandoff: clientHandoffCapability(manifest)
|
|
963
1453
|
};
|
|
964
1454
|
}
|
|
965
1455
|
/** Resolve the replacement package through the ACTIVE official profile. */
|
|
@@ -1009,7 +1499,8 @@ function prepareClientReexec(options) {
|
|
|
1009
1499
|
targetPackageRoot: target.packageRoot,
|
|
1010
1500
|
targetEntry: target.entry,
|
|
1011
1501
|
targetBuildId: target.buildId,
|
|
1012
|
-
targetBundleVersion: target.bundleVersion
|
|
1502
|
+
targetBundleVersion: target.bundleVersion,
|
|
1503
|
+
targetProgramResumeHandoff: target.programResumeHandoff
|
|
1013
1504
|
};
|
|
1014
1505
|
}
|
|
1015
1506
|
/**
|
|
@@ -1096,10 +1587,11 @@ function createClientReexecRequestHandler(options) {
|
|
|
1096
1587
|
};
|
|
1097
1588
|
}
|
|
1098
1589
|
/** Build the environment of the ONE replacement Client child. */
|
|
1099
|
-
function createClientReexecChildEnvironment(intent, source = process.env) {
|
|
1590
|
+
function createClientReexecChildEnvironment(intent, source = process.env, programResume) {
|
|
1100
1591
|
const env = { ...source };
|
|
1101
1592
|
const injectedFailure = source.SPLIT_PROCESS_CLIENT_REEXEC_CHILD_FAILURE;
|
|
1102
1593
|
for (const name of OLD_CLIENT_ENVIRONMENT) delete env[name];
|
|
1594
|
+
scrubProgramResumeEnvironment(env);
|
|
1103
1595
|
delete env.SPLIT_PROCESS_CLIENT_PRESET;
|
|
1104
1596
|
delete env.SPLIT_PROCESS_CLIENT_LAUNCH_V1;
|
|
1105
1597
|
env.SPLIT_PROCESS_CLIENT_MODE = "surface";
|
|
@@ -1108,6 +1600,10 @@ function createClientReexecChildEnvironment(intent, source = process.env) {
|
|
|
1108
1600
|
env.SPLIT_PROCESS_PROFILE = intent.profile;
|
|
1109
1601
|
if (intent.sessionId === void 0) delete env.SPLIT_PROCESS_CLIENT_SESSION;
|
|
1110
1602
|
else env.SPLIT_PROCESS_CLIENT_SESSION = intent.sessionId;
|
|
1603
|
+
if (intent.targetProgramResumeHandoff === true && programResume !== void 0) {
|
|
1604
|
+
env[PROGRAM_RESUME_TOKEN_ENV] = programResume.token;
|
|
1605
|
+
env[PROGRAM_RESUME_HANDOFF_ENV] = encodeProgramResumeHandoff(programResume.facts);
|
|
1606
|
+
}
|
|
1111
1607
|
if (injectedFailure !== void 0 && injectedFailure !== "") env.SPLIT_PROCESS_CLIENT_FORCE_FAILURE = injectedFailure;
|
|
1112
1608
|
return env;
|
|
1113
1609
|
}
|
|
@@ -1225,7 +1721,7 @@ async function finishClientEntryShutdown(options) {
|
|
|
1225
1721
|
options.stderr(handoffStartupFailureLine(error));
|
|
1226
1722
|
return 1;
|
|
1227
1723
|
}
|
|
1228
|
-
if (target.buildId !== reexec.intent.targetBuildId || target.entry !== reexec.intent.targetEntry) {
|
|
1724
|
+
if (target.buildId !== reexec.intent.targetBuildId || target.entry !== reexec.intent.targetEntry || target.programResumeHandoff !== (reexec.intent.targetProgramResumeHandoff === true)) {
|
|
1229
1725
|
const changed = /* @__PURE__ */ new Error("local client reexec: the replacement Client package changed between the preflight and the spawn");
|
|
1230
1726
|
options.emit({
|
|
1231
1727
|
m4r: "handoff-failed",
|
|
@@ -1241,7 +1737,7 @@ async function finishClientEntryShutdown(options) {
|
|
|
1241
1737
|
const spawnChild = options.spawnChild ?? spawnClientReexecChild;
|
|
1242
1738
|
let exit;
|
|
1243
1739
|
try {
|
|
1244
|
-
exit = await spawnChild(target.entry, createClientReexecChildEnvironment(reexec.intent), (child) => options.onChildSpawned?.(child));
|
|
1740
|
+
exit = await spawnChild(target.entry, createClientReexecChildEnvironment(reexec.intent, process.env, reexec.programResume), (child) => options.onChildSpawned?.(child));
|
|
1245
1741
|
} catch (error) {
|
|
1246
1742
|
options.emit({
|
|
1247
1743
|
m4r: "handoff-failed",
|
|
@@ -1444,6 +1940,7 @@ function observeQualificationSocket(socket, emit) {
|
|
|
1444
1940
|
* caller.
|
|
1445
1941
|
*/
|
|
1446
1942
|
async function runLocalClientEntry(options) {
|
|
1943
|
+
const programResumeCapture = takeProgramResumeHandoff(process.env);
|
|
1447
1944
|
const expectedHostInstanceId = expectedHostInstanceFromEnvironment(options.mode);
|
|
1448
1945
|
assertHandoffSignalExclusivity(options.mode, expectedHostInstanceId);
|
|
1449
1946
|
const launchEnvelope = options.mode === "surface" ? readClientLaunchEnvelope() : void 0;
|
|
@@ -1454,6 +1951,42 @@ async function runLocalClientEntry(options) {
|
|
|
1454
1951
|
const invokedEntry = process.argv[1];
|
|
1455
1952
|
const packageRoot = installedPackageRootFromEntry(invokedEntry === void 0 ? import.meta.url : pathToFileURL(invokedEntry).href);
|
|
1456
1953
|
const profileDir = hostModules.resolveProfileDir(options.profile, dshHome);
|
|
1954
|
+
const programResumeHandle = options.mode === "surface" && programResumeAdmitted(process.env) && (launchEnvelope !== void 0 || expectedHostInstanceId !== void 0) ? (() => {
|
|
1955
|
+
const input = {
|
|
1956
|
+
token: programResumeCapture.token,
|
|
1957
|
+
handoff: programResumeCapture.handoff,
|
|
1958
|
+
expectedHome: dshHome,
|
|
1959
|
+
expectedProfile: options.profile,
|
|
1960
|
+
isReexec: expectedHostInstanceId !== void 0,
|
|
1961
|
+
parentPid: process.ppid,
|
|
1962
|
+
env: process.env,
|
|
1963
|
+
execArgv: process.execArgv,
|
|
1964
|
+
stdinIsTTY: process.stdin.isTTY === true,
|
|
1965
|
+
stdoutIsTTY: process.stdout.isTTY === true,
|
|
1966
|
+
platform: process.platform
|
|
1967
|
+
};
|
|
1968
|
+
let reporter;
|
|
1969
|
+
const attach = (next) => {
|
|
1970
|
+
reporter = next;
|
|
1971
|
+
};
|
|
1972
|
+
const unsupportedReloadAccepted = () => {
|
|
1973
|
+
reporter?.unsupportedReloadAccepted();
|
|
1974
|
+
};
|
|
1975
|
+
const capability = clientProgramResumeCapability(input);
|
|
1976
|
+
if (capability !== void 0) return {
|
|
1977
|
+
capability,
|
|
1978
|
+
attach,
|
|
1979
|
+
unsupportedReloadAccepted,
|
|
1980
|
+
forReexec: () => capability
|
|
1981
|
+
};
|
|
1982
|
+
const withdrawal = clientProgramResumeWithdrawal(input);
|
|
1983
|
+
return withdrawal === void 0 ? void 0 : {
|
|
1984
|
+
withdrawal,
|
|
1985
|
+
attach,
|
|
1986
|
+
unsupportedReloadAccepted,
|
|
1987
|
+
forReexec: () => void 0
|
|
1988
|
+
};
|
|
1989
|
+
})() : void 0;
|
|
1457
1990
|
const installedDshVersion = readInstalledDshVersion(options.dshAnchor);
|
|
1458
1991
|
const scope = scopeFromInstalledProfile({
|
|
1459
1992
|
dshHome,
|
|
@@ -1561,6 +2094,7 @@ async function runLocalClientEntry(options) {
|
|
|
1561
2094
|
});
|
|
1562
2095
|
let terminalError;
|
|
1563
2096
|
let compositionDone = false;
|
|
2097
|
+
let dropGenerationObservation;
|
|
1564
2098
|
const stop = (code, failure) => {
|
|
1565
2099
|
if (stopping !== void 0) return stopping;
|
|
1566
2100
|
startupAbort.abort(failure ?? /* @__PURE__ */ new Error("local client entry: stop requested during startup"));
|
|
@@ -1694,7 +2228,10 @@ async function runLocalClientEntry(options) {
|
|
|
1694
2228
|
process.exitCode = code;
|
|
1695
2229
|
if (code === 0 && reexecIntent !== void 0) reexecTeardownSucceeded = true;
|
|
1696
2230
|
}
|
|
1697
|
-
if (options.mode === "surface" && failure !== void 0)
|
|
2231
|
+
if (options.mode === "surface" && failure !== void 0) {
|
|
2232
|
+
const phase = handle !== void 0 ? "client-runtime" : context === void 0 ? "pre-context" : "client-assembly";
|
|
2233
|
+
process.stderr.write(`${reportStopClientFatal(failure, options.profile, phase, expectedHostInstanceId !== void 0, process.env, errors)}\n`);
|
|
2234
|
+
}
|
|
1698
2235
|
process.stdin.pause();
|
|
1699
2236
|
resolveStopped?.();
|
|
1700
2237
|
emit({
|
|
@@ -1787,8 +2324,8 @@ async function runLocalClientEntry(options) {
|
|
|
1787
2324
|
pid: process.pid,
|
|
1788
2325
|
phase: "context-ready"
|
|
1789
2326
|
});
|
|
1790
|
-
const transportModule = await import("./local-transport-
|
|
1791
|
-
const { mountSurfaceClientDomainPrerequisites, startLocalClient } = await import("./client-bootstrap-
|
|
2327
|
+
const transportModule = await import("./local-transport-DeWmdZ5E.mjs");
|
|
2328
|
+
const { mountSurfaceClientDomainPrerequisites, startLocalClient } = await import("./client-bootstrap-4UoeVIHE.mjs");
|
|
1792
2329
|
const onTransportFatal = (error) => {
|
|
1793
2330
|
terminalError ??= error;
|
|
1794
2331
|
if (compositionDone) runDetached("local client: terminal transport identity failure", () => stop(1, terminalError), { diag });
|
|
@@ -1839,7 +2376,8 @@ async function runLocalClientEntry(options) {
|
|
|
1839
2376
|
const remoteService = clientContext.get("remote");
|
|
1840
2377
|
if (options.mode === "surface") interactionDelivery = createSplitClientInteractionDelivery({
|
|
1841
2378
|
remote,
|
|
1842
|
-
sessions: domainPrerequisites.sessions
|
|
2379
|
+
sessions: domainPrerequisites.sessions,
|
|
2380
|
+
generation: installedTransport.connection.generation
|
|
1843
2381
|
});
|
|
1844
2382
|
else peerSeat = createPeerInteractionSeat(remote, domainPrerequisites.sessions, emit);
|
|
1845
2383
|
const agentResolver = clientContext.get("typert")?.contexts.getClient("agent");
|
|
@@ -2347,7 +2885,7 @@ async function runLocalClientEntry(options) {
|
|
|
2347
2885
|
runDetached("local client: surface exit", () => stop(code), { diag });
|
|
2348
2886
|
});
|
|
2349
2887
|
activeBridge = bridge;
|
|
2350
|
-
const { applyRunnerWithRuntime } = await import("./bootstrap-
|
|
2888
|
+
const { applyRunnerWithRuntime } = await import("./bootstrap-CVyHGQDX.mjs");
|
|
2351
2889
|
const launchWorkspace = await classifyLaunchWorkspace(host.identity, CLIENT_LAUNCH_CWD, {
|
|
2352
2890
|
...CLIENT_LAUNCH_OBJECT === void 0 ? {} : { launchObject: CLIENT_LAUNCH_OBJECT },
|
|
2353
2891
|
scope,
|
|
@@ -2367,7 +2905,9 @@ async function runLocalClientEntry(options) {
|
|
|
2367
2905
|
initialSurface: input.mountKind === "initial"
|
|
2368
2906
|
},
|
|
2369
2907
|
presencePeerScope: clientContext,
|
|
2370
|
-
...
|
|
2908
|
+
...programResumeHandle === void 0 ? {} : { programResume: programResumeHandle },
|
|
2909
|
+
...reexecHandler === void 0 ? {} : { requestClientReload: () => reexecHandler.request("manual") },
|
|
2910
|
+
normalPublicLaunch: launchEnvelope !== void 0 && expectedHostInstanceId === void 0 && input.mountKind === "initial"
|
|
2371
2911
|
}, launchWorkspace);
|
|
2372
2912
|
});
|
|
2373
2913
|
await runnerFiber;
|
|
@@ -2390,6 +2930,7 @@ async function runLocalClientEntry(options) {
|
|
|
2390
2930
|
activeBridge?.requestStop(code);
|
|
2391
2931
|
});
|
|
2392
2932
|
if (process.env.SPLIT_PROCESS_CLIENT_HMR_PROBE === "1") {
|
|
2933
|
+
if (process.platform === "win32") throw new Error("local client entry: the SIGUSR2 surface HMR qualification is unavailable on Windows");
|
|
2393
2934
|
if (process.env.SPLIT_PROCESS_CLIENT_PRIVATE_RPC_PROOF === "1" || process.env.SPLIT_PROCESS_CLIENT_REEXEC_PROBE === "1" || process.env.SPLIT_PROCESS_CLIENT_HOLD_SERIALIZE !== void 0 && process.env.SPLIT_PROCESS_CLIENT_HOLD_SERIALIZE !== "") throw new Error("local client entry: the HMR qualification signal is mutually exclusive with the T34/T36/reexec SIGUSR2 modes");
|
|
2394
2935
|
process.on("SIGUSR2", () => {
|
|
2395
2936
|
if (handle === void 0) return;
|
|
@@ -2422,9 +2963,10 @@ async function runLocalClientEntry(options) {
|
|
|
2422
2963
|
canRequest: () => stopping === void 0,
|
|
2423
2964
|
onAccepted: (accepted) => {
|
|
2424
2965
|
reexecIntent = accepted;
|
|
2966
|
+
if (accepted.targetProgramResumeHandoff !== true) programResumeHandle?.unsupportedReloadAccepted();
|
|
2425
2967
|
}
|
|
2426
2968
|
});
|
|
2427
|
-
if (reexecProbe) process.on("SIGUSR2", () => {
|
|
2969
|
+
if (reexecProbe && process.platform !== "win32") process.on("SIGUSR2", () => {
|
|
2428
2970
|
reexecHandler?.request("qualification");
|
|
2429
2971
|
});
|
|
2430
2972
|
const onTerminalEnd = () => {
|
|
@@ -2432,7 +2974,7 @@ async function runLocalClientEntry(options) {
|
|
|
2432
2974
|
};
|
|
2433
2975
|
process.stdin.on("end", onTerminalEnd);
|
|
2434
2976
|
process.stdin.on("close", onTerminalEnd);
|
|
2435
|
-
process.on("SIGUSR1", () => {
|
|
2977
|
+
if (process.platform !== "win32") process.on("SIGUSR1", () => {
|
|
2436
2978
|
transport?.dropWebSocketsForQualification();
|
|
2437
2979
|
emit({
|
|
2438
2980
|
m4b2s: "qualification",
|
|
@@ -2550,7 +3092,63 @@ async function runLocalClientEntry(options) {
|
|
|
2550
3092
|
return true;
|
|
2551
3093
|
}
|
|
2552
3094
|
if (request.op === "qualification-drop-websocket") {
|
|
2553
|
-
|
|
3095
|
+
dropGenerationObservation?.dispose();
|
|
3096
|
+
dropGenerationObservation = void 0;
|
|
3097
|
+
const connection = transport?.connection;
|
|
3098
|
+
const previous = connection?.generation.getSnapshot();
|
|
3099
|
+
let ackEmitted = false;
|
|
3100
|
+
let clearObserved = false;
|
|
3101
|
+
let published = false;
|
|
3102
|
+
let disposed = false;
|
|
3103
|
+
let dispatchStarted = false;
|
|
3104
|
+
const cleanups = [];
|
|
3105
|
+
const dispose = () => {
|
|
3106
|
+
if (disposed) return;
|
|
3107
|
+
disposed = true;
|
|
3108
|
+
for (const cleanup of cleanups.splice(0)) cleanup();
|
|
3109
|
+
if (dropGenerationObservation?.dispose === dispose) dropGenerationObservation = void 0;
|
|
3110
|
+
};
|
|
3111
|
+
const publish = () => {
|
|
3112
|
+
if (disposed || published || !ackEmitted || !clearObserved) return;
|
|
3113
|
+
published = true;
|
|
3114
|
+
emit({
|
|
3115
|
+
m4a0: "qualification",
|
|
3116
|
+
op: "drop-generation-cleared",
|
|
3117
|
+
processRole: "client",
|
|
3118
|
+
pid: process.pid,
|
|
3119
|
+
...request.requestId === void 0 ? {} : { requestId: request.requestId },
|
|
3120
|
+
previousGenerationId: previous.id
|
|
3121
|
+
});
|
|
3122
|
+
dispose();
|
|
3123
|
+
};
|
|
3124
|
+
if (connection !== void 0 && previous !== void 0 && Number.isInteger(previous.id)) {
|
|
3125
|
+
const unsubscribe = connection.generation.subscribe(() => {
|
|
3126
|
+
if (!dispatchStarted || disposed) return;
|
|
3127
|
+
const current = connection.generation.getSnapshot();
|
|
3128
|
+
if (current === void 0) {
|
|
3129
|
+
clearObserved = true;
|
|
3130
|
+
publish();
|
|
3131
|
+
} else if (current.id !== previous.id) dispose();
|
|
3132
|
+
});
|
|
3133
|
+
cleanups.push(unsubscribe);
|
|
3134
|
+
if (connection.generation.getSnapshot()?.id !== previous.id) dispose();
|
|
3135
|
+
else {
|
|
3136
|
+
const timer = setTimeout(() => dispose(), 3e4);
|
|
3137
|
+
cleanups.push(() => clearTimeout(timer));
|
|
3138
|
+
const onAbort = () => dispose();
|
|
3139
|
+
startupAbort.signal.addEventListener("abort", onAbort, { once: true });
|
|
3140
|
+
cleanups.push(() => startupAbort.signal.removeEventListener("abort", onAbort));
|
|
3141
|
+
if (startupAbort.signal.aborted) dispose();
|
|
3142
|
+
else dropGenerationObservation = { dispose };
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
try {
|
|
3146
|
+
dispatchStarted = true;
|
|
3147
|
+
transport?.dropWebSocketsForQualification();
|
|
3148
|
+
} catch (error) {
|
|
3149
|
+
dispose();
|
|
3150
|
+
throw error;
|
|
3151
|
+
}
|
|
2554
3152
|
emit({
|
|
2555
3153
|
m4a0: "qualification",
|
|
2556
3154
|
op: "drop-websocket",
|
|
@@ -2558,6 +3156,8 @@ async function runLocalClientEntry(options) {
|
|
|
2558
3156
|
pid: process.pid,
|
|
2559
3157
|
...request.requestId === void 0 ? {} : { requestId: request.requestId }
|
|
2560
3158
|
});
|
|
3159
|
+
ackEmitted = true;
|
|
3160
|
+
publish();
|
|
2561
3161
|
return false;
|
|
2562
3162
|
}
|
|
2563
3163
|
if (request.op === "qualification-host-foundation") {
|
|
@@ -2570,7 +3170,7 @@ async function runLocalClientEntry(options) {
|
|
|
2570
3170
|
if (workspaceResume === true && workspacePath === void 0) throw new Error("local client entry: the generation-resume control requires a workspacePath");
|
|
2571
3171
|
const schedule = qualificationRequest.schedule;
|
|
2572
3172
|
if (schedule !== void 0 && schedule !== true) throw new Error("local client entry: schedule must be the boolean true when supplied");
|
|
2573
|
-
const { runHostFoundationProbe } = await import("./host-foundation-probe-
|
|
3173
|
+
const { runHostFoundationProbe } = await import("./host-foundation-probe-DlD8-N_Q.mjs");
|
|
2574
3174
|
const proof = await runHostFoundationProbe(context, {
|
|
2575
3175
|
dshAnchor: options.dshAnchor,
|
|
2576
3176
|
host,
|
|
@@ -2612,7 +3212,7 @@ async function runLocalClientEntry(options) {
|
|
|
2612
3212
|
return;
|
|
2613
3213
|
}
|
|
2614
3214
|
const failure = terminalError ?? error;
|
|
2615
|
-
|
|
3215
|
+
const primary = isErrorValue(failure) ? failure : new Error(safeErrorMessage(failure));
|
|
2616
3216
|
const cleanupErrors = [];
|
|
2617
3217
|
const timedOut = await disposeWithinDeadline(async () => {
|
|
2618
3218
|
if (rootReleased) return;
|
|
@@ -2663,22 +3263,22 @@ async function runLocalClientEntry(options) {
|
|
|
2663
3263
|
}
|
|
2664
3264
|
rootReleased = true;
|
|
2665
3265
|
}, cleanupErrors);
|
|
2666
|
-
|
|
2667
|
-
const transportCleanupFailed = error
|
|
3266
|
+
const filePrimary = clientFatalPrimaryWithCleanup(primary, cleanupErrors);
|
|
3267
|
+
const transportCleanupFailed = isErrorValue(error) && error.cleanupFailed === true || cleanupErrors.some((cleanupError) => isErrorValue(cleanupError) && cleanupError.cleanupFailed === true);
|
|
2668
3268
|
emit({
|
|
2669
3269
|
m4a0: "failure",
|
|
2670
3270
|
processRole: "client",
|
|
2671
3271
|
phase: context === void 0 ? "startup" : "after-context",
|
|
2672
3272
|
pid: process.pid,
|
|
2673
3273
|
...traceTransportStatus(),
|
|
2674
|
-
...failure
|
|
2675
|
-
error:
|
|
2676
|
-
...
|
|
2677
|
-
...
|
|
3274
|
+
...isLocalScopeErrorValue(failure) ? { code: failure.code } : {},
|
|
3275
|
+
error: filePrimary.message,
|
|
3276
|
+
...filePrimary.stack === void 0 ? {} : { stack: filePrimary.stack },
|
|
3277
|
+
...filePrimary.cause === void 0 ? {} : { cause: isErrorValue(filePrimary.cause) ? filePrimary.cause.message : safeErrorMessage(filePrimary.cause) }
|
|
2678
3278
|
});
|
|
2679
3279
|
if (options.mode === "surface") {
|
|
2680
|
-
const
|
|
2681
|
-
process.stderr.write(`${
|
|
3280
|
+
const phase = handle === void 0 ? context === void 0 ? "pre-context" : "client-assembly" : "client-runtime";
|
|
3281
|
+
process.stderr.write(`${reportSurfaceClientFatal(failure, options.profile, phase, expectedHostInstanceId !== void 0, process.env, filePrimary)}\n`);
|
|
2682
3282
|
}
|
|
2683
3283
|
process.stdin.pause();
|
|
2684
3284
|
if (cleanupErrors.length === 0 && !timedOut && !transportCleanupFailed) emit({
|
|
@@ -2702,12 +3302,14 @@ async function runLocalClientEntry(options) {
|
|
|
2702
3302
|
if (timedOut || transportCleanupFailed) forceExitAfterCleanupFailure();
|
|
2703
3303
|
} finally {
|
|
2704
3304
|
process.stdin.pause();
|
|
3305
|
+
const programResumeForReexec = programResumeHandle?.forReexec();
|
|
2705
3306
|
const reexecExitCode = await finishClientEntryShutdown({
|
|
2706
3307
|
seat,
|
|
2707
3308
|
...reexecIntent === void 0 ? {} : { reexec: {
|
|
2708
3309
|
intent: reexecIntent,
|
|
2709
3310
|
teardownSucceeded: reexecTeardownSucceeded,
|
|
2710
|
-
cancelled: () => reexecCancelled
|
|
3311
|
+
cancelled: () => reexecCancelled,
|
|
3312
|
+
...programResumeForReexec === void 0 ? {} : { programResume: programResumeForReexec }
|
|
2711
3313
|
} },
|
|
2712
3314
|
emit,
|
|
2713
3315
|
stderr: (line) => {
|
|
@@ -2764,37 +3366,61 @@ function shellProfileArg(profile) {
|
|
|
2764
3366
|
return `'${profile.replace(/'/gu, "'\\''")}'`;
|
|
2765
3367
|
}
|
|
2766
3368
|
/**
|
|
2767
|
-
* The human-facing surface line for one startup failure.
|
|
2768
|
-
* protocol/
|
|
2769
|
-
*
|
|
2770
|
-
*
|
|
2771
|
-
*
|
|
2772
|
-
*
|
|
2773
|
-
* guidance.
|
|
3369
|
+
* The human-facing surface line for one startup failure. Host Typed
|
|
3370
|
+
* protocol/auth/scope refusals keep their dedicated actionable line: the code,
|
|
3371
|
+
* the untouched Host and the public daemon management commands for THIS
|
|
3372
|
+
* official Profile. A Client-local failure is classified on the Client side
|
|
3373
|
+
* and never pretends `daemon logs` contains its detail. It never includes the
|
|
3374
|
+
* registry PID, the launch URL/token or a private profile path.
|
|
2774
3375
|
*/
|
|
2775
|
-
function surfaceStartupFailureLine(error, profile) {
|
|
3376
|
+
function surfaceStartupFailureLine(error, profile, phase = "client-assembly") {
|
|
2776
3377
|
const daemon = (verb) => `dsh --profile ${shellProfileArg(profile)} daemon ${verb}`;
|
|
2777
|
-
if (error
|
|
3378
|
+
if (isLocalScopeErrorValue(error)) {
|
|
2778
3379
|
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.`;
|
|
2779
3380
|
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.`;
|
|
2780
3381
|
}
|
|
2781
|
-
return `split client surface: ${controlledSurfaceReason(error,
|
|
3382
|
+
return `split client surface: ${controlledSurfaceReason(error, phase)}`;
|
|
3383
|
+
}
|
|
3384
|
+
/**
|
|
3385
|
+
* The ONE pure Client-local terminal summary. A missing Client module names
|
|
3386
|
+
* only the safely extracted specifier and points at reinstalling the TUI
|
|
3387
|
+
* plugin; every other failure stays a fixed controlled reason and never
|
|
3388
|
+
* suggests a Host restart, because the Host is not the failing component.
|
|
3389
|
+
*/
|
|
3390
|
+
function controlledSurfaceReason(error, phase) {
|
|
3391
|
+
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.`;
|
|
3392
|
+
if (phase === "client-runtime") return "CLIENT_RUNTIME_FAILED: the Client terminated unexpectedly. The Host was not stopped.";
|
|
3393
|
+
const entryPrefix = "local client entry: ";
|
|
3394
|
+
let raw;
|
|
3395
|
+
try {
|
|
3396
|
+
raw = isErrorValue(error) ? error.message : String(error);
|
|
3397
|
+
} catch {
|
|
3398
|
+
raw = "";
|
|
3399
|
+
}
|
|
3400
|
+
if (raw.startsWith(entryPrefix)) return `CLIENT_STARTUP_FAILED: ${sanitizeSurfaceText(raw.slice(20))}. The Host was not stopped.`;
|
|
3401
|
+
return "CLIENT_STARTUP_FAILED: startup failed before the TUI mounted. The Host was not stopped.";
|
|
3402
|
+
}
|
|
3403
|
+
/**
|
|
3404
|
+
* The ONE surface fatal reporter: build the pure terminal summary, append the
|
|
3405
|
+
* terminal-safe private-file locator, and write exactly one Client artifact.
|
|
3406
|
+
* Used only at the three real fatal entry points (outer catch, body catch and
|
|
3407
|
+
* the stop coordinator), never from an ordinary pure-function test path.
|
|
3408
|
+
*/
|
|
3409
|
+
function reportSurfaceClientFatal(failure, profile, phase, isHandoff, env, primary = failure) {
|
|
3410
|
+
return `${isHandoff ? handoffStartupFailureLine(failure) : surfaceStartupFailureLine(failure, profile, phase)} ${clientDiagnosticLocation(writeClientFatalDiagnostic(primary, phase, env))}`;
|
|
2782
3411
|
}
|
|
2783
3412
|
/**
|
|
2784
|
-
* The
|
|
2785
|
-
*
|
|
2786
|
-
*
|
|
2787
|
-
* in the controlled Client/Host log; the TTY never receives a raw error, a path
|
|
2788
|
-
* or a Host launch URL.
|
|
3413
|
+
* The stop-coordinator report entry: merge its collected cleanup causes into
|
|
3414
|
+
* the ONE artifact primary while the terminal classification stays on the
|
|
3415
|
+
* original failure.
|
|
2789
3416
|
*/
|
|
2790
|
-
function
|
|
2791
|
-
|
|
2792
|
-
if (raw.startsWith("local client entry: ")) return `${sanitizeSurfaceText(raw.slice(20))} The Host was not stopped. Inspect with: ${daemon("status")} and ${daemon("logs")}; if you choose to recover, run ${daemon("restart")} (not guaranteed).`;
|
|
2793
|
-
return `startup failed before the TUI mounted; see the Host log for detail. The Host was not stopped. Inspect with: ${daemon("status")} and ${daemon("logs")}; if you choose to recover, run ${daemon("restart")} (not guaranteed).`;
|
|
3417
|
+
function reportStopClientFatal(failure, profile, phase, isHandoff, env, cleanupErrors) {
|
|
3418
|
+
return reportSurfaceClientFatal(failure, profile, phase, isHandoff, env, clientFatalPrimaryWithCleanup(failure, cleanupErrors));
|
|
2794
3419
|
}
|
|
2795
|
-
/** Strip control characters, URLs and absolute paths; bound the length. */
|
|
3420
|
+
/** Strip control characters, known credential carriers, URLs and absolute paths; bound the length. */
|
|
2796
3421
|
function sanitizeSurfaceText(text) {
|
|
2797
|
-
let out = text.replace(
|
|
3422
|
+
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>");
|
|
3423
|
+
out = out.replace(/[\u0000-\u001f\u007f]/gu, " ");
|
|
2798
3424
|
out = out.replace(/[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s'"]+/gu, "<url>");
|
|
2799
3425
|
out = out.replace(/(?:\/[\w.@+-]+){2,}\/?/gu, "<path>");
|
|
2800
3426
|
out = out.replace(/\s+/gu, " ").trim().slice(0, 200);
|
|
@@ -2812,12 +3438,12 @@ function sanitizeSurfaceText(text) {
|
|
|
2812
3438
|
*/
|
|
2813
3439
|
function handoffStartupFailureLine(error) {
|
|
2814
3440
|
let reason;
|
|
2815
|
-
if (error
|
|
3441
|
+
if (isLocalScopeErrorValue(error)) {
|
|
2816
3442
|
if (error.code === "HOST_HANDOFF_UNAVAILABLE") reason = "the expected Host is no longer available";
|
|
2817
3443
|
else if (error.code === "HOST_IDENTITY_MISMATCH") reason = "the live local Host is not the expected instance";
|
|
2818
3444
|
else if (error.code === "HOST_PROTOCOL_INCOMPATIBLE") reason = "the expected Host uses a different local protocol or DSH runtime";
|
|
2819
3445
|
else reason = "the expected Host could not be authenticated";
|
|
2820
|
-
} else if (error
|
|
3446
|
+
} 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));
|
|
2821
3447
|
else reason = "the replacement Client could not restore the expected Host and Session";
|
|
2822
3448
|
return `Client handoff failed: ${reason}. The Host was not stopped or replaced. Start a compatible Client manually to continue.`;
|
|
2823
3449
|
}
|
|
@@ -2856,10 +3482,10 @@ if (import.meta.main) try {
|
|
|
2856
3482
|
};
|
|
2857
3483
|
if (process.env.SPLIT_PROCESS_CLIENT_MODE === "surface") {
|
|
2858
3484
|
const handoff = process.env.SPLIT_PROCESS_CLIENT_EXPECTED_INSTANCE_ID;
|
|
2859
|
-
const line =
|
|
3485
|
+
const line = reportSurfaceClientFatal(error, process.env.SPLIT_PROCESS_PROFILE ?? "pi-tui", "pre-entry", handoff !== void 0 && handoff !== "", process.env);
|
|
2860
3486
|
process.stderr.write(`${line}\n`);
|
|
2861
3487
|
} else writeEntryRecord(record);
|
|
2862
3488
|
process.exit(1);
|
|
2863
3489
|
}
|
|
2864
3490
|
//#endregion
|
|
2865
|
-
export { ClientReexecRefusal, INTERACTION_STARTUP_GATE, assertHandoffRestored, assertHandoffSignalExclusivity, assertInteractionStartupReady, createClientReexecChildEnvironment, createClientReexecRequestHandler, createInteractionStartupGate, decodeClientLaunchEnvelope, expectedHostInstanceFromEnvironment, finishClientEntryShutdown, handoffStartupFailureLine, inspectClientReexecTarget, prepareClientReexec, resolveProfileInstalledClientTarget, routeReexecTermination, runLocalClientEntry, sanitizeSurfaceText, stopLocalClient, surfaceStartupFacts, surfaceStartupFailureLine };
|
|
3491
|
+
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 };
|