ccem 2.73.0 → 2.74.0
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/dist/index.js +1100 -163
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import Conf2 from "conf";
|
|
6
6
|
import inquirer from "inquirer";
|
|
7
|
-
import
|
|
7
|
+
import chalk8 from "chalk";
|
|
8
8
|
import Table3 from "cli-table3";
|
|
9
9
|
import { spawn as spawn3 } from "child_process";
|
|
10
|
-
import * as
|
|
11
|
-
import * as
|
|
10
|
+
import * as fs14 from "fs";
|
|
11
|
+
import * as path12 from "path";
|
|
12
12
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
13
13
|
|
|
14
14
|
// ../../packages/core/dist/chunk-WF72XTKK.js
|
|
@@ -1043,7 +1043,7 @@ async function parseJSONLFileAsync(filePath, prices, signal) {
|
|
|
1043
1043
|
throw new Error("Aborted");
|
|
1044
1044
|
}
|
|
1045
1045
|
if (lineCount % 1e3 === 0) {
|
|
1046
|
-
await new Promise((
|
|
1046
|
+
await new Promise((resolve5) => setTimeout(resolve5, 0));
|
|
1047
1047
|
}
|
|
1048
1048
|
}
|
|
1049
1049
|
if (!line.trim()) continue;
|
|
@@ -1132,7 +1132,7 @@ async function getUsageStats(signal) {
|
|
|
1132
1132
|
fileStats = cachedFile.stats;
|
|
1133
1133
|
} else {
|
|
1134
1134
|
fileStats = await parseJSONLFileAsync(file, prices, signal);
|
|
1135
|
-
await new Promise((
|
|
1135
|
+
await new Promise((resolve5) => setTimeout(resolve5, 0));
|
|
1136
1136
|
}
|
|
1137
1137
|
return {
|
|
1138
1138
|
file,
|
|
@@ -1312,10 +1312,10 @@ var renderLogoWithEnvPanel = (envName, env, defaultMode) => {
|
|
|
1312
1312
|
const parsed = new URL(url);
|
|
1313
1313
|
const protocol = parsed.protocol + "//";
|
|
1314
1314
|
const host = parsed.host;
|
|
1315
|
-
const
|
|
1315
|
+
const path13 = parsed.pathname + parsed.search;
|
|
1316
1316
|
const hostStart = host.slice(0, 8);
|
|
1317
1317
|
const hostEnd = host.slice(-4);
|
|
1318
|
-
const pathPart =
|
|
1318
|
+
const pathPart = path13.length > 10 ? path13.slice(0, 7) + "..." : path13;
|
|
1319
1319
|
return `${protocol}${hostStart}...${hostEnd}${pathPart}`;
|
|
1320
1320
|
} catch {
|
|
1321
1321
|
return truncate(url, max);
|
|
@@ -1645,7 +1645,7 @@ var renderFooterHints = (hints) => {
|
|
|
1645
1645
|
return minimal;
|
|
1646
1646
|
};
|
|
1647
1647
|
var selectEnvWithKeys = (registries, current) => {
|
|
1648
|
-
return new Promise((
|
|
1648
|
+
return new Promise((resolve5) => {
|
|
1649
1649
|
const envNames = Object.keys(registries);
|
|
1650
1650
|
let selectedIndex = envNames.indexOf(current);
|
|
1651
1651
|
if (selectedIndex === -1) selectedIndex = 0;
|
|
@@ -1707,7 +1707,7 @@ var selectEnvWithKeys = (registries, current) => {
|
|
|
1707
1707
|
}
|
|
1708
1708
|
if (char === "\x1B" && key.length === 1) {
|
|
1709
1709
|
cleanup();
|
|
1710
|
-
|
|
1710
|
+
resolve5({ action: "cancel" });
|
|
1711
1711
|
return;
|
|
1712
1712
|
}
|
|
1713
1713
|
if (char === "\x1B[A" || char === "k") {
|
|
@@ -1724,27 +1724,27 @@ var selectEnvWithKeys = (registries, current) => {
|
|
|
1724
1724
|
}
|
|
1725
1725
|
if (char === "\r" || char === "\n") {
|
|
1726
1726
|
cleanup();
|
|
1727
|
-
|
|
1727
|
+
resolve5({ action: "select", name: envNames[selectedIndex] });
|
|
1728
1728
|
return;
|
|
1729
1729
|
}
|
|
1730
1730
|
if (char === "e" || char === "E") {
|
|
1731
1731
|
cleanup();
|
|
1732
|
-
|
|
1732
|
+
resolve5({ action: "edit", name: envNames[selectedIndex] });
|
|
1733
1733
|
return;
|
|
1734
1734
|
}
|
|
1735
1735
|
if (char === "r" || char === "R") {
|
|
1736
1736
|
cleanup();
|
|
1737
|
-
|
|
1737
|
+
resolve5({ action: "rename", name: envNames[selectedIndex] });
|
|
1738
1738
|
return;
|
|
1739
1739
|
}
|
|
1740
1740
|
if (char === "c" || char === "C") {
|
|
1741
1741
|
cleanup();
|
|
1742
|
-
|
|
1742
|
+
resolve5({ action: "copy", name: envNames[selectedIndex] });
|
|
1743
1743
|
return;
|
|
1744
1744
|
}
|
|
1745
1745
|
if (char === "d" || char === "D") {
|
|
1746
1746
|
cleanup();
|
|
1747
|
-
|
|
1747
|
+
resolve5({ action: "delete", name: envNames[selectedIndex] });
|
|
1748
1748
|
return;
|
|
1749
1749
|
}
|
|
1750
1750
|
};
|
|
@@ -2253,7 +2253,7 @@ async function launchClaude(options) {
|
|
|
2253
2253
|
console.log(renderStarting());
|
|
2254
2254
|
}
|
|
2255
2255
|
const sessionsDir = ensureSessionsDir();
|
|
2256
|
-
return new Promise((
|
|
2256
|
+
return new Promise((resolve5) => {
|
|
2257
2257
|
let provenanceTracking = null;
|
|
2258
2258
|
const child = spawn("claude", args, {
|
|
2259
2259
|
stdio: "inherit",
|
|
@@ -3019,7 +3019,7 @@ var setupEnvSettings = () => {
|
|
|
3019
3019
|
}
|
|
3020
3020
|
};
|
|
3021
3021
|
var setupMcpTool = () => {
|
|
3022
|
-
return new Promise((
|
|
3022
|
+
return new Promise((resolve5) => {
|
|
3023
3023
|
console.log(chalk4.cyan(" \u2192 \u6B63\u5728\u6DFB\u52A0 chrome-devtools MCP \u5DE5\u5177..."));
|
|
3024
3024
|
const child = spawn2("claude", [
|
|
3025
3025
|
"mcp",
|
|
@@ -3044,22 +3044,22 @@ var setupMcpTool = () => {
|
|
|
3044
3044
|
child.on("exit", (code) => {
|
|
3045
3045
|
if (code === 0) {
|
|
3046
3046
|
console.log(chalk4.green(" \u2713 \u5DF2\u6DFB\u52A0 chrome-devtools MCP \u5DE5\u5177"));
|
|
3047
|
-
|
|
3047
|
+
resolve5(true);
|
|
3048
3048
|
} else {
|
|
3049
3049
|
if (stderr.includes("already exists") || stdout.includes("already exists")) {
|
|
3050
3050
|
console.log(chalk4.gray(" \u2713 chrome-devtools MCP \u5DE5\u5177\u5DF2\u5B58\u5728"));
|
|
3051
|
-
|
|
3051
|
+
resolve5(true);
|
|
3052
3052
|
} else {
|
|
3053
3053
|
console.error(chalk4.red(` \u2717 \u6DFB\u52A0 MCP \u5DE5\u5177\u5931\u8D25 (code: ${code})`));
|
|
3054
3054
|
if (stderr) console.error(chalk4.gray(` ${stderr.trim()}`));
|
|
3055
|
-
|
|
3055
|
+
resolve5(false);
|
|
3056
3056
|
}
|
|
3057
3057
|
}
|
|
3058
3058
|
});
|
|
3059
3059
|
child.on("error", (err) => {
|
|
3060
3060
|
console.error(chalk4.red(` \u2717 \u6267\u884C claude \u547D\u4EE4\u5931\u8D25: ${err.message}`));
|
|
3061
3061
|
console.log(chalk4.yellow(" \u8BF7\u786E\u4FDD\u5DF2\u5B89\u88C5 Claude Code CLI"));
|
|
3062
|
-
|
|
3062
|
+
resolve5(false);
|
|
3063
3063
|
});
|
|
3064
3064
|
});
|
|
3065
3065
|
};
|
|
@@ -3636,7 +3636,7 @@ function SkillSelector({ onSelect, onCancel }) {
|
|
|
3636
3636
|
|
|
3637
3637
|
// src/components/index.tsx
|
|
3638
3638
|
async function runSkillSelector() {
|
|
3639
|
-
return new Promise((
|
|
3639
|
+
return new Promise((resolve5) => {
|
|
3640
3640
|
let resolved = false;
|
|
3641
3641
|
const { unmount, waitUntilExit } = render(
|
|
3642
3642
|
/* @__PURE__ */ React2.createElement(
|
|
@@ -3647,23 +3647,23 @@ async function runSkillSelector() {
|
|
|
3647
3647
|
resolved = true;
|
|
3648
3648
|
unmount();
|
|
3649
3649
|
if (result === "custom") {
|
|
3650
|
-
|
|
3650
|
+
resolve5({ type: "custom" });
|
|
3651
3651
|
} else {
|
|
3652
|
-
|
|
3652
|
+
resolve5({ type: "skill", skill: result });
|
|
3653
3653
|
}
|
|
3654
3654
|
},
|
|
3655
3655
|
onCancel: () => {
|
|
3656
3656
|
if (resolved) return;
|
|
3657
3657
|
resolved = true;
|
|
3658
3658
|
unmount();
|
|
3659
|
-
|
|
3659
|
+
resolve5({ type: "cancelled" });
|
|
3660
3660
|
}
|
|
3661
3661
|
}
|
|
3662
3662
|
)
|
|
3663
3663
|
);
|
|
3664
3664
|
waitUntilExit().then(() => {
|
|
3665
3665
|
if (!resolved) {
|
|
3666
|
-
|
|
3666
|
+
resolve5({ type: "cancelled" });
|
|
3667
3667
|
}
|
|
3668
3668
|
});
|
|
3669
3669
|
});
|
|
@@ -3754,13 +3754,13 @@ var getUniqueImportedEnvironmentName = (baseName, existingNames) => {
|
|
|
3754
3754
|
}
|
|
3755
3755
|
return newName;
|
|
3756
3756
|
};
|
|
3757
|
-
var readAllStdin = () => new Promise((
|
|
3757
|
+
var readAllStdin = () => new Promise((resolve5, reject) => {
|
|
3758
3758
|
let data = "";
|
|
3759
3759
|
process.stdin.setEncoding("utf8");
|
|
3760
3760
|
process.stdin.on("data", (chunk) => {
|
|
3761
3761
|
data += chunk;
|
|
3762
3762
|
});
|
|
3763
|
-
process.stdin.on("end", () =>
|
|
3763
|
+
process.stdin.on("end", () => resolve5(data));
|
|
3764
3764
|
process.stdin.on("error", reject);
|
|
3765
3765
|
});
|
|
3766
3766
|
var resolveLoadCredentials = (options, stdinInput) => {
|
|
@@ -4233,11 +4233,944 @@ function formatCronTaskTableRows(tasks) {
|
|
|
4233
4233
|
]);
|
|
4234
4234
|
}
|
|
4235
4235
|
|
|
4236
|
+
// src/dsh/cli.ts
|
|
4237
|
+
import chalk7 from "chalk";
|
|
4238
|
+
|
|
4239
|
+
// src/dsh/provider.ts
|
|
4240
|
+
import { createHash } from "crypto";
|
|
4241
|
+
var DSH_API_KEY_ENV = "CCEM_DSH_API_KEY";
|
|
4242
|
+
var DSH_PROTOCOL = "anthropic-messages";
|
|
4243
|
+
var DSH_TIERS = ["opus", "sonnet", "haiku"];
|
|
4244
|
+
var DshProjectionError = class extends Error {
|
|
4245
|
+
code;
|
|
4246
|
+
constructor(code, message) {
|
|
4247
|
+
super(message);
|
|
4248
|
+
this.name = "DshProjectionError";
|
|
4249
|
+
this.code = code;
|
|
4250
|
+
}
|
|
4251
|
+
};
|
|
4252
|
+
var TIER_MODEL_KEYS = [
|
|
4253
|
+
["opus", "ANTHROPIC_DEFAULT_OPUS_MODEL"],
|
|
4254
|
+
["sonnet", "ANTHROPIC_DEFAULT_SONNET_MODEL"],
|
|
4255
|
+
["haiku", "ANTHROPIC_DEFAULT_HAIKU_MODEL"]
|
|
4256
|
+
];
|
|
4257
|
+
var TIER_MODEL_ALIASES2 = /* @__PURE__ */ new Set(["opus", "sonnet", "haiku"]);
|
|
4258
|
+
function firstConcreteModel(value) {
|
|
4259
|
+
const model = value?.trim();
|
|
4260
|
+
if (!model || TIER_MODEL_ALIASES2.has(model)) return void 0;
|
|
4261
|
+
return model;
|
|
4262
|
+
}
|
|
4263
|
+
function collectDshModels(envName, envConfig) {
|
|
4264
|
+
const runtimeEnv = resolveEnvConfigForRuntime(envName, envConfig);
|
|
4265
|
+
const models = [];
|
|
4266
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4267
|
+
const tierModels = {};
|
|
4268
|
+
const push = (model) => {
|
|
4269
|
+
if (!model || seen.has(model)) return model;
|
|
4270
|
+
seen.add(model);
|
|
4271
|
+
models.push(model);
|
|
4272
|
+
return model;
|
|
4273
|
+
};
|
|
4274
|
+
for (const [tier, key] of TIER_MODEL_KEYS) {
|
|
4275
|
+
tierModels[tier] = push(firstConcreteModel(runtimeEnv[key])) ?? tierModels[tier];
|
|
4276
|
+
}
|
|
4277
|
+
push(firstConcreteModel(runtimeEnv.CLAUDE_CODE_SUBAGENT_MODEL));
|
|
4278
|
+
push(firstConcreteModel(runtimeEnv.ANTHROPIC_MODEL));
|
|
4279
|
+
return { models, tierModels };
|
|
4280
|
+
}
|
|
4281
|
+
function generateProviderId(envName) {
|
|
4282
|
+
const slug = envName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 24) || "env";
|
|
4283
|
+
const hash = createHash("sha256").update(envName).digest("hex").slice(0, 12);
|
|
4284
|
+
return `ccem-${slug}-${hash}`;
|
|
4285
|
+
}
|
|
4286
|
+
function verifyTokenPresence(envConfig) {
|
|
4287
|
+
const raw = envConfig.ANTHROPIC_AUTH_TOKEN?.trim();
|
|
4288
|
+
return raw ? "present" : "missing";
|
|
4289
|
+
}
|
|
4290
|
+
function defaultSelectedModel(catalog) {
|
|
4291
|
+
return catalog.tierModels.opus ?? catalog.tierModels.sonnet ?? catalog.tierModels.haiku ?? catalog.models[0];
|
|
4292
|
+
}
|
|
4293
|
+
function deriveDshProvider(envName, envConfig, options = {}) {
|
|
4294
|
+
const { tier, model } = options;
|
|
4295
|
+
if (tier !== void 0 && model !== void 0) {
|
|
4296
|
+
throw new DshProjectionError(
|
|
4297
|
+
"TIER_MODEL_CONFLICT",
|
|
4298
|
+
"Options --tier and --model are mutually exclusive; pass one of them"
|
|
4299
|
+
);
|
|
4300
|
+
}
|
|
4301
|
+
if (envName === OFFICIAL_ENV_NAME) {
|
|
4302
|
+
throw new DshProjectionError(
|
|
4303
|
+
"OFFICIAL_ENV_REJECTED",
|
|
4304
|
+
`Environment '${OFFICIAL_ENV_NAME}' is the OAuth-backed Claude environment; ccem dsh projects non-official Anthropic-compatible environments only`
|
|
4305
|
+
);
|
|
4306
|
+
}
|
|
4307
|
+
const baseURL = envConfig.ANTHROPIC_BASE_URL?.trim();
|
|
4308
|
+
if (!baseURL) {
|
|
4309
|
+
throw new DshProjectionError(
|
|
4310
|
+
"MISSING_BASE_URL",
|
|
4311
|
+
`Environment '${envName ?? "<unknown>"}' has no ANTHROPIC_BASE_URL`
|
|
4312
|
+
);
|
|
4313
|
+
}
|
|
4314
|
+
const credentialState = verifyTokenPresence(envConfig);
|
|
4315
|
+
if (credentialState === "missing") {
|
|
4316
|
+
throw new DshProjectionError(
|
|
4317
|
+
"MISSING_TOKEN",
|
|
4318
|
+
`Environment '${envName ?? "<unknown>"}' has no auth token; ccem dsh needs a token-based environment`
|
|
4319
|
+
);
|
|
4320
|
+
}
|
|
4321
|
+
const catalog = collectDshModels(envName, envConfig);
|
|
4322
|
+
let selectedModel;
|
|
4323
|
+
if (tier !== void 0) {
|
|
4324
|
+
if (!DSH_TIERS.includes(tier)) {
|
|
4325
|
+
throw new DshProjectionError(
|
|
4326
|
+
"UNKNOWN_TIER",
|
|
4327
|
+
`Unknown tier '${tier}'; expected one of ${DSH_TIERS.join(", ")}`
|
|
4328
|
+
);
|
|
4329
|
+
}
|
|
4330
|
+
selectedModel = catalog.tierModels[tier];
|
|
4331
|
+
if (!selectedModel) {
|
|
4332
|
+
throw new DshProjectionError(
|
|
4333
|
+
"MISSING_TIER_MODEL",
|
|
4334
|
+
`Environment '${envName ?? "<unknown>"}' pins no concrete '${tier}' tier model; available models: ${catalog.models.join(", ")}`
|
|
4335
|
+
);
|
|
4336
|
+
}
|
|
4337
|
+
} else if (model !== void 0) {
|
|
4338
|
+
const normalized = model.trim();
|
|
4339
|
+
if (!normalized) {
|
|
4340
|
+
throw new DshProjectionError(
|
|
4341
|
+
"MISSING_MODEL",
|
|
4342
|
+
"The --model value must be a non-empty model id"
|
|
4343
|
+
);
|
|
4344
|
+
}
|
|
4345
|
+
selectedModel = normalized;
|
|
4346
|
+
if (!catalog.models.includes(normalized)) {
|
|
4347
|
+
catalog.models.push(normalized);
|
|
4348
|
+
}
|
|
4349
|
+
} else {
|
|
4350
|
+
selectedModel = defaultSelectedModel(catalog);
|
|
4351
|
+
}
|
|
4352
|
+
if (!selectedModel || catalog.models.length === 0) {
|
|
4353
|
+
throw new DshProjectionError(
|
|
4354
|
+
"MISSING_MODEL",
|
|
4355
|
+
`Environment '${envName ?? "<unknown>"}' has no concrete tier model (opus/sonnet/haiku pins are all empty or aliases); pass --model <id> to provide one explicitly`
|
|
4356
|
+
);
|
|
4357
|
+
}
|
|
4358
|
+
const providerId = generateProviderId(envName ?? "unknown");
|
|
4359
|
+
return {
|
|
4360
|
+
providerId,
|
|
4361
|
+
displayName: `CCEM ${envName ?? "<unknown>"}`,
|
|
4362
|
+
baseURL,
|
|
4363
|
+
apiKeyEnv: DSH_API_KEY_ENV,
|
|
4364
|
+
models: catalog.models,
|
|
4365
|
+
selectedModel,
|
|
4366
|
+
credentialState
|
|
4367
|
+
};
|
|
4368
|
+
}
|
|
4369
|
+
|
|
4370
|
+
// src/dsh/launcher.ts
|
|
4371
|
+
import { spawn as defaultSpawn } from "child_process";
|
|
4372
|
+
import * as fs13 from "fs";
|
|
4373
|
+
import * as os7 from "os";
|
|
4374
|
+
import * as path11 from "path";
|
|
4375
|
+
|
|
4376
|
+
// src/dsh/patch.ts
|
|
4377
|
+
var IDENTIFIER_PATTERN = /^[A-Za-z0-9][\w./-]*$/;
|
|
4378
|
+
function yamlScalar(value, trusted = false) {
|
|
4379
|
+
if (trusted && IDENTIFIER_PATTERN.test(value)) return value;
|
|
4380
|
+
return JSON.stringify(value);
|
|
4381
|
+
}
|
|
4382
|
+
function renderCordisPatch(spec) {
|
|
4383
|
+
const lines = [
|
|
4384
|
+
"# Generated by ccem dsh \u2014 ephemeral and secret-free; deleted when the run exits.",
|
|
4385
|
+
"- id: settings",
|
|
4386
|
+
" disabled: true",
|
|
4387
|
+
"- id: llm-pi-ai",
|
|
4388
|
+
" config:",
|
|
4389
|
+
" providers:",
|
|
4390
|
+
` ${yamlScalar(spec.providerId, true)}:`,
|
|
4391
|
+
` displayName: ${yamlScalar(spec.displayName)}`,
|
|
4392
|
+
` apiKeyEnv: ${yamlScalar(DSH_API_KEY_ENV, true)}`,
|
|
4393
|
+
` api: ${DSH_PROTOCOL}`,
|
|
4394
|
+
` baseURL: ${yamlScalar(spec.baseURL)}`,
|
|
4395
|
+
" models:"
|
|
4396
|
+
];
|
|
4397
|
+
for (const model of spec.models) {
|
|
4398
|
+
lines.push(` - id: ${yamlScalar(model)}`);
|
|
4399
|
+
}
|
|
4400
|
+
lines.push(
|
|
4401
|
+
"- id: agent-default-model",
|
|
4402
|
+
" config:",
|
|
4403
|
+
` provider: ${yamlScalar(spec.providerId, true)}`,
|
|
4404
|
+
` model: ${yamlScalar(spec.selectedModel)}`
|
|
4405
|
+
);
|
|
4406
|
+
return `${lines.join("\n")}
|
|
4407
|
+
`;
|
|
4408
|
+
}
|
|
4409
|
+
|
|
4410
|
+
// src/dsh/environment.ts
|
|
4411
|
+
import { execFile } from "child_process";
|
|
4412
|
+
import * as fs12 from "fs";
|
|
4413
|
+
import * as os6 from "os";
|
|
4414
|
+
import * as path10 from "path";
|
|
4415
|
+
import { promisify } from "util";
|
|
4416
|
+
|
|
4417
|
+
// src/dsh/version.ts
|
|
4418
|
+
var DSH_REQUIRED_VERSION = "0.1.1-rc.2";
|
|
4419
|
+
var DSH_NODE_MIN_VERSION = "22.19.0";
|
|
4420
|
+
function parseVersion(input) {
|
|
4421
|
+
const value = input.trim().replace(/^v/i, "");
|
|
4422
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(value);
|
|
4423
|
+
if (!match) return null;
|
|
4424
|
+
const core = [
|
|
4425
|
+
Number(match[1]),
|
|
4426
|
+
Number(match[2]),
|
|
4427
|
+
Number(match[3])
|
|
4428
|
+
];
|
|
4429
|
+
const prerelease = match[4] ? match[4].split(".") : [];
|
|
4430
|
+
return { core, prerelease };
|
|
4431
|
+
}
|
|
4432
|
+
function comparePrereleaseIdentifiers(a, b) {
|
|
4433
|
+
const aNumeric = /^\d+$/.test(a);
|
|
4434
|
+
const bNumeric = /^\d+$/.test(b);
|
|
4435
|
+
if (aNumeric && bNumeric) {
|
|
4436
|
+
return Math.sign(Number(a) - Number(b));
|
|
4437
|
+
}
|
|
4438
|
+
if (aNumeric !== bNumeric) {
|
|
4439
|
+
return aNumeric ? -1 : 1;
|
|
4440
|
+
}
|
|
4441
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
4442
|
+
}
|
|
4443
|
+
function compareVersions(a, b) {
|
|
4444
|
+
const left = parseVersion(a);
|
|
4445
|
+
const right = parseVersion(b);
|
|
4446
|
+
if (!left || !right) {
|
|
4447
|
+
throw new Error(`Cannot compare versions '${a}' and '${b}'`);
|
|
4448
|
+
}
|
|
4449
|
+
for (let i = 0; i < 3; i += 1) {
|
|
4450
|
+
if (left.core[i] !== right.core[i]) {
|
|
4451
|
+
return Math.sign(left.core[i] - right.core[i]);
|
|
4452
|
+
}
|
|
4453
|
+
}
|
|
4454
|
+
if (left.prerelease.length === 0 || right.prerelease.length === 0) {
|
|
4455
|
+
return Math.sign(right.prerelease.length - left.prerelease.length);
|
|
4456
|
+
}
|
|
4457
|
+
for (let i = 0; i < Math.max(left.prerelease.length, right.prerelease.length); i += 1) {
|
|
4458
|
+
const l = left.prerelease[i];
|
|
4459
|
+
const r = right.prerelease[i];
|
|
4460
|
+
if (l === void 0) return -1;
|
|
4461
|
+
if (r === void 0) return 1;
|
|
4462
|
+
const compared = comparePrereleaseIdentifiers(l, r);
|
|
4463
|
+
if (compared !== 0) return compared;
|
|
4464
|
+
}
|
|
4465
|
+
return 0;
|
|
4466
|
+
}
|
|
4467
|
+
function isDshVersionCompatible(version) {
|
|
4468
|
+
const parsed = parseVersion(version);
|
|
4469
|
+
if (!parsed) return false;
|
|
4470
|
+
return compareVersions(version, DSH_REQUIRED_VERSION) === 0;
|
|
4471
|
+
}
|
|
4472
|
+
function isNodeVersionCompatible(version) {
|
|
4473
|
+
const parsed = parseVersion(version);
|
|
4474
|
+
if (!parsed) return false;
|
|
4475
|
+
return compareVersions(version, DSH_NODE_MIN_VERSION) >= 0;
|
|
4476
|
+
}
|
|
4477
|
+
|
|
4478
|
+
// src/dsh/environment.ts
|
|
4479
|
+
var execFileAsync = promisify(execFile);
|
|
4480
|
+
var DSH_PROFILE = "headless";
|
|
4481
|
+
function resolveDshRoot(env = process.env) {
|
|
4482
|
+
const inherited = env.DSH_HOME?.trim();
|
|
4483
|
+
if (inherited) return inherited;
|
|
4484
|
+
const home = env.HOME?.trim() || os6.homedir();
|
|
4485
|
+
return path10.join(home, ".dsh");
|
|
4486
|
+
}
|
|
4487
|
+
function resolveBinOnPath(name, env = process.env, platform = process.platform) {
|
|
4488
|
+
if (name.includes("/") || platform === "win32" && name.includes("\\")) {
|
|
4489
|
+
return fileIsExecutable(name, platform) ? name : null;
|
|
4490
|
+
}
|
|
4491
|
+
const searchDirs = (env.PATH ?? "").split(path10.delimiter).filter(Boolean);
|
|
4492
|
+
const extensions = platform === "win32" ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").toLowerCase().split(";").filter(Boolean) : [""];
|
|
4493
|
+
for (const dir of searchDirs) {
|
|
4494
|
+
for (const ext of extensions) {
|
|
4495
|
+
const candidate = path10.join(dir, name + ext);
|
|
4496
|
+
if (fileIsExecutable(candidate, platform)) return candidate;
|
|
4497
|
+
}
|
|
4498
|
+
}
|
|
4499
|
+
return null;
|
|
4500
|
+
}
|
|
4501
|
+
function fileIsExecutable(file, platform = process.platform) {
|
|
4502
|
+
try {
|
|
4503
|
+
if (platform === "win32") {
|
|
4504
|
+
return fs12.statSync(file).isFile();
|
|
4505
|
+
}
|
|
4506
|
+
fs12.accessSync(file, fs12.constants.X_OK);
|
|
4507
|
+
return fs12.statSync(file).isFile();
|
|
4508
|
+
} catch {
|
|
4509
|
+
return false;
|
|
4510
|
+
}
|
|
4511
|
+
}
|
|
4512
|
+
function resolveDshInvocation(deps = {}) {
|
|
4513
|
+
const env = deps.env ?? process.env;
|
|
4514
|
+
const platform = deps.platform ?? process.platform;
|
|
4515
|
+
if (platform === "win32") {
|
|
4516
|
+
return resolveWindowsDshInvocation(env);
|
|
4517
|
+
}
|
|
4518
|
+
const bin = resolveBinOnPath("dsh", env, platform);
|
|
4519
|
+
if (!bin) return null;
|
|
4520
|
+
return { bin, prefix: [] };
|
|
4521
|
+
}
|
|
4522
|
+
function resolveWindowsDshInvocation(env) {
|
|
4523
|
+
const dshFile = resolveBinOnPath("dsh", env, "win32");
|
|
4524
|
+
if (!dshFile) return null;
|
|
4525
|
+
const ext = path10.extname(dshFile).toLowerCase();
|
|
4526
|
+
if (ext === ".exe" || ext === ".com") {
|
|
4527
|
+
return { bin: dshFile, prefix: [] };
|
|
4528
|
+
}
|
|
4529
|
+
if (ext !== ".cmd") return null;
|
|
4530
|
+
const shimDir = path10.dirname(dshFile);
|
|
4531
|
+
const candidates = [
|
|
4532
|
+
path10.join(shimDir, "node_modules", "@deepseek-ai", "dsh"),
|
|
4533
|
+
path10.join(shimDir, "..", "node_modules", "@deepseek-ai", "dsh")
|
|
4534
|
+
];
|
|
4535
|
+
for (const pkgDir of candidates) {
|
|
4536
|
+
const entryScript = verifyDshPackage(pkgDir);
|
|
4537
|
+
if (entryScript) {
|
|
4538
|
+
const nodeExe = resolveBinOnPath("node", env, "win32");
|
|
4539
|
+
if (!nodeExe) return null;
|
|
4540
|
+
return { bin: nodeExe, prefix: [entryScript] };
|
|
4541
|
+
}
|
|
4542
|
+
}
|
|
4543
|
+
return null;
|
|
4544
|
+
}
|
|
4545
|
+
function verifyDshPackage(pkgDir) {
|
|
4546
|
+
const pkgJsonPath = path10.join(pkgDir, "package.json");
|
|
4547
|
+
try {
|
|
4548
|
+
const raw = fs12.readFileSync(pkgJsonPath, "utf-8");
|
|
4549
|
+
const pkg2 = JSON.parse(raw);
|
|
4550
|
+
if (pkg2.name !== "@deepseek-ai/dsh") return null;
|
|
4551
|
+
const binEntry = typeof pkg2.bin === "string" ? pkg2.bin : pkg2.bin?.dsh ?? null;
|
|
4552
|
+
if (!binEntry || typeof binEntry !== "string") return null;
|
|
4553
|
+
const entryPath = path10.resolve(pkgDir, binEntry);
|
|
4554
|
+
const realEntry = fs12.realpathSync(entryPath);
|
|
4555
|
+
const realPkgDir = fs12.realpathSync(pkgDir);
|
|
4556
|
+
if (!realEntry.startsWith(realPkgDir + path10.sep) && realEntry !== realPkgDir) return null;
|
|
4557
|
+
if (!fs12.statSync(realEntry).isFile()) return null;
|
|
4558
|
+
return realEntry;
|
|
4559
|
+
} catch {
|
|
4560
|
+
return null;
|
|
4561
|
+
}
|
|
4562
|
+
}
|
|
4563
|
+
var VERSION_TOKEN = /v?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/;
|
|
4564
|
+
function extractVersionOutput(stdout) {
|
|
4565
|
+
for (const rawLine of stdout.split(/\r?\n/)) {
|
|
4566
|
+
const line = rawLine.trim();
|
|
4567
|
+
if (!line) continue;
|
|
4568
|
+
const match = VERSION_TOKEN.exec(line);
|
|
4569
|
+
if (match) return match[1];
|
|
4570
|
+
}
|
|
4571
|
+
return null;
|
|
4572
|
+
}
|
|
4573
|
+
var PROBE_ALLOWED_KEYS = /* @__PURE__ */ new Set([
|
|
4574
|
+
// Binary/library resolution
|
|
4575
|
+
"PATH",
|
|
4576
|
+
"PATHEXT",
|
|
4577
|
+
// Windows system roots
|
|
4578
|
+
"SystemRoot",
|
|
4579
|
+
"SYSTEMROOT",
|
|
4580
|
+
"COMSPEC",
|
|
4581
|
+
"windir",
|
|
4582
|
+
// Home/user identity (needed by some runtimes for config discovery)
|
|
4583
|
+
"HOME",
|
|
4584
|
+
"USERPROFILE",
|
|
4585
|
+
"USER",
|
|
4586
|
+
"LOGNAME",
|
|
4587
|
+
// Temp dirs (some runtimes need a writable tmp)
|
|
4588
|
+
"TMPDIR",
|
|
4589
|
+
"TMP",
|
|
4590
|
+
"TEMP",
|
|
4591
|
+
// Locale (affects output encoding/parsing)
|
|
4592
|
+
"LANG",
|
|
4593
|
+
"LC_ALL",
|
|
4594
|
+
"LC_CTYPE",
|
|
4595
|
+
// Terminal (some binaries change behavior if missing)
|
|
4596
|
+
"TERM",
|
|
4597
|
+
"COLORTERM",
|
|
4598
|
+
"TERM_PROGRAM"
|
|
4599
|
+
]);
|
|
4600
|
+
function buildProbeEnv(source = process.env) {
|
|
4601
|
+
const env = {};
|
|
4602
|
+
for (const key of PROBE_ALLOWED_KEYS) {
|
|
4603
|
+
const value = source[key];
|
|
4604
|
+
if (value !== void 0) {
|
|
4605
|
+
env[key] = value;
|
|
4606
|
+
}
|
|
4607
|
+
}
|
|
4608
|
+
return env;
|
|
4609
|
+
}
|
|
4610
|
+
async function probeBinVersion(invocation, deps = {}) {
|
|
4611
|
+
const bin = typeof invocation === "string" ? invocation : invocation.bin;
|
|
4612
|
+
const prefix = typeof invocation === "string" ? [] : invocation.prefix;
|
|
4613
|
+
const args = [...prefix, "--version"];
|
|
4614
|
+
const probeEnv = buildProbeEnv(deps.env ?? process.env);
|
|
4615
|
+
if (deps.exec) return deps.exec(bin, args, probeEnv);
|
|
4616
|
+
try {
|
|
4617
|
+
const { stdout } = await execFileAsync(bin, args, {
|
|
4618
|
+
env: probeEnv,
|
|
4619
|
+
timeout: 15e3,
|
|
4620
|
+
windowsHide: true
|
|
4621
|
+
});
|
|
4622
|
+
const version = extractVersionOutput(stdout);
|
|
4623
|
+
return version ?? (parseVersion(stdout.trim()) ? stdout.trim() : null);
|
|
4624
|
+
} catch {
|
|
4625
|
+
return null;
|
|
4626
|
+
}
|
|
4627
|
+
}
|
|
4628
|
+
async function probeSimpleBinVersion(bin, deps = {}) {
|
|
4629
|
+
const probeEnv = buildProbeEnv(deps.env ?? process.env);
|
|
4630
|
+
if (deps.exec) return deps.exec(bin, ["--version"], probeEnv);
|
|
4631
|
+
try {
|
|
4632
|
+
const { stdout } = await execFileAsync(bin, ["--version"], {
|
|
4633
|
+
env: probeEnv,
|
|
4634
|
+
timeout: 15e3,
|
|
4635
|
+
windowsHide: true
|
|
4636
|
+
});
|
|
4637
|
+
const version = extractVersionOutput(stdout);
|
|
4638
|
+
return version ?? (parseVersion(stdout.trim()) ? stdout.trim() : null);
|
|
4639
|
+
} catch {
|
|
4640
|
+
return null;
|
|
4641
|
+
}
|
|
4642
|
+
}
|
|
4643
|
+
|
|
4644
|
+
// src/dsh/launcher.ts
|
|
4645
|
+
var STRIP_PREFIX_PATTERNS = [
|
|
4646
|
+
/^ANTHROPIC_/i,
|
|
4647
|
+
/^CLAUDE_CODE_/i,
|
|
4648
|
+
/^OPENAI_/i,
|
|
4649
|
+
/^DEEPSEEK_/i,
|
|
4650
|
+
/^AWS_/i,
|
|
4651
|
+
/^AZURE_/i,
|
|
4652
|
+
/^GOOGLE_/i,
|
|
4653
|
+
/^HF_/i,
|
|
4654
|
+
/^HUGGING_FACE_/i,
|
|
4655
|
+
/^DSH_/i
|
|
4656
|
+
];
|
|
4657
|
+
var STRIP_CREDENTIAL_SUBSTRINGS = [
|
|
4658
|
+
/TOKEN/i,
|
|
4659
|
+
/SECRET/i,
|
|
4660
|
+
/PASSWORD/i,
|
|
4661
|
+
/CREDENTIALS?/i,
|
|
4662
|
+
/PRIVATE[_-]?KEY/i,
|
|
4663
|
+
/ACCESS[_-]?KEY/i
|
|
4664
|
+
];
|
|
4665
|
+
var PRESERVE_KEYS = /* @__PURE__ */ new Set([
|
|
4666
|
+
"PATH",
|
|
4667
|
+
"HOME",
|
|
4668
|
+
"USER",
|
|
4669
|
+
"SHELL",
|
|
4670
|
+
"TERM",
|
|
4671
|
+
"LANG",
|
|
4672
|
+
"LC_ALL",
|
|
4673
|
+
"LC_CTYPE",
|
|
4674
|
+
"TMPDIR",
|
|
4675
|
+
"TMP",
|
|
4676
|
+
"TEMP",
|
|
4677
|
+
"XDG_RUNTIME_DIR",
|
|
4678
|
+
"COLORTERM",
|
|
4679
|
+
"TERM_PROGRAM"
|
|
4680
|
+
]);
|
|
4681
|
+
function isCredentialShaped(key) {
|
|
4682
|
+
if (PRESERVE_KEYS.has(key)) return false;
|
|
4683
|
+
if (STRIP_PREFIX_PATTERNS.some((re) => re.test(key))) return true;
|
|
4684
|
+
if (STRIP_CREDENTIAL_SUBSTRINGS.some((re) => re.test(key))) return true;
|
|
4685
|
+
return false;
|
|
4686
|
+
}
|
|
4687
|
+
var FORWARD_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
4688
|
+
var DSH_PERMISSION_MODES = [
|
|
4689
|
+
"read-only",
|
|
4690
|
+
"workspace-write",
|
|
4691
|
+
"danger-full-access"
|
|
4692
|
+
];
|
|
4693
|
+
var DSH_PERMISSION_ENV = "DSH_PERMISSION_MODE";
|
|
4694
|
+
function cleanupTempDir(dir) {
|
|
4695
|
+
fs13.rmSync(dir, { recursive: true, force: true });
|
|
4696
|
+
}
|
|
4697
|
+
function signalExitCode(signal) {
|
|
4698
|
+
if (!signal) return 1;
|
|
4699
|
+
const known = os7.constants.signals[signal];
|
|
4700
|
+
const number = typeof known === "number" ? known : known?.number;
|
|
4701
|
+
return number === void 0 ? 1 : 128 + number;
|
|
4702
|
+
}
|
|
4703
|
+
function buildDshArgv(options) {
|
|
4704
|
+
return [
|
|
4705
|
+
...options.invocation.prefix,
|
|
4706
|
+
"--profile",
|
|
4707
|
+
options.profile ?? DSH_PROFILE,
|
|
4708
|
+
"--patch",
|
|
4709
|
+
options.patchPath,
|
|
4710
|
+
options.task
|
|
4711
|
+
];
|
|
4712
|
+
}
|
|
4713
|
+
function buildChildEnv(parent, token, options = {}) {
|
|
4714
|
+
const env = {};
|
|
4715
|
+
for (const [key, value] of Object.entries(parent)) {
|
|
4716
|
+
if (value === void 0) continue;
|
|
4717
|
+
if (isCredentialShaped(key)) continue;
|
|
4718
|
+
env[key] = value;
|
|
4719
|
+
}
|
|
4720
|
+
if (options.inheritedDshHome) {
|
|
4721
|
+
env.DSH_HOME = options.inheritedDshHome;
|
|
4722
|
+
}
|
|
4723
|
+
env[DSH_API_KEY_ENV] = token;
|
|
4724
|
+
env[DSH_PERMISSION_ENV] = options.permission ?? "workspace-write";
|
|
4725
|
+
return env;
|
|
4726
|
+
}
|
|
4727
|
+
async function runPreflightGate(options = {}) {
|
|
4728
|
+
const env = options.env ?? process.env;
|
|
4729
|
+
const platform = options.platform ?? process.platform;
|
|
4730
|
+
const invocation = resolveDshInvocation({ env, platform });
|
|
4731
|
+
if (!invocation) {
|
|
4732
|
+
throw new DshProjectionError(
|
|
4733
|
+
"DSH_BINARY_MISSING",
|
|
4734
|
+
"dsh binary not found on PATH. Install it with: npm install -g @deepseek-ai/dsh@0.1.1-rc.2"
|
|
4735
|
+
);
|
|
4736
|
+
}
|
|
4737
|
+
const dshVersion = await probeBinVersion(invocation, { env });
|
|
4738
|
+
if (dshVersion === null) {
|
|
4739
|
+
throw new DshProjectionError(
|
|
4740
|
+
"DSH_VERSION_UNREADABLE",
|
|
4741
|
+
`Could not determine dsh version from '${invocation.bin}'. Ensure dsh --version works.`
|
|
4742
|
+
);
|
|
4743
|
+
}
|
|
4744
|
+
if (!isDshVersionCompatible(dshVersion)) {
|
|
4745
|
+
throw new DshProjectionError(
|
|
4746
|
+
"DSH_VERSION_UNSUPPORTED",
|
|
4747
|
+
`dsh ${dshVersion} is not the verified contract version. ccem dsh requires exactly dsh ${DSH_REQUIRED_VERSION}. Install: npm install -g @deepseek-ai/dsh@${DSH_REQUIRED_VERSION}`
|
|
4748
|
+
);
|
|
4749
|
+
}
|
|
4750
|
+
const nodeBin = platform === "win32" && invocation.prefix.length > 0 ? invocation.bin : resolveBinOnPath("node", env, platform) ?? "node";
|
|
4751
|
+
const nodeVersion = await probeSimpleBinVersion(nodeBin, { env });
|
|
4752
|
+
if (nodeVersion === null) {
|
|
4753
|
+
throw new DshProjectionError(
|
|
4754
|
+
"NODE_VERSION_UNREADABLE",
|
|
4755
|
+
`Could not determine node version. dsh requires Node >= ${DSH_NODE_MIN_VERSION}.`
|
|
4756
|
+
);
|
|
4757
|
+
}
|
|
4758
|
+
if (!isNodeVersionCompatible(nodeVersion)) {
|
|
4759
|
+
throw new DshProjectionError(
|
|
4760
|
+
"NODE_VERSION_UNSUPPORTED",
|
|
4761
|
+
`Node ${nodeVersion} < ${DSH_NODE_MIN_VERSION}. dsh's LLM stack requires Node >= ${DSH_NODE_MIN_VERSION}; switch the PATH-visible node (e.g. via nvm).`
|
|
4762
|
+
);
|
|
4763
|
+
}
|
|
4764
|
+
return { invocation, dshVersion, nodeVersion };
|
|
4765
|
+
}
|
|
4766
|
+
async function runDshTask(options) {
|
|
4767
|
+
const task = options.task.trim();
|
|
4768
|
+
if (!task) {
|
|
4769
|
+
throw new DshProjectionError("EMPTY_TASK", "A non-empty task is required");
|
|
4770
|
+
}
|
|
4771
|
+
if (task.startsWith("-")) {
|
|
4772
|
+
throw new DshProjectionError(
|
|
4773
|
+
"LEADING_DASH_TASK",
|
|
4774
|
+
'The task must not start with "-" \u2014 dsh would parse it as a launcher flag; rephrase the task'
|
|
4775
|
+
);
|
|
4776
|
+
}
|
|
4777
|
+
if (options.permission !== void 0 && !DSH_PERMISSION_MODES.includes(options.permission)) {
|
|
4778
|
+
throw new DshProjectionError(
|
|
4779
|
+
"INVALID_PERMISSION",
|
|
4780
|
+
`Invalid permission mode '${options.permission}'; expected one of: ${DSH_PERMISSION_MODES.join(", ")}`
|
|
4781
|
+
);
|
|
4782
|
+
}
|
|
4783
|
+
const token = options.token;
|
|
4784
|
+
if (!token) {
|
|
4785
|
+
throw new DshProjectionError("MISSING_TOKEN", "No auth token available for the dsh child");
|
|
4786
|
+
}
|
|
4787
|
+
const env = options.env ?? process.env;
|
|
4788
|
+
const platform = options.platform ?? process.platform;
|
|
4789
|
+
const invocation = options.invocation ?? resolveDshInvocation({ env, platform });
|
|
4790
|
+
if (!invocation) {
|
|
4791
|
+
return {
|
|
4792
|
+
exitCode: 1,
|
|
4793
|
+
signal: null,
|
|
4794
|
+
spawnError: "dsh binary not found on PATH. Install: npm install -g @deepseek-ai/dsh@0.1.1-rc.2",
|
|
4795
|
+
tempDir: ""
|
|
4796
|
+
};
|
|
4797
|
+
}
|
|
4798
|
+
const inheritedDshHome = env.DSH_HOME?.trim() || void 0;
|
|
4799
|
+
const tempDir = fs13.mkdtempSync(path11.join(os7.tmpdir(), "ccem-dsh-"));
|
|
4800
|
+
const patchPath = path11.join(tempDir, "cordis.ccem.patch.yml");
|
|
4801
|
+
const patchContent = renderCordisPatch(options.spec);
|
|
4802
|
+
fs13.writeFileSync(patchPath, patchContent, { mode: 384 });
|
|
4803
|
+
let exitCode = null;
|
|
4804
|
+
let signal = null;
|
|
4805
|
+
let spawnError = null;
|
|
4806
|
+
try {
|
|
4807
|
+
await new Promise((resolve5) => {
|
|
4808
|
+
let settled = false;
|
|
4809
|
+
const finishOnce = () => {
|
|
4810
|
+
if (settled) return;
|
|
4811
|
+
settled = true;
|
|
4812
|
+
for (const [sig, handler] of handlers) {
|
|
4813
|
+
process.removeListener(sig, handler);
|
|
4814
|
+
}
|
|
4815
|
+
resolve5();
|
|
4816
|
+
};
|
|
4817
|
+
const argv = buildDshArgv({
|
|
4818
|
+
invocation,
|
|
4819
|
+
profile: options.profile,
|
|
4820
|
+
patchPath,
|
|
4821
|
+
task
|
|
4822
|
+
});
|
|
4823
|
+
const doSpawn = options.spawnImpl ?? defaultSpawn;
|
|
4824
|
+
let child;
|
|
4825
|
+
try {
|
|
4826
|
+
child = doSpawn(invocation.bin, argv, {
|
|
4827
|
+
shell: false,
|
|
4828
|
+
stdio: options.stdio ?? "inherit",
|
|
4829
|
+
env: buildChildEnv(env, token, {
|
|
4830
|
+
inheritedDshHome,
|
|
4831
|
+
permission: options.permission
|
|
4832
|
+
}),
|
|
4833
|
+
cwd: options.cwd
|
|
4834
|
+
});
|
|
4835
|
+
} catch (err) {
|
|
4836
|
+
const msg2 = err instanceof Error ? err.message : String(err);
|
|
4837
|
+
spawnError = `Failed to launch dsh: ${msg2.replaceAll(token, "<redacted>")}`;
|
|
4838
|
+
resolve5();
|
|
4839
|
+
return;
|
|
4840
|
+
}
|
|
4841
|
+
const forward = (received) => {
|
|
4842
|
+
if (child.exitCode === null && child.signalCode === null && !child.killed) {
|
|
4843
|
+
child.kill(received);
|
|
4844
|
+
}
|
|
4845
|
+
};
|
|
4846
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
4847
|
+
for (const sig of FORWARD_SIGNALS) {
|
|
4848
|
+
const handler = () => forward(sig);
|
|
4849
|
+
handlers.set(sig, handler);
|
|
4850
|
+
process.on(sig, handler);
|
|
4851
|
+
}
|
|
4852
|
+
child.on("error", (err) => {
|
|
4853
|
+
if (err.code === "ENOENT") {
|
|
4854
|
+
spawnError = `dsh binary not found at '${invocation.bin.replaceAll(token, "<redacted>")}'. Install: npm install -g @deepseek-ai/dsh@0.1.1-rc.2`;
|
|
4855
|
+
} else {
|
|
4856
|
+
const msg2 = err.message.replaceAll(token, "<redacted>");
|
|
4857
|
+
spawnError = `Failed to launch dsh: ${msg2}`;
|
|
4858
|
+
}
|
|
4859
|
+
});
|
|
4860
|
+
child.once("close", (code, sig) => {
|
|
4861
|
+
exitCode = code;
|
|
4862
|
+
signal = sig;
|
|
4863
|
+
finishOnce();
|
|
4864
|
+
});
|
|
4865
|
+
options.onSpawned?.(child);
|
|
4866
|
+
});
|
|
4867
|
+
} finally {
|
|
4868
|
+
try {
|
|
4869
|
+
(options.cleanupImpl ?? cleanupTempDir)(tempDir);
|
|
4870
|
+
} catch {
|
|
4871
|
+
}
|
|
4872
|
+
}
|
|
4873
|
+
return {
|
|
4874
|
+
exitCode: exitCode !== null && exitCode >= 0 ? exitCode : signalExitCode(signal),
|
|
4875
|
+
signal,
|
|
4876
|
+
spawnError: spawnError ?? (exitCode !== null && exitCode < 0 ? "dsh exited abnormally" : null),
|
|
4877
|
+
tempDir
|
|
4878
|
+
};
|
|
4879
|
+
}
|
|
4880
|
+
|
|
4881
|
+
// src/dsh/doctor.ts
|
|
4882
|
+
async function collectDshDoctorReport(input, deps = {}) {
|
|
4883
|
+
const env = deps.env ?? process.env;
|
|
4884
|
+
const platform = deps.platform ?? process.platform;
|
|
4885
|
+
const checks = [];
|
|
4886
|
+
const invocation = resolveDshInvocation({ env, platform });
|
|
4887
|
+
checks.push({
|
|
4888
|
+
id: "dsh-binary",
|
|
4889
|
+
label: "dsh binary",
|
|
4890
|
+
status: invocation ? "pass" : "fail",
|
|
4891
|
+
detail: invocation ? invocation.bin : "dsh not found on PATH",
|
|
4892
|
+
remediation: invocation ? void 0 : `Install dsh: npm install -g @deepseek-ai/dsh@${DSH_REQUIRED_VERSION}`
|
|
4893
|
+
});
|
|
4894
|
+
let dshVersion = null;
|
|
4895
|
+
if (invocation) {
|
|
4896
|
+
dshVersion = await probeBinVersion(invocation, deps);
|
|
4897
|
+
if (dshVersion === null) {
|
|
4898
|
+
checks.push({
|
|
4899
|
+
id: "dsh-version",
|
|
4900
|
+
label: "dsh version",
|
|
4901
|
+
status: "fail",
|
|
4902
|
+
detail: `could not read version (requires exactly ${DSH_REQUIRED_VERSION})`,
|
|
4903
|
+
remediation: "Run dsh --version and check the installation"
|
|
4904
|
+
});
|
|
4905
|
+
} else if (isDshVersionCompatible(dshVersion)) {
|
|
4906
|
+
checks.push({
|
|
4907
|
+
id: "dsh-version",
|
|
4908
|
+
label: "dsh version",
|
|
4909
|
+
status: "pass",
|
|
4910
|
+
detail: `${dshVersion} (== ${DSH_REQUIRED_VERSION})`
|
|
4911
|
+
});
|
|
4912
|
+
} else {
|
|
4913
|
+
checks.push({
|
|
4914
|
+
id: "dsh-version",
|
|
4915
|
+
label: "dsh version",
|
|
4916
|
+
status: "fail",
|
|
4917
|
+
detail: `${dshVersion} is not the verified contract version (requires exactly ${DSH_REQUIRED_VERSION})`,
|
|
4918
|
+
remediation: `Install the verified version: npm install -g @deepseek-ai/dsh@${DSH_REQUIRED_VERSION}`
|
|
4919
|
+
});
|
|
4920
|
+
}
|
|
4921
|
+
}
|
|
4922
|
+
const nodeBin = platform === "win32" && invocation && invocation.prefix.length > 0 ? invocation.bin : resolveBinOnPath("node", env, platform);
|
|
4923
|
+
let nodeVersion = null;
|
|
4924
|
+
if (nodeBin) {
|
|
4925
|
+
nodeVersion = await probeSimpleBinVersion(nodeBin, deps);
|
|
4926
|
+
}
|
|
4927
|
+
if (nodeVersion !== null && isNodeVersionCompatible(nodeVersion)) {
|
|
4928
|
+
checks.push({
|
|
4929
|
+
id: "node-version",
|
|
4930
|
+
label: "node version (runs dsh)",
|
|
4931
|
+
status: "pass",
|
|
4932
|
+
detail: `${nodeVersion} (>= ${DSH_NODE_MIN_VERSION}, required by dsh's pi-ai dependency)`
|
|
4933
|
+
});
|
|
4934
|
+
} else if (nodeVersion !== null) {
|
|
4935
|
+
checks.push({
|
|
4936
|
+
id: "node-version",
|
|
4937
|
+
label: "node version (runs dsh)",
|
|
4938
|
+
status: "fail",
|
|
4939
|
+
detail: `${nodeVersion} < ${DSH_NODE_MIN_VERSION}`,
|
|
4940
|
+
remediation: `dsh's LLM stack requires Node >= ${DSH_NODE_MIN_VERSION}; switch the PATH-visible node (e.g. via nvm)`
|
|
4941
|
+
});
|
|
4942
|
+
} else {
|
|
4943
|
+
checks.push({
|
|
4944
|
+
id: "node-version",
|
|
4945
|
+
label: "node version (runs dsh)",
|
|
4946
|
+
status: "fail",
|
|
4947
|
+
detail: "could not resolve the node that will run dsh",
|
|
4948
|
+
remediation: `Ensure node >= ${DSH_NODE_MIN_VERSION} is on PATH`
|
|
4949
|
+
});
|
|
4950
|
+
}
|
|
4951
|
+
const dshRoot = resolveDshRoot(env);
|
|
4952
|
+
checks.push({
|
|
4953
|
+
id: "dsh-root",
|
|
4954
|
+
label: "active dsh root",
|
|
4955
|
+
status: "pass",
|
|
4956
|
+
detail: `${dshRoot} (sessions persist here; ccem dsh run disables the settings row via --patch, so root settings.yaml cannot override the projected provider)`
|
|
4957
|
+
});
|
|
4958
|
+
let spec = null;
|
|
4959
|
+
let environmentError = null;
|
|
4960
|
+
if (!input.envConfig) {
|
|
4961
|
+
environmentError = `Environment '${input.envName}' not found in CCEM configuration`;
|
|
4962
|
+
} else {
|
|
4963
|
+
try {
|
|
4964
|
+
spec = deriveDshProvider(input.envName, input.envConfig, input.deriveOptions);
|
|
4965
|
+
} catch (error) {
|
|
4966
|
+
environmentError = error instanceof Error ? error.message : String(error);
|
|
4967
|
+
}
|
|
4968
|
+
}
|
|
4969
|
+
checks.push({
|
|
4970
|
+
id: "environment",
|
|
4971
|
+
label: `environment '${input.envName}'`,
|
|
4972
|
+
status: spec ? "pass" : "fail",
|
|
4973
|
+
detail: spec ? `${spec.baseURL} \xB7 model ${spec.selectedModel} \xB7 credential ${spec.credentialState} (value redacted)` : environmentError ?? "environment projection failed",
|
|
4974
|
+
remediation: spec ? void 0 : "Fix the environment with ccem add / ccem env, or select another with --env"
|
|
4975
|
+
});
|
|
4976
|
+
const ok = checks.filter((check) => check.id !== "dsh-root").every((check) => check.status !== "fail");
|
|
4977
|
+
return {
|
|
4978
|
+
ok,
|
|
4979
|
+
checks,
|
|
4980
|
+
dshVersion,
|
|
4981
|
+
nodeVersion,
|
|
4982
|
+
dshRoot,
|
|
4983
|
+
environment: { name: input.envName, spec, error: environmentError }
|
|
4984
|
+
};
|
|
4985
|
+
}
|
|
4986
|
+
function buildDshInspectReport(input, meta) {
|
|
4987
|
+
let spec = null;
|
|
4988
|
+
let error = null;
|
|
4989
|
+
if (!input.envConfig) {
|
|
4990
|
+
error = `Environment '${input.envName}' not found in CCEM configuration`;
|
|
4991
|
+
} else {
|
|
4992
|
+
try {
|
|
4993
|
+
spec = deriveDshProvider(input.envName, input.envConfig, input.deriveOptions);
|
|
4994
|
+
} catch (err) {
|
|
4995
|
+
error = err instanceof Error ? err.message : String(err);
|
|
4996
|
+
}
|
|
4997
|
+
}
|
|
4998
|
+
return {
|
|
4999
|
+
environment: {
|
|
5000
|
+
name: input.envName,
|
|
5001
|
+
baseURL: spec?.baseURL ?? input.envConfig?.ANTHROPIC_BASE_URL?.trim() ?? null,
|
|
5002
|
+
models: spec?.models ?? [],
|
|
5003
|
+
selectedModel: spec?.selectedModel ?? null,
|
|
5004
|
+
credentialState: spec?.credentialState ?? null,
|
|
5005
|
+
error
|
|
5006
|
+
},
|
|
5007
|
+
dsh: {
|
|
5008
|
+
root: meta.dshRoot,
|
|
5009
|
+
version: meta.dshVersion,
|
|
5010
|
+
versionCompatible: meta.dshVersion === null ? null : isDshVersionCompatible(meta.dshVersion)
|
|
5011
|
+
},
|
|
5012
|
+
node: {
|
|
5013
|
+
version: meta.nodeVersion,
|
|
5014
|
+
versionCompatible: meta.nodeVersion === null ? null : isNodeVersionCompatible(meta.nodeVersion)
|
|
5015
|
+
},
|
|
5016
|
+
patchPreview: spec ? renderCordisPatch(spec) : null
|
|
5017
|
+
};
|
|
5018
|
+
}
|
|
5019
|
+
|
|
5020
|
+
// src/dsh/cli.ts
|
|
5021
|
+
var STATUS_MARKS = {
|
|
5022
|
+
pass: chalk7.green("\u2713"),
|
|
5023
|
+
fail: chalk7.red("\u2717"),
|
|
5024
|
+
warn: chalk7.yellow("\u26A0")
|
|
5025
|
+
};
|
|
5026
|
+
function resolveEnvironment(context, envFlag) {
|
|
5027
|
+
const envName = envFlag?.trim() || context.getCurrentEnvName();
|
|
5028
|
+
return { envName, envConfig: context.getRegistries()[envName] };
|
|
5029
|
+
}
|
|
5030
|
+
function failWith(error, exit = (c) => process.exit(c)) {
|
|
5031
|
+
const message = error instanceof DshProjectionError || error instanceof Error ? error.message : String(error);
|
|
5032
|
+
console.error(chalk7.red(`\u2717 ${message}`));
|
|
5033
|
+
exit(1);
|
|
5034
|
+
}
|
|
5035
|
+
function formatVersionLine(version, compatible) {
|
|
5036
|
+
if (version === null) return "not found";
|
|
5037
|
+
const suffix = compatible === false ? chalk7.red(" (incompatible)") : "";
|
|
5038
|
+
return `${version}${suffix}`;
|
|
5039
|
+
}
|
|
5040
|
+
function parseDeriveOptions(options) {
|
|
5041
|
+
return {
|
|
5042
|
+
tier: options.tier,
|
|
5043
|
+
model: options.model
|
|
5044
|
+
};
|
|
5045
|
+
}
|
|
5046
|
+
function decryptToken(envName, envConfig) {
|
|
5047
|
+
const raw = envConfig.ANTHROPIC_AUTH_TOKEN?.trim();
|
|
5048
|
+
if (!raw) {
|
|
5049
|
+
throw new DshProjectionError(
|
|
5050
|
+
"MISSING_TOKEN",
|
|
5051
|
+
`Environment '${envName}' has no auth token; ccem dsh needs a token-based environment`
|
|
5052
|
+
);
|
|
5053
|
+
}
|
|
5054
|
+
const token = decrypt(raw).trim();
|
|
5055
|
+
if (!token) {
|
|
5056
|
+
throw new DshProjectionError(
|
|
5057
|
+
"MISSING_TOKEN",
|
|
5058
|
+
`Environment '${envName}' auth token decrypted to empty; check the encryption key`
|
|
5059
|
+
);
|
|
5060
|
+
}
|
|
5061
|
+
return token;
|
|
5062
|
+
}
|
|
5063
|
+
function registerDshCommands(program2, context, deps) {
|
|
5064
|
+
const doPreflightGate = deps?.runPreflightGate ?? runPreflightGate;
|
|
5065
|
+
const doDecryptToken = deps?.decryptToken ?? decryptToken;
|
|
5066
|
+
const doRunDshTask = deps?.runDshTask ?? runDshTask;
|
|
5067
|
+
const doProcessExit = deps?.processExit ?? ((code) => process.exit(code));
|
|
5068
|
+
const doOnActionError = deps?.onActionError;
|
|
5069
|
+
const dshCmd = program2.command("dsh").description("Project a CCEM environment onto DeepSeek Harness (dsh)");
|
|
5070
|
+
dshCmd.command("run <task...>").description("Run one task through dsh headless with the projected environment").option("--env <name>", "CCEM environment to project (default: current)").option("--tier <tier>", `Tier model to select: ${DSH_TIERS.join(" | ")}`).option("--model <id>", "Explicit model id (any non-empty value; added to route if new)").option("--permission <mode>", `dsh permission: ${DSH_PERMISSION_MODES.join(" | ")} (default: workspace-write). headless has no approval responder.`, "workspace-write").option("--cwd <dir>", "Working directory for the dsh process").addHelpText("after", `
|
|
5071
|
+
Examples:
|
|
5072
|
+
ccem dsh run "summarize this repo"
|
|
5073
|
+
ccem dsh run --env partner --tier opus "refactor auth"
|
|
5074
|
+
ccem dsh run --model custom-model-id "do something"
|
|
5075
|
+
ccem dsh run --permission read-only "audit the code"
|
|
5076
|
+
ccem dsh run -- "task text that starts with a dash after --"
|
|
5077
|
+
|
|
5078
|
+
Note: Use -- to separate task text from options if the task could be
|
|
5079
|
+
parsed as flags. headless profile has no interactive approval
|
|
5080
|
+
responder, so --permission controls what the agent can do.`).action(async (taskWords, options) => {
|
|
5081
|
+
const { envName, envConfig } = resolveEnvironment(context, options.env);
|
|
5082
|
+
if (!envConfig) failWith(new Error(`Environment '${envName}' not found in CCEM configuration`));
|
|
5083
|
+
try {
|
|
5084
|
+
const permission = options.permission ?? "workspace-write";
|
|
5085
|
+
if (!DSH_PERMISSION_MODES.includes(permission)) {
|
|
5086
|
+
throw new DshProjectionError(
|
|
5087
|
+
"INVALID_PERMISSION",
|
|
5088
|
+
`Unknown permission mode '${permission}'; expected one of ${DSH_PERMISSION_MODES.join(", ")}`
|
|
5089
|
+
);
|
|
5090
|
+
}
|
|
5091
|
+
const spec = deriveDshProvider(envName, envConfig, parseDeriveOptions(options));
|
|
5092
|
+
const gate = await doPreflightGate();
|
|
5093
|
+
const token = doDecryptToken(envName, envConfig);
|
|
5094
|
+
const result = await doRunDshTask({
|
|
5095
|
+
task: taskWords.join(" ").trim(),
|
|
5096
|
+
spec,
|
|
5097
|
+
token,
|
|
5098
|
+
invocation: gate.invocation,
|
|
5099
|
+
permission,
|
|
5100
|
+
cwd: options.cwd
|
|
5101
|
+
});
|
|
5102
|
+
if (result.spawnError) {
|
|
5103
|
+
console.error(chalk7.red(`\u2717 ${result.spawnError}`));
|
|
5104
|
+
}
|
|
5105
|
+
doProcessExit(result.exitCode);
|
|
5106
|
+
} catch (error) {
|
|
5107
|
+
doOnActionError?.(error);
|
|
5108
|
+
failWith(error, doProcessExit);
|
|
5109
|
+
}
|
|
5110
|
+
});
|
|
5111
|
+
dshCmd.command("inspect").description("Show the projected dsh provider for an environment (secrets redacted)").option("--env <name>", "CCEM environment to inspect (default: current)").option("--tier <tier>", `Tier model to select: ${DSH_TIERS.join(" | ")}`).option("--model <id>", "Explicit model id to preview").option("--json", "Output as JSON").action(async (options) => {
|
|
5112
|
+
const { envName, envConfig } = resolveEnvironment(context, options.env);
|
|
5113
|
+
const invocation = resolveDshInvocation();
|
|
5114
|
+
const nodeBin = resolveBinOnPath("node") ?? "node";
|
|
5115
|
+
const [dshVersion, nodeVersion] = await Promise.all([
|
|
5116
|
+
invocation ? probeBinVersion(invocation) : Promise.resolve(null),
|
|
5117
|
+
probeSimpleBinVersion(nodeBin)
|
|
5118
|
+
]);
|
|
5119
|
+
const report = buildDshInspectReport(
|
|
5120
|
+
{ envName, envConfig, deriveOptions: parseDeriveOptions(options) },
|
|
5121
|
+
{ dshRoot: resolveDshRoot(), dshVersion, nodeVersion }
|
|
5122
|
+
);
|
|
5123
|
+
if (options.json) {
|
|
5124
|
+
console.log(JSON.stringify(report, null, 2));
|
|
5125
|
+
} else {
|
|
5126
|
+
const env = report.environment;
|
|
5127
|
+
if (env.error) {
|
|
5128
|
+
console.error(chalk7.red(`\u2717 ${env.error}`));
|
|
5129
|
+
} else {
|
|
5130
|
+
console.log(chalk7.bold(`Environment ${chalk7.cyan(env.name)} \u2192 dsh provider`));
|
|
5131
|
+
console.log(` endpoint: ${env.baseURL}`);
|
|
5132
|
+
console.log(` models: ${env.models.join(", ")}`);
|
|
5133
|
+
console.log(` selected model: ${chalk7.cyan(env.selectedModel ?? "-")}`);
|
|
5134
|
+
console.log(` credential: ${env.credentialState} (value redacted)`);
|
|
5135
|
+
}
|
|
5136
|
+
console.log(` dsh root: ${report.dsh.root}`);
|
|
5137
|
+
console.log(` dsh version: ${formatVersionLine(report.dsh.version, report.dsh.versionCompatible)}`);
|
|
5138
|
+
console.log(` node version: ${formatVersionLine(report.node.version, report.node.versionCompatible)}`);
|
|
5139
|
+
if (report.patchPreview) {
|
|
5140
|
+
console.log(chalk7.gray(" --- patch preview (secret-free) ---"));
|
|
5141
|
+
for (const line of report.patchPreview.trimEnd().split("\n")) {
|
|
5142
|
+
console.log(chalk7.gray(` ${line}`));
|
|
5143
|
+
}
|
|
5144
|
+
}
|
|
5145
|
+
}
|
|
5146
|
+
process.exit(report.environment.error ? 1 : 0);
|
|
5147
|
+
});
|
|
5148
|
+
dshCmd.command("doctor").description("Check dsh binary, versions, and config readiness (no model request, no token decryption)").option("--env <name>", "CCEM environment to check (default: current)").option("--tier <tier>", `Tier model to select: ${DSH_TIERS.join(" | ")}`).option("--model <id>", "Explicit model id to check").option("--json", "Output as JSON").action(async (options) => {
|
|
5149
|
+
const { envName, envConfig } = resolveEnvironment(context, options.env);
|
|
5150
|
+
const report = await collectDshDoctorReport({
|
|
5151
|
+
envName,
|
|
5152
|
+
envConfig,
|
|
5153
|
+
deriveOptions: parseDeriveOptions(options)
|
|
5154
|
+
});
|
|
5155
|
+
if (options.json) {
|
|
5156
|
+
console.log(JSON.stringify(report, null, 2));
|
|
5157
|
+
} else {
|
|
5158
|
+
for (const check of report.checks) {
|
|
5159
|
+
console.log(`${STATUS_MARKS[check.status]} ${chalk7.bold(check.label)}: ${check.detail}`);
|
|
5160
|
+
if (check.remediation && check.status !== "pass") {
|
|
5161
|
+
console.log(chalk7.gray(` \u2192 ${check.remediation}`));
|
|
5162
|
+
}
|
|
5163
|
+
}
|
|
5164
|
+
}
|
|
5165
|
+
process.exit(report.ok ? 0 : 1);
|
|
5166
|
+
});
|
|
5167
|
+
}
|
|
5168
|
+
|
|
4236
5169
|
// src/index.ts
|
|
4237
5170
|
var __filename2 = fileURLToPath2(import.meta.url);
|
|
4238
|
-
var __dirname2 =
|
|
4239
|
-
var pkgPath =
|
|
4240
|
-
var pkg = JSON.parse(
|
|
5171
|
+
var __dirname2 = path12.dirname(__filename2);
|
|
5172
|
+
var pkgPath = path12.resolve(__dirname2, "..", "package.json");
|
|
5173
|
+
var pkg = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
|
|
4241
5174
|
var program = new Command();
|
|
4242
5175
|
var DEFAULT_OFFICIAL_ENV = {
|
|
4243
5176
|
ANTHROPIC_BASE_URL: "https://api.anthropic.com",
|
|
@@ -4332,11 +5265,11 @@ var recoverRegistriesFromLegacy = (registries) => {
|
|
|
4332
5265
|
return registries;
|
|
4333
5266
|
}
|
|
4334
5267
|
const legacyConfigPath = getLegacyConfigPath();
|
|
4335
|
-
if (!
|
|
5268
|
+
if (!fs14.existsSync(legacyConfigPath)) {
|
|
4336
5269
|
return registries;
|
|
4337
5270
|
}
|
|
4338
5271
|
try {
|
|
4339
|
-
const legacyRaw = JSON.parse(
|
|
5272
|
+
const legacyRaw = JSON.parse(fs14.readFileSync(legacyConfigPath, "utf-8"));
|
|
4340
5273
|
const legacyRegistries = legacyRaw.registries ?? {};
|
|
4341
5274
|
let changed = false;
|
|
4342
5275
|
const recovered = { ...registries };
|
|
@@ -4518,36 +5451,36 @@ var showCurrentEnv = (usageStats2, usageLoading2) => {
|
|
|
4518
5451
|
var switchEnvironment = async (name) => {
|
|
4519
5452
|
const registries = getRegistries();
|
|
4520
5453
|
if (!registries[name]) {
|
|
4521
|
-
console.error(
|
|
5454
|
+
console.error(chalk8.red(`Environment '${name}' not found.`));
|
|
4522
5455
|
return;
|
|
4523
5456
|
}
|
|
4524
5457
|
config2.set("current", name);
|
|
4525
5458
|
if (process.stdout.isTTY) {
|
|
4526
|
-
console.log(
|
|
5459
|
+
console.log(chalk8.green(`Switched to environment '${name}'`));
|
|
4527
5460
|
} else {
|
|
4528
|
-
console.error(
|
|
5461
|
+
console.error(chalk8.green(`Switched to environment '${name}'`));
|
|
4529
5462
|
}
|
|
4530
5463
|
showCurrentEnv(null, false);
|
|
4531
5464
|
const env = registries[name];
|
|
4532
5465
|
const exportCmds = buildShellEnvCommands(name, env);
|
|
4533
5466
|
if (process.stdout.isTTY) {
|
|
4534
|
-
console.log(
|
|
4535
|
-
console.log(
|
|
4536
|
-
console.log(
|
|
5467
|
+
console.log(chalk8.yellow("\nTo apply to current shell immediately, run:"));
|
|
5468
|
+
console.log(chalk8.cyan("eval $(ccem env)"));
|
|
5469
|
+
console.log(chalk8.yellow("\nOr manually export:"));
|
|
4537
5470
|
exportCmds.forEach((cmd) => console.log(cmd));
|
|
4538
5471
|
} else {
|
|
4539
5472
|
exportCmds.forEach((cmd) => console.log(cmd));
|
|
4540
5473
|
}
|
|
4541
5474
|
};
|
|
4542
|
-
var getSessionsFilePath = () =>
|
|
4543
|
-
var getRuntimeStateFilePath = () =>
|
|
4544
|
-
var getBotBindRequestFilePath = () =>
|
|
5475
|
+
var getSessionsFilePath = () => path12.join(getCcemConfigDir(), "sessions.json");
|
|
5476
|
+
var getRuntimeStateFilePath = () => path12.join(getCcemConfigDir(), "runtime-state.json");
|
|
5477
|
+
var getBotBindRequestFilePath = () => path12.join(getCcemConfigDir(), "bot-bind-requests.jsonl");
|
|
4545
5478
|
var parseJsonFile = (filePath) => {
|
|
4546
|
-
if (!
|
|
5479
|
+
if (!fs14.existsSync(filePath)) {
|
|
4547
5480
|
return null;
|
|
4548
5481
|
}
|
|
4549
5482
|
try {
|
|
4550
|
-
return JSON.parse(
|
|
5483
|
+
return JSON.parse(fs14.readFileSync(filePath, "utf-8"));
|
|
4551
5484
|
} catch {
|
|
4552
5485
|
return null;
|
|
4553
5486
|
}
|
|
@@ -4609,12 +5542,12 @@ var findAttachSession = (id) => {
|
|
|
4609
5542
|
};
|
|
4610
5543
|
var attachTmuxTarget = (target) => {
|
|
4611
5544
|
const args = process.env.TMUX ? ["switch-client", "-t", target] : ["attach-session", "-t", target];
|
|
4612
|
-
return new Promise((
|
|
5545
|
+
return new Promise((resolve5, reject) => {
|
|
4613
5546
|
const child = spawn3("tmux", args, { stdio: "inherit" });
|
|
4614
5547
|
child.on("error", reject);
|
|
4615
5548
|
child.on("exit", (code) => {
|
|
4616
5549
|
if (code === 0 || code === null) {
|
|
4617
|
-
|
|
5550
|
+
resolve5();
|
|
4618
5551
|
} else {
|
|
4619
5552
|
reject(new Error(`tmux exited with code ${code}`));
|
|
4620
5553
|
}
|
|
@@ -4639,8 +5572,8 @@ var resolveBotBindRuntimeId = (explicitRuntimeId) => {
|
|
|
4639
5572
|
};
|
|
4640
5573
|
var appendBotBindRequest = (payload) => {
|
|
4641
5574
|
const requestPath = getBotBindRequestFilePath();
|
|
4642
|
-
|
|
4643
|
-
|
|
5575
|
+
fs14.mkdirSync(path12.dirname(requestPath), { recursive: true });
|
|
5576
|
+
fs14.appendFileSync(requestPath, `${JSON.stringify(payload)}
|
|
4644
5577
|
`, "utf-8");
|
|
4645
5578
|
return requestPath;
|
|
4646
5579
|
};
|
|
@@ -4654,7 +5587,7 @@ program.command("ls").description("List all configured environments").action(()
|
|
|
4654
5587
|
Object.keys(registries).forEach((name) => {
|
|
4655
5588
|
const reg = registries[name];
|
|
4656
5589
|
const displayReg = resolveEnvConfigForRuntime(name, reg);
|
|
4657
|
-
const prefix = name === current ?
|
|
5590
|
+
const prefix = name === current ? chalk8.green("* ") : " ";
|
|
4658
5591
|
table.push([
|
|
4659
5592
|
prefix + name,
|
|
4660
5593
|
displayReg.ANTHROPIC_BASE_URL || "-",
|
|
@@ -4669,7 +5602,7 @@ program.command("use <name>").description("Switch to a specific environment").ac
|
|
|
4669
5602
|
program.command("sessions").description("List tmux-backed interactive sessions").action(() => {
|
|
4670
5603
|
const sessions = readInteractiveAttachSessions();
|
|
4671
5604
|
if (sessions.length === 0) {
|
|
4672
|
-
console.log(
|
|
5605
|
+
console.log(chalk8.yellow("No tmux-backed interactive sessions found."));
|
|
4673
5606
|
return;
|
|
4674
5607
|
}
|
|
4675
5608
|
const table = new Table3({
|
|
@@ -4690,39 +5623,39 @@ program.command("sessions").description("List tmux-backed interactive sessions")
|
|
|
4690
5623
|
program.command("attach [id]").description("Attach to a tmux-backed interactive session").action(async (id) => {
|
|
4691
5624
|
const session = findAttachSession(id);
|
|
4692
5625
|
if (!session) {
|
|
4693
|
-
console.error(
|
|
5626
|
+
console.error(chalk8.red(id ? `Interactive session '${id}' not found.` : "No interactive session available to attach."));
|
|
4694
5627
|
process.exit(1);
|
|
4695
5628
|
}
|
|
4696
5629
|
try {
|
|
4697
5630
|
await attachTmuxTarget(session.tmuxTarget);
|
|
4698
5631
|
} catch (error) {
|
|
4699
|
-
console.error(
|
|
5632
|
+
console.error(chalk8.red(`Failed to attach ${session.tmuxTarget}: ${String(error)}`));
|
|
4700
5633
|
process.exit(1);
|
|
4701
5634
|
}
|
|
4702
5635
|
});
|
|
4703
5636
|
program.command("bot-bind").description("Request binding the current ccem session to a chat bot target").requiredOption("--platform <platform>", "target platform: telegram, weixin, or wecom").option("--peer-id <peerId>", "target user/chat id").option("--peer <peerId>", "alias for --peer-id").option("--runtime-id <runtimeId>", "ccem runtime id; defaults to CCEM_RUNTIME_ID").option("--bot-id <botId>", "WeCom bot id or platform bot id").option("--thread-id <threadId>", "thread/topic id for platforms that support it").option("--title <title>", "task card title").option("--summary <summary>", "task card summary").option("--no-send-card", "bind without sending the initial task card").option("--json", "print the queued request as JSON").action((options) => {
|
|
4704
5637
|
const platform = normalizeBotBindPlatform(options.platform);
|
|
4705
5638
|
if (!platform) {
|
|
4706
|
-
console.error(
|
|
5639
|
+
console.error(chalk8.red("\u2717 --platform must be telegram, weixin, or wecom"));
|
|
4707
5640
|
process.exitCode = 1;
|
|
4708
5641
|
return;
|
|
4709
5642
|
}
|
|
4710
5643
|
const peerId = (options.peerId ?? options.peer ?? "").trim();
|
|
4711
5644
|
if (!peerId) {
|
|
4712
|
-
console.error(
|
|
5645
|
+
console.error(chalk8.red("\u2717 --peer-id is required"));
|
|
4713
5646
|
process.exitCode = 1;
|
|
4714
5647
|
return;
|
|
4715
5648
|
}
|
|
4716
5649
|
const runtimeId = resolveBotBindRuntimeId(options.runtimeId);
|
|
4717
5650
|
if (!runtimeId) {
|
|
4718
|
-
console.error(
|
|
4719
|
-
console.error(
|
|
5651
|
+
console.error(chalk8.red("\u2717 Unable to resolve ccem runtime id"));
|
|
5652
|
+
console.error(chalk8.gray(" Run from a ccem-launched session or pass --runtime-id explicitly."));
|
|
4720
5653
|
process.exitCode = 1;
|
|
4721
5654
|
return;
|
|
4722
5655
|
}
|
|
4723
5656
|
const botId = options.botId?.trim() || void 0;
|
|
4724
5657
|
if (platform === "wecom" && !botId) {
|
|
4725
|
-
console.error(
|
|
5658
|
+
console.error(chalk8.red("\u2717 --bot-id is required for WeCom bot bindings"));
|
|
4726
5659
|
process.exitCode = 1;
|
|
4727
5660
|
return;
|
|
4728
5661
|
}
|
|
@@ -4743,18 +5676,18 @@ program.command("bot-bind").description("Request binding the current ccem sessio
|
|
|
4743
5676
|
console.log(JSON.stringify({ requestPath, payload }, null, 2));
|
|
4744
5677
|
return;
|
|
4745
5678
|
}
|
|
4746
|
-
console.log(
|
|
4747
|
-
console.log(
|
|
4748
|
-
console.log(
|
|
4749
|
-
console.log(
|
|
4750
|
-
console.log(
|
|
5679
|
+
console.log(chalk8.green("\u2713 \u5DF2\u63D0\u4EA4 bot \u7ED1\u5B9A\u8BF7\u6C42"));
|
|
5680
|
+
console.log(chalk8.gray(` runtime: ${runtimeId}`));
|
|
5681
|
+
console.log(chalk8.gray(` target: ${platform}/${peerId}`));
|
|
5682
|
+
console.log(chalk8.gray(` queue: ${requestPath}`));
|
|
5683
|
+
console.log(chalk8.cyan(
|
|
4751
5684
|
options.sendCard === false ? " \u5982\u679C CCEM Desktop \u6B63\u5728\u8FD0\u884C\uFF0C\u4F1A\u81EA\u52A8\u6D88\u8D39\u8BE5\u8BF7\u6C42\u5E76\u5EFA\u7ACB\u7ED1\u5B9A\u3002" : " \u5982\u679C CCEM Desktop \u6B63\u5728\u8FD0\u884C\uFF0C\u4F1A\u81EA\u52A8\u6D88\u8D39\u8BE5\u8BF7\u6C42\u5E76\u53D1\u9001\u4EFB\u52A1\u5361\u7247\u5230\u7ED1\u5B9A\u76EE\u6807\u3002"
|
|
4752
5685
|
));
|
|
4753
5686
|
});
|
|
4754
5687
|
program.command("add <name>").description("Add a new environment configuration").action(async (name) => {
|
|
4755
5688
|
const registries = getRegistries();
|
|
4756
5689
|
if (registries[name]) {
|
|
4757
|
-
console.log(
|
|
5690
|
+
console.log(chalk8.red(`Environment '${name}' already exists.`));
|
|
4758
5691
|
return;
|
|
4759
5692
|
}
|
|
4760
5693
|
const { usePreset } = await inquirer.prompt([
|
|
@@ -4780,7 +5713,7 @@ program.command("add <name>").description("Add a new environment configuration")
|
|
|
4780
5713
|
const answers = await promptForEnvironmentConfig(presetConfig);
|
|
4781
5714
|
registries[name] = applyPromptAnswers(normalizeEnvConfig(presetConfig), answers, false);
|
|
4782
5715
|
setRegistries(registries);
|
|
4783
|
-
console.log(
|
|
5716
|
+
console.log(chalk8.green(`Environment '${name}' added successfully.`));
|
|
4784
5717
|
});
|
|
4785
5718
|
program.command("del <name>").description("Delete an environment configuration").action(async (name) => {
|
|
4786
5719
|
const wasCurrent = config2.get("current") === name;
|
|
@@ -4793,13 +5726,13 @@ program.command("del <name>").description("Delete an environment configuration")
|
|
|
4793
5726
|
setEnvironmentMutationConfig(outcome.config);
|
|
4794
5727
|
}
|
|
4795
5728
|
if (wasCurrent) {
|
|
4796
|
-
console.log(
|
|
5729
|
+
console.log(chalk8.yellow(`Deleted current environment. Switched back to 'official'.`));
|
|
4797
5730
|
}
|
|
4798
5731
|
} catch (error) {
|
|
4799
|
-
console.log(
|
|
5732
|
+
console.log(chalk8.red(error instanceof Error ? error.message : String(error)));
|
|
4800
5733
|
return;
|
|
4801
5734
|
}
|
|
4802
|
-
console.log(
|
|
5735
|
+
console.log(chalk8.green(`Environment '${name}' deleted.`));
|
|
4803
5736
|
});
|
|
4804
5737
|
program.command("rename <old> <new>").description("Rename an environment configuration").action(async (oldName, newName) => {
|
|
4805
5738
|
try {
|
|
@@ -4812,24 +5745,24 @@ program.command("rename <old> <new>").description("Rename an environment configu
|
|
|
4812
5745
|
setEnvironmentMutationConfig(outcome.config);
|
|
4813
5746
|
}
|
|
4814
5747
|
} catch (error) {
|
|
4815
|
-
console.log(
|
|
5748
|
+
console.log(chalk8.red(error instanceof Error ? error.message : String(error)));
|
|
4816
5749
|
return;
|
|
4817
5750
|
}
|
|
4818
|
-
console.log(
|
|
5751
|
+
console.log(chalk8.green(`Environment '${oldName}' renamed to '${newName}'.`));
|
|
4819
5752
|
});
|
|
4820
5753
|
program.command("cp <source> <target>").description("Copy an environment configuration").action(async (source, target) => {
|
|
4821
5754
|
const registries = getRegistries();
|
|
4822
5755
|
if (!registries[source]) {
|
|
4823
|
-
console.log(
|
|
5756
|
+
console.log(chalk8.red(`Environment '${source}' not found.`));
|
|
4824
5757
|
return;
|
|
4825
5758
|
}
|
|
4826
5759
|
if (registries[target]) {
|
|
4827
|
-
console.log(
|
|
5760
|
+
console.log(chalk8.red(`Environment '${target}' already exists.`));
|
|
4828
5761
|
return;
|
|
4829
5762
|
}
|
|
4830
5763
|
registries[target] = { ...registries[source] };
|
|
4831
5764
|
setRegistries(registries);
|
|
4832
|
-
console.log(
|
|
5765
|
+
console.log(chalk8.green(`Environment '${source}' copied to '${target}'.`));
|
|
4833
5766
|
const { modify } = await inquirer.prompt([
|
|
4834
5767
|
{
|
|
4835
5768
|
type: "confirm",
|
|
@@ -4843,12 +5776,12 @@ program.command("cp <source> <target>").description("Copy an environment configu
|
|
|
4843
5776
|
const answers = await promptForEnvironmentConfig(current, true);
|
|
4844
5777
|
registries[target] = applyPromptAnswers(current, answers, true);
|
|
4845
5778
|
setRegistries(registries);
|
|
4846
|
-
console.log(
|
|
5779
|
+
console.log(chalk8.green(`Environment '${target}' updated.`));
|
|
4847
5780
|
}
|
|
4848
5781
|
});
|
|
4849
5782
|
program.command("current").description("Show current environment name").action(() => {
|
|
4850
5783
|
const current = config2.get("current");
|
|
4851
|
-
console.log(
|
|
5784
|
+
console.log(chalk8.green(current));
|
|
4852
5785
|
});
|
|
4853
5786
|
program.command("env").description("Output environment variables for shell eval").option("--json", "Output as JSON").action((options) => {
|
|
4854
5787
|
const registries = getRegistries();
|
|
@@ -4867,7 +5800,7 @@ program.command("run <command...>").description("Run a command with the current
|
|
|
4867
5800
|
const current = config2.get("current");
|
|
4868
5801
|
const envConfig = registries[current];
|
|
4869
5802
|
if (!envConfig) {
|
|
4870
|
-
console.error(
|
|
5803
|
+
console.error(chalk8.red("No environment configuration found."));
|
|
4871
5804
|
process.exit(1);
|
|
4872
5805
|
}
|
|
4873
5806
|
const env = { ...process.env };
|
|
@@ -4892,7 +5825,7 @@ cronCmd.command("list").description("List CCEM cron tasks").option("--json", "Ou
|
|
|
4892
5825
|
return;
|
|
4893
5826
|
}
|
|
4894
5827
|
if (tasks.length === 0) {
|
|
4895
|
-
console.log(
|
|
5828
|
+
console.log(chalk8.yellow("No cron tasks found."));
|
|
4896
5829
|
return;
|
|
4897
5830
|
}
|
|
4898
5831
|
const table = new Table3({
|
|
@@ -4901,7 +5834,7 @@ cronCmd.command("list").description("List CCEM cron tasks").option("--json", "Ou
|
|
|
4901
5834
|
table.push(...formatCronTaskTableRows(tasks));
|
|
4902
5835
|
console.log(table.toString());
|
|
4903
5836
|
} catch (err) {
|
|
4904
|
-
console.error(
|
|
5837
|
+
console.error(chalk8.red(`\u2717 ${err instanceof Error ? err.message : String(err)}`));
|
|
4905
5838
|
process.exitCode = 1;
|
|
4906
5839
|
}
|
|
4907
5840
|
});
|
|
@@ -4931,13 +5864,13 @@ cronCmd.command("create").description("Create a CCEM cron task").option("--from-
|
|
|
4931
5864
|
console.log(JSON.stringify(task, null, 2));
|
|
4932
5865
|
return;
|
|
4933
5866
|
}
|
|
4934
|
-
console.log(
|
|
4935
|
-
console.log(
|
|
4936
|
-
console.log(
|
|
4937
|
-
console.log(
|
|
4938
|
-
console.log(
|
|
5867
|
+
console.log(chalk8.green("\u2713 Cron task created"));
|
|
5868
|
+
console.log(chalk8.gray(` id: ${task.id}`));
|
|
5869
|
+
console.log(chalk8.gray(` name: ${task.name}`));
|
|
5870
|
+
console.log(chalk8.gray(` cronExpression: ${task.cronExpression}`));
|
|
5871
|
+
console.log(chalk8.gray(` workingDir: ${task.workingDir}`));
|
|
4939
5872
|
} catch (err) {
|
|
4940
|
-
console.error(
|
|
5873
|
+
console.error(chalk8.red(`\u2717 ${err instanceof Error ? err.message : String(err)}`));
|
|
4941
5874
|
process.exitCode = 1;
|
|
4942
5875
|
}
|
|
4943
5876
|
});
|
|
@@ -4948,10 +5881,10 @@ cronCmd.command("delete <selector>").description("Delete a cron task by exact id
|
|
|
4948
5881
|
console.log(JSON.stringify(task, null, 2));
|
|
4949
5882
|
return;
|
|
4950
5883
|
}
|
|
4951
|
-
console.log(
|
|
4952
|
-
console.log(
|
|
5884
|
+
console.log(chalk8.green(`\u2713 Deleted cron task: ${task.name}`));
|
|
5885
|
+
console.log(chalk8.gray(` id: ${task.id}`));
|
|
4953
5886
|
} catch (err) {
|
|
4954
|
-
console.error(
|
|
5887
|
+
console.error(chalk8.red(`\u2717 ${err instanceof Error ? err.message : String(err)}`));
|
|
4955
5888
|
process.exitCode = 1;
|
|
4956
5889
|
}
|
|
4957
5890
|
});
|
|
@@ -4968,34 +5901,34 @@ setupCmd.command("perms").description("\u6C38\u4E45\u914D\u7F6E\u6743\u9650\u6A2
|
|
|
4968
5901
|
return;
|
|
4969
5902
|
}
|
|
4970
5903
|
}
|
|
4971
|
-
console.log(
|
|
4972
|
-
console.log(
|
|
4973
|
-
console.log(
|
|
5904
|
+
console.log(chalk8.yellow("\u8BF7\u6307\u5B9A\u4E00\u4E2A\u6743\u9650\u6A21\u5F0F\uFF0C\u4F8B\u5982: ccem setup perms --dev"));
|
|
5905
|
+
console.log(chalk8.gray("\u53EF\u7528\u6A21\u5F0F: " + PERMISSION_MODES.join(", ")));
|
|
5906
|
+
console.log(chalk8.gray("\u91CD\u7F6E\u6743\u9650: ccem setup perms --reset"));
|
|
4974
5907
|
});
|
|
4975
5908
|
setupCmd.command("default-mode").description("\u8BBE\u7F6E\u9ED8\u8BA4\u6743\u9650\u6A21\u5F0F").option("--yolo", "YOLO \u6A21\u5F0F").option("--dev", "\u5F00\u53D1\u6A21\u5F0F").option("--readonly", "\u53EA\u8BFB\u6A21\u5F0F").option("--safe", "\u5B89\u5168\u6A21\u5F0F").option("--ci", "CI/CD \u6A21\u5F0F").option("--audit", "\u5BA1\u8BA1\u6A21\u5F0F").option("--reset", "\u6E05\u9664\u9ED8\u8BA4\u6A21\u5F0F").action(function() {
|
|
4976
5909
|
const options = this.opts();
|
|
4977
5910
|
if (options.reset) {
|
|
4978
5911
|
config2.set("defaultMode", null);
|
|
4979
|
-
console.log(
|
|
5912
|
+
console.log(chalk8.green("\u5DF2\u6E05\u9664\u9ED8\u8BA4\u6743\u9650\u6A21\u5F0F"));
|
|
4980
5913
|
return;
|
|
4981
5914
|
}
|
|
4982
5915
|
for (const mode of PERMISSION_MODES) {
|
|
4983
5916
|
if (options[mode]) {
|
|
4984
5917
|
config2.set("defaultMode", mode);
|
|
4985
|
-
console.log(
|
|
4986
|
-
console.log(
|
|
5918
|
+
console.log(chalk8.green(`\u5DF2\u8BBE\u7F6E\u9ED8\u8BA4\u6743\u9650\u6A21\u5F0F: ${PERMISSION_PRESETS[mode].name}`));
|
|
5919
|
+
console.log(chalk8.gray(`\u4E0B\u6B21\u542F\u52A8 ccem \u65F6\u5C06\u9ED8\u8BA4\u4F7F\u7528\u6B64\u6A21\u5F0F`));
|
|
4987
5920
|
return;
|
|
4988
5921
|
}
|
|
4989
5922
|
}
|
|
4990
5923
|
const currentDefault = config2.get("defaultMode");
|
|
4991
5924
|
if (currentDefault && PERMISSION_PRESETS[currentDefault]) {
|
|
4992
|
-
console.log(
|
|
5925
|
+
console.log(chalk8.green(`\u5F53\u524D\u9ED8\u8BA4\u6A21\u5F0F: ${PERMISSION_PRESETS[currentDefault].name}`));
|
|
4993
5926
|
} else {
|
|
4994
|
-
console.log(
|
|
5927
|
+
console.log(chalk8.yellow("\u672A\u8BBE\u7F6E\u9ED8\u8BA4\u6743\u9650\u6A21\u5F0F"));
|
|
4995
5928
|
}
|
|
4996
|
-
console.log(
|
|
4997
|
-
console.log(
|
|
4998
|
-
console.log(
|
|
5929
|
+
console.log(chalk8.gray("\n\u8BBE\u7F6E\u9ED8\u8BA4\u6A21\u5F0F: ccem setup default-mode --dev"));
|
|
5930
|
+
console.log(chalk8.gray("\u6E05\u9664\u9ED8\u8BA4\u6A21\u5F0F: ccem setup default-mode --reset"));
|
|
5931
|
+
console.log(chalk8.gray("\u53EF\u7528\u6A21\u5F0F: " + PERMISSION_MODES.join(", ")));
|
|
4999
5932
|
});
|
|
5000
5933
|
setupCmd.command("init").description("\u521D\u59CB\u5316 Claude Code \u5168\u5C40\u914D\u7F6E\uFF08\u8DF3\u8FC7 onboarding\u3001\u7981\u7528\u9065\u6D4B\uFF09").option("--chrome", "\u540C\u65F6\u5B89\u88C5 chrome-devtools MCP \u5DE5\u5177").action(async function() {
|
|
5001
5934
|
const options = this.opts();
|
|
@@ -5005,52 +5938,52 @@ setupCmd.command("migrate").description("\u8FC1\u79FB\u65E7\u7248\u914D\u7F6E\u5
|
|
|
5005
5938
|
const options = this.opts();
|
|
5006
5939
|
const newConfigPath = getCcemConfigPath();
|
|
5007
5940
|
const legacyConfigPath = getLegacyConfigPath();
|
|
5008
|
-
console.log(
|
|
5009
|
-
if (!
|
|
5010
|
-
console.log(
|
|
5011
|
-
console.log(
|
|
5941
|
+
console.log(chalk8.cyan("\n\u{1F504} \u914D\u7F6E\u8FC1\u79FB\n"));
|
|
5942
|
+
if (!fs14.existsSync(legacyConfigPath)) {
|
|
5943
|
+
console.log(chalk8.yellow("\u672A\u627E\u5230\u65E7\u7248\u914D\u7F6E\u6587\u4EF6"));
|
|
5944
|
+
console.log(chalk8.gray(` \u65E7\u8DEF\u5F84: ${legacyConfigPath}`));
|
|
5012
5945
|
return;
|
|
5013
5946
|
}
|
|
5014
|
-
if (
|
|
5015
|
-
console.log(
|
|
5016
|
-
console.log(
|
|
5017
|
-
console.log(
|
|
5947
|
+
if (fs14.existsSync(newConfigPath) && !options.force) {
|
|
5948
|
+
console.log(chalk8.green("\u2713 \u914D\u7F6E\u5DF2\u5728\u65B0\u8DEF\u5F84"));
|
|
5949
|
+
console.log(chalk8.gray(` \u8DEF\u5F84: ${newConfigPath}`));
|
|
5950
|
+
console.log(chalk8.gray("\n\u4F7F\u7528 --force \u5F3A\u5236\u91CD\u65B0\u8FC1\u79FB"));
|
|
5018
5951
|
return;
|
|
5019
5952
|
}
|
|
5020
5953
|
try {
|
|
5021
5954
|
ensureCcemDir();
|
|
5022
|
-
const legacyRaw = JSON.parse(
|
|
5955
|
+
const legacyRaw = JSON.parse(fs14.readFileSync(legacyConfigPath, "utf-8"));
|
|
5023
5956
|
const migrated = normalizeCcemConfig(legacyRaw);
|
|
5024
5957
|
if (!migrated.registries[OFFICIAL_ENV_NAME]) {
|
|
5025
5958
|
migrated.registries[OFFICIAL_ENV_NAME] = { ...DEFAULT_OFFICIAL_ENV };
|
|
5026
5959
|
}
|
|
5027
5960
|
assertOfficialEnvironmentInvariant(migrated.registries);
|
|
5028
5961
|
setEnvironmentMutationConfig(migrated);
|
|
5029
|
-
console.log(
|
|
5030
|
-
console.log(
|
|
5031
|
-
console.log(
|
|
5962
|
+
console.log(chalk8.green("\u2713 \u914D\u7F6E\u5DF2\u8FC1\u79FB"));
|
|
5963
|
+
console.log(chalk8.gray(` \u4ECE: ${legacyConfigPath}`));
|
|
5964
|
+
console.log(chalk8.gray(` \u5230: ${newConfigPath}`));
|
|
5032
5965
|
if (options.clean) {
|
|
5033
|
-
|
|
5034
|
-
const legacyDir =
|
|
5966
|
+
fs14.unlinkSync(legacyConfigPath);
|
|
5967
|
+
const legacyDir = path12.dirname(legacyConfigPath);
|
|
5035
5968
|
try {
|
|
5036
|
-
|
|
5969
|
+
fs14.rmdirSync(legacyDir);
|
|
5037
5970
|
} catch {
|
|
5038
5971
|
}
|
|
5039
|
-
console.log(
|
|
5972
|
+
console.log(chalk8.green("\u2713 \u5DF2\u5220\u9664\u65E7\u914D\u7F6E\u6587\u4EF6"));
|
|
5040
5973
|
}
|
|
5041
5974
|
} catch (err) {
|
|
5042
|
-
console.error(
|
|
5975
|
+
console.error(chalk8.red(`\u2717 \u8FC1\u79FB\u5931\u8D25: ${err}`));
|
|
5043
5976
|
}
|
|
5044
5977
|
});
|
|
5045
5978
|
setupCmd.command("cron").description("\u5B89\u88C5 ccem-cron skill \u5230 Claude Code\uFF08~/.claude/skills/\uFF09").option("--force", "\u5F3A\u5236\u8986\u76D6\u5DF2\u6709\u6587\u4EF6").action(async function() {
|
|
5046
5979
|
const options = this.opts();
|
|
5047
|
-
const skillDir =
|
|
5048
|
-
const targetPath =
|
|
5049
|
-
if (!
|
|
5050
|
-
|
|
5051
|
-
console.log(
|
|
5980
|
+
const skillDir = path12.join(getHomeDir(), ".claude", "skills");
|
|
5981
|
+
const targetPath = path12.join(skillDir, "ccem-cron.md");
|
|
5982
|
+
if (!fs14.existsSync(skillDir)) {
|
|
5983
|
+
fs14.mkdirSync(skillDir, { recursive: true });
|
|
5984
|
+
console.log(chalk8.gray(`\u521B\u5EFA\u76EE\u5F55: ${skillDir}`));
|
|
5052
5985
|
}
|
|
5053
|
-
if (
|
|
5986
|
+
if (fs14.existsSync(targetPath) && !options.force) {
|
|
5054
5987
|
const { overwrite } = await inquirer.prompt([
|
|
5055
5988
|
{
|
|
5056
5989
|
type: "confirm",
|
|
@@ -5060,25 +5993,25 @@ setupCmd.command("cron").description("\u5B89\u88C5 ccem-cron skill \u5230 Claude
|
|
|
5060
5993
|
}
|
|
5061
5994
|
]);
|
|
5062
5995
|
if (!overwrite) {
|
|
5063
|
-
console.log(
|
|
5996
|
+
console.log(chalk8.yellow("\u5DF2\u53D6\u6D88"));
|
|
5064
5997
|
return;
|
|
5065
5998
|
}
|
|
5066
5999
|
}
|
|
5067
|
-
|
|
5068
|
-
console.log(
|
|
5069
|
-
console.log(
|
|
5070
|
-
console.log(
|
|
6000
|
+
fs14.writeFileSync(targetPath, CCEM_CRON_SKILL_CONTENT, "utf-8");
|
|
6001
|
+
console.log(chalk8.green(`\u2713 \u5DF2\u5B89\u88C5 ccem-cron skill`));
|
|
6002
|
+
console.log(chalk8.gray(` \u8DEF\u5F84: ${targetPath}`));
|
|
6003
|
+
console.log(chalk8.cyan(`
|
|
5071
6004
|
\u5728 Claude Code \u4E2D\u4F7F\u7528 /ccem-cron \u5373\u53EF\u8C03\u7528\u6B64 skill`));
|
|
5072
6005
|
});
|
|
5073
6006
|
setupCmd.command("bot-bind").description("\u5B89\u88C5 ccem-bot-bind skill \u5230 Claude Code\uFF08~/.claude/skills/\uFF09").option("--force", "\u5F3A\u5236\u8986\u76D6\u5DF2\u6709\u6587\u4EF6").action(async function() {
|
|
5074
6007
|
const options = this.opts();
|
|
5075
|
-
const skillDir =
|
|
5076
|
-
const targetPath =
|
|
5077
|
-
if (!
|
|
5078
|
-
|
|
5079
|
-
console.log(
|
|
6008
|
+
const skillDir = path12.join(getHomeDir(), ".claude", "skills");
|
|
6009
|
+
const targetPath = path12.join(skillDir, "ccem-bot-bind.md");
|
|
6010
|
+
if (!fs14.existsSync(skillDir)) {
|
|
6011
|
+
fs14.mkdirSync(skillDir, { recursive: true });
|
|
6012
|
+
console.log(chalk8.gray(`\u521B\u5EFA\u76EE\u5F55: ${skillDir}`));
|
|
5080
6013
|
}
|
|
5081
|
-
if (
|
|
6014
|
+
if (fs14.existsSync(targetPath) && !options.force) {
|
|
5082
6015
|
const { overwrite } = await inquirer.prompt([
|
|
5083
6016
|
{
|
|
5084
6017
|
type: "confirm",
|
|
@@ -5088,14 +6021,14 @@ setupCmd.command("bot-bind").description("\u5B89\u88C5 ccem-bot-bind skill \u523
|
|
|
5088
6021
|
}
|
|
5089
6022
|
]);
|
|
5090
6023
|
if (!overwrite) {
|
|
5091
|
-
console.log(
|
|
6024
|
+
console.log(chalk8.yellow("\u5DF2\u53D6\u6D88"));
|
|
5092
6025
|
return;
|
|
5093
6026
|
}
|
|
5094
6027
|
}
|
|
5095
|
-
|
|
5096
|
-
console.log(
|
|
5097
|
-
console.log(
|
|
5098
|
-
console.log(
|
|
6028
|
+
fs14.writeFileSync(targetPath, CCEM_BOT_BIND_SKILL_CONTENT, "utf-8");
|
|
6029
|
+
console.log(chalk8.green(`\u2713 \u5DF2\u5B89\u88C5 ccem-bot-bind skill`));
|
|
6030
|
+
console.log(chalk8.gray(` \u8DEF\u5F84: ${targetPath}`));
|
|
6031
|
+
console.log(chalk8.cyan(`
|
|
5099
6032
|
\u5728 Claude Code \u4E2D\u8BA9\u5B83\u4F7F\u7528 ccem-bot-bind skill \u5373\u53EF\u7ED1\u5B9A\u5F53\u524D\u4F1A\u8BDD\u5230 bot`));
|
|
5100
6033
|
});
|
|
5101
6034
|
var skillCmd = program.command("skill").description("\u7BA1\u7406 Claude Code skills");
|
|
@@ -5105,7 +6038,7 @@ skillCmd.command("add [url]").description("\u6DFB\u52A0 skill\uFF08\u4ECE\u5B98\
|
|
|
5105
6038
|
} else {
|
|
5106
6039
|
const result = await runSkillSelector();
|
|
5107
6040
|
if (result.type === "cancelled") {
|
|
5108
|
-
console.log(
|
|
6041
|
+
console.log(chalk8.yellow("\u5DF2\u53D6\u6D88"));
|
|
5109
6042
|
return;
|
|
5110
6043
|
}
|
|
5111
6044
|
if (result.type === "custom") {
|
|
@@ -5132,8 +6065,8 @@ skillCmd.command("add [url]").description("\u6DFB\u52A0 skill\uFF08\u4ECE\u5B98\
|
|
|
5132
6065
|
skillCmd.command("ls").description("\u5217\u51FA\u5DF2\u5B89\u88C5\u7684 skills").action(() => {
|
|
5133
6066
|
const skills = listInstalledSkills();
|
|
5134
6067
|
if (skills.length === 0) {
|
|
5135
|
-
console.log(
|
|
5136
|
-
console.log(
|
|
6068
|
+
console.log(chalk8.yellow("\u5F53\u524D\u76EE\u5F55\u6CA1\u6709\u5B89\u88C5\u4EFB\u4F55 skill"));
|
|
6069
|
+
console.log(chalk8.gray("\u4F7F\u7528 ccem skill add \u6DFB\u52A0 skills"));
|
|
5137
6070
|
return;
|
|
5138
6071
|
}
|
|
5139
6072
|
const table = new Table3({
|
|
@@ -5141,7 +6074,7 @@ skillCmd.command("ls").description("\u5217\u51FA\u5DF2\u5B89\u88C5\u7684 skills"
|
|
|
5141
6074
|
style: { head: ["cyan"] }
|
|
5142
6075
|
});
|
|
5143
6076
|
skills.forEach((skill) => {
|
|
5144
|
-
table.push([
|
|
6077
|
+
table.push([chalk8.green(skill.name), chalk8.gray(skill.path)]);
|
|
5145
6078
|
});
|
|
5146
6079
|
console.log(table.toString());
|
|
5147
6080
|
});
|
|
@@ -5154,7 +6087,7 @@ program.command("load <url>").description("\u4ECE\u8FDC\u7A0B\u670D\u52A1\u5668\
|
|
|
5154
6087
|
const stdinInput = options.credentialsStdin ? await readAllStdin() : "";
|
|
5155
6088
|
credentials = resolveLoadCredentials(options, stdinInput);
|
|
5156
6089
|
} catch (err) {
|
|
5157
|
-
console.error(
|
|
6090
|
+
console.error(chalk8.red(`Error: ${err.message}`));
|
|
5158
6091
|
process.exit(1);
|
|
5159
6092
|
}
|
|
5160
6093
|
const results = await loadFromRemote(url, credentials.key, credentials.secret);
|
|
@@ -5176,12 +6109,12 @@ program.command("launch").description(false).option("--env <name>", "\u73AF\u588
|
|
|
5176
6109
|
const registries = getRegistries();
|
|
5177
6110
|
const envConfig = registries[envName];
|
|
5178
6111
|
if (!envConfig) {
|
|
5179
|
-
console.error(
|
|
6112
|
+
console.error(chalk8.red(`Environment '${envName}' not found.`));
|
|
5180
6113
|
process.exit(1);
|
|
5181
6114
|
}
|
|
5182
6115
|
const proxyBaseUrl = opts.proxyBaseUrl || opts.anthropicBaseUrl;
|
|
5183
6116
|
if (proxyBaseUrl && !isTrustedDesktopProxyBaseUrl(proxyBaseUrl)) {
|
|
5184
|
-
console.error(
|
|
6117
|
+
console.error(chalk8.red("Desktop proxy override must use the local CCEM Claude proxy endpoint."));
|
|
5185
6118
|
process.exitCode = 1;
|
|
5186
6119
|
return;
|
|
5187
6120
|
}
|
|
@@ -5212,7 +6145,7 @@ desktopCmd.command("create").description("Create a workspace session in the runn
|
|
|
5212
6145
|
const hasRouteOptions = opts.route.length > 0 || opts.routesJson !== void 0;
|
|
5213
6146
|
const routes = provider === "claude" ? parseDesktopRoutes(opts.route, opts.routesJson) : void 0;
|
|
5214
6147
|
if (provider === "codex" && hasRouteOptions) {
|
|
5215
|
-
console.error(
|
|
6148
|
+
console.error(chalk8.yellow(
|
|
5216
6149
|
"Warning: Codex sessions do not support routing; --route and --routes-json were ignored."
|
|
5217
6150
|
));
|
|
5218
6151
|
}
|
|
@@ -5283,7 +6216,7 @@ program.command("usage").description("\u663E\u793A\u4F7F\u7528\u7EDF\u8BA1\u5E76
|
|
|
5283
6216
|
if (stats) {
|
|
5284
6217
|
console.log(renderUsageDetail(stats));
|
|
5285
6218
|
} else {
|
|
5286
|
-
console.log(
|
|
6219
|
+
console.log(chalk8.yellow("No usage data available"));
|
|
5287
6220
|
}
|
|
5288
6221
|
}
|
|
5289
6222
|
});
|
|
@@ -5309,9 +6242,9 @@ program.action(async (options) => {
|
|
|
5309
6242
|
{
|
|
5310
6243
|
type: "list",
|
|
5311
6244
|
name: "action",
|
|
5312
|
-
message:
|
|
6245
|
+
message: chalk8.gray("Select action"),
|
|
5313
6246
|
choices: getMainMenuChoices(defaultMode),
|
|
5314
|
-
prefix:
|
|
6247
|
+
prefix: chalk8.gray("?")
|
|
5315
6248
|
}
|
|
5316
6249
|
]);
|
|
5317
6250
|
if (action === "start") {
|
|
@@ -5341,7 +6274,7 @@ program.action(async (options) => {
|
|
|
5341
6274
|
{
|
|
5342
6275
|
type: "input",
|
|
5343
6276
|
name: "continue",
|
|
5344
|
-
message:
|
|
6277
|
+
message: chalk8.gray("Press Enter to continue..."),
|
|
5345
6278
|
prefix: ""
|
|
5346
6279
|
}
|
|
5347
6280
|
]);
|
|
@@ -5351,17 +6284,17 @@ program.action(async (options) => {
|
|
|
5351
6284
|
config2.set("current", result.name);
|
|
5352
6285
|
} else if (result.action === "edit") {
|
|
5353
6286
|
const envToEdit = registries[result.name];
|
|
5354
|
-
console.log(
|
|
6287
|
+
console.log(chalk8.yellow(`
|
|
5355
6288
|
Editing environment '${result.name}'`));
|
|
5356
6289
|
const answers = await promptForEnvironmentConfig(envToEdit, true);
|
|
5357
6290
|
registries[result.name] = applyPromptAnswers(envToEdit, answers, true);
|
|
5358
6291
|
setRegistries(registries);
|
|
5359
6292
|
msg.success(`Environment '${result.name}' updated.`);
|
|
5360
|
-
await new Promise((
|
|
6293
|
+
await new Promise((resolve5) => setTimeout(resolve5, 800));
|
|
5361
6294
|
} else if (result.action === "rename") {
|
|
5362
6295
|
if (result.name === OFFICIAL_ENV_NAME) {
|
|
5363
6296
|
msg.error("Cannot rename default 'official' environment.");
|
|
5364
|
-
await new Promise((
|
|
6297
|
+
await new Promise((resolve5) => setTimeout(resolve5, 800));
|
|
5365
6298
|
} else {
|
|
5366
6299
|
const { newName } = await inquirer.prompt([
|
|
5367
6300
|
{
|
|
@@ -5388,7 +6321,7 @@ Editing environment '${result.name}'`));
|
|
|
5388
6321
|
} catch (error) {
|
|
5389
6322
|
msg.error(error instanceof Error ? error.message : String(error));
|
|
5390
6323
|
}
|
|
5391
|
-
await new Promise((
|
|
6324
|
+
await new Promise((resolve5) => setTimeout(resolve5, 800));
|
|
5392
6325
|
}
|
|
5393
6326
|
} else if (result.action === "copy") {
|
|
5394
6327
|
const { targetName } = await inquirer.prompt([
|
|
@@ -5421,11 +6354,11 @@ Editing environment '${result.name}'`));
|
|
|
5421
6354
|
setRegistries(registries);
|
|
5422
6355
|
msg.success(`Environment '${targetName}' updated.`);
|
|
5423
6356
|
}
|
|
5424
|
-
await new Promise((
|
|
6357
|
+
await new Promise((resolve5) => setTimeout(resolve5, 800));
|
|
5425
6358
|
} else if (result.action === "delete") {
|
|
5426
6359
|
if (result.name === OFFICIAL_ENV_NAME) {
|
|
5427
6360
|
msg.error("Cannot delete default 'official' environment.");
|
|
5428
|
-
await new Promise((
|
|
6361
|
+
await new Promise((resolve5) => setTimeout(resolve5, 800));
|
|
5429
6362
|
} else {
|
|
5430
6363
|
const { confirm } = await inquirer.prompt([
|
|
5431
6364
|
{
|
|
@@ -5453,7 +6386,7 @@ Editing environment '${result.name}'`));
|
|
|
5453
6386
|
msg.error(error instanceof Error ? error.message : String(error));
|
|
5454
6387
|
}
|
|
5455
6388
|
}
|
|
5456
|
-
await new Promise((
|
|
6389
|
+
await new Promise((resolve5) => setTimeout(resolve5, 800));
|
|
5457
6390
|
}
|
|
5458
6391
|
}
|
|
5459
6392
|
} else if (action === "perm") {
|
|
@@ -5461,9 +6394,9 @@ Editing environment '${result.name}'`));
|
|
|
5461
6394
|
{
|
|
5462
6395
|
type: "list",
|
|
5463
6396
|
name: "permMode",
|
|
5464
|
-
message:
|
|
6397
|
+
message: chalk8.gray("Select permission mode"),
|
|
5465
6398
|
choices: getPermModeChoices(null, false),
|
|
5466
|
-
prefix:
|
|
6399
|
+
prefix: chalk8.gray("?")
|
|
5467
6400
|
}
|
|
5468
6401
|
]);
|
|
5469
6402
|
if (permMode !== "back") {
|
|
@@ -5476,19 +6409,19 @@ Editing environment '${result.name}'`));
|
|
|
5476
6409
|
{
|
|
5477
6410
|
type: "list",
|
|
5478
6411
|
name: "selectedMode",
|
|
5479
|
-
message:
|
|
6412
|
+
message: chalk8.gray("Set default permission mode"),
|
|
5480
6413
|
choices: getPermModeChoices(currentDefault, true),
|
|
5481
|
-
prefix:
|
|
6414
|
+
prefix: chalk8.gray("?")
|
|
5482
6415
|
}
|
|
5483
6416
|
]);
|
|
5484
6417
|
if (selectedMode === "clear") {
|
|
5485
6418
|
config2.set("defaultMode", null);
|
|
5486
6419
|
msg.success("Default mode cleared");
|
|
5487
|
-
await new Promise((
|
|
6420
|
+
await new Promise((resolve5) => setTimeout(resolve5, 800));
|
|
5488
6421
|
} else if (selectedMode !== "back") {
|
|
5489
6422
|
config2.set("defaultMode", selectedMode);
|
|
5490
6423
|
msg.success(`Default mode set: ${PERMISSION_PRESETS[selectedMode].name}`);
|
|
5491
|
-
await new Promise((
|
|
6424
|
+
await new Promise((resolve5) => setTimeout(resolve5, 800));
|
|
5492
6425
|
}
|
|
5493
6426
|
} else {
|
|
5494
6427
|
process.exit(0);
|
|
@@ -5497,14 +6430,18 @@ Editing environment '${result.name}'`));
|
|
|
5497
6430
|
});
|
|
5498
6431
|
function handleCliError(error) {
|
|
5499
6432
|
if (error instanceof StaleDesktopControlDescriptorError) {
|
|
5500
|
-
console.error(
|
|
6433
|
+
console.error(chalk8.red(error.message));
|
|
5501
6434
|
process.exit(1);
|
|
5502
6435
|
}
|
|
5503
6436
|
if (error instanceof Error) {
|
|
5504
|
-
console.error(
|
|
6437
|
+
console.error(chalk8.red(error.message));
|
|
5505
6438
|
process.exit(1);
|
|
5506
6439
|
}
|
|
5507
|
-
console.error(
|
|
6440
|
+
console.error(chalk8.red(String(error)));
|
|
5508
6441
|
process.exit(1);
|
|
5509
6442
|
}
|
|
6443
|
+
registerDshCommands(program, {
|
|
6444
|
+
getRegistries,
|
|
6445
|
+
getCurrentEnvName: () => config2.get("current") ?? ""
|
|
6446
|
+
});
|
|
5510
6447
|
await program.parseAsync(process.argv).catch(handleCliError);
|