code-kg 0.1.11 → 0.1.13

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/dist/server/ui.js CHANGED
@@ -673,6 +673,22 @@ function renderUiHtml() {
673
673
  return EDGE_COLORS[key] || '#82cf34';
674
674
  }
675
675
 
676
+ function normalizeEndpointId(raw) {
677
+ if (typeof raw === 'string') {
678
+ return raw;
679
+ }
680
+ if (typeof raw === 'number' && Number.isFinite(raw)) {
681
+ return String(raw);
682
+ }
683
+ if (typeof raw === 'bigint') {
684
+ return String(raw);
685
+ }
686
+ if (raw && typeof raw === 'object' && 'id' in raw) {
687
+ return normalizeEndpointId(raw.id);
688
+ }
689
+ return '';
690
+ }
691
+
676
692
  function isQualityMode(value) {
677
693
  return value === 'normal' || value === 'degraded' || value === 'extreme';
678
694
  }
@@ -991,9 +1007,9 @@ function renderUiHtml() {
991
1007
  node.x = x;
992
1008
  node.y = y;
993
1009
  node.z = z;
994
- node.fx = x;
995
- node.fy = y;
996
- node.fz = z;
1010
+ node.fx = undefined;
1011
+ node.fy = undefined;
1012
+ node.fz = undefined;
997
1013
  node.__renderVisible = true;
998
1014
  nodeById.set(node.id, node);
999
1015
  }
