ccem 2.95.0 → 2.96.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 +994 -303
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import { spawn } from "child_process";
|
|
|
5
5
|
import { TextDecoder } from "util";
|
|
6
6
|
|
|
7
7
|
// src/desktopControl.ts
|
|
8
|
-
import
|
|
9
|
-
import
|
|
8
|
+
import fs6 from "fs";
|
|
9
|
+
import path6 from "path";
|
|
10
10
|
|
|
11
11
|
// ../../packages/core/dist/chunk-4WH3CEOL.js
|
|
12
12
|
var DEFAULT_ROUTER_PORT = 17820;
|
|
@@ -234,10 +234,10 @@ function renameRouterEnvironmentReferences(router, oldName, newName) {
|
|
|
234
234
|
profiles: normalized.profiles.map((profile) => {
|
|
235
235
|
const bindings = renameBindings(profile.bindings);
|
|
236
236
|
const allowedEnvs = replaceEnvironmentNames(profile.allowedEnvs, oldName, newName);
|
|
237
|
-
const
|
|
237
|
+
const changed2 = Object.entries(profile.bindings).some(([, target]) => target === oldName && target !== newName) || profile.allowedEnvs.some((target) => target === oldName && target !== newName);
|
|
238
238
|
return {
|
|
239
239
|
...profile,
|
|
240
|
-
revision:
|
|
240
|
+
revision: changed2 ? bumpProfileRevision(profile.revision) : profile.revision,
|
|
241
241
|
bindings,
|
|
242
242
|
allowedEnvs
|
|
243
243
|
};
|
|
@@ -700,16 +700,22 @@ var getPermissionModeNames = () => {
|
|
|
700
700
|
|
|
701
701
|
// ../../packages/core/dist/index.js
|
|
702
702
|
import crypto2 from "crypto";
|
|
703
|
-
import
|
|
703
|
+
import fs5 from "fs";
|
|
704
704
|
import os2 from "os";
|
|
705
|
-
import
|
|
706
|
-
import
|
|
705
|
+
import path5 from "path";
|
|
706
|
+
import fs4 from "fs";
|
|
707
707
|
import os from "os";
|
|
708
|
-
import
|
|
709
|
-
import { randomUUID } from "crypto";
|
|
708
|
+
import path4 from "path";
|
|
709
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
710
710
|
import fs from "fs";
|
|
711
711
|
import path from "path";
|
|
712
712
|
import { execFileSync } from "child_process";
|
|
713
|
+
import fs2 from "fs";
|
|
714
|
+
import path2 from "path";
|
|
715
|
+
import { randomUUID } from "crypto";
|
|
716
|
+
import fs3 from "fs";
|
|
717
|
+
import path3 from "path";
|
|
718
|
+
import { createHash, randomUUID as randomUUID2 } from "crypto";
|
|
713
719
|
import crypto from "crypto";
|
|
714
720
|
function processAlive(pid) {
|
|
715
721
|
try {
|
|
@@ -771,8 +777,8 @@ function persistedProcesses(home) {
|
|
|
771
777
|
const file = path.join(home, ".ccem", name);
|
|
772
778
|
let value;
|
|
773
779
|
try {
|
|
774
|
-
const
|
|
775
|
-
if (!
|
|
780
|
+
const stat22 = fs.lstatSync(file);
|
|
781
|
+
if (!stat22.isFile() || stat22.isSymbolicLink()) continue;
|
|
776
782
|
value = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
777
783
|
} catch (error) {
|
|
778
784
|
if (error.code === "ENOENT") continue;
|
|
@@ -890,6 +896,662 @@ function assertNoLegacyAgentWriters(provider, home, source, destination) {
|
|
|
890
896
|
}
|
|
891
897
|
}
|
|
892
898
|
}
|
|
899
|
+
var CLAUDE_PLUGIN_IMPORT_LEDGER = ".ccem-plugins-import-v1.json";
|
|
900
|
+
function object(value, label) {
|
|
901
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`Invalid ${label}`);
|
|
902
|
+
return value;
|
|
903
|
+
}
|
|
904
|
+
function stat(file) {
|
|
905
|
+
try {
|
|
906
|
+
return fs2.lstatSync(file);
|
|
907
|
+
} catch (error) {
|
|
908
|
+
if (error.code === "ENOENT") return void 0;
|
|
909
|
+
throw error;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
function noLinks(file) {
|
|
913
|
+
let current = path2.parse(file).root;
|
|
914
|
+
for (const part of file.slice(current.length).split(path2.sep).filter(Boolean)) {
|
|
915
|
+
current = path2.join(current, part);
|
|
916
|
+
if (stat(current)?.isSymbolicLink()) throw new Error(`Plugin import cannot use a destination symlink: ${current}`);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
function readDocument(file, fallback = {}) {
|
|
920
|
+
noLinks(file);
|
|
921
|
+
const info = stat(file);
|
|
922
|
+
if (!info) return { file, value: structuredClone(fallback) };
|
|
923
|
+
if (!info.isFile()) throw new Error(`Plugin metadata is not a file: ${file}`);
|
|
924
|
+
const before = fs2.readFileSync(file, "utf8");
|
|
925
|
+
return { file, before, value: object(JSON.parse(before), `plugin metadata: ${file}`) };
|
|
926
|
+
}
|
|
927
|
+
function pluginId(id) {
|
|
928
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*@[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(id)) {
|
|
929
|
+
throw new Error("Invalid plugin identity");
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
function identity(value) {
|
|
933
|
+
const row = object(value, "plugin install");
|
|
934
|
+
if (typeof row.scope !== "string" || !["user", "project", "local"].includes(row.scope)) throw new Error("Invalid plugin scope");
|
|
935
|
+
const projectPath = row.projectPath ?? null;
|
|
936
|
+
if (row.scope === "user" ? projectPath !== null : typeof projectPath !== "string" || !path2.isAbsolute(projectPath) || projectPath.split(/[\\/]/).includes("..")) {
|
|
937
|
+
throw new Error("Invalid plugin project scope");
|
|
938
|
+
}
|
|
939
|
+
return { scope: row.scope, projectPath };
|
|
940
|
+
}
|
|
941
|
+
function same(a, b) {
|
|
942
|
+
return a.scope === b.scope && a.projectPath === b.projectPath;
|
|
943
|
+
}
|
|
944
|
+
function registry(document) {
|
|
945
|
+
if (document.value.version !== 2) throw new Error("Unsupported Claude plugin registry version");
|
|
946
|
+
const plugins = object(document.value.plugins, "Claude plugin registry");
|
|
947
|
+
for (const [id, rows] of Object.entries(plugins)) {
|
|
948
|
+
pluginId(id);
|
|
949
|
+
if (!Array.isArray(rows)) throw new Error("Invalid plugin installations");
|
|
950
|
+
const seen = [];
|
|
951
|
+
for (const row of rows) {
|
|
952
|
+
const key = identity(row);
|
|
953
|
+
if (seen.some((old) => same(old, key))) throw new Error("Duplicate plugin installation identity");
|
|
954
|
+
seen.push(key);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
return plugins;
|
|
958
|
+
}
|
|
959
|
+
function readLedger(target) {
|
|
960
|
+
const document = readDocument(path2.join(target, CLAUDE_PLUGIN_IMPORT_LEDGER), { version: 1, seen: {} });
|
|
961
|
+
if (document.value.version !== 1 || Object.keys(document.value).some((key) => !["version", "seen"].includes(key))) {
|
|
962
|
+
throw new Error("Unsupported Claude plugin import ledger");
|
|
963
|
+
}
|
|
964
|
+
for (const [id, rows] of Object.entries(object(document.value.seen, "plugin import ledger"))) {
|
|
965
|
+
pluginId(id);
|
|
966
|
+
if (!Array.isArray(rows) || rows.length === 0) throw new Error("Invalid plugin import ledger");
|
|
967
|
+
const parsed = [];
|
|
968
|
+
for (const row of rows) {
|
|
969
|
+
if (!Object.hasOwn(object(row, "plugin import identity"), "projectPath") || Object.keys(row).some((key) => !["scope", "projectPath"].includes(key))) {
|
|
970
|
+
throw new Error("Invalid plugin import identity");
|
|
971
|
+
}
|
|
972
|
+
const item = identity(row);
|
|
973
|
+
if (parsed.some((old) => same(old, item))) throw new Error("Duplicate plugin import identity");
|
|
974
|
+
parsed.push(item);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
return document;
|
|
978
|
+
}
|
|
979
|
+
function readSource(source) {
|
|
980
|
+
return readDocument(path2.join(source, "plugins", "installed_plugins.json"), { version: 2, plugins: {} });
|
|
981
|
+
}
|
|
982
|
+
function claudePluginImportPending(source, target) {
|
|
983
|
+
const installed = registry(readSource(source));
|
|
984
|
+
const ledger = readLedger(target).value;
|
|
985
|
+
return Object.entries(installed).some(([id, rows]) => rows.length > 0 && !Object.hasOwn(ledger.seen, id));
|
|
986
|
+
}
|
|
987
|
+
function contained(root, file) {
|
|
988
|
+
const relative2 = path2.relative(root, file);
|
|
989
|
+
return relative2 !== "" && !relative2.startsWith(`..${path2.sep}`) && relative2 !== ".." && !path2.isAbsolute(relative2);
|
|
990
|
+
}
|
|
991
|
+
function rejectPrivateData(root, file) {
|
|
992
|
+
if (path2.relative(root, file).split(path2.sep)[0] === "data") {
|
|
993
|
+
throw new Error("Plugin import cannot copy private plugin data");
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
function relocated(value, source, target) {
|
|
997
|
+
if (typeof value !== "string" || !path2.isAbsolute(value)) throw new Error("Plugin installation path must be absolute");
|
|
998
|
+
const resolved = path2.resolve(value);
|
|
999
|
+
if (!contained(source, resolved)) throw new Error("Plugin path escapes the official plugin store");
|
|
1000
|
+
rejectPrivateData(source, resolved);
|
|
1001
|
+
return { source: resolved, target: path2.join(target, path2.relative(source, resolved)) };
|
|
1002
|
+
}
|
|
1003
|
+
function planCopy(source, target, sourceRoot, copies, excluded = /* @__PURE__ */ new Set(), ancestors = /* @__PURE__ */ new Set()) {
|
|
1004
|
+
if (excluded.has(target)) return;
|
|
1005
|
+
const resolved = fs2.realpathSync(source);
|
|
1006
|
+
if (resolved !== sourceRoot && !contained(sourceRoot, resolved)) throw new Error("Plugin symlink escapes the official plugin store");
|
|
1007
|
+
rejectPrivateData(sourceRoot, resolved);
|
|
1008
|
+
if (ancestors.has(resolved)) throw new Error("Plugin symlink cycle");
|
|
1009
|
+
noLinks(target);
|
|
1010
|
+
const info = fs2.statSync(resolved);
|
|
1011
|
+
const existing = stat(target);
|
|
1012
|
+
if (info.isDirectory()) {
|
|
1013
|
+
if (existing && !existing.isDirectory()) throw new Error("Plugin destination directory conflicts with a file");
|
|
1014
|
+
copies.push({ source: resolved, target, directory: true, mode: 448 });
|
|
1015
|
+
const next = new Set(ancestors).add(resolved);
|
|
1016
|
+
for (const name of fs2.readdirSync(resolved).sort()) planCopy(path2.join(resolved, name), path2.join(target, name), sourceRoot, copies, excluded, next);
|
|
1017
|
+
} else if (info.isFile()) {
|
|
1018
|
+
if (existing) {
|
|
1019
|
+
if (!existing.isFile() || !fs2.readFileSync(target).equals(fs2.readFileSync(resolved))) {
|
|
1020
|
+
throw new Error("Existing CCEM plugin files differ; keeping the CCEM copy");
|
|
1021
|
+
}
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
copies.push({ source: resolved, target, directory: false, mode: 384 | info.mode & 73 });
|
|
1025
|
+
} else {
|
|
1026
|
+
throw new Error("Plugin asset is not a regular file or directory");
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
function privateDirectory(directory) {
|
|
1030
|
+
noLinks(directory);
|
|
1031
|
+
fs2.mkdirSync(directory, { recursive: true, mode: 448 });
|
|
1032
|
+
}
|
|
1033
|
+
function publishCopy(copy) {
|
|
1034
|
+
noLinks(copy.target);
|
|
1035
|
+
if (copy.directory) {
|
|
1036
|
+
privateDirectory(copy.target);
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
privateDirectory(path2.dirname(copy.target));
|
|
1040
|
+
const temporary = `${copy.target}.ccem-${randomUUID()}.tmp`;
|
|
1041
|
+
let input;
|
|
1042
|
+
let output;
|
|
1043
|
+
try {
|
|
1044
|
+
input = fs2.openSync(copy.source, fs2.constants.O_RDONLY | (fs2.constants.O_NOFOLLOW ?? 0));
|
|
1045
|
+
const before = fs2.fstatSync(input);
|
|
1046
|
+
if (!before.isFile()) throw new Error("Plugin source changed during import");
|
|
1047
|
+
output = fs2.openSync(temporary, "wx", copy.mode);
|
|
1048
|
+
const buffer = Buffer.alloc(1024 * 1024);
|
|
1049
|
+
let remaining = before.size;
|
|
1050
|
+
while (remaining > 0) {
|
|
1051
|
+
const count = fs2.readSync(input, buffer, 0, Math.min(buffer.length, remaining), null);
|
|
1052
|
+
if (!count) throw new Error("Plugin source changed during import");
|
|
1053
|
+
let offset = 0;
|
|
1054
|
+
while (offset < count) offset += fs2.writeSync(output, buffer, offset, count - offset);
|
|
1055
|
+
remaining -= count;
|
|
1056
|
+
}
|
|
1057
|
+
const after = fs2.fstatSync(input);
|
|
1058
|
+
if (after.size !== before.size || after.mtimeMs !== before.mtimeMs) throw new Error("Plugin source changed during import");
|
|
1059
|
+
fs2.fsyncSync(output);
|
|
1060
|
+
fs2.closeSync(output);
|
|
1061
|
+
output = void 0;
|
|
1062
|
+
noLinks(copy.target);
|
|
1063
|
+
try {
|
|
1064
|
+
fs2.linkSync(temporary, copy.target);
|
|
1065
|
+
} catch (error) {
|
|
1066
|
+
if (error.code !== "EEXIST" || !stat(copy.target)?.isFile() || !fs2.readFileSync(copy.target).equals(fs2.readFileSync(temporary))) throw error;
|
|
1067
|
+
}
|
|
1068
|
+
} finally {
|
|
1069
|
+
if (input !== void 0) fs2.closeSync(input);
|
|
1070
|
+
if (output !== void 0) fs2.closeSync(output);
|
|
1071
|
+
fs2.rmSync(temporary, { force: true });
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
function unchanged(document) {
|
|
1075
|
+
noLinks(document.file);
|
|
1076
|
+
const current = stat(document.file) ? fs2.readFileSync(document.file, "utf8") : void 0;
|
|
1077
|
+
if (current !== document.before) throw new Error("Plugin metadata changed during import; retry later");
|
|
1078
|
+
}
|
|
1079
|
+
function publishDocument(document, target, backupDirectory = ".ccem-plugins-backup-v1") {
|
|
1080
|
+
const contents = `${JSON.stringify(document.value, null, 2)}
|
|
1081
|
+
`;
|
|
1082
|
+
if (document.before !== void 0 && JSON.stringify(JSON.parse(document.before)) === JSON.stringify(document.value)) return;
|
|
1083
|
+
unchanged(document);
|
|
1084
|
+
privateDirectory(path2.dirname(document.file));
|
|
1085
|
+
if (document.before !== void 0) {
|
|
1086
|
+
const backup = path2.join(target, backupDirectory, path2.relative(target, document.file));
|
|
1087
|
+
privateDirectory(path2.dirname(backup));
|
|
1088
|
+
noLinks(backup);
|
|
1089
|
+
const existing = stat(backup);
|
|
1090
|
+
if (existing && !existing.isFile()) throw new Error("Plugin metadata backup is not a file");
|
|
1091
|
+
if (!existing) fs2.writeFileSync(backup, document.before, { flag: "wx", mode: 384 });
|
|
1092
|
+
}
|
|
1093
|
+
const temporary = `${document.file}.ccem-${randomUUID()}.tmp`;
|
|
1094
|
+
try {
|
|
1095
|
+
const fd = fs2.openSync(temporary, "wx", 384);
|
|
1096
|
+
try {
|
|
1097
|
+
fs2.writeFileSync(fd, contents);
|
|
1098
|
+
fs2.fsyncSync(fd);
|
|
1099
|
+
} finally {
|
|
1100
|
+
fs2.closeSync(fd);
|
|
1101
|
+
}
|
|
1102
|
+
unchanged(document);
|
|
1103
|
+
fs2.renameSync(temporary, document.file);
|
|
1104
|
+
document.before = contents;
|
|
1105
|
+
} finally {
|
|
1106
|
+
fs2.rmSync(temporary, { force: true });
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function importClaudePlugins(sourceHome, targetHome) {
|
|
1110
|
+
const sourceRegistry = readSource(sourceHome);
|
|
1111
|
+
const sourcePlugins = registry(sourceRegistry);
|
|
1112
|
+
const ledger = readLedger(targetHome);
|
|
1113
|
+
const pending = Object.entries(sourcePlugins).flatMap(([id, installs]) => installs.filter(() => !Object.hasOwn(ledger.value.seen, id)).map((install) => ({ id, install, identity: identity(install) })));
|
|
1114
|
+
if (!pending.length) return { imported: 0, observed: 0 };
|
|
1115
|
+
noLinks(path2.join(sourceHome, "plugins"));
|
|
1116
|
+
const sourceRoot = fs2.realpathSync(path2.join(sourceHome, "plugins"));
|
|
1117
|
+
const targetRoot = path2.join(targetHome, "plugins");
|
|
1118
|
+
if (sourceRoot === path2.resolve(targetRoot) || contained(sourceRoot, path2.resolve(targetRoot)) || contained(path2.resolve(targetRoot), sourceRoot)) throw new Error("Plugin stores must not overlap");
|
|
1119
|
+
noLinks(targetRoot);
|
|
1120
|
+
const sourceSettings = readDocument(path2.join(sourceHome, "settings.json"));
|
|
1121
|
+
const sourceMarkets = readDocument(path2.join(sourceRoot, "known_marketplaces.json"));
|
|
1122
|
+
const targetRegistry = readDocument(path2.join(targetRoot, "installed_plugins.json"), { version: 2, plugins: {} });
|
|
1123
|
+
const targetPlugins = registry(targetRegistry);
|
|
1124
|
+
const targetSettings = readDocument(path2.join(targetHome, "settings.json"));
|
|
1125
|
+
const targetMarkets = readDocument(path2.join(targetRoot, "known_marketplaces.json"));
|
|
1126
|
+
const existingMarketplaces = new Set(Object.keys(targetMarkets.value));
|
|
1127
|
+
const sourceCatalogues = /* @__PURE__ */ new Map();
|
|
1128
|
+
const targetCatalogues = /* @__PURE__ */ new Map();
|
|
1129
|
+
const catalogueFiles = /* @__PURE__ */ new Set();
|
|
1130
|
+
const copies = [];
|
|
1131
|
+
function sourceCatalogue(location) {
|
|
1132
|
+
const file = fs2.realpathSync(path2.join(location, ".claude-plugin/marketplace.json"));
|
|
1133
|
+
if (!contained(sourceRoot, file)) throw new Error("Marketplace manifest escapes the official plugin store");
|
|
1134
|
+
rejectPrivateData(sourceRoot, file);
|
|
1135
|
+
const document = sourceCatalogues.get(file) ?? readDocument(file);
|
|
1136
|
+
if (!Array.isArray(document.value.plugins)) throw new Error("Invalid plugin marketplace catalogue");
|
|
1137
|
+
sourceCatalogues.set(file, document);
|
|
1138
|
+
return document;
|
|
1139
|
+
}
|
|
1140
|
+
function localCatalogueEntry(entry, from, to) {
|
|
1141
|
+
const local = typeof entry.source === "string" ? entry.source : entry.source && typeof entry.source === "object" && ["directory", "file"].includes(String(entry.source.source)) ? entry.source.path : void 0;
|
|
1142
|
+
if (local === void 0) return;
|
|
1143
|
+
if (typeof local !== "string") throw new Error("Invalid local marketplace plugin source");
|
|
1144
|
+
const original = path2.resolve(from, local);
|
|
1145
|
+
const destination = path2.isAbsolute(local) ? relocated(local, sourceRoot, targetRoot).target : path2.resolve(to, local);
|
|
1146
|
+
if (!contained(sourceRoot, original) || !contained(targetRoot, destination)) throw new Error("Local marketplace source escapes its plugin store");
|
|
1147
|
+
rejectPrivateData(targetRoot, destination);
|
|
1148
|
+
planCopy(original, destination, sourceRoot, copies, catalogueFiles);
|
|
1149
|
+
if (path2.isAbsolute(local)) {
|
|
1150
|
+
if (typeof entry.source === "string") entry.source = destination;
|
|
1151
|
+
else entry.source.path = destination;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
let imported = 0;
|
|
1155
|
+
const visitedIds = /* @__PURE__ */ new Set();
|
|
1156
|
+
for (const { id, install, identity: key } of pending) {
|
|
1157
|
+
if (!targetPlugins[id]?.some((existing) => same(identity(existing), key))) {
|
|
1158
|
+
const location = relocated(install.installPath, sourceRoot, targetRoot);
|
|
1159
|
+
planCopy(location.source, location.target, sourceRoot, copies);
|
|
1160
|
+
(targetPlugins[id] ??= []).push({ ...install, installPath: location.target });
|
|
1161
|
+
imported += 1;
|
|
1162
|
+
}
|
|
1163
|
+
if (!visitedIds.has(id)) {
|
|
1164
|
+
visitedIds.add(id);
|
|
1165
|
+
const marketplace = id.split("@")[1];
|
|
1166
|
+
if (!Object.hasOwn(sourceMarkets.value, marketplace) && !Object.hasOwn(targetMarkets.value, marketplace)) {
|
|
1167
|
+
throw new Error(`Plugin is missing its marketplace registration: ${id}`);
|
|
1168
|
+
}
|
|
1169
|
+
if (Object.hasOwn(sourceMarkets.value, marketplace) && !Object.hasOwn(targetMarkets.value, marketplace)) {
|
|
1170
|
+
const entry = structuredClone(object(sourceMarkets.value[marketplace], "marketplace"));
|
|
1171
|
+
const location = relocated(entry.installLocation, sourceRoot, targetRoot);
|
|
1172
|
+
const catalogue = sourceCatalogue(location.source);
|
|
1173
|
+
const file = path2.join(location.target, ".claude-plugin/marketplace.json");
|
|
1174
|
+
const destination = readDocument(file);
|
|
1175
|
+
const existingCatalogue = destination.value;
|
|
1176
|
+
destination.value = structuredClone(catalogue.value);
|
|
1177
|
+
targetCatalogues.set(file, destination);
|
|
1178
|
+
catalogueFiles.add(file);
|
|
1179
|
+
for (const item of destination.value.plugins) {
|
|
1180
|
+
const plugin = object(item, "catalogue plugin");
|
|
1181
|
+
localCatalogueEntry(plugin, location.source, location.target);
|
|
1182
|
+
}
|
|
1183
|
+
if (destination.before !== void 0 && JSON.stringify(existingCatalogue) !== JSON.stringify(destination.value)) {
|
|
1184
|
+
throw new Error("Existing CCEM marketplace catalogue differs; keeping the CCEM copy");
|
|
1185
|
+
}
|
|
1186
|
+
for (const newId of pending.filter((item) => item.id.split("@")[1] === marketplace).map((item) => item.id)) {
|
|
1187
|
+
if (!destination.value.plugins.some((item) => item.name === newId.split("@")[0])) {
|
|
1188
|
+
throw new Error(`Plugin is missing from its marketplace catalogue: ${newId}`);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
planCopy(location.source, location.target, sourceRoot, copies, catalogueFiles);
|
|
1192
|
+
entry.installLocation = location.target;
|
|
1193
|
+
if (entry.source && typeof entry.source === "object" && ["directory", "file"].includes(String(entry.source.source)) && "path" in entry.source) {
|
|
1194
|
+
const local = relocated(entry.source.path, sourceRoot, targetRoot);
|
|
1195
|
+
planCopy(local.source, local.target, sourceRoot, copies, catalogueFiles);
|
|
1196
|
+
entry.source.path = local.target;
|
|
1197
|
+
}
|
|
1198
|
+
targetMarkets.value[marketplace] = entry;
|
|
1199
|
+
}
|
|
1200
|
+
if (existingMarketplaces.has(marketplace) && Object.hasOwn(sourceMarkets.value, marketplace)) {
|
|
1201
|
+
const from = relocated(object(sourceMarkets.value[marketplace], "marketplace").installLocation, sourceRoot, targetRoot);
|
|
1202
|
+
const to = relocated(object(targetMarkets.value[marketplace], "marketplace").installLocation, targetRoot, targetRoot);
|
|
1203
|
+
const targetFile = path2.join(to.target, ".claude-plugin/marketplace.json");
|
|
1204
|
+
const officialCatalogue = sourceCatalogue(from.source);
|
|
1205
|
+
const targetCatalogue = targetCatalogues.get(targetFile) ?? readDocument(targetFile);
|
|
1206
|
+
targetCatalogues.set(targetFile, targetCatalogue);
|
|
1207
|
+
catalogueFiles.add(targetFile);
|
|
1208
|
+
if (!Array.isArray(officialCatalogue.value.plugins) || !Array.isArray(targetCatalogue.value.plugins)) {
|
|
1209
|
+
throw new Error("Invalid plugin marketplace catalogue");
|
|
1210
|
+
}
|
|
1211
|
+
const name = id.split("@")[0];
|
|
1212
|
+
if (!targetCatalogue.value.plugins.some((entry) => object(entry, "catalogue plugin").name === name)) {
|
|
1213
|
+
const entry = officialCatalogue.value.plugins.find((entry2) => object(entry2, "catalogue plugin").name === name);
|
|
1214
|
+
if (!entry) throw new Error(`Plugin is missing from its marketplace catalogue: ${id}`);
|
|
1215
|
+
const importedEntry = structuredClone(object(entry, "catalogue plugin"));
|
|
1216
|
+
localCatalogueEntry(importedEntry, from.source, to.target);
|
|
1217
|
+
targetCatalogue.value.plugins.push(importedEntry);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
for (const [field, entryKey] of [["enabledPlugins", id], ["extraKnownMarketplaces", marketplace]]) {
|
|
1221
|
+
if (field === "enabledPlugins" && !pending.some((item) => item.id === id && item.identity.scope === "user")) continue;
|
|
1222
|
+
const from = sourceSettings.value[field] === void 0 ? {} : object(sourceSettings.value[field], field);
|
|
1223
|
+
const to = targetSettings.value[field] === void 0 ? {} : object(targetSettings.value[field], field);
|
|
1224
|
+
if (Object.hasOwn(from, entryKey) && !Object.hasOwn(to, entryKey)) {
|
|
1225
|
+
const value = structuredClone(from[entryKey]);
|
|
1226
|
+
if (field === "enabledPlugins" && typeof value !== "boolean") throw new Error("Invalid plugin enablement");
|
|
1227
|
+
if (field === "extraKnownMarketplaces") {
|
|
1228
|
+
const extra = object(value, field);
|
|
1229
|
+
if (extra.source && typeof extra.source === "object" && ["directory", "file"].includes(String(extra.source.source)) && "path" in extra.source) {
|
|
1230
|
+
const local = relocated(extra.source.path, sourceRoot, targetRoot);
|
|
1231
|
+
planCopy(local.source, local.target, sourceRoot, copies, catalogueFiles);
|
|
1232
|
+
extra.source.path = local.target;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
to[entryKey] = value;
|
|
1236
|
+
targetSettings.value[field] = to;
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
(ledger.value.seen[id] ??= []).push(key);
|
|
1241
|
+
}
|
|
1242
|
+
const sources = [sourceRegistry, sourceSettings, sourceMarkets, ...sourceCatalogues.values()];
|
|
1243
|
+
const targets = [...targetCatalogues.values(), targetMarkets, targetRegistry, targetSettings, ledger];
|
|
1244
|
+
for (const document of [...sources, ...targets]) unchanged(document);
|
|
1245
|
+
for (const copy of copies) if (!catalogueFiles.has(copy.target)) publishCopy(copy);
|
|
1246
|
+
for (const document of [...sources, ...targets]) unchanged(document);
|
|
1247
|
+
for (const document of targets) {
|
|
1248
|
+
for (const observed of [...sources, ...targets]) unchanged(observed);
|
|
1249
|
+
if (document.before === void 0 && Object.keys(document.value).length === 0) continue;
|
|
1250
|
+
publishDocument(document, targetHome);
|
|
1251
|
+
}
|
|
1252
|
+
return { imported, observed: pending.length };
|
|
1253
|
+
}
|
|
1254
|
+
var CLAUDE_PLUGIN_LINK_LEDGER = ".ccem-plugin-links-v1.json";
|
|
1255
|
+
var MARKER = ".ccem-plugin-link-v1.json";
|
|
1256
|
+
var BACKUP = ".ccem-plugin-links-backup-v1";
|
|
1257
|
+
var IGNORED = /* @__PURE__ */ new Set([".git", ".in_use", ".orphaned_at", MARKER]);
|
|
1258
|
+
function absolute(value) {
|
|
1259
|
+
return typeof value === "string" && path3.isAbsolute(value) && !value.split(/[\\/]/).includes("..");
|
|
1260
|
+
}
|
|
1261
|
+
function readLinks(target) {
|
|
1262
|
+
const document = readDocument(path3.join(target, CLAUDE_PLUGIN_LINK_LEDGER), { version: 1, plugins: {} });
|
|
1263
|
+
if (document.value.version !== 1 || Object.keys(document.value).some((key) => !["version", "plugins"].includes(key))) {
|
|
1264
|
+
throw new Error("Unsupported plugin links ledger");
|
|
1265
|
+
}
|
|
1266
|
+
for (const [id, rows] of Object.entries(object(document.value.plugins, "plugin links ledger"))) {
|
|
1267
|
+
pluginId(id);
|
|
1268
|
+
if (!Array.isArray(rows) || !rows.length) throw new Error("Invalid plugin link identities");
|
|
1269
|
+
const seen = [];
|
|
1270
|
+
for (const entry of rows) {
|
|
1271
|
+
const row = object(entry, "plugin link identity");
|
|
1272
|
+
const key = identity(row);
|
|
1273
|
+
const fields = row.local === true ? ["scope", "projectPath", "local"] : ["scope", "projectPath", "sourcePath", "installPath", "version"];
|
|
1274
|
+
if (!Object.hasOwn(row, "projectPath") || Object.keys(row).some((field) => !fields.includes(field)) || seen.some((old) => same(old, key))) throw new Error("Invalid plugin link identity");
|
|
1275
|
+
if (row.local !== true && (!absolute(row.sourcePath) || !absolute(row.installPath) || typeof row.version !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._+-]*$/.test(row.version))) {
|
|
1276
|
+
throw new Error("Invalid managed plugin link");
|
|
1277
|
+
}
|
|
1278
|
+
if (row.local !== true) {
|
|
1279
|
+
const [name, market] = id.split("@");
|
|
1280
|
+
const suffix = `.ccem-linked-${createHash("sha256").update(row.sourcePath).digest("hex").slice(0, 8)}`;
|
|
1281
|
+
if (!row.version.endsWith(suffix) || row.installPath !== path3.resolve(target, "plugins/cache", market, name, row.version)) {
|
|
1282
|
+
throw new Error("Managed plugin link escapes its CCEM cache");
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
seen.push(key);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
return document;
|
|
1289
|
+
}
|
|
1290
|
+
function children(root) {
|
|
1291
|
+
return fs3.readdirSync(root).filter((name) => !IGNORED.has(name)).sort();
|
|
1292
|
+
}
|
|
1293
|
+
function validateCode(file, store, protectedCatalogues, ancestors = /* @__PURE__ */ new Set()) {
|
|
1294
|
+
const resolved = fs3.realpathSync(file);
|
|
1295
|
+
if (!contained(store, resolved)) throw new Error("Linked plugin code escapes the official plugin store");
|
|
1296
|
+
rejectPrivateData(store, resolved);
|
|
1297
|
+
const parts = path3.relative(store, resolved).split(path3.sep);
|
|
1298
|
+
if (parts.length < 2 || protectedCatalogues.has(resolved) || parts.some((part) => [".in_use", ".orphaned_at", MARKER].includes(part))) {
|
|
1299
|
+
throw new Error("Linked plugin code cannot expose official plugin metadata or runtime markers");
|
|
1300
|
+
}
|
|
1301
|
+
if (ancestors.has(resolved)) throw new Error("Linked plugin code has a symlink cycle");
|
|
1302
|
+
const info = fs3.statSync(resolved);
|
|
1303
|
+
if (info.isDirectory()) {
|
|
1304
|
+
const next = new Set(ancestors).add(resolved);
|
|
1305
|
+
const names = ancestors.size === 0 ? children(resolved) : fs3.readdirSync(resolved).sort();
|
|
1306
|
+
for (const name of names) validateCode(path3.join(resolved, name), store, protectedCatalogues, next);
|
|
1307
|
+
} else if (!info.isFile()) throw new Error("Linked plugin code is not a regular file or directory");
|
|
1308
|
+
}
|
|
1309
|
+
function equalCopy(source, target) {
|
|
1310
|
+
noLinks(target);
|
|
1311
|
+
const from = fs3.statSync(source);
|
|
1312
|
+
const to = stat(target);
|
|
1313
|
+
if (!to || from.isDirectory() !== to.isDirectory() || from.isFile() !== to.isFile()) return false;
|
|
1314
|
+
if (from.isFile()) return fs3.readFileSync(source).equals(fs3.readFileSync(target)) && (from.mode & 73) === (to.mode & 73);
|
|
1315
|
+
const names = children(source);
|
|
1316
|
+
const local = children(target);
|
|
1317
|
+
return JSON.stringify(names) === JSON.stringify(local) && names.every((name) => equalCopy(path3.join(source, name), path3.join(target, name)));
|
|
1318
|
+
}
|
|
1319
|
+
function rootMarker(target, source) {
|
|
1320
|
+
noLinks(target);
|
|
1321
|
+
const marker = readDocument(path3.join(target, MARKER));
|
|
1322
|
+
if (stat(target) && (!stat(target)?.isDirectory() || marker.value.version !== 1 || marker.value.source !== source || Object.keys(marker.value).some((key) => !["version", "source"].includes(key)))) {
|
|
1323
|
+
throw new Error("Existing plugin link root is not managed by CCEM");
|
|
1324
|
+
}
|
|
1325
|
+
return marker;
|
|
1326
|
+
}
|
|
1327
|
+
function recoverPublished(row, key, id, sourceRoot, targetRoot) {
|
|
1328
|
+
const [name, market] = id.split("@");
|
|
1329
|
+
if (typeof row.version !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._+-]*$/.test(row.version) || row.installPath !== path3.join(targetRoot, "cache", market, name, row.version) || !stat(row.installPath)) return;
|
|
1330
|
+
const marker = readDocument(path3.join(row.installPath, MARKER));
|
|
1331
|
+
if (marker.value.version !== 1 || !absolute(marker.value.source) || !contained(sourceRoot, marker.value.source)) return;
|
|
1332
|
+
rejectPrivateData(sourceRoot, marker.value.source);
|
|
1333
|
+
const suffix = `.ccem-linked-${createHash("sha256").update(marker.value.source).digest("hex").slice(0, 8)}`;
|
|
1334
|
+
if (!row.version.endsWith(suffix) || row.version.length === suffix.length) return;
|
|
1335
|
+
rootMarker(row.installPath, marker.value.source);
|
|
1336
|
+
return { ...key, sourcePath: marker.value.source, installPath: row.installPath, version: row.version };
|
|
1337
|
+
}
|
|
1338
|
+
function planRoot(source, target) {
|
|
1339
|
+
const marker = rootMarker(target, source);
|
|
1340
|
+
let changed2 = marker.before === void 0;
|
|
1341
|
+
const wanted = new Set(children(source));
|
|
1342
|
+
if (stat(target)) for (const name of children(target)) {
|
|
1343
|
+
const child = path3.join(target, name);
|
|
1344
|
+
if (!stat(child)?.isSymbolicLink() || fs3.readlinkSync(child) !== path3.join(source, name)) {
|
|
1345
|
+
throw new Error("CCEM plugin code was changed locally; keeping it");
|
|
1346
|
+
}
|
|
1347
|
+
if (!wanted.has(name)) changed2 = true;
|
|
1348
|
+
}
|
|
1349
|
+
for (const name of wanted) if (!stat(path3.join(target, name))) changed2 = true;
|
|
1350
|
+
return { source, target, changed: changed2 };
|
|
1351
|
+
}
|
|
1352
|
+
function publishRoot(root) {
|
|
1353
|
+
if (!root.changed) return;
|
|
1354
|
+
planRoot(root.source, root.target);
|
|
1355
|
+
const fresh = !stat(root.target);
|
|
1356
|
+
const directory = fresh ? `${root.target}.ccem-${randomUUID2()}.tmp` : root.target;
|
|
1357
|
+
privateDirectory(directory);
|
|
1358
|
+
try {
|
|
1359
|
+
if (fresh) fs3.writeFileSync(path3.join(directory, MARKER), `${JSON.stringify({ version: 1, source: root.source })}
|
|
1360
|
+
`, { flag: "wx", mode: 384 });
|
|
1361
|
+
const wanted = new Set(children(root.source));
|
|
1362
|
+
for (const name of children(directory)) if (!wanted.has(name)) {
|
|
1363
|
+
const child = path3.join(directory, name);
|
|
1364
|
+
if (!stat(child)?.isSymbolicLink() || fs3.readlinkSync(child) !== path3.join(root.source, name)) throw new Error("Plugin link changed during preparation");
|
|
1365
|
+
fs3.unlinkSync(child);
|
|
1366
|
+
}
|
|
1367
|
+
for (const name of wanted) {
|
|
1368
|
+
const child = path3.join(directory, name);
|
|
1369
|
+
if (stat(child)) continue;
|
|
1370
|
+
const original = path3.join(root.source, name);
|
|
1371
|
+
fs3.symlinkSync(original, child, fs3.statSync(original).isDirectory() ? "dir" : "file");
|
|
1372
|
+
}
|
|
1373
|
+
if (fresh) {
|
|
1374
|
+
noLinks(root.target);
|
|
1375
|
+
if (stat(root.target)) throw new Error("Plugin link root changed during preparation");
|
|
1376
|
+
fs3.renameSync(directory, root.target);
|
|
1377
|
+
}
|
|
1378
|
+
} finally {
|
|
1379
|
+
if (fresh) fs3.rmSync(directory, { recursive: true, force: true });
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
function changed(document) {
|
|
1383
|
+
return document.before === void 0 ? Object.keys(document.value).length > 0 : JSON.stringify(JSON.parse(document.before)) !== JSON.stringify(document.value);
|
|
1384
|
+
}
|
|
1385
|
+
function planLinks(sourceHome, targetHome) {
|
|
1386
|
+
const imports = readLedger(targetHome);
|
|
1387
|
+
if (!Object.keys(imports.value.seen).length) return { documents: [], targets: [], roots: [], changed: false };
|
|
1388
|
+
const sourceRegistry = readSource(sourceHome);
|
|
1389
|
+
const sourcePlugins = registry(sourceRegistry);
|
|
1390
|
+
const targetRegistry = readSource(targetHome);
|
|
1391
|
+
const targetPlugins = registry(targetRegistry);
|
|
1392
|
+
const ledger = readLinks(targetHome);
|
|
1393
|
+
const sourceRoot = fs3.realpathSync(path3.join(sourceHome, "plugins"));
|
|
1394
|
+
noLinks(path3.join(sourceHome, "plugins"));
|
|
1395
|
+
const targetRoot = path3.resolve(targetHome, "plugins");
|
|
1396
|
+
noLinks(targetRoot);
|
|
1397
|
+
if (sourceRoot === targetRoot || contained(sourceRoot, targetRoot) || contained(targetRoot, sourceRoot)) throw new Error("Plugin stores must not overlap");
|
|
1398
|
+
for (const choices of Object.values(ledger.value.plugins)) for (const choice of choices) if (!("local" in choice)) {
|
|
1399
|
+
if (!contained(sourceRoot, choice.sourcePath)) throw new Error("Managed plugin source escapes the official store");
|
|
1400
|
+
rejectPrivateData(sourceRoot, choice.sourcePath);
|
|
1401
|
+
}
|
|
1402
|
+
const sourceMarkets = readDocument(path3.join(sourceRoot, "known_marketplaces.json"));
|
|
1403
|
+
const targetMarkets = readDocument(path3.join(targetRoot, "known_marketplaces.json"));
|
|
1404
|
+
const protectedCatalogues = /* @__PURE__ */ new Set();
|
|
1405
|
+
for (const market of Object.values(sourceMarkets.value)) {
|
|
1406
|
+
const location = market && typeof market === "object" ? market.installLocation : void 0;
|
|
1407
|
+
if (absolute(location) && contained(sourceRoot, location)) {
|
|
1408
|
+
const file = path3.join(location, ".claude-plugin/marketplace.json");
|
|
1409
|
+
if (fs3.existsSync(file)) protectedCatalogues.add(fs3.realpathSync(file));
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
const documents = [imports, sourceRegistry, targetRegistry, ledger, sourceMarkets, targetMarkets];
|
|
1413
|
+
const catalogues = /* @__PURE__ */ new Map();
|
|
1414
|
+
const roots = /* @__PURE__ */ new Map();
|
|
1415
|
+
function catalogue(markets, market, store, mutable) {
|
|
1416
|
+
if (!Object.hasOwn(markets.value, market)) return void 0;
|
|
1417
|
+
const location = relocated(object(markets.value[market], "marketplace").installLocation, store, store).source;
|
|
1418
|
+
const file = path3.join(location, ".claude-plugin/marketplace.json");
|
|
1419
|
+
const document = catalogues.get(file) ?? readDocument(file);
|
|
1420
|
+
if (!Array.isArray(document.value.plugins)) throw new Error("Invalid marketplace catalogue");
|
|
1421
|
+
if (!catalogues.has(file)) {
|
|
1422
|
+
documents.push(document);
|
|
1423
|
+
if (mutable) catalogues.set(file, document);
|
|
1424
|
+
}
|
|
1425
|
+
return { document, location };
|
|
1426
|
+
}
|
|
1427
|
+
for (const [id, identities] of Object.entries(imports.value.seen)) {
|
|
1428
|
+
const choices = ledger.value.plugins[id] ??= [];
|
|
1429
|
+
for (const key of identities) {
|
|
1430
|
+
let index = choices.findIndex((choice) => same(choice, key));
|
|
1431
|
+
let old = index < 0 ? void 0 : choices[index];
|
|
1432
|
+
if (old && "local" in old) continue;
|
|
1433
|
+
const local = targetPlugins[id]?.find((row) => same(identity(row), key));
|
|
1434
|
+
const detach = () => {
|
|
1435
|
+
if (index < 0) {
|
|
1436
|
+
index = choices.length;
|
|
1437
|
+
choices.push({ ...key, local: true });
|
|
1438
|
+
} else choices[index] = { ...key, local: true };
|
|
1439
|
+
};
|
|
1440
|
+
if (!local) {
|
|
1441
|
+
detach();
|
|
1442
|
+
continue;
|
|
1443
|
+
}
|
|
1444
|
+
if (!old || local.installPath !== old.installPath || local.version !== old.version) {
|
|
1445
|
+
const recovered = recoverPublished(local, key, id, sourceRoot, targetRoot);
|
|
1446
|
+
if (recovered) {
|
|
1447
|
+
old = recovered;
|
|
1448
|
+
if (index < 0) {
|
|
1449
|
+
index = choices.length;
|
|
1450
|
+
choices.push(recovered);
|
|
1451
|
+
} else choices[index] = recovered;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
const registryMoved = old && (local.installPath !== old.installPath || local.version !== old.version);
|
|
1455
|
+
const official = sourcePlugins[id]?.find((row) => same(identity(row), key));
|
|
1456
|
+
if (!official) {
|
|
1457
|
+
if (registryMoved) detach();
|
|
1458
|
+
continue;
|
|
1459
|
+
}
|
|
1460
|
+
const original = relocated(official.installPath, sourceRoot, targetRoot);
|
|
1461
|
+
const [name, market] = id.split("@");
|
|
1462
|
+
const fromCatalogue = catalogue(sourceMarkets, market, sourceRoot, false);
|
|
1463
|
+
const toCatalogue = catalogue(targetMarkets, market, targetRoot, true);
|
|
1464
|
+
const fromEntry = fromCatalogue?.document.value.plugins?.find((entry) => entry.name === name);
|
|
1465
|
+
const toEntry = toCatalogue?.document.value.plugins?.find((entry) => entry.name === name);
|
|
1466
|
+
const entrySource = fromEntry?.source;
|
|
1467
|
+
const localSource = typeof entrySource === "string" ? entrySource : entrySource && typeof entrySource === "object" && ["directory", "file"].includes(String(entrySource.source)) ? entrySource.path : void 0;
|
|
1468
|
+
let code = original.source;
|
|
1469
|
+
let legacyCode = original.target;
|
|
1470
|
+
let expectedCatalogueSource;
|
|
1471
|
+
let actualCatalogueSource;
|
|
1472
|
+
if (localSource !== void 0) {
|
|
1473
|
+
if (typeof localSource !== "string" || !fromCatalogue || !toCatalogue || !toEntry) throw new Error("Invalid local plugin catalogue source");
|
|
1474
|
+
code = path3.resolve(fromCatalogue.location, localSource);
|
|
1475
|
+
if (!contained(sourceRoot, code)) throw new Error("Local plugin source escapes the official store");
|
|
1476
|
+
legacyCode = path3.isAbsolute(localSource) ? relocated(localSource, sourceRoot, targetRoot).target : path3.resolve(toCatalogue.location, localSource);
|
|
1477
|
+
if (!contained(targetRoot, legacyCode)) throw new Error("Local plugin destination escapes its store");
|
|
1478
|
+
expectedCatalogueSource = old ? old.installPath : path3.isAbsolute(localSource) ? legacyCode : localSource;
|
|
1479
|
+
actualCatalogueSource = typeof toEntry.source === "string" ? toEntry.source : object(toEntry.source, "local catalogue source").path;
|
|
1480
|
+
}
|
|
1481
|
+
if (!fs3.existsSync(code)) {
|
|
1482
|
+
if (registryMoved) detach();
|
|
1483
|
+
continue;
|
|
1484
|
+
}
|
|
1485
|
+
code = fs3.realpathSync(code);
|
|
1486
|
+
validateCode(code, sourceRoot, protectedCatalogues);
|
|
1487
|
+
const sourceVersion = typeof official.version === "string" ? official.version : path3.basename(original.source);
|
|
1488
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._+-]*$/.test(sourceVersion)) throw new Error("Invalid plugin version");
|
|
1489
|
+
const version = `${sourceVersion}.ccem-linked-${createHash("sha256").update(code).digest("hex").slice(0, 8)}`;
|
|
1490
|
+
const destination = path3.join(targetRoot, "cache", market, name, version);
|
|
1491
|
+
if (registryMoved) {
|
|
1492
|
+
if (local.installPath === destination && local.version === version && stat(destination)) rootMarker(destination, code);
|
|
1493
|
+
else {
|
|
1494
|
+
detach();
|
|
1495
|
+
continue;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
if (old && !registryMoved) {
|
|
1499
|
+
rootMarker(old.installPath, old.sourcePath);
|
|
1500
|
+
if (!stat(old.installPath) || children(old.installPath).some((name2) => {
|
|
1501
|
+
const child = path3.join(old.installPath, name2);
|
|
1502
|
+
return !stat(child)?.isSymbolicLink() || fs3.readlinkSync(child) !== path3.join(old.sourcePath, name2);
|
|
1503
|
+
})) {
|
|
1504
|
+
detach();
|
|
1505
|
+
continue;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
if (localSource !== void 0 && actualCatalogueSource !== expectedCatalogueSource) {
|
|
1509
|
+
const recovered = typeof actualCatalogueSource === "string" ? recoverPublished({
|
|
1510
|
+
installPath: actualCatalogueSource,
|
|
1511
|
+
version: path3.basename(actualCatalogueSource)
|
|
1512
|
+
}, key, id, sourceRoot, targetRoot) : void 0;
|
|
1513
|
+
if (!recovered) {
|
|
1514
|
+
detach();
|
|
1515
|
+
continue;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
if (!old) {
|
|
1519
|
+
const recovering = local.installPath === destination && local.version === version && stat(destination);
|
|
1520
|
+
if (recovering) rootMarker(destination, code);
|
|
1521
|
+
else {
|
|
1522
|
+
validateCode(original.source, sourceRoot, protectedCatalogues);
|
|
1523
|
+
if (local.installPath !== original.target || local.version !== official.version || !equalCopy(original.source, original.target) || !equalCopy(code, legacyCode)) {
|
|
1524
|
+
detach();
|
|
1525
|
+
continue;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
roots.set(destination, planRoot(code, destination));
|
|
1530
|
+
if (localSource !== void 0 && toEntry) toEntry.source = destination;
|
|
1531
|
+
local.installPath = destination;
|
|
1532
|
+
local.version = version;
|
|
1533
|
+
const next = { ...key, sourcePath: code, installPath: destination, version };
|
|
1534
|
+
if (index < 0) choices.push(next);
|
|
1535
|
+
else choices[index] = next;
|
|
1536
|
+
}
|
|
1537
|
+
if (!choices.length) delete ledger.value.plugins[id];
|
|
1538
|
+
}
|
|
1539
|
+
const targets = [...catalogues.values(), targetRegistry, ledger];
|
|
1540
|
+
return { documents, targets, roots: [...roots.values()], changed: targets.some(changed) || [...roots.values()].some((root) => root.changed) };
|
|
1541
|
+
}
|
|
1542
|
+
function claudePluginLinksPending(sourceHome, targetHome) {
|
|
1543
|
+
return planLinks(sourceHome, targetHome).changed;
|
|
1544
|
+
}
|
|
1545
|
+
function linkClaudePlugins(sourceHome, targetHome) {
|
|
1546
|
+
const plan = planLinks(sourceHome, targetHome);
|
|
1547
|
+
if (!plan.changed) return;
|
|
1548
|
+
for (const document of plan.documents) unchanged(document);
|
|
1549
|
+
for (const root of plan.roots) publishRoot(root);
|
|
1550
|
+
for (const document of plan.targets) {
|
|
1551
|
+
for (const observed of plan.documents) unchanged(observed);
|
|
1552
|
+
publishDocument(document, targetHome, BACKUP);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
893
1555
|
var AGENT_MIGRATION_MARKER = ".ccem-migration-v1.json";
|
|
894
1556
|
var MIGRATION_LOCK = ".ccem-migration.lock";
|
|
895
1557
|
var PROFILES_FILE = "profiles.json";
|
|
@@ -911,6 +1573,8 @@ var IDENTITY_ENV_KEYS = [
|
|
|
911
1573
|
"CLAUDE_CODE_DESIGN_OAUTH_CLIENT_ID",
|
|
912
1574
|
"CLAUDE_CODE_REMOTE_SETTINGS_PATH",
|
|
913
1575
|
"CLAUDE_CODE_MOCK_REMOTE_SETTINGS",
|
|
1576
|
+
"CLAUDE_CODE_PLUGIN_SEED_DIR",
|
|
1577
|
+
"CLAUDE_CODE_PLUGIN_USE_ZIP_CACHE",
|
|
914
1578
|
"USE_LOCAL_OAUTH",
|
|
915
1579
|
"USE_STAGING_OAUTH",
|
|
916
1580
|
"CLAUDE_LOCAL_OAUTH_API_BASE",
|
|
@@ -952,6 +1616,7 @@ var INHERITED_AGENT_ENV_KEYS = [
|
|
|
952
1616
|
"CLAUDE_CODE_API_KEY_HELPER_TTL_MS",
|
|
953
1617
|
"CLAUDE_CONFIG_DIR",
|
|
954
1618
|
"CLAUDE_SECURESTORAGE_CONFIG_DIR",
|
|
1619
|
+
"CLAUDE_CODE_PLUGIN_CACHE_DIR",
|
|
955
1620
|
"OPENAI_API_KEY",
|
|
956
1621
|
"OPENAI_BASE_URL",
|
|
957
1622
|
"CODEX_API_KEY",
|
|
@@ -977,18 +1642,18 @@ function userHome(env) {
|
|
|
977
1642
|
}
|
|
978
1643
|
function getCcemAgentBase(env = process.env) {
|
|
979
1644
|
const override = env.CCEM_AGENT_HOME?.trim();
|
|
980
|
-
if (override && (!
|
|
1645
|
+
if (override && (!path4.isAbsolute(override) || override.split(/[\\/]/).includes(".."))) {
|
|
981
1646
|
throw new Error("CCEM_AGENT_HOME must be an absolute path without '..'");
|
|
982
1647
|
}
|
|
983
|
-
return
|
|
1648
|
+
return path4.resolve(override || path4.join(userHome(env), ".ccem", "agents"));
|
|
984
1649
|
}
|
|
985
1650
|
function readCodexIsolation(env) {
|
|
986
1651
|
if (env.CCEM_CODEX_ISOLATED === "1") return true;
|
|
987
1652
|
if (env.CCEM_CODEX_ISOLATED === "0") return false;
|
|
988
|
-
const file =
|
|
1653
|
+
const file = path4.join(getCcemAgentBase(env), PROFILES_FILE);
|
|
989
1654
|
let raw;
|
|
990
1655
|
try {
|
|
991
|
-
raw =
|
|
1656
|
+
raw = fs4.readFileSync(file, "utf8");
|
|
992
1657
|
} catch (error) {
|
|
993
1658
|
if (error.code === "ENOENT") return false;
|
|
994
1659
|
throw new Error("Cannot read CCEM agent profile preferences");
|
|
@@ -1015,14 +1680,14 @@ function isCodexIsolated(env = process.env) {
|
|
|
1015
1680
|
}
|
|
1016
1681
|
}
|
|
1017
1682
|
function getCcemIsolatedAgentHome(provider, env = process.env) {
|
|
1018
|
-
return
|
|
1683
|
+
return path4.join(getCcemAgentBase(env), provider);
|
|
1019
1684
|
}
|
|
1020
1685
|
function getOfficialCodexHome(env) {
|
|
1021
1686
|
const override = env.CODEX_HOME?.trim();
|
|
1022
|
-
if (!override) return
|
|
1023
|
-
if (override === "~") return
|
|
1024
|
-
if (/^~[\\/]/.test(override)) return
|
|
1025
|
-
return
|
|
1687
|
+
if (!override) return path4.resolve(userHome(env), ".codex");
|
|
1688
|
+
if (override === "~") return path4.resolve(userHome(env));
|
|
1689
|
+
if (/^~[\\/]/.test(override)) return path4.resolve(userHome(env), override.slice(2));
|
|
1690
|
+
return path4.resolve(override);
|
|
1026
1691
|
}
|
|
1027
1692
|
function getCcemAgentHome(provider, env = process.env) {
|
|
1028
1693
|
return provider === "codex" && !isCodexIsolated(env) ? getOfficialCodexHome(env) : getCcemIsolatedAgentHome(provider, env);
|
|
@@ -1034,6 +1699,7 @@ function getCcemAgentEnv(env = process.env) {
|
|
|
1034
1699
|
return {
|
|
1035
1700
|
CLAUDE_CONFIG_DIR: claude,
|
|
1036
1701
|
CLAUDE_SECURESTORAGE_CONFIG_DIR: claude,
|
|
1702
|
+
CLAUDE_CODE_PLUGIN_CACHE_DIR: path4.join(claude, "plugins"),
|
|
1037
1703
|
CODEX_HOME: codex,
|
|
1038
1704
|
CCEM_CODEX_ISOLATED: isolated ? "1" : "0",
|
|
1039
1705
|
...isolated ? { CODEX_SQLITE_HOME: codex } : {}
|
|
@@ -1068,7 +1734,7 @@ function buildIsolatedAgentEnv(baseEnv = process.env, selectedEnv = {}) {
|
|
|
1068
1734
|
}
|
|
1069
1735
|
function statIfPresent(file) {
|
|
1070
1736
|
try {
|
|
1071
|
-
return
|
|
1737
|
+
return fs4.lstatSync(file);
|
|
1072
1738
|
} catch (error) {
|
|
1073
1739
|
if (error.code === "ENOENT") return void 0;
|
|
1074
1740
|
throw error;
|
|
@@ -1076,57 +1742,57 @@ function statIfPresent(file) {
|
|
|
1076
1742
|
}
|
|
1077
1743
|
function ensureRealDirectory(directory) {
|
|
1078
1744
|
validateNoSymlinks(directory);
|
|
1079
|
-
|
|
1080
|
-
const
|
|
1081
|
-
if (
|
|
1745
|
+
fs4.mkdirSync(directory, { recursive: true, mode: 448 });
|
|
1746
|
+
const stat22 = fs4.lstatSync(directory);
|
|
1747
|
+
if (stat22.isSymbolicLink() || !stat22.isDirectory()) {
|
|
1082
1748
|
throw new Error(`CCEM agent directory must be a real directory: ${directory}`);
|
|
1083
1749
|
}
|
|
1084
|
-
|
|
1750
|
+
fs4.chmodSync(directory, 448);
|
|
1085
1751
|
}
|
|
1086
1752
|
function validateNoSymlinks(file) {
|
|
1087
|
-
let current =
|
|
1088
|
-
for (const component of file.slice(current.length).split(
|
|
1089
|
-
current =
|
|
1090
|
-
const
|
|
1091
|
-
if (!
|
|
1092
|
-
if (
|
|
1753
|
+
let current = path4.parse(file).root;
|
|
1754
|
+
for (const component of file.slice(current.length).split(path4.sep).filter(Boolean)) {
|
|
1755
|
+
current = path4.join(current, component);
|
|
1756
|
+
const stat22 = statIfPresent(current);
|
|
1757
|
+
if (!stat22) break;
|
|
1758
|
+
if (stat22.isSymbolicLink()) throw new Error(`CCEM agent state cannot use a symlink: ${current}`);
|
|
1093
1759
|
}
|
|
1094
1760
|
}
|
|
1095
1761
|
function resolveExistingParent(file) {
|
|
1096
1762
|
const suffix = [];
|
|
1097
1763
|
let parent = file;
|
|
1098
1764
|
while (!statIfPresent(parent)) {
|
|
1099
|
-
suffix.unshift(
|
|
1100
|
-
parent =
|
|
1765
|
+
suffix.unshift(path4.basename(parent));
|
|
1766
|
+
parent = path4.dirname(parent);
|
|
1101
1767
|
}
|
|
1102
|
-
return
|
|
1768
|
+
return path4.join(fs4.realpathSync(parent), ...suffix);
|
|
1103
1769
|
}
|
|
1104
1770
|
function validateAgentBase(base, env) {
|
|
1105
1771
|
validateNoSymlinks(base);
|
|
1106
1772
|
const resolved = resolveExistingParent(base);
|
|
1107
1773
|
for (const name of [".claude", ".codex"]) {
|
|
1108
|
-
const official = resolveExistingParent(
|
|
1109
|
-
if (resolved === official || resolved.startsWith(`${official}${
|
|
1774
|
+
const official = resolveExistingParent(path4.join(userHome(env), name));
|
|
1775
|
+
if (resolved === official || resolved.startsWith(`${official}${path4.sep}`) || official.startsWith(`${resolved}${path4.sep}`)) {
|
|
1110
1776
|
throw new Error("CCEM agent state must not overlap an official Claude or Codex home");
|
|
1111
1777
|
}
|
|
1112
1778
|
}
|
|
1113
1779
|
}
|
|
1114
1780
|
function syncDirectory(directory) {
|
|
1115
1781
|
if (process.platform === "win32") return;
|
|
1116
|
-
const fd =
|
|
1782
|
+
const fd = fs4.openSync(directory, "r");
|
|
1117
1783
|
try {
|
|
1118
|
-
|
|
1784
|
+
fs4.fsyncSync(fd);
|
|
1119
1785
|
} finally {
|
|
1120
|
-
|
|
1786
|
+
fs4.closeSync(fd);
|
|
1121
1787
|
}
|
|
1122
1788
|
}
|
|
1123
1789
|
function migrationComplete(marker) {
|
|
1124
|
-
const
|
|
1125
|
-
if (!
|
|
1126
|
-
if (!
|
|
1790
|
+
const stat22 = statIfPresent(marker);
|
|
1791
|
+
if (!stat22) return false;
|
|
1792
|
+
if (!stat22.isFile() || stat22.isSymbolicLink()) throw new Error("CCEM agent migration marker is invalid");
|
|
1127
1793
|
let version;
|
|
1128
1794
|
try {
|
|
1129
|
-
version = JSON.parse(
|
|
1795
|
+
version = JSON.parse(fs4.readFileSync(marker, "utf8")).version;
|
|
1130
1796
|
} catch {
|
|
1131
1797
|
}
|
|
1132
1798
|
if (version !== 1) throw new Error("CCEM agent migration marker is invalid or unsupported");
|
|
@@ -1139,35 +1805,35 @@ function writeNewFile(file, contents) {
|
|
|
1139
1805
|
if (!existing.isFile()) throw new Error(`CCEM agent file conflicts with a directory: ${file}`);
|
|
1140
1806
|
return;
|
|
1141
1807
|
}
|
|
1142
|
-
const temporary =
|
|
1808
|
+
const temporary = path4.join(path4.dirname(file), `.ccem-copy-${randomUUID3()}.tmp`);
|
|
1143
1809
|
try {
|
|
1144
|
-
const fd =
|
|
1810
|
+
const fd = fs4.openSync(temporary, "wx", 384);
|
|
1145
1811
|
try {
|
|
1146
|
-
|
|
1147
|
-
|
|
1812
|
+
fs4.writeFileSync(fd, contents);
|
|
1813
|
+
fs4.fsyncSync(fd);
|
|
1148
1814
|
} finally {
|
|
1149
|
-
|
|
1815
|
+
fs4.closeSync(fd);
|
|
1150
1816
|
}
|
|
1151
1817
|
try {
|
|
1152
|
-
|
|
1818
|
+
fs4.linkSync(temporary, file);
|
|
1153
1819
|
} catch (error) {
|
|
1154
1820
|
if (error.code !== "EEXIST") throw error;
|
|
1155
1821
|
}
|
|
1156
1822
|
} finally {
|
|
1157
|
-
|
|
1823
|
+
fs4.rmSync(temporary, { force: true });
|
|
1158
1824
|
}
|
|
1159
1825
|
}
|
|
1160
1826
|
function copyLegacyEntry(source, destination) {
|
|
1161
1827
|
const sourceStat = statIfPresent(source);
|
|
1162
1828
|
if (!sourceStat || sourceStat.isSymbolicLink()) return;
|
|
1163
|
-
if (sourceStat.isFile() && /\.(?:sqlite|sqlite3|db)(?:-(?:wal|shm))?$/i.test(
|
|
1829
|
+
if (sourceStat.isFile() && /\.(?:sqlite|sqlite3|db)(?:-(?:wal|shm))?$/i.test(path4.basename(source))) return;
|
|
1164
1830
|
validateNoSymlinks(destination);
|
|
1165
1831
|
const destinationStat = statIfPresent(destination);
|
|
1166
1832
|
if (sourceStat.isDirectory()) {
|
|
1167
1833
|
if (destinationStat && !destinationStat.isDirectory()) throw new Error(`CCEM agent directory conflicts with a file: ${destination}`);
|
|
1168
1834
|
ensureRealDirectory(destination);
|
|
1169
|
-
for (const name of
|
|
1170
|
-
copyLegacyEntry(
|
|
1835
|
+
for (const name of fs4.readdirSync(source)) {
|
|
1836
|
+
copyLegacyEntry(path4.join(source, name), path4.join(destination, name));
|
|
1171
1837
|
}
|
|
1172
1838
|
syncDirectory(destination);
|
|
1173
1839
|
return;
|
|
@@ -1177,63 +1843,63 @@ function copyLegacyEntry(source, destination) {
|
|
|
1177
1843
|
if (!destinationStat.isFile()) throw new Error(`CCEM agent file conflicts with a directory: ${destination}`);
|
|
1178
1844
|
return;
|
|
1179
1845
|
}
|
|
1180
|
-
const temporary =
|
|
1846
|
+
const temporary = path4.join(path4.dirname(destination), `.ccem-copy-${randomUUID3()}.tmp`);
|
|
1181
1847
|
let sourceFd;
|
|
1182
1848
|
let destinationFd;
|
|
1183
1849
|
try {
|
|
1184
|
-
sourceFd =
|
|
1185
|
-
const openedStat =
|
|
1850
|
+
sourceFd = fs4.openSync(source, fs4.constants.O_RDONLY | (fs4.constants.O_NOFOLLOW ?? 0));
|
|
1851
|
+
const openedStat = fs4.fstatSync(sourceFd);
|
|
1186
1852
|
if (!openedStat.isFile()) throw new Error("Legacy agent history changed during migration");
|
|
1187
|
-
destinationFd =
|
|
1853
|
+
destinationFd = fs4.openSync(temporary, "wx", 384);
|
|
1188
1854
|
const buffer = Buffer.alloc(1024 * 1024);
|
|
1189
1855
|
let remaining = openedStat.size;
|
|
1190
1856
|
while (remaining > 0) {
|
|
1191
|
-
const bytesRead =
|
|
1857
|
+
const bytesRead = fs4.readSync(sourceFd, buffer, 0, Math.min(remaining, buffer.length), null);
|
|
1192
1858
|
if (!bytesRead) throw new Error("Legacy agent history changed during migration");
|
|
1193
1859
|
let offset = 0;
|
|
1194
|
-
while (offset < bytesRead) offset +=
|
|
1860
|
+
while (offset < bytesRead) offset += fs4.writeSync(destinationFd, buffer, offset, bytesRead - offset);
|
|
1195
1861
|
remaining -= bytesRead;
|
|
1196
1862
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1863
|
+
fs4.futimesSync(destinationFd, openedStat.atime, openedStat.mtime);
|
|
1864
|
+
fs4.fsyncSync(destinationFd);
|
|
1865
|
+
fs4.closeSync(destinationFd);
|
|
1200
1866
|
destinationFd = void 0;
|
|
1201
1867
|
try {
|
|
1202
|
-
|
|
1868
|
+
fs4.linkSync(temporary, destination);
|
|
1203
1869
|
} catch (error) {
|
|
1204
1870
|
if (error.code !== "EEXIST") throw error;
|
|
1205
1871
|
}
|
|
1206
1872
|
} finally {
|
|
1207
|
-
if (sourceFd !== void 0)
|
|
1208
|
-
if (destinationFd !== void 0)
|
|
1209
|
-
|
|
1873
|
+
if (sourceFd !== void 0) fs4.closeSync(sourceFd);
|
|
1874
|
+
if (destinationFd !== void 0) fs4.closeSync(destinationFd);
|
|
1875
|
+
fs4.rmSync(temporary, { force: true });
|
|
1210
1876
|
}
|
|
1211
1877
|
}
|
|
1212
1878
|
function acquireMigrationLock(base) {
|
|
1213
|
-
const lockPath =
|
|
1879
|
+
const lockPath = path4.join(base, MIGRATION_LOCK);
|
|
1214
1880
|
const contents = JSON.stringify({ pid: process.pid });
|
|
1215
1881
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
1216
1882
|
try {
|
|
1217
|
-
const fd =
|
|
1883
|
+
const fd = fs4.openSync(lockPath, "wx", 384);
|
|
1218
1884
|
try {
|
|
1219
|
-
|
|
1220
|
-
|
|
1885
|
+
fs4.writeFileSync(fd, contents);
|
|
1886
|
+
fs4.fsyncSync(fd);
|
|
1221
1887
|
} catch (error) {
|
|
1222
|
-
const owned =
|
|
1888
|
+
const owned = fs4.fstatSync(fd);
|
|
1223
1889
|
const current = statIfPresent(lockPath);
|
|
1224
|
-
if (current?.ino === owned.ino && current.dev === owned.dev)
|
|
1890
|
+
if (current?.ino === owned.ino && current.dev === owned.dev) fs4.unlinkSync(lockPath);
|
|
1225
1891
|
throw error;
|
|
1226
1892
|
} finally {
|
|
1227
|
-
|
|
1893
|
+
fs4.closeSync(fd);
|
|
1228
1894
|
}
|
|
1229
1895
|
return () => {
|
|
1230
|
-
if (statIfPresent(lockPath)?.isFile() &&
|
|
1896
|
+
if (statIfPresent(lockPath)?.isFile() && fs4.readFileSync(lockPath, "utf8") === contents) fs4.unlinkSync(lockPath);
|
|
1231
1897
|
};
|
|
1232
1898
|
} catch (error) {
|
|
1233
1899
|
if (error.code !== "EEXIST") throw error;
|
|
1234
|
-
const
|
|
1235
|
-
if (!
|
|
1236
|
-
const old =
|
|
1900
|
+
const stat22 = fs4.lstatSync(lockPath);
|
|
1901
|
+
if (!stat22.isFile() || stat22.isSymbolicLink()) throw new Error("CCEM agent migration lock is invalid");
|
|
1902
|
+
const old = fs4.readFileSync(lockPath, "utf8");
|
|
1237
1903
|
let pid;
|
|
1238
1904
|
try {
|
|
1239
1905
|
pid = JSON.parse(old).pid;
|
|
@@ -1244,8 +1910,8 @@ function acquireMigrationLock(base) {
|
|
|
1244
1910
|
process.kill(pid, 0);
|
|
1245
1911
|
} catch (probeError) {
|
|
1246
1912
|
if (probeError.code === "ESRCH" && attempt === 0) {
|
|
1247
|
-
if (
|
|
1248
|
-
|
|
1913
|
+
if (fs4.readFileSync(lockPath, "utf8") !== old) throw new Error("CCEM agent migration lock changed; retry preparation");
|
|
1914
|
+
fs4.unlinkSync(lockPath);
|
|
1249
1915
|
continue;
|
|
1250
1916
|
}
|
|
1251
1917
|
}
|
|
@@ -1259,31 +1925,56 @@ function ensureCcemAgentHome(provider, env = process.env) {
|
|
|
1259
1925
|
const base = getCcemAgentBase(env);
|
|
1260
1926
|
const root = getCcemIsolatedAgentHome(provider, env);
|
|
1261
1927
|
validateAgentBase(base, env);
|
|
1928
|
+
for (const entry of LEGACY_ENTRIES[provider]) validateNoSymlinks(path4.join(root, entry));
|
|
1929
|
+
validateNoSymlinks(path4.join(root, provider === "claude" ? ".claude.json" : "config.toml"));
|
|
1930
|
+
const marker = path4.join(root, AGENT_MIGRATION_MARKER);
|
|
1931
|
+
const source = provider === "codex" ? getOfficialCodexHome(env) : path4.join(userHome(env), ".claude");
|
|
1932
|
+
const historyReady = migrationComplete(marker);
|
|
1933
|
+
if (historyReady) {
|
|
1934
|
+
if (provider !== "claude") return root;
|
|
1935
|
+
try {
|
|
1936
|
+
if (!claudePluginImportPending(source, root) && !claudePluginLinksPending(source, root)) return root;
|
|
1937
|
+
} catch (error) {
|
|
1938
|
+
console.warn(`CCEM plugin import deferred: ${error.message}`);
|
|
1939
|
+
return root;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1262
1942
|
ensureRealDirectory(base);
|
|
1263
1943
|
ensureRealDirectory(root);
|
|
1264
|
-
|
|
1265
|
-
validateNoSymlinks(path2.join(root, provider === "claude" ? ".claude.json" : "config.toml"));
|
|
1266
|
-
const marker = path2.join(root, AGENT_MIGRATION_MARKER);
|
|
1267
|
-
if (migrationComplete(marker)) return root;
|
|
1268
|
-
const unlock = acquireMigrationLock(base);
|
|
1944
|
+
let unlock;
|
|
1269
1945
|
try {
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
if (
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1946
|
+
unlock = acquireMigrationLock(base);
|
|
1947
|
+
} catch (error) {
|
|
1948
|
+
if (!historyReady) throw error;
|
|
1949
|
+
console.warn(`CCEM plugin import deferred: ${error.message}`);
|
|
1950
|
+
return root;
|
|
1951
|
+
}
|
|
1952
|
+
try {
|
|
1953
|
+
if (!migrationComplete(marker)) {
|
|
1954
|
+
if (provider === "codex") {
|
|
1955
|
+
const resolvedBase = resolveExistingParent(base);
|
|
1956
|
+
const resolvedSource = resolveExistingParent(source);
|
|
1957
|
+
if (resolvedBase === resolvedSource || resolvedBase.startsWith(`${resolvedSource}${path4.sep}`) || resolvedSource.startsWith(`${resolvedBase}${path4.sep}`)) {
|
|
1958
|
+
throw new Error("CCEM Codex migration source must not overlap its isolated agent directory");
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
assertNoLegacyAgentWriters(provider, userHome(env), source, root);
|
|
1962
|
+
const sourceStat = statIfPresent(source);
|
|
1963
|
+
if (sourceStat?.isDirectory() && !sourceStat.isSymbolicLink()) {
|
|
1964
|
+
for (const entry of LEGACY_ENTRIES[provider]) copyLegacyEntry(path4.join(source, entry), path4.join(root, entry));
|
|
1277
1965
|
}
|
|
1966
|
+
if (provider === "claude") writeNewFile(path4.join(root, ".claude.json"), JSON.stringify({ hasCompletedOnboarding: true }));
|
|
1967
|
+
writeNewFile(marker, JSON.stringify({ version: 1 }));
|
|
1968
|
+
syncDirectory(root);
|
|
1278
1969
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1970
|
+
if (provider === "claude") {
|
|
1971
|
+
try {
|
|
1972
|
+
importClaudePlugins(source, root);
|
|
1973
|
+
linkClaudePlugins(source, root);
|
|
1974
|
+
} catch (error) {
|
|
1975
|
+
console.warn(`CCEM plugin import deferred: ${error.message}`);
|
|
1976
|
+
}
|
|
1283
1977
|
}
|
|
1284
|
-
if (provider === "claude") writeNewFile(path2.join(root, ".claude.json"), JSON.stringify({ hasCompletedOnboarding: true }));
|
|
1285
|
-
writeNewFile(marker, JSON.stringify({ version: 1 }));
|
|
1286
|
-
syncDirectory(root);
|
|
1287
1978
|
return root;
|
|
1288
1979
|
} finally {
|
|
1289
1980
|
unlock();
|
|
@@ -1332,14 +2023,14 @@ var LEGACY_KEY = crypto2.scryptSync("claude-code-env-manager-secret", "salt", 32
|
|
|
1332
2023
|
var _installKey = null;
|
|
1333
2024
|
function getOrCreateInstallKey() {
|
|
1334
2025
|
if (_installKey) return _installKey;
|
|
1335
|
-
const keyPath =
|
|
1336
|
-
if (
|
|
1337
|
-
_installKey = Buffer.from(
|
|
2026
|
+
const keyPath = path5.join(getCcemConfigDir(), ".install-key");
|
|
2027
|
+
if (fs5.existsSync(keyPath)) {
|
|
2028
|
+
_installKey = Buffer.from(fs5.readFileSync(keyPath, "utf-8").trim(), "hex");
|
|
1338
2029
|
return _installKey;
|
|
1339
2030
|
}
|
|
1340
2031
|
ensureCcemDir();
|
|
1341
2032
|
_installKey = crypto2.randomBytes(32);
|
|
1342
|
-
|
|
2033
|
+
fs5.writeFileSync(keyPath, _installKey.toString("hex"), { mode: 384 });
|
|
1343
2034
|
return _installKey;
|
|
1344
2035
|
}
|
|
1345
2036
|
var encrypt = (text) => {
|
|
@@ -1373,27 +2064,27 @@ var getHomeDir = () => {
|
|
|
1373
2064
|
return process.env.HOME || process.env.USERPROFILE || os2.homedir() || "";
|
|
1374
2065
|
};
|
|
1375
2066
|
var getCcemConfigDir = () => {
|
|
1376
|
-
return
|
|
2067
|
+
return path5.join(getHomeDir(), ".ccem");
|
|
1377
2068
|
};
|
|
1378
2069
|
var getCcemConfigPath = () => {
|
|
1379
|
-
return
|
|
2070
|
+
return path5.join(getCcemConfigDir(), "config.json");
|
|
1380
2071
|
};
|
|
1381
2072
|
var ensureCcemDir = () => {
|
|
1382
2073
|
const ccemDir = getCcemConfigDir();
|
|
1383
|
-
if (!
|
|
1384
|
-
|
|
2074
|
+
if (!fs5.existsSync(ccemDir)) {
|
|
2075
|
+
fs5.mkdirSync(ccemDir, { recursive: true, mode: 448 });
|
|
1385
2076
|
}
|
|
1386
2077
|
if (process.platform !== "win32") {
|
|
1387
|
-
|
|
2078
|
+
fs5.chmodSync(ccemDir, 448);
|
|
1388
2079
|
}
|
|
1389
2080
|
return ccemDir;
|
|
1390
2081
|
};
|
|
1391
2082
|
var getLegacyConfigPath = () => {
|
|
1392
2083
|
const home = getHomeDir();
|
|
1393
2084
|
if (process.platform === "darwin") {
|
|
1394
|
-
return
|
|
2085
|
+
return path5.join(home, "Library", "Preferences", "claude-code-env-manager-nodejs", "config.json");
|
|
1395
2086
|
}
|
|
1396
|
-
return
|
|
2087
|
+
return path5.join(home, ".config", "claude-code-env-manager-nodejs", "config.json");
|
|
1397
2088
|
};
|
|
1398
2089
|
|
|
1399
2090
|
// src/desktopControl.ts
|
|
@@ -1460,11 +2151,11 @@ function getDesktopControlDescriptorPath() {
|
|
|
1460
2151
|
return process.env.CCEM_CONTROL_FILE?.trim() || getDefaultControlDescriptorPath();
|
|
1461
2152
|
}
|
|
1462
2153
|
function getDefaultControlDescriptorPath() {
|
|
1463
|
-
return
|
|
2154
|
+
return path6.join(getCcemConfigDir(), "control.json");
|
|
1464
2155
|
}
|
|
1465
2156
|
function isDefaultDescriptorPath(descriptorPath) {
|
|
1466
2157
|
try {
|
|
1467
|
-
return
|
|
2158
|
+
return path6.resolve(descriptorPath) === path6.resolve(getDefaultControlDescriptorPath());
|
|
1468
2159
|
} catch {
|
|
1469
2160
|
return false;
|
|
1470
2161
|
}
|
|
@@ -1474,7 +2165,7 @@ function safeRemoveStaleDescriptor(descriptorPath) {
|
|
|
1474
2165
|
return false;
|
|
1475
2166
|
}
|
|
1476
2167
|
try {
|
|
1477
|
-
|
|
2168
|
+
fs6.rmSync(descriptorPath);
|
|
1478
2169
|
return true;
|
|
1479
2170
|
} catch {
|
|
1480
2171
|
return false;
|
|
@@ -1552,10 +2243,10 @@ function isDescriptor(value) {
|
|
|
1552
2243
|
);
|
|
1553
2244
|
}
|
|
1554
2245
|
function resolveDesktopControlDescriptor(descriptorPath = getDesktopControlDescriptorPath()) {
|
|
1555
|
-
if (!
|
|
2246
|
+
if (!fs6.existsSync(descriptorPath)) {
|
|
1556
2247
|
throw new Error(`CCEM Desktop control endpoint not found at ${descriptorPath}. Start CCEM Desktop first.`);
|
|
1557
2248
|
}
|
|
1558
|
-
const parsed = JSON.parse(
|
|
2249
|
+
const parsed = JSON.parse(fs6.readFileSync(descriptorPath, "utf-8"));
|
|
1559
2250
|
const endpoint = parsed.endpoint?.trim();
|
|
1560
2251
|
const token = parsed.token?.trim();
|
|
1561
2252
|
if (!endpoint || !token) {
|
|
@@ -1820,29 +2511,29 @@ import inquirer from "inquirer";
|
|
|
1820
2511
|
import chalk9 from "chalk";
|
|
1821
2512
|
import Table4 from "cli-table3";
|
|
1822
2513
|
import { spawn as spawn4 } from "child_process";
|
|
1823
|
-
import * as
|
|
1824
|
-
import * as
|
|
2514
|
+
import * as fs18 from "fs";
|
|
2515
|
+
import * as path16 from "path";
|
|
1825
2516
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1826
|
-
import { randomUUID as
|
|
2517
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
1827
2518
|
|
|
1828
2519
|
// src/ui.ts
|
|
1829
2520
|
import chalk from "chalk";
|
|
1830
2521
|
import Table from "cli-table3";
|
|
1831
2522
|
|
|
1832
2523
|
// src/usage.ts
|
|
1833
|
-
import * as
|
|
2524
|
+
import * as fs7 from "fs";
|
|
1834
2525
|
import * as fsPromises from "fs/promises";
|
|
1835
|
-
import * as
|
|
2526
|
+
import * as path7 from "path";
|
|
1836
2527
|
import * as os3 from "os";
|
|
1837
2528
|
import * as readline from "readline";
|
|
1838
2529
|
import { fileURLToPath } from "url";
|
|
1839
2530
|
var __filename = fileURLToPath(import.meta.url);
|
|
1840
|
-
var __dirname =
|
|
1841
|
-
var CLAUDE_PROJECTS_DIR =
|
|
1842
|
-
var CCEM_DIR =
|
|
2531
|
+
var __dirname = path7.dirname(__filename);
|
|
2532
|
+
var CLAUDE_PROJECTS_DIR = path7.join(getCcemAgentHome("claude"), "projects");
|
|
2533
|
+
var CCEM_DIR = path7.join(os3.homedir(), ".ccem");
|
|
1843
2534
|
var CACHE_VERSION = 3;
|
|
1844
|
-
var getCachePath = () =>
|
|
1845
|
-
var getPricesPath = () =>
|
|
2535
|
+
var getCachePath = () => path7.join(CCEM_DIR, "usage-cache.json");
|
|
2536
|
+
var getPricesPath = () => path7.join(CCEM_DIR, "model-prices.json");
|
|
1846
2537
|
async function ensureCcemDir2() {
|
|
1847
2538
|
try {
|
|
1848
2539
|
await fsPromises.access(CCEM_DIR);
|
|
@@ -1852,7 +2543,7 @@ async function ensureCcemDir2() {
|
|
|
1852
2543
|
}
|
|
1853
2544
|
var LITELLM_PRICES_URL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json";
|
|
1854
2545
|
var getBundledPricesPath = () => {
|
|
1855
|
-
return
|
|
2546
|
+
return path7.join(__dirname, "..", "model-prices.json");
|
|
1856
2547
|
};
|
|
1857
2548
|
var DEFAULT_PRICES = {
|
|
1858
2549
|
"claude-opus-4-5": {
|
|
@@ -1959,10 +2650,10 @@ function mergeUsage(a, b) {
|
|
|
1959
2650
|
}
|
|
1960
2651
|
async function getFileMetaAsync(filePath) {
|
|
1961
2652
|
try {
|
|
1962
|
-
const
|
|
2653
|
+
const stat3 = await fsPromises.stat(filePath);
|
|
1963
2654
|
return {
|
|
1964
|
-
mtime:
|
|
1965
|
-
size:
|
|
2655
|
+
mtime: stat3.mtimeMs,
|
|
2656
|
+
size: stat3.size
|
|
1966
2657
|
};
|
|
1967
2658
|
} catch {
|
|
1968
2659
|
return null;
|
|
@@ -1971,8 +2662,8 @@ async function getFileMetaAsync(filePath) {
|
|
|
1971
2662
|
function loadCacheSync() {
|
|
1972
2663
|
try {
|
|
1973
2664
|
const cachePath = getCachePath();
|
|
1974
|
-
if (!
|
|
1975
|
-
const data = JSON.parse(
|
|
2665
|
+
if (!fs7.existsSync(cachePath)) return null;
|
|
2666
|
+
const data = JSON.parse(fs7.readFileSync(cachePath, "utf-8"));
|
|
1976
2667
|
if (data.version !== CACHE_VERSION) return null;
|
|
1977
2668
|
return data;
|
|
1978
2669
|
} catch {
|
|
@@ -2040,7 +2731,7 @@ async function parseJSONLFileAsync(filePath, prices, signal) {
|
|
|
2040
2731
|
const entries = [];
|
|
2041
2732
|
const messageEntryIndexes = /* @__PURE__ */ new Map();
|
|
2042
2733
|
try {
|
|
2043
|
-
const fileStream =
|
|
2734
|
+
const fileStream = fs7.createReadStream(filePath, { encoding: "utf-8" });
|
|
2044
2735
|
const rl = readline.createInterface({
|
|
2045
2736
|
input: fileStream,
|
|
2046
2737
|
crlfDelay: Infinity
|
|
@@ -2106,13 +2797,13 @@ async function getAllJSONLFilesAsync() {
|
|
|
2106
2797
|
if (!projectsDirExists) return files;
|
|
2107
2798
|
const projects = await fsPromises.readdir(CLAUDE_PROJECTS_DIR);
|
|
2108
2799
|
for (const project of projects) {
|
|
2109
|
-
const projectPath =
|
|
2800
|
+
const projectPath = path7.join(CLAUDE_PROJECTS_DIR, project);
|
|
2110
2801
|
try {
|
|
2111
|
-
const
|
|
2112
|
-
if (
|
|
2802
|
+
const stat3 = await fsPromises.lstat(projectPath);
|
|
2803
|
+
if (stat3.isDirectory()) {
|
|
2113
2804
|
const projectFiles = await fsPromises.readdir(projectPath);
|
|
2114
2805
|
for (const file of projectFiles) {
|
|
2115
|
-
const filePath =
|
|
2806
|
+
const filePath = path7.join(projectPath, file);
|
|
2116
2807
|
if (file.endsWith(".jsonl") && (await fsPromises.lstat(filePath)).isFile()) {
|
|
2117
2808
|
files.push(filePath);
|
|
2118
2809
|
}
|
|
@@ -2338,10 +3029,10 @@ var renderLogoWithEnvPanel = (envName, env, defaultMode) => {
|
|
|
2338
3029
|
const parsed = new URL(url);
|
|
2339
3030
|
const protocol = parsed.protocol + "//";
|
|
2340
3031
|
const host = parsed.host;
|
|
2341
|
-
const
|
|
3032
|
+
const path17 = parsed.pathname + parsed.search;
|
|
2342
3033
|
const hostStart = host.slice(0, 8);
|
|
2343
3034
|
const hostEnd = host.slice(-4);
|
|
2344
|
-
const pathPart =
|
|
3035
|
+
const pathPart = path17.length > 10 ? path17.slice(0, 7) + "..." : path17;
|
|
2345
3036
|
return `${protocol}${hostStart}...${hostEnd}${pathPart}`;
|
|
2346
3037
|
} catch {
|
|
2347
3038
|
return truncate(url, max);
|
|
@@ -2779,45 +3470,45 @@ var selectEnvWithKeys = (registries, current) => {
|
|
|
2779
3470
|
};
|
|
2780
3471
|
|
|
2781
3472
|
// src/permissions.ts
|
|
2782
|
-
import
|
|
3473
|
+
import fs11 from "fs";
|
|
2783
3474
|
import chalk3 from "chalk";
|
|
2784
3475
|
import Table2 from "cli-table3";
|
|
2785
3476
|
|
|
2786
3477
|
// src/utils.ts
|
|
2787
3478
|
import crypto3 from "crypto";
|
|
2788
|
-
import
|
|
2789
|
-
import
|
|
3479
|
+
import fs8 from "fs";
|
|
3480
|
+
import path8 from "path";
|
|
2790
3481
|
var SECRET_KEY = crypto3.scryptSync("claude-code-env-manager-secret", "salt", 32);
|
|
2791
3482
|
var findProjectRoot = () => {
|
|
2792
3483
|
let currentDir = process.cwd();
|
|
2793
|
-
const root =
|
|
3484
|
+
const root = path8.parse(currentDir).root;
|
|
2794
3485
|
while (currentDir !== root) {
|
|
2795
|
-
if (
|
|
3486
|
+
if (fs8.existsSync(path8.join(currentDir, ".git")) || fs8.existsSync(path8.join(currentDir, "package.json"))) {
|
|
2796
3487
|
return currentDir;
|
|
2797
3488
|
}
|
|
2798
|
-
currentDir =
|
|
3489
|
+
currentDir = path8.dirname(currentDir);
|
|
2799
3490
|
}
|
|
2800
3491
|
return process.cwd();
|
|
2801
3492
|
};
|
|
2802
3493
|
var getSettingsPath = (useLocal = true) => {
|
|
2803
3494
|
const projectRoot = findProjectRoot();
|
|
2804
|
-
const claudeDir =
|
|
3495
|
+
const claudeDir = path8.join(projectRoot, ".claude");
|
|
2805
3496
|
const filename = useLocal ? "settings.local.json" : "settings.json";
|
|
2806
|
-
return
|
|
3497
|
+
return path8.join(claudeDir, filename);
|
|
2807
3498
|
};
|
|
2808
3499
|
var ensureClaudeDir = () => {
|
|
2809
3500
|
const projectRoot = findProjectRoot();
|
|
2810
|
-
const claudeDir =
|
|
2811
|
-
if (!
|
|
2812
|
-
|
|
3501
|
+
const claudeDir = path8.join(projectRoot, ".claude");
|
|
3502
|
+
if (!fs8.existsSync(claudeDir)) {
|
|
3503
|
+
fs8.mkdirSync(claudeDir, { recursive: true });
|
|
2813
3504
|
}
|
|
2814
3505
|
return claudeDir;
|
|
2815
3506
|
};
|
|
2816
3507
|
var getGlobalClaudeConfigPath = () => {
|
|
2817
|
-
return
|
|
3508
|
+
return path8.join(getCcemAgentHome("claude"), ".claude.json");
|
|
2818
3509
|
};
|
|
2819
3510
|
var getGlobalClaudeSettingsPath = () => {
|
|
2820
|
-
return
|
|
3511
|
+
return path8.join(getCcemAgentHome("claude"), "settings.json");
|
|
2821
3512
|
};
|
|
2822
3513
|
var ensureGlobalClaudeDir = () => {
|
|
2823
3514
|
return ensureCcemAgentHome("claude");
|
|
@@ -2825,16 +3516,16 @@ var ensureGlobalClaudeDir = () => {
|
|
|
2825
3516
|
|
|
2826
3517
|
// src/launcher.ts
|
|
2827
3518
|
import { spawn as spawn2 } from "child_process";
|
|
2828
|
-
import * as
|
|
2829
|
-
import * as
|
|
3519
|
+
import * as fs10 from "fs";
|
|
3520
|
+
import * as path10 from "path";
|
|
2830
3521
|
import chalk2 from "chalk";
|
|
2831
3522
|
|
|
2832
3523
|
// src/sessionProvenance.ts
|
|
2833
3524
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
2834
|
-
import
|
|
3525
|
+
import fs9 from "fs";
|
|
2835
3526
|
import { createRequire } from "module";
|
|
2836
3527
|
import os4 from "os";
|
|
2837
|
-
import
|
|
3528
|
+
import path9 from "path";
|
|
2838
3529
|
var DEFAULT_CONFIG_SOURCE = "ccem";
|
|
2839
3530
|
var STATE_DB_FILE_NAME = "state.sqlite";
|
|
2840
3531
|
var BIND_POLL_INTERVAL_MS = 500;
|
|
@@ -2889,7 +3580,7 @@ function startCliClaudeProvenanceTracking(options) {
|
|
|
2889
3580
|
if (!jsonlPath) {
|
|
2890
3581
|
return;
|
|
2891
3582
|
}
|
|
2892
|
-
const sourceSessionId = readClaudeSessionId(jsonlPath) ?? normalizeText(
|
|
3583
|
+
const sourceSessionId = readClaudeSessionId(jsonlPath) ?? normalizeText(path9.parse(jsonlPath).name);
|
|
2893
3584
|
if (!sourceSessionId) {
|
|
2894
3585
|
return;
|
|
2895
3586
|
}
|
|
@@ -3016,7 +3707,7 @@ function bindSourceSessionId(client, ccemSessionId, sourceSessionId) {
|
|
|
3016
3707
|
}
|
|
3017
3708
|
function openNodeSqliteDb(DatabaseSync) {
|
|
3018
3709
|
const dbPath = getStateDbPath();
|
|
3019
|
-
|
|
3710
|
+
fs9.mkdirSync(path9.dirname(dbPath), { recursive: true });
|
|
3020
3711
|
const db = new DatabaseSync(dbPath);
|
|
3021
3712
|
db.exec(schemaSql());
|
|
3022
3713
|
return db;
|
|
@@ -3057,7 +3748,7 @@ function execSqlite3Cli(statementSql) {
|
|
|
3057
3748
|
throw new Error("sqlite3 CLI is unavailable and node:sqlite is not supported by this Node runtime");
|
|
3058
3749
|
}
|
|
3059
3750
|
const dbPath = getStateDbPath();
|
|
3060
|
-
|
|
3751
|
+
fs9.mkdirSync(path9.dirname(dbPath), { recursive: true });
|
|
3061
3752
|
execFileSync2("sqlite3", [dbPath], {
|
|
3062
3753
|
input: `${schemaSql()}
|
|
3063
3754
|
${statementSql}
|
|
@@ -3070,7 +3761,7 @@ function getStateDbPath() {
|
|
|
3070
3761
|
if (override) {
|
|
3071
3762
|
return override;
|
|
3072
3763
|
}
|
|
3073
|
-
return
|
|
3764
|
+
return path9.join(os4.homedir(), ".ccem", STATE_DB_FILE_NAME);
|
|
3074
3765
|
}
|
|
3075
3766
|
function schemaSql() {
|
|
3076
3767
|
return `
|
|
@@ -3096,16 +3787,16 @@ function schemaSql() {
|
|
|
3096
3787
|
`;
|
|
3097
3788
|
}
|
|
3098
3789
|
function discoverClaudeJsonlPath(projectDir, startedAtMs) {
|
|
3099
|
-
const projectsDir =
|
|
3790
|
+
const projectsDir = path9.join(getCcemAgentHome("claude"), "projects");
|
|
3100
3791
|
const earliestModifiedAt = startedAtMs - 15e3;
|
|
3101
3792
|
for (const key of projectDirKeys(projectDir)) {
|
|
3102
|
-
const baseDir =
|
|
3103
|
-
if (!
|
|
3793
|
+
const baseDir = path9.join(projectsDir, key);
|
|
3794
|
+
if (!fs9.existsSync(baseDir)) {
|
|
3104
3795
|
continue;
|
|
3105
3796
|
}
|
|
3106
|
-
const candidates =
|
|
3107
|
-
const fullPath =
|
|
3108
|
-
return { path: fullPath, modifiedAt:
|
|
3797
|
+
const candidates = fs9.readdirSync(baseDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".jsonl")).map((entry) => {
|
|
3798
|
+
const fullPath = path9.join(baseDir, entry.name);
|
|
3799
|
+
return { path: fullPath, modifiedAt: fs9.statSync(fullPath).mtimeMs };
|
|
3109
3800
|
}).filter((candidate) => candidate.modifiedAt >= earliestModifiedAt).sort((left, right) => right.modifiedAt - left.modifiedAt);
|
|
3110
3801
|
if (candidates.length > 0) {
|
|
3111
3802
|
return candidates[0].path;
|
|
@@ -3116,16 +3807,16 @@ function discoverClaudeJsonlPath(projectDir, startedAtMs) {
|
|
|
3116
3807
|
function projectDirKeys(projectDir) {
|
|
3117
3808
|
const candidates = [projectDir];
|
|
3118
3809
|
try {
|
|
3119
|
-
candidates.push(
|
|
3810
|
+
candidates.push(fs9.realpathSync(projectDir));
|
|
3120
3811
|
} catch {
|
|
3121
3812
|
}
|
|
3122
3813
|
if (process.platform === "darwin") {
|
|
3123
3814
|
if (projectDir.startsWith("/private/")) {
|
|
3124
3815
|
candidates.push(projectDir.slice("/private".length));
|
|
3125
3816
|
} else if (projectDir.startsWith("/tmp")) {
|
|
3126
|
-
candidates.push(
|
|
3817
|
+
candidates.push(path9.posix.join("/private", projectDir));
|
|
3127
3818
|
} else if (projectDir.startsWith("/var/")) {
|
|
3128
|
-
candidates.push(
|
|
3819
|
+
candidates.push(path9.posix.join("/private", projectDir));
|
|
3129
3820
|
}
|
|
3130
3821
|
}
|
|
3131
3822
|
return [...new Set(candidates.map(projectDirKey))];
|
|
@@ -3134,7 +3825,7 @@ function projectDirKey(projectDir) {
|
|
|
3134
3825
|
return projectDir.replace(/[\/\\: ]/g, "-");
|
|
3135
3826
|
}
|
|
3136
3827
|
function readClaudeSessionId(jsonlPath) {
|
|
3137
|
-
const lines =
|
|
3828
|
+
const lines = fs9.readFileSync(jsonlPath, "utf8").split("\n");
|
|
3138
3829
|
for (const line of lines) {
|
|
3139
3830
|
if (!line.trim()) {
|
|
3140
3831
|
continue;
|
|
@@ -3209,9 +3900,9 @@ function buildPermArgs(modeName) {
|
|
|
3209
3900
|
return args;
|
|
3210
3901
|
}
|
|
3211
3902
|
function ensureSessionsDir() {
|
|
3212
|
-
const dir =
|
|
3213
|
-
if (!
|
|
3214
|
-
|
|
3903
|
+
const dir = path10.join(ensureCcemDir(), "sessions");
|
|
3904
|
+
if (!fs10.existsSync(dir)) {
|
|
3905
|
+
fs10.mkdirSync(dir, { recursive: true });
|
|
3215
3906
|
}
|
|
3216
3907
|
return dir;
|
|
3217
3908
|
}
|
|
@@ -3282,8 +3973,8 @@ async function launchClaude(options) {
|
|
|
3282
3973
|
provenanceTracking?.stop();
|
|
3283
3974
|
if (sessionId) {
|
|
3284
3975
|
try {
|
|
3285
|
-
|
|
3286
|
-
|
|
3976
|
+
fs10.writeFileSync(
|
|
3977
|
+
path10.join(sessionsDir, `${sessionId}.exit`),
|
|
3287
3978
|
String(code ?? 0)
|
|
3288
3979
|
);
|
|
3289
3980
|
} catch {
|
|
@@ -3353,14 +4044,14 @@ var formatPermissionRulesForDisplay = (rules) => {
|
|
|
3353
4044
|
}).join("\n");
|
|
3354
4045
|
};
|
|
3355
4046
|
var readSettings = (settingsPath) => {
|
|
3356
|
-
if (
|
|
4047
|
+
if (fs11.existsSync(settingsPath)) {
|
|
3357
4048
|
try {
|
|
3358
|
-
const content =
|
|
4049
|
+
const content = fs11.readFileSync(settingsPath, "utf-8");
|
|
3359
4050
|
return JSON.parse(content);
|
|
3360
4051
|
} catch {
|
|
3361
4052
|
console.warn(chalk3.yellow(`\u8B66\u544A: \u65E0\u6CD5\u89E3\u6790 ${settingsPath}\uFF0C\u5C06\u521B\u5EFA\u5907\u4EFD`));
|
|
3362
4053
|
const backupPath = settingsPath + ".error." + Date.now();
|
|
3363
|
-
|
|
4054
|
+
fs11.copyFileSync(settingsPath, backupPath);
|
|
3364
4055
|
console.log(chalk3.gray(`\u5907\u4EFD\u5DF2\u4FDD\u5B58\u5230: ${backupPath}`));
|
|
3365
4056
|
return {};
|
|
3366
4057
|
}
|
|
@@ -3369,7 +4060,7 @@ var readSettings = (settingsPath) => {
|
|
|
3369
4060
|
};
|
|
3370
4061
|
var writeSettings = (settingsPath, config3) => {
|
|
3371
4062
|
ensureClaudeDir();
|
|
3372
|
-
|
|
4063
|
+
fs11.writeFileSync(settingsPath, JSON.stringify(config3, null, 2) + "\n");
|
|
3373
4064
|
};
|
|
3374
4065
|
var mergePermissions = (existing, preset) => {
|
|
3375
4066
|
const existingAllow = normalizePermissionAllowRules(existing.permissions?.allow || []);
|
|
@@ -3402,14 +4093,14 @@ var applyPermissionMode = (modeName) => {
|
|
|
3402
4093
|
};
|
|
3403
4094
|
var resetPermissions = () => {
|
|
3404
4095
|
const settingsPath = getSettingsPath(true);
|
|
3405
|
-
if (!
|
|
4096
|
+
if (!fs11.existsSync(settingsPath)) {
|
|
3406
4097
|
console.log(chalk3.yellow("\u6CA1\u6709\u81EA\u5B9A\u4E49\u6743\u9650\u914D\u7F6E\u9700\u8981\u91CD\u7F6E"));
|
|
3407
4098
|
return;
|
|
3408
4099
|
}
|
|
3409
4100
|
const config3 = readSettings(settingsPath);
|
|
3410
4101
|
delete config3.permissions;
|
|
3411
4102
|
if (Object.keys(config3).length === 0) {
|
|
3412
|
-
|
|
4103
|
+
fs11.unlinkSync(settingsPath);
|
|
3413
4104
|
console.log(chalk3.green("\u5DF2\u5220\u9664\u914D\u7F6E\u6587\u4EF6\uFF08\u6587\u4EF6\u4E3A\u7A7A\uFF09"));
|
|
3414
4105
|
} else {
|
|
3415
4106
|
writeSettings(settingsPath, config3);
|
|
@@ -3419,7 +4110,7 @@ var resetPermissions = () => {
|
|
|
3419
4110
|
};
|
|
3420
4111
|
var showCurrentMode = () => {
|
|
3421
4112
|
const settingsPath = getSettingsPath(true);
|
|
3422
|
-
if (!
|
|
4113
|
+
if (!fs11.existsSync(settingsPath)) {
|
|
3423
4114
|
console.log(chalk3.yellow("\u672A\u914D\u7F6E\u81EA\u5B9A\u4E49\u6743\u9650"));
|
|
3424
4115
|
console.log(chalk3.gray(`\u6587\u4EF6\u4E0D\u5B58\u5728: ${settingsPath}`));
|
|
3425
4116
|
return;
|
|
@@ -3478,14 +4169,14 @@ var runWithTempPermissions = async (modeName, envConfig, envName) => {
|
|
|
3478
4169
|
};
|
|
3479
4170
|
|
|
3480
4171
|
// src/environmentMutations.ts
|
|
3481
|
-
import
|
|
3482
|
-
import
|
|
4172
|
+
import fs12 from "fs";
|
|
4173
|
+
import path11 from "path";
|
|
3483
4174
|
function nativeRuntimeStatePath() {
|
|
3484
|
-
return
|
|
4175
|
+
return path11.join(getCcemConfigDir(), "native-runtime-state.json");
|
|
3485
4176
|
}
|
|
3486
4177
|
function resolveMutationAuthority(options) {
|
|
3487
|
-
const descriptorExists = options.descriptorExists ?? (() =>
|
|
3488
|
-
const stateExists = options.stateExists ?? (() =>
|
|
4178
|
+
const descriptorExists = options.descriptorExists ?? (() => fs12.existsSync(getDesktopControlDescriptorPath()));
|
|
4179
|
+
const stateExists = options.stateExists ?? (() => fs12.existsSync(nativeRuntimeStatePath()));
|
|
3489
4180
|
return { descriptorExists, stateExists };
|
|
3490
4181
|
}
|
|
3491
4182
|
function assertOfflineMutationIsSafe(name, stateExists) {
|
|
@@ -3585,13 +4276,13 @@ function deleteEnvironmentFromConfig(config3, name) {
|
|
|
3585
4276
|
}
|
|
3586
4277
|
|
|
3587
4278
|
// src/setup.ts
|
|
3588
|
-
import
|
|
4279
|
+
import fs13 from "fs";
|
|
3589
4280
|
import chalk4 from "chalk";
|
|
3590
4281
|
import { spawn as spawn3 } from "child_process";
|
|
3591
4282
|
var readJsonFile = (filePath) => {
|
|
3592
|
-
if (
|
|
4283
|
+
if (fs13.existsSync(filePath)) {
|
|
3593
4284
|
try {
|
|
3594
|
-
const content =
|
|
4285
|
+
const content = fs13.readFileSync(filePath, "utf-8");
|
|
3595
4286
|
return JSON.parse(content);
|
|
3596
4287
|
} catch {
|
|
3597
4288
|
console.warn(chalk4.yellow(`\u8B66\u544A: \u65E0\u6CD5\u89E3\u6790 ${filePath}`));
|
|
@@ -3601,7 +4292,7 @@ var readJsonFile = (filePath) => {
|
|
|
3601
4292
|
return {};
|
|
3602
4293
|
};
|
|
3603
4294
|
var writeJsonFile = (filePath, data) => {
|
|
3604
|
-
|
|
4295
|
+
fs13.writeFileSync(filePath, JSON.stringify(data, null, 2) + "\n");
|
|
3605
4296
|
};
|
|
3606
4297
|
var setupOnboarding = () => {
|
|
3607
4298
|
const configPath = getGlobalClaudeConfigPath();
|
|
@@ -3635,14 +4326,14 @@ var setupEnvSettings = () => {
|
|
|
3635
4326
|
"DISABLE_ERROR_REPORTING": "1",
|
|
3636
4327
|
"DISABLE_TELEMETRY": "1"
|
|
3637
4328
|
};
|
|
3638
|
-
let
|
|
4329
|
+
let changed2 = false;
|
|
3639
4330
|
for (const [key, value] of Object.entries(envVars)) {
|
|
3640
4331
|
if (env[key] !== value) {
|
|
3641
4332
|
env[key] = value;
|
|
3642
|
-
|
|
4333
|
+
changed2 = true;
|
|
3643
4334
|
}
|
|
3644
4335
|
}
|
|
3645
|
-
if (!
|
|
4336
|
+
if (!changed2) {
|
|
3646
4337
|
console.log(chalk4.gray(" \u2713 \u73AF\u5883\u53D8\u91CF\u5DF2\u914D\u7F6E"));
|
|
3647
4338
|
return true;
|
|
3648
4339
|
}
|
|
@@ -3730,8 +4421,8 @@ var runSetupInit = async (options = {}) => {
|
|
|
3730
4421
|
|
|
3731
4422
|
// src/skills.ts
|
|
3732
4423
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
3733
|
-
import * as
|
|
3734
|
-
import * as
|
|
4424
|
+
import * as fs14 from "fs";
|
|
4425
|
+
import * as path12 from "path";
|
|
3735
4426
|
import chalk5 from "chalk";
|
|
3736
4427
|
var SKILL_GROUPS = {
|
|
3737
4428
|
official: { label: "\u5B98\u65B9", icon: "\u{1F3E2}" },
|
|
@@ -3967,7 +4658,7 @@ function parseGitHubUrl(url) {
|
|
|
3967
4658
|
repo,
|
|
3968
4659
|
branch,
|
|
3969
4660
|
repoPath,
|
|
3970
|
-
repoPath ?
|
|
4661
|
+
repoPath ? path12.basename(repoPath) : repo
|
|
3971
4662
|
);
|
|
3972
4663
|
return { owner, repo, branch, path: repoPath };
|
|
3973
4664
|
} catch {
|
|
@@ -3975,12 +4666,12 @@ function parseGitHubUrl(url) {
|
|
|
3975
4666
|
}
|
|
3976
4667
|
}
|
|
3977
4668
|
function getSkillsDir() {
|
|
3978
|
-
return
|
|
4669
|
+
return path12.join(process.cwd(), ".claude", "skills");
|
|
3979
4670
|
}
|
|
3980
4671
|
function ensureSkillsDir() {
|
|
3981
4672
|
const skillsDir = getSkillsDir();
|
|
3982
|
-
if (!
|
|
3983
|
-
|
|
4673
|
+
if (!fs14.existsSync(skillsDir)) {
|
|
4674
|
+
fs14.mkdirSync(skillsDir, { recursive: true });
|
|
3984
4675
|
} else {
|
|
3985
4676
|
cleanupTempDirs(skillsDir);
|
|
3986
4677
|
}
|
|
@@ -3988,11 +4679,11 @@ function ensureSkillsDir() {
|
|
|
3988
4679
|
}
|
|
3989
4680
|
function cleanupTempDirs(skillsDir) {
|
|
3990
4681
|
try {
|
|
3991
|
-
const entries =
|
|
4682
|
+
const entries = fs14.readdirSync(skillsDir, { withFileTypes: true });
|
|
3992
4683
|
for (const entry of entries) {
|
|
3993
4684
|
if (entry.isDirectory() && entry.name.startsWith(".tmp-")) {
|
|
3994
|
-
const tmpPath =
|
|
3995
|
-
|
|
4685
|
+
const tmpPath = path12.join(skillsDir, entry.name);
|
|
4686
|
+
fs14.rmSync(tmpPath, { recursive: true });
|
|
3996
4687
|
}
|
|
3997
4688
|
}
|
|
3998
4689
|
} catch {
|
|
@@ -4003,27 +4694,27 @@ function downloadSkillWithGit(owner, repo, branch, repoPath, targetName) {
|
|
|
4003
4694
|
try {
|
|
4004
4695
|
validateGitHubInstallParts(owner, repo, branch, repoPath, targetName);
|
|
4005
4696
|
const skillsDir = ensureSkillsDir();
|
|
4006
|
-
const targetDir =
|
|
4007
|
-
if (
|
|
4697
|
+
const targetDir = path12.join(skillsDir, targetName);
|
|
4698
|
+
if (fs14.existsSync(targetDir)) {
|
|
4008
4699
|
console.log(chalk5.yellow(`Skill "${targetName}" already exists. Updating...`));
|
|
4009
|
-
|
|
4700
|
+
fs14.rmSync(targetDir, { recursive: true });
|
|
4010
4701
|
}
|
|
4011
4702
|
const repoUrl = `https://github.com/${owner}/${repo}.git`;
|
|
4012
|
-
tempDir =
|
|
4013
|
-
|
|
4703
|
+
tempDir = path12.join(skillsDir, `.tmp-${Date.now()}`);
|
|
4704
|
+
fs14.mkdirSync(tempDir, { recursive: true });
|
|
4014
4705
|
execFileSync3("git", ["init"], { cwd: tempDir, stdio: "pipe" });
|
|
4015
4706
|
execFileSync3("git", ["remote", "add", "origin", repoUrl], { cwd: tempDir, stdio: "pipe" });
|
|
4016
4707
|
execFileSync3("git", ["config", "core.sparseCheckout", "true"], { cwd: tempDir, stdio: "pipe" });
|
|
4017
|
-
const sparseFile =
|
|
4018
|
-
|
|
4019
|
-
|
|
4708
|
+
const sparseFile = path12.join(tempDir, ".git", "info", "sparse-checkout");
|
|
4709
|
+
fs14.mkdirSync(path12.dirname(sparseFile), { recursive: true });
|
|
4710
|
+
fs14.writeFileSync(sparseFile, repoPath ? `${repoPath}/
|
|
4020
4711
|
` : "*\n");
|
|
4021
4712
|
execFileSync3("git", ["pull", "--depth=1", "origin", branch], {
|
|
4022
4713
|
cwd: tempDir,
|
|
4023
4714
|
stdio: "pipe"
|
|
4024
4715
|
});
|
|
4025
|
-
const sourceDir = repoPath ?
|
|
4026
|
-
if (!
|
|
4716
|
+
const sourceDir = repoPath ? path12.join(tempDir, repoPath) : tempDir;
|
|
4717
|
+
if (!fs14.existsSync(sourceDir)) {
|
|
4027
4718
|
throw new Error(`Path "${repoPath}" not found in repository`);
|
|
4028
4719
|
}
|
|
4029
4720
|
copyDir(sourceDir, targetDir);
|
|
@@ -4034,31 +4725,31 @@ function downloadSkillWithGit(owner, repo, branch, repoPath, targetName) {
|
|
|
4034
4725
|
console.error(chalk5.red(`Failed to download skill: ${errMsg}`));
|
|
4035
4726
|
return false;
|
|
4036
4727
|
} finally {
|
|
4037
|
-
if (tempDir &&
|
|
4038
|
-
|
|
4728
|
+
if (tempDir && fs14.existsSync(tempDir)) {
|
|
4729
|
+
fs14.rmSync(tempDir, { recursive: true });
|
|
4039
4730
|
}
|
|
4040
4731
|
}
|
|
4041
4732
|
}
|
|
4042
4733
|
function copyDir(src, dest) {
|
|
4043
|
-
|
|
4044
|
-
const entries =
|
|
4734
|
+
fs14.mkdirSync(dest, { recursive: true });
|
|
4735
|
+
const entries = fs14.readdirSync(src, { withFileTypes: true });
|
|
4045
4736
|
for (const entry of entries) {
|
|
4046
4737
|
if (entry.name === ".git") continue;
|
|
4047
|
-
const srcPath =
|
|
4048
|
-
const destPath =
|
|
4738
|
+
const srcPath = path12.join(src, entry.name);
|
|
4739
|
+
const destPath = path12.join(dest, entry.name);
|
|
4049
4740
|
if (entry.isDirectory()) {
|
|
4050
4741
|
copyDir(srcPath, destPath);
|
|
4051
4742
|
} else {
|
|
4052
|
-
|
|
4743
|
+
fs14.copyFileSync(srcPath, destPath);
|
|
4053
4744
|
}
|
|
4054
4745
|
}
|
|
4055
4746
|
}
|
|
4056
4747
|
function isSafeSkillName(name) {
|
|
4057
|
-
return name.trim().length > 0 && name !== "." && name !== ".." && !name.startsWith(".") && !
|
|
4748
|
+
return name.trim().length > 0 && name !== "." && name !== ".." && !name.startsWith(".") && !path12.isAbsolute(name) && !name.includes("/") && !name.includes("\\") && !name.includes("\0");
|
|
4058
4749
|
}
|
|
4059
4750
|
function isPathInside(childPath, parentPath) {
|
|
4060
|
-
const relativePath =
|
|
4061
|
-
return relativePath === "" || relativePath.length > 0 && !relativePath.startsWith("..") && !
|
|
4751
|
+
const relativePath = path12.relative(parentPath, childPath);
|
|
4752
|
+
return relativePath === "" || relativePath.length > 0 && !relativePath.startsWith("..") && !path12.isAbsolute(relativePath);
|
|
4062
4753
|
}
|
|
4063
4754
|
function addSkillFromGitHub(urlOrPreset) {
|
|
4064
4755
|
const preset = SKILL_PRESETS.find((p) => p.name === urlOrPreset);
|
|
@@ -4102,7 +4793,7 @@ function addSkillFromGitHub(urlOrPreset) {
|
|
|
4102
4793
|
}
|
|
4103
4794
|
let skillName;
|
|
4104
4795
|
if (parsed.path) {
|
|
4105
|
-
skillName =
|
|
4796
|
+
skillName = path12.basename(parsed.path);
|
|
4106
4797
|
} else {
|
|
4107
4798
|
skillName = parsed.repo;
|
|
4108
4799
|
}
|
|
@@ -4116,13 +4807,13 @@ function addSkillFromGitHub(urlOrPreset) {
|
|
|
4116
4807
|
}
|
|
4117
4808
|
function listInstalledSkills() {
|
|
4118
4809
|
const skillsDir = getSkillsDir();
|
|
4119
|
-
if (!
|
|
4810
|
+
if (!fs14.existsSync(skillsDir)) {
|
|
4120
4811
|
return [];
|
|
4121
4812
|
}
|
|
4122
|
-
const entries =
|
|
4813
|
+
const entries = fs14.readdirSync(skillsDir, { withFileTypes: true });
|
|
4123
4814
|
return entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => ({
|
|
4124
4815
|
name: entry.name,
|
|
4125
|
-
path:
|
|
4816
|
+
path: path12.join(skillsDir, entry.name)
|
|
4126
4817
|
}));
|
|
4127
4818
|
}
|
|
4128
4819
|
function removeSkill(name) {
|
|
@@ -4131,18 +4822,18 @@ function removeSkill(name) {
|
|
|
4131
4822
|
return false;
|
|
4132
4823
|
}
|
|
4133
4824
|
const skillsDir = getSkillsDir();
|
|
4134
|
-
const targetDir =
|
|
4135
|
-
if (!
|
|
4825
|
+
const targetDir = path12.resolve(skillsDir, name);
|
|
4826
|
+
if (!fs14.existsSync(targetDir)) {
|
|
4136
4827
|
console.error(chalk5.red(`Skill "${name}" not found`));
|
|
4137
4828
|
return false;
|
|
4138
4829
|
}
|
|
4139
|
-
const canonicalSkillsDir =
|
|
4140
|
-
const canonicalTargetDir =
|
|
4830
|
+
const canonicalSkillsDir = fs14.realpathSync(skillsDir);
|
|
4831
|
+
const canonicalTargetDir = fs14.realpathSync(targetDir);
|
|
4141
4832
|
if (!isPathInside(canonicalTargetDir, canonicalSkillsDir)) {
|
|
4142
4833
|
console.error(chalk5.red(`Refusing to remove skill outside skills directory: "${name}"`));
|
|
4143
4834
|
return false;
|
|
4144
4835
|
}
|
|
4145
|
-
|
|
4836
|
+
fs14.rmSync(targetDir, { recursive: true });
|
|
4146
4837
|
console.log(chalk5.green(`Removed skill "${name}"`));
|
|
4147
4838
|
return true;
|
|
4148
4839
|
}
|
|
@@ -4697,9 +5388,9 @@ import Table3 from "cli-table3";
|
|
|
4697
5388
|
|
|
4698
5389
|
// src/cron.ts
|
|
4699
5390
|
import crypto5 from "crypto";
|
|
4700
|
-
import * as
|
|
5391
|
+
import * as fs15 from "fs";
|
|
4701
5392
|
import * as os5 from "os";
|
|
4702
|
-
import * as
|
|
5393
|
+
import * as path13 from "path";
|
|
4703
5394
|
function parseHermesNotification(value) {
|
|
4704
5395
|
if (value == null) return null;
|
|
4705
5396
|
const target = value;
|
|
@@ -4763,13 +5454,13 @@ var EXECUTION_PROFILES = /* @__PURE__ */ new Set([
|
|
|
4763
5454
|
"autonomous"
|
|
4764
5455
|
]);
|
|
4765
5456
|
function getCronTasksPath(baseDir = getCcemConfigDir()) {
|
|
4766
|
-
return
|
|
5457
|
+
return path13.join(baseDir, CRON_TASKS_FILE_NAME);
|
|
4767
5458
|
}
|
|
4768
5459
|
function readCronTasks(tasksPath = getCronTasksPath()) {
|
|
4769
|
-
if (!
|
|
5460
|
+
if (!fs15.existsSync(tasksPath)) {
|
|
4770
5461
|
return [];
|
|
4771
5462
|
}
|
|
4772
|
-
const content =
|
|
5463
|
+
const content = fs15.readFileSync(tasksPath, "utf-8").trim();
|
|
4773
5464
|
if (!content) {
|
|
4774
5465
|
return [];
|
|
4775
5466
|
}
|
|
@@ -4784,14 +5475,14 @@ function writeCronTasks(tasks, tasksPath = getCronTasksPath()) {
|
|
|
4784
5475
|
if (tasksPath === getCronTasksPath()) {
|
|
4785
5476
|
ensureCcemDir();
|
|
4786
5477
|
} else {
|
|
4787
|
-
|
|
5478
|
+
fs15.mkdirSync(path13.dirname(tasksPath), { recursive: true });
|
|
4788
5479
|
}
|
|
4789
5480
|
const payload = { tasks };
|
|
4790
5481
|
const content = `${JSON.stringify(payload, null, 2)}
|
|
4791
5482
|
`;
|
|
4792
5483
|
const tempPath = `${tasksPath}.${process.pid}.${Date.now()}.tmp`;
|
|
4793
|
-
|
|
4794
|
-
|
|
5484
|
+
fs15.writeFileSync(tempPath, content, { encoding: "utf-8", mode: 384 });
|
|
5485
|
+
fs15.renameSync(tempPath, tasksPath);
|
|
4795
5486
|
}
|
|
4796
5487
|
function validateCronExpression(cronExpression) {
|
|
4797
5488
|
const fields = cronExpression.trim().split(/\s+/);
|
|
@@ -4918,10 +5609,10 @@ function deleteCronTask(selector, tasksPath = getCronTasksPath()) {
|
|
|
4918
5609
|
}
|
|
4919
5610
|
function resolveJsonInput(raw) {
|
|
4920
5611
|
if (raw === "-") {
|
|
4921
|
-
return
|
|
5612
|
+
return fs15.readFileSync(0, "utf-8");
|
|
4922
5613
|
}
|
|
4923
5614
|
if (raw.startsWith("@")) {
|
|
4924
|
-
return
|
|
5615
|
+
return fs15.readFileSync(path13.resolve(raw.slice(1)), "utf-8");
|
|
4925
5616
|
}
|
|
4926
5617
|
return raw;
|
|
4927
5618
|
}
|
|
@@ -5066,7 +5757,7 @@ function registerCronCommands(program2) {
|
|
|
5066
5757
|
import chalk8 from "chalk";
|
|
5067
5758
|
|
|
5068
5759
|
// src/dsh/provider.ts
|
|
5069
|
-
import { createHash } from "crypto";
|
|
5760
|
+
import { createHash as createHash2 } from "crypto";
|
|
5070
5761
|
var DSH_API_KEY_ENV = "CCEM_DSH_API_KEY";
|
|
5071
5762
|
var DSH_PROTOCOL = "anthropic-messages";
|
|
5072
5763
|
var DSH_TIERS = ["opus", "sonnet", "haiku"];
|
|
@@ -5109,7 +5800,7 @@ function collectDshModels(envName, envConfig) {
|
|
|
5109
5800
|
}
|
|
5110
5801
|
function generateProviderId(envName) {
|
|
5111
5802
|
const slug = envName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 24) || "env";
|
|
5112
|
-
const hash =
|
|
5803
|
+
const hash = createHash2("sha256").update(envName).digest("hex").slice(0, 12);
|
|
5113
5804
|
return `ccem-${slug}-${hash}`;
|
|
5114
5805
|
}
|
|
5115
5806
|
function verifyTokenPresence(envConfig) {
|
|
@@ -5198,9 +5889,9 @@ function deriveDshProvider(envName, envConfig, options = {}) {
|
|
|
5198
5889
|
|
|
5199
5890
|
// src/dsh/launcher.ts
|
|
5200
5891
|
import { spawn as defaultSpawn } from "child_process";
|
|
5201
|
-
import * as
|
|
5892
|
+
import * as fs17 from "fs";
|
|
5202
5893
|
import * as os7 from "os";
|
|
5203
|
-
import * as
|
|
5894
|
+
import * as path15 from "path";
|
|
5204
5895
|
|
|
5205
5896
|
// src/dsh/patch.ts
|
|
5206
5897
|
var IDENTIFIER_PATTERN = /^[A-Za-z0-9][\w./-]*$/;
|
|
@@ -5238,9 +5929,9 @@ function renderCordisPatch(spec) {
|
|
|
5238
5929
|
|
|
5239
5930
|
// src/dsh/environment.ts
|
|
5240
5931
|
import { execFile } from "child_process";
|
|
5241
|
-
import * as
|
|
5932
|
+
import * as fs16 from "fs";
|
|
5242
5933
|
import * as os6 from "os";
|
|
5243
|
-
import * as
|
|
5934
|
+
import * as path14 from "path";
|
|
5244
5935
|
import { promisify } from "util";
|
|
5245
5936
|
|
|
5246
5937
|
// src/dsh/version.ts
|
|
@@ -5311,17 +6002,17 @@ function resolveDshRoot(env = process.env) {
|
|
|
5311
6002
|
const inherited = env.DSH_HOME?.trim();
|
|
5312
6003
|
if (inherited) return inherited;
|
|
5313
6004
|
const home = env.HOME?.trim() || os6.homedir();
|
|
5314
|
-
return
|
|
6005
|
+
return path14.join(home, ".dsh");
|
|
5315
6006
|
}
|
|
5316
6007
|
function resolveBinOnPath(name, env = process.env, platform = process.platform) {
|
|
5317
6008
|
if (name.includes("/") || platform === "win32" && name.includes("\\")) {
|
|
5318
6009
|
return fileIsExecutable(name, platform) ? name : null;
|
|
5319
6010
|
}
|
|
5320
|
-
const searchDirs = (env.PATH ?? "").split(
|
|
6011
|
+
const searchDirs = (env.PATH ?? "").split(path14.delimiter).filter(Boolean);
|
|
5321
6012
|
const extensions = platform === "win32" ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").toLowerCase().split(";").filter(Boolean) : [""];
|
|
5322
6013
|
for (const dir of searchDirs) {
|
|
5323
6014
|
for (const ext of extensions) {
|
|
5324
|
-
const candidate =
|
|
6015
|
+
const candidate = path14.join(dir, name + ext);
|
|
5325
6016
|
if (fileIsExecutable(candidate, platform)) return candidate;
|
|
5326
6017
|
}
|
|
5327
6018
|
}
|
|
@@ -5330,10 +6021,10 @@ function resolveBinOnPath(name, env = process.env, platform = process.platform)
|
|
|
5330
6021
|
function fileIsExecutable(file, platform = process.platform) {
|
|
5331
6022
|
try {
|
|
5332
6023
|
if (platform === "win32") {
|
|
5333
|
-
return
|
|
6024
|
+
return fs16.statSync(file).isFile();
|
|
5334
6025
|
}
|
|
5335
|
-
|
|
5336
|
-
return
|
|
6026
|
+
fs16.accessSync(file, fs16.constants.X_OK);
|
|
6027
|
+
return fs16.statSync(file).isFile();
|
|
5337
6028
|
} catch {
|
|
5338
6029
|
return false;
|
|
5339
6030
|
}
|
|
@@ -5351,15 +6042,15 @@ function resolveDshInvocation(deps = {}) {
|
|
|
5351
6042
|
function resolveWindowsDshInvocation(env) {
|
|
5352
6043
|
const dshFile = resolveBinOnPath("dsh", env, "win32");
|
|
5353
6044
|
if (!dshFile) return null;
|
|
5354
|
-
const ext =
|
|
6045
|
+
const ext = path14.extname(dshFile).toLowerCase();
|
|
5355
6046
|
if (ext === ".exe" || ext === ".com") {
|
|
5356
6047
|
return { bin: dshFile, prefix: [] };
|
|
5357
6048
|
}
|
|
5358
6049
|
if (ext !== ".cmd") return null;
|
|
5359
|
-
const shimDir =
|
|
6050
|
+
const shimDir = path14.dirname(dshFile);
|
|
5360
6051
|
const candidates = [
|
|
5361
|
-
|
|
5362
|
-
|
|
6052
|
+
path14.join(shimDir, "node_modules", "@deepseek-ai", "dsh"),
|
|
6053
|
+
path14.join(shimDir, "..", "node_modules", "@deepseek-ai", "dsh")
|
|
5363
6054
|
];
|
|
5364
6055
|
for (const pkgDir of candidates) {
|
|
5365
6056
|
const entryScript = verifyDshPackage(pkgDir);
|
|
@@ -5372,18 +6063,18 @@ function resolveWindowsDshInvocation(env) {
|
|
|
5372
6063
|
return null;
|
|
5373
6064
|
}
|
|
5374
6065
|
function verifyDshPackage(pkgDir) {
|
|
5375
|
-
const pkgJsonPath =
|
|
6066
|
+
const pkgJsonPath = path14.join(pkgDir, "package.json");
|
|
5376
6067
|
try {
|
|
5377
|
-
const raw =
|
|
6068
|
+
const raw = fs16.readFileSync(pkgJsonPath, "utf-8");
|
|
5378
6069
|
const pkg2 = JSON.parse(raw);
|
|
5379
6070
|
if (pkg2.name !== "@deepseek-ai/dsh") return null;
|
|
5380
6071
|
const binEntry = typeof pkg2.bin === "string" ? pkg2.bin : pkg2.bin?.dsh ?? null;
|
|
5381
6072
|
if (!binEntry || typeof binEntry !== "string") return null;
|
|
5382
|
-
const entryPath =
|
|
5383
|
-
const realEntry =
|
|
5384
|
-
const realPkgDir =
|
|
5385
|
-
if (!realEntry.startsWith(realPkgDir +
|
|
5386
|
-
if (!
|
|
6073
|
+
const entryPath = path14.resolve(pkgDir, binEntry);
|
|
6074
|
+
const realEntry = fs16.realpathSync(entryPath);
|
|
6075
|
+
const realPkgDir = fs16.realpathSync(pkgDir);
|
|
6076
|
+
if (!realEntry.startsWith(realPkgDir + path14.sep) && realEntry !== realPkgDir) return null;
|
|
6077
|
+
if (!fs16.statSync(realEntry).isFile()) return null;
|
|
5387
6078
|
return realEntry;
|
|
5388
6079
|
} catch {
|
|
5389
6080
|
return null;
|
|
@@ -5521,7 +6212,7 @@ var DSH_PERMISSION_MODES = [
|
|
|
5521
6212
|
];
|
|
5522
6213
|
var DSH_PERMISSION_ENV = "DSH_PERMISSION_MODE";
|
|
5523
6214
|
function cleanupTempDir(dir) {
|
|
5524
|
-
|
|
6215
|
+
fs17.rmSync(dir, { recursive: true, force: true });
|
|
5525
6216
|
}
|
|
5526
6217
|
function signalExitCode(signal) {
|
|
5527
6218
|
if (!signal) return 1;
|
|
@@ -5626,10 +6317,10 @@ async function runDshTask(options) {
|
|
|
5626
6317
|
};
|
|
5627
6318
|
}
|
|
5628
6319
|
const inheritedDshHome = env.DSH_HOME?.trim() || void 0;
|
|
5629
|
-
const tempDir =
|
|
5630
|
-
const patchPath =
|
|
6320
|
+
const tempDir = fs17.mkdtempSync(path15.join(os7.tmpdir(), "ccem-dsh-"));
|
|
6321
|
+
const patchPath = path15.join(tempDir, "cordis.ccem.patch.yml");
|
|
5631
6322
|
const patchContent = renderCordisPatch(options.spec);
|
|
5632
|
-
|
|
6323
|
+
fs17.writeFileSync(patchPath, patchContent, { mode: 384 });
|
|
5633
6324
|
let exitCode = null;
|
|
5634
6325
|
let signal = null;
|
|
5635
6326
|
let spawnError = null;
|
|
@@ -5998,9 +6689,9 @@ Note: Use -- to separate task text from options if the task could be
|
|
|
5998
6689
|
|
|
5999
6690
|
// src/index.ts
|
|
6000
6691
|
var __filename2 = fileURLToPath2(import.meta.url);
|
|
6001
|
-
var __dirname2 =
|
|
6002
|
-
var pkgPath =
|
|
6003
|
-
var pkg = JSON.parse(
|
|
6692
|
+
var __dirname2 = path16.dirname(__filename2);
|
|
6693
|
+
var pkgPath = path16.resolve(__dirname2, "..", "package.json");
|
|
6694
|
+
var pkg = JSON.parse(fs18.readFileSync(pkgPath, "utf-8"));
|
|
6004
6695
|
var program = new Command();
|
|
6005
6696
|
var DEFAULT_OFFICIAL_ENV = {
|
|
6006
6697
|
ANTHROPIC_BASE_URL: "https://api.anthropic.com",
|
|
@@ -6087,13 +6778,13 @@ var recoverRegistriesFromLegacy = (registries) => {
|
|
|
6087
6778
|
return registries;
|
|
6088
6779
|
}
|
|
6089
6780
|
const legacyConfigPath = getLegacyConfigPath();
|
|
6090
|
-
if (!
|
|
6781
|
+
if (!fs18.existsSync(legacyConfigPath)) {
|
|
6091
6782
|
return registries;
|
|
6092
6783
|
}
|
|
6093
6784
|
try {
|
|
6094
|
-
const legacyRaw = JSON.parse(
|
|
6785
|
+
const legacyRaw = JSON.parse(fs18.readFileSync(legacyConfigPath, "utf-8"));
|
|
6095
6786
|
const legacyRegistries = legacyRaw.registries ?? {};
|
|
6096
|
-
let
|
|
6787
|
+
let changed2 = false;
|
|
6097
6788
|
const recovered = { ...registries };
|
|
6098
6789
|
for (const [name, envConfig] of Object.entries(registries)) {
|
|
6099
6790
|
const legacyEnvConfig = legacyRegistries[name];
|
|
@@ -6103,10 +6794,10 @@ var recoverRegistriesFromLegacy = (registries) => {
|
|
|
6103
6794
|
const recoveredEnv = recoverEnvConfigFromLegacy(envConfig, legacyEnvConfig);
|
|
6104
6795
|
if (JSON.stringify(recoveredEnv) !== JSON.stringify(envConfig)) {
|
|
6105
6796
|
recovered[name] = recoveredEnv;
|
|
6106
|
-
|
|
6797
|
+
changed2 = true;
|
|
6107
6798
|
}
|
|
6108
6799
|
}
|
|
6109
|
-
return
|
|
6800
|
+
return changed2 ? recovered : registries;
|
|
6110
6801
|
} catch {
|
|
6111
6802
|
return registries;
|
|
6112
6803
|
}
|
|
@@ -6123,8 +6814,8 @@ var getRegistries = () => {
|
|
|
6123
6814
|
repairedRegistries[OFFICIAL_ENV_NAME] = { ...DEFAULT_OFFICIAL_ENV };
|
|
6124
6815
|
}
|
|
6125
6816
|
assertOfficialEnvironmentInvariant(repairedRegistries);
|
|
6126
|
-
const
|
|
6127
|
-
if (
|
|
6817
|
+
const changed2 = Object.keys(rawRegistries).length !== Object.keys(repairedRegistries).length || JSON.stringify(rawRegistries) !== JSON.stringify(repairedRegistries);
|
|
6818
|
+
if (changed2) {
|
|
6128
6819
|
config2.set("registries", repairedRegistries);
|
|
6129
6820
|
}
|
|
6130
6821
|
return repairedRegistries;
|
|
@@ -6294,15 +6985,15 @@ var switchEnvironment = async (name) => {
|
|
|
6294
6985
|
exportCmds.forEach((cmd) => console.log(cmd));
|
|
6295
6986
|
}
|
|
6296
6987
|
};
|
|
6297
|
-
var getSessionsFilePath = () =>
|
|
6298
|
-
var getRuntimeStateFilePath = () =>
|
|
6299
|
-
var getBotBindRequestFilePath = () =>
|
|
6988
|
+
var getSessionsFilePath = () => path16.join(getCcemConfigDir(), "sessions.json");
|
|
6989
|
+
var getRuntimeStateFilePath = () => path16.join(getCcemConfigDir(), "runtime-state.json");
|
|
6990
|
+
var getBotBindRequestFilePath = () => path16.join(getCcemConfigDir(), "bot-bind-requests.jsonl");
|
|
6300
6991
|
var parseJsonFile = (filePath) => {
|
|
6301
|
-
if (!
|
|
6992
|
+
if (!fs18.existsSync(filePath)) {
|
|
6302
6993
|
return null;
|
|
6303
6994
|
}
|
|
6304
6995
|
try {
|
|
6305
|
-
return JSON.parse(
|
|
6996
|
+
return JSON.parse(fs18.readFileSync(filePath, "utf-8"));
|
|
6306
6997
|
} catch {
|
|
6307
6998
|
return null;
|
|
6308
6999
|
}
|
|
@@ -6394,8 +7085,8 @@ var resolveBotBindRuntimeId = (explicitRuntimeId) => {
|
|
|
6394
7085
|
};
|
|
6395
7086
|
var appendBotBindRequest = (payload) => {
|
|
6396
7087
|
const requestPath = getBotBindRequestFilePath();
|
|
6397
|
-
|
|
6398
|
-
|
|
7088
|
+
fs18.mkdirSync(path16.dirname(requestPath), { recursive: true });
|
|
7089
|
+
fs18.appendFileSync(requestPath, `${JSON.stringify(payload)}
|
|
6399
7090
|
`, "utf-8");
|
|
6400
7091
|
return requestPath;
|
|
6401
7092
|
};
|
|
@@ -6698,12 +7389,12 @@ setupCmd.command("migrate").description("\u8FC1\u79FB\u65E7\u7248\u914D\u7F6E\u5
|
|
|
6698
7389
|
const newConfigPath = getCcemConfigPath();
|
|
6699
7390
|
const legacyConfigPath = getLegacyConfigPath();
|
|
6700
7391
|
console.log(chalk9.cyan("\n\u{1F504} \u914D\u7F6E\u8FC1\u79FB\n"));
|
|
6701
|
-
if (!
|
|
7392
|
+
if (!fs18.existsSync(legacyConfigPath)) {
|
|
6702
7393
|
console.log(chalk9.yellow("\u672A\u627E\u5230\u65E7\u7248\u914D\u7F6E\u6587\u4EF6"));
|
|
6703
7394
|
console.log(chalk9.gray(` \u65E7\u8DEF\u5F84: ${legacyConfigPath}`));
|
|
6704
7395
|
return;
|
|
6705
7396
|
}
|
|
6706
|
-
if (
|
|
7397
|
+
if (fs18.existsSync(newConfigPath) && !options.force) {
|
|
6707
7398
|
console.log(chalk9.green("\u2713 \u914D\u7F6E\u5DF2\u5728\u65B0\u8DEF\u5F84"));
|
|
6708
7399
|
console.log(chalk9.gray(` \u8DEF\u5F84: ${newConfigPath}`));
|
|
6709
7400
|
console.log(chalk9.gray("\n\u4F7F\u7528 --force \u5F3A\u5236\u91CD\u65B0\u8FC1\u79FB"));
|
|
@@ -6711,7 +7402,7 @@ setupCmd.command("migrate").description("\u8FC1\u79FB\u65E7\u7248\u914D\u7F6E\u5
|
|
|
6711
7402
|
}
|
|
6712
7403
|
try {
|
|
6713
7404
|
ensureCcemDir();
|
|
6714
|
-
const legacyRaw = JSON.parse(
|
|
7405
|
+
const legacyRaw = JSON.parse(fs18.readFileSync(legacyConfigPath, "utf-8"));
|
|
6715
7406
|
const migrated = normalizeCcemConfig(legacyRaw);
|
|
6716
7407
|
if (!migrated.registries[OFFICIAL_ENV_NAME]) {
|
|
6717
7408
|
migrated.registries[OFFICIAL_ENV_NAME] = { ...DEFAULT_OFFICIAL_ENV };
|
|
@@ -6722,10 +7413,10 @@ setupCmd.command("migrate").description("\u8FC1\u79FB\u65E7\u7248\u914D\u7F6E\u5
|
|
|
6722
7413
|
console.log(chalk9.gray(` \u4ECE: ${legacyConfigPath}`));
|
|
6723
7414
|
console.log(chalk9.gray(` \u5230: ${newConfigPath}`));
|
|
6724
7415
|
if (options.clean) {
|
|
6725
|
-
|
|
6726
|
-
const legacyDir =
|
|
7416
|
+
fs18.unlinkSync(legacyConfigPath);
|
|
7417
|
+
const legacyDir = path16.dirname(legacyConfigPath);
|
|
6727
7418
|
try {
|
|
6728
|
-
|
|
7419
|
+
fs18.rmdirSync(legacyDir);
|
|
6729
7420
|
} catch {
|
|
6730
7421
|
}
|
|
6731
7422
|
console.log(chalk9.green("\u2713 \u5DF2\u5220\u9664\u65E7\u914D\u7F6E\u6587\u4EF6"));
|
|
@@ -6736,13 +7427,13 @@ setupCmd.command("migrate").description("\u8FC1\u79FB\u65E7\u7248\u914D\u7F6E\u5
|
|
|
6736
7427
|
});
|
|
6737
7428
|
setupCmd.command("cron").description("\u5B89\u88C5 ccem-cron skill \u5230 CCEM \u7684 Claude Code").option("--force", "\u5F3A\u5236\u8986\u76D6\u5DF2\u6709\u6587\u4EF6").action(async function() {
|
|
6738
7429
|
const options = this.opts();
|
|
6739
|
-
const skillDir =
|
|
6740
|
-
const targetPath =
|
|
6741
|
-
if (!
|
|
6742
|
-
|
|
7430
|
+
const skillDir = path16.join(ensureCcemAgentHome("claude"), "skills");
|
|
7431
|
+
const targetPath = path16.join(skillDir, "ccem-cron.md");
|
|
7432
|
+
if (!fs18.existsSync(skillDir)) {
|
|
7433
|
+
fs18.mkdirSync(skillDir, { recursive: true });
|
|
6743
7434
|
console.log(chalk9.gray(`\u521B\u5EFA\u76EE\u5F55: ${skillDir}`));
|
|
6744
7435
|
}
|
|
6745
|
-
if (
|
|
7436
|
+
if (fs18.existsSync(targetPath) && !options.force) {
|
|
6746
7437
|
const { overwrite } = await inquirer.prompt([
|
|
6747
7438
|
{
|
|
6748
7439
|
type: "confirm",
|
|
@@ -6756,7 +7447,7 @@ setupCmd.command("cron").description("\u5B89\u88C5 ccem-cron skill \u5230 CCEM \
|
|
|
6756
7447
|
return;
|
|
6757
7448
|
}
|
|
6758
7449
|
}
|
|
6759
|
-
|
|
7450
|
+
fs18.writeFileSync(targetPath, CCEM_CRON_SKILL_CONTENT, "utf-8");
|
|
6760
7451
|
console.log(chalk9.green(`\u2713 \u5DF2\u5B89\u88C5 ccem-cron skill`));
|
|
6761
7452
|
console.log(chalk9.gray(` \u8DEF\u5F84: ${targetPath}`));
|
|
6762
7453
|
console.log(chalk9.cyan(`
|
|
@@ -6764,13 +7455,13 @@ setupCmd.command("cron").description("\u5B89\u88C5 ccem-cron skill \u5230 CCEM \
|
|
|
6764
7455
|
});
|
|
6765
7456
|
setupCmd.command("bot-bind").description("\u5B89\u88C5 ccem-bot-bind skill \u5230 CCEM \u7684 Claude Code").option("--force", "\u5F3A\u5236\u8986\u76D6\u5DF2\u6709\u6587\u4EF6").action(async function() {
|
|
6766
7457
|
const options = this.opts();
|
|
6767
|
-
const skillDir =
|
|
6768
|
-
const targetPath =
|
|
6769
|
-
if (!
|
|
6770
|
-
|
|
7458
|
+
const skillDir = path16.join(ensureCcemAgentHome("claude"), "skills");
|
|
7459
|
+
const targetPath = path16.join(skillDir, "ccem-bot-bind.md");
|
|
7460
|
+
if (!fs18.existsSync(skillDir)) {
|
|
7461
|
+
fs18.mkdirSync(skillDir, { recursive: true });
|
|
6771
7462
|
console.log(chalk9.gray(`\u521B\u5EFA\u76EE\u5F55: ${skillDir}`));
|
|
6772
7463
|
}
|
|
6773
|
-
if (
|
|
7464
|
+
if (fs18.existsSync(targetPath) && !options.force) {
|
|
6774
7465
|
const { overwrite } = await inquirer.prompt([
|
|
6775
7466
|
{
|
|
6776
7467
|
type: "confirm",
|
|
@@ -6784,7 +7475,7 @@ setupCmd.command("bot-bind").description("\u5B89\u88C5 ccem-bot-bind skill \u523
|
|
|
6784
7475
|
return;
|
|
6785
7476
|
}
|
|
6786
7477
|
}
|
|
6787
|
-
|
|
7478
|
+
fs18.writeFileSync(targetPath, CCEM_BOT_BIND_SKILL_CONTENT, "utf-8");
|
|
6788
7479
|
console.log(chalk9.green(`\u2713 \u5DF2\u5B89\u88C5 ccem-bot-bind skill`));
|
|
6789
7480
|
console.log(chalk9.gray(` \u8DEF\u5F84: ${targetPath}`));
|
|
6790
7481
|
console.log(chalk9.cyan(`
|
|
@@ -6961,7 +7652,7 @@ desktopCmd.command("send <runtimeId>").description("Send input to a CCEM Desktop
|
|
|
6961
7652
|
const opts = this.opts();
|
|
6962
7653
|
const result = await requestDesktopControl("ccem.workspace.sendInput", {
|
|
6963
7654
|
runtimeId,
|
|
6964
|
-
clientMessageId: opts.messageId?.trim() || `ccem-cli-${
|
|
7655
|
+
clientMessageId: opts.messageId?.trim() || `ccem-cli-${randomUUID4()}`,
|
|
6965
7656
|
text: opts.text,
|
|
6966
7657
|
displayText: opts.displayText ?? null
|
|
6967
7658
|
});
|