@chatcode/chatcode-cli-test 1.0.47 → 3.0.1
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 +6 -0
- package/README.md +41 -135
- package/README.zh.md +63 -0
- package/lib/bin.js +302 -0
- package/lib/dump-config-Bn-CzGIR.js +53 -0
- package/lib/home-migration-BejD6LQn.js +307 -0
- package/lib/plugin-DrWxOiv2.js +31 -0
- package/lib/profile-boot-DNB5by4u.js +307 -0
- package/lib/profile-boot.js +2 -0
- package/lib/types/args.d.ts +76 -0
- package/lib/types/bin.d.ts +15 -0
- package/lib/types/dump-config.d.ts +18 -0
- package/lib/types/home-migration.d.ts +58 -0
- package/lib/types/plugin.d.ts +7 -0
- package/lib/types/process-shutdown.d.ts +20 -0
- package/lib/types/profile-boot.d.ts +92 -0
- package/lib/types/startup-diagnostics.d.ts +19 -0
- package/package.json +165 -112
- package/bin/cli.js +0 -102
- package/bin/generation-supervisor.js +0 -142
- package/dist/cli.js +0 -8793
- package/dist/vendor/ripgrep/COPYING +0 -3
- package/dist/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/dist/vendor/ripgrep/arm64-linux/rg +0 -0
- package/dist/vendor/ripgrep/arm64-win32/rg.exe +0 -0
- package/dist/vendor/ripgrep/x64-darwin/rg +0 -0
- package/dist/vendor/ripgrep/x64-linux/rg +0 -0
- package/dist/vendor/ripgrep/x64-win32/rg.exe +0 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { PROFILE_PATCH_FILENAME, PROFILE_TEMPLATES, PluginPackages, boot, createProfileResolutionGeneration, healIsolatedProfileModuleFallback, healProfilesModuleFallback, initProfile, installFailLoud, loadOverlayPatches, loadProfile, readProfilePatches, resolveProfileDir } from "@deepseek-ai/dsh-app-boot";
|
|
4
|
+
import { resolveChatCodeCliHome } from "@deepseek-ai/dsh-home-paths";
|
|
5
|
+
import { dirname, join, resolve } from "node:path";
|
|
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 ChatCode CLI 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 @chatcode/chatcode-cli/profile-boot
|
|
84
|
+
*/
|
|
85
|
+
const NAME = "ChatCode CLI";
|
|
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 (`$CHATCODE_CLI_HOME/cordis.patch.yml`), applied
|
|
111
|
+
* over every profile's own layer. Resolved per call, not at module load:
|
|
112
|
+
* `$CHATCODE_CLI_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(resolveChatCodeCliHome(), PROFILE_PATCH_FILENAME);
|
|
117
|
+
}
|
|
118
|
+
/** Absolute path of this ChatCode CLI 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 = `# ChatCode CLI 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 = resolveChatCodeCliHome()) {
|
|
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, {
|
|
188
|
+
pluginCommand: "chatcode-cli",
|
|
189
|
+
userLayer
|
|
190
|
+
});
|
|
191
|
+
writeFileSync(join(profile.dir, PROFILE_ROOT_FILENAME), PROFILE_ROOT_CONFIG);
|
|
192
|
+
return profile;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Load `name` and compose its effective patch stack: bundle layers in
|
|
196
|
+
* `dsh.profile.bundles` order (a base-backed profile gets the base bundle's
|
|
197
|
+
* platform-gated shell rows), the profile's user layer, the home-level user
|
|
198
|
+
* layer (`$DSH_HOME/cordis.patch.yml` — machine-local preferences that apply
|
|
199
|
+
* to every profile, so it outranks the per-profile layer), `--patch` overlays,
|
|
200
|
+
* then the telemetry switch.
|
|
201
|
+
* @param name - the profile name.
|
|
202
|
+
* @param patchFiles - `--patch` overlay paths, in argv order.
|
|
203
|
+
* @param resolutionMode - runtime lookup, disk links, or dual verification of both.
|
|
204
|
+
* @param fromDefaultProfile - shipped template for a missing named profile.
|
|
205
|
+
* @param resolvedProfile - application-owned profile and installation.
|
|
206
|
+
* @returns the profile and its patch layers.
|
|
207
|
+
*/
|
|
208
|
+
async function composeProfile(name, patchFiles, resolutionMode, fromDefaultProfile, resolvedProfile) {
|
|
209
|
+
const profile = resolvedProfile?.profile ?? prepareProfile(name, true, fromDefaultProfile);
|
|
210
|
+
if (resolvedProfile !== void 0) writeFileSync(join(profile.dir, PROFILE_ROOT_FILENAME), PROFILE_ROOT_CONFIG);
|
|
211
|
+
const resolutionOptions = {
|
|
212
|
+
installAnchor: resolvedProfile?.installAnchor ?? INSTALL_ANCHOR,
|
|
213
|
+
profile
|
|
214
|
+
};
|
|
215
|
+
if (resolvedProfile !== void 0 && resolutionMode !== "runtime") healIsolatedProfileModuleFallback(resolvedProfile);
|
|
216
|
+
return {
|
|
217
|
+
profile,
|
|
218
|
+
resolution: resolutionMode === "runtime" || resolvedProfile !== void 0 ? await createProfileResolutionGeneration(resolutionOptions) : await healProfilesModuleFallback(resolutionOptions),
|
|
219
|
+
overlays: patchFiles.flatMap((file) => loadOverlayPatches(NAME, resolve(file)))
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Boot one profile invocation end to end and leave process lifetime to the
|
|
224
|
+
* mounted plugins (or to a one-shot runner the composition mounts).
|
|
225
|
+
* @param options - environment snapshot, profile name, overlays, and the booted app's own arguments.
|
|
226
|
+
* @returns the settled root context and the shutdown controller.
|
|
227
|
+
* @throws after disposing startup resources; cleanup failures retain the original error.
|
|
228
|
+
*/
|
|
229
|
+
async function runProfile(options) {
|
|
230
|
+
const disposeProxy = await installProxyFromEnvironment(options.environment, (message) => {
|
|
231
|
+
process.stderr.write(`${NAME}: ${message}\n`);
|
|
232
|
+
});
|
|
233
|
+
const resolutionMode = process.pkg !== void 0 ? "runtime" : options.resolutionMode ?? "runtime";
|
|
234
|
+
const app = {};
|
|
235
|
+
let disposal;
|
|
236
|
+
const dispose = () => disposal ??= (async () => {
|
|
237
|
+
const failures = [];
|
|
238
|
+
for (const release of [() => app.current?.fiber.dispose(), disposeProxy]) try {
|
|
239
|
+
await release();
|
|
240
|
+
} catch (error) {
|
|
241
|
+
failures.push(error);
|
|
242
|
+
}
|
|
243
|
+
if (failures.length === 1) throw failures[0];
|
|
244
|
+
if (failures.length > 1) throw new AggregateError(failures, "ChatCode CLI: profile cleanup failed");
|
|
245
|
+
})();
|
|
246
|
+
try {
|
|
247
|
+
const composed = await composeProfile(options.profile, options.patchFiles, resolutionMode, options.fromDefaultProfile, options.resolvedProfile);
|
|
248
|
+
const appReady = createAppReady();
|
|
249
|
+
const shutdown = createProcessShutdown(dispose);
|
|
250
|
+
const signalShutdown = new AbortController();
|
|
251
|
+
const interrupt = (code) => {
|
|
252
|
+
signalShutdown.abort();
|
|
253
|
+
shutdown.interrupt(code);
|
|
254
|
+
};
|
|
255
|
+
process.on("SIGTERM", () => {
|
|
256
|
+
interrupt(0);
|
|
257
|
+
});
|
|
258
|
+
process.on("SIGINT", () => {
|
|
259
|
+
interrupt(130);
|
|
260
|
+
});
|
|
261
|
+
installFailLoud(NAME, process, async () => {
|
|
262
|
+
await app.current?.fiber.dispose();
|
|
263
|
+
});
|
|
264
|
+
const rootConfig = join(composed.profile.dir, PROFILE_ROOT_FILENAME);
|
|
265
|
+
const profileContext = {
|
|
266
|
+
name: options.profile,
|
|
267
|
+
...options.packageManager === void 0 ? {} : { packageManager: options.packageManager },
|
|
268
|
+
dir: composed.profile.dir,
|
|
269
|
+
patchPath: composed.profile.patchPath,
|
|
270
|
+
installAnchor: options.resolvedProfile?.installAnchor ?? INSTALL_ANCHOR,
|
|
271
|
+
startedBundles: composed.profile.layers.map((layer) => layer.packageName),
|
|
272
|
+
cwd: process.cwd(),
|
|
273
|
+
home: resolveChatCodeCliHome(),
|
|
274
|
+
overlays: composed.overlays,
|
|
275
|
+
telemetryDisabledEnv: process.env.CHATCODE_CLI_TELEMETRY_DISABLED ?? process.env.DSH_TELEMETRY_DISABLED
|
|
276
|
+
};
|
|
277
|
+
const ctx = await boot(NAME, rootConfig, readProfilePatches(NAME, profileContext, composed.profile), async (hostCtx) => {
|
|
278
|
+
app.current = hostCtx;
|
|
279
|
+
hostCtx.provide("profileContext", profileContext);
|
|
280
|
+
hostCtx.provide(DSH_LAUNCH_ENVIRONMENT_KEY, options.environment);
|
|
281
|
+
await hostCtx.plugin(PluginPackages, resolutionMode === "link" ? {} : {
|
|
282
|
+
generation: composed.resolution,
|
|
283
|
+
behavior: resolutionMode === "dual" ? "verify" : "enforce"
|
|
284
|
+
});
|
|
285
|
+
provideCmdline(hostCtx, {
|
|
286
|
+
args: options.args,
|
|
287
|
+
exit: (code) => void shutdown.shutdown(code),
|
|
288
|
+
ready: appReady.service
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
app.current = ctx;
|
|
292
|
+
if (!signalShutdown.signal.aborted && ctx.fiber.state === 2 && ctx.get("loader") !== void 0) appReady.commit();
|
|
293
|
+
return {
|
|
294
|
+
ctx,
|
|
295
|
+
shutdown
|
|
296
|
+
};
|
|
297
|
+
} catch (error) {
|
|
298
|
+
try {
|
|
299
|
+
await dispose();
|
|
300
|
+
} catch (cleanupError) {
|
|
301
|
+
throw new AggregateError([error, cleanupError], "ChatCode CLI: profile startup and cleanup failed");
|
|
302
|
+
}
|
|
303
|
+
throw error;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
//#endregion
|
|
307
|
+
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-DNB5by4u.js";
|
|
2
|
+
export { INSTALL_ANCHOR, PROFILE_ROOT_FILENAME, homePatchPath, initializeProfileFromDefault, prepareProfile, runProfile };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commander adapter for the ChatCode CLI launcher.
|
|
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
|
+
* `chatcode-cli --profile cli --resume abc` boots the cli profile with
|
|
11
|
+
* `--resume abc`, and `chatcode-cli --profile web -h` prints the web app's
|
|
12
|
+
* help, not this one's.
|
|
13
|
+
*
|
|
14
|
+
* `chatcode-cli <name>` abbreviates `chatcode-cli --profile <name>`; `plugin`
|
|
15
|
+
* manages a profile's plugin dependencies by forwarding to pnpm. A bare
|
|
16
|
+
* public launcher boots `$CHATCODE_CLI_DEFAULT_PROFILE`, then legacy
|
|
17
|
+
* `$DSH_DEFAULT_PROFILE`, else the builtin `cli` profile.
|
|
18
|
+
* @module @chatcode/chatcode-cli/args
|
|
19
|
+
*/
|
|
20
|
+
/** Environment variables controlling the bare-launcher default profile. */
|
|
21
|
+
export declare const DEFAULT_PROFILE_ENV = "CHATCODE_CLI_DEFAULT_PROFILE";
|
|
22
|
+
export declare const LEGACY_DEFAULT_PROFILE_ENV = "DSH_DEFAULT_PROFILE";
|
|
23
|
+
/** Builtin profile selected by a bare `chatcode-cli` or `cco` invocation. */
|
|
24
|
+
export declare const BUILTIN_DEFAULT_PROFILE = "cli";
|
|
25
|
+
/** Resolve the bare-launcher profile with canonical-before-legacy precedence. */
|
|
26
|
+
export declare function resolveDefaultProfile(env?: Record<string, string | undefined>): string;
|
|
27
|
+
/** Boot a named profile and hand it the invocation's inner arguments. */
|
|
28
|
+
interface ProfileInvocation {
|
|
29
|
+
mode: 'profile';
|
|
30
|
+
profile: string;
|
|
31
|
+
/** Shipped template used once to initialize a missing profile. */
|
|
32
|
+
fromDefaultProfile?: string | undefined;
|
|
33
|
+
/** Extra patch-list overlays applied after the profile's own layer, in argv order. */
|
|
34
|
+
patches: string[];
|
|
35
|
+
/** Everything after the launcher's own flags, verbatim, for injected app plugins. */
|
|
36
|
+
args: string[];
|
|
37
|
+
}
|
|
38
|
+
/** Print a composed profile tree and exit without booting. */
|
|
39
|
+
interface DumpConfigInvocation {
|
|
40
|
+
mode: 'dump-config';
|
|
41
|
+
profile: string;
|
|
42
|
+
/** Shipped template used once to initialize a missing profile. */
|
|
43
|
+
fromDefaultProfile?: string | undefined;
|
|
44
|
+
/** Omit the profile's user layer and --patch overlays; print bundle layers only. */
|
|
45
|
+
defaultOnly: boolean;
|
|
46
|
+
patches: string[];
|
|
47
|
+
}
|
|
48
|
+
/** Manage a profile's plugins: forward `args` to pnpm inside the profile directory. */
|
|
49
|
+
interface PluginInvocation {
|
|
50
|
+
mode: 'plugin';
|
|
51
|
+
profile: string;
|
|
52
|
+
/** Raw pnpm arguments, verbatim. */
|
|
53
|
+
args: string[];
|
|
54
|
+
}
|
|
55
|
+
/** Plan or explicitly apply a copy-only migration from legacy user directories. */
|
|
56
|
+
interface MigrationInvocation {
|
|
57
|
+
mode: 'migrate';
|
|
58
|
+
apply: boolean;
|
|
59
|
+
json: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** The resolved ChatCode CLI invocation. Help, version, and errors exit during parsing. */
|
|
62
|
+
export type ChatCodeCliInvocation = ProfileInvocation | DumpConfigInvocation | PluginInvocation | MigrationInvocation;
|
|
63
|
+
/** @deprecated Use {@link ChatCodeCliInvocation}. */
|
|
64
|
+
export type DshInvocation = ChatCodeCliInvocation;
|
|
65
|
+
/**
|
|
66
|
+
* Resolve argv into one invocation, or print and exit for help, version, or an
|
|
67
|
+
* error.
|
|
68
|
+
* @param argv - arguments after the Node binary and script.
|
|
69
|
+
* @param version - version string printed by `--version`.
|
|
70
|
+
* @returns the resolved invocation.
|
|
71
|
+
*/
|
|
72
|
+
export declare function parseChatCodeCliArgs(argv: readonly string[], version: string): ChatCodeCliInvocation;
|
|
73
|
+
/** @deprecated Use {@link parseChatCodeCliArgs}. */
|
|
74
|
+
export declare const parseDshArgs: typeof parseChatCodeCliArgs;
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Command-line entry for ChatCode CLI and its compatibility aliases.
|
|
4
|
+
* @module @chatcode/chatcode-cli/bin
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Set the canonical process identity shared by all launcher aliases.
|
|
8
|
+
*/
|
|
9
|
+
export declare function initializeProcessIdentity(): void;
|
|
10
|
+
/**
|
|
11
|
+
* Run the public ChatCode CLI command-line interface.
|
|
12
|
+
* @returns a promise that settles when the selected command mode finishes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runCli(): Promise<void>;
|
|
15
|
+
//# 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,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy-only migration from the legacy ~/.dsh tree into ChatCode CLI home.
|
|
3
|
+
* @module @chatcode/chatcode-cli/home-migration
|
|
4
|
+
*/
|
|
5
|
+
export declare const HOME_MIGRATION_VERSION = 1;
|
|
6
|
+
export declare const LEGACY_HOME_DIRECTORY = ".dsh";
|
|
7
|
+
export declare const LEGACY_TUI_HOME_DIRECTORY = ".dsh-tui";
|
|
8
|
+
export declare const MIGRATION_RECORD_DIRECTORY = "migration/chatcode-cli-home-v1";
|
|
9
|
+
export type MigrationEntryAction = 'copy-file' | 'create-directory' | 'skip-existing' | 'exclude-transient' | 'skip-unsafe' | 'skip-unreadable';
|
|
10
|
+
export interface HomeMigrationEntry {
|
|
11
|
+
relativePath: string;
|
|
12
|
+
action: MigrationEntryAction;
|
|
13
|
+
kind: 'file' | 'directory' | 'symlink' | 'other';
|
|
14
|
+
reason?: string;
|
|
15
|
+
size?: number;
|
|
16
|
+
mtimeMs?: number;
|
|
17
|
+
/** SHA-256 of a readable source file, used to detect same-size content changes. */
|
|
18
|
+
fingerprint?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface HomeMigrationPlan {
|
|
21
|
+
version: typeof HOME_MIGRATION_VERSION;
|
|
22
|
+
source: string;
|
|
23
|
+
destination: string;
|
|
24
|
+
sourceExists: boolean;
|
|
25
|
+
entries: HomeMigrationEntry[];
|
|
26
|
+
conflicts: string[];
|
|
27
|
+
excluded: string[];
|
|
28
|
+
planId: string;
|
|
29
|
+
}
|
|
30
|
+
export interface HomeMigrationResult {
|
|
31
|
+
plan: HomeMigrationPlan;
|
|
32
|
+
copied: string[];
|
|
33
|
+
createdDirectories: string[];
|
|
34
|
+
skipped: Array<{
|
|
35
|
+
relativePath: string;
|
|
36
|
+
reason: string;
|
|
37
|
+
}>;
|
|
38
|
+
recordPath?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface HomeMigrationRoots {
|
|
41
|
+
source: string;
|
|
42
|
+
destination: string;
|
|
43
|
+
tuiSource: string;
|
|
44
|
+
tuiDestination: string;
|
|
45
|
+
}
|
|
46
|
+
/** Classify state that must never be migrated because it is runtime-local or transient. */
|
|
47
|
+
export declare function isTransientMigrationPath(relativePath: string, kind: HomeMigrationEntry['kind']): boolean;
|
|
48
|
+
/** Resolve the fixed legacy source and the canonical migration destination. */
|
|
49
|
+
export declare function resolveHomeMigrationRoots(env?: Record<string, string | undefined>): HomeMigrationRoots;
|
|
50
|
+
/** Find legacy trees with durable entries that are still absent from the canonical home. */
|
|
51
|
+
export declare function detectPendingHomeMigrations(roots: HomeMigrationRoots): Promise<HomeMigrationPlan[]>;
|
|
52
|
+
/** Inspect both trees and return a deterministic, side-effect-free migration plan. */
|
|
53
|
+
export declare function planHomeMigration(source: string, destination: string): Promise<HomeMigrationPlan>;
|
|
54
|
+
/** Apply exactly one reviewed plan without overwriting destinations or removing legacy data. */
|
|
55
|
+
export declare function applyHomeMigration(plan: HomeMigrationPlan): Promise<HomeMigrationResult>;
|
|
56
|
+
/** Human-readable review output shared by dry-run and apply. */
|
|
57
|
+
export declare function formatHomeMigrationPlan(plan: HomeMigrationPlan): string;
|
|
58
|
+
//# sourceMappingURL=home-migration.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 ChatCode CLI 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 @chatcode/chatcode-cli/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 (`$CHATCODE_CLI_HOME/cordis.patch.yml`), applied
|
|
18
|
+
* over every profile's own layer. Resolved per call, not at module load:
|
|
19
|
+
* `$CHATCODE_CLI_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 ChatCode CLI 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
|