@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
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, join, sep } from "node:path";
|
|
4
|
+
//#region src/runtime/native-process/installed-dsh.ts
|
|
5
|
+
/**
|
|
6
|
+
* The installed `@deepseek-ai/dsh` anchor and module-closure primitives shared
|
|
7
|
+
* by the platform-native loaders.
|
|
8
|
+
*
|
|
9
|
+
* A real Direct launcher entry (`process.argv[1]`) identifies its own installed
|
|
10
|
+
* DSH package and always wins over an inherited environment anchor: a shell or
|
|
11
|
+
* tool child of a Split Host inherits SPLIT_PROCESS_DSH_ANCHOR, but a Direct
|
|
12
|
+
* `dsh` CLI started from it must use the installation executing that CLI. A
|
|
13
|
+
* caller that already holds the official profile's `installAnchor` may supply
|
|
14
|
+
* it explicitly (the Direct composition does); only a Split Host/Client entry,
|
|
15
|
+
* whose argv[1] is the product's own local-host/local-client script, falls back
|
|
16
|
+
* to the launcher-verified SPLIT_PROCESS_DSH_ANCHOR. No NODE_PATH, profile
|
|
17
|
+
* node_modules or source tree is consulted.
|
|
18
|
+
*
|
|
19
|
+
* Module lookup must prove the resolved dependency belongs to its owner's
|
|
20
|
+
* installation closure: npm keeps sibling dependencies in the owner's nearest
|
|
21
|
+
* `node_modules`; pnpm keeps every package in a shared virtual store (`.mise`
|
|
22
|
+
* in the mise install and `.pnpm` in a project install). Any other ancestor
|
|
23
|
+
* `node_modules` is an accidental hoist and must not supply a dependency.
|
|
24
|
+
*
|
|
25
|
+
* @module runtime/native-process/installed-dsh
|
|
26
|
+
*/
|
|
27
|
+
/** One installed `@deepseek-ai/dsh` manifest, or undefined when the path is
|
|
28
|
+
* unreadable, malformed, or belongs to another package. The name check is
|
|
29
|
+
* load-bearing: `createRequire` would otherwise walk into an unrelated ancestor
|
|
30
|
+
* `node_modules` and silently borrow a dependency that does not belong to the
|
|
31
|
+
* running DSH installation. */
|
|
32
|
+
function installedDshManifest(path) {
|
|
33
|
+
try {
|
|
34
|
+
const real = realpathSync(path);
|
|
35
|
+
const manifest = JSON.parse(readFileSync(real, "utf8"));
|
|
36
|
+
if (manifest === null || typeof manifest !== "object" || Array.isArray(manifest)) return void 0;
|
|
37
|
+
const record = manifest;
|
|
38
|
+
return record.name === "@deepseek-ai/dsh" && typeof record.version === "string" && record.version !== "" ? real : void 0;
|
|
39
|
+
} catch {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The installed `@deepseek-ai/dsh/package.json` this process runs on.
|
|
45
|
+
* @param explicitAnchor - an already-resolved official profile install anchor;
|
|
46
|
+
* when provided and valid it outranks the launcher and environment anchors.
|
|
47
|
+
*/
|
|
48
|
+
function installedDshAnchor(explicitAnchor) {
|
|
49
|
+
if (explicitAnchor !== void 0 && explicitAnchor !== "") {
|
|
50
|
+
const provided = installedDshManifest(explicitAnchor);
|
|
51
|
+
if (provided !== void 0) return provided;
|
|
52
|
+
}
|
|
53
|
+
const entry = process.argv[1];
|
|
54
|
+
if (entry !== void 0) try {
|
|
55
|
+
let dir = dirname(realpathSync(entry));
|
|
56
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
57
|
+
const anchor = installedDshManifest(join(dir, "package.json"));
|
|
58
|
+
if (anchor !== void 0) return anchor;
|
|
59
|
+
const parent = dirname(dir);
|
|
60
|
+
if (parent === dir) break;
|
|
61
|
+
dir = parent;
|
|
62
|
+
}
|
|
63
|
+
} catch {}
|
|
64
|
+
const provided = process.env.SPLIT_PROCESS_DSH_ANCHOR;
|
|
65
|
+
return provided !== void 0 && provided !== "" ? installedDshManifest(provided) : void 0;
|
|
66
|
+
}
|
|
67
|
+
/** The nearest `node_modules` directory above a package directory. */
|
|
68
|
+
function nearestModuleRoot(packageDir) {
|
|
69
|
+
for (let dir = packageDir;; dir = dirname(dir)) {
|
|
70
|
+
if (basename(dir) === "node_modules") return dir;
|
|
71
|
+
const parent = dirname(dir);
|
|
72
|
+
if (parent === dir) return void 0;
|
|
73
|
+
dir = parent;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Whether `path` is `root` or below it. */
|
|
77
|
+
function isInside(path, root) {
|
|
78
|
+
return path === root || path.startsWith(`${root}${sep}`);
|
|
79
|
+
}
|
|
80
|
+
/** Prove a resolved dependency belongs to its owner's installation closure. */
|
|
81
|
+
function assertInstallClosure(ownerDir, dependencyDir, label) {
|
|
82
|
+
const nearest = nearestModuleRoot(ownerDir);
|
|
83
|
+
if (nearest !== void 0 && isInside(dependencyDir, nearest)) return;
|
|
84
|
+
for (let dir = ownerDir;; dir = dirname(dir)) {
|
|
85
|
+
if ((basename(dir) === ".mise" || basename(dir) === ".pnpm") && isInside(dependencyDir, dir)) return;
|
|
86
|
+
const parent = dirname(dir);
|
|
87
|
+
if (parent === dir) break;
|
|
88
|
+
dir = parent;
|
|
89
|
+
}
|
|
90
|
+
throw new Error(`installed DSH module: ${label} resolved outside the installed DSH module tree`);
|
|
91
|
+
}
|
|
92
|
+
/** Read one JSON package manifest as an object, or undefined when unreadable. */
|
|
93
|
+
function readManifestObject(path) {
|
|
94
|
+
try {
|
|
95
|
+
const manifest = JSON.parse(readFileSync(realpathSync(path), "utf8"));
|
|
96
|
+
if (manifest === null || typeof manifest !== "object" || Array.isArray(manifest)) return void 0;
|
|
97
|
+
return manifest;
|
|
98
|
+
} catch {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Require one dependency declaration from an owner manifest. */
|
|
103
|
+
function assertDeclaredDependency(manifest, name, label) {
|
|
104
|
+
const dependencies = manifest.dependencies;
|
|
105
|
+
const declared = dependencies !== null && typeof dependencies === "object" && !Array.isArray(dependencies) ? dependencies[name] : void 0;
|
|
106
|
+
if (typeof declared !== "string" || declared === "") throw new Error(`installed DSH module: ${label} does not declare ${name}`);
|
|
107
|
+
}
|
|
108
|
+
/** Require one peer declaration from an owner manifest. */
|
|
109
|
+
function assertDeclaredPeerDependency(manifest, name, label) {
|
|
110
|
+
const peerDependencies = manifest.peerDependencies;
|
|
111
|
+
const declared = peerDependencies !== null && typeof peerDependencies === "object" && !Array.isArray(peerDependencies) ? peerDependencies[name] : void 0;
|
|
112
|
+
if (typeof declared !== "string" || declared === "") throw new Error(`installed DSH module: ${label} does not declare ${name} as a peer`);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Resolve the Koffi entry owned by the running DSH installation:
|
|
116
|
+
* DSH anchor -> `@deepseek-ai/dsh-subprocess-local` manifest -> that package's
|
|
117
|
+
* own `koffi` dependency. The TUI never resolves Koffi from its own package, a
|
|
118
|
+
* profile, or an ambient module path.
|
|
119
|
+
*
|
|
120
|
+
* The owner's declared dependency selects the implementation; this code does
|
|
121
|
+
* not pin or compare a Koffi version, because the running DSH installation owns
|
|
122
|
+
* that choice and an upgrade must not be rejected only for a different version
|
|
123
|
+
* number. The ABI/struct-size checks in the platform bridge decide actual
|
|
124
|
+
* compatibility.
|
|
125
|
+
*/
|
|
126
|
+
function resolveDshKoffi(anchor) {
|
|
127
|
+
const manifest = installedDshManifest(anchor);
|
|
128
|
+
if (manifest === void 0) throw new Error("native process identity: the DSH anchor is not an installed @deepseek-ai/dsh manifest");
|
|
129
|
+
const dshDir = dirname(manifest);
|
|
130
|
+
const subprocessManifest = realpathSync(createRequire(manifest).resolve("@deepseek-ai/dsh-subprocess-local/package.json"));
|
|
131
|
+
const subprocessDir = dirname(subprocessManifest);
|
|
132
|
+
assertInstallClosure(dshDir, subprocessDir, "@deepseek-ai/dsh-subprocess-local");
|
|
133
|
+
const subprocess = readManifestObject(subprocessManifest);
|
|
134
|
+
if (subprocess?.name !== "@deepseek-ai/dsh-subprocess-local") throw new Error("native process identity: the resolved subprocess manifest is not @deepseek-ai/dsh-subprocess-local");
|
|
135
|
+
assertDeclaredDependency(subprocess, "koffi", "@deepseek-ai/dsh-subprocess-local");
|
|
136
|
+
const koffiEntry = realpathSync(createRequire(subprocessManifest).resolve("koffi"));
|
|
137
|
+
assertInstallClosure(subprocessDir, dirname(koffiEntry), "koffi");
|
|
138
|
+
if (readManifestObject(join(dirname(koffiEntry), "package.json"))?.name !== "koffi") throw new Error("native process identity: the resolved koffi is not the koffi package");
|
|
139
|
+
return koffiEntry;
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
export { installedDshManifest as a, installedDshAnchor as i, assertDeclaredPeerDependency as n, readManifestObject as o, assertInstallClosure as r, resolveDshKoffi as s, assertDeclaredDependency as t };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/runtime/interaction-port.ts
|
|
2
|
+
/** Classify only the invocation's own typed question intent. A non-empty batch
|
|
3
|
+
* is plan-review only when EVERY question carries that exact intent; malformed
|
|
4
|
+
* input is unprovable rather than a generic Question. */
|
|
5
|
+
function questionIntentSubtype(questions) {
|
|
6
|
+
if (!Array.isArray(questions)) return void 0;
|
|
7
|
+
if (questions.length === 0) return "question";
|
|
8
|
+
let planReview = true;
|
|
9
|
+
for (const entry of questions) {
|
|
10
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) return void 0;
|
|
11
|
+
const intent = entry.intent;
|
|
12
|
+
if (intent === void 0) {
|
|
13
|
+
planReview = false;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (typeof intent !== "object" || intent === null || Array.isArray(intent)) return void 0;
|
|
17
|
+
if (intent.kind !== "plan-review") planReview = false;
|
|
18
|
+
}
|
|
19
|
+
return planReview ? "plan-review" : "question";
|
|
20
|
+
}
|
|
21
|
+
/** The official Host code for a late answer whose reply is already queued. */
|
|
22
|
+
const QUESTION_REPLY_QUEUED = "REPLY_QUEUED";
|
|
23
|
+
/** The official Host code for a late answer that does not name each question. */
|
|
24
|
+
const QUESTION_BAD_ANSWER = "BAD_ANSWER";
|
|
25
|
+
/**
|
|
26
|
+
* One rejected late answer with the Host's stable code (`REPLY_QUEUED`,
|
|
27
|
+
* `BAD_ANSWER`, `CALLER_NOT_LIVE`, or a transport/gateway code). Both
|
|
28
|
+
* adapters throw THIS shape so a consumer can offer truthful recovery
|
|
29
|
+
* without switching on a backend.
|
|
30
|
+
*/
|
|
31
|
+
var QuestionAnswerError = class extends Error {
|
|
32
|
+
code;
|
|
33
|
+
constructor(code, message, options) {
|
|
34
|
+
super(message, options);
|
|
35
|
+
this.name = "QuestionAnswerError";
|
|
36
|
+
this.code = code;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/** Wrap an unknown failure from the late-answer path in the port vocabulary. */
|
|
40
|
+
function questionAnswerError(error) {
|
|
41
|
+
if (error instanceof QuestionAnswerError) return error;
|
|
42
|
+
return new QuestionAnswerError(typeof error === "object" && error !== null && typeof error.code === "string" ? error.code : "question/answer-failed", typeof error === "object" && error !== null && typeof error.message === "string" ? error.message : String(error), { cause: error });
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { questionIntentSubtype as a, questionAnswerError as i, QUESTION_REPLY_QUEUED as n, QuestionAnswerError as r, QUESTION_BAD_ANSWER as t };
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { T as inspectInstalledProfileScope } from "./daemon-launcher-DxIgjBHW.mjs";
|
|
2
|
+
import { t as observeAuthenticatedLocalAcpStatus } from "./local-acp-status-B_25Q6kU.mjs";
|
|
3
|
+
import { a as inspectHostProcess, n as assertRecordedHostKernelIdentityCurrent, o as readLocalRecord, r as authenticateLocalHost, s as sameLocalInstanceRecord, t as assertClientHostCompatible } from "./local-discovery-BMhaGIiJ.mjs";
|
|
4
|
+
//#region src/app/remote-process/local-acp-control-route.ts
|
|
5
|
+
/** The one Owner-only authenticated management route of the headless ACP CLI. */
|
|
6
|
+
const LOCAL_ACP_CONTROL_ROUTE = "/api/pi-tui.acp-control";
|
|
7
|
+
/** Hard response-body bound the CLI accepts. */
|
|
8
|
+
const LOCAL_ACP_CONTROL_MAX_RESPONSE_BYTES = 4096;
|
|
9
|
+
/** Bound on one CLI request after authentication has completed. */
|
|
10
|
+
const LOCAL_ACP_CONTROL_TIMEOUT_MS = 1e4;
|
|
11
|
+
const STATE_VALUES = /* @__PURE__ */ new Set([
|
|
12
|
+
"enabled",
|
|
13
|
+
"disabled",
|
|
14
|
+
"changing",
|
|
15
|
+
"unavailable"
|
|
16
|
+
]);
|
|
17
|
+
const ERROR_CODES = /* @__PURE__ */ new Set([
|
|
18
|
+
"ACP_INVALID_REQUEST",
|
|
19
|
+
"ACP_INSTANCE_MISMATCH",
|
|
20
|
+
"ACP_CLI_UNAVAILABLE"
|
|
21
|
+
]);
|
|
22
|
+
function isRecord(value) {
|
|
23
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
function hasExactKeys(record, keys) {
|
|
26
|
+
const actual = Object.keys(record).sort();
|
|
27
|
+
const expected = [...keys].sort();
|
|
28
|
+
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
29
|
+
}
|
|
30
|
+
function isErrorCode(value) {
|
|
31
|
+
return typeof value === "string" && ERROR_CODES.has(value);
|
|
32
|
+
}
|
|
33
|
+
function isState(value) {
|
|
34
|
+
return typeof value === "string" && STATE_VALUES.has(value);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parse one strict route response body. Both the route tests and the CLI use
|
|
38
|
+
* this ONE validator, so the wire shape cannot drift into two implementations.
|
|
39
|
+
* @param text - the raw UTF-8 response body.
|
|
40
|
+
* @returns the discriminated reply.
|
|
41
|
+
*/
|
|
42
|
+
function parseLocalAcpControlReply(text) {
|
|
43
|
+
let value;
|
|
44
|
+
try {
|
|
45
|
+
value = JSON.parse(text);
|
|
46
|
+
} catch {
|
|
47
|
+
throw new TypeError("local acp control: the reply is not JSON");
|
|
48
|
+
}
|
|
49
|
+
if (!isRecord(value) || value.schema !== 1) throw new TypeError("local acp control: the reply must be a schema-1 object");
|
|
50
|
+
if (hasExactKeys(value, ["schema", "error"])) {
|
|
51
|
+
if (!isErrorCode(value.error)) throw new TypeError("local acp control: unknown error code");
|
|
52
|
+
return {
|
|
53
|
+
kind: "error",
|
|
54
|
+
error: value.error
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (hasExactKeys(value, [
|
|
58
|
+
"schema",
|
|
59
|
+
"instanceId",
|
|
60
|
+
"state"
|
|
61
|
+
])) {
|
|
62
|
+
if (typeof value.instanceId !== "string" || value.instanceId === "") throw new TypeError("local acp control: the reply has no instance id");
|
|
63
|
+
if (!isState(value.state)) throw new TypeError("local acp control: unknown ACP state");
|
|
64
|
+
return {
|
|
65
|
+
kind: "state",
|
|
66
|
+
instanceId: value.instanceId,
|
|
67
|
+
state: value.state
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
throw new TypeError("local acp control: unexpected reply shape");
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/app/remote-process/local-acp-control.ts
|
|
74
|
+
/** POSIX-safe single-argument profile literal for the headless hints. */
|
|
75
|
+
function shellQuoteProfile(profile) {
|
|
76
|
+
if (/^[A-Za-z0-9_@%+=:,./-]+$/u.test(profile)) return profile;
|
|
77
|
+
return `'${profile.replace(/'/gu, `'\\''`)}'`;
|
|
78
|
+
}
|
|
79
|
+
/** PowerShell single-quoted profile literal; all recognized single-quote
|
|
80
|
+
* classes are doubled and smart double quotes stay literal. Kept local so
|
|
81
|
+
* this control module never value-imports the startup compatibility island. */
|
|
82
|
+
function powershellQuoteProfile(profile) {
|
|
83
|
+
if (/^[A-Za-z0-9_@%+=:,./-]+$/u.test(profile)) return profile;
|
|
84
|
+
return `'${profile.replace(/['\u2018\u2019\u201a\u201b]/gu, (character) => character + character)}'`;
|
|
85
|
+
}
|
|
86
|
+
function shellQuoteProfileFor(profile, platform) {
|
|
87
|
+
return platform === "win32" ? powershellQuoteProfile(profile) : shellQuoteProfile(profile);
|
|
88
|
+
}
|
|
89
|
+
const EXIT_CODE = {
|
|
90
|
+
UNSUPPORTED_PLATFORM: 3,
|
|
91
|
+
HOST_NOT_RUNNING: 3,
|
|
92
|
+
HOST_IDENTITY_REFUSED: 3,
|
|
93
|
+
HOST_AUTH_FAILED: 3,
|
|
94
|
+
ACP_CLI_UNAVAILABLE: 4,
|
|
95
|
+
ACP_UNAVAILABLE: 4,
|
|
96
|
+
ACP_OUTCOME_UNCONFIRMED: 5
|
|
97
|
+
};
|
|
98
|
+
/** One stable failure with its fixed exit class and a local-only reason. */
|
|
99
|
+
var AcpControlError = class extends Error {
|
|
100
|
+
code;
|
|
101
|
+
exitCode;
|
|
102
|
+
reason;
|
|
103
|
+
constructor(code, reason, cause) {
|
|
104
|
+
super(reason, cause === void 0 ? void 0 : { cause });
|
|
105
|
+
this.name = "AcpControlError";
|
|
106
|
+
this.code = code;
|
|
107
|
+
this.exitCode = EXIT_CODE[code];
|
|
108
|
+
this.reason = reason;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
/** Replace private paths/URLs and control characters in a human reason. */
|
|
112
|
+
function sanitizeReason(text) {
|
|
113
|
+
return (text.split(/\r?\n/u).map((part) => part.trim()).find((part) => part !== "") ?? "").replace(/\/[^\s"']+/gu, "<path>").replace(/https?:\/\/[^\s"']+/giu, "<url>").replace(/[\u0000-\u001f\u007f]/gu, "").slice(0, 200);
|
|
114
|
+
}
|
|
115
|
+
function formatAcpControlError(error) {
|
|
116
|
+
return `dsh-pi-tui acp: ${error.code}: ${sanitizeReason(error.reason)}\n`;
|
|
117
|
+
}
|
|
118
|
+
function platformOf(deps) {
|
|
119
|
+
return deps.platform ?? process.platform;
|
|
120
|
+
}
|
|
121
|
+
function notRunningReason(profile, platform) {
|
|
122
|
+
return `the Host for this Profile is not running; start it with: dsh --profile ${shellQuoteProfileFor(profile.name, platform)} daemon start`;
|
|
123
|
+
}
|
|
124
|
+
/** Map a lower-level failure to the fixed ACP CLI taxonomy. */
|
|
125
|
+
function toAcpControlError(error) {
|
|
126
|
+
if (error instanceof AcpControlError) return error;
|
|
127
|
+
switch (error?.code) {
|
|
128
|
+
case "B1_PLATFORM_UNSUPPORTED": return new AcpControlError("UNSUPPORTED_PLATFORM", "the acp CLI is only supported on Linux, macOS and Windows");
|
|
129
|
+
case "SCOPE_DIRECTORY_UNSAFE":
|
|
130
|
+
case "LOCAL_FILE_UNSAFE":
|
|
131
|
+
case "HOST_PROTOCOL_INCOMPATIBLE":
|
|
132
|
+
case "HOST_BUILD_INCOMPATIBLE":
|
|
133
|
+
case "HOST_IDENTITY_MISMATCH":
|
|
134
|
+
case "PROCESS_STARTTIME_UNAVAILABLE": return new AcpControlError("HOST_IDENTITY_REFUSED", "the local Host identity could not be verified for this Profile", error);
|
|
135
|
+
case "HOST_HANDOFF_UNAVAILABLE": return new AcpControlError("HOST_NOT_RUNNING", "the Host for this Profile is not running", error);
|
|
136
|
+
case "HOST_AUTH_FAILED":
|
|
137
|
+
case "HOST_UNRESPONSIVE": return new AcpControlError("HOST_AUTH_FAILED", "the local Host did not accept the authenticated handshake", error);
|
|
138
|
+
default: return new AcpControlError("ACP_CLI_UNAVAILABLE", "an unexpected local ACP CLI failure occurred", error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/** Read at most `maxBytes` of a response body; an oversize/unreadable body is `undefined`. */
|
|
142
|
+
async function readBoundedResponse(response, maxBytes) {
|
|
143
|
+
if (response.body === null) return "";
|
|
144
|
+
const reader = response.body.getReader();
|
|
145
|
+
const chunks = [];
|
|
146
|
+
let total = 0;
|
|
147
|
+
try {
|
|
148
|
+
for (;;) {
|
|
149
|
+
const { done, value } = await reader.read();
|
|
150
|
+
if (done) break;
|
|
151
|
+
total += value.byteLength;
|
|
152
|
+
if (total > maxBytes) {
|
|
153
|
+
await reader.cancel();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
chunks.push(value);
|
|
157
|
+
}
|
|
158
|
+
} finally {
|
|
159
|
+
reader.releaseLock();
|
|
160
|
+
}
|
|
161
|
+
return Buffer.concat(chunks.map((chunk) => Buffer.from(chunk))).toString("utf8");
|
|
162
|
+
}
|
|
163
|
+
/** One bounded POST against the ONE Owner-only management route. */
|
|
164
|
+
async function callAcpControl(verified, op, deps) {
|
|
165
|
+
const timeout = AbortSignal.timeout(LOCAL_ACP_CONTROL_TIMEOUT_MS);
|
|
166
|
+
const signal = deps.signal === void 0 ? timeout : AbortSignal.any([deps.signal, timeout]);
|
|
167
|
+
const init = {
|
|
168
|
+
method: "POST",
|
|
169
|
+
headers: {
|
|
170
|
+
cookie: verified.cookie,
|
|
171
|
+
"content-type": "application/json"
|
|
172
|
+
},
|
|
173
|
+
body: JSON.stringify({
|
|
174
|
+
schema: 1,
|
|
175
|
+
instanceId: verified.identity.instanceId,
|
|
176
|
+
op
|
|
177
|
+
}),
|
|
178
|
+
redirect: "manual",
|
|
179
|
+
cache: "no-store",
|
|
180
|
+
signal
|
|
181
|
+
};
|
|
182
|
+
const fetchImpl = deps.fetch ?? fetch;
|
|
183
|
+
let response;
|
|
184
|
+
try {
|
|
185
|
+
response = await fetchImpl(`${verified.record.origin}${LOCAL_ACP_CONTROL_ROUTE}`, init);
|
|
186
|
+
} catch {
|
|
187
|
+
return { status: 0 };
|
|
188
|
+
}
|
|
189
|
+
let text;
|
|
190
|
+
try {
|
|
191
|
+
text = await readBoundedResponse(response, LOCAL_ACP_CONTROL_MAX_RESPONSE_BYTES);
|
|
192
|
+
} catch {
|
|
193
|
+
text = void 0;
|
|
194
|
+
}
|
|
195
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
196
|
+
const cacheControl = response.headers.get("cache-control") ?? "";
|
|
197
|
+
if (text === void 0 || !/^application\/json\b/iu.test(contentType) || !/\bno-store\b/iu.test(cacheControl)) return { status: response.status };
|
|
198
|
+
try {
|
|
199
|
+
return {
|
|
200
|
+
status: response.status,
|
|
201
|
+
reply: parseLocalAcpControlReply(text)
|
|
202
|
+
};
|
|
203
|
+
} catch {
|
|
204
|
+
return { status: response.status };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Prove the reply still belongs to the authenticated Host: the reply must echo
|
|
209
|
+
* THIS instance, the same-scope registry must still name the SAME instance and
|
|
210
|
+
* the fresh kernel identity must still be that process. A host replaced during
|
|
211
|
+
* the write cannot lend its answer to this CLI.
|
|
212
|
+
*/
|
|
213
|
+
function assertReplyBelongsToAuthenticatedHost(verified, reply, scope, deps) {
|
|
214
|
+
if (reply.instanceId !== verified.identity.instanceId) throw new AcpControlError("HOST_IDENTITY_REFUSED", "the Host reply names a different instance");
|
|
215
|
+
assertHostStillAuthenticated(verified, scope, deps);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Re-prove the SAME authenticated Host after ONE request: the same-scope
|
|
219
|
+
* registry still names this instance and the fresh kernel identity is still
|
|
220
|
+
* that process. The read-only observation already checked the reply instance
|
|
221
|
+
* id; a Host that disappeared/replaced mid-read must still be refused.
|
|
222
|
+
*/
|
|
223
|
+
function assertHostStillAuthenticated(verified, scope, deps) {
|
|
224
|
+
const current = (deps.readRecord ?? readLocalRecord)(scope);
|
|
225
|
+
if (current === void 0 || !sameLocalInstanceRecord(current, verified.record)) throw new AcpControlError("HOST_IDENTITY_REFUSED", "the Host identity changed while the request was in flight");
|
|
226
|
+
(deps.assertKernelIdentity ?? assertRecordedHostKernelIdentityCurrent)(verified.record);
|
|
227
|
+
}
|
|
228
|
+
/** Map one write result to the fixed settle/unknown contract. */
|
|
229
|
+
function writeResult(verb, state, profile, platform) {
|
|
230
|
+
if (state === (verb === "enable" ? "enabled" : "disabled")) return {
|
|
231
|
+
code: 0,
|
|
232
|
+
stdout: `acp=${state}\n`,
|
|
233
|
+
stderr: ""
|
|
234
|
+
};
|
|
235
|
+
if (state === "unavailable") return {
|
|
236
|
+
code: 4,
|
|
237
|
+
stdout: "acp=unavailable\n",
|
|
238
|
+
stderr: "dsh-pi-tui acp: ACP_UNAVAILABLE: the Host could not reach a settled ACP listener state\n"
|
|
239
|
+
};
|
|
240
|
+
return {
|
|
241
|
+
code: 5,
|
|
242
|
+
stdout: `acp=${state}\n`,
|
|
243
|
+
stderr: `dsh-pi-tui acp: ACP_OUTCOME_UNCONFIRMED: the Host did not confirm the requested ACP listener state; run: dsh --profile ${shellQuoteProfileFor(profile.name, platform)} acp status\n`
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/** The unreached-write outcome: the request may have been committed. */
|
|
247
|
+
function unknownWriteOutcome(profile, platform) {
|
|
248
|
+
return new AcpControlError("ACP_OUTCOME_UNCONFIRMED", `the ACP write result is unknown; run: dsh --profile ${shellQuoteProfileFor(profile.name, platform)} acp status before retrying`);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Run ONE headless ACP command for ONE official Profile. `status` is a pure
|
|
252
|
+
* read; `enable`/`disable` send exactly ONE authenticated write and never
|
|
253
|
+
* replay it.
|
|
254
|
+
*/
|
|
255
|
+
async function runLocalAcpControl(intent, profile, deps = {}) {
|
|
256
|
+
try {
|
|
257
|
+
const platform = platformOf(deps);
|
|
258
|
+
if (platform !== "linux" && platform !== "darwin" && platform !== "win32") throw new AcpControlError("UNSUPPORTED_PLATFORM", "the acp CLI is only supported on Linux, macOS and Windows");
|
|
259
|
+
const scope = inspectInstalledProfileScope({
|
|
260
|
+
dshHome: profile.home,
|
|
261
|
+
profileDir: profile.dir,
|
|
262
|
+
packageRoot: profile.packageRoot,
|
|
263
|
+
dshVersion: profile.dshVersion
|
|
264
|
+
});
|
|
265
|
+
const record = (deps.readRecord ?? readLocalRecord)(scope);
|
|
266
|
+
if (record === void 0) throw new AcpControlError("HOST_NOT_RUNNING", notRunningReason(profile, platform));
|
|
267
|
+
if ((deps.inspectProcess ?? inspectHostProcess)(record) === "dead") throw new AcpControlError("HOST_NOT_RUNNING", notRunningReason(profile, platform));
|
|
268
|
+
assertClientHostCompatible(record, scope);
|
|
269
|
+
const verified = await (deps.authenticate ?? authenticateLocalHost)(record, scope, deps.signal);
|
|
270
|
+
deps.signal?.throwIfAborted();
|
|
271
|
+
if (intent.verb === "status") {
|
|
272
|
+
const status = await observeAuthenticatedLocalAcpStatus(verified, deps.signal);
|
|
273
|
+
if (status === void 0) throw new AcpControlError("ACP_CLI_UNAVAILABLE", "the authenticated Host did not return a readable ACP listener state");
|
|
274
|
+
assertHostStillAuthenticated(verified, scope, deps);
|
|
275
|
+
return {
|
|
276
|
+
code: 0,
|
|
277
|
+
stdout: `acp=${status.state}\n`,
|
|
278
|
+
stderr: ""
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
const result = await callAcpControl(verified, intent.verb, deps);
|
|
282
|
+
if (result.status === 0) throw unknownWriteOutcome(profile, platform);
|
|
283
|
+
if (result.status === 401 || result.status === 403) throw new AcpControlError("HOST_AUTH_FAILED", "the Host rejected the authenticated ACP CLI request");
|
|
284
|
+
if (result.status === 404) throw new AcpControlError("ACP_CLI_UNAVAILABLE", "this Host build does not support the acp CLI; restart the Host from the current install");
|
|
285
|
+
if (result.status === 409) throw new AcpControlError("HOST_IDENTITY_REFUSED", "the Host reply names a different instance");
|
|
286
|
+
if (result.status === 400 || result.status === 405 || result.status === 415) throw new AcpControlError("ACP_CLI_UNAVAILABLE", "the Host rejected the ACP control request before any write");
|
|
287
|
+
if (result.status === 503 || result.status !== 200 || result.reply?.kind !== "state") throw unknownWriteOutcome(profile, platform);
|
|
288
|
+
try {
|
|
289
|
+
assertReplyBelongsToAuthenticatedHost(verified, result.reply, scope, deps);
|
|
290
|
+
} catch {
|
|
291
|
+
throw unknownWriteOutcome(profile, platform);
|
|
292
|
+
}
|
|
293
|
+
return writeResult(intent.verb, result.reply.state, profile, platform);
|
|
294
|
+
} catch (error) {
|
|
295
|
+
const failure = toAcpControlError(error);
|
|
296
|
+
return {
|
|
297
|
+
code: failure.exitCode,
|
|
298
|
+
stdout: "",
|
|
299
|
+
stderr: formatAcpControlError(failure)
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
304
|
+
export { runLocalAcpControl };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/app/remote-process/local-acp-endpoint.ts
|
|
2
|
+
/**
|
|
3
|
+
* The one transport-neutral description of the local ACP endpoint name.
|
|
4
|
+
*
|
|
5
|
+
* POSIX keeps the existing pathname Unix socket contract (Linux/Darwin derive
|
|
6
|
+
* it in the listener module). Native Windows uses one profile-scoped Named
|
|
7
|
+
* Pipe address derived from the existing canonical scope id: this module owns
|
|
8
|
+
* only the pure shape/validation and performs no IO, so the listener, the
|
|
9
|
+
* daemon-control reader and the standalone stdio entry share exactly one
|
|
10
|
+
* definition without pulling Host or SDK side effects into the byte relay.
|
|
11
|
+
*
|
|
12
|
+
* @module app/remote-process/local-acp-endpoint
|
|
13
|
+
*/
|
|
14
|
+
/** The exact local Windows Named Pipe prefix of this product. */
|
|
15
|
+
const ACP_PIPE_PREFIX = "\\\\.\\pipe\\dsh-pi-tui-acp-";
|
|
16
|
+
const SCOPE_ID = /^[0-9a-f]{64}$/u;
|
|
17
|
+
const CONTROL_CHARS = /[\u0000-\u001f\u007f]/u;
|
|
18
|
+
/** The canonical local Named Pipe address of one existing profile scope. The
|
|
19
|
+
* scope id comes from the internal canonical scope producer; external addresses
|
|
20
|
+
* are admitted only through {@link isAcpPipeAddress}. */
|
|
21
|
+
function acpPipeAddress(scopeId) {
|
|
22
|
+
return `${ACP_PIPE_PREFIX}${scopeId}`;
|
|
23
|
+
}
|
|
24
|
+
/** Whether one string is EXACTLY this product's local Named Pipe address. */
|
|
25
|
+
function isAcpPipeAddress(value) {
|
|
26
|
+
if (!value.startsWith("\\\\.\\pipe\\dsh-pi-tui-acp-")) return false;
|
|
27
|
+
const suffix = value.slice(24);
|
|
28
|
+
return SCOPE_ID.test(suffix);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The one target-shape admission used by the stdio relay and its tests. On
|
|
32
|
+
* Windows only the exact local product pipe is accepted (never a remote UNC
|
|
33
|
+
* path or an arbitrary path); POSIX keeps the existing absolute/no-control
|
|
34
|
+
* path rule.
|
|
35
|
+
*/
|
|
36
|
+
function isSafeLocalAcpEndpoint(value, platform) {
|
|
37
|
+
if (platform === "win32") return isAcpPipeAddress(value);
|
|
38
|
+
return value.startsWith("/") && !CONTROL_CHARS.test(value);
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { isSafeLocalAcpEndpoint as n, acpPipeAddress as t };
|