ai-project-manage-cli 7.1.35 → 7.1.37
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 +104 -219
- package/dist/webide-message-worker.js +59 -139
- package/package.json +1 -2
package/dist/index.js
CHANGED
|
@@ -1001,19 +1001,11 @@ init_config();
|
|
|
1001
1001
|
|
|
1002
1002
|
// src/commands/init.ts
|
|
1003
1003
|
import { join as join6 } from "path";
|
|
1004
|
-
import { readFileSync as
|
|
1004
|
+
import { readFileSync as readFileSync4, writeFileSync as writeFileSync5 } from "fs";
|
|
1005
1005
|
|
|
1006
1006
|
// src/command-utils.ts
|
|
1007
1007
|
init_config();
|
|
1008
|
-
import {
|
|
1009
|
-
copyFileSync,
|
|
1010
|
-
existsSync,
|
|
1011
|
-
mkdirSync as mkdirSync2,
|
|
1012
|
-
readFileSync as readFileSync2,
|
|
1013
|
-
readdirSync,
|
|
1014
|
-
statSync,
|
|
1015
|
-
writeFileSync as writeFileSync2
|
|
1016
|
-
} from "fs";
|
|
1008
|
+
import { copyFileSync, existsSync, mkdirSync as mkdirSync2, readdirSync, statSync } from "fs";
|
|
1017
1009
|
import { basename, dirname, extname, join as join2, resolve as resolve2 } from "path";
|
|
1018
1010
|
import { fileURLToPath } from "url";
|
|
1019
1011
|
|
|
@@ -1084,63 +1076,6 @@ function isWorkspaceApmInitialized(workdir) {
|
|
|
1084
1076
|
}
|
|
1085
1077
|
return readdirSync(fsApmDir).length > 0;
|
|
1086
1078
|
}
|
|
1087
|
-
var APM_GITIGNORE_PATTERNS = [
|
|
1088
|
-
/^\.apm\/?$/,
|
|
1089
|
-
/^\.apm\/\*\*$/,
|
|
1090
|
-
/^\*\*\/\.apm\/?$/,
|
|
1091
|
-
/^\*\*\/\.apm\/\*\*$/,
|
|
1092
|
-
/^\/\.apm\/?$/,
|
|
1093
|
-
/^\/\.apm\/\*\*$/
|
|
1094
|
-
];
|
|
1095
|
-
function normalizeGitignorePattern(line) {
|
|
1096
|
-
const trimmed = line.trim();
|
|
1097
|
-
if (!trimmed || trimmed.startsWith("#")) return "";
|
|
1098
|
-
if (trimmed.startsWith("!")) return "";
|
|
1099
|
-
const hashIndex = trimmed.indexOf("#");
|
|
1100
|
-
return (hashIndex >= 0 ? trimmed.slice(0, hashIndex) : trimmed).trim();
|
|
1101
|
-
}
|
|
1102
|
-
function gitignoreIgnoresApm(line) {
|
|
1103
|
-
const pattern = normalizeGitignorePattern(line);
|
|
1104
|
-
if (!pattern) return false;
|
|
1105
|
-
return APM_GITIGNORE_PATTERNS.some((re) => re.test(pattern));
|
|
1106
|
-
}
|
|
1107
|
-
var APM_GITIGNORE_LINE = "**/.apm/**";
|
|
1108
|
-
function ensureApmGitignoredInRepo(workdir) {
|
|
1109
|
-
const gitignorePath = join2(workdir, ".gitignore");
|
|
1110
|
-
const fsGitignorePath = toFsPath(gitignorePath);
|
|
1111
|
-
if (!existsSync(fsGitignorePath)) {
|
|
1112
|
-
writeFileSync2(fsGitignorePath, `${APM_GITIGNORE_LINE}
|
|
1113
|
-
`, "utf8");
|
|
1114
|
-
return true;
|
|
1115
|
-
}
|
|
1116
|
-
const content = readFileSync2(fsGitignorePath, "utf8");
|
|
1117
|
-
if (content.split(/\r?\n/).some(gitignoreIgnoresApm)) {
|
|
1118
|
-
return false;
|
|
1119
|
-
}
|
|
1120
|
-
const suffix = content.endsWith("\n") || content.length === 0 ? "" : "\n";
|
|
1121
|
-
writeFileSync2(
|
|
1122
|
-
fsGitignorePath,
|
|
1123
|
-
`${content}${suffix}${APM_GITIGNORE_LINE}
|
|
1124
|
-
`,
|
|
1125
|
-
"utf8"
|
|
1126
|
-
);
|
|
1127
|
-
return true;
|
|
1128
|
-
}
|
|
1129
|
-
function assertApmGitignoredInRepo(workdir) {
|
|
1130
|
-
const gitignorePath = join2(workdir, ".gitignore");
|
|
1131
|
-
const fsGitignorePath = toFsPath(gitignorePath);
|
|
1132
|
-
if (!existsSync(fsGitignorePath)) {
|
|
1133
|
-
throw new Error(
|
|
1134
|
-
`\u5DE5\u4F5C\u76EE\u5F55 ${workdir} \u7F3A\u5C11 .gitignore \u6587\u4EF6\uFF0C\u8BF7\u6DFB\u52A0\u5BF9 .apm \u7684\u5FFD\u7565\u89C4\u5219\uFF08\u4F8B\u5982 **/.apm/**\uFF09\uFF0C\u907F\u514D\u672C\u5730\u4F1A\u8BDD\u4E0E\u90E8\u7F72\u51ED\u636E\u88AB\u63D0\u4EA4\u3002`
|
|
1135
|
-
);
|
|
1136
|
-
}
|
|
1137
|
-
const content = readFileSync2(fsGitignorePath, "utf8");
|
|
1138
|
-
if (!content.split(/\r?\n/).some(gitignoreIgnoresApm)) {
|
|
1139
|
-
throw new Error(
|
|
1140
|
-
`\u5DE5\u4F5C\u76EE\u5F55 ${workdir} \u7684 .gitignore \u672A\u5FFD\u7565 .apm\uFF0C\u8BF7\u6DFB\u52A0 **/.apm/** \u6216 .apm/\uFF0C\u907F\u514D\u672C\u5730\u4F1A\u8BDD\u4E0E\u90E8\u7F72\u51ED\u636E\u88AB\u63D0\u4EA4\u3002`
|
|
1141
|
-
);
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
1079
|
var SESSIONS_SUBDIR = "sessions";
|
|
1145
1080
|
var SESSION_DOCS_SUBDIR = "docs";
|
|
1146
1081
|
var SESSION_ATTACHMENTS_SUBDIR = "attachments";
|
|
@@ -1199,19 +1134,10 @@ async function ensureDirExists(dir) {
|
|
|
1199
1134
|
async function ensureWorkspaceApmDirForInit(cwd = resolveWorkdirPath()) {
|
|
1200
1135
|
const dir = workspaceApmDir(cwd);
|
|
1201
1136
|
const fsDir = toFsPath(dir);
|
|
1202
|
-
if (
|
|
1203
|
-
mkdirSync2(fsDir, { recursive: true });
|
|
1204
|
-
return;
|
|
1205
|
-
}
|
|
1206
|
-
const st = statSync(fsDir);
|
|
1207
|
-
if (!st.isDirectory()) {
|
|
1137
|
+
if (existsSync(fsDir) && !statSync(fsDir).isDirectory()) {
|
|
1208
1138
|
throw new Error(`[apm] \u8DEF\u5F84\u5DF2\u5B58\u5728\u4F46\u4E0D\u662F\u76EE\u5F55: ${dir}`);
|
|
1209
1139
|
}
|
|
1210
|
-
|
|
1211
|
-
throw new Error(
|
|
1212
|
-
"[apm] .apm \u76EE\u5F55\u5DF2\u5B58\u5728\u4E14\u975E\u7A7A\uFF0C\u8BF7\u5148\u5907\u4EFD\u3001\u6E05\u7A7A\u6216\u5220\u9664\u540E\u518D\u6267\u884C init"
|
|
1213
|
-
);
|
|
1214
|
-
}
|
|
1140
|
+
mkdirSync2(fsDir, { recursive: true });
|
|
1215
1141
|
}
|
|
1216
1142
|
var WORKSPACE_TEMPLATE_SUBDIRS = [
|
|
1217
1143
|
"sessions",
|
|
@@ -1290,7 +1216,7 @@ async function copyTemplateFiles(targetDir, workdir = resolveWorkdirPath()) {
|
|
|
1290
1216
|
// src/deployment-config-sync.ts
|
|
1291
1217
|
init_client();
|
|
1292
1218
|
import { join as join4 } from "path";
|
|
1293
|
-
import { writeFileSync as
|
|
1219
|
+
import { writeFileSync as writeFileSync3 } from "fs";
|
|
1294
1220
|
|
|
1295
1221
|
// src/git-remote.ts
|
|
1296
1222
|
import { execFile } from "child_process";
|
|
@@ -1349,10 +1275,24 @@ async function tryReadHttpsGitOriginUrl(cwd) {
|
|
|
1349
1275
|
import { execFile as execFile2 } from "child_process";
|
|
1350
1276
|
import { promisify as promisify2 } from "util";
|
|
1351
1277
|
var execFileAsync2 = promisify2(execFile2);
|
|
1278
|
+
function gitExecEnv() {
|
|
1279
|
+
const existing = process.env.GIT_SSH_COMMAND?.trim();
|
|
1280
|
+
const acceptNew = "-o StrictHostKeyChecking=accept-new";
|
|
1281
|
+
let gitSshCommand;
|
|
1282
|
+
if (!existing) {
|
|
1283
|
+
gitSshCommand = `ssh ${acceptNew}`;
|
|
1284
|
+
} else if (/\bStrictHostKeyChecking=/.test(existing)) {
|
|
1285
|
+
gitSshCommand = existing;
|
|
1286
|
+
} else {
|
|
1287
|
+
gitSshCommand = `${existing} ${acceptNew}`;
|
|
1288
|
+
}
|
|
1289
|
+
return { ...process.env, GIT_SSH_COMMAND: gitSshCommand };
|
|
1290
|
+
}
|
|
1352
1291
|
async function execGit(cwd, args, quiet = false) {
|
|
1353
1292
|
try {
|
|
1354
1293
|
const { stdout, stderr } = await execFileAsync2("git", args, {
|
|
1355
1294
|
cwd,
|
|
1295
|
+
env: gitExecEnv(),
|
|
1356
1296
|
encoding: "utf8",
|
|
1357
1297
|
maxBuffer: 10 * 1024 * 1024
|
|
1358
1298
|
});
|
|
@@ -1424,46 +1364,6 @@ async function resolveDefaultRemoteBranch(cwd) {
|
|
|
1424
1364
|
"[apm] \u65E0\u6CD5\u786E\u5B9A\u8FDC\u7A0B\u9ED8\u8BA4\u5206\u652F\uFF08origin/HEAD\u3001main\u3001master \u5747\u4E0D\u53EF\u7528\uFF09"
|
|
1425
1365
|
);
|
|
1426
1366
|
}
|
|
1427
|
-
async function hasUpstream(cwd) {
|
|
1428
|
-
try {
|
|
1429
|
-
await execGit(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"], true);
|
|
1430
|
-
return true;
|
|
1431
|
-
} catch {
|
|
1432
|
-
return false;
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
async function pushCurrentBranch(cwd) {
|
|
1436
|
-
if (!await isGitRepo(cwd)) {
|
|
1437
|
-
return false;
|
|
1438
|
-
}
|
|
1439
|
-
const originUrl = await tryReadGitOriginUrl(cwd);
|
|
1440
|
-
if (!originUrl) {
|
|
1441
|
-
console.log("[apm] \u672A\u914D\u7F6E remote.origin\uFF0C\u8DF3\u8FC7 push");
|
|
1442
|
-
return false;
|
|
1443
|
-
}
|
|
1444
|
-
if (await hasUpstream(cwd)) {
|
|
1445
|
-
await execGit(cwd, ["push"]);
|
|
1446
|
-
} else {
|
|
1447
|
-
await execGit(cwd, ["push", "-u", "origin", "HEAD"]);
|
|
1448
|
-
}
|
|
1449
|
-
return true;
|
|
1450
|
-
}
|
|
1451
|
-
var GITIGNORE_COMMIT_MESSAGE = "chore(apm): ignore .apm directory";
|
|
1452
|
-
async function commitAndPushGitignore(workdir) {
|
|
1453
|
-
if (!await isGitRepo(workdir)) {
|
|
1454
|
-
console.log("[apm] \u5F53\u524D\u76EE\u5F55\u4E0D\u662F git \u4ED3\u5E93\uFF0C\u8BF7\u624B\u52A8\u63D0\u4EA4 .gitignore");
|
|
1455
|
-
return;
|
|
1456
|
-
}
|
|
1457
|
-
await execGit(workdir, ["add", "--", ".gitignore"]);
|
|
1458
|
-
await execGit(workdir, ["commit", "-m", GITIGNORE_COMMIT_MESSAGE]);
|
|
1459
|
-
console.log(`[apm] \u5DF2\u63D0\u4EA4 .gitignore: ${GITIGNORE_COMMIT_MESSAGE}`);
|
|
1460
|
-
const pushed = await pushCurrentBranch(workdir);
|
|
1461
|
-
if (pushed) {
|
|
1462
|
-
console.log("[apm] \u5DF2\u63A8\u9001 .gitignore");
|
|
1463
|
-
} else {
|
|
1464
|
-
console.log("[apm] \u672A\u914D\u7F6E remote.origin\uFF0C\u8BF7\u7A0D\u540E\u624B\u52A8 push .gitignore");
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
1367
|
|
|
1468
1368
|
// src/baseline-resolve.ts
|
|
1469
1369
|
function formatBaselineDiagnostic(workdirPath, baselineWorkdirPath, diagnostic) {
|
|
@@ -1555,10 +1455,10 @@ init_config();
|
|
|
1555
1455
|
import {
|
|
1556
1456
|
existsSync as existsSync2,
|
|
1557
1457
|
mkdirSync as mkdirSync3,
|
|
1558
|
-
readFileSync as
|
|
1458
|
+
readFileSync as readFileSync2,
|
|
1559
1459
|
readdirSync as readdirSync2,
|
|
1560
1460
|
statSync as statSync2,
|
|
1561
|
-
writeFileSync as
|
|
1461
|
+
writeFileSync as writeFileSync2
|
|
1562
1462
|
} from "fs";
|
|
1563
1463
|
import { basename as basename2, dirname as dirname2, join as join3, relative, resolve as resolve3 } from "path";
|
|
1564
1464
|
var WORKSPACE_REPOS_MANIFEST = "workspace-repos.json";
|
|
@@ -1593,7 +1493,7 @@ function readManifest(workdir) {
|
|
|
1593
1493
|
}
|
|
1594
1494
|
try {
|
|
1595
1495
|
const raw = JSON.parse(
|
|
1596
|
-
|
|
1496
|
+
readFileSync2(path19, "utf8")
|
|
1597
1497
|
);
|
|
1598
1498
|
if (raw?.version !== WORKSPACE_REPOS_VERSION) {
|
|
1599
1499
|
return null;
|
|
@@ -1626,7 +1526,7 @@ function writeManifest(workdir, manifest) {
|
|
|
1626
1526
|
const apmDir = toFsPath(workspaceApmDir(workdir));
|
|
1627
1527
|
mkdirSync3(apmDir, { recursive: true });
|
|
1628
1528
|
const path19 = toFsPath(manifestPath(workdir));
|
|
1629
|
-
|
|
1529
|
+
writeFileSync2(path19, `${JSON.stringify(manifest, null, 2)}
|
|
1630
1530
|
`, "utf8");
|
|
1631
1531
|
}
|
|
1632
1532
|
function isPathInsideOrEqual(parentAbs, childAbs) {
|
|
@@ -1780,7 +1680,7 @@ async function writeDeploymentConfigContent(apmDir, content, configName) {
|
|
|
1780
1680
|
return false;
|
|
1781
1681
|
}
|
|
1782
1682
|
const apmConfigPath = toFsPath(join4(apmDir, "apm.config.json"));
|
|
1783
|
-
|
|
1683
|
+
writeFileSync3(apmConfigPath, `${JSON.stringify(parsed, null, 2)}
|
|
1784
1684
|
`, "utf8");
|
|
1785
1685
|
console.log(`[apm] \u5DF2\u540C\u6B65\u5E73\u53F0\u90E8\u7F72\u914D\u7F6E: ${configName}`);
|
|
1786
1686
|
console.log("[apm] \u5DF2\u5199\u5165 .apm/apm.config.json");
|
|
@@ -1838,9 +1738,9 @@ init_config();
|
|
|
1838
1738
|
import {
|
|
1839
1739
|
existsSync as existsSync3,
|
|
1840
1740
|
readdirSync as readdirSync3,
|
|
1841
|
-
readFileSync as
|
|
1741
|
+
readFileSync as readFileSync3,
|
|
1842
1742
|
rmSync,
|
|
1843
|
-
writeFileSync as
|
|
1743
|
+
writeFileSync as writeFileSync4
|
|
1844
1744
|
} from "fs";
|
|
1845
1745
|
import { createHash } from "crypto";
|
|
1846
1746
|
import { dirname as dirname3, join as join5, relative as relative2, sep } from "path";
|
|
@@ -1890,7 +1790,7 @@ function readLocalManifest(apmRoot, projectId) {
|
|
|
1890
1790
|
}
|
|
1891
1791
|
try {
|
|
1892
1792
|
return JSON.parse(
|
|
1893
|
-
|
|
1793
|
+
readFileSync3(manifestPath3, "utf8")
|
|
1894
1794
|
);
|
|
1895
1795
|
} catch {
|
|
1896
1796
|
return null;
|
|
@@ -2023,7 +1923,7 @@ ${diagnostic ?? ""}`);
|
|
|
2023
1923
|
projectDocumentLocalPath(targetApmDir, projectId, doc.path)
|
|
2024
1924
|
);
|
|
2025
1925
|
await ensureDirExists(dirname3(absPath));
|
|
2026
|
-
|
|
1926
|
+
writeFileSync4(absPath, doc.content, "utf8");
|
|
2027
1927
|
downloaded += 1;
|
|
2028
1928
|
}
|
|
2029
1929
|
}
|
|
@@ -2037,7 +1937,7 @@ ${diagnostic ?? ""}`);
|
|
|
2037
1937
|
deleted += 1;
|
|
2038
1938
|
}
|
|
2039
1939
|
}
|
|
2040
|
-
|
|
1940
|
+
writeFileSync4(
|
|
2041
1941
|
toFsPath(join5(docsDir, MANIFEST_FILE)),
|
|
2042
1942
|
`${JSON.stringify(remoteManifest, null, 2)}
|
|
2043
1943
|
`,
|
|
@@ -2081,7 +1981,7 @@ async function syncProjectDocumentsPush(cfg, workdirPath, apmRoot, options) {
|
|
|
2081
1981
|
const absPath = toFsPath(
|
|
2082
1982
|
projectDocumentLocalPath(targetApmDir, projectId, path19)
|
|
2083
1983
|
);
|
|
2084
|
-
const content =
|
|
1984
|
+
const content = readFileSync3(absPath, "utf8");
|
|
2085
1985
|
const contentHash = hashLocalFileContent(content);
|
|
2086
1986
|
if (remoteHashByPath.get(path19) === contentHash) {
|
|
2087
1987
|
continue;
|
|
@@ -2102,18 +2002,8 @@ async function syncProjectDocumentsPush(cfg, workdirPath, apmRoot, options) {
|
|
|
2102
2002
|
}
|
|
2103
2003
|
|
|
2104
2004
|
// src/commands/init.ts
|
|
2105
|
-
async function
|
|
2106
|
-
if (isWorkspaceApmInitialized(workdir)) {
|
|
2107
|
-
return { didInit: false };
|
|
2108
|
-
}
|
|
2109
|
-
console.log(
|
|
2110
|
-
`[apm] \u5DE5\u4F5C\u76EE\u5F55 ${workdir} \u672A\u68C0\u6D4B\u5230\u5DF2\u521D\u59CB\u5316\u7684 .apm\uFF0C\u6B63\u5728\u81EA\u52A8\u521D\u59CB\u5316\u2026`
|
|
2111
|
-
);
|
|
2005
|
+
async function initializeWorkspace(workdir, options) {
|
|
2112
2006
|
await ensureWorkspaceApmDirForInit(workdir);
|
|
2113
|
-
if (ensureApmGitignoredInRepo(workdir)) {
|
|
2114
|
-
console.log("[apm] \u5DF2\u5728 .gitignore \u4E2D\u6DFB\u52A0 **/.apm/**");
|
|
2115
|
-
await commitAndPushGitignore(workdir);
|
|
2116
|
-
}
|
|
2117
2007
|
const apmDir = workspaceApmDir(workdir);
|
|
2118
2008
|
await copyTemplateFiles(apmDir, workdir);
|
|
2119
2009
|
const syncResult = await syncRemoteDeploymentConfig(workdir, apmDir);
|
|
@@ -2121,10 +2011,10 @@ async function ensureWorkspaceInitialized(workdir, options) {
|
|
|
2121
2011
|
const trimmedName = options?.name?.trim();
|
|
2122
2012
|
if (trimmedName) {
|
|
2123
2013
|
const apmConfigPath = toFsPath(join6(apmDir, "apm.config.json"));
|
|
2124
|
-
const config =
|
|
2014
|
+
const config = readFileSync4(apmConfigPath, "utf8");
|
|
2125
2015
|
const configJson = JSON.parse(config);
|
|
2126
2016
|
configJson.name = trimmedName;
|
|
2127
|
-
|
|
2017
|
+
writeFileSync5(
|
|
2128
2018
|
apmConfigPath,
|
|
2129
2019
|
`${JSON.stringify(configJson, null, 2)}
|
|
2130
2020
|
`,
|
|
@@ -2134,17 +2024,18 @@ async function ensureWorkspaceInitialized(workdir, options) {
|
|
|
2134
2024
|
console.log(`[apm] \u5DF2\u521D\u59CB\u5316\u5DE5\u4F5C\u533A\uFF1A${apmDir}`);
|
|
2135
2025
|
return { didInit: true, syncResult };
|
|
2136
2026
|
}
|
|
2027
|
+
async function ensureWorkspaceInitialized(workdir, options) {
|
|
2028
|
+
if (isWorkspaceApmInitialized(workdir)) {
|
|
2029
|
+
return { didInit: false };
|
|
2030
|
+
}
|
|
2031
|
+
console.log(
|
|
2032
|
+
`[apm] \u5DE5\u4F5C\u76EE\u5F55 ${workdir} \u672A\u68C0\u6D4B\u5230\u5DF2\u521D\u59CB\u5316\u7684 .apm\uFF0C\u6B63\u5728\u81EA\u52A8\u521D\u59CB\u5316\u2026`
|
|
2033
|
+
);
|
|
2034
|
+
return initializeWorkspace(workdir, options);
|
|
2035
|
+
}
|
|
2137
2036
|
async function runInit(name) {
|
|
2138
2037
|
const workdir = resolveWorkdirPath();
|
|
2139
|
-
await
|
|
2140
|
-
const { didInit, syncResult } = await ensureWorkspaceInitialized(workdir, {
|
|
2141
|
-
name
|
|
2142
|
-
});
|
|
2143
|
-
if (!didInit) {
|
|
2144
|
-
throw new Error(
|
|
2145
|
-
"[apm] .apm \u76EE\u5F55\u5DF2\u5B58\u5728\u4E14\u975E\u7A7A\uFF0C\u8BF7\u5148\u5907\u4EFD\u3001\u6E05\u7A7A\u6216\u5220\u9664\u540E\u518D\u6267\u884C init"
|
|
2146
|
-
);
|
|
2147
|
-
}
|
|
2038
|
+
const { syncResult } = await initializeWorkspace(workdir, { name });
|
|
2148
2039
|
console.log(`[apm] \u5DE5\u4F5C\u76EE\u5F55\u8DEF\u5F84\uFF1A${workdir}`);
|
|
2149
2040
|
if (syncResult && !syncResult.synced) {
|
|
2150
2041
|
console.log(
|
|
@@ -2668,7 +2559,7 @@ async function runCleanBranches(options = {}) {
|
|
|
2668
2559
|
|
|
2669
2560
|
// src/commands/pull.ts
|
|
2670
2561
|
init_client();
|
|
2671
|
-
import { writeFileSync as
|
|
2562
|
+
import { writeFileSync as writeFileSync9 } from "fs";
|
|
2672
2563
|
import { join as join10 } from "path";
|
|
2673
2564
|
import { stringify as yamlStringify } from "yaml";
|
|
2674
2565
|
|
|
@@ -2702,7 +2593,7 @@ function formatSessionMessagesXml(sessionId, messages) {
|
|
|
2702
2593
|
}
|
|
2703
2594
|
|
|
2704
2595
|
// src/commands/sync-session-attachments.ts
|
|
2705
|
-
import { existsSync as existsSync5, readFileSync as
|
|
2596
|
+
import { existsSync as existsSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync6 } from "fs";
|
|
2706
2597
|
import { join as join7 } from "path";
|
|
2707
2598
|
var MANIFEST_FILE2 = ".sync-manifest.json";
|
|
2708
2599
|
async function downloadAttachment(cfg, attachmentId) {
|
|
@@ -2725,7 +2616,7 @@ function loadManifest(dir) {
|
|
|
2725
2616
|
}
|
|
2726
2617
|
try {
|
|
2727
2618
|
const parsed = JSON.parse(
|
|
2728
|
-
|
|
2619
|
+
readFileSync5(path19, "utf8")
|
|
2729
2620
|
);
|
|
2730
2621
|
if (parsed?.version === 1 && parsed.attachments && typeof parsed.attachments === "object") {
|
|
2731
2622
|
return parsed;
|
|
@@ -2735,7 +2626,7 @@ function loadManifest(dir) {
|
|
|
2735
2626
|
return { version: 1, attachments: {} };
|
|
2736
2627
|
}
|
|
2737
2628
|
function saveManifest(dir, manifest) {
|
|
2738
|
-
|
|
2629
|
+
writeFileSync6(
|
|
2739
2630
|
join7(dir, MANIFEST_FILE2),
|
|
2740
2631
|
`${JSON.stringify(manifest, null, 2)}
|
|
2741
2632
|
`,
|
|
@@ -2768,7 +2659,7 @@ async function syncAttachmentsToDirectory(cfg, attachments, dir, logLabel) {
|
|
|
2768
2659
|
continue;
|
|
2769
2660
|
}
|
|
2770
2661
|
const buffer = await downloadAttachment(cfg, item.id);
|
|
2771
|
-
|
|
2662
|
+
writeFileSync6(dest, buffer);
|
|
2772
2663
|
nextManifest.attachments[item.id] = {
|
|
2773
2664
|
name: item.name,
|
|
2774
2665
|
createdAt
|
|
@@ -2791,7 +2682,7 @@ async function syncSessionAttachments(cfg, sessionId, attachments, apmRoot) {
|
|
|
2791
2682
|
// src/rules-sync.ts
|
|
2792
2683
|
init_client();
|
|
2793
2684
|
import { basename as basename3, extname as extname2, join as join9 } from "path";
|
|
2794
|
-
import { existsSync as existsSync7, readFileSync as
|
|
2685
|
+
import { existsSync as existsSync7, readFileSync as readFileSync6, rmSync as rmSync3, writeFileSync as writeFileSync8 } from "fs";
|
|
2795
2686
|
|
|
2796
2687
|
// src/skills-sync.ts
|
|
2797
2688
|
import {
|
|
@@ -2802,7 +2693,7 @@ import {
|
|
|
2802
2693
|
readdirSync as readdirSync4,
|
|
2803
2694
|
rmSync as rmSync2,
|
|
2804
2695
|
statSync as statSync3,
|
|
2805
|
-
writeFileSync as
|
|
2696
|
+
writeFileSync as writeFileSync7
|
|
2806
2697
|
} from "fs";
|
|
2807
2698
|
import { join as join8 } from "path";
|
|
2808
2699
|
var AGENTS_TEMPLATE_PATH = join8(CLI_TEMPLATE_DIR, "AGENTS.md");
|
|
@@ -2867,7 +2758,7 @@ function syncSupplementarySkills(skillsDir, list) {
|
|
|
2867
2758
|
}
|
|
2868
2759
|
const skillDir = join8(skillsDir, dirName);
|
|
2869
2760
|
mkdirSync4(skillDir, { recursive: true });
|
|
2870
|
-
|
|
2761
|
+
writeFileSync7(join8(skillDir, "SKILL.md"), skill.content ?? "", "utf8");
|
|
2871
2762
|
written.push(dirName);
|
|
2872
2763
|
}
|
|
2873
2764
|
const removed = [];
|
|
@@ -2899,7 +2790,7 @@ function loadManifest2(rulesDir) {
|
|
|
2899
2790
|
}
|
|
2900
2791
|
try {
|
|
2901
2792
|
const parsed = JSON.parse(
|
|
2902
|
-
|
|
2793
|
+
readFileSync6(toFsPath(path19), "utf8")
|
|
2903
2794
|
);
|
|
2904
2795
|
if (parsed?.version === 1 && parsed.rules && typeof parsed.rules === "object") {
|
|
2905
2796
|
return parsed;
|
|
@@ -2909,7 +2800,7 @@ function loadManifest2(rulesDir) {
|
|
|
2909
2800
|
return { version: 1, rules: {} };
|
|
2910
2801
|
}
|
|
2911
2802
|
function saveManifest2(rulesDir, manifest) {
|
|
2912
|
-
|
|
2803
|
+
writeFileSync8(
|
|
2913
2804
|
toFsPath(join9(rulesDir, MANIFEST_FILE3)),
|
|
2914
2805
|
`${JSON.stringify(manifest, null, 2)}
|
|
2915
2806
|
`,
|
|
@@ -2924,7 +2815,7 @@ function isRuleUpToDate(entry, rule, dest) {
|
|
|
2924
2815
|
if (entry.fileName !== ruleLocalFileName(rule.name)) return false;
|
|
2925
2816
|
const updatedAt = rule.updatedAt ?? "";
|
|
2926
2817
|
if (entry.updatedAt !== updatedAt) return false;
|
|
2927
|
-
const localContent =
|
|
2818
|
+
const localContent = readFileSync6(toFsPath(dest), "utf8");
|
|
2928
2819
|
return localContent === (rule.content ?? "");
|
|
2929
2820
|
}
|
|
2930
2821
|
async function syncPlatformRules(cfg, sessionId, workdirPath, apmRoot) {
|
|
@@ -2957,7 +2848,7 @@ async function syncPlatformRules(cfg, sessionId, workdirPath, apmRoot) {
|
|
|
2957
2848
|
console.log(`[apm] \u89C4\u5219\u65E0\u53D8\u5316\uFF0C\u5DF2\u8DF3\u8FC7: rules/${fileName}`);
|
|
2958
2849
|
continue;
|
|
2959
2850
|
}
|
|
2960
|
-
|
|
2851
|
+
writeFileSync8(toFsPath(dest), rule.content ?? "", "utf8");
|
|
2961
2852
|
nextManifest.rules[rule.id] = { fileName, updatedAt };
|
|
2962
2853
|
written.push(fileName);
|
|
2963
2854
|
console.log(`[apm] \u5DF2\u540C\u6B65\u5E73\u53F0\u89C4\u5219: rules/${fileName}`);
|
|
@@ -2998,20 +2889,20 @@ async function runPull(sessionId, remoteWorkdir) {
|
|
|
2998
2889
|
const dir = sessionDir(trimmedId, apmRoot);
|
|
2999
2890
|
const docsDir = sessionDocsDir(trimmedId, apmRoot);
|
|
3000
2891
|
await ensureDirExists(docsDir);
|
|
3001
|
-
|
|
2892
|
+
writeFileSync9(
|
|
3002
2893
|
sessionRulePath(trimmedId, apmRoot),
|
|
3003
2894
|
detail.description ?? "",
|
|
3004
2895
|
"utf8"
|
|
3005
2896
|
);
|
|
3006
|
-
|
|
2897
|
+
writeFileSync9(
|
|
3007
2898
|
sessionTaskPath(trimmedId, apmRoot),
|
|
3008
2899
|
detail.task.description ?? "",
|
|
3009
2900
|
"utf8"
|
|
3010
2901
|
);
|
|
3011
|
-
|
|
2902
|
+
writeFileSync9(sessionTodoPath(trimmedId, apmRoot), detail.todo ?? "", "utf8");
|
|
3012
2903
|
for (const doc of documents) {
|
|
3013
2904
|
const fileName = documentLocalFileName(doc.name);
|
|
3014
|
-
|
|
2905
|
+
writeFileSync9(join10(docsDir, fileName), doc.content ?? "", "utf8");
|
|
3015
2906
|
}
|
|
3016
2907
|
const sessionYaml = yamlStringify(
|
|
3017
2908
|
{
|
|
@@ -3028,13 +2919,13 @@ async function runPull(sessionId, remoteWorkdir) {
|
|
|
3028
2919
|
},
|
|
3029
2920
|
{ lineWidth: 0 }
|
|
3030
2921
|
);
|
|
3031
|
-
|
|
2922
|
+
writeFileSync9(
|
|
3032
2923
|
sessionYamlPath(trimmedId, apmRoot),
|
|
3033
2924
|
sessionYaml.endsWith("\n") ? sessionYaml : `${sessionYaml}
|
|
3034
2925
|
`,
|
|
3035
2926
|
"utf8"
|
|
3036
2927
|
);
|
|
3037
|
-
|
|
2928
|
+
writeFileSync9(
|
|
3038
2929
|
sessionMessagesXmlPath(trimmedId, apmRoot),
|
|
3039
2930
|
formatSessionMessagesXml(trimmedId, messages),
|
|
3040
2931
|
"utf8"
|
|
@@ -3051,7 +2942,7 @@ async function runPull(sessionId, remoteWorkdir) {
|
|
|
3051
2942
|
import { spawnSync } from "child_process";
|
|
3052
2943
|
|
|
3053
2944
|
// src/version.ts
|
|
3054
|
-
import { readFileSync as
|
|
2945
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
3055
2946
|
import { dirname as dirname4, join as join11 } from "path";
|
|
3056
2947
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3057
2948
|
var CLI_PACKAGE_NAME = "ai-project-manage-cli";
|
|
@@ -3059,7 +2950,7 @@ function readCliVersion() {
|
|
|
3059
2950
|
try {
|
|
3060
2951
|
const dir = dirname4(fileURLToPath2(import.meta.url));
|
|
3061
2952
|
const pkgPath = join11(dir, "..", "package.json");
|
|
3062
|
-
const pkg = JSON.parse(
|
|
2953
|
+
const pkg = JSON.parse(readFileSync7(pkgPath, "utf8"));
|
|
3063
2954
|
return pkg.version ?? "0.0.0";
|
|
3064
2955
|
} catch {
|
|
3065
2956
|
return "0.0.0";
|
|
@@ -3314,7 +3205,7 @@ async function runSyncProjectDocuments(options) {
|
|
|
3314
3205
|
}
|
|
3315
3206
|
|
|
3316
3207
|
// src/commands/sync-document.ts
|
|
3317
|
-
import { existsSync as existsSync11, readFileSync as
|
|
3208
|
+
import { existsSync as existsSync11, readFileSync as readFileSync9 } from "fs";
|
|
3318
3209
|
import { basename as basename4 } from "path";
|
|
3319
3210
|
|
|
3320
3211
|
// src/assumptions/local-validate.ts
|
|
@@ -3485,7 +3376,7 @@ init_client();
|
|
|
3485
3376
|
|
|
3486
3377
|
// src/commands/sync-session-documents.ts
|
|
3487
3378
|
init_client();
|
|
3488
|
-
import { existsSync as existsSync10, readdirSync as readdirSync5, readFileSync as
|
|
3379
|
+
import { existsSync as existsSync10, readdirSync as readdirSync5, readFileSync as readFileSync8 } from "fs";
|
|
3489
3380
|
import { join as join13 } from "path";
|
|
3490
3381
|
function listLocalMarkdownFiles(docsDir) {
|
|
3491
3382
|
if (!existsSync10(docsDir)) {
|
|
@@ -3504,7 +3395,7 @@ function remoteDocumentByLocalName(remoteDocuments, localFileName) {
|
|
|
3504
3395
|
}
|
|
3505
3396
|
async function upsertLocalDocumentFile(api, sessionId, docsDir, fileName) {
|
|
3506
3397
|
const absPath = join13(docsDir, fileName);
|
|
3507
|
-
const content =
|
|
3398
|
+
const content = readFileSync8(absPath, "utf8");
|
|
3508
3399
|
const name = documentPlatformName(absPath);
|
|
3509
3400
|
return api.cli.upsertDocument({
|
|
3510
3401
|
sessionId,
|
|
@@ -3527,7 +3418,7 @@ async function syncSessionDocuments(cfg, sessionId, apmRoot, options) {
|
|
|
3527
3418
|
let synced = 0;
|
|
3528
3419
|
for (const fileName of localFiles) {
|
|
3529
3420
|
const absPath = join13(docsDir, fileName);
|
|
3530
|
-
const content =
|
|
3421
|
+
const content = readFileSync8(absPath, "utf8");
|
|
3531
3422
|
const remote = remoteDocumentByLocalName(remoteDocuments, fileName);
|
|
3532
3423
|
if (remote && remote.content === content) {
|
|
3533
3424
|
continue;
|
|
@@ -3571,7 +3462,7 @@ async function runSyncDocument(sessionId, options) {
|
|
|
3571
3462
|
const fileName = basename4(absPath);
|
|
3572
3463
|
const assumptionSource = resolveAssumptionSourceFromFileName(fileName);
|
|
3573
3464
|
if (assumptionSource) {
|
|
3574
|
-
const content =
|
|
3465
|
+
const content = readFileSync9(absPath, "utf8");
|
|
3575
3466
|
const validation = validateAssumptionsMarkdown(content, assumptionSource);
|
|
3576
3467
|
if (!validation.ok) {
|
|
3577
3468
|
printAssumptionValidationResult(validation);
|
|
@@ -3934,7 +3825,7 @@ init_client();
|
|
|
3934
3825
|
import path11 from "node:path";
|
|
3935
3826
|
|
|
3936
3827
|
// src/commands/deploy/internal/apm-config.ts
|
|
3937
|
-
import { existsSync as existsSync13, readFileSync as
|
|
3828
|
+
import { existsSync as existsSync13, readFileSync as readFileSync11 } from "node:fs";
|
|
3938
3829
|
import { resolve as resolve5 } from "node:path";
|
|
3939
3830
|
|
|
3940
3831
|
// src/commands/deploy/internal/config/config-validation.ts
|
|
@@ -4027,7 +3918,7 @@ function resolveFrontendDeployFromApmConfig(cfg) {
|
|
|
4027
3918
|
}
|
|
4028
3919
|
|
|
4029
3920
|
// src/commands/deploy/internal/config/maven-repo.ts
|
|
4030
|
-
import { existsSync as existsSync12, readFileSync as
|
|
3921
|
+
import { existsSync as existsSync12, readFileSync as readFileSync10 } from "node:fs";
|
|
4031
3922
|
import { homedir as homedir2 } from "node:os";
|
|
4032
3923
|
import { join as join14, resolve as resolve4 } from "node:path";
|
|
4033
3924
|
var MAVEN_REPO_ENV_KEYS = [
|
|
@@ -4091,7 +3982,7 @@ function readMavenLocalRepoFromSettings() {
|
|
|
4091
3982
|
return null;
|
|
4092
3983
|
}
|
|
4093
3984
|
try {
|
|
4094
|
-
const xml =
|
|
3985
|
+
const xml = readFileSync10(settingsPath, "utf8");
|
|
4095
3986
|
const match = xml.match(
|
|
4096
3987
|
/<localRepository>\s*([^<]+?)\s*<\/localRepository>/
|
|
4097
3988
|
);
|
|
@@ -4227,7 +4118,7 @@ function loadApmConfig(options) {
|
|
|
4227
4118
|
process.exit(1);
|
|
4228
4119
|
}
|
|
4229
4120
|
try {
|
|
4230
|
-
const raw =
|
|
4121
|
+
const raw = readFileSync11(p, "utf8");
|
|
4231
4122
|
return JSON.parse(raw);
|
|
4232
4123
|
} catch (e) {
|
|
4233
4124
|
console.error(`\u65E0\u6CD5\u89E3\u6790 apm.config.json\uFF1A${p}`, e);
|
|
@@ -4398,7 +4289,7 @@ import { dirname as dirname5, join as join17 } from "node:path";
|
|
|
4398
4289
|
init_config();
|
|
4399
4290
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
4400
4291
|
import { setTimeout as delay } from "node:timers/promises";
|
|
4401
|
-
import { existsSync as existsSync15, mkdirSync as mkdirSync7, unlinkSync as unlinkSync2, writeFileSync as
|
|
4292
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync7, unlinkSync as unlinkSync2, writeFileSync as writeFileSync11 } from "fs";
|
|
4402
4293
|
import { join as join16 } from "path";
|
|
4403
4294
|
|
|
4404
4295
|
// src/commands/connect-lock.ts
|
|
@@ -4406,9 +4297,9 @@ init_config();
|
|
|
4406
4297
|
import {
|
|
4407
4298
|
existsSync as existsSync14,
|
|
4408
4299
|
mkdirSync as mkdirSync6,
|
|
4409
|
-
readFileSync as
|
|
4300
|
+
readFileSync as readFileSync12,
|
|
4410
4301
|
unlinkSync,
|
|
4411
|
-
writeFileSync as
|
|
4302
|
+
writeFileSync as writeFileSync10
|
|
4412
4303
|
} from "fs";
|
|
4413
4304
|
import { join as join15 } from "path";
|
|
4414
4305
|
var CONNECT_LOCK_PATH = join15(APM_CONFIG_DIR, "connect.lock");
|
|
@@ -4440,7 +4331,7 @@ function waitForPm2LockHandoff(timeoutMs = 5e3) {
|
|
|
4440
4331
|
function readConnectLock() {
|
|
4441
4332
|
if (!existsSync14(CONNECT_LOCK_PATH)) return null;
|
|
4442
4333
|
try {
|
|
4443
|
-
const raw =
|
|
4334
|
+
const raw = readFileSync12(CONNECT_LOCK_PATH, "utf8");
|
|
4444
4335
|
const parsed = JSON.parse(raw);
|
|
4445
4336
|
if (typeof parsed.pid !== "number" || parsed.mode !== "foreground" && parsed.mode !== "pm2" || typeof parsed.startedAt !== "string") {
|
|
4446
4337
|
return null;
|
|
@@ -4481,7 +4372,7 @@ function acquireConnectLock(mode) {
|
|
|
4481
4372
|
mode,
|
|
4482
4373
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4483
4374
|
};
|
|
4484
|
-
|
|
4375
|
+
writeFileSync10(
|
|
4485
4376
|
CONNECT_LOCK_PATH,
|
|
4486
4377
|
JSON.stringify(lock, null, 2) + "\n",
|
|
4487
4378
|
"utf8"
|
|
@@ -4995,7 +4886,7 @@ async function resolveBaseUrl(server) {
|
|
|
4995
4886
|
}
|
|
4996
4887
|
function writeConnectLaunchFiles(options) {
|
|
4997
4888
|
mkdirSync7(APM_CONFIG_DIR, { recursive: true });
|
|
4998
|
-
|
|
4889
|
+
writeFileSync11(PM2_CONNECT_ENTRY_PATH, CONNECT_ENTRY_SCRIPT, "utf8");
|
|
4999
4890
|
const env = {
|
|
5000
4891
|
...collectPm2LaunchEnv()
|
|
5001
4892
|
};
|
|
@@ -5010,7 +4901,7 @@ function writeConnectLaunchFiles(options) {
|
|
|
5010
4901
|
cwd: options.cwd,
|
|
5011
4902
|
env
|
|
5012
4903
|
};
|
|
5013
|
-
|
|
4904
|
+
writeFileSync11(
|
|
5014
4905
|
PM2_CONNECT_LAUNCH_PATH,
|
|
5015
4906
|
JSON.stringify(launch, null, 2) + "\n",
|
|
5016
4907
|
"utf8"
|
|
@@ -5022,7 +4913,7 @@ function writeEcosystemFile(options) {
|
|
|
5022
4913
|
entryScript: PM2_CONNECT_ENTRY_PATH,
|
|
5023
4914
|
baseUrl: options.baseUrl
|
|
5024
4915
|
});
|
|
5025
|
-
|
|
4916
|
+
writeFileSync11(
|
|
5026
4917
|
PM2_ECOSYSTEM_PATH,
|
|
5027
4918
|
formatConnectPm2EcosystemFile(ecosystem),
|
|
5028
4919
|
"utf8"
|
|
@@ -5443,7 +5334,7 @@ function logWisdomFrontendDeployContext(input) {
|
|
|
5443
5334
|
}
|
|
5444
5335
|
|
|
5445
5336
|
// src/commands/deploy/internal/wisdom-deploy.ts
|
|
5446
|
-
import { existsSync as existsSync21, readFileSync as
|
|
5337
|
+
import { existsSync as existsSync21, readFileSync as readFileSync15, statSync as statSync10 } from "node:fs";
|
|
5447
5338
|
import path10 from "node:path";
|
|
5448
5339
|
|
|
5449
5340
|
// src/commands/deploy/deploy-shell-run.ts
|
|
@@ -5543,9 +5434,9 @@ import path9 from "node:path";
|
|
|
5543
5434
|
import {
|
|
5544
5435
|
mkdirSync as mkdirSync9,
|
|
5545
5436
|
readdirSync as readdirSync6,
|
|
5546
|
-
readFileSync as
|
|
5437
|
+
readFileSync as readFileSync14,
|
|
5547
5438
|
statSync as statSync8,
|
|
5548
|
-
writeFileSync as
|
|
5439
|
+
writeFileSync as writeFileSync13
|
|
5549
5440
|
} from "node:fs";
|
|
5550
5441
|
import path6 from "node:path";
|
|
5551
5442
|
import JSZip2 from "jszip";
|
|
@@ -5554,9 +5445,9 @@ import JSZip2 from "jszip";
|
|
|
5554
5445
|
import {
|
|
5555
5446
|
existsSync as existsSync18,
|
|
5556
5447
|
mkdirSync as mkdirSync8,
|
|
5557
|
-
readFileSync as
|
|
5448
|
+
readFileSync as readFileSync13,
|
|
5558
5449
|
statSync as statSync7,
|
|
5559
|
-
writeFileSync as
|
|
5450
|
+
writeFileSync as writeFileSync12
|
|
5560
5451
|
} from "node:fs";
|
|
5561
5452
|
import path2 from "node:path";
|
|
5562
5453
|
function deployCacheDir() {
|
|
@@ -5577,12 +5468,12 @@ function loadManifest3() {
|
|
|
5577
5468
|
if (!existsSync18(manifestPath3)) {
|
|
5578
5469
|
return {};
|
|
5579
5470
|
}
|
|
5580
|
-
return JSON.parse(
|
|
5471
|
+
return JSON.parse(readFileSync13(manifestPath3, "utf8"));
|
|
5581
5472
|
}
|
|
5582
5473
|
function saveManifest3(manifest) {
|
|
5583
5474
|
const dir = deployCacheDir();
|
|
5584
5475
|
mkdirSync8(dir, { recursive: true });
|
|
5585
|
-
|
|
5476
|
+
writeFileSync12(manifestFilePath(), JSON.stringify(manifest, null, 2), "utf8");
|
|
5586
5477
|
}
|
|
5587
5478
|
function updateManifestEntries(manifest, entries, projectRoot) {
|
|
5588
5479
|
for (const entry of entries) {
|
|
@@ -5996,7 +5887,7 @@ async function createUpdatePackage(entries, packageName) {
|
|
|
5996
5887
|
log(`\u521B\u5EFA\u66F4\u65B0\u5305: ${path6.basename(zipPath)}\uFF08${entries.length} \u4E2A\u6587\u4EF6\uFF09`);
|
|
5997
5888
|
const zip = new JSZip2();
|
|
5998
5889
|
for (const entry of entries) {
|
|
5999
|
-
const content =
|
|
5890
|
+
const content = readFileSync14(entry.path);
|
|
6000
5891
|
zip.file(entry.arcname, content);
|
|
6001
5892
|
log(` \u6253\u5305: ${entry.arcname} (${entry.reason})`);
|
|
6002
5893
|
}
|
|
@@ -6005,7 +5896,7 @@ async function createUpdatePackage(entries, packageName) {
|
|
|
6005
5896
|
compression: "DEFLATE",
|
|
6006
5897
|
compressionOptions: { level: 6 }
|
|
6007
5898
|
});
|
|
6008
|
-
|
|
5899
|
+
writeFileSync13(zipPath, buffer);
|
|
6009
5900
|
return zipPath;
|
|
6010
5901
|
}
|
|
6011
5902
|
function listAllLibFilesForArchive(libDir) {
|
|
@@ -6579,7 +6470,7 @@ function readPackageScripts(cwd) {
|
|
|
6579
6470
|
return {};
|
|
6580
6471
|
}
|
|
6581
6472
|
try {
|
|
6582
|
-
const raw =
|
|
6473
|
+
const raw = readFileSync15(pkgPath, "utf8");
|
|
6583
6474
|
const parsed = JSON.parse(raw);
|
|
6584
6475
|
return parsed.scripts ?? {};
|
|
6585
6476
|
} catch {
|
|
@@ -7247,7 +7138,7 @@ import { resolve as resolve7 } from "node:path";
|
|
|
7247
7138
|
import { getDefaultSdkStateRoot } from "@cursor/sdk";
|
|
7248
7139
|
|
|
7249
7140
|
// src/commands/connect/webide-agent-registry.ts
|
|
7250
|
-
import { existsSync as existsSync23, mkdirSync as mkdirSync10, readFileSync as
|
|
7141
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync10, readFileSync as readFileSync16, writeFileSync as writeFileSync14 } from "node:fs";
|
|
7251
7142
|
import { dirname as dirname7, resolve as resolve6 } from "node:path";
|
|
7252
7143
|
function registryPath(workdir, taskId) {
|
|
7253
7144
|
return resolve6(workdir, ".apm", "webide", taskId, "cursor-agent.json");
|
|
@@ -7257,7 +7148,7 @@ function readRegistry(path19) {
|
|
|
7257
7148
|
return {};
|
|
7258
7149
|
}
|
|
7259
7150
|
try {
|
|
7260
|
-
const parsed = JSON.parse(
|
|
7151
|
+
const parsed = JSON.parse(readFileSync16(path19, "utf8"));
|
|
7261
7152
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
7262
7153
|
const raw = parsed;
|
|
7263
7154
|
const state = {};
|
|
@@ -7742,7 +7633,7 @@ ${JSON.stringify(event, null, 2)}
|
|
|
7742
7633
|
}
|
|
7743
7634
|
|
|
7744
7635
|
// src/commands/connect/agent-session-registry.ts
|
|
7745
|
-
import { existsSync as existsSync25, mkdirSync as mkdirSync11, readFileSync as
|
|
7636
|
+
import { existsSync as existsSync25, mkdirSync as mkdirSync11, readFileSync as readFileSync17, writeFileSync as writeFileSync15 } from "node:fs";
|
|
7746
7637
|
import { dirname as dirname8, resolve as resolve8 } from "node:path";
|
|
7747
7638
|
function registryPath2(workdir, sessionId) {
|
|
7748
7639
|
return resolve8(workdir, ".apm", "sessions", sessionId, "cursor-agents.json");
|
|
@@ -7752,7 +7643,7 @@ function readRegistry2(path19) {
|
|
|
7752
7643
|
return {};
|
|
7753
7644
|
}
|
|
7754
7645
|
try {
|
|
7755
|
-
const parsed = JSON.parse(
|
|
7646
|
+
const parsed = JSON.parse(readFileSync17(path19, "utf8"));
|
|
7756
7647
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
7757
7648
|
const result = {};
|
|
7758
7649
|
for (const [key, value] of Object.entries(
|
|
@@ -7770,7 +7661,7 @@ function readRegistry2(path19) {
|
|
|
7770
7661
|
}
|
|
7771
7662
|
function writeRegistry(path19, registry) {
|
|
7772
7663
|
mkdirSync11(dirname8(path19), { recursive: true });
|
|
7773
|
-
|
|
7664
|
+
writeFileSync15(path19, `${JSON.stringify(registry, null, 2)}
|
|
7774
7665
|
`, "utf8");
|
|
7775
7666
|
}
|
|
7776
7667
|
function loadSessionAgentId(workdir, sessionId, user) {
|
|
@@ -8668,7 +8559,7 @@ async function ensureMessageHasReply(cfg, sessionId, messageId, fallback) {
|
|
|
8668
8559
|
}
|
|
8669
8560
|
|
|
8670
8561
|
// src/commands/connect/cli-version-sync.ts
|
|
8671
|
-
import { existsSync as existsSync26, readFileSync as
|
|
8562
|
+
import { existsSync as existsSync26, readFileSync as readFileSync18, writeFileSync as writeFileSync16 } from "fs";
|
|
8672
8563
|
import { join as join19 } from "path";
|
|
8673
8564
|
var CLI_VERSION_FILE = ".cli-version.json";
|
|
8674
8565
|
function manifestPath2(apmDir) {
|
|
@@ -8681,7 +8572,7 @@ function loadManifest4(apmDir) {
|
|
|
8681
8572
|
}
|
|
8682
8573
|
try {
|
|
8683
8574
|
const parsed = JSON.parse(
|
|
8684
|
-
|
|
8575
|
+
readFileSync18(path19, "utf8")
|
|
8685
8576
|
);
|
|
8686
8577
|
if (parsed?.version === 1 && typeof parsed.cliVersion === "string" && parsed.cliVersion.trim()) {
|
|
8687
8578
|
return parsed;
|
|
@@ -8692,7 +8583,7 @@ function loadManifest4(apmDir) {
|
|
|
8692
8583
|
}
|
|
8693
8584
|
function saveManifest4(apmDir, cliVersion) {
|
|
8694
8585
|
const manifest = { version: 1, cliVersion };
|
|
8695
|
-
|
|
8586
|
+
writeFileSync16(
|
|
8696
8587
|
toFsPath(manifestPath2(apmDir)),
|
|
8697
8588
|
`${JSON.stringify(manifest, null, 2)}
|
|
8698
8589
|
`,
|
|
@@ -8969,13 +8860,7 @@ async function handleInboundMessage(cfg, msg, signal, ctx) {
|
|
|
8969
8860
|
};
|
|
8970
8861
|
try {
|
|
8971
8862
|
if (signal.aborted) return;
|
|
8972
|
-
|
|
8973
|
-
"workspace-init",
|
|
8974
|
-
() => ensureWorkspaceInitialized(workdir)
|
|
8975
|
-
);
|
|
8976
|
-
if (!didInit) {
|
|
8977
|
-
assertApmGitignoredInRepo(workdir);
|
|
8978
|
-
}
|
|
8863
|
+
await runStep("workspace-init", () => ensureWorkspaceInitialized(workdir));
|
|
8979
8864
|
if (shouldRunBranch(msg.sessionId, workdir)) {
|
|
8980
8865
|
if (signal.aborted) return;
|
|
8981
8866
|
await runStep("branch", () => runBranch(msg.sessionId, { cwd: workdir }));
|
|
@@ -9848,7 +9733,7 @@ import path15 from "node:path";
|
|
|
9848
9733
|
import Docker from "dockerode";
|
|
9849
9734
|
|
|
9850
9735
|
// src/commands/deploy/internal/backend-deploy/dockerode-client/connection-options.ts
|
|
9851
|
-
import { existsSync as existsSync27, readFileSync as
|
|
9736
|
+
import { existsSync as existsSync27, readFileSync as readFileSync19 } from "node:fs";
|
|
9852
9737
|
import path12 from "node:path";
|
|
9853
9738
|
function asOptionalTlsBuffer(value) {
|
|
9854
9739
|
if (typeof value !== "string") {
|
|
@@ -9861,7 +9746,7 @@ function asOptionalTlsBuffer(value) {
|
|
|
9861
9746
|
return void 0;
|
|
9862
9747
|
}
|
|
9863
9748
|
if (existsSync27(normalized)) {
|
|
9864
|
-
return
|
|
9749
|
+
return readFileSync19(normalized);
|
|
9865
9750
|
}
|
|
9866
9751
|
const looksLikePath = /[\\/]/.test(normalized) || normalized.endsWith(".pem");
|
|
9867
9752
|
if (looksLikePath) {
|
|
@@ -10071,7 +9956,7 @@ var DockerodeClient = class {
|
|
|
10071
9956
|
var createDockerodeClient = (config) => new DockerodeClient(config);
|
|
10072
9957
|
|
|
10073
9958
|
// src/commands/deploy/internal/backend-deploy/dockerode-client/env.ts
|
|
10074
|
-
import { existsSync as existsSync28, readFileSync as
|
|
9959
|
+
import { existsSync as existsSync28, readFileSync as readFileSync20, statSync as statSync11 } from "node:fs";
|
|
10075
9960
|
import path13 from "node:path";
|
|
10076
9961
|
function stripSurroundingQuotes(value) {
|
|
10077
9962
|
const t = value.trim();
|
|
@@ -10091,7 +9976,7 @@ function loadEnvFromFile(envFilePath) {
|
|
|
10091
9976
|
if (!existsSync28(targetPath) || !statSync11(targetPath).isFile()) {
|
|
10092
9977
|
return {};
|
|
10093
9978
|
}
|
|
10094
|
-
const raw =
|
|
9979
|
+
const raw = readFileSync20(targetPath, "utf-8");
|
|
10095
9980
|
const result = {};
|
|
10096
9981
|
for (const line of raw.split(/\r?\n/)) {
|
|
10097
9982
|
const normalized = line.trim();
|
|
@@ -10673,7 +10558,7 @@ function buildProgram() {
|
|
|
10673
10558
|
await runLogin(opts);
|
|
10674
10559
|
});
|
|
10675
10560
|
program.command("init").description(
|
|
10676
|
-
"\u5728\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\
|
|
10561
|
+
"\u5728\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u521B\u5EFA .apm \u5E76\u521D\u59CB\u5316\u6A21\u677F\uFF1B\u5DF2\u767B\u5F55\u4E14\u5E73\u53F0\u6709\u5339\u914D\u90E8\u7F72\u914D\u7F6E\u65F6\u4F1A\u540C\u6B65 apm.config.json"
|
|
10677
10562
|
).option("--name <name>", "\u5DE5\u4F5C\u76EE\u5F55\u540D\u79F0").action(async (opts) => {
|
|
10678
10563
|
await runInit(opts.name);
|
|
10679
10564
|
});
|
|
@@ -395,10 +395,24 @@ async function tryReadHttpsGitOriginUrl(cwd) {
|
|
|
395
395
|
import { execFile as execFile2 } from "child_process";
|
|
396
396
|
import { promisify as promisify2 } from "util";
|
|
397
397
|
var execFileAsync2 = promisify2(execFile2);
|
|
398
|
+
function gitExecEnv() {
|
|
399
|
+
const existing = process.env.GIT_SSH_COMMAND?.trim();
|
|
400
|
+
const acceptNew = "-o StrictHostKeyChecking=accept-new";
|
|
401
|
+
let gitSshCommand;
|
|
402
|
+
if (!existing) {
|
|
403
|
+
gitSshCommand = `ssh ${acceptNew}`;
|
|
404
|
+
} else if (/\bStrictHostKeyChecking=/.test(existing)) {
|
|
405
|
+
gitSshCommand = existing;
|
|
406
|
+
} else {
|
|
407
|
+
gitSshCommand = `${existing} ${acceptNew}`;
|
|
408
|
+
}
|
|
409
|
+
return { ...process.env, GIT_SSH_COMMAND: gitSshCommand };
|
|
410
|
+
}
|
|
398
411
|
async function execGit(cwd, args, quiet = false) {
|
|
399
412
|
try {
|
|
400
413
|
const { stdout, stderr } = await execFileAsync2("git", args, {
|
|
401
414
|
cwd,
|
|
415
|
+
env: gitExecEnv(),
|
|
402
416
|
encoding: "utf8",
|
|
403
417
|
maxBuffer: 10 * 1024 * 1024
|
|
404
418
|
});
|
|
@@ -586,22 +600,6 @@ async function pushCurrentBranch(cwd) {
|
|
|
586
600
|
}
|
|
587
601
|
return true;
|
|
588
602
|
}
|
|
589
|
-
var GITIGNORE_COMMIT_MESSAGE = "chore(apm): ignore .apm directory";
|
|
590
|
-
async function commitAndPushGitignore(workdir) {
|
|
591
|
-
if (!await isGitRepo(workdir)) {
|
|
592
|
-
console.log("[apm] \u5F53\u524D\u76EE\u5F55\u4E0D\u662F git \u4ED3\u5E93\uFF0C\u8BF7\u624B\u52A8\u63D0\u4EA4 .gitignore");
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
await execGit(workdir, ["add", "--", ".gitignore"]);
|
|
596
|
-
await execGit(workdir, ["commit", "-m", GITIGNORE_COMMIT_MESSAGE]);
|
|
597
|
-
console.log(`[apm] \u5DF2\u63D0\u4EA4 .gitignore: ${GITIGNORE_COMMIT_MESSAGE}`);
|
|
598
|
-
const pushed = await pushCurrentBranch(workdir);
|
|
599
|
-
if (pushed) {
|
|
600
|
-
console.log("[apm] \u5DF2\u63A8\u9001 .gitignore");
|
|
601
|
-
} else {
|
|
602
|
-
console.log("[apm] \u672A\u914D\u7F6E remote.origin\uFF0C\u8BF7\u7A0D\u540E\u624B\u52A8 push .gitignore");
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
603
|
|
|
606
604
|
// src/baseline-resolve.ts
|
|
607
605
|
function formatBaselineDiagnostic(workdirPath, baselineWorkdirPath, diagnostic) {
|
|
@@ -655,15 +653,7 @@ async function resolveWorkspaceBaseline(api, workdirPath) {
|
|
|
655
653
|
}
|
|
656
654
|
|
|
657
655
|
// src/command-utils.ts
|
|
658
|
-
import {
|
|
659
|
-
copyFileSync,
|
|
660
|
-
existsSync,
|
|
661
|
-
mkdirSync as mkdirSync2,
|
|
662
|
-
readFileSync as readFileSync2,
|
|
663
|
-
readdirSync,
|
|
664
|
-
statSync,
|
|
665
|
-
writeFileSync as writeFileSync2
|
|
666
|
-
} from "fs";
|
|
656
|
+
import { copyFileSync, existsSync, mkdirSync as mkdirSync2, readdirSync, statSync } from "fs";
|
|
667
657
|
import { basename, dirname, extname, join as join2, resolve as resolve2 } from "path";
|
|
668
658
|
import { fileURLToPath } from "url";
|
|
669
659
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -685,63 +675,6 @@ function isWorkspaceApmInitialized(workdir) {
|
|
|
685
675
|
}
|
|
686
676
|
return readdirSync(fsApmDir).length > 0;
|
|
687
677
|
}
|
|
688
|
-
var APM_GITIGNORE_PATTERNS = [
|
|
689
|
-
/^\.apm\/?$/,
|
|
690
|
-
/^\.apm\/\*\*$/,
|
|
691
|
-
/^\*\*\/\.apm\/?$/,
|
|
692
|
-
/^\*\*\/\.apm\/\*\*$/,
|
|
693
|
-
/^\/\.apm\/?$/,
|
|
694
|
-
/^\/\.apm\/\*\*$/
|
|
695
|
-
];
|
|
696
|
-
function normalizeGitignorePattern(line) {
|
|
697
|
-
const trimmed = line.trim();
|
|
698
|
-
if (!trimmed || trimmed.startsWith("#")) return "";
|
|
699
|
-
if (trimmed.startsWith("!")) return "";
|
|
700
|
-
const hashIndex = trimmed.indexOf("#");
|
|
701
|
-
return (hashIndex >= 0 ? trimmed.slice(0, hashIndex) : trimmed).trim();
|
|
702
|
-
}
|
|
703
|
-
function gitignoreIgnoresApm(line) {
|
|
704
|
-
const pattern = normalizeGitignorePattern(line);
|
|
705
|
-
if (!pattern) return false;
|
|
706
|
-
return APM_GITIGNORE_PATTERNS.some((re) => re.test(pattern));
|
|
707
|
-
}
|
|
708
|
-
var APM_GITIGNORE_LINE = "**/.apm/**";
|
|
709
|
-
function ensureApmGitignoredInRepo(workdir) {
|
|
710
|
-
const gitignorePath = join2(workdir, ".gitignore");
|
|
711
|
-
const fsGitignorePath = toFsPath(gitignorePath);
|
|
712
|
-
if (!existsSync(fsGitignorePath)) {
|
|
713
|
-
writeFileSync2(fsGitignorePath, `${APM_GITIGNORE_LINE}
|
|
714
|
-
`, "utf8");
|
|
715
|
-
return true;
|
|
716
|
-
}
|
|
717
|
-
const content = readFileSync2(fsGitignorePath, "utf8");
|
|
718
|
-
if (content.split(/\r?\n/).some(gitignoreIgnoresApm)) {
|
|
719
|
-
return false;
|
|
720
|
-
}
|
|
721
|
-
const suffix = content.endsWith("\n") || content.length === 0 ? "" : "\n";
|
|
722
|
-
writeFileSync2(
|
|
723
|
-
fsGitignorePath,
|
|
724
|
-
`${content}${suffix}${APM_GITIGNORE_LINE}
|
|
725
|
-
`,
|
|
726
|
-
"utf8"
|
|
727
|
-
);
|
|
728
|
-
return true;
|
|
729
|
-
}
|
|
730
|
-
function assertApmGitignoredInRepo(workdir) {
|
|
731
|
-
const gitignorePath = join2(workdir, ".gitignore");
|
|
732
|
-
const fsGitignorePath = toFsPath(gitignorePath);
|
|
733
|
-
if (!existsSync(fsGitignorePath)) {
|
|
734
|
-
throw new Error(
|
|
735
|
-
`\u5DE5\u4F5C\u76EE\u5F55 ${workdir} \u7F3A\u5C11 .gitignore \u6587\u4EF6\uFF0C\u8BF7\u6DFB\u52A0\u5BF9 .apm \u7684\u5FFD\u7565\u89C4\u5219\uFF08\u4F8B\u5982 **/.apm/**\uFF09\uFF0C\u907F\u514D\u672C\u5730\u4F1A\u8BDD\u4E0E\u90E8\u7F72\u51ED\u636E\u88AB\u63D0\u4EA4\u3002`
|
|
736
|
-
);
|
|
737
|
-
}
|
|
738
|
-
const content = readFileSync2(fsGitignorePath, "utf8");
|
|
739
|
-
if (!content.split(/\r?\n/).some(gitignoreIgnoresApm)) {
|
|
740
|
-
throw new Error(
|
|
741
|
-
`\u5DE5\u4F5C\u76EE\u5F55 ${workdir} \u7684 .gitignore \u672A\u5FFD\u7565 .apm\uFF0C\u8BF7\u6DFB\u52A0 **/.apm/** \u6216 .apm/\uFF0C\u907F\u514D\u672C\u5730\u4F1A\u8BDD\u4E0E\u90E8\u7F72\u51ED\u636E\u88AB\u63D0\u4EA4\u3002`
|
|
742
|
-
);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
678
|
var SESSION_ATTACHMENTS_SUBDIR = "attachments";
|
|
746
679
|
var WEBIDE_SUBDIR = "webide";
|
|
747
680
|
function webideTaskDir(taskId, workdir) {
|
|
@@ -766,19 +699,10 @@ async function ensureDirExists(dir) {
|
|
|
766
699
|
async function ensureWorkspaceApmDirForInit(cwd = resolveWorkdirPath()) {
|
|
767
700
|
const dir = workspaceApmDir(cwd);
|
|
768
701
|
const fsDir = toFsPath(dir);
|
|
769
|
-
if (
|
|
770
|
-
mkdirSync2(fsDir, { recursive: true });
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
const st = statSync(fsDir);
|
|
774
|
-
if (!st.isDirectory()) {
|
|
702
|
+
if (existsSync(fsDir) && !statSync(fsDir).isDirectory()) {
|
|
775
703
|
throw new Error(`[apm] \u8DEF\u5F84\u5DF2\u5B58\u5728\u4F46\u4E0D\u662F\u76EE\u5F55: ${dir}`);
|
|
776
704
|
}
|
|
777
|
-
|
|
778
|
-
throw new Error(
|
|
779
|
-
"[apm] .apm \u76EE\u5F55\u5DF2\u5B58\u5728\u4E14\u975E\u7A7A\uFF0C\u8BF7\u5148\u5907\u4EFD\u3001\u6E05\u7A7A\u6216\u5220\u9664\u540E\u518D\u6267\u884C init"
|
|
780
|
-
);
|
|
781
|
-
}
|
|
705
|
+
mkdirSync2(fsDir, { recursive: true });
|
|
782
706
|
}
|
|
783
707
|
var WORKSPACE_TEMPLATE_SUBDIRS = [
|
|
784
708
|
"sessions",
|
|
@@ -858,10 +782,10 @@ async function copyTemplateFiles(targetDir, workdir = resolveWorkdirPath()) {
|
|
|
858
782
|
import {
|
|
859
783
|
existsSync as existsSync2,
|
|
860
784
|
mkdirSync as mkdirSync3,
|
|
861
|
-
readFileSync as
|
|
785
|
+
readFileSync as readFileSync2,
|
|
862
786
|
readdirSync as readdirSync2,
|
|
863
787
|
statSync as statSync2,
|
|
864
|
-
writeFileSync as
|
|
788
|
+
writeFileSync as writeFileSync2
|
|
865
789
|
} from "fs";
|
|
866
790
|
import { basename as basename2, dirname as dirname2, join as join3, relative, resolve as resolve3 } from "path";
|
|
867
791
|
var WORKSPACE_REPOS_MANIFEST = "workspace-repos.json";
|
|
@@ -909,7 +833,7 @@ function readManifest(workdir) {
|
|
|
909
833
|
}
|
|
910
834
|
try {
|
|
911
835
|
const raw = JSON.parse(
|
|
912
|
-
|
|
836
|
+
readFileSync2(path, "utf8")
|
|
913
837
|
);
|
|
914
838
|
if (raw?.version !== WORKSPACE_REPOS_VERSION) {
|
|
915
839
|
return null;
|
|
@@ -942,7 +866,7 @@ function writeManifest(workdir, manifest) {
|
|
|
942
866
|
const apmDir = toFsPath(workspaceApmDir(workdir));
|
|
943
867
|
mkdirSync3(apmDir, { recursive: true });
|
|
944
868
|
const path = toFsPath(manifestPath(workdir));
|
|
945
|
-
|
|
869
|
+
writeFileSync2(path, `${JSON.stringify(manifest, null, 2)}
|
|
946
870
|
`, "utf8");
|
|
947
871
|
}
|
|
948
872
|
function manifestStillValid(workdir, manifest) {
|
|
@@ -1562,7 +1486,7 @@ ${JSON.stringify(event, null, 2)}
|
|
|
1562
1486
|
}
|
|
1563
1487
|
|
|
1564
1488
|
// src/commands/connect/agent-session-registry.ts
|
|
1565
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync4, readFileSync as
|
|
1489
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
1566
1490
|
import { dirname as dirname3, resolve as resolve4 } from "node:path";
|
|
1567
1491
|
function registryPath(workdir, sessionId) {
|
|
1568
1492
|
return resolve4(workdir, ".apm", "sessions", sessionId, "cursor-agents.json");
|
|
@@ -1572,7 +1496,7 @@ function readRegistry(path) {
|
|
|
1572
1496
|
return {};
|
|
1573
1497
|
}
|
|
1574
1498
|
try {
|
|
1575
|
-
const parsed = JSON.parse(
|
|
1499
|
+
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
1576
1500
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1577
1501
|
const result = {};
|
|
1578
1502
|
for (const [key, value] of Object.entries(
|
|
@@ -1590,7 +1514,7 @@ function readRegistry(path) {
|
|
|
1590
1514
|
}
|
|
1591
1515
|
function writeRegistry(path, registry) {
|
|
1592
1516
|
mkdirSync4(dirname3(path), { recursive: true });
|
|
1593
|
-
|
|
1517
|
+
writeFileSync3(path, `${JSON.stringify(registry, null, 2)}
|
|
1594
1518
|
`, "utf8");
|
|
1595
1519
|
}
|
|
1596
1520
|
function loadSessionAgentId(workdir, sessionId, user) {
|
|
@@ -2522,7 +2446,7 @@ async function runCursorAgent(cfg, ctx, options) {
|
|
|
2522
2446
|
}
|
|
2523
2447
|
|
|
2524
2448
|
// src/commands/connect/webide-agent-registry.ts
|
|
2525
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as
|
|
2449
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
2526
2450
|
import { dirname as dirname4, resolve as resolve5 } from "node:path";
|
|
2527
2451
|
function registryPath2(workdir, taskId) {
|
|
2528
2452
|
return resolve5(workdir, ".apm", "webide", taskId, "cursor-agent.json");
|
|
@@ -2532,7 +2456,7 @@ function readRegistry2(path) {
|
|
|
2532
2456
|
return {};
|
|
2533
2457
|
}
|
|
2534
2458
|
try {
|
|
2535
|
-
const parsed = JSON.parse(
|
|
2459
|
+
const parsed = JSON.parse(readFileSync4(path, "utf8"));
|
|
2536
2460
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
2537
2461
|
const raw = parsed;
|
|
2538
2462
|
const state = {};
|
|
@@ -2562,7 +2486,7 @@ function readRegistry2(path) {
|
|
|
2562
2486
|
}
|
|
2563
2487
|
function writeRegistry2(path, registry) {
|
|
2564
2488
|
mkdirSync5(dirname4(path), { recursive: true });
|
|
2565
|
-
|
|
2489
|
+
writeFileSync4(path, `${JSON.stringify(registry, null, 2)}
|
|
2566
2490
|
`, "utf8");
|
|
2567
2491
|
}
|
|
2568
2492
|
function syncWebIdeTaskState(workdir, taskId, patch) {
|
|
@@ -3000,11 +2924,11 @@ function resolveMessageReplyFallback(fallback) {
|
|
|
3000
2924
|
|
|
3001
2925
|
// src/commands/init.ts
|
|
3002
2926
|
import { join as join6 } from "path";
|
|
3003
|
-
import { readFileSync as
|
|
2927
|
+
import { readFileSync as readFileSync6, writeFileSync as writeFileSync7 } from "fs";
|
|
3004
2928
|
|
|
3005
2929
|
// src/deployment-config-sync.ts
|
|
3006
2930
|
import { join as join4 } from "path";
|
|
3007
|
-
import { writeFileSync as
|
|
2931
|
+
import { writeFileSync as writeFileSync5 } from "fs";
|
|
3008
2932
|
var TEMPLATE_HINT = "\u4FDD\u7559\u6A21\u677F .apm/apm.config.json";
|
|
3009
2933
|
var SYNC_HINT = "\u767B\u8BB0\u5DE5\u4F5C\u7A7A\u95F4\u8DEF\u5F84\u3001\u7ED1\u5B9A\u4ED3\u5E93\u540E\uFF0C\u53EF\u6267\u884C: apm sync-deploy-config";
|
|
3010
2934
|
async function resolveRepositoryIdForSync(api, workdirPath) {
|
|
@@ -3030,7 +2954,7 @@ async function writeDeploymentConfigContent(apmDir, content, configName) {
|
|
|
3030
2954
|
return false;
|
|
3031
2955
|
}
|
|
3032
2956
|
const apmConfigPath = toFsPath(join4(apmDir, "apm.config.json"));
|
|
3033
|
-
|
|
2957
|
+
writeFileSync5(apmConfigPath, `${JSON.stringify(parsed, null, 2)}
|
|
3034
2958
|
`, "utf8");
|
|
3035
2959
|
console.log(`[apm] \u5DF2\u540C\u6B65\u5E73\u53F0\u90E8\u7F72\u914D\u7F6E: ${configName}`);
|
|
3036
2960
|
console.log("[apm] \u5DF2\u5199\u5165 .apm/apm.config.json");
|
|
@@ -3086,9 +3010,9 @@ ${diagnostic ?? ""}
|
|
|
3086
3010
|
import {
|
|
3087
3011
|
existsSync as existsSync6,
|
|
3088
3012
|
readdirSync as readdirSync3,
|
|
3089
|
-
readFileSync as
|
|
3013
|
+
readFileSync as readFileSync5,
|
|
3090
3014
|
rmSync as rmSync2,
|
|
3091
|
-
writeFileSync as
|
|
3015
|
+
writeFileSync as writeFileSync6
|
|
3092
3016
|
} from "fs";
|
|
3093
3017
|
import { createHash } from "crypto";
|
|
3094
3018
|
import { dirname as dirname5, join as join5, relative as relative2, sep } from "path";
|
|
@@ -3138,7 +3062,7 @@ function readLocalManifest(apmRoot, projectId) {
|
|
|
3138
3062
|
}
|
|
3139
3063
|
try {
|
|
3140
3064
|
return JSON.parse(
|
|
3141
|
-
|
|
3065
|
+
readFileSync5(manifestPath3, "utf8")
|
|
3142
3066
|
);
|
|
3143
3067
|
} catch {
|
|
3144
3068
|
return null;
|
|
@@ -3271,7 +3195,7 @@ ${diagnostic ?? ""}`);
|
|
|
3271
3195
|
projectDocumentLocalPath(targetApmDir, projectId, doc.path)
|
|
3272
3196
|
);
|
|
3273
3197
|
await ensureDirExists(dirname5(absPath));
|
|
3274
|
-
|
|
3198
|
+
writeFileSync6(absPath, doc.content, "utf8");
|
|
3275
3199
|
downloaded += 1;
|
|
3276
3200
|
}
|
|
3277
3201
|
}
|
|
@@ -3285,7 +3209,7 @@ ${diagnostic ?? ""}`);
|
|
|
3285
3209
|
deleted += 1;
|
|
3286
3210
|
}
|
|
3287
3211
|
}
|
|
3288
|
-
|
|
3212
|
+
writeFileSync6(
|
|
3289
3213
|
toFsPath(join5(docsDir, MANIFEST_FILE)),
|
|
3290
3214
|
`${JSON.stringify(remoteManifest, null, 2)}
|
|
3291
3215
|
`,
|
|
@@ -3329,7 +3253,7 @@ async function syncProjectDocumentsPush(cfg, workdirPath, apmRoot, options) {
|
|
|
3329
3253
|
const absPath = toFsPath(
|
|
3330
3254
|
projectDocumentLocalPath(targetApmDir, projectId, path)
|
|
3331
3255
|
);
|
|
3332
|
-
const content =
|
|
3256
|
+
const content = readFileSync5(absPath, "utf8");
|
|
3333
3257
|
const contentHash = hashLocalFileContent(content);
|
|
3334
3258
|
if (remoteHashByPath.get(path) === contentHash) {
|
|
3335
3259
|
continue;
|
|
@@ -3350,18 +3274,8 @@ async function syncProjectDocumentsPush(cfg, workdirPath, apmRoot, options) {
|
|
|
3350
3274
|
}
|
|
3351
3275
|
|
|
3352
3276
|
// src/commands/init.ts
|
|
3353
|
-
async function
|
|
3354
|
-
if (isWorkspaceApmInitialized(workdir)) {
|
|
3355
|
-
return { didInit: false };
|
|
3356
|
-
}
|
|
3357
|
-
console.log(
|
|
3358
|
-
`[apm] \u5DE5\u4F5C\u76EE\u5F55 ${workdir} \u672A\u68C0\u6D4B\u5230\u5DF2\u521D\u59CB\u5316\u7684 .apm\uFF0C\u6B63\u5728\u81EA\u52A8\u521D\u59CB\u5316\u2026`
|
|
3359
|
-
);
|
|
3277
|
+
async function initializeWorkspace(workdir, options) {
|
|
3360
3278
|
await ensureWorkspaceApmDirForInit(workdir);
|
|
3361
|
-
if (ensureApmGitignoredInRepo(workdir)) {
|
|
3362
|
-
console.log("[apm] \u5DF2\u5728 .gitignore \u4E2D\u6DFB\u52A0 **/.apm/**");
|
|
3363
|
-
await commitAndPushGitignore(workdir);
|
|
3364
|
-
}
|
|
3365
3279
|
const apmDir = workspaceApmDir(workdir);
|
|
3366
3280
|
await copyTemplateFiles(apmDir, workdir);
|
|
3367
3281
|
const syncResult = await syncRemoteDeploymentConfig(workdir, apmDir);
|
|
@@ -3369,10 +3283,10 @@ async function ensureWorkspaceInitialized(workdir, options) {
|
|
|
3369
3283
|
const trimmedName = options?.name?.trim();
|
|
3370
3284
|
if (trimmedName) {
|
|
3371
3285
|
const apmConfigPath = toFsPath(join6(apmDir, "apm.config.json"));
|
|
3372
|
-
const config =
|
|
3286
|
+
const config = readFileSync6(apmConfigPath, "utf8");
|
|
3373
3287
|
const configJson = JSON.parse(config);
|
|
3374
3288
|
configJson.name = trimmedName;
|
|
3375
|
-
|
|
3289
|
+
writeFileSync7(
|
|
3376
3290
|
apmConfigPath,
|
|
3377
3291
|
`${JSON.stringify(configJson, null, 2)}
|
|
3378
3292
|
`,
|
|
@@ -3382,6 +3296,15 @@ async function ensureWorkspaceInitialized(workdir, options) {
|
|
|
3382
3296
|
console.log(`[apm] \u5DF2\u521D\u59CB\u5316\u5DE5\u4F5C\u533A\uFF1A${apmDir}`);
|
|
3383
3297
|
return { didInit: true, syncResult };
|
|
3384
3298
|
}
|
|
3299
|
+
async function ensureWorkspaceInitialized(workdir, options) {
|
|
3300
|
+
if (isWorkspaceApmInitialized(workdir)) {
|
|
3301
|
+
return { didInit: false };
|
|
3302
|
+
}
|
|
3303
|
+
console.log(
|
|
3304
|
+
`[apm] \u5DE5\u4F5C\u76EE\u5F55 ${workdir} \u672A\u68C0\u6D4B\u5230\u5DF2\u521D\u59CB\u5316\u7684 .apm\uFF0C\u6B63\u5728\u81EA\u52A8\u521D\u59CB\u5316\u2026`
|
|
3305
|
+
);
|
|
3306
|
+
return initializeWorkspace(workdir, options);
|
|
3307
|
+
}
|
|
3385
3308
|
|
|
3386
3309
|
// src/commands/connect/pre-step-cache.ts
|
|
3387
3310
|
function sessionWorkdirKey(sessionId, workdir) {
|
|
@@ -3632,14 +3555,14 @@ async function ensureWebIdePullRequests(cfg, taskId, workdir) {
|
|
|
3632
3555
|
}
|
|
3633
3556
|
|
|
3634
3557
|
// src/version.ts
|
|
3635
|
-
import { readFileSync as
|
|
3558
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
3636
3559
|
import { dirname as dirname6, join as join7 } from "path";
|
|
3637
3560
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3638
3561
|
function readCliVersion() {
|
|
3639
3562
|
try {
|
|
3640
3563
|
const dir = dirname6(fileURLToPath2(import.meta.url));
|
|
3641
3564
|
const pkgPath = join7(dir, "..", "package.json");
|
|
3642
|
-
const pkg = JSON.parse(
|
|
3565
|
+
const pkg = JSON.parse(readFileSync7(pkgPath, "utf8"));
|
|
3643
3566
|
return pkg.version ?? "0.0.0";
|
|
3644
3567
|
} catch {
|
|
3645
3568
|
return "0.0.0";
|
|
@@ -3659,7 +3582,7 @@ import {
|
|
|
3659
3582
|
readdirSync as readdirSync4,
|
|
3660
3583
|
rmSync as rmSync3,
|
|
3661
3584
|
statSync as statSync3,
|
|
3662
|
-
writeFileSync as
|
|
3585
|
+
writeFileSync as writeFileSync8
|
|
3663
3586
|
} from "fs";
|
|
3664
3587
|
import { join as join8 } from "path";
|
|
3665
3588
|
var AGENTS_TEMPLATE_PATH = join8(CLI_TEMPLATE_DIR, "AGENTS.md");
|
|
@@ -3724,7 +3647,7 @@ function syncSupplementarySkills(skillsDir, list) {
|
|
|
3724
3647
|
}
|
|
3725
3648
|
const skillDir = join8(skillsDir, dirName);
|
|
3726
3649
|
mkdirSync6(skillDir, { recursive: true });
|
|
3727
|
-
|
|
3650
|
+
writeFileSync8(join8(skillDir, "SKILL.md"), skill.content ?? "", "utf8");
|
|
3728
3651
|
written.push(dirName);
|
|
3729
3652
|
}
|
|
3730
3653
|
const removed = [];
|
|
@@ -3788,7 +3711,7 @@ async function syncWorkspaceSkills(cfg, workdir) {
|
|
|
3788
3711
|
}
|
|
3789
3712
|
|
|
3790
3713
|
// src/commands/sync-session-attachments.ts
|
|
3791
|
-
import { existsSync as existsSync9, readFileSync as
|
|
3714
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8, writeFileSync as writeFileSync9 } from "fs";
|
|
3792
3715
|
import { join as join10 } from "path";
|
|
3793
3716
|
var MANIFEST_FILE2 = ".sync-manifest.json";
|
|
3794
3717
|
async function downloadAttachment(cfg, attachmentId) {
|
|
@@ -3811,7 +3734,7 @@ function loadManifest(dir) {
|
|
|
3811
3734
|
}
|
|
3812
3735
|
try {
|
|
3813
3736
|
const parsed = JSON.parse(
|
|
3814
|
-
|
|
3737
|
+
readFileSync8(path, "utf8")
|
|
3815
3738
|
);
|
|
3816
3739
|
if (parsed?.version === 1 && parsed.attachments && typeof parsed.attachments === "object") {
|
|
3817
3740
|
return parsed;
|
|
@@ -3821,7 +3744,7 @@ function loadManifest(dir) {
|
|
|
3821
3744
|
return { version: 1, attachments: {} };
|
|
3822
3745
|
}
|
|
3823
3746
|
function saveManifest(dir, manifest) {
|
|
3824
|
-
|
|
3747
|
+
writeFileSync9(
|
|
3825
3748
|
join10(dir, MANIFEST_FILE2),
|
|
3826
3749
|
`${JSON.stringify(manifest, null, 2)}
|
|
3827
3750
|
`,
|
|
@@ -3854,7 +3777,7 @@ async function syncAttachmentsToDirectory(cfg, attachments, dir, logLabel) {
|
|
|
3854
3777
|
continue;
|
|
3855
3778
|
}
|
|
3856
3779
|
const buffer = await downloadAttachment(cfg, item.id);
|
|
3857
|
-
|
|
3780
|
+
writeFileSync9(dest, buffer);
|
|
3858
3781
|
nextManifest.attachments[item.id] = {
|
|
3859
3782
|
name: item.name,
|
|
3860
3783
|
createdAt
|
|
@@ -3875,7 +3798,7 @@ async function syncWebIdeAttachments(cfg, taskId, workdir, attachments) {
|
|
|
3875
3798
|
}
|
|
3876
3799
|
|
|
3877
3800
|
// src/commands/connect/cli-version-sync.ts
|
|
3878
|
-
import { existsSync as existsSync10, readFileSync as
|
|
3801
|
+
import { existsSync as existsSync10, readFileSync as readFileSync9, writeFileSync as writeFileSync10 } from "fs";
|
|
3879
3802
|
import { join as join11 } from "path";
|
|
3880
3803
|
var CLI_VERSION_FILE = ".cli-version.json";
|
|
3881
3804
|
function manifestPath2(apmDir) {
|
|
@@ -3888,7 +3811,7 @@ function loadManifest2(apmDir) {
|
|
|
3888
3811
|
}
|
|
3889
3812
|
try {
|
|
3890
3813
|
const parsed = JSON.parse(
|
|
3891
|
-
|
|
3814
|
+
readFileSync9(path, "utf8")
|
|
3892
3815
|
);
|
|
3893
3816
|
if (parsed?.version === 1 && typeof parsed.cliVersion === "string" && parsed.cliVersion.trim()) {
|
|
3894
3817
|
return parsed;
|
|
@@ -3899,7 +3822,7 @@ function loadManifest2(apmDir) {
|
|
|
3899
3822
|
}
|
|
3900
3823
|
function saveManifest2(apmDir, cliVersion) {
|
|
3901
3824
|
const manifest = { version: 1, cliVersion };
|
|
3902
|
-
|
|
3825
|
+
writeFileSync10(
|
|
3903
3826
|
toFsPath(manifestPath2(apmDir)),
|
|
3904
3827
|
`${JSON.stringify(manifest, null, 2)}
|
|
3905
3828
|
`,
|
|
@@ -4006,9 +3929,6 @@ async function handleWebIdeInboundMessage(cfg, msg, signal, options) {
|
|
|
4006
3929
|
"\u521D\u59CB\u5316\u5DE5\u4F5C\u533A",
|
|
4007
3930
|
async () => {
|
|
4008
3931
|
const { didInit } = await ensureWorkspaceInitialized(workdir);
|
|
4009
|
-
if (!didInit) {
|
|
4010
|
-
assertApmGitignoredInRepo(workdir);
|
|
4011
|
-
}
|
|
4012
3932
|
return didInit;
|
|
4013
3933
|
},
|
|
4014
3934
|
(didInit) => didInit ? "\u5DF2\u521D\u59CB\u5316\u5DE5\u4F5C\u533A" : "\u5DE5\u4F5C\u533A\u5DF2\u5C31\u7EEA"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-project-manage-cli",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.37",
|
|
4
4
|
"description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "rm -rf dist && esbuild src/index.ts --bundle --platform=node --format=esm --packages=external --outfile=dist/index.js && esbuild src/commands/connect/webide-message-worker.ts --bundle --platform=node --format=esm --packages=external --outfile=dist/webide-message-worker.js && tsc --noEmit -p tsconfig.json",
|
|
18
|
-
"test:plan-cursor": "esbuild scripts/test-plan-cursor.ts --bundle --platform=node --format=esm --packages=external --outfile=dist/test-plan-cursor.mjs && node dist/test-plan-cursor.mjs",
|
|
19
18
|
"prepublishOnly": "npm run build"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|