@atolis-hq/corum 0.1.66 → 0.1.67

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.
@@ -39,6 +39,10 @@ export function isVisibleEdgeType(graph, type) {
39
39
  return true;
40
40
  return def.category !== 'structural' && def.hidden !== true;
41
41
  }
42
+ /** Soft-removed edges (state 'removed') are kept for history but not followed by default traversals. */
43
+ export function isLiveEdge(edge) {
44
+ return edge.state !== 'removed';
45
+ }
42
46
  export function getVisibleEdgeTypes(graph) {
43
47
  return [...(graph.edgeTypes ?? CORE_EDGE_TYPE_MAP).values()]
44
48
  .filter(def => def.category !== 'structural' && def.hidden !== true)
@@ -90,7 +94,7 @@ export function getCluster(graph, nodeId) {
90
94
  const seen = new Set();
91
95
  for (const id of clusterIds) {
92
96
  for (const edge of graph.edgesByFrom.get(id) ?? []) {
93
- if (clusterIds.has(edge.to) && !seen.has(edge.id)) {
97
+ if (clusterIds.has(edge.to) && isLiveEdge(edge) && !seen.has(edge.id)) {
94
98
  edges.push(edge);
95
99
  seen.add(edge.id);
96
100
  }
@@ -124,13 +128,13 @@ export function getClusterView(graph, nodeId, includeEdgeTypes = []) {
124
128
  const seen = new Set(cluster.edges.map(edge => edge.id));
125
129
  for (const id of clusterIds) {
126
130
  for (const edge of graph.edgesByFrom.get(id) ?? []) {
127
- if (!requestedTypes.has(edge.type) || seen.has(edge.id))
131
+ if (!requestedTypes.has(edge.type) || !isLiveEdge(edge) || seen.has(edge.id))
128
132
  continue;
129
133
  edges.push(edge);
130
134
  seen.add(edge.id);
131
135
  }
132
136
  for (const edge of graph.edgesByTo.get(id) ?? []) {
133
- if (!inboundTypes.has(edge.type) || seen.has(edge.id))
137
+ if (!inboundTypes.has(edge.type) || !isLiveEdge(edge) || seen.has(edge.id))
134
138
  continue;
135
139
  edges.push(edge);
136
140
  seen.add(edge.id);
@@ -187,7 +191,7 @@ export function expandExternalNodes(graph, externalIds) {
187
191
  }
188
192
  // Follow outbound uses-type one hop to collect referenced enum/schema types
189
193
  for (const edge of graph.edgesByFrom.get(id) ?? []) {
190
- if (edge.type !== 'uses-type' || result.has(edge.to))
194
+ if (edge.type !== 'uses-type' || !isLiveEdge(edge) || result.has(edge.to))
191
195
  continue;
192
196
  const target = graph.nodesById.get(edge.to);
193
197
  if (!target)
@@ -222,7 +226,7 @@ export function getLinkedFields(graph, nodeId) {
222
226
  // dangling. Edges are returned as authored; node IDs are the live ones.
223
227
  for (const edgeList of graph.edgesByFrom.values()) {
224
228
  for (const edge of edgeList) {
225
- if (edge.type !== 'maps-to' || seen.has(edge.id))
229
+ if (edge.type !== 'maps-to' || !isLiveEdge(edge) || seen.has(edge.id))
226
230
  continue;
227
231
  const from = resolveLive(edge.from);
228
232
  const to = resolveLive(edge.to);
@@ -302,7 +306,7 @@ export function getGraphSummary(graph) {
302
306
  const edgesByType = {};
303
307
  for (const edgeList of graph.edgesByFrom.values()) {
304
308
  for (const edge of edgeList) {
305
- if (!isVisibleEdgeType(graph, edge.type))
309
+ if (!isLiveEdge(edge) || !isVisibleEdgeType(graph, edge.type))
306
310
  continue;
307
311
  edgesByType[edge.type] = (edgesByType[edge.type] ?? 0) + 1;
308
312
  nodesWithEdges.add(edge.from);
@@ -392,7 +396,7 @@ export function getLineage(graph, startNodeIds, options = {}) {
392
396
  const defaultEdgeTypes = new Set();
393
397
  for (const edgeList of graph.edgesByFrom.values()) {
394
398
  for (const edge of edgeList) {
395
- if (isVisibleEdgeType(graph, edge.type))
399
+ if (isLiveEdge(edge) && isVisibleEdgeType(graph, edge.type))
396
400
  defaultEdgeTypes.add(edge.type);
397
401
  }
398
402
  }
@@ -444,7 +448,7 @@ export function getLineage(graph, startNodeIds, options = {}) {
444
448
  if (current.distance >= depth)
445
449
  continue;
446
450
  for (const edge of graph.edgesByFrom.get(current.id) ?? []) {
447
- if (!edgeTypeSet.has(edge.type))
451
+ if (!isLiveEdge(edge) || !edgeTypeSet.has(edge.type))
448
452
  continue;
449
453
  const toId = resolveLive(edge.to);
450
454
  const node = graph.nodesById.get(toId);
@@ -470,7 +474,7 @@ export function getLineage(graph, startNodeIds, options = {}) {
470
474
  if (current.distance >= depth)
471
475
  continue;
472
476
  for (const edge of graph.edgesByTo.get(current.id) ?? []) {
473
- if (!inboundTypeSet.has(edge.type))
477
+ if (!isLiveEdge(edge) || !inboundTypeSet.has(edge.type))
474
478
  continue;
475
479
  const fromId = resolveLive(edge.from);
476
480
  const node = graph.nodesById.get(fromId);
@@ -510,7 +514,7 @@ export function getLineage(graph, startNodeIds, options = {}) {
510
514
  const nodesWithEdges = new Set();
511
515
  for (const id of combinedSet) {
512
516
  for (const edge of graph.edgesByFrom.get(id) ?? []) {
513
- if (seenEdgeIds.has(edge.id) || !edgeTypeSet.has(edge.type))
517
+ if (seenEdgeIds.has(edge.id) || !isLiveEdge(edge) || !edgeTypeSet.has(edge.type))
514
518
  continue;
515
519
  // Endpoints resolve through the alias map so an edge referencing a
516
520
  // retired ID still connects to the live node it was traversed to.
@@ -536,7 +540,7 @@ export function getLineage(graph, startNodeIds, options = {}) {
536
540
  for (const edge of [...(graph.edgesByFrom.get(id) ?? []), ...(graph.edgesByTo.get(id) ?? [])]) {
537
541
  if (danglingSeenIds.has(edge.id) || seenEdgeIds.has(edge.id))
538
542
  continue;
539
- if (!edgeTypeSet.has(edge.type))
543
+ if (!isLiveEdge(edge) || !edgeTypeSet.has(edge.type))
540
544
  continue;
541
545
  const from = resolveLive(edge.from);
542
546
  const to = resolveLive(edge.to);
@@ -1,4 +1,4 @@
1
- import { getStructuralNodeTemplates, isVisibleEdgeType, isOwnedDescendant } from './index.js';
1
+ import { getStructuralNodeTemplates, isLiveEdge, isVisibleEdgeType, isOwnedDescendant } from './index.js';
2
2
  import { getTemplateRole } from './roles.js';
3
3
  const FIELD_EDGE_TYPES = new Set(['maps-to', 'derived-from']);
4
4
  export function collapseClusterSchemas(graph, cluster) {
@@ -138,7 +138,7 @@ function buildField(fieldNode, graph, rootId, parentMappings) {
138
138
  // Gather outbound field edges that cross the cluster boundary
139
139
  const fieldEdges = {};
140
140
  for (const e of graph.edgesByFrom.get(fieldNode.id) ?? []) {
141
- if (!FIELD_EDGE_TYPES.has(e.type))
141
+ if (!FIELD_EDGE_TYPES.has(e.type) || !isLiveEdge(e))
142
142
  continue;
143
143
  if (isOwnedDescendant(graph, e.to, rootId))
144
144
  continue;
@@ -51,6 +51,7 @@ export function loadEdges(content, nodes, diagnostics, edgeTypes = CORE_EDGE_TYP
51
51
  state: resolveState(edgeRecord.state, diagnostics, key),
52
52
  stability: resolveStability(edgeRecord.stability, diagnostics, key),
53
53
  notes: typeof edgeRecord.notes === 'string' ? edgeRecord.notes : undefined,
54
+ ...(typeof edgeRecord.lastModifiedAt === 'string' && { lastModifiedAt: edgeRecord.lastModifiedAt }),
54
55
  ...(typeof properties === 'object' && properties !== null && !Array.isArray(properties) && {
55
56
  properties: properties,
56
57
  }),
@@ -3,7 +3,7 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
3
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
4
  import { CallToolRequestSchema, GetPromptRequestSchema, ListPromptsRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
5
5
  import { pathToFileURL } from 'node:url';
6
- import { computeClusterOverlay, expandExternalNodes, getClusterView, getGraphSummary, getLineage, getLinkedFields, getKindRegistry, getNamespaces, getStructuralNodeTemplates, getVisibleEdgeTypes, isVisibleEdgeType, listNodes, searchNodes, } from '../graph/index.js';
6
+ import { computeClusterOverlay, expandExternalNodes, getClusterView, getGraphSummary, getLineage, getLinkedFields, getKindRegistry, getNamespaces, getStructuralNodeTemplates, getVisibleEdgeTypes, isLiveEdge, isVisibleEdgeType, listNodes, searchNodes, } from '../graph/index.js';
7
7
  import { loadGraph, loadMultiGraph } from '../loader/index.js';
8
8
  import { QueryError } from '../schema/index.js';
9
9
  import { MutationError, getActiveSession, startSession } from '../mutate/index.js';
@@ -346,7 +346,7 @@ export function createMcpHandlers(graph, source, cache) {
346
346
  const edges = [];
347
347
  for (const edgeList of targetGraph.edgesByFrom.values()) {
348
348
  for (const edge of edgeList) {
349
- if (!isVisibleEdgeType(targetGraph, edge.type) || !nodeIds.has(edge.from) || !nodeIds.has(edge.to))
349
+ if (!isLiveEdge(edge) || !isVisibleEdgeType(targetGraph, edge.type) || !nodeIds.has(edge.from) || !nodeIds.has(edge.to))
350
350
  continue;
351
351
  edges.push({ id: edge.id, from: edge.from, to: edge.to, type: edge.type });
352
352
  }
@@ -1,3 +1,4 @@
1
+ import { isVisibleEdgeType } from '../graph/index.js';
1
2
  import { MutationError } from './errors.js';
2
3
  import { shouldRecordTrail } from './rename.js';
3
4
  import { collectEdgesTouching, collectSubtreeIds, findEdgeById, mutationDiagnostic, mutationTimestamp, removeEdgeFromIndexes, } from './util.js';
@@ -25,7 +26,19 @@ export function deleteNode(graph, nodeId, opts = {}, defaultBranchIds) {
25
26
  subtreeNode.state = 'removed';
26
27
  subtreeNode.lastModifiedAt = timestamp;
27
28
  }
28
- return { tier: 'soft', affectedIds: subtreeIds };
29
+ // Cascade: explicit, non-hidden edges touching the subtree stop being live.
30
+ // Edges are kept (like the removed nodes); trail and structural edges are untouched.
31
+ let removedEdgeCount = 0;
32
+ for (const edge of collectEdgesTouching(graph, subtreeIds)) {
33
+ if (edge.generated || edge.state === 'removed')
34
+ continue;
35
+ if (!isVisibleEdgeType(graph, edge.type))
36
+ continue;
37
+ edge.state = 'removed';
38
+ edge.lastModifiedAt = timestamp;
39
+ removedEdgeCount++;
40
+ }
41
+ return { tier: 'soft', affectedIds: subtreeIds, removedEdgeCount };
29
42
  }
30
43
  // Hard delete: remove subtree nodes and every edge touching any removed ID
31
44
  // from both indexes — no orphan edges survive.
@@ -117,7 +117,7 @@ export class WorkingSession {
117
117
  async deleteNode(id, opts = {}) {
118
118
  this.assertOpen();
119
119
  const result = deleteNodePrimitive(this.graph, id, opts, this.defaultBranchIds);
120
- const summary = `delete ${id} (${result.tier}, ${result.affectedIds.length} node${result.affectedIds.length === 1 ? '' : 's'})`;
120
+ const summary = `delete ${id} (${result.tier}, ${result.affectedIds.length} node${result.affectedIds.length === 1 ? '' : 's'}${result.removedEdgeCount ? `, ${result.removedEdgeCount} edge${result.removedEdgeCount === 1 ? '' : 's'} marked removed` : ''})`;
121
121
  await this.record('delete_node', { id, ...opts }, summary);
122
122
  return { ...result, warnings: [], summary };
123
123
  }
@@ -6,7 +6,7 @@ import { existsSync, readFileSync, readdirSync, watch } from 'node:fs';
6
6
  import { readdir } from 'node:fs/promises';
7
7
  import { fileURLToPath, pathToFileURL } from 'node:url';
8
8
  import { parse as parseYaml } from 'yaml';
9
- import { computeClusterOverlay, getClusterView, getGraphSummary, expandExternalNodes, getKindLabel, getKindRegistry, getLineage, getNamespaces, getStructuralNodeTemplates, isVisibleEdgeType, listNodes, searchNodes, } from '../graph/index.js';
9
+ import { computeClusterOverlay, getClusterView, getGraphSummary, expandExternalNodes, getKindLabel, getKindRegistry, getLineage, getNamespaces, getStructuralNodeTemplates, isLiveEdge, isVisibleEdgeType, listNodes, searchNodes, } from '../graph/index.js';
10
10
  import { loadGraph, loadMultiGraph } from '../loader/index.js';
11
11
  import { CORE_EDGE_TYPES } from '../loader/constants.js';
12
12
  import { getOwnedSections } from '../loader/pack-loader.js';
@@ -390,7 +390,7 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
390
390
  const edges = [];
391
391
  for (const edgeList of targetGraph.edgesByFrom.values()) {
392
392
  for (const edge of edgeList) {
393
- if (!isVisibleEdgeType(targetGraph, edge.type))
393
+ if (!isLiveEdge(edge) || !isVisibleEdgeType(targetGraph, edge.type))
394
394
  continue;
395
395
  if (!nodeIds.has(edge.from) || !nodeIds.has(edge.to))
396
396
  continue;
@@ -230,6 +230,8 @@ function toEdgeDocument(graph, edge) {
230
230
  doc.stability = edge.stability;
231
231
  if (edge.notes !== undefined)
232
232
  doc.notes = edge.notes;
233
+ if (edge.lastModifiedAt !== undefined)
234
+ doc.lastModifiedAt = edge.lastModifiedAt;
233
235
  if (edge.properties !== undefined && Object.keys(edge.properties).length > 0) {
234
236
  doc.properties = orderEdgeProperties(graph, edge);
235
237
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/corum",
3
- "version": "0.1.66",
3
+ "version": "0.1.67",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",