@deepseek-ai/dsh 0.1.6-alpha.1 → 0.1.6-alpha.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.
@@ -1,8 +1,8 @@
1
1
  import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
- import { PROFILE_PATCH_FILENAME, PROFILE_TEMPLATES, PluginPackages, boot, composeEntries, createProfileResolutionGeneration, healProfilesModuleFallback, initProfile, installFailLoud, loadOptionalPatches, loadOverlayPatches, loadProfile, resolveProfileDir, watchUserPatches } from "@deepseek-ai/dsh-app-boot";
4
- import { dirname, join, resolve } from "node:path";
3
+ import { PROFILE_PATCH_FILENAME, PROFILE_TEMPLATES, PluginPackages, boot, createProfileResolutionGeneration, healIsolatedProfileModuleFallback, healProfilesModuleFallback, initProfile, installFailLoud, loadOverlayPatches, loadProfile, readProfilePatches, resolveProfileDir } from "@deepseek-ai/dsh-app-boot";
5
4
  import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
5
+ import { dirname, join, resolve } from "node:path";
6
6
  import { installProxyFromEnvironment } from "@deepseek-ai/dsh-http-proxy";
7
7
  import { DSH_LAUNCH_ENVIRONMENT_KEY } from "@deepseek-ai/dsh-launch-environment";
8
8
  import { provideCmdline } from "@deepseek-ai/dsh-cmdline";
