agy-git-graph 1.0.0 → 1.2.0
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 +2 -2
- package/package.json +1 -1
- package/plugin.json +2 -2
- package/sidecars/git_graph/index.html +108 -33
- package/sidecars/git_graph/lib/cdp-sidebar.mjs +306 -0
- package/sidecars/git_graph/lib/render.mjs +36 -0
- package/sidecars/git_graph/server.mjs +4 -28
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/agy-git-graph)
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
|
|
6
|
-
在 **Google Antigravity 2.0**
|
|
6
|
+
在 **Google Antigravity 2.0** 左侧主导航栏(`Codex 同步` / `Powertools` 下方)挂载一键快捷按钮 **Git Graph**:点击后保留当前工作会话,自动展开/收起右侧官方 `Git` 侧边栏,支持查看工作区更改、快捷提交、Diff 预览与多分支 SVG 可视化提交图(Commit Graph),零外部 npm 依赖。
|
|
7
7
|
|
|
8
|
-
A lightweight, zero-dependency Git
|
|
8
|
+
A lightweight, zero-dependency Git plugin for **Google Antigravity 2.0** that mounts a 1-click **Git Graph** quick-launch button in the left navigation bar to toggle the right-hand `Git` sidecar panel alongside your conversation, providing working-tree changes, quick commits, colored diffs, branch filtering, and a multi-branch SVG commit graph.
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agy-git-graph",
|
|
3
3
|
"displayName": "Git Graph (提交图)",
|
|
4
|
-
"version": "1.
|
|
5
|
-
"description": "在 Antigravity
|
|
4
|
+
"version": "1.2.0",
|
|
5
|
+
"description": "在 Antigravity 左侧导航栏挂载一键快捷按钮,点击保留当前会话并弹出/收起右侧 Git 面板:查看工作区更改、提交代码、按分支筛选并浏览多分支可视化提交图与单次提交 Diff。",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "s17765152890-gif",
|
|
8
8
|
"url": "https://github.com/s17765152890-gif"
|
|
@@ -7,21 +7,85 @@
|
|
|
7
7
|
<style>
|
|
8
8
|
:root {
|
|
9
9
|
color-scheme: dark;
|
|
10
|
-
--bg: #0f0f11;
|
|
11
|
-
--surface: #141416;
|
|
12
|
-
--surface-2: #1b1b1e;
|
|
13
|
-
--
|
|
14
|
-
--
|
|
15
|
-
--
|
|
10
|
+
--bg: var(--color-background-primary, #0f0f11);
|
|
11
|
+
--surface: var(--color-background-secondary, #141416);
|
|
12
|
+
--surface-2: var(--color-background-tertiary, #1b1b1e);
|
|
13
|
+
--hover-bg: #29292e;
|
|
14
|
+
--even-row: #121214;
|
|
15
|
+
--active-row: #222331;
|
|
16
|
+
--border: var(--color-border-primary, rgba(255,255,255,0.08));
|
|
17
|
+
--drawer-border: #35353d;
|
|
18
|
+
--text: var(--color-text-primary, #ededef);
|
|
19
|
+
--text-secondary: var(--color-text-secondary, #a1a1aa);
|
|
16
20
|
--muted: #71717a;
|
|
17
|
-
--ui-font-default: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei UI", sans-serif;
|
|
21
|
+
--ui-font-default: var(--font-sans, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei UI", sans-serif);
|
|
18
22
|
--ui-font: var(--ui-font-default);
|
|
19
23
|
--ui-font-weight: 400;
|
|
20
24
|
--mono: "Cascadia Code", Consolas, monospace;
|
|
21
25
|
--accent: #a5b4fc;
|
|
26
|
+
--branch-bg: #1c1d2c;
|
|
27
|
+
--branch-mark: #818cf8;
|
|
28
|
+
--primary-bg: #4f46b6;
|
|
29
|
+
--primary-hover: #6057d2;
|
|
30
|
+
--primary-border: #6b61df;
|
|
31
|
+
--primary-text: #ffffff;
|
|
22
32
|
--green: #86efac;
|
|
33
|
+
--green-bg: #162820;
|
|
23
34
|
--red: #fda4af;
|
|
35
|
+
--red-bg: #311b23;
|
|
36
|
+
--red-border: #723545;
|
|
24
37
|
--amber: #fcd34d;
|
|
38
|
+
--amber-bg: #282117;
|
|
39
|
+
--info-fg: #7dd3fc;
|
|
40
|
+
--info-bg: #132534;
|
|
41
|
+
--hunk-fg: #a5b4fc;
|
|
42
|
+
--hunk-bg: #1c2036;
|
|
43
|
+
--ref-head-fg: #a7f3d0;
|
|
44
|
+
--ref-head-bg: #15352d;
|
|
45
|
+
--ref-local-fg: #bae6fd;
|
|
46
|
+
--ref-local-bg: #153045;
|
|
47
|
+
--ref-remote-fg: #cbd5e1;
|
|
48
|
+
--ref-remote-border: #374151;
|
|
49
|
+
--ref-tag-bg: #392b15;
|
|
50
|
+
}
|
|
51
|
+
:root[data-theme="light"] {
|
|
52
|
+
color-scheme: light;
|
|
53
|
+
--bg: var(--color-background-primary, #faf8f5);
|
|
54
|
+
--surface: var(--color-background-secondary, #f3efe8);
|
|
55
|
+
--surface-2: var(--color-background-tertiary, #eae4da);
|
|
56
|
+
--hover-bg: #e1d9cc;
|
|
57
|
+
--even-row: #f5f1ea;
|
|
58
|
+
--active-row: #e6e9f8;
|
|
59
|
+
--border: var(--color-border-primary, rgba(24,24,27,0.12));
|
|
60
|
+
--drawer-border: rgba(24,24,27,0.2);
|
|
61
|
+
--text: var(--color-text-primary, #1f1f23);
|
|
62
|
+
--text-secondary: var(--color-text-secondary, #57534e);
|
|
63
|
+
--muted: #78716c;
|
|
64
|
+
--accent: #4338ca;
|
|
65
|
+
--branch-bg: #e5e7fb;
|
|
66
|
+
--branch-mark: #4f46e5;
|
|
67
|
+
--primary-bg: #4338ca;
|
|
68
|
+
--primary-hover: #3730a3;
|
|
69
|
+
--primary-border: #3730a3;
|
|
70
|
+
--primary-text: #ffffff;
|
|
71
|
+
--green: #15803d;
|
|
72
|
+
--green-bg: #dcfce7;
|
|
73
|
+
--red: #be123c;
|
|
74
|
+
--red-bg: #ffe4e6;
|
|
75
|
+
--red-border: #fda4af;
|
|
76
|
+
--amber: #b45309;
|
|
77
|
+
--amber-bg: #fef3c7;
|
|
78
|
+
--info-fg: #0369a1;
|
|
79
|
+
--info-bg: #e0f2fe;
|
|
80
|
+
--hunk-fg: #4338ca;
|
|
81
|
+
--hunk-bg: #e0e7ff;
|
|
82
|
+
--ref-head-fg: #047857;
|
|
83
|
+
--ref-head-bg: #d1fae5;
|
|
84
|
+
--ref-local-fg: #0369a1;
|
|
85
|
+
--ref-local-bg: #e0f2fe;
|
|
86
|
+
--ref-remote-fg: #475569;
|
|
87
|
+
--ref-remote-border: #cbd5e1;
|
|
88
|
+
--ref-tag-bg: #fef3c7;
|
|
25
89
|
}
|
|
26
90
|
/*__POWERTOOLS_FONT_CSS__*/
|
|
27
91
|
* { box-sizing: border-box; }
|
|
@@ -36,7 +100,7 @@
|
|
|
36
100
|
min-width: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2);
|
|
37
101
|
}
|
|
38
102
|
button { cursor: pointer; padding: 3px 8px; }
|
|
39
|
-
button:hover:not(:disabled) { background:
|
|
103
|
+
button:hover:not(:disabled) { background: var(--hover-bg); }
|
|
40
104
|
button:disabled { opacity: .45; cursor: default; }
|
|
41
105
|
button:focus-visible, input:focus-visible, select:focus-visible,
|
|
42
106
|
textarea:focus-visible, summary:focus-visible, [role="separator"]:focus-visible {
|
|
@@ -55,9 +119,9 @@
|
|
|
55
119
|
#repos { flex: 1 1 105px; width: 0; }
|
|
56
120
|
.branch {
|
|
57
121
|
max-width: 44%; padding: 3px 7px; display: flex; gap: 5px; align-items: center;
|
|
58
|
-
color: var(--accent); background:
|
|
122
|
+
color: var(--accent); background: var(--branch-bg); border-radius: 5px;
|
|
59
123
|
}
|
|
60
|
-
.branch-mark { color:
|
|
124
|
+
.branch-mark { color: var(--branch-mark); flex: none; }
|
|
61
125
|
#branchCounts { color: var(--text-secondary); flex: none; white-space: nowrap; }
|
|
62
126
|
.repo-form {
|
|
63
127
|
display: flex; align-items: center; gap: 5px; padding: 7px 10px;
|
|
@@ -65,7 +129,7 @@
|
|
|
65
129
|
}
|
|
66
130
|
.repo-form input { flex: 1; }
|
|
67
131
|
.notice { padding: 5px 10px; color: var(--text-secondary); overflow-wrap: anywhere; max-height: 6em; overflow: auto; }
|
|
68
|
-
.notice[data-error="true"] { color: var(--red); background:
|
|
132
|
+
.notice[data-error="true"] { color: var(--red); background: var(--red-bg); }
|
|
69
133
|
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
|
|
70
134
|
.section-bar, .history-bar {
|
|
71
135
|
display: flex; align-items: center; gap: 6px; flex: none;
|
|
@@ -90,10 +154,10 @@
|
|
|
90
154
|
}
|
|
91
155
|
.commit-form textarea::placeholder, input::placeholder { color: var(--text-secondary); }
|
|
92
156
|
.primary {
|
|
93
|
-
background:
|
|
94
|
-
align-self: stretch; min-height: 27px;
|
|
157
|
+
background: var(--primary-bg); border-color: var(--primary-border); color: var(--primary-text);
|
|
158
|
+
font-weight: 650; align-self: stretch; min-height: 27px;
|
|
95
159
|
}
|
|
96
|
-
.primary:hover:not(:disabled) { background:
|
|
160
|
+
.primary:hover:not(:disabled) { background: var(--primary-hover); }
|
|
97
161
|
.change-header {
|
|
98
162
|
display: flex; align-items: center; justify-content: space-between;
|
|
99
163
|
gap: 4px; padding: 3px 10px; border-top: 1px solid var(--border);
|
|
@@ -112,23 +176,23 @@
|
|
|
112
176
|
.file-name { flex: 0 1 auto; }
|
|
113
177
|
.file-status {
|
|
114
178
|
display: grid; place-items: center; flex: 0 0 16px; height: 16px; border-radius: 4px;
|
|
115
|
-
color: var(--amber); background:
|
|
179
|
+
color: var(--amber); background: var(--amber-bg); font: 10px var(--mono);
|
|
116
180
|
}
|
|
117
|
-
.file-status[data-status="A"], .file-status[data-status="?"] { color: var(--green); background:
|
|
118
|
-
.file-status[data-status="D"], .file-status[data-status="U"] { color: var(--red); background:
|
|
119
|
-
.file-status[data-status="R"], .file-status[data-status="C"] { color:
|
|
181
|
+
.file-status[data-status="A"], .file-status[data-status="?"] { color: var(--green); background: var(--green-bg); }
|
|
182
|
+
.file-status[data-status="D"], .file-status[data-status="U"] { color: var(--red); background: var(--red-bg); }
|
|
183
|
+
.file-status[data-status="R"], .file-status[data-status="C"] { color: var(--info-fg); background: var(--info-bg); }
|
|
120
184
|
.row-actions { display: flex; align-items: center; flex: none; opacity: 0; }
|
|
121
185
|
.change-row:hover .row-actions, .change-row:focus-within .row-actions,
|
|
122
186
|
.row-actions:has(.confirm) { opacity: 1; }
|
|
123
187
|
@media (hover: none) { .row-actions { opacity: 1; } }
|
|
124
188
|
.row-actions button { height: 23px; min-width: 22px; padding: 0 4px; }
|
|
125
|
-
.row-actions .confirm { color: var(--red); border-color:
|
|
189
|
+
.row-actions .confirm { color: var(--red); border-color: var(--red-border); background: var(--red-bg); }
|
|
126
190
|
#splitter {
|
|
127
191
|
flex: 0 0 7px; background: var(--surface); border-block: 1px solid var(--border);
|
|
128
192
|
cursor: row-resize; touch-action: none; display: grid; place-items: center;
|
|
129
193
|
}
|
|
130
|
-
#splitter::before { content: ""; height: 2px; width: 26px; background:
|
|
131
|
-
#splitter:hover::before, #splitter:focus-visible::before { background: var(--accent); }
|
|
194
|
+
#splitter::before { content: ""; height: 2px; width: 26px; background: var(--muted); opacity: .45; border-radius: 2px; }
|
|
195
|
+
#splitter:hover::before, #splitter:focus-visible::before { background: var(--accent); opacity: 1; }
|
|
132
196
|
#history { flex: 1; min-height: 0; display: flex; flex-direction: column; }
|
|
133
197
|
.history-bar { border-bottom: 1px solid var(--border); }
|
|
134
198
|
.history-bar h1 { white-space: nowrap; margin-right: 3px; }
|
|
@@ -141,8 +205,8 @@
|
|
|
141
205
|
display: grid; grid-template-columns: var(--lane-width) minmax(0, 1fr) auto;
|
|
142
206
|
align-items: center; gap: 6px; text-align: left; background: var(--bg);
|
|
143
207
|
}
|
|
144
|
-
.commit-row:nth-child(even) { background:
|
|
145
|
-
.commit-row:hover:not(:disabled), .commit-row[aria-current="true"] { background:
|
|
208
|
+
.commit-row:nth-child(even) { background: var(--even-row); }
|
|
209
|
+
.commit-row:hover:not(:disabled), .commit-row[aria-current="true"] { background: var(--active-row); }
|
|
146
210
|
.commit-row svg { display: block; overflow: hidden; }
|
|
147
211
|
.commit-center { display: flex; align-items: center; gap: 4px; overflow: hidden; min-width: 0; }
|
|
148
212
|
.subject { flex: 1 1 50px; }
|
|
@@ -151,19 +215,30 @@
|
|
|
151
215
|
max-width: 118px; min-width: 18px; padding: 0 4px; border: 1px solid transparent;
|
|
152
216
|
border-radius: 4px; font-size: 10px; line-height: 15px;
|
|
153
217
|
}
|
|
154
|
-
.ref.head { color:
|
|
155
|
-
.ref.local { color:
|
|
156
|
-
.ref.remote { color:
|
|
157
|
-
.ref.tag { color: var(--amber); background:
|
|
218
|
+
.ref.head { color: var(--ref-head-fg); background: var(--ref-head-bg); }
|
|
219
|
+
.ref.local { color: var(--ref-local-fg); background: var(--ref-local-bg); }
|
|
220
|
+
.ref.remote { color: var(--ref-remote-fg); border-color: var(--ref-remote-border); }
|
|
221
|
+
.ref.tag { color: var(--amber); background: var(--ref-tag-bg); }
|
|
158
222
|
.commit-meta { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 10px; }
|
|
159
223
|
.commit-author { max-width: 64px; }
|
|
160
224
|
@media (max-width: 440px) { .commit-author { display: none; } }
|
|
161
225
|
@media (max-width: 325px) { .commit-time { display: none; } .toolbar, .history-bar { gap: 4px; } }
|
|
226
|
+
@media (min-width: 960px) {
|
|
227
|
+
main { flex-direction: row; }
|
|
228
|
+
#changes { flex: 0 0 360px; width: 360px; border-right: 1px solid var(--border); }
|
|
229
|
+
#changesBody { max-height: none; flex: 1; }
|
|
230
|
+
#splitter { display: none; }
|
|
231
|
+
#history { flex: 1; min-width: 0; }
|
|
232
|
+
#repos { max-width: 320px; }
|
|
233
|
+
#branchFilter { max-width: 240px; }
|
|
234
|
+
#search { max-width: 240px; }
|
|
235
|
+
.commit-author { max-width: 120px; }
|
|
236
|
+
}
|
|
162
237
|
.empty { padding: 8px 12px; color: var(--text-secondary); }
|
|
163
238
|
#more { display: block; margin: 8px auto; }
|
|
164
239
|
dialog {
|
|
165
240
|
inset: auto 0 0; margin: 0; width: 100%; max-width: none; max-height: min(78dvh, 100%);
|
|
166
|
-
padding: 0; border: 1px solid
|
|
241
|
+
padding: 0; border: 1px solid var(--drawer-border); border-radius: 12px 12px 0 0;
|
|
167
242
|
background: var(--surface); color: var(--text);
|
|
168
243
|
}
|
|
169
244
|
dialog[open] { display: flex; flex-direction: column; }
|
|
@@ -185,16 +260,16 @@
|
|
|
185
260
|
display: flex; width: 100%; align-items: center; gap: 6px;
|
|
186
261
|
border: 0; border-radius: 0; padding: 4px 10px; background: transparent; text-align: left;
|
|
187
262
|
}
|
|
188
|
-
.commit-files button[aria-current="true"] { background:
|
|
263
|
+
.commit-files button[aria-current="true"] { background: var(--active-row); }
|
|
189
264
|
.commit-files .file-path { flex: 1; }
|
|
190
265
|
.stat { font: 10px var(--mono); white-space: nowrap; }
|
|
191
266
|
.stat.add { color: var(--green); }
|
|
192
267
|
.stat.del { color: var(--red); }
|
|
193
268
|
.diff { margin: 0; overflow-x: auto; font: 11px/1.6 var(--mono); tab-size: 4; }
|
|
194
269
|
.diff span { display: block; min-width: 100%; width: max-content; padding: 0 9px; }
|
|
195
|
-
.diff .addition { color: var(--green); background:
|
|
196
|
-
.diff .deletion { color: var(--red); background:
|
|
197
|
-
.diff .hunk { color:
|
|
270
|
+
.diff .addition { color: var(--green); background: var(--green-bg); }
|
|
271
|
+
.diff .deletion { color: var(--red); background: var(--red-bg); }
|
|
272
|
+
.diff .hunk { color: var(--hunk-fg); background: var(--hunk-bg); }
|
|
198
273
|
.diff .header { color: var(--text-secondary); background: var(--surface-2); }
|
|
199
274
|
</style>
|
|
200
275
|
</head>
|
|
@@ -510,7 +585,7 @@
|
|
|
510
585
|
straightIn + straightOut + row.mergeInEdges.map((edge) => curve(edge, 0, 13)).join('') +
|
|
511
586
|
row.branchOutEdges.map((edge) => curve(edge, 13, 26)).join('') +
|
|
512
587
|
(commit.isHead ? circle(5.8, 'none', color, .65) : '') +
|
|
513
|
-
circle(commit.isMerge ? 3.8 : 3, commit.isMerge ? '
|
|
588
|
+
circle(commit.isMerge ? 3.8 : 3, commit.isMerge ? 'var(--surface)' : color, color) + '</svg>';
|
|
514
589
|
}
|
|
515
590
|
|
|
516
591
|
function renderHistory() {
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const INJECT_VERSION = '1.2.0';
|
|
6
|
+
const SIDECAR_ID = 'agy-git-graph/git_graph';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the path to Antigravity's DevToolsActivePort file.
|
|
10
|
+
*/
|
|
11
|
+
export function resolveDevToolsPortFile({ platform = process.platform, env = process.env, home = homedir() } = {}) {
|
|
12
|
+
if (env.ANTIGRAVITY_CDP_PORT_FILE) return env.ANTIGRAVITY_CDP_PORT_FILE;
|
|
13
|
+
if (env.AGY_BROWSER_ACTIVE_PORT_FILE) return env.AGY_BROWSER_ACTIVE_PORT_FILE;
|
|
14
|
+
if (env.ANTIGRAVITY_USER_DATA_DIR) return join(env.ANTIGRAVITY_USER_DATA_DIR, 'DevToolsActivePort');
|
|
15
|
+
if (platform === 'win32') {
|
|
16
|
+
const appData = env.APPDATA || join(home, 'AppData', 'Roaming');
|
|
17
|
+
return join(appData, 'Antigravity', 'DevToolsActivePort');
|
|
18
|
+
}
|
|
19
|
+
if (platform === 'darwin') {
|
|
20
|
+
return join(home, 'Library', 'Application Support', 'Antigravity', 'DevToolsActivePort');
|
|
21
|
+
}
|
|
22
|
+
const xdg = env.XDG_CONFIG_HOME || join(home, '.config');
|
|
23
|
+
return join(xdg, 'Antigravity', 'DevToolsActivePort');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Read the CDP HTTP port from DevToolsActivePort if available.
|
|
28
|
+
*/
|
|
29
|
+
export function readCdpPort(portFile = resolveDevToolsPortFile()) {
|
|
30
|
+
try {
|
|
31
|
+
if (!portFile || !existsSync(portFile)) return 0;
|
|
32
|
+
const firstLine = readFileSync(portFile, 'utf8').split(/\r?\n/)[0]?.trim();
|
|
33
|
+
const port = Number(firstLine);
|
|
34
|
+
return Number.isInteger(port) && port > 0 && port < 65536 ? port : 0;
|
|
35
|
+
} catch {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Build the self-contained renderer script injected into Antigravity windows.
|
|
42
|
+
* It adds a quick-launch button in the top left-sidebar nav group (right below
|
|
43
|
+
* Codex Sync / Powertools / Customizations) and toggles Git Graph in the official right side pane.
|
|
44
|
+
*/
|
|
45
|
+
export function buildSidebarInjectionScript({ sidecarId = SIDECAR_ID } = {}) {
|
|
46
|
+
const safeSidecarId = JSON.stringify(String(sidecarId));
|
|
47
|
+
const safeVer = JSON.stringify(INJECT_VERSION);
|
|
48
|
+
|
|
49
|
+
return `(() => {
|
|
50
|
+
const SIDECAR_ID = ${safeSidecarId};
|
|
51
|
+
const VERSION = ${safeVer};
|
|
52
|
+
const GLOBAL_KEY = '__agyGitGraphSidebar';
|
|
53
|
+
const BTN_ATTR = 'data-agy-git-graph-root';
|
|
54
|
+
const TAB_TITLES = ['Git', 'Git Graph'];
|
|
55
|
+
|
|
56
|
+
const prev = globalThis[GLOBAL_KEY];
|
|
57
|
+
if (prev && prev.version === VERSION && prev.sidecarId === SIDECAR_ID) {
|
|
58
|
+
prev.sync?.();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try { prev?.dispose?.(); } catch {}
|
|
62
|
+
|
|
63
|
+
let observer = null;
|
|
64
|
+
let syncTimer = 0;
|
|
65
|
+
let busy = false;
|
|
66
|
+
|
|
67
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
68
|
+
|
|
69
|
+
const waitFor = async (selector, timeoutMs = 1500) => {
|
|
70
|
+
const deadline = Date.now() + timeoutMs;
|
|
71
|
+
while (Date.now() < deadline) {
|
|
72
|
+
const el = document.querySelector(selector);
|
|
73
|
+
if (el) return el;
|
|
74
|
+
await sleep(30);
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const isOfficialSidePanelOpen = () =>
|
|
80
|
+
document.querySelector('[data-testid="toggle-aux-sidebar"]')?.getAttribute('aria-expanded') === 'true';
|
|
81
|
+
|
|
82
|
+
const isGitGraphVisible = () =>
|
|
83
|
+
isOfficialSidePanelOpen() &&
|
|
84
|
+
document.querySelector(\`[data-testid="sidecar-iframe-slot"][data-sidecar-id="\${SIDECAR_ID}"]\`)?.getAttribute('data-visible') === 'true';
|
|
85
|
+
|
|
86
|
+
const updateButtonState = () => {
|
|
87
|
+
const btn = document.querySelector(\`[\${BTN_ATTR}="sidebar-btn"]\`);
|
|
88
|
+
if (!btn) return;
|
|
89
|
+
const active = isGitGraphVisible();
|
|
90
|
+
btn.setAttribute('aria-pressed', active ? 'true' : 'false');
|
|
91
|
+
if (active) {
|
|
92
|
+
btn.classList.add('bg-sidebar-muted', 'text-foreground');
|
|
93
|
+
btn.classList.remove('bg-transparent', 'text-secondary-foreground');
|
|
94
|
+
} else {
|
|
95
|
+
btn.classList.remove('bg-sidebar-muted', 'text-foreground');
|
|
96
|
+
btn.classList.add('bg-transparent', 'text-secondary-foreground');
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const findExistingTabButton = () => {
|
|
101
|
+
for (const tab of document.querySelectorAll('.agy-aux-tab')) {
|
|
102
|
+
const text = tab.textContent?.trim() || '';
|
|
103
|
+
if (TAB_TITLES.includes(text)) {
|
|
104
|
+
return tab.querySelector('button');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const toggleOfficialSidePanel = async () => {
|
|
111
|
+
if (busy) return;
|
|
112
|
+
busy = true;
|
|
113
|
+
try {
|
|
114
|
+
const toggleBtn = document.querySelector('[data-testid="toggle-aux-sidebar"]');
|
|
115
|
+
if (!toggleBtn) return;
|
|
116
|
+
|
|
117
|
+
// If already open and showing Git Graph, collapse the official side panel
|
|
118
|
+
if (isGitGraphVisible()) {
|
|
119
|
+
toggleBtn.click();
|
|
120
|
+
await sleep(80);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 1. Open the official right-hand side panel if collapsed
|
|
125
|
+
if (!isOfficialSidePanelOpen()) {
|
|
126
|
+
toggleBtn.click();
|
|
127
|
+
await sleep(120);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 2. If the tab is already open in the official tab bar, switch to it
|
|
131
|
+
const existingTabBtn = findExistingTabButton();
|
|
132
|
+
if (existingTabBtn) {
|
|
133
|
+
existingTabBtn.click();
|
|
134
|
+
await sleep(60);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 3. Otherwise open it via the official New Tab -> Plugins -> Git Graph menu
|
|
139
|
+
let extTrigger = document.querySelector('[data-testid="new-tab-card-extensions"]');
|
|
140
|
+
if (!extTrigger) {
|
|
141
|
+
const newTabBtn = await waitFor('[data-testid="side-panel-new-tab-button"]', 1000);
|
|
142
|
+
if (newTabBtn) {
|
|
143
|
+
newTabBtn.click();
|
|
144
|
+
extTrigger = await waitFor('[data-testid="new-tab-card-extensions"]', 1000);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!extTrigger) return;
|
|
148
|
+
|
|
149
|
+
extTrigger.dispatchEvent(new PointerEvent('pointerenter', { bubbles: true }));
|
|
150
|
+
extTrigger.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }));
|
|
151
|
+
extTrigger.click();
|
|
152
|
+
|
|
153
|
+
const submenuItem = await waitFor(
|
|
154
|
+
\`[data-testid="plugins-submenu-item"][data-sidecar-id="\${SIDECAR_ID}"]\`,
|
|
155
|
+
1500
|
|
156
|
+
);
|
|
157
|
+
if (submenuItem) {
|
|
158
|
+
submenuItem.click();
|
|
159
|
+
await sleep(80);
|
|
160
|
+
}
|
|
161
|
+
} finally {
|
|
162
|
+
busy = false;
|
|
163
|
+
updateButtonState();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const mountSidebarButton = () => {
|
|
168
|
+
const customizations = document.querySelector('a[href="/customizations"]');
|
|
169
|
+
const navContainer = customizations?.parentElement || document.querySelector('[data-testid="sidebar-navigation-items"]');
|
|
170
|
+
if (!navContainer) return;
|
|
171
|
+
|
|
172
|
+
const codexMount = navContainer.querySelector('[data-agy-codex-sync-root="sidebar-btn"]');
|
|
173
|
+
const powertoolsMount = navContainer.querySelector('[data-agy-powertools-root="management"]');
|
|
174
|
+
const anchor = codexMount || powertoolsMount || customizations;
|
|
175
|
+
|
|
176
|
+
let btn = navContainer.querySelector(\`[\${BTN_ATTR}="sidebar-btn"]\`);
|
|
177
|
+
if (!btn) {
|
|
178
|
+
btn = document.createElement('button');
|
|
179
|
+
btn.type = 'button';
|
|
180
|
+
btn.setAttribute(BTN_ATTR, 'sidebar-btn');
|
|
181
|
+
btn.className = 'agy-button agy-button-custom inline-flex items-center font-medium transition-colors select-none outline-none cursor-pointer disabled:opacity-50 flex-grow w-full justify-start select-none font-normal min-w-0 gap-1.5 px-2 rounded-lg py-1.5 bg-transparent text-secondary-foreground hover:bg-sidebar-muted hover:text-foreground';
|
|
182
|
+
btn.title = '打开/收起官方右侧栏「Git Graph」';
|
|
183
|
+
btn.innerHTML = '<span class="shrink-0 flex items-center"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="6" cy="6" r="2.5"/><circle cx="6" cy="18" r="2.5"/><circle cx="18" cy="7" r="2.5"/><path d="M6 8.5v7"/><path d="M18 9.5c0 4-12 2.5-12 6"/></svg></span><span class="truncate">Git Graph</span>';
|
|
184
|
+
btn.addEventListener('click', () => { void toggleOfficialSidePanel(); });
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const expectedNext = anchor ? anchor.nextSibling : null;
|
|
188
|
+
if (btn.parentElement !== navContainer || (anchor && btn.previousSibling !== anchor)) {
|
|
189
|
+
navContainer.insertBefore(btn, expectedNext);
|
|
190
|
+
}
|
|
191
|
+
updateButtonState();
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const scheduleSync = () => {
|
|
195
|
+
if (syncTimer) return;
|
|
196
|
+
syncTimer = setTimeout(() => {
|
|
197
|
+
syncTimer = 0;
|
|
198
|
+
mountSidebarButton();
|
|
199
|
+
}, 80);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
observer = new MutationObserver(scheduleSync);
|
|
203
|
+
observer.observe(document.documentElement, {
|
|
204
|
+
childList: true,
|
|
205
|
+
subtree: true,
|
|
206
|
+
attributes: true,
|
|
207
|
+
attributeFilter: ['aria-expanded', 'data-visible'],
|
|
208
|
+
});
|
|
209
|
+
mountSidebarButton();
|
|
210
|
+
|
|
211
|
+
globalThis[GLOBAL_KEY] = {
|
|
212
|
+
version: VERSION,
|
|
213
|
+
sidecarId: SIDECAR_ID,
|
|
214
|
+
sync: mountSidebarButton,
|
|
215
|
+
toggle: toggleOfficialSidePanel,
|
|
216
|
+
dispose: () => {
|
|
217
|
+
clearTimeout(syncTimer);
|
|
218
|
+
observer?.disconnect();
|
|
219
|
+
document.querySelectorAll(\`[\${BTN_ATTR}]\`).forEach((el) => el.remove());
|
|
220
|
+
delete globalThis[GLOBAL_KEY];
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
})();`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Connect to Antigravity's CDP port and keep the sidebar quick-launch button injected.
|
|
228
|
+
*/
|
|
229
|
+
export function startCdpSidebarInjector({ sidecarId = SIDECAR_ID, pollIntervalMs = 3500 } = {}) {
|
|
230
|
+
const attachedTargets = new Set();
|
|
231
|
+
let stopped = false;
|
|
232
|
+
|
|
233
|
+
const evaluateOnTarget = (wsUrl, script) =>
|
|
234
|
+
new Promise((resolve, reject) => {
|
|
235
|
+
const ws = new WebSocket(wsUrl);
|
|
236
|
+
const timer = setTimeout(() => {
|
|
237
|
+
try { ws.close(); } catch {}
|
|
238
|
+
reject(new Error('CDP timeout'));
|
|
239
|
+
}, 6000);
|
|
240
|
+
|
|
241
|
+
ws.addEventListener('open', () => {
|
|
242
|
+
ws.send(JSON.stringify({ id: 1, method: 'Page.addScriptToEvaluateOnNewDocument', params: { source: script } }));
|
|
243
|
+
ws.send(JSON.stringify({ id: 2, method: 'Runtime.evaluate', params: { expression: script } }));
|
|
244
|
+
});
|
|
245
|
+
ws.addEventListener('message', (ev) => {
|
|
246
|
+
try {
|
|
247
|
+
const msg = JSON.parse(ev.data);
|
|
248
|
+
if (msg.id === 2) {
|
|
249
|
+
clearTimeout(timer);
|
|
250
|
+
try { ws.close(); } catch {}
|
|
251
|
+
resolve();
|
|
252
|
+
}
|
|
253
|
+
} catch {}
|
|
254
|
+
});
|
|
255
|
+
ws.addEventListener('error', () => {
|
|
256
|
+
clearTimeout(timer);
|
|
257
|
+
reject(new Error('CDP ws error'));
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const tick = async () => {
|
|
262
|
+
if (stopped) return;
|
|
263
|
+
const port = readCdpPort();
|
|
264
|
+
if (!port) return;
|
|
265
|
+
|
|
266
|
+
try {
|
|
267
|
+
const res = await fetch(`http://127.0.0.1:${port}/json`, { signal: AbortSignal.timeout(2000) });
|
|
268
|
+
if (!res.ok) return;
|
|
269
|
+
const targets = await res.json();
|
|
270
|
+
const pages = targets.filter(
|
|
271
|
+
(t) =>
|
|
272
|
+
t?.type === 'page' &&
|
|
273
|
+
t?.webSocketDebuggerUrl &&
|
|
274
|
+
typeof t.url === 'string' &&
|
|
275
|
+
(t.url.startsWith('https://127.0.0.1:') || t.url.startsWith('http://127.0.0.1:'))
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
const activeIds = new Set(pages.map((p) => p.id));
|
|
279
|
+
for (const oldId of attachedTargets) {
|
|
280
|
+
if (!activeIds.has(oldId)) attachedTargets.delete(oldId);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const script = buildSidebarInjectionScript({ sidecarId });
|
|
284
|
+
for (const page of pages) {
|
|
285
|
+
if (attachedTargets.has(page.id)) continue;
|
|
286
|
+
try {
|
|
287
|
+
await evaluateOnTarget(page.webSocketDebuggerUrl, script);
|
|
288
|
+
attachedTargets.add(page.id);
|
|
289
|
+
} catch {
|
|
290
|
+
// Retry on next poll
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
} catch {
|
|
294
|
+
// CDP port not ready yet
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const interval = setInterval(tick, pollIntervalMs);
|
|
299
|
+
interval.unref?.();
|
|
300
|
+
void tick();
|
|
301
|
+
|
|
302
|
+
return () => {
|
|
303
|
+
stopped = true;
|
|
304
|
+
clearInterval(interval);
|
|
305
|
+
};
|
|
306
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const FONT_SETTINGS = join(
|
|
6
|
+
homedir(),
|
|
7
|
+
'.gemini',
|
|
8
|
+
'antigravity',
|
|
9
|
+
'sidecar_data',
|
|
10
|
+
'agy-powertools',
|
|
11
|
+
'inspector',
|
|
12
|
+
'settings.json',
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export function powertoolsFontCss() {
|
|
16
|
+
try {
|
|
17
|
+
const settings = JSON.parse(readFileSync(FONT_SETTINGS, 'utf8'));
|
|
18
|
+
const font = typeof settings.fontFamily === 'string' ? settings.fontFamily.replace(/["\\]/g, '').trim() : '';
|
|
19
|
+
const weight = Number(settings.fontWeight);
|
|
20
|
+
const rules = [];
|
|
21
|
+
if (font && font.length <= 128 && !/[;{}<>\u0000-\u001f\u007f-\u009f\u2028\u2029]/.test(font)) {
|
|
22
|
+
rules.push('--ui-font: "' + font + '", var(--ui-font-default);');
|
|
23
|
+
}
|
|
24
|
+
if (Number.isInteger(weight) && weight >= 1 && weight <= 1000) {
|
|
25
|
+
rules.push('--ui-font-weight: ' + weight + ';');
|
|
26
|
+
}
|
|
27
|
+
return rules.length ? ':root { ' + rules.join(' ') + ' }' : '';
|
|
28
|
+
} catch {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function renderIndexHtml() {
|
|
34
|
+
return readFileSync(new URL('../index.html', import.meta.url), 'utf8')
|
|
35
|
+
.replace('/*__POWERTOOLS_FONT_CSS__*/', () => powertoolsFontCss());
|
|
36
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
1
|
import { createServer } from 'node:http';
|
|
3
|
-
import {
|
|
4
|
-
import { join } from 'node:path';
|
|
2
|
+
import { startCdpSidebarInjector } from './lib/cdp-sidebar.mjs';
|
|
5
3
|
import { InputError } from './lib/git.mjs';
|
|
6
4
|
import { createHandlers } from './lib/handlers.mjs';
|
|
5
|
+
import { renderIndexHtml } from './lib/render.mjs';
|
|
7
6
|
|
|
8
7
|
for (const stream of [process.stdout, process.stderr]) {
|
|
9
8
|
stream.on('error', (error) => {
|
|
@@ -11,32 +10,8 @@ for (const stream of [process.stdout, process.stderr]) {
|
|
|
11
10
|
});
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
const FONT_SETTINGS = join(homedir(), '.gemini', 'antigravity', 'sidecar_data',
|
|
15
|
-
'agy-powertools', 'inspector', 'settings.json');
|
|
16
13
|
const BODY_LIMIT = 1024 * 1024;
|
|
17
|
-
|
|
18
|
-
function powertoolsFontCss() {
|
|
19
|
-
try {
|
|
20
|
-
const settings = JSON.parse(readFileSync(FONT_SETTINGS, 'utf8'));
|
|
21
|
-
const font = typeof settings.fontFamily === 'string' ? settings.fontFamily.replace(/["\\]/g, '').trim() : '';
|
|
22
|
-
const weight = Number(settings.fontWeight);
|
|
23
|
-
const rules = [];
|
|
24
|
-
if (font && font.length <= 128 && !/[;{}<>\u0000-\u001f\u007f-\u009f\u2028\u2029]/.test(font)) {
|
|
25
|
-
rules.push('--ui-font: "' + font + '", var(--ui-font-default);');
|
|
26
|
-
}
|
|
27
|
-
if (Number.isInteger(weight) && weight >= 1 && weight <= 1000) {
|
|
28
|
-
rules.push('--ui-font-weight: ' + weight + ';');
|
|
29
|
-
}
|
|
30
|
-
return rules.length ? ':root { ' + rules.join(' ') + ' }' : '';
|
|
31
|
-
} catch {
|
|
32
|
-
return '';
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function renderHtml() {
|
|
37
|
-
return readFileSync(new URL('./index.html', import.meta.url), 'utf8')
|
|
38
|
-
.replace('/*__POWERTOOLS_FONT_CSS__*/', () => powertoolsFontCss());
|
|
39
|
-
}
|
|
14
|
+
const renderHtml = () => renderIndexHtml();
|
|
40
15
|
|
|
41
16
|
function sendJson(response, code, data) {
|
|
42
17
|
response.writeHead(code, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
@@ -127,5 +102,6 @@ if (process.argv.includes('--standalone')) {
|
|
|
127
102
|
const app = new SidecarApp();
|
|
128
103
|
app.page('/', () => renderHtml());
|
|
129
104
|
for (const [route, handler] of Object.entries(handlers)) app.api(route, handler);
|
|
105
|
+
startCdpSidebarInjector();
|
|
130
106
|
app.run();
|
|
131
107
|
}
|