@knyazevai/dsh 0.1.5 → 0.2.2
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.i18n.yaml +21 -5
- package/README.md +26 -9
- package/README.zh.md +25 -10
- package/lib/bin.js +175 -73
- package/lib/dump-config-Cxlnwi7L.js +2 -0
- package/lib/{dump-config-DyK_R56g.js → dump-config-DC1v_CSl.js} +18 -6
- package/lib/dump-config-schema-CzGcS3DG.js +41 -0
- package/lib/plugin-CjFov5EZ.js +101 -0
- package/lib/profile-boot-B44a52oE.js +329 -0
- package/lib/profile-boot.js +2 -0
- package/lib/types/args.d.ts +65 -0
- package/lib/types/bin.d.ts +18 -0
- package/lib/types/dump-config-schema.d.ts +17 -0
- package/lib/types/dump-config.d.ts +27 -0
- package/lib/types/plugin.d.ts +9 -0
- package/lib/types/process-shutdown.d.ts +20 -0
- package/lib/types/profile-boot.d.ts +97 -0
- package/lib/types/startup-diagnostics.d.ts +19 -0
- package/package.json +155 -83
- package/config/agent-presets/code/agent.cordis.yml +0 -263
- package/config/agent-presets/code/preset.yml +0 -3
- package/config/agent-presets/cordis/agent.cordis.yml +0 -263
- package/config/agent-presets/cordis/preset.yml +0 -3
- package/config/agent-presets/cordis/skills/cordis-plugin-development/SKILL.md +0 -420
- package/config/agent-presets/cordis/skills/editing-cordis-compositions/SKILL.md +0 -165
- package/config/agent-presets/minimal/agent.cordis.yml +0 -88
- package/config/agent-presets/minimal/preset.yml +0 -3
- package/config/agent-presets/standard/agent.cordis.yml +0 -252
- package/config/agent-presets/standard/preset.yml +0 -3
- package/lib/plugin-b-wPL_wv.js +0 -128
- package/lib/profile-boot-ClKqtiSq.js +0 -2
- package/lib/profile-boot-CuWvAMzG.js +0 -283
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { t as INSTALL_ANCHOR } from "./profile-boot-B44a52oE.js";
|
|
2
|
+
import { DEFAULT_PROFILE_BUNDLES, PROFILE_TEMPLATES, initProfile, readProfileCompatibility, resolveProfileDir } from "@knyazevai/dsh-app-boot";
|
|
3
|
+
import { mkdir } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { runPluginCommand, runProfilePnpm, setProfileVersionExemption } from "@knyazevai/dsh-plugin-manager/operations";
|
|
7
|
+
import { withFileLock } from "@knyazevai/dsh-atomic-write";
|
|
8
|
+
//#region lib/types/plugin.js
|
|
9
|
+
/** Profile package management and explicit, exact-version compatibility approvals. */
|
|
10
|
+
function requireDesktopProfile(dir) {
|
|
11
|
+
if (!existsSync(join(dir, "package.json"))) throw new Error("Open DeepSeek Harness Desktop once to initialize its profile, then fully quit it before running dsh plugin --profile desktop.");
|
|
12
|
+
}
|
|
13
|
+
/** Parse only DSH-owned commands; all other arguments remain pnpm's responsibility. */
|
|
14
|
+
async function versionCommand(profile, args) {
|
|
15
|
+
const [command, ...rest] = args;
|
|
16
|
+
if (command !== "allow-version" && command !== "revoke-version" && command !== "version-exemptions") return void 0;
|
|
17
|
+
try {
|
|
18
|
+
let packageVersion;
|
|
19
|
+
let runtimeVersion;
|
|
20
|
+
let acceptRisk = false;
|
|
21
|
+
const argumentsIterator = rest.values();
|
|
22
|
+
for (const argument of argumentsIterator) if (argument === "--accept-risk" && command === "allow-version" && !acceptRisk) acceptRisk = true;
|
|
23
|
+
else if (argument === "--dsh-version" && runtimeVersion === void 0) runtimeVersion = argumentsIterator.next().value;
|
|
24
|
+
else if (argument.startsWith("--dsh-version=") && runtimeVersion === void 0) runtimeVersion = argument.slice(14);
|
|
25
|
+
else if (!argument.startsWith("-") && packageVersion === void 0) packageVersion = argument;
|
|
26
|
+
else throw new Error(`unexpected argument ${JSON.stringify(argument)}`);
|
|
27
|
+
if (command === "version-exemptions" && rest.length > 0) throw new Error("usage: dsh plugin version-exemptions");
|
|
28
|
+
let request;
|
|
29
|
+
if (command !== "version-exemptions") {
|
|
30
|
+
if (packageVersion === void 0 || runtimeVersion === void 0) throw new Error(`usage: dsh plugin ${command} <package@version> --dsh-version <exact>${command === "allow-version" ? " --accept-risk" : ""}`);
|
|
31
|
+
request = {
|
|
32
|
+
packageVersion,
|
|
33
|
+
runtimeVersion
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (command === "allow-version") process.stderr.write("dsh: warning: allowing incompatible plugin versions can break the application or corrupt data. Approval applies only to the exact package and DSH versions.\n");
|
|
37
|
+
const dir = resolveProfileDir(profile);
|
|
38
|
+
if (profile !== "desktop") await mkdir(dir, { recursive: true });
|
|
39
|
+
await withFileLock(join(dir, "package.json"), async () => {
|
|
40
|
+
if (profile === "desktop") requireDesktopProfile(dir);
|
|
41
|
+
else if (!existsSync(join(dir, "package.json"))) initProfile(dir, PROFILE_TEMPLATES[profile]?.bundles ?? DEFAULT_PROFILE_BUNDLES);
|
|
42
|
+
if (request === void 0) {
|
|
43
|
+
const { exemptions, warnings } = readProfileCompatibility(dir);
|
|
44
|
+
for (const warning of warnings) process.stderr.write(`dsh: warning: ${warning}\n`);
|
|
45
|
+
process.stdout.write(JSON.stringify(exemptions, void 0, 2) + "\n");
|
|
46
|
+
} else {
|
|
47
|
+
await setProfileVersionExemption(dir, request.packageVersion, request.runtimeVersion, command === "allow-version", acceptRisk);
|
|
48
|
+
process.stdout.write(`dsh: ${command === "allow-version" ? "allowed" : "revoked"} ${request.packageVersion} for DSH ${request.runtimeVersion}\n`);
|
|
49
|
+
}
|
|
50
|
+
}, { waitMs: 12e4 });
|
|
51
|
+
return 0;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
process.stderr.write(`dsh: ${String(error)}\n`);
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Run package management for a profile.
|
|
58
|
+
* @param profile Profile name; Desktop's reserved profile must already be initialized by the application.
|
|
59
|
+
* @param args DSH exemption command or pnpm arguments relative to the invoking directory.
|
|
60
|
+
* @param packageManager Installation-owned executable and environment for pnpm operations.
|
|
61
|
+
* @returns Zero on success; nonzero on invalid approval or package-manager failure.
|
|
62
|
+
*/
|
|
63
|
+
async function runPlugin(profile, args, packageManager) {
|
|
64
|
+
if (profile === "desktop") try {
|
|
65
|
+
requireDesktopProfile(resolveProfileDir(profile));
|
|
66
|
+
} catch (error) {
|
|
67
|
+
process.stderr.write(`dsh: ${String(error)}\n`);
|
|
68
|
+
return 1;
|
|
69
|
+
}
|
|
70
|
+
const versionResult = await versionCommand(profile, args);
|
|
71
|
+
if (versionResult !== void 0) return versionResult;
|
|
72
|
+
const dir = resolveProfileDir(profile);
|
|
73
|
+
if (existsSync(join(dir, "package.json"))) for (const warning of readProfileCompatibility(dir).warnings) process.stderr.write(`dsh: warning: ${warning}\n`);
|
|
74
|
+
const context = {
|
|
75
|
+
profile,
|
|
76
|
+
dir,
|
|
77
|
+
installAnchor: INSTALL_ANCHOR,
|
|
78
|
+
cwd: process.cwd()
|
|
79
|
+
};
|
|
80
|
+
const options = {
|
|
81
|
+
...packageManager,
|
|
82
|
+
execution: "cli",
|
|
83
|
+
outputBytes: 16384,
|
|
84
|
+
lockWaitMs: 12e4,
|
|
85
|
+
lookupTimeoutMs: 12e4,
|
|
86
|
+
onOutput: (text, stream) => {
|
|
87
|
+
process[stream].write(text);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const result = profile === "desktop" ? await withFileLock(join(dir, "package.json"), async () => {
|
|
91
|
+
requireDesktopProfile(dir);
|
|
92
|
+
return runProfilePnpm(context, args, options);
|
|
93
|
+
}, { waitMs: 12e4 }) : await runPluginCommand(context, args, options);
|
|
94
|
+
if (result.exitCode === 127) process.stderr.write("dsh: pnpm was not found; install pnpm and make it available on PATH.\n");
|
|
95
|
+
for (const { name, version, runtimeVersion } of result.incompatible ?? []) process.stderr.write(`dsh: to accept the risk, run: dsh plugin --profile ${profile} allow-version ${name}@${version} --dsh-version ${runtimeVersion} --accept-risk\n`);
|
|
96
|
+
if (result.exitCode !== 0) process.stderr.write(`dsh: plugin command failed; diagnostics: ${result.logPath}\n`);
|
|
97
|
+
if (result.exitCode !== 0 && args.some((argument) => /^git\+|^github:|\.git(?:#|$)/.test(argument))) process.stderr.write(`dsh: git-hosted plugins build on install via their prepare script, which pnpm blocks until allowed — add the exact key pnpm printed above under allowBuilds in ${join(resolveProfileDir(profile), "pnpm-workspace.yaml")}, then re-run\n`);
|
|
98
|
+
return result.exitCode;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { runPlugin };
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { PROFILE_PATCH_FILENAME, PROFILE_TEMPLATES, PluginPackages, boot, createRuntimeResolution, initProfile, installFailLoud, loadOverlayPatches, loadProfile, readProfilePatches, reportSkippedBundles, resolveProfileDir } from "@knyazevai/dsh-app-boot";
|
|
2
|
+
import { resolveDshHome } from "@knyazevai/dsh-home-paths";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { existsSync, mkdirSync, mkdtempSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { installProxyFromEnvironment } from "@knyazevai/dsh-http-proxy";
|
|
7
|
+
import { DSH_LAUNCH_ENVIRONMENT_KEY } from "@knyazevai/dsh-launch-environment";
|
|
8
|
+
import { provideCmdline } from "@knyazevai/dsh-cmdline";
|
|
9
|
+
//#region lib/types/process-shutdown.js
|
|
10
|
+
/** Bounded, escalating process shutdown for the long-lived CLI surfaces. */
|
|
11
|
+
/** Maximum grace allowed for the application tree to dispose before process exit. */
|
|
12
|
+
const PROCESS_SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
13
|
+
/**
|
|
14
|
+
* Create one process-exit controller around an application disposer.
|
|
15
|
+
* @param dispose - Whole-application teardown that resolves at quiescence.
|
|
16
|
+
* @param forceExit - Function that exits the process immediately, replaceable by tests.
|
|
17
|
+
* @param complete - Function that records the natural completion code, replaceable by tests.
|
|
18
|
+
* @param timeoutMs - Grace before forced exit, replaceable by tests.
|
|
19
|
+
* @returns A controller whose normal calls coalesce and whose repeated signal call escalates.
|
|
20
|
+
*/
|
|
21
|
+
function createProcessShutdown(dispose, forceExit = (code) => {
|
|
22
|
+
process.exit(code);
|
|
23
|
+
}, complete = (code) => {
|
|
24
|
+
process.exitCode = code;
|
|
25
|
+
}, timeoutMs = PROCESS_SHUTDOWN_TIMEOUT_MS) {
|
|
26
|
+
let pending;
|
|
27
|
+
let timeout;
|
|
28
|
+
let completed = false;
|
|
29
|
+
let forceExited = false;
|
|
30
|
+
const clearExitTimeout = () => {
|
|
31
|
+
/* v8 ignore else -- shutdown() arms the timer before any asynchronous exit path can run. */
|
|
32
|
+
if (timeout !== void 0) clearTimeout(timeout);
|
|
33
|
+
};
|
|
34
|
+
const forceExitOnce = (code) => {
|
|
35
|
+
if (forceExited) return;
|
|
36
|
+
forceExited = true;
|
|
37
|
+
clearExitTimeout();
|
|
38
|
+
forceExit(code);
|
|
39
|
+
};
|
|
40
|
+
const completeOnce = (code) => {
|
|
41
|
+
if (completed || forceExited) return;
|
|
42
|
+
completed = true;
|
|
43
|
+
clearExitTimeout();
|
|
44
|
+
complete(code);
|
|
45
|
+
};
|
|
46
|
+
const start = (code, forceAfterDispose) => {
|
|
47
|
+
if (pending !== void 0) return pending;
|
|
48
|
+
timeout = setTimeout(() => {
|
|
49
|
+
forceExitOnce(code);
|
|
50
|
+
}, timeoutMs);
|
|
51
|
+
pending = Promise.resolve().then(dispose).then(() => {
|
|
52
|
+
if (forceAfterDispose) forceExitOnce(code);
|
|
53
|
+
else completeOnce(code);
|
|
54
|
+
}, () => {
|
|
55
|
+
forceExitOnce(code);
|
|
56
|
+
});
|
|
57
|
+
return pending;
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
shutdown(code) {
|
|
61
|
+
return start(code, false);
|
|
62
|
+
},
|
|
63
|
+
interrupt(code) {
|
|
64
|
+
if (pending !== void 0) {
|
|
65
|
+
forceExitOnce(code);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
start(code, true);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region lib/types/profile-boot.js
|
|
74
|
+
/**
|
|
75
|
+
* Shared profile boot for every `dsh` surface: resolve the profile, stack its
|
|
76
|
+
* patch layers (bundle layers in `dsh.profile.bundles` order, the profile's
|
|
77
|
+
* own `cordis.patch.yml`, `--patch` overlays, the telemetry switch), mount the
|
|
78
|
+
* tree over the profile's empty root config, and wire fail-loud plus bounded shutdown.
|
|
79
|
+
*
|
|
80
|
+
* App flags are not the launcher's business: the invocation's inner arguments
|
|
81
|
+
* are provided to the tree through `ctx.cmdlineArgs`, where any injected app
|
|
82
|
+
* plugin may read the same immutable snapshot.
|
|
83
|
+
* @module @knyazevai/dsh/profile-boot
|
|
84
|
+
*/
|
|
85
|
+
const NAME = "dsh";
|
|
86
|
+
/** Launcher-owned readiness signal committed only after boot and host setup succeed. */
|
|
87
|
+
function createAppReady() {
|
|
88
|
+
let ready = false;
|
|
89
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
90
|
+
return {
|
|
91
|
+
service: { onReady(listener) {
|
|
92
|
+
if (ready) {
|
|
93
|
+
listener();
|
|
94
|
+
return () => {};
|
|
95
|
+
}
|
|
96
|
+
listeners.add(listener);
|
|
97
|
+
return () => {
|
|
98
|
+
listeners.delete(listener);
|
|
99
|
+
};
|
|
100
|
+
} },
|
|
101
|
+
commit() {
|
|
102
|
+
if (ready) return;
|
|
103
|
+
ready = true;
|
|
104
|
+
for (const listener of [...listeners]) listener();
|
|
105
|
+
listeners.clear();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The home-level user patch layer (`$DSH_HOME/cordis.patch.yml`), applied
|
|
111
|
+
* over every profile's own layer. Resolved per call, not at module load:
|
|
112
|
+
* `$DSH_HOME` may be set by the test or launcher after import.
|
|
113
|
+
* @returns the absolute patch-file path.
|
|
114
|
+
*/
|
|
115
|
+
function homePatchPath() {
|
|
116
|
+
return join(resolveDshHome(), PROFILE_PATCH_FILENAME);
|
|
117
|
+
}
|
|
118
|
+
/** Absolute path of this dsh installation's package.json (both anchors: src/ and lib/ sit one level under apps/cli). */
|
|
119
|
+
const INSTALL_ANCHOR = fileURLToPath(new URL("../package.json", import.meta.url));
|
|
120
|
+
/** The empty root entry list every profile tree patches over. */
|
|
121
|
+
const PROFILE_ROOT_CONFIG = `# dsh profile root — an empty entry list. The tree is composed as patches:
|
|
122
|
+
# each bundle in package.json's dsh.profile.bundles, then cordis.patch.yml, then any
|
|
123
|
+
# --patch overlays. Edit cordis.patch.yml, not this file.
|
|
124
|
+
[]
|
|
125
|
+
`;
|
|
126
|
+
/** Root config filename inside a profile directory. */
|
|
127
|
+
const PROFILE_ROOT_FILENAME = "cordis.yml";
|
|
128
|
+
/**
|
|
129
|
+
* Replace the named custom profile with a fresh copy of one shipped template.
|
|
130
|
+
* This copies only the template's bundle list; local state from the
|
|
131
|
+
* same-named shipped profile is not read, and no inheritance metadata is
|
|
132
|
+
* persisted. The new profile is assembled in a `.<name>.staging-*` directory
|
|
133
|
+
* under the profiles directory and moved into place; only then is any previous
|
|
134
|
+
* target directory, including its dependencies and user patch, deleted. A
|
|
135
|
+
* failed move restores the previous directory; when restoring also fails, it
|
|
136
|
+
* stays in the staging directory. Shipped profile names, compared without
|
|
137
|
+
* case, are reserved. Concurrent replacements leave one complete copy; each
|
|
138
|
+
* one either succeeds or reports the concurrent recreation.
|
|
139
|
+
* @param name - the profile name to create or replace.
|
|
140
|
+
* @param fromDefaultProfile - shipped profile template to copy.
|
|
141
|
+
* @param home - Harness home containing the profile directory.
|
|
142
|
+
* @throws when the template is unknown, the target name is shipped, another process recreates the target
|
|
143
|
+
* between the two renames, or a file-system operation fails; a restore failure is an `AggregateError`
|
|
144
|
+
* that names the staging path holding the previous profile.
|
|
145
|
+
*/
|
|
146
|
+
function initializeProfileFromDefault(name, fromDefaultProfile, home = resolveDshHome()) {
|
|
147
|
+
const dir = resolveProfileDir(name, home);
|
|
148
|
+
const template = Object.hasOwn(PROFILE_TEMPLATES, fromDefaultProfile) ? PROFILE_TEMPLATES[fromDefaultProfile] : void 0;
|
|
149
|
+
if (template === void 0) {
|
|
150
|
+
const expected = Object.keys(PROFILE_TEMPLATES).sort().map((value) => JSON.stringify(value)).join(", ");
|
|
151
|
+
throw new Error(`${NAME}: unknown default profile ${JSON.stringify(fromDefaultProfile)}; expected one of ${expected}`);
|
|
152
|
+
}
|
|
153
|
+
const shipped = Object.keys(PROFILE_TEMPLATES).find((shippedName) => shippedName.toLowerCase() === name.toLowerCase());
|
|
154
|
+
if (shipped !== void 0) throw new Error(`${NAME}: profile ${JSON.stringify(name)} names shipped profile ${JSON.stringify(shipped)} and cannot be a custom profile target; omit --from-default-profile to use it`);
|
|
155
|
+
mkdirSync(dirname(dir), { recursive: true });
|
|
156
|
+
const staging = mkdtempSync(join(dirname(dir), `.${name}.staging-`));
|
|
157
|
+
const previous = join(staging, "previous");
|
|
158
|
+
try {
|
|
159
|
+
const fresh = join(staging, "new", name);
|
|
160
|
+
initProfile(fresh, template.bundles);
|
|
161
|
+
let moved = false;
|
|
162
|
+
try {
|
|
163
|
+
renameSync(dir, previous);
|
|
164
|
+
moved = true;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error.code !== "ENOENT") throw error;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
renameSync(fresh, dir);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (existsSync(dir)) {
|
|
172
|
+
rmSync(previous, {
|
|
173
|
+
recursive: true,
|
|
174
|
+
force: true
|
|
175
|
+
});
|
|
176
|
+
throw new Error(`${NAME}: profile ${JSON.stringify(name)} was recreated concurrently at ${dir}`, { cause: error });
|
|
177
|
+
}
|
|
178
|
+
if (moved) try {
|
|
179
|
+
renameSync(previous, dir);
|
|
180
|
+
} catch (restoreError) {
|
|
181
|
+
throw new AggregateError([error, restoreError], `${NAME}: profile replacement failed and ${dir} could not be restored from ${previous}`);
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
} catch (error) {
|
|
186
|
+
if (!existsSync(previous)) rmSync(staging, {
|
|
187
|
+
recursive: true,
|
|
188
|
+
force: true
|
|
189
|
+
});
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
rmSync(staging, {
|
|
194
|
+
recursive: true,
|
|
195
|
+
force: true
|
|
196
|
+
});
|
|
197
|
+
} catch (error) {
|
|
198
|
+
process.stderr.write(`${NAME}: replaced profile ${JSON.stringify(name)} but could not remove ${staging}: ${String(error)}\n`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Load a resolved profile for `name` and (re)write the empty root config. The
|
|
203
|
+
* root is always rewritten: the whole composition is patch layers, and the
|
|
204
|
+
* vendored Loader's tree write-back (a plugin self-disposing persists the
|
|
205
|
+
* current tree) can bake composed rows into this file — which would duplicate
|
|
206
|
+
* every bundle insert on the next boot. The file exists on disk only because
|
|
207
|
+
* the Loader needs a real include root to anchor `baseUrl` at the profile
|
|
208
|
+
* directory (the config dump anchors on the same file, so both compose over
|
|
209
|
+
* the identical base).
|
|
210
|
+
* @param name - the profile name.
|
|
211
|
+
* @param userLayer - `false` skips parsing `cordis.patch.yml` (the default dump).
|
|
212
|
+
* @param fromDefaultProfile - shipped template that replaces the profile before loading it.
|
|
213
|
+
* @returns the loaded profile.
|
|
214
|
+
* @throws when explicit initialization names an unknown template or a shipped target.
|
|
215
|
+
*/
|
|
216
|
+
function prepareProfile(name, userLayer = true, fromDefaultProfile) {
|
|
217
|
+
if (fromDefaultProfile !== void 0) initializeProfileFromDefault(name, fromDefaultProfile);
|
|
218
|
+
const profile = loadProfile(NAME, name, INSTALL_ANCHOR, void 0, { userLayer });
|
|
219
|
+
reportSkippedBundles(NAME, profile);
|
|
220
|
+
writeFileSync(join(profile.dir, PROFILE_ROOT_FILENAME), PROFILE_ROOT_CONFIG);
|
|
221
|
+
return profile;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Load `name` and compose its effective patch stack: bundle layers in
|
|
225
|
+
* `dsh.profile.bundles` order (a base-backed profile gets the base bundle's
|
|
226
|
+
* platform-gated shell rows), the profile's user layer, the home-level user
|
|
227
|
+
* layer (`$DSH_HOME/cordis.patch.yml` — machine-local preferences that apply
|
|
228
|
+
* to every profile, so it outranks the per-profile layer), `--patch` overlays,
|
|
229
|
+
* then the telemetry switch.
|
|
230
|
+
* @param name - the profile name.
|
|
231
|
+
* @param patchFiles - `--patch` overlay paths, in argv order.
|
|
232
|
+
* @param fromDefaultProfile - shipped template that replaces the named profile.
|
|
233
|
+
* @param resolvedProfile - application-owned profile and installation.
|
|
234
|
+
* @returns the profile and its patch layers.
|
|
235
|
+
*/
|
|
236
|
+
async function composeProfile(name, patchFiles, fromDefaultProfile, resolvedProfile) {
|
|
237
|
+
const profile = resolvedProfile?.profile ?? prepareProfile(name, true, fromDefaultProfile);
|
|
238
|
+
if (resolvedProfile !== void 0) writeFileSync(join(profile.dir, PROFILE_ROOT_FILENAME), PROFILE_ROOT_CONFIG);
|
|
239
|
+
return {
|
|
240
|
+
profile,
|
|
241
|
+
resolution: await createRuntimeResolution({
|
|
242
|
+
installAnchor: resolvedProfile?.installAnchor ?? INSTALL_ANCHOR,
|
|
243
|
+
profile
|
|
244
|
+
}),
|
|
245
|
+
overlays: patchFiles.flatMap((file) => loadOverlayPatches(NAME, resolve(file)))
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Boot one profile invocation end to end and leave process lifetime to the
|
|
250
|
+
* mounted plugins (or to a one-shot runner the composition mounts).
|
|
251
|
+
* @param options - environment snapshot, profile name, overlays, and the booted app's own arguments.
|
|
252
|
+
* @returns the settled root context and the shutdown controller.
|
|
253
|
+
* @throws after disposing startup resources; cleanup failures retain the original error.
|
|
254
|
+
*/
|
|
255
|
+
async function runProfile(options) {
|
|
256
|
+
const disposeProxy = await installProxyFromEnvironment(options.environment, (message) => {
|
|
257
|
+
process.stderr.write(`${NAME}: ${message}\n`);
|
|
258
|
+
});
|
|
259
|
+
const app = {};
|
|
260
|
+
let disposal;
|
|
261
|
+
const dispose = () => disposal ??= (async () => {
|
|
262
|
+
const failures = [];
|
|
263
|
+
for (const release of [() => app.current?.fiber.dispose(), disposeProxy]) try {
|
|
264
|
+
await release();
|
|
265
|
+
} catch (error) {
|
|
266
|
+
failures.push(error);
|
|
267
|
+
}
|
|
268
|
+
if (failures.length === 1) throw failures[0];
|
|
269
|
+
if (failures.length > 1) throw new AggregateError(failures, "dsh: profile cleanup failed");
|
|
270
|
+
})();
|
|
271
|
+
try {
|
|
272
|
+
const composed = await composeProfile(options.profile, options.patchFiles, options.fromDefaultProfile, options.resolvedProfile);
|
|
273
|
+
const appReady = createAppReady();
|
|
274
|
+
const shutdown = createProcessShutdown(dispose);
|
|
275
|
+
const signalShutdown = new AbortController();
|
|
276
|
+
const interrupt = (code) => {
|
|
277
|
+
signalShutdown.abort();
|
|
278
|
+
shutdown.interrupt(code);
|
|
279
|
+
};
|
|
280
|
+
process.on("SIGTERM", () => {
|
|
281
|
+
interrupt(0);
|
|
282
|
+
});
|
|
283
|
+
process.on("SIGINT", () => {
|
|
284
|
+
interrupt(130);
|
|
285
|
+
});
|
|
286
|
+
installFailLoud(NAME, process, async () => {
|
|
287
|
+
await app.current?.fiber.dispose();
|
|
288
|
+
});
|
|
289
|
+
const rootConfig = join(composed.profile.dir, PROFILE_ROOT_FILENAME);
|
|
290
|
+
const profileContext = {
|
|
291
|
+
name: options.profile,
|
|
292
|
+
...options.packageManager === void 0 ? {} : { packageManager: options.packageManager },
|
|
293
|
+
dir: composed.profile.dir,
|
|
294
|
+
patchPath: composed.profile.patchPath,
|
|
295
|
+
installAnchor: options.resolvedProfile?.installAnchor ?? INSTALL_ANCHOR,
|
|
296
|
+
startedBundles: composed.profile.layers.map((layer) => layer.packageName),
|
|
297
|
+
cwd: process.cwd(),
|
|
298
|
+
home: resolveDshHome(),
|
|
299
|
+
overlays: composed.overlays,
|
|
300
|
+
telemetryDisabledEnv: process.env.DSH_TELEMETRY_DISABLED
|
|
301
|
+
};
|
|
302
|
+
const ctx = await boot(NAME, rootConfig, readProfilePatches(NAME, profileContext, composed.profile), async (hostCtx) => {
|
|
303
|
+
app.current = hostCtx;
|
|
304
|
+
hostCtx.provide("profileContext", profileContext);
|
|
305
|
+
hostCtx.provide(DSH_LAUNCH_ENVIRONMENT_KEY, options.environment);
|
|
306
|
+
await hostCtx.plugin(PluginPackages, { resolution: composed.resolution });
|
|
307
|
+
provideCmdline(hostCtx, {
|
|
308
|
+
args: options.args,
|
|
309
|
+
exit: (code) => void shutdown.shutdown(code),
|
|
310
|
+
ready: appReady.service
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
app.current = ctx;
|
|
314
|
+
if (!signalShutdown.signal.aborted && ctx.fiber.state === 2 && ctx.get("loader") !== void 0) appReady.commit();
|
|
315
|
+
return {
|
|
316
|
+
ctx,
|
|
317
|
+
shutdown
|
|
318
|
+
};
|
|
319
|
+
} catch (error) {
|
|
320
|
+
try {
|
|
321
|
+
await dispose();
|
|
322
|
+
} catch (cleanupError) {
|
|
323
|
+
throw new AggregateError([error, cleanupError], "dsh: profile startup and cleanup failed");
|
|
324
|
+
}
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
329
|
+
export { prepareProfile as a, initializeProfileFromDefault as i, PROFILE_ROOT_FILENAME as n, runProfile as o, homePatchPath as r, INSTALL_ANCHOR as t };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as prepareProfile, i as initializeProfileFromDefault, n as PROFILE_ROOT_FILENAME, o as runProfile, r as homePatchPath, t as INSTALL_ANCHOR } from "./profile-boot-B44a52oE.js";
|
|
2
|
+
export { INSTALL_ANCHOR, PROFILE_ROOT_FILENAME, homePatchPath, initializeProfileFromDefault, prepareProfile, runProfile };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commander adapter for the `dsh` command line.
|
|
3
|
+
*
|
|
4
|
+
* The launcher parses only what it owns — which profile to boot, which extra
|
|
5
|
+
* patch overlays to apply, and the config dumps — and hands **everything after
|
|
6
|
+
* its own flags** to the booted tree verbatim, where injected app plugins parse
|
|
7
|
+
* their own flag families and print their own `--help` (see
|
|
8
|
+
* `@knyazevai/dsh-cmdline`). Launcher flags therefore come first: the first
|
|
9
|
+
* token this parser does not recognize starts the inner arguments, so
|
|
10
|
+
* `dsh --profile tui --resume abc` boots the tui profile with `--resume abc`,
|
|
11
|
+
* and `dsh --profile web -h` prints the web app's help, not this one's.
|
|
12
|
+
*
|
|
13
|
+
* `dsh <name>` abbreviates `dsh --profile <name>`; `plugin` manages a profile's
|
|
14
|
+
* plugin dependencies by forwarding to pnpm.
|
|
15
|
+
* @module @knyazevai/dsh/args
|
|
16
|
+
*/
|
|
17
|
+
/** Boot a named profile and hand it the invocation's inner arguments. */
|
|
18
|
+
interface ProfileInvocation {
|
|
19
|
+
mode: 'profile';
|
|
20
|
+
profile: string;
|
|
21
|
+
/** Shipped template that replaces the named profile. */
|
|
22
|
+
fromDefaultProfile?: string | undefined;
|
|
23
|
+
/** Extra patch-list overlays applied after the profile's own layer, in argv order. */
|
|
24
|
+
patches: string[];
|
|
25
|
+
/** Everything after the launcher's own flags, verbatim, for injected app plugins. */
|
|
26
|
+
args: string[];
|
|
27
|
+
}
|
|
28
|
+
/** Print a composed profile tree and exit without booting. */
|
|
29
|
+
interface DumpConfigInvocation {
|
|
30
|
+
mode: 'dump-config';
|
|
31
|
+
profile: string;
|
|
32
|
+
/** Shipped template that replaces the named profile. */
|
|
33
|
+
fromDefaultProfile?: string | undefined;
|
|
34
|
+
/** Omit the profile's user layer and --patch overlays; print bundle layers only. */
|
|
35
|
+
defaultOnly: boolean;
|
|
36
|
+
patches: string[];
|
|
37
|
+
}
|
|
38
|
+
/** Print declared plugin schemas without mounting the profile. */
|
|
39
|
+
interface DumpConfigSchemaInvocation {
|
|
40
|
+
mode: 'dump-config-schema';
|
|
41
|
+
profile: string;
|
|
42
|
+
/** Shipped template that replaces the named profile. */
|
|
43
|
+
fromDefaultProfile?: string | undefined;
|
|
44
|
+
patches: string[];
|
|
45
|
+
}
|
|
46
|
+
/** Manage a profile's plugins: forward `args` to pnpm inside the profile directory. */
|
|
47
|
+
interface PluginInvocation {
|
|
48
|
+
mode: 'plugin';
|
|
49
|
+
profile: string;
|
|
50
|
+
/** Raw pnpm arguments, verbatim. */
|
|
51
|
+
args: string[];
|
|
52
|
+
}
|
|
53
|
+
/** The resolved `dsh` invocation. Help, version, and errors exit inside {@link parseDshArgs}. */
|
|
54
|
+
export type DshInvocation = ProfileInvocation | DumpConfigInvocation | DumpConfigSchemaInvocation | PluginInvocation;
|
|
55
|
+
/**
|
|
56
|
+
* Resolve argv into one invocation, or print and exit for help, version, or an
|
|
57
|
+
* error.
|
|
58
|
+
* @param argv - arguments after the Node binary and script.
|
|
59
|
+
* @param version - version string printed by `--version`.
|
|
60
|
+
* @param manageDesktopProfile - permit Desktop's installed carrier to manage its reserved profile's plugins.
|
|
61
|
+
* @returns the resolved invocation.
|
|
62
|
+
*/
|
|
63
|
+
export declare function parseDshArgs(argv: readonly string[], version: string, manageDesktopProfile?: boolean): DshInvocation;
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Command-line entry for dsh.
|
|
4
|
+
* @module @knyazevai/dsh/bin
|
|
5
|
+
*/
|
|
6
|
+
import type { RunProfileOptions } from './profile-boot.ts';
|
|
7
|
+
/** Installation-owned dependencies supplied by a packaged CLI launcher. */
|
|
8
|
+
export type RunCliOptions = Pick<RunProfileOptions, 'packageManager'> & {
|
|
9
|
+
/** Permit plugin commands for Desktop's existing profile; reserved for its installed carrier. */
|
|
10
|
+
manageDesktopProfile?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Run the public dsh command-line interface.
|
|
14
|
+
* @param options - Package runtime and Desktop profile access supplied by the installation.
|
|
15
|
+
* @returns a promise that settles when the selected command mode finishes.
|
|
16
|
+
*/
|
|
17
|
+
export declare function runCli(options?: RunCliOptions): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=bin.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema-dump entry: inspect the composed profile without applying its plugins.
|
|
3
|
+
* Imports and lazy schema builders execute trusted module code.
|
|
4
|
+
* @module @knyazevai/dsh/dump-config-schema
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Print one JSON Schema document; incomplete collection or projection sets exitCode to 1.
|
|
8
|
+
* Profile initialization writes match the YAML dump. Plugin imports may execute
|
|
9
|
+
* top-level code, but collection never applies plugins or evaluates `!!js`.
|
|
10
|
+
* During schema generation, ordinary stdout writes are redirected to stderr.
|
|
11
|
+
* @param profile - the profile name.
|
|
12
|
+
* @param patches - overlay paths, in argv order.
|
|
13
|
+
* @param fromDefaultProfile - shipped template that replaces the profile before loading it.
|
|
14
|
+
* @returns after collection and output, with diagnostics also written to stderr.
|
|
15
|
+
*/
|
|
16
|
+
export declare function runDumpConfigSchema(profile: string, patches: readonly string[], fromDefaultProfile?: string): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=dump-config-schema.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config-dump entry for `dsh --profile <name> --dump-config`: compose the
|
|
3
|
+
* profile's patch layers through the include plugin's patch algorithm without
|
|
4
|
+
* booting or evaluating `!!js`, with one source layer per bundle, the
|
|
5
|
+
* profile's own patch file, and each `--patch` overlay.
|
|
6
|
+
* @module @knyazevai/dsh/dump-config
|
|
7
|
+
*/
|
|
8
|
+
import { type ConfigDumpLayer, type Profile } from '@knyazevai/dsh-app-boot';
|
|
9
|
+
/**
|
|
10
|
+
* Print a profile composition with comments naming each source file and patch layer.
|
|
11
|
+
* @param profile - the profile name.
|
|
12
|
+
* @param defaultOnly - omit the profile's user layer and `--patch` overlays
|
|
13
|
+
* (the recovery diagnostic for a broken `cordis.patch.yml`, which is then
|
|
14
|
+
* never parsed).
|
|
15
|
+
* @param patches - `--patch` overlay paths, in argv order.
|
|
16
|
+
* @param fromDefaultProfile - shipped template that replaces the profile before loading it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function runDumpConfig(profile: string, defaultOnly: boolean, patches: readonly string[], fromDefaultProfile?: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Read dump layers in bundle, profile, home, then argv order without composing them.
|
|
21
|
+
* @param loaded - prepared profile and parsed bundle and profile patches.
|
|
22
|
+
* @param defaultOnly - omit profile, home, and argv layers without reading their files.
|
|
23
|
+
* @param patches - overlay paths relative to the invoking directory, in argv order.
|
|
24
|
+
* @returns the labeled layers shared by YAML and schema dumps.
|
|
25
|
+
*/
|
|
26
|
+
export declare function collectConfigDumpLayers(loaded: Profile, defaultOnly: boolean, patches: readonly string[]): ConfigDumpLayer[];
|
|
27
|
+
//# sourceMappingURL=dump-config.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ProfileContext } from '@knyazevai/dsh-app-boot';
|
|
2
|
+
/** Run package management for a profile.
|
|
3
|
+
* @param profile Profile name; Desktop's reserved profile must already be initialized by the application.
|
|
4
|
+
* @param args DSH exemption command or pnpm arguments relative to the invoking directory.
|
|
5
|
+
* @param packageManager Installation-owned executable and environment for pnpm operations.
|
|
6
|
+
* @returns Zero on success; nonzero on invalid approval or package-manager failure.
|
|
7
|
+
*/
|
|
8
|
+
export declare function runPlugin(profile: string, args: readonly string[], packageManager?: ProfileContext['packageManager']): Promise<number>;
|
|
9
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Bounded, escalating process shutdown for the long-lived CLI surfaces. */
|
|
2
|
+
/** Maximum grace allowed for the application tree to dispose before process exit. */
|
|
3
|
+
export declare const PROCESS_SHUTDOWN_TIMEOUT_MS = 5000;
|
|
4
|
+
/** Process-exit controller shared by normal completion and Unix signal handlers. */
|
|
5
|
+
export interface ProcessShutdown {
|
|
6
|
+
/** Start or join graceful disposal before allowing natural completion with `code`. */
|
|
7
|
+
shutdown(code: number): Promise<void>;
|
|
8
|
+
/** Start graceful disposal followed by exit, or force exit when shutdown is already running. */
|
|
9
|
+
interrupt(code: number): void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create one process-exit controller around an application disposer.
|
|
13
|
+
* @param dispose - Whole-application teardown that resolves at quiescence.
|
|
14
|
+
* @param forceExit - Function that exits the process immediately, replaceable by tests.
|
|
15
|
+
* @param complete - Function that records the natural completion code, replaceable by tests.
|
|
16
|
+
* @param timeoutMs - Grace before forced exit, replaceable by tests.
|
|
17
|
+
* @returns A controller whose normal calls coalesce and whose repeated signal call escalates.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createProcessShutdown(dispose: () => Promise<void>, forceExit?: (code: number) => void, complete?: (code: number) => void, timeoutMs?: number): ProcessShutdown;
|
|
20
|
+
//# sourceMappingURL=process-shutdown.d.ts.map
|