lemma-agent 0.0.0-stage → 1.0.1
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/README.md +140 -2
- package/bin/lemma.mjs +60 -0
- package/dist/acceptance.js +63 -0
- package/dist/admin.js +1482 -0
- package/dist/agents.js +245 -0
- package/dist/api-member.js +537 -0
- package/dist/app.js +161 -0
- package/dist/board.js +185 -0
- package/dist/business-tools.js +153 -0
- package/dist/change-ops.js +91 -0
- package/dist/changes.js +46 -0
- package/dist/cli-runner.js +106 -0
- package/dist/code-tools.js +396 -0
- package/dist/coding-benchmark-fixtures.js +1049 -0
- package/dist/coding-benchmark-suite.js +1252 -0
- package/dist/collaboration-benchmark.js +349 -0
- package/dist/config.js +392 -0
- package/dist/context-benchmark.js +91 -0
- package/dist/conventions.js +282 -0
- package/dist/conversation.js +39 -0
- package/dist/credentials.js +44 -0
- package/dist/deliverables.js +43 -0
- package/dist/digest.js +129 -0
- package/dist/dispatch.js +801 -0
- package/dist/execution-settings.js +24 -0
- package/dist/git-workbench.js +800 -0
- package/dist/git.js +149 -0
- package/dist/integration-git.js +108 -0
- package/dist/integrations.js +557 -0
- package/dist/jobs.js +100 -0
- package/dist/lead.js +263 -0
- package/dist/learning.js +36 -0
- package/dist/main.js +1459 -0
- package/dist/mcp-settings.js +45 -0
- package/dist/mcp-tools.js +102 -0
- package/dist/member-settings.js +245 -0
- package/dist/model-selection.js +48 -0
- package/dist/models.js +145 -0
- package/dist/native-selectors.js +45 -0
- package/dist/native-terminal-components.js +100 -0
- package/dist/ood-benchmark.js +660 -0
- package/dist/operations.js +21 -0
- package/dist/printer.js +113 -0
- package/dist/projects.js +282 -0
- package/dist/repair.js +102 -0
- package/dist/resources.js +31 -0
- package/dist/result-summary.js +8 -0
- package/dist/results.js +41 -0
- package/dist/scope.js +114 -0
- package/dist/sessions.js +95 -0
- package/dist/settings.js +32 -0
- package/dist/task-commands.js +37 -0
- package/dist/task-lifecycle.js +49 -0
- package/dist/task-readiness.js +22 -0
- package/dist/task-recovery.js +116 -0
- package/dist/task-review.js +70 -0
- package/dist/task-workflow.js +424 -0
- package/dist/terminal-layout.js +27 -0
- package/dist/terminal-state.js +145 -0
- package/dist/terminal.js +800 -0
- package/dist/tool-settings.js +111 -0
- package/dist/tools.js +1043 -0
- package/dist/ux-telemetry.js +127 -0
- package/dist/view.js +114 -0
- package/package.json +80 -6
- package/web/index.html +136 -0
- package/web/js/conversations.js +312 -0
- package/web/js/dag.js +495 -0
- package/web/js/drawer.js +139 -0
- package/web/js/editors.js +424 -0
- package/web/js/gitlens.js +844 -0
- package/web/js/main.js +152 -0
- package/web/js/sankey.js +476 -0
- package/web/js/store.js +291 -0
- package/web/js/ticket.js +151 -0
- package/web/js/timeline.js +183 -0
- package/web/js/topology.js +454 -0
- package/web/js/util.js +232 -0
- package/web/js/views.js +1496 -0
- package/web/style.css +5299 -0
|
@@ -0,0 +1,844 @@
|
|
|
1
|
+
// GitLens 风格「改动与推送管理」工作台:
|
|
2
|
+
// 多仓库切换 + 远端同步/Commit/Push 工具栏 + 多泳道 Git Commit Graph(融合 Agent worktree & 联合集成)+ 文件树与 Diff 检视器 + 关键风险人工确认网关。
|
|
3
|
+
import { openDispatch } from "./drawer.js";
|
|
4
|
+
import { openRepairIntegrationDialog, runControlAction } from "./editors.js";
|
|
5
|
+
import { store } from "./store.js";
|
|
6
|
+
import { AGENT_LABEL, agentColor, ago, copy, esc, getJson, post, short, stamp, toast } from "./util.js";
|
|
7
|
+
|
|
8
|
+
const LANE_COLORS = [
|
|
9
|
+
"var(--run)",
|
|
10
|
+
"var(--claude)",
|
|
11
|
+
"var(--codex)",
|
|
12
|
+
"var(--gemini)",
|
|
13
|
+
"var(--deepseek)",
|
|
14
|
+
"var(--lead)",
|
|
15
|
+
"var(--ok)",
|
|
16
|
+
];
|
|
17
|
+
const CHANGE_LABEL = { running: "进行中", pending: "待合并", conflict: "有冲突", applied: "已合并", empty: "无改动", dropped: "已丢弃" };
|
|
18
|
+
const CHANGE_PILL = { running: "running", pending: "pending", conflict: "error", applied: "done", empty: "aborted", dropped: "aborted" };
|
|
19
|
+
const GATE_ACTION_LABEL = { commit: "提交确认", push: "推送确认", force_push: "风险强推 / 分叉", pull: "分叉拉取" };
|
|
20
|
+
|
|
21
|
+
/** 统一差异 → 带行号的着色视图(先转义,不信任内容) */
|
|
22
|
+
export function renderDiff(text) {
|
|
23
|
+
if (!text.trim()) return `<div class="empty-inline"><span class="dot"></span>没有差异</div>`;
|
|
24
|
+
const out = [];
|
|
25
|
+
let oldNo = 0;
|
|
26
|
+
let newNo = 0;
|
|
27
|
+
for (const line of text.split("\n")) {
|
|
28
|
+
if (line.startsWith("diff --git")) {
|
|
29
|
+
const file = line.replace(/^diff --git a\/(.+?) b\/.+$/, "$1");
|
|
30
|
+
out.push(`<div class="df-file">${esc(file)}</div>`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (/^(index |--- |\+\+\+ |new file mode|deleted file mode|similarity|rename )/.test(line)) continue;
|
|
34
|
+
const hunk = line.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)$/);
|
|
35
|
+
if (hunk) {
|
|
36
|
+
oldNo = Number(hunk[1]);
|
|
37
|
+
newNo = Number(hunk[2]);
|
|
38
|
+
out.push(`<div class="df-hunk"><span></span><span></span><code>${esc(line)}</code></div>`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (line.startsWith("+")) out.push(`<div class="df-line add"><span></span><span>${newNo++}</span><code>${esc(line)}</code></div>`);
|
|
42
|
+
else if (line.startsWith("-")) out.push(`<div class="df-line del"><span>${oldNo++}</span><span></span><code>${esc(line)}</code></div>`);
|
|
43
|
+
else if (line.startsWith("\\")) out.push(`<div class="df-line meta"><span></span><span></span><code>${esc(line)}</code></div>`);
|
|
44
|
+
else if (line.length || oldNo) out.push(`<div class="df-line"><span>${oldNo++}</span><span>${newNo++}</span><code>${esc(line || " ")}</code></div>`);
|
|
45
|
+
}
|
|
46
|
+
return `<div class="diff">${out.join("")}</div>`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 计算每条 Commit / WORKTREE 行的 GitLens 地铁轨道布局 */
|
|
50
|
+
export function computeCommitLanes(rows) {
|
|
51
|
+
let active = []; // sha[] | null[]
|
|
52
|
+
let colorOf = new Map();
|
|
53
|
+
let nextColor = 0;
|
|
54
|
+
const pickColor = (sha, preferAgent) => {
|
|
55
|
+
if (preferAgent) return agentColor(preferAgent);
|
|
56
|
+
if (colorOf.has(sha)) return colorOf.get(sha);
|
|
57
|
+
const c = LANE_COLORS[nextColor++ % LANE_COLORS.length];
|
|
58
|
+
colorOf.set(sha, c);
|
|
59
|
+
return c;
|
|
60
|
+
};
|
|
61
|
+
const laidOut = [];
|
|
62
|
+
let maxLanes = 1;
|
|
63
|
+
for (const row of rows) {
|
|
64
|
+
const id = row.sha;
|
|
65
|
+
const inLanes = [...active];
|
|
66
|
+
let lane = active.indexOf(id);
|
|
67
|
+
const hadIncoming = lane !== -1;
|
|
68
|
+
if (lane === -1) {
|
|
69
|
+
lane = active.indexOf(null);
|
|
70
|
+
if (lane === -1) lane = active.length;
|
|
71
|
+
}
|
|
72
|
+
const nodeAgent = row.changes?.[0]?.agent;
|
|
73
|
+
const color = row.isWorktree ? "var(--signal)" : pickColor(id, nodeAgent);
|
|
74
|
+
colorOf.set(id, color);
|
|
75
|
+
|
|
76
|
+
const next = [...active];
|
|
77
|
+
if (!hadIncoming && lane >= next.length) next.length = lane + 1;
|
|
78
|
+
const parents = row.parents ?? [];
|
|
79
|
+
const outgoing = []; // { targetLane, color, merge }
|
|
80
|
+
if (parents.length > 0) {
|
|
81
|
+
const p0 = parents[0];
|
|
82
|
+
const existing0 = next.indexOf(p0);
|
|
83
|
+
if (existing0 !== -1 && existing0 !== lane) {
|
|
84
|
+
next[lane] = null;
|
|
85
|
+
outgoing.push({ targetLane: existing0, color, merge: true });
|
|
86
|
+
} else {
|
|
87
|
+
next[lane] = p0;
|
|
88
|
+
if (!colorOf.has(p0)) colorOf.set(p0, row.isWorktree ? LANE_COLORS[0] : color);
|
|
89
|
+
outgoing.push({ targetLane: lane, color: colorOf.get(p0) ?? color, merge: false });
|
|
90
|
+
}
|
|
91
|
+
for (const p of parents.slice(1)) {
|
|
92
|
+
let pLane = next.indexOf(p);
|
|
93
|
+
if (pLane === -1) {
|
|
94
|
+
pLane = next.indexOf(null);
|
|
95
|
+
if (pLane === -1) { pLane = next.length; next.push(p); }
|
|
96
|
+
else next[pLane] = p;
|
|
97
|
+
}
|
|
98
|
+
const pColor = pickColor(p, null);
|
|
99
|
+
outgoing.push({ targetLane: pLane, color: pColor, merge: true });
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
next[lane] = null;
|
|
103
|
+
}
|
|
104
|
+
while (next.length && next[next.length - 1] === null) next.pop();
|
|
105
|
+
|
|
106
|
+
const passThrough = [];
|
|
107
|
+
for (let i = 0; i < Math.max(inLanes.length, next.length); i++) {
|
|
108
|
+
if (i === lane) continue;
|
|
109
|
+
const shaTop = inLanes[i];
|
|
110
|
+
const shaBot = next[i];
|
|
111
|
+
if (shaTop && shaBot && shaTop === shaBot) {
|
|
112
|
+
passThrough.push({ lane: i, color: colorOf.get(shaTop) ?? LANE_COLORS[i % LANE_COLORS.length] });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
maxLanes = Math.max(maxLanes, inLanes.length, next.length, lane + 1);
|
|
116
|
+
laidOut.push({ row, lane, color, hadIncoming, passThrough, outgoing });
|
|
117
|
+
active = next;
|
|
118
|
+
}
|
|
119
|
+
return { rows: laidOut, maxLanes: Math.min(8, maxLanes) };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function renderLaneSvg(item, maxLanes) {
|
|
123
|
+
const W = Math.max(28, maxLanes * 15 + 10);
|
|
124
|
+
const H = 44;
|
|
125
|
+
const midY = 22;
|
|
126
|
+
const lx = (i) => 11 + i * 15;
|
|
127
|
+
const parts = [];
|
|
128
|
+
for (const pt of item.passThrough) {
|
|
129
|
+
if (pt.lane >= maxLanes) continue;
|
|
130
|
+
const x = lx(pt.lane);
|
|
131
|
+
parts.push(`<line x1="${x}" y1="0" x2="${x}" y2="${H}" stroke="${pt.color}" stroke-width="1.8" stroke-opacity="0.72"/>`);
|
|
132
|
+
}
|
|
133
|
+
const cx = lx(Math.min(item.lane, maxLanes - 1));
|
|
134
|
+
if (item.hadIncoming) {
|
|
135
|
+
parts.push(`<line x1="${cx}" y1="0" x2="${cx}" y2="${midY}" stroke="${item.color}" stroke-width="2" stroke-opacity="0.9"/>`);
|
|
136
|
+
}
|
|
137
|
+
for (const out of item.outgoing) {
|
|
138
|
+
const tx = lx(Math.min(out.targetLane, maxLanes - 1));
|
|
139
|
+
if (tx === cx) {
|
|
140
|
+
parts.push(`<line x1="${cx}" y1="${midY}" x2="${tx}" y2="${H}" stroke="${out.color}" stroke-width="2" stroke-opacity="0.88"${item.row.isWorktree ? ' stroke-dasharray="3 2.5"' : ""}/>`);
|
|
141
|
+
} else {
|
|
142
|
+
parts.push(`<path d="M${cx},${midY} C${cx},${midY + 12} ${tx},${midY + 10} ${tx},${H}" fill="none" stroke="${out.color}" stroke-width="1.85" stroke-opacity="0.82"/>`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (item.row.isWorktree) {
|
|
146
|
+
parts.push(`<circle cx="${cx}" cy="${midY}" r="5" fill="var(--panel)" stroke="var(--signal)" stroke-width="2" stroke-dasharray="2.5 2"/>`);
|
|
147
|
+
} else if (item.row.isHead) {
|
|
148
|
+
parts.push(`<circle cx="${cx}" cy="${midY}" r="7.5" fill="none" stroke="${item.color}" stroke-width="1.4" stroke-opacity="0.5"/>`);
|
|
149
|
+
parts.push(`<circle cx="${cx}" cy="${midY}" r="4.5" fill="${item.color}" stroke="var(--panel)" stroke-width="1.5"/>`);
|
|
150
|
+
} else if (item.row.changes?.length) {
|
|
151
|
+
parts.push(`<rect x="${cx - 4.5}" y="${midY - 4.5}" width="9" height="9" rx="3" transform="rotate(45 ${cx} ${midY})" fill="${item.color}" stroke="var(--panel)" stroke-width="1.2"/>`);
|
|
152
|
+
} else {
|
|
153
|
+
parts.push(`<circle cx="${cx}" cy="${midY}" r="3.8" fill="${item.color}" stroke="var(--panel)" stroke-width="1.3"/>`);
|
|
154
|
+
}
|
|
155
|
+
return `<svg class="gl-rail-svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" aria-hidden="true">${parts.join("")}</svg>`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function diffBlocksHtml(add = 0, del = 0) {
|
|
159
|
+
const total = add + del;
|
|
160
|
+
if (!total) return `<span class="gl-diffbars muted">—</span>`;
|
|
161
|
+
const blocks = 5;
|
|
162
|
+
const addCount = Math.min(blocks, Math.max(add > 0 ? 1 : 0, Math.round((add / total) * blocks)));
|
|
163
|
+
const delCount = Math.min(blocks - addCount, del > 0 ? Math.max(1, blocks - addCount) : 0);
|
|
164
|
+
const rects = [];
|
|
165
|
+
for (let i = 0; i < addCount; i++) rects.push('<i class="a"></i>');
|
|
166
|
+
for (let i = 0; i < delCount; i++) rects.push('<i class="d"></i>');
|
|
167
|
+
while (rects.length < blocks) rects.push('<i class="e"></i>');
|
|
168
|
+
return `<span class="gl-diffstats"><span class="gl-diffbars" title="+${add} / −${del}">${rects.join("")}</span><span class="mono ok-t">+${add}</span><span class="mono err-t">−${del}</span></span>`;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function renderRefs(row) {
|
|
172
|
+
const pills = [];
|
|
173
|
+
if (row.isWorktree) pills.push(`<span class="gl-ref worktree">工作区未提交</span>`);
|
|
174
|
+
if (row.isHead) pills.push(`<span class="gl-ref head">HEAD</span>`);
|
|
175
|
+
for (const ref of row.refs ?? []) {
|
|
176
|
+
if (ref === "HEAD") continue;
|
|
177
|
+
const clean = ref.replace(/^HEAD -> /, "");
|
|
178
|
+
const isOrigin = clean.includes("/");
|
|
179
|
+
pills.push(`<span class="gl-ref ${isOrigin ? "remote" : "branch"}">${esc(clean)}</span>`);
|
|
180
|
+
}
|
|
181
|
+
if (row.unpushed && !row.isWorktree) pills.push(`<span class="gl-ref unpushed" title="本地领先远端尚未推送">↑ 未推送</span>`);
|
|
182
|
+
for (const ch of row.changes ?? []) {
|
|
183
|
+
const who = AGENT_LABEL[ch.agent] ?? ch.agent;
|
|
184
|
+
pills.push(`<span class="gl-ref change s-${esc(ch.status)}" style="--c:${agentColor(ch.agent)}" title="${esc(ch.branch)}">#${esc(ch.id)} ${esc(who)}·${esc(CHANGE_LABEL[ch.status] ?? ch.status)}</span>`);
|
|
185
|
+
}
|
|
186
|
+
return pills.join("");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function createChangesView() {
|
|
190
|
+
let root;
|
|
191
|
+
let repos = [];
|
|
192
|
+
let activeRepo = null;
|
|
193
|
+
let graphData = null;
|
|
194
|
+
let workbench = { requireHumanPush: false, gates: [] };
|
|
195
|
+
let selectedTarget = null; // "WORKTREE" | commit sha | change id
|
|
196
|
+
let selectedFile = null;
|
|
197
|
+
let graphFilter = "all"; // all | unpushed | changes
|
|
198
|
+
let search = "";
|
|
199
|
+
let commitMessageDraft = "";
|
|
200
|
+
let selectedFilesForCommit = null; // Set<string> | null
|
|
201
|
+
let detailData = null;
|
|
202
|
+
let loadingDetail = false;
|
|
203
|
+
let divergedPrompt = null; // { branch, remote, ahead, behind, error } | null
|
|
204
|
+
let lastGateSig = "";
|
|
205
|
+
|
|
206
|
+
function renderGraphRowsHtml(laneRows, maxLanes, emptyMsg) {
|
|
207
|
+
return laneRows.length
|
|
208
|
+
? laneRows
|
|
209
|
+
.map((item) => {
|
|
210
|
+
const r = item.row;
|
|
211
|
+
const active = selectedTarget === r.sha;
|
|
212
|
+
return `<div class="gl-row${active ? " active" : ""}${r.isWorktree ? " worktree" : ""}${r.unpushed ? " unpushed" : ""}" data-select-node="${esc(r.sha)}">
|
|
213
|
+
<div class="gl-cell-rail">${renderLaneSvg(item, maxLanes)}</div>
|
|
214
|
+
<div class="gl-cell-main">
|
|
215
|
+
<div class="gl-cell-top">${renderRefs(r)}<span class="gl-subj">${esc(short(r.subject || "(无标题)", 90))}</span></div>
|
|
216
|
+
<div class="gl-cell-sub"><span class="mono">${esc(r.shortSha)}</span><span>${esc(r.author)}</span><span>${r.isWorktree ? "刚刚" : ago(r.at)}</span></div>
|
|
217
|
+
</div>
|
|
218
|
+
<div class="gl-cell-diff">${diffBlocksHtml(r.add, r.del)}</div>
|
|
219
|
+
</div>`;
|
|
220
|
+
})
|
|
221
|
+
.join("")
|
|
222
|
+
: `<div class="empty-inline"><span class="dot"></span>${esc(emptyMsg)}</div>`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function refreshAll(preferredChangeId) {
|
|
226
|
+
try {
|
|
227
|
+
const listRes = await getJson("/api/git/repos");
|
|
228
|
+
repos = listRes.repos ?? [];
|
|
229
|
+
workbench = listRes.workbench ?? { requireHumanPush: false, gates: [] };
|
|
230
|
+
if (preferredChangeId) {
|
|
231
|
+
const ch = store.changes.find((c) => c.id === preferredChangeId);
|
|
232
|
+
if (ch?.root && repos.some((r) => r.root.toLowerCase() === ch.root.toLowerCase())) {
|
|
233
|
+
activeRepo = ch.root;
|
|
234
|
+
selectedTarget = ch.head || `change:${ch.id}`;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (!activeRepo || !repos.some((r) => r.root.toLowerCase() === activeRepo.toLowerCase())) {
|
|
238
|
+
activeRepo = repos[0]?.root ?? null;
|
|
239
|
+
}
|
|
240
|
+
if (!activeRepo) {
|
|
241
|
+
render();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
await loadGraph();
|
|
245
|
+
} catch (err) {
|
|
246
|
+
toast(err.message);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async function loadGraph() {
|
|
251
|
+
if (!activeRepo) return;
|
|
252
|
+
const g = await getJson(`/api/git/graph?repo=${encodeURIComponent(activeRepo)}&limit=65`);
|
|
253
|
+
graphData = g;
|
|
254
|
+
workbench = g.workbench ?? workbench;
|
|
255
|
+
const working = g.working ?? [];
|
|
256
|
+
if (selectedTarget === "WORKTREE" && !working.length) selectedTarget = g.commits?.[0]?.sha ?? null;
|
|
257
|
+
if (!selectedTarget) {
|
|
258
|
+
selectedTarget = working.length ? "WORKTREE" : g.commits?.[0]?.sha ?? (g.repoChanges?.[0] ? `change:${g.repoChanges[0].id}` : null);
|
|
259
|
+
}
|
|
260
|
+
if (working.length && selectedFilesForCommit === null) {
|
|
261
|
+
selectedFilesForCommit = new Set(working.filter((w) => !w.conflict).map((w) => w.path));
|
|
262
|
+
} else if (!working.length) {
|
|
263
|
+
selectedFilesForCommit = null;
|
|
264
|
+
}
|
|
265
|
+
render();
|
|
266
|
+
await loadDetail();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async function loadDetail() {
|
|
270
|
+
if (!selectedTarget || !activeRepo) {
|
|
271
|
+
detailData = null;
|
|
272
|
+
renderInspector();
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (selectedTarget.startsWith("change:")) {
|
|
276
|
+
const cid = selectedTarget.slice(7);
|
|
277
|
+
const ch = graphData?.repoChanges?.find((x) => x.id === cid) ?? store.changes.find((x) => x.id === cid);
|
|
278
|
+
if (!ch) { detailData = null; renderInspector(); return; }
|
|
279
|
+
loadingDetail = true;
|
|
280
|
+
renderInspector();
|
|
281
|
+
try {
|
|
282
|
+
const diff = ch.files?.length ? await getJson(`/api/changes/${encodeURIComponent(ch.id)}/diff`) : { text: "", truncated: false };
|
|
283
|
+
detailData = { kind: "change", change: ch, files: ch.files ?? [], diff: diff.text ?? "", truncated: !!diff.truncated, error: diff.error };
|
|
284
|
+
} catch (err) {
|
|
285
|
+
detailData = { kind: "change", change: ch, files: ch.files ?? [], diff: "", error: err.message };
|
|
286
|
+
} finally {
|
|
287
|
+
loadingDetail = false;
|
|
288
|
+
renderInspector();
|
|
289
|
+
}
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
loadingDetail = true;
|
|
293
|
+
renderInspector();
|
|
294
|
+
try {
|
|
295
|
+
const fileQs = selectedFile ? `&file=${encodeURIComponent(selectedFile)}` : "";
|
|
296
|
+
const data = await getJson(`/api/git/commit?repo=${encodeURIComponent(activeRepo)}&sha=${encodeURIComponent(selectedTarget)}${fileQs}`);
|
|
297
|
+
detailData = { kind: "commit", ...data };
|
|
298
|
+
} catch (err) {
|
|
299
|
+
detailData = { kind: "error", error: err.message };
|
|
300
|
+
} finally {
|
|
301
|
+
loadingDetail = false;
|
|
302
|
+
renderInspector();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function buildGraphRows() {
|
|
307
|
+
if (!graphData) return [];
|
|
308
|
+
const rows = [];
|
|
309
|
+
if (graphData.working?.length) {
|
|
310
|
+
rows.push({
|
|
311
|
+
sha: "WORKTREE",
|
|
312
|
+
shortSha: "WORK",
|
|
313
|
+
isWorktree: true,
|
|
314
|
+
parents: graphData.repo?.head ? [graphData.repo.head] : [],
|
|
315
|
+
refs: [],
|
|
316
|
+
author: "工作区",
|
|
317
|
+
at: Date.now(),
|
|
318
|
+
subject: `${graphData.working.length} 个未提交文件${graphData.repo?.conflictCount ? `(含 ${graphData.repo.conflictCount} 处冲突)` : ""}`,
|
|
319
|
+
filesCount: graphData.working.length,
|
|
320
|
+
add: 0,
|
|
321
|
+
del: 0,
|
|
322
|
+
unpushed: false,
|
|
323
|
+
changes: [],
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
for (const c of graphData.commits ?? []) rows.push(c);
|
|
327
|
+
// 补充尚不在 log --all 中的孤立改动(如极旧提交或空改动)
|
|
328
|
+
const seenHeads = new Set(rows.map((r) => r.sha));
|
|
329
|
+
for (const ch of graphData.repoChanges ?? []) {
|
|
330
|
+
if (ch.status === "dropped") continue;
|
|
331
|
+
if (ch.head && seenHeads.has(ch.head)) continue;
|
|
332
|
+
rows.push({
|
|
333
|
+
sha: `change:${ch.id}`,
|
|
334
|
+
shortSha: ch.id,
|
|
335
|
+
parents: ch.base && seenHeads.has(ch.base) ? [ch.base] : [],
|
|
336
|
+
refs: [ch.branch],
|
|
337
|
+
author: AGENT_LABEL[ch.agent] ?? ch.agent,
|
|
338
|
+
at: ch.updatedAt,
|
|
339
|
+
subject: ch.task,
|
|
340
|
+
filesCount: ch.files.length,
|
|
341
|
+
add: ch.add,
|
|
342
|
+
del: ch.del,
|
|
343
|
+
isHead: false,
|
|
344
|
+
isUpstream: false,
|
|
345
|
+
unpushed: false,
|
|
346
|
+
changes: [{
|
|
347
|
+
id: ch.id, agent: ch.agent, model: ch.model, status: ch.status, branch: ch.branch,
|
|
348
|
+
base: ch.base, head: ch.head, task: ch.task, filesCount: ch.files.length, add: ch.add, del: ch.del,
|
|
349
|
+
basedOn: ch.basedOn, integrationStatus: ch.integration?.status,
|
|
350
|
+
}],
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
let filtered = rows;
|
|
354
|
+
if (graphFilter === "unpushed") filtered = rows.filter((r) => r.unpushed || r.isWorktree || r.changes?.some((c) => c.status === "pending"));
|
|
355
|
+
else if (graphFilter === "changes") filtered = rows.filter((r) => r.changes?.length > 0 || r.isWorktree);
|
|
356
|
+
const q = search.trim().toLowerCase();
|
|
357
|
+
if (q) {
|
|
358
|
+
filtered = filtered.filter((r) =>
|
|
359
|
+
r.subject?.toLowerCase().includes(q) ||
|
|
360
|
+
r.sha.toLowerCase().includes(q) ||
|
|
361
|
+
r.author?.toLowerCase().includes(q) ||
|
|
362
|
+
(r.refs ?? []).some((x) => x.toLowerCase().includes(q)) ||
|
|
363
|
+
(r.changes ?? []).some((c) => c.id.toLowerCase().includes(q) || c.branch.toLowerCase().includes(q)),
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
return filtered;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function render() {
|
|
370
|
+
if (!root) return;
|
|
371
|
+
const repo = graphData?.repo;
|
|
372
|
+
const pendingGates = (workbench.gates ?? []).filter((g) => g.status === "pending");
|
|
373
|
+
const rows = buildGraphRows();
|
|
374
|
+
const { rows: laneRows, maxLanes } = computeCommitLanes(rows);
|
|
375
|
+
|
|
376
|
+
root.innerHTML = `
|
|
377
|
+
<div class="gl-workbench">
|
|
378
|
+
<section class="card gl-topbar">
|
|
379
|
+
<div class="gl-repo-row">
|
|
380
|
+
<div class="gl-repos" data-n="repos">
|
|
381
|
+
${repos.map((r) => `<button type="button" class="gl-repo-tab${repo && r.root.toLowerCase() === repo.root.toLowerCase() ? " on" : ""}" data-select-repo="${esc(r.root)}" title="${esc(r.root)}">
|
|
382
|
+
<span class="gl-repo-name">${r.isMain ? "📦" : "📁"} ${esc(r.name)}</span>
|
|
383
|
+
${r.branch ? `<span class="gl-mini-branch mono">${esc(r.branch)}</span>` : ""}
|
|
384
|
+
${r.ahead > 0 ? `<span class="gl-badge sky">↑${r.ahead}</span>` : ""}
|
|
385
|
+
${r.behind > 0 ? `<span class="gl-badge warn">↓${r.behind}</span>` : ""}
|
|
386
|
+
${r.changeCounts?.pending ? `<span class="gl-badge mint">待合 ${r.changeCounts.pending}</span>` : ""}
|
|
387
|
+
</button>`).join("")}
|
|
388
|
+
</div>
|
|
389
|
+
<div class="gl-top-controls">
|
|
390
|
+
<button type="button" class="ghost-btn tiny gl-policy-btn${workbench.requireHumanPush ? " strict" : ""}" data-toggle-policy="1" title="切换 Agent 是否允许自主推送无分叉快进更新">
|
|
391
|
+
${workbench.requireHumanPush ? "🔒 推送前需我确认" : "🤖 Agent 可推干净快进(分叉/冲突交人工)"}
|
|
392
|
+
</button>
|
|
393
|
+
<button type="button" class="ghost-btn tiny" data-clean-changes="1" title="清理已合并或空改动的 worktree">清理 worktree</button>
|
|
394
|
+
</div>
|
|
395
|
+
</div>
|
|
396
|
+
${repo ? `
|
|
397
|
+
<div class="gl-sync-bar">
|
|
398
|
+
<div class="gl-branch-status">
|
|
399
|
+
<span class="gl-branch-pill mono">⎇ ${esc(repo.branch ?? "未初始化")}</span>
|
|
400
|
+
${repo.upstream ? `<span class="muted">→</span><span class="gl-up-pill mono">${esc(repo.upstream)}</span>` : repo.remote ? `<span class="gl-up-pill muted">未关联远端跟踪(${esc(repo.remote)})</span>` : `<span class="gl-up-pill muted">无远端仓库</span>`}
|
|
401
|
+
${!repo.isGit ? `<span class="gl-badge warn">未执行 git init</span>` : repo.ahead === 0 && repo.behind === 0 && repo.upstream ? `<span class="gl-badge ok">✓ 已与远端同步</span>` : ""}
|
|
402
|
+
${repo.ahead > 0 ? `<span class="gl-badge sky">↑ ${repo.ahead} 个提交待推送</span>` : ""}
|
|
403
|
+
${repo.behind > 0 ? `<span class="gl-badge warn">↓ 远端领先 ${repo.behind} 个提交</span>` : ""}
|
|
404
|
+
${repo.dirtyCount > 0 ? `<span class="gl-badge amber">工作区 ${repo.dirtyCount} 处未提交</span>` : ""}
|
|
405
|
+
</div>
|
|
406
|
+
<div class="gl-sync-btns">
|
|
407
|
+
<button type="button" class="ghost-btn tiny" data-git-fetch="1" ${!repo.isGit || !repo.remotes.length ? "disabled" : ""}>Fetch</button>
|
|
408
|
+
<button type="button" class="${repo.behind > 0 ? "primary-btn" : "ghost-btn"} tiny" data-git-pull="1" ${!repo.isGit || !repo.remotes.length ? "disabled" : ""}>Pull${repo.behind > 0 ? ` ↓${repo.behind}` : ""}</button>
|
|
409
|
+
<button type="button" class="ghost-btn tiny" data-focus-worktree="1" ${!repo.dirtyCount ? "disabled" : ""}>Commit${repo.dirtyCount ? ` (${repo.dirtyCount})` : ""}</button>
|
|
410
|
+
<button type="button" class="primary-btn tiny gl-push-btn" data-git-push="1" ${!repo.isGit || !repo.remotes.length ? "disabled" : ""}>Push${repo.ahead > 0 ? ` ↑${repo.ahead}` : ""}</button>
|
|
411
|
+
</div>
|
|
412
|
+
</div>
|
|
413
|
+
` : ""}
|
|
414
|
+
${divergedPrompt ? `
|
|
415
|
+
<div class="gl-diverge-alert">
|
|
416
|
+
<div><strong>⚠ 分叉提示(${esc(divergedPrompt.remote)}/${esc(divergedPrompt.branch)})</strong><p>${esc(divergedPrompt.error)}</p></div>
|
|
417
|
+
<div class="row-actions">
|
|
418
|
+
<button type="button" class="primary-btn tiny" data-diverge-pull="1">先拉取快进 (Pull --ff-only)</button>
|
|
419
|
+
<button type="button" class="danger-btn tiny" data-diverge-force="1">确认强推 (--force-with-lease)</button>
|
|
420
|
+
<button type="button" class="ghost-btn tiny" data-diverge-dismiss="1">取消</button>
|
|
421
|
+
</div>
|
|
422
|
+
</div>` : ""}
|
|
423
|
+
</section>
|
|
424
|
+
|
|
425
|
+
${pendingGates.length ? `
|
|
426
|
+
<section class="gl-gates">
|
|
427
|
+
${pendingGates.map((g) => `
|
|
428
|
+
<div class="card gl-gate-card">
|
|
429
|
+
<div class="gl-gate-main">
|
|
430
|
+
<span class="pill" data-s="error">${esc(GATE_ACTION_LABEL[g.action] ?? g.action)}</span>
|
|
431
|
+
<strong class="mono">${esc(g.repo.split(/[\\/]/).pop() || g.repo)} · ${esc(g.branch)}</strong>
|
|
432
|
+
<span>${esc(g.reason)}</span>
|
|
433
|
+
${g.message ? `<code class="gl-gate-msg">${esc(short(g.message, 80))}</code>` : ""}
|
|
434
|
+
${g.details?.length ? `<span class="muted mono">${esc(g.details.join(" · "))}</span>` : ""}
|
|
435
|
+
</div>
|
|
436
|
+
<div class="row-actions">
|
|
437
|
+
<button type="button" class="primary-btn tiny" data-gate-approve="${esc(g.id)}">批准并执行</button>
|
|
438
|
+
<button type="button" class="ghost-btn tiny" data-gate-reject="${esc(g.id)}">驳回</button>
|
|
439
|
+
</div>
|
|
440
|
+
</div>
|
|
441
|
+
`).join("")}
|
|
442
|
+
</section>` : ""}
|
|
443
|
+
|
|
444
|
+
<div class="gl-split">
|
|
445
|
+
<section class="card gl-graph-card">
|
|
446
|
+
<header class="card-head gl-graph-head">
|
|
447
|
+
<div class="seg" data-n="graphFilter">
|
|
448
|
+
<button type="button" data-k="all" class="${graphFilter === "all" ? "on" : ""}">全部图谱</button>
|
|
449
|
+
<button type="button" data-k="unpushed" class="${graphFilter === "unpushed" ? "on" : ""}">未推送 ↑</button>
|
|
450
|
+
<button type="button" data-k="changes" class="${graphFilter === "changes" ? "on" : ""}">Agent 分支</button>
|
|
451
|
+
</div>
|
|
452
|
+
<input class="gl-search" type="search" placeholder="筛选提交、分支、作者或 #改动编号…" value="${esc(search)}" data-n="search" />
|
|
453
|
+
</header>
|
|
454
|
+
<div class="gl-graph-scroll" data-n="graphList">
|
|
455
|
+
${renderGraphRowsHtml(laneRows, maxLanes, repo && !repo.isGit ? "当前目录尚未初始化 Git 仓库。" : "没有匹配的提交或改动记录。")}
|
|
456
|
+
</div>
|
|
457
|
+
</section>
|
|
458
|
+
|
|
459
|
+
<section class="card gl-inspector" data-n="inspector"></section>
|
|
460
|
+
</div>
|
|
461
|
+
</div>`;
|
|
462
|
+
renderInspector();
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function renderInspector() {
|
|
466
|
+
const box = root?.querySelector('[data-n="inspector"]');
|
|
467
|
+
if (!box) return;
|
|
468
|
+
if (!selectedTarget) {
|
|
469
|
+
box.innerHTML = `<div class="card-body"><div class="empty-inline"><span class="dot"></span>在左侧 GitLens 提交图谱中选择任意提交、工作区或成员改动查看详尽差异与推送操作。</div></div>`;
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (loadingDetail && !detailData) {
|
|
473
|
+
box.innerHTML = `<div class="card-body"><div class="empty-inline"><span class="dot"></span>加载差异详情中…</div></div>`;
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (!detailData || detailData.kind === "error") {
|
|
477
|
+
box.innerHTML = `<div class="card-body"><div class="change-msg err">${esc(detailData?.error ?? "无法读取详情")}</div></div>`;
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (detailData.kind === "change") {
|
|
482
|
+
const c = detailData.change;
|
|
483
|
+
const actionable = (c.status === "pending" || c.status === "conflict") && !c.integration?.supersededBy && (!c.integration || c.integration.status === "passed");
|
|
484
|
+
const dispatch = store.dispatches.find((d) => d.changeId === c.id);
|
|
485
|
+
box.innerHTML = renderChangeInspector(c, actionable, dispatch, detailData);
|
|
486
|
+
bindInspectorEvents(box, c);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// Commit / WORKTREE Inspector
|
|
491
|
+
const d = detailData;
|
|
492
|
+
const linkedChanges = (graphData?.repoChanges ?? []).filter((ch) => !d.isWorktree && ch.head === d.sha && ch.status !== "dropped");
|
|
493
|
+
const primaryChange = linkedChanges[0];
|
|
494
|
+
const actionable = primaryChange && (primaryChange.status === "pending" || primaryChange.status === "conflict") && !primaryChange.integration?.supersededBy && (!primaryChange.integration || primaryChange.integration.status === "passed");
|
|
495
|
+
const dispatch = primaryChange ? store.dispatches.find((x) => x.changeId === primaryChange.id) : null;
|
|
496
|
+
const files = d.files ?? [];
|
|
497
|
+
const workingFiles = d.isWorktree ? (graphData?.working ?? []) : [];
|
|
498
|
+
|
|
499
|
+
box.innerHTML = `
|
|
500
|
+
<header class="detail-head gl-insp-head">
|
|
501
|
+
<div class="gl-insp-title-wrap">
|
|
502
|
+
<h2 class="eyebrow">${d.isWorktree ? "WORKTREE · 未提交更改" : `COMMIT · ${esc(d.sha.slice(0, 10))}`}</h2>
|
|
503
|
+
<p class="detail-title">${esc(d.subject || "(无提交说明)")}</p>
|
|
504
|
+
</div>
|
|
505
|
+
<div class="row-actions">
|
|
506
|
+
${!d.isWorktree ? `<button type="button" class="copy-cmd mono" data-copy-sha="${esc(d.sha)}">${esc(d.sha.slice(0, 8))}</button>` : ""}
|
|
507
|
+
</div>
|
|
508
|
+
</header>
|
|
509
|
+
${!d.isWorktree ? `<div class="detail-meta">
|
|
510
|
+
<span>${esc(d.author ?? "—")}</span>
|
|
511
|
+
<span class="sep"></span>
|
|
512
|
+
<span>${d.at ? stamp(d.at) : "—"}</span>
|
|
513
|
+
${d.parents?.length ? `<span class="sep"></span><span class="muted">父节点 ${d.parents.map((p) => `<button type="button" class="linkish mono" data-jump-sha="${esc(p)}">${esc(p.slice(0, 7))}</button>`).join(" ")}</span>` : ""}
|
|
514
|
+
</div>` : ""}
|
|
515
|
+
${d.body ? `<pre class="gl-commit-body">${esc(d.body)}</pre>` : ""}
|
|
516
|
+
<div class="detail-scroll">
|
|
517
|
+
${d.isWorktree ? `
|
|
518
|
+
<div class="gl-commit-box">
|
|
519
|
+
<textarea class="gl-commit-input" rows="2" placeholder="输入清晰的 Commit Message…" data-n="commitMsg">${esc(commitMessageDraft)}</textarea>
|
|
520
|
+
<div class="gl-commit-foot">
|
|
521
|
+
<div class="row-actions">
|
|
522
|
+
<button type="button" class="ghost-btn tiny" data-stage-all="1">全选</button>
|
|
523
|
+
<button type="button" class="ghost-btn tiny" data-stage-none="1">全不选</button>
|
|
524
|
+
<span class="muted">已选 ${selectedFilesForCommit?.size ?? 0}/${files.length}</span>
|
|
525
|
+
</div>
|
|
526
|
+
<div class="row-actions">
|
|
527
|
+
<button type="button" class="ghost-btn tiny" data-do-commit="0">Commit 所选</button>
|
|
528
|
+
<button type="button" class="primary-btn tiny" data-do-commit="1">Commit & Push</button>
|
|
529
|
+
</div>
|
|
530
|
+
</div>
|
|
531
|
+
</div>` : ""}
|
|
532
|
+
${linkedChanges.map((c) => renderLinkedChangeBanner(c, c === primaryChange && actionable, dispatch)).join("")}
|
|
533
|
+
<div class="gl-files-head">
|
|
534
|
+
<h3 class="eyebrow">文件变更树 <span class="eyebrow-note">${files.length} 个文件</span></h3>
|
|
535
|
+
${selectedFile ? `<button type="button" class="linkish tiny" data-clear-file="1">显示全部 Diff</button>` : ""}
|
|
536
|
+
</div>
|
|
537
|
+
<div class="file-list gl-file-tree">
|
|
538
|
+
${files.length ? files.map((f) => {
|
|
539
|
+
const wf = workingFiles.find((w) => w.path === f.path);
|
|
540
|
+
const checked = d.isWorktree ? (selectedFilesForCommit?.has(f.path) ?? false) : false;
|
|
541
|
+
const activeFile = selectedFile === f.path;
|
|
542
|
+
return `<div class="file-row gl-file-row${activeFile ? " on" : ""}" data-select-file="${esc(f.path)}">
|
|
543
|
+
<span class="gl-file-left">
|
|
544
|
+
${d.isWorktree ? `<input type="checkbox" data-check-file="${esc(f.path)}" ${checked ? "checked" : ""} />` : ""}
|
|
545
|
+
<span class="gl-file-tag mono">${esc((wf?.statusLabel ?? f.statusLabel ?? "改").slice(0, 2))}</span>
|
|
546
|
+
<span class="mono gl-file-path">${esc(f.path)}</span>
|
|
547
|
+
${f.sensitive ? `<span class="gl-badge warn">敏感</span>` : ""}
|
|
548
|
+
${wf?.conflict ? `<span class="gl-badge warn">冲突</span>` : ""}
|
|
549
|
+
</span>
|
|
550
|
+
${diffBlocksHtml(f.add, f.del)}
|
|
551
|
+
</div>`;
|
|
552
|
+
}).join("") : `<div class="empty-inline"><span class="dot"></span>没有文件变更</div>`}
|
|
553
|
+
</div>
|
|
554
|
+
<h3 class="eyebrow">${selectedFile ? `Diff · ${esc(selectedFile)}` : "Diff 视图"}</h3>
|
|
555
|
+
<div data-n="diff">${d.diff ? renderDiff(d.diff) : `<div class="empty-inline"><span class="dot"></span>无文本差异(可能是二进制或未跟踪空文件)</div>`}${d.truncated ? `<p class="footnote">差异超过 350KB 已截断,可点击上方单个文件查看局部 Diff。</p>` : ""}</div>
|
|
556
|
+
</div>`;
|
|
557
|
+
bindInspectorEvents(box, primaryChange, d.isWorktree);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function renderLinkedChangeBanner(c, actionable, dispatch) {
|
|
561
|
+
const cmd = (verb) => `/${verb} ${c.id}`;
|
|
562
|
+
return `<div class="change-msg gl-change-card">
|
|
563
|
+
<div class="gl-change-card-top">
|
|
564
|
+
<strong>Lemma 改动 #${esc(c.id)}</strong>
|
|
565
|
+
<span class="pill" data-s="${CHANGE_PILL[c.status]}">${CHANGE_LABEL[c.status] ?? c.status}</span>
|
|
566
|
+
<span class="mono muted">${esc(c.branch)}</span>
|
|
567
|
+
${dispatch ? `<button type="button" class="linkish" data-open-dispatch="${esc(dispatch.key)}">查看派工</button>` : ""}
|
|
568
|
+
</div>
|
|
569
|
+
${c.message ? `<p>${esc(c.message)}</p>` : ""}
|
|
570
|
+
<div class="row-actions">
|
|
571
|
+
${actionable ? `<button type="button" class="primary-btn tiny" data-apply-change="${esc(c.id)}">合并到主目录</button>` : ""}
|
|
572
|
+
${c.branch && c.status !== "dropped" ? `<button type="button" class="ghost-btn tiny" data-push-branch="${esc(c.branch)}">推送分支到远端</button>` : ""}
|
|
573
|
+
${actionable ? `<button type="button" class="ghost-btn tiny" data-drop-change="${esc(c.id)}">丢弃改动</button>` : ""}
|
|
574
|
+
${actionable ? `<button type="button" class="copy-cmd mono" data-copy="${cmd("apply")}">${cmd("apply")}</button>` : ""}
|
|
575
|
+
</div>
|
|
576
|
+
${c.integration ? `<div class="gl-int-sub"><strong>联合集成 · ${esc(c.integration.status)}${c.integration.supersededBy ? `(已被 #${esc(c.integration.supersededBy)} 替代)` : ""}</strong><p>来源:${c.integration.sources.map((s) => `<a href="#/changes/${esc(s.id)}">#${esc(s.id)}</a>`).join(" + ")}</p>${(c.integration.reports ?? []).map((rp) => `<details><summary>${esc(rp.name)} · ${rp.passed ? "通过" : "失败"}</summary><pre>${esc(rp.output || "没有输出")}</pre></details>`).join("")}${!c.integration.supersededBy && !["applied", "dropped"].includes(c.status) ? `<div class="row-actions">${["conflict", "failed"].includes(c.integration.status) ? `<button type="button" class="primary-btn tiny" data-int-repair="${esc(c.id)}">派成员修复</button>` : ""}${!["preparing", "merging", "repairing", "testing"].includes(c.integration.status) ? `<button type="button" class="ghost-btn tiny" data-int-rerun="${esc(c.id)}">重跑集成检查</button>` : ""}</div>` : ""}</div>` : ""}
|
|
577
|
+
</div>`;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function renderChangeInspector(c, actionable, dispatch, d) {
|
|
581
|
+
return `<header class="detail-head">
|
|
582
|
+
<div><h2 class="eyebrow">改动 #${esc(c.id)}</h2><p class="detail-title">${esc(c.task)}</p></div>
|
|
583
|
+
<span class="pill" data-s="${CHANGE_PILL[c.status]}">${CHANGE_LABEL[c.status] ?? c.status}</span>
|
|
584
|
+
</header>
|
|
585
|
+
<div class="detail-scroll">
|
|
586
|
+
${renderLinkedChangeBanner(c, actionable, dispatch)}
|
|
587
|
+
<h3 class="eyebrow">改了哪些文件 <span class="eyebrow-note">${c.files.length} 个 · +${c.add} −${c.del}</span></h3>
|
|
588
|
+
<div class="file-list">${c.files.length ? c.files.map((f) => `<div class="file-row"><span class="mono">${esc(f.path)}</span>${diffBlocksHtml(f.add, f.del)}</div>`).join("") : `<div class="empty-inline"><span class="dot"></span>没有修改文件</div>`}</div>
|
|
589
|
+
<h3 class="eyebrow">差异</h3>
|
|
590
|
+
<div>${d.error ? `<div class="change-msg err">${esc(d.error)}</div>` : renderDiff(d.diff)}</div>
|
|
591
|
+
</div>`;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function bindInspectorEvents(box, _change, isWorktree) {
|
|
595
|
+
box.querySelector("[data-copy-sha]")?.addEventListener("click", (e) => copy(e.currentTarget.dataset.copySha));
|
|
596
|
+
box.querySelector("[data-open-dispatch]")?.addEventListener("click", (e) => openDispatch(e.currentTarget.dataset.openDispatch));
|
|
597
|
+
box.querySelectorAll("[data-jump-sha]").forEach((btn) => {
|
|
598
|
+
btn.addEventListener("click", () => {
|
|
599
|
+
selectedTarget = btn.dataset.jumpSha;
|
|
600
|
+
selectedFile = null;
|
|
601
|
+
render();
|
|
602
|
+
loadDetail();
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
box.querySelector("[data-clear-file]")?.addEventListener("click", () => {
|
|
606
|
+
selectedFile = null;
|
|
607
|
+
loadDetail();
|
|
608
|
+
});
|
|
609
|
+
box.querySelectorAll("[data-select-file]").forEach((row) => {
|
|
610
|
+
row.addEventListener("click", (e) => {
|
|
611
|
+
if (e.target instanceof HTMLInputElement) return;
|
|
612
|
+
selectedFile = selectedFile === row.dataset.selectFile ? null : row.dataset.selectFile;
|
|
613
|
+
loadDetail();
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
if (isWorktree) {
|
|
617
|
+
const msgEl = box.querySelector('[data-n="commitMsg"]');
|
|
618
|
+
msgEl?.addEventListener("input", () => { commitMessageDraft = msgEl.value; });
|
|
619
|
+
box.querySelectorAll("[data-check-file]").forEach((cb) => {
|
|
620
|
+
cb.addEventListener("change", () => {
|
|
621
|
+
selectedFilesForCommit ??= new Set();
|
|
622
|
+
if (cb.checked) selectedFilesForCommit.add(cb.dataset.checkFile);
|
|
623
|
+
else selectedFilesForCommit.delete(cb.dataset.checkFile);
|
|
624
|
+
const counter = box.querySelector(".gl-commit-foot .muted");
|
|
625
|
+
if (counter) counter.textContent = `已选 ${selectedFilesForCommit.size}/${detailData?.files?.length ?? 0}`;
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
box.querySelector("[data-stage-all]")?.addEventListener("click", () => {
|
|
629
|
+
selectedFilesForCommit = new Set((detailData?.files ?? []).map((f) => f.path));
|
|
630
|
+
renderInspector();
|
|
631
|
+
});
|
|
632
|
+
box.querySelector("[data-stage-none]")?.addEventListener("click", () => {
|
|
633
|
+
selectedFilesForCommit = new Set();
|
|
634
|
+
renderInspector();
|
|
635
|
+
});
|
|
636
|
+
box.querySelectorAll("[data-do-commit]").forEach((btn) => {
|
|
637
|
+
btn.addEventListener("click", async () => {
|
|
638
|
+
const message = commitMessageDraft.trim();
|
|
639
|
+
if (!message) { toast("请填写 Commit 提交说明"); msgEl?.focus(); return; }
|
|
640
|
+
const files = [...(selectedFilesForCommit ?? [])];
|
|
641
|
+
if (!files.length) { toast("请至少勾选一个要提交的文件"); return; }
|
|
642
|
+
btn.disabled = true;
|
|
643
|
+
try {
|
|
644
|
+
const res = await post("/api/git/commit", { repo: activeRepo, message, files });
|
|
645
|
+
commitMessageDraft = "";
|
|
646
|
+
selectedFilesForCommit = null;
|
|
647
|
+
selectedTarget = res.sha;
|
|
648
|
+
toast(`已提交 ${res.sha.slice(0, 7)}(${res.committedFiles} 个文件)`);
|
|
649
|
+
if (btn.dataset.doCommit === "1") await doPush();
|
|
650
|
+
else await loadGraph();
|
|
651
|
+
} catch (err) {
|
|
652
|
+
toast(err.message);
|
|
653
|
+
} finally {
|
|
654
|
+
btn.disabled = false;
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
async function doPush(opts = {}) {
|
|
662
|
+
try {
|
|
663
|
+
const res = await post("/api/git/push", { repo: activeRepo, ...opts });
|
|
664
|
+
divergedPrompt = null;
|
|
665
|
+
toast(res.output || `已推送到 ${res.remote}/${res.branch}`);
|
|
666
|
+
await loadGraph();
|
|
667
|
+
} catch (err) {
|
|
668
|
+
if (err.code === "DIVERGED") {
|
|
669
|
+
divergedPrompt = {
|
|
670
|
+
branch: opts.branch || graphData?.repo?.branch || "HEAD",
|
|
671
|
+
remote: opts.remote || graphData?.repo?.remote || "origin",
|
|
672
|
+
ahead: err.ahead ?? 0,
|
|
673
|
+
behind: err.behind ?? 0,
|
|
674
|
+
error: err.message,
|
|
675
|
+
};
|
|
676
|
+
render();
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
toast(err.message);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
return {
|
|
684
|
+
title: "改动 · GitLens",
|
|
685
|
+
sub: "",
|
|
686
|
+
mount(r, params) {
|
|
687
|
+
root = r;
|
|
688
|
+
const initialId = params[0] ?? null;
|
|
689
|
+
root.addEventListener("click", async (e) => {
|
|
690
|
+
const target = e.target instanceof Element ? e.target : null;
|
|
691
|
+
if (!target) return;
|
|
692
|
+
const repoBtn = target.closest("[data-select-repo]");
|
|
693
|
+
if (repoBtn) {
|
|
694
|
+
activeRepo = repoBtn.dataset.selectRepo;
|
|
695
|
+
selectedTarget = null;
|
|
696
|
+
selectedFile = null;
|
|
697
|
+
divergedPrompt = null;
|
|
698
|
+
await loadGraph();
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
const filterBtn = target.closest('[data-n="graphFilter"] button');
|
|
702
|
+
if (filterBtn) {
|
|
703
|
+
graphFilter = filterBtn.dataset.k;
|
|
704
|
+
render();
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
const nodeRow = target.closest("[data-select-node]");
|
|
708
|
+
if (nodeRow) {
|
|
709
|
+
selectedTarget = nodeRow.dataset.selectNode;
|
|
710
|
+
selectedFile = null;
|
|
711
|
+
render();
|
|
712
|
+
await loadDetail();
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
if (target.closest("[data-git-fetch]")) {
|
|
716
|
+
try { const r2 = await post("/api/git/fetch", { repo: activeRepo }); toast(r2.output); await loadGraph(); }
|
|
717
|
+
catch (err) { toast(err.message); }
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
if (target.closest("[data-git-pull]")) {
|
|
721
|
+
try { const r2 = await post("/api/git/pull", { repo: activeRepo }); divergedPrompt = null; toast(r2.output); await loadGraph(); }
|
|
722
|
+
catch (err) { toast(err.message); }
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (target.closest("[data-focus-worktree]")) {
|
|
726
|
+
selectedTarget = "WORKTREE";
|
|
727
|
+
selectedFile = null;
|
|
728
|
+
render();
|
|
729
|
+
await loadDetail();
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
if (target.closest("[data-git-push]")) { await doPush(); return; }
|
|
733
|
+
if (target.closest("[data-diverge-pull]")) {
|
|
734
|
+
try { const r2 = await post("/api/git/pull", { repo: activeRepo }); divergedPrompt = null; toast(r2.output); await loadGraph(); }
|
|
735
|
+
catch (err) { toast(err.message); }
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
if (target.closest("[data-diverge-force]")) {
|
|
739
|
+
const b = divergedPrompt?.branch ?? graphData?.repo?.branch;
|
|
740
|
+
if (!confirm(`确认使用 --force-with-lease 强推分支 ${b}?远端未被本地包含的提交将被安全覆盖。`)) return;
|
|
741
|
+
await doPush({ branch: b, forceWithLease: true });
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
if (target.closest("[data-diverge-dismiss]")) { divergedPrompt = null; render(); return; }
|
|
745
|
+
if (target.closest("[data-toggle-policy]")) {
|
|
746
|
+
try {
|
|
747
|
+
const next = !workbench.requireHumanPush;
|
|
748
|
+
await post("/api/git/policy", { requireHumanPush: next });
|
|
749
|
+
workbench.requireHumanPush = next;
|
|
750
|
+
render();
|
|
751
|
+
toast(next ? "已开启“推送前需我确认”" : "已恢复 Agent 干净快进自主推送");
|
|
752
|
+
} catch (err) { toast(err.message); }
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
const gateApprove = target.closest("[data-gate-approve]");
|
|
756
|
+
if (gateApprove) {
|
|
757
|
+
gateApprove.disabled = true;
|
|
758
|
+
try { await post(`/api/git/gates/${encodeURIComponent(gateApprove.dataset.gateApprove)}/resolve`, { action: "approve" }); toast("已批准并执行"); await loadGraph(); }
|
|
759
|
+
catch (err) { toast(err.message); gateApprove.disabled = false; }
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
const gateReject = target.closest("[data-gate-reject]");
|
|
763
|
+
if (gateReject) {
|
|
764
|
+
gateReject.disabled = true;
|
|
765
|
+
try { await post(`/api/git/gates/${encodeURIComponent(gateReject.dataset.gateReject)}/resolve`, { action: "reject" }); toast("已驳回该请求"); await loadGraph(); }
|
|
766
|
+
catch (err) { toast(err.message); gateReject.disabled = false; }
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
const pushBrBtn = target.closest("[data-push-branch]");
|
|
770
|
+
if (pushBrBtn) { await doPush({ branch: pushBrBtn.dataset.pushBranch, setUpstream: true }); return; }
|
|
771
|
+
if (target.closest("[data-clean-changes]")) {
|
|
772
|
+
if (!confirm("清理所有已合并(applied)或无改动的 worktree 和分支?")) return;
|
|
773
|
+
try { await runControlAction("/api/changes/clean", {}); await refreshAll(); }
|
|
774
|
+
catch (err) { toast(err.message); }
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
const applyBtn = target.closest("[data-apply-change]");
|
|
778
|
+
if (applyBtn) {
|
|
779
|
+
const cid = applyBtn.dataset.applyChange;
|
|
780
|
+
const rec = store.changes.find((x) => x.id === cid);
|
|
781
|
+
if (!confirm(`确认将改动 #${cid}(${rec?.files?.length ?? 0} 个文件,+${rec?.add ?? 0} -${rec?.del ?? 0})合并到主工作目录?不自动 commit。`)) return;
|
|
782
|
+
try { await runControlAction(`/api/changes/${encodeURIComponent(cid)}/apply`, {}); await loadGraph(); }
|
|
783
|
+
catch (err) { toast(err.message); }
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
const dropBtn = target.closest("[data-drop-change]");
|
|
787
|
+
if (dropBtn) {
|
|
788
|
+
const cid = dropBtn.dataset.dropChange;
|
|
789
|
+
if (!confirm(`确认丢弃改动 #${cid}?对应的 worktree 和未合并分支将被删除!`)) return;
|
|
790
|
+
try { await runControlAction(`/api/changes/${encodeURIComponent(cid)}/drop`, {}); selectedTarget = null; await refreshAll(); }
|
|
791
|
+
catch (err) { toast(err.message); }
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
const rerunBtn = target.closest("[data-int-rerun]");
|
|
795
|
+
if (rerunBtn) {
|
|
796
|
+
try { await runControlAction(`/api/integrations/${encodeURIComponent(rerunBtn.dataset.intRerun)}/rerun`, {}, "已重跑联合集成检查"); await loadGraph(); }
|
|
797
|
+
catch (err) { toast(err.message); }
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
const repairBtn = target.closest("[data-int-repair]");
|
|
801
|
+
if (repairBtn) {
|
|
802
|
+
const cid = repairBtn.dataset.intRepair;
|
|
803
|
+
const it = (store.state?.integrations ?? []).find((x) => x.id === cid) ?? store.changes.find((x) => x.id === cid)?.integration;
|
|
804
|
+
if (it) openRepairIntegrationDialog({ ...it, id: cid }, store.state?.agents ?? []);
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
root.addEventListener("input", (e) => {
|
|
808
|
+
const target = e.target;
|
|
809
|
+
if (target instanceof HTMLInputElement && target.dataset.n === "search") {
|
|
810
|
+
search = target.value;
|
|
811
|
+
const listBox = root.querySelector('[data-n="graphList"]');
|
|
812
|
+
if (listBox) {
|
|
813
|
+
const { rows: laneRows, maxLanes } = computeCommitLanes(buildGraphRows());
|
|
814
|
+
listBox.innerHTML = renderGraphRowsHtml(laneRows, maxLanes, "没有匹配的提交或改动记录。");
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
lastGateSig = JSON.stringify(store.state?.gitWorkbench ?? null);
|
|
819
|
+
refreshAll(initialId);
|
|
820
|
+
},
|
|
821
|
+
update(kind) {
|
|
822
|
+
if (!root) return;
|
|
823
|
+
if (kind === "all") {
|
|
824
|
+
activeRepo = null;
|
|
825
|
+
selectedTarget = null;
|
|
826
|
+
selectedFile = null;
|
|
827
|
+
lastGateSig = JSON.stringify(store.state?.gitWorkbench ?? null);
|
|
828
|
+
refreshAll();
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
if (kind === "changes") {
|
|
832
|
+
refreshAll();
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
if (kind === "state") {
|
|
836
|
+
const sig = JSON.stringify(store.state?.gitWorkbench ?? null);
|
|
837
|
+
if (sig !== lastGateSig) {
|
|
838
|
+
lastGateSig = sig;
|
|
839
|
+
refreshAll();
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
},
|
|
843
|
+
};
|
|
844
|
+
}
|