@agent-wiki/mcp 0.17.9

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.
Files changed (217) hide show
  1. package/.claude-plugin/plugin.json +7 -0
  2. package/README.md +171 -0
  3. package/architecture.svg +58 -0
  4. package/dist/atlassian.d.ts +63 -0
  5. package/dist/atlassian.d.ts.map +1 -0
  6. package/dist/atlassian.js +596 -0
  7. package/dist/atlassian.js.map +1 -0
  8. package/dist/cli.d.ts +11 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +391 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/cobol/__tests__/call-boundary-lineage.test.d.ts +2 -0
  13. package/dist/cobol/__tests__/call-boundary-lineage.test.d.ts.map +1 -0
  14. package/dist/cobol/__tests__/call-boundary-lineage.test.js +505 -0
  15. package/dist/cobol/__tests__/call-boundary-lineage.test.js.map +1 -0
  16. package/dist/cobol/__tests__/code-analysis.test.d.ts +2 -0
  17. package/dist/cobol/__tests__/code-analysis.test.d.ts.map +1 -0
  18. package/dist/cobol/__tests__/code-analysis.test.js +465 -0
  19. package/dist/cobol/__tests__/code-analysis.test.js.map +1 -0
  20. package/dist/cobol/__tests__/db2-table-lineage.test.d.ts +2 -0
  21. package/dist/cobol/__tests__/db2-table-lineage.test.d.ts.map +1 -0
  22. package/dist/cobol/__tests__/db2-table-lineage.test.js +182 -0
  23. package/dist/cobol/__tests__/db2-table-lineage.test.js.map +1 -0
  24. package/dist/cobol/__tests__/evidence-mapping.test.d.ts +2 -0
  25. package/dist/cobol/__tests__/evidence-mapping.test.d.ts.map +1 -0
  26. package/dist/cobol/__tests__/evidence-mapping.test.js +49 -0
  27. package/dist/cobol/__tests__/evidence-mapping.test.js.map +1 -0
  28. package/dist/cobol/__tests__/extractors.test.d.ts +2 -0
  29. package/dist/cobol/__tests__/extractors.test.d.ts.map +1 -0
  30. package/dist/cobol/__tests__/extractors.test.js +189 -0
  31. package/dist/cobol/__tests__/extractors.test.js.map +1 -0
  32. package/dist/cobol/__tests__/field-lineage.test.d.ts +2 -0
  33. package/dist/cobol/__tests__/field-lineage.test.d.ts.map +1 -0
  34. package/dist/cobol/__tests__/field-lineage.test.js +329 -0
  35. package/dist/cobol/__tests__/field-lineage.test.js.map +1 -0
  36. package/dist/cobol/__tests__/graph.test.d.ts +2 -0
  37. package/dist/cobol/__tests__/graph.test.d.ts.map +1 -0
  38. package/dist/cobol/__tests__/graph.test.js +456 -0
  39. package/dist/cobol/__tests__/graph.test.js.map +1 -0
  40. package/dist/cobol/__tests__/integration.test.d.ts +2 -0
  41. package/dist/cobol/__tests__/integration.test.d.ts.map +1 -0
  42. package/dist/cobol/__tests__/integration.test.js +971 -0
  43. package/dist/cobol/__tests__/integration.test.js.map +1 -0
  44. package/dist/cobol/__tests__/lexer.test.d.ts +2 -0
  45. package/dist/cobol/__tests__/lexer.test.d.ts.map +1 -0
  46. package/dist/cobol/__tests__/lexer.test.js +111 -0
  47. package/dist/cobol/__tests__/lexer.test.js.map +1 -0
  48. package/dist/cobol/__tests__/parser.test.d.ts +2 -0
  49. package/dist/cobol/__tests__/parser.test.d.ts.map +1 -0
  50. package/dist/cobol/__tests__/parser.test.js +180 -0
  51. package/dist/cobol/__tests__/parser.test.js.map +1 -0
  52. package/dist/cobol/__tests__/variable-tracer.test.d.ts +2 -0
  53. package/dist/cobol/__tests__/variable-tracer.test.d.ts.map +1 -0
  54. package/dist/cobol/__tests__/variable-tracer.test.js +256 -0
  55. package/dist/cobol/__tests__/variable-tracer.test.js.map +1 -0
  56. package/dist/cobol/__tests__/wiki-gen.test.d.ts +2 -0
  57. package/dist/cobol/__tests__/wiki-gen.test.d.ts.map +1 -0
  58. package/dist/cobol/__tests__/wiki-gen.test.js +76 -0
  59. package/dist/cobol/__tests__/wiki-gen.test.js.map +1 -0
  60. package/dist/cobol/call-boundary-lineage.d.ts +49 -0
  61. package/dist/cobol/call-boundary-lineage.d.ts.map +1 -0
  62. package/dist/cobol/call-boundary-lineage.js +159 -0
  63. package/dist/cobol/call-boundary-lineage.js.map +1 -0
  64. package/dist/cobol/db2-table-lineage.d.ts +45 -0
  65. package/dist/cobol/db2-table-lineage.d.ts.map +1 -0
  66. package/dist/cobol/db2-table-lineage.js +127 -0
  67. package/dist/cobol/db2-table-lineage.js.map +1 -0
  68. package/dist/cobol/evidence-mapping.d.ts +31 -0
  69. package/dist/cobol/evidence-mapping.d.ts.map +1 -0
  70. package/dist/cobol/evidence-mapping.js +27 -0
  71. package/dist/cobol/evidence-mapping.js.map +1 -0
  72. package/dist/cobol/extractors.d.ts +88 -0
  73. package/dist/cobol/extractors.d.ts.map +1 -0
  74. package/dist/cobol/extractors.js +297 -0
  75. package/dist/cobol/extractors.js.map +1 -0
  76. package/dist/cobol/field-lineage.d.ts +101 -0
  77. package/dist/cobol/field-lineage.d.ts.map +1 -0
  78. package/dist/cobol/field-lineage.js +603 -0
  79. package/dist/cobol/field-lineage.js.map +1 -0
  80. package/dist/cobol/graph.d.ts +182 -0
  81. package/dist/cobol/graph.d.ts.map +1 -0
  82. package/dist/cobol/graph.js +453 -0
  83. package/dist/cobol/graph.js.map +1 -0
  84. package/dist/cobol/lexer.d.ts +15 -0
  85. package/dist/cobol/lexer.d.ts.map +1 -0
  86. package/dist/cobol/lexer.js +251 -0
  87. package/dist/cobol/lexer.js.map +1 -0
  88. package/dist/cobol/parser.d.ts +13 -0
  89. package/dist/cobol/parser.d.ts.map +1 -0
  90. package/dist/cobol/parser.js +584 -0
  91. package/dist/cobol/parser.js.map +1 -0
  92. package/dist/cobol/plugin.d.ts +23 -0
  93. package/dist/cobol/plugin.d.ts.map +1 -0
  94. package/dist/cobol/plugin.js +507 -0
  95. package/dist/cobol/plugin.js.map +1 -0
  96. package/dist/cobol/types.d.ts +73 -0
  97. package/dist/cobol/types.d.ts.map +1 -0
  98. package/dist/cobol/types.js +9 -0
  99. package/dist/cobol/types.js.map +1 -0
  100. package/dist/cobol/variable-tracer.d.ts +31 -0
  101. package/dist/cobol/variable-tracer.d.ts.map +1 -0
  102. package/dist/cobol/variable-tracer.js +361 -0
  103. package/dist/cobol/variable-tracer.js.map +1 -0
  104. package/dist/cobol/wiki-gen.d.ts +18 -0
  105. package/dist/cobol/wiki-gen.d.ts.map +1 -0
  106. package/dist/cobol/wiki-gen.js +222 -0
  107. package/dist/cobol/wiki-gen.js.map +1 -0
  108. package/dist/code-analysis.d.ts +160 -0
  109. package/dist/code-analysis.d.ts.map +1 -0
  110. package/dist/code-analysis.js +53 -0
  111. package/dist/code-analysis.js.map +1 -0
  112. package/dist/evidence-search.d.ts +43 -0
  113. package/dist/evidence-search.d.ts.map +1 -0
  114. package/dist/evidence-search.js +112 -0
  115. package/dist/evidence-search.js.map +1 -0
  116. package/dist/evidence-search.test.d.ts +2 -0
  117. package/dist/evidence-search.test.d.ts.map +1 -0
  118. package/dist/evidence-search.test.js +98 -0
  119. package/dist/evidence-search.test.js.map +1 -0
  120. package/dist/evidence.d.ts +32 -0
  121. package/dist/evidence.d.ts.map +1 -0
  122. package/dist/evidence.js +16 -0
  123. package/dist/evidence.js.map +1 -0
  124. package/dist/evidence.test.d.ts +2 -0
  125. package/dist/evidence.test.d.ts.map +1 -0
  126. package/dist/evidence.test.js +51 -0
  127. package/dist/evidence.test.js.map +1 -0
  128. package/dist/extraction.d.ts +40 -0
  129. package/dist/extraction.d.ts.map +1 -0
  130. package/dist/extraction.js +283 -0
  131. package/dist/extraction.js.map +1 -0
  132. package/dist/extraction.test.d.ts +5 -0
  133. package/dist/extraction.test.d.ts.map +1 -0
  134. package/dist/extraction.test.js +137 -0
  135. package/dist/extraction.test.js.map +1 -0
  136. package/dist/index.d.ts +38 -0
  137. package/dist/index.d.ts.map +1 -0
  138. package/dist/index.js +35 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/queue.d.ts +52 -0
  141. package/dist/queue.d.ts.map +1 -0
  142. package/dist/queue.js +139 -0
  143. package/dist/queue.js.map +1 -0
  144. package/dist/queue.test.d.ts +2 -0
  145. package/dist/queue.test.d.ts.map +1 -0
  146. package/dist/queue.test.js +161 -0
  147. package/dist/queue.test.js.map +1 -0
  148. package/dist/search.d.ts +163 -0
  149. package/dist/search.d.ts.map +1 -0
  150. package/dist/search.js +653 -0
  151. package/dist/search.js.map +1 -0
  152. package/dist/search.test.d.ts +6 -0
  153. package/dist/search.test.d.ts.map +1 -0
  154. package/dist/search.test.js +551 -0
  155. package/dist/search.test.js.map +1 -0
  156. package/dist/server.d.ts +33 -0
  157. package/dist/server.d.ts.map +1 -0
  158. package/dist/server.js +2530 -0
  159. package/dist/server.js.map +1 -0
  160. package/dist/server.test.d.ts +8 -0
  161. package/dist/server.test.d.ts.map +1 -0
  162. package/dist/server.test.js +2397 -0
  163. package/dist/server.test.js.map +1 -0
  164. package/dist/version.d.ts +2 -0
  165. package/dist/version.d.ts.map +1 -0
  166. package/dist/version.js +5 -0
  167. package/dist/version.js.map +1 -0
  168. package/dist/wiki.d.ts +496 -0
  169. package/dist/wiki.d.ts.map +1 -0
  170. package/dist/wiki.js +2677 -0
  171. package/dist/wiki.js.map +1 -0
  172. package/dist/wiki.test.d.ts +8 -0
  173. package/dist/wiki.test.d.ts.map +1 -0
  174. package/dist/wiki.test.js +1881 -0
  175. package/dist/wiki.test.js.map +1 -0
  176. package/docs/code-analysis-plugins.md +169 -0
  177. package/docs/configuration.md +135 -0
  178. package/docs/diagrams/cobol-analysis-flow.png +0 -0
  179. package/docs/diagrams/cobol-analysis-flow.svg +156 -0
  180. package/docs/evidence-envelope.md +176 -0
  181. package/docs/graph-1.gif +0 -0
  182. package/docs/legacy-code-knowledge-compiler-prd.md +511 -0
  183. package/docs/product-direction.md +120 -0
  184. package/docs/request-optimization.md +201 -0
  185. package/docs/search.md +266 -0
  186. package/docs/tools.md +269 -0
  187. package/graph-viewer/dist/cli.d.ts +3 -0
  188. package/graph-viewer/dist/cli.d.ts.map +1 -0
  189. package/graph-viewer/dist/cli.js +97 -0
  190. package/graph-viewer/dist/cli.js.map +1 -0
  191. package/graph-viewer/dist/graph.d.ts +14 -0
  192. package/graph-viewer/dist/graph.d.ts.map +1 -0
  193. package/graph-viewer/dist/graph.js +96 -0
  194. package/graph-viewer/dist/graph.js.map +1 -0
  195. package/graph-viewer/dist/index.d.ts +6 -0
  196. package/graph-viewer/dist/index.d.ts.map +1 -0
  197. package/graph-viewer/dist/index.js +4 -0
  198. package/graph-viewer/dist/index.js.map +1 -0
  199. package/graph-viewer/dist/parse.d.ts +10 -0
  200. package/graph-viewer/dist/parse.d.ts.map +1 -0
  201. package/graph-viewer/dist/parse.js +62 -0
  202. package/graph-viewer/dist/parse.js.map +1 -0
  203. package/graph-viewer/dist/server.d.ts +15 -0
  204. package/graph-viewer/dist/server.d.ts.map +1 -0
  205. package/graph-viewer/dist/server.js +168 -0
  206. package/graph-viewer/dist/server.js.map +1 -0
  207. package/graph-viewer/dist/types.d.ts +48 -0
  208. package/graph-viewer/dist/types.d.ts.map +1 -0
  209. package/graph-viewer/dist/types.js +2 -0
  210. package/graph-viewer/dist/types.js.map +1 -0
  211. package/graph-viewer/public/app.js +525 -0
  212. package/graph-viewer/public/index.html +68 -0
  213. package/graph-viewer/public/style.css +68 -0
  214. package/package.json +73 -0
  215. package/skills/aceclaw/SKILL.md +173 -0
  216. package/skills/agent-wiki/SKILL.md +184 -0
  217. package/skills/agent-wiki/references/tools-reference.md +368 -0