@@ -75,8 +75,7 @@ function createProcessShutdown(dispose, forceExit = (code) => {
75
75
  * Shared profile boot for every `dsh` surface: resolve the profile, stack its
76
76
  * patch layers (bundle layers in `dsh.profile.bundles` order, the profile's
77
77
  * own `cordis.patch.yml`, `--patch` overlays, the telemetry switch), mount the
78
- * tree over the profile's empty root config, apply its selected patch-reload
79
- * lifecycle, and wire fail-loud plus bounded shutdown.
78
+ * tree over the profile's empty root config, and wire fail-loud plus bounded shutdown.
80
79
  *
81
80
  * App flags are not the launcher's business: the invocation's inner arguments
82
81
  * are provided to the tree through `ctx.cmdlineArgs`, where any injected app
@@ -118,8 +117,6 @@ function homePatchPath() {
118
117
  }
119
118
  /** Absolute path of this dsh installation's package.json (both anchors: src/ and lib/ sit one level under apps/cli). */
120
119
  const INSTALL_ANCHOR = fileURLToPath(new URL("../package.json", import.meta.url));
121
- /** The session-telemetry row id the DSH_TELEMETRY_DISABLED switch targets. */
122
- const TELEMETRY_ROW_ID = "session-telemetry-otel";
123
120
  /** The empty root entry list every profile tree patches over. */
124
121
  const PROFILE_ROOT_CONFIG = `# dsh profile root — an empty entry list. The tree is composed as patches:
125
122
  # each bundle in package.json's dsh.profile.bundles, then cordis.patch.yml, then any
@@ -130,7 +127,7 @@ const PROFILE_ROOT_CONFIG = `# dsh profile root — an empty entry list. The tre
130
127
  const PROFILE_ROOT_FILENAME = "cordis.yml";
131
128
  /**
132
129
  * Initialize a missing profile from one shipped template. This copies only
133
- * the template's bundle list and patch-reload policy; local state from the
130
+ * the template's bundle list; local state from the
134
131
  * same-named shipped profile is not read, and no inheritance metadata is
135
132
  * persisted. Shipped profile names are reserved, and the target directory is
136
133
  * claimed exclusively so existing or concurrent state is never reused.
@@ -157,7 +154,7 @@ function initializeProfileFromDefault(name, fromDefaultProfile, home = resolveDs
157
154
  throw new Error(`${NAME}: profile directory ${dir} already exists; choose an unused profile name`);
158
155
  }
159
156
  try {
160
- initProfile(dir, template.bundles, template.patchReload);
157
+ initProfile(dir, template.bundles);
161
158
  } catch (error) {
162
159
  try {
163
160
  rmSync(dir, {
@@ -171,24 +168,6 @@ function initializeProfileFromDefault(name, fromDefaultProfile, home = resolveDs
171
168
  }
172
169
  }
173
170
  /**
174
- * Resolve the telemetry opt-out switch into its boot patch. ANY non-empty
175
- * value (including `'0'`/`'false'`) disables: a privacy switch prefers
176
- * off-by-mistake over on-by-mistake. A composition without the telemetry row
177
- * exports nothing, so the switch is then trivially satisfied and no patch is
178
- * generated — custom profiles need not mount telemetry to run with the
179
- * switch set.
180
- * @param disabledEnv - the raw `DSH_TELEMETRY_DISABLED` value (`undefined` when unset).
181
- * @param hasRow - whether the composition carries the telemetry row.
182
- * @returns the disable patch, or `undefined` when no hard-disable patch is required.
183
- */
184
- function resolveTelemetryPatch(disabledEnv, hasRow) {
185
- if ((disabledEnv ?? "") === "" || !hasRow) return void 0;
186
- return {
187
- id: TELEMETRY_ROW_ID,
188
- disabled: true
189
- };
190
- }
191
- /**
192
171
  * Load a resolved profile for `name` and (re)write the empty root config. The
193
172
  * root is always rewritten: the whole composition is patch layers, and the
194
173
  * vendored Loader's tree write-back (a plugin self-disposing persists the
@@ -209,15 +188,6 @@ function prepareProfile(name, userLayer = true, fromDefaultProfile) {
209
188
  writeFileSync(join(profile.dir, PROFILE_ROOT_FILENAME), PROFILE_ROOT_CONFIG);
210
189
  return profile;
211
190
  }
212
- /** The full patch stack of one composed profile, in application order. */
213
- function allPatches(composed) {
214
- return [
215
- ...composed.bundlePatches,
216
- ...composed.profile.patches,
217
- ...composed.homePatches,
218
- ...composed.overlays
219
- ];
220
- }
221
191
  /**
222
192
  * Load `name` and compose its effective patch stack: bundle layers in
223
193
  * `dsh.profile.bundles` order (a base-backed profile gets the base bundle's
@@ -227,131 +197,108 @@ function allPatches(composed) {
227
197
  * then the telemetry switch.
228
198
  * @param name - the profile name.
229
199
  * @param patchFiles - `--patch` overlay paths, in argv order.
200
+ * @param resolutionMode - runtime lookup, disk links, or dual verification of both.
201
+ * @param fromDefaultProfile - shipped template for a missing named profile.
202
+ * @param resolvedProfile - application-owned profile and installation.
230
203
  * @returns the profile and its patch layers.
231
204
  */
232
- async function composeProfile(name, patchFiles, resolutionMode, fromDefaultProfile) {
233
- const profile = prepareProfile(name, true, fromDefaultProfile);
205
+ async function composeProfile(name, patchFiles, resolutionMode, 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);
234
208
  const resolutionOptions = {
235
- installAnchor: INSTALL_ANCHOR,
209
+ installAnchor: resolvedProfile?.installAnchor ?? INSTALL_ANCHOR,
236
210
  profile
237
211
  };
238
- const resolution = resolutionMode === "runtime" ? await createProfileResolutionGeneration(resolutionOptions) : await healProfilesModuleFallback(resolutionOptions);
239
- const homePatches = loadOptionalPatches(NAME, homePatchPath()) ?? [];
240
- const overlays = patchFiles.flatMap((file) => loadOverlayPatches(NAME, resolve(file)));
241
- const bundlePatches = profile.layers.flatMap((layer) => layer.patches);
242
- const rows = /* @__PURE__ */ new Map();
243
- for (const row of composeEntries([
244
- bundlePatches,
245
- profile.patches,
246
- homePatches,
247
- overlays
248
- ])) if (typeof row.id === "string") rows.set(row.id, row);
249
- const composedOverlays = [...overlays];
250
- const telemetryPatch = resolveTelemetryPatch(process.env.DSH_TELEMETRY_DISABLED, rows.has(TELEMETRY_ROW_ID));
251
- if (telemetryPatch !== void 0) composedOverlays.push(telemetryPatch);
212
+ if (resolvedProfile !== void 0 && resolutionMode !== "runtime") healIsolatedProfileModuleFallback(resolvedProfile);
252
213
  return {
253
214
  profile,
254
- resolution,
255
- bundlePatches,
256
- homePatches,
257
- overlays: composedOverlays
215
+ resolution: resolutionMode === "runtime" || resolvedProfile !== void 0 ? await createProfileResolutionGeneration(resolutionOptions) : await healProfilesModuleFallback(resolutionOptions),
216
+ overlays: patchFiles.flatMap((file) => loadOverlayPatches(NAME, resolve(file)))
258
217
  };
259
218
  }
260
219
  /**
261
- * Re-throw a watcher-setup failure unless a shutdown already owns the tree:
262
- * a signal aborted this invocation, or an app requested exit (`ctx.appExit`
263
- * from a fast one-shot) and the root's disposal rejected the in-flight setup
264
- * await. Either way the failure describes a tree that is exiting as asked,
265
- * not a broken watch.
266
- * @param ctx - the booted root context.
267
- * @param signal - this invocation's signal-shutdown fact.
268
- * @param error - the setup failure.
269
- */
270
- function suppressShutdownError(ctx, signal, error) {
271
- if (signal.aborted) return;
272
- if (ctx.fiber.state !== 2 || ctx.get("loader") === void 0) return;
273
- throw error;
274
- }
275
- /**
276
220
  * Boot one profile invocation end to end and leave process lifetime to the
277
221
  * mounted plugins (or to a one-shot runner the composition mounts).
278
222
  * @param options - environment snapshot, profile name, overlays, and the booted app's own arguments.
279
223
  * @returns the settled root context and the shutdown controller.
224
+ * @throws after disposing startup resources; cleanup failures retain the original error.
280
225
  */
281
226
  async function runProfile(options) {
282
227
  const disposeProxy = await installProxyFromEnvironment(options.environment, (message) => {
283
228
  process.stderr.write(`${NAME}: ${message}\n`);
284
229
  });
285
- const resolutionMode = process.pkg !== void 0 ? "runtime" : options.resolutionMode ?? "link";
286
- const composed = await composeProfile(options.profile, options.patchFiles, resolutionMode, options.fromDefaultProfile);
230
+ const resolutionMode = process.pkg !== void 0 ? "runtime" : options.resolutionMode ?? "runtime";
287
231
  const app = {};
288
- const appReady = createAppReady();
289
- const shutdown = createProcessShutdown(async () => {
290
- await app.current?.fiber.dispose();
291
- await disposeProxy();
292
- });
293
- const signalShutdown = new AbortController();
294
- const interrupt = (code) => {
295
- signalShutdown.abort();
296
- shutdown.interrupt(code);
297
- };
298
- process.on("SIGTERM", () => {
299
- interrupt(0);
300
- });
301
- process.on("SIGINT", () => {
302
- interrupt(130);
303
- });
304
- installFailLoud(NAME, process, async () => {
305
- await app.current?.fiber.dispose();
306
- });
307
- const rootConfig = join(composed.profile.dir, PROFILE_ROOT_FILENAME);
308
- const composeLive = () => structuredClone([
309
- ...composed.bundlePatches,
310
- ...loadOptionalPatches(NAME, composed.profile.patchPath) ?? [],
311
- ...loadOptionalPatches(NAME, homePatchPath()) ?? [],
312
- ...composed.overlays
313
- ]);
314
- const ctx = await boot(NAME, rootConfig, structuredClone(allPatches(composed)), async (hostCtx) => {
315
- app.current = hostCtx;
316
- hostCtx.provide(DSH_LAUNCH_ENVIRONMENT_KEY, options.environment);
317
- await hostCtx.plugin(PluginPackages, resolutionMode === "link" ? {} : {
318
- generation: composed.resolution,
319
- behavior: resolutionMode === "dual" ? "verify" : "enforce"
232
+ let disposal;
233
+ const dispose = () => disposal ??= (async () => {
234
+ const failures = [];
235
+ for (const release of [() => app.current?.fiber.dispose(), disposeProxy]) try {
236
+ await release();
237
+ } catch (error) {
238
+ failures.push(error);
239
+ }
240
+ if (failures.length === 1) throw failures[0];
241
+ if (failures.length > 1) throw new AggregateError(failures, "dsh: profile cleanup failed");
242
+ })();
243
+ try {
244
+ const composed = await composeProfile(options.profile, options.patchFiles, resolutionMode, options.fromDefaultProfile, options.resolvedProfile);
245
+ const appReady = createAppReady();
246
+ const shutdown = createProcessShutdown(dispose);
247
+ const signalShutdown = new AbortController();
248
+ const interrupt = (code) => {
249
+ signalShutdown.abort();
250
+ shutdown.interrupt(code);
251
+ };
252
+ process.on("SIGTERM", () => {
253
+ interrupt(0);
320
254
  });
321
- provideCmdline(hostCtx, {
322
- args: options.args,
323
- exit: (code) => void shutdown.shutdown(code),
324
- ready: appReady.service
255
+ process.on("SIGINT", () => {
256
+ interrupt(130);
325
257
  });
326
- });
327
- app.current = ctx;
328
- if (composed.profile.patchReload === "live" && !signalShutdown.signal.aborted && ctx.fiber.state === 2 && ctx.get("loader") !== void 0) try {
329
- if (ctx.get("hmr") === void 0) {
330
- if (ctx.get("timer") === void 0) await ctx.loader.create({ name: "@deepseek-ai/cordis-plugin-timer" });
331
- await ctx.loader.create({
332
- name: "@deepseek-ai/cordis-plugin-hmr",
333
- config: { root: [] }
334
- });
335
- await ctx.loader.await();
336
- }
337
- await watchUserPatches(ctx, {
338
- binName: NAME,
339
- filename: composed.profile.patchPath,
340
- compose: composeLive
258
+ installFailLoud(NAME, process, async () => {
259
+ await app.current?.fiber.dispose();
341
260
  });
342
- await watchUserPatches(ctx, {
343
- binName: NAME,
344
- filename: homePatchPath(),
345
- compose: composeLive
261
+ const rootConfig = join(composed.profile.dir, PROFILE_ROOT_FILENAME);
262
+ const profileContext = {
263
+ name: options.profile,
264
+ ...options.packageManager === void 0 ? {} : { packageManager: options.packageManager },
265
+ dir: composed.profile.dir,
266
+ patchPath: composed.profile.patchPath,
267
+ installAnchor: options.resolvedProfile?.installAnchor ?? INSTALL_ANCHOR,
268
+ startedBundles: composed.profile.layers.map((layer) => layer.packageName),
269
+ cwd: process.cwd(),
270
+ home: resolveDshHome(),
271
+ overlays: composed.overlays,
272
+ telemetryDisabledEnv: process.env.DSH_TELEMETRY_DISABLED
273
+ };
274
+ const ctx = await boot(NAME, rootConfig, readProfilePatches(NAME, profileContext, composed.profile), async (hostCtx) => {
275
+ app.current = hostCtx;
276
+ hostCtx.provide("profileContext", profileContext);
277
+ hostCtx.provide(DSH_LAUNCH_ENVIRONMENT_KEY, options.environment);
278
+ await hostCtx.plugin(PluginPackages, resolutionMode === "link" ? {} : {
279
+ generation: composed.resolution,
280
+ behavior: resolutionMode === "dual" ? "verify" : "enforce"
281
+ });
282
+ provideCmdline(hostCtx, {
283
+ args: options.args,
284
+ exit: (code) => void shutdown.shutdown(code),
285
+ ready: appReady.service
286
+ });
346
287
  });
288
+ app.current = ctx;
289
+ if (!signalShutdown.signal.aborted && ctx.fiber.state === 2 && ctx.get("loader") !== void 0) appReady.commit();
290
+ return {
291
+ ctx,
292
+ shutdown
293
+ };
347
294
  } catch (error) {
348
- suppressShutdownError(ctx, signalShutdown.signal, error);
295
+ try {
296
+ await dispose();
297
+ } catch (cleanupError) {
298
+ throw new AggregateError([error, cleanupError], "dsh: profile startup and cleanup failed");
299
+ }
300
+ throw error;
349
301
  }
350
- if (!signalShutdown.signal.aborted && ctx.fiber.state === 2 && ctx.get("loader") !== void 0) appReady.commit();
351
- return {
352
- ctx,
353
- shutdown
354
- };
355
302
  }
356
303
  //#endregion
357
- export { prepareProfile as a, initializeProfileFromDefault as i, PROFILE_ROOT_FILENAME as n, resolveTelemetryPatch as o, homePatchPath as r, runProfile as s, INSTALL_ANCHOR as t };
304
+ 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-BNu17Y9U.js";
2
+ export { INSTALL_ANCHOR, PROFILE_ROOT_FILENAME, homePatchPath, initializeProfileFromDefault, prepareProfile, runProfile };
@@ -0,0 +1,56 @@
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
+ /** Manage a profile's plugins: forward `args` to pnpm inside the profile directory. */
39
+ interface PluginInvocation {
40
+ mode: 'plugin';
41
+ profile: string;
42
+ /** Raw pnpm arguments, verbatim. */
43
+ args: string[];
44
+ }
45
+ /** The resolved `dsh` invocation. Help, version, and errors exit inside {@link parseDshArgs}. */
46
+ export type DshInvocation = ProfileInvocation | DumpConfigInvocation | PluginInvocation;
47
+ /**
48
+ * Resolve argv into one invocation, or print and exit for help, version, or an
49
+ * error.
50
+ * @param argv - arguments after the Node binary and script.
51
+ * @param version - version string printed by `--version`.
52
+ * @returns the resolved invocation.
53
+ */
54
+ export declare function parseDshArgs(argv: readonly string[], version: string): DshInvocation;
55
+ export {};
56
+ //# sourceMappingURL=args.d.ts.map
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Command-line entry for dsh.
4
+ * @module @deepseek-ai/dsh/bin
5
+ */
6
+ /**
7
+ * Run the public dsh command-line interface.
8
+ * @returns a promise that settles when the selected command mode finishes.
9
+ */
10
+ export declare function runCli(): Promise<void>;
11
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1,18 @@
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
+ /**
9
+ * Print a profile composition with comments naming each source file and patch layer.
10
+ * @param profile - the profile name.
11
+ * @param defaultOnly - omit the profile's user layer and `--patch` overlays
12
+ * (the recovery diagnostic for a broken `cordis.patch.yml`, which is then
13
+ * never parsed).
14
+ * @param patches - `--patch` overlay paths, in argv order.
15
+ * @param fromDefaultProfile - shipped template used once to initialize a missing profile.
16
+ */
17
+ export declare function runDumpConfig(profile: string, defaultOnly: boolean, patches: readonly string[], fromDefaultProfile?: string): void;
18
+ //# sourceMappingURL=dump-config.d.ts.map
@@ -0,0 +1,7 @@
1
+ /** Run package management for a profile.
2
+ * @param profile Profile name.
3
+ * @param args Pnpm arguments relative to the invoking directory.
4
+ * @returns Pnpm exit code.
5
+ */
6
+ export declare function runPlugin(profile: string, args: readonly string[]): Promise<number>;
7
+ //# 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,92 @@
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, type ProfileResolutionMode } 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
+ /** Module fallback backend; defaults to runtime. Plain Node callers may override it; pkg executables always use runtime. */
79
+ resolutionMode?: ProfileResolutionMode;
80
+ }
81
+ /**
82
+ * Boot one profile invocation end to end and leave process lifetime to the
83
+ * mounted plugins (or to a one-shot runner the composition mounts).
84
+ * @param options - environment snapshot, profile name, overlays, and the booted app's own arguments.
85
+ * @returns the settled root context and the shutdown controller.
86
+ * @throws after disposing startup resources; cleanup failures retain the original error.
87
+ */
88
+ export declare function runProfile(options: RunProfileOptions): Promise<{
89
+ ctx: Context;
90
+ shutdown: ProcessShutdown;
91
+ }>;
92
+ //# 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