@@ -1206,16 +1222,32 @@ function renderUiHtml() {
1206
1222
 
1207
1223
  const usingWasmLayout = isWasmLayoutEngine(state.layoutEngine);
1208
1224
  if (typeof graph.cooldownTicks === 'function') {
1209
- graph.cooldownTicks(usingWasmLayout ? 0 : mode === 'normal' ? 220 : mode === 'degraded' ? 72 : 28);
1225
+ graph.cooldownTicks(
1226
+ usingWasmLayout
1227
+ ? (mode === 'normal' ? 96 : mode === 'degraded' ? 42 : 20)
1228
+ : (mode === 'normal' ? 220 : mode === 'degraded' ? 72 : 28)
1229
+ );
1210
1230
  }
1211
1231
  if (typeof graph.cooldownTime === 'function') {
1212
- graph.cooldownTime(usingWasmLayout ? 0 : mode === 'normal' ? 9000 : mode === 'degraded' ? 2200 : 900);
1232
+ graph.cooldownTime(
1233
+ usingWasmLayout
1234
+ ? (mode === 'normal' ? 3200 : mode === 'degraded' ? 1700 : 900)
1235
+ : (mode === 'normal' ? 9000 : mode === 'degraded' ? 2200 : 900)
1236
+ );
1213
1237
  }
1214
1238
  if (typeof graph.warmupTicks === 'function') {
1215
- graph.warmupTicks(usingWasmLayout ? 0 : mode === 'normal' ? 60 : mode === 'degraded' ? 12 : 4);
1239
+ graph.warmupTicks(
1240
+ usingWasmLayout
1241
+ ? (mode === 'normal' ? 14 : mode === 'degraded' ? 7 : 4)
1242
+ : (mode === 'normal' ? 60 : mode === 'degraded' ? 12 : 4)
1243
+ );
1216
1244
  }
1217
1245
  if (typeof graph.d3VelocityDecay === 'function') {
1218
- graph.d3VelocityDecay(usingWasmLayout ? 0.9 : mode === 'normal' ? 0.28 : mode === 'degraded' ? 0.4 : 0.58);
1246
+ graph.d3VelocityDecay(
1247
+ usingWasmLayout
1248
+ ? (mode === 'normal' ? 0.36 : mode === 'degraded' ? 0.46 : 0.58)
1249
+ : (mode === 'normal' ? 0.28 : mode === 'degraded' ? 0.4 : 0.58)
1250
+ );
1219
1251
  }
1220
1252
  if (typeof graph.nodeResolution === 'function') {
1221
1253
  graph.nodeResolution(mode === 'normal' ? 6 : mode === 'degraded' ? 4 : 3);
@@ -1248,20 +1280,11 @@ function renderUiHtml() {
1248
1280
  if (typeof graph.d3Force === 'function') {
1249
1281
  const currentCharge = graph.d3Force('charge');
1250
1282
  const currentLink = graph.d3Force('link');
1251
- if (!usingWasmLayout && mode === 'normal') {
1252
- if (state.defaultChargeForce && currentCharge == null) {
1253
- graph.d3Force('charge', state.defaultChargeForce);
1254
- }
1255
- if (state.defaultLinkForce && currentLink == null) {
1256
- graph.d3Force('link', state.defaultLinkForce);
1257
- }
1258
- } else {
1259
- if (currentCharge != null) {
1260
- graph.d3Force('charge', null);
1261
- }
1262
- if (currentLink != null) {
1263
- graph.d3Force('link', null);
1264
- }
1283
+ if (state.defaultChargeForce && currentCharge == null) {
1284
+ graph.d3Force('charge', state.defaultChargeForce);
1285
+ }
1286
+ if (state.defaultLinkForce && currentLink == null) {
1287
+ graph.d3Force('link', state.defaultLinkForce);
1265
1288
  }
1266
1289
  }
1267
1290
 
@@ -1298,30 +1321,37 @@ function renderUiHtml() {
1298
1321
  const rawEdges = Array.isArray(apiData && apiData.edges) ? apiData.edges : [];
1299
1322
  const degree = Object.create(null);
1300
1323
  const links = [];
1324
+ const nodeIdSet = new Set();
1325
+
1326
+ for (let i = 0; i < rawNodes.length; i += 1) {
1327
+ const rawNode = rawNodes[i];
1328
+ if (!rawNode || typeof rawNode !== 'object') {
1329
+ continue;
1330
+ }
1331
+ const normalizedNodeId = normalizeEndpointId(rawNode.id);
1332
+ if (normalizedNodeId.length > 0) {
1333
+ nodeIdSet.add(normalizedNodeId);
1334
+ }
1335
+ }
1301
1336
 
1302
1337
  for (let i = 0; i < rawEdges.length; i += 1) {
1303
1338
  const edge = rawEdges[i];
1304
- const sourceRaw = edge.fromId || edge.from || edge.source;
1305
- const targetRaw = edge.toId || edge.to || edge.target;
1306
- const source = typeof sourceRaw === 'string'
1307
- ? sourceRaw
1308
- : sourceRaw && sourceRaw.id
1309
- ? String(sourceRaw.id)
1310
- : '';
1311
- const target = typeof targetRaw === 'string'
1312
- ? targetRaw
1313
- : targetRaw && targetRaw.id
1314
- ? String(targetRaw.id)
1315
- : '';
1339
+ const sourceRaw = edge.fromId || edge.from_id || edge.from || edge.sourceId || edge.source_id || edge.source;
1340
+ const targetRaw = edge.toId || edge.to_id || edge.to || edge.targetId || edge.target_id || edge.target;
1341
+ const source = normalizeEndpointId(sourceRaw);
1342
+ const target = normalizeEndpointId(targetRaw);
1316
1343
 
1317
1344
  if (source.length === 0 || target.length === 0) {
1318
1345
  continue;
1319
1346
  }
1347
+ if (nodeIdSet.size > 0 && (!nodeIdSet.has(source) || !nodeIdSet.has(target))) {
1348
+ continue;
1349
+ }
1320
1350
  degree[source] = (degree[source] || 0) + 1;
1321
1351
  degree[target] = (degree[target] || 0) + 1;
1322
1352
 
1323
1353
  links.push({
1324
- id: edge.id,
1354
+ id: edge.id || ('edge:' + i + ':' + source + '->' + target),
1325
1355
  source,
1326
1356
  target,
1327
1357
  __sourceId: source,
@@ -1336,7 +1366,7 @@ function renderUiHtml() {
1336
1366
  const nodes = new Array(rawNodes.length);
1337
1367
  for (let i = 0; i < rawNodes.length; i += 1) {
1338
1368
  const node = rawNodes[i];
1339
- const nodeId = String(node.id || '');
1369
+ const nodeId = normalizeEndpointId(node.id);
1340
1370
  const d = degree[nodeId] || 0;
1341
1371
  const name = node.name || node.id || 'node';
1342
1372
  const type = node.type || 'unknown';
@@ -1383,7 +1413,7 @@ function renderUiHtml() {
1383
1413
  })(els.graphCanvas)
1384
1414
  .backgroundColor('#01040f')
1385
1415
  .showNavInfo(false)
1386
- .nodeOpacity(0.92)
1416
+ .nodeOpacity(0.82)
1387
1417
  .nodeVisibility((node) => node.__renderVisible !== false)
1388
1418
  .nodeLabel((node) => {
1389
1419
  const name = String(node.name || node.id || 'node');
@@ -1593,14 +1623,15 @@ function renderUiHtml() {
1593
1623
  if (limit > 0) {
1594
1624
  graphUrl += '&limit=' + encodeURIComponent(String(limit));
1595
1625
  }
1596
- const data = await readEnvelope(graphUrl);
1597
- state.graphData = toGraphData(data);
1626
+ let selectedPayload = await readEnvelope(graphUrl);
1627
+ state.graphData = toGraphData(selectedPayload);
1598
1628
 
1599
1629
  if (state.graphData.links.length === 0 && state.graphData.nodes.length > 1 && view !== 'fileDeps') {
1600
1630
  const fallbackData = await readEnvelope('/api/graph?view=fileDeps');
1601
1631
  const fallbackGraph = toGraphData(fallbackData);
1602
1632
  if (fallbackGraph.links.length > 0) {
1603
1633
  state.graphData = fallbackGraph;
1634
+ selectedPayload = fallbackData;
1604
1635
  state.view = 'fileDeps';
1605
1636
  if (els.view) {
1606
1637
  els.view.value = 'fileDeps';
@@ -1608,13 +1639,14 @@ function renderUiHtml() {
1608
1639
  }
1609
1640
  }
1610
1641
  const normalizedMeta = normalizeGraphMeta(
1611
- data && data.meta ? data.meta : null,
1642
+ selectedPayload && selectedPayload.meta ? selectedPayload.meta : null,
1612
1643
  state.graphData.nodes.length,
1613
1644
  state.graphData.links.length
1614
1645
  );
1615
1646
  state.graphMeta = normalizedMeta;
1647
+ const layoutSeedView = state.view === 'all' ? 'all' : state.view;
1616
1648
  const usedWasm = await applyWasmLayout(
1617
- view + ':' + state.graphData.nodes.length + ':' + state.graphData.links.length
1649
+ layoutSeedView + ':' + state.graphData.nodes.length + ':' + state.graphData.links.length
1618
1650
  );
1619
1651
  if (!usedWasm) {
1620
1652
  state.layoutEngine = 'js';
@@ -1 +1 @@
1
- {"version":3,"file":"ui.js","sourceRoot":"","sources":["../../src/server/ui.ts"],"names":[],"mappings":";;AAEA,oCA88DC;AAh9DD,2DAAmE;AAEnE,SAAgB,YAAY;IAC1B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAo7C3D,CAAC;AACT,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-kg",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Local code knowledge graph CLI with interactive visualization and deterministic analysis APIs",
5
5
  "license": "MIT",
6
6
  "keywords": [