@@ -0,0 +1,525 @@
1
+ // Loaded directly by the browser as an ES module.
2
+ // 3d-force-graph is pulled from a CDN so nothing heavy ships with the core server.
3
+ import ForceGraph3D from "https://esm.sh/3d-force-graph@1.73.4";
4
+
5
+ /** Selection color — distinct from the hash-HSL palette (65% sat, 60% lightness). */
6
+ const SELECTED_COLOR = "#ffd60a";
7
+ /** Edit-pulse color (realtime change feedback). Cyan doesn't collide with yellow selection or red broken. */
8
+ const PULSE_COLOR = "#00e5ff";
9
+ /** Total pulse duration; the node blinks on/off every 200ms within this window. */
10
+ const PULSE_MS = 1200;
11
+ /** Soft lavender for highlighted links. Readable against dark bg without being gaudy. */
12
+ const LINK_HIGHLIGHT = "#b892ff";
13
+ /** Non-highlighted edges during hover/selection — slightly darker than base so
14
+ * highlighted ones stand out, but still visible so the graph doesn't "collapse"
15
+ * visually the moment anything is selected. */
16
+ const LINK_DIM = "#2a2d36";
17
+ /** Default edge color when nothing is highlighted. A cool lavender-grey — forms
18
+ * a quiet network backdrop, like Supermemory's constellation web. */
19
+ const LINK_BASE = "#3a3d4a";
20
+
21
+ const graphEl = document.getElementById("graph");
22
+ const statusEl = document.getElementById("status");
23
+ const colorModeEl = document.getElementById("colorMode");
24
+ const hideOrphansEl = document.getElementById("hideOrphans");
25
+ const hideBrokenEl = document.getElementById("hideBroken");
26
+ const searchEl = document.getElementById("search");
27
+ const sideEl = document.getElementById("side");
28
+ const sidePathEl = document.getElementById("sidePath");
29
+ const sideMetaEl = document.getElementById("sideMeta");
30
+ const sideLinksEl = document.getElementById("sideLinks");
31
+ document.getElementById("closeSide").onclick = () => clearSelection();
32
+
33
+ /** @typedef {{id:string, path:string, title:string, type?:string, topic:string, primaryTag?:string, tags:string[], sources:string[], degree:number, inDegree:number, outDegree:number, orphan:boolean, broken:boolean}} Node */
34
+ /** @typedef {{source:string, target:string, type:string}} Edge */
35
+ /** @type {{nodes:Node[], edges:Edge[], builtAt:string, wikiDir:string}} */
36
+ let currentGraph = { nodes: [], edges: [], builtAt: "", wikiDir: "" };
37
+ let selectedId = null;
38
+ let highlightNodes = new Set();
39
+ let highlightLinks = new Set();
40
+
41
+ /** id → pulse start time (performance.now()). Nodes in this map flash while within PULSE_MS. */
42
+ const pulses = new Map();
43
+ /** Content signature per node; used to detect what changed between graph snapshots. */
44
+ const prevNodeHashes = new Map();
45
+ let hasInitialGraph = false;
46
+ let pulseRafId = null;
47
+
48
+ /** A page is an "index hub" if its slug is the literal root index or ends with
49
+ * /index — these aggregate a topic and should read as landmarks in the graph. */
50
+ function isIndex(n) {
51
+ return n.id === "index" || n.id.endsWith("/index");
52
+ }
53
+
54
+ // Deterministic color hashing so topic/tag/type colors stay stable across reloads.
55
+ // Saturation/lightness tuned for a soft, pastel palette on dark bg — lower
56
+ // saturation than a typical hue wheel so nothing screams, high lightness so
57
+ // small nodes still read at a distance. `bright = true` lifts the shade for
58
+ // index hubs so they glow brighter than their topic's regular pages.
59
+ function colorFor(key, bright = false) {
60
+ if (!key) return bright ? "#f0e6d6" : "#7f8696";
61
+ let h = 0;
62
+ for (let i = 0; i < key.length; i++) h = (h * 31 + key.charCodeAt(i)) >>> 0;
63
+ const hue = h % 360;
64
+ return bright ? `hsl(${hue}, 60%, 82%)` : `hsl(${hue}, 45%, 72%)`;
65
+ }
66
+
67
+ function baseColor(n) {
68
+ if (n.broken) return "#e88a8a"; // softened red — not alarming, still readable
69
+ if (n.orphan) return "#545a66"; // muted grey for nodes with no incoming links
70
+ const mode = colorModeEl.value;
71
+ const key = mode === "topic" ? n.topic : mode === "tag" ? (n.primaryTag ?? "") : (n.type ?? "");
72
+ return colorFor(key, isIndex(n));
73
+ }
74
+
75
+ function pulseVisible(id, now) {
76
+ const start = pulses.get(id);
77
+ if (start === undefined) return false;
78
+ const age = now - start;
79
+ if (age > PULSE_MS) {
80
+ pulses.delete(id);
81
+ return false;
82
+ }
83
+ // Blink every 200ms inside the window so it reads as an active pulse, not a static recolor.
84
+ return Math.floor(age / 200) % 2 === 0;
85
+ }
86
+
87
+ function nodeColor(n) {
88
+ if (pulses.size && pulseVisible(n.id, performance.now())) return PULSE_COLOR;
89
+ if (n.id === selectedId) return SELECTED_COLOR;
90
+ // Deliberately do NOT dim non-neighborhood nodes. Doing so recolors a huge
91
+ // region of the canvas at once and reads as a jarring screen flash. Let the
92
+ // selected node's yellow + highlighted edge colors carry the signal.
93
+ return baseColor(n);
94
+ }
95
+
96
+ function nodeSize(n) {
97
+ // Small by default, gentle growth with degree. Matches the "constellation of
98
+ // tiny stars" feel — hubs read as slightly brighter points, not planets.
99
+ const base = 1.2 + Math.sqrt(n.degree || 0) * 0.9;
100
+ // Index hubs read as landmarks: ~2x the base size of a regular page. Combined
101
+ // with the brighter color this gives them clear visual weight without needing
102
+ // custom geometry.
103
+ return isIndex(n) ? base * 2 : base;
104
+ }
105
+
106
+ // Slug matched at word boundaries (^, /, -); title by substring. Strips ".md" suffix.
107
+ function matchesSearch(id, title, rawQuery) {
108
+ const q = rawQuery.endsWith(".md") ? rawQuery.slice(0, -3) : rawQuery;
109
+ if (!q) return false;
110
+ if ((title ?? "").toLowerCase().includes(q)) return true;
111
+ const escaped = q.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
112
+ return new RegExp("(^|[/\\-])" + escaped).test(id.toLowerCase());
113
+ }
114
+
115
+ function matchesFilter(n) {
116
+ if (hideOrphansEl.checked && n.orphan && !n.broken) return false;
117
+ if (hideBrokenEl.checked && n.broken) return false;
118
+ const q = searchEl.value.trim().toLowerCase();
119
+ if (!q) return true;
120
+ return matchesSearch(n.id, n.title, q);
121
+ }
122
+
123
+ const Graph = ForceGraph3D()(graphEl)
124
+ // Warm blue-black — not pure black, gives the scene some depth.
125
+ .backgroundColor("#0e1014")
126
+ .nodeId("id")
127
+ .nodeLabel((n) => `${n.title}${n.broken ? " (broken)" : ""}`)
128
+ .nodeColor(nodeColor)
129
+ .nodeVal(nodeSize)
130
+ // Slightly translucent nodes: reads as luminescent dots rather than hard solids.
131
+ .nodeOpacity(0.82)
132
+ .linkColor((l) => {
133
+ const k = linkKey(l);
134
+ if (highlightLinks.has(k)) return LINK_HIGHLIGHT;
135
+ if (highlightLinks.size) return LINK_DIM;
136
+ return LINK_BASE;
137
+ })
138
+ // Keep width at 0 — that's the default GPU hairline (1px). Any value > 0
139
+ // switches 3d-force-graph to a thick cylinder mesh, which looks heavy.
140
+ // Emphasis is expressed through color contrast + opacity, not thickness.
141
+ .linkWidth(0)
142
+ .linkOpacity(0.4)
143
+ .onNodeClick(onNodeClick)
144
+ .onNodeHover(onNodeHover)
145
+ .onBackgroundClick(clearSelection)
146
+ .onNodeDragEnd((n) => {
147
+ // Release the node so physics can continue to influence it. Remove if you
148
+ // prefer Obsidian-style pinning after drag.
149
+ n.fx = undefined;
150
+ n.fy = undefined;
151
+ n.fz = undefined;
152
+ });
153
+
154
+ // Pull every node gently toward the origin so disconnected components (orphan
155
+ // pages, tiny sub-graphs) don't drift off into empty space. The force is weak
156
+ // enough that the main cluster's shape is preserved, but strong enough that
157
+ // islands stay reachable without scrolling the camera forever.
158
+ // Inline force avoids pulling in d3-force-3d as a runtime CDN dep.
159
+ Graph.d3Force("pull-to-origin", pullToOrigin(0.04));
160
+
161
+ function pullToOrigin(strength) {
162
+ let nodes = [];
163
+ // d3-force calls the force with the simulation's cooling alpha (1 → 0). We
164
+ // must multiply by alpha so this force decays alongside repulsion; otherwise
165
+ // it stays full-strength and eventually crushes every node to the origin.
166
+ function force(alpha) {
167
+ const k = strength * alpha;
168
+ for (const n of nodes) {
169
+ n.vx -= (n.x || 0) * k;
170
+ n.vy -= (n.y || 0) * k;
171
+ n.vz -= (n.z || 0) * k;
172
+ }
173
+ }
174
+ force.initialize = (ns) => {
175
+ nodes = ns;
176
+ };
177
+ return force;
178
+ }
179
+
180
+ function clearSelection() {
181
+ selectedId = null;
182
+ highlightNodes = new Set();
183
+ highlightLinks = new Set();
184
+ sideEl.classList.add("hidden");
185
+ refreshColors();
186
+ }
187
+
188
+ function linkKey(l) {
189
+ const s = typeof l.source === "object" ? l.source.id : l.source;
190
+ const t = typeof l.target === "object" ? l.target.id : l.target;
191
+ return `${s}→${t}`;
192
+ }
193
+
194
+ function refreshColors() {
195
+ Graph.nodeColor(Graph.nodeColor()).linkColor(Graph.linkColor());
196
+ }
197
+
198
+ /** Compact signature of the fields we care about for "did this node change?" */
199
+ function nodeHash(n) {
200
+ return `${n.title}${n.type ?? ""}${n.topic}${n.inDegree}${n.outDegree}${n.broken ? 1 : 0}`;
201
+ }
202
+
203
+ /** Diff the incoming graph against the last one; start a pulse on anything new or changed. */
204
+ function markPulses(newGraph) {
205
+ const now = performance.now();
206
+ const nextIds = new Set();
207
+ for (const n of newGraph.nodes) {
208
+ nextIds.add(n.id);
209
+ const h = nodeHash(n);
210
+ if (prevNodeHashes.get(n.id) !== h) pulses.set(n.id, now);
211
+ prevNodeHashes.set(n.id, h);
212
+ }
213
+ for (const id of [...prevNodeHashes.keys()]) {
214
+ if (!nextIds.has(id)) prevNodeHashes.delete(id);
215
+ }
216
+ if (pulses.size > 0) startPulseLoop();
217
+ }
218
+
219
+ function startPulseLoop() {
220
+ if (pulseRafId !== null) return;
221
+ const tick = () => {
222
+ refreshColors();
223
+ if (pulses.size === 0) {
224
+ pulseRafId = null;
225
+ return;
226
+ }
227
+ pulseRafId = requestAnimationFrame(tick);
228
+ };
229
+ pulseRafId = requestAnimationFrame(tick);
230
+ }
231
+
232
+ function applyGraph(g) {
233
+ const isFirst = !hasInitialGraph;
234
+ currentGraph = g;
235
+
236
+ // Diff against the previous graph to trigger edit pulses — but on the very
237
+ // first load we just seed the hash map, otherwise every node would flash.
238
+ if (isFirst) {
239
+ for (const n of g.nodes) prevNodeHashes.set(n.id, nodeHash(n));
240
+ hasInitialGraph = true;
241
+ } else {
242
+ markPulses(g);
243
+ }
244
+
245
+ const visible = new Set(g.nodes.filter(matchesFilter).map((n) => n.id));
246
+
247
+ // When hiding orphans, cascade: nodes whose only connections were to orphans
248
+ // become visually isolated after orphan removal — hide them too.
249
+ // Search matches are exempt: a node the user explicitly searched for stays
250
+ // visible even if it becomes disconnected.
251
+ if (hideOrphansEl.checked) {
252
+ const q = searchEl.value.trim().toLowerCase();
253
+ const searchPinned = q
254
+ ? new Set(g.nodes
255
+ .filter((n) => visible.has(n.id) && matchesSearch(n.id, n.title, q))
256
+ .map((n) => n.id))
257
+ : new Set();
258
+ let changed = true;
259
+ while (changed) {
260
+ changed = false;
261
+ const connected = new Set();
262
+ for (const e of g.edges) {
263
+ if (visible.has(e.source) && visible.has(e.target)) {
264
+ connected.add(e.source);
265
+ connected.add(e.target);
266
+ }
267
+ }
268
+ const toRemove = [];
269
+ for (const id of visible) {
270
+ if (!connected.has(id) && !searchPinned.has(id)) toRemove.push(id);
271
+ }
272
+ for (const id of toRemove) visible.delete(id);
273
+ if (toRemove.length) changed = true;
274
+ }
275
+ }
276
+
277
+ const nodes = g.nodes.filter((n) => visible.has(n.id));
278
+ const links = g.edges
279
+ .filter((e) => visible.has(e.source) && visible.has(e.target))
280
+ .map((e) => ({ source: e.source, target: e.target }));
281
+ Graph.graphData({ nodes, links });
282
+
283
+ // If the selected node survived the update, refresh its highlight neighborhood
284
+ // against the new edges. Otherwise drop the selection.
285
+ if (selectedId) {
286
+ const stillPresent = visible.has(selectedId);
287
+ if (!stillPresent) {
288
+ clearSelection();
289
+ } else {
290
+ const { nodes: nn, links: ll } = neighborhood(selectedId, 2);
291
+ highlightNodes = nn;
292
+ highlightLinks = ll;
293
+ refreshColors();
294
+ }
295
+ }
296
+ }
297
+
298
+ function onNodeHover(n) {
299
+ if (!n) {
300
+ // If a node is selected, keep its neighborhood highlighted instead of
301
+ // clearing — otherwise selection becomes invisible the moment the cursor
302
+ // leaves the node.
303
+ if (selectedId) {
304
+ const { nodes, links } = neighborhood(selectedId, 2);
305
+ highlightNodes = nodes;
306
+ highlightLinks = links;
307
+ } else {
308
+ highlightNodes = new Set();
309
+ highlightLinks = new Set();
310
+ }
311
+ refreshColors();
312
+ return;
313
+ }
314
+ const { nodes, links } = neighborhood(n.id, 2);
315
+ highlightNodes = nodes;
316
+ highlightLinks = links;
317
+ refreshColors();
318
+ }
319
+
320
+ /** Track consecutive clicks on the same node to detect double-click ourselves —
321
+ * 3d-force-graph@1.73.4 doesn't expose onNodeDblClick. */
322
+ let lastClickNodeId = null;
323
+ let lastClickAt = 0;
324
+ const DBLCLICK_MS = 400;
325
+
326
+ function onNodeClick(n) {
327
+ const now = performance.now();
328
+ const isDouble = lastClickNodeId === n.id && now - lastClickAt < DBLCLICK_MS;
329
+ lastClickNodeId = n.id;
330
+ lastClickAt = now;
331
+
332
+ selectedId = n.id;
333
+ const { nodes, links } = neighborhood(n.id, 2);
334
+ highlightNodes = nodes;
335
+ highlightLinks = links;
336
+ refreshColors();
337
+ showSide(n);
338
+
339
+ if (isDouble) {
340
+ // Frame the 2-hop neighborhood so selected node + relations + edges are
341
+ // all in view together (Obsidian-style "focus on this cluster").
342
+ Graph.zoomToFit(700, 80, (node) => nodes.has(node.id));
343
+ }
344
+ // Single-click is intentionally non-disruptive: no camera motion.
345
+ }
346
+
347
+ function neighborhood(id, hops) {
348
+ const nodes = new Set([id]);
349
+ const links = new Set();
350
+ let frontier = new Set([id]);
351
+ for (let i = 0; i < hops; i++) {
352
+ const next = new Set();
353
+ for (const e of currentGraph.edges) {
354
+ if (frontier.has(e.source) && !nodes.has(e.target)) {
355
+ next.add(e.target);
356
+ links.add(`${e.source}→${e.target}`);
357
+ } else if (frontier.has(e.target) && !nodes.has(e.source)) {
358
+ next.add(e.source);
359
+ links.add(`${e.source}→${e.target}`);
360
+ } else if (frontier.has(e.source) || frontier.has(e.target)) {
361
+ links.add(`${e.source}→${e.target}`);
362
+ }
363
+ }
364
+ for (const x of next) nodes.add(x);
365
+ frontier = next;
366
+ }
367
+ return { nodes, links };
368
+ }
369
+
370
+ async function showSide(n) {
371
+ sideEl.classList.remove("hidden");
372
+ sidePathEl.textContent = n.broken ? `(broken) ${n.path}` : n.path;
373
+
374
+ const meta = [];
375
+ if (n.title) meta.push(["title", n.title]);
376
+ if (n.type) meta.push(["type", n.type]);
377
+ if (n.topic) meta.push(["topic", n.topic]);
378
+ if (n.tags?.length) meta.push(["tags", n.tags.join(", ")]);
379
+ if (n.sources?.length) meta.push(["sources", n.sources.join(", ")]);
380
+ meta.push(["degree", `${n.degree} (in ${n.inDegree}, out ${n.outDegree})`]);
381
+ if (n.orphan) meta.push(["status", "orphan"]);
382
+ if (n.broken) meta.push(["status", "broken link target"]);
383
+ sideMetaEl.innerHTML = meta.map(([k, v]) => `<dt>${k}</dt><dd>${escapeHtml(v)}</dd>`).join("");
384
+
385
+ const outgoing = currentGraph.edges.filter((e) => e.source === n.id);
386
+ const incoming = currentGraph.edges.filter((e) => e.target === n.id);
387
+ const idToNode = new Map(currentGraph.nodes.map((x) => [x.id, x]));
388
+
389
+ const renderList = (edges, which) =>
390
+ edges
391
+ .map((e) => {
392
+ const other = which === "out" ? e.target : e.source;
393
+ const node = idToNode.get(other);
394
+ const cls = node?.broken ? "broken" : "";
395
+ return `<li class="${cls}" data-id="${escapeAttr(other)}">${escapeHtml(node?.title ?? other)}</li>`;
396
+ })
397
+ .join("");
398
+
399
+ sideLinksEl.innerHTML = `
400
+ ${outgoing.length ? `<h3>outgoing (${outgoing.length})</h3><ul data-dir="out">${renderList(outgoing, "out")}</ul>` : ""}
401
+ ${incoming.length ? `<h3>incoming (${incoming.length})</h3><ul data-dir="in">${renderList(incoming, "in")}</ul>` : ""}
402
+ <h3>file</h3>
403
+ <div id="fileInfo">checking…</div>
404
+ `;
405
+
406
+ sideLinksEl.querySelectorAll("li").forEach((li) => {
407
+ li.onclick = () => {
408
+ const id = li.getAttribute("data-id");
409
+ const target = idToNode.get(id);
410
+ if (target) onNodeClick(target);
411
+ };
412
+ });
413
+
414
+ // Ask the server to resolve the absolute file path for copy/paste.
415
+ if (!n.broken) {
416
+ try {
417
+ const r = await fetch("/api/open", {
418
+ method: "POST",
419
+ headers: { "content-type": "application/json" },
420
+ body: JSON.stringify({ path: n.path }),
421
+ });
422
+ const data = await r.json();
423
+ const fileInfo = document.getElementById("fileInfo");
424
+ if (fileInfo) fileInfo.innerHTML = data.exists ? `<code>${escapeHtml(data.path)}</code>` : `<em>missing: ${escapeHtml(data.path)}</em>`;
425
+ } catch {
426
+ /* non-fatal */
427
+ }
428
+ } else {
429
+ const fileInfo = document.getElementById("fileInfo");
430
+ if (fileInfo) fileInfo.innerHTML = `<em>no file — this is a broken link target</em>`;
431
+ }
432
+ }
433
+
434
+ function escapeHtml(s) {
435
+ return String(s).replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
436
+ }
437
+ function escapeAttr(s) { return escapeHtml(s); }
438
+
439
+ // Wire filter controls
440
+ for (const el of [colorModeEl, hideOrphansEl, hideBrokenEl]) {
441
+ el.addEventListener("change", () => applyGraph(currentGraph));
442
+ }
443
+ let searchTimer;
444
+ searchEl.addEventListener("input", () => {
445
+ clearTimeout(searchTimer);
446
+ searchTimer = setTimeout(() => applyGraph(currentGraph), 80);
447
+ });
448
+
449
+ // Realtime: SSE stream from /api/events
450
+ function setStatus(text, cls) {
451
+ statusEl.textContent = text;
452
+ statusEl.className = `status ${cls ?? ""}`;
453
+ }
454
+
455
+ let statusRevertTimer = null;
456
+
457
+ function setLiveStatus(newGraph, before, isFirst) {
458
+ const after = newGraph.nodes.length;
459
+ const base = `live · ${after} nodes`;
460
+ let msg = base;
461
+ if (!isFirst) {
462
+ const delta = after - before;
463
+ if (delta !== 0) msg = `${base} (${delta > 0 ? "+" : ""}${delta})`;
464
+ else if (pulses.size > 0) msg = `${base} · updated`;
465
+ }
466
+ setStatus(msg, "ok");
467
+ // Transient annotations fade back to the plain count after ~2.5s.
468
+ if (statusRevertTimer) clearTimeout(statusRevertTimer);
469
+ if (msg !== base) statusRevertTimer = setTimeout(() => setStatus(base, "ok"), 2500);
470
+ }
471
+
472
+ function connect() {
473
+ setStatus("connecting…");
474
+ const es = new EventSource("/api/events");
475
+ es.addEventListener("graph", (ev) => {
476
+ const g = JSON.parse(ev.data);
477
+ const before = currentGraph.nodes.length;
478
+ const isFirst = !hasInitialGraph;
479
+ applyGraph(g);
480
+ setLiveStatus(g, before, isFirst);
481
+ });
482
+ es.addEventListener("error", () => {
483
+ setStatus("disconnected — retrying", "err");
484
+ });
485
+ es.addEventListener("open", () => setStatus("live", "ok"));
486
+ }
487
+ connect();
488
+
489
+ /** Move the camera toward or away from its current look-at by a multiplicative
490
+ * factor. < 1 = zoom in, > 1 = zoom out. Works regardless of the camera's
491
+ * current angle because we scale its position vector along the same direction. */
492
+ function zoomByFactor(factor) {
493
+ const cam = Graph.camera();
494
+ const p = cam.position;
495
+ Graph.cameraPosition({ x: p.x * factor, y: p.y * factor, z: p.z * factor }, undefined, 300);
496
+ }
497
+
498
+ function goHome() {
499
+ if (selectedId) clearSelection();
500
+ Graph.zoomToFit(600, 60);
501
+ }
502
+
503
+ document.getElementById("zoomOut").addEventListener("click", () => zoomByFactor(1.25));
504
+ document.getElementById("zoomIn").addEventListener("click", () => zoomByFactor(0.8));
505
+ document.getElementById("home").addEventListener("click", goHome);
506
+
507
+ document.addEventListener("keydown", (ev) => {
508
+ if (isTypingInInput(ev.target)) return;
509
+ if (ev.key === "Escape" && selectedId) clearSelection();
510
+ else if (ev.key === "f" || ev.key === "h") goHome();
511
+ else if (ev.key === "+" || ev.key === "=") zoomByFactor(0.8);
512
+ else if (ev.key === "-" || ev.key === "_") zoomByFactor(1.25);
513
+ });
514
+
515
+ function isTypingInInput(el) {
516
+ return el && (el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable);
517
+ }
518
+
519
+ // Also do an initial plain fetch in case SSE is blocked by an intermediary.
520
+ fetch("/api/graph")
521
+ .then((r) => r.json())
522
+ .then((g) => {
523
+ if (!currentGraph.nodes.length) applyGraph(g);
524
+ })
525
+ .catch(() => {});
@@ -0,0 +1,68 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>agent-wiki graph</title>
7
+ <link rel="stylesheet" href="/style.css" />
8
+ </head>
9
+ <body>
10
+ <header id="topbar">
11
+ <div class="title">agent-wiki graph</div>
12
+ <div class="controls">
13
+ <label>
14
+ color by
15
+ <select id="colorMode">
16
+ <option value="topic">topic (dir)</option>
17
+ <option value="tag">primary tag</option>
18
+ <option value="type">type</option>
19
+ </select>
20
+ </label>
21
+ <label>
22
+ <input type="checkbox" id="hideOrphans" /> hide orphans
23
+ </label>
24
+ <label>
25
+ <input type="checkbox" id="hideBroken" /> hide broken
26
+ </label>
27
+ <input type="search" id="search" placeholder="search title / slug…" />
28
+ <div class="btn-group">
29
+ <button id="zoomOut" type="button" title="zoom out (−)" aria-label="zoom out">−</button>
30
+ <button id="zoomIn" type="button" title="zoom in (+)" aria-label="zoom in">+</button>
31
+ <button id="home" type="button" title="home — fit all nodes and clear selection (f)">home</button>
32
+ </div>
33
+ <span id="status" class="status">connecting…</span>
34
+ </div>
35
+ </header>
36
+ <main id="graph"></main>
37
+ <aside id="side" class="hidden">
38
+ <button id="closeSide" aria-label="close">×</button>
39
+ <h2 id="sidePath"></h2>
40
+ <dl id="sideMeta"></dl>
41
+ <div id="sideLinks"></div>
42
+ </aside>
43
+ <script>
44
+ // Surface unhandled errors and module load failures directly in the UI
45
+ // so we never again get a silent "connecting…" with nothing in console.
46
+ (function () {
47
+ function show(msg) {
48
+ var s = document.getElementById("status");
49
+ if (s) {
50
+ s.textContent = msg;
51
+ s.className = "status err";
52
+ }
53
+ }
54
+ window.addEventListener("error", function (ev) {
55
+ if (ev.filename && ev.filename.indexOf("app.js") !== -1) {
56
+ show("script error: " + (ev.message || "unknown") + " (see DevTools Console)");
57
+ } else {
58
+ show("resource load failed: " + (ev.target && ev.target.src || ev.message || "unknown"));
59
+ }
60
+ }, true);
61
+ window.addEventListener("unhandledrejection", function (ev) {
62
+ show("unhandled: " + (ev.reason && ev.reason.message || ev.reason || "unknown"));
63
+ });
64
+ })();
65
+ </script>
66
+ <script type="module" src="/app.js"></script>
67
+ </body>
68
+ </html>
@@ -0,0 +1,68 @@
1
+ :root {
2
+ --bg: #0e1014;
3
+ --panel: #14171d;
4
+ --panel-2: #1c2028;
5
+ --fg: #e6edf3;
6
+ --fg-dim: #9aa7b4;
7
+ --accent: #b892ff;
8
+ --danger: #e88a8a;
9
+ --muted: #545a66;
10
+ }
11
+
12
+ * { box-sizing: border-box; }
13
+ html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
14
+ body { overflow: hidden; }
15
+
16
+ #topbar {
17
+ position: fixed; top: 0; left: 0; right: 0; z-index: 10;
18
+ display: flex; align-items: center; gap: 16px;
19
+ padding: 10px 16px;
20
+ background: rgba(14, 16, 20, 0.75);
21
+ backdrop-filter: blur(10px);
22
+ border-bottom: 1px solid var(--panel-2);
23
+ }
24
+ #topbar .title { font-weight: 600; letter-spacing: 0.3px; }
25
+ #topbar .controls { display: flex; align-items: center; gap: 12px; margin-left: auto; font-size: 13px; color: var(--fg-dim); }
26
+ #topbar select, #topbar input[type="search"], #topbar button {
27
+ background: var(--panel); color: var(--fg);
28
+ border: 1px solid var(--panel-2); border-radius: 6px;
29
+ padding: 4px 8px; font: inherit;
30
+ }
31
+ #topbar button { cursor: pointer; }
32
+ #topbar button:hover { background: var(--panel-2); }
33
+ #topbar .btn-group { display: inline-flex; gap: 0; }
34
+ #topbar .btn-group button {
35
+ border-radius: 0;
36
+ padding: 4px 10px;
37
+ min-width: 32px;
38
+ text-align: center;
39
+ border-right-width: 0;
40
+ }
41
+ #topbar .btn-group button:first-child { border-top-left-radius: 6px; border-bottom-left-radius: 6px; }
42
+ #topbar .btn-group button:last-child { border-top-right-radius: 6px; border-bottom-right-radius: 6px; border-right-width: 1px; }
43
+ #topbar input[type="search"] { min-width: 220px; }
44
+ #topbar .status { font-size: 12px; color: var(--fg-dim); }
45
+ #topbar .status.ok { color: #3fb950; }
46
+ #topbar .status.err { color: var(--danger); }
47
+
48
+ #graph { position: absolute; inset: 0; }
49
+
50
+ #side {
51
+ position: fixed; top: 52px; right: 0; bottom: 0; width: 360px; z-index: 9;
52
+ background: var(--panel); border-left: 1px solid var(--panel-2);
53
+ padding: 16px 20px; overflow-y: auto;
54
+ transform: translateX(0);
55
+ transition: transform 200ms ease;
56
+ }
57
+ #side.hidden { transform: translateX(100%); }
58
+ #side h2 { font-size: 14px; margin: 0 0 12px; word-break: break-all; color: var(--fg); }
59
+ #side #closeSide { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--fg-dim); font-size: 20px; cursor: pointer; }
60
+ #side dl { display: grid; grid-template-columns: 80px 1fr; gap: 6px 10px; font-size: 12px; margin: 0 0 12px; }
61
+ #side dt { color: var(--fg-dim); }
62
+ #side dd { margin: 0; word-break: break-word; }
63
+ #side #sideLinks { font-size: 12px; }
64
+ #side #sideLinks h3 { font-size: 12px; color: var(--fg-dim); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
65
+ #side #sideLinks ul { list-style: none; padding: 0; margin: 0; }
66
+ #side #sideLinks li { padding: 2px 0; color: var(--accent); cursor: pointer; }
67
+ #side #sideLinks li:hover { text-decoration: underline; }
68
+ #side #sideLinks li.broken { color: var(--danger); }