ai-project-manage-cli 7.1.36 → 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 +90 -219
- package/dist/webide-message-worker.js +45 -139
- package/package.json +1 -1
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";
|
|
@@ -1438,46 +1364,6 @@ async function resolveDefaultRemoteBranch(cwd) {
|
|
|
1438
1364
|
"[apm] \u65E0\u6CD5\u786E\u5B9A\u8FDC\u7A0B\u9ED8\u8BA4\u5206\u652F\uFF08origin/HEAD\u3001main\u3001master \u5747\u4E0D\u53EF\u7528\uFF09"
|
|
1439
1365
|
);
|
|
1440
1366
|
}
|
|
1441
|
-
async function hasUpstream(cwd) {
|
|
1442
|
-
try {
|
|
1443
|
-
await execGit(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"], true);
|
|
1444
|
-
return true;
|
|
1445
|
-
} catch {
|
|
1446
|
-
return false;
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
async function pushCurrentBranch(cwd) {
|
|
1450
|
-
if (!await isGitRepo(cwd)) {
|
|
1451
|
-
return false;
|
|
1452
|
-
}
|
|
1453
|
-
const originUrl = await tryReadGitOriginUrl(cwd);
|
|
1454
|
-
if (!originUrl) {
|
|
1455
|
-
console.log("[apm] \u672A\u914D\u7F6E remote.origin\uFF0C\u8DF3\u8FC7 push");
|
|
1456
|
-
return false;
|
|
1457
|
-
}
|
|
1458
|
-
if (await hasUpstream(cwd)) {
|
|
1459
|
-
await execGit(cwd, ["push"]);
|
|
1460
|
-
} else {
|
|
1461
|
-
await execGit(cwd, ["push", "-u", "origin", "HEAD"]);
|
|
1462
|
-
}
|
|
1463
|
-
return true;
|
|
1464
|
-
}
|
|
1465
|
-
var GITIGNORE_COMMIT_MESSAGE = "chore(apm): ignore .apm directory";
|
|
1466
|
-
async function commitAndPushGitignore(workdir) {
|
|
1467
|
-
if (!await isGitRepo(workdir)) {
|
|
1468
|
-
console.log("[apm] \u5F53\u524D\u76EE\u5F55\u4E0D\u662F git \u4ED3\u5E93\uFF0C\u8BF7\u624B\u52A8\u63D0\u4EA4 .gitignore");
|
|
1469
|
-
return;
|
|
1470
|
-
}
|
|
1471
|
-
await execGit(workdir, ["add", "--", ".gitignore"]);
|
|
1472
|
-
await execGit(workdir, ["commit", "-m", GITIGNORE_COMMIT_MESSAGE]);
|
|
1473
|
-
console.log(`[apm] \u5DF2\u63D0\u4EA4 .gitignore: ${GITIGNORE_COMMIT_MESSAGE}`);
|
|
1474
|
-
const pushed = await pushCurrentBranch(workdir);
|
|
1475
|
-
if (pushed) {
|
|
1476
|
-
console.log("[apm] \u5DF2\u63A8\u9001 .gitignore");
|
|
1477
|
-
} else {
|
|
1478
|
-
console.log("[apm] \u672A\u914D\u7F6E remote.origin\uFF0C\u8BF7\u7A0D\u540E\u624B\u52A8 push .gitignore");
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
1367
|
|
|
1482
1368
|
// src/baseline-resolve.ts
|
|
1483
1369
|
function formatBaselineDiagnostic(workdirPath, baselineWorkdirPath, diagnostic) {
|
|
@@ -1569,10 +1455,10 @@ init_config();
|
|
|
1569
1455
|
import {
|
|
1570
1456
|
existsSync as existsSync2,
|
|
1571
1457
|
mkdirSync as mkdirSync3,
|
|
1572
|
-
readFileSync as
|
|
1458
|
+
readFileSync as readFileSync2,
|
|
1573
1459
|
readdirSync as readdirSync2,
|
|
1574
1460
|
statSync as statSync2,
|
|
1575
|
-
writeFileSync as
|
|
1461
|
+
writeFileSync as writeFileSync2
|
|
1576
1462
|
} from "fs";
|
|
1577
1463
|
import { basename as basename2, dirname as dirname2, join as join3, relative, resolve as resolve3 } from "path";
|
|
1578
1464
|
var WORKSPACE_REPOS_MANIFEST = "workspace-repos.json";
|
|
@@ -1607,7 +1493,7 @@ function readManifest(workdir) {
|
|
|
1607
1493
|
}
|
|
1608
1494
|
try {
|
|
1609
1495
|
const raw = JSON.parse(
|
|
1610
|
-
|
|
1496
|
+
readFileSync2(path19, "utf8")
|
|
1611
1497
|
);
|
|
1612
1498
|
if (raw?.version !== WORKSPACE_REPOS_VERSION) {
|
|
1613
1499
|
return null;
|
|
@@ -1640,7 +1526,7 @@ function writeManifest(workdir, manifest) {
|
|
|
1640
1526
|
const apmDir = toFsPath(workspaceApmDir(workdir));
|
|
1641
1527
|
mkdirSync3(apmDir, { recursive: true });
|
|
1642
1528
|
const path19 = toFsPath(manifestPath(workdir));
|
|
1643
|
-
|
|
1529
|
+
writeFileSync2(path19, `${JSON.stringify(manifest, null, 2)}
|
|
1644
1530
|
`, "utf8");
|
|
1645
1531
|
}
|
|
1646
1532
|
function isPathInsideOrEqual(parentAbs, childAbs) {
|
|
@@ -1794,7 +1680,7 @@ async function writeDeploymentConfigContent(apmDir, content, configName) {
|
|
|
1794
1680
|
return false;
|
|
1795
1681
|
}
|
|
1796
1682
|
const apmConfigPath = toFsPath(join4(apmDir, "apm.config.json"));
|
|
1797
|
-
|
|
1683
|
+
writeFileSync3(apmConfigPath, `${JSON.stringify(parsed, null, 2)}
|
|
1798
1684
|
`, "utf8");
|
|
1799
1685
|
console.log(`[apm] \u5DF2\u540C\u6B65\u5E73\u53F0\u90E8\u7F72\u914D\u7F6E: ${configName}`);
|
|
1800
1686
|
console.log("[apm] \u5DF2\u5199\u5165 .apm/apm.config.json");
|
|
@@ -1852,9 +1738,9 @@ init_config();
|
|
|
1852
1738
|
import {
|
|
1853
1739
|
existsSync as existsSync3,
|
|
1854
1740
|
readdirSync as readdirSync3,
|
|
1855
|
-
readFileSync as
|
|
1741
|
+
readFileSync as readFileSync3,
|
|
1856
1742
|
rmSync,
|
|
1857
|
-
writeFileSync as
|
|
1743
|
+
writeFileSync as writeFileSync4
|
|
1858
1744
|
} from "fs";
|
|
1859
1745
|
import { createHash } from "crypto";
|
|
1860
1746
|
import { dirname as dirname3, join as join5, relative as relative2, sep } from "path";
|
|
@@ -1904,7 +1790,7 @@ function readLocalManifest(apmRoot, projectId) {
|
|
|
1904
1790
|
}
|
|
1905
1791
|
try {
|
|
1906
1792
|
return JSON.parse(
|
|
1907
|
-
|
|
1793
|
+
readFileSync3(manifestPath3, "utf8")
|
|
1908
1794
|
);
|
|
1909
1795
|
} catch {
|
|
1910
1796
|
return null;
|
|
@@ -2037,7 +1923,7 @@ ${diagnostic ?? ""}`);
|
|
|
2037
1923
|
projectDocumentLocalPath(targetApmDir, projectId, doc.path)
|
|
2038
1924
|
);
|
|
2039
1925
|
await ensureDirExists(dirname3(absPath));
|
|
2040
|
-
|
|
1926
|
+
writeFileSync4(absPath, doc.content, "utf8");
|
|
2041
1927
|
downloaded += 1;
|
|
2042
1928
|
}
|
|
2043
1929
|
}
|
|
@@ -2051,7 +1937,7 @@ ${diagnostic ?? ""}`);
|
|
|
2051
1937
|
deleted += 1;
|
|
2052
1938
|
}
|
|
2053
1939
|
}
|
|
2054
|
-
|
|
1940
|
+
writeFileSync4(
|
|
2055
1941
|
toFsPath(join5(docsDir, MANIFEST_FILE)),
|
|
2056
1942
|
`${JSON.stringify(remoteManifest, null, 2)}
|
|
2057
1943
|
`,
|
|
@@ -2095,7 +1981,7 @@ async function syncProjectDocumentsPush(cfg, workdirPath, apmRoot, options) {
|
|
|
2095
1981
|
const absPath = toFsPath(
|
|
2096
1982
|
projectDocumentLocalPath(targetApmDir, projectId, path19)
|
|
2097
1983
|
);
|
|
2098
|
-
const content =
|
|
1984
|
+
const content = readFileSync3(absPath, "utf8");
|
|
2099
1985
|
const contentHash = hashLocalFileContent(content);
|
|
2100
1986
|
if (remoteHashByPath.get(path19) === contentHash) {
|
|
2101
1987
|
continue;
|
|
@@ -2116,18 +2002,8 @@ async function syncProjectDocumentsPush(cfg, workdirPath, apmRoot, options) {
|
|
|
2116
2002
|
}
|
|
2117
2003
|
|
|
2118
2004
|
// src/commands/init.ts
|
|
2119
|
-
async function
|
|
2120
|
-
if (isWorkspaceApmInitialized(workdir)) {
|
|
2121
|
-
return { didInit: false };
|
|
2122
|
-
}
|
|
2123
|
-
console.log(
|
|
2124
|
-
`[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`
|
|
2125
|
-
);
|
|
2005
|
+
async function initializeWorkspace(workdir, options) {
|
|
2126
2006
|
await ensureWorkspaceApmDirForInit(workdir);
|
|
2127
|
-
if (ensureApmGitignoredInRepo(workdir)) {
|
|
2128
|
-
console.log("[apm] \u5DF2\u5728 .gitignore \u4E2D\u6DFB\u52A0 **/.apm/**");
|
|
2129
|
-
await commitAndPushGitignore(workdir);
|
|
2130
|
-
}
|
|
2131
2007
|
const apmDir = workspaceApmDir(workdir);
|
|
2132
2008
|
await copyTemplateFiles(apmDir, workdir);
|
|
2133
2009
|
const syncResult = await syncRemoteDeploymentConfig(workdir, apmDir);
|
|
@@ -2135,10 +2011,10 @@ async function ensureWorkspaceInitialized(workdir, options) {
|
|
|
2135
2011
|
const trimmedName = options?.name?.trim();
|
|
2136
2012
|
if (trimmedName) {
|
|
2137
2013
|
const apmConfigPath = toFsPath(join6(apmDir, "apm.config.json"));
|
|
2138
|
-
const config =
|
|
2014
|
+
const config = readFileSync4(apmConfigPath, "utf8");
|
|
2139
2015
|
const configJson = JSON.parse(config);
|
|
2140
2016
|
configJson.name = trimmedName;
|
|
2141
|
-
|
|
2017
|
+
writeFileSync5(
|
|
2142
2018
|
apmConfigPath,
|
|
2143
2019
|
`${JSON.stringify(configJson, null, 2)}
|
|
2144
2020
|
`,
|
|
@@ -2148,17 +2024,18 @@ async function ensureWorkspaceInitialized(workdir, options) {
|
|
|
2148
2024
|
console.log(`[apm] \u5DF2\u521D\u59CB\u5316\u5DE5\u4F5C\u533A\uFF1A${apmDir}`);
|
|
2149
2025
|
return { didInit: true, syncResult };
|
|
2150
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
|
+
}
|
|
2151
2036
|
async function runInit(name) {
|
|
2152
2037
|
const workdir = resolveWorkdirPath();
|
|
2153
|
-
await
|
|
2154
|
-
const { didInit, syncResult } = await ensureWorkspaceInitialized(workdir, {
|
|
2155
|
-
name
|
|
2156
|
-
});
|
|
2157
|
-
if (!didInit) {
|
|
2158
|
-
throw new Error(
|
|
2159
|
-
"[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"
|
|
2160
|
-
);
|
|
2161
|
-
}
|
|
2038
|
+
const { syncResult } = await initializeWorkspace(workdir, { name });
|
|
2162
2039
|
console.log(`[apm] \u5DE5\u4F5C\u76EE\u5F55\u8DEF\u5F84\uFF1A${workdir}`);
|
|
2163
2040
|
if (syncResult && !syncResult.synced) {
|
|
2164
2041
|
console.log(
|
|
@@ -2682,7 +2559,7 @@ async function runCleanBranches(options = {}) {
|
|
|
2682
2559
|
|
|
2683
2560
|
// src/commands/pull.ts
|
|
2684
2561
|
init_client();
|
|
2685
|
-
import { writeFileSync as
|
|
2562
|
+
import { writeFileSync as writeFileSync9 } from "fs";
|
|
2686
2563
|
import { join as join10 } from "path";
|
|
2687
2564
|
import { stringify as yamlStringify } from "yaml";
|
|
2688
2565
|
|
|
@@ -2716,7 +2593,7 @@ function formatSessionMessagesXml(sessionId, messages) {
|
|
|
2716
2593
|
}
|
|
2717
2594
|
|
|
2718
2595
|
// src/commands/sync-session-attachments.ts
|
|
2719
|
-
import { existsSync as existsSync5, readFileSync as
|
|
2596
|
+
import { existsSync as existsSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync6 } from "fs";
|
|
2720
2597
|
import { join as join7 } from "path";
|
|
2721
2598
|
var MANIFEST_FILE2 = ".sync-manifest.json";
|
|
2722
2599
|
async function downloadAttachment(cfg, attachmentId) {
|
|
@@ -2739,7 +2616,7 @@ function loadManifest(dir) {
|
|
|
2739
2616
|
}
|
|
2740
2617
|
try {
|
|
2741
2618
|
const parsed = JSON.parse(
|
|
2742
|
-
|
|
2619
|
+
readFileSync5(path19, "utf8")
|
|
2743
2620
|
);
|
|
2744
2621
|
if (parsed?.version === 1 && parsed.attachments && typeof parsed.attachments === "object") {
|
|
2745
2622
|
return parsed;
|
|
@@ -2749,7 +2626,7 @@ function loadManifest(dir) {
|
|
|
2749
2626
|
return { version: 1, attachments: {} };
|
|
2750
2627
|
}
|
|
2751
2628
|
function saveManifest(dir, manifest) {
|
|
2752
|
-
|
|
2629
|
+
writeFileSync6(
|
|
2753
2630
|
join7(dir, MANIFEST_FILE2),
|
|
2754
2631
|
`${JSON.stringify(manifest, null, 2)}
|
|
2755
2632
|
`,
|
|
@@ -2782,7 +2659,7 @@ async function syncAttachmentsToDirectory(cfg, attachments, dir, logLabel) {
|
|
|
2782
2659
|
continue;
|
|
2783
2660
|
}
|
|
2784
2661
|
const buffer = await downloadAttachment(cfg, item.id);
|
|
2785
|
-
|
|
2662
|
+
writeFileSync6(dest, buffer);
|
|
2786
2663
|
nextManifest.attachments[item.id] = {
|
|
2787
2664
|
name: item.name,
|
|
2788
2665
|
createdAt
|
|
@@ -2805,7 +2682,7 @@ async function syncSessionAttachments(cfg, sessionId, attachments, apmRoot) {
|
|
|
2805
2682
|
// src/rules-sync.ts
|
|
2806
2683
|
init_client();
|
|
2807
2684
|
import { basename as basename3, extname as extname2, join as join9 } from "path";
|
|
2808
|
-
import { existsSync as existsSync7, readFileSync as
|
|
2685
|
+
import { existsSync as existsSync7, readFileSync as readFileSync6, rmSync as rmSync3, writeFileSync as writeFileSync8 } from "fs";
|
|
2809
2686
|
|
|
2810
2687
|
// src/skills-sync.ts
|
|
2811
2688
|
import {
|
|
@@ -2816,7 +2693,7 @@ import {
|
|
|
2816
2693
|
readdirSync as readdirSync4,
|
|
2817
2694
|
rmSync as rmSync2,
|
|
2818
2695
|
statSync as statSync3,
|
|
2819
|
-
writeFileSync as
|
|
2696
|
+
writeFileSync as writeFileSync7
|
|
2820
2697
|
} from "fs";
|
|
2821
2698
|
import { join as join8 } from "path";
|
|
2822
2699
|
var AGENTS_TEMPLATE_PATH = join8(CLI_TEMPLATE_DIR, "AGENTS.md");
|
|
@@ -2881,7 +2758,7 @@ function syncSupplementarySkills(skillsDir, list) {
|
|
|
2881
2758
|
}
|
|
2882
2759
|
const skillDir = join8(skillsDir, dirName);
|
|
2883
2760
|
mkdirSync4(skillDir, { recursive: true });
|
|
2884
|
-
|
|
2761
|
+
writeFileSync7(join8(skillDir, "SKILL.md"), skill.content ?? "", "utf8");
|
|
2885
2762
|
written.push(dirName);
|
|
2886
2763
|
}
|
|
2887
2764
|
const removed = [];
|
|
@@ -2913,7 +2790,7 @@ function loadManifest2(rulesDir) {
|
|
|
2913
2790
|
}
|
|
2914
2791
|
try {
|
|
2915
2792
|
const parsed = JSON.parse(
|
|
2916
|
-
|
|
2793
|
+
readFileSync6(toFsPath(path19), "utf8")
|
|
2917
2794
|
);
|
|
2918
2795
|
if (parsed?.version === 1 && parsed.rules && typeof parsed.rules === "object") {
|
|
2919
2796
|
return parsed;
|
|
@@ -2923,7 +2800,7 @@ function loadManifest2(rulesDir) {
|
|
|
2923
2800
|
return { version: 1, rules: {} };
|
|
2924
2801
|
}
|
|
2925
2802
|
function saveManifest2(rulesDir, manifest) {
|
|
2926
|
-
|
|
2803
|
+
writeFileSync8(
|
|
2927
2804
|
toFsPath(join9(rulesDir, MANIFEST_FILE3)),
|
|
2928
2805
|
`${JSON.stringify(manifest, null, 2)}
|
|
2929
2806
|
`,
|
|
@@ -2938,7 +2815,7 @@ function isRuleUpToDate(entry, rule, dest) {
|
|
|
2938
2815
|
if (entry.fileName !== ruleLocalFileName(rule.name)) return false;
|
|
2939
2816
|
const updatedAt = rule.updatedAt ?? "";
|
|
2940
2817
|
if (entry.updatedAt !== updatedAt) return false;
|
|
2941
|
-
const localContent =
|
|
2818
|
+
const localContent = readFileSync6(toFsPath(dest), "utf8");
|
|
2942
2819
|
return localContent === (rule.content ?? "");
|
|
2943
2820
|
}
|
|
2944
2821
|
async function syncPlatformRules(cfg, sessionId, workdirPath, apmRoot) {
|
|
@@ -2971,7 +2848,7 @@ async function syncPlatformRules(cfg, sessionId, workdirPath, apmRoot) {
|
|
|
2971
2848
|
console.log(`[apm] \u89C4\u5219\u65E0\u53D8\u5316\uFF0C\u5DF2\u8DF3\u8FC7: rules/${fileName}`);
|
|
2972
2849
|
continue;
|
|
2973
2850
|
}
|
|
2974
|
-
|
|
2851
|
+
writeFileSync8(toFsPath(dest), rule.content ?? "", "utf8");
|
|
2975
2852
|
nextManifest.rules[rule.id] = { fileName, updatedAt };
|
|
2976
2853
|
written.push(fileName);
|
|
2977
2854
|
console.log(`[apm] \u5DF2\u540C\u6B65\u5E73\u53F0\u89C4\u5219: rules/${fileName}`);
|
|
@@ -3012,20 +2889,20 @@ async function runPull(sessionId, remoteWorkdir) {
|
|
|
3012
2889
|
const dir = sessionDir(trimmedId, apmRoot);
|
|
3013
2890
|
const docsDir = sessionDocsDir(trimmedId, apmRoot);
|
|
3014
2891
|
await ensureDirExists(docsDir);
|
|
3015
|
-
|
|
2892
|
+
writeFileSync9(
|
|
3016
2893
|
sessionRulePath(trimmedId, apmRoot),
|
|
3017
2894
|
detail.description ?? "",
|
|
3018
2895
|
"utf8"
|
|
3019
2896
|
);
|
|
3020
|
-
|
|
2897
|
+
writeFileSync9(
|
|
3021
2898
|
sessionTaskPath(trimmedId, apmRoot),
|
|
3022
2899
|
detail.task.description ?? "",
|
|
3023
2900
|
"utf8"
|
|
3024
2901
|
);
|
|
3025
|
-
|
|
2902
|
+
writeFileSync9(sessionTodoPath(trimmedId, apmRoot), detail.todo ?? "", "utf8");
|
|
3026
2903
|
for (const doc of documents) {
|
|
3027
2904
|
const fileName = documentLocalFileName(doc.name);
|
|
3028
|
-
|
|
2905
|
+
writeFileSync9(join10(docsDir, fileName), doc.content ?? "", "utf8");
|
|
3029
2906
|
}
|
|
3030
2907
|
const sessionYaml = yamlStringify(
|
|
3031
2908
|
{
|
|
@@ -3042,13 +2919,13 @@ async function runPull(sessionId, remoteWorkdir) {
|
|
|
3042
2919
|
},
|
|
3043
2920
|
{ lineWidth: 0 }
|
|
3044
2921
|
);
|
|
3045
|
-
|
|
2922
|
+
writeFileSync9(
|
|
3046
2923
|
sessionYamlPath(trimmedId, apmRoot),
|
|
3047
2924
|
sessionYaml.endsWith("\n") ? sessionYaml : `${sessionYaml}
|
|
3048
2925
|
`,
|
|
3049
2926
|
"utf8"
|
|
3050
2927
|
);
|
|
3051
|
-
|
|
2928
|
+
writeFileSync9(
|
|
3052
2929
|
sessionMessagesXmlPath(trimmedId, apmRoot),
|
|
3053
2930
|
formatSessionMessagesXml(trimmedId, messages),
|
|
3054
2931
|
"utf8"
|
|
@@ -3065,7 +2942,7 @@ async function runPull(sessionId, remoteWorkdir) {
|
|
|
3065
2942
|
import { spawnSync } from "child_process";
|
|
3066
2943
|
|
|
3067
2944
|
// src/version.ts
|
|
3068
|
-
import { readFileSync as
|
|
2945
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
3069
2946
|
import { dirname as dirname4, join as join11 } from "path";
|
|
3070
2947
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3071
2948
|
var CLI_PACKAGE_NAME = "ai-project-manage-cli";
|
|
@@ -3073,7 +2950,7 @@ function readCliVersion() {
|
|
|
3073
2950
|
try {
|
|
3074
2951
|
const dir = dirname4(fileURLToPath2(import.meta.url));
|
|
3075
2952
|
const pkgPath = join11(dir, "..", "package.json");
|
|
3076
|
-
const pkg = JSON.parse(
|
|
2953
|
+
const pkg = JSON.parse(readFileSync7(pkgPath, "utf8"));
|
|
3077
2954
|
return pkg.version ?? "0.0.0";
|
|
3078
2955
|
} catch {
|
|
3079
2956
|
return "0.0.0";
|
|
@@ -3328,7 +3205,7 @@ async function runSyncProjectDocuments(options) {
|
|
|
3328
3205
|
}
|
|
3329
3206
|
|
|
3330
3207
|
// src/commands/sync-document.ts
|
|
3331
|
-
import { existsSync as existsSync11, readFileSync as
|
|
3208
|
+
import { existsSync as existsSync11, readFileSync as readFileSync9 } from "fs";
|
|
3332
3209
|
import { basename as basename4 } from "path";
|
|
3333
3210
|
|
|
3334
3211
|
// src/assumptions/local-validate.ts
|
|
@@ -3499,7 +3376,7 @@ init_client();
|
|
|
3499
3376
|
|
|
3500
3377
|
// src/commands/sync-session-documents.ts
|
|
3501
3378
|
init_client();
|
|
3502
|
-
import { existsSync as existsSync10, readdirSync as readdirSync5, readFileSync as
|
|
3379
|
+
import { existsSync as existsSync10, readdirSync as readdirSync5, readFileSync as readFileSync8 } from "fs";
|
|
3503
3380
|
import { join as join13 } from "path";
|
|
3504
3381
|
function listLocalMarkdownFiles(docsDir) {
|
|
3505
3382
|
if (!existsSync10(docsDir)) {
|
|
@@ -3518,7 +3395,7 @@ function remoteDocumentByLocalName(remoteDocuments, localFileName) {
|
|
|
3518
3395
|
}
|
|
3519
3396
|
async function upsertLocalDocumentFile(api, sessionId, docsDir, fileName) {
|
|
3520
3397
|
const absPath = join13(docsDir, fileName);
|
|
3521
|
-
const content =
|
|
3398
|
+
const content = readFileSync8(absPath, "utf8");
|
|
3522
3399
|
const name = documentPlatformName(absPath);
|
|
3523
3400
|
return api.cli.upsertDocument({
|
|
3524
3401
|
sessionId,
|
|
@@ -3541,7 +3418,7 @@ async function syncSessionDocuments(cfg, sessionId, apmRoot, options) {
|
|
|
3541
3418
|
let synced = 0;
|
|
3542
3419
|
for (const fileName of localFiles) {
|
|
3543
3420
|
const absPath = join13(docsDir, fileName);
|
|
3544
|
-
const content =
|
|
3421
|
+
const content = readFileSync8(absPath, "utf8");
|
|
3545
3422
|
const remote = remoteDocumentByLocalName(remoteDocuments, fileName);
|
|
3546
3423
|
if (remote && remote.content === content) {
|
|
3547
3424
|
continue;
|
|
@@ -3585,7 +3462,7 @@ async function runSyncDocument(sessionId, options) {
|
|
|
3585
3462
|
const fileName = basename4(absPath);
|
|
3586
3463
|
const assumptionSource = resolveAssumptionSourceFromFileName(fileName);
|
|
3587
3464
|
if (assumptionSource) {
|
|
3588
|
-
const content =
|
|
3465
|
+
const content = readFileSync9(absPath, "utf8");
|
|
3589
3466
|
const validation = validateAssumptionsMarkdown(content, assumptionSource);
|
|
3590
3467
|
if (!validation.ok) {
|
|
3591
3468
|
printAssumptionValidationResult(validation);
|
|
@@ -3948,7 +3825,7 @@ init_client();
|
|
|
3948
3825
|
import path11 from "node:path";
|
|
3949
3826
|
|
|
3950
3827
|
// src/commands/deploy/internal/apm-config.ts
|
|
3951
|
-
import { existsSync as existsSync13, readFileSync as
|
|
3828
|
+
import { existsSync as existsSync13, readFileSync as readFileSync11 } from "node:fs";
|
|
3952
3829
|
import { resolve as resolve5 } from "node:path";
|
|
3953
3830
|
|
|
3954
3831
|
// src/commands/deploy/internal/config/config-validation.ts
|
|
@@ -4041,7 +3918,7 @@ function resolveFrontendDeployFromApmConfig(cfg) {
|
|
|
4041
3918
|
}
|
|
4042
3919
|
|
|
4043
3920
|
// src/commands/deploy/internal/config/maven-repo.ts
|
|
4044
|
-
import { existsSync as existsSync12, readFileSync as
|
|
3921
|
+
import { existsSync as existsSync12, readFileSync as readFileSync10 } from "node:fs";
|
|
4045
3922
|
import { homedir as homedir2 } from "node:os";
|
|
4046
3923
|
import { join as join14, resolve as resolve4 } from "node:path";
|
|
4047
3924
|
var MAVEN_REPO_ENV_KEYS = [
|
|
@@ -4105,7 +3982,7 @@ function readMavenLocalRepoFromSettings() {
|
|
|
4105
3982
|
return null;
|
|
4106
3983
|
}
|
|
4107
3984
|
try {
|
|
4108
|
-
const xml =
|
|
3985
|
+
const xml = readFileSync10(settingsPath, "utf8");
|
|
4109
3986
|
const match = xml.match(
|
|
4110
3987
|
/<localRepository>\s*([^<]+?)\s*<\/localRepository>/
|
|
4111
3988
|
);
|
|
@@ -4241,7 +4118,7 @@ function loadApmConfig(options) {
|
|
|
4241
4118
|
process.exit(1);
|
|
4242
4119
|
}
|
|
4243
4120
|
try {
|
|
4244
|
-
const raw =
|
|
4121
|
+
const raw = readFileSync11(p, "utf8");
|
|
4245
4122
|
return JSON.parse(raw);
|
|
4246
4123
|
} catch (e) {
|
|
4247
4124
|
console.error(`\u65E0\u6CD5\u89E3\u6790 apm.config.json\uFF1A${p}`, e);
|
|
@@ -4412,7 +4289,7 @@ import { dirname as dirname5, join as join17 } from "node:path";
|
|
|
4412
4289
|
init_config();
|
|
4413
4290
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
4414
4291
|
import { setTimeout as delay } from "node:timers/promises";
|
|
4415
|
-
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";
|
|
4416
4293
|
import { join as join16 } from "path";
|
|
4417
4294
|
|
|
4418
4295
|
// src/commands/connect-lock.ts
|
|
@@ -4420,9 +4297,9 @@ init_config();
|
|
|
4420
4297
|
import {
|
|
4421
4298
|
existsSync as existsSync14,
|
|
4422
4299
|
mkdirSync as mkdirSync6,
|
|
4423
|
-
readFileSync as
|
|
4300
|
+
readFileSync as readFileSync12,
|
|
4424
4301
|
unlinkSync,
|
|
4425
|
-
writeFileSync as
|
|
4302
|
+
writeFileSync as writeFileSync10
|
|
4426
4303
|
} from "fs";
|
|
4427
4304
|
import { join as join15 } from "path";
|
|
4428
4305
|
var CONNECT_LOCK_PATH = join15(APM_CONFIG_DIR, "connect.lock");
|
|
@@ -4454,7 +4331,7 @@ function waitForPm2LockHandoff(timeoutMs = 5e3) {
|
|
|
4454
4331
|
function readConnectLock() {
|
|
4455
4332
|
if (!existsSync14(CONNECT_LOCK_PATH)) return null;
|
|
4456
4333
|
try {
|
|
4457
|
-
const raw =
|
|
4334
|
+
const raw = readFileSync12(CONNECT_LOCK_PATH, "utf8");
|
|
4458
4335
|
const parsed = JSON.parse(raw);
|
|
4459
4336
|
if (typeof parsed.pid !== "number" || parsed.mode !== "foreground" && parsed.mode !== "pm2" || typeof parsed.startedAt !== "string") {
|
|
4460
4337
|
return null;
|
|
@@ -4495,7 +4372,7 @@ function acquireConnectLock(mode) {
|
|
|
4495
4372
|
mode,
|
|
4496
4373
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4497
4374
|
};
|
|
4498
|
-
|
|
4375
|
+
writeFileSync10(
|
|
4499
4376
|
CONNECT_LOCK_PATH,
|
|
4500
4377
|
JSON.stringify(lock, null, 2) + "\n",
|
|
4501
4378
|
"utf8"
|
|
@@ -5009,7 +4886,7 @@ async function resolveBaseUrl(server) {
|
|
|
5009
4886
|
}
|
|
5010
4887
|
function writeConnectLaunchFiles(options) {
|
|
5011
4888
|
mkdirSync7(APM_CONFIG_DIR, { recursive: true });
|
|
5012
|
-
|
|
4889
|
+
writeFileSync11(PM2_CONNECT_ENTRY_PATH, CONNECT_ENTRY_SCRIPT, "utf8");
|
|
5013
4890
|
const env = {
|
|
5014
4891
|
...collectPm2LaunchEnv()
|
|
5015
4892
|
};
|
|
@@ -5024,7 +4901,7 @@ function writeConnectLaunchFiles(options) {
|
|
|
5024
4901
|
cwd: options.cwd,
|
|
5025
4902
|
env
|
|
5026
4903
|
};
|
|
5027
|
-
|
|
4904
|
+
writeFileSync11(
|
|
5028
4905
|
PM2_CONNECT_LAUNCH_PATH,
|
|
5029
4906
|
JSON.stringify(launch, null, 2) + "\n",
|
|
5030
4907
|
"utf8"
|
|
@@ -5036,7 +4913,7 @@ function writeEcosystemFile(options) {
|
|
|
5036
4913
|
entryScript: PM2_CONNECT_ENTRY_PATH,
|
|
5037
4914
|
baseUrl: options.baseUrl
|
|
5038
4915
|
});
|
|
5039
|
-
|
|
4916
|
+
writeFileSync11(
|
|
5040
4917
|
PM2_ECOSYSTEM_PATH,
|
|
5041
4918
|
formatConnectPm2EcosystemFile(ecosystem),
|
|
5042
4919
|
"utf8"
|
|
@@ -5457,7 +5334,7 @@ function logWisdomFrontendDeployContext(input) {
|
|
|
5457
5334
|
}
|
|
5458
5335
|
|
|
5459
5336
|
// src/commands/deploy/internal/wisdom-deploy.ts
|
|
5460
|
-
import { existsSync as existsSync21, readFileSync as
|
|
5337
|
+
import { existsSync as existsSync21, readFileSync as readFileSync15, statSync as statSync10 } from "node:fs";
|
|
5461
5338
|
import path10 from "node:path";
|
|
5462
5339
|
|
|
5463
5340
|
// src/commands/deploy/deploy-shell-run.ts
|
|
@@ -5557,9 +5434,9 @@ import path9 from "node:path";
|
|
|
5557
5434
|
import {
|
|
5558
5435
|
mkdirSync as mkdirSync9,
|
|
5559
5436
|
readdirSync as readdirSync6,
|
|
5560
|
-
readFileSync as
|
|
5437
|
+
readFileSync as readFileSync14,
|
|
5561
5438
|
statSync as statSync8,
|
|
5562
|
-
writeFileSync as
|
|
5439
|
+
writeFileSync as writeFileSync13
|
|
5563
5440
|
} from "node:fs";
|
|
5564
5441
|
import path6 from "node:path";
|
|
5565
5442
|
import JSZip2 from "jszip";
|
|
@@ -5568,9 +5445,9 @@ import JSZip2 from "jszip";
|
|
|
5568
5445
|
import {
|
|
5569
5446
|
existsSync as existsSync18,
|
|
5570
5447
|
mkdirSync as mkdirSync8,
|
|
5571
|
-
readFileSync as
|
|
5448
|
+
readFileSync as readFileSync13,
|
|
5572
5449
|
statSync as statSync7,
|
|
5573
|
-
writeFileSync as
|
|
5450
|
+
writeFileSync as writeFileSync12
|
|
5574
5451
|
} from "node:fs";
|
|
5575
5452
|
import path2 from "node:path";
|
|
5576
5453
|
function deployCacheDir() {
|
|
@@ -5591,12 +5468,12 @@ function loadManifest3() {
|
|
|
5591
5468
|
if (!existsSync18(manifestPath3)) {
|
|
5592
5469
|
return {};
|
|
5593
5470
|
}
|
|
5594
|
-
return JSON.parse(
|
|
5471
|
+
return JSON.parse(readFileSync13(manifestPath3, "utf8"));
|
|
5595
5472
|
}
|
|
5596
5473
|
function saveManifest3(manifest) {
|
|
5597
5474
|
const dir = deployCacheDir();
|
|
5598
5475
|
mkdirSync8(dir, { recursive: true });
|
|
5599
|
-
|
|
5476
|
+
writeFileSync12(manifestFilePath(), JSON.stringify(manifest, null, 2), "utf8");
|
|
5600
5477
|
}
|
|
5601
5478
|
function updateManifestEntries(manifest, entries, projectRoot) {
|
|
5602
5479
|
for (const entry of entries) {
|
|
@@ -6010,7 +5887,7 @@ async function createUpdatePackage(entries, packageName) {
|
|
|
6010
5887
|
log(`\u521B\u5EFA\u66F4\u65B0\u5305: ${path6.basename(zipPath)}\uFF08${entries.length} \u4E2A\u6587\u4EF6\uFF09`);
|
|
6011
5888
|
const zip = new JSZip2();
|
|
6012
5889
|
for (const entry of entries) {
|
|
6013
|
-
const content =
|
|
5890
|
+
const content = readFileSync14(entry.path);
|
|
6014
5891
|
zip.file(entry.arcname, content);
|
|
6015
5892
|
log(` \u6253\u5305: ${entry.arcname} (${entry.reason})`);
|
|
6016
5893
|
}
|
|
@@ -6019,7 +5896,7 @@ async function createUpdatePackage(entries, packageName) {
|
|
|
6019
5896
|
compression: "DEFLATE",
|
|
6020
5897
|
compressionOptions: { level: 6 }
|
|
6021
5898
|
});
|
|
6022
|
-
|
|
5899
|
+
writeFileSync13(zipPath, buffer);
|
|
6023
5900
|
return zipPath;
|
|
6024
5901
|
}
|
|
6025
5902
|
function listAllLibFilesForArchive(libDir) {
|
|
@@ -6593,7 +6470,7 @@ function readPackageScripts(cwd) {
|
|
|
6593
6470
|
return {};
|
|
6594
6471
|
}
|
|
6595
6472
|
try {
|
|
6596
|
-
const raw =
|
|
6473
|
+
const raw = readFileSync15(pkgPath, "utf8");
|
|
6597
6474
|
const parsed = JSON.parse(raw);
|
|
6598
6475
|
return parsed.scripts ?? {};
|
|
6599
6476
|
} catch {
|
|
@@ -7261,7 +7138,7 @@ import { resolve as resolve7 } from "node:path";
|
|
|
7261
7138
|
import { getDefaultSdkStateRoot } from "@cursor/sdk";
|
|
7262
7139
|
|
|
7263
7140
|
// src/commands/connect/webide-agent-registry.ts
|
|
7264
|
-
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";
|
|
7265
7142
|
import { dirname as dirname7, resolve as resolve6 } from "node:path";
|
|
7266
7143
|
function registryPath(workdir, taskId) {
|
|
7267
7144
|
return resolve6(workdir, ".apm", "webide", taskId, "cursor-agent.json");
|
|
@@ -7271,7 +7148,7 @@ function readRegistry(path19) {
|
|
|
7271
7148
|
return {};
|
|
7272
7149
|
}
|
|
7273
7150
|
try {
|
|
7274
|
-
const parsed = JSON.parse(
|
|
7151
|
+
const parsed = JSON.parse(readFileSync16(path19, "utf8"));
|
|
7275
7152
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
7276
7153
|
const raw = parsed;
|
|
7277
7154
|
const state = {};
|
|
@@ -7756,7 +7633,7 @@ ${JSON.stringify(event, null, 2)}
|
|
|
7756
7633
|
}
|
|
7757
7634
|
|
|
7758
7635
|
// src/commands/connect/agent-session-registry.ts
|
|
7759
|
-
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";
|
|
7760
7637
|
import { dirname as dirname8, resolve as resolve8 } from "node:path";
|
|
7761
7638
|
function registryPath2(workdir, sessionId) {
|
|
7762
7639
|
return resolve8(workdir, ".apm", "sessions", sessionId, "cursor-agents.json");
|
|
@@ -7766,7 +7643,7 @@ function readRegistry2(path19) {
|
|
|
7766
7643
|
return {};
|
|
7767
7644
|
}
|
|
7768
7645
|
try {
|
|
7769
|
-
const parsed = JSON.parse(
|
|
7646
|
+
const parsed = JSON.parse(readFileSync17(path19, "utf8"));
|
|
7770
7647
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
7771
7648
|
const result = {};
|
|
7772
7649
|
for (const [key, value] of Object.entries(
|
|
@@ -7784,7 +7661,7 @@ function readRegistry2(path19) {
|
|
|
7784
7661
|
}
|
|
7785
7662
|
function writeRegistry(path19, registry) {
|
|
7786
7663
|
mkdirSync11(dirname8(path19), { recursive: true });
|
|
7787
|
-
|
|
7664
|
+
writeFileSync15(path19, `${JSON.stringify(registry, null, 2)}
|
|
7788
7665
|
`, "utf8");
|
|
7789
7666
|
}
|
|
7790
7667
|
function loadSessionAgentId(workdir, sessionId, user) {
|
|
@@ -8682,7 +8559,7 @@ async function ensureMessageHasReply(cfg, sessionId, messageId, fallback) {
|
|
|
8682
8559
|
}
|
|
8683
8560
|
|
|
8684
8561
|
// src/commands/connect/cli-version-sync.ts
|
|
8685
|
-
import { existsSync as existsSync26, readFileSync as
|
|
8562
|
+
import { existsSync as existsSync26, readFileSync as readFileSync18, writeFileSync as writeFileSync16 } from "fs";
|
|
8686
8563
|
import { join as join19 } from "path";
|
|
8687
8564
|
var CLI_VERSION_FILE = ".cli-version.json";
|
|
8688
8565
|
function manifestPath2(apmDir) {
|
|
@@ -8695,7 +8572,7 @@ function loadManifest4(apmDir) {
|
|
|
8695
8572
|
}
|
|
8696
8573
|
try {
|
|
8697
8574
|
const parsed = JSON.parse(
|
|
8698
|
-
|
|
8575
|
+
readFileSync18(path19, "utf8")
|
|
8699
8576
|
);
|
|
8700
8577
|
if (parsed?.version === 1 && typeof parsed.cliVersion === "string" && parsed.cliVersion.trim()) {
|
|
8701
8578
|
return parsed;
|
|
@@ -8706,7 +8583,7 @@ function loadManifest4(apmDir) {
|
|
|
8706
8583
|
}
|
|
8707
8584
|
function saveManifest4(apmDir, cliVersion) {
|
|
8708
8585
|
const manifest = { version: 1, cliVersion };
|
|
8709
|
-
|
|
8586
|
+
writeFileSync16(
|
|
8710
8587
|
toFsPath(manifestPath2(apmDir)),
|
|
8711
8588
|
`${JSON.stringify(manifest, null, 2)}
|
|
8712
8589
|
`,
|
|
@@ -8983,13 +8860,7 @@ async function handleInboundMessage(cfg, msg, signal, ctx) {
|
|
|
8983
8860
|
};
|
|
8984
8861
|
try {
|
|
8985
8862
|
if (signal.aborted) return;
|
|
8986
|
-
|
|
8987
|
-
"workspace-init",
|
|
8988
|
-
() => ensureWorkspaceInitialized(workdir)
|
|
8989
|
-
);
|
|
8990
|
-
if (!didInit) {
|
|
8991
|
-
assertApmGitignoredInRepo(workdir);
|
|
8992
|
-
}
|
|
8863
|
+
await runStep("workspace-init", () => ensureWorkspaceInitialized(workdir));
|
|
8993
8864
|
if (shouldRunBranch(msg.sessionId, workdir)) {
|
|
8994
8865
|
if (signal.aborted) return;
|
|
8995
8866
|
await runStep("branch", () => runBranch(msg.sessionId, { cwd: workdir }));
|
|
@@ -9862,7 +9733,7 @@ import path15 from "node:path";
|
|
|
9862
9733
|
import Docker from "dockerode";
|
|
9863
9734
|
|
|
9864
9735
|
// src/commands/deploy/internal/backend-deploy/dockerode-client/connection-options.ts
|
|
9865
|
-
import { existsSync as existsSync27, readFileSync as
|
|
9736
|
+
import { existsSync as existsSync27, readFileSync as readFileSync19 } from "node:fs";
|
|
9866
9737
|
import path12 from "node:path";
|
|
9867
9738
|
function asOptionalTlsBuffer(value) {
|
|
9868
9739
|
if (typeof value !== "string") {
|
|
@@ -9875,7 +9746,7 @@ function asOptionalTlsBuffer(value) {
|
|
|
9875
9746
|
return void 0;
|
|
9876
9747
|
}
|
|
9877
9748
|
if (existsSync27(normalized)) {
|
|
9878
|
-
return
|
|
9749
|
+
return readFileSync19(normalized);
|
|
9879
9750
|
}
|
|
9880
9751
|
const looksLikePath = /[\\/]/.test(normalized) || normalized.endsWith(".pem");
|
|
9881
9752
|
if (looksLikePath) {
|
|
@@ -10085,7 +9956,7 @@ var DockerodeClient = class {
|
|
|
10085
9956
|
var createDockerodeClient = (config) => new DockerodeClient(config);
|
|
10086
9957
|
|
|
10087
9958
|
// src/commands/deploy/internal/backend-deploy/dockerode-client/env.ts
|
|
10088
|
-
import { existsSync as existsSync28, readFileSync as
|
|
9959
|
+
import { existsSync as existsSync28, readFileSync as readFileSync20, statSync as statSync11 } from "node:fs";
|
|
10089
9960
|
import path13 from "node:path";
|
|
10090
9961
|
function stripSurroundingQuotes(value) {
|
|
10091
9962
|
const t = value.trim();
|
|
@@ -10105,7 +9976,7 @@ function loadEnvFromFile(envFilePath) {
|
|
|
10105
9976
|
if (!existsSync28(targetPath) || !statSync11(targetPath).isFile()) {
|
|
10106
9977
|
return {};
|
|
10107
9978
|
}
|
|
10108
|
-
const raw =
|
|
9979
|
+
const raw = readFileSync20(targetPath, "utf-8");
|
|
10109
9980
|
const result = {};
|
|
10110
9981
|
for (const line of raw.split(/\r?\n/)) {
|
|
10111
9982
|
const normalized = line.trim();
|
|
@@ -10687,7 +10558,7 @@ function buildProgram() {
|
|
|
10687
10558
|
await runLogin(opts);
|
|
10688
10559
|
});
|
|
10689
10560
|
program.command("init").description(
|
|
10690
|
-
"\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"
|
|
10691
10562
|
).option("--name <name>", "\u5DE5\u4F5C\u76EE\u5F55\u540D\u79F0").action(async (opts) => {
|
|
10692
10563
|
await runInit(opts.name);
|
|
10693
10564
|
});
|
|
@@ -600,22 +600,6 @@ async function pushCurrentBranch(cwd) {
|
|
|
600
600
|
}
|
|
601
601
|
return true;
|
|
602
602
|
}
|
|
603
|
-
var GITIGNORE_COMMIT_MESSAGE = "chore(apm): ignore .apm directory";
|
|
604
|
-
async function commitAndPushGitignore(workdir) {
|
|
605
|
-
if (!await isGitRepo(workdir)) {
|
|
606
|
-
console.log("[apm] \u5F53\u524D\u76EE\u5F55\u4E0D\u662F git \u4ED3\u5E93\uFF0C\u8BF7\u624B\u52A8\u63D0\u4EA4 .gitignore");
|
|
607
|
-
return;
|
|
608
|
-
}
|
|
609
|
-
await execGit(workdir, ["add", "--", ".gitignore"]);
|
|
610
|
-
await execGit(workdir, ["commit", "-m", GITIGNORE_COMMIT_MESSAGE]);
|
|
611
|
-
console.log(`[apm] \u5DF2\u63D0\u4EA4 .gitignore: ${GITIGNORE_COMMIT_MESSAGE}`);
|
|
612
|
-
const pushed = await pushCurrentBranch(workdir);
|
|
613
|
-
if (pushed) {
|
|
614
|
-
console.log("[apm] \u5DF2\u63A8\u9001 .gitignore");
|
|
615
|
-
} else {
|
|
616
|
-
console.log("[apm] \u672A\u914D\u7F6E remote.origin\uFF0C\u8BF7\u7A0D\u540E\u624B\u52A8 push .gitignore");
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
603
|
|
|
620
604
|
// src/baseline-resolve.ts
|
|
621
605
|
function formatBaselineDiagnostic(workdirPath, baselineWorkdirPath, diagnostic) {
|
|
@@ -669,15 +653,7 @@ async function resolveWorkspaceBaseline(api, workdirPath) {
|
|
|
669
653
|
}
|
|
670
654
|
|
|
671
655
|
// src/command-utils.ts
|
|
672
|
-
import {
|
|
673
|
-
copyFileSync,
|
|
674
|
-
existsSync,
|
|
675
|
-
mkdirSync as mkdirSync2,
|
|
676
|
-
readFileSync as readFileSync2,
|
|
677
|
-
readdirSync,
|
|
678
|
-
statSync,
|
|
679
|
-
writeFileSync as writeFileSync2
|
|
680
|
-
} from "fs";
|
|
656
|
+
import { copyFileSync, existsSync, mkdirSync as mkdirSync2, readdirSync, statSync } from "fs";
|
|
681
657
|
import { basename, dirname, extname, join as join2, resolve as resolve2 } from "path";
|
|
682
658
|
import { fileURLToPath } from "url";
|
|
683
659
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -699,63 +675,6 @@ function isWorkspaceApmInitialized(workdir) {
|
|
|
699
675
|
}
|
|
700
676
|
return readdirSync(fsApmDir).length > 0;
|
|
701
677
|
}
|
|
702
|
-
var APM_GITIGNORE_PATTERNS = [
|
|
703
|
-
/^\.apm\/?$/,
|
|
704
|
-
/^\.apm\/\*\*$/,
|
|
705
|
-
/^\*\*\/\.apm\/?$/,
|
|
706
|
-
/^\*\*\/\.apm\/\*\*$/,
|
|
707
|
-
/^\/\.apm\/?$/,
|
|
708
|
-
/^\/\.apm\/\*\*$/
|
|
709
|
-
];
|
|
710
|
-
function normalizeGitignorePattern(line) {
|
|
711
|
-
const trimmed = line.trim();
|
|
712
|
-
if (!trimmed || trimmed.startsWith("#")) return "";
|
|
713
|
-
if (trimmed.startsWith("!")) return "";
|
|
714
|
-
const hashIndex = trimmed.indexOf("#");
|
|
715
|
-
return (hashIndex >= 0 ? trimmed.slice(0, hashIndex) : trimmed).trim();
|
|
716
|
-
}
|
|
717
|
-
function gitignoreIgnoresApm(line) {
|
|
718
|
-
const pattern = normalizeGitignorePattern(line);
|
|
719
|
-
if (!pattern) return false;
|
|
720
|
-
return APM_GITIGNORE_PATTERNS.some((re) => re.test(pattern));
|
|
721
|
-
}
|
|
722
|
-
var APM_GITIGNORE_LINE = "**/.apm/**";
|
|
723
|
-
function ensureApmGitignoredInRepo(workdir) {
|
|
724
|
-
const gitignorePath = join2(workdir, ".gitignore");
|
|
725
|
-
const fsGitignorePath = toFsPath(gitignorePath);
|
|
726
|
-
if (!existsSync(fsGitignorePath)) {
|
|
727
|
-
writeFileSync2(fsGitignorePath, `${APM_GITIGNORE_LINE}
|
|
728
|
-
`, "utf8");
|
|
729
|
-
return true;
|
|
730
|
-
}
|
|
731
|
-
const content = readFileSync2(fsGitignorePath, "utf8");
|
|
732
|
-
if (content.split(/\r?\n/).some(gitignoreIgnoresApm)) {
|
|
733
|
-
return false;
|
|
734
|
-
}
|
|
735
|
-
const suffix = content.endsWith("\n") || content.length === 0 ? "" : "\n";
|
|
736
|
-
writeFileSync2(
|
|
737
|
-
fsGitignorePath,
|
|
738
|
-
`${content}${suffix}${APM_GITIGNORE_LINE}
|
|
739
|
-
`,
|
|
740
|
-
"utf8"
|
|
741
|
-
);
|
|
742
|
-
return true;
|
|
743
|
-
}
|
|
744
|
-
function assertApmGitignoredInRepo(workdir) {
|
|
745
|
-
const gitignorePath = join2(workdir, ".gitignore");
|
|
746
|
-
const fsGitignorePath = toFsPath(gitignorePath);
|
|
747
|
-
if (!existsSync(fsGitignorePath)) {
|
|
748
|
-
throw new Error(
|
|
749
|
-
`\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`
|
|
750
|
-
);
|
|
751
|
-
}
|
|
752
|
-
const content = readFileSync2(fsGitignorePath, "utf8");
|
|
753
|
-
if (!content.split(/\r?\n/).some(gitignoreIgnoresApm)) {
|
|
754
|
-
throw new Error(
|
|
755
|
-
`\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`
|
|
756
|
-
);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
678
|
var SESSION_ATTACHMENTS_SUBDIR = "attachments";
|
|
760
679
|
var WEBIDE_SUBDIR = "webide";
|
|
761
680
|
function webideTaskDir(taskId, workdir) {
|
|
@@ -780,19 +699,10 @@ async function ensureDirExists(dir) {
|
|
|
780
699
|
async function ensureWorkspaceApmDirForInit(cwd = resolveWorkdirPath()) {
|
|
781
700
|
const dir = workspaceApmDir(cwd);
|
|
782
701
|
const fsDir = toFsPath(dir);
|
|
783
|
-
if (
|
|
784
|
-
mkdirSync2(fsDir, { recursive: true });
|
|
785
|
-
return;
|
|
786
|
-
}
|
|
787
|
-
const st = statSync(fsDir);
|
|
788
|
-
if (!st.isDirectory()) {
|
|
702
|
+
if (existsSync(fsDir) && !statSync(fsDir).isDirectory()) {
|
|
789
703
|
throw new Error(`[apm] \u8DEF\u5F84\u5DF2\u5B58\u5728\u4F46\u4E0D\u662F\u76EE\u5F55: ${dir}`);
|
|
790
704
|
}
|
|
791
|
-
|
|
792
|
-
throw new Error(
|
|
793
|
-
"[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"
|
|
794
|
-
);
|
|
795
|
-
}
|
|
705
|
+
mkdirSync2(fsDir, { recursive: true });
|
|
796
706
|
}
|
|
797
707
|
var WORKSPACE_TEMPLATE_SUBDIRS = [
|
|
798
708
|
"sessions",
|
|
@@ -872,10 +782,10 @@ async function copyTemplateFiles(targetDir, workdir = resolveWorkdirPath()) {
|
|
|
872
782
|
import {
|
|
873
783
|
existsSync as existsSync2,
|
|
874
784
|
mkdirSync as mkdirSync3,
|
|
875
|
-
readFileSync as
|
|
785
|
+
readFileSync as readFileSync2,
|
|
876
786
|
readdirSync as readdirSync2,
|
|
877
787
|
statSync as statSync2,
|
|
878
|
-
writeFileSync as
|
|
788
|
+
writeFileSync as writeFileSync2
|
|
879
789
|
} from "fs";
|
|
880
790
|
import { basename as basename2, dirname as dirname2, join as join3, relative, resolve as resolve3 } from "path";
|
|
881
791
|
var WORKSPACE_REPOS_MANIFEST = "workspace-repos.json";
|
|
@@ -923,7 +833,7 @@ function readManifest(workdir) {
|
|
|
923
833
|
}
|
|
924
834
|
try {
|
|
925
835
|
const raw = JSON.parse(
|
|
926
|
-
|
|
836
|
+
readFileSync2(path, "utf8")
|
|
927
837
|
);
|
|
928
838
|
if (raw?.version !== WORKSPACE_REPOS_VERSION) {
|
|
929
839
|
return null;
|
|
@@ -956,7 +866,7 @@ function writeManifest(workdir, manifest) {
|
|
|
956
866
|
const apmDir = toFsPath(workspaceApmDir(workdir));
|
|
957
867
|
mkdirSync3(apmDir, { recursive: true });
|
|
958
868
|
const path = toFsPath(manifestPath(workdir));
|
|
959
|
-
|
|
869
|
+
writeFileSync2(path, `${JSON.stringify(manifest, null, 2)}
|
|
960
870
|
`, "utf8");
|
|
961
871
|
}
|
|
962
872
|
function manifestStillValid(workdir, manifest) {
|
|
@@ -1576,7 +1486,7 @@ ${JSON.stringify(event, null, 2)}
|
|
|
1576
1486
|
}
|
|
1577
1487
|
|
|
1578
1488
|
// src/commands/connect/agent-session-registry.ts
|
|
1579
|
-
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";
|
|
1580
1490
|
import { dirname as dirname3, resolve as resolve4 } from "node:path";
|
|
1581
1491
|
function registryPath(workdir, sessionId) {
|
|
1582
1492
|
return resolve4(workdir, ".apm", "sessions", sessionId, "cursor-agents.json");
|
|
@@ -1586,7 +1496,7 @@ function readRegistry(path) {
|
|
|
1586
1496
|
return {};
|
|
1587
1497
|
}
|
|
1588
1498
|
try {
|
|
1589
|
-
const parsed = JSON.parse(
|
|
1499
|
+
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
1590
1500
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1591
1501
|
const result = {};
|
|
1592
1502
|
for (const [key, value] of Object.entries(
|
|
@@ -1604,7 +1514,7 @@ function readRegistry(path) {
|
|
|
1604
1514
|
}
|
|
1605
1515
|
function writeRegistry(path, registry) {
|
|
1606
1516
|
mkdirSync4(dirname3(path), { recursive: true });
|
|
1607
|
-
|
|
1517
|
+
writeFileSync3(path, `${JSON.stringify(registry, null, 2)}
|
|
1608
1518
|
`, "utf8");
|
|
1609
1519
|
}
|
|
1610
1520
|
function loadSessionAgentId(workdir, sessionId, user) {
|
|
@@ -2536,7 +2446,7 @@ async function runCursorAgent(cfg, ctx, options) {
|
|
|
2536
2446
|
}
|
|
2537
2447
|
|
|
2538
2448
|
// src/commands/connect/webide-agent-registry.ts
|
|
2539
|
-
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";
|
|
2540
2450
|
import { dirname as dirname4, resolve as resolve5 } from "node:path";
|
|
2541
2451
|
function registryPath2(workdir, taskId) {
|
|
2542
2452
|
return resolve5(workdir, ".apm", "webide", taskId, "cursor-agent.json");
|
|
@@ -2546,7 +2456,7 @@ function readRegistry2(path) {
|
|
|
2546
2456
|
return {};
|
|
2547
2457
|
}
|
|
2548
2458
|
try {
|
|
2549
|
-
const parsed = JSON.parse(
|
|
2459
|
+
const parsed = JSON.parse(readFileSync4(path, "utf8"));
|
|
2550
2460
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
2551
2461
|
const raw = parsed;
|
|
2552
2462
|
const state = {};
|
|
@@ -2576,7 +2486,7 @@ function readRegistry2(path) {
|
|
|
2576
2486
|
}
|
|
2577
2487
|
function writeRegistry2(path, registry) {
|
|
2578
2488
|
mkdirSync5(dirname4(path), { recursive: true });
|
|
2579
|
-
|
|
2489
|
+
writeFileSync4(path, `${JSON.stringify(registry, null, 2)}
|
|
2580
2490
|
`, "utf8");
|
|
2581
2491
|
}
|
|
2582
2492
|
function syncWebIdeTaskState(workdir, taskId, patch) {
|
|
@@ -3014,11 +2924,11 @@ function resolveMessageReplyFallback(fallback) {
|
|
|
3014
2924
|
|
|
3015
2925
|
// src/commands/init.ts
|
|
3016
2926
|
import { join as join6 } from "path";
|
|
3017
|
-
import { readFileSync as
|
|
2927
|
+
import { readFileSync as readFileSync6, writeFileSync as writeFileSync7 } from "fs";
|
|
3018
2928
|
|
|
3019
2929
|
// src/deployment-config-sync.ts
|
|
3020
2930
|
import { join as join4 } from "path";
|
|
3021
|
-
import { writeFileSync as
|
|
2931
|
+
import { writeFileSync as writeFileSync5 } from "fs";
|
|
3022
2932
|
var TEMPLATE_HINT = "\u4FDD\u7559\u6A21\u677F .apm/apm.config.json";
|
|
3023
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";
|
|
3024
2934
|
async function resolveRepositoryIdForSync(api, workdirPath) {
|
|
@@ -3044,7 +2954,7 @@ async function writeDeploymentConfigContent(apmDir, content, configName) {
|
|
|
3044
2954
|
return false;
|
|
3045
2955
|
}
|
|
3046
2956
|
const apmConfigPath = toFsPath(join4(apmDir, "apm.config.json"));
|
|
3047
|
-
|
|
2957
|
+
writeFileSync5(apmConfigPath, `${JSON.stringify(parsed, null, 2)}
|
|
3048
2958
|
`, "utf8");
|
|
3049
2959
|
console.log(`[apm] \u5DF2\u540C\u6B65\u5E73\u53F0\u90E8\u7F72\u914D\u7F6E: ${configName}`);
|
|
3050
2960
|
console.log("[apm] \u5DF2\u5199\u5165 .apm/apm.config.json");
|
|
@@ -3100,9 +3010,9 @@ ${diagnostic ?? ""}
|
|
|
3100
3010
|
import {
|
|
3101
3011
|
existsSync as existsSync6,
|
|
3102
3012
|
readdirSync as readdirSync3,
|
|
3103
|
-
readFileSync as
|
|
3013
|
+
readFileSync as readFileSync5,
|
|
3104
3014
|
rmSync as rmSync2,
|
|
3105
|
-
writeFileSync as
|
|
3015
|
+
writeFileSync as writeFileSync6
|
|
3106
3016
|
} from "fs";
|
|
3107
3017
|
import { createHash } from "crypto";
|
|
3108
3018
|
import { dirname as dirname5, join as join5, relative as relative2, sep } from "path";
|
|
@@ -3152,7 +3062,7 @@ function readLocalManifest(apmRoot, projectId) {
|
|
|
3152
3062
|
}
|
|
3153
3063
|
try {
|
|
3154
3064
|
return JSON.parse(
|
|
3155
|
-
|
|
3065
|
+
readFileSync5(manifestPath3, "utf8")
|
|
3156
3066
|
);
|
|
3157
3067
|
} catch {
|
|
3158
3068
|
return null;
|
|
@@ -3285,7 +3195,7 @@ ${diagnostic ?? ""}`);
|
|
|
3285
3195
|
projectDocumentLocalPath(targetApmDir, projectId, doc.path)
|
|
3286
3196
|
);
|
|
3287
3197
|
await ensureDirExists(dirname5(absPath));
|
|
3288
|
-
|
|
3198
|
+
writeFileSync6(absPath, doc.content, "utf8");
|
|
3289
3199
|
downloaded += 1;
|
|
3290
3200
|
}
|
|
3291
3201
|
}
|
|
@@ -3299,7 +3209,7 @@ ${diagnostic ?? ""}`);
|
|
|
3299
3209
|
deleted += 1;
|
|
3300
3210
|
}
|
|
3301
3211
|
}
|
|
3302
|
-
|
|
3212
|
+
writeFileSync6(
|
|
3303
3213
|
toFsPath(join5(docsDir, MANIFEST_FILE)),
|
|
3304
3214
|
`${JSON.stringify(remoteManifest, null, 2)}
|
|
3305
3215
|
`,
|
|
@@ -3343,7 +3253,7 @@ async function syncProjectDocumentsPush(cfg, workdirPath, apmRoot, options) {
|
|
|
3343
3253
|
const absPath = toFsPath(
|
|
3344
3254
|
projectDocumentLocalPath(targetApmDir, projectId, path)
|
|
3345
3255
|
);
|
|
3346
|
-
const content =
|
|
3256
|
+
const content = readFileSync5(absPath, "utf8");
|
|
3347
3257
|
const contentHash = hashLocalFileContent(content);
|
|
3348
3258
|
if (remoteHashByPath.get(path) === contentHash) {
|
|
3349
3259
|
continue;
|
|
@@ -3364,18 +3274,8 @@ async function syncProjectDocumentsPush(cfg, workdirPath, apmRoot, options) {
|
|
|
3364
3274
|
}
|
|
3365
3275
|
|
|
3366
3276
|
// src/commands/init.ts
|
|
3367
|
-
async function
|
|
3368
|
-
if (isWorkspaceApmInitialized(workdir)) {
|
|
3369
|
-
return { didInit: false };
|
|
3370
|
-
}
|
|
3371
|
-
console.log(
|
|
3372
|
-
`[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`
|
|
3373
|
-
);
|
|
3277
|
+
async function initializeWorkspace(workdir, options) {
|
|
3374
3278
|
await ensureWorkspaceApmDirForInit(workdir);
|
|
3375
|
-
if (ensureApmGitignoredInRepo(workdir)) {
|
|
3376
|
-
console.log("[apm] \u5DF2\u5728 .gitignore \u4E2D\u6DFB\u52A0 **/.apm/**");
|
|
3377
|
-
await commitAndPushGitignore(workdir);
|
|
3378
|
-
}
|
|
3379
3279
|
const apmDir = workspaceApmDir(workdir);
|
|
3380
3280
|
await copyTemplateFiles(apmDir, workdir);
|
|
3381
3281
|
const syncResult = await syncRemoteDeploymentConfig(workdir, apmDir);
|
|
@@ -3383,10 +3283,10 @@ async function ensureWorkspaceInitialized(workdir, options) {
|
|
|
3383
3283
|
const trimmedName = options?.name?.trim();
|
|
3384
3284
|
if (trimmedName) {
|
|
3385
3285
|
const apmConfigPath = toFsPath(join6(apmDir, "apm.config.json"));
|
|
3386
|
-
const config =
|
|
3286
|
+
const config = readFileSync6(apmConfigPath, "utf8");
|
|
3387
3287
|
const configJson = JSON.parse(config);
|
|
3388
3288
|
configJson.name = trimmedName;
|
|
3389
|
-
|
|
3289
|
+
writeFileSync7(
|
|
3390
3290
|
apmConfigPath,
|
|
3391
3291
|
`${JSON.stringify(configJson, null, 2)}
|
|
3392
3292
|
`,
|
|
@@ -3396,6 +3296,15 @@ async function ensureWorkspaceInitialized(workdir, options) {
|
|
|
3396
3296
|
console.log(`[apm] \u5DF2\u521D\u59CB\u5316\u5DE5\u4F5C\u533A\uFF1A${apmDir}`);
|
|
3397
3297
|
return { didInit: true, syncResult };
|
|
3398
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
|
+
}
|
|
3399
3308
|
|
|
3400
3309
|
// src/commands/connect/pre-step-cache.ts
|
|
3401
3310
|
function sessionWorkdirKey(sessionId, workdir) {
|
|
@@ -3646,14 +3555,14 @@ async function ensureWebIdePullRequests(cfg, taskId, workdir) {
|
|
|
3646
3555
|
}
|
|
3647
3556
|
|
|
3648
3557
|
// src/version.ts
|
|
3649
|
-
import { readFileSync as
|
|
3558
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
3650
3559
|
import { dirname as dirname6, join as join7 } from "path";
|
|
3651
3560
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3652
3561
|
function readCliVersion() {
|
|
3653
3562
|
try {
|
|
3654
3563
|
const dir = dirname6(fileURLToPath2(import.meta.url));
|
|
3655
3564
|
const pkgPath = join7(dir, "..", "package.json");
|
|
3656
|
-
const pkg = JSON.parse(
|
|
3565
|
+
const pkg = JSON.parse(readFileSync7(pkgPath, "utf8"));
|
|
3657
3566
|
return pkg.version ?? "0.0.0";
|
|
3658
3567
|
} catch {
|
|
3659
3568
|
return "0.0.0";
|
|
@@ -3673,7 +3582,7 @@ import {
|
|
|
3673
3582
|
readdirSync as readdirSync4,
|
|
3674
3583
|
rmSync as rmSync3,
|
|
3675
3584
|
statSync as statSync3,
|
|
3676
|
-
writeFileSync as
|
|
3585
|
+
writeFileSync as writeFileSync8
|
|
3677
3586
|
} from "fs";
|
|
3678
3587
|
import { join as join8 } from "path";
|
|
3679
3588
|
var AGENTS_TEMPLATE_PATH = join8(CLI_TEMPLATE_DIR, "AGENTS.md");
|
|
@@ -3738,7 +3647,7 @@ function syncSupplementarySkills(skillsDir, list) {
|
|
|
3738
3647
|
}
|
|
3739
3648
|
const skillDir = join8(skillsDir, dirName);
|
|
3740
3649
|
mkdirSync6(skillDir, { recursive: true });
|
|
3741
|
-
|
|
3650
|
+
writeFileSync8(join8(skillDir, "SKILL.md"), skill.content ?? "", "utf8");
|
|
3742
3651
|
written.push(dirName);
|
|
3743
3652
|
}
|
|
3744
3653
|
const removed = [];
|
|
@@ -3802,7 +3711,7 @@ async function syncWorkspaceSkills(cfg, workdir) {
|
|
|
3802
3711
|
}
|
|
3803
3712
|
|
|
3804
3713
|
// src/commands/sync-session-attachments.ts
|
|
3805
|
-
import { existsSync as existsSync9, readFileSync as
|
|
3714
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8, writeFileSync as writeFileSync9 } from "fs";
|
|
3806
3715
|
import { join as join10 } from "path";
|
|
3807
3716
|
var MANIFEST_FILE2 = ".sync-manifest.json";
|
|
3808
3717
|
async function downloadAttachment(cfg, attachmentId) {
|
|
@@ -3825,7 +3734,7 @@ function loadManifest(dir) {
|
|
|
3825
3734
|
}
|
|
3826
3735
|
try {
|
|
3827
3736
|
const parsed = JSON.parse(
|
|
3828
|
-
|
|
3737
|
+
readFileSync8(path, "utf8")
|
|
3829
3738
|
);
|
|
3830
3739
|
if (parsed?.version === 1 && parsed.attachments && typeof parsed.attachments === "object") {
|
|
3831
3740
|
return parsed;
|
|
@@ -3835,7 +3744,7 @@ function loadManifest(dir) {
|
|
|
3835
3744
|
return { version: 1, attachments: {} };
|
|
3836
3745
|
}
|
|
3837
3746
|
function saveManifest(dir, manifest) {
|
|
3838
|
-
|
|
3747
|
+
writeFileSync9(
|
|
3839
3748
|
join10(dir, MANIFEST_FILE2),
|
|
3840
3749
|
`${JSON.stringify(manifest, null, 2)}
|
|
3841
3750
|
`,
|
|
@@ -3868,7 +3777,7 @@ async function syncAttachmentsToDirectory(cfg, attachments, dir, logLabel) {
|
|
|
3868
3777
|
continue;
|
|
3869
3778
|
}
|
|
3870
3779
|
const buffer = await downloadAttachment(cfg, item.id);
|
|
3871
|
-
|
|
3780
|
+
writeFileSync9(dest, buffer);
|
|
3872
3781
|
nextManifest.attachments[item.id] = {
|
|
3873
3782
|
name: item.name,
|
|
3874
3783
|
createdAt
|
|
@@ -3889,7 +3798,7 @@ async function syncWebIdeAttachments(cfg, taskId, workdir, attachments) {
|
|
|
3889
3798
|
}
|
|
3890
3799
|
|
|
3891
3800
|
// src/commands/connect/cli-version-sync.ts
|
|
3892
|
-
import { existsSync as existsSync10, readFileSync as
|
|
3801
|
+
import { existsSync as existsSync10, readFileSync as readFileSync9, writeFileSync as writeFileSync10 } from "fs";
|
|
3893
3802
|
import { join as join11 } from "path";
|
|
3894
3803
|
var CLI_VERSION_FILE = ".cli-version.json";
|
|
3895
3804
|
function manifestPath2(apmDir) {
|
|
@@ -3902,7 +3811,7 @@ function loadManifest2(apmDir) {
|
|
|
3902
3811
|
}
|
|
3903
3812
|
try {
|
|
3904
3813
|
const parsed = JSON.parse(
|
|
3905
|
-
|
|
3814
|
+
readFileSync9(path, "utf8")
|
|
3906
3815
|
);
|
|
3907
3816
|
if (parsed?.version === 1 && typeof parsed.cliVersion === "string" && parsed.cliVersion.trim()) {
|
|
3908
3817
|
return parsed;
|
|
@@ -3913,7 +3822,7 @@ function loadManifest2(apmDir) {
|
|
|
3913
3822
|
}
|
|
3914
3823
|
function saveManifest2(apmDir, cliVersion) {
|
|
3915
3824
|
const manifest = { version: 1, cliVersion };
|
|
3916
|
-
|
|
3825
|
+
writeFileSync10(
|
|
3917
3826
|
toFsPath(manifestPath2(apmDir)),
|
|
3918
3827
|
`${JSON.stringify(manifest, null, 2)}
|
|
3919
3828
|
`,
|
|
@@ -4020,9 +3929,6 @@ async function handleWebIdeInboundMessage(cfg, msg, signal, options) {
|
|
|
4020
3929
|
"\u521D\u59CB\u5316\u5DE5\u4F5C\u533A",
|
|
4021
3930
|
async () => {
|
|
4022
3931
|
const { didInit } = await ensureWorkspaceInitialized(workdir);
|
|
4023
|
-
if (!didInit) {
|
|
4024
|
-
assertApmGitignoredInRepo(workdir);
|
|
4025
|
-
}
|
|
4026
3932
|
return didInit;
|
|
4027
3933
|
},
|
|
4028
3934
|
(didInit) => didInit ? "\u5DF2\u521D\u59CB\u5316\u5DE5\u4F5C\u533A" : "\u5DE5\u4F5C\u533A\u5DF2\u5C31\u7EEA"
|