@neat.is/core 0.2.5
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/compat.json +120 -0
- package/dist/chunk-6JT6L2OV.js +164 -0
- package/dist/chunk-6JT6L2OV.js.map +1 -0
- package/dist/chunk-6SFEITLJ.js +3371 -0
- package/dist/chunk-6SFEITLJ.js.map +1 -0
- package/dist/chunk-I5IMCXRO.js +325 -0
- package/dist/chunk-I5IMCXRO.js.map +1 -0
- package/dist/chunk-T2U4U256.js +462 -0
- package/dist/chunk-T2U4U256.js.map +1 -0
- package/dist/chunk-WX55TLUT.js +184 -0
- package/dist/chunk-WX55TLUT.js.map +1 -0
- package/dist/chunk-XOOCA5T7.js +290 -0
- package/dist/chunk-XOOCA5T7.js.map +1 -0
- package/dist/cli.cjs +5754 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +36 -0
- package/dist/cli.d.ts +36 -0
- package/dist/cli.js +1175 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +4552 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +408 -0
- package/dist/index.d.ts +408 -0
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -0
- package/dist/neatd.cjs +3070 -0
- package/dist/neatd.cjs.map +1 -0
- package/dist/neatd.d.cts +1 -0
- package/dist/neatd.d.ts +1 -0
- package/dist/neatd.js +114 -0
- package/dist/neatd.js.map +1 -0
- package/dist/otel-grpc-B4XBSI4W.js +9 -0
- package/dist/otel-grpc-B4XBSI4W.js.map +1 -0
- package/dist/server.cjs +4499 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +2 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +97 -0
- package/dist/server.js.map +1 -0
- package/package.json +77 -0
- package/proto/opentelemetry/proto/collector/trace/v1/trace_service.proto +31 -0
- package/proto/opentelemetry/proto/common/v1/common.proto +46 -0
- package/proto/opentelemetry/proto/resource/v1/resource.proto +19 -0
- package/proto/opentelemetry/proto/trace/v1/trace.proto +93 -0
package/dist/cli.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/tsup/assets/cjs_shims.js","../src/otel-grpc.ts","../src/otel.ts","../src/cli.ts","../src/graph.ts","../src/extract.ts","../src/extract/index.ts","../src/ingest.ts","../src/policy.ts","../src/compat.ts","../compat.json","../src/traverse.ts","../src/extract/services.ts","../src/extract/shared.ts","../src/extract/python.ts","../src/extract/aliases.ts","../src/extract/databases/index.ts","../src/extract/databases/db-config-yaml.ts","../src/extract/databases/dotenv.ts","../src/extract/databases/shared.ts","../src/extract/databases/prisma.ts","../src/extract/databases/drizzle.ts","../src/extract/databases/knex.ts","../src/extract/databases/ormconfig.ts","../src/extract/databases/typeorm.ts","../src/extract/databases/sequelize.ts","../src/extract/databases/docker-compose.ts","../src/extract/configs.ts","../src/extract/calls/index.ts","../src/extract/calls/http.ts","../src/extract/calls/shared.ts","../src/extract/calls/kafka.ts","../src/extract/calls/redis.ts","../src/extract/calls/aws.ts","../src/extract/calls/grpc.ts","../src/extract/infra/index.ts","../src/extract/infra/docker-compose.ts","../src/extract/infra/shared.ts","../src/extract/infra/dockerfile.ts","../src/extract/infra/terraform.ts","../src/extract/infra/k8s.ts","../src/persist.ts","../src/watch.ts","../src/api.ts","../src/diff.ts","../src/projects.ts","../src/extract/retire.ts","../src/search.ts","../src/registry.ts","../src/installers/index.ts","../src/installers/javascript.ts","../src/installers/python.ts","../src/installers/shared.ts"],"sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","import { fileURLToPath } from 'node:url'\nimport path from 'node:path'\nimport * as grpc from '@grpc/grpc-js'\nimport * as protoLoader from '@grpc/proto-loader'\nimport {\n parseOtlpRequest,\n type OtlpTracesRequest,\n type ParsedSpan,\n type SpanHandler,\n} from './otel.js'\n\n// OTLP/gRPC receiver. Sits next to buildOtelReceiver (HTTP/JSON) in otel.ts;\n// shares the same parseOtlpRequest decoder so a span looks identical to the\n// downstream onSpan handler whether it came in over JSON or protobuf.\n//\n// Default OFF — opts.enabled (typically NEAT_OTLP_GRPC=true) decides whether\n// server.ts wires this up. We keep gRPC behind a flag so existing HTTP-only\n// deployments don't get a surprise port binding on upgrade.\n\nexport interface BuildOtelGrpcReceiverOptions {\n onSpan: SpanHandler\n}\n\n// proto-loader output for the trace service has fields like resource_spans,\n// scope_spans, span_id, etc. (snake_case keys, since we leave keepCase: true\n// when loading). The HTTP path uses camelCase JSON, so we shape-shift the\n// gRPC payload onto the HTTP shape and let parseOtlpRequest do the rest.\n//\n// All `bytes` fields arrive as Buffers; the HTTP wire format encodes them as\n// hex strings, so we hex-encode for consistency.\n\ninterface GrpcAnyValue {\n string_value?: string\n bool_value?: boolean\n int_value?: string | number\n double_value?: number\n array_value?: { values?: GrpcAnyValue[] }\n // bytes/kvlist fields exist in the proto but the demo doesn't use them.\n}\n\ninterface GrpcKeyValue {\n key?: string\n value?: GrpcAnyValue\n}\n\ninterface GrpcStatus {\n code?: number\n message?: string\n}\n\ninterface GrpcEvent {\n name?: string\n time_unix_nano?: string | number\n attributes?: GrpcKeyValue[]\n}\n\ninterface GrpcSpan {\n trace_id?: Buffer\n span_id?: Buffer\n parent_span_id?: Buffer\n name?: string\n kind?: number\n start_time_unix_nano?: string | number\n end_time_unix_nano?: string | number\n attributes?: GrpcKeyValue[]\n events?: GrpcEvent[]\n status?: GrpcStatus\n}\n\ninterface GrpcScopeSpans {\n spans?: GrpcSpan[]\n}\n\ninterface GrpcResourceSpans {\n resource?: { attributes?: GrpcKeyValue[] }\n scope_spans?: GrpcScopeSpans[]\n}\n\ninterface GrpcExportRequest {\n resource_spans?: GrpcResourceSpans[]\n}\n\nfunction bytesToHex(buf: Buffer | undefined): string {\n if (!buf) return ''\n return Buffer.isBuffer(buf) ? buf.toString('hex') : ''\n}\n\nfunction nanosToString(n: string | number | undefined): string {\n if (n === undefined || n === null) return '0'\n return typeof n === 'string' ? n : String(n)\n}\n\nfunction reshapeAttributes(\n attrs: GrpcKeyValue[] | undefined,\n): OtlpTracesRequest['resourceSpans'] extends Array<infer R>\n ? R extends { resource?: { attributes?: infer A } }\n ? A\n : never\n : never {\n // Map snake_case oneof fields to the camelCase the JSON path expects.\n const out = (attrs ?? []).map((kv) => ({\n key: kv.key ?? '',\n value: kv.value\n ? {\n stringValue: kv.value.string_value,\n boolValue: kv.value.bool_value,\n intValue: kv.value.int_value,\n doubleValue: kv.value.double_value,\n arrayValue: kv.value.array_value\n ? {\n values: (kv.value.array_value.values ?? []).map((v) => ({\n stringValue: v.string_value,\n boolValue: v.bool_value,\n intValue: v.int_value,\n doubleValue: v.double_value,\n })),\n }\n : undefined,\n }\n : undefined,\n }))\n return out as never\n}\n\nexport function reshapeGrpcRequest(req: GrpcExportRequest): OtlpTracesRequest {\n return {\n resourceSpans: (req.resource_spans ?? []).map((rs) => ({\n resource: rs.resource ? { attributes: reshapeAttributes(rs.resource.attributes) } : undefined,\n scopeSpans: (rs.scope_spans ?? []).map((ss) => ({\n spans: (ss.spans ?? []).map((s) => ({\n traceId: bytesToHex(s.trace_id),\n spanId: bytesToHex(s.span_id),\n parentSpanId: s.parent_span_id ? bytesToHex(s.parent_span_id) : undefined,\n name: s.name,\n kind: s.kind,\n startTimeUnixNano: nanosToString(s.start_time_unix_nano),\n endTimeUnixNano: nanosToString(s.end_time_unix_nano),\n attributes: reshapeAttributes(s.attributes),\n events: (s.events ?? []).map((e) => ({\n name: e.name,\n timeUnixNano: nanosToString(e.time_unix_nano),\n attributes: reshapeAttributes(e.attributes),\n })),\n status: s.status ? { code: s.status.code, message: s.status.message } : undefined,\n })),\n })),\n })),\n }\n}\n\n// Find the bundled .proto tree at packages/core/proto/. The dev server runs\n// from the source tree (tsx); the built bundles run from dist/. tsup keeps\n// source layout, so __dirname-relative resolution works for both — we look two\n// levels up from this file.\nfunction resolveProtoRoot(): string {\n // Built output (CJS) sets __dirname natively; ESM build is bundled by tsup\n // and keeps a dirname injection. import.meta.url is the safe bet.\n const here = path.dirname(fileURLToPath(import.meta.url))\n // src/ → packages/core/proto/, dist/ → packages/core/proto/.\n return path.resolve(here, '..', 'proto')\n}\n\nfunction loadTraceService(): grpc.ServiceDefinition {\n const protoRoot = resolveProtoRoot()\n const def = protoLoader.loadSync(\n 'opentelemetry/proto/collector/trace/v1/trace_service.proto',\n {\n keepCase: true,\n longs: String,\n enums: Number,\n defaults: true,\n oneofs: true,\n includeDirs: [protoRoot],\n },\n )\n const pkg = grpc.loadPackageDefinition(def) as unknown as {\n opentelemetry: {\n proto: {\n collector: {\n trace: {\n v1: {\n TraceService: { service: grpc.ServiceDefinition }\n }\n }\n }\n }\n }\n }\n return pkg.opentelemetry.proto.collector.trace.v1.TraceService.service\n}\n\nexport interface OtelGrpcReceiver {\n // Bound address (host:port) once .start() has resolved. Useful for tests.\n address: string\n // Stop accepting new requests, shut down the server.\n stop: () => Promise<void>\n}\n\nexport async function startOtelGrpcReceiver(\n opts: BuildOtelGrpcReceiverOptions & { host?: string; port?: number },\n): Promise<OtelGrpcReceiver> {\n const server = new grpc.Server()\n const service = loadTraceService()\n\n server.addService(service, {\n Export: (\n call: grpc.ServerUnaryCall<GrpcExportRequest, unknown>,\n callback: grpc.sendUnaryData<{ partial_success: object }>,\n ) => {\n void (async () => {\n try {\n const reshaped = reshapeGrpcRequest(call.request ?? {})\n const spans: ParsedSpan[] = parseOtlpRequest(reshaped)\n for (const span of spans) {\n await opts.onSpan(span)\n }\n callback(null, { partial_success: {} })\n } catch (err) {\n callback({\n code: grpc.status.INTERNAL,\n message: err instanceof Error ? err.message : String(err),\n })\n }\n })()\n },\n })\n\n const host = opts.host ?? '0.0.0.0'\n const port = opts.port ?? 4317\n\n const boundPort = await new Promise<number>((resolve, reject) => {\n server.bindAsync(`${host}:${port}`, grpc.ServerCredentials.createInsecure(), (err, p) => {\n if (err) return reject(err)\n resolve(p)\n })\n })\n\n return {\n address: `${host}:${boundPort}`,\n stop: () =>\n new Promise<void>((resolve) => {\n server.tryShutdown(() => resolve())\n }),\n }\n}\n","import path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport Fastify, { type FastifyInstance } from 'fastify'\nimport protobuf from 'protobufjs'\n\n// OTLP/HTTP receiver. Listens on /v1/traces and decodes the JSON wire format\n// (collector's `otlphttp` exporter with `encoding: json`). Each span is\n// flattened into a ParsedSpan and handed to the configured handler. The\n// handler is the seam #8 wires its edge mapper into; #7 itself stays decoupled\n// from graph mutation.\n\nexport interface ParsedSpan {\n service: string\n traceId: string\n spanId: string\n parentSpanId?: string\n name: string\n kind?: number\n startTimeUnixNano: string\n endTimeUnixNano: string\n // ISO8601 derived from startTimeUnixNano. Production paths (lastObserved on\n // OBSERVED edges) read this so the recorded time reflects when the span fired,\n // not when the receiver received it. Undefined only when startTimeUnixNano is\n // missing or unparseable — handler falls back to wall-clock in that case.\n // See docs/contracts/otel-ingest.md §lastObserved-from-span-time.\n startTimeIso?: string\n // bigint so the 9-digit-nanos arithmetic doesn't lose precision on long traces.\n durationNanos: bigint\n attributes: Record<string, AttributeValue>\n // Convenience accessors for the attributes #8 cares about.\n dbSystem?: string\n dbName?: string\n // 0 = UNSET, 1 = OK, 2 = ERROR per OTLP. We only care that 2 means error.\n statusCode?: number\n errorMessage?: string\n // Pre-extracted from a span event with name=\"exception\". OTLP SDKs record\n // exceptions this way (richer than status.message). handleSpan reads these\n // first, falling back to status.message and span.name. See\n // docs/contracts/otel-ingest.md §exception-data-from-span-events.\n exception?: {\n type?: string\n message?: string\n stacktrace?: string\n }\n}\n\nexport type AttributeValue =\n | string\n | number\n | boolean\n | bigint\n | string[]\n | number[]\n | boolean[]\n | null\n\nexport type SpanHandler = (span: ParsedSpan) => void | Promise<void>\n\nexport interface BuildOtelReceiverOptions {\n onSpan: SpanHandler\n // Synchronous handler for spans with statusCode === 2. The receiver awaits\n // it before replying, so a write failure can return 500 → OTel SDK retries.\n // Optional — wiring is expected to plumb appendErrorEvent here when error\n // durability matters; ad-hoc receivers leave it undefined.\n // See docs/contracts/otel-ingest.md §Error events.\n onErrorSpanSync?: (span: ParsedSpan) => Promise<void>\n // Fastify body limit. OTLP batches can be large; default is 16 MB.\n bodyLimit?: number\n}\n\ninterface OtlpKeyValue {\n key: string\n value?: OtlpAnyValue\n}\n\ninterface OtlpAnyValue {\n stringValue?: string\n intValue?: string | number\n doubleValue?: number\n boolValue?: boolean\n arrayValue?: { values?: OtlpAnyValue[] }\n // kvlistValue / bytesValue are skipped — neither is on the demo path.\n}\n\ninterface OtlpStatus {\n code?: number\n message?: string\n}\n\ninterface OtlpEvent {\n name?: string\n timeUnixNano?: string\n attributes?: OtlpKeyValue[]\n}\n\ninterface OtlpSpan {\n traceId?: string\n spanId?: string\n parentSpanId?: string\n name?: string\n kind?: number\n startTimeUnixNano?: string\n endTimeUnixNano?: string\n attributes?: OtlpKeyValue[]\n events?: OtlpEvent[]\n status?: OtlpStatus\n}\n\nfunction extractExceptionFromEvents(events: OtlpEvent[] | undefined): ParsedSpan['exception'] {\n if (!events) return undefined\n for (const ev of events) {\n if (ev.name !== 'exception') continue\n const attrs = attrsToRecord(ev.attributes)\n const out: ParsedSpan['exception'] = {}\n const t = attrs['exception.type']\n const m = attrs['exception.message']\n const s = attrs['exception.stacktrace']\n if (typeof t === 'string') out.type = t\n if (typeof m === 'string') out.message = m\n if (typeof s === 'string') out.stacktrace = s\n if (out.type || out.message || out.stacktrace) return out\n }\n return undefined\n}\n\ninterface OtlpScopeSpans {\n spans?: OtlpSpan[]\n}\n\ninterface OtlpResourceSpans {\n resource?: { attributes?: OtlpKeyValue[] }\n scopeSpans?: OtlpScopeSpans[]\n}\n\nexport interface OtlpTracesRequest {\n resourceSpans?: OtlpResourceSpans[]\n}\n\nfunction flattenAttribute(v: OtlpAnyValue | undefined): AttributeValue {\n if (!v) return null\n if (v.stringValue !== undefined) return v.stringValue\n if (v.boolValue !== undefined) return v.boolValue\n if (v.intValue !== undefined) {\n return typeof v.intValue === 'string' ? Number(v.intValue) : v.intValue\n }\n if (v.doubleValue !== undefined) return v.doubleValue\n if (v.arrayValue?.values) {\n return v.arrayValue.values.map((x) => flattenAttribute(x)) as AttributeValue\n }\n return null\n}\n\nfunction attrsToRecord(attrs: OtlpKeyValue[] | undefined): Record<string, AttributeValue> {\n const out: Record<string, AttributeValue> = {}\n if (!attrs) return out\n for (const kv of attrs) {\n if (kv.key) out[kv.key] = flattenAttribute(kv.value)\n }\n return out\n}\n\nfunction durationNanos(start?: string, end?: string): bigint {\n if (!start || !end) return 0n\n try {\n return BigInt(end) - BigInt(start)\n } catch {\n return 0n\n }\n}\n\n// Convert OTLP's startTimeUnixNano (a base-10 string of nanoseconds since the\n// Unix epoch) to ISO8601. Returns undefined when the input is missing, zero,\n// or unparseable, so the caller can fall back to wall-clock without surfacing\n// a fake timestamp on the edge.\nexport function isoFromUnixNano(nanos: string | undefined): string | undefined {\n if (!nanos || nanos === '0') return undefined\n try {\n const ms = Number(BigInt(nanos) / 1_000_000n)\n if (!Number.isFinite(ms)) return undefined\n return new Date(ms).toISOString()\n } catch {\n return undefined\n }\n}\n\nexport function parseOtlpRequest(body: OtlpTracesRequest): ParsedSpan[] {\n const out: ParsedSpan[] = []\n for (const rs of body.resourceSpans ?? []) {\n const resourceAttrs = attrsToRecord(rs.resource?.attributes)\n const service = typeof resourceAttrs['service.name'] === 'string'\n ? (resourceAttrs['service.name'] as string)\n : 'unknown'\n\n for (const ss of rs.scopeSpans ?? []) {\n for (const span of ss.spans ?? []) {\n const attrs = attrsToRecord(span.attributes)\n const parsed: ParsedSpan = {\n service,\n traceId: span.traceId ?? '',\n spanId: span.spanId ?? '',\n parentSpanId: span.parentSpanId || undefined,\n name: span.name ?? '',\n kind: span.kind,\n startTimeUnixNano: span.startTimeUnixNano ?? '0',\n endTimeUnixNano: span.endTimeUnixNano ?? '0',\n startTimeIso: isoFromUnixNano(span.startTimeUnixNano),\n durationNanos: durationNanos(span.startTimeUnixNano, span.endTimeUnixNano),\n attributes: attrs,\n dbSystem: typeof attrs['db.system'] === 'string' ? (attrs['db.system'] as string) : undefined,\n dbName: typeof attrs['db.name'] === 'string' ? (attrs['db.name'] as string) : undefined,\n statusCode: span.status?.code,\n errorMessage: span.status?.message,\n exception: extractExceptionFromEvents(span.events),\n }\n out.push(parsed)\n }\n }\n }\n return out\n}\n\nexport interface OtelReceiver {\n app: FastifyInstance\n // Resolves once every span enqueued so far has been handed to opts.onSpan.\n // Test seam — production code never awaits this.\n flushPending: () => Promise<void>\n}\n\n// Lazy-loaded protobuf decoder for ExportTraceServiceRequest. The bundled\n// .proto tree at packages/core/proto/ is shared with the gRPC receiver\n// (ADR-020). Cached after first load so successive receiver builds reuse it.\nlet exportTraceServiceRequestType: protobuf.Type | null = null\n\nfunction loadProtobufDecoder(): protobuf.Type {\n if (exportTraceServiceRequestType) return exportTraceServiceRequestType\n const here = path.dirname(fileURLToPath(import.meta.url))\n const protoRoot = path.resolve(here, '..', 'proto')\n const root = new protobuf.Root()\n root.resolvePath = (_origin, target) => path.resolve(protoRoot, target)\n root.loadSync(\n 'opentelemetry/proto/collector/trace/v1/trace_service.proto',\n { keepCase: true },\n )\n exportTraceServiceRequestType = root.lookupType(\n 'opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest',\n )\n return exportTraceServiceRequestType\n}\n\nasync function decodeProtobufBody(buf: Buffer): Promise<OtlpTracesRequest> {\n const Type = loadProtobufDecoder()\n // Decode keeps the proto field names verbatim (keepCase: true), matching the\n // GrpcExportRequest shape that reshapeGrpcRequest already understands.\n // Dynamic import sidesteps the circular module dep with otel-grpc.ts.\n const decoded = Type.decode(buf).toJSON() as Record<string, unknown>\n const { reshapeGrpcRequest } = await import('./otel-grpc.js')\n return reshapeGrpcRequest(decoded as never)\n}\n\nexport async function buildOtelReceiver(\n opts: BuildOtelReceiverOptions,\n): Promise<FastifyInstance & { flushPending: () => Promise<void> }> {\n const app = Fastify({\n logger: false,\n bodyLimit: opts.bodyLimit ?? 16 * 1024 * 1024,\n })\n\n // Non-blocking ingest (ADR-033). The receiver replies 200 OK as soon as the\n // body is parsed; mutation runs through this queue, drained on the next tick.\n // OTel SDK exporters retry on timeout, so blocking ingest produces observable\n // backpressure on the system being observed — ambient observation requires no\n // observable effect.\n const queue: ParsedSpan[] = []\n let draining = false\n let drainPromise: Promise<void> = Promise.resolve()\n\n const drain = async (): Promise<void> => {\n if (draining) return\n draining = true\n try {\n while (queue.length > 0) {\n const span = queue.shift()!\n try {\n await opts.onSpan(span)\n } catch (err) {\n console.warn(`[neat] otel handler error: ${(err as Error).message}`)\n }\n }\n } finally {\n draining = false\n }\n }\n\n const enqueue = (spans: ParsedSpan[]): void => {\n if (spans.length === 0) return\n for (const s of spans) queue.push(s)\n // Schedule on the next tick so the 200 response is on the wire before any\n // mutation runs. Each call gets its own promise so flushPending() can wait\n // on the latest drain cycle.\n drainPromise = drainPromise.then(() => drain())\n }\n\n // Buffer application/x-protobuf bodies as raw bytes; the route handler\n // decodes them via the bundled .proto tree (ADR-020).\n app.addContentTypeParser(\n 'application/x-protobuf',\n { parseAs: 'buffer', bodyLimit: opts.bodyLimit ?? 16 * 1024 * 1024 },\n (_req, body, done) => {\n done(null, body)\n },\n )\n\n app.get('/health', async () => ({ ok: true }))\n\n app.post('/v1/traces', async (req, reply) => {\n // Content-Type dispatch (ADR-033). Both JSON and protobuf decode to the\n // same OtlpTracesRequest shape, then feed parseOtlpRequest unchanged.\n const ct = (req.headers['content-type'] ?? '').toString().split(';')[0]!.trim().toLowerCase()\n let body: OtlpTracesRequest\n if (ct === 'application/x-protobuf') {\n try {\n body = await decodeProtobufBody(req.body as Buffer)\n } catch (err) {\n return reply.code(400).send({\n error: `protobuf decode failed: ${(err as Error).message}`,\n })\n }\n } else if (!ct || ct === 'application/json') {\n body = (req.body ?? {}) as OtlpTracesRequest\n } else {\n return reply.code(415).send({ error: `unsupported content-type: ${ct}` })\n }\n const spans = parseOtlpRequest(body)\n // Synchronous error-event write before reply (ADR-033 §Error events).\n // Graph mutation stays on the async queue, but the receiver awaits the\n // file write so a write failure surfaces as 500 → OTel SDK retries.\n if (opts.onErrorSpanSync) {\n try {\n for (const span of spans) {\n if (span.statusCode === 2) await opts.onErrorSpanSync(span)\n }\n } catch (err) {\n return reply.code(500).send({\n error: `error-event write failed: ${(err as Error).message}`,\n })\n }\n }\n enqueue(spans)\n // OTLP success response is `{ partialSuccess: {} }` for \"all accepted\".\n return reply.code(200).send({ partialSuccess: {} })\n })\n\n // Attach flushPending so tests can wait for the queue without exporting a\n // separate handle. The cast goes through `unknown` because Fastify's typing\n // is parameterised over the raw server type and the simple intersection\n // confuses TS's structural narrowing.\n const decorated = app as unknown as FastifyInstance & { flushPending: () => Promise<void> }\n decorated.flushPending = async () => {\n // Settle the current drain chain, then loop until the queue is fully empty\n // (a span enqueued mid-flush would otherwise be missed).\n while (queue.length > 0 || draining) {\n await drainPromise\n }\n }\n return decorated\n}\n\nexport function logSpanHandler(span: ParsedSpan): void {\n const parent = span.parentSpanId ? span.parentSpanId.slice(0, 8) : '<root>'\n const status = span.statusCode === 2 ? 'ERROR' : 'OK'\n const db = span.dbSystem ? ` db=${span.dbSystem}/${span.dbName ?? '?'}` : ''\n console.log(\n `otel: ${span.service} ${span.name} parent=${parent} status=${status}${db}`,\n )\n}\n","#!/usr/bin/env node\n\nimport path from 'node:path'\nimport { promises as fs } from 'node:fs'\nimport type { GraphEdge, GraphNode, ServiceNode } from '@neat.is/types'\nimport { DEFAULT_PROJECT, getGraph, resetGraph } from './graph.js'\nimport { extractFromDirectory } from './extract.js'\nimport { discoverServices } from './extract/services.js'\nimport type { DiscoveredService } from './extract/shared.js'\nimport { saveGraphToDisk } from './persist.js'\nimport { startWatch, type WatchHandle } from './watch.js'\nimport { pathsForProject } from './projects.js'\nimport {\n addProject,\n listProjects,\n ProjectNameCollisionError,\n removeProject,\n setStatus,\n} from './registry.js'\nimport {\n INSTALLERS,\n isEmptyPlan,\n pickInstaller,\n renderPatch,\n type InstallPlan,\n type PatchSection,\n} from './installers/index.js'\n\nexport interface InitOptions {\n scanPath: string\n outPath: string\n // The project's registry name. Defaults to the basename of the scan path\n // when the user didn't pass `--project` (ADR-046 — project naming).\n project: string\n // Whether `project` was set explicitly via `--project`. The flag affects\n // which in-memory graph slot we use: explicit names get isolated slots\n // per ADR-026, the default basename keeps using DEFAULT_PROJECT for\n // back-compat with `neat watch`.\n projectExplicit: boolean\n apply: boolean\n dryRun: boolean\n noInstall: boolean\n}\n\nexport interface InitResult {\n // Process exit code. 0 on success, 1 on collision / runtime failure,\n // 2 on misuse (handled before we get here, but documented for completeness).\n exitCode: number\n // Paths the run actually wrote to. Empty in `--dry-run` except for\n // `neat.patch`. Useful for tests asserting \"init only wrote X\".\n writtenFiles: string[]\n}\n\nfunction usage(): void {\n console.log('usage: neat <command> [args] [--project <name>]')\n console.log('')\n console.log('commands:')\n console.log(' init <path> One-time install: discover, extract, register, plan SDK install.')\n console.log(' Snapshot lands in <path>/neat-out/graph.json by default')\n console.log(' (or <path>/neat-out/<project>.json for non-default).')\n console.log(' Flags:')\n console.log(' --apply run the SDK install patch in place')\n console.log(' --dry-run write only neat.patch; do not register or snapshot')\n console.log(' --no-install skip SDK install planning entirely')\n console.log(' watch <path> Start neat-core, watch <path>, re-extract on changes.')\n console.log(' PORT (default 8080), OTEL_PORT (4318), HOST (0.0.0.0)')\n console.log(' control listeners. NEAT_OTLP_GRPC=true also opens 4317.')\n console.log(' list List every project registered in the machine-level registry.')\n console.log(' pause <name> Mark a project paused — daemon stops watching until resumed.')\n console.log(' resume <name> Mark a project active again.')\n console.log(' uninstall <name>')\n console.log(' Remove a project from the registry. Does not touch')\n console.log(' neat-out/, policy.json, or any user file.')\n console.log(' skill Install or print the Claude Code MCP drop-in.')\n console.log(' Flags:')\n console.log(' --print-config print the JSON snippet to stdout')\n console.log(' --apply merge mcpServers.neat into ~/.claude.json')\n console.log('')\n console.log('flags:')\n console.log(' --project <name> Name the project this command targets. Default: \"default\".')\n}\n\n// Tiny argv parser — pulls `--project <name>` and the v0.2.5 init flags\n// (`--apply`, `--dry-run`, `--no-install`) out of `rest`. Boolean flags are\n// only meaningful for `init`; the parser surfaces them unconditionally so\n// `main` can validate per-command.\ninterface ParsedArgs {\n project: string | null\n apply: boolean\n dryRun: boolean\n noInstall: boolean\n printConfig: boolean\n positional: string[]\n}\n\nfunction parseArgs(rest: string[]): ParsedArgs {\n const positional: string[] = []\n let project: string | null = null\n let apply = false\n let dryRun = false\n let noInstall = false\n let printConfig = false\n for (let i = 0; i < rest.length; i++) {\n const arg = rest[i] as string\n if (arg === '--project') {\n const next = rest[i + 1]\n if (!next) {\n console.error('neat: --project requires a value')\n process.exit(2)\n }\n project = next\n i++\n continue\n }\n if (arg.startsWith('--project=')) {\n project = arg.slice('--project='.length)\n continue\n }\n if (arg === '--apply') {\n apply = true\n continue\n }\n if (arg === '--dry-run') {\n dryRun = true\n continue\n }\n if (arg === '--no-install') {\n noInstall = true\n continue\n }\n if (arg === '--print-config') {\n printConfig = true\n continue\n }\n positional.push(arg)\n }\n return { project, apply, dryRun, noInstall, printConfig, positional }\n}\n\nfunction summarise(nodes: GraphNode[], edges: GraphEdge[]): string {\n const byNode = new Map<string, number>()\n for (const n of nodes) byNode.set(n.type, (byNode.get(n.type) ?? 0) + 1)\n const byEdge = new Map<string, number>()\n for (const e of edges) byEdge.set(e.type, (byEdge.get(e.type) ?? 0) + 1)\n\n const nodeLines = [...byNode.entries()]\n .sort((a, b) => a[0].localeCompare(b[0]))\n .map(([t, c]) => ` ${t}: ${c}`)\n const edgeLines = [...byEdge.entries()]\n .sort((a, b) => a[0].localeCompare(b[0]))\n .map(([t, c]) => ` ${t}: ${c}`)\n\n return ['nodes:', ...nodeLines, 'edges:', ...edgeLines].join('\\n')\n}\n\nfunction formatIncompat(inc: NonNullable<ServiceNode['incompatibilities']>[number]): string {\n if (inc.kind === 'node-engine') {\n const range = inc.declaredNodeEngine ? ` (engines.node=\"${inc.declaredNodeEngine}\")` : ''\n return `${inc.package}@${inc.packageVersion ?? '?'} requires Node ${inc.requiredNodeVersion}${range} — ${inc.reason}`\n }\n if (inc.kind === 'package-conflict') {\n const found = inc.foundVersion ? `@${inc.foundVersion}` : ' (missing)'\n return `${inc.package}@${inc.packageVersion ?? '?'} requires ${inc.requires.name}>=${inc.requires.minVersion}; found ${inc.requires.name}${found} — ${inc.reason}`\n }\n if (inc.kind === 'deprecated-api') {\n return `${inc.package}@${inc.packageVersion ?? '?'} is deprecated — ${inc.reason}`\n }\n return `${inc.driver}@${inc.driverVersion} vs ${inc.engine} ${inc.engineVersion} — ${inc.reason}`\n}\n\nfunction findIncompatibilities(nodes: GraphNode[]): ServiceNode[] {\n return nodes.filter(\n (n): n is ServiceNode =>\n n.type === 'ServiceNode' &&\n Array.isArray((n as ServiceNode).incompatibilities) &&\n ((n as ServiceNode).incompatibilities ?? []).length > 0,\n )\n}\n\nfunction printBanner(): void {\n console.log('███╗ ██╗███████╗ █████╗ ████████╗')\n console.log('████╗ ██║██╔════╝██╔══██╗╚══██╔══╝')\n console.log('██╔██╗ ██║█████╗ ███████║ ██║ ')\n console.log('██║╚██╗██║██╔══╝ ██╔══██║ ██║ ')\n console.log('██║ ╚████║███████╗██║ ██║ ██║ ')\n console.log('╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═╝ ')\n console.log('')\n console.log(' Network Expressive Architecting Tool')\n console.log(' neat.is · v0.2.5 · BSL 1.1')\n console.log('')\n}\n\nfunction printDiscoveryReport(opts: InitOptions, services: DiscoveredService[]): void {\n const languages = [...new Set(services.map((s) => s.node.language))].sort()\n const mode = opts.dryRun ? 'dry-run' : opts.apply ? 'apply' : 'patch-only'\n printBanner()\n console.log('=== neat init: discovery ===')\n console.log(`scan path: ${opts.scanPath}`)\n console.log(`project: ${opts.project}`)\n console.log(`mode: ${mode}`)\n console.log(`services: ${services.length}`)\n for (const s of services) {\n const where = s.node.repoPath && s.node.repoPath.length > 0 ? s.node.repoPath : '.'\n console.log(` - ${s.node.name} (${s.node.language}) — ${where}`)\n }\n console.log(`languages: ${languages.length > 0 ? languages.join(', ') : '(none)'}`)\n if (opts.noInstall) {\n console.log('install: skipped (--no-install)')\n } else if (opts.dryRun) {\n console.log('install: patch will be written to neat.patch; nothing else.')\n } else if (opts.apply) {\n console.log('install: patch will be applied in place. Run `npm install` afterwards.')\n } else {\n console.log('install: patch will be written to neat.patch for review.')\n }\n console.log('')\n}\n\nasync function buildPatchSections(\n services: DiscoveredService[],\n): Promise<PatchSection[]> {\n const sections: PatchSection[] = []\n for (const svc of services) {\n const installer = await pickInstaller(svc.dir)\n if (!installer) continue\n const plan: InstallPlan = await installer.plan(svc.dir)\n if (isEmptyPlan(plan)) continue\n sections.push({ installer: installer.name, plan })\n }\n return sections\n}\n\nexport async function runInit(opts: InitOptions): Promise<InitResult> {\n const written: string[] = []\n\n // ── Step 1: validate path ────────────────────────────────────────────\n const stat = await fs.stat(opts.scanPath).catch(() => null)\n if (!stat || !stat.isDirectory()) {\n console.error(`neat init: ${opts.scanPath} is not a directory`)\n return { exitCode: 2, writtenFiles: written }\n }\n\n // ── Step 2: discovery (ADR-046 #2 — before any mutation) ─────────────\n const services = await discoverServices(opts.scanPath)\n printDiscoveryReport(opts, services)\n\n // ── Step 3: plan SDK install (pure data, no fs writes) ───────────────\n const sections = opts.noInstall ? [] : await buildPatchSections(services)\n const patch = renderPatch(sections)\n const patchPath = path.join(opts.scanPath, 'neat.patch')\n\n // ── Step 4: dry-run shortcut — only neat.patch is allowed to land ────\n if (opts.dryRun) {\n await fs.writeFile(patchPath, patch, 'utf8')\n written.push(patchPath)\n console.log(`dry-run: patch written to ${patchPath}`)\n console.log('rerun without --dry-run to register and snapshot.')\n return { exitCode: 0, writtenFiles: written }\n }\n\n // ── Step 5: extraction + snapshot ────────────────────────────────────\n // Use DEFAULT_PROJECT for the in-memory graph slot when --project wasn't\n // explicitly passed; named projects get isolated slots per ADR-026.\n const graphKey = opts.projectExplicit ? opts.project : DEFAULT_PROJECT\n resetGraph(graphKey)\n const graph = getGraph(graphKey)\n const result = await extractFromDirectory(graph, opts.scanPath)\n await saveGraphToDisk(graph, opts.outPath)\n written.push(opts.outPath)\n\n // ── Step 6: register in the machine-level registry ───────────────────\n // Idempotent re-init of the same path under the same name refreshes the\n // entry; collision against a different path exits non-zero (ADR-046 #7).\n const languages = [...new Set(services.map((s) => s.node.language))].sort()\n try {\n await addProject({\n name: opts.project,\n path: opts.scanPath,\n languages,\n status: 'active',\n })\n } catch (err) {\n if (err instanceof ProjectNameCollisionError) {\n console.error(`neat init: ${err.message}`)\n console.error('pass --project <other-name> to register under a different name.')\n return { exitCode: 1, writtenFiles: written }\n }\n throw err\n }\n\n // ── Step 7: write or apply patch ─────────────────────────────────────\n if (!opts.noInstall) {\n if (opts.apply) {\n for (const section of sections) {\n const installer = INSTALLERS.find((i) => i.name === section.installer)\n if (!installer) continue\n await installer.apply(section.plan)\n }\n if (sections.length > 0) {\n console.log('')\n console.log('patch applied. Run `npm install` (or your language equivalent) to refresh lockfiles.')\n }\n } else {\n await fs.writeFile(patchPath, patch, 'utf8')\n written.push(patchPath)\n }\n }\n\n // ── Step 8: summary + incompatibilities ──────────────────────────────\n const nodes: GraphNode[] = []\n graph.forEachNode((_id, attrs) => nodes.push(attrs))\n const edges: GraphEdge[] = []\n graph.forEachEdge((_id, attrs) => edges.push(attrs))\n\n console.log('')\n console.log('=== neat init: summary ===')\n console.log(`snapshot: ${opts.outPath}`)\n console.log(`added: ${result.nodesAdded} nodes, ${result.edgesAdded} edges`)\n console.log(`total: ${graph.order} nodes, ${graph.size} edges`)\n console.log(summarise(nodes, edges))\n\n const incompatibilities = findIncompatibilities(nodes)\n if (incompatibilities.length > 0) {\n console.log('')\n console.log(`incompatibilities found in ${incompatibilities.length} service(s):`)\n for (const svc of incompatibilities) {\n for (const inc of svc.incompatibilities ?? []) {\n console.log(` ${svc.name}: ${formatIncompat(inc)}`)\n }\n }\n }\n\n return { exitCode: 0, writtenFiles: written }\n}\n\n// ── Claude Code skill (ADR-049 / v0.2.5 step 6) ────────────────────────\n//\n// The skill is a one-shot MCP-config drop-in. Source of truth for the\n// snippet lives here (the @neat.is/claude-skill package's\n// claude_code_config.json holds an identical copy for documentation; a\n// contract test keeps the two byte-aligned).\nexport const CLAUDE_SKILL_CONFIG = {\n mcpServers: {\n neat: {\n type: 'stdio' as const,\n command: 'npx',\n args: ['-y', '@neat.is/mcp'],\n env: {\n NEAT_API_URL: 'http://localhost:8080',\n },\n },\n },\n}\n\nfunction claudeConfigPath(): string {\n // ~/.claude.json is Claude Code's user-level MCP config. Tests override\n // via NEAT_CLAUDE_CONFIG so they don't touch the real file.\n const override = process.env.NEAT_CLAUDE_CONFIG\n if (override && override.length > 0) return path.resolve(override)\n const home = process.env.HOME ?? process.env.USERPROFILE ?? ''\n return path.join(home, '.claude.json')\n}\n\nexport interface SkillOptions {\n apply: boolean\n printConfig: boolean\n}\n\nexport async function runSkill(opts: SkillOptions): Promise<{ exitCode: number }> {\n const snippet = JSON.stringify(CLAUDE_SKILL_CONFIG, null, 2) + '\\n'\n\n if (opts.printConfig) {\n process.stdout.write(snippet)\n return { exitCode: 0 }\n }\n\n if (opts.apply) {\n const target = claudeConfigPath()\n let existing: Record<string, unknown> = {}\n try {\n existing = JSON.parse(await fs.readFile(target, 'utf8'))\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {\n console.error(`neat skill: failed to read ${target} — ${(err as Error).message}`)\n return { exitCode: 1 }\n }\n }\n // Merge mcpServers.neat without disturbing other entries the user\n // might have wired up by hand.\n const mcp =\n (existing as { mcpServers?: Record<string, unknown> }).mcpServers ?? {}\n const merged = {\n ...existing,\n mcpServers: { ...mcp, neat: CLAUDE_SKILL_CONFIG.mcpServers.neat },\n }\n await fs.mkdir(path.dirname(target), { recursive: true })\n await fs.writeFile(target, JSON.stringify(merged, null, 2) + '\\n', 'utf8')\n console.log(`neat skill: wrote mcpServers.neat to ${target}`)\n console.log('restart Claude Code to pick up the new MCP server.')\n return { exitCode: 0 }\n }\n\n console.log('neat skill — Claude Code MCP drop-in for NEAT')\n console.log('')\n console.log(' --print-config print the JSON snippet to stdout')\n console.log(' --apply merge mcpServers.neat into ~/.claude.json')\n console.log('')\n console.log('Manual install: copy mcpServers.neat from --print-config into ~/.claude.json,')\n console.log('then restart Claude Code. See packages/claude-skill/SKILL.md for the tool list.')\n return { exitCode: 0 }\n}\n\nasync function main(): Promise<void> {\n const [, , cmd, ...rest] = process.argv\n\n if (!cmd || cmd === '-h' || cmd === '--help') {\n usage()\n process.exit(0)\n }\n\n const parsed = parseArgs(rest)\n const { positional, apply, dryRun, noInstall } = parsed\n const project = parsed.project ?? DEFAULT_PROJECT\n\n if (cmd === 'init') {\n const target = positional[0]\n if (!target) {\n console.error('neat init: missing <path>')\n usage()\n process.exit(2)\n }\n if (apply && dryRun) {\n console.error('neat init: --apply and --dry-run are mutually exclusive')\n process.exit(2)\n }\n const scanPath = path.resolve(target)\n // ADR-046 — when --project isn't passed, the registry name defaults to\n // the basename of the scan path. The in-memory graph slot stays on\n // DEFAULT_PROJECT (back-compat with existing `neat watch` invocations).\n const projectExplicit = parsed.project !== null\n const projectName = projectExplicit ? project : path.basename(scanPath)\n // Default project keeps writing to graph.json (ADR-026 back-compat);\n // named projects use <project>.json under the same neat-out directory.\n const projectKey = projectExplicit ? project : DEFAULT_PROJECT\n const fallback = pathsForProject(projectKey, path.join(scanPath, 'neat-out')).snapshotPath\n const outPath = path.resolve(process.env.NEAT_OUT_PATH ?? fallback)\n const result = await runInit({\n scanPath,\n outPath,\n project: projectName,\n projectExplicit,\n apply,\n dryRun,\n noInstall,\n })\n if (result.exitCode !== 0) process.exit(result.exitCode)\n return\n }\n\n if (cmd === 'watch') {\n const target = positional[0]\n if (!target) {\n console.error('neat watch: missing <path>')\n usage()\n process.exit(2)\n }\n const scanPath = path.resolve(target)\n const stat = await fs.stat(scanPath).catch(() => null)\n if (!stat || !stat.isDirectory()) {\n console.error(`neat watch: ${scanPath} is not a directory`)\n process.exit(2)\n }\n const projectPaths = pathsForProject(project, path.join(scanPath, 'neat-out'))\n const outPath = path.resolve(process.env.NEAT_OUT_PATH ?? projectPaths.snapshotPath)\n const errorsPath = path.resolve(\n process.env.NEAT_ERRORS_PATH ??\n path.join(path.dirname(outPath), path.basename(projectPaths.errorsPath)),\n )\n const staleEventsPath = path.resolve(\n process.env.NEAT_STALE_EVENTS_PATH ??\n path.join(path.dirname(outPath), path.basename(projectPaths.staleEventsPath)),\n )\n\n const embeddingsCachePath = process.env.NEAT_EMBEDDINGS_CACHE_PATH\n ? path.resolve(process.env.NEAT_EMBEDDINGS_CACHE_PATH)\n : undefined\n\n const handle: WatchHandle = await startWatch(getGraph(project), {\n scanPath,\n outPath,\n errorsPath,\n staleEventsPath,\n project,\n ...(embeddingsCachePath ? { embeddingsCachePath } : {}),\n host: process.env.HOST ?? '0.0.0.0',\n port: Number(process.env.PORT ?? 8080),\n otelPort: Number(process.env.OTEL_PORT ?? 4318),\n otelGrpc: process.env.NEAT_OTLP_GRPC === 'true',\n otelGrpcPort: process.env.NEAT_OTLP_GRPC_PORT\n ? Number(process.env.NEAT_OTLP_GRPC_PORT)\n : undefined,\n })\n\n // startPersistLoop already wires SIGTERM/SIGINT to flush + exit. Hook in\n // ahead of it so the watcher closes cleanly first; the persist handler's\n // `process.exit(0)` will still run after our stop() resolves.\n let shuttingDown = false\n const shutdown = (signal: NodeJS.Signals): void => {\n if (shuttingDown) return\n shuttingDown = true\n console.log(`neat watch: ${signal} received, stopping…`)\n void handle.stop().catch((err) => {\n console.error('neat watch: shutdown error', err)\n })\n }\n process.on('SIGTERM', shutdown)\n process.on('SIGINT', shutdown)\n return\n }\n\n if (cmd === 'list') {\n const projects = await listProjects()\n if (projects.length === 0) {\n console.log('no projects registered. run `neat init <path>` to register one.')\n return\n }\n for (const p of projects) {\n const seen = p.lastSeenAt ? p.lastSeenAt : 'never'\n const langs = p.languages.length > 0 ? p.languages.join(',') : '-'\n console.log(`${p.name}\\t${p.status}\\t${langs}\\t${p.path}\\tlast-seen=${seen}`)\n }\n return\n }\n\n if (cmd === 'pause') {\n const name = positional[0]\n if (!name) {\n console.error('neat pause: missing <name>')\n usage()\n process.exit(2)\n }\n try {\n const entry = await setStatus(name, 'paused')\n console.log(`paused: ${entry.name} (${entry.path})`)\n } catch (err) {\n console.error((err as Error).message)\n process.exit(1)\n }\n return\n }\n\n if (cmd === 'resume') {\n const name = positional[0]\n if (!name) {\n console.error('neat resume: missing <name>')\n usage()\n process.exit(2)\n }\n try {\n const entry = await setStatus(name, 'active')\n console.log(`resumed: ${entry.name} (${entry.path})`)\n } catch (err) {\n console.error((err as Error).message)\n process.exit(1)\n }\n return\n }\n\n if (cmd === 'skill') {\n const result = await runSkill({ apply: parsed.apply, printConfig: parsed.printConfig })\n if (result.exitCode !== 0) process.exit(result.exitCode)\n return\n }\n\n if (cmd === 'uninstall') {\n const name = positional[0]\n if (!name) {\n console.error('neat uninstall: missing <name>')\n usage()\n process.exit(2)\n }\n const removed = await removeProject(name)\n if (!removed) {\n console.error(`neat uninstall: no project named \"${name}\"`)\n process.exit(1)\n }\n console.log(`unregistered: ${removed.name} (${removed.path})`)\n console.log('note: neat-out/, policy.json, and other files at the project path were left in place.')\n return\n }\n\n console.error(`neat: unknown command \"${cmd}\"`)\n usage()\n process.exit(1)\n}\n\n// Only auto-run when invoked as the CLI entry point. Importing this module\n// from tests must not start the parser; otherwise vitest sees a stray\n// `process.exit` from `main()` running with no argv.\nconst entry = process.argv[1] ?? ''\nif (/[\\\\/]cli\\.(?:cjs|js)$/.test(entry) || entry.endsWith('/cli') || entry.endsWith('/neat')) {\n main().catch((err) => {\n console.error(err)\n process.exit(1)\n })\n}\n","import GraphDefault from 'graphology'\nimport type { MultiDirectedGraph as MDGType } from 'graphology'\nimport type { GraphEdge, GraphNode } from '@neat.is/types'\n\n// graphology ships as a CJS bundle that does `module.exports = Graph` with\n// the other constructors attached as properties (`Graph.MultiDirectedGraph =\n// ...`). cjs-module-lexer can't see through that attachment, so a named\n// import like `import { MultiDirectedGraph } from 'graphology'` fails under\n// strict Node ESM (Node 22+ via tsx in particular). Pull the constructor off\n// the default export instead — same shape under tsx and tsup-bundled output.\ntype MultiDirectedGraphCtor = typeof MDGType\nconst MultiDirectedGraph: MultiDirectedGraphCtor = (\n GraphDefault as unknown as { MultiDirectedGraph: MultiDirectedGraphCtor }\n).MultiDirectedGraph\n\n// Multi because two nodes can have edges of different types simultaneously\n// (e.g. CALLS and DEPENDS_ON between the same pair of services).\nexport type NeatGraph = MDGType<GraphNode, GraphEdge>\n\nexport const DEFAULT_PROJECT = 'default'\n\n// One graph per project. The map is the source of truth; getGraph() with no\n// arg or with 'default' hits the legacy single-project path so existing\n// callers keep working byte-for-byte (ADR-026).\nconst graphs = new Map<string, NeatGraph>()\n\nfunction makeGraph(): NeatGraph {\n return new MultiDirectedGraph<GraphNode, GraphEdge>({ allowSelfLoops: false })\n}\n\nexport function getGraph(project: string = DEFAULT_PROJECT): NeatGraph {\n let g = graphs.get(project)\n if (!g) {\n g = makeGraph()\n graphs.set(project, g)\n }\n return g\n}\n\nexport function hasProject(project: string): boolean {\n return graphs.has(project)\n}\n\nexport function listProjects(): string[] {\n return [...graphs.keys()].sort()\n}\n\n// Reset a single project, or all of them when the arg is omitted. Tests use\n// the no-arg form between cases; runtime never calls it.\nexport function resetGraph(project?: string): void {\n if (project === undefined) {\n graphs.clear()\n return\n }\n graphs.delete(project)\n}\n","export { extractFromDirectory, type ExtractResult } from './extract/index.js'\n","// Static-extraction pipeline. Phase order is load-bearing:\n// services → aliases → databases (+ compat) → configs → calls → infra → frontier promotion.\n//\n// Contract anchors (see /docs/contracts.md):\n// * Rule 1 — Every emitted edge carries Provenance.EXTRACTED from @neat.is/types.\n// * Rule 2 — EXTRACTED edges use the plain `${type}:src->tgt` id pattern.\n// Never write under the OBSERVED id pattern; that's ingest.ts's territory.\n// * Rule 5 — Nodes/edges constructed against schemas in @neat.is/types; no\n// local interface redefinitions in this tree.\n// * Rule 8 — No demo-name hardcoding. Driver names come from package.json\n// dependencies; engine names from compat.json via compatPairs().\n// * Rule 14 — ConfigNodes record file existence only; never the contents.\nimport type { NeatGraph } from '../graph.js'\nimport { promoteFrontierNodes } from '../ingest.js'\nimport { ensureCompatLoaded } from '../compat.js'\nimport { addServiceNodes, discoverServices } from './services.js'\nimport { addServiceAliases } from './aliases.js'\nimport { addDatabasesAndCompat } from './databases/index.js'\nimport { addConfigNodes } from './configs.js'\nimport { addCallEdges } from './calls/index.js'\nimport { addInfra } from './infra/index.js'\n\nexport interface ExtractResult {\n nodesAdded: number\n edgesAdded: number\n frontiersPromoted: number\n}\n\nexport interface ExtractOptions {\n // Post-extract policy trigger (ADR-043). Awaited after frontier promotion\n // so policies see the final post-pass graph state. Daemons wire this to\n // evaluateAllPolicies + PolicyViolationsLog.append.\n onPolicyTrigger?: (graph: NeatGraph) => Promise<void> | void\n}\n\nexport async function extractFromDirectory(\n graph: NeatGraph,\n scanPath: string,\n opts: ExtractOptions = {},\n): Promise<ExtractResult> {\n await ensureCompatLoaded()\n const services = await discoverServices(scanPath)\n\n const phase1Nodes = addServiceNodes(graph, services)\n await addServiceAliases(graph, scanPath, services)\n const phase2 = await addDatabasesAndCompat(graph, services, scanPath)\n const phase3 = await addConfigNodes(graph, services, scanPath)\n const phase4 = await addCallEdges(graph, services)\n const phase5 = await addInfra(graph, scanPath, services)\n const frontiersPromoted = promoteFrontierNodes(graph)\n\n // Post-extract policy trigger (ADR-043). Fires after frontier promotion so\n // policies see the post-pass graph (including any FRONTIER → OBSERVED edge\n // upgrades that just landed).\n if (opts.onPolicyTrigger) await opts.onPolicyTrigger(graph)\n\n return {\n nodesAdded:\n phase1Nodes +\n phase2.nodesAdded +\n phase3.nodesAdded +\n phase4.nodesAdded +\n phase5.nodesAdded,\n edgesAdded:\n phase2.edgesAdded + phase3.edgesAdded + phase4.edgesAdded + phase5.edgesAdded,\n frontiersPromoted,\n }\n}\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport type {\n DatabaseNode,\n ErrorEvent,\n FrontierNode,\n GraphEdge,\n Policy,\n ServiceNode,\n} from '@neat.is/types'\nimport type { EvaluationContext as PolicyEvaluationContext } from './policy.js'\nimport { canPromoteFrontier } from './policy.js'\nimport {\n EdgeType,\n NodeType,\n Provenance,\n databaseId,\n extractedEdgeId,\n frontierEdgeId,\n frontierId,\n inferredEdgeId,\n observedEdgeId,\n serviceId,\n type EdgeTypeValue,\n} from '@neat.is/types'\nimport type { NeatGraph } from './graph.js'\nimport type { ParsedSpan } from './otel.js'\n\n// Maps OTel spans to graph signal:\n// * Cross-service span → upsert CALLS edge.\n// * Database span (db.system attr present) → upsert CONNECTS_TO edge to a\n// DatabaseNode resolved by host.\n// * Span with status.code === 2 → ErrorEvent appended to errors.ndjson.\n//\n// Contract anchors (see /docs/contracts.md):\n// * Rule 1 — Provenance: every edge here carries Provenance.X from @neat.is/types.\n// * Rule 2 — Coexistence: OBSERVED edges live alongside EXTRACTED ones with a\n// distinct id pattern (`${type}:OBSERVED:src->tgt`). Never write OBSERVED\n// under the EXTRACTED id; that erases the gap NEAT exists to surface.\n// * Rule 4 — Per-edge-type staleness (ADR-024): STALE_THRESHOLDS_BY_EDGE_TYPE\n// governs decay; never hardcode a flat 24h threshold.\n// * Rule 8 — No demo names: derive driver/engine identifiers from node\n// properties, not literals.\n\nexport interface IngestContext {\n graph: NeatGraph\n errorsPath: string\n now?: () => number\n // Set to false when the receiver already wrote the ErrorEvent synchronously\n // (production daemons via watch.ts wire this). When true or omitted, handleSpan\n // appends the ErrorEvent itself — the path used by ad-hoc scripts and tests\n // that don't go through buildOtelReceiver. ADR-033 §Error events.\n writeErrorEventInline?: boolean\n // Post-mutation policy trigger (ADR-043). Fires after handleSpan finishes\n // and the queue is drained. Daemons wire this to evaluateAllPolicies +\n // PolicyViolationsLog.append. Ad-hoc callers leave it undefined; their tests\n // don't need policy side effects.\n onPolicyTrigger?: (graph: NeatGraph) => Promise<void> | void\n}\n\nconst HOUR_MS = 60 * 60 * 1000\nconst DAY_MS = 24 * HOUR_MS\n\n// Per-edge-type stale thresholds. HTTP CALLS at 24h is meaningless because\n// healthy traffic recurs in seconds; infra DEPENDS_ON is the opposite — a\n// docker-compose service can sit idle overnight without anything being wrong.\n// Override via NEAT_STALE_THRESHOLDS (JSON, ms-per-edge-type).\nconst DEFAULT_STALE_THRESHOLDS: Record<string, number> = {\n CALLS: HOUR_MS,\n CONNECTS_TO: 4 * HOUR_MS,\n PUBLISHES_TO: 4 * HOUR_MS,\n CONSUMES_FROM: 4 * HOUR_MS,\n DEPENDS_ON: DAY_MS,\n CONFIGURED_BY: DAY_MS,\n RUNS_ON: DAY_MS,\n}\n// Fallback for any edge type not in the map (forward compat — adding a new\n// EdgeType shouldn't break staleness sweeps).\nconst FALLBACK_STALE_THRESHOLD_MS = DAY_MS\n\nfunction loadStaleThresholdsFromEnv(): Record<string, number> {\n const raw = process.env.NEAT_STALE_THRESHOLDS\n if (!raw) return DEFAULT_STALE_THRESHOLDS\n try {\n const overrides = JSON.parse(raw) as Record<string, unknown>\n const merged = { ...DEFAULT_STALE_THRESHOLDS }\n for (const [k, v] of Object.entries(overrides)) {\n if (typeof v === 'number' && Number.isFinite(v) && v >= 0) merged[k] = v\n }\n return merged\n } catch (err) {\n console.warn(\n `[neat] NEAT_STALE_THRESHOLDS could not be parsed (${(err as Error).message}); using defaults`,\n )\n return DEFAULT_STALE_THRESHOLDS\n }\n}\n\nexport function thresholdForEdgeType(\n edgeType: string,\n overrides?: Record<string, number>,\n): number {\n const map = overrides ?? loadStaleThresholdsFromEnv()\n return map[edgeType] ?? FALLBACK_STALE_THRESHOLD_MS\n}\n\nfunction nowIso(ctx: IngestContext): string {\n return new Date(ctx.now ? ctx.now() : Date.now()).toISOString()\n}\n\nfunction pickAttr(span: ParsedSpan, ...keys: string[]): string | undefined {\n for (const k of keys) {\n const v = span.attributes[k]\n if (typeof v === 'string' && v.length > 0) return v\n }\n return undefined\n}\n\nfunction hostFromUrl(u: string | undefined): string | undefined {\n if (!u) return undefined\n try {\n return new URL(u).hostname\n } catch {\n return undefined\n }\n}\n\n// OTel HTTP/db semconv has gone through several names for \"the host on the\n// other end of this call.\" Try the modern ones first, fall back to the legacy\n// ones, then last resort parse out of a full URL.\nfunction pickAddress(span: ParsedSpan): string | undefined {\n return (\n pickAttr(span, 'server.address', 'net.peer.name', 'net.host.name') ??\n hostFromUrl(pickAttr(span, 'url.full', 'http.url'))\n )\n}\n\n// Edge id helpers live in @neat.is/types/identity.ts (ADR-029). The local\n// signatures below preserve the (type, source, target) argument order ingest.ts\n// has used historically while delegating to the canonical wire-format helpers.\nfunction makeObservedEdgeId(type: EdgeTypeValue, source: string, target: string): string {\n return observedEdgeId(source, target, type)\n}\n\nfunction makeInferredEdgeId(type: EdgeTypeValue, source: string, target: string): string {\n return inferredEdgeId(source, target, type)\n}\n\nconst INFERRED_CONFIDENCE = 0.6\nconst STITCH_MAX_DEPTH = 2\n\n// Parent-span TTL cache (ADR-033). Address-based peer resolution (server.address /\n// net.peer.name / url.full) misses non-HTTP RPCs and any span with an opaque\n// peer. The cache stores each span's service keyed by `${traceId}:${spanId}` so\n// a child span whose address resolution fails can fall back to its parent's\n// service, identifying a cross-service CALLS edge from parent → current.\n//\n// Bounded size + TTL — out-of-order arrival (child before parent) drops the\n// child rather than buffering. We accept that loss because the cache is best-\n// effort: for every cross-service call, the CLIENT span on the caller side\n// covers the same edge via address-based resolution, so missing one direction\n// is recoverable.\nconst PARENT_SPAN_CACHE_SIZE = 10_000\nconst PARENT_SPAN_CACHE_TTL_MS = 5 * 60 * 1000\n\ninterface ParentSpanCacheEntry {\n service: string\n expiresAt: number\n}\n\nconst parentSpanCache = new Map<string, ParentSpanCacheEntry>()\n\nfunction parentSpanKey(traceId: string, spanId: string): string {\n return `${traceId}:${spanId}`\n}\n\nfunction cacheSpanService(span: ParsedSpan, now: number): void {\n if (!span.traceId || !span.spanId) return\n const key = parentSpanKey(span.traceId, span.spanId)\n // Map preserves insertion order, so deleting + re-inserting bumps an entry to\n // the back. Eviction is \"drop oldest\" once size exceeds the cap.\n parentSpanCache.delete(key)\n parentSpanCache.set(key, { service: span.service, expiresAt: now + PARENT_SPAN_CACHE_TTL_MS })\n while (parentSpanCache.size > PARENT_SPAN_CACHE_SIZE) {\n const oldest = parentSpanCache.keys().next().value\n if (!oldest) break\n parentSpanCache.delete(oldest)\n }\n}\n\nfunction lookupParentSpanService(\n traceId: string,\n parentSpanId: string,\n now: number,\n): string | null {\n const entry = parentSpanCache.get(parentSpanKey(traceId, parentSpanId))\n if (!entry) return null\n if (entry.expiresAt <= now) {\n parentSpanCache.delete(parentSpanKey(traceId, parentSpanId))\n return null\n }\n return entry.service\n}\n\n// Test seam: lets unit tests start from a clean slate.\nexport function resetParentSpanCache(): void {\n parentSpanCache.clear()\n}\n\nfunction resolveServiceId(graph: NeatGraph, host: string): string | null {\n const direct = serviceId(host)\n if (graph.hasNode(direct)) return direct\n\n // Service hostnames in the demo can match either the package name (which the\n // node id is built from) or the directory basename — handled by the name\n // check below. Beyond that, anything in `aliases` (compose service names,\n // k8s metadata.name + cluster-DNS variants, Dockerfile labels) should\n // resolve too. Population happens in the extract phases; consumption is\n // here.\n let found: string | null = null\n graph.forEachNode((id, attrs) => {\n if (found) return\n const a = attrs as ServiceNode & { type?: string }\n if (a.type !== NodeType.ServiceNode) return\n if (a.name === host) {\n found = id\n return\n }\n if (a.aliases && a.aliases.includes(host)) {\n found = id\n }\n })\n return found\n}\n\nexport function frontierIdFor(host: string): string {\n return frontierId(host)\n}\n\n// Auto-create a minimal ServiceNode for span.service when no such node exists.\n// Used at the top of handleSpan so subsequent edge upserts always have endpoints\n// — without it, OBSERVED edges silently drop for any service the static\n// extractor hasn't reached yet (and never reaches at all in OTel-only setups).\n// `language: 'unknown'` is the contract's specified placeholder (ADR-033). When\n// static extraction later produces a ServiceNode at the same id, addServiceNodes\n// merges and flips discoveredVia to 'merged' rather than overwriting.\nfunction ensureServiceNode(graph: NeatGraph, serviceName: string): string {\n const id = serviceId(serviceName)\n if (graph.hasNode(id)) return id\n const node: ServiceNode = {\n id,\n type: NodeType.ServiceNode,\n name: serviceName,\n language: 'unknown',\n discoveredVia: 'otel',\n }\n graph.addNode(id, node)\n return id\n}\n\n// Same shape for unseen db.system + host pairs. Engine comes off the OTel\n// attribute as a string per Rule 8 — no hardcoded engine list. compatibleDrivers\n// is empty until static extraction merges in the matrix-derived drivers.\nfunction ensureDatabaseNode(graph: NeatGraph, host: string, engine: string): string {\n const id = databaseId(host)\n if (graph.hasNode(id)) return id\n const node: DatabaseNode = {\n id,\n type: NodeType.DatabaseNode,\n name: host,\n engine,\n engineVersion: 'unknown',\n compatibleDrivers: [],\n host,\n discoveredVia: 'otel',\n }\n graph.addNode(id, node)\n return id\n}\n\nfunction ensureFrontierNode(graph: NeatGraph, host: string, ts: string): string {\n const id = frontierIdFor(host)\n if (graph.hasNode(id)) {\n const existing = graph.getNodeAttributes(id) as FrontierNode\n graph.replaceNodeAttributes(id, { ...existing, lastObserved: ts })\n return id\n }\n const node: FrontierNode = {\n id,\n type: NodeType.FrontierNode,\n name: host,\n host,\n firstObserved: ts,\n lastObserved: ts,\n }\n graph.addNode(id, node)\n return id\n}\n\nfunction upsertFrontierEdge(\n graph: NeatGraph,\n type: EdgeTypeValue,\n source: string,\n target: string,\n ts: string,\n): void {\n const id = frontierEdgeId(source, target, type)\n if (graph.hasEdge(id)) {\n const existing = graph.getEdgeAttributes(id) as GraphEdge\n const updated: GraphEdge = {\n ...existing,\n provenance: Provenance.FRONTIER,\n lastObserved: ts,\n callCount: (existing.callCount ?? 0) + 1,\n }\n graph.replaceEdgeAttributes(id, updated)\n return\n }\n const edge: GraphEdge = {\n id,\n source,\n target,\n type,\n provenance: Provenance.FRONTIER,\n confidence: 1.0,\n lastObserved: ts,\n callCount: 1,\n }\n graph.addEdgeWithKey(id, source, target, edge)\n}\n\ninterface UpsertResult {\n edge: GraphEdge\n created: boolean\n}\n\nfunction upsertObservedEdge(\n graph: NeatGraph,\n type: EdgeTypeValue,\n source: string,\n target: string,\n ts: string,\n isError = false,\n): UpsertResult | null {\n if (!graph.hasNode(source) || !graph.hasNode(target)) return null\n\n const id = makeObservedEdgeId(type, source, target)\n if (graph.hasEdge(id)) {\n const existing = graph.getEdgeAttributes(id) as GraphEdge\n const newSpanCount = (existing.signal?.spanCount ?? existing.callCount ?? 0) + 1\n const newErrorCount = (existing.signal?.errorCount ?? 0) + (isError ? 1 : 0)\n const updated: GraphEdge = {\n ...existing,\n provenance: Provenance.OBSERVED,\n lastObserved: ts,\n callCount: newSpanCount,\n signal: {\n spanCount: newSpanCount,\n errorCount: newErrorCount,\n lastObservedAgeMs: 0,\n },\n confidence: 1.0,\n }\n graph.replaceEdgeAttributes(id, updated)\n return { edge: updated, created: false }\n }\n\n const edge: GraphEdge = {\n id,\n source,\n target,\n type,\n provenance: Provenance.OBSERVED,\n confidence: 1.0,\n lastObserved: ts,\n callCount: 1,\n signal: {\n spanCount: 1,\n errorCount: isError ? 1 : 0,\n lastObservedAgeMs: 0,\n },\n }\n graph.addEdgeWithKey(id, source, target, edge)\n return { edge, created: true }\n}\n\n// When a span errors, the system is exercising its dependencies right now even\n// if some of them aren't auto-instrumented (pg 7.4.0 in the demo, see ADR-014).\n// Walk EXTRACTED edges out from the erroring service for a couple of hops and\n// promote them to INFERRED twins so traversal can prefer them over the bare\n// static edges without claiming OBSERVED-grade certainty.\nfunction stitchTrace(graph: NeatGraph, sourceServiceId: string, ts: string): void {\n if (!graph.hasNode(sourceServiceId)) return\n\n const visited = new Set<string>([sourceServiceId])\n const queue: { nodeId: string; depth: number }[] = [{ nodeId: sourceServiceId, depth: 0 }]\n\n while (queue.length > 0) {\n const { nodeId, depth } = queue.shift()!\n if (depth >= STITCH_MAX_DEPTH) continue\n\n const outbound = graph.outboundEdges(nodeId)\n for (const edgeId of outbound) {\n const edge = graph.getEdgeAttributes(edgeId) as GraphEdge\n if (edge.provenance !== Provenance.EXTRACTED) continue\n\n // OBSERVED twin already covers this hop with ground truth — no inference\n // needed (ADR-034). Stomping it with INFERRED erases the gap NEAT exists\n // to surface; skipping it keeps the OBSERVED edge as the authoritative\n // record and avoids cluttering the graph with a redundant INFERRED twin.\n if (graph.hasEdge(observedEdgeId(edge.source, edge.target, edge.type))) continue\n\n upsertInferredEdge(graph, edge.type, edge.source, edge.target, ts)\n\n if (!visited.has(edge.target)) {\n visited.add(edge.target)\n queue.push({ nodeId: edge.target, depth: depth + 1 })\n }\n }\n }\n}\n\nfunction upsertInferredEdge(\n graph: NeatGraph,\n type: EdgeTypeValue,\n source: string,\n target: string,\n ts: string,\n): void {\n const id = makeInferredEdgeId(type, source, target)\n if (graph.hasEdge(id)) {\n const existing = graph.getEdgeAttributes(id) as GraphEdge\n const updated: GraphEdge = { ...existing, lastObserved: ts }\n graph.replaceEdgeAttributes(id, updated)\n return\n }\n\n const edge: GraphEdge = {\n id,\n source,\n target,\n type,\n provenance: Provenance.INFERRED,\n confidence: INFERRED_CONFIDENCE,\n lastObserved: ts,\n }\n graph.addEdgeWithKey(id, source, target, edge)\n}\n\nasync function appendErrorEvent(ctx: IngestContext, ev: ErrorEvent): Promise<void> {\n await fs.mkdir(path.dirname(ctx.errorsPath), { recursive: true })\n await fs.appendFile(ctx.errorsPath, JSON.stringify(ev) + '\\n', 'utf8')\n}\n\n// Build the minimal ErrorEvent the receiver writes synchronously before\n// replying (ADR-033 §Error events, amended). affectedNode resolves to the\n// originating service because graph state isn't available at this point —\n// the queued handleSpan path may reach a more precise target later, but the\n// durable record is what the receiver writes here.\nexport function buildErrorEventForReceiver(span: ParsedSpan): ErrorEvent | null {\n if (span.statusCode !== 2) return null\n const ts = span.startTimeIso ?? new Date().toISOString()\n return {\n id: `${span.traceId}:${span.spanId}`,\n timestamp: ts,\n service: span.service,\n traceId: span.traceId,\n spanId: span.spanId,\n errorMessage:\n span.exception?.message ?? span.errorMessage ?? span.name ?? 'unknown error',\n ...(span.exception?.type ? { exceptionType: span.exception.type } : {}),\n ...(span.exception?.stacktrace\n ? { exceptionStacktrace: span.exception.stacktrace }\n : {}),\n affectedNode: serviceId(span.service),\n }\n}\n\n// Synchronous file-write helper bound to a receiver. The receiver awaits this\n// before replying, so a write failure surfaces as 500 → OTel SDK retries.\nexport function makeErrorSpanWriter(\n errorsPath: string,\n): (span: ParsedSpan) => Promise<void> {\n return async (span) => {\n const ev = buildErrorEventForReceiver(span)\n if (!ev) return\n await fs.mkdir(path.dirname(errorsPath), { recursive: true })\n await fs.appendFile(errorsPath, JSON.stringify(ev) + '\\n', 'utf8')\n }\n}\n\nexport async function handleSpan(ctx: IngestContext, span: ParsedSpan): Promise<void> {\n // lastObserved derives from the span's own startTime per ADR-033 — replayed\n // traces and out-of-order spans get a timestamp that reflects when the call\n // actually fired, not when the receiver received it. Wall-clock is only the\n // fallback for spans whose startTimeUnixNano is missing or unparseable.\n const ts = span.startTimeIso ?? nowIso(ctx)\n const nowMs = ctx.now ? ctx.now() : Date.now()\n // Auto-create a minimal ServiceNode for unseen span.service so OBSERVED\n // edges land instead of silently dropping. Static extraction merges richer\n // fields when it later finds the same id (ADR-033).\n const sourceId = ensureServiceNode(ctx.graph, span.service)\n const isError = span.statusCode === 2\n // Stash this span in the parent-span cache so any later child whose address\n // resolution misses can still resolve the cross-service edge via parentSpanId.\n cacheSpanService(span, nowMs)\n\n let affectedNode = sourceId\n\n if (span.dbSystem) {\n // Database span — try to resolve the DatabaseNode by host.\n const host = pickAddress(span)\n if (host) {\n // Auto-create a minimal DatabaseNode when this host hasn't been seen.\n // Engine comes off the OTel attribute as a string per Rule 8.\n ensureDatabaseNode(ctx.graph, host, span.dbSystem)\n const targetId = databaseId(host)\n const result = upsertObservedEdge(\n ctx.graph,\n EdgeType.CONNECTS_TO,\n sourceId,\n targetId,\n ts,\n isError,\n )\n if (result) affectedNode = targetId\n }\n } else {\n // Possibly a cross-service call. Resolve the peer; if it matches a known\n // ServiceNode, record an OBSERVED CALLS edge. If it matches nothing — pod\n // IP, ingress hostname, AWS PrivateLink endpoint — drop a FRONTIER\n // placeholder so the call isn't lost. promoteFrontierNodes (run by the\n // extract orchestrator) replaces it once a later round records the host\n // as an alias on a real service.\n const host = pickAddress(span)\n let resolvedViaAddress = false\n if (host && host !== span.service) {\n const targetId = resolveServiceId(ctx.graph, host)\n if (targetId && targetId !== sourceId) {\n upsertObservedEdge(\n ctx.graph,\n EdgeType.CALLS,\n sourceId,\n targetId,\n ts,\n isError,\n )\n affectedNode = targetId\n resolvedViaAddress = true\n } else if (!targetId) {\n const frontierId = ensureFrontierNode(ctx.graph, host, ts)\n if (ctx.graph.hasNode(sourceId)) {\n upsertFrontierEdge(ctx.graph, EdgeType.CALLS, sourceId, frontierId, ts)\n }\n affectedNode = frontierId\n resolvedViaAddress = true\n }\n }\n\n // Parent-span fallback (ADR-033): when address-based resolution didn't\n // produce an edge and the span has a parentSpanId we've cached, the\n // parent's service identifies the caller. The current span is the server\n // side of the call, so the edge direction is parent.service → current.\n if (!resolvedViaAddress && span.parentSpanId) {\n const parentService = lookupParentSpanService(span.traceId, span.parentSpanId, nowMs)\n if (parentService && parentService !== span.service) {\n const parentId = ensureServiceNode(ctx.graph, parentService)\n upsertObservedEdge(\n ctx.graph,\n EdgeType.CALLS,\n parentId,\n sourceId,\n ts,\n isError,\n )\n }\n }\n }\n\n if (span.statusCode === 2) {\n stitchTrace(ctx.graph, sourceId, ts)\n // The durable ErrorEvent write moved to the receiver so the file write\n // happens synchronously before the 200 reply (ADR-033 §Error events,\n // amended). watch.ts wires makeErrorSpanWriter into onErrorSpanSync.\n // handleSpan still runs the in-graph error effects (stitchTrace above);\n // it just doesn't append to errors.ndjson anymore. ctx.errorsPath stays\n // for the optional opt-in path below — daemon-less callers (CLI tests,\n // ad-hoc scripts) that skip the receiver hook still get a write here.\n if (ctx.writeErrorEventInline !== false) {\n const ev: ErrorEvent = {\n id: `${span.traceId}:${span.spanId}`,\n timestamp: ts,\n service: span.service,\n traceId: span.traceId,\n spanId: span.spanId,\n errorMessage:\n span.exception?.message ?? span.errorMessage ?? span.name ?? 'unknown error',\n ...(span.exception?.type ? { exceptionType: span.exception.type } : {}),\n ...(span.exception?.stacktrace\n ? { exceptionStacktrace: span.exception.stacktrace }\n : {}),\n affectedNode,\n }\n await appendErrorEvent(ctx, ev)\n }\n }\n void affectedNode\n\n // Post-ingest policy trigger (ADR-043). The hook is awaited so failures\n // surface; daemons wrap it in a try/catch that logs without throwing.\n if (ctx.onPolicyTrigger) await ctx.onPolicyTrigger(ctx.graph)\n}\n\nexport { stitchTrace }\n\n// Promote any frontier:<host> placeholder whose host matches an alias on a\n// real ServiceNode: re-link inbound/outbound edges to the service, then drop\n// the placeholder. Returns the count of nodes promoted, for tests + logs.\n//\n// Called at the end of every extraction round. Static rounds are when new\n// aliases land (compose names, k8s metadata.name, Dockerfile labels), so\n// running it there picks up the case the issue describes: ingest fills in a\n// frontier when traffic arrives for an unknown host, and the next extraction\n// round resolves it.\n// Optional gate for block-action policies (ADR-044). When `policies` is\n// non-empty, each candidate FrontierNode runs through `canPromoteFrontier`\n// before its incident edges are rewired. Block-action policies that fire on\n// the frontier veto the promotion — the FrontierNode persists; the next\n// extract pass tries again.\nexport interface PromoteFrontierOptions {\n policies?: Policy[]\n policyCtx?: PolicyEvaluationContext\n}\n\nexport function promoteFrontierNodes(\n graph: NeatGraph,\n opts: PromoteFrontierOptions = {},\n): number {\n const aliasIndex = new Map<string, string>()\n graph.forEachNode((id, attrs) => {\n const a = attrs as ServiceNode & { type?: string }\n if (a.type !== NodeType.ServiceNode) return\n aliasIndex.set(a.name, id)\n if (a.aliases) {\n for (const alias of a.aliases) aliasIndex.set(alias, id)\n }\n })\n\n const toPromote: { frontierId: string; serviceId: string }[] = []\n graph.forEachNode((id, attrs) => {\n const a = attrs as FrontierNode & { type?: string }\n if (a.type !== NodeType.FrontierNode) return\n const target = aliasIndex.get(a.host)\n if (!target) return\n if (target === id) return\n toPromote.push({ frontierId: id, serviceId: target })\n })\n\n let promoted = 0\n for (const { frontierId, serviceId } of toPromote) {\n if (opts.policies && opts.policies.length > 0 && opts.policyCtx) {\n const gate = canPromoteFrontier(graph, frontierId, opts.policies, opts.policyCtx)\n if (!gate.allowed) {\n // Block-action policy fired on this frontier — skip the rewire and\n // leave the FrontierNode in place. Violations already surfaced via\n // the policy log on the same evaluation pass.\n continue\n }\n }\n rewireFrontierEdges(graph, frontierId, serviceId)\n graph.dropNode(frontierId)\n promoted++\n }\n return promoted\n}\n\nfunction rewireFrontierEdges(graph: NeatGraph, frontierId: string, serviceId: string): void {\n const inbound = [...graph.inboundEdges(frontierId)]\n const outbound = [...graph.outboundEdges(frontierId)]\n\n for (const edgeId of inbound) {\n const edge = graph.getEdgeAttributes(edgeId) as GraphEdge\n rebuildEdge(graph, edge, edge.source, serviceId, edgeId)\n }\n for (const edgeId of outbound) {\n const edge = graph.getEdgeAttributes(edgeId) as GraphEdge\n rebuildEdge(graph, edge, serviceId, edge.target, edgeId)\n }\n}\n\nfunction rebuildEdge(\n graph: NeatGraph,\n edge: GraphEdge,\n newSource: string,\n newTarget: string,\n oldEdgeId: string,\n): void {\n graph.dropEdge(oldEdgeId)\n // FRONTIER provenance gets upgraded to OBSERVED on promotion: the call\n // certainty was always there; only the target identity was unknown, and now\n // it isn't.\n const promotedProvenance =\n edge.provenance === Provenance.FRONTIER ? Provenance.OBSERVED : edge.provenance\n const newId =\n promotedProvenance === Provenance.OBSERVED\n ? observedEdgeId(newSource, newTarget, edge.type)\n : promotedProvenance === Provenance.INFERRED\n ? inferredEdgeId(newSource, newTarget, edge.type)\n : promotedProvenance === Provenance.EXTRACTED\n ? extractedEdgeId(newSource, newTarget, edge.type)\n : frontierEdgeId(newSource, newTarget, edge.type)\n\n if (graph.hasEdge(newId)) {\n const existing = graph.getEdgeAttributes(newId) as GraphEdge\n const merged: GraphEdge = {\n ...existing,\n callCount: (existing.callCount ?? 0) + (edge.callCount ?? 0),\n lastObserved: pickLater(existing.lastObserved, edge.lastObserved),\n }\n graph.replaceEdgeAttributes(newId, merged)\n return\n }\n\n const rebuilt: GraphEdge = {\n ...edge,\n id: newId,\n source: newSource,\n target: newTarget,\n provenance: promotedProvenance,\n }\n graph.addEdgeWithKey(newId, newSource, newTarget, rebuilt)\n}\n\nfunction pickLater(a: string | undefined, b: string | undefined): string | undefined {\n if (!a) return b\n if (!b) return a\n return new Date(a).getTime() >= new Date(b).getTime() ? a : b\n}\n\nexport function makeSpanHandler(ctx: IngestContext): (span: ParsedSpan) => Promise<void> {\n return (span) => handleSpan(ctx, span)\n}\n\nexport interface StaleEvent {\n edgeId: string\n source: string\n target: string\n edgeType: string\n thresholdMs: number\n ageMs: number\n lastObserved: string\n transitionedAt: string\n}\n\nexport interface MarkStaleOptions {\n // Per-edge-type override map. Defaults to DEFAULT_STALE_THRESHOLDS, merged\n // with NEAT_STALE_THRESHOLDS if the env var is set.\n thresholds?: Record<string, number>\n now?: number\n // ndjson path. When set, every OBSERVED → STALE transition appends one\n // line. Skipped if undefined — tests and embedded use cases don't need a\n // log.\n staleEventsPath?: string\n}\n\n// Demote OBSERVED edges that haven't been seen in a while. Per-edge-type\n// thresholds: HTTP CALLS go stale fast; infra DEPENDS_ON is patient. Returns\n// the count of demotions and the events appended to the log.\nexport async function markStaleEdges(\n graph: NeatGraph,\n options: MarkStaleOptions = {},\n): Promise<{ count: number; events: StaleEvent[] }> {\n const thresholds = options.thresholds ?? loadStaleThresholdsFromEnv()\n const now = options.now ?? Date.now()\n const events: StaleEvent[] = []\n\n graph.forEachEdge((id, attrs) => {\n const e = attrs as GraphEdge\n if (e.provenance !== Provenance.OBSERVED) return\n if (!e.lastObserved) return\n const threshold = thresholdForEdgeType(e.type, thresholds)\n const age = now - new Date(e.lastObserved).getTime()\n if (age > threshold) {\n const updated: GraphEdge = { ...e, provenance: Provenance.STALE, confidence: 0.3 }\n graph.replaceEdgeAttributes(id, updated)\n events.push({\n edgeId: id,\n source: e.source,\n target: e.target,\n edgeType: e.type,\n thresholdMs: threshold,\n ageMs: age,\n lastObserved: e.lastObserved,\n transitionedAt: new Date(now).toISOString(),\n })\n }\n })\n\n if (options.staleEventsPath && events.length > 0) {\n await appendStaleEvents(options.staleEventsPath, events)\n }\n\n return { count: events.length, events }\n}\n\nasync function appendStaleEvents(staleEventsPath: string, events: StaleEvent[]): Promise<void> {\n await fs.mkdir(path.dirname(staleEventsPath), { recursive: true })\n const lines = events.map((e) => JSON.stringify(e)).join('\\n') + '\\n'\n await fs.appendFile(staleEventsPath, lines, 'utf8')\n}\n\nexport async function readStaleEvents(staleEventsPath: string): Promise<StaleEvent[]> {\n try {\n const raw = await fs.readFile(staleEventsPath, 'utf8')\n return raw\n .split('\\n')\n .filter((line) => line.length > 0)\n .map((line) => JSON.parse(line) as StaleEvent)\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return []\n throw err\n }\n}\n\nexport interface StalenessLoopOptions {\n thresholds?: Record<string, number>\n intervalMs?: number\n staleEventsPath?: string\n // Post-stale-transition policy trigger (ADR-043). Fires after each tick of\n // markStaleEdges so policies see the new STALE state. Daemons wire this to\n // evaluateAllPolicies + PolicyViolationsLog.append.\n onPolicyTrigger?: (graph: NeatGraph) => Promise<void> | void\n}\n\nexport function startStalenessLoop(\n graph: NeatGraph,\n options: StalenessLoopOptions = {},\n): () => void {\n let stopped = false\n const intervalMs = options.intervalMs ?? 60_000\n const tick = (): void => {\n if (stopped) return\n void (async () => {\n try {\n await markStaleEdges(graph, {\n thresholds: options.thresholds,\n staleEventsPath: options.staleEventsPath,\n })\n if (options.onPolicyTrigger) await options.onPolicyTrigger(graph)\n } catch (err) {\n console.error('staleness tick failed', err)\n }\n })()\n }\n const interval = setInterval(tick, intervalMs)\n if (typeof interval.unref === 'function') interval.unref()\n return () => {\n stopped = true\n clearInterval(interval)\n }\n}\n\nexport async function readErrorEvents(errorsPath: string): Promise<ErrorEvent[]> {\n try {\n const raw = await fs.readFile(errorsPath, 'utf8')\n return raw\n .split('\\n')\n .filter((line) => line.length > 0)\n .map((line) => JSON.parse(line) as ErrorEvent)\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return []\n throw err\n }\n}\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport type {\n GraphEdge,\n GraphNode,\n Policy,\n PolicyAction,\n PolicyFile,\n PolicyRule,\n PolicySeverity,\n PolicyViolation,\n ServiceNode,\n} from '@neat.is/types'\nimport {\n EdgeType,\n NodeType,\n PolicyFileSchema,\n Provenance,\n} from '@neat.is/types'\nimport type { NeatGraph } from './graph.js'\nimport {\n checkCompatibility,\n checkDeprecatedApi,\n checkNodeEngineConstraint,\n checkPackageConflict,\n compatPairs,\n deprecatedApis,\n nodeEngineConstraints,\n packageConflicts,\n} from './compat.js'\nimport { getBlastRadius } from './traverse.js'\n\n// Policy evaluation engine (ADR-043). The entry point evaluateAllPolicies is\n// pure: same graph + same policies → same violations. Per-rule-type dispatch\n// via the policyEvaluators table. Adding a new rule type means one new\n// evaluator entry plus the schema entry in @neat.is/types/policy.ts.\n//\n// Deterministic violation ids per ADR-043: ${policy.id}:${context}. The\n// context is shape-specific (nodeId, edgeId, or composite). The\n// policy-violations.ndjson writer skips on duplicate ids.\n\nexport interface EvaluationContext {\n // Wall-clock provider. Tests pin this; production uses Date.now.\n now: () => number\n}\n\ninterface RuleEvaluatorArgs<T extends PolicyRule = PolicyRule> {\n graph: NeatGraph\n policy: Policy\n rule: T\n ctx: EvaluationContext\n}\n\ntype RuleEvaluator<T extends PolicyRule = PolicyRule> = (\n args: RuleEvaluatorArgs<T>,\n) => PolicyViolation[]\n\n// Severity-driven default action per ADR-044.\nconst DEFAULT_ACTION_BY_SEVERITY: Record<PolicySeverity, PolicyAction> = {\n info: 'log',\n warning: 'alert',\n error: 'alert',\n critical: 'block',\n}\n\nexport function resolveOnViolation(policy: Policy): PolicyAction {\n return policy.onViolation ?? DEFAULT_ACTION_BY_SEVERITY[policy.severity]\n}\n\nfunction makeViolation(\n policy: Policy,\n rule: PolicyRule,\n contextSuffix: string,\n message: string,\n subject: PolicyViolation['subject'],\n ctx: EvaluationContext,\n): PolicyViolation {\n return {\n id: `${policy.id}:${contextSuffix}`,\n policyId: policy.id,\n policyName: policy.name,\n severity: policy.severity,\n onViolation: resolveOnViolation(policy),\n ruleType: rule.type,\n subject,\n message,\n observedAt: new Date(ctx.now()).toISOString(),\n }\n}\n\n// ──────────────────────────────────────────────────────────────────────────\n// Per-rule-type evaluators\n// ──────────────────────────────────────────────────────────────────────────\n\nconst evaluateStructural: RuleEvaluator<Extract<PolicyRule, { type: 'structural' }>> = ({\n graph,\n policy,\n rule,\n ctx,\n}) => {\n const violations: PolicyViolation[] = []\n graph.forEachNode((id, attrs) => {\n const a = attrs as GraphNode\n if (a.type !== rule.fromNodeType) return\n let satisfied = false\n for (const edgeId of graph.outboundEdges(id)) {\n const e = graph.getEdgeAttributes(edgeId) as GraphEdge\n if (e.type !== rule.edgeType) continue\n if (e.provenance === Provenance.FRONTIER) continue\n const target = graph.getNodeAttributes(e.target) as GraphNode\n if (target.type === rule.toNodeType) {\n satisfied = true\n break\n }\n }\n if (!satisfied) {\n violations.push(\n makeViolation(\n policy,\n rule,\n id,\n `${rule.fromNodeType} ${id} has no ${rule.edgeType} edge to a ${rule.toNodeType}`,\n { nodeId: id },\n ctx,\n ),\n )\n }\n })\n return violations\n}\n\nconst evaluateOwnership: RuleEvaluator<Extract<PolicyRule, { type: 'ownership' }>> = ({\n graph,\n policy,\n rule,\n ctx,\n}) => {\n const violations: PolicyViolation[] = []\n graph.forEachNode((id, attrs) => {\n const a = attrs as GraphNode & Record<string, unknown>\n if (a.type !== rule.nodeType) return\n const value = a[rule.field]\n if (typeof value !== 'string' || value.length === 0) {\n violations.push(\n makeViolation(\n policy,\n rule,\n id,\n `${rule.nodeType} ${id} is missing required field \"${rule.field}\"`,\n { nodeId: id },\n ctx,\n ),\n )\n }\n })\n return violations\n}\n\nconst evaluateProvenance: RuleEvaluator<Extract<PolicyRule, { type: 'provenance' }>> = ({\n graph,\n policy,\n rule,\n ctx,\n}) => {\n const required = Array.isArray(rule.required) ? new Set(rule.required) : new Set([rule.required])\n const violations: PolicyViolation[] = []\n graph.forEachEdge((edgeId, attrs) => {\n const e = attrs as GraphEdge\n if (e.type !== rule.edgeType) return\n if (rule.targetNodeId && e.target !== rule.targetNodeId) return\n if (!required.has(e.provenance)) {\n const requiredList = [...required].join(' | ')\n violations.push(\n makeViolation(\n policy,\n rule,\n edgeId,\n `${rule.edgeType} edge ${edgeId} has provenance ${e.provenance}; required ${requiredList}`,\n { edgeId },\n ctx,\n ),\n )\n }\n })\n return violations\n}\n\nconst evaluateBlastRadius: RuleEvaluator<Extract<PolicyRule, { type: 'blast-radius' }>> = ({\n graph,\n policy,\n rule,\n ctx,\n}) => {\n const violations: PolicyViolation[] = []\n const depth = rule.depth\n graph.forEachNode((id, attrs) => {\n const a = attrs as GraphNode\n if (a.type !== rule.nodeType) return\n const result = depth !== undefined ? getBlastRadius(graph, id, depth) : getBlastRadius(graph, id)\n if (result.totalAffected > rule.maxAffected) {\n violations.push(\n makeViolation(\n policy,\n rule,\n id,\n `${rule.nodeType} ${id} has blast radius ${result.totalAffected} > ${rule.maxAffected}`,\n { nodeId: id, path: [id] },\n ctx,\n ),\n )\n }\n })\n return violations\n}\n\nconst evaluateCompatibility: RuleEvaluator<Extract<PolicyRule, { type: 'compatibility' }>> = ({\n graph,\n policy,\n rule,\n ctx,\n}) => {\n const violations: PolicyViolation[] = []\n // Iterate every ServiceNode and re-run the compat shapes the static\n // extractor runs at extract time. Catches OBSERVED-vs-EXTRACTED divergence:\n // a service whose dep manifest changed since the last extract gets re-flagged\n // here on every evaluation cycle.\n const wantsKind = (kind: NonNullable<typeof rule.kind>): boolean =>\n rule.kind === undefined || rule.kind === kind\n\n graph.forEachNode((svcId, attrs) => {\n const a = attrs as GraphNode\n if (a.type !== NodeType.ServiceNode) return\n const svc = a as ServiceNode\n const deps = svc.dependencies ?? {}\n\n if (wantsKind('driver-engine')) {\n // Walk every CONNECTS_TO edge from this service to a DatabaseNode,\n // then run the driver-engine compat for each (driver, declared, engine,\n // engineVersion) tuple.\n for (const edgeId of graph.outboundEdges(svcId)) {\n const e = graph.getEdgeAttributes(edgeId) as GraphEdge\n if (e.type !== EdgeType.CONNECTS_TO) continue\n if (e.provenance === Provenance.FRONTIER) continue\n const dbAttrs = graph.getNodeAttributes(e.target) as GraphNode\n if (dbAttrs.type !== NodeType.DatabaseNode) continue\n const db = dbAttrs as { engine: string; engineVersion: string }\n for (const pair of compatPairs()) {\n if (pair.engine !== db.engine) continue\n const declared = deps[pair.driver]\n if (!declared) continue\n const result = checkCompatibility(pair.driver, declared, db.engine, db.engineVersion)\n if (!result.compatible && result.reason) {\n violations.push(\n makeViolation(\n policy,\n rule,\n `${svcId}:driver-engine:${pair.driver}@${declared}:${db.engine}@${db.engineVersion}`,\n result.reason,\n { nodeId: svcId, edgeId },\n ctx,\n ),\n )\n }\n }\n }\n }\n\n if (wantsKind('node-engine')) {\n const serviceNodeRange = svc.nodeEngine\n for (const constraint of nodeEngineConstraints()) {\n const declared = deps[constraint.package]\n if (!declared) continue\n const result = checkNodeEngineConstraint(constraint, declared, serviceNodeRange)\n if (!result.compatible && result.reason) {\n violations.push(\n makeViolation(\n policy,\n rule,\n `${svcId}:node-engine:${constraint.package}@${declared}`,\n result.reason,\n { nodeId: svcId },\n ctx,\n ),\n )\n }\n }\n }\n\n if (wantsKind('package-conflict')) {\n for (const conflict of packageConflicts()) {\n const declared = deps[conflict.package]\n if (!declared) continue\n const requiredDeclared = deps[conflict.requires.name]\n const result = checkPackageConflict(conflict, declared, requiredDeclared)\n if (!result.compatible && result.reason) {\n violations.push(\n makeViolation(\n policy,\n rule,\n `${svcId}:package-conflict:${conflict.package}@${declared}`,\n result.reason,\n { nodeId: svcId },\n ctx,\n ),\n )\n }\n }\n }\n\n if (wantsKind('deprecated-api')) {\n for (const dep of deprecatedApis()) {\n const declared = deps[dep.package]\n if (!declared) continue\n const result = checkDeprecatedApi(dep, declared)\n if (!result.compatible && result.reason) {\n violations.push(\n makeViolation(\n policy,\n rule,\n `${svcId}:deprecated-api:${dep.package}@${declared}`,\n result.reason,\n { nodeId: svcId },\n ctx,\n ),\n )\n }\n }\n }\n })\n\n return violations\n}\n\nconst policyEvaluators: { [K in PolicyRule['type']]: RuleEvaluator<Extract<PolicyRule, { type: K }>> } = {\n structural: evaluateStructural,\n ownership: evaluateOwnership,\n provenance: evaluateProvenance,\n 'blast-radius': evaluateBlastRadius,\n compatibility: evaluateCompatibility,\n}\n\n// ──────────────────────────────────────────────────────────────────────────\n// Public entry point\n// ──────────────────────────────────────────────────────────────────────────\n\n// Block-action gating for FrontierNode promotion (ADR-044 §block, MVP scope).\n// Runs the policy evaluator and returns the subset of block-action violations\n// that mention the candidate FrontierNode. Callers (ingest.ts\n// promoteFrontierNodes) check `allowed` before rewiring; when false, the\n// promotion is skipped and the violations surface through the standard\n// policy-violations.ndjson channel.\n//\n// Block scope is tightly bounded per the contract: FrontierNode promotion\n// only. Other gating points (deploy, codemod, OTel auto-create) need their\n// own ADRs before this function expands.\nexport function canPromoteFrontier(\n graph: NeatGraph,\n frontierId: string,\n policies: Policy[],\n ctx: EvaluationContext,\n): { allowed: boolean; violations: PolicyViolation[] } {\n if (policies.length === 0) return { allowed: true, violations: [] }\n const all = evaluateAllPolicies(graph, policies, ctx)\n const blocking = all.filter((v) => {\n if (v.onViolation !== 'block') return false\n return (\n v.subject.nodeId === frontierId ||\n v.subject.path?.includes(frontierId) === true\n )\n })\n return { allowed: blocking.length === 0, violations: blocking }\n}\n\nexport function evaluateAllPolicies(\n graph: NeatGraph,\n policies: Policy[],\n ctx: EvaluationContext,\n): PolicyViolation[] {\n const out: PolicyViolation[] = []\n for (const policy of policies) {\n const evaluator = policyEvaluators[policy.rule.type] as RuleEvaluator\n const violations = evaluator({ graph, policy, rule: policy.rule, ctx })\n for (const v of violations) out.push(v)\n }\n return out\n}\n\n// ──────────────────────────────────────────────────────────────────────────\n// Loader\n// ──────────────────────────────────────────────────────────────────────────\n\n// Reads <projectRoot>/policy.json. Returns [] when the file doesn't exist —\n// a project without policies is a perfectly fine state. Failures to parse\n// throw with the Zod error so the daemon surfaces malformed files loudly\n// instead of silently dropping rules.\nexport async function loadPolicyFile(policyPath: string): Promise<Policy[]> {\n let raw: string\n try {\n raw = await fs.readFile(policyPath, 'utf8')\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return []\n throw err\n }\n const json = JSON.parse(raw) as unknown\n const file: PolicyFile = PolicyFileSchema.parse(json)\n return file.policies\n}\n\n// ──────────────────────────────────────────────────────────────────────────\n// Append-only ndjson writer with id-based dedup\n// ──────────────────────────────────────────────────────────────────────────\n\n// Keeps an in-memory Set of seen violation ids so re-evaluation cycles don't\n// produce duplicate ndjson lines. The set hydrates from disk on first append\n// — startups that load an existing log don't lose dedup state.\nexport class PolicyViolationsLog {\n private readonly path: string\n private seen: Set<string> | null = null\n\n constructor(logPath: string) {\n this.path = logPath\n }\n\n async append(v: PolicyViolation): Promise<boolean> {\n if (!this.seen) await this.hydrate()\n if (this.seen!.has(v.id)) return false\n this.seen!.add(v.id)\n await fs.mkdir(path.dirname(this.path), { recursive: true })\n await fs.appendFile(this.path, JSON.stringify(v) + '\\n', 'utf8')\n return true\n }\n\n async readAll(): Promise<PolicyViolation[]> {\n try {\n const raw = await fs.readFile(this.path, 'utf8')\n return raw\n .split('\\n')\n .filter(Boolean)\n .map((line) => JSON.parse(line) as PolicyViolation)\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return []\n throw err\n }\n }\n\n private async hydrate(): Promise<void> {\n this.seen = new Set()\n const existing = await this.readAll()\n for (const v of existing) this.seen.add(v.id)\n }\n}\n","import { promises as fs } from 'node:fs'\nimport os from 'node:os'\nimport path from 'node:path'\nimport semver from 'semver'\nimport compatData from '../compat.json' with { type: 'json' }\n\nexport interface CompatibilityResult {\n compatible: boolean\n reason?: string\n minDriverVersion?: string\n}\n\nexport interface CompatPair {\n kind?: 'driver-engine'\n driver: string\n engine: string\n minDriverVersion: string\n // The driver constraint only kicks in once the engine is at this major or higher.\n // Older engines (e.g. PostgreSQL 13) accept the older driver fine.\n minEngineVersion?: string\n reason: string\n}\n\nexport interface NodeEngineConstraint {\n kind?: 'node-engine'\n package: string\n packageMinVersion?: string\n minNodeVersion: string\n reason: string\n}\n\nexport interface PackageConflict {\n kind?: 'package-conflict'\n package: string\n packageMinVersion?: string\n requires: { name: string; minVersion: string }\n reason: string\n}\n\nexport interface DeprecatedApi {\n kind?: 'deprecated-api'\n package: string\n packageMaxVersion?: string\n reason: string\n}\n\nexport interface CompatMatrix {\n pairs: CompatPair[]\n nodeEngineConstraints?: NodeEngineConstraint[]\n packageConflicts?: PackageConflict[]\n deprecatedApis?: DeprecatedApi[]\n}\n\nconst bundledMatrix = compatData as CompatMatrix\nlet mergedMatrix: CompatMatrix | null = null\nlet remoteLoadAttempted = false\n\nconst REMOTE_CACHE_DIR = path.join(os.homedir(), '.neat')\nconst REMOTE_CACHE_PATH = path.join(REMOTE_CACHE_DIR, 'compat-cache.json')\nconst REMOTE_TTL_MS = 24 * 60 * 60 * 1000\n\ninterface RemoteCacheFile {\n fetchedAt: string\n url: string\n matrix: CompatMatrix\n}\n\n// Engines like Postgres/MySQL only carry a major in the version field, so semver\n// won't always parse them cleanly. Compare as integers when both sides look like\n// majors; otherwise fall back to semver.coerce.\nfunction engineMeetsThreshold(engineVersion: string, threshold: string): boolean {\n const e = parseInt(engineVersion, 10)\n const t = parseInt(threshold, 10)\n if (Number.isFinite(e) && Number.isFinite(t)) return e >= t\n\n const ec = semver.coerce(engineVersion)\n const tc = semver.coerce(threshold)\n if (ec && tc) return semver.gte(ec, tc)\n\n return false\n}\n\nexport function checkCompatibility(\n driver: string,\n driverVersion: string,\n engine: string,\n engineVersion: string,\n): CompatibilityResult {\n const matrix = currentMatrix()\n const pair = matrix.pairs.find((p) => p.driver === driver && p.engine === engine)\n if (!pair) return { compatible: true }\n\n if (pair.minEngineVersion && !engineMeetsThreshold(engineVersion, pair.minEngineVersion)) {\n return { compatible: true }\n }\n\n const driverCoerced = semver.coerce(driverVersion)\n if (!driverCoerced) return { compatible: true }\n\n if (semver.lt(driverCoerced, pair.minDriverVersion)) {\n return {\n compatible: false,\n reason: pair.reason,\n minDriverVersion: pair.minDriverVersion,\n }\n }\n\n return { compatible: true }\n}\n\nexport interface NodeEngineCheck {\n compatible: boolean\n reason?: string\n requiredNodeVersion?: string\n}\n\n// True when `serviceNodeRange` (a service's `engines.node`) is guaranteed to\n// admit `requiredNodeVersion`. We use a permissive semver compare via `coerce`\n// — exact ranges like \">=20\" parse fine, exotic ones like \"^20 || ^22\" pass as\n// long as semver can resolve them. If the range can't be parsed at all, we\n// don't claim a conflict — under-flag rather than over-flag.\nfunction rangeAdmitsVersion(serviceNodeRange: string, requiredNodeVersion: string): boolean {\n try {\n const required = semver.coerce(requiredNodeVersion)\n if (!required) return true\n // Is every version that satisfies the service's range >= required? If yes,\n // the service guarantees the requirement; if not, there's at least one\n // admissible Node version that won't satisfy the dep — that's the\n // conflict.\n return semver.subset(serviceNodeRange, `>=${required.version}`, {\n includePrerelease: false,\n })\n } catch {\n return true\n }\n}\n\nexport function checkNodeEngineConstraint(\n constraint: NodeEngineConstraint,\n declaredPackageVersion: string | undefined,\n serviceNodeRange: string | undefined,\n): NodeEngineCheck {\n if (constraint.packageMinVersion && declaredPackageVersion) {\n const v = semver.coerce(declaredPackageVersion)\n if (v && semver.lt(v, constraint.packageMinVersion)) {\n return { compatible: true }\n }\n }\n if (!serviceNodeRange) {\n return { compatible: true }\n }\n if (rangeAdmitsVersion(serviceNodeRange, constraint.minNodeVersion)) {\n return { compatible: true }\n }\n return {\n compatible: false,\n reason: constraint.reason,\n requiredNodeVersion: constraint.minNodeVersion,\n }\n}\n\nexport interface PackageConflictCheck {\n compatible: boolean\n reason?: string\n requires?: { name: string; minVersion: string }\n foundVersion?: string\n}\n\nexport function checkPackageConflict(\n conflict: PackageConflict,\n declaredPackageVersion: string | undefined,\n declaredRequiredVersion: string | undefined,\n): PackageConflictCheck {\n if (!declaredPackageVersion) return { compatible: true }\n if (conflict.packageMinVersion) {\n const v = semver.coerce(declaredPackageVersion)\n if (v && semver.lt(v, conflict.packageMinVersion)) {\n return { compatible: true }\n }\n }\n if (!declaredRequiredVersion) {\n return {\n compatible: false,\n reason: conflict.reason,\n requires: conflict.requires,\n }\n }\n const requiredCoerced = semver.coerce(declaredRequiredVersion)\n if (!requiredCoerced) return { compatible: true }\n if (semver.lt(requiredCoerced, conflict.requires.minVersion)) {\n return {\n compatible: false,\n reason: conflict.reason,\n requires: conflict.requires,\n foundVersion: declaredRequiredVersion,\n }\n }\n return { compatible: true }\n}\n\nexport function checkDeprecatedApi(\n rule: DeprecatedApi,\n declaredVersion: string | undefined,\n): { compatible: boolean; reason?: string } {\n if (declaredVersion === undefined) return { compatible: true }\n if (rule.packageMaxVersion) {\n const v = semver.coerce(declaredVersion)\n const max = semver.coerce(rule.packageMaxVersion)\n if (v && max && semver.gt(v, max)) return { compatible: true }\n }\n return { compatible: false, reason: rule.reason }\n}\n\nfunction currentMatrix(): CompatMatrix {\n return mergedMatrix ?? bundledMatrix\n}\n\nfunction mergeMatrices(a: CompatMatrix, b: CompatMatrix): CompatMatrix {\n return {\n pairs: [...a.pairs, ...(b.pairs ?? [])],\n nodeEngineConstraints: [\n ...(a.nodeEngineConstraints ?? []),\n ...(b.nodeEngineConstraints ?? []),\n ],\n packageConflicts: [...(a.packageConflicts ?? []), ...(b.packageConflicts ?? [])],\n deprecatedApis: [...(a.deprecatedApis ?? []), ...(b.deprecatedApis ?? [])],\n }\n}\n\nasync function readRemoteCache(url: string): Promise<CompatMatrix | null> {\n try {\n const raw = await fs.readFile(REMOTE_CACHE_PATH, 'utf8')\n const parsed = JSON.parse(raw) as RemoteCacheFile\n if (parsed.url !== url) return null\n const age = Date.now() - new Date(parsed.fetchedAt).getTime()\n if (age > REMOTE_TTL_MS) return null\n return parsed.matrix\n } catch {\n return null\n }\n}\n\nasync function writeRemoteCache(url: string, matrix: CompatMatrix): Promise<void> {\n const file: RemoteCacheFile = {\n fetchedAt: new Date().toISOString(),\n url,\n matrix,\n }\n try {\n await fs.mkdir(REMOTE_CACHE_DIR, { recursive: true })\n await fs.writeFile(REMOTE_CACHE_PATH, JSON.stringify(file), 'utf8')\n } catch (err) {\n console.warn(`[neat] failed to cache compat matrix: ${(err as Error).message}`)\n }\n}\n\n// Loads the bundled matrix and, if `NEAT_COMPAT_URL` is set, merges in a\n// remote extension. Falls back to a fresh fetch when the on-disk cache is\n// stale (24h TTL) or missing. Returns the merged matrix; subsequent calls are\n// memoised.\n//\n// Async because the fetch happens lazily on first use. Extract phase 2 awaits\n// this before iterating pairs; everything else goes through the sync\n// `currentMatrix()` view, which is fine because by the time CLI / traversal\n// runs, extraction has already loaded.\nexport async function ensureCompatLoaded(): Promise<CompatMatrix> {\n if (mergedMatrix) return mergedMatrix\n if (remoteLoadAttempted) {\n mergedMatrix = bundledMatrix\n return mergedMatrix\n }\n remoteLoadAttempted = true\n\n const url = process.env.NEAT_COMPAT_URL\n if (!url) {\n mergedMatrix = bundledMatrix\n return mergedMatrix\n }\n\n const cached = await readRemoteCache(url)\n if (cached) {\n mergedMatrix = mergeMatrices(bundledMatrix, cached)\n return mergedMatrix\n }\n\n try {\n const res = await fetch(url)\n if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)\n const remote = (await res.json()) as CompatMatrix\n await writeRemoteCache(url, remote)\n mergedMatrix = mergeMatrices(bundledMatrix, remote)\n return mergedMatrix\n } catch (err) {\n console.warn(\n `[neat] NEAT_COMPAT_URL fetch failed (${(err as Error).message}); using bundled matrix only`,\n )\n mergedMatrix = bundledMatrix\n return mergedMatrix\n }\n}\n\n// Reset the merged-matrix memo. Intended for tests so each test starts with a\n// freshly loaded matrix.\nexport function resetCompatMatrix(): void {\n mergedMatrix = null\n remoteLoadAttempted = false\n}\n\nexport function compatPairs(): readonly CompatPair[] {\n return currentMatrix().pairs\n}\n\nexport function nodeEngineConstraints(): readonly NodeEngineConstraint[] {\n return currentMatrix().nodeEngineConstraints ?? []\n}\n\nexport function packageConflicts(): readonly PackageConflict[] {\n return currentMatrix().packageConflicts ?? []\n}\n\nexport function deprecatedApis(): readonly DeprecatedApi[] {\n return currentMatrix().deprecatedApis ?? []\n}\n","{\n \"pairs\": [\n {\n \"kind\": \"driver-engine\",\n \"driver\": \"pg\",\n \"engine\": \"postgresql\",\n \"minDriverVersion\": \"8.0.0\",\n \"minEngineVersion\": \"14\",\n \"reason\": \"PostgreSQL 14+ requires scram-sha-256 auth by default; pg < 8.0.0 only speaks md5.\"\n },\n {\n \"kind\": \"driver-engine\",\n \"driver\": \"mysql2\",\n \"engine\": \"mysql\",\n \"minDriverVersion\": \"3.0.0\",\n \"minEngineVersion\": \"8\",\n \"reason\": \"MySQL 8 defaults to caching_sha2_password; mysql2 < 3.0.0 doesn't negotiate it.\"\n },\n {\n \"kind\": \"driver-engine\",\n \"driver\": \"mongoose\",\n \"engine\": \"mongodb\",\n \"minDriverVersion\": \"7.0.0\",\n \"minEngineVersion\": \"7\",\n \"reason\": \"MongoDB 7 drops legacy wire-protocol opcodes that mongoose < 7.0.0 still emits.\"\n },\n {\n \"kind\": \"driver-engine\",\n \"driver\": \"psycopg2\",\n \"engine\": \"postgresql\",\n \"minDriverVersion\": \"2.9.0\",\n \"minEngineVersion\": \"14\",\n \"reason\": \"PostgreSQL 14+ requires scram-sha-256 auth by default; psycopg2 < 2.9.0 only speaks md5.\"\n },\n {\n \"kind\": \"driver-engine\",\n \"driver\": \"pymongo\",\n \"engine\": \"mongodb\",\n \"minDriverVersion\": \"4.0.0\",\n \"minEngineVersion\": \"7\",\n \"reason\": \"MongoDB 7 drops legacy wire-protocol opcodes that pymongo < 4.0.0 still emits.\"\n },\n {\n \"kind\": \"driver-engine\",\n \"driver\": \"mysql-connector-python\",\n \"engine\": \"mysql\",\n \"minDriverVersion\": \"8.0.0\",\n \"minEngineVersion\": \"8\",\n \"reason\": \"MySQL 8 defaults to caching_sha2_password; mysql-connector-python < 8.0.0 doesn't negotiate it.\"\n }\n ],\n \"nodeEngineConstraints\": [\n {\n \"kind\": \"node-engine\",\n \"package\": \"vitest\",\n \"packageMinVersion\": \"2.0.0\",\n \"minNodeVersion\": \"18.0.0\",\n \"reason\": \"vitest >= 2.0 drops Node 16 support; requires Node 18+.\"\n },\n {\n \"kind\": \"node-engine\",\n \"package\": \"next\",\n \"packageMinVersion\": \"14.0.0\",\n \"minNodeVersion\": \"18.17.0\",\n \"reason\": \"Next 14+ requires Node 18.17+ (uses APIs introduced in that minor).\"\n },\n {\n \"kind\": \"node-engine\",\n \"package\": \"@modelcontextprotocol/sdk\",\n \"packageMinVersion\": \"1.0.0\",\n \"minNodeVersion\": \"18.0.0\",\n \"reason\": \"@modelcontextprotocol/sdk >= 1 requires Node 18+ (web-streams polyfill removed).\"\n }\n ],\n \"packageConflicts\": [\n {\n \"kind\": \"package-conflict\",\n \"package\": \"@tanstack/react-query\",\n \"packageMinVersion\": \"5.0.0\",\n \"requires\": {\n \"name\": \"react\",\n \"minVersion\": \"18.0.0\"\n },\n \"reason\": \"@tanstack/react-query 5+ uses useSyncExternalStore — only available in React 18+.\"\n },\n {\n \"kind\": \"package-conflict\",\n \"package\": \"react-router-dom\",\n \"packageMinVersion\": \"7.0.0\",\n \"requires\": {\n \"name\": \"react\",\n \"minVersion\": \"18.0.0\"\n },\n \"reason\": \"react-router-dom 7+ requires React 18+.\"\n },\n {\n \"kind\": \"package-conflict\",\n \"package\": \"next\",\n \"packageMinVersion\": \"14.0.0\",\n \"requires\": {\n \"name\": \"react\",\n \"minVersion\": \"18.2.0\"\n },\n \"reason\": \"Next.js 14+ requires React 18.2+.\"\n }\n ],\n \"deprecatedApis\": [\n {\n \"kind\": \"deprecated-api\",\n \"package\": \"request\",\n \"packageMaxVersion\": \"2.88.2\",\n \"reason\": \"request is deprecated; use undici, node-fetch, or axios instead.\"\n },\n {\n \"kind\": \"deprecated-api\",\n \"package\": \"node-uuid\",\n \"reason\": \"node-uuid is deprecated; use the `uuid` package.\"\n }\n ]\n}\n","import type {\n BlastRadiusAffectedNode,\n BlastRadiusResult,\n DatabaseNode,\n ErrorEvent,\n GraphEdge,\n GraphNode,\n RootCauseResult,\n ServiceNode,\n TransitiveDependenciesResult,\n TransitiveDependency,\n} from '@neat.is/types'\nimport {\n BlastRadiusResultSchema,\n NodeType,\n PROV_RANK,\n Provenance,\n RootCauseResultSchema,\n TransitiveDependenciesResultSchema,\n} from '@neat.is/types'\nimport type { NeatGraph } from './graph.js'\nimport {\n checkCompatibility,\n checkNodeEngineConstraint,\n checkPackageConflict,\n compatPairs,\n nodeEngineConstraints,\n packageConflicts,\n} from './compat.js'\n\n// Contract anchors (see /docs/contracts.md + docs/contracts/provenance.md):\n// * Rule 2 — Coexistence: walk by provenance priority, never collapse edges.\n// * Rule 3 — FRONTIER edges must be skipped, not merely deprioritized.\n// If a node's only edges are FRONTIER, traversal stops there.\n// * Rule 5 — Validate results against RootCauseResultSchema /\n// BlastRadiusResultSchema before returning.\n// * Rule 8 — No demo-name hardcoding: driver/engine identifiers come from\n// node properties + compatPairs(), never literals.\n// * ADR-029 — PROV_RANK is the canonical provenance ranking, imported\n// from @neat.is/types so consumers (traversal, MCP, policies) all agree.\n\nconst ROOT_CAUSE_MAX_DEPTH = 5\nconst BLAST_RADIUS_DEFAULT_DEPTH = 10\n\n// Multiple edges between the same pair coexist by provenance (EXTRACTED next to\n// OBSERVED next to INFERRED). Traversal walks the system as the graph \"sees it\n// best\", so for any neighbour pair we pick the highest-provenance edge.\n// FRONTIER means unknown territory — ADR-036 / Rule 3 require these edges to\n// be skipped, not merely deprioritized. Filtering happens here so the rest of\n// traversal can stay generic.\nfunction bestEdgeBySource(graph: NeatGraph, edgeIds: string[]): Map<string, GraphEdge> {\n const best = new Map<string, GraphEdge>()\n for (const id of edgeIds) {\n const e = graph.getEdgeAttributes(id) as GraphEdge\n if (e.provenance === Provenance.FRONTIER) continue\n const cur = best.get(e.source)\n if (!cur || PROV_RANK[e.provenance] > PROV_RANK[cur.provenance]) {\n best.set(e.source, e)\n }\n }\n return best\n}\n\nfunction bestEdgeByTarget(graph: NeatGraph, edgeIds: string[]): Map<string, GraphEdge> {\n const best = new Map<string, GraphEdge>()\n for (const id of edgeIds) {\n const e = graph.getEdgeAttributes(id) as GraphEdge\n if (e.provenance === Provenance.FRONTIER) continue\n const cur = best.get(e.target)\n if (!cur || PROV_RANK[e.provenance] > PROV_RANK[cur.provenance]) {\n best.set(e.target, e)\n }\n }\n return best\n}\n\n// Per-edge confidence is provenance × volume × recency × cleanliness.\n// * provenance gives a ceiling: OBSERVED 1.0, INFERRED 0.7, EXTRACTED 0.5,\n// STALE/FRONTIER 0.3.\n// * volume: log-scaled span count, saturating quickly so 1 span ≈ 0.55 and\n// ~1k spans ≈ 1.0.\n// * recency: 1.0 within an hour; decays toward 0.5 by 24h, toward 0.3 past.\n// * cleanliness: error rate above ~10% pulls the score down — a flapping\n// edge with thousands of spans shouldn't outrank a clean low-traffic one.\n// Bounded to [0, 1]. Walks of multiple edges multiply per-edge confidences.\nconst PROVENANCE_CEILING: Record<string, number> = {\n OBSERVED: 1.0,\n INFERRED: 0.7,\n EXTRACTED: 0.5,\n STALE: 0.3,\n FRONTIER: 0.3,\n}\n\nfunction volumeWeight(spanCount: number | undefined): number {\n if (!spanCount || spanCount <= 0) return 0.5\n // log10 saturating around ~1000 spans → ~1.0.\n const w = 0.5 + Math.log10(spanCount + 1) / 3\n return Math.min(1, w)\n}\n\nfunction recencyWeight(ageMs: number | undefined): number {\n if (ageMs === undefined) return 0.8\n const hour = 60 * 60 * 1000\n if (ageMs <= hour) return 1.0\n if (ageMs <= 24 * hour) {\n const t = (ageMs - hour) / (23 * hour)\n return 1.0 - 0.5 * t\n }\n return 0.3\n}\n\nfunction cleanlinessWeight(spanCount: number | undefined, errorCount: number | undefined): number {\n if (!spanCount || spanCount <= 0) return 1\n const rate = (errorCount ?? 0) / spanCount\n if (rate <= 0.01) return 1\n if (rate >= 0.5) return 0.3\n return 1 - rate * 1.4\n}\n\nexport function confidenceForEdge(edge: GraphEdge, now = Date.now()): number {\n const ceiling = PROVENANCE_CEILING[edge.provenance] ?? 0.5\n\n // No runtime signal yet → the provenance ceiling is all we have. This keeps\n // EXTRACTED-only graphs returning the same coarse 0.3/0.5/0.7/1.0 ladder\n // they always have, while letting OBSERVED edges with real OTel data move\n // off the ceiling once ingest starts populating signal counters.\n const spanCount = edge.signal?.spanCount ?? edge.callCount\n const ageMs = edge.signal?.lastObservedAgeMs ?? lastObservedAge(edge, now)\n if (spanCount === undefined && ageMs === undefined && edge.signal === undefined) {\n return ceiling\n }\n\n const v = volumeWeight(spanCount)\n const r = recencyWeight(ageMs)\n const c = cleanlinessWeight(spanCount, edge.signal?.errorCount)\n return Math.max(0, Math.min(1, ceiling * v * r * c))\n}\n\nfunction lastObservedAge(edge: GraphEdge, now: number): number | undefined {\n if (!edge.lastObserved) return undefined\n const t = Date.parse(edge.lastObserved)\n if (!Number.isFinite(t)) return undefined\n return Math.max(0, now - t)\n}\n\n// Path-level confidence is the *product* of per-edge confidences (ADR-036).\n// Each hop is independent evidence and uncertainty compounds — a 3-hop path\n// of edges at confidence 0.8 each gives 0.512, not 0.8. Multiplying punishes\n// long walks accordingly, which is the contract's intent: traversal should\n// surface the cumulative trust the graph actually has, not the weakest link\n// alone.\nfunction confidenceFromMix(edges: GraphEdge[], now = Date.now()): number {\n if (edges.length === 0) return 1.0\n let product = 1\n for (const e of edges) {\n product *= confidenceForEdge(e, now)\n }\n return Math.max(0, Math.min(1, product))\n}\n\ninterface Walk {\n path: string[]\n edges: GraphEdge[]\n}\n\n// DFS along incoming edges from start, depth-bounded. Returns the longest path\n// reachable, picking best-provenance edges per neighbour pair so the walk\n// reflects the system as the graph knows it most reliably.\nfunction longestIncomingWalk(graph: NeatGraph, start: string, maxDepth: number): Walk {\n let best: Walk = { path: [start], edges: [] }\n const visited = new Set<string>([start])\n\n function step(node: string, path: string[], edges: GraphEdge[]): void {\n if (path.length > best.path.length) {\n best = { path: [...path], edges: [...edges] }\n }\n if (path.length - 1 >= maxDepth) return\n\n const incoming = bestEdgeBySource(graph, graph.inboundEdges(node))\n for (const [srcId, edge] of incoming) {\n if (visited.has(srcId)) continue\n visited.add(srcId)\n path.push(srcId)\n edges.push(edge)\n step(srcId, path, edges)\n path.pop()\n edges.pop()\n visited.delete(srcId)\n }\n }\n\n step(start, [start], [])\n return best\n}\n\n// Per-shape match result. Each shape walks the same incoming `walk.path` but\n// looks for a different class of incompatibility. Adding a new shape (e.g. a\n// future ConfigNode \"missing required env var\" rule) is one entry in\n// `rootCauseShapes` plus its match function — no restructure to getRootCause.\ninterface RootCauseMatch {\n rootCauseNode: string\n rootCauseReason: string\n fixRecommendation?: string\n}\n\ntype RootCauseShape = (\n graph: NeatGraph,\n origin: GraphNode,\n walk: Walk,\n) => RootCauseMatch | null\n\n// DatabaseNode origin → driver/engine compat (the original v0.1.x behavior,\n// preserved verbatim). The walk ignores non-ServiceNodes; the first upstream\n// service whose declared driver fails compat against the origin DB's\n// (engine, engineVersion) wins.\nfunction databaseRootCauseShape(\n graph: NeatGraph,\n origin: GraphNode,\n walk: Walk,\n): RootCauseMatch | null {\n const targetDb = origin as DatabaseNode\n // Pairs that could possibly hit on this engine — narrowed once outside the\n // walk so we don't re-scan the matrix for every service we visit.\n const candidatePairs = compatPairs().filter((p) => p.engine === targetDb.engine)\n if (candidatePairs.length === 0) return null\n\n for (const id of walk.path) {\n const attrs = graph.getNodeAttributes(id) as GraphNode\n if (attrs.type !== NodeType.ServiceNode) continue\n const svc = attrs as ServiceNode\n const deps = svc.dependencies ?? {}\n for (const pair of candidatePairs) {\n const declared = deps[pair.driver]\n if (!declared) continue\n const result = checkCompatibility(\n pair.driver,\n declared,\n targetDb.engine,\n targetDb.engineVersion,\n )\n if (!result.compatible) {\n return {\n rootCauseNode: id,\n rootCauseReason: result.reason ?? 'incompatible driver',\n ...(result.minDriverVersion\n ? {\n fixRecommendation: `Upgrade ${svc.name} ${pair.driver} driver to >= ${result.minDriverVersion}`,\n }\n : {}),\n }\n }\n }\n }\n return null\n}\n\n// ServiceNode origin → node-engine + package-conflict shapes from compat.ts.\n// The check is over each ServiceNode along the incoming walk (the origin\n// itself + any upstream callers): a node-engine constraint failing against\n// the service's `engines.node`, or a package-conflict where a declared dep\n// requires a peer at a higher version than the service has.\nfunction serviceRootCauseShape(\n graph: NeatGraph,\n _origin: GraphNode,\n walk: Walk,\n): RootCauseMatch | null {\n for (const id of walk.path) {\n const attrs = graph.getNodeAttributes(id) as GraphNode\n if (attrs.type !== NodeType.ServiceNode) continue\n const svc = attrs as ServiceNode\n const deps = svc.dependencies ?? {}\n const serviceNodeEngine = svc.nodeEngine\n\n for (const constraint of nodeEngineConstraints()) {\n const declared = deps[constraint.package]\n if (!declared) continue\n const result = checkNodeEngineConstraint(constraint, declared, serviceNodeEngine)\n if (!result.compatible && result.reason) {\n return {\n rootCauseNode: id,\n rootCauseReason: result.reason,\n ...(result.requiredNodeVersion\n ? {\n fixRecommendation: `Bump ${svc.name}'s engines.node to >= ${result.requiredNodeVersion}`,\n }\n : {}),\n }\n }\n }\n\n for (const conflict of packageConflicts()) {\n const declared = deps[conflict.package]\n if (!declared) continue\n const requiredDeclared = deps[conflict.requires.name]\n const result = checkPackageConflict(conflict, declared, requiredDeclared)\n if (!result.compatible && result.reason) {\n return {\n rootCauseNode: id,\n rootCauseReason: result.reason,\n fixRecommendation: `Upgrade ${svc.name}'s ${conflict.requires.name} to >= ${conflict.requires.minVersion}`,\n }\n }\n }\n }\n return null\n}\n\n// Dispatch by origin node type per ADR-037. Origin types not present here\n// (InfraNode, ConfigNode, FrontierNode) cleanly return null — getRootCause\n// needs an explicit shape to know what an \"incompatibility\" looks like for\n// that origin, and those types don't have one yet.\nconst rootCauseShapes: Partial<Record<GraphNode['type'], RootCauseShape>> = {\n [NodeType.DatabaseNode]: databaseRootCauseShape,\n [NodeType.ServiceNode]: serviceRootCauseShape,\n}\n\nexport function getRootCause(\n graph: NeatGraph,\n errorNodeId: string,\n errorEvent?: ErrorEvent,\n): RootCauseResult | null {\n if (!graph.hasNode(errorNodeId)) return null\n const origin = graph.getNodeAttributes(errorNodeId) as GraphNode\n const shape = rootCauseShapes[origin.type]\n if (!shape) return null\n\n const walk = longestIncomingWalk(graph, errorNodeId, ROOT_CAUSE_MAX_DEPTH)\n const match = shape(graph, origin, walk)\n if (!match) return null\n\n const reason = errorEvent\n ? `${match.rootCauseReason} (observed error: ${errorEvent.errorMessage})`\n : match.rootCauseReason\n\n // Schema-validate before return (ADR-036, #139). A drift in the result\n // shape becomes a runtime throw at the call site rather than a silently\n // malformed payload reaching MCP / REST consumers.\n return RootCauseResultSchema.parse({\n rootCauseNode: match.rootCauseNode,\n rootCauseReason: reason,\n traversalPath: walk.path,\n edgeProvenances: walk.edges.map((e) => e.provenance),\n confidence: confidenceFromMix(walk.edges),\n fixRecommendation: match.fixRecommendation,\n })\n}\n\n// BFS along outgoing edges from origin. Records each reachable node with the\n// shortest distance back to origin and the provenance of the edge that brought\n// us to it. Best-provenance edge selection per pair mirrors getRootCause.\nexport function getBlastRadius(\n graph: NeatGraph,\n nodeId: string,\n maxDepth = BLAST_RADIUS_DEFAULT_DEPTH,\n): BlastRadiusResult {\n if (!graph.hasNode(nodeId)) {\n return BlastRadiusResultSchema.parse({ origin: nodeId, affectedNodes: [], totalAffected: 0 })\n }\n\n // Each frame carries its full predecessor chain so the affected-node payload\n // can surface `path` (origin → ... → nodeId) and `confidence` (cascaded over\n // every edge along that path). The BFS visits each reachable node once on\n // its shortest-distance path; later frames at greater distance are dropped.\n interface Frame {\n nodeId: string\n distance: number\n path: string[]\n pathEdges: GraphEdge[]\n }\n\n const seen = new Map<string, BlastRadiusAffectedNode>()\n const queue: Frame[] = [{ nodeId, distance: 0, path: [nodeId], pathEdges: [] }]\n const enqueued = new Set<string>([nodeId])\n\n while (queue.length > 0) {\n const frame = queue.shift()!\n if (frame.distance > 0 && frame.pathEdges.length > 0) {\n const lastEdge = frame.pathEdges[frame.pathEdges.length - 1]!\n seen.set(frame.nodeId, {\n nodeId: frame.nodeId,\n distance: frame.distance,\n edgeProvenance: lastEdge.provenance,\n path: frame.path,\n confidence: confidenceFromMix(frame.pathEdges),\n })\n }\n if (frame.distance >= maxDepth) continue\n\n const outgoing = bestEdgeByTarget(graph, graph.outboundEdges(frame.nodeId))\n for (const [tgtId, edge] of outgoing) {\n if (enqueued.has(tgtId)) continue\n enqueued.add(tgtId)\n queue.push({\n nodeId: tgtId,\n distance: frame.distance + 1,\n path: [...frame.path, tgtId],\n pathEdges: [...frame.pathEdges, edge],\n })\n }\n }\n\n const affectedNodes = [...seen.values()].sort(\n (a, b) => a.distance - b.distance || a.nodeId.localeCompare(b.nodeId),\n )\n return BlastRadiusResultSchema.parse({\n origin: nodeId,\n affectedNodes,\n totalAffected: affectedNodes.length,\n })\n}\n\n// Default + max depth for transitive get_dependencies (issue #144). Default\n// 3 keeps the output legible at the agent layer; the contract caps the\n// caller-supplied value at 10 to prevent BFS blow-up on dense graphs.\nexport const TRANSITIVE_DEPENDENCIES_DEFAULT_DEPTH = 3\nexport const TRANSITIVE_DEPENDENCIES_MAX_DEPTH = 10\n\n// Transitive get_dependencies (ADR-039 / #144). BFS outbound from origin to\n// `depth` hops, returning a flat list with distance, edgeType, and provenance\n// per dependency. Origin is never in the list. Direct-only consumers pass\n// depth=1; the MCP get_dependencies tool defaults to 3.\n//\n// Reuses bestEdgeByTarget (FRONTIER filtered, PROV_RANK-best per pair) so\n// dedup behavior matches the rest of traversal. Result is schema-validated\n// before return per ADR-036 §Result schema validation.\nexport function getTransitiveDependencies(\n graph: NeatGraph,\n nodeId: string,\n depth: number = TRANSITIVE_DEPENDENCIES_DEFAULT_DEPTH,\n): TransitiveDependenciesResult {\n if (!graph.hasNode(nodeId)) {\n return TransitiveDependenciesResultSchema.parse({\n origin: nodeId,\n depth,\n dependencies: [],\n total: 0,\n })\n }\n\n interface Frame {\n nodeId: string\n distance: number\n edge: GraphEdge | null\n }\n\n const seen = new Map<string, TransitiveDependency>()\n const queue: Frame[] = [{ nodeId, distance: 0, edge: null }]\n const enqueued = new Set<string>([nodeId])\n\n while (queue.length > 0) {\n const frame = queue.shift()!\n if (frame.distance > 0 && frame.edge) {\n seen.set(frame.nodeId, {\n nodeId: frame.nodeId,\n distance: frame.distance,\n edgeType: frame.edge.type,\n provenance: frame.edge.provenance,\n })\n }\n if (frame.distance >= depth) continue\n\n const outgoing = bestEdgeByTarget(graph, graph.outboundEdges(frame.nodeId))\n for (const [tgtId, edge] of outgoing) {\n if (enqueued.has(tgtId)) continue\n enqueued.add(tgtId)\n queue.push({ nodeId: tgtId, distance: frame.distance + 1, edge })\n }\n }\n\n const dependencies = [...seen.values()].sort(\n (a, b) => a.distance - b.distance || a.nodeId.localeCompare(b.nodeId),\n )\n return TransitiveDependenciesResultSchema.parse({\n origin: nodeId,\n depth,\n dependencies,\n total: dependencies.length,\n })\n}\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport ignore, { type Ignore } from 'ignore'\nimport { minimatch } from 'minimatch'\nimport type { ServiceNode } from '@neat.is/types'\nimport { NodeType, serviceId } from '@neat.is/types'\nimport type { NeatGraph } from '../graph.js'\nimport {\n IGNORED_DIRS,\n exists,\n readJson,\n type DiscoveredService,\n type PackageJson,\n} from './shared.js'\nimport { discoverPythonService, pythonToPackage } from './python.js'\n\nconst DEFAULT_SCAN_DEPTH = 5\n\ninterface RootPackageJson extends PackageJson {\n workspaces?: string[] | { packages?: string[] }\n}\n\nfunction parseScanDepth(): number {\n const raw = process.env.NEAT_SCAN_DEPTH\n if (!raw) return DEFAULT_SCAN_DEPTH\n const n = Number.parseInt(raw, 10)\n return Number.isFinite(n) && n >= 0 ? n : DEFAULT_SCAN_DEPTH\n}\n\nfunction workspaceGlobs(pkg: RootPackageJson): string[] | null {\n const ws = pkg.workspaces\n if (!ws) return null\n if (Array.isArray(ws)) return ws.length > 0 ? ws : null\n if (Array.isArray(ws.packages)) return ws.packages.length > 0 ? ws.packages : null\n return null\n}\n\nasync function loadGitignore(scanPath: string): Promise<Ignore | null> {\n const gitignorePath = path.join(scanPath, '.gitignore')\n if (!(await exists(gitignorePath))) return null\n const raw = await fs.readFile(gitignorePath, 'utf8')\n return ignore().add(raw)\n}\n\ninterface WalkOptions {\n maxDepth: number\n ig: Ignore | null\n}\n\nasync function walkDirs(\n start: string,\n scanPath: string,\n options: WalkOptions,\n visit: (dir: string) => Promise<void> | void,\n): Promise<void> {\n async function recurse(current: string, depth: number): Promise<void> {\n if (depth > options.maxDepth) return\n const entries = await fs.readdir(current, { withFileTypes: true }).catch(() => [])\n for (const entry of entries) {\n if (!entry.isDirectory()) continue\n if (IGNORED_DIRS.has(entry.name)) continue\n const child = path.join(current, entry.name)\n if (options.ig) {\n const rel = path.relative(scanPath, child).split(path.sep).join('/')\n // Trailing slash so `ignore` evaluates the entry as a directory; without\n // it, gitignore patterns like `dist/` won't match because the lib\n // distinguishes file vs. directory tests.\n if (rel && options.ig.ignores(rel + '/')) continue\n }\n await visit(child)\n await recurse(child, depth + 1)\n }\n }\n await recurse(start, 0)\n}\n\nasync function expandWorkspaceGlobs(\n scanPath: string,\n globs: string[],\n): Promise<string[]> {\n const found = new Set<string>()\n const scanDepth = parseScanDepth()\n\n for (const raw of globs) {\n const pattern = raw.replace(/^\\.\\//, '')\n\n if (!pattern.includes('*')) {\n const candidate = path.join(scanPath, pattern)\n if (await exists(path.join(candidate, 'package.json'))) found.add(candidate)\n continue\n }\n\n const segments = pattern.split('/')\n const staticSegments: string[] = []\n for (const seg of segments) {\n if (seg.includes('*')) break\n staticSegments.push(seg)\n }\n const start = path.join(scanPath, ...staticSegments)\n if (!(await exists(start))) continue\n\n const hasDoubleStar = pattern.includes('**')\n const walkDepth = hasDoubleStar\n ? scanDepth\n : Math.max(0, segments.length - staticSegments.length - 1)\n\n await walkDirs(start, scanPath, { maxDepth: walkDepth, ig: null }, async (dir) => {\n const rel = path.relative(scanPath, dir).split(path.sep).join('/')\n if (minimatch(rel, pattern) && (await exists(path.join(dir, 'package.json')))) {\n found.add(dir)\n }\n })\n }\n\n return [...found]\n}\n\nasync function discoverNodeService(\n scanPath: string,\n dir: string,\n): Promise<DiscoveredService | null> {\n const pkgPath = path.join(dir, 'package.json')\n if (!(await exists(pkgPath))) return null\n const pkg = await readJson<PackageJson>(pkgPath)\n if (!pkg.name) return null\n const node: ServiceNode = {\n id: serviceId(pkg.name),\n type: NodeType.ServiceNode,\n name: pkg.name,\n language: 'javascript',\n version: pkg.version,\n dependencies: pkg.dependencies ?? {},\n repoPath: path.relative(scanPath, dir),\n ...(pkg.engines?.node ? { nodeEngine: pkg.engines.node } : {}),\n }\n return { pkg, dir, node }\n}\n\nasync function discoverPyService(\n scanPath: string,\n dir: string,\n): Promise<DiscoveredService | null> {\n const py = await discoverPythonService(dir)\n if (!py) return null\n const pkg = pythonToPackage(py)\n const node: ServiceNode = {\n id: serviceId(py.name),\n type: NodeType.ServiceNode,\n name: py.name,\n language: 'python',\n version: py.version,\n dependencies: py.dependencies,\n repoPath: path.relative(scanPath, dir),\n }\n return { pkg, dir, node }\n}\n\n// Phase 1 — discover service directories under scanPath. A service is any\n// directory containing a JS/TS manifest (`package.json`) or a Python manifest\n// (`pyproject.toml` / `requirements.txt` / `setup.py`). JS wins on tie.\n//\n// If the root `package.json` declares `workspaces`, those globs are\n// authoritative — we don't fall back to a free recursive walk. Otherwise we\n// walk recursively, depth-bounded by `NEAT_SCAN_DEPTH` (default 5), skipping\n// `IGNORED_DIRS` and anything matched by the root `.gitignore`.\n//\n// Two manifests sharing a `name` collapse to one node per ADR-010; the\n// duplicate logs a warning naming both paths.\nexport async function discoverServices(scanPath: string): Promise<DiscoveredService[]> {\n const rootPkgPath = path.join(scanPath, 'package.json')\n const rootPkg = (await exists(rootPkgPath))\n ? await readJson<RootPackageJson>(rootPkgPath)\n : null\n const wsGlobs = rootPkg ? workspaceGlobs(rootPkg) : null\n\n const candidateDirs: string[] = []\n if (wsGlobs) {\n candidateDirs.push(...(await expandWorkspaceGlobs(scanPath, wsGlobs)))\n } else {\n if (rootPkg && rootPkg.name) candidateDirs.push(scanPath)\n const ig = await loadGitignore(scanPath)\n await walkDirs(\n scanPath,\n scanPath,\n { maxDepth: parseScanDepth(), ig },\n async (dir) => {\n if (await exists(path.join(dir, 'package.json'))) {\n candidateDirs.push(dir)\n } else if (\n (await exists(path.join(dir, 'pyproject.toml'))) ||\n (await exists(path.join(dir, 'requirements.txt'))) ||\n (await exists(path.join(dir, 'setup.py')))\n ) {\n candidateDirs.push(dir)\n }\n },\n )\n }\n\n candidateDirs.sort()\n\n const seen = new Map<string, string>()\n const out: DiscoveredService[] = []\n for (const dir of candidateDirs) {\n const service =\n (await discoverNodeService(scanPath, dir)) ??\n (await discoverPyService(scanPath, dir))\n if (!service) continue\n\n const existingDir = seen.get(service.node.name)\n if (existingDir !== undefined) {\n const a = path.relative(scanPath, existingDir) || '.'\n const b = path.relative(scanPath, dir) || '.'\n console.warn(\n `[neat] duplicate package name \"${service.node.name}\" — keeping ${a}, ignoring ${b}`,\n )\n continue\n }\n seen.set(service.node.name, dir)\n out.push(service)\n }\n return out\n}\n\nexport function addServiceNodes(graph: NeatGraph, services: DiscoveredService[]): number {\n let nodesAdded = 0\n for (const service of services) {\n if (!graph.hasNode(service.node.id)) {\n graph.addNode(service.node.id, { ...service.node, discoveredVia: 'static' })\n nodesAdded++\n continue\n }\n // OTel ingest may have auto-created a minimal node at this id. Merge per\n // ADR-033 / identity contract: static fields override OTel-derived fields,\n // and discoveredVia flips to 'merged' when both layers contributed.\n const existing = graph.getNodeAttributes(service.node.id) as ServiceNode\n const mergedDiscoveredVia: 'static' | 'otel' | 'merged' =\n existing.discoveredVia === 'otel' ? 'merged' : 'static'\n graph.replaceNodeAttributes(service.node.id, {\n ...existing,\n ...service.node,\n discoveredVia: mergedDiscoveredVia,\n })\n }\n return nodesAdded\n}\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport { parse as parseYaml } from 'yaml'\nimport type { ServiceNode } from '@neat.is/types'\n\nexport interface PackageJson {\n name: string\n version?: string\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n engines?: { node?: string }\n}\n\nexport interface DiscoveredService {\n pkg: PackageJson\n dir: string\n node: ServiceNode\n}\n\nexport const SERVICE_FILE_EXTENSIONS = new Set(['.js', '.mjs', '.cjs', '.ts', '.tsx', '.py'])\nexport const CONFIG_FILE_EXTENSIONS = new Set(['.yaml', '.yml'])\nexport const IGNORED_DIRS = new Set([\n 'node_modules',\n '.git',\n '.turbo',\n 'dist',\n 'build',\n '.next',\n])\n\nexport function isConfigFile(name: string): { match: boolean; fileType: string } {\n const ext = path.extname(name)\n if (CONFIG_FILE_EXTENSIONS.has(ext)) return { match: true, fileType: ext.slice(1) }\n // .env, .env.local, .env.production. Bare filename or any dotted-suffix\n // variant; folder names get filtered upstream by walking files only.\n if (name === '.env' || name.startsWith('.env.')) return { match: true, fileType: 'env' }\n return { match: false, fileType: '' }\n}\n\n// Strip semver range prefixes (^, ~, >=, etc.) and bare \"v\" so the extracted\n// version is usable for compat checks. We don't try to resolve ranges to actual\n// installed versions — that's a published-lockfile concern, not extraction's job.\nexport function cleanVersion(raw: string | undefined): string | undefined {\n if (!raw) return undefined\n return raw.replace(/^[\\^~><=v\\s]+/, '').trim() || undefined\n}\n\nexport async function readJson<T>(filePath: string): Promise<T> {\n const raw = await fs.readFile(filePath, 'utf8')\n return JSON.parse(raw) as T\n}\n\nexport async function readYaml<T>(filePath: string): Promise<T> {\n const raw = await fs.readFile(filePath, 'utf8')\n return parseYaml(raw) as T\n}\n\nexport async function exists(p: string): Promise<boolean> {\n try {\n await fs.access(p)\n return true\n } catch {\n return false\n }\n}\n\n// Thin re-export so existing callers (calls/, configs.ts, databases/, infra/)\n// keep their import path. Wire format lives in @neat.is/types/identity.ts per\n// ADR-029.\nexport { extractedEdgeId as makeEdgeId } from '@neat.is/types'\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport { parse as parseToml } from 'smol-toml'\nimport { exists, type PackageJson } from './shared.js'\n\n// Lines like `psycopg2==2.7.0`, `psycopg2 == 2.7.0`, `psycopg2[extras]==2.7`,\n// or `psycopg2~=2.7,<3`. We capture the package name and the first version\n// that follows an `==` operator. Anything else (range, no pin, no version) is\n// recorded with an empty version — the compat matrix's semver coercer treats\n// those as \"can't reason\" and under-flags rather than over-flags.\nconst REQUIREMENT_LINE = /^\\s*([A-Za-z0-9_.-]+)(?:\\[[^\\]]*\\])?\\s*(?:(==)\\s*([A-Za-z0-9_.+-]+))?/\n\nfunction parseRequirementsTxt(content: string): Record<string, string> {\n const out: Record<string, string> = {}\n for (const rawLine of content.split('\\n')) {\n const line = rawLine.split('#')[0]?.trim()\n if (!line) continue\n if (line.startsWith('-')) continue // -r requirements-dev.txt etc.\n const match = REQUIREMENT_LINE.exec(line)\n if (!match) continue\n const name = match[1]!.toLowerCase()\n const version = match[3] ?? ''\n out[name] = version\n }\n return out\n}\n\ninterface PyProjectFile {\n project?: {\n name?: string\n version?: string\n dependencies?: string[]\n }\n tool?: {\n poetry?: {\n name?: string\n version?: string\n dependencies?: Record<string, string | { version?: string }>\n }\n }\n}\n\nfunction depsFromPyProject(pyproject: PyProjectFile): Record<string, string> {\n const out: Record<string, string> = {}\n\n // PEP 621 — [project] dependencies = [\"psycopg2==2.7.0\", \"requests\"]\n for (const entry of pyproject.project?.dependencies ?? []) {\n const match = REQUIREMENT_LINE.exec(entry)\n if (!match) continue\n out[match[1]!.toLowerCase()] = match[3] ?? ''\n }\n\n // Poetry — [tool.poetry.dependencies] psycopg2 = \"2.7.0\"\n const poetryDeps = pyproject.tool?.poetry?.dependencies ?? {}\n for (const [name, value] of Object.entries(poetryDeps)) {\n if (name.toLowerCase() === 'python') continue\n const raw = typeof value === 'string' ? value : (value?.version ?? '')\n out[name.toLowerCase()] = raw.replace(/^[\\^~><=v\\s]+/, '')\n }\n return out\n}\n\nexport interface PythonService {\n name: string\n version?: string\n dependencies: Record<string, string>\n}\n\n// Detect a Python service by the conventional manifest files. We try\n// pyproject.toml first because it can name the package; fallback to the\n// directory name when only requirements.txt or setup.py is present.\nexport async function discoverPythonService(serviceDir: string): Promise<PythonService | null> {\n const pyprojectPath = path.join(serviceDir, 'pyproject.toml')\n const requirementsPath = path.join(serviceDir, 'requirements.txt')\n const setupPath = path.join(serviceDir, 'setup.py')\n\n const hasPyproject = await exists(pyprojectPath)\n const hasRequirements = await exists(requirementsPath)\n const hasSetup = await exists(setupPath)\n if (!hasPyproject && !hasRequirements && !hasSetup) return null\n\n let name = path.basename(serviceDir)\n let version: string | undefined\n const dependencies: Record<string, string> = {}\n\n if (hasPyproject) {\n const raw = await fs.readFile(pyprojectPath, 'utf8')\n const pyproject = parseToml(raw) as PyProjectFile\n name = pyproject.project?.name ?? pyproject.tool?.poetry?.name ?? name\n version = pyproject.project?.version ?? pyproject.tool?.poetry?.version ?? undefined\n Object.assign(dependencies, depsFromPyProject(pyproject))\n }\n\n if (hasRequirements) {\n const raw = await fs.readFile(requirementsPath, 'utf8')\n Object.assign(dependencies, parseRequirementsTxt(raw))\n }\n\n return { name, version, dependencies }\n}\n\n// Build the same `pkg`-shaped shim the JS path uses so downstream phases\n// (databases, calls, etc.) can keep reading service.pkg.dependencies and\n// service.pkg.name without caring which language produced the service.\nexport function pythonToPackage(service: PythonService): PackageJson {\n return {\n name: service.name,\n version: service.version,\n dependencies: service.dependencies,\n }\n}\n","import path from 'node:path'\nimport { promises as fs } from 'node:fs'\nimport { parseAllDocuments } from 'yaml'\nimport type { ServiceNode } from '@neat.is/types'\nimport { NodeType } from '@neat.is/types'\nimport type { NeatGraph } from '../graph.js'\nimport {\n CONFIG_FILE_EXTENSIONS,\n IGNORED_DIRS,\n exists,\n readYaml,\n type DiscoveredService,\n} from './shared.js'\n\n// Populate ServiceNode.aliases from sources that the OTel layer is likely to\n// see in span attributes:\n//\n// - docker-compose service names (compose-DNS).\n// - Dockerfile LABEL values that name the service.\n// - k8s metadata.name (and the cluster-DNS variants) for Service /\n// Deployment / StatefulSet whose name matches a known service.\n//\n// resolveServiceId in ingest.ts checks aliases before falling back to a\n// FRONTIER placeholder; promoteFrontierNodes uses them to retire stale\n// placeholders once they map to a real service.\n\ninterface ComposeService {\n container_name?: string\n hostname?: string\n networks?: string[] | Record<string, unknown>\n}\n\ninterface ComposeFile {\n services?: Record<string, ComposeService>\n}\n\ninterface K8sDoc {\n kind?: string\n metadata?: {\n name?: string\n namespace?: string\n labels?: Record<string, string>\n }\n spec?: {\n selector?: {\n app?: string\n matchLabels?: Record<string, string>\n }\n }\n}\n\nconst K8S_KINDS_WITH_HOSTNAMES = new Set([\n 'Service',\n 'Deployment',\n 'StatefulSet',\n 'DaemonSet',\n])\n\nfunction addAliases(graph: NeatGraph, serviceId: string, candidates: Iterable<string>): void {\n if (!graph.hasNode(serviceId)) return\n const node = graph.getNodeAttributes(serviceId) as ServiceNode & { type?: string }\n if (node.type !== NodeType.ServiceNode) return\n const set = new Set(node.aliases ?? [])\n for (const c of candidates) {\n if (!c) continue\n if (c === node.name) continue\n set.add(c)\n }\n if (set.size === 0) return\n const updated: ServiceNode = { ...node, aliases: [...set].sort() }\n graph.replaceNodeAttributes(serviceId, updated)\n}\n\nfunction indexServicesByName(services: DiscoveredService[]): Map<string, string> {\n const map = new Map<string, string>()\n for (const s of services) {\n map.set(s.node.name, s.node.id)\n map.set(path.basename(s.dir), s.node.id)\n }\n return map\n}\n\nasync function collectComposeAliases(\n graph: NeatGraph,\n scanPath: string,\n serviceIndex: Map<string, string>,\n): Promise<void> {\n let composePath: string | null = null\n for (const name of ['docker-compose.yml', 'docker-compose.yaml']) {\n const abs = path.join(scanPath, name)\n if (await exists(abs)) {\n composePath = abs\n break\n }\n }\n if (!composePath) return\n\n const compose = await readYaml<ComposeFile>(composePath)\n if (!compose?.services) return\n\n for (const [composeName, svc] of Object.entries(compose.services)) {\n const serviceId = serviceIndex.get(composeName)\n if (!serviceId) continue\n const aliases = new Set<string>([composeName])\n if (svc.container_name) aliases.add(svc.container_name)\n if (svc.hostname) aliases.add(svc.hostname)\n addAliases(graph, serviceId, aliases)\n }\n}\n\nconst LABEL_KEYS = new Set([\n 'service',\n 'service.name',\n 'app',\n 'app.name',\n 'com.docker.compose.service',\n 'org.opencontainers.image.title',\n])\n\nfunction parseDockerfileLabels(content: string): string[] {\n const out: string[] = []\n // Support `LABEL key=value`, `LABEL key=\"value with spaces\"`, and the\n // multi-pair form `LABEL k1=v1 k2=v2`. We don't try to honour line\n // continuations — the common single-line form is enough.\n const lineRegex = /^\\s*label\\s+(.+)$/i\n for (const raw of content.split('\\n')) {\n const m = lineRegex.exec(raw)\n if (!m) continue\n const rest = m[1]!\n const pairRegex = /([\\w.-]+)\\s*=\\s*(\"([^\"]*)\"|'([^']*)'|([^\\s]+))/g\n let pair: RegExpExecArray | null\n while ((pair = pairRegex.exec(rest)) !== null) {\n const key = pair[1]!.toLowerCase()\n if (!LABEL_KEYS.has(key)) continue\n const value = pair[3] ?? pair[4] ?? pair[5] ?? ''\n if (value) out.push(value)\n }\n }\n return out\n}\n\nasync function collectDockerfileAliases(\n graph: NeatGraph,\n services: DiscoveredService[],\n): Promise<void> {\n for (const service of services) {\n const dockerfilePath = path.join(service.dir, 'Dockerfile')\n if (!(await exists(dockerfilePath))) continue\n const content = await fs.readFile(dockerfilePath, 'utf8')\n const aliases = parseDockerfileLabels(content)\n if (aliases.length > 0) addAliases(graph, service.node.id, aliases)\n }\n}\n\nasync function walkYamlFiles(start: string, depth = 0, max = 5): Promise<string[]> {\n if (depth > max) return []\n const out: string[] = []\n const entries = await fs.readdir(start, { withFileTypes: true }).catch(() => [])\n for (const entry of entries) {\n if (entry.isDirectory()) {\n if (IGNORED_DIRS.has(entry.name)) continue\n out.push(...(await walkYamlFiles(path.join(start, entry.name), depth + 1, max)))\n } else if (entry.isFile() && CONFIG_FILE_EXTENSIONS.has(path.extname(entry.name))) {\n out.push(path.join(start, entry.name))\n }\n }\n return out\n}\n\nfunction k8sHostnames(name: string, namespace: string | undefined): string[] {\n const ns = namespace ?? 'default'\n return [\n name,\n `${name}.${ns}`,\n `${name}.${ns}.svc`,\n `${name}.${ns}.svc.cluster.local`,\n ]\n}\n\nfunction k8sServiceTarget(\n doc: K8sDoc,\n byName: Map<string, string>,\n): string | null {\n // For `Service` resources, the target is whatever app the spec selects, not\n // necessarily the Service's own metadata.name. We prefer that mapping; if no\n // selector, fall back to the metadata.name match.\n const selector = doc.spec?.selector\n const selectorApp = selector?.app ?? selector?.matchLabels?.app\n if (selectorApp && byName.has(selectorApp)) return byName.get(selectorApp)!\n\n const labelApp = doc.metadata?.labels?.app\n if (labelApp && byName.has(labelApp)) return byName.get(labelApp)!\n\n const metaName = doc.metadata?.name\n if (metaName && byName.has(metaName)) return byName.get(metaName)!\n\n return null\n}\n\nasync function collectK8sAliases(\n graph: NeatGraph,\n scanPath: string,\n serviceIndex: Map<string, string>,\n): Promise<void> {\n const files = await walkYamlFiles(scanPath)\n for (const file of files) {\n const content = await fs.readFile(file, 'utf8')\n let docs: K8sDoc[]\n try {\n docs = parseAllDocuments(content).map((d) => d.toJSON() as K8sDoc)\n } catch {\n continue\n }\n for (const doc of docs) {\n if (!doc?.kind || !doc.metadata?.name) continue\n if (!K8S_KINDS_WITH_HOSTNAMES.has(doc.kind)) continue\n const target = k8sServiceTarget(doc, serviceIndex)\n if (!target) continue\n addAliases(graph, target, k8sHostnames(doc.metadata.name, doc.metadata.namespace))\n }\n }\n}\n\nexport async function addServiceAliases(\n graph: NeatGraph,\n scanPath: string,\n services: DiscoveredService[],\n): Promise<void> {\n const byName = indexServicesByName(services)\n await collectComposeAliases(graph, scanPath, byName)\n await collectDockerfileAliases(graph, services)\n await collectK8sAliases(graph, scanPath, byName)\n}\n","import path from 'node:path'\nimport type {\n CompatibleDriver,\n DatabaseNode,\n GraphEdge,\n GraphNode,\n ServiceNode,\n} from '@neat.is/types'\nimport { EdgeType, NodeType, Provenance, databaseId } from '@neat.is/types'\nimport type { NeatGraph } from '../../graph.js'\nimport {\n checkCompatibility,\n checkDeprecatedApi,\n checkNodeEngineConstraint,\n checkPackageConflict,\n compatPairs,\n deprecatedApis,\n nodeEngineConstraints,\n packageConflicts,\n} from '../../compat.js'\nimport { cleanVersion, makeEdgeId, type DiscoveredService } from '../shared.js'\nimport { dbConfigYamlParser } from './db-config-yaml.js'\nimport { dotenvParser } from './dotenv.js'\nimport { prismaParser } from './prisma.js'\nimport { drizzleParser } from './drizzle.js'\nimport { knexParser } from './knex.js'\nimport { ormconfigParser } from './ormconfig.js'\nimport { typeormParser } from './typeorm.js'\nimport { sequelizeParser } from './sequelize.js'\nimport { dockerComposeParser } from './docker-compose.js'\nimport type { DbConfig } from './shared.js'\n\nexport type { DbConfig } from './shared.js'\n\nexport interface DbParser {\n name: string\n parse(serviceDir: string): Promise<DbConfig[]>\n}\n\n// Registry — order is for tie-breaking only (first wins on identical host).\n// db-config.yaml stays first so the canonical demo behaviour matches today's\n// extraction byte-for-byte.\nexport const DB_PARSERS: DbParser[] = [\n dbConfigYamlParser,\n dotenvParser,\n prismaParser,\n drizzleParser,\n knexParser,\n ormconfigParser,\n typeormParser,\n sequelizeParser,\n dockerComposeParser,\n]\n\nfunction compatibleDriversFor(engine: string): CompatibleDriver[] {\n return compatPairs()\n .filter((p) => p.engine === engine)\n .map((p) => ({ name: p.driver, minVersion: p.minDriverVersion }))\n}\n\nfunction toDatabaseNode(config: DbConfig): DatabaseNode {\n return {\n id: databaseId(config.host),\n type: NodeType.DatabaseNode,\n name: config.database || config.host,\n engine: config.engine,\n engineVersion: config.engineVersion,\n compatibleDrivers: compatibleDriversFor(config.engine),\n host: config.host,\n port: config.port,\n }\n}\n\nexport function attachIncompatibilities(\n service: DiscoveredService,\n configs: DbConfig[],\n): void {\n const deps = { ...(service.pkg.dependencies ?? {}), ...(service.pkg.devDependencies ?? {}) }\n const incompatibilities: NonNullable<ServiceNode['incompatibilities']> = []\n const seen = new Set<string>()\n\n // 1. driver-engine — original behaviour. Per (db config, configured driver\n // pair) check that the declared driver version meets the engine threshold.\n for (const config of configs) {\n for (const pair of compatPairs()) {\n if (pair.engine !== config.engine) continue\n const declaredVersion = cleanVersion(deps[pair.driver])\n if (!declaredVersion) continue\n const result = checkCompatibility(\n pair.driver,\n declaredVersion,\n config.engine,\n config.engineVersion,\n )\n if (!result.compatible && result.reason) {\n const key = `driver-engine|${pair.driver}@${declaredVersion}|${config.engine}@${config.engineVersion}`\n if (seen.has(key)) continue\n seen.add(key)\n incompatibilities.push({\n kind: 'driver-engine',\n driver: pair.driver,\n driverVersion: declaredVersion,\n engine: config.engine,\n engineVersion: config.engineVersion,\n reason: result.reason,\n })\n }\n }\n }\n\n // 2. node-engine — service's `engines.node` vs each declared dep that has a\n // matrix-recorded minimum.\n const serviceNodeEngine = service.node.nodeEngine ?? service.pkg.engines?.node\n for (const constraint of nodeEngineConstraints()) {\n const declared = cleanVersion(deps[constraint.package])\n if (!declared) continue\n const result = checkNodeEngineConstraint(constraint, declared, serviceNodeEngine)\n if (!result.compatible && result.reason) {\n const key = `node-engine|${constraint.package}@${declared}|${serviceNodeEngine ?? ''}`\n if (seen.has(key)) continue\n seen.add(key)\n incompatibilities.push({\n kind: 'node-engine',\n package: constraint.package,\n packageVersion: declared,\n requiredNodeVersion: result.requiredNodeVersion ?? constraint.minNodeVersion,\n ...(serviceNodeEngine ? { declaredNodeEngine: serviceNodeEngine } : {}),\n reason: result.reason,\n })\n }\n }\n\n // 3. package-conflict — pair like react-query 5+ requiring react 18+.\n for (const conflict of packageConflicts()) {\n const declared = cleanVersion(deps[conflict.package])\n if (!declared) continue\n const requiredVersion = cleanVersion(deps[conflict.requires.name])\n const result = checkPackageConflict(conflict, declared, requiredVersion)\n if (!result.compatible && result.reason) {\n const key = `package-conflict|${conflict.package}@${declared}|${conflict.requires.name}@${requiredVersion ?? 'missing'}`\n if (seen.has(key)) continue\n seen.add(key)\n incompatibilities.push({\n kind: 'package-conflict',\n package: conflict.package,\n packageVersion: declared,\n requires: conflict.requires,\n ...(requiredVersion ? { foundVersion: requiredVersion } : {}),\n reason: result.reason,\n })\n }\n }\n\n // 4. deprecated-api — flag presence of a known-deprecated package.\n for (const rule of deprecatedApis()) {\n const declared = cleanVersion(deps[rule.package])\n if (declared === undefined) continue\n const result = checkDeprecatedApi(rule, declared)\n if (!result.compatible && result.reason) {\n const key = `deprecated-api|${rule.package}@${declared}`\n if (seen.has(key)) continue\n seen.add(key)\n incompatibilities.push({\n kind: 'deprecated-api',\n package: rule.package,\n packageVersion: declared,\n reason: result.reason,\n })\n }\n }\n\n if (incompatibilities.length > 0) service.node.incompatibilities = incompatibilities\n}\n\n// Phase 2 — for each service, run every parser and merge their DbConfigs by\n// host. Each unique host produces one DatabaseNode + CONNECTS_TO edge from the\n// service. The parser registry decides priority on tie; the demo's\n// db-config.yaml stays first so its `engineVersion: 15` continues to win.\nexport async function addDatabasesAndCompat(\n graph: NeatGraph,\n services: DiscoveredService[],\n scanPath: string,\n): Promise<{ nodesAdded: number; edgesAdded: number }> {\n let nodesAdded = 0\n let edgesAdded = 0\n\n for (const service of services) {\n const merged = new Map<string, DbConfig>()\n for (const parser of DB_PARSERS) {\n let configs: DbConfig[]\n try {\n configs = await parser.parse(service.dir)\n } catch (err) {\n console.warn(\n `[neat] ${parser.name} parser failed on ${service.node.name}: ${(err as Error).message}`,\n )\n continue\n }\n for (const config of configs) {\n if (!config.host) continue\n if (!merged.has(config.host)) merged.set(config.host, config)\n }\n }\n\n const allConfigs = [...merged.values()]\n for (const config of allConfigs) {\n const dbNode = toDatabaseNode(config)\n if (!graph.hasNode(dbNode.id)) {\n graph.addNode(dbNode.id, { ...dbNode, discoveredVia: 'static' })\n nodesAdded++\n } else {\n // OTel ingest may have auto-created a minimal node at this id. Merge\n // per ADR-033: static fields override OTel-derived fields, discoveredVia\n // flips to 'merged' when both layers contributed.\n const existing = graph.getNodeAttributes(dbNode.id) as DatabaseNode\n const mergedDiscoveredVia: 'static' | 'otel' | 'merged' =\n existing.discoveredVia === 'otel' ? 'merged' : 'static'\n graph.replaceNodeAttributes(dbNode.id, {\n ...existing,\n ...dbNode,\n discoveredVia: mergedDiscoveredVia,\n })\n }\n const edge: GraphEdge = {\n id: makeEdgeId(service.node.id, dbNode.id, EdgeType.CONNECTS_TO),\n source: service.node.id,\n target: dbNode.id,\n type: EdgeType.CONNECTS_TO,\n provenance: Provenance.EXTRACTED,\n ...(config.sourceFile\n ? {\n evidence: {\n file: path.relative(scanPath, config.sourceFile).split(path.sep).join('/'),\n },\n }\n : {}),\n }\n if (!graph.hasEdge(edge.id)) {\n graph.addEdgeWithKey(edge.id, edge.source, edge.target, edge)\n edgesAdded++\n }\n }\n\n // Run all kinds of incompat checks even for services with no db connection\n // — node-engine / package-conflict / deprecated-api don't depend on db.\n attachIncompatibilities(service, allConfigs)\n if (graph.hasNode(service.node.id)) {\n // Merge with whatever's on the node already (aliases from γ #75 land\n // before this phase), so the writeback doesn't drop fields populated by\n // earlier passes.\n const current = graph.getNodeAttributes(service.node.id) as ServiceNode\n const updated: ServiceNode = {\n ...current,\n ...(service.node as ServiceNode),\n ...(current.aliases ? { aliases: current.aliases } : {}),\n }\n // attachIncompatibilities only sets the field when there's something to\n // flag. On a re-extract (`neat watch`, `POST /graph/scan`), a stale\n // entry on `current` would otherwise survive the spread and leave the\n // graph reporting a problem the new manifest no longer has.\n if (!service.node.incompatibilities || service.node.incompatibilities.length === 0) {\n delete (updated as { incompatibilities?: unknown }).incompatibilities\n }\n graph.replaceNodeAttributes(service.node.id, updated as unknown as GraphNode)\n }\n }\n\n return { nodesAdded, edgesAdded }\n}\n","import path from 'node:path'\nimport { exists, readYaml } from '../shared.js'\nimport type { DbConfig } from './shared.js'\n\ninterface DbConfigYaml {\n host: string\n port?: number\n database: string\n engine: string\n engineVersion?: string | number\n}\n\n// The original db-config.yaml format, kept as a parser so the demo continues\n// to work. Engine + version are explicit here, so this is the one source that\n// can produce a real engineVersion without inference.\nexport async function parse(serviceDir: string): Promise<DbConfig[]> {\n const yamlPath = path.join(serviceDir, 'db-config.yaml')\n if (!(await exists(yamlPath))) return []\n const raw = await readYaml<DbConfigYaml>(yamlPath)\n return [\n {\n host: raw.host,\n port: raw.port,\n database: raw.database,\n engine: raw.engine,\n engineVersion: raw.engineVersion !== undefined ? String(raw.engineVersion) : 'unknown',\n sourceFile: yamlPath,\n },\n ]\n}\n\nexport const dbConfigYamlParser = { name: 'db-config.yaml', parse }\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport { isConfigFile } from '../shared.js'\nimport { parseConnectionString, type DbConfig } from './shared.js'\n\nconst CONNECTION_KEYS = new Set([\n 'DATABASE_URL',\n 'DB_URL',\n 'POSTGRES_URL',\n 'POSTGRESQL_URL',\n 'MYSQL_URL',\n 'MONGODB_URI',\n 'MONGO_URL',\n 'MONGO_URI',\n 'REDIS_URL',\n])\n\n// Per ADR-016, .env contents do not land in any snapshot. We read them here\n// only to derive a transient DbConfig — the value never reaches a ConfigNode.\nfunction parseDotenvLine(line: string): { key: string; value: string } | null {\n const trimmed = line.trim()\n if (!trimmed || trimmed.startsWith('#')) return null\n const eq = trimmed.indexOf('=')\n if (eq < 0) return null\n const key = trimmed.slice(0, eq).trim()\n let value = trimmed.slice(eq + 1).trim()\n if (\n (value.startsWith('\"') && value.endsWith('\"')) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n value = value.slice(1, -1)\n }\n return { key, value }\n}\n\nexport async function parse(serviceDir: string): Promise<DbConfig[]> {\n const entries = await fs.readdir(serviceDir, { withFileTypes: true }).catch(() => [])\n const configs: DbConfig[] = []\n const seen = new Set<string>()\n\n for (const entry of entries) {\n if (!entry.isFile()) continue\n const match = isConfigFile(entry.name)\n if (!match.match || match.fileType !== 'env') continue\n\n const filePath = path.join(serviceDir, entry.name)\n const content = await fs.readFile(filePath, 'utf8')\n for (const line of content.split('\\n')) {\n const parsed = parseDotenvLine(line)\n if (!parsed) continue\n if (!CONNECTION_KEYS.has(parsed.key.toUpperCase())) continue\n const config = parseConnectionString(parsed.value)\n if (!config) continue\n const key = `${config.engine}://${config.host}:${config.port ?? ''}/${config.database}`\n if (seen.has(key)) continue\n seen.add(key)\n configs.push({ ...config, sourceFile: filePath })\n }\n }\n return configs\n}\n\nexport const dotenvParser = { name: '.env', parse }\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\n\nexport interface DbConfig {\n host: string\n port?: number\n database: string\n engine: string\n engineVersion: string // \"unknown\" when not statically determinable\n // Absolute path to the file the parser read this config from. Used to\n // populate evidence.file on the resulting CONNECTS_TO edge. Optional so\n // synthesized configs (e.g. prisma's env() fallback) can omit it; the\n // CONNECTS_TO writer emits evidence only when present.\n sourceFile?: string\n}\n\n// Map a connection-string scheme to the engine name our compat matrix uses.\n// Schemes like \"postgres+asyncpg\" are normalised by stripping the dialect\n// suffix; anything we don't recognise returns null so the parser can decline.\nexport function schemeToEngine(scheme: string): string | null {\n const s = scheme.toLowerCase().split('+')[0]\n switch (s) {\n case 'postgres':\n case 'postgresql':\n return 'postgresql'\n case 'mysql':\n case 'mariadb':\n return 'mysql'\n case 'mongodb':\n case 'mongodb+srv':\n return 'mongodb'\n case 'redis':\n case 'rediss':\n return 'redis'\n case 'sqlite':\n return 'sqlite'\n default:\n return null\n }\n}\n\nexport function parseConnectionString(url: string): DbConfig | null {\n const m = url.match(\n /^(?<scheme>[a-z][a-z+]*):\\/\\/(?:[^@/]+(?::[^@]*)?@)?(?<host>[^:/?]+)(?::(?<port>\\d+))?(?:\\/(?<db>[^?#]*))?/i,\n )\n if (!m || !m.groups) return null\n const engine = schemeToEngine(m.groups.scheme!)\n if (!engine) return null\n return {\n host: m.groups.host!,\n port: m.groups.port ? Number(m.groups.port) : undefined,\n database: m.groups.db ?? '',\n engine,\n engineVersion: 'unknown',\n }\n}\n\nexport async function readIfExists(filePath: string): Promise<string | null> {\n try {\n return await fs.readFile(filePath, 'utf8')\n } catch {\n return null\n }\n}\n\nexport async function findFirst(\n serviceDir: string,\n candidates: string[],\n): Promise<string | null> {\n for (const rel of candidates) {\n const abs = path.join(serviceDir, rel)\n const content = await readIfExists(abs)\n if (content !== null) return abs\n }\n return null\n}\n\n// Engine name from a docker-compose `image:` value like \"postgres:15-alpine\"\n// or \"mysql/mysql-server:8.0\". Returns the engine + version when both are\n// resolvable, or null if the image isn't one we recognise.\nexport function engineFromImage(\n image: string,\n): { engine: string; engineVersion: string } | null {\n const lower = image.toLowerCase()\n const colon = lower.lastIndexOf(':')\n const repo = colon >= 0 ? lower.slice(0, colon) : lower\n const tag = colon >= 0 ? lower.slice(colon + 1) : 'latest'\n const last = repo.split('/').pop() ?? repo\n let engine: string | null = null\n if (last.startsWith('postgres')) engine = 'postgresql'\n else if (last.startsWith('mysql') || last.startsWith('mariadb')) engine = 'mysql'\n else if (last.startsWith('mongo')) engine = 'mongodb'\n else if (last.startsWith('redis')) engine = 'redis'\n else if (last.startsWith('sqlite')) engine = 'sqlite'\n if (!engine) return null\n // Strip everything after the major version digit run; \"15-alpine\" -> \"15\".\n const versionMatch = tag.match(/^(\\d+(?:\\.\\d+){0,2})/)\n return {\n engine,\n engineVersion: versionMatch ? versionMatch[1]! : 'unknown',\n }\n}\n","import path from 'node:path'\nimport { readIfExists, parseConnectionString, schemeToEngine, type DbConfig } from './shared.js'\n\n// Prisma's schema file declares datasources of the form:\n//\n// datasource db {\n// provider = \"postgresql\"\n// url = env(\"DATABASE_URL\")\n// }\n//\n// We match the provider directly. URLs come in via env() so we can't resolve\n// them statically; host/database fall back to placeholders so the DatabaseNode\n// id remains deterministic per service.\nexport async function parse(serviceDir: string): Promise<DbConfig[]> {\n const schemaPath = path.join(serviceDir, 'prisma', 'schema.prisma')\n const content = await readIfExists(schemaPath)\n if (!content) return []\n\n const block = content.match(/datasource\\s+\\w+\\s*\\{([^}]*)\\}/s)\n if (!block) return []\n const body = block[1] ?? ''\n\n const providerMatch = body.match(/provider\\s*=\\s*\"([^\"]+)\"/)\n if (!providerMatch) return []\n const engine = schemeToEngine(providerMatch[1]!)\n if (!engine) return []\n\n const urlMatch = body.match(/url\\s*=\\s*\"([^\"]+)\"/)\n if (urlMatch) {\n const config = parseConnectionString(urlMatch[1]!)\n if (config) return [{ ...config, sourceFile: schemaPath }]\n }\n\n return [\n {\n host: `${engine}-prisma`,\n database: '',\n engine,\n engineVersion: 'unknown',\n sourceFile: schemaPath,\n },\n ]\n}\n\nexport const prismaParser = { name: 'prisma', parse }\n","import { findFirst, readIfExists, parseConnectionString, schemeToEngine, type DbConfig } from './shared.js'\n\nconst DIALECT_TO_ENGINE: Record<string, string> = {\n postgresql: 'postgresql',\n postgres: 'postgresql',\n pg: 'postgresql',\n mysql: 'mysql',\n mysql2: 'mysql',\n sqlite: 'sqlite',\n 'better-sqlite': 'sqlite',\n}\n\n// Drizzle's drizzle.config.{ts,js,mjs} declares a `dialect` plus credentials.\n// We can't safely eval the file, but the relevant bits are simple key/value\n// expressions — regex-extracted to stay sandbox-clean and dep-free.\nexport async function parse(serviceDir: string): Promise<DbConfig[]> {\n const filePath = await findFirst(serviceDir, [\n 'drizzle.config.ts',\n 'drizzle.config.js',\n 'drizzle.config.mjs',\n ])\n if (!filePath) return []\n const content = await readIfExists(filePath)\n if (!content) return []\n\n const dialectMatch = content.match(/dialect\\s*:\\s*['\"`]([^'\"`]+)['\"`]/)\n if (!dialectMatch) return []\n const engine =\n DIALECT_TO_ENGINE[dialectMatch[1]!.toLowerCase()] ?? schemeToEngine(dialectMatch[1]!)\n if (!engine) return []\n\n const urlMatch = content.match(\n /(?:url|connectionString)\\s*:\\s*['\"`]([a-z][a-z+]*:\\/\\/[^'\"`]+)['\"`]/i,\n )\n if (urlMatch) {\n const config = parseConnectionString(urlMatch[1]!)\n if (config) return [{ ...config, sourceFile: filePath }]\n }\n const hostMatch = content.match(/host\\s*:\\s*['\"`]([^'\"`]+)['\"`]/)\n if (hostMatch) {\n const portMatch = content.match(/port\\s*:\\s*(\\d+)/)\n const dbMatch = content.match(/database\\s*:\\s*['\"`]([^'\"`]+)['\"`]/)\n return [\n {\n host: hostMatch[1]!,\n port: portMatch ? Number(portMatch[1]) : undefined,\n database: dbMatch?.[1] ?? '',\n engine,\n engineVersion: 'unknown',\n sourceFile: filePath,\n },\n ]\n }\n return [\n { host: `${engine}-drizzle`, database: '', engine, engineVersion: 'unknown', sourceFile: filePath },\n ]\n}\n\nexport const drizzleParser = { name: 'drizzle', parse }\n","import { findFirst, readIfExists, parseConnectionString, type DbConfig } from './shared.js'\n\nconst CLIENT_TO_ENGINE: Record<string, string> = {\n pg: 'postgresql',\n postgres: 'postgresql',\n postgresql: 'postgresql',\n mysql: 'mysql',\n mysql2: 'mysql',\n sqlite3: 'sqlite',\n 'better-sqlite3': 'sqlite',\n}\n\n// knexfile.{js,ts} declares a client (one of pg/mysql/sqlite/...) plus a\n// connection string or host/port object. We pick whichever shape is in the\n// file and ignore environment-driven values we can't resolve statically.\nexport async function parse(serviceDir: string): Promise<DbConfig[]> {\n const filePath = await findFirst(serviceDir, [\n 'knexfile.js',\n 'knexfile.ts',\n 'knexfile.cjs',\n 'knexfile.mjs',\n ])\n if (!filePath) return []\n const content = await readIfExists(filePath)\n if (!content) return []\n\n const clientMatch = content.match(/client\\s*:\\s*['\"`]([^'\"`]+)['\"`]/)\n if (!clientMatch) return []\n const engine = CLIENT_TO_ENGINE[clientMatch[1]!.toLowerCase()]\n if (!engine) return []\n\n const urlMatch = content.match(\n /connection\\s*:\\s*['\"`]([a-z][a-z+]*:\\/\\/[^'\"`]+)['\"`]/i,\n )\n if (urlMatch) {\n const config = parseConnectionString(urlMatch[1]!)\n if (config) return [{ ...config, sourceFile: filePath }]\n }\n\n const host = content.match(/host\\s*:\\s*['\"`]([^'\"`]+)['\"`]/)?.[1]\n if (host) {\n const port = content.match(/port\\s*:\\s*(\\d+)/)?.[1]\n const database = content.match(/database\\s*:\\s*['\"`]([^'\"`]+)['\"`]/)?.[1] ?? ''\n return [\n {\n host,\n port: port ? Number(port) : undefined,\n database,\n engine,\n engineVersion: 'unknown',\n sourceFile: filePath,\n },\n ]\n }\n\n return [{ host: `${engine}-knex`, database: '', engine, engineVersion: 'unknown', sourceFile: filePath }]\n}\n\nexport const knexParser = { name: 'knex', parse }\n","import path from 'node:path'\nimport { exists, readJson, readYaml } from '../shared.js'\nimport { schemeToEngine, type DbConfig } from './shared.js'\n\ninterface OrmConfigEntry {\n type?: string\n host?: string\n port?: number\n database?: string\n}\n\n// ormconfig.{json,yaml,yml} — TypeORM's legacy config file. Single object or\n// an array of named connections; we walk both.\nexport async function parse(serviceDir: string): Promise<DbConfig[]> {\n for (const candidate of ['ormconfig.json', 'ormconfig.yaml', 'ormconfig.yml']) {\n const abs = path.join(serviceDir, candidate)\n if (!(await exists(abs))) continue\n const raw = candidate.endsWith('.json')\n ? await readJson<OrmConfigEntry | OrmConfigEntry[]>(abs)\n : await readYaml<OrmConfigEntry | OrmConfigEntry[]>(abs)\n const entries = Array.isArray(raw) ? raw : [raw]\n\n const out: DbConfig[] = []\n for (const entry of entries) {\n if (!entry?.type || !entry.host) continue\n const engine = schemeToEngine(entry.type)\n if (!engine) continue\n out.push({\n host: entry.host,\n port: entry.port,\n database: entry.database ?? '',\n engine,\n engineVersion: 'unknown',\n sourceFile: abs,\n })\n }\n if (out.length > 0) return out\n }\n return []\n}\n\nexport const ormconfigParser = { name: 'ormconfig', parse }\n","import { findFirst, readIfExists, schemeToEngine, type DbConfig } from './shared.js'\n\n// TypeORM's modern shape: `new DataSource({ type: 'postgres', host, port, ... })`\n// in a data-source.ts (or .js). We regex for the type/host/port/database keys\n// in the first DataSource literal we find.\nexport async function parse(serviceDir: string): Promise<DbConfig[]> {\n const filePath = await findFirst(serviceDir, [\n 'data-source.ts',\n 'data-source.js',\n 'src/data-source.ts',\n 'src/data-source.js',\n ])\n if (!filePath) return []\n const content = await readIfExists(filePath)\n if (!content) return []\n\n const block = content.match(/new\\s+DataSource\\s*\\(\\s*\\{([\\s\\S]*?)\\}\\s*\\)/)\n const body = block ? block[1]! : content\n\n const typeMatch = body.match(/type\\s*:\\s*['\"`]([^'\"`]+)['\"`]/)\n const host = body.match(/host\\s*:\\s*['\"`]([^'\"`]+)['\"`]/)?.[1]\n if (!typeMatch || !host) return []\n\n const engine = schemeToEngine(typeMatch[1]!)\n if (!engine) return []\n\n const port = body.match(/port\\s*:\\s*(\\d+)/)?.[1]\n const database = body.match(/database\\s*:\\s*['\"`]([^'\"`]+)['\"`]/)?.[1] ?? ''\n\n return [\n {\n host,\n port: port ? Number(port) : undefined,\n database,\n engine,\n engineVersion: 'unknown',\n sourceFile: filePath,\n },\n ]\n}\n\nexport const typeormParser = { name: 'typeorm', parse }\n","import path from 'node:path'\nimport { exists, readJson } from '../shared.js'\nimport { schemeToEngine, type DbConfig } from './shared.js'\n\ninterface SequelizeConfigEntry {\n dialect?: string\n host?: string\n port?: number\n database?: string\n}\n\ntype SequelizeConfig = Record<string, SequelizeConfigEntry>\n\n// Sequelize stores per-environment configs under config/config.json. We read\n// every named environment so a service that declares production + staging\n// surfaces both DB targets.\nexport async function parse(serviceDir: string): Promise<DbConfig[]> {\n const configPath = path.join(serviceDir, 'config', 'config.json')\n if (!(await exists(configPath))) return []\n const raw = await readJson<SequelizeConfig>(configPath)\n\n const out: DbConfig[] = []\n const seen = new Set<string>()\n for (const entry of Object.values(raw)) {\n if (!entry?.dialect || !entry.host) continue\n const engine = schemeToEngine(entry.dialect)\n if (!engine) continue\n const key = `${engine}://${entry.host}:${entry.port ?? ''}/${entry.database ?? ''}`\n if (seen.has(key)) continue\n seen.add(key)\n out.push({\n host: entry.host,\n port: entry.port,\n database: entry.database ?? '',\n engine,\n engineVersion: 'unknown',\n sourceFile: configPath,\n })\n }\n return out\n}\n\nexport const sequelizeParser = { name: 'sequelize', parse }\n","import path from 'node:path'\nimport { exists, readYaml } from '../shared.js'\nimport { engineFromImage, type DbConfig } from './shared.js'\n\ninterface ComposeService {\n image?: string\n ports?: (string | number)[]\n environment?: Record<string, string> | string[]\n}\n\ninterface ComposeFile {\n services?: Record<string, ComposeService>\n}\n\nfunction portFromService(svc: ComposeService): number | undefined {\n for (const raw of svc.ports ?? []) {\n const str = String(raw)\n // \"5432:5432\", \"5432\", or \"host:5432\" → take the trailing port.\n const last = str.split(':').pop()\n const n = Number(last)\n if (Number.isFinite(n) && n > 0) return n\n }\n return undefined\n}\n\nfunction databaseFromEnv(svc: ComposeService): string {\n const env = svc.environment\n const get = (key: string): string | undefined => {\n if (!env) return undefined\n if (Array.isArray(env)) {\n for (const line of env) {\n const [k, v] = line.split('=')\n if (k === key) return v\n }\n return undefined\n }\n return env[key]\n }\n return get('POSTGRES_DB') ?? get('MYSQL_DATABASE') ?? get('MONGO_INITDB_DATABASE') ?? ''\n}\n\n// Service-local docker-compose.yml — every service whose image we recognise\n// becomes a candidate DB. The compose service name doubles as the host since\n// that's how peer services on the same compose network reach it.\nexport async function parse(serviceDir: string): Promise<DbConfig[]> {\n for (const name of ['docker-compose.yml', 'docker-compose.yaml']) {\n const abs = path.join(serviceDir, name)\n if (!(await exists(abs))) continue\n const raw = await readYaml<ComposeFile>(abs)\n if (!raw?.services) return []\n\n const out: DbConfig[] = []\n for (const [serviceName, svc] of Object.entries(raw.services)) {\n if (!svc.image) continue\n const meta = engineFromImage(svc.image)\n if (!meta) continue\n out.push({\n host: serviceName,\n port: portFromService(svc),\n database: databaseFromEnv(svc),\n engine: meta.engine,\n engineVersion: meta.engineVersion,\n sourceFile: abs,\n })\n }\n return out\n }\n return []\n}\n\nexport const dockerComposeParser = { name: 'docker-compose', parse }\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport type { ConfigNode, GraphEdge } from '@neat.is/types'\nimport { EdgeType, NodeType, Provenance, configId } from '@neat.is/types'\nimport type { NeatGraph } from '../graph.js'\nimport { IGNORED_DIRS, isConfigFile, makeEdgeId, type DiscoveredService } from './shared.js'\n\n// Walk a service directory and collect every config file path\n// (yaml/yml + .env-shaped). We deliberately stop at file paths here so nothing\n// in this module reads file contents — .env files routinely carry secrets\n// (ADR-016).\nexport async function walkConfigFiles(dir: string): Promise<string[]> {\n const out: string[] = []\n async function walk(current: string): Promise<void> {\n const entries = await fs.readdir(current, { withFileTypes: true })\n for (const entry of entries) {\n const full = path.join(current, entry.name)\n if (entry.isDirectory()) {\n if (!IGNORED_DIRS.has(entry.name)) await walk(full)\n } else if (entry.isFile() && isConfigFile(entry.name).match) {\n out.push(full)\n }\n }\n }\n await walk(dir)\n return out\n}\n\n// Phase 3 — turn each config file into a ConfigNode with a CONFIGURED_BY edge\n// from its owning service.\nexport async function addConfigNodes(\n graph: NeatGraph,\n services: DiscoveredService[],\n scanPath: string,\n): Promise<{ nodesAdded: number; edgesAdded: number }> {\n let nodesAdded = 0\n let edgesAdded = 0\n for (const service of services) {\n const configFiles = await walkConfigFiles(service.dir)\n for (const file of configFiles) {\n const relPath = path.relative(scanPath, file)\n const node: ConfigNode = {\n id: configId(relPath),\n type: NodeType.ConfigNode,\n name: path.basename(file),\n path: relPath,\n fileType: isConfigFile(path.basename(file)).fileType,\n }\n if (!graph.hasNode(node.id)) {\n graph.addNode(node.id, node)\n nodesAdded++\n }\n const edge: GraphEdge = {\n id: makeEdgeId(service.node.id, node.id, EdgeType.CONFIGURED_BY),\n source: service.node.id,\n target: node.id,\n type: EdgeType.CONFIGURED_BY,\n provenance: Provenance.EXTRACTED,\n evidence: { file: relPath.split(path.sep).join('/') },\n }\n if (!graph.hasEdge(edge.id)) {\n graph.addEdgeWithKey(edge.id, edge.source, edge.target, edge)\n edgesAdded++\n }\n }\n }\n return { nodesAdded, edgesAdded }\n}\n","import type { GraphEdge, InfraNode } from '@neat.is/types'\nimport { EdgeType, NodeType, Provenance } from '@neat.is/types'\nimport type { NeatGraph } from '../../graph.js'\nimport { makeEdgeId, type DiscoveredService } from '../shared.js'\nimport { addHttpCallEdges } from './http.js'\nimport { loadSourceFiles, type ExternalEndpoint } from './shared.js'\nimport { kafkaEndpointsFromFile } from './kafka.js'\nimport { redisEndpointsFromFile } from './redis.js'\nimport { awsEndpointsFromFile } from './aws.js'\nimport { grpcEndpointsFromFile } from './grpc.js'\n\nexport interface CallExtractResult {\n nodesAdded: number\n edgesAdded: number\n}\n\nfunction edgeTypeFromEndpoint(ep: ExternalEndpoint): (typeof EdgeType)[keyof typeof EdgeType] {\n switch (ep.edgeType) {\n case 'PUBLISHES_TO':\n return EdgeType.PUBLISHES_TO\n case 'CONSUMES_FROM':\n return EdgeType.CONSUMES_FROM\n default:\n return EdgeType.CALLS\n }\n}\n\nasync function addExternalEndpointEdges(\n graph: NeatGraph,\n services: DiscoveredService[],\n): Promise<CallExtractResult> {\n let nodesAdded = 0\n let edgesAdded = 0\n\n for (const service of services) {\n const files = await loadSourceFiles(service.dir)\n const endpoints: ExternalEndpoint[] = []\n for (const file of files) {\n endpoints.push(...kafkaEndpointsFromFile(file, service.dir))\n endpoints.push(...redisEndpointsFromFile(file, service.dir))\n endpoints.push(...awsEndpointsFromFile(file, service.dir))\n endpoints.push(...grpcEndpointsFromFile(file, service.dir))\n }\n if (endpoints.length === 0) continue\n\n const seenEdges = new Set<string>()\n for (const ep of endpoints) {\n if (!graph.hasNode(ep.infraId)) {\n const node: InfraNode = {\n id: ep.infraId,\n type: NodeType.InfraNode,\n name: ep.name,\n provider: ep.kind.startsWith('s3') || ep.kind.startsWith('dynamodb') ? 'aws' : 'self',\n kind: ep.kind,\n }\n graph.addNode(node.id, node)\n nodesAdded++\n }\n\n const edgeType = edgeTypeFromEndpoint(ep)\n const edgeId = makeEdgeId(service.node.id, ep.infraId, edgeType)\n if (seenEdges.has(edgeId)) continue\n seenEdges.add(edgeId)\n if (!graph.hasEdge(edgeId)) {\n const edge: GraphEdge = {\n id: edgeId,\n source: service.node.id,\n target: ep.infraId,\n type: edgeType,\n provenance: Provenance.EXTRACTED,\n evidence: ep.evidence,\n }\n graph.addEdgeWithKey(edgeId, edge.source, edge.target, edge)\n edgesAdded++\n }\n }\n }\n return { nodesAdded, edgesAdded }\n}\n\nexport async function addCallEdges(\n graph: NeatGraph,\n services: DiscoveredService[],\n): Promise<CallExtractResult> {\n const httpEdges = await addHttpCallEdges(graph, services)\n const ext = await addExternalEndpointEdges(graph, services)\n return {\n nodesAdded: ext.nodesAdded,\n edgesAdded: httpEdges + ext.edgesAdded,\n }\n}\n","import path from 'node:path'\nimport Parser from 'tree-sitter'\nimport JavaScript from 'tree-sitter-javascript'\nimport Python from 'tree-sitter-python'\nimport type { GraphEdge } from '@neat.is/types'\nimport { EdgeType, Provenance } from '@neat.is/types'\nimport type { NeatGraph } from '../../graph.js'\nimport { makeEdgeId, type DiscoveredService } from '../shared.js'\nimport { loadSourceFiles, lineOf, snippet } from './shared.js'\n\n// JS uses `string_fragment` for the textual interior of a template/string;\n// Python uses `string_content` inside a `string` node. Either way we want the\n// raw textual content (no quotes), so we accept both.\nconst STRING_LITERAL_NODE_TYPES = new Set(['string_fragment', 'string_content'])\n\nfunction collectStringLiterals(node: Parser.SyntaxNode, out: string[]): void {\n if (STRING_LITERAL_NODE_TYPES.has(node.type)) out.push(node.text)\n for (let i = 0; i < node.namedChildCount; i++) {\n const child = node.namedChild(i)\n if (child) collectStringLiterals(child, out)\n }\n}\n\nexport function callsFromSource(\n source: string,\n parser: Parser,\n knownHosts: Set<string>,\n): Set<string> {\n const tree = parser.parse(source)\n const literals: string[] = []\n collectStringLiterals(tree.rootNode, literals)\n const targets = new Set<string>()\n for (const lit of literals) {\n for (const host of knownHosts) {\n if (lit.includes(`//${host}`) || lit.includes(`//${host}:`)) {\n targets.add(host)\n }\n }\n }\n return targets\n}\n\nfunction makeJsParser(): Parser {\n const p = new Parser()\n p.setLanguage(JavaScript)\n return p\n}\n\nfunction makePyParser(): Parser {\n const p = new Parser()\n p.setLanguage(Python)\n return p\n}\n\n// HTTP CALLS via URL substring match. Parser is picked per file extension:\n// .py uses tree-sitter-python; everything else uses tree-sitter-javascript.\n// The demo's CALLS edges stay byte-for-byte identical to the M1 baseline.\nexport async function addHttpCallEdges(\n graph: NeatGraph,\n services: DiscoveredService[],\n): Promise<number> {\n const jsParser = makeJsParser()\n const pyParser = makePyParser()\n\n const knownHosts = new Set<string>()\n const hostToNodeId = new Map<string, string>()\n for (const service of services) {\n knownHosts.add(path.basename(service.dir))\n knownHosts.add(service.pkg.name)\n hostToNodeId.set(path.basename(service.dir), service.node.id)\n hostToNodeId.set(service.pkg.name, service.node.id)\n }\n\n let edgesAdded = 0\n for (const service of services) {\n const files = await loadSourceFiles(service.dir)\n const seenTargets = new Map<string, { file: string; host: string }>()\n for (const file of files) {\n const parser = path.extname(file.path) === '.py' ? pyParser : jsParser\n const targets = callsFromSource(file.content, parser, knownHosts)\n for (const t of targets) {\n const targetId = hostToNodeId.get(t)\n if (!targetId || targetId === service.node.id) continue\n if (!seenTargets.has(targetId)) {\n seenTargets.set(targetId, { file: file.path, host: t })\n }\n }\n }\n for (const [targetId, evidenceFile] of seenTargets) {\n const fileContent = files.find((f) => f.path === evidenceFile.file)?.content ?? ''\n const line = lineOf(fileContent, `//${evidenceFile.host}`)\n const edge: GraphEdge = {\n id: makeEdgeId(service.node.id, targetId, EdgeType.CALLS),\n source: service.node.id,\n target: targetId,\n type: EdgeType.CALLS,\n provenance: Provenance.EXTRACTED,\n evidence: {\n file: path.relative(service.dir, evidenceFile.file),\n line,\n snippet: snippet(fileContent, line),\n },\n }\n if (!graph.hasEdge(edge.id)) {\n graph.addEdgeWithKey(edge.id, edge.source, edge.target, edge)\n edgesAdded++\n }\n }\n }\n return edgesAdded\n}\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport type { EdgeEvidence } from '@neat.is/types'\nimport { IGNORED_DIRS, SERVICE_FILE_EXTENSIONS } from '../shared.js'\n\nexport interface SourceFile {\n path: string\n content: string\n}\n\nexport interface ExternalEndpoint {\n // Stable id of the InfraNode this evidence implies. Format\n // `infra:<kind>:<name>` so the orchestrator can dedupe across services.\n infraId: string\n // Display name on the InfraNode (e.g., \"orders\" for kafka-topic:orders).\n name: string\n kind: string\n edgeType: 'CALLS' | 'PUBLISHES_TO' | 'CONSUMES_FROM'\n evidence: EdgeEvidence\n}\n\nexport async function walkSourceFiles(dir: string): Promise<string[]> {\n const out: string[] = []\n async function walk(current: string): Promise<void> {\n const entries = await fs.readdir(current, { withFileTypes: true }).catch(() => [])\n for (const entry of entries) {\n const full = path.join(current, entry.name)\n if (entry.isDirectory()) {\n if (!IGNORED_DIRS.has(entry.name)) await walk(full)\n } else if (entry.isFile() && SERVICE_FILE_EXTENSIONS.has(path.extname(entry.name))) {\n out.push(full)\n }\n }\n }\n await walk(dir)\n return out\n}\n\nexport async function loadSourceFiles(dir: string): Promise<SourceFile[]> {\n const paths = await walkSourceFiles(dir)\n const out: SourceFile[] = []\n for (const p of paths) {\n try {\n const content = await fs.readFile(p, 'utf8')\n out.push({ path: p, content })\n } catch {\n // unreadable, skip\n }\n }\n return out\n}\n\n// Locate the line of the first occurrence of `needle` in `text`, 1-indexed.\n// Falls back to line 1 if the needle isn't found verbatim — better to point at\n// the file than to drop the evidence entirely.\nexport function lineOf(text: string, needle: string): number {\n const idx = text.indexOf(needle)\n if (idx < 0) return 1\n return text.slice(0, idx).split('\\n').length\n}\n\nexport function snippet(text: string, line: number): string {\n const lines = text.split('\\n')\n return (lines[line - 1] ?? '').trim()\n}\n","import path from 'node:path'\nimport { infraId } from '@neat.is/types'\nimport { lineOf, snippet, type ExternalEndpoint, type SourceFile } from './shared.js'\n\n// Match `producer.send({ topic: \"orders\" ... })` and `producer.send({\n// topic: 'orders' })` plus the two-arg form `producer.send(\"orders\", ...)`.\n// Kafka client libraries vary; these two forms cover kafkajs + node-rdkafka\n// well enough for static extraction. Same shape covers consumer.subscribe.\nconst PRODUCER_TOPIC_RE =\n /(?:producer|kafkaProducer)[\\s\\S]{0,40}?\\.send\\s*\\(\\s*\\{[\\s\\S]{0,200}?topic\\s*:\\s*['\"`]([^'\"`]+)['\"`]/g\nconst CONSUMER_TOPIC_RE =\n /(?:consumer|kafkaConsumer)[\\s\\S]{0,40}?\\.(?:subscribe|run)\\s*\\(\\s*\\{[\\s\\S]{0,200}?topic[s]?\\s*:\\s*(?:\\[\\s*)?['\"`]([^'\"`]+)['\"`]/g\n\nfunction findAll(re: RegExp, text: string): { topic: string; index: number }[] {\n re.lastIndex = 0\n const out: { topic: string; index: number }[] = []\n let m: RegExpExecArray | null\n while ((m = re.exec(text)) !== null) {\n out.push({ topic: m[1]!, index: m.index })\n }\n return out\n}\n\nexport function kafkaEndpointsFromFile(\n file: SourceFile,\n serviceDir: string,\n): ExternalEndpoint[] {\n const out: ExternalEndpoint[] = []\n const seen = new Set<string>()\n const make = (topic: string, edgeType: 'PUBLISHES_TO' | 'CONSUMES_FROM'): void => {\n const key = `${edgeType}|${topic}`\n if (seen.has(key)) return\n seen.add(key)\n const line = lineOf(file.content, topic)\n out.push({\n infraId: infraId('kafka-topic', topic),\n name: topic,\n kind: 'kafka-topic',\n edgeType,\n evidence: {\n file: path.relative(serviceDir, file.path),\n line,\n snippet: snippet(file.content, line),\n },\n })\n }\n\n for (const { topic } of findAll(PRODUCER_TOPIC_RE, file.content)) make(topic, 'PUBLISHES_TO')\n for (const { topic } of findAll(CONSUMER_TOPIC_RE, file.content)) make(topic, 'CONSUMES_FROM')\n return out\n}\n","import path from 'node:path'\nimport { infraId } from '@neat.is/types'\nimport { lineOf, snippet, type ExternalEndpoint, type SourceFile } from './shared.js'\n\n// Redis URLs in source — `redis://host[:port]` or `rediss://...`. We only\n// catch literal strings; env-driven URLs go through the database parsers\n// (.env, ormconfig, etc.) and don't need a CALLS edge.\nconst REDIS_URL_RE = /redis(?:s)?:\\/\\/(?:[^@'\"`\\s]+@)?([^:/'\"`\\s]+)(?::(\\d+))?/g\n\nexport function redisEndpointsFromFile(\n file: SourceFile,\n serviceDir: string,\n): ExternalEndpoint[] {\n const out: ExternalEndpoint[] = []\n const seen = new Set<string>()\n REDIS_URL_RE.lastIndex = 0\n let m: RegExpExecArray | null\n while ((m = REDIS_URL_RE.exec(file.content)) !== null) {\n const host = m[1]!\n if (seen.has(host)) continue\n seen.add(host)\n const line = lineOf(file.content, host)\n out.push({\n infraId: infraId('redis', host),\n name: host,\n kind: 'redis',\n edgeType: 'CALLS',\n evidence: {\n file: path.relative(serviceDir, file.path),\n line,\n snippet: snippet(file.content, line),\n },\n })\n }\n return out\n}\n","import path from 'node:path'\nimport { infraId } from '@neat.is/types'\nimport { lineOf, snippet, type ExternalEndpoint, type SourceFile } from './shared.js'\n\n// AWS SDK v3 calls. We catch S3 (`Bucket: \"x\"` near a `S3Client`-using\n// PutObjectCommand / GetObjectCommand / DeleteObjectCommand) and DynamoDB\n// (`TableName: \"x\"` near GetCommand / PutCommand / DynamoDBClient). The\n// pattern is intentionally permissive: a literal Bucket/TableName near an\n// SDK constant is good enough evidence; misses are fine because non-static\n// resources can't be catalogued anyway.\nconst S3_BUCKET_RE = /Bucket\\s*:\\s*['\"`]([^'\"`]+)['\"`]/g\nconst DYNAMO_TABLE_RE = /TableName\\s*:\\s*['\"`]([^'\"`]+)['\"`]/g\n\nfunction hasMarker(text: string, markers: string[]): boolean {\n return markers.some((m) => text.includes(m))\n}\n\nfunction findAll(re: RegExp, text: string): { name: string; index: number }[] {\n re.lastIndex = 0\n const out: { name: string; index: number }[] = []\n let m: RegExpExecArray | null\n while ((m = re.exec(text)) !== null) {\n out.push({ name: m[1]!, index: m.index })\n }\n return out\n}\n\nexport function awsEndpointsFromFile(\n file: SourceFile,\n serviceDir: string,\n): ExternalEndpoint[] {\n const out: ExternalEndpoint[] = []\n const seen = new Set<string>()\n const make = (kind: string, name: string): void => {\n const key = `${kind}|${name}`\n if (seen.has(key)) return\n seen.add(key)\n const line = lineOf(file.content, name)\n out.push({\n infraId: infraId(kind, name),\n name,\n kind,\n edgeType: 'CALLS',\n evidence: {\n file: path.relative(serviceDir, file.path),\n line,\n snippet: snippet(file.content, line),\n },\n })\n }\n\n if (hasMarker(file.content, ['S3Client', 'PutObjectCommand', 'GetObjectCommand', 'DeleteObjectCommand'])) {\n for (const { name } of findAll(S3_BUCKET_RE, file.content)) make('s3-bucket', name)\n }\n if (\n hasMarker(file.content, [\n 'DynamoDBClient',\n 'DynamoDBDocumentClient',\n 'GetCommand',\n 'PutCommand',\n 'QueryCommand',\n 'UpdateCommand',\n 'DeleteCommand',\n ])\n ) {\n for (const { name } of findAll(DYNAMO_TABLE_RE, file.content)) make('dynamodb-table', name)\n }\n return out\n}\n","import path from 'node:path'\nimport { infraId } from '@neat.is/types'\nimport { lineOf, snippet, type ExternalEndpoint, type SourceFile } from './shared.js'\n\n// gRPC client construction in JS/TS:\n//\n// const client = new orders_proto.OrderService(...)\n// const client = new OrdersClient('orders.internal:50051', ...)\n//\n// We catch `new <Name>Client(...)` and `new <namespace>.<Name>Service(...)`\n// patterns and use the symbol name as the inferred service id. The address\n// argument, when statically resolvable, becomes the host hint on the\n// resulting CALLS edge — but resolution is best-effort.\nconst GRPC_CLIENT_RE = /new\\s+([A-Z][A-Za-z0-9_]*)Client\\s*\\(\\s*['\"`]?([^,'\"`)]+)?/g\n\nfunction isLikelyAddress(value: string | undefined): boolean {\n if (!value) return false\n return /:\\d{2,5}$/.test(value) || value.includes('.')\n}\n\nexport function grpcEndpointsFromFile(\n file: SourceFile,\n serviceDir: string,\n): ExternalEndpoint[] {\n const out: ExternalEndpoint[] = []\n const seen = new Set<string>()\n GRPC_CLIENT_RE.lastIndex = 0\n let m: RegExpExecArray | null\n while ((m = GRPC_CLIENT_RE.exec(file.content)) !== null) {\n const symbol = m[1]!\n const addr = m[2]?.trim()\n const name = isLikelyAddress(addr) ? addr! : symbol\n if (seen.has(name)) continue\n seen.add(name)\n const line = lineOf(file.content, m[0])\n out.push({\n infraId: infraId('grpc-service', name),\n name,\n kind: 'grpc-service',\n edgeType: 'CALLS',\n evidence: {\n file: path.relative(serviceDir, file.path),\n line,\n snippet: snippet(file.content, line),\n },\n })\n }\n return out\n}\n","import type { NeatGraph } from '../../graph.js'\nimport { type DiscoveredService } from '../shared.js'\nimport { addComposeInfra } from './docker-compose.js'\nimport { addDockerfileRuntimes } from './dockerfile.js'\nimport { addTerraformResources } from './terraform.js'\nimport { addK8sResources } from './k8s.js'\n\nexport interface InfraExtractResult {\n nodesAdded: number\n edgesAdded: number\n}\n\n// Phase 5 — infrastructure. Runs after services so RUNS_ON edges have a\n// ServiceNode to anchor on. Each sub-source contributes its own nodes/edges\n// independently; nothing here mutates ServiceNodes themselves.\nexport async function addInfra(\n graph: NeatGraph,\n scanPath: string,\n services: DiscoveredService[],\n): Promise<InfraExtractResult> {\n const compose = await addComposeInfra(graph, scanPath, services)\n const dockerfile = await addDockerfileRuntimes(graph, services, scanPath)\n const terraform = await addTerraformResources(graph, scanPath)\n const k8s = await addK8sResources(graph, scanPath)\n\n return {\n nodesAdded:\n compose.nodesAdded + dockerfile.nodesAdded + terraform.nodesAdded + k8s.nodesAdded,\n edgesAdded:\n compose.edgesAdded + dockerfile.edgesAdded + terraform.edgesAdded + k8s.edgesAdded,\n }\n}\n","import path from 'node:path'\nimport type { GraphEdge } from '@neat.is/types'\nimport { EdgeType, Provenance } from '@neat.is/types'\nimport type { NeatGraph } from '../../graph.js'\nimport { exists, makeEdgeId, readYaml, type DiscoveredService } from '../shared.js'\nimport { classifyImage, makeInfraNode } from './shared.js'\n\ninterface ComposeService {\n image?: string\n build?: string | { context?: string }\n depends_on?: string[] | Record<string, unknown>\n}\n\ninterface ComposeFile {\n services?: Record<string, ComposeService>\n}\n\nfunction dependsOnList(value: ComposeService['depends_on']): string[] {\n if (!value) return []\n if (Array.isArray(value)) return value\n return Object.keys(value)\n}\n\nfunction serviceNameToServiceNode(\n name: string,\n services: DiscoveredService[],\n): string | null {\n for (const s of services) {\n if (s.node.name === name || path.basename(s.dir) === name) return s.node.id\n }\n return null\n}\n\n// Project-level docker-compose.yml describes deployment topology. Each compose\n// service that is *not* one of the discovered ServiceNodes becomes an\n// InfraNode (databases, brokers, caches). depends_on lists become DEPENDS_ON\n// edges from the dependent to its dependency, regardless of whether the\n// endpoint is a ServiceNode or InfraNode — the edge itself is the deployment\n// fact, not the role.\nexport async function addComposeInfra(\n graph: NeatGraph,\n scanPath: string,\n services: DiscoveredService[],\n): Promise<{ nodesAdded: number; edgesAdded: number }> {\n let nodesAdded = 0\n let edgesAdded = 0\n\n let composePath: string | null = null\n for (const name of ['docker-compose.yml', 'docker-compose.yaml']) {\n const abs = path.join(scanPath, name)\n if (await exists(abs)) {\n composePath = abs\n break\n }\n }\n if (!composePath) return { nodesAdded, edgesAdded }\n\n const compose = await readYaml<ComposeFile>(composePath)\n if (!compose?.services) return { nodesAdded, edgesAdded }\n const evidenceFile = path.relative(scanPath, composePath).split(path.sep).join('/')\n\n const composeNameToNodeId = new Map<string, string>()\n for (const [composeName, svc] of Object.entries(compose.services)) {\n const matchedServiceId = serviceNameToServiceNode(composeName, services)\n if (matchedServiceId) {\n composeNameToNodeId.set(composeName, matchedServiceId)\n continue\n }\n const kind = svc.image ? classifyImage(svc.image) : 'container'\n const node = makeInfraNode(kind, composeName)\n if (!graph.hasNode(node.id)) {\n graph.addNode(node.id, node)\n nodesAdded++\n }\n composeNameToNodeId.set(composeName, node.id)\n }\n\n for (const [composeName, svc] of Object.entries(compose.services)) {\n const sourceId = composeNameToNodeId.get(composeName)\n if (!sourceId) continue\n for (const dep of dependsOnList(svc.depends_on)) {\n const targetId = composeNameToNodeId.get(dep)\n if (!targetId) continue\n const edgeId = makeEdgeId(sourceId, targetId, EdgeType.DEPENDS_ON)\n if (graph.hasEdge(edgeId)) continue\n const edge: GraphEdge = {\n id: edgeId,\n source: sourceId,\n target: targetId,\n type: EdgeType.DEPENDS_ON,\n provenance: Provenance.EXTRACTED,\n evidence: { file: evidenceFile },\n }\n graph.addEdgeWithKey(edgeId, edge.source, edge.target, edge)\n edgesAdded++\n }\n }\n\n return { nodesAdded, edgesAdded }\n}\n","import type { InfraNode } from '@neat.is/types'\nimport { NodeType, infraId } from '@neat.is/types'\n\n// ADR-010 reserves the `infra:` prefix; the kind segment lets traversal and\n// MCP tools sub-type without inventing a new top-level NodeType per source.\nexport function makeInfraNode(\n kind: string,\n name: string,\n provider = 'self',\n extras?: { region?: string },\n): InfraNode {\n return {\n id: infraId(kind, name),\n type: NodeType.InfraNode,\n name,\n provider,\n kind,\n ...(extras?.region ? { region: extras.region } : {}),\n }\n}\n\n// Stable kind for an image string like \"postgres:15-alpine\" or \"mysql:8\".\n// The image name itself ends up in the InfraNode `name` field; this function\n// only classifies what the image *is*, so callers can group similar runtimes.\nexport function classifyImage(image: string): string {\n const lower = image.toLowerCase()\n const repo = lower.split(':')[0]!\n const last = repo.split('/').pop() ?? repo\n if (last.startsWith('postgres')) return 'postgres'\n if (last.startsWith('mysql') || last.startsWith('mariadb')) return 'mysql'\n if (last.startsWith('mongo')) return 'mongodb'\n if (last.startsWith('redis')) return 'redis'\n if (last.startsWith('rabbitmq')) return 'rabbitmq'\n if (last.startsWith('kafka') || last.includes('kafka')) return 'kafka'\n if (last.startsWith('memcached')) return 'memcached'\n return 'container'\n}\n","import path from 'node:path'\nimport { promises as fs } from 'node:fs'\nimport type { GraphEdge } from '@neat.is/types'\nimport { EdgeType, Provenance } from '@neat.is/types'\nimport type { NeatGraph } from '../../graph.js'\nimport { exists, makeEdgeId, type DiscoveredService } from '../shared.js'\nimport { makeInfraNode } from './shared.js'\n\n// Pull the first non-`scratch` `FROM` line out of a Dockerfile, ignoring\n// multi-stage `as` aliases. Returns the image including tag (e.g. `node:20`,\n// `python:3.11-slim`). Multi-stage builds report the *runtime* image — the\n// last FROM that isn't aliasing a previous stage.\nfunction runtimeImage(content: string): string | null {\n const lines = content.split('\\n')\n let last: string | null = null\n for (const raw of lines) {\n const line = raw.trim()\n if (!line || line.startsWith('#')) continue\n if (!/^from\\s+/i.test(line)) continue\n const tokens = line.split(/\\s+/)\n const image = tokens[1]\n if (!image || image.toLowerCase() === 'scratch') continue\n last = image\n }\n return last\n}\n\n// For each ServiceNode that has a Dockerfile in its dir, emit a\n// `infra:container-image:<image>` InfraNode and a RUNS_ON edge from the\n// service to the image.\nexport async function addDockerfileRuntimes(\n graph: NeatGraph,\n services: DiscoveredService[],\n scanPath: string,\n): Promise<{ nodesAdded: number; edgesAdded: number }> {\n let nodesAdded = 0\n let edgesAdded = 0\n\n for (const service of services) {\n const dockerfilePath = path.join(service.dir, 'Dockerfile')\n if (!(await exists(dockerfilePath))) continue\n const content = await fs.readFile(dockerfilePath, 'utf8')\n const image = runtimeImage(content)\n if (!image) continue\n\n const node = makeInfraNode('container-image', image)\n if (!graph.hasNode(node.id)) {\n graph.addNode(node.id, node)\n nodesAdded++\n }\n\n const edgeId = makeEdgeId(service.node.id, node.id, EdgeType.RUNS_ON)\n if (!graph.hasEdge(edgeId)) {\n const edge: GraphEdge = {\n id: edgeId,\n source: service.node.id,\n target: node.id,\n type: EdgeType.RUNS_ON,\n provenance: Provenance.EXTRACTED,\n evidence: {\n file: path.relative(scanPath, dockerfilePath).split(path.sep).join('/'),\n },\n }\n graph.addEdgeWithKey(edgeId, edge.source, edge.target, edge)\n edgesAdded++\n }\n }\n\n return { nodesAdded, edgesAdded }\n}\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport type { NeatGraph } from '../../graph.js'\nimport { IGNORED_DIRS } from '../shared.js'\nimport { makeInfraNode } from './shared.js'\n\n// Light pass: catalogue `resource \"aws_*\" \"name\"` blocks in any *.tf file.\n// We don't interpret references — a real Terraform backend would resolve\n// those — but the resource-type/name pair is enough to register the node so\n// later cross-references can hang off it.\nconst RESOURCE_RE = /resource\\s+\"(aws_[A-Za-z0-9_]+)\"\\s+\"([A-Za-z0-9_-]+)\"/g\n\nasync function walkTfFiles(start: string, depth = 0, max = 5): Promise<string[]> {\n if (depth > max) return []\n const out: string[] = []\n const entries = await fs.readdir(start, { withFileTypes: true }).catch(() => [])\n for (const entry of entries) {\n if (entry.isDirectory()) {\n if (IGNORED_DIRS.has(entry.name) || entry.name === '.terraform') continue\n out.push(...(await walkTfFiles(path.join(start, entry.name), depth + 1, max)))\n } else if (entry.isFile() && entry.name.endsWith('.tf')) {\n out.push(path.join(start, entry.name))\n }\n }\n return out\n}\n\nexport async function addTerraformResources(\n graph: NeatGraph,\n scanPath: string,\n): Promise<{ nodesAdded: number; edgesAdded: number }> {\n let nodesAdded = 0\n const files = await walkTfFiles(scanPath)\n for (const file of files) {\n const content = await fs.readFile(file, 'utf8')\n RESOURCE_RE.lastIndex = 0\n let m: RegExpExecArray | null\n while ((m = RESOURCE_RE.exec(content)) !== null) {\n const kind = m[1]!\n const name = m[2]!\n const node = makeInfraNode(kind, name, 'aws')\n if (!graph.hasNode(node.id)) {\n graph.addNode(node.id, node)\n nodesAdded++\n }\n }\n }\n return { nodesAdded, edgesAdded: 0 }\n}\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport { parseAllDocuments } from 'yaml'\nimport type { NeatGraph } from '../../graph.js'\nimport { CONFIG_FILE_EXTENSIONS, IGNORED_DIRS } from '../shared.js'\nimport { makeInfraNode } from './shared.js'\n\ninterface K8sDoc {\n kind?: string\n metadata?: { name?: string; namespace?: string }\n}\n\nconst K8S_KIND_TO_INFRA_KIND: Record<string, string> = {\n Service: 'k8s-service',\n Deployment: 'k8s-deployment',\n StatefulSet: 'k8s-statefulset',\n DaemonSet: 'k8s-daemonset',\n CronJob: 'k8s-cronjob',\n Job: 'k8s-job',\n Ingress: 'k8s-ingress',\n}\n\nasync function walkYamlFiles(start: string, depth = 0, max = 5): Promise<string[]> {\n if (depth > max) return []\n const out: string[] = []\n const entries = await fs.readdir(start, { withFileTypes: true }).catch(() => [])\n for (const entry of entries) {\n if (entry.isDirectory()) {\n if (IGNORED_DIRS.has(entry.name)) continue\n out.push(...(await walkYamlFiles(path.join(start, entry.name), depth + 1, max)))\n } else if (entry.isFile() && CONFIG_FILE_EXTENSIONS.has(path.extname(entry.name))) {\n out.push(path.join(start, entry.name))\n }\n }\n return out\n}\n\n// Multi-document YAML with kind/metadata.name. We keep the matching simple:\n// any file whose first doc looks k8s-shaped. The match is on `kind` only —\n// random YAML configs (db-config.yaml, etc.) are usually flat objects with no\n// `kind` field, so they're ignored without false positives.\nexport async function addK8sResources(\n graph: NeatGraph,\n scanPath: string,\n): Promise<{ nodesAdded: number; edgesAdded: number }> {\n let nodesAdded = 0\n const files = await walkYamlFiles(scanPath)\n for (const file of files) {\n const content = await fs.readFile(file, 'utf8')\n let docs: K8sDoc[]\n try {\n docs = parseAllDocuments(content).map((d) => d.toJSON() as K8sDoc)\n } catch {\n continue\n }\n for (const doc of docs) {\n if (!doc?.kind || !doc.metadata?.name) continue\n const infraKind = K8S_KIND_TO_INFRA_KIND[doc.kind]\n if (!infraKind) continue\n const namespaced = doc.metadata.namespace\n ? `${doc.metadata.namespace}/${doc.metadata.name}`\n : doc.metadata.name\n const node = makeInfraNode(infraKind, namespaced, 'kubernetes')\n if (!graph.hasNode(node.id)) {\n graph.addNode(node.id, node)\n nodesAdded++\n }\n }\n }\n return { nodesAdded, edgesAdded: 0 }\n}\n","import { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport type { NeatGraph } from './graph.js'\n\nconst SCHEMA_VERSION = 2\n\ninterface PersistedGraph {\n schemaVersion: number\n exportedAt: string\n graph: ReturnType<NeatGraph['export']>\n}\n\n// v1 → v2: ServiceNode shed `pgDriverVersion` (ADR-019). Compat traversal reads\n// `dependencies[driver]` instead. Strip the field from any v1 snapshot rather\n// than hard-failing — a stale snapshot on disk shouldn't cost a re-extract.\nfunction migrateV1ToV2(payload: PersistedGraph): PersistedGraph {\n const nodes = (payload.graph as { nodes?: Array<{ attributes?: Record<string, unknown> }> })\n .nodes\n if (Array.isArray(nodes)) {\n for (const node of nodes) {\n if (node.attributes && 'pgDriverVersion' in node.attributes) {\n delete node.attributes.pgDriverVersion\n }\n }\n }\n return { ...payload, schemaVersion: 2 }\n}\n\nasync function ensureDir(filePath: string): Promise<void> {\n await fs.mkdir(path.dirname(filePath), { recursive: true })\n}\n\nexport async function saveGraphToDisk(graph: NeatGraph, outPath: string): Promise<void> {\n await ensureDir(outPath)\n const payload: PersistedGraph = {\n schemaVersion: SCHEMA_VERSION,\n exportedAt: new Date().toISOString(),\n graph: graph.export(),\n }\n // Atomic write: drop into <name>.tmp first, then rename. A crash mid-write\n // leaves the previous snapshot intact instead of a half-truncated file.\n const tmp = `${outPath}.tmp`\n await fs.writeFile(tmp, JSON.stringify(payload), 'utf8')\n await fs.rename(tmp, outPath)\n}\n\nexport async function loadGraphFromDisk(graph: NeatGraph, outPath: string): Promise<void> {\n let raw: string\n try {\n raw = await fs.readFile(outPath, 'utf8')\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return\n throw err\n }\n let payload = JSON.parse(raw) as PersistedGraph\n if (payload.schemaVersion === 1) {\n payload = migrateV1ToV2(payload)\n }\n if (payload.schemaVersion !== SCHEMA_VERSION) {\n throw new Error(\n `persist: unsupported snapshot schemaVersion ${payload.schemaVersion} (expected ${SCHEMA_VERSION})`,\n )\n }\n graph.clear()\n graph.import(payload.graph)\n}\n\n// Periodic save + best-effort save on SIGTERM/SIGINT. Returns a cleanup that\n// clears the interval and unhooks the signal handlers — important for tests so\n// they don't keep the process alive.\nexport function startPersistLoop(\n graph: NeatGraph,\n outPath: string,\n intervalMs = 60_000,\n): () => void {\n let stopped = false\n\n const tick = async (): Promise<void> => {\n if (stopped) return\n try {\n await saveGraphToDisk(graph, outPath)\n } catch (err) {\n console.error('persist: periodic save failed', err)\n }\n }\n\n const interval = setInterval(() => {\n void tick()\n }, intervalMs)\n\n const onSignal = (signal: NodeJS.Signals): void => {\n void (async () => {\n try {\n await saveGraphToDisk(graph, outPath)\n } catch (err) {\n console.error(`persist: ${signal} save failed`, err)\n } finally {\n process.exit(0)\n }\n })()\n }\n\n process.on('SIGTERM', onSignal)\n process.on('SIGINT', onSignal)\n\n return () => {\n stopped = true\n clearInterval(interval)\n process.off('SIGTERM', onSignal)\n process.off('SIGINT', onSignal)\n }\n}\n","import path from 'node:path'\nimport chokidar, { type FSWatcher } from 'chokidar'\nimport type { FastifyInstance } from 'fastify'\nimport type { NeatGraph } from './graph.js'\nimport { buildApi } from './api.js'\nimport { ensureCompatLoaded } from './compat.js'\nimport { discoverServices, addServiceNodes } from './extract/services.js'\nimport { addServiceAliases } from './extract/aliases.js'\nimport { addDatabasesAndCompat } from './extract/databases/index.js'\nimport { addConfigNodes } from './extract/configs.js'\nimport { addCallEdges } from './extract/calls/index.js'\nimport { addInfra } from './extract/infra/index.js'\nimport { retireEdgesByFile } from './extract/retire.js'\nimport {\n makeErrorSpanWriter,\n makeSpanHandler,\n promoteFrontierNodes,\n startStalenessLoop,\n} from './ingest.js'\nimport {\n evaluateAllPolicies,\n loadPolicyFile,\n PolicyViolationsLog,\n} from './policy.js'\nimport type { Policy } from '@neat.is/types'\nimport { buildOtelReceiver } from './otel.js'\nimport { startOtelGrpcReceiver } from './otel-grpc.js'\nimport { loadGraphFromDisk, startPersistLoop } from './persist.js'\nimport { buildSearchIndex, type SearchIndex } from './search.js'\nimport { DEFAULT_PROJECT } from './graph.js'\nimport { Projects, pathsForProject } from './projects.js'\n\nexport type ExtractPhase =\n | 'services'\n | 'aliases'\n | 'databases'\n | 'configs'\n | 'calls'\n | 'infra'\n\nconst ALL_PHASES: ExtractPhase[] = [\n 'services',\n 'aliases',\n 'databases',\n 'configs',\n 'calls',\n 'infra',\n]\n\n// Map a changed path to the phases that need re-running. Anything not matched\n// here falls back to a full re-extract — better an extra ~50ms of work than a\n// missed update because the path didn't fit a regex.\n//\n// Mapping:\n// package.json / requirements.txt / pyproject.toml → services + aliases + databases\n// (deps drive compat; aliases pull from manifest fields)\n// .env / *.env.* / prisma / knex / ormconfig → databases + configs\n// docker-compose / Dockerfile / *.tf / k8s yaml → infra + aliases\n// (compose labels and Dockerfile labels feed alias discovery)\n// *.js / *.ts / *.tsx / *.py / *.jsx / *.mjs / *.cjs → calls\n// *.yaml / *.yml that isn't compose → databases + configs (ORM yaml fallbacks)\nexport function classifyChange(relPath: string): Set<ExtractPhase> {\n const phases = new Set<ExtractPhase>()\n const base = path.basename(relPath).toLowerCase()\n const segments = relPath.split(path.sep).map((s) => s.toLowerCase())\n\n if (\n base === 'package.json' ||\n base === 'requirements.txt' ||\n base === 'pyproject.toml' ||\n base === 'setup.py'\n ) {\n phases.add('services')\n phases.add('aliases')\n phases.add('databases')\n }\n\n if (\n base === '.env' ||\n base.startsWith('.env.') ||\n base === 'schema.prisma' ||\n /^knexfile\\.(?:js|ts|cjs|mjs)$/.test(base) ||\n /^ormconfig\\.(?:js|ts|json|ya?ml)$/.test(base)\n ) {\n phases.add('databases')\n phases.add('configs')\n }\n\n if (\n base === 'dockerfile' ||\n /^docker-compose.*\\.ya?ml$/.test(base) ||\n base.endsWith('.tf') ||\n segments.includes('k8s') ||\n segments.includes('kustomize') ||\n segments.includes('manifests')\n ) {\n phases.add('infra')\n phases.add('aliases')\n }\n\n if (/\\.(?:js|jsx|mjs|cjs|ts|tsx|py)$/.test(base)) {\n phases.add('calls')\n }\n\n if (/\\.ya?ml$/.test(base) && !/^docker-compose.*\\.ya?ml$/.test(base)) {\n // Generic yaml — could be an ORM file, k8s manifest, or random config.\n // Cheap to run databases + configs; if it was infra, the dir-name check\n // above already added that phase.\n phases.add('databases')\n phases.add('configs')\n }\n\n return phases\n}\n\ninterface RunPhasesResult {\n phases: ExtractPhase[]\n nodesAdded: number\n edgesAdded: number\n frontiersPromoted: number\n durationMs: number\n}\n\nexport async function runExtractPhases(\n graph: NeatGraph,\n scanPath: string,\n phases: Set<ExtractPhase>,\n): Promise<RunPhasesResult> {\n const started = Date.now()\n await ensureCompatLoaded()\n // Discovery is cheap and every phase needs the same DiscoveredService list,\n // so we always re-walk. If the user moved a service directory, this is also\n // the path that picks it up.\n const services = await discoverServices(scanPath)\n\n let nodesAdded = 0\n let edgesAdded = 0\n\n if (phases.has('services')) {\n nodesAdded += addServiceNodes(graph, services)\n }\n if (phases.has('aliases')) {\n await addServiceAliases(graph, scanPath, services)\n }\n if (phases.has('databases')) {\n const r = await addDatabasesAndCompat(graph, services, scanPath)\n nodesAdded += r.nodesAdded\n edgesAdded += r.edgesAdded\n }\n if (phases.has('configs')) {\n const r = await addConfigNodes(graph, services, scanPath)\n nodesAdded += r.nodesAdded\n edgesAdded += r.edgesAdded\n }\n if (phases.has('calls')) {\n const r = await addCallEdges(graph, services)\n nodesAdded += r.nodesAdded\n edgesAdded += r.edgesAdded\n }\n if (phases.has('infra')) {\n const r = await addInfra(graph, scanPath, services)\n nodesAdded += r.nodesAdded\n edgesAdded += r.edgesAdded\n }\n const frontiersPromoted = promoteFrontierNodes(graph)\n\n return {\n phases: ALL_PHASES.filter((p) => phases.has(p)),\n nodesAdded,\n edgesAdded,\n frontiersPromoted,\n durationMs: Date.now() - started,\n }\n}\n\nexport interface WatchOptions {\n scanPath: string\n outPath: string\n errorsPath: string\n staleEventsPath: string\n embeddingsCachePath?: string\n // Project name this watch instance owns. Defaults to `default` for the\n // single-project workflow that's been the only one until #83.\n project?: string\n host?: string\n port?: number\n otelPort?: number\n otelGrpc?: boolean\n otelGrpcPort?: number\n debounceMs?: number\n}\n\nexport interface WatchHandle {\n api: FastifyInstance\n stop: () => Promise<void>\n}\n\nconst IGNORED_WATCH_PATHS = [\n /(?:^|[\\\\/])node_modules[\\\\/]/,\n /(?:^|[\\\\/])\\.git[\\\\/]/,\n /(?:^|[\\\\/])dist[\\\\/]/,\n /(?:^|[\\\\/])build[\\\\/]/,\n /(?:^|[\\\\/])\\.turbo[\\\\/]/,\n /(?:^|[\\\\/])\\.next[\\\\/]/,\n /(?:^|[\\\\/])neat-out[\\\\/]/,\n /[\\\\/]?\\.DS_Store$/,\n]\n\nfunction shouldIgnore(absPath: string): boolean {\n return IGNORED_WATCH_PATHS.some((re) => re.test(absPath))\n}\n\nexport async function startWatch(\n graph: NeatGraph,\n opts: WatchOptions,\n): Promise<WatchHandle> {\n const debounceMs = opts.debounceMs ?? 1000\n\n await loadGraphFromDisk(graph, opts.outPath)\n\n // Load policies + open the violations log once at startup. policy.json\n // lives at the project root per ADR-042 §File location; absent file is\n // a perfectly fine state (loadPolicyFile returns []). Reload-on-change\n // is queued for v0.2.5 — the kickoff doc tracks it.\n const policyFilePath = path.join(opts.scanPath, 'policy.json')\n const policyViolationsPath = path.join(path.dirname(opts.outPath), 'policy-violations.ndjson')\n let policies: Policy[] = []\n try {\n policies = await loadPolicyFile(policyFilePath)\n if (policies.length > 0) {\n console.log(`policies: loaded ${policies.length} from ${policyFilePath}`)\n }\n } catch (err) {\n console.warn(`policies: failed to load ${policyFilePath} — ${(err as Error).message}`)\n }\n const policyLog = new PolicyViolationsLog(policyViolationsPath)\n\n // Single shared trigger callback wired into post-ingest, post-extract, and\n // post-stale per ADR-043. Failures append to console.warn but don't kill\n // the daemon — a malformed evaluator shouldn't take down ingest.\n const onPolicyTrigger = async (g: NeatGraph): Promise<void> => {\n if (policies.length === 0) return\n try {\n const violations = evaluateAllPolicies(g, policies, { now: () => Date.now() })\n for (const v of violations) await policyLog.append(v)\n } catch (err) {\n console.warn(`policies: evaluation failed — ${(err as Error).message}`)\n }\n }\n\n // The post-extract trigger fires from extractFromDirectory via opts.\n // For the initial extract here we run it inline so violations land on\n // startup before the receiver opens. Subsequent watch-driven re-extract\n // passes go through runExtractPhases which doesn't take the hook directly\n // — we run it after each flush() instead.\n const initial = await runExtractPhases(graph, opts.scanPath, new Set(ALL_PHASES))\n console.log(\n `extract: ${initial.nodesAdded} new nodes, ${initial.edgesAdded} new edges (graph total ${graph.order}/${graph.size})`,\n )\n await onPolicyTrigger(graph)\n\n const stopPersist = startPersistLoop(graph, opts.outPath)\n const stopStaleness = startStalenessLoop(graph, {\n staleEventsPath: opts.staleEventsPath,\n onPolicyTrigger,\n })\n\n const host = opts.host ?? '0.0.0.0'\n const port = opts.port ?? 8080\n const otelPort = opts.otelPort ?? 4318\n\n const cachePath =\n opts.embeddingsCachePath ?? path.join(path.dirname(opts.outPath), 'embeddings.json')\n let searchIndex: SearchIndex | undefined\n try {\n searchIndex = await buildSearchIndex(graph, { cachePath })\n console.log(`semantic_search: ${searchIndex.provider} provider`)\n } catch (err) {\n console.warn(\n `semantic_search: index build failed (${(err as Error).message}); falling back to inline substring`,\n )\n }\n\n const projectName = opts.project ?? DEFAULT_PROJECT\n const registry = new Projects()\n registry.set(projectName, {\n graph,\n scanPath: opts.scanPath,\n paths: {\n // Paths are derived from the explicit options the watch caller passes\n // — pathsForProject is only used to fill in the embeddings/snapshot\n // fields so the registry shape is complete.\n ...pathsForProject(projectName, path.dirname(opts.outPath)),\n snapshotPath: opts.outPath,\n errorsPath: opts.errorsPath,\n staleEventsPath: opts.staleEventsPath,\n },\n searchIndex,\n })\n\n const api = await buildApi({ projects: registry })\n await api.listen({ port, host })\n console.log(`neat-core listening on http://${host}:${port}`)\n console.log(` scan path: ${opts.scanPath} (watching for changes)`)\n console.log(` snapshot path: ${opts.outPath}`)\n console.log(` errors log: ${opts.errorsPath}`)\n\n // The receiver writes ErrorEvents synchronously before reply (durability).\n // makeSpanHandler runs on the async queue and skips the inline write\n // because the receiver already handled it. Ad-hoc callers that bypass the\n // receiver (CLI tests, fixtures) leave writeErrorEventInline at its default\n // and get the in-handleSpan write. ADR-033 §Error events.\n const onSpan = makeSpanHandler({\n graph,\n errorsPath: opts.errorsPath,\n writeErrorEventInline: false,\n onPolicyTrigger,\n })\n const onErrorSpanSync = makeErrorSpanWriter(opts.errorsPath)\n const otelHttp = await buildOtelReceiver({ onSpan, onErrorSpanSync })\n await otelHttp.listen({ port: otelPort, host })\n console.log(`neat-core OTLP receiver on http://${host}:${otelPort}/v1/traces`)\n\n let grpcReceiver: { stop: () => Promise<void> } | null = null\n if (opts.otelGrpc) {\n const grpcPort = opts.otelGrpcPort ?? 4317\n // gRPC handler keeps the inline ErrorEvent write — the gRPC receiver\n // awaits onSpan synchronously (otel-grpc.ts), so the same durability\n // guarantee is met without a separate sync hook. Non-blocking gRPC\n // ingest is out of scope for the v0.2.2 batch.\n const onSpanGrpc = makeSpanHandler({\n graph,\n errorsPath: opts.errorsPath,\n onPolicyTrigger,\n })\n const r = await startOtelGrpcReceiver({ onSpan: onSpanGrpc, host, port: grpcPort })\n console.log(`neat-core OTLP/gRPC receiver on ${r.address}`)\n grpcReceiver = r\n }\n\n // Coalesce bursts of changes into a single re-extract. chokidar fires one\n // event per affected path; an editor save can produce 3+ events on the same\n // file in <50ms.\n const pending = new Set<ExtractPhase>()\n const pendingPaths = new Set<string>()\n let timer: NodeJS.Timeout | null = null\n let inflight: Promise<void> | null = null\n\n const flush = async (): Promise<void> => {\n if (pending.size === 0) return\n const phases = new Set(pending)\n const paths = new Set(pendingPaths)\n pending.clear()\n pendingPaths.clear()\n try {\n // Drop EXTRACTED edges keyed to changed paths first, so the producer's\n // idempotent re-extract recreates only the edges that still apply.\n // Without this, edges from deleted code would survive forever\n // (docs/contracts/static-extraction.md §Ghost-edge cleanup).\n let retired = 0\n for (const p of paths) retired += retireEdgesByFile(graph, p)\n const result = await runExtractPhases(graph, opts.scanPath, phases)\n console.log(\n `[watch] re-extract phases=${result.phases.join(',')} retired=${retired} +${result.nodesAdded}n/+${result.edgesAdded}e in ${result.durationMs}ms`,\n )\n if (searchIndex) {\n try {\n await searchIndex.refresh(graph)\n } catch (err) {\n console.warn('[watch] semantic_search refresh failed', err)\n }\n }\n // Post-extract policy trigger (ADR-043). The runExtractPhases call\n // doesn't take the hook directly — it runs through promoteFrontierNodes\n // for FRONTIER → OBSERVED upgrades but doesn't load policies itself.\n // Firing the evaluator here keeps the trigger surface symmetric across\n // ingest / extract / stale paths.\n await onPolicyTrigger(graph)\n } catch (err) {\n console.error('[watch] re-extract failed', err)\n }\n }\n\n const schedule = (): void => {\n if (timer) clearTimeout(timer)\n timer = setTimeout(() => {\n timer = null\n // Serialise re-extracts so two flushes can't interleave on the graph.\n inflight = (inflight ?? Promise.resolve()).then(flush)\n }, debounceMs)\n }\n\n const onPath = (absPath: string): void => {\n if (shouldIgnore(absPath)) return\n const rel = path.relative(opts.scanPath, absPath)\n if (!rel || rel.startsWith('..')) return\n pendingPaths.add(rel.split(path.sep).join('/'))\n const phases = classifyChange(rel)\n if (phases.size === 0) {\n // Unknown file kind — fall back to full re-extract rather than silently\n // miss it. Cheaper than the user wondering why their change didn't show.\n for (const p of ALL_PHASES) pending.add(p)\n } else {\n for (const p of phases) pending.add(p)\n }\n schedule()\n }\n\n const watcher: FSWatcher = chokidar.watch(opts.scanPath, {\n ignoreInitial: true,\n ignored: (p) => shouldIgnore(p),\n persistent: true,\n awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 },\n })\n watcher.on('add', onPath)\n watcher.on('change', onPath)\n watcher.on('unlink', onPath)\n watcher.on('addDir', onPath)\n watcher.on('unlinkDir', onPath)\n\n let stopped = false\n const stop = async (): Promise<void> => {\n if (stopped) return\n stopped = true\n if (timer) clearTimeout(timer)\n timer = null\n if (inflight) {\n try {\n await inflight\n } catch {\n // surfaced already in flush()\n }\n }\n await watcher.close()\n stopStaleness()\n stopPersist()\n await api.close()\n await otelHttp.close()\n if (grpcReceiver) await grpcReceiver.stop()\n }\n\n return { api, stop }\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 { PoliciesCheckBodySchema, PolicySeveritySchema } from '@neat.is/types'\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'\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 scope.get<{ Params: { project?: string } }>('/health', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n return {\n uptime: Math.floor((Date.now() - startedAt) / 1000),\n project: proj.name,\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 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; id: string }\n Querystring: { depth?: string }\n }>('/graph/node/:id/dependencies', 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 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, id, depth)\n })\n\n scope.get<{ Params: { project?: string } }>('/incidents', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const epath = errorsPathFor(proj)\n if (!epath) return []\n return readErrorEvents(epath)\n })\n\n scope.get<{\n Params: { project?: string }\n Querystring: { limit?: string; edgeType?: string }\n }>('/incidents/stale', async (req, reply) => {\n const proj = resolveProject(registry, req, reply)\n if (!proj) return\n const spath = staleEventsPathFor(proj)\n if (!spath) return []\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 limit = req.query.limit ? Number(req.query.limit) : 50\n return ordered.slice(0, Number.isFinite(limit) && limit > 0 ? limit : 50)\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 []\n const events = await readErrorEvents(epath)\n return events.filter(\n (e) =>\n e.affectedNode === nodeId || e.service === nodeId.replace(/^service:/, ''),\n )\n },\n )\n\n scope.get<{\n Params: { project?: string; nodeId: string }\n Querystring: { errorId?: string }\n }>('/traverse/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 }>('/traverse/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 // Top-level discovery — only meaningful at the root.\n app.get('/projects', async () => ({\n projects: registry.list().map((name) => {\n const proj = registry.get(name) as ProjectContext\n return {\n name,\n nodeCount: proj.graph.order,\n edgeCount: proj.graph.size,\n scanPath: proj.scanPath,\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","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","// Project registry — owns the per-project state that lives alongside the\n// graph map: snapshot/error/stale paths, scan path, optional search index.\n//\n// Routes use it via `resolve(project)`. Server / watch construct it once at\n// boot and pass it to buildApi. Tests can mock it with a small literal.\n\nimport path from 'node:path'\nimport type { NeatGraph } from './graph.js'\nimport { DEFAULT_PROJECT, getGraph } from './graph.js'\nimport type { SearchIndex } from './search.js'\n\nexport interface ProjectPaths {\n snapshotPath: string\n errorsPath: string\n staleEventsPath: string\n embeddingsCachePath: string\n // Policy-violations log per ADR-041 § Append-only ndjson sidecars. Lives\n // in the same neat-out directory as the other ndjson sidecars; daemons\n // wire PolicyViolationsLog to it.\n policyViolationsPath: string\n}\n\n// Default project keeps the legacy filenames so existing M5 / β / γ users\n// see no behaviour change. Named projects fan out by name (ADR-026).\nexport function pathsForProject(project: string, baseDir: string): ProjectPaths {\n if (project === DEFAULT_PROJECT) {\n return {\n snapshotPath: path.join(baseDir, 'graph.json'),\n errorsPath: path.join(baseDir, 'errors.ndjson'),\n staleEventsPath: path.join(baseDir, 'stale-events.ndjson'),\n embeddingsCachePath: path.join(baseDir, 'embeddings.json'),\n policyViolationsPath: path.join(baseDir, 'policy-violations.ndjson'),\n }\n }\n return {\n snapshotPath: path.join(baseDir, `${project}.json`),\n errorsPath: path.join(baseDir, `errors.${project}.ndjson`),\n staleEventsPath: path.join(baseDir, `stale-events.${project}.ndjson`),\n embeddingsCachePath: path.join(baseDir, `embeddings.${project}.json`),\n policyViolationsPath: path.join(baseDir, `policy-violations.${project}.ndjson`),\n }\n}\n\nexport interface ProjectContext {\n name: string\n graph: NeatGraph\n scanPath?: string\n paths: ProjectPaths\n searchIndex?: SearchIndex\n}\n\nexport class Projects {\n private contexts = new Map<string, ProjectContext>()\n\n upsert(ctx: ProjectContext): void {\n this.contexts.set(ctx.name, ctx)\n }\n\n set(\n name: string,\n init: Omit<ProjectContext, 'name' | 'graph'> & { graph?: NeatGraph },\n ): ProjectContext {\n const ctx: ProjectContext = {\n name,\n graph: init.graph ?? getGraph(name),\n scanPath: init.scanPath,\n paths: init.paths,\n searchIndex: init.searchIndex,\n }\n this.contexts.set(name, ctx)\n return ctx\n }\n\n get(name: string): ProjectContext | undefined {\n return this.contexts.get(name)\n }\n\n has(name: string): boolean {\n return this.contexts.has(name)\n }\n\n list(): string[] {\n return [...this.contexts.keys()].sort()\n }\n\n attachSearchIndex(name: string, index: SearchIndex | undefined): void {\n const ctx = this.contexts.get(name)\n if (ctx) ctx.searchIndex = index\n }\n}\n\n// Parses NEAT_PROJECTS=a,b,c; trims whitespace, drops empty entries.\n// `default` is implicit (always loaded), so callers usually filter it out\n// before iterating extra projects.\nexport function parseExtraProjects(raw: string | undefined): string[] {\n if (!raw) return []\n return raw\n .split(',')\n .map((p) => p.trim())\n .filter((p) => p.length > 0 && p !== DEFAULT_PROJECT)\n}\n","import type { GraphEdge } from '@neat.is/types'\nimport { Provenance } from '@neat.is/types'\nimport type { NeatGraph } from '../graph.js'\n\n// Drop every EXTRACTED edge whose evidence.file matches the given path.\n// Called from watch.ts before re-running an extract phase, so the producer's\n// idempotent re-write recreates only the edges that still apply. Edges from\n// the deleted code stay deleted. See docs/contracts/static-extraction.md\n// §Ghost-edge cleanup. Mutation authority lives under extract/* per\n// ADR-030, so the dropEdge call must happen here, not in watch.ts.\nexport function retireEdgesByFile(graph: NeatGraph, file: string): number {\n const normalized = file.split('\\\\').join('/')\n const toDrop: string[] = []\n graph.forEachEdge((id, attrs) => {\n const edge = attrs as GraphEdge\n if (edge.provenance !== Provenance.EXTRACTED) return\n if (!edge.evidence?.file) return\n if (edge.evidence.file === normalized) toDrop.push(id)\n })\n for (const id of toDrop) graph.dropEdge(id)\n return toDrop.length\n}\n","// semantic_search — embedding-based node retrieval with a three-tier\n// fallback chain. The chain is settled in ADR-025; this file is the\n// implementation. Public API:\n//\n// buildSearchIndex(graph, opts) → SearchIndex\n// SearchIndex.search(query, limit) → { provider, matches }\n// SearchIndex.refresh(graph) → re-embeds new/changed nodes,\n// drops vanished ones\n//\n// The `/search` route in api.ts holds a single SearchIndex, refreshing it\n// after any extraction. MCP's `semantic_search` tool reads the same shape.\n\nimport { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport { createHash } from 'node:crypto'\nimport type { GraphNode } from '@neat.is/types'\nimport type { NeatGraph } from './graph.js'\n\nexport interface ScoredNode {\n node: GraphNode\n score: number\n}\n\nexport interface SearchResponse {\n query: string\n provider: 'ollama' | 'transformers' | 'substring'\n matches: ScoredNode[]\n}\n\nexport interface SearchIndex {\n readonly provider: SearchResponse['provider']\n search(query: string, limit?: number): Promise<SearchResponse>\n refresh(graph: NeatGraph): Promise<void>\n}\n\ninterface Embedder {\n provider: 'ollama' | 'transformers'\n model: string\n dim: number\n embed(texts: string[]): Promise<Float32Array[]>\n}\n\nconst DEFAULT_LIMIT = 10\nconst NOMIC_DIM = 768\nconst MINI_LM_DIM = 384\n\n// FrontierNodes are noise by design (placeholders that should disappear).\n// Embedding them would just clutter results.\nfunction shouldEmbed(node: GraphNode): boolean {\n return node.type !== 'FrontierNode'\n}\n\n// Deterministic per-node text. Stable keys let the cache hit across\n// extractions when nothing material changed.\nexport function embedText(node: GraphNode): string {\n const parts: string[] = [node.id]\n const name = (node as { name?: string }).name\n if (name) parts.push(name)\n switch (node.type) {\n case 'ServiceNode': {\n const lang = (node as { language?: string }).language\n if (lang) parts.push(`language=${lang}`)\n break\n }\n case 'DatabaseNode': {\n const eng = (node as { engine?: string }).engine\n const ver = (node as { engineVersion?: string }).engineVersion\n if (eng) parts.push(`engine=${eng}`)\n if (ver) parts.push(`engineVersion=${ver}`)\n break\n }\n case 'InfraNode': {\n const kind = (node as { kind?: string }).kind\n if (kind) parts.push(`kind=${kind}`)\n break\n }\n case 'ConfigNode': {\n const filePath = (node as { path?: string }).path\n if (filePath) parts.push(`path=${filePath}`)\n break\n }\n default:\n break\n }\n return parts.join(' ')\n}\n\nfunction attrsHash(node: GraphNode): string {\n return createHash('sha1').update(embedText(node)).digest('hex').slice(0, 16)\n}\n\nexport function cosine(a: Float32Array, b: Float32Array): number {\n if (a.length !== b.length) return 0\n let dot = 0\n let na = 0\n let nb = 0\n for (let i = 0; i < a.length; i++) {\n const ai = a[i] ?? 0\n const bi = b[i] ?? 0\n dot += ai * bi\n na += ai * ai\n nb += bi * bi\n }\n if (na === 0 || nb === 0) return 0\n return dot / (Math.sqrt(na) * Math.sqrt(nb))\n}\n\n// ---------------------------------------------------------------- Embedders\n\nfunction ollamaHost(): string | null {\n return process.env.OLLAMA_HOST ?? null\n}\n\nasync function ollamaReachable(host: string): Promise<boolean> {\n try {\n const res = await fetch(`${host.replace(/\\/$/, '')}/api/tags`, {\n signal: AbortSignal.timeout(500),\n })\n return res.ok\n } catch {\n return false\n }\n}\n\nfunction makeOllamaEmbedder(host: string, model = 'nomic-embed-text'): Embedder {\n const root = host.replace(/\\/$/, '')\n return {\n provider: 'ollama',\n model,\n dim: NOMIC_DIM,\n async embed(texts: string[]): Promise<Float32Array[]> {\n const out: Float32Array[] = []\n // Ollama's /api/embeddings is one-text-per-request. ≤10K nodes × ~30ms\n // each is fine for a one-shot index build; if it ever isn't, the API\n // also accepts batched input on /api/embed (newer routes).\n for (const text of texts) {\n const res = await fetch(`${root}/api/embeddings`, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ model, prompt: text }),\n })\n if (!res.ok) {\n throw new Error(`ollama embeddings: ${res.status} ${res.statusText}`)\n }\n const data = (await res.json()) as { embedding: number[] }\n out.push(Float32Array.from(data.embedding))\n }\n return out\n },\n }\n}\n\ninterface XenovaPipeline {\n (text: string | string[], options?: { pooling?: string; normalize?: boolean }): Promise<{\n data: Float32Array\n }>\n}\n\nasync function makeTransformersEmbedder(): Promise<Embedder | null> {\n let pipelineFn: ((task: string, model: string) => Promise<XenovaPipeline>) | null = null\n try {\n // Lazy require so server.ts boot doesn't pay the WASM init cost when\n // Ollama is available. The package is heavy — only load it on demand.\n // The package is optional so its types may not be installed in every\n // environment. Use a dynamic specifier so tsc keeps the import dynamic\n // and doesn't try to resolve types at build time.\n const specifier = '@xenova/transformers'\n const mod = (await import(specifier)) as unknown as {\n pipeline: (task: string, model: string) => Promise<XenovaPipeline>\n }\n pipelineFn = mod.pipeline\n } catch {\n return null\n }\n if (!pipelineFn) return null\n const model = 'Xenova/all-MiniLM-L6-v2'\n const extractor = await pipelineFn('feature-extraction', model)\n return {\n provider: 'transformers',\n model,\n dim: MINI_LM_DIM,\n async embed(texts: string[]): Promise<Float32Array[]> {\n const out: Float32Array[] = []\n for (const text of texts) {\n // Mean-pooled, L2-normalized → cosine reduces to dot product but\n // we keep the explicit cosine() for clarity.\n const result = await extractor(text, { pooling: 'mean', normalize: true })\n out.push(Float32Array.from(result.data))\n }\n return out\n },\n }\n}\n\n// Picks the highest-tier embedder available. Returns null when only\n// substring is available (caller decides what to build).\nexport async function pickEmbedder(): Promise<Embedder | null> {\n const host = ollamaHost()\n if (host && (await ollamaReachable(host))) {\n return makeOllamaEmbedder(host)\n }\n return makeTransformersEmbedder()\n}\n\n// ------------------------------------------------------------------ Cache\n\ninterface CacheEntry {\n nodeId: string\n attrsHash: string\n vector: number[]\n}\n\ninterface CacheFile {\n version: 1\n provider: 'ollama' | 'transformers'\n model: string\n dim: number\n entries: CacheEntry[]\n}\n\nasync function readCache(cachePath: string): Promise<CacheFile | null> {\n try {\n const raw = await fs.readFile(cachePath, 'utf8')\n const parsed = JSON.parse(raw) as CacheFile\n if (parsed.version !== 1) return null\n return parsed\n } catch {\n return null\n }\n}\n\nasync function writeCache(cachePath: string, cache: CacheFile): Promise<void> {\n await fs.mkdir(path.dirname(cachePath), { recursive: true })\n await fs.writeFile(cachePath, JSON.stringify(cache))\n}\n\n// ----------------------------------------------------------------- Indexes\n\nclass VectorIndex implements SearchIndex {\n readonly provider: 'ollama' | 'transformers'\n private vectors = new Map<string, { node: GraphNode; vector: Float32Array; hash: string }>()\n\n constructor(\n private embedder: Embedder,\n private cachePath: string | null,\n ) {\n this.provider = embedder.provider\n }\n\n async search(query: string, limit = DEFAULT_LIMIT): Promise<SearchResponse> {\n const trimmed = query.trim()\n if (!trimmed || this.vectors.size === 0) {\n return { query: trimmed, provider: this.provider, matches: [] }\n }\n const embedded = await this.embedder.embed([trimmed])\n const qv = embedded[0]\n if (!qv) {\n return { query: trimmed, provider: this.provider, matches: [] }\n }\n const scored: ScoredNode[] = []\n for (const { node, vector } of this.vectors.values()) {\n const score = cosine(qv, vector)\n scored.push({ node, score })\n }\n scored.sort((a, b) => b.score - a.score)\n return { query: trimmed, provider: this.provider, matches: scored.slice(0, limit) }\n }\n\n async refresh(graph: NeatGraph): Promise<void> {\n const present = new Set<string>()\n const toEmbed: { id: string; node: GraphNode; hash: string; text: string }[] = []\n\n graph.forEachNode((id, attrs) => {\n const node = attrs as GraphNode\n if (!shouldEmbed(node)) return\n present.add(id)\n const hash = attrsHash(node)\n const cached = this.vectors.get(id)\n if (cached && cached.hash === hash) {\n cached.node = node\n return\n }\n toEmbed.push({ id, node, hash, text: embedText(node) })\n })\n\n // Drop vanished nodes\n for (const id of [...this.vectors.keys()]) {\n if (!present.has(id)) this.vectors.delete(id)\n }\n\n if (toEmbed.length > 0) {\n const vectors = await this.embedder.embed(toEmbed.map((e) => e.text))\n toEmbed.forEach((entry, i) => {\n const v = vectors[i]\n if (!v) return\n this.vectors.set(entry.id, { node: entry.node, vector: v, hash: entry.hash })\n })\n }\n\n if (this.cachePath) {\n const entries: CacheEntry[] = []\n for (const [id, { vector, hash }] of this.vectors) {\n entries.push({ nodeId: id, attrsHash: hash, vector: Array.from(vector) })\n }\n await writeCache(this.cachePath, {\n version: 1,\n provider: this.embedder.provider,\n model: this.embedder.model,\n dim: this.embedder.dim,\n entries,\n })\n }\n }\n\n // Hydrate the in-memory map from a previously-written cache. Validates\n // shape against the current embedder; mismatch → empty start.\n loadFromCache(cache: CacheFile, graph: NeatGraph): void {\n if (\n cache.provider !== this.embedder.provider ||\n cache.model !== this.embedder.model ||\n cache.dim !== this.embedder.dim\n ) {\n return\n }\n const present = new Map<string, GraphNode>()\n graph.forEachNode((id, attrs) => {\n const node = attrs as GraphNode\n if (shouldEmbed(node)) present.set(id, node)\n })\n for (const entry of cache.entries) {\n const node = present.get(entry.nodeId)\n if (!node) continue\n // Skip cache entries whose attrs no longer match — they'll be\n // re-embedded by the next refresh().\n if (attrsHash(node) !== entry.attrsHash) continue\n if (entry.vector.length !== this.embedder.dim) continue\n this.vectors.set(entry.nodeId, {\n node,\n hash: entry.attrsHash,\n vector: Float32Array.from(entry.vector),\n })\n }\n }\n}\n\nclass SubstringIndex implements SearchIndex {\n readonly provider = 'substring' as const\n private graph: NeatGraph | null = null\n\n async search(query: string, limit = DEFAULT_LIMIT): Promise<SearchResponse> {\n const q = query.trim().toLowerCase()\n const out: ScoredNode[] = []\n if (!q || !this.graph) {\n return { query: q, provider: 'substring', matches: [] }\n }\n this.graph.forEachNode((id, attrs) => {\n const node = attrs as GraphNode\n const name = (node as { name?: string }).name ?? ''\n if (id.toLowerCase().includes(q) || name.toLowerCase().includes(q)) {\n out.push({ node, score: 1 })\n }\n })\n return { query: q, provider: 'substring', matches: out.slice(0, limit) }\n }\n\n async refresh(graph: NeatGraph): Promise<void> {\n this.graph = graph\n }\n}\n\n// ------------------------------------------------------------ Public factory\n\nexport interface BuildSearchIndexOptions {\n // Where to read/write the embedding cache. Falls back to in-memory only\n // if not provided. Pass `null` to explicitly disable caching.\n cachePath?: string | null\n // Override the embedder selection. Useful for tests (substring-only mode\n // skips the Ollama probe + the Transformers.js download).\n forceProvider?: 'ollama' | 'transformers' | 'substring'\n // Pre-built embedder (test injection). Wins over forceProvider.\n embedder?: Embedder\n}\n\nexport async function buildSearchIndex(\n graph: NeatGraph,\n options: BuildSearchIndexOptions = {},\n): Promise<SearchIndex> {\n let embedder: Embedder | null = null\n if (options.embedder) {\n embedder = options.embedder\n } else if (options.forceProvider !== 'substring') {\n embedder = await pickEmbedder()\n if (options.forceProvider === 'ollama' && embedder?.provider !== 'ollama') {\n embedder = null\n }\n if (options.forceProvider === 'transformers' && embedder?.provider !== 'transformers') {\n embedder = null\n }\n }\n\n if (!embedder) {\n const idx = new SubstringIndex()\n await idx.refresh(graph)\n return idx\n }\n\n const cachePath = options.cachePath === undefined ? null : options.cachePath\n const idx = new VectorIndex(embedder, cachePath)\n if (cachePath) {\n const cache = await readCache(cachePath)\n if (cache) idx.loadFromCache(cache, graph)\n }\n await idx.refresh(graph)\n return idx\n}\n","/**\n * Machine-level project registry (ADR-048).\n *\n * One file: `~/.neat/projects.json`. Per-user, machine-local. Not synced.\n * `registry.ts` is the only module that opens it. Everything else — `init`,\n * `daemon`, `cli` — calls into the helpers below.\n *\n * Two safety properties matter:\n * 1. Atomic writes. We tmp + fsync + rename so the daemon never sees a torn\n * file when init races against it.\n * 2. Cross-process exclusion. We hold an exclusive lock on\n * `~/.neat/projects.json.lock` for the read-modify-write window. Two\n * concurrent `neat init` runs cannot both win and overwrite each other.\n *\n * The lock is a file we exclusively-create (`O_EXCL`), hold while we mutate,\n * and unlink on the way out. Crude but cross-platform; matches what\n * `proper-lockfile` does internally without pulling the dep in.\n */\n\nimport { promises as fs } from 'node:fs'\nimport os from 'node:os'\nimport path from 'node:path'\nimport {\n RegistryFileSchema,\n type RegistryEntry,\n type RegistryFile,\n type RegistryStatus,\n} from '@neat.is/types'\n\nconst LOCK_TIMEOUT_MS = 5_000\nconst LOCK_RETRY_MS = 50\n\n// Resolve `~/.neat/` per call so tests can override `HOME` / `NEAT_HOME`\n// before each run without module-load order mattering.\nfunction neatHome(): string {\n const override = process.env.NEAT_HOME\n if (override && override.length > 0) return path.resolve(override)\n return path.join(os.homedir(), '.neat')\n}\n\nexport function registryPath(): string {\n return path.join(neatHome(), 'projects.json')\n}\n\nexport function registryLockPath(): string {\n return path.join(neatHome(), 'projects.json.lock')\n}\n\n/**\n * Path normalisation per ADR-048 #7. Two `init` calls from different relative\n * paths to the same dir must collapse to one entry. `path.resolve` handles\n * relative-to-cwd; we pass it through `fs.realpath` when the dir exists so\n * symlinked paths land on the same canonical entry too.\n */\nexport async function normalizeProjectPath(input: string): Promise<string> {\n const resolved = path.resolve(input)\n try {\n return await fs.realpath(resolved)\n } catch {\n return resolved\n }\n}\n\n/**\n * tmp + fsync + rename. The fsync on the data fd guarantees the bytes are on\n * disk before rename swaps the inode; rename itself is atomic on POSIX.\n *\n * Exported so the init flow and test harnesses can use the same helper.\n */\nexport async function writeAtomically(target: string, contents: string): Promise<void> {\n await fs.mkdir(path.dirname(target), { recursive: true })\n const tmp = `${target}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2, 8)}.tmp`\n const fd = await fs.open(tmp, 'w')\n try {\n await fd.writeFile(contents, 'utf8')\n await fd.sync()\n } finally {\n await fd.close()\n }\n await fs.rename(tmp, target)\n}\n\nasync function acquireLock(lockPath: string, timeoutMs: number = LOCK_TIMEOUT_MS): Promise<void> {\n const deadline = Date.now() + timeoutMs\n await fs.mkdir(path.dirname(lockPath), { recursive: true })\n while (true) {\n try {\n const fd = await fs.open(lockPath, 'wx')\n await fd.close()\n return\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code\n if (code !== 'EEXIST') throw err\n if (Date.now() >= deadline) {\n throw new Error(\n `neat registry: timed out after ${timeoutMs}ms waiting for ${lockPath}. ` +\n `Another neat process is holding the lock; if no such process exists, remove the file by hand.`,\n )\n }\n await new Promise((r) => setTimeout(r, LOCK_RETRY_MS))\n }\n }\n}\n\nasync function releaseLock(lockPath: string): Promise<void> {\n await fs.unlink(lockPath).catch(() => {})\n}\n\nasync function withLock<T>(fn: () => Promise<T>): Promise<T> {\n const lock = registryLockPath()\n await acquireLock(lock)\n try {\n return await fn()\n } finally {\n await releaseLock(lock)\n }\n}\n\n/**\n * Read the registry from disk. Returns an empty registry if the file does\n * not exist yet — first run, never registered anything.\n *\n * Throws on parse / schema errors. The contract is single-source-of-truth;\n * a corrupt file is louder than a silent reset.\n */\nexport async function readRegistry(): Promise<RegistryFile> {\n const file = registryPath()\n let raw: string\n try {\n raw = await fs.readFile(file, 'utf8')\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n return { version: 1, projects: [] }\n }\n throw err\n }\n const parsed = JSON.parse(raw)\n return RegistryFileSchema.parse(parsed)\n}\n\nasync function writeRegistry(reg: RegistryFile): Promise<void> {\n // Re-parse before writing to surface schema drift introduced by callers\n // mutating the in-memory object directly.\n const validated = RegistryFileSchema.parse(reg)\n await writeAtomically(registryPath(), JSON.stringify(validated, null, 2) + '\\n')\n}\n\nexport interface AddProjectOptions {\n name: string\n path: string\n languages?: string[]\n status?: RegistryStatus\n}\n\nexport class ProjectNameCollisionError extends Error {\n readonly projectName: string\n constructor(name: string) {\n super(`neat registry: a project named \"${name}\" is already registered`)\n this.name = 'ProjectNameCollisionError'\n this.projectName = name\n }\n}\n\n/**\n * Register a project, or update its `lastSeenAt` if the same path is already\n * registered under the same name (idempotent re-init).\n *\n * Hard error on name collision against a different path — ADR-046 #7. The\n * caller can recover by passing `--project <new-name>`.\n */\nexport async function addProject(opts: AddProjectOptions): Promise<RegistryEntry> {\n const resolvedPath = await normalizeProjectPath(opts.path)\n return withLock(async () => {\n const reg = await readRegistry()\n const byName = reg.projects.find((p) => p.name === opts.name)\n const byPath = reg.projects.find((p) => p.path === resolvedPath)\n\n if (byName && byName.path !== resolvedPath) {\n throw new ProjectNameCollisionError(opts.name)\n }\n\n const now = new Date().toISOString()\n\n if (byName && byName.path === resolvedPath) {\n // Idempotent re-register: same name, same path. Refresh languages /\n // status if the caller passed new ones.\n byName.lastSeenAt = now\n if (opts.languages) byName.languages = opts.languages\n if (opts.status) byName.status = opts.status\n await writeRegistry(reg)\n return byName\n }\n\n if (byPath && byPath.name !== opts.name) {\n // Same dir already registered under a different name. Treat as a\n // collision so the user is forced to decide which name wins.\n throw new ProjectNameCollisionError(byPath.name)\n }\n\n const entry: RegistryEntry = {\n name: opts.name,\n path: resolvedPath,\n registeredAt: now,\n languages: opts.languages ?? [],\n status: opts.status ?? 'active',\n }\n reg.projects.push(entry)\n await writeRegistry(reg)\n return entry\n })\n}\n\nexport async function getProject(name: string): Promise<RegistryEntry | undefined> {\n const reg = await readRegistry()\n return reg.projects.find((p) => p.name === name)\n}\n\nexport async function listProjects(): Promise<RegistryEntry[]> {\n const reg = await readRegistry()\n return reg.projects\n}\n\nexport async function setStatus(name: string, status: RegistryStatus): Promise<RegistryEntry> {\n return withLock(async () => {\n const reg = await readRegistry()\n const entry = reg.projects.find((p) => p.name === name)\n if (!entry) throw new Error(`neat registry: no project named \"${name}\"`)\n entry.status = status\n await writeRegistry(reg)\n return entry\n })\n}\n\nexport async function touchLastSeen(name: string, at: string = new Date().toISOString()): Promise<void> {\n await withLock(async () => {\n const reg = await readRegistry()\n const entry = reg.projects.find((p) => p.name === name)\n if (!entry) return\n entry.lastSeenAt = at\n await writeRegistry(reg)\n })\n}\n\n/**\n * Remove the registry entry for `name`. Per ADR-048 #6: this only removes the\n * registry row. It does **not** touch `neat-out/`, `policy.json`, or any user\n * file in the project directory. SDK-install rollback is a separate flow\n * (`neat-rollback.patch`) that the caller opts in to.\n */\nexport async function removeProject(name: string): Promise<RegistryEntry | undefined> {\n return withLock(async () => {\n const reg = await readRegistry()\n const idx = reg.projects.findIndex((p) => p.name === name)\n if (idx < 0) return undefined\n const [removed] = reg.projects.splice(idx, 1)\n await writeRegistry(reg)\n return removed\n })\n}\n\n","/**\n * Installer registry. v0.2.5 step 2 ships the scaffolding; the JavaScript\n * installer (step 3) and Python installer (step 4) populate `INSTALLERS`.\n */\n\nimport type { Installer, InstallPlan } from './shared.js'\nimport { javascriptInstaller } from './javascript.js'\nimport { pythonInstaller } from './python.js'\nexport { isEmptyPlan } from './shared.js'\nexport { javascriptInstaller } from './javascript.js'\nexport { pythonInstaller } from './python.js'\nexport type {\n DependencyEdit,\n EntrypointEdit,\n EnvEdit,\n Installer,\n InstallPlan,\n} from './shared.js'\n\n// Lockfile basenames installers must never write to (ADR-047 — \"lockfiles\n// never touched\"). Used by the patch renderer's safety check below.\nexport const FORBIDDEN_LOCKFILES: ReadonlySet<string> = new Set([\n 'package-lock.json',\n 'pnpm-lock.yaml',\n 'yarn.lock',\n 'poetry.lock',\n 'Pipfile.lock',\n 'Gemfile.lock',\n 'Cargo.lock',\n 'go.sum',\n])\n\n// Order is priority — first match wins per service. JavaScript leads because\n// it's the most common shape in the projects NEAT targets; Python follows.\nexport const INSTALLERS: Installer[] = [javascriptInstaller, pythonInstaller]\n\n/**\n * Resolve the first installer that claims a given service directory. Returns\n * `null` if none match.\n *\n * Per language, the first matching installer wins. Order in `INSTALLERS`\n * defines that priority — declarations are explicit, not alphabetical.\n */\nexport async function pickInstaller(serviceDir: string): Promise<Installer | null> {\n for (const inst of INSTALLERS) {\n if (await inst.detect(serviceDir)) return inst\n }\n return null\n}\n\nexport interface PatchSection {\n installer: string\n plan: InstallPlan\n}\n\n/**\n * Render install plans into a single review-friendly text patch. The format\n * is intentionally human-shaped, not unified-diff: agents and humans both\n * read this. Determinism — same input, byte-identical output — is the\n * load-bearing property (ADR-047 #6).\n */\nexport function renderPatch(sections: PatchSection[]): string {\n if (sections.length === 0) {\n return [\n '# neat install plan',\n '',\n 'No SDK installers matched the discovered services. Two reasons this',\n 'normally happens:',\n ' - the project uses a language NEAT does not yet instrument',\n ' (Java / Ruby / .NET / Go / Rust are out of MVP scope per ADR-047);',\n ' - the SDK is already installed, so the installer returned an empty',\n ' plan.',\n '',\n 'You can re-run `neat init --apply` later to pick up new services.',\n '',\n ].join('\\n')\n }\n\n const lines: string[] = ['# neat install plan', '']\n for (const section of sections) {\n const { installer, plan } = section\n lines.push(`## ${installer} (${plan.language}) — ${plan.serviceDir}`)\n lines.push('')\n\n if (plan.dependencyEdits.length > 0) {\n lines.push('### dependencies')\n for (const dep of plan.dependencyEdits) {\n // Hard-fail rather than render a patch that could mislead the user\n // into thinking NEAT touches lockfiles.\n const base = dep.file.split(/[\\\\/]/).pop() ?? dep.file\n if (FORBIDDEN_LOCKFILES.has(base)) {\n throw new Error(\n `installer \"${installer}\" produced a dependency edit against a lockfile (${dep.file}); ` +\n `lockfiles must never be touched (ADR-047).`,\n )\n }\n lines.push(`- ${dep.kind} ${dep.name}@${dep.version} in ${dep.file}`)\n }\n lines.push('')\n }\n\n if (plan.entrypointEdits.length > 0) {\n lines.push('### entrypoint')\n for (const e of plan.entrypointEdits) {\n lines.push(`- ${e.file}`)\n lines.push(` - before: ${e.before}`)\n lines.push(` - after: ${e.after}`)\n }\n lines.push('')\n }\n\n if (plan.envEdits.length > 0) {\n lines.push('### env')\n for (const env of plan.envEdits) {\n const target = env.file ?? '(set in your orchestration layer)'\n lines.push(`- ${env.key}=${env.value} → ${target}`)\n }\n lines.push('')\n }\n }\n return lines.join('\\n')\n}\n","/**\n * Node / TypeScript SDK installer (ADR-047).\n *\n * Detects services by the presence of a `package.json` carrying a `name`\n * field — same shape `extract/services.ts` uses to decide what counts as a\n * Node service. The plan adds three OTel packages to `dependencies` and, if\n * a `scripts.start` exists, prefixes it with the auto-instrumentation hook.\n *\n * Lockfiles are never touched. After `--apply`, init prints \"run npm install\"\n * so the user owns the lockfile commit (ADR-047 — \"Lockfiles never touched\").\n */\n\nimport { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport type { DependencyEdit, EntrypointEdit, EnvEdit, Installer, InstallPlan } from './shared.js'\n\nconst SDK_PACKAGES = [\n { name: '@opentelemetry/api', version: '^1.9.0' },\n { name: '@opentelemetry/sdk-node', version: '^0.57.0' },\n { name: '@opentelemetry/auto-instrumentations-node', version: '^0.55.0' },\n] as const\n\nconst AUTO_INSTRUMENT_REQUIRE = '--require @opentelemetry/auto-instrumentations-node/register'\n\nconst OTEL_ENV: EnvEdit = {\n // null target — NEAT does not write `.env` itself; the user sets the env\n // var in their orchestration layer.\n file: null,\n key: 'OTEL_EXPORTER_OTLP_ENDPOINT',\n value: 'http://localhost:4318',\n}\n\ninterface PackageJsonShape {\n name?: string\n scripts?: Record<string, string>\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n}\n\nasync function readPackageJson(serviceDir: string): Promise<PackageJsonShape | null> {\n try {\n const raw = await fs.readFile(path.join(serviceDir, 'package.json'), 'utf8')\n return JSON.parse(raw) as PackageJsonShape\n } catch {\n return null\n }\n}\n\nasync function detect(serviceDir: string): Promise<boolean> {\n const pkg = await readPackageJson(serviceDir)\n return pkg !== null && typeof pkg.name === 'string'\n}\n\nfunction rewriteStartScript(start: string): string {\n // Already wired via auto-instrumentation? Don't touch — idempotency\n // (ADR-047 — \"Re-running init --apply produces no diff\").\n if (start.includes(AUTO_INSTRUMENT_REQUIRE)) return start\n // Most start scripts begin with `node …`. Keep the rest of the command and\n // splice the require flag in. Non-`node` starts (e.g. `next start`,\n // `tsx server.ts`) get the require flag prefixed via `node` since the\n // OTel hook needs a Node entry to attach to.\n if (/^\\s*node\\b/.test(start)) {\n return start.replace(/^\\s*node\\b\\s*/, `node ${AUTO_INSTRUMENT_REQUIRE} `)\n }\n return `node ${AUTO_INSTRUMENT_REQUIRE} -- ${start}`\n}\n\nasync function plan(serviceDir: string): Promise<InstallPlan> {\n const pkg = await readPackageJson(serviceDir)\n const manifestPath = path.join(serviceDir, 'package.json')\n const empty: InstallPlan = {\n language: 'javascript',\n serviceDir,\n dependencyEdits: [],\n entrypointEdits: [],\n envEdits: [],\n }\n if (!pkg) return empty\n\n const existingDeps = { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) }\n const dependencyEdits: DependencyEdit[] = []\n for (const sdk of SDK_PACKAGES) {\n if (sdk.name in existingDeps) continue\n dependencyEdits.push({\n file: manifestPath,\n kind: 'add',\n name: sdk.name,\n version: sdk.version,\n })\n }\n // SDK_PACKAGES is already in stable declaration order, so the slice above\n // is deterministic across runs (ADR-047 #6).\n\n const entrypointEdits: EntrypointEdit[] = []\n const startScript = pkg.scripts?.start\n if (typeof startScript === 'string' && startScript.trim().length > 0) {\n const rewritten = rewriteStartScript(startScript)\n if (rewritten !== startScript) {\n entrypointEdits.push({ file: manifestPath, before: startScript, after: rewritten })\n }\n }\n\n // Empty plan when nothing needs to change anywhere — that is, every SDK\n // dep is present and the start script already wires the hook (or there's\n // no start script to wire). Surfaces ADR-047 #5: \"plan(dir) returns an\n // empty plan when SDK is already installed.\"\n if (dependencyEdits.length === 0 && entrypointEdits.length === 0) {\n return empty\n }\n\n return {\n language: 'javascript',\n serviceDir,\n dependencyEdits,\n entrypointEdits,\n envEdits: [OTEL_ENV],\n }\n}\n\nasync function apply(installPlan: InstallPlan): Promise<void> {\n const touched = new Set<string>()\n for (const e of installPlan.dependencyEdits) touched.add(e.file)\n for (const e of installPlan.entrypointEdits) touched.add(e.file)\n if (touched.size === 0) return\n\n // Snapshot every file we're about to mutate so a partial failure can roll\n // back the whole batch (ADR-047 #7). Missing files are intentionally not\n // an early-exit: the per-file mutation loop will hit them, fail, and\n // trigger rollback for the files we already wrote.\n const originals = new Map<string, string>()\n for (const file of touched) {\n try {\n originals.set(file, await fs.readFile(file, 'utf8'))\n } catch {\n // No snapshot for this file. Mutation will fail loudly below.\n }\n }\n\n try {\n for (const file of touched) {\n const raw = originals.get(file) ?? ''\n const pkg = JSON.parse(raw) as PackageJsonShape\n pkg.dependencies = pkg.dependencies ?? {}\n\n for (const dep of installPlan.dependencyEdits) {\n if (dep.file !== file) continue\n if (dep.kind === 'add') {\n pkg.dependencies[dep.name] = dep.version\n } else {\n delete pkg.dependencies[dep.name]\n }\n }\n\n for (const ep of installPlan.entrypointEdits) {\n if (ep.file !== file) continue\n pkg.scripts = pkg.scripts ?? {}\n if (pkg.scripts.start === ep.before) {\n pkg.scripts.start = ep.after\n }\n }\n\n // Match the most common npm formatting (two-space indent, trailing\n // newline) so the diff stays minimal on review.\n const newRaw = JSON.stringify(pkg, null, 2) + '\\n'\n const tmp = `${file}.${process.pid}.${Date.now()}.tmp`\n await fs.writeFile(tmp, newRaw, 'utf8')\n await fs.rename(tmp, file)\n }\n } catch (err) {\n await rollback(installPlan, originals)\n throw err\n }\n}\n\nasync function rollback(\n installPlan: InstallPlan,\n originals: Map<string, string>,\n): Promise<void> {\n const restored: string[] = []\n for (const [file, raw] of originals.entries()) {\n try {\n await fs.writeFile(file, raw, 'utf8')\n restored.push(file)\n } catch {\n // Best-effort: keep going so we restore as much as we can.\n }\n }\n const lines = [\n '# neat-rollback.patch',\n '',\n `# Generated after a partial apply failure in the ${installPlan.language} installer.`,\n '# Files listed below were restored to their pre-apply contents.',\n '',\n ...restored.map((f) => `restored: ${f}`),\n '',\n ]\n const rollbackPath = path.join(installPlan.serviceDir, 'neat-rollback.patch')\n await fs.writeFile(rollbackPath, lines.join('\\n'), 'utf8')\n}\n\nexport const javascriptInstaller: Installer = {\n name: 'javascript',\n detect,\n plan,\n apply,\n}\n","/**\n * Python SDK installer (ADR-047).\n *\n * `detect` matches on the canonical Python project markers — requirements.txt,\n * pyproject.toml, setup.py. `plan` produces dependency edits against the\n * primary manifest and entrypoint edits against a Procfile when one exists.\n *\n * MVP scope:\n * - requirements.txt is the full-fidelity manifest (read / append).\n * - pyproject.toml dependencies live inside a TOML `dependencies = [...]`\n * block; we line-insert into that block when found, otherwise hold off\n * on rewriting until a successor ADR addresses TOML editing properly.\n * - Procfile lines starting with `python` get prefixed with\n * `opentelemetry-instrument`.\n *\n * Lockfiles (poetry.lock, Pipfile.lock) are never touched. After `--apply`,\n * init's summary tells the user to run `pip install -r requirements.txt`\n * (or `poetry lock && poetry install`) so they own the lockfile commit.\n */\n\nimport { promises as fs } from 'node:fs'\nimport path from 'node:path'\nimport type { DependencyEdit, EntrypointEdit, EnvEdit, Installer, InstallPlan } from './shared.js'\n\nconst SDK_PACKAGES = [\n { name: 'opentelemetry-distro', version: '>=0.49b0' },\n { name: 'opentelemetry-exporter-otlp', version: '>=1.28.0' },\n] as const\n\nconst OTEL_ENV: EnvEdit = {\n file: null,\n key: 'OTEL_EXPORTER_OTLP_ENDPOINT',\n value: 'http://localhost:4318',\n}\n\nasync function exists(p: string): Promise<boolean> {\n try {\n await fs.stat(p)\n return true\n } catch {\n return false\n }\n}\n\nasync function detect(serviceDir: string): Promise<boolean> {\n const markers = ['requirements.txt', 'pyproject.toml', 'setup.py']\n for (const m of markers) {\n if (await exists(path.join(serviceDir, m))) return true\n }\n return false\n}\n\n// Strip a requirements.txt line down to its lower-cased package name.\n// `flask==3.0.0` → `flask`, `Flask>=2 ; python_version>\"3.6\"` → `flask`.\nfunction reqPackageName(line: string): string {\n const stripped = line.split('#')[0]?.trim() ?? ''\n const head = stripped.split(/[\\s;]/)[0] ?? ''\n return head.replace(/[<>=!~].*$/, '').toLowerCase()\n}\n\nasync function planRequirementsTxtEdits(\n serviceDir: string,\n): Promise<{ manifest: string; missing: typeof SDK_PACKAGES[number][] } | null> {\n const file = path.join(serviceDir, 'requirements.txt')\n if (!(await exists(file))) return null\n const raw = await fs.readFile(file, 'utf8')\n const presentNames = new Set(\n raw\n .split(/\\r?\\n/)\n .map(reqPackageName)\n .filter((n) => n.length > 0),\n )\n const missing = SDK_PACKAGES.filter((p) => !presentNames.has(p.name.toLowerCase()))\n return { manifest: file, missing: [...missing] }\n}\n\nasync function planProcfileEdits(serviceDir: string): Promise<EntrypointEdit[]> {\n const procfile = path.join(serviceDir, 'Procfile')\n if (!(await exists(procfile))) return []\n const raw = await fs.readFile(procfile, 'utf8')\n const edits: EntrypointEdit[] = []\n for (const line of raw.split(/\\r?\\n/)) {\n if (line.length === 0) continue\n // Procfile lines look like `<process>: <cmd>`. Prefix the cmd when it\n // starts with python and isn't already wrapped.\n const m = line.match(/^([a-zA-Z0-9_-]+):\\s*(.+)$/)\n if (!m) continue\n const cmd = m[2]!\n if (!/^python\\b/.test(cmd)) continue\n if (cmd.startsWith('opentelemetry-instrument ')) continue\n const after = `${m[1]}: opentelemetry-instrument ${cmd}`\n edits.push({ file: procfile, before: line, after })\n }\n return edits\n}\n\nasync function plan(serviceDir: string): Promise<InstallPlan> {\n const empty: InstallPlan = {\n language: 'python',\n serviceDir,\n dependencyEdits: [],\n entrypointEdits: [],\n envEdits: [],\n }\n\n const dependencyEdits: DependencyEdit[] = []\n const reqs = await planRequirementsTxtEdits(serviceDir)\n if (reqs) {\n for (const sdk of reqs.missing) {\n dependencyEdits.push({\n file: reqs.manifest,\n kind: 'add',\n name: sdk.name,\n version: sdk.version,\n })\n }\n }\n // pyproject.toml / setup.py without requirements.txt: deferred to a\n // successor ADR. The patch will note it; apply is a no-op for those\n // manifests in the MVP.\n\n const entrypointEdits = await planProcfileEdits(serviceDir)\n\n if (dependencyEdits.length === 0 && entrypointEdits.length === 0) {\n return empty\n }\n return {\n language: 'python',\n serviceDir,\n dependencyEdits,\n entrypointEdits,\n envEdits: [OTEL_ENV],\n }\n}\n\nasync function applyRequirementsTxt(\n manifest: string,\n edits: DependencyEdit[],\n original: string,\n): Promise<void> {\n // Append missing packages on their own lines. Preserve a trailing newline.\n const newlines = edits\n .filter((e) => e.kind === 'add')\n .map((e) => `${e.name}${e.version}`)\n const trailing = original.endsWith('\\n') ? '' : '\\n'\n const next = `${original}${trailing}${newlines.join('\\n')}\\n`\n const tmp = `${manifest}.${process.pid}.${Date.now()}.tmp`\n await fs.writeFile(tmp, next, 'utf8')\n await fs.rename(tmp, manifest)\n}\n\nasync function applyProcfile(\n procfile: string,\n edits: EntrypointEdit[],\n original: string,\n): Promise<void> {\n let next = original\n for (const e of edits) {\n if (!next.includes(e.before)) continue\n next = next.replace(e.before, e.after)\n }\n const tmp = `${procfile}.${process.pid}.${Date.now()}.tmp`\n await fs.writeFile(tmp, next, 'utf8')\n await fs.rename(tmp, procfile)\n}\n\nasync function apply(installPlan: InstallPlan): Promise<void> {\n const touched = new Set<string>()\n for (const e of installPlan.dependencyEdits) touched.add(e.file)\n for (const e of installPlan.entrypointEdits) touched.add(e.file)\n if (touched.size === 0) return\n\n const originals = new Map<string, string>()\n for (const file of touched) {\n try {\n originals.set(file, await fs.readFile(file, 'utf8'))\n } catch {\n // Mutation will fail loudly below; rollback covers what did land.\n }\n }\n\n try {\n for (const file of touched) {\n const raw = originals.get(file)\n if (raw === undefined) {\n throw new Error(`python installer: cannot read ${file} during apply`)\n }\n const base = path.basename(file)\n if (base === 'requirements.txt') {\n const edits = installPlan.dependencyEdits.filter((e) => e.file === file)\n if (edits.length > 0) await applyRequirementsTxt(file, edits, raw)\n } else if (base === 'Procfile') {\n const edits = installPlan.entrypointEdits.filter((e) => e.file === file)\n if (edits.length > 0) await applyProcfile(file, edits, raw)\n }\n // pyproject.toml / setup.py: MVP no-op as planned above.\n }\n } catch (err) {\n await rollback(installPlan, originals)\n throw err\n }\n}\n\nasync function rollback(\n installPlan: InstallPlan,\n originals: Map<string, string>,\n): Promise<void> {\n const restored: string[] = []\n for (const [file, raw] of originals.entries()) {\n try {\n await fs.writeFile(file, raw, 'utf8')\n restored.push(file)\n } catch {\n // Best-effort.\n }\n }\n const lines = [\n '# neat-rollback.patch',\n '',\n `# Generated after a partial apply failure in the ${installPlan.language} installer.`,\n '# Files listed below were restored to their pre-apply contents.',\n '',\n ...restored.map((f) => `restored: ${f}`),\n '',\n ]\n const rollbackPath = path.join(installPlan.serviceDir, 'neat-rollback.patch')\n await fs.writeFile(rollbackPath, lines.join('\\n'), 'utf8')\n}\n\nexport const pythonInstaller: Installer = {\n name: 'python',\n detect,\n plan,\n apply,\n}\n","/**\n * Shared types for SDK installer modules (ADR-047).\n *\n * Each language has its own installer at `installers/<language>.ts` exporting\n * a `detect / plan / apply` triple. Plans are pure data — no fs side effects\n * during planning — so `init --dry-run` can render a patch without ever\n * touching the project. `apply` runs the codemod in place.\n *\n * Step 2 (this PR) ships the interface and an empty registry. Step 3 (Node\n * installer) and step 4 (Python installer) populate it.\n */\n\n// Field names match ADR-047's documented patch shape exactly: `file`, `kind`,\n// `name`, `version`. Patches will be reviewed by humans and matched in tests\n// by name; renaming for clarity would have cost more than it bought.\n\nexport interface DependencyEdit {\n file: string\n kind: 'add' | 'remove'\n name: string\n version: string\n}\n\nexport interface EntrypointEdit {\n file: string\n before: string\n after: string\n}\n\nexport interface EnvEdit {\n // `null` denotes a recommendation only — the user will set the env var in\n // their orchestration layer, NEAT does not write a `.env` file.\n file: string | null\n key: string\n value: string\n}\n\nexport interface InstallPlan {\n // Free-form language tag matching the service node's language: `'javascript'`,\n // `'python'`, …\n language: string\n // Service directory the plan targets. Absolute path.\n serviceDir: string\n dependencyEdits: DependencyEdit[]\n entrypointEdits: EntrypointEdit[]\n envEdits: EnvEdit[]\n}\n\nexport interface Installer {\n // Free-form module name. Used for the patch header and for diagnostics.\n name: string\n // Returns true if the installer thinks `serviceDir` is shaped like a project\n // it can instrument. Cheap; no fs writes.\n detect(serviceDir: string): boolean | Promise<boolean>\n // Builds an `InstallPlan` describing the edits the installer would make.\n // Pure data; no fs writes. An empty plan (every edits array empty) means\n // the SDK is already installed and there is nothing to do.\n plan(serviceDir: string): InstallPlan | Promise<InstallPlan>\n // Apply a previously-produced plan. Mutates files in place. On failure,\n // produces `<serviceDir>/neat-rollback.patch` per ADR-047 #7.\n apply(plan: InstallPlan): Promise<void>\n}\n\nexport function isEmptyPlan(plan: InstallPlan): boolean {\n return (\n plan.dependencyEdits.length === 0 &&\n plan.entryp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uf","reshapeGrpcRequest","Fastify","import_node_path","import_node_url","import_fastify","import_node_path","import_node_fs","GraphDefault","import_node_fs","import_node_path","import_node_fs","import_node_path","import_types","path","os","semver","fs","path","frontierId","fs","path","import_types","entry","fs","path","frontierId","frontierId","serviceId","fs","path","import_node_fs","import_node_path","import_types","import_node_fs","import_node_path","import_types","path","fs","parseYaml","import_node_fs","import_node_path","entry","path","fs","parseToml","path","fs","ignore","entry","import_node_path","import_node_fs","import_yaml","import_types","serviceId","path","fs","entry","import_node_path","import_types","import_node_path","path","import_node_fs","import_node_path","import_node_fs","import_node_path","fs","path","parse","fs","entry","path","import_node_path","parse","path","parse","parse","import_node_path","parse","path","entry","parse","import_node_path","parse","path","entry","import_node_path","parse","path","path","import_node_fs","import_node_path","import_types","fs","entry","path","import_types","import_node_path","import_types","import_node_fs","import_node_path","fs","entry","path","Parser","JavaScript","Python","path","import_node_path","import_types","path","import_node_path","import_types","path","import_node_path","import_types","findAll","path","import_node_path","import_types","path","import_node_path","import_types","import_types","path","import_node_path","import_node_fs","import_types","path","fs","import_node_fs","import_node_path","fs","entry","path","import_node_fs","import_node_path","import_yaml","walkYamlFiles","fs","entry","path","import_node_fs","import_node_path","fs","path","import_node_path","import_types","import_node_fs","fs","entry","import_node_path","path","violations","blocking","Fastify","cors","import_types","import_node_fs","import_node_path","fs","path","entry","idx","path","chokidar","import_node_fs","import_node_os","import_node_path","import_types","path","os","fs","entry","status","entry","import_node_fs","import_node_path","fs","path","import_node_fs","import_node_path","SDK_PACKAGES","OTEL_ENV","exists","fs","detect","path","plan","apply","rollback","plan","plan","apply","plan","fs","path","snippet","entry"]}
|