@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
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
//#region src/app/remote-process/local-workspace-object.ts
|
|
3
|
+
/**
|
|
4
|
+
* The Host-owned read-only directory-object observation route.
|
|
5
|
+
*
|
|
6
|
+
* The automatic Workspace proposal must prove that the authenticated Host
|
|
7
|
+
* process sees the SAME directory object `(dev, ino)` the Client launched in.
|
|
8
|
+
* Same path spelling is never evidence: only the Host's own `stat` proves the
|
|
9
|
+
* Host filesystem view, and the route is reachable only through the official
|
|
10
|
+
* Connection Owner admission (the exact Fetch route is registered with
|
|
11
|
+
* `connection.fetch.register`, so a non-Owner request is refused before this
|
|
12
|
+
* handler runs).
|
|
13
|
+
*
|
|
14
|
+
* The route is deliberately READ-ONLY: it never registers a Workspace, never
|
|
15
|
+
* lists a directory, never creates a Session and never returns file content or
|
|
16
|
+
* a path. It is not a general-purpose filesystem probe: the path is echoed
|
|
17
|
+
* nowhere, and every failure is one stable HTTP status.
|
|
18
|
+
*
|
|
19
|
+
* @module app/remote-process/local-workspace-object
|
|
20
|
+
*/
|
|
21
|
+
/** The exact Owner-only route path on the official local Connection. */
|
|
22
|
+
const LOCAL_WORKSPACE_OBJECT_ROUTE = "/api/pi-tui.workspace-object";
|
|
23
|
+
/** Hard request-body bound (plan §7). */
|
|
24
|
+
const MAX_WORKSPACE_OBJECT_REQUEST_BYTES = 8192;
|
|
25
|
+
/** Hard absolute-path bound in UTF-8 bytes. */
|
|
26
|
+
const MAX_WORKSPACE_OBJECT_PATH_BYTES = 4096;
|
|
27
|
+
/** Hard response-body bound the Client accepts. */
|
|
28
|
+
const MAX_WORKSPACE_OBJECT_RESPONSE_BYTES = 1024;
|
|
29
|
+
/** Bound on one loopback observation after any caller cancellation has been
|
|
30
|
+
* combined with it. The route is local; a stalled response is never evidence. */
|
|
31
|
+
const WORKSPACE_OBJECT_TIMEOUT_MS = 1e4;
|
|
32
|
+
/** The exact request keys. */
|
|
33
|
+
const REQUEST_KEYS = ["instanceId", "path"];
|
|
34
|
+
/** The exact response keys. */
|
|
35
|
+
const RESPONSE_KEYS = [
|
|
36
|
+
"schema",
|
|
37
|
+
"instanceId",
|
|
38
|
+
"device",
|
|
39
|
+
"inode"
|
|
40
|
+
];
|
|
41
|
+
const DECIMAL = /^\d+$/u;
|
|
42
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
|
|
43
|
+
function isRecord(value) {
|
|
44
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
45
|
+
}
|
|
46
|
+
function hasExactKeys(record, keys) {
|
|
47
|
+
const actual = Object.keys(record).sort();
|
|
48
|
+
const expected = [...keys].sort();
|
|
49
|
+
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
50
|
+
}
|
|
51
|
+
/** Read at most `maxBytes` of a request body; an oversize body is rejected. */
|
|
52
|
+
async function readBoundedBody(request, maxBytes) {
|
|
53
|
+
const declared = request.headers.get("content-length");
|
|
54
|
+
if (declared !== null && Number(declared) > maxBytes) return void 0;
|
|
55
|
+
if (request.body === null) return "";
|
|
56
|
+
const reader = request.body.getReader();
|
|
57
|
+
const chunks = [];
|
|
58
|
+
let total = 0;
|
|
59
|
+
try {
|
|
60
|
+
for (;;) {
|
|
61
|
+
const { done, value } = await reader.read();
|
|
62
|
+
if (done) break;
|
|
63
|
+
total += value.byteLength;
|
|
64
|
+
if (total > maxBytes) {
|
|
65
|
+
await reader.cancel();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
chunks.push(value);
|
|
69
|
+
}
|
|
70
|
+
} finally {
|
|
71
|
+
reader.releaseLock();
|
|
72
|
+
}
|
|
73
|
+
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk))).toString("utf8");
|
|
74
|
+
}
|
|
75
|
+
function jsonResponse(body, status = 200) {
|
|
76
|
+
return new Response(JSON.stringify(body), {
|
|
77
|
+
status,
|
|
78
|
+
headers: {
|
|
79
|
+
"content-type": "application/json",
|
|
80
|
+
"cache-control": "no-store"
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/** The status-only failure: no path, host detail or system error crosses it. */
|
|
85
|
+
function failure(status) {
|
|
86
|
+
return new Response(null, {
|
|
87
|
+
status,
|
|
88
|
+
headers: { "cache-control": "no-store" }
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** Validate one absolute path against the route's hard limits. */
|
|
92
|
+
function isBoundedAbsolutePath(value) {
|
|
93
|
+
if (typeof value !== "string" || value === "" || value.includes("\0")) return false;
|
|
94
|
+
if (!value.startsWith("/")) return false;
|
|
95
|
+
return Buffer.byteLength(value, "utf8") <= MAX_WORKSPACE_OBJECT_PATH_BYTES;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Build the ONE Host route handler. It answers only for the CURRENT Host
|
|
99
|
+
* instance and only for a directory the Host itself can `stat`; the returned
|
|
100
|
+
* `(dev, ino)` are exact decimal strings, so a 64-bit inode is never truncated
|
|
101
|
+
* by JS number precision.
|
|
102
|
+
*/
|
|
103
|
+
function createWorkspaceObjectHandler(currentInstanceId, statDirectory = defaultStatDirectory) {
|
|
104
|
+
return async (request) => {
|
|
105
|
+
if (request.method !== "POST") return failure(405);
|
|
106
|
+
const contentType = request.headers.get("content-type") ?? "";
|
|
107
|
+
if (!/^application\/json\b/iu.test(contentType)) return failure(400);
|
|
108
|
+
const text = await readBoundedBody(request, MAX_WORKSPACE_OBJECT_REQUEST_BYTES);
|
|
109
|
+
if (text === void 0) return failure(413);
|
|
110
|
+
let value;
|
|
111
|
+
try {
|
|
112
|
+
value = JSON.parse(text);
|
|
113
|
+
} catch {
|
|
114
|
+
return failure(400);
|
|
115
|
+
}
|
|
116
|
+
if (!isRecord(value) || !hasExactKeys(value, REQUEST_KEYS)) return failure(400);
|
|
117
|
+
if (value.instanceId !== currentInstanceId || !UUID_PATTERN.test(currentInstanceId)) return failure(409);
|
|
118
|
+
if (!isBoundedAbsolutePath(value.path)) return failure(400);
|
|
119
|
+
let directory;
|
|
120
|
+
try {
|
|
121
|
+
directory = statDirectory(value.path);
|
|
122
|
+
} catch {
|
|
123
|
+
return failure(404);
|
|
124
|
+
}
|
|
125
|
+
if (!directory.isDirectory()) return failure(404);
|
|
126
|
+
return jsonResponse({
|
|
127
|
+
schema: 1,
|
|
128
|
+
instanceId: currentInstanceId,
|
|
129
|
+
device: directory.dev,
|
|
130
|
+
inode: directory.ino
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** The production directory observation: exact `bigint` stat converted to
|
|
135
|
+
* decimal strings. `realpath` is deliberately NOT used: the object identity
|
|
136
|
+
* is the one the Host sees at the requested absolute path. */
|
|
137
|
+
function defaultStatDirectory(path) {
|
|
138
|
+
const stat = statSync(path, { bigint: true });
|
|
139
|
+
return {
|
|
140
|
+
isDirectory: () => stat.isDirectory(),
|
|
141
|
+
dev: stat.dev.toString(),
|
|
142
|
+
ino: stat.ino.toString()
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Ask the authenticated Host for its view of one absolute directory path.
|
|
147
|
+
* Every failure — transport, non-200, malformed/oversized body, wrong instance
|
|
148
|
+
* or non-decimal object — is an explicit `unverified`; a successful response is
|
|
149
|
+
* only an observation, never a WorkspaceId or permission.
|
|
150
|
+
*/
|
|
151
|
+
async function observeHostWorkspaceObject(fetchAuthenticated, origin, instanceId, path, signal) {
|
|
152
|
+
const requestSignal = signal === void 0 ? AbortSignal.timeout(WORKSPACE_OBJECT_TIMEOUT_MS) : AbortSignal.any([signal, AbortSignal.timeout(WORKSPACE_OBJECT_TIMEOUT_MS)]);
|
|
153
|
+
if (Boolean(signal?.aborted)) return {
|
|
154
|
+
kind: "unverified",
|
|
155
|
+
reason: "the Host workspace object observation was aborted"
|
|
156
|
+
};
|
|
157
|
+
let response;
|
|
158
|
+
try {
|
|
159
|
+
response = await fetchAuthenticated(`${origin}${LOCAL_WORKSPACE_OBJECT_ROUTE}`, {
|
|
160
|
+
method: "POST",
|
|
161
|
+
headers: { "content-type": "application/json" },
|
|
162
|
+
body: JSON.stringify({
|
|
163
|
+
instanceId,
|
|
164
|
+
path
|
|
165
|
+
}),
|
|
166
|
+
signal: requestSignal
|
|
167
|
+
});
|
|
168
|
+
} catch {
|
|
169
|
+
return {
|
|
170
|
+
kind: "unverified",
|
|
171
|
+
reason: Boolean(signal?.aborted) ? "the Host workspace object observation was aborted" : "the Host workspace object route is unreachable"
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (response.status !== 200) {
|
|
175
|
+
await response.body?.cancel();
|
|
176
|
+
return {
|
|
177
|
+
kind: "unverified",
|
|
178
|
+
reason: `the Host workspace object route answered HTTP ${String(response.status)}`
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
182
|
+
const cacheControl = response.headers.get("cache-control") ?? "";
|
|
183
|
+
if (!/^application\/json\b/iu.test(contentType) || !/\bno-store\b/iu.test(cacheControl)) {
|
|
184
|
+
await response.body?.cancel();
|
|
185
|
+
return {
|
|
186
|
+
kind: "unverified",
|
|
187
|
+
reason: "the Host workspace object response has the wrong shape"
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
let text;
|
|
191
|
+
try {
|
|
192
|
+
text = await readResponseText(response, MAX_WORKSPACE_OBJECT_RESPONSE_BYTES);
|
|
193
|
+
} catch {
|
|
194
|
+
return {
|
|
195
|
+
kind: "unverified",
|
|
196
|
+
reason: "the Host workspace object response exceeds its bound"
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
let value;
|
|
200
|
+
try {
|
|
201
|
+
value = JSON.parse(text);
|
|
202
|
+
} catch {
|
|
203
|
+
return {
|
|
204
|
+
kind: "unverified",
|
|
205
|
+
reason: "the Host workspace object response is not JSON"
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (!isRecord(value) || !hasExactKeys(value, RESPONSE_KEYS)) return {
|
|
209
|
+
kind: "unverified",
|
|
210
|
+
reason: "the Host workspace object response has unexpected fields"
|
|
211
|
+
};
|
|
212
|
+
if (value.schema !== 1 || value.instanceId !== instanceId) return {
|
|
213
|
+
kind: "unverified",
|
|
214
|
+
reason: "the Host workspace object response names another instance or schema"
|
|
215
|
+
};
|
|
216
|
+
if (typeof value.device !== "string" || !DECIMAL.test(value.device) || typeof value.inode !== "string" || !DECIMAL.test(value.inode)) return {
|
|
217
|
+
kind: "unverified",
|
|
218
|
+
reason: "the Host workspace object response is not an exact decimal object"
|
|
219
|
+
};
|
|
220
|
+
return {
|
|
221
|
+
kind: "observed",
|
|
222
|
+
device: value.device,
|
|
223
|
+
inode: value.inode
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
async function readResponseText(response, maxBytes) {
|
|
227
|
+
if (response.body === null) return "";
|
|
228
|
+
const reader = response.body.getReader();
|
|
229
|
+
const chunks = [];
|
|
230
|
+
let total = 0;
|
|
231
|
+
try {
|
|
232
|
+
for (;;) {
|
|
233
|
+
const { done, value } = await reader.read();
|
|
234
|
+
if (done) break;
|
|
235
|
+
total += value.byteLength;
|
|
236
|
+
if (total > maxBytes) {
|
|
237
|
+
await reader.cancel();
|
|
238
|
+
throw new Error("local workspace object: response exceeds its bound");
|
|
239
|
+
}
|
|
240
|
+
chunks.push(value);
|
|
241
|
+
}
|
|
242
|
+
} finally {
|
|
243
|
+
reader.releaseLock();
|
|
244
|
+
}
|
|
245
|
+
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk))).toString("utf8");
|
|
246
|
+
}
|
|
247
|
+
//#endregion
|
|
248
|
+
export { createWorkspaceObjectHandler as n, observeHostWorkspaceObject as r, LOCAL_WORKSPACE_OBJECT_ROUTE as t };
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
//#region src/client/url/open.ts
|
|
3
|
+
/**
|
|
4
|
+
* Open one external URL with the platform opener (fullscreen OSC 8 link
|
|
5
|
+
* clicks — the alt screen's mouse capture swallows the terminal's native
|
|
6
|
+
* click-to-open, so the host owns link activation; the fork reports the
|
|
7
|
+
* URL through its `openUrl` seam).
|
|
8
|
+
*
|
|
9
|
+
* SECURITY: only http/https URLs ever reach an opener — the OSC 8 href
|
|
10
|
+
* comes from rendered transcript content, and `file:`/custom schemes
|
|
11
|
+
* would hand attacker-controlled strings to a shell helper. Fire-and-
|
|
12
|
+
* forget: opener failures are best-effort (a link click must never
|
|
13
|
+
* disturb the TUI).
|
|
14
|
+
* @module @xmoon76/dsh-pi-tui/client/url/open
|
|
15
|
+
*/
|
|
16
|
+
function openExternalUrl(rawUrl) {
|
|
17
|
+
let url;
|
|
18
|
+
try {
|
|
19
|
+
url = new URL(rawUrl);
|
|
20
|
+
} catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") return;
|
|
24
|
+
const { command, args } = openerFor(url.href, process.platform);
|
|
25
|
+
try {
|
|
26
|
+
const child = spawn(command, args, {
|
|
27
|
+
stdio: "ignore",
|
|
28
|
+
detached: true
|
|
29
|
+
});
|
|
30
|
+
child.on("error", () => {});
|
|
31
|
+
child.unref();
|
|
32
|
+
} catch {}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The platform opener command line. WINDOWS INJECTION SAFETY (round-2
|
|
36
|
+
* review P1): `cmd /c start` re-parses its command line with shell
|
|
37
|
+
* metacharacter rules, so a transcript-controlled `&` in a query string
|
|
38
|
+
* would split into a second COMMAND. The URL is therefore wrapped in
|
|
39
|
+
* literal double quotes — the WHATWG URL serializer never emits a raw
|
|
40
|
+
* quote/space/control character in href, so the quoted token cannot be
|
|
41
|
+
* escaped — and cmd treats everything inside double quotes as literal.
|
|
42
|
+
*/
|
|
43
|
+
function openerFor(href, platform = process.platform) {
|
|
44
|
+
if (platform === "win32") return {
|
|
45
|
+
command: "cmd",
|
|
46
|
+
args: [
|
|
47
|
+
"/c",
|
|
48
|
+
"start",
|
|
49
|
+
"",
|
|
50
|
+
`"${href}"`
|
|
51
|
+
]
|
|
52
|
+
};
|
|
53
|
+
if (platform === "darwin") return {
|
|
54
|
+
command: "open",
|
|
55
|
+
args: [href]
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
command: "xdg-open",
|
|
59
|
+
args: [href]
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { openerFor as n, openExternalUrl as t };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
//#region src/app/remote-process/persisted-setting-probe.ts
|
|
4
|
+
/**
|
|
5
|
+
* Qualification-only two-Client probe for the persisted extension-setting
|
|
6
|
+
* writer (R8-E PR-4).
|
|
7
|
+
*
|
|
8
|
+
* Two REAL surface Client processes each run on their own production
|
|
9
|
+
* `ConfigPort` (the Remote adapter over the ONE Host Settings mirror). The
|
|
10
|
+
* probe coordinates through files in the smoke work root:
|
|
11
|
+
*
|
|
12
|
+
* ```text
|
|
13
|
+
* B reads A's revision -> A commits label=omega at that revision
|
|
14
|
+
* -> B's captured-revision Confirm is a conflict
|
|
15
|
+
* -> B refreshes and commits its OWN limit=11
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* No Context, mirror or Settings authority is created here. Production never
|
|
19
|
+
* sets the enabling environment variable, and the result is a JSON-safe
|
|
20
|
+
* qualification record in the existing Client record sink.
|
|
21
|
+
*
|
|
22
|
+
* @module @xmoon76/dsh-pi-tui/app/remote-process/persisted-setting-probe
|
|
23
|
+
*/
|
|
24
|
+
function packagesEnv() {
|
|
25
|
+
const raw = process.env.SPLIT_PROCESS_CLIENT_PERSISTED_SETTING_PACKAGES;
|
|
26
|
+
if (raw === void 0 || raw === "") throw new Error("persisted-setting probe: SPLIT_PROCESS_CLIENT_PERSISTED_SETTING_PACKAGES is not set");
|
|
27
|
+
const parsed = JSON.parse(raw);
|
|
28
|
+
if (typeof parsed.a !== "string" || parsed.a === "" || typeof parsed.b !== "string" || parsed.b === "") throw new Error("persisted-setting probe: package names a and b are required");
|
|
29
|
+
return {
|
|
30
|
+
a: parsed.a,
|
|
31
|
+
b: parsed.b
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function probeRole() {
|
|
35
|
+
const role = process.env.SPLIT_PROCESS_CLIENT_PERSISTED_SETTING_ROLE;
|
|
36
|
+
if (role !== "A" && role !== "B") throw new Error("persisted-setting probe: SPLIT_PROCESS_CLIENT_PERSISTED_SETTING_ROLE must be A or B");
|
|
37
|
+
return role;
|
|
38
|
+
}
|
|
39
|
+
function probeDir() {
|
|
40
|
+
const dir = process.env.SPLIT_PROCESS_CLIENT_PERSISTED_SETTING_DIR;
|
|
41
|
+
if (dir === void 0 || dir === "") throw new Error("persisted-setting probe: SPLIT_PROCESS_CLIENT_PERSISTED_SETTING_DIR is not set");
|
|
42
|
+
return dir;
|
|
43
|
+
}
|
|
44
|
+
function writeJson(dir, name, value) {
|
|
45
|
+
writeFileSync(join(dir, name), `${JSON.stringify(value)}\n`);
|
|
46
|
+
}
|
|
47
|
+
async function waitJson(dir, name, label, timeoutMs = 12e4) {
|
|
48
|
+
const deadline = Date.now() + timeoutMs;
|
|
49
|
+
const path = join(dir, name);
|
|
50
|
+
while (Date.now() < deadline) {
|
|
51
|
+
if (existsSync(path)) return JSON.parse(readFileSync(path, "utf8"));
|
|
52
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
53
|
+
}
|
|
54
|
+
throw new Error(`persisted-setting probe: timed out waiting for ${label}`);
|
|
55
|
+
}
|
|
56
|
+
function clientStatuses(observations) {
|
|
57
|
+
return Object.fromEntries(observations.map((observation) => [observation.packageName, observation.phase]));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Run the fixed two-Client persisted-setting probe.
|
|
61
|
+
*
|
|
62
|
+
* @param config - this surface revision's production ConfigPort.
|
|
63
|
+
* @param observations - this Client's real Loader observations.
|
|
64
|
+
*/
|
|
65
|
+
async function runPersistedSettingProbe(config, observations) {
|
|
66
|
+
const packages = packagesEnv();
|
|
67
|
+
const role = probeRole();
|
|
68
|
+
const dir = probeDir();
|
|
69
|
+
if (role === "B") {
|
|
70
|
+
const a0 = config.extensionConfigs.read(packages.a);
|
|
71
|
+
const b0 = config.extensionConfigs.read(packages.b);
|
|
72
|
+
if (a0.kind !== "ready" || b0.kind !== "ready") throw new Error(`persisted-setting probe: both package rows must be readable (${a0.kind}/${b0.kind})`);
|
|
73
|
+
writeJson(dir, "b-read.json", { revision: a0.revision });
|
|
74
|
+
const committed = await waitJson(dir, "a-commit.json", "Client A commit");
|
|
75
|
+
const stale = await config.extensionConfigs.mutate(packages.a, [{
|
|
76
|
+
op: "set",
|
|
77
|
+
path: ["label"],
|
|
78
|
+
value: "stale-loser"
|
|
79
|
+
}], a0.revision, a0.generation);
|
|
80
|
+
const aAfter = config.extensionConfigs.read(packages.a);
|
|
81
|
+
await config.extensionConfigs.refresh();
|
|
82
|
+
const bFresh = config.extensionConfigs.read(packages.b);
|
|
83
|
+
if (bFresh.kind !== "ready") throw new Error("persisted-setting probe: B row became unreadable after refresh");
|
|
84
|
+
const bWrite = await config.extensionConfigs.mutate(packages.b, [{
|
|
85
|
+
op: "set",
|
|
86
|
+
path: ["limit"],
|
|
87
|
+
value: 11
|
|
88
|
+
}], bFresh.revision, bFresh.generation);
|
|
89
|
+
const bRead = config.extensionConfigs.read(packages.b);
|
|
90
|
+
const result = {
|
|
91
|
+
m4b2s: "qualification",
|
|
92
|
+
op: "persisted-setting-probe",
|
|
93
|
+
processRole: "B",
|
|
94
|
+
pid: process.pid,
|
|
95
|
+
packageA: packages.a,
|
|
96
|
+
packageB: packages.b,
|
|
97
|
+
aBefore: a0.kind,
|
|
98
|
+
bBefore: b0.kind,
|
|
99
|
+
aCommitted: committed.kind,
|
|
100
|
+
stale: stale.kind,
|
|
101
|
+
aAfter: aAfter.kind === "ready" ? {
|
|
102
|
+
effective: aAfter.effective,
|
|
103
|
+
user: aAfter.user
|
|
104
|
+
} : { kind: aAfter.kind },
|
|
105
|
+
bWrite: bWrite.kind,
|
|
106
|
+
bAfter: bRead.kind === "ready" ? {
|
|
107
|
+
effective: bRead.effective,
|
|
108
|
+
user: bRead.user
|
|
109
|
+
} : { kind: bRead.kind },
|
|
110
|
+
observations: clientStatuses(observations())
|
|
111
|
+
};
|
|
112
|
+
writeJson(dir, "b-result.json", result);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
const a0 = config.extensionConfigs.read(packages.a);
|
|
116
|
+
if (a0.kind !== "ready") throw new Error("persisted-setting probe: A row must be readable");
|
|
117
|
+
writeJson(dir, "a-read.json", { revision: a0.revision });
|
|
118
|
+
await waitJson(dir, "b-read.json", "Client B read");
|
|
119
|
+
const writeA = await config.extensionConfigs.mutate(packages.a, [{
|
|
120
|
+
op: "set",
|
|
121
|
+
path: ["label"],
|
|
122
|
+
value: "omega"
|
|
123
|
+
}], a0.revision, a0.generation);
|
|
124
|
+
const a1 = config.extensionConfigs.read(packages.a);
|
|
125
|
+
const result = {
|
|
126
|
+
m4b2s: "qualification",
|
|
127
|
+
op: "persisted-setting-probe",
|
|
128
|
+
processRole: "A",
|
|
129
|
+
pid: process.pid,
|
|
130
|
+
packageA: packages.a,
|
|
131
|
+
packageB: packages.b,
|
|
132
|
+
aBefore: a0.kind,
|
|
133
|
+
writeA: writeA.kind,
|
|
134
|
+
aAfter: a1.kind === "ready" ? {
|
|
135
|
+
effective: a1.effective,
|
|
136
|
+
user: a1.user
|
|
137
|
+
} : { kind: a1.kind },
|
|
138
|
+
observations: clientStatuses(observations())
|
|
139
|
+
};
|
|
140
|
+
writeJson(dir, "a-commit.json", result);
|
|
141
|
+
writeJson(dir, "a-result.json", result);
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
export { runPersistedSettingProbe };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region src/runtime/remote/pi-tui-acp-access-contract.ts
|
|
2
|
+
/** The wire namespace (and Host Cordis service key) of the listener control. */
|
|
3
|
+
const PI_TUI_ACP_ACCESS_NAMESPACE = "piTuiAcpAccess";
|
|
4
|
+
/** The status method's stable endpoint identity. */
|
|
5
|
+
const PI_TUI_ACP_ACCESS_GET_STATUS_ENDPOINT = "@xmoon76/dsh-pi-tui#piTuiAcpAccess/getStatus";
|
|
6
|
+
/** The mutation method's stable endpoint identity. */
|
|
7
|
+
const PI_TUI_ACP_ACCESS_SET_ENABLED_ENDPOINT = "@xmoon76/dsh-pi-tui#piTuiAcpAccess/setEnabled";
|
|
8
|
+
/** One strict JSON codec that validates a wire boolean. */
|
|
9
|
+
const BOOLEAN_CODEC = {
|
|
10
|
+
mode: "strict",
|
|
11
|
+
typeSymbol: "@xmoon76/dsh-pi-tui#piTuiAcpAccess/setEnabled:enabled",
|
|
12
|
+
create: () => ({ parse: (value) => {
|
|
13
|
+
if (typeof value !== "boolean") throw new TypeError("piTuiAcpAccess/setEnabled: the wire value must be a boolean");
|
|
14
|
+
return value;
|
|
15
|
+
} })
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Validate and detach one wire `PiTuiAcpAccessStatus`. The status is produced by
|
|
19
|
+
* this package's own Host service, but it is still a wire boundary on the Client
|
|
20
|
+
* and the ONLY place the shape crosses.
|
|
21
|
+
*/
|
|
22
|
+
function parsePiTuiAcpAccessStatus(value) {
|
|
23
|
+
if (typeof value !== "object" || value === null) throw new TypeError("piTuiAcpAccess: the result must be an object");
|
|
24
|
+
const record = value;
|
|
25
|
+
const field = record.state === "unavailable" ? "reason" : void 0;
|
|
26
|
+
for (const key of Object.keys(record)) if (key !== "state" && key !== field) throw new TypeError(`piTuiAcpAccess: unexpected result field ${JSON.stringify(key)}`);
|
|
27
|
+
if (record.state === "disabled" || record.state === "enabled" || record.state === "changing") return { state: record.state };
|
|
28
|
+
if (record.state !== "unavailable") throw new TypeError("piTuiAcpAccess: the result state must be disabled, enabled, changing or unavailable");
|
|
29
|
+
if (typeof record.reason !== "string" || record.reason === "") throw new TypeError("piTuiAcpAccess: an unavailable result needs a non-empty reason");
|
|
30
|
+
return {
|
|
31
|
+
state: "unavailable",
|
|
32
|
+
reason: record.reason
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const PI_TUI_ACP_ACCESS_STATUS_CODEC = {
|
|
36
|
+
mode: "strict",
|
|
37
|
+
typeSymbol: "@xmoon76/dsh-pi-tui#piTuiAcpAccess:status",
|
|
38
|
+
create: () => ({ parse: parsePiTuiAcpAccessStatus }),
|
|
39
|
+
decode: parsePiTuiAcpAccessStatus
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The `getStatus` invocation both contributions derive from. The Host registers
|
|
43
|
+
* this exact object; the Client mounts this exact object.
|
|
44
|
+
*/
|
|
45
|
+
const PI_TUI_ACP_ACCESS_GET_STATUS = {
|
|
46
|
+
id: PI_TUI_ACP_ACCESS_GET_STATUS_ENDPOINT,
|
|
47
|
+
service: PI_TUI_ACP_ACCESS_NAMESPACE,
|
|
48
|
+
namespace: PI_TUI_ACP_ACCESS_NAMESPACE,
|
|
49
|
+
method: "getStatus",
|
|
50
|
+
invocation: { kind: "direct" },
|
|
51
|
+
parameters: [],
|
|
52
|
+
result: PI_TUI_ACP_ACCESS_STATUS_CODEC
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The `setEnabled` invocation both contributions derive from. `enabled` is one
|
|
56
|
+
* required boolean: the Host Gateway decodes it through {@link BOOLEAN_CODEC}, so
|
|
57
|
+
* a malformed value is refused at the wire boundary and never reaches the
|
|
58
|
+
* listener.
|
|
59
|
+
*/
|
|
60
|
+
const PI_TUI_ACP_ACCESS_SET_ENABLED = {
|
|
61
|
+
id: PI_TUI_ACP_ACCESS_SET_ENABLED_ENDPOINT,
|
|
62
|
+
service: PI_TUI_ACP_ACCESS_NAMESPACE,
|
|
63
|
+
namespace: PI_TUI_ACP_ACCESS_NAMESPACE,
|
|
64
|
+
method: "setEnabled",
|
|
65
|
+
invocation: { kind: "direct" },
|
|
66
|
+
parameters: [{
|
|
67
|
+
name: "enabled",
|
|
68
|
+
wire: "enabled",
|
|
69
|
+
source: "json",
|
|
70
|
+
codec: BOOLEAN_CODEC
|
|
71
|
+
}],
|
|
72
|
+
result: PI_TUI_ACP_ACCESS_STATUS_CODEC
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
export { parsePiTuiAcpAccessStatus as i, PI_TUI_ACP_ACCESS_NAMESPACE as n, PI_TUI_ACP_ACCESS_SET_ENABLED as r, PI_TUI_ACP_ACCESS_GET_STATUS as t };
|