@neat.is/core 0.2.10 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-JMLZOKCS.js → chunk-B7UUGIXB.js} +1 -1
- package/dist/chunk-B7UUGIXB.js.map +1 -0
- package/dist/{chunk-5BQWBQJR.js → chunk-I5KODOJV.js} +2 -2
- package/dist/{chunk-W7ZYJZC7.js → chunk-NVCEZXL7.js} +48 -19
- package/dist/chunk-NVCEZXL7.js.map +1 -0
- package/dist/cli.cjs +60 -25
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +13 -10
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +45 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -12
- package/dist/index.d.ts +4 -12
- package/dist/index.js +3 -3
- package/dist/neatd.cjs.map +1 -1
- package/dist/neatd.js +2 -2
- package/dist/server.cjs +49 -17
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +2 -2
- package/package.json +2 -2
- package/dist/chunk-JMLZOKCS.js.map +0 -1
- package/dist/chunk-W7ZYJZC7.js.map +0 -1
- /package/dist/{chunk-5BQWBQJR.js.map → chunk-I5KODOJV.js.map} +0 -0
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
startPersistLoop,
|
|
12
12
|
touchLastSeen,
|
|
13
13
|
writeAtomically
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-B7UUGIXB.js";
|
|
15
15
|
|
|
16
16
|
// src/daemon.ts
|
|
17
17
|
import { promises as fs } from "fs";
|
|
@@ -159,4 +159,4 @@ export {
|
|
|
159
159
|
routeSpanToProject,
|
|
160
160
|
startDaemon
|
|
161
161
|
};
|
|
162
|
-
//# sourceMappingURL=chunk-
|
|
162
|
+
//# sourceMappingURL=chunk-I5KODOJV.js.map
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
eventBus,
|
|
15
15
|
extractFromDirectory,
|
|
16
16
|
getBlastRadius,
|
|
17
|
+
getProject,
|
|
17
18
|
getRootCause,
|
|
18
19
|
getTransitiveDependencies,
|
|
19
20
|
listProjects,
|
|
@@ -21,7 +22,7 @@ import {
|
|
|
21
22
|
pathsForProject,
|
|
22
23
|
readErrorEvents,
|
|
23
24
|
readStaleEvents
|
|
24
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-B7UUGIXB.js";
|
|
25
26
|
|
|
26
27
|
// src/diff.ts
|
|
27
28
|
import { promises as fs } from "fs";
|
|
@@ -456,9 +457,15 @@ function registerRoutes(scope, ctx) {
|
|
|
456
457
|
scope.get("/health", async (req, reply) => {
|
|
457
458
|
const proj = resolveProject(registry, req, reply);
|
|
458
459
|
if (!proj) return;
|
|
460
|
+
const uptimeMs = Date.now() - startedAt;
|
|
459
461
|
return {
|
|
460
|
-
|
|
462
|
+
ok: true,
|
|
461
463
|
project: proj.name,
|
|
464
|
+
uptimeMs,
|
|
465
|
+
// Legacy fields kept additively. The web shell's StatusBar reads
|
|
466
|
+
// nodeCount / edgeCount; ADR-061's HealthResponseSchema validates
|
|
467
|
+
// the canonical triple and lets the extras pass through.
|
|
468
|
+
uptime: Math.floor(uptimeMs / 1e3),
|
|
462
469
|
nodeCount: proj.graph.order,
|
|
463
470
|
edgeCount: proj.graph.size,
|
|
464
471
|
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -478,7 +485,7 @@ function registerRoutes(scope, ctx) {
|
|
|
478
485
|
if (!proj.graph.hasNode(id)) {
|
|
479
486
|
return reply.code(404).send({ error: "node not found", id });
|
|
480
487
|
}
|
|
481
|
-
return proj.graph.getNodeAttributes(id);
|
|
488
|
+
return { node: proj.graph.getNodeAttributes(id) };
|
|
482
489
|
}
|
|
483
490
|
);
|
|
484
491
|
scope.get(
|
|
@@ -495,12 +502,12 @@ function registerRoutes(scope, ctx) {
|
|
|
495
502
|
return { inbound, outbound };
|
|
496
503
|
}
|
|
497
504
|
);
|
|
498
|
-
scope.get("/graph/
|
|
505
|
+
scope.get("/graph/dependencies/:nodeId", async (req, reply) => {
|
|
499
506
|
const proj = resolveProject(registry, req, reply);
|
|
500
507
|
if (!proj) return;
|
|
501
|
-
const {
|
|
502
|
-
if (!proj.graph.hasNode(
|
|
503
|
-
return reply.code(404).send({ error: "node not found", id });
|
|
508
|
+
const { nodeId } = req.params;
|
|
509
|
+
if (!proj.graph.hasNode(nodeId)) {
|
|
510
|
+
return reply.code(404).send({ error: "node not found", id: nodeId });
|
|
504
511
|
}
|
|
505
512
|
const depth = req.query.depth ? Number(req.query.depth) : TRANSITIVE_DEPENDENCIES_DEFAULT_DEPTH;
|
|
506
513
|
if (!Number.isFinite(depth) || depth < 1 || depth > TRANSITIVE_DEPENDENCIES_MAX_DEPTH) {
|
|
@@ -508,7 +515,7 @@ function registerRoutes(scope, ctx) {
|
|
|
508
515
|
error: `depth must be an integer in [1, ${TRANSITIVE_DEPENDENCIES_MAX_DEPTH}]`
|
|
509
516
|
});
|
|
510
517
|
}
|
|
511
|
-
return getTransitiveDependencies(proj.graph,
|
|
518
|
+
return getTransitiveDependencies(proj.graph, nodeId, depth);
|
|
512
519
|
});
|
|
513
520
|
scope.get("/graph/divergences", async (req, reply) => {
|
|
514
521
|
const proj = resolveProject(registry, req, reply);
|
|
@@ -549,19 +556,26 @@ function registerRoutes(scope, ctx) {
|
|
|
549
556
|
const proj = resolveProject(registry, req, reply);
|
|
550
557
|
if (!proj) return;
|
|
551
558
|
const epath = errorsPathFor(proj);
|
|
552
|
-
if (!epath) return [];
|
|
553
|
-
|
|
559
|
+
if (!epath) return { count: 0, total: 0, events: [] };
|
|
560
|
+
const events = await readErrorEvents(epath);
|
|
561
|
+
const total = events.length;
|
|
562
|
+
const limit = req.query.limit ? Number(req.query.limit) : 50;
|
|
563
|
+
const safeLimit = Number.isFinite(limit) && limit > 0 ? Math.min(limit, 200) : 50;
|
|
564
|
+
const sliced = events.slice(0, safeLimit);
|
|
565
|
+
return { count: sliced.length, total, events: sliced };
|
|
554
566
|
});
|
|
555
|
-
scope.get("/
|
|
567
|
+
scope.get("/stale-events", async (req, reply) => {
|
|
556
568
|
const proj = resolveProject(registry, req, reply);
|
|
557
569
|
if (!proj) return;
|
|
558
570
|
const spath = staleEventsPathFor(proj);
|
|
559
|
-
if (!spath) return [];
|
|
571
|
+
if (!spath) return { count: 0, total: 0, events: [] };
|
|
560
572
|
const events = await readStaleEvents(spath);
|
|
561
573
|
const filtered = req.query.edgeType ? events.filter((e) => e.edgeType === req.query.edgeType) : events;
|
|
562
574
|
const ordered = [...filtered].reverse();
|
|
575
|
+
const total = ordered.length;
|
|
563
576
|
const limit = req.query.limit ? Number(req.query.limit) : 50;
|
|
564
|
-
|
|
577
|
+
const sliced = ordered.slice(0, Number.isFinite(limit) && limit > 0 ? limit : 50);
|
|
578
|
+
return { count: sliced.length, total, events: sliced };
|
|
565
579
|
});
|
|
566
580
|
scope.get(
|
|
567
581
|
"/incidents/:nodeId",
|
|
@@ -573,14 +587,15 @@ function registerRoutes(scope, ctx) {
|
|
|
573
587
|
return reply.code(404).send({ error: "node not found", id: nodeId });
|
|
574
588
|
}
|
|
575
589
|
const epath = errorsPathFor(proj);
|
|
576
|
-
if (!epath) return [];
|
|
590
|
+
if (!epath) return { count: 0, total: 0, events: [] };
|
|
577
591
|
const events = await readErrorEvents(epath);
|
|
578
|
-
|
|
592
|
+
const filtered = events.filter(
|
|
579
593
|
(e) => e.affectedNode === nodeId || e.service === nodeId.replace(/^service:/, "")
|
|
580
594
|
);
|
|
595
|
+
return { count: filtered.length, total: filtered.length, events: filtered };
|
|
581
596
|
}
|
|
582
597
|
);
|
|
583
|
-
scope.get("/
|
|
598
|
+
scope.get("/graph/root-cause/:nodeId", async (req, reply) => {
|
|
584
599
|
const proj = resolveProject(registry, req, reply);
|
|
585
600
|
if (!proj) return;
|
|
586
601
|
const { nodeId } = req.params;
|
|
@@ -600,7 +615,7 @@ function registerRoutes(scope, ctx) {
|
|
|
600
615
|
if (!result) return reply.code(404).send({ error: "no root cause found", id: nodeId });
|
|
601
616
|
return result;
|
|
602
617
|
});
|
|
603
|
-
scope.get("/
|
|
618
|
+
scope.get("/graph/blast-radius/:nodeId", async (req, reply) => {
|
|
604
619
|
const proj = resolveProject(registry, req, reply);
|
|
605
620
|
if (!proj) return;
|
|
606
621
|
const { nodeId } = req.params;
|
|
@@ -710,7 +725,7 @@ function registerRoutes(scope, ctx) {
|
|
|
710
725
|
if (req.query.policyId) {
|
|
711
726
|
violations = violations.filter((v) => v.policyId === req.query.policyId);
|
|
712
727
|
}
|
|
713
|
-
return violations;
|
|
728
|
+
return { violations };
|
|
714
729
|
});
|
|
715
730
|
scope.post("/policies/check", async (req, reply) => {
|
|
716
731
|
const proj = resolveProject(registry, req, reply);
|
|
@@ -789,6 +804,20 @@ async function buildApi(opts) {
|
|
|
789
804
|
});
|
|
790
805
|
}
|
|
791
806
|
});
|
|
807
|
+
app.get("/projects/:project", async (req, reply) => {
|
|
808
|
+
try {
|
|
809
|
+
const entry = await getProject(req.params.project);
|
|
810
|
+
if (!entry) {
|
|
811
|
+
return reply.code(404).send({ error: "project not found", project: req.params.project });
|
|
812
|
+
}
|
|
813
|
+
return { project: entry };
|
|
814
|
+
} catch (err) {
|
|
815
|
+
return reply.code(500).send({
|
|
816
|
+
error: "failed to read project registry",
|
|
817
|
+
details: err.message
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
});
|
|
792
821
|
registerRoutes(app, routeCtx);
|
|
793
822
|
await app.register(
|
|
794
823
|
async (scope) => {
|
|
@@ -804,4 +833,4 @@ export {
|
|
|
804
833
|
computeGraphDiff,
|
|
805
834
|
buildApi
|
|
806
835
|
};
|
|
807
|
-
//# sourceMappingURL=chunk-
|
|
836
|
+
//# sourceMappingURL=chunk-NVCEZXL7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/diff.ts","../src/api.ts","../src/divergences.ts","../src/streaming.ts"],"sourcesContent":["import { promises as fs } from 'node:fs'\nimport type { GraphEdge, GraphNode } from '@neat.is/types'\nimport type { NeatGraph } from './graph.js'\n\n// Diff a snapshot on disk (or fetched over HTTP) against the live in-memory\n// graph. The \"base\" is the snapshot you supplied; the \"current\" is whatever\n// the server has loaded right now. Symmetric in shape, but consumers usually\n// want to read it as \"what changed since base.\"\n//\n// The shape mirrors the issue's spec (#77):\n// { added: { nodes, edges }, removed: { nodes, edges },\n// changed: { nodes: [{id, before, after}], edges: [{id, before, after}] } }\n//\n// Both timestamps are echoed back so the caller doesn't have to track them\n// separately.\n\ninterface PersistedNodeEntry {\n key?: string\n attributes?: Record<string, unknown>\n}\n\ninterface PersistedEdgeEntry {\n key?: string\n source?: string\n target?: string\n attributes?: Record<string, unknown>\n}\n\nexport interface PersistedSnapshot {\n schemaVersion?: number\n exportedAt?: string\n graph?: {\n nodes?: PersistedNodeEntry[]\n edges?: PersistedEdgeEntry[]\n }\n}\n\nexport interface GraphDiff {\n base: { exportedAt?: string }\n current: { exportedAt: string }\n added: { nodes: GraphNode[]; edges: GraphEdge[] }\n removed: { nodes: GraphNode[]; edges: GraphEdge[] }\n changed: {\n nodes: { id: string; before: GraphNode; after: GraphNode }[]\n edges: { id: string; before: GraphEdge; after: GraphEdge }[]\n }\n}\n\nexport async function loadSnapshotForDiff(target: string): Promise<PersistedSnapshot> {\n if (/^https?:\\/\\//i.test(target)) {\n const res = await fetch(target)\n if (!res.ok) {\n throw new Error(`fetch ${target} failed: ${res.status} ${res.statusText}`)\n }\n return (await res.json()) as PersistedSnapshot\n }\n const raw = await fs.readFile(target, 'utf8')\n return JSON.parse(raw) as PersistedSnapshot\n}\n\nfunction indexEntries<T>(\n entries: { key?: string; attributes?: Record<string, unknown> }[] | undefined,\n): Map<string, T> {\n const m = new Map<string, T>()\n if (!entries) return m\n for (const entry of entries) {\n const id = (entry.attributes?.id as string | undefined) ?? entry.key\n if (!id) continue\n m.set(id, entry.attributes as T)\n }\n return m\n}\n\nexport function computeGraphDiff(\n liveGraph: NeatGraph,\n baseSnapshot: PersistedSnapshot,\n currentExportedAt: string = new Date().toISOString(),\n): GraphDiff {\n const baseNodes = indexEntries<GraphNode>(baseSnapshot.graph?.nodes)\n const baseEdges = indexEntries<GraphEdge>(baseSnapshot.graph?.edges)\n\n const liveNodes = new Map<string, GraphNode>()\n liveGraph.forEachNode((id, attrs) => liveNodes.set(id, attrs as GraphNode))\n const liveEdges = new Map<string, GraphEdge>()\n liveGraph.forEachEdge((id, attrs) => liveEdges.set(id, attrs as GraphEdge))\n\n const result: GraphDiff = {\n base: { exportedAt: baseSnapshot.exportedAt },\n current: { exportedAt: currentExportedAt },\n added: { nodes: [], edges: [] },\n removed: { nodes: [], edges: [] },\n changed: { nodes: [], edges: [] },\n }\n\n for (const [id, after] of liveNodes) {\n const before = baseNodes.get(id)\n if (!before) {\n result.added.nodes.push(after)\n } else if (!shallowEqual(before, after)) {\n result.changed.nodes.push({ id, before, after })\n }\n }\n for (const [id, before] of baseNodes) {\n if (!liveNodes.has(id)) result.removed.nodes.push(before)\n }\n for (const [id, after] of liveEdges) {\n const before = baseEdges.get(id)\n if (!before) {\n result.added.edges.push(after)\n } else if (!shallowEqual(before, after)) {\n result.changed.edges.push({ id, before, after })\n }\n }\n for (const [id, before] of baseEdges) {\n if (!liveEdges.has(id)) result.removed.edges.push(before)\n }\n\n return result\n}\n\n// Stable JSON comparison. Snapshot order isn't guaranteed, so canonicalising\n// keys before stringify keeps the comparison robust against re-ordered fields.\nfunction shallowEqual(a: unknown, b: unknown): boolean {\n return canonicalJson(a) === canonicalJson(b)\n}\n\nfunction canonicalJson(value: unknown): string {\n return JSON.stringify(value, (_key, v) => {\n if (v && typeof v === 'object' && !Array.isArray(v)) {\n return Object.keys(v as Record<string, unknown>)\n .sort()\n .reduce<Record<string, unknown>>((acc, k) => {\n acc[k] = (v as Record<string, unknown>)[k]\n return acc\n }, {})\n }\n return v\n })\n}\n","import Fastify, {\n type FastifyInstance,\n type FastifyReply,\n type FastifyRequest,\n} from 'fastify'\nimport cors from '@fastify/cors'\nimport type {\n ErrorEvent,\n GraphEdge,\n GraphNode,\n Policy,\n PolicyViolation,\n} from '@neat.is/types'\nimport { DivergenceTypeSchema, PoliciesCheckBodySchema, PolicySeveritySchema } from '@neat.is/types'\nimport type { DivergenceType } from '@neat.is/types'\nimport { computeDivergences } from './divergences.js'\nimport {\n evaluateAllPolicies,\n loadPolicyFile,\n PolicyViolationsLog,\n} from './policy.js'\nimport type { NeatGraph } from './graph.js'\nimport { DEFAULT_PROJECT } from './graph.js'\nimport { extractFromDirectory } from './extract.js'\nimport { readErrorEvents, readStaleEvents } from './ingest.js'\nimport {\n getBlastRadius,\n getRootCause,\n getTransitiveDependencies,\n TRANSITIVE_DEPENDENCIES_DEFAULT_DEPTH,\n TRANSITIVE_DEPENDENCIES_MAX_DEPTH,\n} from './traverse.js'\nimport { computeGraphDiff, loadSnapshotForDiff } from './diff.js'\nimport type { SearchIndex } from './search.js'\nimport type { Projects, ProjectContext } from './projects.js'\nimport { Projects as ProjectsClass, pathsForProject } from './projects.js'\nimport { getProject as getRegistryProject, listProjects as listRegistryProjects } from './registry.js'\nimport { handleSse } from './streaming.js'\n\nexport interface BuildApiOptions {\n // Multi-project shape. Optional — when absent we synthesise a single-\n // project registry from the legacy fields below so existing callers\n // (mainly tests) keep working unchanged.\n projects?: Projects\n startedAt?: number\n\n // Legacy single-project shape. Mapped to project=`default` if `projects`\n // isn't provided.\n graph?: NeatGraph\n scanPath?: string\n errorsPath?: string\n staleEventsPath?: string\n searchIndex?: SearchIndex\n}\n\ninterface SerializedGraph {\n nodes: GraphNode[]\n edges: GraphEdge[]\n}\n\nfunction serializeGraph(graph: NeatGraph): SerializedGraph {\n const nodes: GraphNode[] = []\n graph.forEachNode((_id, attrs) => {\n nodes.push(attrs)\n })\n const edges: GraphEdge[] = []\n graph.forEachEdge((_id, attrs) => {\n edges.push(attrs)\n })\n return { nodes, edges }\n}\n\nfunction projectFromReq(req: FastifyRequest): string {\n // `:project` is optional in the URL — the request hits either\n // /projects/:project/X or /X (which means default). Coerce the missing\n // param to DEFAULT_PROJECT here so handlers don't repeat the fallback.\n const params = req.params as { project?: string }\n return params.project ?? DEFAULT_PROJECT\n}\n\nfunction resolveProject(\n registry: Projects,\n req: FastifyRequest,\n reply: FastifyReply,\n): ProjectContext | null {\n const name = projectFromReq(req)\n const ctx = registry.get(name)\n if (!ctx) {\n void reply.code(404).send({ error: 'project not found', project: name })\n return null\n }\n return ctx\n}\n\nfunction buildLegacyRegistry(opts: BuildApiOptions): Projects {\n if (opts.projects) return opts.projects\n if (!opts.graph) {\n throw new Error('buildApi: either `projects` or `graph` must be provided')\n }\n const registry = new ProjectsClass()\n // pathsForProject only matters here for the snapshot/embeddings paths\n // routes never read; the ingest paths come from explicit options below.\n const paths = pathsForProject(DEFAULT_PROJECT, '')\n registry.set(DEFAULT_PROJECT, {\n graph: opts.graph,\n scanPath: opts.scanPath,\n paths: {\n snapshotPath: paths.snapshotPath,\n errorsPath: opts.errorsPath ?? paths.errorsPath,\n staleEventsPath: opts.staleEventsPath ?? paths.staleEventsPath,\n embeddingsCachePath: paths.embeddingsCachePath,\n policyViolationsPath: paths.policyViolationsPath,\n },\n searchIndex: opts.searchIndex,\n })\n return registry\n}\n\ninterface RouteContext {\n registry: Projects\n startedAt: number\n // Legacy callers passed `errorsPath`/`staleEventsPath` explicitly and\n // expected absent values to disable the read. Track that intent so the\n // /incidents handlers don't accidentally read a phantom file.\n errorsPathFor: (ctx: ProjectContext) => string | undefined\n staleEventsPathFor: (ctx: ProjectContext) => string | undefined\n // policy.json lives at the project root (per ADR-042 §File location), not\n // under neat-out/. Routes that read it map a project context to the path.\n policyFilePathFor: (ctx: ProjectContext) => string | undefined\n}\n\n// Registers every project-scoped route on `scope`. Called twice from\n// buildApi: once on the root app (so /graph etc. land at default), once\n// inside a `register(_, { prefix: '/projects/:project' })` plugin so the\n// same handlers run when the URL names a project explicitly.\nfunction registerRoutes(scope: FastifyInstance, ctx: RouteContext): void {\n const { registry, startedAt, errorsPathFor, staleEventsPathFor } = ctx\n\n // SSE event stream (ADR-051 #1). Dual-mounted: hits /events for default\n // project and /projects/:project/events when scoped. The handler keeps\n // the connection open and writes one frame per bus envelope whose\n // `project` matches.\n scope.get<{ Params: { project?: string } }>('/events', (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n handleSse(req, reply, { project: proj.name })\n })\n\n scope.get<{ Params: { project?: string } }>('/health', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const uptimeMs = Date.now() - startedAt\n return {\n ok: true,\n project: proj.name,\n uptimeMs,\n // Legacy fields kept additively. The web shell's StatusBar reads\n // nodeCount / edgeCount; ADR-061's HealthResponseSchema validates\n // the canonical triple and lets the extras pass through.\n uptime: Math.floor(uptimeMs / 1000),\n nodeCount: proj.graph.order,\n edgeCount: proj.graph.size,\n lastUpdated: new Date().toISOString(),\n }\n })\n\n scope.get<{ Params: { project?: string } }>('/graph', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n return serializeGraph(proj.graph)\n })\n\n scope.get<{ Params: { project?: string; id: string } }>(\n '/graph/node/:id',\n async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const { id } = req.params\n if (!proj.graph.hasNode(id)) {\n return reply.code(404).send({ error: 'node not found', id })\n }\n return { node: proj.graph.getNodeAttributes(id) as GraphNode }\n },\n )\n\n scope.get<{ Params: { project?: string; id: string } }>(\n '/graph/edges/:id',\n async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const { id } = req.params\n if (!proj.graph.hasNode(id)) {\n return reply.code(404).send({ error: 'node not found', id })\n }\n const inbound = proj.graph\n .inboundEdges(id)\n .map((e) => proj.graph.getEdgeAttributes(e) as GraphEdge)\n const outbound = proj.graph\n .outboundEdges(id)\n .map((e) => proj.graph.getEdgeAttributes(e) as GraphEdge)\n return { inbound, outbound }\n },\n )\n\n // Transitive dependencies (issue #144). BFS outbound to depth N, returning\n // a flat list with distance + edgeType + provenance per dependency.\n // Default depth 3, max 10. The MCP get_dependencies tool calls this.\n scope.get<{\n Params: { project?: string; nodeId: string }\n Querystring: { depth?: string }\n }>('/graph/dependencies/:nodeId', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const { nodeId } = req.params\n if (!proj.graph.hasNode(nodeId)) {\n return reply.code(404).send({ error: 'node not found', id: nodeId })\n }\n const depth = req.query.depth ? Number(req.query.depth) : TRANSITIVE_DEPENDENCIES_DEFAULT_DEPTH\n if (!Number.isFinite(depth) || depth < 1 || depth > TRANSITIVE_DEPENDENCIES_MAX_DEPTH) {\n return reply.code(400).send({\n error: `depth must be an integer in [1, ${TRANSITIVE_DEPENDENCIES_MAX_DEPTH}]`,\n })\n }\n return getTransitiveDependencies(proj.graph, nodeId, depth)\n })\n\n // Divergence query — the thesis surface (ADR-060). Read-only, derived,\n // dual-mounted via registerRoutes. Query params filter the result set;\n // body shape is DivergenceResult.\n scope.get<{\n Params: { project?: string }\n Querystring: { type?: string; minConfidence?: string; node?: string }\n }>('/graph/divergences', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n let typeFilter: Set<DivergenceType> | undefined\n if (req.query.type) {\n const candidates = req.query.type\n .split(',')\n .map((s) => s.trim())\n .filter((s) => s.length > 0)\n const parsed: DivergenceType[] = []\n for (const c of candidates) {\n const r = DivergenceTypeSchema.safeParse(c)\n if (!r.success) {\n return reply.code(400).send({\n error: `unknown divergence type \"${c}\"`,\n allowed: DivergenceTypeSchema.options,\n })\n }\n parsed.push(r.data)\n }\n typeFilter = new Set(parsed)\n }\n let minConfidence: number | undefined\n if (req.query.minConfidence !== undefined) {\n const n = Number(req.query.minConfidence)\n if (!Number.isFinite(n) || n < 0 || n > 1) {\n return reply.code(400).send({\n error: 'minConfidence must be a number in [0, 1]',\n })\n }\n minConfidence = n\n }\n return computeDivergences(proj.graph, {\n ...(typeFilter ? { type: typeFilter } : {}),\n ...(minConfidence !== undefined ? { minConfidence } : {}),\n ...(req.query.node ? { node: req.query.node } : {}),\n })\n })\n\n // ADR-061 envelope rule: list endpoints return { count, total, events }.\n // `total` is the size of the underlying collection; `count` is the size of\n // the slice we're handing back. The web shell counts on both.\n scope.get<{\n Params: { project?: string }\n Querystring: { limit?: string }\n }>('/incidents', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const epath = errorsPathFor(proj)\n if (!epath) return { count: 0, total: 0, events: [] }\n const events = await readErrorEvents(epath)\n const total = events.length\n const limit = req.query.limit ? Number(req.query.limit) : 50\n const safeLimit =\n Number.isFinite(limit) && limit > 0 ? Math.min(limit, 200) : 50\n const sliced = events.slice(0, safeLimit)\n return { count: sliced.length, total, events: sliced }\n })\n\n scope.get<{\n Params: { project?: string }\n Querystring: { limit?: string; edgeType?: string }\n }>('/stale-events', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const spath = staleEventsPathFor(proj)\n if (!spath) return { count: 0, total: 0, events: [] }\n const events = await readStaleEvents(spath)\n const filtered = req.query.edgeType\n ? events.filter((e) => e.edgeType === req.query.edgeType)\n : events\n const ordered = [...filtered].reverse()\n const total = ordered.length\n const limit = req.query.limit ? Number(req.query.limit) : 50\n const sliced = ordered.slice(0, Number.isFinite(limit) && limit > 0 ? limit : 50)\n return { count: sliced.length, total, events: sliced }\n })\n\n scope.get<{ Params: { project?: string; nodeId: string } }>(\n '/incidents/:nodeId',\n async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const { nodeId } = req.params\n if (!proj.graph.hasNode(nodeId)) {\n return reply.code(404).send({ error: 'node not found', id: nodeId })\n }\n const epath = errorsPathFor(proj)\n if (!epath) return { count: 0, total: 0, events: [] }\n const events = await readErrorEvents(epath)\n const filtered = events.filter(\n (e) =>\n e.affectedNode === nodeId || e.service === nodeId.replace(/^service:/, ''),\n )\n return { count: filtered.length, total: filtered.length, events: filtered }\n },\n )\n\n scope.get<{\n Params: { project?: string; nodeId: string }\n Querystring: { errorId?: string }\n }>('/graph/root-cause/:nodeId', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const { nodeId } = req.params\n if (!proj.graph.hasNode(nodeId)) {\n return reply.code(404).send({ error: 'node not found', id: nodeId })\n }\n let errorEvent: ErrorEvent | undefined\n const epath = errorsPathFor(proj)\n if (req.query.errorId && epath) {\n const events = await readErrorEvents(epath)\n errorEvent = events.find((e) => e.id === req.query.errorId)\n if (!errorEvent) {\n return reply\n .code(404)\n .send({ error: 'error event not found', id: req.query.errorId })\n }\n }\n const result = getRootCause(proj.graph, nodeId, errorEvent)\n if (!result) return reply.code(404).send({ error: 'no root cause found', id: nodeId })\n return result\n })\n\n scope.get<{\n Params: { project?: string; nodeId: string }\n Querystring: { depth?: string }\n }>('/graph/blast-radius/:nodeId', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const { nodeId } = req.params\n if (!proj.graph.hasNode(nodeId)) {\n return reply.code(404).send({ error: 'node not found', id: nodeId })\n }\n const depth = req.query.depth ? Number(req.query.depth) : undefined\n if (depth !== undefined && (!Number.isFinite(depth) || depth < 0)) {\n return reply.code(400).send({ error: 'depth must be a non-negative number' })\n }\n return getBlastRadius(proj.graph, nodeId, depth)\n })\n\n scope.get<{\n Params: { project?: string }\n Querystring: { q?: string; limit?: string }\n }>('/search', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const raw = (req.query.q ?? '').trim()\n if (!raw) return reply.code(400).send({ error: 'query parameter `q` is required' })\n const limit = req.query.limit ? Number(req.query.limit) : undefined\n const safeLimit =\n limit !== undefined && Number.isFinite(limit) && limit > 0 ? limit : undefined\n if (proj.searchIndex) {\n const result = await proj.searchIndex.search(raw, safeLimit)\n return {\n query: result.query,\n provider: result.provider,\n matches: result.matches.map((m) => ({ ...m.node, score: m.score })),\n }\n }\n const q = raw.toLowerCase()\n const matches: (GraphNode & { score: number })[] = []\n proj.graph.forEachNode((id, attrs) => {\n const name = (attrs as { name?: string }).name ?? ''\n if (id.toLowerCase().includes(q) || name.toLowerCase().includes(q)) {\n matches.push({ ...(attrs as GraphNode), score: 1 })\n }\n })\n return {\n query: q,\n provider: 'substring' as const,\n matches: matches.slice(0, safeLimit),\n }\n })\n\n scope.get<{ Params: { project?: string }; Querystring: { against?: string } }>(\n '/graph/diff',\n async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const against = req.query.against\n if (!against) {\n return reply.code(400).send({ error: 'query parameter `against` is required' })\n }\n try {\n const snapshot = await loadSnapshotForDiff(against)\n return computeGraphDiff(proj.graph, snapshot)\n } catch (err) {\n return reply\n .code(400)\n .send({ error: 'failed to load snapshot', against, detail: (err as Error).message })\n }\n },\n )\n\n scope.post<{ Params: { project?: string } }>('/graph/scan', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n if (!proj.scanPath) {\n return reply\n .code(409)\n .send({ error: 'scan path not configured for this project', project: proj.name })\n }\n const result = await extractFromDirectory(proj.graph, proj.scanPath)\n return {\n project: proj.name,\n scanned: proj.scanPath,\n nodesAdded: result.nodesAdded,\n edgesAdded: result.edgesAdded,\n nodeCount: proj.graph.order,\n edgeCount: proj.graph.size,\n }\n })\n\n // Policy surface (ADR-045 / contract #18). /policies returns the parsed\n // policy.json; /policies/violations is the persistent log; /policies/check\n // is dry-run evaluation. All dual-mounted via registerRoutes.\n scope.get<{ Params: { project?: string } }>('/policies', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const policyPath = ctx.policyFilePathFor(proj)\n if (!policyPath) {\n // No policy file configured for this project — return the empty file\n // shape so consumers don't have to special-case \"no policies yet.\"\n return { version: 1, policies: [] }\n }\n try {\n const policies = await loadPolicyFile(policyPath)\n return { version: 1, policies }\n } catch (err) {\n return reply.code(400).send({\n error: 'policy.json failed to parse',\n details: (err as Error).message,\n })\n }\n })\n\n scope.get<{\n Params: { project?: string }\n Querystring: { severity?: string; policyId?: string }\n }>('/policies/violations', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const log = new PolicyViolationsLog(proj.paths.policyViolationsPath)\n let violations = await log.readAll()\n if (req.query.severity) {\n const sev = PolicySeveritySchema.safeParse(req.query.severity)\n if (!sev.success) {\n return reply.code(400).send({\n error: 'invalid severity',\n details: sev.error.format(),\n })\n }\n violations = violations.filter((v) => v.severity === sev.data)\n }\n if (req.query.policyId) {\n violations = violations.filter((v) => v.policyId === req.query.policyId)\n }\n return { violations }\n })\n\n scope.post<{\n Params: { project?: string }\n Body: { hypotheticalAction?: unknown }\n }>('/policies/check', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const parsed = PoliciesCheckBodySchema.safeParse(req.body ?? {})\n if (!parsed.success) {\n return reply.code(400).send({\n error: 'invalid /policies/check body',\n details: parsed.error.format(),\n })\n }\n\n const policyPath = ctx.policyFilePathFor(proj)\n let policies: Policy[] = []\n if (policyPath) {\n try {\n policies = await loadPolicyFile(policyPath)\n } catch (err) {\n return reply.code(400).send({\n error: 'policy.json failed to parse',\n details: (err as Error).message,\n })\n }\n }\n\n // No hypothetical → return current violations against the live graph.\n // With a hypothetical → simulate the action against a deep-copy graph\n // (avoids mutation authority concerns), evaluate, return the delta.\n const evalCtx = { now: () => Date.now() }\n if (!parsed.data.hypotheticalAction) {\n const violations = evaluateAllPolicies(proj.graph, policies, evalCtx)\n const blocking = violations.filter((v) => v.onViolation === 'block')\n return { allowed: blocking.length === 0, violations }\n }\n\n // For now the dry-run simulation re-uses evaluateAllPolicies on the\n // current graph. Full hypothetical simulation (e.g. \"what if I added\n // this OBSERVED edge?\") is the v0.2.4-δ scope; #117 ships the surface,\n // #118 fills in the action shapes' simulation logic.\n const violations = evaluateAllPolicies(proj.graph, policies, evalCtx)\n const blocking = violations.filter((v) => v.onViolation === 'block')\n return {\n allowed: blocking.length === 0,\n hypotheticalAction: parsed.data.hypotheticalAction,\n violations,\n } as { allowed: boolean; hypotheticalAction: unknown; violations: PolicyViolation[] }\n })\n}\n\nexport async function buildApi(opts: BuildApiOptions): Promise<FastifyInstance> {\n const app = Fastify({ logger: false })\n await app.register(cors, { origin: true })\n\n const startedAt = opts.startedAt ?? Date.now()\n const registry = buildLegacyRegistry(opts)\n\n const legacyErrorsExplicit = !opts.projects && opts.errorsPath !== undefined\n const legacyStaleExplicit = !opts.projects && opts.staleEventsPath !== undefined\n\n const errorsPathFor = (proj: ProjectContext): string | undefined => {\n if (proj.name === DEFAULT_PROJECT && !opts.projects) {\n return legacyErrorsExplicit ? opts.errorsPath : undefined\n }\n return proj.paths.errorsPath\n }\n const staleEventsPathFor = (proj: ProjectContext): string | undefined => {\n if (proj.name === DEFAULT_PROJECT && !opts.projects) {\n return legacyStaleExplicit ? opts.staleEventsPath : undefined\n }\n return proj.paths.staleEventsPath\n }\n\n // policy.json lives at the project's scanPath root per ADR-042. Without a\n // scanPath we have nowhere to read it from — those projects show as\n // \"no policies configured\" via the empty-file response.\n const policyFilePathFor = (proj: ProjectContext): string | undefined => {\n if (!proj.scanPath) return undefined\n return `${proj.scanPath}/policy.json`\n }\n\n const routeCtx: RouteContext = {\n registry,\n startedAt,\n errorsPathFor,\n staleEventsPathFor,\n policyFilePathFor,\n }\n\n // Multi-project switcher (ADR-051 #4). Direct passthrough of the\n // machine-level registry from registry.ts (ADR-048) — distinct from the\n // dual-mount routing in ADR-026, which exposes per-project endpoints.\n // Returns Array<{ name, path, status, registeredAt, lastSeenAt?, languages }>.\n app.get('/projects', async (_req, reply) => {\n try {\n return await listRegistryProjects()\n } catch (err) {\n return reply.code(500).send({\n error: 'failed to read project registry',\n details: (err as Error).message,\n })\n }\n })\n\n // Singular project lookup (ADR-061 #7). Distinct route from the\n // `/projects/:project/...` dual-mount prefix because Fastify matches on\n // the full path; the trailing-segment-less request lands here.\n app.get<{ Params: { project: string } }>('/projects/:project', async (req, reply) => {\n try {\n const entry = await getRegistryProject(req.params.project)\n if (!entry) {\n return reply\n .code(404)\n .send({ error: 'project not found', project: req.params.project })\n }\n return { project: entry }\n } catch (err) {\n return reply.code(500).send({\n error: 'failed to read project registry',\n details: (err as Error).message,\n })\n }\n })\n\n // Default mount: /health, /graph, /incidents, etc. all hit project=default.\n registerRoutes(app, routeCtx)\n\n // Project-scoped mount: same handlers, URL params include `:project`.\n await app.register(\n async (scope) => {\n registerRoutes(scope, routeCtx)\n },\n { prefix: '/projects/:project' },\n )\n\n return app\n}\n","// computeDivergences — the thesis surface, derived (ADR-060).\n//\n// Walks the live graph and surfaces the five locked divergence shapes:\n// missing-observed, missing-extracted, version-mismatch, host-mismatch,\n// and compat-violation. Pure: no I/O, no mutation, no async. The function\n// operates on a NeatGraph reference and returns a fresh DivergenceResult\n// each call — there is no persistence (binding rule 2).\n//\n// Mutation authority (ADR-030 / contract #3) is locked to ingest.ts and\n// extract/*; this module reads only. The contract test\n// `packages/core/test/audits/contracts.test.ts` enforces it.\n\nimport type {\n CompatRuleRef,\n Divergence,\n DivergenceResult,\n DivergenceType,\n GraphEdge,\n GraphNode,\n ServiceNode,\n} from '@neat.is/types'\nimport {\n DivergenceResultSchema,\n EdgeType,\n NodeType,\n parseEdgeId,\n Provenance,\n} from '@neat.is/types'\nimport type { NeatGraph } from './graph.js'\nimport {\n checkCompatibility,\n checkDeprecatedApi,\n compatPairs,\n deprecatedApis,\n} from './compat.js'\nimport { confidenceForEdge } from './traverse.js'\n\nexport interface DivergenceQueryOpts {\n // Filter the result to a subset of divergence types. Undefined keeps all\n // five. Empty set returns nothing.\n type?: ReadonlySet<DivergenceType>\n // Drop divergences below this confidence threshold. Undefined keeps all.\n minConfidence?: number\n // Scope to divergences that involve this node (as source or target).\n node?: string\n}\n\n// (source, target, type) → which provenance variants are present. Each\n// bucket is the unit the missing-observed / missing-extracted detectors\n// operate over.\ninterface EdgeBucket {\n source: string\n target: string\n type: GraphEdge['type']\n extracted?: GraphEdge\n observed?: GraphEdge\n inferred?: GraphEdge\n stale?: GraphEdge\n frontier?: GraphEdge\n}\n\nfunction bucketKey(source: string, target: string, type: string): string {\n return `${type}|${source}|${target}`\n}\n\nfunction bucketEdges(graph: NeatGraph): Map<string, EdgeBucket> {\n const buckets = new Map<string, EdgeBucket>()\n graph.forEachEdge((id, attrs) => {\n const e = attrs as GraphEdge\n const parsed = parseEdgeId(id)\n // parseEdgeId can fall through to EXTRACTED for unknown shapes — fall\n // back to the edge's own provenance when the id doesn't parse cleanly.\n const provenance = parsed?.provenance ?? e.provenance\n const key = bucketKey(e.source, e.target, e.type)\n const cur =\n buckets.get(key) ?? { source: e.source, target: e.target, type: e.type }\n switch (provenance) {\n case Provenance.EXTRACTED:\n cur.extracted = e\n break\n case Provenance.OBSERVED:\n cur.observed = e\n break\n case Provenance.INFERRED:\n cur.inferred = e\n break\n case Provenance.FRONTIER:\n cur.frontier = e\n break\n default:\n // STALE rides on what used to be an OBSERVED edge — the id format\n // stays OBSERVED per identity.ts, so this branch is mostly defensive.\n if (e.provenance === Provenance.STALE) cur.stale = e\n }\n buckets.set(key, cur)\n })\n return buckets\n}\n\nfunction nodeIsFrontier(graph: NeatGraph, nodeId: string): boolean {\n if (!graph.hasNode(nodeId)) return false\n const attrs = graph.getNodeAttributes(nodeId) as GraphNode\n return attrs.type === NodeType.FrontierNode\n}\n\nfunction hasAnyObservedFromSource(graph: NeatGraph, sourceId: string): boolean {\n if (!graph.hasNode(sourceId)) return false\n for (const edgeId of graph.outboundEdges(sourceId)) {\n const e = graph.getEdgeAttributes(edgeId) as GraphEdge\n if (e.provenance === Provenance.OBSERVED) return true\n }\n return false\n}\n\nfunction clampConfidence(n: number): number {\n if (!Number.isFinite(n)) return 0\n return Math.max(0, Math.min(1, n))\n}\n\nfunction reasonForMissingObserved(source: string, target: string, type: string): string {\n return `Code declares ${source} → ${target} (${type}) but no production traffic has been observed for this edge.`\n}\n\nfunction reasonForMissingExtracted(source: string, target: string, type: string): string {\n return `Production observed ${source} → ${target} (${type}) but static analysis did not surface this edge.`\n}\n\nconst RECOMMENDATION_MISSING_OBSERVED =\n 'Verify the code path is exercised in production; check feature flags or conditional branches that might gate the call.'\nconst RECOMMENDATION_MISSING_EXTRACTED =\n 'Likely dynamic dispatch, reflection, or a coverage gap in tree-sitter extraction. Consider an `aliases` entry on the source service or file an extractor issue.'\nconst RECOMMENDATION_HOST_MISMATCH =\n 'Check environment-specific config overrides — the runtime host differs from what static configuration declares.'\n\nfunction detectMissingDivergences(\n graph: NeatGraph,\n bucket: EdgeBucket,\n): Divergence[] {\n const out: Divergence[] = []\n\n if (bucket.extracted && !bucket.observed) {\n // Skip when the would-be target is a FrontierNode — those represent\n // unresolved span peers, not real entities we expect OBSERVED traffic\n // to. The coexistence contract is between EXTRACTED and OBSERVED on\n // real nodes; FRONTIER is unknown territory.\n if (!nodeIsFrontier(graph, bucket.target)) {\n const sourceHasTraffic = hasAnyObservedFromSource(graph, bucket.source)\n out.push({\n type: 'missing-observed',\n source: bucket.source,\n target: bucket.target,\n edgeType: bucket.type,\n extracted: bucket.extracted,\n confidence: sourceHasTraffic ? 1.0 : 0.5,\n reason: reasonForMissingObserved(bucket.source, bucket.target, bucket.type),\n recommendation: RECOMMENDATION_MISSING_OBSERVED,\n })\n }\n }\n\n if (bucket.observed && !bucket.extracted) {\n const cascaded = clampConfidence(confidenceForEdge(bucket.observed))\n out.push({\n type: 'missing-extracted',\n source: bucket.source,\n target: bucket.target,\n edgeType: bucket.type,\n observed: bucket.observed,\n confidence: cascaded,\n reason: reasonForMissingExtracted(bucket.source, bucket.target, bucket.type),\n recommendation: RECOMMENDATION_MISSING_EXTRACTED,\n })\n }\n\n return out\n}\n\n// Returns the declared host of the service's static DB target, when\n// recoverable. ServiceNode.dbConnectionTarget is the static-extraction\n// surface for \"this service connects to X\" — `X` is host[:port] or a\n// docker-compose-style service name. Empty / undefined means we have no\n// EXTRACTED host to compare against and host-mismatch can't fire.\nfunction declaredHostFor(svc: ServiceNode): string | null {\n const raw = svc.dbConnectionTarget?.trim()\n if (!raw) return null\n // Strip a trailing port if present so it lines up with DatabaseNode.host\n // (ADR-028 §6 — DatabaseNode id excludes port).\n const colon = raw.lastIndexOf(':')\n if (colon === -1) return raw\n const port = raw.slice(colon + 1)\n if (/^\\d+$/.test(port)) return raw.slice(0, colon)\n return raw\n}\n\nfunction hasExtractedConfiguredBy(graph: NeatGraph, svcId: string): boolean {\n for (const edgeId of graph.outboundEdges(svcId)) {\n const e = graph.getEdgeAttributes(edgeId) as GraphEdge\n if (e.type === EdgeType.CONFIGURED_BY && e.provenance === Provenance.EXTRACTED) {\n return true\n }\n }\n return false\n}\n\nfunction detectHostMismatch(\n graph: NeatGraph,\n svcId: string,\n svc: ServiceNode,\n): Divergence[] {\n const declaredHost = declaredHostFor(svc)\n if (!declaredHost) return []\n if (!hasExtractedConfiguredBy(graph, svcId)) return []\n\n const out: Divergence[] = []\n for (const edgeId of graph.outboundEdges(svcId)) {\n const edge = graph.getEdgeAttributes(edgeId) as GraphEdge\n if (edge.type !== EdgeType.CONNECTS_TO) continue\n if (edge.provenance !== Provenance.OBSERVED) continue\n const target = graph.getNodeAttributes(edge.target) as GraphNode\n if (target.type !== NodeType.DatabaseNode) continue\n const observedHost = target.host?.trim()\n if (!observedHost) continue\n if (observedHost === declaredHost) continue\n\n out.push({\n type: 'host-mismatch',\n source: svcId,\n target: edge.target,\n extractedHost: declaredHost,\n observedHost,\n confidence: clampConfidence(confidenceForEdge(edge)),\n reason: `Config declares ${svcId} connects to ${declaredHost}; production connects to ${observedHost}.`,\n recommendation: RECOMMENDATION_HOST_MISMATCH,\n })\n }\n return out\n}\n\nfunction detectCompatDivergences(\n graph: NeatGraph,\n svcId: string,\n svc: ServiceNode,\n): Divergence[] {\n const out: Divergence[] = []\n const deps = svc.dependencies ?? {}\n\n for (const edgeId of graph.outboundEdges(svcId)) {\n const edge = graph.getEdgeAttributes(edgeId) as GraphEdge\n if (edge.type !== EdgeType.CONNECTS_TO) continue\n if (edge.provenance !== Provenance.OBSERVED) continue\n const target = graph.getNodeAttributes(edge.target) as GraphNode\n if (target.type !== NodeType.DatabaseNode) continue\n\n // Driver-engine compat. Definitive — when a rule fires it's a\n // version-mismatch with confidence 1.0.\n for (const pair of compatPairs()) {\n if (pair.engine !== target.engine) continue\n const declared = deps[pair.driver]\n if (!declared) continue\n const result = checkCompatibility(\n pair.driver,\n declared,\n target.engine,\n target.engineVersion,\n )\n if (!result.compatible && result.reason) {\n out.push({\n type: 'version-mismatch',\n source: svcId,\n target: edge.target,\n extractedVersion: declared,\n observedVersion: target.engineVersion,\n compatibility: 'incompatible',\n confidence: 1.0,\n reason: result.reason,\n recommendation: result.minDriverVersion\n ? `Upgrade ${pair.driver} to >= ${result.minDriverVersion}.`\n : `Update the ${pair.driver} driver to a version compatible with ${target.engine} ${target.engineVersion}.`,\n })\n }\n }\n\n // Deprecated-api compat. Broader than version-mismatch — surfaces as\n // compat-violation. Driver-engine rules above already covered the\n // \"version is too low\" shape; deprecated covers \"version is too high\n // / no longer supported.\"\n for (const rule of deprecatedApis()) {\n const declared = deps[rule.package]\n if (!declared) continue\n const result = checkDeprecatedApi(rule, declared)\n if (!result.compatible && result.reason) {\n const ruleRef: CompatRuleRef = {\n kind: rule.kind ?? 'deprecated-api',\n reason: result.reason,\n package: rule.package,\n }\n out.push({\n type: 'compat-violation',\n source: svcId,\n target: edge.target,\n rule: ruleRef,\n observed: edge,\n confidence: 1.0,\n reason: result.reason,\n recommendation: `Replace deprecated ${rule.package}@${declared} with a supported version.`,\n })\n }\n }\n }\n return out\n}\n\nfunction involvesNode(d: Divergence, nodeId: string): boolean {\n return d.source === nodeId || d.target === nodeId\n}\n\nexport function computeDivergences(\n graph: NeatGraph,\n opts: DivergenceQueryOpts = {},\n): DivergenceResult {\n const all: Divergence[] = []\n\n // Pass 1 — bucket every edge and emit missing-observed / missing-extracted.\n const buckets = bucketEdges(graph)\n for (const bucket of buckets.values()) {\n for (const d of detectMissingDivergences(graph, bucket)) all.push(d)\n }\n\n // Pass 2 — per-service host + compat rules.\n graph.forEachNode((nodeId, attrs) => {\n const n = attrs as GraphNode\n if (n.type !== NodeType.ServiceNode) return\n const svc = n as ServiceNode\n for (const d of detectHostMismatch(graph, nodeId, svc)) all.push(d)\n for (const d of detectCompatDivergences(graph, nodeId, svc)) all.push(d)\n })\n\n // Filter + sort. Higher confidence first; within the same confidence,\n // stable on (type, source, target) so callers see deterministic output.\n let filtered = all\n if (opts.type) {\n const allowed = opts.type\n filtered = filtered.filter((d) => allowed.has(d.type))\n }\n if (opts.minConfidence !== undefined) {\n const threshold = opts.minConfidence\n filtered = filtered.filter((d) => d.confidence >= threshold)\n }\n if (opts.node) {\n const target = opts.node\n filtered = filtered.filter((d) => involvesNode(d, target))\n }\n\n filtered.sort((a, b) => {\n if (b.confidence !== a.confidence) return b.confidence - a.confidence\n if (a.type !== b.type) return a.type.localeCompare(b.type)\n if (a.source !== b.source) return a.source.localeCompare(b.source)\n return a.target.localeCompare(b.target)\n })\n\n return DivergenceResultSchema.parse({\n divergences: filtered,\n totalAffected: filtered.length,\n computedAt: new Date().toISOString(),\n })\n}\n","// SSE handler for the frontend-facing event stream (ADR-051 #1).\n// Subscribes to the bus in events.ts, filters by project, writes\n// `event: <type>\\ndata: <json>\\n\\n` frames to the client.\n//\n// Backpressure: per-connection queue cap of 1000 outstanding writes; once\n// hit, the connection is dropped with `event: error data: { reason:\n// 'backpressure' }` per ADR-051 #8. Heartbeat: comment line every 30s\n// keeps proxies from idle-timing out (ADR-051 #3).\n\nimport type { FastifyReply, FastifyRequest } from 'fastify'\nimport {\n EVENT_BUS_CHANNEL,\n eventBus,\n type NeatEventEnvelope,\n} from './events.js'\n\nexport const SSE_HEARTBEAT_MS = 30_000\nexport const SSE_BACKPRESSURE_CAP = 1000\n\nexport interface HandleSseOptions {\n project: string\n heartbeatMs?: number\n backpressureCap?: number\n}\n\nexport function handleSse(\n req: FastifyRequest,\n reply: FastifyReply,\n opts: HandleSseOptions,\n): void {\n const heartbeatMs = opts.heartbeatMs ?? SSE_HEARTBEAT_MS\n const backpressureCap = opts.backpressureCap ?? SSE_BACKPRESSURE_CAP\n\n reply.raw.setHeader('Content-Type', 'text/event-stream')\n reply.raw.setHeader('Cache-Control', 'no-cache, no-transform')\n reply.raw.setHeader('Connection', 'keep-alive')\n reply.raw.setHeader('X-Accel-Buffering', 'no')\n reply.raw.flushHeaders?.()\n\n let pending = 0\n let dropped = false\n\n const closeConnection = (): void => {\n if (dropped) return\n dropped = true\n eventBus.off(EVENT_BUS_CHANNEL, listener)\n clearInterval(heartbeat)\n if (!reply.raw.writableEnded) reply.raw.end()\n }\n\n const writeFrame = (frame: string): void => {\n if (dropped) return\n if (pending >= backpressureCap) {\n // Past the cap — emit one final error frame and drop. Don't try to\n // gracefully drain; a slow consumer that's already 1000 frames behind\n // is not going to catch up.\n const errFrame = `event: error\\ndata: ${JSON.stringify({ reason: 'backpressure' })}\\n\\n`\n reply.raw.write(errFrame)\n closeConnection()\n return\n }\n pending++\n reply.raw.write(frame, () => {\n pending = Math.max(0, pending - 1)\n })\n }\n\n const listener = (envelope: NeatEventEnvelope): void => {\n if (envelope.project !== opts.project) return\n writeFrame(`event: ${envelope.type}\\ndata: ${JSON.stringify(envelope.payload)}\\n\\n`)\n }\n\n eventBus.on(EVENT_BUS_CHANNEL, listener)\n\n const heartbeat = setInterval(() => {\n if (dropped) return\n reply.raw.write(':heartbeat\\n\\n')\n }, heartbeatMs)\n if (typeof heartbeat.unref === 'function') heartbeat.unref()\n\n req.raw.on('close', closeConnection)\n reply.raw.on('close', closeConnection)\n reply.raw.on('error', closeConnection)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,UAAU;AAgD/B,eAAsB,oBAAoB,QAA4C;AACpF,MAAI,gBAAgB,KAAK,MAAM,GAAG;AAChC,UAAM,MAAM,MAAM,MAAM,MAAM;AAC9B,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,IAAI,MAAM,SAAS,M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AA,IACA;AAAA,IACA;AAAA,EACF;AAMA,MAAI,IAAI,aAAa,OAAO,MAAM,UAAU;AAC1C,QAAI;AACF,aAAO,MAAM,aAAqB;AAAA,IACpC,SAAS,KAAK;AACZ,aAAO,MAAM,KAAK,GAAG,EAAE,KAAK;AAAA,QAC1B,OAAO;AAAA,QACP,SAAU,IAAc;AAAA,MAC1B,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAKD,MAAI,IAAqC,sBAAsB,OAAO,KAAK,UAAU;AACnF,QAAI;AACF,YAAM,QAAQ,MAAM,WAAmB,IAAI,OAAO,OAAO;AACzD,UAAI,CAAC,OAAO;AACV,eAAO,MACJ,KAAK,GAAG,EACR,KAAK,EAAE,OAAO,qBAAqB,SAAS,IAAI,OAAO,QAAQ,CAAC;AAAA,MACrE;AACA,aAAO,EAAE,SAAS,MAAM;AAAA,IAC1B,SAAS,KAAK;AACZ,aAAO,MAAM,KAAK,GAAG,EAAE,KAAK;AAAA,QAC1B,OAAO;AAAA,QACP,SAAU,IAAc;AAAA,MAC1B,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAGD,iBAAe,KAAK,QAAQ;AAG5B,QAAM,IAAI;AAAA,IACR,OAAO,UAAU;AACf,qBAAe,OAAO,QAAQ;AAAA,IAChC;AAAA,IACA,EAAE,QAAQ,qBAAqB;AAAA,EACjC;AAEA,SAAO;AACT;","names":["violations","blocking"]}
|
package/dist/cli.cjs
CHANGED
|
@@ -4406,6 +4406,10 @@ async function addProject(opts) {
|
|
|
4406
4406
|
return entry2;
|
|
4407
4407
|
});
|
|
4408
4408
|
}
|
|
4409
|
+
async function getProject(name) {
|
|
4410
|
+
const reg = await readRegistry();
|
|
4411
|
+
return reg.projects.find((p) => p.name === name);
|
|
4412
|
+
}
|
|
4409
4413
|
async function listProjects() {
|
|
4410
4414
|
const reg = await readRegistry();
|
|
4411
4415
|
return reg.projects;
|
|
@@ -4542,9 +4546,15 @@ function registerRoutes(scope, ctx) {
|
|
|
4542
4546
|
scope.get("/health", async (req, reply) => {
|
|
4543
4547
|
const proj = resolveProject(registry, req, reply);
|
|
4544
4548
|
if (!proj) return;
|
|
4549
|
+
const uptimeMs = Date.now() - startedAt;
|
|
4545
4550
|
return {
|
|
4546
|
-
|
|
4551
|
+
ok: true,
|
|
4547
4552
|
project: proj.name,
|
|
4553
|
+
uptimeMs,
|
|
4554
|
+
// Legacy fields kept additively. The web shell's StatusBar reads
|
|
4555
|
+
// nodeCount / edgeCount; ADR-061's HealthResponseSchema validates
|
|
4556
|
+
// the canonical triple and lets the extras pass through.
|
|
4557
|
+
uptime: Math.floor(uptimeMs / 1e3),
|
|
4548
4558
|
nodeCount: proj.graph.order,
|
|
4549
4559
|
edgeCount: proj.graph.size,
|
|
4550
4560
|
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -4564,7 +4574,7 @@ function registerRoutes(scope, ctx) {
|
|
|
4564
4574
|
if (!proj.graph.hasNode(id)) {
|
|
4565
4575
|
return reply.code(404).send({ error: "node not found", id });
|
|
4566
4576
|
}
|
|
4567
|
-
return proj.graph.getNodeAttributes(id);
|
|
4577
|
+
return { node: proj.graph.getNodeAttributes(id) };
|
|
4568
4578
|
}
|
|
4569
4579
|
);
|
|
4570
4580
|
scope.get(
|
|
@@ -4581,12 +4591,12 @@ function registerRoutes(scope, ctx) {
|
|
|
4581
4591
|
return { inbound, outbound };
|
|
4582
4592
|
}
|
|
4583
4593
|
);
|
|
4584
|
-
scope.get("/graph/
|
|
4594
|
+
scope.get("/graph/dependencies/:nodeId", async (req, reply) => {
|
|
4585
4595
|
const proj = resolveProject(registry, req, reply);
|
|
4586
4596
|
if (!proj) return;
|
|
4587
|
-
const {
|
|
4588
|
-
if (!proj.graph.hasNode(
|
|
4589
|
-
return reply.code(404).send({ error: "node not found", id });
|
|
4597
|
+
const { nodeId } = req.params;
|
|
4598
|
+
if (!proj.graph.hasNode(nodeId)) {
|
|
4599
|
+
return reply.code(404).send({ error: "node not found", id: nodeId });
|
|
4590
4600
|
}
|
|
4591
4601
|
const depth = req.query.depth ? Number(req.query.depth) : TRANSITIVE_DEPENDENCIES_DEFAULT_DEPTH;
|
|
4592
4602
|
if (!Number.isFinite(depth) || depth < 1 || depth > TRANSITIVE_DEPENDENCIES_MAX_DEPTH) {
|
|
@@ -4594,7 +4604,7 @@ function registerRoutes(scope, ctx) {
|
|
|
4594
4604
|
error: `depth must be an integer in [1, ${TRANSITIVE_DEPENDENCIES_MAX_DEPTH}]`
|
|
4595
4605
|
});
|
|
4596
4606
|
}
|
|
4597
|
-
return getTransitiveDependencies(proj.graph,
|
|
4607
|
+
return getTransitiveDependencies(proj.graph, nodeId, depth);
|
|
4598
4608
|
});
|
|
4599
4609
|
scope.get("/graph/divergences", async (req, reply) => {
|
|
4600
4610
|
const proj = resolveProject(registry, req, reply);
|
|
@@ -4635,19 +4645,26 @@ function registerRoutes(scope, ctx) {
|
|
|
4635
4645
|
const proj = resolveProject(registry, req, reply);
|
|
4636
4646
|
if (!proj) return;
|
|
4637
4647
|
const epath = errorsPathFor(proj);
|
|
4638
|
-
if (!epath) return [];
|
|
4639
|
-
|
|
4648
|
+
if (!epath) return { count: 0, total: 0, events: [] };
|
|
4649
|
+
const events = await readErrorEvents(epath);
|
|
4650
|
+
const total = events.length;
|
|
4651
|
+
const limit = req.query.limit ? Number(req.query.limit) : 50;
|
|
4652
|
+
const safeLimit = Number.isFinite(limit) && limit > 0 ? Math.min(limit, 200) : 50;
|
|
4653
|
+
const sliced = events.slice(0, safeLimit);
|
|
4654
|
+
return { count: sliced.length, total, events: sliced };
|
|
4640
4655
|
});
|
|
4641
|
-
scope.get("/
|
|
4656
|
+
scope.get("/stale-events", async (req, reply) => {
|
|
4642
4657
|
const proj = resolveProject(registry, req, reply);
|
|
4643
4658
|
if (!proj) return;
|
|
4644
4659
|
const spath = staleEventsPathFor(proj);
|
|
4645
|
-
if (!spath) return [];
|
|
4660
|
+
if (!spath) return { count: 0, total: 0, events: [] };
|
|
4646
4661
|
const events = await readStaleEvents(spath);
|
|
4647
4662
|
const filtered = req.query.edgeType ? events.filter((e) => e.edgeType === req.query.edgeType) : events;
|
|
4648
4663
|
const ordered = [...filtered].reverse();
|
|
4664
|
+
const total = ordered.length;
|
|
4649
4665
|
const limit = req.query.limit ? Number(req.query.limit) : 50;
|
|
4650
|
-
|
|
4666
|
+
const sliced = ordered.slice(0, Number.isFinite(limit) && limit > 0 ? limit : 50);
|
|
4667
|
+
return { count: sliced.length, total, events: sliced };
|
|
4651
4668
|
});
|
|
4652
4669
|
scope.get(
|
|
4653
4670
|
"/incidents/:nodeId",
|
|
@@ -4659,14 +4676,15 @@ function registerRoutes(scope, ctx) {
|
|
|
4659
4676
|
return reply.code(404).send({ error: "node not found", id: nodeId });
|
|
4660
4677
|
}
|
|
4661
4678
|
const epath = errorsPathFor(proj);
|
|
4662
|
-
if (!epath) return [];
|
|
4679
|
+
if (!epath) return { count: 0, total: 0, events: [] };
|
|
4663
4680
|
const events = await readErrorEvents(epath);
|
|
4664
|
-
|
|
4681
|
+
const filtered = events.filter(
|
|
4665
4682
|
(e) => e.affectedNode === nodeId || e.service === nodeId.replace(/^service:/, "")
|
|
4666
4683
|
);
|
|
4684
|
+
return { count: filtered.length, total: filtered.length, events: filtered };
|
|
4667
4685
|
}
|
|
4668
4686
|
);
|
|
4669
|
-
scope.get("/
|
|
4687
|
+
scope.get("/graph/root-cause/:nodeId", async (req, reply) => {
|
|
4670
4688
|
const proj = resolveProject(registry, req, reply);
|
|
4671
4689
|
if (!proj) return;
|
|
4672
4690
|
const { nodeId } = req.params;
|
|
@@ -4686,7 +4704,7 @@ function registerRoutes(scope, ctx) {
|
|
|
4686
4704
|
if (!result) return reply.code(404).send({ error: "no root cause found", id: nodeId });
|
|
4687
4705
|
return result;
|
|
4688
4706
|
});
|
|
4689
|
-
scope.get("/
|
|
4707
|
+
scope.get("/graph/blast-radius/:nodeId", async (req, reply) => {
|
|
4690
4708
|
const proj = resolveProject(registry, req, reply);
|
|
4691
4709
|
if (!proj) return;
|
|
4692
4710
|
const { nodeId } = req.params;
|
|
@@ -4796,7 +4814,7 @@ function registerRoutes(scope, ctx) {
|
|
|
4796
4814
|
if (req.query.policyId) {
|
|
4797
4815
|
violations = violations.filter((v) => v.policyId === req.query.policyId);
|
|
4798
4816
|
}
|
|
4799
|
-
return violations;
|
|
4817
|
+
return { violations };
|
|
4800
4818
|
});
|
|
4801
4819
|
scope.post("/policies/check", async (req, reply) => {
|
|
4802
4820
|
const proj = resolveProject(registry, req, reply);
|
|
@@ -4875,6 +4893,20 @@ async function buildApi(opts) {
|
|
|
4875
4893
|
});
|
|
4876
4894
|
}
|
|
4877
4895
|
});
|
|
4896
|
+
app.get("/projects/:project", async (req, reply) => {
|
|
4897
|
+
try {
|
|
4898
|
+
const entry2 = await getProject(req.params.project);
|
|
4899
|
+
if (!entry2) {
|
|
4900
|
+
return reply.code(404).send({ error: "project not found", project: req.params.project });
|
|
4901
|
+
}
|
|
4902
|
+
return { project: entry2 };
|
|
4903
|
+
} catch (err) {
|
|
4904
|
+
return reply.code(500).send({
|
|
4905
|
+
error: "failed to read project registry",
|
|
4906
|
+
details: err.message
|
|
4907
|
+
});
|
|
4908
|
+
}
|
|
4909
|
+
});
|
|
4878
4910
|
registerRoutes(app, routeCtx);
|
|
4879
4911
|
await app.register(
|
|
4880
4912
|
async (scope) => {
|
|
@@ -5962,7 +5994,7 @@ async function runRootCause(client, input) {
|
|
|
5962
5994
|
const qs = input.errorId ? `?errorId=${encodeURIComponent(input.errorId)}` : "";
|
|
5963
5995
|
const path38 = projectPath(
|
|
5964
5996
|
input.project,
|
|
5965
|
-
`/
|
|
5997
|
+
`/graph/root-cause/${encodeURIComponent(input.errorNode)}${qs}`
|
|
5966
5998
|
);
|
|
5967
5999
|
try {
|
|
5968
6000
|
const result = await client.get(path38);
|
|
@@ -5993,7 +6025,7 @@ async function runBlastRadius(client, input) {
|
|
|
5993
6025
|
const qs = input.depth !== void 0 ? `?depth=${input.depth}` : "";
|
|
5994
6026
|
const path38 = projectPath(
|
|
5995
6027
|
input.project,
|
|
5996
|
-
`/
|
|
6028
|
+
`/graph/blast-radius/${encodeURIComponent(input.nodeId)}${qs}`
|
|
5997
6029
|
);
|
|
5998
6030
|
try {
|
|
5999
6031
|
const result = await client.get(path38);
|
|
@@ -6032,7 +6064,7 @@ async function runDependencies(client, input) {
|
|
|
6032
6064
|
const depth = input.depth ?? 3;
|
|
6033
6065
|
const path38 = projectPath(
|
|
6034
6066
|
input.project,
|
|
6035
|
-
`/graph/
|
|
6067
|
+
`/graph/dependencies/${encodeURIComponent(input.nodeId)}?depth=${depth}`
|
|
6036
6068
|
);
|
|
6037
6069
|
try {
|
|
6038
6070
|
const result = await client.get(path38);
|
|
@@ -6118,7 +6150,8 @@ function formatDuration(ms) {
|
|
|
6118
6150
|
async function runIncidents(client, input) {
|
|
6119
6151
|
const path38 = input.nodeId ? projectPath(input.project, `/incidents/${encodeURIComponent(input.nodeId)}`) : projectPath(input.project, "/incidents");
|
|
6120
6152
|
try {
|
|
6121
|
-
const
|
|
6153
|
+
const body = await client.get(path38);
|
|
6154
|
+
const events = body.events;
|
|
6122
6155
|
if (events.length === 0) {
|
|
6123
6156
|
return {
|
|
6124
6157
|
summary: input.nodeId ? `No incidents recorded against ${input.nodeId}.` : "No incidents recorded."
|
|
@@ -6132,7 +6165,7 @@ async function runIncidents(client, input) {
|
|
|
6132
6165
|
}
|
|
6133
6166
|
const target = input.nodeId ?? "the project";
|
|
6134
6167
|
return {
|
|
6135
|
-
summary: `${target} has ${
|
|
6168
|
+
summary: `${target} has ${body.total} recorded incident${body.total === 1 ? "" : "s"}; showing the ${ordered.length} most recent.`,
|
|
6136
6169
|
block: blockLines.join("\n"),
|
|
6137
6170
|
provenance: import_types22.Provenance.OBSERVED
|
|
6138
6171
|
};
|
|
@@ -6228,9 +6261,10 @@ async function runStaleEdges(client, input) {
|
|
|
6228
6261
|
if (input.limit !== void 0) params.set("limit", String(input.limit));
|
|
6229
6262
|
if (input.edgeType) params.set("edgeType", input.edgeType);
|
|
6230
6263
|
const qs = params.size > 0 ? `?${params.toString()}` : "";
|
|
6231
|
-
const
|
|
6232
|
-
projectPath(input.project, `/
|
|
6264
|
+
const body = await client.get(
|
|
6265
|
+
projectPath(input.project, `/stale-events${qs}`)
|
|
6233
6266
|
);
|
|
6267
|
+
const events = body.events;
|
|
6234
6268
|
if (events.length === 0) {
|
|
6235
6269
|
return {
|
|
6236
6270
|
summary: input.edgeType ? `No stale ${input.edgeType} edges recorded.` : "No stale-edge transitions recorded yet."
|
|
@@ -6264,9 +6298,10 @@ async function runPolicies(client, input) {
|
|
|
6264
6298
|
const params = new URLSearchParams();
|
|
6265
6299
|
if (input.policyId) params.set("policyId", input.policyId);
|
|
6266
6300
|
const qs = params.size > 0 ? `?${params.toString()}` : "";
|
|
6267
|
-
|
|
6301
|
+
const body = await client.get(
|
|
6268
6302
|
projectPath(input.project, `/policies/violations${qs}`)
|
|
6269
6303
|
);
|
|
6304
|
+
violations = body.violations;
|
|
6270
6305
|
allowed = violations.every((v) => v.onViolation !== "block");
|
|
6271
6306
|
}
|
|
6272
6307
|
if (input.nodeId) {
|