cwm-assistant 0.4.4 → 0.4.5
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/{cli-KQ6BULSE.js → cli-JKJYCZCV.js} +456 -166
- package/dist/cli-JKJYCZCV.js.map +1 -0
- package/dist/main.js +1 -1
- package/package.json +1 -1
- package/dist/cli-KQ6BULSE.js.map +0 -1
|
@@ -6,9 +6,9 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
8
|
import { spawn as spawn9 } from "node:child_process";
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
9
|
+
import fs32 from "node:fs";
|
|
10
|
+
import os10 from "node:os";
|
|
11
|
+
import path35 from "node:path";
|
|
12
12
|
import { createInterface } from "node:readline/promises";
|
|
13
13
|
|
|
14
14
|
// ../../node_modules/@sinclair/typebox/build/esm/type/guard/value.mjs
|
|
@@ -2917,7 +2917,8 @@ async function completeChat(settings, messages, timeout = 9e4, extra) {
|
|
|
2917
2917
|
};
|
|
2918
2918
|
}
|
|
2919
2919
|
var SYSTEM_PROMPT = [
|
|
2920
|
-
"\u4F60\u662F\u53D1\u5E03\u4EA4\u63A5\u6587\u6863\u7684\u6574\u7406\u52A9\u624B\u3002\
|
|
2920
|
+
"\u4F60\u662F\u53D1\u5E03\u4EA4\u63A5\u6587\u6863\u7684\u6574\u7406\u52A9\u624B\u3002\u601D\u8003\u4E0E\u8BF4\u660E\u4F7F\u7528\u7B80\u4F53\u4E2D\u6587\uFF1B\u6458\u5F55\u4FDD\u6301\u539F\u6587\u3002",
|
|
2921
|
+
"\u7528\u6237\u7ED9\u51FA\u4E00\u4E2A\u7248\u672C\u7684\u9700\u6C42\u6E05\u5355\u3001\u4ED3\u5E93\u5206\u652F\u548C\u9700\u6C42\u6B63\u6587\u3002",
|
|
2921
2922
|
"\u8BF7\u53EA\u8F93\u51FA\u4E00\u4E2A JSON \u5BF9\u8C61\uFF0C\u4E0D\u8981\u8F93\u51FA\u89E3\u91CA\u3001\u4E0D\u8981\u4F7F\u7528 markdown \u4EE3\u7801\u5757\uFF0C\u5B57\u6BB5\u5982\u4E0B\uFF1A",
|
|
2922
2923
|
'{"wiki": string, "scripts": string, "configs": string}',
|
|
2923
2924
|
"- wiki\uFF1A\u9700\u6C42\u6B63\u6587\u4E2D\u51FA\u73B0\u8FC7\u7684 wiki / \u6587\u6863\u94FE\u63A5\uFF0C\u6BCF\u884C\u4E00\u4E2A\uFF1B\u6CA1\u6709\u5C31\u8F93\u51FA\u7A7A\u5B57\u7B26\u4E32\u3002",
|
|
@@ -3190,12 +3191,12 @@ function parseLog(raw) {
|
|
|
3190
3191
|
}
|
|
3191
3192
|
return details;
|
|
3192
3193
|
}
|
|
3193
|
-
async function loadCommitDetails(
|
|
3194
|
+
async function loadCommitDetails(git6, cwd, shas) {
|
|
3194
3195
|
const unique = [...new Set(shas.filter(Boolean))];
|
|
3195
3196
|
const bySha = /* @__PURE__ */ new Map();
|
|
3196
3197
|
for (let index = 0; index < unique.length; index += LOG_BATCH) {
|
|
3197
3198
|
const batch = unique.slice(index, index + LOG_BATCH);
|
|
3198
|
-
const raw = await
|
|
3199
|
+
const raw = await git6(cwd, [
|
|
3199
3200
|
"-c",
|
|
3200
3201
|
"core.quotepath=false",
|
|
3201
3202
|
"log",
|
|
@@ -3381,12 +3382,12 @@ function parseMessages(raw) {
|
|
|
3381
3382
|
}
|
|
3382
3383
|
return messages;
|
|
3383
3384
|
}
|
|
3384
|
-
async function parentCounts(
|
|
3385
|
+
async function parentCounts(git6, cwd, shas) {
|
|
3385
3386
|
const counts = /* @__PURE__ */ new Map();
|
|
3386
3387
|
const unique = [...new Set(shas.filter(Boolean))];
|
|
3387
3388
|
for (let index = 0; index < unique.length; index += LOG_BATCH2) {
|
|
3388
3389
|
const batch = unique.slice(index, index + LOG_BATCH2);
|
|
3389
|
-
const raw = await
|
|
3390
|
+
const raw = await git6(cwd, ["rev-list", "--no-walk", "--parents", ...batch]);
|
|
3390
3391
|
for (const line of raw.split("\n")) {
|
|
3391
3392
|
const parts = line.trim().split(" ").filter(Boolean);
|
|
3392
3393
|
if (parts.length) counts.set(parts[0], parts.length - 1);
|
|
@@ -3394,20 +3395,20 @@ async function parentCounts(git5, cwd, shas) {
|
|
|
3394
3395
|
}
|
|
3395
3396
|
return counts;
|
|
3396
3397
|
}
|
|
3397
|
-
async function loadMessages(
|
|
3398
|
+
async function loadMessages(git6, cwd, shas) {
|
|
3398
3399
|
const messages = /* @__PURE__ */ new Map();
|
|
3399
3400
|
for (let index = 0; index < shas.length; index += LOG_BATCH2) {
|
|
3400
3401
|
const batch = shas.slice(index, index + LOG_BATCH2);
|
|
3401
|
-
const raw = await
|
|
3402
|
+
const raw = await git6(cwd, ["log", "--no-walk", "--format=%x1e%H%x1f%s%x1f%b", ...batch]);
|
|
3402
3403
|
for (const [sha, message] of parseMessages(raw)) messages.set(sha, message);
|
|
3403
3404
|
}
|
|
3404
3405
|
return messages;
|
|
3405
3406
|
}
|
|
3406
|
-
async function loadIdentities(
|
|
3407
|
+
async function loadIdentities(git6, cwd, shas) {
|
|
3407
3408
|
const unique = [...new Set(shas.filter(Boolean))];
|
|
3408
3409
|
const [ids, messages] = await Promise.all([
|
|
3409
3410
|
loadPatchIds(cwd, unique),
|
|
3410
|
-
loadMessages(
|
|
3411
|
+
loadMessages(git6, cwd, unique)
|
|
3411
3412
|
]);
|
|
3412
3413
|
const identities = /* @__PURE__ */ new Map();
|
|
3413
3414
|
for (const sha of unique) {
|
|
@@ -3422,14 +3423,14 @@ function identitiesFor(shas, identities) {
|
|
|
3422
3423
|
return identity ? [identity] : [];
|
|
3423
3424
|
});
|
|
3424
3425
|
}
|
|
3425
|
-
async function applyPatchEquivalence(
|
|
3426
|
+
async function applyPatchEquivalence(git6, cwd, branches, extras) {
|
|
3426
3427
|
const missing = branches.flatMap((branch) => branch.missingCommits || []);
|
|
3427
3428
|
const extraShas = [...extras.keys()];
|
|
3428
3429
|
if (!missing.length || !extraShas.length) return;
|
|
3429
|
-
const counts = await parentCounts(
|
|
3430
|
+
const counts = await parentCounts(git6, cwd, [...missing, ...extraShas]);
|
|
3430
3431
|
const missingSingle = missing.filter((sha) => isContentCommit(counts, sha));
|
|
3431
3432
|
const extraSingle = extraShas.filter((sha) => isContentCommit(counts, sha));
|
|
3432
|
-
const identities = await loadIdentities(
|
|
3433
|
+
const identities = await loadIdentities(git6, cwd, [...missingSingle, ...extraSingle]);
|
|
3433
3434
|
assignPatchPairs(
|
|
3434
3435
|
branches,
|
|
3435
3436
|
extras,
|
|
@@ -3475,15 +3476,15 @@ function branchVerdict(branch, stagingSet, same, differs, identities) {
|
|
|
3475
3476
|
...messageDiffers.length ? { messageDiffers } : {}
|
|
3476
3477
|
};
|
|
3477
3478
|
}
|
|
3478
|
-
async function classifyStagingRanges(
|
|
3479
|
+
async function classifyStagingRanges(git6, cwd, branches, stagingCommits) {
|
|
3479
3480
|
const owned = new Set(branches.flatMap((branch) => branch.commits || []));
|
|
3480
|
-
const counts = await parentCounts(
|
|
3481
|
+
const counts = await parentCounts(git6, cwd, [...owned, ...stagingCommits]);
|
|
3481
3482
|
const stagingSet = new Set(stagingCommits);
|
|
3482
3483
|
const extraShas = stagingCommits.filter((sha) => isContentCommit(counts, sha) && !owned.has(sha));
|
|
3483
3484
|
const missingShas = [...owned].filter(
|
|
3484
3485
|
(sha) => isContentCommit(counts, sha) && !stagingSet.has(sha)
|
|
3485
3486
|
);
|
|
3486
|
-
const identities = await loadIdentities(
|
|
3487
|
+
const identities = await loadIdentities(git6, cwd, [...missingShas, ...extraShas]);
|
|
3487
3488
|
const pairs = pairPatchIdentities(
|
|
3488
3489
|
identitiesFor(missingShas, identities),
|
|
3489
3490
|
identitiesFor(extraShas, identities)
|
|
@@ -3507,11 +3508,11 @@ async function classifyStagingRanges(git5, cwd, branches, stagingCommits) {
|
|
|
3507
3508
|
}))
|
|
3508
3509
|
};
|
|
3509
3510
|
}
|
|
3510
|
-
async function compareStagingRepository(
|
|
3511
|
+
async function compareStagingRepository(git6, cwd, production, staging, branchNames, revList) {
|
|
3511
3512
|
const stagingCommits = await revList(production, staging) || [];
|
|
3512
3513
|
const branches = [];
|
|
3513
3514
|
for (const name of branchNames) branches.push({ name, commits: await revList(production, name) });
|
|
3514
|
-
return classifyStagingRanges(
|
|
3515
|
+
return classifyStagingRanges(git6, cwd, branches, stagingCommits);
|
|
3515
3516
|
}
|
|
3516
3517
|
|
|
3517
3518
|
// ../../packages/runtime/src/reviews/script-changes.ts
|
|
@@ -3539,16 +3540,16 @@ function safeRelativePath(filePath) {
|
|
|
3539
3540
|
function mergeScriptCandidates(rows) {
|
|
3540
3541
|
const map = /* @__PURE__ */ new Map();
|
|
3541
3542
|
for (const row of rows) {
|
|
3542
|
-
const
|
|
3543
|
-
if (!
|
|
3543
|
+
const path36 = safeRelativePath(row.path);
|
|
3544
|
+
if (!path36 || !isScriptCandidatePath(path36)) continue;
|
|
3544
3545
|
const status = row.status[0] || "M";
|
|
3545
3546
|
if (!"AMDR".includes(status)) continue;
|
|
3546
|
-
const existing = map.get(
|
|
3547
|
+
const existing = map.get(path36);
|
|
3547
3548
|
if (existing) {
|
|
3548
3549
|
if (!existing.ranges.includes(row.range)) existing.ranges.push(row.range);
|
|
3549
3550
|
continue;
|
|
3550
3551
|
}
|
|
3551
|
-
map.set(
|
|
3552
|
+
map.set(path36, { path: path36, status, ranges: [row.range] });
|
|
3552
3553
|
if (map.size >= MAX_SCRIPT_CANDIDATES) break;
|
|
3553
3554
|
}
|
|
3554
3555
|
return [...map.values()];
|
|
@@ -3582,12 +3583,14 @@ function acceptScriptChanges(value) {
|
|
|
3582
3583
|
if (Array.isArray(row.items)) {
|
|
3583
3584
|
for (const item of row.items.slice(0, 100)) {
|
|
3584
3585
|
const entry = item;
|
|
3585
|
-
const
|
|
3586
|
-
|
|
3586
|
+
const path36 = safeRelativePath(entry.path);
|
|
3587
|
+
const branch = typeof entry.branch === "string" ? entry.branch.trim() : "";
|
|
3588
|
+
if (typeof entry.repository !== "string" || !entry.repository.trim() || !branch || branch.includes("..") || !path36 || typeof entry.reason !== "string" || !entry.reason.trim())
|
|
3587
3589
|
continue;
|
|
3588
3590
|
items.push({
|
|
3589
3591
|
repository: entry.repository.trim().slice(0, 200),
|
|
3590
|
-
|
|
3592
|
+
branch: branch.slice(0, 200),
|
|
3593
|
+
path: path36.slice(0, 500),
|
|
3591
3594
|
reason: entry.reason.trim().slice(0, 300)
|
|
3592
3595
|
});
|
|
3593
3596
|
}
|
|
@@ -3759,7 +3762,7 @@ function createReviewTools(options) {
|
|
|
3759
3762
|
},
|
|
3760
3763
|
{
|
|
3761
3764
|
name: "list_script_candidates",
|
|
3762
|
-
description: "\u5217\u51FA\u8BE5\u4ED3\u5E93\u53EF\u80FD\u6D89\u53CA\
|
|
3765
|
+
description: "\u5217\u51FA\u8BE5\u4ED3\u5E93\u53EF\u80FD\u6D89\u53CA\u8868\u7ED3\u6784\u6216\u5B57\u6BB5\u7C7B\u578B\u7684\u6539\u52A8\u8DEF\u5F84\uFF08SQL\u3001Mapper\u3001\u5B9E\u4F53 Java\uFF09\u3002\u6BCF\u6761\u5E26 ranges\uFF0C\u5F62\u5982 production..\u5206\u652F\u540D\u3002\u53EA\u56DE\u8DEF\u5F84\u4E0E\u72B6\u6001\uFF0C\u4E0D\u542B diff\u3002",
|
|
3763
3766
|
parameters: {
|
|
3764
3767
|
...OBJECT,
|
|
3765
3768
|
properties: { repository: { type: "string" } },
|
|
@@ -3846,7 +3849,8 @@ function createReviewTools(options) {
|
|
|
3846
3849
|
|
|
3847
3850
|
// ../../packages/runtime/src/ai/branch-review.ts
|
|
3848
3851
|
var SYSTEM_PROMPT2 = [
|
|
3849
|
-
"\u4F60\u662F\u7248\u672C\u5206\u652F\u5BA1\u67E5\u52A9\u624B\u3002\
|
|
3852
|
+
"\u4F60\u662F\u7248\u672C\u5206\u652F\u5BA1\u67E5\u52A9\u624B\u3002\u601D\u8003\u4E0E\u8BF4\u660E\u4F7F\u7528\u7B80\u4F53\u4E2D\u6587\uFF1Bmessage\u3001summary \u7528\u4E2D\u6587\uFF0C\u5206\u652F\u540D\u3001\u8DEF\u5F84\u3001\u63D0\u4EA4\u53F7\u4FDD\u6301\u539F\u6587\u3002",
|
|
3853
|
+
"\u7528\u6237\u7ED9\u51FA\u9700\u6C42\u6807\u9898\u3001\u6B63\u6587\u6458\u8981\u3001\u63D0\u4EA4\u6807\u9898\uFF0C\u4EE5\u53CA\u8BE5\u5206\u652F\u76F8\u5BF9 production \u7684\u6539\u52A8\u6587\u4EF6\u6E05\u5355 changedFiles\u3002",
|
|
3850
3854
|
"\u8BF7\u53EA\u8F93\u51FA\u4E00\u4E2A JSON \u5BF9\u8C61\uFF0C\u4E0D\u8981\u8F93\u51FA\u89E3\u91CA\u3001\u4E0D\u8981\u4F7F\u7528 markdown \u4EE3\u7801\u5757\uFF0C\u5B57\u6BB5\u5982\u4E0B\uFF1A",
|
|
3851
3855
|
'{"findings":[{"repository":string,"branch":string,"kind":"mismatch"|"incomplete"|"contamination"|"risk","severity":"high"|"medium"|"low","message":string,"evidence":{"shas":string[],"files"?:string[]}}],"summary":string}',
|
|
3852
3856
|
"- mismatch\uFF1A\u63D0\u4EA4\u4E0D\u50CF\u5C5E\u4E8E\u767B\u8BB0\u7684\u9700\u6C42\u3002",
|
|
@@ -3880,9 +3884,9 @@ import path3 from "node:path";
|
|
|
3880
3884
|
// ../../packages/runtime/src/reviews/branch-scope.ts
|
|
3881
3885
|
var lines = (text) => text ? text.split("\n") : [];
|
|
3882
3886
|
var cleanBranch = (name) => name.replace(/^refs\/remotes\/origin\//, "").replace(/^refs\/heads\//, "").replace(/^origin\//, "");
|
|
3883
|
-
async function frozenRefs(
|
|
3887
|
+
async function frozenRefs(git6, cwd) {
|
|
3884
3888
|
return lines(
|
|
3885
|
-
await
|
|
3889
|
+
await git6(cwd, [
|
|
3886
3890
|
"for-each-ref",
|
|
3887
3891
|
"--format=%(refname)%09%(objectname)%09%(symref)",
|
|
3888
3892
|
"refs/remotes/origin/"
|
|
@@ -3893,15 +3897,15 @@ function scopeStatus(conflict, branches, nonVersionEntries) {
|
|
|
3893
3897
|
if (conflict) return "CONFLICT";
|
|
3894
3898
|
return branches.some((branch) => branch.unresolved || (branch.missingCommits || []).length) || nonVersionEntries.length ? "WARN" : "PASS";
|
|
3895
3899
|
}
|
|
3896
|
-
async function branchScope(
|
|
3900
|
+
async function branchScope(git6, cwd, productionSha, stagingSha, refs, branches, production, staging) {
|
|
3897
3901
|
const nodes = lines(
|
|
3898
|
-
await
|
|
3902
|
+
await git6(cwd, ["rev-list", "--topo-order", "--parents", productionSha + ".." + stagingSha])
|
|
3899
3903
|
).map((line) => line.split(" "));
|
|
3900
3904
|
const incoming = new Set(nodes.map(([sha]) => sha));
|
|
3901
3905
|
const histories = /* @__PURE__ */ new Map();
|
|
3902
3906
|
const history = async (sha) => {
|
|
3903
3907
|
if (!histories.has(sha))
|
|
3904
|
-
histories.set(sha, new Set(lines(await
|
|
3908
|
+
histories.set(sha, new Set(lines(await git6(cwd, ["rev-list", productionSha + ".." + sha]))));
|
|
3905
3909
|
return histories.get(sha);
|
|
3906
3910
|
};
|
|
3907
3911
|
const accounted = /* @__PURE__ */ new Set();
|
|
@@ -3933,7 +3937,7 @@ async function branchScope(git5, cwd, productionSha, stagingSha, refs, branches,
|
|
|
3933
3937
|
if (!matches.length) {
|
|
3934
3938
|
const containing = new Set(
|
|
3935
3939
|
lines(
|
|
3936
|
-
await
|
|
3940
|
+
await git6(cwd, [
|
|
3937
3941
|
"for-each-ref",
|
|
3938
3942
|
"--contains=" + tip,
|
|
3939
3943
|
"--format=%(refname)",
|
|
@@ -3962,7 +3966,7 @@ async function branchScope(git5, cwd, productionSha, stagingSha, refs, branches,
|
|
|
3962
3966
|
if (parents.length < 2) {
|
|
3963
3967
|
if (accounted.has(sha)) continue;
|
|
3964
3968
|
const changed = parseNameStatus(
|
|
3965
|
-
await
|
|
3969
|
+
await git6(cwd, [
|
|
3966
3970
|
"diff-tree",
|
|
3967
3971
|
"--root",
|
|
3968
3972
|
"--no-commit-id",
|
|
@@ -3978,8 +3982,8 @@ async function branchScope(git5, cwd, productionSha, stagingSha, refs, branches,
|
|
|
3978
3982
|
let independent = parents.length !== 2;
|
|
3979
3983
|
if (parents.length === 2) {
|
|
3980
3984
|
try {
|
|
3981
|
-
const automatic = (await
|
|
3982
|
-
const actual = await
|
|
3985
|
+
const automatic = (await git6(cwd, ["merge-tree", "--write-tree", parents[0], parents[1]])).split("\n")[0];
|
|
3986
|
+
const actual = await git6(cwd, ["rev-parse", sha + "^{tree}"]);
|
|
3983
3987
|
independent = automatic !== actual;
|
|
3984
3988
|
} catch (error) {
|
|
3985
3989
|
if (error.code !== 1) throw error;
|
|
@@ -3987,7 +3991,7 @@ async function branchScope(git5, cwd, productionSha, stagingSha, refs, branches,
|
|
|
3987
3991
|
}
|
|
3988
3992
|
}
|
|
3989
3993
|
if (independent && parseNameStatus(
|
|
3990
|
-
await
|
|
3994
|
+
await git6(cwd, [
|
|
3991
3995
|
"diff",
|
|
3992
3996
|
"--name-status",
|
|
3993
3997
|
"--no-ext-diff",
|
|
@@ -3999,9 +4003,9 @@ async function branchScope(git5, cwd, productionSha, stagingSha, refs, branches,
|
|
|
3999
4003
|
fallback.set(sha, { kind: "commit", sha, reason: "\u672A\u5F52\u5C5E\u5206\u652F\u7684\u5408\u5E76\u53D8\u52A8" });
|
|
4000
4004
|
}
|
|
4001
4005
|
}
|
|
4002
|
-
await applyPatchEquivalence(
|
|
4006
|
+
await applyPatchEquivalence(git6, cwd, branches, fallback);
|
|
4003
4007
|
nonVersionEntries.push(...fallback.values());
|
|
4004
|
-
await attachCommitDetails(
|
|
4008
|
+
await attachCommitDetails(git6, cwd, branches, nonVersionEntries);
|
|
4005
4009
|
return {
|
|
4006
4010
|
nonVersionEntries,
|
|
4007
4011
|
extraCommits: [...fallback.keys()],
|
|
@@ -4010,12 +4014,12 @@ async function branchScope(git5, cwd, productionSha, stagingSha, refs, branches,
|
|
|
4010
4014
|
mergedStagingCommitId: stagingSha
|
|
4011
4015
|
};
|
|
4012
4016
|
}
|
|
4013
|
-
async function attachCommitDetails(
|
|
4017
|
+
async function attachCommitDetails(git6, cwd, branches, nonVersionEntries) {
|
|
4014
4018
|
const lists = [
|
|
4015
4019
|
...branches.map((branch) => branch.expectedCommits || []),
|
|
4016
4020
|
...nonVersionEntries.map((entry) => entry.commits?.length ? entry.commits : [entry.sha])
|
|
4017
4021
|
];
|
|
4018
|
-
const bySha = await loadCommitDetails(
|
|
4022
|
+
const bySha = await loadCommitDetails(git6, cwd, lists.flat());
|
|
4019
4023
|
const apply = (shas) => takeCommitDetails(bySha, shas);
|
|
4020
4024
|
for (const branch of branches) {
|
|
4021
4025
|
if (!branch.expectedCommits) continue;
|
|
@@ -5259,11 +5263,11 @@ function mountedWorkspaces(store, root) {
|
|
|
5259
5263
|
}).length;
|
|
5260
5264
|
}
|
|
5261
5265
|
function registerLocalRoutes(app, store, options = {}) {
|
|
5262
|
-
const
|
|
5266
|
+
const git6 = (fn) => gitExecution.run({ executable: store.state.git }, fn);
|
|
5263
5267
|
app.get("/v1/capabilities", async () => {
|
|
5264
5268
|
let version = "", error = "";
|
|
5265
5269
|
try {
|
|
5266
|
-
version = await
|
|
5270
|
+
version = await git6(() => runGit(os6.homedir(), ["--version"]));
|
|
5267
5271
|
} catch (cause) {
|
|
5268
5272
|
error = cause.message;
|
|
5269
5273
|
}
|
|
@@ -5356,7 +5360,7 @@ function registerLocalRoutes(app, store, options = {}) {
|
|
|
5356
5360
|
if (!body.repositoryId || !path13.isAbsolute(body.path))
|
|
5357
5361
|
throw new Error("\u8BF7\u586B\u5199\u4ED3\u5E93\u8EAB\u4EFD\u4E0E\u672C\u673A\u7EDD\u5BF9\u76EE\u5F55");
|
|
5358
5362
|
const root = fs12.realpathSync(body.path);
|
|
5359
|
-
if (fs12.realpathSync(await
|
|
5363
|
+
if (fs12.realpathSync(await git6(() => runGit(root, ["rev-parse", "--show-toplevel"]))) !== root)
|
|
5360
5364
|
throw new Error("\u8BF7\u9009\u62E9 Git \u4ED3\u5E93\u6839\u76EE\u5F55");
|
|
5361
5365
|
store.state.repositories[scopeKey(grant.workbenchId, grant.userId, body.repositoryId)] = root;
|
|
5362
5366
|
store.save();
|
|
@@ -5485,7 +5489,8 @@ function registerAiRoutes(app, store) {
|
|
|
5485
5489
|
// src/ai-branch-review-route.ts
|
|
5486
5490
|
var RUN_ID = /^[a-zA-Z0-9-]{1,100}$/;
|
|
5487
5491
|
var SYSTEM_PROMPT3 = [
|
|
5488
|
-
"\u4F60\u662F Staging \u5185\u5BB9\u5BA1\u67E5\u52A9\u624B\u3002\
|
|
5492
|
+
"\u4F60\u662F Staging \u5185\u5BB9\u5BA1\u67E5\u52A9\u624B\u3002\u5168\u7A0B\u4F7F\u7528\u7B80\u4F53\u4E2D\u6587\uFF1A\u601D\u8003\u3001\u5DE5\u5177\u8C03\u7528\u524D\u540E\u7684\u8BF4\u660E\u3001\u6700\u7EC8\u5BA1\u67E5\u6B63\u6587\u3001\u811A\u672C\u53D8\u66F4 reason \u90FD\u7528\u4E2D\u6587\u3002\u5206\u652F\u540D\u3001\u8DEF\u5F84\u3001\u63D0\u4EA4\u53F7\u3001JSON \u5B57\u6BB5\u540D\u4FDD\u6301\u539F\u6587\u3002",
|
|
5493
|
+
"\u4F60\u5FC5\u987B\u7528\u5DE5\u5177\u81EA\u884C\u6BD4\u5BF9 Git \u5386\u53F2\uFF0C\u4E0D\u5F97\u4F9D\u8D56\u7528\u6237\u9884\u5148\u7ED9\u51FA\u7684\u8986\u76D6\u7ED3\u8BBA\u3002",
|
|
5489
5494
|
"\u5BF9\u6BCF\u4E2A\u4ED3\u5E93\u8C03\u7528\u4E00\u6B21 compare_staging\u3002\u5305\u542B\u5173\u7CFB\u548C\u591A\u51FA\u90E8\u5206\u53EA\u91C7\u7528\u8BE5\u5DE5\u5177\u7684\u7ED3\u679C\uFF0C\u4E0D\u8981\u7528\u63D0\u4EA4\u53F7\u662F\u5426\u76F8\u540C\u81EA\u884C\u5224\u65AD\uFF0C\u4E5F\u4E0D\u8981\u81EA\u884C\u8865\u5145\u5408\u5E76\u63D0\u4EA4\u3002",
|
|
5490
5495
|
"\u5DE5\u5177 result\uFF1A",
|
|
5491
5496
|
"- \u300C\u5DF2\u5305\u542B\u300D\u8F93\u51FA\uFF08staging \u5DF2\u5305\u542B\uFF09",
|
|
@@ -5493,9 +5498,11 @@ var SYSTEM_PROMPT3 = [
|
|
|
5493
5498
|
"- \u300C\u672A\u5305\u542B\u300D\u8F93\u51FA\uFF08staging \u672A\u5305\u542B\uFF09\u3002messageDiffers \u4E0D\u6539\u53D8\u672A\u5305\u542B\u3002",
|
|
5494
5499
|
"extras \u4E3A\u7A7A\u65F6\u4E0D\u8981\u8F93\u51FA\u300C\u591A\u51FA\u90E8\u5206\u300D\u3002\u6709 note \u65F6\u5199\u5728\u8BF4\u660E\u540E\u9762\uFF0C\u683C\u5F0F\uFF1A7\u4F4Dsha\uFF1A\u8BF4\u660E\uFF08note\uFF09\u3002",
|
|
5495
5500
|
"list_range_commits\u3001show_commit_meta\u3001diff_file_list \u53EA\u5728\u9700\u8981\u6838\u5BF9\u6807\u9898\u6216\u6587\u4EF6\u65F6\u4F7F\u7528\uFF0C\u4E0D\u80FD\u63A8\u7FFB compare_staging\u3002",
|
|
5496
|
-
"\u6BCF\u4E2A\u4ED3\u5E93\u518D\u8C03\u7528\u4E00\u6B21 list_script_candidates\
|
|
5497
|
-
"\
|
|
5498
|
-
"\
|
|
5501
|
+
"\u6BCF\u4E2A\u4ED3\u5E93\u518D\u8C03\u7528\u4E00\u6B21 list_script_candidates\u3002\u5019\u9009\u7684 ranges \u6807\u660E\u8DEF\u5F84\u51FA\u73B0\u5728\u54EA\u6761\u5206\u652F\u76F8\u5BF9 production\uFF0C\u6216 production..staging\u3002",
|
|
5502
|
+
"\u53EA\u5BF9\u53EF\u80FD\u6539\u8868\u7ED3\u6784\u6216\u5B57\u6BB5\u7C7B\u578B\u7684\u8DEF\u5F84\u8C03\u7528 show_file_diff\uFF0Cbase \u7528 production\uFF0Chead \u7528\u5BF9\u5E94\u5206\u652F\u540D\uFF08staging \u4E0A\u7684\u7528 staging\uFF09\u3002",
|
|
5503
|
+
"\u811A\u672C\u53D8\u66F4\u53EA\u8BA4\u8868\u7ED3\u6784\u6216\u5B57\u6BB5\u7C7B\u578B\uFF1A\u65B0\u589E/\u5220\u9664\u8868\u6216\u5217\u3001\u6539\u5217\u7C7B\u578B\u6216\u957F\u5EA6\u7CBE\u5EA6\u3001\u5B9E\u4F53\u5B57\u6BB5\u4E0E\u5E93\u5217\u7684\u7C7B\u578B\u6216\u5217\u6620\u5C04\u589E\u51CF\u3002",
|
|
5504
|
+
"\u4E0D\u7B97\u811A\u672C\u53D8\u66F4\uFF1A\u67E5\u8BE2\u6761\u4EF6\u3001\u805A\u5408\u53E3\u5F84\uFF08\u5982 SUM\uFF09\u3001\u53C2\u6570\u7ED1\u5B9A\u3001\u6CE8\u91CA\u3001import\u3001\u683C\u5F0F\u5316\u3001\u53EA\u6539 SQL \u6587\u6848\u4F46\u4E0D\u6539\u5217\u5B9A\u4E49\u3002",
|
|
5505
|
+
"\u4E0D\u5F97\u7F16\u9020\u5019\u9009\u5217\u8868\u6216 diff \u91CC\u6CA1\u6709\u51FA\u73B0\u7684\u8DEF\u5F84\u548C\u5206\u652F\u3002\u811A\u672C\u53D8\u66F4\u4E0D\u5F71\u54CD\u5305\u542B\u5173\u7CFB\u7ED3\u8BBA\u3002",
|
|
5499
5506
|
"repository \u586B id \u6216 alias\u3002\u8FDC\u7AEF\u5206\u652F\u4E0D\u5B58\u5728\u65F6\u5DE5\u5177\u4F1A\u7ED9\u51FA\u672A\u5305\u542B\u3002",
|
|
5500
5507
|
"\u8BF7\u53EA\u6309\u4E0B\u9762\u683C\u5F0F\u8F93\u51FA\u7EAF\u6587\u672C\uFF0C\u4E0D\u8981 markdown\uFF0C\u4E0D\u8981\u89E3\u91CA\uFF1A",
|
|
5501
5508
|
"\u4ED3\u5E93\u522B\u540D:",
|
|
@@ -5504,8 +5511,8 @@ var SYSTEM_PROMPT3 = [
|
|
|
5504
5511
|
" - 7\u4F4Dsha\uFF1A\u63D0\u4EA4\u8BF4\u660E",
|
|
5505
5512
|
"\u4E0D\u5F97\u7F16\u9020\u5DE5\u5177\u7ED3\u679C\u91CC\u6CA1\u6709\u51FA\u73B0\u7684\u5206\u652F\u3001\u63D0\u4EA4\u6216\u8BF4\u660E\u3002",
|
|
5506
5513
|
"\u6B63\u6587\u7ED3\u675F\u540E\u5355\u72EC\u4E00\u884C\u5199 ---script-changes---\uFF0C\u4E0B\u4E00\u884C\u53EA\u8F93\u51FA\u4E00\u4E2A JSON \u5BF9\u8C61\uFF1A",
|
|
5507
|
-
'{"status":"none"|"found","items":[{"repository":"\u522B\u540D","path":"\u76F8\u5BF9\u8DEF\u5F84","reason":"\
|
|
5508
|
-
"\
|
|
5514
|
+
'{"status":"none"|"found","items":[{"repository":"\u522B\u540D","branch":"\u5206\u652F\u540D","path":"\u76F8\u5BF9\u8DEF\u5F84","reason":"\u8868\u6216\u5B57\u6BB5\u7C7B\u578B\u53D1\u751F\u4E86\u4EC0\u4E48"}]}',
|
|
5515
|
+
"branch \u5FC5\u987B\u662F\u8BE5\u6587\u4EF6 diff \u6240\u7528\u7684\u7248\u672C\u5185\u5206\u652F\u540D\uFF1B\u4EC5\u51FA\u73B0\u5728 staging \u65F6\u586B staging\u3002\u65E0\u8868\u7ED3\u6784\u6216\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4\u65F6 status \u4E3A none \u4E14 items \u4E3A\u7A7A\u6570\u7EC4\u3002"
|
|
5509
5516
|
].join("\n");
|
|
5510
5517
|
async function git2(cwd, args) {
|
|
5511
5518
|
return runGit(cwd, [
|
|
@@ -5890,7 +5897,8 @@ function scanRepositorySummaryInput(root, subpath = "") {
|
|
|
5890
5897
|
|
|
5891
5898
|
// ../../packages/runtime/src/ai/repo-summary.ts
|
|
5892
5899
|
var REPO_ROLES = ["domain-service", "bff-api", "frontend", "infra", "unknown"];
|
|
5893
|
-
var SUMMARY_TEXT_MAX =
|
|
5900
|
+
var SUMMARY_TEXT_MAX = 400;
|
|
5901
|
+
var USER_SUMMARY_TEXT_MAX = 800;
|
|
5894
5902
|
var TERM_MAX = 40;
|
|
5895
5903
|
var TERMS_MAX = 40;
|
|
5896
5904
|
var OBJECT2 = {
|
|
@@ -5898,10 +5906,15 @@ var OBJECT2 = {
|
|
|
5898
5906
|
additionalProperties: false
|
|
5899
5907
|
};
|
|
5900
5908
|
var SYSTEM_PROMPT4 = [
|
|
5901
|
-
"\u4F60\u662F\u4ED3\u5E93\u6458\u8981\u52A9\u624B\u3002\
|
|
5909
|
+
"\u4F60\u662F\u4ED3\u5E93\u6458\u8981\u52A9\u624B\u3002\u601D\u8003\u4E0E\u8BF4\u660E\u4F7F\u7528\u7B80\u4F53\u4E2D\u6587\uFF1Bdomain\u3001summary\u3001matchHints \u7528\u4E2D\u6587\uFF0C\u8DEF\u5F84\u4E0E\u6807\u8BC6\u4FDD\u6301\u539F\u6587\u3002",
|
|
5910
|
+
"\u7528\u6237\u4F1A\u63D0\u4F9B\u786E\u5B9A\u6027\u626B\u63CF\u5F97\u5230\u7684\u5B9E\u4F53\u8FB9\u754C\u4E0E\u6280\u672F\u6808\u8BC1\u636E\u3002",
|
|
5902
5911
|
"\u4F60\u53EF\u4EE5\u6839\u636E\u5DE5\u5177\u53EA\u8BFB\u67E5\u770B\u76EE\u5F55\u548C\u5C11\u91CF\u6E90\u6587\u4EF6\u4EE5\u8865\u5145\u7406\u89E3\uFF0C\u4F46\u4E0D\u5F97\u7F16\u9020\u626B\u63CF\u7ED3\u679C\u4E2D\u4E0D\u5B58\u5728\u7684\u5B9E\u4F53\u6216\u4F9D\u8D56\u3002",
|
|
5912
|
+
"\u82E5\u63D0\u4F9B priorRevision\uFF0C\u8FD9\u662F\u7528\u6237\u5DF2\u624B\u5DE5\u4FEE\u8BA2\u7684\u4E0A\u4E00\u7248\u753B\u50CF\u3002\u8BF7\u4EE5\u5176\u4E3A\u5E95\u7A3F\uFF0C\u7ED3\u5408\u6700\u65B0\u626B\u63CF\u66F4\u65B0\uFF1A",
|
|
5913
|
+
"- \u4FDD\u7559\u7528\u6237\u8865\u5145\u7684\u4E1A\u52A1\u8BF4\u660E\u3001\u8FB9\u754C\u8868\u8FF0\u4E0E\u5339\u914D\u8BCD\uFF0C\u4E0D\u5F97\u7528\u66F4\u77ED\u7A7A\u6CDB\u6458\u8981\u8986\u76D6\u6389",
|
|
5914
|
+
"- \u626B\u63CF\u65B0\u589E\u7684\u5B9E\u4F53\u3001\u6280\u672F\u8BC1\u636E\u53EF\u5199\u5165 matchTerms / matchHints",
|
|
5915
|
+
"- \u660E\u663E\u8FC7\u65F6\u6216\u4E0E\u626B\u63CF\u51B2\u7A81\u7684\u8868\u8FF0\u53EF\u4EE5\u6539\u5199\uFF0C\u4F46\u5148\u4FDD\u7559\u7528\u6237\u539F\u610F",
|
|
5903
5916
|
"\u53EA\u8F93\u51FA\u4E00\u4E2A JSON \u5BF9\u8C61\uFF0C\u4E0D\u8981 markdown\uFF0C\u5B57\u6BB5\uFF1A",
|
|
5904
|
-
'{"domain":"\u4E1A\u52A1\u57DF\u77ED\u6807\u7B7E","role":"domain-service|bff-api|frontend|infra|unknown","matchTerms":["\u53EF\u68C0\u7D22\u8BCD"],"matchHints":{"strong":["\u5F3A\u76F8\u5173\u4E2D\u6587\u8BCD"],"weak":["\u5F31\u76F8\u5173\u4E2D\u6587\u8BCD"]},"summary":"\u4E0D\u8D85\
|
|
5917
|
+
'{"domain":"\u4E1A\u52A1\u57DF\u77ED\u6807\u7B7E","role":"domain-service|bff-api|frontend|infra|unknown","matchTerms":["\u53EF\u68C0\u7D22\u8BCD"],"matchHints":{"strong":["\u5F3A\u76F8\u5173\u4E2D\u6587\u8BCD"],"weak":["\u5F31\u76F8\u5173\u4E2D\u6587\u8BCD"]},"summary":"\u4E0D\u8D85\u8FC7400\u5B57\uFF0C\u8BF4\u660E\u7BA1\u4EC0\u4E48\u5BF9\u8C61\u3001\u4E0D\u505A\u4EC0\u4E48"}',
|
|
5905
5918
|
"matchTerms \u542B\u5B9E\u4F53\u7B80\u540D\u3001\u53BB Entity/DO/PO \u540E\u7F00\u540E\u7684\u8BCD\u3001\u4EE5\u53CA\u4ECE\u522B\u540D\u80FD\u63A8\u65AD\u7684\u540C\u4E49\u8BCD\u3002",
|
|
5906
5919
|
"role\uFF1A\u9886\u57DF\u670D\u52A1\u7528 domain-service\uFF0C\u7F51\u5173/\u805A\u5408 API \u7528 bff-api\uFF0C\u524D\u7AEF\u7528 frontend\uFF0C\u57FA\u7840\u8BBE\u65BD\u7528 infra\uFF0C\u65E0\u6CD5\u5224\u65AD\u7528 unknown\u3002"
|
|
5907
5920
|
].join("\n");
|
|
@@ -6033,6 +6046,40 @@ function parseRepoSummaryModel(content, entities) {
|
|
|
6033
6046
|
structured
|
|
6034
6047
|
};
|
|
6035
6048
|
}
|
|
6049
|
+
function mergeRepoSummaryPrior(next, prior) {
|
|
6050
|
+
if (!prior) return next;
|
|
6051
|
+
const priorRole = REPO_ROLES.includes(String(prior.role || "")) ? prior.role : void 0;
|
|
6052
|
+
return {
|
|
6053
|
+
...next,
|
|
6054
|
+
domain: next.domain || String(prior.domain || "").trim().slice(0, 40),
|
|
6055
|
+
role: next.role !== "unknown" ? next.role : priorRole || "unknown",
|
|
6056
|
+
summary: (next.summary || String(prior.summary || "").trim()).slice(0, SUMMARY_TEXT_MAX),
|
|
6057
|
+
matchTerms: clipTerms([...prior.matchTerms || [], ...next.matchTerms]),
|
|
6058
|
+
matchHints: {
|
|
6059
|
+
strong: clipTerms([...prior.matchHints?.strong || [], ...next.matchHints.strong]),
|
|
6060
|
+
weak: clipTerms([...prior.matchHints?.weak || [], ...next.matchHints.weak])
|
|
6061
|
+
}
|
|
6062
|
+
};
|
|
6063
|
+
}
|
|
6064
|
+
function acceptRepoSummaryPrior(value) {
|
|
6065
|
+
if (!value || typeof value !== "object") return void 0;
|
|
6066
|
+
const row = value;
|
|
6067
|
+
const prior = {
|
|
6068
|
+
domain: typeof row.domain === "string" ? row.domain.trim().slice(0, 40) : "",
|
|
6069
|
+
role: typeof row.role === "string" ? row.role.trim().slice(0, 40) : "",
|
|
6070
|
+
summary: typeof row.summary === "string" ? row.summary.trim().slice(0, USER_SUMMARY_TEXT_MAX) : "",
|
|
6071
|
+
matchTerms: clipTerms(row.matchTerms),
|
|
6072
|
+
matchHints: {
|
|
6073
|
+
strong: clipTerms(row.matchHints?.strong),
|
|
6074
|
+
weak: clipTerms(row.matchHints?.weak)
|
|
6075
|
+
}
|
|
6076
|
+
};
|
|
6077
|
+
const strong = prior.matchHints?.strong || [];
|
|
6078
|
+
const weak = prior.matchHints?.weak || [];
|
|
6079
|
+
if (!prior.domain && !prior.role && !prior.summary && !(prior.matchTerms || []).length && !strong.length && !weak.length)
|
|
6080
|
+
return void 0;
|
|
6081
|
+
return prior;
|
|
6082
|
+
}
|
|
6036
6083
|
function repoSummaryUserPrompt(input) {
|
|
6037
6084
|
return JSON.stringify(
|
|
6038
6085
|
{
|
|
@@ -6045,7 +6092,8 @@ function repoSummaryUserPrompt(input) {
|
|
|
6045
6092
|
count: input.entities.items.length,
|
|
6046
6093
|
items: input.entities.items.slice(0, 120)
|
|
6047
6094
|
},
|
|
6048
|
-
techStack: input.techStack
|
|
6095
|
+
techStack: input.techStack,
|
|
6096
|
+
...input.prior ? { priorRevision: input.prior } : {}
|
|
6049
6097
|
},
|
|
6050
6098
|
null,
|
|
6051
6099
|
2
|
|
@@ -6064,13 +6112,17 @@ async function runRepoSummary(options) {
|
|
|
6064
6112
|
user: repoSummaryUserPrompt({
|
|
6065
6113
|
alias: options.alias,
|
|
6066
6114
|
entities: scanned.entities,
|
|
6067
|
-
techStack: scanned.techStack
|
|
6115
|
+
techStack: scanned.techStack,
|
|
6116
|
+
prior: options.prior
|
|
6068
6117
|
}),
|
|
6069
6118
|
tools,
|
|
6070
6119
|
budget: options.budget,
|
|
6071
6120
|
trace: options.trace
|
|
6072
6121
|
});
|
|
6073
|
-
profile =
|
|
6122
|
+
profile = mergeRepoSummaryPrior(
|
|
6123
|
+
parseRepoSummaryModel(outcome.content, scanned.entities),
|
|
6124
|
+
options.prior
|
|
6125
|
+
);
|
|
6074
6126
|
if (outcome.stop) {
|
|
6075
6127
|
status = "incomplete";
|
|
6076
6128
|
error = outcome.stop === "rounds" ? "\u5DF2\u8FBE\u8C03\u7528\u4E0A\u9650\uFF08" + options.budget.toolRounds + " \u8F6E\uFF09" : outcome.stop === "tokens" ? "\u5DF2\u8FBE token \u4E0A\u9650" : "AI \u6458\u8981\u8D85\u65F6";
|
|
@@ -6158,6 +6210,7 @@ function registerRepoSummaryRoute(app, store, jobs) {
|
|
|
6158
6210
|
const subpath = String(body.subpath || "").trim();
|
|
6159
6211
|
const force = Boolean(body.force);
|
|
6160
6212
|
const knownHead = String(body.knownHead || "").trim();
|
|
6213
|
+
const prior = acceptRepoSummaryPrior(body.prior);
|
|
6161
6214
|
if (!REPO_ID.test(repositoryId)) throw new Error("\u4ED3\u5E93\u65E0\u6548");
|
|
6162
6215
|
if (subpath && (path17.isAbsolute(subpath) || subpath.split(/[\\/]/).includes("..") || subpath.includes("\0")))
|
|
6163
6216
|
throw new Error("\u5B50\u76EE\u5F55\u65E0\u6548");
|
|
@@ -6207,6 +6260,7 @@ function registerRepoSummaryRoute(app, store, jobs) {
|
|
|
6207
6260
|
subpath,
|
|
6208
6261
|
sourceKind: source.kind,
|
|
6209
6262
|
headSha,
|
|
6263
|
+
prior,
|
|
6210
6264
|
budget,
|
|
6211
6265
|
trace: trace.write
|
|
6212
6266
|
});
|
|
@@ -7214,9 +7268,9 @@ async function fetchWorkbenchIdentity(origin) {
|
|
|
7214
7268
|
}
|
|
7215
7269
|
|
|
7216
7270
|
// src/query-routes.ts
|
|
7217
|
-
import
|
|
7218
|
-
import
|
|
7219
|
-
import
|
|
7271
|
+
import fs30 from "node:fs";
|
|
7272
|
+
import os9 from "node:os";
|
|
7273
|
+
import path32 from "node:path";
|
|
7220
7274
|
|
|
7221
7275
|
// ../../packages/runtime/src/agent-sessions/service.ts
|
|
7222
7276
|
import path29 from "node:path";
|
|
@@ -7786,11 +7840,13 @@ function listAgentSessions(home, scope) {
|
|
|
7786
7840
|
}
|
|
7787
7841
|
|
|
7788
7842
|
// ../../packages/runtime/src/git/commits.ts
|
|
7843
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
7789
7844
|
import fs28 from "node:fs";
|
|
7790
7845
|
import path30 from "node:path";
|
|
7791
7846
|
var PAGE_SIZE = 20;
|
|
7792
7847
|
var SYNC_INTERVAL_MS = 3e4;
|
|
7793
7848
|
var comparisonSyncs = /* @__PURE__ */ new Map();
|
|
7849
|
+
var bareCaches = /* @__PURE__ */ new Map();
|
|
7794
7850
|
function normalizeCommitCompareBranch(value) {
|
|
7795
7851
|
if (value === void 0) return "production";
|
|
7796
7852
|
if (typeof value !== "string") return void 0;
|
|
@@ -7869,6 +7925,49 @@ async function branchHasChanges(cwd, branch, compareBranch) {
|
|
|
7869
7925
|
return true;
|
|
7870
7926
|
}
|
|
7871
7927
|
}
|
|
7928
|
+
async function commitsBetween(cwd, head, branch, base, compareBranch, offset, empty) {
|
|
7929
|
+
try {
|
|
7930
|
+
await git4(cwd, ["merge-base", base.commit, head]);
|
|
7931
|
+
} catch (error) {
|
|
7932
|
+
if (error instanceof GitCommandError && error.exitCode === 1)
|
|
7933
|
+
return { ...empty, branch, unavailable: "\u5F53\u524D\u5206\u652F\u4E0E\u8FDC\u7AEF " + compareBranch + " \u6CA1\u6709\u5171\u540C\u5386\u53F2" };
|
|
7934
|
+
throw error;
|
|
7935
|
+
}
|
|
7936
|
+
const range = base.commit + ".." + head;
|
|
7937
|
+
const total = Number(await git4(cwd, ["rev-list", "--count", range]));
|
|
7938
|
+
const raw = await git4(cwd, [
|
|
7939
|
+
"log",
|
|
7940
|
+
"--date-order",
|
|
7941
|
+
"--no-show-signature",
|
|
7942
|
+
"--format=%H%x00%h%x00%s%x00%an%x00%aI%x00",
|
|
7943
|
+
"--max-count=" + PAGE_SIZE,
|
|
7944
|
+
"--skip=" + offset,
|
|
7945
|
+
range,
|
|
7946
|
+
"--"
|
|
7947
|
+
]);
|
|
7948
|
+
const fields = raw.split("\0");
|
|
7949
|
+
const commits = [];
|
|
7950
|
+
for (let index = 0; index + 5 <= fields.length; index += 5) {
|
|
7951
|
+
const hash = fields[index].trim();
|
|
7952
|
+
if (!hash) continue;
|
|
7953
|
+
commits.push({
|
|
7954
|
+
hash,
|
|
7955
|
+
shortHash: fields[index + 1],
|
|
7956
|
+
subject: fields[index + 2],
|
|
7957
|
+
author: fields[index + 3],
|
|
7958
|
+
authoredAt: fields[index + 4]
|
|
7959
|
+
});
|
|
7960
|
+
}
|
|
7961
|
+
return {
|
|
7962
|
+
commits,
|
|
7963
|
+
total,
|
|
7964
|
+
hasMore: offset + commits.length < total,
|
|
7965
|
+
branch,
|
|
7966
|
+
baseRef: empty.baseRef,
|
|
7967
|
+
baseUpdatedAt: base.updatedAt,
|
|
7968
|
+
head
|
|
7969
|
+
};
|
|
7970
|
+
}
|
|
7872
7971
|
async function readWorkspaceCommits(mount, offset = 0, refresh = false) {
|
|
7873
7972
|
const compareBranch = normalizeCommitCompareBranch(mount.commit_compare_branch);
|
|
7874
7973
|
const empty = {
|
|
@@ -7886,85 +7985,245 @@ async function readWorkspaceCommits(mount, offset = 0, refresh = false) {
|
|
|
7886
7985
|
const branch = await git4(mount.folder_path, ["branch", "--show-current"]) || "\u5206\u79BB HEAD";
|
|
7887
7986
|
const base = await latestComparison(mount.folder_path, compareBranch, refresh);
|
|
7888
7987
|
if ("unavailable" in base) return { ...empty, branch, unavailable: base.unavailable };
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
if (error instanceof GitCommandError && error.exitCode === 1)
|
|
7893
|
-
return {
|
|
7894
|
-
...empty,
|
|
7895
|
-
branch,
|
|
7896
|
-
unavailable: "\u5F53\u524D\u5206\u652F\u4E0E\u8FDC\u7AEF " + compareBranch + " \u6CA1\u6709\u5171\u540C\u5386\u53F2"
|
|
7897
|
-
};
|
|
7898
|
-
throw error;
|
|
7899
|
-
}
|
|
7900
|
-
const range = base.commit + ".." + head;
|
|
7901
|
-
const total = Number(await git4(mount.folder_path, ["rev-list", "--count", range]));
|
|
7902
|
-
const raw = await git4(mount.folder_path, [
|
|
7903
|
-
"log",
|
|
7904
|
-
"--date-order",
|
|
7905
|
-
"--no-show-signature",
|
|
7906
|
-
"--format=%H%x00%h%x00%s%x00%an%x00%aI%x00",
|
|
7907
|
-
"--max-count=" + PAGE_SIZE,
|
|
7908
|
-
"--skip=" + offset,
|
|
7909
|
-
range,
|
|
7910
|
-
"--"
|
|
7911
|
-
]);
|
|
7912
|
-
const fields = raw.split("\0");
|
|
7913
|
-
const commits = [];
|
|
7914
|
-
for (let index = 0; index + 5 <= fields.length; index += 5) {
|
|
7915
|
-
const hash = fields[index].trim();
|
|
7916
|
-
if (!hash) continue;
|
|
7917
|
-
commits.push({
|
|
7918
|
-
hash,
|
|
7919
|
-
shortHash: fields[index + 1],
|
|
7920
|
-
subject: fields[index + 2],
|
|
7921
|
-
author: fields[index + 3],
|
|
7922
|
-
authoredAt: fields[index + 4]
|
|
7923
|
-
});
|
|
7924
|
-
}
|
|
7925
|
-
return {
|
|
7926
|
-
commits,
|
|
7927
|
-
total,
|
|
7928
|
-
hasMore: offset + commits.length < total,
|
|
7988
|
+
return await commitsBetween(
|
|
7989
|
+
mount.folder_path,
|
|
7990
|
+
head,
|
|
7929
7991
|
branch,
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
|
|
7992
|
+
base,
|
|
7993
|
+
compareBranch,
|
|
7994
|
+
offset,
|
|
7995
|
+
empty
|
|
7996
|
+
);
|
|
7934
7997
|
} catch {
|
|
7935
7998
|
return { ...empty, unavailable: "\u65E0\u6CD5\u8BFB\u53D6 Git \u63D0\u4EA4\u8BB0\u5F55\uFF0C\u8BF7\u68C0\u67E5\u4ED3\u5E93\u4E0E\u672C\u5730\u5F15\u7528" };
|
|
7936
7999
|
}
|
|
7937
8000
|
}
|
|
8001
|
+
function prepareBareCache(dir, remoteUrl) {
|
|
8002
|
+
const current = bareCaches.get(dir);
|
|
8003
|
+
if (current) return current;
|
|
8004
|
+
const created = (async () => {
|
|
8005
|
+
fs28.mkdirSync(dir, { recursive: true });
|
|
8006
|
+
if (!fs28.existsSync(path30.join(dir, "HEAD"))) await runGit(dir, ["init", "--bare"]);
|
|
8007
|
+
const remotes = (await runGit(dir, ["remote"])).split("\n").filter(Boolean);
|
|
8008
|
+
if (!remotes.includes("origin")) await runGit(dir, ["remote", "add", "origin", remoteUrl]);
|
|
8009
|
+
})();
|
|
8010
|
+
bareCaches.set(dir, created);
|
|
8011
|
+
return created.finally(() => {
|
|
8012
|
+
if (bareCaches.get(dir) === created) bareCaches.delete(dir);
|
|
8013
|
+
});
|
|
8014
|
+
}
|
|
8015
|
+
async function readRemoteBranchCommits(cacheRoot, remoteUrl, branchName, compareName, offset = 0, refresh = false) {
|
|
8016
|
+
const compareBranch = normalizeCommitCompareBranch(compareName);
|
|
8017
|
+
const branch = normalizeCommitCompareBranch(branchName);
|
|
8018
|
+
const empty = {
|
|
8019
|
+
commits: [],
|
|
8020
|
+
total: 0,
|
|
8021
|
+
hasMore: false,
|
|
8022
|
+
branch: branch || "",
|
|
8023
|
+
baseRef: "origin/" + (compareBranch || "production")
|
|
8024
|
+
};
|
|
8025
|
+
if (!compareBranch || !branch) return { ...empty, unavailable: "\u4ED3\u5E93\u5206\u652F\u6216\u5BF9\u6BD4\u5206\u652F\u65E0\u6548" };
|
|
8026
|
+
if (!remoteUrl || /[\s\x00]/.test(remoteUrl) || remoteUrl.length > 500)
|
|
8027
|
+
return { ...empty, unavailable: "\u4ED3\u5E93\u6CA1\u6709\u8FDC\u7A0B\u5730\u5740\uFF0C\u65E0\u6CD5\u5728\u672A\u6302\u8F7D\u65F6\u62C9\u53D6\u63D0\u4EA4" };
|
|
8028
|
+
const dir = path30.join(
|
|
8029
|
+
cacheRoot,
|
|
8030
|
+
createHash3("sha256").update(remoteUrl).digest("hex").slice(0, 20)
|
|
8031
|
+
);
|
|
8032
|
+
try {
|
|
8033
|
+
await prepareBareCache(dir, remoteUrl);
|
|
8034
|
+
const head = await latestComparison(dir, branch, refresh);
|
|
8035
|
+
if ("unavailable" in head) return { ...empty, unavailable: head.unavailable };
|
|
8036
|
+
const base = await latestComparison(dir, compareBranch, refresh);
|
|
8037
|
+
if ("unavailable" in base) return { ...empty, unavailable: base.unavailable };
|
|
8038
|
+
return await commitsBetween(dir, head.commit, branch, base, compareBranch, offset, empty);
|
|
8039
|
+
} catch {
|
|
8040
|
+
return { ...empty, unavailable: "\u65E0\u6CD5\u8BFB\u53D6\u8FDC\u7AEF\u63D0\u4EA4\u8BB0\u5F55\uFF0C\u8BF7\u68C0\u67E5\u8FDC\u7A0B\u5730\u5740\u3001\u7F51\u7EDC\u548C\u5206\u652F" };
|
|
8041
|
+
}
|
|
8042
|
+
}
|
|
8043
|
+
|
|
8044
|
+
// ../../packages/runtime/src/git/merge-branch.ts
|
|
8045
|
+
import fs29 from "node:fs";
|
|
8046
|
+
import os8 from "node:os";
|
|
8047
|
+
import path31 from "node:path";
|
|
8048
|
+
var MERGE_TARGETS = ["test", "staging"];
|
|
8049
|
+
var repoLocks = /* @__PURE__ */ new Map();
|
|
8050
|
+
function hooksPath() {
|
|
8051
|
+
return process.platform === "win32" ? "NUL" : "/dev/null";
|
|
8052
|
+
}
|
|
8053
|
+
function git5(cwd, args, timeoutMs = 3e4) {
|
|
8054
|
+
return runGit(cwd, ["-c", "core.hooksPath=" + hooksPath(), ...args], { timeoutMs });
|
|
8055
|
+
}
|
|
8056
|
+
function mergeRequest(sourceName, targetName) {
|
|
8057
|
+
const target = MERGE_TARGETS.find((name) => name === targetName);
|
|
8058
|
+
const source = normalizeCommitCompareBranch(sourceName);
|
|
8059
|
+
if (!target) throw new Error("\u53EA\u80FD\u5408\u5165 test \u6216 staging");
|
|
8060
|
+
if (!source) throw new Error("\u6E90\u5206\u652F\u540D\u79F0\u65E0\u6548");
|
|
8061
|
+
if (source === target) throw new Error("\u6E90\u5206\u652F\u4E0E\u76EE\u6807\u5206\u652F\u76F8\u540C\uFF0C\u65E0\u9700\u5408\u5165");
|
|
8062
|
+
return { source, target };
|
|
8063
|
+
}
|
|
8064
|
+
async function withRepoLock(key, run) {
|
|
8065
|
+
const previous = repoLocks.get(key) ?? Promise.resolve();
|
|
8066
|
+
let release = () => {
|
|
8067
|
+
};
|
|
8068
|
+
const current = new Promise((resolve) => {
|
|
8069
|
+
release = resolve;
|
|
8070
|
+
});
|
|
8071
|
+
const tail = previous.then(
|
|
8072
|
+
() => current,
|
|
8073
|
+
() => current
|
|
8074
|
+
);
|
|
8075
|
+
repoLocks.set(key, tail);
|
|
8076
|
+
await previous.catch(() => {
|
|
8077
|
+
});
|
|
8078
|
+
try {
|
|
8079
|
+
return await run();
|
|
8080
|
+
} finally {
|
|
8081
|
+
release();
|
|
8082
|
+
if (repoLocks.get(key) === tail) repoLocks.delete(key);
|
|
8083
|
+
}
|
|
8084
|
+
}
|
|
8085
|
+
async function requireCommitter(cwd) {
|
|
8086
|
+
const name = await git5(cwd, ["config", "--get", "user.name"]).catch(() => "");
|
|
8087
|
+
const email = await git5(cwd, ["config", "--get", "user.email"]).catch(() => "");
|
|
8088
|
+
if (!name.trim() || !email.trim())
|
|
8089
|
+
throw new Error("\u8BF7\u5148\u5728\u672C\u673A Git \u914D\u7F6E user.name \u548C user.email\uFF0C\u518D\u5408\u5165\u5206\u652F");
|
|
8090
|
+
}
|
|
8091
|
+
async function fetchRemoteBranch(cwd, branch) {
|
|
8092
|
+
const remoteRef = "refs/remotes/origin/" + branch;
|
|
8093
|
+
await git5(
|
|
8094
|
+
cwd,
|
|
8095
|
+
[
|
|
8096
|
+
"-c",
|
|
8097
|
+
"gc.auto=0",
|
|
8098
|
+
"fetch",
|
|
8099
|
+
"--no-tags",
|
|
8100
|
+
"--no-write-fetch-head",
|
|
8101
|
+
"origin",
|
|
8102
|
+
"+refs/heads/" + branch + ":" + remoteRef
|
|
8103
|
+
],
|
|
8104
|
+
45e3
|
|
8105
|
+
);
|
|
8106
|
+
return git5(cwd, ["rev-parse", "--verify", "--end-of-options", remoteRef + "^{commit}"]);
|
|
8107
|
+
}
|
|
8108
|
+
async function remotePersonal(cwd, source) {
|
|
8109
|
+
let remoteSha = "";
|
|
8110
|
+
try {
|
|
8111
|
+
remoteSha = await fetchRemoteBranch(cwd, source);
|
|
8112
|
+
} catch {
|
|
8113
|
+
throw new Error("\u4E2A\u4EBA\u5206\u652F\u5C1A\u672A\u63A8\u9001\u5230\u8FDC\u7A0B\u4ED3\u5E93\uFF0C\u4E0D\u80FD\u5408\u5165");
|
|
8114
|
+
}
|
|
8115
|
+
const localSha = await git5(cwd, [
|
|
8116
|
+
"rev-parse",
|
|
8117
|
+
"--verify",
|
|
8118
|
+
"--end-of-options",
|
|
8119
|
+
"refs/heads/" + source
|
|
8120
|
+
]).catch(() => "");
|
|
8121
|
+
if (localSha && !await sourceAlreadyOnTarget(cwd, localSha, remoteSha))
|
|
8122
|
+
throw new Error("\u4E2A\u4EBA\u5206\u652F\u6709\u672A\u63A8\u9001\u7684\u63D0\u4EA4\uFF0C\u8BF7\u5148\u63A8\u9001\u5230\u8FDC\u7A0B\u4ED3\u5E93\u540E\u518D\u5408\u5165");
|
|
8123
|
+
return remoteSha;
|
|
8124
|
+
}
|
|
8125
|
+
async function fetchTarget(cwd, target) {
|
|
8126
|
+
const remotes = (await git5(cwd, ["remote"])).split("\n");
|
|
8127
|
+
if (!remotes.includes("origin")) throw new Error("\u4ED3\u5E93\u672A\u914D\u7F6E origin\uFF0C\u65E0\u6CD5\u5408\u5165\u8FDC\u7AEF " + target);
|
|
8128
|
+
try {
|
|
8129
|
+
return await fetchRemoteBranch(cwd, target);
|
|
8130
|
+
} catch {
|
|
8131
|
+
throw new Error("\u65E0\u6CD5\u540C\u6B65\u8FDC\u7AEF " + target + "\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u3001\u4ED3\u5E93\u6743\u9650\u548C\u8FDC\u7AEF\u5206\u652F\u540E\u91CD\u8BD5");
|
|
8132
|
+
}
|
|
8133
|
+
}
|
|
8134
|
+
async function sourceAlreadyOnTarget(cwd, sourceSha, targetSha) {
|
|
8135
|
+
try {
|
|
8136
|
+
await git5(cwd, ["merge-base", "--is-ancestor", sourceSha, targetSha]);
|
|
8137
|
+
return true;
|
|
8138
|
+
} catch (error) {
|
|
8139
|
+
if (error instanceof GitCommandError && error.exitCode === 1) return false;
|
|
8140
|
+
throw error;
|
|
8141
|
+
}
|
|
8142
|
+
}
|
|
8143
|
+
async function mergeIntoTarget(temp, sourceSha, target) {
|
|
8144
|
+
try {
|
|
8145
|
+
await git5(temp, ["merge", "--no-edit", sourceSha], 45e3);
|
|
8146
|
+
} catch (error) {
|
|
8147
|
+
const listed = await git5(temp, ["diff", "--name-only", "--diff-filter=U"]).catch(() => "");
|
|
8148
|
+
await git5(temp, ["merge", "--abort"]).catch(() => {
|
|
8149
|
+
});
|
|
8150
|
+
const files = listed.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
8151
|
+
if (files.length) return { conflict: files };
|
|
8152
|
+
const message = error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF";
|
|
8153
|
+
throw new Error("\u5408\u5165 " + target + " \u5931\u8D25\uFF1A" + message);
|
|
8154
|
+
}
|
|
8155
|
+
return { commit: await git5(temp, ["rev-parse", "HEAD"]) };
|
|
8156
|
+
}
|
|
8157
|
+
async function pushTarget(temp, target) {
|
|
8158
|
+
try {
|
|
8159
|
+
await git5(temp, ["push", "origin", "HEAD:refs/heads/" + target], 6e4);
|
|
8160
|
+
} catch (error) {
|
|
8161
|
+
const message = error instanceof Error ? error.message : "";
|
|
8162
|
+
if (/non-fast-forward|\[rejected\]|fetch first/i.test(message))
|
|
8163
|
+
throw new Error("\u8FDC\u7AEF " + target + " \u5DF2\u6709\u65B0\u63D0\u4EA4\uFF0C\u672A\u63A8\u9001\u3002\u8BF7\u91CD\u8BD5");
|
|
8164
|
+
throw new Error("\u63A8\u9001\u5230\u8FDC\u7AEF " + target + " \u5931\u8D25\uFF1A" + message);
|
|
8165
|
+
}
|
|
8166
|
+
}
|
|
8167
|
+
async function mergeInWorktree(cwd, source, target) {
|
|
8168
|
+
await requireCommitter(cwd);
|
|
8169
|
+
const targetSha = await fetchTarget(cwd, target);
|
|
8170
|
+
const sourceSha = await remotePersonal(cwd, source);
|
|
8171
|
+
if (await sourceAlreadyOnTarget(cwd, sourceSha, targetSha))
|
|
8172
|
+
return { status: "contained", source, target };
|
|
8173
|
+
const temp = fs29.mkdtempSync(path31.join(os8.tmpdir(), "cwm-merge-"));
|
|
8174
|
+
let added = false;
|
|
8175
|
+
try {
|
|
8176
|
+
await git5(cwd, ["worktree", "add", "--detach", temp, targetSha], 6e4);
|
|
8177
|
+
added = true;
|
|
8178
|
+
const merged = await mergeIntoTarget(temp, sourceSha, target);
|
|
8179
|
+
if ("conflict" in merged) return { status: "conflict", source, target, files: merged.conflict };
|
|
8180
|
+
await pushTarget(temp, target);
|
|
8181
|
+
return { status: "merged", source, target, commit: merged.commit };
|
|
8182
|
+
} finally {
|
|
8183
|
+
if (added) await git5(cwd, ["worktree", "remove", "--force", temp]).catch(() => {
|
|
8184
|
+
});
|
|
8185
|
+
fs29.rmSync(temp, { recursive: true, force: true });
|
|
8186
|
+
await git5(cwd, ["worktree", "prune"]).catch(() => {
|
|
8187
|
+
});
|
|
8188
|
+
}
|
|
8189
|
+
}
|
|
8190
|
+
async function mergeMountedBranch(cwd, sourceName, targetName) {
|
|
8191
|
+
const { source, target } = mergeRequest(sourceName, targetName);
|
|
8192
|
+
if (!cwd || !fs29.existsSync(cwd)) throw new Error("\u6302\u8F7D\u8DEF\u5F84\u4E0D\u5B58\u5728");
|
|
8193
|
+
const relative = await git5(cwd, ["rev-parse", "--git-common-dir"]);
|
|
8194
|
+
const common = fs29.realpathSync(path31.resolve(cwd, relative));
|
|
8195
|
+
return withRepoLock(common, () => mergeInWorktree(cwd, source, target));
|
|
8196
|
+
}
|
|
7938
8197
|
|
|
7939
8198
|
// src/query-routes.ts
|
|
7940
8199
|
function registerQueryRoutes(app, store) {
|
|
7941
|
-
const
|
|
8200
|
+
const git6 = (fn) => gitExecution.run({ executable: store.state.git }, fn);
|
|
7942
8201
|
const cachePath = (root, target) => {
|
|
7943
8202
|
let resolved = root;
|
|
7944
8203
|
try {
|
|
7945
|
-
resolved =
|
|
8204
|
+
resolved = fs30.realpathSync(root);
|
|
7946
8205
|
} catch {
|
|
7947
8206
|
}
|
|
7948
|
-
return target.startsWith(
|
|
8207
|
+
return target.startsWith(path32.join(resolved, ".cwm") + path32.sep);
|
|
7949
8208
|
};
|
|
7950
8209
|
app.get("/v1/repositories", async (request) => {
|
|
7951
8210
|
const grant = requestGrant(request);
|
|
7952
8211
|
const prefix = scopeKey(grant.workbenchId, grant.userId, "");
|
|
7953
8212
|
const root = store.state.root;
|
|
7954
|
-
return Object.entries(store.state.repositories).filter(([key]) => key.startsWith(prefix)).map(([key,
|
|
8213
|
+
return Object.entries(store.state.repositories).filter(([key]) => key.startsWith(prefix)).map(([key, path36]) => ({ id: key.slice(prefix.length), path: path36 })).filter((entry) => !cachePath(root, entry.path));
|
|
7955
8214
|
});
|
|
7956
8215
|
app.post("/v1/repositories/inspect", async (request) => {
|
|
7957
8216
|
const body = request.body;
|
|
7958
|
-
const
|
|
7959
|
-
if (!
|
|
8217
|
+
const path36 = body.path;
|
|
8218
|
+
if (!path36 || !(await import("node:path")).default.isAbsolute(path36))
|
|
7960
8219
|
throw new Error("\u8BF7\u9009\u62E9\u7EDD\u5BF9\u8DEF\u5F84");
|
|
7961
|
-
return
|
|
7962
|
-
root: await runGit(
|
|
7963
|
-
remoteUrl: (await runGit(
|
|
8220
|
+
return git6(async () => ({
|
|
8221
|
+
root: await runGit(path36, ["rev-parse", "--show-toplevel"]),
|
|
8222
|
+
remoteUrl: (await runGit(path36, ["remote", "get-url", "origin"]).catch(() => "")).replace(
|
|
7964
8223
|
/(https?:\/\/)[^/@\s]+@/gi,
|
|
7965
8224
|
"$1"
|
|
7966
8225
|
),
|
|
7967
|
-
branches: (await runGit(
|
|
8226
|
+
branches: (await runGit(path36, [
|
|
7968
8227
|
"for-each-ref",
|
|
7969
8228
|
"--format=%(refname:short)",
|
|
7970
8229
|
"refs/heads",
|
|
@@ -7986,9 +8245,9 @@ function registerQueryRoutes(app, store) {
|
|
|
7986
8245
|
const repositoryId = String(item?.repositoryId || "");
|
|
7987
8246
|
const branch = String(item?.branch || "");
|
|
7988
8247
|
if (!repositoryId || !branch) continue;
|
|
7989
|
-
const
|
|
7990
|
-
const changed = await
|
|
7991
|
-
() => branchHasChanges(
|
|
8248
|
+
const path36 = store.state.repositories[scopeKey(grant.workbenchId, grant.userId, repositoryId)];
|
|
8249
|
+
const changed = await git6(
|
|
8250
|
+
() => branchHasChanges(path36 || "", branch, String(item?.compareBranch || ""))
|
|
7992
8251
|
);
|
|
7993
8252
|
if (changed) active.push(repositoryId + "\0" + branch);
|
|
7994
8253
|
}
|
|
@@ -7998,21 +8257,52 @@ function registerQueryRoutes(app, store) {
|
|
|
7998
8257
|
const { id, index } = request.params;
|
|
7999
8258
|
const query = request.query;
|
|
8000
8259
|
if (!/^\d+$/.test(index) || !/^\d+$/.test(query.offset || "0")) throw new Error("\u5206\u9875\u53C2\u6570\u65E0\u6548");
|
|
8260
|
+
const refresh = query.refresh === "true";
|
|
8261
|
+
const offset = Number(query.offset || 0);
|
|
8262
|
+
let folderPath = "";
|
|
8263
|
+
try {
|
|
8264
|
+
const { folders } = localWorkspace(store, requestGrant(request), id);
|
|
8265
|
+
if (folders[Number(index)]?.exists) folderPath = folders[Number(index)].path;
|
|
8266
|
+
} catch (error) {
|
|
8267
|
+
if (error.statusCode !== 404) throw error;
|
|
8268
|
+
}
|
|
8269
|
+
if (folderPath)
|
|
8270
|
+
return git6(
|
|
8271
|
+
() => readWorkspaceCommits(
|
|
8272
|
+
{ folder_path: folderPath, commit_compare_branch: query.compareBranch },
|
|
8273
|
+
offset,
|
|
8274
|
+
refresh
|
|
8275
|
+
)
|
|
8276
|
+
);
|
|
8277
|
+
const remoteUrl = String(query.remoteUrl || "");
|
|
8278
|
+
if (!/^(https?:\/\/|ssh:\/\/|git:\/\/|git@[^:]+:)/.test(remoteUrl))
|
|
8279
|
+
throw Object.assign(new Error("\u865A\u62DF\u4ED3\u5E93\u6CA1\u6709\u53EF\u62C9\u53D6\u7684\u8FDC\u7A0B\u5730\u5740"), { statusCode: 404 });
|
|
8280
|
+
return git6(
|
|
8281
|
+
() => readRemoteBranchCommits(
|
|
8282
|
+
path32.join(store.directory, "commit-cache"),
|
|
8283
|
+
remoteUrl,
|
|
8284
|
+
String(query.branch || ""),
|
|
8285
|
+
query.compareBranch,
|
|
8286
|
+
offset,
|
|
8287
|
+
refresh
|
|
8288
|
+
)
|
|
8289
|
+
);
|
|
8290
|
+
});
|
|
8291
|
+
app.post("/v1/workspaces/:id/repositories/:index/merge", async (request) => {
|
|
8292
|
+
const { id, index } = request.params;
|
|
8293
|
+
const body = request.body;
|
|
8294
|
+
if (!/^\d+$/.test(index)) throw new Error("\u4ED3\u5E93\u5E8F\u53F7\u65E0\u6548");
|
|
8001
8295
|
const { folders } = localWorkspace(store, requestGrant(request), id);
|
|
8002
8296
|
const folder = folders[Number(index)];
|
|
8003
8297
|
if (!folder?.exists) throw Object.assign(new Error("\u6302\u8F7D\u4ED3\u5E93\u4E0D\u5B58\u5728"), { statusCode: 404 });
|
|
8004
|
-
return
|
|
8005
|
-
() =>
|
|
8006
|
-
{ folder_path: folder.path, commit_compare_branch: query.compareBranch },
|
|
8007
|
-
Number(query.offset || 0),
|
|
8008
|
-
query.refresh === "true"
|
|
8009
|
-
)
|
|
8298
|
+
return git6(
|
|
8299
|
+
() => mergeMountedBranch(folder.path, String(body.branch || ""), String(body.target || ""))
|
|
8010
8300
|
);
|
|
8011
8301
|
});
|
|
8012
8302
|
function sessions(request) {
|
|
8013
8303
|
const { id } = request.params;
|
|
8014
8304
|
const local = localWorkspace(store, requestGrant(request), id);
|
|
8015
|
-
return listAgentSessions(
|
|
8305
|
+
return listAgentSessions(os9.homedir(), {
|
|
8016
8306
|
containerDir: local.mount.directory,
|
|
8017
8307
|
workspaceFile: local.file,
|
|
8018
8308
|
mountPaths: local.folders.map((folder) => folder.path)
|
|
@@ -8035,7 +8325,7 @@ function registerQueryRoutes(app, store) {
|
|
|
8035
8325
|
}
|
|
8036
8326
|
|
|
8037
8327
|
// src/review-route.ts
|
|
8038
|
-
import
|
|
8328
|
+
import path33 from "node:path";
|
|
8039
8329
|
function registerReviewRoute(app, store, jobs) {
|
|
8040
8330
|
app.post("/v1/reviews", async (request) => {
|
|
8041
8331
|
const grant = requestGrant(request);
|
|
@@ -8061,7 +8351,7 @@ function registerReviewRoute(app, store, jobs) {
|
|
|
8061
8351
|
},
|
|
8062
8352
|
(log) => auditLocalVersion(
|
|
8063
8353
|
snapshot,
|
|
8064
|
-
|
|
8354
|
+
path33.join(store.directory, "reviews", body.id),
|
|
8065
8355
|
body.id,
|
|
8066
8356
|
body.inputHash,
|
|
8067
8357
|
body,
|
|
@@ -8074,25 +8364,25 @@ function registerReviewRoute(app, store, jobs) {
|
|
|
8074
8364
|
|
|
8075
8365
|
// src/upgrade.ts
|
|
8076
8366
|
import { spawn as spawn8 } from "node:child_process";
|
|
8077
|
-
import
|
|
8078
|
-
import
|
|
8367
|
+
import fs31 from "node:fs";
|
|
8368
|
+
import path34 from "node:path";
|
|
8079
8369
|
function packageRoot(entry) {
|
|
8080
|
-
let directory =
|
|
8370
|
+
let directory = path34.dirname(path34.resolve(entry));
|
|
8081
8371
|
for (let depth = 0; depth < 4; depth++) {
|
|
8082
|
-
if (
|
|
8083
|
-
directory =
|
|
8372
|
+
if (fs31.existsSync(path34.join(directory, "package.json"))) return directory;
|
|
8373
|
+
directory = path34.dirname(directory);
|
|
8084
8374
|
}
|
|
8085
|
-
return
|
|
8375
|
+
return path34.dirname(path34.dirname(path34.resolve(entry)));
|
|
8086
8376
|
}
|
|
8087
8377
|
function isGlobalInstall(root, prefix) {
|
|
8088
8378
|
if (!prefix) return false;
|
|
8089
|
-
const relative =
|
|
8090
|
-
return Boolean(relative) && !relative.startsWith("..") && !
|
|
8379
|
+
const relative = path34.relative(path34.resolve(prefix), path34.resolve(root));
|
|
8380
|
+
return Boolean(relative) && !relative.startsWith("..") && !path34.isAbsolute(relative);
|
|
8091
8381
|
}
|
|
8092
8382
|
function looksGlobal(root) {
|
|
8093
|
-
const modules =
|
|
8094
|
-
if (
|
|
8095
|
-
return !
|
|
8383
|
+
const modules = path34.dirname(path34.resolve(root));
|
|
8384
|
+
if (path34.basename(modules) !== "node_modules") return false;
|
|
8385
|
+
return !fs31.existsSync(path34.join(path34.dirname(modules), "package.json"));
|
|
8096
8386
|
}
|
|
8097
8387
|
function isNewer(candidate, current) {
|
|
8098
8388
|
const parse = (value) => value.split("-")[0].split(".").map((part) => Number(part) || 0);
|
|
@@ -8113,10 +8403,10 @@ async function latestPublished() {
|
|
|
8113
8403
|
if (!data.version) throw new Error("npm \u8FD4\u56DE\u7684\u7248\u672C\u4FE1\u606F\u65E0\u6548");
|
|
8114
8404
|
return data.version;
|
|
8115
8405
|
}
|
|
8116
|
-
var statusFile = (store) =>
|
|
8406
|
+
var statusFile = (store) => path34.join(store.directory, "upgrade.json");
|
|
8117
8407
|
function readStatus(store) {
|
|
8118
8408
|
try {
|
|
8119
|
-
return JSON.parse(
|
|
8409
|
+
return JSON.parse(fs31.readFileSync(statusFile(store), "utf8"));
|
|
8120
8410
|
} catch {
|
|
8121
8411
|
return void 0;
|
|
8122
8412
|
}
|
|
@@ -8160,7 +8450,7 @@ function registerUpgradeRoutes(app, store, entry, options = {}) {
|
|
|
8160
8450
|
return reply.code(502).send({ error: cause.message });
|
|
8161
8451
|
}
|
|
8162
8452
|
if (!isNewer(latest, ASSISTANT_VERSION)) return { latest, started: false };
|
|
8163
|
-
|
|
8453
|
+
fs31.writeFileSync(
|
|
8164
8454
|
statusFile(store),
|
|
8165
8455
|
JSON.stringify({ target: latest, state: "running", startedAt: (/* @__PURE__ */ new Date()).toISOString() }),
|
|
8166
8456
|
{ mode: 384 }
|
|
@@ -8168,7 +8458,7 @@ function registerUpgradeRoutes(app, store, entry, options = {}) {
|
|
|
8168
8458
|
const child = spawn8(
|
|
8169
8459
|
process.execPath,
|
|
8170
8460
|
[
|
|
8171
|
-
|
|
8461
|
+
path34.join(root, "scripts", "upgrade.mjs"),
|
|
8172
8462
|
"--version",
|
|
8173
8463
|
latest,
|
|
8174
8464
|
"--state-dir",
|
|
@@ -8202,7 +8492,7 @@ async function buildAssistant(store, options = {}, entry, upgrade = {}) {
|
|
|
8202
8492
|
return;
|
|
8203
8493
|
}
|
|
8204
8494
|
const origin = request.headers.origin || "";
|
|
8205
|
-
const
|
|
8495
|
+
const path36 = request.url.split("?")[0];
|
|
8206
8496
|
let workbench = store.state.workbenches[origin];
|
|
8207
8497
|
if (!workbench && trustedOrigin(origin)) {
|
|
8208
8498
|
try {
|
|
@@ -8225,7 +8515,7 @@ async function buildAssistant(store, options = {}, entry, upgrade = {}) {
|
|
|
8225
8515
|
reply.header("Access-Control-Allow-Headers", "Authorization, Content-Type, X-CWM-Binding");
|
|
8226
8516
|
return reply.code(204).send();
|
|
8227
8517
|
}
|
|
8228
|
-
if (
|
|
8518
|
+
if (path36 === "/v1/health" || path36 === "/v1/pairings") return;
|
|
8229
8519
|
try {
|
|
8230
8520
|
const token = request.headers.authorization?.replace(/^Bearer /, "") || "";
|
|
8231
8521
|
const grant = verifyGrant(token, workbench.publicKey);
|
|
@@ -8402,7 +8692,7 @@ async function cli(args, entry) {
|
|
|
8402
8692
|
return;
|
|
8403
8693
|
}
|
|
8404
8694
|
const dirIndex = args.indexOf("--state-dir");
|
|
8405
|
-
const directory = dirIndex >= 0 ?
|
|
8695
|
+
const directory = dirIndex >= 0 ? path35.resolve(args[dirIndex + 1]) : defaultStateDirectory();
|
|
8406
8696
|
const command = args[0] || "status";
|
|
8407
8697
|
const store = new StateStore(directory);
|
|
8408
8698
|
const control = async (action) => {
|
|
@@ -8428,7 +8718,7 @@ async function cli(args, entry) {
|
|
|
8428
8718
|
}
|
|
8429
8719
|
if (store.state.autostart) await startAutostart();
|
|
8430
8720
|
else {
|
|
8431
|
-
const log =
|
|
8721
|
+
const log = fs32.openSync(path35.join(directory, "assistant.log"), "a", 384);
|
|
8432
8722
|
const child = spawn9(process.execPath, [entry, "serve", "--state-dir", directory], {
|
|
8433
8723
|
detached: true,
|
|
8434
8724
|
windowsHide: true,
|
|
@@ -8438,7 +8728,7 @@ async function cli(args, entry) {
|
|
|
8438
8728
|
cwd: directory
|
|
8439
8729
|
});
|
|
8440
8730
|
child.unref();
|
|
8441
|
-
|
|
8731
|
+
fs32.closeSync(log);
|
|
8442
8732
|
}
|
|
8443
8733
|
const deadline = Date.now() + 1e4;
|
|
8444
8734
|
while (Date.now() < deadline) {
|
|
@@ -8453,18 +8743,18 @@ async function cli(args, entry) {
|
|
|
8453
8743
|
throw new Error("\u542F\u52A8\u5931\u8D25\uFF0C\u8BF7\u8FD0\u884C cwm-assistant logs \u68C0\u67E5\u7AEF\u53E3\u548C\u8FD0\u884C\u73AF\u5883");
|
|
8454
8744
|
}
|
|
8455
8745
|
if (command === "serve") {
|
|
8456
|
-
const lock =
|
|
8457
|
-
if (
|
|
8458
|
-
const pid = Number(
|
|
8746
|
+
const lock = path35.join(directory, "process.lock");
|
|
8747
|
+
if (fs32.existsSync(lock)) {
|
|
8748
|
+
const pid = Number(fs32.readFileSync(lock, "utf8"));
|
|
8459
8749
|
try {
|
|
8460
8750
|
process.kill(pid, 0);
|
|
8461
8751
|
throw new Error("Workspace \u52A9\u624B\u5DF2\u8FD0\u884C");
|
|
8462
8752
|
} catch (error) {
|
|
8463
8753
|
if (error.code !== "ESRCH") throw error;
|
|
8464
|
-
|
|
8754
|
+
fs32.unlinkSync(lock);
|
|
8465
8755
|
}
|
|
8466
8756
|
}
|
|
8467
|
-
|
|
8757
|
+
fs32.writeFileSync(lock, String(process.pid), { flag: "wx", mode: 384 });
|
|
8468
8758
|
store.reload();
|
|
8469
8759
|
store.recover();
|
|
8470
8760
|
const { app, jobs } = await buildAssistant(store, {}, entry);
|
|
@@ -8488,12 +8778,12 @@ async function cli(args, entry) {
|
|
|
8488
8778
|
return reply.code(400).send({ error: "\u63A7\u5236\u64CD\u4F5C\u65E0\u6548" });
|
|
8489
8779
|
});
|
|
8490
8780
|
app.addHook("onClose", async () => {
|
|
8491
|
-
|
|
8781
|
+
fs32.rmSync(lock, { force: true });
|
|
8492
8782
|
});
|
|
8493
8783
|
try {
|
|
8494
8784
|
await app.listen({ host: "127.0.0.1", port: ASSISTANT_PORT });
|
|
8495
8785
|
} catch (error) {
|
|
8496
|
-
|
|
8786
|
+
fs32.rmSync(lock, { force: true });
|
|
8497
8787
|
throw error;
|
|
8498
8788
|
}
|
|
8499
8789
|
for (const signal of ["SIGTERM", "SIGINT"])
|
|
@@ -8518,7 +8808,7 @@ async function cli(args, entry) {
|
|
|
8518
8808
|
await control("stop").catch(() => {
|
|
8519
8809
|
});
|
|
8520
8810
|
const deadline = Date.now() + 1e4;
|
|
8521
|
-
while (
|
|
8811
|
+
while (fs32.existsSync(path35.join(directory, "process.lock")) && Date.now() < deadline) {
|
|
8522
8812
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
8523
8813
|
}
|
|
8524
8814
|
}
|
|
@@ -8550,9 +8840,9 @@ async function cli(args, entry) {
|
|
|
8550
8840
|
return;
|
|
8551
8841
|
}
|
|
8552
8842
|
if (command === "logs") {
|
|
8553
|
-
const file =
|
|
8843
|
+
const file = path35.join(directory, "assistant.log");
|
|
8554
8844
|
console.log(
|
|
8555
|
-
|
|
8845
|
+
fs32.existsSync(file) ? fs32.readFileSync(file, "utf8").split("\n").slice(-100).join("\n") : "\u6682\u65E0\u65E5\u5FD7"
|
|
8556
8846
|
);
|
|
8557
8847
|
return;
|
|
8558
8848
|
}
|
|
@@ -8567,10 +8857,10 @@ async function cli(args, entry) {
|
|
|
8567
8857
|
await control("stop").catch(() => {
|
|
8568
8858
|
});
|
|
8569
8859
|
const deadline = Date.now() + 1e4;
|
|
8570
|
-
while (
|
|
8860
|
+
while (fs32.existsSync(path35.join(directory, "process.lock")) && Date.now() < deadline) {
|
|
8571
8861
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
8572
8862
|
}
|
|
8573
|
-
if (
|
|
8863
|
+
if (fs32.existsSync(path35.join(directory, "process.lock")))
|
|
8574
8864
|
throw new Error("\u52A9\u624B\u5C1A\u672A\u505C\u6B62\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF1B\u672A\u4FEE\u6539\u672C\u5730\u72B6\u6001");
|
|
8575
8865
|
}
|
|
8576
8866
|
store.reload();
|
|
@@ -8599,17 +8889,17 @@ async function cli(args, entry) {
|
|
|
8599
8889
|
return;
|
|
8600
8890
|
}
|
|
8601
8891
|
if (command === "doctor") {
|
|
8602
|
-
const gitVersion = await gitExecution.run({ executable: store.state.git }, () => runGit(
|
|
8892
|
+
const gitVersion = await gitExecution.run({ executable: store.state.git }, () => runGit(os10.homedir(), ["--version"])).catch((error) => "\u4E0D\u53EF\u7528\uFF1A" + error.message);
|
|
8603
8893
|
console.log(
|
|
8604
8894
|
JSON.stringify(
|
|
8605
8895
|
{
|
|
8606
8896
|
node: process.version,
|
|
8607
8897
|
nodePath: process.execPath,
|
|
8608
|
-
entryExists:
|
|
8898
|
+
entryExists: fs32.existsSync(entry),
|
|
8609
8899
|
git: store.state.git,
|
|
8610
8900
|
gitVersion,
|
|
8611
8901
|
platform: process.platform,
|
|
8612
|
-
rootExists: Boolean(store.state.root &&
|
|
8902
|
+
rootExists: Boolean(store.state.root && fs32.existsSync(store.state.root)),
|
|
8613
8903
|
configuredWorkbenches: Object.keys(store.state.workbenches),
|
|
8614
8904
|
autostart: store.state.autostart,
|
|
8615
8905
|
process: await control("status").catch(() => "\u672A\u8FD0\u884C")
|
|
@@ -8642,7 +8932,7 @@ async function cli(args, entry) {
|
|
|
8642
8932
|
console.log(
|
|
8643
8933
|
await gitExecution.run(
|
|
8644
8934
|
{ executable: store.state.git },
|
|
8645
|
-
() => runGit(
|
|
8935
|
+
() => runGit(os10.homedir(), ["--version"])
|
|
8646
8936
|
)
|
|
8647
8937
|
);
|
|
8648
8938
|
} catch {
|
|
@@ -8650,9 +8940,9 @@ async function cli(args, entry) {
|
|
|
8650
8940
|
}
|
|
8651
8941
|
}
|
|
8652
8942
|
if (rootArg) {
|
|
8653
|
-
if (!
|
|
8943
|
+
if (!path35.isAbsolute(rootArg) || !fs32.statSync(rootArg).isDirectory())
|
|
8654
8944
|
throw new Error("\u5DE5\u4F5C\u76EE\u5F55\u5FC5\u987B\u662F\u5DF2\u5B58\u5728\u7684\u7EDD\u5BF9\u8DEF\u5F84");
|
|
8655
|
-
store.state.root =
|
|
8945
|
+
store.state.root = fs32.realpathSync(rootArg);
|
|
8656
8946
|
}
|
|
8657
8947
|
const auto = wantAutostart || !assumeYes && await ask("\u767B\u5F55\u7535\u8111\u65F6\u81EA\u52A8\u542F\u52A8\uFF1F[Y/n] ") !== "n";
|
|
8658
8948
|
store.save();
|
|
@@ -8682,4 +8972,4 @@ async function cli(args, entry) {
|
|
|
8682
8972
|
export {
|
|
8683
8973
|
cli
|
|
8684
8974
|
};
|
|
8685
|
-
//# sourceMappingURL=cli-
|
|
8975
|
+
//# sourceMappingURL=cli-JKJYCZCV.js.map
|