@civilization/dsh 0.0.0-stage → 0.2.0-rc.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/LICENSE +21 -0
- package/README.i18n.yaml +22 -0
- package/README.md +63 -2
- package/README.zh.md +64 -0
- package/lib/bin.js +254 -0
- package/lib/dump-config-BEDI-dNY.js +64 -0
- package/lib/dump-config-crgOY3tW.js +2 -0
- package/lib/dump-config-schema-DhhNOaro.js +41 -0
- package/lib/plugin-BGnVfe_D.js +101 -0
- package/lib/profile-boot-BZ2ZjNWi.js +298 -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 +90 -0
- package/lib/types/startup-diagnostics.d.ts +19 -0
- package/package.json +160 -3
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { PROFILE_PATCH_FILENAME, PROFILE_TEMPLATES, PluginPackages, boot, createRuntimeResolution, initProfile, installFailLoud, loadOverlayPatches, loadProfile, readProfilePatches, reportSkippedBundles, resolveProfileDir } from "@deepseek-ai/dsh-app-boot";
|
|
2
|
+
import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { installProxyFromEnvironment } from "@deepseek-ai/dsh-http-proxy";
|
|
7
|
+
import { DSH_LAUNCH_ENVIRONMENT_KEY } from "@deepseek-ai/dsh-launch-environment";
|
|
8
|
+
import { provideCmdline } from "@deepseek-ai/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 @deepseek-ai/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
|
+
* Initialize a missing profile from one shipped template. This copies only
|
|
130
|
+
* the template's bundle list; local state from the
|
|
131
|
+
* same-named shipped profile is not read, and no inheritance metadata is
|
|
132
|
+
* persisted. Shipped profile names are reserved, and the target directory is
|
|
133
|
+
* claimed exclusively so existing or concurrent state is never reused.
|
|
134
|
+
* @param name - the new profile name.
|
|
135
|
+
* @param fromDefaultProfile - shipped profile template to copy.
|
|
136
|
+
* @param home - Harness home containing the profile directory.
|
|
137
|
+
* @throws when the template is unknown, the target name is shipped, or the target directory exists.
|
|
138
|
+
*/
|
|
139
|
+
function initializeProfileFromDefault(name, fromDefaultProfile, home = resolveDshHome()) {
|
|
140
|
+
const dir = resolveProfileDir(name, home);
|
|
141
|
+
const template = Object.hasOwn(PROFILE_TEMPLATES, fromDefaultProfile) ? PROFILE_TEMPLATES[fromDefaultProfile] : void 0;
|
|
142
|
+
if (template === void 0) {
|
|
143
|
+
const expected = Object.keys(PROFILE_TEMPLATES).sort().map((value) => JSON.stringify(value)).join(", ");
|
|
144
|
+
throw new Error(`${NAME}: unknown default profile ${JSON.stringify(fromDefaultProfile)}; expected one of ${expected}`);
|
|
145
|
+
}
|
|
146
|
+
if (Object.hasOwn(PROFILE_TEMPLATES, name)) throw new Error(`${NAME}: profile ${JSON.stringify(name)} is shipped and cannot be a custom profile target; omit --from-default-profile to use it`);
|
|
147
|
+
mkdirSync(dirname(dir), { recursive: true });
|
|
148
|
+
try {
|
|
149
|
+
mkdirSync(dir);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (error.code !== "EEXIST") throw error;
|
|
152
|
+
const manifestPath = join(dir, "package.json");
|
|
153
|
+
if (existsSync(manifestPath)) throw new Error(`${NAME}: profile ${JSON.stringify(name)} already exists at ${manifestPath}; omit --from-default-profile to use it`);
|
|
154
|
+
throw new Error(`${NAME}: profile directory ${dir} already exists; choose an unused profile name`);
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
initProfile(dir, template.bundles);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
try {
|
|
160
|
+
rmSync(dir, {
|
|
161
|
+
recursive: true,
|
|
162
|
+
force: true
|
|
163
|
+
});
|
|
164
|
+
} catch (cleanupError) {
|
|
165
|
+
throw new AggregateError([error, cleanupError], `${NAME}: profile initialization failed and ${dir} could not be removed`);
|
|
166
|
+
}
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Load a resolved profile for `name` and (re)write the empty root config. The
|
|
172
|
+
* root is always rewritten: the whole composition is patch layers, and the
|
|
173
|
+
* vendored Loader's tree write-back (a plugin self-disposing persists the
|
|
174
|
+
* current tree) can bake composed rows into this file — which would duplicate
|
|
175
|
+
* every bundle insert on the next boot. The file exists on disk only because
|
|
176
|
+
* the Loader needs a real include root to anchor `baseUrl` at the profile
|
|
177
|
+
* directory (the config dump anchors on the same file, so both compose over
|
|
178
|
+
* the identical base).
|
|
179
|
+
* @param name - the profile name.
|
|
180
|
+
* @param userLayer - `false` skips parsing `cordis.patch.yml` (the default dump).
|
|
181
|
+
* @param fromDefaultProfile - shipped template used once to initialize a missing profile.
|
|
182
|
+
* @returns the loaded profile.
|
|
183
|
+
* @throws when explicit initialization names an unknown template or an existing profile.
|
|
184
|
+
*/
|
|
185
|
+
function prepareProfile(name, userLayer = true, fromDefaultProfile) {
|
|
186
|
+
if (fromDefaultProfile !== void 0) initializeProfileFromDefault(name, fromDefaultProfile);
|
|
187
|
+
const profile = loadProfile(NAME, name, INSTALL_ANCHOR, void 0, { userLayer });
|
|
188
|
+
reportSkippedBundles(NAME, profile);
|
|
189
|
+
writeFileSync(join(profile.dir, PROFILE_ROOT_FILENAME), PROFILE_ROOT_CONFIG);
|
|
190
|
+
return profile;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Load `name` and compose its effective patch stack: bundle layers in
|
|
194
|
+
* `dsh.profile.bundles` order (a base-backed profile gets the base bundle's
|
|
195
|
+
* platform-gated shell rows), the profile's user layer, the home-level user
|
|
196
|
+
* layer (`$DSH_HOME/cordis.patch.yml` — machine-local preferences that apply
|
|
197
|
+
* to every profile, so it outranks the per-profile layer), `--patch` overlays,
|
|
198
|
+
* then the telemetry switch.
|
|
199
|
+
* @param name - the profile name.
|
|
200
|
+
* @param patchFiles - `--patch` overlay paths, in argv order.
|
|
201
|
+
* @param fromDefaultProfile - shipped template for a missing named profile.
|
|
202
|
+
* @param resolvedProfile - application-owned profile and installation.
|
|
203
|
+
* @returns the profile and its patch layers.
|
|
204
|
+
*/
|
|
205
|
+
async function composeProfile(name, patchFiles, fromDefaultProfile, resolvedProfile) {
|
|
206
|
+
const profile = resolvedProfile?.profile ?? prepareProfile(name, true, fromDefaultProfile);
|
|
207
|
+
if (resolvedProfile !== void 0) writeFileSync(join(profile.dir, PROFILE_ROOT_FILENAME), PROFILE_ROOT_CONFIG);
|
|
208
|
+
return {
|
|
209
|
+
profile,
|
|
210
|
+
resolution: await createRuntimeResolution({
|
|
211
|
+
installAnchor: resolvedProfile?.installAnchor ?? INSTALL_ANCHOR,
|
|
212
|
+
profile
|
|
213
|
+
}),
|
|
214
|
+
overlays: patchFiles.flatMap((file) => loadOverlayPatches(NAME, resolve(file)))
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Boot one profile invocation end to end and leave process lifetime to the
|
|
219
|
+
* mounted plugins (or to a one-shot runner the composition mounts).
|
|
220
|
+
* @param options - environment snapshot, profile name, overlays, and the booted app's own arguments.
|
|
221
|
+
* @returns the settled root context and the shutdown controller.
|
|
222
|
+
* @throws after disposing startup resources; cleanup failures retain the original error.
|
|
223
|
+
*/
|
|
224
|
+
async function runProfile(options) {
|
|
225
|
+
const disposeProxy = await installProxyFromEnvironment(options.environment, (message) => {
|
|
226
|
+
process.stderr.write(`${NAME}: ${message}\n`);
|
|
227
|
+
});
|
|
228
|
+
const app = {};
|
|
229
|
+
let disposal;
|
|
230
|
+
const dispose = () => disposal ??= (async () => {
|
|
231
|
+
const failures = [];
|
|
232
|
+
for (const release of [() => app.current?.fiber.dispose(), disposeProxy]) try {
|
|
233
|
+
await release();
|
|
234
|
+
} catch (error) {
|
|
235
|
+
failures.push(error);
|
|
236
|
+
}
|
|
237
|
+
if (failures.length === 1) throw failures[0];
|
|
238
|
+
if (failures.length > 1) throw new AggregateError(failures, "dsh: profile cleanup failed");
|
|
239
|
+
})();
|
|
240
|
+
try {
|
|
241
|
+
const composed = await composeProfile(options.profile, options.patchFiles, options.fromDefaultProfile, options.resolvedProfile);
|
|
242
|
+
const appReady = createAppReady();
|
|
243
|
+
const shutdown = createProcessShutdown(dispose);
|
|
244
|
+
const signalShutdown = new AbortController();
|
|
245
|
+
const interrupt = (code) => {
|
|
246
|
+
signalShutdown.abort();
|
|
247
|
+
shutdown.interrupt(code);
|
|
248
|
+
};
|
|
249
|
+
process.on("SIGTERM", () => {
|
|
250
|
+
interrupt(0);
|
|
251
|
+
});
|
|
252
|
+
process.on("SIGINT", () => {
|
|
253
|
+
interrupt(130);
|
|
254
|
+
});
|
|
255
|
+
installFailLoud(NAME, process, async () => {
|
|
256
|
+
await app.current?.fiber.dispose();
|
|
257
|
+
});
|
|
258
|
+
const rootConfig = join(composed.profile.dir, PROFILE_ROOT_FILENAME);
|
|
259
|
+
const profileContext = {
|
|
260
|
+
name: options.profile,
|
|
261
|
+
...options.packageManager === void 0 ? {} : { packageManager: options.packageManager },
|
|
262
|
+
dir: composed.profile.dir,
|
|
263
|
+
patchPath: composed.profile.patchPath,
|
|
264
|
+
installAnchor: options.resolvedProfile?.installAnchor ?? INSTALL_ANCHOR,
|
|
265
|
+
startedBundles: composed.profile.layers.map((layer) => layer.packageName),
|
|
266
|
+
cwd: process.cwd(),
|
|
267
|
+
home: resolveDshHome(),
|
|
268
|
+
overlays: composed.overlays,
|
|
269
|
+
telemetryDisabledEnv: process.env.DSH_TELEMETRY_DISABLED
|
|
270
|
+
};
|
|
271
|
+
const ctx = await boot(NAME, rootConfig, readProfilePatches(NAME, profileContext, composed.profile), async (hostCtx) => {
|
|
272
|
+
app.current = hostCtx;
|
|
273
|
+
hostCtx.provide("profileContext", profileContext);
|
|
274
|
+
hostCtx.provide(DSH_LAUNCH_ENVIRONMENT_KEY, options.environment);
|
|
275
|
+
await hostCtx.plugin(PluginPackages, { resolution: composed.resolution });
|
|
276
|
+
provideCmdline(hostCtx, {
|
|
277
|
+
args: options.args,
|
|
278
|
+
exit: (code) => void shutdown.shutdown(code),
|
|
279
|
+
ready: appReady.service
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
app.current = ctx;
|
|
283
|
+
if (!signalShutdown.signal.aborted && ctx.fiber.state === 2 && ctx.get("loader") !== void 0) appReady.commit();
|
|
284
|
+
return {
|
|
285
|
+
ctx,
|
|
286
|
+
shutdown
|
|
287
|
+
};
|
|
288
|
+
} catch (error) {
|
|
289
|
+
try {
|
|
290
|
+
await dispose();
|
|
291
|
+
} catch (cleanupError) {
|
|
292
|
+
throw new AggregateError([error, cleanupError], "dsh: profile startup and cleanup failed");
|
|
293
|
+
}
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
//#endregion
|
|
298
|
+
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-BZ2ZjNWi.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
|
+
* `@deepseek-ai/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 @deepseek-ai/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 used once to initialize a missing 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 used once to initialize a missing 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 used once to initialize a missing 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 @deepseek-ai/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 @deepseek-ai/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 used once to initialize a missing profile.
|
|
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 @deepseek-ai/dsh/dump-config
|
|
7
|
+
*/
|
|
8
|
+
import { type ConfigDumpLayer, type Profile } from '@deepseek-ai/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 used once to initialize a missing profile.
|
|
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 '@deepseek-ai/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
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared profile boot for every `dsh` surface: resolve the profile, stack its
|
|
3
|
+
* patch layers (bundle layers in `dsh.profile.bundles` order, the profile's
|
|
4
|
+
* own `cordis.patch.yml`, `--patch` overlays, the telemetry switch), mount the
|
|
5
|
+
* tree over the profile's empty root config, and wire fail-loud plus bounded shutdown.
|
|
6
|
+
*
|
|
7
|
+
* App flags are not the launcher's business: the invocation's inner arguments
|
|
8
|
+
* are provided to the tree through `ctx.cmdlineArgs`, where any injected app
|
|
9
|
+
* plugin may read the same immutable snapshot.
|
|
10
|
+
* @module @deepseek-ai/dsh/profile-boot
|
|
11
|
+
*/
|
|
12
|
+
import { type Context } from '@deepseek-ai/cordis';
|
|
13
|
+
import { type ProfileContext, type Profile } from '@deepseek-ai/dsh-app-boot';
|
|
14
|
+
import { type LaunchEnvironmentSnapshot } from '@deepseek-ai/dsh-launch-environment';
|
|
15
|
+
import { type ProcessShutdown } from './process-shutdown.ts';
|
|
16
|
+
/**
|
|
17
|
+
* The home-level user patch layer (`$DSH_HOME/cordis.patch.yml`), applied
|
|
18
|
+
* over every profile's own layer. Resolved per call, not at module load:
|
|
19
|
+
* `$DSH_HOME` may be set by the test or launcher after import.
|
|
20
|
+
* @returns the absolute patch-file path.
|
|
21
|
+
*/
|
|
22
|
+
export declare function homePatchPath(): string;
|
|
23
|
+
/** Absolute path of this dsh installation's package.json (both anchors: src/ and lib/ sit one level under apps/cli). */
|
|
24
|
+
export declare const INSTALL_ANCHOR: string;
|
|
25
|
+
/** Root config filename inside a profile directory. */
|
|
26
|
+
export declare const PROFILE_ROOT_FILENAME = "cordis.yml";
|
|
27
|
+
/**
|
|
28
|
+
* Initialize a missing profile from one shipped template. This copies only
|
|
29
|
+
* the template's bundle list; local state from the
|
|
30
|
+
* same-named shipped profile is not read, and no inheritance metadata is
|
|
31
|
+
* persisted. Shipped profile names are reserved, and the target directory is
|
|
32
|
+
* claimed exclusively so existing or concurrent state is never reused.
|
|
33
|
+
* @param name - the new profile name.
|
|
34
|
+
* @param fromDefaultProfile - shipped profile template to copy.
|
|
35
|
+
* @param home - Harness home containing the profile directory.
|
|
36
|
+
* @throws when the template is unknown, the target name is shipped, or the target directory exists.
|
|
37
|
+
*/
|
|
38
|
+
export declare function initializeProfileFromDefault(name: string, fromDefaultProfile: string, home?: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Load a resolved profile for `name` and (re)write the empty root config. The
|
|
41
|
+
* root is always rewritten: the whole composition is patch layers, and the
|
|
42
|
+
* vendored Loader's tree write-back (a plugin self-disposing persists the
|
|
43
|
+
* current tree) can bake composed rows into this file — which would duplicate
|
|
44
|
+
* every bundle insert on the next boot. The file exists on disk only because
|
|
45
|
+
* the Loader needs a real include root to anchor `baseUrl` at the profile
|
|
46
|
+
* directory (the config dump anchors on the same file, so both compose over
|
|
47
|
+
* the identical base).
|
|
48
|
+
* @param name - the profile name.
|
|
49
|
+
* @param userLayer - `false` skips parsing `cordis.patch.yml` (the default dump).
|
|
50
|
+
* @param fromDefaultProfile - shipped template used once to initialize a missing profile.
|
|
51
|
+
* @returns the loaded profile.
|
|
52
|
+
* @throws when explicit initialization names an unknown template or an existing profile.
|
|
53
|
+
*/
|
|
54
|
+
export declare function prepareProfile(name: string, userLayer?: boolean, fromDefaultProfile?: string): Profile;
|
|
55
|
+
/** An application-owned profile and its independent installation fallback. */
|
|
56
|
+
export interface ResolvedProfileRuntime {
|
|
57
|
+
/** Profile already loaded from the application's own directory. */
|
|
58
|
+
profile: Profile;
|
|
59
|
+
/** Absolute package.json path of the application's dsh installation. */
|
|
60
|
+
installAnchor: string;
|
|
61
|
+
}
|
|
62
|
+
/** Options for {@link runProfile}. */
|
|
63
|
+
export interface RunProfileOptions {
|
|
64
|
+
/** This run's frozen environment snapshot, provided before any entry mounts. */
|
|
65
|
+
environment: LaunchEnvironmentSnapshot;
|
|
66
|
+
/** The profile name to boot. */
|
|
67
|
+
profile: string;
|
|
68
|
+
/** Loaded application profile; bypasses named profile initialization when supplied. */
|
|
69
|
+
resolvedProfile?: ResolvedProfileRuntime | undefined;
|
|
70
|
+
/** Shipped template used once to initialize a missing profile. */
|
|
71
|
+
fromDefaultProfile?: string | undefined;
|
|
72
|
+
/** `--patch` overlay paths, in argv order. */
|
|
73
|
+
patchFiles: readonly string[];
|
|
74
|
+
/** The invocation's inner arguments, handed to the tree through `ctx.cmdlineArgs`. */
|
|
75
|
+
args: readonly string[];
|
|
76
|
+
/** Application-owned package runtime, scoped to plugin package operations. */
|
|
77
|
+
packageManager?: ProfileContext['packageManager'];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Boot one profile invocation end to end and leave process lifetime to the
|
|
81
|
+
* mounted plugins (or to a one-shot runner the composition mounts).
|
|
82
|
+
* @param options - environment snapshot, profile name, overlays, and the booted app's own arguments.
|
|
83
|
+
* @returns the settled root context and the shutdown controller.
|
|
84
|
+
* @throws after disposing startup resources; cleanup failures retain the original error.
|
|
85
|
+
*/
|
|
86
|
+
export declare function runProfile(options: RunProfileOptions): Promise<{
|
|
87
|
+
ctx: Context;
|
|
88
|
+
shutdown: ProcessShutdown;
|
|
89
|
+
}>;
|
|
90
|
+
//# sourceMappingURL=profile-boot.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Save original startup diagnostics while keeping the terminal report concise. */
|
|
2
|
+
import type { StartupError } from '@deepseek-ai/dsh-app-boot';
|
|
3
|
+
/** Launcher-owned context; no environment values or plugin configurations are collected. */
|
|
4
|
+
interface StartupDiagnosticContext {
|
|
5
|
+
home: string;
|
|
6
|
+
version: string;
|
|
7
|
+
profile: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Print the startup summary and save a private, uniquely named report under DSH_HOME/logs.
|
|
11
|
+
* Failed writes print the complete report to stderr instead of claiming a saved path.
|
|
12
|
+
* @param error - startup audit failure retaining plugin metadata and original errors.
|
|
13
|
+
* @param context - resolved Harness home, application version, and selected profile.
|
|
14
|
+
* @param write - terminal output sink; awaited before returning, defaults to stderr.
|
|
15
|
+
* @returns after saving or printing the report and completing terminal writes.
|
|
16
|
+
*/
|
|
17
|
+
export declare function reportStartupFailure(error: StartupError, context: StartupDiagnosticContext, write?: (text: string) => void | Promise<void>): Promise<void>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=startup-diagnostics.d.ts.map
|