@tokenroll/llmdoc 3.5.1 → 3.5.2
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/assets/viewer-app.js +243 -0
- package/assets/viewer-detail.js +223 -0
- package/assets/viewer-graph.js +471 -0
- package/assets/viewer-model.js +127 -0
- package/assets/viewer.css +343 -0
- package/assets/viewer.html +51 -547
- package/dist/commands/context.js +14 -1
- package/dist/commands/serve.js +0 -0
- package/dist/commands/status.js +3 -19
- package/dist/lib/repository-health.js +26 -0
- package/dist/lib/viewer-http.js +107 -0
- package/dist/lib/viewer-state.js +131 -0
- package/dist/lib/workspace.js +39 -0
- package/package.json +1 -1
- package/schemas/output.schema.json +8 -0
package/assets/viewer.html
CHANGED
|
@@ -1,554 +1,58 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="zh-CN">
|
|
3
3
|
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
<
|
|
7
|
-
<
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
--text: #171c26; --muted: #667085; --faint: #98a2b3;
|
|
12
|
-
--accent: #4c5fd5; --accent-soft: #eef0fc;
|
|
13
|
-
--fresh: #aab2bd; --impacted: #e8890c; --dirty: #d6453d; --review: #c9a227;
|
|
14
|
-
--shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 14px rgba(16,24,40,.06);
|
|
15
|
-
--radius: 12px;
|
|
16
|
-
}
|
|
17
|
-
* { box-sizing: border-box; }
|
|
18
|
-
html, body { height: 100%; }
|
|
19
|
-
body {
|
|
20
|
-
margin: 0; color: var(--text); background: var(--bg);
|
|
21
|
-
font: 13px/1.6 -apple-system, "SF Pro Text", "Segoe UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
|
|
22
|
-
display: flex; flex-direction: column; overflow: hidden;
|
|
23
|
-
-webkit-font-smoothing: antialiased;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/* ---------- header ---------- */
|
|
27
|
-
header {
|
|
28
|
-
display: flex; align-items: center; gap: 10px; padding: 10px 18px;
|
|
29
|
-
background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; z-index: 3;
|
|
30
|
-
}
|
|
31
|
-
header h1 { font-size: 14.5px; margin: 0 8px 0 0; font-weight: 700; letter-spacing: -.01em; }
|
|
32
|
-
header h1 .repo { color: var(--muted); font-weight: 450; }
|
|
33
|
-
.chip {
|
|
34
|
-
padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border);
|
|
35
|
-
background: #fafbfc; font-size: 11.5px; color: var(--muted); white-space: nowrap;
|
|
36
|
-
}
|
|
37
|
-
.chip.ok { color: #147a3d; border-color: #bfe4cb; background: #f0faf3; }
|
|
38
|
-
.chip.bad { color: var(--dirty); border-color: #f0c7c4; background: #fdf2f1; }
|
|
39
|
-
.chip.warn { color: #b26a05; border-color: #f0dcb4; background: #fdf8ec; }
|
|
40
|
-
.chip.btn { cursor: pointer; user-select: none; }
|
|
41
|
-
.chip.btn:hover { border-color: var(--border-strong); color: var(--text); }
|
|
42
|
-
.toggle { display: flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; margin-left: auto; }
|
|
43
|
-
.toggle button {
|
|
44
|
-
border: 0; background: var(--panel); color: var(--muted); font: inherit; font-size: 12px;
|
|
45
|
-
padding: 5px 14px; cursor: pointer;
|
|
46
|
-
}
|
|
47
|
-
.toggle button.on { background: var(--accent); color: #fff; font-weight: 600; }
|
|
48
|
-
.toggle button:not(.on):hover { background: var(--accent-soft); color: var(--accent); }
|
|
49
|
-
|
|
50
|
-
/* ---------- layout ---------- */
|
|
51
|
-
main { flex: 1; display: grid; grid-template-columns: 272px 1fr 408px; min-height: 0; }
|
|
52
|
-
|
|
53
|
-
/* ---------- sidebar ---------- */
|
|
54
|
-
#sidebar { background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto; padding: 12px; }
|
|
55
|
-
#sidebar input {
|
|
56
|
-
width: 100%; padding: 7px 11px; border: 1px solid var(--border); border-radius: 9px;
|
|
57
|
-
font: inherit; font-size: 12.5px; margin-bottom: 8px; outline: none; background: #fafbfc;
|
|
58
|
-
}
|
|
59
|
-
#sidebar input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(76,95,213,.12); }
|
|
60
|
-
.group-label {
|
|
61
|
-
font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint);
|
|
62
|
-
margin: 14px 6px 5px; display: flex; align-items: center; gap: 7px; font-weight: 600; cursor: pointer;
|
|
63
|
-
}
|
|
64
|
-
.group-label:hover { color: var(--muted); }
|
|
65
|
-
.swatch { width: 10px; height: 10px; border-radius: 3.5px; display: inline-block; }
|
|
66
|
-
.doc-item {
|
|
67
|
-
display: flex; align-items: center; gap: 8px; padding: 5.5px 9px; border-radius: 8px;
|
|
68
|
-
cursor: pointer; transition: background .1s;
|
|
69
|
-
}
|
|
70
|
-
.doc-item:hover { background: #f2f4f7; }
|
|
71
|
-
.doc-item.active { background: var(--accent-soft); }
|
|
72
|
-
.doc-item.active .name { color: var(--accent); font-weight: 600; }
|
|
73
|
-
.doc-item .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2.5px color-mix(in srgb, currentColor 18%, transparent); }
|
|
74
|
-
.doc-item .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; }
|
|
75
|
-
.doc-item .kind { margin-left: auto; font-size: 10px; color: var(--faint); flex: none; }
|
|
76
|
-
|
|
77
|
-
/* ---------- graph ---------- */
|
|
78
|
-
#graph-wrap { position: relative; min-width: 0; background:
|
|
79
|
-
radial-gradient(circle at 1px 1px, #dfe3e8 1px, transparent 0) 0 0/26px 26px; }
|
|
80
|
-
#graph { width: 100%; height: 100%; display: block; cursor: grab; }
|
|
81
|
-
#graph:active { cursor: grabbing; }
|
|
82
|
-
#legend {
|
|
83
|
-
position: absolute; left: 14px; bottom: 14px; background: color-mix(in srgb, var(--panel) 92%, transparent);
|
|
84
|
-
backdrop-filter: blur(6px); border: 1px solid var(--border); border-radius: 10px;
|
|
85
|
-
padding: 8px 14px; font-size: 11px; color: var(--muted); display: flex; gap: 15px; box-shadow: var(--shadow);
|
|
86
|
-
}
|
|
87
|
-
#legend i { display: inline-block; width: 18px; border-top: 2px solid #9aa4b2; vertical-align: middle; margin-right: 5px; border-radius: 2px; }
|
|
88
|
-
#legend i.related { border-top-style: dashed; }
|
|
89
|
-
#legend i.link { border-top-width: 1px; border-top-color: #c8cfd8; }
|
|
90
|
-
#graph-hint {
|
|
91
|
-
position: absolute; top: 14px; left: 14px; font-size: 11.5px; color: var(--muted);
|
|
92
|
-
background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(6px);
|
|
93
|
-
border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; box-shadow: var(--shadow);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/* svg */
|
|
97
|
-
.edge-path { fill: none; transition: opacity .15s; }
|
|
98
|
-
.node { transition: opacity .15s; }
|
|
99
|
-
.node circle, .node .topic-shape { cursor: pointer; transition: filter .12s; }
|
|
100
|
-
.node:hover circle, .node:hover .topic-shape { filter: brightness(1.06) saturate(1.1); }
|
|
101
|
-
.node text { fill: var(--text); pointer-events: none; }
|
|
102
|
-
.node .sub { fill: var(--muted); }
|
|
103
|
-
.node.dim, .edge-path.dim { opacity: .12; }
|
|
104
|
-
|
|
105
|
-
/* ---------- detail ---------- */
|
|
106
|
-
#detail { background: var(--panel); border-left: 1px solid var(--border); overflow-y: auto; }
|
|
107
|
-
#detail .inner { padding: 18px 20px 32px; }
|
|
108
|
-
#detail .placeholder { color: var(--faint); margin-top: 48px; text-align: center; font-size: 12.5px; }
|
|
109
|
-
#detail h2 { font-size: 15px; margin: 0 0 3px; word-break: break-all; letter-spacing: -.01em; }
|
|
110
|
-
#detail .desc { color: var(--muted); font-size: 12.5px; }
|
|
111
|
-
#detail .meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 6px; }
|
|
112
|
-
.rel-block { font-size: 12.5px; margin: 3px 0; }
|
|
113
|
-
.rel-link { color: var(--accent); cursor: pointer; text-decoration: none; }
|
|
114
|
-
.rel-link:hover { text-decoration: underline; }
|
|
115
|
-
.code-path {
|
|
116
|
-
font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px;
|
|
117
|
-
background: #f6f7f9; border: 1px solid var(--border); border-radius: 6px; padding: 2px 7px;
|
|
118
|
-
}
|
|
119
|
-
.coderef {
|
|
120
|
-
font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: #6d3fc0;
|
|
121
|
-
background: #f6f1fd; border: 1px solid #e4d6f8; border-radius: 6px; padding: 1px 7px;
|
|
122
|
-
}
|
|
123
|
-
#doc-body { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 14px; font-size: 13.5px; }
|
|
124
|
-
#doc-body h1 { font-size: 17px; } #doc-body h2 { font-size: 14.5px; margin-top: 22px; } #doc-body h3 { font-size: 13.5px; }
|
|
125
|
-
#doc-body pre { background: #f6f7f9; border: 1px solid var(--border); padding: 11px 13px; border-radius: 9px; overflow-x: auto; font-size: 12px; }
|
|
126
|
-
#doc-body code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; background: #f3f4f6; padding: 1px 5px; border-radius: 5px; }
|
|
127
|
-
#doc-body pre code { background: none; padding: 0; }
|
|
128
|
-
#doc-body table { border-collapse: collapse; font-size: 12.5px; }
|
|
129
|
-
#doc-body td, #doc-body th { border: 1px solid var(--border); padding: 5px 9px; }
|
|
130
|
-
#doc-body a { color: var(--accent); }
|
|
131
|
-
#doc-body blockquote { margin: 0; padding: 2px 14px; border-left: 3px solid var(--border-strong); color: var(--muted); }
|
|
132
|
-
|
|
133
|
-
/* topic detail card list */
|
|
134
|
-
.topic-doc-card {
|
|
135
|
-
border: 1px solid var(--border); border-radius: 10px; padding: 10px 13px; margin: 8px 0;
|
|
136
|
-
cursor: pointer; transition: border-color .12s, box-shadow .12s;
|
|
137
|
-
}
|
|
138
|
-
.topic-doc-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
|
|
139
|
-
.topic-doc-card .t { font-weight: 600; font-size: 12.5px; display: flex; gap: 8px; align-items: center; }
|
|
140
|
-
.topic-doc-card .d { color: var(--muted); font-size: 12px; margin-top: 3px; }
|
|
141
|
-
</style>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<meta name="color-scheme" content="light" />
|
|
7
|
+
<title>llmdoc viewer</title>
|
|
8
|
+
<link rel="stylesheet" href="/assets/viewer.css" />
|
|
9
|
+
<script src="/assets/marked.js"></script>
|
|
10
|
+
<script type="module" src="/assets/viewer-app.js"></script>
|
|
142
11
|
</head>
|
|
143
12
|
<body>
|
|
144
|
-
<header>
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
<button id="
|
|
153
|
-
<
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
<
|
|
162
|
-
<
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
</
|
|
168
|
-
<
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
state.nodes.length + " docs · ~" + state.growth.currentTotalEstimatedTokens + " tokens";
|
|
189
|
-
const behind = state.baseline.behindHead;
|
|
190
|
-
const baselineEl = document.getElementById("stat-baseline");
|
|
191
|
-
baselineEl.textContent = state.baseline.revision
|
|
192
|
-
? "baseline " + state.baseline.revision.slice(0, 7) + (behind ? " · " + behind + " behind" : " · 最新")
|
|
193
|
-
: "baseline 缺失";
|
|
194
|
-
baselineEl.className = "chip " + (behind ? "warn" : state.baseline.revision ? "ok" : "bad");
|
|
195
|
-
const v = state.validate;
|
|
196
|
-
const validateEl = document.getElementById("stat-validate");
|
|
197
|
-
validateEl.textContent = v.ok ? "validate ok" + (v.warnings ? " · " + v.warnings + " warn" : "") : "validate " + v.errors + " errors";
|
|
198
|
-
validateEl.className = "chip " + (v.ok ? "ok" : "bad");
|
|
199
|
-
const stale = state.nodes.filter((n) => n.status !== "fresh").length;
|
|
200
|
-
const deltaEl = document.getElementById("stat-delta");
|
|
201
|
-
deltaEl.textContent = stale ? stale + " 份待同步 · 建议 " + state.delta.suggestedMode : "知识面新鲜";
|
|
202
|
-
deltaEl.className = "chip " + (stale ? "warn" : "ok");
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/* ---------- sidebar ---------- */
|
|
206
|
-
function renderSidebar() {
|
|
207
|
-
const query = document.getElementById("search").value.trim().toLowerCase();
|
|
208
|
-
const match = (n) => !query || n.path.toLowerCase().includes(query) || n.description.toLowerCase().includes(query);
|
|
209
|
-
const container = document.getElementById("doc-list");
|
|
210
|
-
container.innerHTML = "";
|
|
211
|
-
const groups = new Map([["", state.nodes.filter((n) => !n.topic && match(n))]]);
|
|
212
|
-
for (const node of state.nodes) if (node.topic && match(node)) {
|
|
213
|
-
if (!groups.has(node.topic)) groups.set(node.topic, []);
|
|
214
|
-
groups.get(node.topic).push(node);
|
|
215
|
-
}
|
|
216
|
-
for (const [topic, nodes] of groups) {
|
|
217
|
-
if (!nodes.length) continue;
|
|
218
|
-
const label = document.createElement("div");
|
|
219
|
-
label.className = "group-label";
|
|
220
|
-
label.innerHTML = topic
|
|
221
|
-
? '<span class="swatch" style="background:' + colorOf(topic) + '"></span>' + topic + "/"
|
|
222
|
-
: "root";
|
|
223
|
-
if (topic) label.onclick = () => selectTopic(topic);
|
|
224
|
-
container.append(label);
|
|
225
|
-
for (const node of nodes) {
|
|
226
|
-
const item = document.createElement("div");
|
|
227
|
-
item.className = "doc-item" + (selected === node.path ? " active" : "");
|
|
228
|
-
item.innerHTML =
|
|
229
|
-
'<span class="dot" style="background:' + STATUS_COLOR[node.status] + ';color:' + STATUS_COLOR[node.status] + '"></span>' +
|
|
230
|
-
'<span class="name" title="' + node.path + '">' + node.path.split("/").pop().replace(/\.mdx$/, "") + "</span>" +
|
|
231
|
-
'<span class="kind">' + node.kind + "</span>";
|
|
232
|
-
item.onclick = () => selectDoc(node.path);
|
|
233
|
-
container.append(item);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/* ---------- shared force simulation ---------- */
|
|
239
|
-
function simulate(nodes, edges, width, height, spread) {
|
|
240
|
-
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
241
|
-
nodes.forEach((n, i) => {
|
|
242
|
-
const angle = (i / nodes.length) * Math.PI * 2;
|
|
243
|
-
n.x = width / 2 + Math.cos(angle) * spread * 0.55 + Math.cos(i * 5.7) * 30;
|
|
244
|
-
n.y = height / 2 + Math.sin(angle) * spread * 0.55 + Math.sin(i * 5.7) * 30;
|
|
245
|
-
n.vx = 0; n.vy = 0;
|
|
246
|
-
});
|
|
247
|
-
const repulse = spread * spread * 3.2;
|
|
248
|
-
for (let step = 0; step < 320; step++) {
|
|
249
|
-
for (let i = 0; i < nodes.length; i++) for (let j = i + 1; j < nodes.length; j++) {
|
|
250
|
-
const a = nodes[i], b = nodes[j];
|
|
251
|
-
let dx = a.x - b.x, dy = a.y - b.y, d2 = dx * dx + dy * dy || 1, d = Math.sqrt(d2);
|
|
252
|
-
const force = Math.min(14, repulse / d2);
|
|
253
|
-
dx /= d; dy /= d; a.vx += dx * force; a.vy += dy * force; b.vx -= dx * force; b.vy -= dy * force;
|
|
254
|
-
}
|
|
255
|
-
for (const e of edges) {
|
|
256
|
-
const a = byId.get(e.from), b = byId.get(e.to);
|
|
257
|
-
if (!a || !b) continue;
|
|
258
|
-
const dx = b.x - a.x, dy = b.y - a.y, d = Math.sqrt(dx * dx + dy * dy) || 1;
|
|
259
|
-
const pull = (d - (a.r + b.r + spread * 0.55)) * 0.014;
|
|
260
|
-
a.vx += (dx / d) * pull; a.vy += (dy / d) * pull; b.vx -= (dx / d) * pull; b.vy -= (dy / d) * pull;
|
|
261
|
-
}
|
|
262
|
-
for (const n of nodes) {
|
|
263
|
-
if (n.cluster) { n.vx += (n.cluster.x - n.x) * 0.014; n.vy += (n.cluster.y - n.y) * 0.014; }
|
|
264
|
-
n.vx += (width / 2 - n.x) * 0.004; n.vy += (height / 2 - n.y) * 0.004;
|
|
265
|
-
n.x += n.vx *= 0.8; n.y += n.vy *= 0.8;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/* ---------- graph rendering ---------- */
|
|
271
|
-
function renderGraph() {
|
|
272
|
-
const svg = document.getElementById("graph");
|
|
273
|
-
const { width, height } = svg.getBoundingClientRect();
|
|
274
|
-
const NS = "http://www.w3.org/2000/svg";
|
|
275
|
-
svg.innerHTML = "";
|
|
276
|
-
const defs = document.createElementNS(NS, "defs");
|
|
277
|
-
defs.innerHTML =
|
|
278
|
-
'<marker id="arrow" viewBox="0 0 8 8" refX="7.5" refY="4" markerWidth="5.5" markerHeight="5.5" orient="auto">' +
|
|
279
|
-
'<path d="M0 .8 L8 4 L0 7.2 z" fill="#9aa4b2"/></marker>' +
|
|
280
|
-
'<filter id="soft" x="-40%" y="-40%" width="180%" height="180%">' +
|
|
281
|
-
'<feDropShadow dx="0" dy="1.5" stdDeviation="2.5" flood-color="#101828" flood-opacity="0.18"/></filter>';
|
|
282
|
-
const root = document.createElementNS(NS, "g");
|
|
283
|
-
svg.append(defs, root);
|
|
284
|
-
|
|
285
|
-
const graph = mode === "topics" ? buildTopicGraph(width, height) : buildDocGraph(width, height);
|
|
286
|
-
document.getElementById("graph-hint").textContent = mode === "topics"
|
|
287
|
-
? "Topic 拓扑 · 边粗细 = 跨域引用数 · 点击下钻"
|
|
288
|
-
: "文档全图 · 点击节点查看详情 · 拖拽 / 滚轮缩放";
|
|
289
|
-
document.getElementById("legend").innerHTML = (mode === "topics"
|
|
290
|
-
? '<span><i></i>跨域引用</span>'
|
|
291
|
-
: '<span><i></i>requires</span><span><i class="related"></i>related</span><span><i class="link"></i>link</span>') +
|
|
292
|
-
'<span><b style="color:var(--dirty)">●</b> dirty</span><span><b style="color:var(--impacted)">●</b> impacted</span><span><b style="color:var(--review)">●</b> review</span>';
|
|
293
|
-
|
|
294
|
-
const byId = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
295
|
-
const edgeEls = graph.edges.map((e) => {
|
|
296
|
-
const pathEl = document.createElementNS(NS, "path");
|
|
297
|
-
pathEl.setAttribute("class", "edge-path");
|
|
298
|
-
pathEl.setAttribute("stroke", e.style === "link" ? "#c8cfd8" : "#9aa4b2");
|
|
299
|
-
pathEl.setAttribute("stroke-width", e.width ?? (e.style === "link" ? 1 : 1.7));
|
|
300
|
-
pathEl.setAttribute("stroke-linecap", "round");
|
|
301
|
-
pathEl.setAttribute("stroke-opacity", e.style === "link" ? 0.75 : 0.85);
|
|
302
|
-
if (e.style === "related") pathEl.setAttribute("stroke-dasharray", "5 5");
|
|
303
|
-
if (e.style === "requires") pathEl.setAttribute("marker-end", "url(#arrow)");
|
|
304
|
-
root.append(pathEl);
|
|
305
|
-
return { e, pathEl };
|
|
306
|
-
});
|
|
307
|
-
const nodeEls = graph.nodes.map((n) => {
|
|
308
|
-
const g = document.createElementNS(NS, "g");
|
|
309
|
-
g.setAttribute("class", "node");
|
|
310
|
-
const circle = document.createElementNS(NS, "circle");
|
|
311
|
-
circle.setAttribute("r", n.r);
|
|
312
|
-
circle.setAttribute("fill", n.fill);
|
|
313
|
-
circle.setAttribute("fill-opacity", n.isTopic ? "0.92" : "0.88");
|
|
314
|
-
circle.setAttribute("stroke", n.status === "fresh" ? "#ffffff" : STATUS_COLOR[n.status]);
|
|
315
|
-
circle.setAttribute("stroke-width", n.status === "fresh" ? 2 : 3.5);
|
|
316
|
-
circle.setAttribute("filter", "url(#soft)");
|
|
317
|
-
if (n.isTopic) circle.setAttribute("class", "topic-shape");
|
|
318
|
-
g.append(circle);
|
|
319
|
-
if (n.isTopic) {
|
|
320
|
-
const title = textEl(NS, n.label, 0, 4, 12.5, 700, "#ffffff");
|
|
321
|
-
const sub = textEl(NS, n.subLabel, 0, n.r + 15, 10.5, 500, null);
|
|
322
|
-
sub.setAttribute("class", "sub");
|
|
323
|
-
g.append(title, sub);
|
|
324
|
-
} else {
|
|
325
|
-
const label = textEl(NS, n.label, 0, n.r + 13, 10, 500, null);
|
|
326
|
-
g.append(label);
|
|
327
|
-
}
|
|
328
|
-
const tip = document.createElementNS(NS, "title");
|
|
329
|
-
tip.textContent = n.tooltip;
|
|
330
|
-
g.append(tip);
|
|
331
|
-
g.addEventListener("click", (event) => { event.stopPropagation(); n.onClick(); });
|
|
332
|
-
enableDrag(g, n);
|
|
333
|
-
root.append(g);
|
|
334
|
-
return { n, g };
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
function position() {
|
|
338
|
-
for (const { e, pathEl } of edgeEls) {
|
|
339
|
-
const a = byId.get(e.from), b = byId.get(e.to);
|
|
340
|
-
const dx = b.x - a.x, dy = b.y - a.y, d = Math.sqrt(dx * dx + dy * dy) || 1;
|
|
341
|
-
const ax = a.x + (dx / d) * a.r, ay = a.y + (dy / d) * a.r;
|
|
342
|
-
const bx = b.x - (dx / d) * (b.r + (e.style === "requires" ? 4 : 0)), by = b.y - (dy / d) * (b.r + (e.style === "requires" ? 4 : 0));
|
|
343
|
-
const mx = (ax + bx) / 2 - dy / d * d * 0.09, my = (ay + by) / 2 + dx / d * d * 0.09;
|
|
344
|
-
pathEl.setAttribute("d", `M ${ax} ${ay} Q ${mx} ${my} ${bx} ${by}`);
|
|
345
|
-
}
|
|
346
|
-
for (const { n, g } of nodeEls) g.setAttribute("transform", `translate(${n.x},${n.y})`);
|
|
347
|
-
}
|
|
348
|
-
const view = { x: 0, y: 0, k: 1 };
|
|
349
|
-
const applyView = () => root.setAttribute("transform", `translate(${view.x},${view.y}) scale(${view.k})`);
|
|
350
|
-
svg.addEventListener("wheel", (event) => {
|
|
351
|
-
event.preventDefault();
|
|
352
|
-
const factor = event.deltaY < 0 ? 1.12 : 0.9;
|
|
353
|
-
const next = Math.min(4, Math.max(0.25, view.k * factor));
|
|
354
|
-
view.x = event.offsetX - ((event.offsetX - view.x) / view.k) * next;
|
|
355
|
-
view.y = event.offsetY - ((event.offsetY - view.y) / view.k) * next;
|
|
356
|
-
view.k = next; applyView();
|
|
357
|
-
}, { passive: false });
|
|
358
|
-
let pan = null;
|
|
359
|
-
svg.addEventListener("mousedown", (event) => { if (event.target === svg) pan = { x: event.clientX - view.x, y: event.clientY - view.y }; });
|
|
360
|
-
window.addEventListener("mousemove", (event) => { if (pan) { view.x = event.clientX - pan.x; view.y = event.clientY - pan.y; applyView(); } });
|
|
361
|
-
window.addEventListener("mouseup", () => { pan = null; });
|
|
362
|
-
svg.addEventListener("click", () => highlight(null));
|
|
363
|
-
|
|
364
|
-
sim = { nodes: graph.nodes, edges: graph.edges, nodeEls, edgeEls, position, view };
|
|
365
|
-
position();
|
|
366
|
-
highlight(mode === "docs" ? selected : null);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function textEl(NS, content, x, y, size, weight, fill) {
|
|
370
|
-
const t = document.createElementNS(NS, "text");
|
|
371
|
-
t.setAttribute("text-anchor", "middle");
|
|
372
|
-
t.setAttribute("x", x); t.setAttribute("y", y);
|
|
373
|
-
t.setAttribute("font-size", size); t.setAttribute("font-weight", weight);
|
|
374
|
-
if (fill) t.style.fill = fill;
|
|
375
|
-
t.textContent = content;
|
|
376
|
-
return t;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function worstStatus(nodes) {
|
|
380
|
-
return nodes.reduce((worst, n) => (STATUS_RANK[n.status] > STATUS_RANK[worst] ? n.status : worst), "fresh");
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/* Topics 拓扑:topic 聚合节点 + root singletons,边 = 跨域文档关系聚合 */
|
|
384
|
-
function buildTopicGraph(width, height) {
|
|
385
|
-
const topics = [...new Set(state.nodes.map((n) => n.topic).filter(Boolean))].sort();
|
|
386
|
-
const nodes = [];
|
|
387
|
-
for (const topic of topics) {
|
|
388
|
-
const docs = state.nodes.filter((n) => n.topic === topic);
|
|
389
|
-
const tokens = docs.reduce((sum, n) => sum + n.estimatedTokens, 0);
|
|
390
|
-
nodes.push({
|
|
391
|
-
id: "topic:" + topic, isTopic: true, label: topic, subLabel: docs.length + " docs · ~" + tokens + " tk",
|
|
392
|
-
r: 26 + Math.min(26, Math.sqrt(tokens)), fill: colorOf(topic), status: worstStatus(docs),
|
|
393
|
-
tooltip: topic + "/\n" + docs.map((d) => "· " + d.path.split("/").pop()).join("\n"),
|
|
394
|
-
onClick: () => selectTopic(topic)
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
for (const n of state.nodes.filter((n) => !n.topic)) {
|
|
398
|
-
nodes.push({
|
|
399
|
-
id: "doc:" + n.path, isTopic: false, label: n.path.replace(/\.mdx$/, ""),
|
|
400
|
-
r: 10 + Math.min(9, Math.sqrt(n.estimatedTokens)), fill: colorOf(null), status: n.status,
|
|
401
|
-
tooltip: n.path + "\n" + n.description, onClick: () => selectDoc(n.path)
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
const groupOf = (path) => {
|
|
405
|
-
const node = state.nodes.find((n) => n.path === path);
|
|
406
|
-
return node ? (node.topic ? "topic:" + node.topic : "doc:" + path) : null;
|
|
407
|
-
};
|
|
408
|
-
const agg = new Map();
|
|
409
|
-
for (const e of state.edges) {
|
|
410
|
-
const a = groupOf(e.from), b = groupOf(e.to);
|
|
411
|
-
if (!a || !b || a === b) continue;
|
|
412
|
-
const key = [a, b].sort().join("→");
|
|
413
|
-
agg.set(key, (agg.get(key) ?? { from: a, to: b, count: 0 }));
|
|
414
|
-
agg.get(key).count += 1;
|
|
415
|
-
}
|
|
416
|
-
const edges = [...agg.values()].map((e) => ({ from: e.from, to: e.to, style: "aggregate", width: 1.4 + Math.min(6, e.count * 1.1) }));
|
|
417
|
-
simulate(nodes, edges, width, height, Math.min(width, height) / 3.1);
|
|
418
|
-
return { nodes, edges };
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/* Documents 全图 */
|
|
422
|
-
function buildDocGraph(width, height) {
|
|
423
|
-
const topics = [...new Set(state.nodes.map((n) => n.topic || "·root"))];
|
|
424
|
-
const centers = new Map(topics.map((topic, i) => {
|
|
425
|
-
const angle = (i / topics.length) * Math.PI * 2;
|
|
426
|
-
return [topic, { x: width / 2 + Math.cos(angle) * width / 4.6, y: height / 2 + Math.sin(angle) * height / 4.6 }];
|
|
427
|
-
}));
|
|
428
|
-
const nodes = state.nodes.map((n) => ({
|
|
429
|
-
id: n.path, isTopic: false,
|
|
430
|
-
label: n.path.split("/").pop().replace(/\.mdx$/, ""),
|
|
431
|
-
r: 8 + Math.min(11, Math.sqrt(n.estimatedTokens)), fill: colorOf(n.topic), status: n.status,
|
|
432
|
-
cluster: centers.get(n.topic || "·root"),
|
|
433
|
-
tooltip: n.path + "\n" + n.description, onClick: () => selectDoc(n.path)
|
|
434
|
-
}));
|
|
435
|
-
const edges = state.edges.map((e) => ({ from: e.from, to: e.to, style: e.type }));
|
|
436
|
-
simulate(nodes, edges, width, height, Math.min(width, height) / 5.2);
|
|
437
|
-
return { nodes, edges };
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
function enableDrag(g, node) {
|
|
441
|
-
g.addEventListener("mousedown", (event) => {
|
|
442
|
-
event.stopPropagation();
|
|
443
|
-
const start = { x: event.clientX, y: event.clientY, nx: node.x, ny: node.y };
|
|
444
|
-
const move = (e2) => { node.x = start.nx + (e2.clientX - start.x) / sim.view.k; node.y = start.ny + (e2.clientY - start.y) / sim.view.k; sim.position(); };
|
|
445
|
-
const up = () => { window.removeEventListener("mousemove", move); window.removeEventListener("mouseup", up); };
|
|
446
|
-
window.addEventListener("mousemove", move); window.addEventListener("mouseup", up);
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function highlight(id) {
|
|
451
|
-
if (!sim) return;
|
|
452
|
-
const neighbors = new Set();
|
|
453
|
-
if (id) {
|
|
454
|
-
neighbors.add(id);
|
|
455
|
-
for (const e of sim.edges) { if (e.from === id) neighbors.add(e.to); if (e.to === id) neighbors.add(e.from); }
|
|
456
|
-
}
|
|
457
|
-
for (const { n, g } of sim.nodeEls) g.setAttribute("class", "node" + (id && !neighbors.has(n.id) ? " dim" : ""));
|
|
458
|
-
for (const { e, pathEl } of sim.edgeEls) {
|
|
459
|
-
const cls = "edge-path" + (id && e.from !== id && e.to !== id ? " dim" : "");
|
|
460
|
-
pathEl.setAttribute("class", cls);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/* ---------- detail panel ---------- */
|
|
465
|
-
function setMode(next) {
|
|
466
|
-
mode = next;
|
|
467
|
-
document.getElementById("mode-topics").className = mode === "topics" ? "on" : "";
|
|
468
|
-
document.getElementById("mode-docs").className = mode === "docs" ? "on" : "";
|
|
469
|
-
if (state) renderGraph();
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
function selectTopic(topic) {
|
|
473
|
-
selected = null;
|
|
474
|
-
renderSidebar();
|
|
475
|
-
if (mode === "topics") highlight("topic:" + topic);
|
|
476
|
-
const docs = state.nodes.filter((n) => n.topic === topic);
|
|
477
|
-
const detail = document.querySelector("#detail .inner");
|
|
478
|
-
detail.innerHTML =
|
|
479
|
-
'<h2><span class="swatch" style="background:' + colorOf(topic) + ';width:12px;height:12px;border-radius:4px;display:inline-block;margin-right:7px"></span>' + topic + "/</h2>" +
|
|
480
|
-
'<div class="desc">' + docs.length + " docs · ~" + docs.reduce((s, n) => s + n.estimatedTokens, 0) + " tokens · " +
|
|
481
|
-
"状态最差 " + worstStatus(docs) + "</div>" +
|
|
482
|
-
docs.map((n) =>
|
|
483
|
-
'<div class="topic-doc-card" data-path="' + n.path + '">' +
|
|
484
|
-
'<div class="t"><span class="dot" style="width:7px;height:7px;border-radius:50%;background:' + STATUS_COLOR[n.status] + '"></span>' +
|
|
485
|
-
n.path.split("/").pop().replace(/\.mdx$/, "") + '<span style="margin-left:auto;color:var(--faint);font-size:10px;font-weight:500">' + n.kind + "</span></div>" +
|
|
486
|
-
'<div class="d">' + escapeHtml(n.description) + "</div>" +
|
|
487
|
-
"</div>"
|
|
488
|
-
).join("");
|
|
489
|
-
detail.querySelectorAll(".topic-doc-card").forEach((card) => { card.onclick = () => selectDoc(card.dataset.path); });
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
async function selectDoc(path) {
|
|
493
|
-
selected = path;
|
|
494
|
-
renderSidebar();
|
|
495
|
-
if (mode === "docs") highlight(path); else { setMode("docs"); highlight(path); }
|
|
496
|
-
const detail = document.querySelector("#detail .inner");
|
|
497
|
-
const response = await fetch("/api/doc?path=" + encodeURIComponent(path));
|
|
498
|
-
if (!response.ok) { detail.innerHTML = '<div class="placeholder">加载失败</div>'; return; }
|
|
499
|
-
const doc = await response.json();
|
|
500
|
-
const node = state.nodes.find((n) => n.path === path) || {};
|
|
501
|
-
const relations = doc.frontmatter.relations || {};
|
|
502
|
-
const relHtml = (list, label) => (list && list.length)
|
|
503
|
-
? '<div class="rel-block"><b>' + label + ":</b> " + list.map((t) => '<a class="rel-link" data-path="' + t + '">' + t + "</a>").join(" · ") + "</div>"
|
|
504
|
-
: "";
|
|
505
|
-
const body = (doc.body || "").replace(/<CodeRef\s+([^>]*?)\/>/g, (m, attrs) => {
|
|
506
|
-
const pathAttr = /path="([^"]*)"/.exec(attrs), symbol = /symbol="([^"]*)"/.exec(attrs);
|
|
507
|
-
return '<span class="coderef">⌁ ' + (pathAttr ? pathAttr[1] : "") + (symbol ? " · " + symbol[1] : "") + "</span>";
|
|
508
|
-
});
|
|
509
|
-
detail.innerHTML =
|
|
510
|
-
"<h2>" + path + "</h2>" +
|
|
511
|
-
'<div class="desc">' + escapeHtml(doc.frontmatter.description || "") + "</div>" +
|
|
512
|
-
'<div class="meta-row">' +
|
|
513
|
-
'<span class="chip">' + (doc.frontmatter.kind || "?") + "</span>" +
|
|
514
|
-
'<span class="chip" style="color:' + STATUS_COLOR[node.status || "fresh"] + '">' + (node.status || "") + "</span>" +
|
|
515
|
-
'<span class="chip">~' + doc.estimatedTokens + " tokens · " + doc.lineCount + " lines</span>" +
|
|
516
|
-
"</div>" +
|
|
517
|
-
relHtml(relations.requires, "requires") + relHtml(relations.related, "related") +
|
|
518
|
-
((doc.frontmatter.code && doc.frontmatter.code.paths && doc.frontmatter.code.paths.length)
|
|
519
|
-
? '<div class="meta-row">' + doc.frontmatter.code.paths.map((p) => '<span class="code-path">' + escapeHtml(p) + "</span>").join("") + "</div>"
|
|
520
|
-
: "") +
|
|
521
|
-
'<div id="doc-body">' + window.marked.parse(body) + "</div>";
|
|
522
|
-
detail.querySelectorAll(".rel-link").forEach((a) => { a.onclick = () => selectDoc(a.dataset.path); });
|
|
523
|
-
detail.querySelectorAll("#doc-body a[href]").forEach((a) => {
|
|
524
|
-
const href = a.getAttribute("href");
|
|
525
|
-
if (/^https?:|^mailto:|^#/.test(href)) { a.target = "_blank"; return; }
|
|
526
|
-
a.onclick = (event) => {
|
|
527
|
-
event.preventDefault();
|
|
528
|
-
const resolved = normalizePath(path.split("/").slice(0, -1).join("/") + "/" + href.split(/[?#]/)[0]);
|
|
529
|
-
if (state.nodes.some((n) => n.path === resolved)) selectDoc(resolved);
|
|
530
|
-
};
|
|
531
|
-
});
|
|
532
|
-
document.getElementById("detail").scrollTop = 0;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
function normalizePath(p) {
|
|
536
|
-
const parts = [];
|
|
537
|
-
for (const part of p.split("/")) {
|
|
538
|
-
if (!part || part === ".") continue;
|
|
539
|
-
if (part === "..") parts.pop(); else parts.push(part);
|
|
540
|
-
}
|
|
541
|
-
return parts.join("/");
|
|
542
|
-
}
|
|
543
|
-
function escapeHtml(text) { const div = document.createElement("div"); div.textContent = text; return div.innerHTML; }
|
|
544
|
-
|
|
545
|
-
document.getElementById("search").addEventListener("input", renderSidebar);
|
|
546
|
-
document.getElementById("refresh").addEventListener("click", loadState);
|
|
547
|
-
document.getElementById("mode-topics").addEventListener("click", () => setMode("topics"));
|
|
548
|
-
document.getElementById("mode-docs").addEventListener("click", () => setMode("docs"));
|
|
549
|
-
window.addEventListener("resize", () => state && renderGraph());
|
|
550
|
-
setMode("topics");
|
|
551
|
-
loadState();
|
|
552
|
-
</script>
|
|
13
|
+
<header class="app-header">
|
|
14
|
+
<h1>llmdoc <span class="repo" id="repo"></span></h1>
|
|
15
|
+
<div class="health-strip" aria-label="知识面状态">
|
|
16
|
+
<span class="chip" id="stat-docs"></span>
|
|
17
|
+
<span class="chip" id="stat-baseline"></span>
|
|
18
|
+
<span class="chip" id="stat-validate"></span>
|
|
19
|
+
<span class="chip" id="stat-delta"></span>
|
|
20
|
+
</div>
|
|
21
|
+
<button class="chip button" id="refresh" type="button" aria-label="刷新知识面">↻ 刷新</button>
|
|
22
|
+
<div class="toggle" role="group" aria-label="图谱显示模式">
|
|
23
|
+
<button id="mode-topics" type="button">Topics 拓扑</button>
|
|
24
|
+
<button id="mode-docs" type="button">Documents 全图</button>
|
|
25
|
+
</div>
|
|
26
|
+
</header>
|
|
27
|
+
|
|
28
|
+
<div id="load-error" class="load-error" role="alert" hidden></div>
|
|
29
|
+
|
|
30
|
+
<main>
|
|
31
|
+
<nav id="sidebar" aria-label="llmdoc 文档列表">
|
|
32
|
+
<label class="search-box">
|
|
33
|
+
<span class="sr-only">过滤文档</span>
|
|
34
|
+
<input id="search" type="search" placeholder="过滤路径、标题或描述" autocomplete="off" />
|
|
35
|
+
<kbd>/</kbd>
|
|
36
|
+
</label>
|
|
37
|
+
<div id="doc-list"></div>
|
|
38
|
+
</nav>
|
|
39
|
+
|
|
40
|
+
<section id="graph-wrap" aria-label="知识关系图">
|
|
41
|
+
<svg id="graph" role="application" tabindex="0" aria-label="知识关系图;可拖动画布、滚轮缩放,按 0 重置视图"></svg>
|
|
42
|
+
<div id="graph-hint" aria-live="polite"></div>
|
|
43
|
+
<div id="graph-toolbar" role="group" aria-label="图谱缩放控制">
|
|
44
|
+
<button id="zoom-out" type="button" title="缩小">−</button>
|
|
45
|
+
<button id="zoom-reset" type="button" title="重置视图">适应</button>
|
|
46
|
+
<button id="zoom-in" type="button" title="放大">+</button>
|
|
47
|
+
</div>
|
|
48
|
+
<div id="legend" aria-label="图例"></div>
|
|
49
|
+
<div id="graph-empty" hidden>没有可显示的文档</div>
|
|
50
|
+
</section>
|
|
51
|
+
|
|
52
|
+
<aside id="detail" aria-label="文档详情">
|
|
53
|
+
<button id="detail-close" type="button" aria-label="关闭详情">×</button>
|
|
54
|
+
<div class="inner"><div class="placeholder">选择一个 topic 或文档查看详情</div></div>
|
|
55
|
+
</aside>
|
|
56
|
+
</main>
|
|
553
57
|
</body>
|
|
554
58
|
</html>
|
package/dist/commands/context.js
CHANGED
|
@@ -20,7 +20,15 @@ export function runContext(options) {
|
|
|
20
20
|
absolutePath
|
|
21
21
|
};
|
|
22
22
|
});
|
|
23
|
-
const
|
|
23
|
+
const documentsByFile = normalizedFiles.map((file) => ({
|
|
24
|
+
file,
|
|
25
|
+
documents: workspace.documents.filter((document) => (document.frontmatter.code?.paths ?? []).some((pattern) => matchesCodePathPattern(pattern, file.normalized)))
|
|
26
|
+
}));
|
|
27
|
+
const impactedPaths = new Set(documentsByFile.flatMap(({ documents }) => documents.map((document) => document.llmdocPath)));
|
|
28
|
+
const impacted = workspace.documents.filter((document) => impactedPaths.has(document.llmdocPath));
|
|
29
|
+
const unmappedFiles = documentsByFile
|
|
30
|
+
.filter(({ documents }) => documents.length === 0)
|
|
31
|
+
.map(({ file }) => file.normalized);
|
|
24
32
|
const prerequisites = collectRequires(workspace, impacted);
|
|
25
33
|
const rows = [
|
|
26
34
|
...impacted.map((document) => ({ role: "impacted", document })),
|
|
@@ -35,6 +43,7 @@ export function runContext(options) {
|
|
|
35
43
|
return {
|
|
36
44
|
impacted: result.items.filter((row) => row.role === "impacted").map((row) => toPayload(row.document)),
|
|
37
45
|
prerequisites: result.items.filter((row) => row.role === "requires").map((row) => toPayload(row.document)),
|
|
46
|
+
unmappedFiles,
|
|
38
47
|
pagination: paginationMetadata(result)
|
|
39
48
|
};
|
|
40
49
|
}
|
|
@@ -45,6 +54,10 @@ export function runContext(options) {
|
|
|
45
54
|
lines.push(`${prefix} llmdoc/${document.llmdocPath} [${document.frontmatter.kind}]`);
|
|
46
55
|
lines.push(` ${document.frontmatter.description}`);
|
|
47
56
|
}
|
|
57
|
+
lines.push("", `unmapped files: ${unmappedFiles.length}`);
|
|
58
|
+
for (const file of unmappedFiles) {
|
|
59
|
+
lines.push(` unmapped -> ${file}`);
|
|
60
|
+
}
|
|
48
61
|
lines.push("", ...formatPaginationSummary(result));
|
|
49
62
|
return lines.join("\n");
|
|
50
63
|
}
|
package/dist/commands/serve.js
CHANGED
|
Binary file
|