@aiti-ai/ext-shared 0.0.0-stage → 0.1.11
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/LICENSE +21 -0
- package/README.md +36 -2
- package/agent-accounts.test.mjs +227 -0
- package/agent-accounts.ts +324 -0
- package/agent-capability-contract.test.mjs +129 -0
- package/agent-interaction.test.mjs +194 -0
- package/agent-interaction.ts +340 -0
- package/agent-launch.test.mjs +262 -0
- package/agent-spawn-env.test.mjs +169 -0
- package/agent-spawn-env.ts +548 -0
- package/aiti-editor-inject.mjs +49 -0
- package/backend-queue.test.mjs +336 -0
- package/backend-queue.ts +469 -0
- package/blob-save-route.ts +128 -0
- package/cbc-model-catalog.ts +86 -0
- package/check-client.mjs +273 -0
- package/check-ext-globals.mjs +144 -0
- package/controlled-login-dialog.mjs +270 -0
- package/controlled-login.mjs +398 -0
- package/controlled-login.test.mjs +466 -0
- package/convert-saveas.test.mjs +39 -0
- package/convert-saveas.ts +170 -0
- package/copy-client-bundle.mjs +39 -0
- package/cursor-cli-store.ts +377 -0
- package/dedupe-fetch.test.mjs +71 -0
- package/dedupe-fetch.ts +58 -0
- package/deploy-commit.mjs +52 -0
- package/dev-pack.mjs +246 -0
- package/dock-icons.ts +127 -0
- package/esbuild-bin.test.mjs +53 -0
- package/esbuild-bin.ts +66 -0
- package/exec-async.test.mjs +86 -0
- package/exec-async.ts +179 -0
- package/ext-display-names.ts +91 -0
- package/ext-entry-contracts.test.mjs +131 -0
- package/ext-float-dock-core.test.mjs +348 -0
- package/ext-float-dock-core.ts +783 -0
- package/ext-float-dock-lite.ts +52 -0
- package/ext-float-dock.test.mjs +286 -0
- package/ext-float-dock.ts +740 -0
- package/ext-icons-deploy.mjs +24 -0
- package/ext-lazy.test.mjs +186 -0
- package/ext-lazy.tsx +183 -0
- package/ext-model-state.test.mjs +272 -0
- package/ext-model-state.ts +324 -0
- package/ext-protocol.mjs +113 -0
- package/ext-protocol.test.mjs +88 -0
- package/ext-session-usage.test.mjs +219 -0
- package/ext-session-usage.ts +507 -0
- package/external-cli-governance.ts +153 -0
- package/git-ops-client/api.mjs +56 -0
- package/git-ops-client/branch-panel.tsx +987 -0
- package/git-ops-client/i18n.mjs +328 -0
- package/host-tools-allow.test.mjs +46 -0
- package/host-tools-allow.ts +84 -0
- package/icons/alert.svg +1 -0
- package/icons/bookmark.svg +1 -0
- package/icons/bot.svg +1 -0
- package/icons/chart-column.svg +1 -0
- package/icons/check-circle.svg +1 -0
- package/icons/clipboard-list.svg +1 -0
- package/icons/clock.svg +1 -0
- package/icons/coffee.svg +1 -0
- package/icons/edit.svg +1 -0
- package/icons/eye.svg +1 -0
- package/icons/git-branch.svg +1 -0
- package/icons/git-commit-horizontal.svg +1 -0
- package/icons/globe.svg +1 -0
- package/icons/history.svg +1 -0
- package/icons/import.svg +1 -0
- package/icons/inbox.svg +1 -0
- package/icons/key-round.svg +1 -0
- package/icons/layout-grid.svg +1 -0
- package/icons/mail.svg +1 -0
- package/icons/message-circle.svg +1 -0
- package/icons/message-square.svg +1 -0
- package/icons/meter-vertical.svg +1 -0
- package/icons/mic.svg +1 -0
- package/icons/monitor.svg +1 -0
- package/icons/pen-line.svg +1 -0
- package/icons/plug.svg +1 -0
- package/icons/radio-dot.svg +1 -0
- package/icons/radio.svg +1 -0
- package/icons/refresh.svg +1 -0
- package/icons/rocket.svg +1 -0
- package/icons/search.svg +1 -0
- package/icons/shield.svg +1 -0
- package/icons/sparkles.svg +1 -0
- package/icons/square-kanban.svg +1 -0
- package/icons/terminal.svg +1 -0
- package/icons/users.svg +1 -0
- package/icons/volume-2.svg +1 -0
- package/icons/wand.svg +1 -0
- package/icons/wrench.svg +1 -0
- package/icons/x-circle.svg +1 -0
- package/icons/x.svg +1 -0
- package/ignore-semantics.ts +76 -0
- package/lazy-loading-metrics.mjs +61 -0
- package/new-session-cwd.test.mjs +389 -0
- package/new-session-cwd.ts +253 -0
- package/open-viewer-window.ts +65 -0
- package/overlay-back-client.test.mjs +123 -0
- package/overlay-back-client.ts +87 -0
- package/package.json +65 -4
- package/pi-fork-rpc/README.md +12 -0
- package/pi-fork-rpc/cli-resolve.test.mjs +42 -0
- package/pi-fork-rpc/cli-resolve.ts +79 -0
- package/pi-fork-rpc/remote-queue.test.mjs +100 -0
- package/pi-fork-rpc/remote-queue.ts +140 -0
- package/pi-fork-rpc/spec.ts +106 -0
- package/pi-fork-rpc/wire.test.mjs +260 -0
- package/pi-fork-rpc/wire.ts +367 -0
- package/popup-anchor.ts +45 -0
- package/provider-priority-contract.test.mjs +55 -0
- package/reconcile-deps.mjs +41 -0
- package/reload-instances.mjs +60 -0
- package/seed-tool.test.mjs +95 -0
- package/seed-tool.ts +88 -0
- package/session-recycle.ts +109 -0
- package/shared-copy-sync.test.mjs +115 -0
- package/soffice-locate.ts +171 -0
- package/soffice-panel.ts +239 -0
- package/sync-dir.mjs +91 -0
- package/sync-dir.test.mjs +101 -0
- package/sync-gate.test.mjs +93 -0
- package/sync-mirror.test.mjs +85 -0
- package/task-list.test.mjs +91 -0
- package/task-list.ts +118 -0
- package/test-rm-rf.mjs +33 -0
- package/ui-dialogs.test.mjs +198 -0
- package/ui-dialogs.ts +310 -0
|
@@ -0,0 +1,987 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git-ops-client · 共享分支面板(方案 §2:mockup ② 六分区)+ chip 徽标。
|
|
3
|
+
*
|
|
4
|
+
* 消费方(session-manager 折叠头 chip / aiti-folder 工具条)以 bundle 源引内联;
|
|
5
|
+
* react hooks 经宿主 alias 委托(_shared 惯例);apiUrl 由消费方注入(basePath 感知)。
|
|
6
|
+
*
|
|
7
|
+
* 主题硬条款(§2 v2 升格):全部颜色走宿主 CSS vars
|
|
8
|
+
* (--bg/--bg-hover/--border/--text/--text-muted/--text-dim/--accent/--font-mono),
|
|
9
|
+
* 半透明派生一律 color-mix 且基色取自 var——零硬编码色值;验收=深/浅两主题截图比对。
|
|
10
|
+
*
|
|
11
|
+
* 数据:打开拉一次(refs/log/stash),写操作后本地刷新——零轮询。
|
|
12
|
+
* worktree 分区数据与操作由消费方注入(宿主 /api/worktrees* 例外不进引擎,§2)。
|
|
13
|
+
*/
|
|
14
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
15
|
+
import { clampToViewport, fixedOrigin } from "../popup-anchor";
|
|
16
|
+
import { buildAtText, openNewSessionWithExtSvc } from "../new-session-cwd";
|
|
17
|
+
import { createGitOpsApi } from "./api.mjs";
|
|
18
|
+
import { makeT } from "./i18n.mjs";
|
|
19
|
+
|
|
20
|
+
/* ── chip 徽标(折叠头右端;非 git / 引擎缺席由消费方门控不渲染)── */
|
|
21
|
+
|
|
22
|
+
export function BranchChipBadge(p: {
|
|
23
|
+
branch: string;
|
|
24
|
+
dirtyCount?: number;
|
|
25
|
+
open?: boolean;
|
|
26
|
+
compact?: boolean; // 小屏:仅 ⎇ 图标(title 保全文)
|
|
27
|
+
title?: string;
|
|
28
|
+
}) {
|
|
29
|
+
const label = p.compact ? "" : p.branch;
|
|
30
|
+
return (
|
|
31
|
+
<span
|
|
32
|
+
data-branch-chip="1"
|
|
33
|
+
title={p.title ?? `${p.branch}${p.dirtyCount ? ` · ${p.dirtyCount}` : ""}`}
|
|
34
|
+
style={{
|
|
35
|
+
display: "inline-flex", alignItems: "center", gap: 5,
|
|
36
|
+
fontFamily: "var(--font-mono)", fontSize: 10.5,
|
|
37
|
+
color: p.open ? "var(--accent)" : "var(--text)",
|
|
38
|
+
background: "var(--bg-hover)",
|
|
39
|
+
border: "1px solid " + (p.open ? "var(--accent)" : "var(--border)"),
|
|
40
|
+
borderRadius: 6, padding: "2.5px 8px", cursor: "pointer",
|
|
41
|
+
maxWidth: p.compact ? 26 : 150, lineHeight: 1.3, flexShrink: 0,
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
<svg width="10" height="10" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6" style={{ flexShrink: 0 }}>
|
|
45
|
+
<circle cx="4" cy="3.5" r="1.8" /><circle cx="4" cy="12.5" r="1.8" /><circle cx="12" cy="3.5" r="1.8" />
|
|
46
|
+
<path d="M4 5.3v5.4M12 5.3c0 3-3 3.6-6 4.1" />
|
|
47
|
+
</svg>
|
|
48
|
+
<span style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>{label}</span>
|
|
49
|
+
{typeof p.dirtyCount === "number" && p.dirtyCount > 0 && !p.compact ? (
|
|
50
|
+
<span style={{ color: "var(--text-dim)", fontSize: 9.5, flexShrink: 0 }}>{p.dirtyCount}</span>
|
|
51
|
+
) : null}
|
|
52
|
+
</span>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* ── 面板 ── */
|
|
57
|
+
|
|
58
|
+
export interface BranchPanelProps {
|
|
59
|
+
apiUrl: (p: string) => string;
|
|
60
|
+
cwd: string;
|
|
61
|
+
homeDir?: string;
|
|
62
|
+
locale?: string;
|
|
63
|
+
open: boolean;
|
|
64
|
+
onClose: () => void;
|
|
65
|
+
/** chip 按钮视口矩形(getBoundingClientRect;面板右对齐其右缘、展开其下) */
|
|
66
|
+
anchor: { left: number; top: number; right: number; bottom: number } | null;
|
|
67
|
+
/** worktree 例外(宿主 /api/worktrees* 数据与操作,消费方注入) */
|
|
68
|
+
projectRoot?: string | null;
|
|
69
|
+
worktrees?: { path: string; branch?: string; isMain?: boolean }[];
|
|
70
|
+
currentWorktreePath?: string | null;
|
|
71
|
+
onSelectWorktree?: (path: string) => void;
|
|
72
|
+
onCreateWorktree?: (branch: string) => Promise<{ path?: string; error?: string } | void>;
|
|
73
|
+
onRemoveWorktree?: (path: string, force: boolean) => Promise<{ dirty?: boolean; error?: string } | void>;
|
|
74
|
+
onWorktreeChanged?: () => void;
|
|
75
|
+
/** 块级 -p(aiti-cmd PTY;缺席不渲染按钮) */
|
|
76
|
+
pty?: {
|
|
77
|
+
available: boolean;
|
|
78
|
+
stashInteractive: (mode: "push" | "apply", index?: number) => Promise<{ ok: boolean; error?: string }>;
|
|
79
|
+
};
|
|
80
|
+
/** 写操作成功后通知消费方(刷新其他 git 面板) */
|
|
81
|
+
onChanged?: () => void;
|
|
82
|
+
/** 客户端服务解析(getExtService 封装):Git Review 直开 / @ 到新会话所需;缺席隐藏对应按钮 */
|
|
83
|
+
extSvc?: <T>(key: string) => T | undefined;
|
|
84
|
+
/** 打开工作区文件(folder 注入;缺席隐藏「打开」按钮——commit 时点内容≠工作区,按钮文案已标注) */
|
|
85
|
+
openFile?: (absPath: string) => void;
|
|
86
|
+
/** aiti-float 持久化键(面板 portal 到 body 无 data-ext-item 祖先,须显式;两消费方各自传) */
|
|
87
|
+
floatKey?: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const PANEL_W = 330;
|
|
91
|
+
|
|
92
|
+
export function BranchPanel(p: BranchPanelProps) {
|
|
93
|
+
const t = useMemo(() => makeT(p.locale), [p.locale]);
|
|
94
|
+
const api = useMemo(() => createGitOpsApi({ apiUrl: p.apiUrl }), [p.apiUrl]);
|
|
95
|
+
const [refsData, setRefsData] = useState<any>(null);
|
|
96
|
+
const [loadError, setLoadError] = useState<string | null>(null);
|
|
97
|
+
const [filter, setFilter] = useState("");
|
|
98
|
+
const [wtMode, setWtMode] = useState<boolean>(() => {
|
|
99
|
+
try { return localStorage.getItem("gitops.panel.wtMode") === "1"; } catch { return false; }
|
|
100
|
+
});
|
|
101
|
+
const [collapsed, setCollapsed] = useState<Set<string>>(() => new Set());
|
|
102
|
+
const [remotesOpen, setRemotesOpen] = useState(false);
|
|
103
|
+
const [log, setLog] = useState<{ lines: string[]; nextCursor: number | null }>({ lines: [], nextCursor: null });
|
|
104
|
+
const [logCursor, setLogCursor] = useState(0);
|
|
105
|
+
const [stash, setStash] = useState<any[]>([]);
|
|
106
|
+
const [stashFiles, setStashFiles] = useState<Record<number, { tracked: string[]; untracked: string[] }>>({});
|
|
107
|
+
const [expandedStash, setExpandedStash] = useState<number | null>(null);
|
|
108
|
+
const [checkedExtract, setCheckedExtract] = useState<Set<string>>(() => new Set());
|
|
109
|
+
const [partOpen, setPartOpen] = useState(false);
|
|
110
|
+
const [partChecked, setPartChecked] = useState<Set<string> | null>(null);
|
|
111
|
+
const [dropConfirm, setDropConfirm] = useState<number | null>(null);
|
|
112
|
+
const [conflict, setConflict] = useState<{ ref: string; files: string[] } | null>(null);
|
|
113
|
+
const [createAt, setCreateAt] = useState<{ from: string; suggested?: string } | null>(null);
|
|
114
|
+
const [createName, setCreateName] = useState("");
|
|
115
|
+
// ── commit 详情卡(图谱点行;docs/aiti-git-ops-commit-card-plan.md)──
|
|
116
|
+
const [commitSha, setCommitSha] = useState<string | null>(null);
|
|
117
|
+
const [commitInfo, setCommitInfo] = useState<any>(null);
|
|
118
|
+
const [commitLoadErr, setCommitLoadErr] = useState<string | null>(null);
|
|
119
|
+
const [commitDiff, setCommitDiff] = useState<{ path: string; oldPath?: string; patch: string; truncated: boolean } | null>(null);
|
|
120
|
+
const [diffLoading, setDiffLoading] = useState(false);
|
|
121
|
+
const [tagInput, setTagInput] = useState(false);
|
|
122
|
+
const [tagName, setTagName] = useState("");
|
|
123
|
+
const [pickConflict, setPickConflict] = useState<string[] | null>(null);
|
|
124
|
+
const [wtNewOpen, setWtNewOpen] = useState(false);
|
|
125
|
+
const [wtNewName, setWtNewName] = useState("");
|
|
126
|
+
const [wtForceRemove, setWtForceRemove] = useState<string | null>(null);
|
|
127
|
+
const [busy, setBusy] = useState(false);
|
|
128
|
+
const [error, setError] = useState<string | null>(null);
|
|
129
|
+
const [toast, setToast] = useState<string | null>(null);
|
|
130
|
+
const boxRef = useRef<HTMLDivElement | null>(null);
|
|
131
|
+
const [pos, setPos] = useState<{ left: number; top: number } | null>(null);
|
|
132
|
+
|
|
133
|
+
const toggleSection = useCallback((key: string) => {
|
|
134
|
+
setCollapsed((prev) => {
|
|
135
|
+
const next = new Set(prev);
|
|
136
|
+
if (next.has(key)) next.delete(key); else next.add(key);
|
|
137
|
+
return next;
|
|
138
|
+
});
|
|
139
|
+
}, []);
|
|
140
|
+
|
|
141
|
+
const refreshData = useCallback(async () => {
|
|
142
|
+
if (!p.cwd) return;
|
|
143
|
+
setLoadError(null);
|
|
144
|
+
const [r, g, s] = await Promise.all([
|
|
145
|
+
api.refs(p.cwd),
|
|
146
|
+
api.log(p.cwd, 0),
|
|
147
|
+
api.stashList(p.cwd),
|
|
148
|
+
]);
|
|
149
|
+
if (r.status === 404 || r.status === 0) { setLoadError(r.data?.error || "HTTP " + r.status); return; }
|
|
150
|
+
if (r.status !== 200) { setLoadError(r.data?.error || "HTTP " + r.status); setRefsData(null); return; }
|
|
151
|
+
setRefsData(r.data);
|
|
152
|
+
setLog({ lines: g.data?.lines ?? [], nextCursor: g.data?.nextCursor ?? null });
|
|
153
|
+
setLogCursor(0);
|
|
154
|
+
setStash(s.data?.items ?? []);
|
|
155
|
+
}, [api, p.cwd]);
|
|
156
|
+
|
|
157
|
+
// 打开拉一次(cwd 变了重拉)
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
if (!p.open || !p.cwd) return;
|
|
160
|
+
void refreshData();
|
|
161
|
+
}, [p.open, p.cwd, refreshData]);
|
|
162
|
+
|
|
163
|
+
const loadMoreLog = useCallback(async () => {
|
|
164
|
+
if (!p.cwd || log.nextCursor == null) return;
|
|
165
|
+
const g = await api.log(p.cwd, log.nextCursor);
|
|
166
|
+
if (g.status === 200) {
|
|
167
|
+
setLog((prev) => ({ lines: [...prev.lines, ...(g.data?.lines ?? [])], nextCursor: g.data?.nextCursor ?? null }));
|
|
168
|
+
setLogCursor(log.nextCursor);
|
|
169
|
+
}
|
|
170
|
+
}, [api, p.cwd, log.nextCursor]);
|
|
171
|
+
|
|
172
|
+
// 定位:右对齐 chip、展开其下;下方装不下则压缩高度(面板内滚,不上翻——mockup 形态)
|
|
173
|
+
useLayoutEffect(() => {
|
|
174
|
+
if (!p.open || !p.anchor) return;
|
|
175
|
+
const el = boxRef.current;
|
|
176
|
+
const width = Math.min(PANEL_W, window.innerWidth - 16);
|
|
177
|
+
let left = p.anchor.right - width;
|
|
178
|
+
let top = (p.anchor.bottom ?? 0) + 6;
|
|
179
|
+
const maxH = window.innerHeight - top - 8;
|
|
180
|
+
if (el) {
|
|
181
|
+
const c = clampToViewport(left, top, width, Math.min(el.offsetHeight, Math.max(maxH, 120)), 8);
|
|
182
|
+
left = c.left; top = c.top;
|
|
183
|
+
}
|
|
184
|
+
const o = fixedOrigin(el);
|
|
185
|
+
setPos((cur) => (cur && cur.left === left - o.x && cur.top === top - o.y ? cur : { left: left - o.x, top: top - o.y }));
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// 点外关闭(chip 本体除外——由 chip onClick 单一开关)+ Escape
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
if (!p.open) return;
|
|
191
|
+
const onDown = (e: MouseEvent) => {
|
|
192
|
+
const target = e.target as Node | null;
|
|
193
|
+
if (boxRef.current?.contains(target)) return;
|
|
194
|
+
if (target && typeof (target as Element).closest === "function" && (target as Element).closest("[data-branch-chip]")) return;
|
|
195
|
+
p.onClose();
|
|
196
|
+
};
|
|
197
|
+
const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") p.onClose(); };
|
|
198
|
+
document.addEventListener("mousedown", onDown);
|
|
199
|
+
document.addEventListener("keydown", onKey);
|
|
200
|
+
return () => { document.removeEventListener("mousedown", onDown); document.removeEventListener("keydown", onKey); };
|
|
201
|
+
}, [p.open, p.onClose]);
|
|
202
|
+
|
|
203
|
+
const run = useCallback(async (fn: () => Promise<void>) => {
|
|
204
|
+
if (busy) return;
|
|
205
|
+
setBusy(true); setError(null);
|
|
206
|
+
try { await fn(); } finally { setBusy(false); }
|
|
207
|
+
}, [busy]);
|
|
208
|
+
|
|
209
|
+
const afterWrite = useCallback(() => {
|
|
210
|
+
void refreshData();
|
|
211
|
+
p.onChanged?.();
|
|
212
|
+
}, [refreshData, p.onChanged]);
|
|
213
|
+
|
|
214
|
+
/** checkout 家族统一管道:409 → 冲突三选一卡 */
|
|
215
|
+
const switchTo = useCallback((ref: string) => run(async () => {
|
|
216
|
+
if (wtMode) { await openAsWorktree(ref); return; }
|
|
217
|
+
const r = await api.checkout(p.cwd, ref);
|
|
218
|
+
if (r.status === 409 && r.data?.conflict) { setConflict({ ref, files: r.data.files ?? [] }); return; }
|
|
219
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return; }
|
|
220
|
+
afterWrite();
|
|
221
|
+
}), [run, wtMode, api, p.cwd, afterWrite]);
|
|
222
|
+
|
|
223
|
+
/** worktree 形态打开:已有同名 worktree 直接切;否则宿主建(会自动切项目) */
|
|
224
|
+
const openAsWorktree = useCallback(async (branchName: string) => {
|
|
225
|
+
if (!p.onCreateWorktree) { setError("worktree unavailable"); return; }
|
|
226
|
+
const existing = (p.worktrees ?? []).find((w) => w.branch === branchName);
|
|
227
|
+
if (existing) { p.onSelectWorktree?.(existing.path); p.onClose(); return; }
|
|
228
|
+
const r = await p.onCreateWorktree(branchName);
|
|
229
|
+
if (r && typeof r === "object" && r.error) { setError(r.error); return; }
|
|
230
|
+
p.onClose();
|
|
231
|
+
}, [p.onCreateWorktree, p.worktrees, p.onSelectWorktree, p.onClose]);
|
|
232
|
+
|
|
233
|
+
/** 远程分支 → 先确保同名本地分支(无 tracking 语义,MVP),再走 worktree/checkout */
|
|
234
|
+
const ensureLocalBranch = useCallback(async (remoteRef: string): Promise<string | null> => {
|
|
235
|
+
const short = remoteRef.replace(/^[^/]+\//, "");
|
|
236
|
+
if ((refsData?.branches ?? []).includes(short)) return short;
|
|
237
|
+
const r = await api.branchCreate(p.cwd, short, remoteRef, false);
|
|
238
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return null; }
|
|
239
|
+
return short;
|
|
240
|
+
}, [refsData, api, p.cwd]);
|
|
241
|
+
|
|
242
|
+
const onBranchRow = useCallback((branch: string, isRemote = false) => run(async () => {
|
|
243
|
+
const target = isRemote ? await ensureLocalBranch(branch) : branch;
|
|
244
|
+
if (!target) return;
|
|
245
|
+
if (wtMode) await openAsWorktree(target);
|
|
246
|
+
else await switchTo(target);
|
|
247
|
+
}), [run, ensureLocalBranch, wtMode, openAsWorktree, switchTo]);
|
|
248
|
+
|
|
249
|
+
const submitCreate = useCallback((from?: string) => run(async () => {
|
|
250
|
+
const name = createName.trim();
|
|
251
|
+
if (!name) return;
|
|
252
|
+
if (wtMode) {
|
|
253
|
+
const cr = await api.branchCreate(p.cwd, name, from, false);
|
|
254
|
+
if (cr.status !== 200) { setError(cr.data?.error ?? "HTTP " + cr.status); return; }
|
|
255
|
+
setCreateAt(null); setCreateName("");
|
|
256
|
+
await openAsWorktree(name);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const r = await api.branchCreate(p.cwd, name, from, true);
|
|
260
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return; }
|
|
261
|
+
setCreateAt(null); setCreateName("");
|
|
262
|
+
afterWrite();
|
|
263
|
+
}), [run, createName, wtMode, api, p.cwd, openAsWorktree, afterWrite]);
|
|
264
|
+
|
|
265
|
+
const submitWtNew = useCallback(() => run(async () => {
|
|
266
|
+
const name = wtNewName.trim();
|
|
267
|
+
if (!name) return;
|
|
268
|
+
const r = await p.onCreateWorktree?.(name);
|
|
269
|
+
if (r && typeof r === "object" && r.error) { setError(r.error); return; }
|
|
270
|
+
setWtNewOpen(false); setWtNewName("");
|
|
271
|
+
p.onWorktreeChanged?.();
|
|
272
|
+
p.onClose();
|
|
273
|
+
}), [run, wtNewName, p.onCreateWorktree, p.onWorktreeChanged, p.onClose]);
|
|
274
|
+
|
|
275
|
+
const submitWtRemove = useCallback((path: string, force: boolean) => run(async () => {
|
|
276
|
+
const r = await p.onRemoveWorktree?.(path, force);
|
|
277
|
+
if (r && typeof r === "object" && r.dirty && !force) { setWtForceRemove(path); return; }
|
|
278
|
+
if (r && typeof r === "object" && r.error) { setError(r.error); return; }
|
|
279
|
+
setWtForceRemove(null);
|
|
280
|
+
p.onWorktreeChanged?.();
|
|
281
|
+
}), [run, p.onRemoveWorktree, p.onWorktreeChanged]);
|
|
282
|
+
|
|
283
|
+
const expandStash = useCallback((index: number) => run(async () => {
|
|
284
|
+
if (expandedStash === index) { setExpandedStash(null); return; }
|
|
285
|
+
const f = await api.stashFiles(p.cwd, index);
|
|
286
|
+
if (f.status !== 200) { setError(f.data?.error ?? "HTTP " + f.status); return; }
|
|
287
|
+
setStashFiles((prev) => ({ ...prev, [index]: { tracked: f.data.tracked ?? [], untracked: f.data.untracked ?? [] } }));
|
|
288
|
+
setCheckedExtract(new Set([...(f.data.tracked ?? []), ...(f.data.untracked ?? [])]));
|
|
289
|
+
setExpandedStash(index);
|
|
290
|
+
}), [run, expandedStash, api, p.cwd]);
|
|
291
|
+
|
|
292
|
+
const extractChecked = useCallback((index: number) => run(async () => {
|
|
293
|
+
const paths = [...checkedExtract];
|
|
294
|
+
if (paths.length === 0) return;
|
|
295
|
+
const r = await api.stashApply(p.cwd, index, { paths });
|
|
296
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return; }
|
|
297
|
+
setExpandedStash(null);
|
|
298
|
+
afterWrite();
|
|
299
|
+
}), [run, checkedExtract, api, p.cwd, afterWrite]);
|
|
300
|
+
|
|
301
|
+
const stashAct = useCallback((index: number, opts: { pop?: boolean } = {}) => run(async () => {
|
|
302
|
+
const r = await api.stashApply(p.cwd, index, opts);
|
|
303
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return; }
|
|
304
|
+
afterWrite();
|
|
305
|
+
}), [run, api, p.cwd, afterWrite]);
|
|
306
|
+
|
|
307
|
+
const dropStash = useCallback((index: number) => run(async () => {
|
|
308
|
+
const r = await api.stashDrop(p.cwd, index);
|
|
309
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return; }
|
|
310
|
+
setDropConfirm(null);
|
|
311
|
+
afterWrite();
|
|
312
|
+
}), [run, api, p.cwd, afterWrite]);
|
|
313
|
+
|
|
314
|
+
const submitPartialStash = useCallback(() => run(async () => {
|
|
315
|
+
const checked = [...(partChecked ?? [])];
|
|
316
|
+
if (checked.length === 0) return;
|
|
317
|
+
const dirtyFiles = refsData?.dirtyFiles ?? [];
|
|
318
|
+
const includeUntracked = checked.some((s) => dirtyFiles.find((f: any) => f.path === s)?.xy === "??");
|
|
319
|
+
const r = await api.stashPush(p.cwd, { message: "aiti-git-ops partial", includeUntracked, paths: checked });
|
|
320
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return; }
|
|
321
|
+
setPartOpen(false);
|
|
322
|
+
afterWrite();
|
|
323
|
+
}), [run, partChecked, refsData, api, p.cwd, afterWrite]);
|
|
324
|
+
|
|
325
|
+
const stashInteractive = useCallback((mode: "push" | "apply", index?: number) => run(async () => {
|
|
326
|
+
const r = await p.pty?.stashInteractive(mode, index);
|
|
327
|
+
if (r?.ok) setToast(t("stashInteractiveDone"));
|
|
328
|
+
else setError((r?.error) || t("stashInteractiveFail"));
|
|
329
|
+
}), [run, p.pty, t]);
|
|
330
|
+
|
|
331
|
+
// ── commit 详情卡 ──
|
|
332
|
+
const openCommit = useCallback((shaShort: string) => run(async () => {
|
|
333
|
+
setCommitSha(shaShort);
|
|
334
|
+
setCommitInfo(null);
|
|
335
|
+
setCommitLoadErr(null);
|
|
336
|
+
setCommitDiff(null);
|
|
337
|
+
setPickConflict(null);
|
|
338
|
+
setTagInput(false);
|
|
339
|
+
setTagName("");
|
|
340
|
+
const r = await api.commitShow(p.cwd, shaShort);
|
|
341
|
+
if (r.status !== 200) { setCommitLoadErr(r.data?.error ?? "HTTP " + r.status); return; }
|
|
342
|
+
setCommitInfo(r.data);
|
|
343
|
+
}), [run, api, p.cwd]);
|
|
344
|
+
|
|
345
|
+
const commitRef = () => String(commitInfo?.sha || commitSha || "");
|
|
346
|
+
const repoDir = () => String(refsData?.repo || p.cwd || "");
|
|
347
|
+
|
|
348
|
+
const openInReview = (opts?: { files?: string[] }) => {
|
|
349
|
+
const openSvc = p.extSvc?.("aiti-git-review.open") as ((o: any) => void) | undefined;
|
|
350
|
+
const workSvc = p.extSvc?.("aiti-git-review.work") as (() => void) | undefined;
|
|
351
|
+
if (!openSvc || !workSvc) return false;
|
|
352
|
+
const full = commitRef();
|
|
353
|
+
if (!full || commitInfo?.parents?.length === 0) return false; // root commit 无 base,交由选择器手选
|
|
354
|
+
openSvc({
|
|
355
|
+
path: repoDir(),
|
|
356
|
+
base: full + "^",
|
|
357
|
+
ref2: full,
|
|
358
|
+
...(opts?.files?.length ? { files: opts.files } : {}),
|
|
359
|
+
});
|
|
360
|
+
try { workSvc(); } catch { /* work 缺席时 open 已把状态置好,宿主打开工作区后生效 */ }
|
|
361
|
+
return true;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const atNewSession = async (text: string, targetDir: string) => {
|
|
365
|
+
await openNewSessionWithExtSvc({
|
|
366
|
+
text,
|
|
367
|
+
targetDir,
|
|
368
|
+
targetPath: targetDir,
|
|
369
|
+
currentCwd: p.cwd,
|
|
370
|
+
apiUrl: p.apiUrl,
|
|
371
|
+
extSvc: p.extSvc,
|
|
372
|
+
});
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
const copyText = useCallback(async (s: string, okMsg?: string) => {
|
|
376
|
+
try {
|
|
377
|
+
await navigator.clipboard.writeText(s);
|
|
378
|
+
} catch {
|
|
379
|
+
const ta = document.createElement("textarea");
|
|
380
|
+
ta.value = s;
|
|
381
|
+
ta.style.position = "fixed";
|
|
382
|
+
ta.style.opacity = "0";
|
|
383
|
+
document.body.appendChild(ta);
|
|
384
|
+
ta.select();
|
|
385
|
+
try { document.execCommand("copy"); } catch { /* 剪贴板不可用静默 */ }
|
|
386
|
+
ta.remove();
|
|
387
|
+
}
|
|
388
|
+
if (okMsg) setToast(okMsg);
|
|
389
|
+
}, []);
|
|
390
|
+
|
|
391
|
+
const submitTag = useCallback(() => run(async () => {
|
|
392
|
+
const name = tagName.trim();
|
|
393
|
+
if (!name || !commitRef()) return;
|
|
394
|
+
const r = await api.tagCreate(p.cwd, name, commitRef());
|
|
395
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return; }
|
|
396
|
+
setTagInput(false);
|
|
397
|
+
setTagName("");
|
|
398
|
+
setToast(t("commitTagDone", name));
|
|
399
|
+
afterWrite();
|
|
400
|
+
}), [run, tagName, api, p.cwd, afterWrite, t]);
|
|
401
|
+
|
|
402
|
+
const pickCommit = useCallback(() => run(async () => {
|
|
403
|
+
const r = await api.cherryPick(p.cwd, commitRef());
|
|
404
|
+
if (r.status === 409 && r.data?.conflict) { setPickConflict(r.data.files ?? []); return; }
|
|
405
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return; }
|
|
406
|
+
setToast(t("commitPickDone"));
|
|
407
|
+
afterWrite();
|
|
408
|
+
}), [run, api, p.cwd, afterWrite, t]);
|
|
409
|
+
|
|
410
|
+
const abortPick = useCallback(() => run(async () => {
|
|
411
|
+
const r = await api.cherryPick(p.cwd, "", { abort: true });
|
|
412
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return; }
|
|
413
|
+
setPickConflict(null);
|
|
414
|
+
afterWrite();
|
|
415
|
+
}), [run, api, p.cwd, afterWrite]);
|
|
416
|
+
|
|
417
|
+
const showCommitDiff = useCallback((path: string, oldPath?: string) => run(async () => {
|
|
418
|
+
setDiffLoading(true);
|
|
419
|
+
try {
|
|
420
|
+
const r = await api.commitDiff(p.cwd, commitRef(), oldPath ? [path, oldPath] : [path]);
|
|
421
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return; }
|
|
422
|
+
setCommitDiff({ path, oldPath, patch: r.data?.patch ?? "", truncated: !!r.data?.truncated });
|
|
423
|
+
} finally {
|
|
424
|
+
setDiffLoading(false);
|
|
425
|
+
}
|
|
426
|
+
}), [run, api, p.cwd]);
|
|
427
|
+
|
|
428
|
+
const absFile = (rel: string) => repoDir().replace(/\/+$/, "") + "/" + rel;
|
|
429
|
+
|
|
430
|
+
if (!p.open) return null;
|
|
431
|
+
|
|
432
|
+
const sectionHead = (key: string, label: React.ReactNode) => (
|
|
433
|
+
<div
|
|
434
|
+
onClick={() => toggleSection(key)}
|
|
435
|
+
style={{ fontSize: 10, fontWeight: 600, letterSpacing: "0.06em", textTransform: "uppercase" as const,
|
|
436
|
+
color: "var(--text-dim)", padding: "9px 12px 3px", cursor: "pointer", userSelect: "none" as const, display: "flex", alignItems: "center", gap: 4 }}
|
|
437
|
+
>
|
|
438
|
+
<span style={{ fontSize: 8, transform: collapsed.has(key) ? "none" : "rotate(90deg)", transition: "transform 0.15s" }}>▶</span>
|
|
439
|
+
{label}
|
|
440
|
+
</div>
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
const rowStyle = { display: "flex", alignItems: "center", gap: 7, padding: "4px 12px", fontSize: 12, cursor: "pointer", color: "var(--text)" } as const;
|
|
444
|
+
|
|
445
|
+
const filtered = (list: string[]) => {
|
|
446
|
+
const q = filter.trim().toLowerCase();
|
|
447
|
+
return q ? list.filter((x) => x.toLowerCase().includes(q)) : list;
|
|
448
|
+
};
|
|
449
|
+
const branches = filtered(refsData?.branches ?? []);
|
|
450
|
+
const tags = filtered(refsData?.tags ?? []);
|
|
451
|
+
const remotes = filtered(refsData?.remotes ?? []);
|
|
452
|
+
const showFilter = (refsData?.branches?.length ?? 0) + (refsData?.tags?.length ?? 0) >= 8;
|
|
453
|
+
const dirtyCount = refsData?.dirtyCount ?? 0;
|
|
454
|
+
|
|
455
|
+
return (
|
|
456
|
+
<div
|
|
457
|
+
ref={boxRef}
|
|
458
|
+
// aiti-float 浮窗契约(docs/aiti-web-ext-float-dialogs.md):大屏拖拽/缩放/移动/持久化 +
|
|
459
|
+
// 自动 ⛶ 最大化钮;小屏(≤640px)铺满视口。pos="asis" 首次在 chip 下出现;持久化后恢复。
|
|
460
|
+
data-ext-float="1"
|
|
461
|
+
data-ext-float-full="1"
|
|
462
|
+
data-ext-float-pos="asis"
|
|
463
|
+
data-ext-float-w={Math.min(PANEL_W, window.innerWidth - 16)}
|
|
464
|
+
data-ext-float-h={Math.round(Math.min(window.innerHeight * 0.62, 620))}
|
|
465
|
+
{...(p.floatKey ? { "data-ext-float-key": p.floatKey } : {})}
|
|
466
|
+
style={{
|
|
467
|
+
position: "fixed", zIndex: 1000,
|
|
468
|
+
left: pos ? pos.left : -99999, top: pos ? pos.top : -99999, width: Math.min(PANEL_W, window.innerWidth - 16),
|
|
469
|
+
height: "min(62vh, 620px)",
|
|
470
|
+
display: "flex", flexDirection: "column",
|
|
471
|
+
background: "var(--bg)", border: "1px solid var(--border)", borderRadius: 10,
|
|
472
|
+
boxShadow: "0 14px 36px color-mix(in srgb, var(--text) 14%, transparent)",
|
|
473
|
+
overflow: "hidden",
|
|
474
|
+
fontFamily: "inherit", textAlign: "left",
|
|
475
|
+
}}
|
|
476
|
+
>
|
|
477
|
+
{/* 当前态:分支 + 脏文件徽标(点击开部分暂存卡) */}
|
|
478
|
+
<div style={{ display: "flex", alignItems: "center", gap: 8, padding: "9px 12px", borderBottom: "1px solid var(--border)", flexShrink: 0 }}>
|
|
479
|
+
<span style={{ fontFamily: "var(--font-mono)", fontSize: 11.5, color: "var(--text)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>
|
|
480
|
+
⎇ {refsData?.current ?? (loadError ? t("noRepo") : t("loading"))}
|
|
481
|
+
</span>
|
|
482
|
+
{refsData?.aheadBehind ? (
|
|
483
|
+
<span style={{ fontSize: 10, color: "var(--text-dim)", fontFamily: "var(--font-mono)", flexShrink: 0 }}>↑{refsData.aheadBehind[0]} ↓{refsData.aheadBehind[1]}</span>
|
|
484
|
+
) : null}
|
|
485
|
+
<span style={{ flex: 1 }} />
|
|
486
|
+
{typeof dirtyCount === "number" && dirtyCount > 0 ? (
|
|
487
|
+
<button
|
|
488
|
+
type="button"
|
|
489
|
+
title={t("stashPartTitle")}
|
|
490
|
+
onClick={() => {
|
|
491
|
+
setPartOpen((v) => !v);
|
|
492
|
+
setPartChecked(new Set((refsData?.dirtyFiles ?? []).map((f: any) => f.path)));
|
|
493
|
+
}}
|
|
494
|
+
style={{ fontSize: 10, color: "var(--text)", background: "color-mix(in srgb, var(--accent) 12%, transparent)",
|
|
495
|
+
border: "1px solid color-mix(in srgb, var(--accent) 35%, transparent)", borderRadius: 5, padding: "1px 6px", cursor: "pointer", whiteSpace: "nowrap" as const, flexShrink: 0 }}
|
|
496
|
+
>
|
|
497
|
+
{t("dirty", dirtyCount)}
|
|
498
|
+
</button>
|
|
499
|
+
) : null}
|
|
500
|
+
<button type="button" title={t("close")} onClick={p.onClose}
|
|
501
|
+
style={{ border: "none", background: "none", color: "var(--text-dim)", cursor: "pointer", fontSize: 12, padding: "0 2px", flexShrink: 0 }}>✕</button>
|
|
502
|
+
</div>
|
|
503
|
+
|
|
504
|
+
{loadError ? (
|
|
505
|
+
<div style={{ padding: "14px 12px", fontSize: 11.5, color: "var(--text-muted)" }}>{loadError}</div>
|
|
506
|
+
) : !refsData ? (
|
|
507
|
+
<div style={{ padding: "14px 12px", fontSize: 11.5, color: "var(--text-muted)" }}>{t("loading")}</div>
|
|
508
|
+
) : (
|
|
509
|
+
<div style={{ flex: "1 1 auto", minHeight: 0, overflowY: "auto", overscrollBehavior: "contain" as const }}>
|
|
510
|
+
{/* worktree 模式开关 */}
|
|
511
|
+
<label style={{ display: "flex", alignItems: "center", gap: 8, padding: "7px 12px", fontSize: 11.5, color: "var(--text-muted)", borderBottom: "1px solid var(--border)", cursor: "pointer" }}
|
|
512
|
+
title={wtMode ? t("wtModeOn") : t("wtMode")}>
|
|
513
|
+
<input type="checkbox" checked={wtMode} onChange={(e) => {
|
|
514
|
+
setWtMode(e.target.checked);
|
|
515
|
+
try { localStorage.setItem("gitops.panel.wtMode", e.target.checked ? "1" : "0"); } catch { /* ignore */ }
|
|
516
|
+
}}
|
|
517
|
+
style={{ accentColor: "var(--accent)", margin: 0, flexShrink: 0 }} />
|
|
518
|
+
{t("wtMode")}
|
|
519
|
+
</label>
|
|
520
|
+
|
|
521
|
+
{/* 冲突三选一卡(覆盖正文,mockup ③) */}
|
|
522
|
+
{conflict ? (
|
|
523
|
+
<div style={{ padding: "10px 12px" }}>
|
|
524
|
+
<div style={{ fontSize: 12, fontWeight: 600, display: "flex", gap: 7, alignItems: "center" }}>
|
|
525
|
+
<span title="">⚠</span>{t("conflictTitle")} <span style={{ fontFamily: "var(--font-mono)" }}>{conflict.ref}</span>
|
|
526
|
+
</div>
|
|
527
|
+
<div style={{ fontSize: 11, color: "var(--text-muted)", margin: "5px 0 7px" }}>{t("conflictDesc", conflict.files.length)}</div>
|
|
528
|
+
<div style={{ background: "var(--bg-hover)", border: "1px solid var(--border)", borderRadius: 6, padding: "6px 9px",
|
|
529
|
+
fontFamily: "var(--font-mono)", fontSize: 10.5, color: "var(--text-muted)", display: "flex", flexDirection: "column", gap: 3, maxHeight: 96, overflowY: "auto" }}>
|
|
530
|
+
{conflict.files.map((f) => (
|
|
531
|
+
<span key={f} style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }}>{f}</span>
|
|
532
|
+
))}
|
|
533
|
+
</div>
|
|
534
|
+
<div style={{ display: "flex", flexDirection: "column", gap: 6, marginTop: 9 }}>
|
|
535
|
+
{p.onCreateWorktree ? (
|
|
536
|
+
<button type="button" disabled={busy} onClick={() => run(async () => { await openAsWorktree(conflict.ref); setConflict(null); })}
|
|
537
|
+
style={priBtn(busy)}>{t("conflictWt")}</button>
|
|
538
|
+
) : null}
|
|
539
|
+
<button type="button" disabled={busy} onClick={() => run(async () => {
|
|
540
|
+
const r = await api.checkout(p.cwd, conflict.ref, "stash-then-switch");
|
|
541
|
+
if (r.status !== 200) { setError(r.data?.error ?? "HTTP " + r.status); return; }
|
|
542
|
+
setConflict(null); afterWrite();
|
|
543
|
+
})} style={secBtn()}>{t("conflictStash")}</button>
|
|
544
|
+
<button type="button" onClick={() => setConflict(null)} style={ghostBtn()}>{t("cancel")}</button>
|
|
545
|
+
</div>
|
|
546
|
+
</div>
|
|
547
|
+
) : partOpen ? (
|
|
548
|
+
/* 部分暂存卡(mockup ③ 下) */
|
|
549
|
+
<div style={{ padding: "10px 12px" }}>
|
|
550
|
+
<div style={{ fontSize: 12, fontWeight: 600, display: "flex", alignItems: "center", gap: 7 }}>
|
|
551
|
+
{t("stashPartTitle")}
|
|
552
|
+
<span style={{ marginLeft: "auto", color: "var(--text-dim)", fontSize: 10, fontWeight: 400, fontFamily: "var(--font-mono)" }}>{t("stashPartHint")}</span>
|
|
553
|
+
</div>
|
|
554
|
+
<div style={{ marginTop: 7, display: "flex", flexDirection: "column", maxHeight: 180, overflowY: "auto" }}>
|
|
555
|
+
{(refsData?.dirtyFiles ?? []).map((f: any) => {
|
|
556
|
+
const on = partChecked?.has(f.path) ?? false;
|
|
557
|
+
return (
|
|
558
|
+
<label key={f.path} style={{ display: "flex", alignItems: "center", gap: 7, fontFamily: "var(--font-mono)", fontSize: 10.5, color: "var(--text-muted)", padding: "2.5px 0", cursor: "pointer" }}>
|
|
559
|
+
<input type="checkbox" checked={on} onChange={(e) => {
|
|
560
|
+
setPartChecked((prev) => {
|
|
561
|
+
const next = new Set(prev ?? []);
|
|
562
|
+
if (e.target.checked) next.add(f.path); else next.delete(f.path);
|
|
563
|
+
return next;
|
|
564
|
+
});
|
|
565
|
+
}} style={{ accentColor: "var(--accent)", margin: 0, flexShrink: 0 }} />
|
|
566
|
+
<span style={{ color: f.xy === "??" ? "var(--text-dim)" : "var(--text)", width: 20, flexShrink: 0 }}>{f.xy}</span>
|
|
567
|
+
<span style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }}>{f.path}</span>
|
|
568
|
+
</label>
|
|
569
|
+
);
|
|
570
|
+
})}
|
|
571
|
+
</div>
|
|
572
|
+
<div style={{ display: "flex", alignItems: "center", gap: 8, marginTop: 9 }}>
|
|
573
|
+
<button type="button" disabled={busy || !partChecked?.size} onClick={submitPartialStash} style={miniBtn(busy || !partChecked?.size)}>{t("stashPartBtn")}</button>
|
|
574
|
+
{p.pty?.available ? (
|
|
575
|
+
<button type="button" disabled={busy} onClick={() => stashInteractive("push")}
|
|
576
|
+
style={{ fontSize: 10.5, color: "var(--text-dim)", background: "none", border: "none", cursor: "pointer", padding: 0 }}>{t("stashInteractive")}</button>
|
|
577
|
+
) : null}
|
|
578
|
+
</div>
|
|
579
|
+
<div style={{ fontSize: 10, color: "var(--text-dim)", marginTop: 7 }}>{t("stashPartNote")};{t("stashExtractNote")}</div>
|
|
580
|
+
<button type="button" onClick={() => setPartOpen(false)} style={{ ...ghostBtn(), marginTop: 9, width: "100%" }}>{t("cancel")}</button>
|
|
581
|
+
</div>
|
|
582
|
+
) : (
|
|
583
|
+
<>
|
|
584
|
+
{showFilter && (
|
|
585
|
+
<div style={{ padding: "8px 12px 0", flexShrink: 0 }}>
|
|
586
|
+
<input value={filter} onChange={(e) => setFilter(e.target.value)} placeholder={t("filter")}
|
|
587
|
+
onKeyDown={(e) => { if (e.key === "Escape") { setFilter(""); } }}
|
|
588
|
+
style={{ width: "100%", height: 26, boxSizing: "border-box" as const, background: "var(--bg-hover)", border: "1px solid var(--border)", borderRadius: 6,
|
|
589
|
+
color: "var(--text)", fontSize: 11, padding: "0 9px", outline: "none" }} />
|
|
590
|
+
</div>
|
|
591
|
+
)}
|
|
592
|
+
|
|
593
|
+
{/* 分支 */}
|
|
594
|
+
{sectionHead("branches", t("branches"))}
|
|
595
|
+
{!collapsed.has("branches") && (
|
|
596
|
+
<div style={{ paddingBottom: 2 }}>
|
|
597
|
+
{branches.map((b) => {
|
|
598
|
+
const isCur = !refsData.detached && b === refsData.current;
|
|
599
|
+
return (
|
|
600
|
+
<div key={b} className="gitops-row" onClick={() => void onBranchRow(b)} style={rowStyle}>
|
|
601
|
+
{isCur
|
|
602
|
+
? <svg width="10" height="10" viewBox="0 0 10 10" fill="none" stroke="var(--accent)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" style={{ flexShrink: 0 }}><polyline points="1.5 5 4 7.5 8.5 2.5" /></svg>
|
|
603
|
+
: <span style={{ width: 10, flexShrink: 0 }} />}
|
|
604
|
+
<span style={{ fontFamily: "var(--font-mono)", fontSize: 11, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }}>{b}</span>
|
|
605
|
+
{isCur && <span style={{ marginLeft: "auto", color: "var(--text-dim)", fontSize: 10, flexShrink: 0 }}>{t("current")}</span>}
|
|
606
|
+
</div>
|
|
607
|
+
);
|
|
608
|
+
})}
|
|
609
|
+
{(refsData?.remotes?.length ?? 0) > 0 && (
|
|
610
|
+
<div onClick={() => setRemotesOpen((v) => !v)} style={{ ...rowStyle, color: "var(--text-muted)", fontSize: 11 }}>
|
|
611
|
+
<span style={{ width: 10, flexShrink: 0 }} />
|
|
612
|
+
{t("remotes", refsData.remotes.length)}
|
|
613
|
+
</div>
|
|
614
|
+
)}
|
|
615
|
+
{remotesOpen && remotes.map((b) => (
|
|
616
|
+
<div key={b} className="gitops-row" onClick={() => void onBranchRow(b, true)} style={{ ...rowStyle, paddingLeft: 28 }}>
|
|
617
|
+
<span style={{ fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--text-muted)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }}>{b}</span>
|
|
618
|
+
</div>
|
|
619
|
+
))}
|
|
620
|
+
</div>
|
|
621
|
+
)}
|
|
622
|
+
|
|
623
|
+
{/* Tag */}
|
|
624
|
+
{sectionHead("tags", t("tags"))}
|
|
625
|
+
{!collapsed.has("tags") && tags.map((tag) => (
|
|
626
|
+
<div key={tag} style={{ display: "flex", alignItems: "center" }}>
|
|
627
|
+
<div className="gitops-row" onClick={() => void onBranchRow(tag)} style={{ ...rowStyle, flex: 1, minWidth: 0 }}>
|
|
628
|
+
<span style={{ width: 10, flexShrink: 0 }} />
|
|
629
|
+
<span style={{ fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--text-muted)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }}>{tag}</span>
|
|
630
|
+
<span style={{ marginLeft: "auto", color: "var(--text-dim)", fontSize: 10, flexShrink: 0, paddingLeft: 8 }}>{t("tagCheckoutHint")}</span>
|
|
631
|
+
</div>
|
|
632
|
+
<button type="button" title={t("createFromRef")} onClick={(e) => { e.stopPropagation(); setCreateAt({ from: tag, suggested: "tag/" + tag.replace(/[^\w.-]+/g, "-") }); setCreateName("tag/" + tag.replace(/[^\w.-]+/g, "-")); }}
|
|
633
|
+
style={{ border: "none", background: "none", color: "var(--text-dim)", cursor: "pointer", fontSize: 11, padding: "4px 8px", flexShrink: 0 }}>⎘</button>
|
|
634
|
+
</div>
|
|
635
|
+
))}
|
|
636
|
+
|
|
637
|
+
{/* 新建分支 */}
|
|
638
|
+
{sectionHead("new", t("newBranch"))}
|
|
639
|
+
{!collapsed.has("new") && (
|
|
640
|
+
<div style={{ display: "flex", gap: 6, margin: "4px 12px 0" }}>
|
|
641
|
+
<input value={createAt?.from && createAt.from !== "HEAD" ? createName : createName} onChange={(e) => { setCreateName(e.target.value); setCreateAt((prev) => (prev ? { ...prev } : null)); }}
|
|
642
|
+
placeholder={t("newBranchPlaceholder")}
|
|
643
|
+
onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); void submitCreate(createAt?.from); } }}
|
|
644
|
+
style={{ flex: 1, minWidth: 0, height: 25, boxSizing: "border-box" as const, background: "var(--bg-hover)", border: "1px solid var(--border)", borderRadius: 6, color: "var(--text)", fontSize: 11, fontFamily: "var(--font-mono)", padding: "0 8px", outline: "none" }} />
|
|
645
|
+
<button type="button" disabled={busy || !createName.trim()} onClick={() => void submitCreate(createAt?.from)} style={miniBtn(busy || !createName.trim())}>
|
|
646
|
+
{wtMode ? t("createWt") : t("createCheckout")}
|
|
647
|
+
</button>
|
|
648
|
+
</div>
|
|
649
|
+
)}
|
|
650
|
+
{!collapsed.has("new") && createAt?.from && createAt.from !== "HEAD" ? (
|
|
651
|
+
<div style={{ fontSize: 10, color: "var(--text-dim)", margin: "3px 12px 0" }}>{t("from")}: <span style={{ fontFamily: "var(--font-mono)" }}>{createAt.from}</span>
|
|
652
|
+
<button type="button" onClick={() => { setCreateAt(null); setCreateName(""); }} style={{ border: "none", background: "none", color: "var(--text-dim)", cursor: "pointer", fontSize: 10, padding: "0 4px" }}>✕</button>
|
|
653
|
+
</div>
|
|
654
|
+
) : null}
|
|
655
|
+
|
|
656
|
+
{/* worktree */}
|
|
657
|
+
{/* worktree 分区:消费方提供宿主 worktree 回调才渲染(folder 无此面 → 整区隐藏) */}
|
|
658
|
+
{p.onCreateWorktree ? sectionHead("worktree", t("worktree")) : null}
|
|
659
|
+
{!collapsed.has("worktree") && p.onCreateWorktree ? (
|
|
660
|
+
<div style={{ paddingBottom: 2 }}>
|
|
661
|
+
{(p.worktrees ?? []).map((w) => {
|
|
662
|
+
const isCur = w.path === p.currentWorktreePath;
|
|
663
|
+
if (wtForceRemove === w.path) {
|
|
664
|
+
return (
|
|
665
|
+
<div key={w.path} style={{ display: "flex", alignItems: "center", gap: 6, padding: "6px 12px", background: "color-mix(in srgb, var(--text) 6%, transparent)", fontSize: 11 }}>
|
|
666
|
+
<span style={{ flex: 1, color: "var(--text-muted)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }}>{t("worktreeForceConfirm")}</span>
|
|
667
|
+
<button type="button" disabled={busy} onClick={() => void submitWtRemove(w.path, true)} style={miniBtn(busy)}>Force</button>
|
|
668
|
+
<button type="button" onClick={() => setWtForceRemove(null)} style={{ border: "1px solid var(--border)", background: "var(--bg-hover)", color: "var(--text-muted)", borderRadius: 5, fontSize: 11, padding: "3px 9px", cursor: "pointer" }}>{t("cancel")}</button>
|
|
669
|
+
</div>
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
return (
|
|
673
|
+
<div key={w.path} style={{ display: "flex", alignItems: "center" }}>
|
|
674
|
+
<div className="gitops-row" onClick={() => { p.onSelectWorktree?.(w.path); p.onClose(); }} title={w.path} style={{ ...rowStyle, flex: 1, minWidth: 0 }}>
|
|
675
|
+
<span style={{ color: isCur ? "var(--accent)" : "var(--text-dim)", fontSize: 10, flexShrink: 0 }}>●</span>
|
|
676
|
+
<span style={{ fontFamily: "var(--font-mono)", fontSize: 11, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }}>
|
|
677
|
+
{w.branch ?? w.path}{w.isMain ? ` · ${t("worktreeMain")}` : ""}
|
|
678
|
+
</span>
|
|
679
|
+
</div>
|
|
680
|
+
{!w.isMain && (
|
|
681
|
+
<button type="button" title={t("worktreeRemoveTitle")} onClick={() => void submitWtRemove(w.path, false)}
|
|
682
|
+
style={{ border: "none", background: "none", color: "var(--text-dim)", cursor: "pointer", fontSize: 11, padding: "4px 8px", flexShrink: 0 }}>✕</button>
|
|
683
|
+
)}
|
|
684
|
+
</div>
|
|
685
|
+
);
|
|
686
|
+
})}
|
|
687
|
+
{wtNewOpen ? (
|
|
688
|
+
<div style={{ display: "flex", gap: 6, margin: "4px 12px 6px" }}>
|
|
689
|
+
<input value={wtNewName} onChange={(e) => setWtNewName(e.target.value)} placeholder={t("worktreeBranchPlaceholder")} autoFocus
|
|
690
|
+
onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); void submitWtNew(); } if (e.key === "Escape") setWtNewOpen(false); }}
|
|
691
|
+
style={{ flex: 1, minWidth: 0, height: 25, boxSizing: "border-box" as const, background: "var(--bg-hover)", border: "1px solid var(--accent)", borderRadius: 6, color: "var(--text)", fontSize: 11, fontFamily: "var(--font-mono)", padding: "0 8px", outline: "none" }} />
|
|
692
|
+
<button type="button" disabled={busy || !wtNewName.trim()} onClick={() => void submitWtNew()} style={miniBtn(busy || !wtNewName.trim())}>{t("createWt")}</button>
|
|
693
|
+
</div>
|
|
694
|
+
) : (
|
|
695
|
+
<div className="gitops-row" onClick={() => setWtNewOpen(true)} style={{ ...rowStyle, color: "var(--text-muted)", fontSize: 11 }}>{t("newWorktree")}</div>
|
|
696
|
+
)}
|
|
697
|
+
</div>
|
|
698
|
+
) : null}
|
|
699
|
+
|
|
700
|
+
{/* stash */}
|
|
701
|
+
{sectionHead("stash", `${t("stash")}${stash.length ? ` (${stash.length})` : ""}`)}
|
|
702
|
+
{!collapsed.has("stash") && (
|
|
703
|
+
<div style={{ paddingBottom: 6 }}>
|
|
704
|
+
{stash.length === 0 && <div style={{ padding: "2px 12px 4px", fontSize: 11, color: "var(--text-dim)" }}>{t("stashEmpty")}</div>}
|
|
705
|
+
{stash.map((it: any, idxFromEnd: number) => {
|
|
706
|
+
const index = stash.length - 1 - idxFromEnd; // stash@{0} = 最新(列表首行)
|
|
707
|
+
const no = stash.length - 1 - idxFromEnd;
|
|
708
|
+
const files = stashFiles[index];
|
|
709
|
+
return (
|
|
710
|
+
<div key={it.sha + String(index)}>
|
|
711
|
+
<div style={{ display: "flex", alignItems: "center", gap: 7, padding: "4px 12px" }}>
|
|
712
|
+
<span className="gitops-row" onClick={() => void expandStash(index)} title={t("stashExpand")}
|
|
713
|
+
style={{ display: "flex", alignItems: "center", gap: 7, flex: 1, minWidth: 0, cursor: "pointer", fontSize: 12 }}>
|
|
714
|
+
<span style={{ fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--accent)", flexShrink: 0 }}>{`stash@{${no}}`}</span>
|
|
715
|
+
<span style={{ color: "var(--text-muted)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const, fontSize: 11 }}>{it.message}</span>
|
|
716
|
+
</span>
|
|
717
|
+
<button type="button" title={t("stashApply")} onClick={() => void stashAct(index)} style={iconBtn()}>↧</button>
|
|
718
|
+
<button type="button" title={t("stashPop")} onClick={() => void stashAct(index, { pop: true })} style={iconBtn()}>⤓</button>
|
|
719
|
+
<button type="button" title={t("stashDrop")} onClick={() => setDropConfirm(index)} style={iconBtn()}>✕</button>
|
|
720
|
+
</div>
|
|
721
|
+
{expandedStash === index && files ? (
|
|
722
|
+
<div style={{ margin: "2px 12px 6px", padding: "6px 9px", background: "var(--bg-hover)", border: "1px solid var(--border)", borderRadius: 6 }}>
|
|
723
|
+
<div style={{ maxHeight: 110, overflowY: "auto" }}>
|
|
724
|
+
{[...files.tracked.map((f) => ({ f, u: false })), ...files.untracked.map((f) => ({ f, u: true }))].map(({ f, u }) => {
|
|
725
|
+
const on = checkedExtract.has(f);
|
|
726
|
+
return (
|
|
727
|
+
<label key={f} style={{ display: "flex", alignItems: "center", gap: 7, fontFamily: "var(--font-mono)", fontSize: 10.5, color: "var(--text-muted)", padding: "2px 0", cursor: "pointer" }}>
|
|
728
|
+
<input type="checkbox" checked={on} onChange={(e) => {
|
|
729
|
+
setCheckedExtract((prev) => {
|
|
730
|
+
const next = new Set(prev);
|
|
731
|
+
if (e.target.checked) next.add(f); else next.delete(f);
|
|
732
|
+
return next;
|
|
733
|
+
});
|
|
734
|
+
}} style={{ accentColor: "var(--accent)", margin: 0, flexShrink: 0 }} />
|
|
735
|
+
<span style={{ color: u ? "var(--text-dim)" : "var(--text)", flexShrink: 0 }}>{u ? "??" : "M "}</span>
|
|
736
|
+
<span style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }}>{f}</span>
|
|
737
|
+
</label>
|
|
738
|
+
);
|
|
739
|
+
})}
|
|
740
|
+
</div>
|
|
741
|
+
<div style={{ display: "flex", alignItems: "center", gap: 8, marginTop: 6 }}>
|
|
742
|
+
<button type="button" disabled={busy || checkedExtract.size === 0} onClick={() => void extractChecked(index)} style={miniBtn(busy || checkedExtract.size === 0)}>{t("stashExtract")}</button>
|
|
743
|
+
{p.pty?.available ? (
|
|
744
|
+
<button type="button" disabled={busy} onClick={() => stashInteractive("apply", index)} style={{ fontSize: 10.5, color: "var(--text-dim)", background: "none", border: "none", cursor: "pointer", padding: 0 }}>{t("stashInteractive")}</button>
|
|
745
|
+
) : null}
|
|
746
|
+
</div>
|
|
747
|
+
<div style={{ fontSize: 10, color: "var(--text-dim)", marginTop: 5 }}>{t("stashExtractNote")}</div>
|
|
748
|
+
</div>
|
|
749
|
+
) : null}
|
|
750
|
+
{dropConfirm === index ? (
|
|
751
|
+
<div style={{ margin: "2px 12px 6px", padding: "8px 10px", background: "var(--bg-hover)", border: "1px solid var(--border)", borderRadius: 6 }}>
|
|
752
|
+
<div style={{ fontSize: 11.5, fontWeight: 600 }}>⚠ {t("dropConfirmTitle")}</div>
|
|
753
|
+
<div style={{ fontSize: 10.5, color: "var(--text-muted)", margin: "4px 0 8px", fontFamily: "var(--font-mono)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }}>
|
|
754
|
+
stash@{`{${index}}`} {it.sha} · {it.message}
|
|
755
|
+
</div>
|
|
756
|
+
<div style={{ fontSize: 10, color: "var(--text-dim)", marginBottom: 8 }}>{t("dropConfirmNote")}</div>
|
|
757
|
+
<div style={{ display: "flex", gap: 6 }}>
|
|
758
|
+
<button type="button" disabled={busy} onClick={() => void dropStash(index)} style={miniBtn(busy)}>{t("stashDrop")}</button>
|
|
759
|
+
<button type="button" onClick={() => setDropConfirm(null)} style={{ border: "1px solid var(--border)", background: "var(--bg-hover)", color: "var(--text-muted)", borderRadius: 5, fontSize: 11, padding: "3px 9px", cursor: "pointer" }}>{t("cancel")}</button>
|
|
760
|
+
</div>
|
|
761
|
+
</div>
|
|
762
|
+
) : null}
|
|
763
|
+
</div>
|
|
764
|
+
);
|
|
765
|
+
})}
|
|
766
|
+
</div>
|
|
767
|
+
)}
|
|
768
|
+
|
|
769
|
+
{/* 图谱 */}
|
|
770
|
+
{sectionHead("graph", t("graph"))}
|
|
771
|
+
{!collapsed.has("graph") && (
|
|
772
|
+
<div style={{ paddingBottom: 2 }}>
|
|
773
|
+
{log.lines.length === 0 && <div style={{ padding: "2px 12px 4px", fontSize: 11, color: "var(--text-dim)" }}>{t("graphEmpty")}</div>}
|
|
774
|
+
{log.lines.map((line, i) => {
|
|
775
|
+
const m = line.match(/^([*|\\/ ]+\s*)([0-9a-f]{7,})( .*)?$/);
|
|
776
|
+
if (!m) return <div key={i} style={{ ...graphLineStyle, opacity: 0.7 }}>{line}</div>;
|
|
777
|
+
const sha = m[2].slice(0, 7);
|
|
778
|
+
return (
|
|
779
|
+
<div key={i} className="gitops-row" onClick={() => void openCommit(sha)} title={t("commitView")}
|
|
780
|
+
style={{ ...graphLineStyle, cursor: "pointer" }}>
|
|
781
|
+
<span style={{ color: "var(--text-dim)" }}>{m[1]}</span>
|
|
782
|
+
<span style={{ color: "var(--accent)" }}>{sha}</span>
|
|
783
|
+
<span style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }}>{m[3] ?? ""}</span>
|
|
784
|
+
</div>
|
|
785
|
+
);
|
|
786
|
+
})}
|
|
787
|
+
{log.nextCursor != null && (
|
|
788
|
+
<button type="button" disabled={busy} onClick={() => void loadMoreLog()} style={{ display: "block", width: "100%", textAlign: "center" as const, padding: "5px 0", fontSize: 10, color: "var(--text-dim)", background: "none", border: "none", cursor: "pointer" }}>
|
|
789
|
+
{t("graphMore")}
|
|
790
|
+
</button>
|
|
791
|
+
)}
|
|
792
|
+
</div>
|
|
793
|
+
)}
|
|
794
|
+
</>
|
|
795
|
+
)}
|
|
796
|
+
</div>
|
|
797
|
+
)}
|
|
798
|
+
|
|
799
|
+
{/* commit 详情卡(图谱点行;查看/操作面,docs/aiti-git-ops-commit-card-plan.md;覆盖正文) */}
|
|
800
|
+
{commitSha && !conflict && !partOpen ? (
|
|
801
|
+
<div style={{ position: "absolute" as const, inset: 0, background: "var(--bg)", display: "flex", flexDirection: "column" }}>
|
|
802
|
+
{/* 头:返回 + sha/subject + 元信息 + 操作行 */}
|
|
803
|
+
<div style={{ padding: "8px 12px 8px", borderBottom: "1px solid var(--border)", flexShrink: 0, display: "flex", flexDirection: "column", gap: 6 }}>
|
|
804
|
+
<div style={{ display: "flex", alignItems: "center", gap: 6 }}>
|
|
805
|
+
<button type="button" title={t("commitBack")} onClick={() => setCommitSha(null)} style={iconBtn()}>←</button>
|
|
806
|
+
<span style={{ fontFamily: "var(--font-mono)", fontSize: 11.5, color: "var(--accent)", cursor: "pointer", flexShrink: 0 }}
|
|
807
|
+
title={t("commitCopySha")} onClick={() => void copyText(commitRef(), t("commitCopySha"))}>
|
|
808
|
+
{commitRef().slice(0, 9)}
|
|
809
|
+
</span>
|
|
810
|
+
<span style={{ flex: 1, minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const, fontSize: 11.5, color: "var(--text)" }}
|
|
811
|
+
title={commitInfo?.subject || undefined}>
|
|
812
|
+
{commitInfo?.subject ?? (commitLoadErr ? "" : "…")}
|
|
813
|
+
</span>
|
|
814
|
+
</div>
|
|
815
|
+
<div style={{ display: "flex", alignItems: "center", gap: 10, fontSize: 10, color: "var(--text-dim)", fontFamily: "var(--font-mono)", flexWrap: "wrap" as const }}>
|
|
816
|
+
{commitLoadErr ? <span style={{ color: "var(--text-muted)" }}>{t("commitLoadFail")}:{commitLoadErr}</span> : null}
|
|
817
|
+
{commitInfo ? <span>{commitInfo.author} · {String(commitInfo.date || "").slice(0, 10)}</span> : null}
|
|
818
|
+
{commitInfo?.merge ? <span>{t("commitMergeNote", String(commitInfo.parents?.[0] || "").slice(0, 8))}</span> : null}
|
|
819
|
+
</div>
|
|
820
|
+
<div style={{ display: "flex", flexWrap: "wrap" as const, gap: 5 }}>
|
|
821
|
+
<button type="button" disabled={busy} title={t("createAt")} onClick={() => { setCreateAt({ from: commitRef() }); setCreateName(""); }} style={chipBtn()}>{t("commitBranch")}</button>
|
|
822
|
+
<button type="button" disabled={busy} onClick={() => { setTagInput((v) => !v); setTagName(""); }} style={chipBtn()}>{t("commitTag")}</button>
|
|
823
|
+
{!wtMode ? (
|
|
824
|
+
<button type="button" disabled={busy} title={t("commitCheckoutTitle")} onClick={() => void switchTo(commitRef())} style={chipBtn()}>{t("commitCheckout")}</button>
|
|
825
|
+
) : null}
|
|
826
|
+
<button type="button" disabled={busy} title={t("commitPickTitle")} onClick={() => void pickCommit()} style={chipBtn()}>{t("commitPick")}</button>
|
|
827
|
+
{p.extSvc ? (
|
|
828
|
+
<button type="button" disabled={busy} title={t("commitReviewTitle")} onClick={() => { openInReview(); }} style={chipBtn()}>{t("commitReview")}</button>
|
|
829
|
+
) : null}
|
|
830
|
+
<button type="button" disabled={busy} title={t("commitAtNewTitle")} onClick={() => {
|
|
831
|
+
const s = commitInfo?.subject ? `(${commitInfo.subject})` : "";
|
|
832
|
+
void atNewSession(`请解读 commit ${commitRef()}${s} 的改动`, repoDir());
|
|
833
|
+
}} style={chipBtn()}>{t("commitAtNew")}</button>
|
|
834
|
+
</div>
|
|
835
|
+
{tagInput ? (
|
|
836
|
+
<div style={{ display: "flex", gap: 6 }}>
|
|
837
|
+
<input autoFocus value={tagName} onChange={(e) => setTagName(e.target.value)} placeholder={t("commitTagPlaceholder")}
|
|
838
|
+
onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); void submitTag(); } if (e.key === "Escape") setTagInput(false); }}
|
|
839
|
+
style={{ flex: 1, minWidth: 0, height: 25, boxSizing: "border-box" as const, background: "var(--bg-hover)", border: "1px solid var(--accent)", borderRadius: 6, color: "var(--text)", fontSize: 11, fontFamily: "var(--font-mono)", padding: "0 8px", outline: "none" }} />
|
|
840
|
+
<button type="button" disabled={busy || !tagName.trim()} onClick={() => void submitTag()} style={miniBtn(busy || !tagName.trim())}>✓</button>
|
|
841
|
+
</div>
|
|
842
|
+
) : null}
|
|
843
|
+
{pickConflict ? (
|
|
844
|
+
<div style={{ padding: "6px 8px", background: "color-mix(in srgb, var(--text) 6%, transparent)", border: "1px solid var(--border)", borderRadius: 6 }}>
|
|
845
|
+
<div style={{ fontSize: 10.5, color: "var(--text)" }}>{t("commitPickConflict")}</div>
|
|
846
|
+
<div style={{ margin: "4px 0 6px", display: "flex", flexDirection: "column", maxHeight: 72, overflowY: "auto", fontFamily: "var(--font-mono)", fontSize: 10, color: "var(--text-muted)" }}>
|
|
847
|
+
{pickConflict.map((f) => <span key={f} style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }}>{f}</span>)}
|
|
848
|
+
</div>
|
|
849
|
+
<button type="button" disabled={busy} title={t("commitPickAbortTitle")} onClick={() => void abortPick()} style={miniBtn(busy)}>{t("commitPickAbort")}</button>
|
|
850
|
+
</div>
|
|
851
|
+
) : null}
|
|
852
|
+
</div>
|
|
853
|
+
{/* 正文:单文件 diff 视图 / 变更文件清单 */}
|
|
854
|
+
{commitDiff ? (
|
|
855
|
+
<div style={{ flex: "1 1 auto", minHeight: 0, display: "flex", flexDirection: "column" }}>
|
|
856
|
+
<div style={{ display: "flex", alignItems: "center", gap: 5, padding: "5px 12px", borderBottom: "1px solid var(--border)", flexShrink: 0 }}>
|
|
857
|
+
<button type="button" title={t("commitBack")} onClick={() => setCommitDiff(null)} style={iconBtn()}>←</button>
|
|
858
|
+
<span style={{ flex: 1, minWidth: 0, fontFamily: "var(--font-mono)", fontSize: 10.5, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const }} title={commitDiff.oldPath ? `${commitDiff.oldPath} → ${commitDiff.path}` : commitDiff.path}>
|
|
859
|
+
{commitDiff.oldPath ? `${commitDiff.oldPath} → ${commitDiff.path}` : commitDiff.path}
|
|
860
|
+
</span>
|
|
861
|
+
<button type="button" title={t("commitCopyPath")} onClick={() => void copyText(absFile(commitDiff.path))} style={iconBtn()}>⎘</button>
|
|
862
|
+
{p.openFile ? (
|
|
863
|
+
<button type="button" title={t("commitOpenFile")} onClick={() => p.openFile?.(absFile(commitDiff.path))} style={iconBtn()}>↗</button>
|
|
864
|
+
) : null}
|
|
865
|
+
<button type="button" title={t("commitAtFile")} onClick={() => {
|
|
866
|
+
const abs = absFile(commitDiff.path);
|
|
867
|
+
void atNewSession(buildAtText(abs), abs);
|
|
868
|
+
}} style={iconBtn()}>@</button>
|
|
869
|
+
{p.extSvc ? (
|
|
870
|
+
<button type="button" title={t("commitReviewFile")} onClick={() => { openInReview({ files: commitDiff.oldPath ? [commitDiff.path, commitDiff.oldPath] : [commitDiff.path] }); }} style={iconBtn()}>👁</button>
|
|
871
|
+
) : null}
|
|
872
|
+
</div>
|
|
873
|
+
<pre style={{ flex: "1 1 auto", minHeight: 0, overflow: "auto", margin: 0, padding: "6px 0 10px", fontFamily: "var(--font-mono)", fontSize: 10, lineHeight: 1.45, whiteSpace: "pre" as const }}>
|
|
874
|
+
{commitDiff.patch.split("\n").map((ln, i) => (
|
|
875
|
+
<div key={i} style={{
|
|
876
|
+
padding: "0 12px",
|
|
877
|
+
color: ln.startsWith("+") && !ln.startsWith("+++") ? "var(--ok, var(--accent))"
|
|
878
|
+
: ln.startsWith("-") && !ln.startsWith("---") ? "var(--danger, var(--text-muted))"
|
|
879
|
+
: ln.startsWith("@@") || ln.startsWith("diff ") || ln.startsWith("index ") ? "var(--text-dim)"
|
|
880
|
+
: "var(--text-muted)",
|
|
881
|
+
background: ln.startsWith("+") && !ln.startsWith("+++") ? "color-mix(in srgb, var(--ok, var(--accent)) 10%, transparent)"
|
|
882
|
+
: ln.startsWith("-") && !ln.startsWith("---") ? "color-mix(in srgb, var(--danger, var(--text-muted)) 10%, transparent)"
|
|
883
|
+
: undefined,
|
|
884
|
+
}}>{ln || " "}</div>
|
|
885
|
+
))}
|
|
886
|
+
</pre>
|
|
887
|
+
{commitDiff.truncated ? (
|
|
888
|
+
<div style={{ padding: "4px 12px 8px", fontSize: 10, color: "var(--text-dim)", flexShrink: 0 }}>{t("commitDiffTruncated")}</div>
|
|
889
|
+
) : null}
|
|
890
|
+
</div>
|
|
891
|
+
) : (
|
|
892
|
+
<div style={{ flex: "1 1 auto", minHeight: 0, overflowY: "auto", overscrollBehavior: "contain" as const }}>
|
|
893
|
+
<div style={{ padding: "7px 12px 3px", fontSize: 10, fontWeight: 600, letterSpacing: "0.06em", textTransform: "uppercase" as const, color: "var(--text-dim)", display: "flex", alignItems: "baseline", gap: 8 }}>
|
|
894
|
+
<span style={{ flexShrink: 0 }}>{commitInfo ? t("commitFiles", commitInfo.files?.length ?? 0) : "…"}</span>
|
|
895
|
+
{commitInfo ? (
|
|
896
|
+
<span style={{ fontWeight: 400, textTransform: "none" as const, letterSpacing: 0, fontFamily: "var(--font-mono)" }}>
|
|
897
|
+
+{commitInfo.additions ?? 0} / −{commitInfo.deletions ?? 0}
|
|
898
|
+
</span>
|
|
899
|
+
) : null}
|
|
900
|
+
</div>
|
|
901
|
+
{(commitInfo?.files ?? []).map((f: any) => (
|
|
902
|
+
<div key={f.path} className="gitops-row" onClick={() => void showCommitDiff(f.path, f.oldPath)} title={t("commitFileDiffTitle")}
|
|
903
|
+
style={{ display: "flex", alignItems: "center", gap: 7, padding: "3.5px 12px", fontSize: 11, cursor: "pointer" }}>
|
|
904
|
+
<span style={{ width: 12, flexShrink: 0, fontFamily: "var(--font-mono)", color: f.status === "A" ? "var(--ok, var(--accent))" : f.status === "D" ? "var(--danger, var(--text-muted))" : "var(--text-dim)" }}>{f.status}</span>
|
|
905
|
+
<span style={{ flex: 1, minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" as const, fontFamily: "var(--font-mono)", color: "var(--text)" }} title={f.oldPath ? `${f.oldPath} → ${f.path}` : f.path}>
|
|
906
|
+
{f.oldPath ? `${f.path} ← ${f.oldPath}` : f.path}
|
|
907
|
+
</span>
|
|
908
|
+
<span style={{ flexShrink: 0, fontFamily: "var(--font-mono)", fontSize: 10, color: "var(--text-dim)" }}>
|
|
909
|
+
{f.additions ? `+${f.additions}` : ""}{f.deletions ? ` −${f.deletions}` : ""}
|
|
910
|
+
</span>
|
|
911
|
+
</div>
|
|
912
|
+
))}
|
|
913
|
+
{commitInfo && (commitInfo.files?.length ?? 0) === 0 ? (
|
|
914
|
+
<div style={{ padding: "4px 12px", fontSize: 11, color: "var(--text-dim)" }}>—</div>
|
|
915
|
+
) : null}
|
|
916
|
+
</div>
|
|
917
|
+
)}
|
|
918
|
+
</div>
|
|
919
|
+
) : null}
|
|
920
|
+
|
|
921
|
+
{/* commit 建分支卡(图谱/tag 入口;覆盖正文;渲染在详情卡之后 = 叠其上,取消回到详情卡) */}
|
|
922
|
+
{createAt && !conflict && !partOpen ? (
|
|
923
|
+
<div style={{ position: "absolute" as const, inset: 0, background: "var(--bg)", padding: "12px", display: "flex", flexDirection: "column", gap: 8 }}>
|
|
924
|
+
<div style={{ fontSize: 12, fontWeight: 600 }}>{t("createAt")}</div>
|
|
925
|
+
<div style={{ fontSize: 10.5, color: "var(--text-muted)" }}>{t("from")}: <span style={{ fontFamily: "var(--font-mono)" }}>{createAt.from}</span></div>
|
|
926
|
+
<input value={createName} onChange={(e) => setCreateName(e.target.value)} placeholder={t("newBranchPlaceholder")} autoFocus
|
|
927
|
+
onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); void submitCreate(createAt.from); } if (e.key === "Escape") setCreateAt(null); }}
|
|
928
|
+
style={{ height: 27, boxSizing: "border-box" as const, background: "var(--bg-hover)", border: "1px solid var(--accent)", borderRadius: 6, color: "var(--text)", fontSize: 11, fontFamily: "var(--font-mono)", padding: "0 8px", outline: "none" }} />
|
|
929
|
+
<div style={{ display: "flex", gap: 6 }}>
|
|
930
|
+
<button type="button" disabled={busy || !createName.trim()} onClick={() => void submitCreate(createAt.from)} style={{ ...miniBtn(busy || !createName.trim()), flex: 1 }}>
|
|
931
|
+
{wtMode ? t("createWt") : t("createCheckout")}
|
|
932
|
+
</button>
|
|
933
|
+
<button type="button" onClick={() => setCreateAt(null)} style={{ border: "1px solid var(--border)", background: "var(--bg-hover)", color: "var(--text-muted)", borderRadius: 5, fontSize: 11, padding: "3px 9px", cursor: "pointer" }}>{t("cancel")}</button>
|
|
934
|
+
</div>
|
|
935
|
+
</div>
|
|
936
|
+
) : null}
|
|
937
|
+
|
|
938
|
+
{error ? (
|
|
939
|
+
<div style={{ padding: "6px 12px 8px", fontSize: 11, color: "var(--text)", background: "color-mix(in srgb, var(--text) 6%, transparent)", borderTop: "1px solid var(--border)", overflowWrap: "anywhere" as const, flexShrink: 0 }}>
|
|
940
|
+
{t("errPrefix")}:{error}
|
|
941
|
+
<button type="button" onClick={() => setError(null)} style={{ border: "none", background: "none", color: "var(--text-dim)", cursor: "pointer", fontSize: 11, padding: "0 4px" }}>✕</button>
|
|
942
|
+
</div>
|
|
943
|
+
) : null}
|
|
944
|
+
{toast ? (
|
|
945
|
+
<div style={{ padding: "6px 12px 8px", fontSize: 11, color: "var(--text-muted)", borderTop: "1px solid var(--border)", flexShrink: 0, display: "flex", alignItems: "center", gap: 6 }}>
|
|
946
|
+
<span style={{ flex: 1 }}>{toast}</span>
|
|
947
|
+
<button type="button" onClick={() => setToast(null)} style={{ border: "none", background: "none", color: "var(--text-dim)", cursor: "pointer", fontSize: 11, padding: 0 }}>✕</button>
|
|
948
|
+
</div>
|
|
949
|
+
) : null}
|
|
950
|
+
</div>
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/* ── 按钮样式(全部 var 基色)── */
|
|
955
|
+
const priBtn = (busy: boolean) => ({
|
|
956
|
+
height: 27, borderRadius: 7, display: "flex", alignItems: "center", justifyContent: "center", gap: 6,
|
|
957
|
+
fontSize: 11.5, cursor: busy ? "not-allowed" : "pointer", fontWeight: 600,
|
|
958
|
+
background: "var(--accent)", color: "var(--bg)", border: "1px solid var(--accent)", opacity: busy ? 0.6 : 1,
|
|
959
|
+
} as const);
|
|
960
|
+
const secBtn = () => ({
|
|
961
|
+
height: 27, borderRadius: 7, display: "flex", alignItems: "center", justifyContent: "center", gap: 6,
|
|
962
|
+
fontSize: 11.5, cursor: "pointer", background: "var(--bg-hover)", color: "var(--text)", border: "1px solid var(--border)",
|
|
963
|
+
} as const);
|
|
964
|
+
const ghostBtn = () => ({
|
|
965
|
+
height: 27, borderRadius: 7, display: "flex", alignItems: "center", justifyContent: "center",
|
|
966
|
+
fontSize: 11.5, cursor: "pointer", background: "none", color: "var(--text-dim)", border: "none",
|
|
967
|
+
} as const);
|
|
968
|
+
const miniBtn = (disabled?: boolean) => ({
|
|
969
|
+
height: 25, padding: "0 10px", borderRadius: 6, background: "var(--accent)", color: "var(--bg)",
|
|
970
|
+
fontSize: 10.5, display: "inline-flex", alignItems: "center", whiteSpace: "nowrap" as const,
|
|
971
|
+
border: "1px solid var(--accent)", cursor: disabled ? "not-allowed" : "pointer", opacity: disabled ? 0.6 : 1,
|
|
972
|
+
} as const);
|
|
973
|
+
const iconBtn = () => ({
|
|
974
|
+
border: "none", background: "none", color: "var(--text-dim)", cursor: "pointer", fontSize: 11,
|
|
975
|
+
padding: "2px 3px", flexShrink: 0,
|
|
976
|
+
} as const);
|
|
977
|
+
/** commit 卡操作行小按钮(轻量 chip:描边 + var 基色,主题硬条款合规) */
|
|
978
|
+
const chipBtn = (disabled?: boolean) => ({
|
|
979
|
+
height: 22, padding: "0 8px", borderRadius: 6, display: "inline-flex", alignItems: "center", gap: 4,
|
|
980
|
+
fontSize: 10.5, whiteSpace: "nowrap" as const, flexShrink: 0,
|
|
981
|
+
background: "var(--bg-hover)", color: "var(--text)", border: "1px solid var(--border)",
|
|
982
|
+
cursor: disabled ? "not-allowed" : "pointer", opacity: disabled ? 0.55 : 1,
|
|
983
|
+
} as const);
|
|
984
|
+
const graphLineStyle = {
|
|
985
|
+
display: "flex", gap: 7, padding: "2.5px 12px", fontFamily: "var(--font-mono)", fontSize: 10.5,
|
|
986
|
+
color: "var(--text-muted)", overflow: "hidden",
|
|
987
|
+
} as const;
|